@bunnyapp/api-client 2.2.4 → 3.0.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.
Files changed (69) hide show
  1. package/README.md +304 -66
  2. package/dist/generated/graphql.d.ts +9410 -0
  3. package/dist/generated/graphql.d.ts.map +1 -0
  4. package/dist/generated/graphql.js +3 -0
  5. package/dist/generated/graphql.js.map +1 -0
  6. package/dist/helpers/account-update-by-tenant-code.d.ts +10 -0
  7. package/dist/helpers/account-update-by-tenant-code.d.ts.map +1 -0
  8. package/dist/helpers/account-update-by-tenant-code.js +71 -0
  9. package/dist/helpers/account-update-by-tenant-code.js.map +1 -0
  10. package/dist/helpers/feature-usage-create.d.ts +12 -0
  11. package/dist/helpers/feature-usage-create.d.ts.map +1 -0
  12. package/dist/helpers/feature-usage-create.js +55 -0
  13. package/dist/helpers/feature-usage-create.js.map +1 -0
  14. package/dist/helpers/portal-session-create.d.ts +10 -0
  15. package/dist/helpers/portal-session-create.d.ts.map +1 -0
  16. package/dist/helpers/portal-session-create.js +37 -0
  17. package/dist/helpers/portal-session-create.js.map +1 -0
  18. package/dist/helpers/subscription-cancel.d.ts +8 -0
  19. package/dist/helpers/subscription-cancel.d.ts.map +1 -0
  20. package/dist/helpers/subscription-cancel.js +29 -0
  21. package/dist/helpers/subscription-cancel.js.map +1 -0
  22. package/dist/helpers/subscription-create.d.ts +39 -0
  23. package/dist/helpers/subscription-create.d.ts.map +1 -0
  24. package/dist/helpers/subscription-create.js +112 -0
  25. package/dist/helpers/subscription-create.js.map +1 -0
  26. package/dist/helpers/tenant-by-code.d.ts +9 -0
  27. package/dist/helpers/tenant-by-code.d.ts.map +1 -0
  28. package/{src → dist}/helpers/tenant-by-code.js +18 -17
  29. package/dist/helpers/tenant-by-code.js.map +1 -0
  30. package/dist/helpers/tenant-create.d.ts +13 -0
  31. package/dist/helpers/tenant-create.d.ts.map +1 -0
  32. package/dist/helpers/tenant-create.js +52 -0
  33. package/dist/helpers/tenant-create.js.map +1 -0
  34. package/dist/helpers/tenant-metrics-update.d.ts +22 -0
  35. package/dist/helpers/tenant-metrics-update.d.ts.map +1 -0
  36. package/dist/helpers/tenant-metrics-update.js +36 -0
  37. package/dist/helpers/tenant-metrics-update.js.map +1 -0
  38. package/dist/helpers/tenant-update.d.ts +11 -0
  39. package/dist/helpers/tenant-update.d.ts.map +1 -0
  40. package/dist/helpers/tenant-update.js +45 -0
  41. package/dist/helpers/tenant-update.js.map +1 -0
  42. package/dist/index.d.ts +58 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +127 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/types/graphql.d.ts +2 -0
  47. package/dist/types/graphql.d.ts.map +1 -0
  48. package/dist/types/graphql.js +19 -0
  49. package/dist/types/graphql.js.map +1 -0
  50. package/dist/types/index.d.ts +2 -0
  51. package/dist/types/index.d.ts.map +1 -0
  52. package/dist/types/index.js +18 -0
  53. package/dist/types/index.js.map +1 -0
  54. package/dist/webhooks.d.ts +7 -0
  55. package/dist/webhooks.d.ts.map +1 -0
  56. package/dist/webhooks.js +31 -0
  57. package/dist/webhooks.js.map +1 -0
  58. package/package.json +26 -9
  59. package/index.js +0 -1
  60. package/src/helpers/account-update-by-tenant-code.js +0 -63
  61. package/src/helpers/feature-usage-create.js +0 -58
  62. package/src/helpers/portal-session-create.js +0 -38
  63. package/src/helpers/subscription-cancel.js +0 -29
  64. package/src/helpers/subscription-create.js +0 -107
  65. package/src/helpers/tenant-create.js +0 -55
  66. package/src/helpers/tenant-metrics-update.js +0 -34
  67. package/src/helpers/tenant-update.js +0 -38
  68. package/src/index.js +0 -101
  69. package/src/webhooks.js +0 -24
@@ -1,29 +0,0 @@
1
- const query = `mutation subscriptionCancel ($ids: [ID!]!) {
2
- subscriptionCancel (ids: $ids) {
3
- errors
4
- }
5
- }`;
6
-
7
- /**
8
- * Cancel a subsription
9
- * @param {number} subscriptionId
10
- * @returns {boolean} Success
11
- */
12
- module.exports = async function (subscriptionId) {
13
- let variables = {
14
- ids: [subscriptionId],
15
- };
16
-
17
- const res = await this.query(query, variables);
18
- const subscriptionCancel = res?.data?.subscriptionCancel;
19
-
20
- if (res?.errors) {
21
- throw new Error(res.errors.map((e) => e.message).join());
22
- }
23
-
24
- if (subscriptionCancel?.errors) {
25
- throw new Error(subscriptionCancel.errors.join());
26
- }
27
-
28
- return true;
29
- };
@@ -1,107 +0,0 @@
1
- const query = `mutation subscriptionCreate ($attributes: SubscriptionAttributes!) {
2
- subscriptionCreate (attributes: $attributes) {
3
- subscription {
4
- id
5
- account {
6
- id
7
- name
8
- contacts {
9
- id
10
- firstName
11
- lastName
12
- }
13
- }
14
- trialStartDate
15
- trialEndDate
16
- startDate
17
- endDate
18
- state
19
- plan {
20
- code
21
- name
22
- }
23
- priceList {
24
- code
25
- name
26
- }
27
- tenant {
28
- id
29
- code
30
- name
31
- account {
32
- id
33
- name
34
- billingDay
35
- }
36
- }
37
- }
38
- errors
39
- }
40
- }`;
41
-
42
- /**
43
- * Create a new subscription for a tenant
44
- * @param {string} priceListCode The code for the plan to subscribe to
45
- * @param {Object} options
46
- * @returns {Object} The subscription object
47
- */
48
- module.exports = async function (priceListCode, options = {}) {
49
- let variables = {
50
- attributes: {
51
- priceListCode: priceListCode,
52
- trial: options["trial"] || false,
53
- evergreen: options["evergreen"] || true,
54
- },
55
- };
56
-
57
- if (options["accountId"]) {
58
- variables.attributes.accountId = options["accountId"];
59
- } else {
60
- variables.attributes.account = {
61
- name: options["accountName"]?.toString(),
62
- ownerUserId: options["ownerUserId"]?.toString(),
63
- phone: options["phone"]?.toString(),
64
- fax: options["fax"]?.toString(),
65
- website: options["website"]?.toString(),
66
- billingStreet: options["billingStreet"]?.toString(),
67
- billingCity: options["billingCity"]?.toString(),
68
- billingZip: options["billingZip"]?.toString(),
69
- billingState: options["billingState"]?.toString(),
70
- billingCountry: options["billingCountry"]?.toString(),
71
- billingContact: {
72
- firstName: options["firstName"]?.toString(),
73
- lastName: options["lastName"]?.toString(),
74
- email: options["email"]?.toString(),
75
- phone: options["phone"]?.toString(),
76
- mobile: options["mobile"]?.toString(),
77
- salutation: options["salutation"]?.toString(),
78
- title: options["title"]?.toString(),
79
- mailingStreet: options["mailingStreet"]?.toString(),
80
- mailingCity: options["mailingCity"]?.toString(),
81
- mailingZip: options["mailingZip"]?.toString(),
82
- mailingState: options["mailingState"]?.toString(),
83
- mailingCountry: options["mailingCountry"]?.toString(),
84
- },
85
- };
86
- }
87
-
88
- if (options["tenantCode"]) {
89
- variables.attributes.tenant = {
90
- code: options["tenantCode"]?.toString(),
91
- name: options["tenantName"]?.toString(),
92
- };
93
- }
94
-
95
- const res = await this.query(query, variables);
96
- const subscriptionCreate = res?.data?.subscriptionCreate;
97
-
98
- if (res?.errors) {
99
- throw new Error(res.errors.map((e) => e.message).join());
100
- }
101
-
102
- if (subscriptionCreate?.errors) {
103
- throw new Error(subscriptionCreate.errors.join());
104
- }
105
-
106
- return subscriptionCreate?.subscription;
107
- };
@@ -1,55 +0,0 @@
1
- const query = `mutation tenantCreate ($attributes: TenantAttributes!, $subscriptionId: ID!) {
2
- tenantCreate (attributes: $attributes, subscriptionId: $subscriptionId) {
3
- tenant {
4
- code
5
- id
6
- name
7
- platform {
8
- id
9
- name
10
- code
11
- }
12
- }
13
- errors
14
- }
15
- }`;
16
-
17
- /**
18
- *
19
- * @param {string} name Account name of the tenant
20
- * @param {string} code Unique code for the tenant
21
- * @param {string} platformCode Code for the platform that the tenant is on
22
- * @param {number} accountId Id of the account that the tenant is being created for
23
- * @param {number} subscriptionId Id of the subscription that the tenant is being created for
24
- * @returns
25
- */
26
- module.exports = async function (
27
- name,
28
- code,
29
- platformCode,
30
- accountId,
31
- subscriptionId
32
- ) {
33
- let variables = {
34
- attributes: {
35
- name: name,
36
- code: code,
37
- accountId: accountId,
38
- platformCode: platformCode,
39
- },
40
- subscriptionId: subscriptionId,
41
- };
42
-
43
- const res = await this.query(query, variables);
44
- const tenantCreate = res?.data?.tenantCreate;
45
-
46
- if (res?.errors) {
47
- throw new Error(res.errors.map((e) => e.message).join());
48
- }
49
-
50
- if (tenantCreate?.errors) {
51
- throw new Error(tenantCreate.errors.join());
52
- }
53
-
54
- return tenantCreate?.tenant;
55
- };
@@ -1,34 +0,0 @@
1
- const query = `mutation tenantMetricsUpdate ($code: String!, $attributes: TenantMetricsAttributes!){
2
- tenantMetricsUpdate (code: $code, attributes: $attributes) {
3
- errors
4
- }
5
- }`;
6
-
7
- module.exports = async function (
8
- code,
9
- lastLogin,
10
- userCount,
11
- utilizationMetrics
12
- ) {
13
- let variables = {
14
- code: code?.toString(),
15
- attributes: {
16
- lastLogin: lastLogin,
17
- userCount: userCount,
18
- utilizationMetrics: utilizationMetrics,
19
- },
20
- };
21
-
22
- const res = await this.query(query, variables);
23
- const tenantMetricsUpdate = res?.data?.tenantMetricsUpdate;
24
-
25
- if (res?.errors) {
26
- throw new Error(res.errors.map((e) => e.message).join());
27
- }
28
-
29
- if (tenantMetricsUpdate?.errors) {
30
- throw new Error(tenantMetricsUpdate.errors.join());
31
- }
32
-
33
- return true;
34
- };
@@ -1,38 +0,0 @@
1
- const query = `mutation tenantUpdate ($id: ID!, $attributes: TenantAttributes!) {
2
- tenantUpdate (id: $id, attributes: $attributes) {
3
- tenant {
4
- code
5
- id
6
- name
7
- platform {
8
- id
9
- name
10
- code
11
- }
12
- }
13
- errors
14
- }
15
- }`;
16
-
17
- module.exports = async function (id, code, name) {
18
- let variables = {
19
- id: id,
20
- attributes: {
21
- code: code?.toString(),
22
- name: name,
23
- },
24
- };
25
-
26
- const res = await this.query(query, variables);
27
- const tenantUpdate = res?.data?.tenantUpdate;
28
-
29
- if (res?.errors) {
30
- throw new Error(res.errors.map((e) => e.message).join());
31
- }
32
-
33
- if (tenantUpdate?.errors) {
34
- throw new Error(tenantUpdate.errors.join());
35
- }
36
-
37
- return tenantUpdate?.tenant;
38
- };
package/src/index.js DELETED
@@ -1,101 +0,0 @@
1
- var assert = require("assert");
2
- var axios = require("axios");
3
-
4
- var Webhooks = require("./webhooks");
5
-
6
- class Bunny {
7
- constructor(options = {}) {
8
- if (!(this instanceof Bunny)) return new Bunny();
9
- assert(options.baseUrl, "Bunny base url required");
10
-
11
- this.options = options;
12
- this.retryEnabled = false;
13
-
14
- if (options.accessToken == undefined) {
15
- assert(options.clientId, "Bunny API clientId required");
16
- assert(options.clientSecret, "Bunny API clientSecret required");
17
- assert(options.scope, "Bunny API scope required");
18
- this.retryEnabled = true;
19
- }
20
-
21
- this.client = axios.create({
22
- headers: {
23
- "User-Agent": "Bunny-node",
24
- },
25
- baseURL: options.baseUrl,
26
- });
27
-
28
- this.client.interceptors.response.use(null, async (error) => {
29
- if (
30
- this.retryEnabled &&
31
- error.config &&
32
- error.response &&
33
- error.response.status === 401 &&
34
- !error.config.retry &&
35
- error.config.url != "/oauth/token"
36
- ) {
37
- const accessToken = await this.fetchAccessToken();
38
- error.config.retry = true;
39
- error.config.headers["Authorization"] = `bearer ${accessToken}`;
40
-
41
- return axios.request(error.config);
42
- }
43
-
44
- if (error.response?.data?.error_description) {
45
- return Promise.reject(error.response.data.error_description);
46
- }
47
-
48
- return Promise.reject(error.response?.data);
49
- });
50
-
51
- this.webhooks = new Webhooks(options.webhookSigningToken);
52
- }
53
-
54
- async fetchAccessToken() {
55
- const params = new URLSearchParams({
56
- grant_type: "client_credentials",
57
- client_id: this.options.clientId,
58
- client_secret: this.options.clientSecret,
59
- scope: this.options.scope,
60
- });
61
-
62
- let res = await this.client.post("/oauth/token", params, {
63
- headers: {
64
- "Content-Type": "application/x-www-form-urlencoded",
65
- },
66
- });
67
-
68
- return res?.data?.access_token;
69
- }
70
-
71
- async query(query, variables) {
72
- let body = {
73
- query,
74
- variables,
75
- };
76
-
77
- if (this.options.accessToken == undefined) {
78
- this.options.accessToken = await this.fetchAccessToken();
79
- }
80
-
81
- let res = await this.client.post("/graphql", body, {
82
- headers: {
83
- Authorization: `bearer ${this.options.accessToken}`,
84
- },
85
- });
86
-
87
- return res.data;
88
- }
89
- }
90
-
91
- Bunny.prototype.subscriptionCreate = require("./helpers/subscription-create.js");
92
- Bunny.prototype.subscriptionCancel = require("./helpers/subscription-cancel.js");
93
- Bunny.prototype.tenantByCode = require("./helpers/tenant-by-code.js");
94
- Bunny.prototype.tenantCreate = require("./helpers/tenant-create.js");
95
- Bunny.prototype.tenantUpdate = require("./helpers/tenant-update.js");
96
- Bunny.prototype.featureUsageCreate = require("./helpers/feature-usage-create.js");
97
- Bunny.prototype.portalSessionCreate = require("./helpers/portal-session-create.js");
98
- Bunny.prototype.accountUpdateByTenantCode = require("./helpers/account-update-by-tenant-code.js");
99
- Bunny.prototype.tenantMetricsUpdate = require("./helpers/tenant-metrics-update.js");
100
-
101
- module.exports = Bunny;
package/src/webhooks.js DELETED
@@ -1,24 +0,0 @@
1
- const crypto = require("crypto");
2
- const scmp = require("scmp");
3
- const Buffer = require("safe-buffer").Buffer;
4
-
5
- class Webhooks {
6
- constructor(signingToken = null) {
7
- this.signingToken = signingToken;
8
- }
9
- validate(signature, payload, signingToken = null) {
10
- let key = signingToken || this.signingToken;
11
-
12
- let payloadSignature = crypto
13
- .createHmac("sha1", key)
14
- .update(JSON.stringify(payload))
15
- .digest("hex");
16
-
17
- const ps = Buffer.from(payloadSignature, "hex");
18
- const s = Buffer.from(signature, "hex");
19
-
20
- return scmp(ps, s);
21
- }
22
- }
23
-
24
- module.exports = Webhooks;