fiscalia_bo-nest-helpers 0.0.1

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 (41) hide show
  1. package/.env +1 -0
  2. package/.eslintrc.js +25 -0
  3. package/.prettierrc +5 -0
  4. package/.vscode/settings.json +3 -0
  5. package/README.md +51 -0
  6. package/dist/index.d.ts +1 -0
  7. package/dist/index.js +18 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/src/helpers/request.helper.d.ts +4 -0
  10. package/dist/src/helpers/request.helper.js +53 -0
  11. package/dist/src/helpers/request.helper.js.map +1 -0
  12. package/dist/src/services/ms-files.service.d.ts +18 -0
  13. package/dist/src/services/ms-files.service.js +69 -0
  14. package/dist/src/services/ms-files.service.js.map +1 -0
  15. package/dist/src/types/index.d.ts +2 -0
  16. package/dist/src/types/index.js +19 -0
  17. package/dist/src/types/index.js.map +1 -0
  18. package/dist/src/types/input.type.d.ts +32 -0
  19. package/dist/src/types/input.type.js +3 -0
  20. package/dist/src/types/input.type.js.map +1 -0
  21. package/dist/src/types/response.type.d.ts +35 -0
  22. package/dist/src/types/response.type.js +3 -0
  23. package/dist/src/types/response.type.js.map +1 -0
  24. package/dist/tsconfig.tsbuildinfo +1 -0
  25. package/index.ts +1 -0
  26. package/nest-cli.json +8 -0
  27. package/package.json +77 -0
  28. package/src/app.controller.ts +12 -0
  29. package/src/app.module.ts +10 -0
  30. package/src/app.service.ts +8 -0
  31. package/src/helpers/request.helper.ts +76 -0
  32. package/src/main.ts +8 -0
  33. package/src/services/ms-files.service.spec.ts +81 -0
  34. package/src/services/ms-files.service.ts +175 -0
  35. package/src/types/index.ts +2 -0
  36. package/src/types/input.type.ts +35 -0
  37. package/src/types/response.type.ts +38 -0
  38. package/test/app.e2e-spec.ts +24 -0
  39. package/test/jest-e2e.json +9 -0
  40. package/tsconfig.build.json +4 -0
  41. package/tsconfig.json +31 -0
@@ -0,0 +1,175 @@
1
+ import {
2
+ MsFileReplaceFile,
3
+ MsFileVerifyExistFile,
4
+ } from './../types/input.type';
5
+ import { newRequestHttp } from '../helpers/request.helper';
6
+ import { AxiosRequestHeaders } from 'axios';
7
+ import {
8
+ MsFileWriteFile,
9
+ ResponseDTO,
10
+ MsFileCreatedFile,
11
+ MsFileReadFile,
12
+ MsFilesReadFile,
13
+ MsFileRelocatedFile,
14
+ MsFileRelocateFile,
15
+ MsFileVerifiedExistFile,
16
+ MsFileReplacedFile,
17
+ } from '../types';
18
+ import { Injectable } from '@nestjs/common';
19
+
20
+ @Injectable()
21
+ export class MsFilesService {
22
+ MsFileRequest;
23
+ constructor() {
24
+ if (!process.env.ENV_SERVICE_MS_FILE)
25
+ console.warn('Variable de entorno ENV_SERVICE_MS_FILE no encontrado');
26
+ this.MsFileRequest = newRequestHttp(
27
+ process.env.ENV_SERVICE_MS_FILE ||
28
+ 'https://ms-files-test.fiscalia.gob.bo',
29
+ );
30
+ }
31
+
32
+ /**
33
+ * Guardar un archivo en base 64 en ms-files
34
+ * @param data Objeto de consulta a ms-fils
35
+ * @param headers
36
+ * @returns
37
+ */
38
+ async writeFileBase64V1(
39
+ data: MsFileWriteFile,
40
+ headers: Partial<AxiosRequestHeaders> = {},
41
+ ): Promise<ResponseDTO<MsFileCreatedFile>> {
42
+ // === INICIALIZACIÓN DE VARIABLES ===
43
+ headers['Content-Type'] = 'application/json';
44
+ // === OPERACIÓN ===
45
+ return this.MsFileRequest(
46
+ {
47
+ data,
48
+ method: 'POST',
49
+ url: '/v1/write/base64',
50
+ },
51
+ headers,
52
+ );
53
+ }
54
+
55
+ /**
56
+ * Recuperar un archivo en base64 de ms-files
57
+ * @param data
58
+ * @param headers
59
+ * @returns
60
+ */
61
+ async readFileBase64V1(
62
+ data: MsFileReadFile,
63
+ headers: Partial<AxiosRequestHeaders> = {},
64
+ ): Promise<ResponseDTO<MsFilesReadFile>> {
65
+ headers['Content-Type'] = 'application/json';
66
+ // === OPERACIÓN ===
67
+ return this.MsFileRequest(
68
+ {
69
+ url: '/v1/read/base64',
70
+ method: 'POST',
71
+ data,
72
+ },
73
+ headers,
74
+ );
75
+ }
76
+
77
+ /**
78
+ * Obtener un archivo por id de ms-files
79
+ * @param id
80
+ * @param headers
81
+ * @returns
82
+ */
83
+ async getFileById(
84
+ id: string,
85
+ headers: Partial<AxiosRequestHeaders> = {},
86
+ ): Promise<ResponseDTO<MsFilesReadFile>> {
87
+ return this.readFileBase64V1({ id }, headers);
88
+ }
89
+
90
+ /**
91
+ * Eliminar un archivo de ms-files
92
+ * @param data
93
+ * @param headers
94
+ * @returns
95
+ */
96
+ async deleteFileV1(
97
+ data: { id?: string; pathName?: string },
98
+ headers: Partial<AxiosRequestHeaders> = {},
99
+ ): Promise<ResponseDTO<any>> {
100
+ headers['Content-Type'] = 'application/json';
101
+ return this.MsFileRequest(
102
+ { url: '/v1/delete', method: 'DELETE', data },
103
+ headers,
104
+ );
105
+ }
106
+
107
+ /**
108
+ * Reemplazar contenido de archivo en ms-file
109
+ * @param data
110
+ * @param headers
111
+ * @returns
112
+ */
113
+ async replaceFileBase64V1(
114
+ data: MsFileReplaceFile,
115
+ headers: Partial<AxiosRequestHeaders> = {},
116
+ ): Promise<ResponseDTO<MsFileReplacedFile>> {
117
+ headers['Content-Type'] = 'application/json';
118
+ return this.MsFileRequest(
119
+ { url: '/v1/replace/file/base64', method: 'POST', data },
120
+ headers,
121
+ );
122
+ }
123
+
124
+ /**
125
+ * Función para re localizar un archivo en ms-files
126
+ * @param data
127
+ * @param headers
128
+ * @returns
129
+ */
130
+ async relocateFileBase64V1(
131
+ data: MsFileRelocateFile,
132
+ headers: Partial<AxiosRequestHeaders> = {},
133
+ ): Promise<ResponseDTO<MsFileRelocatedFile>> {
134
+ headers['Content-Type'] = 'application/json';
135
+ return this.MsFileRequest(
136
+ { url: '/v1/relocate/file', method: 'POST', data },
137
+ headers,
138
+ );
139
+ }
140
+
141
+ /**
142
+ * Verificar si existe un archivo en ms-files
143
+ * @param data
144
+ * @param headers
145
+ * @returns
146
+ */
147
+ async verifyExistFileV1(
148
+ data: MsFileVerifyExistFile,
149
+ headers: Partial<AxiosRequestHeaders> = {},
150
+ ): Promise<ResponseDTO<MsFileVerifiedExistFile>> {
151
+ headers['Content-Type'] = 'application/json';
152
+ return this.MsFileRequest(
153
+ { url: '/v1/verify/exists/file', method: 'POST', data },
154
+ headers,
155
+ );
156
+ }
157
+
158
+ /**
159
+ * Obtener lista tipos de archivos que se puede almacenar en ms-files
160
+ * @param headers
161
+ * @returns
162
+ */
163
+ async getAllowedTypes(
164
+ headers: Partial<AxiosRequestHeaders> = {},
165
+ ): Promise<ResponseDTO<Array<string>>> {
166
+ // === INICIALIZACIÓN DE VARIABLES ===
167
+ return this.MsFileRequest(
168
+ {
169
+ method: 'GET',
170
+ url: '/v1/application/types',
171
+ },
172
+ headers,
173
+ ); // === RESPUESTA ===
174
+ }
175
+ }
@@ -0,0 +1,2 @@
1
+ export * from './input.type';
2
+ export * from './response.type';
@@ -0,0 +1,35 @@
1
+ import { Method } from 'axios';
2
+
3
+ // Tipos para request
4
+ export interface RequestData {
5
+ url: string;
6
+ method: Method;
7
+ data?: any;
8
+ }
9
+
10
+ // Tipos para guardar un archivo
11
+ export interface MsFileWriteFile {
12
+ appName: string;
13
+ fileName: string;
14
+ base64: string;
15
+ path: string;
16
+ nas: string;
17
+ withDateSubFolder?: boolean;
18
+ }
19
+
20
+ export type MsFileReadFile = { id?: string; pathName?: string };
21
+
22
+ export type MsFileRelocateFile = {
23
+ id?: string;
24
+ pathName?: string;
25
+ newPathName: string;
26
+ replaceIfExists: boolean;
27
+ };
28
+
29
+ export type MsFileVerifyExistFile = { pathName: string };
30
+
31
+ export type MsFileReplaceFile = {
32
+ id?: string;
33
+ pathName?: string;
34
+ base64: string;
35
+ };
@@ -0,0 +1,38 @@
1
+ export type MsFileCreatedFile = {
2
+ originalName: string;
3
+ fileName: string;
4
+ size: number;
5
+ extension: string;
6
+ mimeType: string;
7
+ pathName: string;
8
+ fullPath: string;
9
+ sha256: string;
10
+ id: string;
11
+ };
12
+
13
+ // Tipos para respuesta
14
+ export type ResponseDTO<T> = {
15
+ error: boolean;
16
+ message: string;
17
+ response: T;
18
+ status: number;
19
+ };
20
+
21
+ // tipo de respuesta a leer archivo
22
+ export type MsFilesReadFile = MsFileCreatedFile & { base64: string };
23
+
24
+ export type MsFileRelocatedFile = {
25
+ id: string;
26
+ originalName: string;
27
+ fileName: string;
28
+ size: number;
29
+ extension: string;
30
+ mimeType: string;
31
+ pathName: string;
32
+ fullPath: string;
33
+ sha256: string;
34
+ };
35
+
36
+ export type MsFileVerifiedExistFile = { exists: boolean };
37
+
38
+ export type MsFileReplacedFile = MsFileCreatedFile;
@@ -0,0 +1,24 @@
1
+ import { Test, TestingModule } from '@nestjs/testing';
2
+ import { INestApplication } from '@nestjs/common';
3
+ import * as request from 'supertest';
4
+ import { AppModule } from './../src/app.module';
5
+
6
+ describe('AppController (e2e)', () => {
7
+ let app: INestApplication;
8
+
9
+ beforeEach(async () => {
10
+ const moduleFixture: TestingModule = await Test.createTestingModule({
11
+ imports: [AppModule],
12
+ }).compile();
13
+
14
+ app = moduleFixture.createNestApplication();
15
+ await app.init();
16
+ });
17
+
18
+ it('/ (GET)', () => {
19
+ return request(app.getHttpServer())
20
+ .get('/')
21
+ .expect(200)
22
+ .expect('Hello World!');
23
+ });
24
+ });
@@ -0,0 +1,9 @@
1
+ {
2
+ "moduleFileExtensions": ["js", "json", "ts"],
3
+ "rootDir": ".",
4
+ "testEnvironment": "node",
5
+ "testRegex": ".e2e-spec.ts$",
6
+ "transform": {
7
+ "^.+\\.(t|j)s$": "ts-jest"
8
+ }
9
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "exclude": ["node_modules", "test", "dist", "**/*spec.ts", "app.*", "main.js"]
4
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "declaration": true,
5
+ "removeComments": true,
6
+ "emitDecoratorMetadata": true,
7
+ "experimentalDecorators": true,
8
+ "allowSyntheticDefaultImports": true,
9
+ "target": "es2017",
10
+ "sourceMap": true,
11
+ "outDir": "./dist",
12
+ "baseUrl": "./",
13
+ "incremental": true,
14
+ "skipLibCheck": true,
15
+ "strictNullChecks": false,
16
+ "noImplicitAny": false,
17
+ "strictBindCallApply": false,
18
+ "forceConsistentCasingInFileNames": false,
19
+ "noFallthroughCasesInSwitch": false
20
+ },
21
+ "exclude": [
22
+ "node_modules",
23
+ "test",
24
+ "dist",
25
+ "**/*spec.ts",
26
+ "src/app.controller.ts",
27
+ "src/app.module.ts",
28
+ "src/app.service.ts",
29
+ "src/main.ts"
30
+ ]
31
+ }