@navservice/core 1.95.0 → 1.97.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.
- package/build/es/helpers/_token.d.ts +10 -0
- package/build/es/helpers/index.d.ts +10 -0
- package/build/es/helpers.js +62 -0
- package/build/es/types/index.d.ts +2 -1
- package/build/lib/helpers/_token.d.ts +10 -0
- package/build/lib/helpers/index.d.ts +10 -0
- package/build/lib/helpers.cjs +68 -0
- package/build/lib/types/index.d.ts +2 -1
- package/package.json +1 -1
|
@@ -12,5 +12,15 @@ declare const _token: {
|
|
|
12
12
|
criar_token_login_usuario({ _id, email, app, usuario_tipo, ativo, data_criacao, nome, c }: t.Controller.Usuario.TokenPayload & {
|
|
13
13
|
c: t.Context;
|
|
14
14
|
}): Promise<string>;
|
|
15
|
+
verificar_token_micro_servico(c: t.Context, next: Next): Promise<void | (Response & import("hono").TypedResponse<{
|
|
16
|
+
status: 200 | 201 | 202 | 204 | 400 | 401 | 403 | 404 | 409 | 422 | 500 | 428 | 405;
|
|
17
|
+
code: "SUCCESS" | "ACTION_REQUIRED" | "CREATED" | "WARNING" | "AUTHORIZATION_ERROR" | "SCHEMA_VALIDATION" | "SERVER_ERROR" | "UNAUTHORIZED" | "INVALID_TOKEN" | "NOT_FOUND" | "SUCCESS_FILE" | "DATABASE_ERROR";
|
|
18
|
+
type: "success" | "warning" | "error";
|
|
19
|
+
message?: string | undefined;
|
|
20
|
+
results: any;
|
|
21
|
+
}, 409, "json">)>;
|
|
22
|
+
criar_token_micro_servico({ c }: {
|
|
23
|
+
c: t.Context;
|
|
24
|
+
}): Promise<string>;
|
|
15
25
|
};
|
|
16
26
|
export default _token;
|
|
@@ -214,6 +214,16 @@ declare const helpers: {
|
|
|
214
214
|
criar_token_login_usuario({ _id, email, app, usuario_tipo, ativo, data_criacao, nome, c }: import("../types/_usuario").default.TokenPayload & {
|
|
215
215
|
c: import("..").TypesCore.Context;
|
|
216
216
|
}): Promise<string>;
|
|
217
|
+
verificar_token_micro_servico(c: import("..").TypesCore.Context, next: import("hono").Next): Promise<void | (Response & import("hono").TypedResponse<{
|
|
218
|
+
status: 200 | 201 | 202 | 204 | 400 | 401 | 403 | 404 | 409 | 422 | 500 | 428 | 405;
|
|
219
|
+
code: "SUCCESS" | "ACTION_REQUIRED" | "CREATED" | "WARNING" | "AUTHORIZATION_ERROR" | "SCHEMA_VALIDATION" | "SERVER_ERROR" | "UNAUTHORIZED" | "INVALID_TOKEN" | "NOT_FOUND" | "SUCCESS_FILE" | "DATABASE_ERROR";
|
|
220
|
+
type: "success" | "warning" | "error";
|
|
221
|
+
message?: string | undefined;
|
|
222
|
+
results: any;
|
|
223
|
+
}, 409, "json">)>;
|
|
224
|
+
criar_token_micro_servico({ c }: {
|
|
225
|
+
c: import("..").TypesCore.Context;
|
|
226
|
+
}): Promise<string>;
|
|
217
227
|
};
|
|
218
228
|
secret: typeof _secret;
|
|
219
229
|
data: typeof _data;
|
package/build/es/helpers.js
CHANGED
|
@@ -326,6 +326,68 @@ const _token = class {
|
|
|
326
326
|
}));
|
|
327
327
|
return token;
|
|
328
328
|
}
|
|
329
|
+
static async verificar_token_micro_servico(c, next) {
|
|
330
|
+
try {
|
|
331
|
+
const authHeader = c.req.header("Authorization");
|
|
332
|
+
if (!authHeader) return _set_response.c.INVALID_TOKEN({
|
|
333
|
+
message: 'token service não enviado!',
|
|
334
|
+
c: c,
|
|
335
|
+
results: []
|
|
336
|
+
});
|
|
337
|
+
const token = authHeader.split(" ")[1];
|
|
338
|
+
if (!token) return _set_response.c.INVALID_TOKEN({
|
|
339
|
+
message: 'Acesso negado ao serviço!',
|
|
340
|
+
c: c,
|
|
341
|
+
results: []
|
|
342
|
+
});
|
|
343
|
+
const secret = new TextEncoder().encode(c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO);
|
|
344
|
+
const { payload } = await jwtVerify(token, secret);
|
|
345
|
+
if (!payload._id || !payload.email) return _set_response.c.INVALID_TOKEN({
|
|
346
|
+
message: 'Token inválido para o serviço!',
|
|
347
|
+
c: c,
|
|
348
|
+
results: []
|
|
349
|
+
});
|
|
350
|
+
const setar_token = {
|
|
351
|
+
_id: payload._id,
|
|
352
|
+
email: payload.email,
|
|
353
|
+
ativo: payload.ativo,
|
|
354
|
+
data_criacao: payload.data_criacao,
|
|
355
|
+
nome: payload.nome,
|
|
356
|
+
app: payload.app,
|
|
357
|
+
usuario_tipo: payload.usuario_tipo
|
|
358
|
+
};
|
|
359
|
+
c.set("usuario_auth", setar_token);
|
|
360
|
+
return await next();
|
|
361
|
+
} catch (error) {
|
|
362
|
+
return _set_response.c.INVALID_TOKEN({
|
|
363
|
+
message: 'Erro token inválido!',
|
|
364
|
+
c: c,
|
|
365
|
+
results: []
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
static async criar_token_micro_servico({ c }) {
|
|
370
|
+
if (!c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO) return _set_response.error.WARNING({
|
|
371
|
+
message: "Erro ao gerar token!!",
|
|
372
|
+
results: []
|
|
373
|
+
});
|
|
374
|
+
const usuario_auth = c.get("usuario_auth");
|
|
375
|
+
const token = await new SignJWT({
|
|
376
|
+
_id: usuario_auth?._id,
|
|
377
|
+
email: usuario_auth?.email,
|
|
378
|
+
app: usuario_auth?.app,
|
|
379
|
+
usuario_tipo: usuario_auth?.usuario_tipo,
|
|
380
|
+
ativo: usuario_auth?.ativo,
|
|
381
|
+
data_criacao: usuario_auth?.data_criacao,
|
|
382
|
+
nome: usuario_auth?.nome
|
|
383
|
+
}).setProtectedHeader({
|
|
384
|
+
alg: "HS256"
|
|
385
|
+
}).setIssuedAt().setExpirationTime("30s").sign(new TextEncoder().encode(c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO)).catch((error)=>_set_response.error.WARNING({
|
|
386
|
+
message: "Erro ao gerar token!",
|
|
387
|
+
results: error?.message
|
|
388
|
+
}));
|
|
389
|
+
return token;
|
|
390
|
+
}
|
|
329
391
|
};
|
|
330
392
|
const helpers_token = _token;
|
|
331
393
|
const scryptAsync = promisify(scrypt);
|
|
@@ -7,11 +7,12 @@ declare namespace t {
|
|
|
7
7
|
}
|
|
8
8
|
namespace Geral {
|
|
9
9
|
export import Response = TypeControllerResponse;
|
|
10
|
-
type BaseUrl = "PUBLIC_BASE_URL_BACKEND_FINANCEIRO" | "PUBLIC_BASE_URL_BACKEND_USUARIO" | "PUBLIC_BASE_URL_BACKEND_BUCKET" | "PUBLIC_BASE_URL_CLOUDFLARE_BUCKET_PUBLIC";
|
|
10
|
+
type BaseUrl = "PUBLIC_BASE_URL_BACKEND_FINANCEIRO" | "PUBLIC_BASE_URL_BACKEND_USUARIO" | "PUBLIC_BASE_URL_BACKEND_BUCKET" | "PUBLIC_BASE_URL_CLOUDFLARE_BUCKET_PUBLIC" | "PUBLIC_BASE_URL_BACKEND_PAGES_AI" | "PUBLIC_BASE_URL_BACKEND_BUILD_CLOUDFLARE_PAGES";
|
|
11
11
|
}
|
|
12
12
|
type Env = {
|
|
13
13
|
Bindings: {
|
|
14
14
|
JSON_WEB_TOKEN_AUTH_USER?: string;
|
|
15
|
+
JSON_WEB_TOKEN_AUTH_MICRO_SERVICO?: string;
|
|
15
16
|
};
|
|
16
17
|
Variables: {
|
|
17
18
|
usuario_auth: TypeControllerUsuario.TokenPayload;
|
|
@@ -12,5 +12,15 @@ declare const _token: {
|
|
|
12
12
|
criar_token_login_usuario({ _id, email, app, usuario_tipo, ativo, data_criacao, nome, c }: t.Controller.Usuario.TokenPayload & {
|
|
13
13
|
c: t.Context;
|
|
14
14
|
}): Promise<string>;
|
|
15
|
+
verificar_token_micro_servico(c: t.Context, next: Next): Promise<void | (Response & import("hono").TypedResponse<{
|
|
16
|
+
status: 200 | 201 | 202 | 204 | 400 | 401 | 403 | 404 | 409 | 422 | 500 | 428 | 405;
|
|
17
|
+
code: "SUCCESS" | "ACTION_REQUIRED" | "CREATED" | "WARNING" | "AUTHORIZATION_ERROR" | "SCHEMA_VALIDATION" | "SERVER_ERROR" | "UNAUTHORIZED" | "INVALID_TOKEN" | "NOT_FOUND" | "SUCCESS_FILE" | "DATABASE_ERROR";
|
|
18
|
+
type: "success" | "warning" | "error";
|
|
19
|
+
message?: string | undefined;
|
|
20
|
+
results: any;
|
|
21
|
+
}, 409, "json">)>;
|
|
22
|
+
criar_token_micro_servico({ c }: {
|
|
23
|
+
c: t.Context;
|
|
24
|
+
}): Promise<string>;
|
|
15
25
|
};
|
|
16
26
|
export default _token;
|
|
@@ -214,6 +214,16 @@ declare const helpers: {
|
|
|
214
214
|
criar_token_login_usuario({ _id, email, app, usuario_tipo, ativo, data_criacao, nome, c }: import("../types/_usuario").default.TokenPayload & {
|
|
215
215
|
c: import("..").TypesCore.Context;
|
|
216
216
|
}): Promise<string>;
|
|
217
|
+
verificar_token_micro_servico(c: import("..").TypesCore.Context, next: import("hono").Next): Promise<void | (Response & import("hono").TypedResponse<{
|
|
218
|
+
status: 200 | 201 | 202 | 204 | 400 | 401 | 403 | 404 | 409 | 422 | 500 | 428 | 405;
|
|
219
|
+
code: "SUCCESS" | "ACTION_REQUIRED" | "CREATED" | "WARNING" | "AUTHORIZATION_ERROR" | "SCHEMA_VALIDATION" | "SERVER_ERROR" | "UNAUTHORIZED" | "INVALID_TOKEN" | "NOT_FOUND" | "SUCCESS_FILE" | "DATABASE_ERROR";
|
|
220
|
+
type: "success" | "warning" | "error";
|
|
221
|
+
message?: string | undefined;
|
|
222
|
+
results: any;
|
|
223
|
+
}, 409, "json">)>;
|
|
224
|
+
criar_token_micro_servico({ c }: {
|
|
225
|
+
c: import("..").TypesCore.Context;
|
|
226
|
+
}): Promise<string>;
|
|
217
227
|
};
|
|
218
228
|
secret: typeof _secret;
|
|
219
229
|
data: typeof _data;
|
package/build/lib/helpers.cjs
CHANGED
|
@@ -398,6 +398,74 @@ const _token = class _token {
|
|
|
398
398
|
});
|
|
399
399
|
return token;
|
|
400
400
|
}
|
|
401
|
+
static async verificar_token_micro_servico(c, next) {
|
|
402
|
+
try {
|
|
403
|
+
const authHeader = c.req.header("Authorization");
|
|
404
|
+
if (!authHeader) return _set_response.c.INVALID_TOKEN({
|
|
405
|
+
message: 'token service não enviado!',
|
|
406
|
+
c: c,
|
|
407
|
+
results: []
|
|
408
|
+
});
|
|
409
|
+
const token = authHeader.split(" ")[1];
|
|
410
|
+
if (!token) return _set_response.c.INVALID_TOKEN({
|
|
411
|
+
message: 'Acesso negado ao serviço!',
|
|
412
|
+
c: c,
|
|
413
|
+
results: []
|
|
414
|
+
});
|
|
415
|
+
const secret = new TextEncoder().encode(c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO);
|
|
416
|
+
const { payload } = await external_jose_namespaceObject.jwtVerify(token, secret);
|
|
417
|
+
if (!payload._id || !payload.email) {
|
|
418
|
+
return _set_response.c.INVALID_TOKEN({
|
|
419
|
+
message: 'Token inválido para o serviço!',
|
|
420
|
+
c: c,
|
|
421
|
+
results: []
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
const setar_token = {
|
|
425
|
+
_id: payload._id,
|
|
426
|
+
email: payload.email,
|
|
427
|
+
ativo: payload.ativo,
|
|
428
|
+
data_criacao: payload.data_criacao,
|
|
429
|
+
nome: payload.nome,
|
|
430
|
+
app: payload.app,
|
|
431
|
+
usuario_tipo: payload.usuario_tipo
|
|
432
|
+
};
|
|
433
|
+
c.set("usuario_auth", setar_token);
|
|
434
|
+
return await next();
|
|
435
|
+
} catch (error) {
|
|
436
|
+
return _set_response.c.INVALID_TOKEN({
|
|
437
|
+
message: 'Erro token inválido!',
|
|
438
|
+
c: c,
|
|
439
|
+
results: []
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
static async criar_token_micro_servico({ c }) {
|
|
444
|
+
if (!c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO) {
|
|
445
|
+
return _set_response.error.WARNING({
|
|
446
|
+
message: "Erro ao gerar token!!",
|
|
447
|
+
results: []
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
const usuario_auth = c.get("usuario_auth");
|
|
451
|
+
const token = await new external_jose_namespaceObject.SignJWT({
|
|
452
|
+
_id: usuario_auth?._id,
|
|
453
|
+
email: usuario_auth?.email,
|
|
454
|
+
app: usuario_auth?.app,
|
|
455
|
+
usuario_tipo: usuario_auth?.usuario_tipo,
|
|
456
|
+
ativo: usuario_auth?.ativo,
|
|
457
|
+
data_criacao: usuario_auth?.data_criacao,
|
|
458
|
+
nome: usuario_auth?.nome
|
|
459
|
+
}).setProtectedHeader({
|
|
460
|
+
alg: "HS256"
|
|
461
|
+
}).setIssuedAt().setExpirationTime("30s").sign(new TextEncoder().encode(c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO)).catch((error)=>{
|
|
462
|
+
return _set_response.error.WARNING({
|
|
463
|
+
message: "Erro ao gerar token!",
|
|
464
|
+
results: error?.message
|
|
465
|
+
});
|
|
466
|
+
});
|
|
467
|
+
return token;
|
|
468
|
+
}
|
|
401
469
|
};
|
|
402
470
|
/* export default */ const helpers_token = (_token);
|
|
403
471
|
|
|
@@ -7,11 +7,12 @@ declare namespace t {
|
|
|
7
7
|
}
|
|
8
8
|
namespace Geral {
|
|
9
9
|
export import Response = TypeControllerResponse;
|
|
10
|
-
type BaseUrl = "PUBLIC_BASE_URL_BACKEND_FINANCEIRO" | "PUBLIC_BASE_URL_BACKEND_USUARIO" | "PUBLIC_BASE_URL_BACKEND_BUCKET" | "PUBLIC_BASE_URL_CLOUDFLARE_BUCKET_PUBLIC";
|
|
10
|
+
type BaseUrl = "PUBLIC_BASE_URL_BACKEND_FINANCEIRO" | "PUBLIC_BASE_URL_BACKEND_USUARIO" | "PUBLIC_BASE_URL_BACKEND_BUCKET" | "PUBLIC_BASE_URL_CLOUDFLARE_BUCKET_PUBLIC" | "PUBLIC_BASE_URL_BACKEND_PAGES_AI" | "PUBLIC_BASE_URL_BACKEND_BUILD_CLOUDFLARE_PAGES";
|
|
11
11
|
}
|
|
12
12
|
type Env = {
|
|
13
13
|
Bindings: {
|
|
14
14
|
JSON_WEB_TOKEN_AUTH_USER?: string;
|
|
15
|
+
JSON_WEB_TOKEN_AUTH_MICRO_SERVICO?: string;
|
|
15
16
|
};
|
|
16
17
|
Variables: {
|
|
17
18
|
usuario_auth: TypeControllerUsuario.TokenPayload;
|