@vouchfor/sdk 1.0.9 → 1.1.0

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.
@@ -1,6 +1,7 @@
1
1
  module.exports = Object.freeze({
2
2
  applications: require('./rest/applicationService'),
3
3
  campaigns: require('./rest/campaignService'),
4
+ entities: require('./rest/entityService'),
4
5
  integrations: require('./integration/integrationService'),
5
6
  vouches: require('./rest/vouchService'),
6
7
  });
@@ -13,11 +13,11 @@ class ApplicationService extends BaseRestService {
13
13
  });
14
14
  }
15
15
 
16
- set(application, apiKey) {
16
+ set(id, application, apiKey) {
17
17
  return this._request({
18
18
  apiKey,
19
19
  body: application,
20
- path: `${application.id}`,
20
+ path: `${id}`,
21
21
  });
22
22
  }
23
23
 
@@ -0,0 +1,33 @@
1
+ const BaseRestService = require('./base');
2
+
3
+ class EntityService extends BaseRestService {
4
+ constructor(client, config) {
5
+ super(client, config, 'entities');
6
+ }
7
+
8
+ create(entity, apiKey) {
9
+ return this._request({
10
+ apiKey,
11
+ body: entity,
12
+ path: '',
13
+ });
14
+ }
15
+
16
+ get(id, apiKey) {
17
+ return this._request({ apiKey, path: `${id}` });
18
+ }
19
+
20
+ list(apiKey) {
21
+ return this._request({ apiKey, path: '' });
22
+ }
23
+
24
+ update(id, update, apiKey) {
25
+ return this._request({
26
+ apiKey,
27
+ body: update,
28
+ path: `${id}`
29
+ });
30
+ }
31
+ }
32
+
33
+ module.exports = EntityService;
@@ -24,7 +24,12 @@ module.exports = {
24
24
  res.on('end', () => {
25
25
  try {
26
26
  if (res.statusCode >= 400) {
27
- reject(res.statusMessage || 'error');
27
+ const error = res.statusMessage || 'error';
28
+ try {
29
+ error = JSON.parse(result)?.error || error;
30
+ } catch (_) {}
31
+
32
+ reject(error);
28
33
  }
29
34
 
30
35
  const data = !!result ? JSON.parse(result) : result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vouchfor/sdk",
3
- "version": "1.0.9",
3
+ "version": "1.1.0",
4
4
  "description": "Vouch API SDK",
5
5
  "main": "lib/index.js",
6
6
  "repository": {