@bunnyapp/api-client 2.0.9 → 2.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bunnyapp/api-client",
3
- "version": "2.0.9",
3
+ "version": "2.2.0",
4
4
  "description": "Node.js client for Bunny CRM",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -41,4 +41,4 @@
41
41
  "index.js",
42
42
  "src/"
43
43
  ]
44
- }
44
+ }
@@ -49,10 +49,15 @@ module.exports = async function (tenantCode, attributes) {
49
49
  };
50
50
 
51
51
  const res = await this.query(query, variables);
52
+ const accountUpdate = res?.data?.accountUpdate;
52
53
 
53
54
  if (res?.errors) {
54
55
  throw new Error(res.errors.map((e) => e.message).join());
55
56
  }
56
57
 
57
- return res?.data?.accountUpdate?.account;
58
+ if (accountUpdate?.errors) {
59
+ throw new Error(accountUpdate.errors.join());
60
+ }
61
+
62
+ return accountUpdate?.account;
58
63
  };
@@ -46,10 +46,15 @@ module.exports = async function (
46
46
  }
47
47
 
48
48
  const res = await this.query(query, variables);
49
+ const featureUsageCreate = res?.data?.featureUsageCreate;
49
50
 
50
51
  if (res?.errors) {
51
52
  throw new Error(res.errors.map((e) => e.message).join());
52
53
  }
53
54
 
54
- return res?.data?.featureUsageCreate?.featureUsage;
55
+ if (featureUsageCreate?.errors) {
56
+ throw new Error(featureUsageCreate.errors.join());
57
+ }
58
+
59
+ return featureUsageCreate?.featureUsage;
55
60
  };
@@ -24,10 +24,15 @@ module.exports = async function (
24
24
  };
25
25
 
26
26
  const res = await this.query(query, variables);
27
+ const portalSessionCreate = res?.data?.portalSessionCreate;
27
28
 
28
29
  if (res?.errors) {
29
30
  throw new Error(res.errors.map((e) => e.message).join());
30
31
  }
31
32
 
32
- return res?.data?.portalSessionCreate?.token;
33
+ if (portalSessionCreate?.errors) {
34
+ throw new Error(portalSessionCreate.errors.join());
35
+ }
36
+
37
+ return portalSessionCreate?.token;
33
38
  };
@@ -15,10 +15,15 @@ module.exports = async function (subscriptionId) {
15
15
  };
16
16
 
17
17
  const res = await this.query(query, variables);
18
+ const subscriptionCancel = res?.data?.subscriptionCancel;
18
19
 
19
20
  if (res?.errors) {
20
21
  throw new Error(res.errors.map((e) => e.message).join());
21
22
  }
22
23
 
24
+ if (subscriptionCancel?.errors) {
25
+ throw new Error(subscriptionCancel.errors.join());
26
+ }
27
+
23
28
  return true;
24
29
  };
@@ -93,10 +93,15 @@ module.exports = async function (priceListCode, options = {}) {
93
93
  }
94
94
 
95
95
  const res = await this.query(query, variables);
96
+ const subscriptionCreate = res?.data?.subscriptionCreate;
96
97
 
97
98
  if (res?.errors) {
98
99
  throw new Error(res.errors.map((e) => e.message).join());
99
100
  }
100
101
 
101
- return res?.data?.subscriptionCreate?.subscription;
102
+ if (subscriptionCreate?.errors) {
103
+ throw new Error(subscriptionCreate.errors.join());
104
+ }
105
+
106
+ return subscriptionCreate?.subscription;
102
107
  };
@@ -41,10 +41,15 @@ module.exports = async function (
41
41
  };
42
42
 
43
43
  const res = await this.query(query, variables);
44
+ const tenantCreate = res?.data?.tenantCreate;
44
45
 
45
46
  if (res?.errors) {
46
47
  throw new Error(res.errors.map((e) => e.message).join());
47
48
  }
48
49
 
49
- return res?.data?.tenantCreate?.tenant;
50
+ if (tenantCreate?.errors) {
51
+ throw new Error(tenantCreate.errors.join());
52
+ }
53
+
54
+ return tenantCreate?.tenant;
50
55
  };
@@ -20,10 +20,15 @@ module.exports = async function (
20
20
  };
21
21
 
22
22
  const res = await this.query(query, variables);
23
+ const tenantMetricsUpdate = res?.data?.tenantMetricsUpdate;
23
24
 
24
25
  if (res?.errors) {
25
26
  throw new Error(res.errors.map((e) => e.message).join());
26
27
  }
27
28
 
29
+ if (tenantMetricsUpdate?.errors) {
30
+ throw new Error(tenantMetricsUpdate.errors.join());
31
+ }
32
+
28
33
  return true;
29
34
  };
@@ -24,10 +24,15 @@ module.exports = async function (id, code, name) {
24
24
  };
25
25
 
26
26
  const res = await this.query(query, variables);
27
+ const tenantUpdate = res?.data?.tenantUpdate;
27
28
 
28
29
  if (res?.errors) {
29
30
  throw new Error(res.errors.map((e) => e.message).join());
30
31
  }
31
32
 
32
- return res?.data?.tenantUpdate?.tenant;
33
+ if (tenantUpdate?.errors) {
34
+ throw new Error(tenantUpdate.errors.join());
35
+ }
36
+
37
+ return tenantUpdate?.tenant;
33
38
  };
package/src/index.js CHANGED
@@ -42,6 +42,11 @@ class Bunny {
42
42
  }
43
43
 
44
44
  console.log("Authorization error: ", error);
45
+
46
+ if (error.response?.data?.error_description) {
47
+ return Promise.reject(error.response.data.error_description);
48
+ }
49
+
45
50
  return Promise.reject("Invalid access token");
46
51
  });
47
52