Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add subscriptions #10541

Merged
merged 12 commits into from
Nov 28, 2024

Conversation

sdanialraza
Copy link
Contributor

Please describe the changes this PR makes and why it should be merged:
Adds subscriptions for mainlib

Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating
  • This PR changes the library's interface (methods or parameters added)

Copy link

vercel bot commented Oct 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
discord-js ⬜️ Ignored (Inspect) Visit Preview Nov 28, 2024 8:14am
discord-js-guide ⬜️ Ignored (Inspect) Visit Preview Nov 28, 2024 8:14am

@sdanialraza sdanialraza force-pushed the feat/add-subscriptions-mainlib branch from 2401984 to 1d66e02 Compare October 14, 2024 17:16
Copy link
Contributor

@OfficialSirH OfficialSirH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me parece bien

@sdanialraza sdanialraza marked this pull request as ready for review October 15, 2024 13:41
@sdanialraza sdanialraza requested a review from a team as a code owner October 15, 2024 13:41
@Jiralite Jiralite added this to the discord.js 14.17 milestone Oct 15, 2024
packages/discord.js/src/index.js Outdated Show resolved Hide resolved
packages/discord.js/src/index.js Outdated Show resolved Hide resolved
Copy link
Member

@Jiralite Jiralite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the documentation1 and the specification2, ends_at may now be null. This means this logic needs to be modified as Date.parse(null) will result in NaN:

if ('ends_at' in data) {
/**
* The timestamp at which this entitlement is no longer valid
* <info>This is only `null` for test entitlements</info>
* @type {?number}
*/
this.endsTimestamp = Date.parse(data.ends_at);
} else {
this.endsTimestamp ??= null;
}

I say this, but the entitlement object itself on the documentation does not have it marked as nullable. It probably needs updating (discord/discord-api-docs#7268).

Footnotes

  1. https://discord.com/developers/docs/monetization/implementing-app-subscriptions#how-app-subscriptions-work

  2. https://github.com/discord/discord-api-spec/blob/c979cb269dbaf8cd09b8d0a39cc683d9623d8ce4/specs/openapi.json#L16491-L16495

@sdanialraza sdanialraza force-pushed the feat/add-subscriptions-mainlib branch from cc694a9 to 5468dee Compare November 13, 2024 23:05
@sdanialraza sdanialraza requested a review from Jiralite November 13, 2024 23:06
@Jiralite Jiralite dismissed their stale review November 14, 2024 00:02

Resolved.

@sdanialraza sdanialraza force-pushed the feat/add-subscriptions-mainlib branch from 5468dee to ba472bd Compare November 15, 2024 11:18
packages/discord.js/typings/index.d.ts Outdated Show resolved Hide resolved
@sdanialraza sdanialraza requested a review from Jiralite November 15, 2024 14:10
@Jiralite Jiralite dismissed their stale review November 17, 2024 01:04

Resolved.

@sdanialraza sdanialraza force-pushed the feat/add-subscriptions-mainlib branch from 14b9f7b to 13e69ca Compare November 21, 2024 22:58
@sdanialraza sdanialraza force-pushed the feat/add-subscriptions-mainlib branch from 13e69ca to 080e537 Compare November 24, 2024 15:03
@sdanialraza sdanialraza force-pushed the feat/add-subscriptions-mainlib branch from 080e537 to fa54236 Compare November 26, 2024 12:51
@sdanialraza sdanialraza force-pushed the feat/add-subscriptions-mainlib branch from fa54236 to eac2591 Compare November 27, 2024 21:10
@kodiakhq kodiakhq bot merged commit 108943a into discordjs:main Nov 28, 2024
7 checks passed
@sdanialraza sdanialraza deleted the feat/add-subscriptions-mainlib branch November 29, 2024 00:09
Jiralite added a commit that referenced this pull request Dec 2, 2024
* feat: add subscriptions

* types: fix fetch options types

* fix: correct properties in patch method

* chore: requested changes

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>

* fix: correct export syntax

* chore(Entitlement): mark `ends_at` as nullable`

* types(FetchSubscriptionOptions): add missing `cache` option

* Revert "types(FetchSubscriptionOptions): add missing `cache` option"

This reverts commit ba472bd.

* chore(Entitlement): mark `startsTimestamp` as nullable

* fix: requested changes

* docs(SubscriptionManager): correct return type

---------

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Entitlement#isTest always returns false even though entitlement is a test entitlement
6 participants