@daloyjs/core 1.0.0-beta.6 → 1.0.0-rc.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.
Files changed (99) hide show
  1. package/README.md +2 -2
  2. package/dist/adapters/bun.d.ts +13 -1
  3. package/dist/adapters/bun.js +8 -1
  4. package/dist/adapters/cloudflare.d.ts +7 -1
  5. package/dist/adapters/cloudflare.js +6 -1
  6. package/dist/adapters/deno.d.ts +11 -1
  7. package/dist/adapters/deno.js +8 -1
  8. package/dist/adapters/fastly.d.ts +12 -2
  9. package/dist/adapters/fastly.js +12 -2
  10. package/dist/adapters/lambda.d.ts +37 -1
  11. package/dist/adapters/lambda.js +6 -1
  12. package/dist/adapters/node.d.ts +12 -1
  13. package/dist/adapters/node.js +223 -12
  14. package/dist/adapters/vercel.d.ts +13 -1
  15. package/dist/adapters/vercel.js +12 -1
  16. package/dist/app.d.ts +78 -17
  17. package/dist/app.js +444 -86
  18. package/dist/banner.d.ts +6 -0
  19. package/dist/banner.js +6 -0
  20. package/dist/cli.d.ts +35 -0
  21. package/dist/cli.js +23 -1
  22. package/dist/combine.d.ts +8 -0
  23. package/dist/combine.js +8 -0
  24. package/dist/compression.d.ts +3 -0
  25. package/dist/compression.js +3 -0
  26. package/dist/config.d.ts +4 -0
  27. package/dist/config.js +4 -0
  28. package/dist/conn-info.d.ts +35 -2
  29. package/dist/conn-info.js +35 -2
  30. package/dist/contract.d.ts +2 -0
  31. package/dist/contract.js +2 -0
  32. package/dist/cookie.d.ts +12 -0
  33. package/dist/cookie.js +12 -0
  34. package/dist/dependency.d.ts +4 -0
  35. package/dist/dependency.js +3 -0
  36. package/dist/discriminator.d.ts +13 -0
  37. package/dist/discriminator.js +23 -1
  38. package/dist/docs.d.ts +78 -0
  39. package/dist/docs.js +21 -0
  40. package/dist/errors.d.ts +16 -0
  41. package/dist/errors.js +14 -0
  42. package/dist/etag.d.ts +2 -0
  43. package/dist/etag.js +2 -0
  44. package/dist/fetch-guard.d.ts +7 -0
  45. package/dist/fetch-guard.js +7 -0
  46. package/dist/fetch-resilience.d.ts +4 -0
  47. package/dist/fetch-resilience.js +4 -0
  48. package/dist/http-signatures.d.ts +32 -0
  49. package/dist/http-signatures.js +30 -0
  50. package/dist/index.d.ts +1 -1
  51. package/dist/ip-restriction.d.ts +40 -3
  52. package/dist/ip-restriction.js +35 -3
  53. package/dist/jwk.d.ts +12 -1
  54. package/dist/jwk.js +6 -0
  55. package/dist/jwt.d.ts +14 -0
  56. package/dist/jwt.js +10 -0
  57. package/dist/load-shedding.d.ts +3 -0
  58. package/dist/load-shedding.js +3 -0
  59. package/dist/logger.d.ts +13 -0
  60. package/dist/logger.js +3 -0
  61. package/dist/mcp.d.ts +152 -10
  62. package/dist/mcp.js +223 -19
  63. package/dist/middleware.d.ts +68 -0
  64. package/dist/middleware.js +17 -0
  65. package/dist/mtls.d.ts +19 -2
  66. package/dist/mtls.js +12 -2
  67. package/dist/multipart.d.ts +42 -5
  68. package/dist/multipart.js +41 -5
  69. package/dist/openapi.d.ts +15 -9
  70. package/dist/openapi.js +6 -9
  71. package/dist/rate-limit-redis.d.ts +21 -2
  72. package/dist/rate-limit-redis.js +17 -2
  73. package/dist/safe-redirect.d.ts +6 -0
  74. package/dist/safe-redirect.js +6 -0
  75. package/dist/sbom.cdx.json +9 -9
  76. package/dist/sbom.spdx.json +5 -5
  77. package/dist/scheduler.d.ts +4 -0
  78. package/dist/schema.d.ts +25 -0
  79. package/dist/security-schemes.d.ts +50 -0
  80. package/dist/security-schemes.js +6 -0
  81. package/dist/security.d.ts +33 -0
  82. package/dist/security.js +28 -10
  83. package/dist/session.d.ts +34 -5
  84. package/dist/session.js +31 -5
  85. package/dist/streaming.d.ts +19 -0
  86. package/dist/streaming.js +16 -0
  87. package/dist/subdomains.d.ts +4 -0
  88. package/dist/subdomains.js +4 -0
  89. package/dist/time-claims.d.ts +22 -2
  90. package/dist/time-claims.js +6 -0
  91. package/dist/tracing.d.ts +12 -0
  92. package/dist/tracing.js +6 -0
  93. package/dist/types.d.ts +70 -1
  94. package/dist/waf.js +21 -1
  95. package/dist/webhook-delivery.d.ts +6 -0
  96. package/dist/webhook-delivery.js +5 -0
  97. package/dist/websocket.d.ts +137 -4
  98. package/dist/websocket.js +105 -4
  99. package/package.json +1 -1
@@ -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
- const variant = variants[discriminatorValue];
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;
package/dist/errors.js CHANGED
@@ -37,6 +37,7 @@ export const SAFE_CUSTOM_ERROR_RESPONSE_HEADERS = new Set([
37
37
  * @since 0.32.0
38
38
  */
39
39
  export class MessageLeakError extends Error {
40
+ /** The refused headers, each with its name and the reason it was disallowed. */
40
41
  offendingHeaders;
41
42
  constructor(offendingHeaders) {
42
43
  const summary = offendingHeaders
@@ -53,6 +54,10 @@ export class MessageLeakError extends Error {
53
54
  /**
54
55
  * @internal — header-safety check applied by {@link httpError} when a custom
55
56
  * `res` is supplied. Exported for audits and tests.
57
+ *
58
+ * @param headers Headers of the caller-supplied custom error `Response`.
59
+ * @returns The disallowed headers (name plus refusal reason); an empty array
60
+ * means every header passed the safe-error-response allowlist.
56
61
  */
57
62
  export function checkCustomErrorResponseHeaders(headers) {
58
63
  const offending = [];
@@ -111,6 +116,12 @@ function shouldCopyCustomErrorHeader(name, value) {
111
116
  * Build an {@link HttpError} with optional safe-header extraction from a
112
117
  * custom `Response`. See {@link HttpErrorOptions}.
113
118
  *
119
+ * @param opts Status, problem document, plain headers, and the optional
120
+ * custom `res` whose safe headers are merged (never overwriting
121
+ * caller-supplied headers; `Content-Length` is always dropped).
122
+ * @returns The constructed {@link HttpError}, ready to be thrown.
123
+ * @throws MessageLeakError in production under `secureDefaults` when the
124
+ * custom `res` carries headers outside the safe allowlist.
114
125
  * @since 0.32.0
115
126
  */
116
127
  export function httpError(opts) {
@@ -173,8 +184,11 @@ export function httpError(opts) {
173
184
  * @since 0.1.0
174
185
  */
175
186
  export class HttpError extends Error {
187
+ /** HTTP status code of the rendered response. */
176
188
  status;
189
+ /** RFC 9457 problem document; `type` defaults to `https://httpstatuses.io/<status>`. */
177
190
  problem;
191
+ /** Extra response headers (e.g. `Retry-After`, `Allow`) merged onto the response. */
178
192
  headers;
179
193
  constructor(status, problem, headers) {
180
194
  super(problem.title);
package/dist/etag.d.ts CHANGED
@@ -42,6 +42,8 @@ export interface ETagOptions {
42
42
  * app.use(etag());
43
43
  * ```
44
44
  *
45
+ * @param opts - `weak: true` emits `W/"..."` weak validators (default strong); `generator` replaces the default SHA-1 body digest.
46
+ * @returns A {@link Hooks} bundle (an `onSend` hook) to compose via `app.use()`.
45
47
  * @since 0.21.0
46
48
  */
47
49
  export declare function etag(opts?: ETagOptions): Hooks;
package/dist/etag.js CHANGED
@@ -71,6 +71,8 @@ function inmMatches(headerValue, candidate) {
71
71
  * app.use(etag());
72
72
  * ```
73
73
  *
74
+ * @param opts - `weak: true` emits `W/"..."` weak validators (default strong); `generator` replaces the default SHA-1 body digest.
75
+ * @returns A {@link Hooks} bundle (an `onSend` hook) to compose via `app.use()`.
74
76
  * @since 0.21.0
75
77
  */
76
78
  export function etag(opts = {}) {
@@ -102,8 +102,11 @@ export type SsrfBlockReason = "protocol-not-allowed" | "host-not-allowed" | "dns
102
102
  * @since 0.34.0
103
103
  */
104
104
  export declare class SsrfBlockedError extends Error {
105
+ /** The request URL (or redirect target) that was refused. */
105
106
  readonly url: string;
107
+ /** Machine-readable {@link SsrfBlockReason} explaining the refusal. */
106
108
  readonly reason: SsrfBlockReason;
109
+ /** The resolved IP that tripped the guard, when the block was address-based. */
107
110
  readonly address?: string;
108
111
  constructor(url: string, reason: SsrfBlockReason, address?: string);
109
112
  }
@@ -240,6 +243,10 @@ export interface FetchGuardOptions {
240
243
  * });
241
244
  * ```
242
245
  *
246
+ * @param options - Guard configuration; see {@link FetchGuardOptions}. Omit
247
+ * for the strict default posture (public IPs over `http:`/`https:` only).
248
+ * @returns A `fetch`-compatible function that validates every hop (including
249
+ * redirects) and throws {@link SsrfBlockedError} on refusal.
243
250
  * @since 0.34.0
244
251
  */
245
252
  export declare function fetchGuard(options?: FetchGuardOptions): typeof fetch;
@@ -96,8 +96,11 @@ import { compileCidrMatcher, matchesMatcher, parseIp } from "./ip-restriction.js
96
96
  * @since 0.34.0
97
97
  */
98
98
  export class SsrfBlockedError extends Error {
99
+ /** The request URL (or redirect target) that was refused. */
99
100
  url;
101
+ /** Machine-readable {@link SsrfBlockReason} explaining the refusal. */
100
102
  reason;
103
+ /** The resolved IP that tripped the guard, when the block was address-based. */
101
104
  address;
102
105
  constructor(url, reason, address) {
103
106
  const where = address ? ` -> ${address}` : "";
@@ -155,6 +158,10 @@ const UNIQUE_LOCAL = ["fc00::/7"];
155
158
  * });
156
159
  * ```
157
160
  *
161
+ * @param options - Guard configuration; see {@link FetchGuardOptions}. Omit
162
+ * for the strict default posture (public IPs over `http:`/`https:` only).
163
+ * @returns A `fetch`-compatible function that validates every hop (including
164
+ * redirects) and throws {@link SsrfBlockedError} on refusal.
158
165
  * @since 0.34.0
159
166
  */
160
167
  export function fetchGuard(options = {}) {
@@ -290,6 +290,10 @@ export interface ResilientFetchOptions {
290
290
  * const safeFetch = resilientFetch({ fetch: fetchGuard(), timeoutMs: 2_000 });
291
291
  * ```
292
292
  *
293
+ * @param options - Timeout (default 10000 ms), retry policy (default 2 retries, exponential backoff with jitter, `Retry-After` respected), circuit-breaker config (`false` disables), and the base `fetch`.
294
+ * @returns A drop-in `fetch` replacement applying the configured resilience layers.
295
+ * @throws {Error} When no global `fetch` exists and `options.fetch` is not provided.
296
+ * @throws {RangeError} When `timeoutMs` is negative/non-finite or `retries` is not a non-negative integer.
293
297
  * @since 0.37.0
294
298
  */
295
299
  export declare function resilientFetch(options?: ResilientFetchOptions): typeof fetch;
@@ -355,6 +355,10 @@ function isAbortError(err) {
355
355
  * const safeFetch = resilientFetch({ fetch: fetchGuard(), timeoutMs: 2_000 });
356
356
  * ```
357
357
  *
358
+ * @param options - Timeout (default 10000 ms), retry policy (default 2 retries, exponential backoff with jitter, `Retry-After` respected), circuit-breaker config (`false` disables), and the base `fetch`.
359
+ * @returns A drop-in `fetch` replacement applying the configured resilience layers.
360
+ * @throws {Error} When no global `fetch` exists and `options.fetch` is not provided.
361
+ * @throws {RangeError} When `timeoutMs` is negative/non-finite or `retries` is not a non-negative integer.
358
362
  * @since 0.37.0
359
363
  */
360
364
  export function resilientFetch(options = {}) {
@@ -129,6 +129,10 @@ export interface MessageSignature {
129
129
  * Compute HTTP Message Signature header values (RFC 9421) over the described
130
130
  * message.
131
131
  *
132
+ * @param opts - Message description, covered components, algorithm, and key;
133
+ * see {@link SignMessageOptions}.
134
+ * @returns The `Signature-Input` / `Signature` header values plus the exact
135
+ * signature base that was signed.
132
136
  * @throws {TypeError} for unsupported algorithms, weak HMAC keys, or
133
137
  * unserializable parameter values.
134
138
  * @throws {Error} when a covered component cannot be resolved (e.g. a covered
@@ -148,6 +152,11 @@ export type SignRequestOptions = Omit<SignMessageOptions, "method" | "url" | "he
148
152
  * `Signature` and `Signature-Input` headers attached. The original request is
149
153
  * not mutated.
150
154
  *
155
+ * @param request - The outbound request to sign; its method, URL, and headers
156
+ * form the signature base.
157
+ * @param opts - Signing options minus the per-message fields; see
158
+ * {@link SignRequestOptions}.
159
+ * @returns A new `Request` carrying the signature headers.
151
160
  * @since 0.37.0
152
161
  */
153
162
  export declare function signRequest(request: Request, opts: SignRequestOptions): Promise<Request>;
@@ -164,6 +173,7 @@ export interface KeyResolutionInfo {
164
173
  }
165
174
  /** Successful verification result. */
166
175
  export interface VerifySuccess {
176
+ /** Discriminant: always `true` on success. */
167
177
  valid: true;
168
178
  /** The verified signature label. */
169
179
  label: string;
@@ -184,6 +194,7 @@ export interface VerifySuccess {
184
194
  }
185
195
  /** Failed verification result. Never throws on a bad signature. */
186
196
  export interface VerifyFailure {
197
+ /** Discriminant: always `false` on failure. */
187
198
  valid: false;
188
199
  /** Stable machine-readable reason code. */
189
200
  reason: string;
@@ -242,6 +253,13 @@ export interface VerifyMessageOptions {
242
253
  * structured result and never throws on a bad/forged signature — only on a
243
254
  * programming error (e.g. WebCrypto unavailable).
244
255
  *
256
+ * @param opts - Received message plus verification policy (algorithm
257
+ * allowlist, key resolver, freshness / replay checks); see
258
+ * {@link VerifyMessageOptions}.
259
+ * @returns A {@link VerifySuccess} with the verified parameters, or a
260
+ * {@link VerifyFailure} with a stable `reason` code.
261
+ * @throws {TypeError} when the `algorithms` allowlist is missing or empty;
262
+ * there is no implicit "accept any" mode.
245
263
  * @since 0.37.0
246
264
  */
247
265
  export declare function verifyMessage(opts: VerifyMessageOptions): Promise<VerifyResult>;
@@ -250,6 +268,9 @@ export declare function verifyMessage(opts: VerifyMessageOptions): Promise<Verif
250
268
  * over {@link verifyMessage} that pulls the method, URL, and headers from the
251
269
  * request.
252
270
  *
271
+ * @param request - The inbound request carrying `Signature` / `Signature-Input`.
272
+ * @param opts - Verification policy minus the per-message fields.
273
+ * @returns The {@link VerifyResult}; never rejects on a bad signature.
253
274
  * @since 0.37.0
254
275
  */
255
276
  export declare function verifyRequest(request: Request, opts: Omit<VerifyMessageOptions, "method" | "url" | "headers" | "status">): Promise<VerifyResult>;
@@ -277,6 +298,9 @@ export interface HttpSignatureAuthOptions extends Omit<VerifyMessageOptions, "me
277
298
  * a missing (unless `optional`) or invalid signature it throws
278
299
  * {@link UnauthorizedError} (`401` + `Cache-Control: no-store`).
279
300
  *
301
+ * @param opts - Verification policy plus middleware knobs; see
302
+ * {@link HttpSignatureAuthOptions}.
303
+ * @returns A {@link Hooks} object to pass to `app.use()` or a route's `hooks`.
280
304
  * @since 0.37.0
281
305
  */
282
306
  export declare function httpSignatureAuth(opts: HttpSignatureAuthOptions): Hooks;
@@ -288,6 +312,10 @@ export type ContentDigestAlgorithm = "sha-256" | "sha-512";
288
312
  * bind the request body into the signature, then re-check it against the
289
313
  * received body with {@link verifyContentDigest}.
290
314
  *
315
+ * @param body - Raw body bytes, or a string encoded as UTF-8.
316
+ * @param opts - Optional `algorithm` choice. Defaults to `"sha-256"`.
317
+ * @returns The structured-field header value, e.g. `sha-256=:<base64>:`.
318
+ * @throws {TypeError} for an unsupported digest algorithm.
291
319
  * @since 0.37.0
292
320
  */
293
321
  export declare function contentDigest(body: Uint8Array | string, opts?: {
@@ -298,6 +326,10 @@ export declare function contentDigest(body: Uint8Array | string, opts?: {
298
326
  * Returns `false` for any malformed header or mismatch (never throws on bad
299
327
  * input). Only `sha-256` / `sha-512` members are considered.
300
328
  *
329
+ * @param header - The received `Content-Digest` header value.
330
+ * @param body - Raw body bytes, or a string encoded as UTF-8.
331
+ * @returns `true` only when at least one supported digest member matched
332
+ * (compared in constant time); `false` for mismatch or malformed input.
301
333
  * @since 0.37.0
302
334
  */
303
335
  export declare function verifyContentDigest(header: string, body: Uint8Array | string): Promise<boolean>;
@@ -471,6 +471,10 @@ function parseComponentSpec(spec) {
471
471
  * Compute HTTP Message Signature header values (RFC 9421) over the described
472
472
  * message.
473
473
  *
474
+ * @param opts - Message description, covered components, algorithm, and key;
475
+ * see {@link SignMessageOptions}.
476
+ * @returns The `Signature-Input` / `Signature` header values plus the exact
477
+ * signature base that was signed.
474
478
  * @throws {TypeError} for unsupported algorithms, weak HMAC keys, or
475
479
  * unserializable parameter values.
476
480
  * @throws {Error} when a covered component cannot be resolved (e.g. a covered
@@ -513,6 +517,11 @@ export async function signMessage(opts) {
513
517
  * `Signature` and `Signature-Input` headers attached. The original request is
514
518
  * not mutated.
515
519
  *
520
+ * @param request - The outbound request to sign; its method, URL, and headers
521
+ * form the signature base.
522
+ * @param opts - Signing options minus the per-message fields; see
523
+ * {@link SignRequestOptions}.
524
+ * @returns A new `Request` carrying the signature headers.
516
525
  * @since 0.37.0
517
526
  */
518
527
  export async function signRequest(request, opts) {
@@ -535,6 +544,13 @@ function fail(reason) {
535
544
  * structured result and never throws on a bad/forged signature — only on a
536
545
  * programming error (e.g. WebCrypto unavailable).
537
546
  *
547
+ * @param opts - Received message plus verification policy (algorithm
548
+ * allowlist, key resolver, freshness / replay checks); see
549
+ * {@link VerifyMessageOptions}.
550
+ * @returns A {@link VerifySuccess} with the verified parameters, or a
551
+ * {@link VerifyFailure} with a stable `reason` code.
552
+ * @throws {TypeError} when the `algorithms` allowlist is missing or empty;
553
+ * there is no implicit "accept any" mode.
538
554
  * @since 0.37.0
539
555
  */
540
556
  export async function verifyMessage(opts) {
@@ -688,6 +704,9 @@ export async function verifyMessage(opts) {
688
704
  * over {@link verifyMessage} that pulls the method, URL, and headers from the
689
705
  * request.
690
706
  *
707
+ * @param request - The inbound request carrying `Signature` / `Signature-Input`.
708
+ * @param opts - Verification policy minus the per-message fields.
709
+ * @returns The {@link VerifyResult}; never rejects on a bad signature.
691
710
  * @since 0.37.0
692
711
  */
693
712
  export function verifyRequest(request, opts) {
@@ -704,6 +723,9 @@ export function verifyRequest(request, opts) {
704
723
  * a missing (unless `optional`) or invalid signature it throws
705
724
  * {@link UnauthorizedError} (`401` + `Cache-Control: no-store`).
706
725
  *
726
+ * @param opts - Verification policy plus middleware knobs; see
727
+ * {@link HttpSignatureAuthOptions}.
728
+ * @returns A {@link Hooks} object to pass to `app.use()` or a route's `hooks`.
707
729
  * @since 0.37.0
708
730
  */
709
731
  export function httpSignatureAuth(opts) {
@@ -736,6 +758,10 @@ function toBytes(body) {
736
758
  * bind the request body into the signature, then re-check it against the
737
759
  * received body with {@link verifyContentDigest}.
738
760
  *
761
+ * @param body - Raw body bytes, or a string encoded as UTF-8.
762
+ * @param opts - Optional `algorithm` choice. Defaults to `"sha-256"`.
763
+ * @returns The structured-field header value, e.g. `sha-256=:<base64>:`.
764
+ * @throws {TypeError} for an unsupported digest algorithm.
739
765
  * @since 0.37.0
740
766
  */
741
767
  export async function contentDigest(body, opts = {}) {
@@ -752,6 +778,10 @@ export async function contentDigest(body, opts = {}) {
752
778
  * Returns `false` for any malformed header or mismatch (never throws on bad
753
779
  * input). Only `sha-256` / `sha-512` members are considered.
754
780
  *
781
+ * @param header - The received `Content-Digest` header value.
782
+ * @param body - Raw body bytes, or a string encoded as UTF-8.
783
+ * @returns `true` only when at least one supported digest member matched
784
+ * (compared in constant time); `false` for mismatch or malformed input.
755
785
  * @since 0.37.0
756
786
  */
757
787
  export async function verifyContentDigest(header, body) {