@stigg/react-sdk 4.2.2 → 4.2.4
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/react-sdk.cjs.development.js +34 -29
- package/dist/react-sdk.cjs.development.js.map +1 -1
- package/dist/react-sdk.cjs.production.min.js +1 -1
- package/dist/react-sdk.cjs.production.min.js.map +1 -1
- package/dist/react-sdk.esm.js +34 -29
- package/dist/react-sdk.esm.js.map +1 -1
- package/package.json +19 -5
- package/src/components/StiggProvider.tsx +7 -5
- package/src/components/paywall/BillingPeriodPicker.tsx +1 -1
- package/src/components/utils/calculateDiscountRate.ts +25 -13
- package/src/stories/CustomerPortal.stories.tsx +11 -11
- package/src/stories/Paywall.stories.tsx +4 -6
- package/src/stories/baseArgs.ts +1 -1
- package/src/theme/Fonts.tsx +1 -1
- package/src/theme/Theme.tsx +3 -4
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "4.2.
|
|
2
|
+
"version": "4.2.4",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"start": "tsdx watch",
|
|
15
15
|
"build": "tsdx build",
|
|
16
16
|
"test": "tsdx test --passWithNoTests",
|
|
17
|
-
"lint": "
|
|
17
|
+
"lint": "eslint src/**/*.{ts,tsx} --fix --max-warnings=0",
|
|
18
18
|
"size": "size-limit",
|
|
19
19
|
"analyze": "size-limit --why",
|
|
20
20
|
"storybook": "start-storybook -p 6006",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"husky": {
|
|
30
30
|
"hooks": {
|
|
31
|
-
"pre-commit": "
|
|
31
|
+
"pre-commit": "yarn lint"
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"name": "@stigg/react-sdk",
|
|
@@ -50,7 +50,6 @@
|
|
|
50
50
|
"@commitlint/config-conventional": "^17.0.3",
|
|
51
51
|
"@rollup/plugin-image": "^2.1.1",
|
|
52
52
|
"@size-limit/preset-small-lib": "^7.0.8",
|
|
53
|
-
"@stigg/eslint-config-stigg": "^0.0.7",
|
|
54
53
|
"@storybook/addon-actions": "^6.5.9",
|
|
55
54
|
"@storybook/addon-essentials": "^6.5.9",
|
|
56
55
|
"@storybook/addon-interactions": "^6.5.9",
|
|
@@ -79,7 +78,22 @@
|
|
|
79
78
|
"tsdx": "^0.14.1",
|
|
80
79
|
"tslib": "^2.4.0",
|
|
81
80
|
"typedoc": "^0.23.7",
|
|
82
|
-
"typescript": "^4.6.3"
|
|
81
|
+
"typescript": "^4.6.3",
|
|
82
|
+
"prettier": "^3.0.2",
|
|
83
|
+
"eslint": "^7.11.0",
|
|
84
|
+
"@stigg/eslint-config-stigg": "^0.0.7",
|
|
85
|
+
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
86
|
+
"@typescript-eslint/parser": "^5.0.0",
|
|
87
|
+
"eslint-config-airbnb": "^18.0.4",
|
|
88
|
+
"eslint-config-airbnb-typescript": "^16.1.0",
|
|
89
|
+
"eslint-config-prettier": "^8.3.0",
|
|
90
|
+
"eslint-plugin-jsx-a11y": "^6.3.1",
|
|
91
|
+
"eslint-plugin-import": "^2.28.1",
|
|
92
|
+
"eslint-plugin-jest": "^25.3.2",
|
|
93
|
+
"eslint-plugin-prettier": "^5.0.0",
|
|
94
|
+
"eslint-plugin-react": "^7.28.0",
|
|
95
|
+
"eslint-plugin-react-hooks": "^4.2.0",
|
|
96
|
+
"eslint-plugin-unused-imports": "^2.0.0"
|
|
83
97
|
},
|
|
84
98
|
"dependencies": {
|
|
85
99
|
"@emotion/react": "^11.10.5",
|
|
@@ -76,7 +76,7 @@ export const StiggProvider: React.FC<PropsWithChildren<StiggProviderProps>> = ({
|
|
|
76
76
|
isInitialized: false,
|
|
77
77
|
theme,
|
|
78
78
|
refreshData: async () => {
|
|
79
|
-
setContext(ctx => ({ ...ctx, customerPortalUpdatedAt: new Date() }));
|
|
79
|
+
setContext((ctx) => ({ ...ctx, customerPortalUpdatedAt: new Date() }));
|
|
80
80
|
await ctx.stigg.refresh();
|
|
81
81
|
},
|
|
82
82
|
}));
|
|
@@ -90,10 +90,10 @@ export const StiggProvider: React.FC<PropsWithChildren<StiggProviderProps>> = ({
|
|
|
90
90
|
}
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
-
const onEntitlementsUpdated = () => safeSetContext(ctx => ({ ...ctx, updatedAt: new Date() }));
|
|
93
|
+
const onEntitlementsUpdated = () => safeSetContext((ctx) => ({ ...ctx, updatedAt: new Date() }));
|
|
94
94
|
|
|
95
95
|
const setStiggInstance = (stigg: StiggJs.StiggClient) =>
|
|
96
|
-
safeSetContext(ctx => {
|
|
96
|
+
safeSetContext((ctx) => {
|
|
97
97
|
if (ctx.stigg) {
|
|
98
98
|
ctx.stigg.removeListener('entitlementsUpdated', onEntitlementsUpdated);
|
|
99
99
|
}
|
|
@@ -115,7 +115,7 @@ export const StiggProvider: React.FC<PropsWithChildren<StiggProviderProps>> = ({
|
|
|
115
115
|
stiggClient = Stigg.initialize({
|
|
116
116
|
...initializeParams,
|
|
117
117
|
});
|
|
118
|
-
safeSetContext(ctx => ({ ...ctx, isInitialized: false, updatedAt: new Date() }));
|
|
118
|
+
safeSetContext((ctx) => ({ ...ctx, isInitialized: false, updatedAt: new Date() }));
|
|
119
119
|
}
|
|
120
120
|
await stiggClient.waitForInitialization();
|
|
121
121
|
setStiggInstance(stiggClient);
|
|
@@ -128,6 +128,7 @@ export const StiggProvider: React.FC<PropsWithChildren<StiggProviderProps>> = ({
|
|
|
128
128
|
ctx.stigg.removeListener('entitlementsUpdated', onEntitlementsUpdated);
|
|
129
129
|
ctx.stigg.clearCustomer();
|
|
130
130
|
};
|
|
131
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
131
132
|
}, [apiKey]);
|
|
132
133
|
|
|
133
134
|
useEffect(() => {
|
|
@@ -137,10 +138,11 @@ export const StiggProvider: React.FC<PropsWithChildren<StiggProviderProps>> = ({
|
|
|
137
138
|
} else {
|
|
138
139
|
stiggClient.clearCustomer();
|
|
139
140
|
}
|
|
141
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
140
142
|
}, [customerId, customerToken, resourceId]);
|
|
141
143
|
|
|
142
144
|
useEffect(() => {
|
|
143
|
-
setContext(ctx => ({ ...ctx, theme }));
|
|
145
|
+
setContext((ctx) => ({ ...ctx, theme }));
|
|
144
146
|
}, [theme]);
|
|
145
147
|
|
|
146
148
|
return (
|
|
@@ -87,7 +87,7 @@ export function BillingPeriodPicker({
|
|
|
87
87
|
>
|
|
88
88
|
Annual
|
|
89
89
|
</PeriodText>
|
|
90
|
-
<DiscountRate discount={discountRate} disabled={isMonthlyBillingPeriod} />
|
|
90
|
+
{discountRate !== 0 && <DiscountRate discount={discountRate} disabled={isMonthlyBillingPeriod} />}
|
|
91
91
|
</PickerContainer>
|
|
92
92
|
);
|
|
93
93
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BillingPeriod } from '@stigg/js-client-sdk';
|
|
1
|
+
import { BillingPeriod, PaywallCalculatedPricePoint, Price } from '@stigg/js-client-sdk';
|
|
2
2
|
import isNil from 'lodash/isNil';
|
|
3
3
|
import { PaywallPlan } from '../paywall';
|
|
4
4
|
|
|
@@ -11,20 +11,32 @@ function calculateDiscountRate(monthlyPrice?: number | null, annuallyPrice?: num
|
|
|
11
11
|
return null;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
function getPlanBillingPeriodAmount(plan: PaywallPlan, billingPeriod: BillingPeriod) {
|
|
15
|
+
let pricePoint: PaywallCalculatedPricePoint | Price | undefined;
|
|
16
|
+
|
|
17
|
+
pricePoint = plan.paywallCalculatedPricePoints?.find(price => price.billingPeriod === billingPeriod);
|
|
18
|
+
|
|
19
|
+
if (!pricePoint) {
|
|
20
|
+
pricePoint = plan.pricePoints.find(price => price.billingPeriod === billingPeriod);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (!pricePoint?.amount) {
|
|
24
|
+
const tieredPrice = plan.pricePoints.find(price => {
|
|
25
|
+
return price.isTieredPrice && price.billingPeriod === billingPeriod;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
if (tieredPrice) {
|
|
29
|
+
return tieredPrice.tiers![0].unitPrice.amount;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return pricePoint?.amount;
|
|
34
|
+
}
|
|
35
|
+
|
|
14
36
|
export function calculatePaywallDiscountRate(plans: PaywallPlan[]) {
|
|
15
37
|
return plans.reduce((maxDiscount, plan) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (plan.paywallCalculatedPricePoints?.length) {
|
|
20
|
-
monthlyAmount = plan.paywallCalculatedPricePoints?.find(price => price.billingPeriod === BillingPeriod.Monthly)
|
|
21
|
-
?.amount;
|
|
22
|
-
annuallyAmount = plan.paywallCalculatedPricePoints?.find(price => price.billingPeriod === BillingPeriod.Annually)
|
|
23
|
-
?.amount;
|
|
24
|
-
} else {
|
|
25
|
-
monthlyAmount = plan.pricePoints.find(price => price.billingPeriod === BillingPeriod.Monthly)?.amount;
|
|
26
|
-
annuallyAmount = plan.pricePoints.find(price => price.billingPeriod === BillingPeriod.Annually)?.amount;
|
|
27
|
-
}
|
|
38
|
+
const monthlyAmount = getPlanBillingPeriodAmount(plan, BillingPeriod.Monthly);
|
|
39
|
+
const annuallyAmount = getPlanBillingPeriodAmount(plan, BillingPeriod.Annually);
|
|
28
40
|
|
|
29
41
|
const discountRate = calculateDiscountRate(monthlyAmount, annuallyAmount);
|
|
30
42
|
if (discountRate) {
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
Promotions,
|
|
12
12
|
StiggProvider,
|
|
13
13
|
SubscriptionsOverview,
|
|
14
|
-
} from '
|
|
14
|
+
} from '..';
|
|
15
15
|
import { CustomizedTheme } from '../theme/Theme';
|
|
16
16
|
import { Typography } from '../components/common/Typography';
|
|
17
17
|
import { defaultArgsWithCustomer } from './baseArgs';
|
|
@@ -33,8 +33,7 @@ export default {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
baseUri={args.baseUri}
|
|
36
|
-
enableEdge={args.disableEdge}
|
|
37
|
-
>
|
|
36
|
+
enableEdge={args.disableEdge}>
|
|
38
37
|
<Story />
|
|
39
38
|
</StiggProvider>
|
|
40
39
|
),
|
|
@@ -57,7 +56,8 @@ const ModularWrapper = styled.div`
|
|
|
57
56
|
}
|
|
58
57
|
`;
|
|
59
58
|
|
|
60
|
-
const Template: ComponentStory<any> = args => {
|
|
59
|
+
const Template: ComponentStory<any> = (args) => {
|
|
60
|
+
const { customerPortalTheme, productId } = args;
|
|
61
61
|
return (
|
|
62
62
|
<Wrapper>
|
|
63
63
|
<CustomerPortal
|
|
@@ -66,20 +66,20 @@ const Template: ComponentStory<any> = args => {
|
|
|
66
66
|
onManageSubscription={undefined}
|
|
67
67
|
paywallComponent={
|
|
68
68
|
<Paywall
|
|
69
|
-
productId={
|
|
69
|
+
productId={productId}
|
|
70
70
|
onPlanSelected={(...args) => {
|
|
71
71
|
console.log('onPlanSelected', args);
|
|
72
72
|
}}
|
|
73
73
|
highlightedPlanId="plan-revvenu-unity"
|
|
74
74
|
/>
|
|
75
75
|
}
|
|
76
|
-
theme={
|
|
76
|
+
theme={customerPortalTheme}
|
|
77
77
|
/>
|
|
78
78
|
</Wrapper>
|
|
79
79
|
);
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
-
const SubscriptionOverviewTemplate: ComponentStory<any> = args => {
|
|
82
|
+
const SubscriptionOverviewTemplate: ComponentStory<any> = (args) => {
|
|
83
83
|
return (
|
|
84
84
|
<CustomerPortalProvider>
|
|
85
85
|
<Wrapper>
|
|
@@ -94,7 +94,7 @@ const SubscriptionOverviewTemplate: ComponentStory<any> = args => {
|
|
|
94
94
|
);
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
-
const ModularCustomerPortalTemplate: ComponentStory<any> = args => {
|
|
97
|
+
const ModularCustomerPortalTemplate: ComponentStory<any> = (args) => {
|
|
98
98
|
return (
|
|
99
99
|
<CustomerPortalProvider>
|
|
100
100
|
<ModularWrapper>
|
|
@@ -130,7 +130,7 @@ const ModularCustomerPortalTemplate: ComponentStory<any> = args => {
|
|
|
130
130
|
);
|
|
131
131
|
};
|
|
132
132
|
|
|
133
|
-
const BillingInformationTemplate: ComponentStory<any> = args => {
|
|
133
|
+
const BillingInformationTemplate: ComponentStory<any> = (args) => {
|
|
134
134
|
return (
|
|
135
135
|
<CustomerPortalProvider>
|
|
136
136
|
<Wrapper>
|
|
@@ -140,7 +140,7 @@ const BillingInformationTemplate: ComponentStory<any> = args => {
|
|
|
140
140
|
);
|
|
141
141
|
};
|
|
142
142
|
|
|
143
|
-
const CustomerUsageDataTemplate: ComponentStory<any> = args => {
|
|
143
|
+
const CustomerUsageDataTemplate: ComponentStory<any> = (args) => {
|
|
144
144
|
return (
|
|
145
145
|
<CustomerPortalProvider>
|
|
146
146
|
<Wrapper>
|
|
@@ -150,7 +150,7 @@ const CustomerUsageDataTemplate: ComponentStory<any> = args => {
|
|
|
150
150
|
);
|
|
151
151
|
};
|
|
152
152
|
|
|
153
|
-
const SubscriptionAddonsTemplate: ComponentStory<any> = args => {
|
|
153
|
+
const SubscriptionAddonsTemplate: ComponentStory<any> = (args) => {
|
|
154
154
|
return (
|
|
155
155
|
<CustomerPortalProvider>
|
|
156
156
|
<Wrapper>
|
|
@@ -2,8 +2,7 @@ import { action } from '@storybook/addon-actions';
|
|
|
2
2
|
import { ComponentMeta, ComponentStory } from '@storybook/react';
|
|
3
3
|
import styled from '@emotion/styled/macro';
|
|
4
4
|
import React from 'react';
|
|
5
|
-
import { Paywall } from '../components/paywall';
|
|
6
|
-
import { PaywallPlan } from '../components/paywall';
|
|
5
|
+
import { Paywall, PaywallPlan } from '../components/paywall';
|
|
7
6
|
import { StiggProvider } from '../components/StiggProvider';
|
|
8
7
|
import { CustomizedTheme } from '../theme/Theme';
|
|
9
8
|
import { defaultArgs, defaultArgsWithCustomer } from './baseArgs';
|
|
@@ -22,8 +21,7 @@ export default {
|
|
|
22
21
|
theme={args.theme}
|
|
23
22
|
locale={args.locale}
|
|
24
23
|
baseUri={args.baseUri}
|
|
25
|
-
enableEdge={!args.disableEdge}
|
|
26
|
-
>
|
|
24
|
+
enableEdge={!args.disableEdge}>
|
|
27
25
|
<Story />
|
|
28
26
|
</StiggProvider>
|
|
29
27
|
</Wrapper>
|
|
@@ -31,7 +29,7 @@ export default {
|
|
|
31
29
|
],
|
|
32
30
|
} as ComponentMeta<typeof Paywall>;
|
|
33
31
|
|
|
34
|
-
const Template: ComponentStory<any> = args => (
|
|
32
|
+
const Template: ComponentStory<any> = (args) => (
|
|
35
33
|
<Paywall
|
|
36
34
|
highlightedPlanId={args.highlightedPlanId}
|
|
37
35
|
onPlanSelected={args.onPlanSelected ? args.onPlanSelected : action('onPlanSelected')}
|
|
@@ -112,7 +110,7 @@ CustomerAsyncCTA.args = {
|
|
|
112
110
|
highlightedPlanId: 'plan-revvenu-essentials',
|
|
113
111
|
showOnlyEligiblePlans: true,
|
|
114
112
|
onPlanSelected: async () => {
|
|
115
|
-
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
113
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
116
114
|
},
|
|
117
115
|
};
|
|
118
116
|
|
package/src/stories/baseArgs.ts
CHANGED
package/src/theme/Fonts.tsx
CHANGED
package/src/theme/Theme.tsx
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from 'react';
|
|
2
2
|
import { TypographyProps } from 'styled-typography';
|
|
3
|
-
import { css } from '@emotion/react';
|
|
3
|
+
import { css, ThemeProvider } from '@emotion/react';
|
|
4
4
|
import styled from '@emotion/styled/macro';
|
|
5
|
-
import { ThemeProvider } from '@emotion/react';
|
|
6
5
|
import { ThemeProvider as MuiThemeProvider, createTheme } from '@mui/material/styles';
|
|
7
6
|
import { ThemeProvider as StyledThemeProvider } from 'styled-components';
|
|
7
|
+
import { merge } from 'lodash';
|
|
8
8
|
import { Fonts } from './Fonts';
|
|
9
9
|
import { DeepPartial } from '../types';
|
|
10
10
|
import { StiggTheme } from './types';
|
|
11
11
|
import { useStiggContext } from '../components/StiggProvider';
|
|
12
|
-
import { merge } from 'lodash';
|
|
13
12
|
import { getResolvedTheme } from './getResolvedTheme';
|
|
14
13
|
|
|
15
14
|
export type CustomizedTheme = DeepPartial<StiggTheme>;
|
|
@@ -48,7 +47,7 @@ function createTypographyTheme(theme: StiggTheme): Partial<TypographyProps> {
|
|
|
48
47
|
return {
|
|
49
48
|
// Hack to fix theming issues
|
|
50
49
|
// @ts-ignore
|
|
51
|
-
pxToRem: size => `${(size / htmlFontSize) * coef}rem`,
|
|
50
|
+
pxToRem: (size) => `${(size / htmlFontSize) * coef}rem`,
|
|
52
51
|
bodyFontFamily: typography.fontFamily,
|
|
53
52
|
headingFontFamily: typography.fontFamily,
|
|
54
53
|
fontSizes: [
|