@vouchfor/sdk 1.1.4 → 1.1.6

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.
@@ -13,27 +13,29 @@ class BaseService {
13
13
  async _callApi({
14
14
  apiKey = '',
15
15
  integrationKey = '',
16
+ headers,
16
17
  method,
17
18
  body,
18
19
  url,
19
20
  }) {
20
- const headers = {
21
+ const apiHeaders = {
21
22
  Accept: 'application/json',
22
23
  'Content-Type': 'application/json',
23
24
  'x-api-key': apiKey,
25
+ ...headers
24
26
  };
25
27
 
26
28
  if (integrationKey) {
27
- headers['x-integration-key'] = integrationKey;
29
+ apiHeaders['x-integration-key'] = integrationKey;
28
30
  }
29
31
 
30
32
  return utils.request({
31
33
  body,
32
- headers,
34
+ headers: apiHeaders,
33
35
  method,
34
36
  url,
35
37
  });
36
38
  }
37
39
  }
38
40
 
39
- module.exports = BaseService;
41
+ module.exports = BaseService;
@@ -4,4 +4,5 @@ module.exports = Object.freeze({
4
4
  entities: require('./rest/entityService'),
5
5
  integrations: require('./integration/integrationService'),
6
6
  vouches: require('./rest/vouchService'),
7
- });
7
+ files: require('./rest/fileService'),
8
+ });
@@ -12,15 +12,16 @@ class BaseRestService extends BaseService {
12
12
  });
13
13
  }
14
14
 
15
- _request({ apiKey, body, method, path }) {
15
+ _request({ apiKey, body, method, path, headers }) {
16
16
  return this._callApi({
17
17
  apiKey: apiKey || this._apiKey,
18
18
  integrationKey: this._integrationKey,
19
19
  body,
20
+ headers,
20
21
  method,
21
22
  url: `${this._baseUrl}/${path}`,
22
23
  });
23
24
  }
24
25
  }
25
26
 
26
- module.exports = BaseRestService;
27
+ module.exports = BaseRestService;
@@ -0,0 +1,59 @@
1
+ const fs = require('fs');
2
+ const FormData = require('form-data');
3
+ const axios = require('axios');
4
+
5
+ const BaseRestService = require('./base');
6
+
7
+ class FileService extends BaseRestService {
8
+ constructor(client, config) {
9
+ super(client, config, 'files');
10
+ }
11
+
12
+ upload(file, key, apiKey) {
13
+ const input = fs.createReadStream(file);
14
+ const form = new FormData();
15
+ form.append('title', key);
16
+ form.append('file', input);
17
+ return this._request({
18
+ apiKey,
19
+ body: form,
20
+ path: key,
21
+ headers: form.getHeaders(),
22
+ });
23
+ }
24
+
25
+ /*///////////////////////////////////////////
26
+ // this is what the function should look like
27
+ // but there is an error proxying the data at
28
+ // the moment, I have added a work around
29
+ proxy(url, key, apiKey) {
30
+ return axios({
31
+ method: 'GET',
32
+ url,
33
+ responseType: 'stream',
34
+ maxContentLength: Infinity,
35
+ maxBodyLength: Infinity,
36
+ }).then(resp => {
37
+ const form = new FormData();
38
+ form.append('title', key);
39
+ form.append('file', resp.data);
40
+ return this._request({
41
+ apiKey,
42
+ body: form,
43
+ path: key,
44
+ headers: form.getHeaders(),
45
+ });
46
+ })
47
+ }
48
+ ///////////////////////////////////////////*/
49
+
50
+ proxy(url, key, apiKey) {
51
+ return this._request({
52
+ apiKey,
53
+ body: { url },
54
+ path: key
55
+ });
56
+ }
57
+ }
58
+
59
+ module.exports = FileService;
@@ -25,6 +25,14 @@ class VouchService extends BaseRestService {
25
25
  return this._request({ apiKey, path: `${id}` });
26
26
  }
27
27
 
28
+ counts(id, apiKey) {
29
+ return this._request({ apiKey, path: `${id}/counts` });
30
+ }
31
+
32
+ status(id, apiKey) {
33
+ return this._request({ apiKey, path: `${id}/status` });
34
+ }
35
+
28
36
  list(apiKey) {
29
37
  return this._request({ apiKey, path: '' });
30
38
  }
@@ -36,6 +44,39 @@ class VouchService extends BaseRestService {
36
44
  path: 'upload',
37
45
  });
38
46
  }
47
+
48
+ get clips() {
49
+ function getPath(id, ordinality) {
50
+ return ordinality
51
+ ? `${id}/questions/${ordinality}/clips`
52
+ : `${id}/clips`;
53
+ }
54
+
55
+ return {
56
+ create: (clips, { id, ordinality }, apiKey) => {
57
+ const path = getPath(id, ordinality);
58
+ return this._request({
59
+ apiKey,
60
+ body: clips,
61
+ path
62
+ });
63
+ },
64
+
65
+ delete: (clips, { id, ordinality }, apiKey) => {
66
+ const path = getPath(id, ordinality);
67
+ return this._request({
68
+ apiKey,
69
+ body: clips,
70
+ path: `${path}/delete`
71
+ });
72
+ },
73
+
74
+ list: ({ id, ordinality }, apiKey) => {
75
+ const path = getPath(id, ordinality);
76
+ return this._request({ apiKey, path });
77
+ }
78
+ }
79
+ }
39
80
  }
40
81
 
41
- module.exports = VouchService;
82
+ module.exports = VouchService;
@@ -1,4 +1,8 @@
1
- const https = require('https');
1
+ const followRedirects = require('follow-redirects');
2
+ const { https } = followRedirects;
3
+
4
+ followRedirects.maxRedirects = 10;
5
+ followRedirects.maxBodyLength = Infinity;
2
6
 
3
7
  module.exports = {
4
8
  getApiSuffix(env = 'prod') {
@@ -43,10 +47,14 @@ module.exports = {
43
47
  .on('error', (err) => {
44
48
  reject(err);
45
49
  });
46
- if (body) {
47
- req.write(JSON.stringify(body));
50
+ if (typeof body?.pipe === 'function') {
51
+ body.pipe(req);
52
+ } else {
53
+ if (body) {
54
+ req.write(JSON.stringify(body));
55
+ }
56
+ req.end();
48
57
  }
49
- req.end();
50
- })
58
+ });
51
59
  }
52
- }
60
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vouchfor/sdk",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "Vouch API SDK",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -16,8 +16,11 @@
16
16
  "directories": {
17
17
  "lib": "lib"
18
18
  },
19
- "dependencies": {},
20
- "devDependencies": {},
19
+ "dependencies": {
20
+ "axios": "^1.6.2",
21
+ "follow-redirects": "^1.15.3",
22
+ "form-data": "^4.0.0"
23
+ },
21
24
  "scripts": {
22
25
  "test": "echo \"Error: no test specified\" && exit 1"
23
26
  }