Skip to content

Commit

Permalink
post-publish v4.0.0-beta1
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmantz committed Nov 10, 2019
1 parent dc1a820 commit 8170873
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ node_js:
- "5"

before_install:
- npm install react@15.1.0 react-addons-test-utils@15.1.0 immutable babel-polyfill oidc-client
- npm install react@16.8.4 react-addons-test-utils@16.8.4 immutable babel-polyfill oidc-client
14 changes: 4 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,8 @@ In addition there is a peer dependency for [immutable.js](https://facebook.githu
You need the [babel-polyfill](https://babeljs.io/docs/usage/polyfill/) in your build configuration for this package to work.


### Version 3 released
I've decided to overhaul the API of this library. The main changes include:
- removed `childContext` from the `<OidcProvider />`, user manager now must be passed in as a prop,
- immutablejs is now an optional dependency and doesn't need to be installed for those not using it,
- dropped support for `shouldValidate` - the middleware now always validates the user,
- dropped support for `triggerAuthFlow` - this must now be initiated by a custom action (see example app),
- cleaner API all around

The example app is already updated to reflect these changes.
### Version 4 released
*BREAKING CHANGE*: `immutable` is no longer a dependency. If you are using the immutable reducer, please check out the docs.

#### Documentation
You can find the docs for version 3 here:
Expand All @@ -57,4 +50,5 @@ Check out the [wiki](https://github.com/maxmantz/redux-oidc/wiki) for further in
There is a sample application demonstrating the use of this package [here](https://github.com/maxmantz/redux-oidc-example).

### Tests
`npm run test`
You have to install immutableJS for all the tests to pass: `npm install immutable --no-save`.
Then run `npm run test`.
2 changes: 1 addition & 1 deletion dist/redux-oidc.js

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions docs/API.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# redux-oidc Version 3 API Documentation
# redux-oidc Version 4 API Documentation

### Helpers

Expand Down Expand Up @@ -60,7 +60,13 @@ or

##### Immutable reducer
This reducer is to be used for configurations with immutable.js.
`import { immutableReducer } from 'redux-oidc';`
```
import immutable from 'immutable';
import { createImmutableReducer } from 'redux-oidc';
const reducer = createImmutableReducer(immutable);
```


### React components
##### CallbackComponent / SignoutCallbackComponent
Expand Down
45 changes: 31 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redux-oidc",
"version": "3.1.7",
"version": "4.0.0-beta1",
"description": "A package for managing OpenID Connect authentication in redux apps",
"main": "dist/redux-oidc.js",
"types": "./index.d.ts",
Expand Down Expand Up @@ -63,9 +63,6 @@
"prop-types": ">=15.5.8",
"oidc-client": ">=1.6.1"
},
"optionalDependencies": {
"immutable": ">=3.6.0"
},
"browserify": {
"transform": [
"reactify"
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const createUserManager = require('./helpers/createUserManager').default;
export const processSilentRenew = require('./helpers/processSilentRenew').default;
export const loadUser = require('./helpers/loadUser').default;
export const CallbackComponent = require('./CallbackComponent').default;
export const immutableReducer = require('./reducer/reducer-immutable').default;
export const createImmutableReducer = require('./reducer/reducer-immutable').default;
export const reducer = require('./reducer/reducer').default;
export const OidcProvider = require('./OidcProvider').default;
export const SignoutCallbackComponent = require('./SignoutCallbackComponent').default;
Expand Down
104 changes: 55 additions & 49 deletions src/reducer/reducer-immutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,62 @@ import {
USER_SIGNED_OUT
} from '../constants';

let reducer;
/**
*
* @param {object} immutable - The immutableJS library
*/
export default function createImmutableReducer(immutable) {
let reducer;

try {
const { fromJS, Seq } = require('immutable');

const fromJSGreedy = (js) => {
return typeof js !== 'object' || js === null ? js :
Array.isArray(js) ?
Seq(js).map(fromJSGreedy).toList() :
Seq(js).map(fromJSGreedy).toMap();
}

const initialState = fromJS({
user: null,
isLoadingUser: false
});

reducer = (state = initialState, action) => {
switch (action.type) {
case USER_EXPIRED:
return fromJS({
user: null,
isLoadingUser: false
});
case SILENT_RENEW_ERROR:
return fromJS({
user: null,
isLoadingUser: false
});
case SESSION_TERMINATED:
case USER_SIGNED_OUT:
return fromJS({
user: null,
isLoadingUser: false
});
case USER_FOUND:
return fromJSGreedy({
user: action.payload,
isLoadingUser: false
});
case LOADING_USER:
return state.set('isLoadingUser', true);
default:
return state;
try {
const { fromJS, Seq } = immutable;

const fromJSGreedy = (js) => {
return typeof js !== 'object' || js === null ? js :
Array.isArray(js) ?
Seq(js).map(fromJSGreedy).toList() :
Seq(js).map(fromJSGreedy).toMap();
}

const initialState = fromJS({
user: null,
isLoadingUser: false
});

reducer = (state = initialState, action) => {
switch (action.type) {
case USER_EXPIRED:
return fromJS({
user: null,
isLoadingUser: false
});
case SILENT_RENEW_ERROR:
return fromJS({
user: null,
isLoadingUser: false
});
case SESSION_TERMINATED:
case USER_SIGNED_OUT:
return fromJS({
user: null,
isLoadingUser: false
});
case USER_FOUND:
return fromJSGreedy({
user: action.payload,
isLoadingUser: false
});
case LOADING_USER:
return state.set('isLoadingUser', true);
default:
return state;
}
};

return reducer;
} catch (error) {
reducer = () => {
console.error("redux-oidc: You must install immutable-js for the immutable reducer to work!");
};
} catch (error) {
reducer = () => {
console.error("You must install immutable-js for the immutable reducer to work!");
};
}
}

export default reducer;
20 changes: 16 additions & 4 deletions tests/reducer/reducer-immutable.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import '../setup';
import expect from 'expect';
import { fromJS } from 'immutable';
import immutable from 'immutable';
import { userExpired, userFound, silentRenewError, sessionTerminated, loadingUser, userSignedOut } from '../../src/actions';
import reducer from '../../src/reducer/reducer-immutable';
import createImmutableReducer from '../../src/reducer/reducer-immutable';

const { fromJS } = immutable;

const initialState = fromJS({
user: null,
isLoadingUser: false
});

describe('immutable reducer', () => {
describe('createImmutableReducer(immutable)', () => {
it('should set the correct initial state', () => {

const reducer = createImmutableReducer(immutable);
expect(reducer(undefined, { type: 'SOME_ACTION' })).toEqual(initialState);
});

Expand All @@ -26,6 +28,8 @@ describe('immutable reducer', () => {
isLoadingUser: false
});

const reducer = createImmutableReducer(immutable);

expect(reducer(state, userExpired())).toEqual(expectedResult);
});

Expand All @@ -40,6 +44,8 @@ describe('immutable reducer', () => {
isLoadingUser: false
});

const reducer = createImmutableReducer(immutable);

expect(reducer(fromJS(oldState), silentRenewError())).toEqual(expectedResult);
});

Expand All @@ -50,6 +56,7 @@ describe('immutable reducer', () => {
isLoadingUser: false
});

const reducer = createImmutableReducer(immutable);
expect(reducer(fromJS(initialState), userFound(user))).toEqual(expectedResult);
});

Expand All @@ -59,6 +66,7 @@ describe('immutable reducer', () => {
isLoadingUser: false
});

const reducer = createImmutableReducer(immutable);
expect(reducer(fromJS({}), sessionTerminated())).toEqual(expectedResult);
});

Expand All @@ -68,6 +76,7 @@ describe('immutable reducer', () => {
isLoadingUser: true
});

const reducer = createImmutableReducer(immutable);
expect(reducer(initialState, loadingUser())).toEqual(expectedResult);
});

Expand All @@ -77,6 +86,7 @@ describe('immutable reducer', () => {
isLoadingUser: false
});

const reducer = createImmutableReducer(immutable);
expect(reducer(initialState, userSignedOut())).toEqual(expectedResult);
});

Expand All @@ -85,6 +95,7 @@ describe('immutable reducer', () => {
some: 'data'
});

const reducer = createImmutableReducer(immutable);
expect(reducer(expectedResult, { type: 'UNKNOWN' })).toEqual(expectedResult);
});

Expand All @@ -99,6 +110,7 @@ describe('immutable reducer', () => {
isLoadingUser: false
});

const reducer = createImmutableReducer(immutable);
expect(reducer(fromJS(initialState), userFound(nonObjectUser))).toEqual(expectedResult);
});
});

0 comments on commit 8170873

Please sign in to comment.