@navservice/core 1.63.0 → 1.65.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/index.d.ts +11 -11
- package/build/lib/helpers/index.d.ts +11 -11
- package/build/lib/{index.browser.cjs → index.cjs} +43 -85
- package/package.json +4 -10
- package/build/es/index.node.js +0 -374
- package/build/es/utils.js +0 -638
- package/build/lib/index.node.cjs +0 -510
- package/build/lib/utils.cjs +0 -877
- /package/build/es/{index.browser.d.ts → index.d.ts} +0 -0
- /package/build/es/{index.browser.js → index.js} +0 -0
- /package/build/lib/{index.browser.d.ts → index.d.ts} +0 -0
package/build/es/utils.js
DELETED
|
@@ -1,638 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import v4 from "zod/v4";
|
|
3
|
-
import { useLayoutEffect, useState } from "react";
|
|
4
|
-
class config_env {
|
|
5
|
-
static SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL;
|
|
6
|
-
static init(config) {
|
|
7
|
-
config_env.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL = config.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL;
|
|
8
|
-
}
|
|
9
|
-
static get PUBLIC_BASE_URL_BACKEND_PRINCIPAL() {
|
|
10
|
-
return this.SET_PUBLIC_BASE_URL_BACKEND_PRINCIPAL?.trim();
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
const src_config_env = config_env;
|
|
14
|
-
(function(TypeControllerUsuario) {
|
|
15
|
-
TypeControllerUsuario.AppEnum = [
|
|
16
|
-
"service-usuario",
|
|
17
|
-
"service-financeiro",
|
|
18
|
-
"service-pages-ai"
|
|
19
|
-
];
|
|
20
|
-
TypeControllerUsuario.UsuarioTipoEnum = [
|
|
21
|
-
"padrao"
|
|
22
|
-
];
|
|
23
|
-
v4["enum"]([
|
|
24
|
-
"service-usuario",
|
|
25
|
-
"service-financeiro",
|
|
26
|
-
"service-pages-ai"
|
|
27
|
-
]);
|
|
28
|
-
v4["enum"](TypeControllerUsuario.UsuarioTipoEnum);
|
|
29
|
-
})(_usuario_TypeControllerUsuario || (_usuario_TypeControllerUsuario = {}));
|
|
30
|
-
const _usuario = _usuario_TypeControllerUsuario;
|
|
31
|
-
var _usuario_TypeControllerUsuario;
|
|
32
|
-
(function(TypeControllerResponse) {
|
|
33
|
-
const StatusSchema = v4.union([
|
|
34
|
-
v4.literal(200),
|
|
35
|
-
v4.literal(201),
|
|
36
|
-
v4.literal(202),
|
|
37
|
-
v4.literal(204),
|
|
38
|
-
v4.literal(400),
|
|
39
|
-
v4.literal(401),
|
|
40
|
-
v4.literal(403),
|
|
41
|
-
v4.literal(404),
|
|
42
|
-
v4.literal(409),
|
|
43
|
-
v4.literal(422),
|
|
44
|
-
v4.literal(500),
|
|
45
|
-
v4.literal(428),
|
|
46
|
-
v4.literal(405)
|
|
47
|
-
]);
|
|
48
|
-
const TypeSchema = v4.union([
|
|
49
|
-
v4.literal("success"),
|
|
50
|
-
v4.literal("warning"),
|
|
51
|
-
v4.literal("error")
|
|
52
|
-
]).default("success");
|
|
53
|
-
const CodeSchema = v4.union([
|
|
54
|
-
v4.literal("SUCCESS"),
|
|
55
|
-
v4.literal("ACTION_REQUIRED"),
|
|
56
|
-
v4.literal("CREATED"),
|
|
57
|
-
v4.literal("WARNING"),
|
|
58
|
-
v4.literal("AUTHORIZATION_ERROR"),
|
|
59
|
-
v4.literal("SCHEMA_VALIDATION"),
|
|
60
|
-
v4.literal("SERVER_ERROR"),
|
|
61
|
-
v4.literal("UNAUTHORIZED"),
|
|
62
|
-
v4.literal("INVALID_TOKEN"),
|
|
63
|
-
v4.literal("NOT_FOUND"),
|
|
64
|
-
v4.literal("SUCCESS_FILE"),
|
|
65
|
-
v4.literal("DATABASE_ERROR")
|
|
66
|
-
]);
|
|
67
|
-
v4.object({
|
|
68
|
-
status: StatusSchema,
|
|
69
|
-
code: CodeSchema,
|
|
70
|
-
type: TypeSchema,
|
|
71
|
-
message: v4.string(),
|
|
72
|
-
results: v4.unknown().optional(),
|
|
73
|
-
error: v4.unknown().optional()
|
|
74
|
-
});
|
|
75
|
-
(function(C) {
|
|
76
|
-
C.InputSchema = v4.object({
|
|
77
|
-
status: StatusSchema,
|
|
78
|
-
code: CodeSchema,
|
|
79
|
-
type: TypeSchema.optional().default("success"),
|
|
80
|
-
message: v4.string().optional(),
|
|
81
|
-
results: v4.any(),
|
|
82
|
-
c: v4.custom()
|
|
83
|
-
});
|
|
84
|
-
v4.object({
|
|
85
|
-
status: StatusSchema,
|
|
86
|
-
message: v4.string().optional(),
|
|
87
|
-
file_buffer: v4.union([
|
|
88
|
-
v4["instanceof"](Blob),
|
|
89
|
-
v4["instanceof"](ArrayBuffer),
|
|
90
|
-
v4["instanceof"](Uint8Array)
|
|
91
|
-
]),
|
|
92
|
-
content_type: v4.string(),
|
|
93
|
-
filename: v4.string().optional(),
|
|
94
|
-
c: v4.custom().optional()
|
|
95
|
-
});
|
|
96
|
-
})(TypeControllerResponse.C || (TypeControllerResponse.C = {}));
|
|
97
|
-
(function(Error) {
|
|
98
|
-
Error.InputSchema = v4.object({
|
|
99
|
-
message: v4.string().optional(),
|
|
100
|
-
results: v4.union([
|
|
101
|
-
v4.array(v4.unknown()),
|
|
102
|
-
v4.unknown()
|
|
103
|
-
]).optional(),
|
|
104
|
-
type: TypeSchema.optional().default("success"),
|
|
105
|
-
code: CodeSchema,
|
|
106
|
-
status: v4.number().optional().default(200)
|
|
107
|
-
});
|
|
108
|
-
})(TypeControllerResponse.Error || (TypeControllerResponse.Error = {}));
|
|
109
|
-
})(_type_response_TypeControllerResponse || (_type_response_TypeControllerResponse = {}));
|
|
110
|
-
const _type_response = _type_response_TypeControllerResponse;
|
|
111
|
-
var _type_response_TypeControllerResponse;
|
|
112
|
-
(function(t) {
|
|
113
|
-
(function(Controller) {
|
|
114
|
-
Controller.Usuario = _usuario;
|
|
115
|
-
})(t.Controller || (t.Controller = {}));
|
|
116
|
-
(function(Geral) {
|
|
117
|
-
Geral.Response = _type_response;
|
|
118
|
-
})(t.Geral || (t.Geral = {}));
|
|
119
|
-
})(types_t || (types_t = {}));
|
|
120
|
-
var types_t;
|
|
121
|
-
const _data_data = class {
|
|
122
|
-
static YYYY_MM_DD_00_00_00(newData) {
|
|
123
|
-
let dataAtual = new Date();
|
|
124
|
-
if (newData) dataAtual = new Date(newData);
|
|
125
|
-
const options = {
|
|
126
|
-
timeZone: "America/Sao_Paulo",
|
|
127
|
-
ano: "numeric",
|
|
128
|
-
mes: "numeric",
|
|
129
|
-
dia: "numeric",
|
|
130
|
-
hora: "numeric"
|
|
131
|
-
};
|
|
132
|
-
const horarioFormatado = dataAtual.toLocaleString("pt-BR", options);
|
|
133
|
-
const [data, hora] = horarioFormatado.split(",");
|
|
134
|
-
const [dia, mes, ano] = data.split("/");
|
|
135
|
-
return `${ano}-${mes}-${dia} ${hora}`;
|
|
136
|
-
}
|
|
137
|
-
static DD_MM_YYYY_00_00_00(newData) {
|
|
138
|
-
let dataAtual = new Date();
|
|
139
|
-
if (newData) dataAtual = new Date(newData);
|
|
140
|
-
const options = {
|
|
141
|
-
timeZone: "America/Sao_Paulo",
|
|
142
|
-
ano: "numeric",
|
|
143
|
-
mes: "numeric",
|
|
144
|
-
dia: "numeric",
|
|
145
|
-
hora: "numeric"
|
|
146
|
-
};
|
|
147
|
-
return dataAtual.toLocaleString("pt-BR", options);
|
|
148
|
-
}
|
|
149
|
-
static DD_MM_YYYY_00_00(newData) {
|
|
150
|
-
let dataAtual = new Date();
|
|
151
|
-
if (newData) dataAtual = new Date(newData);
|
|
152
|
-
const options = {
|
|
153
|
-
timeZone: "America/Sao_Paulo",
|
|
154
|
-
ano: "numeric",
|
|
155
|
-
mes: "numeric",
|
|
156
|
-
dia: "numeric",
|
|
157
|
-
hora: "numeric"
|
|
158
|
-
};
|
|
159
|
-
const dataFormatada = dataAtual.toLocaleString("pt-BR", options).replace(",", "");
|
|
160
|
-
return dataFormatada;
|
|
161
|
-
}
|
|
162
|
-
static DD_MM_YYYY(newData) {
|
|
163
|
-
let dataAtual = new Date();
|
|
164
|
-
if (newData) dataAtual = new Date(newData);
|
|
165
|
-
const options = {
|
|
166
|
-
timeZone: "America/Sao_Paulo",
|
|
167
|
-
ano: "numeric",
|
|
168
|
-
mes: "numeric",
|
|
169
|
-
dia: "numeric",
|
|
170
|
-
hora: "numeric"
|
|
171
|
-
};
|
|
172
|
-
return dataAtual.toLocaleString("pt-BR", options);
|
|
173
|
-
}
|
|
174
|
-
static YYYY_MM_DD(newData) {
|
|
175
|
-
let dataAtual = new Date();
|
|
176
|
-
if (newData) dataAtual = new Date(newData);
|
|
177
|
-
const options = {
|
|
178
|
-
timeZone: "America/Sao_Paulo",
|
|
179
|
-
ano: "numeric",
|
|
180
|
-
mes: "numeric",
|
|
181
|
-
dia: "numeric",
|
|
182
|
-
hora: "numeric"
|
|
183
|
-
};
|
|
184
|
-
const horarioFormatado = dataAtual.toLocaleString("pt-BR", options);
|
|
185
|
-
const [data] = horarioFormatado.split(",");
|
|
186
|
-
const [dia, mes, ano] = data.split("/");
|
|
187
|
-
return `${ano}-${mes}-${dia}`;
|
|
188
|
-
}
|
|
189
|
-
static DIFERENCA_SEGUNDOS(data) {
|
|
190
|
-
var dataInicial = new Date(data);
|
|
191
|
-
var dataAtual = new Date();
|
|
192
|
-
var diferenca = Number(dataAtual) - Number(dataInicial);
|
|
193
|
-
var diferencaEmSegundos = Math.floor(diferenca / 1000);
|
|
194
|
-
return diferencaEmSegundos;
|
|
195
|
-
}
|
|
196
|
-
static DIFERENCA_DIAS(data) {
|
|
197
|
-
var dataInicial = new Date(data);
|
|
198
|
-
var dataAtual = new Date();
|
|
199
|
-
var diferenca = dataAtual.getTime() - dataInicial.getTime();
|
|
200
|
-
var diferencaEmDias = Math.floor(diferenca / 86400000);
|
|
201
|
-
return diferencaEmDias;
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
const utils_data = _data_data;
|
|
205
|
-
class _form_form {
|
|
206
|
-
static regex_cpf_cnpj(value) {
|
|
207
|
-
let tempValue = value.replace(/\D/g, "");
|
|
208
|
-
if (tempValue.length > 14) tempValue = tempValue.slice(0, 14);
|
|
209
|
-
tempValue = tempValue.length <= 11 ? tempValue.replace(/^(\d{0,3})(\d{0,3})(\d{0,3})(\d{0,2})$/, (match, p1, p2, p3, p4)=>{
|
|
210
|
-
let result = p1;
|
|
211
|
-
if (p2) result += "." + p2;
|
|
212
|
-
if (p3) result += "." + p3;
|
|
213
|
-
if (p4) result += "-" + p4;
|
|
214
|
-
return result;
|
|
215
|
-
}) : tempValue.replace(/^(\d{0,2})(\d{0,3})(\d{0,3})(\d{0,4})(\d{0,2})$/, (match, p1, p2, p3, p4, p5)=>{
|
|
216
|
-
let result = p1;
|
|
217
|
-
if (p2) result += "." + p2;
|
|
218
|
-
if (p3) result += "." + p3;
|
|
219
|
-
if (p4) result += "/" + p4;
|
|
220
|
-
if (p5) result += "-" + p5;
|
|
221
|
-
return result;
|
|
222
|
-
});
|
|
223
|
-
return tempValue;
|
|
224
|
-
}
|
|
225
|
-
static formatar_cpf(value) {
|
|
226
|
-
const cpf = value.replace(/\D/g, "");
|
|
227
|
-
if (cpf.length > 11) return cpf.slice(0, 11);
|
|
228
|
-
return cpf.replace(/^(\d{0,3})(\d{0,3})(\d{0,3})(\d{0,2})$/, (match, p1, p2, p3, p4)=>{
|
|
229
|
-
let result = p1;
|
|
230
|
-
if (p2) result += "." + p2;
|
|
231
|
-
if (p3) result += "." + p3;
|
|
232
|
-
if (p4) result += "-" + p4;
|
|
233
|
-
return result;
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
static formatar_cnpj(value) {
|
|
237
|
-
const cnpj = value.replace(/\D/g, "");
|
|
238
|
-
if (cnpj.length > 14) return cnpj.slice(0, 14);
|
|
239
|
-
return cnpj.replace(/^(\d{0,2})(\d{0,3})(\d{0,3})(\d{0,4})(\d{0,2})$/, (match, p1, p2, p3, p4, p5)=>{
|
|
240
|
-
let result = p1;
|
|
241
|
-
if (p2) result += "." + p2;
|
|
242
|
-
if (p3) result += "." + p3;
|
|
243
|
-
if (p4) result += "/" + p4;
|
|
244
|
-
if (p5) result += "-" + p5;
|
|
245
|
-
return result;
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
static formatar_cep(value) {
|
|
249
|
-
const cep = value.replace(/\D/g, "");
|
|
250
|
-
if (cep.length > 8) return cep.slice(0, 8);
|
|
251
|
-
return cep.replace(/^(\d{0,5})(\d{0,3})$/, (match, p1, p2)=>{
|
|
252
|
-
if (p2) return `${p1}-${p2}`;
|
|
253
|
-
return p1;
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
static formatar_telefone_fixo(value) {
|
|
257
|
-
const telefone = value.replace(/\D/g, "");
|
|
258
|
-
if (telefone.length > 10) return telefone.slice(0, 10);
|
|
259
|
-
return telefone.replace(/^(\d{0,2})(\d{0,4})(\d{0,4})$/, (match, p1, p2, p3)=>{
|
|
260
|
-
let result = "";
|
|
261
|
-
if (p1) result += `(${p1}`;
|
|
262
|
-
if (p2) result += `) ${p2}`;
|
|
263
|
-
if (p3) result += `-${p3}`;
|
|
264
|
-
return result;
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
static formatar_celular(value) {
|
|
268
|
-
const celular = value.replace(/\D/g, "");
|
|
269
|
-
if (celular.length > 11) return celular.slice(0, 11);
|
|
270
|
-
return celular.replace(/^(\d{0,2})(\d{0,5})(\d{0,4})$/, (match, p1, p2, p3)=>{
|
|
271
|
-
let result = "";
|
|
272
|
-
if (p1) result += `(${p1}`;
|
|
273
|
-
if (p2) result += `) ${p2}`;
|
|
274
|
-
if (p3) result += `-${p3}`;
|
|
275
|
-
return result;
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
static formatar_nome(name) {
|
|
279
|
-
const lowercaseWords = [
|
|
280
|
-
"de",
|
|
281
|
-
"da",
|
|
282
|
-
"do",
|
|
283
|
-
"das",
|
|
284
|
-
"dos",
|
|
285
|
-
"e",
|
|
286
|
-
"a",
|
|
287
|
-
"o"
|
|
288
|
-
];
|
|
289
|
-
const words = name.toLowerCase().split(" ");
|
|
290
|
-
const formattedWords = words.map((word, index)=>{
|
|
291
|
-
if (0 === index) return word.charAt(0).toUpperCase() + word.slice(1);
|
|
292
|
-
if (lowercaseWords.includes(word)) return word;
|
|
293
|
-
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
294
|
-
});
|
|
295
|
-
return formattedWords.join(" ");
|
|
296
|
-
}
|
|
297
|
-
static formatar_reais_br(value) {
|
|
298
|
-
let num = value.replace(/\D/g, "");
|
|
299
|
-
return new Intl.NumberFormat("pt-BR", {
|
|
300
|
-
style: "currency",
|
|
301
|
-
currency: "BRL",
|
|
302
|
-
minimumFractionDigits: 2
|
|
303
|
-
}).format(Number(num) / 100);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
const utils_form = _form_form;
|
|
307
|
-
const geral = class {
|
|
308
|
-
static slice_file_name(filename, maxLength = 30) {
|
|
309
|
-
if (!filename || "string" != typeof filename) return "";
|
|
310
|
-
const lastDotIndex = filename.lastIndexOf(".");
|
|
311
|
-
if (-1 === lastDotIndex) return filename.length > maxLength ? filename.substring(0, maxLength - 3) + "..." : filename;
|
|
312
|
-
const name = filename.substring(0, lastDotIndex);
|
|
313
|
-
const extension = filename.substring(lastDotIndex);
|
|
314
|
-
if (filename.length <= maxLength) return filename;
|
|
315
|
-
const availableLength = maxLength - extension.length - 3;
|
|
316
|
-
if (availableLength <= 0) return name.substring(0, 1) + "..." + extension;
|
|
317
|
-
return name.substring(0, availableLength) + "..." + extension;
|
|
318
|
-
}
|
|
319
|
-
static extrair_id(array_enviado) {
|
|
320
|
-
const ids = [];
|
|
321
|
-
for(let i = 0; i < array_enviado.length; i++)if (array_enviado[i]?._id) ids.push(array_enviado[i]._id);
|
|
322
|
-
return ids;
|
|
323
|
-
}
|
|
324
|
-
static gerar_id = (length = 32)=>{
|
|
325
|
-
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
326
|
-
const timestamp = Date.now().toString(16) + performance.now().toString(16).replace(".", "");
|
|
327
|
-
let result = timestamp;
|
|
328
|
-
while(result.length < length){
|
|
329
|
-
const randomIndex = Math.floor(Math.random() * chars.length);
|
|
330
|
-
result += chars[randomIndex];
|
|
331
|
-
}
|
|
332
|
-
const navigatorData = (window.navigator.userAgent + screen.width + screen.height).split("").map((c)=>c.charCodeAt(0)).reduce((a, b)=>a + b, 0).toString(36);
|
|
333
|
-
const finalResult = (result + navigatorData).replace(/[^a-zA-Z0-9]/g, "");
|
|
334
|
-
return finalResult.substring(0, length);
|
|
335
|
-
};
|
|
336
|
-
};
|
|
337
|
-
const utils_geral = geral;
|
|
338
|
-
const _local_storage_local_storage = class {
|
|
339
|
-
static adicionar_item_local_storage(chave, novoItem) {
|
|
340
|
-
try {
|
|
341
|
-
const valorAtual = window.localStorage.getItem(chave);
|
|
342
|
-
const listaAtual = valorAtual ? JSON.parse(valorAtual) : [];
|
|
343
|
-
const newDataItem = {
|
|
344
|
-
...listaAtual,
|
|
345
|
-
...novoItem
|
|
346
|
-
};
|
|
347
|
-
window.localStorage.setItem(chave, JSON.stringify(newDataItem));
|
|
348
|
-
} catch (error) {
|
|
349
|
-
console.log(error);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
static set_local_storage_sem_incremento(chave, novoItem) {
|
|
353
|
-
try {
|
|
354
|
-
window.localStorage.setItem(chave, JSON.stringify(novoItem));
|
|
355
|
-
} catch (error) {
|
|
356
|
-
console.log(error);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
static get_item_local_storage(chave) {
|
|
360
|
-
try {
|
|
361
|
-
if ("undefined" != typeof window) {
|
|
362
|
-
const valorAtual = window.localStorage.getItem(chave);
|
|
363
|
-
return valorAtual ? JSON.parse(valorAtual) : valorAtual;
|
|
364
|
-
}
|
|
365
|
-
return;
|
|
366
|
-
} catch (error) {
|
|
367
|
-
console.log(error);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
static remover_item_local_storage(chave) {
|
|
371
|
-
try {
|
|
372
|
-
window.localStorage.removeItem(chave);
|
|
373
|
-
} catch (error) {
|
|
374
|
-
console.log(error);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
const utils_local_storage = _local_storage_local_storage;
|
|
379
|
-
const _update_context_update_context = class {
|
|
380
|
-
static set_new_item_end = ({ oldArray = [], newItem = [], key = "_id" })=>{
|
|
381
|
-
try {
|
|
382
|
-
const hasValidIds = Array.isArray(newItem) ? newItem.every((item)=>item?.[key]) : newItem?.[key];
|
|
383
|
-
const newItemArray = hasValidIds ? Array.isArray(newItem) ? newItem : [
|
|
384
|
-
newItem
|
|
385
|
-
] : oldArray;
|
|
386
|
-
if (oldArray?.length === 0) return newItemArray;
|
|
387
|
-
const updatedArray = [
|
|
388
|
-
...oldArray
|
|
389
|
-
];
|
|
390
|
-
newItemArray.forEach((novoItem)=>{
|
|
391
|
-
const index = updatedArray.findIndex((oldItem)=>oldItem?.[key] === novoItem?.[key]);
|
|
392
|
-
if (-1 !== index) {
|
|
393
|
-
novoItem.new = false;
|
|
394
|
-
updatedArray[index] = {
|
|
395
|
-
...updatedArray[index],
|
|
396
|
-
...novoItem
|
|
397
|
-
};
|
|
398
|
-
} else {
|
|
399
|
-
novoItem.new = true;
|
|
400
|
-
updatedArray.push(novoItem);
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
return updatedArray;
|
|
404
|
-
} catch (error) {
|
|
405
|
-
console.error("Erro ao atualizar array:", error);
|
|
406
|
-
return oldArray;
|
|
407
|
-
}
|
|
408
|
-
};
|
|
409
|
-
static update_array_itens = ({ oldArray = [], newItem = [], key = "_id" })=>{
|
|
410
|
-
try {
|
|
411
|
-
const hasValidIds = Array.isArray(newItem) ? newItem.every((item)=>item?.[key]) : newItem?.[key];
|
|
412
|
-
const newItemArray = hasValidIds ? Array.isArray(newItem) ? newItem : [
|
|
413
|
-
newItem
|
|
414
|
-
] : oldArray;
|
|
415
|
-
if (oldArray?.length === 0) return newItemArray;
|
|
416
|
-
const updatedArray = [
|
|
417
|
-
...oldArray
|
|
418
|
-
];
|
|
419
|
-
newItemArray.forEach((novoItem)=>{
|
|
420
|
-
const index = updatedArray.findIndex((oldItem)=>oldItem?.[key] === novoItem?.[key]);
|
|
421
|
-
if (-1 !== index) {
|
|
422
|
-
novoItem.new = false;
|
|
423
|
-
updatedArray[index] = {
|
|
424
|
-
...updatedArray[index],
|
|
425
|
-
...novoItem
|
|
426
|
-
};
|
|
427
|
-
} else {
|
|
428
|
-
novoItem.new = true;
|
|
429
|
-
updatedArray.unshift(novoItem);
|
|
430
|
-
}
|
|
431
|
-
});
|
|
432
|
-
return updatedArray;
|
|
433
|
-
} catch (error) {
|
|
434
|
-
console.error("Erro ao atualizar array:", error);
|
|
435
|
-
return oldArray;
|
|
436
|
-
}
|
|
437
|
-
};
|
|
438
|
-
static remove_array_items = ({ oldArray = [], itemsToRemove = [], key = "_id" })=>{
|
|
439
|
-
try {
|
|
440
|
-
if (!Array.isArray(oldArray) || 0 === oldArray.length) return oldArray;
|
|
441
|
-
if (!itemsToRemove) return oldArray;
|
|
442
|
-
const itemsArray = Array.isArray(itemsToRemove) ? itemsToRemove : [
|
|
443
|
-
itemsToRemove
|
|
444
|
-
];
|
|
445
|
-
if (0 === itemsArray.length) return oldArray;
|
|
446
|
-
const removeIds = new Set(itemsArray.filter((item)=>item?.[key]).map((item)=>item[key]));
|
|
447
|
-
const updatedArray = oldArray.filter((item)=>!removeIds.has(item?.[key]));
|
|
448
|
-
return updatedArray;
|
|
449
|
-
} catch (error) {
|
|
450
|
-
console.error("Erro ao remover itens do array:", error);
|
|
451
|
-
return oldArray;
|
|
452
|
-
}
|
|
453
|
-
};
|
|
454
|
-
static compare_arrays({ arrayAntigo, arrayNovo }) {
|
|
455
|
-
const idsAntigos = new Set(arrayAntigo.map((item)=>item._id));
|
|
456
|
-
const idsNovos = new Set(arrayNovo.map((item)=>item._id));
|
|
457
|
-
const itensMantidos = arrayAntigo.filter((item)=>idsNovos.has(item._id));
|
|
458
|
-
const itensNovos = arrayNovo.filter((item)=>!idsAntigos.has(item._id));
|
|
459
|
-
return [
|
|
460
|
-
...itensMantidos,
|
|
461
|
-
...itensNovos
|
|
462
|
-
];
|
|
463
|
-
}
|
|
464
|
-
};
|
|
465
|
-
const utils_update_context = _update_context_update_context;
|
|
466
|
-
const _session_storage_session_storage = class {
|
|
467
|
-
static adicionar_item_session_storage({ chave, novoItem }) {
|
|
468
|
-
try {
|
|
469
|
-
const valorAtual = window.sessionStorage.getItem(chave);
|
|
470
|
-
const listaAtual = valorAtual ? JSON.parse(valorAtual) : [];
|
|
471
|
-
const newDataItem = {
|
|
472
|
-
...listaAtual,
|
|
473
|
-
...novoItem
|
|
474
|
-
};
|
|
475
|
-
window.sessionStorage.setItem(chave, JSON.stringify(newDataItem));
|
|
476
|
-
} catch (error) {
|
|
477
|
-
console.error(error);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
static set_session_storage_sem_incremento({ chave, novoItem }) {
|
|
481
|
-
try {
|
|
482
|
-
window.sessionStorage.setItem(chave, JSON.stringify(novoItem));
|
|
483
|
-
} catch (error) {
|
|
484
|
-
console.error(error);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
static get_item_session_storage(chave) {
|
|
488
|
-
try {
|
|
489
|
-
if ("undefined" != typeof window) {
|
|
490
|
-
const valorAtual = window.sessionStorage.getItem(chave);
|
|
491
|
-
return valorAtual ? JSON.parse(valorAtual) : valorAtual;
|
|
492
|
-
}
|
|
493
|
-
return;
|
|
494
|
-
} catch (error) {
|
|
495
|
-
console.error(error);
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
static remover_item_session_storage(chave) {
|
|
499
|
-
try {
|
|
500
|
-
window.sessionStorage.removeItem(chave);
|
|
501
|
-
} catch (error) {
|
|
502
|
-
console.error(error);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
};
|
|
506
|
-
const utils_session_storage = _session_storage_session_storage;
|
|
507
|
-
const _sistema_sistema = {
|
|
508
|
-
empresa: {
|
|
509
|
-
nome: "Nav Software",
|
|
510
|
-
email_suporte: "suporte@navsoftware.com.br",
|
|
511
|
-
email_no_replay: "no-replay@navsoftware.com.br",
|
|
512
|
-
razaoSocial: "Nav Software Desenvolvimento de Sistemas Ltda",
|
|
513
|
-
cnpj: "00.000.000/0001-00",
|
|
514
|
-
inscricaoEstadual: "000.000.000.000",
|
|
515
|
-
inscricaoMunicipal: "000000",
|
|
516
|
-
endereco: {
|
|
517
|
-
logradouro: "Rua Exemplo",
|
|
518
|
-
numero: "000",
|
|
519
|
-
complemento: "Sala 00",
|
|
520
|
-
bairro: "Centro",
|
|
521
|
-
cidade: "Navegantes",
|
|
522
|
-
estado: "SC",
|
|
523
|
-
cep: "88370-000",
|
|
524
|
-
pais: "Brasil"
|
|
525
|
-
},
|
|
526
|
-
contato: {
|
|
527
|
-
telefone: "(47) 0000-0000",
|
|
528
|
-
celular: "(47) 90000-0000",
|
|
529
|
-
email: "contato@navsoftware.com.br",
|
|
530
|
-
site: "https://www.navsoftware.com.br"
|
|
531
|
-
},
|
|
532
|
-
dadosBancarios: {
|
|
533
|
-
banco: "000 - Banco Exemplo",
|
|
534
|
-
agencia: "0000",
|
|
535
|
-
conta: "00000-0",
|
|
536
|
-
tipoConta: "Conta Corrente",
|
|
537
|
-
pix: "contato@navsoftware.com.br"
|
|
538
|
-
},
|
|
539
|
-
responsavel: {
|
|
540
|
-
nome: "Nome do Responsável",
|
|
541
|
-
cpf: "000.000.000-00",
|
|
542
|
-
cargo: "Diretor",
|
|
543
|
-
email: "responsavel@navsoftware.com.br"
|
|
544
|
-
},
|
|
545
|
-
configuracoes: {
|
|
546
|
-
ativo: true,
|
|
547
|
-
dataFundacao: "2020-01-01",
|
|
548
|
-
regimeTributario: "Simples Nacional",
|
|
549
|
-
ramoAtividade: "Desenvolvimento de Software",
|
|
550
|
-
cnae: "62.01-5-00",
|
|
551
|
-
porteEmpresa: "ME"
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
};
|
|
555
|
-
const utils_sistema = _sistema_sistema;
|
|
556
|
-
class _hooks_hooks {
|
|
557
|
-
use_is_mobile() {
|
|
558
|
-
const [isMobile, setIsMobile] = useState(false);
|
|
559
|
-
useLayoutEffect(()=>{
|
|
560
|
-
const updateSize = ()=>setIsMobile(window.innerWidth < 768);
|
|
561
|
-
window.addEventListener("resize", updateSize);
|
|
562
|
-
updateSize();
|
|
563
|
-
return ()=>window.removeEventListener("resize", updateSize);
|
|
564
|
-
}, []);
|
|
565
|
-
return isMobile;
|
|
566
|
-
}
|
|
567
|
-
use_dark_mode() {
|
|
568
|
-
if ("dark" === localStorage.getItem("theme")) {
|
|
569
|
-
document.documentElement.classList.add("dark");
|
|
570
|
-
localStorage.setItem("theme", "dark");
|
|
571
|
-
} else {
|
|
572
|
-
document.documentElement.classList.remove("dark");
|
|
573
|
-
localStorage.setItem("theme", "light");
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
const utils_hooks = new _hooks_hooks;
|
|
578
|
-
const _api_api = class _api {
|
|
579
|
-
static servidor_pricipal = class {
|
|
580
|
-
static get #axios() {
|
|
581
|
-
return axios.create({
|
|
582
|
-
baseURL: src_config_env.PUBLIC_BASE_URL_BACKEND_PRINCIPAL
|
|
583
|
-
});
|
|
584
|
-
}
|
|
585
|
-
static async post({ url, data, setToken = true }) {
|
|
586
|
-
return await this.#axios.post(url, data, _api.headers({
|
|
587
|
-
setToken: setToken
|
|
588
|
-
}));
|
|
589
|
-
}
|
|
590
|
-
static async get({ url, params, setToken = true }) {
|
|
591
|
-
const queryParams = new URLSearchParams();
|
|
592
|
-
if (params) Object.entries(params).forEach(([key, value])=>{
|
|
593
|
-
if (null != value) queryParams.append(key, value);
|
|
594
|
-
});
|
|
595
|
-
const queryString = queryParams.toString();
|
|
596
|
-
const fullUrl = queryString ? `${url}?${queryString}` : url;
|
|
597
|
-
return await this.#axios.get(fullUrl, _api.headers({
|
|
598
|
-
setToken: setToken
|
|
599
|
-
}));
|
|
600
|
-
}
|
|
601
|
-
static async patch({ url, data, setToken = true }) {
|
|
602
|
-
return await this.#axios.patch(url, data, _api.headers({
|
|
603
|
-
setToken: setToken
|
|
604
|
-
}));
|
|
605
|
-
}
|
|
606
|
-
static async delete({ url }) {
|
|
607
|
-
return await this.#axios.delete(url);
|
|
608
|
-
}
|
|
609
|
-
};
|
|
610
|
-
static headers({ setToken = true }) {
|
|
611
|
-
const get_auth_user = utils_session_storage.get_item_session_storage("auth_user");
|
|
612
|
-
if (true === setToken) return {
|
|
613
|
-
headers: {
|
|
614
|
-
Authorization: `Bearer ${get_auth_user?.data?.usuario?.token}`,
|
|
615
|
-
"Content-type": "application/json"
|
|
616
|
-
}
|
|
617
|
-
};
|
|
618
|
-
return {
|
|
619
|
-
headers: {
|
|
620
|
-
"Content-type": "application/json"
|
|
621
|
-
}
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
};
|
|
625
|
-
const utils_api = _api_api;
|
|
626
|
-
const utils_utils = {
|
|
627
|
-
api: utils_api,
|
|
628
|
-
data: utils_data,
|
|
629
|
-
form: utils_form,
|
|
630
|
-
geral: utils_geral,
|
|
631
|
-
local_storage: utils_local_storage,
|
|
632
|
-
update_context: utils_update_context,
|
|
633
|
-
session_sorage: utils_session_storage,
|
|
634
|
-
sistema: utils_sistema,
|
|
635
|
-
hooks: utils_hooks
|
|
636
|
-
};
|
|
637
|
-
const src_utils_0 = utils_utils;
|
|
638
|
-
export { src_utils_0 as default };
|