@vouchfor/sdk 1.0.4 → 1.0.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/index.js +1 -1
- package/lib/services/baseService.js +7 -1
- package/lib/services/integration/base.js +2 -1
- package/lib/services/rest/applicationService.js +13 -1
- package/lib/services/rest/base.js +2 -1
- package/lib/shared/events.js +18 -0
- package/lib/shared/utils.js +5 -5
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -13,6 +13,7 @@ class BaseService {
|
|
|
13
13
|
async _callApi({
|
|
14
14
|
apiKey = '',
|
|
15
15
|
integrationKey = '',
|
|
16
|
+
method,
|
|
16
17
|
body,
|
|
17
18
|
url,
|
|
18
19
|
}) {
|
|
@@ -26,7 +27,12 @@ class BaseService {
|
|
|
26
27
|
headers['x-integration-key'] = integrationKey;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
return utils.request({
|
|
30
|
+
return utils.request({
|
|
31
|
+
body,
|
|
32
|
+
headers,
|
|
33
|
+
method,
|
|
34
|
+
url,
|
|
35
|
+
});
|
|
30
36
|
}
|
|
31
37
|
}
|
|
32
38
|
|
|
@@ -11,10 +11,11 @@ class BaseIntegrationService extends BaseService {
|
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
_request({ body, path }) {
|
|
14
|
+
_request({ body, method, path }) {
|
|
15
15
|
return this._callApi({
|
|
16
16
|
apiKey: this._apiKey,
|
|
17
17
|
body,
|
|
18
|
+
method,
|
|
18
19
|
url: `${this._baseUrl}/${path}`,
|
|
19
20
|
});
|
|
20
21
|
}
|
|
@@ -13,12 +13,24 @@ class ApplicationService extends BaseRestService {
|
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
set(application, apiKey) {
|
|
17
|
+
return this._request({
|
|
18
|
+
apiKey,
|
|
19
|
+
body: { application },
|
|
20
|
+
path: `${application.id}`,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
16
24
|
get(id, apiKey) {
|
|
17
25
|
return this._request({ apiKey, path: `${id}` });
|
|
18
26
|
}
|
|
19
27
|
|
|
20
28
|
delete(id, apiKey) {
|
|
21
|
-
return this._request({
|
|
29
|
+
return this._request({
|
|
30
|
+
apiKey,
|
|
31
|
+
method: 'POST',
|
|
32
|
+
path: `${id}/delete`
|
|
33
|
+
});
|
|
22
34
|
}
|
|
23
35
|
}
|
|
24
36
|
|
|
@@ -12,11 +12,12 @@ class BaseRestService extends BaseService {
|
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
_request({ apiKey, body, path }) {
|
|
15
|
+
_request({ apiKey, body, method, path }) {
|
|
16
16
|
return this._callApi({
|
|
17
17
|
apiKey: apiKey || this._apiKey,
|
|
18
18
|
integrationKey: this._integrationKey,
|
|
19
19
|
body,
|
|
20
|
+
method,
|
|
20
21
|
url: `${this._baseUrl}/${path}`,
|
|
21
22
|
});
|
|
22
23
|
}
|
package/lib/shared/events.js
CHANGED
|
@@ -3,5 +3,23 @@ module.exports = {
|
|
|
3
3
|
APPLICATION_DELETE: 'application.delete',
|
|
4
4
|
APPLICATION_CONFIGURE: 'application.configure',
|
|
5
5
|
APPLICATION_VALIDATE: 'application.validate',
|
|
6
|
+
CAMPAIGN_CREATED: 'campaign.created',
|
|
7
|
+
CAMPAIGN_LIVE: 'campaign.published',
|
|
8
|
+
CAMPAIGN_PAUSED: 'campaign.paused',
|
|
9
|
+
CAMPAIGN_VIEWED: 'campaign.viewed',
|
|
10
|
+
CAMPAIGN_STARTED: 'campaign.started',
|
|
11
|
+
CAMPAIGN_RESPONDED: 'campaign.responded',
|
|
12
|
+
CAMPAIGN_DELETED: 'campaign.deleted',
|
|
13
|
+
VOUCH_CREATED: 'vouch.created',
|
|
14
|
+
VOUCH_SENT: 'vouch.sent',
|
|
15
|
+
VOUCH_PUBLISHED: 'vouch.published',
|
|
16
|
+
VOUCH_OPENED: 'vouch.viewed',
|
|
17
|
+
VOUCH_REMINDED: 'vouch.reminded',
|
|
18
|
+
VOUCH_SUBMITTED: 'vouch.submitted',
|
|
19
|
+
VOUCH_DECLINED: 'vouch.declined',
|
|
20
|
+
VOUCH_SCHEDULED: 'vouch.scheduled',
|
|
21
|
+
VOUCH_MESSAGE: 'vouch.message',
|
|
6
22
|
VOUCH_RESPONDED: 'vouch.responded',
|
|
23
|
+
VOUCH_UPDATED: 'vouch.updated',
|
|
24
|
+
VOUCH_DELETED: 'vouch.deleted',
|
|
7
25
|
};
|
package/lib/shared/utils.js
CHANGED
|
@@ -5,17 +5,17 @@ module.exports = {
|
|
|
5
5
|
const isProd = env === 'prod';
|
|
6
6
|
return isProd ? '' : `-${env}`;
|
|
7
7
|
},
|
|
8
|
-
request({ body, headers, url }) {
|
|
9
|
-
const { host, pathname } = new URL(url);
|
|
8
|
+
request({ body, headers, method, url }) {
|
|
9
|
+
const { host, pathname, search = '' } = new URL(url);
|
|
10
10
|
|
|
11
11
|
return new Promise((resolve, reject) => {
|
|
12
12
|
let result = '';
|
|
13
13
|
const req = https
|
|
14
14
|
.request({
|
|
15
15
|
host,
|
|
16
|
-
path: pathname
|
|
16
|
+
path: `${pathname}${search}`,
|
|
17
17
|
headers,
|
|
18
|
-
method: body ? 'POST' : 'GET',
|
|
18
|
+
method: method ? method : body ? 'POST' : 'GET',
|
|
19
19
|
},
|
|
20
20
|
(res) => {
|
|
21
21
|
res.on('data', (chunk) => {
|
|
@@ -27,7 +27,7 @@ module.exports = {
|
|
|
27
27
|
reject(res.statusMessage || 'error');
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
const data = JSON.parse(result);
|
|
30
|
+
const data = !!result ? JSON.parse(result) : result;
|
|
31
31
|
resolve(data);
|
|
32
32
|
} catch (err) {
|
|
33
33
|
reject(err);
|