Skip to content

Commit 8f78190

Browse files
sdanialrazaTAEMBO
andauthored
feat: add subscriptions (#1078)
Co-authored-by: TÆMBØ <[email protected]>
1 parent 3f3fe21 commit 8f78190

File tree

16 files changed

+512
-40
lines changed

16 files changed

+512
-40
lines changed

deno/gateway/v10.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ export enum GatewayDispatchEvents {
278278
EntitlementCreate = 'ENTITLEMENT_CREATE',
279279
EntitlementUpdate = 'ENTITLEMENT_UPDATE',
280280
EntitlementDelete = 'ENTITLEMENT_DELETE',
281+
SubscriptionCreate = 'SUBSCRIPTION_CREATE',
282+
SubscriptionUpdate = 'SUBSCRIPTION_UPDATE',
283+
SubscriptionDelete = 'SUBSCRIPTION_DELETE',
281284
}
282285

283286
export type GatewaySendPayload =
@@ -709,7 +712,9 @@ export type GatewayEntitlementModifyDispatch = DataPayload<
709712
/**
710713
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
711714
*/
712-
export type GatewayEntitlementCreateDispatchData = GatewayEntitlementModifyDispatchData;
715+
export type GatewayEntitlementCreateDispatchData = Omit<GatewayEntitlementModifyDispatchData, 'ends_at'> & {
716+
ends_at: GatewayEntitlementModifyDispatchData['ends_at'] | null;
717+
};
713718

714719
/**
715720
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create

deno/gateway/v9.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ export enum GatewayDispatchEvents {
277277
EntitlementCreate = 'ENTITLEMENT_CREATE',
278278
EntitlementUpdate = 'ENTITLEMENT_UPDATE',
279279
EntitlementDelete = 'ENTITLEMENT_DELETE',
280+
SubscriptionCreate = 'SUBSCRIPTION_CREATE',
281+
SubscriptionUpdate = 'SUBSCRIPTION_UPDATE',
282+
SubscriptionDelete = 'SUBSCRIPTION_DELETE',
280283
}
281284

282285
export type GatewaySendPayload =
@@ -708,7 +711,9 @@ export type GatewayEntitlementModifyDispatch = DataPayload<
708711
/**
709712
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
710713
*/
711-
export type GatewayEntitlementCreateDispatchData = GatewayEntitlementModifyDispatchData;
714+
export type GatewayEntitlementCreateDispatchData = Omit<GatewayEntitlementModifyDispatchData, 'ends_at'> & {
715+
ends_at: GatewayEntitlementModifyDispatchData['ends_at'] | null;
716+
};
712717

713718
/**
714719
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create

deno/payloads/v10/monetization.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ export enum SKUFlags {
135135
UserSubscription = 1 << 8,
136136
}
137137

138+
/**
139+
* https://discord.com/developers/docs/resources/sku#sku-object-sku-types
140+
*/
138141
export enum SKUType {
139142
/**
140143
* Durable one-time purchase
@@ -153,3 +156,63 @@ export enum SKUType {
153156
*/
154157
SubscriptionGroup = 6,
155158
}
159+
160+
/**
161+
* https://discord.com/developers/docs/resources/subscription#subscription-object
162+
*/
163+
export interface APISubscription {
164+
/**
165+
* ID of the subscription
166+
*/
167+
id: Snowflake;
168+
/**
169+
* ID of the user who is subscribed
170+
*/
171+
user_id: Snowflake;
172+
/**
173+
* List of SKUs subscribed to
174+
*/
175+
sku_ids: Snowflake[];
176+
/**
177+
* List of entitlements granted for this subscription
178+
*/
179+
entitlement_ids: Snowflake[];
180+
/**
181+
* Start of the current subscription period
182+
*/
183+
current_period_start: string;
184+
/**
185+
* End of the current subscription period
186+
*/
187+
current_period_end: string;
188+
/**
189+
* Current status of the subscription
190+
*/
191+
status: SubscriptionStatus;
192+
/**
193+
* When the subscription was canceled
194+
*/
195+
canceled_at: string | null;
196+
/**
197+
* ISO3166-1 alpha-2 country code of the payment source used to purchase the subscription. Missing unless queried with a private OAuth scope.
198+
*/
199+
country?: string;
200+
}
201+
202+
/**
203+
* https://discord.com/developers/docs/resources/subscription#subscription-statuses
204+
*/
205+
export enum SubscriptionStatus {
206+
/**
207+
* Subscription is active and scheduled to renew.
208+
*/
209+
Active,
210+
/**
211+
* Subscription is active but will not renew.
212+
*/
213+
Ending,
214+
/**
215+
* Subscription is inactive and not being charged.
216+
*/
217+
Inactive,
218+
}

deno/payloads/v9/monetization.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ export enum SKUFlags {
135135
UserSubscription = 1 << 8,
136136
}
137137

138+
/**
139+
* https://discord.com/developers/docs/resources/sku#sku-object-sku-types
140+
*/
138141
export enum SKUType {
139142
/**
140143
* Durable one-time purchase
@@ -153,3 +156,63 @@ export enum SKUType {
153156
*/
154157
SubscriptionGroup = 6,
155158
}
159+
160+
/**
161+
* https://discord.com/developers/docs/resources/subscription#subscription-object
162+
*/
163+
export interface APISubscription {
164+
/**
165+
* ID of the subscription
166+
*/
167+
id: Snowflake;
168+
/**
169+
* ID of the user who is subscribed
170+
*/
171+
user_id: Snowflake;
172+
/**
173+
* List of SKUs subscribed to
174+
*/
175+
sku_ids: Snowflake[];
176+
/**
177+
* List of entitlements granted for this subscription
178+
*/
179+
entitlement_ids: Snowflake[];
180+
/**
181+
* Start of the current subscription period
182+
*/
183+
current_period_start: string;
184+
/**
185+
* End of the current subscription period
186+
*/
187+
current_period_end: string;
188+
/**
189+
* Current status of the subscription
190+
*/
191+
status: SubscriptionStatus;
192+
/**
193+
* When the subscription was canceled
194+
*/
195+
canceled_at: string | null;
196+
/**
197+
* ISO3166-1 alpha-2 country code of the payment source used to purchase the subscription. Missing unless queried with a private OAuth scope.
198+
*/
199+
country?: string;
200+
}
201+
202+
/**
203+
* https://discord.com/developers/docs/resources/subscription#subscription-statuses
204+
*/
205+
export enum SubscriptionStatus {
206+
/**
207+
* Subscription is active and scheduled to renew.
208+
*/
209+
Active,
210+
/**
211+
* Subscription is active but will not renew.
212+
*/
213+
Ending,
214+
/**
215+
* Subscription is inactive and not being charged.
216+
*/
217+
Inactive,
218+
}

deno/rest/v10/mod.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,22 @@ export const Routes = {
999999
applicationEmoji(applicationId: Snowflake, emojiId: Snowflake) {
10001000
return `/applications/${applicationId}/emojis/${emojiId}` as const;
10011001
},
1002+
1003+
/**
1004+
* Route for:
1005+
* - GET `/skus/{sku.id}/subscriptions`
1006+
*/
1007+
skuSubscriptions(skuId: Snowflake) {
1008+
return `/skus/${skuId}/subscriptions` as const;
1009+
},
1010+
1011+
/**
1012+
* Route for:
1013+
* - GET `/skus/{sku.id}/subscriptions/${subscription.id}`
1014+
*/
1015+
skuSubscription(skuId: Snowflake, subscriptionId: Snowflake) {
1016+
return `/skus/${skuId}/subscriptions/${subscriptionId}` as const;
1017+
},
10021018
};
10031019

10041020
export const StickerPackApplicationId = '710982414301790216';

deno/rest/v10/monetization.ts

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { Snowflake } from '../../globals.ts';
2-
import type { APIEntitlement, APISKU } from '../../v10.ts';
2+
import type { APIEntitlement, APISKU, APISubscription } from '../../v10.ts';
33

44
/**
5-
* https://discord.com/developers/docs/monetization/entitlements#list-entitlements
5+
* https://discord.com/developers/docs/resources/entitlement#list-entitlements
66
*/
77
export interface RESTGetAPIEntitlementsQuery {
88
/**
@@ -39,12 +39,12 @@ export interface RESTGetAPIEntitlementsQuery {
3939
}
4040

4141
/**
42-
* https://discord.com/developers/docs/monetization/entitlements#list-entitlements
42+
* https://discord.com/developers/docs/resources/entitlement#list-entitlements
4343
*/
4444
export type RESTGetAPIEntitlementsResult = APIEntitlement[];
4545

4646
/**
47-
* https://discord.com/developers/docs/monetization/entitlements#create-test-entitlement
47+
* https://discord.com/developers/docs/resources/entitlement#create-test-entitlement
4848
*/
4949
export interface RESTPostAPIEntitlementJSONBody {
5050
/**
@@ -67,29 +67,63 @@ export interface RESTPostAPIEntitlementJSONBody {
6767
export type RESTPostAPIEntitlementBody = RESTPostAPIEntitlementJSONBody;
6868

6969
/**
70-
* https://discord.com/developers/docs/monetization/entitlements#create-test-entitlement
70+
* https://discord.com/developers/docs/resources/entitlement#create-test-entitlement
7171
*/
7272
export type RESTPostAPIEntitlementResult = Partial<Omit<APIEntitlement, 'ends_at' | 'starts_at'>>;
7373

7474
/**
75-
* https://discord.com/developers/docs/monetization/entitlements#create-test-entitlement
75+
* https://discord.com/developers/docs/resources/entitlement#create-test-entitlement
7676
*/
7777
export enum EntitlementOwnerType {
7878
Guild = 1,
7979
User,
8080
}
8181

8282
/**
83-
* https://discord.com/developers/docs/monetization/entitlements#delete-test-entitlement
83+
* https://discord.com/developers/docs/resources/entitlement#delete-test-entitlement
8484
*/
8585
export type RESTDeleteAPIEntitlementResult = never;
8686

8787
/**
88-
* https://discord.com/developers/docs/monetization/skus#list-skus
88+
* https://discord.com/developers/docs/resources/sku#list-skus
8989
*/
9090
export type RESTGetAPISKUsResult = APISKU[];
9191

9292
/**
93-
* https://discord.com/developers/docs/monetization/entitlements#consume-an-entitlement
93+
* https://discord.com/developers/docs/resources/entitlement#consume-an-entitlement
9494
*/
9595
export type RESTPostAPIEntitlementConsumeResult = never;
96+
97+
/**
98+
* https://discord.com/developers/docs/resources/subscription#query-string-params
99+
*/
100+
export interface RESTGetAPISKUSubscriptionsQuery {
101+
/**
102+
* List subscriptions before this ID
103+
*/
104+
before?: Snowflake | undefined;
105+
/**
106+
* List subscriptions after this ID
107+
*/
108+
after?: Snowflake | undefined;
109+
/**
110+
* Number of subscriptions to return (1-100)
111+
*
112+
* @default 50
113+
*/
114+
limit?: number | undefined;
115+
/**
116+
* User ID for which to return subscriptions. Required except for OAuth queries.
117+
*/
118+
user_id?: Snowflake | undefined;
119+
}
120+
121+
/**
122+
* https://discord.com/developers/docs/resources/subscription#list-sku-subscriptions
123+
*/
124+
export type RESTGetAPISKUSubscriptionsResult = APISubscription[];
125+
126+
/**
127+
* https://discord.com/developers/docs/resources/subscription#get-sku-subscription
128+
*/
129+
export type RESTGetAPISKUSubscriptionResult = APISubscription;

deno/rest/v9/mod.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,22 @@ export const Routes = {
10081008
applicationEmoji(applicationId: Snowflake, emojiId: Snowflake) {
10091009
return `/applications/${applicationId}/emojis/${emojiId}` as const;
10101010
},
1011+
1012+
/**
1013+
* Route for:
1014+
* - GET `/skus/{sku.id}/subscriptions`
1015+
*/
1016+
skuSubscriptions(skuId: Snowflake) {
1017+
return `/skus/${skuId}/subscriptions` as const;
1018+
},
1019+
1020+
/**
1021+
* Route for:
1022+
* - GET `/skus/{sku.id}/subscriptions/${subscription.id}`
1023+
*/
1024+
skuSubscription(skuId: Snowflake, subscriptionId: Snowflake) {
1025+
return `/skus/${skuId}/subscriptions/${subscriptionId}` as const;
1026+
},
10111027
};
10121028

10131029
export const StickerPackApplicationId = '710982414301790216';

0 commit comments

Comments
 (0)