@navservice/core 1.127.0 → 1.129.0

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.
@@ -6,6 +6,7 @@ declare class _secret {
6
6
  password: string;
7
7
  dashed_senha: string;
8
8
  }): Promise<boolean>;
9
+ estract_secret(secret: any): Promise<string>;
9
10
  }
10
11
  declare const _default: _secret;
11
12
  export default _default;
@@ -229,6 +229,7 @@ declare const helpers: {
229
229
  password: string;
230
230
  dashed_senha: string;
231
231
  }): Promise<boolean>;
232
+ estract_secret(secret: any): Promise<string>;
232
233
  };
233
234
  data: {
234
235
  get get_now_format_number(): number;
@@ -507,6 +507,33 @@ const set_response = new class {
507
507
  };
508
508
  };
509
509
  const _set_response = set_response;
510
+ const scryptAsync = promisify(scrypt);
511
+ class _secret {
512
+ SALT_LENGTH = 22;
513
+ KEY_LENGTH = 35;
514
+ async gerar_hash_senha(password) {
515
+ const salt = randomBytes(this.SALT_LENGTH);
516
+ const derivedKey = await scryptAsync(password, salt, this.KEY_LENGTH);
517
+ return salt.toString('base64') + '.' + derivedKey.toString('base64');
518
+ }
519
+ async verify({ password, dashed_senha }) {
520
+ try {
521
+ const [saltBase64, hashBase64] = dashed_senha.split('.');
522
+ if (!saltBase64 || !hashBase64) return false;
523
+ const salt = Buffer.from(saltBase64, 'base64');
524
+ const storedHash = Buffer.from(hashBase64, 'base64');
525
+ const derivedKey = await scryptAsync(password, salt, this.KEY_LENGTH);
526
+ return timingSafeEqual(storedHash, derivedKey);
527
+ } catch {
528
+ return false;
529
+ }
530
+ }
531
+ async estract_secret(secret) {
532
+ if ('string' == typeof secret) return secret;
533
+ return await secret?.get() || "";
534
+ }
535
+ }
536
+ const helpers_secret = new _secret;
510
537
  const _token_fn = 'token';
511
538
  const _token = new class {
512
539
  async verificar_token(c, next) {
@@ -525,7 +552,7 @@ const _token = new class {
525
552
  results: [],
526
553
  fn: _token_fn
527
554
  });
528
- const secret = new TextEncoder().encode(await c.env.JSON_WEB_TOKEN_AUTH_USER.get());
555
+ const secret = new TextEncoder().encode(await helpers_secret.estract_secret(c?.env?.JSON_WEB_TOKEN_AUTH_USER));
529
556
  const { payload } = await jwtVerify(token, secret);
530
557
  if (!payload._id || !payload.email) return _set_response.c.INVALID_TOKEN({
531
558
  message: 'Token inválido!!!!',
@@ -557,7 +584,7 @@ const _token = new class {
557
584
  }
558
585
  }
559
586
  async criar_token_login_usuario(props) {
560
- if (!props?.c.env.JSON_WEB_TOKEN_AUTH_USER) _set_response.error.WARNING({
587
+ if (await helpers_secret.estract_secret(props?.c?.env?.JSON_WEB_TOKEN_AUTH_USER)) _set_response.error.WARNING({
561
588
  message: "Erro ao gerar token auth!!",
562
589
  results: [],
563
590
  fn: _token_fn
@@ -574,7 +601,7 @@ const _token = new class {
574
601
  plano_status: props?.plano_status
575
602
  }).setProtectedHeader({
576
603
  alg: "HS256"
577
- }).setIssuedAt().setExpirationTime("1h").sign(new TextEncoder().encode(await props?.c.env.JSON_WEB_TOKEN_AUTH_USER.get())).catch((error)=>_set_response.error.TOKEN_AUTH_USER({
604
+ }).setIssuedAt().setExpirationTime("1h").sign(new TextEncoder().encode(await helpers_secret.estract_secret(props?.c?.env?.JSON_WEB_TOKEN_AUTH_USER))).catch((error)=>_set_response.error.TOKEN_AUTH_USER({
578
605
  message: "Erro ao gerar token auth user!",
579
606
  results: error?.message,
580
607
  fn: _token_fn
@@ -597,7 +624,7 @@ const _token = new class {
597
624
  results: [],
598
625
  fn: _token_fn
599
626
  });
600
- const secret = new TextEncoder().encode(await c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO.get());
627
+ const secret = new TextEncoder().encode(await helpers_secret.estract_secret(c?.env?.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO));
601
628
  const { payload } = await jwtVerify(token, secret);
602
629
  if (!payload._id || !payload.email) return _set_response.c.INVALID_TOKEN({
603
630
  message: 'Token inválido para o serviço!',
@@ -628,7 +655,7 @@ const _token = new class {
628
655
  }
629
656
  }
630
657
  async criar_token_micro_servico({ c }) {
631
- if (!c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO) _set_response.error.WARNING({
658
+ if (!await helpers_secret.estract_secret(c?.env?.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO)) _set_response.error.WARNING({
632
659
  message: "Erro ao gerar token!!",
633
660
  results: [],
634
661
  fn: _token_fn
@@ -646,7 +673,7 @@ const _token = new class {
646
673
  plano_status: usuario_auth?.plano_status
647
674
  }).setProtectedHeader({
648
675
  alg: "HS256"
649
- }).setIssuedAt().setExpirationTime("30s").sign(new TextEncoder().encode(await c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO.get())).catch((error)=>_set_response.error.TOKEN_AUTH_USER({
676
+ }).setIssuedAt().setExpirationTime("30s").sign(new TextEncoder().encode(await helpers_secret.estract_secret(c?.env?.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO))).catch((error)=>_set_response.error.TOKEN_AUTH_USER({
650
677
  message: "Erro ao gerar token micro serviço!",
651
678
  results: error?.message,
652
679
  fn: _token_fn
@@ -654,7 +681,7 @@ const _token = new class {
654
681
  return token;
655
682
  }
656
683
  async criar_refresh_token({ env, usuario_id }) {
657
- if (!env.JSON_WEB_REFRESH_TOKEN_AUTH_USER) _set_response.error.TOKEN_AUTH_USER({
684
+ if (!await helpers_secret.estract_secret(env?.JSON_WEB_REFRESH_TOKEN_AUTH_USER)) _set_response.error.TOKEN_AUTH_USER({
658
685
  message: "Erro ao gerar refresh token!!",
659
686
  results: [],
660
687
  fn: _token_fn
@@ -663,7 +690,7 @@ const _token = new class {
663
690
  usuario_id: usuario_id
664
691
  }).setProtectedHeader({
665
692
  alg: "HS256"
666
- }).setIssuedAt().setExpirationTime("2h").sign(new TextEncoder().encode(await env.JSON_WEB_REFRESH_TOKEN_AUTH_USER?.get())).catch((error)=>_set_response.error.TOKEN_AUTH_USER({
693
+ }).setIssuedAt().setExpirationTime("2h").sign(new TextEncoder().encode(await helpers_secret.estract_secret(env?.JSON_WEB_REFRESH_TOKEN_AUTH_USER))).catch((error)=>_set_response.error.TOKEN_AUTH_USER({
667
694
  message: "Erro ao gerar refresh token!",
668
695
  fn: _token_fn
669
696
  }));
@@ -671,7 +698,7 @@ const _token = new class {
671
698
  }
672
699
  async verificar_refresh_token({ env, refresh_token }) {
673
700
  try {
674
- const secret_verify = new TextEncoder().encode(await env.JSON_WEB_REFRESH_TOKEN_AUTH_USER?.get());
701
+ const secret_verify = new TextEncoder().encode(await helpers_secret.estract_secret(env?.JSON_WEB_REFRESH_TOKEN_AUTH_USER));
675
702
  const { payload } = await jwtVerify(refresh_token, secret_verify);
676
703
  return payload;
677
704
  } catch (error) {
@@ -680,29 +707,6 @@ const _token = new class {
680
707
  }
681
708
  };
682
709
  const helpers_token = _token;
683
- const scryptAsync = promisify(scrypt);
684
- class _secret {
685
- SALT_LENGTH = 22;
686
- KEY_LENGTH = 35;
687
- async gerar_hash_senha(password) {
688
- const salt = randomBytes(this.SALT_LENGTH);
689
- const derivedKey = await scryptAsync(password, salt, this.KEY_LENGTH);
690
- return salt.toString('base64') + '.' + derivedKey.toString('base64');
691
- }
692
- async verify({ password, dashed_senha }) {
693
- try {
694
- const [saltBase64, hashBase64] = dashed_senha.split('.');
695
- if (!saltBase64 || !hashBase64) return false;
696
- const salt = Buffer.from(saltBase64, 'base64');
697
- const storedHash = Buffer.from(hashBase64, 'base64');
698
- const derivedKey = await scryptAsync(password, salt, this.KEY_LENGTH);
699
- return timingSafeEqual(storedHash, derivedKey);
700
- } catch {
701
- return false;
702
- }
703
- }
704
- }
705
- const helpers_secret = new _secret;
706
710
  class _data {
707
711
  get get_now_format_number() {
708
712
  return Math.floor(Date.now() / 1000);
@@ -6,6 +6,7 @@ declare class _secret {
6
6
  password: string;
7
7
  dashed_senha: string;
8
8
  }): Promise<boolean>;
9
+ estract_secret(secret: any): Promise<string>;
9
10
  }
10
11
  declare const _default: _secret;
11
12
  export default _default;
@@ -229,6 +229,7 @@ declare const helpers: {
229
229
  password: string;
230
230
  dashed_senha: string;
231
231
  }): Promise<boolean>;
232
+ estract_secret(secret: any): Promise<string>;
232
233
  };
233
234
  data: {
234
235
  get get_now_format_number(): number;
@@ -579,10 +579,46 @@ const set_response = new class set_response {
579
579
 
580
580
  ;// CONCATENATED MODULE: external "jose"
581
581
  const external_jose_namespaceObject = require("jose");
582
+ ;// CONCATENATED MODULE: external "node:crypto"
583
+ const external_node_crypto_namespaceObject = require("node:crypto");
584
+ ;// CONCATENATED MODULE: external "node:util"
585
+ const external_node_util_namespaceObject = require("node:util");
586
+ ;// CONCATENATED MODULE: ./src/helpers/_secret.ts
587
+
588
+
589
+ const scryptAsync = (0,external_node_util_namespaceObject.promisify)(external_node_crypto_namespaceObject.scrypt);
590
+ class _secret {
591
+ SALT_LENGTH = 22;
592
+ KEY_LENGTH = 35;
593
+ async gerar_hash_senha(password) {
594
+ const salt = (0,external_node_crypto_namespaceObject.randomBytes)(this.SALT_LENGTH);
595
+ const derivedKey = await scryptAsync(password, salt, this.KEY_LENGTH);
596
+ return salt.toString('base64') + '.' + derivedKey.toString('base64');
597
+ }
598
+ async verify({ password, dashed_senha }) {
599
+ try {
600
+ const [saltBase64, hashBase64] = dashed_senha.split('.');
601
+ if (!saltBase64 || !hashBase64) return false;
602
+ const salt = Buffer.from(saltBase64, 'base64');
603
+ const storedHash = Buffer.from(hashBase64, 'base64');
604
+ const derivedKey = await scryptAsync(password, salt, this.KEY_LENGTH);
605
+ return (0,external_node_crypto_namespaceObject.timingSafeEqual)(storedHash, derivedKey);
606
+ } catch {
607
+ return false;
608
+ }
609
+ }
610
+ async estract_secret(secret) {
611
+ if (typeof secret === 'string') return secret;
612
+ return await secret?.get() || "";
613
+ }
614
+ }
615
+ /* export default */ const helpers_secret = (new _secret);
616
+
582
617
  ;// CONCATENATED MODULE: ./src/helpers/_token.ts
583
618
 
584
619
  // Tem que importar assim para evitar dependencia circular
585
620
 
621
+
586
622
  const _token_fn = 'token';
587
623
  const _token = new class _token {
588
624
  async verificar_token(c, next) {
@@ -601,7 +637,7 @@ const _token = new class _token {
601
637
  results: [],
602
638
  fn: _token_fn
603
639
  });
604
- const secret = new TextEncoder().encode(await c.env.JSON_WEB_TOKEN_AUTH_USER.get());
640
+ const secret = new TextEncoder().encode(await helpers_secret.estract_secret(c?.env?.JSON_WEB_TOKEN_AUTH_USER));
605
641
  const { payload } = await external_jose_namespaceObject.jwtVerify(token, secret);
606
642
  if (!payload._id || !payload.email) {
607
643
  return _set_response.c.INVALID_TOKEN({
@@ -635,7 +671,7 @@ const _token = new class _token {
635
671
  }
636
672
  }
637
673
  async criar_token_login_usuario(props) {
638
- if (!props?.c.env.JSON_WEB_TOKEN_AUTH_USER) {
674
+ if (await helpers_secret.estract_secret(props?.c?.env?.JSON_WEB_TOKEN_AUTH_USER)) {
639
675
  _set_response.error.WARNING({
640
676
  message: "Erro ao gerar token auth!!",
641
677
  results: [],
@@ -654,7 +690,7 @@ const _token = new class _token {
654
690
  plano_status: props?.plano_status
655
691
  }).setProtectedHeader({
656
692
  alg: "HS256"
657
- }).setIssuedAt().setExpirationTime("1h").sign(new TextEncoder().encode(await props?.c.env.JSON_WEB_TOKEN_AUTH_USER.get())).catch((error)=>{
693
+ }).setIssuedAt().setExpirationTime("1h").sign(new TextEncoder().encode(await helpers_secret.estract_secret(props?.c?.env?.JSON_WEB_TOKEN_AUTH_USER))).catch((error)=>{
658
694
  return _set_response.error.TOKEN_AUTH_USER({
659
695
  message: "Erro ao gerar token auth user!",
660
696
  results: error?.message,
@@ -679,7 +715,7 @@ const _token = new class _token {
679
715
  results: [],
680
716
  fn: _token_fn
681
717
  });
682
- const secret = new TextEncoder().encode(await c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO.get());
718
+ const secret = new TextEncoder().encode(await helpers_secret.estract_secret(c?.env?.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO));
683
719
  const { payload } = await external_jose_namespaceObject.jwtVerify(token, secret);
684
720
  if (!payload._id || !payload.email) {
685
721
  return _set_response.c.INVALID_TOKEN({
@@ -712,7 +748,7 @@ const _token = new class _token {
712
748
  }
713
749
  }
714
750
  async criar_token_micro_servico({ c }) {
715
- if (!c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO) {
751
+ if (!await helpers_secret.estract_secret(c?.env?.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO)) {
716
752
  _set_response.error.WARNING({
717
753
  message: "Erro ao gerar token!!",
718
754
  results: [],
@@ -732,7 +768,7 @@ const _token = new class _token {
732
768
  plano_status: usuario_auth?.plano_status
733
769
  }).setProtectedHeader({
734
770
  alg: "HS256"
735
- }).setIssuedAt().setExpirationTime("30s").sign(new TextEncoder().encode(await c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO.get())).catch((error)=>{
771
+ }).setIssuedAt().setExpirationTime("30s").sign(new TextEncoder().encode(await helpers_secret.estract_secret(c?.env?.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO))).catch((error)=>{
736
772
  return _set_response.error.TOKEN_AUTH_USER({
737
773
  message: "Erro ao gerar token micro serviço!",
738
774
  results: error?.message,
@@ -742,7 +778,7 @@ const _token = new class _token {
742
778
  return token;
743
779
  }
744
780
  async criar_refresh_token({ env, usuario_id }) {
745
- if (!env.JSON_WEB_REFRESH_TOKEN_AUTH_USER) {
781
+ if (!await helpers_secret.estract_secret(env?.JSON_WEB_REFRESH_TOKEN_AUTH_USER)) {
746
782
  _set_response.error.TOKEN_AUTH_USER({
747
783
  message: "Erro ao gerar refresh token!!",
748
784
  results: [],
@@ -753,7 +789,7 @@ const _token = new class _token {
753
789
  usuario_id: usuario_id
754
790
  }).setProtectedHeader({
755
791
  alg: "HS256"
756
- }).setIssuedAt().setExpirationTime("2h").sign(new TextEncoder().encode(await env.JSON_WEB_REFRESH_TOKEN_AUTH_USER?.get())).catch((error)=>{
792
+ }).setIssuedAt().setExpirationTime("2h").sign(new TextEncoder().encode(await helpers_secret.estract_secret(env?.JSON_WEB_REFRESH_TOKEN_AUTH_USER))).catch((error)=>{
757
793
  return _set_response.error.TOKEN_AUTH_USER({
758
794
  message: "Erro ao gerar refresh token!",
759
795
  fn: _token_fn
@@ -764,7 +800,7 @@ const _token = new class _token {
764
800
  async verificar_refresh_token({ env, refresh_token }) {
765
801
  try {
766
802
  if (!refresh_token) false;
767
- const secret_verify = new TextEncoder().encode(await env.JSON_WEB_REFRESH_TOKEN_AUTH_USER?.get());
803
+ const secret_verify = new TextEncoder().encode(await helpers_secret.estract_secret(env?.JSON_WEB_REFRESH_TOKEN_AUTH_USER));
768
804
  const { payload } = await external_jose_namespaceObject.jwtVerify(refresh_token, secret_verify);
769
805
  return payload;
770
806
  } catch (error) {
@@ -774,37 +810,6 @@ const _token = new class _token {
774
810
  };
775
811
  /* export default */ const helpers_token = (_token);
776
812
 
777
- ;// CONCATENATED MODULE: external "node:crypto"
778
- const external_node_crypto_namespaceObject = require("node:crypto");
779
- ;// CONCATENATED MODULE: external "node:util"
780
- const external_node_util_namespaceObject = require("node:util");
781
- ;// CONCATENATED MODULE: ./src/helpers/_secret.ts
782
-
783
-
784
- const scryptAsync = (0,external_node_util_namespaceObject.promisify)(external_node_crypto_namespaceObject.scrypt);
785
- class _secret {
786
- SALT_LENGTH = 22;
787
- KEY_LENGTH = 35;
788
- async gerar_hash_senha(password) {
789
- const salt = (0,external_node_crypto_namespaceObject.randomBytes)(this.SALT_LENGTH);
790
- const derivedKey = await scryptAsync(password, salt, this.KEY_LENGTH);
791
- return salt.toString('base64') + '.' + derivedKey.toString('base64');
792
- }
793
- async verify({ password, dashed_senha }) {
794
- try {
795
- const [saltBase64, hashBase64] = dashed_senha.split('.');
796
- if (!saltBase64 || !hashBase64) return false;
797
- const salt = Buffer.from(saltBase64, 'base64');
798
- const storedHash = Buffer.from(hashBase64, 'base64');
799
- const derivedKey = await scryptAsync(password, salt, this.KEY_LENGTH);
800
- return (0,external_node_crypto_namespaceObject.timingSafeEqual)(storedHash, derivedKey);
801
- } catch {
802
- return false;
803
- }
804
- }
805
- }
806
- /* export default */ const helpers_secret = (new _secret);
807
-
808
813
  ;// CONCATENATED MODULE: ./src/helpers/_data.ts
809
814
  class _data {
810
815
  get get_now_format_number() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navservice/core",
3
- "version": "1.127.0",
3
+ "version": "1.129.0",
4
4
  "description": "Service core de todos os micro serviços",
5
5
  "type": "module",
6
6
  "exports": {