@minesa-org/mini-interaction 0.3.8 → 0.3.10

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.
@@ -12,6 +12,7 @@ export type InteractionClientOptions = {
12
12
  commandsDirectory?: string | false;
13
13
  componentsDirectory?: string | false;
14
14
  utilsDirectory?: string | false;
15
+ debug?: boolean;
15
16
  fetchImplementation?: typeof fetch;
16
17
  verifyKeyImplementation?: VerifyKeyFunction;
17
18
  timeoutConfig?: InteractionTimeoutConfig;
@@ -178,6 +179,7 @@ export declare class MiniInteraction {
178
179
  private readonly commandsDirectory;
179
180
  private readonly componentsDirectory;
180
181
  readonly utilsDirectory: string | null;
182
+ private readonly debug;
181
183
  private readonly timeoutConfig;
182
184
  private readonly commands;
183
185
  private readonly componentHandlers;
@@ -196,6 +198,7 @@ export declare class MiniInteraction {
196
198
  * Creates a new MiniInteraction client with optional command auto-loading and custom runtime hooks.
197
199
  */
198
200
  constructor(options?: InteractionClientOptions);
201
+ private log;
199
202
  private trackInteractionState;
200
203
  /**
201
204
  * Checks if an interaction can still respond (not expired and not already responded).
@@ -31,6 +31,7 @@ export class MiniInteraction {
31
31
  commandsDirectory;
32
32
  componentsDirectory;
33
33
  utilsDirectory;
34
+ debug;
34
35
  timeoutConfig;
35
36
  commands = new Map();
36
37
  componentHandlers = new Map();
@@ -54,7 +55,8 @@ export class MiniInteraction {
54
55
  // @ts-ignore - Optional dependency, may not have types available during build
55
56
  import("dotenv/config").catch(() => { });
56
57
  }
57
- const { applicationId, publicKey, commandsDirectory, componentsDirectory, utilsDirectory, fetchImplementation, verifyKeyImplementation, timeoutConfig, } = options;
58
+ const { applicationId, publicKey, commandsDirectory, componentsDirectory, utilsDirectory, debug, fetchImplementation, verifyKeyImplementation, timeoutConfig, } = options;
59
+ this.debug = debug ?? (typeof process !== "undefined" ? process.env.DEBUG === "true" || process.env.MINI_DEBUG === "true" : false);
58
60
  const resolvedAppId = applicationId ?? (typeof process !== "undefined" ? process.env.DISCORD_APPLICATION_ID : undefined);
59
61
  const resolvedPublicKey = publicKey ?? (typeof process !== "undefined" ? (process.env.DISCORD_PUBLIC_KEY ?? process.env.DISCORD_APP_PUBLIC_KEY) : undefined);
60
62
  const fetchImpl = fetchImplementation ?? globalThis.fetch;
@@ -85,6 +87,11 @@ export class MiniInteraction {
85
87
  ...timeoutConfig,
86
88
  };
87
89
  }
90
+ log(message, ...args) {
91
+ if (this.debug) {
92
+ console.log(`[MiniInteraction] ${message}`, ...args);
93
+ }
94
+ }
88
95
  trackInteractionState(interactionId, token, state) {
89
96
  const now = Date.now();
90
97
  this.interactionStates.set(interactionId, {
@@ -856,6 +863,9 @@ export class MiniInteraction {
856
863
  * Recursively collects all command module file paths from the target directory.
857
864
  */
858
865
  async collectModuleFiles(directory) {
866
+ if (this.debug) {
867
+ this.log(`Collecting module files from: ${directory}`);
868
+ }
859
869
  const entries = await readdir(directory, { withFileTypes: true });
860
870
  const files = [];
861
871
  for (const entry of entries) {
@@ -891,6 +901,7 @@ export class MiniInteraction {
891
901
  async importCommandModule(absolutePath) {
892
902
  try {
893
903
  const moduleUrl = pathToFileURL(absolutePath).href;
904
+ this.log(`Dynamically importing command: ${moduleUrl}`);
894
905
  const imported = await import(moduleUrl);
895
906
  // Try to find a command object from various export patterns
896
907
  let candidate = imported.default ??
@@ -954,6 +965,7 @@ export class MiniInteraction {
954
965
  async importComponentModule(absolutePath) {
955
966
  try {
956
967
  const moduleUrl = pathToFileURL(absolutePath).href;
968
+ this.log(`Dynamically importing component: ${moduleUrl}`);
957
969
  const imported = await import(moduleUrl);
958
970
  // Collect all potential component candidates
959
971
  const candidates = [];
@@ -1139,10 +1151,17 @@ export class MiniInteraction {
1139
1151
  pushCandidate(path.resolve(root, defaultFolder));
1140
1152
  }
1141
1153
  for (const candidate of candidates) {
1142
- if (existsSync(candidate)) {
1154
+ const exists = existsSync(candidate);
1155
+ if (this.debug) {
1156
+ this.log(`Checking directory: ${candidate} (exists: ${exists})`);
1157
+ }
1158
+ if (exists) {
1143
1159
  return candidate;
1144
1160
  }
1145
1161
  }
1162
+ if (this.debug) {
1163
+ this.log(`No existing directory found for ${defaultFolder}, using default candidate: ${candidates[0]}`);
1164
+ }
1146
1165
  return candidates[0];
1147
1166
  }
1148
1167
  /**
@@ -51,5 +51,6 @@ export declare const MiniPermFlags: {
51
51
  readonly SendPolls: bigint;
52
52
  readonly UseExternalApps: bigint;
53
53
  readonly PinMessages: bigint;
54
+ readonly BypassSlowmode: bigint;
54
55
  };
55
56
  export type MiniPermFlag = (typeof MiniPermFlags)[keyof typeof MiniPermFlags];
@@ -63,24 +63,29 @@ export function createModalSubmitInteraction(interaction, helpers) {
63
63
  };
64
64
  const getResponse = () => capturedResponse;
65
65
  const getTextFieldValue = (customId) => {
66
- for (const actionRow of interaction.data.components) {
67
- if ("components" in actionRow && Array.isArray(actionRow.components)) {
68
- const findValue = (components) => {
69
- for (const component of components) {
70
- if (component.custom_id === customId &&
71
- typeof component.value === "string") {
72
- return component.value;
73
- }
74
- // Check for nested component (e.g. Label wrapper)
75
- if (component.component) {
76
- const found = findValue([component.component]);
77
- if (found)
78
- return found;
79
- }
80
- }
81
- return undefined;
82
- };
83
- const result = findValue(actionRow.components);
66
+ const findValue = (components) => {
67
+ for (const component of components) {
68
+ if (component?.custom_id === customId &&
69
+ typeof component.value === "string") {
70
+ return component.value;
71
+ }
72
+ // Nested Label wrapper: single child in .component
73
+ if (component?.component) {
74
+ const found = findValue([component.component]);
75
+ if (found)
76
+ return found;
77
+ }
78
+ }
79
+ return undefined;
80
+ };
81
+ for (const top of interaction.data.components) {
82
+ if ("components" in top && Array.isArray(top.components)) {
83
+ const result = findValue(top.components);
84
+ if (result)
85
+ return result;
86
+ }
87
+ if ("component" in top && top.component) {
88
+ const result = findValue([top.component]);
84
89
  if (result)
85
90
  return result;
86
91
  }
@@ -89,28 +94,36 @@ export function createModalSubmitInteraction(interaction, helpers) {
89
94
  };
90
95
  /**
91
96
  * Helper method to get the value(s) of a select menu component by its custom ID.
92
- * Handles the nested structure of modal components (Action Rows -> Components).
93
- * Also handles nested components within wrappers (like Label components).
97
+ * Handles the nested structure of modal components (Action Rows -> Components,
98
+ * and Label -> single component). Select menus in modals are typically inside
99
+ * Label components, not Action Rows.
94
100
  */
95
101
  const getSelectMenuValues = (customId) => {
96
- for (const actionRow of interaction.data.components) {
97
- if ("components" in actionRow && Array.isArray(actionRow.components)) {
98
- const findValues = (components) => {
99
- for (const component of components) {
100
- if (component.custom_id === customId &&
101
- Array.isArray(component.values)) {
102
- return component.values;
103
- }
104
- // Check for nested component (e.g. Label wrapper)
105
- if (component.component) {
106
- const found = findValues([component.component]);
107
- if (found)
108
- return found;
109
- }
110
- }
111
- return undefined;
112
- };
113
- const result = findValues(actionRow.components);
102
+ const findValues = (components) => {
103
+ for (const component of components) {
104
+ if (component?.custom_id === customId &&
105
+ Array.isArray(component.values)) {
106
+ return component.values;
107
+ }
108
+ // Nested Label wrapper: single child in .component
109
+ if (component?.component) {
110
+ const found = findValues([component.component]);
111
+ if (found)
112
+ return found;
113
+ }
114
+ }
115
+ return undefined;
116
+ };
117
+ for (const top of interaction.data.components) {
118
+ // Action Row: multiple components in .components
119
+ if ("components" in top && Array.isArray(top.components)) {
120
+ const result = findValues(top.components);
121
+ if (result)
122
+ return result;
123
+ }
124
+ // Label: select menu (and other modal components) wrapped in .component
125
+ if ("component" in top && top.component) {
126
+ const result = findValues([top.component]);
114
127
  if (result)
115
128
  return result;
116
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minesa-org/mini-interaction",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
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",