@arkyn/server 3.0.1-beta.166 → 3.0.1-beta.170

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 (135) hide show
  1. package/package.json +4 -3
  2. package/dist/http/api/_logRequest.d.ts +0 -58
  3. package/dist/http/api/_logRequest.d.ts.map +0 -1
  4. package/dist/http/api/_makeRequest.d.ts +0 -61
  5. package/dist/http/api/_makeRequest.d.ts.map +0 -1
  6. package/dist/http/api/deleteRequest.d.ts +0 -17
  7. package/dist/http/api/deleteRequest.d.ts.map +0 -1
  8. package/dist/http/api/getRequest.d.ts +0 -16
  9. package/dist/http/api/getRequest.d.ts.map +0 -1
  10. package/dist/http/api/patchRequest.d.ts +0 -17
  11. package/dist/http/api/patchRequest.d.ts.map +0 -1
  12. package/dist/http/api/postRequest.d.ts +0 -17
  13. package/dist/http/api/postRequest.d.ts.map +0 -1
  14. package/dist/http/api/putRequest.d.ts +0 -17
  15. package/dist/http/api/putRequest.d.ts.map +0 -1
  16. package/dist/http/badResponses/_badResponse.d.ts +0 -25
  17. package/dist/http/badResponses/_badResponse.d.ts.map +0 -1
  18. package/dist/http/badResponses/badGateway.d.ts +0 -24
  19. package/dist/http/badResponses/badGateway.d.ts.map +0 -1
  20. package/dist/http/badResponses/badRequest.d.ts +0 -22
  21. package/dist/http/badResponses/badRequest.d.ts.map +0 -1
  22. package/dist/http/badResponses/conflict.d.ts +0 -22
  23. package/dist/http/badResponses/conflict.d.ts.map +0 -1
  24. package/dist/http/badResponses/forbidden.d.ts +0 -22
  25. package/dist/http/badResponses/forbidden.d.ts.map +0 -1
  26. package/dist/http/badResponses/notFound.d.ts +0 -22
  27. package/dist/http/badResponses/notFound.d.ts.map +0 -1
  28. package/dist/http/badResponses/notImplemented.d.ts +0 -22
  29. package/dist/http/badResponses/notImplemented.d.ts.map +0 -1
  30. package/dist/http/badResponses/serverError.d.ts +0 -22
  31. package/dist/http/badResponses/serverError.d.ts.map +0 -1
  32. package/dist/http/badResponses/unauthorized.d.ts +0 -22
  33. package/dist/http/badResponses/unauthorized.d.ts.map +0 -1
  34. package/dist/http/badResponses/unprocessableEntity.d.ts +0 -34
  35. package/dist/http/badResponses/unprocessableEntity.d.ts.map +0 -1
  36. package/dist/http/successResponses/_successResponse.d.ts +0 -36
  37. package/dist/http/successResponses/_successResponse.d.ts.map +0 -1
  38. package/dist/http/successResponses/created.d.ts +0 -22
  39. package/dist/http/successResponses/created.d.ts.map +0 -1
  40. package/dist/http/successResponses/found.d.ts +0 -22
  41. package/dist/http/successResponses/found.d.ts.map +0 -1
  42. package/dist/http/successResponses/noContent.d.ts +0 -20
  43. package/dist/http/successResponses/noContent.d.ts.map +0 -1
  44. package/dist/http/successResponses/success.d.ts +0 -22
  45. package/dist/http/successResponses/success.d.ts.map +0 -1
  46. package/dist/http/successResponses/updated.d.ts +0 -23
  47. package/dist/http/successResponses/updated.d.ts.map +0 -1
  48. package/dist/index.d.ts +0 -34
  49. package/dist/index.d.ts.map +0 -1
  50. package/dist/index.js +0 -1065
  51. package/dist/modules/http/api/_logRequest.js +0 -56
  52. package/dist/modules/http/api/_makeRequest.js +0 -70
  53. package/dist/modules/http/api/deleteRequest.js +0 -13
  54. package/dist/modules/http/api/getRequest.js +0 -12
  55. package/dist/modules/http/api/patchRequest.js +0 -13
  56. package/dist/modules/http/api/postRequest.js +0 -13
  57. package/dist/modules/http/api/putRequest.js +0 -13
  58. package/dist/modules/http/badResponses/_badResponse.js +0 -63
  59. package/dist/modules/http/badResponses/badGateway.js +0 -24
  60. package/dist/modules/http/badResponses/badRequest.js +0 -24
  61. package/dist/modules/http/badResponses/conflict.js +0 -24
  62. package/dist/modules/http/badResponses/forbidden.js +0 -24
  63. package/dist/modules/http/badResponses/notFound.js +0 -24
  64. package/dist/modules/http/badResponses/notImplemented.js +0 -24
  65. package/dist/modules/http/badResponses/serverError.js +0 -24
  66. package/dist/modules/http/badResponses/unauthorized.js +0 -24
  67. package/dist/modules/http/badResponses/unprocessableEntity.js +0 -28
  68. package/dist/modules/http/successResponses/_successResponse.js +0 -62
  69. package/dist/modules/http/successResponses/created.js +0 -24
  70. package/dist/modules/http/successResponses/found.js +0 -24
  71. package/dist/modules/http/successResponses/noContent.js +0 -17
  72. package/dist/modules/http/successResponses/success.js +0 -24
  73. package/dist/modules/http/successResponses/updated.js +0 -24
  74. package/dist/modules/index.js +0 -34
  75. package/dist/modules/services/apiService.js +0 -109
  76. package/dist/modules/services/debugService.js +0 -36
  77. package/dist/modules/services/logMapperService.js +0 -29
  78. package/dist/modules/services/logService.js +0 -21
  79. package/dist/modules/utilities/decodeRequestBody.js +0 -20
  80. package/dist/modules/utilities/decodeRequestErrorMessage.js +0 -6
  81. package/dist/modules/utilities/errorHandler.js +0 -39
  82. package/dist/modules/utilities/flushDebugLogs.js +0 -16
  83. package/dist/modules/utilities/formAsyncParse.js +0 -14
  84. package/dist/modules/utilities/formParse.js +0 -14
  85. package/dist/modules/utilities/getScopedParams.js +0 -9
  86. package/dist/modules/utilities/schemaValidator.js +0 -55
  87. package/dist/modules/validations/validateCep.js +0 -9
  88. package/dist/modules/validations/validateCnpj.js +0 -54
  89. package/dist/modules/validations/validateCpf.js +0 -27
  90. package/dist/modules/validations/validateDate.js +0 -26
  91. package/dist/modules/validations/validateEmail.js +0 -54
  92. package/dist/modules/validations/validatePassword.js +0 -12
  93. package/dist/modules/validations/validatePhone.js +0 -10
  94. package/dist/modules/validations/validateRg.js +0 -8
  95. package/dist/services/apiService.d.ts +0 -83
  96. package/dist/services/apiService.d.ts.map +0 -1
  97. package/dist/services/debugService.d.ts +0 -37
  98. package/dist/services/debugService.d.ts.map +0 -1
  99. package/dist/services/logMapperService.d.ts +0 -86
  100. package/dist/services/logMapperService.d.ts.map +0 -1
  101. package/dist/services/logService.d.ts +0 -33
  102. package/dist/services/logService.d.ts.map +0 -1
  103. package/dist/utilities/decodeRequestBody.d.ts +0 -18
  104. package/dist/utilities/decodeRequestBody.d.ts.map +0 -1
  105. package/dist/utilities/decodeRequestErrorMessage.d.ts +0 -19
  106. package/dist/utilities/decodeRequestErrorMessage.d.ts.map +0 -1
  107. package/dist/utilities/errorHandler.d.ts +0 -25
  108. package/dist/utilities/errorHandler.d.ts.map +0 -1
  109. package/dist/utilities/flushDebugLogs.d.ts +0 -24
  110. package/dist/utilities/flushDebugLogs.d.ts.map +0 -1
  111. package/dist/utilities/formAsyncParse.d.ts +0 -38
  112. package/dist/utilities/formAsyncParse.d.ts.map +0 -1
  113. package/dist/utilities/formParse.d.ts +0 -38
  114. package/dist/utilities/formParse.d.ts.map +0 -1
  115. package/dist/utilities/getScopedParams.d.ts +0 -19
  116. package/dist/utilities/getScopedParams.d.ts.map +0 -1
  117. package/dist/utilities/schemaValidator.d.ts +0 -75
  118. package/dist/utilities/schemaValidator.d.ts.map +0 -1
  119. package/dist/validations/validateCep.d.ts +0 -19
  120. package/dist/validations/validateCep.d.ts.map +0 -1
  121. package/dist/validations/validateCnpj.d.ts +0 -21
  122. package/dist/validations/validateCnpj.d.ts.map +0 -1
  123. package/dist/validations/validateCpf.d.ts +0 -16
  124. package/dist/validations/validateCpf.d.ts.map +0 -1
  125. package/dist/validations/validateDate.d.ts +0 -23
  126. package/dist/validations/validateDate.d.ts.map +0 -1
  127. package/dist/validations/validateEmail.d.ts +0 -21
  128. package/dist/validations/validateEmail.d.ts.map +0 -1
  129. package/dist/validations/validatePassword.d.ts +0 -20
  130. package/dist/validations/validatePassword.d.ts.map +0 -1
  131. package/dist/validations/validatePhone.d.ts +0 -16
  132. package/dist/validations/validatePhone.d.ts.map +0 -1
  133. package/dist/validations/validateRg.d.ts +0 -21
  134. package/dist/validations/validateRg.d.ts.map +0 -1
  135. package/generate-version.ts +0 -74
package/dist/index.js DELETED
@@ -1,1065 +0,0 @@
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 {
8
- static ignoreFiles = [];
9
- static setIgnoreFile(e) {
10
- this.ignoreFiles.push(e);
11
- }
12
- static clearIgnoreFiles() {
13
- this.ignoreFiles = [];
14
- }
15
- static getCaller() {
16
- let e = process.cwd(), t = ((/* @__PURE__ */ Error()).stack || "").split("\n").map((e) => e.trim()), n = 2;
17
- for (; n < t.length && (t[n].includes("node:internal") || t[n].includes("/node_modules/"));) n++;
18
- if (this.ignoreFiles.length > 0) for (; n < t.length && this.ignoreFiles.some((e) => t[n].includes(e));) n++;
19
- let r = t[n] || "", a = "Unknown function", o = "Unknown caller", s = r.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);
20
- if (s) a = s[1], o = s[2];
21
- else {
22
- let e = r.match(/at\s+(.+)/);
23
- if (e) {
24
- o = e[1];
25
- let t = o.match(/at\s+([^(\s]+)\s+/);
26
- t && t[1] !== "new" && (a = t[1]);
27
- }
28
- }
29
- o.includes("(") && (o = o.substring(o.indexOf("(") + 1, o.lastIndexOf(")"))), o = o.split(":").slice(0, -2).join(":");
30
- try {
31
- o = i.relative(e, o);
32
- } catch {}
33
- return {
34
- functionName: a,
35
- callerInfo: o
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 {
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) => t[n] = e), t;
438
- }
439
- static handle(e) {
440
- return {
441
- rawUrl: e.rawUrl,
442
- status: e.status,
443
- method: e.method,
444
- token: null,
445
- elapsedTime: e.elapsedTime,
446
- requestHeaders: this.mapHeaders(e.requestHeaders),
447
- requestBody: e.requestBody || null,
448
- queryParams: {
449
- ...this.mapQueryParams(e.queryParams),
450
- ...e.urlParams
451
- },
452
- responseHeaders: this.mapHeaders(e.responseHeaders),
453
- responseBody: e.responseBody || null
454
- };
455
- }
456
- }, O = class {
457
- static config;
458
- static setConfig(e) {
459
- if (this.config) return;
460
- let { trafficSourceId: t, userToken: n, logBaseApiUrl: r } = e, i = `${r || "http://62.238.8.44:8081"}/ingest-log`;
461
- this.config = {
462
- trafficSourceId: t,
463
- userToken: n,
464
- apiUrl: i
465
- };
466
- }
467
- static getConfig() {
468
- return this.config;
469
- }
470
- static resetConfig() {
471
- this.config = void 0;
472
- }
473
- };
474
- //#endregion
475
- //#region src/http/api/_logRequest.ts
476
- async function k(e) {
477
- let n = O.getConfig();
478
- if (!n) return;
479
- let { userToken: r, apiUrl: i, trafficSourceId: a } = n, { elapsedTime: o, method: s, queryParams: c, requestBody: l, requestHeaders: d, responseBody: f, responseHeaders: p, status: m, token: h, rawUrl: g } = e;
480
- if (process.env.NODE_ENV !== "development") try {
481
- let e = new URL(g), n = "https";
482
- e.protocol === "http:" && (n = "http");
483
- let h = JSON.stringify({
484
- domainUrl: e.protocol + "//" + e.host,
485
- pathnameUrl: e.pathname,
486
- trafficSourceId: a,
487
- status: m,
488
- protocol: n,
489
- method: s.toLowerCase(),
490
- trafficUserId: null,
491
- elapsedTime: o,
492
- requestHeaders: JSON.stringify(d),
493
- requestBody: JSON.stringify(l),
494
- queryParams: JSON.stringify(c),
495
- responseHeaders: JSON.stringify(p),
496
- responseBody: JSON.stringify(f)
497
- }), _ = {
498
- "Content-Type": "application/json",
499
- Authorization: `Bearer ${r}`
500
- }, v = await fetch(i, {
501
- method: "POST",
502
- body: h,
503
- headers: _
504
- });
505
- if (!v.ok) {
506
- let e = await v.text(), n = v.status, r = v.statusText, i = await v.json().catch(() => null);
507
- u({
508
- name: "LogError",
509
- scheme: "red",
510
- debugs: [
511
- "Failed to log request.",
512
- `Status: ${n} ${r}.`,
513
- `Status text: ${e}.`,
514
- `JSON Response: ${i ? t(i, 0) : "No JSON response"}`
515
- ]
516
- });
517
- }
518
- } catch (e) {
519
- u({
520
- debugs: [`Error sending request: ${e}`],
521
- name: "LogError",
522
- scheme: "red"
523
- });
524
- }
525
- }
526
- //#endregion
527
- //#region src/http/api/_makeRequest.ts
528
- async function A(e) {
529
- let t = e.url;
530
- e.urlParams && Object.entries(e.urlParams).forEach(([e, n]) => {
531
- t = t.replaceAll(`:${e}`, n);
532
- });
533
- let n = {
534
- POST: "Resource created successfully",
535
- PUT: "Resource updated successfully",
536
- DELETE: "Resource deleted successfully",
537
- PATCH: "Resource patched successfully",
538
- GET: "Request successful"
539
- };
540
- try {
541
- let r = performance.now(), i = {
542
- ...e.headers,
543
- "Content-Type": "application/json"
544
- }, a = await fetch(t, {
545
- headers: i,
546
- method: e.method,
547
- body: e.body ? JSON.stringify(e.body) : void 0
548
- }), o = performance.now() - r, s = a.status, c = null;
549
- try {
550
- c = await a.json();
551
- } catch {
552
- c = null;
553
- }
554
- return k(D.handle({
555
- elapsedTime: o,
556
- method: e.method,
557
- queryParams: new URL(t).searchParams,
558
- requestHeaders: i,
559
- requestBody: e.body,
560
- responseBody: c,
561
- responseHeaders: a.headers,
562
- status: s,
563
- rawUrl: e.url,
564
- urlParams: e.urlParams
565
- })), a.ok ? {
566
- success: !0,
567
- status: s,
568
- message: c?.message || n[e.method],
569
- response: c,
570
- cause: null
571
- } : {
572
- success: !1,
573
- status: s,
574
- message: c?.message || a.statusText || "Request failed",
575
- response: c,
576
- cause: null
577
- };
578
- } catch (e) {
579
- return u({
580
- debugs: [`Network error or request failed: ${e}`],
581
- name: "MakeRequestError",
582
- scheme: "red"
583
- }), {
584
- success: !1,
585
- status: 0,
586
- message: "Network error or request failed",
587
- response: null,
588
- cause: e instanceof Error ? e.message : String(e)
589
- };
590
- }
591
- }
592
- //#endregion
593
- //#region src/http/api/deleteRequest.ts
594
- async function j(e) {
595
- return A({
596
- method: "DELETE",
597
- url: e.url,
598
- urlParams: e.urlParams,
599
- headers: e.headers,
600
- body: e.body
601
- });
602
- }
603
- //#endregion
604
- //#region src/http/api/getRequest.ts
605
- async function M(e) {
606
- return A({
607
- method: "GET",
608
- url: e.url,
609
- urlParams: e.urlParams,
610
- headers: e.headers
611
- });
612
- }
613
- //#endregion
614
- //#region src/http/api/patchRequest.ts
615
- async function ee(e) {
616
- return A({
617
- method: "PATCH",
618
- url: e.url,
619
- urlParams: e.urlParams,
620
- headers: e.headers,
621
- body: e.body
622
- });
623
- }
624
- //#endregion
625
- //#region src/http/api/postRequest.ts
626
- async function N(e) {
627
- return A({
628
- method: "POST",
629
- url: e.url,
630
- urlParams: e.urlParams,
631
- headers: e.headers,
632
- body: e.body
633
- });
634
- }
635
- //#endregion
636
- //#region src/http/api/putRequest.ts
637
- async function P(e) {
638
- return A({
639
- method: "PUT",
640
- url: e.url,
641
- urlParams: e.urlParams,
642
- headers: e.headers,
643
- body: e.body
644
- });
645
- }
646
- //#endregion
647
- //#region src/services/apiService.ts
648
- var F = class {
649
- baseUrl;
650
- baseHeaders;
651
- baseToken;
652
- enableDebug;
653
- constructor(e) {
654
- this.baseUrl = e.baseUrl, this.baseHeaders = e.baseHeaders || void 0, this.baseToken = e.baseToken || void 0, this.enableDebug = e.enableDebug || !1;
655
- }
656
- onDebug(e, t, n) {
657
- if (this.enableDebug) {
658
- let r = [], i = (e) => JSON.stringify(e, null, 2);
659
- 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({
660
- debugs: r,
661
- name: "ApiDebug",
662
- scheme: "yellow"
663
- });
664
- }
665
- }
666
- generateHeaders(e, t) {
667
- let n = {};
668
- return this.baseToken && (n = { Authorization: `Bearer ${this.baseToken}` }), this.baseHeaders && (n = {
669
- ...n,
670
- ...this.baseHeaders
671
- }), e && (n = {
672
- ...n,
673
- ...e
674
- }), t && (n = {
675
- ...n,
676
- Authorization: `Bearer ${t}`
677
- }), n;
678
- }
679
- async get(e, t) {
680
- let n = this.generateHeaders(t?.headers || {}, t?.token), r = await M({
681
- url: this.baseUrl + e,
682
- urlParams: t?.urlParams || {},
683
- headers: n
684
- });
685
- return this.onDebug(e, "get", {
686
- headers: n,
687
- message: r.message,
688
- status: r.status
689
- }), r;
690
- }
691
- async post(e, t) {
692
- let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await N({
693
- url: this.baseUrl + e,
694
- urlParams: t?.urlParams || {},
695
- headers: n,
696
- body: r
697
- });
698
- return this.onDebug(e, "post", {
699
- headers: n,
700
- body: r,
701
- message: i.message,
702
- status: i.status
703
- }), i;
704
- }
705
- async put(e, t) {
706
- let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await P({
707
- url: this.baseUrl + e,
708
- urlParams: t?.urlParams || {},
709
- headers: n,
710
- body: r
711
- });
712
- return this.onDebug(e, "put", {
713
- headers: n,
714
- body: r,
715
- message: i.message,
716
- status: i.status
717
- }), i;
718
- }
719
- async patch(e, t) {
720
- let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await ee({
721
- url: this.baseUrl + e,
722
- urlParams: t?.urlParams || {},
723
- headers: n,
724
- body: r
725
- });
726
- return this.onDebug(e, "patch", {
727
- headers: n,
728
- body: r,
729
- message: i.message,
730
- status: i.status
731
- }), i;
732
- }
733
- async delete(e, t) {
734
- let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await j({
735
- url: this.baseUrl + e,
736
- urlParams: t?.urlParams || {},
737
- headers: n,
738
- body: r
739
- });
740
- return this.onDebug(e, "delete", {
741
- headers: n,
742
- body: r,
743
- message: i.message,
744
- status: i.status
745
- }), i;
746
- }
747
- };
748
- //#endregion
749
- //#region src/utilities/decodeRequestBody.ts
750
- async function I(e) {
751
- let t, n = await e.arrayBuffer(), r = new TextDecoder().decode(n);
752
- try {
753
- t = JSON.parse(r);
754
- } catch {
755
- try {
756
- if (r.includes("=")) {
757
- let e = new URLSearchParams(r);
758
- t = Object.fromEntries(e.entries());
759
- } else throw new p("Invalid URLSearchParams format");
760
- } catch {
761
- throw new p("Failed to extract data from request");
762
- }
763
- }
764
- return t;
765
- }
766
- //#endregion
767
- //#region src/utilities/decodeRequestErrorMessage.ts
768
- function L(e, t) {
769
- 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";
770
- }
771
- //#endregion
772
- //#region src/utilities/errorHandler.ts
773
- function R(e) {
774
- switch (!0) {
775
- case e instanceof Response: return e;
776
- case e instanceof C: return e.toResponse();
777
- case e instanceof S: return e.toResponse();
778
- case e instanceof E: return e.toResponse();
779
- case e instanceof T: return e.toResponse();
780
- case e instanceof w: return e.toResponse();
781
- }
782
- switch (!0) {
783
- case e instanceof f: return e.toResponse();
784
- case e instanceof p: return e.toResponse();
785
- case e instanceof m: return e.toResponse();
786
- case e instanceof h: return e.toResponse();
787
- case e instanceof g: return e.toResponse();
788
- case e instanceof _: return e.toResponse();
789
- case e instanceof v: return e.toResponse();
790
- case e instanceof y: return e.toResponse();
791
- case e instanceof b: return e.toResponse();
792
- }
793
- return new v("Server error", e).toResponse();
794
- }
795
- //#endregion
796
- //#region src/utilities/formAsyncParse.ts
797
- async function z([e, t]) {
798
- let n = await t.safeParseAsync(e);
799
- return n.success === !1 ? {
800
- success: !1,
801
- fieldErrors: Object.fromEntries(n.error.issues.map((e) => [e.path.join("."), e.message])),
802
- fields: e
803
- } : {
804
- success: !0,
805
- data: n.data
806
- };
807
- }
808
- //#endregion
809
- //#region src/utilities/formParse.ts
810
- function B([e, t]) {
811
- let n = t.safeParse(e);
812
- return n.success === !1 ? {
813
- success: !1,
814
- fieldErrors: Object.fromEntries(n.error.issues.map((e) => [e.path.join("."), e.message])),
815
- fields: e
816
- } : {
817
- success: !0,
818
- data: n.data
819
- };
820
- }
821
- //#endregion
822
- //#region src/utilities/getScopedParams.ts
823
- function V(e, t = "") {
824
- let n = new URL(e.url);
825
- if (t === "") return n.searchParams;
826
- let r = Array.from(n.searchParams.entries()).filter(([e]) => e.startsWith(`${t}:`)).map(([e, n]) => [e.replace(`${t}:`, ""), n]);
827
- return new URLSearchParams(r);
828
- }
829
- //#endregion
830
- //#region src/utilities/schemaValidator.ts
831
- function H(e) {
832
- return ["Error validating:", ...e.issues.map(({ path: e, message: t }) => `-> ${e.join(".")}: ${t}`)].join("\n");
833
- }
834
- var U = class {
835
- schema;
836
- constructor(e) {
837
- this.schema = e;
838
- }
839
- isValid(e) {
840
- return this.schema.safeParse(e).success;
841
- }
842
- safeValidate(e) {
843
- return this.schema.safeParse(e);
844
- }
845
- validate(e) {
846
- try {
847
- return this.schema.parse(e);
848
- } catch (e) {
849
- throw new v(H(e));
850
- }
851
- }
852
- formValidate(e, t) {
853
- let n = B([e, this.schema]);
854
- if ("fieldErrors" in n) {
855
- let e = Object.keys(n.fieldErrors)[0];
856
- throw new b({
857
- fields: n.fields,
858
- fieldErrors: n.fieldErrors,
859
- data: { scrollTo: e },
860
- message: t
861
- });
862
- }
863
- return n.data;
864
- }
865
- async formAsyncValidate(e, t) {
866
- let n = await z([e, this.schema]);
867
- if ("fieldErrors" in n) {
868
- let e = Object.keys(n.fieldErrors)[0];
869
- throw new b({
870
- fields: n.fields,
871
- fieldErrors: n.fieldErrors,
872
- data: { scrollTo: e },
873
- message: t
874
- });
875
- }
876
- return n.data;
877
- }
878
- };
879
- //#endregion
880
- //#region src/validations/validateCep.ts
881
- function W(e) {
882
- if (!(/^\d{5}-\d{3}$/.test(e) || /^\d{8}$/.test(e))) return !1;
883
- let t = r(e), n = /^\d{8}$/.test(t);
884
- return t.length === 8 && n;
885
- }
886
- //#endregion
887
- //#region src/validations/validateCnpj.ts
888
- function G(e) {
889
- return e.length !== 14;
890
- }
891
- function K(e) {
892
- let [t] = e;
893
- return [...e].every((e) => e === t);
894
- }
895
- function q(e, t) {
896
- let n = 0;
897
- for (let r = 0; r < t.length; r++) n += parseInt(e[r]) * t[r];
898
- let r = n % 11;
899
- return r < 2 ? 0 : 11 - r;
900
- }
901
- function J(e) {
902
- return e.slice(12);
903
- }
904
- function te(e) {
905
- if (!e || e.length > 18 || e.length < 14 || /\s/.test(e)) return !1;
906
- let t = r(e);
907
- if (G(t) || K(t)) return !1;
908
- let n = t.slice(0, 12), i = q(n, [
909
- 5,
910
- 4,
911
- 3,
912
- 2,
913
- 9,
914
- 8,
915
- 7,
916
- 6,
917
- 5,
918
- 4,
919
- 3,
920
- 2
921
- ]), a = q(n + i, [
922
- 6,
923
- 5,
924
- 4,
925
- 3,
926
- 2,
927
- 9,
928
- 8,
929
- 7,
930
- 6,
931
- 5,
932
- 4,
933
- 3,
934
- 2
935
- ]);
936
- return J(t) === `${i}${a}`;
937
- }
938
- //#endregion
939
- //#region src/validations/validateCpf.ts
940
- function Y(e) {
941
- return e.length !== 11;
942
- }
943
- function X(e) {
944
- let [t] = e;
945
- return [...e].every((e) => e === t);
946
- }
947
- function Z(e, t) {
948
- let n = 0;
949
- for (let r of e) t > 1 && (n += parseInt(r) * t--);
950
- let r = n % 11;
951
- return r < 2 ? 0 : 11 - r;
952
- }
953
- function Q(e) {
954
- return e.slice(9);
955
- }
956
- function ne(e) {
957
- if (!e || e.length > 14 || e.length < 11 || /\s/.test(e)) return !1;
958
- let t = r(e);
959
- if (Y(t) || X(t)) return !1;
960
- let n = Z(t, 10), i = Z(t, 11);
961
- return Q(t) === `${n}${i}`;
962
- }
963
- //#endregion
964
- //#region src/validations/validateDate.ts
965
- function re(t, n) {
966
- let r = n?.inputFormat || "brazilianDate", i = n?.minYear || 1900, a = n?.maxYear || 3e3, o = new e();
967
- o.validateInputFormat(r);
968
- let s, c, l, u = t.split(/[-/]/).map(Number);
969
- if (u.length !== 3) return !1;
970
- try {
971
- switch (r) {
972
- case "brazilianDate":
973
- [s, c, l] = u, o.validateDateParts(l, c, s);
974
- break;
975
- case "isoDate":
976
- [c, s, l] = u, o.validateDateParts(l, c, s);
977
- break;
978
- case "timestamp":
979
- [l, c, s] = u, o.validateDateParts(l, c, s);
980
- break;
981
- }
982
- return !(l < i || l > a);
983
- } catch {
984
- return !1;
985
- }
986
- }
987
- //#endregion
988
- //#region src/validations/validateEmail.ts
989
- function ie(e) {
990
- 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);
991
- }
992
- function ae(e) {
993
- return !(e.length === 0 || e.length > 64 || e.startsWith(".") || e.endsWith(".") || e.includes("..") || !/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/.test(e));
994
- }
995
- function oe(e) {
996
- return !(e.length === 0 || e.length > 63 || e.startsWith("-") || e.endsWith("-") || !/^[a-zA-Z0-9-]+$/.test(e));
997
- }
998
- function $(e) {
999
- if (e.length === 0 || e.length > 253 || e.startsWith(".") || e.endsWith(".") || e.startsWith("-") || e.endsWith("-")) return !1;
1000
- let t = e.split(".");
1001
- if (t.length < 2) return !1;
1002
- for (let e of t) if (!oe(e)) return !1;
1003
- let n = t[t.length - 1];
1004
- return !(n.length < 2 || !/^[a-zA-Z]+$/.test(n));
1005
- }
1006
- function se(e) {
1007
- let t = e.split("@");
1008
- if (t.length !== 2) return !1;
1009
- let [n, r] = t;
1010
- return !(!ae(n) || !$(r));
1011
- }
1012
- function ce(e) {
1013
- let t = e.split("@");
1014
- return t.length === 2 ? t[1].toLowerCase() : null;
1015
- }
1016
- var le = [
1017
- "MX",
1018
- "A",
1019
- "AAAA"
1020
- ];
1021
- async function ue(e, t) {
1022
- try {
1023
- return await a?.promises?.resolve(e, t), !0;
1024
- } catch {
1025
- return !1;
1026
- }
1027
- }
1028
- async function de(e) {
1029
- for (let t of le) if (await ue(e, t)) return !0;
1030
- return !1;
1031
- }
1032
- async function fe(e) {
1033
- if (!e || typeof e != "string") return !1;
1034
- let t = e.trim();
1035
- if (!ie(t) || !se(t)) return !1;
1036
- let n = ce(t);
1037
- return n ? await de(n) : !1;
1038
- }
1039
- //#endregion
1040
- //#region src/validations/validatePassword.ts
1041
- function pe(e) {
1042
- return e ? [
1043
- e.length >= 8,
1044
- /[A-Z]/.test(e),
1045
- /[a-z]/.test(e),
1046
- /\d/.test(e),
1047
- /[!@#$%^&*(),.?":;{}|<>_\-+=~`[\]\\\/]/.test(e)
1048
- ].every((e) => e) : !1;
1049
- }
1050
- //#endregion
1051
- //#region src/validations/validatePhone.ts
1052
- function me(e) {
1053
- if (!s(e)) return !1;
1054
- let t = c(e)?.country;
1055
- return !(!t || !o.find((e) => e.iso === t));
1056
- }
1057
- //#endregion
1058
- //#region src/validations/validateRg.ts
1059
- function he(e) {
1060
- if (!e || !/^[0-9a-zA-Z.-]+$/.test(e)) return !1;
1061
- let t = e.replace(/[^a-zA-Z0-9]/g, "");
1062
- return t.length < 7 || t.length > 9 ? !1 : /^[0-9]{7,8}[0-9Xx]?$/.test(t);
1063
- }
1064
- //#endregion
1065
- 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 };