@bunnyapp/components 1.6.0-beta.9.1 → 1.6.0-beta.9.3

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/dist/cjs/index.js CHANGED
@@ -52,7 +52,7 @@ var css_248z = ":root {\n --row-background: #ffffff;\n --row-background-altern
52
52
  styleInject(css_248z);
53
53
 
54
54
  // This will be replaced at build time by rollup-plugin-replace
55
- const PACKAGE_VERSION = '1.6.0-beta.9';
55
+ const PACKAGE_VERSION = '1.6.0-beta.9.2';
56
56
  const createRequestHeaders = (token) => {
57
57
  const headers = createClientDevHeaders({ token });
58
58
  // Add the components version header
@@ -21983,23 +21983,22 @@ const QuantityInput = ({ charge: maskedCharge, chargeIndex, editingQuote, setEdi
21983
21983
  setUpdatingChargeQuantityId(undefined);
21984
21984
  setEditingQuoteData(undefined);
21985
21985
  }
21986
- if (quantity === charge.quantity) {
21987
- setEditingQuoteData(undefined);
21988
- showErrorNotification('New quantity cannot be the same as current');
21989
- }
21990
- else {
21991
- if (quantity !== undefined && quantity !== charge.quantity) {
21992
- if (!(charge === null || charge === void 0 ? void 0 : charge.priceListChargeId)) {
21993
- showErrorNotification('Charge ID is not found');
21994
- return;
21995
- }
21996
- setUpdatingChargeQuantityId(getUpdatingChargeQuantityId(charge.priceListChargeId, subscription.id));
21986
+ if (quantity !== undefined && quantity !== charge.quantity) {
21987
+ if (!(charge === null || charge === void 0 ? void 0 : charge.priceListChargeId)) {
21988
+ showErrorNotification('Charge ID is not found');
21989
+ return;
21997
21990
  }
21991
+ setUpdatingChargeQuantityId(getUpdatingChargeQuantityId(charge.priceListChargeId, subscription.id));
21998
21992
  }
21999
21993
  };
22000
21994
  const handleSubscriptionUpdate = (editedSubscription) => {
22001
21995
  if (!editedSubscription || editedSubscription.quantity === undefined)
22002
21996
  return;
21997
+ if (editedSubscription.quantity === charge.quantity) {
21998
+ setEditingQuoteData(undefined);
21999
+ showErrorNotification('New quantity cannot be the same as current');
22000
+ return;
22001
+ }
22003
22002
  // If we are not editing a quote, we create a new one
22004
22003
  if (!editingQuote) {
22005
22004
  createQuote.mutate(editedSubscription.subscription.id);
@@ -22627,51 +22626,6 @@ function getAddonsForBillingPeriod(billingPeriod, addonPlans) {
22627
22626
 
22628
22627
  const AddonIndentation = ({ isLast, indentation, verticalMargin, }) => (jsxRuntime.jsxs("div", { className: "bunny-flex bunny-flex-col bunny-relative", style: { width: `${indentation}px` }, children: [jsxRuntime.jsx("div", { className: `bunny-flex-1 bunny-bg-gray-300 bunny-w-0.5 bunny-mx-auto`, style: { marginTop: verticalMargin } }), jsxRuntime.jsx("div", { className: "bunny-bg-gray-300 bunny-h-0.5 bunny-w-1/2 bunny-ml-auto" }), isLast ? (jsxRuntime.jsx("div", { className: "bunny-flex-1" })) : (jsxRuntime.jsx("div", { className: `bunny-flex-1 bunny-bg-gray-300 bunny-w-0.5 bunny-mx-auto`, style: { marginBottom: verticalMargin } }))] }));
22629
22628
 
22630
- const FEATURE_USAGE_MUTATION = `
22631
- query GetFeatureUsage($id: ID!) {
22632
- featureUsageHistogram(subscriptionChargeId: $id) {
22633
- subscriptionCharge {
22634
- id
22635
- name
22636
- amount
22637
- currentPeriodPriceByTiers {
22638
- tier { starts price }
22639
- quantity
22640
- amount
22641
- }
22642
- }
22643
- feature { id name }
22644
- periodRange
22645
- dataInterval
22646
- data {
22647
- periodStart
22648
- periodEnd
22649
- intervals {
22650
- intervalStart
22651
- intervalUsage
22652
- }
22653
- intervalsTotal
22654
- }
22655
- }
22656
- }
22657
- `;
22658
- const getFeatureUsage = async ({ subscriptionChargeId, token, apiHost, }) => {
22659
- var _a;
22660
- const vars = {
22661
- id: subscriptionChargeId,
22662
- };
22663
- const response = await gqlRequest({
22664
- query: FEATURE_USAGE_MUTATION,
22665
- token,
22666
- vars,
22667
- apiHost,
22668
- });
22669
- if ((_a = response.featureUsageHistogram) === null || _a === void 0 ? void 0 : _a.data)
22670
- return response.featureUsageHistogram;
22671
- else
22672
- throw new Error('No data found');
22673
- };
22674
-
22675
22629
  var utc$2 = {exports: {}};
22676
22630
 
22677
22631
  var utc$1 = utc$2.exports;
@@ -23269,24 +23223,10 @@ const SubscriptionCardDesktop = ({ onChangePlanClick, onCancelSubscriptionClick,
23269
23223
  };
23270
23224
  const SubscriptionCardDesktopRow = ({ charge, chargeIndex, subscription, }) => {
23271
23225
  var _a, _b, _c;
23272
- // Context
23273
- const { apiHost } = react.useContext(BunnyContext);
23274
- const token = useToken();
23275
23226
  // Derived state
23276
23227
  const { isRamp } = charge;
23277
23228
  const prevCharge = (_a = subscription === null || subscription === void 0 ? void 0 : subscription.chargeReport) === null || _a === void 0 ? void 0 : _a[chargeIndex - 1];
23278
- const isFirstRampRow = chargeIndex === 0 || (prevCharge === null || prevCharge === void 0 ? void 0 : prevCharge.priceListChargeId) !== charge.priceListChargeId;
23279
23229
  const chargePeriod = `${common.formatDate(charge.startDate)} - ${common.formatDate(charge.endDate)}`;
23280
- // Queries
23281
- const { data } = reactQuery.useQuery({
23282
- queryKey: ['getFeatureUsage', charge.id],
23283
- queryFn: () => getFeatureUsage({
23284
- subscriptionChargeId: charge.id,
23285
- token,
23286
- apiHost,
23287
- }),
23288
- enabled: (!isRamp || (isRamp && isFirstRampRow)) && charge.chargeType === common.ChargeType.USAGE,
23289
- });
23290
23230
  const isRampFirstRow = isRamp && chargeIndex === 0;
23291
23231
  const isTrial = charge.trial;
23292
23232
  const isDiscount = charge.kind === common.QuoteChangeKind.DISCOUNT;
@@ -23297,7 +23237,7 @@ const SubscriptionCardDesktopRow = ({ charge, chargeIndex, subscription, }) => {
23297
23237
  return (jsxRuntime.jsxs("div", { className: "bunny-contents", children: [(isRampFirstRow || !isRamp) && (jsxRuntime.jsx(SubscriptionsListCell, { gridColumn: isRamp ? '1/-1' : '1', children: jsxRuntime.jsx("div", { className: `bunny-flex bunny-items-center bunny-gap-2 ${isDiscount ? 'bunny-pl-4' : ''}`, children: jsxRuntime.jsx("div", { children: isRampFirstRow || (!isRamp && !dontShowChargeName) ? charge.name : '' }) }) })), jsxRuntime.jsx(SubscriptionsListCell, { gridColumn: 2, children: jsxRuntime.jsx("div", { children: chargePeriod }) }), jsxRuntime.jsx(SubscriptionsListCell, { right: true, children: charge.kind === common.QuoteChangeKind.DISCOUNT
23298
23238
  ? ''
23299
23239
  : charge.chargeType === common.ChargeType.USAGE
23300
- ? data && jsxRuntime.jsx(FeatureUsageGraph, { charge: charge, featureUsage: data, useAreaChart: true })
23240
+ ? charge.histogram && (jsxRuntime.jsx(FeatureUsageGraph, { charge: charge, featureUsage: charge.histogram, useAreaChart: true }))
23301
23241
  : charge.isAmendment
23302
23242
  ? `+${(_b = charge.quantity) === null || _b === void 0 ? void 0 : _b.toLocaleString()}`
23303
23243
  : (_c = charge.quantity) === null || _c === void 0 ? void 0 : _c.toLocaleString() }), jsxRuntime.jsx(SubscriptionsListCell, { right: true, children: jsxRuntime.jsx(SubscriptionChargeUnitPrice, { charge: charge, currencyId: subscription.currencyId }) }), jsxRuntime.jsx(SubscriptionsListCell, { right: true, children: jsxRuntime.jsx(SubscriptionChargeTotal, { charge: charge, subscription: subscription }) })] }));
@@ -25354,6 +25294,23 @@ const SubscriptionsQuery = t(`
25354
25294
  id
25355
25295
  code
25356
25296
  }
25297
+ histogram {
25298
+ feature {
25299
+ id
25300
+ name
25301
+ }
25302
+ periodRange
25303
+ dataInterval
25304
+ data {
25305
+ periodStart
25306
+ periodEnd
25307
+ intervals {
25308
+ intervalStart
25309
+ intervalUsage
25310
+ }
25311
+ intervalsTotal
25312
+ }
25313
+ }
25357
25314
  amount
25358
25315
  billingPeriod
25359
25316
  chargeType
@@ -0,0 +1,39 @@
1
+ import { Account, BillingPeriod, ChargeType, Currency, Feature, FeatureUsage, PriceList, PriceListCharge, PriceTier, PricingModel, QuoteChangeKind } from '@bunnyapp/common';
2
+ export type SubscriptionCharge = {
3
+ account: Account;
4
+ amount: number;
5
+ billingPeriod: BillingPeriod;
6
+ chargeType: ChargeType;
7
+ createdAt: string;
8
+ currency: Currency;
9
+ discount?: number;
10
+ discountedPrice: string;
11
+ endDate: string;
12
+ expired: boolean;
13
+ feature?: Feature;
14
+ id: string;
15
+ invoiceLineText: string;
16
+ isAmendment: boolean;
17
+ isRamp?: boolean;
18
+ kind: QuoteChangeKind;
19
+ name: string;
20
+ periodPrice: number;
21
+ price: string;
22
+ priceDecimals: number;
23
+ priceList: PriceList;
24
+ priceListCharge?: PriceListCharge;
25
+ priceListChargeId: string;
26
+ priceListId: string;
27
+ priceTiers: PriceTier[];
28
+ pricingModel: PricingModel;
29
+ prorationRate?: number;
30
+ quantity: number;
31
+ quantityMax?: number;
32
+ quantityMin?: number;
33
+ selfServiceQuantity?: boolean;
34
+ startDate: string;
35
+ tieredAveragePrice?: number;
36
+ trial: boolean;
37
+ updatedAt: string;
38
+ histogram?: FeatureUsage;
39
+ };
@@ -1,5 +1,5 @@
1
1
  import { BillingPeriod, Plan, Product } from "@bunnyapp/common";
2
2
  export type PeriodMonths = 0 | 1 | 3 | 6 | 12;
3
3
  export declare const periodMonthsConverter: (period: PeriodMonths) => BillingPeriod;
4
- export declare const billingPeriodConverter: (period?: BillingPeriod) => 0 | 1 | 3 | 6 | 12;
4
+ export declare const billingPeriodConverter: (period?: BillingPeriod) => 1 | 0 | 3 | 6 | 12;
5
5
  export declare const createAvailableBillingPeriods: (plans?: Plan[], selectedProduct?: Product) => (0 | 1 | 3 | 6 | 12)[] | undefined;
package/dist/esm/index.js CHANGED
@@ -50,7 +50,7 @@ var css_248z = ":root {\n --row-background: #ffffff;\n --row-background-altern
50
50
  styleInject(css_248z);
51
51
 
52
52
  // This will be replaced at build time by rollup-plugin-replace
53
- const PACKAGE_VERSION = '1.6.0-beta.9';
53
+ const PACKAGE_VERSION = '1.6.0-beta.9.2';
54
54
  const createRequestHeaders = (token) => {
55
55
  const headers = createClientDevHeaders({ token });
56
56
  // Add the components version header
@@ -21981,23 +21981,22 @@ const QuantityInput = ({ charge: maskedCharge, chargeIndex, editingQuote, setEdi
21981
21981
  setUpdatingChargeQuantityId(undefined);
21982
21982
  setEditingQuoteData(undefined);
21983
21983
  }
21984
- if (quantity === charge.quantity) {
21985
- setEditingQuoteData(undefined);
21986
- showErrorNotification('New quantity cannot be the same as current');
21987
- }
21988
- else {
21989
- if (quantity !== undefined && quantity !== charge.quantity) {
21990
- if (!(charge === null || charge === void 0 ? void 0 : charge.priceListChargeId)) {
21991
- showErrorNotification('Charge ID is not found');
21992
- return;
21993
- }
21994
- setUpdatingChargeQuantityId(getUpdatingChargeQuantityId(charge.priceListChargeId, subscription.id));
21984
+ if (quantity !== undefined && quantity !== charge.quantity) {
21985
+ if (!(charge === null || charge === void 0 ? void 0 : charge.priceListChargeId)) {
21986
+ showErrorNotification('Charge ID is not found');
21987
+ return;
21995
21988
  }
21989
+ setUpdatingChargeQuantityId(getUpdatingChargeQuantityId(charge.priceListChargeId, subscription.id));
21996
21990
  }
21997
21991
  };
21998
21992
  const handleSubscriptionUpdate = (editedSubscription) => {
21999
21993
  if (!editedSubscription || editedSubscription.quantity === undefined)
22000
21994
  return;
21995
+ if (editedSubscription.quantity === charge.quantity) {
21996
+ setEditingQuoteData(undefined);
21997
+ showErrorNotification('New quantity cannot be the same as current');
21998
+ return;
21999
+ }
22001
22000
  // If we are not editing a quote, we create a new one
22002
22001
  if (!editingQuote) {
22003
22002
  createQuote.mutate(editedSubscription.subscription.id);
@@ -22625,51 +22624,6 @@ function getAddonsForBillingPeriod(billingPeriod, addonPlans) {
22625
22624
 
22626
22625
  const AddonIndentation = ({ isLast, indentation, verticalMargin, }) => (jsxs("div", { className: "bunny-flex bunny-flex-col bunny-relative", style: { width: `${indentation}px` }, children: [jsx("div", { className: `bunny-flex-1 bunny-bg-gray-300 bunny-w-0.5 bunny-mx-auto`, style: { marginTop: verticalMargin } }), jsx("div", { className: "bunny-bg-gray-300 bunny-h-0.5 bunny-w-1/2 bunny-ml-auto" }), isLast ? (jsx("div", { className: "bunny-flex-1" })) : (jsx("div", { className: `bunny-flex-1 bunny-bg-gray-300 bunny-w-0.5 bunny-mx-auto`, style: { marginBottom: verticalMargin } }))] }));
22627
22626
 
22628
- const FEATURE_USAGE_MUTATION = `
22629
- query GetFeatureUsage($id: ID!) {
22630
- featureUsageHistogram(subscriptionChargeId: $id) {
22631
- subscriptionCharge {
22632
- id
22633
- name
22634
- amount
22635
- currentPeriodPriceByTiers {
22636
- tier { starts price }
22637
- quantity
22638
- amount
22639
- }
22640
- }
22641
- feature { id name }
22642
- periodRange
22643
- dataInterval
22644
- data {
22645
- periodStart
22646
- periodEnd
22647
- intervals {
22648
- intervalStart
22649
- intervalUsage
22650
- }
22651
- intervalsTotal
22652
- }
22653
- }
22654
- }
22655
- `;
22656
- const getFeatureUsage = async ({ subscriptionChargeId, token, apiHost, }) => {
22657
- var _a;
22658
- const vars = {
22659
- id: subscriptionChargeId,
22660
- };
22661
- const response = await gqlRequest({
22662
- query: FEATURE_USAGE_MUTATION,
22663
- token,
22664
- vars,
22665
- apiHost,
22666
- });
22667
- if ((_a = response.featureUsageHistogram) === null || _a === void 0 ? void 0 : _a.data)
22668
- return response.featureUsageHistogram;
22669
- else
22670
- throw new Error('No data found');
22671
- };
22672
-
22673
22627
  var utc$2 = {exports: {}};
22674
22628
 
22675
22629
  var utc$1 = utc$2.exports;
@@ -23267,24 +23221,10 @@ const SubscriptionCardDesktop = ({ onChangePlanClick, onCancelSubscriptionClick,
23267
23221
  };
23268
23222
  const SubscriptionCardDesktopRow = ({ charge, chargeIndex, subscription, }) => {
23269
23223
  var _a, _b, _c;
23270
- // Context
23271
- const { apiHost } = useContext(BunnyContext);
23272
- const token = useToken();
23273
23224
  // Derived state
23274
23225
  const { isRamp } = charge;
23275
23226
  const prevCharge = (_a = subscription === null || subscription === void 0 ? void 0 : subscription.chargeReport) === null || _a === void 0 ? void 0 : _a[chargeIndex - 1];
23276
- const isFirstRampRow = chargeIndex === 0 || (prevCharge === null || prevCharge === void 0 ? void 0 : prevCharge.priceListChargeId) !== charge.priceListChargeId;
23277
23227
  const chargePeriod = `${formatDate(charge.startDate)} - ${formatDate(charge.endDate)}`;
23278
- // Queries
23279
- const { data } = useQuery({
23280
- queryKey: ['getFeatureUsage', charge.id],
23281
- queryFn: () => getFeatureUsage({
23282
- subscriptionChargeId: charge.id,
23283
- token,
23284
- apiHost,
23285
- }),
23286
- enabled: (!isRamp || (isRamp && isFirstRampRow)) && charge.chargeType === ChargeType.USAGE,
23287
- });
23288
23228
  const isRampFirstRow = isRamp && chargeIndex === 0;
23289
23229
  const isTrial = charge.trial;
23290
23230
  const isDiscount = charge.kind === QuoteChangeKind.DISCOUNT;
@@ -23295,7 +23235,7 @@ const SubscriptionCardDesktopRow = ({ charge, chargeIndex, subscription, }) => {
23295
23235
  return (jsxs("div", { className: "bunny-contents", children: [(isRampFirstRow || !isRamp) && (jsx(SubscriptionsListCell, { gridColumn: isRamp ? '1/-1' : '1', children: jsx("div", { className: `bunny-flex bunny-items-center bunny-gap-2 ${isDiscount ? 'bunny-pl-4' : ''}`, children: jsx("div", { children: isRampFirstRow || (!isRamp && !dontShowChargeName) ? charge.name : '' }) }) })), jsx(SubscriptionsListCell, { gridColumn: 2, children: jsx("div", { children: chargePeriod }) }), jsx(SubscriptionsListCell, { right: true, children: charge.kind === QuoteChangeKind.DISCOUNT
23296
23236
  ? ''
23297
23237
  : charge.chargeType === ChargeType.USAGE
23298
- ? data && jsx(FeatureUsageGraph, { charge: charge, featureUsage: data, useAreaChart: true })
23238
+ ? charge.histogram && (jsx(FeatureUsageGraph, { charge: charge, featureUsage: charge.histogram, useAreaChart: true }))
23299
23239
  : charge.isAmendment
23300
23240
  ? `+${(_b = charge.quantity) === null || _b === void 0 ? void 0 : _b.toLocaleString()}`
23301
23241
  : (_c = charge.quantity) === null || _c === void 0 ? void 0 : _c.toLocaleString() }), jsx(SubscriptionsListCell, { right: true, children: jsx(SubscriptionChargeUnitPrice, { charge: charge, currencyId: subscription.currencyId }) }), jsx(SubscriptionsListCell, { right: true, children: jsx(SubscriptionChargeTotal, { charge: charge, subscription: subscription }) })] }));
@@ -25352,6 +25292,23 @@ const SubscriptionsQuery = t(`
25352
25292
  id
25353
25293
  code
25354
25294
  }
25295
+ histogram {
25296
+ feature {
25297
+ id
25298
+ name
25299
+ }
25300
+ periodRange
25301
+ dataInterval
25302
+ data {
25303
+ periodStart
25304
+ periodEnd
25305
+ intervals {
25306
+ intervalStart
25307
+ intervalUsage
25308
+ }
25309
+ intervalsTotal
25310
+ }
25311
+ }
25355
25312
  amount
25356
25313
  billingPeriod
25357
25314
  chargeType
@@ -0,0 +1,39 @@
1
+ import { Account, BillingPeriod, ChargeType, Currency, Feature, FeatureUsage, PriceList, PriceListCharge, PriceTier, PricingModel, QuoteChangeKind } from '@bunnyapp/common';
2
+ export type SubscriptionCharge = {
3
+ account: Account;
4
+ amount: number;
5
+ billingPeriod: BillingPeriod;
6
+ chargeType: ChargeType;
7
+ createdAt: string;
8
+ currency: Currency;
9
+ discount?: number;
10
+ discountedPrice: string;
11
+ endDate: string;
12
+ expired: boolean;
13
+ feature?: Feature;
14
+ id: string;
15
+ invoiceLineText: string;
16
+ isAmendment: boolean;
17
+ isRamp?: boolean;
18
+ kind: QuoteChangeKind;
19
+ name: string;
20
+ periodPrice: number;
21
+ price: string;
22
+ priceDecimals: number;
23
+ priceList: PriceList;
24
+ priceListCharge?: PriceListCharge;
25
+ priceListChargeId: string;
26
+ priceListId: string;
27
+ priceTiers: PriceTier[];
28
+ pricingModel: PricingModel;
29
+ prorationRate?: number;
30
+ quantity: number;
31
+ quantityMax?: number;
32
+ quantityMin?: number;
33
+ selfServiceQuantity?: boolean;
34
+ startDate: string;
35
+ tieredAveragePrice?: number;
36
+ trial: boolean;
37
+ updatedAt: string;
38
+ histogram?: FeatureUsage;
39
+ };
@@ -1,5 +1,5 @@
1
1
  import { BillingPeriod, Plan, Product } from "@bunnyapp/common";
2
2
  export type PeriodMonths = 0 | 1 | 3 | 6 | 12;
3
3
  export declare const periodMonthsConverter: (period: PeriodMonths) => BillingPeriod;
4
- export declare const billingPeriodConverter: (period?: BillingPeriod) => 0 | 1 | 3 | 6 | 12;
4
+ export declare const billingPeriodConverter: (period?: BillingPeriod) => 1 | 0 | 3 | 6 | 12;
5
5
  export declare const createAvailableBillingPeriods: (plans?: Plan[], selectedProduct?: Product) => (0 | 1 | 3 | 6 | 12)[] | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bunnyapp/components",
3
- "version": "1.6.0-beta.9.1",
3
+ "version": "1.6.0-beta.9.3",
4
4
  "description": "Components from the Bunny portal to embed Bunny UI functionality into your application.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -1,7 +0,0 @@
1
- import { FeatureUsage } from '@bunnyapp/common';
2
- declare const getFeatureUsage: ({ subscriptionChargeId, token, apiHost, }: {
3
- subscriptionChargeId: string;
4
- token?: string;
5
- apiHost: string;
6
- }) => Promise<FeatureUsage>;
7
- export default getFeatureUsage;
@@ -1,7 +0,0 @@
1
- import { FeatureUsage } from '@bunnyapp/common';
2
- declare const getFeatureUsage: ({ subscriptionChargeId, token, apiHost, }: {
3
- subscriptionChargeId: string;
4
- token?: string;
5
- apiHost: string;
6
- }) => Promise<FeatureUsage>;
7
- export default getFeatureUsage;