@navservice/core 1.25.0 → 1.30.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/README.md +54 -54
- package/build/lib/config_env/index.d.ts +9 -0
- package/build/lib/helpers/_secret.d.ts +10 -0
- package/build/lib/helpers/_set_response.d.ts +84 -0
- package/build/lib/helpers/_token.d.ts +16 -0
- package/build/lib/helpers/index.d.ts +157 -0
- package/build/lib/helpers.cjs +437 -0
- package/build/lib/index.browser.cjs +805 -0
- package/build/lib/index.browser.d.ts +3 -0
- package/build/lib/index.node.cjs +472 -0
- package/build/lib/index.node.d.ts +1 -0
- package/build/lib/types/_type_response.d.ts +54 -0
- package/build/lib/types/_usuario.d.ts +39 -0
- package/build/lib/types/index.d.ts +20 -0
- package/build/lib/utils/_api.d.ts +41 -0
- package/build/lib/utils/_data.d.ts +11 -0
- package/build/lib/utils/_form.d.ts +11 -0
- package/build/lib/utils/_geral.d.ts +9 -0
- package/build/lib/utils/_local_storage.d.ts +8 -0
- package/build/lib/utils/_session_storage.d.ts +14 -0
- package/build/lib/utils/_update_context.d.ts +21 -0
- package/build/lib/utils/index.d.ts +105 -0
- package/build/lib/utils.cjs +660 -0
- package/package.json +50 -49
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
3
|
+
return typeof document === 'undefined'
|
|
4
|
+
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
5
|
+
: (document.currentScript && document.currentScript.src) ||
|
|
6
|
+
new URL('main.js', document.baseURI).href;
|
|
7
|
+
})();
|
|
8
|
+
;
|
|
9
|
+
// The require scope
|
|
10
|
+
var __webpack_require__ = {};
|
|
11
|
+
|
|
12
|
+
// webpack/runtime/compat_get_default_export
|
|
13
|
+
(() => {
|
|
14
|
+
// getDefaultExport function for compatibility with non-ESM modules
|
|
15
|
+
__webpack_require__.n = (module) => {
|
|
16
|
+
var getter = module && module.__esModule ?
|
|
17
|
+
() => (module['default']) :
|
|
18
|
+
() => (module);
|
|
19
|
+
__webpack_require__.d(getter, { a: getter });
|
|
20
|
+
return getter;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
})();
|
|
24
|
+
// webpack/runtime/define_property_getters
|
|
25
|
+
(() => {
|
|
26
|
+
__webpack_require__.d = (exports, definition) => {
|
|
27
|
+
for(var key in definition) {
|
|
28
|
+
if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
29
|
+
Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
})();
|
|
34
|
+
// webpack/runtime/has_own_property
|
|
35
|
+
(() => {
|
|
36
|
+
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
37
|
+
})();
|
|
38
|
+
// webpack/runtime/make_namespace_object
|
|
39
|
+
(() => {
|
|
40
|
+
// define __esModule on exports
|
|
41
|
+
__webpack_require__.r = (exports) => {
|
|
42
|
+
if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
43
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
44
|
+
}
|
|
45
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
46
|
+
};
|
|
47
|
+
})();
|
|
48
|
+
var __webpack_exports__ = {};
|
|
49
|
+
// ESM COMPAT FLAG
|
|
50
|
+
__webpack_require__.r(__webpack_exports__);
|
|
51
|
+
|
|
52
|
+
// EXPORTS
|
|
53
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
54
|
+
"default": () => (/* binding */ src_helpers)
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
;// CONCATENATED MODULE: external "zod/v4"
|
|
58
|
+
const v4_namespaceObject = require("zod/v4");
|
|
59
|
+
var v4_default = /*#__PURE__*/__webpack_require__.n(v4_namespaceObject);
|
|
60
|
+
;// CONCATENATED MODULE: ./src/helpers/_set_response.ts
|
|
61
|
+
// TYPES
|
|
62
|
+
|
|
63
|
+
const set_response = class set_response {
|
|
64
|
+
static c = class c {
|
|
65
|
+
static SUCCESS({ message, results, c }) {
|
|
66
|
+
const payload = {
|
|
67
|
+
status: 200,
|
|
68
|
+
code: "SUCCESS",
|
|
69
|
+
type: "success",
|
|
70
|
+
message: message || "Realizado com sucesso!",
|
|
71
|
+
results: results || []
|
|
72
|
+
};
|
|
73
|
+
if (c) {
|
|
74
|
+
return c.json(payload, {
|
|
75
|
+
status: 200
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return payload;
|
|
79
|
+
}
|
|
80
|
+
static ACTION_REQUIRED({ message, results, c }) {
|
|
81
|
+
const payload = {
|
|
82
|
+
status: 428,
|
|
83
|
+
code: "ACTION_REQUIRED",
|
|
84
|
+
type: "warning",
|
|
85
|
+
message: message || "Ação adicional necessária!",
|
|
86
|
+
results: results || []
|
|
87
|
+
};
|
|
88
|
+
if (c) {
|
|
89
|
+
return c.json(payload, {
|
|
90
|
+
status: 428
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return payload;
|
|
94
|
+
}
|
|
95
|
+
static CREATED({ message, results, c }) {
|
|
96
|
+
const payload = {
|
|
97
|
+
status: 201,
|
|
98
|
+
code: "CREATED",
|
|
99
|
+
type: "success",
|
|
100
|
+
message: message || "Criado com sucesso!",
|
|
101
|
+
results: results || []
|
|
102
|
+
};
|
|
103
|
+
return c ? c.json(payload, {
|
|
104
|
+
status: 201
|
|
105
|
+
}) : payload;
|
|
106
|
+
}
|
|
107
|
+
static WARNING({ message, results, c }) {
|
|
108
|
+
const payload = {
|
|
109
|
+
status: 400,
|
|
110
|
+
code: "WARNING",
|
|
111
|
+
type: "warning",
|
|
112
|
+
message: message || "Aviso!",
|
|
113
|
+
results: results || []
|
|
114
|
+
};
|
|
115
|
+
if (c) c.json(payload, {
|
|
116
|
+
status: 400
|
|
117
|
+
});
|
|
118
|
+
throw payload;
|
|
119
|
+
}
|
|
120
|
+
static AUTHORIZATION_ERROR({ message, results, c }) {
|
|
121
|
+
const payload = {
|
|
122
|
+
status: 405,
|
|
123
|
+
code: "WARNING",
|
|
124
|
+
type: "warning",
|
|
125
|
+
message: message || "Aviso!",
|
|
126
|
+
results: results || []
|
|
127
|
+
};
|
|
128
|
+
if (c) c.json(payload, {
|
|
129
|
+
status: 405
|
|
130
|
+
});
|
|
131
|
+
throw payload;
|
|
132
|
+
}
|
|
133
|
+
static DATABASE_ERROR({ message, results, c }) {
|
|
134
|
+
const payload = {
|
|
135
|
+
status: 500,
|
|
136
|
+
code: "DATABASE_ERROR",
|
|
137
|
+
type: "error",
|
|
138
|
+
message: message || "Erro no banco de dados!",
|
|
139
|
+
results: results || []
|
|
140
|
+
};
|
|
141
|
+
return c ? c.json(payload, {
|
|
142
|
+
status: 500
|
|
143
|
+
}) : payload;
|
|
144
|
+
}
|
|
145
|
+
static SERVER_ERROR({ error, c }) {
|
|
146
|
+
if (error instanceof (v4_default()).ZodError) {
|
|
147
|
+
const payload = {
|
|
148
|
+
status: 500,
|
|
149
|
+
code: "SCHEMA_VALIDATION",
|
|
150
|
+
type: "warning",
|
|
151
|
+
message: "Erro ao validar dados!",
|
|
152
|
+
results: v4_default().treeifyError(error)
|
|
153
|
+
};
|
|
154
|
+
return c.json(payload, {
|
|
155
|
+
status: 500
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
const payload = {
|
|
159
|
+
status: error?.status || 500,
|
|
160
|
+
code: error?.code || "SERVER_ERROR",
|
|
161
|
+
type: error?.type || "error",
|
|
162
|
+
message: error?.message || "Erro interno no servidor!",
|
|
163
|
+
results: error?.results || []
|
|
164
|
+
};
|
|
165
|
+
return c.json(payload, {
|
|
166
|
+
status: error?.status || error?.status || 500
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
static UNAUTHORIZED({ message, c }) {
|
|
170
|
+
const payload = {
|
|
171
|
+
status: 401,
|
|
172
|
+
code: "UNAUTHORIZED",
|
|
173
|
+
type: "error",
|
|
174
|
+
message: message || "Não autorizado!",
|
|
175
|
+
results: []
|
|
176
|
+
};
|
|
177
|
+
return c ? c.json(payload, {
|
|
178
|
+
status: 401
|
|
179
|
+
}) : payload;
|
|
180
|
+
}
|
|
181
|
+
static INVALID_TOKEN({ message, c }) {
|
|
182
|
+
const payload = {
|
|
183
|
+
status: 401,
|
|
184
|
+
code: "INVALID_TOKEN",
|
|
185
|
+
type: "warning",
|
|
186
|
+
message: message || "Token inválido!",
|
|
187
|
+
results: []
|
|
188
|
+
};
|
|
189
|
+
return c ? c.json(payload, {
|
|
190
|
+
status: 401
|
|
191
|
+
}) : payload;
|
|
192
|
+
}
|
|
193
|
+
static NOT_FOUND({ message, c }) {
|
|
194
|
+
const payload = {
|
|
195
|
+
status: 404,
|
|
196
|
+
code: "NOT_FOUND",
|
|
197
|
+
type: "error",
|
|
198
|
+
message: message || "Recurso não encontrado!",
|
|
199
|
+
results: []
|
|
200
|
+
};
|
|
201
|
+
return c ? c.json(payload, {
|
|
202
|
+
status: 404
|
|
203
|
+
}) : payload;
|
|
204
|
+
}
|
|
205
|
+
static async SUCCESS_FILE({ message, file_buffer, content_type, filename, c }) {
|
|
206
|
+
if (c && content_type) {
|
|
207
|
+
const headers = {
|
|
208
|
+
"Content-Type": content_type,
|
|
209
|
+
"Content-Disposition": filename ? `inline; filename="${filename}"` : "inline"
|
|
210
|
+
};
|
|
211
|
+
return new Response(file_buffer, {
|
|
212
|
+
status: 200,
|
|
213
|
+
headers
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
const payload = {
|
|
217
|
+
status: 200,
|
|
218
|
+
code: "SUCCESS_FILE",
|
|
219
|
+
type: "success",
|
|
220
|
+
message: message || "Erro ao retornar arquivo!",
|
|
221
|
+
results: []
|
|
222
|
+
};
|
|
223
|
+
return c ? c.json(payload, {
|
|
224
|
+
status: 200
|
|
225
|
+
}) : payload;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
static error = class error {
|
|
229
|
+
static ACTION_REQUIRED({ message, results }) {
|
|
230
|
+
const payload = {
|
|
231
|
+
status: 428,
|
|
232
|
+
code: "ACTION_REQUIRED",
|
|
233
|
+
type: "warning",
|
|
234
|
+
message: message || "Ação adicional necessária!",
|
|
235
|
+
results: results || []
|
|
236
|
+
};
|
|
237
|
+
throw payload;
|
|
238
|
+
}
|
|
239
|
+
static WARNING({ message, results }) {
|
|
240
|
+
const payload = {
|
|
241
|
+
status: 400,
|
|
242
|
+
code: "WARNING",
|
|
243
|
+
type: "warning",
|
|
244
|
+
message: message || "Aviso!",
|
|
245
|
+
results: results || []
|
|
246
|
+
};
|
|
247
|
+
throw payload;
|
|
248
|
+
}
|
|
249
|
+
static AUTHORIZATION_ERROR({ message, results }) {
|
|
250
|
+
const payload = {
|
|
251
|
+
status: 400,
|
|
252
|
+
code: "WARNING",
|
|
253
|
+
type: "warning",
|
|
254
|
+
message: message || "Aviso!",
|
|
255
|
+
results: results || []
|
|
256
|
+
};
|
|
257
|
+
throw payload;
|
|
258
|
+
}
|
|
259
|
+
static DATABASE_ERROR({ message, results }) {
|
|
260
|
+
const payload = {
|
|
261
|
+
status: 405,
|
|
262
|
+
code: "DATABASE_ERROR",
|
|
263
|
+
type: "error",
|
|
264
|
+
message: message || "Erro no banco de dados!",
|
|
265
|
+
results: results || []
|
|
266
|
+
};
|
|
267
|
+
throw payload;
|
|
268
|
+
}
|
|
269
|
+
static SCHEMA_VALIDATION({ results }) {
|
|
270
|
+
const payload = {
|
|
271
|
+
status: 500,
|
|
272
|
+
code: "SCHEMA_VALIDATION",
|
|
273
|
+
type: "error",
|
|
274
|
+
message: "Erro ao validar dados!",
|
|
275
|
+
results: results || []
|
|
276
|
+
};
|
|
277
|
+
throw payload;
|
|
278
|
+
}
|
|
279
|
+
static UNAUTHORIZED({ message }) {
|
|
280
|
+
const payload = {
|
|
281
|
+
status: 401,
|
|
282
|
+
code: "UNAUTHORIZED",
|
|
283
|
+
type: "error",
|
|
284
|
+
message: message || "Não autorizado!"
|
|
285
|
+
};
|
|
286
|
+
throw payload;
|
|
287
|
+
}
|
|
288
|
+
static INVALID_TOKEN({ message }) {
|
|
289
|
+
const payload = {
|
|
290
|
+
status: 401,
|
|
291
|
+
code: "INVALID_TOKEN",
|
|
292
|
+
type: "warning",
|
|
293
|
+
message: message || "Token inválido!",
|
|
294
|
+
results: []
|
|
295
|
+
};
|
|
296
|
+
throw payload;
|
|
297
|
+
}
|
|
298
|
+
static NOT_FOUND({ message }) {
|
|
299
|
+
const payload = {
|
|
300
|
+
status: 404,
|
|
301
|
+
code: "NOT_FOUND",
|
|
302
|
+
type: "error",
|
|
303
|
+
message: message || "Recurso não encontrado!"
|
|
304
|
+
};
|
|
305
|
+
throw payload;
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
};
|
|
309
|
+
/* export default */ const _set_response = (set_response);
|
|
310
|
+
|
|
311
|
+
;// CONCATENATED MODULE: external "jose"
|
|
312
|
+
const external_jose_namespaceObject = require("jose");
|
|
313
|
+
;// CONCATENATED MODULE: ./src/helpers/_token.ts
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
const _token = class _token {
|
|
317
|
+
static async verificar_token(c, next) {
|
|
318
|
+
try {
|
|
319
|
+
const authHeader = c.req.header("Authorization");
|
|
320
|
+
if (!authHeader) return src_helpers.set_response.c.INVALID_TOKEN({
|
|
321
|
+
message: 'token não enviado!!!',
|
|
322
|
+
c: c,
|
|
323
|
+
results: []
|
|
324
|
+
});
|
|
325
|
+
const token = authHeader.split(" ")[1];
|
|
326
|
+
if (!token) return src_helpers.set_response.c.INVALID_TOKEN({
|
|
327
|
+
message: 'Acesso negado!!!',
|
|
328
|
+
c: c,
|
|
329
|
+
results: []
|
|
330
|
+
});
|
|
331
|
+
const secret = new TextEncoder().encode(c.env.JSON_WEB_TOKEN_AUTH_USER);
|
|
332
|
+
const { payload } = await external_jose_namespaceObject.jwtVerify(token, secret);
|
|
333
|
+
if (!payload._id || !payload.email) {
|
|
334
|
+
return src_helpers.set_response.c.INVALID_TOKEN({
|
|
335
|
+
message: 'Token inválido!!!!',
|
|
336
|
+
c: c,
|
|
337
|
+
results: []
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
const setar_token = {
|
|
341
|
+
_id: payload._id,
|
|
342
|
+
email: payload.email,
|
|
343
|
+
ativo: payload.ativo,
|
|
344
|
+
data_criacao: payload.data_criacao,
|
|
345
|
+
nome: payload.nome,
|
|
346
|
+
app: payload.app,
|
|
347
|
+
usuario_tipo: payload.usuario_tipo
|
|
348
|
+
};
|
|
349
|
+
c.set("usuario_auth", setar_token);
|
|
350
|
+
return await next();
|
|
351
|
+
} catch (error) {
|
|
352
|
+
return src_helpers.set_response.c.INVALID_TOKEN({
|
|
353
|
+
message: 'Token inválido!!!',
|
|
354
|
+
c: c,
|
|
355
|
+
results: []
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
static async criar_token_login_usuario({ _id, email, app, usuario_tipo, ativo, data_criacao, nome, c }) {
|
|
360
|
+
if (!c.env.JSON_WEB_TOKEN_AUTH_USER) {
|
|
361
|
+
return src_helpers.set_response.error.WARNING({
|
|
362
|
+
message: "Erro ao gerar token!!",
|
|
363
|
+
results: []
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
const token = await new external_jose_namespaceObject.SignJWT({
|
|
367
|
+
_id: _id,
|
|
368
|
+
email: email,
|
|
369
|
+
app: app,
|
|
370
|
+
usuario_tipo: usuario_tipo,
|
|
371
|
+
ativo: ativo,
|
|
372
|
+
data_criacao: data_criacao,
|
|
373
|
+
nome: nome
|
|
374
|
+
}).setProtectedHeader({
|
|
375
|
+
alg: "HS256"
|
|
376
|
+
}).setIssuedAt()//.setExpirationTime("24h")
|
|
377
|
+
.sign(new TextEncoder().encode(c.env.JSON_WEB_TOKEN_AUTH_USER)).catch((error)=>{
|
|
378
|
+
return src_helpers.set_response.error.WARNING({
|
|
379
|
+
message: "Erro ao gerar token!",
|
|
380
|
+
results: error?.message
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
return token;
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
/* export default */ const helpers_token = (_token);
|
|
387
|
+
|
|
388
|
+
;// CONCATENATED MODULE: external "node:crypto"
|
|
389
|
+
const external_node_crypto_namespaceObject = require("node:crypto");
|
|
390
|
+
;// CONCATENATED MODULE: external "node:util"
|
|
391
|
+
const external_node_util_namespaceObject = require("node:util");
|
|
392
|
+
;// CONCATENATED MODULE: ./src/helpers/_secret.ts
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
const scryptAsync = (0,external_node_util_namespaceObject.promisify)(external_node_crypto_namespaceObject.scrypt);
|
|
396
|
+
class _secret {
|
|
397
|
+
static SALT_LENGTH = 22;
|
|
398
|
+
static KEY_LENGTH = 35;
|
|
399
|
+
static async gerar_hash_senha(password) {
|
|
400
|
+
const salt = (0,external_node_crypto_namespaceObject.randomBytes)(this.SALT_LENGTH);
|
|
401
|
+
const derivedKey = await scryptAsync(password, salt, this.KEY_LENGTH);
|
|
402
|
+
return salt.toString('base64') + '.' + derivedKey.toString('base64');
|
|
403
|
+
}
|
|
404
|
+
static async verify({ password, dashed_senha }) {
|
|
405
|
+
try {
|
|
406
|
+
const [saltBase64, hashBase64] = dashed_senha.split('.');
|
|
407
|
+
if (!saltBase64 || !hashBase64) return false;
|
|
408
|
+
const salt = Buffer.from(saltBase64, 'base64');
|
|
409
|
+
const storedHash = Buffer.from(hashBase64, 'base64');
|
|
410
|
+
const derivedKey = await scryptAsync(password, salt, this.KEY_LENGTH);
|
|
411
|
+
return (0,external_node_crypto_namespaceObject.timingSafeEqual)(storedHash, derivedKey);
|
|
412
|
+
} catch {
|
|
413
|
+
return false;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
/* export default */ const helpers_secret = (_secret);
|
|
418
|
+
|
|
419
|
+
;// CONCATENATED MODULE: ./src/helpers/index.ts
|
|
420
|
+
//_HELPERS
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
class helpers {
|
|
425
|
+
static set_response = _set_response;
|
|
426
|
+
static token = helpers_token;
|
|
427
|
+
static secret = helpers_secret;
|
|
428
|
+
}
|
|
429
|
+
/* export default */ const src_helpers = (helpers);
|
|
430
|
+
|
|
431
|
+
exports["default"] = __webpack_exports__["default"];
|
|
432
|
+
for(var __rspack_i in __webpack_exports__) {
|
|
433
|
+
if(["default"].indexOf(__rspack_i) === -1) {
|
|
434
|
+
exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|