@techstuff-dev/foundation-api-utils 2.4.1 → 2.7.1

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.
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var toolkit = require('@reduxjs/toolkit');
4
- var slice = require('./slice-C4MKCa5N.js');
4
+ var slice = require('./slice-2_5ax6TZ.js');
5
5
  var slice$1 = require('./slice-CkWobkWw.js');
6
6
 
7
7
  // This file exists just so TypeScript has a module at ./store for IDEs/build.
@@ -11,4 +11,4 @@ var slice$1 = require('./slice-CkWobkWw.js');
11
11
  const rootReducer = toolkit.combineSlices(slice.cartSlice, slice$1.authSlice, slice.authApi, slice.contentApi, slice.paymentApi, slice.productsApi, slice.ordersApi);
12
12
 
13
13
  exports.rootReducer = rootReducer;
14
- //# sourceMappingURL=shared-DVGP3iZ0.js.map
14
+ //# sourceMappingURL=shared-CNZnVs2B.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared-DVGP3iZ0.js","sources":["../../../lib/store/shared.ts"],"sourcesContent":[null],"names":["combineSlices","cartSlice","authSlice","authApi","contentApi","paymentApi","productsApi","ordersApi"],"mappings":";;;;;;AAAA;AACA;AAUA;AAEA;MACa,WAAW,GAAGA,qBAAa,CACtCC,eAAS,EACTC,iBAAS,EACTC,aAAO,EACPC,gBAAU,EACVC,gBAAU,EACVC,iBAAW,EACXC,eAAS;;;;"}
1
+ {"version":3,"file":"shared-CNZnVs2B.js","sources":["../../../lib/store/shared.ts"],"sourcesContent":[null],"names":["combineSlices","cartSlice","authSlice","authApi","contentApi","paymentApi","productsApi","ordersApi"],"mappings":";;;;;;AAAA;AACA;AAUA;AAEA;MACa,WAAW,GAAGA,qBAAa,CACtCC,eAAS,EACTC,iBAAS,EACTC,aAAO,EACPC,gBAAU,EACVC,gBAAU,EACVC,iBAAW,EACXC,eAAS;;;;"}
@@ -5095,18 +5095,6 @@ function createUnwrappingBaseQuery(baseQueryOptions) {
5095
5095
  };
5096
5096
  }
5097
5097
 
5098
- /**
5099
- * Shared helper to extract auth tokens from the Redux store.
5100
- * Used by all RTK Query services to attach tokens to request headers
5101
- * without depending on aws-amplify's Auth.currentSession().
5102
- */
5103
- function getAuthHeaders(getState) {
5104
- const state = getState();
5105
- const accessToken = state?.auth?.user?.accessToken;
5106
- const idToken = state?.auth?.user?.idToken;
5107
- return { accessToken, idToken };
5108
- }
5109
-
5110
5098
  /**
5111
5099
  * Platform detection utilities for cross-platform React/React Native applications
5112
5100
  */
@@ -5208,7 +5196,7 @@ const APP_ES_SCHEDULE_INDEX$1 = getEnvVar$1('NEXT_PUBLIC_APP_ES_SCHEDULE_INDEX')
5208
5196
  const APP_ES_CHALLENGES_INDEX$1 = getEnvVar$1('NEXT_PUBLIC_APP_ES_CHALLENGES_INDEX');
5209
5197
  const APP_ES_CHALLENGE_DAYS_INDEX$1 = getEnvVar$1('NEXT_PUBLIC_APP_ES_CHALLENGE_DAYS_INDEX');
5210
5198
  // Platform identifier
5211
- const PLATFORM$1 = 'web';
5199
+ const PLATFORM$2 = 'web';
5212
5200
 
5213
5201
  var webConfig = /*#__PURE__*/Object.freeze({
5214
5202
  __proto__: null,
@@ -5231,7 +5219,7 @@ var webConfig = /*#__PURE__*/Object.freeze({
5231
5219
  APP_ES_SETTINGS_INDEX: APP_ES_SETTINGS_INDEX$1,
5232
5220
  APP_ES_VIDEOS_INDEX: APP_ES_VIDEOS_INDEX$1,
5233
5221
  APP_ES_WORKOUTS_INDEX: APP_ES_WORKOUTS_INDEX$1,
5234
- PLATFORM: PLATFORM$1
5222
+ PLATFORM: PLATFORM$2
5235
5223
  });
5236
5224
 
5237
5225
  /**
@@ -5275,7 +5263,7 @@ const APP_ES_SCHEDULE_INDEX = getEnvVar('APP_ES_SCHEDULE_INDEX');
5275
5263
  const APP_ES_CHALLENGES_INDEX = getEnvVar('APP_ES_CHALLENGES_INDEX');
5276
5264
  const APP_ES_CHALLENGE_DAYS_INDEX = getEnvVar('APP_ES_CHALLENGE_DAYS_INDEX');
5277
5265
  // Platform identifier
5278
- const PLATFORM = 'native';
5266
+ const PLATFORM$1 = 'native';
5279
5267
 
5280
5268
  var nativeConfig = /*#__PURE__*/Object.freeze({
5281
5269
  __proto__: null,
@@ -5298,7 +5286,7 @@ var nativeConfig = /*#__PURE__*/Object.freeze({
5298
5286
  APP_ES_SETTINGS_INDEX: APP_ES_SETTINGS_INDEX,
5299
5287
  APP_ES_VIDEOS_INDEX: APP_ES_VIDEOS_INDEX,
5300
5288
  APP_ES_WORKOUTS_INDEX: APP_ES_WORKOUTS_INDEX,
5301
- PLATFORM: PLATFORM
5289
+ PLATFORM: PLATFORM$1
5302
5290
  });
5303
5291
 
5304
5292
  /**
@@ -5340,46 +5328,54 @@ apiConfig.APP_ES_WORKOUTS_INDEX;
5340
5328
  apiConfig.APP_ES_SCHEDULE_INDEX;
5341
5329
  apiConfig.APP_ES_CHALLENGES_INDEX;
5342
5330
  apiConfig.APP_ES_CHALLENGE_DAYS_INDEX;
5343
- apiConfig.PLATFORM;
5331
+ const PLATFORM = apiConfig.PLATFORM;
5344
5332
 
5345
- // Create a dynamic baseQuery that resolves URL at request time and unwraps standard responses
5346
- const createAuthBaseQuery = () => {
5347
- const baseUrl = typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_API_AUTH_PREFIX
5348
- ? process.env.NEXT_PUBLIC_API_AUTH_PREFIX
5349
- : (API_AUTH_PREFIX || '');
5350
- return createUnwrappingBaseQuery({
5351
- baseUrl,
5352
- prepareHeaders: (headers, { getState }) => {
5353
- headers.set('Content-Type', 'application/json');
5354
- const { accessToken, idToken } = getAuthHeaders(getState);
5355
- if (accessToken && idToken) {
5356
- headers.set('accesstoken', accessToken);
5357
- headers.set('idtoken', idToken);
5358
- }
5359
- return headers;
5360
- },
5361
- credentials: 'include',
5362
- });
5363
- };
5364
- const authDataBaseQuery = createAuthBaseQuery();
5365
5333
  /**
5366
- * Mutex to prevent multiple concurrent refresh attempts
5334
+ * Mutex to prevent multiple concurrent refresh attempts.
5335
+ * Shared across all APIs so only one refresh happens at a time.
5367
5336
  */
5368
5337
  let isRefreshing = false;
5369
5338
  let refreshPromise = null;
5370
5339
  /**
5371
- * Attempt to refresh the auth token using the refresh token from Redux state.
5340
+ * Read the refresh token from localStorage (redux-persist) as a fallback
5341
+ * when the Redux store is empty (e.g. during rehydration race).
5342
+ */
5343
+ function getRefreshTokenFromPersist() {
5344
+ if (typeof localStorage === 'undefined')
5345
+ return undefined;
5346
+ try {
5347
+ const raw = localStorage.getItem('persist:root');
5348
+ if (!raw)
5349
+ return undefined;
5350
+ const parsed = JSON.parse(raw);
5351
+ const auth = typeof parsed.auth === 'string' ? JSON.parse(parsed.auth) : parsed.auth;
5352
+ return auth?.user?.refreshToken || undefined;
5353
+ }
5354
+ catch {
5355
+ return undefined;
5356
+ }
5357
+ }
5358
+ /**
5359
+ * Attempt to refresh the auth token using the refresh token from Redux state,
5360
+ * falling back to localStorage if Redux is empty (rehydration race).
5372
5361
  * Returns true if refresh succeeded and tokens were updated.
5373
5362
  */
5374
5363
  async function attemptTokenRefresh(api) {
5375
5364
  const state = api.getState();
5376
- const refreshToken = state?.auth?.user?.refreshToken;
5365
+ let refreshToken = state?.auth?.user?.refreshToken;
5366
+ // Fallback: if Redux store is empty (rehydration hasn't completed), read from localStorage
5367
+ if (!refreshToken) {
5368
+ refreshToken = getRefreshTokenFromPersist();
5369
+ if (refreshToken) {
5370
+ console.debug('[TokenRefresh] Redux empty, recovered refresh token from localStorage');
5371
+ }
5372
+ }
5377
5373
  console.debug('[TokenRefresh] Attempting refresh', {
5378
5374
  hasRefreshToken: !!refreshToken,
5379
- refreshTokenPreview: refreshToken ? `${refreshToken.substring(0, 20)}...` : 'none',
5375
+ source: state?.auth?.user?.refreshToken ? 'redux' : (refreshToken ? 'localStorage' : 'none'),
5380
5376
  });
5381
5377
  if (!refreshToken) {
5382
- console.warn('[TokenRefresh] No refresh token in Redux store — cannot refresh');
5378
+ console.warn('[TokenRefresh] No refresh token in Redux or localStorage — cannot refresh');
5383
5379
  return false;
5384
5380
  }
5385
5381
  // Use the Next.js API route for refresh (proxies to auth microservice)
@@ -5451,46 +5447,104 @@ async function attemptTokenRefresh(api) {
5451
5447
  }
5452
5448
  }
5453
5449
  /**
5454
- * This function retries the request after refreshing the token on 401.
5455
- * If the refresh fails, it dispatches logout.
5450
+ * Wraps any base query with 401 reauth logic.
5451
+ * On 401, attempts to refresh the token and retry the original request.
5452
+ * If refresh fails, dispatches logout.
5453
+ *
5454
+ * Uses a shared mutex so concurrent 401s across different APIs
5455
+ * only trigger one refresh.
5456
5456
  */
5457
- const authDataBaseQueryWithReauth = async (args, api, extraOptions) => {
5458
- let result = await authDataBaseQuery(args, api, extraOptions);
5459
- if (result?.error) {
5460
- const requestUrl = typeof args === 'string' ? args : args?.url;
5461
- console.debug('[AuthQuery] Request error', {
5462
- url: requestUrl,
5463
- status: result.error.status,
5464
- data: result.error?.data,
5465
- });
5466
- }
5467
- if (result?.error?.status === 401) {
5468
- const requestUrl = typeof args === 'string' ? args : args?.url;
5469
- console.warn('[TokenRefresh] 401 received, attempting token refresh', {
5470
- url: requestUrl,
5471
- errorStatus: result.error.status,
5472
- isAlreadyRefreshing: isRefreshing,
5473
- });
5474
- // Use mutex to prevent concurrent refreshes
5475
- if (!isRefreshing) {
5476
- isRefreshing = true;
5477
- refreshPromise = attemptTokenRefresh(api).finally(() => {
5478
- isRefreshing = false;
5479
- refreshPromise = null;
5457
+ function withReauth(baseQuery) {
5458
+ return async (args, api, extraOptions) => {
5459
+ let result = await baseQuery(args, api, extraOptions);
5460
+ if (result?.error) {
5461
+ const requestUrl = typeof args === 'string' ? args : args?.url;
5462
+ console.debug('[AuthQuery] Request error', {
5463
+ url: requestUrl,
5464
+ status: result.error.status,
5465
+ data: result.error?.data,
5480
5466
  });
5481
5467
  }
5482
- const refreshed = await (refreshPromise || attemptTokenRefresh(api));
5483
- if (refreshed) {
5484
- console.debug('[TokenRefresh] Refresh succeeded retrying original request');
5485
- result = await authDataBaseQuery(args, api, extraOptions);
5486
- }
5487
- else {
5488
- console.error('[TokenRefresh] Refresh FAILED — dispatching logout');
5489
- api.dispatch(slice.logout());
5468
+ if (result?.error?.status === 401) {
5469
+ const requestUrl = typeof args === 'string' ? args : args?.url;
5470
+ console.warn('[TokenRefresh] 401 received, attempting token refresh', {
5471
+ url: requestUrl,
5472
+ errorStatus: result.error.status,
5473
+ isAlreadyRefreshing: isRefreshing,
5474
+ });
5475
+ // Use mutex to prevent concurrent refreshes across all APIs
5476
+ if (!isRefreshing) {
5477
+ isRefreshing = true;
5478
+ refreshPromise = attemptTokenRefresh(api).finally(() => {
5479
+ isRefreshing = false;
5480
+ });
5481
+ }
5482
+ const refreshed = await refreshPromise;
5483
+ // Safe to clear after all concurrent waiters have resolved
5484
+ refreshPromise = null;
5485
+ if (refreshed) {
5486
+ console.debug('[TokenRefresh] Refresh succeeded — retrying original request');
5487
+ result = await baseQuery(args, api, extraOptions);
5488
+ }
5489
+ else {
5490
+ console.error('[TokenRefresh] Refresh FAILED — dispatching logout');
5491
+ api.dispatch(slice.logout());
5492
+ }
5490
5493
  }
5494
+ return result;
5495
+ };
5496
+ }
5497
+
5498
+ /**
5499
+ * Shared helper to extract auth tokens from the Redux store.
5500
+ * Used by all RTK Query services to attach tokens to request headers
5501
+ * without depending on aws-amplify's Auth.currentSession().
5502
+ */
5503
+ function getAuthHeaders(getState) {
5504
+ const state = getState();
5505
+ const accessToken = state?.auth?.user?.accessToken;
5506
+ const idToken = state?.auth?.user?.idToken;
5507
+ return { accessToken, idToken };
5508
+ }
5509
+
5510
+ /**
5511
+ * Build a per-platform URL for user-scoped data endpoints.
5512
+ *
5513
+ * Native apps call the backend API Gateway directly and must use the canonical
5514
+ * path shape: `/data/user/{sub}/{endpoint}`.
5515
+ *
5516
+ * Web apps route library requests through their own Next.js `/api/user/*`
5517
+ * proxy layer, which then forwards to the same canonical backend path. That
5518
+ * proxy expects the legacy `/user/{endpoint}?sub=X` shape.
5519
+ */
5520
+ const userDataPath = (sub, endpoint, query) => {
5521
+ if (PLATFORM === 'native') {
5522
+ const suffix = query ? `?${query}` : '';
5523
+ return `/data/user/${sub}/${endpoint}${suffix}`;
5491
5524
  }
5492
- return result;
5525
+ const suffix = query ? `&${query}` : '';
5526
+ return `/user/${endpoint}?sub=${sub}${suffix}`;
5527
+ };
5528
+ // Create a dynamic baseQuery that resolves URL at request time and unwraps standard responses
5529
+ const createAuthBaseQuery = () => {
5530
+ const baseUrl = typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_API_AUTH_PREFIX
5531
+ ? process.env.NEXT_PUBLIC_API_AUTH_PREFIX
5532
+ : (API_AUTH_PREFIX || '');
5533
+ return createUnwrappingBaseQuery({
5534
+ baseUrl,
5535
+ prepareHeaders: (headers, { getState }) => {
5536
+ headers.set('Content-Type', 'application/json');
5537
+ const { accessToken, idToken } = getAuthHeaders(getState);
5538
+ if (accessToken && idToken) {
5539
+ headers.set('accesstoken', accessToken);
5540
+ headers.set('idtoken', idToken);
5541
+ }
5542
+ return headers;
5543
+ },
5544
+ credentials: 'include',
5545
+ });
5493
5546
  };
5547
+ const authDataBaseQueryWithReauth = withReauth(createAuthBaseQuery());
5494
5548
  const authApi = createApi({
5495
5549
  reducerPath: 'authApi',
5496
5550
  baseQuery: authDataBaseQueryWithReauth,
@@ -5636,49 +5690,57 @@ const authApi = createApi({
5636
5690
  // Dashboard data endpoints
5637
5691
  getStreak: builder.query({
5638
5692
  query: (sub) => ({
5639
- url: `/user/streak?sub=${sub}`,
5693
+ url: userDataPath(sub, 'streak'),
5640
5694
  method: 'GET',
5641
5695
  }),
5642
5696
  providesTags: ['Streak'],
5643
5697
  }),
5644
5698
  getWeeklyProgress: builder.query({
5645
5699
  query: (sub) => ({
5646
- url: `/user/weekly-progress?sub=${sub}`,
5700
+ url: userDataPath(sub, 'weekly-progress'),
5647
5701
  method: 'GET',
5648
5702
  }),
5649
5703
  providesTags: ['WeeklyProgress'],
5650
5704
  }),
5705
+ setWeeklyGoal: builder.mutation({
5706
+ query: ({ sub, goal }) => ({
5707
+ url: '/user/weekly-goal',
5708
+ method: 'PUT',
5709
+ body: { sub, goal },
5710
+ }),
5711
+ invalidatesTags: ['WeeklyProgress', 'UserData'],
5712
+ }),
5651
5713
  getWatchProgress: builder.query({
5652
5714
  query: ({ sub, limit = 1 }) => ({
5653
- url: `/user/watch-progress?sub=${sub}&limit=${limit}`,
5715
+ url: userDataPath(sub, 'watch-progress', `limit=${limit}`),
5654
5716
  method: 'GET',
5655
5717
  }),
5656
5718
  providesTags: ['WatchProgress'],
5657
5719
  }),
5658
5720
  getRecommendations: builder.query({
5659
5721
  query: ({ sub, limit = 8 }) => ({
5660
- url: `/user/recommendations?sub=${sub}&limit=${limit}`,
5722
+ url: userDataPath(sub, 'recommendations', `limit=${limit}`),
5661
5723
  method: 'GET',
5662
5724
  }),
5663
5725
  providesTags: ['Recommendations'],
5664
5726
  }),
5665
5727
  getActivityStats: builder.query({
5666
5728
  query: ({ sub, period = 'this-month' }) => ({
5667
- url: `/user/activity-stats?sub=${sub}&period=${period}`,
5729
+ url: userDataPath(sub, 'activity-stats', `period=${period}`),
5668
5730
  method: 'GET',
5669
5731
  }),
5670
5732
  providesTags: ['ActivityStats'],
5671
5733
  }),
5672
5734
  getActiveChallenges: builder.query({
5673
5735
  query: (sub) => ({
5674
- url: `/user/active-challenges?sub=${sub}`,
5736
+ url: userDataPath(sub, 'active-challenges'),
5675
5737
  method: 'GET',
5676
5738
  }),
5677
5739
  providesTags: ['UserData'],
5678
5740
  }),
5679
5741
  getChallengeProgress: builder.query({
5680
5742
  query: ({ sub, challengeId }) => ({
5681
- url: `/user/challenge-progress/${challengeId}?sub=${sub}`,
5743
+ url: userDataPath(sub, `challenge-progress/${challengeId}`),
5682
5744
  method: 'GET',
5683
5745
  }),
5684
5746
  providesTags: ['UserData'],
@@ -5686,7 +5748,8 @@ const authApi = createApi({
5686
5748
  // Activity logging — invalidates dashboard caches
5687
5749
  logActivity: builder.mutation({
5688
5750
  query: (data) => ({
5689
- url: '/activity',
5751
+ // Native hits the backend directly at /data/activity; web proxies via /activity → /data/activity
5752
+ url: PLATFORM === 'native' ? '/data/activity' : '/activity',
5690
5753
  method: 'POST',
5691
5754
  body: data,
5692
5755
  }),
@@ -5718,7 +5781,7 @@ const {
5718
5781
  // useLogoutQuery,
5719
5782
  // useLazyLogoutQuery,
5720
5783
  useResetPasswordMutation, // Use this for mobile app.
5721
- useResetPasswordAuthMutation, useRegisterMutation, useVerifyUserQuery, useLazyVerifyUserQuery, useGetUserInfoQuery, useLazyGetUserInfoQuery, useUpdateUserInfoMutation, useForgottenPasswordMutation, useVerifyUserAttributesQuery, useLazyVerifyUserAttributesQuery, useVerifyUserResendQuery, useLazyVerifyUserResendQuery, useUpdateUserMutation, useGetStreakQuery, useLazyGetStreakQuery, useGetWeeklyProgressQuery, useLazyGetWeeklyProgressQuery, useGetWatchProgressQuery, useLazyGetWatchProgressQuery, useGetRecommendationsQuery, useLazyGetRecommendationsQuery, useGetActivityStatsQuery, useLazyGetActivityStatsQuery, useLogActivityMutation, useGetActiveChallengesQuery, useGetChallengeProgressQuery, } = authApi;
5784
+ useResetPasswordAuthMutation, useRegisterMutation, useVerifyUserQuery, useLazyVerifyUserQuery, useGetUserInfoQuery, useLazyGetUserInfoQuery, useUpdateUserInfoMutation, useForgottenPasswordMutation, useVerifyUserAttributesQuery, useLazyVerifyUserAttributesQuery, useVerifyUserResendQuery, useLazyVerifyUserResendQuery, useUpdateUserMutation, useGetStreakQuery, useLazyGetStreakQuery, useGetWeeklyProgressQuery, useLazyGetWeeklyProgressQuery, useSetWeeklyGoalMutation, useGetWatchProgressQuery, useLazyGetWatchProgressQuery, useGetRecommendationsQuery, useLazyGetRecommendationsQuery, useGetActivityStatsQuery, useLazyGetActivityStatsQuery, useLogActivityMutation, useGetActiveChallengesQuery, useGetChallengeProgressQuery, } = authApi;
5722
5785
 
5723
5786
  // Create dynamic baseQuery that resolves URL at request time
5724
5787
  const createContentBaseQuery = () => {
@@ -5783,8 +5846,8 @@ const contentApi = createApi({
5783
5846
  });
5784
5847
  const { useGetDataQuery, useLazyGetDataQuery, useGetDataByIdQuery, useLazyGetDataByIdQuery, } = contentApi;
5785
5848
 
5786
- // Dynamic baseQuery that resolves URL at request time and unwraps standard responses
5787
- const dynamicBaseQuery$1 = async (args, api, extraOptions) => {
5849
+ // Dynamic baseQuery that resolves URL at request time, unwraps responses, and handles 401 reauth
5850
+ const dynamicBaseQuery$1 = withReauth(async (args, api, extraOptions) => {
5788
5851
  // Resolve base URL at request time, not module load time
5789
5852
  const baseUrl = typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_API_PAYMENTS_PREFIX
5790
5853
  ? process.env.NEXT_PUBLIC_API_PAYMENTS_PREFIX
@@ -5803,7 +5866,7 @@ const dynamicBaseQuery$1 = async (args, api, extraOptions) => {
5803
5866
  credentials: 'include',
5804
5867
  });
5805
5868
  return baseQuery(args, api, extraOptions);
5806
- };
5869
+ });
5807
5870
  const paymentApi = createApi({
5808
5871
  reducerPath: 'paymentApi',
5809
5872
  baseQuery: dynamicBaseQuery$1,
@@ -5848,8 +5911,8 @@ const paymentApi = createApi({
5848
5911
  // Export hooks for usage in functional components.
5849
5912
  const { useCheckUserSubscriptionQuery, useLazyCheckUserSubscriptionQuery, useGetPaymentPlansQuery, useLazyGetPaymentPlansQuery, useGetTaxRatesQuery, useLazyGetTaxRatesQuery, useCheckPromoCodeQuery, useLazyCheckPromoCodeQuery, } = paymentApi;
5850
5913
 
5851
- // Dynamic baseQuery that resolves URL at request time and unwraps standard responses
5852
- const dynamicBaseQuery = async (args, api, extraOptions) => {
5914
+ // Dynamic baseQuery that resolves URL at request time, unwraps responses, and handles 401 reauth
5915
+ const dynamicBaseQuery = withReauth(async (args, api, extraOptions) => {
5853
5916
  // Resolve base URL at request time, not module load time
5854
5917
  const baseUrl = typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_API_PAYMENTS_PREFIX
5855
5918
  ? process.env.NEXT_PUBLIC_API_PAYMENTS_PREFIX
@@ -5868,7 +5931,7 @@ const dynamicBaseQuery = async (args, api, extraOptions) => {
5868
5931
  credentials: 'include',
5869
5932
  });
5870
5933
  return baseQuery(args, api, extraOptions);
5871
- };
5934
+ });
5872
5935
  const productsApi = createApi({
5873
5936
  reducerPath: 'productsApi',
5874
5937
  baseQuery: dynamicBaseQuery,
@@ -5925,17 +5988,7 @@ const createOrdersBaseQuery = () => {
5925
5988
  credentials: 'include',
5926
5989
  });
5927
5990
  };
5928
- const dataBaseQuery = createOrdersBaseQuery();
5929
- /**
5930
- * This function is used to retry a request if we get a 401 error.
5931
- */
5932
- const dataBaseQueryWithReauth = async (args, api, extraOptions) => {
5933
- const result = await dataBaseQuery(args, api, extraOptions);
5934
- if (result?.error?.status === 401) {
5935
- api.dispatch(slice.logout());
5936
- }
5937
- return result;
5938
- };
5991
+ const dataBaseQueryWithReauth = withReauth(createOrdersBaseQuery());
5939
5992
  const ordersApi = createApi({
5940
5993
  reducerPath: 'ordersApi',
5941
5994
  baseQuery: dataBaseQueryWithReauth,
@@ -5958,9 +6011,12 @@ const ordersApi = createApi({
5958
6011
  * Get all partnership orders for a customer from Stripe.
5959
6012
  */
5960
6013
  getOrders: builder.query({
5961
- query: ({ customerId }) => ({
6014
+ query: ({ customerId, email }) => ({
5962
6015
  url: `/payment/orders`,
5963
- params: { customerId },
6016
+ params: {
6017
+ ...(customerId && { customerId }),
6018
+ ...(email && { email }),
6019
+ },
5964
6020
  }),
5965
6021
  providesTags: ['Orders'],
5966
6022
  }),
@@ -6229,9 +6285,11 @@ exports.usePurchaseProductMutation = usePurchaseProductMutation;
6229
6285
  exports.useRegisterMutation = useRegisterMutation;
6230
6286
  exports.useResetPasswordAuthMutation = useResetPasswordAuthMutation;
6231
6287
  exports.useResetPasswordMutation = useResetPasswordMutation;
6288
+ exports.useSetWeeklyGoalMutation = useSetWeeklyGoalMutation;
6232
6289
  exports.useUpdateUserInfoMutation = useUpdateUserInfoMutation;
6233
6290
  exports.useUpdateUserMutation = useUpdateUserMutation;
6234
6291
  exports.useVerifyUserAttributesQuery = useVerifyUserAttributesQuery;
6235
6292
  exports.useVerifyUserQuery = useVerifyUserQuery;
6236
6293
  exports.useVerifyUserResendQuery = useVerifyUserResendQuery;
6237
- //# sourceMappingURL=slice-C4MKCa5N.js.map
6294
+ exports.withReauth = withReauth;
6295
+ //# sourceMappingURL=slice-2_5ax6TZ.js.map