@arkyn/server 3.0.1-beta.63 → 3.0.1-beta.65

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
  }
@@ -78,8 +79,8 @@ function R() {
78
79
  const a = c.match(/at\s+(.+)/);
79
80
  if (a) {
80
81
  i = a[1];
81
- const p = i.match(/at\s+([^(\s]+)\s+/);
82
- p && p[1] !== "new" && (h = p[1]);
82
+ const d = i.match(/at\s+([^(\s]+)\s+/);
83
+ d && d[1] !== "new" && (h = d[1]);
83
84
  }
84
85
  }
85
86
  i.includes("(") && (i = i.substring(
@@ -92,7 +93,7 @@ function R() {
92
93
  }
93
94
  return { functionName: h, callerInfo: i };
94
95
  }
95
- class d {
96
+ class y {
96
97
  /**
97
98
  * Logs debug information for bad responses including caller context and response details.
98
99
  *
@@ -116,7 +117,7 @@ class d {
116
117
  `), f({ scheme: "red", name: "ARKYN-BAD-RESPONSE-DEBUG", debugs: o });
117
118
  }
118
119
  }
119
- class j extends d {
120
+ class j extends y {
120
121
  /**
121
122
  * Creates an instance of the `BadGateway` class.
122
123
  *
@@ -159,7 +160,7 @@ class j extends d {
159
160
  return Response.json(this.body, s);
160
161
  }
161
162
  }
162
- class g extends d {
163
+ class g extends y {
163
164
  /**
164
165
  * Creates an instance of the `BadRequest` class.
165
166
  *
@@ -202,7 +203,7 @@ class g extends d {
202
203
  return Response.json(this.body, s);
203
204
  }
204
205
  }
205
- class J extends d {
206
+ class J extends y {
206
207
  /**
207
208
  * Creates an instance of the `Conflict` class.
208
209
  *
@@ -245,7 +246,7 @@ class J extends d {
245
246
  return Response.json(this.body, s);
246
247
  }
247
248
  }
248
- class D extends d {
249
+ class D extends y {
249
250
  /**
250
251
  * Creates an instance of the `Forbidden` class.
251
252
  *
@@ -288,7 +289,7 @@ class D extends d {
288
289
  return Response.json(this.body, s);
289
290
  }
290
291
  }
291
- class C extends d {
292
+ class C extends y {
292
293
  /**
293
294
  * Creates an instance of the `NotFound` class.
294
295
  *
@@ -331,7 +332,7 @@ class C extends d {
331
332
  return Response.json(this.body, s);
332
333
  }
333
334
  }
334
- class B extends d {
335
+ class B extends y {
335
336
  /**
336
337
  * Creates an instance of the `NotImplemented` class.
337
338
  *
@@ -374,7 +375,7 @@ class B extends d {
374
375
  return Response.json(this.body, s);
375
376
  }
376
377
  }
377
- class x extends d {
378
+ class x extends y {
378
379
  /**
379
380
  * Creates an instance of the `ServerError` class.
380
381
  *
@@ -417,7 +418,7 @@ class x extends d {
417
418
  return Response.json(this.body, s);
418
419
  }
419
420
  }
420
- class q extends d {
421
+ class q extends y {
421
422
  /**
422
423
  * Creates an instance of the `Unauthorized` class.
423
424
  *
@@ -460,7 +461,7 @@ class q extends d {
460
461
  return Response.json(this.body, s);
461
462
  }
462
463
  }
463
- class N extends d {
464
+ class N extends y {
464
465
  /**
465
466
  * Creates an instance of the `UnprocessableEntity` class.
466
467
  *
@@ -631,7 +632,7 @@ class H extends T {
631
632
  return Response.json(this.body, s);
632
633
  }
633
634
  }
634
- class L extends T {
635
+ class $ extends T {
635
636
  /**
636
637
  * Creates an instance of the `NoContent` class.
637
638
  *
@@ -659,7 +660,7 @@ class L extends T {
659
660
  return new Response(null, s);
660
661
  }
661
662
  }
662
- class $ extends T {
663
+ class A extends T {
663
664
  /**
664
665
  * Creates an instance of the `Success` class.
665
666
  *
@@ -703,7 +704,7 @@ class $ extends T {
703
704
  return Response.json(this.body, s);
704
705
  }
705
706
  }
706
- class A extends T {
707
+ class L extends T {
707
708
  /**
708
709
  * Creates an instance of the `Updated` class.
709
710
  *
@@ -822,19 +823,19 @@ async function F(n) {
822
823
  requestHeaders: i,
823
824
  responseBody: l,
824
825
  responseHeaders: a,
825
- status: p,
826
+ status: d,
826
827
  token: Q,
827
828
  rawUrl: E
828
829
  } = n;
829
830
  if (process.env.NODE_ENV !== "development")
830
831
  try {
831
- const y = new URL(E);
832
+ const p = new URL(E);
832
833
  let m = "HTTPS";
833
- y.protocol === "http:" && (m = "HTTP");
834
+ p.protocol === "http:" && (m = "HTTP");
834
835
  const O = JSON.stringify({
835
- domainUrl: y.protocol + "//" + y.host,
836
- pathnameUrl: y.pathname,
837
- status: p,
836
+ domainUrl: p.protocol + "//" + p.host,
837
+ pathnameUrl: p.pathname,
838
+ status: d,
838
839
  protocol: m,
839
840
  method: u,
840
841
  trafficUserId: null,
@@ -859,9 +860,9 @@ async function F(n) {
859
860
  }
860
861
  }
861
862
  );
862
- } catch (y) {
863
+ } catch (p) {
863
864
  f({
864
- debugs: [`Error sending request: ${y}`],
865
+ debugs: [`Error sending request: ${p}`],
865
866
  name: "ARKYN_LOG_ERROR",
866
867
  scheme: "red"
867
868
  });
@@ -887,7 +888,7 @@ async function b(n, t, s = {}, e) {
887
888
  } catch {
888
889
  a = null;
889
890
  }
890
- const p = v.handle({
891
+ const d = v.handle({
891
892
  elapsedTime: i,
892
893
  method: n,
893
894
  queryParams: new URL(t).searchParams,
@@ -898,7 +899,7 @@ async function b(n, t, s = {}, e) {
898
899
  status: l,
899
900
  url: t
900
901
  });
901
- return F(p), h.ok ? {
902
+ return F(d), h.ok ? {
902
903
  success: !0,
903
904
  status: l,
904
905
  message: (a == null ? void 0 : a.message) || o[n],
@@ -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(`Full 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
+ 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" });
968
969
  }
969
970
  }
970
971
  generateURL(t) {
@@ -981,54 +982,54 @@ 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 route.
985
- * @param route - The API route to send the get request to.
985
+ * Sends a get request to the specified endpoint.
986
+ * @param endpoint - The API endpoint to send the get request to.
986
987
  * @param data - The request data, including optional headers and token.
987
988
  * @returns The API response data.
988
989
  */
989
990
  async get(t, s) {
990
991
  const e = this.generateURL(t), o = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token);
991
- return this.onDebug(e, "get", [o]), await _(e, o);
992
+ return this.onDebug(t, "get", [o]), await _(e, o);
992
993
  }
993
994
  /**
994
- * Sends a post request to the specified route.
995
- * @param route - The API route to send the post request to.
995
+ * Sends a post request to the specified endpoint.
996
+ * @param endpoint - The API endpoint to send the post request to.
996
997
  * @param data - The request data, including body, optional headers, and token.
997
998
  * @returns The API response data.
998
999
  */
999
1000
  async post(t, s) {
1000
1001
  const e = this.generateURL(t), o = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
1001
- return this.onDebug(e, "post", [o, u]), await G(e, o, u);
1002
+ return this.onDebug(t, "post", [o, u]), await G(e, o, u);
1002
1003
  }
1003
1004
  /**
1004
- * Sends a put request to the specified route.
1005
- * @param route - The API route to send the put request to.
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(e, "put", [o, u]), await K(e, o, u);
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 route.
1015
- * @param route - The API route to send the patch request to.
1015
+ * Sends a patch request to the specified endpoint.
1016
+ * @param endpoint - The API endpoint to send the patch request to.
1016
1017
  * @param data - The request data, including body, optional headers, and token.
1017
1018
  * @returns The API response data.
1018
1019
  */
1019
1020
  async patch(t, s) {
1020
1021
  const e = this.generateURL(t), o = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
1021
- return this.onDebug(e, "patch", [o, u]), await z(e, o, u);
1022
+ return this.onDebug(t, "patch", [o, u]), await z(e, o, u);
1022
1023
  }
1023
1024
  /**
1024
- * Sends a delete request to the specified route.
1025
- * @param route - The API route to send the delete request to.
1025
+ * Sends a delete request to the specified endpoint.
1026
+ * @param endpoint - The API endpoint to send the delete request to.
1026
1027
  * @param data - The request data, including body, optional headers, and token.
1027
1028
  * @returns The API response data.
1028
1029
  */
1029
1030
  async delete(t, s) {
1030
1031
  const e = this.generateURL(t), o = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
1031
- return this.onDebug(e, "delete", [o, u]), await M(e, o, u);
1032
+ return this.onDebug(t, "delete", [o, u]), await M(e, o, u);
1032
1033
  }
1033
1034
  }
1034
1035
  function Z(n, t) {
@@ -1061,12 +1062,12 @@ function es(n) {
1061
1062
  return n.toResponse();
1062
1063
  case n instanceof P:
1063
1064
  return n.toResponse();
1065
+ case n instanceof L:
1066
+ return n.toResponse();
1064
1067
  case n instanceof A:
1065
1068
  return n.toResponse();
1066
1069
  case n instanceof $:
1067
1070
  return n.toResponse();
1068
- case n instanceof L:
1069
- return n.toResponse();
1070
1071
  }
1071
1072
  switch (!0) {
1072
1073
  case n instanceof j:
@@ -1170,15 +1171,15 @@ export {
1170
1171
  S as DebugService,
1171
1172
  D as Forbidden,
1172
1173
  H as Found,
1173
- L as NoContent,
1174
+ $ as NoContent,
1174
1175
  C as NotFound,
1175
1176
  B as NotImplemented,
1176
1177
  ns as SchemaValidator,
1177
1178
  x as ServerError,
1178
- $ as Success,
1179
+ A as Success,
1179
1180
  q as Unauthorized,
1180
1181
  N as UnprocessableEntity,
1181
- A as Updated,
1182
+ L as Updated,
1182
1183
  Z as decodeErrorMessageFromRequest,
1183
1184
  ss as decodeRequestBody,
1184
1185
  es as errorHandler,
@@ -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="<------------------->";n.debugs.forEach(d=>{l+=`${u} ${d}
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(`Full 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(e,"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
- `)}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"})});
14
+ `),c({scheme:"green",name:"ARKYN-SUCCESS-RESPONSE-DEBUG",debugs:o})}}class J extends T{constructor(s,e){super();r(this,"body");r(this,"headers");r(this,"status");r(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||201,this.statusText=(e==null?void 0:e.statusText)||"Resource created successfully",this.onDebug("Created",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class D extends T{constructor(s,e){super();r(this,"body");r(this,"headers");r(this,"status");r(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||302,this.statusText=(e==null?void 0:e.statusText)||"Found",this.onDebug("Found",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class B extends T{constructor(s){super();r(this,"headers");r(this,"status");r(this,"statusText");this.headers=(s==null?void 0:s.headers)||{},this.status=(s==null?void 0:s.status)||204,this.statusText=(s==null?void 0:s.statusText)??"No content",this.onDebug("No content",null)}toResponse(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return new Response(null,s)}}class q extends T{constructor(s,e){super();r(this,"body");r(this,"headers");r(this,"status");r(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||200,this.statusText=(e==null?void 0:e.statusText)??"OK",this.onDebug("Success",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class P extends T{constructor(s,e){super();r(this,"body");r(this,"headers");r(this,"status");r(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||200,this.statusText=(e==null?void 0:e.statusText)||"Resource updated successfully",this.onDebug("Updated",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class H{static mapHeaders(t){return t instanceof Headers?Object.fromEntries(t.entries()):typeof t=="object"?Object.entries(t).reduce((s,[e,o])=>(typeof o=="string"?s[e]=o:Array.isArray(o)?s[e]=o.join(", "):s[e]=JSON.stringify(o),s),{}):{}}static mapQueryParams(t){const s={};return t.forEach((e,o)=>{s[o]=e}),s}static handle(t){return{rawUrl:t.url,status:t.status,method:t.method,token:null,elapsedTime:t.elapsedTime,requestHeaders:this.mapHeaders(t.requestHeaders),requestBody:t.requestBody||null,queryParams:this.mapQueryParams(t.queryParams),responseHeaders:this.mapHeaders(t.responseHeaders),responseBody:t.responseBody||null}}}class E{static setArkynConfig(t){if(this.arkynConfig)return;let e=t.arkynLogBaseApiUrl||"https://logs-arkyn-flow-logs.vw6wo7.easypanel.host";e=e+"/http-traffic-records/:trafficSourceId",this.arkynConfig={arkynTrafficSourceId:t.arkynTrafficSourceId,arkynUserToken:t.arkynUserToken,arkynApiUrl:e}}static getArkynConfig(){return this.arkynConfig}static resetArkynConfig(){this.arkynConfig=void 0}}r(E,"arkynConfig");async function L(n){const t=E.getArkynConfig();if(!t)return;const{arkynUserToken:s,arkynApiUrl:e}=t,{elapsedTime:o,method:u,queryParams:l,requestBody:d,requestHeaders:h,responseBody:f,responseHeaders:i,status:p,token:ns,rawUrl:Z}=n;if(process.env.NODE_ENV!=="development")try{const g=new URL(Z);let A="HTTPS";g.protocol==="http:"&&(A="HTTP");const ss=JSON.stringify({domainUrl:g.protocol+"//"+g.host,pathnameUrl:g.pathname,status:p,protocol:A,method:u,trafficUserId:null,elapsedTime:o,requestHeaders:h,requestBody:d,queryParams:l,responseHeaders:i,responseBody:f});await fetch(e.replace(":trafficSourceId",t.arkynTrafficSourceId),{method:"POST",body:ss,headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`}})}catch(g){c({debugs:[`Error sending request: ${g}`],name:"ARKYN_LOG_ERROR",scheme:"red"})}}async function m(n,t,s={},e){const o={POST:"Resource created successfully",PUT:"Resource updated successfully",DELETE:"Resource deleted successfully",PATCH:"Resource patched successfully",GET:"Request successful"};try{const u=performance.now(),l={...s,"Content-Type":"application/json"},d=await fetch(t,{method:n,headers:l,body:e?JSON.stringify(e):void 0}),h=performance.now()-u,f=d.status;let i=null;try{i=await d.json()}catch{i=null}const p=H.handle({elapsedTime:h,method:n,queryParams:new URL(t).searchParams,requestHeaders:l,requestBody:e,responseBody:i,responseHeaders:d.headers,status:f,url:t});return L(p),d.ok?{success:!0,status:f,message:(i==null?void 0:i.message)||o[n],response:i,cause:null}:{success:!1,status:f,message:(i==null?void 0:i.message)||d.statusText||"Request failed",response:i,cause:null}}catch(u){return c({debugs:[`Network error or request failed: ${u}`],name:"ARKYN_MAKE_REQUEST_ERROR",scheme:"red"}),{success:!1,status:0,message:"Network error or request failed",response:null,cause:u instanceof Error?u.message:String(u)}}}async function $(n,t={},s){return m("DELETE",n,t,s)}async function F(n,t={}){return m("GET",n,t)}async function M(n,t={},s){return m("PATCH",n,t,s)}async function _(n,t={},s){return m("POST",n,t,s)}async function z(n,t={},s){return m("PUT",n,t,s)}class G{constructor(t){r(this,"baseUrl");r(this,"baseHeaders");r(this,"baseToken");r(this,"enableDebug");this.baseUrl=t.baseUrl,this.baseHeaders=t.baseHeaders||void 0,this.baseToken=t.baseToken||void 0,this.enableDebug=t.enableDebug||!1}onDebug(t,s,e){if(this.enableDebug){const o=[];o.push(`Base URL: ${this.baseUrl}`),o.push(`Endpoint: ${t}`),o.push(`Method: ${s}`),e[0]&&o.push(`Headers: ${JSON.stringify(e[0])}`),e[1]&&o.push(`Body: ${JSON.stringify(e[1])}`),c({debugs:o,name:"ARKYN-API-DEBUG",scheme:"yellow"})}}generateURL(t){return this.baseUrl+t}generateHeaders(t,s){let e={};return this.baseToken&&(e={Authorization:`Bearer ${this.baseToken}`}),this.baseHeaders&&(e={...e,...this.baseHeaders}),t&&(e={...e,...t}),s&&(e={...e,Authorization:`Bearer ${s}`}),e}async get(t,s){const e=this.generateURL(t),o=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token);return this.onDebug(t,"get",[o]),await F(e,o)}async post(t,s){const e=this.generateURL(t),o=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(t,"post",[o,u]),await _(e,o,u)}async put(t,s){const e=this.generateURL(t),o=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(t,"put",[o,u]),await z(e,o,u)}async patch(t,s){const e=this.generateURL(t),o=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(t,"patch",[o,u]),await M(e,o,u)}async delete(t,s){const e=this.generateURL(t),o=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(t,"delete",[o,u]),await $(e,o,u)}}function K(n,t){var s,e,o;return n!=null&&n.message&&typeof(n==null?void 0:n.message)=="string"?n==null?void 0:n.message:n!=null&&n.error&&typeof(n==null?void 0:n.error)=="string"?n==null?void 0:n.error:(s=n==null?void 0:n.error)!=null&&s.message&&typeof((e=n==null?void 0:n.error)==null?void 0:e.message)=="string"?(o=n==null?void 0:n.error)==null?void 0:o.message:t!=null&&t.statusText&&typeof(t==null?void 0:t.statusText)=="string"?t==null?void 0:t.statusText:"Missing error message"}const V=async n=>{let t;const s=await n.arrayBuffer(),e=new TextDecoder().decode(s);try{t=JSON.parse(e)}catch{try{if(e.includes("=")){const u=new URLSearchParams(e);t=Object.fromEntries(u.entries())}else throw new x("Invalid URLSearchParams format")}catch{throw new x("Failed to extract data from request")}}return t};function Y(n){switch(!0){case n instanceof Response:return n;case n instanceof D:return n.toResponse();case n instanceof J:return n.toResponse();case n instanceof P:return n.toResponse();case n instanceof q:return n.toResponse();case n instanceof B:return n.toResponse()}switch(!0){case n instanceof O:return n.toResponse();case n instanceof x:return n.toResponse();case n instanceof U:return n.toResponse();case n instanceof I:return n.toResponse();case n instanceof k:return n.toResponse();case n instanceof j:return n.toResponse();case n instanceof S:return n.toResponse();case n instanceof C:return n.toResponse();case n instanceof w:return n.toResponse()}return new S("Server error",n).toResponse()}function v([n,t]){const s=t.safeParse(n);if(s.success===!1){const e=Object.fromEntries(s.error.issues.map(o=>[o.path.join("."),o.message]));return{success:s.success,fieldErrors:e,fields:n}}else return{success:s.success,data:s.data}}const Q=(n,t="")=>{const s=new URL(n.url);if(t==="")return s.searchParams;const e=Array.from(s.searchParams.entries()).filter(([o])=>o.startsWith(`${t}:`)).map(([o,u])=>[o.replace(`${t}:`,""),u]);return new URLSearchParams(e)};function W(n){const t="Error validating:",s=n.issues.map(({path:e,message:o})=>`-> ${e.join(".")}: ${o}`);return[t,...s].join(`
15
+ `)}class X{constructor(t){r(this,"functionName");r(this,"callerInfo");this.schema=t;const{callerInfo:s,functionName:e}=R();this.callerInfo=s,this.functionName=e}isValid(t){return this.schema.safeParse(t).success}safeValidate(t){return this.schema.safeParse(t)}validate(t){try{return this.schema.parse(t)}catch(s){throw new S(W(s))}}formValidate(t,s){const e=v([t,this.schema]);if(!e.success){const o=Object.keys(e.fieldErrors)[0];throw new w({fields:e.fields,fieldErrors:e.fieldErrors,data:{scrollTo:o},message:s})}return e.data}}a.ApiService=G,a.ArkynLogService=E,a.BadGateway=O,a.BadRequest=x,a.Conflict=U,a.Created=J,a.DebugService=N,a.Forbidden=I,a.Found=D,a.NoContent=B,a.NotFound=k,a.NotImplemented=j,a.SchemaValidator=X,a.ServerError=S,a.Success=q,a.Unauthorized=C,a.UnprocessableEntity=w,a.Updated=P,a.decodeErrorMessageFromRequest=K,a.decodeRequestBody=V,a.errorHandler=Y,a.flushDebugLogs=c,a.formParse=v,a.getCaller=R,a.getScopedParams=Q,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
@@ -45,40 +45,40 @@ declare class ApiService {
45
45
  */
46
46
  private generateHeaders;
47
47
  /**
48
- * Sends a get request to the specified route.
49
- * @param route - The API route to send the get request to.
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(route: string, data?: ApiRequestDataWithoutBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
53
+ get(endpoint: string, data?: ApiRequestDataWithoutBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
54
54
  /**
55
- * Sends a post request to the specified route.
56
- * @param route - The API route to send the post request to.
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(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
60
+ post(endpoint: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
61
61
  /**
62
- * Sends a put request to the specified route.
63
- * @param route - The API route to send the put request to.
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(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
67
+ put(endpoint: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
68
68
  /**
69
- * Sends a patch request to the specified route.
70
- * @param route - The API route to send the patch request to.
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(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
74
+ patch(endpoint: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
75
75
  /**
76
- * Sends a delete request to the specified route.
77
- * @param route - The API route to send the delete request to.
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(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
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,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,8BAA8B;IAQ9D;;;;;OAKG;IAEG,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAS5D;;;;;OAKG;IAEG,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAS3D;;;;;OAKG;IAEG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAS7D;;;;;OAKG;IAEG,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;CAQ/D;AAED,OAAO,EAAE,UAAU,EAAE,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(fullRoute, method, data) {
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(`Full URL: ${fullRoute}`);
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])}`);
@@ -66,67 +66,67 @@ class ApiService {
66
66
  return headers;
67
67
  }
68
68
  /**
69
- * Sends a get request to the specified route.
70
- * @param route - The API route to send the get request to.
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(route, data) {
75
- const url = this.generateURL(route);
74
+ async get(endpoint, data) {
75
+ const url = this.generateURL(endpoint);
76
76
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
77
- this.onDebug(url, "get", [headers]);
77
+ this.onDebug(endpoint, "get", [headers]);
78
78
  return await getRequest(url, headers);
79
79
  }
80
80
  /**
81
- * Sends a post request to the specified route.
82
- * @param route - The API route to send the post request to.
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(route, data) {
87
- const url = this.generateURL(route);
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
- this.onDebug(url, "post", [headers, body]);
90
+ this.onDebug(endpoint, "post", [headers, body]);
91
91
  return await postRequest(url, headers, body);
92
92
  }
93
93
  /**
94
- * Sends a put request to the specified route.
95
- * @param route - The API route to send the put request to.
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(route, data) {
100
- const url = this.generateURL(route);
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(url, "put", [headers, body]);
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 route.
108
- * @param route - The API route to send the patch request to.
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(route, data) {
113
- const url = this.generateURL(route);
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
- this.onDebug(url, "patch", [headers, body]);
116
+ this.onDebug(endpoint, "patch", [headers, body]);
117
117
  return await patchRequest(url, headers, body);
118
118
  }
119
119
  /**
120
- * Sends a delete request to the specified route.
121
- * @param route - The API route to send the delete request to.
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(route, data) {
126
- const url = this.generateURL(route);
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
- this.onDebug(url, "delete", [headers, body]);
129
+ this.onDebug(endpoint, "delete", [headers, body]);
130
130
  return await deleteRequest(url, headers, body);
131
131
  }
132
132
  }
@@ -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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkyn/server",
3
- "version": "3.0.1-beta.63",
3
+ "version": "3.0.1-beta.65",
4
4
  "author": "Arkyn | Lucas Gonçalves",
5
5
  "main": "./dist/bundle.js",
6
6
  "module": "./dist/bundle.js",