@navservice/core 1.115.0 → 1.119.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/_set_response.d.ts +41 -32
- package/build/es/helpers/_token.d.ts +2 -2
- package/build/es/helpers/index.d.ts +60 -87
- package/build/es/helpers.js +209 -47
- package/build/es/index.js +5 -3
- package/build/es/types/_type_response.d.ts +4 -4
- package/build/lib/helpers/_set_response.d.ts +41 -32
- package/build/lib/helpers/_token.d.ts +2 -2
- package/build/lib/helpers/index.d.ts +60 -87
- package/build/lib/helpers.cjs +210 -47
- package/build/lib/index.cjs +5 -3
- package/build/lib/types/_type_response.d.ts +4 -4
- package/package.json +1 -1
package/build/lib/helpers.cjs
CHANGED
|
@@ -112,7 +112,7 @@ const _logger = new RequestLoggerClass();
|
|
|
112
112
|
|
|
113
113
|
const set_response = new class set_response {
|
|
114
114
|
c = new class c {
|
|
115
|
-
SUCCESS({ message, results, c }) {
|
|
115
|
+
SUCCESS({ message, results, c, fn }) {
|
|
116
116
|
const payload = {
|
|
117
117
|
status: 200,
|
|
118
118
|
code: "SUCCESS",
|
|
@@ -120,11 +120,17 @@ const set_response = new class set_response {
|
|
|
120
120
|
message: message || "Realizado com sucesso!",
|
|
121
121
|
results: results || []
|
|
122
122
|
};
|
|
123
|
+
helpers_logger.add({
|
|
124
|
+
fn: `${fn}_SUCCESS`,
|
|
125
|
+
level: "info",
|
|
126
|
+
message: payload?.message,
|
|
127
|
+
results: payload?.results
|
|
128
|
+
});
|
|
123
129
|
return c.json(payload, {
|
|
124
130
|
status: 200
|
|
125
131
|
});
|
|
126
132
|
}
|
|
127
|
-
ACTION_REQUIRED({ message, results, c }) {
|
|
133
|
+
ACTION_REQUIRED({ message, results, c, fn }) {
|
|
128
134
|
const payload = {
|
|
129
135
|
status: 428,
|
|
130
136
|
code: "ACTION_REQUIRED",
|
|
@@ -132,11 +138,17 @@ const set_response = new class set_response {
|
|
|
132
138
|
message: message || "Ação adicional necessária!",
|
|
133
139
|
results: results || []
|
|
134
140
|
};
|
|
141
|
+
helpers_logger.add({
|
|
142
|
+
fn: `${fn}_ACTION_REQUIRED`,
|
|
143
|
+
level: "info",
|
|
144
|
+
message: payload?.message,
|
|
145
|
+
results: payload?.results
|
|
146
|
+
});
|
|
135
147
|
return c.json(payload, {
|
|
136
148
|
status: 428
|
|
137
149
|
});
|
|
138
150
|
}
|
|
139
|
-
CREATED({ message, results, c }) {
|
|
151
|
+
CREATED({ message, results, c, fn }) {
|
|
140
152
|
const payload = {
|
|
141
153
|
status: 201,
|
|
142
154
|
code: "CREATED",
|
|
@@ -144,11 +156,17 @@ const set_response = new class set_response {
|
|
|
144
156
|
message: message || "Criado com sucesso!",
|
|
145
157
|
results: results || []
|
|
146
158
|
};
|
|
159
|
+
helpers_logger.add({
|
|
160
|
+
fn: `${fn}_CREATED`,
|
|
161
|
+
level: "info",
|
|
162
|
+
message: payload?.message,
|
|
163
|
+
results: payload?.results
|
|
164
|
+
});
|
|
147
165
|
return c.json(payload, {
|
|
148
166
|
status: 201
|
|
149
167
|
});
|
|
150
168
|
}
|
|
151
|
-
WARNING({ message, results, c }) {
|
|
169
|
+
WARNING({ message, results, c, fn }) {
|
|
152
170
|
const payload = {
|
|
153
171
|
status: 400,
|
|
154
172
|
code: "WARNING",
|
|
@@ -156,11 +174,17 @@ const set_response = new class set_response {
|
|
|
156
174
|
message: message || "Aviso!",
|
|
157
175
|
results: results || []
|
|
158
176
|
};
|
|
177
|
+
helpers_logger.add({
|
|
178
|
+
fn: `${fn}_WARNING`,
|
|
179
|
+
level: "info",
|
|
180
|
+
message: payload?.message,
|
|
181
|
+
results: payload?.results
|
|
182
|
+
});
|
|
159
183
|
return c.json(payload, {
|
|
160
184
|
status: 400
|
|
161
185
|
});
|
|
162
186
|
}
|
|
163
|
-
AUTHORIZATION_ERROR({ message, results, c }) {
|
|
187
|
+
AUTHORIZATION_ERROR({ message, results, c, fn }) {
|
|
164
188
|
const payload = {
|
|
165
189
|
status: 405,
|
|
166
190
|
code: "WARNING",
|
|
@@ -168,11 +192,17 @@ const set_response = new class set_response {
|
|
|
168
192
|
message: message || "Aviso!",
|
|
169
193
|
results: results || []
|
|
170
194
|
};
|
|
195
|
+
helpers_logger.add({
|
|
196
|
+
fn: `${fn}_AUTHORIZATION_ERROR`,
|
|
197
|
+
level: "error",
|
|
198
|
+
message: payload?.message,
|
|
199
|
+
results: payload?.results
|
|
200
|
+
});
|
|
171
201
|
return c.json(payload, {
|
|
172
202
|
status: 405
|
|
173
203
|
});
|
|
174
204
|
}
|
|
175
|
-
SERVER_ERROR({ error, c }) {
|
|
205
|
+
SERVER_ERROR({ error, c, fn }) {
|
|
176
206
|
if (error instanceof (v4_default()).ZodError) {
|
|
177
207
|
const payload = {
|
|
178
208
|
status: 500,
|
|
@@ -182,7 +212,7 @@ const set_response = new class set_response {
|
|
|
182
212
|
results: v4_default().treeifyError(error)
|
|
183
213
|
};
|
|
184
214
|
helpers_logger.add({
|
|
185
|
-
fn:
|
|
215
|
+
fn: `${fn}_SCHEMA_VALIDATION`,
|
|
186
216
|
level: "error",
|
|
187
217
|
message: payload?.message,
|
|
188
218
|
results: payload?.results
|
|
@@ -200,7 +230,7 @@ const set_response = new class set_response {
|
|
|
200
230
|
};
|
|
201
231
|
if (payload?.type === "error") {
|
|
202
232
|
helpers_logger.add({
|
|
203
|
-
fn:
|
|
233
|
+
fn: `${fn}_SERVER_ERROR`,
|
|
204
234
|
level: payload?.type,
|
|
205
235
|
message: payload?.message,
|
|
206
236
|
results: payload?.results
|
|
@@ -210,7 +240,7 @@ const set_response = new class set_response {
|
|
|
210
240
|
status: error?.status || error?.status || 500
|
|
211
241
|
});
|
|
212
242
|
}
|
|
213
|
-
UNAUTHORIZED({ message, c }) {
|
|
243
|
+
UNAUTHORIZED({ message, c, fn }) {
|
|
214
244
|
const payload = {
|
|
215
245
|
status: 401,
|
|
216
246
|
code: "UNAUTHORIZED",
|
|
@@ -218,11 +248,17 @@ const set_response = new class set_response {
|
|
|
218
248
|
message: message || "Não autorizado!",
|
|
219
249
|
results: []
|
|
220
250
|
};
|
|
251
|
+
helpers_logger.add({
|
|
252
|
+
fn: `${fn}_UNAUTHORIZED`,
|
|
253
|
+
level: "error",
|
|
254
|
+
message: payload?.message,
|
|
255
|
+
results: payload?.results
|
|
256
|
+
});
|
|
221
257
|
return c.json(payload, {
|
|
222
258
|
status: 401
|
|
223
259
|
});
|
|
224
260
|
}
|
|
225
|
-
INVALID_TOKEN({ message, c }) {
|
|
261
|
+
INVALID_TOKEN({ message, c, fn }) {
|
|
226
262
|
const payload = {
|
|
227
263
|
status: 409,
|
|
228
264
|
code: "INVALID_TOKEN",
|
|
@@ -230,11 +266,17 @@ const set_response = new class set_response {
|
|
|
230
266
|
message: message || "Token inválido!",
|
|
231
267
|
results: []
|
|
232
268
|
};
|
|
269
|
+
helpers_logger.add({
|
|
270
|
+
fn: `${fn}_INVALID_TOKEN`,
|
|
271
|
+
level: "error",
|
|
272
|
+
message: payload?.message,
|
|
273
|
+
results: payload?.results
|
|
274
|
+
});
|
|
233
275
|
return c.json(payload, {
|
|
234
276
|
status: 409
|
|
235
277
|
});
|
|
236
278
|
}
|
|
237
|
-
NOT_FOUND({ message, c }) {
|
|
279
|
+
NOT_FOUND({ message, c, fn }) {
|
|
238
280
|
const payload = {
|
|
239
281
|
status: 404,
|
|
240
282
|
code: "NOT_FOUND",
|
|
@@ -242,16 +284,28 @@ const set_response = new class set_response {
|
|
|
242
284
|
message: message || "Recurso não encontrado!",
|
|
243
285
|
results: []
|
|
244
286
|
};
|
|
287
|
+
helpers_logger.add({
|
|
288
|
+
fn: `${fn}_NOT_FOUND`,
|
|
289
|
+
level: "info",
|
|
290
|
+
message: payload?.message,
|
|
291
|
+
results: payload?.results
|
|
292
|
+
});
|
|
245
293
|
return c.json(payload, {
|
|
246
294
|
status: 404
|
|
247
295
|
});
|
|
248
296
|
}
|
|
249
|
-
async SUCCESS_FILE({ message, file_buffer, content_type, filename, c }) {
|
|
297
|
+
async SUCCESS_FILE({ message, file_buffer, content_type, filename, c, fn }) {
|
|
250
298
|
if (c && content_type) {
|
|
251
299
|
const headers = {
|
|
252
300
|
"Content-Type": content_type,
|
|
253
301
|
"Content-Disposition": filename ? `inline; filename="${filename}"` : "inline"
|
|
254
302
|
};
|
|
303
|
+
helpers_logger.add({
|
|
304
|
+
fn: `${fn}_SUCCESS_FILE`,
|
|
305
|
+
level: "info",
|
|
306
|
+
message: "",
|
|
307
|
+
results: headers
|
|
308
|
+
});
|
|
255
309
|
return c.json(file_buffer, {
|
|
256
310
|
status: 200,
|
|
257
311
|
headers
|
|
@@ -264,13 +318,19 @@ const set_response = new class set_response {
|
|
|
264
318
|
message: message || "Erro ao retornar arquivo!",
|
|
265
319
|
results: []
|
|
266
320
|
};
|
|
321
|
+
helpers_logger.add({
|
|
322
|
+
fn: `${fn}_SUCCESS_FILE`,
|
|
323
|
+
level: "info",
|
|
324
|
+
message: payload?.message,
|
|
325
|
+
results: payload?.results
|
|
326
|
+
});
|
|
267
327
|
return c.json(payload, {
|
|
268
328
|
status: 200
|
|
269
329
|
});
|
|
270
330
|
}
|
|
271
331
|
};
|
|
272
332
|
error = new class error {
|
|
273
|
-
ACTION_REQUIRED({ message, results }) {
|
|
333
|
+
ACTION_REQUIRED({ message, results, fn }) {
|
|
274
334
|
const payload = {
|
|
275
335
|
status: 428,
|
|
276
336
|
code: "ACTION_REQUIRED",
|
|
@@ -278,9 +338,15 @@ const set_response = new class set_response {
|
|
|
278
338
|
message: message || "Ação adicional necessária!",
|
|
279
339
|
results: results || []
|
|
280
340
|
};
|
|
341
|
+
helpers_logger.add({
|
|
342
|
+
fn: `${fn}_ACTION_REQUIRED`,
|
|
343
|
+
level: "info",
|
|
344
|
+
message: payload?.message,
|
|
345
|
+
results: payload?.results
|
|
346
|
+
});
|
|
281
347
|
throw payload;
|
|
282
348
|
}
|
|
283
|
-
WARNING({ message, results }) {
|
|
349
|
+
WARNING({ message, results, fn }) {
|
|
284
350
|
const payload = {
|
|
285
351
|
status: 400,
|
|
286
352
|
code: "WARNING",
|
|
@@ -288,9 +354,31 @@ const set_response = new class set_response {
|
|
|
288
354
|
message: message || "Aviso!",
|
|
289
355
|
results: results || []
|
|
290
356
|
};
|
|
357
|
+
helpers_logger.add({
|
|
358
|
+
fn: `${fn}_WARNING`,
|
|
359
|
+
level: "info",
|
|
360
|
+
message: payload?.message,
|
|
361
|
+
results: payload?.results
|
|
362
|
+
});
|
|
291
363
|
throw payload;
|
|
292
364
|
}
|
|
293
|
-
|
|
365
|
+
TOKEN_AUTH_USER({ message, results, fn }) {
|
|
366
|
+
const payload = {
|
|
367
|
+
status: 410,
|
|
368
|
+
code: "TOKEN_AUTH_USER",
|
|
369
|
+
type: "warning",
|
|
370
|
+
message: message || "Erro processo de auth token!",
|
|
371
|
+
results: results || []
|
|
372
|
+
};
|
|
373
|
+
helpers_logger.add({
|
|
374
|
+
fn: `${fn}_REFRESH_TOKEN_AUTH_USER`,
|
|
375
|
+
level: "error",
|
|
376
|
+
message: payload?.message,
|
|
377
|
+
results: payload?.results
|
|
378
|
+
});
|
|
379
|
+
throw payload;
|
|
380
|
+
}
|
|
381
|
+
AUTHORIZATION_ERROR({ message, results, fn }) {
|
|
294
382
|
const payload = {
|
|
295
383
|
status: 400,
|
|
296
384
|
code: "WARNING",
|
|
@@ -298,9 +386,16 @@ const set_response = new class set_response {
|
|
|
298
386
|
message: message || "Aviso!",
|
|
299
387
|
results: results || []
|
|
300
388
|
};
|
|
389
|
+
helpers_logger.add({
|
|
390
|
+
fn: `${fn}_AUTHORIZATION_ERROR`,
|
|
391
|
+
level: "error",
|
|
392
|
+
message: payload?.message,
|
|
393
|
+
results: payload?.results
|
|
394
|
+
});
|
|
301
395
|
throw payload;
|
|
302
396
|
}
|
|
303
|
-
|
|
397
|
+
// CONTEM _LOGGER PARA FACILITAR OS LOGS DE TRACING DO SISTEMA
|
|
398
|
+
DATABASE_ERROR({ message, erro, fn }) {
|
|
304
399
|
const errorCode = erro?.cause?.code || erro?.cause?.cause?.code || erro?.code || "";
|
|
305
400
|
const map = {
|
|
306
401
|
"SQLITE_CONSTRAINT_UNIQUE": {
|
|
@@ -344,14 +439,14 @@ const set_response = new class set_response {
|
|
|
344
439
|
results: []
|
|
345
440
|
};
|
|
346
441
|
helpers_logger.add({
|
|
347
|
-
fn:
|
|
442
|
+
fn: `${fn}_DATABASE_ERROR`,
|
|
348
443
|
level: "error",
|
|
349
444
|
message: payload?.message,
|
|
350
445
|
results: erro
|
|
351
446
|
});
|
|
352
447
|
throw payload;
|
|
353
448
|
}
|
|
354
|
-
SCHEMA_VALIDATION({ results }) {
|
|
449
|
+
SCHEMA_VALIDATION({ results, fn }) {
|
|
355
450
|
const payload = {
|
|
356
451
|
status: 500,
|
|
357
452
|
code: "SCHEMA_VALIDATION",
|
|
@@ -359,37 +454,78 @@ const set_response = new class set_response {
|
|
|
359
454
|
message: "Erro ao validar dados!",
|
|
360
455
|
results: results || []
|
|
361
456
|
};
|
|
457
|
+
helpers_logger.add({
|
|
458
|
+
fn: `${fn}_SCHEMA_VALIDATION`,
|
|
459
|
+
level: "error",
|
|
460
|
+
message: payload?.message,
|
|
461
|
+
results: payload?.results
|
|
462
|
+
});
|
|
362
463
|
throw payload;
|
|
363
464
|
}
|
|
364
|
-
UNAUTHORIZED({ message }) {
|
|
465
|
+
UNAUTHORIZED({ message, fn }) {
|
|
365
466
|
const payload = {
|
|
366
467
|
status: 401,
|
|
367
468
|
code: "UNAUTHORIZED",
|
|
368
469
|
type: "error",
|
|
369
470
|
message: message || "Não autorizado!"
|
|
370
471
|
};
|
|
472
|
+
helpers_logger.add({
|
|
473
|
+
fn: `${fn}_UNAUTHORIZED`,
|
|
474
|
+
level: "error",
|
|
475
|
+
message: payload?.message,
|
|
476
|
+
results: payload?.results
|
|
477
|
+
});
|
|
371
478
|
throw payload;
|
|
372
479
|
}
|
|
373
|
-
|
|
480
|
+
INTEGRATION_ERROR({ message, fn, erro }) {
|
|
481
|
+
const payload = {
|
|
482
|
+
status: 401,
|
|
483
|
+
code: "INTEGRATION_ERROR",
|
|
484
|
+
type: "error",
|
|
485
|
+
message: message || "Erro na camada de integração!",
|
|
486
|
+
results: erro
|
|
487
|
+
};
|
|
488
|
+
helpers_logger.add({
|
|
489
|
+
fn: `${fn}_INTEGRATION_ERROR`,
|
|
490
|
+
level: "error",
|
|
491
|
+
message: payload?.message,
|
|
492
|
+
results: erro
|
|
493
|
+
});
|
|
494
|
+
throw payload;
|
|
495
|
+
}
|
|
496
|
+
INVALID_TOKEN({ message, fn, results }) {
|
|
374
497
|
const payload = {
|
|
375
498
|
status: 401,
|
|
376
499
|
code: "INVALID_TOKEN",
|
|
377
500
|
type: "warning",
|
|
378
501
|
message: message || "Token inválido!",
|
|
379
|
-
results: []
|
|
502
|
+
results: results || []
|
|
380
503
|
};
|
|
504
|
+
helpers_logger.add({
|
|
505
|
+
fn: `${fn}_INVALID_TOKEN`,
|
|
506
|
+
level: "error",
|
|
507
|
+
message: payload?.message,
|
|
508
|
+
results: payload?.results
|
|
509
|
+
});
|
|
381
510
|
throw payload;
|
|
382
511
|
}
|
|
383
|
-
NOT_FOUND({ message }) {
|
|
512
|
+
NOT_FOUND({ message, fn, results }) {
|
|
384
513
|
const payload = {
|
|
385
514
|
status: 404,
|
|
386
515
|
code: "NOT_FOUND",
|
|
387
516
|
type: "error",
|
|
388
|
-
message: message || "Recurso não encontrado!"
|
|
517
|
+
message: message || "Recurso não encontrado!",
|
|
518
|
+
results: results || []
|
|
389
519
|
};
|
|
520
|
+
helpers_logger.add({
|
|
521
|
+
fn: `${fn}_NOT_FOUND`,
|
|
522
|
+
level: "info",
|
|
523
|
+
message: payload?.message,
|
|
524
|
+
results: payload?.results
|
|
525
|
+
});
|
|
390
526
|
throw payload;
|
|
391
527
|
}
|
|
392
|
-
BUSINESS_RULE_VIOLATION({ message, results }) {
|
|
528
|
+
BUSINESS_RULE_VIOLATION({ message, results, fn }) {
|
|
393
529
|
const payload = {
|
|
394
530
|
status: 422,
|
|
395
531
|
code: "BUSINESS_RULE_VIOLATION",
|
|
@@ -397,9 +533,15 @@ const set_response = new class set_response {
|
|
|
397
533
|
message: message || "Limite atingido ou regra de negócio violada!",
|
|
398
534
|
results: results || []
|
|
399
535
|
};
|
|
536
|
+
helpers_logger.add({
|
|
537
|
+
fn: `${fn}_BUSINESS_RULE_VIOLATION`,
|
|
538
|
+
level: "info",
|
|
539
|
+
message: payload?.message,
|
|
540
|
+
results: payload?.results
|
|
541
|
+
});
|
|
400
542
|
throw payload;
|
|
401
543
|
}
|
|
402
|
-
PLAN_FORBIDDEN({ message, results }) {
|
|
544
|
+
PLAN_FORBIDDEN({ message, results, fn }) {
|
|
403
545
|
const payload = {
|
|
404
546
|
status: 403,
|
|
405
547
|
code: "PLAN_FORBIDDEN",
|
|
@@ -407,6 +549,12 @@ const set_response = new class set_response {
|
|
|
407
549
|
message: message || "Plano inativo ou sem permissão para esta ação!",
|
|
408
550
|
results: results || []
|
|
409
551
|
};
|
|
552
|
+
helpers_logger.add({
|
|
553
|
+
fn: `${fn}_PLAN_FORBIDDEN`,
|
|
554
|
+
level: "info",
|
|
555
|
+
message: payload?.message,
|
|
556
|
+
results: payload?.results
|
|
557
|
+
});
|
|
410
558
|
throw payload;
|
|
411
559
|
}
|
|
412
560
|
};
|
|
@@ -419,6 +567,7 @@ const external_jose_namespaceObject = require("jose");
|
|
|
419
567
|
|
|
420
568
|
// Tem que importar assim para evitar dependencia circular
|
|
421
569
|
|
|
570
|
+
const _token_fn = 'token';
|
|
422
571
|
const _token = new class _token {
|
|
423
572
|
async verificar_token(c, next) {
|
|
424
573
|
try {
|
|
@@ -426,13 +575,15 @@ const _token = new class _token {
|
|
|
426
575
|
if (!authHeader) return _set_response.c.INVALID_TOKEN({
|
|
427
576
|
message: 'token não enviado!!!',
|
|
428
577
|
c: c,
|
|
429
|
-
results: []
|
|
578
|
+
results: [],
|
|
579
|
+
fn: _token_fn
|
|
430
580
|
});
|
|
431
581
|
const token = authHeader.split(" ")[1];
|
|
432
582
|
if (!token) return _set_response.c.INVALID_TOKEN({
|
|
433
583
|
message: 'Acesso negado!!!',
|
|
434
584
|
c: c,
|
|
435
|
-
results: []
|
|
585
|
+
results: [],
|
|
586
|
+
fn: _token_fn
|
|
436
587
|
});
|
|
437
588
|
const secret = new TextEncoder().encode(c.env.JSON_WEB_TOKEN_AUTH_USER);
|
|
438
589
|
const { payload } = await external_jose_namespaceObject.jwtVerify(token, secret);
|
|
@@ -440,7 +591,8 @@ const _token = new class _token {
|
|
|
440
591
|
return _set_response.c.INVALID_TOKEN({
|
|
441
592
|
message: 'Token inválido!!!!',
|
|
442
593
|
c: c,
|
|
443
|
-
results: []
|
|
594
|
+
results: [],
|
|
595
|
+
fn: _token_fn
|
|
444
596
|
});
|
|
445
597
|
}
|
|
446
598
|
const setar_token = {
|
|
@@ -461,15 +613,17 @@ const _token = new class _token {
|
|
|
461
613
|
return _set_response.c.INVALID_TOKEN({
|
|
462
614
|
message: 'Token inválido!!!',
|
|
463
615
|
c: c,
|
|
464
|
-
results: []
|
|
616
|
+
results: [],
|
|
617
|
+
fn: _token_fn
|
|
465
618
|
});
|
|
466
619
|
}
|
|
467
620
|
}
|
|
468
621
|
async criar_token_login_usuario(props) {
|
|
469
622
|
if (!props?.c.env.JSON_WEB_TOKEN_AUTH_USER) {
|
|
470
623
|
_set_response.error.WARNING({
|
|
471
|
-
message: "Erro ao gerar token!!",
|
|
472
|
-
results: []
|
|
624
|
+
message: "Erro ao gerar token auth!!",
|
|
625
|
+
results: [],
|
|
626
|
+
fn: _token_fn
|
|
473
627
|
});
|
|
474
628
|
}
|
|
475
629
|
const token = await new external_jose_namespaceObject.SignJWT({
|
|
@@ -485,9 +639,10 @@ const _token = new class _token {
|
|
|
485
639
|
}).setProtectedHeader({
|
|
486
640
|
alg: "HS256"
|
|
487
641
|
}).setIssuedAt().setExpirationTime("1h").sign(new TextEncoder().encode(props?.c.env.JSON_WEB_TOKEN_AUTH_USER)).catch((error)=>{
|
|
488
|
-
return _set_response.error.
|
|
489
|
-
message: "Erro ao gerar token!",
|
|
490
|
-
results: error?.message
|
|
642
|
+
return _set_response.error.TOKEN_AUTH_USER({
|
|
643
|
+
message: "Erro ao gerar token auth user!",
|
|
644
|
+
results: error?.message,
|
|
645
|
+
fn: _token_fn
|
|
491
646
|
});
|
|
492
647
|
});
|
|
493
648
|
return token;
|
|
@@ -498,13 +653,15 @@ const _token = new class _token {
|
|
|
498
653
|
if (!authHeader) return _set_response.c.INVALID_TOKEN({
|
|
499
654
|
message: 'token service não enviado!',
|
|
500
655
|
c: c,
|
|
501
|
-
results: []
|
|
656
|
+
results: [],
|
|
657
|
+
fn: _token_fn
|
|
502
658
|
});
|
|
503
659
|
const token = authHeader.split(" ")[1];
|
|
504
660
|
if (!token) return _set_response.c.INVALID_TOKEN({
|
|
505
661
|
message: 'Acesso negado ao serviço!',
|
|
506
662
|
c: c,
|
|
507
|
-
results: []
|
|
663
|
+
results: [],
|
|
664
|
+
fn: _token_fn
|
|
508
665
|
});
|
|
509
666
|
const secret = new TextEncoder().encode(c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO);
|
|
510
667
|
const { payload } = await external_jose_namespaceObject.jwtVerify(token, secret);
|
|
@@ -512,7 +669,8 @@ const _token = new class _token {
|
|
|
512
669
|
return _set_response.c.INVALID_TOKEN({
|
|
513
670
|
message: 'Token inválido para o serviço!',
|
|
514
671
|
c: c,
|
|
515
|
-
results: []
|
|
672
|
+
results: [],
|
|
673
|
+
fn: _token_fn
|
|
516
674
|
});
|
|
517
675
|
}
|
|
518
676
|
const setar_token = {
|
|
@@ -532,15 +690,17 @@ const _token = new class _token {
|
|
|
532
690
|
return _set_response.c.INVALID_TOKEN({
|
|
533
691
|
message: 'Erro token inválido!',
|
|
534
692
|
c: c,
|
|
535
|
-
results: []
|
|
693
|
+
results: [],
|
|
694
|
+
fn: _token_fn
|
|
536
695
|
});
|
|
537
696
|
}
|
|
538
697
|
}
|
|
539
698
|
async criar_token_micro_servico({ c }) {
|
|
540
699
|
if (!c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO) {
|
|
541
|
-
|
|
700
|
+
_set_response.error.WARNING({
|
|
542
701
|
message: "Erro ao gerar token!!",
|
|
543
|
-
results: []
|
|
702
|
+
results: [],
|
|
703
|
+
fn: _token_fn
|
|
544
704
|
});
|
|
545
705
|
}
|
|
546
706
|
const usuario_auth = c.get("usuario_auth");
|
|
@@ -557,18 +717,20 @@ const _token = new class _token {
|
|
|
557
717
|
}).setProtectedHeader({
|
|
558
718
|
alg: "HS256"
|
|
559
719
|
}).setIssuedAt().setExpirationTime("30s").sign(new TextEncoder().encode(c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO)).catch((error)=>{
|
|
560
|
-
return _set_response.error.
|
|
561
|
-
message: "Erro ao gerar token!",
|
|
562
|
-
results: error?.message
|
|
720
|
+
return _set_response.error.TOKEN_AUTH_USER({
|
|
721
|
+
message: "Erro ao gerar token micro serviço!",
|
|
722
|
+
results: error?.message,
|
|
723
|
+
fn: _token_fn
|
|
563
724
|
});
|
|
564
725
|
});
|
|
565
726
|
return token;
|
|
566
727
|
}
|
|
567
728
|
async criar_refresh_token({ env, usuario_id }) {
|
|
568
729
|
if (!env.JSON_WEB_REFRESH_TOKEN_AUTH_USER) {
|
|
569
|
-
|
|
730
|
+
_set_response.error.TOKEN_AUTH_USER({
|
|
570
731
|
message: "Erro ao gerar refresh token!!",
|
|
571
|
-
results: []
|
|
732
|
+
results: [],
|
|
733
|
+
fn: _token_fn
|
|
572
734
|
});
|
|
573
735
|
}
|
|
574
736
|
const token = await new external_jose_namespaceObject.SignJWT({
|
|
@@ -576,8 +738,9 @@ const _token = new class _token {
|
|
|
576
738
|
}).setProtectedHeader({
|
|
577
739
|
alg: "HS256"
|
|
578
740
|
}).setIssuedAt().setExpirationTime("2h").sign(new TextEncoder().encode(env.JSON_WEB_REFRESH_TOKEN_AUTH_USER)).catch((error)=>{
|
|
579
|
-
return _set_response.error.
|
|
580
|
-
message: "Erro ao gerar refresh token!"
|
|
741
|
+
return _set_response.error.TOKEN_AUTH_USER({
|
|
742
|
+
message: "Erro ao gerar refresh token!",
|
|
743
|
+
fn: _token_fn
|
|
581
744
|
});
|
|
582
745
|
});
|
|
583
746
|
return token;
|
package/build/lib/index.cjs
CHANGED
|
@@ -153,7 +153,9 @@ var _usuario_TypeControllerUsuario;
|
|
|
153
153
|
v4_default().literal("SUCCESS_FILE"),
|
|
154
154
|
v4_default().literal("DATABASE_ERROR"),
|
|
155
155
|
v4_default().literal("BUSINESS_RULE_VIOLATION"),
|
|
156
|
-
v4_default().literal("PLAN_FORBIDDEN")
|
|
156
|
+
v4_default().literal("PLAN_FORBIDDEN"),
|
|
157
|
+
v4_default().literal("INTEGRATION_ERROR"),
|
|
158
|
+
v4_default().literal("TOKEN_AUTH_USER")
|
|
157
159
|
]);
|
|
158
160
|
const BaseResponseSchema = v4_default().object({
|
|
159
161
|
status: StatusSchema,
|
|
@@ -175,6 +177,7 @@ var _usuario_TypeControllerUsuario;
|
|
|
175
177
|
const FileResponseParamsSchema = v4_default().object({
|
|
176
178
|
status: StatusSchema,
|
|
177
179
|
message: v4_default().string().optional(),
|
|
180
|
+
fn: v4_default().string(),
|
|
178
181
|
file_buffer: v4_default().union([
|
|
179
182
|
v4_default()["instanceof"](Blob),
|
|
180
183
|
v4_default()["instanceof"](ArrayBuffer),
|
|
@@ -194,8 +197,7 @@ var _usuario_TypeControllerUsuario;
|
|
|
194
197
|
]).optional(),
|
|
195
198
|
type: TypeSchema.optional().default("success"),
|
|
196
199
|
code: CodeSchema,
|
|
197
|
-
status: v4_default().number().optional().default(200)
|
|
198
|
-
fn: v4_default().string().optional()
|
|
200
|
+
status: v4_default().number().optional().default(200)
|
|
199
201
|
});
|
|
200
202
|
})(TypeControllerResponse.Error || (TypeControllerResponse.Error = {}));
|
|
201
203
|
})(_type_response_TypeControllerResponse || (_type_response_TypeControllerResponse = {}));
|
|
@@ -3,7 +3,7 @@ import z4 from "zod/v4";
|
|
|
3
3
|
declare namespace TypeControllerResponse {
|
|
4
4
|
const BaseResponseSchema: z4.ZodObject<{
|
|
5
5
|
status: z4.ZodUnion<readonly [z4.ZodLiteral<200>, z4.ZodLiteral<201>, z4.ZodLiteral<202>, z4.ZodLiteral<204>, z4.ZodLiteral<400>, z4.ZodLiteral<401>, z4.ZodLiteral<403>, z4.ZodLiteral<404>, z4.ZodLiteral<409>, z4.ZodLiteral<422>, z4.ZodLiteral<500>, z4.ZodLiteral<428>, z4.ZodLiteral<405>]>;
|
|
6
|
-
code: z4.ZodUnion<readonly [z4.ZodLiteral<"SUCCESS">, z4.ZodLiteral<"ACTION_REQUIRED">, z4.ZodLiteral<"CREATED">, z4.ZodLiteral<"WARNING">, z4.ZodLiteral<"AUTHORIZATION_ERROR">, z4.ZodLiteral<"SCHEMA_VALIDATION">, z4.ZodLiteral<"SERVER_ERROR">, z4.ZodLiteral<"UNAUTHORIZED">, z4.ZodLiteral<"INVALID_TOKEN">, z4.ZodLiteral<"NOT_FOUND">, z4.ZodLiteral<"SUCCESS_FILE">, z4.ZodLiteral<"DATABASE_ERROR">, z4.ZodLiteral<"BUSINESS_RULE_VIOLATION">, z4.ZodLiteral<"PLAN_FORBIDDEN">]>;
|
|
6
|
+
code: z4.ZodUnion<readonly [z4.ZodLiteral<"SUCCESS">, z4.ZodLiteral<"ACTION_REQUIRED">, z4.ZodLiteral<"CREATED">, z4.ZodLiteral<"WARNING">, z4.ZodLiteral<"AUTHORIZATION_ERROR">, z4.ZodLiteral<"SCHEMA_VALIDATION">, z4.ZodLiteral<"SERVER_ERROR">, z4.ZodLiteral<"UNAUTHORIZED">, z4.ZodLiteral<"INVALID_TOKEN">, z4.ZodLiteral<"NOT_FOUND">, z4.ZodLiteral<"SUCCESS_FILE">, z4.ZodLiteral<"DATABASE_ERROR">, z4.ZodLiteral<"BUSINESS_RULE_VIOLATION">, z4.ZodLiteral<"PLAN_FORBIDDEN">, z4.ZodLiteral<"INTEGRATION_ERROR">, z4.ZodLiteral<"TOKEN_AUTH_USER">]>;
|
|
7
7
|
type: z4.ZodDefault<z4.ZodUnion<readonly [z4.ZodLiteral<"success">, z4.ZodLiteral<"warning">, z4.ZodLiteral<"error">]>>;
|
|
8
8
|
message: z4.ZodString;
|
|
9
9
|
results: z4.ZodOptional<z4.ZodUnknown>;
|
|
@@ -15,7 +15,7 @@ declare namespace TypeControllerResponse {
|
|
|
15
15
|
export namespace C {
|
|
16
16
|
export const InputSchema: z4.ZodObject<{
|
|
17
17
|
status: z4.ZodUnion<readonly [z4.ZodLiteral<200>, z4.ZodLiteral<201>, z4.ZodLiteral<202>, z4.ZodLiteral<204>, z4.ZodLiteral<400>, z4.ZodLiteral<401>, z4.ZodLiteral<403>, z4.ZodLiteral<404>, z4.ZodLiteral<409>, z4.ZodLiteral<422>, z4.ZodLiteral<500>, z4.ZodLiteral<428>, z4.ZodLiteral<405>]>;
|
|
18
|
-
code: z4.ZodUnion<readonly [z4.ZodLiteral<"SUCCESS">, z4.ZodLiteral<"ACTION_REQUIRED">, z4.ZodLiteral<"CREATED">, z4.ZodLiteral<"WARNING">, z4.ZodLiteral<"AUTHORIZATION_ERROR">, z4.ZodLiteral<"SCHEMA_VALIDATION">, z4.ZodLiteral<"SERVER_ERROR">, z4.ZodLiteral<"UNAUTHORIZED">, z4.ZodLiteral<"INVALID_TOKEN">, z4.ZodLiteral<"NOT_FOUND">, z4.ZodLiteral<"SUCCESS_FILE">, z4.ZodLiteral<"DATABASE_ERROR">, z4.ZodLiteral<"BUSINESS_RULE_VIOLATION">, z4.ZodLiteral<"PLAN_FORBIDDEN">]>;
|
|
18
|
+
code: z4.ZodUnion<readonly [z4.ZodLiteral<"SUCCESS">, z4.ZodLiteral<"ACTION_REQUIRED">, z4.ZodLiteral<"CREATED">, z4.ZodLiteral<"WARNING">, z4.ZodLiteral<"AUTHORIZATION_ERROR">, z4.ZodLiteral<"SCHEMA_VALIDATION">, z4.ZodLiteral<"SERVER_ERROR">, z4.ZodLiteral<"UNAUTHORIZED">, z4.ZodLiteral<"INVALID_TOKEN">, z4.ZodLiteral<"NOT_FOUND">, z4.ZodLiteral<"SUCCESS_FILE">, z4.ZodLiteral<"DATABASE_ERROR">, z4.ZodLiteral<"BUSINESS_RULE_VIOLATION">, z4.ZodLiteral<"PLAN_FORBIDDEN">, z4.ZodLiteral<"INTEGRATION_ERROR">, z4.ZodLiteral<"TOKEN_AUTH_USER">]>;
|
|
19
19
|
type: z4.ZodDefault<z4.ZodOptional<z4.ZodDefault<z4.ZodUnion<readonly [z4.ZodLiteral<"success">, z4.ZodLiteral<"warning">, z4.ZodLiteral<"error">]>>>>;
|
|
20
20
|
message: z4.ZodOptional<z4.ZodString>;
|
|
21
21
|
results: z4.ZodAny;
|
|
@@ -28,6 +28,7 @@ declare namespace TypeControllerResponse {
|
|
|
28
28
|
const FileResponseParamsSchema: z4.ZodObject<{
|
|
29
29
|
status: z4.ZodUnion<readonly [z4.ZodLiteral<200>, z4.ZodLiteral<201>, z4.ZodLiteral<202>, z4.ZodLiteral<204>, z4.ZodLiteral<400>, z4.ZodLiteral<401>, z4.ZodLiteral<403>, z4.ZodLiteral<404>, z4.ZodLiteral<409>, z4.ZodLiteral<422>, z4.ZodLiteral<500>, z4.ZodLiteral<428>, z4.ZodLiteral<405>]>;
|
|
30
30
|
message: z4.ZodOptional<z4.ZodString>;
|
|
31
|
+
fn: z4.ZodString;
|
|
31
32
|
file_buffer: z4.ZodUnion<readonly [z4.ZodCustom<Blob, Blob>, z4.ZodCustom<ArrayBuffer, ArrayBuffer>, z4.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>]>;
|
|
32
33
|
content_type: z4.ZodString;
|
|
33
34
|
filename: z4.ZodOptional<z4.ZodString>;
|
|
@@ -41,9 +42,8 @@ declare namespace TypeControllerResponse {
|
|
|
41
42
|
message: z4.ZodOptional<z4.ZodString>;
|
|
42
43
|
results: z4.ZodOptional<z4.ZodUnion<readonly [z4.ZodArray<z4.ZodUnknown>, z4.ZodUnknown]>>;
|
|
43
44
|
type: z4.ZodDefault<z4.ZodOptional<z4.ZodDefault<z4.ZodUnion<readonly [z4.ZodLiteral<"success">, z4.ZodLiteral<"warning">, z4.ZodLiteral<"error">]>>>>;
|
|
44
|
-
code: z4.ZodUnion<readonly [z4.ZodLiteral<"SUCCESS">, z4.ZodLiteral<"ACTION_REQUIRED">, z4.ZodLiteral<"CREATED">, z4.ZodLiteral<"WARNING">, z4.ZodLiteral<"AUTHORIZATION_ERROR">, z4.ZodLiteral<"SCHEMA_VALIDATION">, z4.ZodLiteral<"SERVER_ERROR">, z4.ZodLiteral<"UNAUTHORIZED">, z4.ZodLiteral<"INVALID_TOKEN">, z4.ZodLiteral<"NOT_FOUND">, z4.ZodLiteral<"SUCCESS_FILE">, z4.ZodLiteral<"DATABASE_ERROR">, z4.ZodLiteral<"BUSINESS_RULE_VIOLATION">, z4.ZodLiteral<"PLAN_FORBIDDEN">]>;
|
|
45
|
+
code: z4.ZodUnion<readonly [z4.ZodLiteral<"SUCCESS">, z4.ZodLiteral<"ACTION_REQUIRED">, z4.ZodLiteral<"CREATED">, z4.ZodLiteral<"WARNING">, z4.ZodLiteral<"AUTHORIZATION_ERROR">, z4.ZodLiteral<"SCHEMA_VALIDATION">, z4.ZodLiteral<"SERVER_ERROR">, z4.ZodLiteral<"UNAUTHORIZED">, z4.ZodLiteral<"INVALID_TOKEN">, z4.ZodLiteral<"NOT_FOUND">, z4.ZodLiteral<"SUCCESS_FILE">, z4.ZodLiteral<"DATABASE_ERROR">, z4.ZodLiteral<"BUSINESS_RULE_VIOLATION">, z4.ZodLiteral<"PLAN_FORBIDDEN">, z4.ZodLiteral<"INTEGRATION_ERROR">, z4.ZodLiteral<"TOKEN_AUTH_USER">]>;
|
|
45
46
|
status: z4.ZodDefault<z4.ZodOptional<z4.ZodNumber>>;
|
|
46
|
-
fn: z4.ZodOptional<z4.ZodString>;
|
|
47
47
|
}, z4.core.$strip>;
|
|
48
48
|
type Input<T = unknown> = z4.infer<typeof InputSchema> & {
|
|
49
49
|
results?: T;
|