hono-problem-details 0.12.1 → 0.12.3
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/LICENSE +1 -1
- package/README.md +6 -0
- package/dist/chunk-4NRZFPAP.cjs +60 -0
- package/dist/chunk-MIFBVO2E.cjs +34 -0
- package/dist/chunk-QC5C2ZNY.cjs +47 -0
- package/dist/chunk-YLXWVI2T.cjs +60 -0
- package/dist/index.cjs +56 -197
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +15 -4
- package/dist/integrations/openapi-json-schema.cjs +11 -93
- package/dist/integrations/openapi-json-schema.d.cts +2 -1
- package/dist/integrations/openapi-json-schema.d.ts +2 -1
- package/dist/integrations/openapi.cjs +16 -94
- package/dist/integrations/standard-schema.cjs +9 -195
- package/dist/integrations/valibot.cjs +10 -196
- package/dist/integrations/zod.cjs +9 -195
- package/package.json +6 -5
|
@@ -1,90 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
var openapi_json_schema_exports = {};
|
|
22
|
-
__export(openapi_json_schema_exports, {
|
|
23
|
-
problemDetailsJsonSchema: () => problemDetailsJsonSchema,
|
|
24
|
-
problemDetailsResponseJsonSchema: () => problemDetailsResponseJsonSchema
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(openapi_json_schema_exports);
|
|
3
|
+
var _chunk4NRZFPAPcjs = require('../chunk-4NRZFPAP.cjs');
|
|
27
4
|
|
|
28
|
-
// src/status.ts
|
|
29
|
-
var STATUS_PHRASES = {
|
|
30
|
-
400: "Bad Request",
|
|
31
|
-
401: "Unauthorized",
|
|
32
|
-
402: "Payment Required",
|
|
33
|
-
403: "Forbidden",
|
|
34
|
-
404: "Not Found",
|
|
35
|
-
405: "Method Not Allowed",
|
|
36
|
-
406: "Not Acceptable",
|
|
37
|
-
407: "Proxy Authentication Required",
|
|
38
|
-
408: "Request Timeout",
|
|
39
|
-
409: "Conflict",
|
|
40
|
-
410: "Gone",
|
|
41
|
-
411: "Length Required",
|
|
42
|
-
412: "Precondition Failed",
|
|
43
|
-
413: "Content Too Large",
|
|
44
|
-
414: "URI Too Long",
|
|
45
|
-
415: "Unsupported Media Type",
|
|
46
|
-
416: "Range Not Satisfiable",
|
|
47
|
-
417: "Expectation Failed",
|
|
48
|
-
418: "I'm a Teapot",
|
|
49
|
-
421: "Misdirected Request",
|
|
50
|
-
422: "Unprocessable Content",
|
|
51
|
-
423: "Locked",
|
|
52
|
-
424: "Failed Dependency",
|
|
53
|
-
425: "Too Early",
|
|
54
|
-
426: "Upgrade Required",
|
|
55
|
-
428: "Precondition Required",
|
|
56
|
-
429: "Too Many Requests",
|
|
57
|
-
431: "Request Header Fields Too Large",
|
|
58
|
-
451: "Unavailable For Legal Reasons",
|
|
59
|
-
500: "Internal Server Error",
|
|
60
|
-
501: "Not Implemented",
|
|
61
|
-
502: "Bad Gateway",
|
|
62
|
-
503: "Service Unavailable",
|
|
63
|
-
504: "Gateway Timeout",
|
|
64
|
-
505: "HTTP Version Not Supported",
|
|
65
|
-
506: "Variant Also Negotiates",
|
|
66
|
-
507: "Insufficient Storage",
|
|
67
|
-
508: "Loop Detected",
|
|
68
|
-
510: "Not Extended",
|
|
69
|
-
511: "Network Authentication Required"
|
|
70
|
-
};
|
|
71
|
-
var STATUS_SLUGS = Object.fromEntries(
|
|
72
|
-
Object.entries(STATUS_PHRASES).map(([code, phrase]) => [
|
|
73
|
-
Number(code),
|
|
74
|
-
phrase.toLowerCase().replace(/'/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "")
|
|
75
|
-
])
|
|
76
|
-
);
|
|
77
|
-
function statusToPhrase(status) {
|
|
78
|
-
return STATUS_PHRASES[status];
|
|
79
|
-
}
|
|
80
5
|
|
|
81
|
-
|
|
82
|
-
var DANGEROUS_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
83
|
-
var FALLBACK_BODY = JSON.stringify({
|
|
84
|
-
type: "about:blank",
|
|
85
|
-
status: 500,
|
|
86
|
-
title: "Internal Server Error"
|
|
87
|
-
});
|
|
6
|
+
var _chunkYLXWVI2Tcjs = require('../chunk-YLXWVI2T.cjs');
|
|
88
7
|
|
|
89
8
|
// src/integrations/openapi-json-schema.ts
|
|
90
9
|
var STANDARD_FIELD_KEYS = /* @__PURE__ */ new Set(["type", "status", "title", "detail", "instance"]);
|
|
@@ -100,8 +19,8 @@ function problemDetailsJsonSchema(options) {
|
|
|
100
19
|
detail: { type: "string", description: "Human-readable explanation" },
|
|
101
20
|
instance: { type: "string", description: "URI identifying the occurrence" }
|
|
102
21
|
};
|
|
103
|
-
for (const [key, schema] of Object.entries(options
|
|
104
|
-
if (!STANDARD_FIELD_KEYS.has(key) && !DANGEROUS_KEYS.has(key)) {
|
|
22
|
+
for (const [key, schema] of Object.entries(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _ => _.extensions]), () => ( {})))) {
|
|
23
|
+
if (!STANDARD_FIELD_KEYS.has(key) && !_chunk4NRZFPAPcjs.DANGEROUS_KEYS.has(key)) {
|
|
105
24
|
properties[key] = structuredClone(schema);
|
|
106
25
|
}
|
|
107
26
|
}
|
|
@@ -115,13 +34,12 @@ function problemDetailsJsonSchema(options) {
|
|
|
115
34
|
function problemDetailsResponseJsonSchema(status, description, schema) {
|
|
116
35
|
return {
|
|
117
36
|
content: {
|
|
118
|
-
"application/problem+json": { schema: schema
|
|
37
|
+
"application/problem+json": { schema: _nullishCoalesce(schema, () => ( problemDetailsJsonSchema())) }
|
|
119
38
|
},
|
|
120
|
-
description: description
|
|
39
|
+
description: _nullishCoalesce(_nullishCoalesce(description, () => ( _chunkYLXWVI2Tcjs.statusToPhrase.call(void 0, status))), () => ( "Error"))
|
|
121
40
|
};
|
|
122
41
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
});
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
exports.problemDetailsJsonSchema = problemDetailsJsonSchema; exports.problemDetailsResponseJsonSchema = problemDetailsResponseJsonSchema;
|
|
@@ -37,4 +37,5 @@ declare function problemDetailsResponseJsonSchema(status: number, description?:
|
|
|
37
37
|
description: string;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
export {
|
|
40
|
+
export { problemDetailsJsonSchema, problemDetailsResponseJsonSchema };
|
|
41
|
+
export type { JsonSchemaObject, ProblemDetailsJsonSchema };
|
|
@@ -37,4 +37,5 @@ declare function problemDetailsResponseJsonSchema(status: number, description?:
|
|
|
37
37
|
description: string;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
export {
|
|
40
|
+
export { problemDetailsJsonSchema, problemDetailsResponseJsonSchema };
|
|
41
|
+
export type { JsonSchemaObject, ProblemDetailsJsonSchema };
|
|
@@ -1,95 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/integrations/openapi.ts
|
|
21
|
-
var openapi_exports = {};
|
|
22
|
-
__export(openapi_exports, {
|
|
23
|
-
createProblemDetailsSchema: () => createProblemDetailsSchema,
|
|
24
|
-
getProblemDetailsSchema: () => getProblemDetailsSchema,
|
|
25
|
-
problemDetailsResponse: () => problemDetailsResponse
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(openapi_exports);
|
|
28
|
-
var import_zod_openapi = require("@hono/zod-openapi");
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
29
2
|
|
|
30
|
-
|
|
31
|
-
var STATUS_PHRASES = {
|
|
32
|
-
400: "Bad Request",
|
|
33
|
-
401: "Unauthorized",
|
|
34
|
-
402: "Payment Required",
|
|
35
|
-
403: "Forbidden",
|
|
36
|
-
404: "Not Found",
|
|
37
|
-
405: "Method Not Allowed",
|
|
38
|
-
406: "Not Acceptable",
|
|
39
|
-
407: "Proxy Authentication Required",
|
|
40
|
-
408: "Request Timeout",
|
|
41
|
-
409: "Conflict",
|
|
42
|
-
410: "Gone",
|
|
43
|
-
411: "Length Required",
|
|
44
|
-
412: "Precondition Failed",
|
|
45
|
-
413: "Content Too Large",
|
|
46
|
-
414: "URI Too Long",
|
|
47
|
-
415: "Unsupported Media Type",
|
|
48
|
-
416: "Range Not Satisfiable",
|
|
49
|
-
417: "Expectation Failed",
|
|
50
|
-
418: "I'm a Teapot",
|
|
51
|
-
421: "Misdirected Request",
|
|
52
|
-
422: "Unprocessable Content",
|
|
53
|
-
423: "Locked",
|
|
54
|
-
424: "Failed Dependency",
|
|
55
|
-
425: "Too Early",
|
|
56
|
-
426: "Upgrade Required",
|
|
57
|
-
428: "Precondition Required",
|
|
58
|
-
429: "Too Many Requests",
|
|
59
|
-
431: "Request Header Fields Too Large",
|
|
60
|
-
451: "Unavailable For Legal Reasons",
|
|
61
|
-
500: "Internal Server Error",
|
|
62
|
-
501: "Not Implemented",
|
|
63
|
-
502: "Bad Gateway",
|
|
64
|
-
503: "Service Unavailable",
|
|
65
|
-
504: "Gateway Timeout",
|
|
66
|
-
505: "HTTP Version Not Supported",
|
|
67
|
-
506: "Variant Also Negotiates",
|
|
68
|
-
507: "Insufficient Storage",
|
|
69
|
-
508: "Loop Detected",
|
|
70
|
-
510: "Not Extended",
|
|
71
|
-
511: "Network Authentication Required"
|
|
72
|
-
};
|
|
73
|
-
var STATUS_SLUGS = Object.fromEntries(
|
|
74
|
-
Object.entries(STATUS_PHRASES).map(([code, phrase]) => [
|
|
75
|
-
Number(code),
|
|
76
|
-
phrase.toLowerCase().replace(/'/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "")
|
|
77
|
-
])
|
|
78
|
-
);
|
|
79
|
-
function statusToPhrase(status) {
|
|
80
|
-
return STATUS_PHRASES[status];
|
|
81
|
-
}
|
|
3
|
+
var _chunkYLXWVI2Tcjs = require('../chunk-YLXWVI2T.cjs');
|
|
82
4
|
|
|
83
5
|
// src/integrations/openapi.ts
|
|
6
|
+
var _zodopenapi = require('@hono/zod-openapi');
|
|
84
7
|
var _cached;
|
|
85
8
|
function getProblemDetailsSchema() {
|
|
86
9
|
if (!_cached) {
|
|
87
|
-
_cached =
|
|
88
|
-
type:
|
|
89
|
-
status:
|
|
90
|
-
title:
|
|
91
|
-
detail:
|
|
92
|
-
instance:
|
|
10
|
+
_cached = _zodopenapi.z.object({
|
|
11
|
+
type: _zodopenapi.z.string().openapi({ description: "Problem type URI", example: "about:blank" }),
|
|
12
|
+
status: _zodopenapi.z.number().int().openapi({ description: "HTTP status code", example: 400 }),
|
|
13
|
+
title: _zodopenapi.z.string().openapi({ description: "Short summary of the problem type", example: "Bad Request" }),
|
|
14
|
+
detail: _zodopenapi.z.string().optional().openapi({ description: "Human-readable explanation" }),
|
|
15
|
+
instance: _zodopenapi.z.string().optional().openapi({ description: "URI identifying the occurrence" })
|
|
93
16
|
}).openapi({ title: "ProblemDetails" });
|
|
94
17
|
}
|
|
95
18
|
return _cached;
|
|
@@ -104,14 +27,13 @@ function createProblemDetailsSchema(extensions) {
|
|
|
104
27
|
function problemDetailsResponse(status, description, schema) {
|
|
105
28
|
return {
|
|
106
29
|
content: {
|
|
107
|
-
"application/problem+json": { schema: schema
|
|
30
|
+
"application/problem+json": { schema: _nullishCoalesce(schema, () => ( getProblemDetailsSchema())) }
|
|
108
31
|
},
|
|
109
|
-
description: description
|
|
32
|
+
description: _nullishCoalesce(_nullishCoalesce(description, () => ( _chunkYLXWVI2Tcjs.statusToPhrase.call(void 0, status))), () => ( "Error"))
|
|
110
33
|
};
|
|
111
34
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
});
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
exports.createProblemDetailsSchema = createProblemDetailsSchema; exports.getProblemDetailsSchema = getProblemDetailsSchema; exports.problemDetailsResponse = problemDetailsResponse;
|
|
@@ -1,194 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(standard_schema_exports);
|
|
26
|
-
|
|
27
|
-
// src/status.ts
|
|
28
|
-
var STATUS_PHRASES = {
|
|
29
|
-
400: "Bad Request",
|
|
30
|
-
401: "Unauthorized",
|
|
31
|
-
402: "Payment Required",
|
|
32
|
-
403: "Forbidden",
|
|
33
|
-
404: "Not Found",
|
|
34
|
-
405: "Method Not Allowed",
|
|
35
|
-
406: "Not Acceptable",
|
|
36
|
-
407: "Proxy Authentication Required",
|
|
37
|
-
408: "Request Timeout",
|
|
38
|
-
409: "Conflict",
|
|
39
|
-
410: "Gone",
|
|
40
|
-
411: "Length Required",
|
|
41
|
-
412: "Precondition Failed",
|
|
42
|
-
413: "Content Too Large",
|
|
43
|
-
414: "URI Too Long",
|
|
44
|
-
415: "Unsupported Media Type",
|
|
45
|
-
416: "Range Not Satisfiable",
|
|
46
|
-
417: "Expectation Failed",
|
|
47
|
-
418: "I'm a Teapot",
|
|
48
|
-
421: "Misdirected Request",
|
|
49
|
-
422: "Unprocessable Content",
|
|
50
|
-
423: "Locked",
|
|
51
|
-
424: "Failed Dependency",
|
|
52
|
-
425: "Too Early",
|
|
53
|
-
426: "Upgrade Required",
|
|
54
|
-
428: "Precondition Required",
|
|
55
|
-
429: "Too Many Requests",
|
|
56
|
-
431: "Request Header Fields Too Large",
|
|
57
|
-
451: "Unavailable For Legal Reasons",
|
|
58
|
-
500: "Internal Server Error",
|
|
59
|
-
501: "Not Implemented",
|
|
60
|
-
502: "Bad Gateway",
|
|
61
|
-
503: "Service Unavailable",
|
|
62
|
-
504: "Gateway Timeout",
|
|
63
|
-
505: "HTTP Version Not Supported",
|
|
64
|
-
506: "Variant Also Negotiates",
|
|
65
|
-
507: "Insufficient Storage",
|
|
66
|
-
508: "Loop Detected",
|
|
67
|
-
510: "Not Extended",
|
|
68
|
-
511: "Network Authentication Required"
|
|
69
|
-
};
|
|
70
|
-
var STATUS_SLUGS = Object.fromEntries(
|
|
71
|
-
Object.entries(STATUS_PHRASES).map(([code, phrase]) => [
|
|
72
|
-
Number(code),
|
|
73
|
-
phrase.toLowerCase().replace(/'/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "")
|
|
74
|
-
])
|
|
75
|
-
);
|
|
76
|
-
function statusToPhrase(status) {
|
|
77
|
-
return STATUS_PHRASES[status];
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// src/utils.ts
|
|
81
|
-
var PROBLEM_JSON_CONTENT_TYPE = "application/problem+json; charset=utf-8";
|
|
82
|
-
var DANGEROUS_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
83
|
-
function sanitizeExtensions(extensions) {
|
|
84
|
-
if (!extensions) return extensions;
|
|
85
|
-
let filtered;
|
|
86
|
-
for (const key of Object.keys(extensions)) {
|
|
87
|
-
if (DANGEROUS_KEYS.has(key)) {
|
|
88
|
-
if (!filtered) filtered = { ...extensions };
|
|
89
|
-
delete filtered[key];
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return filtered ?? extensions;
|
|
93
|
-
}
|
|
94
|
-
function clampHttpStatus(status) {
|
|
95
|
-
return Number.isInteger(status) && status >= 200 && status <= 599 ? status : 500;
|
|
96
|
-
}
|
|
97
|
-
var FALLBACK_BODY = JSON.stringify({
|
|
98
|
-
type: "about:blank",
|
|
99
|
-
status: 500,
|
|
100
|
-
title: "Internal Server Error"
|
|
101
|
-
});
|
|
102
|
-
function normalizeProblemDetails(input) {
|
|
103
|
-
return {
|
|
104
|
-
type: input.type ?? "about:blank",
|
|
105
|
-
status: input.status,
|
|
106
|
-
title: input.title ?? statusToPhrase(input.status) ?? "Unknown Error",
|
|
107
|
-
detail: input.detail,
|
|
108
|
-
instance: input.instance,
|
|
109
|
-
extensions: input.extensions
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
function buildProblemResponse(pd) {
|
|
113
|
-
const { extensions, ...standard } = pd;
|
|
114
|
-
const status = clampHttpStatus(pd.status);
|
|
115
|
-
const body = { ...sanitizeExtensions(extensions), ...standard, status };
|
|
116
|
-
const { json, fallback } = safeStringify(body);
|
|
117
|
-
return new Response(json, {
|
|
118
|
-
status: fallback ? 500 : status,
|
|
119
|
-
headers: { "Content-Type": PROBLEM_JSON_CONTENT_TYPE }
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
function safeStringify(body) {
|
|
123
|
-
try {
|
|
124
|
-
return { json: JSON.stringify(body), fallback: false };
|
|
125
|
-
} catch {
|
|
126
|
-
return { json: FALLBACK_BODY, fallback: true };
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// src/error.ts
|
|
131
|
-
var ProblemDetailsError = class extends Error {
|
|
132
|
-
/** The normalized RFC 9457 Problem Details object. */
|
|
133
|
-
problemDetails;
|
|
134
|
-
/**
|
|
135
|
-
* Whether the input carried an explicit `type`. Lets the handler apply
|
|
136
|
-
* `typePrefix`/`defaultType` only when the thrower left `type` unset.
|
|
137
|
-
*/
|
|
138
|
-
hasExplicitType;
|
|
139
|
-
/**
|
|
140
|
-
* @param input - Missing `type` defaults to `"about:blank"`;
|
|
141
|
-
* missing `title` is derived from the HTTP status code.
|
|
142
|
-
*/
|
|
143
|
-
constructor(input) {
|
|
144
|
-
const pd = normalizeProblemDetails(input);
|
|
145
|
-
super(pd.detail ?? pd.title);
|
|
146
|
-
this.name = "ProblemDetailsError";
|
|
147
|
-
this.problemDetails = pd;
|
|
148
|
-
this.hasExplicitType = input.type !== void 0;
|
|
149
|
-
}
|
|
150
|
-
/** Build a standalone `application/problem+json` Response without the handler middleware. */
|
|
151
|
-
getResponse() {
|
|
152
|
-
return buildProblemResponse(this.problemDetails);
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
// src/integrations/validation.ts
|
|
157
|
-
var CONTROL_CHAR_RE = /[\x00-\x1f\x7f]/g;
|
|
158
|
-
function stripControlChars(input) {
|
|
159
|
-
return input.replace(CONTROL_CHAR_RE, "");
|
|
160
|
-
}
|
|
161
|
-
function sanitizeError(error) {
|
|
162
|
-
return {
|
|
163
|
-
field: stripControlChars(error.field),
|
|
164
|
-
message: stripControlChars(error.message),
|
|
165
|
-
...error.code !== void 0 ? { code: stripControlChars(error.code) } : {}
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
function buildValidationResponse(errors, options) {
|
|
169
|
-
const title = options?.title ?? "Validation Error";
|
|
170
|
-
const detail = options?.detail ?? "Request validation failed";
|
|
171
|
-
const sanitizedErrors = errors.map(sanitizeError);
|
|
172
|
-
if (options?.delegateToHandler) {
|
|
173
|
-
throw new ProblemDetailsError({
|
|
174
|
-
status: 422,
|
|
175
|
-
title,
|
|
176
|
-
detail,
|
|
177
|
-
extensions: { errors: sanitizedErrors }
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
const body = {
|
|
181
|
-
type: "about:blank",
|
|
182
|
-
status: 422,
|
|
183
|
-
title,
|
|
184
|
-
detail,
|
|
185
|
-
errors: sanitizedErrors
|
|
186
|
-
};
|
|
187
|
-
return new Response(JSON.stringify(body), {
|
|
188
|
-
status: 422,
|
|
189
|
-
headers: { "Content-Type": PROBLEM_JSON_CONTENT_TYPE }
|
|
190
|
-
});
|
|
191
|
-
}
|
|
3
|
+
var _chunkQC5C2ZNYcjs = require('../chunk-QC5C2ZNY.cjs');
|
|
4
|
+
require('../chunk-MIFBVO2E.cjs');
|
|
5
|
+
require('../chunk-4NRZFPAP.cjs');
|
|
6
|
+
require('../chunk-YLXWVI2T.cjs');
|
|
192
7
|
|
|
193
8
|
// src/integrations/standard-schema.ts
|
|
194
9
|
function formatPath(path) {
|
|
@@ -203,10 +18,9 @@ function formatIssues(issues) {
|
|
|
203
18
|
function standardSchemaProblemHook(options) {
|
|
204
19
|
return (result, _c) => {
|
|
205
20
|
if (result.success) return;
|
|
206
|
-
return buildValidationResponse(formatIssues(result.error), options);
|
|
21
|
+
return _chunkQC5C2ZNYcjs.buildValidationResponse.call(void 0, formatIssues(result.error), options);
|
|
207
22
|
};
|
|
208
23
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
});
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
exports.standardSchemaProblemHook = standardSchemaProblemHook;
|