discord.js 15.0.0-dev.1732752781-e89c6b66a → 15.0.0-dev.1732795515-2b0944a92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -5
- package/src/client/websocket/handlers/SUBSCRIPTION_CREATE.js +14 -0
- package/src/client/websocket/handlers/SUBSCRIPTION_DELETE.js +16 -0
- package/src/client/websocket/handlers/SUBSCRIPTION_UPDATE.js +16 -0
- package/src/client/websocket/handlers/index.js +3 -0
- package/src/index.js +5 -0
- package/src/managers/SubscriptionManager.js +81 -0
- package/src/structures/ClientApplication.js +7 -0
- package/src/structures/Entitlement.js +2 -6
- package/src/structures/InteractionCallback.js +74 -0
- package/src/structures/InteractionCallbackResource.js +52 -0
- package/src/structures/InteractionCallbackResponse.js +33 -0
- package/src/structures/Subscription.js +109 -0
- package/src/structures/interfaces/InteractionResponses.js +48 -22
- package/src/util/Events.js +6 -0
- package/typings/index.d.mts +117 -21
- package/typings/index.d.ts +117 -21
- package/typings/index.test-d.ts +38 -43
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "discord.js",
|
|
4
|
-
"version": "15.0.0-dev.
|
|
4
|
+
"version": "15.0.0-dev.1732795515-2b0944a92",
|
|
5
5
|
"description": "A powerful library for interacting with the Discord API",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"types": "./typings/index.d.ts",
|
|
@@ -61,9 +61,9 @@
|
|
|
61
61
|
"tslib": "^2.8.1",
|
|
62
62
|
"undici": "6.21.0",
|
|
63
63
|
"@discordjs/formatters": "^0.5.0",
|
|
64
|
-
"@discordjs/
|
|
64
|
+
"@discordjs/rest": "^2.4.0",
|
|
65
65
|
"@discordjs/util": "^1.1.1",
|
|
66
|
-
"@discordjs/
|
|
66
|
+
"@discordjs/ws": "^2.0.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@favware/cliff-jumper": "^4.1.0",
|
|
@@ -80,9 +80,9 @@
|
|
|
80
80
|
"tslint": "6.1.3",
|
|
81
81
|
"turbo": "^2.3.0",
|
|
82
82
|
"typescript": "~5.5.4",
|
|
83
|
-
"@discordjs/api-extractor": "^7.38.1",
|
|
84
83
|
"@discordjs/docgen": "^0.12.1",
|
|
85
|
-
"@discordjs/scripts": "^0.1.0"
|
|
84
|
+
"@discordjs/scripts": "^0.1.0",
|
|
85
|
+
"@discordjs/api-extractor": "^7.38.1"
|
|
86
86
|
},
|
|
87
87
|
"engines": {
|
|
88
88
|
"node": ">=20"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Events = require('../../../util/Events');
|
|
4
|
+
|
|
5
|
+
module.exports = (client, { d: data }) => {
|
|
6
|
+
const subscription = client.application.subscriptions._add(data);
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Emitted whenever a subscription is created.
|
|
10
|
+
* @event Client#subscriptionCreate
|
|
11
|
+
* @param {Subscription} subscription The subscription that was created
|
|
12
|
+
*/
|
|
13
|
+
client.emit(Events.SubscriptionCreate, subscription);
|
|
14
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Events = require('../../../util/Events');
|
|
4
|
+
|
|
5
|
+
module.exports = (client, { d: data }) => {
|
|
6
|
+
const subscription = client.application.subscriptions._add(data, false);
|
|
7
|
+
|
|
8
|
+
client.application.subscriptions.cache.delete(subscription.id);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Emitted whenever a subscription is deleted.
|
|
12
|
+
* @event Client#subscriptionDelete
|
|
13
|
+
* @param {Subscription} subscription The subscription that was deleted
|
|
14
|
+
*/
|
|
15
|
+
client.emit(Events.SubscriptionDelete, subscription);
|
|
16
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Events = require('../../../util/Events');
|
|
4
|
+
|
|
5
|
+
module.exports = (client, { d: data }) => {
|
|
6
|
+
const oldSubscription = client.application.subscriptions.cache.get(data.id)?._clone() ?? null;
|
|
7
|
+
const newSubscription = client.application.subscriptions._add(data);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Emitted whenever a subscription is updated - i.e. when a user's subscription renews.
|
|
11
|
+
* @event Client#subscriptionUpdate
|
|
12
|
+
* @param {?Subscription} oldSubscription The subscription before the update
|
|
13
|
+
* @param {Subscription} newSubscription The subscription after the update
|
|
14
|
+
*/
|
|
15
|
+
client.emit(Events.SubscriptionUpdate, oldSubscription, newSubscription);
|
|
16
|
+
};
|
|
@@ -52,6 +52,9 @@ const handlers = Object.fromEntries([
|
|
|
52
52
|
['STAGE_INSTANCE_CREATE', require('./STAGE_INSTANCE_CREATE')],
|
|
53
53
|
['STAGE_INSTANCE_DELETE', require('./STAGE_INSTANCE_DELETE')],
|
|
54
54
|
['STAGE_INSTANCE_UPDATE', require('./STAGE_INSTANCE_UPDATE')],
|
|
55
|
+
['SUBSCRIPTION_CREATE', require('./SUBSCRIPTION_CREATE')],
|
|
56
|
+
['SUBSCRIPTION_DELETE', require('./SUBSCRIPTION_DELETE')],
|
|
57
|
+
['SUBSCRIPTION_UPDATE', require('./SUBSCRIPTION_UPDATE')],
|
|
55
58
|
['THREAD_CREATE', require('./THREAD_CREATE')],
|
|
56
59
|
['THREAD_DELETE', require('./THREAD_DELETE')],
|
|
57
60
|
['THREAD_LIST_SYNC', require('./THREAD_LIST_SYNC')],
|
package/src/index.js
CHANGED
|
@@ -83,6 +83,7 @@ exports.ReactionManager = require('./managers/ReactionManager');
|
|
|
83
83
|
exports.ReactionUserManager = require('./managers/ReactionUserManager');
|
|
84
84
|
exports.RoleManager = require('./managers/RoleManager');
|
|
85
85
|
exports.StageInstanceManager = require('./managers/StageInstanceManager');
|
|
86
|
+
exports.SubscriptionManager = require('./managers/SubscriptionManager').SubscriptionManager;
|
|
86
87
|
exports.ThreadManager = require('./managers/ThreadManager');
|
|
87
88
|
exports.ThreadMemberManager = require('./managers/ThreadMemberManager');
|
|
88
89
|
exports.UserManager = require('./managers/UserManager');
|
|
@@ -142,6 +143,9 @@ exports.GuildScheduledEvent = require('./structures/GuildScheduledEvent').GuildS
|
|
|
142
143
|
exports.GuildTemplate = require('./structures/GuildTemplate');
|
|
143
144
|
exports.Integration = require('./structures/Integration');
|
|
144
145
|
exports.IntegrationApplication = require('./structures/IntegrationApplication');
|
|
146
|
+
exports.InteractionCallback = require('./structures/InteractionCallback');
|
|
147
|
+
exports.InteractionCallbackResource = require('./structures/InteractionCallbackResource');
|
|
148
|
+
exports.InteractionCallbackResponse = require('./structures/InteractionCallbackResponse');
|
|
145
149
|
exports.BaseInteraction = require('./structures/BaseInteraction');
|
|
146
150
|
exports.InteractionCollector = require('./structures/InteractionCollector');
|
|
147
151
|
exports.InteractionResponse = require('./structures/InteractionResponse');
|
|
@@ -193,6 +197,7 @@ exports.SKU = require('./structures/SKU').SKU;
|
|
|
193
197
|
exports.StringSelectMenuOptionBuilder = require('./structures/StringSelectMenuOptionBuilder');
|
|
194
198
|
exports.StageChannel = require('./structures/StageChannel');
|
|
195
199
|
exports.StageInstance = require('./structures/StageInstance').StageInstance;
|
|
200
|
+
exports.Subscription = require('./structures/Subscription').Subscription;
|
|
196
201
|
exports.Sticker = require('./structures/Sticker').Sticker;
|
|
197
202
|
exports.StickerPack = require('./structures/StickerPack');
|
|
198
203
|
exports.Team = require('./structures/Team');
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { Collection } = require('@discordjs/collection');
|
|
4
|
+
const { makeURLSearchParams } = require('@discordjs/rest');
|
|
5
|
+
const { Routes } = require('discord-api-types/v10');
|
|
6
|
+
const CachedManager = require('./CachedManager');
|
|
7
|
+
const { DiscordjsTypeError, ErrorCodes } = require('../errors/index');
|
|
8
|
+
const { Subscription } = require('../structures/Subscription');
|
|
9
|
+
const { resolveSKUId } = require('../util/Util');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Manages API methods for subscriptions and stores their cache.
|
|
13
|
+
* @extends {CachedManager}
|
|
14
|
+
*/
|
|
15
|
+
class SubscriptionManager extends CachedManager {
|
|
16
|
+
constructor(client, iterable) {
|
|
17
|
+
super(client, Subscription, iterable);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The cache of this manager
|
|
22
|
+
* @type {Collection<Snowflake, Subscription>}
|
|
23
|
+
* @name SubscriptionManager#cache
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Options used to fetch a subscription
|
|
28
|
+
* @typedef {BaseFetchOptions} FetchSubscriptionOptions
|
|
29
|
+
* @property {SKUResolvable} sku The SKU to fetch the subscription for
|
|
30
|
+
* @property {Snowflake} subscriptionId The id of the subscription to fetch
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Options used to fetch subscriptions
|
|
35
|
+
* @typedef {Object} FetchSubscriptionsOptions
|
|
36
|
+
* @property {Snowflake} [after] Consider only subscriptions after this subscription id
|
|
37
|
+
* @property {Snowflake} [before] Consider only subscriptions before this subscription id
|
|
38
|
+
* @property {number} [limit] The maximum number of subscriptions to fetch
|
|
39
|
+
* @property {SKUResolvable} sku The SKU to fetch subscriptions for
|
|
40
|
+
* @property {UserResolvable} user The user to fetch entitlements for
|
|
41
|
+
* <warn>If both `before` and `after` are provided, only `before` is respected</warn>
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Fetches subscriptions for this application
|
|
46
|
+
* @param {FetchSubscriptionOptions|FetchSubscriptionsOptions} [options={}] Options for fetching the subscriptions
|
|
47
|
+
* @returns {Promise<Subscription|Collection<Snowflake, Subscription>>}
|
|
48
|
+
*/
|
|
49
|
+
async fetch(options = {}) {
|
|
50
|
+
if (typeof options !== 'object') throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true);
|
|
51
|
+
|
|
52
|
+
const { after, before, cache, limit, sku, subscriptionId, user } = options;
|
|
53
|
+
|
|
54
|
+
const skuId = resolveSKUId(sku);
|
|
55
|
+
|
|
56
|
+
if (!skuId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'sku', 'SKUResolvable');
|
|
57
|
+
|
|
58
|
+
if (subscriptionId) {
|
|
59
|
+
const subscription = await this.client.rest.get(Routes.skuSubscription(skuId, subscriptionId));
|
|
60
|
+
|
|
61
|
+
return this._add(subscription, cache);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const query = makeURLSearchParams({
|
|
65
|
+
limit,
|
|
66
|
+
user_id: this.client.users.resolveId(user) ?? undefined,
|
|
67
|
+
sku_id: skuId,
|
|
68
|
+
before,
|
|
69
|
+
after,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const subscriptions = await this.client.rest.get(Routes.skuSubscriptions(skuId), { query });
|
|
73
|
+
|
|
74
|
+
return subscriptions.reduce(
|
|
75
|
+
(coll, subscription) => coll.set(subscription.id, this._add(subscription, cache)),
|
|
76
|
+
new Collection(),
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
exports.SubscriptionManager = SubscriptionManager;
|
|
@@ -9,6 +9,7 @@ const Application = require('./interfaces/Application');
|
|
|
9
9
|
const ApplicationCommandManager = require('../managers/ApplicationCommandManager');
|
|
10
10
|
const ApplicationEmojiManager = require('../managers/ApplicationEmojiManager');
|
|
11
11
|
const { EntitlementManager } = require('../managers/EntitlementManager');
|
|
12
|
+
const { SubscriptionManager } = require('../managers/SubscriptionManager');
|
|
12
13
|
const ApplicationFlagsBitField = require('../util/ApplicationFlagsBitField');
|
|
13
14
|
const { resolveImage } = require('../util/DataResolver');
|
|
14
15
|
const PermissionsBitField = require('../util/PermissionsBitField');
|
|
@@ -44,6 +45,12 @@ class ClientApplication extends Application {
|
|
|
44
45
|
* @type {EntitlementManager}
|
|
45
46
|
*/
|
|
46
47
|
this.entitlements = new EntitlementManager(this.client);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The subscription manager for this application
|
|
51
|
+
* @type {SubscriptionManager}
|
|
52
|
+
*/
|
|
53
|
+
this.subscriptions = new SubscriptionManager(this.client);
|
|
47
54
|
}
|
|
48
55
|
|
|
49
56
|
_patch(data) {
|
|
@@ -73,10 +73,9 @@ class Entitlement extends Base {
|
|
|
73
73
|
if ('starts_at' in data) {
|
|
74
74
|
/**
|
|
75
75
|
* The timestamp at which this entitlement is valid
|
|
76
|
-
* <info>This is only `null` for test entitlements</info>
|
|
77
76
|
* @type {?number}
|
|
78
77
|
*/
|
|
79
|
-
this.startsTimestamp = Date.parse(data.starts_at);
|
|
78
|
+
this.startsTimestamp = data.starts_at ? Date.parse(data.starts_at) : null;
|
|
80
79
|
} else {
|
|
81
80
|
this.startsTimestamp ??= null;
|
|
82
81
|
}
|
|
@@ -84,10 +83,9 @@ class Entitlement extends Base {
|
|
|
84
83
|
if ('ends_at' in data) {
|
|
85
84
|
/**
|
|
86
85
|
* The timestamp at which this entitlement is no longer valid
|
|
87
|
-
* <info>This is only `null` for test entitlements</info>
|
|
88
86
|
* @type {?number}
|
|
89
87
|
*/
|
|
90
|
-
this.endsTimestamp = Date.parse(data.ends_at);
|
|
88
|
+
this.endsTimestamp = data.ends_at ? Date.parse(data.ends_at) : null;
|
|
91
89
|
} else {
|
|
92
90
|
this.endsTimestamp ??= null;
|
|
93
91
|
}
|
|
@@ -114,7 +112,6 @@ class Entitlement extends Base {
|
|
|
114
112
|
|
|
115
113
|
/**
|
|
116
114
|
* The start date at which this entitlement is valid
|
|
117
|
-
* <info>This is only `null` for test entitlements</info>
|
|
118
115
|
* @type {?Date}
|
|
119
116
|
*/
|
|
120
117
|
get startsAt() {
|
|
@@ -123,7 +120,6 @@ class Entitlement extends Base {
|
|
|
123
120
|
|
|
124
121
|
/**
|
|
125
122
|
* The end date at which this entitlement is no longer valid
|
|
126
|
-
* <info>This is only `null` for test entitlements</info>
|
|
127
123
|
* @type {?Date}
|
|
128
124
|
*/
|
|
129
125
|
get endsAt() {
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { DiscordSnowflake } = require('@sapphire/snowflake');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Represents an interaction callback response from Discord
|
|
7
|
+
*/
|
|
8
|
+
class InteractionCallback {
|
|
9
|
+
constructor(client, data) {
|
|
10
|
+
/**
|
|
11
|
+
* The client that instantiated this.
|
|
12
|
+
* @name InteractionCallback#client
|
|
13
|
+
* @type {Client}
|
|
14
|
+
* @readonly
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(this, 'client', { value: client });
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The id of the original interaction response
|
|
20
|
+
* @type {Snowflake}
|
|
21
|
+
*/
|
|
22
|
+
this.id = data.id;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The type of the original interaction
|
|
26
|
+
* @type {InteractionType}
|
|
27
|
+
*/
|
|
28
|
+
this.type = data.type;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The instance id of the Activity if one was launched or joined
|
|
32
|
+
* @type {?string}
|
|
33
|
+
*/
|
|
34
|
+
this.activityInstanceId = data.activity_instance_id ?? null;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The id of the message that was created by the interaction
|
|
38
|
+
* @type {?Snowflake}
|
|
39
|
+
*/
|
|
40
|
+
this.responseMessageId = data.response_message_id ?? null;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Whether the message is in a loading state
|
|
44
|
+
* @type {?boolean}
|
|
45
|
+
*/
|
|
46
|
+
this.responseMessageLoading = data.response_message_loading ?? null;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Whether the response message was ephemeral
|
|
50
|
+
* @type {?boolean}
|
|
51
|
+
*/
|
|
52
|
+
this.responseMessageEphemeral = data.response_message_ephemeral ?? null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The timestamp the original interaction was created at
|
|
57
|
+
* @type {number}
|
|
58
|
+
* @readonly
|
|
59
|
+
*/
|
|
60
|
+
get createdTimestamp() {
|
|
61
|
+
return DiscordSnowflake.timestampFrom(this.id);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The time the original interaction was created at
|
|
66
|
+
* @type {Date}
|
|
67
|
+
* @readonly
|
|
68
|
+
*/
|
|
69
|
+
get createdAt() {
|
|
70
|
+
return new Date(this.createdTimestamp);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports = InteractionCallback;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { lazy } = require('@discordjs/util');
|
|
4
|
+
|
|
5
|
+
const getMessage = lazy(() => require('./Message').Message);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Represents the resource that was created by the interaction response.
|
|
9
|
+
*/
|
|
10
|
+
class InteractionCallbackResource {
|
|
11
|
+
constructor(client, data) {
|
|
12
|
+
/**
|
|
13
|
+
* The client that instantiated this
|
|
14
|
+
* @name InteractionCallbackResource#client
|
|
15
|
+
* @type {Client}
|
|
16
|
+
* @readonly
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(this, 'client', { value: client });
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The interaction callback type
|
|
22
|
+
* @type {InteractionResponseType}
|
|
23
|
+
*/
|
|
24
|
+
this.type = data.type;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The Activity launched by an interaction
|
|
28
|
+
* @typedef {Object} ActivityInstance
|
|
29
|
+
* @property {string} id The instance id of the Activity
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Represents the Activity launched by this interaction
|
|
34
|
+
* @type {?ActivityInstance}
|
|
35
|
+
*/
|
|
36
|
+
this.activityInstance = data.activity_instance ?? null;
|
|
37
|
+
|
|
38
|
+
if ('message' in data) {
|
|
39
|
+
/**
|
|
40
|
+
* The message created by the interaction
|
|
41
|
+
* @type {?Message}
|
|
42
|
+
*/
|
|
43
|
+
this.message =
|
|
44
|
+
this.client.channels.cache.get(data.message.channel_id)?.messages._add(data.message) ??
|
|
45
|
+
new (getMessage())(client, data.message);
|
|
46
|
+
} else {
|
|
47
|
+
this.message = null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = InteractionCallbackResource;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const InteractionCallback = require('./InteractionCallback');
|
|
4
|
+
const InteractionCallbackResource = require('./InteractionCallbackResource');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents an interaction's response
|
|
8
|
+
*/
|
|
9
|
+
class InteractionCallbackResponse {
|
|
10
|
+
constructor(client, data) {
|
|
11
|
+
/**
|
|
12
|
+
* The client that instantiated this
|
|
13
|
+
* @name InteractionCallbackResponse#client
|
|
14
|
+
* @type {Client}
|
|
15
|
+
* @readonly
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(this, 'client', { value: client });
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The interaction object associated with the interaction callback response
|
|
21
|
+
* @type {InteractionCallback}
|
|
22
|
+
*/
|
|
23
|
+
this.interaction = new InteractionCallback(client, data.interaction);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The resource that was created by the interaction response
|
|
27
|
+
* @type {?InteractionCallbackResource}
|
|
28
|
+
*/
|
|
29
|
+
this.resource = data.resource ? new InteractionCallbackResource(client, data.resource) : null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = InteractionCallbackResponse;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Base = require('./Base');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Represents a Subscription
|
|
7
|
+
* @extends {Base}
|
|
8
|
+
*/
|
|
9
|
+
class Subscription extends Base {
|
|
10
|
+
constructor(client, data) {
|
|
11
|
+
super(client);
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The id of the subscription
|
|
15
|
+
* @type {Snowflake}
|
|
16
|
+
*/
|
|
17
|
+
this.id = data.id;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The id of the user who subscribed
|
|
21
|
+
* @type {Snowflake}
|
|
22
|
+
*/
|
|
23
|
+
this.userId = data.user_id;
|
|
24
|
+
|
|
25
|
+
this._patch(data);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
_patch(data) {
|
|
29
|
+
/**
|
|
30
|
+
* The SKU ids subscribed to
|
|
31
|
+
* @type {Snowflake[]}
|
|
32
|
+
*/
|
|
33
|
+
this.skuIds = data.sku_ids;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The entitlement ids granted for this subscription
|
|
37
|
+
* @type {Snowflake[]}
|
|
38
|
+
*/
|
|
39
|
+
this.entitlementIds = data.entitlement_ids;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The timestamp the current subscription period will start at
|
|
43
|
+
* @type {number}
|
|
44
|
+
*/
|
|
45
|
+
this.currentPeriodStartTimestamp = Date.parse(data.current_period_start);
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The timestamp the current subscription period will end at
|
|
49
|
+
* @type {number}
|
|
50
|
+
*/
|
|
51
|
+
this.currentPeriodEndTimestamp = Date.parse(data.current_period_end);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The current status of the subscription
|
|
55
|
+
* @type {SubscriptionStatus}
|
|
56
|
+
*/
|
|
57
|
+
this.status = data.status;
|
|
58
|
+
|
|
59
|
+
if ('canceled_at' in data) {
|
|
60
|
+
/**
|
|
61
|
+
* The timestamp of when the subscription was canceled
|
|
62
|
+
* @type {?number}
|
|
63
|
+
*/
|
|
64
|
+
this.canceledTimestamp = data.canceled_at ? Date.parse(data.canceled_at) : null;
|
|
65
|
+
} else {
|
|
66
|
+
this.canceledTimestamp ??= null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if ('country' in data) {
|
|
70
|
+
/**
|
|
71
|
+
* ISO 3166-1 alpha-2 country code of the payment source used to purchase the subscription.
|
|
72
|
+
* Missing unless queried with a private OAuth scope.
|
|
73
|
+
* @type {?string}
|
|
74
|
+
*/
|
|
75
|
+
this.country = data.country;
|
|
76
|
+
} else {
|
|
77
|
+
this.country ??= null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The time the subscription was canceled
|
|
83
|
+
* @type {?Date}
|
|
84
|
+
* @readonly
|
|
85
|
+
*/
|
|
86
|
+
get canceledAt() {
|
|
87
|
+
return this.canceledTimestamp && new Date(this.canceledTimestamp);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The time the current subscription period will start at
|
|
92
|
+
* @type {Date}
|
|
93
|
+
* @readonly
|
|
94
|
+
*/
|
|
95
|
+
get currentPeriodStartAt() {
|
|
96
|
+
return new Date(this.currentPeriodStartTimestamp);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The time the current subscription period will end at
|
|
101
|
+
* @type {Date}
|
|
102
|
+
* @readonly
|
|
103
|
+
*/
|
|
104
|
+
get currentPeriodEndAt() {
|
|
105
|
+
return new Date(this.currentPeriodEndTimestamp);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
exports.Subscription = Subscription;
|