@arkyn/server 3.0.8 → 3.0.10

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 (33) hide show
  1. package/dist/http/api/_logRequest.d.ts.map +1 -1
  2. package/dist/http/badResponses/_badResponse.d.ts +7 -0
  3. package/dist/http/badResponses/_badResponse.d.ts.map +1 -1
  4. package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
  5. package/dist/index.js +239 -165
  6. package/dist/index.js.map +1 -1
  7. package/dist/modules/http/api/_logRequest.js +34 -31
  8. package/dist/modules/http/api/_logRequest.js.map +1 -1
  9. package/dist/modules/http/badResponses/_badResponse.js +3 -1
  10. package/dist/modules/http/badResponses/_badResponse.js.map +1 -1
  11. package/dist/modules/http/badResponses/unprocessableEntity.js +15 -5
  12. package/dist/modules/http/badResponses/unprocessableEntity.js.map +1 -1
  13. package/dist/modules/services/apiService.js +35 -23
  14. package/dist/modules/services/apiService.js.map +1 -1
  15. package/dist/modules/services/logService.js +29 -11
  16. package/dist/modules/services/logService.js.map +1 -1
  17. package/dist/modules/utilities/decodeRequestBody.js +13 -8
  18. package/dist/modules/utilities/decodeRequestBody.js.map +1 -1
  19. package/dist/modules/utilities/sensitiveDataKeys.js +31 -0
  20. package/dist/modules/utilities/sensitiveDataKeys.js.map +1 -0
  21. package/dist/modules/validations/validateEmail.js +21 -16
  22. package/dist/modules/validations/validateEmail.js.map +1 -1
  23. package/dist/services/apiService.d.ts +12 -0
  24. package/dist/services/apiService.d.ts.map +1 -1
  25. package/dist/services/logService.d.ts +15 -2
  26. package/dist/services/logService.d.ts.map +1 -1
  27. package/dist/utilities/decodeRequestBody.d.ts +7 -2
  28. package/dist/utilities/decodeRequestBody.d.ts.map +1 -1
  29. package/dist/utilities/sensitiveDataKeys.d.ts +22 -0
  30. package/dist/utilities/sensitiveDataKeys.d.ts.map +1 -0
  31. package/dist/validations/validateEmail.d.ts +10 -1
  32. package/dist/validations/validateEmail.d.ts.map +1 -1
  33. package/package.json +11 -11
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
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";
1
+ import { ValidateDateService as e, formatJsonObject as t, formatJsonString as n, parseSensitiveData as r, removeNonNumeric as i } from "@arkyn/shared";
2
+ import a from "node:path";
3
+ import o from "node:dns";
4
+ import { countries as s } from "@arkyn/templates";
5
+ import { isValidPhoneNumber as c, parsePhoneNumberWithError as l } from "libphonenumber-js";
6
6
  //#region src/services/debugService.ts
7
- var l = class e {
7
+ var u = class e {
8
8
  static ignoreFiles = [];
9
9
  static setIgnoreFile(t) {
10
10
  e.ignoreFiles.push(t);
@@ -16,10 +16,10 @@ var l = class e {
16
16
  let t = process.cwd(), n = ((/* @__PURE__ */ Error()).stack || "").split("\n").map((e) => e.trim()), r = 2;
17
17
  for (; r < n.length && (n[r].includes("node:internal") || n[r].includes("/node_modules/"));) r++;
18
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+\(([^)]+)\)/);
19
+ let i = n[r] || "", o = "Unknown function", s = "Unknown caller", c = i.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);
20
20
  if (c) o = c[1], s = c[2];
21
21
  else {
22
- let e = a.match(/at\s+(.+)/);
22
+ let e = i.match(/at\s+(.+)/);
23
23
  if (e) {
24
24
  s = e[1];
25
25
  let t = s.match(/at\s+([^(\s]+)\s+/);
@@ -28,7 +28,7 @@ var l = class e {
28
28
  }
29
29
  s.includes("(") && (s = s.substring(s.indexOf("(") + 1, s.lastIndexOf(")"))), s = s.split(":").slice(0, -2).join(":");
30
30
  try {
31
- s = i.relative(t, s);
31
+ s = a.relative(t, s);
32
32
  } catch {}
33
33
  return {
34
34
  functionName: o,
@@ -38,7 +38,7 @@ var l = class e {
38
38
  };
39
39
  //#endregion
40
40
  //#region src/utilities/flushDebugLogs.ts
41
- function u(e) {
41
+ function d(e) {
42
42
  if (process.env.NODE_ENV === "development" || process.env?.DEBUG_MODE === "true") {
43
43
  let t = `${{
44
44
  yellow: "\x1B[33m",
@@ -53,12 +53,13 @@ function u(e) {
53
53
  }
54
54
  //#endregion
55
55
  //#region src/http/badResponses/_badResponse.ts
56
- var d = class {
56
+ var f = class {
57
57
  _cause;
58
58
  _name = "BadResponse";
59
59
  _status = 500;
60
60
  _statusText = "Unknown error";
61
61
  _debugColor = "red";
62
+ exposeCauseInProduction = !1;
62
63
  get cause() {
63
64
  return this._cause;
64
65
  }
@@ -95,21 +96,22 @@ var d = class {
95
96
  ].includes(e) && (this._debugColor = e);
96
97
  }
97
98
  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({
99
+ let e = [], { callerInfo: t, functionName: r } = u.getCaller();
100
+ 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))}`), d({
100
101
  scheme: "red",
101
102
  name: this._name,
102
103
  debugs: e
103
104
  });
104
105
  }
105
106
  makeBody() {
107
+ let e = process.env.NODE_ENV === "production" && !this.exposeCauseInProduction;
106
108
  return {
107
109
  name: this._name,
108
110
  message: this._statusText,
109
- cause: this._cause
111
+ cause: e ? void 0 : this._cause
110
112
  };
111
113
  }
112
- }, f = class extends d {
114
+ }, p = class extends f {
113
115
  constructor(e, t) {
114
116
  super(), this.name = "BadGateway", this.status = 502, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
115
117
  }
@@ -128,7 +130,7 @@ var d = class {
128
130
  };
129
131
  return Response.json(this.makeBody(), e);
130
132
  }
131
- }, p = class extends d {
133
+ }, m = class extends f {
132
134
  constructor(e, t) {
133
135
  super(), this.name = "BadRequest", this.status = 400, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
134
136
  }
@@ -147,7 +149,7 @@ var d = class {
147
149
  };
148
150
  return Response.json(this.makeBody(), e);
149
151
  }
150
- }, m = class extends d {
152
+ }, h = class extends f {
151
153
  constructor(e, t) {
152
154
  super(), this.name = "Conflict", this.status = 409, this.statusText = e, this.debugColor = "yellow", this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
153
155
  }
@@ -166,7 +168,7 @@ var d = class {
166
168
  };
167
169
  return Response.json(this.makeBody(), e);
168
170
  }
169
- }, h = class extends d {
171
+ }, g = class extends f {
170
172
  constructor(e, t) {
171
173
  super(), this.name = "Forbidden", this.status = 403, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
172
174
  }
@@ -185,7 +187,7 @@ var d = class {
185
187
  };
186
188
  return Response.json(this.makeBody(), e);
187
189
  }
188
- }, g = class extends d {
190
+ }, _ = class extends f {
189
191
  constructor(e, t) {
190
192
  super(), this.name = "NotFound", this.status = 404, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
191
193
  }
@@ -204,7 +206,7 @@ var d = class {
204
206
  };
205
207
  return Response.json(this.makeBody(), e);
206
208
  }
207
- }, _ = class extends d {
209
+ }, v = class extends f {
208
210
  constructor(e, t) {
209
211
  super(), this.name = "NotImplemented", this.status = 501, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
210
212
  }
@@ -223,7 +225,7 @@ var d = class {
223
225
  };
224
226
  return Response.json(this.makeBody(), e);
225
227
  }
226
- }, v = class extends d {
228
+ }, y = class extends f {
227
229
  constructor(e, t) {
228
230
  super(), this.name = "ServerError", this.status = 500, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
229
231
  }
@@ -242,7 +244,7 @@ var d = class {
242
244
  };
243
245
  return Response.json(this.makeBody(), e);
244
246
  }
245
- }, y = class extends d {
247
+ }, b = class extends f {
246
248
  constructor(e, t) {
247
249
  super(), this.name = "Unauthorized", this.status = 401, this.statusText = e, this.debugColor = "yellow", this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
248
250
  }
@@ -261,12 +263,48 @@ var d = class {
261
263
  };
262
264
  return Response.json(this.makeBody(), e);
263
265
  }
264
- }, b = class extends d {
266
+ }, x = [
267
+ "password",
268
+ "Password",
269
+ "confirmPassword",
270
+ "ConfirmPassword",
271
+ "creditCard",
272
+ "CreditCard",
273
+ "authorization",
274
+ "Authorization",
275
+ "cookie",
276
+ "Cookie",
277
+ "set-cookie",
278
+ "Set-Cookie",
279
+ "setCookie",
280
+ "SetCookie",
281
+ "token",
282
+ "Token",
283
+ "refreshToken",
284
+ "RefreshToken",
285
+ "accessToken",
286
+ "AccessToken",
287
+ "apiKey",
288
+ "ApiKey",
289
+ "secret",
290
+ "Secret"
291
+ ];
292
+ //#endregion
293
+ //#region src/http/badResponses/unprocessableEntity.ts
294
+ function S(e) {
295
+ if (e === void 0) return e;
296
+ try {
297
+ return JSON.parse(r(JSON.stringify(e), [...x]));
298
+ } catch {
299
+ return e;
300
+ }
301
+ }
302
+ var C = class extends f {
265
303
  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,
304
+ super(), this.name = "UnprocessableEntity", this.status = 422, this.statusText = e.message || "Unprocessable entity", this.debugColor = "yellow", this.exposeCauseInProduction = !0, this.cause = {
305
+ data: S(e.data),
268
306
  fieldErrors: e.fieldErrors,
269
- fields: e.fields
307
+ fields: S(e.fields)
270
308
  }, this.onDebug();
271
309
  }
272
310
  toResponse() {
@@ -284,7 +322,7 @@ var d = class {
284
322
  };
285
323
  return Response.json(this.makeBody(), e);
286
324
  }
287
- }, x = class {
325
+ }, w = class {
288
326
  _body = null;
289
327
  _name = "SuccessResponse";
290
328
  _status = 200;
@@ -326,8 +364,8 @@ var d = class {
326
364
  ].includes(e) && (this._debugColor = e);
327
365
  }
328
366
  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({
367
+ let t = [], { callerInfo: n, functionName: r } = u.getCaller();
368
+ t.push(`Caller Function: ${r}`), t.push(`Caller Location: ${n}`), this.statusText && t.push(`Message: ${this.statusText}`), e && t.push(`Body: ${JSON.stringify(e)}`), d({
331
369
  scheme: this._debugColor,
332
370
  name: this.name,
333
371
  debugs: t
@@ -340,7 +378,7 @@ var d = class {
340
378
  body: this.body
341
379
  };
342
380
  }
343
- }, S = class extends x {
381
+ }, T = class extends w {
344
382
  constructor(e, t) {
345
383
  super(), this.name = "Created", this.status = 201, this.statusText = e, this.body = t || void 0, this.onDebug();
346
384
  }
@@ -359,7 +397,7 @@ var d = class {
359
397
  };
360
398
  return Response.json(this.body, e);
361
399
  }
362
- }, C = class extends x {
400
+ }, E = class extends w {
363
401
  constructor(e, t) {
364
402
  super(), this.name = "Found", this.status = 302, this.statusText = e, this.body = t || void 0, this.onDebug();
365
403
  }
@@ -378,7 +416,7 @@ var d = class {
378
416
  };
379
417
  return Response.json(this.body, e);
380
418
  }
381
- }, w = class extends x {
419
+ }, D = class extends w {
382
420
  constructor(e) {
383
421
  super(), this.name = "NoContent", this.status = 204, this.statusText = e, this.onDebug();
384
422
  }
@@ -390,7 +428,7 @@ var d = class {
390
428
  };
391
429
  return new Response(null, e);
392
430
  }
393
- }, T = class extends x {
431
+ }, O = class extends w {
394
432
  constructor(e, t) {
395
433
  super(), this.name = "Success", this.status = 200, this.statusText = e, this.body = t || void 0, this.onDebug();
396
434
  }
@@ -409,7 +447,7 @@ var d = class {
409
447
  };
410
448
  return Response.json(this.body, e);
411
449
  }
412
- }, E = class extends x {
450
+ }, k = class extends w {
413
451
  constructor(e, t) {
414
452
  super(), this.name = "Updated", this.status = 200, this.statusText = e, this.body = t || void 0, this.onDebug();
415
453
  }
@@ -428,7 +466,7 @@ var d = class {
428
466
  };
429
467
  return Response.json(this.body, e);
430
468
  }
431
- }, D = class e {
469
+ }, A = class e {
432
470
  static mapHeaders(e) {
433
471
  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
472
  }
@@ -455,15 +493,32 @@ var d = class {
455
493
  responseBody: t.responseBody || null
456
494
  };
457
495
  }
458
- }, O = class e {
496
+ }, j = class e {
459
497
  static config;
498
+ static isSecureEndpoint(e) {
499
+ return e.protocol === "https:" ? !0 : e.hostname === "localhost" || e.hostname === "127.0.0.1";
500
+ }
460
501
  static setConfig(t) {
461
502
  if (e.config) return;
462
- let { trafficSourceId: n, userToken: r, logBaseApiUrl: i } = t;
503
+ let { trafficSourceId: n, userToken: r, logBaseApiUrl: i } = t, a = null;
504
+ if (i) try {
505
+ let t = new URL(i);
506
+ e.isSecureEndpoint(t) ? a = `${i}/ingest-log` : d({
507
+ name: "LogServiceError",
508
+ scheme: "red",
509
+ debugs: [`Insecure logBaseApiUrl "${i}" rejected: use https://, or http:// only for localhost/127.0.0.1. Remote logging disabled.`]
510
+ });
511
+ } catch {
512
+ d({
513
+ name: "LogServiceError",
514
+ scheme: "red",
515
+ debugs: [`Invalid logBaseApiUrl "${i}". Remote logging disabled.`]
516
+ });
517
+ }
463
518
  e.config = {
464
519
  trafficSourceId: n,
465
520
  userToken: r,
466
- apiUrl: `${i || "http://62.238.8.44:8081"}/ingest-log`
521
+ apiUrl: a
467
522
  };
468
523
  }
469
524
  static getConfig() {
@@ -475,38 +530,40 @@ var d = class {
475
530
  };
476
531
  //#endregion
477
532
  //#region src/http/api/_logRequest.ts
478
- async function k(e) {
479
- let n = O.getConfig();
533
+ async function M(e) {
534
+ let n = j.getConfig();
480
535
  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;
536
+ let { userToken: i, apiUrl: a, trafficSourceId: o } = n;
537
+ if (!a) return;
538
+ let { elapsedTime: s, method: c, queryParams: l, requestBody: u, requestHeaders: f, responseBody: p, responseHeaders: m, status: h, rawUrl: g } = e;
482
539
  if (process.env.NODE_ENV !== "development") try {
483
- let e = new URL(h), n = "https";
540
+ let e = new URL(g), n = "https";
484
541
  e.protocol === "http:" && (n = "http");
485
- let g = JSON.stringify({
542
+ let _ = JSON.stringify({
486
543
  domainUrl: `${e.protocol}//${e.host}`,
487
544
  pathnameUrl: e.pathname,
488
- trafficSourceId: a,
489
- status: m,
545
+ trafficSourceId: o,
546
+ status: h,
490
547
  protocol: n,
491
- method: s.toLowerCase(),
548
+ method: c.toLowerCase(),
492
549
  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
- }), _ = {
550
+ elapsedTime: s,
551
+ requestHeaders: r(JSON.stringify(f), [...x]),
552
+ requestBody: r(JSON.stringify(u), [...x]),
553
+ queryParams: JSON.stringify(l),
554
+ responseHeaders: r(JSON.stringify(m), [...x]),
555
+ responseBody: r(JSON.stringify(p), [...x])
556
+ }), v = {
500
557
  "Content-Type": "application/json",
501
- Authorization: `Bearer ${r}`
502
- }, v = await fetch(i, {
558
+ Authorization: `Bearer ${i}`
559
+ }, y = await fetch(a, {
503
560
  method: "POST",
504
- body: g,
505
- headers: _
561
+ body: _,
562
+ headers: v
506
563
  });
507
- if (!v.ok) {
508
- let e = await v.text(), n = v.status, r = v.statusText, i = await v.json().catch(() => null);
509
- u({
564
+ if (!y.ok) {
565
+ let e = await y.text(), n = y.status, r = y.statusText, i = await y.json().catch(() => null);
566
+ d({
510
567
  name: "LogError",
511
568
  scheme: "red",
512
569
  debugs: [
@@ -518,7 +575,7 @@ async function k(e) {
518
575
  });
519
576
  }
520
577
  } catch (e) {
521
- u({
578
+ d({
522
579
  debugs: [`Error sending request: ${e}`],
523
580
  name: "LogError",
524
581
  scheme: "red"
@@ -527,7 +584,7 @@ async function k(e) {
527
584
  }
528
585
  //#endregion
529
586
  //#region src/http/api/_makeRequest.ts
530
- async function A(e) {
587
+ async function N(e) {
531
588
  let t = e.url;
532
589
  e.urlParams && Object.entries(e.urlParams).forEach(([e, n]) => {
533
590
  t = t.replaceAll(`:${e}`, n);
@@ -553,7 +610,7 @@ async function A(e) {
553
610
  } catch {
554
611
  c = null;
555
612
  }
556
- return k(D.handle({
613
+ return M(A.handle({
557
614
  elapsedTime: o,
558
615
  method: e.method,
559
616
  queryParams: new URL(t).searchParams,
@@ -578,7 +635,7 @@ async function A(e) {
578
635
  cause: null
579
636
  };
580
637
  } catch (e) {
581
- return u({
638
+ return d({
582
639
  debugs: [`Network error or request failed: ${e}`],
583
640
  name: "MakeRequestError",
584
641
  scheme: "red"
@@ -593,8 +650,8 @@ async function A(e) {
593
650
  }
594
651
  //#endregion
595
652
  //#region src/http/api/_deleteRequest.ts
596
- async function j(e) {
597
- return A({
653
+ async function P(e) {
654
+ return N({
598
655
  method: "DELETE",
599
656
  url: e.url,
600
657
  urlParams: e.urlParams,
@@ -604,8 +661,8 @@ async function j(e) {
604
661
  }
605
662
  //#endregion
606
663
  //#region src/http/api/_getRequest.ts
607
- async function M(e) {
608
- return A({
664
+ async function ee(e) {
665
+ return N({
609
666
  method: "GET",
610
667
  url: e.url,
611
668
  urlParams: e.urlParams,
@@ -614,8 +671,8 @@ async function M(e) {
614
671
  }
615
672
  //#endregion
616
673
  //#region src/http/api/_patchRequest.ts
617
- async function ee(e) {
618
- return A({
674
+ async function te(e) {
675
+ return N({
619
676
  method: "PATCH",
620
677
  url: e.url,
621
678
  urlParams: e.urlParams,
@@ -625,8 +682,8 @@ async function ee(e) {
625
682
  }
626
683
  //#endregion
627
684
  //#region src/http/api/_postRequest.ts
628
- async function N(e) {
629
- return A({
685
+ async function F(e) {
686
+ return N({
630
687
  method: "POST",
631
688
  url: e.url,
632
689
  urlParams: e.urlParams,
@@ -636,8 +693,8 @@ async function N(e) {
636
693
  }
637
694
  //#endregion
638
695
  //#region src/http/api/_putRequest.ts
639
- async function P(e) {
640
- return A({
696
+ async function I(e) {
697
+ return N({
641
698
  method: "PUT",
642
699
  url: e.url,
643
700
  urlParams: e.urlParams,
@@ -647,7 +704,7 @@ async function P(e) {
647
704
  }
648
705
  //#endregion
649
706
  //#region src/services/apiService.ts
650
- var F = class {
707
+ var L = class e {
651
708
  baseUrl;
652
709
  baseHeaders;
653
710
  baseToken;
@@ -655,11 +712,21 @@ var F = class {
655
712
  constructor(e) {
656
713
  this.baseUrl = e.baseUrl, this.baseHeaders = e.baseHeaders || void 0, this.baseToken = e.baseToken || void 0, this.enableDebug = e.enableDebug || !1;
657
714
  }
658
- onDebug(e, t, n) {
715
+ static toPlainHeaders(e) {
716
+ return e instanceof Headers ? Object.fromEntries(e.entries()) : Object.fromEntries(new Headers(e).entries());
717
+ }
718
+ static toRedactedJson(e) {
719
+ return r(JSON.stringify(e), [...x]);
720
+ }
721
+ onDebug(t, n, r) {
659
722
  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,
723
+ let i = [];
724
+ if (i.push(`Base URL: ${this.baseUrl}`), i.push(`Endpoint: ${t}`), i.push(`Status/Method: ${n} => ${r.status}`), i.push(`Message: ${r.message}`), r.headers) {
725
+ let t = e.toPlainHeaders(r.headers);
726
+ i.push(`Headers: ${e.toRedactedJson(t)}`);
727
+ }
728
+ r.body && i.push(`Body: ${e.toRedactedJson(r.body)}`), d({
729
+ debugs: i,
663
730
  name: "ApiDebug",
664
731
  scheme: "yellow"
665
732
  });
@@ -679,7 +746,7 @@ var F = class {
679
746
  }), n;
680
747
  }
681
748
  async get(e, t) {
682
- let n = this.generateHeaders(t?.headers || {}, t?.token), r = await M({
749
+ let n = this.generateHeaders(t?.headers || {}, t?.token), r = await ee({
683
750
  url: this.baseUrl + e,
684
751
  urlParams: t?.urlParams || {},
685
752
  headers: n
@@ -691,7 +758,7 @@ var F = class {
691
758
  }), r;
692
759
  }
693
760
  async post(e, t) {
694
- let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await N({
761
+ let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await F({
695
762
  url: this.baseUrl + e,
696
763
  urlParams: t?.urlParams || {},
697
764
  headers: n,
@@ -705,7 +772,7 @@ var F = class {
705
772
  }), i;
706
773
  }
707
774
  async put(e, t) {
708
- let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await P({
775
+ let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await I({
709
776
  url: this.baseUrl + e,
710
777
  urlParams: t?.urlParams || {},
711
778
  headers: n,
@@ -719,7 +786,7 @@ var F = class {
719
786
  }), i;
720
787
  }
721
788
  async patch(e, t) {
722
- let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await ee({
789
+ let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await te({
723
790
  url: this.baseUrl + e,
724
791
  urlParams: t?.urlParams || {},
725
792
  headers: n,
@@ -733,7 +800,7 @@ var F = class {
733
800
  }), i;
734
801
  }
735
802
  async delete(e, t) {
736
- let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await j({
803
+ let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await P({
737
804
  url: this.baseUrl + e,
738
805
  urlParams: t?.urlParams || {},
739
806
  headers: n,
@@ -746,43 +813,44 @@ var F = class {
746
813
  status: i.status
747
814
  }), i;
748
815
  }
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);
816
+ }, R = 5 * 1024 * 1024;
817
+ async function z(e, t) {
818
+ let n, r = t?.maxBodySizeBytes ?? R, i = Number(e.headers.get("content-length"));
819
+ if (Number.isFinite(i) && i > r) throw new m("Request body exceeds the maximum allowed size");
820
+ let a = await e.arrayBuffer();
821
+ if (a.byteLength > r) throw new m("Request body exceeds the maximum allowed size");
822
+ let o = new TextDecoder().decode(a);
754
823
  try {
755
- t = JSON.parse(r);
824
+ n = JSON.parse(o);
756
825
  } catch {
757
826
  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");
827
+ if (o.includes("=")) {
828
+ let e = new URLSearchParams(o);
829
+ n = Object.fromEntries(e.entries());
830
+ } else throw new m("Invalid URLSearchParams format");
762
831
  } catch {
763
- throw new p("Failed to extract data from request");
832
+ throw new m("Failed to extract data from request");
764
833
  }
765
834
  }
766
- return t;
835
+ return n;
767
836
  }
768
837
  //#endregion
769
838
  //#region src/utilities/decodeRequestErrorMessage.ts
770
- function L(e, t) {
839
+ function B(e, t) {
771
840
  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
841
  }
773
842
  //#endregion
774
843
  //#region src/utilities/errorHandler.ts
775
- function R(e) {
844
+ function V(e) {
776
845
  switch (!0) {
777
846
  case e instanceof Response: return e;
778
- case e instanceof C: return e.toResponse();
779
- case e instanceof S: return e.toResponse();
780
847
  case e instanceof E: return e.toResponse();
781
848
  case e instanceof T: return e.toResponse();
782
- case e instanceof w: return e.toResponse();
849
+ case e instanceof k: return e.toResponse();
850
+ case e instanceof O: return e.toResponse();
851
+ case e instanceof D: return e.toResponse();
783
852
  }
784
853
  switch (!0) {
785
- case e instanceof f: return e.toResponse();
786
854
  case e instanceof p: return e.toResponse();
787
855
  case e instanceof m: return e.toResponse();
788
856
  case e instanceof h: return e.toResponse();
@@ -791,12 +859,13 @@ function R(e) {
791
859
  case e instanceof v: return e.toResponse();
792
860
  case e instanceof y: return e.toResponse();
793
861
  case e instanceof b: return e.toResponse();
862
+ case e instanceof C: return e.toResponse();
794
863
  }
795
- return new v("Server error", e).toResponse();
864
+ return new y("Server error", e).toResponse();
796
865
  }
797
866
  //#endregion
798
867
  //#region src/utilities/formAsyncParse.ts
799
- async function z([e, t]) {
868
+ async function H([e, t]) {
800
869
  let n = await t.safeParseAsync(e);
801
870
  return n.success === !1 ? {
802
871
  success: !1,
@@ -809,7 +878,7 @@ async function z([e, t]) {
809
878
  }
810
879
  //#endregion
811
880
  //#region src/utilities/formParse.ts
812
- function B([e, t]) {
881
+ function U([e, t]) {
813
882
  let n = t.safeParse(e);
814
883
  return n.success === !1 ? {
815
884
  success: !1,
@@ -822,7 +891,7 @@ function B([e, t]) {
822
891
  }
823
892
  //#endregion
824
893
  //#region src/utilities/getScopedParams.ts
825
- function V(e, t = "") {
894
+ function W(e, t = "") {
826
895
  let n = new URL(e.url);
827
896
  if (t === "") return n.searchParams;
828
897
  let r = Array.from(n.searchParams.entries()).filter(([e]) => e.startsWith(`${t}:`)).map(([e, n]) => [e.replace(`${t}:`, ""), n]);
@@ -830,10 +899,10 @@ function V(e, t = "") {
830
899
  }
831
900
  //#endregion
832
901
  //#region src/utilities/schemaValidator.ts
833
- function H(e) {
902
+ function G(e) {
834
903
  return ["Error validating:", ...e.issues.map(({ path: e, message: t }) => `-> ${e.join(".")}: ${t}`)].join("\n");
835
904
  }
836
- var U = class {
905
+ var K = class {
837
906
  schema;
838
907
  constructor(e) {
839
908
  this.schema = e;
@@ -848,14 +917,14 @@ var U = class {
848
917
  try {
849
918
  return this.schema.parse(e);
850
919
  } catch (e) {
851
- throw new v(H(e));
920
+ throw new y(G(e));
852
921
  }
853
922
  }
854
923
  formValidate(e, t) {
855
- let n = B([e, this.schema]);
924
+ let n = U([e, this.schema]);
856
925
  if ("fieldErrors" in n) {
857
926
  let e = Object.keys(n.fieldErrors)[0];
858
- throw new b({
927
+ throw new C({
859
928
  fields: n.fields,
860
929
  fieldErrors: n.fieldErrors,
861
930
  data: { scrollTo: e },
@@ -865,10 +934,10 @@ var U = class {
865
934
  return n.data;
866
935
  }
867
936
  async formAsyncValidate(e, t) {
868
- let n = await z([e, this.schema]);
937
+ let n = await H([e, this.schema]);
869
938
  if ("fieldErrors" in n) {
870
939
  let e = Object.keys(n.fieldErrors)[0];
871
- throw new b({
940
+ throw new C({
872
941
  fields: n.fields,
873
942
  fieldErrors: n.fieldErrors,
874
943
  data: { scrollTo: e },
@@ -880,34 +949,34 @@ var U = class {
880
949
  };
881
950
  //#endregion
882
951
  //#region src/validations/validateCep.ts
883
- function W(e) {
952
+ function q(e) {
884
953
  if (!(/^\d{5}-\d{3}$/.test(e) || /^\d{8}$/.test(e))) return !1;
885
- let t = r(e), n = /^\d{8}$/.test(t);
954
+ let t = i(e), n = /^\d{8}$/.test(t);
886
955
  return t.length === 8 && n;
887
956
  }
888
957
  //#endregion
889
958
  //#region src/validations/validateCnpj.ts
890
- function G(e) {
959
+ function J(e) {
891
960
  return e.length !== 14;
892
961
  }
893
- function K(e) {
962
+ function Y(e) {
894
963
  let [t] = e;
895
964
  return [...e].every((e) => e === t);
896
965
  }
897
- function q(e, t) {
966
+ function X(e, t) {
898
967
  let n = 0;
899
968
  for (let r = 0; r < t.length; r++) n += parseInt(e[r], 10) * t[r];
900
969
  let r = n % 11;
901
970
  return r < 2 ? 0 : 11 - r;
902
971
  }
903
- function J(e) {
972
+ function ne(e) {
904
973
  return e.slice(12);
905
974
  }
906
- function te(e) {
975
+ function Z(e) {
907
976
  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, [
977
+ let t = i(e);
978
+ if (J(t) || Y(t)) return !1;
979
+ let n = t.slice(0, 12), r = X(n, [
911
980
  5,
912
981
  4,
913
982
  3,
@@ -920,7 +989,7 @@ function te(e) {
920
989
  4,
921
990
  3,
922
991
  2
923
- ]), a = q(n + i, [
992
+ ]), a = X(n + r, [
924
993
  6,
925
994
  5,
926
995
  4,
@@ -935,36 +1004,36 @@ function te(e) {
935
1004
  3,
936
1005
  2
937
1006
  ]);
938
- return J(t) === `${i}${a}`;
1007
+ return ne(t) === `${r}${a}`;
939
1008
  }
940
1009
  //#endregion
941
1010
  //#region src/validations/validateCpf.ts
942
- function Y(e) {
1011
+ function re(e) {
943
1012
  return e.length !== 11;
944
1013
  }
945
- function X(e) {
1014
+ function ie(e) {
946
1015
  let [t] = e;
947
1016
  return [...e].every((e) => e === t);
948
1017
  }
949
- function Z(e, t) {
1018
+ function Q(e, t) {
950
1019
  let n = 0;
951
1020
  for (let r of e) t > 1 && (n += parseInt(r, 10) * t--);
952
1021
  let r = n % 11;
953
1022
  return r < 2 ? 0 : 11 - r;
954
1023
  }
955
- function Q(e) {
1024
+ function ae(e) {
956
1025
  return e.slice(9);
957
1026
  }
958
- function ne(e) {
1027
+ function oe(e) {
959
1028
  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}`;
1029
+ let t = i(e);
1030
+ if (re(t) || ie(t)) return !1;
1031
+ let n = Q(t, 10), r = Q(t, 11);
1032
+ return ae(t) === `${n}${r}`;
964
1033
  }
965
1034
  //#endregion
966
1035
  //#region src/validations/validateDate.ts
967
- function re(t, n) {
1036
+ function se(t, n) {
968
1037
  let r = n?.inputFormat || "brazilianDate", i = n?.minYear || 1900, a = n?.maxYear || 3e3, o = new e();
969
1038
  o.validateInputFormat(r);
970
1039
  let s, c, l, u = t.split(/[-/]/).map(Number);
@@ -988,59 +1057,64 @@ function re(t, n) {
988
1057
  }
989
1058
  //#endregion
990
1059
  //#region src/validations/validateEmail.ts
991
- function ie(e) {
1060
+ function ce(e) {
992
1061
  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
1062
  }
994
- function ae(e) {
1063
+ function le(e) {
995
1064
  return !(e.length === 0 || e.length > 64 || e.startsWith(".") || e.endsWith(".") || e.includes("..") || !/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/.test(e));
996
1065
  }
997
- function oe(e) {
1066
+ function ue(e) {
998
1067
  return !(e.length === 0 || e.length > 63 || e.startsWith("-") || e.endsWith("-") || !/^[a-zA-Z0-9-]+$/.test(e));
999
1068
  }
1000
- function $(e) {
1069
+ function de(e) {
1001
1070
  if (e.length === 0 || e.length > 253 || e.startsWith(".") || e.endsWith(".") || e.startsWith("-") || e.endsWith("-")) return !1;
1002
1071
  let t = e.split(".");
1003
1072
  if (t.length < 2) return !1;
1004
- for (let e of t) if (!oe(e)) return !1;
1073
+ for (let e of t) if (!ue(e)) return !1;
1005
1074
  let n = t[t.length - 1];
1006
1075
  return !(n.length < 2 || !/^[a-zA-Z]+$/.test(n));
1007
1076
  }
1008
- function se(e) {
1077
+ function fe(e) {
1009
1078
  let t = e.split("@");
1010
1079
  if (t.length !== 2) return !1;
1011
1080
  let [n, r] = t;
1012
- return !(!ae(n) || !$(r));
1081
+ return !(!le(n) || !de(r));
1013
1082
  }
1014
- function ce(e) {
1083
+ function pe(e) {
1015
1084
  let t = e.split("@");
1016
1085
  return t.length === 2 ? t[1].toLowerCase() : null;
1017
1086
  }
1018
- var le = [
1087
+ var $ = [
1019
1088
  "MX",
1020
1089
  "A",
1021
1090
  "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
- }
1091
+ ], me = 5e3;
1092
+ async function he(e, t, n) {
1093
+ return new Promise((r) => {
1094
+ let i = !1, a = setTimeout(() => {
1095
+ i || (i = !0, r(!1));
1096
+ }, n);
1097
+ a.unref?.(), o.promises.resolve(e, t).then(() => {
1098
+ i || (i = !0, clearTimeout(a), r(!0));
1099
+ }).catch(() => {
1100
+ i || (i = !0, clearTimeout(a), r(!1));
1101
+ });
1102
+ });
1029
1103
  }
1030
- async function de(e) {
1031
- for (let t of le) if (await ue(e, t)) return !0;
1104
+ async function ge(e, t) {
1105
+ for (let n of $) if (await he(e, n, t)) return !0;
1032
1106
  return !1;
1033
1107
  }
1034
- async function fe(e) {
1108
+ async function _e(e, t) {
1035
1109
  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;
1110
+ let n = e.trim();
1111
+ if (!ce(n) || !fe(n)) return !1;
1112
+ let r = pe(n);
1113
+ return r ? await ge(r, t?.dnsTimeoutMs ?? me) : !1;
1040
1114
  }
1041
1115
  //#endregion
1042
1116
  //#region src/validations/validatePassword.ts
1043
- function pe(e) {
1117
+ function ve(e) {
1044
1118
  return e ? [
1045
1119
  e.length >= 8,
1046
1120
  /[A-Z]/.test(e),
@@ -1051,19 +1125,19 @@ function pe(e) {
1051
1125
  }
1052
1126
  //#endregion
1053
1127
  //#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));
1128
+ function ye(e) {
1129
+ if (!c(e)) return !1;
1130
+ let t = l(e)?.country;
1131
+ return !(!t || !s.find((e) => e.iso === t));
1058
1132
  }
1059
1133
  //#endregion
1060
1134
  //#region src/validations/validateRg.ts
1061
- function he(e) {
1135
+ function be(e) {
1062
1136
  if (!e || !/^[0-9a-zA-Z.-]+$/.test(e)) return !1;
1063
1137
  let t = e.replace(/[^a-zA-Z0-9]/g, "");
1064
1138
  return t.length < 7 || t.length > 9 ? !1 : /^[0-9]{7,8}[0-9Xx]?$/.test(t);
1065
1139
  }
1066
1140
  //#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 };
1141
+ export { L as ApiService, p as BadGateway, m as BadRequest, h as Conflict, T as Created, u as DebugService, g as Forbidden, E as Found, j as LogService, D as NoContent, _ as NotFound, v as NotImplemented, K as SchemaValidator, y as ServerError, O as Success, b as Unauthorized, C as UnprocessableEntity, k as Updated, z as decodeRequestBody, B as decodeRequestErrorMessage, V as errorHandler, d as flushDebugLogs, H as formAsyncParse, U as formParse, W as getScopedParams, q as validateCep, Z as validateCnpj, oe as validateCpf, se as validateDate, _e as validateEmail, ve as validatePassword, ye as validatePhone, be as validateRg };
1068
1142
 
1069
1143
  //# sourceMappingURL=index.js.map