@navservice/core 1.105.0 → 1.106.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.
@@ -21,5 +21,13 @@ declare const _token: {
21
21
  criar_token_micro_servico({ c }: {
22
22
  c: t.Context;
23
23
  }): Promise<string>;
24
+ criar_refresh_token({ env, usuario_id }: {
25
+ env: t.Env["Bindings"];
26
+ usuario_id: string;
27
+ }): Promise<string>;
28
+ verificar_refresh_token({ env, refresh_token }: {
29
+ env: t.Env["Bindings"];
30
+ refresh_token: string;
31
+ }): Promise<false | import("../types/_usuario").default.RefreshTokenPayload>;
24
32
  };
25
33
  export default _token;
@@ -218,6 +218,14 @@ declare const helpers: {
218
218
  criar_token_micro_servico({ c }: {
219
219
  c: import("..").TypesCore.Context;
220
220
  }): Promise<string>;
221
+ criar_refresh_token({ env, usuario_id }: {
222
+ env: import("..").TypesCore.Env["Bindings"];
223
+ usuario_id: string;
224
+ }): Promise<string>;
225
+ verificar_refresh_token({ env, refresh_token }: {
226
+ env: import("..").TypesCore.Env["Bindings"];
227
+ refresh_token: string;
228
+ }): Promise<false | import("../types/_usuario").default.RefreshTokenPayload>;
221
229
  };
222
230
  secret: {
223
231
  readonly SALT_LENGTH: 22;
@@ -396,6 +396,29 @@ const _token = new class {
396
396
  }));
397
397
  return token;
398
398
  }
399
+ async criar_refresh_token({ env, usuario_id }) {
400
+ if (!env.JSON_WEB_REFRESH_TOKEN_AUTH_USER) return _set_response.error.WARNING({
401
+ message: "Erro ao gerar refresh token!!",
402
+ results: []
403
+ });
404
+ const token = await new SignJWT({
405
+ usuario_id: usuario_id
406
+ }).setProtectedHeader({
407
+ alg: "HS256"
408
+ }).setIssuedAt().setExpirationTime("2h").sign(new TextEncoder().encode(env.JSON_WEB_REFRESH_TOKEN_AUTH_USER)).catch((error)=>_set_response.error.WARNING({
409
+ message: "Erro ao gerar refresh token!"
410
+ }));
411
+ return token;
412
+ }
413
+ async verificar_refresh_token({ env, refresh_token }) {
414
+ try {
415
+ const secret_verify = new TextEncoder().encode(env.JSON_WEB_REFRESH_TOKEN_AUTH_USER);
416
+ const { payload } = await jwtVerify(refresh_token, secret_verify);
417
+ return payload;
418
+ } catch (error) {
419
+ return false;
420
+ }
421
+ }
399
422
  };
400
423
  const helpers_token = _token;
401
424
  const scryptAsync = promisify(scrypt);
@@ -39,11 +39,12 @@ declare namespace TypeControllerUsuario {
39
39
  usuario: {
40
40
  _id: string;
41
41
  email: string;
42
- nome?: string;
42
+ nome: string;
43
43
  imagem?: string;
44
- token?: string;
45
- data_criacao?: number;
46
- ativo?: 0 | 1;
44
+ token: string;
45
+ refresh_token: string;
46
+ data_criacao: number;
47
+ ativo: 0 | 1;
47
48
  usuario_tipo: UsuarioTipo;
48
49
  plano_name: PlanName;
49
50
  plano_status: AssinaturaStatusEnum;
@@ -61,6 +62,9 @@ declare namespace TypeControllerUsuario {
61
62
  plano_name: PlanName;
62
63
  plano_status: AssinaturaStatusEnum;
63
64
  }
65
+ export interface RefreshTokenPayload {
66
+ usuario_id: string;
67
+ }
64
68
  export {};
65
69
  }
66
70
  export default TypeControllerUsuario;
@@ -13,6 +13,7 @@ declare namespace t {
13
13
  Bindings: {
14
14
  JSON_WEB_TOKEN_AUTH_USER?: string;
15
15
  JSON_WEB_TOKEN_AUTH_MICRO_SERVICO?: string;
16
+ JSON_WEB_REFRESH_TOKEN_AUTH_USER?: string;
16
17
  };
17
18
  Variables: {
18
19
  usuario_auth: TypeControllerUsuario.TokenPayload;
@@ -21,5 +21,13 @@ declare const _token: {
21
21
  criar_token_micro_servico({ c }: {
22
22
  c: t.Context;
23
23
  }): Promise<string>;
24
+ criar_refresh_token({ env, usuario_id }: {
25
+ env: t.Env["Bindings"];
26
+ usuario_id: string;
27
+ }): Promise<string>;
28
+ verificar_refresh_token({ env, refresh_token }: {
29
+ env: t.Env["Bindings"];
30
+ refresh_token: string;
31
+ }): Promise<false | import("../types/_usuario").default.RefreshTokenPayload>;
24
32
  };
25
33
  export default _token;
@@ -218,6 +218,14 @@ declare const helpers: {
218
218
  criar_token_micro_servico({ c }: {
219
219
  c: import("..").TypesCore.Context;
220
220
  }): Promise<string>;
221
+ criar_refresh_token({ env, usuario_id }: {
222
+ env: import("..").TypesCore.Env["Bindings"];
223
+ usuario_id: string;
224
+ }): Promise<string>;
225
+ verificar_refresh_token({ env, refresh_token }: {
226
+ env: import("..").TypesCore.Env["Bindings"];
227
+ refresh_token: string;
228
+ }): Promise<false | import("../types/_usuario").default.RefreshTokenPayload>;
221
229
  };
222
230
  secret: {
223
231
  readonly SALT_LENGTH: 22;
@@ -473,6 +473,34 @@ const _token = new class _token {
473
473
  });
474
474
  return token;
475
475
  }
476
+ async criar_refresh_token({ env, usuario_id }) {
477
+ if (!env.JSON_WEB_REFRESH_TOKEN_AUTH_USER) {
478
+ return _set_response.error.WARNING({
479
+ message: "Erro ao gerar refresh token!!",
480
+ results: []
481
+ });
482
+ }
483
+ const token = await new external_jose_namespaceObject.SignJWT({
484
+ usuario_id: usuario_id
485
+ }).setProtectedHeader({
486
+ alg: "HS256"
487
+ }).setIssuedAt().setExpirationTime("2h").sign(new TextEncoder().encode(env.JSON_WEB_REFRESH_TOKEN_AUTH_USER)).catch((error)=>{
488
+ return _set_response.error.WARNING({
489
+ message: "Erro ao gerar refresh token!"
490
+ });
491
+ });
492
+ return token;
493
+ }
494
+ async verificar_refresh_token({ env, refresh_token }) {
495
+ try {
496
+ if (!refresh_token) false;
497
+ const secret_verify = new TextEncoder().encode(env.JSON_WEB_REFRESH_TOKEN_AUTH_USER);
498
+ const { payload } = await external_jose_namespaceObject.jwtVerify(refresh_token, secret_verify);
499
+ return payload;
500
+ } catch (error) {
501
+ return false;
502
+ }
503
+ }
476
504
  };
477
505
  /* export default */ const helpers_token = (_token);
478
506
 
@@ -39,11 +39,12 @@ declare namespace TypeControllerUsuario {
39
39
  usuario: {
40
40
  _id: string;
41
41
  email: string;
42
- nome?: string;
42
+ nome: string;
43
43
  imagem?: string;
44
- token?: string;
45
- data_criacao?: number;
46
- ativo?: 0 | 1;
44
+ token: string;
45
+ refresh_token: string;
46
+ data_criacao: number;
47
+ ativo: 0 | 1;
47
48
  usuario_tipo: UsuarioTipo;
48
49
  plano_name: PlanName;
49
50
  plano_status: AssinaturaStatusEnum;
@@ -61,6 +62,9 @@ declare namespace TypeControllerUsuario {
61
62
  plano_name: PlanName;
62
63
  plano_status: AssinaturaStatusEnum;
63
64
  }
65
+ export interface RefreshTokenPayload {
66
+ usuario_id: string;
67
+ }
64
68
  export {};
65
69
  }
66
70
  export default TypeControllerUsuario;
@@ -13,6 +13,7 @@ declare namespace t {
13
13
  Bindings: {
14
14
  JSON_WEB_TOKEN_AUTH_USER?: string;
15
15
  JSON_WEB_TOKEN_AUTH_MICRO_SERVICO?: string;
16
+ JSON_WEB_REFRESH_TOKEN_AUTH_USER?: string;
16
17
  };
17
18
  Variables: {
18
19
  usuario_auth: TypeControllerUsuario.TokenPayload;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navservice/core",
3
- "version": "1.105.0",
3
+ "version": "1.106.0",
4
4
  "description": "Service core de todos os micro serviços",
5
5
  "type": "module",
6
6
  "exports": {