@arkyn/server 3.0.1-beta.67 → 3.0.1-beta.69
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 +194 -168
- package/dist/bundle.umd.cjs +10 -15
- package/dist/http/badResponses/_badResponse.d.ts +7 -18
- package/dist/http/badResponses/_badResponse.d.ts.map +1 -1
- package/dist/http/badResponses/_badResponse.js +10 -23
- package/dist/http/badResponses/badGateway.d.ts.map +1 -1
- package/dist/http/badResponses/badGateway.js +6 -1
- package/dist/http/badResponses/badRequest.d.ts.map +1 -1
- package/dist/http/badResponses/badRequest.js +6 -1
- package/dist/http/badResponses/conflict.d.ts.map +1 -1
- package/dist/http/badResponses/conflict.js +6 -1
- package/dist/http/badResponses/forbidden.d.ts.map +1 -1
- package/dist/http/badResponses/forbidden.js +6 -1
- package/dist/http/badResponses/notFound.d.ts.map +1 -1
- package/dist/http/badResponses/notFound.js +6 -1
- package/dist/http/badResponses/notImplemented.d.ts.map +1 -1
- package/dist/http/badResponses/notImplemented.js +6 -1
- package/dist/http/badResponses/serverError.d.ts.map +1 -1
- package/dist/http/badResponses/serverError.js +6 -1
- package/dist/http/badResponses/unauthorized.d.ts.map +1 -1
- package/dist/http/badResponses/unauthorized.js +6 -1
- package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
- package/dist/http/badResponses/unprocessableEntity.js +5 -1
- package/dist/services/flushDebugLogs.js +1 -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 o = (n, t, s) => I(n, typeof t != "symbol" ? t + "" : t, s);
|
|
4
|
+
function p(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,7 +10,7 @@ function f(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
15
|
n.debugs.forEach((h) => {
|
|
16
16
|
c += `${u} ${h.trim()}
|
|
@@ -58,15 +58,15 @@ class S {
|
|
|
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
|
-
|
|
62
|
-
function
|
|
61
|
+
o(S, "ignoreFiles", []);
|
|
62
|
+
function x() {
|
|
63
63
|
const n = process.cwd(), e = (new Error().stack || "").split(`
|
|
64
|
-
`).map((a) => a.trim()),
|
|
64
|
+
`).map((a) => a.trim()), r = S.ignoreFiles;
|
|
65
65
|
let u = 2;
|
|
66
66
|
for (; u < e.length && (e[u].includes("node:internal") || e[u].includes("/node_modules/")); )
|
|
67
67
|
u++;
|
|
68
|
-
if (
|
|
69
|
-
for (; u < e.length &&
|
|
68
|
+
if (r.length > 0)
|
|
69
|
+
for (; u < e.length && r.some(
|
|
70
70
|
(a) => e[u].includes(a)
|
|
71
71
|
); )
|
|
72
72
|
u++;
|
|
@@ -94,27 +94,9 @@ function R() {
|
|
|
94
94
|
return { functionName: h, callerInfo: i };
|
|
95
95
|
}
|
|
96
96
|
class y {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
* @param name - The name/type of the bad response being logged
|
|
101
|
-
* @param body - The response body or error data to be logged
|
|
102
|
-
* @param cause - Optional additional cause information for the error
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* ```typescript
|
|
106
|
-
* const badResponse = new BadResponse();
|
|
107
|
-
* badResponse.onDebug("ValidationError", { field: "email", message: "Invalid format" });
|
|
108
|
-
* ```
|
|
109
|
-
*/
|
|
110
|
-
onDebug(t, s, e) {
|
|
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 });
|
|
97
|
+
onDebug(t) {
|
|
98
|
+
const { name: s, body: e, cause: r, message: u } = t, c = [], { callerInfo: h, functionName: i } = x();
|
|
99
|
+
c.push(`${s} initialized`), c.push(`Caller Function: ${i}`), c.push(`Caller Location: ${h}`), u && c.push(`Message: ${u}`), e && c.push(`Body: ${JSON.stringify(e, null, 2)}`), r && c.push(`Cause: ${JSON.stringify(r, null, 2)}`), p({ scheme: "red", name: "ARKYN-BAD-RESPONSE-DEBUG", debugs: c });
|
|
118
100
|
}
|
|
119
101
|
}
|
|
120
102
|
class j extends y {
|
|
@@ -126,11 +108,16 @@ class j extends y {
|
|
|
126
108
|
*/
|
|
127
109
|
constructor(s, e) {
|
|
128
110
|
super();
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
this.body = { name: "BadGateway", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug(
|
|
111
|
+
o(this, "body");
|
|
112
|
+
o(this, "cause");
|
|
113
|
+
o(this, "status", 502);
|
|
114
|
+
o(this, "statusText");
|
|
115
|
+
this.body = { name: "BadGateway", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug({
|
|
116
|
+
name: "BadGateway",
|
|
117
|
+
body: this.body,
|
|
118
|
+
cause: this.cause,
|
|
119
|
+
message: this.statusText
|
|
120
|
+
});
|
|
134
121
|
}
|
|
135
122
|
/**
|
|
136
123
|
* Converts the `BadGateway` instance into a `Response` object with a JSON body.
|
|
@@ -160,7 +147,7 @@ class j extends y {
|
|
|
160
147
|
return Response.json(this.body, s);
|
|
161
148
|
}
|
|
162
149
|
}
|
|
163
|
-
class
|
|
150
|
+
class b extends y {
|
|
164
151
|
/**
|
|
165
152
|
* Creates an instance of the `BadRequest` class.
|
|
166
153
|
*
|
|
@@ -169,11 +156,16 @@ class g extends y {
|
|
|
169
156
|
*/
|
|
170
157
|
constructor(s, e) {
|
|
171
158
|
super();
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
this.body = { name: "BadRequest", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug(
|
|
159
|
+
o(this, "body");
|
|
160
|
+
o(this, "cause");
|
|
161
|
+
o(this, "status", 400);
|
|
162
|
+
o(this, "statusText");
|
|
163
|
+
this.body = { name: "BadRequest", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug({
|
|
164
|
+
name: "BadRequest",
|
|
165
|
+
body: this.body,
|
|
166
|
+
cause: this.cause,
|
|
167
|
+
message: this.statusText
|
|
168
|
+
});
|
|
177
169
|
}
|
|
178
170
|
/**
|
|
179
171
|
* Converts the `BadRequest` instance into a `Response` object with a JSON body.
|
|
@@ -212,11 +204,16 @@ class J extends y {
|
|
|
212
204
|
*/
|
|
213
205
|
constructor(s, e) {
|
|
214
206
|
super();
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
this.body = { name: "Conflict", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug(
|
|
207
|
+
o(this, "body");
|
|
208
|
+
o(this, "cause");
|
|
209
|
+
o(this, "status", 409);
|
|
210
|
+
o(this, "statusText");
|
|
211
|
+
this.body = { name: "Conflict", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug({
|
|
212
|
+
name: "Conflict",
|
|
213
|
+
body: this.body,
|
|
214
|
+
cause: this.cause,
|
|
215
|
+
message: this.statusText
|
|
216
|
+
});
|
|
220
217
|
}
|
|
221
218
|
/**
|
|
222
219
|
* Converts the `Conflict` instance into a `Response` object with a JSON body.
|
|
@@ -255,11 +252,16 @@ class D extends y {
|
|
|
255
252
|
*/
|
|
256
253
|
constructor(s, e) {
|
|
257
254
|
super();
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
this.body = { name: "Forbidden", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug(
|
|
255
|
+
o(this, "body");
|
|
256
|
+
o(this, "cause");
|
|
257
|
+
o(this, "status", 403);
|
|
258
|
+
o(this, "statusText");
|
|
259
|
+
this.body = { name: "Forbidden", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug({
|
|
260
|
+
name: "Forbidden",
|
|
261
|
+
body: this.body,
|
|
262
|
+
cause: this.cause,
|
|
263
|
+
message: this.statusText
|
|
264
|
+
});
|
|
263
265
|
}
|
|
264
266
|
/**
|
|
265
267
|
* Converts the `Forbidden` instance into a `Response` object with a JSON body.
|
|
@@ -298,11 +300,16 @@ class C extends y {
|
|
|
298
300
|
*/
|
|
299
301
|
constructor(s, e) {
|
|
300
302
|
super();
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
this.body = { name: "NotFound", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug(
|
|
303
|
+
o(this, "body");
|
|
304
|
+
o(this, "cause");
|
|
305
|
+
o(this, "status", 404);
|
|
306
|
+
o(this, "statusText");
|
|
307
|
+
this.body = { name: "NotFound", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug({
|
|
308
|
+
name: "NotFound",
|
|
309
|
+
body: this.body,
|
|
310
|
+
cause: this.cause,
|
|
311
|
+
message: this.statusText
|
|
312
|
+
});
|
|
306
313
|
}
|
|
307
314
|
/**
|
|
308
315
|
* Converts the `NotFound` instance into a `Response` object with a JSON body.
|
|
@@ -341,11 +348,16 @@ class B extends y {
|
|
|
341
348
|
*/
|
|
342
349
|
constructor(s, e) {
|
|
343
350
|
super();
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
this.body = { name: "NotImplemented", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug(
|
|
351
|
+
o(this, "body");
|
|
352
|
+
o(this, "cause");
|
|
353
|
+
o(this, "status", 501);
|
|
354
|
+
o(this, "statusText");
|
|
355
|
+
this.body = { name: "NotImplemented", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug({
|
|
356
|
+
name: "NotImplemented",
|
|
357
|
+
body: this.body,
|
|
358
|
+
cause: this.cause,
|
|
359
|
+
message: this.statusText
|
|
360
|
+
});
|
|
349
361
|
}
|
|
350
362
|
/**
|
|
351
363
|
* Converts the `NotImplemented` instance into a `Response` object with a JSON body.
|
|
@@ -375,7 +387,7 @@ class B extends y {
|
|
|
375
387
|
return Response.json(this.body, s);
|
|
376
388
|
}
|
|
377
389
|
}
|
|
378
|
-
class
|
|
390
|
+
class m extends y {
|
|
379
391
|
/**
|
|
380
392
|
* Creates an instance of the `ServerError` class.
|
|
381
393
|
*
|
|
@@ -384,11 +396,16 @@ class x extends y {
|
|
|
384
396
|
*/
|
|
385
397
|
constructor(s, e) {
|
|
386
398
|
super();
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
this.body = { name: "ServerError", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug(
|
|
399
|
+
o(this, "body");
|
|
400
|
+
o(this, "cause");
|
|
401
|
+
o(this, "status", 500);
|
|
402
|
+
o(this, "statusText");
|
|
403
|
+
this.body = { name: "ServerError", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug({
|
|
404
|
+
name: "ServerError",
|
|
405
|
+
body: this.body,
|
|
406
|
+
cause: this.cause,
|
|
407
|
+
message: this.statusText
|
|
408
|
+
});
|
|
392
409
|
}
|
|
393
410
|
/**
|
|
394
411
|
* Converts the `ServerError` instance into a `Response` object with a JSON body.
|
|
@@ -427,11 +444,16 @@ class q extends y {
|
|
|
427
444
|
*/
|
|
428
445
|
constructor(s, e) {
|
|
429
446
|
super();
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
this.body = { name: "Unauthorized", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug(
|
|
447
|
+
o(this, "body");
|
|
448
|
+
o(this, "cause");
|
|
449
|
+
o(this, "status", 401);
|
|
450
|
+
o(this, "statusText");
|
|
451
|
+
this.body = { name: "Unauthorized", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug({
|
|
452
|
+
name: "Unauthorized",
|
|
453
|
+
body: this.body,
|
|
454
|
+
cause: this.cause,
|
|
455
|
+
message: this.statusText
|
|
456
|
+
});
|
|
435
457
|
}
|
|
436
458
|
/**
|
|
437
459
|
* Converts the `Unauthorized` instance into a `Response` object with a JSON body.
|
|
@@ -474,16 +496,20 @@ class N extends y {
|
|
|
474
496
|
*/
|
|
475
497
|
constructor(s) {
|
|
476
498
|
super();
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
499
|
+
o(this, "body");
|
|
500
|
+
o(this, "status", 422);
|
|
501
|
+
o(this, "statusText");
|
|
480
502
|
this.statusText = s.message || "Unprocessable Entity", this.body = {
|
|
481
503
|
name: "UnprocessableEntity",
|
|
482
504
|
message: s.message || null,
|
|
483
505
|
data: s.data,
|
|
484
506
|
fieldErrors: s.fieldErrors,
|
|
485
507
|
fields: s.fields
|
|
486
|
-
}, this.onDebug(
|
|
508
|
+
}, this.onDebug({
|
|
509
|
+
name: "UnprocessableEntity",
|
|
510
|
+
cause: s.fieldErrors,
|
|
511
|
+
message: s.message
|
|
512
|
+
});
|
|
487
513
|
}
|
|
488
514
|
/**
|
|
489
515
|
* Converts the `UnprocessableEntity` instance into a `Response` object with a JSON body.
|
|
@@ -528,16 +554,16 @@ class T {
|
|
|
528
554
|
* ```
|
|
529
555
|
*/
|
|
530
556
|
onDebug(t, s, e) {
|
|
531
|
-
const
|
|
532
|
-
|
|
533
|
-
`),
|
|
534
|
-
`),
|
|
535
|
-
`),
|
|
536
|
-
`), e &&
|
|
537
|
-
`),
|
|
557
|
+
const r = [], { callerInfo: u, functionName: c } = x();
|
|
558
|
+
r.push(`${t} initialized
|
|
559
|
+
`), r.push(`Caller Function: ${c}
|
|
560
|
+
`), r.push(`Caller Location: ${u}
|
|
561
|
+
`), r.push(`Body: ${JSON.stringify(s, null, 2)}
|
|
562
|
+
`), e && r.push(`Cause: ${JSON.stringify(e, null, 2)}
|
|
563
|
+
`), p({
|
|
538
564
|
scheme: "green",
|
|
539
565
|
name: "ARKYN-SUCCESS-RESPONSE-DEBUG",
|
|
540
|
-
debugs:
|
|
566
|
+
debugs: r
|
|
541
567
|
});
|
|
542
568
|
}
|
|
543
569
|
}
|
|
@@ -550,10 +576,10 @@ class P extends T {
|
|
|
550
576
|
*/
|
|
551
577
|
constructor(s, e) {
|
|
552
578
|
super();
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
579
|
+
o(this, "body");
|
|
580
|
+
o(this, "headers");
|
|
581
|
+
o(this, "status");
|
|
582
|
+
o(this, "statusText");
|
|
557
583
|
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);
|
|
558
584
|
}
|
|
559
585
|
/**
|
|
@@ -585,7 +611,7 @@ class P extends T {
|
|
|
585
611
|
return Response.json(this.body, s);
|
|
586
612
|
}
|
|
587
613
|
}
|
|
588
|
-
class
|
|
614
|
+
class $ extends T {
|
|
589
615
|
/**
|
|
590
616
|
* Creates an instance of the `Found` class.
|
|
591
617
|
*
|
|
@@ -597,10 +623,10 @@ class H extends T {
|
|
|
597
623
|
*/
|
|
598
624
|
constructor(s, e) {
|
|
599
625
|
super();
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
626
|
+
o(this, "body");
|
|
627
|
+
o(this, "headers");
|
|
628
|
+
o(this, "status");
|
|
629
|
+
o(this, "statusText");
|
|
604
630
|
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);
|
|
605
631
|
}
|
|
606
632
|
/**
|
|
@@ -632,7 +658,7 @@ class H extends T {
|
|
|
632
658
|
return Response.json(this.body, s);
|
|
633
659
|
}
|
|
634
660
|
}
|
|
635
|
-
class
|
|
661
|
+
class H extends T {
|
|
636
662
|
/**
|
|
637
663
|
* Creates an instance of the `NoContent` class.
|
|
638
664
|
*
|
|
@@ -640,9 +666,9 @@ class $ extends T {
|
|
|
640
666
|
*/
|
|
641
667
|
constructor(s) {
|
|
642
668
|
super();
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
669
|
+
o(this, "headers");
|
|
670
|
+
o(this, "status");
|
|
671
|
+
o(this, "statusText");
|
|
646
672
|
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);
|
|
647
673
|
}
|
|
648
674
|
/**
|
|
@@ -669,10 +695,10 @@ class A extends T {
|
|
|
669
695
|
*/
|
|
670
696
|
constructor(s, e) {
|
|
671
697
|
super();
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
698
|
+
o(this, "body");
|
|
699
|
+
o(this, "headers");
|
|
700
|
+
o(this, "status");
|
|
701
|
+
o(this, "statusText");
|
|
676
702
|
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);
|
|
677
703
|
}
|
|
678
704
|
/**
|
|
@@ -713,10 +739,10 @@ class L extends T {
|
|
|
713
739
|
*/
|
|
714
740
|
constructor(s, e) {
|
|
715
741
|
super();
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
742
|
+
o(this, "body");
|
|
743
|
+
o(this, "headers");
|
|
744
|
+
o(this, "status");
|
|
745
|
+
o(this, "statusText");
|
|
720
746
|
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);
|
|
721
747
|
}
|
|
722
748
|
/**
|
|
@@ -750,12 +776,12 @@ class L extends T {
|
|
|
750
776
|
}
|
|
751
777
|
class v {
|
|
752
778
|
static mapHeaders(t) {
|
|
753
|
-
return t instanceof Headers ? Object.fromEntries(t.entries()) : typeof t == "object" ? Object.entries(t).reduce((s, [e,
|
|
779
|
+
return t instanceof Headers ? Object.fromEntries(t.entries()) : typeof t == "object" ? Object.entries(t).reduce((s, [e, r]) => (typeof r == "string" ? s[e] = r : Array.isArray(r) ? s[e] = r.join(", ") : s[e] = JSON.stringify(r), s), {}) : {};
|
|
754
780
|
}
|
|
755
781
|
static mapQueryParams(t) {
|
|
756
782
|
const s = {};
|
|
757
|
-
return t.forEach((e,
|
|
758
|
-
s[
|
|
783
|
+
return t.forEach((e, r) => {
|
|
784
|
+
s[r] = e;
|
|
759
785
|
}), s;
|
|
760
786
|
}
|
|
761
787
|
static handle(t) {
|
|
@@ -811,12 +837,12 @@ class w {
|
|
|
811
837
|
this.arkynConfig = void 0;
|
|
812
838
|
}
|
|
813
839
|
}
|
|
814
|
-
|
|
840
|
+
o(w, "arkynConfig");
|
|
815
841
|
async function F(n) {
|
|
816
842
|
const t = w.getArkynConfig();
|
|
817
843
|
if (!t) return;
|
|
818
844
|
const { arkynUserToken: s, arkynApiUrl: e } = t, {
|
|
819
|
-
elapsedTime:
|
|
845
|
+
elapsedTime: r,
|
|
820
846
|
method: u,
|
|
821
847
|
queryParams: c,
|
|
822
848
|
requestBody: h,
|
|
@@ -829,17 +855,17 @@ async function F(n) {
|
|
|
829
855
|
} = n;
|
|
830
856
|
if (process.env.NODE_ENV !== "development")
|
|
831
857
|
try {
|
|
832
|
-
const
|
|
833
|
-
let
|
|
834
|
-
|
|
858
|
+
const f = new URL(E);
|
|
859
|
+
let R = "HTTPS";
|
|
860
|
+
f.protocol === "http:" && (R = "HTTP");
|
|
835
861
|
const O = JSON.stringify({
|
|
836
|
-
domainUrl:
|
|
837
|
-
pathnameUrl:
|
|
862
|
+
domainUrl: f.protocol + "//" + f.host,
|
|
863
|
+
pathnameUrl: f.pathname,
|
|
838
864
|
status: d,
|
|
839
|
-
protocol:
|
|
865
|
+
protocol: R,
|
|
840
866
|
method: u,
|
|
841
867
|
trafficUserId: null,
|
|
842
|
-
elapsedTime:
|
|
868
|
+
elapsedTime: r,
|
|
843
869
|
requestHeaders: i,
|
|
844
870
|
requestBody: h,
|
|
845
871
|
queryParams: c,
|
|
@@ -860,16 +886,16 @@ async function F(n) {
|
|
|
860
886
|
}
|
|
861
887
|
}
|
|
862
888
|
);
|
|
863
|
-
} catch (
|
|
864
|
-
|
|
865
|
-
debugs: [`Error sending request: ${
|
|
889
|
+
} catch (f) {
|
|
890
|
+
p({
|
|
891
|
+
debugs: [`Error sending request: ${f}`],
|
|
866
892
|
name: "ARKYN_LOG_ERROR",
|
|
867
893
|
scheme: "red"
|
|
868
894
|
});
|
|
869
895
|
}
|
|
870
896
|
}
|
|
871
|
-
async function
|
|
872
|
-
const
|
|
897
|
+
async function g(n, t, s = {}, e) {
|
|
898
|
+
const r = {
|
|
873
899
|
POST: "Resource created successfully",
|
|
874
900
|
PUT: "Resource updated successfully",
|
|
875
901
|
DELETE: "Resource deleted successfully",
|
|
@@ -902,7 +928,7 @@ async function b(n, t, s = {}, e) {
|
|
|
902
928
|
return F(d), h.ok ? {
|
|
903
929
|
success: !0,
|
|
904
930
|
status: l,
|
|
905
|
-
message: (a == null ? void 0 : a.message) ||
|
|
931
|
+
message: (a == null ? void 0 : a.message) || r[n],
|
|
906
932
|
response: a,
|
|
907
933
|
cause: null
|
|
908
934
|
} : {
|
|
@@ -913,7 +939,7 @@ async function b(n, t, s = {}, e) {
|
|
|
913
939
|
cause: null
|
|
914
940
|
};
|
|
915
941
|
} catch (u) {
|
|
916
|
-
return
|
|
942
|
+
return p({
|
|
917
943
|
debugs: [`Network error or request failed: ${u}`],
|
|
918
944
|
name: "ARKYN_MAKE_REQUEST_ERROR",
|
|
919
945
|
scheme: "red"
|
|
@@ -927,19 +953,19 @@ async function b(n, t, s = {}, e) {
|
|
|
927
953
|
}
|
|
928
954
|
}
|
|
929
955
|
async function M(n, t = {}, s) {
|
|
930
|
-
return
|
|
956
|
+
return g("DELETE", n, t, s);
|
|
931
957
|
}
|
|
932
958
|
async function _(n, t = {}) {
|
|
933
|
-
return
|
|
959
|
+
return g("GET", n, t);
|
|
934
960
|
}
|
|
935
961
|
async function z(n, t = {}, s) {
|
|
936
|
-
return
|
|
962
|
+
return g("PATCH", n, t, s);
|
|
937
963
|
}
|
|
938
964
|
async function G(n, t = {}, s) {
|
|
939
|
-
return
|
|
965
|
+
return g("POST", n, t, s);
|
|
940
966
|
}
|
|
941
967
|
async function K(n, t = {}, s) {
|
|
942
|
-
return
|
|
968
|
+
return g("PUT", n, t, s);
|
|
943
969
|
}
|
|
944
970
|
class X {
|
|
945
971
|
/**
|
|
@@ -951,10 +977,10 @@ class X {
|
|
|
951
977
|
* @param props.enableDebug - Optional flag to enable debug logging for requests.
|
|
952
978
|
*/
|
|
953
979
|
constructor(t) {
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
980
|
+
o(this, "baseUrl");
|
|
981
|
+
o(this, "baseHeaders");
|
|
982
|
+
o(this, "baseToken");
|
|
983
|
+
o(this, "enableDebug");
|
|
958
984
|
this.baseUrl = t.baseUrl, this.baseHeaders = t.baseHeaders || void 0, this.baseToken = t.baseToken || void 0, this.enableDebug = t.enableDebug || !1;
|
|
959
985
|
}
|
|
960
986
|
/**
|
|
@@ -964,8 +990,8 @@ class X {
|
|
|
964
990
|
*/
|
|
965
991
|
onDebug(t, s, e) {
|
|
966
992
|
if (this.enableDebug) {
|
|
967
|
-
const
|
|
968
|
-
|
|
993
|
+
const r = [];
|
|
994
|
+
r.push(`Base URL: ${this.baseUrl}`), r.push(`Endpoint: ${t}`), r.push(`Method: ${s}`), e[0] && r.push(`Headers: ${JSON.stringify(e[0])}`), e[1] && r.push(`Body: ${JSON.stringify(e[1])}`), p({ debugs: r, name: "ARKYN-API-DEBUG", scheme: "yellow" });
|
|
969
995
|
}
|
|
970
996
|
}
|
|
971
997
|
generateURL(t) {
|
|
@@ -988,8 +1014,8 @@ class X {
|
|
|
988
1014
|
* @returns The API response data.
|
|
989
1015
|
*/
|
|
990
1016
|
async get(t, s) {
|
|
991
|
-
const e = this.generateURL(t),
|
|
992
|
-
return this.onDebug(t, "get", [
|
|
1017
|
+
const e = this.generateURL(t), r = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token);
|
|
1018
|
+
return this.onDebug(t, "get", [r]), await _(e, r);
|
|
993
1019
|
}
|
|
994
1020
|
/**
|
|
995
1021
|
* Sends a post request to the specified endpoint.
|
|
@@ -998,8 +1024,8 @@ class X {
|
|
|
998
1024
|
* @returns The API response data.
|
|
999
1025
|
*/
|
|
1000
1026
|
async post(t, s) {
|
|
1001
|
-
const e = this.generateURL(t),
|
|
1002
|
-
return this.onDebug(t, "post", [
|
|
1027
|
+
const e = this.generateURL(t), r = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
|
|
1028
|
+
return this.onDebug(t, "post", [r, u]), await G(e, r, u);
|
|
1003
1029
|
}
|
|
1004
1030
|
/**
|
|
1005
1031
|
* Sends a put request to the specified endpoint.
|
|
@@ -1008,8 +1034,8 @@ class X {
|
|
|
1008
1034
|
* @returns The API response data.
|
|
1009
1035
|
*/
|
|
1010
1036
|
async put(t, s) {
|
|
1011
|
-
const e = this.generateURL(t),
|
|
1012
|
-
return this.onDebug(t, "put", [
|
|
1037
|
+
const e = this.generateURL(t), r = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
|
|
1038
|
+
return this.onDebug(t, "put", [r, u]), await K(e, r, u);
|
|
1013
1039
|
}
|
|
1014
1040
|
/**
|
|
1015
1041
|
* Sends a patch request to the specified endpoint.
|
|
@@ -1018,8 +1044,8 @@ class X {
|
|
|
1018
1044
|
* @returns The API response data.
|
|
1019
1045
|
*/
|
|
1020
1046
|
async patch(t, s) {
|
|
1021
|
-
const e = this.generateURL(t),
|
|
1022
|
-
return this.onDebug(t, "patch", [
|
|
1047
|
+
const e = this.generateURL(t), r = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
|
|
1048
|
+
return this.onDebug(t, "patch", [r, u]), await z(e, r, u);
|
|
1023
1049
|
}
|
|
1024
1050
|
/**
|
|
1025
1051
|
* Sends a delete request to the specified endpoint.
|
|
@@ -1028,13 +1054,13 @@ class X {
|
|
|
1028
1054
|
* @returns The API response data.
|
|
1029
1055
|
*/
|
|
1030
1056
|
async delete(t, s) {
|
|
1031
|
-
const e = this.generateURL(t),
|
|
1032
|
-
return this.onDebug(t, "delete", [
|
|
1057
|
+
const e = this.generateURL(t), r = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
|
|
1058
|
+
return this.onDebug(t, "delete", [r, u]), await M(e, r, u);
|
|
1033
1059
|
}
|
|
1034
1060
|
}
|
|
1035
1061
|
function Z(n, t) {
|
|
1036
|
-
var s, e,
|
|
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" ? (
|
|
1062
|
+
var s, e, r;
|
|
1063
|
+
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" ? (r = n == null ? void 0 : n.error) == null ? void 0 : r.message : t != null && t.statusText && typeof (t == null ? void 0 : t.statusText) == "string" ? t == null ? void 0 : t.statusText : "Missing error message";
|
|
1038
1064
|
}
|
|
1039
1065
|
const ss = async (n) => {
|
|
1040
1066
|
let t;
|
|
@@ -1047,9 +1073,9 @@ const ss = async (n) => {
|
|
|
1047
1073
|
const u = new URLSearchParams(e);
|
|
1048
1074
|
t = Object.fromEntries(u.entries());
|
|
1049
1075
|
} else
|
|
1050
|
-
throw new
|
|
1076
|
+
throw new b("Invalid URLSearchParams format");
|
|
1051
1077
|
} catch {
|
|
1052
|
-
throw new
|
|
1078
|
+
throw new b("Failed to extract data from request");
|
|
1053
1079
|
}
|
|
1054
1080
|
}
|
|
1055
1081
|
return t;
|
|
@@ -1058,7 +1084,7 @@ function es(n) {
|
|
|
1058
1084
|
switch (!0) {
|
|
1059
1085
|
case n instanceof Response:
|
|
1060
1086
|
return n;
|
|
1061
|
-
case n instanceof
|
|
1087
|
+
case n instanceof $:
|
|
1062
1088
|
return n.toResponse();
|
|
1063
1089
|
case n instanceof P:
|
|
1064
1090
|
return n.toResponse();
|
|
@@ -1066,13 +1092,13 @@ function es(n) {
|
|
|
1066
1092
|
return n.toResponse();
|
|
1067
1093
|
case n instanceof A:
|
|
1068
1094
|
return n.toResponse();
|
|
1069
|
-
case n instanceof
|
|
1095
|
+
case n instanceof H:
|
|
1070
1096
|
return n.toResponse();
|
|
1071
1097
|
}
|
|
1072
1098
|
switch (!0) {
|
|
1073
1099
|
case n instanceof j:
|
|
1074
1100
|
return n.toResponse();
|
|
1075
|
-
case n instanceof
|
|
1101
|
+
case n instanceof b:
|
|
1076
1102
|
return n.toResponse();
|
|
1077
1103
|
case n instanceof J:
|
|
1078
1104
|
return n.toResponse();
|
|
@@ -1082,14 +1108,14 @@ function es(n) {
|
|
|
1082
1108
|
return n.toResponse();
|
|
1083
1109
|
case n instanceof B:
|
|
1084
1110
|
return n.toResponse();
|
|
1085
|
-
case n instanceof
|
|
1111
|
+
case n instanceof m:
|
|
1086
1112
|
return n.toResponse();
|
|
1087
1113
|
case n instanceof q:
|
|
1088
1114
|
return n.toResponse();
|
|
1089
1115
|
case n instanceof N:
|
|
1090
1116
|
return n.toResponse();
|
|
1091
1117
|
}
|
|
1092
|
-
return new
|
|
1118
|
+
return new m("Server error", n).toResponse();
|
|
1093
1119
|
}
|
|
1094
1120
|
function V([
|
|
1095
1121
|
n,
|
|
@@ -1098,7 +1124,7 @@ function V([
|
|
|
1098
1124
|
const s = t.safeParse(n);
|
|
1099
1125
|
if (s.success === !1) {
|
|
1100
1126
|
const e = Object.fromEntries(
|
|
1101
|
-
s.error.issues.map((
|
|
1127
|
+
s.error.issues.map((r) => [r.path.join("."), r.message])
|
|
1102
1128
|
);
|
|
1103
1129
|
return {
|
|
1104
1130
|
success: s.success,
|
|
@@ -1116,22 +1142,22 @@ const ts = (n, t = "") => {
|
|
|
1116
1142
|
if (t === "") return s.searchParams;
|
|
1117
1143
|
const e = Array.from(
|
|
1118
1144
|
s.searchParams.entries()
|
|
1119
|
-
).filter(([
|
|
1145
|
+
).filter(([r]) => r.startsWith(`${t}:`)).map(([r, u]) => [r.replace(`${t}:`, ""), u]);
|
|
1120
1146
|
return new URLSearchParams(e);
|
|
1121
1147
|
};
|
|
1122
1148
|
function Y(n) {
|
|
1123
1149
|
const t = "Error validating:", s = n.issues.map(
|
|
1124
|
-
({ path: e, message:
|
|
1150
|
+
({ path: e, message: r }) => `-> ${e.join(".")}: ${r}`
|
|
1125
1151
|
);
|
|
1126
1152
|
return [t, ...s].join(`
|
|
1127
1153
|
`);
|
|
1128
1154
|
}
|
|
1129
1155
|
class ns {
|
|
1130
1156
|
constructor(t) {
|
|
1131
|
-
|
|
1132
|
-
|
|
1157
|
+
o(this, "functionName");
|
|
1158
|
+
o(this, "callerInfo");
|
|
1133
1159
|
this.schema = t;
|
|
1134
|
-
const { callerInfo: s, functionName: e } =
|
|
1160
|
+
const { callerInfo: s, functionName: e } = x();
|
|
1135
1161
|
this.callerInfo = s, this.functionName = e;
|
|
1136
1162
|
}
|
|
1137
1163
|
isValid(t) {
|
|
@@ -1144,17 +1170,17 @@ class ns {
|
|
|
1144
1170
|
try {
|
|
1145
1171
|
return this.schema.parse(t);
|
|
1146
1172
|
} catch (s) {
|
|
1147
|
-
throw new
|
|
1173
|
+
throw new m(Y(s));
|
|
1148
1174
|
}
|
|
1149
1175
|
}
|
|
1150
1176
|
formValidate(t, s) {
|
|
1151
1177
|
const e = V([t, this.schema]);
|
|
1152
1178
|
if (!e.success) {
|
|
1153
|
-
const
|
|
1179
|
+
const r = Object.keys(e.fieldErrors)[0];
|
|
1154
1180
|
throw new N({
|
|
1155
1181
|
fields: e.fields,
|
|
1156
1182
|
fieldErrors: e.fieldErrors,
|
|
1157
|
-
data: { scrollTo:
|
|
1183
|
+
data: { scrollTo: r },
|
|
1158
1184
|
message: s
|
|
1159
1185
|
});
|
|
1160
1186
|
}
|
|
@@ -1165,17 +1191,17 @@ export {
|
|
|
1165
1191
|
X as ApiService,
|
|
1166
1192
|
w as ArkynLogService,
|
|
1167
1193
|
j as BadGateway,
|
|
1168
|
-
|
|
1194
|
+
b as BadRequest,
|
|
1169
1195
|
J as Conflict,
|
|
1170
1196
|
P as Created,
|
|
1171
1197
|
S as DebugService,
|
|
1172
1198
|
D as Forbidden,
|
|
1173
|
-
|
|
1174
|
-
|
|
1199
|
+
$ as Found,
|
|
1200
|
+
H as NoContent,
|
|
1175
1201
|
C as NotFound,
|
|
1176
1202
|
B as NotImplemented,
|
|
1177
1203
|
ns as SchemaValidator,
|
|
1178
|
-
|
|
1204
|
+
m as ServerError,
|
|
1179
1205
|
A as Success,
|
|
1180
1206
|
q as Unauthorized,
|
|
1181
1207
|
N as UnprocessableEntity,
|
|
@@ -1183,8 +1209,8 @@ export {
|
|
|
1183
1209
|
Z as decodeErrorMessageFromRequest,
|
|
1184
1210
|
ss as decodeRequestBody,
|
|
1185
1211
|
es as errorHandler,
|
|
1186
|
-
|
|
1212
|
+
p as flushDebugLogs,
|
|
1187
1213
|
V as formParse,
|
|
1188
|
-
|
|
1214
|
+
x as getCaller,
|
|
1189
1215
|
ts as getScopedParams
|
|
1190
1216
|
};
|
package/dist/bundle.umd.cjs
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
(function(a,
|
|
2
|
-
`;n.debugs.forEach(d=>{
|
|
3
|
-
`}),console.log(
|
|
4
|
-
`).map(i=>i.trim()),
|
|
5
|
-
`),
|
|
6
|
-
`),
|
|
7
|
-
`),
|
|
8
|
-
`),e&&
|
|
9
|
-
`),
|
|
10
|
-
`),o.
|
|
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 H{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 L(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 A="HTTPS";g.protocol==="http:"&&(A="HTTP");const ss=JSON.stringify({domainUrl:g.protocol+"//"+g.host,pathnameUrl:g.pathname,status:p,protocol:A,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=H.handle({elapsedTime:h,method:n,queryParams:new URL(t).searchParams,requestHeaders:l,requestBody:e,responseBody:i,responseHeaders:d.headers,status:f,url:t});return L(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: ${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(t,"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(t,"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(t,"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(t,"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 v([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=v([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=v,a.getCaller=R,a.getScopedParams=Q,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(a,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(a=typeof globalThis<"u"?globalThis:a||self,l(a["@arkyn/server"]={}))})(this,function(a){"use strict";var es=Object.defineProperty;var ts=(a,l,g)=>l in a?es(a,l,{enumerable:!0,configurable:!0,writable:!0,value:g}):a[l]=g;var o=(a,l,g)=>ts(a,typeof l!="symbol"?l+"":l,g);function l(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 c=`
|
|
2
|
+
`;n.debugs.forEach(d=>{c+=`${u} ${d.trim()}
|
|
3
|
+
`}),console.log(c)}}const g={};class N{static setIgnoreFile(t){this.ignoreFiles.push(t)}static clearIgnoreFiles(){this.ignoreFiles=[]}}o(N,"ignoreFiles",[]);function R(){const n=process.cwd(),e=(new Error().stack||"").split(`
|
|
4
|
+
`).map(i=>i.trim()),r=N.ignoreFiles;let u=2;for(;u<e.length&&(e[u].includes("node:internal")||e[u].includes("/node_modules/"));)u++;if(r.length>0)for(;u<e.length&&r.some(i=>e[u].includes(i));)u++;const c=e[u]||"";let d="Unknown function",h="Unknown caller";const f=c.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);if(f)d=f[1],h=f[2];else{const i=c.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=g.relative(n,h)}catch{}return{functionName:d,callerInfo:h}}class y{onDebug(t){const{name:s,body:e,cause:r,message:u}=t,c=[],{callerInfo:d,functionName:h}=R();c.push(`${s} initialized`),c.push(`Caller Function: ${h}`),c.push(`Caller Location: ${d}`),u&&c.push(`Message: ${u}`),e&&c.push(`Body: ${JSON.stringify(e,null,2)}`),r&&c.push(`Cause: ${JSON.stringify(r,null,2)}`),l({scheme:"red",name:"ARKYN-BAD-RESPONSE-DEBUG",debugs:c})}}class O extends y{constructor(s,e){super();o(this,"body");o(this,"cause");o(this,"status",502);o(this,"statusText");this.body={name:"BadGateway",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug({name:"BadGateway",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class x extends y{constructor(s,e){super();o(this,"body");o(this,"cause");o(this,"status",400);o(this,"statusText");this.body={name:"BadRequest",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug({name:"BadRequest",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class U extends y{constructor(s,e){super();o(this,"body");o(this,"cause");o(this,"status",409);o(this,"statusText");this.body={name:"Conflict",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug({name:"Conflict",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class I extends y{constructor(s,e){super();o(this,"body");o(this,"cause");o(this,"status",403);o(this,"statusText");this.body={name:"Forbidden",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug({name:"Forbidden",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class k extends y{constructor(s,e){super();o(this,"body");o(this,"cause");o(this,"status",404);o(this,"statusText");this.body={name:"NotFound",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug({name:"NotFound",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class j extends y{constructor(s,e){super();o(this,"body");o(this,"cause");o(this,"status",501);o(this,"statusText");this.body={name:"NotImplemented",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug({name:"NotImplemented",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class S extends y{constructor(s,e){super();o(this,"body");o(this,"cause");o(this,"status",500);o(this,"statusText");this.body={name:"ServerError",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug({name:"ServerError",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class C extends y{constructor(s,e){super();o(this,"body");o(this,"cause");o(this,"status",401);o(this,"statusText");this.body={name:"Unauthorized",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug({name:"Unauthorized",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class w extends y{constructor(s){super();o(this,"body");o(this,"status",422);o(this,"statusText");this.statusText=s.message||"Unprocessable Entity",this.body={name:"UnprocessableEntity",message:s.message||null,data:s.data,fieldErrors:s.fieldErrors,fields:s.fields},this.onDebug({name:"UnprocessableEntity",cause:s.fieldErrors,message:s.message})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class T{onDebug(t,s,e){const r=[],{callerInfo:u,functionName:c}=R();r.push(`${t} initialized
|
|
5
|
+
`),r.push(`Caller Function: ${c}
|
|
6
|
+
`),r.push(`Caller Location: ${u}
|
|
7
|
+
`),r.push(`Body: ${JSON.stringify(s,null,2)}
|
|
8
|
+
`),e&&r.push(`Cause: ${JSON.stringify(e,null,2)}
|
|
9
|
+
`),l({scheme:"green",name:"ARKYN-SUCCESS-RESPONSE-DEBUG",debugs:r})}}class J extends T{constructor(s,e){super();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",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();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",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();o(this,"headers");o(this,"status");o(this,"statusText");this.headers=(s==null?void 0:s.headers)||{},this.status=(s==null?void 0:s.status)||204,this.statusText=(s==null?void 0:s.statusText)??"No content",this.onDebug("No content",null)}toResponse(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return new Response(null,s)}}class q extends T{constructor(s,e){super();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",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();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",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 H{static mapHeaders(t){return t instanceof Headers?Object.fromEntries(t.entries()):typeof t=="object"?Object.entries(t).reduce((s,[e,r])=>(typeof r=="string"?s[e]=r:Array.isArray(r)?s[e]=r.join(", "):s[e]=JSON.stringify(r),s),{}):{}}static mapQueryParams(t){const s={};return t.forEach((e,r)=>{s[r]=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}}o(E,"arkynConfig");async function L(n){const t=E.getArkynConfig();if(!t)return;const{arkynUserToken:s,arkynApiUrl:e}=t,{elapsedTime:r,method:u,queryParams:c,requestBody:d,requestHeaders:h,responseBody:f,responseHeaders:i,status:p,token:ns,rawUrl:Z}=n;if(process.env.NODE_ENV!=="development")try{const b=new URL(Z);let A="HTTPS";b.protocol==="http:"&&(A="HTTP");const ss=JSON.stringify({domainUrl:b.protocol+"//"+b.host,pathnameUrl:b.pathname,status:p,protocol:A,method:u,trafficUserId:null,elapsedTime:r,requestHeaders:h,requestBody:d,queryParams:c,responseHeaders:i,responseBody:f});await fetch(e.replace(":trafficSourceId",t.arkynTrafficSourceId),{method:"POST",body:ss,headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`}})}catch(b){l({debugs:[`Error sending request: ${b}`],name:"ARKYN_LOG_ERROR",scheme:"red"})}}async function m(n,t,s={},e){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(),c={...s,"Content-Type":"application/json"},d=await fetch(t,{method:n,headers:c,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=H.handle({elapsedTime:h,method:n,queryParams:new URL(t).searchParams,requestHeaders:c,requestBody:e,responseBody:i,responseHeaders:d.headers,status:f,url:t});return L(p),d.ok?{success:!0,status:f,message:(i==null?void 0:i.message)||r[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 l({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){o(this,"baseUrl");o(this,"baseHeaders");o(this,"baseToken");o(this,"enableDebug");this.baseUrl=t.baseUrl,this.baseHeaders=t.baseHeaders||void 0,this.baseToken=t.baseToken||void 0,this.enableDebug=t.enableDebug||!1}onDebug(t,s,e){if(this.enableDebug){const r=[];r.push(`Base URL: ${this.baseUrl}`),r.push(`Endpoint: ${t}`),r.push(`Method: ${s}`),e[0]&&r.push(`Headers: ${JSON.stringify(e[0])}`),e[1]&&r.push(`Body: ${JSON.stringify(e[1])}`),l({debugs:r,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),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token);return this.onDebug(t,"get",[r]),await F(e,r)}async post(t,s){const e=this.generateURL(t),r=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,"post",[r,u]),await _(e,r,u)}async put(t,s){const e=this.generateURL(t),r=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",[r,u]),await z(e,r,u)}async patch(t,s){const e=this.generateURL(t),r=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,"patch",[r,u]),await M(e,r,u)}async delete(t,s){const e=this.generateURL(t),r=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,"delete",[r,u]),await $(e,r,u)}}function K(n,t){var s,e,r;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"?(r=n==null?void 0:n.error)==null?void 0:r.message:t!=null&&t.statusText&&typeof(t==null?void 0:t.statusText)=="string"?t==null?void 0:t.statusText:"Missing error message"}const 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 v([n,t]){const s=t.safeParse(n);if(s.success===!1){const e=Object.fromEntries(s.error.issues.map(r=>[r.path.join("."),r.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(([r])=>r.startsWith(`${t}:`)).map(([r,u])=>[r.replace(`${t}:`,""),u]);return new URLSearchParams(e)};function W(n){const t="Error validating:",s=n.issues.map(({path:e,message:r})=>`-> ${e.join(".")}: ${r}`);return[t,...s].join(`
|
|
10
|
+
`)}class X{constructor(t){o(this,"functionName");o(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=v([t,this.schema]);if(!e.success){const r=Object.keys(e.fieldErrors)[0];throw new w({fields:e.fields,fieldErrors:e.fieldErrors,data:{scrollTo:r},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=l,a.formParse=v,a.getCaller=R,a.getScopedParams=Q,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
type Input = {
|
|
2
|
+
name: string;
|
|
3
|
+
body?: any;
|
|
4
|
+
cause?: any;
|
|
5
|
+
message?: string;
|
|
6
|
+
};
|
|
5
7
|
declare class BadResponse {
|
|
6
|
-
|
|
7
|
-
* Logs debug information for bad responses including caller context and response details.
|
|
8
|
-
*
|
|
9
|
-
* @param name - The name/type of the bad response being logged
|
|
10
|
-
* @param body - The response body or error data to be logged
|
|
11
|
-
* @param cause - Optional additional cause information for the error
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* const badResponse = new BadResponse();
|
|
16
|
-
* badResponse.onDebug("ValidationError", { field: "email", message: "Invalid format" });
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
onDebug(name: string, body: any, cause?: any): void;
|
|
8
|
+
onDebug(input: Input): void;
|
|
20
9
|
}
|
|
21
10
|
export { BadResponse };
|
|
22
11
|
//# sourceMappingURL=_badResponse.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_badResponse.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/_badResponse.ts"],"names":[],"mappings":"AAGA
|
|
1
|
+
{"version":3,"file":"_badResponse.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/_badResponse.ts"],"names":[],"mappings":"AAGA,KAAK,KAAK,GAAG;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,cAAM,WAAW;IACf,OAAO,CAAC,KAAK,EAAE,KAAK;CAgBrB;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -1,32 +1,19 @@
|
|
|
1
1
|
import { flushDebugLogs } from "../../services/flushDebugLogs";
|
|
2
2
|
import { getCaller } from "../../services/getCaller";
|
|
3
|
-
/**
|
|
4
|
-
* Base class for handling bad HTTP responses with debugging capabilities.
|
|
5
|
-
* Provides logging functionality to track response errors and their context.
|
|
6
|
-
*/
|
|
7
3
|
class BadResponse {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
* @param name - The name/type of the bad response being logged
|
|
12
|
-
* @param body - The response body or error data to be logged
|
|
13
|
-
* @param cause - Optional additional cause information for the error
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* const badResponse = new BadResponse();
|
|
18
|
-
* badResponse.onDebug("ValidationError", { field: "email", message: "Invalid format" });
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
onDebug(name, body, cause) {
|
|
4
|
+
onDebug(input) {
|
|
5
|
+
const { name, body, cause, message } = input;
|
|
22
6
|
const debugs = [];
|
|
23
7
|
const { callerInfo, functionName } = getCaller();
|
|
24
|
-
debugs.push(`${name} initialized
|
|
25
|
-
debugs.push(`Caller Function: ${functionName}
|
|
26
|
-
debugs.push(`Caller Location: ${callerInfo}
|
|
27
|
-
|
|
8
|
+
debugs.push(`${name} initialized`);
|
|
9
|
+
debugs.push(`Caller Function: ${functionName}`);
|
|
10
|
+
debugs.push(`Caller Location: ${callerInfo}`);
|
|
11
|
+
if (message)
|
|
12
|
+
debugs.push(`Message: ${message}`);
|
|
13
|
+
if (body)
|
|
14
|
+
debugs.push(`Body: ${JSON.stringify(body, null, 2)}`);
|
|
28
15
|
if (cause)
|
|
29
|
-
debugs.push(`Cause: ${JSON.stringify(cause, null, 2)}
|
|
16
|
+
debugs.push(`Cause: ${JSON.stringify(cause, null, 2)}`);
|
|
30
17
|
flushDebugLogs({ scheme: "red", name: "ARKYN-BAD-RESPONSE-DEBUG", debugs });
|
|
31
18
|
}
|
|
32
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"badGateway.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/badGateway.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,UAAW,SAAQ,WAAW;IAClC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;
|
|
1
|
+
{"version":3,"file":"badGateway.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/badGateway.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,UAAW,SAAQ,WAAW;IAClC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAexC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -20,7 +20,12 @@ class BadGateway extends BadResponse {
|
|
|
20
20
|
this.body = { name: "BadGateway", message: message };
|
|
21
21
|
this.statusText = message;
|
|
22
22
|
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
23
|
-
this.onDebug(
|
|
23
|
+
this.onDebug({
|
|
24
|
+
name: "BadGateway",
|
|
25
|
+
body: this.body,
|
|
26
|
+
cause: this.cause,
|
|
27
|
+
message: this.statusText,
|
|
28
|
+
});
|
|
24
29
|
}
|
|
25
30
|
/**
|
|
26
31
|
* Converts the `BadGateway` instance into a `Response` object with a JSON body.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"badRequest.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/badRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,UAAW,SAAQ,WAAW;IAClC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;
|
|
1
|
+
{"version":3,"file":"badRequest.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/badRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,UAAW,SAAQ,WAAW;IAClC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAexC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -20,7 +20,12 @@ class BadRequest extends BadResponse {
|
|
|
20
20
|
this.body = { name: "BadRequest", message: message };
|
|
21
21
|
this.statusText = message;
|
|
22
22
|
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
23
|
-
this.onDebug(
|
|
23
|
+
this.onDebug({
|
|
24
|
+
name: "BadRequest",
|
|
25
|
+
body: this.body,
|
|
26
|
+
cause: this.cause,
|
|
27
|
+
message: this.statusText,
|
|
28
|
+
});
|
|
24
29
|
}
|
|
25
30
|
/**
|
|
26
31
|
* Converts the `BadRequest` instance into a `Response` object with a JSON body.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conflict.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/conflict.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,QAAS,SAAQ,WAAW;IAChC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;
|
|
1
|
+
{"version":3,"file":"conflict.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/conflict.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,QAAS,SAAQ,WAAW;IAChC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAexC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -20,7 +20,12 @@ class Conflict extends BadResponse {
|
|
|
20
20
|
this.body = { name: "Conflict", message: message };
|
|
21
21
|
this.statusText = message;
|
|
22
22
|
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
23
|
-
this.onDebug(
|
|
23
|
+
this.onDebug({
|
|
24
|
+
name: "Conflict",
|
|
25
|
+
body: this.body,
|
|
26
|
+
cause: this.cause,
|
|
27
|
+
message: this.statusText,
|
|
28
|
+
});
|
|
24
29
|
}
|
|
25
30
|
/**
|
|
26
31
|
* Converts the `Conflict` instance into a `Response` object with a JSON body.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forbidden.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/forbidden.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,SAAU,SAAQ,WAAW;IACjC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;
|
|
1
|
+
{"version":3,"file":"forbidden.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/forbidden.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,SAAU,SAAQ,WAAW;IACjC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAexC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -20,7 +20,12 @@ class Forbidden extends BadResponse {
|
|
|
20
20
|
this.body = { name: "Forbidden", message: message };
|
|
21
21
|
this.statusText = message;
|
|
22
22
|
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
23
|
-
this.onDebug(
|
|
23
|
+
this.onDebug({
|
|
24
|
+
name: "Forbidden",
|
|
25
|
+
body: this.body,
|
|
26
|
+
cause: this.cause,
|
|
27
|
+
message: this.statusText,
|
|
28
|
+
});
|
|
24
29
|
}
|
|
25
30
|
/**
|
|
26
31
|
* Converts the `Forbidden` instance into a `Response` object with a JSON body.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notFound.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/notFound.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,QAAS,SAAQ,WAAW;IAChC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;
|
|
1
|
+
{"version":3,"file":"notFound.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/notFound.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,QAAS,SAAQ,WAAW;IAChC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAexC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -20,7 +20,12 @@ class NotFound extends BadResponse {
|
|
|
20
20
|
this.body = { name: "NotFound", message: message };
|
|
21
21
|
this.statusText = message;
|
|
22
22
|
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
23
|
-
this.onDebug(
|
|
23
|
+
this.onDebug({
|
|
24
|
+
name: "NotFound",
|
|
25
|
+
body: this.body,
|
|
26
|
+
cause: this.cause,
|
|
27
|
+
message: this.statusText,
|
|
28
|
+
});
|
|
24
29
|
}
|
|
25
30
|
/**
|
|
26
31
|
* Converts the `NotFound` instance into a `Response` object with a JSON body.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notImplemented.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/notImplemented.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,cAAe,SAAQ,WAAW;IACtC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;
|
|
1
|
+
{"version":3,"file":"notImplemented.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/notImplemented.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,cAAe,SAAQ,WAAW;IACtC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAexC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -20,7 +20,12 @@ class NotImplemented extends BadResponse {
|
|
|
20
20
|
this.body = { name: "NotImplemented", message: message };
|
|
21
21
|
this.statusText = message;
|
|
22
22
|
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
23
|
-
this.onDebug(
|
|
23
|
+
this.onDebug({
|
|
24
|
+
name: "NotImplemented",
|
|
25
|
+
body: this.body,
|
|
26
|
+
cause: this.cause,
|
|
27
|
+
message: this.statusText,
|
|
28
|
+
});
|
|
24
29
|
}
|
|
25
30
|
/**
|
|
26
31
|
* Converts the `NotImplemented` instance into a `Response` object with a JSON body.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverError.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/serverError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,WAAY,SAAQ,WAAW;IACnC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;
|
|
1
|
+
{"version":3,"file":"serverError.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/serverError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,WAAY,SAAQ,WAAW;IACnC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAexC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -20,7 +20,12 @@ class ServerError extends BadResponse {
|
|
|
20
20
|
this.body = { name: "ServerError", message: message };
|
|
21
21
|
this.statusText = message;
|
|
22
22
|
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
23
|
-
this.onDebug(
|
|
23
|
+
this.onDebug({
|
|
24
|
+
name: "ServerError",
|
|
25
|
+
body: this.body,
|
|
26
|
+
cause: this.cause,
|
|
27
|
+
message: this.statusText,
|
|
28
|
+
});
|
|
24
29
|
}
|
|
25
30
|
/**
|
|
26
31
|
* Converts the `ServerError` instance into a `Response` object with a JSON body.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unauthorized.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/unauthorized.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,YAAa,SAAQ,WAAW;IACpC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;
|
|
1
|
+
{"version":3,"file":"unauthorized.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/unauthorized.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,YAAa,SAAQ,WAAW;IACpC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAexC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -20,7 +20,12 @@ class Unauthorized extends BadResponse {
|
|
|
20
20
|
this.body = { name: "Unauthorized", message: message };
|
|
21
21
|
this.statusText = message;
|
|
22
22
|
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
23
|
-
this.onDebug(
|
|
23
|
+
this.onDebug({
|
|
24
|
+
name: "Unauthorized",
|
|
25
|
+
body: this.body,
|
|
26
|
+
cause: this.cause,
|
|
27
|
+
message: this.statusText,
|
|
28
|
+
});
|
|
24
29
|
}
|
|
25
30
|
/**
|
|
26
31
|
* Converts the `Unauthorized` instance into a `Response` object with a JSON body.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unprocessableEntity.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/unprocessableEntity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,KAAK,wBAAwB,GAAG;IAC9B,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;GAIG;AAEH,cAAM,mBAAoB,SAAQ,WAAW;IAC3C,IAAI,EAAE,GAAG,CAAC;IACV,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;;;;OASG;gBAES,KAAK,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"unprocessableEntity.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/unprocessableEntity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,KAAK,wBAAwB,GAAG;IAC9B,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;GAIG;AAEH,cAAM,mBAAoB,SAAQ,WAAW;IAC3C,IAAI,EAAE,GAAG,CAAC;IACV,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;;;;OASG;gBAES,KAAK,EAAE,wBAAwB;IAmB3C;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -28,7 +28,11 @@ class UnprocessableEntity extends BadResponse {
|
|
|
28
28
|
fieldErrors: props.fieldErrors,
|
|
29
29
|
fields: props.fields,
|
|
30
30
|
};
|
|
31
|
-
this.onDebug(
|
|
31
|
+
this.onDebug({
|
|
32
|
+
name: "UnprocessableEntity",
|
|
33
|
+
cause: props.fieldErrors,
|
|
34
|
+
message: props.message,
|
|
35
|
+
});
|
|
32
36
|
}
|
|
33
37
|
/**
|
|
34
38
|
* Converts the `UnprocessableEntity` instance into a `Response` object with a JSON body.
|
|
@@ -10,7 +10,7 @@ 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
15
|
consoleData += `${debugName} ${debug.trim()}\n`;
|
|
16
16
|
});
|