@techstuff-dev/foundation-api-utils 1.51.0 → 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/chunks/{shared-CPf85o9W.js → shared-DjCjH7LG.js} +2 -2
- package/dist/cjs/chunks/{shared-CPf85o9W.js.map → shared-DjCjH7LG.js.map} +1 -1
- package/dist/cjs/chunks/{slice-CHzSWFmR.js → slice-Jly4VFS9.js} +78 -7
- package/dist/cjs/chunks/slice-Jly4VFS9.js.map +1 -0
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/store/index.native.js +2 -2
- package/dist/cjs/store/index.web.js +2 -2
- package/dist/esm/chunks/{shared-9n1t2QnH.js → shared-DhOT8XMm.js} +2 -2
- package/dist/esm/chunks/{shared-9n1t2QnH.js.map → shared-DhOT8XMm.js.map} +1 -1
- package/dist/esm/chunks/{slice-Bersugzi.js → slice-CFI-0qr6.js} +79 -9
- package/dist/esm/chunks/slice-CFI-0qr6.js.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/store/index.native.js +2 -2
- package/dist/esm/store/index.web.js +2 -2
- package/dist/types/index.d.ts +53 -3
- package/package.json +1 -1
- package/dist/cjs/chunks/slice-CHzSWFmR.js.map +0 -1
- package/dist/esm/chunks/slice-Bersugzi.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var toolkit = require('@reduxjs/toolkit');
|
|
4
|
-
var slice = require('./slice-
|
|
4
|
+
var slice = require('./slice-Jly4VFS9.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.ordersApi);
|
|
12
12
|
|
|
13
13
|
exports.rootReducer = rootReducer;
|
|
14
|
-
//# sourceMappingURL=shared-
|
|
14
|
+
//# sourceMappingURL=shared-DjCjH7LG.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-
|
|
1
|
+
{"version":3,"file":"shared-DjCjH7LG.js","sources":["../../../lib/store/shared.ts"],"sourcesContent":[null],"names":["combineSlices","cartSlice","authSlice","authApi","contentApi","paymentApi","ordersApi"],"mappings":";;;;;;AAAA;AACA;AASA;AAEA;AACO,MAAM,WAAW,GAAGA,qBAAa,CACtCC,eAAS,EACTC,iBAAS,EACTC,aAAO,EACPC,gBAAU,EACVC,gBAAU,EACVC,eAAS;;;;"}
|
|
@@ -4684,6 +4684,75 @@ Hook ${hookName} was either not provided or not a function.`);
|
|
|
4684
4684
|
// src/query/react/index.ts
|
|
4685
4685
|
var createApi = /* @__PURE__ */ buildCreateApi(coreModule(), reactHooksModule());
|
|
4686
4686
|
|
|
4687
|
+
/**
|
|
4688
|
+
* Creates a base query that automatically unwraps standardized API responses.
|
|
4689
|
+
*
|
|
4690
|
+
* If the API returns `{ success: true, data: T }`, this will return just `T`.
|
|
4691
|
+
* If the API returns `{ success: false, error: {...} }`, this will pass through the error correctly.
|
|
4692
|
+
*
|
|
4693
|
+
* This eliminates the need for `transformResponse` on every endpoint when using
|
|
4694
|
+
* a standardized response format across your API routes.
|
|
4695
|
+
*
|
|
4696
|
+
* @param baseQueryOptions - The same options you would pass to fetchBaseQuery
|
|
4697
|
+
* @returns A BaseQueryFn that unwraps standardized responses
|
|
4698
|
+
*
|
|
4699
|
+
* @example
|
|
4700
|
+
* ```typescript
|
|
4701
|
+
* const api = createApi({
|
|
4702
|
+
* baseQuery: createUnwrappingBaseQuery({
|
|
4703
|
+
* baseUrl: '/api',
|
|
4704
|
+
* prepareHeaders: (headers) => {
|
|
4705
|
+
* // Add auth headers
|
|
4706
|
+
* return headers;
|
|
4707
|
+
* },
|
|
4708
|
+
* }),
|
|
4709
|
+
* endpoints: (builder) => ({
|
|
4710
|
+
* getPlans: builder.query<{ plans: Plan[] }, void>({
|
|
4711
|
+
* query: () => '/payment/plans',
|
|
4712
|
+
* // No need for transformResponse!
|
|
4713
|
+
* }),
|
|
4714
|
+
* }),
|
|
4715
|
+
* });
|
|
4716
|
+
* ```
|
|
4717
|
+
*/
|
|
4718
|
+
function createUnwrappingBaseQuery(baseQueryOptions) {
|
|
4719
|
+
const baseQuery = fetchBaseQuery(baseQueryOptions);
|
|
4720
|
+
return async (args, api, extraOptions) => {
|
|
4721
|
+
const result = await baseQuery(args, api, extraOptions);
|
|
4722
|
+
// If there's an error, return it as-is
|
|
4723
|
+
if (result.error) {
|
|
4724
|
+
return result;
|
|
4725
|
+
}
|
|
4726
|
+
// If there's data, check if it matches our standard format
|
|
4727
|
+
if (result.data) {
|
|
4728
|
+
const response = result.data;
|
|
4729
|
+
// Check if this is a wrapped response with success flag
|
|
4730
|
+
if (typeof response === 'object' && response !== null && 'success' in response) {
|
|
4731
|
+
// If success is false, treat it as an error
|
|
4732
|
+
if (response.success === false && response.error) {
|
|
4733
|
+
return {
|
|
4734
|
+
error: {
|
|
4735
|
+
status: 'CUSTOM_ERROR',
|
|
4736
|
+
data: response.error,
|
|
4737
|
+
},
|
|
4738
|
+
};
|
|
4739
|
+
}
|
|
4740
|
+
// If success is true and there's data, unwrap it
|
|
4741
|
+
if (response.success === true && 'data' in response) {
|
|
4742
|
+
return {
|
|
4743
|
+
...result,
|
|
4744
|
+
data: response.data,
|
|
4745
|
+
};
|
|
4746
|
+
}
|
|
4747
|
+
}
|
|
4748
|
+
// If it doesn't match our standard format, return as-is
|
|
4749
|
+
// (e.g., direct responses from external APIs like Elasticsearch)
|
|
4750
|
+
return result;
|
|
4751
|
+
}
|
|
4752
|
+
return result;
|
|
4753
|
+
};
|
|
4754
|
+
}
|
|
4755
|
+
|
|
4687
4756
|
function onlyUnique(value, index, self) {
|
|
4688
4757
|
return self.indexOf(value) === index;
|
|
4689
4758
|
}
|
|
@@ -5555,13 +5624,13 @@ apiConfig.APP_ES_CHALLENGES_INDEX;
|
|
|
5555
5624
|
apiConfig.APP_ES_CHALLENGE_DAYS_INDEX;
|
|
5556
5625
|
apiConfig.PLATFORM;
|
|
5557
5626
|
|
|
5558
|
-
// Create a dynamic baseQuery that resolves URL at request time
|
|
5627
|
+
// Create a dynamic baseQuery that resolves URL at request time and unwraps standard responses
|
|
5559
5628
|
const createAuthBaseQuery = () => {
|
|
5560
5629
|
const baseUrl = typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_API_AUTH_PREFIX
|
|
5561
5630
|
? process.env.NEXT_PUBLIC_API_AUTH_PREFIX
|
|
5562
5631
|
: (API_AUTH_PREFIX || '');
|
|
5563
5632
|
console.log('[authApi] Resolved baseUrl:', baseUrl);
|
|
5564
|
-
return
|
|
5633
|
+
return createUnwrappingBaseQuery({
|
|
5565
5634
|
baseUrl,
|
|
5566
5635
|
prepareHeaders: async (headers) => {
|
|
5567
5636
|
headers.set('Content-Type', 'application/json');
|
|
@@ -5712,9 +5781,10 @@ const authApi = createApi({
|
|
|
5712
5781
|
};
|
|
5713
5782
|
}
|
|
5714
5783
|
},
|
|
5784
|
+
// No need for transformResponse - createUnwrappingBaseQuery handles it
|
|
5715
5785
|
transformResponse: (rawResult) => {
|
|
5716
|
-
|
|
5717
|
-
return { route: 'success', message:
|
|
5786
|
+
// Additional custom transform after unwrapping
|
|
5787
|
+
return { route: 'success', message: rawResult?.message };
|
|
5718
5788
|
},
|
|
5719
5789
|
}),
|
|
5720
5790
|
verifyUserAttributes: builder.query({
|
|
@@ -5826,13 +5896,13 @@ const contentApi = createApi({
|
|
|
5826
5896
|
});
|
|
5827
5897
|
const { useGetDataQuery, useLazyGetDataQuery, useGetDataByIdQuery, useLazyGetDataByIdQuery, } = contentApi;
|
|
5828
5898
|
|
|
5829
|
-
// Dynamic baseQuery that resolves URL at request time
|
|
5899
|
+
// Dynamic baseQuery that resolves URL at request time and unwraps standard responses
|
|
5830
5900
|
const dynamicBaseQuery = async (args, api, extraOptions) => {
|
|
5831
5901
|
// Resolve base URL at request time, not module load time
|
|
5832
5902
|
const baseUrl = typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_API_PAYMENTS_PREFIX
|
|
5833
5903
|
? process.env.NEXT_PUBLIC_API_PAYMENTS_PREFIX
|
|
5834
5904
|
: (API_PAYMENTS_PREFIX || '');
|
|
5835
|
-
const baseQuery =
|
|
5905
|
+
const baseQuery = createUnwrappingBaseQuery({
|
|
5836
5906
|
baseUrl,
|
|
5837
5907
|
prepareHeaders: async (headers) => {
|
|
5838
5908
|
headers.set('Content-Type', 'application/json');
|
|
@@ -6126,6 +6196,7 @@ exports.applyTax = applyTax;
|
|
|
6126
6196
|
exports.authApi = authApi;
|
|
6127
6197
|
exports.cartSlice = cartSlice;
|
|
6128
6198
|
exports.contentApi = contentApi;
|
|
6199
|
+
exports.createUnwrappingBaseQuery = createUnwrappingBaseQuery;
|
|
6129
6200
|
exports.emptyCart = emptyCart;
|
|
6130
6201
|
exports.formatAuthSession = formatAuthSession;
|
|
6131
6202
|
exports.formatChallengeDays = formatChallengeDays;
|
|
@@ -6192,4 +6263,4 @@ exports.useUpdateUserMutation = useUpdateUserMutation;
|
|
|
6192
6263
|
exports.useVerifyUserAttributesQuery = useVerifyUserAttributesQuery;
|
|
6193
6264
|
exports.useVerifyUserQuery = useVerifyUserQuery;
|
|
6194
6265
|
exports.useVerifyUserResendQuery = useVerifyUserResendQuery;
|
|
6195
|
-
//# sourceMappingURL=slice-
|
|
6266
|
+
//# sourceMappingURL=slice-Jly4VFS9.js.map
|