@arkyn/server 3.0.10 → 3.0.12

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 (79) hide show
  1. package/AGENTS.md +7 -2
  2. package/README.md +25 -3
  3. package/dist/http/api/_deleteRequest.d.ts +1 -0
  4. package/dist/http/api/_deleteRequest.d.ts.map +1 -1
  5. package/dist/http/api/_getRequest.d.ts +1 -0
  6. package/dist/http/api/_getRequest.d.ts.map +1 -1
  7. package/dist/http/api/_makeRequest.d.ts +2 -0
  8. package/dist/http/api/_makeRequest.d.ts.map +1 -1
  9. package/dist/http/api/_patchRequest.d.ts +1 -0
  10. package/dist/http/api/_patchRequest.d.ts.map +1 -1
  11. package/dist/http/api/_postRequest.d.ts +1 -0
  12. package/dist/http/api/_postRequest.d.ts.map +1 -1
  13. package/dist/http/api/_putRequest.d.ts +1 -0
  14. package/dist/http/api/_putRequest.d.ts.map +1 -1
  15. package/dist/http/badResponses/_badResponse.d.ts +2 -1
  16. package/dist/http/badResponses/_badResponse.d.ts.map +1 -1
  17. package/dist/http/badResponses/badGateway.d.ts +1 -1
  18. package/dist/http/badResponses/badRequest.d.ts +1 -1
  19. package/dist/http/badResponses/conflict.d.ts +1 -1
  20. package/dist/http/badResponses/forbidden.d.ts +1 -1
  21. package/dist/http/badResponses/notFound.d.ts +1 -1
  22. package/dist/http/badResponses/notImplemented.d.ts +1 -1
  23. package/dist/http/badResponses/serverError.d.ts +1 -1
  24. package/dist/http/badResponses/unauthorized.d.ts +1 -1
  25. package/dist/index.d.ts +1 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +181 -134
  28. package/dist/index.js.map +1 -1
  29. package/dist/modules/http/api/_deleteRequest.js +2 -1
  30. package/dist/modules/http/api/_deleteRequest.js.map +1 -1
  31. package/dist/modules/http/api/_getRequest.js +2 -1
  32. package/dist/modules/http/api/_getRequest.js.map +1 -1
  33. package/dist/modules/http/api/_logRequest.js +1 -1
  34. package/dist/modules/http/api/_logRequest.js.map +1 -1
  35. package/dist/modules/http/api/_makeRequest.js +51 -33
  36. package/dist/modules/http/api/_makeRequest.js.map +1 -1
  37. package/dist/modules/http/api/_patchRequest.js +2 -1
  38. package/dist/modules/http/api/_patchRequest.js.map +1 -1
  39. package/dist/modules/http/api/_postRequest.js +2 -1
  40. package/dist/modules/http/api/_postRequest.js.map +1 -1
  41. package/dist/modules/http/api/_putRequest.js +2 -1
  42. package/dist/modules/http/api/_putRequest.js.map +1 -1
  43. package/dist/modules/http/badResponses/_badResponse.js +4 -1
  44. package/dist/modules/http/badResponses/_badResponse.js.map +1 -1
  45. package/dist/modules/http/badResponses/badGateway.js +1 -1
  46. package/dist/modules/http/badResponses/badGateway.js.map +1 -1
  47. package/dist/modules/http/badResponses/badRequest.js +1 -1
  48. package/dist/modules/http/badResponses/badRequest.js.map +1 -1
  49. package/dist/modules/http/badResponses/conflict.js +1 -1
  50. package/dist/modules/http/badResponses/conflict.js.map +1 -1
  51. package/dist/modules/http/badResponses/forbidden.js +1 -1
  52. package/dist/modules/http/badResponses/forbidden.js.map +1 -1
  53. package/dist/modules/http/badResponses/notFound.js +1 -1
  54. package/dist/modules/http/badResponses/notFound.js.map +1 -1
  55. package/dist/modules/http/badResponses/notImplemented.js +1 -1
  56. package/dist/modules/http/badResponses/notImplemented.js.map +1 -1
  57. package/dist/modules/http/badResponses/serverError.js +1 -1
  58. package/dist/modules/http/badResponses/serverError.js.map +1 -1
  59. package/dist/modules/http/badResponses/unauthorized.js +1 -1
  60. package/dist/modules/http/badResponses/unauthorized.js.map +1 -1
  61. package/dist/modules/http/badResponses/unprocessableEntity.js +1 -1
  62. package/dist/modules/http/badResponses/unprocessableEntity.js.map +1 -1
  63. package/dist/modules/services/apiService.js +12 -6
  64. package/dist/modules/services/apiService.js.map +1 -1
  65. package/dist/modules/services/logService.js +21 -8
  66. package/dist/modules/services/logService.js.map +1 -1
  67. package/dist/modules/utilities/withSecurityHeaders.js +18 -0
  68. package/dist/modules/utilities/withSecurityHeaders.js.map +1 -0
  69. package/dist/modules/validations/validateDate.js +4 -14
  70. package/dist/modules/validations/validateDate.js.map +1 -1
  71. package/dist/services/apiService.d.ts +5 -0
  72. package/dist/services/apiService.d.ts.map +1 -1
  73. package/dist/services/logService.d.ts +25 -5
  74. package/dist/services/logService.d.ts.map +1 -1
  75. package/dist/utilities/withSecurityHeaders.d.ts +45 -0
  76. package/dist/utilities/withSecurityHeaders.d.ts.map +1 -0
  77. package/dist/validations/validateDate.d.ts +3 -2
  78. package/dist/validations/validateDate.d.ts.map +1 -1
  79. package/package.json +9 -1
package/dist/index.js CHANGED
@@ -53,13 +53,16 @@ function d(e) {
53
53
  }
54
54
  //#endregion
55
55
  //#region src/http/badResponses/_badResponse.ts
56
- var f = class {
56
+ var f = class extends Error {
57
57
  _cause;
58
58
  _name = "BadResponse";
59
59
  _status = 500;
60
60
  _statusText = "Unknown error";
61
61
  _debugColor = "red";
62
62
  exposeCauseInProduction = !1;
63
+ constructor(e) {
64
+ super(e || "Unknown error"), this.name = "BadResponse", e && (this._statusText = e), Error.captureStackTrace?.(this, this.constructor);
65
+ }
63
66
  get cause() {
64
67
  return this._cause;
65
68
  }
@@ -113,7 +116,7 @@ var f = class {
113
116
  }
114
117
  }, p = class extends f {
115
118
  constructor(e, t) {
116
- super(), this.name = "BadGateway", this.status = 502, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
119
+ super(e), this.name = "BadGateway", this.status = 502, this.statusText = e, this.cause = t, this.onDebug();
117
120
  }
118
121
  toResponse() {
119
122
  let e = {
@@ -132,7 +135,7 @@ var f = class {
132
135
  }
133
136
  }, m = class extends f {
134
137
  constructor(e, t) {
135
- super(), this.name = "BadRequest", this.status = 400, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
138
+ super(e), this.name = "BadRequest", this.status = 400, this.statusText = e, this.cause = t, this.onDebug();
136
139
  }
137
140
  toResponse() {
138
141
  let e = {
@@ -151,7 +154,7 @@ var f = class {
151
154
  }
152
155
  }, h = class extends f {
153
156
  constructor(e, t) {
154
- super(), this.name = "Conflict", this.status = 409, this.statusText = e, this.debugColor = "yellow", this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
157
+ super(e), this.name = "Conflict", this.status = 409, this.statusText = e, this.debugColor = "yellow", this.cause = t, this.onDebug();
155
158
  }
156
159
  toResponse() {
157
160
  let e = {
@@ -170,7 +173,7 @@ var f = class {
170
173
  }
171
174
  }, g = class extends f {
172
175
  constructor(e, t) {
173
- super(), this.name = "Forbidden", this.status = 403, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
176
+ super(e), this.name = "Forbidden", this.status = 403, this.statusText = e, this.cause = t, this.onDebug();
174
177
  }
175
178
  toResponse() {
176
179
  let e = {
@@ -189,7 +192,7 @@ var f = class {
189
192
  }
190
193
  }, _ = class extends f {
191
194
  constructor(e, t) {
192
- super(), this.name = "NotFound", this.status = 404, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
195
+ super(e), this.name = "NotFound", this.status = 404, this.statusText = e, this.cause = t, this.onDebug();
193
196
  }
194
197
  toResponse() {
195
198
  let e = {
@@ -208,7 +211,7 @@ var f = class {
208
211
  }
209
212
  }, v = class extends f {
210
213
  constructor(e, t) {
211
- super(), this.name = "NotImplemented", this.status = 501, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
214
+ super(e), this.name = "NotImplemented", this.status = 501, this.statusText = e, this.cause = t, this.onDebug();
212
215
  }
213
216
  toResponse() {
214
217
  let e = {
@@ -227,7 +230,7 @@ var f = class {
227
230
  }
228
231
  }, y = class extends f {
229
232
  constructor(e, t) {
230
- super(), this.name = "ServerError", this.status = 500, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
233
+ super(e), this.name = "ServerError", this.status = 500, this.statusText = e, this.cause = t, this.onDebug();
231
234
  }
232
235
  toResponse() {
233
236
  let e = {
@@ -246,7 +249,7 @@ var f = class {
246
249
  }
247
250
  }, b = class extends f {
248
251
  constructor(e, t) {
249
- super(), this.name = "Unauthorized", this.status = 401, this.statusText = e, this.debugColor = "yellow", this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
252
+ super(e), this.name = "Unauthorized", this.status = 401, this.statusText = e, this.debugColor = "yellow", this.cause = t, this.onDebug();
250
253
  }
251
254
  toResponse() {
252
255
  let e = {
@@ -301,7 +304,7 @@ function S(e) {
301
304
  }
302
305
  var C = class extends f {
303
306
  constructor(e) {
304
- super(), this.name = "UnprocessableEntity", this.status = 422, this.statusText = e.message || "Unprocessable entity", this.debugColor = "yellow", this.exposeCauseInProduction = !0, this.cause = {
307
+ super(e.message || "Unprocessable entity"), this.name = "UnprocessableEntity", this.status = 422, this.statusText = e.message || "Unprocessable entity", this.debugColor = "yellow", this.exposeCauseInProduction = !0, this.cause = {
305
308
  data: S(e.data),
306
309
  fieldErrors: e.fieldErrors,
307
310
  fields: S(e.fields)
@@ -466,7 +469,7 @@ var C = class extends f {
466
469
  };
467
470
  return Response.json(this.body, e);
468
471
  }
469
- }, A = class e {
472
+ }, ee = class e {
470
473
  static mapHeaders(e) {
471
474
  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), {}) : {};
472
475
  }
@@ -493,31 +496,44 @@ var C = class extends f {
493
496
  responseBody: t.responseBody || null
494
497
  };
495
498
  }
496
- }, j = class e {
499
+ }, A = class e {
497
500
  static config;
498
501
  static isSecureEndpoint(e) {
499
502
  return e.protocol === "https:" ? !0 : e.hostname === "localhost" || e.hostname === "127.0.0.1";
500
503
  }
501
504
  static setConfig(t) {
502
- if (e.config) return;
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({
505
+ if (e.config) {
506
+ d({
507
+ name: "LogServiceError",
508
+ scheme: "yellow",
509
+ debugs: ["LogService.setConfig() was already called and is a singleton — this call was ignored. Call setConfig() once at application boot, never inside a request handler (a per-request value would only ever apply to the first request that reaches it)."]
510
+ });
511
+ return;
512
+ }
513
+ let { trafficSourceId: n, logBaseApiUrl: r } = t, i = t.serviceToken ?? t.userToken;
514
+ if (t.userToken !== void 0 && t.serviceToken === void 0 && d({
515
+ name: "LogServiceError",
516
+ scheme: "yellow",
517
+ debugs: ["LogService.setConfig({ userToken }) is deprecated — use \"serviceToken\" instead. It must be a static, application-level credential, not a per-user/session value."]
518
+ }), !i) throw Error("LogService.setConfig() requires a serviceToken (or the deprecated userToken alias).");
519
+ let a = null;
520
+ if (r) try {
521
+ let t = new URL(r);
522
+ e.isSecureEndpoint(t) ? a = `${r}/ingest-log` : d({
507
523
  name: "LogServiceError",
508
524
  scheme: "red",
509
- debugs: [`Insecure logBaseApiUrl "${i}" rejected: use https://, or http:// only for localhost/127.0.0.1. Remote logging disabled.`]
525
+ debugs: [`Insecure logBaseApiUrl "${r}" rejected: use https://, or http:// only for localhost/127.0.0.1. Remote logging disabled.`]
510
526
  });
511
527
  } catch {
512
528
  d({
513
529
  name: "LogServiceError",
514
530
  scheme: "red",
515
- debugs: [`Invalid logBaseApiUrl "${i}". Remote logging disabled.`]
531
+ debugs: [`Invalid logBaseApiUrl "${r}". Remote logging disabled.`]
516
532
  });
517
533
  }
518
534
  e.config = {
519
535
  trafficSourceId: n,
520
- userToken: r,
536
+ serviceToken: i,
521
537
  apiUrl: a
522
538
  };
523
539
  }
@@ -530,10 +546,10 @@ var C = class extends f {
530
546
  };
531
547
  //#endregion
532
548
  //#region src/http/api/_logRequest.ts
533
- async function M(e) {
534
- let n = j.getConfig();
549
+ async function j(e) {
550
+ let n = A.getConfig();
535
551
  if (!n) return;
536
- let { userToken: i, apiUrl: a, trafficSourceId: o } = n;
552
+ let { serviceToken: i, apiUrl: a, trafficSourceId: o } = n;
537
553
  if (!a) return;
538
554
  let { elapsedTime: s, method: c, queryParams: l, requestBody: u, requestHeaders: f, responseBody: p, responseHeaders: m, status: h, rawUrl: g } = e;
539
555
  if (process.env.NODE_ENV !== "development") try {
@@ -584,6 +600,7 @@ async function M(e) {
584
600
  }
585
601
  //#endregion
586
602
  //#region src/http/api/_makeRequest.ts
603
+ var M = 1e4;
587
604
  async function N(e) {
588
605
  let t = e.url;
589
606
  e.urlParams && Object.entries(e.urlParams).forEach(([e, n]) => {
@@ -595,47 +612,64 @@ async function N(e) {
595
612
  DELETE: "Resource deleted successfully",
596
613
  PATCH: "Resource patched successfully",
597
614
  GET: "Request successful"
598
- };
615
+ }, r = e.timeoutMs ?? M, i = new AbortController(), a = setTimeout(() => i.abort(), r);
599
616
  try {
600
- let r = performance.now(), i = {
617
+ let r = performance.now(), o = {
601
618
  ...e.headers,
602
619
  "Content-Type": "application/json"
603
- }, a = await fetch(t, {
604
- headers: i,
605
- method: e.method,
606
- body: e.body ? JSON.stringify(e.body) : void 0
607
- }), o = performance.now() - r, s = a.status, c = null;
620
+ }, s;
621
+ try {
622
+ s = await fetch(t, {
623
+ headers: o,
624
+ method: e.method,
625
+ body: e.body ? JSON.stringify(e.body) : void 0,
626
+ signal: i.signal
627
+ });
628
+ } finally {
629
+ clearTimeout(a);
630
+ }
631
+ let c = performance.now() - r, l = s.status, u = null;
608
632
  try {
609
- c = await a.json();
633
+ u = await s.json();
610
634
  } catch {
611
- c = null;
635
+ u = null;
612
636
  }
613
- return M(A.handle({
614
- elapsedTime: o,
637
+ return j(ee.handle({
638
+ elapsedTime: c,
615
639
  method: e.method,
616
640
  queryParams: new URL(t).searchParams,
617
- requestHeaders: i,
641
+ requestHeaders: o,
618
642
  requestBody: e.body,
619
- responseBody: c,
620
- responseHeaders: a.headers,
621
- status: s,
643
+ responseBody: u,
644
+ responseHeaders: s.headers,
645
+ status: l,
622
646
  rawUrl: e.url,
623
647
  urlParams: e.urlParams
624
- })), a.ok ? {
648
+ })), s.ok ? {
625
649
  success: !0,
626
- status: s,
627
- message: c?.message || n[e.method],
628
- response: c,
650
+ status: l,
651
+ message: u?.message || n[e.method],
652
+ response: u,
629
653
  cause: null
630
654
  } : {
631
655
  success: !1,
632
- status: s,
633
- message: c?.message || a.statusText || "Request failed",
634
- response: c,
656
+ status: l,
657
+ message: u?.message || s.statusText || "Request failed",
658
+ response: u,
635
659
  cause: null
636
660
  };
637
661
  } catch (e) {
638
- return d({
662
+ return clearTimeout(a), e instanceof DOMException && e.name === "AbortError" || e instanceof Error && e.name === "AbortError" ? (d({
663
+ debugs: [`Request timed out after ${r}ms`],
664
+ name: "MakeRequestError",
665
+ scheme: "red"
666
+ }), {
667
+ success: !1,
668
+ status: 504,
669
+ message: `Request timed out after ${r}ms`,
670
+ response: null,
671
+ cause: e instanceof Error ? e : Error(String(e))
672
+ }) : (d({
639
673
  debugs: [`Network error or request failed: ${e}`],
640
674
  name: "MakeRequestError",
641
675
  scheme: "red"
@@ -645,72 +679,78 @@ async function N(e) {
645
679
  message: "Network error or request failed",
646
680
  response: null,
647
681
  cause: e instanceof Error ? e.message : String(e)
648
- };
682
+ });
649
683
  }
650
684
  }
651
685
  //#endregion
652
686
  //#region src/http/api/_deleteRequest.ts
653
- async function P(e) {
687
+ async function te(e) {
654
688
  return N({
655
689
  method: "DELETE",
656
690
  url: e.url,
657
691
  urlParams: e.urlParams,
658
692
  headers: e.headers,
659
- body: e.body
693
+ body: e.body,
694
+ timeoutMs: e.timeoutMs
660
695
  });
661
696
  }
662
697
  //#endregion
663
698
  //#region src/http/api/_getRequest.ts
664
- async function ee(e) {
699
+ async function ne(e) {
665
700
  return N({
666
701
  method: "GET",
667
702
  url: e.url,
668
703
  urlParams: e.urlParams,
669
- headers: e.headers
704
+ headers: e.headers,
705
+ timeoutMs: e.timeoutMs
670
706
  });
671
707
  }
672
708
  //#endregion
673
709
  //#region src/http/api/_patchRequest.ts
674
- async function te(e) {
710
+ async function re(e) {
675
711
  return N({
676
712
  method: "PATCH",
677
713
  url: e.url,
678
714
  urlParams: e.urlParams,
679
715
  headers: e.headers,
680
- body: e.body
716
+ body: e.body,
717
+ timeoutMs: e.timeoutMs
681
718
  });
682
719
  }
683
720
  //#endregion
684
721
  //#region src/http/api/_postRequest.ts
685
- async function F(e) {
722
+ async function P(e) {
686
723
  return N({
687
724
  method: "POST",
688
725
  url: e.url,
689
726
  urlParams: e.urlParams,
690
727
  headers: e.headers,
691
- body: e.body
728
+ body: e.body,
729
+ timeoutMs: e.timeoutMs
692
730
  });
693
731
  }
694
732
  //#endregion
695
733
  //#region src/http/api/_putRequest.ts
696
- async function I(e) {
734
+ async function F(e) {
697
735
  return N({
698
736
  method: "PUT",
699
737
  url: e.url,
700
738
  urlParams: e.urlParams,
701
739
  headers: e.headers,
702
- body: e.body
740
+ body: e.body,
741
+ timeoutMs: e.timeoutMs
703
742
  });
704
743
  }
705
744
  //#endregion
706
745
  //#region src/services/apiService.ts
707
- var L = class e {
746
+ var I = class e {
708
747
  baseUrl;
709
748
  baseHeaders;
710
749
  baseToken;
711
750
  enableDebug;
751
+ timeoutMs;
712
752
  constructor(e) {
713
- this.baseUrl = e.baseUrl, this.baseHeaders = e.baseHeaders || void 0, this.baseToken = e.baseToken || void 0, this.enableDebug = e.enableDebug || !1;
753
+ this.baseUrl = e.baseUrl, this.baseHeaders = e.baseHeaders || void 0, this.baseToken = e.baseToken || void 0, this.enableDebug = e.enableDebug || !1, this.timeoutMs = e.timeoutMs;
714
754
  }
715
755
  static toPlainHeaders(e) {
716
756
  return e instanceof Headers ? Object.fromEntries(e.entries()) : Object.fromEntries(new Headers(e).entries());
@@ -746,10 +786,11 @@ var L = class e {
746
786
  }), n;
747
787
  }
748
788
  async get(e, t) {
749
- let n = this.generateHeaders(t?.headers || {}, t?.token), r = await ee({
789
+ let n = this.generateHeaders(t?.headers || {}, t?.token), r = await ne({
750
790
  url: this.baseUrl + e,
751
791
  urlParams: t?.urlParams || {},
752
- headers: n
792
+ headers: n,
793
+ timeoutMs: t?.timeoutMs ?? this.timeoutMs
753
794
  });
754
795
  return this.onDebug(e, "get", {
755
796
  headers: n,
@@ -758,11 +799,12 @@ var L = class e {
758
799
  }), r;
759
800
  }
760
801
  async post(e, t) {
761
- let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await F({
802
+ let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await P({
762
803
  url: this.baseUrl + e,
763
804
  urlParams: t?.urlParams || {},
764
805
  headers: n,
765
- body: r
806
+ body: r,
807
+ timeoutMs: t?.timeoutMs ?? this.timeoutMs
766
808
  });
767
809
  return this.onDebug(e, "post", {
768
810
  headers: n,
@@ -772,11 +814,12 @@ var L = class e {
772
814
  }), i;
773
815
  }
774
816
  async put(e, t) {
775
- let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await I({
817
+ let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await F({
776
818
  url: this.baseUrl + e,
777
819
  urlParams: t?.urlParams || {},
778
820
  headers: n,
779
- body: r
821
+ body: r,
822
+ timeoutMs: t?.timeoutMs ?? this.timeoutMs
780
823
  });
781
824
  return this.onDebug(e, "put", {
782
825
  headers: n,
@@ -786,11 +829,12 @@ var L = class e {
786
829
  }), i;
787
830
  }
788
831
  async patch(e, t) {
789
- let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await te({
832
+ let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await re({
790
833
  url: this.baseUrl + e,
791
834
  urlParams: t?.urlParams || {},
792
835
  headers: n,
793
- body: r
836
+ body: r,
837
+ timeoutMs: t?.timeoutMs ?? this.timeoutMs
794
838
  });
795
839
  return this.onDebug(e, "patch", {
796
840
  headers: n,
@@ -800,11 +844,12 @@ var L = class e {
800
844
  }), i;
801
845
  }
802
846
  async delete(e, t) {
803
- let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await P({
847
+ let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await te({
804
848
  url: this.baseUrl + e,
805
849
  urlParams: t?.urlParams || {},
806
850
  headers: n,
807
- body: r
851
+ body: r,
852
+ timeoutMs: t?.timeoutMs ?? this.timeoutMs
808
853
  });
809
854
  return this.onDebug(e, "delete", {
810
855
  headers: n,
@@ -813,9 +858,9 @@ var L = class e {
813
858
  status: i.status
814
859
  }), i;
815
860
  }
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"));
861
+ }, L = 5 * 1024 * 1024;
862
+ async function R(e, t) {
863
+ let n, r = t?.maxBodySizeBytes ?? L, i = Number(e.headers.get("content-length"));
819
864
  if (Number.isFinite(i) && i > r) throw new m("Request body exceeds the maximum allowed size");
820
865
  let a = await e.arrayBuffer();
821
866
  if (a.byteLength > r) throw new m("Request body exceeds the maximum allowed size");
@@ -836,12 +881,12 @@ async function z(e, t) {
836
881
  }
837
882
  //#endregion
838
883
  //#region src/utilities/decodeRequestErrorMessage.ts
839
- function B(e, t) {
884
+ function z(e, t) {
840
885
  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";
841
886
  }
842
887
  //#endregion
843
888
  //#region src/utilities/errorHandler.ts
844
- function V(e) {
889
+ function B(e) {
845
890
  switch (!0) {
846
891
  case e instanceof Response: return e;
847
892
  case e instanceof E: return e.toResponse();
@@ -865,7 +910,7 @@ function V(e) {
865
910
  }
866
911
  //#endregion
867
912
  //#region src/utilities/formAsyncParse.ts
868
- async function H([e, t]) {
913
+ async function V([e, t]) {
869
914
  let n = await t.safeParseAsync(e);
870
915
  return n.success === !1 ? {
871
916
  success: !1,
@@ -878,7 +923,7 @@ async function H([e, t]) {
878
923
  }
879
924
  //#endregion
880
925
  //#region src/utilities/formParse.ts
881
- function U([e, t]) {
926
+ function H([e, t]) {
882
927
  let n = t.safeParse(e);
883
928
  return n.success === !1 ? {
884
929
  success: !1,
@@ -891,7 +936,7 @@ function U([e, t]) {
891
936
  }
892
937
  //#endregion
893
938
  //#region src/utilities/getScopedParams.ts
894
- function W(e, t = "") {
939
+ function U(e, t = "") {
895
940
  let n = new URL(e.url);
896
941
  if (t === "") return n.searchParams;
897
942
  let r = Array.from(n.searchParams.entries()).filter(([e]) => e.startsWith(`${t}:`)).map(([e, n]) => [e.replace(`${t}:`, ""), n]);
@@ -899,10 +944,10 @@ function W(e, t = "") {
899
944
  }
900
945
  //#endregion
901
946
  //#region src/utilities/schemaValidator.ts
902
- function G(e) {
947
+ function W(e) {
903
948
  return ["Error validating:", ...e.issues.map(({ path: e, message: t }) => `-> ${e.join(".")}: ${t}`)].join("\n");
904
949
  }
905
- var K = class {
950
+ var G = class {
906
951
  schema;
907
952
  constructor(e) {
908
953
  this.schema = e;
@@ -917,11 +962,11 @@ var K = class {
917
962
  try {
918
963
  return this.schema.parse(e);
919
964
  } catch (e) {
920
- throw new y(G(e));
965
+ throw new y(W(e));
921
966
  }
922
967
  }
923
968
  formValidate(e, t) {
924
- let n = U([e, this.schema]);
969
+ let n = H([e, this.schema]);
925
970
  if ("fieldErrors" in n) {
926
971
  let e = Object.keys(n.fieldErrors)[0];
927
972
  throw new C({
@@ -934,7 +979,7 @@ var K = class {
934
979
  return n.data;
935
980
  }
936
981
  async formAsyncValidate(e, t) {
937
- let n = await H([e, this.schema]);
982
+ let n = await V([e, this.schema]);
938
983
  if ("fieldErrors" in n) {
939
984
  let e = Object.keys(n.fieldErrors)[0];
940
985
  throw new C({
@@ -946,37 +991,49 @@ var K = class {
946
991
  }
947
992
  return n.data;
948
993
  }
994
+ }, K = {
995
+ "X-Content-Type-Options": "nosniff",
996
+ "X-Frame-Options": "DENY",
997
+ "Referrer-Policy": "strict-origin-when-cross-origin"
949
998
  };
999
+ function q(e, t) {
1000
+ let n = {
1001
+ ...K,
1002
+ ...t
1003
+ };
1004
+ for (let [t, r] of Object.entries(n)) r === null ? e.headers.delete(t) : e.headers.set(t, r);
1005
+ return e;
1006
+ }
950
1007
  //#endregion
951
1008
  //#region src/validations/validateCep.ts
952
- function q(e) {
1009
+ function J(e) {
953
1010
  if (!(/^\d{5}-\d{3}$/.test(e) || /^\d{8}$/.test(e))) return !1;
954
1011
  let t = i(e), n = /^\d{8}$/.test(t);
955
1012
  return t.length === 8 && n;
956
1013
  }
957
1014
  //#endregion
958
1015
  //#region src/validations/validateCnpj.ts
959
- function J(e) {
1016
+ function Y(e) {
960
1017
  return e.length !== 14;
961
1018
  }
962
- function Y(e) {
1019
+ function X(e) {
963
1020
  let [t] = e;
964
1021
  return [...e].every((e) => e === t);
965
1022
  }
966
- function X(e, t) {
1023
+ function Z(e, t) {
967
1024
  let n = 0;
968
1025
  for (let r = 0; r < t.length; r++) n += parseInt(e[r], 10) * t[r];
969
1026
  let r = n % 11;
970
1027
  return r < 2 ? 0 : 11 - r;
971
1028
  }
972
- function ne(e) {
1029
+ function ie(e) {
973
1030
  return e.slice(12);
974
1031
  }
975
- function Z(e) {
1032
+ function ae(e) {
976
1033
  if (!e || e.length > 18 || e.length < 14 || /\s/.test(e)) return !1;
977
1034
  let t = i(e);
978
- if (J(t) || Y(t)) return !1;
979
- let n = t.slice(0, 12), r = X(n, [
1035
+ if (Y(t) || X(t)) return !1;
1036
+ let n = t.slice(0, 12), r = Z(n, [
980
1037
  5,
981
1038
  4,
982
1039
  3,
@@ -989,7 +1046,7 @@ function Z(e) {
989
1046
  4,
990
1047
  3,
991
1048
  2
992
- ]), a = X(n + r, [
1049
+ ]), a = Z(n + r, [
993
1050
  6,
994
1051
  5,
995
1052
  4,
@@ -1004,14 +1061,14 @@ function Z(e) {
1004
1061
  3,
1005
1062
  2
1006
1063
  ]);
1007
- return ne(t) === `${r}${a}`;
1064
+ return ie(t) === `${r}${a}`;
1008
1065
  }
1009
1066
  //#endregion
1010
1067
  //#region src/validations/validateCpf.ts
1011
- function re(e) {
1068
+ function oe(e) {
1012
1069
  return e.length !== 11;
1013
1070
  }
1014
- function ie(e) {
1071
+ function se(e) {
1015
1072
  let [t] = e;
1016
1073
  return [...e].every((e) => e === t);
1017
1074
  }
@@ -1021,75 +1078,65 @@ function Q(e, t) {
1021
1078
  let r = n % 11;
1022
1079
  return r < 2 ? 0 : 11 - r;
1023
1080
  }
1024
- function ae(e) {
1081
+ function ce(e) {
1025
1082
  return e.slice(9);
1026
1083
  }
1027
- function oe(e) {
1084
+ function le(e) {
1028
1085
  if (!e || e.length > 14 || e.length < 11 || /\s/.test(e)) return !1;
1029
1086
  let t = i(e);
1030
- if (re(t) || ie(t)) return !1;
1087
+ if (oe(t) || se(t)) return !1;
1031
1088
  let n = Q(t, 10), r = Q(t, 11);
1032
- return ae(t) === `${n}${r}`;
1089
+ return ce(t) === `${n}${r}`;
1033
1090
  }
1034
1091
  //#endregion
1035
1092
  //#region src/validations/validateDate.ts
1036
- function se(t, n) {
1093
+ function ue(t, n) {
1037
1094
  let r = n?.inputFormat || "brazilianDate", i = n?.minYear || 1900, a = n?.maxYear || 3e3, o = new e();
1038
1095
  o.validateInputFormat(r);
1039
- let s, c, l, u = t.split(/[-/]/).map(Number);
1040
- if (u.length !== 3) return !1;
1096
+ let s = t.split(/[-/]/).map(Number);
1097
+ if (s.length !== 3) return !1;
1041
1098
  try {
1042
- switch (r) {
1043
- case "brazilianDate":
1044
- [s, c, l] = u, o.validateDateParts(l, c, s);
1045
- break;
1046
- case "isoDate":
1047
- [c, s, l] = u, o.validateDateParts(l, c, s);
1048
- break;
1049
- case "timestamp":
1050
- [l, c, s] = u, o.validateDateParts(l, c, s);
1051
- break;
1052
- }
1053
- return !(l < i || l > a);
1099
+ let { year: e } = o.parseDateParts(s, r);
1100
+ return !(e < i || e > a);
1054
1101
  } catch {
1055
1102
  return !1;
1056
1103
  }
1057
1104
  }
1058
1105
  //#endregion
1059
1106
  //#region src/validations/validateEmail.ts
1060
- function ce(e) {
1107
+ function de(e) {
1061
1108
  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);
1062
1109
  }
1063
- function le(e) {
1110
+ function fe(e) {
1064
1111
  return !(e.length === 0 || e.length > 64 || e.startsWith(".") || e.endsWith(".") || e.includes("..") || !/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/.test(e));
1065
1112
  }
1066
- function ue(e) {
1113
+ function pe(e) {
1067
1114
  return !(e.length === 0 || e.length > 63 || e.startsWith("-") || e.endsWith("-") || !/^[a-zA-Z0-9-]+$/.test(e));
1068
1115
  }
1069
- function de(e) {
1116
+ function $(e) {
1070
1117
  if (e.length === 0 || e.length > 253 || e.startsWith(".") || e.endsWith(".") || e.startsWith("-") || e.endsWith("-")) return !1;
1071
1118
  let t = e.split(".");
1072
1119
  if (t.length < 2) return !1;
1073
- for (let e of t) if (!ue(e)) return !1;
1120
+ for (let e of t) if (!pe(e)) return !1;
1074
1121
  let n = t[t.length - 1];
1075
1122
  return !(n.length < 2 || !/^[a-zA-Z]+$/.test(n));
1076
1123
  }
1077
- function fe(e) {
1124
+ function me(e) {
1078
1125
  let t = e.split("@");
1079
1126
  if (t.length !== 2) return !1;
1080
1127
  let [n, r] = t;
1081
- return !(!le(n) || !de(r));
1128
+ return !(!fe(n) || !$(r));
1082
1129
  }
1083
- function pe(e) {
1130
+ function he(e) {
1084
1131
  let t = e.split("@");
1085
1132
  return t.length === 2 ? t[1].toLowerCase() : null;
1086
1133
  }
1087
- var $ = [
1134
+ var ge = [
1088
1135
  "MX",
1089
1136
  "A",
1090
1137
  "AAAA"
1091
- ], me = 5e3;
1092
- async function he(e, t, n) {
1138
+ ], _e = 5e3;
1139
+ async function ve(e, t, n) {
1093
1140
  return new Promise((r) => {
1094
1141
  let i = !1, a = setTimeout(() => {
1095
1142
  i || (i = !0, r(!1));
@@ -1101,20 +1148,20 @@ async function he(e, t, n) {
1101
1148
  });
1102
1149
  });
1103
1150
  }
1104
- async function ge(e, t) {
1105
- for (let n of $) if (await he(e, n, t)) return !0;
1151
+ async function ye(e, t) {
1152
+ for (let n of ge) if (await ve(e, n, t)) return !0;
1106
1153
  return !1;
1107
1154
  }
1108
- async function _e(e, t) {
1155
+ async function be(e, t) {
1109
1156
  if (!e || typeof e != "string") return !1;
1110
1157
  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;
1158
+ if (!de(n) || !me(n)) return !1;
1159
+ let r = he(n);
1160
+ return r ? await ye(r, t?.dnsTimeoutMs ?? _e) : !1;
1114
1161
  }
1115
1162
  //#endregion
1116
1163
  //#region src/validations/validatePassword.ts
1117
- function ve(e) {
1164
+ function xe(e) {
1118
1165
  return e ? [
1119
1166
  e.length >= 8,
1120
1167
  /[A-Z]/.test(e),
@@ -1125,19 +1172,19 @@ function ve(e) {
1125
1172
  }
1126
1173
  //#endregion
1127
1174
  //#region src/validations/validatePhone.ts
1128
- function ye(e) {
1175
+ function Se(e) {
1129
1176
  if (!c(e)) return !1;
1130
1177
  let t = l(e)?.country;
1131
1178
  return !(!t || !s.find((e) => e.iso === t));
1132
1179
  }
1133
1180
  //#endregion
1134
1181
  //#region src/validations/validateRg.ts
1135
- function be(e) {
1182
+ function Ce(e) {
1136
1183
  if (!e || !/^[0-9a-zA-Z.-]+$/.test(e)) return !1;
1137
1184
  let t = e.replace(/[^a-zA-Z0-9]/g, "");
1138
1185
  return t.length < 7 || t.length > 9 ? !1 : /^[0-9]{7,8}[0-9Xx]?$/.test(t);
1139
1186
  }
1140
1187
  //#endregion
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 };
1188
+ export { I as ApiService, p as BadGateway, m as BadRequest, h as Conflict, T as Created, u as DebugService, g as Forbidden, E as Found, A as LogService, D as NoContent, _ as NotFound, v as NotImplemented, G as SchemaValidator, y as ServerError, O as Success, b as Unauthorized, C as UnprocessableEntity, k as Updated, R as decodeRequestBody, z as decodeRequestErrorMessage, B as errorHandler, d as flushDebugLogs, V as formAsyncParse, H as formParse, U as getScopedParams, J as validateCep, ae as validateCnpj, le as validateCpf, ue as validateDate, be as validateEmail, xe as validatePassword, Se as validatePhone, Ce as validateRg, q as withSecurityHeaders };
1142
1189
 
1143
1190
  //# sourceMappingURL=index.js.map