@basaltkit/hono 1.2.1 → 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
@@ -224,6 +224,7 @@ In this mode errors are still standardized (each handler wraps `toErrorResponse`
224
224
  | Option | Type | Required? | Default | Description |
225
225
  |---|---|---|---|---|
226
226
  | `routes` | `BasaltRoute[]` | No | `[]` | Routes (created with `route()` from `@basaltkit/http`) to mount. |
227
+ | `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. |
227
228
  | `app` | `Hono` | No | `new Hono()` | Bring your own Hono app; otherwise a new one is created. |
228
229
 
229
230
  Behavior: registers the Hono app on the `HONO` token and an `HttpServerCollector` on the `HTTP_SERVER` token. On the `app:booted` event it mounts, in order: *after-hooks* middleware (metrics/tracing, measuring duration), *pre-hooks* middleware (security/CORS/rate limit; if one of these responds, the route doesn't run), the Basalt routes, and the extra edge plugin routes (`/livez`, `/metrics`, `/openapi.json`, …). Publishes the routes to the `'http:routes'` metadata bucket for OpenAPI/CLI/SDK.
package/dist/index.d.ts CHANGED
@@ -8,8 +8,22 @@ export declare const DEFAULT_BODY_LIMIT = 1048576;
8
8
  export declare function registerRoutes(app: Hono<any>, routes: BasaltRoute[], container?: Container, enrichers?: RequestEnricher[], guards?: RouteGuard[]): void;
9
9
  export interface HonoPluginOptions {
10
10
  routes?: BasaltRoute[];
11
+ /**
12
+ * Waives the boot-time check that every route declaring security meta
13
+ * (`auth`, `can`, `teamRole`) has a registered guard enforcing it. Pass
14
+ * `true` to waive everything (e.g. authentication handled at an outer
15
+ * edge/gateway), or an array of specific keys. Default: fail loud at boot.
16
+ */
17
+ allowUnguardedMeta?: boolean | string[];
11
18
  /** Bring your own Hono app; otherwise a fresh one is created. */
12
19
  app?: Hono<any>;
20
+ /**
21
+ * Serve the neutral JSON body (`NOT_FOUND_RESPONSE` from @basaltkit/http)
22
+ * for unmatched routes, identical across all adapters, instead of Hono's
23
+ * text default. Default: true. An app calling `hono.notFound(…)` later
24
+ * still wins (Hono keeps the last handler); pass false to opt out entirely.
25
+ */
26
+ notFound?: boolean;
13
27
  /**
14
28
  * Maximum request body size in bytes. A request whose `Content-Length`
15
29
  * exceeds this is rejected with 413 before the body is read — Hono/edge has
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Container, createToken, definePlugin, ensureMetadata } from '@basaltkit/core';
2
- import { 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 { Hono } from 'hono';
4
4
  export const HONO = createToken('hono');
5
5
  /** Default maximum request body size (1 MiB) — override via honoPlugin({ bodyLimit }). */
@@ -156,6 +156,9 @@ export function honoPlugin(options = {}) {
156
156
  const metadata = ensureMetadata(container);
157
157
  const enrichers = metadata.get('http:enrichers');
158
158
  const guards = metadata.get('http:guards');
159
+ // Fail loud BEFORE traffic if a route declares security meta (auth/can/
160
+ // teamRole) that no registered guard enforces — it would serve open.
161
+ assertRoutesGuarded(routes, new Set(metadata.get(GUARDED_META_BUCKET)), options.allowUnguardedMeta);
159
162
  // Mount once edge plugins have registered their hooks/routes.
160
163
  const bodyLimit = options.bodyLimit ?? DEFAULT_BODY_LIMIT;
161
164
  hooks.on('app:booted', () => {
@@ -182,6 +185,10 @@ export function honoPlugin(options = {}) {
182
185
  return undefined;
183
186
  });
184
187
  registerRoutes(app, routes, container, enrichers, guards);
188
+ // Neutral JSON 404 (an app's own later `notFound` call replaces it).
189
+ if (options.notFound !== false) {
190
+ app.notFound((context) => context.json(NOT_FOUND_RESPONSE, 404));
191
+ }
185
192
  for (const { method, url, handler } of collector.extraRoutes) {
186
193
  app.on(method, url, async (context) => {
187
194
  const reply = new HonoReply(context);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basaltkit/hono",
3
- "version": "1.2.1",
3
+ "version": "1.4.0",
4
4
  "description": "Hono adapter for Basalt: run the same typed routes, enrichers and guards on Hono (Node, Bun, Deno, edge) as on Fastify or Express.",
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.9.1"
17
+ "@basaltkit/core": "^1.3.0",
18
+ "@basaltkit/http": "^1.12.0"
19
19
  },
20
20
  "peerDependencies": {
21
21
  "hono": "^4.0.0"