@frontegg/redux-store 5.21.0 → 5.24.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 (38) hide show
  1. package/auth/AcceptInvitationState/index.d.ts +2 -0
  2. package/auth/AccountSettingsState/index.d.ts +10 -0
  3. package/auth/ActivateState/index.d.ts +3 -0
  4. package/auth/ApiTokensState/index.d.ts +2 -0
  5. package/auth/ForgotPasswordState/index.d.ts +2 -0
  6. package/auth/LoginState/index.d.ts +2 -0
  7. package/auth/LoginState/interfaces.d.ts +2 -0
  8. package/auth/LoginState/saga.d.ts +2 -0
  9. package/auth/MfaState/index.d.ts +6 -6
  10. package/auth/ProfileState/index.d.ts +2 -0
  11. package/auth/ResetPhoneNumberState/index.d.ts +96 -0
  12. package/auth/ResetPhoneNumberState/interfaces.d.ts +18 -0
  13. package/auth/ResetPhoneNumberState/saga.d.ts +17 -0
  14. package/auth/RolesState/index.d.ts +2 -0
  15. package/auth/SSOState/index.d.ts +2 -0
  16. package/auth/SecurityPolicyState/index.d.ts +9 -0
  17. package/auth/SignUp/index.d.ts +2 -0
  18. package/auth/SocialLogins/index.d.ts +2 -8
  19. package/auth/TeamState/index.d.ts +2 -0
  20. package/auth/TenantsState/index.d.ts +2 -8
  21. package/auth/index.d.ts +13 -0
  22. package/auth/index.js +105 -15
  23. package/auth/interfaces.d.ts +15 -1
  24. package/auth/reducer.d.ts +13 -1
  25. package/auth/utils.d.ts +4 -0
  26. package/index.js +2 -2
  27. package/node/auth/index.js +115 -22
  28. package/node/index.js +15 -0
  29. package/node/subscriptions/index.js +187 -151
  30. package/package.json +2 -2
  31. package/subscriptions/ManagedSubscriptions/index.d.ts +10 -0
  32. package/subscriptions/ManagedSubscriptions/interfaces.d.ts +28 -0
  33. package/subscriptions/ManagedSubscriptions/saga.d.ts +1 -0
  34. package/subscriptions/index.d.ts +7 -0
  35. package/subscriptions/index.js +188 -152
  36. package/subscriptions/interfaces.d.ts +4 -0
  37. package/subscriptions/reducer.d.ts +7 -0
  38. package/toolkit/index.d.ts +1 -1
@@ -42,12 +42,12 @@ const plansInitialState = {
42
42
  fetching: true,
43
43
  plans: [],
44
44
  };
45
- const { actions: sliceActions$1, reducer: reducer$7, name: name$6 } = toolkit.createSlice({
45
+ const { actions: sliceActions$2, reducer: reducer$8, name: name$7 } = toolkit.createSlice({
46
46
  name: `${constants.subscriptionsStoreName}/plans`,
47
47
  initialState: plansInitialState,
48
48
  reducers: Object.assign({}, createModuleCaseReducers()),
49
49
  });
50
- const actions$7 = Object.assign({ loadPlans: toolkit.createAction(`${name$6}/loadPlans`) }, sliceActions$1);
50
+ const actions$8 = Object.assign({ loadPlans: toolkit.createAction(`${name$7}/loadPlans`) }, sliceActions$2);
51
51
 
52
52
  const configInitialState = {
53
53
  loading: false,
@@ -55,13 +55,13 @@ const configInitialState = {
55
55
  fetching: true,
56
56
  config: null,
57
57
  };
58
- const reducers$5 = Object.assign({}, createModuleCaseReducers());
59
- const { actions: configActions, reducer: reducer$6, name: name$5, } = toolkit.createSlice({
58
+ const reducers$6 = Object.assign({}, createModuleCaseReducers());
59
+ const { actions: configActions, reducer: reducer$7, name: name$6, } = toolkit.createSlice({
60
60
  name: `${constants.subscriptionsStoreName}/config`,
61
61
  initialState: configInitialState,
62
- reducers: reducers$5,
62
+ reducers: reducers$6,
63
63
  });
64
- const actions$6 = Object.assign({ loadPaymentConfiguration: toolkit.createAction(`${name$5}/loadPaymentConfiguration`) }, configActions);
64
+ const actions$7 = Object.assign({ loadPaymentConfiguration: toolkit.createAction(`${name$6}/loadPaymentConfiguration`) }, configActions);
65
65
 
66
66
  const initialBillingInformationState = {
67
67
  loading: false,
@@ -78,32 +78,32 @@ const initialBillingInformationState = {
78
78
  error: null,
79
79
  },
80
80
  };
81
- const reducers$4 = Object.assign(Object.assign({}, createModuleCaseReducers()), { setBillingInformation: {
81
+ const reducers$5 = Object.assign(Object.assign({}, createModuleCaseReducers()), { setBillingInformation: {
82
82
  prepare: (payload) => ({ payload }),
83
83
  reducer: (state, action) => (Object.assign(Object.assign({}, state), action.payload)),
84
84
  }, setCancellationLoading: createKeyCaseLoadingReducer('cancellation'), setCancellationError: createKeyCaseErrorReducer('cancellation'), setRenewalLoading: createKeyCaseLoadingReducer('renewal'), setRenewalError: createKeyCaseErrorReducer('renewal') });
85
- const { reducer: reducer$5, actions: overviewActions, name: name$4, } = toolkit.createSlice({
85
+ const { reducer: reducer$6, actions: overviewActions, name: name$5, } = toolkit.createSlice({
86
86
  name: `${constants.subscriptionsStoreName}/billing/information`,
87
87
  initialState: initialBillingInformationState,
88
- reducers: reducers$4,
88
+ reducers: reducers$5,
89
89
  });
90
- const actions$5 = Object.assign({ loadBillingInformation: toolkit.createAction(`${name$4}/loadBillingInformation`), cancelSubscription: toolkit.createAction(`${name$4}/cancelSubscription`), renewSubscription: toolkit.createAction(`${name$4}/renewSubscription`) }, overviewActions);
90
+ const actions$6 = Object.assign({ loadBillingInformation: toolkit.createAction(`${name$5}/loadBillingInformation`), cancelSubscription: toolkit.createAction(`${name$5}/cancelSubscription`), renewSubscription: toolkit.createAction(`${name$5}/renewSubscription`) }, overviewActions);
91
91
 
92
92
  const initialPaymentMethodState = {
93
93
  loading: false,
94
94
  error: null,
95
95
  fetching: true,
96
96
  };
97
- const reducers$3 = Object.assign(Object.assign({}, createModuleCaseReducers()), { setState: {
97
+ const reducers$4 = Object.assign(Object.assign({}, createModuleCaseReducers()), { setState: {
98
98
  prepare: (payload) => ({ payload }),
99
99
  reducer: (state, action) => (Object.assign(Object.assign({}, state), action.payload)),
100
100
  } });
101
- const { reducer: reducer$4, actions: paymentActions, name: name$3, } = toolkit.createSlice({
101
+ const { reducer: reducer$5, actions: paymentActions, name: name$4, } = toolkit.createSlice({
102
102
  name: `${constants.subscriptionsStoreName}/billing/payment`,
103
103
  initialState: initialPaymentMethodState,
104
- reducers: reducers$3,
104
+ reducers: reducers$4,
105
105
  });
106
- const actions$4 = Object.assign({ loadPaymentMethod: toolkit.createAction(`${name$3}/loadPaymentMethod`), submitPaymentMethod: toolkit.createAction(`${name$3}/submitPaymentMethod`), submitPaymentMethodError: toolkit.createAction(`${name$3}/submitPaymentMethodError`), submitPaymentMethodSuccess: toolkit.createAction(`${name$3}/submitPaymentMethodSuccess`), updatePaymentMethodBillingDetails: toolkit.createAction(`${name$3}/updateBillingDetails`, (payload) => ({ payload })) }, paymentActions);
106
+ 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);
107
107
 
108
108
  const initialInvoicesState = {
109
109
  loading: false,
@@ -115,16 +115,16 @@ const initialInvoicesState = {
115
115
  error: null
116
116
  }
117
117
  };
118
- const reducers$2 = Object.assign(Object.assign({}, createModuleCaseReducers()), { setInvoiceDownloadState: {
118
+ const reducers$3 = Object.assign(Object.assign({}, createModuleCaseReducers()), { setInvoiceDownloadState: {
119
119
  prepare: (payload) => ({ payload }),
120
120
  reducer: (state, action) => (Object.assign(Object.assign({}, state), { invoiceDownload: Object.assign(Object.assign({}, state.invoiceDownload), action.payload) })),
121
121
  } });
122
- const { reducer: reducer$3, actions: sliceActions, name: name$2, } = toolkit.createSlice({
122
+ const { reducer: reducer$4, actions: sliceActions$1, name: name$3, } = toolkit.createSlice({
123
123
  name: `${constants.subscriptionsStoreName}/billing/invoices`,
124
124
  initialState: initialInvoicesState,
125
- reducers: reducers$2,
125
+ reducers: reducers$3,
126
126
  });
127
- const actions$3 = Object.assign({ loadInvoices: toolkit.createAction(`${name$2}/loadInvoices`), downloadInvoice: toolkit.createAction(`${name$2}/downloadInvoice`, (payload) => ({ payload })) }, sliceActions);
127
+ const actions$4 = Object.assign({ loadInvoices: toolkit.createAction(`${name$3}/loadInvoices`), downloadInvoice: toolkit.createAction(`${name$3}/downloadInvoice`, (payload) => ({ payload })) }, sliceActions$1);
128
128
 
129
129
  const billingInitialState = {
130
130
  information: initialBillingInformationState,
@@ -132,14 +132,14 @@ const billingInitialState = {
132
132
  paymentMethod: initialPaymentMethodState,
133
133
  };
134
134
  const billingActions = {
135
- invoices: actions$3,
136
- information: actions$5,
137
- paymentMethod: actions$4,
135
+ invoices: actions$4,
136
+ information: actions$6,
137
+ paymentMethod: actions$5,
138
138
  };
139
139
  const billingReducer = toolkit.combineReducers({
140
- invoices: reducer$3,
141
- information: reducer$5,
142
- paymentMethod: reducer$4,
140
+ invoices: reducer$4,
141
+ information: reducer$6,
142
+ paymentMethod: reducer$5,
143
143
  });
144
144
 
145
145
  exports.CheckoutStatus = void 0;
@@ -165,35 +165,49 @@ const checkoutInitialState = {
165
165
  status: exports.CheckoutStatus.SELECTION,
166
166
  checkoutPlanId: null,
167
167
  };
168
- const reducers$1 = Object.assign(Object.assign({}, createModuleCaseReducers()), { setStatus: {
168
+ const reducers$2 = Object.assign(Object.assign({}, createModuleCaseReducers()), { setStatus: {
169
169
  prepare: (payload) => ({ payload }),
170
170
  reducer: (state, action) => (Object.assign(Object.assign({}, state), { status: action.payload })),
171
171
  }, selectPlan: {
172
172
  prepare: (payload) => ({ payload }),
173
173
  reducer: (state, action) => (Object.assign(Object.assign({}, state), { checkoutPlanId: action.payload })),
174
174
  } });
175
- const { actions: checkoutActions, reducer: reducer$2, name: name$1 } = toolkit.createSlice({
175
+ const { actions: checkoutActions, reducer: reducer$3, name: name$2 } = toolkit.createSlice({
176
176
  name: `${constants.subscriptionsStoreName}/checkout`,
177
177
  initialState: checkoutInitialState,
178
- reducers: reducers$1,
178
+ reducers: reducers$2,
179
179
  });
180
- const actions$2 = Object.assign({ checkoutPlan: toolkit.createAction(`${name$1}/checkoutPlan`, (payload) => ({ payload })), resetCheckout: toolkit.createAction(`${name$1}/resetCheckout`), confirmCheckout: toolkit.createAction(`${name$1}/confirmCheckout`, (payload) => ({ payload, })), cancelCheckout: toolkit.createAction(`${name$1}/cancelCheckout`), submitCheckout: toolkit.createAction(`${name$1}/submitCheckout`), errorCheckout: toolkit.createAction(`${name$1}/errorCheckout`, (payload) => ({ payload, })), checkoutEvent: toolkit.createAction(`${name$1}/checkoutEvent`, (payload) => ({ payload, })) }, checkoutActions);
180
+ const actions$3 = Object.assign({ checkoutPlan: toolkit.createAction(`${name$2}/checkoutPlan`, (payload) => ({ payload })), resetCheckout: toolkit.createAction(`${name$2}/resetCheckout`), confirmCheckout: toolkit.createAction(`${name$2}/confirmCheckout`, (payload) => ({ payload, })), cancelCheckout: toolkit.createAction(`${name$2}/cancelCheckout`), submitCheckout: toolkit.createAction(`${name$2}/submitCheckout`), errorCheckout: toolkit.createAction(`${name$2}/errorCheckout`, (payload) => ({ payload, })), checkoutEvent: toolkit.createAction(`${name$2}/checkoutEvent`, (payload) => ({ payload, })) }, checkoutActions);
181
181
 
182
182
  const initialSubscriptionStripeState = {
183
183
  loading: false,
184
184
  error: null,
185
185
  cardSetupIntentSecret: null,
186
186
  };
187
- const reducers = Object.assign(Object.assign({}, createModuleCaseReducers()), { setStripeState: {
187
+ const reducers$1 = Object.assign(Object.assign({}, createModuleCaseReducers()), { setStripeState: {
188
188
  prepare: (payload) => ({ payload }),
189
189
  reducer: (state, action) => (Object.assign(Object.assign({}, state), action.payload)),
190
190
  } });
191
- const { reducer: reducer$1, actions: reducerActions, name, } = toolkit.createSlice({
191
+ const { reducer: reducer$2, actions: reducerActions, name: name$1, } = toolkit.createSlice({
192
192
  name: `${constants.subscriptionsStoreName}/stripe`,
193
193
  initialState: initialSubscriptionStripeState,
194
+ reducers: reducers$1,
195
+ });
196
+ const actions$2 = Object.assign({ loadCustomer: toolkit.createAction(`${name$1}/loadCustomer`), createCardSetupIntentSecret: toolkit.createAction(`${name$1}/createCardSetupIntentSecret`) }, reducerActions);
197
+
198
+ const managedSubscriptionsInitialState = {
199
+ loading: false,
200
+ error: null,
201
+ fetching: true,
202
+ managedSubscriptions: [],
203
+ };
204
+ const reducers = Object.assign({}, createModuleCaseReducers());
205
+ const { reducer: reducer$1, actions: sliceActions, name } = toolkit.createSlice({
206
+ name: `${constants.subscriptionsStoreName}/managedSubscriptions`,
207
+ initialState: managedSubscriptionsInitialState,
194
208
  reducers,
195
209
  });
196
- const actions$1 = Object.assign({ loadCustomer: toolkit.createAction(`${name}/loadCustomer`), createCardSetupIntentSecret: toolkit.createAction(`${name}/createCardSetupIntentSecret`) }, reducerActions);
210
+ const actions$1 = Object.assign({ loadManagedSubscriptions: toolkit.createAction(`${name}/loadManagedSubscriptions`) }, sliceActions);
197
211
 
198
212
  const initialState = {
199
213
  config: configInitialState,
@@ -201,20 +215,23 @@ const initialState = {
201
215
  checkout: checkoutInitialState,
202
216
  billing: billingInitialState,
203
217
  stripe: initialSubscriptionStripeState,
218
+ managedSubscriptions: managedSubscriptionsInitialState,
204
219
  };
205
220
  const actions = {
206
- config: actions$6,
221
+ config: actions$7,
207
222
  billing: billingActions,
208
- plans: actions$7,
209
- checkout: actions$2,
210
- stripe: actions$1,
223
+ plans: actions$8,
224
+ checkout: actions$3,
225
+ stripe: actions$2,
226
+ managedSubscriptions: actions$1,
211
227
  };
212
228
  const reducer = toolkit.combineReducers({
213
- config: reducer$6,
229
+ config: reducer$7,
214
230
  billing: billingReducer,
215
- plans: reducer$7,
216
- checkout: reducer$2,
217
- stripe: reducer$1,
231
+ plans: reducer$8,
232
+ checkout: reducer$3,
233
+ stripe: reducer$2,
234
+ managedSubscriptions: reducer$1,
218
235
  });
219
236
 
220
237
  exports.PaymentProvider = void 0;
@@ -347,34 +364,34 @@ const paymentMethodsMock = [
347
364
  ];
348
365
 
349
366
  function* subscriptionBillingInformationSagas() {
350
- yield effects.takeEvery(actions$5.loadBillingInformation, loadBillingInformation);
351
- yield effects.takeEvery(actions$5.cancelSubscription, cancelSubscription);
352
- yield effects.takeEvery(actions$5.renewSubscription, renewSubscription);
353
- yield effects.takeEvery(actions$2.checkoutEvent, checkoutEvent$2);
367
+ yield effects.takeEvery(actions$6.loadBillingInformation, loadBillingInformation);
368
+ yield effects.takeEvery(actions$6.cancelSubscription, cancelSubscription);
369
+ yield effects.takeEvery(actions$6.renewSubscription, renewSubscription);
370
+ yield effects.takeEvery(actions$3.checkoutEvent, checkoutEvent$2);
354
371
  }
355
372
  function* loadBillingInformation() {
356
373
  const paymentProvider = yield effects.select((state) => { var _a; return (_a = state.subscriptions.config.config) === null || _a === void 0 ? void 0 : _a.paymentProvider; });
357
374
  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; });
358
- yield effects.put(actions$5.setLoading(true));
375
+ yield effects.put(actions$6.setLoading(true));
359
376
  if (!paymentProvider || !tenantId) {
360
- yield effects.put(actions$5.setError(!paymentProvider ? 'Internal feature failure' : 'Not authorized'));
377
+ yield effects.put(actions$6.setError(!paymentProvider ? 'Internal feature failure' : 'Not authorized'));
361
378
  return;
362
379
  }
363
380
  try {
364
381
  yield loadSummaries(tenantId);
365
382
  }
366
383
  catch (e) {
367
- yield effects.put(actions$5.setError(e.message));
384
+ yield effects.put(actions$6.setError(e.message));
368
385
  }
369
386
  }
370
387
  function* loadSummaries(tenantId) {
371
388
  var _a, _b;
372
- yield effects.put(actions$5.setLoading(true));
389
+ yield effects.put(actions$6.setLoading(true));
373
390
  try {
374
391
  const { currentPlanId, subscriptionId, externallyManaged, defaultPlanId } = yield effects.call(restApi.api.subscriptions.getSubscriptionSummaries, tenantId);
375
392
  const subscriptionResponse = yield effects.call(restApi.api.subscriptions.getSubscription, subscriptionId);
376
393
  const planResponse = yield effects.call(restApi.api.subscriptions.getSubscriptionPlan, currentPlanId);
377
- yield effects.put(actions$5.setBillingInformation(Object.assign(Object.assign({ loading: false, fetching: false, externallyManaged,
394
+ yield effects.put(actions$6.setBillingInformation(Object.assign(Object.assign({ loading: false, fetching: false, externallyManaged,
378
395
  defaultPlanId }, (subscriptionResponse
379
396
  ? {
380
397
  subscription: {
@@ -405,7 +422,7 @@ function* loadSummaries(tenantId) {
405
422
  : {}))));
406
423
  }
407
424
  catch (e) {
408
- yield effects.put(actions$5.setError(e.message));
425
+ yield effects.put(actions$6.setError(e.message));
409
426
  }
410
427
  }
411
428
  function* cancelSubscription() {
@@ -414,24 +431,24 @@ function* cancelSubscription() {
414
431
  return;
415
432
  }
416
433
  if (overview.externallyManaged) {
417
- yield effects.put(actions$5.setCancellationError('Billing is externally managed'));
434
+ yield effects.put(actions$6.setCancellationError('Billing is externally managed'));
418
435
  return;
419
436
  }
420
437
  const { id: subscriptionId, cancellation, status } = overview.subscription || {};
421
438
  const isCancellable = !cancellation && status === exports.SubscriptionStatus.ACTIVE;
422
439
  if (isCancellable) {
423
440
  try {
424
- yield effects.put(actions$5.setCancellationLoading(true));
441
+ yield effects.put(actions$6.setCancellationLoading(true));
425
442
  yield effects.call(restApi.api.subscriptions.cancelSubscription, subscriptionId);
426
- yield effects.put(actions$5.setBillingInformation({
443
+ yield effects.put(actions$6.setBillingInformation({
427
444
  subscription: Object.assign(Object.assign({}, overview.subscription), { cancellation: {
428
445
  policy: exports.SubscriptionCancellationPolicy.AT_PERIOD_END,
429
446
  } }),
430
447
  }));
431
- yield effects.put(actions$5.setCancellationLoading(false));
448
+ yield effects.put(actions$6.setCancellationLoading(false));
432
449
  }
433
450
  catch (e) {
434
- yield effects.put(actions$5.setCancellationError(e.message));
451
+ yield effects.put(actions$6.setCancellationError(e.message));
435
452
  }
436
453
  }
437
454
  }
@@ -441,22 +458,22 @@ function* renewSubscription() {
441
458
  return;
442
459
  }
443
460
  if (overview.externallyManaged) {
444
- yield effects.put(actions$5.setCancellationError('Billing is externally managed'));
461
+ yield effects.put(actions$6.setCancellationError('Billing is externally managed'));
445
462
  return;
446
463
  }
447
464
  const { id: subscriptionId, cancellation } = overview.subscription || {};
448
465
  const renewable = (cancellation === null || cancellation === void 0 ? void 0 : cancellation.policy) === exports.SubscriptionCancellationPolicy.AT_PERIOD_END;
449
466
  if (renewable) {
450
467
  try {
451
- yield effects.put(actions$5.setRenewalLoading(true));
468
+ yield effects.put(actions$6.setRenewalLoading(true));
452
469
  yield effects.call(restApi.api.subscriptions.renewSubscription, subscriptionId);
453
- yield effects.put(actions$5.setBillingInformation({
470
+ yield effects.put(actions$6.setBillingInformation({
454
471
  subscription: Object.assign(Object.assign({}, overview.subscription), { cancellation: null }),
455
472
  }));
456
- yield effects.put(actions$5.setRenewalLoading(false));
473
+ yield effects.put(actions$6.setRenewalLoading(false));
457
474
  }
458
475
  catch (e) {
459
- yield effects.put(actions$5.setCancellationError(e.message));
476
+ yield effects.put(actions$6.setCancellationError(e.message));
460
477
  }
461
478
  }
462
479
  }
@@ -469,14 +486,14 @@ function* checkoutEvent$2({ payload }) {
469
486
  * Preview Sagas
470
487
  *********************************/
471
488
  function* loadBillingInformationMock() {
472
- yield effects.put(actions$5.setLoading(true));
489
+ yield effects.put(actions$6.setLoading(true));
473
490
  yield loadSummariesMock();
474
491
  }
475
492
  function* loadSummariesMock() {
476
493
  var _a, _b;
477
- yield effects.put(actions$5.setLoading(true));
494
+ yield effects.put(actions$6.setLoading(true));
478
495
  yield effects.delay(500);
479
- yield effects.put(actions$5.setBillingInformation({
496
+ yield effects.put(actions$6.setBillingInformation({
480
497
  loading: false,
481
498
  fetching: false,
482
499
  externallyManaged: false,
@@ -485,30 +502,30 @@ function* loadSummariesMock() {
485
502
  }));
486
503
  }
487
504
  function* subscriptionBillingInformationSagasMock() {
488
- yield effects.takeEvery(actions$5.loadBillingInformation, loadBillingInformationMock);
505
+ yield effects.takeEvery(actions$6.loadBillingInformation, loadBillingInformationMock);
489
506
  }
490
507
 
491
508
  function* subscriptionsPaymentMethodSagas() {
492
- yield effects.takeEvery(actions$4.loadPaymentMethod, loadPaymentMethod);
493
- yield effects.takeEvery(actions$4.submitPaymentMethod, submitPaymentMethod);
494
- yield effects.takeEvery(actions$4.submitPaymentMethodError, submitPaymentMethodError);
495
- yield effects.takeEvery(actions$4.submitPaymentMethodSuccess, submitPaymentMethodSuccess);
496
- yield effects.takeEvery(actions$4.updatePaymentMethodBillingDetails, updateBillingDetails);
497
- yield effects.takeEvery(actions$2.checkoutEvent, checkoutEvent$1);
509
+ yield effects.takeEvery(actions$5.loadPaymentMethod, loadPaymentMethod);
510
+ yield effects.takeEvery(actions$5.submitPaymentMethod, submitPaymentMethod);
511
+ yield effects.takeEvery(actions$5.submitPaymentMethodError, submitPaymentMethodError);
512
+ yield effects.takeEvery(actions$5.submitPaymentMethodSuccess, submitPaymentMethodSuccess);
513
+ yield effects.takeEvery(actions$5.updatePaymentMethodBillingDetails, updateBillingDetails);
514
+ yield effects.takeEvery(actions$3.checkoutEvent, checkoutEvent$1);
498
515
  }
499
516
  function* loadPaymentMethod() {
500
- yield effects.put(actions$4.setLoading(true));
517
+ yield effects.put(actions$5.setLoading(true));
501
518
  try {
502
519
  const paymentMethods = yield effects.call(restApi.api.subscriptions.getPaymentMethods);
503
520
  const paymentMethod = paymentMethods[0];
504
- yield effects.put(actions$4.setState({
521
+ yield effects.put(actions$5.setState({
505
522
  paymentMethod,
506
523
  loading: false,
507
524
  fetching: false,
508
525
  }));
509
526
  }
510
527
  catch (e) {
511
- yield effects.put(actions$4.setError(e.message));
528
+ yield effects.put(actions$5.setError(e.message));
512
529
  }
513
530
  }
514
531
  function* checkoutEvent$1({ payload }) {
@@ -517,7 +534,7 @@ function* checkoutEvent$1({ payload }) {
517
534
  }
518
535
  }
519
536
  function* updateBillingDetails({ payload, }) {
520
- yield effects.put(actions$4.setLoading(true));
537
+ yield effects.put(actions$5.setLoading(true));
521
538
  const { id, email, address, callback } = payload;
522
539
  try {
523
540
  yield effects.call(restApi.api.subscriptions.updatePaymentMethodBillingDetails, id, Object.assign({ email }, address));
@@ -525,44 +542,44 @@ function* updateBillingDetails({ payload, }) {
525
542
  callback === null || callback === void 0 ? void 0 : callback(true);
526
543
  }
527
544
  catch (e) {
528
- yield effects.put(actions$4.setError(e.message));
545
+ yield effects.put(actions$5.setError(e.message));
529
546
  callback === null || callback === void 0 ? void 0 : callback(false);
530
547
  }
531
- yield effects.put(actions$4.setLoading(false));
548
+ yield effects.put(actions$5.setLoading(false));
532
549
  }
533
550
  function* submitPaymentMethod() {
534
- yield effects.put(actions$4.setLoading(true));
551
+ yield effects.put(actions$5.setLoading(true));
535
552
  }
536
553
  function* submitPaymentMethodError({ payload: error }) {
537
- yield effects.put(actions$4.setError(error));
554
+ yield effects.put(actions$5.setError(error));
538
555
  }
539
556
  function* submitPaymentMethodSuccess() {
540
- yield effects.put(actions$4.loadPaymentMethod());
557
+ yield effects.put(actions$5.loadPaymentMethod());
541
558
  }
542
559
  /*********************************
543
560
  * Preview Sagas
544
561
  *********************************/
545
562
  function* loadPaymentMethodMock() {
546
- yield effects.put(actions$4.setLoading(true));
563
+ yield effects.put(actions$5.setLoading(true));
547
564
  yield effects.delay(500);
548
565
  const paymentMethod = paymentMethodsMock[0];
549
- yield effects.put(actions$4.setState({
566
+ yield effects.put(actions$5.setState({
550
567
  paymentMethod,
551
568
  loading: false,
552
569
  fetching: false,
553
570
  }));
554
571
  }
555
572
  function* subscriptionsPaymentMethodSagasMock() {
556
- yield effects.takeEvery(actions$4.loadPaymentMethod, loadPaymentMethodMock);
573
+ yield effects.takeEvery(actions$5.loadPaymentMethod, loadPaymentMethodMock);
557
574
  }
558
575
 
559
576
  function* subscriptionInvoicesSagas() {
560
- yield effects.takeEvery(actions$3.loadInvoices, loadInvoices);
561
- yield effects.takeEvery(actions$3.downloadInvoice, downloadInvoice);
562
- yield effects.takeEvery(actions$2.checkoutEvent, checkoutEvent);
577
+ yield effects.takeEvery(actions$4.loadInvoices, loadInvoices);
578
+ yield effects.takeEvery(actions$4.downloadInvoice, downloadInvoice);
579
+ yield effects.takeEvery(actions$3.checkoutEvent, checkoutEvent);
563
580
  }
564
581
  function* loadInvoices() {
565
- yield effects.put(actions$3.setLoading(true));
582
+ yield effects.put(actions$4.setLoading(true));
566
583
  try {
567
584
  const responseInvoices = yield effects.call(restApi.api.subscriptions.getSubscriptionInvoices);
568
585
  const invoices = responseInvoices.map((invoice) => ({
@@ -575,24 +592,24 @@ function* loadInvoices() {
575
592
  paid: invoice.paid || false,
576
593
  receiptNumber: invoice.receiptNumber,
577
594
  }));
578
- yield effects.put(actions$3.setState({
595
+ yield effects.put(actions$4.setState({
579
596
  loading: false,
580
597
  fetching: false,
581
598
  invoices,
582
599
  }));
583
600
  }
584
601
  catch (e) {
585
- yield effects.put(actions$3.setError(e.message));
602
+ yield effects.put(actions$4.setError(e.message));
586
603
  }
587
604
  }
588
605
  function* downloadInvoice({ payload }) {
589
- yield effects.put(actions$3.setInvoiceDownloadState({ loading: true, error: null }));
606
+ yield effects.put(actions$4.setInvoiceDownloadState({ loading: true, error: null }));
590
607
  try {
591
608
  yield effects.call(restApi.api.subscriptions.getSubscriptionInvoicePdf, payload.invoiceId, payload.filename);
592
- yield effects.put(actions$3.setInvoiceDownloadState({ loading: false, error: null }));
609
+ yield effects.put(actions$4.setInvoiceDownloadState({ loading: false, error: null }));
593
610
  }
594
611
  catch (e) {
595
- yield effects.put(actions$3.setInvoiceDownloadState({ loading: false, error: e.message || null }));
612
+ yield effects.put(actions$4.setInvoiceDownloadState({ loading: false, error: e.message || null }));
596
613
  }
597
614
  }
598
615
  function* checkoutEvent({ payload }) {
@@ -604,18 +621,18 @@ function* checkoutEvent({ payload }) {
604
621
  * Preview Sagas
605
622
  *********************************/
606
623
  function* loadInvoicesMock() {
607
- yield effects.put(actions$3.setLoading(true));
624
+ yield effects.put(actions$4.setLoading(true));
608
625
  yield effects.delay(500);
609
626
  const selectPlanTitle = 'Premium';
610
- yield effects.put(actions$3.setState({
627
+ yield effects.put(actions$4.setState({
611
628
  loading: false,
612
629
  fetching: false,
613
630
  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) }))),
614
631
  }));
615
- yield effects.put(actions$3.setLoading(false));
632
+ yield effects.put(actions$4.setLoading(false));
616
633
  }
617
634
  function* subscriptionInvoicesSagasMock() {
618
- yield effects.takeEvery(actions$3.loadInvoices, loadInvoicesMock);
635
+ yield effects.takeEvery(actions$4.loadInvoices, loadInvoicesMock);
619
636
  }
620
637
 
621
638
  function* billingSagas() {
@@ -634,15 +651,15 @@ function* billingSagasMock() {
634
651
  }
635
652
 
636
653
  function* checkoutSagas() {
637
- yield effects.takeEvery(actions$2.checkoutPlan, checkoutPlan);
638
- yield effects.takeEvery(actions$2.resetCheckout, resetCheckout);
639
- yield effects.takeEvery(actions$2.confirmCheckout, confirmPlan);
640
- yield effects.takeEvery(actions$2.cancelCheckout, cancelPlan);
641
- yield effects.takeEvery(actions$2.submitCheckout, submitCheckout);
642
- yield effects.takeEvery(actions$2.errorCheckout, errorCheckout);
654
+ yield effects.takeEvery(actions$3.checkoutPlan, checkoutPlan);
655
+ yield effects.takeEvery(actions$3.resetCheckout, resetCheckout);
656
+ yield effects.takeEvery(actions$3.confirmCheckout, confirmPlan);
657
+ yield effects.takeEvery(actions$3.cancelCheckout, cancelPlan);
658
+ yield effects.takeEvery(actions$3.submitCheckout, submitCheckout);
659
+ yield effects.takeEvery(actions$3.errorCheckout, errorCheckout);
643
660
  }
644
661
  function* checkoutPlan({ payload: planId }) {
645
- yield effects.put(actions$2.setState({
662
+ yield effects.put(actions$3.setState({
646
663
  checkoutPlanId: planId,
647
664
  loading: false,
648
665
  error: null,
@@ -650,70 +667,62 @@ function* checkoutPlan({ payload: planId }) {
650
667
  }));
651
668
  }
652
669
  function* resetCheckout() {
653
- yield effects.put(actions$2.setState({
670
+ yield effects.put(actions$3.setState({
654
671
  checkoutPlanId: null,
655
672
  loading: false,
656
673
  status: exports.CheckoutStatus.SELECTION,
657
674
  }));
658
675
  }
659
676
  function* confirmPlan({ payload: paymentMethodId }) {
660
- var _a;
661
- const { subscription, status, checkoutPlanId } = yield effects.select(({ subscriptions: { billing: { information }, checkout, }, }) => ({
677
+ const { subscription, status, planId } = yield effects.select(({ subscriptions: { billing: { information }, checkout, }, }) => ({
662
678
  subscription: information.subscription,
663
679
  status: checkout.status,
664
- checkoutPlanId: checkout.checkoutPlanId,
680
+ planId: checkout.checkoutPlanId,
665
681
  }));
666
- const subscriptionId = subscription === null || subscription === void 0 ? void 0 : subscription.id;
667
- const subscriptionItemId = (_a = subscription === null || subscription === void 0 ? void 0 : subscription.items[0]) === null || _a === void 0 ? void 0 : _a.id;
668
- if (!checkoutPlanId || !subscriptionId || !subscriptionItemId) {
669
- yield effects.put(actions$2.setState({
682
+ if (!planId || !subscription) {
683
+ yield effects.put(actions$3.setState({
670
684
  loading: false,
671
685
  status: exports.CheckoutStatus.ERROR,
672
686
  }));
673
687
  return;
674
688
  }
675
689
  if (status === exports.CheckoutStatus.CHECKOUT) {
676
- yield effects.put(actions$2.setState({
690
+ yield effects.put(actions$3.setState({
677
691
  loading: true,
678
692
  error: null,
679
693
  }));
680
694
  try {
681
- yield effects.call(restApi.api.subscriptions.updateSubscription, subscriptionId, {
695
+ yield effects.call(restApi.api.subscriptions.updateSubscription, subscription.id, {
682
696
  paymentMethodId,
683
- items: [
684
- {
685
- id: subscriptionItemId,
686
- planId: checkoutPlanId,
687
- },
688
- ],
697
+ planId,
689
698
  });
690
- yield effects.put(actions$2.setState({
699
+ yield effects.put(actions$3.setState({
691
700
  checkoutPlanId: null,
692
701
  loading: false,
693
702
  status: exports.CheckoutStatus.CONFIRM,
694
703
  }));
695
- yield effects.put(actions$2.checkoutEvent(exports.CheckoutEvent.CONFIRMED));
704
+ yield effects.put(actions$3.checkoutEvent(exports.CheckoutEvent.CONFIRMED));
696
705
  }
697
706
  catch (e) {
698
- yield effects.put(actions$2.setState({
707
+ yield effects.put(actions$3.setState({
699
708
  loading: false,
700
709
  error: e.message,
701
710
  status: exports.CheckoutStatus.ERROR,
702
711
  }));
703
- yield effects.put(actions$2.checkoutEvent(exports.CheckoutEvent.ERROR));
712
+ yield effects.put(actions$3.checkoutEvent(exports.CheckoutEvent.ERROR));
704
713
  }
705
714
  }
706
715
  }
707
716
  function* cancelPlan() {
708
717
  const { status } = yield effects.select((state) => state.subscriptions.checkout);
709
718
  if (status === exports.CheckoutStatus.CHECKOUT) {
710
- yield effects.put(actions$2.setState({
719
+ yield effects.put(actions$3.setState({
711
720
  checkoutPlanId: null,
712
721
  loading: false,
713
722
  error: null,
714
723
  status: exports.CheckoutStatus.CANCEL,
715
724
  }));
716
- yield effects.put(actions$2.checkoutEvent(exports.CheckoutEvent.CANCEL));
725
+ yield effects.put(actions$3.checkoutEvent(exports.CheckoutEvent.CANCEL));
717
726
  }
718
727
  }
719
728
  /**
@@ -722,35 +731,35 @@ function* cancelPlan() {
722
731
  function* submitCheckout() {
723
732
  const { paymentProvider } = yield effects.select((state) => state.subscriptions.config.config);
724
733
  if (paymentProvider === exports.PaymentProvider.STRIPE) {
725
- yield effects.put(actions$2.setState({
734
+ yield effects.put(actions$3.setState({
726
735
  loading: true,
727
736
  error: null,
728
737
  }));
729
- yield effects.put(actions$2.checkoutEvent(exports.CheckoutEvent.SUBMITTED));
738
+ yield effects.put(actions$3.checkoutEvent(exports.CheckoutEvent.SUBMITTED));
730
739
  }
731
740
  }
732
741
  function* errorCheckout({ payload }) {
733
- yield effects.put(actions$2.setState({
742
+ yield effects.put(actions$3.setState({
734
743
  loading: false,
735
744
  error: payload,
736
745
  status: exports.CheckoutStatus.ERROR,
737
746
  }));
738
- yield effects.put(actions$2.checkoutEvent(exports.CheckoutEvent.ERROR));
747
+ yield effects.put(actions$3.checkoutEvent(exports.CheckoutEvent.ERROR));
739
748
  }
740
749
  /*********************************
741
750
  * Preview Sagas
742
751
  *********************************/
743
752
  function* checkoutSagasMock() {
744
- yield effects.takeEvery(actions$2.checkoutPlan, checkoutPlan);
745
- yield effects.takeEvery(actions$2.resetCheckout, resetCheckout);
746
- yield effects.takeEvery(actions$2.cancelCheckout, cancelPlan);
753
+ yield effects.takeEvery(actions$3.checkoutPlan, checkoutPlan);
754
+ yield effects.takeEvery(actions$3.resetCheckout, resetCheckout);
755
+ yield effects.takeEvery(actions$3.cancelCheckout, cancelPlan);
747
756
  }
748
757
 
749
758
  function* plansSagas() {
750
- yield effects.takeEvery(actions$7.loadPlans, loadPlans);
759
+ yield effects.takeEvery(actions$8.loadPlans, loadPlans);
751
760
  }
752
761
  function* loadPlans() {
753
- yield effects.put(actions$7.setLoading(true));
762
+ yield effects.put(actions$8.setLoading(true));
754
763
  try {
755
764
  const products = yield effects.call(restApi.api.subscriptions.getSubscriptionPlans);
756
765
  const plans = products.map((item) => {
@@ -764,23 +773,23 @@ function* loadPlans() {
764
773
  recurringInterval: 'month',
765
774
  });
766
775
  });
767
- yield effects.put(actions$7.setState({
776
+ yield effects.put(actions$8.setState({
768
777
  fetching: false,
769
778
  loading: false,
770
779
  plans,
771
780
  }));
772
781
  }
773
782
  catch (e) {
774
- yield effects.put(actions$7.setError(e.message));
783
+ yield effects.put(actions$8.setError(e.message));
775
784
  }
776
785
  }
777
786
  /*********************************
778
787
  * Preview Sagas
779
788
  *********************************/
780
789
  function* loadPlansMock() {
781
- yield effects.put(actions$7.setLoading(true));
790
+ yield effects.put(actions$8.setLoading(true));
782
791
  yield effects.delay(500);
783
- yield effects.put(actions$7.setState({
792
+ yield effects.put(actions$8.setState({
784
793
  fetching: false,
785
794
  loading: false,
786
795
  plans: planResponseMock.map((item) => {
@@ -790,7 +799,7 @@ function* loadPlansMock() {
790
799
  }));
791
800
  }
792
801
  function* plansSagasMock() {
793
- yield effects.takeEvery(actions$7.loadPlans, loadPlansMock);
802
+ yield effects.takeEvery(actions$8.loadPlans, loadPlansMock);
794
803
  }
795
804
 
796
805
  exports.PaymentMethodType = void 0;
@@ -799,11 +808,20 @@ exports.PaymentMethodType = void 0;
799
808
  PaymentMethodType["CARD"] = "card";
800
809
  })(exports.PaymentMethodType || (exports.PaymentMethodType = {}));
801
810
 
811
+ exports.ManagedSubscriptionStatus = void 0;
812
+ (function (ManagedSubscriptionStatus) {
813
+ ManagedSubscriptionStatus["ACTIVE"] = "ACTIVE";
814
+ ManagedSubscriptionStatus["CANCELED"] = "CANCELED";
815
+ ManagedSubscriptionStatus["INCOMPLETE"] = "INCOMPLETE";
816
+ ManagedSubscriptionStatus["EXPIRED"] = "EXPIRED";
817
+ ManagedSubscriptionStatus["TRIALING"] = "TRIALING";
818
+ })(exports.ManagedSubscriptionStatus || (exports.ManagedSubscriptionStatus = {}));
819
+
802
820
  function* configSagas() {
803
- yield effects.takeEvery(actions$6.loadPaymentConfiguration, loadPaymentConfiguration);
821
+ yield effects.takeEvery(actions$7.loadPaymentConfiguration, loadPaymentConfiguration);
804
822
  }
805
823
  function* loadPaymentConfiguration() {
806
- yield effects.put(actions$6.setLoading(true));
824
+ yield effects.put(actions$7.setLoading(true));
807
825
  try {
808
826
  const response = yield effects.call(restApi.api.subscriptions.getPaymentProviders) || [];
809
827
  const stripePaymentProvider = response.find((paymentProvider) => paymentProvider.status === '1' && paymentProvider.providerType === restApi.ProviderType.Stripe);
@@ -811,18 +829,18 @@ function* loadPaymentConfiguration() {
811
829
  yield loadStripePaymentConfiguration();
812
830
  }
813
831
  else {
814
- yield effects.put(actions$6.setError('Payment provider not configured'));
832
+ yield effects.put(actions$7.setError('Payment provider not configured'));
815
833
  }
816
834
  }
817
835
  catch (e) {
818
- yield effects.put(actions$6.setError(e.message));
836
+ yield effects.put(actions$7.setError(e.message));
819
837
  }
820
838
  }
821
839
  function* loadStripePaymentConfiguration() {
822
- yield effects.put(actions$6.setLoading(true));
840
+ yield effects.put(actions$7.setLoading(true));
823
841
  try {
824
842
  const response = yield effects.call(restApi.api.subscriptions.getStripePaymentProviderConfiguration);
825
- yield effects.put(actions$6.setState({
843
+ yield effects.put(actions$7.setState({
826
844
  loading: false,
827
845
  fetching: false,
828
846
  config: {
@@ -832,16 +850,16 @@ function* loadStripePaymentConfiguration() {
832
850
  }));
833
851
  }
834
852
  catch (e) {
835
- yield effects.put(actions$6.setError(e.message));
853
+ yield effects.put(actions$7.setError(e.message));
836
854
  }
837
855
  }
838
856
  /*********************************
839
857
  * Preview Sagas
840
858
  *********************************/
841
859
  function* loadPaymentConfigurationMock() {
842
- yield effects.put(actions$6.setLoading(true));
860
+ yield effects.put(actions$7.setLoading(true));
843
861
  yield effects.delay(500);
844
- yield effects.put(actions$6.setState({
862
+ yield effects.put(actions$7.setState({
845
863
  loading: false,
846
864
  fetching: false,
847
865
  config: {
@@ -851,14 +869,14 @@ function* loadPaymentConfigurationMock() {
851
869
  }));
852
870
  }
853
871
  function* configSagasMock() {
854
- yield effects.takeEvery(actions$6.loadPaymentConfiguration, loadPaymentConfigurationMock);
872
+ yield effects.takeEvery(actions$7.loadPaymentConfiguration, loadPaymentConfigurationMock);
855
873
  }
856
874
 
857
875
  function* subscriptionStripeSagas() {
858
- yield effects.takeEvery(actions$1.createCardSetupIntentSecret, createCardSetupIntentSecret);
876
+ yield effects.takeEvery(actions$2.createCardSetupIntentSecret, createCardSetupIntentSecret);
859
877
  }
860
878
  function* createCardSetupIntentSecret({ payload }) {
861
- yield effects.put(actions$1.setStripeState({
879
+ yield effects.put(actions$2.setStripeState({
862
880
  loading: true,
863
881
  error: null,
864
882
  cardSetupIntentSecret: null
@@ -867,18 +885,36 @@ function* createCardSetupIntentSecret({ payload }) {
867
885
  const { setupIntentSecret } = yield effects.call(restApi.api.subscriptions.createStripePaymentMethodSetupIntentSecret, {
868
886
  paymentMethodId: payload || undefined
869
887
  });
870
- yield effects.put(actions$1.setStripeState({
888
+ yield effects.put(actions$2.setStripeState({
871
889
  cardSetupIntentSecret: setupIntentSecret,
872
890
  loading: false
873
891
  }));
874
892
  }
893
+ catch (e) {
894
+ yield effects.put(actions$2.setError(e.message));
895
+ }
896
+ }
897
+
898
+ function* loadManagedSubscriptions() {
899
+ yield effects.put(actions$1.setLoading(true));
900
+ try {
901
+ const managedSubscriptions = yield effects.call(restApi.api.subscriptions.getManagedSubscriptions);
902
+ yield effects.put(actions$1.setState({
903
+ fetching: false,
904
+ loading: false,
905
+ managedSubscriptions,
906
+ }));
907
+ }
875
908
  catch (e) {
876
909
  yield effects.put(actions$1.setError(e.message));
877
910
  }
911
+ }
912
+ function* managedSubscriptionsSagas() {
913
+ yield effects.takeEvery(actions$1.loadManagedSubscriptions, loadManagedSubscriptions);
878
914
  }
879
915
 
880
916
  function* sagas() {
881
- yield effects.all([effects.call(billingSagas), effects.call(checkoutSagas), effects.call(plansSagas), effects.call(configSagas), effects.call(subscriptionStripeSagas)]);
917
+ yield effects.all([effects.call(billingSagas), effects.call(checkoutSagas), effects.call(plansSagas), effects.call(configSagas), effects.call(subscriptionStripeSagas), effects.call(managedSubscriptionsSagas)]);
882
918
  }
883
919
  function* mockSagas() {
884
920
  yield effects.all([effects.call(billingSagasMock), effects.call(checkoutSagasMock), effects.call(plansSagasMock), effects.call(configSagasMock)]);