@navservice/core 1.96.0 → 1.99.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/_data.d.ts +4 -3
- package/build/es/helpers/_secret.d.ts +6 -5
- package/build/es/helpers/_set_response.d.ts +0 -3
- package/build/es/helpers/_token.d.ts +10 -1
- package/build/es/helpers/index.d.ts +23 -8
- package/build/es/helpers.js +94 -32
- package/build/es/index.js +44 -40
- package/build/es/types/index.d.ts +1 -0
- package/build/es/utils/_data.d.ts +0 -1
- package/build/es/utils/_environment.d.ts +2 -3
- package/build/es/utils/_form.d.ts +10 -9
- package/build/es/utils/_geral.d.ts +0 -1
- package/build/es/utils/_local_storage.d.ts +0 -1
- package/build/es/utils/_session_storage.d.ts +1 -1
- package/build/es/utils/_update_context.d.ts +0 -1
- package/build/es/utils/index.d.ts +11 -8
- package/build/lib/helpers/_data.d.ts +4 -3
- package/build/lib/helpers/_secret.d.ts +6 -5
- package/build/lib/helpers/_set_response.d.ts +0 -3
- package/build/lib/helpers/_token.d.ts +10 -1
- package/build/lib/helpers/index.d.ts +23 -8
- package/build/lib/helpers.cjs +100 -32
- package/build/lib/index.cjs +44 -41
- package/build/lib/types/index.d.ts +1 -0
- package/build/lib/utils/_data.d.ts +0 -1
- package/build/lib/utils/_environment.d.ts +2 -3
- package/build/lib/utils/_form.d.ts +10 -9
- package/build/lib/utils/_geral.d.ts +0 -1
- package/build/lib/utils/_local_storage.d.ts +0 -1
- package/build/lib/utils/_session_storage.d.ts +1 -1
- package/build/lib/utils/_update_context.d.ts +0 -1
- package/build/lib/utils/index.d.ts +11 -8
- package/package.json +1 -1
package/build/lib/helpers.cjs
CHANGED
|
@@ -60,9 +60,9 @@ var v4_default = /*#__PURE__*/__webpack_require__.n(v4_namespaceObject);
|
|
|
60
60
|
;// CONCATENATED MODULE: ./src/helpers/_set_response.ts
|
|
61
61
|
// TYPES
|
|
62
62
|
|
|
63
|
-
const set_response = class set_response {
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
const set_response = new class set_response {
|
|
64
|
+
c = new class c {
|
|
65
|
+
SUCCESS({ message, results, c }) {
|
|
66
66
|
const payload = {
|
|
67
67
|
status: 200,
|
|
68
68
|
code: "SUCCESS",
|
|
@@ -74,7 +74,7 @@ const set_response = class set_response {
|
|
|
74
74
|
status: 200
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
ACTION_REQUIRED({ message, results, c }) {
|
|
78
78
|
const payload = {
|
|
79
79
|
status: 428,
|
|
80
80
|
code: "ACTION_REQUIRED",
|
|
@@ -86,7 +86,7 @@ const set_response = class set_response {
|
|
|
86
86
|
status: 428
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
|
-
|
|
89
|
+
CREATED({ message, results, c }) {
|
|
90
90
|
const payload = {
|
|
91
91
|
status: 201,
|
|
92
92
|
code: "CREATED",
|
|
@@ -98,7 +98,7 @@ const set_response = class set_response {
|
|
|
98
98
|
status: 201
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
|
-
|
|
101
|
+
WARNING({ message, results, c }) {
|
|
102
102
|
const payload = {
|
|
103
103
|
status: 400,
|
|
104
104
|
code: "WARNING",
|
|
@@ -110,7 +110,7 @@ const set_response = class set_response {
|
|
|
110
110
|
status: 400
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
|
-
|
|
113
|
+
AUTHORIZATION_ERROR({ message, results, c }) {
|
|
114
114
|
const payload = {
|
|
115
115
|
status: 405,
|
|
116
116
|
code: "WARNING",
|
|
@@ -122,7 +122,7 @@ const set_response = class set_response {
|
|
|
122
122
|
status: 405
|
|
123
123
|
});
|
|
124
124
|
}
|
|
125
|
-
|
|
125
|
+
SERVER_ERROR({ error, c }) {
|
|
126
126
|
if (error instanceof (v4_default()).ZodError) {
|
|
127
127
|
const payload = {
|
|
128
128
|
status: 500,
|
|
@@ -146,7 +146,7 @@ const set_response = class set_response {
|
|
|
146
146
|
status: error?.status || error?.status || 500
|
|
147
147
|
});
|
|
148
148
|
}
|
|
149
|
-
|
|
149
|
+
UNAUTHORIZED({ message, c }) {
|
|
150
150
|
const payload = {
|
|
151
151
|
status: 401,
|
|
152
152
|
code: "UNAUTHORIZED",
|
|
@@ -158,7 +158,7 @@ const set_response = class set_response {
|
|
|
158
158
|
status: 401
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
|
-
|
|
161
|
+
INVALID_TOKEN({ message, c }) {
|
|
162
162
|
const payload = {
|
|
163
163
|
status: 409,
|
|
164
164
|
code: "INVALID_TOKEN",
|
|
@@ -170,7 +170,7 @@ const set_response = class set_response {
|
|
|
170
170
|
status: 409
|
|
171
171
|
});
|
|
172
172
|
}
|
|
173
|
-
|
|
173
|
+
NOT_FOUND({ message, c }) {
|
|
174
174
|
const payload = {
|
|
175
175
|
status: 404,
|
|
176
176
|
code: "NOT_FOUND",
|
|
@@ -182,7 +182,7 @@ const set_response = class set_response {
|
|
|
182
182
|
status: 404
|
|
183
183
|
});
|
|
184
184
|
}
|
|
185
|
-
|
|
185
|
+
async SUCCESS_FILE({ message, file_buffer, content_type, filename, c }) {
|
|
186
186
|
if (c && content_type) {
|
|
187
187
|
const headers = {
|
|
188
188
|
"Content-Type": content_type,
|
|
@@ -205,8 +205,8 @@ const set_response = class set_response {
|
|
|
205
205
|
});
|
|
206
206
|
}
|
|
207
207
|
};
|
|
208
|
-
|
|
209
|
-
|
|
208
|
+
error = new class error {
|
|
209
|
+
ACTION_REQUIRED({ message, results }) {
|
|
210
210
|
const payload = {
|
|
211
211
|
status: 428,
|
|
212
212
|
code: "ACTION_REQUIRED",
|
|
@@ -216,7 +216,7 @@ const set_response = class set_response {
|
|
|
216
216
|
};
|
|
217
217
|
throw payload;
|
|
218
218
|
}
|
|
219
|
-
|
|
219
|
+
WARNING({ message, results }) {
|
|
220
220
|
const payload = {
|
|
221
221
|
status: 400,
|
|
222
222
|
code: "WARNING",
|
|
@@ -226,7 +226,7 @@ const set_response = class set_response {
|
|
|
226
226
|
};
|
|
227
227
|
throw payload;
|
|
228
228
|
}
|
|
229
|
-
|
|
229
|
+
AUTHORIZATION_ERROR({ message, results }) {
|
|
230
230
|
const payload = {
|
|
231
231
|
status: 400,
|
|
232
232
|
code: "WARNING",
|
|
@@ -236,7 +236,7 @@ const set_response = class set_response {
|
|
|
236
236
|
};
|
|
237
237
|
throw payload;
|
|
238
238
|
}
|
|
239
|
-
|
|
239
|
+
DATABASE_ERROR({ message, results, erro }) {
|
|
240
240
|
const errorCode = erro?.cause?.code || erro?.cause?.cause?.code || erro?.code || "";
|
|
241
241
|
const map = {
|
|
242
242
|
"SQLITE_CONSTRAINT_UNIQUE": {
|
|
@@ -281,7 +281,7 @@ const set_response = class set_response {
|
|
|
281
281
|
};
|
|
282
282
|
throw payload;
|
|
283
283
|
}
|
|
284
|
-
|
|
284
|
+
SCHEMA_VALIDATION({ results }) {
|
|
285
285
|
const payload = {
|
|
286
286
|
status: 500,
|
|
287
287
|
code: "SCHEMA_VALIDATION",
|
|
@@ -291,7 +291,7 @@ const set_response = class set_response {
|
|
|
291
291
|
};
|
|
292
292
|
throw payload;
|
|
293
293
|
}
|
|
294
|
-
|
|
294
|
+
UNAUTHORIZED({ message }) {
|
|
295
295
|
const payload = {
|
|
296
296
|
status: 401,
|
|
297
297
|
code: "UNAUTHORIZED",
|
|
@@ -300,7 +300,7 @@ const set_response = class set_response {
|
|
|
300
300
|
};
|
|
301
301
|
throw payload;
|
|
302
302
|
}
|
|
303
|
-
|
|
303
|
+
INVALID_TOKEN({ message }) {
|
|
304
304
|
const payload = {
|
|
305
305
|
status: 401,
|
|
306
306
|
code: "INVALID_TOKEN",
|
|
@@ -310,7 +310,7 @@ const set_response = class set_response {
|
|
|
310
310
|
};
|
|
311
311
|
throw payload;
|
|
312
312
|
}
|
|
313
|
-
|
|
313
|
+
NOT_FOUND({ message }) {
|
|
314
314
|
const payload = {
|
|
315
315
|
status: 404,
|
|
316
316
|
code: "NOT_FOUND",
|
|
@@ -329,8 +329,8 @@ const external_jose_namespaceObject = require("jose");
|
|
|
329
329
|
|
|
330
330
|
// Tem que importar assim para evitar dependencia circular
|
|
331
331
|
|
|
332
|
-
const _token = class _token {
|
|
333
|
-
|
|
332
|
+
const _token = new class _token {
|
|
333
|
+
async verificar_token(c, next) {
|
|
334
334
|
try {
|
|
335
335
|
const authHeader = c.req.header("Authorization");
|
|
336
336
|
if (!authHeader) return _set_response.c.INVALID_TOKEN({
|
|
@@ -372,7 +372,7 @@ const _token = class _token {
|
|
|
372
372
|
});
|
|
373
373
|
}
|
|
374
374
|
}
|
|
375
|
-
|
|
375
|
+
async criar_token_login_usuario({ _id, email, app, usuario_tipo, ativo, data_criacao, nome, c }) {
|
|
376
376
|
if (!c.env.JSON_WEB_TOKEN_AUTH_USER) {
|
|
377
377
|
return _set_response.error.WARNING({
|
|
378
378
|
message: "Erro ao gerar token!!",
|
|
@@ -398,6 +398,74 @@ const _token = class _token {
|
|
|
398
398
|
});
|
|
399
399
|
return token;
|
|
400
400
|
}
|
|
401
|
+
async verificar_token_micro_servico(c, next) {
|
|
402
|
+
try {
|
|
403
|
+
const authHeader = c.req.header("Authorization");
|
|
404
|
+
if (!authHeader) return _set_response.c.INVALID_TOKEN({
|
|
405
|
+
message: 'token service não enviado!',
|
|
406
|
+
c: c,
|
|
407
|
+
results: []
|
|
408
|
+
});
|
|
409
|
+
const token = authHeader.split(" ")[1];
|
|
410
|
+
if (!token) return _set_response.c.INVALID_TOKEN({
|
|
411
|
+
message: 'Acesso negado ao serviço!',
|
|
412
|
+
c: c,
|
|
413
|
+
results: []
|
|
414
|
+
});
|
|
415
|
+
const secret = new TextEncoder().encode(c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO);
|
|
416
|
+
const { payload } = await external_jose_namespaceObject.jwtVerify(token, secret);
|
|
417
|
+
if (!payload._id || !payload.email) {
|
|
418
|
+
return _set_response.c.INVALID_TOKEN({
|
|
419
|
+
message: 'Token inválido para o serviço!',
|
|
420
|
+
c: c,
|
|
421
|
+
results: []
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
const setar_token = {
|
|
425
|
+
_id: payload._id,
|
|
426
|
+
email: payload.email,
|
|
427
|
+
ativo: payload.ativo,
|
|
428
|
+
data_criacao: payload.data_criacao,
|
|
429
|
+
nome: payload.nome,
|
|
430
|
+
app: payload.app,
|
|
431
|
+
usuario_tipo: payload.usuario_tipo
|
|
432
|
+
};
|
|
433
|
+
c.set("usuario_auth", setar_token);
|
|
434
|
+
return await next();
|
|
435
|
+
} catch (error) {
|
|
436
|
+
return _set_response.c.INVALID_TOKEN({
|
|
437
|
+
message: 'Erro token inválido!',
|
|
438
|
+
c: c,
|
|
439
|
+
results: []
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
async criar_token_micro_servico({ c }) {
|
|
444
|
+
if (!c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO) {
|
|
445
|
+
return _set_response.error.WARNING({
|
|
446
|
+
message: "Erro ao gerar token!!",
|
|
447
|
+
results: []
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
const usuario_auth = c.get("usuario_auth");
|
|
451
|
+
const token = await new external_jose_namespaceObject.SignJWT({
|
|
452
|
+
_id: usuario_auth?._id,
|
|
453
|
+
email: usuario_auth?.email,
|
|
454
|
+
app: usuario_auth?.app,
|
|
455
|
+
usuario_tipo: usuario_auth?.usuario_tipo,
|
|
456
|
+
ativo: usuario_auth?.ativo,
|
|
457
|
+
data_criacao: usuario_auth?.data_criacao,
|
|
458
|
+
nome: usuario_auth?.nome
|
|
459
|
+
}).setProtectedHeader({
|
|
460
|
+
alg: "HS256"
|
|
461
|
+
}).setIssuedAt().setExpirationTime("30s").sign(new TextEncoder().encode(c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO)).catch((error)=>{
|
|
462
|
+
return _set_response.error.WARNING({
|
|
463
|
+
message: "Erro ao gerar token!",
|
|
464
|
+
results: error?.message
|
|
465
|
+
});
|
|
466
|
+
});
|
|
467
|
+
return token;
|
|
468
|
+
}
|
|
401
469
|
};
|
|
402
470
|
/* export default */ const helpers_token = (_token);
|
|
403
471
|
|
|
@@ -410,14 +478,14 @@ const external_node_util_namespaceObject = require("node:util");
|
|
|
410
478
|
|
|
411
479
|
const scryptAsync = (0,external_node_util_namespaceObject.promisify)(external_node_crypto_namespaceObject.scrypt);
|
|
412
480
|
class _secret {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
481
|
+
SALT_LENGTH = 22;
|
|
482
|
+
KEY_LENGTH = 35;
|
|
483
|
+
async gerar_hash_senha(password) {
|
|
416
484
|
const salt = (0,external_node_crypto_namespaceObject.randomBytes)(this.SALT_LENGTH);
|
|
417
485
|
const derivedKey = await scryptAsync(password, salt, this.KEY_LENGTH);
|
|
418
486
|
return salt.toString('base64') + '.' + derivedKey.toString('base64');
|
|
419
487
|
}
|
|
420
|
-
|
|
488
|
+
async verify({ password, dashed_senha }) {
|
|
421
489
|
try {
|
|
422
490
|
const [saltBase64, hashBase64] = dashed_senha.split('.');
|
|
423
491
|
if (!saltBase64 || !hashBase64) return false;
|
|
@@ -430,14 +498,14 @@ class _secret {
|
|
|
430
498
|
}
|
|
431
499
|
}
|
|
432
500
|
}
|
|
433
|
-
/* export default */ const helpers_secret = (_secret);
|
|
501
|
+
/* export default */ const helpers_secret = (new _secret);
|
|
434
502
|
|
|
435
503
|
;// CONCATENATED MODULE: ./src/helpers/_data.ts
|
|
436
504
|
class _data {
|
|
437
|
-
|
|
505
|
+
get get_now_format_number() {
|
|
438
506
|
return Math.floor(Date.now() / 1000);
|
|
439
507
|
}
|
|
440
|
-
|
|
508
|
+
verificar_data(value) {
|
|
441
509
|
const data = new Date(value * 1000);
|
|
442
510
|
if (isNaN(data.getTime())) {
|
|
443
511
|
throw new Error("Timestamp está inválido.");
|
|
@@ -445,7 +513,7 @@ class _data {
|
|
|
445
513
|
return value; // válido
|
|
446
514
|
}
|
|
447
515
|
}
|
|
448
|
-
/* export default */ const helpers_data = (_data);
|
|
516
|
+
/* export default */ const helpers_data = (new _data);
|
|
449
517
|
|
|
450
518
|
;// CONCATENATED MODULE: ./src/helpers/index.ts
|
|
451
519
|
//_HELPERS
|
package/build/lib/index.cjs
CHANGED
|
@@ -182,8 +182,8 @@ var types_t;
|
|
|
182
182
|
const external_axios_namespaceObject = require("axios");
|
|
183
183
|
var external_axios_default = /*#__PURE__*/__webpack_require__.n(external_axios_namespaceObject);
|
|
184
184
|
;// CONCATENATED MODULE: ./src/utils/_session_storage.ts
|
|
185
|
-
const _session_storage = class _session_storage {
|
|
186
|
-
|
|
185
|
+
const _session_storage = new class _session_storage {
|
|
186
|
+
adicionar_item_session_storage({ chave, novoItem }) {
|
|
187
187
|
try {
|
|
188
188
|
const valorAtual = window.sessionStorage.getItem(chave);
|
|
189
189
|
const listaAtual = valorAtual ? JSON.parse(valorAtual) : [];
|
|
@@ -196,14 +196,14 @@ const _session_storage = class _session_storage {
|
|
|
196
196
|
console.error(error);
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
|
-
|
|
199
|
+
set_session_storage_sem_incremento({ chave, novoItem }) {
|
|
200
200
|
try {
|
|
201
201
|
window.sessionStorage.setItem(chave, JSON.stringify(novoItem));
|
|
202
202
|
} catch (error) {
|
|
203
203
|
console.error(error);
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
|
-
|
|
206
|
+
get_item_session_storage(chave) {
|
|
207
207
|
try {
|
|
208
208
|
if (typeof window !== "undefined") {
|
|
209
209
|
const valorAtual = window.sessionStorage.getItem(chave);
|
|
@@ -214,13 +214,17 @@ const _session_storage = class _session_storage {
|
|
|
214
214
|
console.error(error);
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
-
|
|
217
|
+
remover_item_session_storage(chave) {
|
|
218
218
|
try {
|
|
219
219
|
window.sessionStorage.removeItem(chave);
|
|
220
220
|
} catch (error) {
|
|
221
221
|
console.error(error);
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
|
+
get usuario_auth() {
|
|
225
|
+
const get_auth_user = this.get_item_session_storage("auth_user");
|
|
226
|
+
return get_auth_user;
|
|
227
|
+
}
|
|
224
228
|
};
|
|
225
229
|
/* export default */ const utils_session_storage = (_session_storage);
|
|
226
230
|
|
|
@@ -325,8 +329,8 @@ const _api_api = class _api {
|
|
|
325
329
|
/* export default */ const utils_api = (_api_api);
|
|
326
330
|
|
|
327
331
|
;// CONCATENATED MODULE: ./src/utils/_data.ts
|
|
328
|
-
const _data = class _data {
|
|
329
|
-
|
|
332
|
+
const _data = new class _data {
|
|
333
|
+
YYYY_MM_DD_00_00_00(newData) {
|
|
330
334
|
let dataAtual = new Date();
|
|
331
335
|
if (newData) {
|
|
332
336
|
dataAtual = new Date(newData);
|
|
@@ -343,7 +347,7 @@ const _data = class _data {
|
|
|
343
347
|
const [dia, mes, ano] = data.split("/");
|
|
344
348
|
return `${ano}-${mes}-${dia} ${hora}`;
|
|
345
349
|
}
|
|
346
|
-
|
|
350
|
+
DD_MM_YYYY_00_00_00(newData) {
|
|
347
351
|
let dataAtual = new Date();
|
|
348
352
|
if (newData) {
|
|
349
353
|
dataAtual = new Date(newData);
|
|
@@ -357,7 +361,7 @@ const _data = class _data {
|
|
|
357
361
|
};
|
|
358
362
|
return dataAtual.toLocaleString("pt-BR", options);
|
|
359
363
|
}
|
|
360
|
-
|
|
364
|
+
DD_MM_YYYY_00_00(newData) {
|
|
361
365
|
let dataAtual = new Date();
|
|
362
366
|
if (newData) {
|
|
363
367
|
dataAtual = new Date(newData);
|
|
@@ -372,7 +376,7 @@ const _data = class _data {
|
|
|
372
376
|
const dataFormatada = dataAtual.toLocaleString("pt-BR", options).replace(",", "");
|
|
373
377
|
return dataFormatada;
|
|
374
378
|
}
|
|
375
|
-
|
|
379
|
+
DD_MM_YYYY(newData) {
|
|
376
380
|
let dataAtual = new Date();
|
|
377
381
|
if (newData) {
|
|
378
382
|
dataAtual = new Date(newData);
|
|
@@ -386,7 +390,7 @@ const _data = class _data {
|
|
|
386
390
|
};
|
|
387
391
|
return dataAtual.toLocaleString("pt-BR", options);
|
|
388
392
|
}
|
|
389
|
-
|
|
393
|
+
YYYY_MM_DD(newData) {
|
|
390
394
|
let dataAtual = new Date();
|
|
391
395
|
if (newData) {
|
|
392
396
|
dataAtual = new Date(newData);
|
|
@@ -403,21 +407,21 @@ const _data = class _data {
|
|
|
403
407
|
const [dia, mes, ano] = data.split("/");
|
|
404
408
|
return `${ano}-${mes}-${dia}`;
|
|
405
409
|
}
|
|
406
|
-
|
|
410
|
+
DIFERENCA_SEGUNDOS(data) {
|
|
407
411
|
var dataInicial = new Date(data);
|
|
408
412
|
var dataAtual = new Date();
|
|
409
413
|
var diferenca = Number(dataAtual) - Number(dataInicial);
|
|
410
414
|
var diferencaEmSegundos = Math.floor(diferenca / 1000);
|
|
411
415
|
return diferencaEmSegundos;
|
|
412
416
|
}
|
|
413
|
-
|
|
417
|
+
DIFERENCA_DIAS(data) {
|
|
414
418
|
var dataInicial = new Date(data);
|
|
415
419
|
var dataAtual = new Date();
|
|
416
420
|
var diferenca = dataAtual.getTime() - dataInicial.getTime(); // Obtém a diferença em milissegundos
|
|
417
421
|
var diferencaEmDias = Math.floor(diferenca / (1000 * 60 * 60 * 24)); // Calcula a diferença em dias
|
|
418
422
|
return diferencaEmDias;
|
|
419
423
|
}
|
|
420
|
-
|
|
424
|
+
SET_SECONDS_TO_DD_MM_YYYY_HH_MM(timestamp) {
|
|
421
425
|
const segundos = Number(timestamp);
|
|
422
426
|
if (!Number.isFinite(segundos)) {
|
|
423
427
|
return "-";
|
|
@@ -440,7 +444,7 @@ const _data = class _data {
|
|
|
440
444
|
|
|
441
445
|
;// CONCATENATED MODULE: ./src/utils/_form.ts
|
|
442
446
|
class _form {
|
|
443
|
-
|
|
447
|
+
regex_cpf_cnpj(value) {
|
|
444
448
|
let tempValue = value.replace(/\D/g, "");
|
|
445
449
|
if (tempValue.length > 14) {
|
|
446
450
|
tempValue = tempValue.slice(0, 14);
|
|
@@ -465,7 +469,7 @@ class _form {
|
|
|
465
469
|
}
|
|
466
470
|
return tempValue;
|
|
467
471
|
}
|
|
468
|
-
|
|
472
|
+
formatar_cpf(value) {
|
|
469
473
|
const cpf = value.replace(/\D/g, "");
|
|
470
474
|
if (cpf.length > 11) {
|
|
471
475
|
return cpf.slice(0, 11);
|
|
@@ -478,7 +482,7 @@ class _form {
|
|
|
478
482
|
return result;
|
|
479
483
|
});
|
|
480
484
|
}
|
|
481
|
-
|
|
485
|
+
formatar_cnpj(value) {
|
|
482
486
|
const cnpj = value.replace(/\D/g, "");
|
|
483
487
|
if (cnpj.length > 14) {
|
|
484
488
|
return cnpj.slice(0, 14);
|
|
@@ -492,7 +496,7 @@ class _form {
|
|
|
492
496
|
return result;
|
|
493
497
|
});
|
|
494
498
|
}
|
|
495
|
-
|
|
499
|
+
formatar_cep(value) {
|
|
496
500
|
const cep = value.replace(/\D/g, "");
|
|
497
501
|
if (cep.length > 8) {
|
|
498
502
|
return cep.slice(0, 8);
|
|
@@ -502,7 +506,7 @@ class _form {
|
|
|
502
506
|
return p1;
|
|
503
507
|
});
|
|
504
508
|
}
|
|
505
|
-
|
|
509
|
+
formatar_telefone_fixo(value) {
|
|
506
510
|
const telefone = value.replace(/\D/g, "");
|
|
507
511
|
if (telefone.length > 10) {
|
|
508
512
|
return telefone.slice(0, 10);
|
|
@@ -515,7 +519,7 @@ class _form {
|
|
|
515
519
|
return result;
|
|
516
520
|
});
|
|
517
521
|
}
|
|
518
|
-
|
|
522
|
+
formatar_celular(value) {
|
|
519
523
|
const celular = value.replace(/\D/g, "");
|
|
520
524
|
if (celular.length > 11) {
|
|
521
525
|
return celular.slice(0, 11);
|
|
@@ -528,7 +532,7 @@ class _form {
|
|
|
528
532
|
return result;
|
|
529
533
|
});
|
|
530
534
|
}
|
|
531
|
-
|
|
535
|
+
formatar_nome(name) {
|
|
532
536
|
const lowercaseWords = [
|
|
533
537
|
"de",
|
|
534
538
|
"da",
|
|
@@ -551,7 +555,7 @@ class _form {
|
|
|
551
555
|
});
|
|
552
556
|
return formattedWords.join(" ");
|
|
553
557
|
}
|
|
554
|
-
|
|
558
|
+
formatar_reais_br(value) {
|
|
555
559
|
let num = value.replace(/\D/g, "");
|
|
556
560
|
return new Intl.NumberFormat("pt-BR", {
|
|
557
561
|
style: "currency",
|
|
@@ -560,11 +564,11 @@ class _form {
|
|
|
560
564
|
}).format(Number(num) / 100);
|
|
561
565
|
}
|
|
562
566
|
}
|
|
563
|
-
/* export default */ const utils_form = (_form);
|
|
567
|
+
/* export default */ const utils_form = (new _form);
|
|
564
568
|
|
|
565
569
|
;// CONCATENATED MODULE: ./src/utils/_geral.ts
|
|
566
|
-
const geral = class geral {
|
|
567
|
-
|
|
570
|
+
const geral = new class geral {
|
|
571
|
+
slice_file_name(filename, maxLength = 30) {
|
|
568
572
|
if (!filename || typeof filename !== "string") return "";
|
|
569
573
|
// Encontra a última ocorrência do ponto para identificar a extensão
|
|
570
574
|
const lastDotIndex = filename.lastIndexOf(".");
|
|
@@ -586,14 +590,14 @@ const geral = class geral {
|
|
|
586
590
|
// Trunca o nome e mantém a extensão
|
|
587
591
|
return name.substring(0, availableLength) + "..." + extension;
|
|
588
592
|
}
|
|
589
|
-
|
|
593
|
+
extrair_id(array_enviado) {
|
|
590
594
|
const ids = [];
|
|
591
595
|
for(let i = 0; i < array_enviado.length; i++){
|
|
592
596
|
if (array_enviado[i]?._id) ids.push(array_enviado[i]._id);
|
|
593
597
|
}
|
|
594
598
|
return ids;
|
|
595
599
|
}
|
|
596
|
-
|
|
600
|
+
gerar_id = (length = 32)=>{
|
|
597
601
|
// Caracteres permitidos (apenas alfanuméricos)
|
|
598
602
|
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
599
603
|
// Timestamp em formato hexadecimal (sem separadores)
|
|
@@ -616,8 +620,8 @@ const geral = class geral {
|
|
|
616
620
|
/* export default */ const _geral = (geral);
|
|
617
621
|
|
|
618
622
|
;// CONCATENATED MODULE: ./src/utils/_local_storage.ts
|
|
619
|
-
const _local_storage = class _local_storage {
|
|
620
|
-
|
|
623
|
+
const _local_storage = new class _local_storage {
|
|
624
|
+
adicionar_item_local_storage(chave, novoItem) {
|
|
621
625
|
try {
|
|
622
626
|
const valorAtual = window.localStorage.getItem(chave);
|
|
623
627
|
const listaAtual = valorAtual ? JSON.parse(valorAtual) : [];
|
|
@@ -630,14 +634,14 @@ const _local_storage = class _local_storage {
|
|
|
630
634
|
console.log(error);
|
|
631
635
|
}
|
|
632
636
|
}
|
|
633
|
-
|
|
637
|
+
set_local_storage_sem_incremento(chave, novoItem) {
|
|
634
638
|
try {
|
|
635
639
|
window.localStorage.setItem(chave, JSON.stringify(novoItem));
|
|
636
640
|
} catch (error) {
|
|
637
641
|
console.log(error);
|
|
638
642
|
}
|
|
639
643
|
}
|
|
640
|
-
|
|
644
|
+
get_item_local_storage(chave) {
|
|
641
645
|
try {
|
|
642
646
|
if (typeof window !== "undefined") {
|
|
643
647
|
const valorAtual = window.localStorage.getItem(chave);
|
|
@@ -648,7 +652,7 @@ const _local_storage = class _local_storage {
|
|
|
648
652
|
console.log(error);
|
|
649
653
|
}
|
|
650
654
|
}
|
|
651
|
-
|
|
655
|
+
remover_item_local_storage(chave) {
|
|
652
656
|
try {
|
|
653
657
|
window.localStorage.removeItem(chave);
|
|
654
658
|
} catch (error) {
|
|
@@ -656,12 +660,11 @@ const _local_storage = class _local_storage {
|
|
|
656
660
|
}
|
|
657
661
|
}
|
|
658
662
|
};
|
|
659
|
-
// Para usar a classe, você pode fazer:
|
|
660
663
|
/* export default */ const utils_local_storage = (_local_storage);
|
|
661
664
|
|
|
662
665
|
;// CONCATENATED MODULE: ./src/utils/_update_context.ts
|
|
663
|
-
const _update_context = class _update_context {
|
|
664
|
-
|
|
666
|
+
const _update_context = new class _update_context {
|
|
667
|
+
set_new_item_end = ({ oldArray = [], newItem = [], key = "_id" })=>{
|
|
665
668
|
try {
|
|
666
669
|
const hasValidIds = Array.isArray(newItem) ? newItem.every((item)=>item?.[key]) : newItem?.[key];
|
|
667
670
|
const newItemArray = hasValidIds ? Array.isArray(newItem) ? newItem : [
|
|
@@ -694,7 +697,7 @@ const _update_context = class _update_context {
|
|
|
694
697
|
return oldArray; // Retorna o array original em caso de erro
|
|
695
698
|
}
|
|
696
699
|
};
|
|
697
|
-
|
|
700
|
+
update_array_itens = ({ oldArray = [], newItem = [], key = "_id" })=>{
|
|
698
701
|
try {
|
|
699
702
|
const hasValidIds = Array.isArray(newItem) ? newItem.every((item)=>item?.[key]) : newItem?.[key];
|
|
700
703
|
const newItemArray = hasValidIds ? Array.isArray(newItem) ? newItem : [
|
|
@@ -727,7 +730,7 @@ const _update_context = class _update_context {
|
|
|
727
730
|
return oldArray; // Retorna o array original em caso de erro
|
|
728
731
|
}
|
|
729
732
|
};
|
|
730
|
-
|
|
733
|
+
remove_array_items = ({ oldArray = [], itemsToRemove = [], key = "_id" })=>{
|
|
731
734
|
try {
|
|
732
735
|
// Verifica se os argumentos são válidos
|
|
733
736
|
if (!Array.isArray(oldArray) || oldArray.length === 0) return oldArray;
|
|
@@ -748,7 +751,7 @@ const _update_context = class _update_context {
|
|
|
748
751
|
return oldArray; // Retorna o array original em caso de erro
|
|
749
752
|
}
|
|
750
753
|
};
|
|
751
|
-
|
|
754
|
+
compare_arrays({ arrayAntigo, arrayNovo }) {
|
|
752
755
|
// Cria Sets para performance
|
|
753
756
|
const idsAntigos = new Set(arrayAntigo.map((item)=>item._id));
|
|
754
757
|
const idsNovos = new Set(arrayNovo.map((item)=>item._id));
|
|
@@ -849,15 +852,15 @@ class _hooks {
|
|
|
849
852
|
//BANCO DE DADOS
|
|
850
853
|
//SERVICES
|
|
851
854
|
const _environment = class _environment {
|
|
852
|
-
|
|
855
|
+
set(key, props) {
|
|
853
856
|
window.sessionStorage.setItem(key, props);
|
|
854
857
|
return;
|
|
855
858
|
}
|
|
856
|
-
|
|
859
|
+
get(key) {
|
|
857
860
|
return window.sessionStorage.getItem(key);
|
|
858
861
|
}
|
|
859
862
|
};
|
|
860
|
-
/* export default */ const utils_environment = (_environment);
|
|
863
|
+
/* export default */ const utils_environment = (new _environment);
|
|
861
864
|
|
|
862
865
|
;// CONCATENATED MODULE: ./src/utils/index.ts
|
|
863
866
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
declare class _form {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
regex_cpf_cnpj(value: string): string;
|
|
3
|
+
formatar_cpf(value: string): string;
|
|
4
|
+
formatar_cnpj(value: string): string;
|
|
5
|
+
formatar_cep(value: string): string;
|
|
6
|
+
formatar_telefone_fixo(value: string): string;
|
|
7
|
+
formatar_celular(value: string): string;
|
|
8
|
+
formatar_nome(name: string): string;
|
|
9
|
+
formatar_reais_br(value: string): string;
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
declare const _default: _form;
|
|
12
|
+
export default _default;
|