@techstuff-dev/foundation-api-utils 1.50.3 → 1.52.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/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var slice = require('./chunks/slice-Cy4kZKn1.js');
3
+ var slice = require('./chunks/slice-Jly4VFS9.js');
4
4
  var slice$1 = require('./chunks/slice-CkWobkWw.js');
5
5
  var useAuth = require('./chunks/useAuth-DKhvUX_r.js');
6
6
  require('aws-amplify');
@@ -17,6 +17,7 @@ exports.applyTax = slice.applyTax;
17
17
  exports.authApi = slice.authApi;
18
18
  exports.cartSlice = slice.cartSlice;
19
19
  exports.contentApi = slice.contentApi;
20
+ exports.createUnwrappingBaseQuery = slice.createUnwrappingBaseQuery;
20
21
  exports.emptyCart = slice.emptyCart;
21
22
  exports.formatAuthSession = slice.formatAuthSession;
22
23
  exports.formatChallengeDays = slice.formatChallengeDays;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,10 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var toolkit = require('@reduxjs/toolkit');
4
- var reactNative = require('react-native');
5
4
  var storage = require('@react-native-async-storage/async-storage');
6
- var slice = require('../chunks/slice-Cy4kZKn1.js');
7
- var shared = require('../chunks/shared-9ChxyDgv.js');
5
+ var slice = require('../chunks/slice-Jly4VFS9.js');
6
+ var shared = require('../chunks/shared-DjCjH7LG.js');
8
7
  require('aws-amplify');
9
8
  require('../chunks/slice-CkWobkWw.js');
10
9
  require('react-redux');
@@ -31,8 +30,6 @@ const storageBlackList = [];
31
30
  // are needed for each request to prevent cross-request state pollution.
32
31
  const makeStore = () => {
33
32
  const customEnhancers = [];
34
- // eslint-disable-next-line no-console
35
- console.log('makeNativeStore Platform', reactNative.Platform);
36
33
  // eslint-disable-next-line @typescript-eslint/no-require-imports
37
34
  const reduxPersist = require('redux-persist');
38
35
  // eslint-disable-next-line @typescript-eslint/no-require-imports
@@ -1 +1 @@
1
- {"version":3,"file":"index.native.js","sources":["../../../lib/store/index.native.ts"],"sourcesContent":[null],"names":["Platform","paymentApi","authApi","contentApi","ordersApi","rootReducer","configureStore"],"mappings":";;;;;;;;;;;;;AAoBA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA,MAAM,gBAAgB,GAAa,EAAE;AAErC;AACA;AACA;AACA;AACO,MAAM,SAAS,GAAG,MAAK;IAC5B,MAAM,eAAe,GAAQ,EAAE;;AAG/B,IAAA,OAAO,CAAC,GAAG,CAAC,0BAA0B,EAAEA,oBAAQ,CAAC;;AAGjD,IAAA,MAAM,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC;;IAE7C,MAAM,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC,cAAc;AAC9D,IAAA,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK;AAChC,IAAA,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS;AACxC,IAAA,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK;AAChC,IAAA,MAAM,OAAO,GAAG,YAAY,CAAC,OAAO;AACpC,IAAA,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK;AAChC,IAAA,MAAM,QAAQ,GAAG,YAAY,CAAC,QAAQ;AAEtC,IAAA,gBAAgB,CAAC,IAAI,CACnBC,gBAAU,CAAC,WAAW,EACtBC,aAAO,CAAC,WAAW,EACnBC,gBAAU,CAAC,WAAW,EACtBC,eAAS,CAAC,WAAW,CACtB;AAED,IAAA,MAAM,aAAa,GAAG;AACpB,QAAA,GAAG,EAAE,MAAM;QACX,OAAO;;AAEP,QAAA,SAAS,EAAE,gBAAgB;KAC5B;IACD,MAAM,gBAAgB,GAAG,cAAc,CAAC,aAAa,EAAEC,kBAAW,CAAC;IACnE,MAAM,YAAY,GAAG,gBAAgB;AAErC,IAAA,MAAM,WAAW,GAAG;AAClB,QAAAH,aAAO,CAAC,UAAU;AAClB,QAAAC,gBAAU,CAAC,UAAU;AACrB,QAAAF,gBAAU,CAAC,UAAU;AACrB,QAAAG,eAAS,CAAC,UAAU;KACrB;AAED,IAAA,OAAOE,sBAAc,CAAC;AACpB,QAAA,OAAO,EAAE,YAAY;;;AAGrB,QAAA,UAAU,EAAE,CAAC,oBAAoB,KAAI;AACnC,YAAA,OAAO,oBAAoB,CAAC;AAC1B,gBAAA,cAAc,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE;AAClC,gBAAA,iBAAiB,EAAE;AACjB,oBAAA,SAAS,EAAE,GAAG;AACd,oBAAA,cAAc,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC;AACpE,iBAAA;AACF,aAAA,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC;QACxB,CAAC;AACD,QAAA,SAAS,EAAE,CAAC,mBAAmB,KAAI;AACjC,YAAA,OAAO,mBAAmB,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC;QACtD,CAAC;AACF,KAAA,CAAC;AACJ;AAEO,MAAM,KAAK,GAAG,SAAS;;;;;"}
1
+ {"version":3,"file":"index.native.js","sources":["../../../lib/store/index.native.ts"],"sourcesContent":[null],"names":["paymentApi","authApi","contentApi","ordersApi","rootReducer","configureStore"],"mappings":";;;;;;;;;;;;AAoBA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA,MAAM,gBAAgB,GAAa,EAAE;AAErC;AACA;AACA;AACA;AACO,MAAM,SAAS,GAAG,MAAK;IAC5B,MAAM,eAAe,GAAQ,EAAE;;AAG/B,IAAA,MAAM,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC;;IAE7C,MAAM,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC,cAAc;AAC9D,IAAA,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK;AAChC,IAAA,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS;AACxC,IAAA,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK;AAChC,IAAA,MAAM,OAAO,GAAG,YAAY,CAAC,OAAO;AACpC,IAAA,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK;AAChC,IAAA,MAAM,QAAQ,GAAG,YAAY,CAAC,QAAQ;AAEtC,IAAA,gBAAgB,CAAC,IAAI,CACnBA,gBAAU,CAAC,WAAW,EACtBC,aAAO,CAAC,WAAW,EACnBC,gBAAU,CAAC,WAAW,EACtBC,eAAS,CAAC,WAAW,CACtB;AAED,IAAA,MAAM,aAAa,GAAG;AACpB,QAAA,GAAG,EAAE,MAAM;QACX,OAAO;;AAEP,QAAA,SAAS,EAAE,gBAAgB;KAC5B;IACD,MAAM,gBAAgB,GAAG,cAAc,CAAC,aAAa,EAAEC,kBAAW,CAAC;IACnE,MAAM,YAAY,GAAG,gBAAgB;AAErC,IAAA,MAAM,WAAW,GAAG;AAClB,QAAAH,aAAO,CAAC,UAAU;AAClB,QAAAC,gBAAU,CAAC,UAAU;AACrB,QAAAF,gBAAU,CAAC,UAAU;AACrB,QAAAG,eAAS,CAAC,UAAU;KACrB;AAED,IAAA,OAAOE,sBAAc,CAAC;AACpB,QAAA,OAAO,EAAE,YAAY;;;AAGrB,QAAA,UAAU,EAAE,CAAC,oBAAoB,KAAI;AACnC,YAAA,OAAO,oBAAoB,CAAC;AAC1B,gBAAA,cAAc,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE;AAClC,gBAAA,iBAAiB,EAAE;AACjB,oBAAA,SAAS,EAAE,GAAG;AACd,oBAAA,cAAc,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC;AACpE,iBAAA;AACF,aAAA,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC;QACxB,CAAC;AACD,QAAA,SAAS,EAAE,CAAC,mBAAmB,KAAI;AACjC,YAAA,OAAO,mBAAmB,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC;QACtD,CAAC;AACF,KAAA,CAAC;AACJ;AAEO,MAAM,KAAK,GAAG,SAAS;;;;;"}
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var toolkit = require('@reduxjs/toolkit');
4
- var slice = require('../chunks/slice-Cy4kZKn1.js');
5
- var shared = require('../chunks/shared-9ChxyDgv.js');
4
+ var slice = require('../chunks/slice-Jly4VFS9.js');
5
+ var shared = require('../chunks/shared-DjCjH7LG.js');
6
6
  require('aws-amplify');
7
7
  require('../chunks/slice-CkWobkWw.js');
8
8
  require('react-redux');
@@ -1,5 +1,5 @@
1
1
  import { combineSlices } from '@reduxjs/toolkit';
2
- import { r as cartSlice, a as authApi, c as contentApi, p as paymentApi, o as ordersApi } from './slice-qwy3bNV7.js';
2
+ import { r as cartSlice, a as authApi, c as contentApi, p as paymentApi, o as ordersApi } from './slice-CFI-0qr6.js';
3
3
  import { a as authSlice } from './slice-ChJ8ZvmP.js';
4
4
 
5
5
  // This file exists just so TypeScript has a module at ./store for IDEs/build.
@@ -9,4 +9,4 @@ import { a as authSlice } from './slice-ChJ8ZvmP.js';
9
9
  const rootReducer = combineSlices(cartSlice, authSlice, authApi, contentApi, paymentApi, ordersApi);
10
10
 
11
11
  export { rootReducer as r };
12
- //# sourceMappingURL=shared-Dq2QUWdW.js.map
12
+ //# sourceMappingURL=shared-DhOT8XMm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared-Dq2QUWdW.js","sources":["../../../lib/store/shared.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAAA;AACA;AASA;AAEA;AACO,MAAM,WAAW,GAAG,aAAa,CACtC,SAAS,EACT,SAAS,EACT,OAAO,EACP,UAAU,EACV,UAAU,EACV,SAAS;;;;"}
1
+ {"version":3,"file":"shared-DhOT8XMm.js","sources":["../../../lib/store/shared.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAAA;AACA;AASA;AAEA;AACO,MAAM,WAAW,GAAG,aAAa,CACtC,SAAS,EACT,SAAS,EACT,OAAO,EACP,UAAU,EACV,UAAU,EACV,SAAS;;;;"}
@@ -1,6 +1,6 @@
1
1
  import { Auth } from 'aws-amplify';
2
2
  import { r as resetCreating, s as setCredentials, l as logout } from './slice-ChJ8ZvmP.js';
3
- import { isPlainObject as isPlainObject$1, nanoid, formatProdErrorMessage, createAction, createSelector as createSelector$1, createNextState, createAsyncThunk, createSlice, prepareAutoBatched, isAnyOf, isFulfilled, isRejectedWithValue, combineReducers, SHOULD_AUTOBATCH, isAllOf, isRejected, isPending, isAction, isAsyncThunkAction } from '@reduxjs/toolkit';
3
+ import { nanoid, formatProdErrorMessage, createAction, createSelector as createSelector$1, isPlainObject as isPlainObject$1, createNextState, createAsyncThunk, createSlice, prepareAutoBatched, isAnyOf, isFulfilled, isRejectedWithValue, combineReducers, SHOULD_AUTOBATCH, isAllOf, isRejected, isPending, isAction, isAsyncThunkAction } from '@reduxjs/toolkit';
4
4
  import { useStore, useSelector, useDispatch, batch, shallowEqual } from 'react-redux';
5
5
  import { useCallback, useDebugValue, useMemo, useState, useEffect, useRef, useLayoutEffect } from 'react';
6
6
  import { jwtDecode } from 'jwt-decode';
@@ -4682,6 +4682,75 @@ Hook ${hookName} was either not provided or not a function.`);
4682
4682
  // src/query/react/index.ts
4683
4683
  var createApi = /* @__PURE__ */ buildCreateApi(coreModule(), reactHooksModule());
4684
4684
 
4685
+ /**
4686
+ * Creates a base query that automatically unwraps standardized API responses.
4687
+ *
4688
+ * If the API returns `{ success: true, data: T }`, this will return just `T`.
4689
+ * If the API returns `{ success: false, error: {...} }`, this will pass through the error correctly.
4690
+ *
4691
+ * This eliminates the need for `transformResponse` on every endpoint when using
4692
+ * a standardized response format across your API routes.
4693
+ *
4694
+ * @param baseQueryOptions - The same options you would pass to fetchBaseQuery
4695
+ * @returns A BaseQueryFn that unwraps standardized responses
4696
+ *
4697
+ * @example
4698
+ * ```typescript
4699
+ * const api = createApi({
4700
+ * baseQuery: createUnwrappingBaseQuery({
4701
+ * baseUrl: '/api',
4702
+ * prepareHeaders: (headers) => {
4703
+ * // Add auth headers
4704
+ * return headers;
4705
+ * },
4706
+ * }),
4707
+ * endpoints: (builder) => ({
4708
+ * getPlans: builder.query<{ plans: Plan[] }, void>({
4709
+ * query: () => '/payment/plans',
4710
+ * // No need for transformResponse!
4711
+ * }),
4712
+ * }),
4713
+ * });
4714
+ * ```
4715
+ */
4716
+ function createUnwrappingBaseQuery(baseQueryOptions) {
4717
+ const baseQuery = fetchBaseQuery(baseQueryOptions);
4718
+ return async (args, api, extraOptions) => {
4719
+ const result = await baseQuery(args, api, extraOptions);
4720
+ // If there's an error, return it as-is
4721
+ if (result.error) {
4722
+ return result;
4723
+ }
4724
+ // If there's data, check if it matches our standard format
4725
+ if (result.data) {
4726
+ const response = result.data;
4727
+ // Check if this is a wrapped response with success flag
4728
+ if (typeof response === 'object' && response !== null && 'success' in response) {
4729
+ // If success is false, treat it as an error
4730
+ if (response.success === false && response.error) {
4731
+ return {
4732
+ error: {
4733
+ status: 'CUSTOM_ERROR',
4734
+ data: response.error,
4735
+ },
4736
+ };
4737
+ }
4738
+ // If success is true and there's data, unwrap it
4739
+ if (response.success === true && 'data' in response) {
4740
+ return {
4741
+ ...result,
4742
+ data: response.data,
4743
+ };
4744
+ }
4745
+ }
4746
+ // If it doesn't match our standard format, return as-is
4747
+ // (e.g., direct responses from external APIs like Elasticsearch)
4748
+ return result;
4749
+ }
4750
+ return result;
4751
+ };
4752
+ }
4753
+
4685
4754
  function onlyUnique(value, index, self) {
4686
4755
  return self.indexOf(value) === index;
4687
4756
  }
@@ -5393,7 +5462,8 @@ const runOnPlatform = (config) => {
5393
5462
  */
5394
5463
  // Helper function to get environment variable with fallback
5395
5464
  const getEnvVar$1 = (key, fallback = '') => {
5396
- return process.env[key] || fallback;
5465
+ const value = process.env[key] || fallback;
5466
+ return value;
5397
5467
  };
5398
5468
  // Core API endpoints
5399
5469
  const API_PREFIX$1 = getEnvVar$1('NEXT_PUBLIC_API_PREFIX');
@@ -5552,30 +5622,38 @@ apiConfig.APP_ES_CHALLENGES_INDEX;
5552
5622
  apiConfig.APP_ES_CHALLENGE_DAYS_INDEX;
5553
5623
  apiConfig.PLATFORM;
5554
5624
 
5555
- const authDataBaseQuery = fetchBaseQuery({
5556
- baseUrl: API_AUTH_PREFIX,
5557
- prepareHeaders: async (headers) => {
5558
- headers.set('Content-Type', 'application/json');
5559
- try {
5560
- // add accessToken to headers from slice using selectAccessToken selector
5561
- const session = await Auth.currentSession();
5562
- const idToken = session.getIdToken().getJwtToken(); // ID token
5563
- const accessToken = session.getAccessToken().getJwtToken(); // Access token
5564
- if (accessToken && idToken) {
5565
- headers.set('accesstoken', accessToken);
5566
- headers.set('idtoken', idToken);
5567
- // headers.set('refreshtoken', tokens.refreshToken);
5625
+ // Create a dynamic baseQuery that resolves URL at request time and unwraps standard responses
5626
+ const createAuthBaseQuery = () => {
5627
+ const baseUrl = typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_API_AUTH_PREFIX
5628
+ ? process.env.NEXT_PUBLIC_API_AUTH_PREFIX
5629
+ : (API_AUTH_PREFIX || '');
5630
+ console.log('[authApi] Resolved baseUrl:', baseUrl);
5631
+ return createUnwrappingBaseQuery({
5632
+ baseUrl,
5633
+ prepareHeaders: async (headers) => {
5634
+ headers.set('Content-Type', 'application/json');
5635
+ try {
5636
+ // add accessToken to headers from slice using selectAccessToken selector
5637
+ const session = await Auth.currentSession();
5638
+ const idToken = session.getIdToken().getJwtToken(); // ID token
5639
+ const accessToken = session.getAccessToken().getJwtToken(); // Access token
5640
+ if (accessToken && idToken) {
5641
+ headers.set('accesstoken', accessToken);
5642
+ headers.set('idtoken', idToken);
5643
+ // headers.set('refreshtoken', tokens.refreshToken);
5644
+ }
5645
+ return headers;
5568
5646
  }
5569
- return headers;
5570
- }
5571
- catch (error) {
5572
- // eslint-disable-next-line no-console
5573
- console.error('authDataBaseQuery: ', error);
5574
- return headers;
5575
- }
5576
- },
5577
- credentials: 'include',
5578
- });
5647
+ catch (error) {
5648
+ // eslint-disable-next-line no-console
5649
+ console.error('authDataBaseQuery: ', error);
5650
+ return headers;
5651
+ }
5652
+ },
5653
+ credentials: 'include',
5654
+ });
5655
+ };
5656
+ const authDataBaseQuery = createAuthBaseQuery();
5579
5657
  /**
5580
5658
  * This function is used to retry a request if we get a 401 error.
5581
5659
  */
@@ -5701,9 +5779,10 @@ const authApi = createApi({
5701
5779
  };
5702
5780
  }
5703
5781
  },
5782
+ // No need for transformResponse - createUnwrappingBaseQuery handles it
5704
5783
  transformResponse: (rawResult) => {
5705
- const { data } = rawResult;
5706
- return { route: 'success', message: data?.message };
5784
+ // Additional custom transform after unwrapping
5785
+ return { route: 'success', message: rawResult?.message };
5707
5786
  },
5708
5787
  }),
5709
5788
  verifyUserAttributes: builder.query({
@@ -5756,15 +5835,25 @@ const {
5756
5835
  useResetPasswordMutation, // Use this for mobile app.
5757
5836
  useResetPasswordAuthMutation, useRegisterMutation, useVerifyUserQuery, useLazyVerifyUserQuery, useGetUserInfoQuery, useLazyGetUserInfoQuery, useUpdateUserInfoMutation, useForgottenPasswordMutation, useVerifyUserAttributesQuery, useLazyVerifyUserAttributesQuery, useVerifyUserResendQuery, useLazyVerifyUserResendQuery, useUpdateUserMutation, } = authApi;
5758
5837
 
5759
- const contentApi = createApi({
5760
- reducerPath: 'contentApi',
5761
- baseQuery: fetchBaseQuery({
5762
- baseUrl: APP_ES_INSTANCE,
5838
+ // Create dynamic baseQuery that resolves URL at request time
5839
+ const createContentBaseQuery = () => {
5840
+ const baseUrl = typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_ELASTICSEARCH_HOST
5841
+ ? process.env.NEXT_PUBLIC_ELASTICSEARCH_HOST
5842
+ : (APP_ES_INSTANCE || '');
5843
+ const auth = typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_APP_ES_AUTH
5844
+ ? process.env.NEXT_PUBLIC_APP_ES_AUTH
5845
+ : (APP_ES_AUTH || '');
5846
+ return fetchBaseQuery({
5847
+ baseUrl,
5763
5848
  prepareHeaders: (headers) => {
5764
- headers.set('Authorization', APP_ES_AUTH);
5849
+ headers.set('Authorization', auth);
5765
5850
  return headers;
5766
5851
  },
5767
- }),
5852
+ });
5853
+ };
5854
+ const contentApi = createApi({
5855
+ reducerPath: 'contentApi',
5856
+ baseQuery: createContentBaseQuery(),
5768
5857
  tagTypes: ['Data', 'Workout'],
5769
5858
  // keepUnusedDataFor: 300,
5770
5859
  endpoints: (builder) => ({
@@ -5805,10 +5894,14 @@ const contentApi = createApi({
5805
5894
  });
5806
5895
  const { useGetDataQuery, useLazyGetDataQuery, useGetDataByIdQuery, useLazyGetDataByIdQuery, } = contentApi;
5807
5896
 
5808
- const paymentApi = createApi({
5809
- reducerPath: 'paymentApi',
5810
- baseQuery: fetchBaseQuery({
5811
- baseUrl: API_PAYMENTS_PREFIX,
5897
+ // Dynamic baseQuery that resolves URL at request time and unwraps standard responses
5898
+ const dynamicBaseQuery = async (args, api, extraOptions) => {
5899
+ // Resolve base URL at request time, not module load time
5900
+ const baseUrl = typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_API_PAYMENTS_PREFIX
5901
+ ? process.env.NEXT_PUBLIC_API_PAYMENTS_PREFIX
5902
+ : (API_PAYMENTS_PREFIX || '');
5903
+ const baseQuery = createUnwrappingBaseQuery({
5904
+ baseUrl,
5812
5905
  prepareHeaders: async (headers) => {
5813
5906
  headers.set('Content-Type', 'application/json');
5814
5907
  // add accessToken to headers from slice using selectAccessToken selector
@@ -5823,7 +5916,12 @@ const paymentApi = createApi({
5823
5916
  return headers;
5824
5917
  },
5825
5918
  credentials: 'include',
5826
- }),
5919
+ });
5920
+ return baseQuery(args, api, extraOptions);
5921
+ };
5922
+ const paymentApi = createApi({
5923
+ reducerPath: 'paymentApi',
5924
+ baseQuery: dynamicBaseQuery,
5827
5925
  tagTypes: ['UserSubscription', 'Plans', 'TaxRates', 'PromoCodes'],
5828
5926
  // keepUnusedDataFor: 300,
5829
5927
  endpoints: (builder) => ({
@@ -5865,23 +5963,30 @@ const paymentApi = createApi({
5865
5963
  // Export hooks for usage in functional components.
5866
5964
  const { useCheckUserSubscriptionQuery, useLazyCheckUserSubscriptionQuery, useGetPaymentPlansQuery, useLazyGetPaymentPlansQuery, useGetTaxRatesQuery, useLazyGetTaxRatesQuery, useCheckPromoCodeQuery, useLazyCheckPromoCodeQuery, } = paymentApi;
5867
5965
 
5868
- const dataBaseQuery = fetchBaseQuery({
5869
- baseUrl: API_ORDERS_PREFIX,
5870
- prepareHeaders: async (headers) => {
5871
- headers.set('Content-Type', 'application/json');
5872
- // add accessToken to headers from slice using selectAccessToken selector
5873
- const session = await Auth.currentSession();
5874
- const idToken = session.getIdToken().getJwtToken(); // ID token
5875
- const accessToken = session.getAccessToken().getJwtToken(); // Access token
5876
- if (accessToken && idToken) {
5877
- headers.set('accesstoken', accessToken);
5878
- headers.set('idtoken', idToken);
5879
- // headers.set('refreshtoken', tokens.refreshToken);
5880
- }
5881
- return headers;
5882
- },
5883
- credentials: 'include',
5884
- });
5966
+ // Create dynamic baseQuery that resolves URL at request time
5967
+ const createOrdersBaseQuery = () => {
5968
+ const baseUrl = typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_API_ORDERS_PREFIX
5969
+ ? process.env.NEXT_PUBLIC_API_ORDERS_PREFIX
5970
+ : (API_ORDERS_PREFIX || '');
5971
+ return fetchBaseQuery({
5972
+ baseUrl,
5973
+ prepareHeaders: async (headers) => {
5974
+ headers.set('Content-Type', 'application/json');
5975
+ // add accessToken to headers from slice using selectAccessToken selector
5976
+ const session = await Auth.currentSession();
5977
+ const idToken = session.getIdToken().getJwtToken(); // ID token
5978
+ const accessToken = session.getAccessToken().getJwtToken(); // Access token
5979
+ if (accessToken && idToken) {
5980
+ headers.set('accesstoken', accessToken);
5981
+ headers.set('idtoken', idToken);
5982
+ // headers.set('refreshtoken', tokens.refreshToken);
5983
+ }
5984
+ return headers;
5985
+ },
5986
+ credentials: 'include',
5987
+ });
5988
+ };
5989
+ const dataBaseQuery = createOrdersBaseQuery();
5885
5990
  /**
5886
5991
  * This function is used to retry a request if we get a 401 error.
5887
5992
  */
@@ -6083,5 +6188,5 @@ const selectCartItemsIds = createSelector$1([selectMediaInCart], (items) => {
6083
6188
  });
6084
6189
  cartSlice.reducer;
6085
6190
 
6086
- export { formatAuthSession as $, emptyCart as A, toggleCart as B, selectMediaInCart as C, selectCartTotal as D, selectCartNetTotal as E, selectCartTaxRate as F, selectCartTaxAmount as G, selectCartCount as H, selectCartStatus as I, selectPromoCode as J, selectCartItems as K, selectCartItemsIds as L, formatUserPayload as M, formatPromos as N, formatWorkout as O, formatShortform as P, formatFaqs as Q, formatPages as R, formatSettings as S, formatPress as T, formatGuests as U, formatVideos as V, formatSections as W, formatSchedule as X, formatChallenges as Y, formatChallengeDays as Z, formatSecondsToISO8601Duration as _, authApi as a, formatFedaratedSession as a0, formatSocialAuthSession as a1, formatConfig as a2, formatSectionPanels as a3, formatSectionItems as a4, formatTaxonomies as a5, formatSeries as a6, formatSeasons as a7, formatLongform as a8, formatMediaItem as a9, isWeb as aa, isReactNative as ab, getPlatform as ac, runOnPlatform as ad, onlyUnique as ae, applyCoupon as af, applyTax as ag, toCamelCaseObject as ah, useResetPasswordAuthMutation as b, contentApi as c, useRegisterMutation as d, useVerifyUserQuery as e, useLazyVerifyUserQuery as f, useGetUserInfoQuery as g, useLazyGetUserInfoQuery as h, useUpdateUserInfoMutation as i, useForgottenPasswordMutation as j, useVerifyUserAttributesQuery as k, useLazyVerifyUserAttributesQuery as l, useVerifyUserResendQuery as m, useLazyVerifyUserResendQuery as n, ordersApi as o, paymentApi as p, useUpdateUserMutation as q, cartSlice as r, setTaxRate as s, resetTaxRate as t, useResetPasswordMutation as u, setPromoCode as v, removePromoCode as w, addToCart as x, updateCart as y, removeFromCart as z };
6087
- //# sourceMappingURL=slice-qwy3bNV7.js.map
6191
+ export { formatAuthSession as $, emptyCart as A, toggleCart as B, selectMediaInCart as C, selectCartTotal as D, selectCartNetTotal as E, selectCartTaxRate as F, selectCartTaxAmount as G, selectCartCount as H, selectCartStatus as I, selectPromoCode as J, selectCartItems as K, selectCartItemsIds as L, formatUserPayload as M, formatPromos as N, formatWorkout as O, formatShortform as P, formatFaqs as Q, formatPages as R, formatSettings as S, formatPress as T, formatGuests as U, formatVideos as V, formatSections as W, formatSchedule as X, formatChallenges as Y, formatChallengeDays as Z, formatSecondsToISO8601Duration as _, authApi as a, formatFedaratedSession as a0, formatSocialAuthSession as a1, formatConfig as a2, formatSectionPanels as a3, formatSectionItems as a4, formatTaxonomies as a5, formatSeries as a6, formatSeasons as a7, formatLongform as a8, formatMediaItem as a9, isWeb as aa, isReactNative as ab, getPlatform as ac, runOnPlatform as ad, onlyUnique as ae, applyCoupon as af, applyTax as ag, toCamelCaseObject as ah, createUnwrappingBaseQuery as ai, useResetPasswordAuthMutation as b, contentApi as c, useRegisterMutation as d, useVerifyUserQuery as e, useLazyVerifyUserQuery as f, useGetUserInfoQuery as g, useLazyGetUserInfoQuery as h, useUpdateUserInfoMutation as i, useForgottenPasswordMutation as j, useVerifyUserAttributesQuery as k, useLazyVerifyUserAttributesQuery as l, useVerifyUserResendQuery as m, useLazyVerifyUserResendQuery as n, ordersApi as o, paymentApi as p, useUpdateUserMutation as q, cartSlice as r, setTaxRate as s, resetTaxRate as t, useResetPasswordMutation as u, setPromoCode as v, removePromoCode as w, addToCart as x, updateCart as y, removeFromCart as z };
6192
+ //# sourceMappingURL=slice-CFI-0qr6.js.map