@feardread/feature-factory 4.0.6 → 4.0.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feardread/feature-factory",
3
- "version": "4.0.6",
3
+ "version": "4.0.8",
4
4
  "description": "Library to interact with redux toolkit and reduce boilerplate / repeated code",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -83,7 +83,7 @@ export function FeatureFactory(entity, reducers = {}, endpoints = null) {
83
83
  const createStandardThunks = (sliceName) => ({
84
84
  fetch: ThunkFactory.create(sliceName, 'all'),
85
85
  fetchOne: ThunkFactory.create(sliceName, 'one'),
86
- search: ThunkFactory.create(sliceName, 'search'),
86
+ search: ThunkFactory.post(sliceName, 'search'),
87
87
  });
88
88
 
89
89
  /**
@@ -102,13 +102,13 @@ export function FeatureFactory(entity, reducers = {}, endpoints = null) {
102
102
  .addCase(action.fulfilled, (state, actionPayload) => {
103
103
  state.loading = false;
104
104
  state.success = true;
105
- state.data = actionPayload.payload;
105
+ state.data = actionPayload.payload.result;
106
106
 
107
107
  // Handle single item for fetchOne operation
108
108
  if (key === 'fetchOne' && Array.isArray(actionPayload.payload)) {
109
- state[sliceName] = actionPayload.payload[0];
109
+ state[sliceName] = actionPayload.payload[0].result;
110
110
  } else if (Array.isArray(actionPayload.payload) && actionPayload.payload.length > 0) {
111
- state[sliceName] = actionPayload.payload[0];
111
+ state[sliceName] = actionPayload.payload[0].result;
112
112
  }
113
113
  })
114
114
  .addCase(action.rejected, (state, actionPayload) => {
@@ -68,6 +68,8 @@ const buildUrl = (entity, prefix, params = {}, useIdInUrl = false) => {
68
68
  */
69
69
  const handleResponse = (response) => {
70
70
  // Handle different response structures
71
+ console.log('resp = ', response)
72
+ return response.data;
71
73
  if (response?.data?.result !== undefined) {
72
74
  return response.data.result;
73
75
  }
@@ -120,15 +122,11 @@ const createGenericThunk = (entity, prefix, options = {}) => {
120
122
  `${entity}/${prefix}`,
121
123
  async (payload = {}, thunkApi) => {
122
124
  try {
123
- const url = config.customUrl || buildUrl(entity, prefix, payload, config.useIdInUrl);
125
+ const url = buildUrl(entity, prefix, payload, config.useIdInUrl);
124
126
 
125
127
  let apiCall;
126
128
  const apiConfig = config.useParams ? { params: payload } : {};
127
129
 
128
- if ( config.customApiUrl !== null ) {
129
- API.instance.defaults.baseURL = config.customApiUrl;
130
- }
131
-
132
130
  switch (config.method) {
133
131
  case HTTP_METHODS.GET:
134
132
  apiCall = API.get(url, apiConfig);
@@ -162,20 +160,18 @@ const createGenericThunk = (entity, prefix, options = {}) => {
162
160
  * Factory for creating Redux async thunks with standardized patterns
163
161
  */
164
162
  export const ThunkFactory = {
165
- API_URL: null,
166
163
  /**
167
164
  * Creates a GET request thunk (legacy method for backward compatibility)
168
165
  * @param {string} entity - The entity name
169
166
  * @param {string} prefix - The operation prefix
170
167
  * @returns {Function} The created async thunk
171
168
  */
172
- create: (entity, prefix, apiUrl = ThunkFactory.API_URL) => {
169
+ create: (entity, prefix) => {
173
170
  validateThunkParams(entity, prefix);
174
171
 
175
172
  const operation = STANDARD_OPERATIONS[prefix];
176
- const options = {operation, customApiUrl: apiUrl};
177
173
  if (operation) {
178
- return createGenericThunk(entity, prefix, options);
174
+ return createGenericThunk(entity, prefix);
179
175
  }
180
176
 
181
177
  // Fallback to original behavior for custom prefixes