@seedcord/http 0.1.0-next.2 → 0.1.0-next.3
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/{edge.index-joDL39cK.cjs → edge.index-Bd6sbr37.cjs} +243 -7
- package/dist/edge.index-Bd6sbr37.cjs.map +1 -0
- package/dist/{edge.index-BBRnxxkS.mjs → edge.index-Cv4plNWY.mjs} +198 -10
- package/dist/edge.index-Cv4plNWY.mjs.map +1 -0
- package/dist/{edge.index-C30OZ55m.d.mts → edge.index-atnWgXP-.d.mts} +97 -18
- package/dist/edge.index.cjs +5 -1
- package/dist/edge.index.d.mts +3 -2
- package/dist/edge.index.mjs +2 -2
- package/dist/index.cjs +68 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +15 -8
- package/dist/index.mjs +66 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -5
- package/dist/edge.index-BBRnxxkS.mjs.map +0 -1
- package/dist/edge.index-joDL39cK.cjs.map +0 -1
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
import { t as RouteManifest } from "./RouteManifest-DE-HCMwd.mjs";
|
|
2
2
|
import { REST } from "@discordjs/rest";
|
|
3
|
-
import { AutocompleteOptions, BaseHandler, Bus, CoreBase, DispatchContext, Gate, GateContextBase, GuildPermissionsContext, RepliableHandler, RequiredOf, SelectMenuKind, SlashOptionRegistry, Subscriber, SubscriptionKey, WebhookLog } from "@seedcord/core";
|
|
4
|
-
import { AnyCustomId, AutocompletableNames, BaseReplySender, ChoiceValueOf, EntryFor, FocusedField, GateFitsWith, HasComponentDefs, InteractionRoutes, MatchArms, ModalLike, SingleParams, SlashOptions } from "@seedcord/core/internal";
|
|
5
|
-
import { APIApplicationCommandAutocompleteInteraction, APIApplicationCommandOptionChoice, APIAttachment, APIChatInputApplicationCommandInteraction, APIContextMenuInteraction, APIInteraction, APIInteractionDataResolvedChannelBase, APIInteractionDataResolvedGuildMember, APIInteractionGuildMember, APIMessage, APIMessageApplicationCommandInteraction, APIMessageChannelSelectInteractionData, APIMessageComponentButtonInteraction, APIMessageComponentInteraction, APIMessageComponentSelectMenuInteraction, APIMessageMentionableSelectInteractionData, APIMessageRoleSelectInteractionData, APIMessageStringSelectInteractionData, APIMessageUserSelectInteractionData, APIModalInteractionResponseCallbackData, APIModalSubmitInteraction, APIRole, APIThreadChannel, APIUser, APIUserApplicationCommandInteraction, ApplicationCommandType, ChannelType, ThreadChannelType } from "discord-api-types/v10";
|
|
3
|
+
import { ArraySource, AutocompleteOptions, BaseHandler, Bus, ContextMenuKind, CoreBase, CursorSource, DispatchContext, Gate, GateContextBase, GuildPermissionsContext, PaginatorBase, PaginatorConfig, RepliableHandler, RequiredOf, SelectMenuKind, SlashOptionRegistry, Subscriber, SubscriptionKey, WebhookLog } from "@seedcord/core";
|
|
4
|
+
import { AnyCustomId, AutocompletableNames, BaseReplySender, ChoiceValueOf, EntryFor, FocusedField, GateFitsWith, HasComponentDefs, InteractionRoutes, MatchArms, ModalLike, PageCursor, SingleParams, SlashOptions } from "@seedcord/core/internal";
|
|
5
|
+
import { APIApplicationCommandAutocompleteInteraction, APIApplicationCommandOptionChoice, APIAttachment, APIChatInputApplicationCommandInteraction, APIContextMenuInteraction, APIInteraction, APIInteractionDataResolvedChannelBase, APIInteractionDataResolvedGuildMember, APIInteractionGuildMember, APIMessage, APIMessageApplicationCommandInteraction, APIMessageChannelSelectInteractionData, APIMessageComponentButtonInteraction, APIMessageComponentEmoji, APIMessageComponentInteraction, APIMessageComponentSelectMenuInteraction, APIMessageMentionableSelectInteractionData, APIMessageRoleSelectInteractionData, APIMessageStringSelectInteractionData, APIMessageUserSelectInteractionData, APIModalInteractionResponseCallbackData, APIModalSubmitInteraction, APIRole, APIThreadChannel, APIUser, APIUserApplicationCommandInteraction, ApplicationCommandType, ChannelType, ThreadChannelType } from "discord-api-types/v10";
|
|
6
6
|
import { API } from "@discordjs/core/http-only";
|
|
7
|
-
import { Config, DeferOpts, HealthCheckOption, ReplyResponse, SendOpts } from "@seedcord/types";
|
|
7
|
+
import { Config, DeferOpts, EmojiMap, HealthCheckOption, ReplyResponse, SendOpts } from "@seedcord/types";
|
|
8
8
|
import { NonEmptyTuple, Promisable } from "type-fest";
|
|
9
9
|
|
|
10
|
-
//#region src/plugin-capabilities.d.ts
|
|
11
|
-
declare module '@seedcord/core' {
|
|
12
|
-
interface PluginCapabilityTypes {
|
|
13
|
-
rest: REST;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
//#endregion
|
|
17
10
|
//#region src/subscriptions.d.ts
|
|
18
11
|
declare module '@seedcord/core/internal' {
|
|
19
12
|
interface DefaultSubscriptions {
|
|
@@ -66,8 +59,6 @@ type HttpConfig = HttpServerConfig | HttpEdgeConfig;
|
|
|
66
59
|
* ```
|
|
67
60
|
*/
|
|
68
61
|
interface Core extends CoreBase {
|
|
69
|
-
/** Workerd-compatible Discord REST client. */
|
|
70
|
-
readonly rest: REST;
|
|
71
62
|
readonly config: HttpConfig;
|
|
72
63
|
}
|
|
73
64
|
//#endregion
|
|
@@ -117,6 +108,22 @@ interface HttpLens {
|
|
|
117
108
|
*/
|
|
118
109
|
type SlashOptions$1<Route extends keyof SlashOptionRegistry> = SlashOptions<Route, HttpLens>;
|
|
119
110
|
//#endregion
|
|
111
|
+
//#region src/emojis/EmojiInjector.d.ts
|
|
112
|
+
/** A resolved emoji. Renders as `<:name:id>` in message content, or `<a:name:id>` when animated. */
|
|
113
|
+
interface ResolvedEmoji extends APIMessageComponentEmoji {
|
|
114
|
+
readonly id: string;
|
|
115
|
+
readonly name: string;
|
|
116
|
+
readonly animated: boolean;
|
|
117
|
+
toString(): string;
|
|
118
|
+
}
|
|
119
|
+
/** The global {@link Emojis} accessor type. */
|
|
120
|
+
type InjectedEmojiMap = { [K in keyof EmojiMap]: ResolvedEmoji };
|
|
121
|
+
/**
|
|
122
|
+
* The bot's resolved emojis, keyed by {@link EmojiMap}. Filled by {@link EmojiInjector} during startup.
|
|
123
|
+
* A read before that throws.
|
|
124
|
+
*/
|
|
125
|
+
declare const Emojis: InjectedEmojiMap;
|
|
126
|
+
//#endregion
|
|
120
127
|
//#region src/reply/ReplySender.d.ts
|
|
121
128
|
/** The interaction payload fields the sender writes its wire from. */
|
|
122
129
|
interface InteractionRef {
|
|
@@ -165,6 +172,8 @@ type Repliables = Exclude<ValidInteractionTypes, APIApplicationCommandAutocomple
|
|
|
165
172
|
* @typeParam Event - The repliable interaction type this handler processes
|
|
166
173
|
*/
|
|
167
174
|
declare abstract class RepliableHandler$1<Event extends Repliables> extends RepliableHandler<Event, Core, SentMessage, ReplySender> {
|
|
175
|
+
/** @internal */
|
|
176
|
+
getEvent(): Event;
|
|
168
177
|
protected buildSender(event: Event, core: Core, routeId: string): ReplySender;
|
|
169
178
|
/**
|
|
170
179
|
* Typed Discord REST API (`@discordjs/core/http-only`) over `core.rest`, one instance per core.
|
|
@@ -229,7 +238,6 @@ declare abstract class SlashHandler<Route extends keyof SlashOptionRegistry> ext
|
|
|
229
238
|
}
|
|
230
239
|
//#endregion
|
|
231
240
|
//#region src/handlers/interaction/ContextMenuHandler.d.ts
|
|
232
|
-
type ContextMenuKind = ApplicationCommandType.User | ApplicationCommandType.Message;
|
|
233
241
|
type InteractionFor<Kind extends ContextMenuKind> = Kind extends ApplicationCommandType.User ? APIUserApplicationCommandInteraction : APIMessageApplicationCommandInteraction;
|
|
234
242
|
type TargetFor<Kind extends ContextMenuKind> = Kind extends ApplicationCommandType.User ? APIUser : APIMessage;
|
|
235
243
|
type TargetMemberFor<Kind extends ContextMenuKind> = Kind extends ApplicationCommandType.User ? APIInteractionDataResolvedGuildMember | null : never;
|
|
@@ -412,9 +420,9 @@ declare abstract class SelectMenuHandler<Kind extends SelectMenuKind, Defs exten
|
|
|
412
420
|
declare abstract class ModalHandler<Defs extends readonly AnyCustomId[]> extends ComponentHandler<APIModalSubmitInteraction, Defs> {
|
|
413
421
|
/** @internal */
|
|
414
422
|
readonly __component?: 'modal';
|
|
415
|
-
/** Rewrite the message this modal was opened from
|
|
423
|
+
/** Rewrite the message this modal was opened from. Throws when a command opened the modal. */
|
|
416
424
|
protected update(response: ReplyResponse | string): Promise<SentMessage>;
|
|
417
|
-
/**
|
|
425
|
+
/** Acknowledge the submit without changing the source message. Throws when a command opened the modal. */
|
|
418
426
|
protected deferUpdate(): Promise<void>;
|
|
419
427
|
private ensureSourceMessage;
|
|
420
428
|
}
|
|
@@ -434,6 +442,77 @@ declare abstract class Subscriber$1<KeyOfSubscribers extends SubscriptionKey> ex
|
|
|
434
442
|
*/
|
|
435
443
|
declare abstract class WebhookLog$1<KeyOfSubscribers extends SubscriptionKey> extends WebhookLog<KeyOfSubscribers, Core> {}
|
|
436
444
|
//#endregion
|
|
445
|
+
//#region src/pagination/PageContext.d.ts
|
|
446
|
+
/**
|
|
447
|
+
* The context passed to a source loader. The raw payload carries a guild id with no guild object, so a
|
|
448
|
+
* loader that requires guild data fetches it through `core.rest`.
|
|
449
|
+
*/
|
|
450
|
+
interface PageContext {
|
|
451
|
+
/** The interaction that triggered this load (a command or a nav click). */
|
|
452
|
+
interaction: Repliables;
|
|
453
|
+
/** The acting user, always present. */
|
|
454
|
+
user: APIUser;
|
|
455
|
+
/** The guild id, or `null` in a DM. */
|
|
456
|
+
guildId: string | null;
|
|
457
|
+
/** The framework core. */
|
|
458
|
+
core: Core;
|
|
459
|
+
}
|
|
460
|
+
//#endregion
|
|
461
|
+
//#region src/pagination/Paginator.d.ts
|
|
462
|
+
type PaginatorHandlerCtor<Prefix extends string> = new (event: APIMessageComponentButtonInteraction, core: Core) => ButtonHandler<[PageCursor<Prefix>]> & {
|
|
463
|
+
execute(): Promise<void>;
|
|
464
|
+
};
|
|
465
|
+
/**
|
|
466
|
+
* A restart-proof paginator. Each nav button's customId encodes its full target page, so clicks are
|
|
467
|
+
* idempotent and survive a restart. A persistent `@ButtonRoute` on `Handler` dispatches the clicks.
|
|
468
|
+
*
|
|
469
|
+
* @typeParam Item - The item type, inferred from the source.
|
|
470
|
+
* @typeParam Prefix - The route prefix, inferred from `config.prefix`.
|
|
471
|
+
*
|
|
472
|
+
* @example
|
|
473
|
+
* ```ts
|
|
474
|
+
* export const Bans = new Paginator({
|
|
475
|
+
* prefix: 'bans',
|
|
476
|
+
* source: new ArraySource((ctx) => loadBans(ctx.guildId), { perPage: 10 }),
|
|
477
|
+
* renderItem: (ban) => ban.user.username
|
|
478
|
+
* });
|
|
479
|
+
*
|
|
480
|
+
* \@ButtonRoute(Bans.cursor)
|
|
481
|
+
* export class BansNav extends Bans.Handler {}
|
|
482
|
+
* ```
|
|
483
|
+
*/
|
|
484
|
+
declare class Paginator<Item, const Prefix extends string> extends PaginatorBase<Item, Prefix, PageContext> {
|
|
485
|
+
/** The nav handler base. Extend it with an empty body and decorate it, `@ButtonRoute(p.cursor)`. */
|
|
486
|
+
readonly Handler: PaginatorHandlerCtor<Prefix>;
|
|
487
|
+
constructor(config: PaginatorConfig<Item, Prefix, PageContext>);
|
|
488
|
+
/**
|
|
489
|
+
* Render page 0 and send it through the handler's sender, which picks reply, edit, or followUp from its
|
|
490
|
+
* ack state.
|
|
491
|
+
*
|
|
492
|
+
* @param handler - The handler starting the paginator, normally `this`.
|
|
493
|
+
*/
|
|
494
|
+
start(handler: RepliableHandler$1<Repliables>): Promise<SentMessage>;
|
|
495
|
+
}
|
|
496
|
+
//#endregion
|
|
497
|
+
//#region src/pagination/sources.d.ts
|
|
498
|
+
/**
|
|
499
|
+
* A source for a bounded list you can load whole. It loads the full list on every click, then slices the
|
|
500
|
+
* page, so the real total is known (a real last button, "Page X of Y"). Cache inside your loader if the
|
|
501
|
+
* load is expensive.
|
|
502
|
+
*
|
|
503
|
+
* @typeParam Item - The item type, inferred from the loader's return.
|
|
504
|
+
*/
|
|
505
|
+
declare class ArraySource$1<Item> extends ArraySource<Item, PageContext> {}
|
|
506
|
+
/**
|
|
507
|
+
* A source for a large or unknown-length set you fetch one page at a time (SQL LIMIT/OFFSET, a paged API).
|
|
508
|
+
* The fetcher receives the page index and the page size and reports whether a next page exists. A cursor
|
|
509
|
+
* source has no cheap total, so `totalPages` is undefined, the last button is omitted, and the indicator
|
|
510
|
+
* reads "Page X".
|
|
511
|
+
*
|
|
512
|
+
* @typeParam Item - The item type, inferred from the fetcher's slice.
|
|
513
|
+
*/
|
|
514
|
+
declare class CursorSource$1<Item> extends CursorSource<Item, PageContext> {}
|
|
515
|
+
//#endregion
|
|
437
516
|
//#region src/gates/Gate.d.ts
|
|
438
517
|
/**
|
|
439
518
|
* The interaction gate context on the HTTP transport. It extends the scalar {@link GateContextBase} with the
|
|
@@ -521,5 +600,5 @@ declare function Gated<const Gates extends NonEmptyTuple<Gate<GateContextBase>>>
|
|
|
521
600
|
/** Package version */
|
|
522
601
|
declare const version: string;
|
|
523
602
|
//#endregion
|
|
524
|
-
export {
|
|
525
|
-
//# sourceMappingURL=edge.index-
|
|
603
|
+
export { createSeedcord as C, HttpEdgeConfig as D, HttpConfig as E, HttpServerConfig as O, SlashOptions$1 as S, Core as T, InteractionHandler as _, CursorSource$1 as a, InjectedEmojiMap as b, Subscriber$1 as c, SelectMenuHandler as d, ButtonHandler as f, SlashHandler as g, ContextMenuHandler as h, ArraySource$1 as i, WebhookLog$1 as l, AutocompleteHandler as m, Gated as n, Paginator as o, ComponentHandler as p, InteractionGateContext as r, PageContext as s, version as t, ModalHandler as u, RepliableHandler$1 as v, EngineContext as w, ResolvedEmoji as x, Emojis as y };
|
|
604
|
+
//# sourceMappingURL=edge.index-atnWgXP-.d.mts.map
|
package/dist/edge.index.cjs
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_edge_index = require('./edge.index-
|
|
2
|
+
const require_edge_index = require('./edge.index-Bd6sbr37.cjs');
|
|
3
3
|
|
|
4
|
+
exports.ArraySource = require_edge_index.ArraySource;
|
|
4
5
|
exports.AutocompleteHandler = require_edge_index.AutocompleteHandler;
|
|
5
6
|
exports.ButtonHandler = require_edge_index.ButtonHandler;
|
|
6
7
|
exports.ComponentHandler = require_edge_index.ComponentHandler;
|
|
7
8
|
exports.ContextMenuHandler = require_edge_index.ContextMenuHandler;
|
|
9
|
+
exports.CursorSource = require_edge_index.CursorSource;
|
|
10
|
+
exports.Emojis = require_edge_index.Emojis;
|
|
8
11
|
exports.Gated = require_edge_index.Gated;
|
|
9
12
|
exports.InteractionHandler = require_edge_index.InteractionHandler;
|
|
10
13
|
exports.ModalHandler = require_edge_index.ModalHandler;
|
|
14
|
+
exports.Paginator = require_edge_index.Paginator;
|
|
11
15
|
exports.RepliableHandler = require_edge_index.RepliableHandler;
|
|
12
16
|
exports.SelectMenuHandler = require_edge_index.SelectMenuHandler;
|
|
13
17
|
exports.SlashHandler = require_edge_index.SlashHandler;
|
package/dist/edge.index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { _ as
|
|
1
|
+
import { C as createSeedcord, D as HttpEdgeConfig, E as HttpConfig, O as HttpServerConfig, S as SlashOptions, T as Core, _ as InteractionHandler, a as CursorSource, b as InjectedEmojiMap, c as Subscriber, d as SelectMenuHandler, f as ButtonHandler, g as SlashHandler, h as ContextMenuHandler, i as ArraySource, l as WebhookLog, m as AutocompleteHandler, n as Gated, o as Paginator, p as ComponentHandler, r as InteractionGateContext, s as PageContext, t as version, u as ModalHandler, v as RepliableHandler, w as EngineContext, x as ResolvedEmoji, y as Emojis } from "./edge.index-atnWgXP-.mjs";
|
|
2
2
|
import { t as RouteManifest } from "./RouteManifest-DE-HCMwd.mjs";
|
|
3
3
|
export * from "@seedcord/core";
|
|
4
|
-
export
|
|
4
|
+
export type * from "@seedcord/types";
|
|
5
|
+
export { ArraySource, AutocompleteHandler, ButtonHandler, ComponentHandler, ContextMenuHandler, type Core, CursorSource, Emojis, type EngineContext, Gated, type HttpConfig, type HttpEdgeConfig, type HttpServerConfig, type InjectedEmojiMap, type InteractionGateContext, InteractionHandler, ModalHandler, type PageContext, Paginator, RepliableHandler, type ResolvedEmoji, type RouteManifest, SelectMenuHandler, SlashHandler, type SlashOptions, Subscriber, WebhookLog, createSeedcord, version };
|
package/dist/edge.index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { S as RepliableHandler, _ as createSeedcord, a as Paginator, b as InteractionHandler, c as ModalHandler, d as ComponentHandler, f as ContextMenuHandler, h as Emojis, i as CursorSource, l as SelectMenuHandler, n as Gated, o as Subscriber, p as SlashHandler, r as ArraySource, s as WebhookLog, t as version, u as ButtonHandler, x as AutocompleteHandler } from "./edge.index-Cv4plNWY.mjs";
|
|
2
2
|
|
|
3
3
|
export * from "@seedcord/core"
|
|
4
4
|
|
|
5
|
-
export { AutocompleteHandler, ButtonHandler, ComponentHandler, ContextMenuHandler, Gated, InteractionHandler, ModalHandler, RepliableHandler, SelectMenuHandler, SlashHandler, Subscriber, WebhookLog, createSeedcord, version };
|
|
5
|
+
export { ArraySource, AutocompleteHandler, ButtonHandler, ComponentHandler, ContextMenuHandler, CursorSource, Emojis, Gated, InteractionHandler, ModalHandler, Paginator, RepliableHandler, SelectMenuHandler, SlashHandler, Subscriber, WebhookLog, createSeedcord, version };
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_edge_index = require('./edge.index-
|
|
2
|
+
const require_edge_index = require('./edge.index-Bd6sbr37.cjs');
|
|
3
3
|
let _seedcord_errors_internal = require("@seedcord/errors/internal");
|
|
4
4
|
let envapt = require("envapt");
|
|
5
5
|
let _discordjs_rest = require("@discordjs/rest");
|
|
@@ -17,6 +17,8 @@ let _seedcord_types_internal = require("@seedcord/types/internal");
|
|
|
17
17
|
let _seedcord_core_hmr = require("@seedcord/core/hmr");
|
|
18
18
|
let _seedcord_utils = require("@seedcord/utils");
|
|
19
19
|
let _seedcord_utils_node = require("@seedcord/utils/node");
|
|
20
|
+
let chalk = require("chalk");
|
|
21
|
+
chalk = require_edge_index.__toESM(chalk, 1);
|
|
20
22
|
let _seedcord_core_plugin = require("@seedcord/core/plugin");
|
|
21
23
|
|
|
22
24
|
//#region src/manifest/RouteManifest.ts
|
|
@@ -85,6 +87,19 @@ var InteractionDispatcher = class {
|
|
|
85
87
|
async onHmr(event) {
|
|
86
88
|
await this.hmrHandler?.handle(event);
|
|
87
89
|
}
|
|
90
|
+
warnUnhandledRoutes(commandLeaves) {
|
|
91
|
+
this.warnMissing(commandLeaves, this.maps.slash, "Slash route", "@SlashRoute");
|
|
92
|
+
}
|
|
93
|
+
warnUnhandledContextMenuRoutes(leaves) {
|
|
94
|
+
this.warnMissing(leaves.user, this.maps.userContextMenu, "User context menu", "@ContextMenuRoute");
|
|
95
|
+
this.warnMissing(leaves.message, this.maps.messageContextMenu, "Message context menu", "@ContextMenuRoute");
|
|
96
|
+
}
|
|
97
|
+
warnMissing(names, map, label, decorator) {
|
|
98
|
+
for (const name of names) {
|
|
99
|
+
if (map.has(name)) continue;
|
|
100
|
+
this.logger.warn(`${label} ${_seedcord_logger.paint.sky.bold(name)} has no registered ${chalk.default.bold(decorator)} handler.`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
88
103
|
isHandler(value) {
|
|
89
104
|
if (typeof value !== "function") return false;
|
|
90
105
|
return (value.prototype instanceof require_edge_index.InteractionHandler || value.prototype instanceof require_edge_index.AutocompleteHandler) && Reflect.hasMetadata(_seedcord_core_internal.InteractionMetadataKey, value);
|
|
@@ -251,6 +266,10 @@ var Seedcord = class Seedcord extends _seedcord_core_node_internal.Pluggable {
|
|
|
251
266
|
bus;
|
|
252
267
|
subscribers;
|
|
253
268
|
interactions;
|
|
269
|
+
commandRegistry;
|
|
270
|
+
appId;
|
|
271
|
+
appIdPromise;
|
|
272
|
+
emojiInjector = new require_edge_index.EmojiInjector(this, () => this.applicationId());
|
|
254
273
|
healthCheck;
|
|
255
274
|
hmrManager;
|
|
256
275
|
logger = new _seedcord_logger.Logger("Server", { channel: "bot" });
|
|
@@ -266,6 +285,19 @@ var Seedcord = class Seedcord extends _seedcord_core_node_internal.Pluggable {
|
|
|
266
285
|
this.hmrManager = new _seedcord_core_internal.HmrManager();
|
|
267
286
|
this.hmrManager.init();
|
|
268
287
|
if (this.config.bot.interactions.path) this.interactions = new InteractionDispatcher(this.config.bot.interactions.path);
|
|
288
|
+
const commandsDir = this.config.bot.commands.path;
|
|
289
|
+
if (commandsDir) {
|
|
290
|
+
const injector = new _seedcord_core_internal.CommandInjector();
|
|
291
|
+
const registry = new _seedcord_core_node_internal.CommandRegistry({
|
|
292
|
+
dir: commandsDir,
|
|
293
|
+
rest: this.rest,
|
|
294
|
+
applicationId: () => this.requireApplicationId(),
|
|
295
|
+
onDeployed: (result) => {
|
|
296
|
+
injector.inject(result, registry.allCommands());
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
this.commandRegistry = registry;
|
|
300
|
+
}
|
|
269
301
|
this.rateLimiter = config.store ?? new _seedcord_rate_limiter.MemoryRateLimiter();
|
|
270
302
|
this.bus = new _seedcord_core.Bus(this);
|
|
271
303
|
this.subscribers = new _seedcord_core_node_internal.SubscriberLoader(this.bus, config.subscribers.path);
|
|
@@ -280,13 +312,6 @@ var Seedcord = class Seedcord extends _seedcord_core_node_internal.Pluggable {
|
|
|
280
312
|
get port() {
|
|
281
313
|
return this.boundPort;
|
|
282
314
|
}
|
|
283
|
-
pluginCapabilities() {
|
|
284
|
-
const token = envapt.Envapter.get("DISCORD_BOT_TOKEN");
|
|
285
|
-
return {
|
|
286
|
-
rest: this.rest,
|
|
287
|
-
...token !== void 0 && { token }
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
315
|
/**
|
|
291
316
|
* Starts the host and runs the startup tasks.
|
|
292
317
|
*
|
|
@@ -320,6 +345,19 @@ var Seedcord = class Seedcord extends _seedcord_core_node_internal.Pluggable {
|
|
|
320
345
|
await interactions.init();
|
|
321
346
|
interactions.logger.utils.initialization("Interactions", "end");
|
|
322
347
|
});
|
|
348
|
+
this.startup.addTask(_seedcord_core_node_internal.StartupPhase.Configuration, "authenticate", () => {
|
|
349
|
+
this.authenticate();
|
|
350
|
+
return Promise.resolve();
|
|
351
|
+
});
|
|
352
|
+
this.startup.addTask(_seedcord_core_node_internal.StartupPhase.Login, "emoji-injection", () => this.emojiInjector.init());
|
|
353
|
+
const { commandRegistry } = this;
|
|
354
|
+
if (commandRegistry) this.startup.addTask(_seedcord_core_node_internal.StartupPhase.Login, "command-deploy", async () => {
|
|
355
|
+
await commandRegistry.init();
|
|
356
|
+
this.appId = await this.applicationId();
|
|
357
|
+
await commandRegistry.setCommands();
|
|
358
|
+
interactions?.warnUnhandledRoutes(commandRegistry.routeLeaves());
|
|
359
|
+
interactions?.warnUnhandledContextMenuRoutes(commandRegistry.contextMenuLeaves());
|
|
360
|
+
});
|
|
323
361
|
this.startup.addTask(_seedcord_core_node_internal.StartupPhase.Ready, "http-server", () => this.listen());
|
|
324
362
|
if (!envapt.Envapter.isTest) this.startup.addTask(_seedcord_core_node_internal.StartupPhase.Ready, "identity", () => this.fetchUsername());
|
|
325
363
|
const { healthCheck } = this;
|
|
@@ -332,14 +370,24 @@ var Seedcord = class Seedcord extends _seedcord_core_node_internal.Pluggable {
|
|
|
332
370
|
registerHmrAwareModules() {
|
|
333
371
|
this.startup.addTask(_seedcord_core_node_internal.StartupPhase.Configuration, "hmr-registration", async () => {
|
|
334
372
|
if (this.interactions) this.hmrManager.register(this.interactions);
|
|
373
|
+
if (this.commandRegistry) this.hmrManager.register(this.commandRegistry);
|
|
335
374
|
this.hmrManager.register(this.subscribers);
|
|
336
375
|
for (const plugin of this.plugins) this.hmrManager.register(plugin);
|
|
337
376
|
await Promise.resolve();
|
|
338
377
|
});
|
|
339
378
|
}
|
|
379
|
+
authenticate() {
|
|
380
|
+
this.rest.setToken((0, _seedcord_errors_internal.validateDiscordToken)(envapt.Envapter.get("DISCORD_BOT_TOKEN")));
|
|
381
|
+
}
|
|
382
|
+
applicationId() {
|
|
383
|
+
this.appIdPromise ??= require_edge_index.fetchApplicationId(this.rest);
|
|
384
|
+
return this.appIdPromise;
|
|
385
|
+
}
|
|
386
|
+
requireApplicationId() {
|
|
387
|
+
if (!this.appId) throw new _seedcord_errors_internal.SeedcordError(_seedcord_errors.SeedcordErrorCode.CoreApplicationUnavailable);
|
|
388
|
+
return this.appId;
|
|
389
|
+
}
|
|
340
390
|
async listen() {
|
|
341
|
-
const token = (0, _seedcord_errors_internal.validateDiscordToken)(envapt.Envapter.get("DISCORD_BOT_TOKEN"));
|
|
342
|
-
this.rest.setToken(token);
|
|
343
391
|
const maps = this.interactions?.maps ?? require_edge_index.buildRouteMaps(EMPTY_MANIFEST);
|
|
344
392
|
const { handle, inFlight } = require_edge_index.buildEngine(this, maps);
|
|
345
393
|
const server = (0, node_http.createServer)((incoming, outgoing) => {
|
|
@@ -390,22 +438,26 @@ var Seedcord = class Seedcord extends _seedcord_core_node_internal.Pluggable {
|
|
|
390
438
|
* Base class for an HTTP plugin, binding `this.core` to the HTTP {@link Core}.
|
|
391
439
|
*
|
|
392
440
|
* A plugin that runs on either transport extends the base from `@seedcord/core/plugin`, whose
|
|
393
|
-
* `this.core`
|
|
441
|
+
* `this.core` is typed to the shared members only.
|
|
394
442
|
*
|
|
395
|
-
* @typeParam Opts - The transport
|
|
443
|
+
* @typeParam Opts - The transport and runtime the plugin declares.
|
|
396
444
|
*/
|
|
397
445
|
var Plugin = class extends _seedcord_core_plugin.Plugin {};
|
|
398
446
|
|
|
399
447
|
//#endregion
|
|
400
448
|
//#region src/index.ts
|
|
401
449
|
var src_exports = /* @__PURE__ */ require_edge_index.__exportAll({
|
|
450
|
+
ArraySource: () => require_edge_index.ArraySource,
|
|
402
451
|
AutocompleteHandler: () => require_edge_index.AutocompleteHandler,
|
|
403
452
|
ButtonHandler: () => require_edge_index.ButtonHandler,
|
|
404
453
|
ComponentHandler: () => require_edge_index.ComponentHandler,
|
|
405
454
|
ContextMenuHandler: () => require_edge_index.ContextMenuHandler,
|
|
455
|
+
CursorSource: () => require_edge_index.CursorSource,
|
|
456
|
+
Emojis: () => require_edge_index.Emojis,
|
|
406
457
|
Gated: () => require_edge_index.Gated,
|
|
407
458
|
InteractionHandler: () => require_edge_index.InteractionHandler,
|
|
408
459
|
ModalHandler: () => require_edge_index.ModalHandler,
|
|
460
|
+
Paginator: () => require_edge_index.Paginator,
|
|
409
461
|
Plugin: () => Plugin,
|
|
410
462
|
RepliableHandler: () => require_edge_index.RepliableHandler,
|
|
411
463
|
Seedcord: () => Seedcord,
|
|
@@ -418,13 +470,17 @@ var src_exports = /* @__PURE__ */ require_edge_index.__exportAll({
|
|
|
418
470
|
});
|
|
419
471
|
|
|
420
472
|
//#endregion
|
|
473
|
+
exports.ArraySource = require_edge_index.ArraySource;
|
|
421
474
|
exports.AutocompleteHandler = require_edge_index.AutocompleteHandler;
|
|
422
475
|
exports.ButtonHandler = require_edge_index.ButtonHandler;
|
|
423
476
|
exports.ComponentHandler = require_edge_index.ComponentHandler;
|
|
424
477
|
exports.ContextMenuHandler = require_edge_index.ContextMenuHandler;
|
|
478
|
+
exports.CursorSource = require_edge_index.CursorSource;
|
|
479
|
+
exports.Emojis = require_edge_index.Emojis;
|
|
425
480
|
exports.Gated = require_edge_index.Gated;
|
|
426
481
|
exports.InteractionHandler = require_edge_index.InteractionHandler;
|
|
427
482
|
exports.ModalHandler = require_edge_index.ModalHandler;
|
|
483
|
+
exports.Paginator = require_edge_index.Paginator;
|
|
428
484
|
exports.Plugin = Plugin;
|
|
429
485
|
exports.RepliableHandler = require_edge_index.RepliableHandler;
|
|
430
486
|
exports.Seedcord = Seedcord;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["Logger","buildRouteMaps","Envapter","HmrModuleHandler","InteractionHandler","AutocompleteHandler","InteractionMetadataKey","InteractionRoutes","SeedcordError","SeedcordErrorCode","Pluggable","SeedcordBrand","packageVersion","REST","Logger","CoordinatedShutdown","CoordinatedStartup","HmrManager","MemoryRateLimiter","Bus","SubscriberLoader","HealthCheck","Envapter","StartupPhase","buildRouteMaps","buildEngine","paint","ShutdownPhase","Routes","CorePlugin"],"sources":["../src/manifest/RouteManifest.ts","../src/node/InteractionDispatcher.ts","../src/node/webBridge.ts","../src/node/Seedcord.ts","../src/plugin.ts","../src/index.ts"],"sourcesContent":["import type { SelectMenuKind, SubscriptionKey } from '@seedcord/core';\nimport type { EventFrequency } from '@seedcord/types';\nimport type { ApplicationCommandType } from 'discord-api-types/v10';\n\n/** The command kinds a manifest row registers, the wire enum's other members have no handler base. */\ntype RegistrableCommandType =\n | ApplicationCommandType.ChatInput\n | ApplicationCommandType.User\n | ApplicationCommandType.Message;\n\n/** One file may export several handlers, so the row states which export it registers. */\nexport interface RouteModule {\n /** The exported binding inside the loaded module. */\n readonly exportName: string;\n /** The source file the row came from, reported when the export is missing. */\n readonly from: string;\n /** Lazy import of the module, evaluated on first hit. */\n readonly load: () => Promise<Record<string, unknown>>;\n}\n\n/**\n * A slash or context-menu command row. `type` picks the per-kind map, `name` is the lookup key. For a\n * chat-input command with subcommands, `name` is the full route path (`'config/set'`), the same key\n * `@SlashRoute` registers.\n */\ninterface CommandRoute extends RouteModule {\n readonly name: string;\n readonly type: RegistrableCommandType;\n}\n\n/**\n * A button, select, or modal row. `kind` picks the per-kind map, `prefix` is the stable customId prefix\n * the receiver routes by (the routeKey minus its layout hash).\n */\nexport interface ComponentRoute extends RouteModule {\n readonly kind: 'button' | `${SelectMenuKind}Select` | 'modal';\n readonly prefix: string;\n}\n\n/**\n * An autocomplete row, its own route keyed by the command's route path, separate from the slash row.\n */\ninterface AutocompleteRoute extends RouteModule {\n readonly name: string;\n}\n\n/**\n * A bus subscriber row. The Bus registers it without importing the subscriber module, and resolves the\n * class on the first publish of one of its keys.\n */\ninterface SubscriberRoute extends RouteModule {\n /** The subscription keys this subscriber registers for. */\n readonly keys: readonly SubscriptionKey[];\n /** Mirrors the `@Subscribe` frequency metadata. */\n readonly frequency: EventFrequency;\n}\n\n/** A middleware row. Middleware runs on every dispatch, so it carries no lookup key. */\ntype MiddlewareRoute = RouteModule;\n\n/**\n * The static route table the HTTP engine dispatches through, replacing the filesystem handler scan that\n * cannot run in a bundled isolate. `seedcord build` emits it, the mount path authors it by hand.\n */\nexport interface RouteManifest {\n readonly commandRoutes: readonly CommandRoute[];\n readonly componentRoutes: readonly ComponentRoute[];\n readonly autocompleteRoutes: readonly AutocompleteRoute[];\n readonly subscriberRoutes: readonly SubscriberRoute[];\n readonly middlewareRoutes: readonly MiddlewareRoute[];\n}\n\n/** @internal */\nexport const EMPTY_MANIFEST: RouteManifest = {\n commandRoutes: [],\n componentRoutes: [],\n autocompleteRoutes: [],\n subscriberRoutes: [],\n middlewareRoutes: []\n};\n","import { HmrModuleHandler } from '@seedcord/core/hmr';\nimport { interactionRoutesOf, InteractionMetadataKey, InteractionRoutes } from '@seedcord/core/internal';\nimport { SeedcordErrorCode } from '@seedcord/errors';\nimport { SeedcordError } from '@seedcord/errors/internal';\nimport { Logger } from '@seedcord/logger';\nimport { formatFilePath } from '@seedcord/utils';\nimport { traverseDirectory } from '@seedcord/utils/node';\nimport { Envapter } from 'envapt';\n\nimport { AutocompleteHandler } from '@handlers/interaction/AutocompleteHandler';\nimport { InteractionHandler } from '@handlers/interaction/InteractionHandler';\nimport { buildRouteMaps } from '@src/dispatch/resolve';\nimport { EMPTY_MANIFEST } from '@src/manifest/RouteManifest';\n\nimport type { HandlerConstructor } from '@handlers/constructors';\nimport type { Initializeable } from '@seedcord/core';\nimport type { HmrAware, HmrUpdateEvent } from '@seedcord/types';\nimport type { ResolvedRoute, RouteMap, RouteMaps } from '@src/dispatch/resolve';\n\ninterface RouteTarget {\n readonly map: RouteMap;\n readonly kind: ResolvedRoute['kind'];\n}\n\n/**\n * Discovers interaction handlers from the filesystem into the engine's live route maps.\n *\n * The node host runs it at startup and dev HMR swaps map entries in place. The engine's `resolve`\n * reads `maps` per request. The edge path builds its maps from the generated manifest.\n */\nexport class InteractionDispatcher implements Initializeable, HmrAware {\n public readonly maps: RouteMaps;\n private readonly targets: Record<InteractionRoutes, RouteTarget>;\n\n /** @internal */\n public readonly logger = new Logger('Interactions', { channel: 'interactions' });\n\n private isInitialized = false;\n private readonly hmrHandler?: HmrModuleHandler<HandlerConstructor, void, string[]>;\n // routeId -> owner row, the duplicate guard and the hmr unregister index\n private readonly rowOwners = new Map<\n string,\n { ctor: HandlerConstructor; target: RouteTarget; key: string; from: string }\n >();\n\n private loading = false;\n private readonly loadedHandlers: { name: string; from: string }[] = [];\n\n constructor(private readonly handlersDir: string) {\n this.maps = buildRouteMaps(EMPTY_MANIFEST);\n this.targets = this.buildTargets();\n\n if (!Envapter.isDevelopment && !Envapter.isTest) return;\n this.hmrHandler = new HmrModuleHandler({\n handlersDir,\n isHandler: this.isHandler.bind(this),\n registerHandler: this.registerHandler.bind(this),\n unregisterHandler: this.unregisterHandler.bind(this),\n getArtifacts: this.getArtifacts.bind(this),\n logger: this.logger\n });\n }\n\n /** @internal */\n public async init(): Promise<void> {\n if (this.isInitialized) return;\n this.isInitialized = true;\n\n this.loading = true;\n this.loadedHandlers.length = 0;\n try {\n await traverseDirectory(this.handlersDir, (fullPath, relativePath, imported) => {\n for (const value of Object.values(imported)) {\n if (!this.isHandler(value)) continue;\n this.registerHandler(value, relativePath);\n this.hmrHandler?.trackHandler(fullPath, value);\n }\n });\n } finally {\n this.loading = false;\n }\n\n this.logger.utils.block('Loaded handlers', [\n ...this.logger.utils.entries(this.loadedHandlers),\n ...this.logger.utils.counts({ routes: this.rowOwners.size })\n ]);\n }\n\n /** @internal */\n public async onHmr(event: HmrUpdateEvent): Promise<void> {\n await this.hmrHandler?.handle(event);\n }\n\n private isHandler(value: unknown): value is HandlerConstructor {\n if (typeof value !== 'function') return false;\n // this package's own family bases. A gateway handler in the same dir stays unregistered\n return (\n (value.prototype instanceof InteractionHandler || value.prototype instanceof AutocompleteHandler) &&\n Reflect.hasMetadata(InteractionMetadataKey, value)\n );\n }\n\n private getArtifacts(ctor: HandlerConstructor): string[] {\n const routeIds: string[] = [];\n for (const [routeId, owner] of this.rowOwners) {\n if (owner.ctor === ctor) routeIds.push(routeId);\n }\n return routeIds;\n }\n\n private targetFor(route: InteractionRoutes): RouteTarget {\n return this.targets[route];\n }\n\n private buildTargets(): Record<InteractionRoutes, RouteTarget> {\n return {\n [InteractionRoutes.Slash]: { map: this.maps.slash, kind: 'slash' },\n [InteractionRoutes.UserContextMenu]: { map: this.maps.userContextMenu, kind: 'userContextMenu' },\n [InteractionRoutes.MessageContextMenu]: { map: this.maps.messageContextMenu, kind: 'messageContextMenu' },\n [InteractionRoutes.Autocomplete]: { map: this.maps.autocomplete, kind: 'autocomplete' },\n [InteractionRoutes.Button]: { map: this.maps.components.button, kind: 'button' },\n [InteractionRoutes.StringMenu]: { map: this.maps.components.stringSelect, kind: 'stringMenu' },\n [InteractionRoutes.UserMenu]: { map: this.maps.components.userSelect, kind: 'userMenu' },\n [InteractionRoutes.RoleMenu]: { map: this.maps.components.roleSelect, kind: 'roleMenu' },\n [InteractionRoutes.ChannelMenu]: { map: this.maps.components.channelSelect, kind: 'channelMenu' },\n [InteractionRoutes.MentionableMenu]: {\n map: this.maps.components.mentionableSelect,\n kind: 'mentionableMenu'\n },\n [InteractionRoutes.Modal]: { map: this.maps.components.modal, kind: 'modal' }\n };\n }\n\n private registerHandler(ctor: HandlerConstructor, relativePath: string): void {\n const from = formatFilePath(relativePath);\n // a partial registration would orphan routes and break hmr rollback\n const writes: [RouteTarget, string][] = [];\n\n for (const [route, keys] of interactionRoutesOf(ctor)) {\n const target = this.targetFor(route);\n for (const key of keys) {\n const routeId = `${target.kind}:${key}`;\n const existing = this.rowOwners.get(routeId);\n // a different class on the same route would silently shadow (last write wins), so this throws\n if (existing && existing.ctor !== ctor) {\n throw new SeedcordError(SeedcordErrorCode.InteractionDuplicateRoute, [\n routeId,\n `${existing.ctor.name} (${existing.from})`,\n `${ctor.name} (${from})`\n ]);\n }\n writes.push([target, key]);\n }\n }\n\n if (writes.length === 0) return;\n for (const [target, key] of writes) {\n const routeId = `${target.kind}:${key}`;\n target.map.set(key, { kind: target.kind, routeId, load: () => Promise.resolve(ctor) });\n this.rowOwners.set(routeId, { ctor, target, key, from });\n }\n\n if (this.loading) this.loadedHandlers.push({ name: ctor.name, from });\n else this.logger.utils.registration(ctor.name, from);\n }\n\n private unregisterHandler(ctor: HandlerConstructor, artifacts?: string[]): void {\n const routeIds = artifacts ?? this.getArtifacts(ctor);\n for (const routeId of routeIds) {\n const owner = this.rowOwners.get(routeId);\n if (owner?.ctor !== ctor) continue;\n this.rowOwners.delete(routeId);\n owner.target.map.delete(owner.key);\n }\n }\n}\n","import type { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'node:http';\n\nfunction toHeaders(raw: IncomingHttpHeaders): Headers {\n const headers = new Headers();\n for (const [name, value] of Object.entries(raw)) {\n if (value === undefined) continue;\n if (Array.isArray(value)) {\n for (const item of value) headers.append(name, item);\n } else {\n headers.set(name, value);\n }\n }\n return headers;\n}\n\n// buffers the raw body before any parse so ed25519 verifies the exact signed bytes\nexport async function toWebRequest(request: IncomingMessage): Promise<Request> {\n const chunks: Buffer[] = [];\n // justified: the async iterator is typed any and IncomingMessage yields Buffer chunks\n for await (const chunk of request) chunks.push(chunk as Buffer);\n\n const method = request.method ?? 'GET';\n const body = method === 'GET' || method === 'HEAD' ? undefined : new Uint8Array(Buffer.concat(chunks));\n\n return new Request(`http://${request.headers.host ?? 'localhost'}${request.url ?? '/'}`, {\n method,\n headers: toHeaders(request.headers),\n ...(body !== undefined && { body })\n });\n}\n\nexport async function writeWebResponse(response: Response, out: ServerResponse): Promise<void> {\n const headers: Record<string, string | string[]> = Object.fromEntries(response.headers);\n // iterating Headers comma-joins same-name values, which corrupts Set-Cookie (a per-cookie header)\n const cookies = response.headers.getSetCookie();\n if (cookies.length > 0) headers['set-cookie'] = cookies;\n\n out.writeHead(response.status, headers);\n out.end(response.body === null ? undefined : Buffer.from(await response.arrayBuffer()));\n}\n","import { once } from 'node:events';\nimport { createServer } from 'node:http';\n\nimport { REST } from '@discordjs/rest';\nimport { Bus } from '@seedcord/core';\nimport { HmrManager, setBotColor } from '@seedcord/core/internal';\nimport {\n CoordinatedShutdown,\n CoordinatedStartup,\n HealthCheck,\n Pluggable,\n ShutdownPhase,\n StartupPhase,\n SubscriberLoader\n} from '@seedcord/core/node/internal';\nimport { validateDiscordToken } from '@seedcord/errors/internal';\nimport { Logger, LoggerChannelRegistry, paint } from '@seedcord/logger';\nimport { installNodeDefaults } from '@seedcord/logger/node';\nimport { MemoryRateLimiter } from '@seedcord/rate-limiter';\nimport { SeedcordBrand } from '@seedcord/types/internal';\nimport { Routes } from 'discord-api-types/v10';\nimport { Envapter } from 'envapt';\n\nimport { buildRouteMaps } from '@src/dispatch/resolve';\nimport { buildEngine } from '@src/engine';\nimport { EMPTY_MANIFEST } from '@src/manifest/RouteManifest';\n\nimport { InteractionDispatcher } from './InteractionDispatcher';\nimport { toWebRequest, writeWebResponse } from './webBridge';\nimport { version as packageVersion } from '../version';\n\nimport type { HttpConfig } from '@interfaces/Config';\nimport type { Core } from '@interfaces/Core';\nimport type { PluginCapabilities } from '@seedcord/core/node/internal';\nimport type { IRateLimiter } from '@seedcord/types';\nimport type { SeedcordInstance } from '@seedcord/types/internal';\nimport type { Server } from 'node:http';\nimport type { AddressInfo } from 'node:net';\n\nconst DEFAULT_PORT = 3000;\nconst SERVER_SHUTDOWN_TIMEOUT_MS = 5000;\nconst DRAIN_TIMEOUT_MS = 10_000;\n\ntype RuntimeOfConfig<Cfg extends HttpConfig> = Cfg extends { runtime: 'edge' } ? 'edge' : 'server';\n\n/**\n * The HTTP-interactions bot host, a long-running node server around the engine.\n *\n * Discovers handlers from `config.bot.interactions.path`, verifies and dispatches interactions on\n * `start(port)`, and runs coordinated shutdown with an in-flight drain. The edge deploy path calls\n * `createSeedcord` from a generated entry.\n */\nexport class Seedcord<Cfg extends HttpConfig = HttpConfig>\n extends Pluggable<'http', RuntimeOfConfig<Cfg>>\n implements Core, SeedcordInstance\n{\n // the CLI reads these to detect and augment the instance\n /** @internal */\n public readonly [SeedcordBrand] = true;\n /** @internal */\n public readonly augmentTarget = '@seedcord/http';\n /** @internal */\n public readonly version: string = packageVersion;\n\n /** Workerd-compatible Discord REST client. `start()` sets the token. */\n public readonly rest = new REST();\n\n /** @see {@link IRateLimiter} */\n public readonly rateLimiter: IRateLimiter;\n\n /** @see {@link Bus} */\n public readonly bus: Bus;\n\n private readonly subscribers: SubscriberLoader;\n\n private readonly interactions?: InteractionDispatcher;\n private readonly healthCheck?: HealthCheck | undefined;\n private readonly hmrManager: HmrManager;\n private readonly logger = new Logger('Server', { channel: 'bot' });\n\n private server?: Server;\n private boundPort?: number;\n private requestedPort = DEFAULT_PORT;\n private fetchedUsername?: string | undefined;\n\n constructor(public readonly config: Cfg) {\n super(new CoordinatedShutdown(), new CoordinatedStartup());\n\n installNodeDefaults(config.logger);\n setBotColor(config.botColor);\n\n this.hmrManager = new HmrManager();\n this.hmrManager.init();\n\n if (this.config.bot.interactions.path) {\n this.interactions = new InteractionDispatcher(this.config.bot.interactions.path);\n }\n\n this.rateLimiter = config.store ?? new MemoryRateLimiter();\n this.bus = new Bus(this);\n this.subscribers = new SubscriberLoader(this.bus, config.subscribers.path);\n // the edge arm types healthCheck never, and a dev run of an edge config needs no health server\n this.healthCheck =\n config.runtime === 'edge' ? undefined : HealthCheck.fromOption(this.shutdown, config.healthCheck);\n\n this.registerStartupTasks();\n }\n\n /** The bot's discord username, populated by the ready fetch. */\n public get username(): string | undefined {\n return this.fetchedUsername;\n }\n\n /** The bound server port, populated once `start()` is listening. */\n public get port(): number | undefined {\n return this.boundPort;\n }\n\n protected override pluginCapabilities(): PluginCapabilities {\n const token = Envapter.get('DISCORD_BOT_TOKEN');\n return { rest: this.rest, ...(token !== undefined && { token }) };\n }\n\n /**\n * Starts the host and runs the startup tasks.\n *\n * @param port - The port the interaction server binds. {@default `3000` }\n */\n public async start(port = DEFAULT_PORT): Promise<this> {\n this.requestedPort = port;\n try {\n await super.init();\n } catch (caught) {\n // shutdown releases any resource opened before the failure, then rethrow\n await this.shutdown.run(1, false);\n Seedcord.reset();\n throw caught;\n }\n return this;\n }\n\n protected static override reset(): void {\n super.reset();\n LoggerChannelRegistry.instance.reset();\n }\n\n private registerStartupTasks(): void {\n if (Envapter.isDevelopment || Envapter.isTest) this.registerHmrAwareModules();\n\n this.startup.addTask(StartupPhase.Configuration, 'bus-initialization', async () => {\n this.bus.logger.utils.initialization('Subscribers', 'start');\n await this.subscribers.init();\n this.bus.logger.utils.initialization('Subscribers', 'end');\n });\n\n const { interactions } = this;\n if (interactions) {\n this.startup.addTask(StartupPhase.Configuration, 'interactions-initialization', async () => {\n interactions.logger.utils.initialization('Interactions', 'start');\n await interactions.init();\n interactions.logger.utils.initialization('Interactions', 'end');\n });\n }\n\n this.startup.addTask(StartupPhase.Ready, 'http-server', () => this.listen());\n\n if (!Envapter.isTest) {\n this.startup.addTask(StartupPhase.Ready, 'identity', () => this.fetchUsername());\n }\n\n const { healthCheck } = this;\n if (healthCheck) {\n this.startup.addTask(StartupPhase.Ready, 'health-check', async () => {\n healthCheck.logger.utils.initialization('HealthCheck', 'start');\n await healthCheck.init();\n healthCheck.logger.utils.initialization('HealthCheck', 'end');\n });\n }\n }\n\n private registerHmrAwareModules(): void {\n this.startup.addTask(StartupPhase.Configuration, 'hmr-registration', async () => {\n if (this.interactions) this.hmrManager.register(this.interactions);\n this.hmrManager.register(this.subscribers);\n for (const plugin of this.plugins) {\n this.hmrManager.register(plugin);\n }\n await Promise.resolve();\n });\n }\n\n private async listen(): Promise<void> {\n const token = validateDiscordToken(Envapter.get('DISCORD_BOT_TOKEN'));\n this.rest.setToken(token);\n\n const maps = this.interactions?.maps ?? buildRouteMaps(EMPTY_MANIFEST);\n const { handle, inFlight } = buildEngine(this, maps);\n\n const server = createServer((incoming, outgoing) => {\n void (async () => {\n const response = await handle(await toWebRequest(incoming));\n await writeWebResponse(response, outgoing);\n })().catch((error: unknown) => {\n // a swallowed throw would hang the client request with no cause\n outgoing.destroy(Error.isError(error) ? error : new Error(String(error)));\n });\n });\n this.server = server;\n\n server.listen(this.requestedPort);\n await once(server, 'listening');\n // justified: address() is AddressInfo once a TCP server is listening\n this.boundPort = (server.address() as AddressInfo).port;\n this.logger.info(`Interactions server listening on port ${paint.sky.bold(String(this.boundPort))}`);\n\n this.shutdown.addTask(\n ShutdownPhase.Unbind,\n 'stop-http-server',\n () => this.stopServer(),\n SERVER_SHUTDOWN_TIMEOUT_MS\n );\n // Unbind already ran, so every accepted request is in the in-flight set here\n this.shutdown.addTask(\n ShutdownPhase.Drain,\n 'drain-inflight',\n async () => {\n await Promise.allSettled(inFlight);\n },\n DRAIN_TIMEOUT_MS\n );\n }\n\n private async fetchUsername(): Promise<void> {\n try {\n // justified: the @me payload carries username per the discord api contract\n const me = (await this.rest.get(Routes.user('@me'))) as { username?: string };\n this.fetchedUsername = me.username;\n } catch (caught) {\n // a bad token errors on the first real send. The identity fetch stays non-fatal\n this.logger.warn('could not fetch the bot identity', caught);\n }\n }\n\n private stopServer(): Promise<void> {\n const server = this.server;\n if (!server?.listening) return Promise.resolve();\n\n return new Promise((resolveClose, rejectClose) => {\n server.close((err) => {\n if (err) {\n rejectClose(err);\n return;\n }\n this.logger.info(paint.coral.bold('Interactions server stopped'));\n resolveClose();\n });\n // idle keep-alive sockets would stall close() past the task timeout. Active responses\n // still flush, and the task timeout bounds a hung one\n server.closeIdleConnections();\n });\n }\n}\n","import { Plugin as CorePlugin } from '@seedcord/core/plugin';\n\nimport type { Core } from '@interfaces/Core';\nimport type { PluginOptions } from '@seedcord/core/plugin';\nimport type { TypedOmit } from '@seedcord/types';\n\n/** The options an HTTP plugin declares, narrowed to the transports this base serves. */\nexport type HttpPluginOptions = TypedOmit<PluginOptions, 'transport'> & { transport?: 'http' | 'any' };\n\n/**\n * Base class for an HTTP plugin, binding `this.core` to the HTTP {@link Core}.\n *\n * A plugin that runs on either transport extends the base from `@seedcord/core/plugin`, whose\n * `this.core` carries the shared members only.\n *\n * @typeParam Opts - The transport, runtime, and capabilities the plugin declares.\n */\nexport abstract class Plugin<Opts extends HttpPluginOptions = {}> extends CorePlugin<Opts, Core> {}\n\nexport type { PluginContext, PluginLifecycleSpec, PluginOptions } from '@seedcord/core/plugin';\n","export * from './edge.index';\nexport { Seedcord } from '@src/node/Seedcord';\n\n// the plugin authoring surface with http's Core bound to it\nexport { Plugin } from './plugin';\nexport type { HttpPluginOptions, PluginContext, PluginLifecycleSpec, PluginOptions } from './plugin';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAyEA,MAAa,iBAAgC;CACzC,eAAe,CAAC;CAChB,iBAAiB,CAAC;CAClB,oBAAoB,CAAC;CACrB,kBAAkB,CAAC;CACnB,kBAAkB,CAAC;AACvB;;;;;;;;;;ACjDA,IAAa,wBAAb,MAAuE;CAkBtC;CAjB7B,AAAgB;CAChB,AAAiB;;CAGjB,AAAgB,SAAS,IAAIA,wBAAO,gBAAgB,EAAE,SAAS,eAAe,CAAC;CAE/E,AAAQ,gBAAgB;CACxB,AAAiB;CAEjB,AAAiB,4BAAY,IAAI,IAG/B;CAEF,AAAQ,UAAU;CAClB,AAAiB,iBAAmD,CAAC;CAErE,YAAY,AAAiB,aAAqB;EAArB;EACzB,KAAK,OAAOC,kCAAe,cAAc;EACzC,KAAK,UAAU,KAAK,aAAa;EAEjC,IAAI,CAACC,gBAAS,iBAAiB,CAACA,gBAAS,QAAQ;EACjD,KAAK,aAAa,IAAIC,oCAAiB;GACnC;GACA,WAAW,KAAK,UAAU,KAAK,IAAI;GACnC,iBAAiB,KAAK,gBAAgB,KAAK,IAAI;GAC/C,mBAAmB,KAAK,kBAAkB,KAAK,IAAI;GACnD,cAAc,KAAK,aAAa,KAAK,IAAI;GACzC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QACVC,2CAAc,QACd,0BACM,KAAK,WAAW,GACtB,0BACJ;EAEA,KAAK,SAAS,QACVA,2CAAc,OACd,kBACA,YAAY;GACR,MAAM,QAAQ,WAAW,QAAQ;EACrC,GACA,gBACJ;CACJ;CAEA,MAAc,gBAA+B;EACzC,IAAI;GAEA,MAAM,KAAM,MAAM,KAAK,KAAK,IAAIC,6BAAO,KAAK,KAAK,CAAC;GAClD,KAAK,kBAAkB,GAAG;EAC9B,SAAS,QAAQ;GAEb,KAAK,OAAO,KAAK,oCAAoC,MAAM;EAC/D;CACJ;CAEA,AAAQ,aAA4B;EAChC,MAAM,SAAS,KAAK;EACpB,IAAI,CAAC,QAAQ,WAAW,OAAO,QAAQ,QAAQ;EAE/C,OAAO,IAAI,SAAS,cAAc,gBAAgB;GAC9C,OAAO,OAAO,QAAQ;IAClB,IAAI,KAAK;KACL,YAAY,GAAG;KACf;IACJ;IACA,KAAK,OAAO,KAAKF,uBAAM,MAAM,KAAK,6BAA6B,CAAC;IAChE,aAAa;GACjB,CAAC;GAGD,OAAO,qBAAqB;EAChC,CAAC;CACL;AACJ;;;;;;;;;;;;ACpPA,IAAsB,SAAtB,cAA0EG,6BAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["Logger","buildRouteMaps","Envapter","HmrModuleHandler","paint","InteractionHandler","AutocompleteHandler","InteractionMetadataKey","InteractionRoutes","SeedcordError","SeedcordErrorCode","Pluggable","SeedcordBrand","packageVersion","REST","EmojiInjector","Logger","CoordinatedShutdown","CoordinatedStartup","HmrManager","CommandInjector","CommandRegistry","MemoryRateLimiter","Bus","SubscriberLoader","HealthCheck","Envapter","StartupPhase","fetchApplicationId","SeedcordError","SeedcordErrorCode","buildRouteMaps","buildEngine","paint","ShutdownPhase","Routes","CorePlugin"],"sources":["../src/manifest/RouteManifest.ts","../src/node/InteractionDispatcher.ts","../src/node/webBridge.ts","../src/node/Seedcord.ts","../src/plugin.ts","../src/index.ts"],"sourcesContent":["import type { SelectMenuKind, SubscriptionKey } from '@seedcord/core';\nimport type { EventFrequency } from '@seedcord/types';\nimport type { ApplicationCommandType } from 'discord-api-types/v10';\n\n/** The command kinds a manifest row registers, the wire enum's other members have no handler base. */\ntype RegistrableCommandType =\n | ApplicationCommandType.ChatInput\n | ApplicationCommandType.User\n | ApplicationCommandType.Message;\n\n/** One file may export several handlers, so the row states which export it registers. */\nexport interface RouteModule {\n /** The exported binding inside the loaded module. */\n readonly exportName: string;\n /** The source file the row came from, reported when the export is missing. */\n readonly from: string;\n /** Lazy import of the module, evaluated on first hit. */\n readonly load: () => Promise<Record<string, unknown>>;\n}\n\n/**\n * A slash or context-menu command row. `type` picks the per-kind map, `name` is the lookup key. For a\n * chat-input command with subcommands, `name` is the full route path (`'config/set'`), the same key\n * `@SlashRoute` registers.\n */\ninterface CommandRoute extends RouteModule {\n readonly name: string;\n readonly type: RegistrableCommandType;\n}\n\n/**\n * A button, select, or modal row. `kind` picks the per-kind map, `prefix` is the stable customId prefix\n * the receiver routes by (the routeKey minus its layout hash).\n */\nexport interface ComponentRoute extends RouteModule {\n readonly kind: 'button' | `${SelectMenuKind}Select` | 'modal';\n readonly prefix: string;\n}\n\n/**\n * An autocomplete row, its own route keyed by the command's route path, separate from the slash row.\n */\ninterface AutocompleteRoute extends RouteModule {\n readonly name: string;\n}\n\n/**\n * A bus subscriber row. The Bus registers it without importing the subscriber module, and resolves the\n * class on the first publish of one of its keys.\n */\ninterface SubscriberRoute extends RouteModule {\n /** The subscription keys this subscriber registers for. */\n readonly keys: readonly SubscriptionKey[];\n /** Mirrors the `@Subscribe` frequency metadata. */\n readonly frequency: EventFrequency;\n}\n\n/** A middleware row. Middleware runs on every dispatch, so it carries no lookup key. */\ntype MiddlewareRoute = RouteModule;\n\n/**\n * The static route table the HTTP engine dispatches through, replacing the filesystem handler scan that\n * cannot run in a bundled isolate. `seedcord build` emits it, the mount path authors it by hand.\n */\nexport interface RouteManifest {\n readonly commandRoutes: readonly CommandRoute[];\n readonly componentRoutes: readonly ComponentRoute[];\n readonly autocompleteRoutes: readonly AutocompleteRoute[];\n readonly subscriberRoutes: readonly SubscriberRoute[];\n readonly middlewareRoutes: readonly MiddlewareRoute[];\n}\n\n/** @internal */\nexport const EMPTY_MANIFEST: RouteManifest = {\n commandRoutes: [],\n componentRoutes: [],\n autocompleteRoutes: [],\n subscriberRoutes: [],\n middlewareRoutes: []\n};\n","import { HmrModuleHandler } from '@seedcord/core/hmr';\nimport { interactionRoutesOf, InteractionMetadataKey, InteractionRoutes } from '@seedcord/core/internal';\nimport { SeedcordErrorCode } from '@seedcord/errors';\nimport { SeedcordError } from '@seedcord/errors/internal';\nimport { Logger, paint } from '@seedcord/logger';\nimport { formatFilePath } from '@seedcord/utils';\nimport { traverseDirectory } from '@seedcord/utils/node';\nimport chalk from 'chalk';\nimport { Envapter } from 'envapt';\n\nimport { AutocompleteHandler } from '@handlers/interaction/AutocompleteHandler';\nimport { InteractionHandler } from '@handlers/interaction/InteractionHandler';\nimport { buildRouteMaps } from '@src/dispatch/resolve';\nimport { EMPTY_MANIFEST } from '@src/manifest/RouteManifest';\n\nimport type { HandlerConstructor } from '@handlers/constructors';\nimport type { Initializeable } from '@seedcord/core';\nimport type { ContextMenuLeaves } from '@seedcord/core/internal';\nimport type { HmrAware, HmrUpdateEvent } from '@seedcord/types';\nimport type { ResolvedRoute, RouteMap, RouteMaps } from '@src/dispatch/resolve';\n\ninterface RouteTarget {\n readonly map: RouteMap;\n readonly kind: ResolvedRoute['kind'];\n}\n\n/**\n * Discovers interaction handlers from the filesystem into the engine's live route maps.\n *\n * The node host runs it at startup and dev HMR swaps map entries in place. The engine's `resolve`\n * reads `maps` per request. The edge path builds its maps from the generated manifest.\n */\nexport class InteractionDispatcher implements Initializeable, HmrAware {\n public readonly maps: RouteMaps;\n private readonly targets: Record<InteractionRoutes, RouteTarget>;\n\n /** @internal */\n public readonly logger = new Logger('Interactions', { channel: 'interactions' });\n\n private isInitialized = false;\n private readonly hmrHandler?: HmrModuleHandler<HandlerConstructor, void, string[]>;\n // routeId -> owner row, the duplicate guard and the hmr unregister index\n private readonly rowOwners = new Map<\n string,\n { ctor: HandlerConstructor; target: RouteTarget; key: string; from: string }\n >();\n\n private loading = false;\n private readonly loadedHandlers: { name: string; from: string }[] = [];\n\n constructor(private readonly handlersDir: string) {\n this.maps = buildRouteMaps(EMPTY_MANIFEST);\n this.targets = this.buildTargets();\n\n if (!Envapter.isDevelopment && !Envapter.isTest) return;\n this.hmrHandler = new HmrModuleHandler({\n handlersDir,\n isHandler: this.isHandler.bind(this),\n registerHandler: this.registerHandler.bind(this),\n unregisterHandler: this.unregisterHandler.bind(this),\n getArtifacts: this.getArtifacts.bind(this),\n logger: this.logger\n });\n }\n\n /** @internal */\n public async init(): Promise<void> {\n if (this.isInitialized) return;\n this.isInitialized = true;\n\n this.loading = true;\n this.loadedHandlers.length = 0;\n try {\n await traverseDirectory(this.handlersDir, (fullPath, relativePath, imported) => {\n for (const value of Object.values(imported)) {\n if (!this.isHandler(value)) continue;\n this.registerHandler(value, relativePath);\n this.hmrHandler?.trackHandler(fullPath, value);\n }\n });\n } finally {\n this.loading = false;\n }\n\n this.logger.utils.block('Loaded handlers', [\n ...this.logger.utils.entries(this.loadedHandlers),\n ...this.logger.utils.counts({ routes: this.rowOwners.size })\n ]);\n }\n\n /** @internal */\n public async onHmr(event: HmrUpdateEvent): Promise<void> {\n await this.hmrHandler?.handle(event);\n }\n\n public warnUnhandledRoutes(commandLeaves: Iterable<string>): void {\n this.warnMissing(commandLeaves, this.maps.slash, 'Slash route', '@SlashRoute');\n }\n\n public warnUnhandledContextMenuRoutes(leaves: ContextMenuLeaves): void {\n this.warnMissing(leaves.user, this.maps.userContextMenu, 'User context menu', '@ContextMenuRoute');\n this.warnMissing(leaves.message, this.maps.messageContextMenu, 'Message context menu', '@ContextMenuRoute');\n }\n\n private warnMissing(names: Iterable<string>, map: RouteMap, label: string, decorator: string): void {\n for (const name of names) {\n if (map.has(name)) continue;\n this.logger.warn(`${label} ${paint.sky.bold(name)} has no registered ${chalk.bold(decorator)} handler.`);\n }\n }\n\n private isHandler(value: unknown): value is HandlerConstructor {\n if (typeof value !== 'function') return false;\n // this package's own family bases. A gateway handler in the same dir stays unregistered\n return (\n (value.prototype instanceof InteractionHandler || value.prototype instanceof AutocompleteHandler) &&\n Reflect.hasMetadata(InteractionMetadataKey, value)\n );\n }\n\n private getArtifacts(ctor: HandlerConstructor): string[] {\n const routeIds: string[] = [];\n for (const [routeId, owner] of this.rowOwners) {\n if (owner.ctor === ctor) routeIds.push(routeId);\n }\n return routeIds;\n }\n\n private targetFor(route: InteractionRoutes): RouteTarget {\n return this.targets[route];\n }\n\n private buildTargets(): Record<InteractionRoutes, RouteTarget> {\n return {\n [InteractionRoutes.Slash]: { map: this.maps.slash, kind: 'slash' },\n [InteractionRoutes.UserContextMenu]: { map: this.maps.userContextMenu, kind: 'userContextMenu' },\n [InteractionRoutes.MessageContextMenu]: { map: this.maps.messageContextMenu, kind: 'messageContextMenu' },\n [InteractionRoutes.Autocomplete]: { map: this.maps.autocomplete, kind: 'autocomplete' },\n [InteractionRoutes.Button]: { map: this.maps.components.button, kind: 'button' },\n [InteractionRoutes.StringMenu]: { map: this.maps.components.stringSelect, kind: 'stringMenu' },\n [InteractionRoutes.UserMenu]: { map: this.maps.components.userSelect, kind: 'userMenu' },\n [InteractionRoutes.RoleMenu]: { map: this.maps.components.roleSelect, kind: 'roleMenu' },\n [InteractionRoutes.ChannelMenu]: { map: this.maps.components.channelSelect, kind: 'channelMenu' },\n [InteractionRoutes.MentionableMenu]: {\n map: this.maps.components.mentionableSelect,\n kind: 'mentionableMenu'\n },\n [InteractionRoutes.Modal]: { map: this.maps.components.modal, kind: 'modal' }\n };\n }\n\n private registerHandler(ctor: HandlerConstructor, relativePath: string): void {\n const from = formatFilePath(relativePath);\n // a partial registration would orphan routes and break hmr rollback\n const writes: [RouteTarget, string][] = [];\n\n for (const [route, keys] of interactionRoutesOf(ctor)) {\n const target = this.targetFor(route);\n for (const key of keys) {\n const routeId = `${target.kind}:${key}`;\n const existing = this.rowOwners.get(routeId);\n // a different class on the same route would silently shadow (last write wins), so this throws\n if (existing && existing.ctor !== ctor) {\n throw new SeedcordError(SeedcordErrorCode.InteractionDuplicateRoute, [\n routeId,\n `${existing.ctor.name} (${existing.from})`,\n `${ctor.name} (${from})`\n ]);\n }\n writes.push([target, key]);\n }\n }\n\n if (writes.length === 0) return;\n for (const [target, key] of writes) {\n const routeId = `${target.kind}:${key}`;\n target.map.set(key, { kind: target.kind, routeId, load: () => Promise.resolve(ctor) });\n this.rowOwners.set(routeId, { ctor, target, key, from });\n }\n\n if (this.loading) this.loadedHandlers.push({ name: ctor.name, from });\n else this.logger.utils.registration(ctor.name, from);\n }\n\n private unregisterHandler(ctor: HandlerConstructor, artifacts?: string[]): void {\n const routeIds = artifacts ?? this.getArtifacts(ctor);\n for (const routeId of routeIds) {\n const owner = this.rowOwners.get(routeId);\n if (owner?.ctor !== ctor) continue;\n this.rowOwners.delete(routeId);\n owner.target.map.delete(owner.key);\n }\n }\n}\n","import type { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'node:http';\n\nfunction toHeaders(raw: IncomingHttpHeaders): Headers {\n const headers = new Headers();\n for (const [name, value] of Object.entries(raw)) {\n if (value === undefined) continue;\n if (Array.isArray(value)) {\n for (const item of value) headers.append(name, item);\n } else {\n headers.set(name, value);\n }\n }\n return headers;\n}\n\n// buffers the raw body before any parse so ed25519 verifies the exact signed bytes\nexport async function toWebRequest(request: IncomingMessage): Promise<Request> {\n const chunks: Buffer[] = [];\n // justified: the async iterator is typed any and IncomingMessage yields Buffer chunks\n for await (const chunk of request) chunks.push(chunk as Buffer);\n\n const method = request.method ?? 'GET';\n const body = method === 'GET' || method === 'HEAD' ? undefined : new Uint8Array(Buffer.concat(chunks));\n\n return new Request(`http://${request.headers.host ?? 'localhost'}${request.url ?? '/'}`, {\n method,\n headers: toHeaders(request.headers),\n ...(body !== undefined && { body })\n });\n}\n\nexport async function writeWebResponse(response: Response, out: ServerResponse): Promise<void> {\n const headers: Record<string, string | string[]> = Object.fromEntries(response.headers);\n // iterating Headers comma-joins same-name values, which corrupts Set-Cookie (a per-cookie header)\n const cookies = response.headers.getSetCookie();\n if (cookies.length > 0) headers['set-cookie'] = cookies;\n\n out.writeHead(response.status, headers);\n out.end(response.body === null ? undefined : Buffer.from(await response.arrayBuffer()));\n}\n","import { once } from 'node:events';\nimport { createServer } from 'node:http';\n\nimport { REST } from '@discordjs/rest';\nimport { Bus } from '@seedcord/core';\nimport { CommandInjector, HmrManager, setBotColor } from '@seedcord/core/internal';\nimport {\n CommandRegistry,\n CoordinatedShutdown,\n CoordinatedStartup,\n HealthCheck,\n Pluggable,\n ShutdownPhase,\n StartupPhase,\n SubscriberLoader\n} from '@seedcord/core/node/internal';\nimport { SeedcordErrorCode } from '@seedcord/errors';\nimport { SeedcordError, validateDiscordToken } from '@seedcord/errors/internal';\nimport { Logger, LoggerChannelRegistry, paint } from '@seedcord/logger';\nimport { installNodeDefaults } from '@seedcord/logger/node';\nimport { MemoryRateLimiter } from '@seedcord/rate-limiter';\nimport { SeedcordBrand } from '@seedcord/types/internal';\nimport { Routes } from 'discord-api-types/v10';\nimport { Envapter } from 'envapt';\n\nimport { fetchApplicationId } from '@src/applicationId';\nimport { buildRouteMaps } from '@src/dispatch/resolve';\nimport { EmojiInjector } from '@src/emojis/EmojiInjector';\nimport { buildEngine } from '@src/engine';\nimport { EMPTY_MANIFEST } from '@src/manifest/RouteManifest';\n\nimport { InteractionDispatcher } from './InteractionDispatcher';\nimport { toWebRequest, writeWebResponse } from './webBridge';\nimport { version as packageVersion } from '../version';\n\nimport type { HttpConfig } from '@interfaces/Config';\nimport type { Core } from '@interfaces/Core';\nimport type { IRateLimiter } from '@seedcord/types';\nimport type { SeedcordInstance } from '@seedcord/types/internal';\nimport type { Server } from 'node:http';\nimport type { AddressInfo } from 'node:net';\n\nconst DEFAULT_PORT = 3000;\nconst SERVER_SHUTDOWN_TIMEOUT_MS = 5000;\nconst DRAIN_TIMEOUT_MS = 10_000;\n\ntype RuntimeOfConfig<Cfg extends HttpConfig> = Cfg extends { runtime: 'edge' } ? 'edge' : 'server';\n\n/**\n * The HTTP-interactions bot host, a long-running node server around the engine.\n *\n * Discovers handlers from `config.bot.interactions.path`, verifies and dispatches interactions on\n * `start(port)`, and runs coordinated shutdown with an in-flight drain. The edge deploy path calls\n * `createSeedcord` from a generated entry.\n */\nexport class Seedcord<Cfg extends HttpConfig = HttpConfig>\n extends Pluggable<'http', RuntimeOfConfig<Cfg>>\n implements Core, SeedcordInstance\n{\n // the CLI reads these to detect and augment the instance\n /** @internal */\n public readonly [SeedcordBrand] = true;\n /** @internal */\n public readonly augmentTarget = '@seedcord/http';\n /** @internal */\n public readonly version: string = packageVersion;\n\n /** Workerd-compatible Discord REST client. `start()` sets the token. */\n public readonly rest = new REST();\n\n /** @see {@link IRateLimiter} */\n public readonly rateLimiter: IRateLimiter;\n\n /** @see {@link Bus} */\n public readonly bus: Bus;\n\n private readonly subscribers: SubscriberLoader;\n\n private readonly interactions?: InteractionDispatcher;\n private readonly commandRegistry?: CommandRegistry;\n private appId?: string;\n private appIdPromise?: Promise<string>;\n private readonly emojiInjector = new EmojiInjector(this, () => this.applicationId());\n private readonly healthCheck?: HealthCheck | undefined;\n private readonly hmrManager: HmrManager;\n private readonly logger = new Logger('Server', { channel: 'bot' });\n\n private server?: Server;\n private boundPort?: number;\n private requestedPort = DEFAULT_PORT;\n private fetchedUsername?: string | undefined;\n\n constructor(public readonly config: Cfg) {\n super(new CoordinatedShutdown(), new CoordinatedStartup());\n\n installNodeDefaults(config.logger);\n setBotColor(config.botColor);\n\n this.hmrManager = new HmrManager();\n this.hmrManager.init();\n\n if (this.config.bot.interactions.path) {\n this.interactions = new InteractionDispatcher(this.config.bot.interactions.path);\n }\n\n const commandsDir = this.config.bot.commands.path;\n if (commandsDir) {\n const injector = new CommandInjector();\n // onDeployed only fires at deploy time, so registry is assigned by then\n const registry: CommandRegistry = new CommandRegistry({\n dir: commandsDir,\n rest: this.rest,\n applicationId: () => this.requireApplicationId(),\n onDeployed: (result) => {\n injector.inject(result, registry.allCommands());\n }\n });\n this.commandRegistry = registry;\n }\n\n this.rateLimiter = config.store ?? new MemoryRateLimiter();\n this.bus = new Bus(this);\n this.subscribers = new SubscriberLoader(this.bus, config.subscribers.path);\n // the edge arm types healthCheck never, and a dev run of an edge config needs no health server\n this.healthCheck =\n config.runtime === 'edge' ? undefined : HealthCheck.fromOption(this.shutdown, config.healthCheck);\n\n this.registerStartupTasks();\n }\n\n /** The bot's discord username, populated by the ready fetch. */\n public get username(): string | undefined {\n return this.fetchedUsername;\n }\n\n /** The bound server port, populated once `start()` is listening. */\n public get port(): number | undefined {\n return this.boundPort;\n }\n\n /**\n * Starts the host and runs the startup tasks.\n *\n * @param port - The port the interaction server binds. {@default `3000` }\n */\n public async start(port = DEFAULT_PORT): Promise<this> {\n this.requestedPort = port;\n try {\n await super.init();\n } catch (caught) {\n // shutdown releases any resource opened before the failure, then rethrow\n await this.shutdown.run(1, false);\n Seedcord.reset();\n throw caught;\n }\n return this;\n }\n\n protected static override reset(): void {\n super.reset();\n LoggerChannelRegistry.instance.reset();\n }\n\n private registerStartupTasks(): void {\n if (Envapter.isDevelopment || Envapter.isTest) this.registerHmrAwareModules();\n\n this.startup.addTask(StartupPhase.Configuration, 'bus-initialization', async () => {\n this.bus.logger.utils.initialization('Subscribers', 'start');\n await this.subscribers.init();\n this.bus.logger.utils.initialization('Subscribers', 'end');\n });\n\n const { interactions } = this;\n if (interactions) {\n this.startup.addTask(StartupPhase.Configuration, 'interactions-initialization', async () => {\n interactions.logger.utils.initialization('Interactions', 'start');\n await interactions.init();\n interactions.logger.utils.initialization('Interactions', 'end');\n });\n }\n\n this.startup.addTask(StartupPhase.Configuration, 'authenticate', () => {\n this.authenticate();\n return Promise.resolve();\n });\n\n // needs the token from Configuration, and must finish before Ready opens the server to interactions\n this.startup.addTask(StartupPhase.Login, 'emoji-injection', () => this.emojiInjector.init());\n\n const { commandRegistry } = this;\n if (commandRegistry) {\n // one task, because tasks within a phase run concurrently and the deploy reads the id\n this.startup.addTask(StartupPhase.Login, 'command-deploy', async () => {\n await commandRegistry.init();\n this.appId = await this.applicationId();\n await commandRegistry.setCommands();\n interactions?.warnUnhandledRoutes(commandRegistry.routeLeaves());\n interactions?.warnUnhandledContextMenuRoutes(commandRegistry.contextMenuLeaves());\n });\n }\n\n this.startup.addTask(StartupPhase.Ready, 'http-server', () => this.listen());\n\n if (!Envapter.isTest) {\n this.startup.addTask(StartupPhase.Ready, 'identity', () => this.fetchUsername());\n }\n\n const { healthCheck } = this;\n if (healthCheck) {\n this.startup.addTask(StartupPhase.Ready, 'health-check', async () => {\n healthCheck.logger.utils.initialization('HealthCheck', 'start');\n await healthCheck.init();\n healthCheck.logger.utils.initialization('HealthCheck', 'end');\n });\n }\n }\n\n private registerHmrAwareModules(): void {\n this.startup.addTask(StartupPhase.Configuration, 'hmr-registration', async () => {\n if (this.interactions) this.hmrManager.register(this.interactions);\n if (this.commandRegistry) this.hmrManager.register(this.commandRegistry);\n this.hmrManager.register(this.subscribers);\n for (const plugin of this.plugins) {\n this.hmrManager.register(plugin);\n }\n await Promise.resolve();\n });\n }\n\n private authenticate(): void {\n this.rest.setToken(validateDiscordToken(Envapter.get('DISCORD_BOT_TOKEN')));\n }\n\n // the promise is stored, so two concurrent Login tasks share one fetch\n private applicationId(): Promise<string> {\n this.appIdPromise ??= fetchApplicationId(this.rest);\n return this.appIdPromise;\n }\n\n // the registry deploys on a hot reload too, after the startup task resolved this\n private requireApplicationId(): string {\n if (!this.appId) throw new SeedcordError(SeedcordErrorCode.CoreApplicationUnavailable);\n return this.appId;\n }\n\n private async listen(): Promise<void> {\n const maps = this.interactions?.maps ?? buildRouteMaps(EMPTY_MANIFEST);\n const { handle, inFlight } = buildEngine(this, maps);\n\n const server = createServer((incoming, outgoing) => {\n void (async () => {\n const response = await handle(await toWebRequest(incoming));\n await writeWebResponse(response, outgoing);\n })().catch((error: unknown) => {\n // a swallowed throw would hang the client request with no cause\n outgoing.destroy(Error.isError(error) ? error : new Error(String(error)));\n });\n });\n this.server = server;\n\n server.listen(this.requestedPort);\n await once(server, 'listening');\n // justified: address() is AddressInfo once a TCP server is listening\n this.boundPort = (server.address() as AddressInfo).port;\n this.logger.info(`Interactions server listening on port ${paint.sky.bold(String(this.boundPort))}`);\n\n this.shutdown.addTask(\n ShutdownPhase.Unbind,\n 'stop-http-server',\n () => this.stopServer(),\n SERVER_SHUTDOWN_TIMEOUT_MS\n );\n // Unbind already ran, so every accepted request is in the in-flight set here\n this.shutdown.addTask(\n ShutdownPhase.Drain,\n 'drain-inflight',\n async () => {\n await Promise.allSettled(inFlight);\n },\n DRAIN_TIMEOUT_MS\n );\n }\n\n private async fetchUsername(): Promise<void> {\n try {\n // justified: the @me payload carries username per the discord api contract\n const me = (await this.rest.get(Routes.user('@me'))) as { username?: string };\n this.fetchedUsername = me.username;\n } catch (caught) {\n // a bad token errors on the first real send. The identity fetch stays non-fatal\n this.logger.warn('could not fetch the bot identity', caught);\n }\n }\n\n private stopServer(): Promise<void> {\n const server = this.server;\n if (!server?.listening) return Promise.resolve();\n\n return new Promise((resolveClose, rejectClose) => {\n server.close((err) => {\n if (err) {\n rejectClose(err);\n return;\n }\n this.logger.info(paint.coral.bold('Interactions server stopped'));\n resolveClose();\n });\n // idle keep-alive sockets would stall close() past the task timeout. Active responses\n // still flush, and the task timeout bounds a hung one\n server.closeIdleConnections();\n });\n }\n}\n","import { Plugin as CorePlugin } from '@seedcord/core/plugin';\n\nimport type { Core } from '@interfaces/Core';\nimport type { PluginOptions } from '@seedcord/core/plugin';\nimport type { TypedOmit } from '@seedcord/types';\n\n/** The options an HTTP plugin declares, narrowed to the transports this base serves. */\nexport type HttpPluginOptions = TypedOmit<PluginOptions, 'transport'> & { transport?: 'http' | 'any' };\n\n/**\n * Base class for an HTTP plugin, binding `this.core` to the HTTP {@link Core}.\n *\n * A plugin that runs on either transport extends the base from `@seedcord/core/plugin`, whose\n * `this.core` is typed to the shared members only.\n *\n * @typeParam Opts - The transport and runtime the plugin declares.\n */\nexport abstract class Plugin<Opts extends HttpPluginOptions = {}> extends CorePlugin<Opts, Core> {}\n\nexport type { PluginLifecycleSpec, PluginOptions } from '@seedcord/core/plugin';\n","export * from './edge.index';\nexport { Seedcord } from '@src/node/Seedcord';\n\nexport { Plugin } from './plugin';\nexport type { HttpPluginOptions, PluginLifecycleSpec, PluginOptions } from './plugin';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyEA,MAAa,iBAAgC;CACzC,eAAe,CAAC;CAChB,iBAAiB,CAAC;CAClB,oBAAoB,CAAC;CACrB,kBAAkB,CAAC;CACnB,kBAAkB,CAAC;AACvB;;;;;;;;;;AC/CA,IAAa,wBAAb,MAAuE;CAkBtC;CAjB7B,AAAgB;CAChB,AAAiB;;CAGjB,AAAgB,SAAS,IAAIA,wBAAO,gBAAgB,EAAE,SAAS,eAAe,CAAC;CAE/E,AAAQ,gBAAgB;CACxB,AAAiB;CAEjB,AAAiB,4BAAY,IAAI,IAG/B;CAEF,AAAQ,UAAU;CAClB,AAAiB,iBAAmD,CAAC;CAErE,YAAY,AAAiB,aAAqB;EAArB;EACzB,KAAK,OAAOC,kCAAe,cAAc;EACzC,KAAK,UAAU,KAAK,aAAa;EAEjC,IAAI,CAACC,gBAAS,iBAAiB,CAACA,gBAAS,QAAQ;EACjD,KAAK,aAAa,IAAIC,oCAAiB;GACnC;GACA,WAAW,KAAK,UAAU,KAAK,IAAI;GACnC,iBAAiB,KAAK,gBAAgB,KAAK,IAAI;GAC/C,mBAAmB,KAAK,kBAAkB,KAAK,IAAI;GACnD,cAAc,KAAK,aAAa,KAAK,IAAI;GACzC,QAAQ,KAAK;EACjB,CAAC;CACL;;CAGA,MAAa,OAAsB;EAC/B,IAAI,KAAK,eAAe;EACxB,KAAK,gBAAgB;EAErB,KAAK,U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,YAAa,OAAO,QAAQ,CAAC,CAAiB;EACnD,KAAK,OAAO,KAAK,yCAAyCC,uBAAM,IAAI,KAAK,OAAO,KAAK,SAAS,CAAC,GAAG;EAElG,KAAK,SAAS,QACVC,2CAAc,QACd,0BACM,KAAK,WAAW,GACtB,0BACJ;EAEA,KAAK,SAAS,QACVA,2CAAc,OACd,kBACA,YAAY;GACR,MAAM,QAAQ,WAAW,QAAQ;EACrC,GACA,gBACJ;CACJ;CAEA,MAAc,gBAA+B;EACzC,IAAI;GAEA,MAAM,KAAM,MAAM,KAAK,KAAK,IAAIC,6BAAO,KAAK,KAAK,CAAC;GAClD,KAAK,kBAAkB,GAAG;EAC9B,SAAS,QAAQ;GAEb,KAAK,OAAO,KAAK,oCAAoC,MAAM;EAC/D;CACJ;CAEA,AAAQ,aAA4B;EAChC,MAAM,SAAS,KAAK;EACpB,IAAI,CAAC,QAAQ,WAAW,OAAO,QAAQ,QAAQ;EAE/C,OAAO,IAAI,SAAS,cAAc,gBAAgB;GAC9C,OAAO,OAAO,QAAQ;IAClB,IAAI,KAAK;KACL,YAAY,GAAG;KACf;IACJ;IACA,KAAK,OAAO,KAAKF,uBAAM,MAAM,KAAK,6BAA6B,CAAC;IAChE,aAAa;GACjB,CAAC;GAGD,OAAO,qBAAqB;EAChC,CAAC;CACL;AACJ;;;;;;;;;;;;ACvSA,IAAsB,SAAtB,cAA0EG,6BAAuB,CAAC"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { _ as
|
|
1
|
+
import { C as createSeedcord, D as HttpEdgeConfig, E as HttpConfig, O as HttpServerConfig, S as SlashOptions, T as Core, _ as InteractionHandler, a as CursorSource, b as InjectedEmojiMap, c as Subscriber, d as SelectMenuHandler, f as ButtonHandler, g as SlashHandler, h as ContextMenuHandler, i as ArraySource, l as WebhookLog, m as AutocompleteHandler, n as Gated, o as Paginator, p as ComponentHandler, r as InteractionGateContext, s as PageContext, t as version, u as ModalHandler, v as RepliableHandler, w as EngineContext, x as ResolvedEmoji, y as Emojis } from "./edge.index-atnWgXP-.mjs";
|
|
2
2
|
import { t as RouteManifest } from "./RouteManifest-DE-HCMwd.mjs";
|
|
3
3
|
import { REST } from "@discordjs/rest";
|
|
4
4
|
import { Bus } from "@seedcord/core";
|
|
5
|
-
import { Pluggable
|
|
5
|
+
import { Pluggable } from "@seedcord/core/node/internal";
|
|
6
6
|
import { SeedcordBrand, SeedcordInstance } from "@seedcord/types/internal";
|
|
7
|
-
import { Plugin as Plugin$1,
|
|
7
|
+
import { Plugin as Plugin$1, PluginLifecycleSpec, PluginOptions, PluginOptions as PluginOptions$1 } from "@seedcord/core/plugin";
|
|
8
8
|
import { IRateLimiter, TypedOmit } from "@seedcord/types";
|
|
9
9
|
export * from "@seedcord/core";
|
|
10
|
+
export * from "@seedcord/types";
|
|
10
11
|
|
|
11
12
|
//#region src/node/Seedcord.d.ts
|
|
12
13
|
type RuntimeOfConfig<Cfg extends HttpConfig> = Cfg extends {
|
|
@@ -35,6 +36,10 @@ declare class Seedcord<Cfg extends HttpConfig = HttpConfig> extends Pluggable<'h
|
|
|
35
36
|
readonly bus: Bus;
|
|
36
37
|
private readonly subscribers;
|
|
37
38
|
private readonly interactions?;
|
|
39
|
+
private readonly commandRegistry?;
|
|
40
|
+
private appId?;
|
|
41
|
+
private appIdPromise?;
|
|
42
|
+
private readonly emojiInjector;
|
|
38
43
|
private readonly healthCheck?;
|
|
39
44
|
private readonly hmrManager;
|
|
40
45
|
private readonly logger;
|
|
@@ -47,7 +52,6 @@ declare class Seedcord<Cfg extends HttpConfig = HttpConfig> extends Pluggable<'h
|
|
|
47
52
|
get username(): string | undefined;
|
|
48
53
|
/** The bound server port, populated once `start()` is listening. */
|
|
49
54
|
get port(): number | undefined;
|
|
50
|
-
protected pluginCapabilities(): PluginCapabilities;
|
|
51
55
|
/**
|
|
52
56
|
* Starts the host and runs the startup tasks.
|
|
53
57
|
*
|
|
@@ -57,6 +61,9 @@ declare class Seedcord<Cfg extends HttpConfig = HttpConfig> extends Pluggable<'h
|
|
|
57
61
|
protected static reset(): void;
|
|
58
62
|
private registerStartupTasks;
|
|
59
63
|
private registerHmrAwareModules;
|
|
64
|
+
private authenticate;
|
|
65
|
+
private applicationId;
|
|
66
|
+
private requireApplicationId;
|
|
60
67
|
private listen;
|
|
61
68
|
private fetchUsername;
|
|
62
69
|
private stopServer;
|
|
@@ -71,14 +78,14 @@ type HttpPluginOptions = TypedOmit<PluginOptions$1, 'transport'> & {
|
|
|
71
78
|
* Base class for an HTTP plugin, binding `this.core` to the HTTP {@link Core}.
|
|
72
79
|
*
|
|
73
80
|
* A plugin that runs on either transport extends the base from `@seedcord/core/plugin`, whose
|
|
74
|
-
* `this.core`
|
|
81
|
+
* `this.core` is typed to the shared members only.
|
|
75
82
|
*
|
|
76
|
-
* @typeParam Opts - The transport
|
|
83
|
+
* @typeParam Opts - The transport and runtime the plugin declares.
|
|
77
84
|
*/
|
|
78
85
|
declare abstract class Plugin<Opts extends HttpPluginOptions = {}> extends Plugin$1<Opts, Core> {}
|
|
79
86
|
declare namespace index_d_exports {
|
|
80
|
-
export { AutocompleteHandler, ButtonHandler, ComponentHandler, ContextMenuHandler, Core, EngineContext, Gated, HttpConfig, HttpEdgeConfig, HttpPluginOptions, HttpServerConfig, InteractionGateContext, InteractionHandler, ModalHandler,
|
|
87
|
+
export { ArraySource, AutocompleteHandler, ButtonHandler, ComponentHandler, ContextMenuHandler, Core, CursorSource, Emojis, EngineContext, Gated, HttpConfig, HttpEdgeConfig, HttpPluginOptions, HttpServerConfig, InjectedEmojiMap, InteractionGateContext, InteractionHandler, ModalHandler, PageContext, Paginator, Plugin, PluginLifecycleSpec, PluginOptions, RepliableHandler, ResolvedEmoji, RouteManifest, Seedcord, SelectMenuHandler, SlashHandler, SlashOptions, Subscriber, WebhookLog, createSeedcord, version };
|
|
81
88
|
}
|
|
82
89
|
//#endregion
|
|
83
|
-
export { AutocompleteHandler, ButtonHandler, ComponentHandler, ContextMenuHandler, type Core, type EngineContext, Gated, type HttpConfig, type HttpEdgeConfig, type HttpPluginOptions, type HttpServerConfig, type InteractionGateContext, InteractionHandler, ModalHandler,
|
|
90
|
+
export { ArraySource, AutocompleteHandler, ButtonHandler, ComponentHandler, ContextMenuHandler, type Core, CursorSource, Emojis, type EngineContext, Gated, type HttpConfig, type HttpEdgeConfig, type HttpPluginOptions, type HttpServerConfig, type InjectedEmojiMap, type InteractionGateContext, InteractionHandler, ModalHandler, type PageContext, Paginator, Plugin, type PluginLifecycleSpec, type PluginOptions, RepliableHandler, type ResolvedEmoji, type RouteManifest, Seedcord, SelectMenuHandler, SlashHandler, type SlashOptions, Subscriber, WebhookLog, createSeedcord, version };
|
|
84
91
|
//# sourceMappingURL=index.d.mts.map
|