@daloyjs/core 1.0.0-beta.5 → 1.0.0-beta.7
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 +2 -1
- package/dist/adapters/bun.d.ts +13 -1
- package/dist/adapters/bun.js +8 -1
- package/dist/adapters/cloudflare.d.ts +7 -1
- package/dist/adapters/cloudflare.js +6 -1
- package/dist/adapters/deno.d.ts +11 -1
- package/dist/adapters/deno.js +8 -1
- package/dist/adapters/fastly.d.ts +12 -2
- package/dist/adapters/fastly.js +12 -2
- package/dist/adapters/lambda.d.ts +37 -1
- package/dist/adapters/lambda.js +6 -1
- package/dist/adapters/node.d.ts +12 -1
- package/dist/adapters/node.js +7 -1
- package/dist/adapters/vercel.d.ts +13 -1
- package/dist/adapters/vercel.js +12 -1
- package/dist/app.d.ts +67 -17
- package/dist/app.js +97 -31
- package/dist/banner.d.ts +6 -0
- package/dist/banner.js +6 -0
- package/dist/cli.d.ts +35 -0
- package/dist/cli.js +23 -1
- package/dist/combine.d.ts +8 -0
- package/dist/combine.js +8 -0
- package/dist/compression.d.ts +3 -0
- package/dist/compression.js +3 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.js +4 -0
- package/dist/conn-info.d.ts +35 -2
- package/dist/conn-info.js +35 -2
- package/dist/contract.d.ts +2 -0
- package/dist/contract.js +2 -0
- package/dist/cookie.d.ts +12 -0
- package/dist/cookie.js +12 -0
- package/dist/dependency.d.ts +4 -0
- package/dist/dependency.js +3 -0
- package/dist/discriminator.d.ts +13 -0
- package/dist/discriminator.js +23 -1
- package/dist/docs.d.ts +78 -0
- package/dist/docs.js +21 -0
- package/dist/errors.d.ts +16 -0
- package/dist/errors.js +14 -0
- package/dist/etag.d.ts +2 -0
- package/dist/etag.js +2 -0
- package/dist/fetch-guard.d.ts +7 -0
- package/dist/fetch-guard.js +7 -0
- package/dist/fetch-resilience.d.ts +4 -0
- package/dist/fetch-resilience.js +4 -0
- package/dist/http-signatures.d.ts +32 -0
- package/dist/http-signatures.js +30 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/ip-restriction.d.ts +40 -3
- package/dist/ip-restriction.js +35 -3
- package/dist/jwk.d.ts +12 -1
- package/dist/jwk.js +6 -0
- package/dist/jwt.d.ts +14 -0
- package/dist/jwt.js +10 -0
- package/dist/load-shedding.d.ts +3 -0
- package/dist/load-shedding.js +3 -0
- package/dist/logger.d.ts +13 -0
- package/dist/logger.js +3 -0
- package/dist/mcp.d.ts +574 -0
- package/dist/mcp.js +623 -0
- package/dist/middleware.d.ts +68 -0
- package/dist/middleware.js +17 -0
- package/dist/mtls.d.ts +19 -2
- package/dist/mtls.js +12 -2
- package/dist/multipart.d.ts +42 -5
- package/dist/multipart.js +41 -5
- package/dist/openapi.d.ts +15 -9
- package/dist/openapi.js +6 -9
- package/dist/rate-limit-redis.d.ts +21 -2
- package/dist/rate-limit-redis.js +17 -2
- package/dist/safe-redirect.d.ts +6 -0
- package/dist/safe-redirect.js +6 -0
- package/dist/sbom.cdx.json +9 -9
- package/dist/sbom.spdx.json +5 -5
- package/dist/scheduler.d.ts +4 -0
- package/dist/schema.d.ts +25 -0
- package/dist/security-schemes.d.ts +50 -0
- package/dist/security-schemes.js +6 -0
- package/dist/security.d.ts +33 -0
- package/dist/security.js +28 -10
- package/dist/session.d.ts +34 -5
- package/dist/session.js +31 -5
- package/dist/streaming.d.ts +19 -0
- package/dist/streaming.js +16 -0
- package/dist/subdomains.d.ts +4 -0
- package/dist/subdomains.js +4 -0
- package/dist/time-claims.d.ts +22 -2
- package/dist/time-claims.js +6 -0
- package/dist/tracing.d.ts +12 -0
- package/dist/tracing.js +6 -0
- package/dist/types.d.ts +70 -1
- package/dist/waf.js +21 -1
- package/dist/webhook-delivery.d.ts +6 -0
- package/dist/webhook-delivery.js +5 -0
- package/dist/websocket.d.ts +137 -4
- package/dist/websocket.js +105 -4
- package/package.json +6 -1
package/dist/conn-info.d.ts
CHANGED
|
@@ -69,6 +69,9 @@ interface MutableConnInfo {
|
|
|
69
69
|
* @internal Adapter helper — attach {@link ConnInfo} to a `Request`. Called
|
|
70
70
|
* by the Node / Bun / Deno / Cloudflare / Vercel / Lambda adapters before
|
|
71
71
|
* `app.fetch(request)`.
|
|
72
|
+
*
|
|
73
|
+
* @param request - Incoming request to tag (stored under a private symbol).
|
|
74
|
+
* @param info - Connection metadata gathered by the adapter.
|
|
72
75
|
*/
|
|
73
76
|
export declare function setConnInfo(request: Request, info: ConnInfo): void;
|
|
74
77
|
/**
|
|
@@ -76,6 +79,8 @@ export declare function setConnInfo(request: Request, info: ConnInfo): void;
|
|
|
76
79
|
* `undefined` when the adapter does not expose connection metadata (e.g.
|
|
77
80
|
* Cloudflare Workers without `cf` enabled).
|
|
78
81
|
*
|
|
82
|
+
* @param request - Request previously tagged by {@link setConnInfo}.
|
|
83
|
+
* @returns The attached {@link ConnInfo}, or `undefined` when absent.
|
|
79
84
|
* @since 0.24.0
|
|
80
85
|
*/
|
|
81
86
|
export declare function getConnInfo(request: Request): ConnInfo | undefined;
|
|
@@ -83,6 +88,9 @@ export declare function getConnInfo(request: Request): ConnInfo | undefined;
|
|
|
83
88
|
* Refuses-at-construction on malformed {@link BehindProxyConfig}. Called once
|
|
84
89
|
* during `new App({ behindProxy })`.
|
|
85
90
|
*
|
|
91
|
+
* @param cfg - Proxy posture to validate; `undefined` is accepted as "unset".
|
|
92
|
+
* @throws Error when `hops` is not an integer in [0, 64], when `cidrs` is
|
|
93
|
+
* empty or contains non-string entries, or when the shape is unrecognized.
|
|
86
94
|
* @since 0.24.0
|
|
87
95
|
*/
|
|
88
96
|
export declare function assertBehindProxy(cfg: BehindProxyConfig | undefined): void;
|
|
@@ -93,6 +101,10 @@ export declare function assertBehindProxy(cfg: BehindProxyConfig | undefined): v
|
|
|
93
101
|
* `undefined` when the header is shorter than the configured hop count
|
|
94
102
|
* (caller falls back to the immediate peer).
|
|
95
103
|
*
|
|
104
|
+
* @param header - Raw `X-Forwarded-For` header value, or `null` when absent.
|
|
105
|
+
* @param hops - Declared number of trusted proxy hops (must be >= 1).
|
|
106
|
+
* @returns The client IP at the declared hop, or `undefined` when the chain
|
|
107
|
+
* is too short or `hops < 1`.
|
|
96
108
|
* @internal
|
|
97
109
|
*/
|
|
98
110
|
export declare function pickForwardedForByHops(header: string | null, hops: number): string | undefined;
|
|
@@ -102,6 +114,10 @@ export declare function pickForwardedForByHops(header: string | null, hops: numb
|
|
|
102
114
|
* available (the caller — rate-limit, ipRestriction, audit-log — must fail
|
|
103
115
|
* closed rather than guess).
|
|
104
116
|
*
|
|
117
|
+
* @param request - Incoming request whose client IP should be resolved.
|
|
118
|
+
* @param cfg - The app's `behindProxy` posture; `undefined` behaves as `"none"`.
|
|
119
|
+
* @returns The trusted client IP, or `undefined` when neither the peer
|
|
120
|
+
* address nor a trusted `X-Forwarded-For` slot is available.
|
|
105
121
|
* @since 0.24.0
|
|
106
122
|
*/
|
|
107
123
|
export declare function resolveClientIp(request: Request, cfg: BehindProxyConfig | undefined): string | undefined;
|
|
@@ -110,11 +126,28 @@ export declare function resolveClientIp(request: Request, cfg: BehindProxyConfig
|
|
|
110
126
|
* `undefined` rather than allocating a plain object so the IP cannot be
|
|
111
127
|
* serialized into logs by accident.
|
|
112
128
|
*
|
|
129
|
+
* @param ctx - Request context whose adapter-attached {@link ConnInfo} is read.
|
|
130
|
+
* @returns The immediate peer address, or `undefined` when the adapter did
|
|
131
|
+
* not attach connection metadata.
|
|
113
132
|
* @since 0.24.0
|
|
114
133
|
*/
|
|
115
134
|
export declare function readRemoteAddress(ctx: BaseContext<any, any>): string | undefined;
|
|
116
|
-
/**
|
|
135
|
+
/**
|
|
136
|
+
* Lazy accessor for `ctx.remotePort` (the immediate peer's TCP port).
|
|
137
|
+
*
|
|
138
|
+
* @param ctx - Request context whose adapter-attached {@link ConnInfo} is read.
|
|
139
|
+
* @returns The immediate peer port, or `undefined` when the adapter did not
|
|
140
|
+
* attach connection metadata.
|
|
141
|
+
* @since 0.24.0
|
|
142
|
+
*/
|
|
117
143
|
export declare function readRemotePort(ctx: BaseContext<any, any>): number | undefined;
|
|
118
|
-
/**
|
|
144
|
+
/**
|
|
145
|
+
* Test-only helper that shallow-copies a {@link ConnInfo} into a mutable shape
|
|
146
|
+
* so tests can tweak fields without casting away `readonly`.
|
|
147
|
+
*
|
|
148
|
+
* @param info - Connection metadata to copy.
|
|
149
|
+
* @returns A mutable shallow copy of `info`.
|
|
150
|
+
* @internal
|
|
151
|
+
*/
|
|
119
152
|
export declare function _makeConnInfoForTests(info: ConnInfo): MutableConnInfo;
|
|
120
153
|
export {};
|
package/dist/conn-info.js
CHANGED
|
@@ -23,6 +23,9 @@ const CONN_INFO_SYMBOL = Symbol.for("daloyjs.connInfo");
|
|
|
23
23
|
* @internal Adapter helper — attach {@link ConnInfo} to a `Request`. Called
|
|
24
24
|
* by the Node / Bun / Deno / Cloudflare / Vercel / Lambda adapters before
|
|
25
25
|
* `app.fetch(request)`.
|
|
26
|
+
*
|
|
27
|
+
* @param request - Incoming request to tag (stored under a private symbol).
|
|
28
|
+
* @param info - Connection metadata gathered by the adapter.
|
|
26
29
|
*/
|
|
27
30
|
export function setConnInfo(request, info) {
|
|
28
31
|
request[CONN_INFO_SYMBOL] = info;
|
|
@@ -32,6 +35,8 @@ export function setConnInfo(request, info) {
|
|
|
32
35
|
* `undefined` when the adapter does not expose connection metadata (e.g.
|
|
33
36
|
* Cloudflare Workers without `cf` enabled).
|
|
34
37
|
*
|
|
38
|
+
* @param request - Request previously tagged by {@link setConnInfo}.
|
|
39
|
+
* @returns The attached {@link ConnInfo}, or `undefined` when absent.
|
|
35
40
|
* @since 0.24.0
|
|
36
41
|
*/
|
|
37
42
|
export function getConnInfo(request) {
|
|
@@ -41,6 +46,9 @@ export function getConnInfo(request) {
|
|
|
41
46
|
* Refuses-at-construction on malformed {@link BehindProxyConfig}. Called once
|
|
42
47
|
* during `new App({ behindProxy })`.
|
|
43
48
|
*
|
|
49
|
+
* @param cfg - Proxy posture to validate; `undefined` is accepted as "unset".
|
|
50
|
+
* @throws Error when `hops` is not an integer in [0, 64], when `cidrs` is
|
|
51
|
+
* empty or contains non-string entries, or when the shape is unrecognized.
|
|
44
52
|
* @since 0.24.0
|
|
45
53
|
*/
|
|
46
54
|
export function assertBehindProxy(cfg) {
|
|
@@ -76,6 +84,10 @@ export function assertBehindProxy(cfg) {
|
|
|
76
84
|
* `undefined` when the header is shorter than the configured hop count
|
|
77
85
|
* (caller falls back to the immediate peer).
|
|
78
86
|
*
|
|
87
|
+
* @param header - Raw `X-Forwarded-For` header value, or `null` when absent.
|
|
88
|
+
* @param hops - Declared number of trusted proxy hops (must be >= 1).
|
|
89
|
+
* @returns The client IP at the declared hop, or `undefined` when the chain
|
|
90
|
+
* is too short or `hops < 1`.
|
|
79
91
|
* @internal
|
|
80
92
|
*/
|
|
81
93
|
export function pickForwardedForByHops(header, hops) {
|
|
@@ -97,6 +109,10 @@ export function pickForwardedForByHops(header, hops) {
|
|
|
97
109
|
* available (the caller — rate-limit, ipRestriction, audit-log — must fail
|
|
98
110
|
* closed rather than guess).
|
|
99
111
|
*
|
|
112
|
+
* @param request - Incoming request whose client IP should be resolved.
|
|
113
|
+
* @param cfg - The app's `behindProxy` posture; `undefined` behaves as `"none"`.
|
|
114
|
+
* @returns The trusted client IP, or `undefined` when neither the peer
|
|
115
|
+
* address nor a trusted `X-Forwarded-For` slot is available.
|
|
100
116
|
* @since 0.24.0
|
|
101
117
|
*/
|
|
102
118
|
export function resolveClientIp(request, cfg) {
|
|
@@ -129,16 +145,33 @@ export function resolveClientIp(request, cfg) {
|
|
|
129
145
|
* `undefined` rather than allocating a plain object so the IP cannot be
|
|
130
146
|
* serialized into logs by accident.
|
|
131
147
|
*
|
|
148
|
+
* @param ctx - Request context whose adapter-attached {@link ConnInfo} is read.
|
|
149
|
+
* @returns The immediate peer address, or `undefined` when the adapter did
|
|
150
|
+
* not attach connection metadata.
|
|
132
151
|
* @since 0.24.0
|
|
133
152
|
*/
|
|
134
153
|
export function readRemoteAddress(ctx) {
|
|
135
154
|
return getConnInfo(ctx.request)?.remoteAddress;
|
|
136
155
|
}
|
|
137
|
-
/**
|
|
156
|
+
/**
|
|
157
|
+
* Lazy accessor for `ctx.remotePort` (the immediate peer's TCP port).
|
|
158
|
+
*
|
|
159
|
+
* @param ctx - Request context whose adapter-attached {@link ConnInfo} is read.
|
|
160
|
+
* @returns The immediate peer port, or `undefined` when the adapter did not
|
|
161
|
+
* attach connection metadata.
|
|
162
|
+
* @since 0.24.0
|
|
163
|
+
*/
|
|
138
164
|
export function readRemotePort(ctx) {
|
|
139
165
|
return getConnInfo(ctx.request)?.remotePort;
|
|
140
166
|
}
|
|
141
|
-
/**
|
|
167
|
+
/**
|
|
168
|
+
* Test-only helper that shallow-copies a {@link ConnInfo} into a mutable shape
|
|
169
|
+
* so tests can tweak fields without casting away `readonly`.
|
|
170
|
+
*
|
|
171
|
+
* @param info - Connection metadata to copy.
|
|
172
|
+
* @returns A mutable shallow copy of `info`.
|
|
173
|
+
* @internal
|
|
174
|
+
*/
|
|
142
175
|
export function _makeConnInfoForTests(info) {
|
|
143
176
|
return { ...info };
|
|
144
177
|
}
|
package/dist/contract.d.ts
CHANGED
|
@@ -44,6 +44,8 @@ export interface ContractTestOptions {
|
|
|
44
44
|
* routes don't carry body schemas by accident, and that `meta.examples`
|
|
45
45
|
* reference declared response statuses.
|
|
46
46
|
*
|
|
47
|
+
* @param app The {@link App} whose registered routes are inspected.
|
|
48
|
+
* @param opts Check toggles ({@link ContractTestOptions}); `requireOperationId` defaults to `true`.
|
|
47
49
|
* @returns A {@link ContractReport}. In CI, exit non-zero when `report.ok` is `false`.
|
|
48
50
|
*/
|
|
49
51
|
export declare function runContractTests(app: App, opts?: ContractTestOptions): Promise<ContractReport>;
|
package/dist/contract.js
CHANGED
|
@@ -19,6 +19,8 @@ import { validate } from "./schema.js";
|
|
|
19
19
|
* routes don't carry body schemas by accident, and that `meta.examples`
|
|
20
20
|
* reference declared response statuses.
|
|
21
21
|
*
|
|
22
|
+
* @param app The {@link App} whose registered routes are inspected.
|
|
23
|
+
* @param opts Check toggles ({@link ContractTestOptions}); `requireOperationId` defaults to `true`.
|
|
22
24
|
* @returns A {@link ContractReport}. In CI, exit non-zero when `report.ok` is `false`.
|
|
23
25
|
*/
|
|
24
26
|
export async function runContractTests(app, opts = {}) {
|
package/dist/cookie.d.ts
CHANGED
|
@@ -84,6 +84,11 @@ export declare function assertCookieAttributes(input: {
|
|
|
84
84
|
* The value is URI-encoded so binary signature bytes and base64 padding
|
|
85
85
|
* round-trip safely.
|
|
86
86
|
*
|
|
87
|
+
* @param name Cookie name; `__Host-`/`__Secure-` prefixes are enforced by validation.
|
|
88
|
+
* @param value Cookie value; URI-encoded before serialization.
|
|
89
|
+
* @param attributes Cookie attributes. Defaults: `SameSite=Strict`, `Secure`, `HttpOnly`, `Path=/`.
|
|
90
|
+
* @returns A single `Set-Cookie` header value.
|
|
91
|
+
* @throws Error if the name or attributes fail {@link assertCookieAttributes} validation.
|
|
87
92
|
* @since 0.27.0
|
|
88
93
|
*/
|
|
89
94
|
export declare function serializeCookie(name: string, value: string, attributes?: CookieAttributes): string;
|
|
@@ -92,6 +97,10 @@ export declare function serializeCookie(name: string, value: string, attributes?
|
|
|
92
97
|
* `Max-Age=0` per RFC 6265 §5.2.2 and preserves the original attributes so
|
|
93
98
|
* intermediaries match the original cookie when deciding what to delete.
|
|
94
99
|
*
|
|
100
|
+
* @param name Name of the cookie to clear.
|
|
101
|
+
* @param attributes Attributes of the original cookie; must match for deletion to apply.
|
|
102
|
+
* @returns A `Set-Cookie` header value with an empty value and `Max-Age=0`.
|
|
103
|
+
* @throws Error if the name or attributes fail {@link assertCookieAttributes} validation.
|
|
95
104
|
* @since 0.27.0
|
|
96
105
|
*/
|
|
97
106
|
export declare function serializeClearCookie(name: string, attributes?: CookieAttributes): string;
|
|
@@ -118,6 +127,9 @@ export declare function serializeClearCookie(name: string, attributes?: CookieAt
|
|
|
118
127
|
* parser-level guard is defense-in-depth for developers who customize the
|
|
119
128
|
* cookie name or read other cookies through this helper.
|
|
120
129
|
*
|
|
130
|
+
* @param header The raw `Cookie` request header, or `null`/`undefined` when absent.
|
|
131
|
+
* @param name Exact cookie name to read (case-sensitive).
|
|
132
|
+
* @returns The decoded cookie value, or `null` when absent or duplicated.
|
|
121
133
|
* @since 0.27.0
|
|
122
134
|
*/
|
|
123
135
|
export declare function readRequestCookie(header: string | null | undefined, name: string): string | null;
|
package/dist/cookie.js
CHANGED
|
@@ -96,6 +96,11 @@ export function assertCookieAttributes(input) {
|
|
|
96
96
|
* The value is URI-encoded so binary signature bytes and base64 padding
|
|
97
97
|
* round-trip safely.
|
|
98
98
|
*
|
|
99
|
+
* @param name Cookie name; `__Host-`/`__Secure-` prefixes are enforced by validation.
|
|
100
|
+
* @param value Cookie value; URI-encoded before serialization.
|
|
101
|
+
* @param attributes Cookie attributes. Defaults: `SameSite=Strict`, `Secure`, `HttpOnly`, `Path=/`.
|
|
102
|
+
* @returns A single `Set-Cookie` header value.
|
|
103
|
+
* @throws Error if the name or attributes fail {@link assertCookieAttributes} validation.
|
|
99
104
|
* @since 0.27.0
|
|
100
105
|
*/
|
|
101
106
|
export function serializeCookie(name, value, attributes = {}) {
|
|
@@ -125,6 +130,10 @@ export function serializeCookie(name, value, attributes = {}) {
|
|
|
125
130
|
* `Max-Age=0` per RFC 6265 §5.2.2 and preserves the original attributes so
|
|
126
131
|
* intermediaries match the original cookie when deciding what to delete.
|
|
127
132
|
*
|
|
133
|
+
* @param name Name of the cookie to clear.
|
|
134
|
+
* @param attributes Attributes of the original cookie; must match for deletion to apply.
|
|
135
|
+
* @returns A `Set-Cookie` header value with an empty value and `Max-Age=0`.
|
|
136
|
+
* @throws Error if the name or attributes fail {@link assertCookieAttributes} validation.
|
|
128
137
|
* @since 0.27.0
|
|
129
138
|
*/
|
|
130
139
|
export function serializeClearCookie(name, attributes = {}) {
|
|
@@ -170,6 +179,9 @@ export function serializeClearCookie(name, attributes = {}) {
|
|
|
170
179
|
* parser-level guard is defense-in-depth for developers who customize the
|
|
171
180
|
* cookie name or read other cookies through this helper.
|
|
172
181
|
*
|
|
182
|
+
* @param header The raw `Cookie` request header, or `null`/`undefined` when absent.
|
|
183
|
+
* @param name Exact cookie name to read (case-sensitive).
|
|
184
|
+
* @returns The decoded cookie value, or `null` when absent or duplicated.
|
|
173
185
|
* @since 0.27.0
|
|
174
186
|
*/
|
|
175
187
|
export function readRequestCookie(header, name) {
|
package/dist/dependency.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export interface DependencyOptions<TName extends string, TValue, TStateKey exten
|
|
|
31
31
|
}
|
|
32
32
|
/** Hooks bundle returned by {@link defineDependency} (carries metadata). */
|
|
33
33
|
export interface DependencyHooks extends Hooks {
|
|
34
|
+
/** Non-enumerable dependency metadata (`name` + `dependsOn`) used for dedup and cycle checks. */
|
|
34
35
|
readonly [DEPENDENCY_MARKER]: {
|
|
35
36
|
readonly name: string;
|
|
36
37
|
readonly dependsOn: readonly string[];
|
|
@@ -42,6 +43,9 @@ export interface DependencyHooks extends Hooks {
|
|
|
42
43
|
* `ctx.state[stateKey]` (default `name`). Composing the same dependency
|
|
43
44
|
* twice in one chain runs `resolve()` exactly once.
|
|
44
45
|
*
|
|
46
|
+
* @param opts - Dependency `name`, optional `dependsOn` / `stateKey`, and the `resolve` function.
|
|
47
|
+
* @returns A {@link DependencyHooks} bundle to compose via `app.use()` / route hooks.
|
|
48
|
+
* @throws {Error} When `name` is empty or the dependency declares itself in `dependsOn` (cycle).
|
|
45
49
|
* @since 0.24.0
|
|
46
50
|
*/
|
|
47
51
|
export declare function defineDependency<TName extends string, TValue, TStateKey extends string = TName>(opts: DependencyOptions<TName, TValue, TStateKey>): DependencyHooks;
|
package/dist/dependency.js
CHANGED
|
@@ -21,6 +21,9 @@ const RESULTS_KEY = Symbol.for("daloyjs.dependency.results");
|
|
|
21
21
|
* `ctx.state[stateKey]` (default `name`). Composing the same dependency
|
|
22
22
|
* twice in one chain runs `resolve()` exactly once.
|
|
23
23
|
*
|
|
24
|
+
* @param opts - Dependency `name`, optional `dependsOn` / `stateKey`, and the `resolve` function.
|
|
25
|
+
* @returns A {@link DependencyHooks} bundle to compose via `app.use()` / route hooks.
|
|
26
|
+
* @throws {Error} When `name` is empty or the dependency declares itself in `dependsOn` (cycle).
|
|
24
27
|
* @since 0.24.0
|
|
25
28
|
*/
|
|
26
29
|
export function defineDependency(opts) {
|
package/dist/discriminator.d.ts
CHANGED
|
@@ -27,6 +27,11 @@ export interface DiscriminatorObject {
|
|
|
27
27
|
* Build an OpenAPI 3.1 Discriminator Object. Throws on an empty
|
|
28
28
|
* `propertyName` so misconfigurations fail at boot rather than producing a
|
|
29
29
|
* silently invalid spec.
|
|
30
|
+
*
|
|
31
|
+
* @param propertyName Name of the property that selects the variant schema.
|
|
32
|
+
* @param mapping Optional explicit discriminator-value-to-$ref map.
|
|
33
|
+
* @returns A {@link DiscriminatorObject} ready to embed in an OpenAPI schema.
|
|
34
|
+
* @throws TypeError if `propertyName` is not a non-empty string.
|
|
30
35
|
*/
|
|
31
36
|
export declare function discriminator(propertyName: string, mapping?: Record<string, string>): DiscriminatorObject;
|
|
32
37
|
/** Options for {@link discriminatedUnion}. */
|
|
@@ -68,6 +73,14 @@ export type DiscriminatedUnion<V extends Record<string, StandardSchemaV1>> = Sta
|
|
|
68
73
|
* const Cat = z.object({ kind: z.literal("cat"), meow: z.boolean() });
|
|
69
74
|
* const Dog = z.object({ kind: z.literal("dog"), bark: z.boolean() });
|
|
70
75
|
* const Animal = discriminatedUnion("kind", { cat: Cat, dog: Dog });
|
|
76
|
+
*
|
|
77
|
+
* @param propertyName Discriminator property read off the incoming value.
|
|
78
|
+
* @param variants Map from discriminator value to variant schema. Only own
|
|
79
|
+
* properties are consulted, so prototype names like `constructor` cannot
|
|
80
|
+
* be abused to bypass variant lookup.
|
|
81
|
+
* @param opts Optional {@link DiscriminatedUnionOptions} (explicit `mapping`, `vendor`).
|
|
82
|
+
* @returns A {@link DiscriminatedUnion} usable as validator and OpenAPI emitter.
|
|
83
|
+
* @throws TypeError if `propertyName` is empty or `variants` has no entries.
|
|
71
84
|
*/
|
|
72
85
|
export declare function discriminatedUnion<P extends string, V extends Record<string, StandardSchemaV1>>(propertyName: P, variants: V, opts?: DiscriminatedUnionOptions): DiscriminatedUnion<V>;
|
|
73
86
|
export {};
|
package/dist/discriminator.js
CHANGED
|
@@ -19,6 +19,11 @@
|
|
|
19
19
|
* Build an OpenAPI 3.1 Discriminator Object. Throws on an empty
|
|
20
20
|
* `propertyName` so misconfigurations fail at boot rather than producing a
|
|
21
21
|
* silently invalid spec.
|
|
22
|
+
*
|
|
23
|
+
* @param propertyName Name of the property that selects the variant schema.
|
|
24
|
+
* @param mapping Optional explicit discriminator-value-to-$ref map.
|
|
25
|
+
* @returns A {@link DiscriminatorObject} ready to embed in an OpenAPI schema.
|
|
26
|
+
* @throws TypeError if `propertyName` is not a non-empty string.
|
|
22
27
|
*/
|
|
23
28
|
export function discriminator(propertyName, mapping) {
|
|
24
29
|
if (typeof propertyName !== "string" || propertyName.length === 0) {
|
|
@@ -35,6 +40,14 @@ export function discriminator(propertyName, mapping) {
|
|
|
35
40
|
* const Cat = z.object({ kind: z.literal("cat"), meow: z.boolean() });
|
|
36
41
|
* const Dog = z.object({ kind: z.literal("dog"), bark: z.boolean() });
|
|
37
42
|
* const Animal = discriminatedUnion("kind", { cat: Cat, dog: Dog });
|
|
43
|
+
*
|
|
44
|
+
* @param propertyName Discriminator property read off the incoming value.
|
|
45
|
+
* @param variants Map from discriminator value to variant schema. Only own
|
|
46
|
+
* properties are consulted, so prototype names like `constructor` cannot
|
|
47
|
+
* be abused to bypass variant lookup.
|
|
48
|
+
* @param opts Optional {@link DiscriminatedUnionOptions} (explicit `mapping`, `vendor`).
|
|
49
|
+
* @returns A {@link DiscriminatedUnion} usable as validator and OpenAPI emitter.
|
|
50
|
+
* @throws TypeError if `propertyName` is empty or `variants` has no entries.
|
|
38
51
|
*/
|
|
39
52
|
export function discriminatedUnion(propertyName, variants, opts) {
|
|
40
53
|
if (typeof propertyName !== "string" || propertyName.length === 0) {
|
|
@@ -71,7 +84,16 @@ export function discriminatedUnion(propertyName, variants, opts) {
|
|
|
71
84
|
],
|
|
72
85
|
};
|
|
73
86
|
}
|
|
74
|
-
|
|
87
|
+
// Only accept an OWN property of the variant map. A bare
|
|
88
|
+
// `variants[discriminatorValue]` lookup would resolve inherited
|
|
89
|
+
// `Object.prototype` members (`constructor`, `toString`, `valueOf`,
|
|
90
|
+
// `hasOwnProperty`, `__proto__`, …) to a truthy non-variant, slipping
|
|
91
|
+
// past the `!variant` guard below; the subsequent `variant["~standard"]`
|
|
92
|
+
// access then throws an uncaught `TypeError` that the app surfaces as an
|
|
93
|
+
// unauthenticated 500 (and error-log flood) instead of a clean 400.
|
|
94
|
+
const variant = Object.hasOwn(variants, discriminatorValue)
|
|
95
|
+
? variants[discriminatorValue]
|
|
96
|
+
: undefined;
|
|
75
97
|
if (!variant) {
|
|
76
98
|
return {
|
|
77
99
|
issues: [
|
package/dist/docs.d.ts
CHANGED
|
@@ -24,72 +24,129 @@ export type ScalarTheme = "alternate" | "default" | "moon" | "purple" | "solariz
|
|
|
24
24
|
*/
|
|
25
25
|
export interface ScalarReferenceConfiguration {
|
|
26
26
|
[key: string]: ScalarJsonValue | undefined;
|
|
27
|
+
/** Built-in color theme name. See {@link ScalarTheme}. */
|
|
27
28
|
theme?: ScalarTheme;
|
|
29
|
+
/** Extra CSS injected into the reference UI. */
|
|
28
30
|
customCss?: string;
|
|
31
|
+
/** Start the UI in dark mode. */
|
|
29
32
|
darkMode?: boolean;
|
|
33
|
+
/** Pin the color scheme and hide the user's ability to change it. */
|
|
30
34
|
forceDarkModeState?: "dark" | "light";
|
|
35
|
+
/** Load Scalar's default fonts (Inter/JetBrains Mono) from its CDN. */
|
|
31
36
|
withDefaultFonts?: boolean;
|
|
37
|
+
/** URL of the favicon shown in the browser tab. */
|
|
32
38
|
favicon?: string;
|
|
39
|
+
/** Overall page layout: `"modern"` (default) or `"classic"`. */
|
|
33
40
|
layout?: "modern" | "classic";
|
|
41
|
+
/** Hide the "Open API Client" button. */
|
|
34
42
|
hideClientButton?: boolean;
|
|
43
|
+
/** Hide the dark-mode toggle. */
|
|
35
44
|
hideDarkModeToggle?: boolean;
|
|
45
|
+
/** Hide the Models (schemas) section. */
|
|
36
46
|
hideModels?: boolean;
|
|
47
|
+
/** Hide the search bar. */
|
|
37
48
|
hideSearch?: boolean;
|
|
49
|
+
/** Hide the "Test Request" button on operations. */
|
|
38
50
|
hideTestRequestButton?: boolean;
|
|
51
|
+
/** Show each operation's `operationId` next to its title. */
|
|
39
52
|
showOperationId?: boolean;
|
|
53
|
+
/** Show the navigation sidebar. */
|
|
40
54
|
showSidebar?: boolean;
|
|
55
|
+
/** When to expose Scalar's developer tools panel. */
|
|
41
56
|
showDeveloperTools?: "always" | "localhost" | "never";
|
|
57
|
+
/** Expand the first tag's operations on load. */
|
|
42
58
|
defaultOpenFirstTag?: boolean;
|
|
59
|
+
/** Expand every tag's operations on load. */
|
|
43
60
|
defaultOpenAllTags?: boolean;
|
|
61
|
+
/** Expand all model (schema) sections on load. */
|
|
44
62
|
expandAllModelSections?: boolean;
|
|
63
|
+
/** Expand all response sections on load. */
|
|
45
64
|
expandAllResponses?: boolean;
|
|
65
|
+
/** Which spec download button(s) to offer, or `"none"` to hide them. */
|
|
46
66
|
documentDownloadType?: "json" | "yaml" | "both" | "direct" | "none";
|
|
67
|
+
/** Label operations by their `summary` or by their `path`. */
|
|
47
68
|
operationTitleSource?: "summary" | "path";
|
|
69
|
+
/** List required schema properties before optional ones. */
|
|
48
70
|
orderRequiredPropertiesFirst?: boolean;
|
|
71
|
+
/** Sort schema properties alphabetically or keep spec order. */
|
|
49
72
|
orderSchemaPropertiesBy?: "alpha" | "preserve";
|
|
73
|
+
/** Keyboard key that focuses search, e.g. `"k"` for Ctrl/Cmd+K. */
|
|
50
74
|
searchHotKey?: string;
|
|
75
|
+
/** Base URL prepended to relative server URLs in the spec. */
|
|
51
76
|
baseServerURL?: string;
|
|
77
|
+
/** Proxy URL used by "Test Request" calls to avoid CORS issues. */
|
|
52
78
|
proxyUrl?: string;
|
|
79
|
+
/** Redirect URI used by the OAuth2 authorization-code flow. */
|
|
53
80
|
oauth2RedirectUri?: string;
|
|
81
|
+
/** Persist entered credentials in browser storage across reloads. */
|
|
54
82
|
persistAuth?: boolean;
|
|
83
|
+
/** Enable Scalar's anonymous usage telemetry. */
|
|
55
84
|
telemetry?: boolean;
|
|
85
|
+
/** Sort tags alphabetically. */
|
|
56
86
|
tagsSorter?: "alpha";
|
|
87
|
+
/** Sort operations alphabetically or by HTTP method. */
|
|
57
88
|
operationsSorter?: "alpha" | "method";
|
|
89
|
+
/** Prefill security-scheme credentials (JSON-only Scalar `authentication` object). */
|
|
58
90
|
authentication?: {
|
|
59
91
|
[key: string]: ScalarJsonValue | undefined;
|
|
60
92
|
};
|
|
93
|
+
/** Snippet target preselected in the client picker, e.g. `{ targetKey, clientKey }`. */
|
|
61
94
|
defaultHttpClient?: {
|
|
62
95
|
[key: string]: ScalarJsonValue | undefined;
|
|
63
96
|
};
|
|
97
|
+
/** Extra HTML meta tags (title, description, Open Graph, ...) for the page. */
|
|
64
98
|
metaData?: {
|
|
65
99
|
[key: string]: ScalarJsonValue | undefined;
|
|
66
100
|
};
|
|
101
|
+
/** Scalar MCP integration settings (JSON-only). */
|
|
67
102
|
mcp?: {
|
|
68
103
|
[key: string]: ScalarJsonValue | undefined;
|
|
69
104
|
};
|
|
105
|
+
/** Use path-based routing for deep links, e.g. `{ basePath }`. */
|
|
70
106
|
pathRouting?: {
|
|
71
107
|
[key: string]: ScalarJsonValue | undefined;
|
|
72
108
|
};
|
|
109
|
+
/** Override the spec's `servers` list shown in the UI. */
|
|
73
110
|
servers?: ScalarJsonValue[];
|
|
111
|
+
/** Not serializable; the spec is always loaded from {@link DocsOptions.specUrl}. */
|
|
74
112
|
content?: never;
|
|
113
|
+
/** Function-valued option; cannot cross the server-to-HTML boundary. */
|
|
75
114
|
fetch?: never;
|
|
115
|
+
/** Function-valued option; cannot cross the server-to-HTML boundary. */
|
|
76
116
|
generateHeadingSlug?: never;
|
|
117
|
+
/** Function-valued option; cannot cross the server-to-HTML boundary. */
|
|
77
118
|
generateModelSlug?: never;
|
|
119
|
+
/** Function-valued option; cannot cross the server-to-HTML boundary. */
|
|
78
120
|
generateOperationSlug?: never;
|
|
121
|
+
/** Function-valued option; cannot cross the server-to-HTML boundary. */
|
|
79
122
|
generateTagSlug?: never;
|
|
123
|
+
/** Function-valued option; cannot cross the server-to-HTML boundary. */
|
|
80
124
|
generateWebhookSlug?: never;
|
|
125
|
+
/** Function-valued callback; cannot cross the server-to-HTML boundary. */
|
|
81
126
|
onBeforeRequest?: never;
|
|
127
|
+
/** Function-valued callback; cannot cross the server-to-HTML boundary. */
|
|
82
128
|
onDocumentSelect?: never;
|
|
129
|
+
/** Function-valued callback; cannot cross the server-to-HTML boundary. */
|
|
83
130
|
onLoaded?: never;
|
|
131
|
+
/** Function-valued callback; cannot cross the server-to-HTML boundary. */
|
|
84
132
|
onRequestSent?: never;
|
|
133
|
+
/** Function-valued callback; cannot cross the server-to-HTML boundary. */
|
|
85
134
|
onServerChange?: never;
|
|
135
|
+
/** Function-valued callback; cannot cross the server-to-HTML boundary. */
|
|
86
136
|
onShowMore?: never;
|
|
137
|
+
/** Function-valued callback; cannot cross the server-to-HTML boundary. */
|
|
87
138
|
onSidebarClick?: never;
|
|
139
|
+
/** Function-valued callback; cannot cross the server-to-HTML boundary. */
|
|
88
140
|
onSpecUpdate?: never;
|
|
141
|
+
/** Function-valued Scalar plugins; cannot cross the server-to-HTML boundary. */
|
|
89
142
|
plugins?: never;
|
|
143
|
+
/** Function-valued option; cannot cross the server-to-HTML boundary. */
|
|
90
144
|
redirect?: never;
|
|
145
|
+
/** Multi-document sources are not serializable here; serve one spec per page. */
|
|
91
146
|
sources?: never;
|
|
147
|
+
/** Internal URL wiring owned by DaloyJS. Use {@link DocsOptions.specUrl} instead. */
|
|
92
148
|
spec?: never;
|
|
149
|
+
/** Internal URL wiring owned by DaloyJS. Use {@link DocsOptions.specUrl} instead. */
|
|
93
150
|
url?: never;
|
|
94
151
|
}
|
|
95
152
|
/**
|
|
@@ -425,6 +482,10 @@ export interface HtmlResponseOptions extends DocsContentSecurityPolicyOptions {
|
|
|
425
482
|
* The output is a single HTML document with configurable external assets;
|
|
426
483
|
* pair it with {@link htmlResponse} (or your own `Response`) and serve from
|
|
427
484
|
* any route.
|
|
485
|
+
*
|
|
486
|
+
* @param opts Spec URL, page title, asset overrides, CSP nonce, and Scalar configuration.
|
|
487
|
+
* @returns The complete HTML document as a string.
|
|
488
|
+
* @throws {TypeError} when an SRI integrity value or `auth.loginUrl` is invalid.
|
|
428
489
|
*/
|
|
429
490
|
export declare function scalarHtml(opts: ScalarHtmlOptions): string;
|
|
430
491
|
/**
|
|
@@ -434,6 +495,10 @@ export declare function scalarHtml(opts: ScalarHtmlOptions): string;
|
|
|
434
495
|
* Developer-entered credentials are persisted by default
|
|
435
496
|
* (`persistAuthorization: true`) so routes with OpenAPI security requirements
|
|
436
497
|
* can be exercised after using Swagger UI's Authorize dialog.
|
|
498
|
+
*
|
|
499
|
+
* @param opts Spec URL, page title, asset overrides, CSP nonce, and Swagger UI configuration.
|
|
500
|
+
* @returns The complete HTML document as a string.
|
|
501
|
+
* @throws {TypeError} when an SRI integrity value or `auth.loginUrl` is invalid.
|
|
437
502
|
*/
|
|
438
503
|
export declare function swaggerUiHtml(opts: SwaggerUiHtmlOptions): string;
|
|
439
504
|
/**
|
|
@@ -448,6 +513,9 @@ export declare function swaggerUiHtml(opts: SwaggerUiHtmlOptions): string;
|
|
|
448
513
|
* you). The spec URL and configuration are embedded with `<`-escaped JSON so
|
|
449
514
|
* an attacker-controlled value cannot break out of the inline `<script>`.
|
|
450
515
|
*
|
|
516
|
+
* @param opts Spec URL, page title, asset overrides, CSP nonce, and Redoc configuration.
|
|
517
|
+
* @returns The complete HTML document as a string.
|
|
518
|
+
* @throws {TypeError} when an SRI integrity value or `auth.loginUrl` is invalid.
|
|
451
519
|
* @since 0.39.0
|
|
452
520
|
*/
|
|
453
521
|
export declare function redocHtml(opts: RedocHtmlOptions): string;
|
|
@@ -465,6 +533,9 @@ export declare function redocHtml(opts: RedocHtmlOptions): string;
|
|
|
465
533
|
* and configuration are embedded with `<`-escaped JSON so an attacker-controlled
|
|
466
534
|
* value cannot break out of the inline `<script>`.
|
|
467
535
|
*
|
|
536
|
+
* @param opts Spec URL, page title, asset overrides, CSP nonce, and AsyncAPI configuration.
|
|
537
|
+
* @returns The complete HTML document as a string.
|
|
538
|
+
* @throws {TypeError} when an SRI integrity value is invalid.
|
|
468
539
|
* @since 0.42.0
|
|
469
540
|
*/
|
|
470
541
|
export declare function asyncapiHtml(opts: AsyncApiHtmlOptions): string;
|
|
@@ -474,11 +545,18 @@ export declare function asyncapiHtml(opts: AsyncApiHtmlOptions): string;
|
|
|
474
545
|
*
|
|
475
546
|
* Allows `'self'` plus the listed `assetOrigins` (default: jsDelivr) and
|
|
476
547
|
* either `'unsafe-inline'` or the provided `scriptNonce` for scripts.
|
|
548
|
+
*
|
|
549
|
+
* @param opts Asset/connect origins, script nonce, inline-style, and blob-worker toggles.
|
|
550
|
+
* @returns The policy string, ready for a `content-security-policy` header.
|
|
477
551
|
*/
|
|
478
552
|
export declare function docsContentSecurityPolicy(opts?: DocsContentSecurityPolicyOptions): string;
|
|
479
553
|
/**
|
|
480
554
|
* Wrap a docs HTML string in a `Response` with safe defaults:
|
|
481
555
|
* `text/html` content type, `nosniff`, `no-referrer`, and a CSP from
|
|
482
556
|
* {@link docsContentSecurityPolicy} (or a caller-supplied override).
|
|
557
|
+
*
|
|
558
|
+
* @param html The HTML document body to serve.
|
|
559
|
+
* @param opts CSP options, or a verbatim `contentSecurityPolicy` override.
|
|
560
|
+
* @returns A `Response` with the HTML body and hardened security headers.
|
|
483
561
|
*/
|
|
484
562
|
export declare function htmlResponse(html: string, opts?: HtmlResponseOptions): Response;
|
package/dist/docs.js
CHANGED
|
@@ -45,6 +45,10 @@ function integrityAttr(integrity, crossOrigin) {
|
|
|
45
45
|
* The output is a single HTML document with configurable external assets;
|
|
46
46
|
* pair it with {@link htmlResponse} (or your own `Response`) and serve from
|
|
47
47
|
* any route.
|
|
48
|
+
*
|
|
49
|
+
* @param opts Spec URL, page title, asset overrides, CSP nonce, and Scalar configuration.
|
|
50
|
+
* @returns The complete HTML document as a string.
|
|
51
|
+
* @throws {TypeError} when an SRI integrity value or `auth.loginUrl` is invalid.
|
|
48
52
|
*/
|
|
49
53
|
export function scalarHtml(opts) {
|
|
50
54
|
const title = escapeHtml(opts.title ?? "API Reference");
|
|
@@ -71,6 +75,10 @@ ${docsAuthLauncherHtml(opts.auth, opts.scriptNonce)}
|
|
|
71
75
|
* Developer-entered credentials are persisted by default
|
|
72
76
|
* (`persistAuthorization: true`) so routes with OpenAPI security requirements
|
|
73
77
|
* can be exercised after using Swagger UI's Authorize dialog.
|
|
78
|
+
*
|
|
79
|
+
* @param opts Spec URL, page title, asset overrides, CSP nonce, and Swagger UI configuration.
|
|
80
|
+
* @returns The complete HTML document as a string.
|
|
81
|
+
* @throws {TypeError} when an SRI integrity value or `auth.loginUrl` is invalid.
|
|
74
82
|
*/
|
|
75
83
|
export function swaggerUiHtml(opts) {
|
|
76
84
|
const title = escapeHtml(opts.title ?? "API Docs");
|
|
@@ -110,6 +118,9 @@ ${docsAuthLauncherHtml(opts.auth, opts.scriptNonce)}
|
|
|
110
118
|
* you). The spec URL and configuration are embedded with `<`-escaped JSON so
|
|
111
119
|
* an attacker-controlled value cannot break out of the inline `<script>`.
|
|
112
120
|
*
|
|
121
|
+
* @param opts Spec URL, page title, asset overrides, CSP nonce, and Redoc configuration.
|
|
122
|
+
* @returns The complete HTML document as a string.
|
|
123
|
+
* @throws {TypeError} when an SRI integrity value or `auth.loginUrl` is invalid.
|
|
113
124
|
* @since 0.39.0
|
|
114
125
|
*/
|
|
115
126
|
export function redocHtml(opts) {
|
|
@@ -145,6 +156,9 @@ ${docsAuthLauncherHtml(opts.auth, opts.scriptNonce)}
|
|
|
145
156
|
* and configuration are embedded with `<`-escaped JSON so an attacker-controlled
|
|
146
157
|
* value cannot break out of the inline `<script>`.
|
|
147
158
|
*
|
|
159
|
+
* @param opts Spec URL, page title, asset overrides, CSP nonce, and AsyncAPI configuration.
|
|
160
|
+
* @returns The complete HTML document as a string.
|
|
161
|
+
* @throws {TypeError} when an SRI integrity value is invalid.
|
|
148
162
|
* @since 0.42.0
|
|
149
163
|
*/
|
|
150
164
|
export function asyncapiHtml(opts) {
|
|
@@ -176,6 +190,9 @@ export function asyncapiHtml(opts) {
|
|
|
176
190
|
*
|
|
177
191
|
* Allows `'self'` plus the listed `assetOrigins` (default: jsDelivr) and
|
|
178
192
|
* either `'unsafe-inline'` or the provided `scriptNonce` for scripts.
|
|
193
|
+
*
|
|
194
|
+
* @param opts Asset/connect origins, script nonce, inline-style, and blob-worker toggles.
|
|
195
|
+
* @returns The policy string, ready for a `content-security-policy` header.
|
|
179
196
|
*/
|
|
180
197
|
export function docsContentSecurityPolicy(opts = {}) {
|
|
181
198
|
const assetOrigins = opts.assetOrigins ?? [JSDELIVR_ORIGIN];
|
|
@@ -206,6 +223,10 @@ export function docsContentSecurityPolicy(opts = {}) {
|
|
|
206
223
|
* Wrap a docs HTML string in a `Response` with safe defaults:
|
|
207
224
|
* `text/html` content type, `nosniff`, `no-referrer`, and a CSP from
|
|
208
225
|
* {@link docsContentSecurityPolicy} (or a caller-supplied override).
|
|
226
|
+
*
|
|
227
|
+
* @param html The HTML document body to serve.
|
|
228
|
+
* @param opts CSP options, or a verbatim `contentSecurityPolicy` override.
|
|
229
|
+
* @returns A `Response` with the HTML body and hardened security headers.
|
|
209
230
|
*/
|
|
210
231
|
export function htmlResponse(html, opts = {}) {
|
|
211
232
|
return new Response(html, {
|
package/dist/errors.d.ts
CHANGED
|
@@ -81,6 +81,7 @@ export declare const SAFE_CUSTOM_ERROR_RESPONSE_HEADERS: ReadonlySet<string>;
|
|
|
81
81
|
* @since 0.32.0
|
|
82
82
|
*/
|
|
83
83
|
export declare class MessageLeakError extends Error {
|
|
84
|
+
/** The refused headers, each with its name and the reason it was disallowed. */
|
|
84
85
|
readonly offendingHeaders: ReadonlyArray<{
|
|
85
86
|
name: string;
|
|
86
87
|
reason: string;
|
|
@@ -93,6 +94,10 @@ export declare class MessageLeakError extends Error {
|
|
|
93
94
|
/**
|
|
94
95
|
* @internal — header-safety check applied by {@link httpError} when a custom
|
|
95
96
|
* `res` is supplied. Exported for audits and tests.
|
|
97
|
+
*
|
|
98
|
+
* @param headers Headers of the caller-supplied custom error `Response`.
|
|
99
|
+
* @returns The disallowed headers (name plus refusal reason); an empty array
|
|
100
|
+
* means every header passed the safe-error-response allowlist.
|
|
96
101
|
*/
|
|
97
102
|
export declare function checkCustomErrorResponseHeaders(headers: Headers): Array<{
|
|
98
103
|
name: string;
|
|
@@ -108,7 +113,9 @@ export declare function checkCustomErrorResponseHeaders(headers: Headers): Array
|
|
|
108
113
|
* @since 0.32.0
|
|
109
114
|
*/
|
|
110
115
|
export interface HttpErrorOptions {
|
|
116
|
+
/** HTTP status code for the rendered problem+json response. */
|
|
111
117
|
status: number;
|
|
118
|
+
/** RFC 9457 problem document fields; `title` is required. */
|
|
112
119
|
problem: Partial<ProblemDetails> & {
|
|
113
120
|
title: string;
|
|
114
121
|
};
|
|
@@ -136,6 +143,12 @@ export interface HttpErrorOptions {
|
|
|
136
143
|
* Build an {@link HttpError} with optional safe-header extraction from a
|
|
137
144
|
* custom `Response`. See {@link HttpErrorOptions}.
|
|
138
145
|
*
|
|
146
|
+
* @param opts Status, problem document, plain headers, and the optional
|
|
147
|
+
* custom `res` whose safe headers are merged (never overwriting
|
|
148
|
+
* caller-supplied headers; `Content-Length` is always dropped).
|
|
149
|
+
* @returns The constructed {@link HttpError}, ready to be thrown.
|
|
150
|
+
* @throws MessageLeakError in production under `secureDefaults` when the
|
|
151
|
+
* custom `res` carries headers outside the safe allowlist.
|
|
139
152
|
* @since 0.32.0
|
|
140
153
|
*/
|
|
141
154
|
export declare function httpError(opts: HttpErrorOptions): HttpError;
|
|
@@ -178,8 +191,11 @@ export declare function httpError(opts: HttpErrorOptions): HttpError;
|
|
|
178
191
|
* @since 0.1.0
|
|
179
192
|
*/
|
|
180
193
|
export declare class HttpError extends Error {
|
|
194
|
+
/** HTTP status code of the rendered response. */
|
|
181
195
|
readonly status: number;
|
|
196
|
+
/** RFC 9457 problem document; `type` defaults to `https://httpstatuses.io/<status>`. */
|
|
182
197
|
readonly problem: ProblemDetails;
|
|
198
|
+
/** Extra response headers (e.g. `Retry-After`, `Allow`) merged onto the response. */
|
|
183
199
|
readonly headers?: Record<string, string>;
|
|
184
200
|
constructor(status: number, problem: Partial<ProblemDetails> & {
|
|
185
201
|
title: string;
|