@arkyn/server 3.0.1-beta.168 → 3.0.1-beta.172

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 (134) hide show
  1. package/dist/http/api/_logRequest.d.ts +58 -0
  2. package/dist/http/api/_logRequest.d.ts.map +1 -0
  3. package/dist/http/api/_makeRequest.d.ts +61 -0
  4. package/dist/http/api/_makeRequest.d.ts.map +1 -0
  5. package/dist/http/api/deleteRequest.d.ts +17 -0
  6. package/dist/http/api/deleteRequest.d.ts.map +1 -0
  7. package/dist/http/api/getRequest.d.ts +16 -0
  8. package/dist/http/api/getRequest.d.ts.map +1 -0
  9. package/dist/http/api/patchRequest.d.ts +17 -0
  10. package/dist/http/api/patchRequest.d.ts.map +1 -0
  11. package/dist/http/api/postRequest.d.ts +17 -0
  12. package/dist/http/api/postRequest.d.ts.map +1 -0
  13. package/dist/http/api/putRequest.d.ts +17 -0
  14. package/dist/http/api/putRequest.d.ts.map +1 -0
  15. package/dist/http/badResponses/_badResponse.d.ts +25 -0
  16. package/dist/http/badResponses/_badResponse.d.ts.map +1 -0
  17. package/dist/http/badResponses/badGateway.d.ts +24 -0
  18. package/dist/http/badResponses/badGateway.d.ts.map +1 -0
  19. package/dist/http/badResponses/badRequest.d.ts +22 -0
  20. package/dist/http/badResponses/badRequest.d.ts.map +1 -0
  21. package/dist/http/badResponses/conflict.d.ts +22 -0
  22. package/dist/http/badResponses/conflict.d.ts.map +1 -0
  23. package/dist/http/badResponses/forbidden.d.ts +22 -0
  24. package/dist/http/badResponses/forbidden.d.ts.map +1 -0
  25. package/dist/http/badResponses/notFound.d.ts +22 -0
  26. package/dist/http/badResponses/notFound.d.ts.map +1 -0
  27. package/dist/http/badResponses/notImplemented.d.ts +22 -0
  28. package/dist/http/badResponses/notImplemented.d.ts.map +1 -0
  29. package/dist/http/badResponses/serverError.d.ts +22 -0
  30. package/dist/http/badResponses/serverError.d.ts.map +1 -0
  31. package/dist/http/badResponses/unauthorized.d.ts +22 -0
  32. package/dist/http/badResponses/unauthorized.d.ts.map +1 -0
  33. package/dist/http/badResponses/unprocessableEntity.d.ts +34 -0
  34. package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -0
  35. package/dist/http/successResponses/_successResponse.d.ts +36 -0
  36. package/dist/http/successResponses/_successResponse.d.ts.map +1 -0
  37. package/dist/http/successResponses/created.d.ts +22 -0
  38. package/dist/http/successResponses/created.d.ts.map +1 -0
  39. package/dist/http/successResponses/found.d.ts +22 -0
  40. package/dist/http/successResponses/found.d.ts.map +1 -0
  41. package/dist/http/successResponses/noContent.d.ts +20 -0
  42. package/dist/http/successResponses/noContent.d.ts.map +1 -0
  43. package/dist/http/successResponses/success.d.ts +22 -0
  44. package/dist/http/successResponses/success.d.ts.map +1 -0
  45. package/dist/http/successResponses/updated.d.ts +23 -0
  46. package/dist/http/successResponses/updated.d.ts.map +1 -0
  47. package/dist/index.d.ts +34 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +1067 -0
  50. package/dist/modules/http/api/_logRequest.js +56 -0
  51. package/dist/modules/http/api/_makeRequest.js +70 -0
  52. package/dist/modules/http/api/deleteRequest.js +13 -0
  53. package/dist/modules/http/api/getRequest.js +12 -0
  54. package/dist/modules/http/api/patchRequest.js +13 -0
  55. package/dist/modules/http/api/postRequest.js +13 -0
  56. package/dist/modules/http/api/putRequest.js +13 -0
  57. package/dist/modules/http/badResponses/_badResponse.js +63 -0
  58. package/dist/modules/http/badResponses/badGateway.js +24 -0
  59. package/dist/modules/http/badResponses/badRequest.js +24 -0
  60. package/dist/modules/http/badResponses/conflict.js +24 -0
  61. package/dist/modules/http/badResponses/forbidden.js +24 -0
  62. package/dist/modules/http/badResponses/notFound.js +24 -0
  63. package/dist/modules/http/badResponses/notImplemented.js +24 -0
  64. package/dist/modules/http/badResponses/serverError.js +24 -0
  65. package/dist/modules/http/badResponses/unauthorized.js +24 -0
  66. package/dist/modules/http/badResponses/unprocessableEntity.js +28 -0
  67. package/dist/modules/http/successResponses/_successResponse.js +62 -0
  68. package/dist/modules/http/successResponses/created.js +24 -0
  69. package/dist/modules/http/successResponses/found.js +24 -0
  70. package/dist/modules/http/successResponses/noContent.js +17 -0
  71. package/dist/modules/http/successResponses/success.js +24 -0
  72. package/dist/modules/http/successResponses/updated.js +24 -0
  73. package/dist/modules/index.js +34 -0
  74. package/dist/modules/services/apiService.js +109 -0
  75. package/dist/modules/services/debugService.js +36 -0
  76. package/dist/modules/services/logMapperService.js +31 -0
  77. package/dist/modules/services/logService.js +21 -0
  78. package/dist/modules/utilities/decodeRequestBody.js +20 -0
  79. package/dist/modules/utilities/decodeRequestErrorMessage.js +6 -0
  80. package/dist/modules/utilities/errorHandler.js +39 -0
  81. package/dist/modules/utilities/flushDebugLogs.js +16 -0
  82. package/dist/modules/utilities/formAsyncParse.js +14 -0
  83. package/dist/modules/utilities/formParse.js +14 -0
  84. package/dist/modules/utilities/getScopedParams.js +9 -0
  85. package/dist/modules/utilities/schemaValidator.js +55 -0
  86. package/dist/modules/validations/validateCep.js +9 -0
  87. package/dist/modules/validations/validateCnpj.js +54 -0
  88. package/dist/modules/validations/validateCpf.js +27 -0
  89. package/dist/modules/validations/validateDate.js +26 -0
  90. package/dist/modules/validations/validateEmail.js +54 -0
  91. package/dist/modules/validations/validatePassword.js +12 -0
  92. package/dist/modules/validations/validatePhone.js +10 -0
  93. package/dist/modules/validations/validateRg.js +8 -0
  94. package/dist/services/apiService.d.ts +83 -0
  95. package/dist/services/apiService.d.ts.map +1 -0
  96. package/dist/services/debugService.d.ts +37 -0
  97. package/dist/services/debugService.d.ts.map +1 -0
  98. package/dist/services/logMapperService.d.ts +86 -0
  99. package/dist/services/logMapperService.d.ts.map +1 -0
  100. package/dist/services/logService.d.ts +33 -0
  101. package/dist/services/logService.d.ts.map +1 -0
  102. package/dist/utilities/decodeRequestBody.d.ts +18 -0
  103. package/dist/utilities/decodeRequestBody.d.ts.map +1 -0
  104. package/dist/utilities/decodeRequestErrorMessage.d.ts +19 -0
  105. package/dist/utilities/decodeRequestErrorMessage.d.ts.map +1 -0
  106. package/dist/utilities/errorHandler.d.ts +25 -0
  107. package/dist/utilities/errorHandler.d.ts.map +1 -0
  108. package/dist/utilities/flushDebugLogs.d.ts +24 -0
  109. package/dist/utilities/flushDebugLogs.d.ts.map +1 -0
  110. package/dist/utilities/formAsyncParse.d.ts +38 -0
  111. package/dist/utilities/formAsyncParse.d.ts.map +1 -0
  112. package/dist/utilities/formParse.d.ts +38 -0
  113. package/dist/utilities/formParse.d.ts.map +1 -0
  114. package/dist/utilities/getScopedParams.d.ts +19 -0
  115. package/dist/utilities/getScopedParams.d.ts.map +1 -0
  116. package/dist/utilities/schemaValidator.d.ts +75 -0
  117. package/dist/utilities/schemaValidator.d.ts.map +1 -0
  118. package/dist/validations/validateCep.d.ts +19 -0
  119. package/dist/validations/validateCep.d.ts.map +1 -0
  120. package/dist/validations/validateCnpj.d.ts +21 -0
  121. package/dist/validations/validateCnpj.d.ts.map +1 -0
  122. package/dist/validations/validateCpf.d.ts +16 -0
  123. package/dist/validations/validateCpf.d.ts.map +1 -0
  124. package/dist/validations/validateDate.d.ts +23 -0
  125. package/dist/validations/validateDate.d.ts.map +1 -0
  126. package/dist/validations/validateEmail.d.ts +21 -0
  127. package/dist/validations/validateEmail.d.ts.map +1 -0
  128. package/dist/validations/validatePassword.d.ts +20 -0
  129. package/dist/validations/validatePassword.d.ts.map +1 -0
  130. package/dist/validations/validatePhone.d.ts +16 -0
  131. package/dist/validations/validatePhone.d.ts.map +1 -0
  132. package/dist/validations/validateRg.d.ts +21 -0
  133. package/dist/validations/validateRg.d.ts.map +1 -0
  134. package/package.json +17 -7
package/dist/index.js ADDED
@@ -0,0 +1,1067 @@
1
+ import { ValidateDateService as e, formatJsonObject as t, formatJsonString as n, removeNonNumeric as r } from "@arkyn/shared";
2
+ import i from "node:path";
3
+ import a from "node:dns";
4
+ import { countries as o } from "@arkyn/templates";
5
+ import { isValidPhoneNumber as s, parsePhoneNumberWithError as c } from "libphonenumber-js";
6
+ //#region src/services/debugService.ts
7
+ var l = class e {
8
+ static ignoreFiles = [];
9
+ static setIgnoreFile(t) {
10
+ e.ignoreFiles.push(t);
11
+ }
12
+ static clearIgnoreFiles() {
13
+ e.ignoreFiles = [];
14
+ }
15
+ static getCaller() {
16
+ let t = process.cwd(), n = ((/* @__PURE__ */ Error()).stack || "").split("\n").map((e) => e.trim()), r = 2;
17
+ for (; r < n.length && (n[r].includes("node:internal") || n[r].includes("/node_modules/"));) r++;
18
+ if (e.ignoreFiles.length > 0) for (; r < n.length && e.ignoreFiles.some((e) => n[r].includes(e));) r++;
19
+ let a = n[r] || "", o = "Unknown function", s = "Unknown caller", c = a.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);
20
+ if (c) o = c[1], s = c[2];
21
+ else {
22
+ let e = a.match(/at\s+(.+)/);
23
+ if (e) {
24
+ s = e[1];
25
+ let t = s.match(/at\s+([^(\s]+)\s+/);
26
+ t && t[1] !== "new" && (o = t[1]);
27
+ }
28
+ }
29
+ s.includes("(") && (s = s.substring(s.indexOf("(") + 1, s.lastIndexOf(")"))), s = s.split(":").slice(0, -2).join(":");
30
+ try {
31
+ s = i.relative(t, s);
32
+ } catch {}
33
+ return {
34
+ functionName: o,
35
+ callerInfo: s
36
+ };
37
+ }
38
+ };
39
+ //#endregion
40
+ //#region src/utilities/flushDebugLogs.ts
41
+ function u(e) {
42
+ if (process.env.NODE_ENV === "development" || process.env?.DEBUG_MODE === "true") {
43
+ let t = `${{
44
+ yellow: "\x1B[33m",
45
+ cyan: "\x1B[36m",
46
+ red: "\x1B[31m",
47
+ green: "\x1B[32m"
48
+ }[e.scheme]}[${e.name}]`, n = "\n";
49
+ e.debugs.forEach((r, i) => {
50
+ n += `${t} ${r.trim()}`, i < e.debugs.length - 1 && (n += "\n");
51
+ }), console.log(n);
52
+ }
53
+ }
54
+ //#endregion
55
+ //#region src/http/badResponses/_badResponse.ts
56
+ var d = class {
57
+ _cause;
58
+ _name = "BadResponse";
59
+ _status = 500;
60
+ _statusText = "Unknown error";
61
+ _debugColor = "red";
62
+ get cause() {
63
+ return this._cause;
64
+ }
65
+ set cause(e) {
66
+ this._cause = e;
67
+ }
68
+ get name() {
69
+ return this._name;
70
+ }
71
+ set name(e) {
72
+ this._name = e;
73
+ }
74
+ get status() {
75
+ return this._status;
76
+ }
77
+ set status(e) {
78
+ this._status = e;
79
+ }
80
+ get statusText() {
81
+ return this._statusText;
82
+ }
83
+ set statusText(e) {
84
+ this._statusText = e;
85
+ }
86
+ get debugColor() {
87
+ return this._debugColor;
88
+ }
89
+ set debugColor(e) {
90
+ [
91
+ "green",
92
+ "yellow",
93
+ "cyan",
94
+ "red"
95
+ ].includes(e) && (this._debugColor = e);
96
+ }
97
+ onDebug() {
98
+ let e = [], { callerInfo: t, functionName: r } = l.getCaller();
99
+ e.push(`Caller Function: ${r}`), e.push(`Caller Location: ${t}`), this._statusText && e.push(`Message: ${this._statusText}`), this._cause && e.push(`Cause: ${n(JSON.stringify(this._cause))}`), u({
100
+ scheme: "red",
101
+ name: this._name,
102
+ debugs: e
103
+ });
104
+ }
105
+ makeBody() {
106
+ return {
107
+ name: this._name,
108
+ message: this._statusText,
109
+ cause: this._cause
110
+ };
111
+ }
112
+ }, f = class extends d {
113
+ constructor(e, t) {
114
+ super(), this.name = "BadGateway", this.status = 502, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
115
+ }
116
+ toResponse() {
117
+ let e = {
118
+ headers: { "Content-Type": "application/json" },
119
+ status: this.status,
120
+ statusText: this.statusText
121
+ };
122
+ return new Response(JSON.stringify(this.makeBody()), e);
123
+ }
124
+ toJson() {
125
+ let e = {
126
+ status: this.status,
127
+ statusText: this.statusText
128
+ };
129
+ return Response.json(this.makeBody(), e);
130
+ }
131
+ }, p = class extends d {
132
+ constructor(e, t) {
133
+ super(), this.name = "BadRequest", this.status = 400, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
134
+ }
135
+ toResponse() {
136
+ let e = {
137
+ headers: { "Content-Type": "application/json" },
138
+ status: this.status,
139
+ statusText: this.statusText
140
+ };
141
+ return new Response(JSON.stringify(this.makeBody()), e);
142
+ }
143
+ toJson() {
144
+ let e = {
145
+ status: this.status,
146
+ statusText: this.statusText
147
+ };
148
+ return Response.json(this.makeBody(), e);
149
+ }
150
+ }, m = class extends d {
151
+ constructor(e, t) {
152
+ super(), this.name = "Conflict", this.status = 409, this.statusText = e, this.debugColor = "yellow", this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
153
+ }
154
+ toResponse() {
155
+ let e = {
156
+ headers: { "Content-Type": "application/json" },
157
+ status: this.status,
158
+ statusText: this.statusText
159
+ };
160
+ return new Response(JSON.stringify(this.makeBody()), e);
161
+ }
162
+ toJson() {
163
+ let e = {
164
+ status: this.status,
165
+ statusText: this.statusText
166
+ };
167
+ return Response.json(this.makeBody(), e);
168
+ }
169
+ }, h = class extends d {
170
+ constructor(e, t) {
171
+ super(), this.name = "Forbidden", this.status = 403, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
172
+ }
173
+ toResponse() {
174
+ let e = {
175
+ headers: { "Content-Type": "application/json" },
176
+ status: this.status,
177
+ statusText: this.statusText
178
+ };
179
+ return new Response(JSON.stringify(this.makeBody()), e);
180
+ }
181
+ toJson() {
182
+ let e = {
183
+ status: this.status,
184
+ statusText: this.statusText
185
+ };
186
+ return Response.json(this.makeBody(), e);
187
+ }
188
+ }, g = class extends d {
189
+ constructor(e, t) {
190
+ super(), this.name = "NotFound", this.status = 404, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
191
+ }
192
+ toResponse() {
193
+ let e = {
194
+ headers: { "Content-Type": "application/json" },
195
+ status: this.status,
196
+ statusText: this.statusText
197
+ };
198
+ return new Response(JSON.stringify(this.makeBody()), e);
199
+ }
200
+ toJson() {
201
+ let e = {
202
+ status: this.status,
203
+ statusText: this.statusText
204
+ };
205
+ return Response.json(this.makeBody(), e);
206
+ }
207
+ }, _ = class extends d {
208
+ constructor(e, t) {
209
+ super(), this.name = "NotImplemented", this.status = 501, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
210
+ }
211
+ toResponse() {
212
+ let e = {
213
+ headers: { "Content-Type": "application/json" },
214
+ status: this.status,
215
+ statusText: this.statusText
216
+ };
217
+ return new Response(JSON.stringify(this.makeBody()), e);
218
+ }
219
+ toJson() {
220
+ let e = {
221
+ status: this.status,
222
+ statusText: this.statusText
223
+ };
224
+ return Response.json(this.makeBody(), e);
225
+ }
226
+ }, v = class extends d {
227
+ constructor(e, t) {
228
+ super(), this.name = "ServerError", this.status = 500, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
229
+ }
230
+ toResponse() {
231
+ let e = {
232
+ headers: { "Content-Type": "application/json" },
233
+ status: this.status,
234
+ statusText: this.statusText
235
+ };
236
+ return new Response(JSON.stringify(this.makeBody()), e);
237
+ }
238
+ toJson() {
239
+ let e = {
240
+ status: this.status,
241
+ statusText: this.statusText
242
+ };
243
+ return Response.json(this.makeBody(), e);
244
+ }
245
+ }, y = class extends d {
246
+ constructor(e, t) {
247
+ super(), this.name = "Unauthorized", this.status = 401, this.statusText = e, this.debugColor = "yellow", this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
248
+ }
249
+ toResponse() {
250
+ let e = {
251
+ headers: { "Content-Type": "application/json" },
252
+ status: this.status,
253
+ statusText: this.statusText
254
+ };
255
+ return new Response(JSON.stringify(this.makeBody()), e);
256
+ }
257
+ toJson() {
258
+ let e = {
259
+ status: this.status,
260
+ statusText: this.statusText
261
+ };
262
+ return Response.json(this.makeBody(), e);
263
+ }
264
+ }, b = class extends d {
265
+ constructor(e) {
266
+ super(), this.name = "UnprocessableEntity", this.status = 422, this.statusText = e.message || "Unprocessable entity", this.debugColor = "yellow", this.cause = {
267
+ data: e.data,
268
+ fieldErrors: e.fieldErrors,
269
+ fields: e.fields
270
+ }, this.onDebug();
271
+ }
272
+ toResponse() {
273
+ let e = {
274
+ headers: { "Content-Type": "application/json" },
275
+ status: this.status,
276
+ statusText: this.statusText
277
+ };
278
+ return new Response(JSON.stringify(this.makeBody()), e);
279
+ }
280
+ toJson() {
281
+ let e = {
282
+ status: this.status,
283
+ statusText: this.statusText
284
+ };
285
+ return Response.json(this.makeBody(), e);
286
+ }
287
+ }, x = class {
288
+ _body = null;
289
+ _name = "SuccessResponse";
290
+ _status = 200;
291
+ _statusText = "OK";
292
+ _debugColor = "green";
293
+ get body() {
294
+ return this._body;
295
+ }
296
+ set body(e) {
297
+ this._body = e ?? null;
298
+ }
299
+ get name() {
300
+ return this._name;
301
+ }
302
+ set name(e) {
303
+ this._name = e;
304
+ }
305
+ get status() {
306
+ return this._status;
307
+ }
308
+ set status(e) {
309
+ this._status = e;
310
+ }
311
+ get statusText() {
312
+ return this._statusText;
313
+ }
314
+ set statusText(e) {
315
+ this._statusText = e;
316
+ }
317
+ get debugColor() {
318
+ return this._debugColor;
319
+ }
320
+ set debugColor(e) {
321
+ [
322
+ "green",
323
+ "yellow",
324
+ "cyan",
325
+ "red"
326
+ ].includes(e) && (this._debugColor = e);
327
+ }
328
+ onDebug(e) {
329
+ let t = [], { callerInfo: n, functionName: r } = l.getCaller();
330
+ t.push(`Caller Function: ${r}`), t.push(`Caller Location: ${n}`), this.statusText && t.push(`Message: ${this.statusText}`), e && t.push(`Body: ${JSON.stringify(e)}`), u({
331
+ scheme: this._debugColor,
332
+ name: this.name,
333
+ debugs: t
334
+ });
335
+ }
336
+ makeBody() {
337
+ return {
338
+ name: this.name,
339
+ message: this.statusText,
340
+ body: this.body
341
+ };
342
+ }
343
+ }, S = class extends x {
344
+ constructor(e, t) {
345
+ super(), this.name = "Created", this.status = 201, this.statusText = e, this.body = t || void 0, this.onDebug();
346
+ }
347
+ toResponse() {
348
+ let e = {
349
+ headers: { "Content-Type": "application/json" },
350
+ status: this.status,
351
+ statusText: this.statusText
352
+ };
353
+ return new Response(JSON.stringify(this.body), e);
354
+ }
355
+ toJson() {
356
+ let e = {
357
+ status: this.status,
358
+ statusText: this.statusText
359
+ };
360
+ return Response.json(this.body, e);
361
+ }
362
+ }, C = class extends x {
363
+ constructor(e, t) {
364
+ super(), this.name = "Found", this.status = 302, this.statusText = e, this.body = t || void 0, this.onDebug();
365
+ }
366
+ toResponse() {
367
+ let e = {
368
+ headers: { "Content-Type": "application/json" },
369
+ status: this.status,
370
+ statusText: this.statusText
371
+ };
372
+ return new Response(JSON.stringify(this.body), e);
373
+ }
374
+ toJson() {
375
+ let e = {
376
+ status: this.status,
377
+ statusText: this.statusText
378
+ };
379
+ return Response.json(this.body, e);
380
+ }
381
+ }, w = class extends x {
382
+ constructor(e) {
383
+ super(), this.name = "NoContent", this.status = 204, this.statusText = e, this.onDebug();
384
+ }
385
+ toResponse() {
386
+ let e = {
387
+ headers: { "Content-Type": "application/json" },
388
+ status: this.status,
389
+ statusText: this.statusText
390
+ };
391
+ return new Response(null, e);
392
+ }
393
+ }, T = class extends x {
394
+ constructor(e, t) {
395
+ super(), this.name = "Success", this.status = 200, this.statusText = e, this.body = t || void 0, this.onDebug();
396
+ }
397
+ toResponse() {
398
+ let e = {
399
+ headers: { "Content-Type": "application/json" },
400
+ status: this.status,
401
+ statusText: this.statusText
402
+ };
403
+ return new Response(JSON.stringify(this.body), e);
404
+ }
405
+ toJson() {
406
+ let e = {
407
+ status: this.status,
408
+ statusText: this.statusText
409
+ };
410
+ return Response.json(this.body, e);
411
+ }
412
+ }, E = class extends x {
413
+ constructor(e, t) {
414
+ super(), this.name = "Updated", this.status = 200, this.statusText = e, this.body = t || void 0, this.onDebug();
415
+ }
416
+ toResponse() {
417
+ let e = {
418
+ headers: { "Content-Type": "application/json" },
419
+ status: this.status,
420
+ statusText: this.statusText
421
+ };
422
+ return new Response(JSON.stringify(this.body), e);
423
+ }
424
+ toJson() {
425
+ let e = {
426
+ status: this.status,
427
+ statusText: this.statusText
428
+ };
429
+ return Response.json(this.body, e);
430
+ }
431
+ }, D = class e {
432
+ static mapHeaders(e) {
433
+ return e instanceof Headers ? Object.fromEntries(e.entries()) : typeof e == "object" ? Object.entries(e).reduce((e, [t, n]) => (typeof n == "string" ? e[t] = n : Array.isArray(n) ? e[t] = n.join(", ") : e[t] = JSON.stringify(n), e), {}) : {};
434
+ }
435
+ static mapQueryParams(e) {
436
+ let t = {};
437
+ return e.forEach((e, n) => {
438
+ t[n] = e;
439
+ }), t;
440
+ }
441
+ static handle(t) {
442
+ return {
443
+ rawUrl: t.rawUrl,
444
+ status: t.status,
445
+ method: t.method,
446
+ token: null,
447
+ elapsedTime: t.elapsedTime,
448
+ requestHeaders: e.mapHeaders(t.requestHeaders),
449
+ requestBody: t.requestBody || null,
450
+ queryParams: {
451
+ ...e.mapQueryParams(t.queryParams),
452
+ ...t.urlParams
453
+ },
454
+ responseHeaders: e.mapHeaders(t.responseHeaders),
455
+ responseBody: t.responseBody || null
456
+ };
457
+ }
458
+ }, O = class e {
459
+ static config;
460
+ static setConfig(t) {
461
+ if (e.config) return;
462
+ let { trafficSourceId: n, userToken: r, logBaseApiUrl: i } = t;
463
+ e.config = {
464
+ trafficSourceId: n,
465
+ userToken: r,
466
+ apiUrl: `${i || "http://62.238.8.44:8081"}/ingest-log`
467
+ };
468
+ }
469
+ static getConfig() {
470
+ return e.config;
471
+ }
472
+ static resetConfig() {
473
+ e.config = void 0;
474
+ }
475
+ };
476
+ //#endregion
477
+ //#region src/http/api/_logRequest.ts
478
+ async function k(e) {
479
+ let n = O.getConfig();
480
+ if (!n) return;
481
+ let { userToken: r, apiUrl: i, trafficSourceId: a } = n, { elapsedTime: o, method: s, queryParams: c, requestBody: l, requestHeaders: d, responseBody: f, responseHeaders: p, status: m, rawUrl: h } = e;
482
+ if (process.env.NODE_ENV !== "development") try {
483
+ let e = new URL(h), n = "https";
484
+ e.protocol === "http:" && (n = "http");
485
+ let g = JSON.stringify({
486
+ domainUrl: `${e.protocol}//${e.host}`,
487
+ pathnameUrl: e.pathname,
488
+ trafficSourceId: a,
489
+ status: m,
490
+ protocol: n,
491
+ method: s.toLowerCase(),
492
+ trafficUserId: null,
493
+ elapsedTime: o,
494
+ requestHeaders: JSON.stringify(d),
495
+ requestBody: JSON.stringify(l),
496
+ queryParams: JSON.stringify(c),
497
+ responseHeaders: JSON.stringify(p),
498
+ responseBody: JSON.stringify(f)
499
+ }), _ = {
500
+ "Content-Type": "application/json",
501
+ Authorization: `Bearer ${r}`
502
+ }, v = await fetch(i, {
503
+ method: "POST",
504
+ body: g,
505
+ headers: _
506
+ });
507
+ if (!v.ok) {
508
+ let e = await v.text(), n = v.status, r = v.statusText, i = await v.json().catch(() => null);
509
+ u({
510
+ name: "LogError",
511
+ scheme: "red",
512
+ debugs: [
513
+ "Failed to log request.",
514
+ `Status: ${n} ${r}.`,
515
+ `Status text: ${e}.`,
516
+ `JSON Response: ${i ? t(i, 0) : "No JSON response"}`
517
+ ]
518
+ });
519
+ }
520
+ } catch (e) {
521
+ u({
522
+ debugs: [`Error sending request: ${e}`],
523
+ name: "LogError",
524
+ scheme: "red"
525
+ });
526
+ }
527
+ }
528
+ //#endregion
529
+ //#region src/http/api/_makeRequest.ts
530
+ async function A(e) {
531
+ let t = e.url;
532
+ e.urlParams && Object.entries(e.urlParams).forEach(([e, n]) => {
533
+ t = t.replaceAll(`:${e}`, n);
534
+ });
535
+ let n = {
536
+ POST: "Resource created successfully",
537
+ PUT: "Resource updated successfully",
538
+ DELETE: "Resource deleted successfully",
539
+ PATCH: "Resource patched successfully",
540
+ GET: "Request successful"
541
+ };
542
+ try {
543
+ let r = performance.now(), i = {
544
+ ...e.headers,
545
+ "Content-Type": "application/json"
546
+ }, a = await fetch(t, {
547
+ headers: i,
548
+ method: e.method,
549
+ body: e.body ? JSON.stringify(e.body) : void 0
550
+ }), o = performance.now() - r, s = a.status, c = null;
551
+ try {
552
+ c = await a.json();
553
+ } catch {
554
+ c = null;
555
+ }
556
+ return k(D.handle({
557
+ elapsedTime: o,
558
+ method: e.method,
559
+ queryParams: new URL(t).searchParams,
560
+ requestHeaders: i,
561
+ requestBody: e.body,
562
+ responseBody: c,
563
+ responseHeaders: a.headers,
564
+ status: s,
565
+ rawUrl: e.url,
566
+ urlParams: e.urlParams
567
+ })), a.ok ? {
568
+ success: !0,
569
+ status: s,
570
+ message: c?.message || n[e.method],
571
+ response: c,
572
+ cause: null
573
+ } : {
574
+ success: !1,
575
+ status: s,
576
+ message: c?.message || a.statusText || "Request failed",
577
+ response: c,
578
+ cause: null
579
+ };
580
+ } catch (e) {
581
+ return u({
582
+ debugs: [`Network error or request failed: ${e}`],
583
+ name: "MakeRequestError",
584
+ scheme: "red"
585
+ }), {
586
+ success: !1,
587
+ status: 0,
588
+ message: "Network error or request failed",
589
+ response: null,
590
+ cause: e instanceof Error ? e.message : String(e)
591
+ };
592
+ }
593
+ }
594
+ //#endregion
595
+ //#region src/http/api/deleteRequest.ts
596
+ async function j(e) {
597
+ return A({
598
+ method: "DELETE",
599
+ url: e.url,
600
+ urlParams: e.urlParams,
601
+ headers: e.headers,
602
+ body: e.body
603
+ });
604
+ }
605
+ //#endregion
606
+ //#region src/http/api/getRequest.ts
607
+ async function M(e) {
608
+ return A({
609
+ method: "GET",
610
+ url: e.url,
611
+ urlParams: e.urlParams,
612
+ headers: e.headers
613
+ });
614
+ }
615
+ //#endregion
616
+ //#region src/http/api/patchRequest.ts
617
+ async function ee(e) {
618
+ return A({
619
+ method: "PATCH",
620
+ url: e.url,
621
+ urlParams: e.urlParams,
622
+ headers: e.headers,
623
+ body: e.body
624
+ });
625
+ }
626
+ //#endregion
627
+ //#region src/http/api/postRequest.ts
628
+ async function N(e) {
629
+ return A({
630
+ method: "POST",
631
+ url: e.url,
632
+ urlParams: e.urlParams,
633
+ headers: e.headers,
634
+ body: e.body
635
+ });
636
+ }
637
+ //#endregion
638
+ //#region src/http/api/putRequest.ts
639
+ async function P(e) {
640
+ return A({
641
+ method: "PUT",
642
+ url: e.url,
643
+ urlParams: e.urlParams,
644
+ headers: e.headers,
645
+ body: e.body
646
+ });
647
+ }
648
+ //#endregion
649
+ //#region src/services/apiService.ts
650
+ var F = class {
651
+ baseUrl;
652
+ baseHeaders;
653
+ baseToken;
654
+ enableDebug;
655
+ constructor(e) {
656
+ this.baseUrl = e.baseUrl, this.baseHeaders = e.baseHeaders || void 0, this.baseToken = e.baseToken || void 0, this.enableDebug = e.enableDebug || !1;
657
+ }
658
+ onDebug(e, t, n) {
659
+ if (this.enableDebug) {
660
+ let r = [], i = (e) => JSON.stringify(e, null, 2);
661
+ r.push(`Base URL: ${this.baseUrl}`), r.push(`Endpoint: ${e}`), r.push(`Status/Method: ${t} => ${n.status}`), r.push(`Message: ${n.message}`), n.headers && r.push(`Headers: ${i(n.headers)}`), n.body && r.push(`Body: ${i(n.body)}`), u({
662
+ debugs: r,
663
+ name: "ApiDebug",
664
+ scheme: "yellow"
665
+ });
666
+ }
667
+ }
668
+ generateHeaders(e, t) {
669
+ let n = {};
670
+ return this.baseToken && (n = { Authorization: `Bearer ${this.baseToken}` }), this.baseHeaders && (n = {
671
+ ...n,
672
+ ...this.baseHeaders
673
+ }), e && (n = {
674
+ ...n,
675
+ ...e
676
+ }), t && (n = {
677
+ ...n,
678
+ Authorization: `Bearer ${t}`
679
+ }), n;
680
+ }
681
+ async get(e, t) {
682
+ let n = this.generateHeaders(t?.headers || {}, t?.token), r = await M({
683
+ url: this.baseUrl + e,
684
+ urlParams: t?.urlParams || {},
685
+ headers: n
686
+ });
687
+ return this.onDebug(e, "get", {
688
+ headers: n,
689
+ message: r.message,
690
+ status: r.status
691
+ }), r;
692
+ }
693
+ async post(e, t) {
694
+ let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await N({
695
+ url: this.baseUrl + e,
696
+ urlParams: t?.urlParams || {},
697
+ headers: n,
698
+ body: r
699
+ });
700
+ return this.onDebug(e, "post", {
701
+ headers: n,
702
+ body: r,
703
+ message: i.message,
704
+ status: i.status
705
+ }), i;
706
+ }
707
+ async put(e, t) {
708
+ let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await P({
709
+ url: this.baseUrl + e,
710
+ urlParams: t?.urlParams || {},
711
+ headers: n,
712
+ body: r
713
+ });
714
+ return this.onDebug(e, "put", {
715
+ headers: n,
716
+ body: r,
717
+ message: i.message,
718
+ status: i.status
719
+ }), i;
720
+ }
721
+ async patch(e, t) {
722
+ let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await ee({
723
+ url: this.baseUrl + e,
724
+ urlParams: t?.urlParams || {},
725
+ headers: n,
726
+ body: r
727
+ });
728
+ return this.onDebug(e, "patch", {
729
+ headers: n,
730
+ body: r,
731
+ message: i.message,
732
+ status: i.status
733
+ }), i;
734
+ }
735
+ async delete(e, t) {
736
+ let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await j({
737
+ url: this.baseUrl + e,
738
+ urlParams: t?.urlParams || {},
739
+ headers: n,
740
+ body: r
741
+ });
742
+ return this.onDebug(e, "delete", {
743
+ headers: n,
744
+ body: r,
745
+ message: i.message,
746
+ status: i.status
747
+ }), i;
748
+ }
749
+ };
750
+ //#endregion
751
+ //#region src/utilities/decodeRequestBody.ts
752
+ async function I(e) {
753
+ let t, n = await e.arrayBuffer(), r = new TextDecoder().decode(n);
754
+ try {
755
+ t = JSON.parse(r);
756
+ } catch {
757
+ try {
758
+ if (r.includes("=")) {
759
+ let e = new URLSearchParams(r);
760
+ t = Object.fromEntries(e.entries());
761
+ } else throw new p("Invalid URLSearchParams format");
762
+ } catch {
763
+ throw new p("Failed to extract data from request");
764
+ }
765
+ }
766
+ return t;
767
+ }
768
+ //#endregion
769
+ //#region src/utilities/decodeRequestErrorMessage.ts
770
+ function L(e, t) {
771
+ return e?.message && typeof e?.message == "string" ? e?.message : e?.operator_erro_message && typeof e?.operator_erro_message == "string" ? e?.operator_erro_message : e?.error && typeof e?.error == "string" ? e?.error : e?.error?.message && typeof e?.error?.message == "string" ? e?.error?.message : t?.statusText && typeof t?.statusText == "string" ? t?.statusText : "Missing error message";
772
+ }
773
+ //#endregion
774
+ //#region src/utilities/errorHandler.ts
775
+ function R(e) {
776
+ switch (!0) {
777
+ case e instanceof Response: return e;
778
+ case e instanceof C: return e.toResponse();
779
+ case e instanceof S: return e.toResponse();
780
+ case e instanceof E: return e.toResponse();
781
+ case e instanceof T: return e.toResponse();
782
+ case e instanceof w: return e.toResponse();
783
+ }
784
+ switch (!0) {
785
+ case e instanceof f: return e.toResponse();
786
+ case e instanceof p: return e.toResponse();
787
+ case e instanceof m: return e.toResponse();
788
+ case e instanceof h: return e.toResponse();
789
+ case e instanceof g: return e.toResponse();
790
+ case e instanceof _: return e.toResponse();
791
+ case e instanceof v: return e.toResponse();
792
+ case e instanceof y: return e.toResponse();
793
+ case e instanceof b: return e.toResponse();
794
+ }
795
+ return new v("Server error", e).toResponse();
796
+ }
797
+ //#endregion
798
+ //#region src/utilities/formAsyncParse.ts
799
+ async function z([e, t]) {
800
+ let n = await t.safeParseAsync(e);
801
+ return n.success === !1 ? {
802
+ success: !1,
803
+ fieldErrors: Object.fromEntries(n.error.issues.map((e) => [e.path.join("."), e.message])),
804
+ fields: e
805
+ } : {
806
+ success: !0,
807
+ data: n.data
808
+ };
809
+ }
810
+ //#endregion
811
+ //#region src/utilities/formParse.ts
812
+ function B([e, t]) {
813
+ let n = t.safeParse(e);
814
+ return n.success === !1 ? {
815
+ success: !1,
816
+ fieldErrors: Object.fromEntries(n.error.issues.map((e) => [e.path.join("."), e.message])),
817
+ fields: e
818
+ } : {
819
+ success: !0,
820
+ data: n.data
821
+ };
822
+ }
823
+ //#endregion
824
+ //#region src/utilities/getScopedParams.ts
825
+ function V(e, t = "") {
826
+ let n = new URL(e.url);
827
+ if (t === "") return n.searchParams;
828
+ let r = Array.from(n.searchParams.entries()).filter(([e]) => e.startsWith(`${t}:`)).map(([e, n]) => [e.replace(`${t}:`, ""), n]);
829
+ return new URLSearchParams(r);
830
+ }
831
+ //#endregion
832
+ //#region src/utilities/schemaValidator.ts
833
+ function H(e) {
834
+ return ["Error validating:", ...e.issues.map(({ path: e, message: t }) => `-> ${e.join(".")}: ${t}`)].join("\n");
835
+ }
836
+ var U = class {
837
+ schema;
838
+ constructor(e) {
839
+ this.schema = e;
840
+ }
841
+ isValid(e) {
842
+ return this.schema.safeParse(e).success;
843
+ }
844
+ safeValidate(e) {
845
+ return this.schema.safeParse(e);
846
+ }
847
+ validate(e) {
848
+ try {
849
+ return this.schema.parse(e);
850
+ } catch (e) {
851
+ throw new v(H(e));
852
+ }
853
+ }
854
+ formValidate(e, t) {
855
+ let n = B([e, this.schema]);
856
+ if ("fieldErrors" in n) {
857
+ let e = Object.keys(n.fieldErrors)[0];
858
+ throw new b({
859
+ fields: n.fields,
860
+ fieldErrors: n.fieldErrors,
861
+ data: { scrollTo: e },
862
+ message: t
863
+ });
864
+ }
865
+ return n.data;
866
+ }
867
+ async formAsyncValidate(e, t) {
868
+ let n = await z([e, this.schema]);
869
+ if ("fieldErrors" in n) {
870
+ let e = Object.keys(n.fieldErrors)[0];
871
+ throw new b({
872
+ fields: n.fields,
873
+ fieldErrors: n.fieldErrors,
874
+ data: { scrollTo: e },
875
+ message: t
876
+ });
877
+ }
878
+ return n.data;
879
+ }
880
+ };
881
+ //#endregion
882
+ //#region src/validations/validateCep.ts
883
+ function W(e) {
884
+ if (!(/^\d{5}-\d{3}$/.test(e) || /^\d{8}$/.test(e))) return !1;
885
+ let t = r(e), n = /^\d{8}$/.test(t);
886
+ return t.length === 8 && n;
887
+ }
888
+ //#endregion
889
+ //#region src/validations/validateCnpj.ts
890
+ function G(e) {
891
+ return e.length !== 14;
892
+ }
893
+ function K(e) {
894
+ let [t] = e;
895
+ return [...e].every((e) => e === t);
896
+ }
897
+ function q(e, t) {
898
+ let n = 0;
899
+ for (let r = 0; r < t.length; r++) n += parseInt(e[r], 10) * t[r];
900
+ let r = n % 11;
901
+ return r < 2 ? 0 : 11 - r;
902
+ }
903
+ function J(e) {
904
+ return e.slice(12);
905
+ }
906
+ function te(e) {
907
+ if (!e || e.length > 18 || e.length < 14 || /\s/.test(e)) return !1;
908
+ let t = r(e);
909
+ if (G(t) || K(t)) return !1;
910
+ let n = t.slice(0, 12), i = q(n, [
911
+ 5,
912
+ 4,
913
+ 3,
914
+ 2,
915
+ 9,
916
+ 8,
917
+ 7,
918
+ 6,
919
+ 5,
920
+ 4,
921
+ 3,
922
+ 2
923
+ ]), a = q(n + i, [
924
+ 6,
925
+ 5,
926
+ 4,
927
+ 3,
928
+ 2,
929
+ 9,
930
+ 8,
931
+ 7,
932
+ 6,
933
+ 5,
934
+ 4,
935
+ 3,
936
+ 2
937
+ ]);
938
+ return J(t) === `${i}${a}`;
939
+ }
940
+ //#endregion
941
+ //#region src/validations/validateCpf.ts
942
+ function Y(e) {
943
+ return e.length !== 11;
944
+ }
945
+ function X(e) {
946
+ let [t] = e;
947
+ return [...e].every((e) => e === t);
948
+ }
949
+ function Z(e, t) {
950
+ let n = 0;
951
+ for (let r of e) t > 1 && (n += parseInt(r, 10) * t--);
952
+ let r = n % 11;
953
+ return r < 2 ? 0 : 11 - r;
954
+ }
955
+ function Q(e) {
956
+ return e.slice(9);
957
+ }
958
+ function ne(e) {
959
+ if (!e || e.length > 14 || e.length < 11 || /\s/.test(e)) return !1;
960
+ let t = r(e);
961
+ if (Y(t) || X(t)) return !1;
962
+ let n = Z(t, 10), i = Z(t, 11);
963
+ return Q(t) === `${n}${i}`;
964
+ }
965
+ //#endregion
966
+ //#region src/validations/validateDate.ts
967
+ function re(t, n) {
968
+ let r = n?.inputFormat || "brazilianDate", i = n?.minYear || 1900, a = n?.maxYear || 3e3, o = new e();
969
+ o.validateInputFormat(r);
970
+ let s, c, l, u = t.split(/[-/]/).map(Number);
971
+ if (u.length !== 3) return !1;
972
+ try {
973
+ switch (r) {
974
+ case "brazilianDate":
975
+ [s, c, l] = u, o.validateDateParts(l, c, s);
976
+ break;
977
+ case "isoDate":
978
+ [c, s, l] = u, o.validateDateParts(l, c, s);
979
+ break;
980
+ case "timestamp":
981
+ [l, c, s] = u, o.validateDateParts(l, c, s);
982
+ break;
983
+ }
984
+ return !(l < i || l > a);
985
+ } catch {
986
+ return !1;
987
+ }
988
+ }
989
+ //#endregion
990
+ //#region src/validations/validateEmail.ts
991
+ function ie(e) {
992
+ 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);
993
+ }
994
+ function ae(e) {
995
+ return !(e.length === 0 || e.length > 64 || e.startsWith(".") || e.endsWith(".") || e.includes("..") || !/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/.test(e));
996
+ }
997
+ function oe(e) {
998
+ return !(e.length === 0 || e.length > 63 || e.startsWith("-") || e.endsWith("-") || !/^[a-zA-Z0-9-]+$/.test(e));
999
+ }
1000
+ function $(e) {
1001
+ if (e.length === 0 || e.length > 253 || e.startsWith(".") || e.endsWith(".") || e.startsWith("-") || e.endsWith("-")) return !1;
1002
+ let t = e.split(".");
1003
+ if (t.length < 2) return !1;
1004
+ for (let e of t) if (!oe(e)) return !1;
1005
+ let n = t[t.length - 1];
1006
+ return !(n.length < 2 || !/^[a-zA-Z]+$/.test(n));
1007
+ }
1008
+ function se(e) {
1009
+ let t = e.split("@");
1010
+ if (t.length !== 2) return !1;
1011
+ let [n, r] = t;
1012
+ return !(!ae(n) || !$(r));
1013
+ }
1014
+ function ce(e) {
1015
+ let t = e.split("@");
1016
+ return t.length === 2 ? t[1].toLowerCase() : null;
1017
+ }
1018
+ var le = [
1019
+ "MX",
1020
+ "A",
1021
+ "AAAA"
1022
+ ];
1023
+ async function ue(e, t) {
1024
+ try {
1025
+ return await a?.promises?.resolve(e, t), !0;
1026
+ } catch {
1027
+ return !1;
1028
+ }
1029
+ }
1030
+ async function de(e) {
1031
+ for (let t of le) if (await ue(e, t)) return !0;
1032
+ return !1;
1033
+ }
1034
+ async function fe(e) {
1035
+ if (!e || typeof e != "string") return !1;
1036
+ let t = e.trim();
1037
+ if (!ie(t) || !se(t)) return !1;
1038
+ let n = ce(t);
1039
+ return n ? await de(n) : !1;
1040
+ }
1041
+ //#endregion
1042
+ //#region src/validations/validatePassword.ts
1043
+ function pe(e) {
1044
+ return e ? [
1045
+ e.length >= 8,
1046
+ /[A-Z]/.test(e),
1047
+ /[a-z]/.test(e),
1048
+ /\d/.test(e),
1049
+ /[!@#$%^&*(),.?":;{}|<>_\-+=~`[\]\\/]/.test(e)
1050
+ ].every((e) => e) : !1;
1051
+ }
1052
+ //#endregion
1053
+ //#region src/validations/validatePhone.ts
1054
+ function me(e) {
1055
+ if (!s(e)) return !1;
1056
+ let t = c(e)?.country;
1057
+ return !(!t || !o.find((e) => e.iso === t));
1058
+ }
1059
+ //#endregion
1060
+ //#region src/validations/validateRg.ts
1061
+ function he(e) {
1062
+ if (!e || !/^[0-9a-zA-Z.-]+$/.test(e)) return !1;
1063
+ let t = e.replace(/[^a-zA-Z0-9]/g, "");
1064
+ return t.length < 7 || t.length > 9 ? !1 : /^[0-9]{7,8}[0-9Xx]?$/.test(t);
1065
+ }
1066
+ //#endregion
1067
+ export { F as ApiService, f as BadGateway, p as BadRequest, m as Conflict, S as Created, l as DebugService, h as Forbidden, C as Found, O as LogService, w as NoContent, g as NotFound, _ as NotImplemented, U as SchemaValidator, v as ServerError, T as Success, y as Unauthorized, b as UnprocessableEntity, E as Updated, I as decodeRequestBody, L as decodeRequestErrorMessage, R as errorHandler, u as flushDebugLogs, z as formAsyncParse, B as formParse, V as getScopedParams, W as validateCep, te as validateCnpj, ne as validateCpf, re as validateDate, fe as validateEmail, pe as validatePassword, me as validatePhone, he as validateRg };