@arkyn/server 3.0.1-beta.76 → 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.
package/dist/bundle.js CHANGED
@@ -1,10 +1,10 @@
1
- var v = Object.defineProperty;
2
- var A = (e, t, s) => t in e ? v(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[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
3
  var o = (e, t, s) => A(e, typeof t != "symbol" ? t + "" : t, s);
4
4
  import "zod";
5
- import { removeNonNumeric as R } from "@arkyn/shared";
6
- import k from "node:dns";
7
- import { countries as w } from "@arkyn/templates";
5
+ import { removeNonNumeric as N } from "@arkyn/shared";
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 J = {};
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", []);
66
- function N() {
65
+ o(I, "ignoreFiles", []);
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 N() {
92
92
  i.lastIndexOf(")")
93
93
  )), i = i.split(":").slice(0, -2).join(":");
94
94
  try {
95
- i = J.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
- const { name: s, body: n, cause: r, message: a } = t, c = [], { callerInfo: h, functionName: i } = N();
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 x 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 x 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 b 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 b 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 I extends y {
490
+ class R extends p {
491
491
  /**
492
492
  * Creates an instance of the `UnprocessableEntity` class.
493
493
  *
@@ -558,7 +558,7 @@ class m {
558
558
  * ```
559
559
  */
560
560
  onDebug(t, s, n) {
561
- const r = [], { callerInfo: a, functionName: c } = N();
561
+ const r = [], { callerInfo: a, functionName: c } = E();
562
562
  r.push(`${t} initialized
563
563
  `), r.push(`Caller Function: ${c}
564
564
  `), r.push(`Caller Location: ${a}
@@ -615,7 +615,7 @@ class Y extends m {
615
615
  return Response.json(this.body, s);
616
616
  }
617
617
  }
618
- class P extends m {
618
+ class z extends m {
619
619
  /**
620
620
  * Creates an instance of the `Found` class.
621
621
  *
@@ -690,7 +690,7 @@ class M extends m {
690
690
  return new Response(null, s);
691
691
  }
692
692
  }
693
- class z extends m {
693
+ class _ extends m {
694
694
  /**
695
695
  * Creates an instance of the `Success` class.
696
696
  *
@@ -734,7 +734,7 @@ class z 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 O {
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 O {
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 O {
841
841
  this.arkynConfig = void 0;
842
842
  }
843
843
  }
844
- o(O, "arkynConfig");
845
- async function G(e) {
846
- const t = O.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: U,
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 C = 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: C,
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 Es(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 Ds = 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 {
@@ -1077,51 +1072,71 @@ const Ds = async (e) => {
1077
1072
  const a = new URLSearchParams(n);
1078
1073
  t = Object.fromEntries(a.entries());
1079
1074
  } else
1080
- throw new x("Invalid URLSearchParams format");
1075
+ throw new b("Invalid URLSearchParams format");
1081
1076
  } catch {
1082
- throw new x("Failed to extract data from request");
1077
+ throw new b("Failed to extract data from request");
1083
1078
  }
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;
1091
- case e instanceof P:
1086
+ case e instanceof z:
1092
1087
  return e.toResponse();
1093
1088
  case e instanceof Y:
1094
1089
  return e.toResponse();
1095
- case e instanceof _:
1090
+ case e instanceof V:
1096
1091
  return e.toResponse();
1097
- case e instanceof z:
1092
+ case e instanceof _:
1098
1093
  return e.toResponse();
1099
1094
  case e instanceof M:
1100
1095
  return e.toResponse();
1101
1096
  }
1102
1097
  switch (!0) {
1103
- case e instanceof j:
1104
- return e.toResponse();
1105
- case e instanceof x:
1098
+ case e instanceof B:
1106
1099
  return e.toResponse();
1107
- case e instanceof L:
1100
+ case e instanceof b:
1108
1101
  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();
1115
- case e instanceof b:
1116
- return e.toResponse();
1117
1108
  case e instanceof F:
1118
1109
  return e.toResponse();
1119
- case e instanceof I:
1110
+ case e instanceof x:
1111
+ return e.toResponse();
1112
+ case e instanceof P:
1113
+ return e.toResponse();
1114
+ case e instanceof R:
1120
1115
  return e.toResponse();
1121
1116
  }
1122
- return new b("Server error", e).toResponse();
1117
+ return new x("Server error", e).toResponse();
1123
1118
  }
1124
- function ss([
1119
+ async function es([
1120
+ e,
1121
+ t
1122
+ ]) {
1123
+ const s = await t.safeParseAsync(e);
1124
+ if (s.success === !1) {
1125
+ const n = Object.fromEntries(
1126
+ s.error.issues.map((r) => [r.path.join("."), r.message])
1127
+ );
1128
+ return {
1129
+ success: s.success,
1130
+ fieldErrors: n,
1131
+ fields: e
1132
+ };
1133
+ } else
1134
+ return {
1135
+ success: s.success,
1136
+ data: s.data
1137
+ };
1138
+ }
1139
+ function ts([
1125
1140
  e,
1126
1141
  t
1127
1142
  ]) {
@@ -1141,7 +1156,7 @@ function ss([
1141
1156
  data: s.data
1142
1157
  };
1143
1158
  }
1144
- const Is = (e, t = "") => {
1159
+ const Cs = (e, t = "") => {
1145
1160
  const s = new URL(e.url);
1146
1161
  if (t === "") return s.searchParams;
1147
1162
  const n = Array.from(
@@ -1149,39 +1164,161 @@ const Is = (e, t = "") => {
1149
1164
  ).filter(([r]) => r.startsWith(`${t}:`)).map(([r, a]) => [r.replace(`${t}:`, ""), a]);
1150
1165
  return new URLSearchParams(n);
1151
1166
  };
1152
- function es(e) {
1167
+ function ns(e) {
1153
1168
  const t = "Error validating:", s = e.issues.map(
1154
1169
  ({ path: n, message: r }) => `-> ${n.join(".")}: ${r}`
1155
1170
  );
1156
1171
  return [t, ...s].join(`
1157
1172
  `);
1158
1173
  }
1159
- class Os {
1174
+ class js {
1175
+ /**
1176
+ * Creates a new SchemaValidator instance.
1177
+ *
1178
+ * @param {T} schema - The Zod schema to use for validation.
1179
+ */
1160
1180
  constructor(t) {
1161
1181
  o(this, "functionName");
1162
1182
  o(this, "callerInfo");
1163
1183
  this.schema = t;
1164
- const { callerInfo: s, functionName: n } = N();
1184
+ const { callerInfo: s, functionName: n } = E();
1165
1185
  this.callerInfo = s, this.functionName = n;
1166
1186
  }
1187
+ /**
1188
+ * Checks if the provided data is valid according to the schema without throwing errors.
1189
+ *
1190
+ * @param {any} data - The data to validate.
1191
+ *
1192
+ * @returns {boolean} True if the data is valid, false otherwise.
1193
+ *
1194
+ * @example
1195
+ * ```typescript
1196
+ * const validator = new SchemaValidator(userSchema);
1197
+ * const isValid = validator.isValid({ name: "John", email: "invalid-email" });
1198
+ * console.log(isValid); // false
1199
+ * ```
1200
+ */
1167
1201
  isValid(t) {
1168
1202
  return this.schema.safeParse(t).success;
1169
1203
  }
1204
+ /**
1205
+ * Safely validates data and returns the complete parse result without throwing errors.
1206
+ *
1207
+ * @param {any} data - The data to validate.
1208
+ *
1209
+ * @returns {z.ZodSafeParseResult<z.infer<T>>} The Zod safe parse result containing success status and data or error.
1210
+ *
1211
+ * @example
1212
+ * ```typescript
1213
+ * const validator = new SchemaValidator(userSchema);
1214
+ * const result = validator.safeValidate({ name: "", email: "john@example.com" });
1215
+ *
1216
+ * if (result.success) {
1217
+ * console.log(result.data); // Validated data
1218
+ * } else {
1219
+ * console.log(result.error.issues); // Validation errors
1220
+ * }
1221
+ * ```
1222
+ */
1170
1223
  safeValidate(t) {
1171
1224
  return this.schema.safeParse(t);
1172
1225
  }
1226
+ /**
1227
+ * Validates data and returns the parsed result, throwing a ServerError on validation failure.
1228
+ *
1229
+ * @param {any} data - The data to validate.
1230
+ *
1231
+ * @returns {z.infer<T>} The validated and parsed data.
1232
+ *
1233
+ * @throws {ServerError} When validation fails, with a formatted error message.
1234
+ *
1235
+ * @example
1236
+ * ```typescript
1237
+ * const validator = new SchemaValidator(userSchema);
1238
+ *
1239
+ * try {
1240
+ * const validUser = validator.validate({ name: "John", email: "john@example.com", age: 25 });
1241
+ * console.log(validUser); // { name: "John", email: "john@example.com", age: 25 }
1242
+ * } catch (error) {
1243
+ * console.error(error.message); // "Error validating:\n-> name: String must contain at least 1 character(s)"
1244
+ * }
1245
+ * ```
1246
+ */
1173
1247
  validate(t) {
1174
1248
  try {
1175
1249
  return this.schema.parse(t);
1176
1250
  } catch (s) {
1177
- throw new b(es(s));
1251
+ throw new x(ns(s));
1178
1252
  }
1179
1253
  }
1254
+ /**
1255
+ * Validates form data and returns the parsed result, throwing an UnprocessableEntity error on validation failure.
1256
+ * This method is specifically designed for form validation in web applications.
1257
+ *
1258
+ * @param {any} data - The form data to validate.
1259
+ * @param {string} [message] - Optional custom error message.
1260
+ *
1261
+ * @returns {z.infer<T>} The validated and parsed form data.
1262
+ *
1263
+ * @throws {UnprocessableEntity} When validation fails, with structured field errors for form handling.
1264
+ *
1265
+ * @example
1266
+ * ```typescript
1267
+ * const validator = new SchemaValidator(userSchema);
1268
+ *
1269
+ * try {
1270
+ * const validFormData = validator.formValidate(requestBody, "User data is invalid");
1271
+ * console.log(validFormData);
1272
+ * } catch (error) {
1273
+ * // UnprocessableEntity with fieldErrors, fields, and scrollTo data
1274
+ * console.log(error.fieldErrors); // { name: "Name is required", email: "Invalid email" }
1275
+ * console.log(error.data.scrollTo); // "name" (first error field)
1276
+ * }
1277
+ * ```
1278
+ */
1180
1279
  formValidate(t, s) {
1181
- const n = ss([t, this.schema]);
1280
+ const n = ts([t, this.schema]);
1281
+ if (!n.success) {
1282
+ const r = Object.keys(n.fieldErrors)[0];
1283
+ throw new R({
1284
+ fields: n.fields,
1285
+ fieldErrors: n.fieldErrors,
1286
+ data: { scrollTo: r },
1287
+ message: s
1288
+ });
1289
+ }
1290
+ return n.data;
1291
+ }
1292
+ /**
1293
+ * Asynchronously validates form data and returns the parsed result, throwing an UnprocessableEntity error on validation failure.
1294
+ * This method is the async version of formValidate, designed for form validation with async schemas.
1295
+ *
1296
+ * @param {any} data - The form data to validate.
1297
+ * @param {string} [message] - Optional custom error message.
1298
+ *
1299
+ * @returns {Promise<z.infer<T>>} A promise that resolves to the validated and parsed form data.
1300
+ *
1301
+ * @throws {UnprocessableEntity} When validation fails, with structured field errors for form handling.
1302
+ *
1303
+ * @example
1304
+ * ```typescript
1305
+ * const validator = new SchemaValidator(userSchemaWithAsyncValidation);
1306
+ *
1307
+ * try {
1308
+ * const validFormData = await validator.formAsyncValidate(requestBody, "User data is invalid");
1309
+ * console.log(validFormData);
1310
+ * } catch (error) {
1311
+ * // UnprocessableEntity with fieldErrors, fields, and scrollTo data
1312
+ * console.log(error.fieldErrors); // { name: "Name is required", email: "Invalid email" }
1313
+ * console.log(error.data.scrollTo); // "name" (first error field)
1314
+ * }
1315
+ * ```
1316
+ */
1317
+ async formAsyncValidate(t, s) {
1318
+ const n = await es([t, this.schema]);
1182
1319
  if (!n.success) {
1183
1320
  const r = Object.keys(n.fieldErrors)[0];
1184
- throw new I({
1321
+ throw new R({
1185
1322
  fields: n.fields,
1186
1323
  fieldErrors: n.fieldErrors,
1187
1324
  data: { scrollTo: r },
@@ -1191,62 +1328,62 @@ class Os {
1191
1328
  return n.data;
1192
1329
  }
1193
1330
  }
1194
- const Us = (e) => {
1331
+ const vs = (e) => {
1195
1332
  if (!e || !/^[0-9-]+$/.test(e)) return !1;
1196
- const s = R(e), n = 8, r = /^\d{8}$/.test(s);
1333
+ const s = N(e), n = 8, r = /^\d{8}$/.test(s);
1197
1334
  return s.length === n && r;
1198
1335
  };
1199
- function ts(e) {
1336
+ function rs(e) {
1200
1337
  return e.length !== 14;
1201
1338
  }
1202
- function ns(e) {
1339
+ function os(e) {
1203
1340
  const [t] = e;
1204
1341
  return [...e].every((s) => s === t);
1205
1342
  }
1206
- function E(e, t) {
1343
+ function O(e, t) {
1207
1344
  let s = 0;
1208
1345
  for (let r = 0; r < t.length; r++)
1209
1346
  s += parseInt(e[r]) * t[r];
1210
1347
  const n = s % 11;
1211
1348
  return n < 2 ? 0 : 11 - n;
1212
1349
  }
1213
- function rs(e) {
1350
+ function as(e) {
1214
1351
  return e.slice(12);
1215
1352
  }
1216
- const Cs = (e) => {
1353
+ const ws = (e) => {
1217
1354
  if (!e) return !1;
1218
- const t = R(e);
1219
- if (ts(t) || ns(t)) return !1;
1220
- const s = t.slice(0, 12), n = E(s, [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]), r = E(
1355
+ const t = N(e);
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(
1221
1358
  s + n,
1222
1359
  [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
1223
1360
  );
1224
- return rs(t) === `${n}${r}`;
1361
+ return as(t) === `${n}${r}`;
1225
1362
  };
1226
- function os(e) {
1363
+ function us(e) {
1227
1364
  return e.length !== 11;
1228
1365
  }
1229
- function as(e) {
1366
+ function is(e) {
1230
1367
  const [t] = e;
1231
1368
  return [...e].every((s) => s === t);
1232
1369
  }
1233
- function D(e, t) {
1370
+ function $(e, t) {
1234
1371
  let s = 0;
1235
1372
  for (const r of e)
1236
1373
  t > 1 && (s += parseInt(r) * t--);
1237
1374
  const n = s % 11;
1238
1375
  return n < 2 ? 0 : 11 - n;
1239
1376
  }
1240
- function us(e) {
1377
+ function cs(e) {
1241
1378
  return e.slice(9);
1242
1379
  }
1243
- const vs = (e) => {
1380
+ const As = (e) => {
1244
1381
  if (!e) return !1;
1245
- const t = R(e);
1246
- if (os(t) || as(t)) return !1;
1247
- const s = D(t, 10), n = D(t, 11);
1248
- return us(t) === `${s}${n}`;
1249
- }, As = (e, t) => {
1382
+ const t = N(e);
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) => {
1250
1387
  let s, n, r;
1251
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;
1252
1389
  if (a === "DD/MM/YYYY") {
@@ -1272,55 +1409,55 @@ const vs = (e) => {
1272
1409
  } else if (i > d[l - 1])
1273
1410
  return !1;
1274
1411
  return u < c || u > h ? !1 : new Date(u, l - 1, i).getDate() === i;
1275
- }, is = k.promises.resolve;
1276
- function cs(e) {
1412
+ }, hs = J.promises.resolve;
1413
+ function ls(e) {
1277
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);
1278
1415
  }
1279
- function hs(e) {
1416
+ function fs(e) {
1280
1417
  return !(e.length === 0 || e.length > 64 || e.startsWith(".") || e.endsWith(".") || e.includes("..") || !/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/.test(e));
1281
1418
  }
1282
- function ls(e) {
1419
+ function ds(e) {
1283
1420
  return !(e.length === 0 || e.length > 63 || e.startsWith("-") || e.endsWith("-") || !/^[a-zA-Z0-9-]+$/.test(e));
1284
1421
  }
1285
- function fs(e) {
1422
+ function ps(e) {
1286
1423
  if (e.length === 0 || e.length > 253 || e.startsWith(".") || e.endsWith(".") || e.startsWith("-") || e.endsWith("-"))
1287
1424
  return !1;
1288
1425
  const t = e.split(".");
1289
1426
  if (t.length < 2) return !1;
1290
- for (const n of t) if (!ls(n)) return !1;
1427
+ for (const n of t) if (!ds(n)) return !1;
1291
1428
  const s = t[t.length - 1];
1292
1429
  return !(s.length < 2 || !/^[a-zA-Z]+$/.test(s));
1293
1430
  }
1294
- function ds(e) {
1431
+ function ys(e) {
1295
1432
  const t = e.split("@");
1296
1433
  if (t.length !== 2) return !1;
1297
1434
  const [s, n] = t;
1298
- return !(!hs(s) || !fs(n));
1435
+ return !(!fs(s) || !ps(n));
1299
1436
  }
1300
- function ys(e) {
1437
+ function gs(e) {
1301
1438
  const t = e.split("@");
1302
1439
  return t.length === 2 ? t[1].toLowerCase() : null;
1303
1440
  }
1304
- const ps = ["MX", "A", "AAAA"];
1305
- async function gs(e, t) {
1441
+ const ms = ["MX", "A", "AAAA"];
1442
+ async function Ts(e, t) {
1306
1443
  try {
1307
- return await is(e, t), !0;
1444
+ return await hs(e, t), !0;
1308
1445
  } catch {
1309
1446
  return !1;
1310
1447
  }
1311
1448
  }
1312
- async function ms(e) {
1313
- for (const t of ps)
1314
- if (await gs(e, t)) return !0;
1449
+ async function bs(e) {
1450
+ for (const t of ms)
1451
+ if (await Ts(e, t)) return !0;
1315
1452
  return !1;
1316
1453
  }
1317
- const ks = async (e) => {
1454
+ const Us = async (e) => {
1318
1455
  if (!e || typeof e != "string") return !1;
1319
1456
  const t = e.trim();
1320
- if (!cs(t) || !ds(t)) return !1;
1321
- const s = ys(t);
1322
- return s ? await ms(s) : !1;
1323
- }, ws = (e) => {
1457
+ if (!ls(t) || !ys(t)) return !1;
1458
+ const s = gs(t);
1459
+ return s ? await bs(s) : !1;
1460
+ }, Ls = (e) => {
1324
1461
  if (!e) return !1;
1325
1462
  const t = e.length >= 8, s = /[A-Z]/.test(e), n = /[a-z]/.test(e), r = /\d/.test(e), a = /[!@#$%^&*(),.?":{}|<>_\-+=~`[\]\\\/]/.test(
1326
1463
  e
@@ -1332,8 +1469,8 @@ const ks = async (e) => {
1332
1469
  r,
1333
1470
  a
1334
1471
  ].every((c) => c);
1335
- }, Js = (e) => {
1336
- for (const t of w) {
1472
+ }, Bs = (e) => {
1473
+ for (const t of U) {
1337
1474
  const s = t.code, n = t.prefix ? `-${t.prefix}` : "", r = t.mask.replace(/[^_]/g, "").length;
1338
1475
  if (t.iso === "BR") {
1339
1476
  if (new RegExp(`^\\${s} \\d{2}9?\\d{8}$`).test(e)) return !0;
@@ -1342,43 +1479,44 @@ const ks = async (e) => {
1342
1479
  if (new RegExp(`^\\${s}${n} \\d{${r}}$`).test(e)) return !0;
1343
1480
  }
1344
1481
  return !1;
1345
- }, js = (e) => {
1482
+ }, ks = (e) => {
1346
1483
  if (!e || !/^[0-9a-zA-Z.-]+$/.test(e)) return !1;
1347
1484
  const s = e.replace(/[^a-zA-Z0-9]/g, "");
1348
1485
  return s.length < 7 || s.length > 9 ? !1 : /^[0-9]{7,8}[0-9Xx]?$/.test(s);
1349
1486
  };
1350
1487
  export {
1351
- Ss as ApiService,
1352
- O as ArkynLogService,
1353
- j as BadGateway,
1354
- x as BadRequest,
1355
- L as Conflict,
1488
+ Ds as ApiService,
1489
+ C as ArkynLogService,
1490
+ B as BadGateway,
1491
+ b as BadRequest,
1492
+ k as Conflict,
1356
1493
  Y as Created,
1357
- $ as DebugService,
1358
- B as Forbidden,
1359
- P as Found,
1494
+ I as DebugService,
1495
+ H as Forbidden,
1496
+ z as Found,
1360
1497
  M as NoContent,
1361
- H as NotFound,
1362
- q as NotImplemented,
1363
- Os as SchemaValidator,
1364
- b as ServerError,
1365
- z as Success,
1366
- F as Unauthorized,
1367
- I as UnprocessableEntity,
1368
- _ as Updated,
1369
- Es as decodeErrorMessageFromRequest,
1370
- Ds as decodeRequestBody,
1371
- $s as errorHandler,
1498
+ q as NotFound,
1499
+ F as NotImplemented,
1500
+ js as SchemaValidator,
1501
+ x as ServerError,
1502
+ _ as Success,
1503
+ P as Unauthorized,
1504
+ R as UnprocessableEntity,
1505
+ V as Updated,
1506
+ Os as decodeErrorMessageFromRequest,
1507
+ $s as decodeRequestBody,
1508
+ Is as errorHandler,
1372
1509
  g as flushDebugLogs,
1373
- ss as formParse,
1374
- N as getCaller,
1375
- Is as getScopedParams,
1376
- Us as validateCep,
1377
- Cs as validateCnpj,
1378
- vs as validateCpf,
1379
- As as validateDate,
1380
- ks as validateEmail,
1381
- ws as validatePassword,
1382
- Js as validatePhone,
1383
- js as validateRg
1510
+ es as formAsyncParse,
1511
+ ts as formParse,
1512
+ E as getCaller,
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
1384
1522
  };