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

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,9 +1,10 @@
1
- var A = Object.defineProperty;
2
- var k = (e, t, s) => t in e ? A(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
- var o = (e, t, s) => k(e, typeof t != "symbol" ? t + "" : t, s);
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);
4
4
  import "zod";
5
- import { removeNonNumeric as R } from "@arkyn/shared";
6
- import { countries as w } from "@arkyn/templates";
5
+ import { removeNonNumeric as N } from "@arkyn/shared";
6
+ import v from "node:dns";
7
+ import { countries as j } from "@arkyn/templates";
7
8
  function g(e) {
8
9
  var s;
9
10
  if (process.env.NODE_ENV === "development" || ((s = process.env) == null ? void 0 : s.SHOW_ERRORS_IN_CONSOLE) === "true") {
@@ -21,8 +22,8 @@ function g(e) {
21
22
  }), console.log(c);
22
23
  }
23
24
  }
24
- const $ = {};
25
- class I {
25
+ const k = {};
26
+ class $ {
26
27
  /**
27
28
  * Sets the file name to be ignored during stack trace analysis.
28
29
  *
@@ -61,10 +62,10 @@ class I {
61
62
  * The name of the file to ignore when analyzing the stack trace.
62
63
  * When set, the `getCaller` function will skip stack frames containing this file name.
63
64
  */
64
- o(I, "ignoreFiles", []);
65
- function N() {
65
+ o($, "ignoreFiles", []);
66
+ function E() {
66
67
  const e = process.cwd(), n = (new Error().stack || "").split(`
67
- `).map((u) => u.trim()), r = I.ignoreFiles;
68
+ `).map((u) => u.trim()), r = $.ignoreFiles;
68
69
  let a = 2;
69
70
  for (; a < n.length && (n[a].includes("node:internal") || n[a].includes("/node_modules/")); )
70
71
  a++;
@@ -91,14 +92,14 @@ function N() {
91
92
  i.lastIndexOf(")")
92
93
  )), i = i.split(":").slice(0, -2).join(":");
93
94
  try {
94
- i = $.relative(e, i);
95
+ i = k.relative(e, i);
95
96
  } catch {
96
97
  }
97
98
  return { functionName: h, callerInfo: i };
98
99
  }
99
100
  class y {
100
101
  onDebug(t) {
101
- 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();
102
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 });
103
104
  }
104
105
  }
@@ -150,7 +151,7 @@ class J extends y {
150
151
  return Response.json(this.body, s);
151
152
  }
152
153
  }
153
- class x extends y {
154
+ class b extends y {
154
155
  /**
155
156
  * Creates an instance of the `BadRequest` class.
156
157
  *
@@ -198,7 +199,7 @@ class x extends y {
198
199
  return Response.json(this.body, s);
199
200
  }
200
201
  }
201
- class j extends y {
202
+ class L extends y {
202
203
  /**
203
204
  * Creates an instance of the `Conflict` class.
204
205
  *
@@ -246,7 +247,7 @@ class j extends y {
246
247
  return Response.json(this.body, s);
247
248
  }
248
249
  }
249
- class L extends y {
250
+ class B extends y {
250
251
  /**
251
252
  * Creates an instance of the `Forbidden` class.
252
253
  *
@@ -294,7 +295,7 @@ class L extends y {
294
295
  return Response.json(this.body, s);
295
296
  }
296
297
  }
297
- class B extends y {
298
+ class H extends y {
298
299
  /**
299
300
  * Creates an instance of the `NotFound` class.
300
301
  *
@@ -342,7 +343,7 @@ class B extends y {
342
343
  return Response.json(this.body, s);
343
344
  }
344
345
  }
345
- class H extends y {
346
+ class q extends y {
346
347
  /**
347
348
  * Creates an instance of the `NotImplemented` class.
348
349
  *
@@ -390,7 +391,7 @@ class H extends y {
390
391
  return Response.json(this.body, s);
391
392
  }
392
393
  }
393
- class b extends y {
394
+ class x extends y {
394
395
  /**
395
396
  * Creates an instance of the `ServerError` class.
396
397
  *
@@ -438,7 +439,7 @@ class b extends y {
438
439
  return Response.json(this.body, s);
439
440
  }
440
441
  }
441
- class q extends y {
442
+ class F extends y {
442
443
  /**
443
444
  * Creates an instance of the `Unauthorized` class.
444
445
  *
@@ -486,7 +487,7 @@ class q extends y {
486
487
  return Response.json(this.body, s);
487
488
  }
488
489
  }
489
- class O extends y {
490
+ class R extends y {
490
491
  /**
491
492
  * Creates an instance of the `UnprocessableEntity` class.
492
493
  *
@@ -557,7 +558,7 @@ class m {
557
558
  * ```
558
559
  */
559
560
  onDebug(t, s, n) {
560
- const r = [], { callerInfo: a, functionName: c } = N();
561
+ const r = [], { callerInfo: a, functionName: c } = E();
561
562
  r.push(`${t} initialized
562
563
  `), r.push(`Caller Function: ${c}
563
564
  `), r.push(`Caller Location: ${a}
@@ -570,7 +571,7 @@ class m {
570
571
  });
571
572
  }
572
573
  }
573
- class F extends m {
574
+ class P extends m {
574
575
  /**
575
576
  * Creates an instance of the `Created` class.
576
577
  *
@@ -661,7 +662,7 @@ class Y extends m {
661
662
  return Response.json(this.body, s);
662
663
  }
663
664
  }
664
- class P extends m {
665
+ class z extends m {
665
666
  /**
666
667
  * Creates an instance of the `NoContent` class.
667
668
  *
@@ -733,7 +734,7 @@ class M extends m {
733
734
  return Response.json(this.body, s);
734
735
  }
735
736
  }
736
- class z extends m {
737
+ class _ extends m {
737
738
  /**
738
739
  * Creates an instance of the `Updated` class.
739
740
  *
@@ -777,7 +778,7 @@ class z extends m {
777
778
  return Response.json(this.body, s);
778
779
  }
779
780
  }
780
- class _ {
781
+ class V {
781
782
  static mapHeaders(t) {
782
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), {}) : {};
783
784
  }
@@ -802,7 +803,7 @@ class _ {
802
803
  };
803
804
  }
804
805
  }
805
- class U {
806
+ class I {
806
807
  /**
807
808
  * Sets the configuration for the arkyn. This method initializes the arkyn configuration
808
809
  * with the provided `arkynConfig` values. If the configuration has already been set,
@@ -840,9 +841,9 @@ class U {
840
841
  this.arkynConfig = void 0;
841
842
  }
842
843
  }
843
- o(U, "arkynConfig");
844
- async function V(e) {
845
- const t = U.getArkynConfig();
844
+ o(I, "arkynConfig");
845
+ async function G(e) {
846
+ const t = I.getArkynConfig();
846
847
  if (!t) return;
847
848
  const { arkynUserToken: s, arkynApiUrl: n } = t, {
848
849
  elapsedTime: r,
@@ -853,7 +854,7 @@ async function V(e) {
853
854
  responseBody: l,
854
855
  responseHeaders: u,
855
856
  status: d,
856
- token: C,
857
+ token: A,
857
858
  rawUrl: f
858
859
  } = e;
859
860
  if (process.env.NODE_ENV !== "development")
@@ -861,7 +862,7 @@ async function V(e) {
861
862
  const p = new URL(f);
862
863
  let S = "HTTPS";
863
864
  p.protocol === "http:" && (S = "HTTP");
864
- const v = JSON.stringify({
865
+ const w = JSON.stringify({
865
866
  domainUrl: p.protocol + "//" + p.host,
866
867
  pathnameUrl: p.pathname,
867
868
  status: d,
@@ -882,7 +883,7 @@ async function V(e) {
882
883
  ),
883
884
  {
884
885
  method: "POST",
885
- body: v,
886
+ body: w,
886
887
  headers: {
887
888
  "Content-Type": "application/json",
888
889
  Authorization: `Bearer ${s}`
@@ -917,7 +918,7 @@ async function T(e, t, s = {}, n) {
917
918
  } catch {
918
919
  u = null;
919
920
  }
920
- const d = _.handle({
921
+ const d = V.handle({
921
922
  elapsedTime: i,
922
923
  method: e,
923
924
  queryParams: new URL(t).searchParams,
@@ -928,7 +929,7 @@ async function T(e, t, s = {}, n) {
928
929
  status: l,
929
930
  url: t
930
931
  });
931
- return V(d), h.ok ? {
932
+ return G(d), h.ok ? {
932
933
  success: !0,
933
934
  status: l,
934
935
  message: (u == null ? void 0 : u.message) || r[e],
@@ -955,22 +956,22 @@ async function T(e, t, s = {}, n) {
955
956
  };
956
957
  }
957
958
  }
958
- async function G(e, t = {}, s) {
959
+ async function Z(e, t = {}, s) {
959
960
  return T("DELETE", e, t, s);
960
961
  }
961
- async function Z(e, t = {}) {
962
+ async function W(e, t = {}) {
962
963
  return T("GET", e, t);
963
964
  }
964
- async function W(e, t = {}, s) {
965
+ async function K(e, t = {}, s) {
965
966
  return T("PATCH", e, t, s);
966
967
  }
967
- async function K(e, t = {}, s) {
968
+ async function Q(e, t = {}, s) {
968
969
  return T("POST", e, t, s);
969
970
  }
970
- async function Q(e, t = {}, s) {
971
+ async function X(e, t = {}, s) {
971
972
  return T("PUT", e, t, s);
972
973
  }
973
- class Rs {
974
+ class Ss {
974
975
  /**
975
976
  * Creates an instance of ApiService.
976
977
  * @param props - The configuration properties for the API instance.
@@ -1018,7 +1019,7 @@ class Rs {
1018
1019
  */
1019
1020
  async get(t, s) {
1020
1021
  const n = this.generateURL(t), r = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token);
1021
- return this.onDebug(t, "get", [r]), await Z(n, r);
1022
+ return this.onDebug(t, "get", [r]), await W(n, r);
1022
1023
  }
1023
1024
  /**
1024
1025
  * Sends a post request to the specified endpoint.
@@ -1028,7 +1029,7 @@ class Rs {
1028
1029
  */
1029
1030
  async post(t, s) {
1030
1031
  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;
1031
- return this.onDebug(t, "post", [r, a]), await K(n, r, a);
1032
+ return this.onDebug(t, "post", [r, a]), await Q(n, r, a);
1032
1033
  }
1033
1034
  /**
1034
1035
  * Sends a put request to the specified endpoint.
@@ -1038,7 +1039,7 @@ class Rs {
1038
1039
  */
1039
1040
  async put(t, s) {
1040
1041
  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;
1041
- return this.onDebug(t, "put", [r, a]), await Q(n, r, a);
1042
+ return this.onDebug(t, "put", [r, a]), await X(n, r, a);
1042
1043
  }
1043
1044
  /**
1044
1045
  * Sends a patch request to the specified endpoint.
@@ -1048,7 +1049,7 @@ class Rs {
1048
1049
  */
1049
1050
  async patch(t, s) {
1050
1051
  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;
1051
- return this.onDebug(t, "patch", [r, a]), await W(n, r, a);
1052
+ return this.onDebug(t, "patch", [r, a]), await K(n, r, a);
1052
1053
  }
1053
1054
  /**
1054
1055
  * Sends a delete request to the specified endpoint.
@@ -1058,14 +1059,14 @@ class Rs {
1058
1059
  */
1059
1060
  async delete(t, s) {
1060
1061
  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;
1061
- return this.onDebug(t, "delete", [r, a]), await G(n, r, a);
1062
+ return this.onDebug(t, "delete", [r, a]), await Z(n, r, a);
1062
1063
  }
1063
1064
  }
1064
- function Ns(e, t) {
1065
+ function Ds(e, t) {
1065
1066
  var s, n, r;
1066
1067
  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";
1067
1068
  }
1068
- const Ss = async (e) => {
1069
+ const Os = async (e) => {
1069
1070
  let t;
1070
1071
  const s = await e.arrayBuffer(), n = new TextDecoder().decode(s);
1071
1072
  try {
@@ -1076,34 +1077,32 @@ const Ss = async (e) => {
1076
1077
  const a = new URLSearchParams(n);
1077
1078
  t = Object.fromEntries(a.entries());
1078
1079
  } else
1079
- throw new x("Invalid URLSearchParams format");
1080
+ throw new b("Invalid URLSearchParams format");
1080
1081
  } catch {
1081
- throw new x("Failed to extract data from request");
1082
+ throw new b("Failed to extract data from request");
1082
1083
  }
1083
1084
  }
1084
1085
  return t;
1085
1086
  };
1086
- function Es(e) {
1087
+ function $s(e) {
1087
1088
  switch (!0) {
1088
1089
  case e instanceof Response:
1089
1090
  return e;
1090
1091
  case e instanceof Y:
1091
1092
  return e.toResponse();
1092
- case e instanceof F:
1093
+ case e instanceof P:
1093
1094
  return e.toResponse();
1094
- case e instanceof z:
1095
+ case e instanceof _:
1095
1096
  return e.toResponse();
1096
1097
  case e instanceof M:
1097
1098
  return e.toResponse();
1098
- case e instanceof P:
1099
+ case e instanceof z:
1099
1100
  return e.toResponse();
1100
1101
  }
1101
1102
  switch (!0) {
1102
1103
  case e instanceof J:
1103
1104
  return e.toResponse();
1104
- case e instanceof x:
1105
- return e.toResponse();
1106
- case e instanceof j:
1105
+ case e instanceof b:
1107
1106
  return e.toResponse();
1108
1107
  case e instanceof L:
1109
1108
  return e.toResponse();
@@ -1111,16 +1110,38 @@ function Es(e) {
1111
1110
  return e.toResponse();
1112
1111
  case e instanceof H:
1113
1112
  return e.toResponse();
1114
- case e instanceof b:
1115
- return e.toResponse();
1116
1113
  case e instanceof q:
1117
1114
  return e.toResponse();
1118
- case e instanceof O:
1115
+ case e instanceof x:
1116
+ return e.toResponse();
1117
+ case e instanceof F:
1118
+ return e.toResponse();
1119
+ case e instanceof R:
1119
1120
  return e.toResponse();
1120
1121
  }
1121
- return new b("Server error", e).toResponse();
1122
+ return new x("Server error", e).toResponse();
1122
1123
  }
1123
- function X([
1124
+ async function ss([
1125
+ e,
1126
+ t
1127
+ ]) {
1128
+ const s = await t.safeParseAsync(e);
1129
+ if (s.success === !1) {
1130
+ const n = Object.fromEntries(
1131
+ s.error.issues.map((r) => [r.path.join("."), r.message])
1132
+ );
1133
+ return {
1134
+ success: s.success,
1135
+ fieldErrors: n,
1136
+ fields: e
1137
+ };
1138
+ } else
1139
+ return {
1140
+ success: s.success,
1141
+ data: s.data
1142
+ };
1143
+ }
1144
+ function es([
1124
1145
  e,
1125
1146
  t
1126
1147
  ]) {
@@ -1140,7 +1161,7 @@ function X([
1140
1161
  data: s.data
1141
1162
  };
1142
1163
  }
1143
- const Ds = (e, t = "") => {
1164
+ const Is = (e, t = "") => {
1144
1165
  const s = new URL(e.url);
1145
1166
  if (t === "") return s.searchParams;
1146
1167
  const n = Array.from(
@@ -1148,39 +1169,161 @@ const Ds = (e, t = "") => {
1148
1169
  ).filter(([r]) => r.startsWith(`${t}:`)).map(([r, a]) => [r.replace(`${t}:`, ""), a]);
1149
1170
  return new URLSearchParams(n);
1150
1171
  };
1151
- function ss(e) {
1172
+ function ts(e) {
1152
1173
  const t = "Error validating:", s = e.issues.map(
1153
1174
  ({ path: n, message: r }) => `-> ${n.join(".")}: ${r}`
1154
1175
  );
1155
1176
  return [t, ...s].join(`
1156
1177
  `);
1157
1178
  }
1158
- class $s {
1179
+ class As {
1180
+ /**
1181
+ * Creates a new SchemaValidator instance.
1182
+ *
1183
+ * @param {T} schema - The Zod schema to use for validation.
1184
+ */
1159
1185
  constructor(t) {
1160
1186
  o(this, "functionName");
1161
1187
  o(this, "callerInfo");
1162
1188
  this.schema = t;
1163
- const { callerInfo: s, functionName: n } = N();
1189
+ const { callerInfo: s, functionName: n } = E();
1164
1190
  this.callerInfo = s, this.functionName = n;
1165
1191
  }
1192
+ /**
1193
+ * Checks if the provided data is valid according to the schema without throwing errors.
1194
+ *
1195
+ * @param {any} data - The data to validate.
1196
+ *
1197
+ * @returns {boolean} True if the data is valid, false otherwise.
1198
+ *
1199
+ * @example
1200
+ * ```typescript
1201
+ * const validator = new SchemaValidator(userSchema);
1202
+ * const isValid = validator.isValid({ name: "John", email: "invalid-email" });
1203
+ * console.log(isValid); // false
1204
+ * ```
1205
+ */
1166
1206
  isValid(t) {
1167
1207
  return this.schema.safeParse(t).success;
1168
1208
  }
1209
+ /**
1210
+ * Safely validates data and returns the complete parse result without throwing errors.
1211
+ *
1212
+ * @param {any} data - The data to validate.
1213
+ *
1214
+ * @returns {z.ZodSafeParseResult<z.infer<T>>} The Zod safe parse result containing success status and data or error.
1215
+ *
1216
+ * @example
1217
+ * ```typescript
1218
+ * const validator = new SchemaValidator(userSchema);
1219
+ * const result = validator.safeValidate({ name: "", email: "john@example.com" });
1220
+ *
1221
+ * if (result.success) {
1222
+ * console.log(result.data); // Validated data
1223
+ * } else {
1224
+ * console.log(result.error.issues); // Validation errors
1225
+ * }
1226
+ * ```
1227
+ */
1169
1228
  safeValidate(t) {
1170
1229
  return this.schema.safeParse(t);
1171
1230
  }
1231
+ /**
1232
+ * Validates data and returns the parsed result, throwing a ServerError on validation failure.
1233
+ *
1234
+ * @param {any} data - The data to validate.
1235
+ *
1236
+ * @returns {z.infer<T>} The validated and parsed data.
1237
+ *
1238
+ * @throws {ServerError} When validation fails, with a formatted error message.
1239
+ *
1240
+ * @example
1241
+ * ```typescript
1242
+ * const validator = new SchemaValidator(userSchema);
1243
+ *
1244
+ * try {
1245
+ * const validUser = validator.validate({ name: "John", email: "john@example.com", age: 25 });
1246
+ * console.log(validUser); // { name: "John", email: "john@example.com", age: 25 }
1247
+ * } catch (error) {
1248
+ * console.error(error.message); // "Error validating:\n-> name: String must contain at least 1 character(s)"
1249
+ * }
1250
+ * ```
1251
+ */
1172
1252
  validate(t) {
1173
1253
  try {
1174
1254
  return this.schema.parse(t);
1175
1255
  } catch (s) {
1176
- throw new b(ss(s));
1256
+ throw new x(ts(s));
1177
1257
  }
1178
1258
  }
1259
+ /**
1260
+ * Validates form data and returns the parsed result, throwing an UnprocessableEntity error on validation failure.
1261
+ * This method is specifically designed for form validation in web applications.
1262
+ *
1263
+ * @param {any} data - The form data to validate.
1264
+ * @param {string} [message] - Optional custom error message.
1265
+ *
1266
+ * @returns {z.infer<T>} The validated and parsed form data.
1267
+ *
1268
+ * @throws {UnprocessableEntity} When validation fails, with structured field errors for form handling.
1269
+ *
1270
+ * @example
1271
+ * ```typescript
1272
+ * const validator = new SchemaValidator(userSchema);
1273
+ *
1274
+ * try {
1275
+ * const validFormData = validator.formValidate(requestBody, "User data is invalid");
1276
+ * console.log(validFormData);
1277
+ * } catch (error) {
1278
+ * // UnprocessableEntity with fieldErrors, fields, and scrollTo data
1279
+ * console.log(error.fieldErrors); // { name: "Name is required", email: "Invalid email" }
1280
+ * console.log(error.data.scrollTo); // "name" (first error field)
1281
+ * }
1282
+ * ```
1283
+ */
1179
1284
  formValidate(t, s) {
1180
- const n = X([t, this.schema]);
1285
+ const n = es([t, this.schema]);
1286
+ if (!n.success) {
1287
+ const r = Object.keys(n.fieldErrors)[0];
1288
+ throw new R({
1289
+ fields: n.fields,
1290
+ fieldErrors: n.fieldErrors,
1291
+ data: { scrollTo: r },
1292
+ message: s
1293
+ });
1294
+ }
1295
+ return n.data;
1296
+ }
1297
+ /**
1298
+ * Asynchronously validates form data and returns the parsed result, throwing an UnprocessableEntity error on validation failure.
1299
+ * This method is the async version of formValidate, designed for form validation with async schemas.
1300
+ *
1301
+ * @param {any} data - The form data to validate.
1302
+ * @param {string} [message] - Optional custom error message.
1303
+ *
1304
+ * @returns {Promise<z.infer<T>>} A promise that resolves to the validated and parsed form data.
1305
+ *
1306
+ * @throws {UnprocessableEntity} When validation fails, with structured field errors for form handling.
1307
+ *
1308
+ * @example
1309
+ * ```typescript
1310
+ * const validator = new SchemaValidator(userSchemaWithAsyncValidation);
1311
+ *
1312
+ * try {
1313
+ * const validFormData = await validator.formAsyncValidate(requestBody, "User data is invalid");
1314
+ * console.log(validFormData);
1315
+ * } catch (error) {
1316
+ * // UnprocessableEntity with fieldErrors, fields, and scrollTo data
1317
+ * console.log(error.fieldErrors); // { name: "Name is required", email: "Invalid email" }
1318
+ * console.log(error.data.scrollTo); // "name" (first error field)
1319
+ * }
1320
+ * ```
1321
+ */
1322
+ async formAsyncValidate(t, s) {
1323
+ const n = await ss([t, this.schema]);
1181
1324
  if (!n.success) {
1182
1325
  const r = Object.keys(n.fieldErrors)[0];
1183
- throw new O({
1326
+ throw new R({
1184
1327
  fields: n.fields,
1185
1328
  fieldErrors: n.fieldErrors,
1186
1329
  data: { scrollTo: r },
@@ -1190,62 +1333,62 @@ class $s {
1190
1333
  return n.data;
1191
1334
  }
1192
1335
  }
1193
- const Is = (e) => {
1336
+ const ws = (e) => {
1194
1337
  if (!e || !/^[0-9-]+$/.test(e)) return !1;
1195
- const s = R(e), n = 8, r = /^\d{8}$/.test(s);
1338
+ const s = N(e), n = 8, r = /^\d{8}$/.test(s);
1196
1339
  return s.length === n && r;
1197
1340
  };
1198
- function es(e) {
1341
+ function ns(e) {
1199
1342
  return e.length !== 14;
1200
1343
  }
1201
- function ts(e) {
1344
+ function rs(e) {
1202
1345
  const [t] = e;
1203
1346
  return [...e].every((s) => s === t);
1204
1347
  }
1205
- function E(e, t) {
1348
+ function D(e, t) {
1206
1349
  let s = 0;
1207
1350
  for (let r = 0; r < t.length; r++)
1208
1351
  s += parseInt(e[r]) * t[r];
1209
1352
  const n = s % 11;
1210
1353
  return n < 2 ? 0 : 11 - n;
1211
1354
  }
1212
- function ns(e) {
1355
+ function os(e) {
1213
1356
  return e.slice(12);
1214
1357
  }
1215
- const Os = (e) => {
1358
+ const Us = (e) => {
1216
1359
  if (!e) return !1;
1217
- const t = R(e);
1218
- if (es(t) || ts(t)) return !1;
1219
- const s = t.slice(0, 12), n = E(s, [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]), r = E(
1360
+ 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(
1220
1363
  s + n,
1221
1364
  [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
1222
1365
  );
1223
- return ns(t) === `${n}${r}`;
1366
+ return os(t) === `${n}${r}`;
1224
1367
  };
1225
- function rs(e) {
1368
+ function as(e) {
1226
1369
  return e.length !== 11;
1227
1370
  }
1228
- function os(e) {
1371
+ function us(e) {
1229
1372
  const [t] = e;
1230
1373
  return [...e].every((s) => s === t);
1231
1374
  }
1232
- function D(e, t) {
1375
+ function O(e, t) {
1233
1376
  let s = 0;
1234
1377
  for (const r of e)
1235
1378
  t > 1 && (s += parseInt(r) * t--);
1236
1379
  const n = s % 11;
1237
1380
  return n < 2 ? 0 : 11 - n;
1238
1381
  }
1239
- function as(e) {
1382
+ function is(e) {
1240
1383
  return e.slice(9);
1241
1384
  }
1242
- const Us = (e) => {
1385
+ const Cs = (e) => {
1243
1386
  if (!e) return !1;
1244
- const t = R(e);
1245
- if (rs(t) || os(t)) return !1;
1246
- const s = D(t, 10), n = D(t, 11);
1247
- return as(t) === `${s}${n}`;
1248
- }, Cs = (e, t) => {
1387
+ 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) => {
1249
1392
  let s, n, r;
1250
1393
  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;
1251
1394
  if (a === "DD/MM/YYYY") {
@@ -1271,55 +1414,55 @@ const Us = (e) => {
1271
1414
  } else if (i > d[l - 1])
1272
1415
  return !1;
1273
1416
  return u < c || u > h ? !1 : new Date(u, l - 1, i).getDate() === i;
1274
- }, us = $.promises.resolve;
1275
- function is(e) {
1417
+ }, cs = v.promises.resolve;
1418
+ function hs(e) {
1276
1419
  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);
1277
1420
  }
1278
- function cs(e) {
1421
+ function ls(e) {
1279
1422
  return !(e.length === 0 || e.length > 64 || e.startsWith(".") || e.endsWith(".") || e.includes("..") || !/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/.test(e));
1280
1423
  }
1281
- function hs(e) {
1424
+ function fs(e) {
1282
1425
  return !(e.length === 0 || e.length > 63 || e.startsWith("-") || e.endsWith("-") || !/^[a-zA-Z0-9-]+$/.test(e));
1283
1426
  }
1284
- function ls(e) {
1427
+ function ds(e) {
1285
1428
  if (e.length === 0 || e.length > 253 || e.startsWith(".") || e.endsWith(".") || e.startsWith("-") || e.endsWith("-"))
1286
1429
  return !1;
1287
1430
  const t = e.split(".");
1288
1431
  if (t.length < 2) return !1;
1289
- for (const n of t) if (!hs(n)) return !1;
1432
+ for (const n of t) if (!fs(n)) return !1;
1290
1433
  const s = t[t.length - 1];
1291
1434
  return !(s.length < 2 || !/^[a-zA-Z]+$/.test(s));
1292
1435
  }
1293
- function fs(e) {
1436
+ function ys(e) {
1294
1437
  const t = e.split("@");
1295
1438
  if (t.length !== 2) return !1;
1296
1439
  const [s, n] = t;
1297
- return !(!cs(s) || !ls(n));
1440
+ return !(!ls(s) || !ds(n));
1298
1441
  }
1299
- function ds(e) {
1442
+ function ps(e) {
1300
1443
  const t = e.split("@");
1301
1444
  return t.length === 2 ? t[1].toLowerCase() : null;
1302
1445
  }
1303
- const ys = ["MX", "A", "AAAA"];
1304
- async function ps(e, t) {
1446
+ const gs = ["MX", "A", "AAAA"];
1447
+ async function ms(e, t) {
1305
1448
  try {
1306
- return await us(e, t), !0;
1449
+ return await cs(e, t), !0;
1307
1450
  } catch {
1308
1451
  return !1;
1309
1452
  }
1310
1453
  }
1311
- async function gs(e) {
1312
- for (const t of ys)
1313
- if (await ps(e, t)) return !0;
1454
+ async function Ts(e) {
1455
+ for (const t of gs)
1456
+ if (await ms(e, t)) return !0;
1314
1457
  return !1;
1315
1458
  }
1316
- const vs = async (e) => {
1459
+ const js = async (e) => {
1317
1460
  if (!e || typeof e != "string") return !1;
1318
1461
  const t = e.trim();
1319
- if (!is(t) || !fs(t)) return !1;
1320
- const s = ds(t);
1321
- return s ? await gs(s) : !1;
1322
- }, As = (e) => {
1462
+ if (!hs(t) || !ys(t)) return !1;
1463
+ const s = ps(t);
1464
+ return s ? await Ts(s) : !1;
1465
+ }, ks = (e) => {
1323
1466
  if (!e) return !1;
1324
1467
  const t = e.length >= 8, s = /[A-Z]/.test(e), n = /[a-z]/.test(e), r = /\d/.test(e), a = /[!@#$%^&*(),.?":{}|<>_\-+=~`[\]\\\/]/.test(
1325
1468
  e
@@ -1331,8 +1474,8 @@ const vs = async (e) => {
1331
1474
  r,
1332
1475
  a
1333
1476
  ].every((c) => c);
1334
- }, ks = (e) => {
1335
- for (const t of w) {
1477
+ }, Js = (e) => {
1478
+ for (const t of j) {
1336
1479
  const s = t.code, n = t.prefix ? `-${t.prefix}` : "", r = t.mask.replace(/[^_]/g, "").length;
1337
1480
  if (t.iso === "BR") {
1338
1481
  if (new RegExp(`^\\${s} \\d{2}9?\\d{8}$`).test(e)) return !0;
@@ -1341,43 +1484,44 @@ const vs = async (e) => {
1341
1484
  if (new RegExp(`^\\${s}${n} \\d{${r}}$`).test(e)) return !0;
1342
1485
  }
1343
1486
  return !1;
1344
- }, ws = (e) => {
1487
+ }, Ls = (e) => {
1345
1488
  if (!e || !/^[0-9a-zA-Z.-]+$/.test(e)) return !1;
1346
1489
  const s = e.replace(/[^a-zA-Z0-9]/g, "");
1347
1490
  return s.length < 7 || s.length > 9 ? !1 : /^[0-9]{7,8}[0-9Xx]?$/.test(s);
1348
1491
  };
1349
1492
  export {
1350
- Rs as ApiService,
1351
- U as ArkynLogService,
1493
+ Ss as ApiService,
1494
+ I as ArkynLogService,
1352
1495
  J as BadGateway,
1353
- x as BadRequest,
1354
- j as Conflict,
1355
- F as Created,
1356
- I as DebugService,
1357
- L as Forbidden,
1496
+ b as BadRequest,
1497
+ L as Conflict,
1498
+ P as Created,
1499
+ $ as DebugService,
1500
+ B as Forbidden,
1358
1501
  Y as Found,
1359
- P as NoContent,
1360
- B as NotFound,
1361
- H as NotImplemented,
1362
- $s as SchemaValidator,
1363
- b as ServerError,
1502
+ z as NoContent,
1503
+ H as NotFound,
1504
+ q as NotImplemented,
1505
+ As as SchemaValidator,
1506
+ x as ServerError,
1364
1507
  M as Success,
1365
- q as Unauthorized,
1366
- O as UnprocessableEntity,
1367
- z as Updated,
1368
- Ns as decodeErrorMessageFromRequest,
1369
- Ss as decodeRequestBody,
1370
- Es as errorHandler,
1508
+ F as Unauthorized,
1509
+ R as UnprocessableEntity,
1510
+ _ as Updated,
1511
+ Ds as decodeErrorMessageFromRequest,
1512
+ Os as decodeRequestBody,
1513
+ $s as errorHandler,
1371
1514
  g as flushDebugLogs,
1372
- X as formParse,
1373
- N as getCaller,
1374
- Ds as getScopedParams,
1375
- Is as validateCep,
1376
- Os as validateCnpj,
1377
- Us as validateCpf,
1378
- Cs as validateDate,
1379
- vs as validateEmail,
1380
- As as validatePassword,
1381
- ks as validatePhone,
1382
- ws as validateRg
1515
+ ss as formAsyncParse,
1516
+ es as formParse,
1517
+ 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
1383
1527
  };