@techstuff-dev/foundation-api-utils 1.24.0 → 1.26.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.
- package/dist/@types/lib/hooks/index.d.ts +24 -16
- package/dist/@types/lib/services/cart/slice.d.ts +155 -0
- package/dist/@types/lib/services/content/content.interfaces.d.ts +59 -3
- package/dist/@types/lib/services/index.d.ts +1 -0
- package/dist/@types/lib/services/payment/index.d.ts +563 -39
- package/dist/@types/lib/store/index.d.ts +60 -40
- package/dist/@types/lib/utils/dataFormat/index.d.ts +2 -1
- package/dist/@types/lib/utils/helpers/index.d.ts +12 -0
- package/dist/index.esm.js +201 -46
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +220 -44
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { fetchBaseQuery, createApi } from '@reduxjs/toolkit/query/react';
|
|
2
2
|
import { Auth } from 'aws-amplify';
|
|
3
|
-
import { createSlice, combineSlices, configureStore } from '@reduxjs/toolkit';
|
|
3
|
+
import { createSlice, createSelector, combineSlices, configureStore } from '@reduxjs/toolkit';
|
|
4
4
|
import { jwtDecode } from 'jwt-decode';
|
|
5
5
|
import { useSelector, useDispatch, useStore } from 'react-redux';
|
|
6
6
|
import { useMemo } from 'react';
|
|
@@ -73,13 +73,23 @@ function __generator(thisArg, body) {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
function __spreadArray(to, from, pack) {
|
|
77
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
78
|
+
if (ar || !(i in from)) {
|
|
79
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
80
|
+
ar[i] = from[i];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
84
|
+
}
|
|
85
|
+
|
|
76
86
|
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
77
87
|
var e = new Error(message);
|
|
78
88
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
79
89
|
};
|
|
80
90
|
|
|
81
|
-
var _a$
|
|
82
|
-
var initialState = {
|
|
91
|
+
var _a$2, _b$2;
|
|
92
|
+
var initialState$1 = {
|
|
83
93
|
authenticated: false,
|
|
84
94
|
verifying: false,
|
|
85
95
|
user: {
|
|
@@ -103,29 +113,13 @@ var initialState = {
|
|
|
103
113
|
email: '',
|
|
104
114
|
sub: '',
|
|
105
115
|
},
|
|
106
|
-
// creating: {
|
|
107
|
-
// details: '',
|
|
108
|
-
// payment: '',
|
|
109
|
-
// },
|
|
110
116
|
loading: false,
|
|
111
117
|
error: false,
|
|
112
118
|
session: undefined,
|
|
113
119
|
};
|
|
114
|
-
// interface AuthReducers {
|
|
115
|
-
// setCredentials: (
|
|
116
|
-
// state: AuthState,
|
|
117
|
-
// data: {
|
|
118
|
-
// payload: any;
|
|
119
|
-
// type: string;
|
|
120
|
-
// },
|
|
121
|
-
// ) => AuthState;
|
|
122
|
-
// resetCreating: (state: AuthState) => void;
|
|
123
|
-
// updateSubscription: (state: AuthState, data: any) => void;
|
|
124
|
-
// logout: () => void;
|
|
125
|
-
// }
|
|
126
120
|
var authSlice = createSlice({
|
|
127
121
|
name: 'auth',
|
|
128
|
-
initialState: initialState,
|
|
122
|
+
initialState: initialState$1,
|
|
129
123
|
reducers: {
|
|
130
124
|
setCredentials: function (state, data) {
|
|
131
125
|
return __assign(__assign({}, state), { session: data.payload.accessToken, authenticated: true, verifying: true, user: __assign(__assign({}, state.user), data.payload) });
|
|
@@ -139,15 +133,13 @@ var authSlice = createSlice({
|
|
|
139
133
|
updateSubscription: function (state, data) {
|
|
140
134
|
return __assign(__assign({}, state), { user: __assign(__assign({}, state.user), { details: __assign(__assign({}, state.user.details), { customerId: data.payload.customerId, subscription: data.payload.subscription, subscriptionDetails: data.payload.subscriptionDetails }) }) });
|
|
141
135
|
},
|
|
142
|
-
logout: function () { return initialState; },
|
|
136
|
+
logout: function () { return initialState$1; },
|
|
143
137
|
},
|
|
144
138
|
selectors: {
|
|
145
139
|
isAuthenticated: function (auth) { return auth.authenticated; },
|
|
146
140
|
selectAccessToken: function (auth) { return auth.user.accessToken; },
|
|
147
141
|
selectRefreshToken: function (auth) { return auth.user.refreshToken; },
|
|
148
142
|
selectCurrentUser: function (auth) { return auth.user.details; },
|
|
149
|
-
// selectUserCreating: (auth) => auth.creating,
|
|
150
|
-
// selectUserCreatingDetails: (auth) => auth.creating.details,
|
|
151
143
|
isVerifying: function (auth) { return auth.verifying; },
|
|
152
144
|
getUserSession: function (auth) { return (auth.authenticated ? auth.session : false); },
|
|
153
145
|
selectCurrentUserSub: function (auth) { return auth.user.sub; },
|
|
@@ -174,12 +166,9 @@ var authSlice = createSlice({
|
|
|
174
166
|
},
|
|
175
167
|
});
|
|
176
168
|
// Action creators are generated for each case reducer function.
|
|
177
|
-
var setCredentials = (_a$
|
|
169
|
+
var setCredentials = (_a$2 = authSlice.actions, _a$2.setCredentials), resetCreating = _a$2.resetCreating, logout = _a$2.logout, updateSubscription = _a$2.updateSubscription;
|
|
178
170
|
// Selectors returned by `slice.selectors` take the root state as their first argument.
|
|
179
|
-
var isAuthenticated = (_b$
|
|
180
|
-
// selectUserCreating,
|
|
181
|
-
// selectUserCreatingDetails,
|
|
182
|
-
isVerifying = _b$1.isVerifying, getUserSession = _b$1.getUserSession, selectCurrentUserSub = _b$1.selectCurrentUserSub, selectCurrentUserRefreshToken = _b$1.selectCurrentUserRefreshToken, selectUserTokens = _b$1.selectUserTokens, selectUserSubscriptionStatus = _b$1.selectUserSubscriptionStatus, selectSubscription = _b$1.selectSubscription, selectSubscriptionPrice = _b$1.selectSubscriptionPrice;
|
|
171
|
+
var isAuthenticated = (_b$2 = authSlice.selectors, _b$2.isAuthenticated), selectAccessToken = _b$2.selectAccessToken, selectRefreshToken = _b$2.selectRefreshToken, selectCurrentUser = _b$2.selectCurrentUser, isVerifying = _b$2.isVerifying, getUserSession = _b$2.getUserSession, selectCurrentUserSub = _b$2.selectCurrentUserSub, selectCurrentUserRefreshToken = _b$2.selectCurrentUserRefreshToken, selectUserTokens = _b$2.selectUserTokens, selectUserSubscriptionStatus = _b$2.selectUserSubscriptionStatus, selectSubscription = _b$2.selectSubscription, selectSubscriptionPrice = _b$2.selectSubscriptionPrice;
|
|
183
172
|
authSlice.reducer;
|
|
184
173
|
|
|
185
174
|
// TODO: typing.
|
|
@@ -662,8 +651,8 @@ function formatConfig(data) {
|
|
|
662
651
|
name: (_r = (_q = item === null || item === void 0 ? void 0 : item._source) === null || _q === void 0 ? void 0 : _q.name) === null || _r === void 0 ? void 0 : _r[0],
|
|
663
652
|
price: (_t = (_s = item === null || item === void 0 ? void 0 : item._source) === null || _s === void 0 ? void 0 : _s.price) === null || _t === void 0 ? void 0 : _t[0],
|
|
664
653
|
video: (_v = (_u = item === null || item === void 0 ? void 0 : item._source) === null || _u === void 0 ? void 0 : _u.video) === null || _v === void 0 ? void 0 : _v[0],
|
|
665
|
-
|
|
666
|
-
|
|
654
|
+
imageHomepage: (_x = (_w = item === null || item === void 0 ? void 0 : item._source) === null || _w === void 0 ? void 0 : _w.image_homepage) === null || _x === void 0 ? void 0 : _x[0],
|
|
655
|
+
imageSectionBanner: (_z = (_y = item === null || item === void 0 ? void 0 : item._source) === null || _y === void 0 ? void 0 : _y.image_section_banner) === null || _z === void 0 ? void 0 : _z[0],
|
|
667
656
|
};
|
|
668
657
|
});
|
|
669
658
|
}
|
|
@@ -774,15 +763,46 @@ var formatLongform = function (data) {
|
|
|
774
763
|
};
|
|
775
764
|
});
|
|
776
765
|
};
|
|
766
|
+
var formatMediaItem = function (data) {
|
|
767
|
+
return data.map(function (item) {
|
|
768
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18;
|
|
769
|
+
return {
|
|
770
|
+
changed: (_b = (_a = item === null || item === void 0 ? void 0 : item._source) === null || _a === void 0 ? void 0 : _a.changed) === null || _b === void 0 ? void 0 : _b[0],
|
|
771
|
+
created: (_d = (_c = item === null || item === void 0 ? void 0 : item._source) === null || _c === void 0 ? void 0 : _c.created) === null || _d === void 0 ? void 0 : _d[0],
|
|
772
|
+
image: (_f = (_e = item === null || item === void 0 ? void 0 : item._source) === null || _e === void 0 ? void 0 : _e.image) === null || _f === void 0 ? void 0 : _f[0],
|
|
773
|
+
customThumbnail: (_h = (_g = item === null || item === void 0 ? void 0 : item._source) === null || _g === void 0 ? void 0 : _g.custom_thumbnail) === null || _h === void 0 ? void 0 : _h[0],
|
|
774
|
+
price: (_k = (_j = item === null || item === void 0 ? void 0 : item._source) === null || _j === void 0 ? void 0 : _j.price) === null || _k === void 0 ? void 0 : _k[0],
|
|
775
|
+
priceTwoYear: (_m = (_l = item === null || item === void 0 ? void 0 : item._source) === null || _l === void 0 ? void 0 : _l.price_2_year) === null || _m === void 0 ? void 0 : _m[0],
|
|
776
|
+
revisionTimestamp: (_p = (_o = item === null || item === void 0 ? void 0 : item._source) === null || _o === void 0 ? void 0 : _o.revision_timestamp) === null || _p === void 0 ? void 0 : _p[0],
|
|
777
|
+
sku: (_r = (_q = item === null || item === void 0 ? void 0 : item._source) === null || _q === void 0 ? void 0 : _q.sku) === null || _r === void 0 ? void 0 : _r[0],
|
|
778
|
+
status: (_t = (_s = item === null || item === void 0 ? void 0 : item._source) === null || _s === void 0 ? void 0 : _s.status) === null || _t === void 0 ? void 0 : _t[0],
|
|
779
|
+
uuid: (_v = (_u = item === null || item === void 0 ? void 0 : item._source) === null || _u === void 0 ? void 0 : _u.uuid) === null || _v === void 0 ? void 0 : _v[0],
|
|
780
|
+
description: (_x = (_w = item === null || item === void 0 ? void 0 : item._source) === null || _w === void 0 ? void 0 : _w.description) === null || _x === void 0 ? void 0 : _x[0],
|
|
781
|
+
transcript: (_z = (_y = item === null || item === void 0 ? void 0 : item._source) === null || _y === void 0 ? void 0 : _y.transcript) === null || _z === void 0 ? void 0 : _z[0],
|
|
782
|
+
entities: (_0 = item === null || item === void 0 ? void 0 : item._source) === null || _0 === void 0 ? void 0 : _0.entities,
|
|
783
|
+
phrases: (_1 = item === null || item === void 0 ? void 0 : item._source) === null || _1 === void 0 ? void 0 : _1.phrases,
|
|
784
|
+
video: (_3 = (_2 = item === null || item === void 0 ? void 0 : item._source) === null || _2 === void 0 ? void 0 : _2.video) === null || _3 === void 0 ? void 0 : _3[0],
|
|
785
|
+
title: (_5 = (_4 = item === null || item === void 0 ? void 0 : item._source) === null || _4 === void 0 ? void 0 : _4.title) === null || _5 === void 0 ? void 0 : _5[0],
|
|
786
|
+
generatedTitle: (_7 = (_6 = item === null || item === void 0 ? void 0 : item._source) === null || _6 === void 0 ? void 0 : _6.generated_title) === null || _7 === void 0 ? void 0 : _7[0],
|
|
787
|
+
projectPricing: (_9 = (_8 = item === null || item === void 0 ? void 0 : item._source) === null || _8 === void 0 ? void 0 : _8.project_pricing) === null || _9 === void 0 ? void 0 : _9[0],
|
|
788
|
+
related_items: (_10 = item === null || item === void 0 ? void 0 : item._source) === null || _10 === void 0 ? void 0 : _10.related_uuids,
|
|
789
|
+
franchises: (_11 = item === null || item === void 0 ? void 0 : item._source) === null || _11 === void 0 ? void 0 : _11.franchise_name,
|
|
790
|
+
franchisesIds: (_12 = item === null || item === void 0 ? void 0 : item._source) === null || _12 === void 0 ? void 0 : _12.franchise_tid,
|
|
791
|
+
original: (_14 = (_13 = item === null || item === void 0 ? void 0 : item._source) === null || _13 === void 0 ? void 0 : _13.original) === null || _14 === void 0 ? void 0 : _14[0],
|
|
792
|
+
script: (_16 = (_15 = item === null || item === void 0 ? void 0 : item._source) === null || _15 === void 0 ? void 0 : _15.script) === null || _16 === void 0 ? void 0 : _16[0],
|
|
793
|
+
hideThumbnailTitle: (_18 = (_17 = item === null || item === void 0 ? void 0 : item._source) === null || _17 === void 0 ? void 0 : _17.hide_thumbnail_title) === null || _18 === void 0 ? void 0 : _18[0],
|
|
794
|
+
};
|
|
795
|
+
});
|
|
796
|
+
};
|
|
777
797
|
|
|
778
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
798
|
+
var _a$1, _b$1, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
779
799
|
// Render the store based on the environment.
|
|
780
800
|
var isWeb = process.env.NEXT_PUBLIC_WEB_APP;
|
|
781
801
|
var ENV = isWeb ? process.env : require('react-native-config').default;
|
|
782
802
|
// export const ENV = process.env;
|
|
783
|
-
((_a = process.env) === null || _a === void 0 ? void 0 : _a.NEXT_PUBLIC_API_PREFIX) || ENV.API_PREFIX;
|
|
803
|
+
((_a$1 = process.env) === null || _a$1 === void 0 ? void 0 : _a$1.NEXT_PUBLIC_API_PREFIX) || ENV.API_PREFIX;
|
|
784
804
|
// Auth specific API
|
|
785
|
-
var API_AUTH_PREFIX = ((_b = process.env) === null || _b === void 0 ? void 0 : _b.NEXT_PUBLIC_API_AUTH_PREFIX) || ENV.API_AUTH_PREFIX;
|
|
805
|
+
var API_AUTH_PREFIX = ((_b$1 = process.env) === null || _b$1 === void 0 ? void 0 : _b$1.NEXT_PUBLIC_API_AUTH_PREFIX) || ENV.API_AUTH_PREFIX;
|
|
786
806
|
// Payments specific API
|
|
787
807
|
var API_PAYMENTS_PREFIX = ((_c = process.env) === null || _c === void 0 ? void 0 : _c.NEXT_PUBLIC_API_PAYMENTS_PREFIX) || ENV.API_PAYMENTS_PREFIX;
|
|
788
808
|
((_d = process.env) === null || _d === void 0 ? void 0 : _d.NEXT_PUBLIC_APP_BASE_URL) || ENV.APP_BASE_URL;
|
|
@@ -1189,7 +1209,7 @@ var paymentApi = createApi({
|
|
|
1189
1209
|
}); },
|
|
1190
1210
|
credentials: 'include',
|
|
1191
1211
|
}),
|
|
1192
|
-
tagTypes: ['UserSubscription', 'Plans'],
|
|
1212
|
+
tagTypes: ['UserSubscription', 'Plans', 'TaxRates', 'PromoCodes'],
|
|
1193
1213
|
// keepUnusedDataFor: 300,
|
|
1194
1214
|
endpoints: function (builder) { return ({
|
|
1195
1215
|
/**
|
|
@@ -1211,10 +1231,154 @@ var paymentApi = createApi({
|
|
|
1211
1231
|
query: function () { return '/payment/plans'; },
|
|
1212
1232
|
providesTags: ['Plans'],
|
|
1213
1233
|
}),
|
|
1234
|
+
getTaxRates: builder.query({
|
|
1235
|
+
query: function () { return ({
|
|
1236
|
+
url: '/payment/tax-rates',
|
|
1237
|
+
method: 'GET',
|
|
1238
|
+
}); },
|
|
1239
|
+
providesTags: ['TaxRates'],
|
|
1240
|
+
}),
|
|
1241
|
+
checkPromoCode: builder.query({
|
|
1242
|
+
query: function (promoCode) { return ({
|
|
1243
|
+
url: "/payment/coupon/".concat(promoCode),
|
|
1244
|
+
method: 'GET',
|
|
1245
|
+
}); },
|
|
1246
|
+
providesTags: ['PromoCodes'],
|
|
1247
|
+
}),
|
|
1214
1248
|
}); },
|
|
1215
1249
|
});
|
|
1216
1250
|
// Export hooks for usage in functional components.
|
|
1217
|
-
paymentApi.useCheckUserSubscriptionQuery; paymentApi.useLazyCheckUserSubscriptionQuery; paymentApi.useGetPaymentPlansQuery; paymentApi.useLazyGetPaymentPlansQuery;
|
|
1251
|
+
paymentApi.useCheckUserSubscriptionQuery; paymentApi.useLazyCheckUserSubscriptionQuery; paymentApi.useGetPaymentPlansQuery; paymentApi.useLazyGetPaymentPlansQuery; paymentApi.useGetTaxRatesQuery; paymentApi.useLazyGetTaxRatesQuery; paymentApi.useCheckPromoCodeQuery; paymentApi.useLazyCheckPromoCodeQuery;
|
|
1252
|
+
|
|
1253
|
+
function applyCoupon(coupon, netTotal) {
|
|
1254
|
+
var discountedAmount = netTotal * (Number(coupon.discount) / 100);
|
|
1255
|
+
var discountedTotal = netTotal - discountedAmount;
|
|
1256
|
+
var data = __assign(__assign({}, coupon), { discountedTotal: discountedTotal, discountedAmount: discountedAmount });
|
|
1257
|
+
return data;
|
|
1258
|
+
}
|
|
1259
|
+
function applyTax(taxRate, netTotal) {
|
|
1260
|
+
var taxAmount = netTotal * (taxRate.percentage / 100);
|
|
1261
|
+
return taxAmount;
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
var _a, _b;
|
|
1265
|
+
var initialState = {
|
|
1266
|
+
addedItems: [],
|
|
1267
|
+
netTotal: 0,
|
|
1268
|
+
taxRate: {
|
|
1269
|
+
country: 'none',
|
|
1270
|
+
percentage: 0,
|
|
1271
|
+
},
|
|
1272
|
+
taxAmount: 0,
|
|
1273
|
+
promoCode: {
|
|
1274
|
+
code: '',
|
|
1275
|
+
name: '',
|
|
1276
|
+
discount: '',
|
|
1277
|
+
discountedAmount: 0,
|
|
1278
|
+
},
|
|
1279
|
+
grossTotal: 0,
|
|
1280
|
+
loading: false,
|
|
1281
|
+
error: false,
|
|
1282
|
+
open: false,
|
|
1283
|
+
};
|
|
1284
|
+
var cartSlice = createSlice({
|
|
1285
|
+
name: 'cart',
|
|
1286
|
+
initialState: initialState,
|
|
1287
|
+
reducers: {
|
|
1288
|
+
setTaxRate: function (state, action) {
|
|
1289
|
+
var netTotal = state.netTotal, promoCode = state.promoCode;
|
|
1290
|
+
var currentTotal = netTotal;
|
|
1291
|
+
if (promoCode === null || promoCode === void 0 ? void 0 : promoCode.code) {
|
|
1292
|
+
var data = applyCoupon(promoCode, currentTotal);
|
|
1293
|
+
currentTotal = data.discountedTotal;
|
|
1294
|
+
}
|
|
1295
|
+
var taxAmount = applyTax(action.payload, currentTotal);
|
|
1296
|
+
var grossTotal = currentTotal + taxAmount;
|
|
1297
|
+
return __assign(__assign({}, state), { taxRate: action.payload, taxAmount: taxAmount, grossTotal: grossTotal });
|
|
1298
|
+
},
|
|
1299
|
+
resetTaxRate: function (state, action) {
|
|
1300
|
+
console.log('resetTaxRate', action);
|
|
1301
|
+
return __assign(__assign({}, state), { taxRate: {
|
|
1302
|
+
country: 'none',
|
|
1303
|
+
percentage: 0,
|
|
1304
|
+
}, taxAmount: 0 });
|
|
1305
|
+
},
|
|
1306
|
+
setPromoCode: function (state, action) {
|
|
1307
|
+
var netTotal = state.netTotal, taxRate = state.taxRate;
|
|
1308
|
+
var data = applyCoupon(action.payload, netTotal);
|
|
1309
|
+
var taxAmount = applyTax(taxRate, data.discountedTotal);
|
|
1310
|
+
var grossTotal = data.discountedTotal + taxAmount;
|
|
1311
|
+
return __assign(__assign({}, state), { promoCode: {
|
|
1312
|
+
code: data.code,
|
|
1313
|
+
name: data.code,
|
|
1314
|
+
discount: data.discount,
|
|
1315
|
+
discountedAmount: data.discountedAmount,
|
|
1316
|
+
}, taxAmount: taxAmount, grossTotal: grossTotal });
|
|
1317
|
+
},
|
|
1318
|
+
removePromoCode: function (state, action) {
|
|
1319
|
+
console.log('removePromoCode', action);
|
|
1320
|
+
var netTotal = state.netTotal, taxRate = state.taxRate;
|
|
1321
|
+
var taxAmount = applyTax(taxRate, netTotal);
|
|
1322
|
+
var grossTotal = netTotal + taxAmount;
|
|
1323
|
+
return __assign(__assign({}, state), { promoCode: initialState.promoCode, taxAmount: taxAmount, grossTotal: grossTotal });
|
|
1324
|
+
},
|
|
1325
|
+
addToCart: function (state, action) {
|
|
1326
|
+
var _a = action.payload, options = _a.options, item = _a.item;
|
|
1327
|
+
var newTotal = state.netTotal + options.selectedPrice;
|
|
1328
|
+
var taxAmount = newTotal * (state.taxRate.percentage / 100);
|
|
1329
|
+
var grossTotal = newTotal + taxAmount;
|
|
1330
|
+
var addItem = item ? __assign(__assign({}, item), { options: options }) : null;
|
|
1331
|
+
if (!addItem) {
|
|
1332
|
+
return state;
|
|
1333
|
+
}
|
|
1334
|
+
var addedItems = __spreadArray(__spreadArray([], state.addedItems, true), [addItem], false);
|
|
1335
|
+
return __assign(__assign({}, state), { addedItems: addedItems, netTotal: newTotal, grossTotal: grossTotal });
|
|
1336
|
+
},
|
|
1337
|
+
updateCart: function (state, action) {
|
|
1338
|
+
var options = action.payload.options;
|
|
1339
|
+
return __assign(__assign({}, state), { addedItems: state.addedItems.map(function (item) {
|
|
1340
|
+
return item && __assign(__assign({}, item), { options: options });
|
|
1341
|
+
}) });
|
|
1342
|
+
},
|
|
1343
|
+
removeFromCart: function (state, action) {
|
|
1344
|
+
var _a = action.payload, id = _a.id, price = _a.price;
|
|
1345
|
+
var newTotal = state.netTotal - price;
|
|
1346
|
+
var taxAmount = newTotal * (state.taxRate.percentage / 100);
|
|
1347
|
+
var grossTotal = newTotal + taxAmount;
|
|
1348
|
+
return __assign(__assign({}, state), { addedItems: state.addedItems.filter(function (item) { return item && item.uuid !== id; }), netTotal: newTotal, grossTotal: grossTotal });
|
|
1349
|
+
},
|
|
1350
|
+
toggleCart: function (state, action) {
|
|
1351
|
+
return __assign(__assign({}, state), { open: action.payload });
|
|
1352
|
+
},
|
|
1353
|
+
emptyCart: function () { return initialState; },
|
|
1354
|
+
},
|
|
1355
|
+
selectors: {
|
|
1356
|
+
selectMediaInCart: function (cart) { return cart.addedItems; },
|
|
1357
|
+
selectCartTotal: function (cart) { return cart.grossTotal; },
|
|
1358
|
+
selectCartNetTotal: function (cart) { return cart.netTotal; },
|
|
1359
|
+
selectCartTaxRate: function (cart) { return cart.taxRate; },
|
|
1360
|
+
selectCartTaxAmount: function (cart) { return cart.taxAmount; },
|
|
1361
|
+
selectCartCount: function (cart) { return cart.addedItems.length; },
|
|
1362
|
+
selectCartStatus: function (cart) { return cart.open; },
|
|
1363
|
+
selectPromoCode: function (cart) { return cart.promoCode; },
|
|
1364
|
+
},
|
|
1365
|
+
});
|
|
1366
|
+
var setTaxRate = (_a = cartSlice.actions, _a.setTaxRate), resetTaxRate = _a.resetTaxRate, setPromoCode = _a.setPromoCode, removePromoCode = _a.removePromoCode, addToCart = _a.addToCart, updateCart = _a.updateCart, removeFromCart = _a.removeFromCart, emptyCart = _a.emptyCart, toggleCart = _a.toggleCart;
|
|
1367
|
+
var selectMediaInCart = (_b = cartSlice.selectors, _b.selectMediaInCart), selectCartTotal = _b.selectCartTotal, selectCartNetTotal = _b.selectCartNetTotal, selectCartTaxRate = _b.selectCartTaxRate, selectCartTaxAmount = _b.selectCartTaxAmount, selectCartCount = _b.selectCartCount, selectCartStatus = _b.selectCartStatus, selectPromoCode = _b.selectPromoCode;
|
|
1368
|
+
var selectCartItems = createSelector([selectMediaInCart], function (items) {
|
|
1369
|
+
return items.map(function (item) {
|
|
1370
|
+
return {
|
|
1371
|
+
title: item.title || item.generatedTitle,
|
|
1372
|
+
file: "".concat(item.sku, ".mp4"),
|
|
1373
|
+
options: item.options,
|
|
1374
|
+
script: item.script,
|
|
1375
|
+
};
|
|
1376
|
+
});
|
|
1377
|
+
});
|
|
1378
|
+
var selectCartItemsIds = createSelector([selectMediaInCart], function (items) {
|
|
1379
|
+
return items.map(function (item) { return item.uuid; });
|
|
1380
|
+
});
|
|
1381
|
+
cartSlice.reducer;
|
|
1218
1382
|
|
|
1219
1383
|
var useLoggedIn = function () {
|
|
1220
1384
|
var isLoggedIn = useSelector(isAuthenticated);
|
|
@@ -1247,13 +1411,7 @@ function createPersistStorage() {
|
|
|
1247
1411
|
}
|
|
1248
1412
|
|
|
1249
1413
|
// Infer the `RootState` type from the root reducer
|
|
1250
|
-
var rootReducer = combineSlices(authSlice, authApi, contentApi, paymentApi);
|
|
1251
|
-
// export interface RootState {
|
|
1252
|
-
// [authSlice.name]: ReturnType<typeof authSlice.reducer>;
|
|
1253
|
-
// [authApi.reducerPath]: ReturnType<typeof authApi.reducer>;
|
|
1254
|
-
// [contentApi.reducerPath]: ReturnType<typeof contentApi.reducer>;
|
|
1255
|
-
// [paymentApi.reducerPath]: ReturnType<typeof paymentApi.reducer>;
|
|
1256
|
-
// }
|
|
1414
|
+
var rootReducer = combineSlices(cartSlice, authSlice, authApi, contentApi, paymentApi);
|
|
1257
1415
|
// eg. ['auth', 'creating'], or an empty array if you don't want to whitelist any.
|
|
1258
1416
|
// const storageWhiteList: string[] = [];
|
|
1259
1417
|
var storageBlackList = [];
|
|
@@ -1311,9 +1469,6 @@ var makeNativeStore = function () {
|
|
|
1311
1469
|
};
|
|
1312
1470
|
var makeWebStore = function () {
|
|
1313
1471
|
var storage = createPersistStorage();
|
|
1314
|
-
// if (process.env.NEXT_PUBLIC_STORE_BLACKLIST) {
|
|
1315
|
-
// storageBlackList.push(process.env.NEXT_PUBLIC_STORE_BLACKLIST);
|
|
1316
|
-
// }
|
|
1317
1472
|
storageBlackList.push(paymentApi.reducerPath, authApi.reducerPath, contentApi.reducerPath);
|
|
1318
1473
|
var persistConfig = {
|
|
1319
1474
|
key: 'root',
|
|
@@ -1351,5 +1506,5 @@ var makeWebStore = function () {
|
|
|
1351
1506
|
var nativeStore = !isWeb && makeNativeStore();
|
|
1352
1507
|
var webStore = isWeb && makeWebStore();
|
|
1353
1508
|
|
|
1354
|
-
export { authApi, authSlice, contentApi, formatAuthSession, formatChallengeDays, formatChallenges, formatConfig, formatFaqs, formatFedaratedSession, formatGuests, formatLongform, formatPages, formatPress, formatPromos, formatSchedule, formatSeasons, formatSecondsToISO8601Duration, formatSectionItems, formatSectionPanels, formatSections, formatSeries, formatSettings, formatShortform, formatSocialAuthSession, formatTaxonomies, formatUserPayload, formatVideos, formatWorkout, getUserSession, isAuthenticated, isVerifying, logout, nativeStore, paymentApi, resetCreating, selectAccessToken, selectCurrentUser, selectCurrentUserRefreshToken, selectCurrentUserSub, selectRefreshToken, selectSubscription, selectSubscriptionPrice, selectUserSubscriptionStatus, selectUserTokens, setCredentials, updateSubscription, useAppDispatch, useAppSelector, useAppStore, useForgottenPasswordMutation, useGetUserInfoQuery, useLazyGetUserInfoQuery, useLazyVerifyUserAttributesQuery, useLazyVerifyUserQuery, useLazyVerifyUserResendQuery, useLoggedIn, useRegisterMutation, useResetPasswordAuthMutation, useResetPasswordMutation, useUpdateUserInfoMutation, useUpdateUserMutation, useVerifyUserAttributesQuery, useVerifyUserQuery, useVerifyUserResendQuery, webStore };
|
|
1509
|
+
export { addToCart, authApi, authSlice, cartSlice, contentApi, emptyCart, formatAuthSession, formatChallengeDays, formatChallenges, formatConfig, formatFaqs, formatFedaratedSession, formatGuests, formatLongform, formatMediaItem, formatPages, formatPress, formatPromos, formatSchedule, formatSeasons, formatSecondsToISO8601Duration, formatSectionItems, formatSectionPanels, formatSections, formatSeries, formatSettings, formatShortform, formatSocialAuthSession, formatTaxonomies, formatUserPayload, formatVideos, formatWorkout, getUserSession, isAuthenticated, isVerifying, logout, nativeStore, paymentApi, removeFromCart, removePromoCode, resetCreating, resetTaxRate, selectAccessToken, selectCartCount, selectCartItems, selectCartItemsIds, selectCartNetTotal, selectCartStatus, selectCartTaxAmount, selectCartTaxRate, selectCartTotal, selectCurrentUser, selectCurrentUserRefreshToken, selectCurrentUserSub, selectMediaInCart, selectPromoCode, selectRefreshToken, selectSubscription, selectSubscriptionPrice, selectUserSubscriptionStatus, selectUserTokens, setCredentials, setPromoCode, setTaxRate, toggleCart, updateCart, updateSubscription, useAppDispatch, useAppSelector, useAppStore, useForgottenPasswordMutation, useGetUserInfoQuery, useLazyGetUserInfoQuery, useLazyVerifyUserAttributesQuery, useLazyVerifyUserQuery, useLazyVerifyUserResendQuery, useLoggedIn, useRegisterMutation, useResetPasswordAuthMutation, useResetPasswordMutation, useUpdateUserInfoMutation, useUpdateUserMutation, useVerifyUserAttributesQuery, useVerifyUserQuery, useVerifyUserResendQuery, webStore };
|
|
1355
1510
|
//# sourceMappingURL=index.esm.js.map
|