@arkyn/server 3.0.1-beta.77 → 3.0.1-beta.78

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.
@@ -1 +1 @@
1
- {"version":3,"file":"arkynLogRequest.d.ts","sourceRoot":"","sources":["../../src/api/arkynLogRequest.ts"],"names":[],"mappings":"AAGA,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,iBAAe,eAAe,CAAC,MAAM,EAAE,WAAW,iBA8DjD;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
1
+ {"version":3,"file":"arkynLogRequest.d.ts","sourceRoot":"","sources":["../../src/api/arkynLogRequest.ts"],"names":[],"mappings":"AAGA,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,iBAAe,eAAe,CAAC,MAAM,EAAE,WAAW,iBAyDjD;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -44,7 +44,7 @@ async function arkynLogRequest(config) {
44
44
  const arkynService = ArkynLogService.getArkynConfig();
45
45
  if (!arkynService)
46
46
  return;
47
- const { arkynUserToken, arkynApiUrl } = arkynService;
47
+ const { userToken, apiUrl, trafficSourceId } = arkynService;
48
48
  const { elapsedTime, method, queryParams, requestBody, requestHeaders, responseBody, responseHeaders, status, token, rawUrl, } = config;
49
49
  if (process.env.NODE_ENV === "development")
50
50
  return;
@@ -56,6 +56,7 @@ async function arkynLogRequest(config) {
56
56
  const body = JSON.stringify({
57
57
  domainUrl: url.protocol + "//" + url.host,
58
58
  pathnameUrl: url.pathname,
59
+ trafficSourceId: trafficSourceId,
59
60
  status,
60
61
  protocol,
61
62
  method,
@@ -67,12 +68,12 @@ async function arkynLogRequest(config) {
67
68
  responseHeaders,
68
69
  responseBody,
69
70
  });
70
- await fetch(arkynApiUrl.replace(":trafficSourceId", arkynService.arkynTrafficSourceId), {
71
+ await fetch(apiUrl, {
71
72
  method: "POST",
72
73
  body,
73
74
  headers: {
74
75
  "Content-Type": "application/json",
75
- Authorization: `Bearer ${arkynUserToken}`,
76
+ Authorization: `Bearer ${userToken}`,
76
77
  },
77
78
  });
78
79
  }
package/dist/bundle.js CHANGED
@@ -1,10 +1,10 @@
1
- var U = Object.defineProperty;
2
- var C = (e, t, s) => t in e ? U(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
- var o = (e, t, s) => C(e, typeof t != "symbol" ? t + "" : t, s);
1
+ var w = Object.defineProperty;
2
+ var A = (e, t, s) => t in e ? w(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
+ var o = (e, t, s) => A(e, typeof t != "symbol" ? t + "" : t, s);
4
4
  import "zod";
5
5
  import { removeNonNumeric as N } from "@arkyn/shared";
6
- import v from "node:dns";
7
- import { countries as j } from "@arkyn/templates";
6
+ import J from "node:dns";
7
+ import { countries as U } from "@arkyn/templates";
8
8
  function g(e) {
9
9
  var s;
10
10
  if (process.env.NODE_ENV === "development" || ((s = process.env) == null ? void 0 : s.SHOW_ERRORS_IN_CONSOLE) === "true") {
@@ -22,8 +22,8 @@ function g(e) {
22
22
  }), console.log(c);
23
23
  }
24
24
  }
25
- const k = {};
26
- class $ {
25
+ const L = {};
26
+ class I {
27
27
  /**
28
28
  * Sets the file name to be ignored during stack trace analysis.
29
29
  *
@@ -62,10 +62,10 @@ class $ {
62
62
  * The name of the file to ignore when analyzing the stack trace.
63
63
  * When set, the `getCaller` function will skip stack frames containing this file name.
64
64
  */
65
- o($, "ignoreFiles", []);
65
+ o(I, "ignoreFiles", []);
66
66
  function E() {
67
67
  const e = process.cwd(), n = (new Error().stack || "").split(`
68
- `).map((u) => u.trim()), r = $.ignoreFiles;
68
+ `).map((u) => u.trim()), r = I.ignoreFiles;
69
69
  let a = 2;
70
70
  for (; a < n.length && (n[a].includes("node:internal") || n[a].includes("/node_modules/")); )
71
71
  a++;
@@ -92,18 +92,18 @@ function E() {
92
92
  i.lastIndexOf(")")
93
93
  )), i = i.split(":").slice(0, -2).join(":");
94
94
  try {
95
- i = k.relative(e, i);
95
+ i = L.relative(e, i);
96
96
  } catch {
97
97
  }
98
98
  return { functionName: h, callerInfo: i };
99
99
  }
100
- class y {
100
+ class p {
101
101
  onDebug(t) {
102
102
  const { name: s, body: n, cause: r, message: a } = t, c = [], { callerInfo: h, functionName: i } = E();
103
103
  c.push(`${s} initialized`), c.push(`Caller Function: ${i}`), c.push(`Caller Location: ${h}`), a && c.push(`Message: ${a}`), n && c.push(`Body: ${JSON.stringify(n, null, 2)}`), r && c.push(`Cause: ${JSON.stringify(r, null, 2)}`), g({ scheme: "red", name: "ARKYN-BAD-RESPONSE-DEBUG", debugs: c });
104
104
  }
105
105
  }
106
- class J extends y {
106
+ class B extends p {
107
107
  /**
108
108
  * Creates an instance of the `BadGateway` class.
109
109
  *
@@ -151,7 +151,7 @@ class J extends y {
151
151
  return Response.json(this.body, s);
152
152
  }
153
153
  }
154
- class b extends y {
154
+ class b extends p {
155
155
  /**
156
156
  * Creates an instance of the `BadRequest` class.
157
157
  *
@@ -199,7 +199,7 @@ class b extends y {
199
199
  return Response.json(this.body, s);
200
200
  }
201
201
  }
202
- class L extends y {
202
+ class k extends p {
203
203
  /**
204
204
  * Creates an instance of the `Conflict` class.
205
205
  *
@@ -247,7 +247,7 @@ class L extends y {
247
247
  return Response.json(this.body, s);
248
248
  }
249
249
  }
250
- class B extends y {
250
+ class H extends p {
251
251
  /**
252
252
  * Creates an instance of the `Forbidden` class.
253
253
  *
@@ -295,7 +295,7 @@ class B extends y {
295
295
  return Response.json(this.body, s);
296
296
  }
297
297
  }
298
- class H extends y {
298
+ class q extends p {
299
299
  /**
300
300
  * Creates an instance of the `NotFound` class.
301
301
  *
@@ -343,7 +343,7 @@ class H extends y {
343
343
  return Response.json(this.body, s);
344
344
  }
345
345
  }
346
- class q extends y {
346
+ class F extends p {
347
347
  /**
348
348
  * Creates an instance of the `NotImplemented` class.
349
349
  *
@@ -391,7 +391,7 @@ class q extends y {
391
391
  return Response.json(this.body, s);
392
392
  }
393
393
  }
394
- class x extends y {
394
+ class x extends p {
395
395
  /**
396
396
  * Creates an instance of the `ServerError` class.
397
397
  *
@@ -439,7 +439,7 @@ class x extends y {
439
439
  return Response.json(this.body, s);
440
440
  }
441
441
  }
442
- class F extends y {
442
+ class P extends p {
443
443
  /**
444
444
  * Creates an instance of the `Unauthorized` class.
445
445
  *
@@ -487,7 +487,7 @@ class F extends y {
487
487
  return Response.json(this.body, s);
488
488
  }
489
489
  }
490
- class R extends y {
490
+ class R extends p {
491
491
  /**
492
492
  * Creates an instance of the `UnprocessableEntity` class.
493
493
  *
@@ -571,7 +571,7 @@ class m {
571
571
  });
572
572
  }
573
573
  }
574
- class P extends m {
574
+ class Y extends m {
575
575
  /**
576
576
  * Creates an instance of the `Created` class.
577
577
  *
@@ -615,7 +615,7 @@ class P extends m {
615
615
  return Response.json(this.body, s);
616
616
  }
617
617
  }
618
- class Y extends m {
618
+ class z extends m {
619
619
  /**
620
620
  * Creates an instance of the `Found` class.
621
621
  *
@@ -662,7 +662,7 @@ class Y extends m {
662
662
  return Response.json(this.body, s);
663
663
  }
664
664
  }
665
- class z extends m {
665
+ class M extends m {
666
666
  /**
667
667
  * Creates an instance of the `NoContent` class.
668
668
  *
@@ -690,7 +690,7 @@ class z extends m {
690
690
  return new Response(null, s);
691
691
  }
692
692
  }
693
- class M extends m {
693
+ class _ extends m {
694
694
  /**
695
695
  * Creates an instance of the `Success` class.
696
696
  *
@@ -734,7 +734,7 @@ class M extends m {
734
734
  return Response.json(this.body, s);
735
735
  }
736
736
  }
737
- class _ extends m {
737
+ class V extends m {
738
738
  /**
739
739
  * Creates an instance of the `Updated` class.
740
740
  *
@@ -778,7 +778,7 @@ class _ extends m {
778
778
  return Response.json(this.body, s);
779
779
  }
780
780
  }
781
- class V {
781
+ class G {
782
782
  static mapHeaders(t) {
783
783
  return t instanceof Headers ? Object.fromEntries(t.entries()) : typeof t == "object" ? Object.entries(t).reduce((s, [n, r]) => (typeof r == "string" ? s[n] = r : Array.isArray(r) ? s[n] = r.join(", ") : s[n] = JSON.stringify(r), s), {}) : {};
784
784
  }
@@ -803,7 +803,7 @@ class V {
803
803
  };
804
804
  }
805
805
  }
806
- class I {
806
+ class C {
807
807
  /**
808
808
  * Sets the configuration for the arkyn. This method initializes the arkyn configuration
809
809
  * with the provided `arkynConfig` values. If the configuration has already been set,
@@ -817,11 +817,11 @@ class I {
817
817
  */
818
818
  static setArkynConfig(t) {
819
819
  if (this.arkynConfig) return;
820
- let n = t.arkynLogBaseApiUrl || "https://logs-arkyn-flow-logs.vw6wo7.easypanel.host";
821
- n = n + "/http-traffic-records/:trafficSourceId", this.arkynConfig = {
822
- arkynTrafficSourceId: t.arkynTrafficSourceId,
823
- arkynUserToken: t.arkynUserToken,
824
- arkynApiUrl: n
820
+ const { trafficSourceId: s, userToken: n, logBaseApiUrl: r } = t;
821
+ this.arkynConfig = {
822
+ trafficSourceId: s,
823
+ userToken: n,
824
+ apiUrl: r || "http://95.216.190.158:8080/ingest-log"
825
825
  };
826
826
  }
827
827
  /**
@@ -841,58 +841,53 @@ class I {
841
841
  this.arkynConfig = void 0;
842
842
  }
843
843
  }
844
- o(I, "arkynConfig");
845
- async function G(e) {
846
- const t = I.getArkynConfig();
844
+ o(C, "arkynConfig");
845
+ async function Z(e) {
846
+ const t = C.getArkynConfig();
847
847
  if (!t) return;
848
- const { arkynUserToken: s, arkynApiUrl: n } = t, {
849
- elapsedTime: r,
850
- method: a,
851
- queryParams: c,
852
- requestBody: h,
853
- requestHeaders: i,
854
- responseBody: l,
855
- responseHeaders: u,
856
- status: d,
857
- token: A,
858
- rawUrl: f
848
+ const { userToken: s, apiUrl: n, trafficSourceId: r } = t, {
849
+ elapsedTime: a,
850
+ method: c,
851
+ queryParams: h,
852
+ requestBody: i,
853
+ requestHeaders: l,
854
+ responseBody: u,
855
+ responseHeaders: d,
856
+ status: S,
857
+ token: f,
858
+ rawUrl: j
859
859
  } = e;
860
860
  if (process.env.NODE_ENV !== "development")
861
861
  try {
862
- const p = new URL(f);
863
- let S = "HTTPS";
864
- p.protocol === "http:" && (S = "HTTP");
865
- const w = JSON.stringify({
866
- domainUrl: p.protocol + "//" + p.host,
867
- pathnameUrl: p.pathname,
868
- status: d,
869
- protocol: S,
870
- method: a,
862
+ const y = new URL(j);
863
+ let D = "HTTPS";
864
+ y.protocol === "http:" && (D = "HTTP");
865
+ const v = JSON.stringify({
866
+ domainUrl: y.protocol + "//" + y.host,
867
+ pathnameUrl: y.pathname,
868
+ trafficSourceId: r,
869
+ status: S,
870
+ protocol: D,
871
+ method: c,
871
872
  trafficUserId: null,
872
- elapsedTime: r,
873
- requestHeaders: i,
874
- requestBody: h,
875
- queryParams: c,
876
- responseHeaders: u,
877
- responseBody: l
873
+ elapsedTime: a,
874
+ requestHeaders: l,
875
+ requestBody: i,
876
+ queryParams: h,
877
+ responseHeaders: d,
878
+ responseBody: u
878
879
  });
879
- await fetch(
880
- n.replace(
881
- ":trafficSourceId",
882
- t.arkynTrafficSourceId
883
- ),
884
- {
885
- method: "POST",
886
- body: w,
887
- headers: {
888
- "Content-Type": "application/json",
889
- Authorization: `Bearer ${s}`
890
- }
880
+ await fetch(n, {
881
+ method: "POST",
882
+ body: v,
883
+ headers: {
884
+ "Content-Type": "application/json",
885
+ Authorization: `Bearer ${s}`
891
886
  }
892
- );
893
- } catch (p) {
887
+ });
888
+ } catch (y) {
894
889
  g({
895
- debugs: [`Error sending request: ${p}`],
890
+ debugs: [`Error sending request: ${y}`],
896
891
  name: "ARKYN_LOG_ERROR",
897
892
  scheme: "red"
898
893
  });
@@ -918,7 +913,7 @@ async function T(e, t, s = {}, n) {
918
913
  } catch {
919
914
  u = null;
920
915
  }
921
- const d = V.handle({
916
+ const d = G.handle({
922
917
  elapsedTime: i,
923
918
  method: e,
924
919
  queryParams: new URL(t).searchParams,
@@ -929,7 +924,7 @@ async function T(e, t, s = {}, n) {
929
924
  status: l,
930
925
  url: t
931
926
  });
932
- return G(d), h.ok ? {
927
+ return Z(d), h.ok ? {
933
928
  success: !0,
934
929
  status: l,
935
930
  message: (u == null ? void 0 : u.message) || r[e],
@@ -956,22 +951,22 @@ async function T(e, t, s = {}, n) {
956
951
  };
957
952
  }
958
953
  }
959
- async function Z(e, t = {}, s) {
954
+ async function W(e, t = {}, s) {
960
955
  return T("DELETE", e, t, s);
961
956
  }
962
- async function W(e, t = {}) {
957
+ async function K(e, t = {}) {
963
958
  return T("GET", e, t);
964
959
  }
965
- async function K(e, t = {}, s) {
960
+ async function Q(e, t = {}, s) {
966
961
  return T("PATCH", e, t, s);
967
962
  }
968
- async function Q(e, t = {}, s) {
963
+ async function X(e, t = {}, s) {
969
964
  return T("POST", e, t, s);
970
965
  }
971
- async function X(e, t = {}, s) {
966
+ async function ss(e, t = {}, s) {
972
967
  return T("PUT", e, t, s);
973
968
  }
974
- class Ss {
969
+ class Ds {
975
970
  /**
976
971
  * Creates an instance of ApiService.
977
972
  * @param props - The configuration properties for the API instance.
@@ -1019,7 +1014,7 @@ class Ss {
1019
1014
  */
1020
1015
  async get(t, s) {
1021
1016
  const n = this.generateURL(t), r = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token);
1022
- return this.onDebug(t, "get", [r]), await W(n, r);
1017
+ return this.onDebug(t, "get", [r]), await K(n, r);
1023
1018
  }
1024
1019
  /**
1025
1020
  * Sends a post request to the specified endpoint.
@@ -1029,7 +1024,7 @@ class Ss {
1029
1024
  */
1030
1025
  async post(t, s) {
1031
1026
  const n = this.generateURL(t), r = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), a = s == null ? void 0 : s.body;
1032
- return this.onDebug(t, "post", [r, a]), await Q(n, r, a);
1027
+ return this.onDebug(t, "post", [r, a]), await X(n, r, a);
1033
1028
  }
1034
1029
  /**
1035
1030
  * Sends a put request to the specified endpoint.
@@ -1039,7 +1034,7 @@ class Ss {
1039
1034
  */
1040
1035
  async put(t, s) {
1041
1036
  const n = this.generateURL(t), r = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), a = s == null ? void 0 : s.body;
1042
- return this.onDebug(t, "put", [r, a]), await X(n, r, a);
1037
+ return this.onDebug(t, "put", [r, a]), await ss(n, r, a);
1043
1038
  }
1044
1039
  /**
1045
1040
  * Sends a patch request to the specified endpoint.
@@ -1049,7 +1044,7 @@ class Ss {
1049
1044
  */
1050
1045
  async patch(t, s) {
1051
1046
  const n = this.generateURL(t), r = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), a = s == null ? void 0 : s.body;
1052
- return this.onDebug(t, "patch", [r, a]), await K(n, r, a);
1047
+ return this.onDebug(t, "patch", [r, a]), await Q(n, r, a);
1053
1048
  }
1054
1049
  /**
1055
1050
  * Sends a delete request to the specified endpoint.
@@ -1059,14 +1054,14 @@ class Ss {
1059
1054
  */
1060
1055
  async delete(t, s) {
1061
1056
  const n = this.generateURL(t), r = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), a = s == null ? void 0 : s.body;
1062
- return this.onDebug(t, "delete", [r, a]), await Z(n, r, a);
1057
+ return this.onDebug(t, "delete", [r, a]), await W(n, r, a);
1063
1058
  }
1064
1059
  }
1065
- function Ds(e, t) {
1060
+ function Os(e, t) {
1066
1061
  var s, n, r;
1067
1062
  return e != null && e.message && typeof (e == null ? void 0 : e.message) == "string" ? e == null ? void 0 : e.message : e != null && e.error && typeof (e == null ? void 0 : e.error) == "string" ? e == null ? void 0 : e.error : (s = e == null ? void 0 : e.error) != null && s.message && typeof ((n = e == null ? void 0 : e.error) == null ? void 0 : n.message) == "string" ? (r = e == null ? void 0 : e.error) == null ? void 0 : r.message : t != null && t.statusText && typeof (t == null ? void 0 : t.statusText) == "string" ? t == null ? void 0 : t.statusText : "Missing error message";
1068
1063
  }
1069
- const Os = async (e) => {
1064
+ const $s = async (e) => {
1070
1065
  let t;
1071
1066
  const s = await e.arrayBuffer(), n = new TextDecoder().decode(s);
1072
1067
  try {
@@ -1084,44 +1079,44 @@ const Os = async (e) => {
1084
1079
  }
1085
1080
  return t;
1086
1081
  };
1087
- function $s(e) {
1082
+ function Is(e) {
1088
1083
  switch (!0) {
1089
1084
  case e instanceof Response:
1090
1085
  return e;
1086
+ case e instanceof z:
1087
+ return e.toResponse();
1091
1088
  case e instanceof Y:
1092
1089
  return e.toResponse();
1093
- case e instanceof P:
1090
+ case e instanceof V:
1094
1091
  return e.toResponse();
1095
1092
  case e instanceof _:
1096
1093
  return e.toResponse();
1097
1094
  case e instanceof M:
1098
1095
  return e.toResponse();
1099
- case e instanceof z:
1100
- return e.toResponse();
1101
1096
  }
1102
1097
  switch (!0) {
1103
- case e instanceof J:
1098
+ case e instanceof B:
1104
1099
  return e.toResponse();
1105
1100
  case e instanceof b:
1106
1101
  return e.toResponse();
1107
- case e instanceof L:
1108
- return e.toResponse();
1109
- case e instanceof B:
1102
+ case e instanceof k:
1110
1103
  return e.toResponse();
1111
1104
  case e instanceof H:
1112
1105
  return e.toResponse();
1113
1106
  case e instanceof q:
1114
1107
  return e.toResponse();
1108
+ case e instanceof F:
1109
+ return e.toResponse();
1115
1110
  case e instanceof x:
1116
1111
  return e.toResponse();
1117
- case e instanceof F:
1112
+ case e instanceof P:
1118
1113
  return e.toResponse();
1119
1114
  case e instanceof R:
1120
1115
  return e.toResponse();
1121
1116
  }
1122
1117
  return new x("Server error", e).toResponse();
1123
1118
  }
1124
- async function ss([
1119
+ async function es([
1125
1120
  e,
1126
1121
  t
1127
1122
  ]) {
@@ -1141,7 +1136,7 @@ async function ss([
1141
1136
  data: s.data
1142
1137
  };
1143
1138
  }
1144
- function es([
1139
+ function ts([
1145
1140
  e,
1146
1141
  t
1147
1142
  ]) {
@@ -1161,7 +1156,7 @@ function es([
1161
1156
  data: s.data
1162
1157
  };
1163
1158
  }
1164
- const Is = (e, t = "") => {
1159
+ const Cs = (e, t = "") => {
1165
1160
  const s = new URL(e.url);
1166
1161
  if (t === "") return s.searchParams;
1167
1162
  const n = Array.from(
@@ -1169,14 +1164,14 @@ const Is = (e, t = "") => {
1169
1164
  ).filter(([r]) => r.startsWith(`${t}:`)).map(([r, a]) => [r.replace(`${t}:`, ""), a]);
1170
1165
  return new URLSearchParams(n);
1171
1166
  };
1172
- function ts(e) {
1167
+ function ns(e) {
1173
1168
  const t = "Error validating:", s = e.issues.map(
1174
1169
  ({ path: n, message: r }) => `-> ${n.join(".")}: ${r}`
1175
1170
  );
1176
1171
  return [t, ...s].join(`
1177
1172
  `);
1178
1173
  }
1179
- class As {
1174
+ class js {
1180
1175
  /**
1181
1176
  * Creates a new SchemaValidator instance.
1182
1177
  *
@@ -1253,7 +1248,7 @@ class As {
1253
1248
  try {
1254
1249
  return this.schema.parse(t);
1255
1250
  } catch (s) {
1256
- throw new x(ts(s));
1251
+ throw new x(ns(s));
1257
1252
  }
1258
1253
  }
1259
1254
  /**
@@ -1282,7 +1277,7 @@ class As {
1282
1277
  * ```
1283
1278
  */
1284
1279
  formValidate(t, s) {
1285
- const n = es([t, this.schema]);
1280
+ const n = ts([t, this.schema]);
1286
1281
  if (!n.success) {
1287
1282
  const r = Object.keys(n.fieldErrors)[0];
1288
1283
  throw new R({
@@ -1320,7 +1315,7 @@ class As {
1320
1315
  * ```
1321
1316
  */
1322
1317
  async formAsyncValidate(t, s) {
1323
- const n = await ss([t, this.schema]);
1318
+ const n = await es([t, this.schema]);
1324
1319
  if (!n.success) {
1325
1320
  const r = Object.keys(n.fieldErrors)[0];
1326
1321
  throw new R({
@@ -1333,62 +1328,62 @@ class As {
1333
1328
  return n.data;
1334
1329
  }
1335
1330
  }
1336
- const ws = (e) => {
1331
+ const vs = (e) => {
1337
1332
  if (!e || !/^[0-9-]+$/.test(e)) return !1;
1338
1333
  const s = N(e), n = 8, r = /^\d{8}$/.test(s);
1339
1334
  return s.length === n && r;
1340
1335
  };
1341
- function ns(e) {
1336
+ function rs(e) {
1342
1337
  return e.length !== 14;
1343
1338
  }
1344
- function rs(e) {
1339
+ function os(e) {
1345
1340
  const [t] = e;
1346
1341
  return [...e].every((s) => s === t);
1347
1342
  }
1348
- function D(e, t) {
1343
+ function O(e, t) {
1349
1344
  let s = 0;
1350
1345
  for (let r = 0; r < t.length; r++)
1351
1346
  s += parseInt(e[r]) * t[r];
1352
1347
  const n = s % 11;
1353
1348
  return n < 2 ? 0 : 11 - n;
1354
1349
  }
1355
- function os(e) {
1350
+ function as(e) {
1356
1351
  return e.slice(12);
1357
1352
  }
1358
- const Us = (e) => {
1353
+ const ws = (e) => {
1359
1354
  if (!e) return !1;
1360
1355
  const t = N(e);
1361
- if (ns(t) || rs(t)) return !1;
1362
- const s = t.slice(0, 12), n = D(s, [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]), r = D(
1356
+ if (rs(t) || os(t)) return !1;
1357
+ const s = t.slice(0, 12), n = O(s, [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]), r = O(
1363
1358
  s + n,
1364
1359
  [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
1365
1360
  );
1366
- return os(t) === `${n}${r}`;
1361
+ return as(t) === `${n}${r}`;
1367
1362
  };
1368
- function as(e) {
1363
+ function us(e) {
1369
1364
  return e.length !== 11;
1370
1365
  }
1371
- function us(e) {
1366
+ function is(e) {
1372
1367
  const [t] = e;
1373
1368
  return [...e].every((s) => s === t);
1374
1369
  }
1375
- function O(e, t) {
1370
+ function $(e, t) {
1376
1371
  let s = 0;
1377
1372
  for (const r of e)
1378
1373
  t > 1 && (s += parseInt(r) * t--);
1379
1374
  const n = s % 11;
1380
1375
  return n < 2 ? 0 : 11 - n;
1381
1376
  }
1382
- function is(e) {
1377
+ function cs(e) {
1383
1378
  return e.slice(9);
1384
1379
  }
1385
- const Cs = (e) => {
1380
+ const As = (e) => {
1386
1381
  if (!e) return !1;
1387
1382
  const t = N(e);
1388
- if (as(t) || us(t)) return !1;
1389
- const s = O(t, 10), n = O(t, 11);
1390
- return is(t) === `${s}${n}`;
1391
- }, vs = (e, t) => {
1383
+ if (us(t) || is(t)) return !1;
1384
+ const s = $(t, 10), n = $(t, 11);
1385
+ return cs(t) === `${s}${n}`;
1386
+ }, Js = (e, t) => {
1392
1387
  let s, n, r;
1393
1388
  const a = (t == null ? void 0 : t.inputFormat) || "DD/MM/YYYY", c = (t == null ? void 0 : t.minYear) || 1900, h = (t == null ? void 0 : t.maxYear) || 3e3;
1394
1389
  if (a === "DD/MM/YYYY") {
@@ -1414,22 +1409,22 @@ const Cs = (e) => {
1414
1409
  } else if (i > d[l - 1])
1415
1410
  return !1;
1416
1411
  return u < c || u > h ? !1 : new Date(u, l - 1, i).getDate() === i;
1417
- }, cs = v.promises.resolve;
1418
- function hs(e) {
1412
+ }, hs = J.promises.resolve;
1413
+ function ls(e) {
1419
1414
  return /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(e);
1420
1415
  }
1421
- function ls(e) {
1416
+ function fs(e) {
1422
1417
  return !(e.length === 0 || e.length > 64 || e.startsWith(".") || e.endsWith(".") || e.includes("..") || !/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/.test(e));
1423
1418
  }
1424
- function fs(e) {
1419
+ function ds(e) {
1425
1420
  return !(e.length === 0 || e.length > 63 || e.startsWith("-") || e.endsWith("-") || !/^[a-zA-Z0-9-]+$/.test(e));
1426
1421
  }
1427
- function ds(e) {
1422
+ function ps(e) {
1428
1423
  if (e.length === 0 || e.length > 253 || e.startsWith(".") || e.endsWith(".") || e.startsWith("-") || e.endsWith("-"))
1429
1424
  return !1;
1430
1425
  const t = e.split(".");
1431
1426
  if (t.length < 2) return !1;
1432
- for (const n of t) if (!fs(n)) return !1;
1427
+ for (const n of t) if (!ds(n)) return !1;
1433
1428
  const s = t[t.length - 1];
1434
1429
  return !(s.length < 2 || !/^[a-zA-Z]+$/.test(s));
1435
1430
  }
@@ -1437,32 +1432,32 @@ function ys(e) {
1437
1432
  const t = e.split("@");
1438
1433
  if (t.length !== 2) return !1;
1439
1434
  const [s, n] = t;
1440
- return !(!ls(s) || !ds(n));
1435
+ return !(!fs(s) || !ps(n));
1441
1436
  }
1442
- function ps(e) {
1437
+ function gs(e) {
1443
1438
  const t = e.split("@");
1444
1439
  return t.length === 2 ? t[1].toLowerCase() : null;
1445
1440
  }
1446
- const gs = ["MX", "A", "AAAA"];
1447
- async function ms(e, t) {
1441
+ const ms = ["MX", "A", "AAAA"];
1442
+ async function Ts(e, t) {
1448
1443
  try {
1449
- return await cs(e, t), !0;
1444
+ return await hs(e, t), !0;
1450
1445
  } catch {
1451
1446
  return !1;
1452
1447
  }
1453
1448
  }
1454
- async function Ts(e) {
1455
- for (const t of gs)
1456
- if (await ms(e, t)) return !0;
1449
+ async function bs(e) {
1450
+ for (const t of ms)
1451
+ if (await Ts(e, t)) return !0;
1457
1452
  return !1;
1458
1453
  }
1459
- const js = async (e) => {
1454
+ const Us = async (e) => {
1460
1455
  if (!e || typeof e != "string") return !1;
1461
1456
  const t = e.trim();
1462
- if (!hs(t) || !ys(t)) return !1;
1463
- const s = ps(t);
1464
- return s ? await Ts(s) : !1;
1465
- }, ks = (e) => {
1457
+ if (!ls(t) || !ys(t)) return !1;
1458
+ const s = gs(t);
1459
+ return s ? await bs(s) : !1;
1460
+ }, Ls = (e) => {
1466
1461
  if (!e) return !1;
1467
1462
  const t = e.length >= 8, s = /[A-Z]/.test(e), n = /[a-z]/.test(e), r = /\d/.test(e), a = /[!@#$%^&*(),.?":{}|<>_\-+=~`[\]\\\/]/.test(
1468
1463
  e
@@ -1474,8 +1469,8 @@ const js = async (e) => {
1474
1469
  r,
1475
1470
  a
1476
1471
  ].every((c) => c);
1477
- }, Js = (e) => {
1478
- for (const t of j) {
1472
+ }, Bs = (e) => {
1473
+ for (const t of U) {
1479
1474
  const s = t.code, n = t.prefix ? `-${t.prefix}` : "", r = t.mask.replace(/[^_]/g, "").length;
1480
1475
  if (t.iso === "BR") {
1481
1476
  if (new RegExp(`^\\${s} \\d{2}9?\\d{8}$`).test(e)) return !0;
@@ -1484,44 +1479,44 @@ const js = async (e) => {
1484
1479
  if (new RegExp(`^\\${s}${n} \\d{${r}}$`).test(e)) return !0;
1485
1480
  }
1486
1481
  return !1;
1487
- }, Ls = (e) => {
1482
+ }, ks = (e) => {
1488
1483
  if (!e || !/^[0-9a-zA-Z.-]+$/.test(e)) return !1;
1489
1484
  const s = e.replace(/[^a-zA-Z0-9]/g, "");
1490
1485
  return s.length < 7 || s.length > 9 ? !1 : /^[0-9]{7,8}[0-9Xx]?$/.test(s);
1491
1486
  };
1492
1487
  export {
1493
- Ss as ApiService,
1494
- I as ArkynLogService,
1495
- J as BadGateway,
1488
+ Ds as ApiService,
1489
+ C as ArkynLogService,
1490
+ B as BadGateway,
1496
1491
  b as BadRequest,
1497
- L as Conflict,
1498
- P as Created,
1499
- $ as DebugService,
1500
- B as Forbidden,
1501
- Y as Found,
1502
- z as NoContent,
1503
- H as NotFound,
1504
- q as NotImplemented,
1505
- As as SchemaValidator,
1492
+ k as Conflict,
1493
+ Y as Created,
1494
+ I as DebugService,
1495
+ H as Forbidden,
1496
+ z as Found,
1497
+ M as NoContent,
1498
+ q as NotFound,
1499
+ F as NotImplemented,
1500
+ js as SchemaValidator,
1506
1501
  x as ServerError,
1507
- M as Success,
1508
- F as Unauthorized,
1502
+ _ as Success,
1503
+ P as Unauthorized,
1509
1504
  R as UnprocessableEntity,
1510
- _ as Updated,
1511
- Ds as decodeErrorMessageFromRequest,
1512
- Os as decodeRequestBody,
1513
- $s as errorHandler,
1505
+ V as Updated,
1506
+ Os as decodeErrorMessageFromRequest,
1507
+ $s as decodeRequestBody,
1508
+ Is as errorHandler,
1514
1509
  g as flushDebugLogs,
1515
- ss as formAsyncParse,
1516
- es as formParse,
1510
+ es as formAsyncParse,
1511
+ ts as formParse,
1517
1512
  E as getCaller,
1518
- Is as getScopedParams,
1519
- ws as validateCep,
1520
- Us as validateCnpj,
1521
- Cs as validateCpf,
1522
- vs as validateDate,
1523
- js as validateEmail,
1524
- ks as validatePassword,
1525
- Js as validatePhone,
1526
- Ls as validateRg
1513
+ Cs as getScopedParams,
1514
+ vs as validateCep,
1515
+ ws as validateCnpj,
1516
+ As as validateCpf,
1517
+ Js as validateDate,
1518
+ Us as validateEmail,
1519
+ Ls as validatePassword,
1520
+ Bs as validatePhone,
1521
+ ks as validateRg
1527
1522
  };
@@ -1,10 +1,10 @@
1
- (function(a,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("zod"),require("@arkyn/shared"),require("node:dns"),require("@arkyn/templates")):typeof define=="function"&&define.amd?define(["exports","zod","@arkyn/shared","node:dns","@arkyn/templates"],d):(a=typeof globalThis<"u"?globalThis:a||self,d(a["@arkyn/server"]={},null,a.shared,a.dns,a.templates))})(this,function(a,d,m,M,Y){"use strict";var Us=Object.defineProperty;var ws=(a,d,m)=>d in a?Us(a,d,{enumerable:!0,configurable:!0,writable:!0,value:m}):a[d]=m;var o=(a,d,m)=>ws(a,typeof d!="symbol"?d+"":d,m);function T(e){var s;if(process.env.NODE_ENV==="development"||((s=process.env)==null?void 0:s.SHOW_ERRORS_IN_CONSOLE)==="true"){const u=`${{yellow:"\x1B[33m",cyan:"\x1B[36m",red:"\x1B[31m",green:"\x1B[32m"}[e.scheme]}[${e.name}]\x1B[0m`;let h=`
1
+ (function(a,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("zod"),require("@arkyn/shared"),require("node:dns"),require("@arkyn/templates")):typeof define=="function"&&define.amd?define(["exports","zod","@arkyn/shared","node:dns","@arkyn/templates"],d):(a=typeof globalThis<"u"?globalThis:a||self,d(a["@arkyn/server"]={},null,a.shared,a.dns,a.templates))})(this,function(a,d,m,Y,_){"use strict";var Us=Object.defineProperty;var Js=(a,d,m)=>d in a?Us(a,d,{enumerable:!0,configurable:!0,writable:!0,value:m}):a[d]=m;var o=(a,d,m)=>Js(a,typeof d!="symbol"?d+"":d,m);function T(e){var s;if(process.env.NODE_ENV==="development"||((s=process.env)==null?void 0:s.SHOW_ERRORS_IN_CONSOLE)==="true"){const u=`${{yellow:"\x1B[33m",cyan:"\x1B[36m",red:"\x1B[31m",green:"\x1B[32m"}[e.scheme]}[${e.name}]\x1B[0m`;let h=`
2
2
  `;e.debugs.forEach(l=>{h+=`${u} ${l.trim()}
3
- `}),console.log(h)}}const _={};class v{static setIgnoreFile(t){this.ignoreFiles.push(t)}static clearIgnoreFiles(){this.ignoreFiles=[]}}o(v,"ignoreFiles",[]);function N(){const e=process.cwd(),n=(new Error().stack||"").split(`
4
- `).map(i=>i.trim()),r=v.ignoreFiles;let u=2;for(;u<n.length&&(n[u].includes("node:internal")||n[u].includes("/node_modules/"));)u++;if(r.length>0)for(;u<n.length&&r.some(i=>n[u].includes(i));)u++;const h=n[u]||"";let l="Unknown function",c="Unknown caller";const f=h.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);if(f)l=f[1],c=f[2];else{const i=h.match(/at\s+(.+)/);if(i){c=i[1];const g=c.match(/at\s+([^(\s]+)\s+/);g&&g[1]!=="new"&&(l=g[1])}}c.includes("(")&&(c=c.substring(c.indexOf("(")+1,c.lastIndexOf(")"))),c=c.split(":").slice(0,-2).join(":");try{c=_.relative(e,c)}catch{}return{functionName:l,callerInfo:c}}class p{onDebug(t){const{name:s,body:n,cause:r,message:u}=t,h=[],{callerInfo:l,functionName:c}=N();h.push(`${s} initialized`),h.push(`Caller Function: ${c}`),h.push(`Caller Location: ${l}`),u&&h.push(`Message: ${u}`),n&&h.push(`Body: ${JSON.stringify(n,null,2)}`),r&&h.push(`Cause: ${JSON.stringify(r,null,2)}`),T({scheme:"red",name:"ARKYN-BAD-RESPONSE-DEBUG",debugs:h})}}class I extends p{constructor(s,n){super();o(this,"body");o(this,"cause");o(this,"status",502);o(this,"statusText");this.body={name:"BadGateway",message:s},this.statusText=s,this.cause=n?JSON.stringify(n):void 0,this.onDebug({name:"BadGateway",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class S extends p{constructor(s,n){super();o(this,"body");o(this,"cause");o(this,"status",400);o(this,"statusText");this.body={name:"BadRequest",message:s},this.statusText=s,this.cause=n?JSON.stringify(n):void 0,this.onDebug({name:"BadRequest",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class $ extends p{constructor(s,n){super();o(this,"body");o(this,"cause");o(this,"status",409);o(this,"statusText");this.body={name:"Conflict",message:s},this.statusText=s,this.cause=n?JSON.stringify(n):void 0,this.onDebug({name:"Conflict",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class C extends p{constructor(s,n){super();o(this,"body");o(this,"cause");o(this,"status",403);o(this,"statusText");this.body={name:"Forbidden",message:s},this.statusText=s,this.cause=n?JSON.stringify(n):void 0,this.onDebug({name:"Forbidden",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class A extends p{constructor(s,n){super();o(this,"body");o(this,"cause");o(this,"status",404);o(this,"statusText");this.body={name:"NotFound",message:s},this.statusText=s,this.cause=n?JSON.stringify(n):void 0,this.onDebug({name:"NotFound",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class k extends p{constructor(s,n){super();o(this,"body");o(this,"cause");o(this,"status",501);o(this,"statusText");this.body={name:"NotImplemented",message:s},this.statusText=s,this.cause=n?JSON.stringify(n):void 0,this.onDebug({name:"NotImplemented",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class E extends p{constructor(s,n){super();o(this,"body");o(this,"cause");o(this,"status",500);o(this,"statusText");this.body={name:"ServerError",message:s},this.statusText=s,this.cause=n?JSON.stringify(n):void 0,this.onDebug({name:"ServerError",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class U extends p{constructor(s,n){super();o(this,"body");o(this,"cause");o(this,"status",401);o(this,"statusText");this.body={name:"Unauthorized",message:s},this.statusText=s,this.cause=n?JSON.stringify(n):void 0,this.onDebug({name:"Unauthorized",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class D extends p{constructor(s){super();o(this,"body");o(this,"status",422);o(this,"statusText");this.statusText=s.message||"Unprocessable Entity",this.body={name:"UnprocessableEntity",message:s.message||null,data:s.data,fieldErrors:s.fieldErrors,fields:s.fields},this.onDebug({name:"UnprocessableEntity",cause:s.fieldErrors,message:s.message})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class R{onDebug(t,s,n){const r=[],{callerInfo:u,functionName:h}=N();r.push(`${t} initialized
3
+ `}),console.log(h)}}const V={};class v{static setIgnoreFile(t){this.ignoreFiles.push(t)}static clearIgnoreFiles(){this.ignoreFiles=[]}}o(v,"ignoreFiles",[]);function N(){const e=process.cwd(),n=(new Error().stack||"").split(`
4
+ `).map(i=>i.trim()),r=v.ignoreFiles;let u=2;for(;u<n.length&&(n[u].includes("node:internal")||n[u].includes("/node_modules/"));)u++;if(r.length>0)for(;u<n.length&&r.some(i=>n[u].includes(i));)u++;const h=n[u]||"";let l="Unknown function",c="Unknown caller";const f=h.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);if(f)l=f[1],c=f[2];else{const i=h.match(/at\s+(.+)/);if(i){c=i[1];const g=c.match(/at\s+([^(\s]+)\s+/);g&&g[1]!=="new"&&(l=g[1])}}c.includes("(")&&(c=c.substring(c.indexOf("(")+1,c.lastIndexOf(")"))),c=c.split(":").slice(0,-2).join(":");try{c=V.relative(e,c)}catch{}return{functionName:l,callerInfo:c}}class p{onDebug(t){const{name:s,body:n,cause:r,message:u}=t,h=[],{callerInfo:l,functionName:c}=N();h.push(`${s} initialized`),h.push(`Caller Function: ${c}`),h.push(`Caller Location: ${l}`),u&&h.push(`Message: ${u}`),n&&h.push(`Body: ${JSON.stringify(n,null,2)}`),r&&h.push(`Cause: ${JSON.stringify(r,null,2)}`),T({scheme:"red",name:"ARKYN-BAD-RESPONSE-DEBUG",debugs:h})}}class C extends p{constructor(s,n){super();o(this,"body");o(this,"cause");o(this,"status",502);o(this,"statusText");this.body={name:"BadGateway",message:s},this.statusText=s,this.cause=n?JSON.stringify(n):void 0,this.onDebug({name:"BadGateway",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class E extends p{constructor(s,n){super();o(this,"body");o(this,"cause");o(this,"status",400);o(this,"statusText");this.body={name:"BadRequest",message:s},this.statusText=s,this.cause=n?JSON.stringify(n):void 0,this.onDebug({name:"BadRequest",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class $ extends p{constructor(s,n){super();o(this,"body");o(this,"cause");o(this,"status",409);o(this,"statusText");this.body={name:"Conflict",message:s},this.statusText=s,this.cause=n?JSON.stringify(n):void 0,this.onDebug({name:"Conflict",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class I extends p{constructor(s,n){super();o(this,"body");o(this,"cause");o(this,"status",403);o(this,"statusText");this.body={name:"Forbidden",message:s},this.statusText=s,this.cause=n?JSON.stringify(n):void 0,this.onDebug({name:"Forbidden",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class j extends p{constructor(s,n){super();o(this,"body");o(this,"cause");o(this,"status",404);o(this,"statusText");this.body={name:"NotFound",message:s},this.statusText=s,this.cause=n?JSON.stringify(n):void 0,this.onDebug({name:"NotFound",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class w extends p{constructor(s,n){super();o(this,"body");o(this,"cause");o(this,"status",501);o(this,"statusText");this.body={name:"NotImplemented",message:s},this.statusText=s,this.cause=n?JSON.stringify(n):void 0,this.onDebug({name:"NotImplemented",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class S extends p{constructor(s,n){super();o(this,"body");o(this,"cause");o(this,"status",500);o(this,"statusText");this.body={name:"ServerError",message:s},this.statusText=s,this.cause=n?JSON.stringify(n):void 0,this.onDebug({name:"ServerError",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class A extends p{constructor(s,n){super();o(this,"body");o(this,"cause");o(this,"status",401);o(this,"statusText");this.body={name:"Unauthorized",message:s},this.statusText=s,this.cause=n?JSON.stringify(n):void 0,this.onDebug({name:"Unauthorized",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class D extends p{constructor(s){super();o(this,"body");o(this,"status",422);o(this,"statusText");this.statusText=s.message||"Unprocessable Entity",this.body={name:"UnprocessableEntity",message:s.message||null,data:s.data,fieldErrors:s.fieldErrors,fields:s.fields},this.onDebug({name:"UnprocessableEntity",cause:s.fieldErrors,message:s.message})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class R{onDebug(t,s,n){const r=[],{callerInfo:u,functionName:h}=N();r.push(`${t} initialized
5
5
  `),r.push(`Caller Function: ${h}
6
6
  `),r.push(`Caller Location: ${u}
7
7
  `),r.push(`Body: ${JSON.stringify(s,null,2)}
8
8
  `),n&&r.push(`Cause: ${JSON.stringify(n,null,2)}
9
- `),T({scheme:"green",name:"ARKYN-SUCCESS-RESPONSE-DEBUG",debugs:r})}}class w extends R{constructor(s,n){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(n==null?void 0:n.headers)||{},this.status=(n==null?void 0:n.status)||201,this.statusText=(n==null?void 0:n.statusText)||"Resource created successfully",this.onDebug("Created",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class j extends R{constructor(s,n){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(n==null?void 0:n.headers)||{},this.status=(n==null?void 0:n.status)||302,this.statusText=(n==null?void 0:n.statusText)||"Found",this.onDebug("Found",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class J extends R{constructor(s){super();o(this,"headers");o(this,"status");o(this,"statusText");this.headers=(s==null?void 0:s.headers)||{},this.status=(s==null?void 0:s.status)||204,this.statusText=(s==null?void 0:s.statusText)??"No content",this.onDebug("No content",null)}toResponse(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return new Response(null,s)}}class L extends R{constructor(s,n){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(n==null?void 0:n.headers)||{},this.status=(n==null?void 0:n.status)||200,this.statusText=(n==null?void 0:n.statusText)??"OK",this.onDebug("Success",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class B extends R{constructor(s,n){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(n==null?void 0:n.headers)||{},this.status=(n==null?void 0:n.status)||200,this.statusText=(n==null?void 0:n.statusText)||"Resource updated successfully",this.onDebug("Updated",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class V{static mapHeaders(t){return t instanceof Headers?Object.fromEntries(t.entries()):typeof t=="object"?Object.entries(t).reduce((s,[n,r])=>(typeof r=="string"?s[n]=r:Array.isArray(r)?s[n]=r.join(", "):s[n]=JSON.stringify(r),s),{}):{}}static mapQueryParams(t){const s={};return t.forEach((n,r)=>{s[r]=n}),s}static handle(t){return{rawUrl:t.url,status:t.status,method:t.method,token:null,elapsedTime:t.elapsedTime,requestHeaders:this.mapHeaders(t.requestHeaders),requestBody:t.requestBody||null,queryParams:this.mapQueryParams(t.queryParams),responseHeaders:this.mapHeaders(t.responseHeaders),responseBody:t.responseBody||null}}}class O{static setArkynConfig(t){if(this.arkynConfig)return;let n=t.arkynLogBaseApiUrl||"https://logs-arkyn-flow-logs.vw6wo7.easypanel.host";n=n+"/http-traffic-records/:trafficSourceId",this.arkynConfig={arkynTrafficSourceId:t.arkynTrafficSourceId,arkynUserToken:t.arkynUserToken,arkynApiUrl:n}}static getArkynConfig(){return this.arkynConfig}static resetArkynConfig(){this.arkynConfig=void 0}}o(O,"arkynConfig");async function G(e){const t=O.getArkynConfig();if(!t)return;const{arkynUserToken:s,arkynApiUrl:n}=t,{elapsedTime:r,method:u,queryParams:h,requestBody:l,requestHeaders:c,responseBody:f,responseHeaders:i,status:g,token:As,rawUrl:y}=e;if(process.env.NODE_ENV!=="development")try{const b=new URL(y);let z="HTTPS";b.protocol==="http:"&&(z="HTTP");const ks=JSON.stringify({domainUrl:b.protocol+"//"+b.host,pathnameUrl:b.pathname,status:g,protocol:z,method:u,trafficUserId:null,elapsedTime:r,requestHeaders:c,requestBody:l,queryParams:h,responseHeaders:i,responseBody:f});await fetch(n.replace(":trafficSourceId",t.arkynTrafficSourceId),{method:"POST",body:ks,headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`}})}catch(b){T({debugs:[`Error sending request: ${b}`],name:"ARKYN_LOG_ERROR",scheme:"red"})}}async function x(e,t,s={},n){const r={POST:"Resource created successfully",PUT:"Resource updated successfully",DELETE:"Resource deleted successfully",PATCH:"Resource patched successfully",GET:"Request successful"};try{const u=performance.now(),h={...s,"Content-Type":"application/json"},l=await fetch(t,{method:e,headers:h,body:n?JSON.stringify(n):void 0}),c=performance.now()-u,f=l.status;let i=null;try{i=await l.json()}catch{i=null}const g=V.handle({elapsedTime:c,method:e,queryParams:new URL(t).searchParams,requestHeaders:h,requestBody:n,responseBody:i,responseHeaders:l.headers,status:f,url:t});return G(g),l.ok?{success:!0,status:f,message:(i==null?void 0:i.message)||r[e],response:i,cause:null}:{success:!1,status:f,message:(i==null?void 0:i.message)||l.statusText||"Request failed",response:i,cause:null}}catch(u){return T({debugs:[`Network error or request failed: ${u}`],name:"ARKYN_MAKE_REQUEST_ERROR",scheme:"red"}),{success:!1,status:0,message:"Network error or request failed",response:null,cause:u instanceof Error?u.message:String(u)}}}async function Z(e,t={},s){return x("DELETE",e,t,s)}async function W(e,t={}){return x("GET",e,t)}async function K(e,t={},s){return x("PATCH",e,t,s)}async function Q(e,t={},s){return x("POST",e,t,s)}async function X(e,t={},s){return x("PUT",e,t,s)}class ss{constructor(t){o(this,"baseUrl");o(this,"baseHeaders");o(this,"baseToken");o(this,"enableDebug");this.baseUrl=t.baseUrl,this.baseHeaders=t.baseHeaders||void 0,this.baseToken=t.baseToken||void 0,this.enableDebug=t.enableDebug||!1}onDebug(t,s,n){if(this.enableDebug){const r=[];r.push(`Base URL: ${this.baseUrl}`),r.push(`Endpoint: ${t}`),r.push(`Method: ${s}`),n[0]&&r.push(`Headers: ${JSON.stringify(n[0])}`),n[1]&&r.push(`Body: ${JSON.stringify(n[1])}`),T({debugs:r,name:"ARKYN-API-DEBUG",scheme:"yellow"})}}generateURL(t){return this.baseUrl+t}generateHeaders(t,s){let n={};return this.baseToken&&(n={Authorization:`Bearer ${this.baseToken}`}),this.baseHeaders&&(n={...n,...this.baseHeaders}),t&&(n={...n,...t}),s&&(n={...n,Authorization:`Bearer ${s}`}),n}async get(t,s){const n=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token);return this.onDebug(t,"get",[r]),await W(n,r)}async post(t,s){const n=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(t,"post",[r,u]),await Q(n,r,u)}async put(t,s){const n=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(t,"put",[r,u]),await X(n,r,u)}async patch(t,s){const n=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(t,"patch",[r,u]),await K(n,r,u)}async delete(t,s){const n=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(t,"delete",[r,u]),await Z(n,r,u)}}function es(e,t){var s,n,r;return e!=null&&e.message&&typeof(e==null?void 0:e.message)=="string"?e==null?void 0:e.message:e!=null&&e.error&&typeof(e==null?void 0:e.error)=="string"?e==null?void 0:e.error:(s=e==null?void 0:e.error)!=null&&s.message&&typeof((n=e==null?void 0:e.error)==null?void 0:n.message)=="string"?(r=e==null?void 0:e.error)==null?void 0:r.message:t!=null&&t.statusText&&typeof(t==null?void 0:t.statusText)=="string"?t==null?void 0:t.statusText:"Missing error message"}const ts=async e=>{let t;const s=await e.arrayBuffer(),n=new TextDecoder().decode(s);try{t=JSON.parse(n)}catch{try{if(n.includes("=")){const u=new URLSearchParams(n);t=Object.fromEntries(u.entries())}else throw new S("Invalid URLSearchParams format")}catch{throw new S("Failed to extract data from request")}}return t};function ns(e){switch(!0){case e instanceof Response:return e;case e instanceof j:return e.toResponse();case e instanceof w:return e.toResponse();case e instanceof B:return e.toResponse();case e instanceof L:return e.toResponse();case e instanceof J:return e.toResponse()}switch(!0){case e instanceof I:return e.toResponse();case e instanceof S:return e.toResponse();case e instanceof $:return e.toResponse();case e instanceof C:return e.toResponse();case e instanceof A:return e.toResponse();case e instanceof k:return e.toResponse();case e instanceof E:return e.toResponse();case e instanceof U:return e.toResponse();case e instanceof D:return e.toResponse()}return new E("Server error",e).toResponse()}async function q([e,t]){const s=await t.safeParseAsync(e);if(s.success===!1){const n=Object.fromEntries(s.error.issues.map(r=>[r.path.join("."),r.message]));return{success:s.success,fieldErrors:n,fields:e}}else return{success:s.success,data:s.data}}function F([e,t]){const s=t.safeParse(e);if(s.success===!1){const n=Object.fromEntries(s.error.issues.map(r=>[r.path.join("."),r.message]));return{success:s.success,fieldErrors:n,fields:e}}else return{success:s.success,data:s.data}}const rs=(e,t="")=>{const s=new URL(e.url);if(t==="")return s.searchParams;const n=Array.from(s.searchParams.entries()).filter(([r])=>r.startsWith(`${t}:`)).map(([r,u])=>[r.replace(`${t}:`,""),u]);return new URLSearchParams(n)};function os(e){const t="Error validating:",s=e.issues.map(({path:n,message:r})=>`-> ${n.join(".")}: ${r}`);return[t,...s].join(`
10
- `)}class as{constructor(t){o(this,"functionName");o(this,"callerInfo");this.schema=t;const{callerInfo:s,functionName:n}=N();this.callerInfo=s,this.functionName=n}isValid(t){return this.schema.safeParse(t).success}safeValidate(t){return this.schema.safeParse(t)}validate(t){try{return this.schema.parse(t)}catch(s){throw new E(os(s))}}formValidate(t,s){const n=F([t,this.schema]);if(!n.success){const r=Object.keys(n.fieldErrors)[0];throw new D({fields:n.fields,fieldErrors:n.fieldErrors,data:{scrollTo:r},message:s})}return n.data}async formAsyncValidate(t,s){const n=await q([t,this.schema]);if(!n.success){const r=Object.keys(n.fieldErrors)[0];throw new D({fields:n.fields,fieldErrors:n.fieldErrors,data:{scrollTo:r},message:s})}return n.data}}const us=e=>{if(!e||!/^[0-9-]+$/.test(e))return!1;const s=m.removeNonNumeric(e),n=8,r=/^\d{8}$/.test(s);return s.length===n&&r};function is(e){return e.length!==14}function cs(e){const[t]=e;return[...e].every(s=>s===t)}function H(e,t){let s=0;for(let r=0;r<t.length;r++)s+=parseInt(e[r])*t[r];const n=s%11;return n<2?0:11-n}function hs(e){return e.slice(12)}const ls=e=>{if(!e)return!1;const t=m.removeNonNumeric(e);if(is(t)||cs(t))return!1;const s=t.slice(0,12),n=H(s,[5,4,3,2,9,8,7,6,5,4,3,2]),r=H(s+n,[6,5,4,3,2,9,8,7,6,5,4,3,2]);return hs(t)===`${n}${r}`};function fs(e){return e.length!==11}function ds(e){const[t]=e;return[...e].every(s=>s===t)}function P(e,t){let s=0;for(const r of e)t>1&&(s+=parseInt(r)*t--);const n=s%11;return n<2?0:11-n}function ys(e){return e.slice(9)}const ps=e=>{if(!e)return!1;const t=m.removeNonNumeric(e);if(fs(t)||ds(t))return!1;const s=P(t,10),n=P(t,11);return ys(t)===`${s}${n}`},gs=(e,t)=>{let s,n,r;const u=(t==null?void 0:t.inputFormat)||"DD/MM/YYYY",h=(t==null?void 0:t.minYear)||1900,l=(t==null?void 0:t.maxYear)||3e3;if(u==="DD/MM/YYYY"){const y=/^(\d{2})\/(\d{2})\/(\d{4})$/;if(!y.test(e))return!1;[,s,n,r]=e.match(y)||[]}else if(u==="MM-DD-YYYY"){const y=/^(\d{2})-(\d{2})-(\d{4})$/;if(!y.test(e))return!1;[,n,s,r]=e.match(y)||[]}else if(u==="YYYY-MM-DD"){const y=/^(\d{4})-(\d{2})-(\d{2})$/;if(!y.test(e))return!1;[,r,n,s]=e.match(y)||[]}else throw new Error("Invalid date format");const c=parseInt(s,10),f=parseInt(n,10),i=parseInt(r,10);if(c<1||c>31||f<1||f>12)return!1;const g=[31,28,31,30,31,30,31,31,30,31,30,31];if(f===2){const y=i%4===0&&i%100!==0||i%400===0;if(c>(y?29:28))return!1}else if(c>g[f-1])return!1;return i<h||i>l?!1:new Date(i,f-1,c).getDate()===c},ms=M.promises.resolve;function Ts(e){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)}function bs(e){return!(e.length===0||e.length>64||e.startsWith(".")||e.endsWith(".")||e.includes("..")||!/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/.test(e))}function Rs(e){return!(e.length===0||e.length>63||e.startsWith("-")||e.endsWith("-")||!/^[a-zA-Z0-9-]+$/.test(e))}function xs(e){if(e.length===0||e.length>253||e.startsWith(".")||e.endsWith(".")||e.startsWith("-")||e.endsWith("-"))return!1;const t=e.split(".");if(t.length<2)return!1;for(const n of t)if(!Rs(n))return!1;const s=t[t.length-1];return!(s.length<2||!/^[a-zA-Z]+$/.test(s))}function Ns(e){const t=e.split("@");if(t.length!==2)return!1;const[s,n]=t;return!(!bs(s)||!xs(n))}function Ss(e){const t=e.split("@");return t.length===2?t[1].toLowerCase():null}const Es=["MX","A","AAAA"];async function Ds(e,t){try{return await ms(e,t),!0}catch{return!1}}async function vs(e){for(const t of Es)if(await Ds(e,t))return!0;return!1}const Os=async e=>{if(!e||typeof e!="string")return!1;const t=e.trim();if(!Ts(t)||!Ns(t))return!1;const s=Ss(t);return s?await vs(s):!1},Is=e=>{if(!e)return!1;const t=e.length>=8,s=/[A-Z]/.test(e),n=/[a-z]/.test(e),r=/\d/.test(e),u=/[!@#$%^&*(),.?":{}|<>_\-+=~`[\]\\\/]/.test(e);return[t,s,n,r,u].every(h=>h)},$s=e=>{for(const t of Y.countries){const s=t.code,n=t.prefix?`-${t.prefix}`:"",r=t.mask.replace(/[^_]/g,"").length;if(t.iso==="BR"){if(new RegExp(`^\\${s} \\d{2}9?\\d{8}$`).test(e))return!0;continue}if(new RegExp(`^\\${s}${n} \\d{${r}}$`).test(e))return!0}return!1},Cs=e=>{if(!e||!/^[0-9a-zA-Z.-]+$/.test(e))return!1;const s=e.replace(/[^a-zA-Z0-9]/g,"");return s.length<7||s.length>9?!1:/^[0-9]{7,8}[0-9Xx]?$/.test(s)};a.ApiService=ss,a.ArkynLogService=O,a.BadGateway=I,a.BadRequest=S,a.Conflict=$,a.Created=w,a.DebugService=v,a.Forbidden=C,a.Found=j,a.NoContent=J,a.NotFound=A,a.NotImplemented=k,a.SchemaValidator=as,a.ServerError=E,a.Success=L,a.Unauthorized=U,a.UnprocessableEntity=D,a.Updated=B,a.decodeErrorMessageFromRequest=es,a.decodeRequestBody=ts,a.errorHandler=ns,a.flushDebugLogs=T,a.formAsyncParse=q,a.formParse=F,a.getCaller=N,a.getScopedParams=rs,a.validateCep=us,a.validateCnpj=ls,a.validateCpf=ps,a.validateDate=gs,a.validateEmail=Os,a.validatePassword=Is,a.validatePhone=$s,a.validateRg=Cs,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
9
+ `),T({scheme:"green",name:"ARKYN-SUCCESS-RESPONSE-DEBUG",debugs:r})}}class U extends R{constructor(s,n){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(n==null?void 0:n.headers)||{},this.status=(n==null?void 0:n.status)||201,this.statusText=(n==null?void 0:n.statusText)||"Resource created successfully",this.onDebug("Created",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class J extends R{constructor(s,n){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(n==null?void 0:n.headers)||{},this.status=(n==null?void 0:n.status)||302,this.statusText=(n==null?void 0:n.statusText)||"Found",this.onDebug("Found",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class k extends R{constructor(s){super();o(this,"headers");o(this,"status");o(this,"statusText");this.headers=(s==null?void 0:s.headers)||{},this.status=(s==null?void 0:s.status)||204,this.statusText=(s==null?void 0:s.statusText)??"No content",this.onDebug("No content",null)}toResponse(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return new Response(null,s)}}class L extends R{constructor(s,n){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(n==null?void 0:n.headers)||{},this.status=(n==null?void 0:n.status)||200,this.statusText=(n==null?void 0:n.statusText)??"OK",this.onDebug("Success",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class q extends R{constructor(s,n){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(n==null?void 0:n.headers)||{},this.status=(n==null?void 0:n.status)||200,this.statusText=(n==null?void 0:n.statusText)||"Resource updated successfully",this.onDebug("Updated",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class G{static mapHeaders(t){return t instanceof Headers?Object.fromEntries(t.entries()):typeof t=="object"?Object.entries(t).reduce((s,[n,r])=>(typeof r=="string"?s[n]=r:Array.isArray(r)?s[n]=r.join(", "):s[n]=JSON.stringify(r),s),{}):{}}static mapQueryParams(t){const s={};return t.forEach((n,r)=>{s[r]=n}),s}static handle(t){return{rawUrl:t.url,status:t.status,method:t.method,token:null,elapsedTime:t.elapsedTime,requestHeaders:this.mapHeaders(t.requestHeaders),requestBody:t.requestBody||null,queryParams:this.mapQueryParams(t.queryParams),responseHeaders:this.mapHeaders(t.responseHeaders),responseBody:t.responseBody||null}}}class O{static setArkynConfig(t){if(this.arkynConfig)return;const{trafficSourceId:s,userToken:n,logBaseApiUrl:r}=t;this.arkynConfig={trafficSourceId:s,userToken:n,apiUrl:r||"http://95.216.190.158:8080/ingest-log"}}static getArkynConfig(){return this.arkynConfig}static resetArkynConfig(){this.arkynConfig=void 0}}o(O,"arkynConfig");async function Z(e){const t=O.getArkynConfig();if(!t)return;const{userToken:s,apiUrl:n,trafficSourceId:r}=t,{elapsedTime:u,method:h,queryParams:l,requestBody:c,requestHeaders:f,responseBody:i,responseHeaders:g,status:z,token:y,rawUrl:ws}=e;if(process.env.NODE_ENV!=="development")try{const b=new URL(ws);let M="HTTPS";b.protocol==="http:"&&(M="HTTP");const As=JSON.stringify({domainUrl:b.protocol+"//"+b.host,pathnameUrl:b.pathname,trafficSourceId:r,status:z,protocol:M,method:h,trafficUserId:null,elapsedTime:u,requestHeaders:f,requestBody:c,queryParams:l,responseHeaders:g,responseBody:i});await fetch(n,{method:"POST",body:As,headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`}})}catch(b){T({debugs:[`Error sending request: ${b}`],name:"ARKYN_LOG_ERROR",scheme:"red"})}}async function x(e,t,s={},n){const r={POST:"Resource created successfully",PUT:"Resource updated successfully",DELETE:"Resource deleted successfully",PATCH:"Resource patched successfully",GET:"Request successful"};try{const u=performance.now(),h={...s,"Content-Type":"application/json"},l=await fetch(t,{method:e,headers:h,body:n?JSON.stringify(n):void 0}),c=performance.now()-u,f=l.status;let i=null;try{i=await l.json()}catch{i=null}const g=G.handle({elapsedTime:c,method:e,queryParams:new URL(t).searchParams,requestHeaders:h,requestBody:n,responseBody:i,responseHeaders:l.headers,status:f,url:t});return Z(g),l.ok?{success:!0,status:f,message:(i==null?void 0:i.message)||r[e],response:i,cause:null}:{success:!1,status:f,message:(i==null?void 0:i.message)||l.statusText||"Request failed",response:i,cause:null}}catch(u){return T({debugs:[`Network error or request failed: ${u}`],name:"ARKYN_MAKE_REQUEST_ERROR",scheme:"red"}),{success:!1,status:0,message:"Network error or request failed",response:null,cause:u instanceof Error?u.message:String(u)}}}async function W(e,t={},s){return x("DELETE",e,t,s)}async function K(e,t={}){return x("GET",e,t)}async function Q(e,t={},s){return x("PATCH",e,t,s)}async function X(e,t={},s){return x("POST",e,t,s)}async function ss(e,t={},s){return x("PUT",e,t,s)}class es{constructor(t){o(this,"baseUrl");o(this,"baseHeaders");o(this,"baseToken");o(this,"enableDebug");this.baseUrl=t.baseUrl,this.baseHeaders=t.baseHeaders||void 0,this.baseToken=t.baseToken||void 0,this.enableDebug=t.enableDebug||!1}onDebug(t,s,n){if(this.enableDebug){const r=[];r.push(`Base URL: ${this.baseUrl}`),r.push(`Endpoint: ${t}`),r.push(`Method: ${s}`),n[0]&&r.push(`Headers: ${JSON.stringify(n[0])}`),n[1]&&r.push(`Body: ${JSON.stringify(n[1])}`),T({debugs:r,name:"ARKYN-API-DEBUG",scheme:"yellow"})}}generateURL(t){return this.baseUrl+t}generateHeaders(t,s){let n={};return this.baseToken&&(n={Authorization:`Bearer ${this.baseToken}`}),this.baseHeaders&&(n={...n,...this.baseHeaders}),t&&(n={...n,...t}),s&&(n={...n,Authorization:`Bearer ${s}`}),n}async get(t,s){const n=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token);return this.onDebug(t,"get",[r]),await K(n,r)}async post(t,s){const n=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(t,"post",[r,u]),await X(n,r,u)}async put(t,s){const n=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(t,"put",[r,u]),await ss(n,r,u)}async patch(t,s){const n=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(t,"patch",[r,u]),await Q(n,r,u)}async delete(t,s){const n=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(t,"delete",[r,u]),await W(n,r,u)}}function ts(e,t){var s,n,r;return e!=null&&e.message&&typeof(e==null?void 0:e.message)=="string"?e==null?void 0:e.message:e!=null&&e.error&&typeof(e==null?void 0:e.error)=="string"?e==null?void 0:e.error:(s=e==null?void 0:e.error)!=null&&s.message&&typeof((n=e==null?void 0:e.error)==null?void 0:n.message)=="string"?(r=e==null?void 0:e.error)==null?void 0:r.message:t!=null&&t.statusText&&typeof(t==null?void 0:t.statusText)=="string"?t==null?void 0:t.statusText:"Missing error message"}const ns=async e=>{let t;const s=await e.arrayBuffer(),n=new TextDecoder().decode(s);try{t=JSON.parse(n)}catch{try{if(n.includes("=")){const u=new URLSearchParams(n);t=Object.fromEntries(u.entries())}else throw new E("Invalid URLSearchParams format")}catch{throw new E("Failed to extract data from request")}}return t};function rs(e){switch(!0){case e instanceof Response:return e;case e instanceof J:return e.toResponse();case e instanceof U:return e.toResponse();case e instanceof q:return e.toResponse();case e instanceof L:return e.toResponse();case e instanceof k:return e.toResponse()}switch(!0){case e instanceof C:return e.toResponse();case e instanceof E:return e.toResponse();case e instanceof $:return e.toResponse();case e instanceof I:return e.toResponse();case e instanceof j:return e.toResponse();case e instanceof w:return e.toResponse();case e instanceof S:return e.toResponse();case e instanceof A:return e.toResponse();case e instanceof D:return e.toResponse()}return new S("Server error",e).toResponse()}async function B([e,t]){const s=await t.safeParseAsync(e);if(s.success===!1){const n=Object.fromEntries(s.error.issues.map(r=>[r.path.join("."),r.message]));return{success:s.success,fieldErrors:n,fields:e}}else return{success:s.success,data:s.data}}function F([e,t]){const s=t.safeParse(e);if(s.success===!1){const n=Object.fromEntries(s.error.issues.map(r=>[r.path.join("."),r.message]));return{success:s.success,fieldErrors:n,fields:e}}else return{success:s.success,data:s.data}}const os=(e,t="")=>{const s=new URL(e.url);if(t==="")return s.searchParams;const n=Array.from(s.searchParams.entries()).filter(([r])=>r.startsWith(`${t}:`)).map(([r,u])=>[r.replace(`${t}:`,""),u]);return new URLSearchParams(n)};function as(e){const t="Error validating:",s=e.issues.map(({path:n,message:r})=>`-> ${n.join(".")}: ${r}`);return[t,...s].join(`
10
+ `)}class us{constructor(t){o(this,"functionName");o(this,"callerInfo");this.schema=t;const{callerInfo:s,functionName:n}=N();this.callerInfo=s,this.functionName=n}isValid(t){return this.schema.safeParse(t).success}safeValidate(t){return this.schema.safeParse(t)}validate(t){try{return this.schema.parse(t)}catch(s){throw new S(as(s))}}formValidate(t,s){const n=F([t,this.schema]);if(!n.success){const r=Object.keys(n.fieldErrors)[0];throw new D({fields:n.fields,fieldErrors:n.fieldErrors,data:{scrollTo:r},message:s})}return n.data}async formAsyncValidate(t,s){const n=await B([t,this.schema]);if(!n.success){const r=Object.keys(n.fieldErrors)[0];throw new D({fields:n.fields,fieldErrors:n.fieldErrors,data:{scrollTo:r},message:s})}return n.data}}const is=e=>{if(!e||!/^[0-9-]+$/.test(e))return!1;const s=m.removeNonNumeric(e),n=8,r=/^\d{8}$/.test(s);return s.length===n&&r};function cs(e){return e.length!==14}function hs(e){const[t]=e;return[...e].every(s=>s===t)}function H(e,t){let s=0;for(let r=0;r<t.length;r++)s+=parseInt(e[r])*t[r];const n=s%11;return n<2?0:11-n}function ls(e){return e.slice(12)}const fs=e=>{if(!e)return!1;const t=m.removeNonNumeric(e);if(cs(t)||hs(t))return!1;const s=t.slice(0,12),n=H(s,[5,4,3,2,9,8,7,6,5,4,3,2]),r=H(s+n,[6,5,4,3,2,9,8,7,6,5,4,3,2]);return ls(t)===`${n}${r}`};function ds(e){return e.length!==11}function ys(e){const[t]=e;return[...e].every(s=>s===t)}function P(e,t){let s=0;for(const r of e)t>1&&(s+=parseInt(r)*t--);const n=s%11;return n<2?0:11-n}function ps(e){return e.slice(9)}const gs=e=>{if(!e)return!1;const t=m.removeNonNumeric(e);if(ds(t)||ys(t))return!1;const s=P(t,10),n=P(t,11);return ps(t)===`${s}${n}`},ms=(e,t)=>{let s,n,r;const u=(t==null?void 0:t.inputFormat)||"DD/MM/YYYY",h=(t==null?void 0:t.minYear)||1900,l=(t==null?void 0:t.maxYear)||3e3;if(u==="DD/MM/YYYY"){const y=/^(\d{2})\/(\d{2})\/(\d{4})$/;if(!y.test(e))return!1;[,s,n,r]=e.match(y)||[]}else if(u==="MM-DD-YYYY"){const y=/^(\d{2})-(\d{2})-(\d{4})$/;if(!y.test(e))return!1;[,n,s,r]=e.match(y)||[]}else if(u==="YYYY-MM-DD"){const y=/^(\d{4})-(\d{2})-(\d{2})$/;if(!y.test(e))return!1;[,r,n,s]=e.match(y)||[]}else throw new Error("Invalid date format");const c=parseInt(s,10),f=parseInt(n,10),i=parseInt(r,10);if(c<1||c>31||f<1||f>12)return!1;const g=[31,28,31,30,31,30,31,31,30,31,30,31];if(f===2){const y=i%4===0&&i%100!==0||i%400===0;if(c>(y?29:28))return!1}else if(c>g[f-1])return!1;return i<h||i>l?!1:new Date(i,f-1,c).getDate()===c},Ts=Y.promises.resolve;function bs(e){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)}function Rs(e){return!(e.length===0||e.length>64||e.startsWith(".")||e.endsWith(".")||e.includes("..")||!/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/.test(e))}function xs(e){return!(e.length===0||e.length>63||e.startsWith("-")||e.endsWith("-")||!/^[a-zA-Z0-9-]+$/.test(e))}function Ns(e){if(e.length===0||e.length>253||e.startsWith(".")||e.endsWith(".")||e.startsWith("-")||e.endsWith("-"))return!1;const t=e.split(".");if(t.length<2)return!1;for(const n of t)if(!xs(n))return!1;const s=t[t.length-1];return!(s.length<2||!/^[a-zA-Z]+$/.test(s))}function Es(e){const t=e.split("@");if(t.length!==2)return!1;const[s,n]=t;return!(!Rs(s)||!Ns(n))}function Ss(e){const t=e.split("@");return t.length===2?t[1].toLowerCase():null}const Ds=["MX","A","AAAA"];async function vs(e,t){try{return await Ts(e,t),!0}catch{return!1}}async function Os(e){for(const t of Ds)if(await vs(e,t))return!0;return!1}const Cs=async e=>{if(!e||typeof e!="string")return!1;const t=e.trim();if(!bs(t)||!Es(t))return!1;const s=Ss(t);return s?await Os(s):!1},$s=e=>{if(!e)return!1;const t=e.length>=8,s=/[A-Z]/.test(e),n=/[a-z]/.test(e),r=/\d/.test(e),u=/[!@#$%^&*(),.?":{}|<>_\-+=~`[\]\\\/]/.test(e);return[t,s,n,r,u].every(h=>h)},Is=e=>{for(const t of _.countries){const s=t.code,n=t.prefix?`-${t.prefix}`:"",r=t.mask.replace(/[^_]/g,"").length;if(t.iso==="BR"){if(new RegExp(`^\\${s} \\d{2}9?\\d{8}$`).test(e))return!0;continue}if(new RegExp(`^\\${s}${n} \\d{${r}}$`).test(e))return!0}return!1},js=e=>{if(!e||!/^[0-9a-zA-Z.-]+$/.test(e))return!1;const s=e.replace(/[^a-zA-Z0-9]/g,"");return s.length<7||s.length>9?!1:/^[0-9]{7,8}[0-9Xx]?$/.test(s)};a.ApiService=es,a.ArkynLogService=O,a.BadGateway=C,a.BadRequest=E,a.Conflict=$,a.Created=U,a.DebugService=v,a.Forbidden=I,a.Found=J,a.NoContent=k,a.NotFound=j,a.NotImplemented=w,a.SchemaValidator=us,a.ServerError=S,a.Success=L,a.Unauthorized=A,a.UnprocessableEntity=D,a.Updated=q,a.decodeErrorMessageFromRequest=ts,a.decodeRequestBody=ns,a.errorHandler=rs,a.flushDebugLogs=T,a.formAsyncParse=B,a.formParse=F,a.getCaller=N,a.getScopedParams=os,a.validateCep=is,a.validateCnpj=fs,a.validateCpf=gs,a.validateDate=ms,a.validateEmail=Cs,a.validatePassword=$s,a.validatePhone=Is,a.validateRg=js,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
@@ -1,12 +1,12 @@
1
1
  type ArkynConfigProps = {
2
- arkynTrafficSourceId: string;
3
- arkynUserToken: string;
4
- arkynApiUrl: string;
2
+ trafficSourceId: string;
3
+ userToken: string;
4
+ apiUrl: string;
5
5
  };
6
6
  type SetArkynConfigProps = {
7
- arkynTrafficSourceId: string;
8
- arkynUserToken: string;
9
- arkynLogBaseApiUrl?: string;
7
+ trafficSourceId: string;
8
+ userToken: string;
9
+ logBaseApiUrl?: string;
10
10
  };
11
11
  /**
12
12
  * The `ArkynLogService` class manages the configuration for the arkyn flow.
@@ -1 +1 @@
1
- {"version":3,"file":"arkynLogService.d.ts","sourceRoot":"","sources":["../../src/services/arkynLogService.ts"],"names":[],"mappings":"AAAA,KAAK,gBAAgB,GAAG;IACtB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF;;;;GAIG;AAEH,cAAM,eAAe;IACnB,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAmB;IAE9C;;;;;;;;;;OAUG;IAEH,MAAM,CAAC,cAAc,CAAC,WAAW,EAAE,mBAAmB;IAgBtD;;;;;OAKG;IACH,MAAM,CAAC,cAAc,IAAI,gBAAgB,GAAG,SAAS;IAIrD;;;OAGG;IAEH,MAAM,CAAC,gBAAgB;CAGxB;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
1
+ {"version":3,"file":"arkynLogService.d.ts","sourceRoot":"","sources":["../../src/services/arkynLogService.ts"],"names":[],"mappings":"AAAA,KAAK,gBAAgB,GAAG;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;;;GAIG;AAEH,cAAM,eAAe;IACnB,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAmB;IAE9C;;;;;;;;;;OAUG;IAEH,MAAM,CAAC,cAAc,CAAC,WAAW,EAAE,mBAAmB;IAYtD;;;;;OAKG;IACH,MAAM,CAAC,cAAc,IAAI,gBAAgB,GAAG,SAAS;IAIrD;;;OAGG;IAEH,MAAM,CAAC,gBAAgB;CAGxB;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -19,14 +19,11 @@ class ArkynLogService {
19
19
  static setArkynConfig(arkynConfig) {
20
20
  if (!!this.arkynConfig)
21
21
  return;
22
- let defaultArkynURL = `https://logs-arkyn-flow-logs.vw6wo7.easypanel.host`;
23
- let arkynLogBaseApiUrl = arkynConfig.arkynLogBaseApiUrl || defaultArkynURL;
24
- arkynLogBaseApiUrl =
25
- arkynLogBaseApiUrl + "/http-traffic-records/:trafficSourceId";
22
+ const { trafficSourceId, userToken, logBaseApiUrl } = arkynConfig;
26
23
  this.arkynConfig = {
27
- arkynTrafficSourceId: arkynConfig.arkynTrafficSourceId,
28
- arkynUserToken: arkynConfig.arkynUserToken,
29
- arkynApiUrl: arkynLogBaseApiUrl,
24
+ trafficSourceId,
25
+ userToken,
26
+ apiUrl: logBaseApiUrl || `http://95.216.190.158:8080/ingest-log`,
30
27
  };
31
28
  }
32
29
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkyn/server",
3
- "version": "3.0.1-beta.77",
3
+ "version": "3.0.1-beta.78",
4
4
  "author": "Arkyn | Lucas Gonçalves",
5
5
  "main": "./dist/bundle.js",
6
6
  "module": "./dist/bundle.js",