@theholocron/holocron-plugin-discord 5.0.0-alpha.365 → 5.0.0-alpha.366

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
@@ -7,8 +7,9 @@ export declare const resolveBotToken: import("@theholocron/cli").TokenResolver;
7
7
  /** Resolves the Discord application's OAuth client secret used to sign members in, from `HOLOCRON_DISCORD_CLIENT_SECRET`, `DISCORD_CLIENT_SECRET` or the keyring. */
8
8
  export declare const resolveClientSecret: import("@theholocron/cli").TokenResolver;
9
9
  /**
10
- * Every token this plugin takes, for `holocron doctor tokens`. `verifyToken` checks a webhook URL, so the bot token and
11
- * the OAuth client secret are listed but not handed to it. The webhook is the last resort for a post that names no
10
+ * Every token this plugin takes, for `holocron doctor tokens`. `verifyToken` checks a webhook URL, so the bot token has
11
+ * its own `verify` (it asks for the bot's application) and the OAuth client secret, which cannot be checked without a
12
+ * sign-in, is listed but not handed to it. The webhook is the last resort for a post that names no
12
13
  * channel, alias or `defaultChannel`, so nothing needs it by default (`optional`).
13
14
  */
14
15
  export declare const tokens: PluginToken[];
package/dist/index.mjs CHANGED
@@ -1,6 +1,26 @@
1
1
  import { AuthError, ElevationRequiredError, ProviderApiError, connectionProbe, createResolveToken } from "@theholocron/cli";
2
2
  import { errorMessage } from "@theholocron/misc-utils";
3
3
  import { ApplicationFlag, ChannelType, MessageFlag, createDiscordBotClient, createDiscordClient, createDiscordOAuthClient, findVerifiedConnection, parseWebhookUrl, permissionNames, permissions } from "@theholocron/discord-client";
4
+ // src/verify-bot-token.ts
5
+ /** Checks a Discord bot token by asking for the bot's own application; resolves to its name and id, or the failure message. */
6
+ async function verifyBotToken(botToken, opts = {}) {
7
+ try {
8
+ const app = await createDiscordBotClient({
9
+ botToken,
10
+ ...opts.unsafeBotBaseUrl && opts.baseUrl ? { baseUrl: opts.baseUrl } : {},
11
+ ...opts.fetch ? { fetch: opts.fetch } : {}
12
+ }).application.get();
13
+ return {
14
+ ok: true,
15
+ subject: `bot: ${app.name} (id: ${app.id})`
16
+ };
17
+ } catch (err) {
18
+ return {
19
+ ok: false,
20
+ message: errorMessage(err)
21
+ };
22
+ }
23
+ }
4
24
  // src/auth.ts
5
25
  /** Resolves the Discord webhook URL from `--token`, `HOLOCRON_DISCORD_WEBHOOK`, `DISCORD_WEBHOOK_URL` or the keyring, and throws an `AuthError` when none is set. */
6
26
  const resolveToken = createResolveToken({
@@ -24,8 +44,9 @@ const resolveClientSecret = createResolveToken({
24
44
  errorMessage: "no Discord client secret found. Set HOLOCRON_DISCORD_CLIENT_SECRET (or DISCORD_CLIENT_SECRET), or run: holocron auth set discord.holonet.oauth <secret> — it is the client secret from the developer portal (OAuth2 → Reset Secret), which the API cannot create or read."
25
45
  });
26
46
  /**
27
- * Every token this plugin takes, for `holocron doctor tokens`. `verifyToken` checks a webhook URL, so the bot token and
28
- * the OAuth client secret are listed but not handed to it. The webhook is the last resort for a post that names no
47
+ * Every token this plugin takes, for `holocron doctor tokens`. `verifyToken` checks a webhook URL, so the bot token has
48
+ * its own `verify` (it asks for the bot's application) and the OAuth client secret, which cannot be checked without a
49
+ * sign-in, is listed but not handed to it. The webhook is the last resort for a post that names no
29
50
  * channel, alias or `defaultChannel`, so nothing needs it by default (`optional`).
30
51
  */
31
52
  const tokens = [
@@ -35,7 +56,7 @@ const tokens = [
35
56
  },
36
57
  {
37
58
  ...resolveBotToken.token,
38
- verifiable: false
59
+ verify: (token) => verifyBotToken(token)
39
60
  },
40
61
  {
41
62
  ...resolveClientSecret.token,
@@ -2092,26 +2113,6 @@ var DiscordNotifications = class DiscordNotifications {
2092
2113
  return this.defaultWebhookUrl();
2093
2114
  }
2094
2115
  };
2095
- // src/verify-bot-token.ts
2096
- /** Checks a Discord bot token by asking for the bot's own application; resolves to its name and id, or the failure message. */
2097
- async function verifyBotToken(botToken, opts = {}) {
2098
- try {
2099
- const app = await createDiscordBotClient({
2100
- botToken,
2101
- ...opts.unsafeBotBaseUrl && opts.baseUrl ? { baseUrl: opts.baseUrl } : {},
2102
- ...opts.fetch ? { fetch: opts.fetch } : {}
2103
- }).application.get();
2104
- return {
2105
- ok: true,
2106
- subject: `bot: ${app.name} (id: ${app.id})`
2107
- };
2108
- } catch (err) {
2109
- return {
2110
- ok: false,
2111
- message: errorMessage(err)
2112
- };
2113
- }
2114
- }
2115
2116
  // src/verify-token.ts
2116
2117
  /** Checks a Discord webhook URL by fetching the webhook; resolves to its name and id, or the failure message. */
2117
2118
  async function verifyToken(webhookUrl, opts = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-discord",
3
- "version": "5.0.0-alpha.365",
3
+ "version": "5.0.0-alpha.366",
4
4
  "description": "Holocron plugin for Discord. Implements the notifications capability via Discord incoming webhooks.",
5
5
  "keywords": [
6
6
  "discord",
@@ -41,19 +41,19 @@
41
41
  "tsx": "4.23.15",
42
42
  "typescript": "^5.9.3",
43
43
  "vitest": "^5.0.5",
44
- "@theholocron/cli": "5.0.0-alpha.365",
44
+ "@theholocron/cli": "5.0.0-alpha.366",
45
+ "@theholocron/eslint-config": "^8.9.0-alpha.11",
46
+ "@theholocron/discord-client": "^1.58.0-alpha.15",
45
47
  "@theholocron/misc-utils": "^1.17.0-alpha.1",
46
48
  "@theholocron/tsconfig": "^8.9.0-alpha.11",
47
- "@theholocron/http-client": "^1.58.0-alpha.15",
49
+ "@theholocron/tsdown-config": "^8.9.0-alpha.11",
48
50
  "@theholocron/vitest-config": "^8.9.0-alpha.11",
49
- "@theholocron/discord-client": "^1.58.0-alpha.15",
50
- "@theholocron/eslint-config": "^8.9.0-alpha.11",
51
- "@theholocron/tsdown-config": "^8.9.0-alpha.11"
51
+ "@theholocron/http-client": "^1.58.0-alpha.15"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "@theholocron/discord-client": "^1.50.0",
55
55
  "@theholocron/misc-utils": "^1.16.0",
56
- "@theholocron/cli": "5.0.0-alpha.365"
56
+ "@theholocron/cli": "5.0.0-alpha.366"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">=22"