@vouchfor/sdk 1.1.28 → 1.1.30
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/index.js +3 -0
- package/lib/services/rest/accountService.js +21 -0
- package/lib/services/rest/campaignService.js +43 -6
- package/lib/services/rest/compositionService.js +52 -0
- package/lib/services/rest/entityService.js +8 -8
- package/lib/services/rest/fileService.js +4 -2
- package/lib/services/rest/playlistService.js +51 -0
- package/lib/services/rest/vouchService.js +20 -16
- package/lib/shared/utils.js +18 -5
- package/package.json +1 -1
- package/test-accounts.js +16 -0
- package/test-compositions.js +14 -0
- package/test-upload.js +17 -0
package/lib/services/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
module.exports = Object.freeze({
|
|
2
|
+
accounts: require('./rest/accountService'),
|
|
2
3
|
answers: require('./rest/answerService'),
|
|
3
4
|
assets: require('./rest/assetService'),
|
|
4
5
|
applications: require('./rest/applicationService'),
|
|
@@ -6,6 +7,8 @@ module.exports = Object.freeze({
|
|
|
6
7
|
entities: require('./rest/entityService'),
|
|
7
8
|
integrations: require('./integration/integrationService'),
|
|
8
9
|
vouches: require('./rest/vouchService'),
|
|
10
|
+
playlists: require('./rest/playlistService'),
|
|
11
|
+
compositions: require('./rest/compositionService'),
|
|
9
12
|
files: require('./rest/fileService'),
|
|
10
13
|
advocacy: require('./rest/advocacyService'),
|
|
11
14
|
utilities: require('./rest/utilityService'),
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const BaseRestService = require('./base');
|
|
2
|
+
|
|
3
|
+
class CompositionService extends BaseRestService {
|
|
4
|
+
constructor(client, config, logger) {
|
|
5
|
+
super(client, config, 'accounts', logger);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
get(id, apiKey, opts = {}) {
|
|
9
|
+
return this._request({
|
|
10
|
+
apiKey,
|
|
11
|
+
path: `${id}`+ this._utils.queryString(opts)
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
list(apiKey) {
|
|
16
|
+
return this._request({ apiKey, path: '' });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = CompositionService;
|
|
21
|
+
|
|
@@ -5,24 +5,31 @@ class CampaignService extends BaseRestService {
|
|
|
5
5
|
super(client, config, 'campaigns', logger);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
create(
|
|
8
|
+
create(payload, apiKey) {
|
|
9
9
|
return this._request({
|
|
10
10
|
apiKey,
|
|
11
|
-
body:
|
|
11
|
+
body: payload,
|
|
12
12
|
path: '',
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
update(id,
|
|
16
|
+
update(id, payload, apiKey) {
|
|
17
17
|
return this._request({
|
|
18
18
|
apiKey,
|
|
19
|
-
body:
|
|
19
|
+
body: payload,
|
|
20
20
|
path: `${id}`
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
get(id, apiKey) {
|
|
25
|
-
return this._request({
|
|
24
|
+
get(id, apiKey, opts = {}) {
|
|
25
|
+
return this._request({
|
|
26
|
+
apiKey,
|
|
27
|
+
path: `${id}`+ this._utils.queryString(opts)
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
delete(id, apiKey) {
|
|
32
|
+
return this._request({ apiKey, path: `${id}/delete` });
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
list(apiKey) {
|
|
@@ -36,6 +43,22 @@ class CampaignService extends BaseRestService {
|
|
|
36
43
|
});
|
|
37
44
|
}
|
|
38
45
|
|
|
46
|
+
counts(id, apiKey) {
|
|
47
|
+
return this._request({ apiKey, path: `${id}/counts` });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
status(id, apiKey) {
|
|
51
|
+
return this._request({ apiKey, path: `${id}/status` });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
publish(id, apiKey) {
|
|
55
|
+
return this._request({ apiKey, path: `${id}/publish` });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
pause(id, apiKey) {
|
|
59
|
+
return this._request({ apiKey, path: `${id}/pause` });
|
|
60
|
+
}
|
|
61
|
+
|
|
39
62
|
vouches(id, apiKey, opts = {}) {
|
|
40
63
|
return this._request({
|
|
41
64
|
apiKey,
|
|
@@ -43,6 +66,20 @@ class CampaignService extends BaseRestService {
|
|
|
43
66
|
});
|
|
44
67
|
}
|
|
45
68
|
|
|
69
|
+
responses(id, apiKey, opts = {}) {
|
|
70
|
+
return this._request({
|
|
71
|
+
apiKey,
|
|
72
|
+
path: `${id}/responses` + this._utils.queryString(opts)
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
keywords(id, apiKey, opts = {}) {
|
|
77
|
+
return this._request({
|
|
78
|
+
apiKey,
|
|
79
|
+
path: `${id}/keywords` + this._utils.queryString(opts)
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
46
83
|
convert(id, params, apiKey) {
|
|
47
84
|
return this._request({
|
|
48
85
|
apiKey,
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const BaseRestService = require('./base');
|
|
2
|
+
|
|
3
|
+
class CompositionService extends BaseRestService {
|
|
4
|
+
constructor(client, config, logger) {
|
|
5
|
+
super(client, config, 'compositions', logger);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
create(payload, apiKey) {
|
|
9
|
+
return this._request({
|
|
10
|
+
apiKey,
|
|
11
|
+
body: payload,
|
|
12
|
+
path: '',
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
update(id, payload, apiKey) {
|
|
17
|
+
return this._request({
|
|
18
|
+
apiKey,
|
|
19
|
+
body: payload,
|
|
20
|
+
path: `${id}`
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get(id, apiKey, opts = {}) {
|
|
25
|
+
return this._request({
|
|
26
|
+
apiKey,
|
|
27
|
+
path: `${id}`+ this._utils.queryString(opts)
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
delete(id, apiKey) {
|
|
32
|
+
return this._request({ apiKey, path: `${id}/delete` });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
list(apiKey) {
|
|
36
|
+
return this._request({ apiKey, path: '' });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
search(params = {}, apiKey) {
|
|
40
|
+
return this._request({
|
|
41
|
+
apiKey,
|
|
42
|
+
path: 'search' + this._utils.queryString(params)
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
counts(id, apiKey) {
|
|
47
|
+
return this._request({ apiKey, path: `${id}/counts` });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = CompositionService;
|
|
52
|
+
|
|
@@ -37,6 +37,14 @@ class EntityService extends BaseRestService {
|
|
|
37
37
|
return this._request({ apiKey, path: `${id}/brand` });
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
tags(id, apiKey) {
|
|
41
|
+
return this._request({ apiKey, path: `${id}/tags` });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
templates(id, apiKey) {
|
|
45
|
+
return this._request({ apiKey, path: `${id}/templates` });
|
|
46
|
+
}
|
|
47
|
+
|
|
40
48
|
users(id, apiKey) {
|
|
41
49
|
return this._request({ apiKey, path: `${id}/users` });
|
|
42
50
|
}
|
|
@@ -48,14 +56,6 @@ class EntityService extends BaseRestService {
|
|
|
48
56
|
path: `${id}/quotes`
|
|
49
57
|
});
|
|
50
58
|
}
|
|
51
|
-
|
|
52
|
-
video(id, params, apiKey) {
|
|
53
|
-
return this._request({
|
|
54
|
-
apiKey,
|
|
55
|
-
body: params,
|
|
56
|
-
path: `${id}/video`
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
module.exports = EntityService;
|
|
@@ -13,12 +13,13 @@ class FileService extends BaseRestService {
|
|
|
13
13
|
return this._request({ apiKey, path: `${id}` });
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
upload(file, key, apiKey, { extract } = {}) {
|
|
16
|
+
upload(file, key, apiKey, { extract, extname } = {}) {
|
|
17
17
|
const input = fs.createReadStream(file);
|
|
18
18
|
const form = new FormData();
|
|
19
19
|
form.append('title', key);
|
|
20
20
|
form.append('file', input);
|
|
21
21
|
form.append('extract', !!extract);
|
|
22
|
+
form.append('extname', !!extname);
|
|
22
23
|
return this._request({
|
|
23
24
|
apiKey,
|
|
24
25
|
body: form,
|
|
@@ -54,12 +55,13 @@ class FileService extends BaseRestService {
|
|
|
54
55
|
}
|
|
55
56
|
///////////////////////////////////////////*/
|
|
56
57
|
|
|
57
|
-
proxy(url, key, apiKey, { extract, headers } = {}) {
|
|
58
|
+
proxy(url, key, apiKey, { extract, extname, headers } = {}) {
|
|
58
59
|
return this._request({
|
|
59
60
|
apiKey,
|
|
60
61
|
body: {
|
|
61
62
|
url,
|
|
62
63
|
extract,
|
|
64
|
+
extname,
|
|
63
65
|
headers
|
|
64
66
|
},
|
|
65
67
|
path: key
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const BaseRestService = require('./base');
|
|
2
|
+
|
|
3
|
+
class PlaylistService extends BaseRestService {
|
|
4
|
+
constructor(client, config, logger) {
|
|
5
|
+
super(client, config, 'playlists', logger);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
create(payload, apiKey) {
|
|
9
|
+
return this._request({
|
|
10
|
+
apiKey,
|
|
11
|
+
body: payload,
|
|
12
|
+
path: '',
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
update(id, payload, apiKey) {
|
|
17
|
+
return this._request({
|
|
18
|
+
apiKey,
|
|
19
|
+
body: payload,
|
|
20
|
+
path: `${id}`
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get(id, apiKey, opts = {}) {
|
|
25
|
+
return this._request({
|
|
26
|
+
apiKey,
|
|
27
|
+
path: `${id}`+ this._utils.queryString(opts)
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
delete(id, apiKey) {
|
|
32
|
+
return this._request({ apiKey, path: `${id}/delete` });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
list(apiKey) {
|
|
36
|
+
return this._request({ apiKey, path: '' });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
search(params = {}, apiKey) {
|
|
40
|
+
return this._request({
|
|
41
|
+
apiKey,
|
|
42
|
+
path: 'search' + this._utils.queryString(params)
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
counts(id, apiKey) {
|
|
47
|
+
return this._request({ apiKey, path: `${id}/counts` });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = PlaylistService;
|
|
@@ -5,18 +5,18 @@ class VouchService extends BaseRestService {
|
|
|
5
5
|
super(client, config, 'vouches', logger);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
create(
|
|
8
|
+
create(payload, apiKey) {
|
|
9
9
|
return this._request({
|
|
10
10
|
apiKey,
|
|
11
|
-
body:
|
|
11
|
+
body: payload,
|
|
12
12
|
path: '',
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
update(id,
|
|
16
|
+
update(id, payload, apiKey) {
|
|
17
17
|
return this._request({
|
|
18
18
|
apiKey,
|
|
19
|
-
body:
|
|
19
|
+
body: payload,
|
|
20
20
|
path: `${id}`
|
|
21
21
|
});
|
|
22
22
|
}
|
|
@@ -28,12 +28,8 @@ class VouchService extends BaseRestService {
|
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
return this._request({ apiKey, path: `${id}/
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
status(id, apiKey) {
|
|
36
|
-
return this._request({ apiKey, path: `${id}/status` });
|
|
31
|
+
delete(id, apiKey) {
|
|
32
|
+
return this._request({ apiKey, path: `${id}/delete` });
|
|
37
33
|
}
|
|
38
34
|
|
|
39
35
|
list(apiKey) {
|
|
@@ -47,10 +43,18 @@ class VouchService extends BaseRestService {
|
|
|
47
43
|
});
|
|
48
44
|
}
|
|
49
45
|
|
|
50
|
-
|
|
46
|
+
counts(id, apiKey) {
|
|
47
|
+
return this._request({ apiKey, path: `${id}/counts` });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
status(id, apiKey) {
|
|
51
|
+
return this._request({ apiKey, path: `${id}/status` });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
upload(payload, apiKey) {
|
|
51
55
|
return this._request({
|
|
52
56
|
apiKey,
|
|
53
|
-
body:
|
|
57
|
+
body: payload,
|
|
54
58
|
path: 'upload',
|
|
55
59
|
});
|
|
56
60
|
}
|
|
@@ -63,20 +67,20 @@ class VouchService extends BaseRestService {
|
|
|
63
67
|
}
|
|
64
68
|
|
|
65
69
|
return {
|
|
66
|
-
create: (
|
|
70
|
+
create: (payload, { id, ordinality }, apiKey) => {
|
|
67
71
|
const path = getPath(id, ordinality);
|
|
68
72
|
return this._request({
|
|
69
73
|
apiKey,
|
|
70
|
-
body:
|
|
74
|
+
body: payload,
|
|
71
75
|
path
|
|
72
76
|
});
|
|
73
77
|
},
|
|
74
78
|
|
|
75
|
-
delete: (
|
|
79
|
+
delete: (payload, { id, ordinality }, apiKey) => {
|
|
76
80
|
const path = getPath(id, ordinality);
|
|
77
81
|
return this._request({
|
|
78
82
|
apiKey,
|
|
79
|
-
body:
|
|
83
|
+
body: payload,
|
|
80
84
|
path: `${path}/delete`
|
|
81
85
|
});
|
|
82
86
|
},
|
package/lib/shared/utils.js
CHANGED
|
@@ -82,7 +82,7 @@ module.exports = {
|
|
|
82
82
|
).toString();
|
|
83
83
|
return query ? `?${query}` : '';
|
|
84
84
|
},
|
|
85
|
-
request({ body, headers, method, url, logger }) {
|
|
85
|
+
request({ body, headers, method, url, logger }, attempt = 1) {
|
|
86
86
|
const { protocol, hostname, port, pathname, search = '' } = new URL(url);
|
|
87
87
|
|
|
88
88
|
return new Promise((resolve, reject) => {
|
|
@@ -100,27 +100,40 @@ module.exports = {
|
|
|
100
100
|
res.on('data', (chunk) => {
|
|
101
101
|
result += chunk;
|
|
102
102
|
});
|
|
103
|
-
res.on('end', () => {
|
|
103
|
+
res.on('end', async () => {
|
|
104
104
|
try {
|
|
105
105
|
if (logger) {
|
|
106
106
|
logHttpResponse({ req, res, body, result, start, logger });
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
const errors = [
|
|
110
|
+
502, // bad gateway, the BE is deploying
|
|
111
|
+
504, // gatewat timeout, the BE will scale
|
|
112
|
+
];
|
|
113
|
+
const maxAttempts = 8;
|
|
114
|
+
const interval = 1000;
|
|
115
|
+
if (attempt < maxAttempts && errors.includes(res.statusCode)) {
|
|
116
|
+
await new Promise((resolve) => setTimeout(resolve, interval * attempt));
|
|
117
|
+
return resolve(
|
|
118
|
+
this.request({ body, headers, method, url, logger }, attempt + 1)
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
109
122
|
if (res.statusCode >= 400) {
|
|
110
123
|
let error = res.statusMessage || 'error';
|
|
111
124
|
try {
|
|
112
125
|
error = JSON.parse(result)?.error || error;
|
|
113
126
|
} catch (_) {}
|
|
114
127
|
|
|
115
|
-
reject(error);
|
|
128
|
+
return reject(error);
|
|
116
129
|
}
|
|
117
130
|
|
|
118
131
|
const type = res.headers['content-type'] ?? 'application/json';
|
|
119
132
|
const json = type.indexOf('application/json') !== -1;
|
|
120
133
|
const data = !!result && json ? JSON.parse(result) : result;
|
|
121
|
-
resolve(data);
|
|
134
|
+
return resolve(data);
|
|
122
135
|
} catch (err) {
|
|
123
|
-
reject(err);
|
|
136
|
+
return reject(err);
|
|
124
137
|
}
|
|
125
138
|
});
|
|
126
139
|
},
|
package/package.json
CHANGED
package/test-accounts.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const Vouch = require("./lib/vouch");
|
|
2
|
+
|
|
3
|
+
const vouchClient = new Vouch({
|
|
4
|
+
env: 'dev',
|
|
5
|
+
integrationKey: 'b0883f06-84af-4108-8543-31874c335c36-kkr3Wy4CLY8C2g65UT79sgUfOIR2ZzkA9uQam3bTs4ZNdlSs7M',
|
|
6
|
+
}, console);
|
|
7
|
+
|
|
8
|
+
const apiKey = 'kTYGShoaeg-QvraTZk9LmHNsxP4dWcye82uJB6Rf0XtIsgq7UaEcYpVhMDl3z';
|
|
9
|
+
const id = 'WncEfS4KgY';
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
const accounts = await vouchClient.accounts.list(apiKey).catch(() => undefined);
|
|
13
|
+
console.log(accounts);
|
|
14
|
+
const account = await vouchClient.accounts.get(id, apiKey).catch(() => undefined);
|
|
15
|
+
console.log(account);
|
|
16
|
+
})();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const Vouch = require("./lib/vouch");
|
|
2
|
+
|
|
3
|
+
const vouchClient = new Vouch({
|
|
4
|
+
env: 'dev',
|
|
5
|
+
integrationKey: 'b0883f06-84af-4108-8543-31874c335c36-kkr3Wy4CLY8C2g65UT79sgUfOIR2ZzkA9uQam3bTs4ZNdlSs7M',
|
|
6
|
+
}, console);
|
|
7
|
+
|
|
8
|
+
const apiKey = 'kTYGShoaeg-QvraTZk9LmHNsxP4dWcye82uJB6Rf0XtIsgq7UaEcYpVhMDl3z';
|
|
9
|
+
|
|
10
|
+
(async () => {
|
|
11
|
+
const data = await vouchClient.compositions.get('fMMsKxK9Ic', apiKey).catch(() => undefined);
|
|
12
|
+
console.log(data);
|
|
13
|
+
})();
|
|
14
|
+
|
package/test-upload.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const Vouch = require("./lib/vouch");
|
|
2
|
+
|
|
3
|
+
const vouchClient = new Vouch({
|
|
4
|
+
env: 'dev',
|
|
5
|
+
integrationKey: 'b0883f06-84af-4108-8543-31874c335c36-kkr3Wy4CLY8C2g65UT79sgUfOIR2ZzkA9uQam3bTs4ZNdlSs7M',
|
|
6
|
+
}, console);
|
|
7
|
+
|
|
8
|
+
const apiKey = 'kTYGShoaeg-QvraTZk9LmHNsxP4dWcye82uJB6Rf0XtIsgq7UaEcYpVhMDl3z';
|
|
9
|
+
const url = 'https://examplefiles.org/files/video/mp4-example-video-download-640x480.mp4'
|
|
10
|
+
const key1 = 'delete/file_example_MP4_480_1_5MG.mp4';
|
|
11
|
+
const key2 = 'delete/file_example_MP4_480_1_EXT';
|
|
12
|
+
|
|
13
|
+
(async () => {
|
|
14
|
+
const result = await vouchClient.files.proxy(url, key1, apiKey, { extract: true, extname: true }).catch(() => undefined);
|
|
15
|
+
console.log(result);
|
|
16
|
+
})();
|
|
17
|
+
|