Skip to content

Commit 2deea25

Browse files
sdanialrazaalmeidxkodiakhq[bot]
authored andcommitted
feat: add subscriptions (#10486)
* feat: add subscriptions * docs: requested changes Co-authored-by: Almeida <[email protected]> --------- Co-authored-by: Almeida <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 5c5b545 commit 2deea25

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed

packages/core/src/api/monetization.ts

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import {
66
type RESTGetAPIEntitlementsQuery,
77
type RESTGetAPIEntitlementsResult,
88
type RESTGetAPISKUsResult,
9+
type RESTGetAPISKUSubscriptionResult,
10+
type RESTGetAPISKUSubscriptionsQuery,
11+
type RESTGetAPISKUSubscriptionsResult,
912
type RESTPostAPIEntitlementJSONBody,
1013
type RESTPostAPIEntitlementResult,
1114
type Snowflake,
@@ -17,17 +20,55 @@ export class MonetizationAPI {
1720
/**
1821
* Fetches the SKUs for an application.
1922
*
20-
* @see {@link https://discord.com/developers/docs/monetization/skus#list-skus}
23+
* @see {@link https://discord.com/developers/docs/resources/sku#list-skus}
24+
* @param applicationId - The application id to fetch SKUs for
2125
* @param options - The options for fetching the SKUs.
2226
*/
2327
public async getSKUs(applicationId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
2428
return this.rest.get(Routes.skus(applicationId), { signal }) as Promise<RESTGetAPISKUsResult>;
2529
}
2630

31+
/**
32+
* Fetches subscriptions for an SKU.
33+
*
34+
* @see {@link https://discord.com/developers/docs/resources/subscription#list-sku-subscriptions}
35+
* @param skuId - The SKU id to fetch subscriptions for
36+
* @param query - The query options for fetching subscriptions
37+
* @param options - The options for fetching subscriptions
38+
*/
39+
public async getSKUSubscriptions(
40+
skuId: Snowflake,
41+
query: RESTGetAPISKUSubscriptionsQuery,
42+
{ signal }: Pick<RequestData, 'signal'> = {},
43+
) {
44+
return this.rest.get(Routes.skuSubscriptions(skuId), {
45+
signal,
46+
query: makeURLSearchParams(query),
47+
}) as Promise<RESTGetAPISKUSubscriptionsResult>;
48+
}
49+
50+
/**
51+
* Fetches a subscription for an SKU.
52+
*
53+
* @see {@link https://discord.com/developers/docs/resources/subscription#get-sku-subscription}
54+
* @param skuId - The SKU id to fetch subscription for
55+
* @param subscriptionId - The subscription id to fetch
56+
* @param options - The options for fetching the subscription
57+
*/
58+
public async getSKUSubscription(
59+
skuId: Snowflake,
60+
subscriptionId: Snowflake,
61+
{ signal }: Pick<RequestData, 'signal'> = {},
62+
) {
63+
return this.rest.get(Routes.skuSubscription(skuId, subscriptionId), {
64+
signal,
65+
}) as Promise<RESTGetAPISKUSubscriptionResult>;
66+
}
67+
2768
/**
2869
* Fetches the entitlements for an application.
2970
*
30-
* @see {@link https://discord.com/developers/docs/monetization/entitlements#list-entitlements}
71+
* @see {@link https://discord.com/developers/docs/resources/entitlement#list-entitlements}
3172
* @param applicationId - The application id to fetch entitlements for
3273
* @param query - The query options for fetching entitlements
3374
* @param options - The options for fetching entitlements
@@ -46,7 +87,7 @@ export class MonetizationAPI {
4687
/**
4788
* Creates a test entitlement for an application's SKU.
4889
*
49-
* @see {@link https://discord.com/developers/docs/monetization/entitlements#create-test-entitlement}
90+
* @see {@link https://discord.com/developers/docs/resources/entitlement#create-test-entitlement}
5091
* @param applicationId - The application id to create the entitlement for
5192
* @param body - The data for creating the entitlement
5293
* @param options - The options for creating the entitlement
@@ -65,7 +106,7 @@ export class MonetizationAPI {
65106
/**
66107
* Deletes a test entitlement for an application's SKU.
67108
*
68-
* @see {@link https://discord.com/developers/docs/monetization/entitlements#delete-test-entitlement}
109+
* @see {@link https://discord.com/developers/docs/resources/entitlement#delete-test-entitlement}
69110
* @param applicationId - The application id to delete the entitlement for
70111
* @param entitlementId - The entitlement id to delete
71112
* @param options - The options for deleting the entitlement
@@ -81,7 +122,7 @@ export class MonetizationAPI {
81122
/**
82123
* Marks a given entitlement for the user as consumed. Only available for One-Time Purchase consumable SKUs.
83124
*
84-
* @see {@link https://discord.com/developers/docs/monetization/entitlements#consume-an-entitlement}
125+
* @see {@link https://discord.com/developers/docs/resources/entitlement#consume-an-entitlement}
85126
* @param applicationId - The application id to consume the entitlement for
86127
* @param entitlementId - The entitlement id to consume
87128
* @param options - The options for consuming the entitlement

packages/core/src/client.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ import {
6363
type GatewayStageInstanceCreateDispatchData,
6464
type GatewayStageInstanceDeleteDispatchData,
6565
type GatewayStageInstanceUpdateDispatchData,
66+
type GatewaySubscriptionCreateDispatchData,
67+
type GatewaySubscriptionDeleteDispatchData,
68+
type GatewaySubscriptionUpdateDispatchData,
6669
type GatewayThreadCreateDispatchData,
6770
type GatewayThreadDeleteDispatchData,
6871
type GatewayThreadListSyncDispatchData,
@@ -157,6 +160,9 @@ export interface MappedEvents {
157160
[GatewayDispatchEvents.StageInstanceCreate]: [ToEventProps<GatewayStageInstanceCreateDispatchData>];
158161
[GatewayDispatchEvents.StageInstanceDelete]: [ToEventProps<GatewayStageInstanceDeleteDispatchData>];
159162
[GatewayDispatchEvents.StageInstanceUpdate]: [ToEventProps<GatewayStageInstanceUpdateDispatchData>];
163+
[GatewayDispatchEvents.SubscriptionCreate]: [ToEventProps<GatewaySubscriptionCreateDispatchData>];
164+
[GatewayDispatchEvents.SubscriptionDelete]: [ToEventProps<GatewaySubscriptionDeleteDispatchData>];
165+
[GatewayDispatchEvents.SubscriptionUpdate]: [ToEventProps<GatewaySubscriptionUpdateDispatchData>];
160166
[GatewayDispatchEvents.ThreadCreate]: [ToEventProps<GatewayThreadCreateDispatchData>];
161167
[GatewayDispatchEvents.ThreadDelete]: [ToEventProps<GatewayThreadDeleteDispatchData>];
162168
[GatewayDispatchEvents.ThreadListSync]: [ToEventProps<GatewayThreadListSyncDispatchData>];

0 commit comments

Comments
 (0)