@theholocron/holocron-plugin-discord 5.0.0-alpha.116 → 5.0.0-alpha.117

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.
package/dist/index.d.mts CHANGED
@@ -1,31 +1,8 @@
1
1
  import { AuthError, Notifications, ResolveTokenInput, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess } from "@theholocron/cli";
2
+ import { DiscordClient, DiscordClientOptions, DiscordWebhookInfo, createDiscordClient, parseWebhookUrl } from "@theholocron/discord-client";
2
3
  //#region src/auth.d.ts
3
4
  declare const resolveToken: (input?: ResolveTokenInput) => string;
4
5
  //#endregion
5
- //#region src/rest.d.ts
6
- interface DiscordClientOptions {
7
- /** Override base URL for tests. Default: https://discord.com/api/v10 */
8
- baseUrl?: string;
9
- fetch?: typeof fetch;
10
- }
11
- interface DiscordWebhookInfo {
12
- id: string;
13
- name: string;
14
- guild_id?: string;
15
- }
16
- interface DiscordClient {
17
- webhooks: {
18
- get(id: string, token: string): Promise<DiscordWebhookInfo>;
19
- execute(id: string, token: string, content: string): Promise<void>;
20
- };
21
- }
22
- declare function createDiscordClient({ baseUrl, fetch: fetchImpl }?: DiscordClientOptions): DiscordClient;
23
- /** Parse a Discord webhook URL into its id and token parts. */
24
- declare function parseWebhookUrl(url: string): {
25
- id: string;
26
- token: string;
27
- };
28
- //#endregion
29
6
  //#region src/capabilities/notifications.d.ts
30
7
  interface DiscordNotificationsOptions {
31
8
  /**
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import { AuthError, ProviderApiError, createResolveToken } from "@theholocron/cli";
1
+ import { AuthError, createResolveToken } from "@theholocron/cli";
2
+ import { createDiscordClient, parseWebhookUrl } from "@theholocron/discord-client";
2
3
  import { errorMessage } from "@theholocron/misc-utils";
3
4
  //#region src/auth.ts
4
5
  const resolveToken = createResolveToken({
@@ -8,36 +9,6 @@ const resolveToken = createResolveToken({
8
9
  errorMessage: "no Discord webhook URL found. Pass --token <WEBHOOK_URL>, set HOLOCRON_DISCORD_WEBHOOK / DISCORD_WEBHOOK_URL, or run: holocron auth set discord <https://discord.com/api/webhooks/...>"
9
10
  });
10
11
  //#endregion
11
- //#region src/rest.ts
12
- function createDiscordClient({ baseUrl, fetch: fetchImpl } = {}) {
13
- const base = baseUrl ?? "https://discord.com/api/v10";
14
- const f = fetchImpl ?? globalThis.fetch;
15
- return { webhooks: {
16
- get: async (id, token) => {
17
- const res = await f(`${base}/webhooks/${id}/${token}`, { method: "GET" });
18
- if (!res.ok) throw new ProviderApiError(`Discord webhook not found or invalid (${res.status})`, res.status, void 0);
19
- return res.json();
20
- },
21
- execute: async (id, token, content) => {
22
- const res = await f(`${base}/webhooks/${id}/${token}`, {
23
- method: "POST",
24
- headers: { "content-type": "application/json" },
25
- body: JSON.stringify({ content })
26
- });
27
- if (!res.ok) throw new ProviderApiError(`Discord webhook POST failed (${res.status})`, res.status, void 0);
28
- }
29
- } };
30
- }
31
- /** Parse a Discord webhook URL into its id and token parts. */
32
- function parseWebhookUrl(url) {
33
- const match = url.match(/webhooks\/(\d+)\/([^/?#]+)/);
34
- if (!match) throw new Error(`Invalid Discord webhook URL: ${url}`);
35
- return {
36
- id: match[1],
37
- token: match[2]
38
- };
39
- }
40
- //#endregion
41
12
  //#region src/capabilities/notifications.ts
42
13
  var DiscordNotifications = class {
43
14
  client;
@@ -51,7 +22,8 @@ var DiscordNotifications = class {
51
22
  this.defaultWebhookUrl = defaultWebhookUrl;
52
23
  }
53
24
  async send(channel, message) {
54
- const { id, token } = parseWebhookUrl(this.resolve(channel || this.opts.defaultChannel || ""));
25
+ const webhookUrl = this.resolve(channel || this.opts.defaultChannel || "");
26
+ const { id, token } = parseWebhookUrl(webhookUrl);
55
27
  await this.client.webhooks.execute(id, token, message);
56
28
  }
57
29
  resolve(channel) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-discord",
3
- "version": "5.0.0-alpha.116",
3
+ "version": "5.0.0-alpha.117",
4
4
  "description": "Holocron plugin for Discord. Implements the notifications capability via Discord incoming webhooks.",
5
5
  "keywords": [
6
6
  "discord",
@@ -30,8 +30,9 @@
30
30
  "dist"
31
31
  ],
32
32
  "devDependencies": {
33
+ "@theholocron/discord-client": "^1.37.1",
33
34
  "@theholocron/eslint-config": "^8.7.0",
34
- "@theholocron/http-client": "^1.37.1",
35
+ "@theholocron/http-client": "^1.38.0",
35
36
  "@theholocron/misc-utils": "^1.9.2",
36
37
  "@theholocron/tsconfig": "^8.7.0",
37
38
  "@theholocron/tsdown-config": "^8.7.0",
@@ -47,11 +48,12 @@
47
48
  "tsx": "4.23.12",
48
49
  "typescript": "^5.9.3",
49
50
  "vitest": "^4.1.11",
50
- "@theholocron/cli": "5.0.0-alpha.116"
51
+ "@theholocron/cli": "5.0.0-alpha.117"
51
52
  },
52
53
  "peerDependencies": {
54
+ "@theholocron/discord-client": "^1.37.1",
53
55
  "@theholocron/misc-utils": "^1.9.2",
54
- "@theholocron/cli": "5.0.0-alpha.116"
56
+ "@theholocron/cli": "5.0.0-alpha.117"
55
57
  },
56
58
  "engines": {
57
59
  "node": ">=22"