@frontegg/react-hooks 7.78.0-alpha.1 → 7.78.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 (120) hide show
  1. package/audits/auditLogs.d.ts +3 -2
  2. package/audits/auditLogs.js +9 -8
  3. package/audits/auditsMetadata.d.ts +3 -2
  4. package/audits/auditsMetadata.js +9 -8
  5. package/audits/hooks.d.ts +9 -2
  6. package/audits/hooks.js +14 -10
  7. package/auth/acceptInvitation.d.ts +5 -7
  8. package/auth/acceptInvitation.js +13 -8
  9. package/auth/activateAccount.d.ts +5 -11
  10. package/auth/activateAccount.js +13 -8
  11. package/auth/allAccounts.d.ts +7 -47
  12. package/auth/allAccounts.js +20 -12
  13. package/auth/apiTokens.d.ts +3 -14
  14. package/auth/apiTokens.js +9 -8
  15. package/auth/applications.d.ts +3 -22
  16. package/auth/applications.js +9 -8
  17. package/auth/customLogin.d.ts +3 -9
  18. package/auth/customLogin.js +12 -9
  19. package/auth/entitlements.d.ts +25 -6
  20. package/auth/entitlements.js +73 -41
  21. package/auth/forgotPassword.d.ts +3 -12
  22. package/auth/forgotPassword.js +9 -10
  23. package/auth/groups.d.ts +5 -32
  24. package/auth/groups.js +14 -14
  25. package/auth/impersonate.d.ts +3 -6
  26. package/auth/impersonate.js +8 -8
  27. package/auth/login.d.ts +3 -74
  28. package/auth/login.js +8 -8
  29. package/auth/passkeys.d.ts +3 -10
  30. package/auth/passkeys.js +8 -8
  31. package/auth/passwordRotation.d.ts +3 -4
  32. package/auth/passwordRotation.js +9 -8
  33. package/auth/profile.d.ts +3 -19
  34. package/auth/profile.js +12 -17
  35. package/auth/provisioning.d.ts +3 -20
  36. package/auth/provisioning.js +8 -8
  37. package/auth/resetPhoneNumber.d.ts +3 -8
  38. package/auth/resetPhoneNumber.js +8 -8
  39. package/auth/roles.d.ts +3 -14
  40. package/auth/roles.js +8 -8
  41. package/auth/security/restrictions.d.ts +3 -21
  42. package/auth/security/restrictions.js +19 -20
  43. package/auth/security/securityCenter.d.ts +3 -15
  44. package/auth/security/securityCenter.js +9 -8
  45. package/auth/security/securityPolicy.d.ts +5 -35
  46. package/auth/security/securityPolicy.js +18 -16
  47. package/auth/security/sessionsPolicy.d.ts +3 -7
  48. package/auth/security/sessionsPolicy.js +9 -8
  49. package/auth/sessions.d.ts +3 -12
  50. package/auth/sessions.js +8 -8
  51. package/auth/signup.d.ts +5 -10
  52. package/auth/signup.js +16 -8
  53. package/auth/sms.d.ts +3 -13
  54. package/auth/sms.js +8 -8
  55. package/auth/socialLogin.d.ts +5 -9
  56. package/auth/socialLogin.js +13 -8
  57. package/auth/sso.d.ts +6 -31
  58. package/auth/sso.js +13 -8
  59. package/auth/stepUp.d.ts +14 -15
  60. package/auth/stepUp.js +22 -9
  61. package/auth/team.d.ts +13 -84
  62. package/auth/team.js +23 -12
  63. package/auth/tenants.d.ts +3 -9
  64. package/auth/tenants.js +9 -8
  65. package/auth/unlockAccount.d.ts +5 -6
  66. package/auth/unlockAccount.js +10 -8
  67. package/auth/usernames.d.ts +3 -7
  68. package/auth/usernames.js +8 -8
  69. package/auth/usersEmailsPolicyState.d.ts +5 -5
  70. package/auth/usersEmailsPolicyState.js +10 -8
  71. package/connectivity/hooks.d.ts +3 -41
  72. package/connectivity/hooks.js +9 -8
  73. package/index.js +1 -1
  74. package/node/audits/auditLogs.js +12 -11
  75. package/node/audits/auditsMetadata.js +12 -11
  76. package/node/audits/hooks.js +17 -13
  77. package/node/auth/acceptInvitation.js +13 -11
  78. package/node/auth/activateAccount.js +13 -11
  79. package/node/auth/allAccounts.js +20 -15
  80. package/node/auth/apiTokens.js +12 -11
  81. package/node/auth/applications.js +12 -11
  82. package/node/auth/customLogin.js +15 -11
  83. package/node/auth/entitlements.js +73 -41
  84. package/node/auth/forgotPassword.js +12 -13
  85. package/node/auth/groups.js +17 -17
  86. package/node/auth/impersonate.js +11 -11
  87. package/node/auth/login.js +11 -11
  88. package/node/auth/passkeys.js +11 -11
  89. package/node/auth/passwordRotation.js +12 -11
  90. package/node/auth/profile.js +13 -19
  91. package/node/auth/provisioning.js +11 -11
  92. package/node/auth/resetPhoneNumber.js +11 -11
  93. package/node/auth/roles.js +11 -11
  94. package/node/auth/security/restrictions.js +21 -22
  95. package/node/auth/security/securityCenter.js +12 -11
  96. package/node/auth/security/securityPolicy.js +17 -18
  97. package/node/auth/security/sessionsPolicy.js +12 -11
  98. package/node/auth/sessions.js +11 -11
  99. package/node/auth/signup.js +16 -11
  100. package/node/auth/sms.js +11 -11
  101. package/node/auth/socialLogin.js +13 -11
  102. package/node/auth/sso.js +13 -11
  103. package/node/auth/stepUp.js +24 -11
  104. package/node/auth/team.js +28 -16
  105. package/node/auth/tenants.js +12 -11
  106. package/node/auth/unlockAccount.js +13 -11
  107. package/node/auth/usernames.js +11 -11
  108. package/node/auth/usersEmailsPolicyState.js +13 -11
  109. package/node/connectivity/hooks.js +12 -11
  110. package/node/index.js +1 -1
  111. package/node/subscriptions/hooks.js +115 -86
  112. package/node/vendor/hooks.js +14 -11
  113. package/package.json +3 -3
  114. package/subscriptions/hooks.d.ts +22 -48
  115. package/subscriptions/hooks.js +103 -77
  116. package/vendor/hooks.d.ts +5 -2
  117. package/vendor/hooks.js +14 -8
  118. package/node/useSnapshot/hookFactory.js +0 -32
  119. package/useSnapshot/hookFactory.d.ts +0 -18
  120. package/useSnapshot/hookFactory.js +0 -26
@@ -6,102 +6,131 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.useVendorPublicConfigActions = exports.useVendorPublicConfig = exports.useSubscriptionRenewal = exports.useSubscriptionCancellation = exports.useSubscriptionActions = exports.useSubscription = exports.useStripeState = exports.useStripeActions = exports.usePlansActions = exports.usePlans = exports.usePaymentProviderActions = exports.usePaymentProvider = exports.usePaymentMethodActions = exports.usePaymentMethod = exports.useInvoicesActions = exports.useInvoices = exports.useCheckoutActions = exports.useCheckout = exports.useBillingInformationActions = exports.useBillingInformation = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
- var _hookFactory = require("../useSnapshot/hookFactory");
10
- /* ───────────────────────── subscriptions root helpers ───────────────────────── */
11
-
12
- const {
13
- useSliceState: usePaymentProvider,
14
- useSliceActions: usePaymentProviderActions
15
- } = (0, _hookFactory.createSliceHooks)({
16
- getState: s => s.subscriptions.config,
17
- getActions: a => a.subscriptions.config
18
- });
19
- exports.usePaymentProviderActions = usePaymentProviderActions;
9
+ var _FronteggStoreContext = require("../FronteggStoreContext");
10
+ var _useSnapshot = require("../useSnapshot");
11
+ function getSubscriptionsState() {
12
+ // eslint-disable-next-line react-hooks/rules-of-hooks
13
+ return (0, _FronteggStoreContext.useStore)().store.subscriptions;
14
+ }
15
+ const usePaymentProvider = () => {
16
+ const {
17
+ config
18
+ } = getSubscriptionsState();
19
+ return (0, _useSnapshot.useSnapshot)(config);
20
+ };
20
21
  exports.usePaymentProvider = usePaymentProvider;
21
- const {
22
- useSliceState: usePlans,
23
- useSliceActions: usePlansActions
24
- } = (0, _hookFactory.createSliceHooks)({
25
- getState: s => s.subscriptions.plans,
26
- getActions: a => a.subscriptions.plans
27
- });
28
- exports.usePlansActions = usePlansActions;
22
+ const usePaymentProviderActions = () => {
23
+ return (0, _FronteggStoreContext.useStore)().stateActions.subscriptions.config;
24
+ };
25
+ exports.usePaymentProviderActions = usePaymentProviderActions;
26
+ const usePlans = () => {
27
+ const {
28
+ plans
29
+ } = getSubscriptionsState();
30
+ return (0, _useSnapshot.useSnapshot)(plans);
31
+ };
29
32
  exports.usePlans = usePlans;
30
- const {
31
- useSliceState: useCheckout,
32
- useSliceActions: useCheckoutActions
33
- } = (0, _hookFactory.createSliceHooks)({
34
- getState: s => s.subscriptions.checkout,
35
- getActions: a => a.subscriptions.checkout
36
- });
37
- exports.useCheckoutActions = useCheckoutActions;
33
+ const usePlansActions = () => {
34
+ return (0, _FronteggStoreContext.useStore)().stateActions.subscriptions.plans;
35
+ };
36
+ exports.usePlansActions = usePlansActions;
37
+ const useCheckout = () => {
38
+ const {
39
+ checkout
40
+ } = getSubscriptionsState();
41
+ return (0, _useSnapshot.useSnapshot)(checkout);
42
+ };
38
43
  exports.useCheckout = useCheckout;
39
- const {
40
- useSliceState: useStripeState,
41
- useSliceActions: useStripeActions
42
- } = (0, _hookFactory.createSliceHooks)({
43
- getState: s => s.subscriptions.stripe,
44
- getActions: a => a.subscriptions.stripe
45
- });
46
- exports.useStripeActions = useStripeActions;
47
- exports.useStripeState = useStripeState;
48
- const {
49
- useSliceState: useVendorPublicConfig,
50
- useSliceActions: useVendorPublicConfigActions
51
- } = (0, _hookFactory.createSliceHooks)({
52
- getState: s => s.subscriptions.vendorPublicConfig,
53
- getActions: a => a.subscriptions.vendorPublicConfig
54
- });
55
-
56
- /* ───────────────────────── billing sub-slices ───────────────────────── */
57
- exports.useVendorPublicConfigActions = useVendorPublicConfigActions;
58
- exports.useVendorPublicConfig = useVendorPublicConfig;
59
- const {
60
- useSliceState: useBillingInformation,
61
- useSliceActions: useBillingInformationActions
62
- } = (0, _hookFactory.createSliceHooks)({
63
- getState: s => s.subscriptions.billing.information,
64
- getActions: a => a.subscriptions.billing.information
65
- });
66
- exports.useBillingInformationActions = useBillingInformationActions;
44
+ const useCheckoutActions = () => {
45
+ return (0, _FronteggStoreContext.useStore)().stateActions.subscriptions.checkout;
46
+ };
47
+ exports.useCheckoutActions = useCheckoutActions;
48
+ const useBillingActions = billingKey => {
49
+ return (0, _FronteggStoreContext.useStore)().stateActions.subscriptions.billing[billingKey];
50
+ };
51
+ const useBillingInformation = () => {
52
+ const {
53
+ billing
54
+ } = getSubscriptionsState();
55
+ return (0, _useSnapshot.useSnapshot)(billing.information);
56
+ };
67
57
  exports.useBillingInformation = useBillingInformation;
68
- const {
69
- useSliceState: usePaymentMethod,
70
- useSliceActions: usePaymentMethodActions
71
- } = (0, _hookFactory.createSliceHooks)({
72
- getState: s => s.subscriptions.billing.paymentMethod,
73
- getActions: a => a.subscriptions.billing.paymentMethod
74
- });
75
- exports.usePaymentMethodActions = usePaymentMethodActions;
58
+ const useBillingInformationActions = () => {
59
+ return useBillingActions('information');
60
+ };
61
+ exports.useBillingInformationActions = useBillingInformationActions;
62
+ const usePaymentMethod = () => {
63
+ const {
64
+ billing
65
+ } = getSubscriptionsState();
66
+ return (0, _useSnapshot.useSnapshot)(billing.paymentMethod);
67
+ };
76
68
  exports.usePaymentMethod = usePaymentMethod;
77
- const {
78
- useSliceState: useInvoices,
79
- useSliceActions: useInvoicesActions
80
- } = (0, _hookFactory.createSliceHooks)({
81
- getState: s => s.subscriptions.billing.invoices,
82
- getActions: a => a.subscriptions.billing.invoices
83
- });
84
-
85
- /* ───────────────────────── subscription sub-slice ───────────────────────── */
86
- exports.useInvoicesActions = useInvoicesActions;
69
+ const usePaymentMethodActions = () => {
70
+ return useBillingActions('paymentMethod');
71
+ };
72
+ exports.usePaymentMethodActions = usePaymentMethodActions;
73
+ const useInvoices = () => {
74
+ const {
75
+ billing
76
+ } = getSubscriptionsState();
77
+ return (0, _useSnapshot.useSnapshot)(billing.invoices);
78
+ };
87
79
  exports.useInvoices = useInvoices;
88
- const {
89
- useSliceState: useSubscriptionState,
90
- useSliceActions: _useSubscriptionActions
91
- } = (0, _hookFactory.createSliceHooks)({
92
- getState: s => s.subscriptions.billing.subscription,
93
- getActions: a => a.subscriptions.billing.subscription
94
- });
95
- const useSubscription = useSubscriptionState;
96
- exports.useSubscription = useSubscription;
97
- const useSubscriptionCancellation = () => useSubscription().cancellation;
80
+ const useInvoicesActions = () => {
81
+ return useBillingActions('invoices');
82
+ };
83
+ exports.useInvoicesActions = useInvoicesActions;
84
+ const useSubscriptionCancellation = () => {
85
+ const {
86
+ billing
87
+ } = getSubscriptionsState();
88
+ const {
89
+ cancellation
90
+ } = (0, _useSnapshot.useSnapshot)(billing.subscription);
91
+ return cancellation;
92
+ };
98
93
  exports.useSubscriptionCancellation = useSubscriptionCancellation;
99
- const useSubscriptionRenewal = () => useSubscription().renewal;
94
+ const useSubscriptionRenewal = () => {
95
+ const {
96
+ billing
97
+ } = getSubscriptionsState();
98
+ const {
99
+ renewal
100
+ } = (0, _useSnapshot.useSnapshot)(billing.subscription);
101
+ return renewal;
102
+ };
100
103
  exports.useSubscriptionRenewal = useSubscriptionRenewal;
104
+ const useSubscription = () => {
105
+ const {
106
+ billing
107
+ } = getSubscriptionsState();
108
+ return (0, _useSnapshot.useSnapshot)(billing.subscription);
109
+ };
110
+ exports.useSubscription = useSubscription;
101
111
  const useSubscriptionActions = () => {
102
- const actions = _useSubscriptionActions();
112
+ const actions = (0, _FronteggStoreContext.useStore)().stateActions.subscriptions.billing.subscription;
103
113
  return (0, _extends2.default)({}, actions, {
104
114
  load: actions.loadSubscription
105
115
  });
106
116
  };
107
- exports.useSubscriptionActions = useSubscriptionActions;
117
+ exports.useSubscriptionActions = useSubscriptionActions;
118
+ const useStripeState = () => {
119
+ const {
120
+ stripe
121
+ } = getSubscriptionsState();
122
+ return (0, _useSnapshot.useSnapshot)(stripe);
123
+ };
124
+ exports.useStripeState = useStripeState;
125
+ const useStripeActions = () => {
126
+ return (0, _FronteggStoreContext.useStore)().stateActions.subscriptions.stripe;
127
+ };
128
+ exports.useStripeActions = useStripeActions;
129
+ const useVendorPublicConfig = () => {
130
+ return (0, _useSnapshot.useSnapshot)((0, _FronteggStoreContext.useStore)().store.subscriptions.vendorPublicConfig);
131
+ };
132
+ exports.useVendorPublicConfig = useVendorPublicConfig;
133
+ const useVendorPublicConfigActions = () => {
134
+ return (0, _FronteggStoreContext.useStore)().stateActions.subscriptions.vendorPublicConfig;
135
+ };
136
+ exports.useVendorPublicConfigActions = useVendorPublicConfigActions;
@@ -3,14 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useVendorState = exports.useVendorActions = void 0;
7
- var _hookFactory = require("../useSnapshot/hookFactory");
8
- const {
9
- useSliceState: useVendorState,
10
- useSliceActions: useVendorActions
11
- } = (0, _hookFactory.createSliceHooks)({
12
- getState: s => s.vendor,
13
- getActions: a => a.vendor
14
- });
15
- exports.useVendorActions = useVendorActions;
16
- exports.useVendorState = useVendorState;
6
+ exports.useVendorActions = void 0;
7
+ exports.useVendorState = useVendorState;
8
+ var _FronteggStoreContext = require("../FronteggStoreContext");
9
+ var _useSnapshot = require("../useSnapshot");
10
+ const defaultMapper = state => state;
11
+ // @deprecated use useVendorState() instead
12
+ function useVendorState(stateMapper = defaultMapper) {
13
+ const state = (0, _FronteggStoreContext.useStore)().store.vendor;
14
+ return stateMapper((0, _useSnapshot.useSnapshot)(state));
15
+ }
16
+ const useVendorActions = () => {
17
+ return (0, _FronteggStoreContext.useStore)().stateActions.vendor;
18
+ };
19
+ exports.useVendorActions = useVendorActions;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@frontegg/react-hooks",
3
- "version": "7.78.0-alpha.1",
3
+ "version": "7.78.0",
4
4
  "main": "./node/index.js",
5
5
  "license": "MIT",
6
6
  "author": "Frontegg LTD",
7
7
  "dependencies": {
8
8
  "@babel/runtime": "^7.18.6",
9
- "@frontegg/redux-store": "7.78.0-alpha.1",
10
- "@frontegg/types": "7.78.0-alpha.1",
9
+ "@frontegg/redux-store": "7.78.0",
10
+ "@frontegg/types": "7.78.0",
11
11
  "@types/react": "*",
12
12
  "@types/react-is": "^17.0.7",
13
13
  "get-value": "^3.0.1",
@@ -1,34 +1,19 @@
1
- import { CheckoutState, PaymentProviderConfigState, PaymentProviderConfigActions, PlansState, StripeState, StripeActions, BillingInformationState, PaymentMethodState, InvoicesState, SubscriptionState, VendorPublicConfigurationState } from '@frontegg/redux-store';
2
- export declare const usePaymentProvider: <S = PaymentProviderConfigState>(selector?: (s: PaymentProviderConfigState) => S) => S, usePaymentProviderActions: () => PaymentProviderConfigActions;
3
- export declare const usePlans: <S = PlansState>(selector?: (s: PlansState) => S) => S, usePlansActions: () => {
4
- setPlansState: (state: Partial<PlansState>) => void;
5
- resetPlansState: () => void;
6
- loadPlans: () => Promise<void>;
7
- };
8
- export declare const useCheckout: <S = CheckoutState>(selector?: (s: CheckoutState) => S) => S, useCheckoutActions: () => {
9
- setCheckoutState: (state: Partial<CheckoutState>) => void;
10
- resetCheckoutState: () => void;
11
- loadCheckout: () => void;
12
- resetCheckout: () => void;
13
- submitCheckout: () => void;
14
- confirmCheckout: (payload: import("@frontegg/redux-store").ConfirmCheckoutActionPayload) => Promise<void>;
15
- errorCheckout: (payload: import("dist/@frontegg/rest-api").FronteggApiError) => void;
16
- };
17
- export declare const useStripeState: <S = StripeState>(selector?: (s: StripeState) => S) => S, useStripeActions: () => StripeActions;
18
- export declare const useVendorPublicConfig: <S = VendorPublicConfigurationState>(selector?: (s: VendorPublicConfigurationState) => S) => S, useVendorPublicConfigActions: () => {
19
- setVendorPublicConfigState: (state: Partial<VendorPublicConfigurationState>) => void;
20
- resetVendorPublicConfigState: () => void;
21
- setVendorPublicConfigError: (error: import("dist/@frontegg/rest-api").FronteggApiError) => void;
22
- setVendorPublicConfigLoading: (loading: boolean) => void;
23
- loadVendorPublicConfiguration: () => Promise<void>;
24
- };
25
- export declare const useBillingInformation: <S = BillingInformationState>(selector?: (s: BillingInformationState) => S) => S, useBillingInformationActions: () => {
1
+ import { CheckoutActions, CheckoutState, PaymentProviderConfigActions, PaymentProviderConfigState, PlansActions, PlansState, StripeActions, StripeState, SubscriptionState, BillingInformationState, InvoicesState, PaymentMethodState, BillingStateActions, VendorPublicConfigurationState, VendorPublicConfigurationActions } from '@frontegg/redux-store';
2
+ export declare const usePaymentProvider: () => PaymentProviderConfigState;
3
+ export declare const usePaymentProviderActions: () => PaymentProviderConfigActions;
4
+ export declare const usePlans: () => PlansState;
5
+ export declare const usePlansActions: () => PlansActions;
6
+ export declare const useCheckout: () => CheckoutState;
7
+ export declare const useCheckoutActions: () => CheckoutActions;
8
+ export declare const useBillingInformation: () => BillingInformationState;
9
+ export declare const useBillingInformationActions: () => {
26
10
  setBillingInformationState: (state: Partial<BillingInformationState>) => void;
27
11
  resetBillingInformationState: () => void;
28
12
  loadSummaries: (tenantId: string, forceActive?: boolean) => Promise<void>;
29
13
  loadBillingInformation: (forceActive?: boolean) => Promise<void>;
30
14
  };
31
- export declare const usePaymentMethod: <S = PaymentMethodState>(selector?: (s: PaymentMethodState) => S) => S, usePaymentMethodActions: () => {
15
+ export declare const usePaymentMethod: () => PaymentMethodState;
16
+ export declare const usePaymentMethodActions: () => {
32
17
  setBillingPaymentMethodState: (state: Partial<{}>) => void;
33
18
  resetBillingPaymentMethodState: () => void;
34
19
  loadPaymentMethod: () => Promise<void>;
@@ -37,7 +22,8 @@ export declare const usePaymentMethod: <S = PaymentMethodState>(selector?: (s: P
37
22
  submitPaymentMethodSuccess: () => Promise<void>;
38
23
  updatePaymentMethodBillingDetails: (payload: import("@frontegg/redux-store").WithCallback<import("@frontegg/redux-store").WithId<import("dist/@frontegg/rest-api").ISubscriptionUpdatePaymentMethodBillingDetails>>) => Promise<void>;
39
24
  };
40
- export declare const useInvoices: <S = InvoicesState>(selector?: (s: InvoicesState) => S) => S, useInvoicesActions: () => {
25
+ export declare const useInvoices: () => InvoicesState;
26
+ export declare const useInvoicesActions: () => {
41
27
  setBillingInvoiceState: (state: Partial<InvoicesState>) => void;
42
28
  resetBillingInvoiceState: () => void;
43
29
  loadInvoices: () => Promise<void>;
@@ -45,25 +31,13 @@ export declare const useInvoices: <S = InvoicesState>(selector?: (s: InvoicesSta
45
31
  downloadInvoice: (payload: import("@frontegg/redux-store").DownloadInvoiceActionPayload) => Promise<void>;
46
32
  downloadBillingInvoice: (payload: import("@frontegg/redux-store").DownloadInvoiceActionPayload) => Promise<void>;
47
33
  };
48
- export declare const useSubscription: <S = SubscriptionState>(selector?: (s: SubscriptionState) => S) => S;
49
- export declare const useSubscriptionCancellation: () => {
50
- loading: boolean;
51
- error: import("dist/@frontegg/rest-api").FronteggApiError | null;
52
- };
53
- export declare const useSubscriptionRenewal: () => {
54
- loading: boolean;
55
- error: import("dist/@frontegg/rest-api").FronteggApiError | null;
56
- };
57
- export declare const useSubscriptionActions: () => {
58
- load: () => Promise<void>;
59
- setBillingSubscriptionState: (state: Partial<{}>) => void;
60
- resetBillingSubscriptionState: () => void;
61
- setCancellationLoading: (loading: boolean) => void;
62
- setCancellationError: (error: import("dist/@frontegg/rest-api").FronteggApiError | null) => void;
63
- setRenewalLoading: (loading: boolean) => void;
64
- setRenewalError: (error: import("dist/@frontegg/rest-api").FronteggApiError | null) => void;
65
- loadSubscription: () => Promise<void>;
66
- loadSubscriptionTenant: () => Promise<void>;
67
- cancelSubscription: () => Promise<void>;
68
- renewSubscription: () => Promise<void>;
34
+ export declare const useSubscriptionCancellation: () => SubscriptionState["cancellation"];
35
+ export declare const useSubscriptionRenewal: () => SubscriptionState["renewal"];
36
+ export declare const useSubscription: () => SubscriptionState;
37
+ export declare const useSubscriptionActions: () => BillingStateActions["subscription"] & {
38
+ load: () => void;
69
39
  };
40
+ export declare const useStripeState: () => StripeState;
41
+ export declare const useStripeActions: () => StripeActions;
42
+ export declare const useVendorPublicConfig: () => VendorPublicConfigurationState;
43
+ export declare const useVendorPublicConfigActions: () => VendorPublicConfigurationActions;
@@ -1,83 +1,109 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- import { createSliceHooks } from '../useSnapshot/hookFactory';
3
-
4
- /* ───────────────────────── subscriptions root helpers ───────────────────────── */
5
-
6
- export const {
7
- useSliceState: usePaymentProvider,
8
- useSliceActions: usePaymentProviderActions
9
- } = createSliceHooks({
10
- getState: s => s.subscriptions.config,
11
- getActions: a => a.subscriptions.config
12
- });
13
- export const {
14
- useSliceState: usePlans,
15
- useSliceActions: usePlansActions
16
- } = createSliceHooks({
17
- getState: s => s.subscriptions.plans,
18
- getActions: a => a.subscriptions.plans
19
- });
20
- export const {
21
- useSliceState: useCheckout,
22
- useSliceActions: useCheckoutActions
23
- } = createSliceHooks({
24
- getState: s => s.subscriptions.checkout,
25
- getActions: a => a.subscriptions.checkout
26
- });
27
- export const {
28
- useSliceState: useStripeState,
29
- useSliceActions: useStripeActions
30
- } = createSliceHooks({
31
- getState: s => s.subscriptions.stripe,
32
- getActions: a => a.subscriptions.stripe
33
- });
34
- export const {
35
- useSliceState: useVendorPublicConfig,
36
- useSliceActions: useVendorPublicConfigActions
37
- } = createSliceHooks({
38
- getState: s => s.subscriptions.vendorPublicConfig,
39
- getActions: a => a.subscriptions.vendorPublicConfig
40
- });
41
-
42
- /* ───────────────────────── billing sub-slices ───────────────────────── */
43
-
44
- export const {
45
- useSliceState: useBillingInformation,
46
- useSliceActions: useBillingInformationActions
47
- } = createSliceHooks({
48
- getState: s => s.subscriptions.billing.information,
49
- getActions: a => a.subscriptions.billing.information
50
- });
51
- export const {
52
- useSliceState: usePaymentMethod,
53
- useSliceActions: usePaymentMethodActions
54
- } = createSliceHooks({
55
- getState: s => s.subscriptions.billing.paymentMethod,
56
- getActions: a => a.subscriptions.billing.paymentMethod
57
- });
58
- export const {
59
- useSliceState: useInvoices,
60
- useSliceActions: useInvoicesActions
61
- } = createSliceHooks({
62
- getState: s => s.subscriptions.billing.invoices,
63
- getActions: a => a.subscriptions.billing.invoices
64
- });
65
-
66
- /* ───────────────────────── subscription sub-slice ───────────────────────── */
67
-
68
- const {
69
- useSliceState: useSubscriptionState,
70
- useSliceActions: _useSubscriptionActions
71
- } = createSliceHooks({
72
- getState: s => s.subscriptions.billing.subscription,
73
- getActions: a => a.subscriptions.billing.subscription
74
- });
75
- export const useSubscription = useSubscriptionState;
76
- export const useSubscriptionCancellation = () => useSubscription().cancellation;
77
- export const useSubscriptionRenewal = () => useSubscription().renewal;
2
+ import { useStore } from '../FronteggStoreContext';
3
+ import { useSnapshot } from '../useSnapshot';
4
+ function getSubscriptionsState() {
5
+ // eslint-disable-next-line react-hooks/rules-of-hooks
6
+ return useStore().store.subscriptions;
7
+ }
8
+ export const usePaymentProvider = () => {
9
+ const {
10
+ config
11
+ } = getSubscriptionsState();
12
+ return useSnapshot(config);
13
+ };
14
+ export const usePaymentProviderActions = () => {
15
+ return useStore().stateActions.subscriptions.config;
16
+ };
17
+ export const usePlans = () => {
18
+ const {
19
+ plans
20
+ } = getSubscriptionsState();
21
+ return useSnapshot(plans);
22
+ };
23
+ export const usePlansActions = () => {
24
+ return useStore().stateActions.subscriptions.plans;
25
+ };
26
+ export const useCheckout = () => {
27
+ const {
28
+ checkout
29
+ } = getSubscriptionsState();
30
+ return useSnapshot(checkout);
31
+ };
32
+ export const useCheckoutActions = () => {
33
+ return useStore().stateActions.subscriptions.checkout;
34
+ };
35
+ const useBillingActions = billingKey => {
36
+ return useStore().stateActions.subscriptions.billing[billingKey];
37
+ };
38
+ export const useBillingInformation = () => {
39
+ const {
40
+ billing
41
+ } = getSubscriptionsState();
42
+ return useSnapshot(billing.information);
43
+ };
44
+ export const useBillingInformationActions = () => {
45
+ return useBillingActions('information');
46
+ };
47
+ export const usePaymentMethod = () => {
48
+ const {
49
+ billing
50
+ } = getSubscriptionsState();
51
+ return useSnapshot(billing.paymentMethod);
52
+ };
53
+ export const usePaymentMethodActions = () => {
54
+ return useBillingActions('paymentMethod');
55
+ };
56
+ export const useInvoices = () => {
57
+ const {
58
+ billing
59
+ } = getSubscriptionsState();
60
+ return useSnapshot(billing.invoices);
61
+ };
62
+ export const useInvoicesActions = () => {
63
+ return useBillingActions('invoices');
64
+ };
65
+ export const useSubscriptionCancellation = () => {
66
+ const {
67
+ billing
68
+ } = getSubscriptionsState();
69
+ const {
70
+ cancellation
71
+ } = useSnapshot(billing.subscription);
72
+ return cancellation;
73
+ };
74
+ export const useSubscriptionRenewal = () => {
75
+ const {
76
+ billing
77
+ } = getSubscriptionsState();
78
+ const {
79
+ renewal
80
+ } = useSnapshot(billing.subscription);
81
+ return renewal;
82
+ };
83
+ export const useSubscription = () => {
84
+ const {
85
+ billing
86
+ } = getSubscriptionsState();
87
+ return useSnapshot(billing.subscription);
88
+ };
78
89
  export const useSubscriptionActions = () => {
79
- const actions = _useSubscriptionActions();
90
+ const actions = useStore().stateActions.subscriptions.billing.subscription;
80
91
  return _extends({}, actions, {
81
92
  load: actions.loadSubscription
82
93
  });
94
+ };
95
+ export const useStripeState = () => {
96
+ const {
97
+ stripe
98
+ } = getSubscriptionsState();
99
+ return useSnapshot(stripe);
100
+ };
101
+ export const useStripeActions = () => {
102
+ return useStore().stateActions.subscriptions.stripe;
103
+ };
104
+ export const useVendorPublicConfig = () => {
105
+ return useSnapshot(useStore().store.subscriptions.vendorPublicConfig);
106
+ };
107
+ export const useVendorPublicConfigActions = () => {
108
+ return useStore().stateActions.subscriptions.vendorPublicConfig;
83
109
  };
package/vendor/hooks.d.ts CHANGED
@@ -1,2 +1,5 @@
1
- import type { VendorState, VendorActions } from '@frontegg/redux-store';
2
- export declare const useVendorState: <S = VendorState>(selector?: (s: VendorState) => S) => S, useVendorActions: () => VendorActions;
1
+ import { VendorActions, VendorState } from '@frontegg/redux-store';
2
+ export type VendorStateMapper<S> = (state: VendorState) => S;
3
+ export declare function useVendorState(): VendorState;
4
+ export declare function useVendorState<S>(stateMapper: VendorStateMapper<S>): S;
5
+ export declare const useVendorActions: () => VendorActions;
package/vendor/hooks.js CHANGED
@@ -1,8 +1,14 @@
1
- import { createSliceHooks } from '../useSnapshot/hookFactory';
2
- export const {
3
- useSliceState: useVendorState,
4
- useSliceActions: useVendorActions
5
- } = createSliceHooks({
6
- getState: s => s.vendor,
7
- getActions: a => a.vendor
8
- });
1
+ import { useStore } from '../FronteggStoreContext';
2
+ import { useSnapshot } from '../useSnapshot';
3
+
4
+ // TODO: remove useless stateMapper, valtio already does this
5
+
6
+ const defaultMapper = state => state;
7
+ // @deprecated use useVendorState() instead
8
+ export function useVendorState(stateMapper = defaultMapper) {
9
+ const state = useStore().store.vendor;
10
+ return stateMapper(useSnapshot(state));
11
+ }
12
+ export const useVendorActions = () => {
13
+ return useStore().stateActions.vendor;
14
+ };
@@ -1,32 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createSliceHooks = createSliceHooks;
7
- var _index = require("./index");
8
- var _FronteggStoreContext = require("../FronteggStoreContext");
9
- // hooksFactory.ts ✅ type-safe, no TS2345
10
-
11
- /**
12
- * Build hooks for any slice in Frontegg’s store tree.
13
- */
14
- function createSliceHooks(cfg) {
15
- /* ---------- state ---------- */
16
- const useSliceState = (selector = x => x) => selector((0, _index.useSnapshot)(cfg.getState((0, _FronteggStoreContext.useStore)().store)));
17
-
18
- /* ---------- actions ---------- */
19
- const useSliceActions = () => cfg.getActions((0, _FronteggStoreContext.useStore)().stateActions);
20
-
21
- /* ---------- dialogs (optional) ---------- */
22
- const useSliceDialogsState = () => (0, _index.useSnapshot)(cfg.getDialogsState((0, _FronteggStoreContext.useStore)().store));
23
- const useSliceDialogsActions = () => cfg.getDialogsActions((0, _FronteggStoreContext.useStore)().stateActions);
24
-
25
- /* IntelliSense hides the dialogs hooks when you didn’t supply them */
26
- return {
27
- useSliceState,
28
- useSliceActions,
29
- useSliceDialogsState,
30
- useSliceDialogsActions
31
- };
32
- }
@@ -1,18 +0,0 @@
1
- import { useStore } from '../FronteggStoreContext';
2
- type Store = ReturnType<typeof useStore>['store'];
3
- type Actions = ReturnType<typeof useStore>['stateActions'];
4
- /**
5
- * Build hooks for any slice in Frontegg’s store tree.
6
- */
7
- export declare function createSliceHooks<SliceState extends object, SliceActions, SliceDialogsState extends object = never, SliceDialogsActions = never>(cfg: {
8
- getState: (s: Store) => SliceState;
9
- getActions: (a: Actions) => SliceActions;
10
- getDialogsState?: (s: Store) => SliceDialogsState;
11
- getDialogsActions?: (a: Actions) => SliceDialogsActions;
12
- }): {
13
- readonly useSliceState: <S = SliceState>(selector?: (s: SliceState) => S) => S;
14
- readonly useSliceActions: () => SliceActions;
15
- readonly useSliceDialogsState: () => SliceDialogsState;
16
- readonly useSliceDialogsActions: () => SliceDialogsActions;
17
- };
18
- export {};