@bunnyapp/api-client 2.2.3 → 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 (70) 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/product-create.js +0 -40
  64. package/src/helpers/subscription-cancel.js +0 -29
  65. package/src/helpers/subscription-create.js +0 -107
  66. package/src/helpers/tenant-create.js +0 -55
  67. package/src/helpers/tenant-metrics-update.js +0 -34
  68. package/src/helpers/tenant-update.js +0 -38
  69. package/src/index.js +0 -102
  70. package/src/webhooks.js +0 -24
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=graphql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql.js","sourceRoot":"","sources":["../../src/generated/graphql.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import { AccountAttributes, Mutation } from '../generated/graphql';
2
+ import Bunny from '../';
3
+ /**
4
+ * Update an account by tenant code
5
+ * @param {string} tenantCode The unique code that represents the tenant
6
+ * @param {AccountAttributes} attributes The attributes to update the account with
7
+ * @returns {Promise<NonNullable<NonNullable<Mutation['accountUpdate']>['account']> | undefined>} The updated account
8
+ */
9
+ export default function accountUpdateByTenantCode(this: Bunny, tenantCode: string, attributes: AccountAttributes): Promise<NonNullable<NonNullable<Mutation['accountUpdate']>['account']> | undefined>;
10
+ //# sourceMappingURL=account-update-by-tenant-code.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-update-by-tenant-code.d.ts","sourceRoot":"","sources":["../../src/helpers/account-update-by-tenant-code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,iBAAiB,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,KAAK,MAAM,KAAK,CAAC;AA4CxB;;;;;GAKG;AACH,wBAA8B,yBAAyB,CAAC,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC,CA0B3M"}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = accountUpdateByTenantCode;
4
+ const query = `mutation accountUpdate ($id: ID!, $attributes: AccountAttributes!) {
5
+ accountUpdate (id: $id, attributes: $attributes) {
6
+ account {
7
+ accountTypeId
8
+ addressValidated
9
+ annualRevenue
10
+ billingCity
11
+ billingContactId
12
+ billingCountry
13
+ billingDay
14
+ billingState
15
+ billingStreet
16
+ billingZip
17
+ code
18
+ createdAt
19
+ currencyId
20
+ description
21
+ duns
22
+ employees
23
+ entityUseCode
24
+ fax
25
+ groupId
26
+ id
27
+ industryId
28
+ name
29
+ netPaymentDays
30
+ ownerUserId
31
+ phone
32
+ shippingCity
33
+ shippingCountry
34
+ shippingState
35
+ shippingStreet
36
+ shippingZip
37
+ taxNumber
38
+ timezone
39
+ updatedAt
40
+ website
41
+ }
42
+ errors
43
+ }
44
+ }`;
45
+ /**
46
+ * Update an account by tenant code
47
+ * @param {string} tenantCode The unique code that represents the tenant
48
+ * @param {AccountAttributes} attributes The attributes to update the account with
49
+ * @returns {Promise<NonNullable<NonNullable<Mutation['accountUpdate']>['account']> | undefined>} The updated account
50
+ */
51
+ async function accountUpdateByTenantCode(tenantCode, attributes) {
52
+ var _a, _b;
53
+ const tenant = await this.tenantByCode(tenantCode);
54
+ if (!tenant) {
55
+ throw new Error('Tenant not found');
56
+ }
57
+ const variables = {
58
+ id: tenant.account.id,
59
+ attributes: attributes,
60
+ };
61
+ const res = await this.query(query, variables);
62
+ const accountUpdate = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.accountUpdate;
63
+ if (res === null || res === void 0 ? void 0 : res.errors) {
64
+ throw new Error(Array.isArray(res.errors) ? res.errors.map(e => e.message).join() : res.errors);
65
+ }
66
+ if (accountUpdate === null || accountUpdate === void 0 ? void 0 : accountUpdate.errors) {
67
+ throw new Error(Array.isArray(accountUpdate.errors) ? accountUpdate.errors.join() : accountUpdate.errors);
68
+ }
69
+ return (_b = accountUpdate === null || accountUpdate === void 0 ? void 0 : accountUpdate.account) !== null && _b !== void 0 ? _b : undefined;
70
+ }
71
+ //# sourceMappingURL=account-update-by-tenant-code.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-update-by-tenant-code.js","sourceRoot":"","sources":["../../src/helpers/account-update-by-tenant-code.ts"],"names":[],"mappings":";;AAmDA,4CA0BC;AA1ED,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwCZ,CAAC;AAEH;;;;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../';
2
+ import { Mutation } from '../types/graphql';
3
+ /**
4
+ * Record feature usage for a subscription
5
+ * @param {string} featureCode Code for the feature that is being used
6
+ * @param {number} quantity Amount of usage to record
7
+ * @param {string} subscriptionId ID of the subscription that has the usage
8
+ * @param {string} usageAt ISO8601 date string. Defaults to now
9
+ * @returns {Promise<NonNullable<NonNullable<Mutation['featureUsageCreate']>['featureUsage']>>}
10
+ */
11
+ export default function featureUsageCreate(this: Bunny, featureCode: string, quantity: number, subscriptionId: string, usageAt?: string | null): Promise<NonNullable<NonNullable<Mutation['featureUsageCreate']>['featureUsage']>>;
12
+ //# sourceMappingURL=feature-usage-create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature-usage-create.d.ts","sourceRoot":"","sources":["../../src/helpers/feature-usage-create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAA0B,MAAM,kBAAkB,CAAC;AAqBpE;;;;;;;GAOG;AACH,wBAA8B,kBAAkB,CAC9C,IAAI,EAAE,KAAK,EACX,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,EACtB,OAAO,GAAE,MAAM,GAAG,IAAW,GAC5B,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAkCnF"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = featureUsageCreate;
4
+ const query = `mutation featureUsageCreate ($attributes: FeatureUsageAttributes!) {
5
+ featureUsageCreate (attributes: $attributes) {
6
+ errors
7
+ featureUsage {
8
+ id
9
+ quantity
10
+ usageAt
11
+ subscription {
12
+ id
13
+ }
14
+ feature {
15
+ id
16
+ code
17
+ name
18
+ }
19
+ }
20
+ }
21
+ }`;
22
+ /**
23
+ * Record feature usage for a subscription
24
+ * @param {string} featureCode Code for the feature that is being used
25
+ * @param {number} quantity Amount of usage to record
26
+ * @param {string} subscriptionId ID of the subscription that has the usage
27
+ * @param {string} usageAt ISO8601 date string. Defaults to now
28
+ * @returns {Promise<NonNullable<NonNullable<Mutation['featureUsageCreate']>['featureUsage']>>}
29
+ */
30
+ async function featureUsageCreate(featureCode, quantity, subscriptionId, usageAt = null) {
31
+ var _a;
32
+ const variables = {
33
+ attributes: {
34
+ quantity,
35
+ subscriptionId,
36
+ featureCode,
37
+ },
38
+ };
39
+ if (usageAt) {
40
+ variables.attributes.usageAt = usageAt;
41
+ }
42
+ const res = await this.query(query, variables);
43
+ const featureUsageCreate = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.featureUsageCreate;
44
+ if (res === null || res === void 0 ? void 0 : res.errors) {
45
+ throw new Error(Array.isArray(res.errors) ? res.errors.map(e => e.message).join() : res.errors);
46
+ }
47
+ if (featureUsageCreate === null || featureUsageCreate === void 0 ? void 0 : featureUsageCreate.errors) {
48
+ throw new Error(Array.isArray(featureUsageCreate.errors) ? featureUsageCreate.errors.join() : featureUsageCreate.errors);
49
+ }
50
+ if (!(featureUsageCreate === null || featureUsageCreate === void 0 ? void 0 : featureUsageCreate.featureUsage)) {
51
+ throw new Error('Feature usage not created');
52
+ }
53
+ return featureUsageCreate.featureUsage;
54
+ }
55
+ //# sourceMappingURL=feature-usage-create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature-usage-create.js","sourceRoot":"","sources":["../../src/helpers/feature-usage-create.ts"],"names":[],"mappings":";;AA8BA,qCAwCC;AAnED,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;EAiBZ,CAAC;AAEH;;;;;;;GAOG;AACY,KAAK,UAAU,kBAAkB,CAE9C,WAAmB,EACnB,QAAgB,EAChB,cAAsB,EACtB,UAAyB,IAAI;;IAE7B,MAAM,SAAS,GAEX;QACF,UAAU,EAAE;YACV,QAAQ;YACR,cAAc;YACd,WAAW;SACZ;KACF,CAAC;IAEF,IAAI,OAAO,EAAE,CAAC;QACZ,SAAS,CAAC,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;IACzC,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAEzB,KAAK,EAAE,SAAS,CAAC,CAAC;IAErB,MAAM,kBAAkB,GAAG,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,0CAAE,kBAAkB,CAAC;IAEzD,IAAI,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAClG,CAAC;IAED,IAAI,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,CAAE,MAAM,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC3H,CAAC;IAED,IAAI,CAAC,CAAA,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,CAAE,YAAY,CAAA,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,kBAAkB,CAAC,YAAY,CAAC;AACzC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import Bunny from '../';
2
+ /**
3
+ * Generate a session token for customer portal
4
+ * @param {string} tenantCode The unique code that represents the tenant
5
+ * @param {string} returnUrl A URL to redirect the user back to the original app after using the portal
6
+ * @param {number} expiryInHours Length of time in hours before the token expires. Defaults to 24
7
+ * @returns {Promise<string>} The session token
8
+ */
9
+ export default function portalSessionCreate(this: Bunny, tenantCode: string, returnUrl?: string, expiryInHours?: number): Promise<string>;
10
+ //# sourceMappingURL=portal-session-create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portal-session-create.d.ts","sourceRoot":"","sources":["../../src/helpers/portal-session-create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,KAAK,CAAC;AAUxB;;;;;;GAMG;AACH,wBAA8B,mBAAmB,CAC/C,IAAI,EAAE,KAAK,EACX,UAAU,EAAE,MAAM,EAClB,SAAS,GAAE,MAAW,EACtB,aAAa,GAAE,MAAW,GACzB,OAAO,CAAC,MAAM,CAAC,CA0BjB"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = portalSessionCreate;
4
+ const query = `mutation portalSessionCreate ($tenantCode: String!, $expiry: Int!, $returnUrl: String!) {
5
+ portalSessionCreate (tenantCode: $tenantCode, expiry: $expiry, returnUrl: $returnUrl) {
6
+ errors
7
+ token
8
+ }
9
+ }`;
10
+ /**
11
+ * Generate a session token for customer portal
12
+ * @param {string} tenantCode The unique code that represents the tenant
13
+ * @param {string} returnUrl A URL to redirect the user back to the original app after using the portal
14
+ * @param {number} expiryInHours Length of time in hours before the token expires. Defaults to 24
15
+ * @returns {Promise<string>} The session token
16
+ */
17
+ async function portalSessionCreate(tenantCode, returnUrl = '', expiryInHours = 24) {
18
+ var _a;
19
+ const variables = {
20
+ tenantCode,
21
+ returnUrl,
22
+ expiry: expiryInHours,
23
+ };
24
+ const res = await this.query(query, variables);
25
+ const portalSessionCreate = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.portalSessionCreate;
26
+ if (res === null || res === void 0 ? void 0 : res.errors) {
27
+ throw new Error(Array.isArray(res.errors) ? res.errors.map(e => e.message).join() : res.errors);
28
+ }
29
+ if (portalSessionCreate === null || portalSessionCreate === void 0 ? void 0 : portalSessionCreate.errors) {
30
+ throw new Error(Array.isArray(portalSessionCreate.errors) ? portalSessionCreate.errors.join() : portalSessionCreate.errors);
31
+ }
32
+ if (!(portalSessionCreate === null || portalSessionCreate === void 0 ? void 0 : portalSessionCreate.token)) {
33
+ throw new Error('No token returned from portal session creation');
34
+ }
35
+ return portalSessionCreate.token;
36
+ }
37
+ //# sourceMappingURL=portal-session-create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portal-session-create.js","sourceRoot":"","sources":["../../src/helpers/portal-session-create.ts"],"names":[],"mappings":";;AAiBA,sCA+BC;AA7CD,MAAM,KAAK,GAAG;;;;;EAKZ,CAAC;AAEH;;;;;;GAMG;AACY,KAAK,UAAU,mBAAmB,CAE/C,UAAkB,EAClB,YAAoB,EAAE,EACtB,gBAAwB,EAAE;;IAE1B,MAAM,SAAS,GAAG;QAChB,UAAU;QACV,SAAS;QACT,MAAM,EAAE,aAAa;KACtB,CAAC;IAEF,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAEzB,KAAK,EAAE,SAAS,CAAC,CAAC;IAErB,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,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAClG,CAAC;IAED,IAAI,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,MAAM,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC9H,CAAC;IAED,IAAI,CAAC,CAAA,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,KAAK,CAAA,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IAED,OAAO,mBAAmB,CAAC,KAAK,CAAC;AACnC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import Bunny from '../';
2
+ /**
3
+ * Cancel a subscription
4
+ * @param {number} subscriptionId The subscription ID
5
+ * @returns {Promise<boolean>} True if the subscription was cancelled, false otherwise
6
+ */
7
+ export default function subscriptionCancel(this: Bunny, subscriptionId: number): Promise<boolean>;
8
+ //# sourceMappingURL=subscription-cancel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription-cancel.d.ts","sourceRoot":"","sources":["../../src/helpers/subscription-cancel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,KAAK,CAAC;AASxB;;;;GAIG;AACH,wBAA8B,kBAAkB,CAC9C,IAAI,EAAE,KAAK,EACX,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,OAAO,CAAC,CAoBlB"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = subscriptionCancel;
4
+ const query = `mutation subscriptionCancel ($ids: [ID!]!) {
5
+ subscriptionCancel (ids: $ids) {
6
+ errors
7
+ }
8
+ }`;
9
+ /**
10
+ * Cancel a subscription
11
+ * @param {number} subscriptionId The subscription ID
12
+ * @returns {Promise<boolean>} True if the subscription was cancelled, false otherwise
13
+ */
14
+ async function subscriptionCancel(subscriptionId) {
15
+ var _a;
16
+ const variables = {
17
+ id: subscriptionId,
18
+ };
19
+ const res = await this.query(query, variables);
20
+ const subscriptionCancel = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.subscriptionCancel;
21
+ if (res === null || res === void 0 ? void 0 : res.errors) {
22
+ throw new Error(Array.isArray(res.errors) ? res.errors.map(e => e.message).join() : res.errors);
23
+ }
24
+ if (subscriptionCancel === null || subscriptionCancel === void 0 ? void 0 : subscriptionCancel.errors) {
25
+ throw new Error(Array.isArray(subscriptionCancel.errors) ? subscriptionCancel.errors.join() : subscriptionCancel.errors);
26
+ }
27
+ return true;
28
+ }
29
+ //# sourceMappingURL=subscription-cancel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription-cancel.js","sourceRoot":"","sources":["../../src/helpers/subscription-cancel.ts"],"names":[],"mappings":";;AAcA,qCAuBC;AAlCD,MAAM,KAAK,GAAG;;;;EAIZ,CAAC;AAEH;;;;GAIG;AACY,KAAK,UAAU,kBAAkB,CAE9C,cAAsB;;IAEtB,MAAM,SAAS,GAAG;QAChB,EAAE,EAAE,cAAc;KACnB,CAAC;IAEF,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAEzB,KAAK,EAAE,SAAS,CAAC,CAAC;IAErB,MAAM,kBAAkB,GAAG,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,0CAAE,kBAAkB,CAAC;IAEzD,IAAI,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAClG,CAAC;IAED,IAAI,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,CAAE,MAAM,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC3H,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,39 @@
1
+ import Bunny from '../';
2
+ import { Mutation } from '../types/graphql';
3
+ interface SubscriptionOptions {
4
+ trial?: boolean;
5
+ evergreen?: boolean;
6
+ accountId?: string;
7
+ accountName?: string;
8
+ ownerUserId?: string;
9
+ phone?: string;
10
+ fax?: string;
11
+ website?: string;
12
+ billingStreet?: string;
13
+ billingCity?: string;
14
+ billingZip?: string;
15
+ billingState?: string;
16
+ billingCountry?: string;
17
+ firstName?: string;
18
+ lastName?: string;
19
+ email?: string;
20
+ mobile?: string;
21
+ salutation?: string;
22
+ title?: string;
23
+ mailingStreet?: string;
24
+ mailingCity?: string;
25
+ mailingZip?: string;
26
+ mailingState?: string;
27
+ mailingCountry?: string;
28
+ tenantCode?: string;
29
+ tenantName?: string;
30
+ }
31
+ /**
32
+ * Create a subscription
33
+ * @param {string} priceListCode The unique code that represents the price list
34
+ * @param {SubscriptionOptions} [options={}] Additional options for subscription creation
35
+ * @returns {Promise<NonNullable<NonNullable<Mutation['subscriptionCreate']>['subscription']>>} The created subscription
36
+ */
37
+ export default function subscriptionCreate(this: Bunny, priceListCode: string, options?: SubscriptionOptions): Promise<NonNullable<NonNullable<Mutation['subscriptionCreate']>['subscription']>>;
38
+ export {};
39
+ //# sourceMappingURL=subscription-create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription-create.d.ts","sourceRoot":"","sources":["../../src/helpers/subscription-create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,KAAK,CA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,CAAC,CAyEnF"}
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = subscriptionCreate;
4
+ const query = `mutation subscriptionCreate ($attributes: SubscriptionAttributes!) {
5
+ subscriptionCreate (attributes: $attributes) {
6
+ subscription {
7
+ id
8
+ account {
9
+ id
10
+ name
11
+ contacts {
12
+ id
13
+ firstName
14
+ lastName
15
+ }
16
+ }
17
+ trialStartDate
18
+ trialEndDate
19
+ startDate
20
+ endDate
21
+ state
22
+ plan {
23
+ code
24
+ name
25
+ }
26
+ priceList {
27
+ code
28
+ name
29
+ }
30
+ tenant {
31
+ id
32
+ code
33
+ name
34
+ account {
35
+ id
36
+ name
37
+ billingDay
38
+ }
39
+ }
40
+ }
41
+ errors
42
+ }
43
+ }`;
44
+ /**
45
+ * Create a subscription
46
+ * @param {string} priceListCode The unique code that represents the price list
47
+ * @param {SubscriptionOptions} [options={}] Additional options for subscription creation
48
+ * @returns {Promise<NonNullable<NonNullable<Mutation['subscriptionCreate']>['subscription']>>} The created subscription
49
+ */
50
+ async function subscriptionCreate(priceListCode, options = {}) {
51
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
52
+ const variables = {
53
+ attributes: {
54
+ priceListCode,
55
+ trial: options.trial || false,
56
+ evergreen: (_a = options.evergreen) !== null && _a !== void 0 ? _a : true,
57
+ },
58
+ };
59
+ if (options.accountId) {
60
+ variables.attributes.accountId = options.accountId;
61
+ }
62
+ else {
63
+ const billingContact = {
64
+ firstName: (_b = options.firstName) === null || _b === void 0 ? void 0 : _b.toString(),
65
+ lastName: (_c = options.lastName) === null || _c === void 0 ? void 0 : _c.toString(),
66
+ email: (_d = options.email) === null || _d === void 0 ? void 0 : _d.toString(),
67
+ phone: (_e = options.phone) === null || _e === void 0 ? void 0 : _e.toString(),
68
+ mobile: (_f = options.mobile) === null || _f === void 0 ? void 0 : _f.toString(),
69
+ salutation: (_g = options.salutation) === null || _g === void 0 ? void 0 : _g.toString(),
70
+ title: (_h = options.title) === null || _h === void 0 ? void 0 : _h.toString(),
71
+ mailingStreet: (_j = options.mailingStreet) === null || _j === void 0 ? void 0 : _j.toString(),
72
+ mailingCity: (_k = options.mailingCity) === null || _k === void 0 ? void 0 : _k.toString(),
73
+ mailingZip: (_l = options.mailingZip) === null || _l === void 0 ? void 0 : _l.toString(),
74
+ mailingState: (_m = options.mailingState) === null || _m === void 0 ? void 0 : _m.toString(),
75
+ mailingCountry: (_o = options.mailingCountry) === null || _o === void 0 ? void 0 : _o.toString(),
76
+ };
77
+ // Only include non-empty billing contact
78
+ const filteredBillingContact = Object.fromEntries(Object.entries(billingContact).filter(([_, value]) => value !== undefined));
79
+ variables.attributes.account = {
80
+ name: (_p = options.accountName) === null || _p === void 0 ? void 0 : _p.toString(),
81
+ ownerUserId: (_q = options.ownerUserId) === null || _q === void 0 ? void 0 : _q.toString(),
82
+ phone: (_r = options.phone) === null || _r === void 0 ? void 0 : _r.toString(),
83
+ fax: (_s = options.fax) === null || _s === void 0 ? void 0 : _s.toString(),
84
+ website: (_t = options.website) === null || _t === void 0 ? void 0 : _t.toString(),
85
+ billingStreet: (_u = options.billingStreet) === null || _u === void 0 ? void 0 : _u.toString(),
86
+ billingCity: (_v = options.billingCity) === null || _v === void 0 ? void 0 : _v.toString(),
87
+ billingZip: (_w = options.billingZip) === null || _w === void 0 ? void 0 : _w.toString(),
88
+ billingState: (_x = options.billingState) === null || _x === void 0 ? void 0 : _x.toString(),
89
+ billingCountry: (_y = options.billingCountry) === null || _y === void 0 ? void 0 : _y.toString(),
90
+ ...(Object.keys(filteredBillingContact).length > 0 && { billingContact: filteredBillingContact }),
91
+ };
92
+ }
93
+ if (options.tenantCode) {
94
+ variables.attributes.tenant = {
95
+ code: options.tenantCode.toString(),
96
+ name: (_z = options.tenantName) === null || _z === void 0 ? void 0 : _z.toString(),
97
+ };
98
+ }
99
+ const res = await this.query(query, variables);
100
+ const subscriptionCreate = (_0 = res === null || res === void 0 ? void 0 : res.data) === null || _0 === void 0 ? void 0 : _0.subscriptionCreate;
101
+ if (res === null || res === void 0 ? void 0 : res.errors) {
102
+ throw new Error(Array.isArray(res.errors) ? res.errors.map(e => e.message).join() : res.errors);
103
+ }
104
+ if (subscriptionCreate === null || subscriptionCreate === void 0 ? void 0 : subscriptionCreate.errors) {
105
+ throw new Error(Array.isArray(subscriptionCreate.errors) ? subscriptionCreate.errors.join() : subscriptionCreate.errors);
106
+ }
107
+ if (!(subscriptionCreate === null || subscriptionCreate === void 0 ? void 0 : subscriptionCreate.subscription)) {
108
+ throw new Error('No subscription returned from subscription creation');
109
+ }
110
+ return subscriptionCreate.subscription;
111
+ }
112
+ //# sourceMappingURL=subscription-create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription-create.js","sourceRoot":"","sources":["../../src/helpers/subscription-create.ts"],"names":[],"mappings":";;AA+EA,qCA6EC;AA5HD,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuCZ,CAAC;AAEH;;;;;GAKG;AACY,KAAK,UAAU,kBAAkB,CAE9C,aAAqB,EACrB,UAA+B,EAAE;;IAEjC,MAAM,SAAS,GAAwC;QACrD,UAAU,EAAE;YACV,aAAa;YACb,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,KAAK;YAC7B,SAAS,EAAE,MAAA,OAAO,CAAC,SAAS,mCAAI,IAAI;SACrC;KACF,CAAC;IAEF,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACtB,SAAS,CAAC,UAAU,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IACrD,CAAC;SAAM,CAAC;QACN,MAAM,cAAc,GAAuC;YACzD,SAAS,EAAE,MAAA,OAAO,CAAC,SAAS,0CAAE,QAAQ,EAAE;YACxC,QAAQ,EAAE,MAAA,OAAO,CAAC,QAAQ,0CAAE,QAAQ,E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AAkB,CAAE,MAAM,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC3H,CAAC;IAED,IAAI,CAAC,CAAA,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,CAAE,YAAY,CAAA,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IAED,OAAO,kBAAkB,CAAC,YAAY,CAAC;AACzC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import Bunny from '../';
2
+ import { Query } from '../types/graphql';
3
+ /**
4
+ * Fetches tenant information by code
5
+ * @param {string} code - Unique code for the tenant
6
+ * @returns {Promise<NonNullable<Query['tenant']>>} Tenant object
7
+ */
8
+ export default function getTenantByCode(this: Bunny, code: string): Promise<NonNullable<Query['tenant']> | undefined>;
9
+ //# sourceMappingURL=tenant-by-code.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenant-by-code.d.ts","sourceRoot":"","sources":["../../src/helpers/tenant-by-code.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,KAAK,EAAU,MAAM,kBAAkB,CAAC;AAsDjD;;;;GAIG;AACH,wBAA8B,eAAe,CAC3C,IAAI,EAAE,KAAK,EACX,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,CAAC,CAcnD"}
@@ -1,3 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = getTenantByCode;
1
4
  const query = `query tenant ($code: String!) {
2
5
  tenant (code: $code) {
3
6
  id
@@ -49,22 +52,20 @@ const query = `query tenant ($code: String!) {
49
52
  }
50
53
  }
51
54
  }`;
52
-
53
55
  /**
54
- *
55
- * @param {string} code Unique code for the tenant
56
- * @returns {object} Tenant object
56
+ * Fetches tenant information by code
57
+ * @param {string} code - Unique code for the tenant
58
+ * @returns {Promise<NonNullable<Query['tenant']>>} Tenant object
57
59
  */
58
- module.exports = async function (code) {
59
- let variables = {
60
- code: code,
61
- };
62
-
63
- const res = await this.query(query, variables);
64
-
65
- if (res?.errors) {
66
- throw new Error(res.errors.map((e) => e.message).join());
67
- }
68
-
69
- return res?.data?.tenant;
70
- };
60
+ async function getTenantByCode(code) {
61
+ var _a;
62
+ const variables = {
63
+ code,
64
+ };
65
+ const res = await this.query(query, variables);
66
+ if (res === null || res === void 0 ? void 0 : res.errors) {
67
+ throw new Error(res.errors.map((e) => e.message).join());
68
+ }
69
+ return (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.tenant;
70
+ }
71
+ //# sourceMappingURL=tenant-by-code.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenant-by-code.js","sourceRoot":"","sources":["../../src/helpers/tenant-by-code.ts"],"names":[],"mappings":";;AA4DA,kCAiBC;AA1ED,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkDZ,CAAC;AAEH;;;;GAIG;AACY,KAAK,UAAU,eAAe,CAE3C,IAAY;;IAEZ,MAAM,SAAS,GAAG;QAChB,IAAI;KACL,CAAC;IAEF,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAEzB,KAAK,EAAE,SAAS,CAAC,CAAC;IAErB,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,OAAO,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,0CAAE,MAAM,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,13 @@
1
+ import Bunny from '../';
2
+ import { Mutation } from '../types/graphql';
3
+ /**
4
+ * Creates a new tenant with the specified attributes
5
+ * @param {string} name Account name of the tenant
6
+ * @param {string} code Unique code for the tenant
7
+ * @param {string} platformCode Code for the platform that the tenant is on
8
+ * @param {string} accountId Id of the account that the tenant is being created for
9
+ * @param {string} subscriptionId Id of the subscription that the tenant is being created for
10
+ * @returns {Promise<NonNullable<Mutation['tenantCreate']>['tenant']>} The created tenant
11
+ */
12
+ export default function tenantCreate(this: Bunny, name: string, code: string, platformCode: string, accountId: string, subscriptionId: string): Promise<NonNullable<NonNullable<Mutation['tenantCreate']>['tenant']>>;
13
+ //# sourceMappingURL=tenant-create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenant-create.d.ts","sourceRoot":"","sources":["../../src/helpers/tenant-create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAoB,MAAM,kBAAkB,CAAC;AAkB9D;;;;;;;;GAQG;AACH,wBAA8B,YAAY,CACxC,IAAI,EAAE,KAAK,EACX,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CA6BvE"}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = tenantCreate;
4
+ const query = `mutation tenantCreate ($attributes: TenantAttributes!, $subscriptionId: ID!) {
5
+ tenantCreate (attributes: $attributes, subscriptionId: $subscriptionId) {
6
+ tenant {
7
+ code
8
+ id
9
+ name
10
+ platform {
11
+ id
12
+ name
13
+ code
14
+ }
15
+ }
16
+ errors
17
+ }
18
+ }`;
19
+ /**
20
+ * Creates a new tenant with the specified attributes
21
+ * @param {string} name Account name of the tenant
22
+ * @param {string} code Unique code for the tenant
23
+ * @param {string} platformCode Code for the platform that the tenant is on
24
+ * @param {string} accountId Id of the account that the tenant is being created for
25
+ * @param {string} subscriptionId Id of the subscription that the tenant is being created for
26
+ * @returns {Promise<NonNullable<Mutation['tenantCreate']>['tenant']>} The created tenant
27
+ */
28
+ async function tenantCreate(name, code, platformCode, accountId, subscriptionId) {
29
+ var _a;
30
+ const variables = {
31
+ attributes: {
32
+ name,
33
+ code,
34
+ accountId,
35
+ platformCode,
36
+ },
37
+ subscriptionId,
38
+ };
39
+ const res = await this.query(query, variables);
40
+ const tenantCreate = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.tenantCreate;
41
+ if (res === null || res === void 0 ? void 0 : res.errors) {
42
+ throw new Error(res.errors.map((e) => e.message).join());
43
+ }
44
+ if (tenantCreate === null || tenantCreate === void 0 ? void 0 : tenantCreate.errors) {
45
+ throw new Error(tenantCreate.errors.join());
46
+ }
47
+ if (!(tenantCreate === null || tenantCreate === void 0 ? void 0 : tenantCreate.tenant)) {
48
+ throw new Error('Tenant not created');
49
+ }
50
+ return tenantCreate.tenant;
51
+ }
52
+ //# sourceMappingURL=tenant-create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenant-create.js","sourceRoot":"","sources":["../../src/helpers/tenant-create.ts"],"names":[],"mappings":";;AA4BA,+BAoCC;AA7DD,MAAM,KAAK,GAAG;;;;;;;;;;;;;;EAcZ,CAAC;AAEH;;;;;;;;GAQG;AACY,KAAK,UAAU,YAAY,CAExC,IAAY,EACZ,IAAY,EACZ,YAAoB,EACpB,SAAiB,EACjB,cAAsB;;IAEtB,MAAM,SAAS,GAAG;QAChB,UAAU,EAAE;YACV,IAAI;YACJ,IAAI;YACJ,SAAS;YACT,YAAY;SACO;QACrB,cAAc;KACf,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,IAAI,CAAC,CAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,MAAM,CAAA,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,YAAY,CAAC,MAAM,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { TenantMetricsUpdatePayload } from '../generated/graphql';
2
+ interface GraphQLResponse<T> {
3
+ data?: T;
4
+ errors?: Array<{
5
+ message: string;
6
+ }>;
7
+ }
8
+ interface TenantMetricsUpdateResponse {
9
+ tenantMetricsUpdate?: TenantMetricsUpdatePayload;
10
+ }
11
+ /**
12
+ * Update tenant metrics
13
+ * @param {string} code The code of the tenant
14
+ * @param {string} lastLogin The last login date of the tenant
15
+ * @param {number} userCount The number of users in the tenant
16
+ * @param {Record<string, any>} utilizationMetrics The utilization metrics of the tenant
17
+ **/
18
+ export default function tenantMetricsUpdate(this: {
19
+ query: (query: string, variables: any) => Promise<GraphQLResponse<TenantMetricsUpdateResponse>>;
20
+ }, code: string | undefined, lastLogin?: string | Date | null, userCount?: number | null, utilizationMetrics?: Record<string, any> | null): Promise<boolean>;
21
+ export {};
22
+ //# sourceMappingURL=tenant-metrics-update.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenant-metrics-update.d.ts","sourceRoot":"","sources":["../../src/helpers/tenant-metrics-update.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAE3F,UAAU,eAAe,CAAC,CAAC;IACzB,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACrC;AAED,UAAU,2BAA2B;IACnC,mBAAmB,CAAC,EAAE,0BAA0B,CAAC;CAClD;AAQD;;;;;;GAMG;AACH,wBAA8B,mBAAmB,CAC/C,IAAI,EAAE;IAAE,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,OAAO,CAAC,eAAe,CAAC,2BAA2B,CAAC,CAAC,CAAA;CAAE,EACzG,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,EAChC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,EACzB,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAC9C,OAAO,CAAC,OAAO,CAAC,CAsBlB"}