@techstuff-dev/foundation-api-utils 1.51.0 → 1.52.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.
- package/dist/cjs/chunks/{shared-CPf85o9W.js → shared-YoGh9ksj.js} +2 -2
- package/dist/cjs/chunks/{shared-CPf85o9W.js.map → shared-YoGh9ksj.js.map} +1 -1
- package/dist/cjs/chunks/{slice-CHzSWFmR.js → slice-4qoZ1wSU.js} +84 -9
- package/dist/cjs/chunks/slice-4qoZ1wSU.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-DYJftbDt.js} +2 -2
- package/dist/esm/chunks/{shared-9n1t2QnH.js.map → shared-DYJftbDt.js.map} +1 -1
- package/dist/esm/chunks/{slice-Bersugzi.js → slice-DJ0YEPf7.js} +85 -11
- package/dist/esm/chunks/slice-DJ0YEPf7.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-4qoZ1wSU.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-YoGh9ksj.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-
|
|
1
|
+
{"version":3,"file":"shared-YoGh9ksj.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({
|
|
@@ -5813,8 +5883,12 @@ const contentApi = createApi({
|
|
|
5813
5883
|
from: 0,
|
|
5814
5884
|
size: ids.length,
|
|
5815
5885
|
query: {
|
|
5816
|
-
|
|
5817
|
-
|
|
5886
|
+
bool: {
|
|
5887
|
+
should: [
|
|
5888
|
+
{ terms: { 'uuid': ids } },
|
|
5889
|
+
{ terms: { 'uuid.keyword': ids } },
|
|
5890
|
+
],
|
|
5891
|
+
minimum_should_match: 1, // ensures at least one must match
|
|
5818
5892
|
},
|
|
5819
5893
|
},
|
|
5820
5894
|
},
|
|
@@ -5826,13 +5900,13 @@ const contentApi = createApi({
|
|
|
5826
5900
|
});
|
|
5827
5901
|
const { useGetDataQuery, useLazyGetDataQuery, useGetDataByIdQuery, useLazyGetDataByIdQuery, } = contentApi;
|
|
5828
5902
|
|
|
5829
|
-
// Dynamic baseQuery that resolves URL at request time
|
|
5903
|
+
// Dynamic baseQuery that resolves URL at request time and unwraps standard responses
|
|
5830
5904
|
const dynamicBaseQuery = async (args, api, extraOptions) => {
|
|
5831
5905
|
// Resolve base URL at request time, not module load time
|
|
5832
5906
|
const baseUrl = typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_API_PAYMENTS_PREFIX
|
|
5833
5907
|
? process.env.NEXT_PUBLIC_API_PAYMENTS_PREFIX
|
|
5834
5908
|
: (API_PAYMENTS_PREFIX || '');
|
|
5835
|
-
const baseQuery =
|
|
5909
|
+
const baseQuery = createUnwrappingBaseQuery({
|
|
5836
5910
|
baseUrl,
|
|
5837
5911
|
prepareHeaders: async (headers) => {
|
|
5838
5912
|
headers.set('Content-Type', 'application/json');
|
|
@@ -6126,6 +6200,7 @@ exports.applyTax = applyTax;
|
|
|
6126
6200
|
exports.authApi = authApi;
|
|
6127
6201
|
exports.cartSlice = cartSlice;
|
|
6128
6202
|
exports.contentApi = contentApi;
|
|
6203
|
+
exports.createUnwrappingBaseQuery = createUnwrappingBaseQuery;
|
|
6129
6204
|
exports.emptyCart = emptyCart;
|
|
6130
6205
|
exports.formatAuthSession = formatAuthSession;
|
|
6131
6206
|
exports.formatChallengeDays = formatChallengeDays;
|
|
@@ -6192,4 +6267,4 @@ exports.useUpdateUserMutation = useUpdateUserMutation;
|
|
|
6192
6267
|
exports.useVerifyUserAttributesQuery = useVerifyUserAttributesQuery;
|
|
6193
6268
|
exports.useVerifyUserQuery = useVerifyUserQuery;
|
|
6194
6269
|
exports.useVerifyUserResendQuery = useVerifyUserResendQuery;
|
|
6195
|
-
//# sourceMappingURL=slice-
|
|
6270
|
+
//# sourceMappingURL=slice-4qoZ1wSU.js.map
|