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