@vouchfor/sdk 1.1.6 → 1.1.8
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/lib/services/rest/fileService.js +11 -4
- package/lib/shared/utils.js +3 -1
- package/package.json +1 -1
- package/test.js +1 -0
|
@@ -9,11 +9,12 @@ class FileService extends BaseRestService {
|
|
|
9
9
|
super(client, config, 'files');
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
upload(file, key, apiKey) {
|
|
12
|
+
upload(file, key, apiKey, { extract } = {}) {
|
|
13
13
|
const input = fs.createReadStream(file);
|
|
14
14
|
const form = new FormData();
|
|
15
15
|
form.append('title', key);
|
|
16
16
|
form.append('file', input);
|
|
17
|
+
form.append('extract', !!extract);
|
|
17
18
|
return this._request({
|
|
18
19
|
apiKey,
|
|
19
20
|
body: form,
|
|
@@ -26,10 +27,11 @@ class FileService extends BaseRestService {
|
|
|
26
27
|
// this is what the function should look like
|
|
27
28
|
// but there is an error proxying the data at
|
|
28
29
|
// the moment, I have added a work around
|
|
29
|
-
proxy(url, key, apiKey) {
|
|
30
|
+
proxy(url, key, apiKey, { extract, headers } = {}) {
|
|
30
31
|
return axios({
|
|
31
32
|
method: 'GET',
|
|
32
33
|
url,
|
|
34
|
+
headers,
|
|
33
35
|
responseType: 'stream',
|
|
34
36
|
maxContentLength: Infinity,
|
|
35
37
|
maxBodyLength: Infinity,
|
|
@@ -37,6 +39,7 @@ class FileService extends BaseRestService {
|
|
|
37
39
|
const form = new FormData();
|
|
38
40
|
form.append('title', key);
|
|
39
41
|
form.append('file', resp.data);
|
|
42
|
+
form.append('extract', !!extract);
|
|
40
43
|
return this._request({
|
|
41
44
|
apiKey,
|
|
42
45
|
body: form,
|
|
@@ -47,10 +50,14 @@ class FileService extends BaseRestService {
|
|
|
47
50
|
}
|
|
48
51
|
///////////////////////////////////////////*/
|
|
49
52
|
|
|
50
|
-
proxy(url, key, apiKey) {
|
|
53
|
+
proxy(url, key, apiKey, { extract, headers } = {}) {
|
|
51
54
|
return this._request({
|
|
52
55
|
apiKey,
|
|
53
|
-
body: {
|
|
56
|
+
body: {
|
|
57
|
+
url,
|
|
58
|
+
extract,
|
|
59
|
+
headers
|
|
60
|
+
},
|
|
54
61
|
path: key
|
|
55
62
|
});
|
|
56
63
|
}
|
package/lib/shared/utils.js
CHANGED
|
@@ -36,7 +36,9 @@ module.exports = {
|
|
|
36
36
|
reject(error);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
const
|
|
39
|
+
const type = res.headers['content-type'] ?? 'application/json';
|
|
40
|
+
const json = type.indexOf('application/json') !== -1;
|
|
41
|
+
const data = !!result && json ? JSON.parse(result) : result;
|
|
40
42
|
resolve(data);
|
|
41
43
|
} catch (err) {
|
|
42
44
|
reject(err);
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -7,6 +7,7 @@ const vouchClient = new Vouch({
|
|
|
7
7
|
|
|
8
8
|
(async () => {
|
|
9
9
|
const response = await vouchClient.integrations.applications.list();
|
|
10
|
+
console.log(typeof response);
|
|
10
11
|
const items = await response.applications.reduce(async (ac, application) => {
|
|
11
12
|
const arr = await ac;
|
|
12
13
|
console.log(`id => ${application.id}`);
|