@arkyn/server 3.0.1-beta.60 → 3.0.1-beta.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +190 -182
- package/dist/bundle.umd.cjs +5 -5
- package/dist/services/apiService.d.ts +4 -0
- package/dist/services/apiService.d.ts.map +1 -1
- package/dist/services/apiService.js +22 -0
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var o = (
|
|
4
|
-
const
|
|
5
|
-
function
|
|
6
|
-
const
|
|
7
|
-
`).map((u) => u.trim()), r =
|
|
1
|
+
var U = Object.defineProperty;
|
|
2
|
+
var k = (t, s, e) => s in t ? U(t, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[s] = e;
|
|
3
|
+
var o = (t, s, e) => k(t, typeof s != "symbol" ? s + "" : s, e);
|
|
4
|
+
const I = {};
|
|
5
|
+
function x() {
|
|
6
|
+
const t = process.cwd(), n = (new Error().stack || "").split(`
|
|
7
|
+
`).map((u) => u.trim()), r = R.ignoreFile;
|
|
8
8
|
let a = 2;
|
|
9
9
|
for (; a < n.length && (n[a].includes("node:internal") || n[a].includes("/node_modules/")); )
|
|
10
10
|
a++;
|
|
11
11
|
if (r)
|
|
12
12
|
for (; a < n.length && n[a].includes(r); )
|
|
13
13
|
a++;
|
|
14
|
-
const
|
|
14
|
+
const h = n[a] || "";
|
|
15
15
|
let i = "Unknown function", c = "Unknown caller";
|
|
16
|
-
const
|
|
17
|
-
if (
|
|
18
|
-
i =
|
|
16
|
+
const y = h.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);
|
|
17
|
+
if (y)
|
|
18
|
+
i = y[1], c = y[2];
|
|
19
19
|
else {
|
|
20
|
-
const u =
|
|
20
|
+
const u = h.match(/at\s+(.+)/);
|
|
21
21
|
if (u) {
|
|
22
22
|
c = u[1];
|
|
23
23
|
const f = c.match(/at\s+([^(\s]+)\s+/);
|
|
@@ -29,12 +29,12 @@ function R() {
|
|
|
29
29
|
c.lastIndexOf(")")
|
|
30
30
|
)), c = c.split(":").slice(0, -2).join(":");
|
|
31
31
|
try {
|
|
32
|
-
c =
|
|
32
|
+
c = I.relative(t, c);
|
|
33
33
|
} catch {
|
|
34
34
|
}
|
|
35
35
|
return { functionName: i, callerInfo: c };
|
|
36
36
|
}
|
|
37
|
-
class
|
|
37
|
+
class R {
|
|
38
38
|
/**
|
|
39
39
|
* Sets the file name to be ignored during stack trace analysis.
|
|
40
40
|
*
|
|
@@ -58,33 +58,33 @@ class g {
|
|
|
58
58
|
* The name of the file to ignore when analyzing the stack trace.
|
|
59
59
|
* When set, the `getCaller` function will skip stack frames containing this file name.
|
|
60
60
|
*/
|
|
61
|
-
o(
|
|
62
|
-
function
|
|
61
|
+
o(R, "ignoreFile");
|
|
62
|
+
function l(t, s, e) {
|
|
63
63
|
var r;
|
|
64
64
|
if (process.env.NODE_ENV === "development" || ((r = process.env) == null ? void 0 : r.SHOW_ERRORS_IN_CONSOLE) === "true") {
|
|
65
|
-
const i = "\x1B[36m[ARKYN-DEBUG]\x1B[0m", { callerInfo: c, functionName:
|
|
66
|
-
let u = `${i} ${
|
|
65
|
+
const i = "\x1B[36m[ARKYN-DEBUG]\x1B[0m", { callerInfo: c, functionName: y } = x();
|
|
66
|
+
let u = `${i} ${t} initialized
|
|
67
67
|
`;
|
|
68
|
-
u += `${i} Caller Function: ${
|
|
68
|
+
u += `${i} Caller Function: ${y}
|
|
69
69
|
`, u += `${i} Caller Location: ${c}
|
|
70
70
|
`, u += `${i} Body: ${JSON.stringify(s, null, 2)}
|
|
71
|
-
`,
|
|
71
|
+
`, e && (u += `${i} Cause: ${JSON.stringify(e, null, 2)}
|
|
72
72
|
`), console.log(u);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
class
|
|
75
|
+
class j {
|
|
76
76
|
/**
|
|
77
77
|
* Creates an instance of the `BadGateway` class.
|
|
78
78
|
*
|
|
79
79
|
* @param message - A descriptive message explaining the cause of the error.
|
|
80
80
|
* @param cause - Optional additional information about the cause of the error.
|
|
81
81
|
*/
|
|
82
|
-
constructor(s,
|
|
82
|
+
constructor(s, e) {
|
|
83
83
|
o(this, "body");
|
|
84
84
|
o(this, "cause");
|
|
85
85
|
o(this, "status", 502);
|
|
86
86
|
o(this, "statusText");
|
|
87
|
-
this.body = { name: "BadGateway", message: s }, this.statusText = s, this.cause =
|
|
87
|
+
this.body = { name: "BadGateway", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, l("BadGateway", this.body, this.cause);
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
90
|
* Converts the `BadGateway` instance into a `Response` object with a JSON body.
|
|
@@ -121,12 +121,12 @@ class T {
|
|
|
121
121
|
* @param message - A descriptive message explaining the cause of the error.
|
|
122
122
|
* @param cause - Optional additional information about the cause of the error.
|
|
123
123
|
*/
|
|
124
|
-
constructor(s,
|
|
124
|
+
constructor(s, e) {
|
|
125
125
|
o(this, "body");
|
|
126
126
|
o(this, "cause");
|
|
127
127
|
o(this, "status", 400);
|
|
128
128
|
o(this, "statusText");
|
|
129
|
-
this.body = { name: "BadRequest", message: s }, this.statusText = s, this.cause =
|
|
129
|
+
this.body = { name: "BadRequest", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, l("BadRequest", this.body, this.cause);
|
|
130
130
|
}
|
|
131
131
|
/**
|
|
132
132
|
* Converts the `BadRequest` instance into a `Response` object with a JSON body.
|
|
@@ -156,19 +156,19 @@ class T {
|
|
|
156
156
|
return Response.json(this.body, s);
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
-
class
|
|
159
|
+
class O {
|
|
160
160
|
/**
|
|
161
161
|
* Creates an instance of the `Conflict` class.
|
|
162
162
|
*
|
|
163
163
|
* @param message - A descriptive message explaining the cause of the conflict.
|
|
164
164
|
* @param cause - Optional additional information about the cause of the conflict.
|
|
165
165
|
*/
|
|
166
|
-
constructor(s,
|
|
166
|
+
constructor(s, e) {
|
|
167
167
|
o(this, "body");
|
|
168
168
|
o(this, "cause");
|
|
169
169
|
o(this, "status", 409);
|
|
170
170
|
o(this, "statusText");
|
|
171
|
-
this.body = { name: "Conflict", message: s }, this.statusText = s, this.cause =
|
|
171
|
+
this.body = { name: "Conflict", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, l("Conflict", this.body, this.cause);
|
|
172
172
|
}
|
|
173
173
|
/**
|
|
174
174
|
* Converts the `Conflict` instance into a `Response` object with a JSON body.
|
|
@@ -205,12 +205,12 @@ class E {
|
|
|
205
205
|
* @param message - A descriptive message explaining why access is forbidden.
|
|
206
206
|
* @param cause - Optional additional information about the cause of the error.
|
|
207
207
|
*/
|
|
208
|
-
constructor(s,
|
|
208
|
+
constructor(s, e) {
|
|
209
209
|
o(this, "body");
|
|
210
210
|
o(this, "cause");
|
|
211
211
|
o(this, "status", 403);
|
|
212
212
|
o(this, "statusText");
|
|
213
|
-
this.body = { name: "Forbidden", message: s }, this.statusText = s, this.cause =
|
|
213
|
+
this.body = { name: "Forbidden", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, l("Forbidden", this.body, this.cause);
|
|
214
214
|
}
|
|
215
215
|
/**
|
|
216
216
|
* Converts the `Forbidden` instance into a `Response` object with a JSON body.
|
|
@@ -247,12 +247,12 @@ class J {
|
|
|
247
247
|
* @param message - A descriptive message explaining the reason the resource was not found.
|
|
248
248
|
* @param cause - Optional additional information about the cause of the error.
|
|
249
249
|
*/
|
|
250
|
-
constructor(s,
|
|
250
|
+
constructor(s, e) {
|
|
251
251
|
o(this, "body");
|
|
252
252
|
o(this, "cause");
|
|
253
253
|
o(this, "status", 404);
|
|
254
254
|
o(this, "statusText");
|
|
255
|
-
this.body = { name: "NotFound", message: s }, this.statusText = s, this.cause =
|
|
255
|
+
this.body = { name: "NotFound", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, l("NotFound", this.body, this.cause);
|
|
256
256
|
}
|
|
257
257
|
/**
|
|
258
258
|
* Converts the `NotFound` instance into a `Response` object with a JSON body.
|
|
@@ -289,12 +289,12 @@ class C {
|
|
|
289
289
|
* @param message - A descriptive message explaining why the functionality is not implemented.
|
|
290
290
|
* @param cause - Optional additional information about the cause of the error.
|
|
291
291
|
*/
|
|
292
|
-
constructor(s,
|
|
292
|
+
constructor(s, e) {
|
|
293
293
|
o(this, "body");
|
|
294
294
|
o(this, "cause");
|
|
295
295
|
o(this, "status", 501);
|
|
296
296
|
o(this, "statusText");
|
|
297
|
-
this.body = { name: "NotImplemented", message: s }, this.statusText = s, this.cause =
|
|
297
|
+
this.body = { name: "NotImplemented", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, l("NotImplemented", this.body, this.cause);
|
|
298
298
|
}
|
|
299
299
|
/**
|
|
300
300
|
* Converts the `NotImplemented` instance into a `Response` object with a JSON body.
|
|
@@ -331,12 +331,12 @@ class b {
|
|
|
331
331
|
* @param message - A descriptive message explaining the cause of the server error.
|
|
332
332
|
* @param cause - Optional additional information about the cause of the error.
|
|
333
333
|
*/
|
|
334
|
-
constructor(s,
|
|
334
|
+
constructor(s, e) {
|
|
335
335
|
o(this, "body");
|
|
336
336
|
o(this, "cause");
|
|
337
337
|
o(this, "status", 500);
|
|
338
338
|
o(this, "statusText");
|
|
339
|
-
this.body = { name: "ServerError", message: s }, this.statusText = s, this.cause =
|
|
339
|
+
this.body = { name: "ServerError", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, l("ServerError", this.body, this.cause);
|
|
340
340
|
}
|
|
341
341
|
/**
|
|
342
342
|
* Converts the `ServerError` instance into a `Response` object with a JSON body.
|
|
@@ -373,12 +373,12 @@ class q {
|
|
|
373
373
|
* @param message - A descriptive message explaining why the request is unauthorized.
|
|
374
374
|
* @param cause - Optional additional information about the cause of the error.
|
|
375
375
|
*/
|
|
376
|
-
constructor(s,
|
|
376
|
+
constructor(s, e) {
|
|
377
377
|
o(this, "body");
|
|
378
378
|
o(this, "cause");
|
|
379
379
|
o(this, "status", 401);
|
|
380
380
|
o(this, "statusText");
|
|
381
|
-
this.body = { name: "Unauthorized", message: s }, this.statusText = s, this.cause =
|
|
381
|
+
this.body = { name: "Unauthorized", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, l("Unauthorized", this.body, this.cause);
|
|
382
382
|
}
|
|
383
383
|
/**
|
|
384
384
|
* Converts the `Unauthorized` instance into a `Response` object with a JSON body.
|
|
@@ -419,7 +419,7 @@ class m {
|
|
|
419
419
|
* - `message`: A descriptive message explaining the error.
|
|
420
420
|
* @param enableDebug - A boolean indicating whether to enable debug logging for this error.
|
|
421
421
|
*/
|
|
422
|
-
constructor(s,
|
|
422
|
+
constructor(s, e = !1) {
|
|
423
423
|
o(this, "body");
|
|
424
424
|
o(this, "status", 422);
|
|
425
425
|
o(this, "statusText");
|
|
@@ -429,7 +429,7 @@ class m {
|
|
|
429
429
|
data: s.data,
|
|
430
430
|
fieldErrors: s.fieldErrors,
|
|
431
431
|
fields: s.fields
|
|
432
|
-
},
|
|
432
|
+
}, e && l("UnprocessableEntity", this.body);
|
|
433
433
|
}
|
|
434
434
|
/**
|
|
435
435
|
* Converts the `UnprocessableEntity` instance into a `Response` object with a JSON body.
|
|
@@ -459,19 +459,19 @@ class m {
|
|
|
459
459
|
return Response.json(this.body, s);
|
|
460
460
|
}
|
|
461
461
|
}
|
|
462
|
-
class
|
|
462
|
+
class B {
|
|
463
463
|
/**
|
|
464
464
|
* Creates an instance of the `Created` class.
|
|
465
465
|
*
|
|
466
466
|
* @param body - The response body to be included in the HTTP response.
|
|
467
467
|
* @param init - Optional initialization object for customizing headers, status, and status text.
|
|
468
468
|
*/
|
|
469
|
-
constructor(s,
|
|
469
|
+
constructor(s, e) {
|
|
470
470
|
o(this, "body");
|
|
471
471
|
o(this, "headers");
|
|
472
472
|
o(this, "status");
|
|
473
473
|
o(this, "statusText");
|
|
474
|
-
this.body = s, this.headers = (
|
|
474
|
+
this.body = s, this.headers = (e == null ? void 0 : e.headers) || {}, this.status = (e == null ? void 0 : e.status) || 201, this.statusText = (e == null ? void 0 : e.statusText) || "Resource created successfully";
|
|
475
475
|
}
|
|
476
476
|
/**
|
|
477
477
|
* Converts the `Created` instance into a `Response` object with a JSON body.
|
|
@@ -502,7 +502,7 @@ class H {
|
|
|
502
502
|
return Response.json(this.body, s);
|
|
503
503
|
}
|
|
504
504
|
}
|
|
505
|
-
class
|
|
505
|
+
class H {
|
|
506
506
|
/**
|
|
507
507
|
* Creates an instance of the `Found` class.
|
|
508
508
|
*
|
|
@@ -512,12 +512,12 @@ class P {
|
|
|
512
512
|
* - `status`: HTTP status code (default is 302).
|
|
513
513
|
* - `statusText`: HTTP status text (default is "Found").
|
|
514
514
|
*/
|
|
515
|
-
constructor(s,
|
|
515
|
+
constructor(s, e) {
|
|
516
516
|
o(this, "body");
|
|
517
517
|
o(this, "headers");
|
|
518
518
|
o(this, "status");
|
|
519
519
|
o(this, "statusText");
|
|
520
|
-
this.body = s, this.headers = (
|
|
520
|
+
this.body = s, this.headers = (e == null ? void 0 : e.headers) || {}, this.status = (e == null ? void 0 : e.status) || 302, this.statusText = (e == null ? void 0 : e.statusText) || "Found";
|
|
521
521
|
}
|
|
522
522
|
/**
|
|
523
523
|
* Converts the `Found` instance into a `Response` object.
|
|
@@ -548,7 +548,7 @@ class P {
|
|
|
548
548
|
return Response.json(this.body, s);
|
|
549
549
|
}
|
|
550
550
|
}
|
|
551
|
-
class
|
|
551
|
+
class P {
|
|
552
552
|
/**
|
|
553
553
|
* Creates an instance of the `NoContent` class.
|
|
554
554
|
*
|
|
@@ -575,19 +575,19 @@ class B {
|
|
|
575
575
|
return new Response(null, s);
|
|
576
576
|
}
|
|
577
577
|
}
|
|
578
|
-
class
|
|
578
|
+
class $ {
|
|
579
579
|
/**
|
|
580
580
|
* Creates an instance of the `Success` class.
|
|
581
581
|
*
|
|
582
582
|
* @param body - The response body to be included in the HTTP response.
|
|
583
583
|
* @param init - Optional initialization object for customizing headers, status, and status text.
|
|
584
584
|
*/
|
|
585
|
-
constructor(s,
|
|
585
|
+
constructor(s, e) {
|
|
586
586
|
o(this, "body");
|
|
587
587
|
o(this, "headers");
|
|
588
588
|
o(this, "status");
|
|
589
589
|
o(this, "statusText");
|
|
590
|
-
this.body = s, this.headers = (
|
|
590
|
+
this.body = s, this.headers = (e == null ? void 0 : e.headers) || {}, this.status = (e == null ? void 0 : e.status) || 200, this.statusText = (e == null ? void 0 : e.statusText) ?? "OK";
|
|
591
591
|
}
|
|
592
592
|
/**
|
|
593
593
|
* Converts the `Success` instance into a `Response` object with a JSON body.
|
|
@@ -618,19 +618,19 @@ class L {
|
|
|
618
618
|
return Response.json(this.body, s);
|
|
619
619
|
}
|
|
620
620
|
}
|
|
621
|
-
class
|
|
621
|
+
class L {
|
|
622
622
|
/**
|
|
623
623
|
* Creates an instance of the `Updated` class.
|
|
624
624
|
*
|
|
625
625
|
* @param body - The response body to be included in the HTTP response.
|
|
626
626
|
* @param init - Optional initialization object for customizing headers, status, and status text.
|
|
627
627
|
*/
|
|
628
|
-
constructor(s,
|
|
628
|
+
constructor(s, e) {
|
|
629
629
|
o(this, "body");
|
|
630
630
|
o(this, "headers");
|
|
631
631
|
o(this, "status");
|
|
632
632
|
o(this, "statusText");
|
|
633
|
-
this.body = s, this.headers = (
|
|
633
|
+
this.body = s, this.headers = (e == null ? void 0 : e.headers) || {}, this.status = (e == null ? void 0 : e.status) || 200, this.statusText = (e == null ? void 0 : e.statusText) || "Resource updated successfully";
|
|
634
634
|
}
|
|
635
635
|
/**
|
|
636
636
|
* Converts the `Updated` instance into a `Response` object with a JSON body.
|
|
@@ -663,13 +663,13 @@ class v {
|
|
|
663
663
|
}
|
|
664
664
|
class A {
|
|
665
665
|
static mapHeaders(s) {
|
|
666
|
-
return s instanceof Headers ? Object.fromEntries(s.entries()) : typeof s == "object" ? Object.entries(s).reduce((
|
|
666
|
+
return s instanceof Headers ? Object.fromEntries(s.entries()) : typeof s == "object" ? Object.entries(s).reduce((e, [n, r]) => (typeof r == "string" ? e[n] = r : Array.isArray(r) ? e[n] = r.join(", ") : e[n] = JSON.stringify(r), e), {}) : {};
|
|
667
667
|
}
|
|
668
668
|
static mapQueryParams(s) {
|
|
669
|
-
const
|
|
669
|
+
const e = {};
|
|
670
670
|
return s.forEach((n, r) => {
|
|
671
|
-
|
|
672
|
-
}),
|
|
671
|
+
e[r] = n;
|
|
672
|
+
}), e;
|
|
673
673
|
}
|
|
674
674
|
static handle(s) {
|
|
675
675
|
return {
|
|
@@ -725,38 +725,38 @@ class w {
|
|
|
725
725
|
}
|
|
726
726
|
}
|
|
727
727
|
o(w, "arkynConfig");
|
|
728
|
-
async function
|
|
728
|
+
async function v(t) {
|
|
729
729
|
const s = w.getArkynConfig();
|
|
730
730
|
if (!s) return;
|
|
731
|
-
const { arkynUserToken:
|
|
731
|
+
const { arkynUserToken: e, arkynApiUrl: n } = s, {
|
|
732
732
|
elapsedTime: r,
|
|
733
733
|
method: a,
|
|
734
|
-
queryParams:
|
|
734
|
+
queryParams: h,
|
|
735
735
|
requestBody: i,
|
|
736
736
|
requestHeaders: c,
|
|
737
|
-
responseBody:
|
|
737
|
+
responseBody: y,
|
|
738
738
|
responseHeaders: u,
|
|
739
739
|
status: f,
|
|
740
740
|
token: K,
|
|
741
741
|
rawUrl: S
|
|
742
|
-
} =
|
|
742
|
+
} = t;
|
|
743
743
|
try {
|
|
744
744
|
const d = new URL(S);
|
|
745
|
-
let
|
|
746
|
-
d.protocol === "http:" && (
|
|
745
|
+
let g = "HTTPS";
|
|
746
|
+
d.protocol === "http:" && (g = "HTTP");
|
|
747
747
|
const N = JSON.stringify({
|
|
748
748
|
domainUrl: d.protocol + "//" + d.host,
|
|
749
749
|
pathnameUrl: d.pathname,
|
|
750
750
|
status: f,
|
|
751
|
-
protocol:
|
|
751
|
+
protocol: g,
|
|
752
752
|
method: a,
|
|
753
753
|
trafficUserId: null,
|
|
754
754
|
elapsedTime: r,
|
|
755
755
|
requestHeaders: c,
|
|
756
756
|
requestBody: i,
|
|
757
|
-
queryParams:
|
|
757
|
+
queryParams: h,
|
|
758
758
|
responseHeaders: u,
|
|
759
|
-
responseBody:
|
|
759
|
+
responseBody: y
|
|
760
760
|
});
|
|
761
761
|
await fetch(
|
|
762
762
|
n.replace(
|
|
@@ -768,15 +768,15 @@ async function $(e) {
|
|
|
768
768
|
body: N,
|
|
769
769
|
headers: {
|
|
770
770
|
"Content-Type": "application/json",
|
|
771
|
-
Authorization: `Bearer ${
|
|
771
|
+
Authorization: `Bearer ${e}`
|
|
772
772
|
}
|
|
773
773
|
}
|
|
774
774
|
);
|
|
775
775
|
} catch (d) {
|
|
776
|
-
|
|
776
|
+
l("arkyn log error", "Error sending request", d);
|
|
777
777
|
}
|
|
778
778
|
}
|
|
779
|
-
async function p(
|
|
779
|
+
async function p(t, s, e = {}, n) {
|
|
780
780
|
const r = {
|
|
781
781
|
POST: "Resource created successfully",
|
|
782
782
|
PUT: "Resource updated successfully",
|
|
@@ -785,11 +785,11 @@ async function p(e, s, t = {}, n) {
|
|
|
785
785
|
GET: "Request successful"
|
|
786
786
|
};
|
|
787
787
|
try {
|
|
788
|
-
const a = performance.now(),
|
|
789
|
-
method:
|
|
790
|
-
headers:
|
|
788
|
+
const a = performance.now(), h = { ...e, "Content-Type": "application/json" }, i = await fetch(s, {
|
|
789
|
+
method: t,
|
|
790
|
+
headers: h,
|
|
791
791
|
body: n ? JSON.stringify(n) : void 0
|
|
792
|
-
}), c = performance.now() - a,
|
|
792
|
+
}), c = performance.now() - a, y = i.status;
|
|
793
793
|
let u = null;
|
|
794
794
|
try {
|
|
795
795
|
u = await i.json();
|
|
@@ -798,30 +798,30 @@ async function p(e, s, t = {}, n) {
|
|
|
798
798
|
}
|
|
799
799
|
const f = A.handle({
|
|
800
800
|
elapsedTime: c,
|
|
801
|
-
method:
|
|
801
|
+
method: t,
|
|
802
802
|
queryParams: new URL(s).searchParams,
|
|
803
|
-
requestHeaders:
|
|
803
|
+
requestHeaders: h,
|
|
804
804
|
requestBody: n,
|
|
805
805
|
responseBody: u,
|
|
806
806
|
responseHeaders: i.headers,
|
|
807
|
-
status:
|
|
807
|
+
status: y,
|
|
808
808
|
url: s
|
|
809
809
|
});
|
|
810
|
-
return
|
|
810
|
+
return v(f), i.ok ? {
|
|
811
811
|
success: !0,
|
|
812
|
-
status:
|
|
813
|
-
message: (u == null ? void 0 : u.message) || r[
|
|
812
|
+
status: y,
|
|
813
|
+
message: (u == null ? void 0 : u.message) || r[t],
|
|
814
814
|
response: u,
|
|
815
815
|
cause: null
|
|
816
816
|
} : {
|
|
817
817
|
success: !1,
|
|
818
|
-
status:
|
|
818
|
+
status: y,
|
|
819
819
|
message: (u == null ? void 0 : u.message) || i.statusText || "Request failed",
|
|
820
820
|
response: u,
|
|
821
821
|
cause: null
|
|
822
822
|
};
|
|
823
823
|
} catch (a) {
|
|
824
|
-
return
|
|
824
|
+
return l("Network error or request failed", null, a), {
|
|
825
825
|
success: !1,
|
|
826
826
|
status: 0,
|
|
827
827
|
message: "Network error or request failed",
|
|
@@ -830,20 +830,20 @@ async function p(e, s, t = {}, n) {
|
|
|
830
830
|
};
|
|
831
831
|
}
|
|
832
832
|
}
|
|
833
|
-
async function
|
|
834
|
-
return p("DELETE",
|
|
833
|
+
async function D(t, s = {}, e) {
|
|
834
|
+
return p("DELETE", t, s, e);
|
|
835
835
|
}
|
|
836
|
-
async function
|
|
837
|
-
return p("GET",
|
|
836
|
+
async function F(t, s = {}) {
|
|
837
|
+
return p("GET", t, s);
|
|
838
838
|
}
|
|
839
|
-
async function M(
|
|
840
|
-
return p("PATCH",
|
|
839
|
+
async function M(t, s = {}, e) {
|
|
840
|
+
return p("PATCH", t, s, e);
|
|
841
841
|
}
|
|
842
|
-
async function z(
|
|
843
|
-
return p("POST",
|
|
842
|
+
async function z(t, s = {}, e) {
|
|
843
|
+
return p("POST", t, s, e);
|
|
844
844
|
}
|
|
845
|
-
async function G(
|
|
846
|
-
return p("PUT",
|
|
845
|
+
async function G(t, s = {}, e) {
|
|
846
|
+
return p("PUT", t, s, e);
|
|
847
847
|
}
|
|
848
848
|
class W {
|
|
849
849
|
/**
|
|
@@ -852,18 +852,26 @@ class W {
|
|
|
852
852
|
* @param props.baseUrl - The base URL for the API.
|
|
853
853
|
* @param props.baseHeaders - Optional base headers to include in all requests.
|
|
854
854
|
* @param props.baseToken - Optional base token for authorization.
|
|
855
|
+
* @param props.enableDebug - Optional flag to enable debug logging for requests.
|
|
855
856
|
*/
|
|
856
857
|
constructor(s) {
|
|
857
858
|
o(this, "baseUrl");
|
|
858
859
|
o(this, "baseHeaders");
|
|
859
860
|
o(this, "baseToken");
|
|
860
|
-
this
|
|
861
|
+
o(this, "enableDebug");
|
|
862
|
+
this.baseUrl = s.baseUrl, this.baseHeaders = s.baseHeaders || void 0, this.baseToken = s.baseToken || void 0, this.enableDebug = s.enableDebug || !1;
|
|
861
863
|
}
|
|
862
864
|
/**
|
|
863
865
|
* Generates the full URL by appending the route to the base URL.
|
|
864
866
|
* @param route - The route to append to the base URL.
|
|
865
867
|
* @returns The full URL as a string.
|
|
866
868
|
*/
|
|
869
|
+
onDebug(s, e, n) {
|
|
870
|
+
if (this.enableDebug) {
|
|
871
|
+
const h = "\x1B[33m[ARKYN-API-DEBUG]\x1B[0m";
|
|
872
|
+
console.log(`${h} Base URL: ${this.baseUrl}`), console.log(`${h} Full URL: ${s}`), console.log(`${h} Method: ${e}`), n[0] && console.log(`${h} Headers: `, n[0]), n[1] && console.log(`${h} Body: `, n[1]);
|
|
873
|
+
}
|
|
874
|
+
}
|
|
867
875
|
generateURL(s) {
|
|
868
876
|
return this.baseUrl + s;
|
|
869
877
|
}
|
|
@@ -873,9 +881,9 @@ class W {
|
|
|
873
881
|
* @param token - Optional token to override the base token.
|
|
874
882
|
* @returns The merged headers as a HeadersInit object.
|
|
875
883
|
*/
|
|
876
|
-
generateHeaders(s,
|
|
884
|
+
generateHeaders(s, e) {
|
|
877
885
|
let n = {};
|
|
878
|
-
return this.baseToken && (n = { Authorization: `Bearer ${this.baseToken}` }), this.baseHeaders && (n = { ...n, ...this.baseHeaders }), s && (n = { ...n, ...s }),
|
|
886
|
+
return this.baseToken && (n = { Authorization: `Bearer ${this.baseToken}` }), this.baseHeaders && (n = { ...n, ...this.baseHeaders }), s && (n = { ...n, ...s }), e && (n = { ...n, Authorization: `Bearer ${e}` }), n;
|
|
879
887
|
}
|
|
880
888
|
/**
|
|
881
889
|
* Sends a get request to the specified route.
|
|
@@ -883,9 +891,9 @@ class W {
|
|
|
883
891
|
* @param data - The request data, including optional headers and token.
|
|
884
892
|
* @returns The API response data.
|
|
885
893
|
*/
|
|
886
|
-
async get(s,
|
|
887
|
-
const n = this.generateURL(s), r = this.generateHeaders((
|
|
888
|
-
return await
|
|
894
|
+
async get(s, e) {
|
|
895
|
+
const n = this.generateURL(s), r = this.generateHeaders((e == null ? void 0 : e.headers) || {}, e == null ? void 0 : e.token);
|
|
896
|
+
return this.onDebug(n, "get", [r]), await F(n, r);
|
|
889
897
|
}
|
|
890
898
|
/**
|
|
891
899
|
* Sends a post request to the specified route.
|
|
@@ -893,9 +901,9 @@ class W {
|
|
|
893
901
|
* @param data - The request data, including body, optional headers, and token.
|
|
894
902
|
* @returns The API response data.
|
|
895
903
|
*/
|
|
896
|
-
async post(s,
|
|
897
|
-
const n = this.generateURL(s), r = this.generateHeaders((
|
|
898
|
-
return await z(n, r, a);
|
|
904
|
+
async post(s, e) {
|
|
905
|
+
const n = this.generateURL(s), r = this.generateHeaders((e == null ? void 0 : e.headers) || {}, e == null ? void 0 : e.token), a = e == null ? void 0 : e.body;
|
|
906
|
+
return this.onDebug(n, "post", [r, a]), await z(n, r, a);
|
|
899
907
|
}
|
|
900
908
|
/**
|
|
901
909
|
* Sends a put request to the specified route.
|
|
@@ -903,9 +911,9 @@ class W {
|
|
|
903
911
|
* @param data - The request data, including body, optional headers, and token.
|
|
904
912
|
* @returns The API response data.
|
|
905
913
|
*/
|
|
906
|
-
async put(s,
|
|
907
|
-
const n = this.generateURL(s), r = this.generateHeaders((
|
|
908
|
-
return await G(n, r, a);
|
|
914
|
+
async put(s, e) {
|
|
915
|
+
const n = this.generateURL(s), r = this.generateHeaders((e == null ? void 0 : e.headers) || {}, e == null ? void 0 : e.token), a = e == null ? void 0 : e.body;
|
|
916
|
+
return this.onDebug(n, "put", [r, a]), await G(n, r, a);
|
|
909
917
|
}
|
|
910
918
|
/**
|
|
911
919
|
* Sends a patch request to the specified route.
|
|
@@ -913,9 +921,9 @@ class W {
|
|
|
913
921
|
* @param data - The request data, including body, optional headers, and token.
|
|
914
922
|
* @returns The API response data.
|
|
915
923
|
*/
|
|
916
|
-
async patch(s,
|
|
917
|
-
const n = this.generateURL(s), r = this.generateHeaders((
|
|
918
|
-
return await M(n, r, a);
|
|
924
|
+
async patch(s, e) {
|
|
925
|
+
const n = this.generateURL(s), r = this.generateHeaders((e == null ? void 0 : e.headers) || {}, e == null ? void 0 : e.token), a = e == null ? void 0 : e.body;
|
|
926
|
+
return this.onDebug(n, "patch", [r, a]), await M(n, r, a);
|
|
919
927
|
}
|
|
920
928
|
/**
|
|
921
929
|
* Sends a delete request to the specified route.
|
|
@@ -923,18 +931,18 @@ class W {
|
|
|
923
931
|
* @param data - The request data, including body, optional headers, and token.
|
|
924
932
|
* @returns The API response data.
|
|
925
933
|
*/
|
|
926
|
-
async delete(s,
|
|
927
|
-
const n = this.generateURL(s), r = this.generateHeaders((
|
|
928
|
-
return await
|
|
934
|
+
async delete(s, e) {
|
|
935
|
+
const n = this.generateURL(s), r = this.generateHeaders((e == null ? void 0 : e.headers) || {}, e == null ? void 0 : e.token), a = e == null ? void 0 : e.body;
|
|
936
|
+
return this.onDebug(n, "delete", [r, a]), await D(n, r, a);
|
|
929
937
|
}
|
|
930
938
|
}
|
|
931
|
-
function Y(
|
|
932
|
-
var
|
|
933
|
-
return
|
|
939
|
+
function Y(t, s) {
|
|
940
|
+
var e, n, r;
|
|
941
|
+
return t != null && t.message && typeof (t == null ? void 0 : t.message) == "string" ? t == null ? void 0 : t.message : t != null && t.error && typeof (t == null ? void 0 : t.error) == "string" ? t == null ? void 0 : t.error : (e = t == null ? void 0 : t.error) != null && e.message && typeof ((n = t == null ? void 0 : t.error) == null ? void 0 : n.message) == "string" ? (r = t == null ? void 0 : t.error) == null ? void 0 : r.message : s != null && s.statusText && typeof (s == null ? void 0 : s.statusText) == "string" ? s == null ? void 0 : s.statusText : "Missing error message";
|
|
934
942
|
}
|
|
935
|
-
const X = async (
|
|
943
|
+
const X = async (t) => {
|
|
936
944
|
let s;
|
|
937
|
-
const
|
|
945
|
+
const e = await t.arrayBuffer(), n = new TextDecoder().decode(e);
|
|
938
946
|
try {
|
|
939
947
|
s = JSON.parse(n);
|
|
940
948
|
} catch {
|
|
@@ -950,85 +958,85 @@ const X = async (e) => {
|
|
|
950
958
|
}
|
|
951
959
|
return s;
|
|
952
960
|
};
|
|
953
|
-
function Z(
|
|
961
|
+
function Z(t) {
|
|
954
962
|
switch (!0) {
|
|
955
|
-
case
|
|
956
|
-
return
|
|
957
|
-
case
|
|
958
|
-
return
|
|
959
|
-
case
|
|
960
|
-
return
|
|
961
|
-
case
|
|
962
|
-
return
|
|
963
|
-
case
|
|
964
|
-
return
|
|
965
|
-
case
|
|
966
|
-
return
|
|
963
|
+
case t instanceof Response:
|
|
964
|
+
return t;
|
|
965
|
+
case t instanceof H:
|
|
966
|
+
return t.toResponse();
|
|
967
|
+
case t instanceof B:
|
|
968
|
+
return t.toResponse();
|
|
969
|
+
case t instanceof L:
|
|
970
|
+
return t.toResponse();
|
|
971
|
+
case t instanceof $:
|
|
972
|
+
return t.toResponse();
|
|
973
|
+
case t instanceof P:
|
|
974
|
+
return t.toResponse();
|
|
967
975
|
}
|
|
968
976
|
switch (!0) {
|
|
969
|
-
case
|
|
970
|
-
return
|
|
971
|
-
case
|
|
972
|
-
return
|
|
973
|
-
case
|
|
974
|
-
return
|
|
975
|
-
case
|
|
976
|
-
return
|
|
977
|
-
case
|
|
978
|
-
return
|
|
979
|
-
case
|
|
980
|
-
return
|
|
981
|
-
case
|
|
982
|
-
return
|
|
983
|
-
case
|
|
984
|
-
return
|
|
985
|
-
case
|
|
986
|
-
return
|
|
987
|
-
}
|
|
988
|
-
return new b("Server error",
|
|
977
|
+
case t instanceof j:
|
|
978
|
+
return t.toResponse();
|
|
979
|
+
case t instanceof T:
|
|
980
|
+
return t.toResponse();
|
|
981
|
+
case t instanceof O:
|
|
982
|
+
return t.toResponse();
|
|
983
|
+
case t instanceof E:
|
|
984
|
+
return t.toResponse();
|
|
985
|
+
case t instanceof J:
|
|
986
|
+
return t.toResponse();
|
|
987
|
+
case t instanceof C:
|
|
988
|
+
return t.toResponse();
|
|
989
|
+
case t instanceof b:
|
|
990
|
+
return t.toResponse();
|
|
991
|
+
case t instanceof q:
|
|
992
|
+
return t.toResponse();
|
|
993
|
+
case t instanceof m:
|
|
994
|
+
return t.toResponse();
|
|
995
|
+
}
|
|
996
|
+
return new b("Server error", t).toResponse();
|
|
989
997
|
}
|
|
990
998
|
function V([
|
|
991
|
-
|
|
999
|
+
t,
|
|
992
1000
|
s
|
|
993
1001
|
]) {
|
|
994
|
-
const
|
|
995
|
-
if (
|
|
1002
|
+
const e = s.safeParse(t);
|
|
1003
|
+
if (e.success === !1) {
|
|
996
1004
|
const n = Object.fromEntries(
|
|
997
|
-
|
|
1005
|
+
e.error.issues.map((r) => (console.log(r), [r.path.join("."), r.message]))
|
|
998
1006
|
);
|
|
999
1007
|
return {
|
|
1000
|
-
success:
|
|
1008
|
+
success: e.success,
|
|
1001
1009
|
fieldErrors: n,
|
|
1002
|
-
fields:
|
|
1010
|
+
fields: t
|
|
1003
1011
|
};
|
|
1004
1012
|
} else
|
|
1005
1013
|
return {
|
|
1006
|
-
success:
|
|
1007
|
-
data:
|
|
1014
|
+
success: e.success,
|
|
1015
|
+
data: e.data
|
|
1008
1016
|
};
|
|
1009
1017
|
}
|
|
1010
|
-
const ss = (
|
|
1011
|
-
const
|
|
1012
|
-
if (s === "") return
|
|
1018
|
+
const ss = (t, s = "") => {
|
|
1019
|
+
const e = new URL(t.url);
|
|
1020
|
+
if (s === "") return e.searchParams;
|
|
1013
1021
|
const n = Array.from(
|
|
1014
|
-
|
|
1022
|
+
e.searchParams.entries()
|
|
1015
1023
|
).filter(([r]) => r.startsWith(`${s}:`)).map(([r, a]) => [r.replace(`${s}:`, ""), a]);
|
|
1016
1024
|
return new URLSearchParams(n);
|
|
1017
1025
|
};
|
|
1018
|
-
function _(
|
|
1019
|
-
const s = "Error validating:",
|
|
1026
|
+
function _(t) {
|
|
1027
|
+
const s = "Error validating:", e = t.issues.map(
|
|
1020
1028
|
({ path: n, message: r }) => `-> ${n.join(".")}: ${r}`
|
|
1021
1029
|
);
|
|
1022
|
-
return [s, ...
|
|
1030
|
+
return [s, ...e].join(`
|
|
1023
1031
|
`);
|
|
1024
1032
|
}
|
|
1025
|
-
class
|
|
1033
|
+
class es {
|
|
1026
1034
|
constructor(s) {
|
|
1027
1035
|
o(this, "functionName");
|
|
1028
1036
|
o(this, "callerInfo");
|
|
1029
1037
|
this.schema = s;
|
|
1030
|
-
const { callerInfo:
|
|
1031
|
-
this.callerInfo =
|
|
1038
|
+
const { callerInfo: e, functionName: n } = x();
|
|
1039
|
+
this.callerInfo = e, this.functionName = n;
|
|
1032
1040
|
}
|
|
1033
1041
|
isValid(s) {
|
|
1034
1042
|
return this.schema.safeParse(s).success;
|
|
@@ -1039,21 +1047,21 @@ class ts {
|
|
|
1039
1047
|
validate(s) {
|
|
1040
1048
|
try {
|
|
1041
1049
|
return this.schema.parse(s);
|
|
1042
|
-
} catch (
|
|
1043
|
-
throw new b(_(
|
|
1050
|
+
} catch (e) {
|
|
1051
|
+
throw new b(_(e));
|
|
1044
1052
|
}
|
|
1045
1053
|
}
|
|
1046
|
-
formValidate(s,
|
|
1054
|
+
formValidate(s, e) {
|
|
1047
1055
|
const n = V([s, this.schema]);
|
|
1048
1056
|
if (!n.success) {
|
|
1049
|
-
|
|
1057
|
+
l("UnprocessableEntity", n);
|
|
1050
1058
|
const r = Object.keys(n.fieldErrors)[0];
|
|
1051
1059
|
throw new m(
|
|
1052
1060
|
{
|
|
1053
1061
|
fields: n.fields,
|
|
1054
1062
|
fieldErrors: n.fieldErrors,
|
|
1055
1063
|
data: { scrollTo: r },
|
|
1056
|
-
message:
|
|
1064
|
+
message: e
|
|
1057
1065
|
},
|
|
1058
1066
|
!1
|
|
1059
1067
|
);
|
|
@@ -1064,27 +1072,27 @@ class ts {
|
|
|
1064
1072
|
export {
|
|
1065
1073
|
W as ApiService,
|
|
1066
1074
|
w as ArkynLogService,
|
|
1067
|
-
|
|
1075
|
+
j as BadGateway,
|
|
1068
1076
|
T as BadRequest,
|
|
1069
|
-
|
|
1070
|
-
|
|
1077
|
+
O as Conflict,
|
|
1078
|
+
B as Created,
|
|
1071
1079
|
E as Forbidden,
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1080
|
+
H as Found,
|
|
1081
|
+
R as HttpDebugService,
|
|
1082
|
+
P as NoContent,
|
|
1075
1083
|
J as NotFound,
|
|
1076
1084
|
C as NotImplemented,
|
|
1077
|
-
|
|
1085
|
+
es as SchemaValidator,
|
|
1078
1086
|
b as ServerError,
|
|
1079
|
-
|
|
1087
|
+
$ as Success,
|
|
1080
1088
|
q as Unauthorized,
|
|
1081
1089
|
m as UnprocessableEntity,
|
|
1082
|
-
|
|
1090
|
+
L as Updated,
|
|
1083
1091
|
Y as decodeErrorMessageFromRequest,
|
|
1084
1092
|
X as decodeRequestBody,
|
|
1085
1093
|
Z as errorHandler,
|
|
1086
1094
|
V as formParse,
|
|
1087
|
-
|
|
1095
|
+
x as getCaller,
|
|
1088
1096
|
ss as getScopedParams,
|
|
1089
|
-
|
|
1097
|
+
l as httpDebug
|
|
1090
1098
|
};
|
package/dist/bundle.umd.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
(function(a,
|
|
2
|
-
`).map(c=>c.trim()),r=x.ignoreFile;let u=2;for(;u<n.length&&(n[u].includes("node:internal")||n[u].includes("/node_modules/"));)u++;if(r)for(;u<n.length&&n[u].includes(r);)u++;const
|
|
3
|
-
`;c+=`${h} Caller Function: ${
|
|
1
|
+
(function(a,y){typeof exports=="object"&&typeof module<"u"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):(a=typeof globalThis<"u"?globalThis:a||self,y(a["@arkyn/server"]={}))})(this,function(a){"use strict";var Z=Object.defineProperty;var ss=(a,y,p)=>y in a?Z(a,y,{enumerable:!0,configurable:!0,writable:!0,value:p}):a[y]=p;var o=(a,y,p)=>ss(a,typeof y!="symbol"?y+"":y,p);const y={};function p(){const t=process.cwd(),n=(new Error().stack||"").split(`
|
|
2
|
+
`).map(c=>c.trim()),r=x.ignoreFile;let u=2;for(;u<n.length&&(n[u].includes("node:internal")||n[u].includes("/node_modules/"));)u++;if(r)for(;u<n.length&&n[u].includes(r);)u++;const l=n[u]||"";let h="Unknown function",i="Unknown caller";const f=l.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);if(f)h=f[1],i=f[2];else{const c=l.match(/at\s+(.+)/);if(c){i=c[1];const T=i.match(/at\s+([^(\s]+)\s+/);T&&T[1]!=="new"&&(h=T[1])}}i.includes("(")&&(i=i.substring(i.indexOf("(")+1,i.lastIndexOf(")"))),i=i.split(":").slice(0,-2).join(":");try{i=y.relative(t,i)}catch{}return{functionName:h,callerInfo:i}}class x{static setIgnoreFile(s){this.ignoreFile=s}}o(x,"ignoreFile");function d(t,s,e){var r;if(process.env.NODE_ENV==="development"||((r=process.env)==null?void 0:r.SHOW_ERRORS_IN_CONSOLE)==="true"){const h="\x1B[36m[ARKYN-DEBUG]\x1B[0m",{callerInfo:i,functionName:f}=p();let c=`${h} ${t} initialized
|
|
3
|
+
`;c+=`${h} Caller Function: ${f}
|
|
4
4
|
`,c+=`${h} Caller Location: ${i}
|
|
5
5
|
`,c+=`${h} Body: ${JSON.stringify(s,null,2)}
|
|
6
6
|
`,e&&(c+=`${h} Cause: ${JSON.stringify(e,null,2)}
|
|
7
|
-
`),console.log(c)}}class N{constructor(s,e){o(this,"body");o(this,"cause");o(this,"status",502);o(this,"statusText");this.body={name:"BadGateway",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,y("BadGateway",this.body,this.cause)}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 m{constructor(s,e){o(this,"body");o(this,"cause");o(this,"status",400);o(this,"statusText");this.body={name:"BadRequest",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,y("BadRequest",this.body,this.cause)}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class k{constructor(s,e){o(this,"body");o(this,"cause");o(this,"status",409);o(this,"statusText");this.body={name:"Conflict",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,y("Conflict",this.body,this.cause)}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{constructor(s,e){o(this,"body");o(this,"cause");o(this,"status",403);o(this,"statusText");this.body={name:"Forbidden",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,y("Forbidden",this.body,this.cause)}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class U{constructor(s,e){o(this,"body");o(this,"cause");o(this,"status",404);o(this,"statusText");this.body={name:"NotFound",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,y("NotFound",this.body,this.cause)}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{constructor(s,e){o(this,"body");o(this,"cause");o(this,"status",501);o(this,"statusText");this.body={name:"NotImplemented",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,y("NotImplemented",this.body,this.cause)}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{constructor(s,e){o(this,"body");o(this,"cause");o(this,"status",500);o(this,"statusText");this.body={name:"ServerError",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,y("ServerError",this.body,this.cause)}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{constructor(s,e){o(this,"body");o(this,"cause");o(this,"status",401);o(this,"statusText");this.body={name:"Unauthorized",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,y("Unauthorized",this.body,this.cause)}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{constructor(s,e=!1){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},e&&y("UnprocessableEntity",this.body)}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{constructor(s,e){o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||201,this.statusText=(e==null?void 0:e.statusText)||"Resource created successfully"}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class J{constructor(s,e){o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||302,this.statusText=(e==null?void 0:e.statusText)||"Found"}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 C{constructor(s){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"}toResponse(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return new Response(null,s)}}class q{constructor(s,e){o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||200,this.statusText=(e==null?void 0:e.statusText)??"OK"}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 P{constructor(s,e){o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||200,this.statusText=(e==null?void 0:e.statusText)||"Resource updated successfully"}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(s){return s instanceof Headers?Object.fromEntries(s.entries()):typeof s=="object"?Object.entries(s).reduce((e,[n,r])=>(typeof r=="string"?e[n]=r:Array.isArray(r)?e[n]=r.join(", "):e[n]=JSON.stringify(r),e),{}):{}}static mapQueryParams(s){const e={};return s.forEach((n,r)=>{e[r]=n}),e}static handle(s){return{rawUrl:s.url,status:s.status,method:s.method,token:null,elapsedTime:s.elapsedTime,requestHeaders:this.mapHeaders(s.requestHeaders),requestBody:s.requestBody||null,queryParams:this.mapQueryParams(s.queryParams),responseHeaders:this.mapHeaders(s.responseHeaders),responseBody:s.responseBody||null}}}class w{static setArkynConfig(s){if(this.arkynConfig)return;let n=s.arkynLogBaseApiUrl||"https://logs-arkyn-flow-logs.vw6wo7.easypanel.host";n=n+"/http-traffic-records/:trafficSourceId",this.arkynConfig={arkynTrafficSourceId:s.arkynTrafficSourceId,arkynUserToken:s.arkynUserToken,arkynApiUrl:n}}static getArkynConfig(){return this.arkynConfig}static resetArkynConfig(){this.arkynConfig=void 0}}o(w,"arkynConfig");async function L(t){const s=w.getArkynConfig();if(!s)return;const{arkynUserToken:e,arkynApiUrl:n}=s,{elapsedTime:r,method:u,queryParams:p,requestBody:h,requestHeaders:i,responseBody:d,responseHeaders:c,status:T,token:es,rawUrl:Y}=t;try{const b=new URL(Y);let B="HTTPS";b.protocol==="http:"&&(B="HTTP");const X=JSON.stringify({domainUrl:b.protocol+"//"+b.host,pathnameUrl:b.pathname,status:T,protocol:B,method:u,trafficUserId:null,elapsedTime:r,requestHeaders:i,requestBody:h,queryParams:p,responseHeaders:c,responseBody:d});await fetch(n.replace(":trafficSourceId",s.arkynTrafficSourceId),{method:"POST",body:X,headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`}})}catch(b){y("arkyn log error","Error sending request",b)}}async function g(t,s,e={},n){const r={POST:"Resource created successfully",PUT:"Resource updated successfully",DELETE:"Resource deleted successfully",PATCH:"Resource patched successfully",GET:"Request successful"};try{const u=performance.now(),p={...e,"Content-Type":"application/json"},h=await fetch(s,{method:t,headers:p,body:n?JSON.stringify(n):void 0}),i=performance.now()-u,d=h.status;let c=null;try{c=await h.json()}catch{c=null}const T=v.handle({elapsedTime:i,method:t,queryParams:new URL(s).searchParams,requestHeaders:p,requestBody:n,responseBody:c,responseHeaders:h.headers,status:d,url:s});return L(T),h.ok?{success:!0,status:d,message:(c==null?void 0:c.message)||r[t],response:c,cause:null}:{success:!1,status:d,message:(c==null?void 0:c.message)||h.statusText||"Request failed",response:c,cause:null}}catch(u){return y("Network error or request failed",null,u),{success:!1,status:0,message:"Network error or request failed",response:null,cause:u instanceof Error?u.message:String(u)}}}async function A(t,s={},e){return g("DELETE",t,s,e)}async function F(t,s={}){return g("GET",t,s)}async function $(t,s={},e){return g("PATCH",t,s,e)}async function D(t,s={},e){return g("POST",t,s,e)}async function M(t,s={},e){return g("PUT",t,s,e)}class z{constructor(s){o(this,"baseUrl");o(this,"baseHeaders");o(this,"baseToken");this.baseUrl=s.baseUrl,this.baseHeaders=s.baseHeaders||void 0,this.baseToken=s.baseToken||void 0}generateURL(s){return this.baseUrl+s}generateHeaders(s,e){let n={};return this.baseToken&&(n={Authorization:`Bearer ${this.baseToken}`}),this.baseHeaders&&(n={...n,...this.baseHeaders}),s&&(n={...n,...s}),e&&(n={...n,Authorization:`Bearer ${e}`}),n}async get(s,e){const n=this.generateURL(s),r=this.generateHeaders((e==null?void 0:e.headers)||{},e==null?void 0:e.token);return await F(n,r)}async post(s,e){const n=this.generateURL(s),r=this.generateHeaders((e==null?void 0:e.headers)||{},e==null?void 0:e.token),u=e==null?void 0:e.body;return await D(n,r,u)}async put(s,e){const n=this.generateURL(s),r=this.generateHeaders((e==null?void 0:e.headers)||{},e==null?void 0:e.token),u=e==null?void 0:e.body;return await M(n,r,u)}async patch(s,e){const n=this.generateURL(s),r=this.generateHeaders((e==null?void 0:e.headers)||{},e==null?void 0:e.token),u=e==null?void 0:e.body;return await $(n,r,u)}async delete(s,e){const n=this.generateURL(s),r=this.generateHeaders((e==null?void 0:e.headers)||{},e==null?void 0:e.token),u=e==null?void 0:e.body;return await A(n,r,u)}}function G(t,s){var e,n,r;return t!=null&&t.message&&typeof(t==null?void 0:t.message)=="string"?t==null?void 0:t.message:t!=null&&t.error&&typeof(t==null?void 0:t.error)=="string"?t==null?void 0:t.error:(e=t==null?void 0:t.error)!=null&&e.message&&typeof((n=t==null?void 0:t.error)==null?void 0:n.message)=="string"?(r=t==null?void 0:t.error)==null?void 0:r.message:s!=null&&s.statusText&&typeof(s==null?void 0:s.statusText)=="string"?s==null?void 0:s.statusText:"Missing error message"}const V=async t=>{let s;const e=await t.arrayBuffer(),n=new TextDecoder().decode(e);try{s=JSON.parse(n)}catch{try{if(n.includes("=")){const u=new URLSearchParams(n);s=Object.fromEntries(u.entries())}else throw new m("Invalid URLSearchParams format")}catch{throw new m("Failed to extract data from request")}}return s};function _(t){switch(!0){case t instanceof Response:return t;case t instanceof J:return t.toResponse();case t instanceof E:return t.toResponse();case t instanceof P:return t.toResponse();case t instanceof q:return t.toResponse();case t instanceof C:return t.toResponse()}switch(!0){case t instanceof N:return t.toResponse();case t instanceof m:return t.toResponse();case t instanceof k:return t.toResponse();case t instanceof I:return t.toResponse();case t instanceof U:return t.toResponse();case t instanceof j:return t.toResponse();case t instanceof R:return t.toResponse();case t instanceof O:return t.toResponse();case t instanceof S:return t.toResponse()}return new R("Server error",t).toResponse()}function H([t,s]){const e=s.safeParse(t);if(e.success===!1){const n=Object.fromEntries(e.error.issues.map(r=>(console.log(r),[r.path.join("."),r.message])));return{success:e.success,fieldErrors:n,fields:t}}else return{success:e.success,data:e.data}}const K=(t,s="")=>{const e=new URL(t.url);if(s==="")return e.searchParams;const n=Array.from(e.searchParams.entries()).filter(([r])=>r.startsWith(`${s}:`)).map(([r,u])=>[r.replace(`${s}:`,""),u]);return new URLSearchParams(n)};function Q(t){const s="Error validating:",e=t.issues.map(({path:n,message:r})=>`-> ${n.join(".")}: ${r}`);return[s,...e].join(`
|
|
8
|
-
`)}class W{constructor(s){o(this,"functionName");o(this,"callerInfo");this.schema=s;const{callerInfo:e,functionName:n}=
|
|
7
|
+
`),console.log(c)}}class N{constructor(s,e){o(this,"body");o(this,"cause");o(this,"status",502);o(this,"statusText");this.body={name:"BadGateway",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,d("BadGateway",this.body,this.cause)}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 m{constructor(s,e){o(this,"body");o(this,"cause");o(this,"status",400);o(this,"statusText");this.body={name:"BadRequest",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,d("BadRequest",this.body,this.cause)}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class U{constructor(s,e){o(this,"body");o(this,"cause");o(this,"status",409);o(this,"statusText");this.body={name:"Conflict",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,d("Conflict",this.body,this.cause)}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class k{constructor(s,e){o(this,"body");o(this,"cause");o(this,"status",403);o(this,"statusText");this.body={name:"Forbidden",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,d("Forbidden",this.body,this.cause)}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{constructor(s,e){o(this,"body");o(this,"cause");o(this,"status",404);o(this,"statusText");this.body={name:"NotFound",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,d("NotFound",this.body,this.cause)}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{constructor(s,e){o(this,"body");o(this,"cause");o(this,"status",501);o(this,"statusText");this.body={name:"NotImplemented",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,d("NotImplemented",this.body,this.cause)}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{constructor(s,e){o(this,"body");o(this,"cause");o(this,"status",500);o(this,"statusText");this.body={name:"ServerError",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,d("ServerError",this.body,this.cause)}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{constructor(s,e){o(this,"body");o(this,"cause");o(this,"status",401);o(this,"statusText");this.body={name:"Unauthorized",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,d("Unauthorized",this.body,this.cause)}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{constructor(s,e=!1){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},e&&d("UnprocessableEntity",this.body)}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{constructor(s,e){o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||201,this.statusText=(e==null?void 0:e.statusText)||"Resource created successfully"}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class J{constructor(s,e){o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||302,this.statusText=(e==null?void 0:e.statusText)||"Found"}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 C{constructor(s){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"}toResponse(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return new Response(null,s)}}class q{constructor(s,e){o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||200,this.statusText=(e==null?void 0:e.statusText)??"OK"}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{constructor(s,e){o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||200,this.statusText=(e==null?void 0:e.statusText)||"Resource updated successfully"}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class ${static mapHeaders(s){return s instanceof Headers?Object.fromEntries(s.entries()):typeof s=="object"?Object.entries(s).reduce((e,[n,r])=>(typeof r=="string"?e[n]=r:Array.isArray(r)?e[n]=r.join(", "):e[n]=JSON.stringify(r),e),{}):{}}static mapQueryParams(s){const e={};return s.forEach((n,r)=>{e[r]=n}),e}static handle(s){return{rawUrl:s.url,status:s.status,method:s.method,token:null,elapsedTime:s.elapsedTime,requestHeaders:this.mapHeaders(s.requestHeaders),requestBody:s.requestBody||null,queryParams:this.mapQueryParams(s.queryParams),responseHeaders:this.mapHeaders(s.responseHeaders),responseBody:s.responseBody||null}}}class S{static setArkynConfig(s){if(this.arkynConfig)return;let n=s.arkynLogBaseApiUrl||"https://logs-arkyn-flow-logs.vw6wo7.easypanel.host";n=n+"/http-traffic-records/:trafficSourceId",this.arkynConfig={arkynTrafficSourceId:s.arkynTrafficSourceId,arkynUserToken:s.arkynUserToken,arkynApiUrl:n}}static getArkynConfig(){return this.arkynConfig}static resetArkynConfig(){this.arkynConfig=void 0}}o(S,"arkynConfig");async function v(t){const s=S.getArkynConfig();if(!s)return;const{arkynUserToken:e,arkynApiUrl:n}=s,{elapsedTime:r,method:u,queryParams:l,requestBody:h,requestHeaders:i,responseBody:f,responseHeaders:c,status:T,token:es,rawUrl:Y}=t;try{const b=new URL(Y);let H="HTTPS";b.protocol==="http:"&&(H="HTTP");const X=JSON.stringify({domainUrl:b.protocol+"//"+b.host,pathnameUrl:b.pathname,status:T,protocol:H,method:u,trafficUserId:null,elapsedTime:r,requestHeaders:i,requestBody:h,queryParams:l,responseHeaders:c,responseBody:f});await fetch(n.replace(":trafficSourceId",s.arkynTrafficSourceId),{method:"POST",body:X,headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`}})}catch(b){d("arkyn log error","Error sending request",b)}}async function g(t,s,e={},n){const r={POST:"Resource created successfully",PUT:"Resource updated successfully",DELETE:"Resource deleted successfully",PATCH:"Resource patched successfully",GET:"Request successful"};try{const u=performance.now(),l={...e,"Content-Type":"application/json"},h=await fetch(s,{method:t,headers:l,body:n?JSON.stringify(n):void 0}),i=performance.now()-u,f=h.status;let c=null;try{c=await h.json()}catch{c=null}const T=$.handle({elapsedTime:i,method:t,queryParams:new URL(s).searchParams,requestHeaders:l,requestBody:n,responseBody:c,responseHeaders:h.headers,status:f,url:s});return v(T),h.ok?{success:!0,status:f,message:(c==null?void 0:c.message)||r[t],response:c,cause:null}:{success:!1,status:f,message:(c==null?void 0:c.message)||h.statusText||"Request failed",response:c,cause:null}}catch(u){return d("Network error or request failed",null,u),{success:!1,status:0,message:"Network error or request failed",response:null,cause:u instanceof Error?u.message:String(u)}}}async function L(t,s={},e){return g("DELETE",t,s,e)}async function A(t,s={}){return g("GET",t,s)}async function D(t,s={},e){return g("PATCH",t,s,e)}async function F(t,s={},e){return g("POST",t,s,e)}async function M(t,s={},e){return g("PUT",t,s,e)}class z{constructor(s){o(this,"baseUrl");o(this,"baseHeaders");o(this,"baseToken");o(this,"enableDebug");this.baseUrl=s.baseUrl,this.baseHeaders=s.baseHeaders||void 0,this.baseToken=s.baseToken||void 0,this.enableDebug=s.enableDebug||!1}onDebug(s,e,n){if(this.enableDebug){const l="\x1B[33m[ARKYN-API-DEBUG]\x1B[0m";console.log(`${l} Base URL: ${this.baseUrl}`),console.log(`${l} Full URL: ${s}`),console.log(`${l} Method: ${e}`),n[0]&&console.log(`${l} Headers: `,n[0]),n[1]&&console.log(`${l} Body: `,n[1])}}generateURL(s){return this.baseUrl+s}generateHeaders(s,e){let n={};return this.baseToken&&(n={Authorization:`Bearer ${this.baseToken}`}),this.baseHeaders&&(n={...n,...this.baseHeaders}),s&&(n={...n,...s}),e&&(n={...n,Authorization:`Bearer ${e}`}),n}async get(s,e){const n=this.generateURL(s),r=this.generateHeaders((e==null?void 0:e.headers)||{},e==null?void 0:e.token);return this.onDebug(n,"get",[r]),await A(n,r)}async post(s,e){const n=this.generateURL(s),r=this.generateHeaders((e==null?void 0:e.headers)||{},e==null?void 0:e.token),u=e==null?void 0:e.body;return this.onDebug(n,"post",[r,u]),await F(n,r,u)}async put(s,e){const n=this.generateURL(s),r=this.generateHeaders((e==null?void 0:e.headers)||{},e==null?void 0:e.token),u=e==null?void 0:e.body;return this.onDebug(n,"put",[r,u]),await M(n,r,u)}async patch(s,e){const n=this.generateURL(s),r=this.generateHeaders((e==null?void 0:e.headers)||{},e==null?void 0:e.token),u=e==null?void 0:e.body;return this.onDebug(n,"patch",[r,u]),await D(n,r,u)}async delete(s,e){const n=this.generateURL(s),r=this.generateHeaders((e==null?void 0:e.headers)||{},e==null?void 0:e.token),u=e==null?void 0:e.body;return this.onDebug(n,"delete",[r,u]),await L(n,r,u)}}function G(t,s){var e,n,r;return t!=null&&t.message&&typeof(t==null?void 0:t.message)=="string"?t==null?void 0:t.message:t!=null&&t.error&&typeof(t==null?void 0:t.error)=="string"?t==null?void 0:t.error:(e=t==null?void 0:t.error)!=null&&e.message&&typeof((n=t==null?void 0:t.error)==null?void 0:n.message)=="string"?(r=t==null?void 0:t.error)==null?void 0:r.message:s!=null&&s.statusText&&typeof(s==null?void 0:s.statusText)=="string"?s==null?void 0:s.statusText:"Missing error message"}const V=async t=>{let s;const e=await t.arrayBuffer(),n=new TextDecoder().decode(e);try{s=JSON.parse(n)}catch{try{if(n.includes("=")){const u=new URLSearchParams(n);s=Object.fromEntries(u.entries())}else throw new m("Invalid URLSearchParams format")}catch{throw new m("Failed to extract data from request")}}return s};function _(t){switch(!0){case t instanceof Response:return t;case t instanceof J:return t.toResponse();case t instanceof E:return t.toResponse();case t instanceof B:return t.toResponse();case t instanceof q:return t.toResponse();case t instanceof C:return t.toResponse()}switch(!0){case t instanceof N:return t.toResponse();case t instanceof m:return t.toResponse();case t instanceof U:return t.toResponse();case t instanceof k:return t.toResponse();case t instanceof I:return t.toResponse();case t instanceof j:return t.toResponse();case t instanceof R:return t.toResponse();case t instanceof O:return t.toResponse();case t instanceof w:return t.toResponse()}return new R("Server error",t).toResponse()}function P([t,s]){const e=s.safeParse(t);if(e.success===!1){const n=Object.fromEntries(e.error.issues.map(r=>(console.log(r),[r.path.join("."),r.message])));return{success:e.success,fieldErrors:n,fields:t}}else return{success:e.success,data:e.data}}const K=(t,s="")=>{const e=new URL(t.url);if(s==="")return e.searchParams;const n=Array.from(e.searchParams.entries()).filter(([r])=>r.startsWith(`${s}:`)).map(([r,u])=>[r.replace(`${s}:`,""),u]);return new URLSearchParams(n)};function Q(t){const s="Error validating:",e=t.issues.map(({path:n,message:r})=>`-> ${n.join(".")}: ${r}`);return[s,...e].join(`
|
|
8
|
+
`)}class W{constructor(s){o(this,"functionName");o(this,"callerInfo");this.schema=s;const{callerInfo:e,functionName:n}=p();this.callerInfo=e,this.functionName=n}isValid(s){return this.schema.safeParse(s).success}safeValidate(s){return this.schema.safeParse(s)}validate(s){try{return this.schema.parse(s)}catch(e){throw new R(Q(e))}}formValidate(s,e){const n=P([s,this.schema]);if(!n.success){d("UnprocessableEntity",n);const r=Object.keys(n.fieldErrors)[0];throw new w({fields:n.fields,fieldErrors:n.fieldErrors,data:{scrollTo:r},message:e},!1)}return n.data}}a.ApiService=z,a.ArkynLogService=S,a.BadGateway=N,a.BadRequest=m,a.Conflict=U,a.Created=E,a.Forbidden=k,a.Found=J,a.HttpDebugService=x,a.NoContent=C,a.NotFound=I,a.NotImplemented=j,a.SchemaValidator=W,a.ServerError=R,a.Success=q,a.Unauthorized=O,a.UnprocessableEntity=w,a.Updated=B,a.decodeErrorMessageFromRequest=G,a.decodeRequestBody=V,a.errorHandler=_,a.formParse=P,a.getCaller=p,a.getScopedParams=K,a.httpDebug=d,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -2,6 +2,7 @@ type ApiServiceConstructorProps = {
|
|
|
2
2
|
baseUrl: string;
|
|
3
3
|
baseHeaders?: HeadersInit;
|
|
4
4
|
baseToken?: string | null;
|
|
5
|
+
enableDebug?: boolean;
|
|
5
6
|
};
|
|
6
7
|
type ApiRequestDataWithoutBodyProps = {
|
|
7
8
|
headers?: HeadersInit;
|
|
@@ -19,12 +20,14 @@ declare class ApiService {
|
|
|
19
20
|
private baseUrl;
|
|
20
21
|
private baseHeaders?;
|
|
21
22
|
private baseToken?;
|
|
23
|
+
private enableDebug?;
|
|
22
24
|
/**
|
|
23
25
|
* Creates an instance of ApiService.
|
|
24
26
|
* @param props - The configuration properties for the API instance.
|
|
25
27
|
* @param props.baseUrl - The base URL for the API.
|
|
26
28
|
* @param props.baseHeaders - Optional base headers to include in all requests.
|
|
27
29
|
* @param props.baseToken - Optional base token for authorization.
|
|
30
|
+
* @param props.enableDebug - Optional flag to enable debug logging for requests.
|
|
28
31
|
*/
|
|
29
32
|
constructor(props: ApiServiceConstructorProps);
|
|
30
33
|
/**
|
|
@@ -32,6 +35,7 @@ declare class ApiService {
|
|
|
32
35
|
* @param route - The route to append to the base URL.
|
|
33
36
|
* @returns The full URL as a string.
|
|
34
37
|
*/
|
|
38
|
+
private onDebug;
|
|
35
39
|
private generateURL;
|
|
36
40
|
/**
|
|
37
41
|
* Generates the headers for a request by merging base headers, provided headers, and tokens.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiService.d.ts","sourceRoot":"","sources":["../../src/services/apiService.ts"],"names":[],"mappings":"AAMA,KAAK,0BAA0B,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"apiService.d.ts","sourceRoot":"","sources":["../../src/services/apiService.ts"],"names":[],"mappings":"AAMA,KAAK,0BAA0B,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,KAAK,8BAA8B,GAAG;IACpC,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,2BAA2B,GAAG;IACjC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AAEH,cAAM,UAAU;IACd,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAC,CAAc;IAClC,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,WAAW,CAAC,CAAU;IAE9B;;;;;;;OAOG;gBAES,KAAK,EAAE,0BAA0B;IAO7C;;;;OAIG;IAEH,OAAO,CAAC,OAAO;IAcf,OAAO,CAAC,WAAW;IAInB;;;;;OAKG;IAEH,OAAO,CAAC,eAAe;IAcvB;;;;;OAKG;IAEG,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,8BAA8B;IAQ9D;;;;;OAKG;IAEG,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAS5D;;;;;OAKG;IAEG,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAS3D;;;;;OAKG;IAEG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAS7D;;;;;OAKG;IAEG,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;CAQ/D;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -10,23 +10,40 @@ class ApiService {
|
|
|
10
10
|
baseUrl;
|
|
11
11
|
baseHeaders;
|
|
12
12
|
baseToken;
|
|
13
|
+
enableDebug;
|
|
13
14
|
/**
|
|
14
15
|
* Creates an instance of ApiService.
|
|
15
16
|
* @param props - The configuration properties for the API instance.
|
|
16
17
|
* @param props.baseUrl - The base URL for the API.
|
|
17
18
|
* @param props.baseHeaders - Optional base headers to include in all requests.
|
|
18
19
|
* @param props.baseToken - Optional base token for authorization.
|
|
20
|
+
* @param props.enableDebug - Optional flag to enable debug logging for requests.
|
|
19
21
|
*/
|
|
20
22
|
constructor(props) {
|
|
21
23
|
this.baseUrl = props.baseUrl;
|
|
22
24
|
this.baseHeaders = props.baseHeaders || undefined;
|
|
23
25
|
this.baseToken = props.baseToken || undefined;
|
|
26
|
+
this.enableDebug = props.enableDebug || false;
|
|
24
27
|
}
|
|
25
28
|
/**
|
|
26
29
|
* Generates the full URL by appending the route to the base URL.
|
|
27
30
|
* @param route - The route to append to the base URL.
|
|
28
31
|
* @returns The full URL as a string.
|
|
29
32
|
*/
|
|
33
|
+
onDebug(fullRoute, method, data) {
|
|
34
|
+
if (this.enableDebug) {
|
|
35
|
+
const reset = "\x1b[0m";
|
|
36
|
+
const yellow = "\x1b[33m";
|
|
37
|
+
const debugName = `${yellow}[ARKYN-API-DEBUG]${reset}`;
|
|
38
|
+
console.log(`${debugName} Base URL: ${this.baseUrl}`);
|
|
39
|
+
console.log(`${debugName} Full URL: ${fullRoute}`);
|
|
40
|
+
console.log(`${debugName} Method: ${method}`);
|
|
41
|
+
if (data[0])
|
|
42
|
+
console.log(`${debugName} Headers: `, data[0]);
|
|
43
|
+
if (data[1])
|
|
44
|
+
console.log(`${debugName} Body: `, data[1]);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
30
47
|
generateURL(route) {
|
|
31
48
|
return this.baseUrl + route;
|
|
32
49
|
}
|
|
@@ -57,6 +74,7 @@ class ApiService {
|
|
|
57
74
|
async get(route, data) {
|
|
58
75
|
const url = this.generateURL(route);
|
|
59
76
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
77
|
+
this.onDebug(url, "get", [headers]);
|
|
60
78
|
return await getRequest(url, headers);
|
|
61
79
|
}
|
|
62
80
|
/**
|
|
@@ -69,6 +87,7 @@ class ApiService {
|
|
|
69
87
|
const url = this.generateURL(route);
|
|
70
88
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
71
89
|
const body = data?.body;
|
|
90
|
+
this.onDebug(url, "post", [headers, body]);
|
|
72
91
|
return await postRequest(url, headers, body);
|
|
73
92
|
}
|
|
74
93
|
/**
|
|
@@ -81,6 +100,7 @@ class ApiService {
|
|
|
81
100
|
const url = this.generateURL(route);
|
|
82
101
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
83
102
|
const body = data?.body;
|
|
103
|
+
this.onDebug(url, "put", [headers, body]);
|
|
84
104
|
return await putRequest(url, headers, body);
|
|
85
105
|
}
|
|
86
106
|
/**
|
|
@@ -93,6 +113,7 @@ class ApiService {
|
|
|
93
113
|
const url = this.generateURL(route);
|
|
94
114
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
95
115
|
const body = data?.body;
|
|
116
|
+
this.onDebug(url, "patch", [headers, body]);
|
|
96
117
|
return await patchRequest(url, headers, body);
|
|
97
118
|
}
|
|
98
119
|
/**
|
|
@@ -105,6 +126,7 @@ class ApiService {
|
|
|
105
126
|
const url = this.generateURL(route);
|
|
106
127
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
107
128
|
const body = data?.body;
|
|
129
|
+
this.onDebug(url, "delete", [headers, body]);
|
|
108
130
|
return await deleteRequest(url, headers, body);
|
|
109
131
|
}
|
|
110
132
|
}
|