@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
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = tenantMetricsUpdate;
4
+ const query = `mutation tenantMetricsUpdate ($code: String!, $attributes: TenantMetricsAttributes!){
5
+ tenantMetricsUpdate (code: $code, attributes: $attributes) {
6
+ errors
7
+ }
8
+ }`;
9
+ /**
10
+ * Update tenant metrics
11
+ * @param {string} code The code of the tenant
12
+ * @param {string} lastLogin The last login date of the tenant
13
+ * @param {number} userCount The number of users in the tenant
14
+ * @param {Record<string, any>} utilizationMetrics The utilization metrics of the tenant
15
+ **/
16
+ async function tenantMetricsUpdate(code, lastLogin, userCount, utilizationMetrics) {
17
+ var _a;
18
+ let variables = {
19
+ code: code === null || code === void 0 ? void 0 : code.toString(),
20
+ attributes: {
21
+ lastLogin: lastLogin,
22
+ userCount: userCount,
23
+ utilizationMetrics: utilizationMetrics,
24
+ },
25
+ };
26
+ const res = await this.query(query, variables);
27
+ const tenantMetricsUpdate = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.tenantMetricsUpdate;
28
+ if (res === null || res === void 0 ? void 0 : res.errors) {
29
+ throw new Error(res.errors.map((e) => e.message).join());
30
+ }
31
+ if (tenantMetricsUpdate === null || tenantMetricsUpdate === void 0 ? void 0 : tenantMetricsUpdate.errors) {
32
+ throw new Error(tenantMetricsUpdate.errors.join());
33
+ }
34
+ return true;
35
+ }
36
+ //# sourceMappingURL=tenant-metrics-update.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenant-metrics-update.js","sourceRoot":"","sources":["../../src/helpers/tenant-metrics-update.ts"],"names":[],"mappings":";;AAwBA,sCA4BC;AAzCD,MAAM,KAAK,GAAG;;;;EAIZ,CAAC;AAEH;;;;;;GAMG;AACY,KAAK,UAAU,mBAAmB,CAE/C,IAAwB,EACxB,SAAgC,EAChC,SAAyB,EACzB,kBAA+C;;IAE/C,IAAI,SAAS,GAAG;QACd,IAAI,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAAQ,EAAE;QACtB,UAAU,EAAE;YACV,SAAS,EAAE,SAAS;YACpB,SAAS,EAAE,SAAS;YACpB,kBAAkB,EAAE,kBAAkB;SACvC;KACF,CAAC;IAEF,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAC/C,MAAM,mBAAmB,GAAG,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,0CAAE,mBAAmB,CAAC;IAE3D,IAAI,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,IAAI,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,MAAM,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,11 @@
1
+ import Bunny from '../';
2
+ import { Mutation } from '../types/graphql';
3
+ /**
4
+ * Updates an existing tenant
5
+ * @param {string} id The ID of the tenant to update
6
+ * @param {string} code New code for the tenant
7
+ * @param {string} name New name for the tenant
8
+ * @returns {Promise<NonNullable<Mutation['tenantUpdate']>['tenant']>} The updated tenant
9
+ */
10
+ export default function tenantUpdate(this: Bunny, id: string, code?: string, name?: string): Promise<NonNullable<NonNullable<Mutation['tenantUpdate']>['tenant']> | undefined>;
11
+ //# sourceMappingURL=tenant-update.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenant-update.d.ts","sourceRoot":"","sources":["../../src/helpers/tenant-update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAoB,MAAM,kBAAkB,CAAC;AAkB9D;;;;;;GAMG;AACH,wBAA8B,YAAY,CACxC,IAAI,EAAE,KAAK,EACX,EAAE,EAAE,MAAM,EACV,IAAI,CAAC,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,CAAC,CAwBnF"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = tenantUpdate;
4
+ const query = `mutation tenantUpdate ($id: ID!, $attributes: TenantAttributes!) {
5
+ tenantUpdate (id: $id, attributes: $attributes) {
6
+ tenant {
7
+ code
8
+ id
9
+ name
10
+ platform {
11
+ id
12
+ name
13
+ code
14
+ }
15
+ }
16
+ errors
17
+ }
18
+ }`;
19
+ /**
20
+ * Updates an existing tenant
21
+ * @param {string} id The ID of the tenant to update
22
+ * @param {string} code New code for the tenant
23
+ * @param {string} name New name for the tenant
24
+ * @returns {Promise<NonNullable<Mutation['tenantUpdate']>['tenant']>} The updated tenant
25
+ */
26
+ async function tenantUpdate(id, code, name) {
27
+ var _a, _b;
28
+ const variables = {
29
+ id,
30
+ attributes: {
31
+ code: code === null || code === void 0 ? void 0 : code.toString(),
32
+ name,
33
+ },
34
+ };
35
+ const res = await this.query(query, variables);
36
+ const tenantUpdate = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.tenantUpdate;
37
+ if (res === null || res === void 0 ? void 0 : res.errors) {
38
+ throw new Error(res.errors.map((e) => e.message).join());
39
+ }
40
+ if (tenantUpdate === null || tenantUpdate === void 0 ? void 0 : tenantUpdate.errors) {
41
+ throw new Error(tenantUpdate.errors.join());
42
+ }
43
+ return (_b = tenantUpdate === null || tenantUpdate === void 0 ? void 0 : tenantUpdate.tenant) !== null && _b !== void 0 ? _b : undefined;
44
+ }
45
+ //# sourceMappingURL=tenant-update.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenant-update.js","sourceRoot":"","sources":["../../src/helpers/tenant-update.ts"],"names":[],"mappings":";;AA0BA,+BA6BC;AApDD,MAAM,KAAK,GAAG;;;;;;;;;;;;;;EAcZ,CAAC;AAEH;;;;;;GAMG;AACY,KAAK,UAAU,YAAY,CAExC,EAAU,EACV,IAAa,EACb,IAAa;;IAEb,MAAM,SAAS,GAAG;QAChB,EAAE;QACF,UAAU,EAAE;YACV,IAAI,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAAQ,EAAE;YACtB,IAAI;SACe;KACtB,CAAC;IAEF,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAEzB,KAAK,EAAE,SAAS,CAAC,CAAC;IAErB,MAAM,YAAY,GAAG,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,0CAAE,YAAY,CAAC;IAE7C,IAAI,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,IAAI,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,MAAM,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO,MAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,MAAM,mCAAI,SAAS,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,58 @@
1
+ import { AxiosInstance } from "axios";
2
+ import Webhooks from "./webhooks";
3
+ import subscriptionCreate from "./helpers/subscription-create";
4
+ import subscriptionCancel from "./helpers/subscription-cancel";
5
+ import tenantByCode from "./helpers/tenant-by-code";
6
+ import tenantCreate from "./helpers/tenant-create";
7
+ import tenantUpdate from "./helpers/tenant-update";
8
+ import featureUsageCreate from "./helpers/feature-usage-create";
9
+ import portalSessionCreate from "./helpers/portal-session-create";
10
+ import accountUpdateByTenantCode from "./helpers/account-update-by-tenant-code";
11
+ import tenantMetricsUpdate from "./helpers/tenant-metrics-update";
12
+ export * from './types';
13
+ declare module 'axios' {
14
+ interface InternalAxiosRequestConfig {
15
+ retry?: boolean;
16
+ }
17
+ }
18
+ interface BunnyOptions {
19
+ baseUrl?: string;
20
+ accessToken?: string;
21
+ clientId?: string;
22
+ clientSecret?: string;
23
+ scope?: string;
24
+ webhookSigningToken?: string;
25
+ }
26
+ declare class Bunny {
27
+ options: BunnyOptions;
28
+ retryEnabled: boolean;
29
+ client: AxiosInstance;
30
+ webhooks: Webhooks;
31
+ subscriptionCreate: typeof subscriptionCreate;
32
+ subscriptionCancel: typeof subscriptionCancel;
33
+ tenantByCode: typeof tenantByCode;
34
+ tenantCreate: typeof tenantCreate;
35
+ tenantUpdate: typeof tenantUpdate;
36
+ featureUsageCreate: typeof featureUsageCreate;
37
+ portalSessionCreate: typeof portalSessionCreate;
38
+ accountUpdateByTenantCode: typeof accountUpdateByTenantCode;
39
+ tenantMetricsUpdate: typeof tenantMetricsUpdate;
40
+ constructor(options?: BunnyOptions);
41
+ fetchAccessToken(): Promise<string>;
42
+ /**
43
+ * Execute a GraphQL query against the Bunny API
44
+ * @template TData The expected shape of the response data
45
+ * @template TVariables The shape of the variables object
46
+ * @param {string} query The GraphQL query string
47
+ * @param {TVariables} [variables] Optional variables for the query
48
+ * @returns {Promise<{ data?: TData; errors?: Array<{ message: string }> }>}
49
+ */
50
+ query<TData = unknown, TVariables = Record<string, unknown>>(query: string, variables?: TVariables): Promise<{
51
+ data?: TData;
52
+ errors?: Array<{
53
+ message: string;
54
+ }>;
55
+ }>;
56
+ }
57
+ export default Bunny;
58
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAc,EAAE,aAAa,EAA0C,MAAM,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AAC;IAC7D,mBAAmB,EAAG,OAAO,mBAAmB,CAAC;gBAErC,OAAO,GAAE,YAAiB;IA8ChC,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IAiBzC;;;;;;;OAOG;IACG,KAAK,CAAC,KAAK,GAAG,OAAO,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/D,KAAK,EAAE,MAAM,EACb,SAAS,CAAC,EAAE,UAAU,GACrB,OAAO,CAAC;QAAE,IAAI,CAAC,EAAE,KAAK,CAAC;QAAC,MAAM,CAAC,EAAE,KAAK,CAAC;YAAE,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE,CAAC;CAkBlE;AAcD,eAAe,KAAK,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ const assert = require("assert");
21
+ const axios_1 = __importDefault(require("axios"));
22
+ const webhooks_1 = __importDefault(require("./webhooks"));
23
+ // Import your generated GraphQL types
24
+ const subscription_create_1 = __importDefault(require("./helpers/subscription-create"));
25
+ const subscription_cancel_1 = __importDefault(require("./helpers/subscription-cancel"));
26
+ const tenant_by_code_1 = __importDefault(require("./helpers/tenant-by-code"));
27
+ const tenant_create_1 = __importDefault(require("./helpers/tenant-create"));
28
+ const tenant_update_1 = __importDefault(require("./helpers/tenant-update"));
29
+ const feature_usage_create_1 = __importDefault(require("./helpers/feature-usage-create"));
30
+ const portal_session_create_1 = __importDefault(require("./helpers/portal-session-create"));
31
+ const account_update_by_tenant_code_1 = __importDefault(require("./helpers/account-update-by-tenant-code"));
32
+ const tenant_metrics_update_1 = __importDefault(require("./helpers/tenant-metrics-update"));
33
+ // Export all types for consumers
34
+ __exportStar(require("./types"), exports);
35
+ class Bunny {
36
+ constructor(options = {}) {
37
+ if (!(this instanceof Bunny))
38
+ return new Bunny(options);
39
+ assert(options.baseUrl, "Bunny base url required");
40
+ this.options = options;
41
+ this.retryEnabled = false;
42
+ if (!options.accessToken) {
43
+ assert(options.clientId, "Bunny API clientId required");
44
+ assert(options.clientSecret, "Bunny API clientSecret required");
45
+ assert(options.scope, "Bunny API scope required");
46
+ this.retryEnabled = true;
47
+ }
48
+ this.client = axios_1.default.create({
49
+ headers: {
50
+ "User-Agent": "Bunny-node",
51
+ },
52
+ baseURL: options.baseUrl,
53
+ });
54
+ this.client.interceptors.response.use(null, async (error) => {
55
+ var _a, _b, _c;
56
+ if (this.retryEnabled &&
57
+ error.config &&
58
+ error.response &&
59
+ error.response.status === 401 &&
60
+ !error.config.retry &&
61
+ error.config.url !== "/oauth/token") {
62
+ const accessToken = await this.fetchAccessToken();
63
+ error.config.retry = true;
64
+ error.config.headers["Authorization"] = `bearer ${accessToken}`;
65
+ return axios_1.default.request(error.config);
66
+ }
67
+ if ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error_description) {
68
+ return Promise.reject(error.response.data.error_description);
69
+ }
70
+ return Promise.reject((_c = error.response) === null || _c === void 0 ? void 0 : _c.data);
71
+ });
72
+ this.webhooks = new webhooks_1.default(options.webhookSigningToken);
73
+ }
74
+ async fetchAccessToken() {
75
+ var _a;
76
+ const params = new URLSearchParams({
77
+ grant_type: "client_credentials",
78
+ client_id: this.options.clientId,
79
+ client_secret: this.options.clientSecret,
80
+ scope: this.options.scope,
81
+ });
82
+ const res = await this.client.post("/oauth/token", params, {
83
+ headers: {
84
+ "Content-Type": "application/x-www-form-urlencoded",
85
+ },
86
+ });
87
+ return (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.access_token;
88
+ }
89
+ /**
90
+ * Execute a GraphQL query against the Bunny API
91
+ * @template TData The expected shape of the response data
92
+ * @template TVariables The shape of the variables object
93
+ * @param {string} query The GraphQL query string
94
+ * @param {TVariables} [variables] Optional variables for the query
95
+ * @returns {Promise<{ data?: TData; errors?: Array<{ message: string }> }>}
96
+ */
97
+ async query(query, variables) {
98
+ const body = {
99
+ query,
100
+ variables,
101
+ };
102
+ if (!this.options.accessToken) {
103
+ this.options.accessToken = await this.fetchAccessToken();
104
+ }
105
+ const res = await this.client.post("/graphql", body, {
106
+ headers: {
107
+ Authorization: `bearer ${this.options.accessToken}`,
108
+ },
109
+ });
110
+ return res.data;
111
+ }
112
+ }
113
+ // Attach helper methods (you'll need to type these too, see below)
114
+ Bunny.prototype.subscriptionCreate = subscription_create_1.default;
115
+ Bunny.prototype.subscriptionCancel = subscription_cancel_1.default;
116
+ Bunny.prototype.tenantByCode = tenant_by_code_1.default;
117
+ Bunny.prototype.tenantCreate = tenant_create_1.default;
118
+ Bunny.prototype.tenantUpdate = tenant_update_1.default;
119
+ Bunny.prototype.featureUsageCreate = feature_usage_create_1.default;
120
+ Bunny.prototype.portalSessionCreate = portal_session_create_1.default;
121
+ Bunny.prototype.accountUpdateByTenantCode = account_update_by_tenant_code_1.default;
122
+ Bunny.prototype.tenantMetricsUpdate = tenant_metrics_update_1.default;
123
+ // Support both default export and CommonJS module.exports
124
+ exports.default = Bunny;
125
+ module.exports = Bunny;
126
+ module.exports.default = Bunny;
127
+ //# source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kBAAe,KAAK,CAAC;AACrB,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC;AACvB,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from '../generated/graphql';
2
+ //# sourceMappingURL=graphql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/types/graphql.ts"],"names":[],"mappings":"AACA,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ // Re-export all generated GraphQL types
18
+ __exportStar(require("../generated/graphql"), exports);
19
+ //# sourceMappingURL=graphql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql.js","sourceRoot":"","sources":["../../src/types/graphql.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAwC;AACxC,uDAAqC"}
@@ -0,0 +1,2 @@
1
+ export * from './graphql';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./graphql"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B"}
@@ -0,0 +1,7 @@
1
+ declare class Webhooks {
2
+ private signingToken;
3
+ constructor(signingToken?: string | null);
4
+ validate(signature: string, payload: unknown, signingToken?: string | null): boolean;
5
+ }
6
+ export default Webhooks;
7
+ //# sourceMappingURL=webhooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../src/webhooks.ts"],"names":[],"mappings":"AAGA,cAAM,QAAQ;IACZ,OAAO,CAAC,YAAY,CAAgB;gBAExB,YAAY,GAAE,MAAM,GAAG,IAAW;IAI9C,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,GAAE,MAAM,GAAG,IAAW,GAAG,OAAO;CAsB3F;AAED,eAAe,QAAQ,CAAC"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const crypto_1 = __importDefault(require("crypto"));
7
+ const buffer_1 = require("buffer");
8
+ class Webhooks {
9
+ constructor(signingToken = null) {
10
+ this.signingToken = signingToken;
11
+ }
12
+ validate(signature, payload, signingToken = null) {
13
+ const key = signingToken || this.signingToken;
14
+ if (!key) {
15
+ throw new Error('Signing token is required');
16
+ }
17
+ const payloadSignature = crypto_1.default
18
+ .createHmac('sha1', key)
19
+ .update(JSON.stringify(payload))
20
+ .digest('hex');
21
+ const ps = buffer_1.Buffer.from(payloadSignature, 'hex');
22
+ const s = buffer_1.Buffer.from(signature, 'hex');
23
+ // Ensure buffers are the same length before comparison
24
+ if (ps.length !== s.length) {
25
+ return false;
26
+ }
27
+ return crypto_1.default.timingSafeEqual(ps, s);
28
+ }
29
+ }
30
+ exports.default = Webhooks;
31
+ //# sourceMappingURL=webhooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../src/webhooks.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAC5B,mCAAgC;AAEhC,MAAM,QAAQ;IAGZ,YAAY,eAA8B,IAAI;QAC5C,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED,QAAQ,CAAC,SAAiB,EAAE,OAAgB,EAAE,eAA8B,IAAI;QAC9E,MAAM,GAAG,GAAG,YAAY,IAAI,IAAI,CAAC,YAAY,CAAC;QAE9C,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC/C,CAAC;QAED,MAAM,gBAAgB,GAAG,gBAAM;aAC5B,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC;aACvB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;aAC/B,MAAM,CAAC,KAAK,CAAC,CAAC;QAEjB,MAAM,EAAE,GAAG,eAAM,CAAC,IAAI,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;QAChD,MAAM,CAAC,GAAG,eAAM,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAExC,uDAAuD;QACvD,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;YAC3B,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,gBAAM,CAAC,eAAe,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IACvC,CAAC;CACF;AAED,kBAAe,QAAQ,CAAC"}
package/package.json CHANGED
@@ -1,13 +1,19 @@
1
1
  {
2
2
  "name": "@bunnyapp/api-client",
3
- "version": "2.2.4",
3
+ "version": "3.0.0",
4
4
  "description": "Node.js client for Bunny CRM",
5
- "main": "index.js",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
6
7
  "directories": {
7
8
  "test": "tests"
8
9
  },
9
10
  "scripts": {
10
- "test": "node_modules/.bin/mocha"
11
+ "build": "tsc",
12
+ "clean": "rm -rf dist",
13
+ "prepare": "npm run clean && npm run build",
14
+ "prepublishOnly": "npm run build",
15
+ "test": "mocha -r ts-node/register 'tests/**/*.ts'",
16
+ "generate-types": "node_modules/.bin/graphql-codegen"
11
17
  },
12
18
  "repository": {
13
19
  "type": "git",
@@ -27,18 +33,29 @@
27
33
  },
28
34
  "homepage": "https://github.com/bunnyapp/bunny-node#readme",
29
35
  "dependencies": {
30
- "axios": "^1.6.2",
36
+ "axios": "^1.8.4",
31
37
  "safe-buffer": "^5.2.1",
32
38
  "scmp": "^2.1.0"
33
39
  },
34
40
  "devDependencies": {
35
- "mocha": "^9.2.0",
36
- "sinon": "^14.0.0"
41
+ "@0no-co/graphqlsp": "^1.12.16",
42
+ "@graphql-codegen/cli": "^5.0.5",
43
+ "@graphql-codegen/schema-ast": "^4.1.0",
44
+ "@graphql-codegen/typescript": "^4.1.6",
45
+ "@graphql-codegen/typescript-operations": "^4.6.0",
46
+ "@graphql-typed-document-node/core": "^3.2.0",
47
+ "@parcel/watcher": "^2.5.1",
48
+ "@types/mocha": "^10.0.10",
49
+ "@types/sinon": "^17.0.4",
50
+ "dotenv": "^16.4.7",
51
+ "mocha": "^11.1.0",
52
+ "sinon": "^14.0.0",
53
+ "ts-node": "^10.9.2",
54
+ "typescript": "^5.8.2"
37
55
  },
38
56
  "files": [
57
+ "dist/**/*",
39
58
  "LICENSE",
40
- "README.md",
41
- "index.js",
42
- "src/"
59
+ "README.md"
43
60
  ]
44
61
  }
package/index.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require("./src");
@@ -1,63 +0,0 @@
1
- const query = `mutation accountUpdate ($id: ID!, $attributes: AccountAttributes!) {
2
- accountUpdate (id: $id, attributes: $attributes) {
3
- account {
4
- accountTypeId
5
- addressValidated
6
- annualRevenue
7
- billingCity
8
- billingContactId
9
- billingCountry
10
- billingDay
11
- billingState
12
- billingStreet
13
- billingZip
14
- code
15
- createdAt
16
- currencyId
17
- description
18
- duns
19
- employees
20
- entityUseCode
21
- fax
22
- groupId
23
- id
24
- industryId
25
- name
26
- netPaymentDays
27
- ownerUserId
28
- phone
29
- shippingCity
30
- shippingCountry
31
- shippingState
32
- shippingStreet
33
- shippingZip
34
- taxNumber
35
- timezone
36
- updatedAt
37
- website
38
- }
39
- errors
40
- }
41
- }`;
42
-
43
- module.exports = async function (tenantCode, attributes) {
44
- let tenant = await this.tenantByCode(tenantCode);
45
-
46
- let variables = {
47
- id: tenant.account.id,
48
- attributes: attributes,
49
- };
50
-
51
- const res = await this.query(query, variables);
52
- const accountUpdate = res?.data?.accountUpdate;
53
-
54
- if (res?.errors) {
55
- throw new Error(res.errors.map((e) => e.message).join());
56
- }
57
-
58
- if (accountUpdate?.errors) {
59
- throw new Error(accountUpdate.errors.join());
60
- }
61
-
62
- return accountUpdate?.account;
63
- };
@@ -1,58 +0,0 @@
1
- const query = `mutation featureUsageCreate ($attributes: FeatureUsageAttributes!) {
2
- featureUsageCreate (attributes: $attributes) {
3
- errors
4
- featureUsage {
5
- id
6
- quantity
7
- usageAt
8
- subscription {
9
- id
10
- }
11
- feature {
12
- id
13
- code
14
- name
15
- }
16
- }
17
- }
18
- }`;
19
-
20
- /**
21
- * Record feature usage for a subscription
22
- * @param {string} featureCode Code for the feature that is being used
23
- * @param {number} quantity Amount of usage to record
24
- * @param {number} subscriptionId ID of the subscription that has the usage
25
- * @param {string} usageAt ISO8601 date string. Deafults to now
26
- * @returns
27
- */
28
- module.exports = async function (
29
- featureCode,
30
- quantity,
31
- subscriptionId,
32
- usageAt = null
33
- ) {
34
- let variables = {
35
- attributes: {
36
- quantity: quantity,
37
- subscriptionId: subscriptionId,
38
- featureCode: featureCode,
39
- },
40
- };
41
-
42
- if (usageAt) {
43
- variables["attributes"]["usageAt"] = usageAt;
44
- }
45
-
46
- const res = await this.query(query, variables);
47
- const featureUsageCreate = res?.data?.featureUsageCreate;
48
-
49
- if (res?.errors) {
50
- throw new Error(res.errors.map((e) => e.message).join());
51
- }
52
-
53
- if (featureUsageCreate?.errors) {
54
- throw new Error(featureUsageCreate.errors.join());
55
- }
56
-
57
- return featureUsageCreate?.featureUsage;
58
- };
@@ -1,38 +0,0 @@
1
- const query = `mutation portalSessionCreate ($tenantCode: String!, $expiry: Int!, $returnUrl: String!) {
2
- portalSessionCreate (tenantCode: $tenantCode, expiry: $expiry, returnUrl: $returnUrl) {
3
- errors
4
- token
5
- }
6
- }`;
7
-
8
- /**
9
- * Generate a session token for customer portal
10
- * @param {string} tenantCode The unique code that represents the tenant
11
- * @param {string} returnUrl A URL to redirect the user back to the original app after using the portal
12
- * @param {number} expiryInHours Length of time in hours before the token expires. Deafults to 24
13
- * @returns {string} The session token
14
- */
15
- module.exports = async function (
16
- tenantCode,
17
- returnUrl = null,
18
- expiryInHours = 24
19
- ) {
20
- let variables = {
21
- tenantCode: tenantCode,
22
- returnUrl: returnUrl,
23
- expiry: expiryInHours,
24
- };
25
-
26
- const res = await this.query(query, variables);
27
- const portalSessionCreate = res?.data?.portalSessionCreate;
28
-
29
- if (res?.errors) {
30
- throw new Error(res.errors.map((e) => e.message).join());
31
- }
32
-
33
- if (portalSessionCreate?.errors) {
34
- throw new Error(portalSessionCreate.errors.join());
35
- }
36
-
37
- return portalSessionCreate?.token;
38
- };