@navservice/core 1.116.0 → 1.120.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 +42 -33
- package/build/es/helpers/_token.d.ts +2 -2
- package/build/es/helpers/index.d.ts +62 -91
- package/build/es/helpers.js +119 -70
- 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 +42 -33
- package/build/lib/helpers/_token.d.ts +2 -2
- package/build/lib/helpers/index.d.ts +62 -91
- package/build/lib/helpers.cjs +119 -70
- 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",
|
|
@@ -121,7 +121,7 @@ const set_response = new class set_response {
|
|
|
121
121
|
results: results || []
|
|
122
122
|
};
|
|
123
123
|
helpers_logger.add({
|
|
124
|
-
fn:
|
|
124
|
+
fn: `${fn}_SUCCESS`,
|
|
125
125
|
level: "info",
|
|
126
126
|
message: payload?.message,
|
|
127
127
|
results: payload?.results
|
|
@@ -130,7 +130,7 @@ const set_response = new class set_response {
|
|
|
130
130
|
status: 200
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
|
-
ACTION_REQUIRED({ message, results, c }) {
|
|
133
|
+
ACTION_REQUIRED({ message, results, c, fn }) {
|
|
134
134
|
const payload = {
|
|
135
135
|
status: 428,
|
|
136
136
|
code: "ACTION_REQUIRED",
|
|
@@ -139,7 +139,7 @@ const set_response = new class set_response {
|
|
|
139
139
|
results: results || []
|
|
140
140
|
};
|
|
141
141
|
helpers_logger.add({
|
|
142
|
-
fn:
|
|
142
|
+
fn: `${fn}_ACTION_REQUIRED`,
|
|
143
143
|
level: "info",
|
|
144
144
|
message: payload?.message,
|
|
145
145
|
results: payload?.results
|
|
@@ -148,7 +148,7 @@ const set_response = new class set_response {
|
|
|
148
148
|
status: 428
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
|
-
CREATED({ message, results, c }) {
|
|
151
|
+
CREATED({ message, results, c, fn }) {
|
|
152
152
|
const payload = {
|
|
153
153
|
status: 201,
|
|
154
154
|
code: "CREATED",
|
|
@@ -157,7 +157,7 @@ const set_response = new class set_response {
|
|
|
157
157
|
results: results || []
|
|
158
158
|
};
|
|
159
159
|
helpers_logger.add({
|
|
160
|
-
fn:
|
|
160
|
+
fn: `${fn}_CREATED`,
|
|
161
161
|
level: "info",
|
|
162
162
|
message: payload?.message,
|
|
163
163
|
results: payload?.results
|
|
@@ -166,7 +166,7 @@ const set_response = new class set_response {
|
|
|
166
166
|
status: 201
|
|
167
167
|
});
|
|
168
168
|
}
|
|
169
|
-
WARNING({ message, results, c }) {
|
|
169
|
+
WARNING({ message, results, c, fn }) {
|
|
170
170
|
const payload = {
|
|
171
171
|
status: 400,
|
|
172
172
|
code: "WARNING",
|
|
@@ -175,7 +175,7 @@ const set_response = new class set_response {
|
|
|
175
175
|
results: results || []
|
|
176
176
|
};
|
|
177
177
|
helpers_logger.add({
|
|
178
|
-
fn:
|
|
178
|
+
fn: `${fn}_WARNING`,
|
|
179
179
|
level: "info",
|
|
180
180
|
message: payload?.message,
|
|
181
181
|
results: payload?.results
|
|
@@ -184,7 +184,7 @@ const set_response = new class set_response {
|
|
|
184
184
|
status: 400
|
|
185
185
|
});
|
|
186
186
|
}
|
|
187
|
-
AUTHORIZATION_ERROR({ message, results, c }) {
|
|
187
|
+
AUTHORIZATION_ERROR({ message, results, c, fn }) {
|
|
188
188
|
const payload = {
|
|
189
189
|
status: 405,
|
|
190
190
|
code: "WARNING",
|
|
@@ -193,7 +193,7 @@ const set_response = new class set_response {
|
|
|
193
193
|
results: results || []
|
|
194
194
|
};
|
|
195
195
|
helpers_logger.add({
|
|
196
|
-
fn:
|
|
196
|
+
fn: `${fn}_AUTHORIZATION_ERROR`,
|
|
197
197
|
level: "error",
|
|
198
198
|
message: payload?.message,
|
|
199
199
|
results: payload?.results
|
|
@@ -202,7 +202,7 @@ const set_response = new class set_response {
|
|
|
202
202
|
status: 405
|
|
203
203
|
});
|
|
204
204
|
}
|
|
205
|
-
SERVER_ERROR({ error, c }) {
|
|
205
|
+
SERVER_ERROR({ error, c, fn }) {
|
|
206
206
|
if (error instanceof (v4_default()).ZodError) {
|
|
207
207
|
const payload = {
|
|
208
208
|
status: 500,
|
|
@@ -212,7 +212,7 @@ const set_response = new class set_response {
|
|
|
212
212
|
results: v4_default().treeifyError(error)
|
|
213
213
|
};
|
|
214
214
|
helpers_logger.add({
|
|
215
|
-
fn:
|
|
215
|
+
fn: `${fn}_SCHEMA_VALIDATION`,
|
|
216
216
|
level: "error",
|
|
217
217
|
message: payload?.message,
|
|
218
218
|
results: payload?.results
|
|
@@ -230,7 +230,7 @@ const set_response = new class set_response {
|
|
|
230
230
|
};
|
|
231
231
|
if (payload?.type === "error") {
|
|
232
232
|
helpers_logger.add({
|
|
233
|
-
fn:
|
|
233
|
+
fn: `${fn}_SERVER_ERROR`,
|
|
234
234
|
level: payload?.type,
|
|
235
235
|
message: payload?.message,
|
|
236
236
|
results: payload?.results
|
|
@@ -240,7 +240,7 @@ const set_response = new class set_response {
|
|
|
240
240
|
status: error?.status || error?.status || 500
|
|
241
241
|
});
|
|
242
242
|
}
|
|
243
|
-
UNAUTHORIZED({ message, c }) {
|
|
243
|
+
UNAUTHORIZED({ message, c, fn }) {
|
|
244
244
|
const payload = {
|
|
245
245
|
status: 401,
|
|
246
246
|
code: "UNAUTHORIZED",
|
|
@@ -249,7 +249,7 @@ const set_response = new class set_response {
|
|
|
249
249
|
results: []
|
|
250
250
|
};
|
|
251
251
|
helpers_logger.add({
|
|
252
|
-
fn:
|
|
252
|
+
fn: `${fn}_UNAUTHORIZED`,
|
|
253
253
|
level: "error",
|
|
254
254
|
message: payload?.message,
|
|
255
255
|
results: payload?.results
|
|
@@ -258,7 +258,7 @@ const set_response = new class set_response {
|
|
|
258
258
|
status: 401
|
|
259
259
|
});
|
|
260
260
|
}
|
|
261
|
-
INVALID_TOKEN({ message, c }) {
|
|
261
|
+
INVALID_TOKEN({ message, c, fn }) {
|
|
262
262
|
const payload = {
|
|
263
263
|
status: 409,
|
|
264
264
|
code: "INVALID_TOKEN",
|
|
@@ -267,7 +267,7 @@ const set_response = new class set_response {
|
|
|
267
267
|
results: []
|
|
268
268
|
};
|
|
269
269
|
helpers_logger.add({
|
|
270
|
-
fn:
|
|
270
|
+
fn: `${fn}_INVALID_TOKEN`,
|
|
271
271
|
level: "error",
|
|
272
272
|
message: payload?.message,
|
|
273
273
|
results: payload?.results
|
|
@@ -276,7 +276,7 @@ const set_response = new class set_response {
|
|
|
276
276
|
status: 409
|
|
277
277
|
});
|
|
278
278
|
}
|
|
279
|
-
NOT_FOUND({ message, c }) {
|
|
279
|
+
NOT_FOUND({ message, c, fn }) {
|
|
280
280
|
const payload = {
|
|
281
281
|
status: 404,
|
|
282
282
|
code: "NOT_FOUND",
|
|
@@ -285,7 +285,7 @@ const set_response = new class set_response {
|
|
|
285
285
|
results: []
|
|
286
286
|
};
|
|
287
287
|
helpers_logger.add({
|
|
288
|
-
fn:
|
|
288
|
+
fn: `${fn}_NOT_FOUND`,
|
|
289
289
|
level: "info",
|
|
290
290
|
message: payload?.message,
|
|
291
291
|
results: payload?.results
|
|
@@ -294,14 +294,14 @@ const set_response = new class set_response {
|
|
|
294
294
|
status: 404
|
|
295
295
|
});
|
|
296
296
|
}
|
|
297
|
-
async SUCCESS_FILE({ message, file_buffer, content_type, filename, c }) {
|
|
297
|
+
async SUCCESS_FILE({ message, file_buffer, content_type, filename, c, fn }) {
|
|
298
298
|
if (c && content_type) {
|
|
299
299
|
const headers = {
|
|
300
300
|
"Content-Type": content_type,
|
|
301
301
|
"Content-Disposition": filename ? `inline; filename="${filename}"` : "inline"
|
|
302
302
|
};
|
|
303
303
|
helpers_logger.add({
|
|
304
|
-
fn:
|
|
304
|
+
fn: `${fn}_SUCCESS_FILE`,
|
|
305
305
|
level: "info",
|
|
306
306
|
message: "",
|
|
307
307
|
results: headers
|
|
@@ -319,7 +319,7 @@ const set_response = new class set_response {
|
|
|
319
319
|
results: []
|
|
320
320
|
};
|
|
321
321
|
helpers_logger.add({
|
|
322
|
-
fn:
|
|
322
|
+
fn: `${fn}_SUCCESS_FILE`,
|
|
323
323
|
level: "info",
|
|
324
324
|
message: payload?.message,
|
|
325
325
|
results: payload?.results
|
|
@@ -330,7 +330,7 @@ const set_response = new class set_response {
|
|
|
330
330
|
}
|
|
331
331
|
};
|
|
332
332
|
error = new class error {
|
|
333
|
-
ACTION_REQUIRED({ message, results }) {
|
|
333
|
+
ACTION_REQUIRED({ message, results, fn }) {
|
|
334
334
|
const payload = {
|
|
335
335
|
status: 428,
|
|
336
336
|
code: "ACTION_REQUIRED",
|
|
@@ -339,14 +339,14 @@ const set_response = new class set_response {
|
|
|
339
339
|
results: results || []
|
|
340
340
|
};
|
|
341
341
|
helpers_logger.add({
|
|
342
|
-
fn:
|
|
342
|
+
fn: `${fn}_ACTION_REQUIRED`,
|
|
343
343
|
level: "info",
|
|
344
344
|
message: payload?.message,
|
|
345
345
|
results: payload?.results
|
|
346
346
|
});
|
|
347
347
|
throw payload;
|
|
348
348
|
}
|
|
349
|
-
WARNING({ message, results }) {
|
|
349
|
+
WARNING({ message, results, fn }) {
|
|
350
350
|
const payload = {
|
|
351
351
|
status: 400,
|
|
352
352
|
code: "WARNING",
|
|
@@ -355,14 +355,46 @@ const set_response = new class set_response {
|
|
|
355
355
|
results: results || []
|
|
356
356
|
};
|
|
357
357
|
helpers_logger.add({
|
|
358
|
-
fn:
|
|
358
|
+
fn: `${fn}_WARNING`,
|
|
359
359
|
level: "info",
|
|
360
360
|
message: payload?.message,
|
|
361
361
|
results: payload?.results
|
|
362
362
|
});
|
|
363
363
|
throw payload;
|
|
364
364
|
}
|
|
365
|
-
|
|
365
|
+
ERROR({ message, results, fn }) {
|
|
366
|
+
const payload = {
|
|
367
|
+
status: 400,
|
|
368
|
+
code: "ERROR",
|
|
369
|
+
type: "error",
|
|
370
|
+
message: message || "Aviso!",
|
|
371
|
+
results: results || []
|
|
372
|
+
};
|
|
373
|
+
helpers_logger.add({
|
|
374
|
+
fn: `${fn}_ERROR`,
|
|
375
|
+
level: "info",
|
|
376
|
+
message: payload?.message,
|
|
377
|
+
results: payload?.results
|
|
378
|
+
});
|
|
379
|
+
throw payload;
|
|
380
|
+
}
|
|
381
|
+
TOKEN_AUTH_USER({ message, results, fn }) {
|
|
382
|
+
const payload = {
|
|
383
|
+
status: 410,
|
|
384
|
+
code: "TOKEN_AUTH_USER",
|
|
385
|
+
type: "warning",
|
|
386
|
+
message: message || "Erro processo de auth token!",
|
|
387
|
+
results: results || []
|
|
388
|
+
};
|
|
389
|
+
helpers_logger.add({
|
|
390
|
+
fn: `${fn}_REFRESH_TOKEN_AUTH_USER`,
|
|
391
|
+
level: "error",
|
|
392
|
+
message: payload?.message,
|
|
393
|
+
results: payload?.results
|
|
394
|
+
});
|
|
395
|
+
throw payload;
|
|
396
|
+
}
|
|
397
|
+
AUTHORIZATION_ERROR({ message, results, fn }) {
|
|
366
398
|
const payload = {
|
|
367
399
|
status: 400,
|
|
368
400
|
code: "WARNING",
|
|
@@ -371,7 +403,7 @@ const set_response = new class set_response {
|
|
|
371
403
|
results: results || []
|
|
372
404
|
};
|
|
373
405
|
helpers_logger.add({
|
|
374
|
-
fn:
|
|
406
|
+
fn: `${fn}_AUTHORIZATION_ERROR`,
|
|
375
407
|
level: "error",
|
|
376
408
|
message: payload?.message,
|
|
377
409
|
results: payload?.results
|
|
@@ -379,7 +411,7 @@ const set_response = new class set_response {
|
|
|
379
411
|
throw payload;
|
|
380
412
|
}
|
|
381
413
|
// CONTEM _LOGGER PARA FACILITAR OS LOGS DE TRACING DO SISTEMA
|
|
382
|
-
DATABASE_ERROR({ message, erro }) {
|
|
414
|
+
DATABASE_ERROR({ message, erro, fn }) {
|
|
383
415
|
const errorCode = erro?.cause?.code || erro?.cause?.cause?.code || erro?.code || "";
|
|
384
416
|
const map = {
|
|
385
417
|
"SQLITE_CONSTRAINT_UNIQUE": {
|
|
@@ -423,14 +455,14 @@ const set_response = new class set_response {
|
|
|
423
455
|
results: []
|
|
424
456
|
};
|
|
425
457
|
helpers_logger.add({
|
|
426
|
-
fn:
|
|
458
|
+
fn: `${fn}_DATABASE_ERROR`,
|
|
427
459
|
level: "error",
|
|
428
460
|
message: payload?.message,
|
|
429
461
|
results: erro
|
|
430
462
|
});
|
|
431
463
|
throw payload;
|
|
432
464
|
}
|
|
433
|
-
SCHEMA_VALIDATION({ results }) {
|
|
465
|
+
SCHEMA_VALIDATION({ results, fn }) {
|
|
434
466
|
const payload = {
|
|
435
467
|
status: 500,
|
|
436
468
|
code: "SCHEMA_VALIDATION",
|
|
@@ -439,14 +471,14 @@ const set_response = new class set_response {
|
|
|
439
471
|
results: results || []
|
|
440
472
|
};
|
|
441
473
|
helpers_logger.add({
|
|
442
|
-
fn:
|
|
474
|
+
fn: `${fn}_SCHEMA_VALIDATION`,
|
|
443
475
|
level: "error",
|
|
444
476
|
message: payload?.message,
|
|
445
477
|
results: payload?.results
|
|
446
478
|
});
|
|
447
479
|
throw payload;
|
|
448
480
|
}
|
|
449
|
-
UNAUTHORIZED({ message }) {
|
|
481
|
+
UNAUTHORIZED({ message, fn }) {
|
|
450
482
|
const payload = {
|
|
451
483
|
status: 401,
|
|
452
484
|
code: "UNAUTHORIZED",
|
|
@@ -454,60 +486,62 @@ const set_response = new class set_response {
|
|
|
454
486
|
message: message || "Não autorizado!"
|
|
455
487
|
};
|
|
456
488
|
helpers_logger.add({
|
|
457
|
-
fn:
|
|
489
|
+
fn: `${fn}_UNAUTHORIZED`,
|
|
458
490
|
level: "error",
|
|
459
491
|
message: payload?.message,
|
|
460
492
|
results: payload?.results
|
|
461
493
|
});
|
|
462
494
|
throw payload;
|
|
463
495
|
}
|
|
464
|
-
INTEGRATION_ERROR({ message }) {
|
|
496
|
+
INTEGRATION_ERROR({ message, fn, erro }) {
|
|
465
497
|
const payload = {
|
|
466
498
|
status: 401,
|
|
467
499
|
code: "INTEGRATION_ERROR",
|
|
468
500
|
type: "error",
|
|
469
|
-
message: message || "Erro na camada de integração!"
|
|
501
|
+
message: message || "Erro na camada de integração!",
|
|
502
|
+
results: erro
|
|
470
503
|
};
|
|
471
504
|
helpers_logger.add({
|
|
472
|
-
fn:
|
|
505
|
+
fn: `${fn}_INTEGRATION_ERROR`,
|
|
473
506
|
level: "error",
|
|
474
507
|
message: payload?.message,
|
|
475
|
-
results:
|
|
508
|
+
results: erro
|
|
476
509
|
});
|
|
477
510
|
throw payload;
|
|
478
511
|
}
|
|
479
|
-
INVALID_TOKEN({ message }) {
|
|
512
|
+
INVALID_TOKEN({ message, fn, results }) {
|
|
480
513
|
const payload = {
|
|
481
514
|
status: 401,
|
|
482
515
|
code: "INVALID_TOKEN",
|
|
483
516
|
type: "warning",
|
|
484
517
|
message: message || "Token inválido!",
|
|
485
|
-
results: []
|
|
518
|
+
results: results || []
|
|
486
519
|
};
|
|
487
520
|
helpers_logger.add({
|
|
488
|
-
fn:
|
|
521
|
+
fn: `${fn}_INVALID_TOKEN`,
|
|
489
522
|
level: "error",
|
|
490
523
|
message: payload?.message,
|
|
491
524
|
results: payload?.results
|
|
492
525
|
});
|
|
493
526
|
throw payload;
|
|
494
527
|
}
|
|
495
|
-
NOT_FOUND({ message }) {
|
|
528
|
+
NOT_FOUND({ message, fn, results }) {
|
|
496
529
|
const payload = {
|
|
497
530
|
status: 404,
|
|
498
531
|
code: "NOT_FOUND",
|
|
499
532
|
type: "error",
|
|
500
|
-
message: message || "Recurso não encontrado!"
|
|
533
|
+
message: message || "Recurso não encontrado!",
|
|
534
|
+
results: results || []
|
|
501
535
|
};
|
|
502
536
|
helpers_logger.add({
|
|
503
|
-
fn:
|
|
537
|
+
fn: `${fn}_NOT_FOUND`,
|
|
504
538
|
level: "info",
|
|
505
539
|
message: payload?.message,
|
|
506
540
|
results: payload?.results
|
|
507
541
|
});
|
|
508
542
|
throw payload;
|
|
509
543
|
}
|
|
510
|
-
BUSINESS_RULE_VIOLATION({ message, results }) {
|
|
544
|
+
BUSINESS_RULE_VIOLATION({ message, results, fn }) {
|
|
511
545
|
const payload = {
|
|
512
546
|
status: 422,
|
|
513
547
|
code: "BUSINESS_RULE_VIOLATION",
|
|
@@ -516,14 +550,14 @@ const set_response = new class set_response {
|
|
|
516
550
|
results: results || []
|
|
517
551
|
};
|
|
518
552
|
helpers_logger.add({
|
|
519
|
-
fn:
|
|
553
|
+
fn: `${fn}_BUSINESS_RULE_VIOLATION`,
|
|
520
554
|
level: "info",
|
|
521
555
|
message: payload?.message,
|
|
522
556
|
results: payload?.results
|
|
523
557
|
});
|
|
524
558
|
throw payload;
|
|
525
559
|
}
|
|
526
|
-
PLAN_FORBIDDEN({ message, results }) {
|
|
560
|
+
PLAN_FORBIDDEN({ message, results, fn }) {
|
|
527
561
|
const payload = {
|
|
528
562
|
status: 403,
|
|
529
563
|
code: "PLAN_FORBIDDEN",
|
|
@@ -532,7 +566,7 @@ const set_response = new class set_response {
|
|
|
532
566
|
results: results || []
|
|
533
567
|
};
|
|
534
568
|
helpers_logger.add({
|
|
535
|
-
fn:
|
|
569
|
+
fn: `${fn}_PLAN_FORBIDDEN`,
|
|
536
570
|
level: "info",
|
|
537
571
|
message: payload?.message,
|
|
538
572
|
results: payload?.results
|
|
@@ -549,6 +583,7 @@ const external_jose_namespaceObject = require("jose");
|
|
|
549
583
|
|
|
550
584
|
// Tem que importar assim para evitar dependencia circular
|
|
551
585
|
|
|
586
|
+
const _token_fn = 'token';
|
|
552
587
|
const _token = new class _token {
|
|
553
588
|
async verificar_token(c, next) {
|
|
554
589
|
try {
|
|
@@ -556,13 +591,15 @@ const _token = new class _token {
|
|
|
556
591
|
if (!authHeader) return _set_response.c.INVALID_TOKEN({
|
|
557
592
|
message: 'token não enviado!!!',
|
|
558
593
|
c: c,
|
|
559
|
-
results: []
|
|
594
|
+
results: [],
|
|
595
|
+
fn: _token_fn
|
|
560
596
|
});
|
|
561
597
|
const token = authHeader.split(" ")[1];
|
|
562
598
|
if (!token) return _set_response.c.INVALID_TOKEN({
|
|
563
599
|
message: 'Acesso negado!!!',
|
|
564
600
|
c: c,
|
|
565
|
-
results: []
|
|
601
|
+
results: [],
|
|
602
|
+
fn: _token_fn
|
|
566
603
|
});
|
|
567
604
|
const secret = new TextEncoder().encode(c.env.JSON_WEB_TOKEN_AUTH_USER);
|
|
568
605
|
const { payload } = await external_jose_namespaceObject.jwtVerify(token, secret);
|
|
@@ -570,7 +607,8 @@ const _token = new class _token {
|
|
|
570
607
|
return _set_response.c.INVALID_TOKEN({
|
|
571
608
|
message: 'Token inválido!!!!',
|
|
572
609
|
c: c,
|
|
573
|
-
results: []
|
|
610
|
+
results: [],
|
|
611
|
+
fn: _token_fn
|
|
574
612
|
});
|
|
575
613
|
}
|
|
576
614
|
const setar_token = {
|
|
@@ -591,15 +629,17 @@ const _token = new class _token {
|
|
|
591
629
|
return _set_response.c.INVALID_TOKEN({
|
|
592
630
|
message: 'Token inválido!!!',
|
|
593
631
|
c: c,
|
|
594
|
-
results: []
|
|
632
|
+
results: [],
|
|
633
|
+
fn: _token_fn
|
|
595
634
|
});
|
|
596
635
|
}
|
|
597
636
|
}
|
|
598
637
|
async criar_token_login_usuario(props) {
|
|
599
638
|
if (!props?.c.env.JSON_WEB_TOKEN_AUTH_USER) {
|
|
600
639
|
_set_response.error.WARNING({
|
|
601
|
-
message: "Erro ao gerar token!!",
|
|
602
|
-
results: []
|
|
640
|
+
message: "Erro ao gerar token auth!!",
|
|
641
|
+
results: [],
|
|
642
|
+
fn: _token_fn
|
|
603
643
|
});
|
|
604
644
|
}
|
|
605
645
|
const token = await new external_jose_namespaceObject.SignJWT({
|
|
@@ -615,9 +655,10 @@ const _token = new class _token {
|
|
|
615
655
|
}).setProtectedHeader({
|
|
616
656
|
alg: "HS256"
|
|
617
657
|
}).setIssuedAt().setExpirationTime("1h").sign(new TextEncoder().encode(props?.c.env.JSON_WEB_TOKEN_AUTH_USER)).catch((error)=>{
|
|
618
|
-
return _set_response.error.
|
|
619
|
-
message: "Erro ao gerar token!",
|
|
620
|
-
results: error?.message
|
|
658
|
+
return _set_response.error.TOKEN_AUTH_USER({
|
|
659
|
+
message: "Erro ao gerar token auth user!",
|
|
660
|
+
results: error?.message,
|
|
661
|
+
fn: _token_fn
|
|
621
662
|
});
|
|
622
663
|
});
|
|
623
664
|
return token;
|
|
@@ -628,13 +669,15 @@ const _token = new class _token {
|
|
|
628
669
|
if (!authHeader) return _set_response.c.INVALID_TOKEN({
|
|
629
670
|
message: 'token service não enviado!',
|
|
630
671
|
c: c,
|
|
631
|
-
results: []
|
|
672
|
+
results: [],
|
|
673
|
+
fn: _token_fn
|
|
632
674
|
});
|
|
633
675
|
const token = authHeader.split(" ")[1];
|
|
634
676
|
if (!token) return _set_response.c.INVALID_TOKEN({
|
|
635
677
|
message: 'Acesso negado ao serviço!',
|
|
636
678
|
c: c,
|
|
637
|
-
results: []
|
|
679
|
+
results: [],
|
|
680
|
+
fn: _token_fn
|
|
638
681
|
});
|
|
639
682
|
const secret = new TextEncoder().encode(c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO);
|
|
640
683
|
const { payload } = await external_jose_namespaceObject.jwtVerify(token, secret);
|
|
@@ -642,7 +685,8 @@ const _token = new class _token {
|
|
|
642
685
|
return _set_response.c.INVALID_TOKEN({
|
|
643
686
|
message: 'Token inválido para o serviço!',
|
|
644
687
|
c: c,
|
|
645
|
-
results: []
|
|
688
|
+
results: [],
|
|
689
|
+
fn: _token_fn
|
|
646
690
|
});
|
|
647
691
|
}
|
|
648
692
|
const setar_token = {
|
|
@@ -662,15 +706,17 @@ const _token = new class _token {
|
|
|
662
706
|
return _set_response.c.INVALID_TOKEN({
|
|
663
707
|
message: 'Erro token inválido!',
|
|
664
708
|
c: c,
|
|
665
|
-
results: []
|
|
709
|
+
results: [],
|
|
710
|
+
fn: _token_fn
|
|
666
711
|
});
|
|
667
712
|
}
|
|
668
713
|
}
|
|
669
714
|
async criar_token_micro_servico({ c }) {
|
|
670
715
|
if (!c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO) {
|
|
671
|
-
|
|
716
|
+
_set_response.error.WARNING({
|
|
672
717
|
message: "Erro ao gerar token!!",
|
|
673
|
-
results: []
|
|
718
|
+
results: [],
|
|
719
|
+
fn: _token_fn
|
|
674
720
|
});
|
|
675
721
|
}
|
|
676
722
|
const usuario_auth = c.get("usuario_auth");
|
|
@@ -687,18 +733,20 @@ const _token = new class _token {
|
|
|
687
733
|
}).setProtectedHeader({
|
|
688
734
|
alg: "HS256"
|
|
689
735
|
}).setIssuedAt().setExpirationTime("30s").sign(new TextEncoder().encode(c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO)).catch((error)=>{
|
|
690
|
-
return _set_response.error.
|
|
691
|
-
message: "Erro ao gerar token!",
|
|
692
|
-
results: error?.message
|
|
736
|
+
return _set_response.error.TOKEN_AUTH_USER({
|
|
737
|
+
message: "Erro ao gerar token micro serviço!",
|
|
738
|
+
results: error?.message,
|
|
739
|
+
fn: _token_fn
|
|
693
740
|
});
|
|
694
741
|
});
|
|
695
742
|
return token;
|
|
696
743
|
}
|
|
697
744
|
async criar_refresh_token({ env, usuario_id }) {
|
|
698
745
|
if (!env.JSON_WEB_REFRESH_TOKEN_AUTH_USER) {
|
|
699
|
-
|
|
746
|
+
_set_response.error.TOKEN_AUTH_USER({
|
|
700
747
|
message: "Erro ao gerar refresh token!!",
|
|
701
|
-
results: []
|
|
748
|
+
results: [],
|
|
749
|
+
fn: _token_fn
|
|
702
750
|
});
|
|
703
751
|
}
|
|
704
752
|
const token = await new external_jose_namespaceObject.SignJWT({
|
|
@@ -706,8 +754,9 @@ const _token = new class _token {
|
|
|
706
754
|
}).setProtectedHeader({
|
|
707
755
|
alg: "HS256"
|
|
708
756
|
}).setIssuedAt().setExpirationTime("2h").sign(new TextEncoder().encode(env.JSON_WEB_REFRESH_TOKEN_AUTH_USER)).catch((error)=>{
|
|
709
|
-
return _set_response.error.
|
|
710
|
-
message: "Erro ao gerar refresh token!"
|
|
757
|
+
return _set_response.error.TOKEN_AUTH_USER({
|
|
758
|
+
message: "Erro ao gerar refresh token!",
|
|
759
|
+
fn: _token_fn
|
|
711
760
|
});
|
|
712
761
|
});
|
|
713
762
|
return token;
|
package/build/lib/index.cjs
CHANGED
|
@@ -144,6 +144,7 @@ var _usuario_TypeControllerUsuario;
|
|
|
144
144
|
v4_default().literal("ACTION_REQUIRED"),
|
|
145
145
|
v4_default().literal("CREATED"),
|
|
146
146
|
v4_default().literal("WARNING"),
|
|
147
|
+
v4_default().literal("ERROR"),
|
|
147
148
|
v4_default().literal("AUTHORIZATION_ERROR"),
|
|
148
149
|
v4_default().literal("SCHEMA_VALIDATION"),
|
|
149
150
|
v4_default().literal("SERVER_ERROR"),
|
|
@@ -154,7 +155,8 @@ var _usuario_TypeControllerUsuario;
|
|
|
154
155
|
v4_default().literal("DATABASE_ERROR"),
|
|
155
156
|
v4_default().literal("BUSINESS_RULE_VIOLATION"),
|
|
156
157
|
v4_default().literal("PLAN_FORBIDDEN"),
|
|
157
|
-
v4_default().literal("INTEGRATION_ERROR")
|
|
158
|
+
v4_default().literal("INTEGRATION_ERROR"),
|
|
159
|
+
v4_default().literal("TOKEN_AUTH_USER")
|
|
158
160
|
]);
|
|
159
161
|
const BaseResponseSchema = v4_default().object({
|
|
160
162
|
status: StatusSchema,
|
|
@@ -176,6 +178,7 @@ var _usuario_TypeControllerUsuario;
|
|
|
176
178
|
const FileResponseParamsSchema = v4_default().object({
|
|
177
179
|
status: StatusSchema,
|
|
178
180
|
message: v4_default().string().optional(),
|
|
181
|
+
fn: v4_default().string(),
|
|
179
182
|
file_buffer: v4_default().union([
|
|
180
183
|
v4_default()["instanceof"](Blob),
|
|
181
184
|
v4_default()["instanceof"](ArrayBuffer),
|
|
@@ -195,8 +198,7 @@ var _usuario_TypeControllerUsuario;
|
|
|
195
198
|
]).optional(),
|
|
196
199
|
type: TypeSchema.optional().default("success"),
|
|
197
200
|
code: CodeSchema,
|
|
198
|
-
status: v4_default().number().optional().default(200)
|
|
199
|
-
fn: v4_default().string().optional()
|
|
201
|
+
status: v4_default().number().optional().default(200)
|
|
200
202
|
});
|
|
201
203
|
})(TypeControllerResponse.Error || (TypeControllerResponse.Error = {}));
|
|
202
204
|
})(_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">, z4.ZodLiteral<"INTEGRATION_ERROR">]>;
|
|
6
|
+
code: z4.ZodUnion<readonly [z4.ZodLiteral<"SUCCESS">, z4.ZodLiteral<"ACTION_REQUIRED">, z4.ZodLiteral<"CREATED">, z4.ZodLiteral<"WARNING">, z4.ZodLiteral<"ERROR">, 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">, z4.ZodLiteral<"INTEGRATION_ERROR">]>;
|
|
18
|
+
code: z4.ZodUnion<readonly [z4.ZodLiteral<"SUCCESS">, z4.ZodLiteral<"ACTION_REQUIRED">, z4.ZodLiteral<"CREATED">, z4.ZodLiteral<"WARNING">, z4.ZodLiteral<"ERROR">, 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">, z4.ZodLiteral<"INTEGRATION_ERROR">]>;
|
|
45
|
+
code: z4.ZodUnion<readonly [z4.ZodLiteral<"SUCCESS">, z4.ZodLiteral<"ACTION_REQUIRED">, z4.ZodLiteral<"CREATED">, z4.ZodLiteral<"WARNING">, z4.ZodLiteral<"ERROR">, 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;
|