@guren/server 2.13.0 → 2.15.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/dist/{Hash-CzrwKeDp.js → Hash-C8aejmi8.js} +5 -0
- package/dist/{McpServiceProvider-D6D9nhgn.js → McpServiceProvider-BawsYjgN.js} +72 -0
- package/dist/agent/AgentApprovalRequested.d.ts +59 -0
- package/dist/agent/approval.d.ts +295 -0
- package/dist/agent/audit-emitter.d.ts +64 -0
- package/dist/agent/audit.d.ts +103 -0
- package/dist/agent/derive.d.ts +155 -0
- package/dist/agent/dispatch.d.ts +165 -0
- package/dist/agent/events.d.ts +80 -0
- package/dist/agent/meta-tools.d.ts +62 -0
- package/dist/agent/public.d.ts +33 -0
- package/dist/agent/public.js +2 -0
- package/dist/agent/redact.d.ts +55 -0
- package/dist/agent/scopes.d.ts +115 -0
- package/dist/auth/AuthManager.d.ts +64 -0
- package/dist/auth/RequestAuthContext.d.ts +3 -5
- package/dist/auth/TokenGuard.d.ts +61 -0
- package/dist/auth/api-token.d.ts +25 -5
- package/dist/auth/context.d.ts +24 -0
- package/dist/auth/index.d.ts +5 -2
- package/dist/auth/index.js +2 -2
- package/dist/auth/password/DefaultHasher.d.ts +18 -5
- package/dist/auth/password/PasswordHasher.d.ts +15 -0
- package/dist/auth/password/hash-format.d.ts +19 -0
- package/dist/auth/providers/UserProvider.d.ts +7 -0
- package/dist/auth/types.d.ts +6 -0
- package/dist/{auth-C7sVmYgc.js → auth-DkYoAPVn.js} +431 -151
- package/dist/authorization/index.js +1 -1
- package/dist/authorization/middleware.d.ts +28 -1
- package/dist/{authorization-Dbcuc5ZK.js → authorization-CdfbCj8J.js} +119 -12
- package/dist/broadcasting/index.js +1 -1
- package/dist/{broadcasting-Dw-FhyjN.js → broadcasting-BwodCA4q.js} +2 -45
- package/dist/container/bindings.d.ts +19 -0
- package/dist/context-DoD0c7J_.js +26 -0
- package/dist/dispatch-erOS9epZ.js +285 -0
- package/dist/encryption/index.js +2 -2
- package/dist/{encryption-DJtkkhiw.js → encryption-D99Vmls3.js} +4 -1
- package/dist/http/dev-assets.d.ts +16 -0
- package/dist/http/middleware/auth.d.ts +2 -2
- package/dist/http/middleware/capabilities.d.ts +57 -0
- package/dist/http/middleware/csrf.d.ts +3 -0
- package/dist/http/public-assets.d.ts +10 -0
- package/dist/http/request.d.ts +139 -3
- package/dist/http/static-documents.d.ts +31 -0
- package/dist/index.d.ts +21 -4
- package/dist/index.js +1302 -118
- package/dist/internal/agent-preflight.d.ts +28 -0
- package/dist/internal/request.d.ts +25 -0
- package/dist/internal/request.js +2 -0
- package/dist/internal/route-path.d.ts +28 -0
- package/dist/internal/route-path.js +33 -0
- package/dist/internal/zod-compat.d.ts +201 -0
- package/dist/internal/zod-compat.js +193 -0
- package/dist/internal/zod-json-schema.d.ts +102 -0
- package/dist/internal/zod-json-schema.js +461 -0
- package/dist/logging/channels/DailyFileChannel.d.ts +0 -2
- package/dist/logging/daily-file-path.d.ts +24 -0
- package/dist/logging/index.d.ts +1 -0
- package/dist/logging/index.js +2 -2
- package/dist/{logging-CPaRMuPP.js → logging-B-kngi3q.js} +61 -18
- package/dist/mcp/create-mcp-server.d.ts +29 -0
- package/dist/mcp/index.js +1 -1
- package/dist/mvc/Controller.d.ts +20 -0
- package/dist/mvc/Router.d.ts +53 -0
- package/dist/request-CVQwpu2J.js +129 -0
- package/dist/runtime/index.js +94 -15
- package/dist/{vite-manifest-gdONBsM3.js → vite-manifest-w_RSOvQW.js} +1 -1
- package/package.json +22 -2
|
@@ -218,11 +218,14 @@ const PURPOSE = "signed-url";
|
|
|
218
218
|
const SIGNATURE_PARAM = "signature";
|
|
219
219
|
const EXPIRES_PARAM = "expires";
|
|
220
220
|
const RELATIVE_BASE = "https://relative.invalid";
|
|
221
|
+
const RELATIVE_ORIGIN = new URL(RELATIVE_BASE).origin;
|
|
221
222
|
const EXPIRES_SHAPE = /^[0-9]{1,15}$/;
|
|
222
223
|
function parseUrl(value) {
|
|
223
224
|
const relative = value.startsWith("/");
|
|
225
|
+
const url = relative ? new URL(value, RELATIVE_BASE) : new URL(value);
|
|
226
|
+
if (relative && (url.origin !== RELATIVE_ORIGIN || url.pathname.startsWith("//"))) throw new TypeError(`signed-url: an app-relative URL must not begin with an authority, got ${value}`);
|
|
224
227
|
return {
|
|
225
|
-
url
|
|
228
|
+
url,
|
|
226
229
|
relative
|
|
227
230
|
};
|
|
228
231
|
}
|
|
@@ -41,6 +41,22 @@ export interface DevAssetsOptions {
|
|
|
41
41
|
favicon?: boolean;
|
|
42
42
|
/** Serve selected files from the public directory without the `/public` prefix. */
|
|
43
43
|
rootPublicAssets?: RootPublicAssetsConfig;
|
|
44
|
+
/**
|
|
45
|
+
* Serve document types (`.svg`, `.html`, XML) from `/public/*` and
|
|
46
|
+
* `/resources/css/*` inline instead of forcing them to download. Defaults to
|
|
47
|
+
* false.
|
|
48
|
+
*
|
|
49
|
+
* Off by default because `public/` is also where an app's uploads land, and
|
|
50
|
+
* a stored `.html` or `.svg` served inline is script in the app's own
|
|
51
|
+
* origin. Turn it on for a public directory holding nothing user-supplied —
|
|
52
|
+
* a static microsite under `public/docs/index.html`, say, which Hono resolves
|
|
53
|
+
* from a directory request and would otherwise hand back as a download.
|
|
54
|
+
*
|
|
55
|
+
* The root-level allowlist route has its own switch,
|
|
56
|
+
* `rootPublicAssets: { inlineDocuments: true }`; an app serving documents
|
|
57
|
+
* both ways sets both.
|
|
58
|
+
*/
|
|
59
|
+
inlineDocuments?: boolean;
|
|
44
60
|
}
|
|
45
61
|
/**
|
|
46
62
|
* Absolute path to `@guren/inertia-client`'s build output, the directory
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { Context, MiddlewareHandler } from 'hono';
|
|
2
2
|
import type { AuthContext } from '../../auth/types.js';
|
|
3
|
+
import { AUTH_CONTEXT_KEY, getAuthContext } from '../../auth/context.js';
|
|
3
4
|
export type { AuthContext } from '../../auth/types.js';
|
|
4
5
|
export interface RequireAuthOptions {
|
|
5
6
|
redirectTo?: string;
|
|
6
7
|
status?: number;
|
|
7
8
|
responseFactory?: () => Response;
|
|
8
9
|
}
|
|
9
|
-
declare const AUTH_CONTEXT_KEY = "guren:auth";
|
|
10
10
|
export declare function attachAuthContext(contextFactory: (ctx: Context) => AuthContext): MiddlewareHandler;
|
|
11
11
|
export declare function requireAuthenticated(options?: RequireAuthOptions): MiddlewareHandler;
|
|
12
12
|
export declare function requireGuest(options?: RequireAuthOptions): MiddlewareHandler;
|
|
13
|
-
export { AUTH_CONTEXT_KEY };
|
|
13
|
+
export { AUTH_CONTEXT_KEY, getAuthContext };
|
|
@@ -14,9 +14,66 @@ import type { MiddlewareHandler } from 'hono';
|
|
|
14
14
|
*/
|
|
15
15
|
export declare const CAPABILITIES: unique symbol;
|
|
16
16
|
export interface MiddlewareCapabilities {
|
|
17
|
+
/**
|
|
18
|
+
* Authentication enforced by the chain. `'required'` beats `'guest-only'`
|
|
19
|
+
* when a chain somehow carries both.
|
|
20
|
+
*/
|
|
17
21
|
authentication?: {
|
|
18
22
|
mode: 'required' | 'guest-only';
|
|
19
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Authorization enforced by the chain (RFC 0016 §4): what makes
|
|
26
|
+
* route → ability derivable without reading controller bodies.
|
|
27
|
+
*
|
|
28
|
+
* - `abilities` — the ability names checked, in the order the chain
|
|
29
|
+
* checks them. Empty when every check derives its ability at request
|
|
30
|
+
* time (see `resource`), and also for the degenerate
|
|
31
|
+
* `authorizeMiddleware([])`, which denies every request.
|
|
32
|
+
* - `mode` — how they combine. `'all'` every listed ability must pass,
|
|
33
|
+
* `'any'` at least one must. A list of exactly one normalizes to
|
|
34
|
+
* `'all'`, because any-of one ability *is* that ability — and the
|
|
35
|
+
* middleware treats it that way at runtime too, down to the denial
|
|
36
|
+
* message. So `'any'` means either two or more alternatives, or the
|
|
37
|
+
* degenerate empty list that denies every request. `'mixed'` means the
|
|
38
|
+
* chain carries more than one check and the conjunction of them is not
|
|
39
|
+
* expressible as either: authorization is present, but the ability is
|
|
40
|
+
* *not* cleanly derivable, and a consumer must treat it as undetermined
|
|
41
|
+
* rather than picking a name out of `abilities`. A single derivable
|
|
42
|
+
* ability is `abilities.length === 1` with `mode: 'all'` and no
|
|
43
|
+
* `resource`.
|
|
44
|
+
* - `resource` — present when a check resolves its ability from the
|
|
45
|
+
* request method (`authorizeResourceMiddleware`). `fromMethodMap: true`
|
|
46
|
+
* means the built-in verb map decides, so a consumer holding the
|
|
47
|
+
* route's method resolves the ability through
|
|
48
|
+
* `resourceAbilityForMethod()` in `../../authorization/middleware`.
|
|
49
|
+
* `false` means an `abilityFor` callback overrides that map and the
|
|
50
|
+
* real ability is unknowable statically — fail closed, do not fall
|
|
51
|
+
* back to the verb map.
|
|
52
|
+
*/
|
|
53
|
+
authorization?: {
|
|
54
|
+
abilities: string[];
|
|
55
|
+
mode: 'all' | 'any' | 'mixed';
|
|
56
|
+
resource?: {
|
|
57
|
+
fromMethodMap: boolean;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
20
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Fold one middleware's stamp into an accumulating aggregate, applying the
|
|
63
|
+
* rules the type above states: `'required'` beats `'guest-only'`; abilities
|
|
64
|
+
* union; two checks are a conjunction, so all-of + all-of stays `'all'` and
|
|
65
|
+
* anything else becomes `'mixed'`; `fromMethodMap` ANDs, since one
|
|
66
|
+
* non-authoritative check makes the verb map unusable for the whole chain.
|
|
67
|
+
*
|
|
68
|
+
* Mutates `into` and never `stamp` — nested objects and arrays are copied
|
|
69
|
+
* the first time they are taken, so a later merge cannot write back through
|
|
70
|
+
* the aggregate into a handler's stamp.
|
|
71
|
+
*
|
|
72
|
+
* Every call counts as an independent check. Folding the *same* stamp twice
|
|
73
|
+
* would read as two of them and degrade an `'any'` to `'mixed'`, so
|
|
74
|
+
* de-duplicating handlers that appear more than once in a chain is the
|
|
75
|
+
* caller's job.
|
|
76
|
+
*/
|
|
77
|
+
export declare function mergeCapabilities(into: MiddlewareCapabilities, stamp: MiddlewareCapabilities): void;
|
|
21
78
|
export declare function stampCapabilities(handler: MiddlewareHandler, capabilities: MiddlewareCapabilities): MiddlewareHandler;
|
|
22
79
|
export declare function capabilitiesOf(handler: unknown): MiddlewareCapabilities | undefined;
|
|
@@ -94,6 +94,9 @@ export declare function verifyCsrfToken(ctx: Context, token: string | undefined)
|
|
|
94
94
|
* those sessions expire
|
|
95
95
|
* - Exempts the dev-only MCP endpoint while it is mounted, since agent
|
|
96
96
|
* clients cannot fetch a token first (it guards local-only access instead)
|
|
97
|
+
* - Skips verification for `Authorization: Bearer` requests that carry no
|
|
98
|
+
* cookies (RFC 0016) — token clients authenticate per request and hold no
|
|
99
|
+
* cookie ambient authority for CSRF to defend
|
|
97
100
|
*
|
|
98
101
|
* `cookie: false` disables the `XSRF-TOKEN` cookie for apps that deliver the
|
|
99
102
|
* token themselves (meta tag / form field). Session-bound tokens still
|
|
@@ -11,5 +11,15 @@ export interface RootPublicAssetsOptions {
|
|
|
11
11
|
routePrefix?: string;
|
|
12
12
|
/** Override content types per extension. */
|
|
13
13
|
contentTypeMap?: Record<string, string>;
|
|
14
|
+
/**
|
|
15
|
+
* Serve document types (`.svg`, `.html`, XML) inline instead of forcing them
|
|
16
|
+
* to download. Defaults to false.
|
|
17
|
+
*
|
|
18
|
+
* The default exists because this directory is also where an app's uploads
|
|
19
|
+
* land — `.svg` is in the default extension list, and an SVG navigated to
|
|
20
|
+
* directly is script in the app's own origin. Turn it on only for a
|
|
21
|
+
* directory holding nothing user-supplied.
|
|
22
|
+
*/
|
|
23
|
+
inlineDocuments?: boolean;
|
|
14
24
|
}
|
|
15
25
|
export declare function registerRootPublicAssets(app: Application, publicDir: string, config?: RootPublicAssetsConfig): void;
|
package/dist/http/request.d.ts
CHANGED
|
@@ -1,16 +1,152 @@
|
|
|
1
|
+
import type { HonoRequest } from 'hono';
|
|
1
2
|
import type { Context } from './Application.js';
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
4
|
+
* What {@link parseRequestBody} actually reads: three members off `ctx.req`,
|
|
5
|
+
* not a whole Hono context.
|
|
6
|
+
*
|
|
7
|
+
* Declared structurally because the difference is load bearing. `parseBody` is
|
|
8
|
+
* optional here, which is what makes the `typeof` guard below meaningful — a
|
|
9
|
+
* real `Context` always carries one, so against `Context` that guard reads as
|
|
10
|
+
* dead code. It is not: `@guren/testing`'s controller mock reaches this parser
|
|
11
|
+
* through a `HonoRequest` built from a plain `Request`, and this is the
|
|
12
|
+
* declaration that lets it do so without casting its way past the signature.
|
|
13
|
+
*
|
|
14
|
+
* Narrowing a parameter accepts strictly more callers, so every existing one —
|
|
15
|
+
* `Router`, `Controller`, the validation middleware, `FormRequest`,
|
|
16
|
+
* `BroadcastManager` — keeps passing a real `Context` unchanged.
|
|
17
|
+
*/
|
|
18
|
+
export interface RequestBodyContext {
|
|
19
|
+
req: Pick<HonoRequest, 'header' | 'json'> & Partial<Pick<HonoRequest, 'parseBody'>>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Parses the incoming request body and returns the parsed value as-is: a JSON
|
|
23
|
+
* array stays an array, a JSON string stays a string. Use this wherever the
|
|
24
|
+
* result is handed to a schema and *that* decides the shape — a route
|
|
25
|
+
* contract's `body`, `Controller.validateBody()`, `validateRequest()`.
|
|
26
|
+
*
|
|
27
|
+
* Falls back to an empty object when the body cannot be parsed (malformed
|
|
28
|
+
* JSON, a form body the parser cannot decode, an empty POST, an unsupported
|
|
29
|
+
* content type). That fallback is load bearing: an all-optional object schema
|
|
30
|
+
* has to keep passing on an empty body, which `undefined` would break. The
|
|
31
|
+
* cost is that a non-object schema sees `{}` there and fails validation,
|
|
32
|
+
* rather than receiving nothing.
|
|
33
|
+
*
|
|
34
|
+
* The fallback does not distinguish whose fault the failure was: a body the
|
|
35
|
+
* client could never have sent correctly and a body already consumed upstream
|
|
36
|
+
* (middleware reading `ctx.req.raw` directly, bypassing Hono's cache) both read
|
|
37
|
+
* as `{}` here. That is deliberate — the JSON branch above has always behaved
|
|
38
|
+
* this way, and telling the two apart means matching runtime-specific error
|
|
39
|
+
* codes, which would answer differently on Bun, Node and Workers. A parser
|
|
40
|
+
* error is a poor signal for a middleware-ordering bug either way.
|
|
41
|
+
*
|
|
42
|
+
* Form submissions have no non-object shape to preserve, so they normalize to
|
|
43
|
+
* a record exactly as {@link parseRequestPayload} does.
|
|
44
|
+
*/
|
|
45
|
+
export declare function parseRequestBody(ctx: RequestBodyContext): Promise<unknown>;
|
|
46
|
+
/**
|
|
47
|
+
* What {@link parseRequestUploads} reads: one member off `ctx.req`, not a whole
|
|
48
|
+
* Hono context — the same narrowing, and for the same caller, as
|
|
49
|
+
* {@link RequestBodyContext}.
|
|
50
|
+
*
|
|
51
|
+
* `parseBody` is required here where the body parser makes it optional. That
|
|
52
|
+
* parser has a fallback for a context without one; this has none, because
|
|
53
|
+
* there is no second way to read an upload. A caller that cannot supply
|
|
54
|
+
* `parseBody` should fail to compile rather than silently answer "no files".
|
|
55
|
+
*/
|
|
56
|
+
export interface RequestUploadsContext {
|
|
57
|
+
req: Pick<HonoRequest, 'parseBody'>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The shape an upload read answers with: Hono's `{ all: true }` record, where a
|
|
61
|
+
* field repeated in the body is an array and a single one is not.
|
|
62
|
+
*/
|
|
63
|
+
export type RequestUploads = Record<string, string | File | (string | File)[]>;
|
|
64
|
+
/**
|
|
65
|
+
* The one multipart read behind `Controller.file()` and `Controller.files()`,
|
|
66
|
+
* guarded so a body the parser cannot decode carries no files rather than
|
|
67
|
+
* crashing the request: it reads as `{}`, which is the same answer both helpers
|
|
68
|
+
* already give for a field that is simply absent — `null` and `[]`. Left to
|
|
69
|
+
* throw, the parser's `TypeError` escaped as a 500 reporting the exception and
|
|
70
|
+
* a stack, the defect {@link parseRequestBody} fixes for the validation paths.
|
|
71
|
+
*
|
|
72
|
+
* Deliberately *not* routed through {@link parseRequestBody}, which looks like
|
|
73
|
+
* the same rule and is not: it parses without `{ all: true }` and flattens a
|
|
74
|
+
* repeated field to its first value, so sharing it would silently reduce
|
|
75
|
+
* `files()` to one file per field. `{ all: true }` is the contract here, and a
|
|
76
|
+
* malformed-body test cannot see its loss — hence the separate function.
|
|
77
|
+
*
|
|
78
|
+
* There is no media-type gate, deliberately: Hono decides the media type inside
|
|
79
|
+
* `parseBody()`, having lowercased it first. A caller that gates before calling
|
|
80
|
+
* — or that reads uploads through `Request.formData()`, whose handling of the
|
|
81
|
+
* media type is not Hono's — answers `null` for an uppercase
|
|
82
|
+
* `MULTIPART/FORM-DATA` body this returns the file for.
|
|
83
|
+
*
|
|
84
|
+
* That was measured on Bun 1.3.14, and the host half of it has already moved:
|
|
85
|
+
* Bun 1.4.0 accepts the same header `1.3.14` rejects, and Node always did. The
|
|
86
|
+
* divergence is therefore a property of *where the media type is decided*, not
|
|
87
|
+
* of any one runtime — which is the argument for deciding it in one place, and
|
|
88
|
+
* why `@guren/testing`'s controller mock reaches this function rather than
|
|
89
|
+
* restating it.
|
|
90
|
+
*
|
|
91
|
+
* try/catch rather than `.catch()`, for the reason given on the shared
|
|
92
|
+
* fallback: `parseBody` may throw synchronously as well as reject, and only one
|
|
93
|
+
* of those two shapes reaches a `.catch()`.
|
|
94
|
+
*
|
|
95
|
+
* It fails open in one direction, deliberately and for the same reason
|
|
96
|
+
* {@link parseRequestBody} does: a body already consumed upstream reads as
|
|
97
|
+
* "no upload" rather than throwing, so a middleware-ordering bug loses the 500
|
|
98
|
+
* that used to announce it. Telling that apart from a client's malformed body
|
|
99
|
+
* means matching runtime-specific error codes, which answer differently on Bun,
|
|
100
|
+
* Node and Workers.
|
|
101
|
+
*/
|
|
102
|
+
export declare function parseRequestUploads(ctx: RequestUploadsContext): Promise<RequestUploads>;
|
|
103
|
+
/**
|
|
104
|
+
* The record-shaped view of {@link parseRequestBody}, for callers that read the
|
|
105
|
+
* payload field by field (`payload.channel`, per-field validation rules,
|
|
106
|
+
* `Controller.input()`/`only()`/`except()`/`has()`). A body that is not a plain
|
|
107
|
+
* object — an array, a string, `null` — becomes `{}`, because there is no
|
|
108
|
+
* field to read on one.
|
|
5
109
|
*/
|
|
6
110
|
export declare function parseRequestPayload(ctx: Context): Promise<Record<string, unknown>>;
|
|
111
|
+
/** Narrow a parsed body to the record view described on {@link parseRequestPayload}. */
|
|
112
|
+
export declare function asRecord(body: unknown): Record<string, unknown>;
|
|
113
|
+
/**
|
|
114
|
+
* What {@link flattenRequestQueries} actually reads: one no-arg `queries()` off
|
|
115
|
+
* `ctx.req`, not a whole Hono context.
|
|
116
|
+
*
|
|
117
|
+
* Spelled as the call shape rather than as `Pick<HonoRequest, 'queries'>` — the
|
|
118
|
+
* one place this departs from {@link RequestBodyContext} above, and not by
|
|
119
|
+
* preference. `HonoRequest.queries` is *overloaded* (`queries(key)` returning
|
|
120
|
+
* `string[] | undefined`, `queries()` returning the record), and a `Pick` keeps
|
|
121
|
+
* both signatures, so the plain `() => Record<string, string[]>` that
|
|
122
|
+
* `@guren/testing`'s `ControllerContext` declares cannot satisfy it. Naming the
|
|
123
|
+
* one signature this function calls admits both: an overloaded member is
|
|
124
|
+
* assignable to any of its own signatures, so a real `HonoRequest` still passes.
|
|
125
|
+
*
|
|
126
|
+
* Narrowing a parameter accepts strictly more callers, so every existing one
|
|
127
|
+
* keeps passing a real `Context` unchanged.
|
|
128
|
+
*/
|
|
129
|
+
export interface RequestQueryContext {
|
|
130
|
+
req: {
|
|
131
|
+
queries(): Record<string, string[]>;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
7
134
|
/**
|
|
8
135
|
* Collects query parameters preserving repeated keys as arrays while keeping
|
|
9
136
|
* single occurrences as plain strings (`?tag=a&tag=b` → `{ tag: ['a', 'b'] }`,
|
|
10
137
|
* `?page=2` → `{ page: '2' }`). Use this instead of `ctx.req.query()` when
|
|
11
138
|
* feeding query data into validation schemas.
|
|
139
|
+
*
|
|
140
|
+
* Materialized with `Object.fromEntries`, never by assigning into an object
|
|
141
|
+
* literal — the same rule, and for the same reason, as the form branch of
|
|
142
|
+
* {@link parseRequestBody} above. Query keys are attacker-controlled, and
|
|
143
|
+
* `flat['__proto__'] = …` hits `Object.prototype`'s inherited setter instead
|
|
144
|
+
* of defining a field: `?__proto__=one` silently vanished before reaching the
|
|
145
|
+
* schema, and `?__proto__=one&__proto__=two` set the returned record's own
|
|
146
|
+
* prototype to that array. Hono hands over a null-prototype object, so the
|
|
147
|
+
* key arrives here intact; only this last step could lose it.
|
|
12
148
|
*/
|
|
13
|
-
export declare function flattenRequestQueries(ctx:
|
|
149
|
+
export declare function flattenRequestQueries(ctx: RequestQueryContext): Record<string, unknown>;
|
|
14
150
|
export interface ValidationIssueLike {
|
|
15
151
|
path: PropertyKey[];
|
|
16
152
|
message: string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
/**
|
|
3
|
+
* Judged on the media type alone. Both inputs this module reads are
|
|
4
|
+
* parameterised — Hono's `getMimeType` returns `text/html; charset=utf-8`, and
|
|
5
|
+
* so does a hand-written `contentTypeMap` entry — so comparing the header
|
|
6
|
+
* verbatim is precisely how the check stops matching while still looking
|
|
7
|
+
* present.
|
|
8
|
+
*/
|
|
9
|
+
export declare function rendersAsDocument(contentType: string | undefined | null): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Neutralizes a served document by turning it into a download.
|
|
12
|
+
*
|
|
13
|
+
* `Content-Disposition: attachment` is honoured for navigations and ignored
|
|
14
|
+
* for subresource loads, which is what makes it usable on a general asset
|
|
15
|
+
* route: `<img src="/logo.svg">`, `<link rel="icon">` and CSS `url()` keep
|
|
16
|
+
* working unchanged, while `/logo.svg` opened directly is downloaded instead
|
|
17
|
+
* of rendered. An `<iframe>` or `<object>` *is* a navigation, so an SVG or
|
|
18
|
+
* HTML page embedded that way stops rendering — which is the same mechanism
|
|
19
|
+
* as the fix, not an exception to it. `nosniff` rides along for the types a
|
|
20
|
+
* browser would otherwise promote on its own.
|
|
21
|
+
*/
|
|
22
|
+
export declare function applyDocumentDisposition(headers: Headers, contentType: string | undefined | null): void;
|
|
23
|
+
/**
|
|
24
|
+
* The {@link import('hono/bun').serveStatic} form of
|
|
25
|
+
* {@link applyDocumentDisposition}, for use as its `onFound` hook.
|
|
26
|
+
*
|
|
27
|
+
* Keyed on the same `getMimeType(path)` the middleware itself used a line
|
|
28
|
+
* earlier to set `Content-Type`, rather than on the extension: the two agree
|
|
29
|
+
* by construction only while they read the same function.
|
|
30
|
+
*/
|
|
31
|
+
export declare function guardStaticDocument(path: string, ctx: Context): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,24 @@ export type { FC, PropsWithChildren } from 'hono/jsx';
|
|
|
9
9
|
export { viteAsset } from './http/vite-assets.js';
|
|
10
10
|
export type { ViteAssetOptions } from './http/vite-assets.js';
|
|
11
11
|
export { Router } from './mvc/Router.js';
|
|
12
|
-
export type { BindableModel, RouteBuilder, RouteContractOptions, RouteDefinition, RouteMiddlewareInput, RouteModelBinding, RouteOpenApiMetadata, ResourceAction as RouteResourceAction, ResourceResponseHint, ResourceResponseShape, ResourceRouteOptions, } from './mvc/Router.js';
|
|
12
|
+
export type { BindableModel, AgentRouteMetadata, RouteBuilder, RouteContractOptions, RouteDefinition, RouteMiddlewareInput, RouteModelBinding, RouteOpenApiMetadata, ResourceAction as RouteResourceAction, ResourceResponseHint, ResourceResponseShape, ResourceRouteOptions, } from './mvc/Router.js';
|
|
13
|
+
export { deriveAgentTools } from './agent/derive.js';
|
|
14
|
+
export type { AgentToolInputSource, AgentToolSchema, DeriveAgentToolsResult, DerivedAgentTool, DerivedAgentToolAnnotations, DerivedAgentToolExposure, } from './agent/derive.js';
|
|
15
|
+
export { advertisesStructuredOutput, buildToolRequest, describeBuildFailure, mapToolResponse, PREFLIGHT_ARGUMENT, } from './agent/dispatch.js';
|
|
16
|
+
export type { BuildToolRequestOptions, BuiltToolRequest, ToolCallOutcome, ToolRequestBuildFailure, } from './agent/dispatch.js';
|
|
17
|
+
export { APPROVAL_STATUS_TOOL_NAME, isReservedAgentToolName, PREFLIGHT_TOOL_NAME, RESERVED_AGENT_TOOL_NAMES, } from './agent/meta-tools.js';
|
|
18
|
+
export { AGENT_TOOL_NAME_PATTERN, expandToolScopes, parseToolScope, scopesAllowTool, } from './agent/scopes.js';
|
|
19
|
+
export type { ParsedToolScope, ScopedTool } from './agent/scopes.js';
|
|
20
|
+
export { AgentToolDenied, AgentToolInvoked } from './agent/events.js';
|
|
21
|
+
export type { AgentPrincipal, AgentSurface, AgentToolDenialReason } from './agent/events.js';
|
|
22
|
+
export { AGENT_REDACTED, redactAgentArguments } from './agent/redact.js';
|
|
23
|
+
export { DEFAULT_AGENT_AUDIT_PATH, parseAuditRecord, toAuditRecord } from './agent/audit.js';
|
|
24
|
+
export type { AgentAuditDeniedRecord, AgentAuditInvokedRecord, AgentAuditRecord, } from './agent/audit.js';
|
|
25
|
+
export { AGENT_AUDIT_BINDING, createAuditEmitter } from './agent/audit-emitter.js';
|
|
26
|
+
export type { AgentAuditEmitter, AgentAuditSink } from './agent/audit-emitter.js';
|
|
27
|
+
export { AGENT_APPROVAL_CONFIG_KEY, agentApprovalExpiredAt, agentApprovalFingerprint, agentApprovalPrincipalKey, agentApprovalStatusAt, agentApprovalUsableAt, agentApprovalVisibleTo, buildAgentApprovalRequest, canonicalizeAgentApprovalInput, DEFAULT_AGENT_APPROVAL_TTL_MS, } from './agent/approval.js';
|
|
28
|
+
export type { AgentApprovalMatch, AgentApprovalRequest, AgentApprovalRequestInput, AgentApprovalStatus, AgentApprovalStore, } from './agent/approval.js';
|
|
29
|
+
export { AgentApprovalRequested } from './agent/AgentApprovalRequested.js';
|
|
13
30
|
export { ViewEngine } from './mvc/ViewEngine.js';
|
|
14
31
|
export { inertia, setInertiaSsrRenderer, setInertiaDocument } from './mvc/inertia/InertiaEngine.js';
|
|
15
32
|
export { setInertiaSharedProps, getInertiaSharedPropsResolver, shareInertiaProps } from './mvc/inertia/shared.js';
|
|
@@ -17,8 +34,8 @@ export type { InertiaDocumentContext, InertiaDocumentOptions, InertiaOptions, In
|
|
|
17
34
|
export type { SharedInertiaPropsResolver, InertiaSharedProps, ResolvedSharedInertiaProps, SharedPropsContainer, } from './mvc/inertia/shared.js';
|
|
18
35
|
export { InertiaServiceProvider, AuthServiceProvider, OAuthServiceProvider, EventServiceProvider, CacheServiceProvider, QueueServiceProvider, MailServiceProvider, LogServiceProvider, I18nServiceProvider, NotificationServiceProvider, BroadcastServiceProvider, EncryptionServiceProvider, StorageServiceProvider, HealthServiceProvider, SchedulingServiceProvider, AuthorizationServiceProvider, ErrorServiceProvider, } from './providers/index.js';
|
|
19
36
|
export { FormRequest } from './http/FormRequest.js';
|
|
20
|
-
export { AuthManager, SessionGuard, ModelUserProvider, BaseUserProvider, AuthenticatableModel, ScryptHasher, createPasswordResetToken, verifyPasswordResetToken, completePasswordReset, buildPasswordResetUrl, parsePasswordResetUrl, MemoryPasswordResetStore, createEmailVerificationToken, verifyEmailToken, completeEmailVerification, buildVerificationUrl, parseVerificationUrl, isEmailVerified, requireVerifiedEmail, MemoryEmailVerificationStore, createApiToken, parseApiToken, verifyApiToken, tokenCan, tokenCanAll, tokenCanAny, revokeApiToken, revokeAllApiTokens, getUserApiTokens, createBearerTokenMiddleware, getApiToken, getApiTokenOrFail, MemoryApiTokenStore, API_TOKEN_KEY, OAuthManager, MemoryOAuthStateStore, createOAuthManager, createOAuthState, verifyOAuthState, sanitizeOAuthRedirect, OAUTH_SESSION_BINDING_KEY, buildOAuthAuthorizeUrl, exchangeOAuthCode, fetchOAuthUserProfile, createGitHubOAuthProviderConfig, createGoogleOAuthProviderConfig, createDiscordOAuthProviderConfig, buildOAuthRedirectUrl, parseOAuthRedirectUrl, } from './auth/index.js';
|
|
21
|
-
export type { AuthContext as AuthRuntimeContext, AuthCredentials, AuthManagerOptions, Authenticatable, Guard, GuardContext, GuardFactory, UserProvider, ProviderFactory, DefaultSanitizedKeys, Sanitized, PasswordResetConfig, PasswordResetTokenStore, PasswordResetTokenResult, EmailVerificationConfig, EmailVerificationTokenStore, EmailVerificationToken, EmailVerificationTokenResult, ApiToken, ApiTokenStore, CreateApiTokenOptions, CreateApiTokenResult, BearerTokenMiddlewareOptions, OAuthProviderConfig, OAuthTokenResult, OAuthUserProfile, OAuthFallbackEmail, OAuthStatePayload, OAuthStateStore, OAuthStateConfig, OAuthAuthorizeOptions, OAuthCallbackPayload, OAuthManagerOptions, OAuthProviderFactoryInput, OAuthBindingSession, } from './auth/index.js';
|
|
37
|
+
export { AuthManager, SessionGuard, TokenGuard, ModelUserProvider, BaseUserProvider, AuthenticatableModel, ScryptHasher, createPasswordResetToken, verifyPasswordResetToken, completePasswordReset, buildPasswordResetUrl, parsePasswordResetUrl, MemoryPasswordResetStore, createEmailVerificationToken, verifyEmailToken, completeEmailVerification, buildVerificationUrl, parseVerificationUrl, isEmailVerified, requireVerifiedEmail, MemoryEmailVerificationStore, createApiToken, parseApiToken, readBearerToken, verifyApiToken, tokenCan, tokenCanAll, tokenCanAny, revokeApiToken, revokeAllApiTokens, getUserApiTokens, createBearerTokenMiddleware, getApiToken, getApiTokenOrFail, MemoryApiTokenStore, API_TOKEN_KEY, OAuthManager, MemoryOAuthStateStore, createOAuthManager, createOAuthState, verifyOAuthState, sanitizeOAuthRedirect, OAUTH_SESSION_BINDING_KEY, buildOAuthAuthorizeUrl, exchangeOAuthCode, fetchOAuthUserProfile, createGitHubOAuthProviderConfig, createGoogleOAuthProviderConfig, createDiscordOAuthProviderConfig, buildOAuthRedirectUrl, parseOAuthRedirectUrl, } from './auth/index.js';
|
|
38
|
+
export type { AuthContext as AuthRuntimeContext, AuthCredentials, AuthManagerOptions, Authenticatable, Guard, GuardContext, GuardFactory, UserProvider, ProviderFactory, DefaultSanitizedKeys, Sanitized, PasswordResetConfig, PasswordResetTokenStore, PasswordResetTokenResult, EmailVerificationConfig, EmailVerificationTokenStore, EmailVerificationToken, EmailVerificationTokenResult, ApiToken, ApiTokenGuardOptions, ApiTokenStore, CreateApiTokenOptions, CreateApiTokenResult, BearerTokenMiddlewareOptions, VerifiedApiToken, TokenGuardOptions, OAuthProviderConfig, OAuthTokenResult, OAuthUserProfile, OAuthFallbackEmail, OAuthStatePayload, OAuthStateStore, OAuthStateConfig, OAuthAuthorizeOptions, OAuthCallbackPayload, OAuthManagerOptions, OAuthProviderFactoryInput, OAuthBindingSession, } from './auth/index.js';
|
|
22
39
|
export { defineMiddleware, jsonResponse, createSessionMiddleware, MemorySessionStore, getSessionFromContext, requireAuthenticated, requireGuest, attachAuthContext, createCsrfMiddleware, getCsrfToken, csrfField, verifyCsrfToken, CSRF_TOKEN_KEY, CSRF_HEADER_NAME, CSRF_FORM_FIELD, validateRequest, validateRequestWith, getValidatedData, validate, validateSafe, VALIDATED_DATA_KEY, createRateLimitMiddleware, getRateLimitInfo, resetRateLimit, MemoryRateLimitStore, SlidingWindowRateLimitStore, createSecurityHeaders, createCspMiddleware, getCspNonce, CSP_NONCE_KEY, createHostAuthorizationMiddleware, createCorsMiddleware, createRedirectSafetyMiddleware, isSafeRedirectUrl, createForceHttpsMiddleware, requestIdMiddleware, requestLoggingMiddleware, detectLocaleMiddleware, LOCALE_CONTEXT_KEY, getRequestLocale, getRequestTranslator, } from './http/middleware/index.js';
|
|
23
40
|
export { AUTH_CONTEXT_KEY } from './http/middleware/auth.js';
|
|
24
41
|
export type { Middleware, Session, SessionData, SessionStore, AuthContext, RequireAuthOptions, CsrfOptions, ValidationSchema, ValidateRequestOptions, RateLimitOptions, RateLimitStore, RateLimitEntry, RateLimitInfo, SecurityHeadersOptions, HstsOptions, CspOptions, CspDirectives, HostAuthorizationOptions, CorsOptions, RedirectSafetyOptions, ForceHttpsOptions, DetectLocaleOptions, DetectLocaleVariables, TranslatorBinding, LocaleSource, } from './http/middleware/index.js';
|
|
@@ -36,7 +53,7 @@ export { StorageManager, LocalDriver as LocalStorageDriver, MemoryDriver as Memo
|
|
|
36
53
|
export type { StorageDriver, StorageConfig, DiskConfig, StorageDriverFactory, PutOptions, FileMetadata, TemporaryUrlOptions, GetStreamOptions, StorageDriverCapabilities, } from './storage/index.js';
|
|
37
54
|
export { Scheduler, Schedule, PendingSchedule, ScheduledTask, parseCron, matchesCron, getNextOccurrence, getNextOccurrences, isDue, isDueInTimezone, toTimezone, createScheduler, } from './scheduling/index.js';
|
|
38
55
|
export type { TaskCallback, TaskDefinition, SchedulerOptions, ParsedCron, JobClass as ScheduledJobClass, } from './scheduling/index.js';
|
|
39
|
-
export { Logger, filterSensitiveData, LogManager, ConsoleChannel, FileChannel, DailyFileChannel, LOG_LEVEL_PRIORITY, createLogManager, setLogManager, getLogManager, } from './logging/index.js';
|
|
56
|
+
export { Logger, filterSensitiveData, LogManager, ConsoleChannel, FileChannel, DailyFileChannel, dailyFileDateStamp, dailyFilePath, matchDailyFileDate, LOG_LEVEL_PRIORITY, createLogManager, setLogManager, getLogManager, } from './logging/index.js';
|
|
40
57
|
export type { LogLevel, LogContext, LogEntry, LogChannel, LogChannelFactory, LogChannelConfig, ConsoleChannelConfig, FileChannelConfig, DailyFileChannelConfig, StackChannelConfig, LogConfig, LogFormatter, LoggerOptions, } from './logging/index.js';
|
|
41
58
|
export { Translator, I18nManager, JsonLoader, MemoryLoader, pluralizationRules, getPluralizationRule, selectPluralForm, createI18n, setI18n, getI18n, tryGetI18n, t, tc, } from './i18n/index.js';
|
|
42
59
|
export type { TranslationMessages, ReplacementValues, PluralizationRule, TranslationLoader, TranslatorOptions, I18nConfig, TranslationLoaderFactory, GurenTranslationKeys, RegisteredTranslationKey, } from './i18n/index.js';
|