From f1d975465fa56f2666538d88bf14f079878bc18e Mon Sep 17 00:00:00 2001 From: Danial Raza Date: Thu, 5 Sep 2024 17:08:21 +0200 Subject: [PATCH] feat: add subscriptions --- packages/core/src/api/monetization.ts | 49 ++++++++++++++++++++++++--- packages/core/src/client.ts | 6 ++++ 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/packages/core/src/api/monetization.ts b/packages/core/src/api/monetization.ts index 736b8930a1e5..6ef9b24bd2e8 100644 --- a/packages/core/src/api/monetization.ts +++ b/packages/core/src/api/monetization.ts @@ -6,6 +6,9 @@ import { type RESTGetAPIEntitlementsQuery, type RESTGetAPIEntitlementsResult, type RESTGetAPISKUsResult, + type RESTGetAPISKUSubscriptionResult, + type RESTGetAPISKUSubscriptionsQuery, + type RESTGetAPISKUSubscriptionsResult, type RESTPostAPIEntitlementJSONBody, type RESTPostAPIEntitlementResult, type Snowflake, @@ -17,17 +20,53 @@ 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 options - The options for fetching the SKUs. */ public async getSKUs(applicationId: Snowflake, { signal }: Pick = {}) { return this.rest.get(Routes.skus(applicationId), { signal }) as Promise; } + /** + * Fetches the subscriptions for an SKU. + * + * @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 = {}, + ) { + return this.rest.get(Routes.skuSubscriptions(skuId), { + signal, + query: makeURLSearchParams(query), + }) as Promise; + } + + /** + * Fetches the subscription for an SKU. + * + * @see {@link https://discord.com/developers/docs/resources/subscription#get-sku-subscription} + * @param skuId - The SKU id to fetch subscription for + * @param options - The options for fetching the subscription + */ + public async getSKUSubscription( + skuId: Snowflake, + subscriptionId: Snowflake, + { signal }: Pick = {}, + ) { + return this.rest.get(Routes.skuSubscription(skuId, subscriptionId), { + signal, + }) as Promise; + } + /** * 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 @@ -46,7 +85,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 @@ -65,7 +104,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 @@ -81,7 +120,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 diff --git a/packages/core/src/client.ts b/packages/core/src/client.ts index 90eea1e2d8e9..73311b35a271 100644 --- a/packages/core/src/client.ts +++ b/packages/core/src/client.ts @@ -62,6 +62,9 @@ import { type GatewayStageInstanceCreateDispatchData, type GatewayStageInstanceDeleteDispatchData, type GatewayStageInstanceUpdateDispatchData, + type GatewaySubscriptionCreateDispatchData, + type GatewaySubscriptionDeleteDispatchData, + type GatewaySubscriptionUpdateDispatchData, type GatewayThreadCreateDispatchData, type GatewayThreadDeleteDispatchData, type GatewayThreadListSyncDispatchData, @@ -155,6 +158,9 @@ export interface MappedEvents { [GatewayDispatchEvents.StageInstanceCreate]: [ToEventProps]; [GatewayDispatchEvents.StageInstanceDelete]: [ToEventProps]; [GatewayDispatchEvents.StageInstanceUpdate]: [ToEventProps]; + [GatewayDispatchEvents.SubscriptionCreate]: [ToEventProps]; + [GatewayDispatchEvents.SubscriptionDelete]: [ToEventProps]; + [GatewayDispatchEvents.SubscriptionUpdate]: [ToEventProps]; [GatewayDispatchEvents.ThreadCreate]: [ToEventProps]; [GatewayDispatchEvents.ThreadDelete]: [ToEventProps]; [GatewayDispatchEvents.ThreadListSync]: [ToEventProps];