@frontegg/react-hooks 5.30.1 → 5.33.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.
@@ -0,0 +1,64 @@
1
+ import { subscriptionsStoreName, bindActionCreators, subscriptionActions, PaymentProvider } from '@frontegg/redux-store';
2
+ import { u as useSelector, a as useDispatch } from './FronteggStoreContext-d6c3b684.js';
3
+ import { shallowEqual } from 'react-redux';
4
+ import { useMemo } from 'react';
5
+
6
+ function getSubscriptionState(state) {
7
+ return state[subscriptionsStoreName];
8
+ }
9
+ const usePaymentProvider = () => {
10
+ return useSelector((state) => getSubscriptionState(state).config, shallowEqual);
11
+ };
12
+ const usePaymentProviderActions = () => {
13
+ const dispatch = useDispatch();
14
+ return useMemo(() => bindActionCreators(subscriptionActions.config, dispatch), [dispatch]);
15
+ };
16
+ const usePlans = () => {
17
+ return useSelector((state) => getSubscriptionState(state).plans, shallowEqual);
18
+ };
19
+ const usePlansActions = () => {
20
+ const dispatch = useDispatch();
21
+ return useMemo(() => bindActionCreators(subscriptionActions.plans, dispatch), [dispatch]);
22
+ };
23
+ const useCheckout = () => {
24
+ return useSelector((state) => getSubscriptionState(state).checkout, shallowEqual);
25
+ };
26
+ const useCheckoutActions = () => {
27
+ const dispatch = useDispatch();
28
+ return useMemo(() => bindActionCreators(subscriptionActions.checkout, dispatch), [dispatch]);
29
+ };
30
+ const useBillingActions = (billingKey) => {
31
+ const dispatch = useDispatch();
32
+ return useMemo(() => bindActionCreators(subscriptionActions.billing[billingKey], dispatch), [billingKey, dispatch]);
33
+ };
34
+ const useBillingInformation = () => useSelector((state) => getSubscriptionState(state).billing.information, shallowEqual);
35
+ const useBillingInformationActions = () => useBillingActions('information');
36
+ const usePaymentMethod = () => useSelector((state) => getSubscriptionState(state).billing.paymentMethod, shallowEqual);
37
+ const usePaymentMethodActions = () => useBillingActions('paymentMethod');
38
+ const useInvoices = () => useSelector((state) => getSubscriptionState(state).billing.invoices, shallowEqual);
39
+ const useInvoicesActions = () => useBillingActions('invoices');
40
+ const useStripeState = () => {
41
+ return useSelector((state) => getSubscriptionState(state).stripe, shallowEqual);
42
+ };
43
+ const useStripeActions = () => {
44
+ const dispatch = useDispatch();
45
+ return useMemo(() => bindActionCreators(subscriptionActions.stripe, dispatch), [dispatch]);
46
+ };
47
+ const useSubscription = () => {
48
+ return useSelector((state) => {
49
+ const { billing: { information: { subscription, plan, summary }, }, } = getSubscriptionState(state);
50
+ if ((summary === null || summary === void 0 ? void 0 : summary.externallyManaged) || !subscription || !plan) {
51
+ return null;
52
+ }
53
+ return Object.assign(Object.assign({}, subscription), { paymentProvider: PaymentProvider.STRIPE, plan: {
54
+ slug: plan.id,
55
+ name: plan.name,
56
+ } });
57
+ }, shallowEqual);
58
+ };
59
+ const useSubscriptionActions = () => {
60
+ const dispatch = useDispatch();
61
+ return useMemo(() => bindActionCreators(subscriptionActions.billing.subscription, dispatch), [dispatch]);
62
+ };
63
+
64
+ export { usePaymentProviderActions as a, usePlans as b, usePlansActions as c, useCheckout as d, useCheckoutActions as e, useBillingInformation as f, useBillingInformationActions as g, usePaymentMethod as h, usePaymentMethodActions as i, useInvoices as j, useInvoicesActions as k, useStripeState as l, useStripeActions as m, useSubscription as n, useSubscriptionActions as o, usePaymentProvider as u };
package/index.js CHANGED
@@ -10,7 +10,7 @@ import { F as FronteggStoreContext } from './FronteggStoreContext-d6c3b684.js';
10
10
  export { F as FronteggStoreContext, a as useDispatch, u as useSelector, b as useStore } from './FronteggStoreContext-d6c3b684.js';
11
11
  export { c as useAuditLogsActions, b as useAuditLogsState, a as useAuditsActions, e as useAuditsMetadataActions, d as useAuditsMetadataState, u as useAuditsState } from './auditsMetadata-9ab88593.js';
12
12
  export { u as useConnectivityActions, a as useConnectivityState } from './hooks-6400e233.js';
13
- export { f as useBillingInformation, g as useBillingInformationActions, h as useBillingPaymentMethod, i as useBillingPaymentMethodActions, d as useCheckout, e as useCheckoutActions, j as useInvoices, k as useInvoicesActions, n as useManagedSubscriptions, o as useManagedSubscriptionsActions, u as usePaymentProvider, a as usePaymentProviderActions, b as usePlans, c as usePlansActions, m as useStripeActions, l as useStripeState } from './hooks-93d932b9.js';
13
+ export { f as useBillingInformation, g as useBillingInformationActions, d as useCheckout, e as useCheckoutActions, j as useInvoices, k as useInvoicesActions, h as usePaymentMethod, i as usePaymentMethodActions, u as usePaymentProvider, a as usePaymentProviderActions, b as usePlans, c as usePlansActions, m as useStripeActions, l as useStripeState, n as useSubscription, o as useSubscriptionActions } from './hooks-29df4f5c.js';
14
14
  export { u as useVendorActions, a as useVendorState } from './hooks-eaf879c9.js';
15
15
 
16
16
  const setLoading = (loading) => {
@@ -5,68 +5,77 @@ var FronteggStoreContext = require('./FronteggStoreContext-6cfac56c.js');
5
5
  var reactRedux = require('react-redux');
6
6
  var React = require('react');
7
7
 
8
+ function getSubscriptionState(state) {
9
+ return state[reduxStore.subscriptionsStoreName];
10
+ }
8
11
  const usePaymentProvider = () => {
9
- return FronteggStoreContext.useSelector((state) => state[reduxStore.subscriptionsStoreName]['config'], reactRedux.shallowEqual);
12
+ return FronteggStoreContext.useSelector((state) => getSubscriptionState(state).config, reactRedux.shallowEqual);
10
13
  };
11
14
  const usePaymentProviderActions = () => {
12
15
  const dispatch = FronteggStoreContext.useDispatch();
13
16
  return React.useMemo(() => reduxStore.bindActionCreators(reduxStore.subscriptionActions.config, dispatch), [dispatch]);
14
17
  };
15
18
  const usePlans = () => {
16
- return FronteggStoreContext.useSelector((state) => state[reduxStore.subscriptionsStoreName]['plans'], reactRedux.shallowEqual);
19
+ return FronteggStoreContext.useSelector((state) => getSubscriptionState(state).plans, reactRedux.shallowEqual);
17
20
  };
18
21
  const usePlansActions = () => {
19
22
  const dispatch = FronteggStoreContext.useDispatch();
20
23
  return React.useMemo(() => reduxStore.bindActionCreators(reduxStore.subscriptionActions.plans, dispatch), [dispatch]);
21
24
  };
22
25
  const useCheckout = () => {
23
- return FronteggStoreContext.useSelector((state) => state[reduxStore.subscriptionsStoreName]['checkout'], reactRedux.shallowEqual);
26
+ return FronteggStoreContext.useSelector((state) => getSubscriptionState(state).checkout, reactRedux.shallowEqual);
24
27
  };
25
28
  const useCheckoutActions = () => {
26
29
  const dispatch = FronteggStoreContext.useDispatch();
27
30
  return React.useMemo(() => reduxStore.bindActionCreators(reduxStore.subscriptionActions.checkout, dispatch), [dispatch]);
28
31
  };
29
- const useBilling = (billingKey) => {
30
- return FronteggStoreContext.useSelector((state) => state[reduxStore.subscriptionsStoreName]['billing'][billingKey], reactRedux.shallowEqual);
31
- };
32
32
  const useBillingActions = (billingKey) => {
33
33
  const dispatch = FronteggStoreContext.useDispatch();
34
- return React.useMemo(() => reduxStore.bindActionCreators(reduxStore.subscriptionActions['billing'][billingKey], dispatch), [billingKey, dispatch]);
34
+ return React.useMemo(() => reduxStore.bindActionCreators(reduxStore.subscriptionActions.billing[billingKey], dispatch), [billingKey, dispatch]);
35
35
  };
36
- const useBillingInformation = () => useBilling('information');
36
+ const useBillingInformation = () => FronteggStoreContext.useSelector((state) => getSubscriptionState(state).billing.information, reactRedux.shallowEqual);
37
37
  const useBillingInformationActions = () => useBillingActions('information');
38
- const useBillingPaymentMethod = () => useBilling('paymentMethod');
39
- const useBillingPaymentMethodActions = () => useBillingActions('paymentMethod');
40
- const useInvoices = () => useBilling('invoices');
38
+ const usePaymentMethod = () => FronteggStoreContext.useSelector((state) => getSubscriptionState(state).billing.paymentMethod, reactRedux.shallowEqual);
39
+ const usePaymentMethodActions = () => useBillingActions('paymentMethod');
40
+ const useInvoices = () => FronteggStoreContext.useSelector((state) => getSubscriptionState(state).billing.invoices, reactRedux.shallowEqual);
41
41
  const useInvoicesActions = () => useBillingActions('invoices');
42
42
  const useStripeState = () => {
43
- return FronteggStoreContext.useSelector((state) => state[reduxStore.subscriptionsStoreName]['stripe'], reactRedux.shallowEqual);
43
+ return FronteggStoreContext.useSelector((state) => getSubscriptionState(state).stripe, reactRedux.shallowEqual);
44
44
  };
45
45
  const useStripeActions = () => {
46
46
  const dispatch = FronteggStoreContext.useDispatch();
47
47
  return React.useMemo(() => reduxStore.bindActionCreators(reduxStore.subscriptionActions.stripe, dispatch), [dispatch]);
48
48
  };
49
- const useManagedSubscriptions = () => {
50
- return FronteggStoreContext.useSelector((state) => state[reduxStore.subscriptionsStoreName]['managedSubscriptions'], reactRedux.shallowEqual);
49
+ const useSubscription = () => {
50
+ return FronteggStoreContext.useSelector((state) => {
51
+ const { billing: { information: { subscription, plan, summary }, }, } = getSubscriptionState(state);
52
+ if ((summary === null || summary === void 0 ? void 0 : summary.externallyManaged) || !subscription || !plan) {
53
+ return null;
54
+ }
55
+ return Object.assign(Object.assign({}, subscription), { paymentProvider: reduxStore.PaymentProvider.STRIPE, plan: {
56
+ slug: plan.id,
57
+ name: plan.name,
58
+ } });
59
+ }, reactRedux.shallowEqual);
51
60
  };
52
- const useManagedSubscriptionsActions = () => {
61
+ const useSubscriptionActions = () => {
53
62
  const dispatch = FronteggStoreContext.useDispatch();
54
- return React.useMemo(() => reduxStore.bindActionCreators(reduxStore.subscriptionActions.managedSubscriptions, dispatch), [dispatch]);
63
+ return React.useMemo(() => reduxStore.bindActionCreators(reduxStore.subscriptionActions.billing.subscription, dispatch), [dispatch]);
55
64
  };
56
65
 
57
66
  exports.useBillingInformation = useBillingInformation;
58
67
  exports.useBillingInformationActions = useBillingInformationActions;
59
- exports.useBillingPaymentMethod = useBillingPaymentMethod;
60
- exports.useBillingPaymentMethodActions = useBillingPaymentMethodActions;
61
68
  exports.useCheckout = useCheckout;
62
69
  exports.useCheckoutActions = useCheckoutActions;
63
70
  exports.useInvoices = useInvoices;
64
71
  exports.useInvoicesActions = useInvoicesActions;
65
- exports.useManagedSubscriptions = useManagedSubscriptions;
66
- exports.useManagedSubscriptionsActions = useManagedSubscriptionsActions;
72
+ exports.usePaymentMethod = usePaymentMethod;
73
+ exports.usePaymentMethodActions = usePaymentMethodActions;
67
74
  exports.usePaymentProvider = usePaymentProvider;
68
75
  exports.usePaymentProviderActions = usePaymentProviderActions;
69
76
  exports.usePlans = usePlans;
70
77
  exports.usePlansActions = usePlansActions;
71
78
  exports.useStripeActions = useStripeActions;
72
79
  exports.useStripeState = useStripeState;
80
+ exports.useSubscription = useSubscription;
81
+ exports.useSubscriptionActions = useSubscriptionActions;
package/node/index.js CHANGED
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var roles = require('./roles-23d24a59.js');
6
6
  var auditsMetadata = require('./auditsMetadata-d15799a1.js');
7
7
  var hooks = require('./hooks-5d5a445e.js');
8
- var hooks$1 = require('./hooks-0bc9e30c.js');
8
+ var hooks$1 = require('./hooks-be556189.js');
9
9
  var hooks$2 = require('./hooks-cf739b27.js');
10
10
  var tslib = require('tslib');
11
11
  var React = require('react');
@@ -146,20 +146,20 @@ exports.useConnectivityActions = hooks.useConnectivityActions;
146
146
  exports.useConnectivityState = hooks.useConnectivityState;
147
147
  exports.useBillingInformation = hooks$1.useBillingInformation;
148
148
  exports.useBillingInformationActions = hooks$1.useBillingInformationActions;
149
- exports.useBillingPaymentMethod = hooks$1.useBillingPaymentMethod;
150
- exports.useBillingPaymentMethodActions = hooks$1.useBillingPaymentMethodActions;
151
149
  exports.useCheckout = hooks$1.useCheckout;
152
150
  exports.useCheckoutActions = hooks$1.useCheckoutActions;
153
151
  exports.useInvoices = hooks$1.useInvoices;
154
152
  exports.useInvoicesActions = hooks$1.useInvoicesActions;
155
- exports.useManagedSubscriptions = hooks$1.useManagedSubscriptions;
156
- exports.useManagedSubscriptionsActions = hooks$1.useManagedSubscriptionsActions;
153
+ exports.usePaymentMethod = hooks$1.usePaymentMethod;
154
+ exports.usePaymentMethodActions = hooks$1.usePaymentMethodActions;
157
155
  exports.usePaymentProvider = hooks$1.usePaymentProvider;
158
156
  exports.usePaymentProviderActions = hooks$1.usePaymentProviderActions;
159
157
  exports.usePlans = hooks$1.usePlans;
160
158
  exports.usePlansActions = hooks$1.usePlansActions;
161
159
  exports.useStripeActions = hooks$1.useStripeActions;
162
160
  exports.useStripeState = hooks$1.useStripeState;
161
+ exports.useSubscription = hooks$1.useSubscription;
162
+ exports.useSubscriptionActions = hooks$1.useSubscriptionActions;
163
163
  exports.useVendorActions = hooks$2.useVendorActions;
164
164
  exports.useVendorState = hooks$2.useVendorState;
165
165
  Object.defineProperty(exports, 'Provider', {
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var hooks = require('../hooks-0bc9e30c.js');
5
+ var hooks = require('../hooks-be556189.js');
6
6
  require('@frontegg/redux-store');
7
7
  require('../FronteggStoreContext-6cfac56c.js');
8
8
  require('react');
@@ -12,17 +12,17 @@ require('react-redux');
12
12
 
13
13
  exports.useBillingInformation = hooks.useBillingInformation;
14
14
  exports.useBillingInformationActions = hooks.useBillingInformationActions;
15
- exports.useBillingPaymentMethod = hooks.useBillingPaymentMethod;
16
- exports.useBillingPaymentMethodActions = hooks.useBillingPaymentMethodActions;
17
15
  exports.useCheckout = hooks.useCheckout;
18
16
  exports.useCheckoutActions = hooks.useCheckoutActions;
19
17
  exports.useInvoices = hooks.useInvoices;
20
18
  exports.useInvoicesActions = hooks.useInvoicesActions;
21
- exports.useManagedSubscriptions = hooks.useManagedSubscriptions;
22
- exports.useManagedSubscriptionsActions = hooks.useManagedSubscriptionsActions;
19
+ exports.usePaymentMethod = hooks.usePaymentMethod;
20
+ exports.usePaymentMethodActions = hooks.usePaymentMethodActions;
23
21
  exports.usePaymentProvider = hooks.usePaymentProvider;
24
22
  exports.usePaymentProviderActions = hooks.usePaymentProviderActions;
25
23
  exports.usePlans = hooks.usePlans;
26
24
  exports.usePlansActions = hooks.usePlansActions;
27
25
  exports.useStripeActions = hooks.useStripeActions;
28
26
  exports.useStripeState = hooks.useStripeState;
27
+ exports.useSubscription = hooks.useSubscription;
28
+ exports.useSubscriptionActions = hooks.useSubscriptionActions;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@frontegg/react-hooks",
3
3
  "libName": "FronteggReactHooks",
4
- "version": "5.30.1",
4
+ "version": "5.33.0",
5
5
  "author": "Frontegg LTD",
6
6
  "main": "./node/index.js",
7
7
  "module": "./index.js",
8
8
  "types": "./index.d.ts",
9
9
  "dependencies": {
10
- "@frontegg/redux-store": "5.30.1",
10
+ "@frontegg/redux-store": "5.33.0",
11
11
  "react-redux": "^7.x"
12
12
  }
13
13
  }
@@ -1,4 +1,4 @@
1
- import { CheckoutActions, CheckoutState, PaymentProviderConfigActions, PaymentProviderConfigState, PlansActions, PlansState, StripeActions, StripeState, ManagedSubscriptionsActions, ManagedSubscriptionsState } from '@frontegg/redux-store';
1
+ import { CheckoutActions, CheckoutState, PaymentProviderConfigActions, PaymentProviderConfigState, PlansActions, PlansState, StripeActions, StripeState, SubscriptionActions, SubscriptionState } from '@frontegg/redux-store';
2
2
  export declare const usePaymentProvider: () => PaymentProviderConfigState;
3
3
  export declare const usePaymentProviderActions: () => PaymentProviderConfigActions;
4
4
  export declare const usePlans: () => PlansState;
@@ -7,11 +7,11 @@ export declare const useCheckout: () => CheckoutState;
7
7
  export declare const useCheckoutActions: () => CheckoutActions;
8
8
  export declare const useBillingInformation: () => import("@frontegg/redux-store").BillingInformationState;
9
9
  export declare const useBillingInformationActions: () => import("@frontegg/redux-store").BillingInformationActions;
10
- export declare const useBillingPaymentMethod: () => import("@frontegg/redux-store").PaymentMethodState;
11
- export declare const useBillingPaymentMethodActions: () => import("@frontegg/redux-store").PaymentMethodActions;
10
+ export declare const usePaymentMethod: () => import("@frontegg/redux-store").PaymentMethodState;
11
+ export declare const usePaymentMethodActions: () => import("@frontegg/redux-store").PaymentMethodActions;
12
12
  export declare const useInvoices: () => import("@frontegg/redux-store").InvoicesState;
13
13
  export declare const useInvoicesActions: () => import("@frontegg/redux-store").InvoicesActions;
14
14
  export declare const useStripeState: () => StripeState;
15
15
  export declare const useStripeActions: () => StripeActions;
16
- export declare const useManagedSubscriptions: () => ManagedSubscriptionsState;
17
- export declare const useManagedSubscriptionsActions: () => ManagedSubscriptionsActions;
16
+ export declare const useSubscription: () => SubscriptionState['subscription'] | null;
17
+ export declare const useSubscriptionActions: () => SubscriptionActions;
@@ -1,4 +1,4 @@
1
- export { f as useBillingInformation, g as useBillingInformationActions, h as useBillingPaymentMethod, i as useBillingPaymentMethodActions, d as useCheckout, e as useCheckoutActions, j as useInvoices, k as useInvoicesActions, n as useManagedSubscriptions, o as useManagedSubscriptionsActions, u as usePaymentProvider, a as usePaymentProviderActions, b as usePlans, c as usePlansActions, m as useStripeActions, l as useStripeState } from '../hooks-93d932b9.js';
1
+ export { f as useBillingInformation, g as useBillingInformationActions, d as useCheckout, e as useCheckoutActions, j as useInvoices, k as useInvoicesActions, h as usePaymentMethod, i as usePaymentMethodActions, u as usePaymentProvider, a as usePaymentProviderActions, b as usePlans, c as usePlansActions, m as useStripeActions, l as useStripeState, n as useSubscription, o as useSubscriptionActions } from '../hooks-29df4f5c.js';
2
2
  import '@frontegg/redux-store';
3
3
  import '../FronteggStoreContext-d6c3b684.js';
4
4
  import 'react';
package/hooks-93d932b9.js DELETED
@@ -1,55 +0,0 @@
1
- import { subscriptionsStoreName, bindActionCreators, subscriptionActions } from '@frontegg/redux-store';
2
- import { u as useSelector, a as useDispatch } from './FronteggStoreContext-d6c3b684.js';
3
- import { shallowEqual } from 'react-redux';
4
- import { useMemo } from 'react';
5
-
6
- const usePaymentProvider = () => {
7
- return useSelector((state) => state[subscriptionsStoreName]['config'], shallowEqual);
8
- };
9
- const usePaymentProviderActions = () => {
10
- const dispatch = useDispatch();
11
- return useMemo(() => bindActionCreators(subscriptionActions.config, dispatch), [dispatch]);
12
- };
13
- const usePlans = () => {
14
- return useSelector((state) => state[subscriptionsStoreName]['plans'], shallowEqual);
15
- };
16
- const usePlansActions = () => {
17
- const dispatch = useDispatch();
18
- return useMemo(() => bindActionCreators(subscriptionActions.plans, dispatch), [dispatch]);
19
- };
20
- const useCheckout = () => {
21
- return useSelector((state) => state[subscriptionsStoreName]['checkout'], shallowEqual);
22
- };
23
- const useCheckoutActions = () => {
24
- const dispatch = useDispatch();
25
- return useMemo(() => bindActionCreators(subscriptionActions.checkout, dispatch), [dispatch]);
26
- };
27
- const useBilling = (billingKey) => {
28
- return useSelector((state) => state[subscriptionsStoreName]['billing'][billingKey], shallowEqual);
29
- };
30
- const useBillingActions = (billingKey) => {
31
- const dispatch = useDispatch();
32
- return useMemo(() => bindActionCreators(subscriptionActions['billing'][billingKey], dispatch), [billingKey, dispatch]);
33
- };
34
- const useBillingInformation = () => useBilling('information');
35
- const useBillingInformationActions = () => useBillingActions('information');
36
- const useBillingPaymentMethod = () => useBilling('paymentMethod');
37
- const useBillingPaymentMethodActions = () => useBillingActions('paymentMethod');
38
- const useInvoices = () => useBilling('invoices');
39
- const useInvoicesActions = () => useBillingActions('invoices');
40
- const useStripeState = () => {
41
- return useSelector((state) => state[subscriptionsStoreName]['stripe'], shallowEqual);
42
- };
43
- const useStripeActions = () => {
44
- const dispatch = useDispatch();
45
- return useMemo(() => bindActionCreators(subscriptionActions.stripe, dispatch), [dispatch]);
46
- };
47
- const useManagedSubscriptions = () => {
48
- return useSelector((state) => state[subscriptionsStoreName]['managedSubscriptions'], shallowEqual);
49
- };
50
- const useManagedSubscriptionsActions = () => {
51
- const dispatch = useDispatch();
52
- return useMemo(() => bindActionCreators(subscriptionActions.managedSubscriptions, dispatch), [dispatch]);
53
- };
54
-
55
- export { usePaymentProviderActions as a, usePlans as b, usePlansActions as c, useCheckout as d, useCheckoutActions as e, useBillingInformation as f, useBillingInformationActions as g, useBillingPaymentMethod as h, useBillingPaymentMethodActions as i, useInvoices as j, useInvoicesActions as k, useStripeState as l, useStripeActions as m, useManagedSubscriptions as n, useManagedSubscriptionsActions as o, usePaymentProvider as u };