@arkyn/server 3.0.1-beta.62 → 3.0.1-beta.64
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 +172 -171
- package/dist/bundle.umd.cjs +15 -14
- package/dist/services/apiService.d.ts +15 -15
- package/dist/services/apiService.d.ts.map +1 -1
- package/dist/services/apiService.js +30 -30
- package/dist/services/flushDebugLogs.d.ts.map +1 -1
- package/dist/services/flushDebugLogs.js +3 -2
- package/dist/services/formParse.d.ts.map +1 -1
- package/dist/services/formParse.js +0 -1
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var U = Object.defineProperty;
|
|
2
2
|
var I = (n, t, s) => t in n ? U(n, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : n[t] = s;
|
|
3
|
-
var
|
|
4
|
-
function
|
|
3
|
+
var r = (n, t, s) => I(n, typeof t != "symbol" ? t + "" : t, s);
|
|
4
|
+
function f(n) {
|
|
5
5
|
var s;
|
|
6
6
|
if (process.env.NODE_ENV === "development" || ((s = process.env) == null ? void 0 : s.SHOW_ERRORS_IN_CONSOLE) === "true") {
|
|
7
7
|
const u = `${{
|
|
@@ -10,11 +10,12 @@ function g(n) {
|
|
|
10
10
|
red: "\x1B[31m",
|
|
11
11
|
green: "\x1B[32m"
|
|
12
12
|
}[n.scheme]}[${n.name}]\x1B[0m`;
|
|
13
|
-
let c =
|
|
13
|
+
let c = `<------------------->
|
|
14
|
+
`;
|
|
14
15
|
n.debugs.forEach((h) => {
|
|
15
|
-
c += `${u} ${h}
|
|
16
|
+
c += `${u} ${h.trim()}
|
|
16
17
|
`;
|
|
17
|
-
}), console.log(c);
|
|
18
|
+
}), c += "<------------------->", console.log(c);
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
const k = {};
|
|
@@ -57,15 +58,15 @@ class S {
|
|
|
57
58
|
* The name of the file to ignore when analyzing the stack trace.
|
|
58
59
|
* When set, the `getCaller` function will skip stack frames containing this file name.
|
|
59
60
|
*/
|
|
60
|
-
|
|
61
|
+
r(S, "ignoreFiles", []);
|
|
61
62
|
function R() {
|
|
62
63
|
const n = process.cwd(), e = (new Error().stack || "").split(`
|
|
63
|
-
`).map((a) => a.trim()),
|
|
64
|
+
`).map((a) => a.trim()), o = S.ignoreFiles;
|
|
64
65
|
let u = 2;
|
|
65
66
|
for (; u < e.length && (e[u].includes("node:internal") || e[u].includes("/node_modules/")); )
|
|
66
67
|
u++;
|
|
67
|
-
if (
|
|
68
|
-
for (; u < e.length &&
|
|
68
|
+
if (o.length > 0)
|
|
69
|
+
for (; u < e.length && o.some(
|
|
69
70
|
(a) => e[u].includes(a)
|
|
70
71
|
); )
|
|
71
72
|
u++;
|
|
@@ -78,8 +79,8 @@ function R() {
|
|
|
78
79
|
const a = c.match(/at\s+(.+)/);
|
|
79
80
|
if (a) {
|
|
80
81
|
i = a[1];
|
|
81
|
-
const
|
|
82
|
-
|
|
82
|
+
const p = i.match(/at\s+([^(\s]+)\s+/);
|
|
83
|
+
p && p[1] !== "new" && (h = p[1]);
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
i.includes("(") && (i = i.substring(
|
|
@@ -107,13 +108,13 @@ class d {
|
|
|
107
108
|
* ```
|
|
108
109
|
*/
|
|
109
110
|
onDebug(t, s, e) {
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
`),
|
|
113
|
-
`),
|
|
114
|
-
`),
|
|
115
|
-
`), e &&
|
|
116
|
-
`),
|
|
111
|
+
const o = [], { callerInfo: u, functionName: c } = R();
|
|
112
|
+
o.push(`${t} initialized
|
|
113
|
+
`), o.push(`Caller Function: ${c}
|
|
114
|
+
`), o.push(`Caller Location: ${u}
|
|
115
|
+
`), o.push(`Body: ${JSON.stringify(s, null, 2)}
|
|
116
|
+
`), e && o.push(`Cause: ${JSON.stringify(e, null, 2)}
|
|
117
|
+
`), f({ scheme: "red", name: "ARKYN-BAD-RESPONSE-DEBUG", debugs: o });
|
|
117
118
|
}
|
|
118
119
|
}
|
|
119
120
|
class j extends d {
|
|
@@ -125,10 +126,10 @@ class j extends d {
|
|
|
125
126
|
*/
|
|
126
127
|
constructor(s, e) {
|
|
127
128
|
super();
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
r(this, "body");
|
|
130
|
+
r(this, "cause");
|
|
131
|
+
r(this, "status", 502);
|
|
132
|
+
r(this, "statusText");
|
|
132
133
|
this.body = { name: "BadGateway", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug("BadGateway", this.body, this.cause);
|
|
133
134
|
}
|
|
134
135
|
/**
|
|
@@ -159,7 +160,7 @@ class j extends d {
|
|
|
159
160
|
return Response.json(this.body, s);
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
|
-
class
|
|
163
|
+
class g extends d {
|
|
163
164
|
/**
|
|
164
165
|
* Creates an instance of the `BadRequest` class.
|
|
165
166
|
*
|
|
@@ -168,10 +169,10 @@ class b extends d {
|
|
|
168
169
|
*/
|
|
169
170
|
constructor(s, e) {
|
|
170
171
|
super();
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
r(this, "body");
|
|
173
|
+
r(this, "cause");
|
|
174
|
+
r(this, "status", 400);
|
|
175
|
+
r(this, "statusText");
|
|
175
176
|
this.body = { name: "BadRequest", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug("BadRequest", this.body, this.cause);
|
|
176
177
|
}
|
|
177
178
|
/**
|
|
@@ -211,10 +212,10 @@ class J extends d {
|
|
|
211
212
|
*/
|
|
212
213
|
constructor(s, e) {
|
|
213
214
|
super();
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
215
|
+
r(this, "body");
|
|
216
|
+
r(this, "cause");
|
|
217
|
+
r(this, "status", 409);
|
|
218
|
+
r(this, "statusText");
|
|
218
219
|
this.body = { name: "Conflict", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug("Conflict", this.body, this.cause);
|
|
219
220
|
}
|
|
220
221
|
/**
|
|
@@ -254,10 +255,10 @@ class D extends d {
|
|
|
254
255
|
*/
|
|
255
256
|
constructor(s, e) {
|
|
256
257
|
super();
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
258
|
+
r(this, "body");
|
|
259
|
+
r(this, "cause");
|
|
260
|
+
r(this, "status", 403);
|
|
261
|
+
r(this, "statusText");
|
|
261
262
|
this.body = { name: "Forbidden", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug("Forbidden", this.body, this.cause);
|
|
262
263
|
}
|
|
263
264
|
/**
|
|
@@ -297,10 +298,10 @@ class C extends d {
|
|
|
297
298
|
*/
|
|
298
299
|
constructor(s, e) {
|
|
299
300
|
super();
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
301
|
+
r(this, "body");
|
|
302
|
+
r(this, "cause");
|
|
303
|
+
r(this, "status", 404);
|
|
304
|
+
r(this, "statusText");
|
|
304
305
|
this.body = { name: "NotFound", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug("NotFound", this.body, this.cause);
|
|
305
306
|
}
|
|
306
307
|
/**
|
|
@@ -340,10 +341,10 @@ class B extends d {
|
|
|
340
341
|
*/
|
|
341
342
|
constructor(s, e) {
|
|
342
343
|
super();
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
344
|
+
r(this, "body");
|
|
345
|
+
r(this, "cause");
|
|
346
|
+
r(this, "status", 501);
|
|
347
|
+
r(this, "statusText");
|
|
347
348
|
this.body = { name: "NotImplemented", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug("NotImplemented", this.body, this.cause);
|
|
348
349
|
}
|
|
349
350
|
/**
|
|
@@ -383,10 +384,10 @@ class x extends d {
|
|
|
383
384
|
*/
|
|
384
385
|
constructor(s, e) {
|
|
385
386
|
super();
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
387
|
+
r(this, "body");
|
|
388
|
+
r(this, "cause");
|
|
389
|
+
r(this, "status", 500);
|
|
390
|
+
r(this, "statusText");
|
|
390
391
|
this.body = { name: "ServerError", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug("ServerError", this.body, this.cause);
|
|
391
392
|
}
|
|
392
393
|
/**
|
|
@@ -417,7 +418,7 @@ class x extends d {
|
|
|
417
418
|
return Response.json(this.body, s);
|
|
418
419
|
}
|
|
419
420
|
}
|
|
420
|
-
class
|
|
421
|
+
class q extends d {
|
|
421
422
|
/**
|
|
422
423
|
* Creates an instance of the `Unauthorized` class.
|
|
423
424
|
*
|
|
@@ -426,10 +427,10 @@ class $ extends d {
|
|
|
426
427
|
*/
|
|
427
428
|
constructor(s, e) {
|
|
428
429
|
super();
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
430
|
+
r(this, "body");
|
|
431
|
+
r(this, "cause");
|
|
432
|
+
r(this, "status", 401);
|
|
433
|
+
r(this, "statusText");
|
|
433
434
|
this.body = { name: "Unauthorized", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug("Unauthorized", this.body, this.cause);
|
|
434
435
|
}
|
|
435
436
|
/**
|
|
@@ -460,7 +461,7 @@ class $ extends d {
|
|
|
460
461
|
return Response.json(this.body, s);
|
|
461
462
|
}
|
|
462
463
|
}
|
|
463
|
-
class
|
|
464
|
+
class N extends d {
|
|
464
465
|
/**
|
|
465
466
|
* Creates an instance of the `UnprocessableEntity` class.
|
|
466
467
|
*
|
|
@@ -473,9 +474,9 @@ class w extends d {
|
|
|
473
474
|
*/
|
|
474
475
|
constructor(s) {
|
|
475
476
|
super();
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
477
|
+
r(this, "body");
|
|
478
|
+
r(this, "status", 422);
|
|
479
|
+
r(this, "statusText");
|
|
479
480
|
this.statusText = s.message || "Unprocessable Entity", this.body = {
|
|
480
481
|
name: "UnprocessableEntity",
|
|
481
482
|
message: s.message || null,
|
|
@@ -512,7 +513,7 @@ class w extends d {
|
|
|
512
513
|
return Response.json(this.body, s);
|
|
513
514
|
}
|
|
514
515
|
}
|
|
515
|
-
class
|
|
516
|
+
class T {
|
|
516
517
|
/**
|
|
517
518
|
* Logs debug information for success responses including caller context and response details.
|
|
518
519
|
*
|
|
@@ -527,20 +528,20 @@ class f {
|
|
|
527
528
|
* ```
|
|
528
529
|
*/
|
|
529
530
|
onDebug(t, s, e) {
|
|
530
|
-
const
|
|
531
|
-
|
|
532
|
-
`),
|
|
533
|
-
`),
|
|
534
|
-
`),
|
|
535
|
-
`), e &&
|
|
536
|
-
`),
|
|
531
|
+
const o = [], { callerInfo: u, functionName: c } = R();
|
|
532
|
+
o.push(`${t} initialized
|
|
533
|
+
`), o.push(`Caller Function: ${c}
|
|
534
|
+
`), o.push(`Caller Location: ${u}
|
|
535
|
+
`), o.push(`Body: ${JSON.stringify(s, null, 2)}
|
|
536
|
+
`), e && o.push(`Cause: ${JSON.stringify(e, null, 2)}
|
|
537
|
+
`), f({
|
|
537
538
|
scheme: "green",
|
|
538
539
|
name: "ARKYN-SUCCESS-RESPONSE-DEBUG",
|
|
539
|
-
debugs:
|
|
540
|
+
debugs: o
|
|
540
541
|
});
|
|
541
542
|
}
|
|
542
543
|
}
|
|
543
|
-
class
|
|
544
|
+
class P extends T {
|
|
544
545
|
/**
|
|
545
546
|
* Creates an instance of the `Created` class.
|
|
546
547
|
*
|
|
@@ -549,10 +550,10 @@ class q extends f {
|
|
|
549
550
|
*/
|
|
550
551
|
constructor(s, e) {
|
|
551
552
|
super();
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
553
|
+
r(this, "body");
|
|
554
|
+
r(this, "headers");
|
|
555
|
+
r(this, "status");
|
|
556
|
+
r(this, "statusText");
|
|
556
557
|
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", this.onDebug("Created", s);
|
|
557
558
|
}
|
|
558
559
|
/**
|
|
@@ -584,7 +585,7 @@ class q extends f {
|
|
|
584
585
|
return Response.json(this.body, s);
|
|
585
586
|
}
|
|
586
587
|
}
|
|
587
|
-
class
|
|
588
|
+
class H extends T {
|
|
588
589
|
/**
|
|
589
590
|
* Creates an instance of the `Found` class.
|
|
590
591
|
*
|
|
@@ -596,10 +597,10 @@ class P extends f {
|
|
|
596
597
|
*/
|
|
597
598
|
constructor(s, e) {
|
|
598
599
|
super();
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
600
|
+
r(this, "body");
|
|
601
|
+
r(this, "headers");
|
|
602
|
+
r(this, "status");
|
|
603
|
+
r(this, "statusText");
|
|
603
604
|
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", this.onDebug("Found", s);
|
|
604
605
|
}
|
|
605
606
|
/**
|
|
@@ -631,7 +632,7 @@ class P extends f {
|
|
|
631
632
|
return Response.json(this.body, s);
|
|
632
633
|
}
|
|
633
634
|
}
|
|
634
|
-
class
|
|
635
|
+
class L extends T {
|
|
635
636
|
/**
|
|
636
637
|
* Creates an instance of the `NoContent` class.
|
|
637
638
|
*
|
|
@@ -639,9 +640,9 @@ class H extends f {
|
|
|
639
640
|
*/
|
|
640
641
|
constructor(s) {
|
|
641
642
|
super();
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
643
|
+
r(this, "headers");
|
|
644
|
+
r(this, "status");
|
|
645
|
+
r(this, "statusText");
|
|
645
646
|
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);
|
|
646
647
|
}
|
|
647
648
|
/**
|
|
@@ -659,7 +660,7 @@ class H extends f {
|
|
|
659
660
|
return new Response(null, s);
|
|
660
661
|
}
|
|
661
662
|
}
|
|
662
|
-
class
|
|
663
|
+
class $ extends T {
|
|
663
664
|
/**
|
|
664
665
|
* Creates an instance of the `Success` class.
|
|
665
666
|
*
|
|
@@ -668,10 +669,10 @@ class L extends f {
|
|
|
668
669
|
*/
|
|
669
670
|
constructor(s, e) {
|
|
670
671
|
super();
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
672
|
+
r(this, "body");
|
|
673
|
+
r(this, "headers");
|
|
674
|
+
r(this, "status");
|
|
675
|
+
r(this, "statusText");
|
|
675
676
|
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", this.onDebug("Success", s);
|
|
676
677
|
}
|
|
677
678
|
/**
|
|
@@ -703,7 +704,7 @@ class L extends f {
|
|
|
703
704
|
return Response.json(this.body, s);
|
|
704
705
|
}
|
|
705
706
|
}
|
|
706
|
-
class A extends
|
|
707
|
+
class A extends T {
|
|
707
708
|
/**
|
|
708
709
|
* Creates an instance of the `Updated` class.
|
|
709
710
|
*
|
|
@@ -712,10 +713,10 @@ class A extends f {
|
|
|
712
713
|
*/
|
|
713
714
|
constructor(s, e) {
|
|
714
715
|
super();
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
716
|
+
r(this, "body");
|
|
717
|
+
r(this, "headers");
|
|
718
|
+
r(this, "status");
|
|
719
|
+
r(this, "statusText");
|
|
719
720
|
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", this.onDebug("Updated", s);
|
|
720
721
|
}
|
|
721
722
|
/**
|
|
@@ -749,12 +750,12 @@ class A extends f {
|
|
|
749
750
|
}
|
|
750
751
|
class v {
|
|
751
752
|
static mapHeaders(t) {
|
|
752
|
-
return t instanceof Headers ? Object.fromEntries(t.entries()) : typeof t == "object" ? Object.entries(t).reduce((s, [e,
|
|
753
|
+
return t instanceof Headers ? Object.fromEntries(t.entries()) : typeof t == "object" ? Object.entries(t).reduce((s, [e, o]) => (typeof o == "string" ? s[e] = o : Array.isArray(o) ? s[e] = o.join(", ") : s[e] = JSON.stringify(o), s), {}) : {};
|
|
753
754
|
}
|
|
754
755
|
static mapQueryParams(t) {
|
|
755
756
|
const s = {};
|
|
756
|
-
return t.forEach((e,
|
|
757
|
-
s[
|
|
757
|
+
return t.forEach((e, o) => {
|
|
758
|
+
s[o] = e;
|
|
758
759
|
}), s;
|
|
759
760
|
}
|
|
760
761
|
static handle(t) {
|
|
@@ -772,7 +773,7 @@ class v {
|
|
|
772
773
|
};
|
|
773
774
|
}
|
|
774
775
|
}
|
|
775
|
-
class
|
|
776
|
+
class w {
|
|
776
777
|
/**
|
|
777
778
|
* Sets the configuration for the arkyn. This method initializes the arkyn configuration
|
|
778
779
|
* with the provided `arkynConfig` values. If the configuration has already been set,
|
|
@@ -810,35 +811,35 @@ class N {
|
|
|
810
811
|
this.arkynConfig = void 0;
|
|
811
812
|
}
|
|
812
813
|
}
|
|
813
|
-
|
|
814
|
+
r(w, "arkynConfig");
|
|
814
815
|
async function F(n) {
|
|
815
|
-
const t =
|
|
816
|
+
const t = w.getArkynConfig();
|
|
816
817
|
if (!t) return;
|
|
817
818
|
const { arkynUserToken: s, arkynApiUrl: e } = t, {
|
|
818
|
-
elapsedTime:
|
|
819
|
+
elapsedTime: o,
|
|
819
820
|
method: u,
|
|
820
821
|
queryParams: c,
|
|
821
822
|
requestBody: h,
|
|
822
823
|
requestHeaders: i,
|
|
823
824
|
responseBody: l,
|
|
824
825
|
responseHeaders: a,
|
|
825
|
-
status:
|
|
826
|
+
status: p,
|
|
826
827
|
token: Q,
|
|
827
828
|
rawUrl: E
|
|
828
829
|
} = n;
|
|
829
830
|
if (process.env.NODE_ENV !== "development")
|
|
830
831
|
try {
|
|
831
|
-
const
|
|
832
|
+
const y = new URL(E);
|
|
832
833
|
let m = "HTTPS";
|
|
833
|
-
|
|
834
|
+
y.protocol === "http:" && (m = "HTTP");
|
|
834
835
|
const O = JSON.stringify({
|
|
835
|
-
domainUrl:
|
|
836
|
-
pathnameUrl:
|
|
837
|
-
status:
|
|
836
|
+
domainUrl: y.protocol + "//" + y.host,
|
|
837
|
+
pathnameUrl: y.pathname,
|
|
838
|
+
status: p,
|
|
838
839
|
protocol: m,
|
|
839
840
|
method: u,
|
|
840
841
|
trafficUserId: null,
|
|
841
|
-
elapsedTime:
|
|
842
|
+
elapsedTime: o,
|
|
842
843
|
requestHeaders: i,
|
|
843
844
|
requestBody: h,
|
|
844
845
|
queryParams: c,
|
|
@@ -859,16 +860,16 @@ async function F(n) {
|
|
|
859
860
|
}
|
|
860
861
|
}
|
|
861
862
|
);
|
|
862
|
-
} catch (
|
|
863
|
-
|
|
864
|
-
debugs: [`Error sending request: ${
|
|
863
|
+
} catch (y) {
|
|
864
|
+
f({
|
|
865
|
+
debugs: [`Error sending request: ${y}`],
|
|
865
866
|
name: "ARKYN_LOG_ERROR",
|
|
866
867
|
scheme: "red"
|
|
867
868
|
});
|
|
868
869
|
}
|
|
869
870
|
}
|
|
870
|
-
async function
|
|
871
|
-
const
|
|
871
|
+
async function b(n, t, s = {}, e) {
|
|
872
|
+
const o = {
|
|
872
873
|
POST: "Resource created successfully",
|
|
873
874
|
PUT: "Resource updated successfully",
|
|
874
875
|
DELETE: "Resource deleted successfully",
|
|
@@ -887,7 +888,7 @@ async function T(n, t, s = {}, e) {
|
|
|
887
888
|
} catch {
|
|
888
889
|
a = null;
|
|
889
890
|
}
|
|
890
|
-
const
|
|
891
|
+
const p = v.handle({
|
|
891
892
|
elapsedTime: i,
|
|
892
893
|
method: n,
|
|
893
894
|
queryParams: new URL(t).searchParams,
|
|
@@ -898,10 +899,10 @@ async function T(n, t, s = {}, e) {
|
|
|
898
899
|
status: l,
|
|
899
900
|
url: t
|
|
900
901
|
});
|
|
901
|
-
return F(
|
|
902
|
+
return F(p), h.ok ? {
|
|
902
903
|
success: !0,
|
|
903
904
|
status: l,
|
|
904
|
-
message: (a == null ? void 0 : a.message) ||
|
|
905
|
+
message: (a == null ? void 0 : a.message) || o[n],
|
|
905
906
|
response: a,
|
|
906
907
|
cause: null
|
|
907
908
|
} : {
|
|
@@ -912,7 +913,7 @@ async function T(n, t, s = {}, e) {
|
|
|
912
913
|
cause: null
|
|
913
914
|
};
|
|
914
915
|
} catch (u) {
|
|
915
|
-
return
|
|
916
|
+
return f({
|
|
916
917
|
debugs: [`Network error or request failed: ${u}`],
|
|
917
918
|
name: "ARKYN_MAKE_REQUEST_ERROR",
|
|
918
919
|
scheme: "red"
|
|
@@ -926,19 +927,19 @@ async function T(n, t, s = {}, e) {
|
|
|
926
927
|
}
|
|
927
928
|
}
|
|
928
929
|
async function M(n, t = {}, s) {
|
|
929
|
-
return
|
|
930
|
+
return b("DELETE", n, t, s);
|
|
930
931
|
}
|
|
931
932
|
async function _(n, t = {}) {
|
|
932
|
-
return
|
|
933
|
+
return b("GET", n, t);
|
|
933
934
|
}
|
|
934
935
|
async function z(n, t = {}, s) {
|
|
935
|
-
return
|
|
936
|
+
return b("PATCH", n, t, s);
|
|
936
937
|
}
|
|
937
938
|
async function G(n, t = {}, s) {
|
|
938
|
-
return
|
|
939
|
+
return b("POST", n, t, s);
|
|
939
940
|
}
|
|
940
941
|
async function K(n, t = {}, s) {
|
|
941
|
-
return
|
|
942
|
+
return b("PUT", n, t, s);
|
|
942
943
|
}
|
|
943
944
|
class X {
|
|
944
945
|
/**
|
|
@@ -950,10 +951,10 @@ class X {
|
|
|
950
951
|
* @param props.enableDebug - Optional flag to enable debug logging for requests.
|
|
951
952
|
*/
|
|
952
953
|
constructor(t) {
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
954
|
+
r(this, "baseUrl");
|
|
955
|
+
r(this, "baseHeaders");
|
|
956
|
+
r(this, "baseToken");
|
|
957
|
+
r(this, "enableDebug");
|
|
957
958
|
this.baseUrl = t.baseUrl, this.baseHeaders = t.baseHeaders || void 0, this.baseToken = t.baseToken || void 0, this.enableDebug = t.enableDebug || !1;
|
|
958
959
|
}
|
|
959
960
|
/**
|
|
@@ -963,8 +964,8 @@ class X {
|
|
|
963
964
|
*/
|
|
964
965
|
onDebug(t, s, e) {
|
|
965
966
|
if (this.enableDebug) {
|
|
966
|
-
const
|
|
967
|
-
|
|
967
|
+
const o = [];
|
|
968
|
+
o.push(`Base URL: ${this.baseUrl}`), o.push(`Endpoint URL: ${t}`), o.push(`Method: ${s}`), e[0] && o.push(`Headers: ${JSON.stringify(e[0])}`), e[1] && o.push(`Body: ${JSON.stringify(e[1])}`), f({ debugs: o, name: "ARKYN-API-DEBUG", scheme: "yellow" });
|
|
968
969
|
}
|
|
969
970
|
}
|
|
970
971
|
generateURL(t) {
|
|
@@ -981,59 +982,59 @@ class X {
|
|
|
981
982
|
return this.baseToken && (e = { Authorization: `Bearer ${this.baseToken}` }), this.baseHeaders && (e = { ...e, ...this.baseHeaders }), t && (e = { ...e, ...t }), s && (e = { ...e, Authorization: `Bearer ${s}` }), e;
|
|
982
983
|
}
|
|
983
984
|
/**
|
|
984
|
-
* Sends a get request to the specified
|
|
985
|
-
* @param
|
|
985
|
+
* Sends a get request to the specified endpoint.
|
|
986
|
+
* @param endpoint - The API endpoint to send the get request to.
|
|
986
987
|
* @param data - The request data, including optional headers and token.
|
|
987
988
|
* @returns The API response data.
|
|
988
989
|
*/
|
|
989
990
|
async get(t, s) {
|
|
990
|
-
const e = this.generateURL(t),
|
|
991
|
-
return this.onDebug(e, "get", [
|
|
991
|
+
const e = this.generateURL(t), o = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token);
|
|
992
|
+
return this.onDebug(e, "get", [o]), await _(e, o);
|
|
992
993
|
}
|
|
993
994
|
/**
|
|
994
|
-
* Sends a post request to the specified
|
|
995
|
-
* @param
|
|
995
|
+
* Sends a post request to the specified endpoint.
|
|
996
|
+
* @param endpoint - The API endpoint to send the post request to.
|
|
996
997
|
* @param data - The request data, including body, optional headers, and token.
|
|
997
998
|
* @returns The API response data.
|
|
998
999
|
*/
|
|
999
1000
|
async post(t, s) {
|
|
1000
|
-
const e = this.generateURL(t),
|
|
1001
|
-
return this.onDebug(e, "post", [
|
|
1001
|
+
const e = this.generateURL(t), o = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
|
|
1002
|
+
return this.onDebug(e, "post", [o, u]), await G(e, o, u);
|
|
1002
1003
|
}
|
|
1003
1004
|
/**
|
|
1004
|
-
* Sends a put request to the specified
|
|
1005
|
-
* @param
|
|
1005
|
+
* Sends a put request to the specified endpoint.
|
|
1006
|
+
* @param endpoint - The API endpoint to send the put request to.
|
|
1006
1007
|
* @param data - The request data, including body, optional headers, and token.
|
|
1007
1008
|
* @returns The API response data.
|
|
1008
1009
|
*/
|
|
1009
1010
|
async put(t, s) {
|
|
1010
|
-
const e = this.generateURL(t),
|
|
1011
|
-
return this.onDebug(
|
|
1011
|
+
const e = this.generateURL(t), o = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
|
|
1012
|
+
return this.onDebug(t, "put", [o, u]), await K(e, o, u);
|
|
1012
1013
|
}
|
|
1013
1014
|
/**
|
|
1014
|
-
* Sends a patch request to the specified
|
|
1015
|
-
* @param
|
|
1015
|
+
* Sends a patch request to the specified endpoint.
|
|
1016
|
+
* @param endpoint - The API endpoint to send the patch request to.
|
|
1016
1017
|
* @param data - The request data, including body, optional headers, and token.
|
|
1017
1018
|
* @returns The API response data.
|
|
1018
1019
|
*/
|
|
1019
1020
|
async patch(t, s) {
|
|
1020
|
-
const e = this.generateURL(t),
|
|
1021
|
-
return this.onDebug(e, "patch", [
|
|
1021
|
+
const e = this.generateURL(t), o = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
|
|
1022
|
+
return this.onDebug(e, "patch", [o, u]), await z(e, o, u);
|
|
1022
1023
|
}
|
|
1023
1024
|
/**
|
|
1024
|
-
* Sends a delete request to the specified
|
|
1025
|
-
* @param
|
|
1025
|
+
* Sends a delete request to the specified endpoint.
|
|
1026
|
+
* @param endpoint - The API endpoint to send the delete request to.
|
|
1026
1027
|
* @param data - The request data, including body, optional headers, and token.
|
|
1027
1028
|
* @returns The API response data.
|
|
1028
1029
|
*/
|
|
1029
1030
|
async delete(t, s) {
|
|
1030
|
-
const e = this.generateURL(t),
|
|
1031
|
-
return this.onDebug(e, "delete", [
|
|
1031
|
+
const e = this.generateURL(t), o = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
|
|
1032
|
+
return this.onDebug(e, "delete", [o, u]), await M(e, o, u);
|
|
1032
1033
|
}
|
|
1033
1034
|
}
|
|
1034
1035
|
function Z(n, t) {
|
|
1035
|
-
var s, e,
|
|
1036
|
-
return n != null && n.message && typeof (n == null ? void 0 : n.message) == "string" ? n == null ? void 0 : n.message : n != null && n.error && typeof (n == null ? void 0 : n.error) == "string" ? n == null ? void 0 : n.error : (s = n == null ? void 0 : n.error) != null && s.message && typeof ((e = n == null ? void 0 : n.error) == null ? void 0 : e.message) == "string" ? (
|
|
1036
|
+
var s, e, o;
|
|
1037
|
+
return n != null && n.message && typeof (n == null ? void 0 : n.message) == "string" ? n == null ? void 0 : n.message : n != null && n.error && typeof (n == null ? void 0 : n.error) == "string" ? n == null ? void 0 : n.error : (s = n == null ? void 0 : n.error) != null && s.message && typeof ((e = n == null ? void 0 : n.error) == null ? void 0 : e.message) == "string" ? (o = n == null ? void 0 : n.error) == null ? void 0 : o.message : t != null && t.statusText && typeof (t == null ? void 0 : t.statusText) == "string" ? t == null ? void 0 : t.statusText : "Missing error message";
|
|
1037
1038
|
}
|
|
1038
1039
|
const ss = async (n) => {
|
|
1039
1040
|
let t;
|
|
@@ -1046,9 +1047,9 @@ const ss = async (n) => {
|
|
|
1046
1047
|
const u = new URLSearchParams(e);
|
|
1047
1048
|
t = Object.fromEntries(u.entries());
|
|
1048
1049
|
} else
|
|
1049
|
-
throw new
|
|
1050
|
+
throw new g("Invalid URLSearchParams format");
|
|
1050
1051
|
} catch {
|
|
1051
|
-
throw new
|
|
1052
|
+
throw new g("Failed to extract data from request");
|
|
1052
1053
|
}
|
|
1053
1054
|
}
|
|
1054
1055
|
return t;
|
|
@@ -1057,21 +1058,21 @@ function es(n) {
|
|
|
1057
1058
|
switch (!0) {
|
|
1058
1059
|
case n instanceof Response:
|
|
1059
1060
|
return n;
|
|
1060
|
-
case n instanceof
|
|
1061
|
+
case n instanceof H:
|
|
1061
1062
|
return n.toResponse();
|
|
1062
|
-
case n instanceof
|
|
1063
|
+
case n instanceof P:
|
|
1063
1064
|
return n.toResponse();
|
|
1064
1065
|
case n instanceof A:
|
|
1065
1066
|
return n.toResponse();
|
|
1066
|
-
case n instanceof
|
|
1067
|
+
case n instanceof $:
|
|
1067
1068
|
return n.toResponse();
|
|
1068
|
-
case n instanceof
|
|
1069
|
+
case n instanceof L:
|
|
1069
1070
|
return n.toResponse();
|
|
1070
1071
|
}
|
|
1071
1072
|
switch (!0) {
|
|
1072
1073
|
case n instanceof j:
|
|
1073
1074
|
return n.toResponse();
|
|
1074
|
-
case n instanceof
|
|
1075
|
+
case n instanceof g:
|
|
1075
1076
|
return n.toResponse();
|
|
1076
1077
|
case n instanceof J:
|
|
1077
1078
|
return n.toResponse();
|
|
@@ -1083,9 +1084,9 @@ function es(n) {
|
|
|
1083
1084
|
return n.toResponse();
|
|
1084
1085
|
case n instanceof x:
|
|
1085
1086
|
return n.toResponse();
|
|
1086
|
-
case n instanceof
|
|
1087
|
+
case n instanceof q:
|
|
1087
1088
|
return n.toResponse();
|
|
1088
|
-
case n instanceof
|
|
1089
|
+
case n instanceof N:
|
|
1089
1090
|
return n.toResponse();
|
|
1090
1091
|
}
|
|
1091
1092
|
return new x("Server error", n).toResponse();
|
|
@@ -1097,7 +1098,7 @@ function V([
|
|
|
1097
1098
|
const s = t.safeParse(n);
|
|
1098
1099
|
if (s.success === !1) {
|
|
1099
1100
|
const e = Object.fromEntries(
|
|
1100
|
-
s.error.issues.map((
|
|
1101
|
+
s.error.issues.map((o) => [o.path.join("."), o.message])
|
|
1101
1102
|
);
|
|
1102
1103
|
return {
|
|
1103
1104
|
success: s.success,
|
|
@@ -1115,20 +1116,20 @@ const ts = (n, t = "") => {
|
|
|
1115
1116
|
if (t === "") return s.searchParams;
|
|
1116
1117
|
const e = Array.from(
|
|
1117
1118
|
s.searchParams.entries()
|
|
1118
|
-
).filter(([
|
|
1119
|
+
).filter(([o]) => o.startsWith(`${t}:`)).map(([o, u]) => [o.replace(`${t}:`, ""), u]);
|
|
1119
1120
|
return new URLSearchParams(e);
|
|
1120
1121
|
};
|
|
1121
1122
|
function Y(n) {
|
|
1122
1123
|
const t = "Error validating:", s = n.issues.map(
|
|
1123
|
-
({ path: e, message:
|
|
1124
|
+
({ path: e, message: o }) => `-> ${e.join(".")}: ${o}`
|
|
1124
1125
|
);
|
|
1125
1126
|
return [t, ...s].join(`
|
|
1126
1127
|
`);
|
|
1127
1128
|
}
|
|
1128
1129
|
class ns {
|
|
1129
1130
|
constructor(t) {
|
|
1130
|
-
|
|
1131
|
-
|
|
1131
|
+
r(this, "functionName");
|
|
1132
|
+
r(this, "callerInfo");
|
|
1132
1133
|
this.schema = t;
|
|
1133
1134
|
const { callerInfo: s, functionName: e } = R();
|
|
1134
1135
|
this.callerInfo = s, this.functionName = e;
|
|
@@ -1149,11 +1150,11 @@ class ns {
|
|
|
1149
1150
|
formValidate(t, s) {
|
|
1150
1151
|
const e = V([t, this.schema]);
|
|
1151
1152
|
if (!e.success) {
|
|
1152
|
-
const
|
|
1153
|
-
throw new
|
|
1153
|
+
const o = Object.keys(e.fieldErrors)[0];
|
|
1154
|
+
throw new N({
|
|
1154
1155
|
fields: e.fields,
|
|
1155
1156
|
fieldErrors: e.fieldErrors,
|
|
1156
|
-
data: { scrollTo:
|
|
1157
|
+
data: { scrollTo: o },
|
|
1157
1158
|
message: s
|
|
1158
1159
|
});
|
|
1159
1160
|
}
|
|
@@ -1162,27 +1163,27 @@ class ns {
|
|
|
1162
1163
|
}
|
|
1163
1164
|
export {
|
|
1164
1165
|
X as ApiService,
|
|
1165
|
-
|
|
1166
|
+
w as ArkynLogService,
|
|
1166
1167
|
j as BadGateway,
|
|
1167
|
-
|
|
1168
|
+
g as BadRequest,
|
|
1168
1169
|
J as Conflict,
|
|
1169
|
-
|
|
1170
|
+
P as Created,
|
|
1170
1171
|
S as DebugService,
|
|
1171
1172
|
D as Forbidden,
|
|
1172
|
-
|
|
1173
|
-
|
|
1173
|
+
H as Found,
|
|
1174
|
+
L as NoContent,
|
|
1174
1175
|
C as NotFound,
|
|
1175
1176
|
B as NotImplemented,
|
|
1176
1177
|
ns as SchemaValidator,
|
|
1177
1178
|
x as ServerError,
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1179
|
+
$ as Success,
|
|
1180
|
+
q as Unauthorized,
|
|
1181
|
+
N as UnprocessableEntity,
|
|
1181
1182
|
A as Updated,
|
|
1182
1183
|
Z as decodeErrorMessageFromRequest,
|
|
1183
1184
|
ss as decodeRequestBody,
|
|
1184
1185
|
es as errorHandler,
|
|
1185
|
-
|
|
1186
|
+
f as flushDebugLogs,
|
|
1186
1187
|
V as formParse,
|
|
1187
1188
|
R as getCaller,
|
|
1188
1189
|
ts as getScopedParams
|
package/dist/bundle.umd.cjs
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
(function(a,
|
|
2
|
-
|
|
3
|
-
`)
|
|
4
|
-
`),
|
|
5
|
-
`),
|
|
6
|
-
`),
|
|
7
|
-
`),
|
|
8
|
-
`),
|
|
9
|
-
`),r.
|
|
10
|
-
`),
|
|
11
|
-
`),
|
|
12
|
-
`),
|
|
13
|
-
`),
|
|
14
|
-
`)}class
|
|
1
|
+
(function(a,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(a=typeof globalThis<"u"?globalThis:a||self,c(a["@arkyn/server"]={}))})(this,function(a){"use strict";var es=Object.defineProperty;var ts=(a,c,b)=>c in a?es(a,c,{enumerable:!0,configurable:!0,writable:!0,value:b}):a[c]=b;var r=(a,c,b)=>ts(a,typeof c!="symbol"?c+"":c,b);function c(n){var s;if(process.env.NODE_ENV==="development"||((s=process.env)==null?void 0:s.SHOW_ERRORS_IN_CONSOLE)==="true"){const u=`${{yellow:"\x1B[33m",cyan:"\x1B[36m",red:"\x1B[31m",green:"\x1B[32m"}[n.scheme]}[${n.name}]\x1B[0m`;let l=`<------------------->
|
|
2
|
+
`;n.debugs.forEach(d=>{l+=`${u} ${d.trim()}
|
|
3
|
+
`}),l+="<------------------->",console.log(l)}}const b={};class N{static setIgnoreFile(t){this.ignoreFiles.push(t)}static clearIgnoreFiles(){this.ignoreFiles=[]}}r(N,"ignoreFiles",[]);function R(){const n=process.cwd(),e=(new Error().stack||"").split(`
|
|
4
|
+
`).map(i=>i.trim()),o=N.ignoreFiles;let u=2;for(;u<e.length&&(e[u].includes("node:internal")||e[u].includes("/node_modules/"));)u++;if(o.length>0)for(;u<e.length&&o.some(i=>e[u].includes(i));)u++;const l=e[u]||"";let d="Unknown function",h="Unknown caller";const f=l.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);if(f)d=f[1],h=f[2];else{const i=l.match(/at\s+(.+)/);if(i){h=i[1];const p=h.match(/at\s+([^(\s]+)\s+/);p&&p[1]!=="new"&&(d=p[1])}}h.includes("(")&&(h=h.substring(h.indexOf("(")+1,h.lastIndexOf(")"))),h=h.split(":").slice(0,-2).join(":");try{h=b.relative(n,h)}catch{}return{functionName:d,callerInfo:h}}class y{onDebug(t,s,e){const o=[],{callerInfo:u,functionName:l}=R();o.push(`${t} initialized
|
|
5
|
+
`),o.push(`Caller Function: ${l}
|
|
6
|
+
`),o.push(`Caller Location: ${u}
|
|
7
|
+
`),o.push(`Body: ${JSON.stringify(s,null,2)}
|
|
8
|
+
`),e&&o.push(`Cause: ${JSON.stringify(e,null,2)}
|
|
9
|
+
`),c({scheme:"red",name:"ARKYN-BAD-RESPONSE-DEBUG",debugs:o})}}class O extends y{constructor(s,e){super();r(this,"body");r(this,"cause");r(this,"status",502);r(this,"statusText");this.body={name:"BadGateway",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("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 x extends y{constructor(s,e){super();r(this,"body");r(this,"cause");r(this,"status",400);r(this,"statusText");this.body={name:"BadRequest",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("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 extends y{constructor(s,e){super();r(this,"body");r(this,"cause");r(this,"status",409);r(this,"statusText");this.body={name:"Conflict",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("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 extends y{constructor(s,e){super();r(this,"body");r(this,"cause");r(this,"status",403);r(this,"statusText");this.body={name:"Forbidden",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("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 k extends y{constructor(s,e){super();r(this,"body");r(this,"cause");r(this,"status",404);r(this,"statusText");this.body={name:"NotFound",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("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 extends y{constructor(s,e){super();r(this,"body");r(this,"cause");r(this,"status",501);r(this,"statusText");this.body={name:"NotImplemented",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("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 S extends y{constructor(s,e){super();r(this,"body");r(this,"cause");r(this,"status",500);r(this,"statusText");this.body={name:"ServerError",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("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 C extends y{constructor(s,e){super();r(this,"body");r(this,"cause");r(this,"status",401);r(this,"statusText");this.body={name:"Unauthorized",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("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 extends y{constructor(s){super();r(this,"body");r(this,"status",422);r(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("UnprocessableEntity",this.body,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 T{onDebug(t,s,e){const o=[],{callerInfo:u,functionName:l}=R();o.push(`${t} initialized
|
|
10
|
+
`),o.push(`Caller Function: ${l}
|
|
11
|
+
`),o.push(`Caller Location: ${u}
|
|
12
|
+
`),o.push(`Body: ${JSON.stringify(s,null,2)}
|
|
13
|
+
`),e&&o.push(`Cause: ${JSON.stringify(e,null,2)}
|
|
14
|
+
`),c({scheme:"green",name:"ARKYN-SUCCESS-RESPONSE-DEBUG",debugs:o})}}class J extends T{constructor(s,e){super();r(this,"body");r(this,"headers");r(this,"status");r(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",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 D extends T{constructor(s,e){super();r(this,"body");r(this,"headers");r(this,"status");r(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",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 B extends T{constructor(s){super();r(this,"headers");r(this,"status");r(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 q extends T{constructor(s,e){super();r(this,"body");r(this,"headers");r(this,"status");r(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",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 P extends T{constructor(s,e){super();r(this,"body");r(this,"headers");r(this,"status");r(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",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 A{static mapHeaders(t){return t instanceof Headers?Object.fromEntries(t.entries()):typeof t=="object"?Object.entries(t).reduce((s,[e,o])=>(typeof o=="string"?s[e]=o:Array.isArray(o)?s[e]=o.join(", "):s[e]=JSON.stringify(o),s),{}):{}}static mapQueryParams(t){const s={};return t.forEach((e,o)=>{s[o]=e}),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 E{static setArkynConfig(t){if(this.arkynConfig)return;let e=t.arkynLogBaseApiUrl||"https://logs-arkyn-flow-logs.vw6wo7.easypanel.host";e=e+"/http-traffic-records/:trafficSourceId",this.arkynConfig={arkynTrafficSourceId:t.arkynTrafficSourceId,arkynUserToken:t.arkynUserToken,arkynApiUrl:e}}static getArkynConfig(){return this.arkynConfig}static resetArkynConfig(){this.arkynConfig=void 0}}r(E,"arkynConfig");async function H(n){const t=E.getArkynConfig();if(!t)return;const{arkynUserToken:s,arkynApiUrl:e}=t,{elapsedTime:o,method:u,queryParams:l,requestBody:d,requestHeaders:h,responseBody:f,responseHeaders:i,status:p,token:ns,rawUrl:Z}=n;if(process.env.NODE_ENV!=="development")try{const g=new URL(Z);let v="HTTPS";g.protocol==="http:"&&(v="HTTP");const ss=JSON.stringify({domainUrl:g.protocol+"//"+g.host,pathnameUrl:g.pathname,status:p,protocol:v,method:u,trafficUserId:null,elapsedTime:o,requestHeaders:h,requestBody:d,queryParams:l,responseHeaders:i,responseBody:f});await fetch(e.replace(":trafficSourceId",t.arkynTrafficSourceId),{method:"POST",body:ss,headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`}})}catch(g){c({debugs:[`Error sending request: ${g}`],name:"ARKYN_LOG_ERROR",scheme:"red"})}}async function m(n,t,s={},e){const o={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={...s,"Content-Type":"application/json"},d=await fetch(t,{method:n,headers:l,body:e?JSON.stringify(e):void 0}),h=performance.now()-u,f=d.status;let i=null;try{i=await d.json()}catch{i=null}const p=A.handle({elapsedTime:h,method:n,queryParams:new URL(t).searchParams,requestHeaders:l,requestBody:e,responseBody:i,responseHeaders:d.headers,status:f,url:t});return H(p),d.ok?{success:!0,status:f,message:(i==null?void 0:i.message)||o[n],response:i,cause:null}:{success:!1,status:f,message:(i==null?void 0:i.message)||d.statusText||"Request failed",response:i,cause:null}}catch(u){return c({debugs:[`Network error or request failed: ${u}`],name:"ARKYN_MAKE_REQUEST_ERROR",scheme:"red"}),{success:!1,status:0,message:"Network error or request failed",response:null,cause:u instanceof Error?u.message:String(u)}}}async function $(n,t={},s){return m("DELETE",n,t,s)}async function F(n,t={}){return m("GET",n,t)}async function M(n,t={},s){return m("PATCH",n,t,s)}async function _(n,t={},s){return m("POST",n,t,s)}async function z(n,t={},s){return m("PUT",n,t,s)}class G{constructor(t){r(this,"baseUrl");r(this,"baseHeaders");r(this,"baseToken");r(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,e){if(this.enableDebug){const o=[];o.push(`Base URL: ${this.baseUrl}`),o.push(`Endpoint URL: ${t}`),o.push(`Method: ${s}`),e[0]&&o.push(`Headers: ${JSON.stringify(e[0])}`),e[1]&&o.push(`Body: ${JSON.stringify(e[1])}`),c({debugs:o,name:"ARKYN-API-DEBUG",scheme:"yellow"})}}generateURL(t){return this.baseUrl+t}generateHeaders(t,s){let e={};return this.baseToken&&(e={Authorization:`Bearer ${this.baseToken}`}),this.baseHeaders&&(e={...e,...this.baseHeaders}),t&&(e={...e,...t}),s&&(e={...e,Authorization:`Bearer ${s}`}),e}async get(t,s){const e=this.generateURL(t),o=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token);return this.onDebug(e,"get",[o]),await F(e,o)}async post(t,s){const e=this.generateURL(t),o=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(e,"post",[o,u]),await _(e,o,u)}async put(t,s){const e=this.generateURL(t),o=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(t,"put",[o,u]),await z(e,o,u)}async patch(t,s){const e=this.generateURL(t),o=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(e,"patch",[o,u]),await M(e,o,u)}async delete(t,s){const e=this.generateURL(t),o=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(e,"delete",[o,u]),await $(e,o,u)}}function K(n,t){var s,e,o;return n!=null&&n.message&&typeof(n==null?void 0:n.message)=="string"?n==null?void 0:n.message:n!=null&&n.error&&typeof(n==null?void 0:n.error)=="string"?n==null?void 0:n.error:(s=n==null?void 0:n.error)!=null&&s.message&&typeof((e=n==null?void 0:n.error)==null?void 0:e.message)=="string"?(o=n==null?void 0:n.error)==null?void 0:o.message:t!=null&&t.statusText&&typeof(t==null?void 0:t.statusText)=="string"?t==null?void 0:t.statusText:"Missing error message"}const V=async n=>{let t;const s=await n.arrayBuffer(),e=new TextDecoder().decode(s);try{t=JSON.parse(e)}catch{try{if(e.includes("=")){const u=new URLSearchParams(e);t=Object.fromEntries(u.entries())}else throw new x("Invalid URLSearchParams format")}catch{throw new x("Failed to extract data from request")}}return t};function Y(n){switch(!0){case n instanceof Response:return n;case n instanceof D:return n.toResponse();case n instanceof J:return n.toResponse();case n instanceof P:return n.toResponse();case n instanceof q:return n.toResponse();case n instanceof B:return n.toResponse()}switch(!0){case n instanceof O:return n.toResponse();case n instanceof x:return n.toResponse();case n instanceof U:return n.toResponse();case n instanceof I:return n.toResponse();case n instanceof k:return n.toResponse();case n instanceof j:return n.toResponse();case n instanceof S:return n.toResponse();case n instanceof C:return n.toResponse();case n instanceof w:return n.toResponse()}return new S("Server error",n).toResponse()}function L([n,t]){const s=t.safeParse(n);if(s.success===!1){const e=Object.fromEntries(s.error.issues.map(o=>[o.path.join("."),o.message]));return{success:s.success,fieldErrors:e,fields:n}}else return{success:s.success,data:s.data}}const Q=(n,t="")=>{const s=new URL(n.url);if(t==="")return s.searchParams;const e=Array.from(s.searchParams.entries()).filter(([o])=>o.startsWith(`${t}:`)).map(([o,u])=>[o.replace(`${t}:`,""),u]);return new URLSearchParams(e)};function W(n){const t="Error validating:",s=n.issues.map(({path:e,message:o})=>`-> ${e.join(".")}: ${o}`);return[t,...s].join(`
|
|
15
|
+
`)}class X{constructor(t){r(this,"functionName");r(this,"callerInfo");this.schema=t;const{callerInfo:s,functionName:e}=R();this.callerInfo=s,this.functionName=e}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 S(W(s))}}formValidate(t,s){const e=L([t,this.schema]);if(!e.success){const o=Object.keys(e.fieldErrors)[0];throw new w({fields:e.fields,fieldErrors:e.fieldErrors,data:{scrollTo:o},message:s})}return e.data}}a.ApiService=G,a.ArkynLogService=E,a.BadGateway=O,a.BadRequest=x,a.Conflict=U,a.Created=J,a.DebugService=N,a.Forbidden=I,a.Found=D,a.NoContent=B,a.NotFound=k,a.NotImplemented=j,a.SchemaValidator=X,a.ServerError=S,a.Success=q,a.Unauthorized=C,a.UnprocessableEntity=w,a.Updated=P,a.decodeErrorMessageFromRequest=K,a.decodeRequestBody=V,a.errorHandler=Y,a.flushDebugLogs=c,a.formParse=L,a.getCaller=R,a.getScopedParams=Q,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -45,40 +45,40 @@ declare class ApiService {
|
|
|
45
45
|
*/
|
|
46
46
|
private generateHeaders;
|
|
47
47
|
/**
|
|
48
|
-
* Sends a get request to the specified
|
|
49
|
-
* @param
|
|
48
|
+
* Sends a get request to the specified endpoint.
|
|
49
|
+
* @param endpoint - The API endpoint to send the get request to.
|
|
50
50
|
* @param data - The request data, including optional headers and token.
|
|
51
51
|
* @returns The API response data.
|
|
52
52
|
*/
|
|
53
|
-
get(
|
|
53
|
+
get(endpoint: string, data?: ApiRequestDataWithoutBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
|
|
54
54
|
/**
|
|
55
|
-
* Sends a post request to the specified
|
|
56
|
-
* @param
|
|
55
|
+
* Sends a post request to the specified endpoint.
|
|
56
|
+
* @param endpoint - The API endpoint to send the post request to.
|
|
57
57
|
* @param data - The request data, including body, optional headers, and token.
|
|
58
58
|
* @returns The API response data.
|
|
59
59
|
*/
|
|
60
|
-
post(
|
|
60
|
+
post(endpoint: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
|
|
61
61
|
/**
|
|
62
|
-
* Sends a put request to the specified
|
|
63
|
-
* @param
|
|
62
|
+
* Sends a put request to the specified endpoint.
|
|
63
|
+
* @param endpoint - The API endpoint to send the put request to.
|
|
64
64
|
* @param data - The request data, including body, optional headers, and token.
|
|
65
65
|
* @returns The API response data.
|
|
66
66
|
*/
|
|
67
|
-
put(
|
|
67
|
+
put(endpoint: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
|
|
68
68
|
/**
|
|
69
|
-
* Sends a patch request to the specified
|
|
70
|
-
* @param
|
|
69
|
+
* Sends a patch request to the specified endpoint.
|
|
70
|
+
* @param endpoint - The API endpoint to send the patch request to.
|
|
71
71
|
* @param data - The request data, including body, optional headers, and token.
|
|
72
72
|
* @returns The API response data.
|
|
73
73
|
*/
|
|
74
|
-
patch(
|
|
74
|
+
patch(endpoint: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
|
|
75
75
|
/**
|
|
76
|
-
* Sends a delete request to the specified
|
|
77
|
-
* @param
|
|
76
|
+
* Sends a delete request to the specified endpoint.
|
|
77
|
+
* @param endpoint - The API endpoint to send the delete request to.
|
|
78
78
|
* @param data - The request data, including body, optional headers, and token.
|
|
79
79
|
* @returns The API response data.
|
|
80
80
|
*/
|
|
81
|
-
delete(
|
|
81
|
+
delete(endpoint: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
|
|
82
82
|
}
|
|
83
83
|
export { ApiService };
|
|
84
84
|
//# sourceMappingURL=apiService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiService.d.ts","sourceRoot":"","sources":["../../src/services/apiService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"apiService.d.ts","sourceRoot":"","sources":["../../src/services/apiService.ts"],"names":[],"mappings":"AAOA,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,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,8BAA8B;IAQjE;;;;;OAKG;IAEG,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAS/D;;;;;OAKG;IAEG,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAS9D;;;;;OAKG;IAEG,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAShE;;;;;OAKG;IAEG,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;CAQlE;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -3,6 +3,7 @@ import { getRequest } from "../api/getRequest";
|
|
|
3
3
|
import { patchRequest } from "../api/patchRequest";
|
|
4
4
|
import { postRequest } from "../api/postRequest";
|
|
5
5
|
import { putRequest } from "../api/putRequest";
|
|
6
|
+
import { flushDebugLogs } from "./flushDebugLogs";
|
|
6
7
|
/**
|
|
7
8
|
* Class representing an API instance to handle HTTP requests with base configurations.
|
|
8
9
|
*/
|
|
@@ -30,18 +31,17 @@ class ApiService {
|
|
|
30
31
|
* @param route - The route to append to the base URL.
|
|
31
32
|
* @returns The full URL as a string.
|
|
32
33
|
*/
|
|
33
|
-
onDebug(
|
|
34
|
+
onDebug(endpoint, method, data) {
|
|
34
35
|
if (this.enableDebug) {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
console.log(`${debugName} Full URL: ${fullRoute}`);
|
|
40
|
-
console.log(`${debugName} Method: ${method}`);
|
|
36
|
+
const debugs = [];
|
|
37
|
+
debugs.push(`Base URL: ${this.baseUrl}`);
|
|
38
|
+
debugs.push(`Endpoint URL: ${endpoint}`);
|
|
39
|
+
debugs.push(`Method: ${method}`);
|
|
41
40
|
if (data[0])
|
|
42
|
-
|
|
41
|
+
debugs.push(`Headers: ${JSON.stringify(data[0])}`);
|
|
43
42
|
if (data[1])
|
|
44
|
-
|
|
43
|
+
debugs.push(`Body: ${JSON.stringify(data[1])}`);
|
|
44
|
+
flushDebugLogs({ debugs, name: "ARKYN-API-DEBUG", scheme: "yellow" });
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
generateURL(route) {
|
|
@@ -66,64 +66,64 @@ class ApiService {
|
|
|
66
66
|
return headers;
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
|
-
* Sends a get request to the specified
|
|
70
|
-
* @param
|
|
69
|
+
* Sends a get request to the specified endpoint.
|
|
70
|
+
* @param endpoint - The API endpoint to send the get request to.
|
|
71
71
|
* @param data - The request data, including optional headers and token.
|
|
72
72
|
* @returns The API response data.
|
|
73
73
|
*/
|
|
74
|
-
async get(
|
|
75
|
-
const url = this.generateURL(
|
|
74
|
+
async get(endpoint, data) {
|
|
75
|
+
const url = this.generateURL(endpoint);
|
|
76
76
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
77
77
|
this.onDebug(url, "get", [headers]);
|
|
78
78
|
return await getRequest(url, headers);
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
|
-
* Sends a post request to the specified
|
|
82
|
-
* @param
|
|
81
|
+
* Sends a post request to the specified endpoint.
|
|
82
|
+
* @param endpoint - The API endpoint to send the post request to.
|
|
83
83
|
* @param data - The request data, including body, optional headers, and token.
|
|
84
84
|
* @returns The API response data.
|
|
85
85
|
*/
|
|
86
|
-
async post(
|
|
87
|
-
const url = this.generateURL(
|
|
86
|
+
async post(endpoint, data) {
|
|
87
|
+
const url = this.generateURL(endpoint);
|
|
88
88
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
89
89
|
const body = data?.body;
|
|
90
90
|
this.onDebug(url, "post", [headers, body]);
|
|
91
91
|
return await postRequest(url, headers, body);
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
|
-
* Sends a put request to the specified
|
|
95
|
-
* @param
|
|
94
|
+
* Sends a put request to the specified endpoint.
|
|
95
|
+
* @param endpoint - The API endpoint to send the put request to.
|
|
96
96
|
* @param data - The request data, including body, optional headers, and token.
|
|
97
97
|
* @returns The API response data.
|
|
98
98
|
*/
|
|
99
|
-
async put(
|
|
100
|
-
const url = this.generateURL(
|
|
99
|
+
async put(endpoint, data) {
|
|
100
|
+
const url = this.generateURL(endpoint);
|
|
101
101
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
102
102
|
const body = data?.body;
|
|
103
|
-
this.onDebug(
|
|
103
|
+
this.onDebug(endpoint, "put", [headers, body]);
|
|
104
104
|
return await putRequest(url, headers, body);
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
|
-
* Sends a patch request to the specified
|
|
108
|
-
* @param
|
|
107
|
+
* Sends a patch request to the specified endpoint.
|
|
108
|
+
* @param endpoint - The API endpoint to send the patch request to.
|
|
109
109
|
* @param data - The request data, including body, optional headers, and token.
|
|
110
110
|
* @returns The API response data.
|
|
111
111
|
*/
|
|
112
|
-
async patch(
|
|
113
|
-
const url = this.generateURL(
|
|
112
|
+
async patch(endpoint, data) {
|
|
113
|
+
const url = this.generateURL(endpoint);
|
|
114
114
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
115
115
|
const body = data?.body;
|
|
116
116
|
this.onDebug(url, "patch", [headers, body]);
|
|
117
117
|
return await patchRequest(url, headers, body);
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
120
|
-
* Sends a delete request to the specified
|
|
121
|
-
* @param
|
|
120
|
+
* Sends a delete request to the specified endpoint.
|
|
121
|
+
* @param endpoint - The API endpoint to send the delete request to.
|
|
122
122
|
* @param data - The request data, including body, optional headers, and token.
|
|
123
123
|
* @returns The API response data.
|
|
124
124
|
*/
|
|
125
|
-
async delete(
|
|
126
|
-
const url = this.generateURL(
|
|
125
|
+
async delete(endpoint, data) {
|
|
126
|
+
const url = this.generateURL(endpoint);
|
|
127
127
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
128
128
|
const body = data?.body;
|
|
129
129
|
this.onDebug(url, "delete", [headers, body]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flushDebugLogs.d.ts","sourceRoot":"","sources":["../../src/services/flushDebugLogs.ts"],"names":[],"mappings":"AAAA,KAAK,mBAAmB,GAAG;IACzB,MAAM,EAAE,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,iBAAS,cAAc,CAAC,KAAK,EAAE,mBAAmB,
|
|
1
|
+
{"version":3,"file":"flushDebugLogs.d.ts","sourceRoot":"","sources":["../../src/services/flushDebugLogs.ts"],"names":[],"mappings":"AAAA,KAAK,mBAAmB,GAAG;IACzB,MAAM,EAAE,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,iBAAS,cAAc,CAAC,KAAK,EAAE,mBAAmB,QA0BjD;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -10,10 +10,11 @@ function flushDebugLogs(props) {
|
|
|
10
10
|
green: "\x1b[32m",
|
|
11
11
|
};
|
|
12
12
|
const debugName = `${colors[props.scheme]}[${props.name}]${reset}`;
|
|
13
|
-
let consoleData =
|
|
13
|
+
let consoleData = `<------------------->\n`;
|
|
14
14
|
props.debugs.forEach((debug) => {
|
|
15
|
-
consoleData += `${debugName} ${debug}\n`;
|
|
15
|
+
consoleData += `${debugName} ${debug.trim()}\n`;
|
|
16
16
|
});
|
|
17
|
+
consoleData += `<------------------->`;
|
|
17
18
|
console.log(consoleData);
|
|
18
19
|
}
|
|
19
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formParse.d.ts","sourceRoot":"","sources":["../../src/services/formParse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,KAAK,eAAe,CAAC,CAAC,SAAS,cAAc,IAAI;IAC/C,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;CACjD,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAChC,WAAW,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACtC,CAAC;AAEF,KAAK,cAAc,GAAG,CAAC,QAAQ,EAAE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAExE,KAAK,mBAAmB,CAAC,CAAC,SAAS,cAAc,IAC7C,eAAe,CAAC,CAAC,CAAC,GAClB,aAAa,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,iBAAS,SAAS,CAAC,CAAC,SAAS,cAAc,EAAE,CAC3C,QAAQ,EACR,MAAM,EACP,EAAE,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"formParse.d.ts","sourceRoot":"","sources":["../../src/services/formParse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,KAAK,eAAe,CAAC,CAAC,SAAS,cAAc,IAAI;IAC/C,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;CACjD,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAChC,WAAW,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACtC,CAAC;AAEF,KAAK,cAAc,GAAG,CAAC,QAAQ,EAAE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAExE,KAAK,mBAAmB,CAAC,CAAC,SAAS,cAAc,IAC7C,eAAe,CAAC,CAAC,CAAC,GAClB,aAAa,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,iBAAS,SAAS,CAAC,CAAC,SAAS,cAAc,EAAE,CAC3C,QAAQ,EACR,MAAM,EACP,EAAE,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAqB5B;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -40,7 +40,6 @@ function formParse([formData, schema,]) {
|
|
|
40
40
|
const zodResponse = schema.safeParse(formData);
|
|
41
41
|
if (zodResponse.success === false) {
|
|
42
42
|
const errorsObject = Object.fromEntries(zodResponse.error.issues.map((item) => {
|
|
43
|
-
console.log(item);
|
|
44
43
|
return [item.path.join("."), item.message];
|
|
45
44
|
}));
|
|
46
45
|
return {
|