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,118 @@
|
|
|
1
|
+
import { MessageFlags, } from "discord-api-types/v10";
|
|
2
|
+
import { resolveJSONEncodable } from "../builders/shared.js";
|
|
3
|
+
import { ComponentType, } from "discord-api-types/v10";
|
|
4
|
+
import { InteractionFlags } from "../types/InteractionFlags.js";
|
|
5
|
+
/**
|
|
6
|
+
* Message component types that require the IsComponentsV2 message flag.
|
|
7
|
+
* Label (18), FileUpload (19), RadioGroup (21), CheckboxGroup (22) and
|
|
8
|
+
* Checkbox (23) are modal-only components and intentionally excluded.
|
|
9
|
+
*/
|
|
10
|
+
const COMPONENTS_V2_TYPES = new Set([
|
|
11
|
+
ComponentType.Section,
|
|
12
|
+
ComponentType.TextDisplay,
|
|
13
|
+
ComponentType.Thumbnail,
|
|
14
|
+
ComponentType.MediaGallery,
|
|
15
|
+
ComponentType.File,
|
|
16
|
+
ComponentType.Separator,
|
|
17
|
+
ComponentType.Container,
|
|
18
|
+
]);
|
|
19
|
+
/**
|
|
20
|
+
* Normalises helper flag enums into the raw Discord `MessageFlags` bitfield.
|
|
21
|
+
*
|
|
22
|
+
* @param flags - A flag or array of flags from helper enums or raw Discord flags.
|
|
23
|
+
* @returns The value coerced to a `MessageFlags` compatible bitfield.
|
|
24
|
+
*/
|
|
25
|
+
export function normaliseMessageFlags(flags) {
|
|
26
|
+
if (flags === undefined) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
if (Array.isArray(flags)) {
|
|
30
|
+
if (flags.length === 0) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
// Combine multiple flags using bitwise OR
|
|
34
|
+
return flags.reduce((acc, flag) => (acc | flag), 0);
|
|
35
|
+
}
|
|
36
|
+
return flags;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Ensures helper message payloads include correctly normalised message flags.
|
|
40
|
+
*
|
|
41
|
+
* @param data - The helper-supplied response payload.
|
|
42
|
+
* @returns A payload safe to send to Discord's API.
|
|
43
|
+
*/
|
|
44
|
+
export function normaliseInteractionMessageData(data) {
|
|
45
|
+
if (!data) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
49
|
+
const responseData = { ...data };
|
|
50
|
+
if (data.components) {
|
|
51
|
+
const components = resolveJSONEncodable(data.components);
|
|
52
|
+
if (Array.isArray(components)) {
|
|
53
|
+
responseData.components = components.map((c) => resolveJSONEncodable(c));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (data.embeds) {
|
|
57
|
+
responseData.embeds = data.embeds.map((e) => resolveJSONEncodable(e));
|
|
58
|
+
}
|
|
59
|
+
const normalisedFlags = normaliseMessageFlags(data.flags);
|
|
60
|
+
if (data.ephemeral) {
|
|
61
|
+
responseData.flags = ((normalisedFlags ?? 0) | MessageFlags.Ephemeral);
|
|
62
|
+
}
|
|
63
|
+
else if (normalisedFlags !== undefined) {
|
|
64
|
+
responseData.flags = normalisedFlags;
|
|
65
|
+
}
|
|
66
|
+
delete responseData.ephemeral;
|
|
67
|
+
// Automatically handle IsComponentsV2 flag if Components V2 are detected
|
|
68
|
+
if (responseData.components && Array.isArray(responseData.components)) {
|
|
69
|
+
if (containsComponentsV2(responseData.components)) {
|
|
70
|
+
const currentFlags = responseData.flags ?? 0;
|
|
71
|
+
responseData.flags = (currentFlags | (0x1 << 15));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const flags = Number(responseData.flags ?? 0);
|
|
75
|
+
if ((flags & InteractionFlags.IsComponentsV2) === InteractionFlags.IsComponentsV2) {
|
|
76
|
+
const forbiddenFields = [];
|
|
77
|
+
if (responseData.content !== undefined && responseData.content !== null)
|
|
78
|
+
forbiddenFields.push("content");
|
|
79
|
+
if (responseData.embeds !== undefined && responseData.embeds !== null)
|
|
80
|
+
forbiddenFields.push("embeds");
|
|
81
|
+
if (forbiddenFields.length > 0) {
|
|
82
|
+
throw new Error(`[MiniInteraction] ${forbiddenFields.join(", ")} cannot be used together with the IsComponentsV2 flag. Use TextDisplay components instead.`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return responseData;
|
|
86
|
+
}
|
|
87
|
+
function containsComponentsV2(components) {
|
|
88
|
+
return components.some((component) => componentUsesComponentsV2(component));
|
|
89
|
+
}
|
|
90
|
+
function componentUsesComponentsV2(component) {
|
|
91
|
+
const resolved = resolveComponentLike(component);
|
|
92
|
+
if (!resolved || typeof resolved !== "object") {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
const type = resolved.type;
|
|
96
|
+
if (typeof type !== "number") {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
if (COMPONENTS_V2_TYPES.has(type)) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
if (type === ComponentType.ActionRow) {
|
|
103
|
+
const rowComponents = resolved.components;
|
|
104
|
+
if (Array.isArray(rowComponents)) {
|
|
105
|
+
return containsComponentsV2(rowComponents);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
function resolveComponentLike(component) {
|
|
111
|
+
if (component && typeof component === "object" && "toJSON" in component) {
|
|
112
|
+
const encoder = component;
|
|
113
|
+
if (typeof encoder.toJSON === "function") {
|
|
114
|
+
return encoder.toJSON();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return component;
|
|
118
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Locale } from "discord-api-types/v10";
|
|
2
|
+
import type { DiscordLocale, LocalizationMap } from "../types/RoleConnectionMetadata.js";
|
|
3
|
+
/** Typed alias so consumers can build localisation maps against real locales. */
|
|
4
|
+
export type { DiscordLocale, LocalizationMap };
|
|
5
|
+
/**
|
|
6
|
+
* Creates a `LocalizationMap` with full key typing against Discord's locales.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const name = createLocalizationMap({
|
|
10
|
+
* "en-US": "Balance",
|
|
11
|
+
* tr: "Bakiye",
|
|
12
|
+
* de: "Guthaben",
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function createLocalizationMap(entries: Partial<Record<Locale, string>>): LocalizationMap;
|
|
17
|
+
/** Shallowly merges several maps; later entries win. */
|
|
18
|
+
export declare function mergeLocalizationMaps(...maps: Array<LocalizationMap | undefined>): LocalizationMap;
|
|
19
|
+
/**
|
|
20
|
+
* Resolves the best string for a locale using a fallback chain:
|
|
21
|
+
* exact match (`pt-BR`) → base language (`pt`) → provided default.
|
|
22
|
+
*
|
|
23
|
+
* Useful when rendering user-facing content from your own localisation data.
|
|
24
|
+
*/
|
|
25
|
+
export declare function resolveLocalization(map: LocalizationMap | undefined, locale: string, fallback: string): string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a `LocalizationMap` with full key typing against Discord's locales.
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* const name = createLocalizationMap({
|
|
6
|
+
* "en-US": "Balance",
|
|
7
|
+
* tr: "Bakiye",
|
|
8
|
+
* de: "Guthaben",
|
|
9
|
+
* });
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export function createLocalizationMap(entries) {
|
|
13
|
+
return { ...entries };
|
|
14
|
+
}
|
|
15
|
+
/** Shallowly merges several maps; later entries win. */
|
|
16
|
+
export function mergeLocalizationMaps(...maps) {
|
|
17
|
+
return Object.assign({}, ...maps.filter(Boolean));
|
|
18
|
+
}
|
|
19
|
+
const BASE_LOCALE = (locale) => locale.split("-")[0];
|
|
20
|
+
/**
|
|
21
|
+
* Resolves the best string for a locale using a fallback chain:
|
|
22
|
+
* exact match (`pt-BR`) → base language (`pt`) → provided default.
|
|
23
|
+
*
|
|
24
|
+
* Useful when rendering user-facing content from your own localisation data.
|
|
25
|
+
*/
|
|
26
|
+
export function resolveLocalization(map, locale, fallback) {
|
|
27
|
+
if (!map)
|
|
28
|
+
return fallback;
|
|
29
|
+
const exact = map[locale];
|
|
30
|
+
if (exact !== undefined)
|
|
31
|
+
return exact;
|
|
32
|
+
const base = BASE_LOCALE(locale);
|
|
33
|
+
for (const [key, value] of Object.entries(map)) {
|
|
34
|
+
if (value !== undefined && BASE_LOCALE(key) === base)
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
return fallback;
|
|
38
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discord Snowflake utilities.
|
|
3
|
+
*
|
|
4
|
+
* A snowflake encodes its creation time: `(id >> 22) + Discord epoch`.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://discord.com/developers/docs/reference#snowflakes}
|
|
7
|
+
*/
|
|
8
|
+
/** 2015-01-01T00:00:00.000Z, the first millisecond of Discord's epoch. */
|
|
9
|
+
export declare const DISCORD_EPOCH = 1420070400000n;
|
|
10
|
+
/** Checks whether a value is a well-formed snowflake (17–20 digits). */
|
|
11
|
+
export declare function isValidSnowflake(value: unknown): value is string;
|
|
12
|
+
/**
|
|
13
|
+
* Extracts the creation timestamp (ms since Unix epoch) from a snowflake.
|
|
14
|
+
*
|
|
15
|
+
* @throws when the input is not a valid snowflake.
|
|
16
|
+
*/
|
|
17
|
+
export declare function snowflakeToTimestamp(id: string): number;
|
|
18
|
+
/** Convenience wrapper returning a `Date` for a snowflake's creation time. */
|
|
19
|
+
export declare function snowflakeToDate(id: string): Date;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discord Snowflake utilities.
|
|
3
|
+
*
|
|
4
|
+
* A snowflake encodes its creation time: `(id >> 22) + Discord epoch`.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://discord.com/developers/docs/reference#snowflakes}
|
|
7
|
+
*/
|
|
8
|
+
/** 2015-01-01T00:00:00.000Z, the first millisecond of Discord's epoch. */
|
|
9
|
+
export const DISCORD_EPOCH = 1420070400000n;
|
|
10
|
+
const SNOWFLAKE_REGEX = /^\d{17,20}$/;
|
|
11
|
+
/** Checks whether a value is a well-formed snowflake (17–20 digits). */
|
|
12
|
+
export function isValidSnowflake(value) {
|
|
13
|
+
return typeof value === "string" && SNOWFLAKE_REGEX.test(value);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Extracts the creation timestamp (ms since Unix epoch) from a snowflake.
|
|
17
|
+
*
|
|
18
|
+
* @throws when the input is not a valid snowflake.
|
|
19
|
+
*/
|
|
20
|
+
export function snowflakeToTimestamp(id) {
|
|
21
|
+
assertSnowflake(id);
|
|
22
|
+
return Number((BigInt(id) >> 22n) + DISCORD_EPOCH);
|
|
23
|
+
}
|
|
24
|
+
/** Convenience wrapper returning a `Date` for a snowflake's creation time. */
|
|
25
|
+
export function snowflakeToDate(id) {
|
|
26
|
+
return new Date(snowflakeToTimestamp(id));
|
|
27
|
+
}
|
|
28
|
+
function assertSnowflake(id) {
|
|
29
|
+
if (!isValidSnowflake(id)) {
|
|
30
|
+
throw new Error(`[MiniInteraction] "${id}" is not a valid snowflake (expected 17-20 digits).`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import type { APIApplication, APIAttachment, APIChannel, APIEntitlement, APIGuild, APIMessageActivity, APIUser } from "discord-api-types/v10";
|
|
2
|
+
/**
|
|
3
|
+
* Webhook Events ("outgoing webhooks") are one-way HTTP events Discord posts to
|
|
4
|
+
* an app's **Webhook Event URL** when something happens in Discord — as opposed
|
|
5
|
+
* to incoming webhooks, which an external service triggers.
|
|
6
|
+
*
|
|
7
|
+
* Unlike Gateway events they are **not realtime and not guaranteed to be in
|
|
8
|
+
* order**, so handlers must be idempotent and reconcile state rather than
|
|
9
|
+
* assume sequencing.
|
|
10
|
+
*
|
|
11
|
+
* @see {@link https://docs.discord.com/developers/events/webhook-events}
|
|
12
|
+
*/
|
|
13
|
+
/** Outer payload `type`. */
|
|
14
|
+
export declare const WebhookEventPayloadType: {
|
|
15
|
+
/** Sent when Discord validates your endpoint URL. Answer with an empty `204`. */
|
|
16
|
+
readonly Ping: 0;
|
|
17
|
+
/** A real event; the details live in `event`. */
|
|
18
|
+
readonly Event: 1;
|
|
19
|
+
};
|
|
20
|
+
export type WebhookEventPayloadType = (typeof WebhookEventPayloadType)[keyof typeof WebhookEventPayloadType];
|
|
21
|
+
/** Installation context of an authorization: `0` = server, `1` = user account. */
|
|
22
|
+
export declare const WebhookEventIntegrationType: {
|
|
23
|
+
readonly GuildInstall: 0;
|
|
24
|
+
readonly UserInstall: 1;
|
|
25
|
+
};
|
|
26
|
+
export type WebhookEventIntegrationType = (typeof WebhookEventIntegrationType)[keyof typeof WebhookEventIntegrationType];
|
|
27
|
+
/**
|
|
28
|
+
* Every event name an app can subscribe to.
|
|
29
|
+
*
|
|
30
|
+
* `ENTITLEMENT_UPDATE` and `ENTITLEMENT_DELETE` are included here even though
|
|
31
|
+
* `discord-interactions`' own `WebhookEventType` enum predates them.
|
|
32
|
+
*/
|
|
33
|
+
export declare const WebhookEventType: {
|
|
34
|
+
/** The app was authorized by a user to a server or to their account. */
|
|
35
|
+
readonly ApplicationAuthorized: "APPLICATION_AUTHORIZED";
|
|
36
|
+
/** The app was deauthorized by a user. */
|
|
37
|
+
readonly ApplicationDeauthorized: "APPLICATION_DEAUTHORIZED";
|
|
38
|
+
/** An entitlement was created. */
|
|
39
|
+
readonly EntitlementCreate: "ENTITLEMENT_CREATE";
|
|
40
|
+
/** An entitlement was updated. */
|
|
41
|
+
readonly EntitlementUpdate: "ENTITLEMENT_UPDATE";
|
|
42
|
+
/** An entitlement was deleted. */
|
|
43
|
+
readonly EntitlementDelete: "ENTITLEMENT_DELETE";
|
|
44
|
+
/** A user was added to a Quest. Documented, but currently unavailable to apps. */
|
|
45
|
+
readonly QuestUserEnrollment: "QUEST_USER_ENROLLMENT";
|
|
46
|
+
/** A message was created in a lobby. */
|
|
47
|
+
readonly LobbyMessageCreate: "LOBBY_MESSAGE_CREATE";
|
|
48
|
+
/** A message was updated in a lobby. */
|
|
49
|
+
readonly LobbyMessageUpdate: "LOBBY_MESSAGE_UPDATE";
|
|
50
|
+
/** A message was deleted from a lobby. */
|
|
51
|
+
readonly LobbyMessageDelete: "LOBBY_MESSAGE_DELETE";
|
|
52
|
+
/** A direct message was created during an active Social SDK session. */
|
|
53
|
+
readonly GameDirectMessageCreate: "GAME_DIRECT_MESSAGE_CREATE";
|
|
54
|
+
/** A direct message was updated during an active Social SDK session. */
|
|
55
|
+
readonly GameDirectMessageUpdate: "GAME_DIRECT_MESSAGE_UPDATE";
|
|
56
|
+
/** A direct message was deleted during an active Social SDK session. */
|
|
57
|
+
readonly GameDirectMessageDelete: "GAME_DIRECT_MESSAGE_DELETE";
|
|
58
|
+
};
|
|
59
|
+
export type WebhookEventType = (typeof WebhookEventType)[keyof typeof WebhookEventType];
|
|
60
|
+
/** `APPLICATION_AUTHORIZED` — the app was added to a server or a user's account. */
|
|
61
|
+
export type ApplicationAuthorizedEventData = {
|
|
62
|
+
/** `0` when installed to a server, `1` when installed to a user's account. */
|
|
63
|
+
integration_type?: WebhookEventIntegrationType;
|
|
64
|
+
/** The user who authorized the app. */
|
|
65
|
+
user: APIUser;
|
|
66
|
+
/** OAuth2 scopes the user granted. */
|
|
67
|
+
scopes: string[];
|
|
68
|
+
/** Present when `integration_type` is `0`. */
|
|
69
|
+
guild?: APIGuild;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* `APPLICATION_DEAUTHORIZED` — the app was deauthorized by a user.
|
|
73
|
+
*
|
|
74
|
+
* For Social SDK apps this is the **only out-of-game signal that a user's link
|
|
75
|
+
* state changed**. Every revocation is mechanically an unmerge: the Discord
|
|
76
|
+
* account reverts to a provisional account and that user's OAuth2 tokens become
|
|
77
|
+
* invalid, so you must fall back to the provisional account flow. Missing this
|
|
78
|
+
* event means the next token use fails instead.
|
|
79
|
+
*/
|
|
80
|
+
export type ApplicationDeauthorizedEventData = {
|
|
81
|
+
/** The user who deauthorized the app. */
|
|
82
|
+
user: APIUser;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* A message sent in a lobby or in a
|
|
86
|
+
* [Linked Channel](https://docs.discord.com/developers/discord-social-sdk/development-guides/linked-channels).
|
|
87
|
+
*/
|
|
88
|
+
export type LobbyMessageEventData = {
|
|
89
|
+
id: string;
|
|
90
|
+
/** Message type. */
|
|
91
|
+
type: number;
|
|
92
|
+
content: string;
|
|
93
|
+
/** The lobby the message belongs to. */
|
|
94
|
+
lobby_id: string;
|
|
95
|
+
/** The channel the message was sent in. */
|
|
96
|
+
channel_id: string;
|
|
97
|
+
author: APIUser;
|
|
98
|
+
/** Arbitrary key/value metadata attached to the message. */
|
|
99
|
+
metadata?: Record<string, unknown>;
|
|
100
|
+
/** Message flags, combined as a bitfield. */
|
|
101
|
+
flags: number;
|
|
102
|
+
/** Only present during an active Social SDK session. */
|
|
103
|
+
application_id?: string;
|
|
104
|
+
};
|
|
105
|
+
/** `LOBBY_MESSAGE_UPDATE` adds the original and edited timestamps. */
|
|
106
|
+
export type LobbyMessageUpdateEventData = LobbyMessageEventData & {
|
|
107
|
+
/** ISO8601 timestamp of the edit. */
|
|
108
|
+
edited_timestamp?: string;
|
|
109
|
+
/** ISO8601 timestamp of the original message. */
|
|
110
|
+
timestamp?: string;
|
|
111
|
+
};
|
|
112
|
+
/** `LOBBY_MESSAGE_DELETE` is deliberately thin — just enough to reconcile state. */
|
|
113
|
+
export type LobbyMessageDeleteEventData = {
|
|
114
|
+
/** ID of the deleted message. */
|
|
115
|
+
id: string;
|
|
116
|
+
/** ID of the lobby the message was deleted from. */
|
|
117
|
+
lobby_id: string;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Standard Discord message body as it appears inside a webhook event.
|
|
121
|
+
*
|
|
122
|
+
* Deliberately looser than `discord-api-types`' `APIMessage`: the documented
|
|
123
|
+
* webhook payloads omit fields that are required on a full message object.
|
|
124
|
+
*/
|
|
125
|
+
export type WebhookEventMessageBody = {
|
|
126
|
+
id: string;
|
|
127
|
+
type?: number;
|
|
128
|
+
content?: string;
|
|
129
|
+
channel_id?: string;
|
|
130
|
+
author?: APIUser;
|
|
131
|
+
timestamp?: string;
|
|
132
|
+
edited_timestamp?: string | null;
|
|
133
|
+
flags?: number;
|
|
134
|
+
attachments?: APIAttachment[];
|
|
135
|
+
/** Channel object with recipient information. */
|
|
136
|
+
channel?: APIChannel;
|
|
137
|
+
application_id?: string;
|
|
138
|
+
};
|
|
139
|
+
/** A standard message object; Linked Channel messages additionally carry `lobby_id`. */
|
|
140
|
+
export type WebhookEventMessage = WebhookEventMessageBody & {
|
|
141
|
+
/** Only present in Linked Channel messages. */
|
|
142
|
+
lobby_id?: string;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* A direct message between two **provisional** accounts. It exists only in-game
|
|
146
|
+
* and is never delivered to the Discord client.
|
|
147
|
+
*/
|
|
148
|
+
export type WebhookEventSdkDirectMessage = {
|
|
149
|
+
id: string;
|
|
150
|
+
type: number;
|
|
151
|
+
content: string;
|
|
152
|
+
author: APIUser;
|
|
153
|
+
/** Message flags, combined as a bitfield. */
|
|
154
|
+
flags: number;
|
|
155
|
+
/** The application that created the message. */
|
|
156
|
+
application_id: string;
|
|
157
|
+
/** Channel object with recipient information. */
|
|
158
|
+
channel: APIChannel;
|
|
159
|
+
/** Sent with Rich Presence-related chat embeds. */
|
|
160
|
+
activity?: APIMessageActivity;
|
|
161
|
+
/** Partial application object, sent with Rich Presence-related chat embeds. */
|
|
162
|
+
application?: Partial<APIApplication>;
|
|
163
|
+
/** Present when the message also targetted a standard Discord channel. */
|
|
164
|
+
recipient_id?: string;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* `GAME_DIRECT_MESSAGE_*` data.
|
|
168
|
+
*
|
|
169
|
+
* Which shape arrives depends on the session: a standard
|
|
170
|
+
* {@link WebhookEventMessage} when a linked Discord account is involved, or a
|
|
171
|
+
* {@link WebhookEventSdkDirectMessage} when both participants are provisional.
|
|
172
|
+
*/
|
|
173
|
+
export type GameDirectMessageEventData = WebhookEventMessage | WebhookEventSdkDirectMessage;
|
|
174
|
+
/** Maps every event name to the shape of its `event.data`. */
|
|
175
|
+
export type WebhookEventDataMap = {
|
|
176
|
+
APPLICATION_AUTHORIZED: ApplicationAuthorizedEventData;
|
|
177
|
+
APPLICATION_DEAUTHORIZED: ApplicationDeauthorizedEventData;
|
|
178
|
+
ENTITLEMENT_CREATE: APIEntitlement;
|
|
179
|
+
ENTITLEMENT_UPDATE: APIEntitlement;
|
|
180
|
+
ENTITLEMENT_DELETE: APIEntitlement;
|
|
181
|
+
QUEST_USER_ENROLLMENT: Record<string, unknown>;
|
|
182
|
+
LOBBY_MESSAGE_CREATE: LobbyMessageEventData;
|
|
183
|
+
LOBBY_MESSAGE_UPDATE: LobbyMessageUpdateEventData;
|
|
184
|
+
LOBBY_MESSAGE_DELETE: LobbyMessageDeleteEventData;
|
|
185
|
+
GAME_DIRECT_MESSAGE_CREATE: GameDirectMessageEventData;
|
|
186
|
+
GAME_DIRECT_MESSAGE_UPDATE: GameDirectMessageEventData;
|
|
187
|
+
GAME_DIRECT_MESSAGE_DELETE: GameDirectMessageEventData;
|
|
188
|
+
};
|
|
189
|
+
/** High-level data about a single event: what happened, and when. */
|
|
190
|
+
export type WebhookEventBody<TName extends WebhookEventType> = {
|
|
191
|
+
type: TName;
|
|
192
|
+
/** ISO8601 timestamp of when the event occurred. */
|
|
193
|
+
timestamp: string;
|
|
194
|
+
/** Event-specific payload; the shape is tied to `type`. */
|
|
195
|
+
data?: WebhookEventDataMap[TName];
|
|
196
|
+
};
|
|
197
|
+
/** Outer envelope for a single event, as delivered to your endpoint. */
|
|
198
|
+
export type WebhookEventPayloadOf<TName extends WebhookEventType> = {
|
|
199
|
+
/** Always `1`. */
|
|
200
|
+
version: 1;
|
|
201
|
+
/** ID of the app the event belongs to. */
|
|
202
|
+
application_id: string;
|
|
203
|
+
type: typeof WebhookEventPayloadType.Event;
|
|
204
|
+
event: WebhookEventBody<TName>;
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Discriminated union of every event payload.
|
|
208
|
+
*
|
|
209
|
+
* Narrowing on `payload.event.type` narrows `payload.event.data` with it:
|
|
210
|
+
*
|
|
211
|
+
* ```ts
|
|
212
|
+
* if (payload.event.type === WebhookEventType.ApplicationDeauthorized) {
|
|
213
|
+
* payload.event.data?.user.id; // typed
|
|
214
|
+
* }
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
export type WebhookEventPayload = {
|
|
218
|
+
[TName in WebhookEventType]: WebhookEventPayloadOf<TName>;
|
|
219
|
+
}[WebhookEventType];
|
|
220
|
+
/** The `PING` Discord sends when validating your Webhook Event URL. */
|
|
221
|
+
export type WebhookEventPingPayload = {
|
|
222
|
+
version: 1;
|
|
223
|
+
application_id: string;
|
|
224
|
+
type: typeof WebhookEventPayloadType.Ping;
|
|
225
|
+
};
|
|
226
|
+
/** Anything Discord can deliver to your Webhook Event URL. */
|
|
227
|
+
export type WebhookEventRequest = WebhookEventPingPayload | WebhookEventPayload;
|
|
228
|
+
/** Narrows a request to an actual event (i.e. not a `PING`). */
|
|
229
|
+
export declare function isWebhookEventPayload(request: WebhookEventRequest): request is WebhookEventPayload;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webhook Events ("outgoing webhooks") are one-way HTTP events Discord posts to
|
|
3
|
+
* an app's **Webhook Event URL** when something happens in Discord — as opposed
|
|
4
|
+
* to incoming webhooks, which an external service triggers.
|
|
5
|
+
*
|
|
6
|
+
* Unlike Gateway events they are **not realtime and not guaranteed to be in
|
|
7
|
+
* order**, so handlers must be idempotent and reconcile state rather than
|
|
8
|
+
* assume sequencing.
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://docs.discord.com/developers/events/webhook-events}
|
|
11
|
+
*/
|
|
12
|
+
/** Outer payload `type`. */
|
|
13
|
+
export const WebhookEventPayloadType = {
|
|
14
|
+
/** Sent when Discord validates your endpoint URL. Answer with an empty `204`. */
|
|
15
|
+
Ping: 0,
|
|
16
|
+
/** A real event; the details live in `event`. */
|
|
17
|
+
Event: 1,
|
|
18
|
+
};
|
|
19
|
+
/** Installation context of an authorization: `0` = server, `1` = user account. */
|
|
20
|
+
export const WebhookEventIntegrationType = {
|
|
21
|
+
GuildInstall: 0,
|
|
22
|
+
UserInstall: 1,
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Every event name an app can subscribe to.
|
|
26
|
+
*
|
|
27
|
+
* `ENTITLEMENT_UPDATE` and `ENTITLEMENT_DELETE` are included here even though
|
|
28
|
+
* `discord-interactions`' own `WebhookEventType` enum predates them.
|
|
29
|
+
*/
|
|
30
|
+
export const WebhookEventType = {
|
|
31
|
+
/** The app was authorized by a user to a server or to their account. */
|
|
32
|
+
ApplicationAuthorized: "APPLICATION_AUTHORIZED",
|
|
33
|
+
/** The app was deauthorized by a user. */
|
|
34
|
+
ApplicationDeauthorized: "APPLICATION_DEAUTHORIZED",
|
|
35
|
+
/** An entitlement was created. */
|
|
36
|
+
EntitlementCreate: "ENTITLEMENT_CREATE",
|
|
37
|
+
/** An entitlement was updated. */
|
|
38
|
+
EntitlementUpdate: "ENTITLEMENT_UPDATE",
|
|
39
|
+
/** An entitlement was deleted. */
|
|
40
|
+
EntitlementDelete: "ENTITLEMENT_DELETE",
|
|
41
|
+
/** A user was added to a Quest. Documented, but currently unavailable to apps. */
|
|
42
|
+
QuestUserEnrollment: "QUEST_USER_ENROLLMENT",
|
|
43
|
+
/** A message was created in a lobby. */
|
|
44
|
+
LobbyMessageCreate: "LOBBY_MESSAGE_CREATE",
|
|
45
|
+
/** A message was updated in a lobby. */
|
|
46
|
+
LobbyMessageUpdate: "LOBBY_MESSAGE_UPDATE",
|
|
47
|
+
/** A message was deleted from a lobby. */
|
|
48
|
+
LobbyMessageDelete: "LOBBY_MESSAGE_DELETE",
|
|
49
|
+
/** A direct message was created during an active Social SDK session. */
|
|
50
|
+
GameDirectMessageCreate: "GAME_DIRECT_MESSAGE_CREATE",
|
|
51
|
+
/** A direct message was updated during an active Social SDK session. */
|
|
52
|
+
GameDirectMessageUpdate: "GAME_DIRECT_MESSAGE_UPDATE",
|
|
53
|
+
/** A direct message was deleted during an active Social SDK session. */
|
|
54
|
+
GameDirectMessageDelete: "GAME_DIRECT_MESSAGE_DELETE",
|
|
55
|
+
};
|
|
56
|
+
/** Narrows a request to an actual event (i.e. not a `PING`). */
|
|
57
|
+
export function isWebhookEventPayload(request) {
|
|
58
|
+
return request.type === WebhookEventPayloadType.Event;
|
|
59
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { type WebhookEventPayload, type WebhookEventPayloadOf, type WebhookEventPingPayload, type WebhookEventRequest, type WebhookEventType } from "./WebhookEvent.js";
|
|
2
|
+
/** Ambient data handed to every handler. */
|
|
3
|
+
export type WebhookEventContext = {
|
|
4
|
+
/** ID of the app the event belongs to. */
|
|
5
|
+
applicationId: string;
|
|
6
|
+
};
|
|
7
|
+
/** Handler for a single event type; `data` is typed from the event name. */
|
|
8
|
+
export type WebhookEventHandler<TName extends WebhookEventType> = (payload: WebhookEventPayloadOf<TName>, ctx: WebhookEventContext) => Promise<void> | void;
|
|
9
|
+
/** Handler for any event, used as the fallback when no specific handler matches. */
|
|
10
|
+
export type WebhookEventAnyHandler = (payload: WebhookEventPayload, ctx: WebhookEventContext) => Promise<void> | void;
|
|
11
|
+
/** Handler for the `PING` Discord sends when validating the endpoint URL. */
|
|
12
|
+
export type WebhookEventPingHandler = (payload: WebhookEventPingPayload, ctx: WebhookEventContext) => Promise<void> | void;
|
|
13
|
+
/** Middleware executed before dispatch; call `next()` to continue the chain. */
|
|
14
|
+
export type WebhookEventMiddleware = (request: WebhookEventRequest, ctx: WebhookEventContext, next: () => Promise<void>) => Promise<void> | void;
|
|
15
|
+
/**
|
|
16
|
+
* Error hook. Returning normally acks with `204`; rethrowing lets the failure
|
|
17
|
+
* surface so Discord retries the delivery.
|
|
18
|
+
*/
|
|
19
|
+
export type WebhookEventErrorHandler = (error: unknown, request: WebhookEventRequest, ctx: WebhookEventContext) => Promise<void> | void;
|
|
20
|
+
/**
|
|
21
|
+
* Dispatches verified Webhook Events to handlers by event name.
|
|
22
|
+
*
|
|
23
|
+
* Webhook events arrive **out of order and are retried** on failure, so keep
|
|
24
|
+
* handlers idempotent. Do the minimum work needed to ack and defer the rest
|
|
25
|
+
* (see `WebhookEventEndpoint`'s `waitUntil` option) — Discord expects a
|
|
26
|
+
* response within 3 seconds.
|
|
27
|
+
*/
|
|
28
|
+
export declare class WebhookEventRouter {
|
|
29
|
+
private readonly handlers;
|
|
30
|
+
private readonly middleware;
|
|
31
|
+
private anyHandler?;
|
|
32
|
+
private pingHandler?;
|
|
33
|
+
private errorHandler?;
|
|
34
|
+
/** Registers a handler for one event type. */
|
|
35
|
+
on<TName extends WebhookEventType>(name: TName, handler: WebhookEventHandler<TName>): this;
|
|
36
|
+
/**
|
|
37
|
+
* Registers the fallback for event types without a dedicated handler.
|
|
38
|
+
* Specific handlers win; this only runs when nothing matched.
|
|
39
|
+
*/
|
|
40
|
+
onAny(handler: WebhookEventAnyHandler): this;
|
|
41
|
+
/**
|
|
42
|
+
* Registers a `PING` handler. Optional: a `PING` is always acked with `204`
|
|
43
|
+
* whether or not you handle it.
|
|
44
|
+
*/
|
|
45
|
+
onPing(handler: WebhookEventPingHandler): this;
|
|
46
|
+
/** Adds middleware that runs before dispatch. Call `next()` to continue. */
|
|
47
|
+
use(middleware: WebhookEventMiddleware): this;
|
|
48
|
+
/** Sets the error hook used when middleware or a handler throws. */
|
|
49
|
+
onError(handler: WebhookEventErrorHandler): this;
|
|
50
|
+
/**
|
|
51
|
+
* Runs the middleware chain and the matched handler.
|
|
52
|
+
*
|
|
53
|
+
* @throws when a handler throws and no {@link onError} hook is registered.
|
|
54
|
+
*/
|
|
55
|
+
dispatch(request: WebhookEventRequest, ctx?: Partial<WebhookEventContext>): Promise<void>;
|
|
56
|
+
private handle;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The status your endpoint should return. Webhook events are always acknowledged
|
|
60
|
+
* with an empty body — Discord does not accept a JSON reply here.
|
|
61
|
+
*/
|
|
62
|
+
export type WebhookEventEndpointResult = {
|
|
63
|
+
/** `204` acked · `401` signature rejected · `400` unparseable · `500` handler threw. */
|
|
64
|
+
status: 204 | 401 | 400 | 500;
|
|
65
|
+
/** Always empty. */
|
|
66
|
+
body: "";
|
|
67
|
+
};
|
|
68
|
+
/** The parts of an incoming request the endpoint needs. */
|
|
69
|
+
export type WebhookEventHttpRequest = {
|
|
70
|
+
body: string | Uint8Array;
|
|
71
|
+
signature?: string;
|
|
72
|
+
timestamp?: string;
|
|
73
|
+
};
|
|
74
|
+
export type WebhookEventEndpointOptions = {
|
|
75
|
+
/** Your app's public key from the Developer Portal. */
|
|
76
|
+
publicKey: string;
|
|
77
|
+
/** Dispatcher for verified events. */
|
|
78
|
+
router?: WebhookEventRouter;
|
|
79
|
+
/**
|
|
80
|
+
* Schedules work that outlives the response — `@vercel/functions`' `waitUntil`
|
|
81
|
+
* or Cloudflare's `ctx.waitUntil`.
|
|
82
|
+
*
|
|
83
|
+
* When set, the `204` is sent immediately and a failing handler can no longer
|
|
84
|
+
* change the status, so report failures yourself (e.g. in `router.onError`).
|
|
85
|
+
* When omitted, handlers are awaited before acking — keep total work under
|
|
86
|
+
* Discord's 3 second budget or Discord will retry the delivery.
|
|
87
|
+
*/
|
|
88
|
+
waitUntil?: (promise: Promise<unknown>) => void;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Verifies and dispatches Discord Webhook Events for a single endpoint URL.
|
|
92
|
+
*
|
|
93
|
+
* ```ts
|
|
94
|
+
* const endpoint = new WebhookEventEndpoint({
|
|
95
|
+
* publicKey: process.env.DISCORD_PUBLIC_KEY!,
|
|
96
|
+
* router: new WebhookEventRouter().on(
|
|
97
|
+
* WebhookEventType.ApplicationDeauthorized,
|
|
98
|
+
* (payload) => unlinkAccount(payload.event.data!.user.id),
|
|
99
|
+
* ),
|
|
100
|
+
* });
|
|
101
|
+
*
|
|
102
|
+
* export async function POST(req: Request) {
|
|
103
|
+
* return endpoint.handleFetch(req);
|
|
104
|
+
* }
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export declare class WebhookEventEndpoint {
|
|
108
|
+
private readonly options;
|
|
109
|
+
constructor(options: WebhookEventEndpointOptions);
|
|
110
|
+
/**
|
|
111
|
+
* Verifies the signature, dispatches the event and returns the status to send
|
|
112
|
+
* back. Framework-agnostic — wire it into any HTTP server.
|
|
113
|
+
*/
|
|
114
|
+
handle(request: WebhookEventHttpRequest): Promise<WebhookEventEndpointResult>;
|
|
115
|
+
/**
|
|
116
|
+
* Convenience wrapper for Fetch-API runtimes (Cloudflare Workers, Bun, Deno,
|
|
117
|
+
* Vercel Edge).
|
|
118
|
+
*
|
|
119
|
+
* Always returns a bodiless response with an explicit `Content-Type`, which
|
|
120
|
+
* Discord requires when acknowledging `PING`s.
|
|
121
|
+
*/
|
|
122
|
+
handleFetch(request: Request): Promise<Response>;
|
|
123
|
+
}
|