@arkyn/server 3.0.1-beta.64 → 3.0.1-beta.66
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 +36 -37
- package/dist/bundle.umd.cjs +3 -4
- package/dist/services/apiService.js +5 -5
- package/dist/services/flushDebugLogs.js +1 -1
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -10,8 +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 =
|
|
14
|
-
`;
|
|
13
|
+
let c = "";
|
|
15
14
|
n.debugs.forEach((h) => {
|
|
16
15
|
c += `${u} ${h.trim()}
|
|
17
16
|
`;
|
|
@@ -79,8 +78,8 @@ function R() {
|
|
|
79
78
|
const a = c.match(/at\s+(.+)/);
|
|
80
79
|
if (a) {
|
|
81
80
|
i = a[1];
|
|
82
|
-
const
|
|
83
|
-
|
|
81
|
+
const d = i.match(/at\s+([^(\s]+)\s+/);
|
|
82
|
+
d && d[1] !== "new" && (h = d[1]);
|
|
84
83
|
}
|
|
85
84
|
}
|
|
86
85
|
i.includes("(") && (i = i.substring(
|
|
@@ -93,7 +92,7 @@ function R() {
|
|
|
93
92
|
}
|
|
94
93
|
return { functionName: h, callerInfo: i };
|
|
95
94
|
}
|
|
96
|
-
class
|
|
95
|
+
class y {
|
|
97
96
|
/**
|
|
98
97
|
* Logs debug information for bad responses including caller context and response details.
|
|
99
98
|
*
|
|
@@ -117,7 +116,7 @@ class d {
|
|
|
117
116
|
`), f({ scheme: "red", name: "ARKYN-BAD-RESPONSE-DEBUG", debugs: o });
|
|
118
117
|
}
|
|
119
118
|
}
|
|
120
|
-
class j extends
|
|
119
|
+
class j extends y {
|
|
121
120
|
/**
|
|
122
121
|
* Creates an instance of the `BadGateway` class.
|
|
123
122
|
*
|
|
@@ -160,7 +159,7 @@ class j extends d {
|
|
|
160
159
|
return Response.json(this.body, s);
|
|
161
160
|
}
|
|
162
161
|
}
|
|
163
|
-
class g extends
|
|
162
|
+
class g extends y {
|
|
164
163
|
/**
|
|
165
164
|
* Creates an instance of the `BadRequest` class.
|
|
166
165
|
*
|
|
@@ -203,7 +202,7 @@ class g extends d {
|
|
|
203
202
|
return Response.json(this.body, s);
|
|
204
203
|
}
|
|
205
204
|
}
|
|
206
|
-
class J extends
|
|
205
|
+
class J extends y {
|
|
207
206
|
/**
|
|
208
207
|
* Creates an instance of the `Conflict` class.
|
|
209
208
|
*
|
|
@@ -246,7 +245,7 @@ class J extends d {
|
|
|
246
245
|
return Response.json(this.body, s);
|
|
247
246
|
}
|
|
248
247
|
}
|
|
249
|
-
class D extends
|
|
248
|
+
class D extends y {
|
|
250
249
|
/**
|
|
251
250
|
* Creates an instance of the `Forbidden` class.
|
|
252
251
|
*
|
|
@@ -289,7 +288,7 @@ class D extends d {
|
|
|
289
288
|
return Response.json(this.body, s);
|
|
290
289
|
}
|
|
291
290
|
}
|
|
292
|
-
class C extends
|
|
291
|
+
class C extends y {
|
|
293
292
|
/**
|
|
294
293
|
* Creates an instance of the `NotFound` class.
|
|
295
294
|
*
|
|
@@ -332,7 +331,7 @@ class C extends d {
|
|
|
332
331
|
return Response.json(this.body, s);
|
|
333
332
|
}
|
|
334
333
|
}
|
|
335
|
-
class B extends
|
|
334
|
+
class B extends y {
|
|
336
335
|
/**
|
|
337
336
|
* Creates an instance of the `NotImplemented` class.
|
|
338
337
|
*
|
|
@@ -375,7 +374,7 @@ class B extends d {
|
|
|
375
374
|
return Response.json(this.body, s);
|
|
376
375
|
}
|
|
377
376
|
}
|
|
378
|
-
class x extends
|
|
377
|
+
class x extends y {
|
|
379
378
|
/**
|
|
380
379
|
* Creates an instance of the `ServerError` class.
|
|
381
380
|
*
|
|
@@ -418,7 +417,7 @@ class x extends d {
|
|
|
418
417
|
return Response.json(this.body, s);
|
|
419
418
|
}
|
|
420
419
|
}
|
|
421
|
-
class q extends
|
|
420
|
+
class q extends y {
|
|
422
421
|
/**
|
|
423
422
|
* Creates an instance of the `Unauthorized` class.
|
|
424
423
|
*
|
|
@@ -461,7 +460,7 @@ class q extends d {
|
|
|
461
460
|
return Response.json(this.body, s);
|
|
462
461
|
}
|
|
463
462
|
}
|
|
464
|
-
class N extends
|
|
463
|
+
class N extends y {
|
|
465
464
|
/**
|
|
466
465
|
* Creates an instance of the `UnprocessableEntity` class.
|
|
467
466
|
*
|
|
@@ -632,7 +631,7 @@ class H extends T {
|
|
|
632
631
|
return Response.json(this.body, s);
|
|
633
632
|
}
|
|
634
633
|
}
|
|
635
|
-
class
|
|
634
|
+
class $ extends T {
|
|
636
635
|
/**
|
|
637
636
|
* Creates an instance of the `NoContent` class.
|
|
638
637
|
*
|
|
@@ -660,7 +659,7 @@ class L extends T {
|
|
|
660
659
|
return new Response(null, s);
|
|
661
660
|
}
|
|
662
661
|
}
|
|
663
|
-
class
|
|
662
|
+
class A extends T {
|
|
664
663
|
/**
|
|
665
664
|
* Creates an instance of the `Success` class.
|
|
666
665
|
*
|
|
@@ -704,7 +703,7 @@ class $ extends T {
|
|
|
704
703
|
return Response.json(this.body, s);
|
|
705
704
|
}
|
|
706
705
|
}
|
|
707
|
-
class
|
|
706
|
+
class L extends T {
|
|
708
707
|
/**
|
|
709
708
|
* Creates an instance of the `Updated` class.
|
|
710
709
|
*
|
|
@@ -823,19 +822,19 @@ async function F(n) {
|
|
|
823
822
|
requestHeaders: i,
|
|
824
823
|
responseBody: l,
|
|
825
824
|
responseHeaders: a,
|
|
826
|
-
status:
|
|
825
|
+
status: d,
|
|
827
826
|
token: Q,
|
|
828
827
|
rawUrl: E
|
|
829
828
|
} = n;
|
|
830
829
|
if (process.env.NODE_ENV !== "development")
|
|
831
830
|
try {
|
|
832
|
-
const
|
|
831
|
+
const p = new URL(E);
|
|
833
832
|
let m = "HTTPS";
|
|
834
|
-
|
|
833
|
+
p.protocol === "http:" && (m = "HTTP");
|
|
835
834
|
const O = JSON.stringify({
|
|
836
|
-
domainUrl:
|
|
837
|
-
pathnameUrl:
|
|
838
|
-
status:
|
|
835
|
+
domainUrl: p.protocol + "//" + p.host,
|
|
836
|
+
pathnameUrl: p.pathname,
|
|
837
|
+
status: d,
|
|
839
838
|
protocol: m,
|
|
840
839
|
method: u,
|
|
841
840
|
trafficUserId: null,
|
|
@@ -860,9 +859,9 @@ async function F(n) {
|
|
|
860
859
|
}
|
|
861
860
|
}
|
|
862
861
|
);
|
|
863
|
-
} catch (
|
|
862
|
+
} catch (p) {
|
|
864
863
|
f({
|
|
865
|
-
debugs: [`Error sending request: ${
|
|
864
|
+
debugs: [`Error sending request: ${p}`],
|
|
866
865
|
name: "ARKYN_LOG_ERROR",
|
|
867
866
|
scheme: "red"
|
|
868
867
|
});
|
|
@@ -888,7 +887,7 @@ async function b(n, t, s = {}, e) {
|
|
|
888
887
|
} catch {
|
|
889
888
|
a = null;
|
|
890
889
|
}
|
|
891
|
-
const
|
|
890
|
+
const d = v.handle({
|
|
892
891
|
elapsedTime: i,
|
|
893
892
|
method: n,
|
|
894
893
|
queryParams: new URL(t).searchParams,
|
|
@@ -899,7 +898,7 @@ async function b(n, t, s = {}, e) {
|
|
|
899
898
|
status: l,
|
|
900
899
|
url: t
|
|
901
900
|
});
|
|
902
|
-
return F(
|
|
901
|
+
return F(d), h.ok ? {
|
|
903
902
|
success: !0,
|
|
904
903
|
status: l,
|
|
905
904
|
message: (a == null ? void 0 : a.message) || o[n],
|
|
@@ -965,7 +964,7 @@ class X {
|
|
|
965
964
|
onDebug(t, s, e) {
|
|
966
965
|
if (this.enableDebug) {
|
|
967
966
|
const o = [];
|
|
968
|
-
o.push(`Base URL: ${this.baseUrl}`), o.push(`Endpoint
|
|
967
|
+
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])}`), f({ debugs: o, name: "ARKYN-API-DEBUG", scheme: "yellow" });
|
|
969
968
|
}
|
|
970
969
|
}
|
|
971
970
|
generateURL(t) {
|
|
@@ -989,7 +988,7 @@ class X {
|
|
|
989
988
|
*/
|
|
990
989
|
async get(t, s) {
|
|
991
990
|
const e = this.generateURL(t), o = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token);
|
|
992
|
-
return this.onDebug(
|
|
991
|
+
return this.onDebug(t, "get", [o]), await _(e, o);
|
|
993
992
|
}
|
|
994
993
|
/**
|
|
995
994
|
* Sends a post request to the specified endpoint.
|
|
@@ -999,7 +998,7 @@ class X {
|
|
|
999
998
|
*/
|
|
1000
999
|
async post(t, s) {
|
|
1001
1000
|
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(
|
|
1001
|
+
return this.onDebug(t, "post", [o, u]), await G(e, o, u);
|
|
1003
1002
|
}
|
|
1004
1003
|
/**
|
|
1005
1004
|
* Sends a put request to the specified endpoint.
|
|
@@ -1019,7 +1018,7 @@ class X {
|
|
|
1019
1018
|
*/
|
|
1020
1019
|
async patch(t, s) {
|
|
1021
1020
|
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(
|
|
1021
|
+
return this.onDebug(t, "patch", [o, u]), await z(e, o, u);
|
|
1023
1022
|
}
|
|
1024
1023
|
/**
|
|
1025
1024
|
* Sends a delete request to the specified endpoint.
|
|
@@ -1029,7 +1028,7 @@ class X {
|
|
|
1029
1028
|
*/
|
|
1030
1029
|
async delete(t, s) {
|
|
1031
1030
|
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(
|
|
1031
|
+
return this.onDebug(t, "delete", [o, u]), await M(e, o, u);
|
|
1033
1032
|
}
|
|
1034
1033
|
}
|
|
1035
1034
|
function Z(n, t) {
|
|
@@ -1062,12 +1061,12 @@ function es(n) {
|
|
|
1062
1061
|
return n.toResponse();
|
|
1063
1062
|
case n instanceof P:
|
|
1064
1063
|
return n.toResponse();
|
|
1064
|
+
case n instanceof L:
|
|
1065
|
+
return n.toResponse();
|
|
1065
1066
|
case n instanceof A:
|
|
1066
1067
|
return n.toResponse();
|
|
1067
1068
|
case n instanceof $:
|
|
1068
1069
|
return n.toResponse();
|
|
1069
|
-
case n instanceof L:
|
|
1070
|
-
return n.toResponse();
|
|
1071
1070
|
}
|
|
1072
1071
|
switch (!0) {
|
|
1073
1072
|
case n instanceof j:
|
|
@@ -1171,15 +1170,15 @@ export {
|
|
|
1171
1170
|
S as DebugService,
|
|
1172
1171
|
D as Forbidden,
|
|
1173
1172
|
H as Found,
|
|
1174
|
-
|
|
1173
|
+
$ as NoContent,
|
|
1175
1174
|
C as NotFound,
|
|
1176
1175
|
B as NotImplemented,
|
|
1177
1176
|
ns as SchemaValidator,
|
|
1178
1177
|
x as ServerError,
|
|
1179
|
-
|
|
1178
|
+
A as Success,
|
|
1180
1179
|
q as Unauthorized,
|
|
1181
1180
|
N as UnprocessableEntity,
|
|
1182
|
-
|
|
1181
|
+
L as Updated,
|
|
1183
1182
|
Z as decodeErrorMessageFromRequest,
|
|
1184
1183
|
ss as decodeRequestBody,
|
|
1185
1184
|
es as errorHandler,
|
package/dist/bundle.umd.cjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
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()}
|
|
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="";n.debugs.forEach(d=>{l+=`${u} ${d.trim()}
|
|
3
2
|
`}),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
3
|
`).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
4
|
`),o.push(`Caller Function: ${l}
|
|
@@ -11,5 +10,5 @@
|
|
|
11
10
|
`),o.push(`Caller Location: ${u}
|
|
12
11
|
`),o.push(`Body: ${JSON.stringify(s,null,2)}
|
|
13
12
|
`),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
|
|
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=
|
|
13
|
+
`),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(`
|
|
14
|
+
`)}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"})});
|
|
@@ -35,7 +35,7 @@ class ApiService {
|
|
|
35
35
|
if (this.enableDebug) {
|
|
36
36
|
const debugs = [];
|
|
37
37
|
debugs.push(`Base URL: ${this.baseUrl}`);
|
|
38
|
-
debugs.push(`Endpoint
|
|
38
|
+
debugs.push(`Endpoint: ${endpoint}`);
|
|
39
39
|
debugs.push(`Method: ${method}`);
|
|
40
40
|
if (data[0])
|
|
41
41
|
debugs.push(`Headers: ${JSON.stringify(data[0])}`);
|
|
@@ -74,7 +74,7 @@ class ApiService {
|
|
|
74
74
|
async get(endpoint, data) {
|
|
75
75
|
const url = this.generateURL(endpoint);
|
|
76
76
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
77
|
-
this.onDebug(
|
|
77
|
+
this.onDebug(endpoint, "get", [headers]);
|
|
78
78
|
return await getRequest(url, headers);
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
@@ -87,7 +87,7 @@ class ApiService {
|
|
|
87
87
|
const url = this.generateURL(endpoint);
|
|
88
88
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
89
89
|
const body = data?.body;
|
|
90
|
-
this.onDebug(
|
|
90
|
+
this.onDebug(endpoint, "post", [headers, body]);
|
|
91
91
|
return await postRequest(url, headers, body);
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
@@ -113,7 +113,7 @@ class ApiService {
|
|
|
113
113
|
const url = this.generateURL(endpoint);
|
|
114
114
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
115
115
|
const body = data?.body;
|
|
116
|
-
this.onDebug(
|
|
116
|
+
this.onDebug(endpoint, "patch", [headers, body]);
|
|
117
117
|
return await patchRequest(url, headers, body);
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
@@ -126,7 +126,7 @@ class ApiService {
|
|
|
126
126
|
const url = this.generateURL(endpoint);
|
|
127
127
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
128
128
|
const body = data?.body;
|
|
129
|
-
this.onDebug(
|
|
129
|
+
this.onDebug(endpoint, "delete", [headers, body]);
|
|
130
130
|
return await deleteRequest(url, headers, body);
|
|
131
131
|
}
|
|
132
132
|
}
|
|
@@ -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 = ``;
|
|
14
14
|
props.debugs.forEach((debug) => {
|
|
15
15
|
consoleData += `${debugName} ${debug.trim()}\n`;
|
|
16
16
|
});
|