@arkyn/server 3.0.1-beta.82 → 3.0.1-beta.83
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.js +8 -8
- package/dist/bundle.js +61 -61
- package/dist/bundle.umd.cjs +5 -5
- package/package.json +1 -1
|
@@ -49,23 +49,23 @@ async function arkynLogRequest(config) {
|
|
|
49
49
|
// if (process.env.NODE_ENV === "development") return;
|
|
50
50
|
try {
|
|
51
51
|
const url = new URL(rawUrl);
|
|
52
|
-
let protocol = "
|
|
52
|
+
let protocol = "https";
|
|
53
53
|
if (url.protocol === "http:")
|
|
54
|
-
protocol = "
|
|
54
|
+
protocol = "http";
|
|
55
55
|
const body = JSON.stringify({
|
|
56
56
|
domainUrl: url.protocol + "//" + url.host,
|
|
57
57
|
pathnameUrl: url.pathname,
|
|
58
58
|
trafficSourceId: trafficSourceId,
|
|
59
59
|
status,
|
|
60
60
|
protocol,
|
|
61
|
-
method,
|
|
61
|
+
method: method.toLowerCase(),
|
|
62
62
|
trafficUserId: null,
|
|
63
63
|
elapsedTime,
|
|
64
|
-
requestHeaders,
|
|
65
|
-
requestBody,
|
|
66
|
-
queryParams,
|
|
67
|
-
responseHeaders,
|
|
68
|
-
responseBody,
|
|
64
|
+
requestHeaders: JSON.stringify(requestHeaders),
|
|
65
|
+
requestBody: JSON.stringify(requestBody),
|
|
66
|
+
queryParams: JSON.stringify(queryParams),
|
|
67
|
+
responseHeaders: JSON.stringify(responseHeaders),
|
|
68
|
+
responseBody: JSON.stringify(responseBody),
|
|
69
69
|
});
|
|
70
70
|
const data = await fetch(apiUrl, {
|
|
71
71
|
method: "POST",
|
package/dist/bundle.js
CHANGED
|
@@ -97,13 +97,13 @@ function E() {
|
|
|
97
97
|
}
|
|
98
98
|
return { functionName: h, callerInfo: i };
|
|
99
99
|
}
|
|
100
|
-
class
|
|
100
|
+
class y {
|
|
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 B extends
|
|
106
|
+
class B extends y {
|
|
107
107
|
/**
|
|
108
108
|
* Creates an instance of the `BadGateway` class.
|
|
109
109
|
*
|
|
@@ -151,7 +151,7 @@ class B extends p {
|
|
|
151
151
|
return Response.json(this.body, s);
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
-
class
|
|
154
|
+
class x extends y {
|
|
155
155
|
/**
|
|
156
156
|
* Creates an instance of the `BadRequest` class.
|
|
157
157
|
*
|
|
@@ -199,7 +199,7 @@ class T extends p {
|
|
|
199
199
|
return Response.json(this.body, s);
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
|
-
class k extends
|
|
202
|
+
class k extends y {
|
|
203
203
|
/**
|
|
204
204
|
* Creates an instance of the `Conflict` class.
|
|
205
205
|
*
|
|
@@ -247,7 +247,7 @@ class k extends p {
|
|
|
247
247
|
return Response.json(this.body, s);
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
|
-
class
|
|
250
|
+
class q extends y {
|
|
251
251
|
/**
|
|
252
252
|
* Creates an instance of the `Forbidden` class.
|
|
253
253
|
*
|
|
@@ -295,7 +295,7 @@ class H extends p {
|
|
|
295
295
|
return Response.json(this.body, s);
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
|
-
class
|
|
298
|
+
class H extends y {
|
|
299
299
|
/**
|
|
300
300
|
* Creates an instance of the `NotFound` class.
|
|
301
301
|
*
|
|
@@ -343,7 +343,7 @@ class q extends p {
|
|
|
343
343
|
return Response.json(this.body, s);
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
|
-
class F extends
|
|
346
|
+
class F extends y {
|
|
347
347
|
/**
|
|
348
348
|
* Creates an instance of the `NotImplemented` class.
|
|
349
349
|
*
|
|
@@ -391,7 +391,7 @@ class F extends p {
|
|
|
391
391
|
return Response.json(this.body, s);
|
|
392
392
|
}
|
|
393
393
|
}
|
|
394
|
-
class
|
|
394
|
+
class T extends y {
|
|
395
395
|
/**
|
|
396
396
|
* Creates an instance of the `ServerError` class.
|
|
397
397
|
*
|
|
@@ -439,7 +439,7 @@ class x extends p {
|
|
|
439
439
|
return Response.json(this.body, s);
|
|
440
440
|
}
|
|
441
441
|
}
|
|
442
|
-
class P extends
|
|
442
|
+
class P extends y {
|
|
443
443
|
/**
|
|
444
444
|
* Creates an instance of the `Unauthorized` class.
|
|
445
445
|
*
|
|
@@ -487,7 +487,7 @@ class P extends p {
|
|
|
487
487
|
return Response.json(this.body, s);
|
|
488
488
|
}
|
|
489
489
|
}
|
|
490
|
-
class R extends
|
|
490
|
+
class R extends y {
|
|
491
491
|
/**
|
|
492
492
|
* Creates an instance of the `UnprocessableEntity` class.
|
|
493
493
|
*
|
|
@@ -855,38 +855,38 @@ async function Z(e) {
|
|
|
855
855
|
responseHeaders: d,
|
|
856
856
|
status: S,
|
|
857
857
|
token: f,
|
|
858
|
-
rawUrl:
|
|
858
|
+
rawUrl: J
|
|
859
859
|
} = e;
|
|
860
860
|
try {
|
|
861
|
-
const
|
|
862
|
-
let
|
|
863
|
-
|
|
864
|
-
const
|
|
865
|
-
domainUrl:
|
|
866
|
-
pathnameUrl:
|
|
861
|
+
const p = new URL(J);
|
|
862
|
+
let O = "https";
|
|
863
|
+
p.protocol === "http:" && (O = "http");
|
|
864
|
+
const j = JSON.stringify({
|
|
865
|
+
domainUrl: p.protocol + "//" + p.host,
|
|
866
|
+
pathnameUrl: p.pathname,
|
|
867
867
|
trafficSourceId: r,
|
|
868
868
|
status: S,
|
|
869
|
-
protocol:
|
|
870
|
-
method: c,
|
|
869
|
+
protocol: O,
|
|
870
|
+
method: c.toLowerCase(),
|
|
871
871
|
trafficUserId: null,
|
|
872
872
|
elapsedTime: a,
|
|
873
|
-
requestHeaders: l,
|
|
874
|
-
requestBody: i,
|
|
875
|
-
queryParams: h,
|
|
876
|
-
responseHeaders: d,
|
|
877
|
-
responseBody: u
|
|
878
|
-
}),
|
|
873
|
+
requestHeaders: JSON.stringify(l),
|
|
874
|
+
requestBody: JSON.stringify(i),
|
|
875
|
+
queryParams: JSON.stringify(h),
|
|
876
|
+
responseHeaders: JSON.stringify(d),
|
|
877
|
+
responseBody: JSON.stringify(u)
|
|
878
|
+
}), w = await fetch(n, {
|
|
879
879
|
method: "POST",
|
|
880
|
-
body:
|
|
880
|
+
body: j,
|
|
881
881
|
headers: {
|
|
882
882
|
"Content-Type": "application/json",
|
|
883
883
|
Authorization: `Bearer ${s}`
|
|
884
884
|
}
|
|
885
885
|
});
|
|
886
|
-
console.log(await
|
|
887
|
-
} catch (
|
|
888
|
-
console.log(
|
|
889
|
-
debugs: [`Error sending request: ${
|
|
886
|
+
console.log(await w.json());
|
|
887
|
+
} catch (p) {
|
|
888
|
+
console.log(p), g({
|
|
889
|
+
debugs: [`Error sending request: ${p}`],
|
|
890
890
|
name: "ARKYN_LOG_ERROR",
|
|
891
891
|
scheme: "red"
|
|
892
892
|
});
|
|
@@ -1071,9 +1071,9 @@ const Es = async (e) => {
|
|
|
1071
1071
|
const a = new URLSearchParams(n);
|
|
1072
1072
|
t = Object.fromEntries(a.entries());
|
|
1073
1073
|
} else
|
|
1074
|
-
throw new
|
|
1074
|
+
throw new x("Invalid URLSearchParams format");
|
|
1075
1075
|
} catch {
|
|
1076
|
-
throw new
|
|
1076
|
+
throw new x("Failed to extract data from request");
|
|
1077
1077
|
}
|
|
1078
1078
|
}
|
|
1079
1079
|
return t;
|
|
@@ -1096,24 +1096,24 @@ function Ss(e) {
|
|
|
1096
1096
|
switch (!0) {
|
|
1097
1097
|
case e instanceof B:
|
|
1098
1098
|
return e.toResponse();
|
|
1099
|
-
case e instanceof
|
|
1099
|
+
case e instanceof x:
|
|
1100
1100
|
return e.toResponse();
|
|
1101
1101
|
case e instanceof k:
|
|
1102
1102
|
return e.toResponse();
|
|
1103
|
-
case e instanceof H:
|
|
1104
|
-
return e.toResponse();
|
|
1105
1103
|
case e instanceof q:
|
|
1106
1104
|
return e.toResponse();
|
|
1105
|
+
case e instanceof H:
|
|
1106
|
+
return e.toResponse();
|
|
1107
1107
|
case e instanceof F:
|
|
1108
1108
|
return e.toResponse();
|
|
1109
|
-
case e instanceof
|
|
1109
|
+
case e instanceof T:
|
|
1110
1110
|
return e.toResponse();
|
|
1111
1111
|
case e instanceof P:
|
|
1112
1112
|
return e.toResponse();
|
|
1113
1113
|
case e instanceof R:
|
|
1114
1114
|
return e.toResponse();
|
|
1115
1115
|
}
|
|
1116
|
-
return new
|
|
1116
|
+
return new T("Server error", e).toResponse();
|
|
1117
1117
|
}
|
|
1118
1118
|
async function es([
|
|
1119
1119
|
e,
|
|
@@ -1155,7 +1155,7 @@ function ts([
|
|
|
1155
1155
|
data: s.data
|
|
1156
1156
|
};
|
|
1157
1157
|
}
|
|
1158
|
-
const
|
|
1158
|
+
const Os = (e, t = "") => {
|
|
1159
1159
|
const s = new URL(e.url);
|
|
1160
1160
|
if (t === "") return s.searchParams;
|
|
1161
1161
|
const n = Array.from(
|
|
@@ -1170,7 +1170,7 @@ function ns(e) {
|
|
|
1170
1170
|
return [t, ...s].join(`
|
|
1171
1171
|
`);
|
|
1172
1172
|
}
|
|
1173
|
-
class
|
|
1173
|
+
class Ds {
|
|
1174
1174
|
/**
|
|
1175
1175
|
* Creates a new SchemaValidator instance.
|
|
1176
1176
|
*
|
|
@@ -1247,7 +1247,7 @@ class $s {
|
|
|
1247
1247
|
try {
|
|
1248
1248
|
return this.schema.parse(t);
|
|
1249
1249
|
} catch (s) {
|
|
1250
|
-
throw new
|
|
1250
|
+
throw new T(ns(s));
|
|
1251
1251
|
}
|
|
1252
1252
|
}
|
|
1253
1253
|
/**
|
|
@@ -1327,7 +1327,7 @@ class $s {
|
|
|
1327
1327
|
return n.data;
|
|
1328
1328
|
}
|
|
1329
1329
|
}
|
|
1330
|
-
const
|
|
1330
|
+
const $s = (e) => {
|
|
1331
1331
|
if (!e || !/^[0-9-]+$/.test(e)) return !1;
|
|
1332
1332
|
const s = N(e), n = 8, r = /^\d{8}$/.test(s);
|
|
1333
1333
|
return s.length === n && r;
|
|
@@ -1339,7 +1339,7 @@ function os(e) {
|
|
|
1339
1339
|
const [t] = e;
|
|
1340
1340
|
return [...e].every((s) => s === t);
|
|
1341
1341
|
}
|
|
1342
|
-
function
|
|
1342
|
+
function D(e, t) {
|
|
1343
1343
|
let s = 0;
|
|
1344
1344
|
for (let r = 0; r < t.length; r++)
|
|
1345
1345
|
s += parseInt(e[r]) * t[r];
|
|
@@ -1353,7 +1353,7 @@ const Is = (e) => {
|
|
|
1353
1353
|
if (!e) return !1;
|
|
1354
1354
|
const t = N(e);
|
|
1355
1355
|
if (rs(t) || os(t)) return !1;
|
|
1356
|
-
const s = t.slice(0, 12), n =
|
|
1356
|
+
const s = t.slice(0, 12), n = D(s, [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]), r = D(
|
|
1357
1357
|
s + n,
|
|
1358
1358
|
[6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
|
|
1359
1359
|
);
|
|
@@ -1366,7 +1366,7 @@ function is(e) {
|
|
|
1366
1366
|
const [t] = e;
|
|
1367
1367
|
return [...e].every((s) => s === t);
|
|
1368
1368
|
}
|
|
1369
|
-
function
|
|
1369
|
+
function $(e, t) {
|
|
1370
1370
|
let s = 0;
|
|
1371
1371
|
for (const r of e)
|
|
1372
1372
|
t > 1 && (s += parseInt(r) * t--);
|
|
@@ -1380,9 +1380,9 @@ const Cs = (e) => {
|
|
|
1380
1380
|
if (!e) return !1;
|
|
1381
1381
|
const t = N(e);
|
|
1382
1382
|
if (us(t) || is(t)) return !1;
|
|
1383
|
-
const s =
|
|
1383
|
+
const s = $(t, 10), n = $(t, 11);
|
|
1384
1384
|
return cs(t) === `${s}${n}`;
|
|
1385
|
-
},
|
|
1385
|
+
}, Js = (e, t) => {
|
|
1386
1386
|
let s, n, r;
|
|
1387
1387
|
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
1388
|
if (a === "DD/MM/YYYY") {
|
|
@@ -1427,21 +1427,21 @@ function ds(e) {
|
|
|
1427
1427
|
const s = t[t.length - 1];
|
|
1428
1428
|
return !(s.length < 2 || !/^[a-zA-Z]+$/.test(s));
|
|
1429
1429
|
}
|
|
1430
|
-
function
|
|
1430
|
+
function ys(e) {
|
|
1431
1431
|
const t = e.split("@");
|
|
1432
1432
|
if (t.length !== 2) return !1;
|
|
1433
1433
|
const [s, n] = t;
|
|
1434
1434
|
return !(!ls(s) || !ds(n));
|
|
1435
1435
|
}
|
|
1436
|
-
function
|
|
1436
|
+
function ps(e) {
|
|
1437
1437
|
const t = e.split("@");
|
|
1438
1438
|
return t.length === 2 ? t[1].toLowerCase() : null;
|
|
1439
1439
|
}
|
|
1440
|
-
const
|
|
1440
|
+
const js = async (e) => {
|
|
1441
1441
|
if (!e || typeof e != "string") return !1;
|
|
1442
1442
|
const t = e.trim();
|
|
1443
|
-
return !(!hs(t) || !
|
|
1444
|
-
},
|
|
1443
|
+
return !(!hs(t) || !ys(t) || !ps(t));
|
|
1444
|
+
}, ws = (e) => {
|
|
1445
1445
|
if (!e) return !1;
|
|
1446
1446
|
const t = e.length >= 8, s = /[A-Z]/.test(e), n = /[a-z]/.test(e), r = /\d/.test(e), a = /[!@#$%^&*(),.?":{}|<>_\-+=~`[\]\\\/]/.test(
|
|
1447
1447
|
e
|
|
@@ -1472,17 +1472,17 @@ export {
|
|
|
1472
1472
|
Rs as ApiService,
|
|
1473
1473
|
C as ArkynLogService,
|
|
1474
1474
|
B as BadGateway,
|
|
1475
|
-
|
|
1475
|
+
x as BadRequest,
|
|
1476
1476
|
k as Conflict,
|
|
1477
1477
|
Y as Created,
|
|
1478
1478
|
I as DebugService,
|
|
1479
|
-
|
|
1479
|
+
q as Forbidden,
|
|
1480
1480
|
z as Found,
|
|
1481
1481
|
M as NoContent,
|
|
1482
|
-
|
|
1482
|
+
H as NotFound,
|
|
1483
1483
|
F as NotImplemented,
|
|
1484
|
-
|
|
1485
|
-
|
|
1484
|
+
Ds as SchemaValidator,
|
|
1485
|
+
T as ServerError,
|
|
1486
1486
|
_ as Success,
|
|
1487
1487
|
P as Unauthorized,
|
|
1488
1488
|
R as UnprocessableEntity,
|
|
@@ -1494,13 +1494,13 @@ export {
|
|
|
1494
1494
|
es as formAsyncParse,
|
|
1495
1495
|
ts as formParse,
|
|
1496
1496
|
E as getCaller,
|
|
1497
|
-
|
|
1498
|
-
|
|
1497
|
+
Os as getScopedParams,
|
|
1498
|
+
$s as validateCep,
|
|
1499
1499
|
Is as validateCnpj,
|
|
1500
1500
|
Cs as validateCpf,
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1501
|
+
Js as validateDate,
|
|
1502
|
+
js as validateEmail,
|
|
1503
|
+
ws as validatePassword,
|
|
1504
1504
|
Us as validatePhone,
|
|
1505
1505
|
vs as validateRg
|
|
1506
1506
|
};
|
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 Is=Object.defineProperty;var js=(u,d,m)=>d in u?Is(u,d,{enumerable:!0,configurable:!0,writable:!0,value:m}):u[d]=m;var o=(u,d,m)=>js(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 _={};class
|
|
4
|
-
`).map(i=>i.trim()),r=
|
|
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 p=c.match(/at\s+([^(\s]+)\s+/);p&&p[1]!=="new"&&(l=p[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 g{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 C extends g{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 g{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 g{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 g{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 g{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 g{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 g{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 g{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 g{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 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)||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 k extends R{constructor(s){super();o(this,"headers");o(this,"status");o(this,"statusText");this.headers=(s==null?void 0:s.headers)||{},this.status=(s==null?void 0:s.status)||204,this.statusText=(s==null?void 0:s.statusText)??"No content",this.onDebug("No content",null)}toResponse(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return new Response(null,s)}}class L extends R{constructor(s,n){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(n==null?void 0:n.headers)||{},this.status=(n==null?void 0:n.status)||200,this.statusText=(n==null?void 0:n.statusText)??"OK",this.onDebug("Success",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class q extends R{constructor(s,n){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(n==null?void 0:n.headers)||{},this.status=(n==null?void 0:n.status)||200,this.statusText=(n==null?void 0:n.statusText)||"Resource updated successfully",this.onDebug("Updated",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class 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 ${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($,"arkynConfig");async function G(e){const t=$.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:$s}=e;try{const b=new URL($s);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,trafficUserId:null,elapsedTime:a,requestHeaders:f,requestBody:c,queryParams:l,responseHeaders:p,responseBody:i}),Os=await fetch(n,{method:"POST",body:Cs,headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`}});console.log(await Os.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 J:return e.toResponse();case e instanceof q:return e.toResponse();case e instanceof L:return e.toResponse();case e instanceof k:return e.toResponse()}switch(!0){case e instanceof C:return e.toResponse();case e instanceof S:return e.toResponse();case e instanceof O:return e.toResponse();case e instanceof I:return e.toResponse();case e instanceof j:return e.toResponse();case e instanceof w:return e.toResponse();case e instanceof E:return e.toResponse();case e instanceof U:return e.toResponse();case e instanceof D:return e.toResponse()}return new E("Server error",e).toResponse()}async function B([e,t]){const s=await t.safeParseAsync(e);if(s.success===!1){const n=Object.fromEntries(s.error.issues.map(r=>[r.path.join("."),r.message]));return{success:s.success,fieldErrors:n,fields:e}}else return{success:s.success,data:s.data}}function F([e,t]){const s=t.safeParse(e);if(s.success===!1){const n=Object.fromEntries(s.error.issues.map(r=>[r.path.join("."),r.message]));return{success:s.success,fieldErrors:n,fields:e}}else return{success:s.success,data:s.data}}const 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
|
|
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 gs=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}`},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 p=[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>p[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=T,u.formAsyncParse=L,u.formParse=F,u.getCaller=N,u.getScopedParams=rs,u.validateCep=us,u.validateCnpj=ls,u.validateCpf=gs,u.validateDate=ps,u.validateEmail=Ss,u.validatePassword=Es,u.validatePhone=Os,u.validateRg=Ds,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|