@minesa-org/mini-interaction 0.4.7 → 0.4.8

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,7 +12,9 @@ export declare class DiscordRestClient {
12
12
  private readonly baseUrl;
13
13
  private readonly maxRetries;
14
14
  constructor(options: DiscordRestClientOptions);
15
- request<T>(path: string, init?: RequestInit): Promise<T>;
15
+ request<T>(path: string, init?: RequestInit & {
16
+ authenticated?: boolean;
17
+ }): Promise<T>;
16
18
  createFollowup(interactionToken: string, body: unknown): Promise<unknown>;
17
19
  editOriginal(interactionToken: string, body: unknown): Promise<unknown>;
18
20
  }
@@ -12,13 +12,14 @@ export class DiscordRestClient {
12
12
  }
13
13
  async request(path, init = {}) {
14
14
  let lastError;
15
+ const { authenticated = true, ...requestInit } = init;
15
16
  for (let attempt = 0; attempt <= this.maxRetries; attempt += 1) {
16
17
  const response = await this.fetchImpl(`${this.baseUrl}${path}`, {
17
- ...init,
18
+ ...requestInit,
18
19
  headers: {
19
- Authorization: `Bot ${this.options.token}`,
20
+ ...(authenticated ? { Authorization: `Bot ${this.options.token}` } : {}),
20
21
  'Content-Type': 'application/json',
21
- ...(init.headers ?? {}),
22
+ ...(requestInit.headers ?? {}),
22
23
  },
23
24
  });
24
25
  if (response.status === 429) {
@@ -35,7 +36,7 @@ export class DiscordRestClient {
35
36
  await sleep(150 * (attempt + 1));
36
37
  continue;
37
38
  }
38
- lastError = new Error(`[DiscordRestClient] ${init.method ?? 'GET'} ${path} failed: ${response.status}`);
39
+ lastError = new Error(`[DiscordRestClient] ${requestInit.method ?? 'GET'} ${path} failed: ${response.status}`);
39
40
  break;
40
41
  }
41
42
  throw lastError instanceof Error ? lastError : new Error('[DiscordRestClient] unknown request failure');
@@ -44,12 +45,14 @@ export class DiscordRestClient {
44
45
  return this.request(`/webhooks/${this.options.applicationId}/${interactionToken}`, {
45
46
  method: 'POST',
46
47
  body: JSON.stringify(body),
48
+ authenticated: false,
47
49
  });
48
50
  }
49
51
  editOriginal(interactionToken, body) {
50
52
  return this.request(`/webhooks/${this.options.applicationId}/${interactionToken}/messages/@original`, {
51
53
  method: 'PATCH',
52
54
  body: JSON.stringify(body),
55
+ authenticated: false,
53
56
  });
54
57
  }
55
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minesa-org/mini-interaction",
3
- "version": "0.4.7",
3
+ "version": "0.4.8",
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",