@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/es/helpers.js
CHANGED
|
@@ -46,7 +46,7 @@ const _logger = new RequestLoggerClass();
|
|
|
46
46
|
const helpers_logger = _logger;
|
|
47
47
|
const set_response = new class {
|
|
48
48
|
c = new class {
|
|
49
|
-
SUCCESS({ message, results, c }) {
|
|
49
|
+
SUCCESS({ message, results, c, fn }) {
|
|
50
50
|
const payload = {
|
|
51
51
|
status: 200,
|
|
52
52
|
code: "SUCCESS",
|
|
@@ -55,7 +55,7 @@ const set_response = new class {
|
|
|
55
55
|
results: results || []
|
|
56
56
|
};
|
|
57
57
|
helpers_logger.add({
|
|
58
|
-
fn:
|
|
58
|
+
fn: `${fn}_SUCCESS`,
|
|
59
59
|
level: "info",
|
|
60
60
|
message: payload?.message,
|
|
61
61
|
results: payload?.results
|
|
@@ -64,7 +64,7 @@ const set_response = new class {
|
|
|
64
64
|
status: 200
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
|
-
ACTION_REQUIRED({ message, results, c }) {
|
|
67
|
+
ACTION_REQUIRED({ message, results, c, fn }) {
|
|
68
68
|
const payload = {
|
|
69
69
|
status: 428,
|
|
70
70
|
code: "ACTION_REQUIRED",
|
|
@@ -73,7 +73,7 @@ const set_response = new class {
|
|
|
73
73
|
results: results || []
|
|
74
74
|
};
|
|
75
75
|
helpers_logger.add({
|
|
76
|
-
fn:
|
|
76
|
+
fn: `${fn}_ACTION_REQUIRED`,
|
|
77
77
|
level: "info",
|
|
78
78
|
message: payload?.message,
|
|
79
79
|
results: payload?.results
|
|
@@ -82,7 +82,7 @@ const set_response = new class {
|
|
|
82
82
|
status: 428
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
|
-
CREATED({ message, results, c }) {
|
|
85
|
+
CREATED({ message, results, c, fn }) {
|
|
86
86
|
const payload = {
|
|
87
87
|
status: 201,
|
|
88
88
|
code: "CREATED",
|
|
@@ -91,7 +91,7 @@ const set_response = new class {
|
|
|
91
91
|
results: results || []
|
|
92
92
|
};
|
|
93
93
|
helpers_logger.add({
|
|
94
|
-
fn:
|
|
94
|
+
fn: `${fn}_CREATED`,
|
|
95
95
|
level: "info",
|
|
96
96
|
message: payload?.message,
|
|
97
97
|
results: payload?.results
|
|
@@ -100,7 +100,7 @@ const set_response = new class {
|
|
|
100
100
|
status: 201
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
|
-
WARNING({ message, results, c }) {
|
|
103
|
+
WARNING({ message, results, c, fn }) {
|
|
104
104
|
const payload = {
|
|
105
105
|
status: 400,
|
|
106
106
|
code: "WARNING",
|
|
@@ -109,7 +109,7 @@ const set_response = new class {
|
|
|
109
109
|
results: results || []
|
|
110
110
|
};
|
|
111
111
|
helpers_logger.add({
|
|
112
|
-
fn:
|
|
112
|
+
fn: `${fn}_WARNING`,
|
|
113
113
|
level: "info",
|
|
114
114
|
message: payload?.message,
|
|
115
115
|
results: payload?.results
|
|
@@ -118,7 +118,7 @@ const set_response = new class {
|
|
|
118
118
|
status: 400
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
|
-
AUTHORIZATION_ERROR({ message, results, c }) {
|
|
121
|
+
AUTHORIZATION_ERROR({ message, results, c, fn }) {
|
|
122
122
|
const payload = {
|
|
123
123
|
status: 405,
|
|
124
124
|
code: "WARNING",
|
|
@@ -127,7 +127,7 @@ const set_response = new class {
|
|
|
127
127
|
results: results || []
|
|
128
128
|
};
|
|
129
129
|
helpers_logger.add({
|
|
130
|
-
fn:
|
|
130
|
+
fn: `${fn}_AUTHORIZATION_ERROR`,
|
|
131
131
|
level: "error",
|
|
132
132
|
message: payload?.message,
|
|
133
133
|
results: payload?.results
|
|
@@ -136,7 +136,7 @@ const set_response = new class {
|
|
|
136
136
|
status: 405
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
|
-
SERVER_ERROR({ error, c }) {
|
|
139
|
+
SERVER_ERROR({ error, c, fn }) {
|
|
140
140
|
if (error instanceof v4.ZodError) {
|
|
141
141
|
const payload = {
|
|
142
142
|
status: 500,
|
|
@@ -146,7 +146,7 @@ const set_response = new class {
|
|
|
146
146
|
results: v4.treeifyError(error)
|
|
147
147
|
};
|
|
148
148
|
helpers_logger.add({
|
|
149
|
-
fn:
|
|
149
|
+
fn: `${fn}_SCHEMA_VALIDATION`,
|
|
150
150
|
level: "error",
|
|
151
151
|
message: payload?.message,
|
|
152
152
|
results: payload?.results
|
|
@@ -163,7 +163,7 @@ const set_response = new class {
|
|
|
163
163
|
results: error?.results || []
|
|
164
164
|
};
|
|
165
165
|
if (payload?.type === "error") helpers_logger.add({
|
|
166
|
-
fn:
|
|
166
|
+
fn: `${fn}_SERVER_ERROR`,
|
|
167
167
|
level: payload?.type,
|
|
168
168
|
message: payload?.message,
|
|
169
169
|
results: payload?.results
|
|
@@ -172,7 +172,7 @@ const set_response = new class {
|
|
|
172
172
|
status: error?.status || error?.status || 500
|
|
173
173
|
});
|
|
174
174
|
}
|
|
175
|
-
UNAUTHORIZED({ message, c }) {
|
|
175
|
+
UNAUTHORIZED({ message, c, fn }) {
|
|
176
176
|
const payload = {
|
|
177
177
|
status: 401,
|
|
178
178
|
code: "UNAUTHORIZED",
|
|
@@ -181,7 +181,7 @@ const set_response = new class {
|
|
|
181
181
|
results: []
|
|
182
182
|
};
|
|
183
183
|
helpers_logger.add({
|
|
184
|
-
fn:
|
|
184
|
+
fn: `${fn}_UNAUTHORIZED`,
|
|
185
185
|
level: "error",
|
|
186
186
|
message: payload?.message,
|
|
187
187
|
results: payload?.results
|
|
@@ -190,7 +190,7 @@ const set_response = new class {
|
|
|
190
190
|
status: 401
|
|
191
191
|
});
|
|
192
192
|
}
|
|
193
|
-
INVALID_TOKEN({ message, c }) {
|
|
193
|
+
INVALID_TOKEN({ message, c, fn }) {
|
|
194
194
|
const payload = {
|
|
195
195
|
status: 409,
|
|
196
196
|
code: "INVALID_TOKEN",
|
|
@@ -199,7 +199,7 @@ const set_response = new class {
|
|
|
199
199
|
results: []
|
|
200
200
|
};
|
|
201
201
|
helpers_logger.add({
|
|
202
|
-
fn:
|
|
202
|
+
fn: `${fn}_INVALID_TOKEN`,
|
|
203
203
|
level: "error",
|
|
204
204
|
message: payload?.message,
|
|
205
205
|
results: payload?.results
|
|
@@ -208,7 +208,7 @@ const set_response = new class {
|
|
|
208
208
|
status: 409
|
|
209
209
|
});
|
|
210
210
|
}
|
|
211
|
-
NOT_FOUND({ message, c }) {
|
|
211
|
+
NOT_FOUND({ message, c, fn }) {
|
|
212
212
|
const payload = {
|
|
213
213
|
status: 404,
|
|
214
214
|
code: "NOT_FOUND",
|
|
@@ -217,7 +217,7 @@ const set_response = new class {
|
|
|
217
217
|
results: []
|
|
218
218
|
};
|
|
219
219
|
helpers_logger.add({
|
|
220
|
-
fn:
|
|
220
|
+
fn: `${fn}_NOT_FOUND`,
|
|
221
221
|
level: "info",
|
|
222
222
|
message: payload?.message,
|
|
223
223
|
results: payload?.results
|
|
@@ -226,14 +226,14 @@ const set_response = new class {
|
|
|
226
226
|
status: 404
|
|
227
227
|
});
|
|
228
228
|
}
|
|
229
|
-
async SUCCESS_FILE({ message, file_buffer, content_type, filename, c }) {
|
|
229
|
+
async SUCCESS_FILE({ message, file_buffer, content_type, filename, c, fn }) {
|
|
230
230
|
if (c && content_type) {
|
|
231
231
|
const headers = {
|
|
232
232
|
"Content-Type": content_type,
|
|
233
233
|
"Content-Disposition": filename ? `inline; filename="${filename}"` : "inline"
|
|
234
234
|
};
|
|
235
235
|
helpers_logger.add({
|
|
236
|
-
fn:
|
|
236
|
+
fn: `${fn}_SUCCESS_FILE`,
|
|
237
237
|
level: "info",
|
|
238
238
|
message: "",
|
|
239
239
|
results: headers
|
|
@@ -251,7 +251,7 @@ const set_response = new class {
|
|
|
251
251
|
results: []
|
|
252
252
|
};
|
|
253
253
|
helpers_logger.add({
|
|
254
|
-
fn:
|
|
254
|
+
fn: `${fn}_SUCCESS_FILE`,
|
|
255
255
|
level: "info",
|
|
256
256
|
message: payload?.message,
|
|
257
257
|
results: payload?.results
|
|
@@ -262,7 +262,7 @@ const set_response = new class {
|
|
|
262
262
|
}
|
|
263
263
|
};
|
|
264
264
|
error = new class {
|
|
265
|
-
ACTION_REQUIRED({ message, results }) {
|
|
265
|
+
ACTION_REQUIRED({ message, results, fn }) {
|
|
266
266
|
const payload = {
|
|
267
267
|
status: 428,
|
|
268
268
|
code: "ACTION_REQUIRED",
|
|
@@ -271,14 +271,14 @@ const set_response = new class {
|
|
|
271
271
|
results: results || []
|
|
272
272
|
};
|
|
273
273
|
helpers_logger.add({
|
|
274
|
-
fn:
|
|
274
|
+
fn: `${fn}_ACTION_REQUIRED`,
|
|
275
275
|
level: "info",
|
|
276
276
|
message: payload?.message,
|
|
277
277
|
results: payload?.results
|
|
278
278
|
});
|
|
279
279
|
throw payload;
|
|
280
280
|
}
|
|
281
|
-
WARNING({ message, results }) {
|
|
281
|
+
WARNING({ message, results, fn }) {
|
|
282
282
|
const payload = {
|
|
283
283
|
status: 400,
|
|
284
284
|
code: "WARNING",
|
|
@@ -287,14 +287,30 @@ const set_response = new class {
|
|
|
287
287
|
results: results || []
|
|
288
288
|
};
|
|
289
289
|
helpers_logger.add({
|
|
290
|
-
fn:
|
|
290
|
+
fn: `${fn}_WARNING`,
|
|
291
291
|
level: "info",
|
|
292
292
|
message: payload?.message,
|
|
293
293
|
results: payload?.results
|
|
294
294
|
});
|
|
295
295
|
throw payload;
|
|
296
296
|
}
|
|
297
|
-
|
|
297
|
+
TOKEN_AUTH_USER({ message, results, fn }) {
|
|
298
|
+
const payload = {
|
|
299
|
+
status: 410,
|
|
300
|
+
code: "TOKEN_AUTH_USER",
|
|
301
|
+
type: "warning",
|
|
302
|
+
message: message || "Erro processo de auth token!",
|
|
303
|
+
results: results || []
|
|
304
|
+
};
|
|
305
|
+
helpers_logger.add({
|
|
306
|
+
fn: `${fn}_REFRESH_TOKEN_AUTH_USER`,
|
|
307
|
+
level: "error",
|
|
308
|
+
message: payload?.message,
|
|
309
|
+
results: payload?.results
|
|
310
|
+
});
|
|
311
|
+
throw payload;
|
|
312
|
+
}
|
|
313
|
+
AUTHORIZATION_ERROR({ message, results, fn }) {
|
|
298
314
|
const payload = {
|
|
299
315
|
status: 400,
|
|
300
316
|
code: "WARNING",
|
|
@@ -303,14 +319,14 @@ const set_response = new class {
|
|
|
303
319
|
results: results || []
|
|
304
320
|
};
|
|
305
321
|
helpers_logger.add({
|
|
306
|
-
fn:
|
|
322
|
+
fn: `${fn}_AUTHORIZATION_ERROR`,
|
|
307
323
|
level: "error",
|
|
308
324
|
message: payload?.message,
|
|
309
325
|
results: payload?.results
|
|
310
326
|
});
|
|
311
327
|
throw payload;
|
|
312
328
|
}
|
|
313
|
-
DATABASE_ERROR({ message, erro }) {
|
|
329
|
+
DATABASE_ERROR({ message, erro, fn }) {
|
|
314
330
|
const errorCode = erro?.cause?.code || erro?.cause?.cause?.code || erro?.code || "";
|
|
315
331
|
const map = {
|
|
316
332
|
SQLITE_CONSTRAINT_UNIQUE: {
|
|
@@ -354,14 +370,14 @@ const set_response = new class {
|
|
|
354
370
|
results: []
|
|
355
371
|
};
|
|
356
372
|
helpers_logger.add({
|
|
357
|
-
fn:
|
|
373
|
+
fn: `${fn}_DATABASE_ERROR`,
|
|
358
374
|
level: "error",
|
|
359
375
|
message: payload?.message,
|
|
360
376
|
results: erro
|
|
361
377
|
});
|
|
362
378
|
throw payload;
|
|
363
379
|
}
|
|
364
|
-
SCHEMA_VALIDATION({ results }) {
|
|
380
|
+
SCHEMA_VALIDATION({ results, fn }) {
|
|
365
381
|
const payload = {
|
|
366
382
|
status: 500,
|
|
367
383
|
code: "SCHEMA_VALIDATION",
|
|
@@ -370,14 +386,14 @@ const set_response = new class {
|
|
|
370
386
|
results: results || []
|
|
371
387
|
};
|
|
372
388
|
helpers_logger.add({
|
|
373
|
-
fn:
|
|
389
|
+
fn: `${fn}_SCHEMA_VALIDATION`,
|
|
374
390
|
level: "error",
|
|
375
391
|
message: payload?.message,
|
|
376
392
|
results: payload?.results
|
|
377
393
|
});
|
|
378
394
|
throw payload;
|
|
379
395
|
}
|
|
380
|
-
UNAUTHORIZED({ message }) {
|
|
396
|
+
UNAUTHORIZED({ message, fn }) {
|
|
381
397
|
const payload = {
|
|
382
398
|
status: 401,
|
|
383
399
|
code: "UNAUTHORIZED",
|
|
@@ -385,60 +401,62 @@ const set_response = new class {
|
|
|
385
401
|
message: message || "Não autorizado!"
|
|
386
402
|
};
|
|
387
403
|
helpers_logger.add({
|
|
388
|
-
fn:
|
|
404
|
+
fn: `${fn}_UNAUTHORIZED`,
|
|
389
405
|
level: "error",
|
|
390
406
|
message: payload?.message,
|
|
391
407
|
results: payload?.results
|
|
392
408
|
});
|
|
393
409
|
throw payload;
|
|
394
410
|
}
|
|
395
|
-
INTEGRATION_ERROR({ message }) {
|
|
411
|
+
INTEGRATION_ERROR({ message, fn, erro }) {
|
|
396
412
|
const payload = {
|
|
397
413
|
status: 401,
|
|
398
414
|
code: "INTEGRATION_ERROR",
|
|
399
415
|
type: "error",
|
|
400
|
-
message: message || "Erro na camada de integração!"
|
|
416
|
+
message: message || "Erro na camada de integração!",
|
|
417
|
+
results: erro
|
|
401
418
|
};
|
|
402
419
|
helpers_logger.add({
|
|
403
|
-
fn:
|
|
420
|
+
fn: `${fn}_INTEGRATION_ERROR`,
|
|
404
421
|
level: "error",
|
|
405
422
|
message: payload?.message,
|
|
406
|
-
results:
|
|
423
|
+
results: erro
|
|
407
424
|
});
|
|
408
425
|
throw payload;
|
|
409
426
|
}
|
|
410
|
-
INVALID_TOKEN({ message }) {
|
|
427
|
+
INVALID_TOKEN({ message, fn, results }) {
|
|
411
428
|
const payload = {
|
|
412
429
|
status: 401,
|
|
413
430
|
code: "INVALID_TOKEN",
|
|
414
431
|
type: "warning",
|
|
415
432
|
message: message || "Token inválido!",
|
|
416
|
-
results: []
|
|
433
|
+
results: results || []
|
|
417
434
|
};
|
|
418
435
|
helpers_logger.add({
|
|
419
|
-
fn:
|
|
436
|
+
fn: `${fn}_INVALID_TOKEN`,
|
|
420
437
|
level: "error",
|
|
421
438
|
message: payload?.message,
|
|
422
439
|
results: payload?.results
|
|
423
440
|
});
|
|
424
441
|
throw payload;
|
|
425
442
|
}
|
|
426
|
-
NOT_FOUND({ message }) {
|
|
443
|
+
NOT_FOUND({ message, fn, results }) {
|
|
427
444
|
const payload = {
|
|
428
445
|
status: 404,
|
|
429
446
|
code: "NOT_FOUND",
|
|
430
447
|
type: "error",
|
|
431
|
-
message: message || "Recurso não encontrado!"
|
|
448
|
+
message: message || "Recurso não encontrado!",
|
|
449
|
+
results: results || []
|
|
432
450
|
};
|
|
433
451
|
helpers_logger.add({
|
|
434
|
-
fn:
|
|
452
|
+
fn: `${fn}_NOT_FOUND`,
|
|
435
453
|
level: "info",
|
|
436
454
|
message: payload?.message,
|
|
437
455
|
results: payload?.results
|
|
438
456
|
});
|
|
439
457
|
throw payload;
|
|
440
458
|
}
|
|
441
|
-
BUSINESS_RULE_VIOLATION({ message, results }) {
|
|
459
|
+
BUSINESS_RULE_VIOLATION({ message, results, fn }) {
|
|
442
460
|
const payload = {
|
|
443
461
|
status: 422,
|
|
444
462
|
code: "BUSINESS_RULE_VIOLATION",
|
|
@@ -447,14 +465,14 @@ const set_response = new class {
|
|
|
447
465
|
results: results || []
|
|
448
466
|
};
|
|
449
467
|
helpers_logger.add({
|
|
450
|
-
fn:
|
|
468
|
+
fn: `${fn}_BUSINESS_RULE_VIOLATION`,
|
|
451
469
|
level: "info",
|
|
452
470
|
message: payload?.message,
|
|
453
471
|
results: payload?.results
|
|
454
472
|
});
|
|
455
473
|
throw payload;
|
|
456
474
|
}
|
|
457
|
-
PLAN_FORBIDDEN({ message, results }) {
|
|
475
|
+
PLAN_FORBIDDEN({ message, results, fn }) {
|
|
458
476
|
const payload = {
|
|
459
477
|
status: 403,
|
|
460
478
|
code: "PLAN_FORBIDDEN",
|
|
@@ -463,7 +481,7 @@ const set_response = new class {
|
|
|
463
481
|
results: results || []
|
|
464
482
|
};
|
|
465
483
|
helpers_logger.add({
|
|
466
|
-
fn:
|
|
484
|
+
fn: `${fn}_PLAN_FORBIDDEN`,
|
|
467
485
|
level: "info",
|
|
468
486
|
message: payload?.message,
|
|
469
487
|
results: payload?.results
|
|
@@ -473,6 +491,7 @@ const set_response = new class {
|
|
|
473
491
|
};
|
|
474
492
|
};
|
|
475
493
|
const _set_response = set_response;
|
|
494
|
+
const _token_fn = 'token';
|
|
476
495
|
const _token = new class {
|
|
477
496
|
async verificar_token(c, next) {
|
|
478
497
|
try {
|
|
@@ -480,20 +499,23 @@ const _token = new class {
|
|
|
480
499
|
if (!authHeader) return _set_response.c.INVALID_TOKEN({
|
|
481
500
|
message: 'token não enviado!!!',
|
|
482
501
|
c: c,
|
|
483
|
-
results: []
|
|
502
|
+
results: [],
|
|
503
|
+
fn: _token_fn
|
|
484
504
|
});
|
|
485
505
|
const token = authHeader.split(" ")[1];
|
|
486
506
|
if (!token) return _set_response.c.INVALID_TOKEN({
|
|
487
507
|
message: 'Acesso negado!!!',
|
|
488
508
|
c: c,
|
|
489
|
-
results: []
|
|
509
|
+
results: [],
|
|
510
|
+
fn: _token_fn
|
|
490
511
|
});
|
|
491
512
|
const secret = new TextEncoder().encode(c.env.JSON_WEB_TOKEN_AUTH_USER);
|
|
492
513
|
const { payload } = await jwtVerify(token, secret);
|
|
493
514
|
if (!payload._id || !payload.email) return _set_response.c.INVALID_TOKEN({
|
|
494
515
|
message: 'Token inválido!!!!',
|
|
495
516
|
c: c,
|
|
496
|
-
results: []
|
|
517
|
+
results: [],
|
|
518
|
+
fn: _token_fn
|
|
497
519
|
});
|
|
498
520
|
const setar_token = {
|
|
499
521
|
_id: payload._id,
|
|
@@ -513,14 +535,16 @@ const _token = new class {
|
|
|
513
535
|
return _set_response.c.INVALID_TOKEN({
|
|
514
536
|
message: 'Token inválido!!!',
|
|
515
537
|
c: c,
|
|
516
|
-
results: []
|
|
538
|
+
results: [],
|
|
539
|
+
fn: _token_fn
|
|
517
540
|
});
|
|
518
541
|
}
|
|
519
542
|
}
|
|
520
543
|
async criar_token_login_usuario(props) {
|
|
521
544
|
if (!props?.c.env.JSON_WEB_TOKEN_AUTH_USER) _set_response.error.WARNING({
|
|
522
|
-
message: "Erro ao gerar token!!",
|
|
523
|
-
results: []
|
|
545
|
+
message: "Erro ao gerar token auth!!",
|
|
546
|
+
results: [],
|
|
547
|
+
fn: _token_fn
|
|
524
548
|
});
|
|
525
549
|
const token = await new SignJWT({
|
|
526
550
|
_id: props?._id,
|
|
@@ -534,9 +558,10 @@ const _token = new class {
|
|
|
534
558
|
plano_status: props?.plano_status
|
|
535
559
|
}).setProtectedHeader({
|
|
536
560
|
alg: "HS256"
|
|
537
|
-
}).setIssuedAt().setExpirationTime("1h").sign(new TextEncoder().encode(props?.c.env.JSON_WEB_TOKEN_AUTH_USER)).catch((error)=>_set_response.error.
|
|
538
|
-
message: "Erro ao gerar token!",
|
|
539
|
-
results: error?.message
|
|
561
|
+
}).setIssuedAt().setExpirationTime("1h").sign(new TextEncoder().encode(props?.c.env.JSON_WEB_TOKEN_AUTH_USER)).catch((error)=>_set_response.error.TOKEN_AUTH_USER({
|
|
562
|
+
message: "Erro ao gerar token auth user!",
|
|
563
|
+
results: error?.message,
|
|
564
|
+
fn: _token_fn
|
|
540
565
|
}));
|
|
541
566
|
return token;
|
|
542
567
|
}
|
|
@@ -546,20 +571,23 @@ const _token = new class {
|
|
|
546
571
|
if (!authHeader) return _set_response.c.INVALID_TOKEN({
|
|
547
572
|
message: 'token service não enviado!',
|
|
548
573
|
c: c,
|
|
549
|
-
results: []
|
|
574
|
+
results: [],
|
|
575
|
+
fn: _token_fn
|
|
550
576
|
});
|
|
551
577
|
const token = authHeader.split(" ")[1];
|
|
552
578
|
if (!token) return _set_response.c.INVALID_TOKEN({
|
|
553
579
|
message: 'Acesso negado ao serviço!',
|
|
554
580
|
c: c,
|
|
555
|
-
results: []
|
|
581
|
+
results: [],
|
|
582
|
+
fn: _token_fn
|
|
556
583
|
});
|
|
557
584
|
const secret = new TextEncoder().encode(c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO);
|
|
558
585
|
const { payload } = await jwtVerify(token, secret);
|
|
559
586
|
if (!payload._id || !payload.email) return _set_response.c.INVALID_TOKEN({
|
|
560
587
|
message: 'Token inválido para o serviço!',
|
|
561
588
|
c: c,
|
|
562
|
-
results: []
|
|
589
|
+
results: [],
|
|
590
|
+
fn: _token_fn
|
|
563
591
|
});
|
|
564
592
|
const setar_token = {
|
|
565
593
|
_id: payload._id,
|
|
@@ -578,14 +606,16 @@ const _token = new class {
|
|
|
578
606
|
return _set_response.c.INVALID_TOKEN({
|
|
579
607
|
message: 'Erro token inválido!',
|
|
580
608
|
c: c,
|
|
581
|
-
results: []
|
|
609
|
+
results: [],
|
|
610
|
+
fn: _token_fn
|
|
582
611
|
});
|
|
583
612
|
}
|
|
584
613
|
}
|
|
585
614
|
async criar_token_micro_servico({ c }) {
|
|
586
|
-
if (!c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO)
|
|
615
|
+
if (!c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO) _set_response.error.WARNING({
|
|
587
616
|
message: "Erro ao gerar token!!",
|
|
588
|
-
results: []
|
|
617
|
+
results: [],
|
|
618
|
+
fn: _token_fn
|
|
589
619
|
});
|
|
590
620
|
const usuario_auth = c.get("usuario_auth");
|
|
591
621
|
const token = await new SignJWT({
|
|
@@ -600,23 +630,26 @@ const _token = new class {
|
|
|
600
630
|
plano_status: usuario_auth?.plano_status
|
|
601
631
|
}).setProtectedHeader({
|
|
602
632
|
alg: "HS256"
|
|
603
|
-
}).setIssuedAt().setExpirationTime("30s").sign(new TextEncoder().encode(c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO)).catch((error)=>_set_response.error.
|
|
604
|
-
message: "Erro ao gerar token!",
|
|
605
|
-
results: error?.message
|
|
633
|
+
}).setIssuedAt().setExpirationTime("30s").sign(new TextEncoder().encode(c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO)).catch((error)=>_set_response.error.TOKEN_AUTH_USER({
|
|
634
|
+
message: "Erro ao gerar token micro serviço!",
|
|
635
|
+
results: error?.message,
|
|
636
|
+
fn: _token_fn
|
|
606
637
|
}));
|
|
607
638
|
return token;
|
|
608
639
|
}
|
|
609
640
|
async criar_refresh_token({ env, usuario_id }) {
|
|
610
|
-
if (!env.JSON_WEB_REFRESH_TOKEN_AUTH_USER)
|
|
641
|
+
if (!env.JSON_WEB_REFRESH_TOKEN_AUTH_USER) _set_response.error.TOKEN_AUTH_USER({
|
|
611
642
|
message: "Erro ao gerar refresh token!!",
|
|
612
|
-
results: []
|
|
643
|
+
results: [],
|
|
644
|
+
fn: _token_fn
|
|
613
645
|
});
|
|
614
646
|
const token = await new SignJWT({
|
|
615
647
|
usuario_id: usuario_id
|
|
616
648
|
}).setProtectedHeader({
|
|
617
649
|
alg: "HS256"
|
|
618
|
-
}).setIssuedAt().setExpirationTime("2h").sign(new TextEncoder().encode(env.JSON_WEB_REFRESH_TOKEN_AUTH_USER)).catch((error)=>_set_response.error.
|
|
619
|
-
message: "Erro ao gerar refresh token!"
|
|
650
|
+
}).setIssuedAt().setExpirationTime("2h").sign(new TextEncoder().encode(env.JSON_WEB_REFRESH_TOKEN_AUTH_USER)).catch((error)=>_set_response.error.TOKEN_AUTH_USER({
|
|
651
|
+
message: "Erro ao gerar refresh token!",
|
|
652
|
+
fn: _token_fn
|
|
620
653
|
}));
|
|
621
654
|
return token;
|
|
622
655
|
}
|
package/build/es/index.js
CHANGED
|
@@ -92,7 +92,8 @@ var _usuario_TypeControllerUsuario;
|
|
|
92
92
|
v4.literal("DATABASE_ERROR"),
|
|
93
93
|
v4.literal("BUSINESS_RULE_VIOLATION"),
|
|
94
94
|
v4.literal("PLAN_FORBIDDEN"),
|
|
95
|
-
v4.literal("INTEGRATION_ERROR")
|
|
95
|
+
v4.literal("INTEGRATION_ERROR"),
|
|
96
|
+
v4.literal("TOKEN_AUTH_USER")
|
|
96
97
|
]);
|
|
97
98
|
v4.object({
|
|
98
99
|
status: StatusSchema,
|
|
@@ -114,6 +115,7 @@ var _usuario_TypeControllerUsuario;
|
|
|
114
115
|
v4.object({
|
|
115
116
|
status: StatusSchema,
|
|
116
117
|
message: v4.string().optional(),
|
|
118
|
+
fn: v4.string(),
|
|
117
119
|
file_buffer: v4.union([
|
|
118
120
|
v4["instanceof"](Blob),
|
|
119
121
|
v4["instanceof"](ArrayBuffer),
|
|
@@ -133,8 +135,7 @@ var _usuario_TypeControllerUsuario;
|
|
|
133
135
|
]).optional(),
|
|
134
136
|
type: TypeSchema.optional().default("success"),
|
|
135
137
|
code: CodeSchema,
|
|
136
|
-
status: v4.number().optional().default(200)
|
|
137
|
-
fn: v4.string().optional()
|
|
138
|
+
status: v4.number().optional().default(200)
|
|
138
139
|
});
|
|
139
140
|
})(TypeControllerResponse.Error || (TypeControllerResponse.Error = {}));
|
|
140
141
|
})(_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;
|