@stigg/react-sdk 6.3.0 → 6.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.
- 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 +34 -1
- 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 -3
- package/dist/react-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/EnumEntitlementGuard.tsx +18 -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
|
+
}
|
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';
|