@feardread/feature-factory 4.0.5 → 4.0.7

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.5",
3
+ "version": "4.0.7",
4
4
  "description": "Library to interact with redux toolkit and reduce boilerplate / repeated code",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -38,8 +38,8 @@ const CONFIG = {
38
38
  */
39
39
  const getBaseUrl = () => {
40
40
  const env = process.env.NODE_ENV || 'development';
41
- const uri = 'production';
42
- return CONFIG.baseUrls[uri] || CONFIG.baseUrls.development;
41
+ //const uri = 'production';
42
+ return CONFIG.baseUrls[env] || CONFIG.baseUrls.development;
43
43
  };
44
44
 
45
45
  /**
@@ -237,6 +237,7 @@ const responseInterceptor = (response) => {
237
237
  if (process.env.NODE_ENV === 'development') {
238
238
  console.log(`✅ API Success [${response.status}]:`, {
239
239
  url: response.config.url,
240
+ data: response.data,
240
241
  method: response.config.method?.toUpperCase(),
241
242
  responseTime: response.metadata.responseTime,
242
243
  requestId: response.metadata.requestId,
@@ -278,6 +279,7 @@ const responseErrorInterceptor = async (error) => {
278
279
  if (process.env.NODE_ENV === 'development') {
279
280
  console.error(`❌ API Error [${formattedError.status}]:`, {
280
281
  url: originalRequest?.url,
282
+ error: formattedError,
281
283
  method: originalRequest?.method?.toUpperCase(),
282
284
  message: formattedError.message,
283
285
  requestId: originalRequest?.headers['X-Request-ID'],
@@ -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) => {
@@ -19,6 +19,7 @@ const STANDARD_OPERATIONS = {
19
19
  all: { method: HTTP_METHODS.GET, useParams: false },
20
20
  one: { method: HTTP_METHODS.GET, useParams: false, useIdInUrl: true },
21
21
  search: { method: HTTP_METHODS.GET, useParams: true },
22
+ new: { method: HTTP_METHODS.POST, useParams: false },
22
23
  create: { method: HTTP_METHODS.POST, useParams: false },
23
24
  update: { method: HTTP_METHODS.PUT, useParams: false, useIdInUrl: true },
24
25
  patch: { method: HTTP_METHODS.PATCH, useParams: false, useIdInUrl: true },
@@ -67,6 +68,8 @@ const buildUrl = (entity, prefix, params = {}, useIdInUrl = false) => {
67
68
  */
68
69
  const handleResponse = (response) => {
69
70
  // Handle different response structures
71
+ console.log('resp = ', response)
72
+ return response.data;
70
73
  if (response?.data?.result !== undefined) {
71
74
  return response.data.result;
72
75
  }
@@ -119,15 +122,11 @@ const createGenericThunk = (entity, prefix, options = {}) => {
119
122
  `${entity}/${prefix}`,
120
123
  async (payload = {}, thunkApi) => {
121
124
  try {
122
- const url = config.customUrl || buildUrl(entity, prefix, payload, config.useIdInUrl);
125
+ const url = buildUrl(entity, prefix, payload, config.useIdInUrl);
123
126
 
124
127
  let apiCall;
125
128
  const apiConfig = config.useParams ? { params: payload } : {};
126
129
 
127
- if ( config.customApiUrl !== null ) {
128
- API.instance.defaults.baseURL = config.customApiUrl;
129
- }
130
-
131
130
  switch (config.method) {
132
131
  case HTTP_METHODS.GET:
133
132
  apiCall = API.get(url, apiConfig);
@@ -161,18 +160,16 @@ const createGenericThunk = (entity, prefix, options = {}) => {
161
160
  * Factory for creating Redux async thunks with standardized patterns
162
161
  */
163
162
  export const ThunkFactory = {
164
- API_URL: null,
165
163
  /**
166
164
  * Creates a GET request thunk (legacy method for backward compatibility)
167
165
  * @param {string} entity - The entity name
168
166
  * @param {string} prefix - The operation prefix
169
167
  * @returns {Function} The created async thunk
170
168
  */
171
- create: (entity, prefix, apiUrl = ThunkFactory.API_URL) => {
169
+ create: (entity, prefix) => {
172
170
  validateThunkParams(entity, prefix);
173
171
 
174
172
  const operation = STANDARD_OPERATIONS[prefix];
175
- const options = {operation, customApiUrl: apiUrl};
176
173
  if (operation) {
177
174
  return createGenericThunk(entity, prefix, options);
178
175
  }