@seedcord/http 0.1.0-next.1 → 0.1.0-next.2
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/{RouteManifest-BHdAeyLG.d.mts → RouteManifest-DE-HCMwd.d.mts} +27 -22
- package/dist/{edge.index-BAgNb6TV.mjs → edge.index-BBRnxxkS.mjs} +330 -91
- package/dist/edge.index-BBRnxxkS.mjs.map +1 -0
- package/dist/{edge.index-CTOyjsO4.d.mts → edge.index-C30OZ55m.d.mts} +60 -36
- package/dist/{edge.index-D-60VfMn.cjs → edge.index-joDL39cK.cjs} +339 -88
- package/dist/edge.index-joDL39cK.cjs.map +1 -0
- package/dist/edge.index.cjs +3 -1
- package/dist/edge.index.d.mts +3 -3
- package/dist/edge.index.mjs +2 -2
- package/dist/index.cjs +56 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +34 -15
- package/dist/index.mjs +55 -32
- package/dist/index.mjs.map +1 -1
- package/dist/manifest.index.cjs +22 -5
- package/dist/manifest.index.cjs.map +1 -1
- package/dist/manifest.index.d.mts +3 -3
- package/dist/manifest.index.mjs +22 -5
- package/dist/manifest.index.mjs.map +1 -1
- package/package.json +7 -7
- package/dist/edge.index-BAgNb6TV.mjs.map +0 -1
- package/dist/edge.index-D-60VfMn.cjs.map +0 -1
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","HealthCheck","Envapter","StartupPhase","buildRouteMaps","buildEngine","paint","ShutdownPhase","Routes"],"sources":["../src/manifest/RouteManifest.ts","../src/node/InteractionDispatcher.ts","../src/node/webBridge.ts","../src/node/Seedcord.ts","../src/index.ts"],"sourcesContent":["import type { SelectMenuKind } from '@seedcord/core';\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/**\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 {\n readonly name: string;\n readonly type: RegistrableCommandType;\n /** Lazy import of the handler module, evaluated on first hit. */\n readonly load: () => Promise<unknown>;\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 {\n readonly kind: 'button' | `${SelectMenuKind}Select` | 'modal';\n readonly prefix: string;\n /** Lazy import of the handler module, evaluated on first hit. */\n readonly load: () => Promise<unknown>;\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 {\n readonly name: string;\n /** Lazy import of the handler module, evaluated on first hit. */\n readonly load: () => Promise<unknown>;\n}\n\n/**\n * A bus subscriber row. The Bus routes off it without importing the subscriber module. The HTTP engine\n * ignores these rows until the Bus ships on this transport.\n */\ninterface SubscriberRoute {\n /** The subscription keys this subscriber registers for. */\n readonly keys: readonly string[];\n /** Mirrors the `@Subscribe` frequency metadata. */\n readonly frequency: 'on' | 'once';\n /** Lazy import of the subscriber module. */\n readonly load: () => Promise<unknown>;\n}\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 commands: readonly CommandRoute[];\n readonly components: readonly ComponentRoute[];\n readonly autocomplete: readonly AutocompleteRoute[];\n readonly subscribers: readonly SubscriberRoute[];\n}\n\n/** @internal */\nexport const EMPTY_MANIFEST: RouteManifest = { commands: [], components: [], autocomplete: [], subscribers: [] };\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');\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<string, { ctor: HandlerConstructor; target: RouteTarget; key: string }>();\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(\n this.handlersDir,\n (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 this.logger\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 // 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 existing = this.rowOwners.get(`${target.kind}:${key}`);\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 key,\n existing.ctor.name,\n ctor.name\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 // a one-export module, the dispatch first-handler scan resolves exactly this row's class\n target.map.set(key, { kind: target.kind, routeId, load: () => Promise.resolve({ [ctor.name]: ctor }) });\n this.rowOwners.set(routeId, { ctor, target, key });\n }\n\n const from = formatFilePath(relativePath);\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 { HmrManager, setBotColor } from '@seedcord/core/internal';\nimport {\n CoordinatedShutdown,\n CoordinatedStartup,\n HealthCheck,\n Pluggable,\n ShutdownPhase,\n StartupPhase\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 { 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\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 extends Pluggable implements Core {\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 CoordinatedShutdown} */\n public override readonly shutdown: CoordinatedShutdown;\n\n /** @see {@link CoordinatedStartup} */\n public override readonly startup: CoordinatedStartup;\n\n private readonly interactions?: InteractionDispatcher;\n private readonly healthCheck?: HealthCheck | undefined;\n private readonly hmrManager: HmrManager;\n private readonly logger = new Logger('Server');\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: HttpConfig) {\n const shutdown = new CoordinatedShutdown();\n const startup = new CoordinatedStartup();\n\n super(shutdown, startup);\n\n installNodeDefaults(config.logger);\n setBotColor(config.botColor);\n\n this.shutdown = shutdown;\n this.startup = startup;\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 // 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 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 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","export * from './edge.index';\nexport { Seedcord } from '@src/node/Seedcord';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkEA,MAAa,iBAAgC;CAAE,UAAU,CAAC;CAAG,YAAY,CAAC;CAAG,cAAc,CAAC;CAAG,aAAa,CAAC;AAAE;;;;;;;;;;ACpC/G,IAAa,wBAAb,MAAuE;CAetC;CAd7B,AAAgB;CAChB,AAAiB;;CAGjB,AAAgB,SAAS,IAAIA,wBAAO,cAAc;CAElD,AAAQ,gBAAgB;CACxB,AAAiB;CAEjB,AAAiB,4BAAY,IAAI,IAA4E;CAE7G,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,UAAU;EACf,KAAK,eAAe,SAAS;EAC7B,IAAI;GACA,kDACI,KAAK,cACJ,UAAU,cAAc,aAAa;IAClC,KAAK,MAAM,SAAS,OAAO,OAAO,QAAQ,GAA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,OAAO,KAAKF,uBAAM,MAAM,KAAK,6BAA6B,CAAC;IAChE,aAAa;GACjB,CAAC;GAGD,OAAO,qBAAqB;EAChC,CAAC;CACL;AACJ"}
|
|
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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C5E,CAAC;EACL,CAAC;EACD,KAAK,SAAS;EAEd,OAAO,OAAO,KAAK,aAAa;EAChC,4BAAW,QAAQ,WAAW;EAE9B,KAAK,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;;;;;;;;;;;;ACpPA,IAAsB,SAAtB,cAA0EG,6BAAuB,CAAC"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
import { t as RouteManifest } from "./RouteManifest-
|
|
1
|
+
import { _ as EngineContext, a as WebhookLog, b as HttpEdgeConfig, c as ButtonHandler, d as ContextMenuHandler, f as SlashHandler, g as createSeedcord, h as SlashOptions, i as Subscriber, l as ComponentHandler, m as RepliableHandler, n as Gated, o as ModalHandler, p as InteractionHandler, r as InteractionGateContext, s as SelectMenuHandler, t as version, u as AutocompleteHandler, v as Core, x as HttpServerConfig, y as HttpConfig } from "./edge.index-C30OZ55m.mjs";
|
|
2
|
+
import { t as RouteManifest } from "./RouteManifest-DE-HCMwd.mjs";
|
|
3
3
|
import { REST } from "@discordjs/rest";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { Bus } from "@seedcord/core";
|
|
5
|
+
import { Pluggable, PluginCapabilities } from "@seedcord/core/node/internal";
|
|
6
|
+
import { SeedcordBrand, SeedcordInstance } from "@seedcord/types/internal";
|
|
7
|
+
import { Plugin as Plugin$1, PluginContext, PluginLifecycleSpec, PluginOptions, PluginOptions as PluginOptions$1 } from "@seedcord/core/plugin";
|
|
8
|
+
import { IRateLimiter, TypedOmit } from "@seedcord/types";
|
|
7
9
|
export * from "@seedcord/core";
|
|
8
10
|
|
|
9
11
|
//#region src/node/Seedcord.d.ts
|
|
12
|
+
type RuntimeOfConfig<Cfg extends HttpConfig> = Cfg extends {
|
|
13
|
+
runtime: 'edge';
|
|
14
|
+
} ? 'edge' : 'server';
|
|
10
15
|
/**
|
|
11
16
|
* The HTTP-interactions bot host, a long-running node server around the engine.
|
|
12
17
|
*
|
|
@@ -14,8 +19,8 @@ export * from "@seedcord/core";
|
|
|
14
19
|
* `start(port)`, and runs coordinated shutdown with an in-flight drain. The edge deploy path calls
|
|
15
20
|
* `createSeedcord` from a generated entry.
|
|
16
21
|
*/
|
|
17
|
-
declare class Seedcord extends Pluggable implements Core {
|
|
18
|
-
readonly config:
|
|
22
|
+
declare class Seedcord<Cfg extends HttpConfig = HttpConfig> extends Pluggable<'http', RuntimeOfConfig<Cfg>> implements Core, SeedcordInstance {
|
|
23
|
+
readonly config: Cfg;
|
|
19
24
|
/** @internal */
|
|
20
25
|
readonly [SeedcordBrand] = true;
|
|
21
26
|
/** @internal */
|
|
@@ -26,10 +31,9 @@ declare class Seedcord extends Pluggable implements Core {
|
|
|
26
31
|
readonly rest: REST;
|
|
27
32
|
/** @see {@link IRateLimiter} */
|
|
28
33
|
readonly rateLimiter: IRateLimiter;
|
|
29
|
-
/** @see {@link
|
|
30
|
-
readonly
|
|
31
|
-
|
|
32
|
-
readonly startup: CoordinatedStartup;
|
|
34
|
+
/** @see {@link Bus} */
|
|
35
|
+
readonly bus: Bus;
|
|
36
|
+
private readonly subscribers;
|
|
33
37
|
private readonly interactions?;
|
|
34
38
|
private readonly healthCheck?;
|
|
35
39
|
private readonly hmrManager;
|
|
@@ -38,7 +42,7 @@ declare class Seedcord extends Pluggable implements Core {
|
|
|
38
42
|
private boundPort?;
|
|
39
43
|
private requestedPort;
|
|
40
44
|
private fetchedUsername?;
|
|
41
|
-
constructor(config:
|
|
45
|
+
constructor(config: Cfg);
|
|
42
46
|
/** The bot's discord username, populated by the ready fetch. */
|
|
43
47
|
get username(): string | undefined;
|
|
44
48
|
/** The bound server port, populated once `start()` is listening. */
|
|
@@ -47,7 +51,7 @@ declare class Seedcord extends Pluggable implements Core {
|
|
|
47
51
|
/**
|
|
48
52
|
* Starts the host and runs the startup tasks.
|
|
49
53
|
*
|
|
50
|
-
* @param port - The port the interaction server binds. {@default `3000`}
|
|
54
|
+
* @param port - The port the interaction server binds. {@default `3000` }
|
|
51
55
|
*/
|
|
52
56
|
start(port?: number): Promise<this>;
|
|
53
57
|
protected static reset(): void;
|
|
@@ -57,9 +61,24 @@ declare class Seedcord extends Pluggable implements Core {
|
|
|
57
61
|
private fetchUsername;
|
|
58
62
|
private stopServer;
|
|
59
63
|
}
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/plugin.d.ts
|
|
66
|
+
/** The options an HTTP plugin declares, narrowed to the transports this base serves. */
|
|
67
|
+
type HttpPluginOptions = TypedOmit<PluginOptions$1, 'transport'> & {
|
|
68
|
+
transport?: 'http' | 'any';
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Base class for an HTTP plugin, binding `this.core` to the HTTP {@link Core}.
|
|
72
|
+
*
|
|
73
|
+
* A plugin that runs on either transport extends the base from `@seedcord/core/plugin`, whose
|
|
74
|
+
* `this.core` carries the shared members only.
|
|
75
|
+
*
|
|
76
|
+
* @typeParam Opts - The transport, runtime, and capabilities the plugin declares.
|
|
77
|
+
*/
|
|
78
|
+
declare abstract class Plugin<Opts extends HttpPluginOptions = {}> extends Plugin$1<Opts, Core> {}
|
|
60
79
|
declare namespace index_d_exports {
|
|
61
|
-
export { AutocompleteHandler, ButtonHandler, ComponentHandler, ContextMenuHandler, Core, EngineContext, Gated, HttpConfig, HttpEdgeConfig, HttpServerConfig, InteractionGateContext, InteractionHandler, ModalHandler, RepliableHandler, RouteManifest, Seedcord, SelectMenuHandler, SlashHandler, SlashOptions, createSeedcord, version };
|
|
80
|
+
export { AutocompleteHandler, ButtonHandler, ComponentHandler, ContextMenuHandler, Core, EngineContext, Gated, HttpConfig, HttpEdgeConfig, HttpPluginOptions, HttpServerConfig, InteractionGateContext, InteractionHandler, ModalHandler, Plugin, PluginContext, PluginLifecycleSpec, PluginOptions, RepliableHandler, RouteManifest, Seedcord, SelectMenuHandler, SlashHandler, SlashOptions, Subscriber, WebhookLog, createSeedcord, version };
|
|
62
81
|
}
|
|
63
82
|
//#endregion
|
|
64
|
-
export { AutocompleteHandler, ButtonHandler, ComponentHandler, ContextMenuHandler, type Core, type EngineContext, Gated, type HttpConfig, type HttpEdgeConfig, type HttpServerConfig, type InteractionGateContext, InteractionHandler, ModalHandler, RepliableHandler, type RouteManifest, Seedcord, SelectMenuHandler, SlashHandler, type SlashOptions, createSeedcord, version };
|
|
83
|
+
export { AutocompleteHandler, ButtonHandler, ComponentHandler, ContextMenuHandler, type Core, type EngineContext, Gated, type HttpConfig, type HttpEdgeConfig, type HttpPluginOptions, type HttpServerConfig, type InteractionGateContext, InteractionHandler, ModalHandler, Plugin, type PluginContext, type PluginLifecycleSpec, type PluginOptions, RepliableHandler, type RouteManifest, Seedcord, SelectMenuHandler, SlashHandler, type SlashOptions, Subscriber, WebhookLog, createSeedcord, version };
|
|
65
84
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { n as __reExport, t as __exportAll } from "./rolldown-runtime-BUUfjzRC.mjs";
|
|
2
|
-
import { a as
|
|
2
|
+
import { a as ModalHandler, c as ComponentHandler, d as createSeedcord, f as buildEngine, g as RepliableHandler, h as AutocompleteHandler, i as WebhookLog, l as ContextMenuHandler, m as InteractionHandler, n as Gated, o as SelectMenuHandler, p as buildRouteMaps, r as Subscriber, s as ButtonHandler, t as version, u as SlashHandler } from "./edge.index-BBRnxxkS.mjs";
|
|
3
3
|
import { SeedcordError, validateDiscordToken } from "@seedcord/errors/internal";
|
|
4
4
|
import { Envapter } from "envapt";
|
|
5
5
|
import { REST } from "@discordjs/rest";
|
|
6
|
+
import { Bus } from "@seedcord/core";
|
|
6
7
|
import { HmrManager, InteractionMetadataKey, InteractionRoutes, interactionRoutesOf, setBotColor } from "@seedcord/core/internal";
|
|
7
8
|
import { Logger, LoggerChannelRegistry, paint } from "@seedcord/logger";
|
|
8
9
|
import { MemoryRateLimiter } from "@seedcord/rate-limiter";
|
|
@@ -10,22 +11,24 @@ import { Routes } from "discord-api-types/v10";
|
|
|
10
11
|
import { SeedcordErrorCode } from "@seedcord/errors";
|
|
11
12
|
import { once } from "node:events";
|
|
12
13
|
import { createServer } from "node:http";
|
|
13
|
-
import { CoordinatedShutdown, CoordinatedStartup, HealthCheck, Pluggable, ShutdownPhase, StartupPhase } from "@seedcord/core/node/internal";
|
|
14
|
+
import { CoordinatedShutdown, CoordinatedStartup, HealthCheck, Pluggable, ShutdownPhase, StartupPhase, SubscriberLoader } from "@seedcord/core/node/internal";
|
|
14
15
|
import { installNodeDefaults } from "@seedcord/logger/node";
|
|
15
16
|
import { SeedcordBrand } from "@seedcord/types/internal";
|
|
16
17
|
import { HmrModuleHandler } from "@seedcord/core/hmr";
|
|
17
18
|
import { formatFilePath } from "@seedcord/utils";
|
|
18
19
|
import { traverseDirectory } from "@seedcord/utils/node";
|
|
20
|
+
import { Plugin as Plugin$1 } from "@seedcord/core/plugin";
|
|
19
21
|
|
|
20
22
|
export * from "@seedcord/core"
|
|
21
23
|
|
|
22
24
|
//#region src/manifest/RouteManifest.ts
|
|
23
25
|
/** @internal */
|
|
24
26
|
const EMPTY_MANIFEST = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
commandRoutes: [],
|
|
28
|
+
componentRoutes: [],
|
|
29
|
+
autocompleteRoutes: [],
|
|
30
|
+
subscriberRoutes: [],
|
|
31
|
+
middlewareRoutes: []
|
|
29
32
|
};
|
|
30
33
|
|
|
31
34
|
//#endregion
|
|
@@ -41,7 +44,7 @@ var InteractionDispatcher = class {
|
|
|
41
44
|
maps;
|
|
42
45
|
targets;
|
|
43
46
|
/** @internal */
|
|
44
|
-
logger = new Logger("Interactions");
|
|
47
|
+
logger = new Logger("Interactions", { channel: "interactions" });
|
|
45
48
|
isInitialized = false;
|
|
46
49
|
hmrHandler;
|
|
47
50
|
rowOwners = /* @__PURE__ */ new Map();
|
|
@@ -74,7 +77,7 @@ var InteractionDispatcher = class {
|
|
|
74
77
|
this.registerHandler(value, relativePath);
|
|
75
78
|
this.hmrHandler?.trackHandler(fullPath, value);
|
|
76
79
|
}
|
|
77
|
-
}
|
|
80
|
+
});
|
|
78
81
|
} finally {
|
|
79
82
|
this.loading = false;
|
|
80
83
|
}
|
|
@@ -145,15 +148,17 @@ var InteractionDispatcher = class {
|
|
|
145
148
|
};
|
|
146
149
|
}
|
|
147
150
|
registerHandler(ctor, relativePath) {
|
|
151
|
+
const from = formatFilePath(relativePath);
|
|
148
152
|
const writes = [];
|
|
149
153
|
for (const [route, keys] of interactionRoutesOf(ctor)) {
|
|
150
154
|
const target = this.targetFor(route);
|
|
151
155
|
for (const key of keys) {
|
|
152
|
-
const
|
|
156
|
+
const routeId = `${target.kind}:${key}`;
|
|
157
|
+
const existing = this.rowOwners.get(routeId);
|
|
153
158
|
if (existing && existing.ctor !== ctor) throw new SeedcordError(SeedcordErrorCode.InteractionDuplicateRoute, [
|
|
154
|
-
|
|
155
|
-
existing.ctor.name
|
|
156
|
-
ctor.name
|
|
159
|
+
routeId,
|
|
160
|
+
`${existing.ctor.name} (${existing.from})`,
|
|
161
|
+
`${ctor.name} (${from})`
|
|
157
162
|
]);
|
|
158
163
|
writes.push([target, key]);
|
|
159
164
|
}
|
|
@@ -164,15 +169,15 @@ var InteractionDispatcher = class {
|
|
|
164
169
|
target.map.set(key, {
|
|
165
170
|
kind: target.kind,
|
|
166
171
|
routeId,
|
|
167
|
-
load: () => Promise.resolve(
|
|
172
|
+
load: () => Promise.resolve(ctor)
|
|
168
173
|
});
|
|
169
174
|
this.rowOwners.set(routeId, {
|
|
170
175
|
ctor,
|
|
171
176
|
target,
|
|
172
|
-
key
|
|
177
|
+
key,
|
|
178
|
+
from
|
|
173
179
|
});
|
|
174
180
|
}
|
|
175
|
-
const from = formatFilePath(relativePath);
|
|
176
181
|
if (this.loading) this.loadedHandlers.push({
|
|
177
182
|
name: ctor.name,
|
|
178
183
|
from
|
|
@@ -244,31 +249,28 @@ var Seedcord = class Seedcord extends Pluggable {
|
|
|
244
249
|
rest = new REST();
|
|
245
250
|
/** @see {@link IRateLimiter} */
|
|
246
251
|
rateLimiter;
|
|
247
|
-
/** @see {@link
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
startup;
|
|
252
|
+
/** @see {@link Bus} */
|
|
253
|
+
bus;
|
|
254
|
+
subscribers;
|
|
251
255
|
interactions;
|
|
252
256
|
healthCheck;
|
|
253
257
|
hmrManager;
|
|
254
|
-
logger = new Logger("Server");
|
|
258
|
+
logger = new Logger("Server", { channel: "bot" });
|
|
255
259
|
server;
|
|
256
260
|
boundPort;
|
|
257
261
|
requestedPort = DEFAULT_PORT;
|
|
258
262
|
fetchedUsername;
|
|
259
263
|
constructor(config) {
|
|
260
|
-
|
|
261
|
-
const startup = new CoordinatedStartup();
|
|
262
|
-
super(shutdown, startup);
|
|
264
|
+
super(new CoordinatedShutdown(), new CoordinatedStartup());
|
|
263
265
|
this.config = config;
|
|
264
266
|
installNodeDefaults(config.logger);
|
|
265
267
|
setBotColor(config.botColor);
|
|
266
|
-
this.shutdown = shutdown;
|
|
267
|
-
this.startup = startup;
|
|
268
268
|
this.hmrManager = new HmrManager();
|
|
269
269
|
this.hmrManager.init();
|
|
270
270
|
if (this.config.bot.interactions.path) this.interactions = new InteractionDispatcher(this.config.bot.interactions.path);
|
|
271
271
|
this.rateLimiter = config.store ?? new MemoryRateLimiter();
|
|
272
|
+
this.bus = new Bus(this);
|
|
273
|
+
this.subscribers = new SubscriberLoader(this.bus, config.subscribers.path);
|
|
272
274
|
this.healthCheck = config.runtime === "edge" ? void 0 : HealthCheck.fromOption(this.shutdown, config.healthCheck);
|
|
273
275
|
this.registerStartupTasks();
|
|
274
276
|
}
|
|
@@ -290,7 +292,7 @@ var Seedcord = class Seedcord extends Pluggable {
|
|
|
290
292
|
/**
|
|
291
293
|
* Starts the host and runs the startup tasks.
|
|
292
294
|
*
|
|
293
|
-
* @param port - The port the interaction server binds. {@default `3000`}
|
|
295
|
+
* @param port - The port the interaction server binds. {@default `3000` }
|
|
294
296
|
*/
|
|
295
297
|
async start(port = DEFAULT_PORT) {
|
|
296
298
|
this.requestedPort = port;
|
|
@@ -309,24 +311,30 @@ var Seedcord = class Seedcord extends Pluggable {
|
|
|
309
311
|
}
|
|
310
312
|
registerStartupTasks() {
|
|
311
313
|
if (Envapter.isDevelopment || Envapter.isTest) this.registerHmrAwareModules();
|
|
314
|
+
this.startup.addTask(StartupPhase.Configuration, "bus-initialization", async () => {
|
|
315
|
+
this.bus.logger.utils.initialization("Subscribers", "start");
|
|
316
|
+
await this.subscribers.init();
|
|
317
|
+
this.bus.logger.utils.initialization("Subscribers", "end");
|
|
318
|
+
});
|
|
312
319
|
const { interactions } = this;
|
|
313
|
-
if (interactions) this.startup.addTask(StartupPhase.Configuration, "
|
|
320
|
+
if (interactions) this.startup.addTask(StartupPhase.Configuration, "interactions-initialization", async () => {
|
|
314
321
|
interactions.logger.utils.initialization("Interactions", "start");
|
|
315
322
|
await interactions.init();
|
|
316
323
|
interactions.logger.utils.initialization("Interactions", "end");
|
|
317
324
|
});
|
|
318
|
-
this.startup.addTask(StartupPhase.Ready, "
|
|
319
|
-
if (!Envapter.isTest) this.startup.addTask(StartupPhase.Ready, "
|
|
325
|
+
this.startup.addTask(StartupPhase.Ready, "http-server", () => this.listen());
|
|
326
|
+
if (!Envapter.isTest) this.startup.addTask(StartupPhase.Ready, "identity", () => this.fetchUsername());
|
|
320
327
|
const { healthCheck } = this;
|
|
321
|
-
if (healthCheck) this.startup.addTask(StartupPhase.Ready, "
|
|
328
|
+
if (healthCheck) this.startup.addTask(StartupPhase.Ready, "health-check", async () => {
|
|
322
329
|
healthCheck.logger.utils.initialization("HealthCheck", "start");
|
|
323
330
|
await healthCheck.init();
|
|
324
331
|
healthCheck.logger.utils.initialization("HealthCheck", "end");
|
|
325
332
|
});
|
|
326
333
|
}
|
|
327
334
|
registerHmrAwareModules() {
|
|
328
|
-
this.startup.addTask(StartupPhase.Configuration, "
|
|
335
|
+
this.startup.addTask(StartupPhase.Configuration, "hmr-registration", async () => {
|
|
329
336
|
if (this.interactions) this.hmrManager.register(this.interactions);
|
|
337
|
+
this.hmrManager.register(this.subscribers);
|
|
330
338
|
for (const plugin of this.plugins) this.hmrManager.register(plugin);
|
|
331
339
|
await Promise.resolve();
|
|
332
340
|
});
|
|
@@ -378,6 +386,18 @@ var Seedcord = class Seedcord extends Pluggable {
|
|
|
378
386
|
}
|
|
379
387
|
};
|
|
380
388
|
|
|
389
|
+
//#endregion
|
|
390
|
+
//#region src/plugin.ts
|
|
391
|
+
/**
|
|
392
|
+
* Base class for an HTTP plugin, binding `this.core` to the HTTP {@link Core}.
|
|
393
|
+
*
|
|
394
|
+
* A plugin that runs on either transport extends the base from `@seedcord/core/plugin`, whose
|
|
395
|
+
* `this.core` carries the shared members only.
|
|
396
|
+
*
|
|
397
|
+
* @typeParam Opts - The transport, runtime, and capabilities the plugin declares.
|
|
398
|
+
*/
|
|
399
|
+
var Plugin = class extends Plugin$1 {};
|
|
400
|
+
|
|
381
401
|
//#endregion
|
|
382
402
|
//#region src/index.ts
|
|
383
403
|
var src_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -388,14 +408,17 @@ var src_exports = /* @__PURE__ */ __exportAll({
|
|
|
388
408
|
Gated: () => Gated,
|
|
389
409
|
InteractionHandler: () => InteractionHandler,
|
|
390
410
|
ModalHandler: () => ModalHandler,
|
|
411
|
+
Plugin: () => Plugin,
|
|
391
412
|
RepliableHandler: () => RepliableHandler,
|
|
392
413
|
Seedcord: () => Seedcord,
|
|
393
414
|
SelectMenuHandler: () => SelectMenuHandler,
|
|
394
415
|
SlashHandler: () => SlashHandler,
|
|
416
|
+
Subscriber: () => Subscriber,
|
|
417
|
+
WebhookLog: () => WebhookLog,
|
|
395
418
|
createSeedcord: () => createSeedcord,
|
|
396
419
|
version: () => version
|
|
397
420
|
});
|
|
398
421
|
|
|
399
422
|
//#endregion
|
|
400
|
-
export { AutocompleteHandler, ButtonHandler, ComponentHandler, ContextMenuHandler, Gated, InteractionHandler, ModalHandler, RepliableHandler, Seedcord, SelectMenuHandler, SlashHandler, createSeedcord, version };
|
|
423
|
+
export { AutocompleteHandler, ButtonHandler, ComponentHandler, ContextMenuHandler, Gated, InteractionHandler, ModalHandler, Plugin, RepliableHandler, Seedcord, SelectMenuHandler, SlashHandler, Subscriber, WebhookLog, createSeedcord, version };
|
|
401
424
|
//# sourceMappingURL=index.mjs.map
|