@navservice/core 1.116.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 -33
- package/build/es/helpers/_token.d.ts +2 -2
- package/build/es/helpers/index.d.ts +59 -91
- package/build/es/helpers.js +103 -70
- package/build/es/index.js +4 -3
- package/build/es/types/_type_response.d.ts +4 -4
- package/build/lib/helpers/_set_response.d.ts +41 -33
- package/build/lib/helpers/_token.d.ts +2 -2
- package/build/lib/helpers/index.d.ts +59 -91
- package/build/lib/helpers.cjs +103 -70
- package/build/lib/index.cjs +4 -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,30 @@ 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
|
+
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 }) {
|
|
366
382
|
const payload = {
|
|
367
383
|
status: 400,
|
|
368
384
|
code: "WARNING",
|
|
@@ -371,7 +387,7 @@ const set_response = new class set_response {
|
|
|
371
387
|
results: results || []
|
|
372
388
|
};
|
|
373
389
|
helpers_logger.add({
|
|
374
|
-
fn:
|
|
390
|
+
fn: `${fn}_AUTHORIZATION_ERROR`,
|
|
375
391
|
level: "error",
|
|
376
392
|
message: payload?.message,
|
|
377
393
|
results: payload?.results
|
|
@@ -379,7 +395,7 @@ const set_response = new class set_response {
|
|
|
379
395
|
throw payload;
|
|
380
396
|
}
|
|
381
397
|
// CONTEM _LOGGER PARA FACILITAR OS LOGS DE TRACING DO SISTEMA
|
|
382
|
-
DATABASE_ERROR({ message, erro }) {
|
|
398
|
+
DATABASE_ERROR({ message, erro, fn }) {
|
|
383
399
|
const errorCode = erro?.cause?.code || erro?.cause?.cause?.code || erro?.code || "";
|
|
384
400
|
const map = {
|
|
385
401
|
"SQLITE_CONSTRAINT_UNIQUE": {
|
|
@@ -423,14 +439,14 @@ const set_response = new class set_response {
|
|
|
423
439
|
results: []
|
|
424
440
|
};
|
|
425
441
|
helpers_logger.add({
|
|
426
|
-
fn:
|
|
442
|
+
fn: `${fn}_DATABASE_ERROR`,
|
|
427
443
|
level: "error",
|
|
428
444
|
message: payload?.message,
|
|
429
445
|
results: erro
|
|
430
446
|
});
|
|
431
447
|
throw payload;
|
|
432
448
|
}
|
|
433
|
-
SCHEMA_VALIDATION({ results }) {
|
|
449
|
+
SCHEMA_VALIDATION({ results, fn }) {
|
|
434
450
|
const payload = {
|
|
435
451
|
status: 500,
|
|
436
452
|
code: "SCHEMA_VALIDATION",
|
|
@@ -439,14 +455,14 @@ const set_response = new class set_response {
|
|
|
439
455
|
results: results || []
|
|
440
456
|
};
|
|
441
457
|
helpers_logger.add({
|
|
442
|
-
fn:
|
|
458
|
+
fn: `${fn}_SCHEMA_VALIDATION`,
|
|
443
459
|
level: "error",
|
|
444
460
|
message: payload?.message,
|
|
445
461
|
results: payload?.results
|
|
446
462
|
});
|
|
447
463
|
throw payload;
|
|
448
464
|
}
|
|
449
|
-
UNAUTHORIZED({ message }) {
|
|
465
|
+
UNAUTHORIZED({ message, fn }) {
|
|
450
466
|
const payload = {
|
|
451
467
|
status: 401,
|
|
452
468
|
code: "UNAUTHORIZED",
|
|
@@ -454,60 +470,62 @@ const set_response = new class set_response {
|
|
|
454
470
|
message: message || "Não autorizado!"
|
|
455
471
|
};
|
|
456
472
|
helpers_logger.add({
|
|
457
|
-
fn:
|
|
473
|
+
fn: `${fn}_UNAUTHORIZED`,
|
|
458
474
|
level: "error",
|
|
459
475
|
message: payload?.message,
|
|
460
476
|
results: payload?.results
|
|
461
477
|
});
|
|
462
478
|
throw payload;
|
|
463
479
|
}
|
|
464
|
-
INTEGRATION_ERROR({ message }) {
|
|
480
|
+
INTEGRATION_ERROR({ message, fn, erro }) {
|
|
465
481
|
const payload = {
|
|
466
482
|
status: 401,
|
|
467
483
|
code: "INTEGRATION_ERROR",
|
|
468
484
|
type: "error",
|
|
469
|
-
message: message || "Erro na camada de integração!"
|
|
485
|
+
message: message || "Erro na camada de integração!",
|
|
486
|
+
results: erro
|
|
470
487
|
};
|
|
471
488
|
helpers_logger.add({
|
|
472
|
-
fn:
|
|
489
|
+
fn: `${fn}_INTEGRATION_ERROR`,
|
|
473
490
|
level: "error",
|
|
474
491
|
message: payload?.message,
|
|
475
|
-
results:
|
|
492
|
+
results: erro
|
|
476
493
|
});
|
|
477
494
|
throw payload;
|
|
478
495
|
}
|
|
479
|
-
INVALID_TOKEN({ message }) {
|
|
496
|
+
INVALID_TOKEN({ message, fn, results }) {
|
|
480
497
|
const payload = {
|
|
481
498
|
status: 401,
|
|
482
499
|
code: "INVALID_TOKEN",
|
|
483
500
|
type: "warning",
|
|
484
501
|
message: message || "Token inválido!",
|
|
485
|
-
results: []
|
|
502
|
+
results: results || []
|
|
486
503
|
};
|
|
487
504
|
helpers_logger.add({
|
|
488
|
-
fn:
|
|
505
|
+
fn: `${fn}_INVALID_TOKEN`,
|
|
489
506
|
level: "error",
|
|
490
507
|
message: payload?.message,
|
|
491
508
|
results: payload?.results
|
|
492
509
|
});
|
|
493
510
|
throw payload;
|
|
494
511
|
}
|
|
495
|
-
NOT_FOUND({ message }) {
|
|
512
|
+
NOT_FOUND({ message, fn, results }) {
|
|
496
513
|
const payload = {
|
|
497
514
|
status: 404,
|
|
498
515
|
code: "NOT_FOUND",
|
|
499
516
|
type: "error",
|
|
500
|
-
message: message || "Recurso não encontrado!"
|
|
517
|
+
message: message || "Recurso não encontrado!",
|
|
518
|
+
results: results || []
|
|
501
519
|
};
|
|
502
520
|
helpers_logger.add({
|
|
503
|
-
fn:
|
|
521
|
+
fn: `${fn}_NOT_FOUND`,
|
|
504
522
|
level: "info",
|
|
505
523
|
message: payload?.message,
|
|
506
524
|
results: payload?.results
|
|
507
525
|
});
|
|
508
526
|
throw payload;
|
|
509
527
|
}
|
|
510
|
-
BUSINESS_RULE_VIOLATION({ message, results }) {
|
|
528
|
+
BUSINESS_RULE_VIOLATION({ message, results, fn }) {
|
|
511
529
|
const payload = {
|
|
512
530
|
status: 422,
|
|
513
531
|
code: "BUSINESS_RULE_VIOLATION",
|
|
@@ -516,14 +534,14 @@ const set_response = new class set_response {
|
|
|
516
534
|
results: results || []
|
|
517
535
|
};
|
|
518
536
|
helpers_logger.add({
|
|
519
|
-
fn:
|
|
537
|
+
fn: `${fn}_BUSINESS_RULE_VIOLATION`,
|
|
520
538
|
level: "info",
|
|
521
539
|
message: payload?.message,
|
|
522
540
|
results: payload?.results
|
|
523
541
|
});
|
|
524
542
|
throw payload;
|
|
525
543
|
}
|
|
526
|
-
PLAN_FORBIDDEN({ message, results }) {
|
|
544
|
+
PLAN_FORBIDDEN({ message, results, fn }) {
|
|
527
545
|
const payload = {
|
|
528
546
|
status: 403,
|
|
529
547
|
code: "PLAN_FORBIDDEN",
|
|
@@ -532,7 +550,7 @@ const set_response = new class set_response {
|
|
|
532
550
|
results: results || []
|
|
533
551
|
};
|
|
534
552
|
helpers_logger.add({
|
|
535
|
-
fn:
|
|
553
|
+
fn: `${fn}_PLAN_FORBIDDEN`,
|
|
536
554
|
level: "info",
|
|
537
555
|
message: payload?.message,
|
|
538
556
|
results: payload?.results
|
|
@@ -549,6 +567,7 @@ const external_jose_namespaceObject = require("jose");
|
|
|
549
567
|
|
|
550
568
|
// Tem que importar assim para evitar dependencia circular
|
|
551
569
|
|
|
570
|
+
const _token_fn = 'token';
|
|
552
571
|
const _token = new class _token {
|
|
553
572
|
async verificar_token(c, next) {
|
|
554
573
|
try {
|
|
@@ -556,13 +575,15 @@ const _token = new class _token {
|
|
|
556
575
|
if (!authHeader) return _set_response.c.INVALID_TOKEN({
|
|
557
576
|
message: 'token não enviado!!!',
|
|
558
577
|
c: c,
|
|
559
|
-
results: []
|
|
578
|
+
results: [],
|
|
579
|
+
fn: _token_fn
|
|
560
580
|
});
|
|
561
581
|
const token = authHeader.split(" ")[1];
|
|
562
582
|
if (!token) return _set_response.c.INVALID_TOKEN({
|
|
563
583
|
message: 'Acesso negado!!!',
|
|
564
584
|
c: c,
|
|
565
|
-
results: []
|
|
585
|
+
results: [],
|
|
586
|
+
fn: _token_fn
|
|
566
587
|
});
|
|
567
588
|
const secret = new TextEncoder().encode(c.env.JSON_WEB_TOKEN_AUTH_USER);
|
|
568
589
|
const { payload } = await external_jose_namespaceObject.jwtVerify(token, secret);
|
|
@@ -570,7 +591,8 @@ const _token = new class _token {
|
|
|
570
591
|
return _set_response.c.INVALID_TOKEN({
|
|
571
592
|
message: 'Token inválido!!!!',
|
|
572
593
|
c: c,
|
|
573
|
-
results: []
|
|
594
|
+
results: [],
|
|
595
|
+
fn: _token_fn
|
|
574
596
|
});
|
|
575
597
|
}
|
|
576
598
|
const setar_token = {
|
|
@@ -591,15 +613,17 @@ const _token = new class _token {
|
|
|
591
613
|
return _set_response.c.INVALID_TOKEN({
|
|
592
614
|
message: 'Token inválido!!!',
|
|
593
615
|
c: c,
|
|
594
|
-
results: []
|
|
616
|
+
results: [],
|
|
617
|
+
fn: _token_fn
|
|
595
618
|
});
|
|
596
619
|
}
|
|
597
620
|
}
|
|
598
621
|
async criar_token_login_usuario(props) {
|
|
599
622
|
if (!props?.c.env.JSON_WEB_TOKEN_AUTH_USER) {
|
|
600
623
|
_set_response.error.WARNING({
|
|
601
|
-
message: "Erro ao gerar token!!",
|
|
602
|
-
results: []
|
|
624
|
+
message: "Erro ao gerar token auth!!",
|
|
625
|
+
results: [],
|
|
626
|
+
fn: _token_fn
|
|
603
627
|
});
|
|
604
628
|
}
|
|
605
629
|
const token = await new external_jose_namespaceObject.SignJWT({
|
|
@@ -615,9 +639,10 @@ const _token = new class _token {
|
|
|
615
639
|
}).setProtectedHeader({
|
|
616
640
|
alg: "HS256"
|
|
617
641
|
}).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
|
|
642
|
+
return _set_response.error.TOKEN_AUTH_USER({
|
|
643
|
+
message: "Erro ao gerar token auth user!",
|
|
644
|
+
results: error?.message,
|
|
645
|
+
fn: _token_fn
|
|
621
646
|
});
|
|
622
647
|
});
|
|
623
648
|
return token;
|
|
@@ -628,13 +653,15 @@ const _token = new class _token {
|
|
|
628
653
|
if (!authHeader) return _set_response.c.INVALID_TOKEN({
|
|
629
654
|
message: 'token service não enviado!',
|
|
630
655
|
c: c,
|
|
631
|
-
results: []
|
|
656
|
+
results: [],
|
|
657
|
+
fn: _token_fn
|
|
632
658
|
});
|
|
633
659
|
const token = authHeader.split(" ")[1];
|
|
634
660
|
if (!token) return _set_response.c.INVALID_TOKEN({
|
|
635
661
|
message: 'Acesso negado ao serviço!',
|
|
636
662
|
c: c,
|
|
637
|
-
results: []
|
|
663
|
+
results: [],
|
|
664
|
+
fn: _token_fn
|
|
638
665
|
});
|
|
639
666
|
const secret = new TextEncoder().encode(c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO);
|
|
640
667
|
const { payload } = await external_jose_namespaceObject.jwtVerify(token, secret);
|
|
@@ -642,7 +669,8 @@ const _token = new class _token {
|
|
|
642
669
|
return _set_response.c.INVALID_TOKEN({
|
|
643
670
|
message: 'Token inválido para o serviço!',
|
|
644
671
|
c: c,
|
|
645
|
-
results: []
|
|
672
|
+
results: [],
|
|
673
|
+
fn: _token_fn
|
|
646
674
|
});
|
|
647
675
|
}
|
|
648
676
|
const setar_token = {
|
|
@@ -662,15 +690,17 @@ const _token = new class _token {
|
|
|
662
690
|
return _set_response.c.INVALID_TOKEN({
|
|
663
691
|
message: 'Erro token inválido!',
|
|
664
692
|
c: c,
|
|
665
|
-
results: []
|
|
693
|
+
results: [],
|
|
694
|
+
fn: _token_fn
|
|
666
695
|
});
|
|
667
696
|
}
|
|
668
697
|
}
|
|
669
698
|
async criar_token_micro_servico({ c }) {
|
|
670
699
|
if (!c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO) {
|
|
671
|
-
|
|
700
|
+
_set_response.error.WARNING({
|
|
672
701
|
message: "Erro ao gerar token!!",
|
|
673
|
-
results: []
|
|
702
|
+
results: [],
|
|
703
|
+
fn: _token_fn
|
|
674
704
|
});
|
|
675
705
|
}
|
|
676
706
|
const usuario_auth = c.get("usuario_auth");
|
|
@@ -687,18 +717,20 @@ const _token = new class _token {
|
|
|
687
717
|
}).setProtectedHeader({
|
|
688
718
|
alg: "HS256"
|
|
689
719
|
}).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
|
|
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
|
|
693
724
|
});
|
|
694
725
|
});
|
|
695
726
|
return token;
|
|
696
727
|
}
|
|
697
728
|
async criar_refresh_token({ env, usuario_id }) {
|
|
698
729
|
if (!env.JSON_WEB_REFRESH_TOKEN_AUTH_USER) {
|
|
699
|
-
|
|
730
|
+
_set_response.error.TOKEN_AUTH_USER({
|
|
700
731
|
message: "Erro ao gerar refresh token!!",
|
|
701
|
-
results: []
|
|
732
|
+
results: [],
|
|
733
|
+
fn: _token_fn
|
|
702
734
|
});
|
|
703
735
|
}
|
|
704
736
|
const token = await new external_jose_namespaceObject.SignJWT({
|
|
@@ -706,8 +738,9 @@ const _token = new class _token {
|
|
|
706
738
|
}).setProtectedHeader({
|
|
707
739
|
alg: "HS256"
|
|
708
740
|
}).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!"
|
|
741
|
+
return _set_response.error.TOKEN_AUTH_USER({
|
|
742
|
+
message: "Erro ao gerar refresh token!",
|
|
743
|
+
fn: _token_fn
|
|
711
744
|
});
|
|
712
745
|
});
|
|
713
746
|
return token;
|
package/build/lib/index.cjs
CHANGED
|
@@ -154,7 +154,8 @@ var _usuario_TypeControllerUsuario;
|
|
|
154
154
|
v4_default().literal("DATABASE_ERROR"),
|
|
155
155
|
v4_default().literal("BUSINESS_RULE_VIOLATION"),
|
|
156
156
|
v4_default().literal("PLAN_FORBIDDEN"),
|
|
157
|
-
v4_default().literal("INTEGRATION_ERROR")
|
|
157
|
+
v4_default().literal("INTEGRATION_ERROR"),
|
|
158
|
+
v4_default().literal("TOKEN_AUTH_USER")
|
|
158
159
|
]);
|
|
159
160
|
const BaseResponseSchema = v4_default().object({
|
|
160
161
|
status: StatusSchema,
|
|
@@ -176,6 +177,7 @@ var _usuario_TypeControllerUsuario;
|
|
|
176
177
|
const FileResponseParamsSchema = v4_default().object({
|
|
177
178
|
status: StatusSchema,
|
|
178
179
|
message: v4_default().string().optional(),
|
|
180
|
+
fn: v4_default().string(),
|
|
179
181
|
file_buffer: v4_default().union([
|
|
180
182
|
v4_default()["instanceof"](Blob),
|
|
181
183
|
v4_default()["instanceof"](ArrayBuffer),
|
|
@@ -195,8 +197,7 @@ var _usuario_TypeControllerUsuario;
|
|
|
195
197
|
]).optional(),
|
|
196
198
|
type: TypeSchema.optional().default("success"),
|
|
197
199
|
code: CodeSchema,
|
|
198
|
-
status: v4_default().number().optional().default(200)
|
|
199
|
-
fn: v4_default().string().optional()
|
|
200
|
+
status: v4_default().number().optional().default(200)
|
|
200
201
|
});
|
|
201
202
|
})(TypeControllerResponse.Error || (TypeControllerResponse.Error = {}));
|
|
202
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">, z4.ZodLiteral<"INTEGRATION_ERROR">]>;
|
|
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">, z4.ZodLiteral<"INTEGRATION_ERROR">]>;
|
|
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">, z4.ZodLiteral<"INTEGRATION_ERROR">]>;
|
|
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;
|