@arkyn/server 3.0.1-beta.67 → 3.0.1-beta.68
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
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
3
|
var r = (n, t, s) => I(n, typeof t != "symbol" ? t + "" : t, s);
|
|
4
|
-
function
|
|
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()}
|
|
@@ -59,7 +59,7 @@ class S {
|
|
|
59
59
|
* When set, the `getCaller` function will skip stack frames containing this file name.
|
|
60
60
|
*/
|
|
61
61
|
r(S, "ignoreFiles", []);
|
|
62
|
-
function
|
|
62
|
+
function m() {
|
|
63
63
|
const n = process.cwd(), e = (new Error().stack || "").split(`
|
|
64
64
|
`).map((a) => a.trim()), o = S.ignoreFiles;
|
|
65
65
|
let u = 2;
|
|
@@ -108,13 +108,13 @@ class y {
|
|
|
108
108
|
* ```
|
|
109
109
|
*/
|
|
110
110
|
onDebug(t, s, e) {
|
|
111
|
-
const o = [], { callerInfo: u, functionName: c } =
|
|
111
|
+
const o = [], { callerInfo: u, functionName: c } = m();
|
|
112
112
|
o.push(`${t} initialized
|
|
113
113
|
`), o.push(`Caller Function: ${c}
|
|
114
114
|
`), o.push(`Caller Location: ${u}
|
|
115
115
|
`), o.push(`Body: ${JSON.stringify(s, null, 2)}
|
|
116
116
|
`), e && o.push(`Cause: ${JSON.stringify(e, null, 2)}
|
|
117
|
-
`),
|
|
117
|
+
`), p({ scheme: "red", name: "ARKYN-BAD-RESPONSE-DEBUG", debugs: o });
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
class j extends y {
|
|
@@ -160,7 +160,7 @@ class j extends y {
|
|
|
160
160
|
return Response.json(this.body, s);
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
class
|
|
163
|
+
class b extends y {
|
|
164
164
|
/**
|
|
165
165
|
* Creates an instance of the `BadRequest` class.
|
|
166
166
|
*
|
|
@@ -483,7 +483,11 @@ class N extends y {
|
|
|
483
483
|
data: s.data,
|
|
484
484
|
fieldErrors: s.fieldErrors,
|
|
485
485
|
fields: s.fields
|
|
486
|
-
}, this.onDebug(
|
|
486
|
+
}, this.onDebug(
|
|
487
|
+
"UnprocessableEntity",
|
|
488
|
+
s.message || null,
|
|
489
|
+
s.fieldErrors || null
|
|
490
|
+
);
|
|
487
491
|
}
|
|
488
492
|
/**
|
|
489
493
|
* Converts the `UnprocessableEntity` instance into a `Response` object with a JSON body.
|
|
@@ -528,13 +532,13 @@ class T {
|
|
|
528
532
|
* ```
|
|
529
533
|
*/
|
|
530
534
|
onDebug(t, s, e) {
|
|
531
|
-
const o = [], { callerInfo: u, functionName: c } =
|
|
535
|
+
const o = [], { callerInfo: u, functionName: c } = m();
|
|
532
536
|
o.push(`${t} initialized
|
|
533
537
|
`), o.push(`Caller Function: ${c}
|
|
534
538
|
`), o.push(`Caller Location: ${u}
|
|
535
539
|
`), o.push(`Body: ${JSON.stringify(s, null, 2)}
|
|
536
540
|
`), e && o.push(`Cause: ${JSON.stringify(e, null, 2)}
|
|
537
|
-
`),
|
|
541
|
+
`), p({
|
|
538
542
|
scheme: "green",
|
|
539
543
|
name: "ARKYN-SUCCESS-RESPONSE-DEBUG",
|
|
540
544
|
debugs: o
|
|
@@ -829,14 +833,14 @@ async function F(n) {
|
|
|
829
833
|
} = n;
|
|
830
834
|
if (process.env.NODE_ENV !== "development")
|
|
831
835
|
try {
|
|
832
|
-
const
|
|
833
|
-
let
|
|
834
|
-
|
|
836
|
+
const f = new URL(E);
|
|
837
|
+
let R = "HTTPS";
|
|
838
|
+
f.protocol === "http:" && (R = "HTTP");
|
|
835
839
|
const O = JSON.stringify({
|
|
836
|
-
domainUrl:
|
|
837
|
-
pathnameUrl:
|
|
840
|
+
domainUrl: f.protocol + "//" + f.host,
|
|
841
|
+
pathnameUrl: f.pathname,
|
|
838
842
|
status: d,
|
|
839
|
-
protocol:
|
|
843
|
+
protocol: R,
|
|
840
844
|
method: u,
|
|
841
845
|
trafficUserId: null,
|
|
842
846
|
elapsedTime: o,
|
|
@@ -860,15 +864,15 @@ async function F(n) {
|
|
|
860
864
|
}
|
|
861
865
|
}
|
|
862
866
|
);
|
|
863
|
-
} catch (
|
|
864
|
-
|
|
865
|
-
debugs: [`Error sending request: ${
|
|
867
|
+
} catch (f) {
|
|
868
|
+
p({
|
|
869
|
+
debugs: [`Error sending request: ${f}`],
|
|
866
870
|
name: "ARKYN_LOG_ERROR",
|
|
867
871
|
scheme: "red"
|
|
868
872
|
});
|
|
869
873
|
}
|
|
870
874
|
}
|
|
871
|
-
async function
|
|
875
|
+
async function g(n, t, s = {}, e) {
|
|
872
876
|
const o = {
|
|
873
877
|
POST: "Resource created successfully",
|
|
874
878
|
PUT: "Resource updated successfully",
|
|
@@ -913,7 +917,7 @@ async function b(n, t, s = {}, e) {
|
|
|
913
917
|
cause: null
|
|
914
918
|
};
|
|
915
919
|
} catch (u) {
|
|
916
|
-
return
|
|
920
|
+
return p({
|
|
917
921
|
debugs: [`Network error or request failed: ${u}`],
|
|
918
922
|
name: "ARKYN_MAKE_REQUEST_ERROR",
|
|
919
923
|
scheme: "red"
|
|
@@ -927,19 +931,19 @@ async function b(n, t, s = {}, e) {
|
|
|
927
931
|
}
|
|
928
932
|
}
|
|
929
933
|
async function M(n, t = {}, s) {
|
|
930
|
-
return
|
|
934
|
+
return g("DELETE", n, t, s);
|
|
931
935
|
}
|
|
932
936
|
async function _(n, t = {}) {
|
|
933
|
-
return
|
|
937
|
+
return g("GET", n, t);
|
|
934
938
|
}
|
|
935
939
|
async function z(n, t = {}, s) {
|
|
936
|
-
return
|
|
940
|
+
return g("PATCH", n, t, s);
|
|
937
941
|
}
|
|
938
942
|
async function G(n, t = {}, s) {
|
|
939
|
-
return
|
|
943
|
+
return g("POST", n, t, s);
|
|
940
944
|
}
|
|
941
945
|
async function K(n, t = {}, s) {
|
|
942
|
-
return
|
|
946
|
+
return g("PUT", n, t, s);
|
|
943
947
|
}
|
|
944
948
|
class X {
|
|
945
949
|
/**
|
|
@@ -965,7 +969,7 @@ class X {
|
|
|
965
969
|
onDebug(t, s, e) {
|
|
966
970
|
if (this.enableDebug) {
|
|
967
971
|
const o = [];
|
|
968
|
-
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])}`),
|
|
972
|
+
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])}`), p({ debugs: o, name: "ARKYN-API-DEBUG", scheme: "yellow" });
|
|
969
973
|
}
|
|
970
974
|
}
|
|
971
975
|
generateURL(t) {
|
|
@@ -1047,9 +1051,9 @@ const ss = async (n) => {
|
|
|
1047
1051
|
const u = new URLSearchParams(e);
|
|
1048
1052
|
t = Object.fromEntries(u.entries());
|
|
1049
1053
|
} else
|
|
1050
|
-
throw new
|
|
1054
|
+
throw new b("Invalid URLSearchParams format");
|
|
1051
1055
|
} catch {
|
|
1052
|
-
throw new
|
|
1056
|
+
throw new b("Failed to extract data from request");
|
|
1053
1057
|
}
|
|
1054
1058
|
}
|
|
1055
1059
|
return t;
|
|
@@ -1072,7 +1076,7 @@ function es(n) {
|
|
|
1072
1076
|
switch (!0) {
|
|
1073
1077
|
case n instanceof j:
|
|
1074
1078
|
return n.toResponse();
|
|
1075
|
-
case n instanceof
|
|
1079
|
+
case n instanceof b:
|
|
1076
1080
|
return n.toResponse();
|
|
1077
1081
|
case n instanceof J:
|
|
1078
1082
|
return n.toResponse();
|
|
@@ -1131,7 +1135,7 @@ class ns {
|
|
|
1131
1135
|
r(this, "functionName");
|
|
1132
1136
|
r(this, "callerInfo");
|
|
1133
1137
|
this.schema = t;
|
|
1134
|
-
const { callerInfo: s, functionName: e } =
|
|
1138
|
+
const { callerInfo: s, functionName: e } = m();
|
|
1135
1139
|
this.callerInfo = s, this.functionName = e;
|
|
1136
1140
|
}
|
|
1137
1141
|
isValid(t) {
|
|
@@ -1165,7 +1169,7 @@ export {
|
|
|
1165
1169
|
X as ApiService,
|
|
1166
1170
|
w as ArkynLogService,
|
|
1167
1171
|
j as BadGateway,
|
|
1168
|
-
|
|
1172
|
+
b as BadRequest,
|
|
1169
1173
|
J as Conflict,
|
|
1170
1174
|
P as Created,
|
|
1171
1175
|
S as DebugService,
|
|
@@ -1183,8 +1187,8 @@ export {
|
|
|
1183
1187
|
Z as decodeErrorMessageFromRequest,
|
|
1184
1188
|
ss as decodeRequestBody,
|
|
1185
1189
|
es as errorHandler,
|
|
1186
|
-
|
|
1190
|
+
p as flushDebugLogs,
|
|
1187
1191
|
V as formParse,
|
|
1188
|
-
|
|
1192
|
+
m as getCaller,
|
|
1189
1193
|
ts as getScopedParams
|
|
1190
1194
|
};
|
package/dist/bundle.umd.cjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
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,
|
|
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,g)=>c in a?es(a,c,{enumerable:!0,configurable:!0,writable:!0,value:g}):a[c]=g;var r=(a,c,g)=>ts(a,typeof c!="symbol"?c+"":c,g);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
2
|
`;n.debugs.forEach(d=>{l+=`${u} ${d.trim()}
|
|
3
|
-
`}),console.log(l)}}const
|
|
4
|
-
`).map(i=>i.trim()),o=N.ignoreFiles;let u=2;for(;u<e.length&&(e[u].includes("node:internal")||e[u].includes("/node_modules/"));)u++;if(o.length>0)for(;u<e.length&&o.some(i=>e[u].includes(i));)u++;const l=e[u]||"";let d="Unknown function",h="Unknown caller";const
|
|
3
|
+
`}),console.log(l)}}const g={};class N{static setIgnoreFile(t){this.ignoreFiles.push(t)}static clearIgnoreFiles(){this.ignoreFiles=[]}}r(N,"ignoreFiles",[]);function R(){const n=process.cwd(),e=(new Error().stack||"").split(`
|
|
4
|
+
`).map(i=>i.trim()),o=N.ignoreFiles;let u=2;for(;u<e.length&&(e[u].includes("node:internal")||e[u].includes("/node_modules/"));)u++;if(o.length>0)for(;u<e.length&&o.some(i=>e[u].includes(i));)u++;const l=e[u]||"";let d="Unknown function",h="Unknown caller";const y=l.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);if(y)d=y[1],h=y[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=g.relative(n,h)}catch{}return{functionName:d,callerInfo:h}}class f{onDebug(t,s,e){const o=[],{callerInfo:u,functionName:l}=R();o.push(`${t} initialized
|
|
5
5
|
`),o.push(`Caller Function: ${l}
|
|
6
6
|
`),o.push(`Caller Location: ${u}
|
|
7
7
|
`),o.push(`Body: ${JSON.stringify(s,null,2)}
|
|
8
8
|
`),e&&o.push(`Cause: ${JSON.stringify(e,null,2)}
|
|
9
|
-
`),c({scheme:"red",name:"ARKYN-BAD-RESPONSE-DEBUG",debugs:o})}}class O extends
|
|
9
|
+
`),c({scheme:"red",name:"ARKYN-BAD-RESPONSE-DEBUG",debugs:o})}}class O extends f{constructor(s,e){super();r(this,"body");r(this,"cause");r(this,"status",502);r(this,"statusText");this.body={name:"BadGateway",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("BadGateway",this.body,this.cause)}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class x extends f{constructor(s,e){super();r(this,"body");r(this,"cause");r(this,"status",400);r(this,"statusText");this.body={name:"BadRequest",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("BadRequest",this.body,this.cause)}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class U extends f{constructor(s,e){super();r(this,"body");r(this,"cause");r(this,"status",409);r(this,"statusText");this.body={name:"Conflict",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("Conflict",this.body,this.cause)}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class I extends f{constructor(s,e){super();r(this,"body");r(this,"cause");r(this,"status",403);r(this,"statusText");this.body={name:"Forbidden",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("Forbidden",this.body,this.cause)}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class k extends f{constructor(s,e){super();r(this,"body");r(this,"cause");r(this,"status",404);r(this,"statusText");this.body={name:"NotFound",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("NotFound",this.body,this.cause)}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class j extends f{constructor(s,e){super();r(this,"body");r(this,"cause");r(this,"status",501);r(this,"statusText");this.body={name:"NotImplemented",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("NotImplemented",this.body,this.cause)}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class S extends f{constructor(s,e){super();r(this,"body");r(this,"cause");r(this,"status",500);r(this,"statusText");this.body={name:"ServerError",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("ServerError",this.body,this.cause)}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class C extends f{constructor(s,e){super();r(this,"body");r(this,"cause");r(this,"status",401);r(this,"statusText");this.body={name:"Unauthorized",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("Unauthorized",this.body,this.cause)}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class w extends f{constructor(s){super();r(this,"body");r(this,"status",422);r(this,"statusText");this.statusText=s.message||"Unprocessable Entity",this.body={name:"UnprocessableEntity",message:s.message||null,data:s.data,fieldErrors:s.fieldErrors,fields:s.fields},this.onDebug("UnprocessableEntity",s.message||null,s.fieldErrors||null)}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 b{onDebug(t,s,e){const o=[],{callerInfo:u,functionName:l}=R();o.push(`${t} initialized
|
|
10
10
|
`),o.push(`Caller Function: ${l}
|
|
11
11
|
`),o.push(`Caller Location: ${u}
|
|
12
12
|
`),o.push(`Body: ${JSON.stringify(s,null,2)}
|
|
13
13
|
`),e&&o.push(`Cause: ${JSON.stringify(e,null,2)}
|
|
14
|
-
`),c({scheme:"green",name:"ARKYN-SUCCESS-RESPONSE-DEBUG",debugs:o})}}class J extends
|
|
14
|
+
`),c({scheme:"green",name:"ARKYN-SUCCESS-RESPONSE-DEBUG",debugs:o})}}class J extends b{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 b{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 b{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 b{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 b{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:y,responseHeaders:i,status:p,token:ns,rawUrl:Z}=n;if(process.env.NODE_ENV!=="development")try{const T=new URL(Z);let A="HTTPS";T.protocol==="http:"&&(A="HTTP");const ss=JSON.stringify({domainUrl:T.protocol+"//"+T.host,pathnameUrl:T.pathname,status:p,protocol:A,method:u,trafficUserId:null,elapsedTime:o,requestHeaders:h,requestBody:d,queryParams:l,responseHeaders:i,responseBody:y});await fetch(e.replace(":trafficSourceId",t.arkynTrafficSourceId),{method:"POST",body:ss,headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`}})}catch(T){c({debugs:[`Error sending request: ${T}`],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,y=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:y,url:t});return L(p),d.ok?{success:!0,status:y,message:(i==null?void 0:i.message)||o[n],response:i,cause:null}:{success:!1,status:y,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
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 +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,7 @@ class UnprocessableEntity extends BadResponse {
|
|
|
28
28
|
fieldErrors: props.fieldErrors,
|
|
29
29
|
fields: props.fields,
|
|
30
30
|
};
|
|
31
|
-
this.onDebug("UnprocessableEntity",
|
|
31
|
+
this.onDebug("UnprocessableEntity", props.message || null, props.fieldErrors || null);
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* 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
|
});
|