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,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Application Identity profiles power **Game Stats Widgets** — the rank,
|
|
3
|
+
* playtime and win panel a *claimed* game can render on a Discord user profile.
|
|
4
|
+
*
|
|
5
|
+
* Everything here is plain HTTP authenticated with the application's **bot
|
|
6
|
+
* token**, so it works in stateless/serverless deployments with no gateway.
|
|
7
|
+
*
|
|
8
|
+
* Prerequisites (configured outside this library):
|
|
9
|
+
* - The game must be **claimed on Discord** and a widget configured under
|
|
10
|
+
* Developer Portal → Games → Widget.
|
|
11
|
+
* - The player must have linked their Discord account via OAuth2 with the
|
|
12
|
+
* `application_identities.write` scope.
|
|
13
|
+
* - Media URLs must be reachable from the public internet: Discord's unfurler
|
|
14
|
+
* fetches them server-side, so `localhost`/LAN URLs never resolve.
|
|
15
|
+
*
|
|
16
|
+
* @see {@link https://docs.discord.com/developers/resources/application-identity-profile}
|
|
17
|
+
* @see {@link https://docs.discord.com/developers/social-layer/game-stats-widgets/overview}
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Discriminator for a dynamic (custom) profile field.
|
|
21
|
+
*
|
|
22
|
+
* - `String` (1) — a text value
|
|
23
|
+
* - `Number` (2) — a numeric value
|
|
24
|
+
* - `Media` (3) — a media object (public image URL)
|
|
25
|
+
*/
|
|
26
|
+
export const DynamicFieldType = {
|
|
27
|
+
String: 1,
|
|
28
|
+
Number: 2,
|
|
29
|
+
Media: 3,
|
|
30
|
+
};
|
|
31
|
+
/** Hard limits enforced by Discord; validated client-side so failures are obvious. */
|
|
32
|
+
export const APPLICATION_IDENTITY_LIMITS = {
|
|
33
|
+
/** Serialized `data` object must stay under 10 KB. */
|
|
34
|
+
MaxSerializedDataBytes: 10 * 1024,
|
|
35
|
+
/** Maximum number of `dynamic` fields. */
|
|
36
|
+
MaxDynamicFields: 30,
|
|
37
|
+
/** Maximum length of any string stat value (e.g. `rank_name`). */
|
|
38
|
+
MaxStringValueLength: 100,
|
|
39
|
+
/** Maximum length of a dynamic field `name` (its data key). */
|
|
40
|
+
MaxDynamicFieldNameLength: 100,
|
|
41
|
+
/** Maximum length of `username`. */
|
|
42
|
+
MaxUsernameLength: 1024,
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Thrown when a Game Stats payload would be rejected by Discord, so callers can
|
|
46
|
+
* branch on {@link code} instead of string-matching an API error.
|
|
47
|
+
*/
|
|
48
|
+
export class ApplicationIdentityProfileError extends Error {
|
|
49
|
+
code;
|
|
50
|
+
constructor(code, message) {
|
|
51
|
+
super(`[ApplicationIdentityProfile] ${message}`);
|
|
52
|
+
this.code = code;
|
|
53
|
+
this.name = "ApplicationIdentityProfileError";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Error strings the Application Identity Profile API returns that are worth branching on. */
|
|
57
|
+
export const APPLICATION_IDENTITY_PROFILE_ERRORS = {
|
|
58
|
+
PayloadTooLarge: "Profile data is too large, must be less than 10KB",
|
|
59
|
+
IdentityAlreadyExists: "Application identity for this external account already exists for another user",
|
|
60
|
+
ProviderUserMismatch: "does not match existing identity record",
|
|
61
|
+
};
|
|
62
|
+
/** Shared encoder so the size check works on both Node and Cloudflare Workers. */
|
|
63
|
+
const UTF8_ENCODER = new TextEncoder();
|
|
64
|
+
/**
|
|
65
|
+
* Hosts the unfurler cannot reach. Matched against a normalised hostname
|
|
66
|
+
* (brackets and any trailing dot removed, lowercased), so IPv6 literals and
|
|
67
|
+
* trailing-dot FQDNs like `localhost.` are covered too.
|
|
68
|
+
*/
|
|
69
|
+
const PRIVATE_HOST_PATTERNS = [
|
|
70
|
+
/^localhost$/,
|
|
71
|
+
/^127\./,
|
|
72
|
+
/^0\.0\.0\.0$/,
|
|
73
|
+
/^::1$/,
|
|
74
|
+
/^10\./,
|
|
75
|
+
/^192\.168\./,
|
|
76
|
+
/^172\.(1[6-9]|2\d|3[01])\./,
|
|
77
|
+
/^169\.254\./,
|
|
78
|
+
// IPv6 link-local (fe80::/10) and unique-local (fc00::/7)
|
|
79
|
+
/^fe[89ab][0-9a-f]:/,
|
|
80
|
+
/^f[cd][0-9a-f]{2}:/,
|
|
81
|
+
// IPv4-mapped IPv6 literals are rejected conservatively.
|
|
82
|
+
/^::ffff:/,
|
|
83
|
+
/\.local$/,
|
|
84
|
+
/\.internal$/,
|
|
85
|
+
];
|
|
86
|
+
/** Strips IPv6 brackets and a trailing FQDN dot, then lowercases. */
|
|
87
|
+
function normalizeHostname(hostname) {
|
|
88
|
+
return hostname.replace(/^\[|\]$/g, "").replace(/\.$/, "").toLowerCase();
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Whether a media URL is reachable from Discord's servers.
|
|
92
|
+
*
|
|
93
|
+
* The unfurler fetches media server-side, so `localhost`, loopback, link-local
|
|
94
|
+
* and private-range hosts render as nothing in the widget. Expose local assets
|
|
95
|
+
* through a tunnel (Cloudflare Tunnel, ngrok) during development.
|
|
96
|
+
*/
|
|
97
|
+
export function isPublicMediaUrl(url) {
|
|
98
|
+
let parsed;
|
|
99
|
+
try {
|
|
100
|
+
parsed = new URL(url);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:")
|
|
106
|
+
return false;
|
|
107
|
+
const hostname = normalizeHostname(parsed.hostname);
|
|
108
|
+
return !PRIVATE_HOST_PATTERNS.some((pattern) => pattern.test(hostname));
|
|
109
|
+
}
|
|
110
|
+
/** Serializes `data` exactly as Discord measures it, for the 10 KB ceiling. */
|
|
111
|
+
export function serializeProfileData(data) {
|
|
112
|
+
return JSON.stringify(data);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Validates a `data` payload against Discord's documented limits.
|
|
116
|
+
*
|
|
117
|
+
* @throws {@link ApplicationIdentityProfileError} with a specific `code`.
|
|
118
|
+
*/
|
|
119
|
+
export function assertProfileDataWithinLimits(data, options = {}) {
|
|
120
|
+
const primary = data.primary;
|
|
121
|
+
if (primary) {
|
|
122
|
+
for (const [key, value] of Object.entries(primary)) {
|
|
123
|
+
if (typeof value === "string") {
|
|
124
|
+
assertStringValueLength(key, value);
|
|
125
|
+
}
|
|
126
|
+
else if (isMediaValue(value)) {
|
|
127
|
+
assertMediaUrl(key, value.url, options.allowPrivateMediaUrls);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const dynamic = data.dynamic ?? [];
|
|
132
|
+
if (dynamic.length > APPLICATION_IDENTITY_LIMITS.MaxDynamicFields) {
|
|
133
|
+
throw new ApplicationIdentityProfileError("too_many_dynamic_fields", `dynamic accepts at most ${APPLICATION_IDENTITY_LIMITS.MaxDynamicFields} fields, got ${dynamic.length}`);
|
|
134
|
+
}
|
|
135
|
+
for (const field of dynamic) {
|
|
136
|
+
if (field.name.length > APPLICATION_IDENTITY_LIMITS.MaxDynamicFieldNameLength) {
|
|
137
|
+
throw new ApplicationIdentityProfileError("dynamic_field_name_too_long", `dynamic field name "${field.name}" exceeds ${APPLICATION_IDENTITY_LIMITS.MaxDynamicFieldNameLength} characters`);
|
|
138
|
+
}
|
|
139
|
+
if (field.type === DynamicFieldType.String) {
|
|
140
|
+
assertStringValueLength(field.name, field.value);
|
|
141
|
+
}
|
|
142
|
+
else if (field.type === DynamicFieldType.Media) {
|
|
143
|
+
assertMediaUrl(field.name, field.value.url, options.allowPrivateMediaUrls);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const serialized = serializeProfileData(data);
|
|
147
|
+
if (UTF8_ENCODER.encode(serialized).length > APPLICATION_IDENTITY_LIMITS.MaxSerializedDataBytes) {
|
|
148
|
+
throw new ApplicationIdentityProfileError("payload_too_large", `serialized data exceeds ${APPLICATION_IDENTITY_LIMITS.MaxSerializedDataBytes / 1024}KB; send fewer stats or shorten values`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/** Validates a `username` against Discord's length limit. */
|
|
152
|
+
export function assertUsernameLength(username) {
|
|
153
|
+
if (username.length > APPLICATION_IDENTITY_LIMITS.MaxUsernameLength) {
|
|
154
|
+
throw new ApplicationIdentityProfileError("username_too_long", `username exceeds ${APPLICATION_IDENTITY_LIMITS.MaxUsernameLength} characters`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Builds a `data` object from optional parts, dropping undefined keys so the
|
|
159
|
+
* resulting payload never contains empty `primary`/`dynamic` values.
|
|
160
|
+
*/
|
|
161
|
+
export function buildProfileData(parts) {
|
|
162
|
+
const data = {};
|
|
163
|
+
if (parts.primary)
|
|
164
|
+
data.primary = parts.primary;
|
|
165
|
+
if (parts.dynamic)
|
|
166
|
+
data.dynamic = [...parts.dynamic];
|
|
167
|
+
return Object.keys(data).length > 0 ? data : undefined;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Merges incoming stats into existing stats.
|
|
171
|
+
*
|
|
172
|
+
* `primary` is shallow-merged; `dynamic` fields are matched by `name`, so
|
|
173
|
+
* updating one custom stat leaves the others intact. This is the read-then-write
|
|
174
|
+
* counterpart to Discord's replace-on-PATCH behaviour.
|
|
175
|
+
*/
|
|
176
|
+
export function mergeProfileData(existing, incoming) {
|
|
177
|
+
const primary = { ...existing?.primary, ...incoming.primary };
|
|
178
|
+
const byName = new Map();
|
|
179
|
+
for (const field of existing?.dynamic ?? [])
|
|
180
|
+
byName.set(field.name, field);
|
|
181
|
+
for (const field of incoming.dynamic ?? [])
|
|
182
|
+
byName.set(field.name, field);
|
|
183
|
+
const dynamic = [...byName.values()];
|
|
184
|
+
const merged = {};
|
|
185
|
+
if (Object.keys(primary).length > 0)
|
|
186
|
+
merged.primary = primary;
|
|
187
|
+
if (dynamic.length > 0)
|
|
188
|
+
merged.dynamic = dynamic;
|
|
189
|
+
return Object.keys(merged).length > 0 ? merged : undefined;
|
|
190
|
+
}
|
|
191
|
+
function isMediaValue(value) {
|
|
192
|
+
return (typeof value === "object" &&
|
|
193
|
+
value !== null &&
|
|
194
|
+
typeof value.url === "string");
|
|
195
|
+
}
|
|
196
|
+
function assertStringValueLength(key, value) {
|
|
197
|
+
if (value.length > APPLICATION_IDENTITY_LIMITS.MaxStringValueLength) {
|
|
198
|
+
throw new ApplicationIdentityProfileError("string_value_too_long", `"${key}" exceeds ${APPLICATION_IDENTITY_LIMITS.MaxStringValueLength} characters`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function assertMediaUrl(key, url, allowPrivateMediaUrls) {
|
|
202
|
+
if (allowPrivateMediaUrls)
|
|
203
|
+
return;
|
|
204
|
+
if (!isPublicMediaUrl(url)) {
|
|
205
|
+
throw new ApplicationIdentityProfileError("media_url_not_public", `"${key}" points at "${url}", which Discord cannot fetch. Use a publicly reachable URL or pass allowPrivateMediaUrls.`);
|
|
206
|
+
}
|
|
207
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export { MiniBot, createBot } from "./bot.js";
|
|
2
|
+
export type { BotEnvironment, CreateBotOptions } from "./bot.js";
|
|
3
|
+
export { CommandBuilder, CommandContext, IntegrationType, } from "./commands/CommandBuilder.js";
|
|
4
|
+
export { UserCommandBuilder, MessageCommandBuilder, AppCommandBuilder, } from "./commands/ContextMenuCommandBuilder.js";
|
|
5
|
+
export type { AttachmentOptionBuilder, ChannelOptionBuilder, MentionableOptionBuilder, NumberOptionBuilder, RoleOptionBuilder, StringOptionBuilder, SubcommandBuilder, SubcommandGroupBuilder, UserOptionBuilder, } from "./commands/CommandBuilder.js";
|
|
6
|
+
export { CommandInteractionOptionResolver, createCommandInteraction, } from "./utils/CommandInteractionOptions.js";
|
|
7
|
+
export type { CommandInteraction, MentionableOption, ResolvedUserOption, } from "./utils/CommandInteractionOptions.js";
|
|
8
|
+
export { createAppCommandInteraction, createMessageContextMenuInteraction, createUserContextMenuInteraction, } from "./utils/ContextMenuInteraction.js";
|
|
9
|
+
export type { UserContextMenuInteraction, MessageContextMenuInteraction, AppCommandInteraction, } from "./utils/ContextMenuInteraction.js";
|
|
10
|
+
export type { InteractionCommand, SlashCommandHandler, UserCommandHandler, MessageCommandHandler, AppCommandHandler, CommandHandler, ComponentInteraction, InteractionComponent, InteractionModal, } from "./types/Commands.js";
|
|
11
|
+
export { createMessageComponentInteraction } from "./utils/MessageComponentInteraction.js";
|
|
12
|
+
export type { MessageComponentInteraction, ButtonInteraction, StringSelectInteraction, RoleSelectInteraction, UserSelectInteraction, ChannelSelectInteraction, MentionableSelectInteraction, RadioInteraction, CheckboxInteraction, ResolvedUserOption as ComponentResolvedUserOption, ResolvedMentionableOption as ComponentResolvedMentionableOption, } from "./utils/MessageComponentInteraction.js";
|
|
13
|
+
export { createModalSubmitInteraction } from "./utils/ModalSubmitInteraction.js";
|
|
14
|
+
export type { ModalSubmitInteraction } from "./utils/ModalSubmitInteraction.js";
|
|
15
|
+
export { RoleConnectionMetadataTypes } from "./types/RoleConnectionMetadataTypes.js";
|
|
16
|
+
export { ChannelType } from "./types/ChannelType.js";
|
|
17
|
+
export { InteractionFlags, } from "./types/InteractionFlags.js";
|
|
18
|
+
export { ButtonStyle } from "./types/ButtonStyle.js";
|
|
19
|
+
export { SeparatorSpacingSize } from "./types/SeparatorSpacingSize.js";
|
|
20
|
+
export { MessageFlags, type APIAllowedMentions } from "discord-api-types/v10";
|
|
21
|
+
export { TextInputStyle } from "discord-api-types/v10";
|
|
22
|
+
export { MiniPermFlags } from "./types/PermissionFlags.js";
|
|
23
|
+
export type { ActionRowComponent, MessageActionRowComponent, InteractionComponentData, } from "./types/ComponentTypes.js";
|
|
24
|
+
export * from "./builders/index.js";
|
|
25
|
+
export type { DiscordLocale, LocalizationMap, RegisterMetadataResult, RoleConnectionMetadata, RoleConnectionMetadataInput, } from "./types/RoleConnectionMetadata.js";
|
|
26
|
+
export { DiscordRestClient, DiscordRestApiError, } from "./core/http/DiscordRestClient.js";
|
|
27
|
+
export type { DiscordRestClientOptions, DiscordMemberEditOptions, DiscordRoleOptions, SendGameStatsOptions, LobbyCreateOptions, LobbyModifyOptions, LobbyCreateOrJoinOptions, LobbyMessageSendOptions, } from "./core/http/DiscordRestClient.js";
|
|
28
|
+
export { LobbyMemberFlags, LOBBY_LIMITS, LOBBY_DEVELOPMENT_RATE_LIMITS, canLinkLobby, linkedChannelId, metadataLength, } from "./lobby/Lobby.js";
|
|
29
|
+
export type { APILobby, APILobbyInvite, APILobbyMember, APILobbyMessage, LobbyMemberInput, LobbyMemberUpdateInput, LobbyMetadata, } from "./lobby/Lobby.js";
|
|
30
|
+
export { DynamicFieldType, APPLICATION_IDENTITY_LIMITS, APPLICATION_IDENTITY_PROFILE_ERRORS, ApplicationIdentityProfileError, isPublicMediaUrl, serializeProfileData, assertProfileDataWithinLimits, assertUsernameLength, buildProfileData, mergeProfileData, } from "./identity/ApplicationIdentityProfile.js";
|
|
31
|
+
export type { APIApplicationIdentity, ApplicationIdentityProfile, ApplicationIdentityProfileData, ApplicationIdentityProfileErrorCode, ApplicationIdentityProviderType, DynamicProfileField, PrimaryProfileData, ProfileMedia, UpdateIdentityProfileBody, } from "./identity/ApplicationIdentityProfile.js";
|
|
32
|
+
export { DiscordSentMessage } from "./core/messages/DiscordSentMessage.js";
|
|
33
|
+
export type { DiscordMessageFile, DiscordMessageReference, DiscordReaction, DiscordSendMessageOptions, DiscordStartThreadOptions, DiscordWebhookSendOptions, DiscordCreateThreadOptions, DiscordChannelEditOptions, DiscordPollSpec, DiscordPollAnswer, } from "./core/messages/message-payloads.js";
|
|
34
|
+
export { avatarURL, defaultAvatarURL, userBannerURL, guildIconURL, guildBannerURL, guildSplashURL, emojiURL, stickerURL, attachmentURL, } from "./utils/cdn.js";
|
|
35
|
+
export type { ImageSize, ImageFormat, ImageOptions } from "./utils/cdn.js";
|
|
36
|
+
export { DISCORD_EPOCH, isValidSnowflake, snowflakeToTimestamp, snowflakeToDate, } from "./utils/snowflake.js";
|
|
37
|
+
export { createLocalizationMap, mergeLocalizationMaps, resolveLocalization, } from "./utils/localization.js";
|
|
38
|
+
export { bold, italic, underline, strikethrough, inlineCode, codeBlock, blockQuote, multilineBlockQuote, spoiler, subtext, heading, bulletList, numberedList, maskLink, timestamp, userMention, roleMention, channelMention, slashCommandMention, escapeMarkdown, } from "./utils/formatting.js";
|
|
39
|
+
export type { DiscordTimestampStyle } from "./utils/formatting.js";
|
|
40
|
+
export { DiscordWebhook } from "./core/webhooks/DiscordWebhook.js";
|
|
41
|
+
export { InteractionContext } from "./core/interactions/InteractionContext.js";
|
|
42
|
+
export type { InteractionContextOptions } from "./core/interactions/InteractionContext.js";
|
|
43
|
+
export { verifyAndParseInteraction } from "./core/interactions/InteractionVerifier.js";
|
|
44
|
+
export { InteractionRouter } from "./router/InteractionRouter.js";
|
|
45
|
+
export type { ChatInputHandler, UserMenuHandler, MessageMenuHandler, EntryPointHandler, ComponentHandler, ModalHandler, AutocompleteHandler, RouterMiddleware, RouterErrorHandler, RouterFallback, InteractionRouterOptions, } from "./router/InteractionRouter.js";
|
|
46
|
+
export { AutocompleteContext } from "./router/AutocompleteContext.js";
|
|
47
|
+
export type { FocusedOption } from "./router/AutocompleteContext.js";
|
|
48
|
+
export type { APIRadioComponent, APIRadioOption } from "./types/radio.js";
|
|
49
|
+
export { RADIO_COMPONENT_TYPE, RADIO_GROUP_COMPONENT_TYPE, } from "./types/radio.js";
|
|
50
|
+
export type { APICheckboxComponent, APICheckboxGroupComponent, APICheckboxGroupOption, APICheckboxOption, } from "./types/checkbox.js";
|
|
51
|
+
export { CHECKBOX_COMPONENT_TYPE, CHECKBOX_GROUP_COMPONENT_TYPE, } from "./types/checkbox.js";
|
|
52
|
+
export { CheckboxGroupBuilder } from "./builders/CheckboxGroupBuilder.js";
|
|
53
|
+
export type { CheckboxGroupBuilderData } from "./builders/CheckboxGroupBuilder.js";
|
|
54
|
+
export { ValidationError } from "./types/validation.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export { MiniBot, createBot } from "./bot.js";
|
|
2
|
+
export { CommandBuilder, CommandContext, IntegrationType, } from "./commands/CommandBuilder.js";
|
|
3
|
+
export { UserCommandBuilder, MessageCommandBuilder, AppCommandBuilder, } from "./commands/ContextMenuCommandBuilder.js";
|
|
4
|
+
export { CommandInteractionOptionResolver, createCommandInteraction, } from "./utils/CommandInteractionOptions.js";
|
|
5
|
+
export { createAppCommandInteraction, createMessageContextMenuInteraction, createUserContextMenuInteraction, } from "./utils/ContextMenuInteraction.js";
|
|
6
|
+
export { createMessageComponentInteraction } from "./utils/MessageComponentInteraction.js";
|
|
7
|
+
export { createModalSubmitInteraction } from "./utils/ModalSubmitInteraction.js";
|
|
8
|
+
export { RoleConnectionMetadataTypes } from "./types/RoleConnectionMetadataTypes.js";
|
|
9
|
+
export { ChannelType } from "./types/ChannelType.js";
|
|
10
|
+
export { InteractionFlags, } from "./types/InteractionFlags.js";
|
|
11
|
+
export { ButtonStyle } from "./types/ButtonStyle.js";
|
|
12
|
+
export { SeparatorSpacingSize } from "./types/SeparatorSpacingSize.js";
|
|
13
|
+
export { MessageFlags } from "discord-api-types/v10";
|
|
14
|
+
export { TextInputStyle } from "discord-api-types/v10";
|
|
15
|
+
export { MiniPermFlags } from "./types/PermissionFlags.js";
|
|
16
|
+
export * from "./builders/index.js";
|
|
17
|
+
// New v10 core modules
|
|
18
|
+
export { DiscordRestClient, DiscordRestApiError, } from "./core/http/DiscordRestClient.js";
|
|
19
|
+
export { LobbyMemberFlags, LOBBY_LIMITS, LOBBY_DEVELOPMENT_RATE_LIMITS, canLinkLobby, linkedChannelId, metadataLength, } from "./lobby/Lobby.js";
|
|
20
|
+
export { DynamicFieldType, APPLICATION_IDENTITY_LIMITS, APPLICATION_IDENTITY_PROFILE_ERRORS, ApplicationIdentityProfileError, isPublicMediaUrl, serializeProfileData, assertProfileDataWithinLimits, assertUsernameLength, buildProfileData, mergeProfileData, } from "./identity/ApplicationIdentityProfile.js";
|
|
21
|
+
export { DiscordSentMessage } from "./core/messages/DiscordSentMessage.js";
|
|
22
|
+
export { avatarURL, defaultAvatarURL, userBannerURL, guildIconURL, guildBannerURL, guildSplashURL, emojiURL, stickerURL, attachmentURL, } from "./utils/cdn.js";
|
|
23
|
+
export { DISCORD_EPOCH, isValidSnowflake, snowflakeToTimestamp, snowflakeToDate, } from "./utils/snowflake.js";
|
|
24
|
+
export { createLocalizationMap, mergeLocalizationMaps, resolveLocalization, } from "./utils/localization.js";
|
|
25
|
+
export { bold, italic, underline, strikethrough, inlineCode, codeBlock, blockQuote, multilineBlockQuote, spoiler, subtext, heading, bulletList, numberedList, maskLink, timestamp, userMention, roleMention, channelMention, slashCommandMention, escapeMarkdown, } from "./utils/formatting.js";
|
|
26
|
+
export { DiscordWebhook } from "./core/webhooks/DiscordWebhook.js";
|
|
27
|
+
export { InteractionContext } from "./core/interactions/InteractionContext.js";
|
|
28
|
+
export { verifyAndParseInteraction } from "./core/interactions/InteractionVerifier.js";
|
|
29
|
+
export { InteractionRouter } from "./router/InteractionRouter.js";
|
|
30
|
+
export { AutocompleteContext } from "./router/AutocompleteContext.js";
|
|
31
|
+
export { RADIO_COMPONENT_TYPE, RADIO_GROUP_COMPONENT_TYPE, } from "./types/radio.js";
|
|
32
|
+
export { CHECKBOX_COMPONENT_TYPE, CHECKBOX_GROUP_COMPONENT_TYPE, } from "./types/checkbox.js";
|
|
33
|
+
export { CheckboxGroupBuilder } from "./builders/CheckboxGroupBuilder.js";
|
|
34
|
+
export { ValidationError } from "./types/validation.js";
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { APIChannel, APIUser } from "discord-api-types/v10";
|
|
2
|
+
/**
|
|
3
|
+
* Discord lobbies and **Linked Channels**: binding an in-game lobby to a guild
|
|
4
|
+
* text channel so messages flow both ways, and minting on-demand invites so a
|
|
5
|
+
* lobby's players can join the server.
|
|
6
|
+
*
|
|
7
|
+
* @see {@link https://docs.discord.com/developers/resources/lobby}
|
|
8
|
+
* @see {@link https://docs.discord.com/developers/discord-social-sdk/development-guides/linked-channels}
|
|
9
|
+
*
|
|
10
|
+
* ## Two things the HTTP API does *not* give you
|
|
11
|
+
*
|
|
12
|
+
* 1. **`isLinkable` and `isViewableAndWriteableByAllMembers` are Social SDK
|
|
13
|
+
* fields, not HTTP fields.** The C++/Unity SDK computes them client-side from
|
|
14
|
+
* channel validity (text channel? age-restricted? already linked?) and the
|
|
15
|
+
* user's permissions. Over HTTP you get the raw channel list and must derive
|
|
16
|
+
* the same answer yourself — or let the `PATCH .../channel-linking` call fail.
|
|
17
|
+
* 2. **Private channels can be linked.** Discord allows any channel the user can
|
|
18
|
+
* access, including a private `#admins`. Read/write permissions are enforced
|
|
19
|
+
* only in the Discord client, so **every lobby member** can read and post in
|
|
20
|
+
* the linked channel in-game. Warn the player performing the link; the
|
|
21
|
+
* library cannot tell you which channel is private.
|
|
22
|
+
*
|
|
23
|
+
* ## Tokens
|
|
24
|
+
*
|
|
25
|
+
* Lobby endpoints acting *on behalf of a user* (channel linking, lobby
|
|
26
|
+
* messages, self-invites, create-or-join) need a **Bearer** user token with the
|
|
27
|
+
* `sdk.social_layer` scope — not the bot token. Application-scoped calls
|
|
28
|
+
* (create/modify/delete lobby, member administration, invites for another user)
|
|
29
|
+
* use the bot token, which the client applies by default.
|
|
30
|
+
*
|
|
31
|
+
* ## Rate limits
|
|
32
|
+
*
|
|
33
|
+
* Unapproved apps get per-application development limits. Channel linking is
|
|
34
|
+
* capped at **20 per 2 hours**, so a tight test loop will exhaust it — see
|
|
35
|
+
* {@link LOBBY_DEVELOPMENT_RATE_LIMITS}.
|
|
36
|
+
*/
|
|
37
|
+
/** Lobby member flags, combined as a bitfield. */
|
|
38
|
+
export declare const LobbyMemberFlags: {
|
|
39
|
+
/** The user can link a text channel to a lobby. Required to link *and* unlink. */
|
|
40
|
+
readonly CanLinkLobby: number;
|
|
41
|
+
};
|
|
42
|
+
export type LobbyMemberFlags = (typeof LobbyMemberFlags)[keyof typeof LobbyMemberFlags];
|
|
43
|
+
/** Arbitrary string key/value pairs; combined length capped at 1000 characters. */
|
|
44
|
+
export type LobbyMetadata = Record<string, string>;
|
|
45
|
+
/** A lobby member. */
|
|
46
|
+
export type APILobbyMember = {
|
|
47
|
+
/** Discord user ID. */
|
|
48
|
+
id: string;
|
|
49
|
+
metadata?: LobbyMetadata | null;
|
|
50
|
+
/** Lobby member flags, combined as a bitfield. */
|
|
51
|
+
flags?: number;
|
|
52
|
+
/**
|
|
53
|
+
* 1–80 character display name such as an in-game character name. Settable
|
|
54
|
+
* over HTTP only; expose it via `MessageHandle::AdditionalName` in the SDK.
|
|
55
|
+
*/
|
|
56
|
+
additional_name?: string;
|
|
57
|
+
};
|
|
58
|
+
/** A lobby. */
|
|
59
|
+
export type APILobby = {
|
|
60
|
+
id: string;
|
|
61
|
+
/** The application that created the lobby. */
|
|
62
|
+
application_id: string;
|
|
63
|
+
metadata?: LobbyMetadata | null;
|
|
64
|
+
members: APILobbyMember[];
|
|
65
|
+
/** The guild channel linked to the lobby, when one is. */
|
|
66
|
+
linked_channel?: APIChannel;
|
|
67
|
+
};
|
|
68
|
+
/** A message sent to a lobby, forwarded to the linked channel when one exists. */
|
|
69
|
+
export type APILobbyMessage = {
|
|
70
|
+
id: string;
|
|
71
|
+
/** Message type. */
|
|
72
|
+
type: number;
|
|
73
|
+
content: string;
|
|
74
|
+
/** ID of the lobby this message was sent to. */
|
|
75
|
+
lobby_id: string;
|
|
76
|
+
/** Included for compatibility with the messages interface; equal to `lobby_id`. */
|
|
77
|
+
channel_id: string;
|
|
78
|
+
author: APIUser;
|
|
79
|
+
/** The author's `additional_name`, captured when the message was sent. */
|
|
80
|
+
lobby_member?: {
|
|
81
|
+
additional_name: string;
|
|
82
|
+
};
|
|
83
|
+
/** Dispatch-only metadata; not persisted on the linked channel message. */
|
|
84
|
+
metadata?: LobbyMetadata | null;
|
|
85
|
+
moderation_metadata?: LobbyMetadata | null;
|
|
86
|
+
flags: number;
|
|
87
|
+
application_id: string;
|
|
88
|
+
};
|
|
89
|
+
/** A single-use invite to a lobby's linked channel; expires after one hour. */
|
|
90
|
+
export type APILobbyInvite = {
|
|
91
|
+
/** The invite code for the lobby's linked channel. */
|
|
92
|
+
code: string;
|
|
93
|
+
};
|
|
94
|
+
/** Payload for creating or modifying a lobby member. */
|
|
95
|
+
export type LobbyMemberInput = {
|
|
96
|
+
/** Discord user ID. */
|
|
97
|
+
id: string;
|
|
98
|
+
metadata?: LobbyMetadata | null;
|
|
99
|
+
/** Lobby member flags, combined as a bitfield. Set `CanLinkLobby` here. */
|
|
100
|
+
flags?: number;
|
|
101
|
+
/** 1–80 characters. Omit to preserve the current value, or send `null` to clear. */
|
|
102
|
+
additional_name?: string | null;
|
|
103
|
+
};
|
|
104
|
+
/** A member entry for {@link bulkUpdateLobbyMembers}; may also remove. */
|
|
105
|
+
export type LobbyMemberUpdateInput = LobbyMemberInput & {
|
|
106
|
+
/** When `true` the member is removed instead of upserted. Defaults to `false`. */
|
|
107
|
+
remove_member?: boolean;
|
|
108
|
+
};
|
|
109
|
+
/** Documented limits, encoded so callers fail fast instead of at the API. */
|
|
110
|
+
export declare const LOBBY_LIMITS: {
|
|
111
|
+
/** Combined length of a `metadata` dictionary. */
|
|
112
|
+
readonly MaxMetadataLength: 1000;
|
|
113
|
+
/** Members accepted per create/modify request. */
|
|
114
|
+
readonly MaxMembersPerRequest: 25;
|
|
115
|
+
readonly MinAdditionalNameLength: 1;
|
|
116
|
+
readonly MaxAdditionalNameLength: 80;
|
|
117
|
+
/** Length of the `secret` used by create-or-join. */
|
|
118
|
+
readonly MaxSecretLength: 250;
|
|
119
|
+
/** `idle_timeout_seconds` bounds, in seconds. */
|
|
120
|
+
readonly MinIdleTimeoutSeconds: 5;
|
|
121
|
+
readonly MaxIdleTimeoutSeconds: 604800;
|
|
122
|
+
/** Messages returned per read. */
|
|
123
|
+
readonly MaxMessagesPerPage: 200;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Default per-application development rate limits, each per **2 hour** window.
|
|
127
|
+
* They apply application-wide (not per user), and production apps can request
|
|
128
|
+
* higher ceilings.
|
|
129
|
+
*/
|
|
130
|
+
export declare const LOBBY_DEVELOPMENT_RATE_LIMITS: {
|
|
131
|
+
/** `POST|PUT /lobbies` and `PATCH|DELETE /lobbies/{id}`. */
|
|
132
|
+
readonly LobbyMutation: 100;
|
|
133
|
+
/** `PUT|DELETE /lobbies/{id}/members/{user.id}` and `.../members/bulk`. */
|
|
134
|
+
readonly MemberMutation: 100;
|
|
135
|
+
/** `PATCH /lobbies/{id}/channel-linking` — the tightest limit of the set. */
|
|
136
|
+
readonly ChannelLinking: 20;
|
|
137
|
+
/** `POST /lobbies/{id}/messages`. */
|
|
138
|
+
readonly MessageSend: 100;
|
|
139
|
+
/** `POST /lobbies/{id}/members/{@me|user.id}/invites`. */
|
|
140
|
+
readonly Invite: 100;
|
|
141
|
+
};
|
|
142
|
+
/** Whether a lobby member may link (or unlink) a channel to the lobby. */
|
|
143
|
+
export declare function canLinkLobby(member: Pick<APILobbyMember, "flags">): boolean;
|
|
144
|
+
/** The ID of the channel linked to a lobby, if any. */
|
|
145
|
+
export declare function linkedChannelId(lobby: Pick<APILobby, "linked_channel">): string | undefined;
|
|
146
|
+
/**
|
|
147
|
+
* Combined character length of a metadata dictionary, for checking against
|
|
148
|
+
* {@link LOBBY_LIMITS.MaxMetadataLength} before the request.
|
|
149
|
+
*/
|
|
150
|
+
export declare function metadataLength(metadata: LobbyMetadata | null | undefined): number;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discord lobbies and **Linked Channels**: binding an in-game lobby to a guild
|
|
3
|
+
* text channel so messages flow both ways, and minting on-demand invites so a
|
|
4
|
+
* lobby's players can join the server.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://docs.discord.com/developers/resources/lobby}
|
|
7
|
+
* @see {@link https://docs.discord.com/developers/discord-social-sdk/development-guides/linked-channels}
|
|
8
|
+
*
|
|
9
|
+
* ## Two things the HTTP API does *not* give you
|
|
10
|
+
*
|
|
11
|
+
* 1. **`isLinkable` and `isViewableAndWriteableByAllMembers` are Social SDK
|
|
12
|
+
* fields, not HTTP fields.** The C++/Unity SDK computes them client-side from
|
|
13
|
+
* channel validity (text channel? age-restricted? already linked?) and the
|
|
14
|
+
* user's permissions. Over HTTP you get the raw channel list and must derive
|
|
15
|
+
* the same answer yourself — or let the `PATCH .../channel-linking` call fail.
|
|
16
|
+
* 2. **Private channels can be linked.** Discord allows any channel the user can
|
|
17
|
+
* access, including a private `#admins`. Read/write permissions are enforced
|
|
18
|
+
* only in the Discord client, so **every lobby member** can read and post in
|
|
19
|
+
* the linked channel in-game. Warn the player performing the link; the
|
|
20
|
+
* library cannot tell you which channel is private.
|
|
21
|
+
*
|
|
22
|
+
* ## Tokens
|
|
23
|
+
*
|
|
24
|
+
* Lobby endpoints acting *on behalf of a user* (channel linking, lobby
|
|
25
|
+
* messages, self-invites, create-or-join) need a **Bearer** user token with the
|
|
26
|
+
* `sdk.social_layer` scope — not the bot token. Application-scoped calls
|
|
27
|
+
* (create/modify/delete lobby, member administration, invites for another user)
|
|
28
|
+
* use the bot token, which the client applies by default.
|
|
29
|
+
*
|
|
30
|
+
* ## Rate limits
|
|
31
|
+
*
|
|
32
|
+
* Unapproved apps get per-application development limits. Channel linking is
|
|
33
|
+
* capped at **20 per 2 hours**, so a tight test loop will exhaust it — see
|
|
34
|
+
* {@link LOBBY_DEVELOPMENT_RATE_LIMITS}.
|
|
35
|
+
*/
|
|
36
|
+
/** Lobby member flags, combined as a bitfield. */
|
|
37
|
+
export const LobbyMemberFlags = {
|
|
38
|
+
/** The user can link a text channel to a lobby. Required to link *and* unlink. */
|
|
39
|
+
CanLinkLobby: 1 << 0,
|
|
40
|
+
};
|
|
41
|
+
/** Documented limits, encoded so callers fail fast instead of at the API. */
|
|
42
|
+
export const LOBBY_LIMITS = {
|
|
43
|
+
/** Combined length of a `metadata` dictionary. */
|
|
44
|
+
MaxMetadataLength: 1000,
|
|
45
|
+
/** Members accepted per create/modify request. */
|
|
46
|
+
MaxMembersPerRequest: 25,
|
|
47
|
+
MinAdditionalNameLength: 1,
|
|
48
|
+
MaxAdditionalNameLength: 80,
|
|
49
|
+
/** Length of the `secret` used by create-or-join. */
|
|
50
|
+
MaxSecretLength: 250,
|
|
51
|
+
/** `idle_timeout_seconds` bounds, in seconds. */
|
|
52
|
+
MinIdleTimeoutSeconds: 5,
|
|
53
|
+
MaxIdleTimeoutSeconds: 604_800,
|
|
54
|
+
/** Messages returned per read. */
|
|
55
|
+
MaxMessagesPerPage: 200,
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Default per-application development rate limits, each per **2 hour** window.
|
|
59
|
+
* They apply application-wide (not per user), and production apps can request
|
|
60
|
+
* higher ceilings.
|
|
61
|
+
*/
|
|
62
|
+
export const LOBBY_DEVELOPMENT_RATE_LIMITS = {
|
|
63
|
+
/** `POST|PUT /lobbies` and `PATCH|DELETE /lobbies/{id}`. */
|
|
64
|
+
LobbyMutation: 100,
|
|
65
|
+
/** `PUT|DELETE /lobbies/{id}/members/{user.id}` and `.../members/bulk`. */
|
|
66
|
+
MemberMutation: 100,
|
|
67
|
+
/** `PATCH /lobbies/{id}/channel-linking` — the tightest limit of the set. */
|
|
68
|
+
ChannelLinking: 20,
|
|
69
|
+
/** `POST /lobbies/{id}/messages`. */
|
|
70
|
+
MessageSend: 100,
|
|
71
|
+
/** `POST /lobbies/{id}/members/{@me|user.id}/invites`. */
|
|
72
|
+
Invite: 100,
|
|
73
|
+
};
|
|
74
|
+
/** Whether a lobby member may link (or unlink) a channel to the lobby. */
|
|
75
|
+
export function canLinkLobby(member) {
|
|
76
|
+
return ((member.flags ?? 0) & LobbyMemberFlags.CanLinkLobby) === LobbyMemberFlags.CanLinkLobby;
|
|
77
|
+
}
|
|
78
|
+
/** The ID of the channel linked to a lobby, if any. */
|
|
79
|
+
export function linkedChannelId(lobby) {
|
|
80
|
+
return lobby.linked_channel?.id;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Combined character length of a metadata dictionary, for checking against
|
|
84
|
+
* {@link LOBBY_LIMITS.MaxMetadataLength} before the request.
|
|
85
|
+
*/
|
|
86
|
+
export function metadataLength(metadata) {
|
|
87
|
+
if (!metadata)
|
|
88
|
+
return 0;
|
|
89
|
+
return Object.entries(metadata).reduce((total, [key, value]) => total + key.length + value.length, 0);
|
|
90
|
+
}
|