@basaltkit/express 1.3.0 → 1.4.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.
package/README.md CHANGED
@@ -212,6 +212,7 @@ In this mode each handler already handles its own errors (the wrapper responds w
212
212
  | Option | Type | Required? | Default | Description |
213
213
  |---|---|---|---|---|
214
214
  | `routes` | `BasaltRoute[]` | No | `[]` | Routes (created with `route()` from `@basaltkit/http`) to mount. |
215
+ | `allowUnguardedMeta` | `boolean \| string[]` | No | fail loud at boot | Waives the boot check that every route declaring security meta (`auth`, `can`, `teamRole`) has a registered guard enforcing it (`UnguardedRouteMetaError` otherwise). `true` waives everything (edge/gateway auth); an array waives specific keys. |
215
216
  | `app` | `Express` | No | new `express()` | Bring your own Express app; either way, `express.json()` is added. |
216
217
 
217
218
  Behavior: registers the Express app under the `EXPRESS` token and an `HttpServerCollector` under the `HTTP_SERVER` token. On the `app:booted` event it mounts everything in the order Express requires: *after-hooks* middleware (metrics/tracing, via `res.on('finish')`) → *pre-hooks* middleware (security/CORS/rate limit; if one of them responds, the route doesn't run) → Basalt routes → extra routes from edge plugins (`/livez`, `/metrics`, …). Publishes the routes in the `'http:routes'` metadata bucket for OpenAPI/CLI/SDK.
package/dist/index.d.ts CHANGED
@@ -6,6 +6,13 @@ export declare const EXPRESS: import("@basaltkit/core").Token<Express>;
6
6
  export declare function registerRoutes(app: Express, routes: BasaltRoute[], container?: Container, enrichers?: RequestEnricher[], guards?: RouteGuard[]): void;
7
7
  export interface ExpressPluginOptions {
8
8
  routes?: BasaltRoute[];
9
+ /**
10
+ * Waives the boot-time check that every route declaring security meta
11
+ * (`auth`, `can`, `teamRole`) has a registered guard enforcing it. Pass
12
+ * `true` to waive everything (e.g. authentication handled at an outer
13
+ * edge/gateway), or an array of specific keys. Default: fail loud at boot.
14
+ */
15
+ allowUnguardedMeta?: boolean | string[];
9
16
  /** Bring your own Express app; otherwise one is created with `express.json()`. */
10
17
  app?: Express;
11
18
  /**
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Container, createToken, definePlugin, ensureMetadata } from '@basaltkit/core';
2
- import { NOT_FOUND_RESPONSE, HttpServerCollector, HTTP_SERVER, runRoute, toErrorResponse, isSseResponse, sseProducerOf, driveSse, SSE_HEADERS, } from '@basaltkit/http';
2
+ import { NOT_FOUND_RESPONSE, HttpServerCollector, HTTP_SERVER, runRoute, toErrorResponse, isSseResponse, sseProducerOf, driveSse, SSE_HEADERS, GUARDED_META_BUCKET, assertRoutesGuarded, } from '@basaltkit/http';
3
3
  import express, {} from 'express';
4
4
  export const EXPRESS = createToken('express');
5
5
  function toNeutralRequest(req) {
@@ -112,6 +112,9 @@ export function expressPlugin(options = {}) {
112
112
  const metadata = ensureMetadata(container);
113
113
  const enrichers = metadata.get('http:enrichers');
114
114
  const guards = metadata.get('http:guards');
115
+ // Fail loud BEFORE traffic if a route declares security meta (auth/can/
116
+ // teamRole) that no registered guard enforces — it would serve open.
117
+ assertRoutesGuarded(routes, new Set(metadata.get(GUARDED_META_BUCKET)), options.allowUnguardedMeta);
115
118
  const router = app;
116
119
  // Mount everything once edge plugins have registered their hooks/routes,
117
120
  // in the order Express needs: after-hooks → pre-hooks → routes.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basaltkit/express",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Express adapter for Basalt: run the same typed routes, enrichers and guards on Express that you would on Fastify or Hono.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,8 +14,8 @@
14
14
  "dist"
15
15
  ],
16
16
  "dependencies": {
17
- "@basaltkit/core": "^1.1.2",
18
- "@basaltkit/http": "^1.10.0"
17
+ "@basaltkit/core": "^1.3.0",
18
+ "@basaltkit/http": "^1.12.0"
19
19
  },
20
20
  "peerDependencies": {
21
21
  "express": "^4.19.0 || ^5.0.0"