@zerosls/clm-sdk 1.0.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.
Files changed (81) hide show
  1. package/.docs/publicacion-npm.md +111 -0
  2. package/.env.example +14 -0
  3. package/.gitlab-ci.yml +23 -0
  4. package/README.md +202 -0
  5. package/dist/config/config.d.ts +3 -0
  6. package/dist/config/config.js +21 -0
  7. package/dist/core/api-client.d.ts +27 -0
  8. package/dist/core/api-client.js +183 -0
  9. package/dist/core/api-error.d.ts +15 -0
  10. package/dist/core/api-error.js +46 -0
  11. package/dist/core/event-emitter.d.ts +11 -0
  12. package/dist/core/event-emitter.js +32 -0
  13. package/dist/index.d.ts +41 -0
  14. package/dist/index.js +59 -0
  15. package/dist/modules/legacy/areas/areas-api.d.ts +34 -0
  16. package/dist/modules/legacy/areas/areas-api.js +44 -0
  17. package/dist/modules/legacy/areas/types.d.ts +37 -0
  18. package/dist/modules/legacy/areas/types.js +1 -0
  19. package/dist/modules/legacy/classificationtypes/classificationtypes-api.d.ts +34 -0
  20. package/dist/modules/legacy/classificationtypes/classificationtypes-api.js +46 -0
  21. package/dist/modules/legacy/classificationtypes/types.d.ts +41 -0
  22. package/dist/modules/legacy/classificationtypes/types.js +1 -0
  23. package/dist/modules/v1/auth/auth-api.d.ts +17 -0
  24. package/dist/modules/v1/auth/auth-api.js +63 -0
  25. package/dist/modules/v1/auth/types.d.ts +18 -0
  26. package/dist/modules/v1/auth/types.js +1 -0
  27. package/dist/modules/v1/main/main-api.d.ts +11 -0
  28. package/dist/modules/v1/main/main-api.js +14 -0
  29. package/dist/modules/v1/main/types.d.ts +3 -0
  30. package/dist/modules/v1/main/types.js +1 -0
  31. package/dist/modules/v1/notifications/notification-api.d.ts +16 -0
  32. package/dist/modules/v1/notifications/notification-api.js +26 -0
  33. package/dist/modules/v1/notifications/types.d.ts +53 -0
  34. package/dist/modules/v1/notifications/types.js +1 -0
  35. package/dist/modules/v1/users/types.d.ts +64 -0
  36. package/dist/modules/v1/users/types.js +1 -0
  37. package/dist/modules/v1/users/users-api.d.ts +81 -0
  38. package/dist/modules/v1/users/users-api.js +113 -0
  39. package/dist/types/common.d.ts +18 -0
  40. package/dist/types/common.js +1 -0
  41. package/dist/types/sdk.d.ts +42 -0
  42. package/dist/types/sdk.js +11 -0
  43. package/dist/utils/cache.d.ts +10 -0
  44. package/dist/utils/cache.js +43 -0
  45. package/dist/utils/http.d.ts +5 -0
  46. package/dist/utils/http.js +56 -0
  47. package/package.json +38 -0
  48. package/src/config/config.ts +24 -0
  49. package/src/core/api-client.ts +272 -0
  50. package/src/core/api-error.ts +54 -0
  51. package/src/core/event-emitter.ts +43 -0
  52. package/src/index.ts +89 -0
  53. package/src/modules/legacy/areas/areas-api.ts +73 -0
  54. package/src/modules/legacy/areas/types.ts +49 -0
  55. package/src/modules/legacy/classificationtypes/classificationtypes-api.ts +80 -0
  56. package/src/modules/legacy/classificationtypes/types.ts +52 -0
  57. package/src/modules/v1/auth/auth-api.ts +75 -0
  58. package/src/modules/v1/auth/types.ts +20 -0
  59. package/src/modules/v1/main/main-api.ts +20 -0
  60. package/src/modules/v1/main/types.ts +3 -0
  61. package/src/modules/v1/notifications/notification-api.ts +55 -0
  62. package/src/modules/v1/notifications/types.ts +58 -0
  63. package/src/modules/v1/users/types.ts +83 -0
  64. package/src/modules/v1/users/users-api.ts +148 -0
  65. package/src/types/common.ts +22 -0
  66. package/src/types/sdk.ts +38 -0
  67. package/src/utils/cache.ts +58 -0
  68. package/src/utils/http.ts +77 -0
  69. package/tests/integration/legacy/auth-areas.test.ts +115 -0
  70. package/tests/integration/legacy/auth-classification-types.test.ts +80 -0
  71. package/tests/integration/v1/auth-logs.test.ts +145 -0
  72. package/tests/integration/v1/auth-users.test.ts +189 -0
  73. package/tests/modules/legacy/areas/areas-api.test.ts +232 -0
  74. package/tests/modules/legacy/classification-types/classification-types-api.test.ts +100 -0
  75. package/tests/modules/v1/auth/auth-api.test.ts +134 -0
  76. package/tests/modules/v1/users/users-api.test.ts +176 -0
  77. package/tests/setup.ts +12 -0
  78. package/tests/utils/test-utils.ts +453 -0
  79. package/tsconfig.json +16 -0
  80. package/tsconfig.test.json +13 -0
  81. package/vitest.config.ts +16 -0
@@ -0,0 +1,453 @@
1
+ import { vi } from 'vitest';
2
+
3
+ /**
4
+ * Crea un mock de respuesta de fetch con la estructura correcta
5
+ */
6
+ export const mockFetchResponse = (status: number, data: any): Response => {
7
+ const isSuccess = status >= 200 && status < 300;
8
+
9
+ return {
10
+ ok: isSuccess,
11
+ status,
12
+ statusText: isSuccess ? 'OK' : 'Error',
13
+ json: vi.fn().mockResolvedValue(data),
14
+ text: vi.fn().mockResolvedValue(JSON.stringify(data)),
15
+ headers: new Headers({ 'Content-Type': 'application/json' })
16
+ } as unknown as Response;
17
+ };
18
+
19
+ /**
20
+ * Configura un mock para fetch que devuelve diferentes respuestas
21
+ * según la URL y método
22
+ */
23
+ export const setupFetchMock = (mocks: {
24
+ url: string;
25
+ method: string;
26
+ response: {
27
+ status: number;
28
+ data: any;
29
+ };
30
+ }[]) => {
31
+ (global.fetch as unknown as ReturnType<typeof vi.fn>).mockImplementation(
32
+ (url: string, options: RequestInit) => {
33
+ // Buscar un mock que coincida con la URL y método
34
+ const mock = mocks.find(
35
+ m => url.includes(m.url) && (!options.method || options.method === m.method)
36
+ );
37
+
38
+ if (mock) {
39
+ return Promise.resolve(mockFetchResponse(mock.response.status, mock.response.data));
40
+ }
41
+
42
+ // Si no hay un mock para esta petición, retornamos un 404
43
+ console.warn(`No se encontró mock para: ${options.method || 'GET'} ${url}`);
44
+ return Promise.resolve(mockFetchResponse(404, { message: 'Not Found' }));
45
+ }
46
+ );
47
+ };
48
+
49
+ /**
50
+ * Utilidad para esperar un tiempo determinado
51
+ */
52
+ export const wait = (ms: number): Promise<void> =>
53
+ new Promise(resolve => setTimeout(resolve, ms));
54
+
55
+ /**
56
+ * Datos de prueba para auth
57
+ */
58
+ export const AUTH_TEST_DATA = {
59
+ loginRequest: {
60
+ email: 'ivan@zeroclm.com',
61
+ password: 'Pass#Dev2024'
62
+ },
63
+ loginToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI4ZDMxZjhiMC1lODYyLTQxMmMtYmQyMy04OTNjYTVlZDY0NjIiLCJlbWFpbCI6Iml2YW5AemVyb2NsbS5jb20iLCJzY29wZSI6WyJhZG1pbmlzdHJhZG9yIiwidXNlciIsInVzZXI6OGQzMWY4YjAtZTg2Mi00MTJjLWJkMjMtODkzY2E1ZWQ2NDYyIiwidXNlcjppdmFuQHplcm9jbG0uY29tIl0sImlhdCI6MTc0NjIyODkyMn0.EyNCM4RdPeOD_ZXqDRy2gWFJ_OrKJNcaLSjEpGhkKpo'
64
+ };
65
+
66
+ /**
67
+ * Datos de prueba para users
68
+ */
69
+ export const USERS_TEST_DATA = {
70
+ usersList: {
71
+ data: [
72
+ {
73
+ id: '8d31f8b0-e862-412c-bd23-893ca5ed6462',
74
+ email: 'test@example.com',
75
+ full_name: 'Test User',
76
+ role_id: 1,
77
+ is_deleted: false,
78
+ deleted_at: null,
79
+ is_active: true,
80
+ created_at: '2025-05-01T13:48:57.411Z',
81
+ updated_at: '2025-05-01T13:48:57.411Z',
82
+ phone: null,
83
+ area: null,
84
+ area_id: null,
85
+ organization_id: 1
86
+ }
87
+ ],
88
+ meta: {
89
+ total: 1,
90
+ page: 1,
91
+ limit: 20,
92
+ pages: 1
93
+ }
94
+ }
95
+ };
96
+
97
+ /**
98
+ * Datos de prueba para logs
99
+ */
100
+ export const LOGS_TEST_DATA = {
101
+ // GET /logs - Lista completa
102
+ logsList: {
103
+ results: [
104
+ {
105
+ id: 181,
106
+ organization_id: 1,
107
+ level: "debug" as const,
108
+ message: "Solicitud",
109
+ source: "/swaggerui/favicon-32x32.png",
110
+ user_id: null,
111
+ ip_address: "127.0.0.1",
112
+ request_data: {
113
+ path: "/swaggerui/favicon-32x32.png",
114
+ query: {},
115
+ method: "get",
116
+ params: {},
117
+ payload: {}
118
+ },
119
+ stack_trace: null,
120
+ created_at: "2025-09-30T03:39:19.819Z",
121
+ request_detail: null
122
+ },
123
+ {
124
+ id: 173,
125
+ organization_id: 1,
126
+ level: "info" as const,
127
+ message: "Documento subido y validado correctamente",
128
+ source: "/documents/upload",
129
+ user_id: 456,
130
+ ip_address: "10.0.0.25",
131
+ request_data: {
132
+ filename: "contrato_comercial.pdf",
133
+ file_size: "1.2MB",
134
+ mime_type: "application/pdf"
135
+ },
136
+ stack_trace: null,
137
+ created_at: "2025-09-19T15:19:32.441Z",
138
+ request_detail: {
139
+ type: "document",
140
+ comment: "Documento validado automáticamente, sin errores detectados",
141
+ next_stage: "validated",
142
+ request_id: 1001,
143
+ start_state: "uploading",
144
+ upload_date: "2025-09-16T16:15:00.000Z",
145
+ approved_date: "2025-09-16T16:15:45.000Z",
146
+ request_folio: "DOC-2025-005",
147
+ doc_anexo_name: "contrato_comercial.pdf"
148
+ }
149
+ }
150
+ ],
151
+ pagination: { page: 1, limit: 25, totalItems: 13, totalPages: 1 }
152
+ },
153
+
154
+ // GET /logs?level=info&page=1&limit=1 - Filtrado (solo cambia pagination)
155
+ logsFiltered: {
156
+ results: [
157
+ {
158
+ id: 173,
159
+ organization_id: 1,
160
+ level: "info" as const,
161
+ message: "Documento subido y validado correctamente",
162
+ source: "/documents/upload",
163
+ user_id: 456,
164
+ ip_address: "10.0.0.25",
165
+ request_data: {
166
+ filename: "contrato_comercial.pdf",
167
+ file_size: "1.2MB",
168
+ mime_type: "application/pdf"
169
+ },
170
+ stack_trace: null,
171
+ created_at: "2025-09-19T15:19:32.441Z",
172
+ request_detail: {
173
+ type: "document",
174
+ comment: "Documento validado automáticamente, sin errores detectados",
175
+ next_stage: "validated",
176
+ request_id: 1001,
177
+ start_state: "uploading",
178
+ upload_date: "2025-09-16T16:15:00.000Z",
179
+ approved_date: "2025-09-16T16:15:45.000Z",
180
+ request_folio: "DOC-2025-005",
181
+ doc_anexo_name: "contrato_comercial.pdf"
182
+ }
183
+ }
184
+ ],
185
+ pagination: { page: 1, limit: 1, totalItems: 2, totalPages: 2 }
186
+ },
187
+
188
+ // GET /logs/:id - Log individual
189
+ singleLog: {
190
+ id: 171,
191
+ organization_id: 1,
192
+ level: "debug" as const,
193
+ message: "Solicitud",
194
+ source: "/auth/login",
195
+ user_id: 4,
196
+ ip_address: "127.0.0.1",
197
+ request_data: {
198
+ path: "/auth/login",
199
+ query: {},
200
+ method: "get",
201
+ params: {},
202
+ payload: {}
203
+ },
204
+ stack_trace: null,
205
+ created_at: "2025-09-19T14:53:53.706Z",
206
+ request_detail: null
207
+ },
208
+
209
+ // POST /logs - Crear log
210
+ createLogRequest: {
211
+ level: "info" as const,
212
+ message: "Documento subido y validado correctamente",
213
+ source: "/documents/upload",
214
+ user_id: 456,
215
+ ip_address: "10.0.0.25",
216
+ request_data: {
217
+ filename: "contrato_comercial.pdf",
218
+ file_size: "1.2MB",
219
+ mime_type: "application/pdf"
220
+ },
221
+ request_detail: {
222
+ request_id: 1001,
223
+ request_folio: "DOC-2025-005",
224
+ type: "document",
225
+ start_state: "uploading",
226
+ next_stage: "validated",
227
+ doc_anexo_name: "contrato_comercial.pdf",
228
+ upload_date: "2025-09-16T16:15:00Z",
229
+ approved_date: "2025-09-16T16:15:45Z",
230
+ comment: "Documento validado automáticamente, sin errores detectados"
231
+ }
232
+ },
233
+
234
+ createLogResponse: {
235
+ id: 200,
236
+ organization_id: 1,
237
+ level: "info" as const,
238
+ message: "Documento subido y validado correctamente",
239
+ source: "/documents/upload",
240
+ user_id: 456,
241
+ ip_address: "10.0.0.25",
242
+ request_data: {
243
+ filename: "contrato_comercial.pdf",
244
+ file_size: "1.2MB",
245
+ mime_type: "application/pdf"
246
+ },
247
+ stack_trace: null,
248
+ created_at: "2025-09-30T10:00:00.000Z",
249
+ request_detail: {
250
+ request_id: 1001,
251
+ request_folio: "DOC-2025-005",
252
+ type: "document",
253
+ start_state: "uploading",
254
+ next_stage: "validated",
255
+ doc_anexo_name: "contrato_comercial.pdf",
256
+ upload_date: "2025-09-16T16:15:00Z",
257
+ approved_date: "2025-09-16T16:15:45Z",
258
+ comment: "Documento validado automáticamente, sin errores detectados"
259
+ }
260
+ }
261
+ } as const;
262
+
263
+ /**
264
+ * Datos de prueba para areas
265
+ */
266
+ export const AREAS_TEST_DATA = {
267
+ areasList: {
268
+ dataResult: [
269
+ {
270
+ id: 26,
271
+ name: 'CALIDAD',
272
+ description: '-',
273
+ createdBy: 'USR001',
274
+ createdByName: 'Admin',
275
+ createdOn: '2025-01-01T00:00:00.000Z',
276
+ lastModBy: 'USR001',
277
+ lastModByName: 'Admin',
278
+ lastModOn: '2025-01-01T00:00:00.000Z'
279
+ },
280
+ {
281
+ id: 27,
282
+ name: 'Gerencia de Tecnologías de la Información',
283
+ description: 'Gerencia de Tecnologías de la Información',
284
+ createdBy: 'USR001',
285
+ createdByName: 'Admin',
286
+ createdOn: '2025-01-01T00:00:00.000Z',
287
+ lastModBy: 'USR001',
288
+ lastModByName: 'Admin',
289
+ lastModOn: '2025-01-01T00:00:00.000Z'
290
+ }
291
+ ],
292
+ statusResponse: {
293
+ code: 200,
294
+ success: true,
295
+ message: 'success'
296
+ }
297
+ },
298
+
299
+ newAreaRequest: {
300
+ createdBy: 'USR001',
301
+ createdByName: 'Juan Pérez',
302
+ createdOn: '2025-09-29T15:53:09.136Z',
303
+ lastModBy: 'USR001',
304
+ lastModByName: 'Juan Pérez',
305
+ lastModOn: '2025-09-29T15:53:09.136Z',
306
+ name: 'Testing QA',
307
+ description: 'Área de pruebas y aseguramiento de calidad'
308
+ },
309
+
310
+ createAreaResponse: {
311
+ dataResult: {
312
+ id: 26,
313
+ createdBy: 'USR001',
314
+ createdByName: 'Juan Pérez',
315
+ createdOn: '2025-09-29T15:53:09.136Z',
316
+ lastModBy: 'USR001',
317
+ lastModByName: 'Juan Pérez',
318
+ lastModOn: '2025-09-29T15:53:09.136Z',
319
+ name: 'Testing QA',
320
+ description: 'Área de pruebas y aseguramiento de calidad'
321
+ },
322
+ statusResponse: {
323
+ code: 200,
324
+ success: true,
325
+ message: 'Area created successfully'
326
+ }
327
+ },
328
+
329
+ updateAreaRequest: {
330
+ id: 26,
331
+ createdBy: 'USR001',
332
+ createdByName: 'Juan Pérez',
333
+ createdOn: '2025-09-29T15:53:09.136Z',
334
+ lastModBy: 'USR002',
335
+ lastModByName: 'María González',
336
+ lastModOn: '2025-09-29T16:30:00.000Z',
337
+ name: 'Testing QA - Actualizado',
338
+ description: 'Área de pruebas, QA y automatización'
339
+ },
340
+
341
+ updateAreaResponse: {
342
+ dataResult: {
343
+ id: 26,
344
+ createdBy: 'USR001',
345
+ createdByName: 'Juan Pérez',
346
+ createdOn: '2025-09-29T15:53:09.136Z',
347
+ lastModBy: 'USR002',
348
+ lastModByName: 'María González',
349
+ lastModOn: '2025-09-29T16:30:00.000Z',
350
+ name: 'Testing QA - Actualizado',
351
+ description: 'Área de pruebas, QA y automatización'
352
+ },
353
+ statusResponse: {
354
+ code: 200,
355
+ success: true,
356
+ message: 'Area updated successfully'
357
+ }
358
+ },
359
+
360
+ deleteAreaResponse: {
361
+ statusResponse: {
362
+ code: 200,
363
+ success: true,
364
+ message: 'Area deleted successfully'
365
+ }
366
+ }
367
+ };
368
+
369
+ /**
370
+ * Datos de prueba para classification types
371
+ */
372
+ export const CLASSIFICATION_TYPES_TEST_DATA = {
373
+ classificationTypesList: {
374
+ dataResult: [
375
+ {
376
+ id: 2,
377
+ name: "Contrato de Compraventa",
378
+ description: "Description updated"
379
+ },
380
+ {
381
+ id: 3,
382
+ name: "Contrato Laboral",
383
+ description: ""
384
+ },
385
+ {
386
+ id: 4,
387
+ name: "Contrato de Marketplace",
388
+ description: null
389
+ },
390
+ {
391
+ id: 5,
392
+ name: "Contrato de Confidencialidad",
393
+ description: null
394
+ }
395
+ ],
396
+ statusResponse: {
397
+ code: 200,
398
+ success: true,
399
+ message: "success"
400
+ }
401
+ },
402
+
403
+ newClassificationTypeRequest: {
404
+ createdBy: "USR001",
405
+ createdByName: "Juan Pérez",
406
+ createdOn: "2025-09-29T18:01:06.337Z",
407
+ lastModBy: "USR001",
408
+ lastModByName: "Juan Pérez",
409
+ lastModOn: "2025-09-29T18:01:06.337Z",
410
+ name: "Contrato de Prueba",
411
+ description: "Tipo de clasificación de prueba"
412
+ },
413
+
414
+ createClassificationTypeResponse: {
415
+ dataResult: {
416
+ id: 20,
417
+ name: "Contrato de Prueba",
418
+ description: "Tipo de clasificación de prueba"
419
+ },
420
+ statusResponse: {
421
+ code: 200,
422
+ success: true,
423
+ message: "Classification type created successfully"
424
+ }
425
+ },
426
+
427
+ updateClassificationTypeRequest: {
428
+ id: 20,
429
+ name: "Contrato de Prueba Actualizado",
430
+ description: "Descripción actualizada"
431
+ },
432
+
433
+ updateClassificationTypeResponse: {
434
+ dataResult: {
435
+ id: 20,
436
+ name: "Contrato de Prueba Actualizado",
437
+ description: "Descripción actualizada"
438
+ },
439
+ statusResponse: {
440
+ code: 200,
441
+ success: true,
442
+ message: "Classification type updated successfully"
443
+ }
444
+ },
445
+
446
+ deleteClassificationTypeResponse: {
447
+ statusResponse: {
448
+ code: 200,
449
+ success: true,
450
+ message: "Classification type deleted successfully"
451
+ }
452
+ }
453
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2018",
4
+ "module": "ES2020",
5
+ "declaration": true,
6
+ "outDir": "./dist",
7
+ "strict": true,
8
+ "esModuleInterop": true,
9
+ "skipLibCheck": true,
10
+ "forceConsistentCasingInFileNames": true,
11
+ "lib": ["es2018", "dom"],
12
+ "moduleResolution": "node"
13
+ },
14
+ "include": ["src/**/*"],
15
+ "exclude": ["node_modules", "dist", "**/*.test.ts"]
16
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "types": ["jest", "node"],
5
+ "esModuleInterop": true,
6
+ "jsx": "react"
7
+ },
8
+ "include": [
9
+ "src/**/*",
10
+ "__tests__/**/*",
11
+ "jest.setup.js"
12
+ ]
13
+ }
@@ -0,0 +1,16 @@
1
+ /// <reference types="vitest" />
2
+
3
+ import { defineConfig } from 'vitest/config';
4
+
5
+ export default defineConfig({
6
+ test: {
7
+ globals: true,
8
+ environment: 'jsdom',
9
+ setupFiles: ['./tests/setup.ts'],
10
+ include: ['tests/**/*.test.ts'],
11
+ coverage: {
12
+ reporter: ['text', 'html'],
13
+ exclude: ['node_modules/']
14
+ }
15
+ }
16
+ });