@frontegg/react-hooks 7.77.0 → 7.78.0-alpha.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.
Files changed (120) hide show
  1. package/audits/auditLogs.d.ts +2 -3
  2. package/audits/auditLogs.js +8 -9
  3. package/audits/auditsMetadata.d.ts +2 -3
  4. package/audits/auditsMetadata.js +8 -9
  5. package/audits/hooks.d.ts +2 -9
  6. package/audits/hooks.js +10 -14
  7. package/auth/acceptInvitation.d.ts +7 -5
  8. package/auth/acceptInvitation.js +8 -13
  9. package/auth/activateAccount.d.ts +11 -5
  10. package/auth/activateAccount.js +8 -13
  11. package/auth/allAccounts.d.ts +47 -7
  12. package/auth/allAccounts.js +12 -20
  13. package/auth/apiTokens.d.ts +14 -3
  14. package/auth/apiTokens.js +8 -9
  15. package/auth/applications.d.ts +22 -3
  16. package/auth/applications.js +8 -9
  17. package/auth/customLogin.d.ts +9 -3
  18. package/auth/customLogin.js +9 -12
  19. package/auth/entitlements.d.ts +6 -25
  20. package/auth/entitlements.js +41 -73
  21. package/auth/forgotPassword.d.ts +12 -3
  22. package/auth/forgotPassword.js +10 -9
  23. package/auth/groups.d.ts +32 -5
  24. package/auth/groups.js +14 -14
  25. package/auth/impersonate.d.ts +6 -3
  26. package/auth/impersonate.js +8 -8
  27. package/auth/login.d.ts +74 -3
  28. package/auth/login.js +8 -8
  29. package/auth/passkeys.d.ts +10 -3
  30. package/auth/passkeys.js +8 -8
  31. package/auth/passwordRotation.d.ts +4 -3
  32. package/auth/passwordRotation.js +8 -9
  33. package/auth/profile.d.ts +19 -3
  34. package/auth/profile.js +17 -12
  35. package/auth/provisioning.d.ts +20 -3
  36. package/auth/provisioning.js +8 -8
  37. package/auth/resetPhoneNumber.d.ts +8 -3
  38. package/auth/resetPhoneNumber.js +8 -8
  39. package/auth/roles.d.ts +14 -3
  40. package/auth/roles.js +8 -8
  41. package/auth/security/restrictions.d.ts +21 -3
  42. package/auth/security/restrictions.js +20 -19
  43. package/auth/security/securityCenter.d.ts +15 -3
  44. package/auth/security/securityCenter.js +8 -9
  45. package/auth/security/securityPolicy.d.ts +35 -5
  46. package/auth/security/securityPolicy.js +16 -18
  47. package/auth/security/sessionsPolicy.d.ts +7 -3
  48. package/auth/security/sessionsPolicy.js +8 -9
  49. package/auth/sessions.d.ts +12 -3
  50. package/auth/sessions.js +8 -8
  51. package/auth/signup.d.ts +10 -5
  52. package/auth/signup.js +8 -16
  53. package/auth/sms.d.ts +13 -3
  54. package/auth/sms.js +8 -8
  55. package/auth/socialLogin.d.ts +9 -5
  56. package/auth/socialLogin.js +8 -13
  57. package/auth/sso.d.ts +31 -6
  58. package/auth/sso.js +8 -13
  59. package/auth/stepUp.d.ts +15 -14
  60. package/auth/stepUp.js +9 -22
  61. package/auth/team.d.ts +84 -13
  62. package/auth/team.js +12 -23
  63. package/auth/tenants.d.ts +9 -3
  64. package/auth/tenants.js +8 -9
  65. package/auth/unlockAccount.d.ts +6 -5
  66. package/auth/unlockAccount.js +8 -10
  67. package/auth/usernames.d.ts +7 -3
  68. package/auth/usernames.js +8 -8
  69. package/auth/usersEmailsPolicyState.d.ts +5 -5
  70. package/auth/usersEmailsPolicyState.js +8 -10
  71. package/connectivity/hooks.d.ts +41 -3
  72. package/connectivity/hooks.js +8 -9
  73. package/index.js +1 -1
  74. package/node/audits/auditLogs.js +11 -12
  75. package/node/audits/auditsMetadata.js +11 -12
  76. package/node/audits/hooks.js +13 -17
  77. package/node/auth/acceptInvitation.js +11 -13
  78. package/node/auth/activateAccount.js +11 -13
  79. package/node/auth/allAccounts.js +15 -20
  80. package/node/auth/apiTokens.js +11 -12
  81. package/node/auth/applications.js +11 -12
  82. package/node/auth/customLogin.js +11 -15
  83. package/node/auth/entitlements.js +41 -73
  84. package/node/auth/forgotPassword.js +13 -12
  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 +11 -12
  90. package/node/auth/profile.js +19 -13
  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 +22 -21
  95. package/node/auth/security/securityCenter.js +11 -12
  96. package/node/auth/security/securityPolicy.js +18 -17
  97. package/node/auth/security/sessionsPolicy.js +11 -12
  98. package/node/auth/sessions.js +11 -11
  99. package/node/auth/signup.js +11 -16
  100. package/node/auth/sms.js +11 -11
  101. package/node/auth/socialLogin.js +11 -13
  102. package/node/auth/sso.js +11 -13
  103. package/node/auth/stepUp.js +11 -24
  104. package/node/auth/team.js +16 -28
  105. package/node/auth/tenants.js +11 -12
  106. package/node/auth/unlockAccount.js +11 -13
  107. package/node/auth/usernames.js +11 -11
  108. package/node/auth/usersEmailsPolicyState.js +11 -13
  109. package/node/connectivity/hooks.js +11 -12
  110. package/node/index.js +1 -1
  111. package/node/subscriptions/hooks.js +86 -115
  112. package/node/useSnapshot/hookFactory.js +32 -0
  113. package/node/vendor/hooks.js +11 -14
  114. package/package.json +3 -3
  115. package/subscriptions/hooks.d.ts +48 -22
  116. package/subscriptions/hooks.js +77 -103
  117. package/useSnapshot/hookFactory.d.ts +18 -0
  118. package/useSnapshot/hookFactory.js +26 -0
  119. package/vendor/hooks.d.ts +2 -5
  120. package/vendor/hooks.js +8 -14
@@ -6,131 +6,102 @@ 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 _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
- };
21
- exports.usePaymentProvider = usePaymentProvider;
22
- const usePaymentProviderActions = () => {
23
- return (0, _FronteggStoreContext.useStore)().stateActions.subscriptions.config;
24
- };
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
+ });
25
19
  exports.usePaymentProviderActions = usePaymentProviderActions;
26
- const usePlans = () => {
27
- const {
28
- plans
29
- } = getSubscriptionsState();
30
- return (0, _useSnapshot.useSnapshot)(plans);
31
- };
32
- exports.usePlans = usePlans;
33
- const usePlansActions = () => {
34
- return (0, _FronteggStoreContext.useStore)().stateActions.subscriptions.plans;
35
- };
20
+ 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
+ });
36
28
  exports.usePlansActions = usePlansActions;
37
- const useCheckout = () => {
38
- const {
39
- checkout
40
- } = getSubscriptionsState();
41
- return (0, _useSnapshot.useSnapshot)(checkout);
42
- };
43
- exports.useCheckout = useCheckout;
44
- const useCheckoutActions = () => {
45
- return (0, _FronteggStoreContext.useStore)().stateActions.subscriptions.checkout;
46
- };
29
+ 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
+ });
47
37
  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
- };
57
- exports.useBillingInformation = useBillingInformation;
58
- const useBillingInformationActions = () => {
59
- return useBillingActions('information');
60
- };
38
+ 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
+ });
61
66
  exports.useBillingInformationActions = useBillingInformationActions;
62
- const usePaymentMethod = () => {
63
- const {
64
- billing
65
- } = getSubscriptionsState();
66
- return (0, _useSnapshot.useSnapshot)(billing.paymentMethod);
67
- };
68
- exports.usePaymentMethod = usePaymentMethod;
69
- const usePaymentMethodActions = () => {
70
- return useBillingActions('paymentMethod');
71
- };
67
+ 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
+ });
72
75
  exports.usePaymentMethodActions = usePaymentMethodActions;
73
- const useInvoices = () => {
74
- const {
75
- billing
76
- } = getSubscriptionsState();
77
- return (0, _useSnapshot.useSnapshot)(billing.invoices);
78
- };
79
- exports.useInvoices = useInvoices;
80
- const useInvoicesActions = () => {
81
- return useBillingActions('invoices');
82
- };
76
+ 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 ───────────────────────── */
83
86
  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
- };
87
+ 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;
93
98
  exports.useSubscriptionCancellation = useSubscriptionCancellation;
94
- const useSubscriptionRenewal = () => {
95
- const {
96
- billing
97
- } = getSubscriptionsState();
98
- const {
99
- renewal
100
- } = (0, _useSnapshot.useSnapshot)(billing.subscription);
101
- return renewal;
102
- };
99
+ const useSubscriptionRenewal = () => useSubscription().renewal;
103
100
  exports.useSubscriptionRenewal = useSubscriptionRenewal;
104
- const useSubscription = () => {
105
- const {
106
- billing
107
- } = getSubscriptionsState();
108
- return (0, _useSnapshot.useSnapshot)(billing.subscription);
109
- };
110
- exports.useSubscription = useSubscription;
111
101
  const useSubscriptionActions = () => {
112
- const actions = (0, _FronteggStoreContext.useStore)().stateActions.subscriptions.billing.subscription;
102
+ const actions = _useSubscriptionActions();
113
103
  return (0, _extends2.default)({}, actions, {
114
104
  load: actions.loadSubscription
115
105
  });
116
106
  };
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;
107
+ exports.useSubscriptionActions = useSubscriptionActions;
@@ -0,0 +1,32 @@
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
+ }
@@ -3,17 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
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;
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;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@frontegg/react-hooks",
3
- "version": "7.77.0",
3
+ "version": "7.78.0-alpha.1",
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.77.0",
10
- "@frontegg/types": "7.77.0",
9
+ "@frontegg/redux-store": "7.78.0-alpha.1",
10
+ "@frontegg/types": "7.78.0-alpha.1",
11
11
  "@types/react": "*",
12
12
  "@types/react-is": "^17.0.7",
13
13
  "get-value": "^3.0.1",
@@ -1,19 +1,34 @@
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: () => {
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: () => {
10
26
  setBillingInformationState: (state: Partial<BillingInformationState>) => void;
11
27
  resetBillingInformationState: () => void;
12
28
  loadSummaries: (tenantId: string, forceActive?: boolean) => Promise<void>;
13
29
  loadBillingInformation: (forceActive?: boolean) => Promise<void>;
14
30
  };
15
- export declare const usePaymentMethod: () => PaymentMethodState;
16
- export declare const usePaymentMethodActions: () => {
31
+ export declare const usePaymentMethod: <S = PaymentMethodState>(selector?: (s: PaymentMethodState) => S) => S, usePaymentMethodActions: () => {
17
32
  setBillingPaymentMethodState: (state: Partial<{}>) => void;
18
33
  resetBillingPaymentMethodState: () => void;
19
34
  loadPaymentMethod: () => Promise<void>;
@@ -22,8 +37,7 @@ export declare const usePaymentMethodActions: () => {
22
37
  submitPaymentMethodSuccess: () => Promise<void>;
23
38
  updatePaymentMethodBillingDetails: (payload: import("@frontegg/redux-store").WithCallback<import("@frontegg/redux-store").WithId<import("dist/@frontegg/rest-api").ISubscriptionUpdatePaymentMethodBillingDetails>>) => Promise<void>;
24
39
  };
25
- export declare const useInvoices: () => InvoicesState;
26
- export declare const useInvoicesActions: () => {
40
+ export declare const useInvoices: <S = InvoicesState>(selector?: (s: InvoicesState) => S) => S, useInvoicesActions: () => {
27
41
  setBillingInvoiceState: (state: Partial<InvoicesState>) => void;
28
42
  resetBillingInvoiceState: () => void;
29
43
  loadInvoices: () => Promise<void>;
@@ -31,13 +45,25 @@ export declare const useInvoicesActions: () => {
31
45
  downloadInvoice: (payload: import("@frontegg/redux-store").DownloadInvoiceActionPayload) => Promise<void>;
32
46
  downloadBillingInvoice: (payload: import("@frontegg/redux-store").DownloadInvoiceActionPayload) => Promise<void>;
33
47
  };
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;
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>;
39
69
  };
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,109 +1,83 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
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
- };
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;
89
78
  export const useSubscriptionActions = () => {
90
- const actions = useStore().stateActions.subscriptions.billing.subscription;
79
+ const actions = _useSubscriptionActions();
91
80
  return _extends({}, actions, {
92
81
  load: actions.loadSubscription
93
82
  });
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;
109
83
  };
@@ -0,0 +1,18 @@
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 {};
@@ -0,0 +1,26 @@
1
+ // hooksFactory.ts ✅ type-safe, no TS2345
2
+
3
+ import { useSnapshot } from './index';
4
+ import { useStore } from '../FronteggStoreContext';
5
+ /**
6
+ * Build hooks for any slice in Frontegg’s store tree.
7
+ */
8
+ export function createSliceHooks(cfg) {
9
+ /* ---------- state ---------- */
10
+ const useSliceState = (selector = x => x) => selector(useSnapshot(cfg.getState(useStore().store)));
11
+
12
+ /* ---------- actions ---------- */
13
+ const useSliceActions = () => cfg.getActions(useStore().stateActions);
14
+
15
+ /* ---------- dialogs (optional) ---------- */
16
+ const useSliceDialogsState = () => useSnapshot(cfg.getDialogsState(useStore().store));
17
+ const useSliceDialogsActions = () => cfg.getDialogsActions(useStore().stateActions);
18
+
19
+ /* IntelliSense hides the dialogs hooks when you didn’t supply them */
20
+ return {
21
+ useSliceState,
22
+ useSliceActions,
23
+ useSliceDialogsState,
24
+ useSliceDialogsActions
25
+ };
26
+ }
package/vendor/hooks.d.ts CHANGED
@@ -1,5 +1,2 @@
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;
1
+ import type { VendorState, VendorActions } from '@frontegg/redux-store';
2
+ export declare const useVendorState: <S = VendorState>(selector?: (s: VendorState) => S) => S, useVendorActions: () => VendorActions;