@navservice/core 1.97.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 +0 -1
- package/build/es/helpers/index.d.ts +13 -8
- package/build/es/helpers.js +34 -34
- package/build/es/index.js +44 -40
- 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 +0 -1
- package/build/lib/helpers/index.d.ts +13 -8
- package/build/lib/helpers.cjs +34 -34
- package/build/lib/index.cjs +44 -41
- 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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
declare class _data {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
get get_now_format_number(): number;
|
|
3
|
+
verificar_data(value: number): number;
|
|
4
4
|
}
|
|
5
|
-
|
|
5
|
+
declare const _default: _data;
|
|
6
|
+
export default _default;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
declare class _secret {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
readonly SALT_LENGTH = 22;
|
|
3
|
+
readonly KEY_LENGTH = 35;
|
|
4
|
+
gerar_hash_senha(password: string): Promise<string>;
|
|
5
|
+
verify({ password, dashed_senha }: {
|
|
6
6
|
password: string;
|
|
7
7
|
dashed_senha: string;
|
|
8
8
|
}): Promise<boolean>;
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
declare const _default: _secret;
|
|
11
|
+
export default _default;
|
|
@@ -3,9 +3,7 @@ type ResponseCOmmit = Omit<t.Geral.Response.C.Input, "type" | "code" | "status">
|
|
|
3
3
|
type ResponseErrorOmmit = Omit<t.Geral.Response.Error.Input, "type" | "code" | "status">;
|
|
4
4
|
export type ResponseCPayload<T = unknown> = Omit<t.Geral.Response.C.Input<T>, "c">;
|
|
5
5
|
declare const set_response: {
|
|
6
|
-
new (): {};
|
|
7
6
|
c: {
|
|
8
|
-
new (): {};
|
|
9
7
|
SUCCESS<T>({ message, results, c }: ResponseCOmmit): Response & import("hono").TypedResponse<{
|
|
10
8
|
status: 200 | 201 | 202 | 204 | 400 | 401 | 403 | 404 | 409 | 422 | 500 | 428 | 405;
|
|
11
9
|
code: "SUCCESS" | "ACTION_REQUIRED" | "CREATED" | "WARNING" | "AUTHORIZATION_ERROR" | "SCHEMA_VALIDATION" | "SERVER_ERROR" | "UNAUTHORIZED" | "INVALID_TOKEN" | "NOT_FOUND" | "SUCCESS_FILE" | "DATABASE_ERROR";
|
|
@@ -134,7 +132,6 @@ declare const set_response: {
|
|
|
134
132
|
}, 200, "json">)>;
|
|
135
133
|
};
|
|
136
134
|
error: {
|
|
137
|
-
new (): {};
|
|
138
135
|
ACTION_REQUIRED({ message, results }: ResponseErrorOmmit): void;
|
|
139
136
|
WARNING({ message, results }: ResponseErrorOmmit): void;
|
|
140
137
|
AUTHORIZATION_ERROR({ message, results }: ResponseErrorOmmit): void;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Next } from 'hono';
|
|
2
2
|
import t from '../types';
|
|
3
3
|
declare const _token: {
|
|
4
|
-
new (): {};
|
|
5
4
|
verificar_token(c: t.Context, next: Next): Promise<void | (Response & import("hono").TypedResponse<{
|
|
6
5
|
status: 200 | 201 | 202 | 204 | 400 | 401 | 403 | 404 | 409 | 422 | 500 | 428 | 405;
|
|
7
6
|
code: "SUCCESS" | "ACTION_REQUIRED" | "CREATED" | "WARNING" | "AUTHORIZATION_ERROR" | "SCHEMA_VALIDATION" | "SERVER_ERROR" | "UNAUTHORIZED" | "INVALID_TOKEN" | "NOT_FOUND" | "SUCCESS_FILE" | "DATABASE_ERROR";
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import _secret from "./_secret";
|
|
2
|
-
import _data from "./_data";
|
|
3
1
|
declare const helpers: {
|
|
4
2
|
set_response: {
|
|
5
|
-
new (): {};
|
|
6
3
|
c: {
|
|
7
|
-
new (): {};
|
|
8
4
|
SUCCESS<T>({ message, results, c }: {
|
|
9
5
|
message?: string | undefined;
|
|
10
6
|
results: any;
|
|
@@ -165,7 +161,6 @@ declare const helpers: {
|
|
|
165
161
|
}, 200, "json">)>;
|
|
166
162
|
};
|
|
167
163
|
error: {
|
|
168
|
-
new (): {};
|
|
169
164
|
ACTION_REQUIRED({ message, results }: {
|
|
170
165
|
message?: string | undefined;
|
|
171
166
|
results?: unknown;
|
|
@@ -203,7 +198,6 @@ declare const helpers: {
|
|
|
203
198
|
};
|
|
204
199
|
};
|
|
205
200
|
token: {
|
|
206
|
-
new (): {};
|
|
207
201
|
verificar_token(c: import("..").TypesCore.Context, next: import("hono").Next): Promise<void | (Response & import("hono").TypedResponse<{
|
|
208
202
|
status: 200 | 201 | 202 | 204 | 400 | 401 | 403 | 404 | 409 | 422 | 500 | 428 | 405;
|
|
209
203
|
code: "SUCCESS" | "ACTION_REQUIRED" | "CREATED" | "WARNING" | "AUTHORIZATION_ERROR" | "SCHEMA_VALIDATION" | "SERVER_ERROR" | "UNAUTHORIZED" | "INVALID_TOKEN" | "NOT_FOUND" | "SUCCESS_FILE" | "DATABASE_ERROR";
|
|
@@ -225,7 +219,18 @@ declare const helpers: {
|
|
|
225
219
|
c: import("..").TypesCore.Context;
|
|
226
220
|
}): Promise<string>;
|
|
227
221
|
};
|
|
228
|
-
secret:
|
|
229
|
-
|
|
222
|
+
secret: {
|
|
223
|
+
readonly SALT_LENGTH: 22;
|
|
224
|
+
readonly KEY_LENGTH: 35;
|
|
225
|
+
gerar_hash_senha(password: string): Promise<string>;
|
|
226
|
+
verify({ password, dashed_senha }: {
|
|
227
|
+
password: string;
|
|
228
|
+
dashed_senha: string;
|
|
229
|
+
}): Promise<boolean>;
|
|
230
|
+
};
|
|
231
|
+
data: {
|
|
232
|
+
get get_now_format_number(): number;
|
|
233
|
+
verificar_data(value: number): number;
|
|
234
|
+
};
|
|
230
235
|
};
|
|
231
236
|
export default helpers;
|
package/build/es/helpers.js
CHANGED
|
@@ -2,9 +2,9 @@ import v4 from "zod/v4";
|
|
|
2
2
|
import { SignJWT, jwtVerify } from "jose";
|
|
3
3
|
import { randomBytes, scrypt, timingSafeEqual } from "node:crypto";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
|
-
const set_response = class {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const set_response = new class {
|
|
6
|
+
c = new class {
|
|
7
|
+
SUCCESS({ message, results, c }) {
|
|
8
8
|
const payload = {
|
|
9
9
|
status: 200,
|
|
10
10
|
code: "SUCCESS",
|
|
@@ -16,7 +16,7 @@ const set_response = class {
|
|
|
16
16
|
status: 200
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
ACTION_REQUIRED({ message, results, c }) {
|
|
20
20
|
const payload = {
|
|
21
21
|
status: 428,
|
|
22
22
|
code: "ACTION_REQUIRED",
|
|
@@ -28,7 +28,7 @@ const set_response = class {
|
|
|
28
28
|
status: 428
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
CREATED({ message, results, c }) {
|
|
32
32
|
const payload = {
|
|
33
33
|
status: 201,
|
|
34
34
|
code: "CREATED",
|
|
@@ -40,7 +40,7 @@ const set_response = class {
|
|
|
40
40
|
status: 201
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
WARNING({ message, results, c }) {
|
|
44
44
|
const payload = {
|
|
45
45
|
status: 400,
|
|
46
46
|
code: "WARNING",
|
|
@@ -52,7 +52,7 @@ const set_response = class {
|
|
|
52
52
|
status: 400
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
|
-
|
|
55
|
+
AUTHORIZATION_ERROR({ message, results, c }) {
|
|
56
56
|
const payload = {
|
|
57
57
|
status: 405,
|
|
58
58
|
code: "WARNING",
|
|
@@ -64,7 +64,7 @@ const set_response = class {
|
|
|
64
64
|
status: 405
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
|
-
|
|
67
|
+
SERVER_ERROR({ error, c }) {
|
|
68
68
|
if (error instanceof v4.ZodError) {
|
|
69
69
|
const payload = {
|
|
70
70
|
status: 500,
|
|
@@ -88,7 +88,7 @@ const set_response = class {
|
|
|
88
88
|
status: error?.status || error?.status || 500
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
|
-
|
|
91
|
+
UNAUTHORIZED({ message, c }) {
|
|
92
92
|
const payload = {
|
|
93
93
|
status: 401,
|
|
94
94
|
code: "UNAUTHORIZED",
|
|
@@ -100,7 +100,7 @@ const set_response = class {
|
|
|
100
100
|
status: 401
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
|
-
|
|
103
|
+
INVALID_TOKEN({ message, c }) {
|
|
104
104
|
const payload = {
|
|
105
105
|
status: 409,
|
|
106
106
|
code: "INVALID_TOKEN",
|
|
@@ -112,7 +112,7 @@ const set_response = class {
|
|
|
112
112
|
status: 409
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
|
-
|
|
115
|
+
NOT_FOUND({ message, c }) {
|
|
116
116
|
const payload = {
|
|
117
117
|
status: 404,
|
|
118
118
|
code: "NOT_FOUND",
|
|
@@ -124,7 +124,7 @@ const set_response = class {
|
|
|
124
124
|
status: 404
|
|
125
125
|
});
|
|
126
126
|
}
|
|
127
|
-
|
|
127
|
+
async SUCCESS_FILE({ message, file_buffer, content_type, filename, c }) {
|
|
128
128
|
if (c && content_type) {
|
|
129
129
|
const headers = {
|
|
130
130
|
"Content-Type": content_type,
|
|
@@ -147,8 +147,8 @@ const set_response = class {
|
|
|
147
147
|
});
|
|
148
148
|
}
|
|
149
149
|
};
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
error = new class {
|
|
151
|
+
ACTION_REQUIRED({ message, results }) {
|
|
152
152
|
const payload = {
|
|
153
153
|
status: 428,
|
|
154
154
|
code: "ACTION_REQUIRED",
|
|
@@ -158,7 +158,7 @@ const set_response = class {
|
|
|
158
158
|
};
|
|
159
159
|
throw payload;
|
|
160
160
|
}
|
|
161
|
-
|
|
161
|
+
WARNING({ message, results }) {
|
|
162
162
|
const payload = {
|
|
163
163
|
status: 400,
|
|
164
164
|
code: "WARNING",
|
|
@@ -168,7 +168,7 @@ const set_response = class {
|
|
|
168
168
|
};
|
|
169
169
|
throw payload;
|
|
170
170
|
}
|
|
171
|
-
|
|
171
|
+
AUTHORIZATION_ERROR({ message, results }) {
|
|
172
172
|
const payload = {
|
|
173
173
|
status: 400,
|
|
174
174
|
code: "WARNING",
|
|
@@ -178,7 +178,7 @@ const set_response = class {
|
|
|
178
178
|
};
|
|
179
179
|
throw payload;
|
|
180
180
|
}
|
|
181
|
-
|
|
181
|
+
DATABASE_ERROR({ message, results, erro }) {
|
|
182
182
|
const errorCode = erro?.cause?.code || erro?.cause?.cause?.code || erro?.code || "";
|
|
183
183
|
const map = {
|
|
184
184
|
SQLITE_CONSTRAINT_UNIQUE: {
|
|
@@ -223,7 +223,7 @@ const set_response = class {
|
|
|
223
223
|
};
|
|
224
224
|
throw payload;
|
|
225
225
|
}
|
|
226
|
-
|
|
226
|
+
SCHEMA_VALIDATION({ results }) {
|
|
227
227
|
const payload = {
|
|
228
228
|
status: 500,
|
|
229
229
|
code: "SCHEMA_VALIDATION",
|
|
@@ -233,7 +233,7 @@ const set_response = class {
|
|
|
233
233
|
};
|
|
234
234
|
throw payload;
|
|
235
235
|
}
|
|
236
|
-
|
|
236
|
+
UNAUTHORIZED({ message }) {
|
|
237
237
|
const payload = {
|
|
238
238
|
status: 401,
|
|
239
239
|
code: "UNAUTHORIZED",
|
|
@@ -242,7 +242,7 @@ const set_response = class {
|
|
|
242
242
|
};
|
|
243
243
|
throw payload;
|
|
244
244
|
}
|
|
245
|
-
|
|
245
|
+
INVALID_TOKEN({ message }) {
|
|
246
246
|
const payload = {
|
|
247
247
|
status: 401,
|
|
248
248
|
code: "INVALID_TOKEN",
|
|
@@ -252,7 +252,7 @@ const set_response = class {
|
|
|
252
252
|
};
|
|
253
253
|
throw payload;
|
|
254
254
|
}
|
|
255
|
-
|
|
255
|
+
NOT_FOUND({ message }) {
|
|
256
256
|
const payload = {
|
|
257
257
|
status: 404,
|
|
258
258
|
code: "NOT_FOUND",
|
|
@@ -264,8 +264,8 @@ const set_response = class {
|
|
|
264
264
|
};
|
|
265
265
|
};
|
|
266
266
|
const _set_response = set_response;
|
|
267
|
-
const _token = class {
|
|
268
|
-
|
|
267
|
+
const _token = new class {
|
|
268
|
+
async verificar_token(c, next) {
|
|
269
269
|
try {
|
|
270
270
|
const authHeader = c.req.header("Authorization");
|
|
271
271
|
if (!authHeader) return _set_response.c.INVALID_TOKEN({
|
|
@@ -305,7 +305,7 @@ const _token = class {
|
|
|
305
305
|
});
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
|
-
|
|
308
|
+
async criar_token_login_usuario({ _id, email, app, usuario_tipo, ativo, data_criacao, nome, c }) {
|
|
309
309
|
if (!c.env.JSON_WEB_TOKEN_AUTH_USER) return _set_response.error.WARNING({
|
|
310
310
|
message: "Erro ao gerar token!!",
|
|
311
311
|
results: []
|
|
@@ -326,7 +326,7 @@ const _token = class {
|
|
|
326
326
|
}));
|
|
327
327
|
return token;
|
|
328
328
|
}
|
|
329
|
-
|
|
329
|
+
async verificar_token_micro_servico(c, next) {
|
|
330
330
|
try {
|
|
331
331
|
const authHeader = c.req.header("Authorization");
|
|
332
332
|
if (!authHeader) return _set_response.c.INVALID_TOKEN({
|
|
@@ -366,7 +366,7 @@ const _token = class {
|
|
|
366
366
|
});
|
|
367
367
|
}
|
|
368
368
|
}
|
|
369
|
-
|
|
369
|
+
async criar_token_micro_servico({ c }) {
|
|
370
370
|
if (!c.env.JSON_WEB_TOKEN_AUTH_MICRO_SERVICO) return _set_response.error.WARNING({
|
|
371
371
|
message: "Erro ao gerar token!!",
|
|
372
372
|
results: []
|
|
@@ -392,14 +392,14 @@ const _token = class {
|
|
|
392
392
|
const helpers_token = _token;
|
|
393
393
|
const scryptAsync = promisify(scrypt);
|
|
394
394
|
class _secret {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
395
|
+
SALT_LENGTH = 22;
|
|
396
|
+
KEY_LENGTH = 35;
|
|
397
|
+
async gerar_hash_senha(password) {
|
|
398
398
|
const salt = randomBytes(this.SALT_LENGTH);
|
|
399
399
|
const derivedKey = await scryptAsync(password, salt, this.KEY_LENGTH);
|
|
400
400
|
return salt.toString('base64') + '.' + derivedKey.toString('base64');
|
|
401
401
|
}
|
|
402
|
-
|
|
402
|
+
async verify({ password, dashed_senha }) {
|
|
403
403
|
try {
|
|
404
404
|
const [saltBase64, hashBase64] = dashed_senha.split('.');
|
|
405
405
|
if (!saltBase64 || !hashBase64) return false;
|
|
@@ -412,18 +412,18 @@ class _secret {
|
|
|
412
412
|
}
|
|
413
413
|
}
|
|
414
414
|
}
|
|
415
|
-
const helpers_secret = _secret;
|
|
415
|
+
const helpers_secret = new _secret;
|
|
416
416
|
class _data {
|
|
417
|
-
|
|
417
|
+
get get_now_format_number() {
|
|
418
418
|
return Math.floor(Date.now() / 1000);
|
|
419
419
|
}
|
|
420
|
-
|
|
420
|
+
verificar_data(value) {
|
|
421
421
|
const data = new Date(1000 * value);
|
|
422
422
|
if (isNaN(data.getTime())) throw new Error("Timestamp está inválido.");
|
|
423
423
|
return value;
|
|
424
424
|
}
|
|
425
425
|
}
|
|
426
|
-
const helpers_data = _data;
|
|
426
|
+
const helpers_data = new _data;
|
|
427
427
|
const helpers = {
|
|
428
428
|
set_response: _set_response,
|
|
429
429
|
token: helpers_token,
|
package/build/es/index.js
CHANGED
|
@@ -109,8 +109,8 @@ var _type_response_TypeControllerResponse;
|
|
|
109
109
|
})(types_t || (types_t = {}));
|
|
110
110
|
const types = types_t;
|
|
111
111
|
var types_t;
|
|
112
|
-
const _session_storage = class {
|
|
113
|
-
|
|
112
|
+
const _session_storage = new class {
|
|
113
|
+
adicionar_item_session_storage({ chave, novoItem }) {
|
|
114
114
|
try {
|
|
115
115
|
const valorAtual = window.sessionStorage.getItem(chave);
|
|
116
116
|
const listaAtual = valorAtual ? JSON.parse(valorAtual) : [];
|
|
@@ -123,14 +123,14 @@ const _session_storage = class {
|
|
|
123
123
|
console.error(error);
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
|
|
126
|
+
set_session_storage_sem_incremento({ chave, novoItem }) {
|
|
127
127
|
try {
|
|
128
128
|
window.sessionStorage.setItem(chave, JSON.stringify(novoItem));
|
|
129
129
|
} catch (error) {
|
|
130
130
|
console.error(error);
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
|
|
133
|
+
get_item_session_storage(chave) {
|
|
134
134
|
try {
|
|
135
135
|
if ("undefined" != typeof window) {
|
|
136
136
|
const valorAtual = window.sessionStorage.getItem(chave);
|
|
@@ -141,13 +141,17 @@ const _session_storage = class {
|
|
|
141
141
|
console.error(error);
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
|
|
144
|
+
remover_item_session_storage(chave) {
|
|
145
145
|
try {
|
|
146
146
|
window.sessionStorage.removeItem(chave);
|
|
147
147
|
} catch (error) {
|
|
148
148
|
console.error(error);
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
+
get usuario_auth() {
|
|
152
|
+
const get_auth_user = this.get_item_session_storage("auth_user");
|
|
153
|
+
return get_auth_user;
|
|
154
|
+
}
|
|
151
155
|
};
|
|
152
156
|
const utils_session_storage = _session_storage;
|
|
153
157
|
const _api_api = class _api {
|
|
@@ -233,8 +237,8 @@ const _api_api = class _api {
|
|
|
233
237
|
}
|
|
234
238
|
};
|
|
235
239
|
const utils_api = _api_api;
|
|
236
|
-
const _data = class {
|
|
237
|
-
|
|
240
|
+
const _data = new class {
|
|
241
|
+
YYYY_MM_DD_00_00_00(newData) {
|
|
238
242
|
let dataAtual = new Date();
|
|
239
243
|
if (newData) dataAtual = new Date(newData);
|
|
240
244
|
const options = {
|
|
@@ -249,7 +253,7 @@ const _data = class {
|
|
|
249
253
|
const [dia, mes, ano] = data.split("/");
|
|
250
254
|
return `${ano}-${mes}-${dia} ${hora}`;
|
|
251
255
|
}
|
|
252
|
-
|
|
256
|
+
DD_MM_YYYY_00_00_00(newData) {
|
|
253
257
|
let dataAtual = new Date();
|
|
254
258
|
if (newData) dataAtual = new Date(newData);
|
|
255
259
|
const options = {
|
|
@@ -261,7 +265,7 @@ const _data = class {
|
|
|
261
265
|
};
|
|
262
266
|
return dataAtual.toLocaleString("pt-BR", options);
|
|
263
267
|
}
|
|
264
|
-
|
|
268
|
+
DD_MM_YYYY_00_00(newData) {
|
|
265
269
|
let dataAtual = new Date();
|
|
266
270
|
if (newData) dataAtual = new Date(newData);
|
|
267
271
|
const options = {
|
|
@@ -274,7 +278,7 @@ const _data = class {
|
|
|
274
278
|
const dataFormatada = dataAtual.toLocaleString("pt-BR", options).replace(",", "");
|
|
275
279
|
return dataFormatada;
|
|
276
280
|
}
|
|
277
|
-
|
|
281
|
+
DD_MM_YYYY(newData) {
|
|
278
282
|
let dataAtual = new Date();
|
|
279
283
|
if (newData) dataAtual = new Date(newData);
|
|
280
284
|
const options = {
|
|
@@ -286,7 +290,7 @@ const _data = class {
|
|
|
286
290
|
};
|
|
287
291
|
return dataAtual.toLocaleString("pt-BR", options);
|
|
288
292
|
}
|
|
289
|
-
|
|
293
|
+
YYYY_MM_DD(newData) {
|
|
290
294
|
let dataAtual = new Date();
|
|
291
295
|
if (newData) dataAtual = new Date(newData);
|
|
292
296
|
const options = {
|
|
@@ -301,21 +305,21 @@ const _data = class {
|
|
|
301
305
|
const [dia, mes, ano] = data.split("/");
|
|
302
306
|
return `${ano}-${mes}-${dia}`;
|
|
303
307
|
}
|
|
304
|
-
|
|
308
|
+
DIFERENCA_SEGUNDOS(data) {
|
|
305
309
|
var dataInicial = new Date(data);
|
|
306
310
|
var dataAtual = new Date();
|
|
307
311
|
var diferenca = Number(dataAtual) - Number(dataInicial);
|
|
308
312
|
var diferencaEmSegundos = Math.floor(diferenca / 1000);
|
|
309
313
|
return diferencaEmSegundos;
|
|
310
314
|
}
|
|
311
|
-
|
|
315
|
+
DIFERENCA_DIAS(data) {
|
|
312
316
|
var dataInicial = new Date(data);
|
|
313
317
|
var dataAtual = new Date();
|
|
314
318
|
var diferenca = dataAtual.getTime() - dataInicial.getTime();
|
|
315
319
|
var diferencaEmDias = Math.floor(diferenca / 86400000);
|
|
316
320
|
return diferencaEmDias;
|
|
317
321
|
}
|
|
318
|
-
|
|
322
|
+
SET_SECONDS_TO_DD_MM_YYYY_HH_MM(timestamp) {
|
|
319
323
|
const segundos = Number(timestamp);
|
|
320
324
|
if (!Number.isFinite(segundos)) return "-";
|
|
321
325
|
const data = new Date(1000 * segundos);
|
|
@@ -332,7 +336,7 @@ const _data = class {
|
|
|
332
336
|
};
|
|
333
337
|
const utils_data = _data;
|
|
334
338
|
class _form {
|
|
335
|
-
|
|
339
|
+
regex_cpf_cnpj(value) {
|
|
336
340
|
let tempValue = value.replace(/\D/g, "");
|
|
337
341
|
if (tempValue.length > 14) tempValue = tempValue.slice(0, 14);
|
|
338
342
|
tempValue = tempValue.length <= 11 ? tempValue.replace(/^(\d{0,3})(\d{0,3})(\d{0,3})(\d{0,2})$/, (match, p1, p2, p3, p4)=>{
|
|
@@ -351,7 +355,7 @@ class _form {
|
|
|
351
355
|
});
|
|
352
356
|
return tempValue;
|
|
353
357
|
}
|
|
354
|
-
|
|
358
|
+
formatar_cpf(value) {
|
|
355
359
|
const cpf = value.replace(/\D/g, "");
|
|
356
360
|
if (cpf.length > 11) return cpf.slice(0, 11);
|
|
357
361
|
return cpf.replace(/^(\d{0,3})(\d{0,3})(\d{0,3})(\d{0,2})$/, (match, p1, p2, p3, p4)=>{
|
|
@@ -362,7 +366,7 @@ class _form {
|
|
|
362
366
|
return result;
|
|
363
367
|
});
|
|
364
368
|
}
|
|
365
|
-
|
|
369
|
+
formatar_cnpj(value) {
|
|
366
370
|
const cnpj = value.replace(/\D/g, "");
|
|
367
371
|
if (cnpj.length > 14) return cnpj.slice(0, 14);
|
|
368
372
|
return cnpj.replace(/^(\d{0,2})(\d{0,3})(\d{0,3})(\d{0,4})(\d{0,2})$/, (match, p1, p2, p3, p4, p5)=>{
|
|
@@ -374,7 +378,7 @@ class _form {
|
|
|
374
378
|
return result;
|
|
375
379
|
});
|
|
376
380
|
}
|
|
377
|
-
|
|
381
|
+
formatar_cep(value) {
|
|
378
382
|
const cep = value.replace(/\D/g, "");
|
|
379
383
|
if (cep.length > 8) return cep.slice(0, 8);
|
|
380
384
|
return cep.replace(/^(\d{0,5})(\d{0,3})$/, (match, p1, p2)=>{
|
|
@@ -382,7 +386,7 @@ class _form {
|
|
|
382
386
|
return p1;
|
|
383
387
|
});
|
|
384
388
|
}
|
|
385
|
-
|
|
389
|
+
formatar_telefone_fixo(value) {
|
|
386
390
|
const telefone = value.replace(/\D/g, "");
|
|
387
391
|
if (telefone.length > 10) return telefone.slice(0, 10);
|
|
388
392
|
return telefone.replace(/^(\d{0,2})(\d{0,4})(\d{0,4})$/, (match, p1, p2, p3)=>{
|
|
@@ -393,7 +397,7 @@ class _form {
|
|
|
393
397
|
return result;
|
|
394
398
|
});
|
|
395
399
|
}
|
|
396
|
-
|
|
400
|
+
formatar_celular(value) {
|
|
397
401
|
const celular = value.replace(/\D/g, "");
|
|
398
402
|
if (celular.length > 11) return celular.slice(0, 11);
|
|
399
403
|
return celular.replace(/^(\d{0,2})(\d{0,5})(\d{0,4})$/, (match, p1, p2, p3)=>{
|
|
@@ -404,7 +408,7 @@ class _form {
|
|
|
404
408
|
return result;
|
|
405
409
|
});
|
|
406
410
|
}
|
|
407
|
-
|
|
411
|
+
formatar_nome(name) {
|
|
408
412
|
const lowercaseWords = [
|
|
409
413
|
"de",
|
|
410
414
|
"da",
|
|
@@ -423,7 +427,7 @@ class _form {
|
|
|
423
427
|
});
|
|
424
428
|
return formattedWords.join(" ");
|
|
425
429
|
}
|
|
426
|
-
|
|
430
|
+
formatar_reais_br(value) {
|
|
427
431
|
let num = value.replace(/\D/g, "");
|
|
428
432
|
return new Intl.NumberFormat("pt-BR", {
|
|
429
433
|
style: "currency",
|
|
@@ -432,9 +436,9 @@ class _form {
|
|
|
432
436
|
}).format(Number(num) / 100);
|
|
433
437
|
}
|
|
434
438
|
}
|
|
435
|
-
const utils_form = _form;
|
|
436
|
-
const geral = class {
|
|
437
|
-
|
|
439
|
+
const utils_form = new _form;
|
|
440
|
+
const geral = new class {
|
|
441
|
+
slice_file_name(filename, maxLength = 30) {
|
|
438
442
|
if (!filename || "string" != typeof filename) return "";
|
|
439
443
|
const lastDotIndex = filename.lastIndexOf(".");
|
|
440
444
|
if (-1 === lastDotIndex) return filename.length > maxLength ? filename.substring(0, maxLength - 3) + "..." : filename;
|
|
@@ -445,12 +449,12 @@ const geral = class {
|
|
|
445
449
|
if (availableLength <= 0) return name.substring(0, 1) + "..." + extension;
|
|
446
450
|
return name.substring(0, availableLength) + "..." + extension;
|
|
447
451
|
}
|
|
448
|
-
|
|
452
|
+
extrair_id(array_enviado) {
|
|
449
453
|
const ids = [];
|
|
450
454
|
for(let i = 0; i < array_enviado.length; i++)if (array_enviado[i]?._id) ids.push(array_enviado[i]._id);
|
|
451
455
|
return ids;
|
|
452
456
|
}
|
|
453
|
-
|
|
457
|
+
gerar_id = (length = 32)=>{
|
|
454
458
|
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
455
459
|
const timestamp = Date.now().toString(16) + performance.now().toString(16).replace(".", "");
|
|
456
460
|
let result = timestamp;
|
|
@@ -464,8 +468,8 @@ const geral = class {
|
|
|
464
468
|
};
|
|
465
469
|
};
|
|
466
470
|
const _geral = geral;
|
|
467
|
-
const _local_storage = class {
|
|
468
|
-
|
|
471
|
+
const _local_storage = new class {
|
|
472
|
+
adicionar_item_local_storage(chave, novoItem) {
|
|
469
473
|
try {
|
|
470
474
|
const valorAtual = window.localStorage.getItem(chave);
|
|
471
475
|
const listaAtual = valorAtual ? JSON.parse(valorAtual) : [];
|
|
@@ -478,14 +482,14 @@ const _local_storage = class {
|
|
|
478
482
|
console.log(error);
|
|
479
483
|
}
|
|
480
484
|
}
|
|
481
|
-
|
|
485
|
+
set_local_storage_sem_incremento(chave, novoItem) {
|
|
482
486
|
try {
|
|
483
487
|
window.localStorage.setItem(chave, JSON.stringify(novoItem));
|
|
484
488
|
} catch (error) {
|
|
485
489
|
console.log(error);
|
|
486
490
|
}
|
|
487
491
|
}
|
|
488
|
-
|
|
492
|
+
get_item_local_storage(chave) {
|
|
489
493
|
try {
|
|
490
494
|
if ("undefined" != typeof window) {
|
|
491
495
|
const valorAtual = window.localStorage.getItem(chave);
|
|
@@ -496,7 +500,7 @@ const _local_storage = class {
|
|
|
496
500
|
console.log(error);
|
|
497
501
|
}
|
|
498
502
|
}
|
|
499
|
-
|
|
503
|
+
remover_item_local_storage(chave) {
|
|
500
504
|
try {
|
|
501
505
|
window.localStorage.removeItem(chave);
|
|
502
506
|
} catch (error) {
|
|
@@ -505,8 +509,8 @@ const _local_storage = class {
|
|
|
505
509
|
}
|
|
506
510
|
};
|
|
507
511
|
const utils_local_storage = _local_storage;
|
|
508
|
-
const _update_context = class {
|
|
509
|
-
|
|
512
|
+
const _update_context = new class {
|
|
513
|
+
set_new_item_end = ({ oldArray = [], newItem = [], key = "_id" })=>{
|
|
510
514
|
try {
|
|
511
515
|
const hasValidIds = Array.isArray(newItem) ? newItem.every((item)=>item?.[key]) : newItem?.[key];
|
|
512
516
|
const newItemArray = hasValidIds ? Array.isArray(newItem) ? newItem : [
|
|
@@ -535,7 +539,7 @@ const _update_context = class {
|
|
|
535
539
|
return oldArray;
|
|
536
540
|
}
|
|
537
541
|
};
|
|
538
|
-
|
|
542
|
+
update_array_itens = ({ oldArray = [], newItem = [], key = "_id" })=>{
|
|
539
543
|
try {
|
|
540
544
|
const hasValidIds = Array.isArray(newItem) ? newItem.every((item)=>item?.[key]) : newItem?.[key];
|
|
541
545
|
const newItemArray = hasValidIds ? Array.isArray(newItem) ? newItem : [
|
|
@@ -564,7 +568,7 @@ const _update_context = class {
|
|
|
564
568
|
return oldArray;
|
|
565
569
|
}
|
|
566
570
|
};
|
|
567
|
-
|
|
571
|
+
remove_array_items = ({ oldArray = [], itemsToRemove = [], key = "_id" })=>{
|
|
568
572
|
try {
|
|
569
573
|
if (!Array.isArray(oldArray) || 0 === oldArray.length) return oldArray;
|
|
570
574
|
if (!itemsToRemove) return oldArray;
|
|
@@ -580,7 +584,7 @@ const _update_context = class {
|
|
|
580
584
|
return oldArray;
|
|
581
585
|
}
|
|
582
586
|
};
|
|
583
|
-
|
|
587
|
+
compare_arrays({ arrayAntigo, arrayNovo }) {
|
|
584
588
|
const idsAntigos = new Set(arrayAntigo.map((item)=>item._id));
|
|
585
589
|
const idsNovos = new Set(arrayNovo.map((item)=>item._id));
|
|
586
590
|
const itensMantidos = arrayAntigo.filter((item)=>idsNovos.has(item._id));
|
|
@@ -664,14 +668,14 @@ class _hooks {
|
|
|
664
668
|
}
|
|
665
669
|
const utils_hooks = new _hooks;
|
|
666
670
|
const _environment = class {
|
|
667
|
-
|
|
671
|
+
set(key, props) {
|
|
668
672
|
window.sessionStorage.setItem(key, props);
|
|
669
673
|
}
|
|
670
|
-
|
|
674
|
+
get(key) {
|
|
671
675
|
return window.sessionStorage.getItem(key);
|
|
672
676
|
}
|
|
673
677
|
};
|
|
674
|
-
const utils_environment = _environment;
|
|
678
|
+
const utils_environment = new _environment;
|
|
675
679
|
const utils = {
|
|
676
680
|
api: utils_api,
|
|
677
681
|
data: utils_data,
|