@arkyn/server 3.0.1-beta.75 → 3.0.1-beta.76
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 +125 -124
- package/dist/bundle.umd.cjs +5 -5
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var o = (e, t, s) =>
|
|
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;
|
|
3
|
+
var o = (e, t, s) => A(e, typeof t != "symbol" ? t + "" : t, s);
|
|
4
4
|
import "zod";
|
|
5
5
|
import { removeNonNumeric as R } from "@arkyn/shared";
|
|
6
|
+
import k from "node:dns";
|
|
6
7
|
import { countries as w } from "@arkyn/templates";
|
|
7
8
|
function g(e) {
|
|
8
9
|
var s;
|
|
@@ -21,8 +22,8 @@ function g(e) {
|
|
|
21
22
|
}), console.log(c);
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
|
-
const
|
|
25
|
-
class
|
|
25
|
+
const J = {};
|
|
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(
|
|
65
|
+
o($, "ignoreFiles", []);
|
|
65
66
|
function N() {
|
|
66
67
|
const e = process.cwd(), n = (new Error().stack || "").split(`
|
|
67
|
-
`).map((u) => u.trim()), r =
|
|
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,7 +92,7 @@ function N() {
|
|
|
91
92
|
i.lastIndexOf(")")
|
|
92
93
|
)), i = i.split(":").slice(0, -2).join(":");
|
|
93
94
|
try {
|
|
94
|
-
i =
|
|
95
|
+
i = J.relative(e, i);
|
|
95
96
|
} catch {
|
|
96
97
|
}
|
|
97
98
|
return { functionName: h, callerInfo: i };
|
|
@@ -102,7 +103,7 @@ class y {
|
|
|
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
|
}
|
|
105
|
-
class
|
|
106
|
+
class j extends y {
|
|
106
107
|
/**
|
|
107
108
|
* Creates an instance of the `BadGateway` class.
|
|
108
109
|
*
|
|
@@ -198,7 +199,7 @@ class x extends y {
|
|
|
198
199
|
return Response.json(this.body, s);
|
|
199
200
|
}
|
|
200
201
|
}
|
|
201
|
-
class
|
|
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
|
|
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
|
|
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
|
|
346
|
+
class q extends y {
|
|
346
347
|
/**
|
|
347
348
|
* Creates an instance of the `NotImplemented` class.
|
|
348
349
|
*
|
|
@@ -438,7 +439,7 @@ class b extends y {
|
|
|
438
439
|
return Response.json(this.body, s);
|
|
439
440
|
}
|
|
440
441
|
}
|
|
441
|
-
class
|
|
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
|
|
490
|
+
class I extends y {
|
|
490
491
|
/**
|
|
491
492
|
* Creates an instance of the `UnprocessableEntity` class.
|
|
492
493
|
*
|
|
@@ -570,7 +571,7 @@ class m {
|
|
|
570
571
|
});
|
|
571
572
|
}
|
|
572
573
|
}
|
|
573
|
-
class
|
|
574
|
+
class Y extends m {
|
|
574
575
|
/**
|
|
575
576
|
* Creates an instance of the `Created` class.
|
|
576
577
|
*
|
|
@@ -614,7 +615,7 @@ class F extends m {
|
|
|
614
615
|
return Response.json(this.body, s);
|
|
615
616
|
}
|
|
616
617
|
}
|
|
617
|
-
class
|
|
618
|
+
class P extends m {
|
|
618
619
|
/**
|
|
619
620
|
* Creates an instance of the `Found` class.
|
|
620
621
|
*
|
|
@@ -661,7 +662,7 @@ class Y extends m {
|
|
|
661
662
|
return Response.json(this.body, s);
|
|
662
663
|
}
|
|
663
664
|
}
|
|
664
|
-
class
|
|
665
|
+
class M extends m {
|
|
665
666
|
/**
|
|
666
667
|
* Creates an instance of the `NoContent` class.
|
|
667
668
|
*
|
|
@@ -689,7 +690,7 @@ class P extends m {
|
|
|
689
690
|
return new Response(null, s);
|
|
690
691
|
}
|
|
691
692
|
}
|
|
692
|
-
class
|
|
693
|
+
class z extends m {
|
|
693
694
|
/**
|
|
694
695
|
* Creates an instance of the `Success` class.
|
|
695
696
|
*
|
|
@@ -733,7 +734,7 @@ class M extends m {
|
|
|
733
734
|
return Response.json(this.body, s);
|
|
734
735
|
}
|
|
735
736
|
}
|
|
736
|
-
class
|
|
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
|
|
806
|
+
class O {
|
|
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(
|
|
844
|
-
async function
|
|
845
|
-
const t =
|
|
844
|
+
o(O, "arkynConfig");
|
|
845
|
+
async function G(e) {
|
|
846
|
+
const t = O.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:
|
|
857
|
+
token: U,
|
|
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
|
|
865
|
+
const C = 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:
|
|
886
|
+
body: C,
|
|
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 =
|
|
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
|
|
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
|
|
959
|
+
async function Z(e, t = {}, s) {
|
|
959
960
|
return T("DELETE", e, t, s);
|
|
960
961
|
}
|
|
961
|
-
async function
|
|
962
|
+
async function W(e, t = {}) {
|
|
962
963
|
return T("GET", e, t);
|
|
963
964
|
}
|
|
964
|
-
async function
|
|
965
|
+
async function K(e, t = {}, s) {
|
|
965
966
|
return T("PATCH", e, t, s);
|
|
966
967
|
}
|
|
967
|
-
async function
|
|
968
|
+
async function Q(e, t = {}, s) {
|
|
968
969
|
return T("POST", e, t, s);
|
|
969
970
|
}
|
|
970
|
-
async function
|
|
971
|
+
async function X(e, t = {}, s) {
|
|
971
972
|
return T("PUT", e, t, s);
|
|
972
973
|
}
|
|
973
|
-
class
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
1062
|
+
return this.onDebug(t, "delete", [r, a]), await Z(n, r, a);
|
|
1062
1063
|
}
|
|
1063
1064
|
}
|
|
1064
|
-
function
|
|
1065
|
+
function Es(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
|
|
1069
|
+
const Ds = async (e) => {
|
|
1069
1070
|
let t;
|
|
1070
1071
|
const s = await e.arrayBuffer(), n = new TextDecoder().decode(s);
|
|
1071
1072
|
try {
|
|
@@ -1083,44 +1084,44 @@ const Ss = async (e) => {
|
|
|
1083
1084
|
}
|
|
1084
1085
|
return t;
|
|
1085
1086
|
};
|
|
1086
|
-
function
|
|
1087
|
+
function $s(e) {
|
|
1087
1088
|
switch (!0) {
|
|
1088
1089
|
case e instanceof Response:
|
|
1089
1090
|
return e;
|
|
1091
|
+
case e instanceof P:
|
|
1092
|
+
return e.toResponse();
|
|
1090
1093
|
case e instanceof Y:
|
|
1091
1094
|
return e.toResponse();
|
|
1092
|
-
case e instanceof
|
|
1095
|
+
case e instanceof _:
|
|
1093
1096
|
return e.toResponse();
|
|
1094
1097
|
case e instanceof z:
|
|
1095
1098
|
return e.toResponse();
|
|
1096
1099
|
case e instanceof M:
|
|
1097
1100
|
return e.toResponse();
|
|
1098
|
-
case e instanceof P:
|
|
1099
|
-
return e.toResponse();
|
|
1100
1101
|
}
|
|
1101
1102
|
switch (!0) {
|
|
1102
|
-
case e instanceof
|
|
1103
|
+
case e instanceof j:
|
|
1103
1104
|
return e.toResponse();
|
|
1104
1105
|
case e instanceof x:
|
|
1105
1106
|
return e.toResponse();
|
|
1106
|
-
case e instanceof j:
|
|
1107
|
-
return e.toResponse();
|
|
1108
1107
|
case e instanceof L:
|
|
1109
1108
|
return e.toResponse();
|
|
1110
1109
|
case e instanceof B:
|
|
1111
1110
|
return e.toResponse();
|
|
1112
1111
|
case e instanceof H:
|
|
1113
1112
|
return e.toResponse();
|
|
1113
|
+
case e instanceof q:
|
|
1114
|
+
return e.toResponse();
|
|
1114
1115
|
case e instanceof b:
|
|
1115
1116
|
return e.toResponse();
|
|
1116
|
-
case e instanceof
|
|
1117
|
+
case e instanceof F:
|
|
1117
1118
|
return e.toResponse();
|
|
1118
|
-
case e instanceof
|
|
1119
|
+
case e instanceof I:
|
|
1119
1120
|
return e.toResponse();
|
|
1120
1121
|
}
|
|
1121
1122
|
return new b("Server error", e).toResponse();
|
|
1122
1123
|
}
|
|
1123
|
-
function
|
|
1124
|
+
function ss([
|
|
1124
1125
|
e,
|
|
1125
1126
|
t
|
|
1126
1127
|
]) {
|
|
@@ -1140,7 +1141,7 @@ function X([
|
|
|
1140
1141
|
data: s.data
|
|
1141
1142
|
};
|
|
1142
1143
|
}
|
|
1143
|
-
const
|
|
1144
|
+
const Is = (e, t = "") => {
|
|
1144
1145
|
const s = new URL(e.url);
|
|
1145
1146
|
if (t === "") return s.searchParams;
|
|
1146
1147
|
const n = Array.from(
|
|
@@ -1148,14 +1149,14 @@ const Ds = (e, t = "") => {
|
|
|
1148
1149
|
).filter(([r]) => r.startsWith(`${t}:`)).map(([r, a]) => [r.replace(`${t}:`, ""), a]);
|
|
1149
1150
|
return new URLSearchParams(n);
|
|
1150
1151
|
};
|
|
1151
|
-
function
|
|
1152
|
+
function es(e) {
|
|
1152
1153
|
const t = "Error validating:", s = e.issues.map(
|
|
1153
1154
|
({ path: n, message: r }) => `-> ${n.join(".")}: ${r}`
|
|
1154
1155
|
);
|
|
1155
1156
|
return [t, ...s].join(`
|
|
1156
1157
|
`);
|
|
1157
1158
|
}
|
|
1158
|
-
class
|
|
1159
|
+
class Os {
|
|
1159
1160
|
constructor(t) {
|
|
1160
1161
|
o(this, "functionName");
|
|
1161
1162
|
o(this, "callerInfo");
|
|
@@ -1173,14 +1174,14 @@ class $s {
|
|
|
1173
1174
|
try {
|
|
1174
1175
|
return this.schema.parse(t);
|
|
1175
1176
|
} catch (s) {
|
|
1176
|
-
throw new b(
|
|
1177
|
+
throw new b(es(s));
|
|
1177
1178
|
}
|
|
1178
1179
|
}
|
|
1179
1180
|
formValidate(t, s) {
|
|
1180
|
-
const n =
|
|
1181
|
+
const n = ss([t, this.schema]);
|
|
1181
1182
|
if (!n.success) {
|
|
1182
1183
|
const r = Object.keys(n.fieldErrors)[0];
|
|
1183
|
-
throw new
|
|
1184
|
+
throw new I({
|
|
1184
1185
|
fields: n.fields,
|
|
1185
1186
|
fieldErrors: n.fieldErrors,
|
|
1186
1187
|
data: { scrollTo: r },
|
|
@@ -1190,15 +1191,15 @@ class $s {
|
|
|
1190
1191
|
return n.data;
|
|
1191
1192
|
}
|
|
1192
1193
|
}
|
|
1193
|
-
const
|
|
1194
|
+
const Us = (e) => {
|
|
1194
1195
|
if (!e || !/^[0-9-]+$/.test(e)) return !1;
|
|
1195
1196
|
const s = R(e), n = 8, r = /^\d{8}$/.test(s);
|
|
1196
1197
|
return s.length === n && r;
|
|
1197
1198
|
};
|
|
1198
|
-
function
|
|
1199
|
+
function ts(e) {
|
|
1199
1200
|
return e.length !== 14;
|
|
1200
1201
|
}
|
|
1201
|
-
function
|
|
1202
|
+
function ns(e) {
|
|
1202
1203
|
const [t] = e;
|
|
1203
1204
|
return [...e].every((s) => s === t);
|
|
1204
1205
|
}
|
|
@@ -1209,23 +1210,23 @@ function E(e, t) {
|
|
|
1209
1210
|
const n = s % 11;
|
|
1210
1211
|
return n < 2 ? 0 : 11 - n;
|
|
1211
1212
|
}
|
|
1212
|
-
function
|
|
1213
|
+
function rs(e) {
|
|
1213
1214
|
return e.slice(12);
|
|
1214
1215
|
}
|
|
1215
|
-
const
|
|
1216
|
+
const Cs = (e) => {
|
|
1216
1217
|
if (!e) return !1;
|
|
1217
1218
|
const t = R(e);
|
|
1218
|
-
if (
|
|
1219
|
+
if (ts(t) || ns(t)) return !1;
|
|
1219
1220
|
const s = t.slice(0, 12), n = E(s, [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]), r = E(
|
|
1220
1221
|
s + n,
|
|
1221
1222
|
[6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
|
|
1222
1223
|
);
|
|
1223
|
-
return
|
|
1224
|
+
return rs(t) === `${n}${r}`;
|
|
1224
1225
|
};
|
|
1225
|
-
function
|
|
1226
|
+
function os(e) {
|
|
1226
1227
|
return e.length !== 11;
|
|
1227
1228
|
}
|
|
1228
|
-
function
|
|
1229
|
+
function as(e) {
|
|
1229
1230
|
const [t] = e;
|
|
1230
1231
|
return [...e].every((s) => s === t);
|
|
1231
1232
|
}
|
|
@@ -1236,16 +1237,16 @@ function D(e, t) {
|
|
|
1236
1237
|
const n = s % 11;
|
|
1237
1238
|
return n < 2 ? 0 : 11 - n;
|
|
1238
1239
|
}
|
|
1239
|
-
function
|
|
1240
|
+
function us(e) {
|
|
1240
1241
|
return e.slice(9);
|
|
1241
1242
|
}
|
|
1242
|
-
const
|
|
1243
|
+
const vs = (e) => {
|
|
1243
1244
|
if (!e) return !1;
|
|
1244
1245
|
const t = R(e);
|
|
1245
|
-
if (
|
|
1246
|
+
if (os(t) || as(t)) return !1;
|
|
1246
1247
|
const s = D(t, 10), n = D(t, 11);
|
|
1247
|
-
return
|
|
1248
|
-
},
|
|
1248
|
+
return us(t) === `${s}${n}`;
|
|
1249
|
+
}, As = (e, t) => {
|
|
1249
1250
|
let s, n, r;
|
|
1250
1251
|
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
1252
|
if (a === "DD/MM/YYYY") {
|
|
@@ -1271,55 +1272,55 @@ const Us = (e) => {
|
|
|
1271
1272
|
} else if (i > d[l - 1])
|
|
1272
1273
|
return !1;
|
|
1273
1274
|
return u < c || u > h ? !1 : new Date(u, l - 1, i).getDate() === i;
|
|
1274
|
-
},
|
|
1275
|
-
function
|
|
1275
|
+
}, is = k.promises.resolve;
|
|
1276
|
+
function cs(e) {
|
|
1276
1277
|
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
1278
|
}
|
|
1278
|
-
function
|
|
1279
|
+
function hs(e) {
|
|
1279
1280
|
return !(e.length === 0 || e.length > 64 || e.startsWith(".") || e.endsWith(".") || e.includes("..") || !/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/.test(e));
|
|
1280
1281
|
}
|
|
1281
|
-
function
|
|
1282
|
+
function ls(e) {
|
|
1282
1283
|
return !(e.length === 0 || e.length > 63 || e.startsWith("-") || e.endsWith("-") || !/^[a-zA-Z0-9-]+$/.test(e));
|
|
1283
1284
|
}
|
|
1284
|
-
function
|
|
1285
|
+
function fs(e) {
|
|
1285
1286
|
if (e.length === 0 || e.length > 253 || e.startsWith(".") || e.endsWith(".") || e.startsWith("-") || e.endsWith("-"))
|
|
1286
1287
|
return !1;
|
|
1287
1288
|
const t = e.split(".");
|
|
1288
1289
|
if (t.length < 2) return !1;
|
|
1289
|
-
for (const n of t) if (!
|
|
1290
|
+
for (const n of t) if (!ls(n)) return !1;
|
|
1290
1291
|
const s = t[t.length - 1];
|
|
1291
1292
|
return !(s.length < 2 || !/^[a-zA-Z]+$/.test(s));
|
|
1292
1293
|
}
|
|
1293
|
-
function
|
|
1294
|
+
function ds(e) {
|
|
1294
1295
|
const t = e.split("@");
|
|
1295
1296
|
if (t.length !== 2) return !1;
|
|
1296
1297
|
const [s, n] = t;
|
|
1297
|
-
return !(!
|
|
1298
|
+
return !(!hs(s) || !fs(n));
|
|
1298
1299
|
}
|
|
1299
|
-
function
|
|
1300
|
+
function ys(e) {
|
|
1300
1301
|
const t = e.split("@");
|
|
1301
1302
|
return t.length === 2 ? t[1].toLowerCase() : null;
|
|
1302
1303
|
}
|
|
1303
|
-
const
|
|
1304
|
-
async function
|
|
1304
|
+
const ps = ["MX", "A", "AAAA"];
|
|
1305
|
+
async function gs(e, t) {
|
|
1305
1306
|
try {
|
|
1306
|
-
return await
|
|
1307
|
+
return await is(e, t), !0;
|
|
1307
1308
|
} catch {
|
|
1308
1309
|
return !1;
|
|
1309
1310
|
}
|
|
1310
1311
|
}
|
|
1311
|
-
async function
|
|
1312
|
-
for (const t of
|
|
1313
|
-
if (await
|
|
1312
|
+
async function ms(e) {
|
|
1313
|
+
for (const t of ps)
|
|
1314
|
+
if (await gs(e, t)) return !0;
|
|
1314
1315
|
return !1;
|
|
1315
1316
|
}
|
|
1316
|
-
const
|
|
1317
|
+
const ks = async (e) => {
|
|
1317
1318
|
if (!e || typeof e != "string") return !1;
|
|
1318
1319
|
const t = e.trim();
|
|
1319
|
-
if (!
|
|
1320
|
-
const s =
|
|
1321
|
-
return s ? await
|
|
1322
|
-
},
|
|
1320
|
+
if (!cs(t) || !ds(t)) return !1;
|
|
1321
|
+
const s = ys(t);
|
|
1322
|
+
return s ? await ms(s) : !1;
|
|
1323
|
+
}, ws = (e) => {
|
|
1323
1324
|
if (!e) return !1;
|
|
1324
1325
|
const t = e.length >= 8, s = /[A-Z]/.test(e), n = /[a-z]/.test(e), r = /\d/.test(e), a = /[!@#$%^&*(),.?":{}|<>_\-+=~`[\]\\\/]/.test(
|
|
1325
1326
|
e
|
|
@@ -1331,7 +1332,7 @@ const vs = async (e) => {
|
|
|
1331
1332
|
r,
|
|
1332
1333
|
a
|
|
1333
1334
|
].every((c) => c);
|
|
1334
|
-
},
|
|
1335
|
+
}, Js = (e) => {
|
|
1335
1336
|
for (const t of w) {
|
|
1336
1337
|
const s = t.code, n = t.prefix ? `-${t.prefix}` : "", r = t.mask.replace(/[^_]/g, "").length;
|
|
1337
1338
|
if (t.iso === "BR") {
|
|
@@ -1341,43 +1342,43 @@ const vs = async (e) => {
|
|
|
1341
1342
|
if (new RegExp(`^\\${s}${n} \\d{${r}}$`).test(e)) return !0;
|
|
1342
1343
|
}
|
|
1343
1344
|
return !1;
|
|
1344
|
-
},
|
|
1345
|
+
}, js = (e) => {
|
|
1345
1346
|
if (!e || !/^[0-9a-zA-Z.-]+$/.test(e)) return !1;
|
|
1346
1347
|
const s = e.replace(/[^a-zA-Z0-9]/g, "");
|
|
1347
1348
|
return s.length < 7 || s.length > 9 ? !1 : /^[0-9]{7,8}[0-9Xx]?$/.test(s);
|
|
1348
1349
|
};
|
|
1349
1350
|
export {
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1351
|
+
Ss as ApiService,
|
|
1352
|
+
O as ArkynLogService,
|
|
1353
|
+
j as BadGateway,
|
|
1353
1354
|
x as BadRequest,
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1355
|
+
L as Conflict,
|
|
1356
|
+
Y as Created,
|
|
1357
|
+
$ as DebugService,
|
|
1358
|
+
B as Forbidden,
|
|
1359
|
+
P as Found,
|
|
1360
|
+
M as NoContent,
|
|
1361
|
+
H as NotFound,
|
|
1362
|
+
q as NotImplemented,
|
|
1363
|
+
Os as SchemaValidator,
|
|
1363
1364
|
b as ServerError,
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
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,
|
|
1371
1372
|
g as flushDebugLogs,
|
|
1372
|
-
|
|
1373
|
+
ss as formParse,
|
|
1373
1374
|
N as getCaller,
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
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
|
|
1383
1384
|
};
|
package/dist/bundle.umd.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
(function(u,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("zod"),require("@arkyn/shared"),require("@arkyn/templates")):typeof define=="function"&&define.amd?define(["exports","zod","@arkyn/shared","@arkyn/templates"],d):(u=typeof globalThis<"u"?globalThis:u||self,d(u["@arkyn/server"]={},null,u.shared,u.templates))})(this,function(u,d,m,M){"use strict";var
|
|
1
|
+
(function(u,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):(u=typeof globalThis<"u"?globalThis:u||self,d(u["@arkyn/server"]={},null,u.shared,u.dns,u.templates))})(this,function(u,d,m,z,M){"use strict";var ks=Object.defineProperty;var As=(u,d,m)=>d in u?ks(u,d,{enumerable:!0,configurable:!0,writable:!0,value:m}):u[d]=m;var o=(u,d,m)=>As(u,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 a=`${{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+=`${a} ${l.trim()}
|
|
3
|
-
`}),console.log(h)}}const
|
|
4
|
-
`).map(i=>i.trim()),r=D.ignoreFiles;let a=2;for(;a<n.length&&(n[a].includes("node:internal")||n[a].includes("/node_modules/"));)a++;if(r.length>0)for(;a<n.length&&r.some(i=>n[a].includes(i));)a++;const h=n[a]||"";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
|
|
3
|
+
`}),console.log(h)}}const Y={};class D{static setIgnoreFile(t){this.ignoreFiles.push(t)}static clearIgnoreFiles(){this.ignoreFiles=[]}}o(D,"ignoreFiles",[]);function N(){const e=process.cwd(),n=(new Error().stack||"").split(`
|
|
4
|
+
`).map(i=>i.trim()),r=D.ignoreFiles;let a=2;for(;a<n.length&&(n[a].includes("node:internal")||n[a].includes("/node_modules/"));)a++;if(r.length>0)for(;a<n.length&&r.some(i=>n[a].includes(i));)a++;const h=n[a]||"";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=Y.relative(e,c)}catch{}return{functionName:l,callerInfo:c}}class p{onDebug(t){const{name:s,body:n,cause:r,message:a}=t,h=[],{callerInfo:l,functionName:c}=N();h.push(`${s} initialized`),h.push(`Caller Function: ${c}`),h.push(`Caller Location: ${l}`),a&&h.push(`Message: ${a}`),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 $ 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 C 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 O 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 U 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 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 v 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:a,functionName:h}=N();r.push(`${t} initialized
|
|
5
5
|
`),r.push(`Caller Function: ${h}
|
|
6
6
|
`),r.push(`Caller Location: ${a}
|
|
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
|
|
10
|
-
`)}class
|
|
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 _{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 I{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(I,"arkynConfig");async function V(e){const t=I.getArkynConfig();if(!t)return;const{arkynUserToken:s,arkynApiUrl:n}=t,{elapsedTime:r,method:a,queryParams:h,requestBody:l,requestHeaders:c,responseBody:f,responseHeaders:i,status:g,token:Os,rawUrl:y}=e;if(process.env.NODE_ENV!=="development")try{const b=new URL(y);let P="HTTPS";b.protocol==="http:"&&(P="HTTP");const Us=JSON.stringify({domainUrl:b.protocol+"//"+b.host,pathnameUrl:b.pathname,status:g,protocol:P,method:a,trafficUserId:null,elapsedTime:r,requestHeaders:c,requestBody:l,queryParams:h,responseHeaders:i,responseBody:f});await fetch(n.replace(":trafficSourceId",t.arkynTrafficSourceId),{method:"POST",body:Us,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 a=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()-a,f=l.status;let i=null;try{i=await l.json()}catch{i=null}const 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 V(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(a){return T({debugs:[`Network error or request failed: ${a}`],name:"ARKYN_MAKE_REQUEST_ERROR",scheme:"red"}),{success:!1,status:0,message:"Network error or request failed",response:null,cause:a instanceof Error?a.message:String(a)}}}async function G(e,t={},s){return x("DELETE",e,t,s)}async function Z(e,t={}){return x("GET",e,t)}async function W(e,t={},s){return x("PATCH",e,t,s)}async function K(e,t={},s){return x("POST",e,t,s)}async function Q(e,t={},s){return x("PUT",e,t,s)}class X{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 Z(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),a=s==null?void 0:s.body;return this.onDebug(t,"post",[r,a]),await K(n,r,a)}async put(t,s){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;return this.onDebug(t,"put",[r,a]),await Q(n,r,a)}async patch(t,s){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;return this.onDebug(t,"patch",[r,a]),await W(n,r,a)}async delete(t,s){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;return this.onDebug(t,"delete",[r,a]),await G(n,r,a)}}function ss(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 es=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 a=new URLSearchParams(n);t=Object.fromEntries(a.entries())}else throw new S("Invalid URLSearchParams format")}catch{throw new S("Failed to extract data from request")}}return t};function ts(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 $:return e.toResponse();case e instanceof S:return e.toResponse();case e instanceof C:return e.toResponse();case e instanceof O:return e.toResponse();case e instanceof U:return e.toResponse();case e instanceof k:return e.toResponse();case e instanceof E:return e.toResponse();case e instanceof A:return e.toResponse();case e instanceof v:return e.toResponse()}return new E("Server error",e).toResponse()}function q([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 ns=(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,a])=>[r.replace(`${t}:`,""),a]);return new URLSearchParams(n)};function rs(e){const t="Error validating:",s=e.issues.map(({path:n,message:r})=>`-> ${n.join(".")}: ${r}`);return[t,...s].join(`
|
|
10
|
+
`)}class os{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(rs(s))}}formValidate(t,s){const n=q([t,this.schema]);if(!n.success){const r=Object.keys(n.fieldErrors)[0];throw new v({fields:n.fields,fieldErrors:n.fieldErrors,data:{scrollTo:r},message:s})}return n.data}}const as=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 us(e){return e.length!==14}function is(e){const[t]=e;return[...e].every(s=>s===t)}function F(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 cs(e){return e.slice(12)}const hs=e=>{if(!e)return!1;const t=m.removeNonNumeric(e);if(us(t)||is(t))return!1;const s=t.slice(0,12),n=F(s,[5,4,3,2,9,8,7,6,5,4,3,2]),r=F(s+n,[6,5,4,3,2,9,8,7,6,5,4,3,2]);return cs(t)===`${n}${r}`};function ls(e){return e.length!==11}function fs(e){const[t]=e;return[...e].every(s=>s===t)}function H(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 ds(e){return e.slice(9)}const ys=e=>{if(!e)return!1;const t=m.removeNonNumeric(e);if(ls(t)||fs(t))return!1;const s=H(t,10),n=H(t,11);return ds(t)===`${s}${n}`},ps=(e,t)=>{let s,n,r;const a=(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(a==="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(a==="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(a==="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},gs=z.promises.resolve;function ms(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 Ts(e){return!(e.length===0||e.length>64||e.startsWith(".")||e.endsWith(".")||e.includes("..")||!/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/.test(e))}function bs(e){return!(e.length===0||e.length>63||e.startsWith("-")||e.endsWith("-")||!/^[a-zA-Z0-9-]+$/.test(e))}function Rs(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(!bs(n))return!1;const s=t[t.length-1];return!(s.length<2||!/^[a-zA-Z]+$/.test(s))}function xs(e){const t=e.split("@");if(t.length!==2)return!1;const[s,n]=t;return!(!Ts(s)||!Rs(n))}function Ns(e){const t=e.split("@");return t.length===2?t[1].toLowerCase():null}const Ss=["MX","A","AAAA"];async function Es(e,t){try{return await gs(e,t),!0}catch{return!1}}async function Ds(e){for(const t of Ss)if(await Es(e,t))return!0;return!1}const vs=async e=>{if(!e||typeof e!="string")return!1;const t=e.trim();if(!ms(t)||!xs(t))return!1;const s=Ns(t);return s?await Ds(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),a=/[!@#$%^&*(),.?":{}|<>_\-+=~`[\]\\\/]/.test(e);return[t,s,n,r,a].every(h=>h)},$s=e=>{for(const t of M.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)};u.ApiService=X,u.ArkynLogService=I,u.BadGateway=$,u.BadRequest=S,u.Conflict=C,u.Created=w,u.DebugService=D,u.Forbidden=O,u.Found=j,u.NoContent=J,u.NotFound=U,u.NotImplemented=k,u.SchemaValidator=os,u.ServerError=E,u.Success=L,u.Unauthorized=A,u.UnprocessableEntity=v,u.Updated=B,u.decodeErrorMessageFromRequest=ss,u.decodeRequestBody=es,u.errorHandler=ts,u.flushDebugLogs=T,u.formParse=q,u.getCaller=N,u.getScopedParams=ns,u.validateCep=as,u.validateCnpj=hs,u.validateCpf=ys,u.validateDate=ps,u.validateEmail=vs,u.validatePassword=Is,u.validatePhone=$s,u.validateRg=Cs,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|