@vouchfor/sdk 1.0.2 → 1.0.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.
- package/lib/index.js +6 -1
- package/lib/services/baseService.js +15 -17
- package/lib/services/integration/base.js +10 -1
- package/lib/services/integration/integrationService.js +0 -10
- package/lib/services/rest/applicationService.js +8 -8
- package/lib/services/rest/base.js +8 -18
- package/lib/services/rest/campaignService.js +6 -6
- package/lib/services/rest/vouchService.js +6 -6
- package/lib/shared/events.js +7 -0
- package/lib/{utils.js → shared/utils.js} +4 -4
- package/package.json +1 -1
- package/index.js +0 -14
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const utils = require('../utils');
|
|
1
|
+
const utils = require('../shared/utils');
|
|
2
2
|
|
|
3
3
|
class BaseService {
|
|
4
4
|
constructor(client, config = {}) {
|
|
@@ -10,30 +10,28 @@ class BaseService {
|
|
|
10
10
|
this._baseUrl = `${config.baseUrl}${basePath}`;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
_callApi({
|
|
13
|
+
async _callApi({
|
|
14
14
|
apiKey = '',
|
|
15
15
|
integrationKey = '',
|
|
16
|
+
method,
|
|
16
17
|
body,
|
|
17
18
|
url,
|
|
18
19
|
}) {
|
|
20
|
+
const headers = {
|
|
21
|
+
Accept: 'application/json',
|
|
22
|
+
'Content-Type': 'application/json',
|
|
23
|
+
'x-api-key': apiKey,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
if (integrationKey) {
|
|
27
|
+
headers['x-integration-key'] = integrationKey;
|
|
28
|
+
}
|
|
29
|
+
|
|
19
30
|
return utils.request({
|
|
20
31
|
body,
|
|
32
|
+
headers,
|
|
33
|
+
method,
|
|
21
34
|
url,
|
|
22
|
-
headers: {
|
|
23
|
-
Accept: 'application/json',
|
|
24
|
-
'Content-Type': 'application/json',
|
|
25
|
-
'x-api-key': apiKey,
|
|
26
|
-
'x-integration-key': integrationKey,
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
_request({ apiKey, body, path }) {
|
|
32
|
-
return this._callApi({
|
|
33
|
-
apiKey: apiKey || this._apiKey,
|
|
34
|
-
integrationKey: this._integrationKey,
|
|
35
|
-
body,
|
|
36
|
-
url: `${this._baseUrl}/${path}`,
|
|
37
35
|
});
|
|
38
36
|
}
|
|
39
37
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const BaseService = require('../baseService');
|
|
2
|
-
const utils = require('../../utils');
|
|
2
|
+
const utils = require('../../shared/utils');
|
|
3
3
|
|
|
4
4
|
class BaseIntegrationService extends BaseService {
|
|
5
5
|
constructor(client, config = {}, basePath = '') {
|
|
@@ -10,6 +10,15 @@ class BaseIntegrationService extends BaseService {
|
|
|
10
10
|
env: config.env,
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
|
+
|
|
14
|
+
_request({ body, method, path }) {
|
|
15
|
+
return this._callApi({
|
|
16
|
+
apiKey: this._apiKey,
|
|
17
|
+
body,
|
|
18
|
+
method,
|
|
19
|
+
url: `${this._baseUrl}/${path}`,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
13
22
|
}
|
|
14
23
|
|
|
15
24
|
module.exports = BaseIntegrationService;
|
|
@@ -5,16 +5,6 @@ class IntegrationService extends BaseIntegrationService {
|
|
|
5
5
|
super(client, config, '');
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
/*
|
|
9
|
-
* Integration method to resolve an application from a entityId
|
|
10
|
-
*/
|
|
11
|
-
async application(entityId) {
|
|
12
|
-
const response = await this.authenticate({ entityId });
|
|
13
|
-
return this._client.applications.get(
|
|
14
|
-
response.application.id
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
8
|
authenticate({ applicationId, entityId }) {
|
|
19
9
|
if (applicationId) {
|
|
20
10
|
return this._request({ path: `applications/${applicationId}/entity` });
|
|
@@ -5,23 +5,23 @@ class ApplicationService extends BaseRestService {
|
|
|
5
5
|
super(client, config, 'applications');
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
create(application,
|
|
8
|
+
create(application, apiKey) {
|
|
9
9
|
return this._request({
|
|
10
|
-
|
|
10
|
+
apiKey,
|
|
11
11
|
body: application,
|
|
12
12
|
path: '',
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
get(id,
|
|
17
|
-
return this._request({
|
|
16
|
+
get(id, apiKey) {
|
|
17
|
+
return this._request({ apiKey, path: `${id}` });
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
delete(id,
|
|
20
|
+
delete(id, apiKey) {
|
|
21
21
|
return this._request({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
path: `${id}/delete
|
|
22
|
+
apiKey,
|
|
23
|
+
method: 'POST',
|
|
24
|
+
path: `${id}/delete`
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const BaseService = require('../baseService');
|
|
2
|
-
const utils = require('../../utils');
|
|
2
|
+
const utils = require('../../shared/utils');
|
|
3
3
|
|
|
4
4
|
class BaseRestService extends BaseService {
|
|
5
5
|
constructor(client, config = {}, basePath = '') {
|
|
@@ -12,24 +12,14 @@ class BaseRestService extends BaseService {
|
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
apiKey:
|
|
15
|
+
_request({ apiKey, body, method, path }) {
|
|
16
|
+
return this._callApi({
|
|
17
|
+
apiKey: apiKey || this._apiKey,
|
|
18
18
|
integrationKey: this._integrationKey,
|
|
19
|
-
body
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (!options.apiKey) {
|
|
24
|
-
const response = await this._client.integrations.authenticate({
|
|
25
|
-
applicationId: opts.applicationId,
|
|
26
|
-
entityId: opts.entityId
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
options.apiKey = response.entity.keys.api;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return this._callApi(options);
|
|
19
|
+
body,
|
|
20
|
+
method,
|
|
21
|
+
url: `${this._baseUrl}/${path}`,
|
|
22
|
+
});
|
|
33
23
|
}
|
|
34
24
|
}
|
|
35
25
|
|
|
@@ -5,20 +5,20 @@ class CampaignService extends BaseRestService {
|
|
|
5
5
|
super(client, config, 'campaigns');
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
create(campaign,
|
|
8
|
+
create(campaign, apiKey) {
|
|
9
9
|
return this._request({
|
|
10
|
-
|
|
10
|
+
apiKey,
|
|
11
11
|
body: campaign,
|
|
12
12
|
path: '',
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
get(id,
|
|
17
|
-
return this._request({
|
|
16
|
+
get(id, apiKey) {
|
|
17
|
+
return this._request({ apiKey, path: `${id}` });
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
list(
|
|
21
|
-
return this._request({
|
|
20
|
+
list(apiKey) {
|
|
21
|
+
return this._request({ apiKey, path: '' });
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -5,20 +5,20 @@ class VouchService extends BaseRestService {
|
|
|
5
5
|
super(client, config, 'vouches');
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
create(vouch,
|
|
8
|
+
create(vouch, apiKey) {
|
|
9
9
|
return this._request({
|
|
10
|
-
|
|
10
|
+
apiKey,
|
|
11
11
|
body: vouch,
|
|
12
12
|
path: '',
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
get(id,
|
|
17
|
-
return this._request({
|
|
16
|
+
get(id, apiKey) {
|
|
17
|
+
return this._request({ apiKey, path: `${id}` });
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
list(
|
|
21
|
-
return this._request({
|
|
20
|
+
list(apiKey) {
|
|
21
|
+
return this._request({ apiKey, path: '' });
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -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) => {
|
package/package.json
CHANGED
package/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const Vouch = require('./lib');
|
|
2
|
-
|
|
3
|
-
async function test() {
|
|
4
|
-
const x = new Vouch({
|
|
5
|
-
integrationKey: `ae0c85d5-bcca-4ad1-aa38-2860f9abf3e2-jG3gzsOne4UrZUvSxZxGbWcBDcQbuuGJlq7axF85tC53f7TxGz`,
|
|
6
|
-
env: 'dev',
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
const t = await x.integrations.authenticate({ entityId: 'RVzB3aYVnL' });
|
|
10
|
-
console.log(t)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
test()
|
|
14
|
-
|