hono-ban 0.2.4 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/esm/formatters/index.js +1 -0
  2. package/dist/esm/index.js +1 -311
  3. package/package.json +9 -24
  4. package/dist/cjs/formatters/rfc7807/index.js +0 -364
  5. package/dist/cjs/formatters/rfc7807/index.js.map +0 -16
  6. package/dist/cjs/index.js +0 -271
  7. package/dist/cjs/index.js.map +0 -16
  8. package/dist/esm/formatters/rfc7807/index.js +0 -333
  9. package/dist/esm/formatters/rfc7807/index.js.map +0 -16
  10. package/dist/esm/index.js.map +0 -16
  11. package/src/__tests__/core/convert-error.test.ts +0 -158
  12. package/src/__tests__/core/create-error.test.ts +0 -113
  13. package/src/__tests__/core/format-error.test.ts +0 -162
  14. package/src/__tests__/factories/factories.test.ts +0 -380
  15. package/src/__tests__/formatters/default-formatter.test.ts +0 -117
  16. package/src/__tests__/middleware/README.md +0 -49
  17. package/src/__tests__/middleware/ban-middleware.test.ts.disabled +0 -23
  18. package/src/__tests__/utils/sanitize.test.ts +0 -117
  19. package/src/__tests__/utils/validate.test.ts +0 -35
  20. package/src/constants/index.ts +0 -6
  21. package/src/constants/status-codes.ts +0 -52
  22. package/src/core/convert-error.ts +0 -74
  23. package/src/core/create-error.ts +0 -65
  24. package/src/core/format-error.ts +0 -76
  25. package/src/core/index.ts +0 -8
  26. package/src/factories/client-errors.ts +0 -492
  27. package/src/factories/index.ts +0 -7
  28. package/src/factories/server-errors.ts +0 -230
  29. package/src/formatters/default/index.ts +0 -72
  30. package/src/formatters/index.ts +0 -13
  31. package/src/formatters/interfaces.ts +0 -7
  32. package/src/formatters/rfc7807/formatter.ts +0 -105
  33. package/src/formatters/rfc7807/hooks.ts +0 -73
  34. package/src/formatters/rfc7807/index.ts +0 -20
  35. package/src/formatters/rfc7807/schemas.ts +0 -88
  36. package/src/index.ts +0 -23
  37. package/src/middleware/ban-middleware.ts +0 -77
  38. package/src/middleware/index.ts +0 -6
  39. package/src/types/common.ts +0 -14
  40. package/src/types/error.ts +0 -46
  41. package/src/types/formatter.ts +0 -61
  42. package/src/types/index.ts +0 -11
  43. package/src/types/options.ts +0 -71
  44. package/src/types/rfc7807.ts +0 -93
  45. package/src/utils/index.ts +0 -7
  46. package/src/utils/sanitize.ts +0 -34
  47. package/src/utils/validate.ts +0 -24
@@ -0,0 +1 @@
1
+ var N={400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Payload Too Large",414:"URI Too Long",415:"Unsupported Media Type",416:"Range Not Satisfiable",417:"Expectation Failed",418:"I'm a teapot",421:"Misdirected Request",422:"Unprocessable Entity",423:"Locked",424:"Failed Dependency",425:"Too Early",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",451:"Unavailable For Legal Reasons",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",508:"Loop Detected",510:"Not Extended",511:"Network Authentication Required"};import{z as B}from"@hono/zod-openapi";var J=B.object({name:B.string().openapi({example:"username",description:"The field name that failed validation"}),reason:B.string().openapi({example:"String must contain at least 3 character(s)",description:"The reason for validation failure"})}),Q=B.object({name:B.string().openapi({example:"email",description:"The field name that violated a constraint"}),reason:B.string().openapi({example:"Email already exists",description:"The reason for the constraint violation"}),resource:B.string().openapi({example:"user",description:"The resource type that contains the constraint"}),constraint:B.string().openapi({example:"unique",description:"The type of constraint that was violated"})}),$=B.object({"invalid-params":B.array(J).optional(),violations:B.array(Q).optional()}),K=B.object({type:B.string().url().openapi({example:"https://api.example.com/problems/validation-error",description:"A URI reference that identifies the problem type"}),title:B.string().openapi({example:"Validation Failed",description:"A short, human-readable summary of the problem type"}),status:B.number().int().min(400).max(599).openapi({example:400,description:"The HTTP status code"}),detail:B.string().optional().openapi({example:"The request contains invalid fields",description:"A human-readable explanation specific to this occurrence of the problem"}),instance:B.string().url().optional().openapi({example:"urn:uuid:6b56944d-5e89-4b4d-9ca7-c1be3d1f0e3f",description:"A URI reference that identifies the specific occurrence of the problem"}),timestamp:B.string().datetime().optional().openapi({example:"2025-02-26T12:34:56.789Z",description:"When the error occurred"})}).merge($);function M(x={}){let j=x.baseUrl||"https://api.example.com/problems";return{contentType:"application/problem+json",format(H){let G={type:`${j}/${H.status}`,title:N[H.status]||"Unknown Error",status:H.status,detail:H.message,instance:`urn:uuid:${crypto.randomUUID()}`,timestamp:new Date().toISOString()};if(H.data?.["invalid-params"])return K.parse({...G,"invalid-params":H.data["invalid-params"]});if(H.data?.violations)return K.parse({...G,violations:H.data.violations});return K.parse(G)}}}function V(x){return{"invalid-params":J.array().parse(x)}}function Y(x){return{"invalid-params":J.array().parse(x.errors.map((j)=>({name:j.path.join("."),reason:j.message})))}}function Z(x,j,H,G="unique"){return{violations:Q.array().parse([{name:x,reason:j,resource:H,constraint:G}])}}import{ZodError as q}from"zod";function k(x){if(typeof x!=="number"||isNaN(x))return 500;if(x<400||x>=600)return 500;return x}function X(x){let j=k(x.statusCode??500),H={status:j,message:x.message??N[j],isBan:!0};if(x.data!==void 0)H.data=x.data;if(x.headers)H.headers={...x.headers};if(x.allow)H.allow=Array.isArray(x.allow)?[...x.allow]:[x.allow];if(x.cause){if(H.cause=x.cause,x.cause instanceof Error)H.causeStack=x.cause.stack}return Error.captureStackTrace(H,X),H}function _(x,j,H){if(typeof j==="string")return X({...H,statusCode:x,message:j});return X({...j,...H,statusCode:x})}function I(x,j){return _(400,x,j)}function L(x){return(j,H)=>{if(!j.success&&"error"in j&&j.error instanceof q){let G=Y(j.error);throw I({message:x?.message||"Validation Error",data:G,formatter:x?.formatter,headers:x?.headers,sanitize:x?.sanitize,includeStackTrace:x?.includeStackTrace})}}}var y=L();export{y as rfc7807Hook,Y as createRFC7807ZodValidationError,V as createRFC7807ValidationError,L as createRFC7807Hook,M as createRFC7807Formatter,Z as createRFC7807ConstraintViolation,J as RFC7807ValidationParamSchema,$ as RFC7807ErrorDataSchema,K as RFC7807DetailsSchema,Q as RFC7807ConstraintViolationSchema};
package/dist/esm/index.js CHANGED
@@ -1,311 +1 @@
1
- import {
2
- RFC7807ConstraintViolationSchema,
3
- RFC7807DetailsSchema,
4
- RFC7807ErrorDataSchema,
5
- RFC7807ValidationParamSchema,
6
- STATUS_CODES,
7
- badData,
8
- badRequest,
9
- clientTimeout,
10
- conflict,
11
- createError,
12
- createRFC7807ConstraintViolation,
13
- createRFC7807Formatter,
14
- createRFC7807Hook,
15
- createRFC7807ValidationError,
16
- createRFC7807ZodValidationError,
17
- entityTooLarge,
18
- expectationFailed,
19
- failedDependency,
20
- forbidden,
21
- headerFieldsTooLarge,
22
- illegal,
23
- lengthRequired,
24
- locked,
25
- methodNotAllowed,
26
- misdirectedRequest,
27
- notAcceptable,
28
- notFound,
29
- paymentRequired,
30
- preconditionFailed,
31
- preconditionRequired,
32
- proxyAuthRequired,
33
- rangeNotSatisfiable,
34
- resourceGone,
35
- rfc7807Hook,
36
- teapot,
37
- tooEarly,
38
- tooManyRequests,
39
- unauthorized,
40
- unsupportedMediaType,
41
- upgradeRequired,
42
- uriTooLong
43
- } from "./formatters/rfc7807/index.js";
44
-
45
- // src/core/convert-error.ts
46
- function isBanError(err, statusCode) {
47
- return typeof err === "object" && err !== null && "isBan" in err && err.isBan === true && (!statusCode || err.status === statusCode);
48
- }
49
- function convertToBanError(err, options = {}) {
50
- if (isBanError(err)) {
51
- const merged = {
52
- status: options.statusCode ?? err.status,
53
- message: options.message ?? err.message,
54
- isBan: true,
55
- data: options.data !== undefined ? options.data : err.data,
56
- headers: {
57
- ...err.headers,
58
- ...options.headers
59
- },
60
- allow: options.allow ? Array.isArray(options.allow) ? [...options.allow] : [options.allow] : err.allow,
61
- cause: options.cause ?? err.cause,
62
- stack: err.stack
63
- };
64
- return merged;
65
- }
66
- if (err instanceof Error) {
67
- return createError({
68
- ...options,
69
- message: options.message ?? err.message,
70
- cause: err
71
- });
72
- }
73
- return createError({
74
- ...options,
75
- message: options.message ?? (typeof err === "string" ? err : "Unknown error"),
76
- cause: err
77
- });
78
- }
79
-
80
- // src/core/format-error.ts
81
- function formatError(error, formatter, options = {}) {
82
- return formatter.format(error, options.headers, options.sanitize, options.includeStackTrace);
83
- }
84
- function createErrorResponse(error, formatted) {
85
- const headers = new Headers({
86
- "Content-Type": "application/json",
87
- ...error.headers
88
- });
89
- if (error.allow?.length) {
90
- headers.set("Allow", error.allow.join(", "));
91
- }
92
- const isDeveloperError = error.data && typeof error.data === "object" && "isDeveloperError" in error.data && error.data.isDeveloperError === true;
93
- if (isDeveloperError && false) {
94
- }
95
- return new Response(JSON.stringify(formatted), {
96
- status: error.status,
97
- headers
98
- });
99
- }
100
- // src/utils/sanitize.ts
101
- function sanitizeObject(obj, keysToRemove) {
102
- if (!keysToRemove.length) {
103
- return obj;
104
- }
105
- if (Array.isArray(obj)) {
106
- return obj.map((item) => sanitizeObject(item, keysToRemove));
107
- }
108
- if (obj !== null && typeof obj === "object") {
109
- return Object.entries(obj).reduce((acc, [key, value]) => {
110
- if (keysToRemove.includes(key)) {
111
- return acc;
112
- }
113
- acc[key] = sanitizeObject(value, keysToRemove);
114
- return acc;
115
- }, {});
116
- }
117
- return obj;
118
- }
119
-
120
- // src/formatters/default/index.ts
121
- var defaultFormatter = {
122
- contentType: "application/json",
123
- format(error, headers = {}, sanitize = [], includeStackTrace = false) {
124
- const { status, message, data } = error;
125
- const payload = {
126
- statusCode: status,
127
- error: STATUS_CODES[status] || "Unknown Error"
128
- };
129
- if (typeof message === "string") {
130
- payload.message = message;
131
- }
132
- const isDeveloperError = data && typeof data === "object" && "isDeveloperError" in data && data.isDeveloperError === true;
133
- if (includeStackTrace || isDeveloperError) {
134
- if (error.stack) {
135
- payload.stack = error.stack;
136
- }
137
- if (error.causeStack) {
138
- payload.causeStack = error.causeStack;
139
- }
140
- }
141
- if (data !== undefined) {
142
- payload.data = data;
143
- }
144
- const output = {
145
- statusCode: status,
146
- payload: sanitizeObject(payload, sanitize)
147
- };
148
- return output;
149
- }
150
- };
151
-
152
- // src/factories/server-errors.ts
153
- function createErrorWithStatus(statusCode, messageOrOptions, options) {
154
- if (typeof messageOrOptions === "string") {
155
- return createError({
156
- ...options,
157
- statusCode,
158
- message: messageOrOptions
159
- });
160
- }
161
- return createError({ ...messageOrOptions, ...options, statusCode });
162
- }
163
- function internal(messageOrOptions, options) {
164
- return createErrorWithStatus(500, messageOrOptions, options);
165
- }
166
- function notImplemented(messageOrOptions, options) {
167
- return createErrorWithStatus(501, messageOrOptions, options);
168
- }
169
- function badGateway(messageOrOptions, options) {
170
- return createErrorWithStatus(502, messageOrOptions, options);
171
- }
172
- function serverUnavailable(messageOrOptions, options) {
173
- return createErrorWithStatus(503, messageOrOptions, options);
174
- }
175
- function gatewayTimeout(messageOrOptions, options) {
176
- return createErrorWithStatus(504, messageOrOptions, options);
177
- }
178
- function httpVersionNotSupported(messageOrOptions, options) {
179
- return createErrorWithStatus(505, messageOrOptions, options);
180
- }
181
- function variantAlsoNegotiates(messageOrOptions, options) {
182
- return createErrorWithStatus(506, messageOrOptions, options);
183
- }
184
- function insufficientStorage(messageOrOptions, options) {
185
- return createErrorWithStatus(507, messageOrOptions, options);
186
- }
187
- function loopDetected(messageOrOptions, options) {
188
- return createErrorWithStatus(508, messageOrOptions, options);
189
- }
190
- function notExtended(messageOrOptions, options) {
191
- return createErrorWithStatus(510, messageOrOptions, options);
192
- }
193
- function networkAuthRequired(messageOrOptions, options) {
194
- return createErrorWithStatus(511, messageOrOptions, options);
195
- }
196
- function badImplementation(messageOrOptions, options) {
197
- const mergedOptions = typeof messageOrOptions === "string" ? { ...options, message: messageOrOptions } : { ...messageOrOptions, ...options };
198
- const mergedData = {
199
- isDeveloperError: true,
200
- ...mergedOptions.data || {}
201
- };
202
- return createError({
203
- ...mergedOptions,
204
- statusCode: 500,
205
- data: mergedData
206
- });
207
- }
208
- // src/middleware/ban-middleware.ts
209
- var DEFAULT_OPTIONS = {
210
- formatter: defaultFormatter,
211
- sanitize: [],
212
- includeStackTrace: false,
213
- headers: {}
214
- };
215
- function ban(options = {}) {
216
- const resolvedOptions = {
217
- ...DEFAULT_OPTIONS,
218
- ...options,
219
- formatter: options.formatter ? options.formatter : DEFAULT_OPTIONS.formatter,
220
- headers: {
221
- ...DEFAULT_OPTIONS.headers,
222
- ...options.headers
223
- },
224
- sanitize: [...DEFAULT_OPTIONS.sanitize, ...options.sanitize || []]
225
- };
226
- return async (_, next) => {
227
- try {
228
- await next();
229
- } catch (err) {
230
- const formatter = resolvedOptions.formatter;
231
- const error = convertToBanError(err, {
232
- formatter,
233
- headers: resolvedOptions.headers,
234
- sanitize: resolvedOptions.sanitize,
235
- includeStackTrace: resolvedOptions.includeStackTrace
236
- });
237
- const formatted = formatError(error, formatter, {
238
- headers: resolvedOptions.headers,
239
- sanitize: resolvedOptions.sanitize,
240
- includeStackTrace: resolvedOptions.includeStackTrace
241
- });
242
- return createErrorResponse(error, formatted);
243
- }
244
- };
245
- }
246
- // src/index.ts
247
- var src_default = ban;
248
- export {
249
- variantAlsoNegotiates,
250
- uriTooLong,
251
- upgradeRequired,
252
- unsupportedMediaType,
253
- unauthorized,
254
- tooManyRequests,
255
- tooEarly,
256
- teapot,
257
- serverUnavailable,
258
- rfc7807Hook,
259
- resourceGone,
260
- rangeNotSatisfiable,
261
- proxyAuthRequired,
262
- preconditionRequired,
263
- preconditionFailed,
264
- paymentRequired,
265
- notImplemented,
266
- notFound,
267
- notExtended,
268
- notAcceptable,
269
- networkAuthRequired,
270
- misdirectedRequest,
271
- methodNotAllowed,
272
- loopDetected,
273
- locked,
274
- lengthRequired,
275
- isBanError,
276
- internal,
277
- insufficientStorage,
278
- illegal,
279
- httpVersionNotSupported,
280
- headerFieldsTooLarge,
281
- gatewayTimeout,
282
- formatError,
283
- forbidden,
284
- failedDependency,
285
- expectationFailed,
286
- entityTooLarge,
287
- defaultFormatter,
288
- src_default as default,
289
- createRFC7807ZodValidationError,
290
- createRFC7807ValidationError,
291
- createRFC7807Hook,
292
- createRFC7807Formatter,
293
- createRFC7807ConstraintViolation,
294
- createErrorResponse,
295
- createError,
296
- convertToBanError,
297
- conflict,
298
- clientTimeout,
299
- badRequest,
300
- badImplementation,
301
- badGateway,
302
- badData,
303
- STATUS_CODES,
304
- RFC7807ValidationParamSchema,
305
- RFC7807ErrorDataSchema,
306
- RFC7807DetailsSchema,
307
- RFC7807ConstraintViolationSchema
308
- };
309
-
310
- //# debugId=4A7C3F0FCA1780B264756E2164756E21
311
- //# sourceMappingURL=index.js.map
1
+ var V={400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Payload Too Large",414:"URI Too Long",415:"Unsupported Media Type",416:"Range Not Satisfiable",417:"Expectation Failed",418:"I'm a teapot",421:"Misdirected Request",422:"Unprocessable Entity",423:"Locked",424:"Failed Dependency",425:"Too Early",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",451:"Unavailable For Legal Reasons",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",508:"Loop Detected",510:"Not Extended",511:"Network Authentication Required"};function N(x){if(typeof x!=="number"||isNaN(x))return 500;if(x<400||x>=600)return 500;return x}function J(x){let f=N(x.statusCode??500),K={status:f,message:x.message??V[f],isBan:!0};if(x.data!==void 0)K.data=x.data;if(x.headers)K.headers={...x.headers};if(x.allow)K.allow=Array.isArray(x.allow)?[...x.allow]:[x.allow];if(x.cause){if(K.cause=x.cause,x.cause instanceof Error)K.causeStack=x.cause.stack}return Error.captureStackTrace(K,J),K}function D(x,f){return typeof x==="object"&&x!==null&&"isBan"in x&&x.isBan===!0&&(!f||x.status===f)}function L(x,f={}){if(D(x))return{status:f.statusCode??x.status,message:f.message??x.message,isBan:!0,data:f.data!==void 0?f.data:x.data,headers:{...x.headers,...f.headers},allow:f.allow?Array.isArray(f.allow)?[...f.allow]:[f.allow]:x.allow,cause:f.cause??x.cause,stack:x.stack};if(x instanceof Error)return J({...f,message:f.message??x.message,cause:x});return J({...f,message:f.message??(typeof x==="string"?x:"Unknown error"),cause:x})}function R(x,f,K={}){return f.format(x,K.headers,K.sanitize,K.includeStackTrace)}function _(x,f){let K=new Headers({"Content-Type":"application/json",...x.headers});if(x.allow?.length)K.set("Allow",x.allow.join(", "));let j=x.data&&typeof x.data==="object"&&"isDeveloperError"in x.data&&x.data.isDeveloperError===!0;return new Response(JSON.stringify(f),{status:x.status,headers:K})}function b(x,f){if(!f.length)return x;if(Array.isArray(x))return x.map((K)=>b(K,f));if(x!==null&&typeof x==="object")return Object.entries(x).reduce((K,[j,Y])=>{if(f.includes(j))return K;return K[j]=b(Y,f),K},{});return x}var I={contentType:"application/json",format(x,f={},K=[],j=!1){let{status:Y,message:Z,data:X}=x,$={statusCode:Y,error:V[Y]||"Unknown Error"};if(typeof Z==="string")$.message=Z;let U=X&&typeof X==="object"&&"isDeveloperError"in X&&X.isDeveloperError===!0;if(j||U){if(x.stack)$.stack=x.stack;if(x.causeStack)$.causeStack=x.causeStack}if(X!==void 0)$.data=X;return{statusCode:Y,payload:b($,K)}}};import{z as G}from"@hono/zod-openapi";var q=G.object({name:G.string().openapi({example:"username",description:"The field name that failed validation"}),reason:G.string().openapi({example:"String must contain at least 3 character(s)",description:"The reason for validation failure"})}),w=G.object({name:G.string().openapi({example:"email",description:"The field name that violated a constraint"}),reason:G.string().openapi({example:"Email already exists",description:"The reason for the constraint violation"}),resource:G.string().openapi({example:"user",description:"The resource type that contains the constraint"}),constraint:G.string().openapi({example:"unique",description:"The type of constraint that was violated"})}),A=G.object({"invalid-params":G.array(q).optional(),violations:G.array(w).optional()}),H=G.object({type:G.string().url().openapi({example:"https://api.example.com/problems/validation-error",description:"A URI reference that identifies the problem type"}),title:G.string().openapi({example:"Validation Failed",description:"A short, human-readable summary of the problem type"}),status:G.number().int().min(400).max(599).openapi({example:400,description:"The HTTP status code"}),detail:G.string().optional().openapi({example:"The request contains invalid fields",description:"A human-readable explanation specific to this occurrence of the problem"}),instance:G.string().url().optional().openapi({example:"urn:uuid:6b56944d-5e89-4b4d-9ca7-c1be3d1f0e3f",description:"A URI reference that identifies the specific occurrence of the problem"}),timestamp:G.string().datetime().optional().openapi({example:"2025-02-26T12:34:56.789Z",description:"When the error occurred"})}).merge(A);function z(x={}){let f=x.baseUrl||"https://api.example.com/problems";return{contentType:"application/problem+json",format(K){let j={type:`${f}/${K.status}`,title:V[K.status]||"Unknown Error",status:K.status,detail:K.message,instance:`urn:uuid:${crypto.randomUUID()}`,timestamp:new Date().toISOString()};if(K.data?.["invalid-params"])return H.parse({...j,"invalid-params":K.data["invalid-params"]});if(K.data?.violations)return H.parse({...j,violations:K.data.violations});return H.parse(j)}}}function v(x){return{"invalid-params":q.array().parse(x)}}function y(x){return{"invalid-params":q.array().parse(x.errors.map((f)=>({name:f.path.join("."),reason:f.message})))}}function T(x,f,K,j="unique"){return{violations:w.array().parse([{name:x,reason:f,resource:K,constraint:j}])}}import{ZodError as C}from"zod";function M(x,f,K){if(typeof f==="string")return J({...K,statusCode:x,message:f});return J({...f,...K,statusCode:x})}function F(x,f){return M(400,x,f)}function x7(x,f){return M(401,x,f)}function f7(x,f){return M(402,x,f)}function K7(x,f){return M(403,x,f)}function M7(x,f){return M(404,x,f)}function j7(x,f){return M(405,x,f)}function G7(x,f){return M(406,x,f)}function J7(x,f){return M(407,x,f)}function Q7(x,f){return M(408,x,f)}function X7(x,f){return M(409,x,f)}function Y7(x,f){return M(410,x,f)}function $7(x,f){return M(411,x,f)}function V7(x,f){return M(412,x,f)}function Z7(x,f){return M(413,x,f)}function q7(x,f){return M(414,x,f)}function H7(x,f){return M(415,x,f)}function b7(x,f){return M(416,x,f)}function w7(x,f){return M(417,x,f)}function k7(x,f){return M(418,x,f)}function y7(x,f){return M(421,x,f)}function B7(x,f){return M(422,x,f)}function N7(x,f){return M(423,x,f)}function L7(x,f){return M(424,x,f)}function R7(x,f){return M(425,x,f)}function _7(x,f){return M(426,x,f)}function I7(x,f){return M(428,x,f)}function A7(x,f){return M(429,x,f)}function F7(x,f){return M(431,x,f)}function P7(x,f){return M(451,x,f)}function Q(x,f,K){if(typeof f==="string")return J({...K,statusCode:x,message:f});return J({...f,...K,statusCode:x})}function z7(x,f){return Q(500,x,f)}function v7(x,f){return Q(501,x,f)}function T7(x,f){return Q(502,x,f)}function C7(x,f){return Q(503,x,f)}function l7(x,f){return Q(504,x,f)}function W7(x,f){return Q(505,x,f)}function h7(x,f){return Q(506,x,f)}function S7(x,f){return Q(507,x,f)}function E7(x,f){return Q(508,x,f)}function u7(x,f){return Q(510,x,f)}function d7(x,f){return Q(511,x,f)}function c7(x,f){let K=typeof x==="string"?{...f,message:x}:{...x,...f},j={isDeveloperError:!0,...K.data||{}};return J({...K,statusCode:500,data:j})}function P(x){return(f,K)=>{if(!f.success&&"error"in f&&f.error instanceof C){let j=y(f.error);throw F({message:x?.message||"Validation Error",data:j,formatter:x?.formatter,headers:x?.headers,sanitize:x?.sanitize,includeStackTrace:x?.includeStackTrace})}}}var l=P();var k={formatter:I,sanitize:[],includeStackTrace:!1,headers:{}};function B(x={}){let f={...k,...x,formatter:x.formatter?x.formatter:k.formatter,headers:{...k.headers,...x.headers},sanitize:[...k.sanitize,...x.sanitize||[]]};return async(K,j)=>{try{await j()}catch(Y){let Z=f.formatter,X=L(Y,{formatter:Z,headers:f.headers,sanitize:f.sanitize,includeStackTrace:f.includeStackTrace}),$=R(X,Z,{headers:f.headers,sanitize:f.sanitize,includeStackTrace:f.includeStackTrace});return _(X,$)}}}var Yx=B;export{h7 as variantAlsoNegotiates,q7 as uriTooLong,_7 as upgradeRequired,H7 as unsupportedMediaType,x7 as unauthorized,A7 as tooManyRequests,R7 as tooEarly,k7 as teapot,C7 as serverUnavailable,l as rfc7807Hook,Y7 as resourceGone,b7 as rangeNotSatisfiable,J7 as proxyAuthRequired,I7 as preconditionRequired,V7 as preconditionFailed,f7 as paymentRequired,v7 as notImplemented,M7 as notFound,u7 as notExtended,G7 as notAcceptable,d7 as networkAuthRequired,y7 as misdirectedRequest,j7 as methodNotAllowed,E7 as loopDetected,N7 as locked,$7 as lengthRequired,D as isBanError,z7 as internal,S7 as insufficientStorage,P7 as illegal,W7 as httpVersionNotSupported,F7 as headerFieldsTooLarge,l7 as gatewayTimeout,R as formatError,K7 as forbidden,L7 as failedDependency,w7 as expectationFailed,Z7 as entityTooLarge,I as defaultFormatter,Yx as default,y as createRFC7807ZodValidationError,v as createRFC7807ValidationError,P as createRFC7807Hook,z as createRFC7807Formatter,T as createRFC7807ConstraintViolation,_ as createErrorResponse,J as createError,L as convertToBanError,X7 as conflict,Q7 as clientTimeout,F as badRequest,c7 as badImplementation,T7 as badGateway,B7 as badData,V as STATUS_CODES,q as RFC7807ValidationParamSchema,A as RFC7807ErrorDataSchema,H as RFC7807DetailsSchema,w as RFC7807ConstraintViolationSchema};
package/package.json CHANGED
@@ -1,47 +1,32 @@
1
1
  {
2
2
  "name": "hono-ban",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "HTTP-friendly error objects for Hono, inspired by Boom",
5
5
  "type": "module",
6
- "main": "dist/cjs/index.js",
7
- "module": "dist/esm/index.js",
6
+ "main": "dist/esm/index.js",
8
7
  "types": "dist/types/index.d.ts",
9
8
  "files": [
10
9
  "dist/*",
11
- "src",
12
10
  "LICENSE.md",
13
11
  "README.md"
14
12
  ],
15
13
  "exports": {
16
14
  ".": {
17
- "import": {
18
- "types": "./dist/types/index.d.ts",
19
- "default": "./dist/esm/index.js"
20
- },
21
- "require": {
22
- "types": "./dist/types/index.d.ts",
23
- "default": "./dist/cjs/index.js"
24
- }
15
+ "types": "./dist/types/index.d.ts",
16
+ "default": "./dist/esm/index.js"
25
17
  },
26
18
  "./formatters/rfc7807": {
27
- "import": {
28
- "types": "./dist/types/formatters/rfc7807/index.d.ts",
29
- "default": "./dist/esm/formatters/rfc7807/index.js"
30
- },
31
- "require": {
32
- "types": "./dist/types/formatters/rfc7807/index.d.ts",
33
- "default": "./dist/cjs/formatters/rfc7807/index.js"
34
- }
19
+ "types": "./dist/types/formatters/rfc7807/index.d.ts",
20
+ "default": "./dist/esm/formatters/rfc7807/index.js"
35
21
  }
36
22
  },
37
23
  "sideEffects": false,
38
24
  "scripts": {
39
- "build": "bun run build:esm && bun run build:cjs && bun run build:declaration",
40
- "build:esm": "bun build --target=node --format=esm --packages=external --outdir=dist/esm --sourcemap=linked --splitting ./src/index.ts ./src/formatters/rfc7807/index.ts",
41
- "build:cjs": "bun build --target=node --format=cjs --packages=external --outdir=dist/cjs --sourcemap=linked --splitting ./src/index.ts ./src/formatters/rfc7807/index.ts",
25
+ "build": "bun run build:esm && bun run build:declaration",
26
+ "build:esm": "bun build --target=node --format=esm --packages=external --outdir=dist/esm --minify ./src/index.ts && bun build --target=node --format=esm --packages=external --outdir=dist/esm/formatters --minify ./src/formatters/rfc7807/index.ts",
42
27
  "build:declaration": "tsc --emitDeclarationOnly --project tsconfig.types.json",
43
28
  "postbuild": "rimraf tsconfig.types.tsbuildinfo",
44
- "dev": "bun build --target=node --packages=external --outdir=dist --watch ./src/index.ts ./src/formatters/rfc7807/index.ts",
29
+ "dev": "bun build --target=node --format=esm --packages=external --outdir=dist/esm --watch ./src/index.ts",
45
30
  "test": "bun test",
46
31
  "test:watch": "bun test --watch",
47
32
  "test:coverage": "bun test --coverage",