@techstuff-dev/foundation-api-utils 1.13.0 → 1.14.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/index.js CHANGED
@@ -101,6 +101,7 @@ var initialState = {
101
101
  accessTokenExpiry: null,
102
102
  refreshToken: '',
103
103
  email: '',
104
+ sub: '',
104
105
  },
105
106
  creating: {
106
107
  details: '',
@@ -137,7 +138,7 @@ var authSlice = toolkit.createSlice({
137
138
  selectUserCreatingDetails: function (auth) { return auth.creating.details; },
138
139
  isVerifying: function (auth) { return auth.verifying; },
139
140
  getUserSession: function (auth) { return (auth.authenticated ? auth.session : false); },
140
- selectCurrentUserSub: function (auth) { var _a, _b; return (_b = (_a = auth === null || auth === void 0 ? void 0 : auth.user) === null || _a === void 0 ? void 0 : _a.details) === null || _b === void 0 ? void 0 : _b.uuid; },
141
+ selectCurrentUserSub: function (auth) { return auth.user.sub; },
141
142
  selectCurrentUserRefreshToken: function (auth) { return auth.user.refreshToken; },
142
143
  selectUserTokens: function (auth) {
143
144
  return {
@@ -217,30 +218,29 @@ function formatPromos(data) {
217
218
  });
218
219
  }
219
220
  function formatWorkout(data) {
220
- var response = 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, _10, _11;
221
+ return data.map(function (item) {
222
+ 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;
222
223
  return {
223
224
  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],
224
225
  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],
225
226
  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],
226
227
  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],
227
- duration: (_k = (_j = item === null || item === void 0 ? void 0 : item._source) === null || _j === void 0 ? void 0 : _j.duration) === null || _k === void 0 ? void 0 : _k[0],
228
- duration_filter: (_m = (_l = item === null || item === void 0 ? void 0 : item._source) === null || _l === void 0 ? void 0 : _l.duration_filter) === null || _m === void 0 ? void 0 : _m[0],
229
- level: (_p = (_o = item === null || item === void 0 ? void 0 : item._source) === null || _o === void 0 ? void 0 : _o.level) === null || _p === void 0 ? void 0 : _p[0],
230
- published: (_r = (_q = item === null || item === void 0 ? void 0 : item._source) === null || _q === void 0 ? void 0 : _q.published) === null || _r === void 0 ? void 0 : _r[0],
231
- targeted_section: (_t = (_s = item === null || item === void 0 ? void 0 : item._source) === null || _s === void 0 ? void 0 : _s.targeted_section) === null || _t === void 0 ? void 0 : _t[0],
232
- uid: (_v = (_u = item === null || item === void 0 ? void 0 : item._source) === null || _u === void 0 ? void 0 : _u.uid) === null || _v === void 0 ? void 0 : _v[0],
233
- image: (_x = (_w = item === null || item === void 0 ? void 0 : item._source) === null || _w === void 0 ? void 0 : _w.image) === null || _x === void 0 ? void 0 : _x[0],
234
- title: (_z = (_y = item === null || item === void 0 ? void 0 : item._source) === null || _y === void 0 ? void 0 : _y.title) === null || _z === void 0 ? void 0 : _z[0],
235
- video: (_1 = (_0 = item === null || item === void 0 ? void 0 : item._source) === null || _0 === void 0 ? void 0 : _0.video_url) === null || _1 === void 0 ? void 0 : _1[0],
236
- videoDownload: (_3 = (_2 = item === null || item === void 0 ? void 0 : item._source) === null || _2 === void 0 ? void 0 : _2.video_download) === null || _3 === void 0 ? void 0 : _3[0],
237
- videoPoster: (_5 = (_4 = item === null || item === void 0 ? void 0 : item._source) === null || _4 === void 0 ? void 0 : _4.video_poster) === null || _5 === void 0 ? void 0 : _5[0],
238
- workoutCategory: (_7 = (_6 = item === null || item === void 0 ? void 0 : item._source) === null || _6 === void 0 ? void 0 : _6.workout_category) === null || _7 === void 0 ? void 0 : _7[0],
239
- workoutType: (_9 = (_8 = item === null || item === void 0 ? void 0 : item._source) === null || _8 === void 0 ? void 0 : _8.workout_type) === null || _9 === void 0 ? void 0 : _9[0],
240
- livestream_section: (_11 = (_10 = item === null || item === void 0 ? void 0 : item._source) === null || _10 === void 0 ? void 0 : _10.livestream_section) === null || _11 === void 0 ? void 0 : _11[0],
228
+ 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],
229
+ // duration_filter: item?._source?.duration_filter?.[0],
230
+ 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],
231
+ 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],
232
+ 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],
233
+ 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],
234
+ 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],
235
+ 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],
236
+ 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],
237
+ 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],
238
+ 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],
239
+ 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],
240
+ 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],
241
+ 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],
241
242
  };
242
243
  });
243
- return response;
244
244
  }
245
245
  function formatSeries(data, channel) {
246
246
  var formattedSeriesSelection = data.map(function (series) {
@@ -381,7 +381,7 @@ function formatGuests(data) {
381
381
  });
382
382
  }
383
383
  function formatVideos(data) {
384
- var response = data.map(function (item) {
384
+ return data.map(function (item) {
385
385
  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;
386
386
  return {
387
387
  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],
@@ -393,12 +393,11 @@ function formatVideos(data) {
393
393
  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],
394
394
  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],
395
395
  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],
396
- videoUrl: (_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],
396
+ 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],
397
397
  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],
398
398
  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],
399
399
  };
400
400
  });
401
- return response;
402
401
  }
403
402
  function formatSections(data) {
404
403
  return data.map(function (item) {
@@ -513,9 +512,10 @@ function formatSchedule(data) {
513
512
  }
514
513
  function formatChallenges(data) {
515
514
  return data.map(function (item) {
515
+ var _a;
516
516
  var _source = item._source;
517
517
  return {
518
- uuid: _source.uuid && _source.uuid[0],
518
+ uuid: (_a = _source === null || _source === void 0 ? void 0 : _source.uuid) === null || _a === void 0 ? void 0 : _a[0],
519
519
  title: _source.title && _source.title[0],
520
520
  body: _source.body && _source.body[0],
521
521
  image: _source.image && _source.image[0],
@@ -543,6 +543,26 @@ function formatChallengeDays(data) {
543
543
  };
544
544
  });
545
545
  }
546
+ function formatSecondsToISO8601Duration(seconds) {
547
+ if (!seconds)
548
+ return '';
549
+ // Calculate hours, minutes, and remaining seconds
550
+ var hours = Math.floor(seconds / 3600);
551
+ var minutes = Math.floor((seconds % 3600) / 60);
552
+ var remainingSeconds = seconds % 60;
553
+ // Build the ISO 8601 duration string
554
+ var duration = 'PT';
555
+ if (hours > 0) {
556
+ duration += "".concat(hours, "H");
557
+ }
558
+ if (minutes > 0) {
559
+ duration += "".concat(minutes, "M");
560
+ }
561
+ if (remainingSeconds > 0 || duration === 'PT') {
562
+ duration += "".concat(remainingSeconds, "S");
563
+ }
564
+ return duration;
565
+ }
546
566
 
547
567
  // console.log('process.env', process.env);
548
568
  // console.log('process.env?.WEB_APP', process.env?.WEB_APP);
@@ -590,17 +610,17 @@ var authApi = react.createApi({
590
610
  // add accessToken to headers from slice using selectAccessToken selector
591
611
  var tokens = selectUserTokens(state);
592
612
  console.log('tokens: ', tokens);
593
- if (tokens) {
613
+ if (tokens.accessToken && tokens.idToken) {
594
614
  headers.set('accesstoken', tokens.accessToken);
595
615
  headers.set('idtoken', tokens.idToken);
596
- headers.set('refreshtoken', tokens.refreshToken);
616
+ // headers.set('refreshtoken', tokens.refreshToken);
597
617
  }
598
618
  return headers;
599
619
  },
600
620
  credentials: 'include',
601
621
  }),
602
- tagTypes: ['UserToken'],
603
- keepUnusedDataFor: 300,
622
+ tagTypes: ['UserToken', 'UserData'],
623
+ // keepUnusedDataFor: 300,
604
624
  endpoints: function (builder) { return ({
605
625
  /**
606
626
  * USER API.
@@ -850,6 +870,7 @@ var authApi = react.createApi({
850
870
  url: "/data/user/".concat(uuid),
851
871
  method: 'GET',
852
872
  }); },
873
+ providesTags: ['UserData'],
853
874
  }),
854
875
  updateUserInfo: builder.mutation({
855
876
  query: function (expressions) { return ({
@@ -857,6 +878,7 @@ var authApi = react.createApi({
857
878
  method: 'PATCH',
858
879
  body: expressions,
859
880
  }); },
881
+ invalidatesTags: ['UserData'],
860
882
  }),
861
883
  updateUser: builder.mutation({
862
884
  query: function (data) { return ({
@@ -864,14 +886,13 @@ var authApi = react.createApi({
864
886
  method: 'PATCH',
865
887
  body: data,
866
888
  }); },
889
+ invalidatesTags: ['UserData'],
867
890
  }),
868
891
  }); },
869
892
  });
870
893
  // Export hooks for usage in functional components.
871
- authApi.useLoginQuery; authApi.useLazyLoginQuery; authApi.useResetPasswordMutation; authApi.useResetPasswordAuthMutation; authApi.useRefreshTokenQuery; authApi.useLazyRefreshTokenQuery; authApi.useLogoutQuery; authApi.useLazyLogoutQuery; authApi.useRegisterMutation; authApi.useVerifyUserQuery; authApi.useLazyVerifyUserQuery; authApi.useGetUserInfoQuery; authApi.useLazyGetUserInfoQuery; authApi.useUpdateUserInfoMutation; authApi.useForgottenPasswordMutation; authApi.useVerifyUserAttributesQuery; authApi.useLazyVerifyUserAttributesQuery; authApi.useVerifyUserResendQuery; authApi.useLazyVerifyUserResendQuery; authApi.useUpdateUserMutation;
894
+ 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;
872
895
 
873
- // console.log('APP_ES_INSTANCE', APP_ES_INSTANCE);
874
- // console.log('APP_ES_AUTH', APP_ES_AUTH);
875
896
  var contentApi = react.createApi({
876
897
  reducerPath: 'contentApi',
877
898
  baseQuery: react.fetchBaseQuery({
@@ -903,41 +924,7 @@ var contentApi = react.createApi({
903
924
  transformResponse: function (response) { var _a; return (_a = response === null || response === void 0 ? void 0 : response.hits) === null || _a === void 0 ? void 0 : _a.hits; },
904
925
  providesTags: ['Data'],
905
926
  }),
906
- // getPromos: builder.query<Promo[], string | undefined>({
907
- // query: (index) => ({
908
- // url: `${index}/_search`,
909
- // method: 'POST',
910
- // body: {
911
- // from: 0,
912
- // size: 100,
913
- // sort: [{ created: { order: 'desc' } }],
914
- // query: {
915
- // match_all: {},
916
- // },
917
- // },
918
- // }),
919
- // transformResponse: (response: ESPromoResponse) =>
920
- // formatPromos(response?.hits?.hits),
921
- // providesTags: ['Promos'],
922
- // }),
923
- // getWorkouts: builder.query<Workout[], string | undefined>({
924
- // query: (index) => ({
925
- // url: `${index}/_search`,
926
- // method: 'POST',
927
- // body: {
928
- // from: 0,
929
- // size: 100,
930
- // sort: [{ created: { order: 'desc' } }],
931
- // query: {
932
- // match_all: {},
933
- // },
934
- // },
935
- // }),
936
- // transformResponse: (response: ESWorkoutResponse) =>
937
- // formatESWorkoutItems(response?.hits?.hits),
938
- // providesTags: ['Workouts'],
939
- // }),
940
- getWorkoutById: builder.query({
927
+ getDataById: builder.query({
941
928
  query: function (_a) {
942
929
  var index = _a.index, id = _a.id;
943
930
  return ({
@@ -945,25 +932,20 @@ var contentApi = react.createApi({
945
932
  method: 'POST',
946
933
  body: {
947
934
  query: {
948
- term: {
935
+ match: {
949
936
  uuid: id,
950
937
  },
951
938
  },
952
939
  },
953
940
  });
954
941
  },
942
+ transformResponse: function (response) { var _a; return (_a = response === null || response === void 0 ? void 0 : response.hits) === null || _a === void 0 ? void 0 : _a.hits; },
955
943
  providesTags: ['Workout'],
956
944
  }),
957
945
  }); },
958
946
  });
959
- contentApi.useGetDataQuery; contentApi.useLazyGetDataQuery;
960
- // useGetPromosQuery,
961
- // useLazyGetPromosQuery,
962
- // useGetWorkoutsQuery,
963
- // useLazyGetWorkoutsQuery,
964
- contentApi.useGetWorkoutByIdQuery; contentApi.useLazyGetWorkoutByIdQuery;
947
+ contentApi.useGetDataQuery; contentApi.useLazyGetDataQuery; contentApi.useGetDataByIdQuery; contentApi.useLazyGetDataByIdQuery;
965
948
 
966
- console.log('API_PAYMENTS_PREFIX: ', API_PAYMENTS_PREFIX);
967
949
  var paymentApi = react.createApi({
968
950
  reducerPath: 'paymentApi',
969
951
  baseQuery: react.fetchBaseQuery({
@@ -975,10 +957,10 @@ var paymentApi = react.createApi({
975
957
  // add accessToken to headers from slice using selectAccessToken selector
976
958
  var tokens = selectUserTokens(state);
977
959
  console.log('tokens: ', tokens);
978
- if (tokens) {
960
+ if (tokens.accessToken && tokens.idToken) {
979
961
  headers.set('accesstoken', tokens.accessToken);
980
962
  headers.set('idtoken', tokens.idToken);
981
- headers.set('refreshtoken', tokens.refreshToken);
963
+ // headers.set('refreshtoken', tokens.refreshToken);
982
964
  }
983
965
  return headers;
984
966
  },
@@ -1057,6 +1039,12 @@ function createPersistStorage() {
1057
1039
 
1058
1040
  // Infer the `RootState` type from the root reducer
1059
1041
  var rootReducer = toolkit.combineSlices(authSlice, authApi, contentApi, paymentApi);
1042
+ // export interface RootState {
1043
+ // [authSlice.name]: ReturnType<typeof authSlice.reducer>;
1044
+ // [authApi.reducerPath]: ReturnType<typeof authApi.reducer>;
1045
+ // [contentApi.reducerPath]: ReturnType<typeof contentApi.reducer>;
1046
+ // [paymentApi.reducerPath]: ReturnType<typeof paymentApi.reducer>;
1047
+ // }
1060
1048
  // eg. ['auth', 'creating'], or an empty array if you don't want to whitelist any.
1061
1049
  // const storageWhiteList: string[] = [];
1062
1050
  // `makeStore` encapsulates the store configuration to allow
@@ -1158,6 +1146,7 @@ exports.formatPages = formatPages;
1158
1146
  exports.formatPress = formatPress;
1159
1147
  exports.formatPromos = formatPromos;
1160
1148
  exports.formatSchedule = formatSchedule;
1149
+ exports.formatSecondsToISO8601Duration = formatSecondsToISO8601Duration;
1161
1150
  exports.formatSections = formatSections;
1162
1151
  exports.formatSeries = formatSeries;
1163
1152
  exports.formatSettings = formatSettings;
@@ -1188,6 +1177,26 @@ exports.updateSubscription = updateSubscription;
1188
1177
  exports.useAppDispatch = useAppDispatch;
1189
1178
  exports.useAppSelector = useAppSelector;
1190
1179
  exports.useAppStore = useAppStore;
1180
+ exports.useForgottenPasswordMutation = useForgottenPasswordMutation;
1181
+ exports.useGetUserInfoQuery = useGetUserInfoQuery;
1182
+ exports.useLazyGetUserInfoQuery = useLazyGetUserInfoQuery;
1183
+ exports.useLazyLoginQuery = useLazyLoginQuery;
1184
+ exports.useLazyLogoutQuery = useLazyLogoutQuery;
1185
+ exports.useLazyRefreshTokenQuery = useLazyRefreshTokenQuery;
1186
+ exports.useLazyVerifyUserAttributesQuery = useLazyVerifyUserAttributesQuery;
1187
+ exports.useLazyVerifyUserQuery = useLazyVerifyUserQuery;
1188
+ exports.useLazyVerifyUserResendQuery = useLazyVerifyUserResendQuery;
1191
1189
  exports.useLoggedIn = useLoggedIn;
1190
+ exports.useLoginQuery = useLoginQuery;
1191
+ exports.useLogoutQuery = useLogoutQuery;
1192
+ exports.useRefreshTokenQuery = useRefreshTokenQuery;
1193
+ exports.useRegisterMutation = useRegisterMutation;
1194
+ exports.useResetPasswordAuthMutation = useResetPasswordAuthMutation;
1195
+ exports.useResetPasswordMutation = useResetPasswordMutation;
1196
+ exports.useUpdateUserInfoMutation = useUpdateUserInfoMutation;
1197
+ exports.useUpdateUserMutation = useUpdateUserMutation;
1198
+ exports.useVerifyUserAttributesQuery = useVerifyUserAttributesQuery;
1199
+ exports.useVerifyUserQuery = useVerifyUserQuery;
1200
+ exports.useVerifyUserResendQuery = useVerifyUserResendQuery;
1192
1201
  exports.webStore = webStore;
1193
1202
  //# sourceMappingURL=index.js.map