
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react_redux_api
Advanced tools
react_redux_api_helpers is library for eiser using redux store and redux-sagas with request to server.
It based on redux-saga and axios packages.
$ npm install --save react_redux_api_helpers
or
$ yarn add react_redux_api_helpers
init in root saga:
import * as apiHelpers from 'api';
// some code
const {modules: { apiWatchRequest },axios: { init },} = apiHelpers;
//init main routes
if (process.env.NODE_ENV == 'development') {
init('http://localhost:3001'); //develop server
} else if (process.env.NODE_ENV == 'production') {
init('https://translates.goman.live');// production server
}
function* rootSaga(dispatch) {
yield all([
apiWatchRequest({
additiveCallback: function*({ showLoaderFlag = true, ...data }) {
//show loader
if (showLoaderFlag) {
yield put(showLoader());
}
// add credentials for request
const credentials = yield select(authHashSelector);
if (credentials) {
set(data, 'headers.Authorization', `${credentials}`);
}
return data;
},
successCallback: function*(data) {
yield put(hideLoader());
if (
data.config.method === 'put' ||
data.config.method === 'post' ||
data.config.method === 'delete'
) {
console.log(data);
const message = get(data, 'data.message');
if (message) {
yield put(showSuccess({ message }));
} else {
yield put(
showSuccess({ message: 'Successful operation.' }),
);
}
}
},
failedCallback: function*(data) {
const dataStatus = data.status;
yield put(hideLoader());
switch (true) {
case dataStatus === 401:
yield call(history.push, '/login');
return;
case dataStatus === 500:
yield put(
showError({ message: 'Internal server error.' }),
);
return;
case dataStatus === 406: {
const message = get(
data,
'response.data.message',
'Internal server error.',
);
yield put(showError({ message }));
return;
}
case dataStatus === 403: {
const message = get(
data,
'response.data.message',
'Internal server error.',
);
yield put(showError({ message }));
return;
}
default: {
const error = get(data, 'response.data.error');
if (
typeof error === 'object' &&
error.type === 'popup'
) {
yield put(showError({ message: error.message }));
}
return;
}
}
},
}),
initModuleSaga(dispatch),
authSaga(dispatch),
i18nextModuleSaga(dispatch),
notificationSaga(dispatch),
]);
}
I recommended use principe Redux-ducks for organization of code , example below.
import * as api_helpers from 'api';
const modules = 'languages';
const {
helpers: { actionCreator, apiSelector },
modules: { ApiRoutes },
} = api_helpers;
const apiRoutes = new ApiRoutes();
export const GET_LANGUAGES_LIST_REQUEST = `${modules}/GET_LANGUAGES_LIST_REQUEST`
export const POST_IMPORT_JSON_REQUEST = `${modules}/POST_IMPORT_JSON_REQUEST`;
export const getTranslatedListRequest = actionCreator(
GET_LANGUAGES_LIST_REQUEST,
);
export const postImportJsonRequest = actionCreator(POST_IMPORT_JSON_REQUEST);
apiRoutes.add(GET_LANGUAGES_LIST_REQUEST, ({ ...params }) => ({
url: `/get-all-keys`,
method: 'get',
params,
}));
apiRoutes.add(POST_IMPORT_JSON_REQUEST, (data) => {
return {
url: `/import-json`,
method: 'post',
data,
headers: { 'Content-Type': 'multipart/form-data' },
showLoaderFlag:false
};
});
export const getTranslatedListSelector = apiSelector(GET_LANGUAGES_LIST_REQUEST);
url - base url for the axios.
actionType - string must end with _REQUEST. For example GET_USER_REQUEST.
fn - function for prepare request. For example - `url: /import-json,
(data) => {
return {
url: `/import-json`,
method: 'post',
data,
headers: { 'Content-Type': 'multipart/form-data' },
showLoaderFlag:false
}
More information: https://github.com/axios/axios#request-config
FAQs
Collection of actions, reducers and helpers for work with API
We found that react_redux_api demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.