@arkyn/server 3.0.1-beta.143 → 3.0.1-beta.144
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 +90 -323
- package/dist/http/badResponses/badGateway.d.ts +12 -19
- package/dist/http/badResponses/badGateway.d.ts.map +1 -1
- package/dist/http/badResponses/badGateway.js +12 -19
- package/dist/http/badResponses/badRequest.d.ts +10 -19
- package/dist/http/badResponses/badRequest.d.ts.map +1 -1
- package/dist/http/badResponses/badRequest.js +10 -19
- package/dist/http/badResponses/conflict.d.ts +10 -19
- package/dist/http/badResponses/conflict.d.ts.map +1 -1
- package/dist/http/badResponses/conflict.js +10 -19
- package/dist/http/badResponses/forbidden.d.ts +10 -19
- package/dist/http/badResponses/forbidden.d.ts.map +1 -1
- package/dist/http/badResponses/forbidden.js +10 -19
- package/dist/http/badResponses/notFound.d.ts +10 -19
- package/dist/http/badResponses/notFound.d.ts.map +1 -1
- package/dist/http/badResponses/notFound.js +10 -19
- package/dist/http/badResponses/notImplemented.d.ts +10 -19
- package/dist/http/badResponses/notImplemented.d.ts.map +1 -1
- package/dist/http/badResponses/notImplemented.js +10 -19
- package/dist/http/badResponses/serverError.d.ts +10 -19
- package/dist/http/badResponses/serverError.d.ts.map +1 -1
- package/dist/http/badResponses/serverError.js +10 -19
- package/dist/http/badResponses/unauthorized.d.ts +10 -19
- package/dist/http/badResponses/unauthorized.d.ts.map +1 -1
- package/dist/http/badResponses/unauthorized.js +10 -19
- package/dist/http/badResponses/unprocessableEntity.d.ts +17 -22
- package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
- package/dist/http/badResponses/unprocessableEntity.js +17 -22
- package/dist/http/successResponses/created.d.ts +10 -14
- package/dist/http/successResponses/created.d.ts.map +1 -1
- package/dist/http/successResponses/created.js +10 -14
- package/dist/http/successResponses/found.d.ts +10 -14
- package/dist/http/successResponses/found.d.ts.map +1 -1
- package/dist/http/successResponses/found.js +10 -14
- package/dist/http/successResponses/noContent.d.ts +9 -7
- package/dist/http/successResponses/noContent.d.ts.map +1 -1
- package/dist/http/successResponses/noContent.js +9 -7
- package/dist/http/successResponses/success.d.ts +10 -14
- package/dist/http/successResponses/success.d.ts.map +1 -1
- package/dist/http/successResponses/success.js +10 -14
- package/dist/http/successResponses/updated.d.ts +11 -14
- package/dist/http/successResponses/updated.d.ts.map +1 -1
- package/dist/http/successResponses/updated.js +11 -14
- package/dist/services/apiService.d.ts +20 -0
- package/dist/services/apiService.d.ts.map +1 -1
- package/dist/services/apiService.js +16 -0
- package/dist/services/debugService.d.ts +10 -42
- package/dist/services/debugService.d.ts.map +1 -1
- package/dist/services/debugService.js +10 -42
- package/dist/services/logService.d.ts +5 -10
- package/dist/services/logService.d.ts.map +1 -1
- package/dist/services/logService.js +5 -10
- package/dist/utilities/decodeRequestBody.d.ts +11 -9
- package/dist/utilities/decodeRequestBody.d.ts.map +1 -1
- package/dist/utilities/decodeRequestBody.js +11 -9
- package/dist/utilities/decodeRequestErrorMessage.d.ts +12 -10
- package/dist/utilities/decodeRequestErrorMessage.d.ts.map +1 -1
- package/dist/utilities/decodeRequestErrorMessage.js +12 -10
- package/dist/utilities/errorHandler.d.ts +13 -38
- package/dist/utilities/errorHandler.d.ts.map +1 -1
- package/dist/utilities/errorHandler.js +13 -38
- package/dist/utilities/flushDebugLogs.d.ts +6 -28
- package/dist/utilities/flushDebugLogs.d.ts.map +1 -1
- package/dist/utilities/flushDebugLogs.js +6 -28
- package/dist/utilities/formAsyncParse.d.ts +7 -28
- package/dist/utilities/formAsyncParse.d.ts.map +1 -1
- package/dist/utilities/formAsyncParse.js +7 -28
- package/dist/utilities/formParse.d.ts +7 -28
- package/dist/utilities/formParse.d.ts.map +1 -1
- package/dist/utilities/formParse.js +7 -28
- package/dist/utilities/getScopedParams.d.ts +11 -19
- package/dist/utilities/getScopedParams.d.ts.map +1 -1
- package/dist/utilities/getScopedParams.js +11 -19
- package/dist/utilities/schemaValidator.d.ts +31 -102
- package/dist/utilities/schemaValidator.d.ts.map +1 -1
- package/dist/utilities/schemaValidator.js +31 -102
- package/dist/validations/validateCep.d.ts +2 -2
- package/dist/validations/validateCep.js +2 -2
- package/dist/validations/validateCnpj.d.ts +2 -2
- package/dist/validations/validateCnpj.js +2 -2
- package/dist/validations/validateCpf.d.ts +4 -11
- package/dist/validations/validateCpf.d.ts.map +1 -1
- package/dist/validations/validateCpf.js +4 -11
- package/dist/validations/validateDate.d.ts +7 -11
- package/dist/validations/validateDate.d.ts.map +1 -1
- package/dist/validations/validateDate.js +7 -11
- package/dist/validations/validateEmail.d.ts +2 -2
- package/dist/validations/validateEmail.js +2 -2
- package/dist/validations/validatePassword.d.ts +2 -2
- package/dist/validations/validatePassword.js +2 -2
- package/dist/validations/validatePhone.d.ts +6 -18
- package/dist/validations/validatePhone.d.ts.map +1 -1
- package/dist/validations/validatePhone.js +6 -18
- package/dist/validations/validateRg.d.ts +2 -2
- package/dist/validations/validateRg.js +2 -2
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -7,48 +7,22 @@ import Qe from "node:dns";
|
|
|
7
7
|
import { countries as et } from "@arkyn/templates";
|
|
8
8
|
class ee {
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Adds a file name to the ignore list so it is skipped when resolving the caller in stack traces.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
* determining the actual caller of a function. This is useful when you have
|
|
14
|
-
* adapter or wrapper functions that you want to be transparent in the debug output.
|
|
15
|
-
*
|
|
16
|
-
* @param {string} file - The name of the file to ignore in stack traces (e.g., "httpAdapter.ts")
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* // Ignore the HTTP adapter file so debug shows the actual business logic caller
|
|
21
|
-
* DebugService.setIgnoreFile("httpAdapter.ts");
|
|
22
|
-
* ```
|
|
12
|
+
* @param file - File name to ignore (e.g. `"httpAdapter.ts"`).
|
|
23
13
|
*/
|
|
24
14
|
static setIgnoreFile(e) {
|
|
25
15
|
this.ignoreFiles.push(e);
|
|
26
16
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Clears all configured ignore files.
|
|
29
|
-
*
|
|
30
|
-
* This method resets the ignore file configuration, allowing all files to be
|
|
31
|
-
* considered in stack trace analysis again.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```typescript
|
|
35
|
-
* // Clear all ignore file configurations
|
|
36
|
-
* DebugService.clearIgnoreFiles();
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
17
|
+
/** Resets the ignore list, restoring full stack trace analysis. */
|
|
39
18
|
static clearIgnoreFiles() {
|
|
40
19
|
this.ignoreFiles = [];
|
|
41
20
|
}
|
|
42
21
|
/**
|
|
43
|
-
*
|
|
22
|
+
* Resolves the file path and function name of the code that triggered the current debug call,
|
|
23
|
+
* skipping internal node modules and any files registered with `setIgnoreFile`.
|
|
44
24
|
*
|
|
45
|
-
*
|
|
46
|
-
* of the caller. It excludes stack trace entries related to the `@arkyn/server` package
|
|
47
|
-
* and attempts to resolve the file path relative to the project root directory.
|
|
48
|
-
*
|
|
49
|
-
* @returns An object containing:
|
|
50
|
-
* - `functionName`: The name of the function that called the current function, or "Unknown function" if it cannot be determined.
|
|
51
|
-
* - `callerInfo`: The file path of the caller relative to the project root, or "Unknown caller" if it cannot be determined.
|
|
25
|
+
* @returns `{ functionName, callerInfo }` — caller function name and file path relative to `process.cwd()`.
|
|
52
26
|
*/
|
|
53
27
|
static getCaller() {
|
|
54
28
|
const e = process.cwd(), n = (new Error().stack || "").split(`
|
|
@@ -159,20 +133,13 @@ class p {
|
|
|
159
133
|
}
|
|
160
134
|
class tt extends p {
|
|
161
135
|
/**
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* @param {string} message - A descriptive message explaining the cause of the error.
|
|
165
|
-
* @param {any} cause - Optional additional information about the cause of the error.
|
|
136
|
+
* @param message - Error description sent in the response body and logged for debugging.
|
|
137
|
+
* @param cause - Optional extra context (serialized to JSON in the response).
|
|
166
138
|
*/
|
|
167
139
|
constructor(e, d) {
|
|
168
140
|
super(), this.name = "BadGateway", this.status = 502, this.statusText = e, this.cause = d ? JSON.stringify(d) : void 0, this.onDebug();
|
|
169
141
|
}
|
|
170
|
-
/**
|
|
171
|
-
* Converts the `BadGateway` 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 {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
175
|
-
*/
|
|
142
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
176
143
|
toResponse() {
|
|
177
144
|
const e = {
|
|
178
145
|
headers: { "Content-Type": "application/json" },
|
|
@@ -181,12 +148,7 @@ class tt extends p {
|
|
|
181
148
|
};
|
|
182
149
|
return new Response(JSON.stringify(this.makeBody()), e);
|
|
183
150
|
}
|
|
184
|
-
/**
|
|
185
|
-
* Converts the `BadGateway` 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 {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
189
|
-
*/
|
|
151
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
190
152
|
toJson() {
|
|
191
153
|
const e = {
|
|
192
154
|
status: this.status,
|
|
@@ -197,20 +159,13 @@ class tt extends p {
|
|
|
197
159
|
}
|
|
198
160
|
class V extends p {
|
|
199
161
|
/**
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
* @param {string} message - A descriptive message explaining the cause of the error.
|
|
203
|
-
* @param {any} cause - Optional additional information about the cause of the error.
|
|
162
|
+
* @param message - Error description.
|
|
163
|
+
* @param cause - Optional extra context (serialized to JSON).
|
|
204
164
|
*/
|
|
205
165
|
constructor(e, d) {
|
|
206
166
|
super(), this.name = "BadRequest", this.status = 400, this.statusText = e, this.cause = d ? JSON.stringify(d) : void 0, this.onDebug();
|
|
207
167
|
}
|
|
208
|
-
/**
|
|
209
|
-
* Converts the `BadRequest` instance into a `Response` object with a JSON body.
|
|
210
|
-
* This method ensures the response has the appropriate headers, status, and status text.
|
|
211
|
-
*
|
|
212
|
-
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
213
|
-
*/
|
|
168
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
214
169
|
toResponse() {
|
|
215
170
|
const e = {
|
|
216
171
|
headers: { "Content-Type": "application/json" },
|
|
@@ -219,12 +174,7 @@ class V extends p {
|
|
|
219
174
|
};
|
|
220
175
|
return new Response(JSON.stringify(this.makeBody()), e);
|
|
221
176
|
}
|
|
222
|
-
/**
|
|
223
|
-
* Converts the `BadRequest` instance into a `Response` object using the `Response.json` method.
|
|
224
|
-
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
225
|
-
*
|
|
226
|
-
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
227
|
-
*/
|
|
177
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
228
178
|
toJson() {
|
|
229
179
|
const e = {
|
|
230
180
|
status: this.status,
|
|
@@ -235,20 +185,13 @@ class V extends p {
|
|
|
235
185
|
}
|
|
236
186
|
class dt extends p {
|
|
237
187
|
/**
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* @param {string} message - A descriptive message explaining the cause of the conflict.
|
|
241
|
-
* @param {any} cause - Optional additional information about the cause of the conflict.
|
|
188
|
+
* @param message - Error description.
|
|
189
|
+
* @param cause - Optional extra context (serialized to JSON).
|
|
242
190
|
*/
|
|
243
191
|
constructor(e, d) {
|
|
244
192
|
super(), this.name = "Conflict", this.status = 409, this.statusText = e, this.debugColor = "yellow", this.cause = d ? JSON.stringify(d) : void 0, this.onDebug();
|
|
245
193
|
}
|
|
246
|
-
/**
|
|
247
|
-
* Converts the `Conflict` instance into a `Response` object with a JSON body.
|
|
248
|
-
* This method ensures the response has the appropriate headers, status, and status text.
|
|
249
|
-
*
|
|
250
|
-
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
251
|
-
*/
|
|
194
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
252
195
|
toResponse() {
|
|
253
196
|
const e = {
|
|
254
197
|
headers: { "Content-Type": "application/json" },
|
|
@@ -257,12 +200,7 @@ class dt extends p {
|
|
|
257
200
|
};
|
|
258
201
|
return new Response(JSON.stringify(this.makeBody()), e);
|
|
259
202
|
}
|
|
260
|
-
/**
|
|
261
|
-
* Converts the `Conflict` instance into a `Response` object using the `Response.json` method.
|
|
262
|
-
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
263
|
-
*
|
|
264
|
-
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
265
|
-
*/
|
|
203
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
266
204
|
toJson() {
|
|
267
205
|
const e = {
|
|
268
206
|
status: this.status,
|
|
@@ -273,20 +211,13 @@ class dt extends p {
|
|
|
273
211
|
}
|
|
274
212
|
class rt extends p {
|
|
275
213
|
/**
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
* @param {string} message - A descriptive message explaining why access is forbidden.
|
|
279
|
-
* @param {any} cause - Optional additional information about the cause of the error.
|
|
214
|
+
* @param message - Error description.
|
|
215
|
+
* @param cause - Optional extra context (serialized to JSON).
|
|
280
216
|
*/
|
|
281
217
|
constructor(e, d) {
|
|
282
218
|
super(), this.name = "Forbidden", this.status = 403, this.statusText = e, this.cause = d ? JSON.stringify(d) : void 0, this.onDebug();
|
|
283
219
|
}
|
|
284
|
-
/**
|
|
285
|
-
* Converts the `Forbidden` instance into a `Response` object with a JSON body.
|
|
286
|
-
* This method ensures the response has the appropriate headers, status, and status text.
|
|
287
|
-
*
|
|
288
|
-
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
289
|
-
*/
|
|
220
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
290
221
|
toResponse() {
|
|
291
222
|
const e = {
|
|
292
223
|
headers: { "Content-Type": "application/json" },
|
|
@@ -295,12 +226,7 @@ class rt extends p {
|
|
|
295
226
|
};
|
|
296
227
|
return new Response(JSON.stringify(this.makeBody()), e);
|
|
297
228
|
}
|
|
298
|
-
/**
|
|
299
|
-
* Converts the `Forbidden` instance into a `Response` object using the `Response.json` method.
|
|
300
|
-
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
301
|
-
*
|
|
302
|
-
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
303
|
-
*/
|
|
229
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
304
230
|
toJson() {
|
|
305
231
|
const e = {
|
|
306
232
|
status: this.status,
|
|
@@ -311,20 +237,13 @@ class rt extends p {
|
|
|
311
237
|
}
|
|
312
238
|
class nt extends p {
|
|
313
239
|
/**
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
* @param {string} message - A descriptive message explaining the reason the resource was not found.
|
|
317
|
-
* @param {any} cause - Optional additional information about the cause of the error.
|
|
240
|
+
* @param message - Error description.
|
|
241
|
+
* @param cause - Optional extra context (serialized to JSON).
|
|
318
242
|
*/
|
|
319
243
|
constructor(e, d) {
|
|
320
244
|
super(), this.name = "NotFound", this.status = 404, this.statusText = e, this.cause = d ? JSON.stringify(d) : void 0, this.onDebug();
|
|
321
245
|
}
|
|
322
|
-
/**
|
|
323
|
-
* Converts the `NotFound` instance into a `Response` object with a JSON body.
|
|
324
|
-
* This method ensures the response has the appropriate headers, status, and status text.
|
|
325
|
-
*
|
|
326
|
-
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
327
|
-
*/
|
|
246
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
328
247
|
toResponse() {
|
|
329
248
|
const e = {
|
|
330
249
|
headers: { "Content-Type": "application/json" },
|
|
@@ -333,12 +252,7 @@ class nt extends p {
|
|
|
333
252
|
};
|
|
334
253
|
return new Response(JSON.stringify(this.makeBody()), e);
|
|
335
254
|
}
|
|
336
|
-
/**
|
|
337
|
-
* Converts the `NotFound` instance into a `Response` object using the `Response.json` method.
|
|
338
|
-
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
339
|
-
*
|
|
340
|
-
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
341
|
-
*/
|
|
255
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
342
256
|
toJson() {
|
|
343
257
|
const e = {
|
|
344
258
|
status: this.status,
|
|
@@ -349,20 +263,13 @@ class nt extends p {
|
|
|
349
263
|
}
|
|
350
264
|
class st extends p {
|
|
351
265
|
/**
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
* @param {string} message - A descriptive message explaining why the functionality is not implemented.
|
|
355
|
-
* @param {any} cause - Optional additional information about the cause of the error.
|
|
266
|
+
* @param message - Error description.
|
|
267
|
+
* @param cause - Optional extra context (serialized to JSON).
|
|
356
268
|
*/
|
|
357
269
|
constructor(e, d) {
|
|
358
270
|
super(), this.name = "NotImplemented", this.status = 501, this.statusText = e, this.cause = d ? JSON.stringify(d) : void 0, this.onDebug();
|
|
359
271
|
}
|
|
360
|
-
/**
|
|
361
|
-
* Converts the `NotImplemented` instance into a `Response` object with a JSON body.
|
|
362
|
-
* This method ensures the response has the appropriate headers, status, and status text.
|
|
363
|
-
*
|
|
364
|
-
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
365
|
-
*/
|
|
272
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
366
273
|
toResponse() {
|
|
367
274
|
const e = {
|
|
368
275
|
headers: { "Content-Type": "application/json" },
|
|
@@ -371,12 +278,7 @@ class st extends p {
|
|
|
371
278
|
};
|
|
372
279
|
return new Response(JSON.stringify(this.makeBody()), e);
|
|
373
280
|
}
|
|
374
|
-
/**
|
|
375
|
-
* Converts the `NotImplemented` instance into a `Response` object using the `Response.json` method.
|
|
376
|
-
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
377
|
-
*
|
|
378
|
-
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
379
|
-
*/
|
|
281
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
380
282
|
toJson() {
|
|
381
283
|
const e = {
|
|
382
284
|
status: this.status,
|
|
@@ -387,20 +289,13 @@ class st extends p {
|
|
|
387
289
|
}
|
|
388
290
|
class W extends p {
|
|
389
291
|
/**
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
* @param {string} message - A descriptive message explaining the cause of the server error.
|
|
393
|
-
* @param {any} cause - Optional additional information about the cause of the error.
|
|
292
|
+
* @param message - Error description.
|
|
293
|
+
* @param cause - Optional extra context (serialized to JSON).
|
|
394
294
|
*/
|
|
395
295
|
constructor(e, d) {
|
|
396
296
|
super(), this.name = "ServerError", this.status = 500, this.statusText = e, this.cause = d ? JSON.stringify(d) : void 0, this.onDebug();
|
|
397
297
|
}
|
|
398
|
-
/**
|
|
399
|
-
* Converts the `ServerError` instance into a `Response` object with a JSON body.
|
|
400
|
-
* This method ensures the response has the appropriate headers, status, and status text.
|
|
401
|
-
*
|
|
402
|
-
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
403
|
-
*/
|
|
298
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
404
299
|
toResponse() {
|
|
405
300
|
const e = {
|
|
406
301
|
headers: { "Content-Type": "application/json" },
|
|
@@ -409,12 +304,7 @@ class W extends p {
|
|
|
409
304
|
};
|
|
410
305
|
return new Response(JSON.stringify(this.makeBody()), e);
|
|
411
306
|
}
|
|
412
|
-
/**
|
|
413
|
-
* Converts the `ServerError` instance into a `Response` object using the `Response.json` method.
|
|
414
|
-
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
415
|
-
*
|
|
416
|
-
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
417
|
-
*/
|
|
307
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
418
308
|
toJson() {
|
|
419
309
|
const e = {
|
|
420
310
|
status: this.status,
|
|
@@ -425,20 +315,13 @@ class W extends p {
|
|
|
425
315
|
}
|
|
426
316
|
class $t extends p {
|
|
427
317
|
/**
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
* @param message - A descriptive message explaining why the request is unauthorized.
|
|
431
|
-
* @param cause - Optional additional information about the cause of the error.
|
|
318
|
+
* @param message - Error description.
|
|
319
|
+
* @param cause - Optional extra context (serialized to JSON).
|
|
432
320
|
*/
|
|
433
321
|
constructor(e, d) {
|
|
434
322
|
super(), this.name = "Unauthorized", this.status = 401, this.statusText = e, this.debugColor = "yellow", this.cause = d ? JSON.stringify(d) : void 0, this.onDebug();
|
|
435
323
|
}
|
|
436
|
-
/**
|
|
437
|
-
* Converts the `Unauthorized` instance into a `Response` object with a JSON body.
|
|
438
|
-
* This method ensures the response has the appropriate headers, status, and status text.
|
|
439
|
-
*
|
|
440
|
-
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
441
|
-
*/
|
|
324
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
442
325
|
toResponse() {
|
|
443
326
|
const e = {
|
|
444
327
|
headers: { "Content-Type": "application/json" },
|
|
@@ -447,12 +330,7 @@ class $t extends p {
|
|
|
447
330
|
};
|
|
448
331
|
return new Response(JSON.stringify(this.makeBody()), e);
|
|
449
332
|
}
|
|
450
|
-
/**
|
|
451
|
-
* Converts the `Unauthorized` instance into a `Response` object using the `Response.json` method.
|
|
452
|
-
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
453
|
-
*
|
|
454
|
-
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
455
|
-
*/
|
|
333
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
456
334
|
toJson() {
|
|
457
335
|
const e = {
|
|
458
336
|
status: this.status,
|
|
@@ -463,13 +341,10 @@ class $t extends p {
|
|
|
463
341
|
}
|
|
464
342
|
class K extends p {
|
|
465
343
|
/**
|
|
466
|
-
*
|
|
467
|
-
*
|
|
468
|
-
* @param
|
|
469
|
-
* @param
|
|
470
|
-
* @param {Record<string, string>} [props.fieldErrors] - `fieldErrors`: A record of field-specific error messages.
|
|
471
|
-
* @param {Record<string, string>} [props.fields] - `fields`: A record of field values that caused the error.
|
|
472
|
-
* @param {string} [props.message] - `message`: A descriptive message explaining the error.
|
|
344
|
+
* @param props.message - Human-readable description of the error.
|
|
345
|
+
* @param props.fieldErrors - Per-field validation messages keyed by field name.
|
|
346
|
+
* @param props.fields - Original submitted field values (useful for repopulating forms).
|
|
347
|
+
* @param props.data - Any extra data to include in the response body.
|
|
473
348
|
*/
|
|
474
349
|
constructor(e) {
|
|
475
350
|
super(), this.name = "UnprocessableEntity", this.status = 422, this.statusText = e.message || "Unprocessable entity", this.debugColor = "yellow", this.cause = {
|
|
@@ -478,12 +353,7 @@ class K extends p {
|
|
|
478
353
|
fields: e.fields
|
|
479
354
|
}, this.onDebug();
|
|
480
355
|
}
|
|
481
|
-
/**
|
|
482
|
-
* Converts the `UnprocessableEntity` instance into a `Response` object with a JSON body.
|
|
483
|
-
* This method ensures the response has the appropriate headers, status, and status text.
|
|
484
|
-
*
|
|
485
|
-
* @returns {Response} A `Response` object with the serialized JSON body and response metadata.
|
|
486
|
-
*/
|
|
356
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
487
357
|
toResponse() {
|
|
488
358
|
const e = {
|
|
489
359
|
headers: { "Content-Type": "application/json" },
|
|
@@ -492,12 +362,7 @@ class K extends p {
|
|
|
492
362
|
};
|
|
493
363
|
return new Response(JSON.stringify(this.makeBody()), e);
|
|
494
364
|
}
|
|
495
|
-
/**
|
|
496
|
-
* Converts the `UnprocessableEntity` instance into a `Response` object using the `Response.json` method.
|
|
497
|
-
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
498
|
-
*
|
|
499
|
-
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
500
|
-
*/
|
|
365
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
501
366
|
toJson() {
|
|
502
367
|
const e = {
|
|
503
368
|
status: this.status,
|
|
@@ -569,18 +434,13 @@ class A {
|
|
|
569
434
|
}
|
|
570
435
|
class it extends A {
|
|
571
436
|
/**
|
|
572
|
-
*
|
|
573
|
-
*
|
|
574
|
-
* @param {string} message - A message describing the creation status.
|
|
575
|
-
* @param {any} body - The response body to be included in the HTTP response.
|
|
437
|
+
* @param message - Description included in the response status text.
|
|
438
|
+
* @param body - Data to include in the response body.
|
|
576
439
|
*/
|
|
577
440
|
constructor(e, d) {
|
|
578
441
|
super(), this.name = "Created", this.status = 201, this.statusText = e, this.body = d || void 0, this.onDebug();
|
|
579
442
|
}
|
|
580
|
-
/**
|
|
581
|
-
* Converts the `Created` instance into a `Response` object.
|
|
582
|
-
* @returns {Response} A `Response` object with the body and response metadata.
|
|
583
|
-
*/
|
|
443
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
584
444
|
toResponse() {
|
|
585
445
|
const e = {
|
|
586
446
|
headers: { "Content-Type": "application/json" },
|
|
@@ -589,11 +449,7 @@ class it extends A {
|
|
|
589
449
|
};
|
|
590
450
|
return new Response(JSON.stringify(this.body), e);
|
|
591
451
|
}
|
|
592
|
-
/**
|
|
593
|
-
* Converts the `Created` instance into a `Response` object using the `Response.json` method.
|
|
594
|
-
* This method is an alternative to `toResponse` for generating JSON responses.
|
|
595
|
-
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
596
|
-
*/
|
|
452
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
597
453
|
toJson() {
|
|
598
454
|
const e = {
|
|
599
455
|
status: this.status,
|
|
@@ -604,18 +460,13 @@ class it extends A {
|
|
|
604
460
|
}
|
|
605
461
|
class ot extends A {
|
|
606
462
|
/**
|
|
607
|
-
*
|
|
608
|
-
*
|
|
609
|
-
* @param {string} message - A message describing the creation status.
|
|
610
|
-
* @param {any} body - The response body to be included in the HTTP response.
|
|
463
|
+
* @param message - Description included in the response status text.
|
|
464
|
+
* @param body - Data to include in the response body.
|
|
611
465
|
*/
|
|
612
466
|
constructor(e, d) {
|
|
613
467
|
super(), this.name = "Found", this.status = 302, this.statusText = e, this.body = d || void 0, this.onDebug();
|
|
614
468
|
}
|
|
615
|
-
/**
|
|
616
|
-
* Converts the `Found` instance into a `Response` object.
|
|
617
|
-
* @returns {Response} A `Response` object with the body and response metadata.
|
|
618
|
-
*/
|
|
469
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
619
470
|
toResponse() {
|
|
620
471
|
const e = {
|
|
621
472
|
headers: { "Content-Type": "application/json" },
|
|
@@ -624,11 +475,7 @@ class ot extends A {
|
|
|
624
475
|
};
|
|
625
476
|
return new Response(JSON.stringify(this.body), e);
|
|
626
477
|
}
|
|
627
|
-
/**
|
|
628
|
-
* Converts the `Found` instance into a `Response` object using the `Response.json` method.
|
|
629
|
-
* This method is an alternative to `toResponse` for generating JSON responses.
|
|
630
|
-
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
631
|
-
*/
|
|
478
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
632
479
|
toJson() {
|
|
633
480
|
const e = {
|
|
634
481
|
status: this.status,
|
|
@@ -639,16 +486,12 @@ class ot extends A {
|
|
|
639
486
|
}
|
|
640
487
|
class at extends A {
|
|
641
488
|
/**
|
|
642
|
-
*
|
|
643
|
-
* @param {string} message - A message describing the creation status.
|
|
489
|
+
* @param message - Description included in the response status text.
|
|
644
490
|
*/
|
|
645
491
|
constructor(e) {
|
|
646
492
|
super(), this.name = "NoContent", this.status = 204, this.statusText = e, this.onDebug();
|
|
647
493
|
}
|
|
648
|
-
/**
|
|
649
|
-
* Converts the `NoContent` instance into a `Response` object.
|
|
650
|
-
* @returns {Response} A `Response` object with the body and response metadata.
|
|
651
|
-
*/
|
|
494
|
+
/** Converts to a `Response` with `Content-Type: application/json` header and no body. */
|
|
652
495
|
toResponse() {
|
|
653
496
|
const e = {
|
|
654
497
|
headers: { "Content-Type": "application/json" },
|
|
@@ -660,18 +503,13 @@ class at extends A {
|
|
|
660
503
|
}
|
|
661
504
|
class ut extends A {
|
|
662
505
|
/**
|
|
663
|
-
*
|
|
664
|
-
*
|
|
665
|
-
* @param {string} message - A message describing the creation status.
|
|
666
|
-
* @param {any} body - The response body to be included in the HTTP response.
|
|
506
|
+
* @param message - Description included in the response status text.
|
|
507
|
+
* @param body - Data to include in the response body.
|
|
667
508
|
*/
|
|
668
509
|
constructor(e, d) {
|
|
669
510
|
super(), this.name = "Success", this.status = 200, this.statusText = e, this.body = d || void 0, this.onDebug();
|
|
670
511
|
}
|
|
671
|
-
/**
|
|
672
|
-
* Converts the `Success` instance into a `Response` object.
|
|
673
|
-
* @returns {Response} A `Response` object with the body and response metadata.
|
|
674
|
-
*/
|
|
512
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
675
513
|
toResponse() {
|
|
676
514
|
const e = {
|
|
677
515
|
headers: { "Content-Type": "application/json" },
|
|
@@ -680,11 +518,7 @@ class ut extends A {
|
|
|
680
518
|
};
|
|
681
519
|
return new Response(JSON.stringify(this.body), e);
|
|
682
520
|
}
|
|
683
|
-
/**
|
|
684
|
-
* Converts the `Success` instance into a `Response` object using the `Response.json` method.
|
|
685
|
-
* This method is an alternative to `toResponse` for generating JSON responses.
|
|
686
|
-
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
687
|
-
*/
|
|
521
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
688
522
|
toJson() {
|
|
689
523
|
const e = {
|
|
690
524
|
status: this.status,
|
|
@@ -695,18 +529,13 @@ class ut extends A {
|
|
|
695
529
|
}
|
|
696
530
|
class lt extends A {
|
|
697
531
|
/**
|
|
698
|
-
*
|
|
699
|
-
*
|
|
700
|
-
* @param {string} message - A message describing the creation status.
|
|
701
|
-
* @param {any} body - The response body to be included in the HTTP response.
|
|
532
|
+
* @param message - Description included in the response status text.
|
|
533
|
+
* @param body - Data to include in the response body.
|
|
702
534
|
*/
|
|
703
535
|
constructor(e, d) {
|
|
704
536
|
super(), this.name = "Updated", this.status = 200, this.statusText = e, this.body = d || void 0, this.onDebug();
|
|
705
537
|
}
|
|
706
|
-
/**
|
|
707
|
-
* Converts the `Updated` instance into a `Response` object.
|
|
708
|
-
* @returns {Response} A `Response` object with the body and response metadata.
|
|
709
|
-
*/
|
|
538
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
710
539
|
toResponse() {
|
|
711
540
|
const e = {
|
|
712
541
|
headers: { "Content-Type": "application/json" },
|
|
@@ -715,11 +544,7 @@ class lt extends A {
|
|
|
715
544
|
};
|
|
716
545
|
return new Response(JSON.stringify(this.body), e);
|
|
717
546
|
}
|
|
718
|
-
/**
|
|
719
|
-
* Converts the `Updated` instance into a `Response` object using the `Response.json` method.
|
|
720
|
-
* This method is an alternative to `toResponse` for generating JSON responses.
|
|
721
|
-
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
722
|
-
*/
|
|
547
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
723
548
|
toJson() {
|
|
724
549
|
const e = {
|
|
725
550
|
status: this.status,
|
|
@@ -779,23 +604,18 @@ class ct {
|
|
|
779
604
|
}
|
|
780
605
|
class Fe {
|
|
781
606
|
/**
|
|
782
|
-
* Sets the log service configuration
|
|
783
|
-
* If the configuration is already set, the call is ignored.
|
|
607
|
+
* Sets the log service configuration once. Subsequent calls are ignored.
|
|
784
608
|
*
|
|
785
|
-
* @param
|
|
786
|
-
* @param
|
|
787
|
-
* @param
|
|
788
|
-
* @param {string} [config.logBaseApiUrl] - Optional base URL for the log service.
|
|
609
|
+
* @param config.trafficSourceId - Traffic source identifier.
|
|
610
|
+
* @param config.userToken - User token for authentication.
|
|
611
|
+
* @param config.logBaseApiUrl - Override the default log ingestion base URL.
|
|
789
612
|
*/
|
|
790
613
|
static setConfig(e) {
|
|
791
614
|
if (this.config) return;
|
|
792
615
|
const { trafficSourceId: d, userToken: r, logBaseApiUrl: n } = e, $ = `${n || "http://62.238.8.44:8081"}/ingest-log`;
|
|
793
616
|
this.config = { trafficSourceId: d, userToken: r, apiUrl: $ };
|
|
794
617
|
}
|
|
795
|
-
/**
|
|
796
|
-
* Returns the current service configuration, if it exists.
|
|
797
|
-
* @returns {{ trafficSourceId: string; userToken: string; apiUrl: string } | undefined} The stored configuration or `undefined` if not set.
|
|
798
|
-
*/
|
|
618
|
+
/** Returns the stored configuration, or `undefined` if `setConfig` has not been called. */
|
|
799
619
|
static getConfig() {
|
|
800
620
|
return this.config;
|
|
801
621
|
}
|
|
@@ -1210,68 +1030,34 @@ function Pt(t) {
|
|
|
1210
1030
|
}
|
|
1211
1031
|
class od {
|
|
1212
1032
|
/**
|
|
1213
|
-
*
|
|
1214
|
-
* @param {T} schema - The Zod schema to use for validation.
|
|
1033
|
+
* @param schema - The Zod schema used for all validation methods on this instance.
|
|
1215
1034
|
*/
|
|
1216
1035
|
constructor(e) {
|
|
1217
1036
|
this.schema = e;
|
|
1218
1037
|
}
|
|
1219
1038
|
/**
|
|
1220
|
-
*
|
|
1039
|
+
* Returns `true` if the data satisfies the schema, `false` otherwise. Never throws.
|
|
1221
1040
|
*
|
|
1222
|
-
* @param
|
|
1223
|
-
*
|
|
1224
|
-
* @returns {boolean} True if the data is valid, false otherwise.
|
|
1225
|
-
*
|
|
1226
|
-
* @example
|
|
1227
|
-
* ```typescript
|
|
1228
|
-
* const validator = new SchemaValidator(userSchema);
|
|
1229
|
-
* const isValid = validator.isValid({ name: "John", email: "invalid-email" });
|
|
1230
|
-
* console.log(isValid); // false
|
|
1231
|
-
* ```
|
|
1041
|
+
* @param data - The value to check.
|
|
1232
1042
|
*/
|
|
1233
1043
|
isValid(e) {
|
|
1234
1044
|
return this.schema.safeParse(e).success;
|
|
1235
1045
|
}
|
|
1236
1046
|
/**
|
|
1237
|
-
*
|
|
1047
|
+
* Validates data and returns the raw Zod `safeParseResult` without throwing.
|
|
1048
|
+
* Useful when you need access to the full error details.
|
|
1238
1049
|
*
|
|
1239
|
-
* @param
|
|
1240
|
-
* @returns {z.ZodSafeParseResult<z.infer<T>>} The Zod safe parse result containing success status and data or error.
|
|
1241
|
-
*
|
|
1242
|
-
* @example
|
|
1243
|
-
* ```typescript
|
|
1244
|
-
* const validator = new SchemaValidator(userSchema);
|
|
1245
|
-
* const result = validator.safeValidate({ name: "", email: "john@example.com" });
|
|
1246
|
-
*
|
|
1247
|
-
* if (result.success) {
|
|
1248
|
-
* console.log(result.data); // Validated data
|
|
1249
|
-
* } else {
|
|
1250
|
-
* console.log(result.error.issues); // Validation errors
|
|
1251
|
-
* }
|
|
1252
|
-
* ```
|
|
1050
|
+
* @param data - The value to validate.
|
|
1253
1051
|
*/
|
|
1254
1052
|
safeValidate(e) {
|
|
1255
1053
|
return this.schema.safeParse(e);
|
|
1256
1054
|
}
|
|
1257
1055
|
/**
|
|
1258
|
-
* Validates data and returns the
|
|
1056
|
+
* Validates data and returns the typed result, throwing `ServerError` on failure.
|
|
1057
|
+
* Use for validating internal/trusted data (e.g. env vars, config objects).
|
|
1259
1058
|
*
|
|
1260
|
-
* @param
|
|
1261
|
-
* @throws
|
|
1262
|
-
* @returns {z.infer<T>} The validated and parsed data.
|
|
1263
|
-
*
|
|
1264
|
-
* @example
|
|
1265
|
-
* ```typescript
|
|
1266
|
-
* const validator = new SchemaValidator(userSchema);
|
|
1267
|
-
*
|
|
1268
|
-
* try {
|
|
1269
|
-
* const validUser = validator.validate({ name: "John", email: "john@example.com", age: 25 });
|
|
1270
|
-
* console.log(validUser); // { name: "John", email: "john@example.com", age: 25 }
|
|
1271
|
-
* } catch (error) {
|
|
1272
|
-
* console.error(error.message); // "Error validating:\n-> name: String must contain at least 1 character(s)"
|
|
1273
|
-
* }
|
|
1274
|
-
* ```
|
|
1059
|
+
* @param data - The value to validate.
|
|
1060
|
+
* @throws `ServerError` with a formatted field-by-field error message.
|
|
1275
1061
|
*/
|
|
1276
1062
|
validate(e) {
|
|
1277
1063
|
try {
|
|
@@ -1281,26 +1067,17 @@ class od {
|
|
|
1281
1067
|
}
|
|
1282
1068
|
}
|
|
1283
1069
|
/**
|
|
1284
|
-
* Validates form data and returns the
|
|
1285
|
-
*
|
|
1070
|
+
* Validates form data and returns the typed result, throwing `UnprocessableEntity` on failure.
|
|
1071
|
+
* The error includes `fieldErrors`, `fields`, and `data.scrollTo` (first failing field name).
|
|
1286
1072
|
*
|
|
1287
|
-
* @param
|
|
1288
|
-
* @param
|
|
1289
|
-
* @throws
|
|
1290
|
-
* @returns {z.infer<T>} The validated and parsed form data.
|
|
1073
|
+
* @param data - The raw form data to validate.
|
|
1074
|
+
* @param message - Optional human-readable error message for the 422 response.
|
|
1075
|
+
* @throws `UnprocessableEntity` with structured field errors for client-side form handling.
|
|
1291
1076
|
*
|
|
1292
1077
|
* @example
|
|
1293
1078
|
* ```typescript
|
|
1294
|
-
* const validator = new SchemaValidator(
|
|
1295
|
-
*
|
|
1296
|
-
* try {
|
|
1297
|
-
* const validFormData = validator.formValidate(requestBody, "User data is invalid");
|
|
1298
|
-
* console.log(validFormData);
|
|
1299
|
-
* } catch (error) {
|
|
1300
|
-
* // UnprocessableEntity with fieldErrors, fields, and scrollTo data
|
|
1301
|
-
* console.log(error.fieldErrors); // { name: "Name is required", email: "Invalid email" }
|
|
1302
|
-
* console.log(error.data.scrollTo); // "name" (first error field)
|
|
1303
|
-
* }
|
|
1079
|
+
* const validator = new SchemaValidator(registerSchema);
|
|
1080
|
+
* const body = validator.formValidate(await decodeRequestBody(request));
|
|
1304
1081
|
* ```
|
|
1305
1082
|
*/
|
|
1306
1083
|
formValidate(e, d) {
|
|
@@ -1317,26 +1094,16 @@ class od {
|
|
|
1317
1094
|
return r.data;
|
|
1318
1095
|
}
|
|
1319
1096
|
/**
|
|
1320
|
-
*
|
|
1321
|
-
* This method is the async version of formValidate, designed for form validation with async schemas.
|
|
1097
|
+
* Async version of `formValidate` for schemas with async refinements (e.g. uniqueness checks).
|
|
1322
1098
|
*
|
|
1323
|
-
* @param
|
|
1324
|
-
* @param
|
|
1325
|
-
* @throws
|
|
1326
|
-
* @returns {Promise<z.infer<T>>} A promise that resolves to the validated and parsed form data.
|
|
1099
|
+
* @param data - The raw form data to validate.
|
|
1100
|
+
* @param message - Optional human-readable error message for the 422 response.
|
|
1101
|
+
* @throws `UnprocessableEntity` with structured field errors for client-side form handling.
|
|
1327
1102
|
*
|
|
1328
1103
|
* @example
|
|
1329
1104
|
* ```typescript
|
|
1330
|
-
* const validator = new SchemaValidator(
|
|
1331
|
-
*
|
|
1332
|
-
* try {
|
|
1333
|
-
* const validFormData = await validator.formAsyncValidate(requestBody, "User data is invalid");
|
|
1334
|
-
* console.log(validFormData);
|
|
1335
|
-
* } catch (error) {
|
|
1336
|
-
* // UnprocessableEntity with fieldErrors, fields, and scrollTo data
|
|
1337
|
-
* console.log(error.fieldErrors); // { name: "Name is required", email: "Invalid email" }
|
|
1338
|
-
* console.log(error.data.scrollTo); // "name" (first error field)
|
|
1339
|
-
* }
|
|
1105
|
+
* const validator = new SchemaValidator(registerSchema);
|
|
1106
|
+
* const body = await validator.formAsyncValidate(await decodeRequestBody(request));
|
|
1340
1107
|
* ```
|
|
1341
1108
|
*/
|
|
1342
1109
|
async formAsyncValidate(e, d) {
|