@arkyn/server 3.0.1-beta.63 → 3.0.1-beta.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bundle.js
CHANGED
|
@@ -10,9 +10,10 @@ 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
|
n.debugs.forEach((h) => {
|
|
15
|
-
c += `${u} ${h}
|
|
16
|
+
c += `${u} ${h.trim()}
|
|
16
17
|
`;
|
|
17
18
|
}), c += "<------------------->", console.log(c);
|
|
18
19
|
}
|
|
@@ -964,7 +965,7 @@ class X {
|
|
|
964
965
|
onDebug(t, s, e) {
|
|
965
966
|
if (this.enableDebug) {
|
|
966
967
|
const o = [];
|
|
967
|
-
o.push(`Base URL: ${this.baseUrl}`), o.push(`
|
|
968
|
+
o.push(`Base URL: ${this.baseUrl}`), o.push(`Endpoint URL: ${t}`), o.push(`Method: ${s}`), e[0] && o.push(`Headers: ${JSON.stringify(e[0])}`), e[1] && o.push(`Body: ${JSON.stringify(e[1])}`), f({ debugs: o, name: "ARKYN-API-DEBUG", scheme: "yellow" });
|
|
968
969
|
}
|
|
969
970
|
}
|
|
970
971
|
generateURL(t) {
|
|
@@ -981,8 +982,8 @@ class X {
|
|
|
981
982
|
return this.baseToken && (e = { Authorization: `Bearer ${this.baseToken}` }), this.baseHeaders && (e = { ...e, ...this.baseHeaders }), t && (e = { ...e, ...t }), s && (e = { ...e, Authorization: `Bearer ${s}` }), e;
|
|
982
983
|
}
|
|
983
984
|
/**
|
|
984
|
-
* Sends a get request to the specified
|
|
985
|
-
* @param
|
|
985
|
+
* Sends a get request to the specified endpoint.
|
|
986
|
+
* @param endpoint - The API endpoint to send the get request to.
|
|
986
987
|
* @param data - The request data, including optional headers and token.
|
|
987
988
|
* @returns The API response data.
|
|
988
989
|
*/
|
|
@@ -991,8 +992,8 @@ class X {
|
|
|
991
992
|
return this.onDebug(e, "get", [o]), await _(e, o);
|
|
992
993
|
}
|
|
993
994
|
/**
|
|
994
|
-
* Sends a post request to the specified
|
|
995
|
-
* @param
|
|
995
|
+
* Sends a post request to the specified endpoint.
|
|
996
|
+
* @param endpoint - The API endpoint to send the post request to.
|
|
996
997
|
* @param data - The request data, including body, optional headers, and token.
|
|
997
998
|
* @returns The API response data.
|
|
998
999
|
*/
|
|
@@ -1001,18 +1002,18 @@ class X {
|
|
|
1001
1002
|
return this.onDebug(e, "post", [o, u]), await G(e, o, u);
|
|
1002
1003
|
}
|
|
1003
1004
|
/**
|
|
1004
|
-
* Sends a put request to the specified
|
|
1005
|
-
* @param
|
|
1005
|
+
* Sends a put request to the specified endpoint.
|
|
1006
|
+
* @param endpoint - The API endpoint to send the put request to.
|
|
1006
1007
|
* @param data - The request data, including body, optional headers, and token.
|
|
1007
1008
|
* @returns The API response data.
|
|
1008
1009
|
*/
|
|
1009
1010
|
async put(t, s) {
|
|
1010
1011
|
const e = this.generateURL(t), o = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
|
|
1011
|
-
return this.onDebug(
|
|
1012
|
+
return this.onDebug(t, "put", [o, u]), await K(e, o, u);
|
|
1012
1013
|
}
|
|
1013
1014
|
/**
|
|
1014
|
-
* Sends a patch request to the specified
|
|
1015
|
-
* @param
|
|
1015
|
+
* Sends a patch request to the specified endpoint.
|
|
1016
|
+
* @param endpoint - The API endpoint to send the patch request to.
|
|
1016
1017
|
* @param data - The request data, including body, optional headers, and token.
|
|
1017
1018
|
* @returns The API response data.
|
|
1018
1019
|
*/
|
|
@@ -1021,8 +1022,8 @@ class X {
|
|
|
1021
1022
|
return this.onDebug(e, "patch", [o, u]), await z(e, o, u);
|
|
1022
1023
|
}
|
|
1023
1024
|
/**
|
|
1024
|
-
* Sends a delete request to the specified
|
|
1025
|
-
* @param
|
|
1025
|
+
* Sends a delete request to the specified endpoint.
|
|
1026
|
+
* @param endpoint - The API endpoint to send the delete request to.
|
|
1026
1027
|
* @param data - The request data, including body, optional headers, and token.
|
|
1027
1028
|
* @returns The API response data.
|
|
1028
1029
|
*/
|
package/dist/bundle.umd.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
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
|
|
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()}
|
|
2
3
|
`}),l+="<------------------->",console.log(l)}}const b={};class N{static setIgnoreFile(t){this.ignoreFiles.push(t)}static clearIgnoreFiles(){this.ignoreFiles=[]}}r(N,"ignoreFiles",[]);function R(){const n=process.cwd(),e=(new Error().stack||"").split(`
|
|
3
4
|
`).map(i=>i.trim()),o=N.ignoreFiles;let u=2;for(;u<e.length&&(e[u].includes("node:internal")||e[u].includes("/node_modules/"));)u++;if(o.length>0)for(;u<e.length&&o.some(i=>e[u].includes(i));)u++;const l=e[u]||"";let d="Unknown function",h="Unknown caller";const f=l.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);if(f)d=f[1],h=f[2];else{const i=l.match(/at\s+(.+)/);if(i){h=i[1];const p=h.match(/at\s+([^(\s]+)\s+/);p&&p[1]!=="new"&&(d=p[1])}}h.includes("(")&&(h=h.substring(h.indexOf("(")+1,h.lastIndexOf(")"))),h=h.split(":").slice(0,-2).join(":");try{h=b.relative(n,h)}catch{}return{functionName:d,callerInfo:h}}class y{onDebug(t,s,e){const o=[],{callerInfo:u,functionName:l}=R();o.push(`${t} initialized
|
|
4
5
|
`),o.push(`Caller Function: ${l}
|
|
@@ -10,5 +11,5 @@
|
|
|
10
11
|
`),o.push(`Caller Location: ${u}
|
|
11
12
|
`),o.push(`Body: ${JSON.stringify(s,null,2)}
|
|
12
13
|
`),e&&o.push(`Cause: ${JSON.stringify(e,null,2)}
|
|
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 A{static mapHeaders(t){return t instanceof Headers?Object.fromEntries(t.entries()):typeof t=="object"?Object.entries(t).reduce((s,[e,o])=>(typeof o=="string"?s[e]=o:Array.isArray(o)?s[e]=o.join(", "):s[e]=JSON.stringify(o),s),{}):{}}static mapQueryParams(t){const s={};return t.forEach((e,o)=>{s[o]=e}),s}static handle(t){return{rawUrl:t.url,status:t.status,method:t.method,token:null,elapsedTime:t.elapsedTime,requestHeaders:this.mapHeaders(t.requestHeaders),requestBody:t.requestBody||null,queryParams:this.mapQueryParams(t.queryParams),responseHeaders:this.mapHeaders(t.responseHeaders),responseBody:t.responseBody||null}}}class E{static setArkynConfig(t){if(this.arkynConfig)return;let e=t.arkynLogBaseApiUrl||"https://logs-arkyn-flow-logs.vw6wo7.easypanel.host";e=e+"/http-traffic-records/:trafficSourceId",this.arkynConfig={arkynTrafficSourceId:t.arkynTrafficSourceId,arkynUserToken:t.arkynUserToken,arkynApiUrl:e}}static getArkynConfig(){return this.arkynConfig}static resetArkynConfig(){this.arkynConfig=void 0}}r(E,"arkynConfig");async function H(n){const t=E.getArkynConfig();if(!t)return;const{arkynUserToken:s,arkynApiUrl:e}=t,{elapsedTime:o,method:u,queryParams:l,requestBody:d,requestHeaders:h,responseBody:f,responseHeaders:i,status:p,token:ns,rawUrl:Z}=n;if(process.env.NODE_ENV!=="development")try{const g=new URL(Z);let v="HTTPS";g.protocol==="http:"&&(v="HTTP");const ss=JSON.stringify({domainUrl:g.protocol+"//"+g.host,pathnameUrl:g.pathname,status:p,protocol:v,method:u,trafficUserId:null,elapsedTime:o,requestHeaders:h,requestBody:d,queryParams:l,responseHeaders:i,responseBody:f});await fetch(e.replace(":trafficSourceId",t.arkynTrafficSourceId),{method:"POST",body:ss,headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`}})}catch(g){c({debugs:[`Error sending request: ${g}`],name:"ARKYN_LOG_ERROR",scheme:"red"})}}async function m(n,t,s={},e){const o={POST:"Resource created successfully",PUT:"Resource updated successfully",DELETE:"Resource deleted successfully",PATCH:"Resource patched successfully",GET:"Request successful"};try{const u=performance.now(),l={...s,"Content-Type":"application/json"},d=await fetch(t,{method:n,headers:l,body:e?JSON.stringify(e):void 0}),h=performance.now()-u,f=d.status;let i=null;try{i=await d.json()}catch{i=null}const p=A.handle({elapsedTime:h,method:n,queryParams:new URL(t).searchParams,requestHeaders:l,requestBody:e,responseBody:i,responseHeaders:d.headers,status:f,url:t});return H(p),d.ok?{success:!0,status:f,message:(i==null?void 0:i.message)||o[n],response:i,cause:null}:{success:!1,status:f,message:(i==null?void 0:i.message)||d.statusText||"Request failed",response:i,cause:null}}catch(u){return c({debugs:[`Network error or request failed: ${u}`],name:"ARKYN_MAKE_REQUEST_ERROR",scheme:"red"}),{success:!1,status:0,message:"Network error or request failed",response:null,cause:u instanceof Error?u.message:String(u)}}}async function $(n,t={},s){return m("DELETE",n,t,s)}async function F(n,t={}){return m("GET",n,t)}async function M(n,t={},s){return m("PATCH",n,t,s)}async function _(n,t={},s){return m("POST",n,t,s)}async function z(n,t={},s){return m("PUT",n,t,s)}class G{constructor(t){r(this,"baseUrl");r(this,"baseHeaders");r(this,"baseToken");r(this,"enableDebug");this.baseUrl=t.baseUrl,this.baseHeaders=t.baseHeaders||void 0,this.baseToken=t.baseToken||void 0,this.enableDebug=t.enableDebug||!1}onDebug(t,s,e){if(this.enableDebug){const o=[];o.push(`Base URL: ${this.baseUrl}`),o.push(`
|
|
14
|
+
`),c({scheme:"green",name:"ARKYN-SUCCESS-RESPONSE-DEBUG",debugs:o})}}class J extends T{constructor(s,e){super();r(this,"body");r(this,"headers");r(this,"status");r(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||201,this.statusText=(e==null?void 0:e.statusText)||"Resource created successfully",this.onDebug("Created",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class D extends T{constructor(s,e){super();r(this,"body");r(this,"headers");r(this,"status");r(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||302,this.statusText=(e==null?void 0:e.statusText)||"Found",this.onDebug("Found",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class B extends T{constructor(s){super();r(this,"headers");r(this,"status");r(this,"statusText");this.headers=(s==null?void 0:s.headers)||{},this.status=(s==null?void 0:s.status)||204,this.statusText=(s==null?void 0:s.statusText)??"No content",this.onDebug("No content",null)}toResponse(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return new Response(null,s)}}class q extends T{constructor(s,e){super();r(this,"body");r(this,"headers");r(this,"status");r(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||200,this.statusText=(e==null?void 0:e.statusText)??"OK",this.onDebug("Success",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class P extends T{constructor(s,e){super();r(this,"body");r(this,"headers");r(this,"status");r(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||200,this.statusText=(e==null?void 0:e.statusText)||"Resource updated successfully",this.onDebug("Updated",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class A{static mapHeaders(t){return t instanceof Headers?Object.fromEntries(t.entries()):typeof t=="object"?Object.entries(t).reduce((s,[e,o])=>(typeof o=="string"?s[e]=o:Array.isArray(o)?s[e]=o.join(", "):s[e]=JSON.stringify(o),s),{}):{}}static mapQueryParams(t){const s={};return t.forEach((e,o)=>{s[o]=e}),s}static handle(t){return{rawUrl:t.url,status:t.status,method:t.method,token:null,elapsedTime:t.elapsedTime,requestHeaders:this.mapHeaders(t.requestHeaders),requestBody:t.requestBody||null,queryParams:this.mapQueryParams(t.queryParams),responseHeaders:this.mapHeaders(t.responseHeaders),responseBody:t.responseBody||null}}}class E{static setArkynConfig(t){if(this.arkynConfig)return;let e=t.arkynLogBaseApiUrl||"https://logs-arkyn-flow-logs.vw6wo7.easypanel.host";e=e+"/http-traffic-records/:trafficSourceId",this.arkynConfig={arkynTrafficSourceId:t.arkynTrafficSourceId,arkynUserToken:t.arkynUserToken,arkynApiUrl:e}}static getArkynConfig(){return this.arkynConfig}static resetArkynConfig(){this.arkynConfig=void 0}}r(E,"arkynConfig");async function H(n){const t=E.getArkynConfig();if(!t)return;const{arkynUserToken:s,arkynApiUrl:e}=t,{elapsedTime:o,method:u,queryParams:l,requestBody:d,requestHeaders:h,responseBody:f,responseHeaders:i,status:p,token:ns,rawUrl:Z}=n;if(process.env.NODE_ENV!=="development")try{const g=new URL(Z);let v="HTTPS";g.protocol==="http:"&&(v="HTTP");const ss=JSON.stringify({domainUrl:g.protocol+"//"+g.host,pathnameUrl:g.pathname,status:p,protocol:v,method:u,trafficUserId:null,elapsedTime:o,requestHeaders:h,requestBody:d,queryParams:l,responseHeaders:i,responseBody:f});await fetch(e.replace(":trafficSourceId",t.arkynTrafficSourceId),{method:"POST",body:ss,headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`}})}catch(g){c({debugs:[`Error sending request: ${g}`],name:"ARKYN_LOG_ERROR",scheme:"red"})}}async function m(n,t,s={},e){const o={POST:"Resource created successfully",PUT:"Resource updated successfully",DELETE:"Resource deleted successfully",PATCH:"Resource patched successfully",GET:"Request successful"};try{const u=performance.now(),l={...s,"Content-Type":"application/json"},d=await fetch(t,{method:n,headers:l,body:e?JSON.stringify(e):void 0}),h=performance.now()-u,f=d.status;let i=null;try{i=await d.json()}catch{i=null}const p=A.handle({elapsedTime:h,method:n,queryParams:new URL(t).searchParams,requestHeaders:l,requestBody:e,responseBody:i,responseHeaders:d.headers,status:f,url:t});return H(p),d.ok?{success:!0,status:f,message:(i==null?void 0:i.message)||o[n],response:i,cause:null}:{success:!1,status:f,message:(i==null?void 0:i.message)||d.statusText||"Request failed",response:i,cause:null}}catch(u){return c({debugs:[`Network error or request failed: ${u}`],name:"ARKYN_MAKE_REQUEST_ERROR",scheme:"red"}),{success:!1,status:0,message:"Network error or request failed",response:null,cause:u instanceof Error?u.message:String(u)}}}async function $(n,t={},s){return m("DELETE",n,t,s)}async function F(n,t={}){return m("GET",n,t)}async function M(n,t={},s){return m("PATCH",n,t,s)}async function _(n,t={},s){return m("POST",n,t,s)}async function z(n,t={},s){return m("PUT",n,t,s)}class G{constructor(t){r(this,"baseUrl");r(this,"baseHeaders");r(this,"baseToken");r(this,"enableDebug");this.baseUrl=t.baseUrl,this.baseHeaders=t.baseHeaders||void 0,this.baseToken=t.baseToken||void 0,this.enableDebug=t.enableDebug||!1}onDebug(t,s,e){if(this.enableDebug){const o=[];o.push(`Base URL: ${this.baseUrl}`),o.push(`Endpoint URL: ${t}`),o.push(`Method: ${s}`),e[0]&&o.push(`Headers: ${JSON.stringify(e[0])}`),e[1]&&o.push(`Body: ${JSON.stringify(e[1])}`),c({debugs:o,name:"ARKYN-API-DEBUG",scheme:"yellow"})}}generateURL(t){return this.baseUrl+t}generateHeaders(t,s){let e={};return this.baseToken&&(e={Authorization:`Bearer ${this.baseToken}`}),this.baseHeaders&&(e={...e,...this.baseHeaders}),t&&(e={...e,...t}),s&&(e={...e,Authorization:`Bearer ${s}`}),e}async get(t,s){const e=this.generateURL(t),o=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token);return this.onDebug(e,"get",[o]),await F(e,o)}async post(t,s){const e=this.generateURL(t),o=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(e,"post",[o,u]),await _(e,o,u)}async put(t,s){const e=this.generateURL(t),o=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(t,"put",[o,u]),await z(e,o,u)}async patch(t,s){const e=this.generateURL(t),o=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(e,"patch",[o,u]),await M(e,o,u)}async delete(t,s){const e=this.generateURL(t),o=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(e,"delete",[o,u]),await $(e,o,u)}}function K(n,t){var s,e,o;return n!=null&&n.message&&typeof(n==null?void 0:n.message)=="string"?n==null?void 0:n.message:n!=null&&n.error&&typeof(n==null?void 0:n.error)=="string"?n==null?void 0:n.error:(s=n==null?void 0:n.error)!=null&&s.message&&typeof((e=n==null?void 0:n.error)==null?void 0:e.message)=="string"?(o=n==null?void 0:n.error)==null?void 0:o.message:t!=null&&t.statusText&&typeof(t==null?void 0:t.statusText)=="string"?t==null?void 0:t.statusText:"Missing error message"}const V=async n=>{let t;const s=await n.arrayBuffer(),e=new TextDecoder().decode(s);try{t=JSON.parse(e)}catch{try{if(e.includes("=")){const u=new URLSearchParams(e);t=Object.fromEntries(u.entries())}else throw new x("Invalid URLSearchParams format")}catch{throw new x("Failed to extract data from request")}}return t};function Y(n){switch(!0){case n instanceof Response:return n;case n instanceof D:return n.toResponse();case n instanceof J:return n.toResponse();case n instanceof P:return n.toResponse();case n instanceof q:return n.toResponse();case n instanceof B:return n.toResponse()}switch(!0){case n instanceof O:return n.toResponse();case n instanceof x:return n.toResponse();case n instanceof U:return n.toResponse();case n instanceof I:return n.toResponse();case n instanceof k:return n.toResponse();case n instanceof j:return n.toResponse();case n instanceof S:return n.toResponse();case n instanceof C:return n.toResponse();case n instanceof w:return n.toResponse()}return new S("Server error",n).toResponse()}function L([n,t]){const s=t.safeParse(n);if(s.success===!1){const e=Object.fromEntries(s.error.issues.map(o=>[o.path.join("."),o.message]));return{success:s.success,fieldErrors:e,fields:n}}else return{success:s.success,data:s.data}}const Q=(n,t="")=>{const s=new URL(n.url);if(t==="")return s.searchParams;const e=Array.from(s.searchParams.entries()).filter(([o])=>o.startsWith(`${t}:`)).map(([o,u])=>[o.replace(`${t}:`,""),u]);return new URLSearchParams(e)};function W(n){const t="Error validating:",s=n.issues.map(({path:e,message:o})=>`-> ${e.join(".")}: ${o}`);return[t,...s].join(`
|
|
14
15
|
`)}class X{constructor(t){r(this,"functionName");r(this,"callerInfo");this.schema=t;const{callerInfo:s,functionName:e}=R();this.callerInfo=s,this.functionName=e}isValid(t){return this.schema.safeParse(t).success}safeValidate(t){return this.schema.safeParse(t)}validate(t){try{return this.schema.parse(t)}catch(s){throw new S(W(s))}}formValidate(t,s){const e=L([t,this.schema]);if(!e.success){const o=Object.keys(e.fieldErrors)[0];throw new w({fields:e.fields,fieldErrors:e.fieldErrors,data:{scrollTo:o},message:s})}return e.data}}a.ApiService=G,a.ArkynLogService=E,a.BadGateway=O,a.BadRequest=x,a.Conflict=U,a.Created=J,a.DebugService=N,a.Forbidden=I,a.Found=D,a.NoContent=B,a.NotFound=k,a.NotImplemented=j,a.SchemaValidator=X,a.ServerError=S,a.Success=q,a.Unauthorized=C,a.UnprocessableEntity=w,a.Updated=P,a.decodeErrorMessageFromRequest=K,a.decodeRequestBody=V,a.errorHandler=Y,a.flushDebugLogs=c,a.formParse=L,a.getCaller=R,a.getScopedParams=Q,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -45,40 +45,40 @@ declare class ApiService {
|
|
|
45
45
|
*/
|
|
46
46
|
private generateHeaders;
|
|
47
47
|
/**
|
|
48
|
-
* Sends a get request to the specified
|
|
49
|
-
* @param
|
|
48
|
+
* Sends a get request to the specified endpoint.
|
|
49
|
+
* @param endpoint - The API endpoint to send the get request to.
|
|
50
50
|
* @param data - The request data, including optional headers and token.
|
|
51
51
|
* @returns The API response data.
|
|
52
52
|
*/
|
|
53
|
-
get(
|
|
53
|
+
get(endpoint: string, data?: ApiRequestDataWithoutBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
|
|
54
54
|
/**
|
|
55
|
-
* Sends a post request to the specified
|
|
56
|
-
* @param
|
|
55
|
+
* Sends a post request to the specified endpoint.
|
|
56
|
+
* @param endpoint - The API endpoint to send the post request to.
|
|
57
57
|
* @param data - The request data, including body, optional headers, and token.
|
|
58
58
|
* @returns The API response data.
|
|
59
59
|
*/
|
|
60
|
-
post(
|
|
60
|
+
post(endpoint: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
|
|
61
61
|
/**
|
|
62
|
-
* Sends a put request to the specified
|
|
63
|
-
* @param
|
|
62
|
+
* Sends a put request to the specified endpoint.
|
|
63
|
+
* @param endpoint - The API endpoint to send the put request to.
|
|
64
64
|
* @param data - The request data, including body, optional headers, and token.
|
|
65
65
|
* @returns The API response data.
|
|
66
66
|
*/
|
|
67
|
-
put(
|
|
67
|
+
put(endpoint: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
|
|
68
68
|
/**
|
|
69
|
-
* Sends a patch request to the specified
|
|
70
|
-
* @param
|
|
69
|
+
* Sends a patch request to the specified endpoint.
|
|
70
|
+
* @param endpoint - The API endpoint to send the patch request to.
|
|
71
71
|
* @param data - The request data, including body, optional headers, and token.
|
|
72
72
|
* @returns The API response data.
|
|
73
73
|
*/
|
|
74
|
-
patch(
|
|
74
|
+
patch(endpoint: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
|
|
75
75
|
/**
|
|
76
|
-
* Sends a delete request to the specified
|
|
77
|
-
* @param
|
|
76
|
+
* Sends a delete request to the specified endpoint.
|
|
77
|
+
* @param endpoint - The API endpoint to send the delete request to.
|
|
78
78
|
* @param data - The request data, including body, optional headers, and token.
|
|
79
79
|
* @returns The API response data.
|
|
80
80
|
*/
|
|
81
|
-
delete(
|
|
81
|
+
delete(endpoint: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
|
|
82
82
|
}
|
|
83
83
|
export { ApiService };
|
|
84
84
|
//# sourceMappingURL=apiService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiService.d.ts","sourceRoot":"","sources":["../../src/services/apiService.ts"],"names":[],"mappings":"AAOA,KAAK,0BAA0B,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,KAAK,8BAA8B,GAAG;IACpC,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,2BAA2B,GAAG;IACjC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AAEH,cAAM,UAAU;IACd,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAC,CAAc;IAClC,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,WAAW,CAAC,CAAU;IAE9B;;;;;;;OAOG;gBAES,KAAK,EAAE,0BAA0B;IAO7C;;;;OAIG;IAEH,OAAO,CAAC,OAAO;IAcf,OAAO,CAAC,WAAW;IAInB;;;;;OAKG;IAEH,OAAO,CAAC,eAAe;IAcvB;;;;;OAKG;IAEG,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"apiService.d.ts","sourceRoot":"","sources":["../../src/services/apiService.ts"],"names":[],"mappings":"AAOA,KAAK,0BAA0B,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,KAAK,8BAA8B,GAAG;IACpC,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,2BAA2B,GAAG;IACjC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AAEH,cAAM,UAAU;IACd,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAC,CAAc;IAClC,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,WAAW,CAAC,CAAU;IAE9B;;;;;;;OAOG;gBAES,KAAK,EAAE,0BAA0B;IAO7C;;;;OAIG;IAEH,OAAO,CAAC,OAAO;IAcf,OAAO,CAAC,WAAW;IAInB;;;;;OAKG;IAEH,OAAO,CAAC,eAAe;IAcvB;;;;;OAKG;IAEG,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,8BAA8B;IAQjE;;;;;OAKG;IAEG,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAS/D;;;;;OAKG;IAEG,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAS9D;;;;;OAKG;IAEG,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAShE;;;;;OAKG;IAEG,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;CAQlE;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -31,11 +31,11 @@ class ApiService {
|
|
|
31
31
|
* @param route - The route to append to the base URL.
|
|
32
32
|
* @returns The full URL as a string.
|
|
33
33
|
*/
|
|
34
|
-
onDebug(
|
|
34
|
+
onDebug(endpoint, method, data) {
|
|
35
35
|
if (this.enableDebug) {
|
|
36
36
|
const debugs = [];
|
|
37
37
|
debugs.push(`Base URL: ${this.baseUrl}`);
|
|
38
|
-
debugs.push(`
|
|
38
|
+
debugs.push(`Endpoint URL: ${endpoint}`);
|
|
39
39
|
debugs.push(`Method: ${method}`);
|
|
40
40
|
if (data[0])
|
|
41
41
|
debugs.push(`Headers: ${JSON.stringify(data[0])}`);
|
|
@@ -66,64 +66,64 @@ class ApiService {
|
|
|
66
66
|
return headers;
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
|
-
* Sends a get request to the specified
|
|
70
|
-
* @param
|
|
69
|
+
* Sends a get request to the specified endpoint.
|
|
70
|
+
* @param endpoint - The API endpoint to send the get request to.
|
|
71
71
|
* @param data - The request data, including optional headers and token.
|
|
72
72
|
* @returns The API response data.
|
|
73
73
|
*/
|
|
74
|
-
async get(
|
|
75
|
-
const url = this.generateURL(
|
|
74
|
+
async get(endpoint, data) {
|
|
75
|
+
const url = this.generateURL(endpoint);
|
|
76
76
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
77
77
|
this.onDebug(url, "get", [headers]);
|
|
78
78
|
return await getRequest(url, headers);
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
|
-
* Sends a post request to the specified
|
|
82
|
-
* @param
|
|
81
|
+
* Sends a post request to the specified endpoint.
|
|
82
|
+
* @param endpoint - The API endpoint to send the post request to.
|
|
83
83
|
* @param data - The request data, including body, optional headers, and token.
|
|
84
84
|
* @returns The API response data.
|
|
85
85
|
*/
|
|
86
|
-
async post(
|
|
87
|
-
const url = this.generateURL(
|
|
86
|
+
async post(endpoint, data) {
|
|
87
|
+
const url = this.generateURL(endpoint);
|
|
88
88
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
89
89
|
const body = data?.body;
|
|
90
90
|
this.onDebug(url, "post", [headers, body]);
|
|
91
91
|
return await postRequest(url, headers, body);
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
|
-
* Sends a put request to the specified
|
|
95
|
-
* @param
|
|
94
|
+
* Sends a put request to the specified endpoint.
|
|
95
|
+
* @param endpoint - The API endpoint to send the put request to.
|
|
96
96
|
* @param data - The request data, including body, optional headers, and token.
|
|
97
97
|
* @returns The API response data.
|
|
98
98
|
*/
|
|
99
|
-
async put(
|
|
100
|
-
const url = this.generateURL(
|
|
99
|
+
async put(endpoint, data) {
|
|
100
|
+
const url = this.generateURL(endpoint);
|
|
101
101
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
102
102
|
const body = data?.body;
|
|
103
|
-
this.onDebug(
|
|
103
|
+
this.onDebug(endpoint, "put", [headers, body]);
|
|
104
104
|
return await putRequest(url, headers, body);
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
|
-
* Sends a patch request to the specified
|
|
108
|
-
* @param
|
|
107
|
+
* Sends a patch request to the specified endpoint.
|
|
108
|
+
* @param endpoint - The API endpoint to send the patch request to.
|
|
109
109
|
* @param data - The request data, including body, optional headers, and token.
|
|
110
110
|
* @returns The API response data.
|
|
111
111
|
*/
|
|
112
|
-
async patch(
|
|
113
|
-
const url = this.generateURL(
|
|
112
|
+
async patch(endpoint, data) {
|
|
113
|
+
const url = this.generateURL(endpoint);
|
|
114
114
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
115
115
|
const body = data?.body;
|
|
116
116
|
this.onDebug(url, "patch", [headers, body]);
|
|
117
117
|
return await patchRequest(url, headers, body);
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
120
|
-
* Sends a delete request to the specified
|
|
121
|
-
* @param
|
|
120
|
+
* Sends a delete request to the specified endpoint.
|
|
121
|
+
* @param endpoint - The API endpoint to send the delete request to.
|
|
122
122
|
* @param data - The request data, including body, optional headers, and token.
|
|
123
123
|
* @returns The API response data.
|
|
124
124
|
*/
|
|
125
|
-
async delete(
|
|
126
|
-
const url = this.generateURL(
|
|
125
|
+
async delete(endpoint, data) {
|
|
126
|
+
const url = this.generateURL(endpoint);
|
|
127
127
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
128
128
|
const body = data?.body;
|
|
129
129
|
this.onDebug(url, "delete", [headers, body]);
|
|
@@ -10,9 +10,9 @@ function flushDebugLogs(props) {
|
|
|
10
10
|
green: "\x1b[32m",
|
|
11
11
|
};
|
|
12
12
|
const debugName = `${colors[props.scheme]}[${props.name}]${reset}`;
|
|
13
|
-
let consoleData =
|
|
13
|
+
let consoleData = `<------------------->\n`;
|
|
14
14
|
props.debugs.forEach((debug) => {
|
|
15
|
-
consoleData += `${debugName} ${debug}\n`;
|
|
15
|
+
consoleData += `${debugName} ${debug.trim()}\n`;
|
|
16
16
|
});
|
|
17
17
|
consoleData += `<------------------->`;
|
|
18
18
|
console.log(consoleData);
|