@theholocron/holocron-plugin-discord 5.0.0-alpha.49 → 5.0.0-alpha.491

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/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ <!-- alex disable host-hostess -->
2
+
1
3
  <!-- editorconfig-checker-disable-file -->
2
4
 
3
5
  # `@theholocron/holocron-plugin-discord`
@@ -21,7 +23,7 @@ Token resolution order:
21
23
  2. `HOLOCRON_DISCORD_WEBHOOK` env var
22
24
  3. `DISCORD_WEBHOOK_URL` env var
23
25
  4. Keyring `discord.<org>` — tried first when an org is active via `--org`, `HOLOCRON_ORG`, or `org` in `holocron.config.ts`
24
- 5. Keyring `discord` — unnamespaced fallback; set via `holocron auth set discord <webhook-url>`
26
+ 5. Keyring `discord` — unnamespaced fallback; set via `holocron new token discord <webhook-url>`
25
27
 
26
28
  The "token" is the full incoming webhook URL
27
29
  (`https://discord.com/api/webhooks/{id}/{token}`). No bot account or
@@ -61,3 +63,29 @@ server membership is required — generate one in Discord under
61
63
  The webhook id and token are embedded in the URL path — no `Authorization`
62
64
  header is sent. `parseWebhookUrl` is exported as a utility for callers
63
65
  that need to split the URL into its parts.
66
+
67
+ ## Provisioning
68
+
69
+ `holocron setup notifications` and `holocron new channel` create
70
+ channels, roles and webhooks through the `notifications` capability's `ensure*`
71
+ methods. They use the **Holonet bot**, not a webhook URL:
72
+
73
+ - `HOLOCRON_DISCORD_BOT_TOKEN` (or `DISCORD_BOT_TOKEN`), or the keyring entry
74
+ `discord.holonet` (`holocron new token discord.holonet <token>`) — the bot token
75
+ from the Developer Portal. Only read when a provisioning command runs, or when
76
+ `holocron doctor` checks a provider that has a `guildId`; posting never needs it.
77
+ - `HOLOCRON_DISCORD_CLIENT_SECRET` (or `DISCORD_CLIENT_SECRET`), or the keyring entry
78
+ `discord.holonet.oauth` — the application's OAuth client secret (Developer Portal →
79
+ OAuth2 → Reset Secret). Only `holocron link account` reads it, to learn which
80
+ GitHub account a member owns; the API can neither create nor read it.
81
+ - `guildId` — the server id (not a secret), set in the provider options.
82
+ - `layout` — categories, channels (each optionally with a `webhook`) and roles.
83
+
84
+ The bot needs Manage Channels, Manage Roles, Manage Webhooks and View Channels.
85
+ Everything is idempotent (looked up by name). Discord returns a webhook's URL
86
+ only to the application that created it, so a webhook the bot did not create
87
+ cannot have its URL read back.
88
+
89
+ `baseUrl` only redirects posting. The bot token is always sent to the real
90
+ Discord API unless `unsafeBotBaseUrl: true` is also set (meant for tests that
91
+ stub the API), so a changed config cannot redirect the token to another host.
package/dist/index.d.mts CHANGED
@@ -1,32 +1,20 @@
1
- import { AuthError, Notifications, ResolveTokenInput } from "@theholocron/cli";
2
- //#region src/auth.d.ts
3
- declare const resolveToken: (input?: ResolveTokenInput) => string;
4
- //#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
- //#region src/capabilities/notifications.d.ts
1
+ import { AuthError, DiscussionPatch, DiscussionPost, DuplicateDiscussion, EnsureDiscussionInput, EnsureWebhookResult, EnsuredDiscussion, EnsuredResource, Notifications, NotificationsAccess, NotificationsApplicationLayout, NotificationsDelivery, NotificationsEveryoneLayout, NotificationsForumTag, NotificationsLayout, NotificationsMember, NotificationsOnboardingLayout, NotificationsPinnedLayout, NotificationsReaction, NotificationsServerLayout, NotificationsSignIn, NotificationsWelcomeLayout, PluginToken, ResolveTokenInput, ServerInspection, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess } from "@theholocron/cli";
2
+ import { DiscordBotClient, DiscordClient, DiscordClientOptions, DiscordOAuthClient, DiscordWebhookInfo, createDiscordClient, parseWebhookUrl } from "@theholocron/discord-client";
3
+ /** Resolves the Discord webhook URL from `--token`, `HOLOCRON_DISCORD_WEBHOOK`, `DISCORD_WEBHOOK_URL` or the keyring, and throws an `AuthError` when none is set. */
4
+ export declare const resolveToken: import("@theholocron/cli").TokenResolver;
5
+ /** Resolves the Discord bot token used to provision channels, roles and webhooks, from `HOLOCRON_DISCORD_BOT_TOKEN`, `DISCORD_BOT_TOKEN` or the keyring. */
6
+ export declare const resolveBotToken: import("@theholocron/cli").TokenResolver;
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
+ export declare const resolveClientSecret: import("@theholocron/cli").TokenResolver;
9
+ /**
10
+ * Every token this plugin takes, for `holocron doctor secrets --verify`. `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 bot's `expect` is what each
13
+ * layer's token must carry (membership of the server and the permissions `setup` needs). The webhook is the last resort for a post that names no
14
+ * channel, alias or `defaultChannel`, so nothing needs it by default (`optional`).
15
+ */
16
+ export declare const tokens: PluginToken[];
17
+ /** Options for the Discord `notifications` capability: webhook aliases, the default channel, and the server it provisions. */
30
18
  interface DiscordNotificationsOptions {
31
19
  /**
32
20
  * Named aliases mapping a logical channel name to its webhook URL.
@@ -38,60 +26,400 @@ interface DiscordNotificationsOptions {
38
26
  * without an explicit channel, or with an empty string.
39
27
  */
40
28
  defaultChannel?: string;
29
+ /** Discord server (guild) id that `setup notifications` provisions. Not a secret. */
30
+ guildId?: string;
31
+ /** The server layout `setup notifications` applies. */
32
+ layout?: NotificationsLayout;
33
+ /** A custom API host, for tests. Webhook tokens are only sent to it when `unsafeBotBaseUrl` is also set. */
34
+ baseUrl?: string;
35
+ /** Also send the bot token to `baseUrl`. Off by default so a changed config cannot redirect the bot token to another host; tests that stub the API set it. */
36
+ unsafeBotBaseUrl?: boolean;
41
37
  }
42
- declare class DiscordNotifications implements Notifications {
38
+ /** The Discord implementation of the `notifications` capability: sends messages through webhooks and provisions the server's channels, roles and webhooks with the bot. */
39
+ export declare class DiscordNotifications implements Notifications {
43
40
  private readonly client;
44
41
  private readonly opts;
45
42
  /** Memoized thunk — resolves the default webhook URL on the first `send()`. */
46
43
  private readonly defaultWebhookUrl;
44
+ /** Memoized thunk — resolves the bot token on first provisioning call, never on `send()`. */
45
+ private readonly bot;
46
+ /** Builds the OAuth client for one redirect URI; needs the application's client secret. */
47
+ private readonly oauth;
48
+ /** The capability this class provides, always `"notifications"`. */
47
49
  readonly key: "notifications";
50
+ /** The provider name, `"discord"`. */
48
51
  readonly providerName = "discord";
49
52
  constructor(client: DiscordClient, opts: DiscordNotificationsOptions,
50
53
  /** Memoized thunk — resolves the default webhook URL on the first `send()`. */
51
- defaultWebhookUrl: () => string);
54
+ defaultWebhookUrl: () => string,
55
+ /** Memoized thunk — resolves the bot token on first provisioning call, never on `send()`. */
56
+ bot?: () => DiscordBotClient,
57
+ /** Builds the OAuth client for one redirect URI; needs the application's client secret. */
58
+ oauth?: (redirectUri: string) => Promise<DiscordOAuthClient>);
59
+ /**
60
+ * Sign a member in with Discord to learn which GitHub account they own. Asks only for `identify` and
61
+ * `connections`, reads the account Discord has verified, and revokes the token before returning: nothing
62
+ * about the sign-in is kept.
63
+ */
64
+ signIn(): NotificationsSignIn;
65
+ get layout(): NotificationsLayout | undefined;
52
66
  send(channel: string, message: string): Promise<void>;
67
+ /**
68
+ * `holocron doctor`: the bot token is valid and can see the configured server.
69
+ * Null when no `guildId` is set -- a post-only config has no bot to check. A
70
+ * `layout` without a `guildId` is a half-written provisioning config, so that
71
+ * fails instead of passing as post-only.
72
+ */
73
+ whoami(): Promise<{
74
+ target: string;
75
+ } | null>;
76
+ /**
77
+ * Read-only: what is on the server, for the parts of `layout` we will compare. Webhooks are
78
+ * listed only for channels the layout gives one (one request each), so the cost scales with
79
+ * the layout, not with the server.
80
+ */
81
+ inspect(layout: NotificationsLayout): Promise<ServerInspection>;
82
+ /**
83
+ * What the bot keeps: the usual set, Pin Messages when the layout pins messages, and Manage Threads when it
84
+ * declares a forum (a post's tags are applied by the bot, and a moderated tag only by someone who can manage threads),
85
+ * and Add Reactions when a forum has `starterReactions` (without it the bot skips them and the post still gets made).
86
+ */
87
+ private needs;
88
+ /** Where to re-invite the bot so its role holds what `setup` needs. Re-authorising updates the role in place. */
89
+ private inviteUrl;
90
+ /** Changing server settings needs Manage Server; an empty edit proves the bot has it without changing anything. */
91
+ preflight(layout: NotificationsLayout): Promise<void>;
92
+ /** The one role with this name, or an error saying why not: two would mean granting something to the wrong members. */
93
+ private static pickRole;
94
+ /**
95
+ * The one text or announcement channel with this name, or an error saying why not. A forum counts only for a
96
+ * setting that can point at one (`forums`): the welcome screen and onboarding can; a pinned message and the server's
97
+ * own channels cannot.
98
+ */
99
+ private static pickChannelId;
100
+ /** True for a 403 that is about permissions, not about the bot being unable to see the server at all. */
101
+ private static missingPermissions;
102
+ /** An invite link, or nothing when building it needs a request that fails: the advice must not depend on one. */
103
+ private inviteOrNothing;
104
+ /**
105
+ * Changing a role's permissions is refused (403) when the role would gain one the bot does not hold itself: Discord
106
+ * lets a bot give only what it has. The bot's own role is managed by its integration, so it cannot be edited by
107
+ * hand; re-authorising the bot with the permissions setup needs updates it in place.
108
+ */
109
+ private rolePermissionsHint;
110
+ /** Turning community on or off needs Administrator, which is more than the bot should keep. */
111
+ private communityHint;
112
+ /** A 403 on a server edit becomes the explanation and the invite link; anything else is passed on as it is. */
113
+ private manageServerHint;
114
+ ensureServer(settings: NotificationsServerLayout): Promise<{
115
+ updated: string[];
116
+ }>;
117
+ /** What the bot's roles give it server-wide (the owner holds every permission), before any channel overwrite. */
118
+ private serverPermissions;
119
+ /**
120
+ * The permissions `needs()` lists that the bot's roles do not give it server-wide, in plain words ("Manage Threads"),
121
+ * with the invite link that asks for them again when some are missing. The owner and an Administrator hold every
122
+ * permission. Channel overwrites are not looked at: the forum's own check does that.
123
+ */
124
+ private missingBotPermissions;
125
+ holdsPermission(permission: string): Promise<boolean>;
126
+ /**
127
+ * What a member holding `bits` through the roles in `held` has in a channel, in the order Discord applies the
128
+ * channel's overwrites: @everyone, then the roles, then the member itself.
129
+ */
130
+ private static afterOverwrites;
131
+ /**
132
+ * What the bot can do with the threads of a forum: start posts and reply (`post`) and tag and close them (`manage`).
133
+ * The owner and an Administrator hold every permission, whatever the forum's overwrites say.
134
+ */
135
+ private botThreadsIn;
136
+ /**
137
+ * Whether a channel's own overwrites take a permission away from a bot whose roles grant it, in the order Discord
138
+ * applies them: @everyone, then the bot's roles, then the bot itself. Read fresh, since a person may have just edited them.
139
+ */
140
+ private channelDenies;
141
+ /** The messages this bot posted in a channel, pinned or not, among the channel's last hundred. */
142
+ private ownMessages;
143
+ /**
144
+ * The layout's text with each `#name` that is one of the server's channels turned into Discord's own link to it
145
+ * (`<#id>`), so the message shows clickable channels. A name that matches no channel, or more than one, is left as written.
146
+ */
147
+ private static linkChannels;
148
+ /**
149
+ * The text of a pinned message. The CLI reads a message's `file` into `content` before it calls the provider, so
150
+ * the text is only missing when a caller skipped that.
151
+ */
152
+ private static pinText;
153
+ /** The layout's messages grouped by channel, in the order the channels first appear, with channel names linked. */
154
+ private static pinsByChannel;
155
+ /**
156
+ * What differs in one channel: the declared messages that are not pinned yet, and the bot's pinned messages the
157
+ * layout does not declare (or declares once and the bot pinned twice). The layout is the whole set of the bot's
158
+ * pins in a channel it names.
159
+ */
160
+ private static pinDrift;
161
+ /** Whether each pinned message is in place: pinned by this bot with exactly the layout's text, and nothing else of the bot's pinned beside it. */
162
+ private pinnedStates;
163
+ private discussionStore?;
164
+ /** The discussion posts of this instance's forum channels, which read each forum once. */
165
+ private discussions;
166
+ /** Finds the post for a document in a forum channel, or makes it. See {@link DiscordDiscussions}. */
167
+ ensureDiscussion(input: EnsureDiscussionInput): Promise<EnsuredDiscussion>;
168
+ /** The post for a document in a forum channel, or `undefined`. */
169
+ readDiscussion(channel: string, key: string, url?: string): Promise<DiscussionPost | undefined>;
170
+ /** Changes a document's post: its title, its tag, the state last synced, the pull request line. */
171
+ updateDiscussion(channel: string, key: string, patch: DiscussionPatch): Promise<void>;
172
+ /** Appends a message to a document's post, reopening and closing it again if it was closed. */
173
+ postDiscussionMessage(channel: string, key: string, content: string, opts?: {
174
+ quiet?: boolean;
175
+ }): Promise<void>;
176
+ /** The text of a post's recent messages, newest first. */
177
+ readDiscussionMessages(channel: string, key: string, limit?: number): Promise<string[]>;
178
+ /** Keeps the oldest post for `key` and deletes the others; returns how many it deleted. `refresh` reads the forum again first. */
179
+ dedupeDiscussion(channel: string, key: string, opts?: {
180
+ refresh?: boolean;
181
+ }): Promise<number>;
182
+ /** The keys with more than one post in a forum, with how many are beyond the oldest. Deletes nothing. */
183
+ duplicateDiscussions(channel: string): Promise<DuplicateDiscussion[]>;
184
+ /**
185
+ * Posts `content` (up to 2000 characters) in a text channel as the bot, without letting it mention anyone. A `#name`
186
+ * that is one of the server's channels is linked.
187
+ */
188
+ postMessage(channel: string, content: string): Promise<void>;
189
+ ensurePinned(pinned: NotificationsPinnedLayout[]): Promise<{
190
+ updated: string[];
191
+ }>;
192
+ /** A 403 on pinning becomes the missing permission and a link that grants it, which `setup` can walk a person through. */
193
+ private pinHint;
194
+ /** A 403 on the welcome screen or onboarding becomes the likely reason; anything else is passed on. */
195
+ private static communityFeatureHint;
196
+ /** The numeric code Discord puts in the JSON body of an error, or undefined when the body is not that. */
197
+ private static codeOf;
198
+ /** The welcome screen; a server that never had one answers 404 (10069), which is an empty screen. */
199
+ private welcomeScreenOf;
200
+ ensureWelcome(welcome: NotificationsWelcomeLayout): Promise<{
201
+ updated: string[];
202
+ }>;
203
+ /** An onboarding prompt reduced to what the layout can state, so the server's and the layout's can be compared. */
204
+ private static onboardingKey;
205
+ ensureOnboarding(onboarding: NotificationsOnboardingLayout): Promise<{
206
+ updated: string[];
207
+ }>;
208
+ ensureEveryone(everyone: NotificationsEveryoneLayout): Promise<{
209
+ updated: string[];
210
+ }>;
211
+ ensureApplication(app: NotificationsApplicationLayout): Promise<{
212
+ updated: string[];
213
+ todo?: string[];
214
+ }>;
215
+ /** Whether the Server Members Intent is on: the unverified app's toggle, or the verified app's own bit. */
216
+ private static membersIntentOn;
217
+ validateLayout(layout: NotificationsLayout): string | undefined;
218
+ private botUser?;
219
+ private botId;
220
+ /**
221
+ * The overwrites that make a channel look like `access`. The list is exact: it replaces
222
+ * whatever was set by hand. `[]` (public) when nothing is restricted.
223
+ */
224
+ private overwritesFor;
225
+ /**
226
+ * Read an access back out of a channel's overwrites, naming roles as the layout does. Only
227
+ * overwrites of the shape {@link overwritesFor} writes can be read back; anything else
228
+ * (a role-specific deny, a member overwrite, only some of the posting bits) means the
229
+ * channel's real access is not something the layout can state, and is reported as `"custom"`
230
+ * rather than guessed at.
231
+ */
232
+ private accessOf;
233
+ /** The server's roles, fetched once and forgotten whenever setup changes a role. */
234
+ private roleLoad?;
235
+ private roleList;
236
+ /** The server this run created, which takes over from `guildId` for the rest of the run. */
237
+ private createdGuild?;
238
+ private guild;
239
+ /**
240
+ * The server's channel list, fetched once per instance. Every ensure* call used
241
+ * to refetch it -- about 40 identical GETs in one setup run -- and Discord
242
+ * rate-limited the route. Our own creates and edits update the copy, so it
243
+ * stays accurate for the run; a new run builds a new instance.
244
+ *
245
+ * It is the in-flight promise that is shared, not the array: callers that start
246
+ * while the first fetch is pending all get the same snapshot, so a later
247
+ * response can never overwrite what an earlier caller added.
248
+ */
249
+ private channelLoad?;
250
+ private channelList;
251
+ /**
252
+ * Create a channel and add it to the shared list. If the create fails, Discord
253
+ * may still have applied it (a timeout looks the same as a refusal), so forget the
254
+ * list: the next ensure refetches the server's real state instead of creating a
255
+ * duplicate.
256
+ */
257
+ private createChannel;
258
+ private static same;
259
+ ensureCategory(name: string, opts?: {
260
+ access?: NotificationsAccess;
261
+ }): Promise<EnsuredResource>;
262
+ /**
263
+ * Edit a channel and keep the shared list in step; forget the list if the edit may have half-applied.
264
+ * Discord answers with the channel as it now is: if the overwrites that come back are not the ones we
265
+ * sent, something else changed it at the same time, so say so instead of reporting success.
266
+ */
267
+ private modifyChannel;
268
+ /**
269
+ * Find a channel by name. A name can exist in several categories, so with a
270
+ * parent: prefer the one already there, then an uncategorised one (moved in);
271
+ * never grab a channel that lives under a different category. Announcement
272
+ * channels count: reusing one beats creating a same-named text channel.
273
+ */
274
+ private static findChannel;
275
+ /** A forum tag in the layout's terms. */
276
+ private static tagOf;
277
+ /** A layout tag as Discord takes it. */
278
+ private static tagInput;
279
+ /**
280
+ * The forum's tags once the layout's are in: every tag it has already (kept, with the emoji and `moderated` the layout
281
+ * gives it) and each layout tag it lacks, added. A tag the layout does not list is never removed, since a post
282
+ * carries it. Returns `undefined` when nothing differs.
283
+ */
284
+ private static mergeTags;
285
+ /**
286
+ * Finds the text or announcement channel with this name (under the category, when given), or creates it; reports
287
+ * whether it was created. With `kind: "forum"` it is a forum channel with the layout's tags. Discord cannot turn one
288
+ * kind into the other and this never deletes, so a channel of the other kind with the name stops the run with the fix.
289
+ */
290
+ ensureChannel(input: {
291
+ name: string;
292
+ category?: string;
293
+ topic?: string;
294
+ access?: NotificationsAccess;
295
+ kind?: "text" | "forum";
296
+ tags?: NotificationsForumTag[];
297
+ defaultReaction?: NotificationsReaction;
298
+ }): Promise<EnsuredResource>;
299
+ /**
300
+ * Finds the server emoji with this name or makes it from `image` (a `data:` URI). One that exists is left exactly as it
301
+ * is: never replaced, renamed or deleted, and the image is not compared with it. Making one needs Create Guild
302
+ * Expressions; without it the error says so and carries the link that invites the bot again asking for it.
303
+ */
304
+ ensureEmoji(input: {
305
+ name: string;
306
+ image: string;
307
+ }): Promise<EnsuredResource>;
308
+ /** The server emoji with this name, or an error naming it and the two ways to get one. */
309
+ private emojiNamed;
310
+ /** A layout reaction as Discord's default reaction takes it: the emoji id of a server emoji, or the Unicode character; never both. */
311
+ private defaultReactionOf;
312
+ /**
313
+ * Whether a forum's default reaction is the wanted one. A server emoji is compared by its id alone (Discord may or may
314
+ * not echo its name); a Unicode one by its character, with no id.
315
+ */
316
+ private static sameReaction;
317
+ /**
318
+ * The starter reactions as the text the reaction route takes: the character of a Unicode emoji, `name:id` of a server
319
+ * one. One the server lacks (or whose list cannot be read) is left out, like any reaction that fails: the post is made
320
+ * and `doctor notifications` names the missing emoji.
321
+ */
322
+ private starterReactionTexts;
323
+ /** Finds the webhook with this name on the channel, or creates it; the optional avatar is the picture it posts with. */
324
+ ensureWebhook(input: {
325
+ channel: string;
326
+ name: string;
327
+ category?: string;
328
+ avatar?: string;
329
+ }): Promise<EnsureWebhookResult>;
330
+ checkDelivery(input: {
331
+ channel: string;
332
+ name: string;
333
+ category?: string;
334
+ text: string;
335
+ keep?: boolean;
336
+ }): Promise<NotificationsDelivery>;
337
+ createServer(input: {
338
+ name: string;
339
+ force?: boolean;
340
+ }): Promise<{
341
+ id: string;
342
+ name: string;
343
+ }>;
344
+ /** A server this bot owns (not one it only belongs to) with exactly this name, read across every page. */
345
+ private botOwnedServer;
346
+ inviteLink(channelName: string): Promise<string>;
347
+ hasMember(memberId: string): Promise<boolean>;
348
+ transferServer(memberId: string): Promise<void>;
349
+ serverOwner(): Promise<{
350
+ id: string;
351
+ isBot: boolean;
352
+ name?: string;
353
+ }>;
354
+ /** The one role with this name, or an error that says what to fix: none, or more than one. */
355
+ private roleNamed;
356
+ roleMembers(roleName: string): Promise<NotificationsMember[]>;
357
+ addRoleMember(roleName: string, memberId: string): Promise<void>;
358
+ removeRoleMember(roleName: string, memberId: string): Promise<void>;
359
+ /** Finds the role with this name, or creates it with the given mentionable, color, hoist and permissions settings; reports whether it was created. */
360
+ ensureRole(input: {
361
+ name: string;
362
+ mentionable?: boolean;
363
+ color?: string;
364
+ hoist?: boolean;
365
+ permissions?: string[];
366
+ }): Promise<EnsuredResource>;
53
367
  private resolve;
54
368
  }
55
- //#endregion
56
- //#region src/verify-token.d.ts
57
- interface VerifyTokenSuccess {
58
- ok: true;
59
- subject: string;
60
- }
61
- interface VerifyTokenFailure {
62
- ok: false;
63
- message: string;
64
- }
65
- type VerifyTokenResult = VerifyTokenSuccess | VerifyTokenFailure;
66
369
  interface VerifyTokenOptions {
67
370
  baseUrl?: string;
68
371
  fetch?: typeof fetch;
69
372
  }
70
- declare function verifyToken(webhookUrl: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult>;
71
- //#endregion
72
- //#region src/index.d.ts
73
- interface DiscordPluginOptions extends ResolveTokenInput, DiscordNotificationsOptions {
373
+ /** Checks a Discord webhook URL by fetching the webhook; resolves to its name and id, or the failure message. */
374
+ export declare function verifyToken(webhookUrl: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult$1>;
375
+ /** Options for the Discord plugin: how the webhook URL is resolved plus the notifications settings. */
376
+ export interface DiscordPluginOptions extends ResolveTokenInput, DiscordNotificationsOptions {
74
377
  /** Override base URL for tests. Default: https://discord.com/api/v10 */
75
378
  baseUrl?: string;
379
+ /** The `fetch` to use instead of the global one, for tests. */
76
380
  fetch?: typeof fetch;
381
+ /**
382
+ * Also send the BOT token to `baseUrl`. Off by default: `baseUrl` comes from a
383
+ * repo's config, and a changed config must not be able to redirect the bot
384
+ * token to another host. Tests that stub the API set it.
385
+ */
386
+ unsafeBotBaseUrl?: boolean;
77
387
  }
78
- interface PluginContext {
388
+ /** The shared state the Discord plugin's capability and probes are built from. */
389
+ export interface PluginContext {
390
+ /** The options the plugin was created with. */
79
391
  options: DiscordPluginOptions;
392
+ /** The webhook client used to send messages. */
80
393
  client: DiscordClient;
81
394
  /**
82
395
  * Memoized — the resolved "token" IS Discord's default webhook URL, and it is
83
396
  * resolved on first `send()`, not at plugin load. `describe()` never calls it.
84
397
  */
85
398
  defaultWebhookUrl: () => string;
399
+ /** Memoized — resolves the bot token on the first provisioning call, or when `holocron doctor` checks a provider that has a `guildId`; `send()` and `describe()` never touch it. */
400
+ bot: () => DiscordBotClient;
401
+ /** Builds the OAuth client for one redirect URI; resolves the application id and the client secret on first use. */
402
+ oauth: (redirectUri: string) => Promise<DiscordOAuthClient>;
86
403
  }
87
- declare function createContext(options?: DiscordPluginOptions): PluginContext;
88
- declare function notifications(ctx: PluginContext): Notifications;
89
- declare function createPlugin(options?: DiscordPluginOptions): {
404
+ /** Builds the plugin context from its options; the webhook URL, bot token and client secret are each resolved on first use. */
405
+ export declare function createContext(options?: DiscordPluginOptions): PluginContext;
406
+ /** Builds the `notifications` capability for a context. */
407
+ export declare function notifications(ctx: PluginContext): Notifications;
408
+ /**
409
+ * Creates the Discord plugin: its `notifications` capability and its `connection` and `token` probes. The probe checks the webhook
410
+ * when there is one, and the bot token when there is not: the webhook is only a last resort for a post that names no
411
+ * channel, so a missing one is not a failed connection when the bot can be reached.
412
+ */
413
+ export declare function createPlugin(options?: DiscordPluginOptions): {
90
414
  name: string;
415
+ probes: {
416
+ token: import("@theholocron/cli").Probe;
417
+ connection: import("@theholocron/cli").Probe;
418
+ };
91
419
  capabilities: {
92
420
  notifications: () => Notifications;
93
421
  };
94
422
  };
95
- declare const AUTH_HINT: string;
96
- //#endregion
97
- export { AUTH_HINT, AuthError, type DiscordClient, type DiscordClientOptions, DiscordNotifications, type DiscordNotificationsOptions, DiscordPluginOptions, type DiscordWebhookInfo, PluginContext, type ResolveTokenInput, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, createContext, createDiscordClient, createPlugin, notifications, parseWebhookUrl, resolveToken, verifyToken };
423
+ /** One-line hint printed by `holocron new token discord` when no webhook URL is supplied or the supplied one is rejected. */
424
+ export declare const AUTH_HINT: string;
425
+ export { AuthError, type DiscordClient, type DiscordClientOptions, type DiscordNotificationsOptions, type DiscordWebhookInfo, type ResolveTokenInput, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, createDiscordClient, parseWebhookUrl };