@bunnyapp/api-client 1.0.15 → 1.0.17

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": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "Node.js client for Bunny CRM",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -0,0 +1,19 @@
1
+ const query = `mutation subscriptionCancel ($ids: [ID!]!) {
2
+ subscriptionCancel (ids: $ids) {
3
+ errors
4
+ }
5
+ }`;
6
+
7
+ module.exports = async function (subscriptionId) {
8
+ let variables = {
9
+ ids: [subscriptionId],
10
+ };
11
+
12
+ const res = await this.query(query, variables);
13
+
14
+ return (
15
+ res.data &&
16
+ res.data.subscriptionCancel &&
17
+ res.data.subscriptionCancel.errors == null
18
+ );
19
+ };
@@ -39,6 +39,7 @@ module.exports = async function (priceListCode, options = {}) {
39
39
  attributes: {
40
40
  priceListCode: priceListCode,
41
41
  trial: options["trial"] || false,
42
+ evergreen: options["evergreen"] || false,
42
43
  },
43
44
  };
44
45
 
@@ -0,0 +1,35 @@
1
+ const subscriptionReinstateMutation = `mutation subscriptionReinstate ($ids: [ID!]!) {
2
+ subscriptionReinstate (ids: $ids) {
3
+ quote {
4
+ id
5
+ }
6
+ }
7
+ }`;
8
+
9
+ const quoteApplyChangesMutation = `mutation quoteApplyChanges ($quoteId: ID!, $persist: Boolean!) {
10
+ quoteApplyChanges (quoteId: $quoteId, persist: $persist, paymentId: $paymentId, taxes: $taxes) {
11
+ errors
12
+ subscriptions {
13
+ id
14
+ state
15
+ }
16
+ }
17
+ }`;
18
+
19
+ module.exports = async function (subscriptionId) {
20
+ const res = await this.query(subscriptionReinstateMutation, {
21
+ ids: [subscriptionId],
22
+ });
23
+ console.log(res.data.subscriptionReinstate.quote);
24
+
25
+ const quoteId = res?.data?.subscriptionReinstate?.quote?.id;
26
+
27
+ if (!quoteId) return false;
28
+
29
+ const res2 = await this.query(quoteApplyChangesMutation, {
30
+ quoteId: quoteId,
31
+ persist: true,
32
+ });
33
+
34
+ return res2;
35
+ };
package/src/index.js CHANGED
@@ -85,6 +85,8 @@ class Bunny {
85
85
  }
86
86
 
87
87
  Bunny.prototype.createSubscription = require("./helpers/create-subscription.js");
88
+ Bunny.prototype.cancelSubscription = require("./helpers/cancel-subscription.js");
89
+ Bunny.prototype.reinstateSubscription = require("./helpers/reinstate-subscription.js");
88
90
  Bunny.prototype.createTenant = require("./helpers/create-tenant.js");
89
91
  Bunny.prototype.updateTenant = require("./helpers/update-tenant.js");
90
92
  Bunny.prototype.trackUsage = require("./helpers/track-usage.js");