investira.sdk 2.3.11 → 2.3.13
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/CHANGELOG.md +9 -0
- package/lib/utils/httpRequests.js +62 -7
- package/lib/utils/strings.js +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,8 @@ const axios = require('axios');
|
|
|
6
6
|
const baseRequest = axios.create();
|
|
7
7
|
|
|
8
8
|
const https = require('https');
|
|
9
|
+
const FormData = require('form-data');
|
|
10
|
+
const fs = require('fs');
|
|
9
11
|
|
|
10
12
|
const { RequestCanceled } = require('../messages/ClientErrors');
|
|
11
13
|
const { NoResponse } = require('../messages/ServerErrors');
|
|
@@ -42,15 +44,24 @@ const httpRequests = {
|
|
|
42
44
|
method: pMethod,
|
|
43
45
|
url: pProps.url,
|
|
44
46
|
headers: pProps.headers,
|
|
45
|
-
params: pProps.params,
|
|
46
|
-
data: pProps.data,
|
|
47
|
-
cancelToken: pProps.cancelToken,
|
|
48
47
|
timeout: pProps.timeout || 24000
|
|
49
48
|
};
|
|
50
49
|
|
|
50
|
+
if (pProps.hasOwnProperty('data')) {
|
|
51
|
+
xConfig.data = pProps.data;
|
|
52
|
+
}
|
|
53
|
+
if (pProps.hasOwnProperty('cancelToken')) {
|
|
54
|
+
xConfig.cancelToken = pProps.cancelToken;
|
|
55
|
+
}
|
|
56
|
+
if (pProps.hasOwnProperty('params')) {
|
|
57
|
+
xConfig.params = pProps.params;
|
|
58
|
+
}
|
|
51
59
|
if (pProps.hasOwnProperty('responseType')) {
|
|
52
60
|
xConfig.responseType = pProps.responseType;
|
|
53
61
|
}
|
|
62
|
+
if (pProps.hasOwnProperty('contentType')) {
|
|
63
|
+
xConfig.contentType = pProps.contentType;
|
|
64
|
+
}
|
|
54
65
|
if (pProps.hasOwnProperty('rejectUnauthorized')) {
|
|
55
66
|
xConfig.httpsAgent = new https.Agent({ rejectUnauthorized: pProps.rejectUnauthorized });
|
|
56
67
|
}
|
|
@@ -120,7 +131,6 @@ const httpRequests = {
|
|
|
120
131
|
/**
|
|
121
132
|
*Request POST
|
|
122
133
|
*
|
|
123
|
-
* @param {string} pMethod
|
|
124
134
|
* @param {object} pProps Objeto contendo atributos
|
|
125
135
|
* {
|
|
126
136
|
* url:string (URL do request),
|
|
@@ -138,7 +148,6 @@ const httpRequests = {
|
|
|
138
148
|
/**
|
|
139
149
|
*Request PUT
|
|
140
150
|
*
|
|
141
|
-
* @param {string} pMethod
|
|
142
151
|
* @param {object} pProps Objeto contendo atributos
|
|
143
152
|
* {
|
|
144
153
|
* url:string (URL do request),
|
|
@@ -156,7 +165,6 @@ const httpRequests = {
|
|
|
156
165
|
/**
|
|
157
166
|
*Request DELETE
|
|
158
167
|
*
|
|
159
|
-
* @param {string} pMethod
|
|
160
168
|
* @param {object} pProps Objeto contendo atributos
|
|
161
169
|
* {
|
|
162
170
|
* url:string (URL do request),
|
|
@@ -174,7 +182,6 @@ const httpRequests = {
|
|
|
174
182
|
/**
|
|
175
183
|
*Request PACTH
|
|
176
184
|
*
|
|
177
|
-
* @param {string} pMethod
|
|
178
185
|
* @param {object} pProps Objeto contendo atributos
|
|
179
186
|
* {
|
|
180
187
|
* url:string (URL do request),
|
|
@@ -272,6 +279,54 @@ const httpRequests = {
|
|
|
272
279
|
cancelToken: () => {
|
|
273
280
|
// @ts-ignore
|
|
274
281
|
return axios.CancelToken.source();
|
|
282
|
+
},
|
|
283
|
+
/**
|
|
284
|
+
* Upload de arquivos
|
|
285
|
+
*
|
|
286
|
+
* @param {Object} pOptions Objeto contendo atributos.
|
|
287
|
+
* - url: Url destino do upload
|
|
288
|
+
* - files: array com o caminho completo de cada arquivo
|
|
289
|
+
* - fields: objeto com os atributos a serem enviados
|
|
290
|
+
* - cancel: função para cancelar upload anterior
|
|
291
|
+
* - accessToken: Bearer token de acesso
|
|
292
|
+
* @return {promise}
|
|
293
|
+
*/
|
|
294
|
+
upload: function (pOptions) {
|
|
295
|
+
const { url, files, fields, cancel } = pOptions;
|
|
296
|
+
if (!url || !files || files.length === 0) {
|
|
297
|
+
return Promise.resolve();
|
|
298
|
+
}
|
|
299
|
+
if (cancel) {
|
|
300
|
+
//Cancela upload anterior
|
|
301
|
+
cancel();
|
|
302
|
+
}
|
|
303
|
+
const xCancel = httpRequests.cancelToken();
|
|
304
|
+
//Salva função para cancelar upload
|
|
305
|
+
pOptions.cancel = xCancel.cancel;
|
|
306
|
+
//Cria novo FormData
|
|
307
|
+
const xFormData = new FormData();
|
|
308
|
+
//Adiciona arquivos ao FormData
|
|
309
|
+
files.forEach((xFilename, xIndex) => {
|
|
310
|
+
xFormData.append(`file-${xIndex}`, fs.createReadStream(xFilename));
|
|
311
|
+
});
|
|
312
|
+
//Adiciona campos ao FormData
|
|
313
|
+
for (const xFieldName in fields) {
|
|
314
|
+
xFormData.append(xFieldName, fields[xFieldName]);
|
|
315
|
+
}
|
|
316
|
+
//Configura propriedades do request/upload
|
|
317
|
+
const xProps = {
|
|
318
|
+
url,
|
|
319
|
+
headers: {
|
|
320
|
+
'Content-Type': xFormData.getHeaders()
|
|
321
|
+
},
|
|
322
|
+
data: xFormData
|
|
323
|
+
};
|
|
324
|
+
//Configura token de acesso
|
|
325
|
+
if (pOptions.accessToken) {
|
|
326
|
+
xProps.headers.Authorization = `Bearer ${pOptions.accessToken}`;
|
|
327
|
+
}
|
|
328
|
+
//Executa upload
|
|
329
|
+
return httpRequests.requestPOST(xProps);
|
|
275
330
|
}
|
|
276
331
|
};
|
|
277
332
|
|
package/lib/utils/strings.js
CHANGED
|
@@ -108,7 +108,7 @@ const strings = {
|
|
|
108
108
|
return pString;
|
|
109
109
|
}
|
|
110
110
|
if (!isString(pString)) {
|
|
111
|
-
throw new InvalidData('[
|
|
111
|
+
throw new InvalidData('[string.toTitleCase] is not a string [' + JSON.stringify(pString) + ']');
|
|
112
112
|
}
|
|
113
113
|
let xString = pvtoTitleCase(pString);
|
|
114
114
|
for (const xSepatator of toTitleCaseSeparators) {
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "investira.sdk",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.13",
|
|
4
4
|
"author": "Investira",
|
|
5
5
|
"description": "Investira SDK",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"type": "commonjs",
|
|
8
8
|
"registry": true,
|
|
9
|
-
"raw": "investira.sdk@2.3.
|
|
9
|
+
"raw": "investira.sdk@2.3.13",
|
|
10
10
|
"escapedName": "investira.sdk",
|
|
11
|
-
"rawSpec": "2.3.
|
|
11
|
+
"rawSpec": "2.3.13",
|
|
12
12
|
"saveSpec": null,
|
|
13
|
-
"fetchSpec": "2.3.
|
|
13
|
+
"fetchSpec": "2.3.13",
|
|
14
14
|
"homepage": "https://investira.com.br/",
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=11.11.0 <=18.12",
|
|
@@ -35,14 +35,14 @@
|
|
|
35
35
|
"_test": "nodemon ./_tests/test"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"axios": "
|
|
38
|
+
"axios": "1.5.1",
|
|
39
39
|
"deep-diff": "1.0.2",
|
|
40
|
-
"flatted": "3.2.
|
|
41
|
-
"investira.data": "^1.3.
|
|
40
|
+
"flatted": "3.2.9",
|
|
41
|
+
"investira.data": "^1.3.1",
|
|
42
42
|
"moment": "^2.29.4"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"tape": "^4.
|
|
45
|
+
"tape": "^4.17.0"
|
|
46
46
|
},
|
|
47
47
|
"jshintConfig": {
|
|
48
48
|
"curly": true,
|