@minesa-org/mini-interaction 0.4.5 → 0.4.7

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.
@@ -203,8 +203,13 @@ export class MiniInteraction {
203
203
  }
204
204
  async runWithResponseLifecycle(interaction, executor) {
205
205
  let ackResponse;
206
+ let initialResponseCommitted = false;
206
207
  const helpers = {
207
- canRespond: (interactionId) => (this.responseStates.get(interactionId) ?? "pending") === "pending",
208
+ // Legacy helper contracts use canRespond for both initial acknowledgements
209
+ // and later editReply/followUp calls. The compat layer does not currently
210
+ // track Discord token expiry, so we only block on real expiry outside of
211
+ // this helper and allow the wrapped interaction methods to complete.
212
+ canRespond: (_interactionId) => true,
208
213
  trackResponse: (interactionId, _token, state) => {
209
214
  this.responseStates.set(interactionId, state);
210
215
  },
@@ -212,6 +217,14 @@ export class MiniInteraction {
212
217
  ackResponse = response;
213
218
  },
214
219
  sendFollowUp: async (token, response, messageId) => {
220
+ // If the initial interaction response has not been sent yet, collapse the
221
+ // deferred/edit flow back into a single immediate response instead of
222
+ // calling the webhook endpoints early.
223
+ if (!initialResponseCommitted) {
224
+ ackResponse = response;
225
+ this.responseStates.set(interaction.id, "responded");
226
+ return;
227
+ }
215
228
  const responseData = "data" in response ? response.data ?? {} : {};
216
229
  if (messageId === "@original") {
217
230
  await this.rest.editOriginal(token, responseData);
@@ -247,6 +260,7 @@ export class MiniInteraction {
247
260
  if (this.options.debug || this.options.timeoutConfig?.enableResponseDebugLogging) {
248
261
  console.debug(`[MiniInteraction] Interaction ${interaction.id} completed with ${result ? "explicit" : "fallback"} response.`);
249
262
  }
263
+ initialResponseCommitted = true;
250
264
  return result ?? ackResponse;
251
265
  }
252
266
  finally {
@@ -35,6 +35,7 @@ export declare class MiniDatabase {
35
35
  collectionName?: string;
36
36
  }): MiniDatabase;
37
37
  constructor(config: DatabaseConfig, schema?: MiniDataBuilder);
38
+ private sanitiseStoredData;
38
39
  /**
39
40
  * Initializes the database connection.
40
41
  */
@@ -44,6 +44,10 @@ export class MiniDatabase {
44
44
  this.config = config;
45
45
  this.schema = schema;
46
46
  }
47
+ sanitiseStoredData(data) {
48
+ const { _id, createdAt, updatedAt, ...rest } = data;
49
+ return rest;
50
+ }
47
51
  /**
48
52
  * Initializes the database connection.
49
53
  */
@@ -125,9 +129,10 @@ export class MiniDatabase {
125
129
  const dataWithDefaults = this.schema
126
130
  ? this.schema.applyDefaults(data)
127
131
  : data;
132
+ const sanitizedData = this.sanitiseStoredData(dataWithDefaults);
128
133
  await collection.updateOne({ _id: key }, {
129
134
  $set: {
130
- ...dataWithDefaults,
135
+ ...sanitizedData,
131
136
  _id: key,
132
137
  updatedAt: new Date(),
133
138
  },
@@ -164,9 +169,10 @@ export class MiniDatabase {
164
169
  const dataWithDefaults = this.schema
165
170
  ? this.schema.applyDefaults(merged)
166
171
  : merged;
172
+ const sanitizedData = this.sanitiseStoredData(dataWithDefaults);
167
173
  await collection.updateOne({ _id: key }, {
168
174
  $set: {
169
- ...dataWithDefaults,
175
+ ...sanitizedData,
170
176
  updatedAt: new Date(),
171
177
  },
172
178
  $setOnInsert: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minesa-org/mini-interaction",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
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",