@minesa-org/mini-interaction 0.4.1 → 0.4.3

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.
@@ -1,12 +1,11 @@
1
- import type { APIActionRowComponent } from "discord-api-types/v10";
2
1
  import type { JSONEncodable } from "./shared.js";
3
- import type { ActionRowComponent } from "../types/ComponentTypes.js";
2
+ import type { ActionRowComponent, MiniActionRow } from "../types/ComponentTypes.js";
4
3
  /** Values accepted when composing component action rows. */
5
4
  export type ActionRowComponentLike<T extends ActionRowComponent> = JSONEncodable<T> | T;
6
5
  /** Builder for creating Action Row components. */
7
- export declare class ActionRowBuilder<T extends ActionRowComponent> implements JSONEncodable<APIActionRowComponent<T>> {
6
+ export declare class ActionRowBuilder<T extends ActionRowComponent> implements JSONEncodable<MiniActionRow<T>> {
8
7
  private components;
9
- constructor(data?: Partial<APIActionRowComponent<T>>);
8
+ constructor(data?: Partial<MiniActionRow<T>>);
10
9
  /**
11
10
  * Adds components to this action row.
12
11
  *
@@ -19,5 +18,5 @@ export declare class ActionRowBuilder<T extends ActionRowComponent> implements J
19
18
  * @param components - The new components to set.
20
19
  */
21
20
  setComponents(...components: (T | JSONEncodable<T>)[]): this;
22
- toJSON(): APIActionRowComponent<T>;
21
+ toJSON(): MiniActionRow<T>;
23
22
  }
@@ -0,0 +1,17 @@
1
+ import type { JSONEncodable } from './shared.js';
2
+ import { APICheckboxComponent, APICheckboxOption } from '../types/checkbox.js';
3
+ export type CheckboxBuilderData = {
4
+ customId?: string;
5
+ required?: boolean;
6
+ disabled?: boolean;
7
+ options?: APICheckboxOption[];
8
+ };
9
+ export declare class CheckboxBuilder implements JSONEncodable<APICheckboxComponent> {
10
+ private readonly data;
11
+ constructor(data?: CheckboxBuilderData);
12
+ setCustomId(customId: string): this;
13
+ setRequired(required: boolean): this;
14
+ setDisabled(disabled: boolean): this;
15
+ addOptions(...options: APICheckboxOption[]): this;
16
+ toJSON(): APICheckboxComponent;
17
+ }
@@ -0,0 +1,24 @@
1
+ import { CHECKBOX_COMPONENT_TYPE } from '../types/checkbox.js';
2
+ import { assertDefined, assertStringLength, ValidationError } from '../types/validation.js';
3
+ export class CheckboxBuilder {
4
+ data;
5
+ constructor(data = {}) { this.data = { ...data, options: data.options ? [...data.options] : [] }; }
6
+ setCustomId(customId) { this.data.customId = customId; return this; }
7
+ setRequired(required) { this.data.required = required; return this; }
8
+ setDisabled(disabled) { this.data.disabled = disabled; return this; }
9
+ addOptions(...options) { this.data.options = [...(this.data.options ?? []), ...options]; return this; }
10
+ toJSON() {
11
+ const customId = assertDefined('CheckboxBuilder', 'custom_id', this.data.customId);
12
+ assertStringLength('CheckboxBuilder', 'custom_id', customId, 1, 100);
13
+ const options = [...(this.data.options ?? [])];
14
+ if (options.length === 0 || options.length > 25)
15
+ throw new ValidationError('CheckboxBuilder', 'options', 'must contain 1-25 options');
16
+ for (const [index, option] of options.entries()) {
17
+ assertStringLength('CheckboxBuilder', `options[${index}].label`, option.label, 1, 100);
18
+ assertStringLength('CheckboxBuilder', `options[${index}].value`, option.value, 1, 100);
19
+ if (option.description)
20
+ assertStringLength('CheckboxBuilder', `options[${index}].description`, option.description, 1, 100);
21
+ }
22
+ return { type: CHECKBOX_COMPONENT_TYPE, custom_id: customId, disabled: this.data.disabled, required: this.data.required, options };
23
+ }
24
+ }
@@ -38,3 +38,5 @@ export type { ContainerBuilderData, SectionBuilderData, TextDisplayBuilderData,
38
38
  export type { JSONEncodable } from "./shared.js";
39
39
  export { RadioBuilder } from "./RadioBuilder.js";
40
40
  export type { RadioBuilderData } from "./RadioBuilder.js";
41
+ export { CheckboxBuilder } from "./CheckboxBuilder.js";
42
+ export type { CheckboxBuilderData } from "./CheckboxBuilder.js";
@@ -18,3 +18,4 @@ export { AutomodRuleBuilder } from "./AutomodRuleBuilder.js";
18
18
  export { EmbedBuilder } from "./EmbedBuilder.js";
19
19
  export { ContainerBuilder, SectionBuilder, TextDisplayBuilder, SeparatorBuilder, GalleryBuilder, GalleryItemBuilder, ThumbnailBuilder, } from "./MiniContainerBuilder.js";
20
20
  export { RadioBuilder } from "./RadioBuilder.js";
21
+ export { CheckboxBuilder } from "./CheckboxBuilder.js";
package/dist/index.d.ts CHANGED
@@ -4,8 +4,8 @@ export type { AttachmentOptionBuilder, ChannelOptionBuilder, MentionableOptionBu
4
4
  export { CommandInteractionOptionResolver, createCommandInteraction, } from "./utils/CommandInteractionOptions.js";
5
5
  export { CommandInteraction, MentionableOption, ResolvedUserOption, } from "./utils/CommandInteractionOptions.js";
6
6
  export { UserContextMenuInteraction, MessageContextMenuInteraction, AppCommandInteraction, } from "./utils/ContextMenuInteraction.js";
7
- export type { InteractionCommand, SlashCommandHandler, UserCommandHandler, MessageCommandHandler, AppCommandHandler, CommandHandler, } from "./types/Commands.js";
8
- export { MessageComponentInteraction, ButtonInteraction, StringSelectInteraction, RoleSelectInteraction, UserSelectInteraction, ChannelSelectInteraction, MentionableSelectInteraction, ResolvedUserOption as ComponentResolvedUserOption, ResolvedMentionableOption as ComponentResolvedMentionableOption, } from "./utils/MessageComponentInteraction.js";
7
+ export type { InteractionCommand, SlashCommandHandler, UserCommandHandler, MessageCommandHandler, AppCommandHandler, CommandHandler, ComponentInteraction, InteractionComponent, InteractionModal, } from "./types/Commands.js";
8
+ export { MessageComponentInteraction, ButtonInteraction, StringSelectInteraction, RoleSelectInteraction, UserSelectInteraction, ChannelSelectInteraction, MentionableSelectInteraction, RadioInteraction, CheckboxInteraction, ResolvedUserOption as ComponentResolvedUserOption, ResolvedMentionableOption as ComponentResolvedMentionableOption, } from "./utils/MessageComponentInteraction.js";
9
9
  export { ModalSubmitInteraction } from "./utils/ModalSubmitInteraction.js";
10
10
  export { RoleConnectionMetadataTypes } from "./types/RoleConnectionMetadataTypes.js";
11
11
  export { ChannelType } from "./types/ChannelType.js";
@@ -14,7 +14,7 @@ export { ButtonStyle } from "./types/ButtonStyle.js";
14
14
  export { SeparatorSpacingSize } from "./types/SeparatorSpacingSize.js";
15
15
  export { TextInputStyle } from "discord-api-types/v10";
16
16
  export { MiniPermFlags } from "./types/PermissionFlags.js";
17
- export type { ActionRowComponent, MessageActionRowComponent, } from "./types/ComponentTypes.js";
17
+ export type { ActionRowComponent, MessageActionRowComponent, InteractionComponentData, } from "./types/ComponentTypes.js";
18
18
  export * from "./builders/index.js";
19
19
  export { MiniDataBuilder } from "./database/MiniDataBuilder.js";
20
20
  export type { DataField } from "./database/MiniDataBuilder.js";
@@ -32,4 +32,6 @@ export { verifyAndParseInteraction } from "./core/interactions/InteractionVerifi
32
32
  export { InteractionRouter } from "./router/InteractionRouter.js";
33
33
  export type { APIRadioComponent, APIRadioOption } from "./types/radio.js";
34
34
  export { RADIO_COMPONENT_TYPE } from "./types/radio.js";
35
+ export type { APICheckboxComponent, APICheckboxOption } from "./types/checkbox.js";
36
+ export { CHECKBOX_COMPONENT_TYPE } from "./types/checkbox.js";
35
37
  export { ValidationError } from "./types/validation.js";
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ export { UserCommandBuilder, MessageCommandBuilder, AppCommandBuilder, } from ".
3
3
  export { CommandInteractionOptionResolver, createCommandInteraction, } from "./utils/CommandInteractionOptions.js";
4
4
  export { CommandInteraction, MentionableOption, ResolvedUserOption, } from "./utils/CommandInteractionOptions.js";
5
5
  export { UserContextMenuInteraction, MessageContextMenuInteraction, AppCommandInteraction, } from "./utils/ContextMenuInteraction.js";
6
- export { MessageComponentInteraction, ButtonInteraction, StringSelectInteraction, RoleSelectInteraction, UserSelectInteraction, ChannelSelectInteraction, MentionableSelectInteraction, ResolvedUserOption as ComponentResolvedUserOption, ResolvedMentionableOption as ComponentResolvedMentionableOption, } from "./utils/MessageComponentInteraction.js";
6
+ export { MessageComponentInteraction, ButtonInteraction, StringSelectInteraction, RoleSelectInteraction, UserSelectInteraction, ChannelSelectInteraction, MentionableSelectInteraction, RadioInteraction, CheckboxInteraction, ResolvedUserOption as ComponentResolvedUserOption, ResolvedMentionableOption as ComponentResolvedMentionableOption, } from "./utils/MessageComponentInteraction.js";
7
7
  export { ModalSubmitInteraction } from "./utils/ModalSubmitInteraction.js";
8
8
  export { RoleConnectionMetadataTypes } from "./types/RoleConnectionMetadataTypes.js";
9
9
  export { ChannelType } from "./types/ChannelType.js";
@@ -24,4 +24,5 @@ export { InteractionContext } from "./core/interactions/InteractionContext.js";
24
24
  export { verifyAndParseInteraction } from "./core/interactions/InteractionVerifier.js";
25
25
  export { InteractionRouter } from "./router/InteractionRouter.js";
26
26
  export { RADIO_COMPONENT_TYPE } from "./types/radio.js";
27
+ export { CHECKBOX_COMPONENT_TYPE } from "./types/checkbox.js";
27
28
  export { ValidationError } from "./types/validation.js";
@@ -1,6 +1,8 @@
1
1
  import type { APIInteractionResponse, RESTPostAPIChatInputApplicationCommandsJSONBody, RESTPostAPIContextMenuApplicationCommandsJSONBody, RESTPostAPIPrimaryEntryPointApplicationCommandJSONBody } from "discord-api-types/v10";
2
2
  import type { CommandInteraction } from "../utils/CommandInteractionOptions.js";
3
3
  import type { UserContextMenuInteraction, MessageContextMenuInteraction, AppCommandInteraction } from "../utils/ContextMenuInteraction.js";
4
+ import type { ButtonInteraction, StringSelectInteraction, RoleSelectInteraction, UserSelectInteraction, ChannelSelectInteraction, MentionableSelectInteraction, RadioInteraction, CheckboxInteraction } from "../utils/MessageComponentInteraction.js";
5
+ import type { ModalSubmitInteraction } from "../utils/ModalSubmitInteraction.js";
4
6
  import type { JSONEncodable } from "../builders/shared.js";
5
7
  import type { CommandBuilder } from "../commands/CommandBuilder.js";
6
8
  import type { MessageCommandBuilder, UserCommandBuilder, AppCommandBuilder } from "../commands/ContextMenuCommandBuilder.js";
@@ -19,5 +21,17 @@ export type InteractionCommand = {
19
21
  data: RESTPostAPIChatInputApplicationCommandsJSONBody | RESTPostAPIContextMenuApplicationCommandsJSONBody | RESTPostAPIPrimaryEntryPointApplicationCommandJSONBody | CommandBuilder | UserCommandBuilder | MessageCommandBuilder | AppCommandBuilder | JSONEncodable<RESTPostAPIChatInputApplicationCommandsJSONBody | RESTPostAPIContextMenuApplicationCommandsJSONBody | RESTPostAPIPrimaryEntryPointApplicationCommandJSONBody>;
20
22
  handler: CommandHandler;
21
23
  };
24
+ /** Handler for any message component interaction */
25
+ export type ComponentInteraction = ButtonInteraction | StringSelectInteraction | RoleSelectInteraction | UserSelectInteraction | ChannelSelectInteraction | MentionableSelectInteraction | RadioInteraction | CheckboxInteraction;
26
+ /** Structure for a standalone component handler */
27
+ export type InteractionComponent = {
28
+ customId: string;
29
+ handler: (interaction: ComponentInteraction) => Promise<APIInteractionResponse | void> | APIInteractionResponse | void;
30
+ };
31
+ /** Structure for a standalone modal handler */
32
+ export type InteractionModal = {
33
+ customId: string;
34
+ handler: (interaction: ModalSubmitInteraction) => Promise<APIInteractionResponse | void> | APIInteractionResponse | void;
35
+ };
22
36
  /** Map of command names to their registered MiniInteraction command definitions. */
23
37
  export type InteractionCommandsMap = Map<string, InteractionCommand>;
@@ -1,5 +1,19 @@
1
- import type { APIComponentInActionRow, APIComponentInMessageActionRow } from "discord-api-types/v10";
1
+ import type { APIComponentInActionRow, APIComponentInMessageActionRow, APIModalInteractionResponseCallbackComponent } from "discord-api-types/v10";
2
+ import type { APIRadioComponent } from "./radio.js";
3
+ import type { APICheckboxComponent } from "./checkbox.js";
2
4
  /** Defines a component structure for use in ActionRow builders. */
3
- export type ActionRowComponent = APIComponentInActionRow;
5
+ export type ActionRowComponent = APIComponentInActionRow | APIRadioComponent | APICheckboxComponent;
4
6
  /** Defines a message component structure for use in message builders. */
5
- export type MessageActionRowComponent = APIComponentInMessageActionRow;
7
+ export type MessageActionRowComponent = APIComponentInMessageActionRow | APIRadioComponent | APICheckboxComponent;
8
+ /** Structure for an action row containing mini-interaction components. */
9
+ export interface MiniActionRow<T extends ActionRowComponent = ActionRowComponent> {
10
+ type: 1;
11
+ components: T[];
12
+ }
13
+ /** Structure for a message action row containing mini-interaction components. */
14
+ export interface MessageMiniActionRow<T extends MessageActionRowComponent = MessageActionRowComponent> {
15
+ type: 1;
16
+ components: T[];
17
+ }
18
+ /** Generic type for any supported interaction component data. */
19
+ export type InteractionComponentData = MessageActionRowComponent | APIModalInteractionResponseCallbackComponent;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Discord API support for checkbox components may lag behind discord-api-types releases.
3
+ * These local contracts are runtime-validated and serialized as raw component payloads.
4
+ */
5
+ export declare const CHECKBOX_COMPONENT_TYPE: 2002;
6
+ export type APICheckboxOption = {
7
+ label: string;
8
+ value: string;
9
+ description?: string;
10
+ emoji?: {
11
+ id?: string;
12
+ name?: string;
13
+ animated?: boolean;
14
+ };
15
+ default?: boolean;
16
+ };
17
+ export type APICheckboxComponent = {
18
+ type: typeof CHECKBOX_COMPONENT_TYPE;
19
+ custom_id: string;
20
+ disabled?: boolean;
21
+ required?: boolean;
22
+ options: APICheckboxOption[];
23
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Discord API support for checkbox components may lag behind discord-api-types releases.
3
+ * These local contracts are runtime-validated and serialized as raw component payloads.
4
+ */
5
+ export const CHECKBOX_COMPONENT_TYPE = 2002;
@@ -138,6 +138,44 @@ export interface MentionableSelectInteraction extends Omit<APIMessageComponentIn
138
138
  trackResponse?: (interactionId: string, token: string, state: 'responded' | 'deferred') => void;
139
139
  }
140
140
  export declare const MentionableSelectInteraction: {};
141
+ /**
142
+ * Radio interaction with helper methods.
143
+ */
144
+ export interface RadioInteraction extends Omit<APIMessageComponentInteraction, "data"> {
145
+ data: APIMessageStringSelectInteractionData;
146
+ values: string[];
147
+ getStringValues: () => string[];
148
+ getResponse: () => APIInteractionResponse | null;
149
+ reply: (data: InteractionMessageData) => Promise<APIInteractionResponseChannelMessageWithSource>;
150
+ deferReply: (options?: DeferReplyOptions) => APIInteractionResponseDeferredChannelMessageWithSource;
151
+ update: (data?: InteractionMessageData) => Promise<APIInteractionResponseUpdateMessage>;
152
+ deferUpdate: () => APIInteractionResponseDeferredMessageUpdate;
153
+ showModal: (data: APIModalInteractionResponseCallbackData | {
154
+ toJSON(): APIModalInteractionResponseCallbackData;
155
+ }) => APIModalInteractionResponse;
156
+ canRespond?: (interactionId: string) => boolean;
157
+ trackResponse?: (interactionId: string, token: string, state: 'responded' | 'deferred') => void;
158
+ }
159
+ export declare const RadioInteraction: {};
160
+ /**
161
+ * Checkbox interaction with helper methods.
162
+ */
163
+ export interface CheckboxInteraction extends Omit<APIMessageComponentInteraction, "data"> {
164
+ data: APIMessageStringSelectInteractionData;
165
+ values: string[];
166
+ getStringValues: () => string[];
167
+ getResponse: () => APIInteractionResponse | null;
168
+ reply: (data: InteractionMessageData) => Promise<APIInteractionResponseChannelMessageWithSource>;
169
+ deferReply: (options?: DeferReplyOptions) => APIInteractionResponseDeferredChannelMessageWithSource;
170
+ update: (data?: InteractionMessageData) => Promise<APIInteractionResponseUpdateMessage>;
171
+ deferUpdate: () => APIInteractionResponseDeferredMessageUpdate;
172
+ showModal: (data: APIModalInteractionResponseCallbackData | {
173
+ toJSON(): APIModalInteractionResponseCallbackData;
174
+ }) => APIModalInteractionResponse;
175
+ canRespond?: (interactionId: string) => boolean;
176
+ trackResponse?: (interactionId: string, token: string, state: 'responded' | 'deferred') => void;
177
+ }
178
+ export declare const CheckboxInteraction: {};
141
179
  /**
142
180
  * Represents a component interaction augmented with helper response methods.
143
181
  *
@@ -8,6 +8,8 @@ export const RoleSelectInteraction = {};
8
8
  export const UserSelectInteraction = {};
9
9
  export const ChannelSelectInteraction = {};
10
10
  export const MentionableSelectInteraction = {};
11
+ export const RadioInteraction = {};
12
+ export const CheckboxInteraction = {};
11
13
  export const MessageComponentInteraction = {};
12
14
  /**
13
15
  * Wraps a raw component interaction with helper methods mirroring Discord's expected responses.
@@ -1,11 +1,12 @@
1
1
  import type { APIInteractionResponseCallbackData, MessageFlags } from "discord-api-types/v10";
2
- import type { APIActionRowComponent, APIComponentInMessageActionRow, APIContainerComponent } from "discord-api-types/v10";
2
+ import type { APIContainerComponent } from "discord-api-types/v10";
3
3
  import type { JSONEncodable } from "../builders/shared.js";
4
4
  import { InteractionFlags } from "../types/InteractionFlags.js";
5
+ import type { MessageMiniActionRow } from "../types/ComponentTypes.js";
5
6
  /** Union of helper flag enums and raw Discord message flags. */
6
7
  export type MessageFlagLike = MessageFlags | InteractionFlags;
7
8
  /** Top-level components allowed in messages (ActionRows or Containers) */
8
- export type TopLevelComponent = APIActionRowComponent<APIComponentInMessageActionRow> | APIContainerComponent;
9
+ export type TopLevelComponent = MessageMiniActionRow | APIContainerComponent;
9
10
  /** Message payload accepted by helper reply/edit functions. */
10
11
  export type InteractionMessageData = {
11
12
  content?: string;
@@ -10,6 +10,8 @@ const COMPONENTS_V2_TYPES = new Set([
10
10
  ComponentType.Thumbnail,
11
11
  18, // Label
12
12
  19, // FileUpload
13
+ 2001, // Radio
14
+ 2002, // Checkbox
13
15
  ]);
14
16
  /**
15
17
  * Normalises helper flag enums into the raw Discord `MessageFlags` bitfield.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minesa-org/mini-interaction",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "Mini interaction, connecting your app with Discord via HTTP-interaction (Vercel support).",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",