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

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
- var o = (n, t, s) => I(n, typeof t != "symbol" ? t + "" : t, s);
4
- function g(n) {
3
+ var r = (n, t, s) => I(n, typeof t != "symbol" ? t + "" : t, s);
4
+ function f(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,11 +10,11 @@ function g(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
  n.debugs.forEach((h) => {
15
15
  c += `${u} ${h}
16
16
  `;
17
- }), console.log(c);
17
+ }), c += "<------------------->", console.log(c);
18
18
  }
19
19
  }
20
20
  const k = {};
@@ -57,15 +57,15 @@ class S {
57
57
  * The name of the file to ignore when analyzing the stack trace.
58
58
  * When set, the `getCaller` function will skip stack frames containing this file name.
59
59
  */
60
- o(S, "ignoreFiles", []);
60
+ r(S, "ignoreFiles", []);
61
61
  function R() {
62
62
  const n = process.cwd(), e = (new Error().stack || "").split(`
63
- `).map((a) => a.trim()), r = S.ignoreFiles;
63
+ `).map((a) => a.trim()), o = S.ignoreFiles;
64
64
  let u = 2;
65
65
  for (; u < e.length && (e[u].includes("node:internal") || e[u].includes("/node_modules/")); )
66
66
  u++;
67
- if (r.length > 0)
68
- for (; u < e.length && r.some(
67
+ if (o.length > 0)
68
+ for (; u < e.length && o.some(
69
69
  (a) => e[u].includes(a)
70
70
  ); )
71
71
  u++;
@@ -78,8 +78,8 @@ function R() {
78
78
  const a = c.match(/at\s+(.+)/);
79
79
  if (a) {
80
80
  i = a[1];
81
- const y = i.match(/at\s+([^(\s]+)\s+/);
82
- y && y[1] !== "new" && (h = y[1]);
81
+ const p = i.match(/at\s+([^(\s]+)\s+/);
82
+ p && p[1] !== "new" && (h = p[1]);
83
83
  }
84
84
  }
85
85
  i.includes("(") && (i = i.substring(
@@ -107,13 +107,13 @@ class d {
107
107
  * ```
108
108
  */
109
109
  onDebug(t, s, e) {
110
- const r = [], { callerInfo: u, functionName: c } = R();
111
- r.push(`${t} initialized
112
- `), r.push(`Caller Function: ${c}
113
- `), r.push(`Caller Location: ${u}
114
- `), r.push(`Body: ${JSON.stringify(s, null, 2)}
115
- `), e && r.push(`Cause: ${JSON.stringify(e, null, 2)}
116
- `), g({ scheme: "red", name: "ARKYN-BAD-RESPONSE-DEBUG", debugs: r });
110
+ const o = [], { callerInfo: u, functionName: c } = R();
111
+ o.push(`${t} initialized
112
+ `), o.push(`Caller Function: ${c}
113
+ `), o.push(`Caller Location: ${u}
114
+ `), o.push(`Body: ${JSON.stringify(s, null, 2)}
115
+ `), e && o.push(`Cause: ${JSON.stringify(e, null, 2)}
116
+ `), f({ scheme: "red", name: "ARKYN-BAD-RESPONSE-DEBUG", debugs: o });
117
117
  }
118
118
  }
119
119
  class j extends d {
@@ -125,10 +125,10 @@ class j extends d {
125
125
  */
126
126
  constructor(s, e) {
127
127
  super();
128
- o(this, "body");
129
- o(this, "cause");
130
- o(this, "status", 502);
131
- o(this, "statusText");
128
+ r(this, "body");
129
+ r(this, "cause");
130
+ r(this, "status", 502);
131
+ r(this, "statusText");
132
132
  this.body = { name: "BadGateway", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug("BadGateway", this.body, this.cause);
133
133
  }
134
134
  /**
@@ -159,7 +159,7 @@ class j extends d {
159
159
  return Response.json(this.body, s);
160
160
  }
161
161
  }
162
- class b extends d {
162
+ class g extends d {
163
163
  /**
164
164
  * Creates an instance of the `BadRequest` class.
165
165
  *
@@ -168,10 +168,10 @@ class b extends d {
168
168
  */
169
169
  constructor(s, e) {
170
170
  super();
171
- o(this, "body");
172
- o(this, "cause");
173
- o(this, "status", 400);
174
- o(this, "statusText");
171
+ r(this, "body");
172
+ r(this, "cause");
173
+ r(this, "status", 400);
174
+ r(this, "statusText");
175
175
  this.body = { name: "BadRequest", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug("BadRequest", this.body, this.cause);
176
176
  }
177
177
  /**
@@ -211,10 +211,10 @@ class J extends d {
211
211
  */
212
212
  constructor(s, e) {
213
213
  super();
214
- o(this, "body");
215
- o(this, "cause");
216
- o(this, "status", 409);
217
- o(this, "statusText");
214
+ r(this, "body");
215
+ r(this, "cause");
216
+ r(this, "status", 409);
217
+ r(this, "statusText");
218
218
  this.body = { name: "Conflict", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug("Conflict", this.body, this.cause);
219
219
  }
220
220
  /**
@@ -254,10 +254,10 @@ class D extends d {
254
254
  */
255
255
  constructor(s, e) {
256
256
  super();
257
- o(this, "body");
258
- o(this, "cause");
259
- o(this, "status", 403);
260
- o(this, "statusText");
257
+ r(this, "body");
258
+ r(this, "cause");
259
+ r(this, "status", 403);
260
+ r(this, "statusText");
261
261
  this.body = { name: "Forbidden", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug("Forbidden", this.body, this.cause);
262
262
  }
263
263
  /**
@@ -297,10 +297,10 @@ class C extends d {
297
297
  */
298
298
  constructor(s, e) {
299
299
  super();
300
- o(this, "body");
301
- o(this, "cause");
302
- o(this, "status", 404);
303
- o(this, "statusText");
300
+ r(this, "body");
301
+ r(this, "cause");
302
+ r(this, "status", 404);
303
+ r(this, "statusText");
304
304
  this.body = { name: "NotFound", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug("NotFound", this.body, this.cause);
305
305
  }
306
306
  /**
@@ -340,10 +340,10 @@ class B extends d {
340
340
  */
341
341
  constructor(s, e) {
342
342
  super();
343
- o(this, "body");
344
- o(this, "cause");
345
- o(this, "status", 501);
346
- o(this, "statusText");
343
+ r(this, "body");
344
+ r(this, "cause");
345
+ r(this, "status", 501);
346
+ r(this, "statusText");
347
347
  this.body = { name: "NotImplemented", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug("NotImplemented", this.body, this.cause);
348
348
  }
349
349
  /**
@@ -383,10 +383,10 @@ class x extends d {
383
383
  */
384
384
  constructor(s, e) {
385
385
  super();
386
- o(this, "body");
387
- o(this, "cause");
388
- o(this, "status", 500);
389
- o(this, "statusText");
386
+ r(this, "body");
387
+ r(this, "cause");
388
+ r(this, "status", 500);
389
+ r(this, "statusText");
390
390
  this.body = { name: "ServerError", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug("ServerError", this.body, this.cause);
391
391
  }
392
392
  /**
@@ -417,7 +417,7 @@ class x extends d {
417
417
  return Response.json(this.body, s);
418
418
  }
419
419
  }
420
- class $ extends d {
420
+ class q extends d {
421
421
  /**
422
422
  * Creates an instance of the `Unauthorized` class.
423
423
  *
@@ -426,10 +426,10 @@ class $ extends d {
426
426
  */
427
427
  constructor(s, e) {
428
428
  super();
429
- o(this, "body");
430
- o(this, "cause");
431
- o(this, "status", 401);
432
- o(this, "statusText");
429
+ r(this, "body");
430
+ r(this, "cause");
431
+ r(this, "status", 401);
432
+ r(this, "statusText");
433
433
  this.body = { name: "Unauthorized", message: s }, this.statusText = s, this.cause = e ? JSON.stringify(e) : void 0, this.onDebug("Unauthorized", this.body, this.cause);
434
434
  }
435
435
  /**
@@ -460,7 +460,7 @@ class $ extends d {
460
460
  return Response.json(this.body, s);
461
461
  }
462
462
  }
463
- class w extends d {
463
+ class N extends d {
464
464
  /**
465
465
  * Creates an instance of the `UnprocessableEntity` class.
466
466
  *
@@ -473,9 +473,9 @@ class w extends d {
473
473
  */
474
474
  constructor(s) {
475
475
  super();
476
- o(this, "body");
477
- o(this, "status", 422);
478
- o(this, "statusText");
476
+ r(this, "body");
477
+ r(this, "status", 422);
478
+ r(this, "statusText");
479
479
  this.statusText = s.message || "Unprocessable Entity", this.body = {
480
480
  name: "UnprocessableEntity",
481
481
  message: s.message || null,
@@ -512,7 +512,7 @@ class w extends d {
512
512
  return Response.json(this.body, s);
513
513
  }
514
514
  }
515
- class f {
515
+ class T {
516
516
  /**
517
517
  * Logs debug information for success responses including caller context and response details.
518
518
  *
@@ -527,20 +527,20 @@ class f {
527
527
  * ```
528
528
  */
529
529
  onDebug(t, s, e) {
530
- const r = [], { callerInfo: u, functionName: c } = R();
531
- r.push(`${t} initialized
532
- `), r.push(`Caller Function: ${c}
533
- `), r.push(`Caller Location: ${u}
534
- `), r.push(`Body: ${JSON.stringify(s, null, 2)}
535
- `), e && r.push(`Cause: ${JSON.stringify(e, null, 2)}
536
- `), g({
530
+ const o = [], { callerInfo: u, functionName: c } = R();
531
+ o.push(`${t} initialized
532
+ `), o.push(`Caller Function: ${c}
533
+ `), o.push(`Caller Location: ${u}
534
+ `), o.push(`Body: ${JSON.stringify(s, null, 2)}
535
+ `), e && o.push(`Cause: ${JSON.stringify(e, null, 2)}
536
+ `), f({
537
537
  scheme: "green",
538
538
  name: "ARKYN-SUCCESS-RESPONSE-DEBUG",
539
- debugs: r
539
+ debugs: o
540
540
  });
541
541
  }
542
542
  }
543
- class q extends f {
543
+ class P extends T {
544
544
  /**
545
545
  * Creates an instance of the `Created` class.
546
546
  *
@@ -549,10 +549,10 @@ class q extends f {
549
549
  */
550
550
  constructor(s, e) {
551
551
  super();
552
- o(this, "body");
553
- o(this, "headers");
554
- o(this, "status");
555
- o(this, "statusText");
552
+ r(this, "body");
553
+ r(this, "headers");
554
+ r(this, "status");
555
+ r(this, "statusText");
556
556
  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);
557
557
  }
558
558
  /**
@@ -584,7 +584,7 @@ class q extends f {
584
584
  return Response.json(this.body, s);
585
585
  }
586
586
  }
587
- class P extends f {
587
+ class H extends T {
588
588
  /**
589
589
  * Creates an instance of the `Found` class.
590
590
  *
@@ -596,10 +596,10 @@ class P extends f {
596
596
  */
597
597
  constructor(s, e) {
598
598
  super();
599
- o(this, "body");
600
- o(this, "headers");
601
- o(this, "status");
602
- o(this, "statusText");
599
+ r(this, "body");
600
+ r(this, "headers");
601
+ r(this, "status");
602
+ r(this, "statusText");
603
603
  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);
604
604
  }
605
605
  /**
@@ -631,7 +631,7 @@ class P extends f {
631
631
  return Response.json(this.body, s);
632
632
  }
633
633
  }
634
- class H extends f {
634
+ class L extends T {
635
635
  /**
636
636
  * Creates an instance of the `NoContent` class.
637
637
  *
@@ -639,9 +639,9 @@ class H extends f {
639
639
  */
640
640
  constructor(s) {
641
641
  super();
642
- o(this, "headers");
643
- o(this, "status");
644
- o(this, "statusText");
642
+ r(this, "headers");
643
+ r(this, "status");
644
+ r(this, "statusText");
645
645
  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);
646
646
  }
647
647
  /**
@@ -659,7 +659,7 @@ class H extends f {
659
659
  return new Response(null, s);
660
660
  }
661
661
  }
662
- class L extends f {
662
+ class $ extends T {
663
663
  /**
664
664
  * Creates an instance of the `Success` class.
665
665
  *
@@ -668,10 +668,10 @@ class L extends f {
668
668
  */
669
669
  constructor(s, e) {
670
670
  super();
671
- o(this, "body");
672
- o(this, "headers");
673
- o(this, "status");
674
- o(this, "statusText");
671
+ r(this, "body");
672
+ r(this, "headers");
673
+ r(this, "status");
674
+ r(this, "statusText");
675
675
  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);
676
676
  }
677
677
  /**
@@ -703,7 +703,7 @@ class L extends f {
703
703
  return Response.json(this.body, s);
704
704
  }
705
705
  }
706
- class A extends f {
706
+ class A extends T {
707
707
  /**
708
708
  * Creates an instance of the `Updated` class.
709
709
  *
@@ -712,10 +712,10 @@ class A extends f {
712
712
  */
713
713
  constructor(s, e) {
714
714
  super();
715
- o(this, "body");
716
- o(this, "headers");
717
- o(this, "status");
718
- o(this, "statusText");
715
+ r(this, "body");
716
+ r(this, "headers");
717
+ r(this, "status");
718
+ r(this, "statusText");
719
719
  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);
720
720
  }
721
721
  /**
@@ -749,12 +749,12 @@ class A extends f {
749
749
  }
750
750
  class v {
751
751
  static mapHeaders(t) {
752
- return t instanceof Headers ? Object.fromEntries(t.entries()) : typeof t == "object" ? Object.entries(t).reduce((s, [e, r]) => (typeof r == "string" ? s[e] = r : Array.isArray(r) ? s[e] = r.join(", ") : s[e] = JSON.stringify(r), s), {}) : {};
752
+ 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), {}) : {};
753
753
  }
754
754
  static mapQueryParams(t) {
755
755
  const s = {};
756
- return t.forEach((e, r) => {
757
- s[r] = e;
756
+ return t.forEach((e, o) => {
757
+ s[o] = e;
758
758
  }), s;
759
759
  }
760
760
  static handle(t) {
@@ -772,7 +772,7 @@ class v {
772
772
  };
773
773
  }
774
774
  }
775
- class N {
775
+ class w {
776
776
  /**
777
777
  * Sets the configuration for the arkyn. This method initializes the arkyn configuration
778
778
  * with the provided `arkynConfig` values. If the configuration has already been set,
@@ -810,35 +810,35 @@ class N {
810
810
  this.arkynConfig = void 0;
811
811
  }
812
812
  }
813
- o(N, "arkynConfig");
813
+ r(w, "arkynConfig");
814
814
  async function F(n) {
815
- const t = N.getArkynConfig();
815
+ const t = w.getArkynConfig();
816
816
  if (!t) return;
817
817
  const { arkynUserToken: s, arkynApiUrl: e } = t, {
818
- elapsedTime: r,
818
+ elapsedTime: o,
819
819
  method: u,
820
820
  queryParams: c,
821
821
  requestBody: h,
822
822
  requestHeaders: i,
823
823
  responseBody: l,
824
824
  responseHeaders: a,
825
- status: y,
825
+ status: p,
826
826
  token: Q,
827
827
  rawUrl: E
828
828
  } = n;
829
829
  if (process.env.NODE_ENV !== "development")
830
830
  try {
831
- const p = new URL(E);
831
+ const y = new URL(E);
832
832
  let m = "HTTPS";
833
- p.protocol === "http:" && (m = "HTTP");
833
+ y.protocol === "http:" && (m = "HTTP");
834
834
  const O = JSON.stringify({
835
- domainUrl: p.protocol + "//" + p.host,
836
- pathnameUrl: p.pathname,
837
- status: y,
835
+ domainUrl: y.protocol + "//" + y.host,
836
+ pathnameUrl: y.pathname,
837
+ status: p,
838
838
  protocol: m,
839
839
  method: u,
840
840
  trafficUserId: null,
841
- elapsedTime: r,
841
+ elapsedTime: o,
842
842
  requestHeaders: i,
843
843
  requestBody: h,
844
844
  queryParams: c,
@@ -859,16 +859,16 @@ async function F(n) {
859
859
  }
860
860
  }
861
861
  );
862
- } catch (p) {
863
- g({
864
- debugs: [`Error sending request: ${p}`],
862
+ } catch (y) {
863
+ f({
864
+ debugs: [`Error sending request: ${y}`],
865
865
  name: "ARKYN_LOG_ERROR",
866
866
  scheme: "red"
867
867
  });
868
868
  }
869
869
  }
870
- async function T(n, t, s = {}, e) {
871
- const r = {
870
+ async function b(n, t, s = {}, e) {
871
+ const o = {
872
872
  POST: "Resource created successfully",
873
873
  PUT: "Resource updated successfully",
874
874
  DELETE: "Resource deleted successfully",
@@ -887,7 +887,7 @@ async function T(n, t, s = {}, e) {
887
887
  } catch {
888
888
  a = null;
889
889
  }
890
- const y = v.handle({
890
+ const p = v.handle({
891
891
  elapsedTime: i,
892
892
  method: n,
893
893
  queryParams: new URL(t).searchParams,
@@ -898,10 +898,10 @@ async function T(n, t, s = {}, e) {
898
898
  status: l,
899
899
  url: t
900
900
  });
901
- return F(y), h.ok ? {
901
+ return F(p), h.ok ? {
902
902
  success: !0,
903
903
  status: l,
904
- message: (a == null ? void 0 : a.message) || r[n],
904
+ message: (a == null ? void 0 : a.message) || o[n],
905
905
  response: a,
906
906
  cause: null
907
907
  } : {
@@ -912,7 +912,7 @@ async function T(n, t, s = {}, e) {
912
912
  cause: null
913
913
  };
914
914
  } catch (u) {
915
- return g({
915
+ return f({
916
916
  debugs: [`Network error or request failed: ${u}`],
917
917
  name: "ARKYN_MAKE_REQUEST_ERROR",
918
918
  scheme: "red"
@@ -926,19 +926,19 @@ async function T(n, t, s = {}, e) {
926
926
  }
927
927
  }
928
928
  async function M(n, t = {}, s) {
929
- return T("DELETE", n, t, s);
929
+ return b("DELETE", n, t, s);
930
930
  }
931
931
  async function _(n, t = {}) {
932
- return T("GET", n, t);
932
+ return b("GET", n, t);
933
933
  }
934
934
  async function z(n, t = {}, s) {
935
- return T("PATCH", n, t, s);
935
+ return b("PATCH", n, t, s);
936
936
  }
937
937
  async function G(n, t = {}, s) {
938
- return T("POST", n, t, s);
938
+ return b("POST", n, t, s);
939
939
  }
940
940
  async function K(n, t = {}, s) {
941
- return T("PUT", n, t, s);
941
+ return b("PUT", n, t, s);
942
942
  }
943
943
  class X {
944
944
  /**
@@ -950,10 +950,10 @@ class X {
950
950
  * @param props.enableDebug - Optional flag to enable debug logging for requests.
951
951
  */
952
952
  constructor(t) {
953
- o(this, "baseUrl");
954
- o(this, "baseHeaders");
955
- o(this, "baseToken");
956
- o(this, "enableDebug");
953
+ r(this, "baseUrl");
954
+ r(this, "baseHeaders");
955
+ r(this, "baseToken");
956
+ r(this, "enableDebug");
957
957
  this.baseUrl = t.baseUrl, this.baseHeaders = t.baseHeaders || void 0, this.baseToken = t.baseToken || void 0, this.enableDebug = t.enableDebug || !1;
958
958
  }
959
959
  /**
@@ -963,8 +963,8 @@ class X {
963
963
  */
964
964
  onDebug(t, s, e) {
965
965
  if (this.enableDebug) {
966
- const c = "\x1B[33m[ARKYN-API-DEBUG]\x1B[0m";
967
- console.log(`${c} Base URL: ${this.baseUrl}`), console.log(`${c} Full URL: ${t}`), console.log(`${c} Method: ${s}`), e[0] && console.log(`${c} Headers: `, e[0]), e[1] && console.log(`${c} Body: `, e[1]);
966
+ 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
968
  }
969
969
  }
970
970
  generateURL(t) {
@@ -987,8 +987,8 @@ class X {
987
987
  * @returns The API response data.
988
988
  */
989
989
  async get(t, s) {
990
- const e = this.generateURL(t), r = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token);
991
- return this.onDebug(e, "get", [r]), await _(e, r);
990
+ 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
992
  }
993
993
  /**
994
994
  * Sends a post request to the specified route.
@@ -997,8 +997,8 @@ class X {
997
997
  * @returns The API response data.
998
998
  */
999
999
  async post(t, s) {
1000
- const e = this.generateURL(t), r = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
1001
- return this.onDebug(e, "post", [r, u]), await G(e, r, u);
1000
+ const e = this.generateURL(t), o = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
1001
+ return this.onDebug(e, "post", [o, u]), await G(e, o, u);
1002
1002
  }
1003
1003
  /**
1004
1004
  * Sends a put request to the specified route.
@@ -1007,8 +1007,8 @@ class X {
1007
1007
  * @returns The API response data.
1008
1008
  */
1009
1009
  async put(t, s) {
1010
- const e = this.generateURL(t), r = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
1011
- return this.onDebug(e, "put", [r, u]), await K(e, r, u);
1010
+ 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
1012
  }
1013
1013
  /**
1014
1014
  * Sends a patch request to the specified route.
@@ -1017,8 +1017,8 @@ class X {
1017
1017
  * @returns The API response data.
1018
1018
  */
1019
1019
  async patch(t, s) {
1020
- const e = this.generateURL(t), r = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
1021
- return this.onDebug(e, "patch", [r, u]), await z(e, r, u);
1020
+ const e = this.generateURL(t), o = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
1021
+ return this.onDebug(e, "patch", [o, u]), await z(e, o, u);
1022
1022
  }
1023
1023
  /**
1024
1024
  * Sends a delete request to the specified route.
@@ -1027,13 +1027,13 @@ class X {
1027
1027
  * @returns The API response data.
1028
1028
  */
1029
1029
  async delete(t, s) {
1030
- const e = this.generateURL(t), r = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
1031
- return this.onDebug(e, "delete", [r, u]), await M(e, r, u);
1030
+ const e = this.generateURL(t), o = this.generateHeaders((s == null ? void 0 : s.headers) || {}, s == null ? void 0 : s.token), u = s == null ? void 0 : s.body;
1031
+ return this.onDebug(e, "delete", [o, u]), await M(e, o, u);
1032
1032
  }
1033
1033
  }
1034
1034
  function Z(n, t) {
1035
- var s, e, r;
1036
- return n != null && n.message && typeof (n == null ? void 0 : n.message) == "string" ? n == null ? void 0 : n.message : n != null && n.error && typeof (n == null ? void 0 : n.error) == "string" ? n == null ? void 0 : n.error : (s = n == null ? void 0 : n.error) != null && s.message && typeof ((e = n == null ? void 0 : n.error) == null ? void 0 : e.message) == "string" ? (r = n == null ? void 0 : n.error) == null ? void 0 : r.message : t != null && t.statusText && typeof (t == null ? void 0 : t.statusText) == "string" ? t == null ? void 0 : t.statusText : "Missing error message";
1035
+ var s, e, o;
1036
+ 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";
1037
1037
  }
1038
1038
  const ss = async (n) => {
1039
1039
  let t;
@@ -1046,9 +1046,9 @@ const ss = async (n) => {
1046
1046
  const u = new URLSearchParams(e);
1047
1047
  t = Object.fromEntries(u.entries());
1048
1048
  } else
1049
- throw new b("Invalid URLSearchParams format");
1049
+ throw new g("Invalid URLSearchParams format");
1050
1050
  } catch {
1051
- throw new b("Failed to extract data from request");
1051
+ throw new g("Failed to extract data from request");
1052
1052
  }
1053
1053
  }
1054
1054
  return t;
@@ -1057,21 +1057,21 @@ function es(n) {
1057
1057
  switch (!0) {
1058
1058
  case n instanceof Response:
1059
1059
  return n;
1060
- case n instanceof P:
1060
+ case n instanceof H:
1061
1061
  return n.toResponse();
1062
- case n instanceof q:
1062
+ case n instanceof P:
1063
1063
  return n.toResponse();
1064
1064
  case n instanceof A:
1065
1065
  return n.toResponse();
1066
- case n instanceof L:
1066
+ case n instanceof $:
1067
1067
  return n.toResponse();
1068
- case n instanceof H:
1068
+ case n instanceof L:
1069
1069
  return n.toResponse();
1070
1070
  }
1071
1071
  switch (!0) {
1072
1072
  case n instanceof j:
1073
1073
  return n.toResponse();
1074
- case n instanceof b:
1074
+ case n instanceof g:
1075
1075
  return n.toResponse();
1076
1076
  case n instanceof J:
1077
1077
  return n.toResponse();
@@ -1083,9 +1083,9 @@ function es(n) {
1083
1083
  return n.toResponse();
1084
1084
  case n instanceof x:
1085
1085
  return n.toResponse();
1086
- case n instanceof $:
1086
+ case n instanceof q:
1087
1087
  return n.toResponse();
1088
- case n instanceof w:
1088
+ case n instanceof N:
1089
1089
  return n.toResponse();
1090
1090
  }
1091
1091
  return new x("Server error", n).toResponse();
@@ -1097,7 +1097,7 @@ function V([
1097
1097
  const s = t.safeParse(n);
1098
1098
  if (s.success === !1) {
1099
1099
  const e = Object.fromEntries(
1100
- s.error.issues.map((r) => (console.log(r), [r.path.join("."), r.message]))
1100
+ s.error.issues.map((o) => [o.path.join("."), o.message])
1101
1101
  );
1102
1102
  return {
1103
1103
  success: s.success,
@@ -1115,20 +1115,20 @@ const ts = (n, t = "") => {
1115
1115
  if (t === "") return s.searchParams;
1116
1116
  const e = Array.from(
1117
1117
  s.searchParams.entries()
1118
- ).filter(([r]) => r.startsWith(`${t}:`)).map(([r, u]) => [r.replace(`${t}:`, ""), u]);
1118
+ ).filter(([o]) => o.startsWith(`${t}:`)).map(([o, u]) => [o.replace(`${t}:`, ""), u]);
1119
1119
  return new URLSearchParams(e);
1120
1120
  };
1121
1121
  function Y(n) {
1122
1122
  const t = "Error validating:", s = n.issues.map(
1123
- ({ path: e, message: r }) => `-> ${e.join(".")}: ${r}`
1123
+ ({ path: e, message: o }) => `-> ${e.join(".")}: ${o}`
1124
1124
  );
1125
1125
  return [t, ...s].join(`
1126
1126
  `);
1127
1127
  }
1128
1128
  class ns {
1129
1129
  constructor(t) {
1130
- o(this, "functionName");
1131
- o(this, "callerInfo");
1130
+ r(this, "functionName");
1131
+ r(this, "callerInfo");
1132
1132
  this.schema = t;
1133
1133
  const { callerInfo: s, functionName: e } = R();
1134
1134
  this.callerInfo = s, this.functionName = e;
@@ -1149,11 +1149,11 @@ class ns {
1149
1149
  formValidate(t, s) {
1150
1150
  const e = V([t, this.schema]);
1151
1151
  if (!e.success) {
1152
- const r = Object.keys(e.fieldErrors)[0];
1153
- throw new w({
1152
+ const o = Object.keys(e.fieldErrors)[0];
1153
+ throw new N({
1154
1154
  fields: e.fields,
1155
1155
  fieldErrors: e.fieldErrors,
1156
- data: { scrollTo: r },
1156
+ data: { scrollTo: o },
1157
1157
  message: s
1158
1158
  });
1159
1159
  }
@@ -1162,27 +1162,27 @@ class ns {
1162
1162
  }
1163
1163
  export {
1164
1164
  X as ApiService,
1165
- N as ArkynLogService,
1165
+ w as ArkynLogService,
1166
1166
  j as BadGateway,
1167
- b as BadRequest,
1167
+ g as BadRequest,
1168
1168
  J as Conflict,
1169
- q as Created,
1169
+ P as Created,
1170
1170
  S as DebugService,
1171
1171
  D as Forbidden,
1172
- P as Found,
1173
- H as NoContent,
1172
+ H as Found,
1173
+ L as NoContent,
1174
1174
  C as NotFound,
1175
1175
  B as NotImplemented,
1176
1176
  ns as SchemaValidator,
1177
1177
  x as ServerError,
1178
- L as Success,
1179
- $ as Unauthorized,
1180
- w as UnprocessableEntity,
1178
+ $ as Success,
1179
+ q as Unauthorized,
1180
+ N as UnprocessableEntity,
1181
1181
  A as Updated,
1182
1182
  Z as decodeErrorMessageFromRequest,
1183
1183
  ss as decodeRequestBody,
1184
1184
  es as errorHandler,
1185
- g as flushDebugLogs,
1185
+ f as flushDebugLogs,
1186
1186
  V as formParse,
1187
1187
  R as getCaller,
1188
1188
  ts as getScopedParams
@@ -1,14 +1,14 @@
1
- (function(a,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(a=typeof globalThis<"u"?globalThis:a||self,h(a["@arkyn/server"]={}))})(this,function(a){"use strict";var es=Object.defineProperty;var ts=(a,h,g)=>h in a?es(a,h,{enumerable:!0,configurable:!0,writable:!0,value:g}):a[h]=g;var o=(a,h,g)=>ts(a,typeof h!="symbol"?h+"":h,g);function h(n){var s;if(process.env.NODE_ENV==="development"||((s=process.env)==null?void 0:s.SHOW_ERRORS_IN_CONSOLE)==="true"){const u=`${{yellow:"\x1B[33m",cyan:"\x1B[36m",red:"\x1B[31m",green:"\x1B[32m"}[n.scheme]}[${n.name}]\x1B[0m`;let c="";n.debugs.forEach(d=>{c+=`${u} ${d}
2
- `}),console.log(c)}}const g={};class N{static setIgnoreFile(t){this.ignoreFiles.push(t)}static clearIgnoreFiles(){this.ignoreFiles=[]}}o(N,"ignoreFiles",[]);function R(){const n=process.cwd(),e=(new Error().stack||"").split(`
3
- `).map(i=>i.trim()),r=N.ignoreFiles;let u=2;for(;u<e.length&&(e[u].includes("node:internal")||e[u].includes("/node_modules/"));)u++;if(r.length>0)for(;u<e.length&&r.some(i=>e[u].includes(i));)u++;const c=e[u]||"";let d="Unknown function",l="Unknown caller";const f=c.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);if(f)d=f[1],l=f[2];else{const i=c.match(/at\s+(.+)/);if(i){l=i[1];const p=l.match(/at\s+([^(\s]+)\s+/);p&&p[1]!=="new"&&(d=p[1])}}l.includes("(")&&(l=l.substring(l.indexOf("(")+1,l.lastIndexOf(")"))),l=l.split(":").slice(0,-2).join(":");try{l=g.relative(n,l)}catch{}return{functionName:d,callerInfo:l}}class y{onDebug(t,s,e){const r=[],{callerInfo:u,functionName:c}=R();r.push(`${t} initialized
4
- `),r.push(`Caller Function: ${c}
5
- `),r.push(`Caller Location: ${u}
6
- `),r.push(`Body: ${JSON.stringify(s,null,2)}
7
- `),e&&r.push(`Cause: ${JSON.stringify(e,null,2)}
8
- `),h({scheme:"red",name:"ARKYN-BAD-RESPONSE-DEBUG",debugs:r})}}class U extends y{constructor(s,e){super();o(this,"body");o(this,"cause");o(this,"status",502);o(this,"statusText");this.body={name:"BadGateway",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("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 y{constructor(s,e){super();o(this,"body");o(this,"cause");o(this,"status",400);o(this,"statusText");this.body={name:"BadRequest",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("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 O extends y{constructor(s,e){super();o(this,"body");o(this,"cause");o(this,"status",409);o(this,"statusText");this.body={name:"Conflict",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("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 y{constructor(s,e){super();o(this,"body");o(this,"cause");o(this,"status",403);o(this,"statusText");this.body={name:"Forbidden",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("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 y{constructor(s,e){super();o(this,"body");o(this,"cause");o(this,"status",404);o(this,"statusText");this.body={name:"NotFound",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("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 y{constructor(s,e){super();o(this,"body");o(this,"cause");o(this,"status",501);o(this,"statusText");this.body={name:"NotImplemented",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("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 y{constructor(s,e){super();o(this,"body");o(this,"cause");o(this,"status",500);o(this,"statusText");this.body={name:"ServerError",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("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 y{constructor(s,e){super();o(this,"body");o(this,"cause");o(this,"status",401);o(this,"statusText");this.body={name:"Unauthorized",message:s},this.statusText=s,this.cause=e?JSON.stringify(e):void 0,this.onDebug("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 y{constructor(s){super();o(this,"body");o(this,"status",422);o(this,"statusText");this.statusText=s.message||"Unprocessable Entity",this.body={name:"UnprocessableEntity",message:s.message||null,data:s.data,fieldErrors:s.fieldErrors,fields:s.fields},this.onDebug("UnprocessableEntity",this.body,this.body)}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class T{onDebug(t,s,e){const r=[],{callerInfo:u,functionName:c}=R();r.push(`${t} initialized
9
- `),r.push(`Caller Function: ${c}
10
- `),r.push(`Caller Location: ${u}
11
- `),r.push(`Body: ${JSON.stringify(s,null,2)}
12
- `),e&&r.push(`Cause: ${JSON.stringify(e,null,2)}
13
- `),h({scheme:"green",name:"ARKYN-SUCCESS-RESPONSE-DEBUG",debugs:r})}}class D extends T{constructor(s,e){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||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 J extends T{constructor(s,e){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||302,this.statusText=(e==null?void 0:e.statusText)||"Found",this.onDebug("Found",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class B extends T{constructor(s){super();o(this,"headers");o(this,"status");o(this,"statusText");this.headers=(s==null?void 0:s.headers)||{},this.status=(s==null?void 0:s.status)||204,this.statusText=(s==null?void 0:s.statusText)??"No content",this.onDebug("No content",null)}toResponse(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return new Response(null,s)}}class q extends T{constructor(s,e){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||200,this.statusText=(e==null?void 0:e.statusText)??"OK",this.onDebug("Success",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class P extends T{constructor(s,e){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||200,this.statusText=(e==null?void 0:e.statusText)||"Resource updated successfully",this.onDebug("Updated",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class v{static mapHeaders(t){return t instanceof Headers?Object.fromEntries(t.entries()):typeof t=="object"?Object.entries(t).reduce((s,[e,r])=>(typeof r=="string"?s[e]=r:Array.isArray(r)?s[e]=r.join(", "):s[e]=JSON.stringify(r),s),{}):{}}static mapQueryParams(t){const s={};return t.forEach((e,r)=>{s[r]=e}),s}static handle(t){return{rawUrl:t.url,status:t.status,method:t.method,token:null,elapsedTime:t.elapsedTime,requestHeaders:this.mapHeaders(t.requestHeaders),requestBody:t.requestBody||null,queryParams:this.mapQueryParams(t.queryParams),responseHeaders:this.mapHeaders(t.responseHeaders),responseBody:t.responseBody||null}}}class E{static setArkynConfig(t){if(this.arkynConfig)return;let e=t.arkynLogBaseApiUrl||"https://logs-arkyn-flow-logs.vw6wo7.easypanel.host";e=e+"/http-traffic-records/:trafficSourceId",this.arkynConfig={arkynTrafficSourceId:t.arkynTrafficSourceId,arkynUserToken:t.arkynUserToken,arkynApiUrl:e}}static getArkynConfig(){return this.arkynConfig}static resetArkynConfig(){this.arkynConfig=void 0}}o(E,"arkynConfig");async function A(n){const t=E.getArkynConfig();if(!t)return;const{arkynUserToken:s,arkynApiUrl:e}=t,{elapsedTime:r,method:u,queryParams:c,requestBody:d,requestHeaders:l,responseBody:f,responseHeaders:i,status:p,token:ns,rawUrl:Z}=n;if(process.env.NODE_ENV!=="development")try{const b=new URL(Z);let L="HTTPS";b.protocol==="http:"&&(L="HTTP");const ss=JSON.stringify({domainUrl:b.protocol+"//"+b.host,pathnameUrl:b.pathname,status:p,protocol:L,method:u,trafficUserId:null,elapsedTime:r,requestHeaders:l,requestBody:d,queryParams:c,responseHeaders:i,responseBody:f});await fetch(e.replace(":trafficSourceId",t.arkynTrafficSourceId),{method:"POST",body:ss,headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`}})}catch(b){h({debugs:[`Error sending request: ${b}`],name:"ARKYN_LOG_ERROR",scheme:"red"})}}async function m(n,t,s={},e){const r={POST:"Resource created successfully",PUT:"Resource updated successfully",DELETE:"Resource deleted successfully",PATCH:"Resource patched successfully",GET:"Request successful"};try{const u=performance.now(),c={...s,"Content-Type":"application/json"},d=await fetch(t,{method:n,headers:c,body:e?JSON.stringify(e):void 0}),l=performance.now()-u,f=d.status;let i=null;try{i=await d.json()}catch{i=null}const p=v.handle({elapsedTime:l,method:n,queryParams:new URL(t).searchParams,requestHeaders:c,requestBody:e,responseBody:i,responseHeaders:d.headers,status:f,url:t});return A(p),d.ok?{success:!0,status:f,message:(i==null?void 0:i.message)||r[n],response:i,cause:null}:{success:!1,status:f,message:(i==null?void 0:i.message)||d.statusText||"Request failed",response:i,cause:null}}catch(u){return h({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 H(n,t={},s){return m("DELETE",n,t,s)}async function F(n,t={}){return m("GET",n,t)}async function M(n,t={},s){return m("PATCH",n,t,s)}async function _(n,t={},s){return m("POST",n,t,s)}async function z(n,t={},s){return m("PUT",n,t,s)}class G{constructor(t){o(this,"baseUrl");o(this,"baseHeaders");o(this,"baseToken");o(this,"enableDebug");this.baseUrl=t.baseUrl,this.baseHeaders=t.baseHeaders||void 0,this.baseToken=t.baseToken||void 0,this.enableDebug=t.enableDebug||!1}onDebug(t,s,e){if(this.enableDebug){const c="\x1B[33m[ARKYN-API-DEBUG]\x1B[0m";console.log(`${c} Base URL: ${this.baseUrl}`),console.log(`${c} Full URL: ${t}`),console.log(`${c} Method: ${s}`),e[0]&&console.log(`${c} Headers: `,e[0]),e[1]&&console.log(`${c} Body: `,e[1])}}generateURL(t){return this.baseUrl+t}generateHeaders(t,s){let e={};return this.baseToken&&(e={Authorization:`Bearer ${this.baseToken}`}),this.baseHeaders&&(e={...e,...this.baseHeaders}),t&&(e={...e,...t}),s&&(e={...e,Authorization:`Bearer ${s}`}),e}async get(t,s){const e=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token);return this.onDebug(e,"get",[r]),await F(e,r)}async post(t,s){const e=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(e,"post",[r,u]),await _(e,r,u)}async put(t,s){const e=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(e,"put",[r,u]),await z(e,r,u)}async patch(t,s){const e=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(e,"patch",[r,u]),await M(e,r,u)}async delete(t,s){const e=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(e,"delete",[r,u]),await H(e,r,u)}}function K(n,t){var s,e,r;return n!=null&&n.message&&typeof(n==null?void 0:n.message)=="string"?n==null?void 0:n.message:n!=null&&n.error&&typeof(n==null?void 0:n.error)=="string"?n==null?void 0:n.error:(s=n==null?void 0:n.error)!=null&&s.message&&typeof((e=n==null?void 0:n.error)==null?void 0:e.message)=="string"?(r=n==null?void 0:n.error)==null?void 0:r.message:t!=null&&t.statusText&&typeof(t==null?void 0:t.statusText)=="string"?t==null?void 0:t.statusText:"Missing error message"}const V=async n=>{let t;const s=await n.arrayBuffer(),e=new TextDecoder().decode(s);try{t=JSON.parse(e)}catch{try{if(e.includes("=")){const u=new URLSearchParams(e);t=Object.fromEntries(u.entries())}else throw new x("Invalid URLSearchParams format")}catch{throw new x("Failed to extract data from request")}}return t};function Y(n){switch(!0){case n instanceof Response:return n;case n instanceof J:return n.toResponse();case n instanceof D: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 U:return n.toResponse();case n instanceof x:return n.toResponse();case n instanceof O: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 $([n,t]){const s=t.safeParse(n);if(s.success===!1){const e=Object.fromEntries(s.error.issues.map(r=>(console.log(r),[r.path.join("."),r.message])));return{success:s.success,fieldErrors:e,fields:n}}else return{success:s.success,data:s.data}}const Q=(n,t="")=>{const s=new URL(n.url);if(t==="")return s.searchParams;const e=Array.from(s.searchParams.entries()).filter(([r])=>r.startsWith(`${t}:`)).map(([r,u])=>[r.replace(`${t}:`,""),u]);return new URLSearchParams(e)};function W(n){const t="Error validating:",s=n.issues.map(({path:e,message:r})=>`-> ${e.join(".")}: ${r}`);return[t,...s].join(`
14
- `)}class X{constructor(t){o(this,"functionName");o(this,"callerInfo");this.schema=t;const{callerInfo:s,functionName:e}=R();this.callerInfo=s,this.functionName=e}isValid(t){return this.schema.safeParse(t).success}safeValidate(t){return this.schema.safeParse(t)}validate(t){try{return this.schema.parse(t)}catch(s){throw new S(W(s))}}formValidate(t,s){const e=$([t,this.schema]);if(!e.success){const r=Object.keys(e.fieldErrors)[0];throw new w({fields:e.fields,fieldErrors:e.fieldErrors,data:{scrollTo:r},message:s})}return e.data}}a.ApiService=G,a.ArkynLogService=E,a.BadGateway=U,a.BadRequest=x,a.Conflict=O,a.Created=D,a.DebugService=N,a.Forbidden=I,a.Found=J,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=h,a.formParse=$,a.getCaller=R,a.getScopedParams=Q,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
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}
2
+ `}),l+="<------------------->",console.log(l)}}const b={};class N{static setIgnoreFile(t){this.ignoreFiles.push(t)}static clearIgnoreFiles(){this.ignoreFiles=[]}}r(N,"ignoreFiles",[]);function R(){const n=process.cwd(),e=(new Error().stack||"").split(`
3
+ `).map(i=>i.trim()),o=N.ignoreFiles;let u=2;for(;u<e.length&&(e[u].includes("node:internal")||e[u].includes("/node_modules/"));)u++;if(o.length>0)for(;u<e.length&&o.some(i=>e[u].includes(i));)u++;const l=e[u]||"";let d="Unknown function",h="Unknown caller";const f=l.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);if(f)d=f[1],h=f[2];else{const i=l.match(/at\s+(.+)/);if(i){h=i[1];const p=h.match(/at\s+([^(\s]+)\s+/);p&&p[1]!=="new"&&(d=p[1])}}h.includes("(")&&(h=h.substring(h.indexOf("(")+1,h.lastIndexOf(")"))),h=h.split(":").slice(0,-2).join(":");try{h=b.relative(n,h)}catch{}return{functionName:d,callerInfo:h}}class y{onDebug(t,s,e){const o=[],{callerInfo:u,functionName:l}=R();o.push(`${t} initialized
4
+ `),o.push(`Caller Function: ${l}
5
+ `),o.push(`Caller Location: ${u}
6
+ `),o.push(`Body: ${JSON.stringify(s,null,2)}
7
+ `),e&&o.push(`Cause: ${JSON.stringify(e,null,2)}
8
+ `),c({scheme:"red",name:"ARKYN-BAD-RESPONSE-DEBUG",debugs:o})}}class O extends y{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 y{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 y{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 y{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 y{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 y{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 y{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 y{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 y{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",this.body,this.body)}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class T{onDebug(t,s,e){const o=[],{callerInfo:u,functionName:l}=R();o.push(`${t} initialized
9
+ `),o.push(`Caller Function: ${l}
10
+ `),o.push(`Caller Location: ${u}
11
+ `),o.push(`Body: ${JSON.stringify(s,null,2)}
12
+ `),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"})});
@@ -1 +1 @@
1
- {"version":3,"file":"apiService.d.ts","sourceRoot":"","sources":["../../src/services/apiService.ts"],"names":[],"mappings":"AAMA,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,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"}
@@ -3,6 +3,7 @@ import { getRequest } from "../api/getRequest";
3
3
  import { patchRequest } from "../api/patchRequest";
4
4
  import { postRequest } from "../api/postRequest";
5
5
  import { putRequest } from "../api/putRequest";
6
+ import { flushDebugLogs } from "./flushDebugLogs";
6
7
  /**
7
8
  * Class representing an API instance to handle HTTP requests with base configurations.
8
9
  */
@@ -32,16 +33,15 @@ class ApiService {
32
33
  */
33
34
  onDebug(fullRoute, method, data) {
34
35
  if (this.enableDebug) {
35
- const reset = "\x1b[0m";
36
- const yellow = "\x1b[33m";
37
- const debugName = `${yellow}[ARKYN-API-DEBUG]${reset}`;
38
- console.log(`${debugName} Base URL: ${this.baseUrl}`);
39
- console.log(`${debugName} Full URL: ${fullRoute}`);
40
- console.log(`${debugName} Method: ${method}`);
36
+ const debugs = [];
37
+ debugs.push(`Base URL: ${this.baseUrl}`);
38
+ debugs.push(`Full URL: ${fullRoute}`);
39
+ debugs.push(`Method: ${method}`);
41
40
  if (data[0])
42
- console.log(`${debugName} Headers: `, data[0]);
41
+ debugs.push(`Headers: ${JSON.stringify(data[0])}`);
43
42
  if (data[1])
44
- console.log(`${debugName} Body: `, data[1]);
43
+ debugs.push(`Body: ${JSON.stringify(data[1])}`);
44
+ flushDebugLogs({ debugs, name: "ARKYN-API-DEBUG", scheme: "yellow" });
45
45
  }
46
46
  }
47
47
  generateURL(route) {
@@ -1 +1 @@
1
- {"version":3,"file":"flushDebugLogs.d.ts","sourceRoot":"","sources":["../../src/services/flushDebugLogs.ts"],"names":[],"mappings":"AAAA,KAAK,mBAAmB,GAAG;IACzB,MAAM,EAAE,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,iBAAS,cAAc,CAAC,KAAK,EAAE,mBAAmB,QAwBjD;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
1
+ {"version":3,"file":"flushDebugLogs.d.ts","sourceRoot":"","sources":["../../src/services/flushDebugLogs.ts"],"names":[],"mappings":"AAAA,KAAK,mBAAmB,GAAG;IACzB,MAAM,EAAE,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,iBAAS,cAAc,CAAC,KAAK,EAAE,mBAAmB,QA0BjD;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -10,10 +10,11 @@ function flushDebugLogs(props) {
10
10
  green: "\x1b[32m",
11
11
  };
12
12
  const debugName = `${colors[props.scheme]}[${props.name}]${reset}`;
13
- let consoleData = ``;
13
+ let consoleData = `<------------------->`;
14
14
  props.debugs.forEach((debug) => {
15
15
  consoleData += `${debugName} ${debug}\n`;
16
16
  });
17
+ consoleData += `<------------------->`;
17
18
  console.log(consoleData);
18
19
  }
19
20
  }
@@ -1 +1 @@
1
- {"version":3,"file":"formParse.d.ts","sourceRoot":"","sources":["../../src/services/formParse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,KAAK,eAAe,CAAC,CAAC,SAAS,cAAc,IAAI;IAC/C,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;CACjD,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAChC,WAAW,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACtC,CAAC;AAEF,KAAK,cAAc,GAAG,CAAC,QAAQ,EAAE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAExE,KAAK,mBAAmB,CAAC,CAAC,SAAS,cAAc,IAC7C,eAAe,CAAC,CAAC,CAAC,GAClB,aAAa,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,iBAAS,SAAS,CAAC,CAAC,SAAS,cAAc,EAAE,CAC3C,QAAQ,EACR,MAAM,EACP,EAAE,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAsB5B;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"formParse.d.ts","sourceRoot":"","sources":["../../src/services/formParse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,KAAK,eAAe,CAAC,CAAC,SAAS,cAAc,IAAI;IAC/C,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;CACjD,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAChC,WAAW,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACtC,CAAC;AAEF,KAAK,cAAc,GAAG,CAAC,QAAQ,EAAE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAExE,KAAK,mBAAmB,CAAC,CAAC,SAAS,cAAc,IAC7C,eAAe,CAAC,CAAC,CAAC,GAClB,aAAa,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,iBAAS,SAAS,CAAC,CAAC,SAAS,cAAc,EAAE,CAC3C,QAAQ,EACR,MAAM,EACP,EAAE,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAqB5B;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -40,7 +40,6 @@ function formParse([formData, schema,]) {
40
40
  const zodResponse = schema.safeParse(formData);
41
41
  if (zodResponse.success === false) {
42
42
  const errorsObject = Object.fromEntries(zodResponse.error.issues.map((item) => {
43
- console.log(item);
44
43
  return [item.path.join("."), item.message];
45
44
  }));
46
45
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkyn/server",
3
- "version": "3.0.1-beta.62",
3
+ "version": "3.0.1-beta.63",
4
4
  "author": "Arkyn | Lucas Gonçalves",
5
5
  "main": "./dist/bundle.js",
6
6
  "module": "./dist/bundle.js",