@stigg/react-sdk 5.2.1 → 5.4.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 (33) hide show
  1. package/dist/components/common/TiersSelectContainer.d.ts +2 -4
  2. package/dist/components/common/VolumeBulkSelect.d.ts +1 -1
  3. package/dist/components/common/VolumePerUnitInput.d.ts +1 -1
  4. package/dist/components/paywall/PlanOfferingButton.d.ts +2 -3
  5. package/dist/components/paywall/PlanPrice.d.ts +2 -4
  6. package/dist/components/utils/fixtures/price.fixtures.d.ts +7 -0
  7. package/dist/components/utils/getPaidPriceText.d.ts +2 -3
  8. package/dist/components/utils/getPlanPrice.d.ts +1 -1
  9. package/dist/components/utils/priceTierUtils.d.ts +11 -6
  10. package/dist/components/utils/priceTierUtils.spec.d.ts +1 -0
  11. package/dist/react-sdk.cjs.development.js +137 -188
  12. package/dist/react-sdk.cjs.development.js.map +1 -1
  13. package/dist/react-sdk.cjs.production.min.js +1 -1
  14. package/dist/react-sdk.cjs.production.min.js.map +1 -1
  15. package/dist/react-sdk.esm.js +140 -191
  16. package/dist/react-sdk.esm.js.map +1 -1
  17. package/package.json +2 -2
  18. package/src/components/checkout/hooks/usePlanStepModel.ts +1 -1
  19. package/src/components/checkout/steps/plan/CheckoutChargeList.tsx +4 -11
  20. package/src/components/checkout/summary/components/LineItems.tsx +5 -8
  21. package/src/components/common/TiersSelectContainer.tsx +5 -16
  22. package/src/components/common/VolumeBulkSelect.tsx +7 -4
  23. package/src/components/common/VolumePerUnitInput.tsx +3 -5
  24. package/src/components/paywall/Paywall.tsx +2 -2
  25. package/src/components/paywall/PlanOffering.tsx +6 -27
  26. package/src/components/paywall/PlanOfferingButton.tsx +2 -8
  27. package/src/components/paywall/PlanPrice.tsx +4 -23
  28. package/src/components/utils/calculateDiscountRate.ts +2 -2
  29. package/src/components/utils/fixtures/price.fixtures.ts +42 -0
  30. package/src/components/utils/getPaidPriceText.ts +6 -24
  31. package/src/components/utils/getPlanPrice.ts +0 -2
  32. package/src/components/utils/priceTierUtils.spec.ts +84 -0
  33. package/src/components/utils/priceTierUtils.ts +78 -73
@@ -4,11 +4,9 @@ export declare type TiersSelectContainerProps = {
4
4
  componentId: string;
5
5
  tiers?: PriceTierFragment[] | null;
6
6
  tierUnits?: string;
7
- selectedTier?: PriceTierFragment;
8
- handleTierChange: (tier: PriceTierFragment) => void;
9
7
  tiersMode?: TiersMode | null;
10
- handlePerUnitQuantityChange: (quantity: number) => void;
11
- perUnitQuantity?: number;
8
+ handleChange: (quantity: number) => void;
9
+ value: number;
12
10
  width?: number;
13
11
  };
14
12
  export declare function TiersSelectContainer(props: TiersSelectContainerProps): JSX.Element;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { TiersSelectContainerProps } from './TiersSelectContainer';
3
- export declare function VolumeBulkSelect({ selectedTier, componentId, tierUnits, tiers, handleChange, }: Pick<TiersSelectContainerProps, 'selectedTier' | 'componentId' | 'tiers' | 'tierUnits'> & {
3
+ export declare function VolumeBulkSelect({ value, componentId, tierUnits, tiers, handleChange, }: Pick<TiersSelectContainerProps, 'value' | 'componentId' | 'tiers' | 'tierUnits'> & {
4
4
  handleChange: (quantity: number) => void;
5
5
  }): JSX.Element | null;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { TiersSelectContainerProps } from './TiersSelectContainer';
3
- export declare function VolumePerUnitInput({ width, tierUnits, perUnitQuantity, handlePerUnitQuantityChange, handleChange, }: Pick<TiersSelectContainerProps, 'width' | 'tierUnits' | 'perUnitQuantity' | 'handlePerUnitQuantityChange'> & {
3
+ export declare function VolumePerUnitInput({ width, tierUnits, value, handleChange, }: Pick<TiersSelectContainerProps, 'width' | 'tierUnits' | 'value'> & {
4
4
  handleChange: (quantity: number) => void;
5
5
  }): JSX.Element;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { BillingPeriod, Customer, PriceTierFragment, Subscription } from '@stigg/js-client-sdk';
2
+ import { BillingPeriod, Customer, Subscription } from '@stigg/js-client-sdk';
3
3
  import { PaywallPlan, SubscribeIntentionType } from './types';
4
4
  import { PaywallLocalization } from './paywallTextOverrides';
5
5
  declare type PlanOfferingButtonProps = {
@@ -12,8 +12,7 @@ declare type PlanOfferingButtonProps = {
12
12
  paywallLocale: PaywallLocalization;
13
13
  onPlanSelected: (intentionType: SubscribeIntentionType) => void | Promise<void>;
14
14
  withTrialLeftRow: boolean;
15
- selectedTierByFeature: Record<string, PriceTierFragment>;
16
15
  perUnitQuantityByFeature: Record<string, number>;
17
16
  };
18
- export declare function PlanOfferingButton({ isNextPlan, customer, plan, billingPeriod, isCustomerOnTrial, onPlanSelected, paywallLocale, withTrialLeftRow, currentSubscription, selectedTierByFeature, perUnitQuantityByFeature, }: PlanOfferingButtonProps): JSX.Element;
17
+ export declare function PlanOfferingButton({ isNextPlan, customer, plan, billingPeriod, isCustomerOnTrial, onPlanSelected, paywallLocale, withTrialLeftRow, currentSubscription, perUnitQuantityByFeature, }: PlanOfferingButtonProps): JSX.Element;
19
18
  export {};
@@ -1,14 +1,12 @@
1
1
  import React from 'react';
2
- import { BillingPeriod, PriceTierFragment } from '@stigg/js-client-sdk';
2
+ import { BillingPeriod } from '@stigg/js-client-sdk';
3
3
  import { PaywallPlan } from './types';
4
4
  import { PaywallLocalization } from './paywallTextOverrides';
5
- export declare const PlanPrice: ({ showStartingAt, withUnitPriceRow, withStartingAtRow, withTiersRow, selectedTierByFeature, setSelectedTierByFeature, plan, billingPeriod, paywallLocale, locale, hasMonthlyPrice, hasAnnuallyPrice, perUnitQuantityByFeature, setPerUnitQuantityByFeature, }: {
5
+ export declare const PlanPrice: ({ showStartingAt, withUnitPriceRow, withStartingAtRow, withTiersRow, plan, billingPeriod, paywallLocale, locale, hasMonthlyPrice, hasAnnuallyPrice, perUnitQuantityByFeature, setPerUnitQuantityByFeature, }: {
6
6
  showStartingAt: boolean;
7
7
  withUnitPriceRow: boolean;
8
8
  withStartingAtRow: boolean;
9
9
  withTiersRow: boolean;
10
- selectedTierByFeature: Record<string, PriceTierFragment>;
11
- setSelectedTierByFeature: React.Dispatch<React.SetStateAction<Record<string, PriceTierFragment>>>;
12
10
  perUnitQuantityByFeature: Record<string, number>;
13
11
  setPerUnitQuantityByFeature: React.Dispatch<React.SetStateAction<Record<string, number>>>;
14
12
  plan: PaywallPlan;
@@ -0,0 +1,7 @@
1
+ import { Currency, Price, TiersMode } from '@stigg/js-client-sdk';
2
+ export declare const money: (amount: number, currency: Currency) => {
3
+ amount: number;
4
+ currency: Currency;
5
+ };
6
+ export declare const priceTiersFlat: (tiersMode: TiersMode, currency: Currency) => Pick<Price, 'tiers' | 'tiersMode'>;
7
+ export declare const priceTiersUnit: (tiersMode: TiersMode, currency: Currency) => Pick<Price, 'tiers' | 'tiersMode'>;
@@ -1,4 +1,4 @@
1
- import { BillingPeriod, PaywallCalculatedPricePoint, Price, PriceTierFragment } from '@stigg/js-client-sdk';
1
+ import { BillingPeriod, PaywallCalculatedPricePoint, Price } from '@stigg/js-client-sdk';
2
2
  import { PlanPriceText } from './getPlanPrice';
3
3
  import { PaywallLocalization } from '../paywall';
4
4
  declare type GetPaidPriceTextParams = {
@@ -7,9 +7,8 @@ declare type GetPaidPriceTextParams = {
7
7
  selectedBillingPeriod: BillingPeriod;
8
8
  locale: string;
9
9
  shouldShowMonthlyPriceAmount: boolean;
10
- selectedTierByFeature: Record<string, PriceTierFragment>;
11
10
  paywallLocale: PaywallLocalization;
12
11
  perUnitQuantityByFeature?: Record<string, number>;
13
12
  };
14
- export declare function getPaidPriceText({ planPrices, paywallCalculatedPrice, selectedBillingPeriod, locale, shouldShowMonthlyPriceAmount, selectedTierByFeature, paywallLocale, perUnitQuantityByFeature, }: GetPaidPriceTextParams): PlanPriceText;
13
+ export declare function getPaidPriceText({ planPrices, paywallCalculatedPrice, selectedBillingPeriod, locale, shouldShowMonthlyPriceAmount, paywallLocale, perUnitQuantityByFeature, }: GetPaidPriceTextParams): PlanPriceText;
15
14
  export {};
@@ -6,4 +6,4 @@ export declare type PlanPriceText = {
6
6
  tiers?: PriceTierFragment[] | null | undefined;
7
7
  tierUnits?: string;
8
8
  };
9
- export declare function getPlanPrice(plan: PaywallPlan, billingPeriod: BillingPeriod, paywallLocale: PaywallLocalization, locale: string, shouldShowMonthlyPriceAmount: boolean, selectedTierByFeature?: Record<string, PriceTierFragment>, perUnitQuantityByFeature?: Record<string, number>): PlanPriceText;
9
+ export declare function getPlanPrice(plan: PaywallPlan, billingPeriod: BillingPeriod, paywallLocale: PaywallLocalization, locale: string, shouldShowMonthlyPriceAmount: boolean, perUnitQuantityByFeature?: Record<string, number>): PlanPriceText;
@@ -2,15 +2,20 @@ import { BillingPeriod, Price, PriceTierFragment, Subscription } from '@stigg/js
2
2
  import { PaywallPlan } from '../paywall';
3
3
  import { SelectDefaultTierIndexFn } from '../paywall/types';
4
4
  export declare function getPriceFeatureUnit(price: Price): string;
5
- export declare function getTierByQuantity(tiers: PriceTierFragment[], quantity: number): PriceTierFragment | undefined;
6
- export declare function calculateTierPriceVolume(currentTier: PriceTierFragment, perUnitQuantity: number, selectedBillingPeriod?: BillingPeriod, shouldShowMonthlyPriceAmount?: boolean): number;
7
- export declare function calculateTierPrice(price: Price, currentTier: PriceTierFragment, selectedBillingPeriod: BillingPeriod, shouldShowMonthlyPriceAmount: boolean, perUnitQuantity: number): number;
8
- export declare function getSelectedTierQuantityBeFeature(plan: PaywallPlan, billingPeriod: BillingPeriod, currentSubscription: Subscription | null): Record<string, number>;
5
+ export declare function getTierByQuantity(tiers: PriceTierFragment[], quantity: number): PriceTierFragment;
6
+ export declare function calculateTierPriceGraduated(tiers: PriceTierFragment[], unitQuantity: number, selectedBillingPeriod?: BillingPeriod, shouldShowMonthlyPriceAmount?: boolean): {
7
+ total: number;
8
+ breakdown: Array<{
9
+ unitQuantity: number;
10
+ amount: number;
11
+ }>;
12
+ };
13
+ export declare function calculateTierPrice(price: Pick<Price, 'tiers' | 'tiersMode'>, unitQuantity: number, selectedBillingPeriod?: BillingPeriod, shouldShowMonthlyPriceAmount?: boolean): number;
9
14
  export declare function hasTierWithUnitPrice(tiers: PriceTierFragment[] | null | undefined): boolean | undefined;
10
- export declare function getSelectedTier(plan: PaywallPlan, billingPeriod: BillingPeriod, currentSubscription: Subscription | null, selectedTierByFeature: Record<string, PriceTierFragment>, selectDefaultTierIndex?: SelectDefaultTierIndexFn): Record<string, PriceTierFragment>;
15
+ export declare function getTiersPerUnitQuantities(plan: PaywallPlan, billingPeriod: BillingPeriod, currentSubscription: Subscription | null, selectDefaultTierIndex?: SelectDefaultTierIndexFn): Record<string, number>;
11
16
  export declare enum PriceTierComparison {
12
17
  Lower = -1,
13
18
  Equal = 0,
14
19
  Higher = 1
15
20
  }
16
- export declare function compareSelectedTierToCurrentTier(selectedTierByFeature: Record<string, PriceTierFragment>, perUnitQuantityByFeature: Record<string, number>, currentSubscription: Subscription | null): PriceTierComparison;
21
+ export declare function compareSelectedTierToCurrentTier(perUnitQuantityByFeature: Record<string, number>, currentSubscription: Subscription | null): PriceTierComparison;
@@ -0,0 +1 @@
1
+ export {};