@theholocron/holocron-plugin-discord 3.63.0 → 3.64.0

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
@@ -42,9 +42,13 @@ interface DiscordNotificationsOptions {
42
42
  declare class DiscordNotifications implements Notifications {
43
43
  private readonly client;
44
44
  private readonly opts;
45
+ /** Memoized thunk — resolves the default webhook URL on the first `send()`. */
46
+ private readonly defaultWebhookUrl;
45
47
  readonly key: "notifications";
46
48
  readonly providerName = "discord";
47
- constructor(client: DiscordClient, opts: DiscordNotificationsOptions);
49
+ constructor(client: DiscordClient, opts: DiscordNotificationsOptions,
50
+ /** Memoized thunk — resolves the default webhook URL on the first `send()`. */
51
+ defaultWebhookUrl: () => string);
48
52
  send(channel: string, message: string): Promise<void>;
49
53
  private resolve;
50
54
  }
@@ -74,7 +78,11 @@ interface DiscordPluginOptions extends ResolveTokenInput, DiscordNotificationsOp
74
78
  interface PluginContext {
75
79
  options: DiscordPluginOptions;
76
80
  client: DiscordClient;
77
- defaultWebhookUrl: string;
81
+ /**
82
+ * Memoized — the resolved "token" IS Discord's default webhook URL, and it is
83
+ * resolved on first `send()`, not at plugin load. `describe()` never calls it.
84
+ */
85
+ defaultWebhookUrl: () => string;
78
86
  }
79
87
  declare function createContext(options?: DiscordPluginOptions): PluginContext;
80
88
  declare function notifications(ctx: PluginContext): Notifications;
package/dist/index.mjs CHANGED
@@ -41,14 +41,16 @@ function parseWebhookUrl(url) {
41
41
  var DiscordNotifications = class {
42
42
  client;
43
43
  opts;
44
+ defaultWebhookUrl;
44
45
  key = "notifications";
45
46
  providerName = "discord";
46
- constructor(client, opts) {
47
+ constructor(client, opts, defaultWebhookUrl) {
47
48
  this.client = client;
48
49
  this.opts = opts;
50
+ this.defaultWebhookUrl = defaultWebhookUrl;
49
51
  }
50
52
  async send(channel, message) {
51
- const { id, token } = parseWebhookUrl(this.resolve(channel || (this.opts.defaultChannel ?? "")));
53
+ const { id, token } = parseWebhookUrl(this.resolve(channel || this.opts.defaultChannel || ""));
52
54
  await this.client.webhooks.execute(id, token, message);
53
55
  }
54
56
  resolve(channel) {
@@ -57,7 +59,7 @@ var DiscordNotifications = class {
57
59
  if (channel.startsWith("https://")) return channel;
58
60
  const def = this.opts.defaultChannel;
59
61
  if (def) return this.opts.webhooks?.[def] ?? def;
60
- throw new Error(`DiscordNotifications.send: unknown channel "${channel}" — pass a webhook URL, an alias key, or set defaultChannel`);
62
+ return this.defaultWebhookUrl();
61
63
  }
62
64
  };
63
65
  //#endregion
@@ -83,21 +85,18 @@ async function verifyToken(webhookUrl, opts = {}) {
83
85
  //#endregion
84
86
  //#region src/index.ts
85
87
  function createContext(options = {}) {
86
- const defaultWebhookUrl = resolveToken(options);
88
+ let url;
87
89
  return {
88
90
  options,
89
91
  client: createDiscordClient({
90
92
  baseUrl: options.baseUrl,
91
93
  fetch: options.fetch
92
94
  }),
93
- defaultWebhookUrl
95
+ defaultWebhookUrl: () => url ??= resolveToken(options)
94
96
  };
95
97
  }
96
98
  function notifications(ctx) {
97
- return new DiscordNotifications(ctx.client, {
98
- ...ctx.options,
99
- defaultChannel: ctx.options.defaultChannel ?? ctx.defaultWebhookUrl
100
- });
99
+ return new DiscordNotifications(ctx.client, ctx.options, ctx.defaultWebhookUrl);
101
100
  }
102
101
  function createPlugin(options = {}) {
103
102
  const ctx = createContext(options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-discord",
3
- "version": "3.63.0",
3
+ "version": "3.64.0",
4
4
  "description": "Holocron plugin for Discord. Implements the notifications capability via Discord incoming webhooks.",
5
5
  "keywords": [
6
6
  "discord",
@@ -45,10 +45,10 @@
45
45
  "tsx": "4.23.12",
46
46
  "typescript": "^5.9.3",
47
47
  "vitest": "^4.1.11",
48
- "@theholocron/cli": "3.63.0"
48
+ "@theholocron/cli": "3.64.0"
49
49
  },
50
50
  "peerDependencies": {
51
- "@theholocron/cli": "3.63.0"
51
+ "@theholocron/cli": "3.64.0"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=22"