@techstuff-dev/foundation-api-utils 1.13.0 → 1.15.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 +72 -72
- package/dist/@types/lib/services/auth/index.d.ts +17 -16
- package/dist/@types/lib/services/content/content.interfaces.d.ts +60 -20
- package/dist/@types/lib/services/content/index.d.ts +2 -2
- package/dist/@types/lib/services/index.d.ts +1 -0
- package/dist/@types/lib/store/index.d.ts +179 -179
- package/dist/@types/lib/types/index.interfaces.d.ts +1 -1
- package/dist/@types/lib/utils/dataFormat/index.d.ts +16 -49
- package/dist/index.esm.js +144 -92
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +164 -90
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { AuthSession } from '@aws-amplify/core';
|
|
2
|
+
import { User } from '../../types/index.interfaces';
|
|
1
3
|
export declare const formatUserPayload: (payload: UserPayload) => {
|
|
2
4
|
userEmail: string;
|
|
3
5
|
lastName: string;
|
|
@@ -51,7 +53,7 @@ export declare function formatLongform(data: ESLongForm[]): {
|
|
|
51
53
|
image_promo_large: string | undefined;
|
|
52
54
|
image_poster: string | undefined;
|
|
53
55
|
summary: string | undefined;
|
|
54
|
-
created:
|
|
56
|
+
created: number | undefined;
|
|
55
57
|
updated: string | undefined;
|
|
56
58
|
video: string | undefined;
|
|
57
59
|
rating: string | undefined;
|
|
@@ -69,23 +71,14 @@ export declare function formatFaqs(data: ESFaq[]): {
|
|
|
69
71
|
id: string | undefined;
|
|
70
72
|
title: string | undefined;
|
|
71
73
|
answer: string | undefined;
|
|
72
|
-
created:
|
|
73
|
-
updated:
|
|
74
|
-
}[];
|
|
75
|
-
export declare function formatPages(data: ESPage[]): {
|
|
76
|
-
uuid: string | undefined;
|
|
77
|
-
id: string | undefined;
|
|
78
|
-
title: string | undefined;
|
|
79
|
-
body: string | undefined;
|
|
80
|
-
created: string | undefined;
|
|
81
|
-
updated: string | undefined;
|
|
82
|
-
langcode: string | undefined;
|
|
83
|
-
url: string | undefined;
|
|
74
|
+
created: number | undefined;
|
|
75
|
+
updated: number | undefined;
|
|
84
76
|
}[];
|
|
77
|
+
export declare function formatPages(data: ESPage[]): Page[];
|
|
85
78
|
export declare function formatSettings(data: ESSetting[]): {
|
|
86
79
|
uuid: string | undefined;
|
|
87
|
-
created:
|
|
88
|
-
updated:
|
|
80
|
+
created: number | undefined;
|
|
81
|
+
updated: number | undefined;
|
|
89
82
|
status: string | undefined;
|
|
90
83
|
type: string | undefined;
|
|
91
84
|
video: string | undefined;
|
|
@@ -95,8 +88,8 @@ export declare function formatSettings(data: ESSetting[]): {
|
|
|
95
88
|
}[];
|
|
96
89
|
export declare function formatPress(data: ESPress[]): {
|
|
97
90
|
uuid: string | undefined;
|
|
98
|
-
created:
|
|
99
|
-
updated:
|
|
91
|
+
created: number | undefined;
|
|
92
|
+
updated: number | undefined;
|
|
100
93
|
image: string | undefined;
|
|
101
94
|
title: string | undefined;
|
|
102
95
|
}[];
|
|
@@ -104,41 +97,15 @@ export declare function formatGuests(data: ESGuest[]): {
|
|
|
104
97
|
uuid: string | undefined;
|
|
105
98
|
id: string | undefined;
|
|
106
99
|
title: string | undefined;
|
|
107
|
-
updated:
|
|
100
|
+
updated: number | undefined;
|
|
108
101
|
description: string | undefined;
|
|
109
102
|
image: string | undefined;
|
|
110
103
|
display: string | undefined;
|
|
111
104
|
}[];
|
|
112
105
|
export declare function formatVideos(data: ESVideo[]): Video[];
|
|
113
|
-
export declare function formatSections(data: ESSection[]):
|
|
114
|
-
uuid: string | undefined;
|
|
115
|
-
title: string | undefined;
|
|
116
|
-
description: string | undefined;
|
|
117
|
-
image: string | undefined;
|
|
118
|
-
challenge: string | undefined;
|
|
119
|
-
display: string | undefined;
|
|
120
|
-
id: string | undefined;
|
|
121
|
-
}[];
|
|
106
|
+
export declare function formatSections(data: ESSection[]): Section[];
|
|
122
107
|
export declare function formatSchedule(data: ESSchedule[]): Schedule[];
|
|
123
|
-
export declare function formatChallenges(data: ESChallenge[]):
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
image: string | undefined;
|
|
128
|
-
challengeKey: string | undefined;
|
|
129
|
-
created: string | undefined;
|
|
130
|
-
days: string[] | undefined;
|
|
131
|
-
updated: string | undefined;
|
|
132
|
-
purchaseButtonLabel: string | undefined;
|
|
133
|
-
price: string | undefined;
|
|
134
|
-
}[];
|
|
135
|
-
export declare function formatChallengeDays(data: ESChallengeDay[]): {
|
|
136
|
-
uuid: string | undefined;
|
|
137
|
-
title: string | undefined;
|
|
138
|
-
body: string | undefined;
|
|
139
|
-
image: string | undefined;
|
|
140
|
-
created: string | undefined;
|
|
141
|
-
updated: string | undefined;
|
|
142
|
-
video: string | undefined;
|
|
143
|
-
workout: string | undefined;
|
|
144
|
-
}[];
|
|
108
|
+
export declare function formatChallenges(data: ESChallenge[]): Challenge[];
|
|
109
|
+
export declare function formatChallengeDays(data: ESChallengeDay[]): ChallengeDay[];
|
|
110
|
+
export declare function formatSecondsToISO8601Duration(seconds?: number): string;
|
|
111
|
+
export declare function formatAuthSession(session: AuthSession): User;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fetchBaseQuery, createApi } from '@reduxjs/toolkit/query/react';
|
|
2
|
+
import { fetchAuthSession, signOut } from '@aws-amplify/auth';
|
|
2
3
|
import { jwtDecode } from 'jwt-decode';
|
|
3
4
|
import { createSlice, combineSlices, configureStore } from '@reduxjs/toolkit';
|
|
4
5
|
import { useSelector, useDispatch, useStore } from 'react-redux';
|
|
@@ -99,6 +100,7 @@ var initialState = {
|
|
|
99
100
|
accessTokenExpiry: null,
|
|
100
101
|
refreshToken: '',
|
|
101
102
|
email: '',
|
|
103
|
+
sub: '',
|
|
102
104
|
},
|
|
103
105
|
creating: {
|
|
104
106
|
details: '',
|
|
@@ -135,7 +137,7 @@ var authSlice = createSlice({
|
|
|
135
137
|
selectUserCreatingDetails: function (auth) { return auth.creating.details; },
|
|
136
138
|
isVerifying: function (auth) { return auth.verifying; },
|
|
137
139
|
getUserSession: function (auth) { return (auth.authenticated ? auth.session : false); },
|
|
138
|
-
selectCurrentUserSub: function (auth) {
|
|
140
|
+
selectCurrentUserSub: function (auth) { return auth.user.sub; },
|
|
139
141
|
selectCurrentUserRefreshToken: function (auth) { return auth.user.refreshToken; },
|
|
140
142
|
selectUserTokens: function (auth) {
|
|
141
143
|
return {
|
|
@@ -215,30 +217,29 @@ function formatPromos(data) {
|
|
|
215
217
|
});
|
|
216
218
|
}
|
|
217
219
|
function formatWorkout(data) {
|
|
218
|
-
|
|
219
|
-
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
|
|
220
|
+
return data.map(function (item) {
|
|
221
|
+
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;
|
|
220
222
|
return {
|
|
221
223
|
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],
|
|
222
224
|
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],
|
|
223
225
|
uuid: (_f = (_e = item === null || item === void 0 ? void 0 : item._source) === null || _e === void 0 ? void 0 : _e.uuid) === null || _f === void 0 ? void 0 : _f[0],
|
|
224
226
|
description: (_h = (_g = item === null || item === void 0 ? void 0 : item._source) === null || _g === void 0 ? void 0 : _g.description) === null || _h === void 0 ? void 0 : _h[0],
|
|
225
|
-
duration: (_k = (_j = item === null || item === void 0 ? void 0 : item._source) === null || _j === void 0 ? void 0 : _j.
|
|
226
|
-
duration_filter:
|
|
227
|
-
level: (
|
|
228
|
-
published: (
|
|
229
|
-
targeted_section: (
|
|
230
|
-
uid: (
|
|
231
|
-
image: (
|
|
232
|
-
title: (
|
|
233
|
-
video: (
|
|
234
|
-
videoDownload: (
|
|
235
|
-
videoPoster: (
|
|
236
|
-
workoutCategory: (
|
|
237
|
-
workoutType: (
|
|
238
|
-
|
|
227
|
+
duration: (_k = (_j = item === null || item === void 0 ? void 0 : item._source) === null || _j === void 0 ? void 0 : _j.duration_filter) === null || _k === void 0 ? void 0 : _k[0],
|
|
228
|
+
// duration_filter: item?._source?.duration_filter?.[0],
|
|
229
|
+
level: (_m = (_l = item === null || item === void 0 ? void 0 : item._source) === null || _l === void 0 ? void 0 : _l.level) === null || _m === void 0 ? void 0 : _m[0],
|
|
230
|
+
published: (_p = (_o = item === null || item === void 0 ? void 0 : item._source) === null || _o === void 0 ? void 0 : _o.published) === null || _p === void 0 ? void 0 : _p[0],
|
|
231
|
+
targeted_section: (_r = (_q = item === null || item === void 0 ? void 0 : item._source) === null || _q === void 0 ? void 0 : _q.targeted_section) === null || _r === void 0 ? void 0 : _r[0],
|
|
232
|
+
uid: (_t = (_s = item === null || item === void 0 ? void 0 : item._source) === null || _s === void 0 ? void 0 : _s.uid) === null || _t === void 0 ? void 0 : _t[0],
|
|
233
|
+
image: (_v = (_u = item === null || item === void 0 ? void 0 : item._source) === null || _u === void 0 ? void 0 : _u.image) === null || _v === void 0 ? void 0 : _v[0],
|
|
234
|
+
title: (_x = (_w = item === null || item === void 0 ? void 0 : item._source) === null || _w === void 0 ? void 0 : _w.title) === null || _x === void 0 ? void 0 : _x[0],
|
|
235
|
+
video: (_z = (_y = item === null || item === void 0 ? void 0 : item._source) === null || _y === void 0 ? void 0 : _y.video_url) === null || _z === void 0 ? void 0 : _z[0],
|
|
236
|
+
videoDownload: (_1 = (_0 = item === null || item === void 0 ? void 0 : item._source) === null || _0 === void 0 ? void 0 : _0.video_download) === null || _1 === void 0 ? void 0 : _1[0],
|
|
237
|
+
videoPoster: (_3 = (_2 = item === null || item === void 0 ? void 0 : item._source) === null || _2 === void 0 ? void 0 : _2.video_poster) === null || _3 === void 0 ? void 0 : _3[0],
|
|
238
|
+
workoutCategory: (_5 = (_4 = item === null || item === void 0 ? void 0 : item._source) === null || _4 === void 0 ? void 0 : _4.workout_category) === null || _5 === void 0 ? void 0 : _5[0],
|
|
239
|
+
workoutType: (_7 = (_6 = item === null || item === void 0 ? void 0 : item._source) === null || _6 === void 0 ? void 0 : _6.workout_type) === null || _7 === void 0 ? void 0 : _7[0],
|
|
240
|
+
livestreamSection: (_9 = (_8 = item === null || item === void 0 ? void 0 : item._source) === null || _8 === void 0 ? void 0 : _8.livestream_section) === null || _9 === void 0 ? void 0 : _9[0],
|
|
239
241
|
};
|
|
240
242
|
});
|
|
241
|
-
return response;
|
|
242
243
|
}
|
|
243
244
|
function formatSeries(data, channel) {
|
|
244
245
|
var formattedSeriesSelection = data.map(function (series) {
|
|
@@ -379,7 +380,7 @@ function formatGuests(data) {
|
|
|
379
380
|
});
|
|
380
381
|
}
|
|
381
382
|
function formatVideos(data) {
|
|
382
|
-
|
|
383
|
+
return data.map(function (item) {
|
|
383
384
|
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;
|
|
384
385
|
return {
|
|
385
386
|
uuid: (_b = (_a = item === null || item === void 0 ? void 0 : item._source) === null || _a === void 0 ? void 0 : _a.uuid) === null || _b === void 0 ? void 0 : _b[0],
|
|
@@ -391,12 +392,11 @@ function formatVideos(data) {
|
|
|
391
392
|
duration: (_p = (_o = item === null || item === void 0 ? void 0 : item._source) === null || _o === void 0 ? void 0 : _o.duration) === null || _p === void 0 ? void 0 : _p[0],
|
|
392
393
|
section: (_r = (_q = item === null || item === void 0 ? void 0 : item._source) === null || _q === void 0 ? void 0 : _q.section) === null || _r === void 0 ? void 0 : _r[0],
|
|
393
394
|
videoPoster: (_t = (_s = item === null || item === void 0 ? void 0 : item._source) === null || _s === void 0 ? void 0 : _s.video_poster) === null || _t === void 0 ? void 0 : _t[0],
|
|
394
|
-
|
|
395
|
+
video: (_v = (_u = item === null || item === void 0 ? void 0 : item._source) === null || _u === void 0 ? void 0 : _u.video_url) === null || _v === void 0 ? void 0 : _v[0],
|
|
395
396
|
videoDownload: (_x = (_w = item === null || item === void 0 ? void 0 : item._source) === null || _w === void 0 ? void 0 : _w.video_download) === null || _x === void 0 ? void 0 : _x[0],
|
|
396
397
|
sectionId: (_z = (_y = item === null || item === void 0 ? void 0 : item._source) === null || _y === void 0 ? void 0 : _y.section_id) === null || _z === void 0 ? void 0 : _z[0],
|
|
397
398
|
};
|
|
398
399
|
});
|
|
399
|
-
return response;
|
|
400
400
|
}
|
|
401
401
|
function formatSections(data) {
|
|
402
402
|
return data.map(function (item) {
|
|
@@ -511,9 +511,10 @@ function formatSchedule(data) {
|
|
|
511
511
|
}
|
|
512
512
|
function formatChallenges(data) {
|
|
513
513
|
return data.map(function (item) {
|
|
514
|
+
var _a;
|
|
514
515
|
var _source = item._source;
|
|
515
516
|
return {
|
|
516
|
-
uuid: _source
|
|
517
|
+
uuid: (_a = _source === null || _source === void 0 ? void 0 : _source.uuid) === null || _a === void 0 ? void 0 : _a[0],
|
|
517
518
|
title: _source.title && _source.title[0],
|
|
518
519
|
body: _source.body && _source.body[0],
|
|
519
520
|
image: _source.image && _source.image[0],
|
|
@@ -541,6 +542,48 @@ function formatChallengeDays(data) {
|
|
|
541
542
|
};
|
|
542
543
|
});
|
|
543
544
|
}
|
|
545
|
+
function formatSecondsToISO8601Duration(seconds) {
|
|
546
|
+
if (!seconds)
|
|
547
|
+
return '';
|
|
548
|
+
// Calculate hours, minutes, and remaining seconds
|
|
549
|
+
var hours = Math.floor(seconds / 3600);
|
|
550
|
+
var minutes = Math.floor((seconds % 3600) / 60);
|
|
551
|
+
var remainingSeconds = seconds % 60;
|
|
552
|
+
// Build the ISO 8601 duration string
|
|
553
|
+
var duration = 'PT';
|
|
554
|
+
if (hours > 0) {
|
|
555
|
+
duration += "".concat(hours, "H");
|
|
556
|
+
}
|
|
557
|
+
if (minutes > 0) {
|
|
558
|
+
duration += "".concat(minutes, "M");
|
|
559
|
+
}
|
|
560
|
+
if (remainingSeconds > 0 || duration === 'PT') {
|
|
561
|
+
duration += "".concat(remainingSeconds, "S");
|
|
562
|
+
}
|
|
563
|
+
return duration;
|
|
564
|
+
}
|
|
565
|
+
function formatAuthSession(session) {
|
|
566
|
+
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, _19, _20, _21, _22, _23, _24;
|
|
567
|
+
return {
|
|
568
|
+
accessToken: (_a = session === null || session === void 0 ? void 0 : session.tokens) === null || _a === void 0 ? void 0 : _a.accessToken.toString(),
|
|
569
|
+
idToken: (_c = (_b = session === null || session === void 0 ? void 0 : session.tokens) === null || _b === void 0 ? void 0 : _b.idToken) === null || _c === void 0 ? void 0 : _c.toString(),
|
|
570
|
+
refreshToken: undefined,
|
|
571
|
+
accessTokenExpiry: (_f = (_e = (_d = session === null || session === void 0 ? void 0 : session.tokens) === null || _d === void 0 ? void 0 : _d.idToken) === null || _e === void 0 ? void 0 : _e.payload) === null || _f === void 0 ? void 0 : _f.exp,
|
|
572
|
+
expires: (_j = (_h = (_g = session === null || session === void 0 ? void 0 : session.tokens) === null || _g === void 0 ? void 0 : _g.idToken) === null || _h === void 0 ? void 0 : _h.payload) === null || _j === void 0 ? void 0 : _j.exp,
|
|
573
|
+
sub: (_o = (_m = (_l = (_k = session === null || session === void 0 ? void 0 : session.tokens) === null || _k === void 0 ? void 0 : _k.idToken) === null || _l === void 0 ? void 0 : _l.payload) === null || _m === void 0 ? void 0 : _m['cognito:username']) === null || _o === void 0 ? void 0 : _o.toString(),
|
|
574
|
+
details: {
|
|
575
|
+
userEmail: (_s = (_r = (_q = (_p = session === null || session === void 0 ? void 0 : session.tokens) === null || _p === void 0 ? void 0 : _p.idToken) === null || _q === void 0 ? void 0 : _q.payload) === null || _r === void 0 ? void 0 : _r.email) === null || _s === void 0 ? void 0 : _s.toString(),
|
|
576
|
+
firstName: (_w = (_v = (_u = (_t = session === null || session === void 0 ? void 0 : session.tokens) === null || _t === void 0 ? void 0 : _t.idToken) === null || _u === void 0 ? void 0 : _u.payload) === null || _v === void 0 ? void 0 : _v.given_name) === null || _w === void 0 ? void 0 : _w.toString(),
|
|
577
|
+
lastName: (_0 = (_z = (_y = (_x = session === null || session === void 0 ? void 0 : session.tokens) === null || _x === void 0 ? void 0 : _x.idToken) === null || _y === void 0 ? void 0 : _y.payload) === null || _z === void 0 ? void 0 : _z.family_name) === null || _0 === void 0 ? void 0 : _0.toString(),
|
|
578
|
+
dateOfBirth: (_4 = (_3 = (_2 = (_1 = session === null || session === void 0 ? void 0 : session.tokens) === null || _1 === void 0 ? void 0 : _1.idToken) === null || _2 === void 0 ? void 0 : _2.payload) === null || _3 === void 0 ? void 0 : _3.birthdate) === null || _4 === void 0 ? void 0 : _4.toString(),
|
|
579
|
+
'cognito:username': (_8 = (_7 = (_6 = (_5 = session === null || session === void 0 ? void 0 : session.tokens) === null || _5 === void 0 ? void 0 : _5.idToken) === null || _6 === void 0 ? void 0 : _6.payload) === null || _7 === void 0 ? void 0 : _7['cognito:username']) === null || _8 === void 0 ? void 0 : _8.toString(),
|
|
580
|
+
'custom:termsAccepted': (_12 = (_11 = (_10 = (_9 = session === null || session === void 0 ? void 0 : session.tokens) === null || _9 === void 0 ? void 0 : _9.idToken) === null || _10 === void 0 ? void 0 : _10.payload) === null || _11 === void 0 ? void 0 : _11['custom:termsAccepted']) === null || _12 === void 0 ? void 0 : _12.toString(),
|
|
581
|
+
'custom:subscriptionId': (_16 = (_15 = (_14 = (_13 = session === null || session === void 0 ? void 0 : session.tokens) === null || _13 === void 0 ? void 0 : _13.idToken) === null || _14 === void 0 ? void 0 : _14.payload) === null || _15 === void 0 ? void 0 : _15['custom:subscriptionId']) === null || _16 === void 0 ? void 0 : _16.toString(),
|
|
582
|
+
'custom:contactPreferences': (_20 = (_19 = (_18 = (_17 = session === null || session === void 0 ? void 0 : session.tokens) === null || _17 === void 0 ? void 0 : _17.idToken) === null || _18 === void 0 ? void 0 : _18.payload) === null || _19 === void 0 ? void 0 : _19['custom:contactPreferences']) === null || _20 === void 0 ? void 0 : _20.toString(),
|
|
583
|
+
'custom:customerId': (_24 = (_23 = (_22 = (_21 = session === null || session === void 0 ? void 0 : session.tokens) === null || _21 === void 0 ? void 0 : _21.idToken) === null || _22 === void 0 ? void 0 : _22.payload) === null || _23 === void 0 ? void 0 : _23['custom:customerId']) === null || _24 === void 0 ? void 0 : _24.toString(),
|
|
584
|
+
},
|
|
585
|
+
};
|
|
586
|
+
}
|
|
544
587
|
|
|
545
588
|
// console.log('process.env', process.env);
|
|
546
589
|
// console.log('process.env?.WEB_APP', process.env?.WEB_APP);
|
|
@@ -577,28 +620,69 @@ var APP_ES_AUTH = ((_f = process.env) === null || _f === void 0 ? void 0 : _f.NE
|
|
|
577
620
|
((_t = process.env) === null || _t === void 0 ? void 0 : _t.NEXT_PUBLIC_APP_ES_CHALLENGE_DAYS_INDEX) ||
|
|
578
621
|
ENV.APP_ES_CHALLENGE_DAYS_INDEX;
|
|
579
622
|
|
|
623
|
+
var authDataBaseQuery = fetchBaseQuery({
|
|
624
|
+
baseUrl: API_AUTH_PREFIX,
|
|
625
|
+
prepareHeaders: function (headers_1, _a) { return __awaiter(void 0, [headers_1, _a], void 0, function (headers, _b) {
|
|
626
|
+
var tokens;
|
|
627
|
+
return __generator(this, function (_c) {
|
|
628
|
+
switch (_c.label) {
|
|
629
|
+
case 0:
|
|
630
|
+
headers.set('Content-Type', 'application/json');
|
|
631
|
+
return [4 /*yield*/, fetchAuthSession()];
|
|
632
|
+
case 1:
|
|
633
|
+
tokens = (_c.sent()).tokens;
|
|
634
|
+
if ((tokens === null || tokens === void 0 ? void 0 : tokens.accessToken) && tokens.idToken) {
|
|
635
|
+
headers.set('accesstoken', tokens.accessToken.toString());
|
|
636
|
+
headers.set('idtoken', tokens.idToken.toString());
|
|
637
|
+
// headers.set('refreshtoken', tokens.refreshToken);
|
|
638
|
+
}
|
|
639
|
+
return [2 /*return*/, headers];
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
}); },
|
|
643
|
+
credentials: 'include',
|
|
644
|
+
});
|
|
645
|
+
/**
|
|
646
|
+
* This function is used to retry a request if we get a 401 error.
|
|
647
|
+
*/
|
|
648
|
+
var authDataBaseQueryWithReauth = function (args, api, extraOptions) { return __awaiter(void 0, void 0, void 0, function () {
|
|
649
|
+
var result, authSession, user;
|
|
650
|
+
var _a;
|
|
651
|
+
return __generator(this, function (_b) {
|
|
652
|
+
switch (_b.label) {
|
|
653
|
+
case 0: return [4 /*yield*/, authDataBaseQuery(args, api, extraOptions)];
|
|
654
|
+
case 1:
|
|
655
|
+
result = _b.sent();
|
|
656
|
+
if (!(((_a = result === null || result === void 0 ? void 0 : result.error) === null || _a === void 0 ? void 0 : _a.status) === 401)) return [3 /*break*/, 6];
|
|
657
|
+
return [4 /*yield*/, fetchAuthSession()];
|
|
658
|
+
case 2:
|
|
659
|
+
authSession = _b.sent();
|
|
660
|
+
user = formatAuthSession(authSession);
|
|
661
|
+
api.dispatch(setCredentials(user));
|
|
662
|
+
if (!(authSession === null || authSession === void 0 ? void 0 : authSession.tokens)) return [3 /*break*/, 4];
|
|
663
|
+
return [4 /*yield*/, authDataBaseQuery(args, api, extraOptions)];
|
|
664
|
+
case 3:
|
|
665
|
+
// If we get a new access token, retry the original request.
|
|
666
|
+
result = _b.sent();
|
|
667
|
+
return [3 /*break*/, 6];
|
|
668
|
+
case 4:
|
|
669
|
+
// TODO; require full data reset?
|
|
670
|
+
return [4 /*yield*/, signOut()];
|
|
671
|
+
case 5:
|
|
672
|
+
// TODO; require full data reset?
|
|
673
|
+
_b.sent();
|
|
674
|
+
api.dispatch(logout());
|
|
675
|
+
// If no access token throw error.
|
|
676
|
+
throw new Error('No access token found');
|
|
677
|
+
case 6: return [2 /*return*/, result];
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
}); };
|
|
580
681
|
var authApi = createApi({
|
|
581
682
|
reducerPath: 'authApi',
|
|
582
|
-
baseQuery:
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
var getState = _a.getState;
|
|
586
|
-
var state = getState();
|
|
587
|
-
headers.set('Content-Type', 'application/json');
|
|
588
|
-
// add accessToken to headers from slice using selectAccessToken selector
|
|
589
|
-
var tokens = selectUserTokens(state);
|
|
590
|
-
console.log('tokens: ', tokens);
|
|
591
|
-
if (tokens) {
|
|
592
|
-
headers.set('accesstoken', tokens.accessToken);
|
|
593
|
-
headers.set('idtoken', tokens.idToken);
|
|
594
|
-
headers.set('refreshtoken', tokens.refreshToken);
|
|
595
|
-
}
|
|
596
|
-
return headers;
|
|
597
|
-
},
|
|
598
|
-
credentials: 'include',
|
|
599
|
-
}),
|
|
600
|
-
tagTypes: ['UserToken'],
|
|
601
|
-
keepUnusedDataFor: 300,
|
|
683
|
+
baseQuery: authDataBaseQueryWithReauth,
|
|
684
|
+
tagTypes: ['UserToken', 'UserData'],
|
|
685
|
+
// keepUnusedDataFor: 300,
|
|
602
686
|
endpoints: function (builder) { return ({
|
|
603
687
|
/**
|
|
604
688
|
* USER API.
|
|
@@ -848,6 +932,7 @@ var authApi = createApi({
|
|
|
848
932
|
url: "/data/user/".concat(uuid),
|
|
849
933
|
method: 'GET',
|
|
850
934
|
}); },
|
|
935
|
+
providesTags: ['UserData'],
|
|
851
936
|
}),
|
|
852
937
|
updateUserInfo: builder.mutation({
|
|
853
938
|
query: function (expressions) { return ({
|
|
@@ -855,6 +940,7 @@ var authApi = createApi({
|
|
|
855
940
|
method: 'PATCH',
|
|
856
941
|
body: expressions,
|
|
857
942
|
}); },
|
|
943
|
+
invalidatesTags: ['UserData'],
|
|
858
944
|
}),
|
|
859
945
|
updateUser: builder.mutation({
|
|
860
946
|
query: function (data) { return ({
|
|
@@ -862,14 +948,13 @@ var authApi = createApi({
|
|
|
862
948
|
method: 'PATCH',
|
|
863
949
|
body: data,
|
|
864
950
|
}); },
|
|
951
|
+
invalidatesTags: ['UserData'],
|
|
865
952
|
}),
|
|
866
953
|
}); },
|
|
867
954
|
});
|
|
868
955
|
// Export hooks for usage in functional components.
|
|
869
|
-
authApi.useLoginQuery
|
|
956
|
+
var useLoginQuery = authApi.useLoginQuery, useLazyLoginQuery = authApi.useLazyLoginQuery, useResetPasswordMutation = authApi.useResetPasswordMutation, useResetPasswordAuthMutation = authApi.useResetPasswordAuthMutation, useRefreshTokenQuery = authApi.useRefreshTokenQuery, useLazyRefreshTokenQuery = authApi.useLazyRefreshTokenQuery, useLogoutQuery = authApi.useLogoutQuery, useLazyLogoutQuery = authApi.useLazyLogoutQuery, useRegisterMutation = authApi.useRegisterMutation, useVerifyUserQuery = authApi.useVerifyUserQuery, useLazyVerifyUserQuery = authApi.useLazyVerifyUserQuery, useGetUserInfoQuery = authApi.useGetUserInfoQuery, useLazyGetUserInfoQuery = authApi.useLazyGetUserInfoQuery, useUpdateUserInfoMutation = authApi.useUpdateUserInfoMutation, useForgottenPasswordMutation = authApi.useForgottenPasswordMutation, useVerifyUserAttributesQuery = authApi.useVerifyUserAttributesQuery, useLazyVerifyUserAttributesQuery = authApi.useLazyVerifyUserAttributesQuery, useVerifyUserResendQuery = authApi.useVerifyUserResendQuery, useLazyVerifyUserResendQuery = authApi.useLazyVerifyUserResendQuery, useUpdateUserMutation = authApi.useUpdateUserMutation;
|
|
870
957
|
|
|
871
|
-
// console.log('APP_ES_INSTANCE', APP_ES_INSTANCE);
|
|
872
|
-
// console.log('APP_ES_AUTH', APP_ES_AUTH);
|
|
873
958
|
var contentApi = createApi({
|
|
874
959
|
reducerPath: 'contentApi',
|
|
875
960
|
baseQuery: fetchBaseQuery({
|
|
@@ -901,41 +986,7 @@ var contentApi = createApi({
|
|
|
901
986
|
transformResponse: function (response) { var _a; return (_a = response === null || response === void 0 ? void 0 : response.hits) === null || _a === void 0 ? void 0 : _a.hits; },
|
|
902
987
|
providesTags: ['Data'],
|
|
903
988
|
}),
|
|
904
|
-
|
|
905
|
-
// query: (index) => ({
|
|
906
|
-
// url: `${index}/_search`,
|
|
907
|
-
// method: 'POST',
|
|
908
|
-
// body: {
|
|
909
|
-
// from: 0,
|
|
910
|
-
// size: 100,
|
|
911
|
-
// sort: [{ created: { order: 'desc' } }],
|
|
912
|
-
// query: {
|
|
913
|
-
// match_all: {},
|
|
914
|
-
// },
|
|
915
|
-
// },
|
|
916
|
-
// }),
|
|
917
|
-
// transformResponse: (response: ESPromoResponse) =>
|
|
918
|
-
// formatPromos(response?.hits?.hits),
|
|
919
|
-
// providesTags: ['Promos'],
|
|
920
|
-
// }),
|
|
921
|
-
// getWorkouts: builder.query<Workout[], string | undefined>({
|
|
922
|
-
// query: (index) => ({
|
|
923
|
-
// url: `${index}/_search`,
|
|
924
|
-
// method: 'POST',
|
|
925
|
-
// body: {
|
|
926
|
-
// from: 0,
|
|
927
|
-
// size: 100,
|
|
928
|
-
// sort: [{ created: { order: 'desc' } }],
|
|
929
|
-
// query: {
|
|
930
|
-
// match_all: {},
|
|
931
|
-
// },
|
|
932
|
-
// },
|
|
933
|
-
// }),
|
|
934
|
-
// transformResponse: (response: ESWorkoutResponse) =>
|
|
935
|
-
// formatESWorkoutItems(response?.hits?.hits),
|
|
936
|
-
// providesTags: ['Workouts'],
|
|
937
|
-
// }),
|
|
938
|
-
getWorkoutById: builder.query({
|
|
989
|
+
getDataById: builder.query({
|
|
939
990
|
query: function (_a) {
|
|
940
991
|
var index = _a.index, id = _a.id;
|
|
941
992
|
return ({
|
|
@@ -943,25 +994,20 @@ var contentApi = createApi({
|
|
|
943
994
|
method: 'POST',
|
|
944
995
|
body: {
|
|
945
996
|
query: {
|
|
946
|
-
|
|
997
|
+
match: {
|
|
947
998
|
uuid: id,
|
|
948
999
|
},
|
|
949
1000
|
},
|
|
950
1001
|
},
|
|
951
1002
|
});
|
|
952
1003
|
},
|
|
1004
|
+
transformResponse: function (response) { var _a; return (_a = response === null || response === void 0 ? void 0 : response.hits) === null || _a === void 0 ? void 0 : _a.hits; },
|
|
953
1005
|
providesTags: ['Workout'],
|
|
954
1006
|
}),
|
|
955
1007
|
}); },
|
|
956
1008
|
});
|
|
957
|
-
contentApi.useGetDataQuery; contentApi.useLazyGetDataQuery;
|
|
958
|
-
// useGetPromosQuery,
|
|
959
|
-
// useLazyGetPromosQuery,
|
|
960
|
-
// useGetWorkoutsQuery,
|
|
961
|
-
// useLazyGetWorkoutsQuery,
|
|
962
|
-
contentApi.useGetWorkoutByIdQuery; contentApi.useLazyGetWorkoutByIdQuery;
|
|
1009
|
+
contentApi.useGetDataQuery; contentApi.useLazyGetDataQuery; contentApi.useGetDataByIdQuery; contentApi.useLazyGetDataByIdQuery;
|
|
963
1010
|
|
|
964
|
-
console.log('API_PAYMENTS_PREFIX: ', API_PAYMENTS_PREFIX);
|
|
965
1011
|
var paymentApi = createApi({
|
|
966
1012
|
reducerPath: 'paymentApi',
|
|
967
1013
|
baseQuery: fetchBaseQuery({
|
|
@@ -973,10 +1019,10 @@ var paymentApi = createApi({
|
|
|
973
1019
|
// add accessToken to headers from slice using selectAccessToken selector
|
|
974
1020
|
var tokens = selectUserTokens(state);
|
|
975
1021
|
console.log('tokens: ', tokens);
|
|
976
|
-
if (tokens) {
|
|
1022
|
+
if (tokens.accessToken && tokens.idToken) {
|
|
977
1023
|
headers.set('accesstoken', tokens.accessToken);
|
|
978
1024
|
headers.set('idtoken', tokens.idToken);
|
|
979
|
-
headers.set('refreshtoken', tokens.refreshToken);
|
|
1025
|
+
// headers.set('refreshtoken', tokens.refreshToken);
|
|
980
1026
|
}
|
|
981
1027
|
return headers;
|
|
982
1028
|
},
|
|
@@ -1055,6 +1101,12 @@ function createPersistStorage() {
|
|
|
1055
1101
|
|
|
1056
1102
|
// Infer the `RootState` type from the root reducer
|
|
1057
1103
|
var rootReducer = combineSlices(authSlice, authApi, contentApi, paymentApi);
|
|
1104
|
+
// export interface RootState {
|
|
1105
|
+
// [authSlice.name]: ReturnType<typeof authSlice.reducer>;
|
|
1106
|
+
// [authApi.reducerPath]: ReturnType<typeof authApi.reducer>;
|
|
1107
|
+
// [contentApi.reducerPath]: ReturnType<typeof contentApi.reducer>;
|
|
1108
|
+
// [paymentApi.reducerPath]: ReturnType<typeof paymentApi.reducer>;
|
|
1109
|
+
// }
|
|
1058
1110
|
// eg. ['auth', 'creating'], or an empty array if you don't want to whitelist any.
|
|
1059
1111
|
// const storageWhiteList: string[] = [];
|
|
1060
1112
|
// `makeStore` encapsulates the store configuration to allow
|
|
@@ -1144,5 +1196,5 @@ var makeWebStore = function () {
|
|
|
1144
1196
|
var nativeStore = !isWeb && makeNativeStore();
|
|
1145
1197
|
var webStore = isWeb && makeWebStore();
|
|
1146
1198
|
|
|
1147
|
-
export { authApi, authSlice, contentApi, formatChallengeDays, formatChallenges, formatFaqs, formatGuests, formatLongform, formatPages, formatPress, formatPromos, formatSchedule, formatSections, formatSeries, formatSettings, formatShortform, formatUserPayload, formatVideos, formatWorkout, getUserSession, isAuthenticated, isVerifying, logout, nativeStore, paymentApi, resetCreating, selectAccessToken, selectCurrentUser, selectCurrentUserRefreshToken, selectCurrentUserSub, selectRefreshToken, selectSubscription, selectSubscriptionPrice, selectUserCreating, selectUserCreatingDetails, selectUserSubscriptionStatus, selectUserTokens, setCredentials, updateSubscription, useAppDispatch, useAppSelector, useAppStore, useLoggedIn, webStore };
|
|
1199
|
+
export { authApi, authSlice, contentApi, formatAuthSession, formatChallengeDays, formatChallenges, formatFaqs, formatGuests, formatLongform, formatPages, formatPress, formatPromos, formatSchedule, formatSecondsToISO8601Duration, formatSections, formatSeries, formatSettings, formatShortform, formatUserPayload, formatVideos, formatWorkout, getUserSession, isAuthenticated, isVerifying, logout, nativeStore, paymentApi, resetCreating, selectAccessToken, selectCurrentUser, selectCurrentUserRefreshToken, selectCurrentUserSub, selectRefreshToken, selectSubscription, selectSubscriptionPrice, selectUserCreating, selectUserCreatingDetails, selectUserSubscriptionStatus, selectUserTokens, setCredentials, updateSubscription, useAppDispatch, useAppSelector, useAppStore, useForgottenPasswordMutation, useGetUserInfoQuery, useLazyGetUserInfoQuery, useLazyLoginQuery, useLazyLogoutQuery, useLazyRefreshTokenQuery, useLazyVerifyUserAttributesQuery, useLazyVerifyUserQuery, useLazyVerifyUserResendQuery, useLoggedIn, useLoginQuery, useLogoutQuery, useRefreshTokenQuery, useRegisterMutation, useResetPasswordAuthMutation, useResetPasswordMutation, useUpdateUserInfoMutation, useUpdateUserMutation, useVerifyUserAttributesQuery, useVerifyUserQuery, useVerifyUserResendQuery, webStore };
|
|
1148
1200
|
//# sourceMappingURL=index.esm.js.map
|