@vouchfor/sdk 1.1.27 → 1.1.28

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,4 +1,6 @@
1
1
  module.exports = Object.freeze({
2
+ answers: require('./rest/answerService'),
3
+ assets: require('./rest/assetService'),
2
4
  applications: require('./rest/applicationService'),
3
5
  campaigns: require('./rest/campaignService'),
4
6
  entities: require('./rest/entityService'),
@@ -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;
@@ -29,8 +29,26 @@ class CampaignService extends BaseRestService {
29
29
  return this._request({ apiKey, path: '' });
30
30
  }
31
31
 
32
- vouches(id, apiKey) {
33
- return this._request({ apiKey, path: `${id}/vouches` });
32
+ search(params = {}, apiKey) {
33
+ return this._request({
34
+ apiKey,
35
+ path: 'search' + this._utils.queryString(params)
36
+ });
37
+ }
38
+
39
+ vouches(id, apiKey, opts = {}) {
40
+ return this._request({
41
+ apiKey,
42
+ path: `${id}/vouches` + this._utils.queryString(opts)
43
+ });
44
+ }
45
+
46
+ convert(id, params, apiKey) {
47
+ return this._request({
48
+ apiKey,
49
+ body: params,
50
+ path: `${id}/vouch`
51
+ });
34
52
  }
35
53
  }
36
54
 
@@ -40,6 +40,22 @@ 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
+ }
51
+
52
+ video(id, params, apiKey) {
53
+ return this._request({
54
+ apiKey,
55
+ body: params,
56
+ path: `${id}/video`
57
+ });
58
+ }
43
59
  }
44
60
 
45
61
  module.exports = EntityService;
@@ -21,11 +21,10 @@ class VouchService extends BaseRestService {
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)
29
28
  });
30
29
  }
31
30
 
@@ -41,6 +40,13 @@ class VouchService extends BaseRestService {
41
40
  return this._request({ apiKey, path: '' });
42
41
  }
43
42
 
43
+ search(params = {}, apiKey) {
44
+ return this._request({
45
+ apiKey,
46
+ path: 'search' + this._utils.queryString(params)
47
+ });
48
+ }
49
+
44
50
  upload(vouch, apiKey) {
45
51
  return this._request({
46
52
  apiKey,
@@ -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.28",
4
4
  "description": "Vouch API SDK",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -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
+