Skip to content

Commit 8170873

Browse files
committed
post-publish v4.0.0-beta1
1 parent dc1a820 commit 8170873

File tree

9 files changed

+118
-86
lines changed

9 files changed

+118
-86
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ node_js:
44
- "5"
55

66
before_install:
7-
- npm install react@15.1.0 react-addons-test-utils@15.1.0 immutable babel-polyfill oidc-client
7+
- npm install react@16.8.4 react-addons-test-utils@16.8.4 immutable babel-polyfill oidc-client

README.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,8 @@ In addition there is a peer dependency for [immutable.js](https://facebook.githu
3030
You need the [babel-polyfill](https://babeljs.io/docs/usage/polyfill/) in your build configuration for this package to work.
3131

3232

33-
### Version 3 released
34-
I've decided to overhaul the API of this library. The main changes include:
35-
- removed `childContext` from the `<OidcProvider />`, user manager now must be passed in as a prop,
36-
- immutablejs is now an optional dependency and doesn't need to be installed for those not using it,
37-
- dropped support for `shouldValidate` - the middleware now always validates the user,
38-
- dropped support for `triggerAuthFlow` - this must now be initiated by a custom action (see example app),
39-
- cleaner API all around
40-
41-
The example app is already updated to reflect these changes.
33+
### Version 4 released
34+
*BREAKING CHANGE*: `immutable` is no longer a dependency. If you are using the immutable reducer, please check out the docs.
4235

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

5952
### Tests
60-
`npm run test`
53+
You have to install immutableJS for all the tests to pass: `npm install immutable --no-save`.
54+
Then run `npm run test`.

dist/redux-oidc.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/API.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# redux-oidc Version 3 API Documentation
1+
# redux-oidc Version 4 API Documentation
22

33
### Helpers
44

@@ -60,7 +60,13 @@ or
6060

6161
##### Immutable reducer
6262
This reducer is to be used for configurations with immutable.js.
63-
`import { immutableReducer } from 'redux-oidc';`
63+
```
64+
import immutable from 'immutable';
65+
import { createImmutableReducer } from 'redux-oidc';
66+
67+
const reducer = createImmutableReducer(immutable);
68+
```
69+
6470

6571
### React components
6672
##### CallbackComponent / SignoutCallbackComponent

package-lock.json

Lines changed: 31 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "redux-oidc",
3-
"version": "3.1.7",
3+
"version": "4.0.0-beta1",
44
"description": "A package for managing OpenID Connect authentication in redux apps",
55
"main": "dist/redux-oidc.js",
66
"types": "./index.d.ts",
@@ -63,9 +63,6 @@
6363
"prop-types": ">=15.5.8",
6464
"oidc-client": ">=1.6.1"
6565
},
66-
"optionalDependencies": {
67-
"immutable": ">=3.6.0"
68-
},
6966
"browserify": {
7067
"transform": [
7168
"reactify"

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const createUserManager = require('./helpers/createUserManager').default;
55
export const processSilentRenew = require('./helpers/processSilentRenew').default;
66
export const loadUser = require('./helpers/loadUser').default;
77
export const CallbackComponent = require('./CallbackComponent').default;
8-
export const immutableReducer = require('./reducer/reducer-immutable').default;
8+
export const createImmutableReducer = require('./reducer/reducer-immutable').default;
99
export const reducer = require('./reducer/reducer').default;
1010
export const OidcProvider = require('./OidcProvider').default;
1111
export const SignoutCallbackComponent = require('./SignoutCallbackComponent').default;

src/reducer/reducer-immutable.js

Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,62 @@ import {
77
USER_SIGNED_OUT
88
} from '../constants';
99

10-
let reducer;
10+
/**
11+
*
12+
* @param {object} immutable - The immutableJS library
13+
*/
14+
export default function createImmutableReducer(immutable) {
15+
let reducer;
1116

12-
try {
13-
const { fromJS, Seq } = require('immutable');
14-
15-
const fromJSGreedy = (js) => {
16-
return typeof js !== 'object' || js === null ? js :
17-
Array.isArray(js) ?
18-
Seq(js).map(fromJSGreedy).toList() :
19-
Seq(js).map(fromJSGreedy).toMap();
20-
}
21-
22-
const initialState = fromJS({
23-
user: null,
24-
isLoadingUser: false
25-
});
26-
27-
reducer = (state = initialState, action) => {
28-
switch (action.type) {
29-
case USER_EXPIRED:
30-
return fromJS({
31-
user: null,
32-
isLoadingUser: false
33-
});
34-
case SILENT_RENEW_ERROR:
35-
return fromJS({
36-
user: null,
37-
isLoadingUser: false
38-
});
39-
case SESSION_TERMINATED:
40-
case USER_SIGNED_OUT:
41-
return fromJS({
42-
user: null,
43-
isLoadingUser: false
44-
});
45-
case USER_FOUND:
46-
return fromJSGreedy({
47-
user: action.payload,
48-
isLoadingUser: false
49-
});
50-
case LOADING_USER:
51-
return state.set('isLoadingUser', true);
52-
default:
53-
return state;
17+
try {
18+
const { fromJS, Seq } = immutable;
19+
20+
const fromJSGreedy = (js) => {
21+
return typeof js !== 'object' || js === null ? js :
22+
Array.isArray(js) ?
23+
Seq(js).map(fromJSGreedy).toList() :
24+
Seq(js).map(fromJSGreedy).toMap();
5425
}
26+
27+
const initialState = fromJS({
28+
user: null,
29+
isLoadingUser: false
30+
});
31+
32+
reducer = (state = initialState, action) => {
33+
switch (action.type) {
34+
case USER_EXPIRED:
35+
return fromJS({
36+
user: null,
37+
isLoadingUser: false
38+
});
39+
case SILENT_RENEW_ERROR:
40+
return fromJS({
41+
user: null,
42+
isLoadingUser: false
43+
});
44+
case SESSION_TERMINATED:
45+
case USER_SIGNED_OUT:
46+
return fromJS({
47+
user: null,
48+
isLoadingUser: false
49+
});
50+
case USER_FOUND:
51+
return fromJSGreedy({
52+
user: action.payload,
53+
isLoadingUser: false
54+
});
55+
case LOADING_USER:
56+
return state.set('isLoadingUser', true);
57+
default:
58+
return state;
59+
}
60+
};
61+
62+
return reducer;
63+
} catch (error) {
64+
reducer = () => {
65+
console.error("redux-oidc: You must install immutable-js for the immutable reducer to work!");
5566
};
56-
} catch (error) {
57-
reducer = () => {
58-
console.error("You must install immutable-js for the immutable reducer to work!");
59-
};
67+
}
6068
}
61-
62-
export default reducer;

tests/reducer/reducer-immutable.test.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import '../setup';
22
import expect from 'expect';
3-
import { fromJS } from 'immutable';
3+
import immutable from 'immutable';
44
import { userExpired, userFound, silentRenewError, sessionTerminated, loadingUser, userSignedOut } from '../../src/actions';
5-
import reducer from '../../src/reducer/reducer-immutable';
5+
import createImmutableReducer from '../../src/reducer/reducer-immutable';
6+
7+
const { fromJS } = immutable;
68

79
const initialState = fromJS({
810
user: null,
911
isLoadingUser: false
1012
});
1113

12-
describe('immutable reducer', () => {
14+
describe('createImmutableReducer(immutable)', () => {
1315
it('should set the correct initial state', () => {
14-
16+
const reducer = createImmutableReducer(immutable);
1517
expect(reducer(undefined, { type: 'SOME_ACTION' })).toEqual(initialState);
1618
});
1719

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

31+
const reducer = createImmutableReducer(immutable);
32+
2933
expect(reducer(state, userExpired())).toEqual(expectedResult);
3034
});
3135

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

47+
const reducer = createImmutableReducer(immutable);
48+
4349
expect(reducer(fromJS(oldState), silentRenewError())).toEqual(expectedResult);
4450
});
4551

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

59+
const reducer = createImmutableReducer(immutable);
5360
expect(reducer(fromJS(initialState), userFound(user))).toEqual(expectedResult);
5461
});
5562

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

69+
const reducer = createImmutableReducer(immutable);
6270
expect(reducer(fromJS({}), sessionTerminated())).toEqual(expectedResult);
6371
});
6472

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

79+
const reducer = createImmutableReducer(immutable);
7180
expect(reducer(initialState, loadingUser())).toEqual(expectedResult);
7281
});
7382

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

89+
const reducer = createImmutableReducer(immutable);
8090
expect(reducer(initialState, userSignedOut())).toEqual(expectedResult);
8191
});
8292

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

98+
const reducer = createImmutableReducer(immutable);
8899
expect(reducer(expectedResult, { type: 'UNKNOWN' })).toEqual(expectedResult);
89100
});
90101

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

113+
const reducer = createImmutableReducer(immutable);
102114
expect(reducer(fromJS(initialState), userFound(nonObjectUser))).toEqual(expectedResult);
103115
});
104116
});

0 commit comments

Comments
 (0)