hono-problem-details 0.1.6 → 0.1.8
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/{chunk-LMBOCQPX.js → chunk-GMDHMECS.js} +14 -3
- package/dist/chunk-GMDHMECS.js.map +1 -0
- package/dist/{chunk-X2MUB5YP.js → chunk-XPBA7IIJ.js} +2 -2
- package/dist/chunk-XPBA7IIJ.js.map +1 -0
- package/dist/index.cjs +5 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/integrations/standard-schema.cjs +12 -1
- package/dist/integrations/standard-schema.cjs.map +1 -1
- package/dist/integrations/standard-schema.js +2 -2
- package/dist/integrations/valibot.cjs +12 -1
- package/dist/integrations/valibot.cjs.map +1 -1
- package/dist/integrations/valibot.d.cts +2 -2
- package/dist/integrations/valibot.d.ts +2 -2
- package/dist/integrations/valibot.js +2 -2
- package/dist/integrations/valibot.js.map +1 -1
- package/dist/integrations/zod.cjs +12 -1
- package/dist/integrations/zod.cjs.map +1 -1
- package/dist/integrations/zod.js +2 -2
- package/package.json +2 -2
- package/dist/chunk-LMBOCQPX.js.map +0 -1
- package/dist/chunk-X2MUB5YP.js.map +0 -1
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
2
|
PROBLEM_JSON_CONTENT_TYPE
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-XPBA7IIJ.js";
|
|
4
4
|
|
|
5
5
|
// src/integrations/validation.ts
|
|
6
|
+
var CONTROL_CHAR_RE = /[\x00-\x1f\x7f]/g;
|
|
7
|
+
function stripControlChars(input) {
|
|
8
|
+
return input.replace(CONTROL_CHAR_RE, "");
|
|
9
|
+
}
|
|
10
|
+
function sanitizeError(error) {
|
|
11
|
+
return {
|
|
12
|
+
field: stripControlChars(error.field),
|
|
13
|
+
message: stripControlChars(error.message),
|
|
14
|
+
...error.code !== void 0 ? { code: stripControlChars(error.code) } : {}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
6
17
|
function buildValidationResponse(errors, options) {
|
|
7
18
|
const body = {
|
|
8
19
|
type: "about:blank",
|
|
9
20
|
status: 422,
|
|
10
21
|
title: options?.title ?? "Validation Error",
|
|
11
22
|
detail: options?.detail ?? "Request validation failed",
|
|
12
|
-
errors
|
|
23
|
+
errors: errors.map(sanitizeError)
|
|
13
24
|
};
|
|
14
25
|
return new Response(JSON.stringify(body), {
|
|
15
26
|
status: 422,
|
|
@@ -20,4 +31,4 @@ function buildValidationResponse(errors, options) {
|
|
|
20
31
|
export {
|
|
21
32
|
buildValidationResponse
|
|
22
33
|
};
|
|
23
|
-
//# sourceMappingURL=chunk-
|
|
34
|
+
//# sourceMappingURL=chunk-GMDHMECS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/integrations/validation.ts"],"sourcesContent":["import { PROBLEM_JSON_CONTENT_TYPE } from \"../utils.js\";\n\nexport interface ValidationError {\n\tfield: string;\n\tmessage: string;\n\tcode?: string;\n}\n\nexport interface ValidationHookOptions {\n\ttitle?: string;\n\tdetail?: string;\n}\n\n/**\n * Strip C0 control characters (\\x00-\\x1f) and DEL (\\x7f) from untrusted text.\n * Bidi/format control chars (U+2028, U+202E, etc.) are intentionally left intact\n * to avoid breaking legitimate i18n content; log consumers should apply their\n * own bidi-safe rendering.\n */\n// biome-ignore lint/suspicious/noControlCharactersInRegex: intentional stripping of C0 controls\nconst CONTROL_CHAR_RE = /[\\x00-\\x1f\\x7f]/g;\n\nfunction stripControlChars(input: string): string {\n\treturn input.replace(CONTROL_CHAR_RE, \"\");\n}\n\nfunction sanitizeError(error: ValidationError): ValidationError {\n\treturn {\n\t\tfield: stripControlChars(error.field),\n\t\tmessage: stripControlChars(error.message),\n\t\t...(error.code !== undefined ? { code: stripControlChars(error.code) } : {}),\n\t};\n}\n\n/** Build a RFC 9457 validation error response from formatted errors */\nexport function buildValidationResponse(\n\terrors: ValidationError[],\n\toptions?: ValidationHookOptions,\n): Response {\n\tconst body = {\n\t\ttype: \"about:blank\",\n\t\tstatus: 422,\n\t\ttitle: options?.title ?? \"Validation Error\",\n\t\tdetail: options?.detail ?? \"Request validation failed\",\n\t\terrors: errors.map(sanitizeError),\n\t};\n\n\treturn new Response(JSON.stringify(body), {\n\t\tstatus: 422,\n\t\theaders: { \"Content-Type\": PROBLEM_JSON_CONTENT_TYPE },\n\t});\n}\n"],"mappings":";;;;;AAoBA,IAAM,kBAAkB;AAExB,SAAS,kBAAkB,OAAuB;AACjD,SAAO,MAAM,QAAQ,iBAAiB,EAAE;AACzC;AAEA,SAAS,cAAc,OAAyC;AAC/D,SAAO;AAAA,IACN,OAAO,kBAAkB,MAAM,KAAK;AAAA,IACpC,SAAS,kBAAkB,MAAM,OAAO;AAAA,IACxC,GAAI,MAAM,SAAS,SAAY,EAAE,MAAM,kBAAkB,MAAM,IAAI,EAAE,IAAI,CAAC;AAAA,EAC3E;AACD;AAGO,SAAS,wBACf,QACA,SACW;AACX,QAAM,OAAO;AAAA,IACZ,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,OAAO,SAAS,SAAS;AAAA,IACzB,QAAQ,SAAS,UAAU;AAAA,IAC3B,QAAQ,OAAO,IAAI,aAAa;AAAA,EACjC;AAEA,SAAO,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG;AAAA,IACzC,QAAQ;AAAA,IACR,SAAS,EAAE,gBAAgB,0BAA0B;AAAA,EACtD,CAAC;AACF;","names":[]}
|
|
@@ -17,7 +17,7 @@ function sanitizeExtensions(extensions) {
|
|
|
17
17
|
return filtered ?? extensions;
|
|
18
18
|
}
|
|
19
19
|
function clampHttpStatus(status) {
|
|
20
|
-
return status >= 200 && status <= 599 ? status : 500;
|
|
20
|
+
return Number.isInteger(status) && status >= 200 && status <= 599 ? status : 500;
|
|
21
21
|
}
|
|
22
22
|
var FALLBACK_BODY = JSON.stringify({
|
|
23
23
|
type: "about:blank",
|
|
@@ -56,4 +56,4 @@ export {
|
|
|
56
56
|
normalizeProblemDetails,
|
|
57
57
|
buildProblemResponse
|
|
58
58
|
};
|
|
59
|
-
//# sourceMappingURL=chunk-
|
|
59
|
+
//# sourceMappingURL=chunk-XPBA7IIJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import { statusToPhrase } from \"./status.js\";\nimport type { ProblemDetails, ProblemDetailsInput } from \"./types.js\";\n\nexport const PROBLEM_JSON_CONTENT_TYPE = \"application/problem+json; charset=utf-8\";\n\nconst DANGEROUS_KEYS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\n/** Strip keys that could cause prototype pollution in downstream consumers */\nexport function sanitizeExtensions(\n\textensions: Record<string, unknown> | undefined,\n): Record<string, unknown> | undefined {\n\tif (!extensions) return extensions;\n\tlet filtered: Record<string, unknown> | undefined;\n\tfor (const key of Object.keys(extensions)) {\n\t\tif (DANGEROUS_KEYS.has(key)) {\n\t\t\tif (!filtered) filtered = { ...extensions };\n\t\t\tdelete filtered[key];\n\t\t}\n\t}\n\treturn filtered ?? extensions;\n}\n\n/** Clamp HTTP status to 200-599 integer range; returns 500 for out-of-range or non-integer values */\nexport function clampHttpStatus(status: number): number {\n\treturn Number.isInteger(status) && status >= 200 && status <= 599 ? status : 500;\n}\n\nconst FALLBACK_BODY = JSON.stringify({\n\ttype: \"about:blank\",\n\tstatus: 500,\n\ttitle: \"Internal Server Error\",\n});\n\n/** Normalize ProblemDetailsInput to ProblemDetails with defaults for type and title */\nexport function normalizeProblemDetails<T extends Record<string, unknown>>(\n\tinput: ProblemDetailsInput<T>,\n): ProblemDetails<T> {\n\treturn {\n\t\ttype: input.type ?? \"about:blank\",\n\t\tstatus: input.status,\n\t\ttitle: input.title ?? statusToPhrase(input.status) ?? \"Unknown Error\",\n\t\tdetail: input.detail,\n\t\tinstance: input.instance,\n\t\textensions: input.extensions,\n\t};\n}\n\n/** Build a RFC 9457 Problem Details Response from a ProblemDetails object */\nexport function buildProblemResponse(pd: ProblemDetails): Response {\n\tconst { extensions, ...standard } = pd;\n\tconst body = { ...sanitizeExtensions(extensions), ...standard };\n\tconst { json, fallback } = safeStringify(body);\n\treturn new Response(json, {\n\t\tstatus: fallback ? 500 : clampHttpStatus(pd.status),\n\t\theaders: { \"Content-Type\": PROBLEM_JSON_CONTENT_TYPE },\n\t});\n}\n\n/** JSON.stringify with fallback for non-serializable values (circular refs, BigInt) */\nexport function safeStringify(body: unknown): { json: string; fallback: boolean } {\n\ttry {\n\t\treturn { json: JSON.stringify(body), fallback: false };\n\t} catch {\n\t\treturn { json: FALLBACK_BODY, fallback: true };\n\t}\n}\n"],"mappings":";;;;;AAGO,IAAM,4BAA4B;AAEzC,IAAM,iBAAiB,oBAAI,IAAI,CAAC,aAAa,eAAe,WAAW,CAAC;AAGjE,SAAS,mBACf,YACsC;AACtC,MAAI,CAAC,WAAY,QAAO;AACxB,MAAI;AACJ,aAAW,OAAO,OAAO,KAAK,UAAU,GAAG;AAC1C,QAAI,eAAe,IAAI,GAAG,GAAG;AAC5B,UAAI,CAAC,SAAU,YAAW,EAAE,GAAG,WAAW;AAC1C,aAAO,SAAS,GAAG;AAAA,IACpB;AAAA,EACD;AACA,SAAO,YAAY;AACpB;AAGO,SAAS,gBAAgB,QAAwB;AACvD,SAAO,OAAO,UAAU,MAAM,KAAK,UAAU,OAAO,UAAU,MAAM,SAAS;AAC9E;AAEA,IAAM,gBAAgB,KAAK,UAAU;AAAA,EACpC,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AACR,CAAC;AAGM,SAAS,wBACf,OACoB;AACpB,SAAO;AAAA,IACN,MAAM,MAAM,QAAQ;AAAA,IACpB,QAAQ,MAAM;AAAA,IACd,OAAO,MAAM,SAAS,eAAe,MAAM,MAAM,KAAK;AAAA,IACtD,QAAQ,MAAM;AAAA,IACd,UAAU,MAAM;AAAA,IAChB,YAAY,MAAM;AAAA,EACnB;AACD;AAGO,SAAS,qBAAqB,IAA8B;AAClE,QAAM,EAAE,YAAY,GAAG,SAAS,IAAI;AACpC,QAAM,OAAO,EAAE,GAAG,mBAAmB,UAAU,GAAG,GAAG,SAAS;AAC9D,QAAM,EAAE,MAAM,SAAS,IAAI,cAAc,IAAI;AAC7C,SAAO,IAAI,SAAS,MAAM;AAAA,IACzB,QAAQ,WAAW,MAAM,gBAAgB,GAAG,MAAM;AAAA,IAClD,SAAS,EAAE,gBAAgB,0BAA0B;AAAA,EACtD,CAAC;AACF;AAGO,SAAS,cAAc,MAAoD;AACjF,MAAI;AACH,WAAO,EAAE,MAAM,KAAK,UAAU,IAAI,GAAG,UAAU,MAAM;AAAA,EACtD,QAAQ;AACP,WAAO,EAAE,MAAM,eAAe,UAAU,KAAK;AAAA,EAC9C;AACD;","names":[]}
|
package/dist/index.cjs
CHANGED
|
@@ -101,7 +101,7 @@ function sanitizeExtensions(extensions) {
|
|
|
101
101
|
return filtered ?? extensions;
|
|
102
102
|
}
|
|
103
103
|
function clampHttpStatus(status) {
|
|
104
|
-
return status >= 200 && status <= 599 ? status : 500;
|
|
104
|
+
return Number.isInteger(status) && status >= 200 && status <= 599 ? status : 500;
|
|
105
105
|
}
|
|
106
106
|
var FALLBACK_BODY = JSON.stringify({
|
|
107
107
|
type: "about:blank",
|
|
@@ -166,7 +166,10 @@ function buildType(status, options) {
|
|
|
166
166
|
function toResponse(input, c, options) {
|
|
167
167
|
let pd = normalizeProblemDetails(input);
|
|
168
168
|
if (options.localize) {
|
|
169
|
-
|
|
169
|
+
try {
|
|
170
|
+
pd = { ...pd, ...options.localize(pd, c) };
|
|
171
|
+
} catch {
|
|
172
|
+
}
|
|
170
173
|
}
|
|
171
174
|
c.set("problemDetails", pd);
|
|
172
175
|
return buildProblemResponse(pd);
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/status.ts","../src/utils.ts","../src/error.ts","../src/factory.ts","../src/handler.ts","../src/registry.ts"],"sourcesContent":["export type {\n\tProblemDetails,\n\tProblemDetailsHandlerOptions,\n\tProblemDetailsInput,\n} from \"./types.js\";\nexport { statusToPhrase, statusToSlug } from \"./status.js\";\nexport { ProblemDetailsError } from \"./error.js\";\nexport { problemDetails } from \"./factory.js\";\nexport { PROBLEM_JSON_CONTENT_TYPE } from \"./utils.js\";\nexport { problemDetailsHandler } from \"./handler.js\";\nexport { createProblemTypeRegistry } from \"./registry.js\";\n","const STATUS_PHRASES: Record<number, string> = {\n\t400: \"Bad Request\",\n\t401: \"Unauthorized\",\n\t402: \"Payment Required\",\n\t403: \"Forbidden\",\n\t404: \"Not Found\",\n\t405: \"Method Not Allowed\",\n\t406: \"Not Acceptable\",\n\t407: \"Proxy Authentication Required\",\n\t408: \"Request Timeout\",\n\t409: \"Conflict\",\n\t410: \"Gone\",\n\t411: \"Length Required\",\n\t412: \"Precondition Failed\",\n\t413: \"Content Too Large\",\n\t414: \"URI Too Long\",\n\t415: \"Unsupported Media Type\",\n\t416: \"Range Not Satisfiable\",\n\t417: \"Expectation Failed\",\n\t418: \"I'm a Teapot\",\n\t421: \"Misdirected Request\",\n\t422: \"Unprocessable Content\",\n\t423: \"Locked\",\n\t424: \"Failed Dependency\",\n\t425: \"Too Early\",\n\t426: \"Upgrade Required\",\n\t428: \"Precondition Required\",\n\t429: \"Too Many Requests\",\n\t431: \"Request Header Fields Too Large\",\n\t451: \"Unavailable For Legal Reasons\",\n\t500: \"Internal Server Error\",\n\t501: \"Not Implemented\",\n\t502: \"Bad Gateway\",\n\t503: \"Service Unavailable\",\n\t504: \"Gateway Timeout\",\n\t505: \"HTTP Version Not Supported\",\n\t506: \"Variant Also Negotiates\",\n\t507: \"Insufficient Storage\",\n\t508: \"Loop Detected\",\n\t510: \"Not Extended\",\n\t511: \"Network Authentication Required\",\n};\n\nconst STATUS_SLUGS: Record<number, string> = Object.fromEntries(\n\tObject.entries(STATUS_PHRASES).map(([code, phrase]) => [\n\t\tNumber(code),\n\t\tphrase\n\t\t\t.toLowerCase()\n\t\t\t.replace(/'/g, \"\")\n\t\t\t.replace(/[^a-z0-9]+/g, \"-\")\n\t\t\t.replace(/^-|-$/g, \"\"),\n\t]),\n);\n\nexport function statusToPhrase(status: number): string | undefined {\n\treturn STATUS_PHRASES[status];\n}\n\nexport function statusToSlug(status: number): string | undefined {\n\treturn STATUS_SLUGS[status];\n}\n","import { statusToPhrase } from \"./status.js\";\nimport type { ProblemDetails, ProblemDetailsInput } from \"./types.js\";\n\nexport const PROBLEM_JSON_CONTENT_TYPE = \"application/problem+json; charset=utf-8\";\n\nconst DANGEROUS_KEYS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\n/** Strip keys that could cause prototype pollution in downstream consumers */\nexport function sanitizeExtensions(\n\textensions: Record<string, unknown> | undefined,\n): Record<string, unknown> | undefined {\n\tif (!extensions) return extensions;\n\tlet filtered: Record<string, unknown> | undefined;\n\tfor (const key of Object.keys(extensions)) {\n\t\tif (DANGEROUS_KEYS.has(key)) {\n\t\t\tif (!filtered) filtered = { ...extensions };\n\t\t\tdelete filtered[key];\n\t\t}\n\t}\n\treturn filtered ?? extensions;\n}\n\n/** Clamp HTTP status to 200-599 range; returns 500 for out-of-range values */\nexport function clampHttpStatus(status: number): number {\n\treturn status >= 200 && status <= 599 ? status : 500;\n}\n\nconst FALLBACK_BODY = JSON.stringify({\n\ttype: \"about:blank\",\n\tstatus: 500,\n\ttitle: \"Internal Server Error\",\n});\n\n/** Normalize ProblemDetailsInput to ProblemDetails with defaults for type and title */\nexport function normalizeProblemDetails<T extends Record<string, unknown>>(\n\tinput: ProblemDetailsInput<T>,\n): ProblemDetails<T> {\n\treturn {\n\t\ttype: input.type ?? \"about:blank\",\n\t\tstatus: input.status,\n\t\ttitle: input.title ?? statusToPhrase(input.status) ?? \"Unknown Error\",\n\t\tdetail: input.detail,\n\t\tinstance: input.instance,\n\t\textensions: input.extensions,\n\t};\n}\n\n/** Build a RFC 9457 Problem Details Response from a ProblemDetails object */\nexport function buildProblemResponse(pd: ProblemDetails): Response {\n\tconst { extensions, ...standard } = pd;\n\tconst body = { ...sanitizeExtensions(extensions), ...standard };\n\tconst { json, fallback } = safeStringify(body);\n\treturn new Response(json, {\n\t\tstatus: fallback ? 500 : clampHttpStatus(pd.status),\n\t\theaders: { \"Content-Type\": PROBLEM_JSON_CONTENT_TYPE },\n\t});\n}\n\n/** JSON.stringify with fallback for non-serializable values (circular refs, BigInt) */\nexport function safeStringify(body: unknown): { json: string; fallback: boolean } {\n\ttry {\n\t\treturn { json: JSON.stringify(body), fallback: false };\n\t} catch {\n\t\treturn { json: FALLBACK_BODY, fallback: true };\n\t}\n}\n","import type { ProblemDetails, ProblemDetailsInput } from \"./types.js\";\nimport { buildProblemResponse, normalizeProblemDetails } from \"./utils.js\";\n\nexport class ProblemDetailsError extends Error {\n\treadonly problemDetails: ProblemDetails;\n\n\tconstructor(input: ProblemDetailsInput) {\n\t\tconst pd = normalizeProblemDetails(input);\n\t\tsuper(pd.detail ?? pd.title);\n\t\tthis.name = \"ProblemDetailsError\";\n\t\tthis.problemDetails = pd;\n\t}\n\n\tgetResponse(): Response {\n\t\treturn buildProblemResponse(this.problemDetails);\n\t}\n}\n","import { ProblemDetailsError } from \"./error.js\";\nimport type { ProblemDetailsInput } from \"./types.js\";\n\nexport function problemDetails<T extends Record<string, unknown>>(\n\tinput: ProblemDetailsInput<T>,\n): ProblemDetailsError {\n\treturn new ProblemDetailsError(input);\n}\n","import type { Context, ErrorHandler } from \"hono\";\nimport { HTTPException } from \"hono/http-exception\";\nimport { ProblemDetailsError } from \"./error.js\";\nimport { statusToPhrase, statusToSlug } from \"./status.js\";\nimport type { ProblemDetailsHandlerOptions, ProblemDetailsInput } from \"./types.js\";\nimport { buildProblemResponse, normalizeProblemDetails } from \"./utils.js\";\n\nfunction buildType(status: number, options: ProblemDetailsHandlerOptions): string {\n\tif (options.typePrefix) {\n\t\tconst slug = statusToSlug(status);\n\t\tif (slug) return `${options.typePrefix}/${slug}`;\n\t}\n\treturn options.defaultType ?? \"about:blank\";\n}\n\nfunction toResponse(\n\tinput: ProblemDetailsInput,\n\tc: Context,\n\toptions: ProblemDetailsHandlerOptions,\n): Response {\n\tlet pd = normalizeProblemDetails(input);\n\n\tif (options.localize) {\n\t\tpd = { ...pd, ...options.localize(pd, c) };\n\t}\n\n\tc.set(\"problemDetails\", pd);\n\n\treturn buildProblemResponse(pd);\n}\n\nexport function problemDetailsHandler(options: ProblemDetailsHandlerOptions = {}): ErrorHandler {\n\treturn (error, c) => {\n\t\tif (error instanceof ProblemDetailsError) {\n\t\t\treturn toResponse(error.problemDetails, c, options);\n\t\t}\n\n\t\tif (options.mapError) {\n\t\t\tconst mapped = options.mapError(error);\n\t\t\tif (mapped) {\n\t\t\t\treturn toResponse(mapped, c, options);\n\t\t\t}\n\t\t}\n\n\t\tif (error instanceof HTTPException) {\n\t\t\treturn toResponse(\n\t\t\t\t{\n\t\t\t\t\tstatus: error.status,\n\t\t\t\t\ttype: buildType(error.status, options),\n\t\t\t\t\ttitle: statusToPhrase(error.status),\n\t\t\t\t\tdetail: error.message,\n\t\t\t\t},\n\t\t\t\tc,\n\t\t\t\toptions,\n\t\t\t);\n\t\t}\n\n\t\treturn toResponse(\n\t\t\t{\n\t\t\t\tstatus: 500,\n\t\t\t\ttype: buildType(500, options),\n\t\t\t\ttitle: \"Internal Server Error\",\n\t\t\t\tdetail: options.includeStack ? error.stack : undefined,\n\t\t\t},\n\t\t\tc,\n\t\t\toptions,\n\t\t);\n\t};\n}\n","import { ProblemDetailsError } from \"./error.js\";\n\ninterface ProblemTypeDefinition {\n\ttype: string;\n\tstatus: number;\n\ttitle: string;\n}\n\ninterface CreateOptions<T extends Record<string, unknown> = Record<string, unknown>> {\n\tdetail?: string;\n\tinstance?: string;\n\textensions?: T;\n}\n\ninterface ProblemTypeRegistry<K extends string> {\n\tcreate: <T extends Record<string, unknown>>(\n\t\tkey: K,\n\t\toptions?: CreateOptions<T>,\n\t) => ProblemDetailsError;\n\tget: (key: K) => ProblemTypeDefinition;\n\ttypes: () => K[];\n}\n\n/**\n * Create a registry of pre-defined problem types.\n * Provides type-safe error creation from registered definitions.\n */\nexport function createProblemTypeRegistry<K extends string>(\n\tdefinitions: Record<K, ProblemTypeDefinition>,\n): ProblemTypeRegistry<K> {\n\treturn {\n\t\tcreate: (key, options) => new ProblemDetailsError({ ...definitions[key], ...options }),\n\t\tget: (key) => definitions[key],\n\t\ttypes: () => Object.keys(definitions) as K[],\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAM,iBAAyC;AAAA,EAC9C,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AACN;AAEA,IAAM,eAAuC,OAAO;AAAA,EACnD,OAAO,QAAQ,cAAc,EAAE,IAAI,CAAC,CAAC,MAAM,MAAM,MAAM;AAAA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AAU;AACrB,YAAM,SAAS,QAAQ,SAAS,KAAK;AACrC,UAAI,QAAQ;AACX,eAAO,WAAW,QAAQ,GAAG,OAAO;AAAA,MACrC;AAAA,IACD;AAEA,QAAI,iBAAiB,qCAAe;AACnC,aAAO;AAAA,QACN;AAAA,UACC,QAAQ,MAAM;AAAA,UACd,MAAM,UAAU,MAAM,QAAQ,OAAO;AAAA,UACrC,OAAO,eAAe,MAAM,MAAM;AAAA,UAClC,QAAQ,MAAM;AAAA,QACf;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAEA,WAAO;AAAA,MACN;AAAA,QACC,QAAQ;AAAA,QACR,MAAM,UAAU,KAAK,OAAO;AAAA,QAC5B,OAAO;AAAA,QACP,QAAQ,QAAQ,eAAe,MAAM,QAAQ;AAAA,MAC9C;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AACD;;;ACzCO,SAAS,0BACf,aACyB;AACzB,SAAO;AAAA,IACN,QAAQ,CAAC,KAAK,YAAY,IAAI,oBAAoB,EAAE,GAAG,YAAY,GAAG,GAAG,GAAG,QAAQ,CAAC;AAAA,IACrF,KAAK,CAAC,QAAQ,YAAY,GAAG;AAAA,IAC7B,OAAO,MAAM,OAAO,KAAK,WAAW;AAAA,EACrC;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/status.ts","../src/utils.ts","../src/error.ts","../src/factory.ts","../src/handler.ts","../src/registry.ts"],"sourcesContent":["export type {\n\tProblemDetails,\n\tProblemDetailsHandlerOptions,\n\tProblemDetailsInput,\n} from \"./types.js\";\nexport { statusToPhrase, statusToSlug } from \"./status.js\";\nexport { ProblemDetailsError } from \"./error.js\";\nexport { problemDetails } from \"./factory.js\";\nexport { PROBLEM_JSON_CONTENT_TYPE } from \"./utils.js\";\nexport { problemDetailsHandler } from \"./handler.js\";\nexport { createProblemTypeRegistry } from \"./registry.js\";\n","const STATUS_PHRASES: Record<number, string> = {\n\t400: \"Bad Request\",\n\t401: \"Unauthorized\",\n\t402: \"Payment Required\",\n\t403: \"Forbidden\",\n\t404: \"Not Found\",\n\t405: \"Method Not Allowed\",\n\t406: \"Not Acceptable\",\n\t407: \"Proxy Authentication Required\",\n\t408: \"Request Timeout\",\n\t409: \"Conflict\",\n\t410: \"Gone\",\n\t411: \"Length Required\",\n\t412: \"Precondition Failed\",\n\t413: \"Content Too Large\",\n\t414: \"URI Too Long\",\n\t415: \"Unsupported Media Type\",\n\t416: \"Range Not Satisfiable\",\n\t417: \"Expectation Failed\",\n\t418: \"I'm a Teapot\",\n\t421: \"Misdirected Request\",\n\t422: \"Unprocessable Content\",\n\t423: \"Locked\",\n\t424: \"Failed Dependency\",\n\t425: \"Too Early\",\n\t426: \"Upgrade Required\",\n\t428: \"Precondition Required\",\n\t429: \"Too Many Requests\",\n\t431: \"Request Header Fields Too Large\",\n\t451: \"Unavailable For Legal Reasons\",\n\t500: \"Internal Server Error\",\n\t501: \"Not Implemented\",\n\t502: \"Bad Gateway\",\n\t503: \"Service Unavailable\",\n\t504: \"Gateway Timeout\",\n\t505: \"HTTP Version Not Supported\",\n\t506: \"Variant Also Negotiates\",\n\t507: \"Insufficient Storage\",\n\t508: \"Loop Detected\",\n\t510: \"Not Extended\",\n\t511: \"Network Authentication Required\",\n};\n\nconst STATUS_SLUGS: Record<number, string> = Object.fromEntries(\n\tObject.entries(STATUS_PHRASES).map(([code, phrase]) => [\n\t\tNumber(code),\n\t\tphrase\n\t\t\t.toLowerCase()\n\t\t\t.replace(/'/g, \"\")\n\t\t\t.replace(/[^a-z0-9]+/g, \"-\")\n\t\t\t.replace(/^-|-$/g, \"\"),\n\t]),\n);\n\nexport function statusToPhrase(status: number): string | undefined {\n\treturn STATUS_PHRASES[status];\n}\n\nexport function statusToSlug(status: number): string | undefined {\n\treturn STATUS_SLUGS[status];\n}\n","import { statusToPhrase } from \"./status.js\";\nimport type { ProblemDetails, ProblemDetailsInput } from \"./types.js\";\n\nexport const PROBLEM_JSON_CONTENT_TYPE = \"application/problem+json; charset=utf-8\";\n\nconst DANGEROUS_KEYS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\n/** Strip keys that could cause prototype pollution in downstream consumers */\nexport function sanitizeExtensions(\n\textensions: Record<string, unknown> | undefined,\n): Record<string, unknown> | undefined {\n\tif (!extensions) return extensions;\n\tlet filtered: Record<string, unknown> | undefined;\n\tfor (const key of Object.keys(extensions)) {\n\t\tif (DANGEROUS_KEYS.has(key)) {\n\t\t\tif (!filtered) filtered = { ...extensions };\n\t\t\tdelete filtered[key];\n\t\t}\n\t}\n\treturn filtered ?? extensions;\n}\n\n/** Clamp HTTP status to 200-599 integer range; returns 500 for out-of-range or non-integer values */\nexport function clampHttpStatus(status: number): number {\n\treturn Number.isInteger(status) && status >= 200 && status <= 599 ? status : 500;\n}\n\nconst FALLBACK_BODY = JSON.stringify({\n\ttype: \"about:blank\",\n\tstatus: 500,\n\ttitle: \"Internal Server Error\",\n});\n\n/** Normalize ProblemDetailsInput to ProblemDetails with defaults for type and title */\nexport function normalizeProblemDetails<T extends Record<string, unknown>>(\n\tinput: ProblemDetailsInput<T>,\n): ProblemDetails<T> {\n\treturn {\n\t\ttype: input.type ?? \"about:blank\",\n\t\tstatus: input.status,\n\t\ttitle: input.title ?? statusToPhrase(input.status) ?? \"Unknown Error\",\n\t\tdetail: input.detail,\n\t\tinstance: input.instance,\n\t\textensions: input.extensions,\n\t};\n}\n\n/** Build a RFC 9457 Problem Details Response from a ProblemDetails object */\nexport function buildProblemResponse(pd: ProblemDetails): Response {\n\tconst { extensions, ...standard } = pd;\n\tconst body = { ...sanitizeExtensions(extensions), ...standard };\n\tconst { json, fallback } = safeStringify(body);\n\treturn new Response(json, {\n\t\tstatus: fallback ? 500 : clampHttpStatus(pd.status),\n\t\theaders: { \"Content-Type\": PROBLEM_JSON_CONTENT_TYPE },\n\t});\n}\n\n/** JSON.stringify with fallback for non-serializable values (circular refs, BigInt) */\nexport function safeStringify(body: unknown): { json: string; fallback: boolean } {\n\ttry {\n\t\treturn { json: JSON.stringify(body), fallback: false };\n\t} catch {\n\t\treturn { json: FALLBACK_BODY, fallback: true };\n\t}\n}\n","import type { ProblemDetails, ProblemDetailsInput } from \"./types.js\";\nimport { buildProblemResponse, normalizeProblemDetails } from \"./utils.js\";\n\nexport class ProblemDetailsError extends Error {\n\treadonly problemDetails: ProblemDetails;\n\n\tconstructor(input: ProblemDetailsInput) {\n\t\tconst pd = normalizeProblemDetails(input);\n\t\tsuper(pd.detail ?? pd.title);\n\t\tthis.name = \"ProblemDetailsError\";\n\t\tthis.problemDetails = pd;\n\t}\n\n\tgetResponse(): Response {\n\t\treturn buildProblemResponse(this.problemDetails);\n\t}\n}\n","import { ProblemDetailsError } from \"./error.js\";\nimport type { ProblemDetailsInput } from \"./types.js\";\n\nexport function problemDetails<T extends Record<string, unknown>>(\n\tinput: ProblemDetailsInput<T>,\n): ProblemDetailsError {\n\treturn new ProblemDetailsError(input);\n}\n","import type { Context, ErrorHandler } from \"hono\";\nimport { HTTPException } from \"hono/http-exception\";\nimport { ProblemDetailsError } from \"./error.js\";\nimport { statusToPhrase, statusToSlug } from \"./status.js\";\nimport type { ProblemDetailsHandlerOptions, ProblemDetailsInput } from \"./types.js\";\nimport { buildProblemResponse, normalizeProblemDetails } from \"./utils.js\";\n\nfunction buildType(status: number, options: ProblemDetailsHandlerOptions): string {\n\tif (options.typePrefix) {\n\t\tconst slug = statusToSlug(status);\n\t\tif (slug) return `${options.typePrefix}/${slug}`;\n\t}\n\treturn options.defaultType ?? \"about:blank\";\n}\n\nfunction toResponse(\n\tinput: ProblemDetailsInput,\n\tc: Context,\n\toptions: ProblemDetailsHandlerOptions,\n): Response {\n\tlet pd = normalizeProblemDetails(input);\n\n\tif (options.localize) {\n\t\ttry {\n\t\t\tpd = { ...pd, ...options.localize(pd, c) };\n\t\t} catch {\n\t\t\t// Fall through with the un-localized pd. A throwing localize must not\n\t\t\t// cause the error handler itself to throw — that would re-enter onError.\n\t\t}\n\t}\n\n\tc.set(\"problemDetails\", pd);\n\n\treturn buildProblemResponse(pd);\n}\n\nexport function problemDetailsHandler(options: ProblemDetailsHandlerOptions = {}): ErrorHandler {\n\treturn (error, c) => {\n\t\tif (error instanceof ProblemDetailsError) {\n\t\t\treturn toResponse(error.problemDetails, c, options);\n\t\t}\n\n\t\tif (options.mapError) {\n\t\t\tconst mapped = options.mapError(error);\n\t\t\tif (mapped) {\n\t\t\t\treturn toResponse(mapped, c, options);\n\t\t\t}\n\t\t}\n\n\t\tif (error instanceof HTTPException) {\n\t\t\treturn toResponse(\n\t\t\t\t{\n\t\t\t\t\tstatus: error.status,\n\t\t\t\t\ttype: buildType(error.status, options),\n\t\t\t\t\ttitle: statusToPhrase(error.status),\n\t\t\t\t\tdetail: error.message,\n\t\t\t\t},\n\t\t\t\tc,\n\t\t\t\toptions,\n\t\t\t);\n\t\t}\n\n\t\treturn toResponse(\n\t\t\t{\n\t\t\t\tstatus: 500,\n\t\t\t\ttype: buildType(500, options),\n\t\t\t\ttitle: \"Internal Server Error\",\n\t\t\t\tdetail: options.includeStack ? error.stack : undefined,\n\t\t\t},\n\t\t\tc,\n\t\t\toptions,\n\t\t);\n\t};\n}\n","import { ProblemDetailsError } from \"./error.js\";\n\ninterface ProblemTypeDefinition {\n\ttype: string;\n\tstatus: number;\n\ttitle: string;\n}\n\ninterface CreateOptions<T extends Record<string, unknown> = Record<string, unknown>> {\n\tdetail?: string;\n\tinstance?: string;\n\textensions?: T;\n}\n\ninterface ProblemTypeRegistry<K extends string> {\n\tcreate: <T extends Record<string, unknown>>(\n\t\tkey: K,\n\t\toptions?: CreateOptions<T>,\n\t) => ProblemDetailsError;\n\tget: (key: K) => ProblemTypeDefinition;\n\ttypes: () => K[];\n}\n\n/**\n * Create a registry of pre-defined problem types.\n * Provides type-safe error creation from registered definitions.\n */\nexport function createProblemTypeRegistry<K extends string>(\n\tdefinitions: Record<K, ProblemTypeDefinition>,\n): ProblemTypeRegistry<K> {\n\treturn {\n\t\tcreate: (key, options) => new ProblemDetailsError({ ...definitions[key], ...options }),\n\t\tget: (key) => definitions[key],\n\t\ttypes: () => Object.keys(definitions) as K[],\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAM,iBAAyC;AAAA,EAC9C,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AACN;AAEA,IAAM,eAAuC,OAAO;AAAA,EACnD,OAAO,QAAQ,cAAc,EAAE,IAAI,CAAC,CAAC,MAAM,MAAM,MAAM;AAAA,IACtD,OAAO,IAAI;AAAA,IACX,OACE,YAAY,EACZ,QAAQ,MAAM,EAAE,EAChB,QAAQ,eAAe,GAAG,EAC1B,QAAQ,UAAU,EAAE;AAAA,EACvB,CAAC;AACF;AAEO,SAAS,eAAe,QAAoC;AAClE,SAAO,eAAe,MAAM;AAC7B;AAEO,SAAS,aAAa,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ACnC,aAAO;AAAA,QACN;AAAA,UACC,QAAQ,MAAM;AAAA,UACd,MAAM,UAAU,MAAM,QAAQ,OAAO;AAAA,UACrC,OAAO,eAAe,MAAM,MAAM;AAAA,UAClC,QAAQ,MAAM;AAAA,QACf;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAEA,WAAO;AAAA,MACN;AAAA,QACC,QAAQ;AAAA,QACR,MAAM,UAAU,KAAK,OAAO;AAAA,QAC5B,OAAO;AAAA,QACP,QAAQ,QAAQ,eAAe,MAAM,QAAQ;AAAA,MAC9C;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AACD;;;AC9CO,SAAS,0BACf,aACyB;AACzB,SAAO;AAAA,IACN,QAAQ,CAAC,KAAK,YAAY,IAAI,oBAAoB,EAAE,GAAG,YAAY,GAAG,GAAG,GAAG,QAAQ,CAAC;AAAA,IACrF,KAAK,CAAC,QAAQ,YAAY,GAAG;AAAA,IAC7B,OAAO,MAAM,OAAO,KAAK,WAAW;AAAA,EACrC;AACD;","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
PROBLEM_JSON_CONTENT_TYPE,
|
|
3
3
|
buildProblemResponse,
|
|
4
4
|
normalizeProblemDetails
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-XPBA7IIJ.js";
|
|
6
6
|
import {
|
|
7
7
|
statusToPhrase,
|
|
8
8
|
statusToSlug
|
|
@@ -39,7 +39,10 @@ function buildType(status, options) {
|
|
|
39
39
|
function toResponse(input, c, options) {
|
|
40
40
|
let pd = normalizeProblemDetails(input);
|
|
41
41
|
if (options.localize) {
|
|
42
|
-
|
|
42
|
+
try {
|
|
43
|
+
pd = { ...pd, ...options.localize(pd, c) };
|
|
44
|
+
} catch {
|
|
45
|
+
}
|
|
43
46
|
}
|
|
44
47
|
c.set("problemDetails", pd);
|
|
45
48
|
return buildProblemResponse(pd);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/error.ts","../src/factory.ts","../src/handler.ts","../src/registry.ts"],"sourcesContent":["import type { ProblemDetails, ProblemDetailsInput } from \"./types.js\";\nimport { buildProblemResponse, normalizeProblemDetails } from \"./utils.js\";\n\nexport class ProblemDetailsError extends Error {\n\treadonly problemDetails: ProblemDetails;\n\n\tconstructor(input: ProblemDetailsInput) {\n\t\tconst pd = normalizeProblemDetails(input);\n\t\tsuper(pd.detail ?? pd.title);\n\t\tthis.name = \"ProblemDetailsError\";\n\t\tthis.problemDetails = pd;\n\t}\n\n\tgetResponse(): Response {\n\t\treturn buildProblemResponse(this.problemDetails);\n\t}\n}\n","import { ProblemDetailsError } from \"./error.js\";\nimport type { ProblemDetailsInput } from \"./types.js\";\n\nexport function problemDetails<T extends Record<string, unknown>>(\n\tinput: ProblemDetailsInput<T>,\n): ProblemDetailsError {\n\treturn new ProblemDetailsError(input);\n}\n","import type { Context, ErrorHandler } from \"hono\";\nimport { HTTPException } from \"hono/http-exception\";\nimport { ProblemDetailsError } from \"./error.js\";\nimport { statusToPhrase, statusToSlug } from \"./status.js\";\nimport type { ProblemDetailsHandlerOptions, ProblemDetailsInput } from \"./types.js\";\nimport { buildProblemResponse, normalizeProblemDetails } from \"./utils.js\";\n\nfunction buildType(status: number, options: ProblemDetailsHandlerOptions): string {\n\tif (options.typePrefix) {\n\t\tconst slug = statusToSlug(status);\n\t\tif (slug) return `${options.typePrefix}/${slug}`;\n\t}\n\treturn options.defaultType ?? \"about:blank\";\n}\n\nfunction toResponse(\n\tinput: ProblemDetailsInput,\n\tc: Context,\n\toptions: ProblemDetailsHandlerOptions,\n): Response {\n\tlet pd = normalizeProblemDetails(input);\n\n\tif (options.localize) {\n\t\tpd = { ...pd, ...options.localize(pd, c) };\n\t}\n\n\tc.set(\"problemDetails\", pd);\n\n\treturn buildProblemResponse(pd);\n}\n\nexport function problemDetailsHandler(options: ProblemDetailsHandlerOptions = {}): ErrorHandler {\n\treturn (error, c) => {\n\t\tif (error instanceof ProblemDetailsError) {\n\t\t\treturn toResponse(error.problemDetails, c, options);\n\t\t}\n\n\t\tif (options.mapError) {\n\t\t\tconst mapped = options.mapError(error);\n\t\t\tif (mapped) {\n\t\t\t\treturn toResponse(mapped, c, options);\n\t\t\t}\n\t\t}\n\n\t\tif (error instanceof HTTPException) {\n\t\t\treturn toResponse(\n\t\t\t\t{\n\t\t\t\t\tstatus: error.status,\n\t\t\t\t\ttype: buildType(error.status, options),\n\t\t\t\t\ttitle: statusToPhrase(error.status),\n\t\t\t\t\tdetail: error.message,\n\t\t\t\t},\n\t\t\t\tc,\n\t\t\t\toptions,\n\t\t\t);\n\t\t}\n\n\t\treturn toResponse(\n\t\t\t{\n\t\t\t\tstatus: 500,\n\t\t\t\ttype: buildType(500, options),\n\t\t\t\ttitle: \"Internal Server Error\",\n\t\t\t\tdetail: options.includeStack ? error.stack : undefined,\n\t\t\t},\n\t\t\tc,\n\t\t\toptions,\n\t\t);\n\t};\n}\n","import { ProblemDetailsError } from \"./error.js\";\n\ninterface ProblemTypeDefinition {\n\ttype: string;\n\tstatus: number;\n\ttitle: string;\n}\n\ninterface CreateOptions<T extends Record<string, unknown> = Record<string, unknown>> {\n\tdetail?: string;\n\tinstance?: string;\n\textensions?: T;\n}\n\ninterface ProblemTypeRegistry<K extends string> {\n\tcreate: <T extends Record<string, unknown>>(\n\t\tkey: K,\n\t\toptions?: CreateOptions<T>,\n\t) => ProblemDetailsError;\n\tget: (key: K) => ProblemTypeDefinition;\n\ttypes: () => K[];\n}\n\n/**\n * Create a registry of pre-defined problem types.\n * Provides type-safe error creation from registered definitions.\n */\nexport function createProblemTypeRegistry<K extends string>(\n\tdefinitions: Record<K, ProblemTypeDefinition>,\n): ProblemTypeRegistry<K> {\n\treturn {\n\t\tcreate: (key, options) => new ProblemDetailsError({ ...definitions[key], ...options }),\n\t\tget: (key) => definitions[key],\n\t\ttypes: () => Object.keys(definitions) as K[],\n\t};\n}\n"],"mappings":";;;;;;;;;;;AAGO,IAAM,sBAAN,cAAkC,MAAM;AAAA,EACrC;AAAA,EAET,YAAY,OAA4B;AACvC,UAAM,KAAK,wBAAwB,KAAK;AACxC,UAAM,GAAG,UAAU,GAAG,KAAK;AAC3B,SAAK,OAAO;AACZ,SAAK,iBAAiB;AAAA,EACvB;AAAA,EAEA,cAAwB;AACvB,WAAO,qBAAqB,KAAK,cAAc;AAAA,EAChD;AACD;;;ACbO,SAAS,eACf,OACsB;AACtB,SAAO,IAAI,oBAAoB,KAAK;AACrC;;;ACNA,SAAS,qBAAqB;AAM9B,SAAS,UAAU,QAAgB,SAA+C;AACjF,MAAI,QAAQ,YAAY;AACvB,UAAM,OAAO,aAAa,MAAM;AAChC,QAAI,KAAM,QAAO,GAAG,QAAQ,UAAU,IAAI,IAAI;AAAA,EAC/C;AACA,SAAO,QAAQ,eAAe;AAC/B;AAEA,SAAS,WACR,OACA,GACA,SACW;AACX,MAAI,KAAK,wBAAwB,KAAK;AAEtC,MAAI,QAAQ,UAAU;AACrB,
|
|
1
|
+
{"version":3,"sources":["../src/error.ts","../src/factory.ts","../src/handler.ts","../src/registry.ts"],"sourcesContent":["import type { ProblemDetails, ProblemDetailsInput } from \"./types.js\";\nimport { buildProblemResponse, normalizeProblemDetails } from \"./utils.js\";\n\nexport class ProblemDetailsError extends Error {\n\treadonly problemDetails: ProblemDetails;\n\n\tconstructor(input: ProblemDetailsInput) {\n\t\tconst pd = normalizeProblemDetails(input);\n\t\tsuper(pd.detail ?? pd.title);\n\t\tthis.name = \"ProblemDetailsError\";\n\t\tthis.problemDetails = pd;\n\t}\n\n\tgetResponse(): Response {\n\t\treturn buildProblemResponse(this.problemDetails);\n\t}\n}\n","import { ProblemDetailsError } from \"./error.js\";\nimport type { ProblemDetailsInput } from \"./types.js\";\n\nexport function problemDetails<T extends Record<string, unknown>>(\n\tinput: ProblemDetailsInput<T>,\n): ProblemDetailsError {\n\treturn new ProblemDetailsError(input);\n}\n","import type { Context, ErrorHandler } from \"hono\";\nimport { HTTPException } from \"hono/http-exception\";\nimport { ProblemDetailsError } from \"./error.js\";\nimport { statusToPhrase, statusToSlug } from \"./status.js\";\nimport type { ProblemDetailsHandlerOptions, ProblemDetailsInput } from \"./types.js\";\nimport { buildProblemResponse, normalizeProblemDetails } from \"./utils.js\";\n\nfunction buildType(status: number, options: ProblemDetailsHandlerOptions): string {\n\tif (options.typePrefix) {\n\t\tconst slug = statusToSlug(status);\n\t\tif (slug) return `${options.typePrefix}/${slug}`;\n\t}\n\treturn options.defaultType ?? \"about:blank\";\n}\n\nfunction toResponse(\n\tinput: ProblemDetailsInput,\n\tc: Context,\n\toptions: ProblemDetailsHandlerOptions,\n): Response {\n\tlet pd = normalizeProblemDetails(input);\n\n\tif (options.localize) {\n\t\ttry {\n\t\t\tpd = { ...pd, ...options.localize(pd, c) };\n\t\t} catch {\n\t\t\t// Fall through with the un-localized pd. A throwing localize must not\n\t\t\t// cause the error handler itself to throw — that would re-enter onError.\n\t\t}\n\t}\n\n\tc.set(\"problemDetails\", pd);\n\n\treturn buildProblemResponse(pd);\n}\n\nexport function problemDetailsHandler(options: ProblemDetailsHandlerOptions = {}): ErrorHandler {\n\treturn (error, c) => {\n\t\tif (error instanceof ProblemDetailsError) {\n\t\t\treturn toResponse(error.problemDetails, c, options);\n\t\t}\n\n\t\tif (options.mapError) {\n\t\t\tconst mapped = options.mapError(error);\n\t\t\tif (mapped) {\n\t\t\t\treturn toResponse(mapped, c, options);\n\t\t\t}\n\t\t}\n\n\t\tif (error instanceof HTTPException) {\n\t\t\treturn toResponse(\n\t\t\t\t{\n\t\t\t\t\tstatus: error.status,\n\t\t\t\t\ttype: buildType(error.status, options),\n\t\t\t\t\ttitle: statusToPhrase(error.status),\n\t\t\t\t\tdetail: error.message,\n\t\t\t\t},\n\t\t\t\tc,\n\t\t\t\toptions,\n\t\t\t);\n\t\t}\n\n\t\treturn toResponse(\n\t\t\t{\n\t\t\t\tstatus: 500,\n\t\t\t\ttype: buildType(500, options),\n\t\t\t\ttitle: \"Internal Server Error\",\n\t\t\t\tdetail: options.includeStack ? error.stack : undefined,\n\t\t\t},\n\t\t\tc,\n\t\t\toptions,\n\t\t);\n\t};\n}\n","import { ProblemDetailsError } from \"./error.js\";\n\ninterface ProblemTypeDefinition {\n\ttype: string;\n\tstatus: number;\n\ttitle: string;\n}\n\ninterface CreateOptions<T extends Record<string, unknown> = Record<string, unknown>> {\n\tdetail?: string;\n\tinstance?: string;\n\textensions?: T;\n}\n\ninterface ProblemTypeRegistry<K extends string> {\n\tcreate: <T extends Record<string, unknown>>(\n\t\tkey: K,\n\t\toptions?: CreateOptions<T>,\n\t) => ProblemDetailsError;\n\tget: (key: K) => ProblemTypeDefinition;\n\ttypes: () => K[];\n}\n\n/**\n * Create a registry of pre-defined problem types.\n * Provides type-safe error creation from registered definitions.\n */\nexport function createProblemTypeRegistry<K extends string>(\n\tdefinitions: Record<K, ProblemTypeDefinition>,\n): ProblemTypeRegistry<K> {\n\treturn {\n\t\tcreate: (key, options) => new ProblemDetailsError({ ...definitions[key], ...options }),\n\t\tget: (key) => definitions[key],\n\t\ttypes: () => Object.keys(definitions) as K[],\n\t};\n}\n"],"mappings":";;;;;;;;;;;AAGO,IAAM,sBAAN,cAAkC,MAAM;AAAA,EACrC;AAAA,EAET,YAAY,OAA4B;AACvC,UAAM,KAAK,wBAAwB,KAAK;AACxC,UAAM,GAAG,UAAU,GAAG,KAAK;AAC3B,SAAK,OAAO;AACZ,SAAK,iBAAiB;AAAA,EACvB;AAAA,EAEA,cAAwB;AACvB,WAAO,qBAAqB,KAAK,cAAc;AAAA,EAChD;AACD;;;ACbO,SAAS,eACf,OACsB;AACtB,SAAO,IAAI,oBAAoB,KAAK;AACrC;;;ACNA,SAAS,qBAAqB;AAM9B,SAAS,UAAU,QAAgB,SAA+C;AACjF,MAAI,QAAQ,YAAY;AACvB,UAAM,OAAO,aAAa,MAAM;AAChC,QAAI,KAAM,QAAO,GAAG,QAAQ,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C,QAAQ,YAAY,GAAG;AAAA,IAC7B,OAAO,MAAM,OAAO,KAAK,WAAW;AAAA,EACrC;AACD;","names":[]}
|
|
@@ -33,13 +33,24 @@ var FALLBACK_BODY = JSON.stringify({
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
// src/integrations/validation.ts
|
|
36
|
+
var CONTROL_CHAR_RE = /[\x00-\x1f\x7f]/g;
|
|
37
|
+
function stripControlChars(input) {
|
|
38
|
+
return input.replace(CONTROL_CHAR_RE, "");
|
|
39
|
+
}
|
|
40
|
+
function sanitizeError(error) {
|
|
41
|
+
return {
|
|
42
|
+
field: stripControlChars(error.field),
|
|
43
|
+
message: stripControlChars(error.message),
|
|
44
|
+
...error.code !== void 0 ? { code: stripControlChars(error.code) } : {}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
36
47
|
function buildValidationResponse(errors, options) {
|
|
37
48
|
const body = {
|
|
38
49
|
type: "about:blank",
|
|
39
50
|
status: 422,
|
|
40
51
|
title: options?.title ?? "Validation Error",
|
|
41
52
|
detail: options?.detail ?? "Request validation failed",
|
|
42
|
-
errors
|
|
53
|
+
errors: errors.map(sanitizeError)
|
|
43
54
|
};
|
|
44
55
|
return new Response(JSON.stringify(body), {
|
|
45
56
|
status: 422,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/integrations/standard-schema.ts","../../src/utils.ts","../../src/integrations/validation.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { Context } from \"hono\";\nimport {\n\ttype ValidationError,\n\ttype ValidationHookOptions,\n\tbuildValidationResponse,\n} from \"./validation.js\";\n\nexport type { ValidationHookOptions as StandardSchemaProblemHookOptions };\n\nfunction formatPath(path: ReadonlyArray<PropertyKey | StandardSchemaV1.PathSegment>): string {\n\treturn path\n\t\t.map((segment) => (typeof segment === \"object\" ? String(segment.key) : String(segment)))\n\t\t.join(\".\");\n}\n\nfunction formatIssues(issues: readonly StandardSchemaV1.Issue[]): ValidationError[] {\n\treturn issues.map((issue) => ({\n\t\tfield: issue.path ? formatPath(issue.path) : \"\",\n\t\tmessage: issue.message,\n\t}));\n}\n\nexport function standardSchemaProblemHook(\n\toptions?: ValidationHookOptions,\n): (\n\tresult:\n\t\t| { success: true; data: unknown }\n\t\t| { success: false; error: readonly StandardSchemaV1.Issue[] },\n\tc: Context,\n) => Response | undefined {\n\treturn (result, _c) => {\n\t\tif (result.success) return;\n\t\treturn buildValidationResponse(formatIssues(result.error), options);\n\t};\n}\n","import { statusToPhrase } from \"./status.js\";\nimport type { ProblemDetails, ProblemDetailsInput } from \"./types.js\";\n\nexport const PROBLEM_JSON_CONTENT_TYPE = \"application/problem+json; charset=utf-8\";\n\nconst DANGEROUS_KEYS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\n/** Strip keys that could cause prototype pollution in downstream consumers */\nexport function sanitizeExtensions(\n\textensions: Record<string, unknown> | undefined,\n): Record<string, unknown> | undefined {\n\tif (!extensions) return extensions;\n\tlet filtered: Record<string, unknown> | undefined;\n\tfor (const key of Object.keys(extensions)) {\n\t\tif (DANGEROUS_KEYS.has(key)) {\n\t\t\tif (!filtered) filtered = { ...extensions };\n\t\t\tdelete filtered[key];\n\t\t}\n\t}\n\treturn filtered ?? extensions;\n}\n\n/** Clamp HTTP status to 200-599 range; returns 500 for out-of-range values */\nexport function clampHttpStatus(status: number): number {\n\treturn status >= 200 && status <= 599 ? status : 500;\n}\n\nconst FALLBACK_BODY = JSON.stringify({\n\ttype: \"about:blank\",\n\tstatus: 500,\n\ttitle: \"Internal Server Error\",\n});\n\n/** Normalize ProblemDetailsInput to ProblemDetails with defaults for type and title */\nexport function normalizeProblemDetails<T extends Record<string, unknown>>(\n\tinput: ProblemDetailsInput<T>,\n): ProblemDetails<T> {\n\treturn {\n\t\ttype: input.type ?? \"about:blank\",\n\t\tstatus: input.status,\n\t\ttitle: input.title ?? statusToPhrase(input.status) ?? \"Unknown Error\",\n\t\tdetail: input.detail,\n\t\tinstance: input.instance,\n\t\textensions: input.extensions,\n\t};\n}\n\n/** Build a RFC 9457 Problem Details Response from a ProblemDetails object */\nexport function buildProblemResponse(pd: ProblemDetails): Response {\n\tconst { extensions, ...standard } = pd;\n\tconst body = { ...sanitizeExtensions(extensions), ...standard };\n\tconst { json, fallback } = safeStringify(body);\n\treturn new Response(json, {\n\t\tstatus: fallback ? 500 : clampHttpStatus(pd.status),\n\t\theaders: { \"Content-Type\": PROBLEM_JSON_CONTENT_TYPE },\n\t});\n}\n\n/** JSON.stringify with fallback for non-serializable values (circular refs, BigInt) */\nexport function safeStringify(body: unknown): { json: string; fallback: boolean } {\n\ttry {\n\t\treturn { json: JSON.stringify(body), fallback: false };\n\t} catch {\n\t\treturn { json: FALLBACK_BODY, fallback: true };\n\t}\n}\n","import { PROBLEM_JSON_CONTENT_TYPE } from \"../utils.js\";\n\nexport interface ValidationError {\n\tfield: string;\n\tmessage: string;\n\tcode?: string;\n}\n\nexport interface ValidationHookOptions {\n\ttitle?: string;\n\tdetail?: string;\n}\n\n/** Build a RFC 9457 validation error response from formatted errors */\nexport function buildValidationResponse(\n\terrors: ValidationError[],\n\toptions?: ValidationHookOptions,\n): Response {\n\tconst body = {\n\t\ttype: \"about:blank\",\n\t\tstatus: 422,\n\t\ttitle: options?.title ?? \"Validation Error\",\n\t\tdetail: options?.detail ?? \"Request validation failed\",\n\t\terrors,\n\t};\n\n\treturn new Response(JSON.stringify(body), {\n\t\tstatus: 422,\n\t\theaders: { \"Content-Type\": PROBLEM_JSON_CONTENT_TYPE },\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,4BAA4B;AAwBzC,IAAM,gBAAgB,KAAK,UAAU;AAAA,EACpC,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AACR,CAAC;;;
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/standard-schema.ts","../../src/utils.ts","../../src/integrations/validation.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { Context } from \"hono\";\nimport {\n\ttype ValidationError,\n\ttype ValidationHookOptions,\n\tbuildValidationResponse,\n} from \"./validation.js\";\n\nexport type { ValidationHookOptions as StandardSchemaProblemHookOptions };\n\nfunction formatPath(path: ReadonlyArray<PropertyKey | StandardSchemaV1.PathSegment>): string {\n\treturn path\n\t\t.map((segment) => (typeof segment === \"object\" ? String(segment.key) : String(segment)))\n\t\t.join(\".\");\n}\n\nfunction formatIssues(issues: readonly StandardSchemaV1.Issue[]): ValidationError[] {\n\treturn issues.map((issue) => ({\n\t\tfield: issue.path ? formatPath(issue.path) : \"\",\n\t\tmessage: issue.message,\n\t}));\n}\n\nexport function standardSchemaProblemHook(\n\toptions?: ValidationHookOptions,\n): (\n\tresult:\n\t\t| { success: true; data: unknown }\n\t\t| { success: false; error: readonly StandardSchemaV1.Issue[] },\n\tc: Context,\n) => Response | undefined {\n\treturn (result, _c) => {\n\t\tif (result.success) return;\n\t\treturn buildValidationResponse(formatIssues(result.error), options);\n\t};\n}\n","import { statusToPhrase } from \"./status.js\";\nimport type { ProblemDetails, ProblemDetailsInput } from \"./types.js\";\n\nexport const PROBLEM_JSON_CONTENT_TYPE = \"application/problem+json; charset=utf-8\";\n\nconst DANGEROUS_KEYS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\n/** Strip keys that could cause prototype pollution in downstream consumers */\nexport function sanitizeExtensions(\n\textensions: Record<string, unknown> | undefined,\n): Record<string, unknown> | undefined {\n\tif (!extensions) return extensions;\n\tlet filtered: Record<string, unknown> | undefined;\n\tfor (const key of Object.keys(extensions)) {\n\t\tif (DANGEROUS_KEYS.has(key)) {\n\t\t\tif (!filtered) filtered = { ...extensions };\n\t\t\tdelete filtered[key];\n\t\t}\n\t}\n\treturn filtered ?? extensions;\n}\n\n/** Clamp HTTP status to 200-599 integer range; returns 500 for out-of-range or non-integer values */\nexport function clampHttpStatus(status: number): number {\n\treturn Number.isInteger(status) && status >= 200 && status <= 599 ? status : 500;\n}\n\nconst FALLBACK_BODY = JSON.stringify({\n\ttype: \"about:blank\",\n\tstatus: 500,\n\ttitle: \"Internal Server Error\",\n});\n\n/** Normalize ProblemDetailsInput to ProblemDetails with defaults for type and title */\nexport function normalizeProblemDetails<T extends Record<string, unknown>>(\n\tinput: ProblemDetailsInput<T>,\n): ProblemDetails<T> {\n\treturn {\n\t\ttype: input.type ?? \"about:blank\",\n\t\tstatus: input.status,\n\t\ttitle: input.title ?? statusToPhrase(input.status) ?? \"Unknown Error\",\n\t\tdetail: input.detail,\n\t\tinstance: input.instance,\n\t\textensions: input.extensions,\n\t};\n}\n\n/** Build a RFC 9457 Problem Details Response from a ProblemDetails object */\nexport function buildProblemResponse(pd: ProblemDetails): Response {\n\tconst { extensions, ...standard } = pd;\n\tconst body = { ...sanitizeExtensions(extensions), ...standard };\n\tconst { json, fallback } = safeStringify(body);\n\treturn new Response(json, {\n\t\tstatus: fallback ? 500 : clampHttpStatus(pd.status),\n\t\theaders: { \"Content-Type\": PROBLEM_JSON_CONTENT_TYPE },\n\t});\n}\n\n/** JSON.stringify with fallback for non-serializable values (circular refs, BigInt) */\nexport function safeStringify(body: unknown): { json: string; fallback: boolean } {\n\ttry {\n\t\treturn { json: JSON.stringify(body), fallback: false };\n\t} catch {\n\t\treturn { json: FALLBACK_BODY, fallback: true };\n\t}\n}\n","import { PROBLEM_JSON_CONTENT_TYPE } from \"../utils.js\";\n\nexport interface ValidationError {\n\tfield: string;\n\tmessage: string;\n\tcode?: string;\n}\n\nexport interface ValidationHookOptions {\n\ttitle?: string;\n\tdetail?: string;\n}\n\n/**\n * Strip C0 control characters (\\x00-\\x1f) and DEL (\\x7f) from untrusted text.\n * Bidi/format control chars (U+2028, U+202E, etc.) are intentionally left intact\n * to avoid breaking legitimate i18n content; log consumers should apply their\n * own bidi-safe rendering.\n */\n// biome-ignore lint/suspicious/noControlCharactersInRegex: intentional stripping of C0 controls\nconst CONTROL_CHAR_RE = /[\\x00-\\x1f\\x7f]/g;\n\nfunction stripControlChars(input: string): string {\n\treturn input.replace(CONTROL_CHAR_RE, \"\");\n}\n\nfunction sanitizeError(error: ValidationError): ValidationError {\n\treturn {\n\t\tfield: stripControlChars(error.field),\n\t\tmessage: stripControlChars(error.message),\n\t\t...(error.code !== undefined ? { code: stripControlChars(error.code) } : {}),\n\t};\n}\n\n/** Build a RFC 9457 validation error response from formatted errors */\nexport function buildValidationResponse(\n\terrors: ValidationError[],\n\toptions?: ValidationHookOptions,\n): Response {\n\tconst body = {\n\t\ttype: \"about:blank\",\n\t\tstatus: 422,\n\t\ttitle: options?.title ?? \"Validation Error\",\n\t\tdetail: options?.detail ?? \"Request validation failed\",\n\t\terrors: errors.map(sanitizeError),\n\t};\n\n\treturn new Response(JSON.stringify(body), {\n\t\tstatus: 422,\n\t\theaders: { \"Content-Type\": PROBLEM_JSON_CONTENT_TYPE },\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,4BAA4B;AAwBzC,IAAM,gBAAgB,KAAK,UAAU;AAAA,EACpC,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AACR,CAAC;;;ACXD,IAAM,kBAAkB;AAExB,SAAS,kBAAkB,OAAuB;AACjD,SAAO,MAAM,QAAQ,iBAAiB,EAAE;AACzC;AAEA,SAAS,cAAc,OAAyC;AAC/D,SAAO;AAAA,IACN,OAAO,kBAAkB,MAAM,KAAK;AAAA,IACpC,SAAS,kBAAkB,MAAM,OAAO;AAAA,IACxC,GAAI,MAAM,SAAS,SAAY,EAAE,MAAM,kBAAkB,MAAM,IAAI,EAAE,IAAI,CAAC;AAAA,EAC3E;AACD;AAGO,SAAS,wBACf,QACA,SACW;AACX,QAAM,OAAO;AAAA,IACZ,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,OAAO,SAAS,SAAS;AAAA,IACzB,QAAQ,SAAS,UAAU;AAAA,IAC3B,QAAQ,OAAO,IAAI,aAAa;AAAA,EACjC;AAEA,SAAO,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG;AAAA,IACzC,QAAQ;AAAA,IACR,SAAS,EAAE,gBAAgB,0BAA0B;AAAA,EACtD,CAAC;AACF;;;AFzCA,SAAS,WAAW,MAAyE;AAC5F,SAAO,KACL,IAAI,CAAC,YAAa,OAAO,YAAY,WAAW,OAAO,QAAQ,GAAG,IAAI,OAAO,OAAO,CAAE,EACtF,KAAK,GAAG;AACX;AAEA,SAAS,aAAa,QAA8D;AACnF,SAAO,OAAO,IAAI,CAAC,WAAW;AAAA,IAC7B,OAAO,MAAM,OAAO,WAAW,MAAM,IAAI,IAAI;AAAA,IAC7C,SAAS,MAAM;AAAA,EAChB,EAAE;AACH;AAEO,SAAS,0BACf,SAMyB;AACzB,SAAO,CAAC,QAAQ,OAAO;AACtB,QAAI,OAAO,QAAS;AACpB,WAAO,wBAAwB,aAAa,OAAO,KAAK,GAAG,OAAO;AAAA,EACnE;AACD;","names":[]}
|
|
@@ -33,13 +33,24 @@ var FALLBACK_BODY = JSON.stringify({
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
// src/integrations/validation.ts
|
|
36
|
+
var CONTROL_CHAR_RE = /[\x00-\x1f\x7f]/g;
|
|
37
|
+
function stripControlChars(input) {
|
|
38
|
+
return input.replace(CONTROL_CHAR_RE, "");
|
|
39
|
+
}
|
|
40
|
+
function sanitizeError(error) {
|
|
41
|
+
return {
|
|
42
|
+
field: stripControlChars(error.field),
|
|
43
|
+
message: stripControlChars(error.message),
|
|
44
|
+
...error.code !== void 0 ? { code: stripControlChars(error.code) } : {}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
36
47
|
function buildValidationResponse(errors, options) {
|
|
37
48
|
const body = {
|
|
38
49
|
type: "about:blank",
|
|
39
50
|
status: 422,
|
|
40
51
|
title: options?.title ?? "Validation Error",
|
|
41
52
|
detail: options?.detail ?? "Request validation failed",
|
|
42
|
-
errors
|
|
53
|
+
errors: errors.map(sanitizeError)
|
|
43
54
|
};
|
|
44
55
|
return new Response(JSON.stringify(body), {
|
|
45
56
|
status: 422,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/integrations/valibot.ts","../../src/utils.ts","../../src/integrations/validation.ts"],"sourcesContent":["import type { Context } from \"hono\";\nimport type { BaseIssue, SafeParseResult } from \"valibot\";\nimport {\n\ttype ValidationError,\n\ttype ValidationHookOptions,\n\tbuildValidationResponse,\n} from \"./validation.js\";\n\nexport type { ValidationHookOptions as ValibotProblemHookOptions };\n\nfunction formatIssues(issues: BaseIssue<unknown>[]): ValidationError[] {\n\treturn issues.map((issue) => ({\n\t\tfield: issue.path?.map((p) => p.key).join(\".\") ?? \"\",\n\t\tmessage: issue.message,\n\t\tcode: issue.type,\n\t}));\n}\n\nexport function valibotProblemHook(\n\toptions?: ValidationHookOptions,\n): (result: SafeParseResult<
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/valibot.ts","../../src/utils.ts","../../src/integrations/validation.ts"],"sourcesContent":["import type { Context } from \"hono\";\nimport type { BaseIssue, GenericSchema, GenericSchemaAsync, SafeParseResult } from \"valibot\";\nimport {\n\ttype ValidationError,\n\ttype ValidationHookOptions,\n\tbuildValidationResponse,\n} from \"./validation.js\";\n\nexport type { ValidationHookOptions as ValibotProblemHookOptions };\n\nfunction formatIssues(issues: BaseIssue<unknown>[]): ValidationError[] {\n\treturn issues.map((issue) => ({\n\t\tfield: issue.path?.map((p) => p.key).join(\".\") ?? \"\",\n\t\tmessage: issue.message,\n\t\tcode: issue.type,\n\t}));\n}\n\nexport function valibotProblemHook<T extends GenericSchema | GenericSchemaAsync = GenericSchema>(\n\toptions?: ValidationHookOptions,\n): (result: SafeParseResult<T> & { target: string }, c: Context) => Response | undefined {\n\treturn (result, _c) => {\n\t\tif (result.success) return;\n\t\treturn buildValidationResponse(formatIssues(result.issues), options);\n\t};\n}\n","import { statusToPhrase } from \"./status.js\";\nimport type { ProblemDetails, ProblemDetailsInput } from \"./types.js\";\n\nexport const PROBLEM_JSON_CONTENT_TYPE = \"application/problem+json; charset=utf-8\";\n\nconst DANGEROUS_KEYS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\n/** Strip keys that could cause prototype pollution in downstream consumers */\nexport function sanitizeExtensions(\n\textensions: Record<string, unknown> | undefined,\n): Record<string, unknown> | undefined {\n\tif (!extensions) return extensions;\n\tlet filtered: Record<string, unknown> | undefined;\n\tfor (const key of Object.keys(extensions)) {\n\t\tif (DANGEROUS_KEYS.has(key)) {\n\t\t\tif (!filtered) filtered = { ...extensions };\n\t\t\tdelete filtered[key];\n\t\t}\n\t}\n\treturn filtered ?? extensions;\n}\n\n/** Clamp HTTP status to 200-599 integer range; returns 500 for out-of-range or non-integer values */\nexport function clampHttpStatus(status: number): number {\n\treturn Number.isInteger(status) && status >= 200 && status <= 599 ? status : 500;\n}\n\nconst FALLBACK_BODY = JSON.stringify({\n\ttype: \"about:blank\",\n\tstatus: 500,\n\ttitle: \"Internal Server Error\",\n});\n\n/** Normalize ProblemDetailsInput to ProblemDetails with defaults for type and title */\nexport function normalizeProblemDetails<T extends Record<string, unknown>>(\n\tinput: ProblemDetailsInput<T>,\n): ProblemDetails<T> {\n\treturn {\n\t\ttype: input.type ?? \"about:blank\",\n\t\tstatus: input.status,\n\t\ttitle: input.title ?? statusToPhrase(input.status) ?? \"Unknown Error\",\n\t\tdetail: input.detail,\n\t\tinstance: input.instance,\n\t\textensions: input.extensions,\n\t};\n}\n\n/** Build a RFC 9457 Problem Details Response from a ProblemDetails object */\nexport function buildProblemResponse(pd: ProblemDetails): Response {\n\tconst { extensions, ...standard } = pd;\n\tconst body = { ...sanitizeExtensions(extensions), ...standard };\n\tconst { json, fallback } = safeStringify(body);\n\treturn new Response(json, {\n\t\tstatus: fallback ? 500 : clampHttpStatus(pd.status),\n\t\theaders: { \"Content-Type\": PROBLEM_JSON_CONTENT_TYPE },\n\t});\n}\n\n/** JSON.stringify with fallback for non-serializable values (circular refs, BigInt) */\nexport function safeStringify(body: unknown): { json: string; fallback: boolean } {\n\ttry {\n\t\treturn { json: JSON.stringify(body), fallback: false };\n\t} catch {\n\t\treturn { json: FALLBACK_BODY, fallback: true };\n\t}\n}\n","import { PROBLEM_JSON_CONTENT_TYPE } from \"../utils.js\";\n\nexport interface ValidationError {\n\tfield: string;\n\tmessage: string;\n\tcode?: string;\n}\n\nexport interface ValidationHookOptions {\n\ttitle?: string;\n\tdetail?: string;\n}\n\n/**\n * Strip C0 control characters (\\x00-\\x1f) and DEL (\\x7f) from untrusted text.\n * Bidi/format control chars (U+2028, U+202E, etc.) are intentionally left intact\n * to avoid breaking legitimate i18n content; log consumers should apply their\n * own bidi-safe rendering.\n */\n// biome-ignore lint/suspicious/noControlCharactersInRegex: intentional stripping of C0 controls\nconst CONTROL_CHAR_RE = /[\\x00-\\x1f\\x7f]/g;\n\nfunction stripControlChars(input: string): string {\n\treturn input.replace(CONTROL_CHAR_RE, \"\");\n}\n\nfunction sanitizeError(error: ValidationError): ValidationError {\n\treturn {\n\t\tfield: stripControlChars(error.field),\n\t\tmessage: stripControlChars(error.message),\n\t\t...(error.code !== undefined ? { code: stripControlChars(error.code) } : {}),\n\t};\n}\n\n/** Build a RFC 9457 validation error response from formatted errors */\nexport function buildValidationResponse(\n\terrors: ValidationError[],\n\toptions?: ValidationHookOptions,\n): Response {\n\tconst body = {\n\t\ttype: \"about:blank\",\n\t\tstatus: 422,\n\t\ttitle: options?.title ?? \"Validation Error\",\n\t\tdetail: options?.detail ?? \"Request validation failed\",\n\t\terrors: errors.map(sanitizeError),\n\t};\n\n\treturn new Response(JSON.stringify(body), {\n\t\tstatus: 422,\n\t\theaders: { \"Content-Type\": PROBLEM_JSON_CONTENT_TYPE },\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,4BAA4B;AAwBzC,IAAM,gBAAgB,KAAK,UAAU;AAAA,EACpC,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AACR,CAAC;;;ACXD,IAAM,kBAAkB;AAExB,SAAS,kBAAkB,OAAuB;AACjD,SAAO,MAAM,QAAQ,iBAAiB,EAAE;AACzC;AAEA,SAAS,cAAc,OAAyC;AAC/D,SAAO;AAAA,IACN,OAAO,kBAAkB,MAAM,KAAK;AAAA,IACpC,SAAS,kBAAkB,MAAM,OAAO;AAAA,IACxC,GAAI,MAAM,SAAS,SAAY,EAAE,MAAM,kBAAkB,MAAM,IAAI,EAAE,IAAI,CAAC;AAAA,EAC3E;AACD;AAGO,SAAS,wBACf,QACA,SACW;AACX,QAAM,OAAO;AAAA,IACZ,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,OAAO,SAAS,SAAS;AAAA,IACzB,QAAQ,SAAS,UAAU;AAAA,IAC3B,QAAQ,OAAO,IAAI,aAAa;AAAA,EACjC;AAEA,SAAO,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG;AAAA,IACzC,QAAQ;AAAA,IACR,SAAS,EAAE,gBAAgB,0BAA0B;AAAA,EACtD,CAAC;AACF;;;AFzCA,SAAS,aAAa,QAAiD;AACtE,SAAO,OAAO,IAAI,CAAC,WAAW;AAAA,IAC7B,OAAO,MAAM,MAAM,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,GAAG,KAAK;AAAA,IAClD,SAAS,MAAM;AAAA,IACf,MAAM,MAAM;AAAA,EACb,EAAE;AACH;AAEO,SAAS,mBACf,SACwF;AACxF,SAAO,CAAC,QAAQ,OAAO;AACtB,QAAI,OAAO,QAAS;AACpB,WAAO,wBAAwB,aAAa,OAAO,MAAM,GAAG,OAAO;AAAA,EACpE;AACD;","names":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Context } from 'hono';
|
|
2
|
-
import { SafeParseResult } from 'valibot';
|
|
2
|
+
import { GenericSchema, GenericSchemaAsync, SafeParseResult } from 'valibot';
|
|
3
3
|
import { V as ValidationHookOptions } from '../validation-DqPEnoIw.cjs';
|
|
4
4
|
|
|
5
|
-
declare function valibotProblemHook(options?: ValidationHookOptions): (result: SafeParseResult<
|
|
5
|
+
declare function valibotProblemHook<T extends GenericSchema | GenericSchemaAsync = GenericSchema>(options?: ValidationHookOptions): (result: SafeParseResult<T> & {
|
|
6
6
|
target: string;
|
|
7
7
|
}, c: Context) => Response | undefined;
|
|
8
8
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Context } from 'hono';
|
|
2
|
-
import { SafeParseResult } from 'valibot';
|
|
2
|
+
import { GenericSchema, GenericSchemaAsync, SafeParseResult } from 'valibot';
|
|
3
3
|
import { V as ValidationHookOptions } from '../validation-DqPEnoIw.js';
|
|
4
4
|
|
|
5
|
-
declare function valibotProblemHook(options?: ValidationHookOptions): (result: SafeParseResult<
|
|
5
|
+
declare function valibotProblemHook<T extends GenericSchema | GenericSchemaAsync = GenericSchema>(options?: ValidationHookOptions): (result: SafeParseResult<T> & {
|
|
6
6
|
target: string;
|
|
7
7
|
}, c: Context) => Response | undefined;
|
|
8
8
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/integrations/valibot.ts"],"sourcesContent":["import type { Context } from \"hono\";\nimport type { BaseIssue, SafeParseResult } from \"valibot\";\nimport {\n\ttype ValidationError,\n\ttype ValidationHookOptions,\n\tbuildValidationResponse,\n} from \"./validation.js\";\n\nexport type { ValidationHookOptions as ValibotProblemHookOptions };\n\nfunction formatIssues(issues: BaseIssue<unknown>[]): ValidationError[] {\n\treturn issues.map((issue) => ({\n\t\tfield: issue.path?.map((p) => p.key).join(\".\") ?? \"\",\n\t\tmessage: issue.message,\n\t\tcode: issue.type,\n\t}));\n}\n\nexport function valibotProblemHook(\n\toptions?: ValidationHookOptions,\n): (result: SafeParseResult<
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/valibot.ts"],"sourcesContent":["import type { Context } from \"hono\";\nimport type { BaseIssue, GenericSchema, GenericSchemaAsync, SafeParseResult } from \"valibot\";\nimport {\n\ttype ValidationError,\n\ttype ValidationHookOptions,\n\tbuildValidationResponse,\n} from \"./validation.js\";\n\nexport type { ValidationHookOptions as ValibotProblemHookOptions };\n\nfunction formatIssues(issues: BaseIssue<unknown>[]): ValidationError[] {\n\treturn issues.map((issue) => ({\n\t\tfield: issue.path?.map((p) => p.key).join(\".\") ?? \"\",\n\t\tmessage: issue.message,\n\t\tcode: issue.type,\n\t}));\n}\n\nexport function valibotProblemHook<T extends GenericSchema | GenericSchemaAsync = GenericSchema>(\n\toptions?: ValidationHookOptions,\n): (result: SafeParseResult<T> & { target: string }, c: Context) => Response | undefined {\n\treturn (result, _c) => {\n\t\tif (result.success) return;\n\t\treturn buildValidationResponse(formatIssues(result.issues), options);\n\t};\n}\n"],"mappings":";;;;;;;AAUA,SAAS,aAAa,QAAiD;AACtE,SAAO,OAAO,IAAI,CAAC,WAAW;AAAA,IAC7B,OAAO,MAAM,MAAM,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,GAAG,KAAK;AAAA,IAClD,SAAS,MAAM;AAAA,IACf,MAAM,MAAM;AAAA,EACb,EAAE;AACH;AAEO,SAAS,mBACf,SACwF;AACxF,SAAO,CAAC,QAAQ,OAAO;AACtB,QAAI,OAAO,QAAS;AACpB,WAAO,wBAAwB,aAAa,OAAO,MAAM,GAAG,OAAO;AAAA,EACpE;AACD;","names":[]}
|
|
@@ -33,13 +33,24 @@ var FALLBACK_BODY = JSON.stringify({
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
// src/integrations/validation.ts
|
|
36
|
+
var CONTROL_CHAR_RE = /[\x00-\x1f\x7f]/g;
|
|
37
|
+
function stripControlChars(input) {
|
|
38
|
+
return input.replace(CONTROL_CHAR_RE, "");
|
|
39
|
+
}
|
|
40
|
+
function sanitizeError(error) {
|
|
41
|
+
return {
|
|
42
|
+
field: stripControlChars(error.field),
|
|
43
|
+
message: stripControlChars(error.message),
|
|
44
|
+
...error.code !== void 0 ? { code: stripControlChars(error.code) } : {}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
36
47
|
function buildValidationResponse(errors, options) {
|
|
37
48
|
const body = {
|
|
38
49
|
type: "about:blank",
|
|
39
50
|
status: 422,
|
|
40
51
|
title: options?.title ?? "Validation Error",
|
|
41
52
|
detail: options?.detail ?? "Request validation failed",
|
|
42
|
-
errors
|
|
53
|
+
errors: errors.map(sanitizeError)
|
|
43
54
|
};
|
|
44
55
|
return new Response(JSON.stringify(body), {
|
|
45
56
|
status: 422,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/integrations/zod.ts","../../src/utils.ts","../../src/integrations/validation.ts"],"sourcesContent":["import type { Context } from \"hono\";\nimport type { ZodError } from \"zod\";\nimport {\n\ttype ValidationError,\n\ttype ValidationHookOptions,\n\tbuildValidationResponse,\n} from \"./validation.js\";\n\nexport type { ValidationHookOptions as ZodProblemHookOptions };\n\nfunction formatErrors(zodError: ZodError): ValidationError[] {\n\treturn zodError.issues.map((issue) => ({\n\t\tfield: issue.path.join(\".\"),\n\t\tmessage: issue.message,\n\t\tcode: issue.code,\n\t}));\n}\n\nexport function zodProblemHook(\n\toptions?: ValidationHookOptions,\n): (\n\tresult: { success: true; data: unknown } | { success: false; error: ZodError },\n\tc: Context,\n) => Response | undefined {\n\treturn (result, _c) => {\n\t\tif (result.success) return;\n\t\treturn buildValidationResponse(formatErrors(result.error), options);\n\t};\n}\n","import { statusToPhrase } from \"./status.js\";\nimport type { ProblemDetails, ProblemDetailsInput } from \"./types.js\";\n\nexport const PROBLEM_JSON_CONTENT_TYPE = \"application/problem+json; charset=utf-8\";\n\nconst DANGEROUS_KEYS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\n/** Strip keys that could cause prototype pollution in downstream consumers */\nexport function sanitizeExtensions(\n\textensions: Record<string, unknown> | undefined,\n): Record<string, unknown> | undefined {\n\tif (!extensions) return extensions;\n\tlet filtered: Record<string, unknown> | undefined;\n\tfor (const key of Object.keys(extensions)) {\n\t\tif (DANGEROUS_KEYS.has(key)) {\n\t\t\tif (!filtered) filtered = { ...extensions };\n\t\t\tdelete filtered[key];\n\t\t}\n\t}\n\treturn filtered ?? extensions;\n}\n\n/** Clamp HTTP status to 200-599 range; returns 500 for out-of-range values */\nexport function clampHttpStatus(status: number): number {\n\treturn status >= 200 && status <= 599 ? status : 500;\n}\n\nconst FALLBACK_BODY = JSON.stringify({\n\ttype: \"about:blank\",\n\tstatus: 500,\n\ttitle: \"Internal Server Error\",\n});\n\n/** Normalize ProblemDetailsInput to ProblemDetails with defaults for type and title */\nexport function normalizeProblemDetails<T extends Record<string, unknown>>(\n\tinput: ProblemDetailsInput<T>,\n): ProblemDetails<T> {\n\treturn {\n\t\ttype: input.type ?? \"about:blank\",\n\t\tstatus: input.status,\n\t\ttitle: input.title ?? statusToPhrase(input.status) ?? \"Unknown Error\",\n\t\tdetail: input.detail,\n\t\tinstance: input.instance,\n\t\textensions: input.extensions,\n\t};\n}\n\n/** Build a RFC 9457 Problem Details Response from a ProblemDetails object */\nexport function buildProblemResponse(pd: ProblemDetails): Response {\n\tconst { extensions, ...standard } = pd;\n\tconst body = { ...sanitizeExtensions(extensions), ...standard };\n\tconst { json, fallback } = safeStringify(body);\n\treturn new Response(json, {\n\t\tstatus: fallback ? 500 : clampHttpStatus(pd.status),\n\t\theaders: { \"Content-Type\": PROBLEM_JSON_CONTENT_TYPE },\n\t});\n}\n\n/** JSON.stringify with fallback for non-serializable values (circular refs, BigInt) */\nexport function safeStringify(body: unknown): { json: string; fallback: boolean } {\n\ttry {\n\t\treturn { json: JSON.stringify(body), fallback: false };\n\t} catch {\n\t\treturn { json: FALLBACK_BODY, fallback: true };\n\t}\n}\n","import { PROBLEM_JSON_CONTENT_TYPE } from \"../utils.js\";\n\nexport interface ValidationError {\n\tfield: string;\n\tmessage: string;\n\tcode?: string;\n}\n\nexport interface ValidationHookOptions {\n\ttitle?: string;\n\tdetail?: string;\n}\n\n/** Build a RFC 9457 validation error response from formatted errors */\nexport function buildValidationResponse(\n\terrors: ValidationError[],\n\toptions?: ValidationHookOptions,\n): Response {\n\tconst body = {\n\t\ttype: \"about:blank\",\n\t\tstatus: 422,\n\t\ttitle: options?.title ?? \"Validation Error\",\n\t\tdetail: options?.detail ?? \"Request validation failed\",\n\t\terrors,\n\t};\n\n\treturn new Response(JSON.stringify(body), {\n\t\tstatus: 422,\n\t\theaders: { \"Content-Type\": PROBLEM_JSON_CONTENT_TYPE },\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,4BAA4B;AAwBzC,IAAM,gBAAgB,KAAK,UAAU;AAAA,EACpC,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AACR,CAAC;;;
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/zod.ts","../../src/utils.ts","../../src/integrations/validation.ts"],"sourcesContent":["import type { Context } from \"hono\";\nimport type { ZodError } from \"zod\";\nimport {\n\ttype ValidationError,\n\ttype ValidationHookOptions,\n\tbuildValidationResponse,\n} from \"./validation.js\";\n\nexport type { ValidationHookOptions as ZodProblemHookOptions };\n\nfunction formatErrors(zodError: ZodError): ValidationError[] {\n\treturn zodError.issues.map((issue) => ({\n\t\tfield: issue.path.join(\".\"),\n\t\tmessage: issue.message,\n\t\tcode: issue.code,\n\t}));\n}\n\nexport function zodProblemHook(\n\toptions?: ValidationHookOptions,\n): (\n\tresult: { success: true; data: unknown } | { success: false; error: ZodError },\n\tc: Context,\n) => Response | undefined {\n\treturn (result, _c) => {\n\t\tif (result.success) return;\n\t\treturn buildValidationResponse(formatErrors(result.error), options);\n\t};\n}\n","import { statusToPhrase } from \"./status.js\";\nimport type { ProblemDetails, ProblemDetailsInput } from \"./types.js\";\n\nexport const PROBLEM_JSON_CONTENT_TYPE = \"application/problem+json; charset=utf-8\";\n\nconst DANGEROUS_KEYS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\n/** Strip keys that could cause prototype pollution in downstream consumers */\nexport function sanitizeExtensions(\n\textensions: Record<string, unknown> | undefined,\n): Record<string, unknown> | undefined {\n\tif (!extensions) return extensions;\n\tlet filtered: Record<string, unknown> | undefined;\n\tfor (const key of Object.keys(extensions)) {\n\t\tif (DANGEROUS_KEYS.has(key)) {\n\t\t\tif (!filtered) filtered = { ...extensions };\n\t\t\tdelete filtered[key];\n\t\t}\n\t}\n\treturn filtered ?? extensions;\n}\n\n/** Clamp HTTP status to 200-599 integer range; returns 500 for out-of-range or non-integer values */\nexport function clampHttpStatus(status: number): number {\n\treturn Number.isInteger(status) && status >= 200 && status <= 599 ? status : 500;\n}\n\nconst FALLBACK_BODY = JSON.stringify({\n\ttype: \"about:blank\",\n\tstatus: 500,\n\ttitle: \"Internal Server Error\",\n});\n\n/** Normalize ProblemDetailsInput to ProblemDetails with defaults for type and title */\nexport function normalizeProblemDetails<T extends Record<string, unknown>>(\n\tinput: ProblemDetailsInput<T>,\n): ProblemDetails<T> {\n\treturn {\n\t\ttype: input.type ?? \"about:blank\",\n\t\tstatus: input.status,\n\t\ttitle: input.title ?? statusToPhrase(input.status) ?? \"Unknown Error\",\n\t\tdetail: input.detail,\n\t\tinstance: input.instance,\n\t\textensions: input.extensions,\n\t};\n}\n\n/** Build a RFC 9457 Problem Details Response from a ProblemDetails object */\nexport function buildProblemResponse(pd: ProblemDetails): Response {\n\tconst { extensions, ...standard } = pd;\n\tconst body = { ...sanitizeExtensions(extensions), ...standard };\n\tconst { json, fallback } = safeStringify(body);\n\treturn new Response(json, {\n\t\tstatus: fallback ? 500 : clampHttpStatus(pd.status),\n\t\theaders: { \"Content-Type\": PROBLEM_JSON_CONTENT_TYPE },\n\t});\n}\n\n/** JSON.stringify with fallback for non-serializable values (circular refs, BigInt) */\nexport function safeStringify(body: unknown): { json: string; fallback: boolean } {\n\ttry {\n\t\treturn { json: JSON.stringify(body), fallback: false };\n\t} catch {\n\t\treturn { json: FALLBACK_BODY, fallback: true };\n\t}\n}\n","import { PROBLEM_JSON_CONTENT_TYPE } from \"../utils.js\";\n\nexport interface ValidationError {\n\tfield: string;\n\tmessage: string;\n\tcode?: string;\n}\n\nexport interface ValidationHookOptions {\n\ttitle?: string;\n\tdetail?: string;\n}\n\n/**\n * Strip C0 control characters (\\x00-\\x1f) and DEL (\\x7f) from untrusted text.\n * Bidi/format control chars (U+2028, U+202E, etc.) are intentionally left intact\n * to avoid breaking legitimate i18n content; log consumers should apply their\n * own bidi-safe rendering.\n */\n// biome-ignore lint/suspicious/noControlCharactersInRegex: intentional stripping of C0 controls\nconst CONTROL_CHAR_RE = /[\\x00-\\x1f\\x7f]/g;\n\nfunction stripControlChars(input: string): string {\n\treturn input.replace(CONTROL_CHAR_RE, \"\");\n}\n\nfunction sanitizeError(error: ValidationError): ValidationError {\n\treturn {\n\t\tfield: stripControlChars(error.field),\n\t\tmessage: stripControlChars(error.message),\n\t\t...(error.code !== undefined ? { code: stripControlChars(error.code) } : {}),\n\t};\n}\n\n/** Build a RFC 9457 validation error response from formatted errors */\nexport function buildValidationResponse(\n\terrors: ValidationError[],\n\toptions?: ValidationHookOptions,\n): Response {\n\tconst body = {\n\t\ttype: \"about:blank\",\n\t\tstatus: 422,\n\t\ttitle: options?.title ?? \"Validation Error\",\n\t\tdetail: options?.detail ?? \"Request validation failed\",\n\t\terrors: errors.map(sanitizeError),\n\t};\n\n\treturn new Response(JSON.stringify(body), {\n\t\tstatus: 422,\n\t\theaders: { \"Content-Type\": PROBLEM_JSON_CONTENT_TYPE },\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,4BAA4B;AAwBzC,IAAM,gBAAgB,KAAK,UAAU;AAAA,EACpC,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AACR,CAAC;;;ACXD,IAAM,kBAAkB;AAExB,SAAS,kBAAkB,OAAuB;AACjD,SAAO,MAAM,QAAQ,iBAAiB,EAAE;AACzC;AAEA,SAAS,cAAc,OAAyC;AAC/D,SAAO;AAAA,IACN,OAAO,kBAAkB,MAAM,KAAK;AAAA,IACpC,SAAS,kBAAkB,MAAM,OAAO;AAAA,IACxC,GAAI,MAAM,SAAS,SAAY,EAAE,MAAM,kBAAkB,MAAM,IAAI,EAAE,IAAI,CAAC;AAAA,EAC3E;AACD;AAGO,SAAS,wBACf,QACA,SACW;AACX,QAAM,OAAO;AAAA,IACZ,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,OAAO,SAAS,SAAS;AAAA,IACzB,QAAQ,SAAS,UAAU;AAAA,IAC3B,QAAQ,OAAO,IAAI,aAAa;AAAA,EACjC;AAEA,SAAO,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG;AAAA,IACzC,QAAQ;AAAA,IACR,SAAS,EAAE,gBAAgB,0BAA0B;AAAA,EACtD,CAAC;AACF;;;AFzCA,SAAS,aAAa,UAAuC;AAC5D,SAAO,SAAS,OAAO,IAAI,CAAC,WAAW;AAAA,IACtC,OAAO,MAAM,KAAK,KAAK,GAAG;AAAA,IAC1B,SAAS,MAAM;AAAA,IACf,MAAM,MAAM;AAAA,EACb,EAAE;AACH;AAEO,SAAS,eACf,SAIyB;AACzB,SAAO,CAAC,QAAQ,OAAO;AACtB,QAAI,OAAO,QAAS;AACpB,WAAO,wBAAwB,aAAa,OAAO,KAAK,GAAG,OAAO;AAAA,EACnE;AACD;","names":[]}
|
package/dist/integrations/zod.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono-problem-details",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "RFC 9457 Problem Details middleware for Hono",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -156,7 +156,7 @@
|
|
|
156
156
|
"lint:fix": "biome check --write .",
|
|
157
157
|
"format": "biome format --write .",
|
|
158
158
|
"typecheck": "tsc --noEmit",
|
|
159
|
-
"release": "pnpm build && changeset publish
|
|
159
|
+
"release": "pnpm build && changeset publish",
|
|
160
160
|
"version-packages": "changeset version && pnpm lint:fix"
|
|
161
161
|
}
|
|
162
162
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/integrations/validation.ts"],"sourcesContent":["import { PROBLEM_JSON_CONTENT_TYPE } from \"../utils.js\";\n\nexport interface ValidationError {\n\tfield: string;\n\tmessage: string;\n\tcode?: string;\n}\n\nexport interface ValidationHookOptions {\n\ttitle?: string;\n\tdetail?: string;\n}\n\n/** Build a RFC 9457 validation error response from formatted errors */\nexport function buildValidationResponse(\n\terrors: ValidationError[],\n\toptions?: ValidationHookOptions,\n): Response {\n\tconst body = {\n\t\ttype: \"about:blank\",\n\t\tstatus: 422,\n\t\ttitle: options?.title ?? \"Validation Error\",\n\t\tdetail: options?.detail ?? \"Request validation failed\",\n\t\terrors,\n\t};\n\n\treturn new Response(JSON.stringify(body), {\n\t\tstatus: 422,\n\t\theaders: { \"Content-Type\": PROBLEM_JSON_CONTENT_TYPE },\n\t});\n}\n"],"mappings":";;;;;AAcO,SAAS,wBACf,QACA,SACW;AACX,QAAM,OAAO;AAAA,IACZ,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,OAAO,SAAS,SAAS;AAAA,IACzB,QAAQ,SAAS,UAAU;AAAA,IAC3B;AAAA,EACD;AAEA,SAAO,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG;AAAA,IACzC,QAAQ;AAAA,IACR,SAAS,EAAE,gBAAgB,0BAA0B;AAAA,EACtD,CAAC;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import { statusToPhrase } from \"./status.js\";\nimport type { ProblemDetails, ProblemDetailsInput } from \"./types.js\";\n\nexport const PROBLEM_JSON_CONTENT_TYPE = \"application/problem+json; charset=utf-8\";\n\nconst DANGEROUS_KEYS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\n/** Strip keys that could cause prototype pollution in downstream consumers */\nexport function sanitizeExtensions(\n\textensions: Record<string, unknown> | undefined,\n): Record<string, unknown> | undefined {\n\tif (!extensions) return extensions;\n\tlet filtered: Record<string, unknown> | undefined;\n\tfor (const key of Object.keys(extensions)) {\n\t\tif (DANGEROUS_KEYS.has(key)) {\n\t\t\tif (!filtered) filtered = { ...extensions };\n\t\t\tdelete filtered[key];\n\t\t}\n\t}\n\treturn filtered ?? extensions;\n}\n\n/** Clamp HTTP status to 200-599 range; returns 500 for out-of-range values */\nexport function clampHttpStatus(status: number): number {\n\treturn status >= 200 && status <= 599 ? status : 500;\n}\n\nconst FALLBACK_BODY = JSON.stringify({\n\ttype: \"about:blank\",\n\tstatus: 500,\n\ttitle: \"Internal Server Error\",\n});\n\n/** Normalize ProblemDetailsInput to ProblemDetails with defaults for type and title */\nexport function normalizeProblemDetails<T extends Record<string, unknown>>(\n\tinput: ProblemDetailsInput<T>,\n): ProblemDetails<T> {\n\treturn {\n\t\ttype: input.type ?? \"about:blank\",\n\t\tstatus: input.status,\n\t\ttitle: input.title ?? statusToPhrase(input.status) ?? \"Unknown Error\",\n\t\tdetail: input.detail,\n\t\tinstance: input.instance,\n\t\textensions: input.extensions,\n\t};\n}\n\n/** Build a RFC 9457 Problem Details Response from a ProblemDetails object */\nexport function buildProblemResponse(pd: ProblemDetails): Response {\n\tconst { extensions, ...standard } = pd;\n\tconst body = { ...sanitizeExtensions(extensions), ...standard };\n\tconst { json, fallback } = safeStringify(body);\n\treturn new Response(json, {\n\t\tstatus: fallback ? 500 : clampHttpStatus(pd.status),\n\t\theaders: { \"Content-Type\": PROBLEM_JSON_CONTENT_TYPE },\n\t});\n}\n\n/** JSON.stringify with fallback for non-serializable values (circular refs, BigInt) */\nexport function safeStringify(body: unknown): { json: string; fallback: boolean } {\n\ttry {\n\t\treturn { json: JSON.stringify(body), f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