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 #10486

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 46 additions & 5 deletions packages/core/src/api/monetization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import {
type RESTGetAPIEntitlementsQuery,
type RESTGetAPIEntitlementsResult,
type RESTGetAPISKUsResult,
type RESTGetAPISKUSubscriptionResult,
type RESTGetAPISKUSubscriptionsQuery,
type RESTGetAPISKUSubscriptionsResult,
type RESTPostAPIEntitlementJSONBody,
type RESTPostAPIEntitlementResult,
type Snowflake,
Expand All @@ -17,17 +20,55 @@ export class MonetizationAPI {
/**
* Fetches the SKUs for an application.
*
* @see {@link https://discord.com/developers/docs/monetization/skus#list-skus}
* @see {@link https://discord.com/developers/docs/resources/sku#list-skus}
* @param applicationId - The application id to fetch SKUs for
* @param options - The options for fetching the SKUs.
*/
public async getSKUs(applicationId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.skus(applicationId), { signal }) as Promise<RESTGetAPISKUsResult>;
}

/**
* Fetches the subscriptions for an SKU.
sdanialraza marked this conversation as resolved.
Show resolved Hide resolved
*
* @see {@link https://discord.com/developers/docs/resources/subscription#list-sku-subscriptions}
* @param skuId - The SKU id to fetch subscriptions for
* @param query - The query options for fetching subscriptions
* @param options - The options for fetching subscriptions
*/
public async getSKUSubscriptions(
skuId: Snowflake,
query: RESTGetAPISKUSubscriptionsQuery,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.get(Routes.skuSubscriptions(skuId), {
signal,
query: makeURLSearchParams(query),
}) as Promise<RESTGetAPISKUSubscriptionsResult>;
}

/**
* Fetches the subscription for an SKU.
sdanialraza marked this conversation as resolved.
Show resolved Hide resolved
*
* @see {@link https://discord.com/developers/docs/resources/subscription#get-sku-subscription}
* @param skuId - The SKU id to fetch subscription for
* @param subscriptionId - The subscription id to fetch
* @param options - The options for fetching the subscription
*/
public async getSKUSubscription(
skuId: Snowflake,
subscriptionId: Snowflake,
sdanialraza marked this conversation as resolved.
Show resolved Hide resolved
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.get(Routes.skuSubscription(skuId, subscriptionId), {
signal,
}) as Promise<RESTGetAPISKUSubscriptionResult>;
}

/**
* Fetches the entitlements for an application.
*
* @see {@link https://discord.com/developers/docs/monetization/entitlements#list-entitlements}
* @see {@link https://discord.com/developers/docs/resources/entitlement#list-entitlements}
* @param applicationId - The application id to fetch entitlements for
* @param query - The query options for fetching entitlements
* @param options - The options for fetching entitlements
Expand All @@ -46,7 +87,7 @@ export class MonetizationAPI {
/**
* Creates a test entitlement for an application's SKU.
*
* @see {@link https://discord.com/developers/docs/monetization/entitlements#create-test-entitlement}
* @see {@link https://discord.com/developers/docs/resources/entitlement#create-test-entitlement}
* @param applicationId - The application id to create the entitlement for
* @param body - The data for creating the entitlement
* @param options - The options for creating the entitlement
Expand All @@ -65,7 +106,7 @@ export class MonetizationAPI {
/**
* Deletes a test entitlement for an application's SKU.
*
* @see {@link https://discord.com/developers/docs/monetization/entitlements#delete-test-entitlement}
* @see {@link https://discord.com/developers/docs/resources/entitlement#delete-test-entitlement}
* @param applicationId - The application id to delete the entitlement for
* @param entitlementId - The entitlement id to delete
* @param options - The options for deleting the entitlement
Expand All @@ -81,7 +122,7 @@ export class MonetizationAPI {
/**
* Marks a given entitlement for the user as consumed. Only available for One-Time Purchase consumable SKUs.
*
* @see {@link https://discord.com/developers/docs/monetization/entitlements#consume-an-entitlement}
* @see {@link https://discord.com/developers/docs/resources/entitlement#consume-an-entitlement}
* @param applicationId - The application id to consume the entitlement for
* @param entitlementId - The entitlement id to consume
* @param options - The options for consuming the entitlement
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ import {
type GatewayStageInstanceCreateDispatchData,
type GatewayStageInstanceDeleteDispatchData,
type GatewayStageInstanceUpdateDispatchData,
type GatewaySubscriptionCreateDispatchData,
type GatewaySubscriptionDeleteDispatchData,
type GatewaySubscriptionUpdateDispatchData,
type GatewayThreadCreateDispatchData,
type GatewayThreadDeleteDispatchData,
type GatewayThreadListSyncDispatchData,
Expand Down Expand Up @@ -155,6 +158,9 @@ export interface MappedEvents {
[GatewayDispatchEvents.StageInstanceCreate]: [ToEventProps<GatewayStageInstanceCreateDispatchData>];
[GatewayDispatchEvents.StageInstanceDelete]: [ToEventProps<GatewayStageInstanceDeleteDispatchData>];
[GatewayDispatchEvents.StageInstanceUpdate]: [ToEventProps<GatewayStageInstanceUpdateDispatchData>];
[GatewayDispatchEvents.SubscriptionCreate]: [ToEventProps<GatewaySubscriptionCreateDispatchData>];
[GatewayDispatchEvents.SubscriptionDelete]: [ToEventProps<GatewaySubscriptionDeleteDispatchData>];
[GatewayDispatchEvents.SubscriptionUpdate]: [ToEventProps<GatewaySubscriptionUpdateDispatchData>];
[GatewayDispatchEvents.ThreadCreate]: [ToEventProps<GatewayThreadCreateDispatchData>];
[GatewayDispatchEvents.ThreadDelete]: [ToEventProps<GatewayThreadDeleteDispatchData>];
[GatewayDispatchEvents.ThreadListSync]: [ToEventProps<GatewayThreadListSyncDispatchData>];
Expand Down