@brickkit/core 0.14.0 → 0.16.0-beta.0

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.
@@ -1,12 +1,15 @@
1
- import { $n as EventsOptions, E as Logger, En as PluginInstance, Et as DatabaseHandle, J as ValidationErrorItem, Pn as SecretSource, R as Service, Yt as InstalledPlugin, ht as EventsHub, mt as EventsDefinition, ot as SocketBroker, rt as BrickSocketSchema, t as Action, un as ServicePort, wr as HttpMethod } from "./types.js";
1
+ import { Gt as DatabaseHandle, Nn as ServicePort, O as Logger, V as Service, Vt as Sensitivity, Xr as SecretSource, Z as ValidationErrorItem, _t as EventsDefinition, jt as DashboardUser, lt as SocketBroker, mn as InstalledPlugin, ot as BrickSocketSchema, ri as HttpMethod, t as Action, tr as PluginInstance, vt as EventsHub, wt as ClientIp, yr as EventsOptions } from "./types.js";
2
2
  import { Elysia } from "elysia";
3
3
  type RouteMethod = HttpMethod;
4
+ /** How a string from a query or form field becomes the schema's type; objects travel as JSON. */
5
+ type Coercion = "number" | "boolean" | "array" | "json";
4
6
  interface RouteIR {
5
7
  readonly method: RouteMethod;
6
8
  readonly path: string;
7
9
  readonly service: string;
8
10
  readonly action: string;
9
- readonly kind: "action";
11
+ /** A `webhook` has a verified raw body; see `service.webhook`. */
12
+ readonly kind: "action" | "webhook";
10
13
  /** The plugin that registered the action, if one did. */
11
14
  readonly plugin?: string;
12
15
  readonly input: boolean;
@@ -19,8 +22,12 @@ interface RouteIR {
19
22
  readonly inputSource: "query" | "body";
20
23
  readonly coercions: readonly {
21
24
  readonly key: string;
22
- readonly type: "number" | "boolean" | "array";
25
+ readonly type: Coercion;
26
+ /** How each item of an `array` field is coerced. */
27
+ readonly items?: Exclude<Coercion, "array">;
23
28
  }[];
29
+ /** The most bytes a body may have: multipart bodies with `t.File` fields (by `Content-Length`), and a webhook's (counted as read). */
30
+ readonly bodyLimit?: number;
24
31
  /** JSON projection for inspection and stale-artifact detection, not runtime validation. */
25
32
  readonly inputSchema?: unknown;
26
33
  readonly outputSchema?: unknown;
@@ -107,11 +114,20 @@ interface DashboardAuth {
107
114
  * `Response` to send instead, such as a redirect to your login page. If it
108
115
  * throws or takes longer than five seconds, the request is refused with 503.
109
116
  *
117
+ * Return `{ user: { id, name } }` to let it in and say who it is: requests
118
+ * the dashboard's pages send to the app through `/app/*` carry that user,
119
+ * signed, which the app reads with `ctx.dashboard?.user` in an action or
120
+ * `dashboardUser(request)` in an endpoint.
121
+ *
110
122
  * A request is let in when it carries a valid `token`, or when this
111
123
  * returns `true`; give both to let monitors in by token and people in by
112
124
  * sign-in.
113
125
  */
114
- authorize?: (request: Request) => boolean | Response | Promise<boolean | Response>;
126
+ authorize?: (request: Request) => boolean | Response | {
127
+ user: DashboardUser;
128
+ } | Promise<boolean | Response | {
129
+ user: DashboardUser;
130
+ }>;
115
131
  }
116
132
  /**
117
133
  * The monitoring dashboard `brick start` serves beside the app, on a port of
@@ -249,6 +265,7 @@ interface CompiledRoutePlan {
249
265
  readonly contextHook?: (baseCtx: any) => unknown;
250
266
  readonly inputChecker?: Checker;
251
267
  readonly outputChecker?: Checker;
268
+ readonly sensitive?: Sensitivity;
252
269
  /** A plugin's check that runs before `inputChecker`. */
253
270
  readonly checkInput?: (input: unknown) => ValidationErrorItem[] | undefined;
254
271
  readonly errorBuilder: unknown;
@@ -394,12 +411,6 @@ interface CreateServerOptions {
394
411
  broker?: SocketBroker;
395
412
  secret?: string;
396
413
  };
397
- /**
398
- * The values of the services' declared `deps` (`port<T>()`), by name. Every
399
- * declared dep must be provided, and every provided one declared. Actions read
400
- * them as `ctx.deps`, listeners and workflow steps with `useDeps()`.
401
- */
402
- deps?: Record<string, unknown>;
403
414
  /**
404
415
  * App-wide plugins from `definePlugin`, in install order: their `app` part
405
416
  * adds start/stop lifecycle, middleware and listeners. Plugins installed with
@@ -413,6 +424,15 @@ interface CreateServerOptions {
413
424
  * Other origins get no `Access-Control-Allow-Origin`. Preflights are answered.
414
425
  */
415
426
  cors?: false | CorsOptions;
427
+ /**
428
+ * Where the client address is, for `rateLimit: { per: "ip" }`. By default it
429
+ * is the socket peer; behind a proxy, read the header your proxy sets. Brick
430
+ * never reads `X-Forwarded-For` or any other header itself.
431
+ *
432
+ * @example
433
+ * clientIp: ({ request, peer }) => request.headers.get("fly-client-ip") ?? peer,
434
+ */
435
+ clientIp?: ClientIp;
416
436
  }
417
437
  /**
418
438
  * Create the HTTP application: an Elysia app that serves every service's
@@ -428,11 +448,11 @@ interface CreateServerOptions {
428
448
  * @param options - `prefix` for action routes (default `/api`), `services`,
429
449
  * `title`, `version`, and `description` for the OpenAPI document, `docs` and the
430
450
  * paths of its pages, `requestLogging`, `reference`, `endpoints`, `secrets`,
431
- * `telemetry`, `documentation`, `dashboard`, and `deps`. See `CreateServerOptions`.
451
+ * `telemetry`, `documentation`, and `dashboard`. See `CreateServerOptions`.
432
452
  * @returns The app, with `definition` (its services, prefix, and routes),
433
453
  * `endpoint()` to add raw routes, and `listEndpoints()` to list them.
434
454
  * @throws When a required secret is missing, `documentation` or `dashboard`
435
- * is invalid, or `deps` misses a dep a service declares or has one none declares.
455
+ * is invalid, or `deps` is passed (it moved to `defineService({ deps })`).
436
456
  * @example
437
457
  * import { brick } from "@brickkit/core";
438
458
  * import { pagesService } from "./services/pages";
@@ -444,5 +464,4 @@ interface CreateServerOptions {
444
464
  * });
445
465
  */
446
466
  declare function brick(options?: CreateServerOptions): BrickApp;
447
- export { scalarDocsHTML as A, ApiDocument as C, ReferenceOptions as D, ReferenceDocument as E, RouteIR as M, RouteMethod as N, referencePlugin as O, DashboardOptions as S, OpenApiDocument as T, EndpointContext as _, RequestLoggingOptions as a, EndpointMethod as b, CompiledRoute as c, loadCompiledBrickApp as d, CompiledHandler as f, BrickApp as g, deny as h, CorsOrigin as i, BrickIR as j, registerReferenceRoute as k, bindCompiledApplication as l, HandlerFactory as m, brick as n, requestLoggingPlugin as o, CompiledRoutePlan as p, CorsOptions as r, CompiledApplication as s, CreateServerOptions as t, compileBrickApplication as u, EndpointDefinition as v, DocumentationOptions as w, DashboardAuth as x, EndpointLogger as y };
448
- //# sourceMappingURL=server.d.ts.map
467
+ export { scalarDocsHTML as A, ApiDocument as C, ReferenceOptions as D, ReferenceDocument as E, RouteIR as M, RouteMethod as N, referencePlugin as O, DashboardOptions as S, OpenApiDocument as T, EndpointContext as _, RequestLoggingOptions as a, EndpointMethod as b, CompiledRoute as c, loadCompiledBrickApp as d, CompiledHandler as f, BrickApp as g, deny as h, CorsOrigin as i, BrickIR as j, registerReferenceRoute as k, bindCompiledApplication as l, HandlerFactory as m, brick as n, requestLoggingPlugin as o, CompiledRoutePlan as p, CorsOptions as r, CompiledApplication as s, CreateServerOptions as t, compileBrickApplication as u, EndpointDefinition as v, DocumentationOptions as w, DashboardAuth as x, EndpointLogger as y };