Skip to content

Commit

Permalink
feat: add subscriptions (#1078)
Browse files Browse the repository at this point in the history
Co-authored-by: TÆMBØ <[email protected]>
  • Loading branch information
sdanialraza and TAEMBO authored Sep 5, 2024
1 parent 3f3fe21 commit 8f78190
Show file tree
Hide file tree
Showing 16 changed files with 512 additions and 40 deletions.
7 changes: 6 additions & 1 deletion deno/gateway/v10.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ export enum GatewayDispatchEvents {
EntitlementCreate = 'ENTITLEMENT_CREATE',
EntitlementUpdate = 'ENTITLEMENT_UPDATE',
EntitlementDelete = 'ENTITLEMENT_DELETE',
SubscriptionCreate = 'SUBSCRIPTION_CREATE',
SubscriptionUpdate = 'SUBSCRIPTION_UPDATE',
SubscriptionDelete = 'SUBSCRIPTION_DELETE',
}

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

/**
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
Expand Down
7 changes: 6 additions & 1 deletion deno/gateway/v9.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ export enum GatewayDispatchEvents {
EntitlementCreate = 'ENTITLEMENT_CREATE',
EntitlementUpdate = 'ENTITLEMENT_UPDATE',
EntitlementDelete = 'ENTITLEMENT_DELETE',
SubscriptionCreate = 'SUBSCRIPTION_CREATE',
SubscriptionUpdate = 'SUBSCRIPTION_UPDATE',
SubscriptionDelete = 'SUBSCRIPTION_DELETE',
}

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

/**
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
Expand Down
63 changes: 63 additions & 0 deletions deno/payloads/v10/monetization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ export enum SKUFlags {
UserSubscription = 1 << 8,
}

/**
* https://discord.com/developers/docs/resources/sku#sku-object-sku-types
*/
export enum SKUType {
/**
* Durable one-time purchase
Expand All @@ -153,3 +156,63 @@ export enum SKUType {
*/
SubscriptionGroup = 6,
}

/**
* https://discord.com/developers/docs/resources/subscription#subscription-object
*/
export interface APISubscription {
/**
* ID of the subscription
*/
id: Snowflake;
/**
* ID of the user who is subscribed
*/
user_id: Snowflake;
/**
* List of SKUs subscribed to
*/
sku_ids: Snowflake[];
/**
* List of entitlements granted for this subscription
*/
entitlement_ids: Snowflake[];
/**
* Start of the current subscription period
*/
current_period_start: string;
/**
* End of the current subscription period
*/
current_period_end: string;
/**
* Current status of the subscription
*/
status: SubscriptionStatus;
/**
* When the subscription was canceled
*/
canceled_at: string | null;
/**
* ISO3166-1 alpha-2 country code of the payment source used to purchase the subscription. Missing unless queried with a private OAuth scope.
*/
country?: string;
}

/**
* https://discord.com/developers/docs/resources/subscription#subscription-statuses
*/
export enum SubscriptionStatus {
/**
* Subscription is active and scheduled to renew.
*/
Active,
/**
* Subscription is active but will not renew.
*/
Ending,
/**
* Subscription is inactive and not being charged.
*/
Inactive,
}
63 changes: 63 additions & 0 deletions deno/payloads/v9/monetization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ export enum SKUFlags {
UserSubscription = 1 << 8,
}

/**
* https://discord.com/developers/docs/resources/sku#sku-object-sku-types
*/
export enum SKUType {
/**
* Durable one-time purchase
Expand All @@ -153,3 +156,63 @@ export enum SKUType {
*/
SubscriptionGroup = 6,
}

/**
* https://discord.com/developers/docs/resources/subscription#subscription-object
*/
export interface APISubscription {
/**
* ID of the subscription
*/
id: Snowflake;
/**
* ID of the user who is subscribed
*/
user_id: Snowflake;
/**
* List of SKUs subscribed to
*/
sku_ids: Snowflake[];
/**
* List of entitlements granted for this subscription
*/
entitlement_ids: Snowflake[];
/**
* Start of the current subscription period
*/
current_period_start: string;
/**
* End of the current subscription period
*/
current_period_end: string;
/**
* Current status of the subscription
*/
status: SubscriptionStatus;
/**
* When the subscription was canceled
*/
canceled_at: string | null;
/**
* ISO3166-1 alpha-2 country code of the payment source used to purchase the subscription. Missing unless queried with a private OAuth scope.
*/
country?: string;
}

/**
* https://discord.com/developers/docs/resources/subscription#subscription-statuses
*/
export enum SubscriptionStatus {
/**
* Subscription is active and scheduled to renew.
*/
Active,
/**
* Subscription is active but will not renew.
*/
Ending,
/**
* Subscription is inactive and not being charged.
*/
Inactive,
}
16 changes: 16 additions & 0 deletions deno/rest/v10/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,22 @@ export const Routes = {
applicationEmoji(applicationId: Snowflake, emojiId: Snowflake) {
return `/applications/${applicationId}/emojis/${emojiId}` as const;
},

/**
* Route for:
* - GET `/skus/{sku.id}/subscriptions`
*/
skuSubscriptions(skuId: Snowflake) {
return `/skus/${skuId}/subscriptions` as const;
},

/**
* Route for:
* - GET `/skus/{sku.id}/subscriptions/${subscription.id}`
*/
skuSubscription(skuId: Snowflake, subscriptionId: Snowflake) {
return `/skus/${skuId}/subscriptions/${subscriptionId}` as const;
},
};

export const StickerPackApplicationId = '710982414301790216';
Expand Down
52 changes: 43 additions & 9 deletions deno/rest/v10/monetization.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Snowflake } from '../../globals.ts';
import type { APIEntitlement, APISKU } from '../../v10.ts';
import type { APIEntitlement, APISKU, APISubscription } from '../../v10.ts';

/**
* https://discord.com/developers/docs/monetization/entitlements#list-entitlements
* https://discord.com/developers/docs/resources/entitlement#list-entitlements
*/
export interface RESTGetAPIEntitlementsQuery {
/**
Expand Down Expand Up @@ -39,12 +39,12 @@ export interface RESTGetAPIEntitlementsQuery {
}

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

/**
* https://discord.com/developers/docs/monetization/entitlements#create-test-entitlement
* https://discord.com/developers/docs/resources/entitlement#create-test-entitlement
*/
export interface RESTPostAPIEntitlementJSONBody {
/**
Expand All @@ -67,29 +67,63 @@ export interface RESTPostAPIEntitlementJSONBody {
export type RESTPostAPIEntitlementBody = RESTPostAPIEntitlementJSONBody;

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

/**
* https://discord.com/developers/docs/monetization/entitlements#create-test-entitlement
* https://discord.com/developers/docs/resources/entitlement#create-test-entitlement
*/
export enum EntitlementOwnerType {
Guild = 1,
User,
}

/**
* https://discord.com/developers/docs/monetization/entitlements#delete-test-entitlement
* https://discord.com/developers/docs/resources/entitlement#delete-test-entitlement
*/
export type RESTDeleteAPIEntitlementResult = never;

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

/**
* https://discord.com/developers/docs/monetization/entitlements#consume-an-entitlement
* https://discord.com/developers/docs/resources/entitlement#consume-an-entitlement
*/
export type RESTPostAPIEntitlementConsumeResult = never;

/**
* https://discord.com/developers/docs/resources/subscription#query-string-params
*/
export interface RESTGetAPISKUSubscriptionsQuery {
/**
* List subscriptions before this ID
*/
before?: Snowflake | undefined;
/**
* List subscriptions after this ID
*/
after?: Snowflake | undefined;
/**
* Number of subscriptions to return (1-100)
*
* @default 50
*/
limit?: number | undefined;
/**
* User ID for which to return subscriptions. Required except for OAuth queries.
*/
user_id?: Snowflake | undefined;
}

/**
* https://discord.com/developers/docs/resources/subscription#list-sku-subscriptions
*/
export type RESTGetAPISKUSubscriptionsResult = APISubscription[];

/**
* https://discord.com/developers/docs/resources/subscription#get-sku-subscription
*/
export type RESTGetAPISKUSubscriptionResult = APISubscription;
16 changes: 16 additions & 0 deletions deno/rest/v9/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,22 @@ export const Routes = {
applicationEmoji(applicationId: Snowflake, emojiId: Snowflake) {
return `/applications/${applicationId}/emojis/${emojiId}` as const;
},

/**
* Route for:
* - GET `/skus/{sku.id}/subscriptions`
*/
skuSubscriptions(skuId: Snowflake) {
return `/skus/${skuId}/subscriptions` as const;
},

/**
* Route for:
* - GET `/skus/{sku.id}/subscriptions/${subscription.id}`
*/
skuSubscription(skuId: Snowflake, subscriptionId: Snowflake) {
return `/skus/${skuId}/subscriptions/${subscriptionId}` as const;
},
};

export const StickerPackApplicationId = '710982414301790216';
Expand Down
Loading

0 comments on commit 8f78190

Please sign in to comment.