@rudderjs/core 1.1.2 → 1.1.4

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
@@ -54,7 +54,7 @@ export default Application.configure({
54
54
  - `ServiceProvider` — `register()`, `boot()`, `publishes()`
55
55
  - `PublishGroup` — `{ from, to, tag? }`
56
56
  - `getPublishGroups()` — returns the global publish registry (used by `vendor:publish`)
57
- - `Listener`, `EventDispatcher`, `dispatcher`, `dispatch()`, `events()`
57
+ - `Listener`, `EventDispatcher`, `dispatcher`, `dispatch()`, `eventsProvider()`
58
58
  - `Application`, `AppConfig`
59
59
  - `ConfigureOptions`, `RoutingOptions`
60
60
  - `MiddlewareConfigurator`, `ExceptionConfigurator`
@@ -259,7 +259,7 @@ pnpm rudder vendor:publish --list # see all available assets
259
259
  ## Events
260
260
 
261
261
  ```ts
262
- import { dispatch, dispatcher, events } from '@rudderjs/core'
262
+ import { dispatch, dispatcher, eventsProvider } from '@rudderjs/core'
263
263
 
264
264
  // Define an event
265
265
  class UserCreated {
@@ -274,9 +274,9 @@ class SendWelcomeEmail {
274
274
  }
275
275
 
276
276
  // Register via provider in bootstrap/providers.ts
277
- import { events } from '@rudderjs/core'
277
+ import { eventsProvider } from '@rudderjs/core'
278
278
  export default [
279
- events({ UserCreated: [SendWelcomeEmail] }),
279
+ eventsProvider({ UserCreated: [SendWelcomeEmail] }),
280
280
  ]
281
281
 
282
282
  // Dispatch anywhere
@@ -294,6 +294,20 @@ await dispatch(new UserCreated(42))
294
294
  | `list()` | `Record<string, number>` snapshot of all registered events and counts. |
295
295
  | `reset()` | Clear all listeners (testing / hot-reload). |
296
296
 
297
+ ### Testing events (`EventFake`)
298
+
299
+ ```ts
300
+ import { EventFake, dispatch } from '@rudderjs/core'
301
+
302
+ const fake = EventFake.fake()
303
+ await dispatch(new UserCreated(42))
304
+
305
+ fake.assertDispatched('UserCreated')
306
+ fake.assertDispatchedTimes('UserCreated', 1)
307
+ fake.assertNotDispatched('OrderPlaced')
308
+ fake.restore() // always call in afterEach
309
+ ```
310
+
297
311
  ## Exception Handling
298
312
 
299
313
  ### `abort()` helpers
@@ -402,7 +416,7 @@ class StoreUser extends FormRequest<typeof schema> {
402
416
  }
403
417
  ```
404
418
 
405
- **Pipeline order:** `authorizeprepareForValidation → rules.parse → after → passedValidation`. Both Zod parse failures and `after()` errors converge through `failedValidation(errors)`.
419
+ **Pipeline order:** `prepareForValidationauthorize → rules.parse → after → passedValidation`. Both Zod parse failures and `after()` errors converge through `failedValidation(errors)`.
406
420
 
407
421
  **Short-circuit responses:** `failedValidation` may `return` a Web `Response` to bypass the default 422 — the framework's exception handler unwraps the `ValidationResponse` sentinel and emits the wrapped Response directly.
408
422
 
@@ -132,6 +132,30 @@ Use `abort(status, message?)`, `abort_if(condition, status)`, and `abort_unless(
132
132
 
133
133
  Extend `Listener` and call `dispatch(new MyEvent(data))`. Register listeners in a provider's `boot()`.
134
134
 
135
+ ### Testing Events (`EventFake`)
136
+
137
+ Use `EventFake.fake()` in tests to intercept dispatched events without running real listeners:
138
+
139
+ ```ts
140
+ import { EventFake, dispatch } from '@rudderjs/core'
141
+
142
+ const fake = EventFake.fake()
143
+
144
+ await dispatch(new UserRegistered(user))
145
+
146
+ fake.assertDispatched('UserRegistered')
147
+ fake.assertDispatchedTimes('UserRegistered', 1)
148
+ fake.assertNotDispatched('OrderPlaced')
149
+ fake.assertNothingDispatched() // fails if anything was dispatched
150
+
151
+ // Access payloads
152
+ const [event] = fake.dispatched('UserRegistered')
153
+
154
+ fake.restore() // always call in afterEach
155
+ ```
156
+
157
+ `EventFake.fake()` replaces `dispatcher.dispatch` globally for the duration of the test. Always restore in `afterEach` to avoid leaking state across tests.
158
+
135
159
  ### Validation
136
160
 
137
161
  Extend `FormRequest` and define a `rules()` method returning a Zod schema (`z.object({...})`). `z` is re-exported from `@rudderjs/core`. Five optional lifecycle hooks mirror Laravel: `prepareForValidation` (mutate input pre-parse), `messages` (per-request error message overrides keyed by dot-path), `after` (array of cross-field check closures with `addError(path, msg)`), `passedValidation` (final transform on parsed data), and `failedValidation` (override the throw — return a `Response` to short-circuit, otherwise it throws `ValidationError`). Parameterize as `extends FormRequest<typeof schema>` to get `z.infer<typeof schema>` typing inside the hooks.
@@ -140,7 +164,7 @@ Extend `FormRequest` and define a `rules()` method returning a Zod schema (`z.ob
140
164
 
141
165
  - **Missing `reflect-metadata`**: Must be imported at the very top of `bootstrap/app.ts` before any other imports. Install as a `dependency`, not `devDependency`.
142
166
  - **Provider boot order matters**: `DatabaseServiceProvider` must come before any provider that uses ORM models. Order your `providers` array accordingly.
143
- - **Scoped bindings outside request scope**: Calling `app().make('scopedToken')` outside of `container.runScoped()` throws. Ensure `ScopeMiddleware` is registered or wrap the call manually.
167
+ - **Scoped bindings outside request scope**: Calling `app().make('scopedToken')` outside of `container.runScoped()` throws. `@rudderjs/server-hono` wraps each request automatically — in tests or scripts, call `container.runScoped(() => ...)` manually.
144
168
  - **Dynamic provider duplicates**: `app().register()` is safe to call multiple times with the same class -- duplicates are skipped. But factory functions create anonymous classes, so use consistent references.
145
169
  - **Circular dependency with `@rudderjs/router`**: Core loads router at runtime via dynamic `import()`. Never add `@rudderjs/core` to router's `dependencies` -- use `peerDependencies` only.
146
170
 
@@ -149,7 +173,7 @@ Extend `FormRequest` and define a `rules()` method returning a Zod schema (`z.ob
149
173
  ```ts
150
174
  import { Application, app, resolve, ServiceProvider, Injectable, Inject, Tag, tagToken } from '@rudderjs/core'
151
175
  import { FormRequest, ValidationError, ValidationResponse, z } from '@rudderjs/core'
152
- import { Listener, dispatch, events } from '@rudderjs/core'
176
+ import { Listener, dispatch, eventsProvider } from '@rudderjs/core'
153
177
  import { HttpException, abort, abort_if, report } from '@rudderjs/core'
154
178
  import { Collection, Env, env, config, sleep } from '@rudderjs/core'
155
179
  import { rudder, Command } from '@rudderjs/core'
@@ -0,0 +1,98 @@
1
+ import type { AppRequest, MiddlewareHandler, ServerAdapterProvider } from '@rudderjs/contracts';
2
+ import { Application, type ProviderClass } from './application.js';
3
+ export interface ConfigureOptions {
4
+ server: ServerAdapterProvider;
5
+ config?: Record<string, unknown>;
6
+ providers?: ProviderClass[];
7
+ }
8
+ export interface RoutingOptions {
9
+ web?: () => Promise<unknown>;
10
+ api?: () => Promise<unknown>;
11
+ commands?: () => Promise<unknown>;
12
+ channels?: () => Promise<unknown>;
13
+ }
14
+ type RouteGroupName = 'web' | 'api';
15
+ export declare class MiddlewareConfigurator {
16
+ private _handlers;
17
+ private _groupHandlers;
18
+ /** Global middleware — runs on every request, regardless of route group. */
19
+ use(handler: MiddlewareHandler): this;
20
+ /** Append middleware to the `web` route group (routes loaded via withRouting({ web })). */
21
+ web(...handlers: MiddlewareHandler[]): this;
22
+ /** Append middleware to the `api` route group (routes loaded via withRouting({ api })). */
23
+ api(...handlers: MiddlewareHandler[]): this;
24
+ getHandlers(): MiddlewareHandler[];
25
+ /** Combined group stack — user-config + any provider-registered group middleware. */
26
+ getGroupHandlers(group: RouteGroupName): MiddlewareHandler[];
27
+ }
28
+ export type ErrorRenderer = (err: unknown, req: AppRequest) => Response | Promise<Response>;
29
+ export declare class ExceptionConfigurator {
30
+ private _renders;
31
+ private _ignored;
32
+ /**
33
+ * Register a custom renderer for a specific error type.
34
+ *
35
+ * @example
36
+ * e.render(PaymentError, (err, req) =>
37
+ * new Response(JSON.stringify({ code: err.code }), { status: 402, headers: { 'Content-Type': 'application/json' } })
38
+ * )
39
+ */
40
+ render<T extends Error>(type: new (...args: any[]) => T, fn: (err: T, req: AppRequest) => Response | Promise<Response>): this;
41
+ /**
42
+ * Ignore an error type — re-throws it so the server's native handler sees it.
43
+ */
44
+ ignore(type: new (...args: any[]) => unknown): this;
45
+ /**
46
+ * Override the global exception reporter for unhandled errors.
47
+ * By default, `@rudderjs/log` wires this automatically when installed.
48
+ *
49
+ * @example
50
+ * e.reportUsing((err) => Sentry.captureException(err))
51
+ */
52
+ reportUsing(fn: (err: unknown) => void): this;
53
+ /** @internal — called by RudderJS to produce the combined error handler */
54
+ buildHandler(): ErrorRenderer;
55
+ }
56
+ export declare class AppBuilder {
57
+ private readonly _options;
58
+ private _loaders;
59
+ private _mwFn?;
60
+ private _excFn?;
61
+ constructor(_options: ConfigureOptions);
62
+ withRouting(routes: RoutingOptions): this;
63
+ /** Wrap a route loader so routes registered inside it get tagged with `group`. */
64
+ private _taggedLoader;
65
+ withMiddleware(fn: (m: MiddlewareConfigurator) => void): this;
66
+ withExceptions(fn: (e: ExceptionConfigurator) => void): this;
67
+ create(): RudderJS;
68
+ }
69
+ export declare class RudderJS {
70
+ private readonly _app;
71
+ private readonly _server;
72
+ private readonly _loaders;
73
+ private readonly _mwFn?;
74
+ private readonly _excFn?;
75
+ /** Phase 1: providers only — safe to await in CLI (no Vike virtual imports) */
76
+ private _providerBoot;
77
+ /** Phase 2: provider boot + HTTP handler — created lazily on first handleRequest call */
78
+ private _boot;
79
+ private _handler;
80
+ constructor(_app: Application, _server: ServerAdapterProvider, _loaders: Array<() => Promise<unknown>>, _mwFn?: ((m: MiddlewareConfigurator) => void) | undefined, _excFn?: ((e: ExceptionConfigurator) => void) | undefined);
81
+ private _suppressVikeNoise;
82
+ /** Phase 1 — boot providers + routes. Safe in CLI (no Vike virtual URLs). */
83
+ private _bootstrapProviders;
84
+ /**
85
+ * Dev-only — print the auto-discovered providers grouped by stage so a missing
86
+ * package is visible at every boot instead of failing silently when first used.
87
+ * Wraps long stage lines so the output stays readable in narrow terminals.
88
+ */
89
+ private _printDevBootLog;
90
+ /** Phase 2 — create the HTTP fetch handler. Requires Vite context (virtual: URLs). */
91
+ private _createHandler;
92
+ /** Boot providers without starting an HTTP server — used by the CLI */
93
+ boot(): Promise<void>;
94
+ handleRequest(request: Request, env?: unknown, ctx?: unknown): Promise<Response>;
95
+ readonly fetch: (request: Request, env?: unknown, ctx?: unknown) => Promise<Response>;
96
+ }
97
+ export {};
98
+ //# sourceMappingURL=app-builder.d.ts.map
@@ -0,0 +1 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AQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IAX1B,+EAA+E;IAC/E,OAAO,CAAC,aAAa,CAAe;IACpC,yFAAyF;IACzF,OAAO,CAAC,KAAK,CAA6B;IAC1C,OAAO,CAAC,QAAQ,CAA4B;gBAGzB,IAAI,EAAM,WAAW,EACrB,OAAO,EAAG,qBAAqB,EAC/B,QAAQ,EAAE,KAAK,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,EACvC,KAAK,CAAC,GAAI,CAAC,CAAC,EAAE,sBAAsB,KAAK,IAAI,aAAA,EAC7C,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,qBAAqB,KAAK,IAAI,aAAA;IAK/D,OAAO,CAAC,kBAAkB;IAe1B,6EAA6E;YAC/D,mBAAmB;IAmBjC;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IAiFxB,sFAAsF;YACxE,cAAc;IAkB5B,uEAAuE;IACjE,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IAOtF,QAAQ,CAAC,KAAK,GAAI,SAAS,OAAO,EAAE,MAAM,OAAO,EAAE,MAAM,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC,CAC7C;CACxC"}
@@ -0,0 +1,352 @@
1
+ import { rudder } from '@rudderjs/console';
2
+ import { Application, groupMiddlewareStore, resetGroupMiddleware, } from './application.js';
3
+ import { getLastLoadedProviderEntries } from './default-providers.js';
4
+ import { HttpException, renderHttpException, renderServerError, report, setExceptionReporter, wantsJson, } from './exceptions.js';
5
+ import { ValidationError, ValidationResponse } from './validation.js';
6
+ export class MiddlewareConfigurator {
7
+ _handlers = [];
8
+ _groupHandlers = { web: [], api: [] };
9
+ /** Global middleware — runs on every request, regardless of route group. */
10
+ use(handler) {
11
+ this._handlers.push(handler);
12
+ return this;
13
+ }
14
+ /** Append middleware to the `web` route group (routes loaded via withRouting({ web })). */
15
+ web(...handlers) {
16
+ this._groupHandlers.web.push(...handlers);
17
+ return this;
18
+ }
19
+ /** Append middleware to the `api` route group (routes loaded via withRouting({ api })). */
20
+ api(...handlers) {
21
+ this._groupHandlers.api.push(...handlers);
22
+ return this;
23
+ }
24
+ getHandlers() { return this._handlers; }
25
+ /** Combined group stack — user-config + any provider-registered group middleware. */
26
+ getGroupHandlers(group) {
27
+ return [...groupMiddlewareStore[group], ...this._groupHandlers[group]];
28
+ }
29
+ }
30
+ export class ExceptionConfigurator {
31
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
+ _renders = [];
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+ _ignored = new Set();
35
+ /**
36
+ * Register a custom renderer for a specific error type.
37
+ *
38
+ * @example
39
+ * e.render(PaymentError, (err, req) =>
40
+ * new Response(JSON.stringify({ code: err.code }), { status: 402, headers: { 'Content-Type': 'application/json' } })
41
+ * )
42
+ */
43
+ render(
44
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
+ type, fn) {
46
+ this._renders.push({ type, fn: fn });
47
+ return this;
48
+ }
49
+ /**
50
+ * Ignore an error type — re-throws it so the server's native handler sees it.
51
+ */
52
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
+ ignore(type) {
54
+ this._ignored.add(type);
55
+ return this;
56
+ }
57
+ /**
58
+ * Override the global exception reporter for unhandled errors.
59
+ * By default, `@rudderjs/log` wires this automatically when installed.
60
+ *
61
+ * @example
62
+ * e.reportUsing((err) => Sentry.captureException(err))
63
+ */
64
+ reportUsing(fn) {
65
+ setExceptionReporter(fn);
66
+ return this;
67
+ }
68
+ /** @internal — called by RudderJS to produce the combined error handler */
69
+ buildHandler() {
70
+ const renders = this._renders.slice();
71
+ const ignored = new Set(this._ignored);
72
+ return async (err, req) => {
73
+ // 1. Explicitly ignored — re-throw
74
+ for (const type of ignored) {
75
+ if (err instanceof type)
76
+ throw err;
77
+ }
78
+ // 2. User-registered renderers (take priority)
79
+ for (const { type, fn } of renders) {
80
+ if (err instanceof type)
81
+ return fn(err, req);
82
+ }
83
+ // 3. ValidationResponse — short-circuit emit the wrapped Response (FormRequest.failedValidation)
84
+ if (err instanceof ValidationResponse) {
85
+ return err.response;
86
+ }
87
+ // 4. ValidationError — 422 JSON
88
+ if (err instanceof ValidationError) {
89
+ return new Response(JSON.stringify(err.toJSON()), {
90
+ status: 422,
91
+ headers: { 'Content-Type': 'application/json' },
92
+ });
93
+ }
94
+ // 4. HttpException — render with its status code (JSON or HTML)
95
+ if (err instanceof HttpException) {
96
+ return renderHttpException(err, req);
97
+ }
98
+ // 5. Errors carrying a duck-typed `httpStatus` (e.g. ModelNotFoundError,
99
+ // RouteModelNotFoundError) — render with that status. Avoids a hard
100
+ // dependency on @rudderjs/orm or @rudderjs/router from here.
101
+ if (err instanceof Error) {
102
+ const status = err.httpStatus;
103
+ if (typeof status === 'number' && status >= 400 && status < 600) {
104
+ return renderHttpException(new HttpException(status, err.message), req);
105
+ }
106
+ }
107
+ // 6. Unhandled — report, then either bubble (so the adapter's rich
108
+ // dev error page fires) or render the safe fallback page.
109
+ //
110
+ // In dev mode AND for HTML-accepting clients, re-throw so the adapter
111
+ // (e.g. server-hono's Ignition-style `renderErrorPage`) catches it
112
+ // and renders a stack-frame view with source context. Without this,
113
+ // every unhandled 500 fell through to `renderServerError`'s plain
114
+ // card-style page below — the dev page was effectively dead code from
115
+ // 2026-04-06 onward when this central pipeline was added.
116
+ //
117
+ // Prod (`debug === false`) and JSON clients always use the safe page:
118
+ // the former mustn't leak source-context to attackers, the latter
119
+ // doesn't render HTML at all.
120
+ report(err);
121
+ let debug = false;
122
+ try {
123
+ debug = Application.getInstance().debug;
124
+ }
125
+ catch { /* app not ready */ }
126
+ if (debug && !wantsJson(req)) {
127
+ throw err;
128
+ }
129
+ return renderServerError(req, debug, err);
130
+ };
131
+ }
132
+ }
133
+ // ─── App Builder ───────────────────────────────────────────
134
+ export class AppBuilder {
135
+ _options;
136
+ _loaders = [];
137
+ _mwFn;
138
+ _excFn;
139
+ constructor(_options) {
140
+ this._options = _options;
141
+ }
142
+ withRouting(routes) {
143
+ if (routes.web)
144
+ this._loaders.push(this._taggedLoader('web', routes.web));
145
+ if (routes.api)
146
+ this._loaders.push(this._taggedLoader('api', routes.api));
147
+ if (routes.commands)
148
+ this._loaders.push(routes.commands);
149
+ if (routes.channels)
150
+ this._loaders.push(routes.channels);
151
+ return this;
152
+ }
153
+ /** Wrap a route loader so routes registered inside it get tagged with `group`. */
154
+ _taggedLoader(group, loader) {
155
+ return async () => {
156
+ const { runWithGroup } = await import('@rudderjs/router');
157
+ return runWithGroup(group, loader);
158
+ };
159
+ }
160
+ withMiddleware(fn) {
161
+ this._mwFn = fn;
162
+ return this;
163
+ }
164
+ withExceptions(fn) {
165
+ this._excFn = fn;
166
+ return this;
167
+ }
168
+ create() {
169
+ const g = globalThis;
170
+ if (g['__rudderjs_instance__'])
171
+ return g['__rudderjs_instance__'];
172
+ const app = Application.create({
173
+ ...(this._options.config && { config: this._options.config }),
174
+ ...(this._options.providers && { providers: this._options.providers }),
175
+ });
176
+ const instance = new RudderJS(app, this._options.server, this._loaders, this._mwFn, this._excFn);
177
+ g['__rudderjs_instance__'] = instance;
178
+ return instance;
179
+ }
180
+ }
181
+ // ─── RudderJS (Configured Application) ─────────────────────
182
+ export class RudderJS {
183
+ _app;
184
+ _server;
185
+ _loaders;
186
+ _mwFn;
187
+ _excFn;
188
+ /** Phase 1: providers only — safe to await in CLI (no Vike virtual imports) */
189
+ _providerBoot;
190
+ /** Phase 2: provider boot + HTTP handler — created lazily on first handleRequest call */
191
+ _boot = null;
192
+ _handler = null;
193
+ constructor(_app, _server, _loaders, _mwFn, _excFn) {
194
+ this._app = _app;
195
+ this._server = _server;
196
+ this._loaders = _loaders;
197
+ this._mwFn = _mwFn;
198
+ this._excFn = _excFn;
199
+ this._providerBoot = this._bootstrapProviders();
200
+ }
201
+ _suppressVikeNoise() {
202
+ const isNoise = (args) => {
203
+ const msg = args.map(a => String(a ?? '')).join(' ');
204
+ if (msg.includes('[vike]'))
205
+ return true;
206
+ if (msg.includes('Server running at '))
207
+ return true;
208
+ return false;
209
+ };
210
+ const _log = console.log;
211
+ const _warn = console.warn;
212
+ const _info = console.info;
213
+ console.log = (...a) => { if (!isNoise(a))
214
+ _log(...a); };
215
+ console.warn = (...a) => { if (!isNoise(a))
216
+ _warn(...a); };
217
+ console.info = (...a) => { if (!isNoise(a))
218
+ _info(...a); };
219
+ }
220
+ /** Phase 1 — boot providers + routes. Safe in CLI (no Vike virtual URLs). */
221
+ async _bootstrapProviders() {
222
+ this._suppressVikeNoise();
223
+ if (this._app.isDevelopment()) {
224
+ rudder.reset();
225
+ const { router } = await import('@rudderjs/router');
226
+ router.reset();
227
+ resetGroupMiddleware();
228
+ }
229
+ await this._app.bootstrap();
230
+ // Serial loader execution — required for per-loader group tagging in
231
+ // @rudderjs/router's runWithGroup(). Parallel execution would set the
232
+ // module-level currentGroup to whichever loader was invoked last before
233
+ // any module bodies evaluated in microtasks. Sequential is negligibly
234
+ // slower for ≤4 loaders and keeps the group context correct.
235
+ for (const loader of this._loaders)
236
+ await loader();
237
+ if (this._app.isDevelopment())
238
+ this._printDevBootLog();
239
+ console.log('[RudderJS] ready');
240
+ }
241
+ /**
242
+ * Dev-only — print the auto-discovered providers grouped by stage so a missing
243
+ * package is visible at every boot instead of failing silently when first used.
244
+ * Wraps long stage lines so the output stays readable in narrow terminals.
245
+ */
246
+ _printDevBootLog() {
247
+ const entries = getLastLoadedProviderEntries();
248
+ if (entries.length === 0)
249
+ return;
250
+ const C = {
251
+ dim: (s) => `\x1b[2m${s}\x1b[0m`,
252
+ magenta: (s) => `\x1b[35m${s}\x1b[0m`,
253
+ cyan: (s) => `\x1b[36m${s}\x1b[0m`,
254
+ green: (s) => `\x1b[32m${s}\x1b[0m`,
255
+ yellow: (s) => `\x1b[33m${s}\x1b[0m`,
256
+ };
257
+ const STAGE_COLORS = {
258
+ foundation: C.magenta,
259
+ infrastructure: C.cyan,
260
+ feature: C.green,
261
+ monitoring: C.yellow,
262
+ };
263
+ const STAGE_ORDER = ['foundation', 'infrastructure', 'feature', 'monitoring'];
264
+ const shortName = (p) => p.startsWith('@rudderjs/') ? p.slice('@rudderjs/'.length) : p;
265
+ const grouped = new Map();
266
+ for (const e of entries) {
267
+ const list = grouped.get(e.stage) ?? [];
268
+ list.push(shortName(e.package));
269
+ grouped.set(e.stage, list);
270
+ }
271
+ console.log(`[RudderJS] ${entries.length} provider${entries.length === 1 ? '' : 's'} booted`);
272
+ // Find which stages have entries — needed to know which one is the last
273
+ // (gets `└─` instead of `├─`).
274
+ const activeStages = STAGE_ORDER.filter(s => (grouped.get(s)?.length ?? 0) > 0);
275
+ const labelWidth = 16;
276
+ const indent = ' ';
277
+ const connector = '── '; // 3 visible chars after the corner
278
+ const cornerLen = 2 + connector.length; // ├─ + space-after width
279
+ // Wrap at min(terminal width, 80) so the layout is consistent across
280
+ // narrow and wide terminals — wide terminals would otherwise stretch a
281
+ // long feature list to one unreadable line.
282
+ const termCols = Math.min(process.stdout.columns ?? 80, 80);
283
+ const wrapWidth = termCols - indent.length - cornerLen - labelWidth - 2;
284
+ activeStages.forEach((stage, idx) => {
285
+ const list = grouped.get(stage);
286
+ const isLast = idx === activeStages.length - 1;
287
+ const corner = isLast ? '└─ ' : '├─ ';
288
+ const colorize = STAGE_COLORS[stage];
289
+ const label = colorize(stage.padEnd(labelWidth));
290
+ // Greedy line-wrap: pack as many comma-joined names as fit per line.
291
+ const lines = [[]];
292
+ let currentLen = 0;
293
+ for (const name of list) {
294
+ const piece = (lines[lines.length - 1].length === 0 ? '' : ', ') + name;
295
+ if (currentLen + piece.length > wrapWidth && lines[lines.length - 1].length > 0) {
296
+ lines.push([name]);
297
+ currentLen = name.length;
298
+ }
299
+ else {
300
+ lines[lines.length - 1].push(name);
301
+ currentLen += piece.length;
302
+ }
303
+ }
304
+ // Continuation lines use `│` to maintain the tree visual when there are
305
+ // more stages below; the last stage uses spaces instead.
306
+ const continuation = isLast
307
+ ? ' '.repeat(corner.length + labelWidth)
308
+ : C.dim('│ ') + ' '.repeat(labelWidth);
309
+ lines.forEach((parts, i) => {
310
+ const prefix = i === 0
311
+ ? `${indent}${C.dim(corner)}${label}`
312
+ : `${indent}${continuation}`;
313
+ console.log(`${prefix}${parts.join(', ')}`);
314
+ });
315
+ });
316
+ }
317
+ /** Phase 2 — create the HTTP fetch handler. Requires Vite context (virtual: URLs). */
318
+ async _createHandler() {
319
+ const mw = new MiddlewareConfigurator();
320
+ this._mwFn?.(mw);
321
+ const exc = new ExceptionConfigurator();
322
+ this._excFn?.(exc);
323
+ const errorHandler = exc.buildHandler();
324
+ const { router } = await import('@rudderjs/router');
325
+ this._handler = await this._server.createFetchHandler((adapter) => {
326
+ for (const h of mw.getHandlers())
327
+ adapter.applyMiddleware(h);
328
+ if (adapter.applyGroupMiddleware) {
329
+ for (const h of mw.getGroupHandlers('web'))
330
+ adapter.applyGroupMiddleware('web', h);
331
+ for (const h of mw.getGroupHandlers('api'))
332
+ adapter.applyGroupMiddleware('api', h);
333
+ }
334
+ router.mount(adapter);
335
+ adapter.setErrorHandler?.(errorHandler);
336
+ });
337
+ }
338
+ /** Boot providers without starting an HTTP server — used by the CLI */
339
+ async boot() {
340
+ await this._providerBoot;
341
+ }
342
+ async handleRequest(request, env, ctx) {
343
+ if (!this._boot)
344
+ this._boot = this._providerBoot.then(() => this._createHandler());
345
+ await this._boot;
346
+ if (!this._handler)
347
+ throw new Error('[RudderJS] Request handler not initialized.');
348
+ return this._handler(request, env, ctx);
349
+ }
350
+ fetch = (request, env, ctx) => this.handleRequest(request, env, ctx);
351
+ }
352
+ //# sourceMappingURL=app-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-builder.js","sour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