Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

next-persist

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-persist - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

2

package.json
{
"name": "next-persist",
"version": "1.1.0",
"version": "1.1.1",
"description": "Bridging the gap between client-side persistence and server-side rendering",

@@ -5,0 +5,0 @@ "main": "src/next-persist.js",

@@ -24,6 +24,7 @@ /**

nextPersistCookie.setCookie = (cookieConfig, state) => {
const { key, allowList } = cookieConfig;
const key = Object.keys(cookieConfig)[0];
const allowList = Object.values(cookieConfig)[0];
// if allowList was not defined in cookieConfig, sets cookie containing entire state
if (!allowList) {
Cookie.set(key, state);
if (allowList.length === 0) {
Cookie.set(key, JSON.stringify(state));
} else {

@@ -35,3 +36,3 @@ // sets cookie containing only properties listed in allowList

}, {});
Cookie.set(key, allowedState);
Cookie.set(key, JSON.stringify(allowedState));
}

@@ -52,11 +53,11 @@ };

nextPersistCookie.getCookie = (req, state, cookieName) => {
nextPersistCookie.getCookie = (req, cookieName, state) => {
// if application is running client-side, parse and return cookie from browser
if (!req) {
const stateFromCookie = Cookie.get(cookieName);
return stateFromCookie ? JSON.parse(stateFromCookie) : state
return stateFromCookie ? JSON.parse(stateFromCookie) : state;
} // if application is running server-side, parse and return cooking from request body
else return cookie.parse(req.ctx.req.headers.cookie || '');
}
};
module.exports = nextPersistCookie;

@@ -21,3 +21,4 @@ /**

nextPersist.setStorage = (storageConfig, state) => {
const { key, allowList } = storageConfig;
const key = Object.keys(storageConfig)[0];
const allowList = Object.values(storageConfig)[0];

@@ -27,3 +28,3 @@ // if application is running client-side, localStorage is accessible

// if allowList was not defined in persistConfig, set all propertiesfrom state to localStorage
if (!allowList) {
if (allowList.length === 0) {
localStorage.setItem(key, JSON.stringify(state));

@@ -30,0 +31,0 @@ } else {

@@ -32,23 +32,18 @@ /**

// if redux combines reducers, each reducer's state gets saved to local storage
// under a unique key specified in wrapperConfig
if (this.props.wrapperConfig.combinedReducers) {
const { allowedKeys } = this.props.wrapperConfig;
const { allowedReducers } = this.props.wrapperConfig;
const { allowList } = this.props.wrapperConfig;
const nextPersistConfig = {};
allowedReducers.forEach((allowedReducer, index) => {
const nextPersistConfig = {
key: allowedKeys[index],
};
// if no allowlist provided save all state to their corresponding keys
if (!allowList) {
const key = Object.keys(this.props.state)[0];
nextPersistConfig[key] = [];
method(nextPersistConfig, this.props.state[key]);
}
// if allowlist exists pass subconfigs of allowed reducers into storage method
else {
const allowedReducers = Object.keys(allowList);
allowedReducers.forEach((allowedReducer) => {
nextPersistConfig[allowedReducer] = allowList[allowedReducer];
method(nextPersistConfig, this.props.state[allowedReducer]);
});
// otherwise, the single reducer's state gets saved to local storage
// according to allowList configuration
} else {
const nextPersistConfig = {
key: this.props.wrapperConfig.key,
allowList: this.props.wrapperConfig.allowList,
};
method(nextPersistConfig, this.props.state);
}

@@ -55,0 +50,0 @@ return this.props.children;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc