@wolfstar/http-framework 3.3.0 → 3.4.0-next-20260904111115

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -21,6 +21,7 @@ A powerful HTTP framework for building your Discord bots, powered by [`node:http
21
21
 
22
22
  - Support for reloading and unloading commands
23
23
  - Built-in Hot Module Reloading for every store
24
+ - Built-in logger, extendable by plugins
24
25
  - Support for attachment responses
25
26
  - Seamless integration with low-level libraries
26
27
  - Thin wrapper on top of raw data for maximum performance
@@ -311,6 +312,39 @@ await client.load();
311
312
  await client.listen({ port: 3000 });
312
313
  ```
313
314
 
315
+ ### Logger
316
+
317
+ The framework ships a minimal logger, available as `container.logger` (and as `client.logger`) as soon as
318
+ `@wolfstar/http-framework` is imported. It writes to the matching `console` method and filters entries by
319
+ `LogLevel`, which defaults to `LogLevel.Info`:
320
+
321
+ ```typescript
322
+ import { container, Client, LogLevel } from '@wolfstar/http-framework';
323
+
324
+ const client = new Client({ logger: { level: LogLevel.Debug } });
325
+
326
+ container.logger.info('Ready');
327
+ container.logger.debug('Interaction received', interaction.id);
328
+ ```
329
+
330
+ The built-in implementation is intentionally bare: it has no timestamps, colours, or transports. Those belong to a
331
+ logger plugin, which replaces it by assigning an `ILogger` to `options.logger.instance` from a
332
+ `preGenericsInitialization` hook:
333
+
334
+ ```typescript
335
+ import { Plugin, preGenericsInitialization, type ClientOptions } from '@wolfstar/http-framework';
336
+
337
+ export class LoggerPlugin extends Plugin {
338
+ public static [preGenericsInitialization](options: ClientOptions): void {
339
+ options.logger ??= {};
340
+ options.logger.instance = new MyLogger(options.logger);
341
+ }
342
+ }
343
+ ```
344
+
345
+ Because the plugin only has to satisfy the `ILogger` interface, the rest of the framework — including Hot Module
346
+ Reloading and the command router — keeps logging through `container.logger` without any change.
347
+
314
348
  ### Client events
315
349
 
316
350
  The `Client` extends an event emitter typed by the `ClientEvents` interface. Every event name is also available as a
@@ -426,6 +460,87 @@ client.on(Events.HmrPieceReloaded, async (piece) => {
426
460
  > registered exactly once. HMR does not push the updated commands to Discord on its own, subscribe to the events above
427
461
  > if you want that behaviour.
428
462
 
463
+ ### Project configuration (`stars.config.*`)
464
+
465
+ `@wolfstar/http-framework` owns the typed project configuration consumed by the [`stars` CLI](../cli) — the
466
+ `defineConfig` helper and the config loader live here, not in the CLI, so any tool can resolve a project's
467
+ configuration without pulling in `@wolfstar/cli`.
468
+
469
+ ```typescript
470
+ // stars.config.ts
471
+ import { defineConfig } from '@wolfstar/http-framework/config';
472
+
473
+ export default defineConfig({
474
+ entry: 'src/main.ts',
475
+ build: { tool: 'tsdown' }
476
+ });
477
+ ```
478
+
479
+ `@wolfstar/http-framework/config` has no side effects — importing it (or a `stars.config.ts` that imports it) never
480
+ starts the bot. `loadStarsConfig` discovers `stars.config.{ts,mts,cts,js,mjs,cjs}` from a directory, applies defaults,
481
+ validates every option and resolves all paths to absolute ones.
482
+
483
+ `dev.url`, the URL `stars dev` shows and health-checks the bot on, needs no configuration either: it is detected the
484
+ way Vite's and Nuxt's dev servers are, from `HTTP_PORT` (env var, `.env.local`/`.env`, or `dev.env`) or `3000`, and
485
+ `localhost` is swapped for `127.0.0.1` at runtime if that is what is actually reachable. Set `dev.url` explicitly only
486
+ to override it, e.g. for a LAN address: `dev: { url: 'http://192.168.1.5:3000' }`.
487
+
488
+ `dev` also carries the three options that round out the dev loop:
489
+
490
+ ```typescript
491
+ export default defineConfig({
492
+ entry: 'src/main.ts',
493
+ build: { tool: 'tsdown' },
494
+ dev: {
495
+ // A type checker next to the bot, reported on the dev UI's `tsc` channel. Never blocks a build.
496
+ // `checker` is 'tsc' | 'golar' | 'tsz' | 'auto' (default: golar when installed, tsc otherwise).
497
+ typecheck: { checker: 'golar' },
498
+ // A cloudflared quick tunnel so Discord can reach the interactions endpoint, or an https URL you serve.
499
+ tunnel: true,
500
+ // Where the session's logs are mirrored, so a run can be read after the terminal UI is gone.
501
+ logFile: '.stars/dev.log'
502
+ }
503
+ });
504
+ ```
505
+
506
+ `tunnel.updateEndpoint` writes the public URL to the Discord application's `interactions_endpoint_url`; it is opt-in
507
+ because it edits a live application, and needs `DISCORD_TOKEN` in the environment or the project's `.env`.
508
+
509
+ ### Experimental flags
510
+
511
+ `experimental` is the same kind of block Nuxt's own `experimental` is: opt-in booleans, all `false` by default, each
512
+ guarding work that is still landing.
513
+
514
+ ```typescript
515
+ export default defineConfig({
516
+ entry: 'src/main.ts',
517
+ // `build.tool: 'vite'` is only accepted with `enableVite`, and `'auto'` only then detects a vite.config.*
518
+ build: { tool: 'vite' },
519
+ experimental: {
520
+ // Vite as the build tool and the HTTP server, in place of tsdown plus the framework's node:http listener.
521
+ enableVite: true,
522
+ // The project runs Vite itself: `stars dev` only watches the output and restarts the bot.
523
+ enableExternalVite: false,
524
+ // Build and serve through Nitro. Needs the framework's Fetch adapter, so `stars dev`/`stars build` still
525
+ // refuse it with an actionable error for now.
526
+ enableNitro: false
527
+ }
528
+ });
529
+ ```
530
+
531
+ The resolved configuration is also available programmatically:
532
+
533
+ ```typescript
534
+ import { loadStarsConfig } from '@wolfstar/http-framework/config';
535
+
536
+ const config = await loadStarsConfig({ cwd: process.cwd() });
537
+ console.log(config.entry, config.build.output);
538
+ ```
539
+
540
+ Invalid options raise a `ConfigError` with a stable `code`, the offending option `path`, the `file` it came from, and
541
+ an actionable `hint`. See the [`@wolfstar/cli` README](../cli#configuration) for the full option reference and how the
542
+ `stars` commands (`dev`, `build`, `info`, `codegen`, `prepare`, `commands`) use it.
543
+
429
544
  ### ApplicationCommandRegistry
430
545
 
431
546
  The `ApplicationCommandRegistry` is `@wolfstar/http-framework`'s centralized registry and uses [`@discordjs/rest`] to register them in Discord.