@arkyn/server 3.0.1-beta.7 → 3.0.1-beta.71
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/README.md +368 -65
- package/dist/api/arkynLogRequest.d.ts +1 -1
- package/dist/api/arkynLogRequest.d.ts.map +1 -1
- package/dist/api/arkynLogRequest.js +14 -13
- package/dist/api/makeRequest.d.ts +1 -1
- package/dist/api/makeRequest.d.ts.map +1 -1
- package/dist/api/makeRequest.js +9 -8
- package/dist/bundle.js +1216 -0
- package/dist/bundle.umd.cjs +10 -0
- package/dist/http/badResponses/_badResponse.d.ts +11 -0
- package/dist/http/badResponses/_badResponse.d.ts.map +1 -0
- package/dist/http/badResponses/_badResponse.js +20 -0
- package/dist/http/badResponses/badGateway.d.ts +2 -1
- package/dist/http/badResponses/badGateway.d.ts.map +1 -1
- package/dist/http/badResponses/badGateway.js +9 -3
- package/dist/http/badResponses/badRequest.d.ts +2 -1
- package/dist/http/badResponses/badRequest.d.ts.map +1 -1
- package/dist/http/badResponses/badRequest.js +9 -3
- package/dist/http/badResponses/conflict.d.ts +2 -1
- package/dist/http/badResponses/conflict.d.ts.map +1 -1
- package/dist/http/badResponses/conflict.js +9 -3
- package/dist/http/badResponses/forbidden.d.ts +2 -1
- package/dist/http/badResponses/forbidden.d.ts.map +1 -1
- package/dist/http/badResponses/forbidden.js +9 -3
- package/dist/http/badResponses/notFound.d.ts +2 -1
- package/dist/http/badResponses/notFound.d.ts.map +1 -1
- package/dist/http/badResponses/notFound.js +9 -3
- package/dist/http/badResponses/notImplemented.d.ts +2 -1
- package/dist/http/badResponses/notImplemented.d.ts.map +1 -1
- package/dist/http/badResponses/notImplemented.js +9 -3
- package/dist/http/badResponses/serverError.d.ts +2 -1
- package/dist/http/badResponses/serverError.d.ts.map +1 -1
- package/dist/http/badResponses/serverError.js +9 -3
- package/dist/http/badResponses/unauthorized.d.ts +2 -1
- package/dist/http/badResponses/unauthorized.d.ts.map +1 -1
- package/dist/http/badResponses/unauthorized.js +9 -3
- package/dist/http/badResponses/unprocessableEntity.d.ts +3 -2
- package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
- package/dist/http/badResponses/unprocessableEntity.js +9 -4
- package/dist/http/successResponses/_successResponse.d.ts +22 -0
- package/dist/http/successResponses/_successResponse.d.ts.map +1 -0
- package/dist/http/successResponses/_successResponse.js +37 -0
- package/dist/http/successResponses/created.d.ts +2 -1
- package/dist/http/successResponses/created.d.ts.map +1 -1
- package/dist/http/successResponses/created.js +4 -1
- package/dist/http/successResponses/found.d.ts +2 -1
- package/dist/http/successResponses/found.d.ts.map +1 -1
- package/dist/http/successResponses/found.js +4 -1
- package/dist/http/successResponses/noContent.d.ts +2 -1
- package/dist/http/successResponses/noContent.d.ts.map +1 -1
- package/dist/http/successResponses/noContent.js +4 -1
- package/dist/http/successResponses/success.d.ts +2 -1
- package/dist/http/successResponses/success.d.ts.map +1 -1
- package/dist/http/successResponses/success.js +4 -1
- package/dist/http/successResponses/updated.d.ts +2 -1
- package/dist/http/successResponses/updated.d.ts.map +1 -1
- package/dist/http/successResponses/updated.js +4 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/{config/apiInstance.d.ts → services/apiService.d.ts} +25 -21
- package/dist/services/apiService.d.ts.map +1 -0
- package/dist/{config/apiInstance.js → services/apiService.js} +45 -23
- package/dist/{config/arkynLogInstance.d.ts → services/arkynLogService.d.ts} +5 -5
- package/dist/services/arkynLogService.d.ts.map +1 -0
- package/dist/{config/arkynLogInstance.js → services/arkynLogService.js} +4 -5
- package/dist/services/debugService.d.ts +54 -0
- package/dist/services/debugService.d.ts.map +1 -0
- package/dist/services/debugService.js +57 -0
- package/dist/services/flushDebugLogs.d.ts +8 -0
- package/dist/services/flushDebugLogs.d.ts.map +1 -0
- package/dist/services/flushDebugLogs.js +20 -0
- package/dist/services/formParse.d.ts +3 -3
- package/dist/services/formParse.d.ts.map +1 -1
- package/dist/services/formParse.js +7 -5
- package/dist/services/getCaller.d.ts.map +1 -1
- package/dist/services/getCaller.js +9 -14
- package/dist/services/measureRouteExecution.d.ts +3 -0
- package/dist/services/measureRouteExecution.d.ts.map +1 -0
- package/dist/services/measureRouteExecution.js +24 -0
- package/dist/services/schemaValidator.d.ts +3 -3
- package/dist/services/schemaValidator.d.ts.map +1 -1
- package/dist/services/schemaValidator.js +2 -4
- package/package.json +33 -18
- package/dist/config/apiInstance.d.ts.map +0 -1
- package/dist/config/arkynLogInstance.d.ts.map +0 -1
- package/dist/services/httpDebug.d.ts +0 -35
- package/dist/services/httpDebug.d.ts.map +0 -1
- package/dist/services/httpDebug.js +0 -52
- package/src/api/arkynLogRequest.ts +0 -118
- package/src/api/deleteRequest.ts +0 -22
- package/src/api/getRequest.ts +0 -20
- package/src/api/makeRequest.ts +0 -122
- package/src/api/patchRequest.ts +0 -22
- package/src/api/postRequest.ts +0 -22
- package/src/api/putRequest.ts +0 -22
- package/src/config/apiInstance.ts +0 -148
- package/src/config/arkynLogInstance.ts +0 -75
- package/src/http/badResponses/badGateway.ts +0 -63
- package/src/http/badResponses/badRequest.ts +0 -63
- package/src/http/badResponses/conflict.ts +0 -63
- package/src/http/badResponses/forbidden.ts +0 -63
- package/src/http/badResponses/notFound.ts +0 -63
- package/src/http/badResponses/notImplemented.ts +0 -63
- package/src/http/badResponses/serverError.ts +0 -63
- package/src/http/badResponses/unauthorized.ts +0 -63
- package/src/http/badResponses/unprocessableEntity.ts +0 -79
- package/src/http/successResponses/created.ts +0 -64
- package/src/http/successResponses/found.ts +0 -67
- package/src/http/successResponses/noContent.ts +0 -42
- package/src/http/successResponses/success.ts +0 -64
- package/src/http/successResponses/updated.ts +0 -64
- package/src/index.ts +0 -31
- package/src/mapper/arkynLogRequestMapper.ts +0 -73
- package/src/services/decodeErrorMessageFromRequest.ts +0 -36
- package/src/services/decodeRequestBody.ts +0 -43
- package/src/services/errorHandler.ts +0 -99
- package/src/services/formParse.ts +0 -83
- package/src/services/getCaller.ts +0 -82
- package/src/services/getScopedParams.ts +0 -43
- package/src/services/httpDebug.ts +0 -61
- package/src/services/schemaValidator.ts +0 -66
- package/src/types/ApiResponseDTO.ts +0 -19
- package/tsconfig.json +0 -21
- package/vitest.config.ts +0 -5
package/dist/bundle.js
ADDED
|
@@ -0,0 +1,1216 @@
|
|
|
1
|
+
var U = Object.defineProperty;
|
|
2
|
+
var I = (n, t, s) => t in n ? U(n, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : n[t] = s;
|
|
3
|
+
var o = (n, t, s) => I(n, typeof t != "symbol" ? t + "" : t, s);
|
|
4
|
+
function p(n) {
|
|
5
|
+
var s;
|
|
6
|
+
if (process.env.NODE_ENV === "development" || ((s = process.env) == null ? void 0 : s.SHOW_ERRORS_IN_CONSOLE) === "true") {
|
|
7
|
+
const u = `${{
|
|
8
|
+
yellow: "\x1B[33m",
|
|
9
|
+
cyan: "\x1B[36m",
|
|
10
|
+
red: "\x1B[31m",
|
|
11
|
+
green: "\x1B[32m"
|
|
12
|
+
}[n.scheme]}[${n.name}]\x1B[0m`;
|
|
13
|
+
let c = `
|
|
14
|
+
`;
|
|
15
|
+
n.debugs.forEach((h) => {
|
|
16
|
+
c += `${u} ${h.trim()}
|
|
17
|
+
`;
|
|
18
|
+
}), console.log(c);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const k = {};
|
|
22
|
+
class S {
|
|
23
|
+
/**
|
|
24
|
+
* Sets the file name to be ignored during stack trace analysis.
|
|
25
|
+
*
|
|
26
|
+
* This method configures the debug service to skip specific files when
|
|
27
|
+
* determining the actual caller of a function. This is useful when you have
|
|
28
|
+
* adapter or wrapper functions that you want to be transparent in the debug output.
|
|
29
|
+
*
|
|
30
|
+
* @param file - The name of the file to ignore in stack traces (e.g., "httpAdapter.ts")
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // Ignore the HTTP adapter file so debug shows the actual business logic caller
|
|
35
|
+
* DebugService.setIgnoreFile("httpAdapter.ts");
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
static setIgnoreFile(t) {
|
|
39
|
+
this.ignoreFiles.push(t);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Clears all configured ignore files.
|
|
43
|
+
*
|
|
44
|
+
* This method resets the ignore file configuration, allowing all files to be
|
|
45
|
+
* considered in stack trace analysis again.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* // Clear all ignore file configurations
|
|
50
|
+
* DebugService.clearIgnoreFiles();
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
static clearIgnoreFiles() {
|
|
54
|
+
this.ignoreFiles = [];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The name of the file to ignore when analyzing the stack trace.
|
|
59
|
+
* When set, the `getCaller` function will skip stack frames containing this file name.
|
|
60
|
+
*/
|
|
61
|
+
o(S, "ignoreFiles", []);
|
|
62
|
+
function x() {
|
|
63
|
+
const n = process.cwd(), e = (new Error().stack || "").split(`
|
|
64
|
+
`).map((a) => a.trim()), r = S.ignoreFiles;
|
|
65
|
+
let u = 2;
|
|
66
|
+
for (; u < e.length && (e[u].includes("node:internal") || e[u].includes("/node_modules/")); )
|
|
67
|
+
u++;
|
|
68
|
+
if (r.length > 0)
|
|
69
|
+
for (; u < e.length && r.some(
|
|
70
|
+
(a) => e[u].includes(a)
|
|
71
|
+
); )
|
|
72
|
+
u++;
|
|
73
|
+
const c = e[u] || "";
|
|
74
|
+
let h = "Unknown function", i = "Unknown caller";
|
|
75
|
+
const l = c.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);
|
|
76
|
+
if (l)
|
|
77
|
+
h = l[1], i = l[2];
|
|
78
|
+
else {
|
|
79
|
+
const a = c.match(/at\s+(.+)/);
|
|
80
|
+
if (a) {
|
|
81
|
+
i = a[1];
|
|
82
|
+
const d = i.match(/at\s+([^(\s]+)\s+/);
|
|
83
|
+
d && d[1] !== "new" && (h = d[1]);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
i.includes("(") && (i = i.substring(
|
|
87
|
+
i.indexOf("(") + 1,
|
|
88
|
+
i.lastIndexOf(")")
|
|
89
|
+
)), i = i.split(":").slice(0, -2).join(":");
|
|
90
|
+
try {
|
|
91
|
+
i = k.relative(n, i);
|
|
92
|
+
} catch {
|
|
93
|
+
}
|
|
94
|
+
return { functionName: h, callerInfo: i };
|
|
95
|
+
}
|
|
96
|
+
class y {
|
|
97
|
+
onDebug(t) {
|
|
98
|
+
const { name: s, body: e, cause: r, message: u } = t, c = [], { callerInfo: h, functionName: i } = x();
|
|
99
|
+
c.push(`${s} initialized`), c.push(`Caller Function: ${i}`), c.push(`Caller Location: ${h}`), u && c.push(`Message: ${u}`), e && c.push(`Body: ${JSON.stringify(e, null, 2)}`), r && c.push(`Cause: ${JSON.stringify(r, null, 2)}`), p({ scheme: "red", name: "ARKYN-BAD-RESPONSE-DEBUG", debugs: c });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
class j extends y {
|
|
103
|
+
/**
|
|
104
|
+
* Creates an instance of the `BadGateway` class.
|
|
105
|
+
*
|
|
106
|
+
* @param message - A descriptive message explaining the cause of the error.
|
|
107
|
+
* @param cause - Optional additional information about the cause of the error.
|
|
108
|
+
*/
|
|
109
|
+
constructor(s, e) {
|
|
110
|
+
super();
|
|
111
|
+
o(this, "body");
|
|
112
|
+
o(this, "cause");
|
|
113
|
+
o(this, "status", 502);
|
|
114
|
+
o(this, "statusText");
|
|
115
|
+
this.body = { name: "BadGateway", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug({
|
|
116
|
+
name: "BadGateway",
|
|
117
|
+
body: this.body,
|
|
118
|
+
cause: this.cause,
|
|
119
|
+
message: this.statusText
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Converts the `BadGateway` instance into a `Response` object with a JSON body.
|
|
124
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
125
|
+
*
|
|
126
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
127
|
+
*/
|
|
128
|
+
toResponse() {
|
|
129
|
+
const s = {
|
|
130
|
+
headers: { "Content-Type": "application/json" },
|
|
131
|
+
status: this.status,
|
|
132
|
+
statusText: this.statusText
|
|
133
|
+
};
|
|
134
|
+
return new Response(JSON.stringify(this.body), s);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Converts the `BadGateway` instance into a `Response` object using the `Response.json` method.
|
|
138
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
139
|
+
*
|
|
140
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
141
|
+
*/
|
|
142
|
+
toJson() {
|
|
143
|
+
const s = {
|
|
144
|
+
status: this.status,
|
|
145
|
+
statusText: this.statusText
|
|
146
|
+
};
|
|
147
|
+
return Response.json(this.body, s);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
class b extends y {
|
|
151
|
+
/**
|
|
152
|
+
* Creates an instance of the `BadRequest` class.
|
|
153
|
+
*
|
|
154
|
+
* @param message - A descriptive message explaining the cause of the error.
|
|
155
|
+
* @param cause - Optional additional information about the cause of the error.
|
|
156
|
+
*/
|
|
157
|
+
constructor(s, e) {
|
|
158
|
+
super();
|
|
159
|
+
o(this, "body");
|
|
160
|
+
o(this, "cause");
|
|
161
|
+
o(this, "status", 400);
|
|
162
|
+
o(this, "statusText");
|
|
163
|
+
this.body = { name: "BadRequest", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug({
|
|
164
|
+
name: "BadRequest",
|
|
165
|
+
body: this.body,
|
|
166
|
+
cause: this.cause,
|
|
167
|
+
message: this.statusText
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Converts the `BadRequest` instance into a `Response` object with a JSON body.
|
|
172
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
173
|
+
*
|
|
174
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
175
|
+
*/
|
|
176
|
+
toResponse() {
|
|
177
|
+
const s = {
|
|
178
|
+
headers: { "Content-Type": "application/json" },
|
|
179
|
+
status: this.status,
|
|
180
|
+
statusText: this.statusText
|
|
181
|
+
};
|
|
182
|
+
return new Response(JSON.stringify(this.body), s);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Converts the `BadRequest` instance into a `Response` object using the `Response.json` method.
|
|
186
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
187
|
+
*
|
|
188
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
189
|
+
*/
|
|
190
|
+
toJson() {
|
|
191
|
+
const s = {
|
|
192
|
+
status: this.status,
|
|
193
|
+
statusText: this.statusText
|
|
194
|
+
};
|
|
195
|
+
return Response.json(this.body, s);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
class J extends y {
|
|
199
|
+
/**
|
|
200
|
+
* Creates an instance of the `Conflict` class.
|
|
201
|
+
*
|
|
202
|
+
* @param message - A descriptive message explaining the cause of the conflict.
|
|
203
|
+
* @param cause - Optional additional information about the cause of the conflict.
|
|
204
|
+
*/
|
|
205
|
+
constructor(s, e) {
|
|
206
|
+
super();
|
|
207
|
+
o(this, "body");
|
|
208
|
+
o(this, "cause");
|
|
209
|
+
o(this, "status", 409);
|
|
210
|
+
o(this, "statusText");
|
|
211
|
+
this.body = { name: "Conflict", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug({
|
|
212
|
+
name: "Conflict",
|
|
213
|
+
body: this.body,
|
|
214
|
+
cause: this.cause,
|
|
215
|
+
message: this.statusText
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Converts the `Conflict` instance into a `Response` object with a JSON body.
|
|
220
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
221
|
+
*
|
|
222
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
223
|
+
*/
|
|
224
|
+
toResponse() {
|
|
225
|
+
const s = {
|
|
226
|
+
headers: { "Content-Type": "application/json" },
|
|
227
|
+
status: this.status,
|
|
228
|
+
statusText: this.statusText
|
|
229
|
+
};
|
|
230
|
+
return new Response(JSON.stringify(this.body), s);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Converts the `Conflict` instance into a `Response` object using the `Response.json` method.
|
|
234
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
235
|
+
*
|
|
236
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
237
|
+
*/
|
|
238
|
+
toJson() {
|
|
239
|
+
const s = {
|
|
240
|
+
status: this.status,
|
|
241
|
+
statusText: this.statusText
|
|
242
|
+
};
|
|
243
|
+
return Response.json(this.body, s);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
class D extends y {
|
|
247
|
+
/**
|
|
248
|
+
* Creates an instance of the `Forbidden` class.
|
|
249
|
+
*
|
|
250
|
+
* @param message - A descriptive message explaining why access is forbidden.
|
|
251
|
+
* @param cause - Optional additional information about the cause of the error.
|
|
252
|
+
*/
|
|
253
|
+
constructor(s, e) {
|
|
254
|
+
super();
|
|
255
|
+
o(this, "body");
|
|
256
|
+
o(this, "cause");
|
|
257
|
+
o(this, "status", 403);
|
|
258
|
+
o(this, "statusText");
|
|
259
|
+
this.body = { name: "Forbidden", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug({
|
|
260
|
+
name: "Forbidden",
|
|
261
|
+
body: this.body,
|
|
262
|
+
cause: this.cause,
|
|
263
|
+
message: this.statusText
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Converts the `Forbidden` instance into a `Response` object with a JSON body.
|
|
268
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
269
|
+
*
|
|
270
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
271
|
+
*/
|
|
272
|
+
toResponse() {
|
|
273
|
+
const s = {
|
|
274
|
+
headers: { "Content-Type": "application/json" },
|
|
275
|
+
status: this.status,
|
|
276
|
+
statusText: this.statusText
|
|
277
|
+
};
|
|
278
|
+
return new Response(JSON.stringify(this.body), s);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Converts the `Forbidden` instance into a `Response` object using the `Response.json` method.
|
|
282
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
283
|
+
*
|
|
284
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
285
|
+
*/
|
|
286
|
+
toJson() {
|
|
287
|
+
const s = {
|
|
288
|
+
status: this.status,
|
|
289
|
+
statusText: this.statusText
|
|
290
|
+
};
|
|
291
|
+
return Response.json(this.body, s);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
class C extends y {
|
|
295
|
+
/**
|
|
296
|
+
* Creates an instance of the `NotFound` class.
|
|
297
|
+
*
|
|
298
|
+
* @param message - A descriptive message explaining the reason the resource was not found.
|
|
299
|
+
* @param cause - Optional additional information about the cause of the error.
|
|
300
|
+
*/
|
|
301
|
+
constructor(s, e) {
|
|
302
|
+
super();
|
|
303
|
+
o(this, "body");
|
|
304
|
+
o(this, "cause");
|
|
305
|
+
o(this, "status", 404);
|
|
306
|
+
o(this, "statusText");
|
|
307
|
+
this.body = { name: "NotFound", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug({
|
|
308
|
+
name: "NotFound",
|
|
309
|
+
body: this.body,
|
|
310
|
+
cause: this.cause,
|
|
311
|
+
message: this.statusText
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Converts the `NotFound` instance into a `Response` object with a JSON body.
|
|
316
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
317
|
+
*
|
|
318
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
319
|
+
*/
|
|
320
|
+
toResponse() {
|
|
321
|
+
const s = {
|
|
322
|
+
headers: { "Content-Type": "application/json" },
|
|
323
|
+
status: this.status,
|
|
324
|
+
statusText: this.statusText
|
|
325
|
+
};
|
|
326
|
+
return new Response(JSON.stringify(this.body), s);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Converts the `NotFound` instance into a `Response` object using the `Response.json` method.
|
|
330
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
331
|
+
*
|
|
332
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
333
|
+
*/
|
|
334
|
+
toJson() {
|
|
335
|
+
const s = {
|
|
336
|
+
status: this.status,
|
|
337
|
+
statusText: this.statusText
|
|
338
|
+
};
|
|
339
|
+
return Response.json(this.body, s);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
class B extends y {
|
|
343
|
+
/**
|
|
344
|
+
* Creates an instance of the `NotImplemented` class.
|
|
345
|
+
*
|
|
346
|
+
* @param message - A descriptive message explaining why the functionality is not implemented.
|
|
347
|
+
* @param cause - Optional additional information about the cause of the error.
|
|
348
|
+
*/
|
|
349
|
+
constructor(s, e) {
|
|
350
|
+
super();
|
|
351
|
+
o(this, "body");
|
|
352
|
+
o(this, "cause");
|
|
353
|
+
o(this, "status", 501);
|
|
354
|
+
o(this, "statusText");
|
|
355
|
+
this.body = { name: "NotImplemented", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug({
|
|
356
|
+
name: "NotImplemented",
|
|
357
|
+
body: this.body,
|
|
358
|
+
cause: this.cause,
|
|
359
|
+
message: this.statusText
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Converts the `NotImplemented` instance into a `Response` object with a JSON body.
|
|
364
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
365
|
+
*
|
|
366
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
367
|
+
*/
|
|
368
|
+
toResponse() {
|
|
369
|
+
const s = {
|
|
370
|
+
headers: { "Content-Type": "application/json" },
|
|
371
|
+
status: this.status,
|
|
372
|
+
statusText: this.statusText
|
|
373
|
+
};
|
|
374
|
+
return new Response(JSON.stringify(this.body), s);
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Converts the `NotImplemented` instance into a `Response` object using the `Response.json` method.
|
|
378
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
379
|
+
*
|
|
380
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
381
|
+
*/
|
|
382
|
+
toJson() {
|
|
383
|
+
const s = {
|
|
384
|
+
status: this.status,
|
|
385
|
+
statusText: this.statusText
|
|
386
|
+
};
|
|
387
|
+
return Response.json(this.body, s);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
class m extends y {
|
|
391
|
+
/**
|
|
392
|
+
* Creates an instance of the `ServerError` class.
|
|
393
|
+
*
|
|
394
|
+
* @param message - A descriptive message explaining the cause of the server error.
|
|
395
|
+
* @param cause - Optional additional information about the cause of the error.
|
|
396
|
+
*/
|
|
397
|
+
constructor(s, e) {
|
|
398
|
+
super();
|
|
399
|
+
o(this, "body");
|
|
400
|
+
o(this, "cause");
|
|
401
|
+
o(this, "status", 500);
|
|
402
|
+
o(this, "statusText");
|
|
403
|
+
this.body = { name: "ServerError", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug({
|
|
404
|
+
name: "ServerError",
|
|
405
|
+
body: this.body,
|
|
406
|
+
cause: this.cause,
|
|
407
|
+
message: this.statusText
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Converts the `ServerError` instance into a `Response` object with a JSON body.
|
|
412
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
413
|
+
*
|
|
414
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
415
|
+
*/
|
|
416
|
+
toResponse() {
|
|
417
|
+
const s = {
|
|
418
|
+
headers: { "Content-Type": "application/json" },
|
|
419
|
+
status: this.status,
|
|
420
|
+
statusText: this.statusText
|
|
421
|
+
};
|
|
422
|
+
return new Response(JSON.stringify(this.body), s);
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Converts the `ServerError` instance into a `Response` object using the `Response.json` method.
|
|
426
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
427
|
+
*
|
|
428
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
429
|
+
*/
|
|
430
|
+
toJson() {
|
|
431
|
+
const s = {
|
|
432
|
+
status: this.status,
|
|
433
|
+
statusText: this.statusText
|
|
434
|
+
};
|
|
435
|
+
return Response.json(this.body, s);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
class q extends y {
|
|
439
|
+
/**
|
|
440
|
+
* Creates an instance of the `Unauthorized` class.
|
|
441
|
+
*
|
|
442
|
+
* @param message - A descriptive message explaining why the request is unauthorized.
|
|
443
|
+
* @param cause - Optional additional information about the cause of the error.
|
|
444
|
+
*/
|
|
445
|
+
constructor(s, e) {
|
|
446
|
+
super();
|
|
447
|
+
o(this, "body");
|
|
448
|
+
o(this, "cause");
|
|
449
|
+
o(this, "status", 401);
|
|
450
|
+
o(this, "statusText");
|
|
451
|
+
this.body = { name: "Unauthorized", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug({
|
|
452
|
+
name: "Unauthorized",
|
|
453
|
+
body: this.body,
|
|
454
|
+
cause: this.cause,
|
|
455
|
+
message: this.statusText
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Converts the `Unauthorized` instance into a `Response` object with a JSON body.
|
|
460
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
461
|
+
*
|
|
462
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
463
|
+
*/
|
|
464
|
+
toResponse() {
|
|
465
|
+
const s = {
|
|
466
|
+
headers: { "Content-Type": "application/json" },
|
|
467
|
+
status: this.status,
|
|
468
|
+
statusText: this.statusText
|
|
469
|
+
};
|
|
470
|
+
return new Response(JSON.stringify(this.body), s);
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Converts the `Unauthorized` instance into a `Response` object using the `Response.json` method.
|
|
474
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
475
|
+
*
|
|
476
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
477
|
+
*/
|
|
478
|
+
toJson() {
|
|
479
|
+
const s = {
|
|
480
|
+
status: this.status,
|
|
481
|
+
statusText: this.statusText
|
|
482
|
+
};
|
|
483
|
+
return Response.json(this.body, s);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
class N extends y {
|
|
487
|
+
/**
|
|
488
|
+
* Creates an instance of the `UnprocessableEntity` class.
|
|
489
|
+
*
|
|
490
|
+
* @param props - An object containing details about the error, such as:
|
|
491
|
+
* - `data`: Additional data related to the error.
|
|
492
|
+
* - `fieldErrors`: A record of field-specific error messages.
|
|
493
|
+
* - `fields`: A record of field values that caused the error.
|
|
494
|
+
* - `message`: A descriptive message explaining the error.
|
|
495
|
+
* @param enableDebug - A boolean indicating whether to enable debug logging for this error.
|
|
496
|
+
*/
|
|
497
|
+
constructor(s) {
|
|
498
|
+
super();
|
|
499
|
+
o(this, "body");
|
|
500
|
+
o(this, "status", 422);
|
|
501
|
+
o(this, "statusText");
|
|
502
|
+
this.statusText = s.message || "Unprocessable Entity", this.body = {
|
|
503
|
+
name: "UnprocessableEntity",
|
|
504
|
+
message: s.message || null,
|
|
505
|
+
data: s.data,
|
|
506
|
+
fieldErrors: s.fieldErrors,
|
|
507
|
+
fields: s.fields
|
|
508
|
+
}, this.onDebug({
|
|
509
|
+
name: "UnprocessableEntity",
|
|
510
|
+
cause: s.fieldErrors,
|
|
511
|
+
message: s.message
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Converts the `UnprocessableEntity` instance into a `Response` object with a JSON body.
|
|
516
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
517
|
+
*
|
|
518
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
519
|
+
*/
|
|
520
|
+
toResponse() {
|
|
521
|
+
const s = {
|
|
522
|
+
headers: { "Content-Type": "application/json" },
|
|
523
|
+
status: this.status,
|
|
524
|
+
statusText: this.statusText
|
|
525
|
+
};
|
|
526
|
+
return new Response(JSON.stringify(this.body), s);
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Converts the `UnprocessableEntity` instance into a `Response` object using the `Response.json` method.
|
|
530
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
531
|
+
*
|
|
532
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
533
|
+
*/
|
|
534
|
+
toJson() {
|
|
535
|
+
const s = {
|
|
536
|
+
status: this.status,
|
|
537
|
+
statusText: this.statusText
|
|
538
|
+
};
|
|
539
|
+
return Response.json(this.body, s);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
class T {
|
|
543
|
+
/**
|
|
544
|
+
* Logs debug information for success responses including caller context and response details.
|
|
545
|
+
*
|
|
546
|
+
* @param name - The name/type of the success response being logged
|
|
547
|
+
* @param body - The response body or success data to be logged
|
|
548
|
+
* @param cause - Optional additional cause information for the error
|
|
549
|
+
*
|
|
550
|
+
* @example
|
|
551
|
+
* ```typescript
|
|
552
|
+
* const SuccessResponse = new SuccessResponse();
|
|
553
|
+
* SuccessResponse.onDebug("ValidationError", { field: "email", message: "Invalid format" });
|
|
554
|
+
* ```
|
|
555
|
+
*/
|
|
556
|
+
onDebug(t, s, e) {
|
|
557
|
+
const r = [], { callerInfo: u, functionName: c } = x();
|
|
558
|
+
r.push(`${t} initialized
|
|
559
|
+
`), r.push(`Caller Function: ${c}
|
|
560
|
+
`), r.push(`Caller Location: ${u}
|
|
561
|
+
`), r.push(`Body: ${JSON.stringify(s, null, 2)}
|
|
562
|
+
`), e && r.push(`Cause: ${JSON.stringify(e, null, 2)}
|
|
563
|
+
`), p({
|
|
564
|
+
scheme: "green",
|
|
565
|
+
name: "ARKYN-SUCCESS-RESPONSE-DEBUG",
|
|
566
|
+
debugs: r
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
class P extends T {
|
|
571
|
+
/**
|
|
572
|
+
* Creates an instance of the `Created` class.
|
|
573
|
+
*
|
|
574
|
+
* @param body - The response body to be included in the HTTP response.
|
|
575
|
+
* @param init - Optional initialization object for customizing headers, status, and status text.
|
|
576
|
+
*/
|
|
577
|
+
constructor(s, e) {
|
|
578
|
+
super();
|
|
579
|
+
o(this, "body");
|
|
580
|
+
o(this, "headers");
|
|
581
|
+
o(this, "status");
|
|
582
|
+
o(this, "statusText");
|
|
583
|
+
this.body = s, this.headers = (e == null ? void 0 : e.headers) || {}, this.status = (e == null ? void 0 : e.status) || 201, this.statusText = (e == null ? void 0 : e.statusText) || "Resource created successfully", this.onDebug("Created", s);
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Converts the `Created` instance into a `Response` object with a JSON body.
|
|
587
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
588
|
+
*
|
|
589
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
590
|
+
*/
|
|
591
|
+
toResponse() {
|
|
592
|
+
const s = {
|
|
593
|
+
headers: { "Content-Type": "application/json", ...this.headers },
|
|
594
|
+
status: this.status,
|
|
595
|
+
statusText: this.statusText
|
|
596
|
+
};
|
|
597
|
+
return new Response(JSON.stringify(this.body), s);
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Converts the `Created` instance into a `Response` object using the `Response.json` method.
|
|
601
|
+
* This method is an alternative to `toResponse` for generating JSON responses.
|
|
602
|
+
*
|
|
603
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
604
|
+
*/
|
|
605
|
+
toJson() {
|
|
606
|
+
const s = {
|
|
607
|
+
headers: this.headers,
|
|
608
|
+
status: this.status,
|
|
609
|
+
statusText: this.statusText
|
|
610
|
+
};
|
|
611
|
+
return Response.json(this.body, s);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
class $ extends T {
|
|
615
|
+
/**
|
|
616
|
+
* Creates an instance of the `Found` class.
|
|
617
|
+
*
|
|
618
|
+
* @param body - The body of the response.
|
|
619
|
+
* @param init - Optional initialization object to set headers, status, and statusText.
|
|
620
|
+
* - `headers`: Additional headers to include in the response.
|
|
621
|
+
* - `status`: HTTP status code (default is 302).
|
|
622
|
+
* - `statusText`: HTTP status text (default is "Found").
|
|
623
|
+
*/
|
|
624
|
+
constructor(s, e) {
|
|
625
|
+
super();
|
|
626
|
+
o(this, "body");
|
|
627
|
+
o(this, "headers");
|
|
628
|
+
o(this, "status");
|
|
629
|
+
o(this, "statusText");
|
|
630
|
+
this.body = s, this.headers = (e == null ? void 0 : e.headers) || {}, this.status = (e == null ? void 0 : e.status) || 302, this.statusText = (e == null ? void 0 : e.statusText) || "Found", this.onDebug("Found", s);
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Converts the `Found` instance into a `Response` object.
|
|
634
|
+
* This method serializes the response body as JSON and includes the appropriate headers.
|
|
635
|
+
*
|
|
636
|
+
* @returns A `Response` object with the serialized JSON body and the specified headers, status, and statusText.
|
|
637
|
+
*/
|
|
638
|
+
toResponse() {
|
|
639
|
+
const s = {
|
|
640
|
+
headers: { "Content-Type": "application/json", ...this.headers },
|
|
641
|
+
status: this.status,
|
|
642
|
+
statusText: this.statusText
|
|
643
|
+
};
|
|
644
|
+
return new Response(JSON.stringify(this.body), s);
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Converts the `Found` instance into a JSON response using `Response.json`.
|
|
648
|
+
* This method is an alternative to `toResponse` for creating JSON responses.
|
|
649
|
+
*
|
|
650
|
+
* @returns A `Response` object with the JSON body and the specified headers, status, and statusText.
|
|
651
|
+
*/
|
|
652
|
+
toJson() {
|
|
653
|
+
const s = {
|
|
654
|
+
headers: this.headers,
|
|
655
|
+
status: this.status,
|
|
656
|
+
statusText: this.statusText
|
|
657
|
+
};
|
|
658
|
+
return Response.json(this.body, s);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
class H extends T {
|
|
662
|
+
/**
|
|
663
|
+
* Creates an instance of the `NoContent` class.
|
|
664
|
+
*
|
|
665
|
+
* @param init - Optional initialization object for customizing headers, status, and status text.
|
|
666
|
+
*/
|
|
667
|
+
constructor(s) {
|
|
668
|
+
super();
|
|
669
|
+
o(this, "headers");
|
|
670
|
+
o(this, "status");
|
|
671
|
+
o(this, "statusText");
|
|
672
|
+
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);
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Converts the `NoContent` instance into a `Response` object.
|
|
676
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
677
|
+
*
|
|
678
|
+
* @returns A `Response` object with no body and response metadata.
|
|
679
|
+
*/
|
|
680
|
+
toResponse() {
|
|
681
|
+
const s = {
|
|
682
|
+
headers: this.headers,
|
|
683
|
+
status: this.status,
|
|
684
|
+
statusText: this.statusText
|
|
685
|
+
};
|
|
686
|
+
return new Response(null, s);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
class A extends T {
|
|
690
|
+
/**
|
|
691
|
+
* Creates an instance of the `Success` class.
|
|
692
|
+
*
|
|
693
|
+
* @param body - The response body to be included in the HTTP response.
|
|
694
|
+
* @param init - Optional initialization object for customizing headers, status, and status text.
|
|
695
|
+
*/
|
|
696
|
+
constructor(s, e) {
|
|
697
|
+
super();
|
|
698
|
+
o(this, "body");
|
|
699
|
+
o(this, "headers");
|
|
700
|
+
o(this, "status");
|
|
701
|
+
o(this, "statusText");
|
|
702
|
+
this.body = s, this.headers = (e == null ? void 0 : e.headers) || {}, this.status = (e == null ? void 0 : e.status) || 200, this.statusText = (e == null ? void 0 : e.statusText) ?? "OK", this.onDebug("Success", s);
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* Converts the `Success` instance into a `Response` object with a JSON body.
|
|
706
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
707
|
+
*
|
|
708
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
709
|
+
*/
|
|
710
|
+
toResponse() {
|
|
711
|
+
const s = {
|
|
712
|
+
headers: { "Content-Type": "application/json", ...this.headers },
|
|
713
|
+
status: this.status,
|
|
714
|
+
statusText: this.statusText
|
|
715
|
+
};
|
|
716
|
+
return new Response(JSON.stringify(this.body), s);
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* Converts the `Success` instance into a `Response` object using the `Response.json` method.
|
|
720
|
+
* This method is an alternative to `toResponse` for generating JSON responses.
|
|
721
|
+
*
|
|
722
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
723
|
+
*/
|
|
724
|
+
toJson() {
|
|
725
|
+
const s = {
|
|
726
|
+
headers: this.headers,
|
|
727
|
+
status: this.status,
|
|
728
|
+
statusText: this.statusText
|
|
729
|
+
};
|
|
730
|
+
return Response.json(this.body, s);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
class L extends T {
|
|
734
|
+
/**
|
|
735
|
+
* Creates an instance of the `Updated` class.
|
|
736
|
+
*
|
|
737
|
+
* @param body - The response body to be included in the HTTP response.
|
|
738
|
+
* @param init - Optional initialization object for customizing headers, status, and status text.
|
|
739
|
+
*/
|
|
740
|
+
constructor(s, e) {
|
|
741
|
+
super();
|
|
742
|
+
o(this, "body");
|
|
743
|
+
o(this, "headers");
|
|
744
|
+
o(this, "status");
|
|
745
|
+
o(this, "statusText");
|
|
746
|
+
this.body = s, this.headers = (e == null ? void 0 : e.headers) || {}, this.status = (e == null ? void 0 : e.status) || 200, this.statusText = (e == null ? void 0 : e.statusText) || "Resource updated successfully", this.onDebug("Updated", s);
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* Converts the `Updated` instance into a `Response` object with a JSON body.
|
|
750
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
751
|
+
*
|
|
752
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
753
|
+
*/
|
|
754
|
+
toResponse() {
|
|
755
|
+
const s = {
|
|
756
|
+
headers: { "Content-Type": "application/json", ...this.headers },
|
|
757
|
+
status: this.status,
|
|
758
|
+
statusText: this.statusText
|
|
759
|
+
};
|
|
760
|
+
return new Response(JSON.stringify(this.body), s);
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* Converts the `Updated` instance into a `Response` object using the `Response.json` method.
|
|
764
|
+
* This method is an alternative to `toResponse` for generating JSON responses.
|
|
765
|
+
*
|
|
766
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
767
|
+
*/
|
|
768
|
+
toJson() {
|
|
769
|
+
const s = {
|
|
770
|
+
headers: this.headers,
|
|
771
|
+
status: this.status,
|
|
772
|
+
statusText: this.statusText
|
|
773
|
+
};
|
|
774
|
+
return Response.json(this.body, s);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
class v {
|
|
778
|
+
static mapHeaders(t) {
|
|
779
|
+
return t instanceof Headers ? Object.fromEntries(t.entries()) : typeof t == "object" ? Object.entries(t).reduce((s, [e, r]) => (typeof r == "string" ? s[e] = r : Array.isArray(r) ? s[e] = r.join(", ") : s[e] = JSON.stringify(r), s), {}) : {};
|
|
780
|
+
}
|
|
781
|
+
static mapQueryParams(t) {
|
|
782
|
+
const s = {};
|
|
783
|
+
return t.forEach((e, r) => {
|
|
784
|
+
s[r] = e;
|
|
785
|
+
}), s;
|
|
786
|
+
}
|
|
787
|
+
static handle(t) {
|
|
788
|
+
return {
|
|
789
|
+
rawUrl: t.url,
|
|
790
|
+
status: t.status,
|
|
791
|
+
method: t.method,
|
|
792
|
+
token: null,
|
|
793
|
+
elapsedTime: t.elapsedTime,
|
|
794
|
+
requestHeaders: this.mapHeaders(t.requestHeaders),
|
|
795
|
+
requestBody: t.requestBody || null,
|
|
796
|
+
queryParams: this.mapQueryParams(t.queryParams),
|
|
797
|
+
responseHeaders: this.mapHeaders(t.responseHeaders),
|
|
798
|
+
responseBody: t.responseBody || null
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
class w {
|
|
803
|
+
/**
|
|
804
|
+
* Sets the configuration for the arkyn. This method initializes the arkyn configuration
|
|
805
|
+
* with the provided `arkynConfig` values. If the configuration has already been set,
|
|
806
|
+
* the method will return early without making any changes.
|
|
807
|
+
*
|
|
808
|
+
* @param arkynConfig - An object containing the arkyn configuration properties.
|
|
809
|
+
* @param arkynConfig.arkynTrafficSourceId - The key used to identify the arkyn.
|
|
810
|
+
* @param arkynConfig.arkynUserToken - The user token for authenticating with the arkyn.
|
|
811
|
+
* @param arkynConfig.arkynLogBaseApiUrl - (Optional) The API URL for the arkyn. If not provided,
|
|
812
|
+
* a default URL will be used.
|
|
813
|
+
*/
|
|
814
|
+
static setArkynConfig(t) {
|
|
815
|
+
if (this.arkynConfig) return;
|
|
816
|
+
let e = t.arkynLogBaseApiUrl || "https://logs-arkyn-flow-logs.vw6wo7.easypanel.host";
|
|
817
|
+
e = e + "/http-traffic-records/:trafficSourceId", this.arkynConfig = {
|
|
818
|
+
arkynTrafficSourceId: t.arkynTrafficSourceId,
|
|
819
|
+
arkynUserToken: t.arkynUserToken,
|
|
820
|
+
arkynApiUrl: e
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* Retrieves the current arkyn configuration for the ArkynLogService.
|
|
825
|
+
*
|
|
826
|
+
* @returns {ArkynConfigProps | undefined} The current arkyn configuration if set,
|
|
827
|
+
* or `undefined` if no configuration has been initialized.
|
|
828
|
+
*/
|
|
829
|
+
static getArkynConfig() {
|
|
830
|
+
return this.arkynConfig;
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* Resets the arkyn configuration to `undefined`.
|
|
834
|
+
* This method can be used to clear the current configuration.
|
|
835
|
+
*/
|
|
836
|
+
static resetArkynConfig() {
|
|
837
|
+
this.arkynConfig = void 0;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
o(w, "arkynConfig");
|
|
841
|
+
async function F(n) {
|
|
842
|
+
const t = w.getArkynConfig();
|
|
843
|
+
if (!t) return;
|
|
844
|
+
const { arkynUserToken: s, arkynApiUrl: e } = t, {
|
|
845
|
+
elapsedTime: r,
|
|
846
|
+
method: u,
|
|
847
|
+
queryParams: c,
|
|
848
|
+
requestBody: h,
|
|
849
|
+
requestHeaders: i,
|
|
850
|
+
responseBody: l,
|
|
851
|
+
responseHeaders: a,
|
|
852
|
+
status: d,
|
|
853
|
+
token: Q,
|
|
854
|
+
rawUrl: E
|
|
855
|
+
} = n;
|
|
856
|
+
if (process.env.NODE_ENV !== "development")
|
|
857
|
+
try {
|
|
858
|
+
const f = new URL(E);
|
|
859
|
+
let R = "HTTPS";
|
|
860
|
+
f.protocol === "http:" && (R = "HTTP");
|
|
861
|
+
const O = JSON.stringify({
|
|
862
|
+
domainUrl: f.protocol + "//" + f.host,
|
|
863
|
+
pathnameUrl: f.pathname,
|
|
864
|
+
status: d,
|
|
865
|
+
protocol: R,
|
|
866
|
+
method: u,
|
|
867
|
+
trafficUserId: null,
|
|
868
|
+
elapsedTime: r,
|
|
869
|
+
requestHeaders: i,
|
|
870
|
+
requestBody: h,
|
|
871
|
+
queryParams: c,
|
|
872
|
+
responseHeaders: a,
|
|
873
|
+
responseBody: l
|
|
874
|
+
});
|
|
875
|
+
await fetch(
|
|
876
|
+
e.replace(
|
|
877
|
+
":trafficSourceId",
|
|
878
|
+
t.arkynTrafficSourceId
|
|
879
|
+
),
|
|
880
|
+
{
|
|
881
|
+
method: "POST",
|
|
882
|
+
body: O,
|
|
883
|
+
headers: {
|
|
884
|
+
"Content-Type": "application/json",
|
|
885
|
+
Authorization: `Bearer ${s}`
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
);
|
|
889
|
+
} catch (f) {
|
|
890
|
+
p({
|
|
891
|
+
debugs: [`Error sending request: ${f}`],
|
|
892
|
+
name: "ARKYN_LOG_ERROR",
|
|
893
|
+
scheme: "red"
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
async function g(n, t, s = {}, e) {
|
|
898
|
+
const r = {
|
|
899
|
+
POST: "Resource created successfully",
|
|
900
|
+
PUT: "Resource updated successfully",
|
|
901
|
+
DELETE: "Resource deleted successfully",
|
|
902
|
+
PATCH: "Resource patched successfully",
|
|
903
|
+
GET: "Request successful"
|
|
904
|
+
};
|
|
905
|
+
try {
|
|
906
|
+
const u = performance.now(), c = { ...s, "Content-Type": "application/json" }, h = await fetch(t, {
|
|
907
|
+
method: n,
|
|
908
|
+
headers: c,
|
|
909
|
+
body: e ? JSON.stringify(e) : void 0
|
|
910
|
+
}), i = performance.now() - u, l = h.status;
|
|
911
|
+
let a = null;
|
|
912
|
+
try {
|
|
913
|
+
a = await h.json();
|
|
914
|
+
} catch {
|
|
915
|
+
a = null;
|
|
916
|
+
}
|
|
917
|
+
const d = v.handle({
|
|
918
|
+
elapsedTime: i,
|
|
919
|
+
method: n,
|
|
920
|
+
queryParams: new URL(t).searchParams,
|
|
921
|
+
requestHeaders: c,
|
|
922
|
+
requestBody: e,
|
|
923
|
+
responseBody: a,
|
|
924
|
+
responseHeaders: h.headers,
|
|
925
|
+
status: l,
|
|
926
|
+
url: t
|
|
927
|
+
});
|
|
928
|
+
return F(d), h.ok ? {
|
|
929
|
+
success: !0,
|
|
930
|
+
status: l,
|
|
931
|
+
message: (a == null ? void 0 : a.message) || r[n],
|
|
932
|
+
response: a,
|
|
933
|
+
cause: null
|
|
934
|
+
} : {
|
|
935
|
+
success: !1,
|
|
936
|
+
status: l,
|
|
937
|
+
message: (a == null ? void 0 : a.message) || h.statusText || "Request failed",
|
|
938
|
+
response: a,
|
|
939
|
+
cause: null
|
|
940
|
+
};
|
|
941
|
+
} catch (u) {
|
|
942
|
+
return p({
|
|
943
|
+
debugs: [`Network error or request failed: ${u}`],
|
|
944
|
+
name: "ARKYN_MAKE_REQUEST_ERROR",
|
|
945
|
+
scheme: "red"
|
|
946
|
+
}), {
|
|
947
|
+
success: !1,
|
|
948
|
+
status: 0,
|
|
949
|
+
message: "Network error or request failed",
|
|
950
|
+
response: null,
|
|
951
|
+
cause: u instanceof Error ? u.message : String(u)
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
async function M(n, t = {}, s) {
|
|
956
|
+
return g("DELETE", n, t, s);
|
|
957
|
+
}
|
|
958
|
+
async function _(n, t = {}) {
|
|
959
|
+
return g("GET", n, t);
|
|
960
|
+
}
|
|
961
|
+
async function z(n, t = {}, s) {
|
|
962
|
+
return g("PATCH", n, t, s);
|
|
963
|
+
}
|
|
964
|
+
async function G(n, t = {}, s) {
|
|
965
|
+
return g("POST", n, t, s);
|
|
966
|
+
}
|
|
967
|
+
async function K(n, t = {}, s) {
|
|
968
|
+
return g("PUT", n, t, s);
|
|
969
|
+
}
|
|
970
|
+
class X {
|
|
971
|
+
/**
|
|
972
|
+
* Creates an instance of ApiService.
|
|
973
|
+
* @param props - The configuration properties for the API instance.
|
|
974
|
+
* @param props.baseUrl - The base URL for the API.
|
|
975
|
+
* @param props.baseHeaders - Optional base headers to include in all requests.
|
|
976
|
+
* @param props.baseToken - Optional base token for authorization.
|
|
977
|
+
* @param props.enableDebug - Optional flag to enable debug logging for requests.
|
|
978
|
+
*/
|
|
979
|
+
constructor(t) {
|
|
980
|
+
o(this, "baseUrl");
|
|
981
|
+
o(this, "baseHeaders");
|
|
982
|
+
o(this, "baseToken");
|
|
983
|
+
o(this, "enableDebug");
|
|
984
|
+
this.baseUrl = t.baseUrl, this.baseHeaders = t.baseHeaders || void 0, this.baseToken = t.baseToken || void 0, this.enableDebug = t.enableDebug || !1;
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* Generates the full URL by appending the route to the base URL.
|
|
988
|
+
* @param route - The route to append to the base URL.
|
|
989
|
+
* @returns The full URL as a string.
|
|
990
|
+
*/
|
|
991
|
+
onDebug(t, s, e) {
|
|
992
|
+
if (this.enableDebug) {
|
|
993
|
+
const r = [];
|
|
994
|
+
r.push(`Base URL: ${this.baseUrl}`), r.push(`Endpoint: ${t}`), r.push(`Method: ${s}`), e[0] && r.push(`Headers: ${JSON.stringify(e[0])}`), e[1] && r.push(`Body: ${JSON.stringify(e[1])}`), p({ debugs: r, name: "ARKYN-API-DEBUG", scheme: "yellow" });
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
generateURL(t) {
|
|
998
|
+
return this.baseUrl + t;
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* Generates the headers for a request by merging base headers, provided headers, and tokens.
|
|
1002
|
+
* @param initHeaders - Initial headers to include in the request.
|
|
1003
|
+
* @param token - Optional token to override the base token.
|
|
1004
|
+
* @returns The merged headers as a HeadersInit object.
|
|
1005
|
+
*/
|
|
1006
|
+
generateHeaders(t, s) {
|
|
1007
|
+
let e = {};
|
|
1008
|
+
return this.baseToken && (e = { Authorization: `Bearer ${this.baseToken}` }), this.baseHeaders && (e = { ...e, ...this.baseHeaders }), t && (e = { ...e, ...t }), s && (e = { ...e, Authorization: `Bearer ${s}` }), e;
|
|
1009
|
+
}
|
|
1010
|
+
/**
|
|
1011
|
+
* Sends a get request to the specified endpoint.
|
|
1012
|
+
* @param endpoint - The API endpoint to send the get request to.
|
|
1013
|
+
* @param data - The request data, including optional headers and token.
|
|
1014
|
+
* @returns The API response data.
|
|
1015
|
+
*/
|
|
1016
|
+
async get(t, s) {
|
|
1017
|
+
const e = this.generateURL(t), r = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token);
|
|
1018
|
+
return this.onDebug(t, "get", [r]), await _(e, r);
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Sends a post request to the specified endpoint.
|
|
1022
|
+
* @param endpoint - The API endpoint to send the post request to.
|
|
1023
|
+
* @param data - The request data, including body, optional headers, and token.
|
|
1024
|
+
* @returns The API response data.
|
|
1025
|
+
*/
|
|
1026
|
+
async post(t, s) {
|
|
1027
|
+
const e = this.generateURL(t), r = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
|
|
1028
|
+
return this.onDebug(t, "post", [r, u]), await G(e, r, u);
|
|
1029
|
+
}
|
|
1030
|
+
/**
|
|
1031
|
+
* Sends a put request to the specified endpoint.
|
|
1032
|
+
* @param endpoint - The API endpoint to send the put request to.
|
|
1033
|
+
* @param data - The request data, including body, optional headers, and token.
|
|
1034
|
+
* @returns The API response data.
|
|
1035
|
+
*/
|
|
1036
|
+
async put(t, s) {
|
|
1037
|
+
const e = this.generateURL(t), r = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
|
|
1038
|
+
return this.onDebug(t, "put", [r, u]), await K(e, r, u);
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
1041
|
+
* Sends a patch request to the specified endpoint.
|
|
1042
|
+
* @param endpoint - The API endpoint to send the patch request to.
|
|
1043
|
+
* @param data - The request data, including body, optional headers, and token.
|
|
1044
|
+
* @returns The API response data.
|
|
1045
|
+
*/
|
|
1046
|
+
async patch(t, s) {
|
|
1047
|
+
const e = this.generateURL(t), r = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
|
|
1048
|
+
return this.onDebug(t, "patch", [r, u]), await z(e, r, u);
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* Sends a delete request to the specified endpoint.
|
|
1052
|
+
* @param endpoint - The API endpoint to send the delete request to.
|
|
1053
|
+
* @param data - The request data, including body, optional headers, and token.
|
|
1054
|
+
* @returns The API response data.
|
|
1055
|
+
*/
|
|
1056
|
+
async delete(t, s) {
|
|
1057
|
+
const e = this.generateURL(t), r = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
|
|
1058
|
+
return this.onDebug(t, "delete", [r, u]), await M(e, r, u);
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
function Z(n, t) {
|
|
1062
|
+
var s, e, r;
|
|
1063
|
+
return n != null && n.message && typeof (n == null ? void 0 : n.message) == "string" ? n == null ? void 0 : n.message : n != null && n.error && typeof (n == null ? void 0 : n.error) == "string" ? n == null ? void 0 : n.error : (s = n == null ? void 0 : n.error) != null && s.message && typeof ((e = n == null ? void 0 : n.error) == null ? void 0 : e.message) == "string" ? (r = n == null ? void 0 : n.error) == null ? void 0 : r.message : t != null && t.statusText && typeof (t == null ? void 0 : t.statusText) == "string" ? t == null ? void 0 : t.statusText : "Missing error message";
|
|
1064
|
+
}
|
|
1065
|
+
const ss = async (n) => {
|
|
1066
|
+
let t;
|
|
1067
|
+
const s = await n.arrayBuffer(), e = new TextDecoder().decode(s);
|
|
1068
|
+
try {
|
|
1069
|
+
t = JSON.parse(e);
|
|
1070
|
+
} catch {
|
|
1071
|
+
try {
|
|
1072
|
+
if (e.includes("=")) {
|
|
1073
|
+
const u = new URLSearchParams(e);
|
|
1074
|
+
t = Object.fromEntries(u.entries());
|
|
1075
|
+
} else
|
|
1076
|
+
throw new b("Invalid URLSearchParams format");
|
|
1077
|
+
} catch {
|
|
1078
|
+
throw new b("Failed to extract data from request");
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
return t;
|
|
1082
|
+
};
|
|
1083
|
+
function es(n) {
|
|
1084
|
+
switch (!0) {
|
|
1085
|
+
case n instanceof Response:
|
|
1086
|
+
return n;
|
|
1087
|
+
case n instanceof $:
|
|
1088
|
+
return n.toResponse();
|
|
1089
|
+
case n instanceof P:
|
|
1090
|
+
return n.toResponse();
|
|
1091
|
+
case n instanceof L:
|
|
1092
|
+
return n.toResponse();
|
|
1093
|
+
case n instanceof A:
|
|
1094
|
+
return n.toResponse();
|
|
1095
|
+
case n instanceof H:
|
|
1096
|
+
return n.toResponse();
|
|
1097
|
+
}
|
|
1098
|
+
switch (!0) {
|
|
1099
|
+
case n instanceof j:
|
|
1100
|
+
return n.toResponse();
|
|
1101
|
+
case n instanceof b:
|
|
1102
|
+
return n.toResponse();
|
|
1103
|
+
case n instanceof J:
|
|
1104
|
+
return n.toResponse();
|
|
1105
|
+
case n instanceof D:
|
|
1106
|
+
return n.toResponse();
|
|
1107
|
+
case n instanceof C:
|
|
1108
|
+
return n.toResponse();
|
|
1109
|
+
case n instanceof B:
|
|
1110
|
+
return n.toResponse();
|
|
1111
|
+
case n instanceof m:
|
|
1112
|
+
return n.toResponse();
|
|
1113
|
+
case n instanceof q:
|
|
1114
|
+
return n.toResponse();
|
|
1115
|
+
case n instanceof N:
|
|
1116
|
+
return n.toResponse();
|
|
1117
|
+
}
|
|
1118
|
+
return new m("Server error", n).toResponse();
|
|
1119
|
+
}
|
|
1120
|
+
function V([
|
|
1121
|
+
n,
|
|
1122
|
+
t
|
|
1123
|
+
]) {
|
|
1124
|
+
const s = t.safeParse(n);
|
|
1125
|
+
if (s.success === !1) {
|
|
1126
|
+
const e = Object.fromEntries(
|
|
1127
|
+
s.error.issues.map((r) => [r.path.join("."), r.message])
|
|
1128
|
+
);
|
|
1129
|
+
return {
|
|
1130
|
+
success: s.success,
|
|
1131
|
+
fieldErrors: e,
|
|
1132
|
+
fields: n
|
|
1133
|
+
};
|
|
1134
|
+
} else
|
|
1135
|
+
return {
|
|
1136
|
+
success: s.success,
|
|
1137
|
+
data: s.data
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
const ts = (n, t = "") => {
|
|
1141
|
+
const s = new URL(n.url);
|
|
1142
|
+
if (t === "") return s.searchParams;
|
|
1143
|
+
const e = Array.from(
|
|
1144
|
+
s.searchParams.entries()
|
|
1145
|
+
).filter(([r]) => r.startsWith(`${t}:`)).map(([r, u]) => [r.replace(`${t}:`, ""), u]);
|
|
1146
|
+
return new URLSearchParams(e);
|
|
1147
|
+
};
|
|
1148
|
+
function Y(n) {
|
|
1149
|
+
const t = "Error validating:", s = n.issues.map(
|
|
1150
|
+
({ path: e, message: r }) => `-> ${e.join(".")}: ${r}`
|
|
1151
|
+
);
|
|
1152
|
+
return [t, ...s].join(`
|
|
1153
|
+
`);
|
|
1154
|
+
}
|
|
1155
|
+
class ns {
|
|
1156
|
+
constructor(t) {
|
|
1157
|
+
o(this, "functionName");
|
|
1158
|
+
o(this, "callerInfo");
|
|
1159
|
+
this.schema = t;
|
|
1160
|
+
const { callerInfo: s, functionName: e } = x();
|
|
1161
|
+
this.callerInfo = s, this.functionName = e;
|
|
1162
|
+
}
|
|
1163
|
+
isValid(t) {
|
|
1164
|
+
return this.schema.safeParse(t).success;
|
|
1165
|
+
}
|
|
1166
|
+
safeValidate(t) {
|
|
1167
|
+
return this.schema.safeParse(t);
|
|
1168
|
+
}
|
|
1169
|
+
validate(t) {
|
|
1170
|
+
try {
|
|
1171
|
+
return this.schema.parse(t);
|
|
1172
|
+
} catch (s) {
|
|
1173
|
+
throw new m(Y(s));
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
formValidate(t, s) {
|
|
1177
|
+
const e = V([t, this.schema]);
|
|
1178
|
+
if (!e.success) {
|
|
1179
|
+
const r = Object.keys(e.fieldErrors)[0];
|
|
1180
|
+
throw new N({
|
|
1181
|
+
fields: e.fields,
|
|
1182
|
+
fieldErrors: e.fieldErrors,
|
|
1183
|
+
data: { scrollTo: r },
|
|
1184
|
+
message: s
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
return e.data;
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
export {
|
|
1191
|
+
X as ApiService,
|
|
1192
|
+
w as ArkynLogService,
|
|
1193
|
+
j as BadGateway,
|
|
1194
|
+
b as BadRequest,
|
|
1195
|
+
J as Conflict,
|
|
1196
|
+
P as Created,
|
|
1197
|
+
S as DebugService,
|
|
1198
|
+
D as Forbidden,
|
|
1199
|
+
$ as Found,
|
|
1200
|
+
H as NoContent,
|
|
1201
|
+
C as NotFound,
|
|
1202
|
+
B as NotImplemented,
|
|
1203
|
+
ns as SchemaValidator,
|
|
1204
|
+
m as ServerError,
|
|
1205
|
+
A as Success,
|
|
1206
|
+
q as Unauthorized,
|
|
1207
|
+
N as UnprocessableEntity,
|
|
1208
|
+
L as Updated,
|
|
1209
|
+
Z as decodeErrorMessageFromRequest,
|
|
1210
|
+
ss as decodeRequestBody,
|
|
1211
|
+
es as errorHandler,
|
|
1212
|
+
p as flushDebugLogs,
|
|
1213
|
+
V as formParse,
|
|
1214
|
+
x as getCaller,
|
|
1215
|
+
ts as getScopedParams
|
|
1216
|
+
};
|