
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
net-provider
Advanced tools
This package depend on redux-saga and can be run inside react and react-native projects
with net-provider you can read and update your DB is with less of code and less effort by using the set of ready actions or with the data component provider
import React, { Component } from 'react'
import {dispatchAction, Query} from 'net-provider';
const URL = '/me'
export default class HomeScreen extends Component {
render() {
return (
<Query
query={{
targetKey: URL,
url: URL,
onEnd: ({data}) => alert('END')
}}
>
{({ data,
error,
loading,
crudActions,
count}) => {
return <Text>
{data && JSON.stringify(data)}
{error && JSON.stringify(error)}
{loading && 'Loading'}
{count && count}
</Text>
}}
</Query>
)}}
import React, { Component } from 'react'
import { connect } from 'react-redux';
import {dispatchAction, selectors} from 'net-provider';
const URL = '/me'
class HomeScreen extends Component {
componentDidMount() {
dispatchAction.Read({
targetKey: URL,
url: URL
})
}
componentWillUnmount() {
dispatchAction.Clean({targetKey: URL})
}
render() {
const {data, error, loading, count} = this.props;
return (
<Text>
Example:
{data && JSON.stringify(data)}
{error && JSON.stringify(error)}
{loading && 'Loading'}
{count && count}
</Text>
)
}
}
const mapStateToProps = state => {
const {data, error, loading, count} = selectors.getCrudObject(state, URL)
return {
data, error, loading, count
}
};
export default connect(mapStateToProps, null)(HomeScreenN)
import React, { Component } from 'react'
import {dispatchAction, selectors} from 'net-provider';
const URL = '/me'
class HomeScreen extends Component {
constructor(props){
super(props);
this.state= {
loading: false, data: null, error: null
};
};
componentDidMount() {
this.setState({loading: true})
dispatchAction.Read({
targetKey: URL,
url: URL,
// data: values,
onEnd: ({data}) => {
this.setState({loading: false,data, error: null})
},
onFailed: ({error}) => {
const errorMessage = (error && error.response && error.response.data && error.response.data.message)|| 'oops something went wrong. please try again later'
this.setState({loading: false, error: errorMessage})}
})
}
componentWillUnmount() {
dispatchAction.Clean({targetKey: URL})
}
render() {
const {data, error, loading, count} = this.state;
return (
<Text>
Example:
{data && JSON.stringify(data)}
{error && JSON.stringify(error)}
{loading && 'Loading'}
{count && count}
</Text>
)
}
}
export default HomeScreen
npm install net-provider --save
import {setApiInstance, setDispatch, setDefaultIdKey, setErrorHandler} from 'net-provider'
import axios from 'axios';
// Set an axios instance
setApiInstance(
axios.create({baseURL: 'www.myDomain.com'})
)
// Set Dispatch - Optional, if you want to use actions with any place without worry about redux-connect
setDispatch(store.dispatch)
// Set the unique id Key In Your database
setDefaultIdKey('_id')
// Set error handler - Optional, function that will call whenever an error will catch
setErrorHandler(
function(err) {
if(err && err.response
&& (err.response.statusText === 'Unauthorized'
|| err.response.status === 401)) {
store.dispatch(logout())}
}}
)
import { combineReducers } from 'redux';
import { crudReduxReducer } from 'net-provider'
export default combineReducers({
...
crud: crudReduxReducer
});
* the key must be crudimport { all, call } from 'redux-saga/effects';
import { crudReduxSaga } from 'net-provider';
function* rootSaga() {
yield all([
....
call(crudReduxSaga, 'crudReduxSaga'),
]);
}
export default rootSaga;
You can dispatch an action from any part of your app like this:
import {dispatchAction} from 'net-provider'
dispatchAction.Read({url: 'users', targetKey: 'usersScreen'})
And you can use it with out the dispatchAction provider, like this: if you want to put an action inside saga, use this option.
import {actions} from 'net-provider'
dispatch(
actions.Read({url: 'users', targetKey: 'usersScreen'})
)
Server actions
All the server actions accept an object with this parameters
targetKey {string} required the key to set the parameters in store
url {string} API endpoint - required only for the first action to this targetKey
method {string} one of ['get' , 'post' , 'put' , 'delete'] method will set by default base the action type but you can override this defaults: Read() = 'get' | Create() = 'post' | Update() = 'put' | Delete() = 'delete'
params {object} request params
data {object} request params
dispatchId {string} optional -pass dispatch Id that can help you track your specific request
customHandleResponse {func} help us find the data from response when the structure is not response.data, this function will get the response from server and need to return the data
getCountRequestConfig {func}- use it when you want to fetch the count from diffrent url, function that get ({actionPayload, response, fetchObject}) => ({url, method, params, data})
- actionPayload - the current action.payload that trigger this
- response - the response from this current request
- fetchObject - fetchObject from reduxStore.crud[targetKey] contain data, lastRead...
* If you want to skip the request and persist the current count (maybe filters didnt change and only pagination) then return false
when you using this the getCountFromResponse is required and will run on this request response
example:
<NetProvider loadData={{
url: 'products',
targetKey: 'productsScreen'
params: {filter: {active: 1}},
getCountRequestConfig: ({actionPayload, response, fetchObject}) => {
const currentCount = fetchObject.count
const lastFilters = getDeepObjectValue(fetchObject, 'lastRead.params.filter')
const newFilter = getDeepObjectValue(actionPayload, 'params.filter')
if((currentCount || currentCount === 0) && isEqual(lastFilters, newFilter)) {
return false // persist count
}
const config = { url: actionPayload.url + '/count', method: actionPayload.method}
const filter = getDeepObjectValue(response, 'config.params.filter')
if(filter) { config.params = {filter} }
return config
},
getCountFromResponse: (response) => {
return getDeepObjectValue(response,'data.count') || 0
}
}} />
getCountFromResponse {func} help us find the count of your data from the response if it is possible
customAxiosInstance {object} when the default axios is not relevant pass a different instance
customFetch {func} - when you want to take the control of the fetch to your hand, can be useful for custom requests or for request that need to be handle by SDK or somthing else your function will be call by saga like this
response = yield call(customFetch, { url, method, data, params, payload: action.payload})
onStart {func} - call back that be call before the request
onEnd {func} - call back that be call when request end
onFailed {func} - call back that be call when request failed
refreshType {string} - one of ['local', 'server', 'none'] - server is the default This parameter is relevant when we change a record inside a list, we let you decide how to keep your list update after any change(create,delete,update)
useResponseValues - {boolean}- sometimes when we put data to server it will return us an object or a list of objects with the updating values, set true if this is the situation to set the result from server on store
Local Actions
All the data will be store inside redux > crud > {.....} Example:
store : {
crud: {
"Admin-orders-list" : {
targetKey: "Admin-orders-list"
url: "orders"
status: "read-success"
error: null
loading: false
count: 150
data: [...]
},
"Admin-posts-list" : {
targetKey: "Admin-posts-list"
url: "posts"
status: "read-start"
error: null
loading: true
count: 0
data: null
}
}
}
You can connect any component and find the data with our selectors, like that:
import { connect } from 'react-redux';
import {selectors} from 'net-provider';
const postListTargetKey = 'Admin-posts-list' // This the target key from your action
const mapStateToProps = state => ({
adminPostList: selectors.getCrudObject(state, postListTargetKey ),
});
export default connect(mapStateToProps , null)(MyComponent);
Selectors list:
<NetProvider /> will handle all for you, when your screen mount the component will fetch data from the server and provide to your function component a query status, data, actions and more...when the screen un mount netProvider will clean the store
props:
There are three ways to render things with <NetProvider />
<NetProvider component={<YourComponent />}><NetProvider render={(res) => <div></div>}><NetProvider>{(res) => <div></div>} </NetProvider>A collection of actions:
You can work directly with the dispactActions collection from this package, but when you work with crudActions from the NetProvider you didn't need to pass a targetKey in each request, all the rest is the same like the dispactActions collection
{Read, Refresh, Create, Update, Delete, SetParameters, Clean, CreateLocal, DeleteLocal, UpdateLocal}
FAQs
net-provider React component
We found that net-provider demonstrated a not healthy version release cadence and project activity because the last version was released 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
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.