@arkyn/server 3.0.9 → 3.0.10

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.
@@ -4,6 +4,13 @@ declare class BadResponse {
4
4
  private _status;
5
5
  private _statusText;
6
6
  private _debugColor;
7
+ /**
8
+ * When `false` (the default), `makeBody()` omits `cause` in production so internal
9
+ * details (stack traces, SQL, infra info) never reach the client. Subclasses whose
10
+ * `cause` is safe, client-facing data (e.g. `UnprocessableEntity`'s form field errors)
11
+ * set this to `true`.
12
+ */
13
+ protected exposeCauseInProduction: boolean;
7
14
  get cause(): any;
8
15
  set cause(value: any);
9
16
  get name(): string;
@@ -1 +1 @@
1
- {"version":3,"file":"_badResponse.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/_badResponse.ts"],"names":[],"mappings":"AAKA,cAAM,WAAW;IAEhB,OAAO,CAAC,MAAM,CAAC,CAAM;IACrB,OAAO,CAAC,KAAK,CAAyB;IACtC,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,WAAW,CAA8C;IAGjE,IAAI,KAAK,IAAI,GAAG,CAEf;IAGD,IAAI,KAAK,CAAC,KAAK,EAAE,GAAG,EAEnB;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,EAErB;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,MAAM,EAEvB;IAED,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,IAAI,UAAU,CAAC,KAAK,EAAE,MAAM,EAE3B;IAED,IAAI,UAAU,IAAI,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,CAEpD;IAED,IAAI,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,EAGxD;IAED,OAAO;IAeP,QAAQ;;;;;CAOR;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
1
+ {"version":3,"file":"_badResponse.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/_badResponse.ts"],"names":[],"mappings":"AAKA,cAAM,WAAW;IAEhB,OAAO,CAAC,MAAM,CAAC,CAAM;IACrB,OAAO,CAAC,KAAK,CAAyB;IACtC,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,WAAW,CAA8C;IACjE;;;;;OAKG;IACH,SAAS,CAAC,uBAAuB,UAAS;IAG1C,IAAI,KAAK,IAAI,GAAG,CAEf;IAGD,IAAI,KAAK,CAAC,KAAK,EAAE,GAAG,EAEnB;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,EAErB;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,MAAM,EAEvB;IAED,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,IAAI,UAAU,CAAC,KAAK,EAAE,MAAM,EAE3B;IAED,IAAI,UAAU,IAAI,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,CAEpD;IAED,IAAI,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,EAGxD;IAED,OAAO;IAeP,QAAQ;;;;;CAUR;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"unprocessableEntity.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/unprocessableEntity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;;;;;;;;;GAYG;AACH,cAAM,mBAAoB,SAAQ,WAAW;IAC5C;;;;;OAKG;gBACS,KAAK,EAAE;QAElB,IAAI,CAAC,EAAE,GAAG,CAAC;QACX,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACrC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAChC,OAAO,CAAC,EAAE,MAAM,CAAC;KACjB;IAgBD,6EAA6E;IAC7E,UAAU,IAAI,QAAQ;IAUtB,uFAAuF;IACvF,MAAM,IAAI,QAAQ;CAQlB;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
1
+ {"version":3,"file":"unprocessableEntity.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/unprocessableEntity.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAoB7C;;;;;;;;;;;;GAYG;AACH,cAAM,mBAAoB,SAAQ,WAAW;IAC5C;;;;;OAKG;gBACS,KAAK,EAAE;QAElB,IAAI,CAAC,EAAE,GAAG,CAAC;QACX,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACrC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAChC,OAAO,CAAC,EAAE,MAAM,CAAC;KACjB;IAoBD,6EAA6E;IAC7E,UAAU,IAAI,QAAQ;IAUtB,uFAAuF;IACvF,MAAM,IAAI,QAAQ;CAQlB;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
package/dist/index.js CHANGED
@@ -59,6 +59,7 @@ var f = class {
59
59
  _status = 500;
60
60
  _statusText = "Unknown error";
61
61
  _debugColor = "red";
62
+ exposeCauseInProduction = !1;
62
63
  get cause() {
63
64
  return this._cause;
64
65
  }
@@ -103,10 +104,11 @@ var f = class {
103
104
  });
104
105
  }
105
106
  makeBody() {
107
+ let e = process.env.NODE_ENV === "production" && !this.exposeCauseInProduction;
106
108
  return {
107
109
  name: this._name,
108
110
  message: this._statusText,
109
- cause: this._cause
111
+ cause: e ? void 0 : this._cause
110
112
  };
111
113
  }
112
114
  }, p = class extends f {
@@ -261,12 +263,48 @@ var f = class {
261
263
  };
262
264
  return Response.json(this.makeBody(), e);
263
265
  }
264
- }, x = class extends f {
266
+ }, x = [
267
+ "password",
268
+ "Password",
269
+ "confirmPassword",
270
+ "ConfirmPassword",
271
+ "creditCard",
272
+ "CreditCard",
273
+ "authorization",
274
+ "Authorization",
275
+ "cookie",
276
+ "Cookie",
277
+ "set-cookie",
278
+ "Set-Cookie",
279
+ "setCookie",
280
+ "SetCookie",
281
+ "token",
282
+ "Token",
283
+ "refreshToken",
284
+ "RefreshToken",
285
+ "accessToken",
286
+ "AccessToken",
287
+ "apiKey",
288
+ "ApiKey",
289
+ "secret",
290
+ "Secret"
291
+ ];
292
+ //#endregion
293
+ //#region src/http/badResponses/unprocessableEntity.ts
294
+ function S(e) {
295
+ if (e === void 0) return e;
296
+ try {
297
+ return JSON.parse(r(JSON.stringify(e), [...x]));
298
+ } catch {
299
+ return e;
300
+ }
301
+ }
302
+ var C = class extends f {
265
303
  constructor(e) {
266
- super(), this.name = "UnprocessableEntity", this.status = 422, this.statusText = e.message || "Unprocessable entity", this.debugColor = "yellow", this.cause = {
267
- data: e.data,
304
+ super(), this.name = "UnprocessableEntity", this.status = 422, this.statusText = e.message || "Unprocessable entity", this.debugColor = "yellow", this.exposeCauseInProduction = !0, this.cause = {
305
+ data: S(e.data),
268
306
  fieldErrors: e.fieldErrors,
269
- fields: e.fields
307
+ fields: S(e.fields)
270
308
  }, this.onDebug();
271
309
  }
272
310
  toResponse() {
@@ -284,7 +322,7 @@ var f = class {
284
322
  };
285
323
  return Response.json(this.makeBody(), e);
286
324
  }
287
- }, S = class {
325
+ }, w = class {
288
326
  _body = null;
289
327
  _name = "SuccessResponse";
290
328
  _status = 200;
@@ -340,7 +378,7 @@ var f = class {
340
378
  body: this.body
341
379
  };
342
380
  }
343
- }, C = class extends S {
381
+ }, T = class extends w {
344
382
  constructor(e, t) {
345
383
  super(), this.name = "Created", this.status = 201, this.statusText = e, this.body = t || void 0, this.onDebug();
346
384
  }
@@ -359,7 +397,7 @@ var f = class {
359
397
  };
360
398
  return Response.json(this.body, e);
361
399
  }
362
- }, w = class extends S {
400
+ }, E = class extends w {
363
401
  constructor(e, t) {
364
402
  super(), this.name = "Found", this.status = 302, this.statusText = e, this.body = t || void 0, this.onDebug();
365
403
  }
@@ -378,7 +416,7 @@ var f = class {
378
416
  };
379
417
  return Response.json(this.body, e);
380
418
  }
381
- }, T = class extends S {
419
+ }, D = class extends w {
382
420
  constructor(e) {
383
421
  super(), this.name = "NoContent", this.status = 204, this.statusText = e, this.onDebug();
384
422
  }
@@ -390,7 +428,7 @@ var f = class {
390
428
  };
391
429
  return new Response(null, e);
392
430
  }
393
- }, E = class extends S {
431
+ }, O = class extends w {
394
432
  constructor(e, t) {
395
433
  super(), this.name = "Success", this.status = 200, this.statusText = e, this.body = t || void 0, this.onDebug();
396
434
  }
@@ -409,7 +447,7 @@ var f = class {
409
447
  };
410
448
  return Response.json(this.body, e);
411
449
  }
412
- }, D = class extends S {
450
+ }, k = class extends w {
413
451
  constructor(e, t) {
414
452
  super(), this.name = "Updated", this.status = 200, this.statusText = e, this.body = t || void 0, this.onDebug();
415
453
  }
@@ -428,7 +466,7 @@ var f = class {
428
466
  };
429
467
  return Response.json(this.body, e);
430
468
  }
431
- }, O = class e {
469
+ }, A = class e {
432
470
  static mapHeaders(e) {
433
471
  return e instanceof Headers ? Object.fromEntries(e.entries()) : typeof e == "object" ? Object.entries(e).reduce((e, [t, n]) => (typeof n == "string" ? e[t] = n : Array.isArray(n) ? e[t] = n.join(", ") : e[t] = JSON.stringify(n), e), {}) : {};
434
472
  }
@@ -455,7 +493,7 @@ var f = class {
455
493
  responseBody: t.responseBody || null
456
494
  };
457
495
  }
458
- }, k = class e {
496
+ }, j = class e {
459
497
  static config;
460
498
  static isSecureEndpoint(e) {
461
499
  return e.protocol === "https:" ? !0 : e.hostname === "localhost" || e.hostname === "127.0.0.1";
@@ -489,36 +527,11 @@ var f = class {
489
527
  static resetConfig() {
490
528
  e.config = void 0;
491
529
  }
492
- }, A = [
493
- "password",
494
- "Password",
495
- "confirmPassword",
496
- "ConfirmPassword",
497
- "creditCard",
498
- "CreditCard",
499
- "authorization",
500
- "Authorization",
501
- "cookie",
502
- "Cookie",
503
- "set-cookie",
504
- "Set-Cookie",
505
- "setCookie",
506
- "SetCookie",
507
- "token",
508
- "Token",
509
- "refreshToken",
510
- "RefreshToken",
511
- "accessToken",
512
- "AccessToken",
513
- "apiKey",
514
- "ApiKey",
515
- "secret",
516
- "Secret"
517
- ];
530
+ };
518
531
  //#endregion
519
532
  //#region src/http/api/_logRequest.ts
520
- async function j(e) {
521
- let n = k.getConfig();
533
+ async function M(e) {
534
+ let n = j.getConfig();
522
535
  if (!n) return;
523
536
  let { userToken: i, apiUrl: a, trafficSourceId: o } = n;
524
537
  if (!a) return;
@@ -535,11 +548,11 @@ async function j(e) {
535
548
  method: c.toLowerCase(),
536
549
  trafficUserId: null,
537
550
  elapsedTime: s,
538
- requestHeaders: r(JSON.stringify(f), [...A]),
539
- requestBody: r(JSON.stringify(u), [...A]),
551
+ requestHeaders: r(JSON.stringify(f), [...x]),
552
+ requestBody: r(JSON.stringify(u), [...x]),
540
553
  queryParams: JSON.stringify(l),
541
- responseHeaders: r(JSON.stringify(m), [...A]),
542
- responseBody: r(JSON.stringify(p), [...A])
554
+ responseHeaders: r(JSON.stringify(m), [...x]),
555
+ responseBody: r(JSON.stringify(p), [...x])
543
556
  }), v = {
544
557
  "Content-Type": "application/json",
545
558
  Authorization: `Bearer ${i}`
@@ -571,7 +584,7 @@ async function j(e) {
571
584
  }
572
585
  //#endregion
573
586
  //#region src/http/api/_makeRequest.ts
574
- async function M(e) {
587
+ async function N(e) {
575
588
  let t = e.url;
576
589
  e.urlParams && Object.entries(e.urlParams).forEach(([e, n]) => {
577
590
  t = t.replaceAll(`:${e}`, n);
@@ -597,7 +610,7 @@ async function M(e) {
597
610
  } catch {
598
611
  c = null;
599
612
  }
600
- return j(O.handle({
613
+ return M(A.handle({
601
614
  elapsedTime: o,
602
615
  method: e.method,
603
616
  queryParams: new URL(t).searchParams,
@@ -637,8 +650,8 @@ async function M(e) {
637
650
  }
638
651
  //#endregion
639
652
  //#region src/http/api/_deleteRequest.ts
640
- async function N(e) {
641
- return M({
653
+ async function P(e) {
654
+ return N({
642
655
  method: "DELETE",
643
656
  url: e.url,
644
657
  urlParams: e.urlParams,
@@ -649,7 +662,7 @@ async function N(e) {
649
662
  //#endregion
650
663
  //#region src/http/api/_getRequest.ts
651
664
  async function ee(e) {
652
- return M({
665
+ return N({
653
666
  method: "GET",
654
667
  url: e.url,
655
668
  urlParams: e.urlParams,
@@ -659,7 +672,7 @@ async function ee(e) {
659
672
  //#endregion
660
673
  //#region src/http/api/_patchRequest.ts
661
674
  async function te(e) {
662
- return M({
675
+ return N({
663
676
  method: "PATCH",
664
677
  url: e.url,
665
678
  urlParams: e.urlParams,
@@ -669,8 +682,8 @@ async function te(e) {
669
682
  }
670
683
  //#endregion
671
684
  //#region src/http/api/_postRequest.ts
672
- async function P(e) {
673
- return M({
685
+ async function F(e) {
686
+ return N({
674
687
  method: "POST",
675
688
  url: e.url,
676
689
  urlParams: e.urlParams,
@@ -680,8 +693,8 @@ async function P(e) {
680
693
  }
681
694
  //#endregion
682
695
  //#region src/http/api/_putRequest.ts
683
- async function F(e) {
684
- return M({
696
+ async function I(e) {
697
+ return N({
685
698
  method: "PUT",
686
699
  url: e.url,
687
700
  urlParams: e.urlParams,
@@ -691,7 +704,7 @@ async function F(e) {
691
704
  }
692
705
  //#endregion
693
706
  //#region src/services/apiService.ts
694
- var I = class e {
707
+ var L = class e {
695
708
  baseUrl;
696
709
  baseHeaders;
697
710
  baseToken;
@@ -703,7 +716,7 @@ var I = class e {
703
716
  return e instanceof Headers ? Object.fromEntries(e.entries()) : Object.fromEntries(new Headers(e).entries());
704
717
  }
705
718
  static toRedactedJson(e) {
706
- return r(JSON.stringify(e), [...A]);
719
+ return r(JSON.stringify(e), [...x]);
707
720
  }
708
721
  onDebug(t, n, r) {
709
722
  if (this.enableDebug) {
@@ -745,7 +758,7 @@ var I = class e {
745
758
  }), r;
746
759
  }
747
760
  async post(e, t) {
748
- let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await P({
761
+ let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await F({
749
762
  url: this.baseUrl + e,
750
763
  urlParams: t?.urlParams || {},
751
764
  headers: n,
@@ -759,7 +772,7 @@ var I = class e {
759
772
  }), i;
760
773
  }
761
774
  async put(e, t) {
762
- let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await F({
775
+ let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await I({
763
776
  url: this.baseUrl + e,
764
777
  urlParams: t?.urlParams || {},
765
778
  headers: n,
@@ -787,7 +800,7 @@ var I = class e {
787
800
  }), i;
788
801
  }
789
802
  async delete(e, t) {
790
- let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await N({
803
+ let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await P({
791
804
  url: this.baseUrl + e,
792
805
  urlParams: t?.urlParams || {},
793
806
  headers: n,
@@ -800,40 +813,42 @@ var I = class e {
800
813
  status: i.status
801
814
  }), i;
802
815
  }
803
- };
804
- //#endregion
805
- //#region src/utilities/decodeRequestBody.ts
806
- async function L(e) {
807
- let t, n = await e.arrayBuffer(), r = new TextDecoder().decode(n);
816
+ }, R = 5 * 1024 * 1024;
817
+ async function z(e, t) {
818
+ let n, r = t?.maxBodySizeBytes ?? R, i = Number(e.headers.get("content-length"));
819
+ if (Number.isFinite(i) && i > r) throw new m("Request body exceeds the maximum allowed size");
820
+ let a = await e.arrayBuffer();
821
+ if (a.byteLength > r) throw new m("Request body exceeds the maximum allowed size");
822
+ let o = new TextDecoder().decode(a);
808
823
  try {
809
- t = JSON.parse(r);
824
+ n = JSON.parse(o);
810
825
  } catch {
811
826
  try {
812
- if (r.includes("=")) {
813
- let e = new URLSearchParams(r);
814
- t = Object.fromEntries(e.entries());
827
+ if (o.includes("=")) {
828
+ let e = new URLSearchParams(o);
829
+ n = Object.fromEntries(e.entries());
815
830
  } else throw new m("Invalid URLSearchParams format");
816
831
  } catch {
817
832
  throw new m("Failed to extract data from request");
818
833
  }
819
834
  }
820
- return t;
835
+ return n;
821
836
  }
822
837
  //#endregion
823
838
  //#region src/utilities/decodeRequestErrorMessage.ts
824
- function R(e, t) {
839
+ function B(e, t) {
825
840
  return e?.message && typeof e?.message == "string" ? e?.message : e?.operator_erro_message && typeof e?.operator_erro_message == "string" ? e?.operator_erro_message : e?.error && typeof e?.error == "string" ? e?.error : e?.error?.message && typeof e?.error?.message == "string" ? e?.error?.message : t?.statusText && typeof t?.statusText == "string" ? t?.statusText : "Missing error message";
826
841
  }
827
842
  //#endregion
828
843
  //#region src/utilities/errorHandler.ts
829
- function z(e) {
844
+ function V(e) {
830
845
  switch (!0) {
831
846
  case e instanceof Response: return e;
832
- case e instanceof w: return e.toResponse();
833
- case e instanceof C: return e.toResponse();
834
- case e instanceof D: return e.toResponse();
835
847
  case e instanceof E: return e.toResponse();
836
848
  case e instanceof T: return e.toResponse();
849
+ case e instanceof k: return e.toResponse();
850
+ case e instanceof O: return e.toResponse();
851
+ case e instanceof D: return e.toResponse();
837
852
  }
838
853
  switch (!0) {
839
854
  case e instanceof p: return e.toResponse();
@@ -844,13 +859,13 @@ function z(e) {
844
859
  case e instanceof v: return e.toResponse();
845
860
  case e instanceof y: return e.toResponse();
846
861
  case e instanceof b: return e.toResponse();
847
- case e instanceof x: return e.toResponse();
862
+ case e instanceof C: return e.toResponse();
848
863
  }
849
864
  return new y("Server error", e).toResponse();
850
865
  }
851
866
  //#endregion
852
867
  //#region src/utilities/formAsyncParse.ts
853
- async function B([e, t]) {
868
+ async function H([e, t]) {
854
869
  let n = await t.safeParseAsync(e);
855
870
  return n.success === !1 ? {
856
871
  success: !1,
@@ -863,7 +878,7 @@ async function B([e, t]) {
863
878
  }
864
879
  //#endregion
865
880
  //#region src/utilities/formParse.ts
866
- function V([e, t]) {
881
+ function U([e, t]) {
867
882
  let n = t.safeParse(e);
868
883
  return n.success === !1 ? {
869
884
  success: !1,
@@ -876,7 +891,7 @@ function V([e, t]) {
876
891
  }
877
892
  //#endregion
878
893
  //#region src/utilities/getScopedParams.ts
879
- function H(e, t = "") {
894
+ function W(e, t = "") {
880
895
  let n = new URL(e.url);
881
896
  if (t === "") return n.searchParams;
882
897
  let r = Array.from(n.searchParams.entries()).filter(([e]) => e.startsWith(`${t}:`)).map(([e, n]) => [e.replace(`${t}:`, ""), n]);
@@ -884,10 +899,10 @@ function H(e, t = "") {
884
899
  }
885
900
  //#endregion
886
901
  //#region src/utilities/schemaValidator.ts
887
- function U(e) {
902
+ function G(e) {
888
903
  return ["Error validating:", ...e.issues.map(({ path: e, message: t }) => `-> ${e.join(".")}: ${t}`)].join("\n");
889
904
  }
890
- var W = class {
905
+ var K = class {
891
906
  schema;
892
907
  constructor(e) {
893
908
  this.schema = e;
@@ -902,14 +917,14 @@ var W = class {
902
917
  try {
903
918
  return this.schema.parse(e);
904
919
  } catch (e) {
905
- throw new y(U(e));
920
+ throw new y(G(e));
906
921
  }
907
922
  }
908
923
  formValidate(e, t) {
909
- let n = V([e, this.schema]);
924
+ let n = U([e, this.schema]);
910
925
  if ("fieldErrors" in n) {
911
926
  let e = Object.keys(n.fieldErrors)[0];
912
- throw new x({
927
+ throw new C({
913
928
  fields: n.fields,
914
929
  fieldErrors: n.fieldErrors,
915
930
  data: { scrollTo: e },
@@ -919,10 +934,10 @@ var W = class {
919
934
  return n.data;
920
935
  }
921
936
  async formAsyncValidate(e, t) {
922
- let n = await B([e, this.schema]);
937
+ let n = await H([e, this.schema]);
923
938
  if ("fieldErrors" in n) {
924
939
  let e = Object.keys(n.fieldErrors)[0];
925
- throw new x({
940
+ throw new C({
926
941
  fields: n.fields,
927
942
  fieldErrors: n.fieldErrors,
928
943
  data: { scrollTo: e },
@@ -934,34 +949,34 @@ var W = class {
934
949
  };
935
950
  //#endregion
936
951
  //#region src/validations/validateCep.ts
937
- function G(e) {
952
+ function q(e) {
938
953
  if (!(/^\d{5}-\d{3}$/.test(e) || /^\d{8}$/.test(e))) return !1;
939
954
  let t = i(e), n = /^\d{8}$/.test(t);
940
955
  return t.length === 8 && n;
941
956
  }
942
957
  //#endregion
943
958
  //#region src/validations/validateCnpj.ts
944
- function K(e) {
959
+ function J(e) {
945
960
  return e.length !== 14;
946
961
  }
947
- function q(e) {
962
+ function Y(e) {
948
963
  let [t] = e;
949
964
  return [...e].every((e) => e === t);
950
965
  }
951
- function J(e, t) {
966
+ function X(e, t) {
952
967
  let n = 0;
953
968
  for (let r = 0; r < t.length; r++) n += parseInt(e[r], 10) * t[r];
954
969
  let r = n % 11;
955
970
  return r < 2 ? 0 : 11 - r;
956
971
  }
957
- function Y(e) {
972
+ function ne(e) {
958
973
  return e.slice(12);
959
974
  }
960
- function ne(e) {
975
+ function Z(e) {
961
976
  if (!e || e.length > 18 || e.length < 14 || /\s/.test(e)) return !1;
962
977
  let t = i(e);
963
- if (K(t) || q(t)) return !1;
964
- let n = t.slice(0, 12), r = J(n, [
978
+ if (J(t) || Y(t)) return !1;
979
+ let n = t.slice(0, 12), r = X(n, [
965
980
  5,
966
981
  4,
967
982
  3,
@@ -974,7 +989,7 @@ function ne(e) {
974
989
  4,
975
990
  3,
976
991
  2
977
- ]), a = J(n + r, [
992
+ ]), a = X(n + r, [
978
993
  6,
979
994
  5,
980
995
  4,
@@ -989,14 +1004,14 @@ function ne(e) {
989
1004
  3,
990
1005
  2
991
1006
  ]);
992
- return Y(t) === `${r}${a}`;
1007
+ return ne(t) === `${r}${a}`;
993
1008
  }
994
1009
  //#endregion
995
1010
  //#region src/validations/validateCpf.ts
996
- function X(e) {
1011
+ function re(e) {
997
1012
  return e.length !== 11;
998
1013
  }
999
- function Z(e) {
1014
+ function ie(e) {
1000
1015
  let [t] = e;
1001
1016
  return [...e].every((e) => e === t);
1002
1017
  }
@@ -1006,19 +1021,19 @@ function Q(e, t) {
1006
1021
  let r = n % 11;
1007
1022
  return r < 2 ? 0 : 11 - r;
1008
1023
  }
1009
- function re(e) {
1024
+ function ae(e) {
1010
1025
  return e.slice(9);
1011
1026
  }
1012
- function ie(e) {
1027
+ function oe(e) {
1013
1028
  if (!e || e.length > 14 || e.length < 11 || /\s/.test(e)) return !1;
1014
1029
  let t = i(e);
1015
- if (X(t) || Z(t)) return !1;
1030
+ if (re(t) || ie(t)) return !1;
1016
1031
  let n = Q(t, 10), r = Q(t, 11);
1017
- return re(t) === `${n}${r}`;
1032
+ return ae(t) === `${n}${r}`;
1018
1033
  }
1019
1034
  //#endregion
1020
1035
  //#region src/validations/validateDate.ts
1021
- function ae(t, n) {
1036
+ function se(t, n) {
1022
1037
  let r = n?.inputFormat || "brazilianDate", i = n?.minYear || 1900, a = n?.maxYear || 3e3, o = new e();
1023
1038
  o.validateInputFormat(r);
1024
1039
  let s, c, l, u = t.split(/[-/]/).map(Number);
@@ -1042,59 +1057,64 @@ function ae(t, n) {
1042
1057
  }
1043
1058
  //#endregion
1044
1059
  //#region src/validations/validateEmail.ts
1045
- function oe(e) {
1060
+ function ce(e) {
1046
1061
  return /^[a-zA-Z0-9.!$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(e);
1047
1062
  }
1048
- function se(e) {
1063
+ function le(e) {
1049
1064
  return !(e.length === 0 || e.length > 64 || e.startsWith(".") || e.endsWith(".") || e.includes("..") || !/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/.test(e));
1050
1065
  }
1051
- function ce(e) {
1066
+ function ue(e) {
1052
1067
  return !(e.length === 0 || e.length > 63 || e.startsWith("-") || e.endsWith("-") || !/^[a-zA-Z0-9-]+$/.test(e));
1053
1068
  }
1054
- function le(e) {
1069
+ function de(e) {
1055
1070
  if (e.length === 0 || e.length > 253 || e.startsWith(".") || e.endsWith(".") || e.startsWith("-") || e.endsWith("-")) return !1;
1056
1071
  let t = e.split(".");
1057
1072
  if (t.length < 2) return !1;
1058
- for (let e of t) if (!ce(e)) return !1;
1073
+ for (let e of t) if (!ue(e)) return !1;
1059
1074
  let n = t[t.length - 1];
1060
1075
  return !(n.length < 2 || !/^[a-zA-Z]+$/.test(n));
1061
1076
  }
1062
- function ue(e) {
1077
+ function fe(e) {
1063
1078
  let t = e.split("@");
1064
1079
  if (t.length !== 2) return !1;
1065
1080
  let [n, r] = t;
1066
- return !(!se(n) || !le(r));
1081
+ return !(!le(n) || !de(r));
1067
1082
  }
1068
- function de(e) {
1083
+ function pe(e) {
1069
1084
  let t = e.split("@");
1070
1085
  return t.length === 2 ? t[1].toLowerCase() : null;
1071
1086
  }
1072
- var fe = [
1087
+ var $ = [
1073
1088
  "MX",
1074
1089
  "A",
1075
1090
  "AAAA"
1076
- ];
1077
- async function pe(e, t) {
1078
- try {
1079
- return await o?.promises?.resolve(e, t), !0;
1080
- } catch {
1081
- return !1;
1082
- }
1091
+ ], me = 5e3;
1092
+ async function he(e, t, n) {
1093
+ return new Promise((r) => {
1094
+ let i = !1, a = setTimeout(() => {
1095
+ i || (i = !0, r(!1));
1096
+ }, n);
1097
+ a.unref?.(), o.promises.resolve(e, t).then(() => {
1098
+ i || (i = !0, clearTimeout(a), r(!0));
1099
+ }).catch(() => {
1100
+ i || (i = !0, clearTimeout(a), r(!1));
1101
+ });
1102
+ });
1083
1103
  }
1084
- async function $(e) {
1085
- for (let t of fe) if (await pe(e, t)) return !0;
1104
+ async function ge(e, t) {
1105
+ for (let n of $) if (await he(e, n, t)) return !0;
1086
1106
  return !1;
1087
1107
  }
1088
- async function me(e) {
1108
+ async function _e(e, t) {
1089
1109
  if (!e || typeof e != "string") return !1;
1090
- let t = e.trim();
1091
- if (!oe(t) || !ue(t)) return !1;
1092
- let n = de(t);
1093
- return n ? await $(n) : !1;
1110
+ let n = e.trim();
1111
+ if (!ce(n) || !fe(n)) return !1;
1112
+ let r = pe(n);
1113
+ return r ? await ge(r, t?.dnsTimeoutMs ?? me) : !1;
1094
1114
  }
1095
1115
  //#endregion
1096
1116
  //#region src/validations/validatePassword.ts
1097
- function he(e) {
1117
+ function ve(e) {
1098
1118
  return e ? [
1099
1119
  e.length >= 8,
1100
1120
  /[A-Z]/.test(e),
@@ -1105,19 +1125,19 @@ function he(e) {
1105
1125
  }
1106
1126
  //#endregion
1107
1127
  //#region src/validations/validatePhone.ts
1108
- function ge(e) {
1128
+ function ye(e) {
1109
1129
  if (!c(e)) return !1;
1110
1130
  let t = l(e)?.country;
1111
1131
  return !(!t || !s.find((e) => e.iso === t));
1112
1132
  }
1113
1133
  //#endregion
1114
1134
  //#region src/validations/validateRg.ts
1115
- function _e(e) {
1135
+ function be(e) {
1116
1136
  if (!e || !/^[0-9a-zA-Z.-]+$/.test(e)) return !1;
1117
1137
  let t = e.replace(/[^a-zA-Z0-9]/g, "");
1118
1138
  return t.length < 7 || t.length > 9 ? !1 : /^[0-9]{7,8}[0-9Xx]?$/.test(t);
1119
1139
  }
1120
1140
  //#endregion
1121
- export { I as ApiService, p as BadGateway, m as BadRequest, h as Conflict, C as Created, u as DebugService, g as Forbidden, w as Found, k as LogService, T as NoContent, _ as NotFound, v as NotImplemented, W as SchemaValidator, y as ServerError, E as Success, b as Unauthorized, x as UnprocessableEntity, D as Updated, L as decodeRequestBody, R as decodeRequestErrorMessage, z as errorHandler, d as flushDebugLogs, B as formAsyncParse, V as formParse, H as getScopedParams, G as validateCep, ne as validateCnpj, ie as validateCpf, ae as validateDate, me as validateEmail, he as validatePassword, ge as validatePhone, _e as validateRg };
1141
+ export { L as ApiService, p as BadGateway, m as BadRequest, h as Conflict, T as Created, u as DebugService, g as Forbidden, E as Found, j as LogService, D as NoContent, _ as NotFound, v as NotImplemented, K as SchemaValidator, y as ServerError, O as Success, b as Unauthorized, C as UnprocessableEntity, k as Updated, z as decodeRequestBody, B as decodeRequestErrorMessage, V as errorHandler, d as flushDebugLogs, H as formAsyncParse, U as formParse, W as getScopedParams, q as validateCep, Z as validateCnpj, oe as validateCpf, se as validateDate, _e as validateEmail, ve as validatePassword, ye as validatePhone, be as validateRg };
1122
1142
 
1123
1143
  //# sourceMappingURL=index.js.map