@navservice/core 1.64.0 → 1.66.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.
@@ -1,510 +0,0 @@
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
- var __webpack_modules__ = ({
10
- "./src/helpers/index.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
11
-
12
- // EXPORTS
13
- __webpack_require__.d(__webpack_exports__, {
14
- "default": () => (/* binding */ src_helpers)
15
- });
16
-
17
- ;// CONCATENATED MODULE: external "zod/v4"
18
- const v4_namespaceObject = require("zod/v4");
19
- var v4_default = /*#__PURE__*/__webpack_require__.n(v4_namespaceObject);
20
- ;// CONCATENATED MODULE: ./src/helpers/_set_response.ts
21
- // TYPES
22
-
23
- const set_response = class set_response {
24
- static c = class c {
25
- static SUCCESS({ message, results, c }) {
26
- const payload = {
27
- status: 200,
28
- code: "SUCCESS",
29
- type: "success",
30
- message: message || "Realizado com sucesso!",
31
- results: results || []
32
- };
33
- if (c) {
34
- return c.json(payload, {
35
- status: 200
36
- });
37
- }
38
- return payload;
39
- }
40
- static ACTION_REQUIRED({ message, results, c }) {
41
- const payload = {
42
- status: 428,
43
- code: "ACTION_REQUIRED",
44
- type: "warning",
45
- message: message || "Ação adicional necessária!",
46
- results: results || []
47
- };
48
- if (c) {
49
- return c.json(payload, {
50
- status: 428
51
- });
52
- }
53
- return payload;
54
- }
55
- static CREATED({ message, results, c }) {
56
- const payload = {
57
- status: 201,
58
- code: "CREATED",
59
- type: "success",
60
- message: message || "Criado com sucesso!",
61
- results: results || []
62
- };
63
- return c ? c.json(payload, {
64
- status: 201
65
- }) : payload;
66
- }
67
- static WARNING({ message, results, c }) {
68
- const payload = {
69
- status: 400,
70
- code: "WARNING",
71
- type: "warning",
72
- message: message || "Aviso!",
73
- results: results || []
74
- };
75
- if (c) c.json(payload, {
76
- status: 400
77
- });
78
- throw payload;
79
- }
80
- static AUTHORIZATION_ERROR({ message, results, c }) {
81
- const payload = {
82
- status: 405,
83
- code: "WARNING",
84
- type: "warning",
85
- message: message || "Aviso!",
86
- results: results || []
87
- };
88
- if (c) c.json(payload, {
89
- status: 405
90
- });
91
- throw payload;
92
- }
93
- static SERVER_ERROR({ error, c }) {
94
- if (error instanceof (v4_default()).ZodError) {
95
- const payload = {
96
- status: 500,
97
- code: "SCHEMA_VALIDATION",
98
- type: "warning",
99
- message: "Erro ao validar dados!",
100
- results: v4_default().treeifyError(error)
101
- };
102
- return c.json(payload, {
103
- status: 500
104
- });
105
- }
106
- const payload = {
107
- status: error?.status || 500,
108
- code: error?.code || "SERVER_ERROR",
109
- type: error?.type || "error",
110
- message: error?.message || "Erro interno no servidor!",
111
- results: error?.results || []
112
- };
113
- return c.json(payload, {
114
- status: error?.status || error?.status || 500
115
- });
116
- }
117
- static UNAUTHORIZED({ message, c }) {
118
- const payload = {
119
- status: 401,
120
- code: "UNAUTHORIZED",
121
- type: "error",
122
- message: message || "Não autorizado!",
123
- results: []
124
- };
125
- return c ? c.json(payload, {
126
- status: 401
127
- }) : payload;
128
- }
129
- static INVALID_TOKEN({ message, c }) {
130
- const payload = {
131
- status: 401,
132
- code: "INVALID_TOKEN",
133
- type: "warning",
134
- message: message || "Token inválido!",
135
- results: []
136
- };
137
- return c ? c.json(payload, {
138
- status: 401
139
- }) : payload;
140
- }
141
- static NOT_FOUND({ message, c }) {
142
- const payload = {
143
- status: 404,
144
- code: "NOT_FOUND",
145
- type: "error",
146
- message: message || "Recurso não encontrado!",
147
- results: []
148
- };
149
- return c ? c.json(payload, {
150
- status: 404
151
- }) : payload;
152
- }
153
- static async SUCCESS_FILE({ message, file_buffer, content_type, filename, c }) {
154
- if (c && content_type) {
155
- const headers = {
156
- "Content-Type": content_type,
157
- "Content-Disposition": filename ? `inline; filename="${filename}"` : "inline"
158
- };
159
- return new Response(file_buffer, {
160
- status: 200,
161
- headers
162
- });
163
- }
164
- const payload = {
165
- status: 200,
166
- code: "SUCCESS_FILE",
167
- type: "success",
168
- message: message || "Erro ao retornar arquivo!",
169
- results: []
170
- };
171
- return c ? c.json(payload, {
172
- status: 200
173
- }) : payload;
174
- }
175
- };
176
- static error = class error {
177
- static ACTION_REQUIRED({ message, results }) {
178
- const payload = {
179
- status: 428,
180
- code: "ACTION_REQUIRED",
181
- type: "warning",
182
- message: message || "Ação adicional necessária!",
183
- results: results || []
184
- };
185
- throw payload;
186
- }
187
- static WARNING({ message, results }) {
188
- const payload = {
189
- status: 400,
190
- code: "WARNING",
191
- type: "warning",
192
- message: message || "Aviso!",
193
- results: results || []
194
- };
195
- throw payload;
196
- }
197
- static AUTHORIZATION_ERROR({ message, results }) {
198
- const payload = {
199
- status: 400,
200
- code: "WARNING",
201
- type: "warning",
202
- message: message || "Aviso!",
203
- results: results || []
204
- };
205
- throw payload;
206
- }
207
- static DATABASE_ERROR({ message, results, erro }) {
208
- const errorCode = erro?.cause?.code || erro?.cause?.cause?.code || erro?.code || "";
209
- const map = {
210
- "SQLITE_CONSTRAINT_UNIQUE": {
211
- status: 409,
212
- message: "Registro duplicado. Violação de UNIQUE."
213
- },
214
- "SQLITE_CONSTRAINT_FOREIGNKEY": {
215
- status: 409,
216
- message: "Registro relacionado não encontrado (FOREIGN KEY)."
217
- },
218
- "SQLITE_CONSTRAINT_NOTNULL": {
219
- status: 400,
220
- message: "Campo obrigatório ausente."
221
- },
222
- "SQLITE_CONSTRAINT_CHECK": {
223
- status: 400,
224
- message: "Regra de validação violada."
225
- },
226
- "SQLITE_CONSTRAINT_PRIMARYKEY": {
227
- status: 409,
228
- message: "Chave primária duplicada."
229
- },
230
- "SQLITE_BUSY": {
231
- status: 503,
232
- message: "Banco ocupado. Tente novamente."
233
- },
234
- "SQLITE_READONLY": {
235
- status: 500,
236
- message: "Banco de dados em modo somente leitura."
237
- }
238
- };
239
- const causeMessage = erro?.cause?.message;
240
- const isUniqueMessage = causeMessage?.includes("UNIQUE constraint failed");
241
- const isForeignMessage = causeMessage?.includes("FOREIGN KEY constraint failed");
242
- const mapped = map[errorCode] || (isUniqueMessage ? map["SQLITE_CONSTRAINT_UNIQUE"] : null) || (isForeignMessage ? map["SQLITE_CONSTRAINT_FOREIGNKEY"] : null);
243
- const payload = {
244
- status: mapped?.status || 500,
245
- code: "DATABASE_ERROR",
246
- type: "error",
247
- message: mapped?.message || message || "Erro no banco de dados!",
248
- results: []
249
- };
250
- throw payload;
251
- }
252
- static SCHEMA_VALIDATION({ results }) {
253
- const payload = {
254
- status: 500,
255
- code: "SCHEMA_VALIDATION",
256
- type: "error",
257
- message: "Erro ao validar dados!",
258
- results: results || []
259
- };
260
- throw payload;
261
- }
262
- static UNAUTHORIZED({ message }) {
263
- const payload = {
264
- status: 401,
265
- code: "UNAUTHORIZED",
266
- type: "error",
267
- message: message || "Não autorizado!"
268
- };
269
- throw payload;
270
- }
271
- static INVALID_TOKEN({ message }) {
272
- const payload = {
273
- status: 401,
274
- code: "INVALID_TOKEN",
275
- type: "warning",
276
- message: message || "Token inválido!",
277
- results: []
278
- };
279
- throw payload;
280
- }
281
- static NOT_FOUND({ message }) {
282
- const payload = {
283
- status: 404,
284
- code: "NOT_FOUND",
285
- type: "error",
286
- message: message || "Recurso não encontrado!"
287
- };
288
- throw payload;
289
- }
290
- };
291
- };
292
- /* export default */ const _set_response = (set_response);
293
-
294
- ;// CONCATENATED MODULE: external "jose"
295
- const external_jose_namespaceObject = require("jose");
296
- ;// CONCATENATED MODULE: ./src/helpers/_token.ts
297
-
298
-
299
- const _token = class _token {
300
- static async verificar_token(c, next) {
301
- try {
302
- const authHeader = c.req.header("Authorization");
303
- if (!authHeader) return src_helpers.set_response.c.INVALID_TOKEN({
304
- message: 'token não enviado!!!',
305
- c: c,
306
- results: []
307
- });
308
- const token = authHeader.split(" ")[1];
309
- if (!token) return src_helpers.set_response.c.INVALID_TOKEN({
310
- message: 'Acesso negado!!!',
311
- c: c,
312
- results: []
313
- });
314
- const secret = new TextEncoder().encode(c.env.JSON_WEB_TOKEN_AUTH_USER);
315
- const { payload } = await external_jose_namespaceObject.jwtVerify(token, secret);
316
- if (!payload._id || !payload.email) {
317
- return src_helpers.set_response.c.INVALID_TOKEN({
318
- message: 'Token inválido!!!!',
319
- c: c,
320
- results: []
321
- });
322
- }
323
- const setar_token = {
324
- _id: payload._id,
325
- email: payload.email,
326
- ativo: payload.ativo,
327
- data_criacao: payload.data_criacao,
328
- nome: payload.nome,
329
- app: payload.app,
330
- usuario_tipo: payload.usuario_tipo
331
- };
332
- c.set("usuario_auth", setar_token);
333
- return await next();
334
- } catch (error) {
335
- return src_helpers.set_response.c.INVALID_TOKEN({
336
- message: 'Token inválido!!!',
337
- c: c,
338
- results: []
339
- });
340
- }
341
- }
342
- static async criar_token_login_usuario({ _id, email, app, usuario_tipo, ativo, data_criacao, nome, c }) {
343
- if (!c.env.JSON_WEB_TOKEN_AUTH_USER) {
344
- return src_helpers.set_response.error.WARNING({
345
- message: "Erro ao gerar token!!",
346
- results: []
347
- });
348
- }
349
- const token = await new external_jose_namespaceObject.SignJWT({
350
- _id: _id,
351
- email: email,
352
- app: app,
353
- usuario_tipo: usuario_tipo,
354
- ativo: ativo,
355
- data_criacao: data_criacao,
356
- nome: nome
357
- }).setProtectedHeader({
358
- alg: "HS256"
359
- }).setIssuedAt()//.setExpirationTime("24h")
360
- .sign(new TextEncoder().encode(c.env.JSON_WEB_TOKEN_AUTH_USER)).catch((error)=>{
361
- return src_helpers.set_response.error.WARNING({
362
- message: "Erro ao gerar token!",
363
- results: error?.message
364
- });
365
- });
366
- return token;
367
- }
368
- };
369
- /* export default */ const helpers_token = (_token);
370
-
371
- ;// CONCATENATED MODULE: external "node:crypto"
372
- const external_node_crypto_namespaceObject = require("node:crypto");
373
- ;// CONCATENATED MODULE: external "node:util"
374
- const external_node_util_namespaceObject = require("node:util");
375
- ;// CONCATENATED MODULE: ./src/helpers/_secret.ts
376
-
377
-
378
- const scryptAsync = (0,external_node_util_namespaceObject.promisify)(external_node_crypto_namespaceObject.scrypt);
379
- class _secret {
380
- static SALT_LENGTH = 22;
381
- static KEY_LENGTH = 35;
382
- static async gerar_hash_senha(password) {
383
- const salt = (0,external_node_crypto_namespaceObject.randomBytes)(this.SALT_LENGTH);
384
- const derivedKey = await scryptAsync(password, salt, this.KEY_LENGTH);
385
- return salt.toString('base64') + '.' + derivedKey.toString('base64');
386
- }
387
- static async verify({ password, dashed_senha }) {
388
- try {
389
- const [saltBase64, hashBase64] = dashed_senha.split('.');
390
- if (!saltBase64 || !hashBase64) return false;
391
- const salt = Buffer.from(saltBase64, 'base64');
392
- const storedHash = Buffer.from(hashBase64, 'base64');
393
- const derivedKey = await scryptAsync(password, salt, this.KEY_LENGTH);
394
- return (0,external_node_crypto_namespaceObject.timingSafeEqual)(storedHash, derivedKey);
395
- } catch {
396
- return false;
397
- }
398
- }
399
- }
400
- /* export default */ const helpers_secret = (_secret);
401
-
402
- ;// CONCATENATED MODULE: ./src/helpers/_data.ts
403
- const _data = {
404
- get_now_format_number: Math.floor(Date.now() / 1000),
405
- verificar_data: (value)=>{
406
- const data = new Date(value * 1000);
407
- if (isNaN(data.getTime())) {
408
- throw new Error("Timestamp está inválido.");
409
- }
410
- return value; // válido
411
- }
412
- };
413
- /* export default */ const helpers_data = (_data);
414
-
415
- ;// CONCATENATED MODULE: ./src/helpers/index.ts
416
- //_HELPERS
417
-
418
-
419
-
420
-
421
- const helpers = {
422
- set_response: _set_response,
423
- token: helpers_token,
424
- secret: helpers_secret,
425
- data: helpers_data
426
- };
427
- /* export default */ const src_helpers = (helpers);
428
-
429
-
430
- },
431
-
432
- });
433
- // The module cache
434
- var __webpack_module_cache__ = {};
435
-
436
- // The require function
437
- function __webpack_require__(moduleId) {
438
-
439
- // Check if module is in cache
440
- var cachedModule = __webpack_module_cache__[moduleId];
441
- if (cachedModule !== undefined) {
442
- return cachedModule.exports;
443
- }
444
- // Create a new module (and put it into the cache)
445
- var module = (__webpack_module_cache__[moduleId] = {
446
- exports: {}
447
- });
448
- // Execute the module function
449
- __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
450
-
451
- // Return the exports of the module
452
- return module.exports;
453
-
454
- }
455
-
456
- // webpack/runtime/compat_get_default_export
457
- (() => {
458
- // getDefaultExport function for compatibility with non-ESM modules
459
- __webpack_require__.n = (module) => {
460
- var getter = module && module.__esModule ?
461
- () => (module['default']) :
462
- () => (module);
463
- __webpack_require__.d(getter, { a: getter });
464
- return getter;
465
- };
466
-
467
- })();
468
- // webpack/runtime/define_property_getters
469
- (() => {
470
- __webpack_require__.d = (exports, definition) => {
471
- for(var key in definition) {
472
- if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
473
- Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
474
- }
475
- }
476
- };
477
- })();
478
- // webpack/runtime/has_own_property
479
- (() => {
480
- __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
481
- })();
482
- // webpack/runtime/make_namespace_object
483
- (() => {
484
- // define __esModule on exports
485
- __webpack_require__.r = (exports) => {
486
- if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
487
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
488
- }
489
- Object.defineProperty(exports, '__esModule', { value: true });
490
- };
491
- })();
492
- var __webpack_exports__ = {};
493
- // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
494
- (() => {
495
- __webpack_require__.r(__webpack_exports__);
496
- __webpack_require__.d(__webpack_exports__, {
497
- helpers: () => (/* reexport safe */ _helpers__rspack_import_0["default"])
498
- });
499
- /* import */ var _helpers__rspack_import_0 = __webpack_require__("./src/helpers/index.ts");
500
-
501
-
502
- })();
503
-
504
- exports.helpers = __webpack_exports__.helpers;
505
- for(var __rspack_i in __webpack_exports__) {
506
- if(["helpers"].indexOf(__rspack_i) === -1) {
507
- exports[__rspack_i] = __webpack_exports__[__rspack_i];
508
- }
509
- }
510
- Object.defineProperty(exports, '__esModule', { value: true });