@accounts/client
Advanced tools
Comparing version 0.0.4 to 0.0.5-alpha.451f3013
@@ -36,2 +36,4 @@ 'use strict'; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -47,3 +49,3 @@ | ||
var getTokenKey = function getTokenKey(type, options) { | ||
return (0, _lodash.isString)(options.localStoragePrefix) && options.localStoragePrefix.length > 0 ? options.localStoragePrefix + ':' + type : type; | ||
return (0, _lodash.isString)(options.tokenStoragePrefix) && options.tokenStoragePrefix.length > 0 ? options.tokenStoragePrefix + ':' + type : type; | ||
}; | ||
@@ -56,2 +58,3 @@ | ||
this.options = options; | ||
this.storage = options.tokenStorage; | ||
if (!transport) { | ||
@@ -65,6 +68,4 @@ throw new _common.AccountsError('A REST or GraphQL transport is required'); | ||
this.store = (0, _createStore2.default)({ | ||
reducers: { | ||
accounts: _module2.default | ||
}, | ||
this.store = options.store || (0, _createStore2.default)({ | ||
reducers: _defineProperty({}, options.reduxStoreKey, _module2.default), | ||
middleware: middleware | ||
@@ -77,5 +78,83 @@ }); | ||
value: function getState() { | ||
return this.store.getState().get('accounts'); | ||
var state = this.store.getState(); | ||
if (typeof state.get === 'function') { | ||
return state.get(this.options.reduxStoreKey); | ||
} | ||
return state[this.options.reduxStoreKey]; | ||
} | ||
}, { | ||
key: 'getStorageData', | ||
value: function () { | ||
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(keyName) { | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
return _context.abrupt('return', Promise.resolve(this.storage.getItem(keyName))); | ||
case 1: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
function getStorageData(_x) { | ||
return _ref.apply(this, arguments); | ||
} | ||
return getStorageData; | ||
}() | ||
}, { | ||
key: 'setStorageData', | ||
value: function () { | ||
var _ref2 = _asyncToGenerator(regeneratorRuntime.mark(function _callee2(keyName, value) { | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
return _context2.abrupt('return', Promise.resolve(this.storage.setItem(keyName, value))); | ||
case 1: | ||
case 'end': | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, this); | ||
})); | ||
function setStorageData(_x2, _x3) { | ||
return _ref2.apply(this, arguments); | ||
} | ||
return setStorageData; | ||
}() | ||
}, { | ||
key: 'removeStorageData', | ||
value: function () { | ||
var _ref3 = _asyncToGenerator(regeneratorRuntime.mark(function _callee3(keyName) { | ||
return regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
return _context3.abrupt('return', Promise.resolve(this.storage.removeItem(keyName))); | ||
case 1: | ||
case 'end': | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3, this); | ||
})); | ||
function removeStorageData(_x4) { | ||
return _ref3.apply(this, arguments); | ||
} | ||
return removeStorageData; | ||
}() | ||
}, { | ||
key: 'user', | ||
@@ -87,15 +166,111 @@ value: function user() { | ||
key: 'tokens', | ||
value: function tokens() { | ||
return { | ||
accessToken: localStorage.getItem(getTokenKey(ACCESS_TOKEN, this.options)), | ||
refreshToken: localStorage.getItem(getTokenKey(REFRESH_TOKEN, this.options)) | ||
}; | ||
} | ||
value: function () { | ||
var _ref4 = _asyncToGenerator(regeneratorRuntime.mark(function _callee4() { | ||
return regeneratorRuntime.wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
_context4.next = 2; | ||
return this.getStorageData(getTokenKey(ACCESS_TOKEN, this.options)); | ||
case 2: | ||
_context4.t0 = _context4.sent; | ||
_context4.next = 5; | ||
return this.getStorageData(getTokenKey(REFRESH_TOKEN, this.options)); | ||
case 5: | ||
_context4.t1 = _context4.sent; | ||
return _context4.abrupt('return', { | ||
accessToken: _context4.t0, | ||
refreshToken: _context4.t1 | ||
}); | ||
case 7: | ||
case 'end': | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee4, this); | ||
})); | ||
function tokens() { | ||
return _ref4.apply(this, arguments); | ||
} | ||
return tokens; | ||
}() | ||
}, { | ||
key: 'clearTokens', | ||
value: function clearTokens() { | ||
localStorage.removeItem(getTokenKey(ACCESS_TOKEN, this.options)); | ||
localStorage.removeItem(getTokenKey(REFRESH_TOKEN, this.options)); | ||
} | ||
value: function () { | ||
var _ref5 = _asyncToGenerator(regeneratorRuntime.mark(function _callee5() { | ||
return regeneratorRuntime.wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
_context5.next = 2; | ||
return this.removeStorageData(getTokenKey(ACCESS_TOKEN, this.options)); | ||
case 2: | ||
_context5.next = 4; | ||
return this.removeStorageData(getTokenKey(REFRESH_TOKEN, this.options)); | ||
case 4: | ||
case 'end': | ||
return _context5.stop(); | ||
} | ||
} | ||
}, _callee5, this); | ||
})); | ||
function clearTokens() { | ||
return _ref5.apply(this, arguments); | ||
} | ||
return clearTokens; | ||
}() | ||
}, { | ||
key: 'storeTokens', | ||
value: function () { | ||
var _ref6 = _asyncToGenerator(regeneratorRuntime.mark(function _callee6(loginResponse) { | ||
var newAccessToken, newRefreshToken; | ||
return regeneratorRuntime.wrap(function _callee6$(_context6) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
case 0: | ||
newAccessToken = loginResponse.tokens.accessToken; | ||
if (!newAccessToken) { | ||
_context6.next = 4; | ||
break; | ||
} | ||
_context6.next = 4; | ||
return this.setStorageData(getTokenKey(ACCESS_TOKEN, this.options), newAccessToken); | ||
case 4: | ||
newRefreshToken = loginResponse.tokens.refreshToken; | ||
if (!newRefreshToken) { | ||
_context6.next = 8; | ||
break; | ||
} | ||
_context6.next = 8; | ||
return this.setStorageData(getTokenKey(REFRESH_TOKEN, this.options), newRefreshToken); | ||
case 8: | ||
case 'end': | ||
return _context6.stop(); | ||
} | ||
} | ||
}, _callee6, this); | ||
})); | ||
function storeTokens(_x5) { | ||
return _ref6.apply(this, arguments); | ||
} | ||
return storeTokens; | ||
}() | ||
}, { | ||
key: 'clearUser', | ||
@@ -114,17 +289,23 @@ value: function clearUser() { | ||
value: function () { | ||
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee() { | ||
var _tokens, accessToken, refreshToken, decodedRefreshToken, currentTime, refreshedSession; | ||
var _ref7 = _asyncToGenerator(regeneratorRuntime.mark(function _callee7() { | ||
var _ref8, accessToken, refreshToken, decodedRefreshToken, currentTime, refreshedSession; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
return regeneratorRuntime.wrap(function _callee7$(_context7) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
switch (_context7.prev = _context7.next) { | ||
case 0: | ||
_tokens = this.tokens(), accessToken = _tokens.accessToken, refreshToken = _tokens.refreshToken; | ||
_context7.next = 2; | ||
return this.tokens(); | ||
case 2: | ||
_ref8 = _context7.sent; | ||
accessToken = _ref8.accessToken; | ||
refreshToken = _ref8.refreshToken; | ||
if (!(accessToken && refreshToken)) { | ||
_context.next = 25; | ||
_context7.next = 29; | ||
break; | ||
} | ||
_context.prev = 2; | ||
_context7.prev = 6; | ||
decodedRefreshToken = (0, _jwtDecode2.default)(refreshToken); | ||
@@ -135,3 +316,3 @@ currentTime = Date.now() / 1000; | ||
if (!(decodedRefreshToken.exp < currentTime)) { | ||
_context.next = 10; | ||
_context7.next = 14; | ||
break; | ||
@@ -142,23 +323,24 @@ } | ||
this.clearUser(); | ||
_context.next = 16; | ||
_context7.next = 20; | ||
break; | ||
case 10: | ||
_context.next = 12; | ||
case 14: | ||
_context7.next = 16; | ||
return this.transport.refreshTokens(accessToken, refreshToken); | ||
case 12: | ||
refreshedSession = _context.sent; | ||
case 16: | ||
refreshedSession = _context7.sent; | ||
_context7.next = 19; | ||
return this.storeTokens(refreshedSession); | ||
localStorage.setItem(getTokenKey(ACCESS_TOKEN, this.options), refreshedSession.tokens.accessToken); | ||
localStorage.setItem(getTokenKey(REFRESH_TOKEN, this.options), refreshedSession.tokens.refreshToken); | ||
case 19: | ||
this.store.dispatch((0, _module.setUser)(refreshedSession.user)); | ||
case 16: | ||
_context.next = 23; | ||
case 20: | ||
_context7.next = 27; | ||
break; | ||
case 18: | ||
_context.prev = 18; | ||
_context.t0 = _context['catch'](2); | ||
case 22: | ||
_context7.prev = 22; | ||
_context7.t0 = _context7['catch'](6); | ||
@@ -169,20 +351,20 @@ this.clearTokens(); | ||
case 23: | ||
_context.next = 27; | ||
case 27: | ||
_context7.next = 31; | ||
break; | ||
case 25: | ||
case 29: | ||
this.clearTokens(); | ||
this.clearUser(); | ||
case 27: | ||
case 31: | ||
case 'end': | ||
return _context.stop(); | ||
return _context7.stop(); | ||
} | ||
} | ||
}, _callee, this, [[2, 18]]); | ||
}, _callee7, this, [[6, 22]]); | ||
})); | ||
function refreshSession() { | ||
return _ref.apply(this, arguments); | ||
return _ref7.apply(this, arguments); | ||
} | ||
@@ -195,10 +377,10 @@ | ||
value: function () { | ||
var _ref2 = _asyncToGenerator(regeneratorRuntime.mark(function _callee2(user, callback) { | ||
var _ref9 = _asyncToGenerator(regeneratorRuntime.mark(function _callee8(user, callback) { | ||
var userId; | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
return regeneratorRuntime.wrap(function _callee8$(_context8) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
switch (_context8.prev = _context8.next) { | ||
case 0: | ||
if (!(!user || user.password === undefined)) { | ||
_context2.next = 2; | ||
_context8.next = 2; | ||
break; | ||
@@ -214,3 +396,3 @@ } | ||
if (_common.validators.validatePassword(user.password)) { | ||
_context2.next = 4; | ||
_context8.next = 4; | ||
break; | ||
@@ -223,3 +405,3 @@ } | ||
if (!(!_common.validators.validateUsername(user.username) && !_common.validators.validateEmail(user.email))) { | ||
_context2.next = 6; | ||
_context8.next = 6; | ||
break; | ||
@@ -231,8 +413,8 @@ } | ||
case 6: | ||
_context2.prev = 6; | ||
_context2.next = 9; | ||
_context8.prev = 6; | ||
_context8.next = 9; | ||
return this.transport.createUser(user); | ||
case 9: | ||
userId = _context2.sent; | ||
userId = _context8.sent; | ||
@@ -242,28 +424,28 @@ if (callback && (0, _lodash.isFunction)(callback)) { | ||
} | ||
_context2.next = 13; | ||
_context8.next = 13; | ||
return this.loginWithPassword({ id: userId }, user.password); | ||
case 13: | ||
_context2.next = 19; | ||
_context8.next = 19; | ||
break; | ||
case 15: | ||
_context2.prev = 15; | ||
_context2.t0 = _context2['catch'](6); | ||
_context8.prev = 15; | ||
_context8.t0 = _context8['catch'](6); | ||
if (callback && (0, _lodash.isFunction)(callback)) { | ||
callback(_context2.t0); | ||
callback(_context8.t0); | ||
} | ||
throw new _common.AccountsError(_context2.t0.message); | ||
throw new _common.AccountsError(_context8.t0.message); | ||
case 19: | ||
case 'end': | ||
return _context2.stop(); | ||
return _context8.stop(); | ||
} | ||
} | ||
}, _callee2, this, [[6, 15]]); | ||
}, _callee8, this, [[6, 15]]); | ||
})); | ||
function createUser(_x, _x2) { | ||
return _ref2.apply(this, arguments); | ||
function createUser(_x6, _x7) { | ||
return _ref9.apply(this, arguments); | ||
} | ||
@@ -276,10 +458,10 @@ | ||
value: function () { | ||
var _ref3 = _asyncToGenerator(regeneratorRuntime.mark(function _callee3(user, password, callback) { | ||
var _ref10 = _asyncToGenerator(regeneratorRuntime.mark(function _callee9(user, password, callback) { | ||
var res; | ||
return regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
return regeneratorRuntime.wrap(function _callee9$(_context9) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
switch (_context9.prev = _context9.next) { | ||
case 0: | ||
if (!(!password || !user)) { | ||
_context3.next = 2; | ||
_context9.next = 2; | ||
break; | ||
@@ -292,3 +474,3 @@ } | ||
if (!(!(0, _lodash.isString)(user) && !isValidUserObject(user) || !(0, _lodash.isString)(password))) { | ||
_context3.next = 4; | ||
_context9.next = 4; | ||
break; | ||
@@ -302,11 +484,12 @@ } | ||
this.store.dispatch((0, _module.loggingIn)(true)); | ||
_context3.prev = 5; | ||
_context3.next = 8; | ||
_context9.prev = 5; | ||
_context9.next = 8; | ||
return this.transport.loginWithPassword(user, password); | ||
case 8: | ||
res = _context3.sent; | ||
res = _context9.sent; | ||
_context9.next = 11; | ||
return this.storeTokens(res); | ||
localStorage.setItem(getTokenKey(ACCESS_TOKEN, this.options), res.tokens.accessToken); | ||
localStorage.setItem(getTokenKey(REFRESH_TOKEN, this.options), res.tokens.refreshToken); | ||
case 11: | ||
this.store.dispatch((0, _module.setUser)(res.user)); | ||
@@ -317,13 +500,13 @@ this.options.onSignedInHook(); | ||
} | ||
_context3.next = 20; | ||
_context9.next = 20; | ||
break; | ||
case 16: | ||
_context3.prev = 16; | ||
_context3.t0 = _context3['catch'](5); | ||
_context9.prev = 16; | ||
_context9.t0 = _context9['catch'](5); | ||
if (callback && (0, _lodash.isFunction)(callback)) { | ||
callback(_context3.t0); | ||
callback(_context9.t0); | ||
} | ||
throw new _common.AccountsError(_context3.t0.message); | ||
throw new _common.AccountsError(_context9.t0.message); | ||
@@ -335,10 +518,10 @@ case 20: | ||
case 'end': | ||
return _context3.stop(); | ||
return _context9.stop(); | ||
} | ||
} | ||
}, _callee3, this, [[5, 16]]); | ||
}, _callee9, this, [[5, 16]]); | ||
})); | ||
function loginWithPassword(_x3, _x4, _x5) { | ||
return _ref3.apply(this, arguments); | ||
function loginWithPassword(_x8, _x9, _x10) { | ||
return _ref10.apply(this, arguments); | ||
} | ||
@@ -361,15 +544,27 @@ | ||
value: function () { | ||
var _ref4 = _asyncToGenerator(regeneratorRuntime.mark(function _callee4(callback) { | ||
var _tokens2, accessToken; | ||
var _ref11 = _asyncToGenerator(regeneratorRuntime.mark(function _callee10(callback) { | ||
var _ref12, accessToken; | ||
return regeneratorRuntime.wrap(function _callee4$(_context4) { | ||
return regeneratorRuntime.wrap(function _callee10$(_context10) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
switch (_context10.prev = _context10.next) { | ||
case 0: | ||
_context4.prev = 0; | ||
_tokens2 = this.tokens(), accessToken = _tokens2.accessToken; | ||
_context4.next = 4; | ||
_context10.prev = 0; | ||
_context10.next = 3; | ||
return this.tokens(); | ||
case 3: | ||
_ref12 = _context10.sent; | ||
accessToken = _ref12.accessToken; | ||
if (!accessToken) { | ||
_context10.next = 8; | ||
break; | ||
} | ||
_context10.next = 8; | ||
return this.transport.logout(accessToken); | ||
case 4: | ||
case 8: | ||
this.clearTokens(); | ||
@@ -381,24 +576,24 @@ this.store.dispatch((0, _module.clearUser)()); | ||
this.options.onSignedOutHook(); | ||
_context4.next = 14; | ||
_context10.next = 18; | ||
break; | ||
case 10: | ||
_context4.prev = 10; | ||
_context4.t0 = _context4['catch'](0); | ||
case 14: | ||
_context10.prev = 14; | ||
_context10.t0 = _context10['catch'](0); | ||
if (callback && (0, _lodash.isFunction)(callback)) { | ||
callback(_context4.t0); | ||
callback(_context10.t0); | ||
} | ||
throw new _common.AccountsError(_context4.t0.message); | ||
throw new _common.AccountsError(_context10.t0.message); | ||
case 14: | ||
case 18: | ||
case 'end': | ||
return _context4.stop(); | ||
return _context10.stop(); | ||
} | ||
} | ||
}, _callee4, this, [[0, 10]]); | ||
}, _callee10, this, [[0, 14]]); | ||
})); | ||
function logout(_x6) { | ||
return _ref4.apply(this, arguments); | ||
function logout(_x11) { | ||
return _ref11.apply(this, arguments); | ||
} | ||
@@ -405,0 +600,0 @@ |
@@ -533,4 +533,5 @@ 'use strict'; | ||
}))); | ||
it('stores user in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee15() { | ||
var transport; | ||
it('fetch tokens from storage when storage is async', _asyncToGenerator(regeneratorRuntime.mark(function _callee15() { | ||
var transport, tokens; | ||
return regeneratorRuntime.wrap(function _callee15$(_context15) { | ||
@@ -546,4 +547,82 @@ while (1) { | ||
_AccountsClient2.default.config({ | ||
history: history, | ||
tokenStorage: { | ||
getItem: function getItem() { | ||
return Promise.resolve('testValue'); | ||
} | ||
} | ||
}, transport); | ||
_context15.next = 4; | ||
return _AccountsClient2.default.tokens(); | ||
case 4: | ||
tokens = _context15.sent; | ||
expect(tokens.accessToken).toBe('testValue'); | ||
expect(tokens.refreshToken).toBe('testValue'); | ||
case 7: | ||
case 'end': | ||
return _context15.stop(); | ||
} | ||
} | ||
}, _callee15, undefined); | ||
}))); | ||
it('fetch tokens from storage when storage is sync', _asyncToGenerator(regeneratorRuntime.mark(function _callee16() { | ||
var transport, tokens; | ||
return regeneratorRuntime.wrap(function _callee16$(_context16) { | ||
while (1) { | ||
switch (_context16.prev = _context16.next) { | ||
case 0: | ||
transport = { | ||
loginWithPassword: function loginWithPassword() { | ||
return Promise.resolve(loggedInUser); | ||
} | ||
}; | ||
_AccountsClient2.default.config({ | ||
history: history, | ||
tokenStorage: { | ||
getItem: function getItem() { | ||
return 'testValue'; | ||
} | ||
} | ||
}, transport); | ||
_context16.next = 4; | ||
return _AccountsClient2.default.tokens(); | ||
case 4: | ||
tokens = _context16.sent; | ||
expect(tokens.accessToken).toBe('testValue'); | ||
expect(tokens.refreshToken).toBe('testValue'); | ||
case 7: | ||
case 'end': | ||
return _context16.stop(); | ||
} | ||
} | ||
}, _callee16, undefined); | ||
}))); | ||
it('stores user in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee17() { | ||
var transport; | ||
return regeneratorRuntime.wrap(function _callee17$(_context17) { | ||
while (1) { | ||
switch (_context17.prev = _context17.next) { | ||
case 0: | ||
transport = { | ||
loginWithPassword: function loginWithPassword() { | ||
return Promise.resolve(loggedInUser); | ||
} | ||
}; | ||
_AccountsClient2.default.config({ history: history }, transport); | ||
_context15.next = 4; | ||
_context17.next = 4; | ||
return _AccountsClient2.default.loginWithPassword('username', 'password'); | ||
@@ -556,14 +635,14 @@ | ||
case 'end': | ||
return _context15.stop(); | ||
return _context17.stop(); | ||
} | ||
} | ||
}, _callee15, undefined); | ||
}, _callee17, undefined); | ||
}))); | ||
}); | ||
describe('logout', function () { | ||
it('calls callback on successful logout', _asyncToGenerator(regeneratorRuntime.mark(function _callee16() { | ||
it('calls callback on successful logout', _asyncToGenerator(regeneratorRuntime.mark(function _callee18() { | ||
var transport, callback; | ||
return regeneratorRuntime.wrap(function _callee16$(_context16) { | ||
return regeneratorRuntime.wrap(function _callee18$(_context18) { | ||
while (1) { | ||
switch (_context16.prev = _context16.next) { | ||
switch (_context18.prev = _context18.next) { | ||
case 0: | ||
@@ -578,3 +657,3 @@ transport = { | ||
callback = jest.fn(); | ||
_context16.next = 5; | ||
_context18.next = 5; | ||
return _AccountsClient2.default.logout(callback); | ||
@@ -587,12 +666,12 @@ | ||
case 'end': | ||
return _context16.stop(); | ||
return _context18.stop(); | ||
} | ||
} | ||
}, _callee16, undefined); | ||
}, _callee18, undefined); | ||
}))); | ||
it('calls onLogout on successful logout', _asyncToGenerator(regeneratorRuntime.mark(function _callee17() { | ||
it('calls onLogout on successful logout', _asyncToGenerator(regeneratorRuntime.mark(function _callee19() { | ||
var onSignedOutHook, transport; | ||
return regeneratorRuntime.wrap(function _callee17$(_context17) { | ||
return regeneratorRuntime.wrap(function _callee19$(_context19) { | ||
while (1) { | ||
switch (_context17.prev = _context17.next) { | ||
switch (_context19.prev = _context19.next) { | ||
case 0: | ||
@@ -607,3 +686,3 @@ onSignedOutHook = jest.fn(); | ||
_AccountsClient2.default.config({ history: history, onSignedOutHook: onSignedOutHook }, transport); | ||
_context17.next = 5; | ||
_context19.next = 5; | ||
return _AccountsClient2.default.logout(); | ||
@@ -616,12 +695,13 @@ | ||
case 'end': | ||
return _context17.stop(); | ||
return _context19.stop(); | ||
} | ||
} | ||
}, _callee17, undefined); | ||
}, _callee19, undefined); | ||
}))); | ||
it('calls callback on failure with error message', _asyncToGenerator(regeneratorRuntime.mark(function _callee18() { | ||
it('calls callback on failure with error message', _asyncToGenerator(regeneratorRuntime.mark(function _callee20() { | ||
var transport, callback; | ||
return regeneratorRuntime.wrap(function _callee18$(_context18) { | ||
return regeneratorRuntime.wrap(function _callee20$(_context20) { | ||
while (1) { | ||
switch (_context18.prev = _context18.next) { | ||
switch (_context20.prev = _context20.next) { | ||
case 0: | ||
@@ -634,37 +714,38 @@ transport = { | ||
_AccountsClient2.default.instance.storeTokens({ tokens: { accessToken: '1' } }); | ||
_AccountsClient2.default.config({ history: history }, transport); | ||
callback = jest.fn(); | ||
_context18.prev = 3; | ||
_context18.next = 6; | ||
_context20.prev = 4; | ||
_context20.next = 7; | ||
return _AccountsClient2.default.logout(callback); | ||
case 6: | ||
case 7: | ||
throw new Error(); | ||
case 9: | ||
_context18.prev = 9; | ||
_context18.t0 = _context18['catch'](3); | ||
case 10: | ||
_context20.prev = 10; | ||
_context20.t0 = _context20['catch'](4); | ||
expect(_context18.t0.message).toEqual('error message'); | ||
expect(_context20.t0.message).toEqual('error message'); | ||
expect(callback.mock.calls.length).toEqual(1); | ||
expect(callback.mock.calls[0][0]).toEqual({ message: 'error message' }); | ||
case 14: | ||
case 15: | ||
case 'end': | ||
return _context18.stop(); | ||
return _context20.stop(); | ||
} | ||
} | ||
}, _callee18, undefined, [[3, 9]]); | ||
}, _callee20, undefined, [[4, 10]]); | ||
}))); | ||
}); | ||
describe('refreshSession', _asyncToGenerator(regeneratorRuntime.mark(function _callee21() { | ||
return regeneratorRuntime.wrap(function _callee21$(_context21) { | ||
describe('refreshSession', _asyncToGenerator(regeneratorRuntime.mark(function _callee23() { | ||
return regeneratorRuntime.wrap(function _callee23$(_context23) { | ||
while (1) { | ||
switch (_context21.prev = _context21.next) { | ||
switch (_context23.prev = _context23.next) { | ||
case 0: | ||
// TODO test that user and tokens are cleared if refreshToken is expired | ||
it('clears tokens and user if tokens are not set', _asyncToGenerator(regeneratorRuntime.mark(function _callee19() { | ||
return regeneratorRuntime.wrap(function _callee19$(_context19) { | ||
it('clears tokens and user if tokens are not set', _asyncToGenerator(regeneratorRuntime.mark(function _callee21() { | ||
return regeneratorRuntime.wrap(function _callee21$(_context21) { | ||
while (1) { | ||
switch (_context19.prev = _context19.next) { | ||
switch (_context21.prev = _context21.next) { | ||
case 0: | ||
@@ -678,3 +759,3 @@ _AccountsClient2.default.config({}, {}); | ||
}); | ||
_context19.next = 5; | ||
_context21.next = 5; | ||
return _AccountsClient2.default.refreshSession(); | ||
@@ -688,12 +769,12 @@ | ||
case 'end': | ||
return _context19.stop(); | ||
return _context21.stop(); | ||
} | ||
} | ||
}, _callee19, undefined); | ||
}, _callee21, undefined); | ||
}))); | ||
it('clears tokens, users and throws error if bad refresh token provided', _asyncToGenerator(regeneratorRuntime.mark(function _callee20() { | ||
it('clears tokens, users and throws error if bad refresh token provided', _asyncToGenerator(regeneratorRuntime.mark(function _callee22() { | ||
var message; | ||
return regeneratorRuntime.wrap(function _callee20$(_context20) { | ||
return regeneratorRuntime.wrap(function _callee22$(_context22) { | ||
while (1) { | ||
switch (_context20.prev = _context20.next) { | ||
switch (_context22.prev = _context22.next) { | ||
case 0: | ||
@@ -709,4 +790,4 @@ _AccountsClient2.default.config({}, {}); | ||
}); | ||
_context20.prev = 5; | ||
_context20.next = 8; | ||
_context22.prev = 5; | ||
_context22.next = 8; | ||
return _AccountsClient2.default.refreshSession(); | ||
@@ -718,5 +799,5 @@ | ||
case 11: | ||
_context20.prev = 11; | ||
_context20.t0 = _context20['catch'](5); | ||
message = _context20.t0.message; | ||
_context22.prev = 11; | ||
_context22.t0 = _context22['catch'](5); | ||
message = _context22.t0.message; | ||
@@ -727,6 +808,6 @@ expect(message).toEqual('falsy token provided'); | ||
case 'end': | ||
return _context20.stop(); | ||
return _context22.stop(); | ||
} | ||
} | ||
}, _callee20, undefined, [[5, 11]]); | ||
}, _callee22, undefined, [[5, 11]]); | ||
}))); | ||
@@ -770,7 +851,7 @@ // it('requests a new token pair, sets the tokens and the user', async () => { | ||
case 'end': | ||
return _context21.stop(); | ||
return _context23.stop(); | ||
} | ||
} | ||
}, _callee21, undefined); | ||
}, _callee23, undefined); | ||
}))); | ||
}); |
@@ -22,5 +22,8 @@ 'use strict'; | ||
exports.default = _extends({}, _common.config, { | ||
store: null, | ||
reduxLogger: null, | ||
reduxStoreKey: 'accounts', | ||
tokenStorage: global.localStorage, | ||
server: '', | ||
localStoragePrefix: '', | ||
tokenStoragePrefix: '', | ||
title: '', | ||
@@ -27,0 +30,0 @@ requestPermissions: [], |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.config = exports.AccountsClient = undefined; | ||
exports.reducer = exports.config = exports.AccountsClient = undefined; | ||
@@ -17,2 +17,6 @@ var _AccountsClient = require('./AccountsClient'); | ||
var _module = require('./module'); | ||
var _module2 = _interopRequireDefault(_module); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -22,2 +26,3 @@ | ||
exports.AccountsClient = _AccountsClient.AccountsClient; | ||
exports.config = _config2.default; | ||
exports.config = _config2.default; | ||
exports.reducer = _module2.default; |
@@ -15,2 +15,3 @@ 'use strict'; | ||
return _AccountsClient2.default.options().history.push(path); | ||
}; // eslint-disable-next-line import/no-named-as-default | ||
}; | ||
// eslint-disable-next-line import/no-named-as-default |
{ | ||
"name": "@accounts/client", | ||
"version": "0.0.4", | ||
"version": "0.0.5-alpha.451f3013", | ||
"description": "Fullstack authentication and accounts-management", | ||
@@ -12,2 +12,3 @@ "main": "lib/index.js", | ||
"compile": "babel ./src --out-dir ./lib", | ||
"postcompile": "npm run flow:prepublish", | ||
"prepublish": "npm run compile", | ||
@@ -17,2 +18,5 @@ "test": "npm run testonly", | ||
"testonly": "jest", | ||
"flow:check": "flow check", | ||
"flow:gen": "flow gen-flow-files ./src/index.js > ./lib/index.js.flow", | ||
"flow:prepublish": "for i in `ls ./src/*.js`; do cp $i `echo $i | sed \"s/src/lib/g\" | sed \"s/js/js\\.flow/g\"`; done", | ||
"coverage": "npm run testonly -- --coverage", | ||
@@ -56,3 +60,3 @@ "coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage" | ||
"coveralls": "^2.11.14", | ||
"flow-bin": "^0.37.0", | ||
"flow-bin": "^0.39.0", | ||
"jest": "^18.0.0", | ||
@@ -66,3 +70,3 @@ "lerna": "2.0.0-beta.32", | ||
"dependencies": { | ||
"@accounts/common": "^0.0.4", | ||
"@accounts/common": "^0.0.5-alpha.451f3013", | ||
"immutable": "^3.8.1", | ||
@@ -69,0 +73,0 @@ "jwt-decode": "^2.1.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
135976
26
2557
0
+ Added@accounts/common@0.0.5(transitive)
- Removed@accounts/common@0.0.4(transitive)