@frontegg/redux-store 5.29.0 → 5.31.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.
@@ -47,7 +47,7 @@ const { actions: sliceActions$2, reducer: reducer$8, name: name$7 } = toolkit.cr
47
47
  initialState: plansInitialState,
48
48
  reducers: Object.assign({}, createModuleCaseReducers()),
49
49
  });
50
- const actions$8 = Object.assign({ loadPlans: toolkit.createAction(`${name$7}/loadPlans`) }, sliceActions$2);
50
+ const actions$9 = Object.assign({ loadPlans: toolkit.createAction(`${name$7}/loadPlans`) }, sliceActions$2);
51
51
 
52
52
  const configInitialState = {
53
53
  loading: false,
@@ -61,7 +61,7 @@ const { actions: configActions, reducer: reducer$7, name: name$6, } = toolkit.cr
61
61
  initialState: configInitialState,
62
62
  reducers: reducers$6,
63
63
  });
64
- const actions$7 = Object.assign({ loadPaymentConfiguration: toolkit.createAction(`${name$6}/loadPaymentConfiguration`) }, configActions);
64
+ const actions$8 = Object.assign({ loadPaymentConfiguration: toolkit.createAction(`${name$6}/loadPaymentConfiguration`) }, configActions);
65
65
 
66
66
  const initialBillingInformationState = {
67
67
  loading: false,
@@ -82,7 +82,7 @@ const { reducer: reducer$6, actions: overviewActions, name: name$5, } = toolkit.
82
82
  initialState: initialBillingInformationState,
83
83
  reducers: reducers$5,
84
84
  });
85
- const actions$6 = Object.assign({ loadBillingInformation: toolkit.createAction(`${name$5}/loadBillingInformation`), cancelSubscription: toolkit.createAction(`${name$5}/cancelSubscription`), renewSubscription: toolkit.createAction(`${name$5}/renewSubscription`) }, overviewActions);
85
+ const actions$7 = Object.assign({ loadBillingInformation: toolkit.createAction(`${name$5}/loadBillingInformation`), cancelSubscription: toolkit.createAction(`${name$5}/cancelSubscription`), renewSubscription: toolkit.createAction(`${name$5}/renewSubscription`) }, overviewActions);
86
86
 
87
87
  const initialPaymentMethodState = {
88
88
  loading: false,
@@ -98,7 +98,7 @@ const { reducer: reducer$5, actions: paymentActions, name: name$4, } = toolkit.c
98
98
  initialState: initialPaymentMethodState,
99
99
  reducers: reducers$4,
100
100
  });
101
- const actions$5 = Object.assign({ loadPaymentMethod: toolkit.createAction(`${name$4}/loadPaymentMethod`), submitPaymentMethod: toolkit.createAction(`${name$4}/submitPaymentMethod`), submitPaymentMethodError: toolkit.createAction(`${name$4}/submitPaymentMethodError`), submitPaymentMethodSuccess: toolkit.createAction(`${name$4}/submitPaymentMethodSuccess`), updatePaymentMethodBillingDetails: toolkit.createAction(`${name$4}/updateBillingDetails`, (payload) => ({ payload })) }, paymentActions);
101
+ const actions$6 = Object.assign({ loadPaymentMethod: toolkit.createAction(`${name$4}/loadPaymentMethod`), submitPaymentMethod: toolkit.createAction(`${name$4}/submitPaymentMethod`), submitPaymentMethodError: toolkit.createAction(`${name$4}/submitPaymentMethodError`), submitPaymentMethodSuccess: toolkit.createAction(`${name$4}/submitPaymentMethodSuccess`), updatePaymentMethodBillingDetails: toolkit.createAction(`${name$4}/updateBillingDetails`, (payload) => ({ payload })) }, paymentActions);
102
102
 
103
103
  const initialInvoicesState = {
104
104
  loading: false,
@@ -119,7 +119,11 @@ const { reducer: reducer$4, actions: sliceActions$1, name: name$3, } = toolkit.c
119
119
  initialState: initialInvoicesState,
120
120
  reducers: reducers$3,
121
121
  });
122
- const actions$4 = Object.assign({ loadInvoices: toolkit.createAction(`${name$3}/loadInvoices`), downloadInvoice: toolkit.createAction(`${name$3}/downloadInvoice`, (payload) => ({ payload })) }, sliceActions$1);
122
+ const actions$5 = Object.assign({ loadInvoices: toolkit.createAction(`${name$3}/loadInvoices`), downloadInvoice: toolkit.createAction(`${name$3}/downloadInvoice`, (payload) => ({ payload })) }, sliceActions$1);
123
+
124
+ const actions$4 = {
125
+ load: toolkit.createAction(`${constants.subscriptionsStoreName}/subscription/load`),
126
+ };
123
127
 
124
128
  const billingInitialState = {
125
129
  information: initialBillingInformationState,
@@ -127,9 +131,10 @@ const billingInitialState = {
127
131
  paymentMethod: initialPaymentMethodState,
128
132
  };
129
133
  const billingActions = {
130
- invoices: actions$4,
131
- information: actions$6,
132
- paymentMethod: actions$5,
134
+ invoices: actions$5,
135
+ information: actions$7,
136
+ paymentMethod: actions$6,
137
+ subscription: actions$4,
133
138
  };
134
139
  const billingReducer = toolkit.combineReducers({
135
140
  invoices: reducer$4,
@@ -179,10 +184,7 @@ const initialSubscriptionStripeState = {
179
184
  error: null,
180
185
  cardSetupIntentSecret: null,
181
186
  };
182
- const reducers$1 = Object.assign(Object.assign({}, createModuleCaseReducers()), { setStripeState: {
183
- prepare: (payload) => ({ payload }),
184
- reducer: (state, action) => (Object.assign(Object.assign({}, state), action.payload)),
185
- } });
187
+ const reducers$1 = Object.assign({}, createModuleCaseReducers());
186
188
  const { reducer: reducer$2, actions: reducerActions, name: name$1, } = toolkit.createSlice({
187
189
  name: `${constants.subscriptionsStoreName}/stripe`,
188
190
  initialState: initialSubscriptionStripeState,
@@ -213,9 +215,9 @@ const initialState = {
213
215
  managedSubscriptions: managedSubscriptionsInitialState,
214
216
  };
215
217
  const actions = {
216
- config: actions$7,
218
+ config: actions$8,
217
219
  billing: billingActions,
218
- plans: actions$8,
220
+ plans: actions$9,
219
221
  checkout: actions$3,
220
222
  stripe: actions$2,
221
223
  managedSubscriptions: actions$1,
@@ -360,49 +362,48 @@ const paymentMethodsMock = [
360
362
  ];
361
363
 
362
364
  function* subscriptionBillingInformationSagas() {
363
- yield effects.takeEvery(actions$6.loadBillingInformation, loadBillingInformation);
364
- yield effects.takeEvery(actions$6.cancelSubscription, cancelSubscription);
365
- yield effects.takeEvery(actions$6.renewSubscription, renewSubscription);
365
+ yield effects.takeEvery(actions$7.loadBillingInformation, loadBillingInformation);
366
+ yield effects.takeEvery(actions$7.cancelSubscription, cancelSubscription);
367
+ yield effects.takeEvery(actions$7.renewSubscription, renewSubscription);
366
368
  yield effects.takeEvery(actions$3.checkoutEvent, checkoutEvent$2);
367
369
  }
368
370
  function* loadBillingInformation() {
369
371
  const paymentProvider = yield effects.select((state) => { var _a; return (_a = state.subscriptions.config.config) === null || _a === void 0 ? void 0 : _a.paymentProvider; });
370
372
  const tenantId = yield effects.select((state) => { var _a, _b, _c; return (_c = (_b = (_a = state.auth) === null || _a === void 0 ? void 0 : _a.profileState) === null || _b === void 0 ? void 0 : _b.profile) === null || _c === void 0 ? void 0 : _c.tenantId; });
371
- yield effects.put(actions$6.setLoading(true));
372
373
  if (!paymentProvider || !tenantId) {
373
- yield effects.put(actions$6.setError(!paymentProvider ? 'Internal feature failure' : 'Not authorized'));
374
+ yield effects.put(actions$7.setError(!paymentProvider ? 'Internal feature failure' : 'Not authorized'));
374
375
  return;
375
376
  }
376
- try {
377
- yield loadSummaries(tenantId);
378
- }
379
- catch (e) {
380
- yield effects.put(actions$6.setError(e.message));
381
- }
377
+ yield loadSummaries(tenantId);
382
378
  }
383
379
  function* loadSummaries(tenantId) {
384
380
  var _a, _b;
385
- yield effects.put(actions$6.setLoading(true));
381
+ yield effects.put(actions$7.setLoading(true));
386
382
  try {
387
383
  const summary = yield effects.call(restApi.api.subscriptions.getSubscriptionSummaries, tenantId);
388
- const { currentPlanId, subscriptionId, } = summary;
389
- const subscriptionResponse = yield effects.call(restApi.api.subscriptions.getManagedSubscription, subscriptionId);
390
- const planResponse = yield effects.call(restApi.api.subscriptions.getSubscriptionPlan, currentPlanId);
391
- yield effects.put(actions$6.setState(Object.assign(Object.assign({ loading: false, fetching: false, summary }, (subscriptionResponse
384
+ const { currentPlanId, externallyManaged, subscriptionId } = summary;
385
+ let subscriptionResponse = null;
386
+ let planResponse;
387
+ if (!externallyManaged) {
388
+ [subscriptionResponse, planResponse] = yield effects.all([
389
+ effects.call(restApi.api.subscriptions.getManagedSubscription, subscriptionId),
390
+ effects.call(restApi.api.subscriptions.getSubscriptionPlan, currentPlanId),
391
+ ]);
392
+ }
393
+ else {
394
+ planResponse = yield effects.call(restApi.api.subscriptions.getSubscriptionPlan, currentPlanId);
395
+ }
396
+ yield effects.put(actions$7.setState(Object.assign(Object.assign({ loading: false, fetching: false, summary }, (subscriptionResponse
392
397
  ? {
393
398
  subscription: {
394
399
  id: subscriptionResponse.id,
395
400
  externalId: subscriptionResponse.externalId,
396
- startDate: new Date(subscriptionResponse.startDate),
397
- currentPeriodStart: new Date(subscriptionResponse.currentPeriodStart),
398
- currentPeriodEnd: new Date(subscriptionResponse.currentPeriodEnd),
401
+ startDate: subscriptionResponse.startDate,
402
+ currentPeriodStart: subscriptionResponse.currentPeriodStart,
403
+ currentPeriodEnd: subscriptionResponse.currentPeriodEnd,
399
404
  status: toSubscriptionStatus(subscriptionResponse.status),
400
405
  cancellation: subscriptionResponse.cancellation && toSubscriptionCancellation(subscriptionResponse.cancellation),
401
- items: subscriptionResponse.items.map((subscriptionItem) => ({
402
- id: subscriptionItem.id,
403
- planId: subscriptionItem.planId,
404
- })),
405
- trialEnd: subscriptionResponse.trialEnd ? new Date(subscriptionResponse.trialEnd) : null,
406
+ trialEnd: subscriptionResponse.trialEnd ? subscriptionResponse.trialEnd : null,
406
407
  },
407
408
  }
408
409
  : {})), (planResponse
@@ -419,34 +420,33 @@ function* loadSummaries(tenantId) {
419
420
  : {}))));
420
421
  }
421
422
  catch (e) {
422
- yield effects.put(actions$6.setError(e.message));
423
+ yield effects.put(actions$7.setError(e.message));
423
424
  }
424
425
  }
425
426
  function* cancelSubscription() {
426
- var _a;
427
- const overview = yield effects.select((state) => state.subscriptions.billing.information);
428
- if (!overview.subscription) {
427
+ const { summary, subscription } = yield effects.select((state) => state.subscriptions.billing.information);
428
+ if (!subscription) {
429
429
  return;
430
430
  }
431
- if ((_a = overview.summary) === null || _a === void 0 ? void 0 : _a.externallyManaged) {
432
- yield effects.put(actions$6.setCancellationError('Billing is externally managed'));
431
+ if (summary === null || summary === void 0 ? void 0 : summary.externallyManaged) {
432
+ yield effects.put(actions$7.setCancellationError('Billing is externally managed'));
433
433
  return;
434
434
  }
435
- const { id: subscriptionId, cancellation, status } = overview.subscription || {};
435
+ const { id: subscriptionId, cancellation, status } = subscription || {};
436
436
  const isCancellable = !cancellation && status === exports.SubscriptionStatus.ACTIVE;
437
437
  if (isCancellable) {
438
438
  try {
439
- yield effects.put(actions$6.setCancellationLoading(true));
439
+ yield effects.put(actions$7.setCancellationLoading(true));
440
440
  yield effects.call(restApi.api.subscriptions.cancelManagedSubscription, subscriptionId);
441
- yield effects.put(actions$6.setState({
442
- subscription: Object.assign(Object.assign({}, overview.subscription), { cancellation: {
441
+ yield effects.put(actions$7.setState({
442
+ subscription: Object.assign(Object.assign({}, subscription), { cancellation: {
443
443
  policy: exports.SubscriptionCancellationPolicy.AT_PERIOD_END,
444
444
  } }),
445
445
  }));
446
- yield effects.put(actions$6.setCancellationLoading(false));
446
+ yield effects.put(actions$7.setCancellationLoading(false));
447
447
  }
448
448
  catch (e) {
449
- yield effects.put(actions$6.setCancellationError(e.message));
449
+ yield effects.put(actions$7.setCancellationError(e.message));
450
450
  }
451
451
  }
452
452
  }
@@ -457,22 +457,22 @@ function* renewSubscription() {
457
457
  return;
458
458
  }
459
459
  if ((_a = overview.summary) === null || _a === void 0 ? void 0 : _a.externallyManaged) {
460
- yield effects.put(actions$6.setCancellationError('Billing is externally managed'));
460
+ yield effects.put(actions$7.setCancellationError('Billing is externally managed'));
461
461
  return;
462
462
  }
463
463
  const { id: subscriptionId, cancellation } = overview.subscription || {};
464
464
  const renewable = (cancellation === null || cancellation === void 0 ? void 0 : cancellation.policy) === exports.SubscriptionCancellationPolicy.AT_PERIOD_END;
465
465
  if (renewable) {
466
466
  try {
467
- yield effects.put(actions$6.setRenewalLoading(true));
467
+ yield effects.put(actions$7.setRenewalLoading(true));
468
468
  yield effects.call(restApi.api.subscriptions.renewManagedSubscription, subscriptionId);
469
- yield effects.put(actions$6.setState({
469
+ yield effects.put(actions$7.setState({
470
470
  subscription: Object.assign(Object.assign({}, overview.subscription), { cancellation: null }),
471
471
  }));
472
- yield effects.put(actions$6.setRenewalLoading(false));
472
+ yield effects.put(actions$7.setRenewalLoading(false));
473
473
  }
474
474
  catch (e) {
475
- yield effects.put(actions$6.setCancellationError(e.message));
475
+ yield effects.put(actions$7.setCancellationError(e.message));
476
476
  }
477
477
  }
478
478
  }
@@ -485,14 +485,13 @@ function* checkoutEvent$2({ payload }) {
485
485
  * Preview Sagas
486
486
  *********************************/
487
487
  function* loadBillingInformationMock() {
488
- yield effects.put(actions$6.setLoading(true));
489
488
  yield loadSummariesMock();
490
489
  }
491
490
  function* loadSummariesMock() {
492
491
  var _a, _b;
493
- yield effects.put(actions$6.setLoading(true));
492
+ yield effects.put(actions$7.setLoading(true));
494
493
  yield effects.delay(500);
495
- yield effects.put(actions$6.setState({
494
+ yield effects.put(actions$7.setState({
496
495
  loading: false,
497
496
  fetching: false,
498
497
  summary: {
@@ -504,35 +503,35 @@ function* loadSummariesMock() {
504
503
  currentPlanId: planResponseMock[0].id,
505
504
  defaultPlanId: planResponseMock[0].id,
506
505
  },
507
- subscription: Object.assign(Object.assign({}, subscriptionResponseMock), { startDate: new Date(subscriptionResponseMock.startDate), currentPeriodStart: new Date(subscriptionResponseMock.currentPeriodStart), currentPeriodEnd: new Date(subscriptionResponseMock.currentPeriodEnd), status: toSubscriptionStatus(subscriptionResponseMock.status), cancellation: subscriptionResponseMock.cancellation && toSubscriptionCancellation(subscriptionResponseMock.cancellation), items: subscriptionResponseMock.items, trialEnd: null }),
506
+ subscription: Object.assign(Object.assign({}, subscriptionResponseMock), { startDate: subscriptionResponseMock.startDate, currentPeriodStart: subscriptionResponseMock.currentPeriodStart, currentPeriodEnd: subscriptionResponseMock.currentPeriodEnd, status: toSubscriptionStatus(subscriptionResponseMock.status), cancellation: subscriptionResponseMock.cancellation && toSubscriptionCancellation(subscriptionResponseMock.cancellation), trialEnd: null }),
508
507
  plan: Object.assign(Object.assign({}, planResponseMock[0]), { price: (_a = planResponseMock[0].price) === null || _a === void 0 ? void 0 : _a.amount, currency: (_b = planResponseMock[0].price) === null || _b === void 0 ? void 0 : _b.currency, recurringInterval: 'month' }),
509
508
  }));
510
509
  }
511
510
  function* subscriptionBillingInformationSagasMock() {
512
- yield effects.takeEvery(actions$6.loadBillingInformation, loadBillingInformationMock);
511
+ yield effects.takeEvery(actions$7.loadBillingInformation, loadBillingInformationMock);
513
512
  }
514
513
 
515
514
  function* subscriptionsPaymentMethodSagas() {
516
- yield effects.takeEvery(actions$5.loadPaymentMethod, loadPaymentMethod);
517
- yield effects.takeEvery(actions$5.submitPaymentMethod, submitPaymentMethod);
518
- yield effects.takeEvery(actions$5.submitPaymentMethodError, submitPaymentMethodError);
519
- yield effects.takeEvery(actions$5.submitPaymentMethodSuccess, submitPaymentMethodSuccess);
520
- yield effects.takeEvery(actions$5.updatePaymentMethodBillingDetails, updateBillingDetails);
515
+ yield effects.takeEvery(actions$6.loadPaymentMethod, loadPaymentMethod);
516
+ yield effects.takeEvery(actions$6.submitPaymentMethod, submitPaymentMethod);
517
+ yield effects.takeEvery(actions$6.submitPaymentMethodError, submitPaymentMethodError);
518
+ yield effects.takeEvery(actions$6.submitPaymentMethodSuccess, submitPaymentMethodSuccess);
519
+ yield effects.takeEvery(actions$6.updatePaymentMethodBillingDetails, updateBillingDetails);
521
520
  yield effects.takeEvery(actions$3.checkoutEvent, checkoutEvent$1);
522
521
  }
523
522
  function* loadPaymentMethod() {
524
- yield effects.put(actions$5.setLoading(true));
523
+ yield effects.put(actions$6.setLoading(true));
525
524
  try {
526
525
  const paymentMethods = yield effects.call(restApi.api.subscriptions.getPaymentMethods);
527
526
  const paymentMethod = paymentMethods[0];
528
- yield effects.put(actions$5.setState({
527
+ yield effects.put(actions$6.setState({
529
528
  paymentMethod,
530
529
  loading: false,
531
530
  fetching: false,
532
531
  }));
533
532
  }
534
533
  catch (e) {
535
- yield effects.put(actions$5.setError(e.message));
534
+ yield effects.put(actions$6.setError(e.message));
536
535
  }
537
536
  }
538
537
  function* checkoutEvent$1({ payload }) {
@@ -541,7 +540,7 @@ function* checkoutEvent$1({ payload }) {
541
540
  }
542
541
  }
543
542
  function* updateBillingDetails({ payload, }) {
544
- yield effects.put(actions$5.setLoading(true));
543
+ yield effects.put(actions$6.setLoading(true));
545
544
  const { id, email, address, callback } = payload;
546
545
  try {
547
546
  yield effects.call(restApi.api.subscriptions.updatePaymentMethodBillingDetails, id, Object.assign({ email }, address));
@@ -549,44 +548,44 @@ function* updateBillingDetails({ payload, }) {
549
548
  callback === null || callback === void 0 ? void 0 : callback(true);
550
549
  }
551
550
  catch (e) {
552
- yield effects.put(actions$5.setError(e.message));
551
+ yield effects.put(actions$6.setError(e.message));
553
552
  callback === null || callback === void 0 ? void 0 : callback(false);
554
553
  }
555
- yield effects.put(actions$5.setLoading(false));
554
+ yield effects.put(actions$6.setLoading(false));
556
555
  }
557
556
  function* submitPaymentMethod() {
558
- yield effects.put(actions$5.setLoading(true));
557
+ yield effects.put(actions$6.setLoading(true));
559
558
  }
560
559
  function* submitPaymentMethodError({ payload: error }) {
561
- yield effects.put(actions$5.setError(error));
560
+ yield effects.put(actions$6.setError(error));
562
561
  }
563
562
  function* submitPaymentMethodSuccess() {
564
- yield effects.put(actions$5.loadPaymentMethod());
563
+ yield effects.put(actions$6.loadPaymentMethod());
565
564
  }
566
565
  /*********************************
567
566
  * Preview Sagas
568
567
  *********************************/
569
568
  function* loadPaymentMethodMock() {
570
- yield effects.put(actions$5.setLoading(true));
569
+ yield effects.put(actions$6.setLoading(true));
571
570
  yield effects.delay(500);
572
571
  const paymentMethod = paymentMethodsMock[0];
573
- yield effects.put(actions$5.setState({
572
+ yield effects.put(actions$6.setState({
574
573
  paymentMethod,
575
574
  loading: false,
576
575
  fetching: false,
577
576
  }));
578
577
  }
579
578
  function* subscriptionsPaymentMethodSagasMock() {
580
- yield effects.takeEvery(actions$5.loadPaymentMethod, loadPaymentMethodMock);
579
+ yield effects.takeEvery(actions$6.loadPaymentMethod, loadPaymentMethodMock);
581
580
  }
582
581
 
583
582
  function* subscriptionInvoicesSagas() {
584
- yield effects.takeEvery(actions$4.loadInvoices, loadInvoices);
585
- yield effects.takeEvery(actions$4.downloadInvoice, downloadInvoice);
583
+ yield effects.takeEvery(actions$5.loadInvoices, loadInvoices);
584
+ yield effects.takeEvery(actions$5.downloadInvoice, downloadInvoice);
586
585
  yield effects.takeEvery(actions$3.checkoutEvent, checkoutEvent);
587
586
  }
588
587
  function* loadInvoices() {
589
- yield effects.put(actions$4.setLoading(true));
588
+ yield effects.put(actions$5.setLoading(true));
590
589
  try {
591
590
  const responseInvoices = yield effects.call(restApi.api.subscriptions.getSubscriptionInvoices);
592
591
  const invoices = responseInvoices.map((invoice) => ({
@@ -599,24 +598,24 @@ function* loadInvoices() {
599
598
  paid: invoice.paid || false,
600
599
  receiptNumber: invoice.receiptNumber,
601
600
  }));
602
- yield effects.put(actions$4.setState({
601
+ yield effects.put(actions$5.setState({
603
602
  loading: false,
604
603
  fetching: false,
605
604
  invoices,
606
605
  }));
607
606
  }
608
607
  catch (e) {
609
- yield effects.put(actions$4.setError(e.message));
608
+ yield effects.put(actions$5.setError(e.message));
610
609
  }
611
610
  }
612
611
  function* downloadInvoice({ payload }) {
613
- yield effects.put(actions$4.setInvoiceDownloadState({ loading: true, error: null }));
612
+ yield effects.put(actions$5.setInvoiceDownloadState({ loading: true, error: null }));
614
613
  try {
615
614
  yield effects.call(restApi.api.subscriptions.getSubscriptionInvoicePdf, payload.invoiceId, payload.filename);
616
- yield effects.put(actions$4.setInvoiceDownloadState({ loading: false, error: null }));
615
+ yield effects.put(actions$5.setInvoiceDownloadState({ loading: false, error: null }));
617
616
  }
618
617
  catch (e) {
619
- yield effects.put(actions$4.setInvoiceDownloadState({ loading: false, error: e.message || null }));
618
+ yield effects.put(actions$5.setInvoiceDownloadState({ loading: false, error: e.message || null }));
620
619
  }
621
620
  }
622
621
  function* checkoutEvent({ payload }) {
@@ -628,18 +627,35 @@ function* checkoutEvent({ payload }) {
628
627
  * Preview Sagas
629
628
  *********************************/
630
629
  function* loadInvoicesMock() {
631
- yield effects.put(actions$4.setLoading(true));
630
+ yield effects.put(actions$5.setLoading(true));
632
631
  yield effects.delay(500);
633
632
  const selectPlanTitle = 'Premium';
634
- yield effects.put(actions$4.setState({
633
+ yield effects.put(actions$5.setState({
635
634
  loading: false,
636
635
  fetching: false,
637
636
  invoices: invoicesMock.map((invoice) => (Object.assign(Object.assign({}, invoice), { selectedPlan: selectPlanTitle, paymentDate: new Date(Date.parse(invoice.paymentDate)), totalAmount: +((invoice.totalAmount || 0) / 100).toFixed(2) }))),
638
637
  }));
639
- yield effects.put(actions$4.setLoading(false));
638
+ yield effects.put(actions$5.setLoading(false));
640
639
  }
641
640
  function* subscriptionInvoicesSagasMock() {
642
- yield effects.takeEvery(actions$4.loadInvoices, loadInvoicesMock);
641
+ yield effects.takeEvery(actions$5.loadInvoices, loadInvoicesMock);
642
+ }
643
+
644
+ function* subscriptionSagas() {
645
+ yield effects.takeEvery(actions$4.load, loadSubscription);
646
+ }
647
+ function* loadSubscription() {
648
+ const profile = yield effects.select((state) => { var _a, _b; return (_b = (_a = state.auth) === null || _a === void 0 ? void 0 : _a.profileState) === null || _b === void 0 ? void 0 : _b.profile; });
649
+ yield loadSummaries(profile.tenantId);
650
+ }
651
+ /*********************************
652
+ * Preview Sagas
653
+ *********************************/
654
+ function* loadMock() {
655
+ yield loadSummariesMock();
656
+ }
657
+ function* subscriptionSagasMock() {
658
+ yield effects.takeEvery(actions$4.load, loadMock);
643
659
  }
644
660
 
645
661
  function* billingSagas() {
@@ -647,6 +663,7 @@ function* billingSagas() {
647
663
  effects.call(subscriptionBillingInformationSagas),
648
664
  effects.call(subscriptionsPaymentMethodSagas),
649
665
  effects.call(subscriptionInvoicesSagas),
666
+ effects.call(subscriptionSagas),
650
667
  ]);
651
668
  }
652
669
  function* billingSagasMock() {
@@ -654,6 +671,7 @@ function* billingSagasMock() {
654
671
  effects.call(subscriptionBillingInformationSagasMock),
655
672
  effects.call(subscriptionsPaymentMethodSagasMock),
656
673
  effects.call(subscriptionInvoicesSagasMock),
674
+ effects.call(subscriptionSagasMock),
657
675
  ]);
658
676
  }
659
677
 
@@ -666,18 +684,6 @@ function* checkoutSagas() {
666
684
  yield effects.takeEvery(actions$3.errorCheckout, errorCheckout);
667
685
  }
668
686
  function* checkoutPlan({ payload: planId }) {
669
- const { subscription, summary } = yield effects.select((state) => state.subscriptions.billing.information);
670
- const isTrialing = (subscription === null || subscription === void 0 ? void 0 : subscription.trialEnd) || (subscription === null || subscription === void 0 ? void 0 : subscription.status) === exports.SubscriptionStatus.TRIALING;
671
- const hasPaymentMethod = !!(summary === null || summary === void 0 ? void 0 : summary.paymentMethodId);
672
- if (isTrialing && hasPaymentMethod) {
673
- yield effects.put(actions$3.setState({
674
- checkoutPlanId: null,
675
- loading: false,
676
- status: exports.CheckoutStatus.CONFIRM,
677
- }));
678
- yield effects.put(actions$3.checkoutEvent(exports.CheckoutEvent.CONFIRMED));
679
- return;
680
- }
681
687
  yield effects.put(actions$3.setState({
682
688
  checkoutPlanId: planId,
683
689
  loading: false,
@@ -693,18 +699,29 @@ function* resetCheckout() {
693
699
  }));
694
700
  }
695
701
  function* confirmPlan({ payload: paymentMethodId }) {
696
- const { subscription, status, planId } = yield effects.select(({ subscriptions: { billing: { information }, checkout, }, }) => ({
697
- subscription: information.subscription,
698
- status: checkout.status,
699
- planId: checkout.checkoutPlanId,
702
+ const { checkout: { status, checkoutPlanId, }, subscription, summary } = yield effects.select(({ subscriptions: { billing: { information: { summary, subscription } }, checkout, }, }) => ({
703
+ subscription,
704
+ summary,
705
+ checkout,
700
706
  }));
701
- if (!planId || !subscription) {
707
+ const isTrialing = (subscription === null || subscription === void 0 ? void 0 : subscription.trialEnd) || (subscription === null || subscription === void 0 ? void 0 : subscription.status) === exports.SubscriptionStatus.TRIALING;
708
+ const hasPaymentMethod = !!(summary === null || summary === void 0 ? void 0 : summary.paymentMethodId);
709
+ if (!checkoutPlanId || !subscription) {
702
710
  yield effects.put(actions$3.setState({
703
711
  loading: false,
704
712
  status: exports.CheckoutStatus.ERROR,
705
713
  }));
706
714
  return;
707
715
  }
716
+ if (isTrialing && hasPaymentMethod) {
717
+ yield effects.put(actions$3.setState({
718
+ checkoutPlanId: null,
719
+ loading: false,
720
+ status: exports.CheckoutStatus.CONFIRM,
721
+ }));
722
+ yield effects.put(actions$3.checkoutEvent(exports.CheckoutEvent.CONFIRMED));
723
+ return;
724
+ }
708
725
  if (status === exports.CheckoutStatus.CHECKOUT) {
709
726
  yield effects.put(actions$3.setState({
710
727
  loading: true,
@@ -713,7 +730,7 @@ function* confirmPlan({ payload: paymentMethodId }) {
713
730
  try {
714
731
  yield effects.call(restApi.api.subscriptions.updateManagedSubscription, subscription.id, {
715
732
  paymentMethodId,
716
- planId,
733
+ planId: checkoutPlanId,
717
734
  });
718
735
  yield effects.put(actions$3.setState({
719
736
  checkoutPlanId: null,
@@ -775,10 +792,10 @@ function* checkoutSagasMock() {
775
792
  }
776
793
 
777
794
  function* plansSagas() {
778
- yield effects.takeEvery(actions$8.loadPlans, loadPlans);
795
+ yield effects.takeEvery(actions$9.loadPlans, loadPlans);
779
796
  }
780
797
  function* loadPlans() {
781
- yield effects.put(actions$8.setLoading(true));
798
+ yield effects.put(actions$9.setLoading(true));
782
799
  try {
783
800
  const products = yield effects.call(restApi.api.subscriptions.getSubscriptionPlans);
784
801
  const plans = products.map((item) => {
@@ -787,38 +804,38 @@ function* loadPlans() {
787
804
  id: item.id,
788
805
  name: item.name,
789
806
  description: item.description,
790
- price: +((((_a = item.price) === null || _a === void 0 ? void 0 : _a.amount) || 0) / 100).toFixed(2),
807
+ price: ((_a = item.price) === null || _a === void 0 ? void 0 : _a.amount) || 0,
791
808
  currency: ((_b = item.price) === null || _b === void 0 ? void 0 : _b.currency) || 'usd',
792
809
  recurringInterval: 'month',
793
810
  });
794
811
  });
795
- yield effects.put(actions$8.setState({
812
+ yield effects.put(actions$9.setState({
796
813
  fetching: false,
797
814
  loading: false,
798
815
  plans,
799
816
  }));
800
817
  }
801
818
  catch (e) {
802
- yield effects.put(actions$8.setError(e.message));
819
+ yield effects.put(actions$9.setError(e.message));
803
820
  }
804
821
  }
805
822
  /*********************************
806
823
  * Preview Sagas
807
824
  *********************************/
808
825
  function* loadPlansMock() {
809
- yield effects.put(actions$8.setLoading(true));
826
+ yield effects.put(actions$9.setLoading(true));
810
827
  yield effects.delay(500);
811
- yield effects.put(actions$8.setState({
828
+ yield effects.put(actions$9.setState({
812
829
  fetching: false,
813
830
  loading: false,
814
831
  plans: planResponseMock.map((item) => {
815
832
  var _a, _b;
816
- return (Object.assign(Object.assign({}, item), { price: +((((_a = item.price) === null || _a === void 0 ? void 0 : _a.amount) || 0) / 100).toFixed(2), currency: ((_b = item.price) === null || _b === void 0 ? void 0 : _b.currency) || 'usd', recurringInterval: 'month' }));
833
+ return (Object.assign(Object.assign({}, item), { price: ((_a = item.price) === null || _a === void 0 ? void 0 : _a.amount) || 0, currency: ((_b = item.price) === null || _b === void 0 ? void 0 : _b.currency) || 'usd', recurringInterval: 'month' }));
817
834
  }),
818
835
  }));
819
836
  }
820
837
  function* plansSagasMock() {
821
- yield effects.takeEvery(actions$8.loadPlans, loadPlansMock);
838
+ yield effects.takeEvery(actions$9.loadPlans, loadPlansMock);
822
839
  }
823
840
 
824
841
  exports.PaymentMethodType = void 0;
@@ -828,10 +845,10 @@ exports.PaymentMethodType = void 0;
828
845
  })(exports.PaymentMethodType || (exports.PaymentMethodType = {}));
829
846
 
830
847
  function* configSagas() {
831
- yield effects.takeEvery(actions$7.loadPaymentConfiguration, loadPaymentConfiguration);
848
+ yield effects.takeEvery(actions$8.loadPaymentConfiguration, loadPaymentConfiguration);
832
849
  }
833
850
  function* loadPaymentConfiguration() {
834
- yield effects.put(actions$7.setLoading(true));
851
+ yield effects.put(actions$8.setLoading(true));
835
852
  try {
836
853
  const response = yield effects.call(restApi.api.subscriptions.getPaymentProviders) || [];
837
854
  const stripePaymentProvider = response.find((paymentProvider) => paymentProvider.status === '1' && paymentProvider.providerType === restApi.ProviderType.Stripe);
@@ -839,18 +856,18 @@ function* loadPaymentConfiguration() {
839
856
  yield loadStripePaymentConfiguration();
840
857
  }
841
858
  else {
842
- yield effects.put(actions$7.setError('Payment provider not configured'));
859
+ yield effects.put(actions$8.setError('Payment provider not configured'));
843
860
  }
844
861
  }
845
862
  catch (e) {
846
- yield effects.put(actions$7.setError(e.message));
863
+ yield effects.put(actions$8.setError(e.message));
847
864
  }
848
865
  }
849
866
  function* loadStripePaymentConfiguration() {
850
- yield effects.put(actions$7.setLoading(true));
867
+ yield effects.put(actions$8.setLoading(true));
851
868
  try {
852
869
  const response = yield effects.call(restApi.api.subscriptions.getStripePaymentProviderConfiguration);
853
- yield effects.put(actions$7.setState({
870
+ yield effects.put(actions$8.setState({
854
871
  loading: false,
855
872
  fetching: false,
856
873
  config: {
@@ -860,16 +877,16 @@ function* loadStripePaymentConfiguration() {
860
877
  }));
861
878
  }
862
879
  catch (e) {
863
- yield effects.put(actions$7.setError(e.message));
880
+ yield effects.put(actions$8.setError(e.message));
864
881
  }
865
882
  }
866
883
  /*********************************
867
884
  * Preview Sagas
868
885
  *********************************/
869
886
  function* loadPaymentConfigurationMock() {
870
- yield effects.put(actions$7.setLoading(true));
887
+ yield effects.put(actions$8.setLoading(true));
871
888
  yield effects.delay(500);
872
- yield effects.put(actions$7.setState({
889
+ yield effects.put(actions$8.setState({
873
890
  loading: false,
874
891
  fetching: false,
875
892
  config: {
@@ -879,25 +896,27 @@ function* loadPaymentConfigurationMock() {
879
896
  }));
880
897
  }
881
898
  function* configSagasMock() {
882
- yield effects.takeEvery(actions$7.loadPaymentConfiguration, loadPaymentConfigurationMock);
899
+ yield effects.takeEvery(actions$8.loadPaymentConfiguration, loadPaymentConfigurationMock);
883
900
  }
884
901
 
885
902
  function* subscriptionStripeSagas() {
886
903
  yield effects.takeEvery(actions$2.createCardSetupIntentSecret, createCardSetupIntentSecret);
887
904
  }
888
905
  function* createCardSetupIntentSecret({ payload }) {
889
- yield effects.put(actions$2.setStripeState({
906
+ yield effects.put(actions$2.setState({
890
907
  loading: true,
891
908
  error: null,
892
- cardSetupIntentSecret: null
909
+ cardSetupIntentSecret: null,
893
910
  }));
894
911
  try {
895
- const { setupIntentSecret } = yield effects.call(restApi.api.subscriptions.createStripePaymentMethodSetupIntentSecret, {
896
- paymentMethodId: payload || undefined
897
- });
898
- yield effects.put(actions$2.setStripeState({
912
+ const request = {};
913
+ if (payload) {
914
+ request.paymentMethodId = payload;
915
+ }
916
+ const { setupIntentSecret } = yield effects.call(restApi.api.subscriptions.createStripePaymentMethodSetupIntentSecret, request);
917
+ yield effects.put(actions$2.setState({
899
918
  cardSetupIntentSecret: setupIntentSecret,
900
- loading: false
919
+ loading: false,
901
920
  }));
902
921
  }
903
922
  catch (e) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@frontegg/redux-store",
3
3
  "libName": "FronteggReduxStore",
4
- "version": "5.29.0",
4
+ "version": "5.31.0",
5
5
  "author": "Frontegg LTD",
6
6
  "main": "./node/index.js",
7
7
  "module": "./index.js",