@arkyn/server 3.0.1-beta.8 → 3.0.1-beta.80

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