better-call 1.1.5 → 1.1.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.
- package/dist/client.cjs +7 -0
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +3 -2
- package/dist/client.d.ts +3 -2
- package/dist/client.js +2 -1
- package/dist/client.js.map +1 -1
- package/dist/error.cjs +8 -0
- package/dist/error.d.cts +2 -0
- package/dist/error.d.ts +2 -0
- package/dist/error.js +3 -0
- package/dist/error2.cjs +171 -0
- package/dist/error2.cjs.map +1 -0
- package/dist/error2.d.cts +157 -0
- package/dist/error2.d.ts +157 -0
- package/dist/error2.js +135 -0
- package/dist/error2.js.map +1 -0
- package/dist/index.cjs +17 -149
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -133
- package/dist/index.js.map +1 -1
- package/dist/router.d.cts +3 -156
- package/dist/router.d.ts +3 -156
- package/package.json +11 -1
package/dist/error2.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
//#region src/error.ts
|
|
2
|
+
function isErrorStackTraceLimitWritable() {
|
|
3
|
+
const desc = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit");
|
|
4
|
+
if (desc === void 0) return Object.isExtensible(Error);
|
|
5
|
+
return Object.prototype.hasOwnProperty.call(desc, "writable") ? desc.writable : desc.set !== void 0;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Hide internal stack frames from the error stack trace.
|
|
9
|
+
*/
|
|
10
|
+
function hideInternalStackFrames(stack) {
|
|
11
|
+
const lines = stack.split("\n at ");
|
|
12
|
+
if (lines.length <= 1) return stack;
|
|
13
|
+
lines.splice(1, 1);
|
|
14
|
+
return lines.join("\n at ");
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Creates a custom error class that hides stack frames.
|
|
18
|
+
*/
|
|
19
|
+
function makeErrorForHideStackFrame(Base, clazz) {
|
|
20
|
+
class HideStackFramesError extends Base {
|
|
21
|
+
#hiddenStack;
|
|
22
|
+
constructor(...args) {
|
|
23
|
+
if (isErrorStackTraceLimitWritable()) {
|
|
24
|
+
const limit = Error.stackTraceLimit;
|
|
25
|
+
Error.stackTraceLimit = 0;
|
|
26
|
+
super(...args);
|
|
27
|
+
Error.stackTraceLimit = limit;
|
|
28
|
+
} else super(...args);
|
|
29
|
+
const stack = (/* @__PURE__ */ new Error()).stack;
|
|
30
|
+
if (stack) this.#hiddenStack = hideInternalStackFrames(stack.replace(/^Error/, this.name));
|
|
31
|
+
}
|
|
32
|
+
get errorStack() {
|
|
33
|
+
return this.#hiddenStack;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
Object.defineProperty(HideStackFramesError.prototype, "constructor", {
|
|
37
|
+
get() {
|
|
38
|
+
return clazz;
|
|
39
|
+
},
|
|
40
|
+
enumerable: false,
|
|
41
|
+
configurable: true
|
|
42
|
+
});
|
|
43
|
+
return HideStackFramesError;
|
|
44
|
+
}
|
|
45
|
+
const statusCodes = {
|
|
46
|
+
OK: 200,
|
|
47
|
+
CREATED: 201,
|
|
48
|
+
ACCEPTED: 202,
|
|
49
|
+
NO_CONTENT: 204,
|
|
50
|
+
MULTIPLE_CHOICES: 300,
|
|
51
|
+
MOVED_PERMANENTLY: 301,
|
|
52
|
+
FOUND: 302,
|
|
53
|
+
SEE_OTHER: 303,
|
|
54
|
+
NOT_MODIFIED: 304,
|
|
55
|
+
TEMPORARY_REDIRECT: 307,
|
|
56
|
+
BAD_REQUEST: 400,
|
|
57
|
+
UNAUTHORIZED: 401,
|
|
58
|
+
PAYMENT_REQUIRED: 402,
|
|
59
|
+
FORBIDDEN: 403,
|
|
60
|
+
NOT_FOUND: 404,
|
|
61
|
+
METHOD_NOT_ALLOWED: 405,
|
|
62
|
+
NOT_ACCEPTABLE: 406,
|
|
63
|
+
PROXY_AUTHENTICATION_REQUIRED: 407,
|
|
64
|
+
REQUEST_TIMEOUT: 408,
|
|
65
|
+
CONFLICT: 409,
|
|
66
|
+
GONE: 410,
|
|
67
|
+
LENGTH_REQUIRED: 411,
|
|
68
|
+
PRECONDITION_FAILED: 412,
|
|
69
|
+
PAYLOAD_TOO_LARGE: 413,
|
|
70
|
+
URI_TOO_LONG: 414,
|
|
71
|
+
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
72
|
+
RANGE_NOT_SATISFIABLE: 416,
|
|
73
|
+
EXPECTATION_FAILED: 417,
|
|
74
|
+
"I'M_A_TEAPOT": 418,
|
|
75
|
+
MISDIRECTED_REQUEST: 421,
|
|
76
|
+
UNPROCESSABLE_ENTITY: 422,
|
|
77
|
+
LOCKED: 423,
|
|
78
|
+
FAILED_DEPENDENCY: 424,
|
|
79
|
+
TOO_EARLY: 425,
|
|
80
|
+
UPGRADE_REQUIRED: 426,
|
|
81
|
+
PRECONDITION_REQUIRED: 428,
|
|
82
|
+
TOO_MANY_REQUESTS: 429,
|
|
83
|
+
REQUEST_HEADER_FIELDS_TOO_LARGE: 431,
|
|
84
|
+
UNAVAILABLE_FOR_LEGAL_REASONS: 451,
|
|
85
|
+
INTERNAL_SERVER_ERROR: 500,
|
|
86
|
+
NOT_IMPLEMENTED: 501,
|
|
87
|
+
BAD_GATEWAY: 502,
|
|
88
|
+
SERVICE_UNAVAILABLE: 503,
|
|
89
|
+
GATEWAY_TIMEOUT: 504,
|
|
90
|
+
HTTP_VERSION_NOT_SUPPORTED: 505,
|
|
91
|
+
VARIANT_ALSO_NEGOTIATES: 506,
|
|
92
|
+
INSUFFICIENT_STORAGE: 507,
|
|
93
|
+
LOOP_DETECTED: 508,
|
|
94
|
+
NOT_EXTENDED: 510,
|
|
95
|
+
NETWORK_AUTHENTICATION_REQUIRED: 511
|
|
96
|
+
};
|
|
97
|
+
var InternalAPIError = class extends Error {
|
|
98
|
+
constructor(status = "INTERNAL_SERVER_ERROR", body = void 0, headers = {}, statusCode = typeof status === "number" ? status : statusCodes[status]) {
|
|
99
|
+
super(body?.message, body?.cause ? { cause: body.cause } : void 0);
|
|
100
|
+
this.status = status;
|
|
101
|
+
this.body = body;
|
|
102
|
+
this.headers = headers;
|
|
103
|
+
this.statusCode = statusCode;
|
|
104
|
+
this.name = "APIError";
|
|
105
|
+
this.status = status;
|
|
106
|
+
this.headers = headers;
|
|
107
|
+
this.statusCode = statusCode;
|
|
108
|
+
this.body = body ? {
|
|
109
|
+
code: body?.message?.toUpperCase().replace(/ /g, "_").replace(/[^A-Z0-9_]/g, ""),
|
|
110
|
+
...body
|
|
111
|
+
} : void 0;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
var ValidationError = class extends InternalAPIError {
|
|
115
|
+
constructor(message, issues) {
|
|
116
|
+
super(400, {
|
|
117
|
+
message,
|
|
118
|
+
code: "VALIDATION_ERROR"
|
|
119
|
+
});
|
|
120
|
+
this.message = message;
|
|
121
|
+
this.issues = issues;
|
|
122
|
+
this.issues = issues;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var BetterCallError = class extends Error {
|
|
126
|
+
constructor(message) {
|
|
127
|
+
super(message);
|
|
128
|
+
this.name = "BetterCallError";
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
const APIError = makeErrorForHideStackFrame(InternalAPIError, Error);
|
|
132
|
+
|
|
133
|
+
//#endregion
|
|
134
|
+
export { makeErrorForHideStackFrame as a, hideInternalStackFrames as i, BetterCallError as n, statusCodes as o, ValidationError as r, APIError as t };
|
|
135
|
+
//# sourceMappingURL=error2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error2.js","names":["#hiddenStack","status: keyof typeof statusCodes | Status","body:\n\t\t\t| ({\n\t\t\t\t\tmessage?: string;\n\t\t\t\t\tcode?: string;\n\t\t\t\t\tcause?: unknown;\n\t\t\t } & Record<string, any>)\n\t\t\t| undefined","headers: HeadersInit","message: string","issues: readonly StandardSchemaV1.Issue[]"],"sources":["../src/error.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"./standard-schema\";\n// https://github.com/nodejs/node/blob/360f7cc7867b43344aac00564286b895e15f21d7/lib/internal/errors.js#L246C1-L261C2\nfunction isErrorStackTraceLimitWritable() {\n\tconst desc = Object.getOwnPropertyDescriptor(Error, \"stackTraceLimit\");\n\tif (desc === undefined) {\n\t\treturn Object.isExtensible(Error);\n\t}\n\n\treturn Object.prototype.hasOwnProperty.call(desc, \"writable\")\n\t\t? desc.writable\n\t\t: desc.set !== undefined;\n}\n\n/**\n * Hide internal stack frames from the error stack trace.\n */\nexport function hideInternalStackFrames(stack: string): string {\n\tconst lines = stack.split(\"\\n at \");\n\tif (lines.length <= 1) {\n\t\treturn stack;\n\t}\n\tlines.splice(1, 1);\n\treturn lines.join(\"\\n at \");\n}\n\n// https://github.com/nodejs/node/blob/360f7cc7867b43344aac00564286b895e15f21d7/lib/internal/errors.js#L411-L432\n/**\n * Creates a custom error class that hides stack frames.\n */\nexport function makeErrorForHideStackFrame<B extends new (...args: any[]) => Error>(\n\tBase: B,\n\tclazz: any,\n): {\n\tnew (...args: ConstructorParameters<B>): InstanceType<B> & { errorStack: string | undefined };\n} {\n\tclass HideStackFramesError extends Base {\n\t\t#hiddenStack: string | undefined;\n\n\t\tconstructor(...args: any[]) {\n\t\t\tif (isErrorStackTraceLimitWritable()) {\n\t\t\t\tconst limit = Error.stackTraceLimit;\n\t\t\t\tError.stackTraceLimit = 0;\n\t\t\t\tsuper(...args);\n\t\t\t\tError.stackTraceLimit = limit;\n\t\t\t} else {\n\t\t\t\tsuper(...args);\n\t\t\t}\n\t\t\tconst stack = new Error().stack;\n\t\t\tif (stack) {\n\t\t\t\tthis.#hiddenStack = hideInternalStackFrames(stack.replace(/^Error/, this.name));\n\t\t\t}\n\t\t}\n\n\t\t// use `getter` here to avoid the stack trace being captured by loggers\n\t\tget errorStack() {\n\t\t\treturn this.#hiddenStack;\n\t\t}\n\t}\n\n\t// This is a workaround for wpt tests that expect that the error\n\t// constructor has a `name` property of the base class.\n\tObject.defineProperty(HideStackFramesError.prototype, \"constructor\", {\n\t\tget() {\n\t\t\treturn clazz;\n\t\t},\n\t\tenumerable: false,\n\t\tconfigurable: true,\n\t});\n\n\treturn HideStackFramesError as any;\n}\n\nexport const statusCodes = {\n\tOK: 200,\n\tCREATED: 201,\n\tACCEPTED: 202,\n\tNO_CONTENT: 204,\n\tMULTIPLE_CHOICES: 300,\n\tMOVED_PERMANENTLY: 301,\n\tFOUND: 302,\n\tSEE_OTHER: 303,\n\tNOT_MODIFIED: 304,\n\tTEMPORARY_REDIRECT: 307,\n\tBAD_REQUEST: 400,\n\tUNAUTHORIZED: 401,\n\tPAYMENT_REQUIRED: 402,\n\tFORBIDDEN: 403,\n\tNOT_FOUND: 404,\n\tMETHOD_NOT_ALLOWED: 405,\n\tNOT_ACCEPTABLE: 406,\n\tPROXY_AUTHENTICATION_REQUIRED: 407,\n\tREQUEST_TIMEOUT: 408,\n\tCONFLICT: 409,\n\tGONE: 410,\n\tLENGTH_REQUIRED: 411,\n\tPRECONDITION_FAILED: 412,\n\tPAYLOAD_TOO_LARGE: 413,\n\tURI_TOO_LONG: 414,\n\tUNSUPPORTED_MEDIA_TYPE: 415,\n\tRANGE_NOT_SATISFIABLE: 416,\n\tEXPECTATION_FAILED: 417,\n\t\"I'M_A_TEAPOT\": 418,\n\tMISDIRECTED_REQUEST: 421,\n\tUNPROCESSABLE_ENTITY: 422,\n\tLOCKED: 423,\n\tFAILED_DEPENDENCY: 424,\n\tTOO_EARLY: 425,\n\tUPGRADE_REQUIRED: 426,\n\tPRECONDITION_REQUIRED: 428,\n\tTOO_MANY_REQUESTS: 429,\n\tREQUEST_HEADER_FIELDS_TOO_LARGE: 431,\n\tUNAVAILABLE_FOR_LEGAL_REASONS: 451,\n\tINTERNAL_SERVER_ERROR: 500,\n\tNOT_IMPLEMENTED: 501,\n\tBAD_GATEWAY: 502,\n\tSERVICE_UNAVAILABLE: 503,\n\tGATEWAY_TIMEOUT: 504,\n\tHTTP_VERSION_NOT_SUPPORTED: 505,\n\tVARIANT_ALSO_NEGOTIATES: 506,\n\tINSUFFICIENT_STORAGE: 507,\n\tLOOP_DETECTED: 508,\n\tNOT_EXTENDED: 510,\n\tNETWORK_AUTHENTICATION_REQUIRED: 511,\n};\n\nexport type Status =\n\t| 100\n\t| 101\n\t| 102\n\t| 103\n\t| 200\n\t| 201\n\t| 202\n\t| 203\n\t| 204\n\t| 205\n\t| 206\n\t| 207\n\t| 208\n\t| 226\n\t| 300\n\t| 301\n\t| 302\n\t| 303\n\t| 304\n\t| 305\n\t| 306\n\t| 307\n\t| 308\n\t| 400\n\t| 401\n\t| 402\n\t| 403\n\t| 404\n\t| 405\n\t| 406\n\t| 407\n\t| 408\n\t| 409\n\t| 410\n\t| 411\n\t| 412\n\t| 413\n\t| 414\n\t| 415\n\t| 416\n\t| 417\n\t| 418\n\t| 421\n\t| 422\n\t| 423\n\t| 424\n\t| 425\n\t| 426\n\t| 428\n\t| 429\n\t| 431\n\t| 451\n\t| 500\n\t| 501\n\t| 502\n\t| 503\n\t| 504\n\t| 505\n\t| 506\n\t| 507\n\t| 508\n\t| 510\n\t| 511;\n\nclass InternalAPIError extends Error {\n\tconstructor(\n\t\tpublic status: keyof typeof statusCodes | Status = \"INTERNAL_SERVER_ERROR\",\n\t\tpublic body:\n\t\t\t| ({\n\t\t\t\t\tmessage?: string;\n\t\t\t\t\tcode?: string;\n\t\t\t\t\tcause?: unknown;\n\t\t\t } & Record<string, any>)\n\t\t\t| undefined = undefined,\n\t\tpublic headers: HeadersInit = {},\n\t\tpublic statusCode = typeof status === \"number\" ? status : statusCodes[status],\n\t) {\n\t\tsuper(\n\t\t\tbody?.message,\n\t\t\tbody?.cause\n\t\t\t\t? {\n\t\t\t\t\t\tcause: body.cause,\n\t\t\t\t\t}\n\t\t\t\t: undefined,\n\t\t);\n\t\tthis.name = \"APIError\";\n\t\tthis.status = status;\n\t\tthis.headers = headers;\n\t\tthis.statusCode = statusCode;\n\t\tthis.body = body\n\t\t\t? {\n\t\t\t\t\tcode: body?.message\n\t\t\t\t\t\t?.toUpperCase()\n\t\t\t\t\t\t.replace(/ /g, \"_\")\n\t\t\t\t\t\t.replace(/[^A-Z0-9_]/g, \"\"),\n\t\t\t\t\t...body,\n\t\t\t\t}\n\t\t\t: undefined;\n\t}\n}\n\nexport class ValidationError extends InternalAPIError {\n\tconstructor(\n\t\tpublic message: string,\n\t\tpublic issues: readonly StandardSchemaV1.Issue[],\n\t) {\n\t\tsuper(400, {\n\t\t\tmessage: message,\n\t\t\tcode: \"VALIDATION_ERROR\",\n\t\t});\n\n\t\tthis.issues = issues;\n\t}\n}\n\nexport class BetterCallError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"BetterCallError\";\n\t}\n}\n\nexport type APIError = InstanceType<typeof InternalAPIError>;\nexport const APIError = makeErrorForHideStackFrame(InternalAPIError, Error);\n"],"mappings":";AAEA,SAAS,iCAAiC;CACzC,MAAM,OAAO,OAAO,yBAAyB,OAAO,kBAAkB;AACtE,KAAI,SAAS,OACZ,QAAO,OAAO,aAAa,MAAM;AAGlC,QAAO,OAAO,UAAU,eAAe,KAAK,MAAM,WAAW,GAC1D,KAAK,WACL,KAAK,QAAQ;;;;;AAMjB,SAAgB,wBAAwB,OAAuB;CAC9D,MAAM,QAAQ,MAAM,MAAM,YAAY;AACtC,KAAI,MAAM,UAAU,EACnB,QAAO;AAER,OAAM,OAAO,GAAG,EAAE;AAClB,QAAO,MAAM,KAAK,YAAY;;;;;AAO/B,SAAgB,2BACf,MACA,OAGC;CACD,MAAM,6BAA6B,KAAK;EACvC;EAEA,YAAY,GAAG,MAAa;AAC3B,OAAI,gCAAgC,EAAE;IACrC,MAAM,QAAQ,MAAM;AACpB,UAAM,kBAAkB;AACxB,UAAM,GAAG,KAAK;AACd,UAAM,kBAAkB;SAExB,OAAM,GAAG,KAAK;GAEf,MAAM,yBAAQ,IAAI,OAAO,EAAC;AAC1B,OAAI,MACH,OAAKA,cAAe,wBAAwB,MAAM,QAAQ,UAAU,KAAK,KAAK,CAAC;;EAKjF,IAAI,aAAa;AAChB,UAAO,MAAKA;;;AAMd,QAAO,eAAe,qBAAqB,WAAW,eAAe;EACpE,MAAM;AACL,UAAO;;EAER,YAAY;EACZ,cAAc;EACd,CAAC;AAEF,QAAO;;AAGR,MAAa,cAAc;CAC1B,IAAI;CACJ,SAAS;CACT,UAAU;CACV,YAAY;CACZ,kBAAkB;CAClB,mBAAmB;CACnB,OAAO;CACP,WAAW;CACX,cAAc;CACd,oBAAoB;CACpB,aAAa;CACb,cAAc;CACd,kBAAkB;CAClB,WAAW;CACX,WAAW;CACX,oBAAoB;CACpB,gBAAgB;CAChB,+BAA+B;CAC/B,iBAAiB;CACjB,UAAU;CACV,MAAM;CACN,iBAAiB;CACjB,qBAAqB;CACrB,mBAAmB;CACnB,cAAc;CACd,wBAAwB;CACxB,uBAAuB;CACvB,oBAAoB;CACpB,gBAAgB;CAChB,qBAAqB;CACrB,sBAAsB;CACtB,QAAQ;CACR,mBAAmB;CACnB,WAAW;CACX,kBAAkB;CAClB,uBAAuB;CACvB,mBAAmB;CACnB,iCAAiC;CACjC,+BAA+B;CAC/B,uBAAuB;CACvB,iBAAiB;CACjB,aAAa;CACb,qBAAqB;CACrB,iBAAiB;CACjB,4BAA4B;CAC5B,yBAAyB;CACzB,sBAAsB;CACtB,eAAe;CACf,cAAc;CACd,iCAAiC;CACjC;AAmED,IAAM,mBAAN,cAA+B,MAAM;CACpC,YACC,AAAOC,SAA4C,yBACnD,AAAOC,OAMQ,QACf,AAAOC,UAAuB,EAAE,EAChC,AAAO,aAAa,OAAO,WAAW,WAAW,SAAS,YAAY,SACrE;AACD,QACC,MAAM,SACN,MAAM,QACH,EACA,OAAO,KAAK,OACZ,GACA,OACH;EAlBM;EACA;EAOA;EACA;AAUP,OAAK,OAAO;AACZ,OAAK,SAAS;AACd,OAAK,UAAU;AACf,OAAK,aAAa;AAClB,OAAK,OAAO,OACT;GACA,MAAM,MAAM,SACT,aAAa,CACd,QAAQ,MAAM,IAAI,CAClB,QAAQ,eAAe,GAAG;GAC5B,GAAG;GACH,GACA;;;AAIL,IAAa,kBAAb,cAAqC,iBAAiB;CACrD,YACC,AAAOC,SACP,AAAOC,QACN;AACD,QAAM,KAAK;GACD;GACT,MAAM;GACN,CAAC;EANK;EACA;AAOP,OAAK,SAAS;;;AAIhB,IAAa,kBAAb,cAAqC,MAAM;CAC1C,YAAY,SAAiB;AAC5B,QAAM,QAAQ;AACd,OAAK,OAAO;;;AAKd,MAAa,WAAW,2BAA2B,kBAAkB,MAAM"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,141 +1,9 @@
|
|
|
1
|
+
const require_error = require('./error2.cjs');
|
|
1
2
|
const require_node = require('./node.cjs');
|
|
2
3
|
let __better_auth_utils = require("@better-auth/utils");
|
|
3
4
|
let rou3 = require("rou3");
|
|
4
5
|
let zod = require("zod");
|
|
5
6
|
|
|
6
|
-
//#region src/error.ts
|
|
7
|
-
function isErrorStackTraceLimitWritable() {
|
|
8
|
-
const desc = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit");
|
|
9
|
-
if (desc === void 0) return Object.isExtensible(Error);
|
|
10
|
-
return Object.prototype.hasOwnProperty.call(desc, "writable") ? desc.writable : desc.set !== void 0;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Hide internal stack frames from the error stack trace.
|
|
14
|
-
*/
|
|
15
|
-
function hideInternalStackFrames(stack) {
|
|
16
|
-
const lines = stack.split("\n at ");
|
|
17
|
-
if (lines.length <= 1) return stack;
|
|
18
|
-
lines.splice(1, 1);
|
|
19
|
-
return lines.join("\n at ");
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Creates a custom error class that hides stack frames.
|
|
23
|
-
*/
|
|
24
|
-
function makeErrorForHideStackFrame(Base, clazz) {
|
|
25
|
-
class HideStackFramesError extends Base {
|
|
26
|
-
#hiddenStack;
|
|
27
|
-
constructor(...args) {
|
|
28
|
-
if (isErrorStackTraceLimitWritable()) {
|
|
29
|
-
const limit = Error.stackTraceLimit;
|
|
30
|
-
Error.stackTraceLimit = 0;
|
|
31
|
-
super(...args);
|
|
32
|
-
Error.stackTraceLimit = limit;
|
|
33
|
-
} else super(...args);
|
|
34
|
-
const stack = (/* @__PURE__ */ new Error()).stack;
|
|
35
|
-
if (stack) this.#hiddenStack = hideInternalStackFrames(stack.replace(/^Error/, this.name));
|
|
36
|
-
}
|
|
37
|
-
get errorStack() {
|
|
38
|
-
return this.#hiddenStack;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
Object.defineProperty(HideStackFramesError.prototype, "constructor", {
|
|
42
|
-
get() {
|
|
43
|
-
return clazz;
|
|
44
|
-
},
|
|
45
|
-
enumerable: false,
|
|
46
|
-
configurable: true
|
|
47
|
-
});
|
|
48
|
-
return HideStackFramesError;
|
|
49
|
-
}
|
|
50
|
-
const statusCodes = {
|
|
51
|
-
OK: 200,
|
|
52
|
-
CREATED: 201,
|
|
53
|
-
ACCEPTED: 202,
|
|
54
|
-
NO_CONTENT: 204,
|
|
55
|
-
MULTIPLE_CHOICES: 300,
|
|
56
|
-
MOVED_PERMANENTLY: 301,
|
|
57
|
-
FOUND: 302,
|
|
58
|
-
SEE_OTHER: 303,
|
|
59
|
-
NOT_MODIFIED: 304,
|
|
60
|
-
TEMPORARY_REDIRECT: 307,
|
|
61
|
-
BAD_REQUEST: 400,
|
|
62
|
-
UNAUTHORIZED: 401,
|
|
63
|
-
PAYMENT_REQUIRED: 402,
|
|
64
|
-
FORBIDDEN: 403,
|
|
65
|
-
NOT_FOUND: 404,
|
|
66
|
-
METHOD_NOT_ALLOWED: 405,
|
|
67
|
-
NOT_ACCEPTABLE: 406,
|
|
68
|
-
PROXY_AUTHENTICATION_REQUIRED: 407,
|
|
69
|
-
REQUEST_TIMEOUT: 408,
|
|
70
|
-
CONFLICT: 409,
|
|
71
|
-
GONE: 410,
|
|
72
|
-
LENGTH_REQUIRED: 411,
|
|
73
|
-
PRECONDITION_FAILED: 412,
|
|
74
|
-
PAYLOAD_TOO_LARGE: 413,
|
|
75
|
-
URI_TOO_LONG: 414,
|
|
76
|
-
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
77
|
-
RANGE_NOT_SATISFIABLE: 416,
|
|
78
|
-
EXPECTATION_FAILED: 417,
|
|
79
|
-
"I'M_A_TEAPOT": 418,
|
|
80
|
-
MISDIRECTED_REQUEST: 421,
|
|
81
|
-
UNPROCESSABLE_ENTITY: 422,
|
|
82
|
-
LOCKED: 423,
|
|
83
|
-
FAILED_DEPENDENCY: 424,
|
|
84
|
-
TOO_EARLY: 425,
|
|
85
|
-
UPGRADE_REQUIRED: 426,
|
|
86
|
-
PRECONDITION_REQUIRED: 428,
|
|
87
|
-
TOO_MANY_REQUESTS: 429,
|
|
88
|
-
REQUEST_HEADER_FIELDS_TOO_LARGE: 431,
|
|
89
|
-
UNAVAILABLE_FOR_LEGAL_REASONS: 451,
|
|
90
|
-
INTERNAL_SERVER_ERROR: 500,
|
|
91
|
-
NOT_IMPLEMENTED: 501,
|
|
92
|
-
BAD_GATEWAY: 502,
|
|
93
|
-
SERVICE_UNAVAILABLE: 503,
|
|
94
|
-
GATEWAY_TIMEOUT: 504,
|
|
95
|
-
HTTP_VERSION_NOT_SUPPORTED: 505,
|
|
96
|
-
VARIANT_ALSO_NEGOTIATES: 506,
|
|
97
|
-
INSUFFICIENT_STORAGE: 507,
|
|
98
|
-
LOOP_DETECTED: 508,
|
|
99
|
-
NOT_EXTENDED: 510,
|
|
100
|
-
NETWORK_AUTHENTICATION_REQUIRED: 511
|
|
101
|
-
};
|
|
102
|
-
var InternalAPIError = class extends Error {
|
|
103
|
-
constructor(status = "INTERNAL_SERVER_ERROR", body = void 0, headers = {}, statusCode = typeof status === "number" ? status : statusCodes[status]) {
|
|
104
|
-
super(body?.message, body?.cause ? { cause: body.cause } : void 0);
|
|
105
|
-
this.status = status;
|
|
106
|
-
this.body = body;
|
|
107
|
-
this.headers = headers;
|
|
108
|
-
this.statusCode = statusCode;
|
|
109
|
-
this.name = "APIError";
|
|
110
|
-
this.status = status;
|
|
111
|
-
this.headers = headers;
|
|
112
|
-
this.statusCode = statusCode;
|
|
113
|
-
this.body = body ? {
|
|
114
|
-
code: body?.message?.toUpperCase().replace(/ /g, "_").replace(/[^A-Z0-9_]/g, ""),
|
|
115
|
-
...body
|
|
116
|
-
} : void 0;
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
var ValidationError = class extends InternalAPIError {
|
|
120
|
-
constructor(message, issues) {
|
|
121
|
-
super(400, {
|
|
122
|
-
message,
|
|
123
|
-
code: "VALIDATION_ERROR"
|
|
124
|
-
});
|
|
125
|
-
this.message = message;
|
|
126
|
-
this.issues = issues;
|
|
127
|
-
this.issues = issues;
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
var BetterCallError = class extends Error {
|
|
131
|
-
constructor(message) {
|
|
132
|
-
super(message);
|
|
133
|
-
this.name = "BetterCallError";
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
const APIError = makeErrorForHideStackFrame(InternalAPIError, Error);
|
|
137
|
-
|
|
138
|
-
//#endregion
|
|
139
7
|
//#region src/utils.ts
|
|
140
8
|
const jsonContentTypeRegex = /^application\/([a-z0-9.+-]*\+)?json/i;
|
|
141
9
|
async function getBody(request, allowedMediaTypes) {
|
|
@@ -148,11 +16,11 @@ async function getBody(request, allowedMediaTypes) {
|
|
|
148
16
|
const normalizedAllowed = allowed.toLowerCase().trim();
|
|
149
17
|
return normalizedContentTypeBase === normalizedAllowed || normalizedContentTypeBase.includes(normalizedAllowed);
|
|
150
18
|
})) {
|
|
151
|
-
if (!normalizedContentType) throw new APIError(415, {
|
|
19
|
+
if (!normalizedContentType) throw new require_error.APIError(415, {
|
|
152
20
|
message: `Content-Type is required. Allowed types: ${allowedMediaTypes.join(", ")}`,
|
|
153
21
|
code: "UNSUPPORTED_MEDIA_TYPE"
|
|
154
22
|
});
|
|
155
|
-
throw new APIError(415, {
|
|
23
|
+
throw new require_error.APIError(415, {
|
|
156
24
|
message: `Content-Type "${contentType}" is not allowed. Allowed types: ${allowedMediaTypes.join(", ")}`,
|
|
157
25
|
code: "UNSUPPORTED_MEDIA_TYPE"
|
|
158
26
|
});
|
|
@@ -182,7 +50,7 @@ async function getBody(request, allowedMediaTypes) {
|
|
|
182
50
|
return await request.text();
|
|
183
51
|
}
|
|
184
52
|
function isAPIError(error) {
|
|
185
|
-
return error instanceof APIError || error?.name === "APIError";
|
|
53
|
+
return error instanceof require_error.APIError || error?.name === "APIError";
|
|
186
54
|
}
|
|
187
55
|
function tryDecode(str) {
|
|
188
56
|
try {
|
|
@@ -468,7 +336,7 @@ const createInternalContext = async (context, { options, path }) => {
|
|
|
468
336
|
const headers = new Headers();
|
|
469
337
|
let responseStatus = void 0;
|
|
470
338
|
const { data, error } = await runValidation(options, context);
|
|
471
|
-
if (error) throw new ValidationError(error.message, error.issues);
|
|
339
|
+
if (error) throw new require_error.ValidationError(error.message, error.issues);
|
|
472
340
|
const requestHeaders = "headers" in context ? context.headers instanceof Headers ? context.headers : new Headers(context.headers) : "request" in context && context.request instanceof Request ? context.request.headers : null;
|
|
473
341
|
const requestCookies = requestHeaders?.get("cookie");
|
|
474
342
|
const parsedCookies = requestCookies ? parseCookies(requestCookies) : void 0;
|
|
@@ -519,10 +387,10 @@ const createInternalContext = async (context, { options, path }) => {
|
|
|
519
387
|
},
|
|
520
388
|
redirect: (url) => {
|
|
521
389
|
headers.set("location", url);
|
|
522
|
-
return new APIError("FOUND", void 0, headers);
|
|
390
|
+
return new require_error.APIError("FOUND", void 0, headers);
|
|
523
391
|
},
|
|
524
392
|
error: (status, body, headers$1) => {
|
|
525
|
-
return new APIError(status, body, headers$1);
|
|
393
|
+
return new require_error.APIError(status, body, headers$1);
|
|
526
394
|
},
|
|
527
395
|
setStatus: (status) => {
|
|
528
396
|
responseStatus = status;
|
|
@@ -563,8 +431,8 @@ function createEndpoint(pathOrOptions, handlerOrOptions, handlerOrNever) {
|
|
|
563
431
|
const path = typeof pathOrOptions === "string" ? pathOrOptions : void 0;
|
|
564
432
|
const options = typeof handlerOrOptions === "object" ? handlerOrOptions : pathOrOptions;
|
|
565
433
|
const handler = typeof handlerOrOptions === "function" ? handlerOrOptions : handlerOrNever;
|
|
566
|
-
if ((options.method === "GET" || options.method === "HEAD") && options.body) throw new BetterCallError("Body is not allowed with GET or HEAD methods");
|
|
567
|
-
if (path && /\/{2,}/.test(path)) throw new BetterCallError("Path cannot contain consecutive slashes");
|
|
434
|
+
if ((options.method === "GET" || options.method === "HEAD") && options.body) throw new require_error.BetterCallError("Body is not allowed with GET or HEAD methods");
|
|
435
|
+
if (path && /\/{2,}/.test(path)) throw new require_error.BetterCallError("Path cannot contain consecutive slashes");
|
|
568
436
|
const internalHandler = async (...inputCtx) => {
|
|
569
437
|
const context = inputCtx[0] || {};
|
|
570
438
|
const { data: internalContext, error: validationError } = await tryCatch(createInternalContext(context, {
|
|
@@ -572,12 +440,12 @@ function createEndpoint(pathOrOptions, handlerOrOptions, handlerOrNever) {
|
|
|
572
440
|
path
|
|
573
441
|
}));
|
|
574
442
|
if (validationError) {
|
|
575
|
-
if (!(validationError instanceof ValidationError)) throw validationError;
|
|
443
|
+
if (!(validationError instanceof require_error.ValidationError)) throw validationError;
|
|
576
444
|
if (options.onValidationError) await options.onValidationError({
|
|
577
445
|
message: validationError.message,
|
|
578
446
|
issues: validationError.issues
|
|
579
447
|
});
|
|
580
|
-
throw new APIError(400, {
|
|
448
|
+
throw new require_error.APIError(400, {
|
|
581
449
|
message: validationError.message,
|
|
582
450
|
code: "VALIDATION_ERROR"
|
|
583
451
|
});
|
|
@@ -948,9 +816,9 @@ const createRouter = (endpoints, config) => {
|
|
|
948
816
|
};
|
|
949
817
|
|
|
950
818
|
//#endregion
|
|
951
|
-
exports.APIError = APIError;
|
|
952
|
-
exports.BetterCallError = BetterCallError;
|
|
953
|
-
exports.ValidationError = ValidationError;
|
|
819
|
+
exports.APIError = require_error.APIError;
|
|
820
|
+
exports.BetterCallError = require_error.BetterCallError;
|
|
821
|
+
exports.ValidationError = require_error.ValidationError;
|
|
954
822
|
exports.createEndpoint = createEndpoint;
|
|
955
823
|
exports.createInternalContext = createInternalContext;
|
|
956
824
|
exports.createMiddleware = createMiddleware;
|
|
@@ -958,11 +826,11 @@ exports.createRouter = createRouter;
|
|
|
958
826
|
exports.generator = generator;
|
|
959
827
|
exports.getCookieKey = getCookieKey;
|
|
960
828
|
exports.getHTML = getHTML;
|
|
961
|
-
exports.hideInternalStackFrames = hideInternalStackFrames;
|
|
962
|
-
exports.makeErrorForHideStackFrame = makeErrorForHideStackFrame;
|
|
829
|
+
exports.hideInternalStackFrames = require_error.hideInternalStackFrames;
|
|
830
|
+
exports.makeErrorForHideStackFrame = require_error.makeErrorForHideStackFrame;
|
|
963
831
|
exports.parseCookies = parseCookies;
|
|
964
832
|
exports.serializeCookie = serializeCookie;
|
|
965
833
|
exports.serializeSignedCookie = serializeSignedCookie;
|
|
966
|
-
exports.statusCodes = statusCodes;
|
|
834
|
+
exports.statusCodes = require_error.statusCodes;
|
|
967
835
|
exports.toResponse = toResponse;
|
|
968
836
|
//# sourceMappingURL=index.cjs.map
|