@vouchfor/sdk 1.1.27 → 1.1.29

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.
@@ -27,6 +27,7 @@ class BaseService {
27
27
  this._integrationKey = config.integrationKey || '';
28
28
  this._baseUrl = `${config.baseUrl}${basePath}`;
29
29
  this._logger = logger;
30
+ this._utils = utils;
30
31
  }
31
32
 
32
33
  async _callApi({
@@ -48,7 +49,7 @@ class BaseService {
48
49
  apiHeaders['x-integration-key'] = integrationKey;
49
50
  }
50
51
 
51
- return utils.request({
52
+ return this._utils.request({
52
53
  body,
53
54
  headers: apiHeaders,
54
55
  method,
@@ -1,9 +1,14 @@
1
1
  module.exports = Object.freeze({
2
+ accounts: require('./rest/accountService'),
3
+ answers: require('./rest/answerService'),
4
+ assets: require('./rest/assetService'),
2
5
  applications: require('./rest/applicationService'),
3
6
  campaigns: require('./rest/campaignService'),
4
7
  entities: require('./rest/entityService'),
5
8
  integrations: require('./integration/integrationService'),
6
9
  vouches: require('./rest/vouchService'),
10
+ playlists: require('./rest/playlistService'),
11
+ compositions: require('./rest/compositionService'),
7
12
  files: require('./rest/fileService'),
8
13
  advocacy: require('./rest/advocacyService'),
9
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
+
@@ -7,7 +7,7 @@ class AdvocacyService extends BaseRestService {
7
7
  this.requests = new AdvocacyRequestService(client, config, logger);
8
8
  }
9
9
 
10
- // advocacy has not methods yet
10
+ // advocacy has no methods yet
11
11
  }
12
12
 
13
13
  module.exports = AdvocacyService;
@@ -0,0 +1,16 @@
1
+ const BaseRestService = require('./base');
2
+
3
+ class AnswerService extends BaseRestService {
4
+ constructor(client, config, logger) {
5
+ super(client, config, 'answers', logger);
6
+ }
7
+
8
+ search(params, apiKey) {
9
+ return this._request({
10
+ apiKey,
11
+ path: '' + this._utils.queryString(params)
12
+ });
13
+ }
14
+ }
15
+
16
+ module.exports = AnswerService;
@@ -0,0 +1,16 @@
1
+ const BaseRestService = require('./base');
2
+
3
+ class AssetService extends BaseRestService {
4
+ constructor(client, config, logger) {
5
+ super(client, config, 'assets', logger);
6
+ }
7
+
8
+ search(params, apiKey) {
9
+ return this._request({
10
+ apiKey,
11
+ path: '' + this._utils.queryString(params)
12
+ });
13
+ }
14
+ }
15
+
16
+ module.exports = AssetService;
@@ -5,32 +5,73 @@ class CampaignService extends BaseRestService {
5
5
  super(client, config, 'campaigns', logger);
6
6
  }
7
7
 
8
- create(campaign, apiKey) {
8
+ create(payload, apiKey) {
9
9
  return this._request({
10
10
  apiKey,
11
- body: campaign,
11
+ body: payload,
12
12
  path: '',
13
13
  });
14
14
  }
15
15
 
16
- update(id, update, apiKey) {
16
+ update(id, payload, apiKey) {
17
17
  return this._request({
18
18
  apiKey,
19
- body: update,
19
+ body: payload,
20
20
  path: `${id}`
21
21
  });
22
22
  }
23
23
 
24
- get(id, apiKey) {
25
- return this._request({ apiKey, path: `${id}` });
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) {
29
36
  return this._request({ apiKey, path: '' });
30
37
  }
31
38
 
32
- vouches(id, apiKey) {
33
- return this._request({ apiKey, path: `${id}/vouches` });
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
+ 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
+
62
+ vouches(id, apiKey, opts = {}) {
63
+ return this._request({
64
+ apiKey,
65
+ path: `${id}/vouches` + this._utils.queryString(opts)
66
+ });
67
+ }
68
+
69
+ convert(id, params, apiKey) {
70
+ return this._request({
71
+ apiKey,
72
+ body: params,
73
+ path: `${id}/vouch`
74
+ });
34
75
  }
35
76
  }
36
77
 
@@ -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
+
@@ -40,6 +40,14 @@ class EntityService extends BaseRestService {
40
40
  users(id, apiKey) {
41
41
  return this._request({ apiKey, path: `${id}/users` });
42
42
  }
43
+
44
+ quotes(id, params, apiKey) {
45
+ return this._request({
46
+ apiKey,
47
+ body: params,
48
+ path: `${id}/quotes`
49
+ });
50
+ }
43
51
  }
44
52
 
45
53
  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,27 +5,41 @@ class VouchService extends BaseRestService {
5
5
  super(client, config, 'vouches', logger);
6
6
  }
7
7
 
8
- create(vouch, apiKey) {
8
+ create(payload, apiKey) {
9
9
  return this._request({
10
10
  apiKey,
11
- body: vouch,
11
+ body: payload,
12
12
  path: '',
13
13
  });
14
14
  }
15
15
 
16
- update(id, update, apiKey) {
16
+ update(id, payload, apiKey) {
17
17
  return this._request({
18
18
  apiKey,
19
- body: update,
19
+ body: payload,
20
20
  path: `${id}`
21
21
  });
22
22
  }
23
23
 
24
- get(id, apiKey, media = false) {
25
- const query = media ? '?media=true' : ''
24
+ get(id, apiKey, opts = {}) {
26
25
  return this._request({
27
26
  apiKey,
28
- path: `${id}`+ query
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)
29
43
  });
30
44
  }
31
45
 
@@ -37,14 +51,10 @@ class VouchService extends BaseRestService {
37
51
  return this._request({ apiKey, path: `${id}/status` });
38
52
  }
39
53
 
40
- list(apiKey) {
41
- return this._request({ apiKey, path: '' });
42
- }
43
-
44
- upload(vouch, apiKey) {
54
+ upload(payload, apiKey) {
45
55
  return this._request({
46
56
  apiKey,
47
- body: vouch,
57
+ body: payload,
48
58
  path: 'upload',
49
59
  });
50
60
  }
@@ -57,20 +67,20 @@ class VouchService extends BaseRestService {
57
67
  }
58
68
 
59
69
  return {
60
- create: (clips, { id, ordinality }, apiKey) => {
70
+ create: (payload, { id, ordinality }, apiKey) => {
61
71
  const path = getPath(id, ordinality);
62
72
  return this._request({
63
73
  apiKey,
64
- body: clips,
74
+ body: payload,
65
75
  path
66
76
  });
67
77
  },
68
78
 
69
- delete: (clips, { id, ordinality }, apiKey) => {
79
+ delete: (payload, { id, ordinality }, apiKey) => {
70
80
  const path = getPath(id, ordinality);
71
81
  return this._request({
72
82
  apiKey,
73
- body: clips,
83
+ body: payload,
74
84
  path: `${path}/delete`
75
85
  });
76
86
  },
@@ -76,6 +76,12 @@ module.exports = {
76
76
  const isProd = env === 'prod';
77
77
  return isProd ? '' : `-${env}`;
78
78
  },
79
+ queryString(opts) {
80
+ const query = new URLSearchParams(
81
+ Object.entries(opts).filter(([,value]) => value)
82
+ ).toString();
83
+ return query ? `?${query}` : '';
84
+ },
79
85
  request({ body, headers, method, url, logger }) {
80
86
  const { protocol, hostname, port, pathname, search = '' } = new URL(url);
81
87
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vouchfor/sdk",
3
- "version": "1.1.27",
3
+ "version": "1.1.29",
4
4
  "description": "Vouch API SDK",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -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,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
+
10
+ (async () => {
11
+ const params = {
12
+ //query: 'clients',
13
+ limit: 5
14
+ };
15
+ const data = await vouchClient.answers.search(params, apiKey).catch(() => undefined);
16
+ console.log(data);
17
+ })();
package/test-assets.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
+
10
+ (async () => {
11
+ const params = {
12
+ //query: 'clients',
13
+ limit: 5
14
+ };
15
+ const data = await vouchClient.assets.search(params, apiKey).catch(() => undefined);
16
+ console.log(data);
17
+ })();
@@ -0,0 +1,20 @@
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
+ console.log(vouchClient);
9
+
10
+ const apiKey = 'kTYGShoaeg-QvraTZk9LmHNsxP4dWcye82uJB6Rf0XtIsgq7UaEcYpVhMDl3z';
11
+
12
+ (async () => {
13
+ const params = {
14
+ query: 'why',
15
+ limit: 2
16
+ };
17
+ const data = await vouchClient.campaigns.search(params, apiKey).catch(() => undefined);
18
+ console.log(data);
19
+ })();
20
+
package/test-canva.js ADDED
@@ -0,0 +1,53 @@
1
+ const axios = require('axios');
2
+ const Vouch = require("./lib/vouch");
3
+
4
+ const vouchClient = new Vouch({
5
+ env: 'dev',
6
+ integrationKey: 'b0883f06-84af-4108-8543-31874c335c36-kkr3Wy4CLY8C2g65UT79sgUfOIR2ZzkA9uQam3bTs4ZNdlSs7M',
7
+ }, console);
8
+
9
+ const VOUCH_APPLICATION_API_KEY = vouchClient.integrationKey;
10
+
11
+ const apiKey = 'kTYGShoaeg-QvraTZk9LmHNsxP4dWcye82uJB6Rf0XtIsgq7UaEcYpVhMDl3z';
12
+
13
+ const answerBaseUrl = vouchClient.vouches._baseUrl.replace('/vouches', '/answers');
14
+ const listAnswersUrl = answerBaseUrl;
15
+ const trackAnswerUrl = answerBaseUrl + '/track';
16
+
17
+ const listAssetsUrl = vouchClient.vouches._baseUrl.replace('/vouches', '/assets');
18
+
19
+ const listAnswers = (key, params) => {
20
+ return axios({
21
+ method: 'GET',
22
+ params,
23
+ url: listAnswersUrl,
24
+ headers: {
25
+ accept: 'application/json',
26
+ 'content-type': 'application/json',
27
+ 'x-integration-key': VOUCH_APPLICATION_API_KEY,
28
+ 'x-api-key': key
29
+ }
30
+ });
31
+ };
32
+
33
+ const listAssets = (key, params) => {
34
+ return axios({
35
+ method: 'GET',
36
+ params,
37
+ url: listAssetsUrl,
38
+ headers: {
39
+ accept: 'application/json',
40
+ 'content-type': 'application/json',
41
+ 'x-integration-key': VOUCH_APPLICATION_API_KEY,
42
+ 'x-api-key': key
43
+ }
44
+ });
45
+ };
46
+
47
+ (async () => {
48
+ const params = {
49
+ query: 'clients'
50
+ };
51
+ const data = await listAnswers(apiKey, params).catch(() => undefined);
52
+ console.log(data.data);
53
+ })();
package/test-search.js ADDED
@@ -0,0 +1,18 @@
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 params = {
12
+ query: 'clients',
13
+ limit: 2
14
+ };
15
+ const data = await vouchClient.vouches.search(params, apiKey).catch(() => undefined);
16
+ console.log(data);
17
+ })();
18
+
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
+