mini-interactions 0.0.0-stage → 0.15.0
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/LICENSE +21 -0
- package/MIGRATION.md +126 -0
- package/README.md +253 -2
- package/dist/bot.d.ts +58 -0
- package/dist/bot.js +217 -0
- package/dist/builders/ActionRowBuilder.d.ts +22 -0
- package/dist/builders/ActionRowBuilder.js +33 -0
- package/dist/builders/AutomodRuleBuilder.d.ts +45 -0
- package/dist/builders/AutomodRuleBuilder.js +151 -0
- package/dist/builders/ButtonBuilder.d.ts +53 -0
- package/dist/builders/ButtonBuilder.js +124 -0
- package/dist/builders/ChannelSelectMenuBuilder.d.ts +53 -0
- package/dist/builders/ChannelSelectMenuBuilder.js +105 -0
- package/dist/builders/CheckboxBuilder.d.ts +20 -0
- package/dist/builders/CheckboxBuilder.js +20 -0
- package/dist/builders/CheckboxGroupBuilder.d.ts +25 -0
- package/dist/builders/CheckboxGroupBuilder.js +48 -0
- package/dist/builders/EmbedBuilder.d.ts +33 -0
- package/dist/builders/EmbedBuilder.js +103 -0
- package/dist/builders/FileUploadBuilder.d.ts +17 -0
- package/dist/builders/FileUploadBuilder.js +22 -0
- package/dist/builders/LabelBuilder.d.ts +16 -0
- package/dist/builders/LabelBuilder.js +21 -0
- package/dist/builders/MiniContainerBuilder.d.ts +131 -0
- package/dist/builders/MiniContainerBuilder.js +347 -0
- package/dist/builders/ModalBuilder.d.ts +16 -0
- package/dist/builders/ModalBuilder.js +36 -0
- package/dist/builders/ModalChannelSelectMenuBuilder.d.ts +29 -0
- package/dist/builders/ModalChannelSelectMenuBuilder.js +25 -0
- package/dist/builders/ModalMentionableSelectMenuBuilder.d.ts +53 -0
- package/dist/builders/ModalMentionableSelectMenuBuilder.js +87 -0
- package/dist/builders/ModalRoleSelectMenuBuilder.d.ts +27 -0
- package/dist/builders/ModalRoleSelectMenuBuilder.js +24 -0
- package/dist/builders/ModalStringSelectMenuBuilder.d.ts +62 -0
- package/dist/builders/ModalStringSelectMenuBuilder.js +120 -0
- package/dist/builders/ModalUserSelectMenuBuilder.d.ts +53 -0
- package/dist/builders/ModalUserSelectMenuBuilder.js +96 -0
- package/dist/builders/RadioBuilder.d.ts +22 -0
- package/dist/builders/RadioBuilder.js +36 -0
- package/dist/builders/RoleSelectMenuBuilder.d.ts +47 -0
- package/dist/builders/RoleSelectMenuBuilder.js +92 -0
- package/dist/builders/StringSelectMenuBuilder.d.ts +52 -0
- package/dist/builders/StringSelectMenuBuilder.js +104 -0
- package/dist/builders/StringSelectMenuOptionBuilder.d.ts +46 -0
- package/dist/builders/StringSelectMenuOptionBuilder.js +106 -0
- package/dist/builders/TextInputBuilder.d.ts +23 -0
- package/dist/builders/TextInputBuilder.js +26 -0
- package/dist/builders/index.d.ts +44 -0
- package/dist/builders/index.js +22 -0
- package/dist/builders/shared.d.ts +8 -0
- package/dist/builders/shared.js +11 -0
- package/dist/commands/CommandBuilder.d.ts +278 -0
- package/dist/commands/CommandBuilder.js +687 -0
- package/dist/commands/ContextMenuCommandBuilder.d.ts +94 -0
- package/dist/commands/ContextMenuCommandBuilder.js +145 -0
- package/dist/core/http/DiscordRestClient.d.ts +400 -0
- package/dist/core/http/DiscordRestClient.js +988 -0
- package/dist/core/interactions/InteractionContext.d.ts +33 -0
- package/dist/core/interactions/InteractionContext.js +61 -0
- package/dist/core/interactions/InteractionVerifier.d.ts +8 -0
- package/dist/core/interactions/InteractionVerifier.js +9 -0
- package/dist/core/messages/DiscordSentMessage.d.ts +32 -0
- package/dist/core/messages/DiscordSentMessage.js +64 -0
- package/dist/core/messages/message-payloads.d.ts +94 -0
- package/dist/core/messages/message-payloads.js +99 -0
- package/dist/core/webhooks/DiscordWebhook.d.ts +14 -0
- package/dist/core/webhooks/DiscordWebhook.js +69 -0
- package/dist/database/MiniDataBuilder.d.ts +61 -0
- package/dist/database/MiniDataBuilder.js +98 -0
- package/dist/database/MiniDatabase.d.ts +67 -0
- package/dist/database/MiniDatabase.js +222 -0
- package/dist/database/MiniDatabaseBuilder.d.ts +58 -0
- package/dist/database/MiniDatabaseBuilder.js +84 -0
- package/dist/database/index.d.ts +5 -0
- package/dist/database/index.js +3 -0
- package/dist/identity/ApplicationIdentityProfile.d.ts +188 -0
- package/dist/identity/ApplicationIdentityProfile.js +207 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.js +34 -0
- package/dist/lobby/Lobby.d.ts +150 -0
- package/dist/lobby/Lobby.js +90 -0
- package/dist/node/MiniInteraction.d.ts +199 -0
- package/dist/node/MiniInteraction.js +861 -0
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.js +1 -0
- package/dist/oauth2/DiscordOAuth.d.ts +49 -0
- package/dist/oauth2/DiscordOAuth.js +113 -0
- package/dist/oauth2/OAuth2Builder.d.ts +296 -0
- package/dist/oauth2/OAuth2Builder.js +435 -0
- package/dist/oauth2/OAuth2Scopes.d.ts +285 -0
- package/dist/oauth2/OAuth2Scopes.js +438 -0
- package/dist/oauth2/OAuthTokenStorage.d.ts +37 -0
- package/dist/oauth2/OAuthTokenStorage.js +109 -0
- package/dist/oauth2/index.d.ts +8 -0
- package/dist/oauth2/index.js +4 -0
- package/dist/router/AutocompleteContext.d.ts +36 -0
- package/dist/router/AutocompleteContext.js +82 -0
- package/dist/router/InteractionRouter.d.ts +82 -0
- package/dist/router/InteractionRouter.js +225 -0
- package/dist/types/ButtonStyle.d.ts +16 -0
- package/dist/types/ButtonStyle.js +17 -0
- package/dist/types/ChannelType.d.ts +2 -0
- package/dist/types/ChannelType.js +2 -0
- package/dist/types/Commands.d.ts +35 -0
- package/dist/types/Commands.js +1 -0
- package/dist/types/ComponentTypes.d.ts +19 -0
- package/dist/types/ComponentTypes.js +1 -0
- package/dist/types/InteractionFlags.d.ts +5 -0
- package/dist/types/InteractionFlags.js +6 -0
- package/dist/types/PermissionFlags.d.ts +56 -0
- package/dist/types/PermissionFlags.js +5 -0
- package/dist/types/RoleConnectionMetadata.d.ts +14 -0
- package/dist/types/RoleConnectionMetadata.js +1 -0
- package/dist/types/RoleConnectionMetadataTypes.d.ts +11 -0
- package/dist/types/RoleConnectionMetadataTypes.js +12 -0
- package/dist/types/SeparatorSpacingSize.d.ts +2 -0
- package/dist/types/SeparatorSpacingSize.js +2 -0
- package/dist/types/checkbox.d.ts +16 -0
- package/dist/types/checkbox.js +12 -0
- package/dist/types/discord.d.ts +2 -0
- package/dist/types/discord.js +1 -0
- package/dist/types/radio.d.ts +12 -0
- package/dist/types/radio.js +10 -0
- package/dist/types/validation.d.ts +14 -0
- package/dist/types/validation.js +40 -0
- package/dist/utils/CommandInteractionOptions.d.ts +66 -0
- package/dist/utils/CommandInteractionOptions.js +364 -0
- package/dist/utils/ContextMenuInteraction.d.ts +76 -0
- package/dist/utils/ContextMenuInteraction.js +152 -0
- package/dist/utils/MessageComponentInteraction.d.ts +148 -0
- package/dist/utils/MessageComponentInteraction.js +259 -0
- package/dist/utils/ModalSubmitInteraction.d.ts +86 -0
- package/dist/utils/ModalSubmitInteraction.js +267 -0
- package/dist/utils/cdn.d.ts +30 -0
- package/dist/utils/cdn.js +60 -0
- package/dist/utils/formatting.d.ts +76 -0
- package/dist/utils/formatting.js +132 -0
- package/dist/utils/interactionMessageHelpers.d.ts +40 -0
- package/dist/utils/interactionMessageHelpers.js +118 -0
- package/dist/utils/localization.d.ts +25 -0
- package/dist/utils/localization.js +38 -0
- package/dist/utils/snowflake.d.ts +19 -0
- package/dist/utils/snowflake.js +32 -0
- package/dist/webhooks/WebhookEvent.d.ts +229 -0
- package/dist/webhooks/WebhookEvent.js +59 -0
- package/dist/webhooks/WebhookEventRouter.d.ts +123 -0
- package/dist/webhooks/WebhookEventRouter.js +160 -0
- package/dist/webhooks/WebhookEventVerifier.d.ts +33 -0
- package/dist/webhooks/WebhookEventVerifier.js +37 -0
- package/dist/webhooks/index.d.ts +6 -0
- package/dist/webhooks/index.js +3 -0
- package/package.json +90 -4
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every OAuth2 scope Discord supports, with human-readable descriptions for
|
|
3
|
+
* rendering a consent screen.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://docs.discord.com/developers/topics/oauth2#shared-resources-oauth2-scopes}
|
|
6
|
+
* @see {@link https://docs.discord.com/developers/discord-social-sdk/core-concepts/oauth2-scopes}
|
|
7
|
+
*
|
|
8
|
+
* Scopes are added only when you need them: requesting capabilities a feature
|
|
9
|
+
* does not use measurably increases the number of users who abandon the link
|
|
10
|
+
* flow.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* The scope registry. Use the values (not the keys) when building an
|
|
14
|
+
* authorization URL, and pass them to `OAuth2Builder.addScopes`.
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* new OAuth2Builder({ clientId })
|
|
18
|
+
* .addScopes(OAuth2Scope.Identify, OAuth2Scope.Email)
|
|
19
|
+
* .toURL();
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export const OAuth2Scope = {
|
|
23
|
+
/**
|
|
24
|
+
* `identify` — read the user's basic profile through `/users/@me` (id,
|
|
25
|
+
* username, avatar, flags) **without** email.
|
|
26
|
+
*
|
|
27
|
+
* The safest baseline: every user-facing flow should request at least this.
|
|
28
|
+
*/
|
|
29
|
+
Identify: "identify",
|
|
30
|
+
/**
|
|
31
|
+
* `identify.premium` — read the user's Nitro subscription type (`premium_type`
|
|
32
|
+
* on the user object).
|
|
33
|
+
*
|
|
34
|
+
* Only available to approved partners.
|
|
35
|
+
*/
|
|
36
|
+
IdentifyPremium: "identify.premium",
|
|
37
|
+
/** `email` — makes `/users/@me` return the user's verified email address. */
|
|
38
|
+
Email: "email",
|
|
39
|
+
/** `connections` — read the user's linked third-party accounts via `/users/@me/connections`. */
|
|
40
|
+
Connections: "connections",
|
|
41
|
+
/** `guilds` — list the user's servers (`/users/@me/guilds`), names and icons included. */
|
|
42
|
+
Guilds: "guilds",
|
|
43
|
+
/**
|
|
44
|
+
* `guilds.join` — add the user to a server with
|
|
45
|
+
* `PUT /guilds/{guild.id}/members/{user.id}`.
|
|
46
|
+
*
|
|
47
|
+
* Your bot must already be in that server.
|
|
48
|
+
*/
|
|
49
|
+
GuildsJoin: "guilds.join",
|
|
50
|
+
/** `guilds.members.read` — read the user's own member record in a guild (nickname, roles, join date). */
|
|
51
|
+
GuildsMembersRead: "guilds.members.read",
|
|
52
|
+
/** `applications.builds.read` — read build data for the user's applications. */
|
|
53
|
+
ApplicationsBuildsRead: "applications.builds.read",
|
|
54
|
+
/**
|
|
55
|
+
* `applications.builds.upload` — upload or update builds for the user's
|
|
56
|
+
* applications. Only available to approved partners.
|
|
57
|
+
*/
|
|
58
|
+
ApplicationsBuildsUpload: "applications.builds.upload",
|
|
59
|
+
/**
|
|
60
|
+
* `applications.commands` — add application commands to a guild.
|
|
61
|
+
*
|
|
62
|
+
* Included automatically when the `bot` scope is requested; list it
|
|
63
|
+
* explicitly only for a command-only install with no bot user.
|
|
64
|
+
*/
|
|
65
|
+
ApplicationsCommands: "applications.commands",
|
|
66
|
+
/**
|
|
67
|
+
* `applications.commands.update` — let the app update its own commands with a
|
|
68
|
+
* Bearer token.
|
|
69
|
+
*
|
|
70
|
+
* Client-credentials grant only. Also one of the two scopes a **team-owned**
|
|
71
|
+
* application may request without a user context.
|
|
72
|
+
*/
|
|
73
|
+
ApplicationsCommandsUpdate: "applications.commands.update",
|
|
74
|
+
/**
|
|
75
|
+
* `applications.commands.permissions.update` — update command permissions in
|
|
76
|
+
* a guild the user is allowed to manage.
|
|
77
|
+
*/
|
|
78
|
+
ApplicationsCommandsPermissionsUpdate: "applications.commands.permissions.update",
|
|
79
|
+
/** `applications.entitlements` — read the user's entitlements (SKU grants, purchases). */
|
|
80
|
+
ApplicationsEntitlements: "applications.entitlements",
|
|
81
|
+
/** `applications.store.update` — read and update store data (SKUs, listings, achievements) for the user's applications. */
|
|
82
|
+
ApplicationsStoreUpdate: "applications.store.update",
|
|
83
|
+
/**
|
|
84
|
+
* `bot` — the bot-authorization flow: puts the bot in the user's selected
|
|
85
|
+
* server by default and implicitly grants `applications.commands`.
|
|
86
|
+
*
|
|
87
|
+
* A passthrough scope, so authorization is always re-confirmed even when
|
|
88
|
+
* `prompt=none`.
|
|
89
|
+
*/
|
|
90
|
+
Bot: "bot",
|
|
91
|
+
/**
|
|
92
|
+
* `webhook.incoming` — creates a webhook in a channel the user picks, returned
|
|
93
|
+
* in the token response.
|
|
94
|
+
*
|
|
95
|
+
* A passthrough scope, so authorization is always re-confirmed even when
|
|
96
|
+
* `prompt=none`. Still needs a `redirect_uri` to receive the code back.
|
|
97
|
+
*/
|
|
98
|
+
WebhookIncoming: "webhook.incoming",
|
|
99
|
+
/** `messages.read` — read messages from all client channels through the local RPC server. */
|
|
100
|
+
MessagesRead: "messages.read",
|
|
101
|
+
/**
|
|
102
|
+
* `dm_channels.read` — see the user's DMs and group DMs.
|
|
103
|
+
*
|
|
104
|
+
* Only available to approved partners.
|
|
105
|
+
*/
|
|
106
|
+
DmChannelsRead: "dm_channels.read",
|
|
107
|
+
/** `gdm.join` — add the user to a group DM. */
|
|
108
|
+
GdmJoin: "gdm.join",
|
|
109
|
+
/**
|
|
110
|
+
* `relationships.read` — read the user's friends list, pending requests and
|
|
111
|
+
* blocks.
|
|
112
|
+
*
|
|
113
|
+
* Part of the Social SDK; requires an access request, and the Social SDK
|
|
114
|
+
* terms apply to the data you receive. Pair it with
|
|
115
|
+
* {@link OAuth2Scope.SdkSocialLayerPresence} for a friends list.
|
|
116
|
+
*/
|
|
117
|
+
RelationshipsRead: "relationships.read",
|
|
118
|
+
/**
|
|
119
|
+
* `rpc` — control the user's local Discord client over the RPC server.
|
|
120
|
+
*
|
|
121
|
+
* Only available to approved partners.
|
|
122
|
+
*/
|
|
123
|
+
Rpc: "rpc",
|
|
124
|
+
/** `rpc.activities.write` — update the user's activity over RPC. Approved partners only. */
|
|
125
|
+
RpcActivitiesWrite: "rpc.activities.write",
|
|
126
|
+
/** `rpc.notifications.read` — receive the user's pushed notifications over RPC. Approved partners only. */
|
|
127
|
+
RpcNotificationsRead: "rpc.notifications.read",
|
|
128
|
+
/** `rpc.voice.read` — read voice settings and listen to voice events over RPC. Approved partners only. */
|
|
129
|
+
RpcVoiceRead: "rpc.voice.read",
|
|
130
|
+
/** `rpc.voice.write` — update voice settings over RPC. Approved partners only. */
|
|
131
|
+
RpcVoiceWrite: "rpc.voice.write",
|
|
132
|
+
/**
|
|
133
|
+
* `voice` — connect to voice on the user's behalf and see every voice member.
|
|
134
|
+
*
|
|
135
|
+
* Only available to approved partners.
|
|
136
|
+
*/
|
|
137
|
+
Voice: "voice",
|
|
138
|
+
/**
|
|
139
|
+
* `activities.read` — read the user's "Now Playing / Recently Played" list.
|
|
140
|
+
*
|
|
141
|
+
* Not currently available to applications.
|
|
142
|
+
*/
|
|
143
|
+
ActivitiesRead: "activities.read",
|
|
144
|
+
/**
|
|
145
|
+
* `activities.write` — update the user's activity.
|
|
146
|
+
*
|
|
147
|
+
* Not currently available to applications, and **not** required for the Game
|
|
148
|
+
* SDK activity manager.
|
|
149
|
+
*/
|
|
150
|
+
ActivitiesWrite: "activities.write",
|
|
151
|
+
/**
|
|
152
|
+
* `openid` — the OpenID Connect identifier claim.
|
|
153
|
+
*
|
|
154
|
+
* Always part of the Social SDK's default scope sets; request it alongside
|
|
155
|
+
* {@link OAuth2Scope.SdkSocialLayer} or
|
|
156
|
+
* {@link OAuth2Scope.SdkSocialLayerPresence} rather than on its own.
|
|
157
|
+
*/
|
|
158
|
+
OpenId: "openid",
|
|
159
|
+
/**
|
|
160
|
+
* `sdk.social_layer` — full Discord Social SDK access: account linking,
|
|
161
|
+
* provisional accounts, relationships, presence **and** the limited-access
|
|
162
|
+
* communication features (messaging, lobbies and in-game chat, and
|
|
163
|
+
* **[Linked Channels]**).
|
|
164
|
+
*
|
|
165
|
+
* Implies {@link OAuth2Scope.SdkSocialLayerPresence}. Subject to limited
|
|
166
|
+
* access; see {@link RestrictedOAuth2Scopes}.
|
|
167
|
+
*
|
|
168
|
+
* [Linked Channels]: https://docs.discord.com/developers/discord-social-sdk/development-guides/linked-channels
|
|
169
|
+
*/
|
|
170
|
+
SdkSocialLayer: "sdk.social_layer",
|
|
171
|
+
/**
|
|
172
|
+
* `sdk.social_layer_presence` — the Social SDK's default presence set:
|
|
173
|
+
* account linking, provisional accounts, the friend system and rich presence.
|
|
174
|
+
*
|
|
175
|
+
* Does **not** unlock any communication or Linked Channel feature.
|
|
176
|
+
*/
|
|
177
|
+
SdkSocialLayerPresence: "sdk.social_layer_presence",
|
|
178
|
+
/**
|
|
179
|
+
* `role_connections.write` — update a user's connection and metadata for your
|
|
180
|
+
* app, i.e. the platform that renders a linked role on their profile.
|
|
181
|
+
*
|
|
182
|
+
* **Only usable with the authorization code grant** — Discord rejects it on
|
|
183
|
+
* the implicit grant.
|
|
184
|
+
*/
|
|
185
|
+
RoleConnectionsWrite: "role_connections.write",
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Runtime metadata for every scope: the same descriptions as the JSDoc above,
|
|
189
|
+
* so a UI can render a real consent screen without duplicating the copy.
|
|
190
|
+
*/
|
|
191
|
+
export const OAuth2ScopeMetadata = {
|
|
192
|
+
[OAuth2Scope.Identify]: {
|
|
193
|
+
description: "Read your basic Discord profile, without your email address.",
|
|
194
|
+
category: "identity",
|
|
195
|
+
},
|
|
196
|
+
[OAuth2Scope.IdentifyPremium]: {
|
|
197
|
+
description: "Read your Discord Nitro subscription type.",
|
|
198
|
+
category: "identity",
|
|
199
|
+
restricted: true,
|
|
200
|
+
},
|
|
201
|
+
[OAuth2Scope.Email]: {
|
|
202
|
+
description: "Read your email address.",
|
|
203
|
+
category: "identity",
|
|
204
|
+
},
|
|
205
|
+
[OAuth2Scope.Connections]: {
|
|
206
|
+
description: "See your linked third-party accounts.",
|
|
207
|
+
category: "identity",
|
|
208
|
+
},
|
|
209
|
+
[OAuth2Scope.Guilds]: {
|
|
210
|
+
description: "See the servers you are in.",
|
|
211
|
+
category: "identity",
|
|
212
|
+
},
|
|
213
|
+
[OAuth2Scope.GuildsJoin]: {
|
|
214
|
+
description: "Add you to a server.",
|
|
215
|
+
category: "identity",
|
|
216
|
+
},
|
|
217
|
+
[OAuth2Scope.GuildsMembersRead]: {
|
|
218
|
+
description: "See your member profile in a server, including your roles.",
|
|
219
|
+
category: "identity",
|
|
220
|
+
},
|
|
221
|
+
[OAuth2Scope.ApplicationsBuildsRead]: {
|
|
222
|
+
description: "Read build data for your applications.",
|
|
223
|
+
category: "applications",
|
|
224
|
+
},
|
|
225
|
+
[OAuth2Scope.ApplicationsBuildsUpload]: {
|
|
226
|
+
description: "Upload and update builds for your applications.",
|
|
227
|
+
category: "applications",
|
|
228
|
+
restricted: true,
|
|
229
|
+
},
|
|
230
|
+
[OAuth2Scope.ApplicationsCommands]: {
|
|
231
|
+
description: "Add this app's commands to a server.",
|
|
232
|
+
category: "applications",
|
|
233
|
+
},
|
|
234
|
+
[OAuth2Scope.ApplicationsCommandsUpdate]: {
|
|
235
|
+
description: "Update this app's commands using a Bearer token.",
|
|
236
|
+
category: "applications",
|
|
237
|
+
},
|
|
238
|
+
[OAuth2Scope.ApplicationsCommandsPermissionsUpdate]: {
|
|
239
|
+
description: "Update command permissions in servers you manage.",
|
|
240
|
+
category: "applications",
|
|
241
|
+
},
|
|
242
|
+
[OAuth2Scope.ApplicationsEntitlements]: {
|
|
243
|
+
description: "Read your entitlements for this app.",
|
|
244
|
+
category: "applications",
|
|
245
|
+
},
|
|
246
|
+
[OAuth2Scope.ApplicationsStoreUpdate]: {
|
|
247
|
+
description: "Read and update store data for your applications.",
|
|
248
|
+
category: "applications",
|
|
249
|
+
},
|
|
250
|
+
[OAuth2Scope.Bot]: {
|
|
251
|
+
description: "Add this app's bot to a server.",
|
|
252
|
+
category: "bot",
|
|
253
|
+
},
|
|
254
|
+
[OAuth2Scope.WebhookIncoming]: {
|
|
255
|
+
description: "Create a webhook in a channel you choose.",
|
|
256
|
+
category: "bot",
|
|
257
|
+
},
|
|
258
|
+
[OAuth2Scope.MessagesRead]: {
|
|
259
|
+
description: "Read messages from all your client channels.",
|
|
260
|
+
category: "messaging",
|
|
261
|
+
},
|
|
262
|
+
[OAuth2Scope.DmChannelsRead]: {
|
|
263
|
+
description: "See information about your direct messages and group DMs.",
|
|
264
|
+
category: "messaging",
|
|
265
|
+
restricted: true,
|
|
266
|
+
},
|
|
267
|
+
[OAuth2Scope.GdmJoin]: {
|
|
268
|
+
description: "Add you to a group direct message.",
|
|
269
|
+
category: "messaging",
|
|
270
|
+
},
|
|
271
|
+
[OAuth2Scope.RelationshipsRead]: {
|
|
272
|
+
description: "See your friends, pending requests and blocked users.",
|
|
273
|
+
category: "social-sdk",
|
|
274
|
+
restricted: true,
|
|
275
|
+
},
|
|
276
|
+
[OAuth2Scope.Rpc]: {
|
|
277
|
+
description: "Control your local Discord client.",
|
|
278
|
+
category: "rpc",
|
|
279
|
+
restricted: true,
|
|
280
|
+
},
|
|
281
|
+
[OAuth2Scope.RpcActivitiesWrite]: {
|
|
282
|
+
description: "Update your activity on the local Discord client.",
|
|
283
|
+
category: "rpc",
|
|
284
|
+
restricted: true,
|
|
285
|
+
},
|
|
286
|
+
[OAuth2Scope.RpcNotificationsRead]: {
|
|
287
|
+
description: "Receive your notifications from the local Discord client.",
|
|
288
|
+
category: "rpc",
|
|
289
|
+
restricted: true,
|
|
290
|
+
},
|
|
291
|
+
[OAuth2Scope.RpcVoiceRead]: {
|
|
292
|
+
description: "Read your voice settings and listen for voice events.",
|
|
293
|
+
category: "rpc",
|
|
294
|
+
restricted: true,
|
|
295
|
+
},
|
|
296
|
+
[OAuth2Scope.RpcVoiceWrite]: {
|
|
297
|
+
description: "Update your voice settings.",
|
|
298
|
+
category: "rpc",
|
|
299
|
+
restricted: true,
|
|
300
|
+
},
|
|
301
|
+
[OAuth2Scope.Voice]: {
|
|
302
|
+
description: "Connect to voice on your behalf and see all voice members.",
|
|
303
|
+
category: "rpc",
|
|
304
|
+
restricted: true,
|
|
305
|
+
},
|
|
306
|
+
[OAuth2Scope.ActivitiesRead]: {
|
|
307
|
+
description: "Read your Now Playing / Recently Played list.",
|
|
308
|
+
category: "rpc",
|
|
309
|
+
restricted: true,
|
|
310
|
+
},
|
|
311
|
+
[OAuth2Scope.ActivitiesWrite]: {
|
|
312
|
+
description: "Update your activity.",
|
|
313
|
+
category: "rpc",
|
|
314
|
+
restricted: true,
|
|
315
|
+
},
|
|
316
|
+
[OAuth2Scope.OpenId]: {
|
|
317
|
+
description: "Confirm your Discord identity to the app.",
|
|
318
|
+
category: "social-sdk",
|
|
319
|
+
},
|
|
320
|
+
[OAuth2Scope.SdkSocialLayer]: {
|
|
321
|
+
description: "Use Discord Social features: account linking, friends, presence, messaging, lobbies and linked channels.",
|
|
322
|
+
category: "social-sdk",
|
|
323
|
+
restricted: true,
|
|
324
|
+
},
|
|
325
|
+
[OAuth2Scope.SdkSocialLayerPresence]: {
|
|
326
|
+
description: "Use Discord Social presence features: account linking, friends and rich presence.",
|
|
327
|
+
category: "social-sdk",
|
|
328
|
+
restricted: true,
|
|
329
|
+
},
|
|
330
|
+
[OAuth2Scope.RoleConnectionsWrite]: {
|
|
331
|
+
description: "Update your connection and metadata for this app on your profile.",
|
|
332
|
+
category: "verification",
|
|
333
|
+
},
|
|
334
|
+
};
|
|
335
|
+
/**
|
|
336
|
+
* Scope name to description, for a consent screen that only needs the copy:
|
|
337
|
+
*
|
|
338
|
+
* ```ts
|
|
339
|
+
* OAuth2ScopeDescriptions[OAuth2Scope.GuildsJoin];
|
|
340
|
+
* // "Add you to a server."
|
|
341
|
+
* ```
|
|
342
|
+
*
|
|
343
|
+
* Prefer {@link OAuth2ScopeMetadata} when you also want the category or the
|
|
344
|
+
* restricted flag.
|
|
345
|
+
*/
|
|
346
|
+
export const OAuth2ScopeDescriptions = Object.fromEntries(Object.entries(OAuth2ScopeMetadata).map(([scope, metadata]) => [
|
|
347
|
+
scope,
|
|
348
|
+
metadata.description,
|
|
349
|
+
]));
|
|
350
|
+
/**
|
|
351
|
+
* Scopes Discord only grants after an approval request (or, for the Social SDK,
|
|
352
|
+
* an access request). Requesting them without approval can fail the flow or
|
|
353
|
+
* behave unpredictably.
|
|
354
|
+
*/
|
|
355
|
+
export const RestrictedOAuth2Scopes = new Set(Object.entries(OAuth2ScopeMetadata)
|
|
356
|
+
.filter(([, metadata]) => metadata.restricted)
|
|
357
|
+
.map(([scope]) => scope));
|
|
358
|
+
/** Scopes grouped by category, in a stable order, for rendering a consent screen. */
|
|
359
|
+
export const OAuth2ScopeCategories = {
|
|
360
|
+
identity: [],
|
|
361
|
+
applications: [],
|
|
362
|
+
bot: [],
|
|
363
|
+
messaging: [],
|
|
364
|
+
rpc: [],
|
|
365
|
+
"social-sdk": [],
|
|
366
|
+
verification: [],
|
|
367
|
+
};
|
|
368
|
+
for (const scope of Object.values(OAuth2Scope)) {
|
|
369
|
+
OAuth2ScopeCategories[OAuth2ScopeMetadata[scope].category].push(scope);
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Ready-made scope sets for the common flows.
|
|
373
|
+
*
|
|
374
|
+
* `Communication` is the one Linked Channels needs — see
|
|
375
|
+
* {@link https://docs.discord.com/developers/discord-social-sdk/core-concepts/oauth2-scopes}
|
|
376
|
+
*/
|
|
377
|
+
export const OAuth2ScopePresets = {
|
|
378
|
+
/** `identify` only: the smallest request that still identifies the user. */
|
|
379
|
+
Minimal: [OAuth2Scope.Identify],
|
|
380
|
+
/** `identify email`: the usual "sign in with Discord". */
|
|
381
|
+
SignIn: [OAuth2Scope.Identify, OAuth2Scope.Email],
|
|
382
|
+
/** `identify guilds`: sign-in plus the user's server list. */
|
|
383
|
+
SignInWithGuilds: [OAuth2Scope.Identify, OAuth2Scope.Email, OAuth2Scope.Guilds],
|
|
384
|
+
/**
|
|
385
|
+
* The Social SDK's default `Client::GetDefaultPresenceScopes` — account
|
|
386
|
+
* linking, provisional accounts, friends and rich presence. No messaging.
|
|
387
|
+
*/
|
|
388
|
+
SocialPresence: [OAuth2Scope.OpenId, OAuth2Scope.SdkSocialLayerPresence],
|
|
389
|
+
/**
|
|
390
|
+
* The Social SDK's `Client::GetDefaultCommunicationScopes` — required for
|
|
391
|
+
* lobbies, in-game chat and **Linked Channels**.
|
|
392
|
+
*/
|
|
393
|
+
SocialCommunication: [OAuth2Scope.OpenId, OAuth2Scope.SdkSocialLayer],
|
|
394
|
+
/** Add the bot, with its commands. */
|
|
395
|
+
Bot: [OAuth2Scope.Bot, OAuth2Scope.ApplicationsCommands],
|
|
396
|
+
/** Create an incoming webhook in a channel the user picks. */
|
|
397
|
+
Webhook: [OAuth2Scope.WebhookIncoming],
|
|
398
|
+
/** Linked roles: read the profile and write the connection metadata. */
|
|
399
|
+
RoleConnection: [OAuth2Scope.Identify, OAuth2Scope.RoleConnectionsWrite],
|
|
400
|
+
};
|
|
401
|
+
/** The authorization URL Discord serves the consent screen from. */
|
|
402
|
+
export const OAUTH2_AUTHORIZE_URL = "https://discord.com/oauth2/authorize";
|
|
403
|
+
/** The token endpoint, used by the authorization code, refresh and client credentials grants. */
|
|
404
|
+
export const OAUTH2_TOKEN_URL = "https://discord.com/api/oauth2/token";
|
|
405
|
+
/** The token revocation endpoint. */
|
|
406
|
+
export const OAUTH2_REVOKE_URL = "https://discord.com/api/oauth2/token/revoke";
|
|
407
|
+
/** `GET` this with a Bearer token to learn what the token may actually do. */
|
|
408
|
+
export const OAUTH2_ME_URL = "https://discord.com/api/oauth2/@me";
|
|
409
|
+
/** Whether a string is a scope Discord documents support for. */
|
|
410
|
+
export function isOAuth2Scope(value) {
|
|
411
|
+
return Object.hasOwn(OAuth2ScopeMetadata, value);
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Descriptions for a set of scopes, ready to render as a consent list:
|
|
415
|
+
*
|
|
416
|
+
* ```ts
|
|
417
|
+
* describeOAuth2Scopes(OAuth2ScopePresets.SignIn);
|
|
418
|
+
* // [{ scope: "identify", description: "…" }, …]
|
|
419
|
+
* ```
|
|
420
|
+
*
|
|
421
|
+
* Unknown scope names are included with a `undefined` description rather than
|
|
422
|
+
* dropped, so a typo stays visible.
|
|
423
|
+
*/
|
|
424
|
+
export function describeOAuth2Scopes(scopes) {
|
|
425
|
+
return Array.from(scopes, (scope) => ({
|
|
426
|
+
scope,
|
|
427
|
+
description: isOAuth2Scope(scope) ? OAuth2ScopeDescriptions[scope] : undefined,
|
|
428
|
+
restricted: isOAuth2Scope(scope) && RestrictedOAuth2Scopes.has(scope),
|
|
429
|
+
}));
|
|
430
|
+
}
|
|
431
|
+
/** Whether any of the given scopes needs Discord's approval before use. */
|
|
432
|
+
export function requiresOAuth2ScopeApproval(scopes) {
|
|
433
|
+
for (const scope of scopes) {
|
|
434
|
+
if (isOAuth2Scope(scope) && RestrictedOAuth2Scopes.has(scope))
|
|
435
|
+
return true;
|
|
436
|
+
}
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { OAuthTokens } from "./DiscordOAuth.js";
|
|
2
|
+
/** Structural storage contract satisfied by `mini-interactions/database` and custom databases. */
|
|
3
|
+
export interface OAuthTokenDatabase {
|
|
4
|
+
get(key: string): Promise<Record<string, unknown> | null>;
|
|
5
|
+
set(key: string, data: Record<string, unknown>): Promise<boolean>;
|
|
6
|
+
update(key: string, updates: Record<string, unknown>): Promise<boolean>;
|
|
7
|
+
delete(key: string): Promise<boolean>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Manages OAuth token storage using MiniDatabase.
|
|
11
|
+
* Handles both in-memory and persistent storage.
|
|
12
|
+
*/
|
|
13
|
+
export declare class OAuthTokenStorage {
|
|
14
|
+
private db?;
|
|
15
|
+
private inMemoryStore;
|
|
16
|
+
constructor(db?: OAuthTokenDatabase);
|
|
17
|
+
/**
|
|
18
|
+
* Stores OAuth tokens for a user.
|
|
19
|
+
*/
|
|
20
|
+
storeTokens(userId: string, tokens: OAuthTokens): Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves OAuth tokens for a user.
|
|
23
|
+
*/
|
|
24
|
+
getTokens(userId: string): Promise<OAuthTokens | null>;
|
|
25
|
+
/**
|
|
26
|
+
* Updates OAuth tokens for a user.
|
|
27
|
+
*/
|
|
28
|
+
updateTokens(userId: string, tokens: OAuthTokens): Promise<boolean>;
|
|
29
|
+
/**
|
|
30
|
+
* Deletes OAuth tokens for a user.
|
|
31
|
+
*/
|
|
32
|
+
deleteTokens(userId: string): Promise<boolean>;
|
|
33
|
+
/**
|
|
34
|
+
* Clears all in-memory tokens (useful for testing).
|
|
35
|
+
*/
|
|
36
|
+
clearMemory(): void;
|
|
37
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages OAuth token storage using MiniDatabase.
|
|
3
|
+
* Handles both in-memory and persistent storage.
|
|
4
|
+
*/
|
|
5
|
+
export class OAuthTokenStorage {
|
|
6
|
+
db;
|
|
7
|
+
inMemoryStore = new Map();
|
|
8
|
+
constructor(db) {
|
|
9
|
+
this.db = db;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Stores OAuth tokens for a user.
|
|
13
|
+
*/
|
|
14
|
+
async storeTokens(userId, tokens) {
|
|
15
|
+
try {
|
|
16
|
+
// Always store in memory for fast access
|
|
17
|
+
this.inMemoryStore.set(`oauth-${userId}`, tokens);
|
|
18
|
+
// Also store in database if available
|
|
19
|
+
if (this.db) {
|
|
20
|
+
return await this.db.set(`oauth-${userId}`, {
|
|
21
|
+
userId,
|
|
22
|
+
...tokens,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
console.error(`❌ [OAuthTokenStorage] Failed to store tokens for ${userId}:`, err);
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Retrieves OAuth tokens for a user.
|
|
34
|
+
*/
|
|
35
|
+
async getTokens(userId) {
|
|
36
|
+
try {
|
|
37
|
+
// Check in-memory store first
|
|
38
|
+
const cached = this.inMemoryStore.get(`oauth-${userId}`);
|
|
39
|
+
if (cached) {
|
|
40
|
+
return cached;
|
|
41
|
+
}
|
|
42
|
+
// Check database if available
|
|
43
|
+
if (this.db) {
|
|
44
|
+
const data = await this.db.get(`oauth-${userId}`);
|
|
45
|
+
if (data) {
|
|
46
|
+
const tokens = {
|
|
47
|
+
access_token: data.access_token,
|
|
48
|
+
refresh_token: data.refresh_token,
|
|
49
|
+
expires_at: data.expires_at,
|
|
50
|
+
token_type: data.token_type,
|
|
51
|
+
scope: data.scope,
|
|
52
|
+
};
|
|
53
|
+
// Cache in memory
|
|
54
|
+
this.inMemoryStore.set(`oauth-${userId}`, tokens);
|
|
55
|
+
return tokens;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
console.error(`❌ [OAuthTokenStorage] Failed to get tokens for ${userId}:`, err);
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Updates OAuth tokens for a user.
|
|
67
|
+
*/
|
|
68
|
+
async updateTokens(userId, tokens) {
|
|
69
|
+
try {
|
|
70
|
+
// Update in-memory store
|
|
71
|
+
this.inMemoryStore.set(`oauth-${userId}`, tokens);
|
|
72
|
+
// Update in database if available
|
|
73
|
+
if (this.db) {
|
|
74
|
+
return await this.db.update(`oauth-${userId}`, {
|
|
75
|
+
...tokens,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
console.error(`❌ [OAuthTokenStorage] Failed to update tokens for ${userId}:`, err);
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Deletes OAuth tokens for a user.
|
|
87
|
+
*/
|
|
88
|
+
async deleteTokens(userId) {
|
|
89
|
+
try {
|
|
90
|
+
// Remove from in-memory store
|
|
91
|
+
this.inMemoryStore.delete(`oauth-${userId}`);
|
|
92
|
+
// Remove from database if available
|
|
93
|
+
if (this.db) {
|
|
94
|
+
return await this.db.delete(`oauth-${userId}`);
|
|
95
|
+
}
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
console.error(`❌ [OAuthTokenStorage] Failed to delete tokens for ${userId}:`, err);
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Clears all in-memory tokens (useful for testing).
|
|
105
|
+
*/
|
|
106
|
+
clearMemory() {
|
|
107
|
+
this.inMemoryStore.clear();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { generateOAuthUrl, getOAuthTokens, refreshAccessToken, getDiscordUser, ensureValidToken, } from "./DiscordOAuth.js";
|
|
2
|
+
export type { OAuthConfig, OAuthTokens, DiscordUser, } from "./DiscordOAuth.js";
|
|
3
|
+
export { OAuthTokenStorage } from "./OAuthTokenStorage.js";
|
|
4
|
+
export type { OAuthTokenDatabase } from "./OAuthTokenStorage.js";
|
|
5
|
+
export { OAuth2Builder, OAuth2BuilderError, OAuth2RequestError, } from "./OAuth2Builder.js";
|
|
6
|
+
export type { OAuth2AuthorizationInfo, OAuth2AuthorizationUrl, OAuth2AuthorizedGuild, OAuth2BuilderErrorCode, OAuth2BuilderOptions, OAuth2ConsentEntry, OAuth2ConsentGroup, OAuth2IntegrationType, OAuth2Prompt, OAuth2RequestOptions, OAuth2ResponseType, OAuth2TokenResponse, OAuth2TokenType, } from "./OAuth2Builder.js";
|
|
7
|
+
export { OAUTH2_AUTHORIZE_URL, OAUTH2_ME_URL, OAUTH2_REVOKE_URL, OAUTH2_TOKEN_URL, OAuth2Scope, OAuth2ScopeCategories, OAuth2ScopeDescriptions, OAuth2ScopeMetadata, OAuth2ScopePresets, RestrictedOAuth2Scopes, describeOAuth2Scopes, isOAuth2Scope, requiresOAuth2ScopeApproval, } from "./OAuth2Scopes.js";
|
|
8
|
+
export type { OAuth2ScopeCategory } from "./OAuth2Scopes.js";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { generateOAuthUrl, getOAuthTokens, refreshAccessToken, getDiscordUser, ensureValidToken, } from "./DiscordOAuth.js";
|
|
2
|
+
export { OAuthTokenStorage } from "./OAuthTokenStorage.js";
|
|
3
|
+
export { OAuth2Builder, OAuth2BuilderError, OAuth2RequestError, } from "./OAuth2Builder.js";
|
|
4
|
+
export { OAUTH2_AUTHORIZE_URL, OAUTH2_ME_URL, OAUTH2_REVOKE_URL, OAUTH2_TOKEN_URL, OAuth2Scope, OAuth2ScopeCategories, OAuth2ScopeDescriptions, OAuth2ScopeMetadata, OAuth2ScopePresets, RestrictedOAuth2Scopes, describeOAuth2Scopes, isOAuth2Scope, requiresOAuth2ScopeApproval, } from "./OAuth2Scopes.js";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type APIApplicationCommandAutocompleteInteraction, type APIApplicationCommandOptionChoice, type APIInteractionResponse } from "discord-api-types/v10";
|
|
2
|
+
/** A focused (currently-typed) option inside an autocomplete interaction. */
|
|
3
|
+
export type FocusedOption = {
|
|
4
|
+
name: string;
|
|
5
|
+
value: string | number;
|
|
6
|
+
type: number;
|
|
7
|
+
subcommandGroup?: string;
|
|
8
|
+
subcommand?: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Context for autocomplete interactions (`InteractionType.ApplicationCommandAutocomplete`).
|
|
12
|
+
* Collects up to 25 choice suggestions and produces the `type: 8` response.
|
|
13
|
+
*/
|
|
14
|
+
export declare class AutocompleteContext {
|
|
15
|
+
private readonly interaction;
|
|
16
|
+
private responded;
|
|
17
|
+
private autocompleteResponse?;
|
|
18
|
+
constructor(interaction: APIApplicationCommandAutocompleteInteraction);
|
|
19
|
+
/** Name of the command being autocompleted. */
|
|
20
|
+
get commandName(): string;
|
|
21
|
+
get hasResponded(): boolean;
|
|
22
|
+
/** The raw response produced by {@link respond}, if any. */
|
|
23
|
+
get result(): APIInteractionResponse | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Finds the option the user is currently typing in.
|
|
26
|
+
*
|
|
27
|
+
* @param required - Throw when no focused option exists instead of returning null.
|
|
28
|
+
*/
|
|
29
|
+
getFocusedOption(required?: boolean): FocusedOption | null;
|
|
30
|
+
/**
|
|
31
|
+
* Answers the autocomplete request with up to 25 choices.
|
|
32
|
+
* Plain strings are accepted as shorthand for `{ name, value }` pairs.
|
|
33
|
+
*/
|
|
34
|
+
respond(choices: ReadonlyArray<string | APIApplicationCommandOptionChoice>): APIInteractionResponse;
|
|
35
|
+
private search;
|
|
36
|
+
}
|