@arkyn/server 3.0.1-beta.116 → 3.0.1-beta.118
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/bundle.js +721 -734
- package/dist/bundle.umd.cjs +5 -10
- package/dist/{api/arkynLogRequest.d.ts → http/api/_logRequest.d.ts} +22 -19
- package/dist/{api/arkynLogRequest.d.ts.map → http/api/_logRequest.d.ts.map} +1 -1
- package/dist/{api/arkynLogRequest.js → http/api/_logRequest.js} +30 -30
- package/dist/http/api/_makeRequest.d.ts +61 -0
- package/dist/http/api/_makeRequest.d.ts.map +1 -0
- package/dist/{api/makeRequest.js → http/api/_makeRequest.js} +29 -20
- package/dist/http/api/deleteRequest.d.ts +17 -0
- package/dist/http/api/deleteRequest.d.ts.map +1 -0
- package/dist/http/api/deleteRequest.js +18 -0
- package/dist/http/api/getRequest.d.ts +16 -0
- package/dist/http/api/getRequest.d.ts.map +1 -0
- package/dist/http/api/getRequest.js +17 -0
- package/dist/http/api/patchRequest.d.ts +17 -0
- package/dist/http/api/patchRequest.d.ts.map +1 -0
- package/dist/http/api/patchRequest.js +18 -0
- package/dist/http/api/postRequest.d.ts +17 -0
- package/dist/http/api/postRequest.d.ts.map +1 -0
- package/dist/http/api/postRequest.js +18 -0
- package/dist/http/api/putRequest.d.ts +17 -0
- package/dist/http/api/putRequest.d.ts.map +1 -0
- package/dist/http/api/putRequest.js +18 -0
- package/dist/http/badResponses/_badResponse.d.ts +18 -7
- package/dist/http/badResponses/_badResponse.d.ts.map +1 -1
- package/dist/http/badResponses/_badResponse.js +44 -13
- package/dist/http/badResponses/badGateway.d.ts +4 -8
- package/dist/http/badResponses/badGateway.d.ts.map +1 -1
- package/dist/http/badResponses/badGateway.js +9 -17
- package/dist/http/badResponses/badRequest.d.ts +4 -8
- package/dist/http/badResponses/badRequest.d.ts.map +1 -1
- package/dist/http/badResponses/badRequest.js +9 -17
- package/dist/http/badResponses/conflict.d.ts +4 -8
- package/dist/http/badResponses/conflict.d.ts.map +1 -1
- package/dist/http/badResponses/conflict.js +9 -17
- package/dist/http/badResponses/forbidden.d.ts +4 -8
- package/dist/http/badResponses/forbidden.d.ts.map +1 -1
- package/dist/http/badResponses/forbidden.js +9 -17
- package/dist/http/badResponses/notFound.d.ts +4 -8
- package/dist/http/badResponses/notFound.d.ts.map +1 -1
- package/dist/http/badResponses/notFound.js +9 -17
- package/dist/http/badResponses/notImplemented.d.ts +4 -8
- package/dist/http/badResponses/notImplemented.d.ts.map +1 -1
- package/dist/http/badResponses/notImplemented.js +9 -17
- package/dist/http/badResponses/serverError.d.ts +4 -8
- package/dist/http/badResponses/serverError.d.ts.map +1 -1
- package/dist/http/badResponses/serverError.js +9 -17
- package/dist/http/badResponses/unauthorized.d.ts +2 -6
- package/dist/http/badResponses/unauthorized.d.ts.map +1 -1
- package/dist/http/badResponses/unauthorized.js +7 -15
- package/dist/http/badResponses/unprocessableEntity.d.ts +13 -18
- package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
- package/dist/http/badResponses/unprocessableEntity.js +14 -22
- package/dist/http/successResponses/_successResponse.d.ts +18 -7
- package/dist/http/successResponses/_successResponse.d.ts.map +1 -1
- package/dist/http/successResponses/_successResponse.js +50 -21
- package/dist/http/successResponses/created.d.ts +8 -22
- package/dist/http/successResponses/created.d.ts.map +1 -1
- package/dist/http/successResponses/created.js +13 -25
- package/dist/http/successResponses/found.d.ts +9 -26
- package/dist/http/successResponses/found.d.ts.map +1 -1
- package/dist/http/successResponses/found.js +14 -29
- package/dist/http/successResponses/noContent.d.ts +4 -12
- package/dist/http/successResponses/noContent.d.ts.map +1 -1
- package/dist/http/successResponses/noContent.js +9 -17
- package/dist/http/successResponses/success.d.ts +8 -22
- package/dist/http/successResponses/success.d.ts.map +1 -1
- package/dist/http/successResponses/success.js +13 -25
- package/dist/http/successResponses/updated.d.ts +8 -22
- package/dist/http/successResponses/updated.d.ts.map +1 -1
- package/dist/http/successResponses/updated.js +13 -25
- package/dist/index.d.ts +9 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -12
- package/dist/services/apiService.d.ts +7 -28
- package/dist/services/apiService.d.ts.map +1 -1
- package/dist/services/apiService.js +35 -41
- package/dist/services/debugService.d.ts +16 -1
- package/dist/services/debugService.d.ts.map +1 -1
- package/dist/services/debugService.js +58 -1
- package/dist/services/logMapperService.d.ts +86 -0
- package/dist/services/logMapperService.d.ts.map +1 -0
- package/dist/services/logMapperService.js +68 -0
- package/dist/services/logService.d.ts +38 -0
- package/dist/services/logService.d.ts.map +1 -0
- package/dist/services/logService.js +40 -0
- package/dist/{services → utilities}/decodeRequestBody.d.ts +3 -4
- package/dist/utilities/decodeRequestBody.d.ts.map +1 -0
- package/dist/{services → utilities}/decodeRequestBody.js +5 -5
- package/dist/{services/decodeErrorMessageFromRequest.d.ts → utilities/decodeRequestErrorMessage.d.ts} +6 -6
- package/dist/utilities/decodeRequestErrorMessage.d.ts.map +1 -0
- package/dist/{services/decodeErrorMessageFromRequest.js → utilities/decodeRequestErrorMessage.js} +5 -5
- package/dist/utilities/errorHandler.d.ts +50 -0
- package/dist/utilities/errorHandler.d.ts.map +1 -0
- package/dist/{services → utilities}/errorHandler.js +34 -28
- package/dist/utilities/flushDebugLogs.d.ts +46 -0
- package/dist/utilities/flushDebugLogs.d.ts.map +1 -0
- package/dist/utilities/flushDebugLogs.js +59 -0
- package/dist/{services → utilities}/formAsyncParse.d.ts +3 -3
- package/dist/utilities/formAsyncParse.d.ts.map +1 -0
- package/dist/{services → utilities}/formAsyncParse.js +3 -3
- package/dist/{services → utilities}/formParse.d.ts +3 -3
- package/dist/utilities/formParse.d.ts.map +1 -0
- package/dist/{services → utilities}/formParse.js +3 -3
- package/dist/{services → utilities}/getScopedParams.d.ts +3 -4
- package/dist/utilities/getScopedParams.d.ts.map +1 -0
- package/dist/{services → utilities}/getScopedParams.js +4 -4
- package/dist/{services → utilities}/schemaValidator.d.ts +3 -15
- package/dist/utilities/schemaValidator.d.ts.map +1 -0
- package/dist/{services → utilities}/schemaValidator.js +3 -19
- package/dist/validations/validateCep.d.ts +7 -12
- package/dist/validations/validateCep.d.ts.map +1 -1
- package/dist/validations/validateCep.js +9 -15
- package/dist/validations/validateCnpj.d.ts +4 -5
- package/dist/validations/validateCnpj.d.ts.map +1 -1
- package/dist/validations/validateCnpj.js +12 -5
- package/dist/validations/validateCpf.d.ts +3 -4
- package/dist/validations/validateCpf.d.ts.map +1 -1
- package/dist/validations/validateCpf.js +11 -4
- package/dist/validations/validateDate.d.ts +16 -23
- package/dist/validations/validateDate.d.ts.map +1 -1
- package/dist/validations/validateDate.js +38 -56
- package/dist/validations/validateEmail.d.ts +3 -4
- package/dist/validations/validateEmail.d.ts.map +1 -1
- package/dist/validations/validateEmail.js +23 -35
- package/dist/validations/validatePassword.d.ts +3 -4
- package/dist/validations/validatePassword.d.ts.map +1 -1
- package/dist/validations/validatePassword.js +5 -5
- package/dist/validations/validatePhone.d.ts +3 -4
- package/dist/validations/validatePhone.d.ts.map +1 -1
- package/dist/validations/validatePhone.js +4 -4
- package/dist/validations/validateRg.d.ts +3 -4
- package/dist/validations/validateRg.d.ts.map +1 -1
- package/dist/validations/validateRg.js +4 -4
- package/package.json +1 -1
- package/dist/api/deleteRequest.d.ts +0 -13
- package/dist/api/deleteRequest.d.ts.map +0 -1
- package/dist/api/deleteRequest.js +0 -14
- package/dist/api/getRequest.d.ts +0 -12
- package/dist/api/getRequest.d.ts.map +0 -1
- package/dist/api/getRequest.js +0 -13
- package/dist/api/makeRequest.d.ts +0 -38
- package/dist/api/makeRequest.d.ts.map +0 -1
- package/dist/api/patchRequest.d.ts +0 -13
- package/dist/api/patchRequest.d.ts.map +0 -1
- package/dist/api/patchRequest.js +0 -14
- package/dist/api/postRequest.d.ts +0 -13
- package/dist/api/postRequest.d.ts.map +0 -1
- package/dist/api/postRequest.js +0 -14
- package/dist/api/putRequest.d.ts +0 -13
- package/dist/api/putRequest.d.ts.map +0 -1
- package/dist/api/putRequest.js +0 -14
- package/dist/mapper/arkynLogRequestMapper.d.ts +0 -30
- package/dist/mapper/arkynLogRequestMapper.d.ts.map +0 -1
- package/dist/mapper/arkynLogRequestMapper.js +0 -44
- package/dist/services/arkynLogService.d.ts +0 -44
- package/dist/services/arkynLogService.d.ts.map +0 -1
- package/dist/services/arkynLogService.js +0 -46
- package/dist/services/decodeErrorMessageFromRequest.d.ts.map +0 -1
- package/dist/services/decodeRequestBody.d.ts.map +0 -1
- package/dist/services/errorHandler.d.ts +0 -44
- package/dist/services/errorHandler.d.ts.map +0 -1
- package/dist/services/flushDebugLogs.d.ts +0 -8
- package/dist/services/flushDebugLogs.d.ts.map +0 -1
- package/dist/services/flushDebugLogs.js +0 -20
- package/dist/services/formAsyncParse.d.ts.map +0 -1
- package/dist/services/formParse.d.ts.map +0 -1
- package/dist/services/getCaller.d.ts +0 -17
- package/dist/services/getCaller.d.ts.map +0 -1
- package/dist/services/getCaller.js +0 -60
- package/dist/services/getScopedParams.d.ts.map +0 -1
- package/dist/services/measureRouteExecution.d.ts +0 -3
- package/dist/services/measureRouteExecution.d.ts.map +0 -1
- package/dist/services/measureRouteExecution.js +0 -24
- package/dist/services/schemaValidator.d.ts.map +0 -1
- package/dist/types/ApiResponseDTO.d.ts +0 -17
- package/dist/types/ApiResponseDTO.d.ts.map +0 -1
- package/dist/types/ApiResponseDTO.js +0 -1
package/dist/bundle.js
CHANGED
|
@@ -1,29 +1,12 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
var k = Object.defineProperty;
|
|
2
|
+
var w = (e, s, t) => s in e ? k(e, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[s] = t;
|
|
3
|
+
var c = (e, s, t) => w(e, typeof s != "symbol" ? s + "" : s, t);
|
|
4
4
|
import "zod";
|
|
5
|
-
import { removeNonNumeric as
|
|
6
|
-
import "node:dns";
|
|
7
|
-
import { countries as
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (process.env.NODE_ENV === "development" || ((s = process.env) == null ? void 0 : s.SHOW_ERRORS_IN_CONSOLE) === "true") {
|
|
11
|
-
const a = `${{
|
|
12
|
-
yellow: "\x1B[33m",
|
|
13
|
-
cyan: "\x1B[36m",
|
|
14
|
-
red: "\x1B[31m",
|
|
15
|
-
green: "\x1B[32m"
|
|
16
|
-
}[e.scheme]}[${e.name}]\x1B[0m`;
|
|
17
|
-
let c = `
|
|
18
|
-
`;
|
|
19
|
-
e.debugs.forEach((h) => {
|
|
20
|
-
c += `${a} ${h.trim()}
|
|
21
|
-
`;
|
|
22
|
-
}), console.log(c);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
const A = {};
|
|
26
|
-
class I {
|
|
5
|
+
import { removeNonNumeric as R, ValidateDateService as J } from "@arkyn/shared";
|
|
6
|
+
import j from "node:dns";
|
|
7
|
+
import { countries as _ } from "@arkyn/templates";
|
|
8
|
+
const I = {};
|
|
9
|
+
class S {
|
|
27
10
|
/**
|
|
28
11
|
* Sets the file name to be ignored during stack trace analysis.
|
|
29
12
|
*
|
|
@@ -31,7 +14,7 @@ class I {
|
|
|
31
14
|
* determining the actual caller of a function. This is useful when you have
|
|
32
15
|
* adapter or wrapper functions that you want to be transparent in the debug output.
|
|
33
16
|
*
|
|
34
|
-
* @param file - The name of the file to ignore in stack traces (e.g., "httpAdapter.ts")
|
|
17
|
+
* @param {string} file - The name of the file to ignore in stack traces (e.g., "httpAdapter.ts")
|
|
35
18
|
*
|
|
36
19
|
* @example
|
|
37
20
|
* ```typescript
|
|
@@ -39,8 +22,8 @@ class I {
|
|
|
39
22
|
* DebugService.setIgnoreFile("httpAdapter.ts");
|
|
40
23
|
* ```
|
|
41
24
|
*/
|
|
42
|
-
static setIgnoreFile(
|
|
43
|
-
this.ignoreFiles.push(
|
|
25
|
+
static setIgnoreFile(s) {
|
|
26
|
+
this.ignoreFiles.push(s);
|
|
44
27
|
}
|
|
45
28
|
/**
|
|
46
29
|
* Clears all configured ignore files.
|
|
@@ -57,77 +40,132 @@ class I {
|
|
|
57
40
|
static clearIgnoreFiles() {
|
|
58
41
|
this.ignoreFiles = [];
|
|
59
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Retrieves information about the caller of the current function.
|
|
45
|
+
*
|
|
46
|
+
* This function analyzes the stack trace to determine the file path and function name
|
|
47
|
+
* of the caller. It excludes stack trace entries related to the `@arkyn/server` package
|
|
48
|
+
* and attempts to resolve the file path relative to the project root directory.
|
|
49
|
+
*
|
|
50
|
+
* @returns An object containing:
|
|
51
|
+
* - `functionName`: The name of the function that called the current function, or "Unknown function" if it cannot be determined.
|
|
52
|
+
* - `callerInfo`: The file path of the caller relative to the project root, or "Unknown caller" if it cannot be determined.
|
|
53
|
+
*/
|
|
54
|
+
static getCaller() {
|
|
55
|
+
const s = process.cwd(), r = (new Error().stack || "").split(`
|
|
56
|
+
`).map((l) => l.trim());
|
|
57
|
+
let i = 2;
|
|
58
|
+
for (; i < r.length && (r[i].includes("node:internal") || r[i].includes("/node_modules/")); )
|
|
59
|
+
i++;
|
|
60
|
+
if (this.ignoreFiles.length > 0)
|
|
61
|
+
for (; i < r.length && this.ignoreFiles.some(
|
|
62
|
+
(l) => r[i].includes(l)
|
|
63
|
+
); )
|
|
64
|
+
i++;
|
|
65
|
+
const a = r[i] || "";
|
|
66
|
+
let u = "Unknown function", o = "Unknown caller";
|
|
67
|
+
const h = a.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);
|
|
68
|
+
if (h)
|
|
69
|
+
u = h[1], o = h[2];
|
|
70
|
+
else {
|
|
71
|
+
const l = a.match(/at\s+(.+)/);
|
|
72
|
+
if (l) {
|
|
73
|
+
o = l[1];
|
|
74
|
+
const d = o.match(/at\s+([^(\s]+)\s+/);
|
|
75
|
+
d && d[1] !== "new" && (u = d[1]);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
o.includes("(") && (o = o.substring(
|
|
79
|
+
o.indexOf("(") + 1,
|
|
80
|
+
o.lastIndexOf(")")
|
|
81
|
+
)), o = o.split(":").slice(0, -2).join(":");
|
|
82
|
+
try {
|
|
83
|
+
o = I.relative(s, o);
|
|
84
|
+
} catch {
|
|
85
|
+
}
|
|
86
|
+
return { functionName: u, callerInfo: o };
|
|
87
|
+
}
|
|
60
88
|
}
|
|
61
89
|
/**
|
|
62
90
|
* The name of the file to ignore when analyzing the stack trace.
|
|
63
91
|
* When set, the `getCaller` function will skip stack frames containing this file name.
|
|
64
92
|
*/
|
|
65
|
-
|
|
66
|
-
function
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
h = l[1], i = l[2];
|
|
82
|
-
else {
|
|
83
|
-
const u = c.match(/at\s+(.+)/);
|
|
84
|
-
if (u) {
|
|
85
|
-
i = u[1];
|
|
86
|
-
const d = i.match(/at\s+([^(\s]+)\s+/);
|
|
87
|
-
d && d[1] !== "new" && (h = d[1]);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
i.includes("(") && (i = i.substring(
|
|
91
|
-
i.indexOf("(") + 1,
|
|
92
|
-
i.lastIndexOf(")")
|
|
93
|
-
)), i = i.split(":").slice(0, -2).join(":");
|
|
94
|
-
try {
|
|
95
|
-
i = A.relative(e, i);
|
|
96
|
-
} catch {
|
|
93
|
+
c(S, "ignoreFiles", []);
|
|
94
|
+
function p(e) {
|
|
95
|
+
var t;
|
|
96
|
+
if (process.env.NODE_ENV === "development" || ((t = process.env) == null ? void 0 : t.DEBUG_MODE) === "true") {
|
|
97
|
+
const i = `${{
|
|
98
|
+
yellow: "\x1B[33m",
|
|
99
|
+
cyan: "\x1B[36m",
|
|
100
|
+
red: "\x1B[31m",
|
|
101
|
+
green: "\x1B[32m"
|
|
102
|
+
}[e.scheme]}[${e.name}]\x1B[0m`;
|
|
103
|
+
let a = `
|
|
104
|
+
`;
|
|
105
|
+
e.debugs.forEach((u) => {
|
|
106
|
+
a += `${i} ${u.trim()}
|
|
107
|
+
`;
|
|
108
|
+
}), console.log(a);
|
|
97
109
|
}
|
|
98
|
-
return { functionName: h, callerInfo: i };
|
|
99
110
|
}
|
|
100
|
-
class
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
c
|
|
111
|
+
class f {
|
|
112
|
+
constructor() {
|
|
113
|
+
c(this, "_cause");
|
|
114
|
+
c(this, "_name", "BadResponse");
|
|
115
|
+
c(this, "_status", 500);
|
|
116
|
+
c(this, "_statusText", "Unknown error");
|
|
117
|
+
}
|
|
118
|
+
get cause() {
|
|
119
|
+
return this._cause;
|
|
120
|
+
}
|
|
121
|
+
set cause(s) {
|
|
122
|
+
this._cause = s;
|
|
123
|
+
}
|
|
124
|
+
get name() {
|
|
125
|
+
return this._name;
|
|
126
|
+
}
|
|
127
|
+
set name(s) {
|
|
128
|
+
this._name = s;
|
|
129
|
+
}
|
|
130
|
+
get status() {
|
|
131
|
+
return this._status;
|
|
132
|
+
}
|
|
133
|
+
set status(s) {
|
|
134
|
+
this._status = s;
|
|
135
|
+
}
|
|
136
|
+
get statusText() {
|
|
137
|
+
return this._statusText;
|
|
138
|
+
}
|
|
139
|
+
set statusText(s) {
|
|
140
|
+
this._statusText = s;
|
|
141
|
+
}
|
|
142
|
+
onDebug() {
|
|
143
|
+
const s = [], { callerInfo: t, functionName: n } = S.getCaller();
|
|
144
|
+
s.push(`Caller Function: ${n}`), s.push(`Caller Location: ${t}`), this._statusText && s.push(`Message: ${this._statusText}`), this._cause && s.push(`Cause: ${JSON.stringify(this._cause)}`), p({ scheme: "red", name: this._name, debugs: s });
|
|
145
|
+
}
|
|
146
|
+
makeBody() {
|
|
147
|
+
return {
|
|
148
|
+
name: this._name,
|
|
149
|
+
message: this._statusText,
|
|
150
|
+
cause: this._cause
|
|
151
|
+
};
|
|
104
152
|
}
|
|
105
153
|
}
|
|
106
|
-
class
|
|
154
|
+
class U extends f {
|
|
107
155
|
/**
|
|
108
156
|
* Creates an instance of the `BadGateway` class.
|
|
109
157
|
*
|
|
110
|
-
* @param message - A descriptive message explaining the cause of the error.
|
|
111
|
-
* @param cause - Optional additional information about the cause of the error.
|
|
158
|
+
* @param {string} message - A descriptive message explaining the cause of the error.
|
|
159
|
+
* @param {any} cause - Optional additional information about the cause of the error.
|
|
112
160
|
*/
|
|
113
|
-
constructor(s,
|
|
114
|
-
super();
|
|
115
|
-
o(this, "body");
|
|
116
|
-
o(this, "cause");
|
|
117
|
-
o(this, "status", 502);
|
|
118
|
-
o(this, "statusText");
|
|
119
|
-
this.body = { name: "BadGateway", message: s }, this.statusText = s, this.cause = n ? JSON.stringify(n) : void 0, this.onDebug({
|
|
120
|
-
name: "BadGateway",
|
|
121
|
-
body: this.body,
|
|
122
|
-
cause: this.cause,
|
|
123
|
-
message: this.statusText
|
|
124
|
-
});
|
|
161
|
+
constructor(s, t) {
|
|
162
|
+
super(), this.name = "BadGateway", this.status = 502, this.statusText = s, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
125
163
|
}
|
|
126
164
|
/**
|
|
127
165
|
* Converts the `BadGateway` instance into a `Response` object with a JSON body.
|
|
128
166
|
* This method ensures the response has the appropriate headers, status, and status text.
|
|
129
167
|
*
|
|
130
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
168
|
+
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
131
169
|
*/
|
|
132
170
|
toResponse() {
|
|
133
171
|
const s = {
|
|
@@ -135,47 +173,37 @@ class L extends p {
|
|
|
135
173
|
status: this.status,
|
|
136
174
|
statusText: this.statusText
|
|
137
175
|
};
|
|
138
|
-
return new Response(JSON.stringify(this.
|
|
176
|
+
return new Response(JSON.stringify(this.makeBody()), s);
|
|
139
177
|
}
|
|
140
178
|
/**
|
|
141
179
|
* Converts the `BadGateway` instance into a `Response` object using the `Response.json` method.
|
|
142
180
|
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
143
181
|
*
|
|
144
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
182
|
+
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
145
183
|
*/
|
|
146
184
|
toJson() {
|
|
147
185
|
const s = {
|
|
148
186
|
status: this.status,
|
|
149
187
|
statusText: this.statusText
|
|
150
188
|
};
|
|
151
|
-
return Response.json(this.
|
|
189
|
+
return Response.json(this.makeBody(), s);
|
|
152
190
|
}
|
|
153
191
|
}
|
|
154
|
-
class
|
|
192
|
+
class T extends f {
|
|
155
193
|
/**
|
|
156
194
|
* Creates an instance of the `BadRequest` class.
|
|
157
195
|
*
|
|
158
|
-
* @param message - A descriptive message explaining the cause of the error.
|
|
159
|
-
* @param cause - Optional additional information about the cause of the error.
|
|
196
|
+
* @param {string} message - A descriptive message explaining the cause of the error.
|
|
197
|
+
* @param {any} cause - Optional additional information about the cause of the error.
|
|
160
198
|
*/
|
|
161
|
-
constructor(s,
|
|
162
|
-
super();
|
|
163
|
-
o(this, "body");
|
|
164
|
-
o(this, "cause");
|
|
165
|
-
o(this, "status", 400);
|
|
166
|
-
o(this, "statusText");
|
|
167
|
-
this.body = { name: "BadRequest", message: s }, this.statusText = s, this.cause = n ? JSON.stringify(n) : void 0, this.onDebug({
|
|
168
|
-
name: "BadRequest",
|
|
169
|
-
body: this.body,
|
|
170
|
-
cause: this.cause,
|
|
171
|
-
message: this.statusText
|
|
172
|
-
});
|
|
199
|
+
constructor(s, t) {
|
|
200
|
+
super(), this.name = "BadRequest", this.status = 400, this.statusText = s, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
173
201
|
}
|
|
174
202
|
/**
|
|
175
203
|
* Converts the `BadRequest` instance into a `Response` object with a JSON body.
|
|
176
204
|
* This method ensures the response has the appropriate headers, status, and status text.
|
|
177
205
|
*
|
|
178
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
206
|
+
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
179
207
|
*/
|
|
180
208
|
toResponse() {
|
|
181
209
|
const s = {
|
|
@@ -183,47 +211,37 @@ class x extends p {
|
|
|
183
211
|
status: this.status,
|
|
184
212
|
statusText: this.statusText
|
|
185
213
|
};
|
|
186
|
-
return new Response(JSON.stringify(this.
|
|
214
|
+
return new Response(JSON.stringify(this.makeBody()), s);
|
|
187
215
|
}
|
|
188
216
|
/**
|
|
189
217
|
* Converts the `BadRequest` instance into a `Response` object using the `Response.json` method.
|
|
190
218
|
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
191
219
|
*
|
|
192
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
220
|
+
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
193
221
|
*/
|
|
194
222
|
toJson() {
|
|
195
223
|
const s = {
|
|
196
224
|
status: this.status,
|
|
197
225
|
statusText: this.statusText
|
|
198
226
|
};
|
|
199
|
-
return Response.json(this.
|
|
227
|
+
return Response.json(this.makeBody(), s);
|
|
200
228
|
}
|
|
201
229
|
}
|
|
202
|
-
class
|
|
230
|
+
class C extends f {
|
|
203
231
|
/**
|
|
204
232
|
* Creates an instance of the `Conflict` class.
|
|
205
233
|
*
|
|
206
|
-
* @param message - A descriptive message explaining the cause of the conflict.
|
|
207
|
-
* @param cause - Optional additional information about the cause of the conflict.
|
|
234
|
+
* @param {string} message - A descriptive message explaining the cause of the conflict.
|
|
235
|
+
* @param {any} cause - Optional additional information about the cause of the conflict.
|
|
208
236
|
*/
|
|
209
|
-
constructor(s,
|
|
210
|
-
super();
|
|
211
|
-
o(this, "body");
|
|
212
|
-
o(this, "cause");
|
|
213
|
-
o(this, "status", 409);
|
|
214
|
-
o(this, "statusText");
|
|
215
|
-
this.body = { name: "Conflict", message: s }, this.statusText = s, this.cause = n ? JSON.stringify(n) : void 0, this.onDebug({
|
|
216
|
-
name: "Conflict",
|
|
217
|
-
body: this.body,
|
|
218
|
-
cause: this.cause,
|
|
219
|
-
message: this.statusText
|
|
220
|
-
});
|
|
237
|
+
constructor(s, t) {
|
|
238
|
+
super(), this.name = "Conflict", this.status = 409, this.statusText = s, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
221
239
|
}
|
|
222
240
|
/**
|
|
223
241
|
* Converts the `Conflict` instance into a `Response` object with a JSON body.
|
|
224
242
|
* This method ensures the response has the appropriate headers, status, and status text.
|
|
225
243
|
*
|
|
226
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
244
|
+
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
227
245
|
*/
|
|
228
246
|
toResponse() {
|
|
229
247
|
const s = {
|
|
@@ -231,47 +249,37 @@ class B extends p {
|
|
|
231
249
|
status: this.status,
|
|
232
250
|
statusText: this.statusText
|
|
233
251
|
};
|
|
234
|
-
return new Response(JSON.stringify(this.
|
|
252
|
+
return new Response(JSON.stringify(this.makeBody()), s);
|
|
235
253
|
}
|
|
236
254
|
/**
|
|
237
255
|
* Converts the `Conflict` instance into a `Response` object using the `Response.json` method.
|
|
238
256
|
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
239
257
|
*
|
|
240
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
258
|
+
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
241
259
|
*/
|
|
242
260
|
toJson() {
|
|
243
261
|
const s = {
|
|
244
262
|
status: this.status,
|
|
245
263
|
statusText: this.statusText
|
|
246
264
|
};
|
|
247
|
-
return Response.json(this.
|
|
265
|
+
return Response.json(this.makeBody(), s);
|
|
248
266
|
}
|
|
249
267
|
}
|
|
250
|
-
class
|
|
268
|
+
class A extends f {
|
|
251
269
|
/**
|
|
252
270
|
* Creates an instance of the `Forbidden` class.
|
|
253
271
|
*
|
|
254
|
-
* @param message - A descriptive message explaining why access is forbidden.
|
|
255
|
-
* @param cause - Optional additional information about the cause of the error.
|
|
272
|
+
* @param {string} message - A descriptive message explaining why access is forbidden.
|
|
273
|
+
* @param {any} cause - Optional additional information about the cause of the error.
|
|
256
274
|
*/
|
|
257
|
-
constructor(s,
|
|
258
|
-
super();
|
|
259
|
-
o(this, "body");
|
|
260
|
-
o(this, "cause");
|
|
261
|
-
o(this, "status", 403);
|
|
262
|
-
o(this, "statusText");
|
|
263
|
-
this.body = { name: "Forbidden", message: s }, this.statusText = s, this.cause = n ? JSON.stringify(n) : void 0, this.onDebug({
|
|
264
|
-
name: "Forbidden",
|
|
265
|
-
body: this.body,
|
|
266
|
-
cause: this.cause,
|
|
267
|
-
message: this.statusText
|
|
268
|
-
});
|
|
275
|
+
constructor(s, t) {
|
|
276
|
+
super(), this.name = "Forbidden", this.status = 403, this.statusText = s, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
269
277
|
}
|
|
270
278
|
/**
|
|
271
279
|
* Converts the `Forbidden` instance into a `Response` object with a JSON body.
|
|
272
280
|
* This method ensures the response has the appropriate headers, status, and status text.
|
|
273
281
|
*
|
|
274
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
282
|
+
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
275
283
|
*/
|
|
276
284
|
toResponse() {
|
|
277
285
|
const s = {
|
|
@@ -279,47 +287,37 @@ class k extends p {
|
|
|
279
287
|
status: this.status,
|
|
280
288
|
statusText: this.statusText
|
|
281
289
|
};
|
|
282
|
-
return new Response(JSON.stringify(this.
|
|
290
|
+
return new Response(JSON.stringify(this.makeBody()), s);
|
|
283
291
|
}
|
|
284
292
|
/**
|
|
285
293
|
* Converts the `Forbidden` instance into a `Response` object using the `Response.json` method.
|
|
286
294
|
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
287
295
|
*
|
|
288
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
296
|
+
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
289
297
|
*/
|
|
290
298
|
toJson() {
|
|
291
299
|
const s = {
|
|
292
300
|
status: this.status,
|
|
293
301
|
statusText: this.statusText
|
|
294
302
|
};
|
|
295
|
-
return Response.json(this.
|
|
303
|
+
return Response.json(this.makeBody(), s);
|
|
296
304
|
}
|
|
297
305
|
}
|
|
298
|
-
class q extends
|
|
306
|
+
class q extends f {
|
|
299
307
|
/**
|
|
300
308
|
* Creates an instance of the `NotFound` class.
|
|
301
309
|
*
|
|
302
|
-
* @param message - A descriptive message explaining the reason the resource was not found.
|
|
303
|
-
* @param cause - Optional additional information about the cause of the error.
|
|
310
|
+
* @param {string} message - A descriptive message explaining the reason the resource was not found.
|
|
311
|
+
* @param {any} cause - Optional additional information about the cause of the error.
|
|
304
312
|
*/
|
|
305
|
-
constructor(s,
|
|
306
|
-
super();
|
|
307
|
-
o(this, "body");
|
|
308
|
-
o(this, "cause");
|
|
309
|
-
o(this, "status", 404);
|
|
310
|
-
o(this, "statusText");
|
|
311
|
-
this.body = { name: "NotFound", message: s }, this.statusText = s, this.cause = n ? JSON.stringify(n) : void 0, this.onDebug({
|
|
312
|
-
name: "NotFound",
|
|
313
|
-
body: this.body,
|
|
314
|
-
cause: this.cause,
|
|
315
|
-
message: this.statusText
|
|
316
|
-
});
|
|
313
|
+
constructor(s, t) {
|
|
314
|
+
super(), this.name = "NotFound", this.status = 404, this.statusText = s, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
317
315
|
}
|
|
318
316
|
/**
|
|
319
317
|
* Converts the `NotFound` instance into a `Response` object with a JSON body.
|
|
320
318
|
* This method ensures the response has the appropriate headers, status, and status text.
|
|
321
319
|
*
|
|
322
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
320
|
+
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
323
321
|
*/
|
|
324
322
|
toResponse() {
|
|
325
323
|
const s = {
|
|
@@ -327,47 +325,37 @@ class q extends p {
|
|
|
327
325
|
status: this.status,
|
|
328
326
|
statusText: this.statusText
|
|
329
327
|
};
|
|
330
|
-
return new Response(JSON.stringify(this.
|
|
328
|
+
return new Response(JSON.stringify(this.makeBody()), s);
|
|
331
329
|
}
|
|
332
330
|
/**
|
|
333
331
|
* Converts the `NotFound` instance into a `Response` object using the `Response.json` method.
|
|
334
332
|
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
335
333
|
*
|
|
336
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
334
|
+
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
337
335
|
*/
|
|
338
336
|
toJson() {
|
|
339
337
|
const s = {
|
|
340
338
|
status: this.status,
|
|
341
339
|
statusText: this.statusText
|
|
342
340
|
};
|
|
343
|
-
return Response.json(this.
|
|
341
|
+
return Response.json(this.makeBody(), s);
|
|
344
342
|
}
|
|
345
343
|
}
|
|
346
|
-
class
|
|
344
|
+
class H extends f {
|
|
347
345
|
/**
|
|
348
346
|
* Creates an instance of the `NotImplemented` class.
|
|
349
347
|
*
|
|
350
|
-
* @param message - A descriptive message explaining why the functionality is not implemented.
|
|
351
|
-
* @param cause - Optional additional information about the cause of the error.
|
|
348
|
+
* @param {string} message - A descriptive message explaining why the functionality is not implemented.
|
|
349
|
+
* @param {any} cause - Optional additional information about the cause of the error.
|
|
352
350
|
*/
|
|
353
|
-
constructor(s,
|
|
354
|
-
super();
|
|
355
|
-
o(this, "body");
|
|
356
|
-
o(this, "cause");
|
|
357
|
-
o(this, "status", 501);
|
|
358
|
-
o(this, "statusText");
|
|
359
|
-
this.body = { name: "NotImplemented", message: s }, this.statusText = s, this.cause = n ? JSON.stringify(n) : void 0, this.onDebug({
|
|
360
|
-
name: "NotImplemented",
|
|
361
|
-
body: this.body,
|
|
362
|
-
cause: this.cause,
|
|
363
|
-
message: this.statusText
|
|
364
|
-
});
|
|
351
|
+
constructor(s, t) {
|
|
352
|
+
super(), this.name = "NotImplemented", this.status = 501, this.statusText = s, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
365
353
|
}
|
|
366
354
|
/**
|
|
367
355
|
* Converts the `NotImplemented` instance into a `Response` object with a JSON body.
|
|
368
356
|
* This method ensures the response has the appropriate headers, status, and status text.
|
|
369
357
|
*
|
|
370
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
358
|
+
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
371
359
|
*/
|
|
372
360
|
toResponse() {
|
|
373
361
|
const s = {
|
|
@@ -375,47 +363,37 @@ class F extends p {
|
|
|
375
363
|
status: this.status,
|
|
376
364
|
statusText: this.statusText
|
|
377
365
|
};
|
|
378
|
-
return new Response(JSON.stringify(this.
|
|
366
|
+
return new Response(JSON.stringify(this.makeBody()), s);
|
|
379
367
|
}
|
|
380
368
|
/**
|
|
381
369
|
* Converts the `NotImplemented` instance into a `Response` object using the `Response.json` method.
|
|
382
370
|
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
383
371
|
*
|
|
384
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
372
|
+
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
385
373
|
*/
|
|
386
374
|
toJson() {
|
|
387
375
|
const s = {
|
|
388
376
|
status: this.status,
|
|
389
377
|
statusText: this.statusText
|
|
390
378
|
};
|
|
391
|
-
return Response.json(this.
|
|
379
|
+
return Response.json(this.makeBody(), s);
|
|
392
380
|
}
|
|
393
381
|
}
|
|
394
|
-
class
|
|
382
|
+
class x extends f {
|
|
395
383
|
/**
|
|
396
384
|
* Creates an instance of the `ServerError` class.
|
|
397
385
|
*
|
|
398
|
-
* @param message - A descriptive message explaining the cause of the server error.
|
|
399
|
-
* @param cause - Optional additional information about the cause of the error.
|
|
386
|
+
* @param {string} message - A descriptive message explaining the cause of the server error.
|
|
387
|
+
* @param {any} cause - Optional additional information about the cause of the error.
|
|
400
388
|
*/
|
|
401
|
-
constructor(s,
|
|
402
|
-
super();
|
|
403
|
-
o(this, "body");
|
|
404
|
-
o(this, "cause");
|
|
405
|
-
o(this, "status", 500);
|
|
406
|
-
o(this, "statusText");
|
|
407
|
-
this.body = { name: "ServerError", message: s }, this.statusText = s, this.cause = n ? JSON.stringify(n) : void 0, this.onDebug({
|
|
408
|
-
name: "ServerError",
|
|
409
|
-
body: this.body,
|
|
410
|
-
cause: this.cause,
|
|
411
|
-
message: this.statusText
|
|
412
|
-
});
|
|
389
|
+
constructor(s, t) {
|
|
390
|
+
super(), this.name = "ServerError", this.status = 500, this.statusText = s, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
413
391
|
}
|
|
414
392
|
/**
|
|
415
393
|
* Converts the `ServerError` instance into a `Response` object with a JSON body.
|
|
416
394
|
* This method ensures the response has the appropriate headers, status, and status text.
|
|
417
395
|
*
|
|
418
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
396
|
+
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
419
397
|
*/
|
|
420
398
|
toResponse() {
|
|
421
399
|
const s = {
|
|
@@ -423,47 +401,37 @@ class T extends p {
|
|
|
423
401
|
status: this.status,
|
|
424
402
|
statusText: this.statusText
|
|
425
403
|
};
|
|
426
|
-
return new Response(JSON.stringify(this.
|
|
404
|
+
return new Response(JSON.stringify(this.makeBody()), s);
|
|
427
405
|
}
|
|
428
406
|
/**
|
|
429
407
|
* Converts the `ServerError` instance into a `Response` object using the `Response.json` method.
|
|
430
408
|
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
431
409
|
*
|
|
432
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
410
|
+
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
433
411
|
*/
|
|
434
412
|
toJson() {
|
|
435
413
|
const s = {
|
|
436
414
|
status: this.status,
|
|
437
415
|
statusText: this.statusText
|
|
438
416
|
};
|
|
439
|
-
return Response.json(this.
|
|
417
|
+
return Response.json(this.makeBody(), s);
|
|
440
418
|
}
|
|
441
419
|
}
|
|
442
|
-
class
|
|
420
|
+
class L extends f {
|
|
443
421
|
/**
|
|
444
422
|
* Creates an instance of the `Unauthorized` class.
|
|
445
423
|
*
|
|
446
424
|
* @param message - A descriptive message explaining why the request is unauthorized.
|
|
447
425
|
* @param cause - Optional additional information about the cause of the error.
|
|
448
426
|
*/
|
|
449
|
-
constructor(s,
|
|
450
|
-
super();
|
|
451
|
-
o(this, "body");
|
|
452
|
-
o(this, "cause");
|
|
453
|
-
o(this, "status", 401);
|
|
454
|
-
o(this, "statusText");
|
|
455
|
-
this.body = { name: "Unauthorized", message: s }, this.statusText = s, this.cause = n ? JSON.stringify(n) : void 0, this.onDebug({
|
|
456
|
-
name: "Unauthorized",
|
|
457
|
-
body: this.body,
|
|
458
|
-
cause: this.cause,
|
|
459
|
-
message: this.statusText
|
|
460
|
-
});
|
|
427
|
+
constructor(s, t) {
|
|
428
|
+
super(), this.name = "Unauthorized", this.status = 401, this.statusText = s, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
461
429
|
}
|
|
462
430
|
/**
|
|
463
431
|
* Converts the `Unauthorized` instance into a `Response` object with a JSON body.
|
|
464
432
|
* This method ensures the response has the appropriate headers, status, and status text.
|
|
465
433
|
*
|
|
466
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
434
|
+
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
467
435
|
*/
|
|
468
436
|
toResponse() {
|
|
469
437
|
const s = {
|
|
@@ -471,55 +439,44 @@ class H extends p {
|
|
|
471
439
|
status: this.status,
|
|
472
440
|
statusText: this.statusText
|
|
473
441
|
};
|
|
474
|
-
return new Response(JSON.stringify(this.
|
|
442
|
+
return new Response(JSON.stringify(this.makeBody()), s);
|
|
475
443
|
}
|
|
476
444
|
/**
|
|
477
445
|
* Converts the `Unauthorized` instance into a `Response` object using the `Response.json` method.
|
|
478
446
|
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
479
447
|
*
|
|
480
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
448
|
+
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
481
449
|
*/
|
|
482
450
|
toJson() {
|
|
483
451
|
const s = {
|
|
484
452
|
status: this.status,
|
|
485
453
|
statusText: this.statusText
|
|
486
454
|
};
|
|
487
|
-
return Response.json(this.
|
|
455
|
+
return Response.json(this.makeBody(), s);
|
|
488
456
|
}
|
|
489
457
|
}
|
|
490
|
-
class
|
|
458
|
+
class b extends f {
|
|
491
459
|
/**
|
|
492
460
|
* Creates an instance of the `UnprocessableEntity` class.
|
|
493
461
|
*
|
|
494
|
-
* @param props - An object containing details about the error, such as:
|
|
495
|
-
*
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
* @param enableDebug - A boolean indicating whether to enable debug logging for this error.
|
|
462
|
+
* @param {object} props - An object containing details about the error, such as:
|
|
463
|
+
* @param {any} [props.data] - `data`: Additional data related to the error.
|
|
464
|
+
* @param {Record<string, string>} [props.fieldErrors] - `fieldErrors`: A record of field-specific error messages.
|
|
465
|
+
* @param {Record<string, string>} [props.fields] - `fields`: A record of field values that caused the error.
|
|
466
|
+
* @param {string} [props.message] - `message`: A descriptive message explaining the error.
|
|
500
467
|
*/
|
|
501
468
|
constructor(s) {
|
|
502
|
-
super()
|
|
503
|
-
o(this, "body");
|
|
504
|
-
o(this, "status", 422);
|
|
505
|
-
o(this, "statusText");
|
|
506
|
-
this.statusText = s.message || "Unprocessable Entity", this.body = {
|
|
507
|
-
name: "UnprocessableEntity",
|
|
508
|
-
message: s.message || null,
|
|
469
|
+
super(), this.name = "UnprocessableEntity", this.status = 422, this.statusText = s.message || "Unprocessable entity", this.cause = {
|
|
509
470
|
data: s.data,
|
|
510
471
|
fieldErrors: s.fieldErrors,
|
|
511
472
|
fields: s.fields
|
|
512
|
-
}, this.onDebug(
|
|
513
|
-
name: "UnprocessableEntity",
|
|
514
|
-
cause: s.fieldErrors,
|
|
515
|
-
message: s.message
|
|
516
|
-
});
|
|
473
|
+
}, this.onDebug();
|
|
517
474
|
}
|
|
518
475
|
/**
|
|
519
476
|
* Converts the `UnprocessableEntity` instance into a `Response` object with a JSON body.
|
|
520
477
|
* This method ensures the response has the appropriate headers, status, and status text.
|
|
521
478
|
*
|
|
522
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
479
|
+
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
523
480
|
*/
|
|
524
481
|
toResponse() {
|
|
525
482
|
const s = {
|
|
@@ -527,74 +484,93 @@ class R extends p {
|
|
|
527
484
|
status: this.status,
|
|
528
485
|
statusText: this.statusText
|
|
529
486
|
};
|
|
530
|
-
return new Response(JSON.stringify(this.
|
|
487
|
+
return new Response(JSON.stringify(this.makeBody()), s);
|
|
531
488
|
}
|
|
532
489
|
/**
|
|
533
490
|
* Converts the `UnprocessableEntity` instance into a `Response` object using the `Response.json` method.
|
|
534
491
|
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
535
492
|
*
|
|
536
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
493
|
+
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
537
494
|
*/
|
|
538
495
|
toJson() {
|
|
539
496
|
const s = {
|
|
540
497
|
status: this.status,
|
|
541
498
|
statusText: this.statusText
|
|
542
499
|
};
|
|
543
|
-
return Response.json(this.
|
|
500
|
+
return Response.json(this.makeBody(), s);
|
|
544
501
|
}
|
|
545
502
|
}
|
|
546
|
-
class
|
|
503
|
+
class y {
|
|
504
|
+
constructor() {
|
|
505
|
+
c(this, "_body", null);
|
|
506
|
+
c(this, "_name", "SuccessResponse");
|
|
507
|
+
c(this, "_status", 200);
|
|
508
|
+
c(this, "_statusText", "OK");
|
|
509
|
+
}
|
|
510
|
+
get body() {
|
|
511
|
+
return this._body;
|
|
512
|
+
}
|
|
513
|
+
set body(s) {
|
|
514
|
+
this._body = s ?? null;
|
|
515
|
+
}
|
|
516
|
+
get name() {
|
|
517
|
+
return this._name;
|
|
518
|
+
}
|
|
519
|
+
set name(s) {
|
|
520
|
+
this._name = s;
|
|
521
|
+
}
|
|
522
|
+
get status() {
|
|
523
|
+
return this._status;
|
|
524
|
+
}
|
|
525
|
+
set status(s) {
|
|
526
|
+
this._status = s;
|
|
527
|
+
}
|
|
528
|
+
get statusText() {
|
|
529
|
+
return this._statusText;
|
|
530
|
+
}
|
|
531
|
+
set statusText(s) {
|
|
532
|
+
this._statusText = s;
|
|
533
|
+
}
|
|
547
534
|
/**
|
|
548
535
|
* Logs debug information for success responses including caller context and response details.
|
|
549
536
|
*
|
|
550
|
-
* @param
|
|
551
|
-
* @param body - The response body or success data to be logged
|
|
552
|
-
* @param cause - Optional additional cause information for the error
|
|
537
|
+
* @param {any} body - The response body or success data to be logged
|
|
553
538
|
*
|
|
554
539
|
* @example
|
|
555
540
|
* ```typescript
|
|
556
541
|
* const SuccessResponse = new SuccessResponse();
|
|
557
|
-
* SuccessResponse.onDebug(
|
|
542
|
+
* SuccessResponse.onDebug({ data: "Operation completed successfully" });
|
|
558
543
|
* ```
|
|
559
544
|
*/
|
|
560
|
-
onDebug(
|
|
561
|
-
const
|
|
562
|
-
r.push(
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
debugs: r
|
|
571
|
-
});
|
|
545
|
+
onDebug(s) {
|
|
546
|
+
const t = [], { callerInfo: n, functionName: r } = S.getCaller();
|
|
547
|
+
t.push(`Caller Function: ${r}`), t.push(`Caller Location: ${n}`), this.statusText && t.push(`Message: ${this.statusText}`), s && t.push(`Body: ${JSON.stringify(s)}`), p({ scheme: "red", name: this.name, debugs: t });
|
|
548
|
+
}
|
|
549
|
+
makeBody() {
|
|
550
|
+
return {
|
|
551
|
+
name: this.name,
|
|
552
|
+
message: this.statusText,
|
|
553
|
+
body: this.body
|
|
554
|
+
};
|
|
572
555
|
}
|
|
573
556
|
}
|
|
574
|
-
class
|
|
557
|
+
class F extends y {
|
|
575
558
|
/**
|
|
576
559
|
* Creates an instance of the `Created` class.
|
|
577
560
|
*
|
|
578
|
-
* @param
|
|
579
|
-
* @param
|
|
561
|
+
* @param {string} message - A message describing the creation status.
|
|
562
|
+
* @param {any} body - The response body to be included in the HTTP response.
|
|
580
563
|
*/
|
|
581
|
-
constructor(s,
|
|
582
|
-
super();
|
|
583
|
-
o(this, "body");
|
|
584
|
-
o(this, "headers");
|
|
585
|
-
o(this, "status");
|
|
586
|
-
o(this, "statusText");
|
|
587
|
-
this.body = { ...s, name: "Created", message: n == null ? void 0 : n.message }, this.headers = (n == null ? void 0 : n.headers) || {}, this.status = (n == null ? void 0 : n.status) || 201, this.statusText = (n == null ? void 0 : n.statusText) || "Resource created successfully", this.onDebug("Created", s);
|
|
564
|
+
constructor(s, t) {
|
|
565
|
+
super(), this.name = "Created", this.status = 201, this.statusText = s, this.body = t || void 0, this.onDebug();
|
|
588
566
|
}
|
|
589
567
|
/**
|
|
590
|
-
* Converts the `Created` instance into a `Response` object
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
568
|
+
* Converts the `Created` instance into a `Response` object.
|
|
569
|
+
* @returns {Response} A `Response` object with the body and response metadata.
|
|
594
570
|
*/
|
|
595
571
|
toResponse() {
|
|
596
572
|
const s = {
|
|
597
|
-
headers: { "Content-Type": "application/json"
|
|
573
|
+
headers: { "Content-Type": "application/json" },
|
|
598
574
|
status: this.status,
|
|
599
575
|
statusText: this.statusText
|
|
600
576
|
};
|
|
@@ -603,117 +579,89 @@ class P extends m {
|
|
|
603
579
|
/**
|
|
604
580
|
* Converts the `Created` instance into a `Response` object using the `Response.json` method.
|
|
605
581
|
* This method is an alternative to `toResponse` for generating JSON responses.
|
|
606
|
-
*
|
|
607
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
582
|
+
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
608
583
|
*/
|
|
609
584
|
toJson() {
|
|
610
585
|
const s = {
|
|
611
|
-
headers: this.headers,
|
|
612
586
|
status: this.status,
|
|
613
587
|
statusText: this.statusText
|
|
614
588
|
};
|
|
615
589
|
return Response.json(this.body, s);
|
|
616
590
|
}
|
|
617
591
|
}
|
|
618
|
-
class
|
|
592
|
+
class z extends y {
|
|
619
593
|
/**
|
|
620
594
|
* Creates an instance of the `Found` class.
|
|
621
595
|
*
|
|
622
|
-
* @param
|
|
623
|
-
* @param
|
|
624
|
-
* - `headers`: Additional headers to include in the response.
|
|
625
|
-
* - `status`: HTTP status code (default is 302).
|
|
626
|
-
* - `statusText`: HTTP status text (default is "Found").
|
|
596
|
+
* @param {string} message - A message describing the creation status.
|
|
597
|
+
* @param {any} body - The response body to be included in the HTTP response.
|
|
627
598
|
*/
|
|
628
|
-
constructor(s,
|
|
629
|
-
super();
|
|
630
|
-
o(this, "body");
|
|
631
|
-
o(this, "headers");
|
|
632
|
-
o(this, "status");
|
|
633
|
-
o(this, "statusText");
|
|
634
|
-
this.body = { ...s, name: "Found", message: n == null ? void 0 : n.message }, this.headers = (n == null ? void 0 : n.headers) || {}, this.status = (n == null ? void 0 : n.status) || 302, this.statusText = (n == null ? void 0 : n.statusText) || "Found", this.onDebug("Found", s);
|
|
599
|
+
constructor(s, t) {
|
|
600
|
+
super(), this.name = "Found", this.status = 302, this.statusText = s, this.body = t || void 0, this.onDebug();
|
|
635
601
|
}
|
|
636
602
|
/**
|
|
637
603
|
* Converts the `Found` instance into a `Response` object.
|
|
638
|
-
*
|
|
639
|
-
*
|
|
640
|
-
* @returns A `Response` object with the serialized JSON body and the specified headers, status, and statusText.
|
|
604
|
+
* @returns {Response} A `Response` object with the body and response metadata.
|
|
641
605
|
*/
|
|
642
606
|
toResponse() {
|
|
643
607
|
const s = {
|
|
644
|
-
headers: { "Content-Type": "application/json"
|
|
608
|
+
headers: { "Content-Type": "application/json" },
|
|
645
609
|
status: this.status,
|
|
646
610
|
statusText: this.statusText
|
|
647
611
|
};
|
|
648
612
|
return new Response(JSON.stringify(this.body), s);
|
|
649
613
|
}
|
|
650
614
|
/**
|
|
651
|
-
* Converts the `Found` instance into a
|
|
652
|
-
* This method is an alternative to `toResponse` for
|
|
653
|
-
*
|
|
654
|
-
* @returns A `Response` object with the JSON body and the specified headers, status, and statusText.
|
|
615
|
+
* Converts the `Found` instance into a `Response` object using the `Response.json` method.
|
|
616
|
+
* This method is an alternative to `toResponse` for generating JSON responses.
|
|
617
|
+
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
655
618
|
*/
|
|
656
619
|
toJson() {
|
|
657
620
|
const s = {
|
|
658
|
-
headers: this.headers,
|
|
659
621
|
status: this.status,
|
|
660
622
|
statusText: this.statusText
|
|
661
623
|
};
|
|
662
624
|
return Response.json(this.body, s);
|
|
663
625
|
}
|
|
664
626
|
}
|
|
665
|
-
class
|
|
627
|
+
class M extends y {
|
|
666
628
|
/**
|
|
667
629
|
* Creates an instance of the `NoContent` class.
|
|
668
|
-
*
|
|
669
|
-
* @param init - Optional initialization object for customizing headers, status, and status text.
|
|
630
|
+
* @param {string} message - A message describing the creation status.
|
|
670
631
|
*/
|
|
671
632
|
constructor(s) {
|
|
672
|
-
super();
|
|
673
|
-
o(this, "headers");
|
|
674
|
-
o(this, "status");
|
|
675
|
-
o(this, "statusText");
|
|
676
|
-
this.headers = (s == null ? void 0 : s.headers) || {}, this.status = (s == null ? void 0 : s.status) || 204, this.statusText = (s == null ? void 0 : s.statusText) ?? "No content", this.onDebug("No content", null);
|
|
633
|
+
super(), this.name = "NoContent", this.status = 204, this.statusText = s, this.onDebug();
|
|
677
634
|
}
|
|
678
635
|
/**
|
|
679
636
|
* Converts the `NoContent` instance into a `Response` object.
|
|
680
|
-
*
|
|
681
|
-
*
|
|
682
|
-
* @returns A `Response` object with no body and response metadata.
|
|
637
|
+
* @returns {Response} A `Response` object with the body and response metadata.
|
|
683
638
|
*/
|
|
684
639
|
toResponse() {
|
|
685
640
|
const s = {
|
|
686
|
-
headers:
|
|
641
|
+
headers: { "Content-Type": "application/json" },
|
|
687
642
|
status: this.status,
|
|
688
643
|
statusText: this.statusText
|
|
689
644
|
};
|
|
690
645
|
return new Response(null, s);
|
|
691
646
|
}
|
|
692
647
|
}
|
|
693
|
-
class
|
|
648
|
+
class V extends y {
|
|
694
649
|
/**
|
|
695
650
|
* Creates an instance of the `Success` class.
|
|
696
651
|
*
|
|
697
|
-
* @param
|
|
698
|
-
* @param
|
|
652
|
+
* @param {string} message - A message describing the creation status.
|
|
653
|
+
* @param {any} body - The response body to be included in the HTTP response.
|
|
699
654
|
*/
|
|
700
|
-
constructor(s,
|
|
701
|
-
super();
|
|
702
|
-
o(this, "body");
|
|
703
|
-
o(this, "headers");
|
|
704
|
-
o(this, "status");
|
|
705
|
-
o(this, "statusText");
|
|
706
|
-
this.body = { ...s, name: "Success", message: n == null ? void 0 : n.message }, this.headers = (n == null ? void 0 : n.headers) || {}, this.status = (n == null ? void 0 : n.status) || 200, this.statusText = (n == null ? void 0 : n.statusText) ?? "OK", this.onDebug("Success", s);
|
|
655
|
+
constructor(s, t) {
|
|
656
|
+
super(), this.name = "Success", this.status = 200, this.statusText = s, this.body = t || void 0, this.onDebug();
|
|
707
657
|
}
|
|
708
658
|
/**
|
|
709
|
-
* Converts the `Success` instance into a `Response` object
|
|
710
|
-
*
|
|
711
|
-
*
|
|
712
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
659
|
+
* Converts the `Success` instance into a `Response` object.
|
|
660
|
+
* @returns {Response} A `Response` object with the body and response metadata.
|
|
713
661
|
*/
|
|
714
662
|
toResponse() {
|
|
715
663
|
const s = {
|
|
716
|
-
headers: { "Content-Type": "application/json"
|
|
664
|
+
headers: { "Content-Type": "application/json" },
|
|
717
665
|
status: this.status,
|
|
718
666
|
statusText: this.statusText
|
|
719
667
|
};
|
|
@@ -722,42 +670,33 @@ class M extends m {
|
|
|
722
670
|
/**
|
|
723
671
|
* Converts the `Success` instance into a `Response` object using the `Response.json` method.
|
|
724
672
|
* This method is an alternative to `toResponse` for generating JSON responses.
|
|
725
|
-
*
|
|
726
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
673
|
+
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
727
674
|
*/
|
|
728
675
|
toJson() {
|
|
729
676
|
const s = {
|
|
730
|
-
headers: this.headers,
|
|
731
677
|
status: this.status,
|
|
732
678
|
statusText: this.statusText
|
|
733
679
|
};
|
|
734
680
|
return Response.json(this.body, s);
|
|
735
681
|
}
|
|
736
682
|
}
|
|
737
|
-
class
|
|
683
|
+
class Z extends y {
|
|
738
684
|
/**
|
|
739
685
|
* Creates an instance of the `Updated` class.
|
|
740
686
|
*
|
|
741
|
-
* @param
|
|
742
|
-
* @param
|
|
687
|
+
* @param {string} message - A message describing the creation status.
|
|
688
|
+
* @param {any} body - The response body to be included in the HTTP response.
|
|
743
689
|
*/
|
|
744
|
-
constructor(s,
|
|
745
|
-
super();
|
|
746
|
-
o(this, "body");
|
|
747
|
-
o(this, "headers");
|
|
748
|
-
o(this, "status");
|
|
749
|
-
o(this, "statusText");
|
|
750
|
-
this.body = { ...s, name: "Updated", message: n == null ? void 0 : n.message }, this.headers = (n == null ? void 0 : n.headers) || {}, this.status = (n == null ? void 0 : n.status) || 200, this.statusText = (n == null ? void 0 : n.statusText) || "Resource updated successfully", this.onDebug("Updated", s);
|
|
690
|
+
constructor(s, t) {
|
|
691
|
+
super(), this.name = "Updated", this.status = 200, this.statusText = s, this.body = t || void 0, this.onDebug();
|
|
751
692
|
}
|
|
752
693
|
/**
|
|
753
|
-
* Converts the `Updated` instance into a `Response` object
|
|
754
|
-
*
|
|
755
|
-
*
|
|
756
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
694
|
+
* Converts the `Updated` instance into a `Response` object.
|
|
695
|
+
* @returns {Response} A `Response` object with the body and response metadata.
|
|
757
696
|
*/
|
|
758
697
|
toResponse() {
|
|
759
698
|
const s = {
|
|
760
|
-
headers: { "Content-Type": "application/json"
|
|
699
|
+
headers: { "Content-Type": "application/json" },
|
|
761
700
|
status: this.status,
|
|
762
701
|
statusText: this.statusText
|
|
763
702
|
};
|
|
@@ -766,135 +705,148 @@ class _ extends m {
|
|
|
766
705
|
/**
|
|
767
706
|
* Converts the `Updated` instance into a `Response` object using the `Response.json` method.
|
|
768
707
|
* This method is an alternative to `toResponse` for generating JSON responses.
|
|
769
|
-
*
|
|
770
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
708
|
+
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
771
709
|
*/
|
|
772
710
|
toJson() {
|
|
773
711
|
const s = {
|
|
774
|
-
headers: this.headers,
|
|
775
712
|
status: this.status,
|
|
776
713
|
statusText: this.statusText
|
|
777
714
|
};
|
|
778
715
|
return Response.json(this.body, s);
|
|
779
716
|
}
|
|
780
717
|
}
|
|
781
|
-
class
|
|
782
|
-
|
|
783
|
-
|
|
718
|
+
class G {
|
|
719
|
+
/**
|
|
720
|
+
* Converts various header formats into a plain key-value object.
|
|
721
|
+
*
|
|
722
|
+
* @param {HeadersInit} headers - The headers to map.
|
|
723
|
+
* @returns {Record<string, string>} A plain object with header key-value pairs.
|
|
724
|
+
* @private
|
|
725
|
+
*/
|
|
726
|
+
static mapHeaders(s) {
|
|
727
|
+
return s instanceof Headers ? Object.fromEntries(s.entries()) : typeof s == "object" ? Object.entries(s).reduce(
|
|
728
|
+
(t, [n, r]) => (typeof r == "string" ? t[n] = r : Array.isArray(r) ? t[n] = r.join(", ") : t[n] = JSON.stringify(r), t),
|
|
729
|
+
{}
|
|
730
|
+
) : {};
|
|
784
731
|
}
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
732
|
+
/**
|
|
733
|
+
* Converts URLSearchParams into a plain key-value object.
|
|
734
|
+
*
|
|
735
|
+
* @param {URLSearchParams} queryParams - The query parameters to map.
|
|
736
|
+
* @returns {Record<string, string>} A plain object with query parameter key-value pairs.
|
|
737
|
+
* @private
|
|
738
|
+
*/
|
|
739
|
+
static mapQueryParams(s) {
|
|
740
|
+
const t = {};
|
|
741
|
+
return s.forEach((n, r) => t[r] = n), t;
|
|
790
742
|
}
|
|
791
|
-
|
|
743
|
+
/**
|
|
744
|
+
* Transforms raw HTTP request/response data into a standardized log output format.
|
|
745
|
+
*
|
|
746
|
+
* @param {InputProps} props - The input properties containing request/response data.
|
|
747
|
+
* @returns {OutputProps} The mapped output object ready for logging.
|
|
748
|
+
*/
|
|
749
|
+
static handle(s) {
|
|
792
750
|
return {
|
|
793
|
-
rawUrl:
|
|
794
|
-
status:
|
|
795
|
-
method:
|
|
751
|
+
rawUrl: s.rawUrl,
|
|
752
|
+
status: s.status,
|
|
753
|
+
method: s.method,
|
|
796
754
|
token: null,
|
|
797
|
-
elapsedTime:
|
|
798
|
-
requestHeaders: this.mapHeaders(
|
|
799
|
-
requestBody:
|
|
800
|
-
queryParams:
|
|
801
|
-
|
|
802
|
-
|
|
755
|
+
elapsedTime: s.elapsedTime,
|
|
756
|
+
requestHeaders: this.mapHeaders(s.requestHeaders),
|
|
757
|
+
requestBody: s.requestBody || null,
|
|
758
|
+
queryParams: {
|
|
759
|
+
...this.mapQueryParams(s.queryParams),
|
|
760
|
+
...s.urlParams
|
|
761
|
+
},
|
|
762
|
+
responseHeaders: this.mapHeaders(s.responseHeaders),
|
|
763
|
+
responseBody: s.responseBody || null
|
|
803
764
|
};
|
|
804
765
|
}
|
|
805
766
|
}
|
|
806
|
-
class
|
|
767
|
+
class v {
|
|
807
768
|
/**
|
|
808
|
-
* Sets the configuration
|
|
809
|
-
*
|
|
810
|
-
* the method will return early without making any changes.
|
|
769
|
+
* Sets the log service configuration only once.
|
|
770
|
+
* If the configuration is already set, the call is ignored.
|
|
811
771
|
*
|
|
812
|
-
* @param
|
|
813
|
-
* @param
|
|
814
|
-
* @param
|
|
815
|
-
* @param
|
|
816
|
-
* a default URL will be used.
|
|
772
|
+
* @param {object} config - Service configuration parameters.
|
|
773
|
+
* @param {string} config.trafficSourceId - Traffic source identifier.
|
|
774
|
+
* @param {string} config.userToken - User token for authentication.
|
|
775
|
+
* @param {string} [config.logBaseApiUrl] - Optional base URL for the log service.
|
|
817
776
|
*/
|
|
818
|
-
static
|
|
819
|
-
if (this.
|
|
820
|
-
const { trafficSourceId:
|
|
821
|
-
this.
|
|
822
|
-
trafficSourceId: s,
|
|
823
|
-
userToken: n,
|
|
824
|
-
apiUrl: r || "http://95.216.190.158:8081/ingest-log"
|
|
825
|
-
};
|
|
777
|
+
static setConfig(s) {
|
|
778
|
+
if (this.config) return;
|
|
779
|
+
const { trafficSourceId: t, userToken: n, logBaseApiUrl: r } = s, a = `${r || "http://95.216.190.158:8081"}/ingest-log`;
|
|
780
|
+
this.config = { trafficSourceId: t, userToken: n, apiUrl: a };
|
|
826
781
|
}
|
|
827
782
|
/**
|
|
828
|
-
*
|
|
829
|
-
*
|
|
830
|
-
* @returns {ArkynConfigProps | undefined} The current arkyn configuration if set,
|
|
831
|
-
* or `undefined` if no configuration has been initialized.
|
|
783
|
+
* Returns the current service configuration, if it exists.
|
|
784
|
+
* @returns {{ trafficSourceId: string; userToken: string; apiUrl: string } | undefined} The stored configuration or `undefined` if not set.
|
|
832
785
|
*/
|
|
833
|
-
static
|
|
834
|
-
return this.
|
|
786
|
+
static getConfig() {
|
|
787
|
+
return this.config;
|
|
835
788
|
}
|
|
836
789
|
/**
|
|
837
|
-
* Resets the
|
|
838
|
-
* This method can be used to clear the current configuration.
|
|
790
|
+
* Resets the stored configuration, allowing a new initialization.
|
|
839
791
|
*/
|
|
840
|
-
static
|
|
841
|
-
this.
|
|
792
|
+
static resetConfig() {
|
|
793
|
+
this.config = void 0;
|
|
842
794
|
}
|
|
843
795
|
}
|
|
844
|
-
|
|
845
|
-
async function
|
|
846
|
-
const
|
|
847
|
-
if (!
|
|
848
|
-
const { userToken:
|
|
849
|
-
elapsedTime:
|
|
850
|
-
method:
|
|
851
|
-
queryParams:
|
|
852
|
-
requestBody:
|
|
853
|
-
requestHeaders:
|
|
854
|
-
responseBody:
|
|
796
|
+
c(v, "config");
|
|
797
|
+
async function W(e) {
|
|
798
|
+
const s = v.getConfig();
|
|
799
|
+
if (!s) return;
|
|
800
|
+
const { userToken: t, apiUrl: n, trafficSourceId: r } = s, {
|
|
801
|
+
elapsedTime: i,
|
|
802
|
+
method: a,
|
|
803
|
+
queryParams: u,
|
|
804
|
+
requestBody: o,
|
|
805
|
+
requestHeaders: h,
|
|
806
|
+
responseBody: l,
|
|
855
807
|
responseHeaders: d,
|
|
856
|
-
status:
|
|
857
|
-
token:
|
|
858
|
-
rawUrl:
|
|
808
|
+
status: $,
|
|
809
|
+
token: xs,
|
|
810
|
+
rawUrl: B
|
|
859
811
|
} = e;
|
|
860
812
|
if (process.env.NODE_ENV !== "development")
|
|
861
813
|
try {
|
|
862
|
-
const
|
|
863
|
-
let
|
|
864
|
-
|
|
865
|
-
const
|
|
866
|
-
domainUrl:
|
|
867
|
-
pathnameUrl:
|
|
814
|
+
const m = new URL(B);
|
|
815
|
+
let D = "https";
|
|
816
|
+
m.protocol === "http:" && (D = "http");
|
|
817
|
+
const O = JSON.stringify({
|
|
818
|
+
domainUrl: m.protocol + "//" + m.host,
|
|
819
|
+
pathnameUrl: m.pathname,
|
|
868
820
|
trafficSourceId: r,
|
|
869
|
-
status:
|
|
870
|
-
protocol:
|
|
871
|
-
method:
|
|
821
|
+
status: $,
|
|
822
|
+
protocol: D,
|
|
823
|
+
method: a.toLowerCase(),
|
|
872
824
|
trafficUserId: null,
|
|
873
|
-
elapsedTime:
|
|
874
|
-
requestHeaders: JSON.stringify(
|
|
875
|
-
requestBody: JSON.stringify(
|
|
876
|
-
queryParams: JSON.stringify(
|
|
825
|
+
elapsedTime: i,
|
|
826
|
+
requestHeaders: JSON.stringify(h),
|
|
827
|
+
requestBody: JSON.stringify(o),
|
|
828
|
+
queryParams: JSON.stringify(u),
|
|
877
829
|
responseHeaders: JSON.stringify(d),
|
|
878
|
-
responseBody: JSON.stringify(
|
|
879
|
-
})
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
} catch (y) {
|
|
889
|
-
g({
|
|
890
|
-
debugs: [`Error sending request: ${y}`],
|
|
891
|
-
name: "ARKYN_LOG_ERROR",
|
|
830
|
+
responseBody: JSON.stringify(l)
|
|
831
|
+
}), P = {
|
|
832
|
+
"Content-Type": "application/json",
|
|
833
|
+
Authorization: `Bearer ${t}`
|
|
834
|
+
};
|
|
835
|
+
await fetch(n, { method: "POST", body: O, headers: P });
|
|
836
|
+
} catch (m) {
|
|
837
|
+
p({
|
|
838
|
+
debugs: [`Error sending request: ${m}`],
|
|
839
|
+
name: "LogError",
|
|
892
840
|
scheme: "red"
|
|
893
841
|
});
|
|
894
842
|
}
|
|
895
843
|
}
|
|
896
|
-
async function
|
|
897
|
-
|
|
844
|
+
async function g(e) {
|
|
845
|
+
let s = e.url;
|
|
846
|
+
e.urlParams && Object.entries(e.urlParams).forEach(([n, r]) => {
|
|
847
|
+
s = s.replaceAll(`:${n}`, r);
|
|
848
|
+
});
|
|
849
|
+
const t = {
|
|
898
850
|
POST: "Resource created successfully",
|
|
899
851
|
PUT: "Resource updated successfully",
|
|
900
852
|
DELETE: "Resource deleted successfully",
|
|
@@ -902,109 +854,117 @@ async function b(e, t, s = {}, n) {
|
|
|
902
854
|
GET: "Request successful"
|
|
903
855
|
};
|
|
904
856
|
try {
|
|
905
|
-
const
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
body:
|
|
909
|
-
}),
|
|
910
|
-
let
|
|
857
|
+
const n = performance.now(), r = { ...e.headers, "Content-Type": "application/json" }, i = await fetch(s, {
|
|
858
|
+
headers: r,
|
|
859
|
+
method: e.method,
|
|
860
|
+
body: e.body ? JSON.stringify(e.body) : void 0
|
|
861
|
+
}), a = performance.now() - n, u = i.status;
|
|
862
|
+
let o = null;
|
|
911
863
|
try {
|
|
912
|
-
|
|
864
|
+
o = await i.json();
|
|
913
865
|
} catch {
|
|
914
|
-
|
|
866
|
+
o = null;
|
|
915
867
|
}
|
|
916
|
-
const
|
|
917
|
-
elapsedTime:
|
|
918
|
-
method: e,
|
|
919
|
-
queryParams: new URL(
|
|
920
|
-
requestHeaders:
|
|
921
|
-
requestBody:
|
|
922
|
-
responseBody:
|
|
923
|
-
responseHeaders:
|
|
924
|
-
status:
|
|
925
|
-
|
|
868
|
+
const h = G.handle({
|
|
869
|
+
elapsedTime: a,
|
|
870
|
+
method: e.method,
|
|
871
|
+
queryParams: new URL(s).searchParams,
|
|
872
|
+
requestHeaders: r,
|
|
873
|
+
requestBody: e.body,
|
|
874
|
+
responseBody: o,
|
|
875
|
+
responseHeaders: i.headers,
|
|
876
|
+
status: u,
|
|
877
|
+
rawUrl: e.url,
|
|
878
|
+
urlParams: e.urlParams
|
|
926
879
|
});
|
|
927
|
-
return
|
|
880
|
+
return W(h), i.ok ? {
|
|
928
881
|
success: !0,
|
|
929
|
-
status:
|
|
930
|
-
message: (
|
|
931
|
-
response:
|
|
882
|
+
status: u,
|
|
883
|
+
message: (o == null ? void 0 : o.message) || t[e.method],
|
|
884
|
+
response: o,
|
|
932
885
|
cause: null
|
|
933
886
|
} : {
|
|
934
887
|
success: !1,
|
|
935
|
-
status:
|
|
936
|
-
message: (
|
|
937
|
-
response:
|
|
888
|
+
status: u,
|
|
889
|
+
message: (o == null ? void 0 : o.message) || i.statusText || "Request failed",
|
|
890
|
+
response: o,
|
|
938
891
|
cause: null
|
|
939
892
|
};
|
|
940
|
-
} catch (
|
|
941
|
-
return
|
|
942
|
-
debugs: [`Network error or request failed: ${
|
|
943
|
-
name: "
|
|
893
|
+
} catch (n) {
|
|
894
|
+
return p({
|
|
895
|
+
debugs: [`Network error or request failed: ${n}`],
|
|
896
|
+
name: "MakeRequestError",
|
|
944
897
|
scheme: "red"
|
|
945
898
|
}), {
|
|
946
899
|
success: !1,
|
|
947
900
|
status: 0,
|
|
948
901
|
message: "Network error or request failed",
|
|
949
902
|
response: null,
|
|
950
|
-
cause:
|
|
903
|
+
cause: n instanceof Error ? n.message : String(n)
|
|
951
904
|
};
|
|
952
905
|
}
|
|
953
906
|
}
|
|
954
|
-
async function
|
|
955
|
-
return
|
|
907
|
+
async function Y(e) {
|
|
908
|
+
return g({
|
|
909
|
+
method: "DELETE",
|
|
910
|
+
url: e.url,
|
|
911
|
+
urlParams: e.urlParams,
|
|
912
|
+
headers: e.headers,
|
|
913
|
+
body: e.body
|
|
914
|
+
});
|
|
956
915
|
}
|
|
957
|
-
async function
|
|
958
|
-
return
|
|
916
|
+
async function K(e) {
|
|
917
|
+
return g({
|
|
918
|
+
method: "GET",
|
|
919
|
+
url: e.url,
|
|
920
|
+
urlParams: e.urlParams,
|
|
921
|
+
headers: e.headers
|
|
922
|
+
});
|
|
959
923
|
}
|
|
960
|
-
async function
|
|
961
|
-
return
|
|
924
|
+
async function Q(e) {
|
|
925
|
+
return g({
|
|
926
|
+
method: "PATCH",
|
|
927
|
+
url: e.url,
|
|
928
|
+
urlParams: e.urlParams,
|
|
929
|
+
headers: e.headers,
|
|
930
|
+
body: e.body
|
|
931
|
+
});
|
|
962
932
|
}
|
|
963
|
-
async function
|
|
964
|
-
return
|
|
933
|
+
async function X(e) {
|
|
934
|
+
return g({
|
|
935
|
+
method: "POST",
|
|
936
|
+
url: e.url,
|
|
937
|
+
urlParams: e.urlParams,
|
|
938
|
+
headers: e.headers,
|
|
939
|
+
body: e.body
|
|
940
|
+
});
|
|
965
941
|
}
|
|
966
|
-
async function
|
|
967
|
-
return
|
|
942
|
+
async function ss(e) {
|
|
943
|
+
return g({
|
|
944
|
+
method: "PUT",
|
|
945
|
+
url: e.url,
|
|
946
|
+
urlParams: e.urlParams,
|
|
947
|
+
headers: e.headers,
|
|
948
|
+
body: e.body
|
|
949
|
+
});
|
|
968
950
|
}
|
|
969
|
-
class
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
* @param props.enableDebug - Optional flag to enable debug logging for requests.
|
|
977
|
-
*/
|
|
978
|
-
constructor(t) {
|
|
979
|
-
o(this, "baseUrl");
|
|
980
|
-
o(this, "baseHeaders");
|
|
981
|
-
o(this, "baseToken");
|
|
982
|
-
o(this, "enableDebug");
|
|
983
|
-
this.baseUrl = t.baseUrl, this.baseHeaders = t.baseHeaders || void 0, this.baseToken = t.baseToken || void 0, this.enableDebug = t.enableDebug || !1;
|
|
951
|
+
class Es {
|
|
952
|
+
constructor(s) {
|
|
953
|
+
c(this, "baseUrl");
|
|
954
|
+
c(this, "baseHeaders");
|
|
955
|
+
c(this, "baseToken");
|
|
956
|
+
c(this, "enableDebug");
|
|
957
|
+
this.baseUrl = s.baseUrl, this.baseHeaders = s.baseHeaders || void 0, this.baseToken = s.baseToken || void 0, this.enableDebug = s.enableDebug || !1;
|
|
984
958
|
}
|
|
985
|
-
|
|
986
|
-
* Generates the full URL by appending the route to the base URL.
|
|
987
|
-
* @param route - The route to append to the base URL.
|
|
988
|
-
* @returns The full URL as a string.
|
|
989
|
-
*/
|
|
990
|
-
onDebug(t, s, n) {
|
|
959
|
+
onDebug(s, t, n) {
|
|
991
960
|
if (this.enableDebug) {
|
|
992
961
|
const r = [];
|
|
993
|
-
r.push(`Base URL: ${this.baseUrl}`), r.push(`Endpoint: ${
|
|
962
|
+
r.push(`Base URL: ${this.baseUrl}`), r.push(`Endpoint: ${s}`), r.push(`Method: ${t}`), n[0] && r.push(`Headers: ${JSON.stringify(n[0])}`), n[1] && r.push(`Body: ${JSON.stringify(n[1])}`), p({ debugs: r, name: "ARKYN-API-DEBUG", scheme: "yellow" });
|
|
994
963
|
}
|
|
995
964
|
}
|
|
996
|
-
|
|
997
|
-
return this.baseUrl + t;
|
|
998
|
-
}
|
|
999
|
-
/**
|
|
1000
|
-
* Generates the headers for a request by merging base headers, provided headers, and tokens.
|
|
1001
|
-
* @param initHeaders - Initial headers to include in the request.
|
|
1002
|
-
* @param token - Optional token to override the base token.
|
|
1003
|
-
* @returns The merged headers as a HeadersInit object.
|
|
1004
|
-
*/
|
|
1005
|
-
generateHeaders(t, s) {
|
|
965
|
+
generateHeaders(s, t) {
|
|
1006
966
|
let n = {};
|
|
1007
|
-
return this.baseToken && (n = { Authorization: `Bearer ${this.baseToken}` }), this.baseHeaders && (n = { ...n, ...this.baseHeaders }),
|
|
967
|
+
return this.baseToken && (n = { Authorization: `Bearer ${this.baseToken}` }), this.baseHeaders && (n = { ...n, ...this.baseHeaders }), s && (n = { ...n, ...s }), t && (n = { ...n, Authorization: `Bearer ${t}` }), n;
|
|
1008
968
|
}
|
|
1009
969
|
/**
|
|
1010
970
|
* Sends a get request to the specified endpoint.
|
|
@@ -1012,9 +972,13 @@ class Ts {
|
|
|
1012
972
|
* @param data - The request data, including optional headers and token.
|
|
1013
973
|
* @returns The API response data.
|
|
1014
974
|
*/
|
|
1015
|
-
async get(
|
|
1016
|
-
const n = this.
|
|
1017
|
-
return this.onDebug(
|
|
975
|
+
async get(s, t) {
|
|
976
|
+
const n = this.generateHeaders((t == null ? void 0 : t.headers) || {}, t == null ? void 0 : t.token);
|
|
977
|
+
return this.onDebug(s, "get", [n]), await K({
|
|
978
|
+
url: this.baseUrl + s,
|
|
979
|
+
urlParams: (t == null ? void 0 : t.urlParams) || {},
|
|
980
|
+
headers: n
|
|
981
|
+
});
|
|
1018
982
|
}
|
|
1019
983
|
/**
|
|
1020
984
|
* Sends a post request to the specified endpoint.
|
|
@@ -1022,9 +986,14 @@ class Ts {
|
|
|
1022
986
|
* @param data - The request data, including body, optional headers, and token.
|
|
1023
987
|
* @returns The API response data.
|
|
1024
988
|
*/
|
|
1025
|
-
async post(
|
|
1026
|
-
const n = this.
|
|
1027
|
-
return this.onDebug(
|
|
989
|
+
async post(s, t) {
|
|
990
|
+
const n = this.generateHeaders((t == null ? void 0 : t.headers) || {}, t == null ? void 0 : t.token), r = t == null ? void 0 : t.body;
|
|
991
|
+
return this.onDebug(s, "post", [n, r]), await X({
|
|
992
|
+
url: this.baseUrl + s,
|
|
993
|
+
urlParams: (t == null ? void 0 : t.urlParams) || {},
|
|
994
|
+
headers: n,
|
|
995
|
+
body: r
|
|
996
|
+
});
|
|
1028
997
|
}
|
|
1029
998
|
/**
|
|
1030
999
|
* Sends a put request to the specified endpoint.
|
|
@@ -1032,9 +1001,14 @@ class Ts {
|
|
|
1032
1001
|
* @param data - The request data, including body, optional headers, and token.
|
|
1033
1002
|
* @returns The API response data.
|
|
1034
1003
|
*/
|
|
1035
|
-
async put(
|
|
1036
|
-
const n = this.
|
|
1037
|
-
return this.onDebug(
|
|
1004
|
+
async put(s, t) {
|
|
1005
|
+
const n = this.generateHeaders((t == null ? void 0 : t.headers) || {}, t == null ? void 0 : t.token), r = t == null ? void 0 : t.body;
|
|
1006
|
+
return this.onDebug(s, "put", [n, r]), await ss({
|
|
1007
|
+
url: this.baseUrl + s,
|
|
1008
|
+
urlParams: (t == null ? void 0 : t.urlParams) || {},
|
|
1009
|
+
headers: n,
|
|
1010
|
+
body: r
|
|
1011
|
+
});
|
|
1038
1012
|
}
|
|
1039
1013
|
/**
|
|
1040
1014
|
* Sends a patch request to the specified endpoint.
|
|
@@ -1042,9 +1016,14 @@ class Ts {
|
|
|
1042
1016
|
* @param data - The request data, including body, optional headers, and token.
|
|
1043
1017
|
* @returns The API response data.
|
|
1044
1018
|
*/
|
|
1045
|
-
async patch(
|
|
1046
|
-
const n = this.
|
|
1047
|
-
return this.onDebug(
|
|
1019
|
+
async patch(s, t) {
|
|
1020
|
+
const n = this.generateHeaders((t == null ? void 0 : t.headers) || {}, t == null ? void 0 : t.token), r = t == null ? void 0 : t.body;
|
|
1021
|
+
return this.onDebug(s, "patch", [n, r]), await Q({
|
|
1022
|
+
url: this.baseUrl + s,
|
|
1023
|
+
urlParams: (t == null ? void 0 : t.urlParams) || {},
|
|
1024
|
+
headers: n,
|
|
1025
|
+
body: r
|
|
1026
|
+
});
|
|
1048
1027
|
}
|
|
1049
1028
|
/**
|
|
1050
1029
|
* Sends a delete request to the specified endpoint.
|
|
@@ -1052,137 +1031,137 @@ class Ts {
|
|
|
1052
1031
|
* @param data - The request data, including body, optional headers, and token.
|
|
1053
1032
|
* @returns The API response data.
|
|
1054
1033
|
*/
|
|
1055
|
-
async delete(
|
|
1056
|
-
const n = this.
|
|
1057
|
-
return this.onDebug(
|
|
1034
|
+
async delete(s, t) {
|
|
1035
|
+
const n = this.generateHeaders((t == null ? void 0 : t.headers) || {}, t == null ? void 0 : t.token), r = t == null ? void 0 : t.body;
|
|
1036
|
+
return this.onDebug(s, "delete", [n, r]), await Y({
|
|
1037
|
+
url: this.baseUrl + s,
|
|
1038
|
+
urlParams: (t == null ? void 0 : t.urlParams) || {},
|
|
1039
|
+
headers: n,
|
|
1040
|
+
body: r
|
|
1041
|
+
});
|
|
1058
1042
|
}
|
|
1059
1043
|
}
|
|
1060
|
-
function
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
}
|
|
1064
|
-
const Ns = async (e) => {
|
|
1065
|
-
let t;
|
|
1066
|
-
const s = await e.arrayBuffer(), n = new TextDecoder().decode(s);
|
|
1044
|
+
async function vs(e) {
|
|
1045
|
+
let s;
|
|
1046
|
+
const t = await e.arrayBuffer(), n = new TextDecoder().decode(t);
|
|
1067
1047
|
try {
|
|
1068
|
-
|
|
1048
|
+
s = JSON.parse(n);
|
|
1069
1049
|
} catch {
|
|
1070
1050
|
try {
|
|
1071
1051
|
if (n.includes("=")) {
|
|
1072
|
-
const
|
|
1073
|
-
|
|
1052
|
+
const i = new URLSearchParams(n);
|
|
1053
|
+
s = Object.fromEntries(i.entries());
|
|
1074
1054
|
} else
|
|
1075
|
-
throw new
|
|
1055
|
+
throw new T("Invalid URLSearchParams format");
|
|
1076
1056
|
} catch {
|
|
1077
|
-
throw new
|
|
1057
|
+
throw new T("Failed to extract data from request");
|
|
1078
1058
|
}
|
|
1079
1059
|
}
|
|
1080
|
-
return
|
|
1081
|
-
}
|
|
1082
|
-
function
|
|
1060
|
+
return s;
|
|
1061
|
+
}
|
|
1062
|
+
function $s(e, s) {
|
|
1063
|
+
var t, n, r;
|
|
1064
|
+
return e != null && e.message && typeof (e == null ? void 0 : e.message) == "string" ? e == null ? void 0 : e.message : e != null && e.error && typeof (e == null ? void 0 : e.error) == "string" ? e == null ? void 0 : e.error : (t = e == null ? void 0 : e.error) != null && t.message && typeof ((n = e == null ? void 0 : e.error) == null ? void 0 : n.message) == "string" ? (r = e == null ? void 0 : e.error) == null ? void 0 : r.message : s != null && s.statusText && typeof (s == null ? void 0 : s.statusText) == "string" ? s == null ? void 0 : s.statusText : "Missing error message";
|
|
1065
|
+
}
|
|
1066
|
+
function Bs(e) {
|
|
1083
1067
|
switch (!0) {
|
|
1084
1068
|
case e instanceof Response:
|
|
1085
1069
|
return e;
|
|
1086
|
-
case e instanceof
|
|
1070
|
+
case e instanceof z:
|
|
1087
1071
|
return e.toResponse();
|
|
1088
|
-
case e instanceof
|
|
1072
|
+
case e instanceof F:
|
|
1089
1073
|
return e.toResponse();
|
|
1090
|
-
case e instanceof
|
|
1074
|
+
case e instanceof Z:
|
|
1091
1075
|
return e.toResponse();
|
|
1092
|
-
case e instanceof
|
|
1076
|
+
case e instanceof V:
|
|
1093
1077
|
return e.toResponse();
|
|
1094
|
-
case e instanceof
|
|
1078
|
+
case e instanceof M:
|
|
1095
1079
|
return e.toResponse();
|
|
1096
1080
|
}
|
|
1097
1081
|
switch (!0) {
|
|
1098
|
-
case e instanceof
|
|
1082
|
+
case e instanceof U:
|
|
1099
1083
|
return e.toResponse();
|
|
1100
|
-
case e instanceof
|
|
1084
|
+
case e instanceof T:
|
|
1101
1085
|
return e.toResponse();
|
|
1102
|
-
case e instanceof
|
|
1086
|
+
case e instanceof C:
|
|
1103
1087
|
return e.toResponse();
|
|
1104
|
-
case e instanceof
|
|
1088
|
+
case e instanceof A:
|
|
1105
1089
|
return e.toResponse();
|
|
1106
1090
|
case e instanceof q:
|
|
1107
1091
|
return e.toResponse();
|
|
1108
|
-
case e instanceof
|
|
1092
|
+
case e instanceof H:
|
|
1109
1093
|
return e.toResponse();
|
|
1110
|
-
case e instanceof
|
|
1094
|
+
case e instanceof x:
|
|
1111
1095
|
return e.toResponse();
|
|
1112
|
-
case e instanceof
|
|
1096
|
+
case e instanceof L:
|
|
1113
1097
|
return e.toResponse();
|
|
1114
|
-
case e instanceof
|
|
1098
|
+
case e instanceof b:
|
|
1115
1099
|
return e.toResponse();
|
|
1116
1100
|
}
|
|
1117
|
-
return new
|
|
1101
|
+
return new x("Server error", e).toResponse();
|
|
1118
1102
|
}
|
|
1119
|
-
async function
|
|
1103
|
+
async function es([
|
|
1120
1104
|
e,
|
|
1121
|
-
|
|
1105
|
+
s
|
|
1122
1106
|
]) {
|
|
1123
|
-
const
|
|
1124
|
-
if (
|
|
1107
|
+
const t = await s.safeParseAsync(e);
|
|
1108
|
+
if (t.success === !1) {
|
|
1125
1109
|
const n = Object.fromEntries(
|
|
1126
|
-
|
|
1110
|
+
t.error.issues.map((r) => [r.path.join("."), r.message])
|
|
1127
1111
|
);
|
|
1128
1112
|
return {
|
|
1129
|
-
success:
|
|
1113
|
+
success: t.success,
|
|
1130
1114
|
fieldErrors: n,
|
|
1131
1115
|
fields: e
|
|
1132
1116
|
};
|
|
1133
1117
|
} else
|
|
1134
1118
|
return {
|
|
1135
|
-
success:
|
|
1136
|
-
data:
|
|
1119
|
+
success: t.success,
|
|
1120
|
+
data: t.data
|
|
1137
1121
|
};
|
|
1138
1122
|
}
|
|
1139
|
-
function
|
|
1123
|
+
function ts([
|
|
1140
1124
|
e,
|
|
1141
|
-
|
|
1125
|
+
s
|
|
1142
1126
|
]) {
|
|
1143
|
-
const
|
|
1144
|
-
if (
|
|
1127
|
+
const t = s.safeParse(e);
|
|
1128
|
+
if (t.success === !1) {
|
|
1145
1129
|
const n = Object.fromEntries(
|
|
1146
|
-
|
|
1130
|
+
t.error.issues.map((r) => [r.path.join("."), r.message])
|
|
1147
1131
|
);
|
|
1148
1132
|
return {
|
|
1149
|
-
success:
|
|
1133
|
+
success: t.success,
|
|
1150
1134
|
fieldErrors: n,
|
|
1151
1135
|
fields: e
|
|
1152
1136
|
};
|
|
1153
1137
|
} else
|
|
1154
1138
|
return {
|
|
1155
|
-
success:
|
|
1156
|
-
data:
|
|
1139
|
+
success: t.success,
|
|
1140
|
+
data: t.data
|
|
1157
1141
|
};
|
|
1158
1142
|
}
|
|
1159
|
-
|
|
1160
|
-
const
|
|
1161
|
-
if (
|
|
1143
|
+
function Os(e, s = "") {
|
|
1144
|
+
const t = new URL(e.url);
|
|
1145
|
+
if (s === "") return t.searchParams;
|
|
1162
1146
|
const n = Array.from(
|
|
1163
|
-
|
|
1164
|
-
).filter(([r]) => r.startsWith(`${
|
|
1147
|
+
t.searchParams.entries()
|
|
1148
|
+
).filter(([r]) => r.startsWith(`${s}:`)).map(([r, i]) => [r.replace(`${s}:`, ""), i]);
|
|
1165
1149
|
return new URLSearchParams(n);
|
|
1166
|
-
}
|
|
1167
|
-
function
|
|
1168
|
-
const
|
|
1150
|
+
}
|
|
1151
|
+
function ns(e) {
|
|
1152
|
+
const s = "Error validating:", t = e.issues.map(
|
|
1169
1153
|
({ path: n, message: r }) => `-> ${n.join(".")}: ${r}`
|
|
1170
1154
|
);
|
|
1171
|
-
return [
|
|
1155
|
+
return [s, ...t].join(`
|
|
1172
1156
|
`);
|
|
1173
1157
|
}
|
|
1174
|
-
class
|
|
1158
|
+
class Ps {
|
|
1175
1159
|
/**
|
|
1176
1160
|
* Creates a new SchemaValidator instance.
|
|
1177
|
-
*
|
|
1178
1161
|
* @param {T} schema - The Zod schema to use for validation.
|
|
1179
1162
|
*/
|
|
1180
|
-
constructor(
|
|
1181
|
-
|
|
1182
|
-
o(this, "callerInfo");
|
|
1183
|
-
this.schema = t;
|
|
1184
|
-
const { callerInfo: s, functionName: n } = E();
|
|
1185
|
-
this.callerInfo = s, this.functionName = n;
|
|
1163
|
+
constructor(s) {
|
|
1164
|
+
this.schema = s;
|
|
1186
1165
|
}
|
|
1187
1166
|
/**
|
|
1188
1167
|
* Checks if the provided data is valid according to the schema without throwing errors.
|
|
@@ -1198,14 +1177,13 @@ class Os {
|
|
|
1198
1177
|
* console.log(isValid); // false
|
|
1199
1178
|
* ```
|
|
1200
1179
|
*/
|
|
1201
|
-
isValid(
|
|
1202
|
-
return this.schema.safeParse(
|
|
1180
|
+
isValid(s) {
|
|
1181
|
+
return this.schema.safeParse(s).success;
|
|
1203
1182
|
}
|
|
1204
1183
|
/**
|
|
1205
1184
|
* Safely validates data and returns the complete parse result without throwing errors.
|
|
1206
1185
|
*
|
|
1207
1186
|
* @param {any} data - The data to validate.
|
|
1208
|
-
*
|
|
1209
1187
|
* @returns {z.ZodSafeParseResult<z.infer<T>>} The Zod safe parse result containing success status and data or error.
|
|
1210
1188
|
*
|
|
1211
1189
|
* @example
|
|
@@ -1220,17 +1198,15 @@ class Os {
|
|
|
1220
1198
|
* }
|
|
1221
1199
|
* ```
|
|
1222
1200
|
*/
|
|
1223
|
-
safeValidate(
|
|
1224
|
-
return this.schema.safeParse(
|
|
1201
|
+
safeValidate(s) {
|
|
1202
|
+
return this.schema.safeParse(s);
|
|
1225
1203
|
}
|
|
1226
1204
|
/**
|
|
1227
1205
|
* Validates data and returns the parsed result, throwing a ServerError on validation failure.
|
|
1228
1206
|
*
|
|
1229
1207
|
* @param {any} data - The data to validate.
|
|
1230
|
-
*
|
|
1231
|
-
* @returns {z.infer<T>} The validated and parsed data.
|
|
1232
|
-
*
|
|
1233
1208
|
* @throws {ServerError} When validation fails, with a formatted error message.
|
|
1209
|
+
* @returns {z.infer<T>} The validated and parsed data.
|
|
1234
1210
|
*
|
|
1235
1211
|
* @example
|
|
1236
1212
|
* ```typescript
|
|
@@ -1244,11 +1220,11 @@ class Os {
|
|
|
1244
1220
|
* }
|
|
1245
1221
|
* ```
|
|
1246
1222
|
*/
|
|
1247
|
-
validate(
|
|
1223
|
+
validate(s) {
|
|
1248
1224
|
try {
|
|
1249
|
-
return this.schema.parse(
|
|
1250
|
-
} catch (
|
|
1251
|
-
throw new
|
|
1225
|
+
return this.schema.parse(s);
|
|
1226
|
+
} catch (t) {
|
|
1227
|
+
throw new x(ns(t));
|
|
1252
1228
|
}
|
|
1253
1229
|
}
|
|
1254
1230
|
/**
|
|
@@ -1257,10 +1233,8 @@ class Os {
|
|
|
1257
1233
|
*
|
|
1258
1234
|
* @param {any} data - The form data to validate.
|
|
1259
1235
|
* @param {string} [message] - Optional custom error message.
|
|
1260
|
-
*
|
|
1261
|
-
* @returns {z.infer<T>} The validated and parsed form data.
|
|
1262
|
-
*
|
|
1263
1236
|
* @throws {UnprocessableEntity} When validation fails, with structured field errors for form handling.
|
|
1237
|
+
* @returns {z.infer<T>} The validated and parsed form data.
|
|
1264
1238
|
*
|
|
1265
1239
|
* @example
|
|
1266
1240
|
* ```typescript
|
|
@@ -1276,15 +1250,15 @@ class Os {
|
|
|
1276
1250
|
* }
|
|
1277
1251
|
* ```
|
|
1278
1252
|
*/
|
|
1279
|
-
formValidate(
|
|
1280
|
-
const n =
|
|
1253
|
+
formValidate(s, t) {
|
|
1254
|
+
const n = ts([s, this.schema]);
|
|
1281
1255
|
if (!n.success) {
|
|
1282
1256
|
const r = Object.keys(n.fieldErrors)[0];
|
|
1283
|
-
throw new
|
|
1257
|
+
throw new b({
|
|
1284
1258
|
fields: n.fields,
|
|
1285
1259
|
fieldErrors: n.fieldErrors,
|
|
1286
1260
|
data: { scrollTo: r },
|
|
1287
|
-
message:
|
|
1261
|
+
message: t
|
|
1288
1262
|
});
|
|
1289
1263
|
}
|
|
1290
1264
|
return n.data;
|
|
@@ -1295,10 +1269,8 @@ class Os {
|
|
|
1295
1269
|
*
|
|
1296
1270
|
* @param {any} data - The form data to validate.
|
|
1297
1271
|
* @param {string} [message] - Optional custom error message.
|
|
1298
|
-
*
|
|
1299
|
-
* @returns {Promise<z.infer<T>>} A promise that resolves to the validated and parsed form data.
|
|
1300
|
-
*
|
|
1301
1272
|
* @throws {UnprocessableEntity} When validation fails, with structured field errors for form handling.
|
|
1273
|
+
* @returns {Promise<z.infer<T>>} A promise that resolves to the validated and parsed form data.
|
|
1302
1274
|
*
|
|
1303
1275
|
* @example
|
|
1304
1276
|
* ```typescript
|
|
@@ -1314,194 +1286,209 @@ class Os {
|
|
|
1314
1286
|
* }
|
|
1315
1287
|
* ```
|
|
1316
1288
|
*/
|
|
1317
|
-
async formAsyncValidate(
|
|
1318
|
-
const n = await
|
|
1289
|
+
async formAsyncValidate(s, t) {
|
|
1290
|
+
const n = await es([s, this.schema]);
|
|
1319
1291
|
if (!n.success) {
|
|
1320
1292
|
const r = Object.keys(n.fieldErrors)[0];
|
|
1321
|
-
throw new
|
|
1293
|
+
throw new b({
|
|
1322
1294
|
fields: n.fields,
|
|
1323
1295
|
fieldErrors: n.fieldErrors,
|
|
1324
1296
|
data: { scrollTo: r },
|
|
1325
|
-
message:
|
|
1297
|
+
message: t
|
|
1326
1298
|
});
|
|
1327
1299
|
}
|
|
1328
1300
|
return n.data;
|
|
1329
1301
|
}
|
|
1330
1302
|
}
|
|
1331
|
-
|
|
1332
|
-
if (!e ||
|
|
1333
|
-
const
|
|
1334
|
-
return
|
|
1335
|
-
};
|
|
1336
|
-
function ns(e) {
|
|
1337
|
-
return e.length !== 14;
|
|
1303
|
+
function ks(e) {
|
|
1304
|
+
if (!(/^\d{5}-\d{3}$/.test(e) || /^\d{8}$/.test(e))) return !1;
|
|
1305
|
+
const t = R(e), n = 8, r = /^\d{8}$/.test(t);
|
|
1306
|
+
return t.length === n && r;
|
|
1338
1307
|
}
|
|
1339
1308
|
function rs(e) {
|
|
1340
|
-
|
|
1341
|
-
|
|
1309
|
+
return e.length !== 14;
|
|
1310
|
+
}
|
|
1311
|
+
function os(e) {
|
|
1312
|
+
const [s] = e;
|
|
1313
|
+
return [...e].every((t) => t === s);
|
|
1342
1314
|
}
|
|
1343
|
-
function
|
|
1344
|
-
let
|
|
1345
|
-
for (let r = 0; r <
|
|
1346
|
-
|
|
1347
|
-
const n =
|
|
1315
|
+
function N(e, s) {
|
|
1316
|
+
let t = 0;
|
|
1317
|
+
for (let r = 0; r < s.length; r++)
|
|
1318
|
+
t += parseInt(e[r]) * s[r];
|
|
1319
|
+
const n = t % 11;
|
|
1348
1320
|
return n < 2 ? 0 : 11 - n;
|
|
1349
1321
|
}
|
|
1350
|
-
function
|
|
1322
|
+
function is(e) {
|
|
1351
1323
|
return e.slice(12);
|
|
1352
1324
|
}
|
|
1353
|
-
|
|
1354
|
-
if (!e) return !1;
|
|
1355
|
-
const t =
|
|
1356
|
-
if (
|
|
1357
|
-
const
|
|
1358
|
-
|
|
1325
|
+
function ws(e) {
|
|
1326
|
+
if (!e || e.length > 18 || e.length < 14 || /\s/.test(e)) return !1;
|
|
1327
|
+
const t = R(e);
|
|
1328
|
+
if (rs(t) || os(t)) return !1;
|
|
1329
|
+
const n = t.slice(0, 12), r = N(n, [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]), i = N(
|
|
1330
|
+
n + r,
|
|
1359
1331
|
[6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
|
|
1360
1332
|
);
|
|
1361
|
-
return
|
|
1362
|
-
}
|
|
1333
|
+
return is(t) === `${r}${i}`;
|
|
1334
|
+
}
|
|
1363
1335
|
function as(e) {
|
|
1364
1336
|
return e.length !== 11;
|
|
1365
1337
|
}
|
|
1366
1338
|
function us(e) {
|
|
1367
|
-
const [
|
|
1368
|
-
return [...e].every((
|
|
1339
|
+
const [s] = e;
|
|
1340
|
+
return [...e].every((t) => t === s);
|
|
1369
1341
|
}
|
|
1370
|
-
function
|
|
1371
|
-
let
|
|
1342
|
+
function E(e, s) {
|
|
1343
|
+
let t = 0;
|
|
1372
1344
|
for (const r of e)
|
|
1373
|
-
|
|
1374
|
-
const n =
|
|
1345
|
+
s > 1 && (t += parseInt(r) * s--);
|
|
1346
|
+
const n = t % 11;
|
|
1375
1347
|
return n < 2 ? 0 : 11 - n;
|
|
1376
1348
|
}
|
|
1377
|
-
function
|
|
1349
|
+
function cs(e) {
|
|
1378
1350
|
return e.slice(9);
|
|
1379
1351
|
}
|
|
1380
|
-
|
|
1381
|
-
if (!e) return !1;
|
|
1382
|
-
const t =
|
|
1352
|
+
function Js(e) {
|
|
1353
|
+
if (!e || e.length > 14 || e.length < 11 || /\s/.test(e)) return !1;
|
|
1354
|
+
const t = R(e);
|
|
1383
1355
|
if (as(t) || us(t)) return !1;
|
|
1384
|
-
const
|
|
1385
|
-
return
|
|
1386
|
-
}
|
|
1387
|
-
|
|
1388
|
-
const
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
const f = u % 4 === 0 && u % 100 !== 0 || u % 400 === 0;
|
|
1408
|
-
if (i > (f ? 29 : 28)) return !1;
|
|
1409
|
-
} else if (i > d[l - 1])
|
|
1356
|
+
const n = E(t, 10), r = E(t, 11);
|
|
1357
|
+
return cs(t) === `${n}${r}`;
|
|
1358
|
+
}
|
|
1359
|
+
function js(e, s) {
|
|
1360
|
+
const t = (s == null ? void 0 : s.inputFormat) || "brazilianDate", n = (s == null ? void 0 : s.minYear) || 1900, r = (s == null ? void 0 : s.maxYear) || 3e3, i = new J();
|
|
1361
|
+
i.validateInputFormat(t);
|
|
1362
|
+
let a, u, o;
|
|
1363
|
+
const h = e.split(/[-/]/).map(Number);
|
|
1364
|
+
if (h.length !== 3) return !1;
|
|
1365
|
+
try {
|
|
1366
|
+
switch (t) {
|
|
1367
|
+
case "brazilianDate":
|
|
1368
|
+
[a, u, o] = h, i.validateDateParts(o, u, a);
|
|
1369
|
+
break;
|
|
1370
|
+
case "isoDate":
|
|
1371
|
+
[u, a, o] = h, i.validateDateParts(o, u, a);
|
|
1372
|
+
break;
|
|
1373
|
+
case "timestamp":
|
|
1374
|
+
[o, u, a] = h, i.validateDateParts(o, u, a);
|
|
1375
|
+
break;
|
|
1376
|
+
}
|
|
1377
|
+
return !(o < n || o > r);
|
|
1378
|
+
} catch {
|
|
1410
1379
|
return !1;
|
|
1411
|
-
|
|
1412
|
-
};
|
|
1413
|
-
function cs(e) {
|
|
1414
|
-
return /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(e);
|
|
1380
|
+
}
|
|
1415
1381
|
}
|
|
1416
1382
|
function hs(e) {
|
|
1417
|
-
return
|
|
1383
|
+
return /^[a-zA-Z0-9.!$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(e);
|
|
1418
1384
|
}
|
|
1419
1385
|
function ls(e) {
|
|
1420
|
-
return !(e.length === 0 || e.length >
|
|
1386
|
+
return !(e.length === 0 || e.length > 64 || e.startsWith(".") || e.endsWith(".") || e.includes("..") || !/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/.test(e));
|
|
1421
1387
|
}
|
|
1422
1388
|
function fs(e) {
|
|
1389
|
+
return !(e.length === 0 || e.length > 63 || e.startsWith("-") || e.endsWith("-") || !/^[a-zA-Z0-9-]+$/.test(e));
|
|
1390
|
+
}
|
|
1391
|
+
function ms(e) {
|
|
1423
1392
|
if (e.length === 0 || e.length > 253 || e.startsWith(".") || e.endsWith(".") || e.startsWith("-") || e.endsWith("-"))
|
|
1424
1393
|
return !1;
|
|
1425
|
-
const
|
|
1426
|
-
if (
|
|
1427
|
-
for (const n of
|
|
1428
|
-
const
|
|
1429
|
-
return !(
|
|
1394
|
+
const s = e.split(".");
|
|
1395
|
+
if (s.length < 2) return !1;
|
|
1396
|
+
for (const n of s) if (!fs(n)) return !1;
|
|
1397
|
+
const t = s[s.length - 1];
|
|
1398
|
+
return !(t.length < 2 || !/^[a-zA-Z]+$/.test(t));
|
|
1430
1399
|
}
|
|
1431
1400
|
function ds(e) {
|
|
1432
|
-
const
|
|
1433
|
-
if (
|
|
1434
|
-
const [
|
|
1435
|
-
return !(!
|
|
1401
|
+
const s = e.split("@");
|
|
1402
|
+
if (s.length !== 2) return !1;
|
|
1403
|
+
const [t, n] = s;
|
|
1404
|
+
return !(!ls(t) || !ms(n));
|
|
1436
1405
|
}
|
|
1437
1406
|
function ps(e) {
|
|
1438
|
-
const
|
|
1439
|
-
return
|
|
1407
|
+
const s = e.split("@");
|
|
1408
|
+
return s.length === 2 ? s[1].toLowerCase() : null;
|
|
1409
|
+
}
|
|
1410
|
+
const ys = ["MX", "A", "AAAA"];
|
|
1411
|
+
async function gs(e, s) {
|
|
1412
|
+
var t, n;
|
|
1413
|
+
try {
|
|
1414
|
+
return await ((n = (t = j) == null ? void 0 : t.promises) == null ? void 0 : n.resolve(e, s)), !0;
|
|
1415
|
+
} catch {
|
|
1416
|
+
return !1;
|
|
1417
|
+
}
|
|
1440
1418
|
}
|
|
1441
|
-
|
|
1419
|
+
async function Ts(e) {
|
|
1420
|
+
for (const s of ys)
|
|
1421
|
+
if (await gs(e, s)) return !0;
|
|
1422
|
+
return !1;
|
|
1423
|
+
}
|
|
1424
|
+
async function _s(e) {
|
|
1442
1425
|
if (!e || typeof e != "string") return !1;
|
|
1443
|
-
const
|
|
1444
|
-
|
|
1445
|
-
|
|
1426
|
+
const s = e.trim();
|
|
1427
|
+
if (!hs(s) || !ds(s)) return !1;
|
|
1428
|
+
const t = ps(s);
|
|
1429
|
+
return t ? await Ts(t) : !1;
|
|
1430
|
+
}
|
|
1431
|
+
function Is(e) {
|
|
1446
1432
|
if (!e) return !1;
|
|
1447
|
-
const
|
|
1433
|
+
const s = e.length >= 8, t = /[A-Z]/.test(e), n = /[a-z]/.test(e), r = /\d/.test(e), i = /[!@#$%^&*(),.?":;{}|<>_\-+=~`[\]\\\/]/.test(
|
|
1448
1434
|
e
|
|
1449
1435
|
);
|
|
1450
1436
|
return [
|
|
1451
|
-
t,
|
|
1452
1437
|
s,
|
|
1438
|
+
t,
|
|
1453
1439
|
n,
|
|
1454
1440
|
r,
|
|
1455
|
-
|
|
1456
|
-
].every((
|
|
1457
|
-
}
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1441
|
+
i
|
|
1442
|
+
].every((a) => a);
|
|
1443
|
+
}
|
|
1444
|
+
function Us(e) {
|
|
1445
|
+
for (const s of _) {
|
|
1446
|
+
const t = s.code, n = s.prefix ? `-${s.prefix}` : "", r = s.mask.replace(/[^_]/g, "").length;
|
|
1447
|
+
if (s.iso === "BR") {
|
|
1448
|
+
if (new RegExp(`^\\${t} \\d{2}9?\\d{8}$`).test(e)) return !0;
|
|
1462
1449
|
continue;
|
|
1463
1450
|
}
|
|
1464
|
-
if (new RegExp(`^\\${
|
|
1451
|
+
if (new RegExp(`^\\${t}${n} \\d{${r}}$`).test(e)) return !0;
|
|
1465
1452
|
}
|
|
1466
1453
|
return !1;
|
|
1467
|
-
}
|
|
1454
|
+
}
|
|
1455
|
+
function Cs(e) {
|
|
1468
1456
|
if (!e || !/^[0-9a-zA-Z.-]+$/.test(e)) return !1;
|
|
1469
|
-
const
|
|
1470
|
-
return
|
|
1471
|
-
}
|
|
1457
|
+
const t = e.replace(/[^a-zA-Z0-9]/g, "");
|
|
1458
|
+
return t.length < 7 || t.length > 9 ? !1 : /^[0-9]{7,8}[0-9Xx]?$/.test(t);
|
|
1459
|
+
}
|
|
1472
1460
|
export {
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1461
|
+
Es as ApiService,
|
|
1462
|
+
U as BadGateway,
|
|
1463
|
+
T as BadRequest,
|
|
1464
|
+
C as Conflict,
|
|
1465
|
+
F as Created,
|
|
1466
|
+
S as DebugService,
|
|
1467
|
+
A as Forbidden,
|
|
1468
|
+
z as Found,
|
|
1469
|
+
v as LogService,
|
|
1470
|
+
M as NoContent,
|
|
1483
1471
|
q as NotFound,
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
Us as validateRg
|
|
1472
|
+
H as NotImplemented,
|
|
1473
|
+
Ps as SchemaValidator,
|
|
1474
|
+
x as ServerError,
|
|
1475
|
+
V as Success,
|
|
1476
|
+
L as Unauthorized,
|
|
1477
|
+
b as UnprocessableEntity,
|
|
1478
|
+
Z as Updated,
|
|
1479
|
+
vs as decodeRequestBody,
|
|
1480
|
+
$s as decodeRequestErrorMessage,
|
|
1481
|
+
Bs as errorHandler,
|
|
1482
|
+
p as flushDebugLogs,
|
|
1483
|
+
es as formAsyncParse,
|
|
1484
|
+
ts as formParse,
|
|
1485
|
+
Os as getScopedParams,
|
|
1486
|
+
ks as validateCep,
|
|
1487
|
+
ws as validateCnpj,
|
|
1488
|
+
Js as validateCpf,
|
|
1489
|
+
js as validateDate,
|
|
1490
|
+
_s as validateEmail,
|
|
1491
|
+
Is as validatePassword,
|
|
1492
|
+
Us as validatePhone,
|
|
1493
|
+
Cs as validateRg
|
|
1507
1494
|
};
|