@minesa-org/mini-interaction 0.0.1

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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/dist/builders/ActionRowBuilder.d.ts +25 -0
  4. package/dist/builders/ActionRowBuilder.js +35 -0
  5. package/dist/builders/ButtonBuilder.d.ts +53 -0
  6. package/dist/builders/ButtonBuilder.js +124 -0
  7. package/dist/builders/ChannelSelectMenuBuilder.d.ts +58 -0
  8. package/dist/builders/ChannelSelectMenuBuilder.js +111 -0
  9. package/dist/builders/ModalBuilder.d.ts +40 -0
  10. package/dist/builders/ModalBuilder.js +65 -0
  11. package/dist/builders/RoleSelectMenuBuilder.d.ts +52 -0
  12. package/dist/builders/RoleSelectMenuBuilder.js +98 -0
  13. package/dist/builders/StringSelectMenuBuilder.d.ts +56 -0
  14. package/dist/builders/StringSelectMenuBuilder.js +100 -0
  15. package/dist/builders/index.d.ts +14 -0
  16. package/dist/builders/index.js +7 -0
  17. package/dist/builders/shared.d.ts +8 -0
  18. package/dist/builders/shared.js +11 -0
  19. package/dist/clients/MiniInteraction.d.ts +176 -0
  20. package/dist/clients/MiniInteraction.js +578 -0
  21. package/dist/commands/CommandBuilder.d.ts +278 -0
  22. package/dist/commands/CommandBuilder.js +687 -0
  23. package/dist/index.d.ts +16 -0
  24. package/dist/index.js +9 -0
  25. package/dist/types/ButtonStyle.d.ts +16 -0
  26. package/dist/types/ButtonStyle.js +17 -0
  27. package/dist/types/ChannelType.d.ts +2 -0
  28. package/dist/types/ChannelType.js +2 -0
  29. package/dist/types/Commands.d.ts +11 -0
  30. package/dist/types/Commands.js +1 -0
  31. package/dist/types/ComponentTypes.d.ts +5 -0
  32. package/dist/types/ComponentTypes.js +1 -0
  33. package/dist/types/InteractionFlags.d.ts +10 -0
  34. package/dist/types/InteractionFlags.js +12 -0
  35. package/dist/types/RoleConnectionMetadataTypes.d.ts +11 -0
  36. package/dist/types/RoleConnectionMetadataTypes.js +12 -0
  37. package/dist/utils/CommandInteractionOptions.d.ts +143 -0
  38. package/dist/utils/CommandInteractionOptions.js +376 -0
  39. package/dist/utils/MessageComponentInteraction.d.ts +19 -0
  40. package/dist/utils/MessageComponentInteraction.js +60 -0
  41. package/dist/utils/constants.d.ts +16 -0
  42. package/dist/utils/constants.js +16 -0
  43. package/dist/utils/interactionMessageHelpers.d.ts +30 -0
  44. package/dist/utils/interactionMessageHelpers.js +32 -0
  45. package/package.json +50 -0
@@ -0,0 +1,60 @@
1
+ import { InteractionResponseType, } from "discord-api-types/v10";
2
+ import { normaliseInteractionMessageData, normaliseMessageFlags, } from "./interactionMessageHelpers.js";
3
+ /**
4
+ * Wraps a raw component interaction with helper methods mirroring Discord's expected responses.
5
+ *
6
+ * @param interaction - The raw interaction payload from Discord.
7
+ * @returns A helper-augmented interaction object.
8
+ */
9
+ export function createMessageComponentInteraction(interaction) {
10
+ let capturedResponse = null;
11
+ const captureResponse = (response) => {
12
+ capturedResponse = response;
13
+ return response;
14
+ };
15
+ const reply = (data) => {
16
+ const normalisedData = normaliseInteractionMessageData(data);
17
+ if (!normalisedData) {
18
+ throw new Error("[MiniInteraction] Component replies require response data to be provided.");
19
+ }
20
+ return captureResponse({
21
+ type: InteractionResponseType.ChannelMessageWithSource,
22
+ data: normalisedData,
23
+ });
24
+ };
25
+ const deferReply = (options) => {
26
+ const flags = normaliseMessageFlags(options?.flags);
27
+ const response = flags !== undefined
28
+ ? {
29
+ type: InteractionResponseType.DeferredChannelMessageWithSource,
30
+ data: { flags },
31
+ }
32
+ : {
33
+ type: InteractionResponseType.DeferredChannelMessageWithSource,
34
+ };
35
+ return captureResponse(response);
36
+ };
37
+ const update = (data) => {
38
+ const normalisedData = normaliseInteractionMessageData(data);
39
+ const response = normalisedData
40
+ ? {
41
+ type: InteractionResponseType.UpdateMessage,
42
+ data: normalisedData,
43
+ }
44
+ : {
45
+ type: InteractionResponseType.UpdateMessage,
46
+ };
47
+ return captureResponse(response);
48
+ };
49
+ const deferUpdate = () => captureResponse({
50
+ type: InteractionResponseType.DeferredMessageUpdate,
51
+ });
52
+ const getResponse = () => capturedResponse;
53
+ return Object.assign(interaction, {
54
+ reply,
55
+ deferReply,
56
+ update,
57
+ deferUpdate,
58
+ getResponse,
59
+ });
60
+ }
@@ -0,0 +1,16 @@
1
+ import "dotenv/config";
2
+ /** Discord application's public key used for request signature verification. */
3
+ declare const DISCORD_APP_PUBLIC_KEY: string;
4
+ /** Discord application identifier used for REST requests. */
5
+ declare const DISCORD_APPLICATION_ID: string;
6
+ /** Bot token used when registering commands against Discord's API. */
7
+ declare const DISCORD_BOT_TOKEN: string;
8
+ /** Guild identifier used for guild-scoped command registration. */
9
+ declare const DISCORD_GUILD_ID: string;
10
+ /** Whether commands should be registered globally instead of per guild. */
11
+ declare const DISCORD_GLOBAL: boolean;
12
+ /** Local development port for the example interaction server. */
13
+ declare const DISCORD_APP_PORT: string;
14
+ /** Discord REST API base URL used for all network requests. */
15
+ declare const DISCORD_BASE_URL = "https://discord.com/api/v10";
16
+ export { DISCORD_APPLICATION_ID, DISCORD_APP_PORT, DISCORD_APP_PUBLIC_KEY, DISCORD_BASE_URL, DISCORD_BOT_TOKEN, DISCORD_GLOBAL, DISCORD_GUILD_ID, };
@@ -0,0 +1,16 @@
1
+ import "dotenv/config";
2
+ /** Discord application's public key used for request signature verification. */
3
+ const DISCORD_APP_PUBLIC_KEY = process.env.DISCORD_APP_PUBLIC_KEY;
4
+ /** Discord application identifier used for REST requests. */
5
+ const DISCORD_APPLICATION_ID = process.env.DISCORD_APPLICATION_ID;
6
+ /** Bot token used when registering commands against Discord's API. */
7
+ const DISCORD_BOT_TOKEN = process.env.DISCORD_BOT_TOKEN;
8
+ /** Guild identifier used for guild-scoped command registration. */
9
+ const DISCORD_GUILD_ID = process.env.DISCORD_GUILD_ID;
10
+ /** Whether commands should be registered globally instead of per guild. */
11
+ const DISCORD_GLOBAL = (process.env.DISCORD_GLOBAL ?? "false").toLowerCase() === "true";
12
+ /** Local development port for the example interaction server. */
13
+ const DISCORD_APP_PORT = process.env.DISCORD_PORT;
14
+ /** Discord REST API base URL used for all network requests. */
15
+ const DISCORD_BASE_URL = "https://discord.com/api/v10";
16
+ export { DISCORD_APPLICATION_ID, DISCORD_APP_PORT, DISCORD_APP_PUBLIC_KEY, DISCORD_BASE_URL, DISCORD_BOT_TOKEN, DISCORD_GLOBAL, DISCORD_GUILD_ID, };
@@ -0,0 +1,30 @@
1
+ import type { APIInteractionResponseCallbackData, MessageFlags } from "discord-api-types/v10";
2
+ import type { InteractionFollowUpFlags, InteractionReplyFlags } from "../types/InteractionFlags.js";
3
+ /** Union of helper flag enums and raw Discord message flags. */
4
+ export type MessageFlagLike = MessageFlags | InteractionReplyFlags | InteractionFollowUpFlags;
5
+ /** Message payload accepted by helper reply/edit functions. */
6
+ export type InteractionMessageData = Omit<APIInteractionResponseCallbackData, "flags"> & {
7
+ flags?: MessageFlagLike;
8
+ };
9
+ /** Deferred response payload recognised by helper methods. */
10
+ export type DeferredResponseData = {
11
+ flags: MessageFlagLike;
12
+ };
13
+ /** Options accepted when deferring a reply. */
14
+ export type DeferReplyOptions = {
15
+ flags?: MessageFlagLike;
16
+ };
17
+ /**
18
+ * Normalises helper flag enums into the raw Discord `MessageFlags` bitfield.
19
+ *
20
+ * @param flags - A flag from helper enums or raw Discord flags.
21
+ * @returns The value coerced to a `MessageFlags` compatible bitfield.
22
+ */
23
+ export declare function normaliseMessageFlags(flags: MessageFlagLike | undefined): MessageFlags | undefined;
24
+ /**
25
+ * Ensures helper message payloads include correctly normalised message flags.
26
+ *
27
+ * @param data - The helper-supplied response payload.
28
+ * @returns A payload safe to send to Discord's API.
29
+ */
30
+ export declare function normaliseInteractionMessageData(data?: InteractionMessageData): APIInteractionResponseCallbackData | undefined;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Normalises helper flag enums into the raw Discord `MessageFlags` bitfield.
3
+ *
4
+ * @param flags - A flag from helper enums or raw Discord flags.
5
+ * @returns The value coerced to a `MessageFlags` compatible bitfield.
6
+ */
7
+ export function normaliseMessageFlags(flags) {
8
+ return flags === undefined ? undefined : flags;
9
+ }
10
+ /**
11
+ * Ensures helper message payloads include correctly normalised message flags.
12
+ *
13
+ * @param data - The helper-supplied response payload.
14
+ * @returns A payload safe to send to Discord's API.
15
+ */
16
+ export function normaliseInteractionMessageData(data) {
17
+ if (!data) {
18
+ return undefined;
19
+ }
20
+ if (data.flags === undefined) {
21
+ return data;
22
+ }
23
+ const { flags, ...rest } = data;
24
+ const normalisedFlags = normaliseMessageFlags(flags);
25
+ if (normalisedFlags === flags) {
26
+ return data;
27
+ }
28
+ return {
29
+ ...rest,
30
+ flags: normalisedFlags,
31
+ };
32
+ }
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@minesa-org/mini-interaction",
3
+ "version": "0.0.1",
4
+ "description": "Mini interaction, connecting your app with Discord via HTTP-interaction (Vercel support).",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "README.md",
11
+ "LICENSE"
12
+ ],
13
+ "scripts": {
14
+ "build": "tsc --project tsconfig.json",
15
+ "typecheck": "tsc --noEmit",
16
+ "prepare": "npm run build",
17
+ "publish:npm": "npm publish",
18
+ "publish:gh": "npm publish --registry=https://npm.pkg.github.com"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/minesa-org/mini-interaction.git"
26
+ },
27
+ "keywords": [
28
+ "discord",
29
+ "interactions",
30
+ "http-interaction",
31
+ "vercel",
32
+ "typescript"
33
+ ],
34
+ "author": "Minesa",
35
+ "license": "MIT",
36
+ "bugs": {
37
+ "url": "https://github.com/minesa-org/mini-interaction/issues"
38
+ },
39
+ "homepage": "https://github.com/minesa-org/mini-interaction#readme",
40
+ "dependencies": {
41
+ "discord-api-types": "^0.38.32",
42
+ "discord-interactions": "^4.4.0",
43
+ "dotenv": "^17.2.3"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^24.10.0",
47
+ "ts-node": "^10.9.2",
48
+ "typescript": "^5.9.3"
49
+ }
50
+ }