redux-persist-transform-compress-encrypt
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

redux-persist-transform-compress-encrypt

GitHub license Build Status Coverage Status

To persist a compressed and encrypted Redux store

The package creates a transformer for redux-persist. The transformer stringifies the inbound state, compresses it using lz-string and encrypts the compressed string with AES.

Installation

npm install --save redux-persist-transform-compress-encrypt

Usage

import { persistReducer } from 'redux-persist'
import createCompressEncryptor from 'redux-persist-transform-compress-encrypt'
 
const transformer = createCompressEncryptor({
    secretKey: 'secret-key',
    onError: function(error) {
        //fired whenever there is any issue with transformation, 
        //compression or encryption/decryption
    }
})
 
const reducer = persistReducer({ transforms: [transformer] }, baseReducer)

If the package encounters anything unexpected, it skips the transformation, called onError and returns the state as it received.

Config

Here are all the keys you can pass to createCompressEncryptor.

interface TransformConfigType {
    //The whitelist and blacklist keys are passed as it is to the 
    //createTransform function
    whitelist?: Array<string>
    blacklist?: Array<string>
 
    //key for encryption/decryption
    secretKey: string
 
    //if any error occurs during transformation, this function is called
    onError?: (e: Error) => void
}

Test

npm run test

Notes

This package is technically bundling the packages redux-persist-transform-compress and redux-persist-transform-encrypt into one. Personally, I could not get them to work together and found it easier to just create my own transform.

Package Sidebar

Install

npm i redux-persist-transform-compress-encrypt

Weekly Downloads

62

Version

1.0.2

License

MIT

Unpacked Size

10.8 kB

Total Files

6

Last publish

Collaborators

  • dante-101