@arkyn/server 3.0.1-beta.83 → 3.0.1-beta.84
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/api/arkynLogRequest.d.ts.map +1 -1
- package/dist/api/arkynLogRequest.js +3 -4
- package/dist/bundle.js +140 -139
- package/dist/bundle.umd.cjs +4 -4
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arkynLogRequest.d.ts","sourceRoot":"","sources":["../../src/api/arkynLogRequest.ts"],"names":[],"mappings":"AAGA,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,iBAAe,eAAe,CAAC,MAAM,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"arkynLogRequest.d.ts","sourceRoot":"","sources":["../../src/api/arkynLogRequest.ts"],"names":[],"mappings":"AAGA,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,iBAAe,eAAe,CAAC,MAAM,EAAE,WAAW,iBAyDjD;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -46,7 +46,8 @@ async function arkynLogRequest(config) {
|
|
|
46
46
|
return;
|
|
47
47
|
const { userToken, apiUrl, trafficSourceId } = arkynService;
|
|
48
48
|
const { elapsedTime, method, queryParams, requestBody, requestHeaders, responseBody, responseHeaders, status, token, rawUrl, } = config;
|
|
49
|
-
|
|
49
|
+
if (process.env.NODE_ENV === "development")
|
|
50
|
+
return;
|
|
50
51
|
try {
|
|
51
52
|
const url = new URL(rawUrl);
|
|
52
53
|
let protocol = "https";
|
|
@@ -67,7 +68,7 @@ async function arkynLogRequest(config) {
|
|
|
67
68
|
responseHeaders: JSON.stringify(responseHeaders),
|
|
68
69
|
responseBody: JSON.stringify(responseBody),
|
|
69
70
|
});
|
|
70
|
-
|
|
71
|
+
await fetch(apiUrl, {
|
|
71
72
|
method: "POST",
|
|
72
73
|
body,
|
|
73
74
|
headers: {
|
|
@@ -75,10 +76,8 @@ async function arkynLogRequest(config) {
|
|
|
75
76
|
Authorization: `Bearer ${userToken}`,
|
|
76
77
|
},
|
|
77
78
|
});
|
|
78
|
-
console.log(await data.json());
|
|
79
79
|
}
|
|
80
80
|
catch (err) {
|
|
81
|
-
console.log(err);
|
|
82
81
|
flushDebugLogs({
|
|
83
82
|
debugs: [`Error sending request: ${err}`],
|
|
84
83
|
name: "ARKYN_LOG_ERROR",
|
package/dist/bundle.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
2
|
-
var v = (e, t, s) => t in e ?
|
|
1
|
+
var w = Object.defineProperty;
|
|
2
|
+
var v = (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) => v(e, typeof t != "symbol" ? t + "" : t, s);
|
|
4
4
|
import "zod";
|
|
5
5
|
import { removeNonNumeric as N } from "@arkyn/shared";
|
|
6
6
|
import "node:dns";
|
|
7
|
-
import { countries as
|
|
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,7 +22,7 @@ function g(e) {
|
|
|
22
22
|
}), console.log(c);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
const
|
|
25
|
+
const A = {};
|
|
26
26
|
class I {
|
|
27
27
|
/**
|
|
28
28
|
* Sets the file name to be ignored during stack trace analysis.
|
|
@@ -92,18 +92,18 @@ function E() {
|
|
|
92
92
|
i.lastIndexOf(")")
|
|
93
93
|
)), i = i.split(":").slice(0, -2).join(":");
|
|
94
94
|
try {
|
|
95
|
-
i =
|
|
95
|
+
i = A.relative(e, i);
|
|
96
96
|
} catch {
|
|
97
97
|
}
|
|
98
98
|
return { functionName: h, callerInfo: i };
|
|
99
99
|
}
|
|
100
|
-
class
|
|
100
|
+
class p {
|
|
101
101
|
onDebug(t) {
|
|
102
102
|
const { name: s, body: n, cause: r, message: a } = t, c = [], { callerInfo: h, functionName: i } = E();
|
|
103
103
|
c.push(`${s} initialized`), c.push(`Caller Function: ${i}`), c.push(`Caller Location: ${h}`), a && c.push(`Message: ${a}`), n && c.push(`Body: ${JSON.stringify(n, null, 2)}`), r && c.push(`Cause: ${JSON.stringify(r, null, 2)}`), g({ scheme: "red", name: "ARKYN-BAD-RESPONSE-DEBUG", debugs: c });
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
class
|
|
106
|
+
class L extends p {
|
|
107
107
|
/**
|
|
108
108
|
* Creates an instance of the `BadGateway` class.
|
|
109
109
|
*
|
|
@@ -151,7 +151,7 @@ class B extends y {
|
|
|
151
151
|
return Response.json(this.body, s);
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
-
class x extends
|
|
154
|
+
class x 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
|
|
202
|
+
class B extends p {
|
|
203
203
|
/**
|
|
204
204
|
* Creates an instance of the `Conflict` class.
|
|
205
205
|
*
|
|
@@ -247,7 +247,7 @@ class k extends y {
|
|
|
247
247
|
return Response.json(this.body, s);
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
|
-
class
|
|
250
|
+
class k extends p {
|
|
251
251
|
/**
|
|
252
252
|
* Creates an instance of the `Forbidden` class.
|
|
253
253
|
*
|
|
@@ -295,7 +295,7 @@ class q extends y {
|
|
|
295
295
|
return Response.json(this.body, s);
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
|
-
class
|
|
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
|
|
346
|
+
class H extends p {
|
|
347
347
|
/**
|
|
348
348
|
* Creates an instance of the `NotImplemented` class.
|
|
349
349
|
*
|
|
@@ -391,7 +391,7 @@ class F extends y {
|
|
|
391
391
|
return Response.json(this.body, s);
|
|
392
392
|
}
|
|
393
393
|
}
|
|
394
|
-
class T extends
|
|
394
|
+
class T extends p {
|
|
395
395
|
/**
|
|
396
396
|
* Creates an instance of the `ServerError` class.
|
|
397
397
|
*
|
|
@@ -439,7 +439,7 @@ class T extends y {
|
|
|
439
439
|
return Response.json(this.body, s);
|
|
440
440
|
}
|
|
441
441
|
}
|
|
442
|
-
class
|
|
442
|
+
class F extends p {
|
|
443
443
|
/**
|
|
444
444
|
* Creates an instance of the `Unauthorized` class.
|
|
445
445
|
*
|
|
@@ -487,7 +487,7 @@ class P extends y {
|
|
|
487
487
|
return Response.json(this.body, s);
|
|
488
488
|
}
|
|
489
489
|
}
|
|
490
|
-
class R extends
|
|
490
|
+
class R extends p {
|
|
491
491
|
/**
|
|
492
492
|
* Creates an instance of the `UnprocessableEntity` class.
|
|
493
493
|
*
|
|
@@ -571,7 +571,7 @@ class m {
|
|
|
571
571
|
});
|
|
572
572
|
}
|
|
573
573
|
}
|
|
574
|
-
class
|
|
574
|
+
class P extends m {
|
|
575
575
|
/**
|
|
576
576
|
* Creates an instance of the `Created` class.
|
|
577
577
|
*
|
|
@@ -615,7 +615,7 @@ class Y extends m {
|
|
|
615
615
|
return Response.json(this.body, s);
|
|
616
616
|
}
|
|
617
617
|
}
|
|
618
|
-
class
|
|
618
|
+
class Y extends m {
|
|
619
619
|
/**
|
|
620
620
|
* Creates an instance of the `Found` class.
|
|
621
621
|
*
|
|
@@ -662,7 +662,7 @@ class z extends m {
|
|
|
662
662
|
return Response.json(this.body, s);
|
|
663
663
|
}
|
|
664
664
|
}
|
|
665
|
-
class
|
|
665
|
+
class z extends m {
|
|
666
666
|
/**
|
|
667
667
|
* Creates an instance of the `NoContent` class.
|
|
668
668
|
*
|
|
@@ -690,7 +690,7 @@ class M extends m {
|
|
|
690
690
|
return new Response(null, s);
|
|
691
691
|
}
|
|
692
692
|
}
|
|
693
|
-
class
|
|
693
|
+
class M extends m {
|
|
694
694
|
/**
|
|
695
695
|
* Creates an instance of the `Success` class.
|
|
696
696
|
*
|
|
@@ -734,7 +734,7 @@ class _ extends m {
|
|
|
734
734
|
return Response.json(this.body, s);
|
|
735
735
|
}
|
|
736
736
|
}
|
|
737
|
-
class
|
|
737
|
+
class _ extends m {
|
|
738
738
|
/**
|
|
739
739
|
* Creates an instance of the `Updated` class.
|
|
740
740
|
*
|
|
@@ -778,7 +778,7 @@ class V extends m {
|
|
|
778
778
|
return Response.json(this.body, s);
|
|
779
779
|
}
|
|
780
780
|
}
|
|
781
|
-
class
|
|
781
|
+
class V {
|
|
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
|
}
|
|
@@ -842,7 +842,7 @@ class C {
|
|
|
842
842
|
}
|
|
843
843
|
}
|
|
844
844
|
o(C, "arkynConfig");
|
|
845
|
-
async function
|
|
845
|
+
async function G(e) {
|
|
846
846
|
const t = C.getArkynConfig();
|
|
847
847
|
if (!t) return;
|
|
848
848
|
const { userToken: s, apiUrl: n, trafficSourceId: r } = t, {
|
|
@@ -857,40 +857,41 @@ async function Z(e) {
|
|
|
857
857
|
token: f,
|
|
858
858
|
rawUrl: J
|
|
859
859
|
} = e;
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
860
|
+
if (process.env.NODE_ENV !== "development")
|
|
861
|
+
try {
|
|
862
|
+
const y = new URL(J);
|
|
863
|
+
let O = "https";
|
|
864
|
+
y.protocol === "http:" && (O = "http");
|
|
865
|
+
const j = JSON.stringify({
|
|
866
|
+
domainUrl: y.protocol + "//" + y.host,
|
|
867
|
+
pathnameUrl: y.pathname,
|
|
868
|
+
trafficSourceId: r,
|
|
869
|
+
status: S,
|
|
870
|
+
protocol: O,
|
|
871
|
+
method: c.toLowerCase(),
|
|
872
|
+
trafficUserId: null,
|
|
873
|
+
elapsedTime: a,
|
|
874
|
+
requestHeaders: JSON.stringify(l),
|
|
875
|
+
requestBody: JSON.stringify(i),
|
|
876
|
+
queryParams: JSON.stringify(h),
|
|
877
|
+
responseHeaders: JSON.stringify(d),
|
|
878
|
+
responseBody: JSON.stringify(u)
|
|
879
|
+
});
|
|
880
|
+
await fetch(n, {
|
|
881
|
+
method: "POST",
|
|
882
|
+
body: j,
|
|
883
|
+
headers: {
|
|
884
|
+
"Content-Type": "application/json",
|
|
885
|
+
Authorization: `Bearer ${s}`
|
|
886
|
+
}
|
|
887
|
+
});
|
|
888
|
+
} catch (y) {
|
|
889
|
+
g({
|
|
890
|
+
debugs: [`Error sending request: ${y}`],
|
|
891
|
+
name: "ARKYN_LOG_ERROR",
|
|
892
|
+
scheme: "red"
|
|
893
|
+
});
|
|
894
|
+
}
|
|
894
895
|
}
|
|
895
896
|
async function b(e, t, s = {}, n) {
|
|
896
897
|
const r = {
|
|
@@ -912,7 +913,7 @@ async function b(e, t, s = {}, n) {
|
|
|
912
913
|
} catch {
|
|
913
914
|
u = null;
|
|
914
915
|
}
|
|
915
|
-
const d =
|
|
916
|
+
const d = V.handle({
|
|
916
917
|
elapsedTime: i,
|
|
917
918
|
method: e,
|
|
918
919
|
queryParams: new URL(t).searchParams,
|
|
@@ -923,7 +924,7 @@ async function b(e, t, s = {}, n) {
|
|
|
923
924
|
status: l,
|
|
924
925
|
url: t
|
|
925
926
|
});
|
|
926
|
-
return
|
|
927
|
+
return G(d), h.ok ? {
|
|
927
928
|
success: !0,
|
|
928
929
|
status: l,
|
|
929
930
|
message: (u == null ? void 0 : u.message) || r[e],
|
|
@@ -950,22 +951,22 @@ async function b(e, t, s = {}, n) {
|
|
|
950
951
|
};
|
|
951
952
|
}
|
|
952
953
|
}
|
|
953
|
-
async function
|
|
954
|
+
async function Z(e, t = {}, s) {
|
|
954
955
|
return b("DELETE", e, t, s);
|
|
955
956
|
}
|
|
956
|
-
async function
|
|
957
|
+
async function W(e, t = {}) {
|
|
957
958
|
return b("GET", e, t);
|
|
958
959
|
}
|
|
959
|
-
async function
|
|
960
|
+
async function K(e, t = {}, s) {
|
|
960
961
|
return b("PATCH", e, t, s);
|
|
961
962
|
}
|
|
962
|
-
async function
|
|
963
|
+
async function Q(e, t = {}, s) {
|
|
963
964
|
return b("POST", e, t, s);
|
|
964
965
|
}
|
|
965
|
-
async function
|
|
966
|
+
async function X(e, t = {}, s) {
|
|
966
967
|
return b("PUT", e, t, s);
|
|
967
968
|
}
|
|
968
|
-
class
|
|
969
|
+
class Ts {
|
|
969
970
|
/**
|
|
970
971
|
* Creates an instance of ApiService.
|
|
971
972
|
* @param props - The configuration properties for the API instance.
|
|
@@ -1013,7 +1014,7 @@ class Rs {
|
|
|
1013
1014
|
*/
|
|
1014
1015
|
async get(t, s) {
|
|
1015
1016
|
const n = this.generateURL(t), r = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token);
|
|
1016
|
-
return this.onDebug(t, "get", [r]), await
|
|
1017
|
+
return this.onDebug(t, "get", [r]), await W(n, r);
|
|
1017
1018
|
}
|
|
1018
1019
|
/**
|
|
1019
1020
|
* Sends a post request to the specified endpoint.
|
|
@@ -1023,7 +1024,7 @@ class Rs {
|
|
|
1023
1024
|
*/
|
|
1024
1025
|
async post(t, s) {
|
|
1025
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;
|
|
1026
|
-
return this.onDebug(t, "post", [r, a]), await
|
|
1027
|
+
return this.onDebug(t, "post", [r, a]), await Q(n, r, a);
|
|
1027
1028
|
}
|
|
1028
1029
|
/**
|
|
1029
1030
|
* Sends a put request to the specified endpoint.
|
|
@@ -1033,7 +1034,7 @@ class Rs {
|
|
|
1033
1034
|
*/
|
|
1034
1035
|
async put(t, s) {
|
|
1035
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;
|
|
1036
|
-
return this.onDebug(t, "put", [r, a]), await
|
|
1037
|
+
return this.onDebug(t, "put", [r, a]), await X(n, r, a);
|
|
1037
1038
|
}
|
|
1038
1039
|
/**
|
|
1039
1040
|
* Sends a patch request to the specified endpoint.
|
|
@@ -1043,7 +1044,7 @@ class Rs {
|
|
|
1043
1044
|
*/
|
|
1044
1045
|
async patch(t, s) {
|
|
1045
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;
|
|
1046
|
-
return this.onDebug(t, "patch", [r, a]), await
|
|
1047
|
+
return this.onDebug(t, "patch", [r, a]), await K(n, r, a);
|
|
1047
1048
|
}
|
|
1048
1049
|
/**
|
|
1049
1050
|
* Sends a delete request to the specified endpoint.
|
|
@@ -1053,14 +1054,14 @@ class Rs {
|
|
|
1053
1054
|
*/
|
|
1054
1055
|
async delete(t, s) {
|
|
1055
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;
|
|
1056
|
-
return this.onDebug(t, "delete", [r, a]), await
|
|
1057
|
+
return this.onDebug(t, "delete", [r, a]), await Z(n, r, a);
|
|
1057
1058
|
}
|
|
1058
1059
|
}
|
|
1059
|
-
function
|
|
1060
|
+
function Rs(e, t) {
|
|
1060
1061
|
var s, n, r;
|
|
1061
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";
|
|
1062
1063
|
}
|
|
1063
|
-
const
|
|
1064
|
+
const Ns = async (e) => {
|
|
1064
1065
|
let t;
|
|
1065
1066
|
const s = await e.arrayBuffer(), n = new TextDecoder().decode(s);
|
|
1066
1067
|
try {
|
|
@@ -1078,44 +1079,44 @@ const Es = async (e) => {
|
|
|
1078
1079
|
}
|
|
1079
1080
|
return t;
|
|
1080
1081
|
};
|
|
1081
|
-
function
|
|
1082
|
+
function Es(e) {
|
|
1082
1083
|
switch (!0) {
|
|
1083
1084
|
case e instanceof Response:
|
|
1084
1085
|
return e;
|
|
1085
|
-
case e instanceof z:
|
|
1086
|
-
return e.toResponse();
|
|
1087
1086
|
case e instanceof Y:
|
|
1088
1087
|
return e.toResponse();
|
|
1089
|
-
case e instanceof
|
|
1088
|
+
case e instanceof P:
|
|
1090
1089
|
return e.toResponse();
|
|
1091
1090
|
case e instanceof _:
|
|
1092
1091
|
return e.toResponse();
|
|
1093
1092
|
case e instanceof M:
|
|
1094
1093
|
return e.toResponse();
|
|
1094
|
+
case e instanceof z:
|
|
1095
|
+
return e.toResponse();
|
|
1095
1096
|
}
|
|
1096
1097
|
switch (!0) {
|
|
1097
|
-
case e instanceof
|
|
1098
|
+
case e instanceof L:
|
|
1098
1099
|
return e.toResponse();
|
|
1099
1100
|
case e instanceof x:
|
|
1100
1101
|
return e.toResponse();
|
|
1102
|
+
case e instanceof B:
|
|
1103
|
+
return e.toResponse();
|
|
1101
1104
|
case e instanceof k:
|
|
1102
1105
|
return e.toResponse();
|
|
1103
1106
|
case e instanceof q:
|
|
1104
1107
|
return e.toResponse();
|
|
1105
1108
|
case e instanceof H:
|
|
1106
1109
|
return e.toResponse();
|
|
1107
|
-
case e instanceof F:
|
|
1108
|
-
return e.toResponse();
|
|
1109
1110
|
case e instanceof T:
|
|
1110
1111
|
return e.toResponse();
|
|
1111
|
-
case e instanceof
|
|
1112
|
+
case e instanceof F:
|
|
1112
1113
|
return e.toResponse();
|
|
1113
1114
|
case e instanceof R:
|
|
1114
1115
|
return e.toResponse();
|
|
1115
1116
|
}
|
|
1116
1117
|
return new T("Server error", e).toResponse();
|
|
1117
1118
|
}
|
|
1118
|
-
async function
|
|
1119
|
+
async function ss([
|
|
1119
1120
|
e,
|
|
1120
1121
|
t
|
|
1121
1122
|
]) {
|
|
@@ -1135,7 +1136,7 @@ async function es([
|
|
|
1135
1136
|
data: s.data
|
|
1136
1137
|
};
|
|
1137
1138
|
}
|
|
1138
|
-
function
|
|
1139
|
+
function es([
|
|
1139
1140
|
e,
|
|
1140
1141
|
t
|
|
1141
1142
|
]) {
|
|
@@ -1155,7 +1156,7 @@ function ts([
|
|
|
1155
1156
|
data: s.data
|
|
1156
1157
|
};
|
|
1157
1158
|
}
|
|
1158
|
-
const
|
|
1159
|
+
const Ss = (e, t = "") => {
|
|
1159
1160
|
const s = new URL(e.url);
|
|
1160
1161
|
if (t === "") return s.searchParams;
|
|
1161
1162
|
const n = Array.from(
|
|
@@ -1163,14 +1164,14 @@ const Os = (e, t = "") => {
|
|
|
1163
1164
|
).filter(([r]) => r.startsWith(`${t}:`)).map(([r, a]) => [r.replace(`${t}:`, ""), a]);
|
|
1164
1165
|
return new URLSearchParams(n);
|
|
1165
1166
|
};
|
|
1166
|
-
function
|
|
1167
|
+
function ts(e) {
|
|
1167
1168
|
const t = "Error validating:", s = e.issues.map(
|
|
1168
1169
|
({ path: n, message: r }) => `-> ${n.join(".")}: ${r}`
|
|
1169
1170
|
);
|
|
1170
1171
|
return [t, ...s].join(`
|
|
1171
1172
|
`);
|
|
1172
1173
|
}
|
|
1173
|
-
class
|
|
1174
|
+
class Os {
|
|
1174
1175
|
/**
|
|
1175
1176
|
* Creates a new SchemaValidator instance.
|
|
1176
1177
|
*
|
|
@@ -1247,7 +1248,7 @@ class Ds {
|
|
|
1247
1248
|
try {
|
|
1248
1249
|
return this.schema.parse(t);
|
|
1249
1250
|
} catch (s) {
|
|
1250
|
-
throw new T(
|
|
1251
|
+
throw new T(ts(s));
|
|
1251
1252
|
}
|
|
1252
1253
|
}
|
|
1253
1254
|
/**
|
|
@@ -1276,7 +1277,7 @@ class Ds {
|
|
|
1276
1277
|
* ```
|
|
1277
1278
|
*/
|
|
1278
1279
|
formValidate(t, s) {
|
|
1279
|
-
const n =
|
|
1280
|
+
const n = es([t, this.schema]);
|
|
1280
1281
|
if (!n.success) {
|
|
1281
1282
|
const r = Object.keys(n.fieldErrors)[0];
|
|
1282
1283
|
throw new R({
|
|
@@ -1314,7 +1315,7 @@ class Ds {
|
|
|
1314
1315
|
* ```
|
|
1315
1316
|
*/
|
|
1316
1317
|
async formAsyncValidate(t, s) {
|
|
1317
|
-
const n = await
|
|
1318
|
+
const n = await ss([t, this.schema]);
|
|
1318
1319
|
if (!n.success) {
|
|
1319
1320
|
const r = Object.keys(n.fieldErrors)[0];
|
|
1320
1321
|
throw new R({
|
|
@@ -1327,15 +1328,15 @@ class Ds {
|
|
|
1327
1328
|
return n.data;
|
|
1328
1329
|
}
|
|
1329
1330
|
}
|
|
1330
|
-
const
|
|
1331
|
+
const Ds = (e) => {
|
|
1331
1332
|
if (!e || !/^[0-9-]+$/.test(e)) return !1;
|
|
1332
1333
|
const s = N(e), n = 8, r = /^\d{8}$/.test(s);
|
|
1333
1334
|
return s.length === n && r;
|
|
1334
1335
|
};
|
|
1335
|
-
function
|
|
1336
|
+
function ns(e) {
|
|
1336
1337
|
return e.length !== 14;
|
|
1337
1338
|
}
|
|
1338
|
-
function
|
|
1339
|
+
function rs(e) {
|
|
1339
1340
|
const [t] = e;
|
|
1340
1341
|
return [...e].every((s) => s === t);
|
|
1341
1342
|
}
|
|
@@ -1346,23 +1347,23 @@ function D(e, t) {
|
|
|
1346
1347
|
const n = s % 11;
|
|
1347
1348
|
return n < 2 ? 0 : 11 - n;
|
|
1348
1349
|
}
|
|
1349
|
-
function
|
|
1350
|
+
function os(e) {
|
|
1350
1351
|
return e.slice(12);
|
|
1351
1352
|
}
|
|
1352
|
-
const
|
|
1353
|
+
const $s = (e) => {
|
|
1353
1354
|
if (!e) return !1;
|
|
1354
1355
|
const t = N(e);
|
|
1355
|
-
if (
|
|
1356
|
+
if (ns(t) || rs(t)) return !1;
|
|
1356
1357
|
const s = t.slice(0, 12), n = D(s, [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]), r = D(
|
|
1357
1358
|
s + n,
|
|
1358
1359
|
[6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
|
|
1359
1360
|
);
|
|
1360
|
-
return
|
|
1361
|
+
return os(t) === `${n}${r}`;
|
|
1361
1362
|
};
|
|
1362
|
-
function
|
|
1363
|
+
function as(e) {
|
|
1363
1364
|
return e.length !== 11;
|
|
1364
1365
|
}
|
|
1365
|
-
function
|
|
1366
|
+
function us(e) {
|
|
1366
1367
|
const [t] = e;
|
|
1367
1368
|
return [...e].every((s) => s === t);
|
|
1368
1369
|
}
|
|
@@ -1373,16 +1374,16 @@ function $(e, t) {
|
|
|
1373
1374
|
const n = s % 11;
|
|
1374
1375
|
return n < 2 ? 0 : 11 - n;
|
|
1375
1376
|
}
|
|
1376
|
-
function
|
|
1377
|
+
function is(e) {
|
|
1377
1378
|
return e.slice(9);
|
|
1378
1379
|
}
|
|
1379
|
-
const
|
|
1380
|
+
const Is = (e) => {
|
|
1380
1381
|
if (!e) return !1;
|
|
1381
1382
|
const t = N(e);
|
|
1382
|
-
if (
|
|
1383
|
+
if (as(t) || us(t)) return !1;
|
|
1383
1384
|
const s = $(t, 10), n = $(t, 11);
|
|
1384
|
-
return
|
|
1385
|
-
},
|
|
1385
|
+
return is(t) === `${s}${n}`;
|
|
1386
|
+
}, Cs = (e, t) => {
|
|
1386
1387
|
let s, n, r;
|
|
1387
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;
|
|
1388
1389
|
if (a === "DD/MM/YYYY") {
|
|
@@ -1409,39 +1410,39 @@ const Cs = (e) => {
|
|
|
1409
1410
|
return !1;
|
|
1410
1411
|
return u < c || u > h ? !1 : new Date(u, l - 1, i).getDate() === i;
|
|
1411
1412
|
};
|
|
1412
|
-
function
|
|
1413
|
+
function cs(e) {
|
|
1413
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);
|
|
1414
1415
|
}
|
|
1415
|
-
function
|
|
1416
|
+
function hs(e) {
|
|
1416
1417
|
return !(e.length === 0 || e.length > 64 || e.startsWith(".") || e.endsWith(".") || e.includes("..") || !/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/.test(e));
|
|
1417
1418
|
}
|
|
1418
|
-
function
|
|
1419
|
+
function ls(e) {
|
|
1419
1420
|
return !(e.length === 0 || e.length > 63 || e.startsWith("-") || e.endsWith("-") || !/^[a-zA-Z0-9-]+$/.test(e));
|
|
1420
1421
|
}
|
|
1421
|
-
function
|
|
1422
|
+
function fs(e) {
|
|
1422
1423
|
if (e.length === 0 || e.length > 253 || e.startsWith(".") || e.endsWith(".") || e.startsWith("-") || e.endsWith("-"))
|
|
1423
1424
|
return !1;
|
|
1424
1425
|
const t = e.split(".");
|
|
1425
1426
|
if (t.length < 2) return !1;
|
|
1426
|
-
for (const n of t) if (!
|
|
1427
|
+
for (const n of t) if (!ls(n)) return !1;
|
|
1427
1428
|
const s = t[t.length - 1];
|
|
1428
1429
|
return !(s.length < 2 || !/^[a-zA-Z]+$/.test(s));
|
|
1429
1430
|
}
|
|
1430
|
-
function
|
|
1431
|
+
function ds(e) {
|
|
1431
1432
|
const t = e.split("@");
|
|
1432
1433
|
if (t.length !== 2) return !1;
|
|
1433
1434
|
const [s, n] = t;
|
|
1434
|
-
return !(!
|
|
1435
|
+
return !(!hs(s) || !fs(n));
|
|
1435
1436
|
}
|
|
1436
1437
|
function ps(e) {
|
|
1437
1438
|
const t = e.split("@");
|
|
1438
1439
|
return t.length === 2 ? t[1].toLowerCase() : null;
|
|
1439
1440
|
}
|
|
1440
|
-
const
|
|
1441
|
+
const Js = async (e) => {
|
|
1441
1442
|
if (!e || typeof e != "string") return !1;
|
|
1442
1443
|
const t = e.trim();
|
|
1443
|
-
return !(!
|
|
1444
|
-
},
|
|
1444
|
+
return !(!cs(t) || !ds(t) || !ps(t));
|
|
1445
|
+
}, js = (e) => {
|
|
1445
1446
|
if (!e) return !1;
|
|
1446
1447
|
const t = e.length >= 8, s = /[A-Z]/.test(e), n = /[a-z]/.test(e), r = /\d/.test(e), a = /[!@#$%^&*(),.?":{}|<>_\-+=~`[\]\\\/]/.test(
|
|
1447
1448
|
e
|
|
@@ -1453,8 +1454,8 @@ const js = async (e) => {
|
|
|
1453
1454
|
r,
|
|
1454
1455
|
a
|
|
1455
1456
|
].every((c) => c);
|
|
1456
|
-
},
|
|
1457
|
-
for (const t of
|
|
1457
|
+
}, ws = (e) => {
|
|
1458
|
+
for (const t of U) {
|
|
1458
1459
|
const s = t.code, n = t.prefix ? `-${t.prefix}` : "", r = t.mask.replace(/[^_]/g, "").length;
|
|
1459
1460
|
if (t.iso === "BR") {
|
|
1460
1461
|
if (new RegExp(`^\\${s} \\d{2}9?\\d{8}$`).test(e)) return !0;
|
|
@@ -1469,38 +1470,38 @@ const js = async (e) => {
|
|
|
1469
1470
|
return s.length < 7 || s.length > 9 ? !1 : /^[0-9]{7,8}[0-9Xx]?$/.test(s);
|
|
1470
1471
|
};
|
|
1471
1472
|
export {
|
|
1472
|
-
|
|
1473
|
+
Ts as ApiService,
|
|
1473
1474
|
C as ArkynLogService,
|
|
1474
|
-
|
|
1475
|
+
L as BadGateway,
|
|
1475
1476
|
x as BadRequest,
|
|
1476
|
-
|
|
1477
|
-
|
|
1477
|
+
B as Conflict,
|
|
1478
|
+
P as Created,
|
|
1478
1479
|
I as DebugService,
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1480
|
+
k as Forbidden,
|
|
1481
|
+
Y as Found,
|
|
1482
|
+
z as NoContent,
|
|
1483
|
+
q as NotFound,
|
|
1484
|
+
H as NotImplemented,
|
|
1485
|
+
Os as SchemaValidator,
|
|
1485
1486
|
T as ServerError,
|
|
1486
|
-
|
|
1487
|
-
|
|
1487
|
+
M as Success,
|
|
1488
|
+
F as Unauthorized,
|
|
1488
1489
|
R as UnprocessableEntity,
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1490
|
+
_ as Updated,
|
|
1491
|
+
Rs as decodeErrorMessageFromRequest,
|
|
1492
|
+
Ns as decodeRequestBody,
|
|
1493
|
+
Es as errorHandler,
|
|
1493
1494
|
g as flushDebugLogs,
|
|
1494
|
-
|
|
1495
|
-
|
|
1495
|
+
ss as formAsyncParse,
|
|
1496
|
+
es as formParse,
|
|
1496
1497
|
E as getCaller,
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1498
|
+
Ss as getScopedParams,
|
|
1499
|
+
Ds as validateCep,
|
|
1500
|
+
$s as validateCnpj,
|
|
1501
|
+
Is as validateCpf,
|
|
1502
|
+
Cs as validateDate,
|
|
1503
|
+
Js as validateEmail,
|
|
1504
|
+
js as validatePassword,
|
|
1505
|
+
ws as validatePhone,
|
|
1505
1506
|
vs as validateRg
|
|
1506
1507
|
};
|
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("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,null,u.templates))})(this,function(u,d,m,
|
|
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,null,u.templates))})(this,function(u,d,m,js,Y){"use strict";var $s=Object.defineProperty;var Is=(u,d,m)=>d in u?$s(u,d,{enumerable:!0,configurable:!0,writable:!0,value:m}):u[d]=m;var o=(u,d,m)=>Is(u,typeof d!="symbol"?d+"":d,m);function b(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
3
|
`}),console.log(h)}}const _={};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
|
|
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=_.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)}`),b({scheme:"red",name:"ARKYN-BAD-RESPONSE-DEBUG",debugs:h})}}class C extends p{constructor(s,n){super();o(this,"body");o(this,"cause");o(this,"status",502);o(this,"statusText");this.body={name:"BadGateway",message:s},this.statusText=s,this.cause=n?JSON.stringify(n):void 0,this.onDebug({name:"BadGateway",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class S extends p{constructor(s,n){super();o(this,"body");o(this,"cause");o(this,"status",400);o(this,"statusText");this.body={name:"BadRequest",message:s},this.statusText=s,this.cause=n?JSON.stringify(n):void 0,this.onDebug({name:"BadRequest",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class $ extends p{constructor(s,n){super();o(this,"body");o(this,"cause");o(this,"status",409);o(this,"statusText");this.body={name:"Conflict",message:s},this.statusText=s,this.cause=n?JSON.stringify(n):void 0,this.onDebug({name:"Conflict",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class I extends p{constructor(s,n){super();o(this,"body");o(this,"cause");o(this,"status",403);o(this,"statusText");this.body={name:"Forbidden",message:s},this.statusText=s,this.cause=n?JSON.stringify(n):void 0,this.onDebug({name:"Forbidden",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class j extends p{constructor(s,n){super();o(this,"body");o(this,"cause");o(this,"status",404);o(this,"statusText");this.body={name:"NotFound",message:s},this.statusText=s,this.cause=n?JSON.stringify(n):void 0,this.onDebug({name:"NotFound",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class J 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 w 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 O 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 U extends R{constructor(s,n){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(n==null?void 0:n.headers)||{},this.status=(n==null?void 0:n.status)||201,this.statusText=(n==null?void 0:n.statusText)||"Resource created successfully",this.onDebug("Created",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class A 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 q 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 k extends R{constructor(s,n){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(n==null?void 0:n.headers)||{},this.status=(n==null?void 0:n.status)||200,this.statusText=(n==null?void 0:n.statusText)??"OK",this.onDebug("Success",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class B extends R{constructor(s,n){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(n==null?void 0:n.headers)||{},this.status=(n==null?void 0:n.status)||200,this.statusText=(n==null?void 0:n.statusText)||"Resource updated successfully",this.onDebug("Updated",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class V{static mapHeaders(t){return t instanceof Headers?Object.fromEntries(t.entries()):typeof t=="object"?Object.entries(t).reduce((s,[n,r])=>(typeof r=="string"?s[n]=r:Array.isArray(r)?s[n]=r.join(", "):s[n]=JSON.stringify(r),s),{}):{}}static mapQueryParams(t){const s={};return t.forEach((n,r)=>{s[r]=n}),s}static handle(t){return{rawUrl:t.url,status:t.status,method:t.method,token:null,elapsedTime:t.elapsedTime,requestHeaders:this.mapHeaders(t.requestHeaders),requestBody:t.requestBody||null,queryParams:this.mapQueryParams(t.queryParams),responseHeaders:this.mapHeaders(t.responseHeaders),responseBody:t.responseBody||null}}}class v{static setArkynConfig(t){if(this.arkynConfig)return;const{trafficSourceId:s,userToken:n,logBaseApiUrl:r}=t;this.arkynConfig={trafficSourceId:s,userToken:n,apiUrl:r||"http://95.216.190.158:8081/ingest-log"}}static getArkynConfig(){return this.arkynConfig}static resetArkynConfig(){this.arkynConfig=void 0}}o(v,"arkynConfig");async function G(e){const t=v.getArkynConfig();if(!t)return;const{userToken:s,apiUrl:n,trafficSourceId:r}=t,{elapsedTime:a,method:h,queryParams:l,requestBody:c,requestHeaders:f,responseBody:i,responseHeaders:p,status:z,token:y,rawUrl:vs}=e;try{const b=new URL(vs);let M="https";b.protocol==="http:"&&(M="http");const Cs=JSON.stringify({domainUrl:b.protocol+"//"+b.host,pathnameUrl:b.pathname,trafficSourceId:r,status:z,protocol:M,method:h.toLowerCase(),trafficUserId:null,elapsedTime:a,requestHeaders:JSON.stringify(f),requestBody:JSON.stringify(c),queryParams:JSON.stringify(l),responseHeaders:JSON.stringify(p),responseBody:JSON.stringify(i)}),$s=await fetch(n,{method:"POST",body:Cs,headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`}});console.log(await $s.json())}catch(b){console.log(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 p=V.handle({elapsedTime:c,method:e,queryParams:new URL(t).searchParams,requestHeaders:h,requestBody:n,responseBody:i,responseHeaders:l.headers,status:f,url:t});return G(p),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 Z(e,t={},s){return x("DELETE",e,t,s)}async function W(e,t={}){return x("GET",e,t)}async function K(e,t={},s){return x("PATCH",e,t,s)}async function Q(e,t={},s){return x("POST",e,t,s)}async function X(e,t={},s){return x("PUT",e,t,s)}class ss{constructor(t){o(this,"baseUrl");o(this,"baseHeaders");o(this,"baseToken");o(this,"enableDebug");this.baseUrl=t.baseUrl,this.baseHeaders=t.baseHeaders||void 0,this.baseToken=t.baseToken||void 0,this.enableDebug=t.enableDebug||!1}onDebug(t,s,n){if(this.enableDebug){const r=[];r.push(`Base URL: ${this.baseUrl}`),r.push(`Endpoint: ${t}`),r.push(`Method: ${s}`),n[0]&&r.push(`Headers: ${JSON.stringify(n[0])}`),n[1]&&r.push(`Body: ${JSON.stringify(n[1])}`),T({debugs:r,name:"ARKYN-API-DEBUG",scheme:"yellow"})}}generateURL(t){return this.baseUrl+t}generateHeaders(t,s){let n={};return this.baseToken&&(n={Authorization:`Bearer ${this.baseToken}`}),this.baseHeaders&&(n={...n,...this.baseHeaders}),t&&(n={...n,...t}),s&&(n={...n,Authorization:`Bearer ${s}`}),n}async get(t,s){const n=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token);return this.onDebug(t,"get",[r]),await W(n,r)}async post(t,s){const n=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),a=s==null?void 0:s.body;return this.onDebug(t,"post",[r,a]),await Q(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 X(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 K(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 Z(n,r,a)}}function es(e,t){var s,n,r;return e!=null&&e.message&&typeof(e==null?void 0:e.message)=="string"?e==null?void 0:e.message:e!=null&&e.error&&typeof(e==null?void 0:e.error)=="string"?e==null?void 0:e.error:(s=e==null?void 0:e.error)!=null&&s.message&&typeof((n=e==null?void 0:e.error)==null?void 0:n.message)=="string"?(r=e==null?void 0:e.error)==null?void 0:r.message:t!=null&&t.statusText&&typeof(t==null?void 0:t.statusText)=="string"?t==null?void 0:t.statusText:"Missing error message"}const ts=async e=>{let t;const s=await e.arrayBuffer(),n=new TextDecoder().decode(s);try{t=JSON.parse(n)}catch{try{if(n.includes("=")){const 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 ns(e){switch(!0){case e instanceof Response:return e;case e instanceof A:return e.toResponse();case e instanceof U:return e.toResponse();case e instanceof B:return e.toResponse();case e instanceof k:return e.toResponse();case e instanceof q:return e.toResponse()}switch(!0){case e instanceof C:return e.toResponse();case e instanceof S:return e.toResponse();case e instanceof $:return e.toResponse();case e instanceof I:return e.toResponse();case e instanceof j:return e.toResponse();case e instanceof J:return e.toResponse();case e instanceof E:return e.toResponse();case e instanceof w:return e.toResponse();case e instanceof O:return e.toResponse()}return new E("Server error",e).toResponse()}async function L([e,t]){const s=await t.safeParseAsync(e);if(s.success===!1){const n=Object.fromEntries(s.error.issues.map(r=>[r.path.join("."),r.message]));return{success:s.success,fieldErrors:n,fields:e}}else return{success:s.success,data:s.data}}function F([e,t]){const s=t.safeParse(e);if(s.success===!1){const n=Object.fromEntries(s.error.issues.map(r=>[r.path.join("."),r.message]));return{success:s.success,fieldErrors:n,fields:e}}else return{success:s.success,data:s.data}}const rs=(e,t="")=>{const s=new URL(e.url);if(t==="")return s.searchParams;const n=Array.from(s.searchParams.entries()).filter(([r])=>r.startsWith(`${t}:`)).map(([r,a])=>[r.replace(`${t}:`,""),a]);return new URLSearchParams(n)};function os(e){const t="Error validating:",s=e.issues.map(({path:n,message:r})=>`-> ${n.join(".")}: ${r}`);return[t,...s].join(`
|
|
10
|
-
`)}class as{constructor(t){o(this,"functionName");o(this,"callerInfo");this.schema=t;const{callerInfo:s,functionName:n}=N();this.callerInfo=s,this.functionName=n}isValid(t){return this.schema.safeParse(t).success}safeValidate(t){return this.schema.safeParse(t)}validate(t){try{return this.schema.parse(t)}catch(s){throw new E(os(s))}}formValidate(t,s){const n=F([t,this.schema]);if(!n.success){const r=Object.keys(n.fieldErrors)[0];throw new O({fields:n.fields,fieldErrors:n.fieldErrors,data:{scrollTo:r},message:s})}return n.data}async formAsyncValidate(t,s){const n=await L([t,this.schema]);if(!n.success){const r=Object.keys(n.fieldErrors)[0];throw new O({fields:n.fields,fieldErrors:n.fieldErrors,data:{scrollTo:r},message:s})}return n.data}}const us=e=>{if(!e||!/^[0-9-]+$/.test(e))return!1;const s=m.removeNonNumeric(e),n=8,r=/^\d{8}$/.test(s);return s.length===n&&r};function is(e){return e.length!==14}function cs(e){const[t]=e;return[...e].every(s=>s===t)}function H(e,t){let s=0;for(let r=0;r<t.length;r++)s+=parseInt(e[r])*t[r];const n=s%11;return n<2?0:11-n}function hs(e){return e.slice(12)}const ls=e=>{if(!e)return!1;const t=m.removeNonNumeric(e);if(is(t)||cs(t))return!1;const s=t.slice(0,12),n=H(s,[5,4,3,2,9,8,7,6,5,4,3,2]),r=H(s+n,[6,5,4,3,2,9,8,7,6,5,4,3,2]);return hs(t)===`${n}${r}`};function fs(e){return e.length!==11}function ds(e){const[t]=e;return[...e].every(s=>s===t)}function P(e,t){let s=0;for(const r of e)t>1&&(s+=parseInt(r)*t--);const n=s%11;return n<2?0:11-n}function ys(e){return e.slice(9)}const
|
|
9
|
+
`),b({scheme:"green",name:"ARKYN-SUCCESS-RESPONSE-DEBUG",debugs:r})}}class U extends R{constructor(s,n){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(n==null?void 0:n.headers)||{},this.status=(n==null?void 0:n.status)||201,this.statusText=(n==null?void 0:n.statusText)||"Resource created successfully",this.onDebug("Created",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class A 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 q 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 k extends R{constructor(s,n){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(n==null?void 0:n.headers)||{},this.status=(n==null?void 0:n.status)||200,this.statusText=(n==null?void 0:n.statusText)??"OK",this.onDebug("Success",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class B extends R{constructor(s,n){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(n==null?void 0:n.headers)||{},this.status=(n==null?void 0:n.status)||200,this.statusText=(n==null?void 0:n.statusText)||"Resource updated successfully",this.onDebug("Updated",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class V{static mapHeaders(t){return t instanceof Headers?Object.fromEntries(t.entries()):typeof t=="object"?Object.entries(t).reduce((s,[n,r])=>(typeof r=="string"?s[n]=r:Array.isArray(r)?s[n]=r.join(", "):s[n]=JSON.stringify(r),s),{}):{}}static mapQueryParams(t){const s={};return t.forEach((n,r)=>{s[r]=n}),s}static handle(t){return{rawUrl:t.url,status:t.status,method:t.method,token:null,elapsedTime:t.elapsedTime,requestHeaders:this.mapHeaders(t.requestHeaders),requestBody:t.requestBody||null,queryParams:this.mapQueryParams(t.queryParams),responseHeaders:this.mapHeaders(t.responseHeaders),responseBody:t.responseBody||null}}}class v{static setArkynConfig(t){if(this.arkynConfig)return;const{trafficSourceId:s,userToken:n,logBaseApiUrl:r}=t;this.arkynConfig={trafficSourceId:s,userToken:n,apiUrl:r||"http://95.216.190.158:8081/ingest-log"}}static getArkynConfig(){return this.arkynConfig}static resetArkynConfig(){this.arkynConfig=void 0}}o(v,"arkynConfig");async function G(e){const t=v.getArkynConfig();if(!t)return;const{userToken:s,apiUrl:n,trafficSourceId:r}=t,{elapsedTime:a,method:h,queryParams:l,requestBody:c,requestHeaders:f,responseBody:i,responseHeaders:g,status:z,token:y,rawUrl:vs}=e;if(process.env.NODE_ENV!=="development")try{const T=new URL(vs);let M="https";T.protocol==="http:"&&(M="http");const Cs=JSON.stringify({domainUrl:T.protocol+"//"+T.host,pathnameUrl:T.pathname,trafficSourceId:r,status:z,protocol:M,method:h.toLowerCase(),trafficUserId:null,elapsedTime:a,requestHeaders:JSON.stringify(f),requestBody:JSON.stringify(c),queryParams:JSON.stringify(l),responseHeaders:JSON.stringify(g),responseBody:JSON.stringify(i)});await fetch(n,{method:"POST",body:Cs,headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`}})}catch(T){b({debugs:[`Error sending request: ${T}`],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=V.handle({elapsedTime:c,method:e,queryParams:new URL(t).searchParams,requestHeaders:h,requestBody:n,responseBody:i,responseHeaders:l.headers,status:f,url:t});return G(g),l.ok?{success:!0,status:f,message:(i==null?void 0:i.message)||r[e],response:i,cause:null}:{success:!1,status:f,message:(i==null?void 0:i.message)||l.statusText||"Request failed",response:i,cause:null}}catch(a){return b({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 Z(e,t={},s){return x("DELETE",e,t,s)}async function W(e,t={}){return x("GET",e,t)}async function K(e,t={},s){return x("PATCH",e,t,s)}async function Q(e,t={},s){return x("POST",e,t,s)}async function X(e,t={},s){return x("PUT",e,t,s)}class ss{constructor(t){o(this,"baseUrl");o(this,"baseHeaders");o(this,"baseToken");o(this,"enableDebug");this.baseUrl=t.baseUrl,this.baseHeaders=t.baseHeaders||void 0,this.baseToken=t.baseToken||void 0,this.enableDebug=t.enableDebug||!1}onDebug(t,s,n){if(this.enableDebug){const r=[];r.push(`Base URL: ${this.baseUrl}`),r.push(`Endpoint: ${t}`),r.push(`Method: ${s}`),n[0]&&r.push(`Headers: ${JSON.stringify(n[0])}`),n[1]&&r.push(`Body: ${JSON.stringify(n[1])}`),b({debugs:r,name:"ARKYN-API-DEBUG",scheme:"yellow"})}}generateURL(t){return this.baseUrl+t}generateHeaders(t,s){let n={};return this.baseToken&&(n={Authorization:`Bearer ${this.baseToken}`}),this.baseHeaders&&(n={...n,...this.baseHeaders}),t&&(n={...n,...t}),s&&(n={...n,Authorization:`Bearer ${s}`}),n}async get(t,s){const n=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token);return this.onDebug(t,"get",[r]),await W(n,r)}async post(t,s){const n=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),a=s==null?void 0:s.body;return this.onDebug(t,"post",[r,a]),await Q(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 X(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 K(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 Z(n,r,a)}}function es(e,t){var s,n,r;return e!=null&&e.message&&typeof(e==null?void 0:e.message)=="string"?e==null?void 0:e.message:e!=null&&e.error&&typeof(e==null?void 0:e.error)=="string"?e==null?void 0:e.error:(s=e==null?void 0:e.error)!=null&&s.message&&typeof((n=e==null?void 0:e.error)==null?void 0:n.message)=="string"?(r=e==null?void 0:e.error)==null?void 0:r.message:t!=null&&t.statusText&&typeof(t==null?void 0:t.statusText)=="string"?t==null?void 0:t.statusText:"Missing error message"}const ts=async e=>{let t;const s=await e.arrayBuffer(),n=new TextDecoder().decode(s);try{t=JSON.parse(n)}catch{try{if(n.includes("=")){const 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 ns(e){switch(!0){case e instanceof Response:return e;case e instanceof A:return e.toResponse();case e instanceof U:return e.toResponse();case e instanceof B:return e.toResponse();case e instanceof k:return e.toResponse();case e instanceof q:return e.toResponse()}switch(!0){case e instanceof C:return e.toResponse();case e instanceof S:return e.toResponse();case e instanceof $:return e.toResponse();case e instanceof I:return e.toResponse();case e instanceof j:return e.toResponse();case e instanceof J:return e.toResponse();case e instanceof E:return e.toResponse();case e instanceof w:return e.toResponse();case e instanceof O:return e.toResponse()}return new E("Server error",e).toResponse()}async function L([e,t]){const s=await t.safeParseAsync(e);if(s.success===!1){const n=Object.fromEntries(s.error.issues.map(r=>[r.path.join("."),r.message]));return{success:s.success,fieldErrors:n,fields:e}}else return{success:s.success,data:s.data}}function F([e,t]){const s=t.safeParse(e);if(s.success===!1){const n=Object.fromEntries(s.error.issues.map(r=>[r.path.join("."),r.message]));return{success:s.success,fieldErrors:n,fields:e}}else return{success:s.success,data:s.data}}const rs=(e,t="")=>{const s=new URL(e.url);if(t==="")return s.searchParams;const n=Array.from(s.searchParams.entries()).filter(([r])=>r.startsWith(`${t}:`)).map(([r,a])=>[r.replace(`${t}:`,""),a]);return new URLSearchParams(n)};function os(e){const t="Error validating:",s=e.issues.map(({path:n,message:r})=>`-> ${n.join(".")}: ${r}`);return[t,...s].join(`
|
|
10
|
+
`)}class as{constructor(t){o(this,"functionName");o(this,"callerInfo");this.schema=t;const{callerInfo:s,functionName:n}=N();this.callerInfo=s,this.functionName=n}isValid(t){return this.schema.safeParse(t).success}safeValidate(t){return this.schema.safeParse(t)}validate(t){try{return this.schema.parse(t)}catch(s){throw new E(os(s))}}formValidate(t,s){const n=F([t,this.schema]);if(!n.success){const r=Object.keys(n.fieldErrors)[0];throw new O({fields:n.fields,fieldErrors:n.fieldErrors,data:{scrollTo:r},message:s})}return n.data}async formAsyncValidate(t,s){const n=await L([t,this.schema]);if(!n.success){const r=Object.keys(n.fieldErrors)[0];throw new O({fields:n.fields,fieldErrors:n.fieldErrors,data:{scrollTo:r},message:s})}return n.data}}const us=e=>{if(!e||!/^[0-9-]+$/.test(e))return!1;const s=m.removeNonNumeric(e),n=8,r=/^\d{8}$/.test(s);return s.length===n&&r};function is(e){return e.length!==14}function cs(e){const[t]=e;return[...e].every(s=>s===t)}function H(e,t){let s=0;for(let r=0;r<t.length;r++)s+=parseInt(e[r])*t[r];const n=s%11;return n<2?0:11-n}function hs(e){return e.slice(12)}const ls=e=>{if(!e)return!1;const t=m.removeNonNumeric(e);if(is(t)||cs(t))return!1;const s=t.slice(0,12),n=H(s,[5,4,3,2,9,8,7,6,5,4,3,2]),r=H(s+n,[6,5,4,3,2,9,8,7,6,5,4,3,2]);return hs(t)===`${n}${r}`};function fs(e){return e.length!==11}function ds(e){const[t]=e;return[...e].every(s=>s===t)}function P(e,t){let s=0;for(const r of e)t>1&&(s+=parseInt(r)*t--);const n=s%11;return n<2?0:11-n}function ys(e){return e.slice(9)}const ps=e=>{if(!e)return!1;const t=m.removeNonNumeric(e);if(fs(t)||ds(t))return!1;const s=P(t,10),n=P(t,11);return ys(t)===`${s}${n}`},gs=(e,t)=>{let s,n,r;const 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};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 bs(e){return!(e.length===0||e.length>64||e.startsWith(".")||e.endsWith(".")||e.includes("..")||!/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/.test(e))}function Ts(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(!Ts(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!(!bs(s)||!Rs(n))}function Ns(e){const t=e.split("@");return t.length===2?t[1].toLowerCase():null}const Ss=async e=>{if(!e||typeof e!="string")return!1;const t=e.trim();return!(!ms(t)||!xs(t)||!Ns(t))},Es=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)},Os=e=>{for(const t of Y.countries){const s=t.code,n=t.prefix?`-${t.prefix}`:"",r=t.mask.replace(/[^_]/g,"").length;if(t.iso==="BR"){if(new RegExp(`^\\${s} \\d{2}9?\\d{8}$`).test(e))return!0;continue}if(new RegExp(`^\\${s}${n} \\d{${r}}$`).test(e))return!0}return!1},Ds=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=ss,u.ArkynLogService=v,u.BadGateway=C,u.BadRequest=S,u.Conflict=$,u.Created=U,u.DebugService=D,u.Forbidden=I,u.Found=A,u.NoContent=q,u.NotFound=j,u.NotImplemented=J,u.SchemaValidator=as,u.ServerError=E,u.Success=k,u.Unauthorized=w,u.UnprocessableEntity=O,u.Updated=B,u.decodeErrorMessageFromRequest=es,u.decodeRequestBody=ts,u.errorHandler=ns,u.flushDebugLogs=b,u.formAsyncParse=L,u.formParse=F,u.getCaller=N,u.getScopedParams=rs,u.validateCep=us,u.validateCnpj=ls,u.validateCpf=ps,u.validateDate=gs,u.validateEmail=Ss,u.validatePassword=Es,u.validatePhone=Os,u.validateRg=Ds,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|