@stigg/react-sdk 6.3.0 → 6.4.1
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/components/EnumEntitlementGuard.d.ts +8 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useEnumEntitlement.d.ts +6 -0
- package/dist/index.d.ts +2 -1
- package/dist/react-sdk.cjs.development.js +44 -10
- 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 +44 -12
- package/dist/react-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/EnumEntitlementGuard.tsx +18 -0
- package/src/components/paywall/PlanCompatibleAddons.tsx +2 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useEnumEntitlement.ts +20 -0
- package/src/index.ts +2 -0
package/package.json
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { GetEnumEntitlement } from '@stigg/js-client-sdk';
|
|
3
|
+
import { useEnumEntitlement } from '../hooks';
|
|
4
|
+
|
|
5
|
+
type EnumEntitlementGuardProps = GetEnumEntitlement & {
|
|
6
|
+
noAccessComponent?: React.ReactNode;
|
|
7
|
+
children: React.ReactElement;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function EnumEntitlementGuard({ noAccessComponent, children, ...rest }: EnumEntitlementGuardProps): JSX.Element {
|
|
11
|
+
const { hasAccess } = useEnumEntitlement(rest);
|
|
12
|
+
|
|
13
|
+
if (!hasAccess) {
|
|
14
|
+
return <>{noAccessComponent ?? null}</>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return children;
|
|
18
|
+
}
|
|
@@ -90,6 +90,8 @@ export function PlanCompatibleAddons({ addons, paywallLocale }: PlanCompatibleAd
|
|
|
90
90
|
|
|
91
91
|
const displayedAddons = showAllAddons ? visibleAddons : visibleAddons.slice(0, MAX_ADDONS);
|
|
92
92
|
|
|
93
|
+
if (displayedAddons.length === 0) return null;
|
|
94
|
+
|
|
93
95
|
return (
|
|
94
96
|
<AddonsBox className="stigg-compatible-addons-container">
|
|
95
97
|
<Typography className="stigg-compatible-addons-header" color="secondary" variant="body1" bold>
|
package/src/hooks/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { useBooleanEntitlement } from './useBooleanEntitlement';
|
|
2
2
|
export { useNumericEntitlement } from './useNumericEntitlement';
|
|
3
3
|
export { useMeteredEntitlement } from './useMeteredEntitlement';
|
|
4
|
+
export { useEnumEntitlement } from './useEnumEntitlement';
|
|
4
5
|
export { useActiveSubscriptions } from './useActiveSubscriptions';
|
|
5
6
|
export { usePaywall } from './usePaywall';
|
|
6
7
|
export { useCustomerPortal } from './useCustomerPortal';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { GetEnumEntitlement, ENUM_DEFAULT_FALLBACK_ENTITLEMENT, EnumEntitlement } from '@stigg/js-client-sdk';
|
|
2
|
+
import { useStiggContext } from './useStiggContext';
|
|
3
|
+
|
|
4
|
+
type TypedGetEnumEntitlement<T> = Omit<GetEnumEntitlement, 'featureId'> & {
|
|
5
|
+
featureId: T;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export function useEnumEntitlement<T extends string>(params: TypedGetEnumEntitlement<T>): EnumEntitlement {
|
|
9
|
+
const stiggContext = useStiggContext({ optional: true });
|
|
10
|
+
const stigg = stiggContext?.stigg;
|
|
11
|
+
|
|
12
|
+
if (!stigg) {
|
|
13
|
+
return {
|
|
14
|
+
...ENUM_DEFAULT_FALLBACK_ENTITLEMENT,
|
|
15
|
+
...params.options?.fallback,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return stigg.getEnumEntitlement(params);
|
|
20
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -56,6 +56,7 @@ export { useWaitForCheckoutCompleted, ProvisionStatus } from './components/hooks
|
|
|
56
56
|
export {
|
|
57
57
|
useBooleanEntitlement,
|
|
58
58
|
useMeteredEntitlement,
|
|
59
|
+
useEnumEntitlement,
|
|
59
60
|
useNumericEntitlement,
|
|
60
61
|
useActiveSubscriptions,
|
|
61
62
|
useCustomerPortal,
|
|
@@ -67,3 +68,4 @@ export { CustomizedTheme as Theme } from './theme/Theme';
|
|
|
67
68
|
export { BooleanEntitlementGuard } from './components/BooleanEntitlementGuard';
|
|
68
69
|
export { NumericEntitlementGuard } from './components/NumericEntitlementGuard';
|
|
69
70
|
export { MeteredEntitlementGuard } from './components/MeteredEntitlementGuard';
|
|
71
|
+
export { EnumEntitlementGuard } from './components/EnumEntitlementGuard';
|