@accounts/client
Advanced tools
Comparing version 0.0.19 to 0.1.0-alpha.357173dd
1764
lib/index.js
@@ -1,1754 +0,10 @@ | ||
(function webpackUniversalModuleDefinition(root, factory) { | ||
if(typeof exports === 'object' && typeof module === 'object') | ||
module.exports = factory(require("babel-runtime/helpers/extends"), require("babel-runtime/regenerator"), require("babel-runtime/core-js/promise"), require("babel-runtime/helpers/asyncToGenerator"), require("babel-runtime/helpers/defineProperty"), require("babel-runtime/helpers/classCallCheck"), require("babel-runtime/helpers/createClass"), require("lodash"), require("jwt-decode"), require("@accounts/common"), require("babel-runtime/helpers/toConsumableArray"), require("redux"), require("immutable"), require("redux-immutable"), require("lodash/isString"), require("crypto-js")); | ||
else if(typeof define === 'function' && define.amd) | ||
define(["babel-runtime/helpers/extends", "babel-runtime/regenerator", "babel-runtime/core-js/promise", "babel-runtime/helpers/asyncToGenerator", "babel-runtime/helpers/defineProperty", "babel-runtime/helpers/classCallCheck", "babel-runtime/helpers/createClass", "lodash", "jwt-decode", "@accounts/common", "babel-runtime/helpers/toConsumableArray", "redux", "immutable", "redux-immutable", "lodash/isString", "crypto-js"], factory); | ||
else if(typeof exports === 'object') | ||
exports["@accounts/client"] = factory(require("babel-runtime/helpers/extends"), require("babel-runtime/regenerator"), require("babel-runtime/core-js/promise"), require("babel-runtime/helpers/asyncToGenerator"), require("babel-runtime/helpers/defineProperty"), require("babel-runtime/helpers/classCallCheck"), require("babel-runtime/helpers/createClass"), require("lodash"), require("jwt-decode"), require("@accounts/common"), require("babel-runtime/helpers/toConsumableArray"), require("redux"), require("immutable"), require("redux-immutable"), require("lodash/isString"), require("crypto-js")); | ||
else | ||
root["@accounts/client"] = factory(root["babel-runtime/helpers/extends"], root["babel-runtime/regenerator"], root["babel-runtime/core-js/promise"], root["babel-runtime/helpers/asyncToGenerator"], root["babel-runtime/helpers/defineProperty"], root["babel-runtime/helpers/classCallCheck"], root["babel-runtime/helpers/createClass"], root["lodash"], root["jwt-decode"], root["@accounts/common"], root["babel-runtime/helpers/toConsumableArray"], root["redux"], root["immutable"], root["redux-immutable"], root["lodash/isString"], root["crypto-js"]); | ||
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__, __WEBPACK_EXTERNAL_MODULE_3__, __WEBPACK_EXTERNAL_MODULE_4__, __WEBPACK_EXTERNAL_MODULE_5__, __WEBPACK_EXTERNAL_MODULE_6__, __WEBPACK_EXTERNAL_MODULE_7__, __WEBPACK_EXTERNAL_MODULE_8__, __WEBPACK_EXTERNAL_MODULE_9__, __WEBPACK_EXTERNAL_MODULE_10__, __WEBPACK_EXTERNAL_MODULE_11__, __WEBPACK_EXTERNAL_MODULE_15__, __WEBPACK_EXTERNAL_MODULE_16__, __WEBPACK_EXTERNAL_MODULE_17__, __WEBPACK_EXTERNAL_MODULE_18__, __WEBPACK_EXTERNAL_MODULE_21__, __WEBPACK_EXTERNAL_MODULE_22__) { | ||
return /******/ (function(modules) { // webpackBootstrap | ||
/******/ // The module cache | ||
/******/ var installedModules = {}; | ||
/******/ // The require function | ||
/******/ function __webpack_require__(moduleId) { | ||
/******/ // Check if module is in cache | ||
/******/ if(installedModules[moduleId]) | ||
/******/ return installedModules[moduleId].exports; | ||
/******/ // Create a new module (and put it into the cache) | ||
/******/ var module = installedModules[moduleId] = { | ||
/******/ exports: {}, | ||
/******/ id: moduleId, | ||
/******/ loaded: false | ||
/******/ }; | ||
/******/ // Execute the module function | ||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | ||
/******/ // Flag the module as loaded | ||
/******/ module.loaded = true; | ||
/******/ // Return the exports of the module | ||
/******/ return module.exports; | ||
/******/ } | ||
/******/ // expose the modules object (__webpack_modules__) | ||
/******/ __webpack_require__.m = modules; | ||
/******/ // expose the module cache | ||
/******/ __webpack_require__.c = installedModules; | ||
/******/ // __webpack_public_path__ | ||
/******/ __webpack_require__.p = ""; | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(0); | ||
/******/ }) | ||
/************************************************************************/ | ||
/******/ ([ | ||
/* 0 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.reducer = exports.config = exports.AccountsClient = undefined; | ||
var _AccountsClient = __webpack_require__(1); | ||
var _AccountsClient2 = _interopRequireDefault(_AccountsClient); | ||
var _config = __webpack_require__(12); | ||
var _config2 = _interopRequireDefault(_config); | ||
var _module = __webpack_require__(19); | ||
var _module2 = _interopRequireDefault(_module); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = _AccountsClient2.default; | ||
exports.AccountsClient = _AccountsClient.AccountsClient; | ||
exports.config = _config2.default; | ||
exports.reducer = _module2.default; | ||
/***/ }), | ||
/* 1 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.AccountsClient = undefined; | ||
var _extends2 = __webpack_require__(2); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _regenerator = __webpack_require__(3); | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
var _promise = __webpack_require__(4); | ||
var _promise2 = _interopRequireDefault(_promise); | ||
var _asyncToGenerator2 = __webpack_require__(5); | ||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
var _defineProperty2 = __webpack_require__(6); | ||
var _defineProperty3 = _interopRequireDefault(_defineProperty2); | ||
var _classCallCheck2 = __webpack_require__(7); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = __webpack_require__(8); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _lodash = __webpack_require__(9); | ||
var _jwtDecode = __webpack_require__(10); | ||
var _jwtDecode2 = _interopRequireDefault(_jwtDecode); | ||
var _common = __webpack_require__(11); | ||
var _config2 = __webpack_require__(12); | ||
var _config3 = _interopRequireDefault(_config2); | ||
var _createStore = __webpack_require__(14); | ||
var _createStore2 = _interopRequireDefault(_createStore); | ||
var _module = __webpack_require__(19); | ||
var _module2 = _interopRequireDefault(_module); | ||
var _encryption = __webpack_require__(20); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var isValidUserObject = function isValidUserObject(user) { | ||
return (0, _lodash.has)(user, 'username') || (0, _lodash.has)(user, 'email') || (0, _lodash.has)(user, 'id'); | ||
}; | ||
var ACCESS_TOKEN = 'accounts:accessToken'; | ||
var REFRESH_TOKEN = 'accounts:refreshToken'; | ||
var ORIGINAL_ACCESS_TOKEN = 'accounts:originalAccessToken'; | ||
var ORIGINAL_REFRESH_TOKEN = 'accounts:originalRefreshToken'; | ||
var getTokenKey = function getTokenKey(type, options) { | ||
return (0, _lodash.isString)(options.tokenStoragePrefix) && options.tokenStoragePrefix.length > 0 ? options.tokenStoragePrefix + ':' + type : type; | ||
}; | ||
var AccountsClient = exports.AccountsClient = function () { | ||
function AccountsClient(options, transport) { | ||
(0, _classCallCheck3.default)(this, AccountsClient); | ||
this.options = options; | ||
this.storage = options.tokenStorage || _config3.default.tokenStorage; | ||
if (!transport) { | ||
throw new _common.AccountsError('A REST or GraphQL transport is required'); | ||
} | ||
this.transport = transport; | ||
var middleware = options.reduxLogger ? [options.reduxLogger] : []; | ||
var reduxStoreKey = options.reduxStoreKey || _config3.default.reduxStoreKey; | ||
this.store = options.store || (0, _createStore2.default)({ | ||
reducers: (0, _defineProperty3.default)({}, reduxStoreKey, _module2.default), | ||
middleware: middleware | ||
}); | ||
} | ||
(0, _createClass3.default)(AccountsClient, [{ | ||
key: 'getState', | ||
value: function getState() { | ||
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 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(keyName) { | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
return _context.abrupt('return', _promise2.default.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 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(keyName, value) { | ||
return _regenerator2.default.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
return _context2.abrupt('return', _promise2.default.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 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3(keyName) { | ||
return _regenerator2.default.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
return _context3.abrupt('return', _promise2.default.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: 'loadTokensFromStorage', | ||
value: function () { | ||
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4() { | ||
var tokens; | ||
return _regenerator2.default.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; | ||
if (_context4.t0) { | ||
_context4.next = 5; | ||
break; | ||
} | ||
_context4.t0 = null; | ||
case 5: | ||
_context4.t1 = _context4.t0; | ||
_context4.next = 8; | ||
return this.getStorageData(getTokenKey(REFRESH_TOKEN, this.options)); | ||
case 8: | ||
_context4.t2 = _context4.sent; | ||
if (_context4.t2) { | ||
_context4.next = 11; | ||
break; | ||
} | ||
_context4.t2 = null; | ||
case 11: | ||
_context4.t3 = _context4.t2; | ||
tokens = { | ||
accessToken: _context4.t1, | ||
refreshToken: _context4.t3 | ||
}; | ||
this.store.dispatch((0, _module.setTokens)(tokens)); | ||
case 14: | ||
case 'end': | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee4, this); | ||
})); | ||
function loadTokensFromStorage() { | ||
return _ref4.apply(this, arguments); | ||
} | ||
return loadTokensFromStorage; | ||
}() | ||
}, { | ||
key: 'loadOriginalTokensFromStorage', | ||
value: function () { | ||
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5() { | ||
var tokens; | ||
return _regenerator2.default.wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
_context5.next = 2; | ||
return this.getStorageData(getTokenKey(ORIGINAL_ACCESS_TOKEN, this.options)); | ||
case 2: | ||
_context5.t0 = _context5.sent; | ||
if (_context5.t0) { | ||
_context5.next = 5; | ||
break; | ||
} | ||
_context5.t0 = null; | ||
case 5: | ||
_context5.t1 = _context5.t0; | ||
_context5.next = 8; | ||
return this.getStorageData(getTokenKey(ORIGINAL_REFRESH_TOKEN, this.options)); | ||
case 8: | ||
_context5.t2 = _context5.sent; | ||
if (_context5.t2) { | ||
_context5.next = 11; | ||
break; | ||
} | ||
_context5.t2 = null; | ||
case 11: | ||
_context5.t3 = _context5.t2; | ||
tokens = { | ||
accessToken: _context5.t1, | ||
refreshToken: _context5.t3 | ||
}; | ||
this.store.dispatch((0, _module.setOriginalTokens)(tokens)); | ||
case 14: | ||
case 'end': | ||
return _context5.stop(); | ||
} | ||
} | ||
}, _callee5, this); | ||
})); | ||
function loadOriginalTokensFromStorage() { | ||
return _ref5.apply(this, arguments); | ||
} | ||
return loadOriginalTokensFromStorage; | ||
}() | ||
}, { | ||
key: 'user', | ||
value: function user() { | ||
var user = this.getState().get('user'); | ||
return user ? user.toJS() : null; | ||
} | ||
}, { | ||
key: 'impersonate', | ||
value: function () { | ||
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(username) { | ||
var _ref7, accessToken, refreshToken, res, persistImpersonation; | ||
return _regenerator2.default.wrap(function _callee6$(_context6) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
case 0: | ||
if ((0, _lodash.isString)(username)) { | ||
_context6.next = 2; | ||
break; | ||
} | ||
throw new _common.AccountsError('Username is required'); | ||
case 2: | ||
if (!this.isImpersonated()) { | ||
_context6.next = 4; | ||
break; | ||
} | ||
throw new _common.AccountsError('User already impersonating'); | ||
case 4: | ||
_context6.next = 6; | ||
return this.tokens(); | ||
case 6: | ||
_ref7 = _context6.sent; | ||
accessToken = _ref7.accessToken; | ||
refreshToken = _ref7.refreshToken; | ||
if (accessToken) { | ||
_context6.next = 11; | ||
break; | ||
} | ||
throw new _common.AccountsError('There is no access tokens available'); | ||
case 11: | ||
_context6.next = 13; | ||
return this.transport.impersonate(accessToken, username); | ||
case 13: | ||
res = _context6.sent; | ||
if (res.authorized) { | ||
_context6.next = 18; | ||
break; | ||
} | ||
throw new _common.AccountsError('User unauthorized to impersonate ' + username); | ||
case 18: | ||
persistImpersonation = this.options.persistImpersonation; | ||
this.store.dispatch((0, _module.setImpersonated)(true)); | ||
this.store.dispatch((0, _module.setOriginalTokens)({ accessToken: accessToken, refreshToken: refreshToken })); | ||
if (!persistImpersonation) { | ||
_context6.next = 26; | ||
break; | ||
} | ||
_context6.next = 24; | ||
return this.storeOriginalTokens({ accessToken: accessToken, refreshToken: refreshToken }); | ||
case 24: | ||
_context6.next = 26; | ||
return this.storeTokens(res.tokens); | ||
case 26: | ||
this.store.dispatch((0, _module.setTokens)(res.tokens)); | ||
this.store.dispatch((0, _module.setUser)(res.user)); | ||
return _context6.abrupt('return', res); | ||
case 29: | ||
case 'end': | ||
return _context6.stop(); | ||
} | ||
} | ||
}, _callee6, this); | ||
})); | ||
function impersonate(_x5) { | ||
return _ref6.apply(this, arguments); | ||
} | ||
return impersonate; | ||
}() | ||
}, { | ||
key: 'stopImpersonation', | ||
value: function () { | ||
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7() { | ||
return _regenerator2.default.wrap(function _callee7$(_context7) { | ||
while (1) { | ||
switch (_context7.prev = _context7.next) { | ||
case 0: | ||
if (!this.isImpersonated()) { | ||
_context7.next = 6; | ||
break; | ||
} | ||
this.store.dispatch((0, _module.setTokens)(this.originalTokens())); | ||
this.store.dispatch((0, _module.clearOriginalTokens)()); | ||
this.store.dispatch((0, _module.setImpersonated)(false)); | ||
_context7.next = 6; | ||
return this.refreshSession(); | ||
case 6: | ||
case 'end': | ||
return _context7.stop(); | ||
} | ||
} | ||
}, _callee7, this); | ||
})); | ||
function stopImpersonation() { | ||
return _ref8.apply(this, arguments); | ||
} | ||
return stopImpersonation; | ||
}() | ||
}, { | ||
key: 'isImpersonated', | ||
value: function isImpersonated() { | ||
return this.getState().get('isImpersonated'); | ||
} | ||
}, { | ||
key: 'originalTokens', | ||
value: function originalTokens() { | ||
var tokens = this.getState().get('originalTokens'); | ||
return tokens ? tokens.toJS() : { | ||
accessToken: null, | ||
refreshToken: null | ||
}; | ||
} | ||
}, { | ||
key: 'tokens', | ||
value: function tokens() { | ||
var tokens = this.getState().get('tokens'); | ||
return tokens ? tokens.toJS() : { | ||
accessToken: null, | ||
refreshToken: null | ||
}; | ||
} | ||
}, { | ||
key: 'clearTokens', | ||
value: function () { | ||
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8() { | ||
return _regenerator2.default.wrap(function _callee8$(_context8) { | ||
while (1) { | ||
switch (_context8.prev = _context8.next) { | ||
case 0: | ||
this.store.dispatch((0, _module.clearTokens)()); | ||
_context8.next = 3; | ||
return this.removeStorageData(getTokenKey(ACCESS_TOKEN, this.options)); | ||
case 3: | ||
_context8.next = 5; | ||
return this.removeStorageData(getTokenKey(REFRESH_TOKEN, this.options)); | ||
case 5: | ||
case 'end': | ||
return _context8.stop(); | ||
} | ||
} | ||
}, _callee8, this); | ||
})); | ||
function clearTokens() { | ||
return _ref9.apply(this, arguments); | ||
} | ||
return clearTokens; | ||
}() | ||
}, { | ||
key: 'storeTokens', | ||
value: function () { | ||
var _ref10 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(tokens) { | ||
var newAccessToken, newRefreshToken; | ||
return _regenerator2.default.wrap(function _callee9$(_context9) { | ||
while (1) { | ||
switch (_context9.prev = _context9.next) { | ||
case 0: | ||
if (!tokens) { | ||
_context9.next = 9; | ||
break; | ||
} | ||
newAccessToken = tokens.accessToken; | ||
if (!newAccessToken) { | ||
_context9.next = 5; | ||
break; | ||
} | ||
_context9.next = 5; | ||
return this.setStorageData(getTokenKey(ACCESS_TOKEN, this.options), newAccessToken); | ||
case 5: | ||
newRefreshToken = tokens.refreshToken; | ||
if (!newRefreshToken) { | ||
_context9.next = 9; | ||
break; | ||
} | ||
_context9.next = 9; | ||
return this.setStorageData(getTokenKey(REFRESH_TOKEN, this.options), newRefreshToken); | ||
case 9: | ||
case 'end': | ||
return _context9.stop(); | ||
} | ||
} | ||
}, _callee9, this); | ||
})); | ||
function storeTokens(_x6) { | ||
return _ref10.apply(this, arguments); | ||
} | ||
return storeTokens; | ||
}() | ||
}, { | ||
key: 'storeOriginalTokens', | ||
value: function () { | ||
var _ref11 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee10(tokens) { | ||
var originalAccessToken, originalRefreshToken; | ||
return _regenerator2.default.wrap(function _callee10$(_context10) { | ||
while (1) { | ||
switch (_context10.prev = _context10.next) { | ||
case 0: | ||
if (!tokens) { | ||
_context10.next = 9; | ||
break; | ||
} | ||
originalAccessToken = tokens.accessToken; | ||
if (!originalAccessToken) { | ||
_context10.next = 5; | ||
break; | ||
} | ||
_context10.next = 5; | ||
return this.setStorageData(getTokenKey(ORIGINAL_ACCESS_TOKEN, this.options), originalAccessToken); | ||
case 5: | ||
originalRefreshToken = tokens.refreshToken; | ||
if (!originalRefreshToken) { | ||
_context10.next = 9; | ||
break; | ||
} | ||
_context10.next = 9; | ||
return this.setStorageData(getTokenKey(ORIGINAL_REFRESH_TOKEN, this.options), originalRefreshToken); | ||
case 9: | ||
case 'end': | ||
return _context10.stop(); | ||
} | ||
} | ||
}, _callee10, this); | ||
})); | ||
function storeOriginalTokens(_x7) { | ||
return _ref11.apply(this, arguments); | ||
} | ||
return storeOriginalTokens; | ||
}() | ||
}, { | ||
key: 'clearUser', | ||
value: function clearUser() { | ||
this.store.dispatch((0, _module.clearUser)()); | ||
} | ||
}, { | ||
key: 'resumeSession', | ||
value: function () { | ||
var _ref12 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee11() { | ||
return _regenerator2.default.wrap(function _callee11$(_context11) { | ||
while (1) { | ||
switch (_context11.prev = _context11.next) { | ||
case 0: | ||
_context11.prev = 0; | ||
_context11.next = 3; | ||
return this.refreshSession(); | ||
case 3: | ||
if (this.options.onResumedSessionHook && (0, _lodash.isFunction)(this.options.onResumedSessionHook)) { | ||
this.options.onResumedSessionHook(); | ||
} | ||
_context11.next = 9; | ||
break; | ||
case 6: | ||
_context11.prev = 6; | ||
_context11.t0 = _context11['catch'](0); | ||
throw _context11.t0; | ||
case 9: | ||
case 'end': | ||
return _context11.stop(); | ||
} | ||
} | ||
}, _callee11, this, [[0, 6]]); | ||
})); | ||
function resumeSession() { | ||
return _ref12.apply(this, arguments); | ||
} | ||
return resumeSession; | ||
}() | ||
}, { | ||
key: 'refreshSession', | ||
value: function () { | ||
var _ref13 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee12() { | ||
var _ref14, accessToken, refreshToken, decodedRefreshToken, currentTime, refreshedSession; | ||
return _regenerator2.default.wrap(function _callee12$(_context12) { | ||
while (1) { | ||
switch (_context12.prev = _context12.next) { | ||
case 0: | ||
_context12.next = 2; | ||
return this.tokens(); | ||
case 2: | ||
_ref14 = _context12.sent; | ||
accessToken = _ref14.accessToken; | ||
refreshToken = _ref14.refreshToken; | ||
if (!(accessToken && refreshToken)) { | ||
_context12.next = 33; | ||
break; | ||
} | ||
_context12.prev = 6; | ||
this.store.dispatch((0, _module.loggingIn)(true)); | ||
decodedRefreshToken = (0, _jwtDecode2.default)(refreshToken); | ||
currentTime = Date.now() / 1000; | ||
// Refresh token is expired, user must sign back in | ||
if (!(decodedRefreshToken.exp < currentTime)) { | ||
_context12.next = 15; | ||
break; | ||
} | ||
this.clearTokens(); | ||
this.clearUser(); | ||
_context12.next = 23; | ||
break; | ||
case 15: | ||
_context12.next = 17; | ||
return this.transport.refreshTokens(accessToken, refreshToken); | ||
case 17: | ||
refreshedSession = _context12.sent; | ||
this.store.dispatch((0, _module.loggingIn)(false)); | ||
_context12.next = 21; | ||
return this.storeTokens(refreshedSession.tokens); | ||
case 21: | ||
this.store.dispatch((0, _module.setTokens)(refreshedSession.tokens)); | ||
this.store.dispatch((0, _module.setUser)(refreshedSession.user)); | ||
case 23: | ||
_context12.next = 31; | ||
break; | ||
case 25: | ||
_context12.prev = 25; | ||
_context12.t0 = _context12['catch'](6); | ||
this.store.dispatch((0, _module.loggingIn)(false)); | ||
this.clearTokens(); | ||
this.clearUser(); | ||
throw new _common.AccountsError('falsy token provided'); | ||
case 31: | ||
_context12.next = 36; | ||
break; | ||
case 33: | ||
this.clearTokens(); | ||
this.clearUser(); | ||
throw new _common.AccountsError('no tokens provided'); | ||
case 36: | ||
case 'end': | ||
return _context12.stop(); | ||
} | ||
} | ||
}, _callee12, this, [[6, 25]]); | ||
})); | ||
function refreshSession() { | ||
return _ref13.apply(this, arguments); | ||
} | ||
return refreshSession; | ||
}() | ||
}, { | ||
key: 'createUser', | ||
value: function () { | ||
var _ref15 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee13(user, callback) { | ||
var hashAlgorithm, password, userToCreate, userId, onUserCreated; | ||
return _regenerator2.default.wrap(function _callee13$(_context13) { | ||
while (1) { | ||
switch (_context13.prev = _context13.next) { | ||
case 0: | ||
if (!(!user || user.password === undefined)) { | ||
_context13.next = 2; | ||
break; | ||
} | ||
throw new _common.AccountsError('Unrecognized options for create user request', { | ||
username: user && user.username, | ||
email: user && user.email | ||
}, 400); | ||
case 2: | ||
if (!(!user.password || (0, _lodash.isString)(user.password) && !_common.validators.validatePassword(user.password))) { | ||
_context13.next = 4; | ||
break; | ||
} | ||
throw new _common.AccountsError('Password is required'); | ||
case 4: | ||
if (!(!_common.validators.validateUsername(user.username) && !_common.validators.validateEmail(user.email))) { | ||
_context13.next = 6; | ||
break; | ||
} | ||
throw new _common.AccountsError('Username or Email is required'); | ||
case 6: | ||
hashAlgorithm = this.options.passwordHashAlgorithm; | ||
password = user.password && hashAlgorithm ? (0, _encryption.hashPassword)(user.password, hashAlgorithm) : user.password; | ||
userToCreate = (0, _extends3.default)({}, user, { password: password }); | ||
_context13.prev = 9; | ||
_context13.next = 12; | ||
return this.transport.createUser(userToCreate); | ||
case 12: | ||
userId = _context13.sent; | ||
onUserCreated = this.options.onUserCreated; | ||
if (callback && (0, _lodash.isFunction)(callback)) { | ||
callback(); | ||
} | ||
if (!(0, _lodash.isFunction)(onUserCreated)) { | ||
_context13.next = 24; | ||
break; | ||
} | ||
_context13.prev = 16; | ||
_context13.next = 19; | ||
return onUserCreated({ id: userId }); | ||
case 19: | ||
_context13.next = 24; | ||
break; | ||
case 21: | ||
_context13.prev = 21; | ||
_context13.t0 = _context13['catch'](16); | ||
console.log(_context13.t0); | ||
case 24: | ||
_context13.next = 26; | ||
return this.loginWithPassword({ id: userId }, user.password); | ||
case 26: | ||
_context13.next = 32; | ||
break; | ||
case 28: | ||
_context13.prev = 28; | ||
_context13.t1 = _context13['catch'](9); | ||
if (callback && (0, _lodash.isFunction)(callback)) { | ||
callback(_context13.t1); | ||
} | ||
throw new _common.AccountsError(_context13.t1.message); | ||
case 32: | ||
case 'end': | ||
return _context13.stop(); | ||
} | ||
} | ||
}, _callee13, this, [[9, 28], [16, 21]]); | ||
})); | ||
function createUser(_x8, _x9) { | ||
return _ref15.apply(this, arguments); | ||
} | ||
return createUser; | ||
}() | ||
}, { | ||
key: 'loginWithPassword', | ||
value: function () { | ||
var _ref16 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee14(user, password, callback) { | ||
var hashAlgorithm, pass, res; | ||
return _regenerator2.default.wrap(function _callee14$(_context14) { | ||
while (1) { | ||
switch (_context14.prev = _context14.next) { | ||
case 0: | ||
if (!(!password || !user)) { | ||
_context14.next = 2; | ||
break; | ||
} | ||
throw new _common.AccountsError('Unrecognized options for login request', user, 400); | ||
case 2: | ||
if (!(!(0, _lodash.isString)(user) && !isValidUserObject(user) || !(0, _lodash.isString)(password))) { | ||
_context14.next = 4; | ||
break; | ||
} | ||
throw new _common.AccountsError('Match failed', user, 400); | ||
case 4: | ||
this.store.dispatch((0, _module.loggingIn)(true)); | ||
_context14.prev = 5; | ||
hashAlgorithm = this.options.passwordHashAlgorithm; | ||
pass = hashAlgorithm ? (0, _encryption.hashPassword)(password, hashAlgorithm) : password; | ||
_context14.next = 10; | ||
return this.transport.loginWithPassword(user, pass); | ||
case 10: | ||
res = _context14.sent; | ||
this.store.dispatch((0, _module.loggingIn)(false)); | ||
_context14.next = 14; | ||
return this.storeTokens(res.tokens); | ||
case 14: | ||
this.store.dispatch((0, _module.setTokens)(res.tokens)); | ||
this.store.dispatch((0, _module.setUser)(res.user)); | ||
if (this.options.onSignedInHook && (0, _lodash.isFunction)(this.options.onSignedInHook)) { | ||
this.options.onSignedInHook(); | ||
} | ||
if (callback && (0, _lodash.isFunction)(callback)) { | ||
callback(null, res); | ||
} | ||
return _context14.abrupt('return', res); | ||
case 21: | ||
_context14.prev = 21; | ||
_context14.t0 = _context14['catch'](5); | ||
this.store.dispatch((0, _module.loggingIn)(false)); | ||
if (callback && (0, _lodash.isFunction)(callback)) { | ||
callback(_context14.t0, null); | ||
} | ||
throw new _common.AccountsError(_context14.t0.message); | ||
case 26: | ||
case 'end': | ||
return _context14.stop(); | ||
} | ||
} | ||
}, _callee14, this, [[5, 21]]); | ||
})); | ||
function loginWithPassword(_x10, _x11, _x12) { | ||
return _ref16.apply(this, arguments); | ||
} | ||
return loginWithPassword; | ||
}() | ||
}, { | ||
key: 'loggingIn', | ||
value: function loggingIn() { | ||
return this.getState().get('loggingIn'); | ||
} | ||
}, { | ||
key: 'isLoading', | ||
value: function isLoading() { | ||
return this.getState().get('isLoading'); | ||
} | ||
}, { | ||
key: 'logout', | ||
value: function () { | ||
var _ref17 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee15(callback) { | ||
var _ref18, accessToken; | ||
return _regenerator2.default.wrap(function _callee15$(_context15) { | ||
while (1) { | ||
switch (_context15.prev = _context15.next) { | ||
case 0: | ||
_context15.prev = 0; | ||
_context15.next = 3; | ||
return this.tokens(); | ||
case 3: | ||
_ref18 = _context15.sent; | ||
accessToken = _ref18.accessToken; | ||
if (!accessToken) { | ||
_context15.next = 8; | ||
break; | ||
} | ||
_context15.next = 8; | ||
return this.transport.logout(accessToken); | ||
case 8: | ||
this.clearTokens(); | ||
this.store.dispatch((0, _module.clearUser)()); | ||
if (callback && (0, _lodash.isFunction)(callback)) { | ||
callback(); | ||
} | ||
if (this.options.onSignedOutHook) { | ||
this.options.onSignedOutHook(); | ||
} | ||
_context15.next = 20; | ||
break; | ||
case 14: | ||
_context15.prev = 14; | ||
_context15.t0 = _context15['catch'](0); | ||
this.clearTokens(); | ||
this.store.dispatch((0, _module.clearUser)()); | ||
if (callback && (0, _lodash.isFunction)(callback)) { | ||
callback(_context15.t0); | ||
} | ||
throw new _common.AccountsError(_context15.t0.message); | ||
case 20: | ||
case 'end': | ||
return _context15.stop(); | ||
} | ||
} | ||
}, _callee15, this, [[0, 14]]); | ||
})); | ||
function logout(_x13) { | ||
return _ref17.apply(this, arguments); | ||
} | ||
return logout; | ||
}() | ||
}, { | ||
key: 'verifyEmail', | ||
value: function () { | ||
var _ref19 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee16(token) { | ||
return _regenerator2.default.wrap(function _callee16$(_context16) { | ||
while (1) { | ||
switch (_context16.prev = _context16.next) { | ||
case 0: | ||
_context16.prev = 0; | ||
_context16.next = 3; | ||
return this.transport.verifyEmail(token); | ||
case 3: | ||
_context16.next = 8; | ||
break; | ||
case 5: | ||
_context16.prev = 5; | ||
_context16.t0 = _context16['catch'](0); | ||
throw new _common.AccountsError(_context16.t0.message); | ||
case 8: | ||
case 'end': | ||
return _context16.stop(); | ||
} | ||
} | ||
}, _callee16, this, [[0, 5]]); | ||
})); | ||
function verifyEmail(_x14) { | ||
return _ref19.apply(this, arguments); | ||
} | ||
return verifyEmail; | ||
}() | ||
}, { | ||
key: 'resetPassword', | ||
value: function () { | ||
var _ref20 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee17(token, newPassword) { | ||
var hashAlgorithm, password; | ||
return _regenerator2.default.wrap(function _callee17$(_context17) { | ||
while (1) { | ||
switch (_context17.prev = _context17.next) { | ||
case 0: | ||
if (_common.validators.validatePassword(newPassword)) { | ||
_context17.next = 2; | ||
break; | ||
} | ||
throw new _common.AccountsError('Password is invalid!'); | ||
case 2: | ||
hashAlgorithm = this.options.passwordHashAlgorithm; | ||
password = hashAlgorithm ? (0, _encryption.hashPassword)(newPassword, hashAlgorithm) : newPassword; | ||
_context17.prev = 4; | ||
_context17.next = 7; | ||
return this.transport.resetPassword(token, password); | ||
case 7: | ||
_context17.next = 12; | ||
break; | ||
case 9: | ||
_context17.prev = 9; | ||
_context17.t0 = _context17['catch'](4); | ||
throw new _common.AccountsError(_context17.t0.message); | ||
case 12: | ||
case 'end': | ||
return _context17.stop(); | ||
} | ||
} | ||
}, _callee17, this, [[4, 9]]); | ||
})); | ||
function resetPassword(_x15, _x16) { | ||
return _ref20.apply(this, arguments); | ||
} | ||
return resetPassword; | ||
}() | ||
}, { | ||
key: 'requestPasswordReset', | ||
value: function () { | ||
var _ref21 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee18(email) { | ||
return _regenerator2.default.wrap(function _callee18$(_context18) { | ||
while (1) { | ||
switch (_context18.prev = _context18.next) { | ||
case 0: | ||
if (_common.validators.validateEmail(email)) { | ||
_context18.next = 2; | ||
break; | ||
} | ||
throw new _common.AccountsError('Valid email must be provided'); | ||
case 2: | ||
_context18.prev = 2; | ||
_context18.next = 5; | ||
return this.transport.sendResetPasswordEmail(email); | ||
case 5: | ||
_context18.next = 10; | ||
break; | ||
case 7: | ||
_context18.prev = 7; | ||
_context18.t0 = _context18['catch'](2); | ||
throw new _common.AccountsError(_context18.t0.message); | ||
case 10: | ||
case 'end': | ||
return _context18.stop(); | ||
} | ||
} | ||
}, _callee18, this, [[2, 7]]); | ||
})); | ||
function requestPasswordReset(_x17) { | ||
return _ref21.apply(this, arguments); | ||
} | ||
return requestPasswordReset; | ||
}() | ||
}, { | ||
key: 'requestVerificationEmail', | ||
value: function () { | ||
var _ref22 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee19(email) { | ||
return _regenerator2.default.wrap(function _callee19$(_context19) { | ||
while (1) { | ||
switch (_context19.prev = _context19.next) { | ||
case 0: | ||
if (_common.validators.validateEmail(email)) { | ||
_context19.next = 2; | ||
break; | ||
} | ||
throw new _common.AccountsError('Valid email must be provided'); | ||
case 2: | ||
_context19.prev = 2; | ||
_context19.next = 5; | ||
return this.transport.sendVerificationEmail(email); | ||
case 5: | ||
_context19.next = 10; | ||
break; | ||
case 7: | ||
_context19.prev = 7; | ||
_context19.t0 = _context19['catch'](2); | ||
throw new _common.AccountsError(_context19.t0.message); | ||
case 10: | ||
case 'end': | ||
return _context19.stop(); | ||
} | ||
} | ||
}, _callee19, this, [[2, 7]]); | ||
})); | ||
function requestVerificationEmail(_x18) { | ||
return _ref22.apply(this, arguments); | ||
} | ||
return requestVerificationEmail; | ||
}() | ||
}]); | ||
return AccountsClient; | ||
}(); | ||
var Accounts = { | ||
instance: AccountsClient, | ||
ui: {}, | ||
config: function config(options, transport) { | ||
var _this = this; | ||
return (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee20() { | ||
return _regenerator2.default.wrap(function _callee20$(_context20) { | ||
while (1) { | ||
switch (_context20.prev = _context20.next) { | ||
case 0: | ||
_this.instance = new AccountsClient((0, _extends3.default)({}, _config3.default, options), transport); | ||
_context20.next = 3; | ||
return _this.instance.loadTokensFromStorage(); | ||
case 3: | ||
_context20.next = 5; | ||
return _this.instance.loadOriginalTokensFromStorage(); | ||
case 5: | ||
return _context20.abrupt('return', _this.instance); | ||
case 6: | ||
case 'end': | ||
return _context20.stop(); | ||
} | ||
} | ||
}, _callee20, _this); | ||
}))(); | ||
}, | ||
user: function user() { | ||
return this.instance.user(); | ||
}, | ||
options: function options() { | ||
return this.instance.options; | ||
}, | ||
createUser: function createUser(user, callback) { | ||
return this.instance.createUser(user, callback); | ||
}, | ||
loginWithPassword: function loginWithPassword(user, password, callback) { | ||
return this.instance.loginWithPassword(user, password, callback); | ||
}, | ||
loggingIn: function loggingIn() { | ||
return this.instance.loggingIn(); | ||
}, | ||
isLoading: function isLoading() { | ||
return this.instance.isLoading(); | ||
}, | ||
logout: function logout(callback) { | ||
return this.instance.logout(callback); | ||
}, | ||
tokens: function tokens() { | ||
return this.instance.tokens(); | ||
}, | ||
resumeSession: function resumeSession() { | ||
return this.instance.resumeSession(); | ||
}, | ||
refreshSession: function refreshSession() { | ||
return this.instance.refreshSession(); | ||
}, | ||
verifyEmail: function verifyEmail(token) { | ||
return this.instance.verifyEmail(token); | ||
}, | ||
resetPassword: function resetPassword(token, newPassword) { | ||
return this.instance.resetPassword(token, newPassword); | ||
}, | ||
requestPasswordReset: function requestPasswordReset(email) { | ||
return this.instance.requestPasswordReset(email); | ||
}, | ||
requestVerificationEmail: function requestVerificationEmail(email) { | ||
return this.instance.requestVerificationEmail(email); | ||
}, | ||
impersonate: function impersonate(username) { | ||
return this.instance.impersonate(username); | ||
}, | ||
stopImpersonation: function stopImpersonation() { | ||
return this.instance.stopImpersonation(); | ||
}, | ||
isImpersonated: function isImpersonated() { | ||
return this.instance.isImpersonated(); | ||
}, | ||
originalTokens: function originalTokens() { | ||
return this.instance.originalTokens(); | ||
} | ||
}; | ||
exports.default = Accounts; | ||
// TODO Could this be handled better? | ||
// if (typeof window !== 'undefined') { | ||
// window.onload = async () => { | ||
// if (Accounts.instance && Accounts.instance.resumeSession) { | ||
// await Accounts.resumeSession(); | ||
// } | ||
// }; | ||
// } | ||
/***/ }), | ||
/* 2 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("babel-runtime/helpers/extends"); | ||
/***/ }), | ||
/* 3 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("babel-runtime/regenerator"); | ||
/***/ }), | ||
/* 4 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("babel-runtime/core-js/promise"); | ||
/***/ }), | ||
/* 5 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("babel-runtime/helpers/asyncToGenerator"); | ||
/***/ }), | ||
/* 6 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("babel-runtime/helpers/defineProperty"); | ||
/***/ }), | ||
/* 7 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("babel-runtime/helpers/classCallCheck"); | ||
/***/ }), | ||
/* 8 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("babel-runtime/helpers/createClass"); | ||
/***/ }), | ||
/* 9 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("lodash"); | ||
/***/ }), | ||
/* 10 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("jwt-decode"); | ||
/***/ }), | ||
/* 11 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("@accounts/common"); | ||
/***/ }), | ||
/* 12 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _extends2 = __webpack_require__(2); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _common = __webpack_require__(11); | ||
var _AccountsClient = __webpack_require__(1); | ||
var _AccountsClient2 = _interopRequireDefault(_AccountsClient); | ||
var _redirect = __webpack_require__(13); | ||
var _redirect2 = _interopRequireDefault(_redirect); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = (0, _extends3.default)({}, _common.config, { | ||
store: null, | ||
reduxLogger: null, | ||
reduxStoreKey: 'accounts', | ||
tokenStorage: global.localStorage, | ||
server: '', | ||
tokenStoragePrefix: '', | ||
title: '', | ||
requestPermissions: [], | ||
requestOfflineToken: {}, | ||
forceApprovalPrompt: {}, | ||
requireEmailVerification: false, | ||
loginPath: '/', | ||
signUpPath: null, | ||
resetPasswordPath: null, | ||
profilePath: '/', | ||
changePasswordPath: null, | ||
homePath: '/', | ||
signOutPath: '/', | ||
// TODO enable all of these | ||
// onSubmitHook: () => {}, | ||
// onPreSignUpHook: () => new Promise(resolve => resolve()), | ||
// onPostSignUpHook: () => {}, | ||
onEnrollAccountHook: function onEnrollAccountHook() { | ||
return (0, _redirect2.default)(_AccountsClient2.default.options().loginPath || '/'); | ||
}, | ||
onResetPasswordHook: function onResetPasswordHook() { | ||
return (0, _redirect2.default)(_AccountsClient2.default.options().loginPath || '/'); | ||
}, | ||
onVerifyEmailHook: function onVerifyEmailHook() { | ||
return (0, _redirect2.default)(_AccountsClient2.default.options().profilePath || '/'); | ||
}, | ||
onSignedInHook: function onSignedInHook() { | ||
return (0, _redirect2.default)(_AccountsClient2.default.options().homePath || '/'); | ||
}, | ||
onSignedOutHook: function onSignedOutHook() { | ||
return (0, _redirect2.default)(_AccountsClient2.default.options().signOutPath || '/'); | ||
}, | ||
loginOnSignUp: true, | ||
persistImpersonation: true | ||
}); | ||
/***/ }), | ||
/* 13 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _AccountsClient = __webpack_require__(1); | ||
var _AccountsClient2 = _interopRequireDefault(_AccountsClient); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
// $FlowFixMe | ||
exports.default = function (path) { | ||
return _AccountsClient2.default.options().history.push(path); | ||
}; | ||
// eslint-disable-next-line import/no-named-as-default | ||
/***/ }), | ||
/* 14 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _toConsumableArray2 = __webpack_require__(15); | ||
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); | ||
var _redux = __webpack_require__(16); | ||
var _immutable = __webpack_require__(17); | ||
var _reduxImmutable = __webpack_require__(18); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = function (_ref) { | ||
var _ref$reducers = _ref.reducers, | ||
reducers = _ref$reducers === undefined ? {} : _ref$reducers, | ||
_ref$middleware = _ref.middleware, | ||
middleware = _ref$middleware === undefined ? [] : _ref$middleware, | ||
_ref$state = _ref.state, | ||
state = _ref$state === undefined ? (0, _immutable.Map)() : _ref$state; | ||
return (0, _redux.createStore)((0, _reduxImmutable.combineReducers)(reducers), state, (0, _redux.compose)(_redux.applyMiddleware.apply(undefined, (0, _toConsumableArray3.default)(middleware)))); | ||
}; | ||
/***/ }), | ||
/* 15 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("babel-runtime/helpers/toConsumableArray"); | ||
/***/ }), | ||
/* 16 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("redux"); | ||
/***/ }), | ||
/* 17 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("immutable"); | ||
/***/ }), | ||
/* 18 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("redux-immutable"); | ||
/***/ }), | ||
/* 19 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.setImpersonated = exports.clearOriginalTokens = exports.setOriginalTokens = exports.clearUser = exports.clearTokens = exports.setTokens = exports.setUser = exports.loggingIn = undefined; | ||
var _immutable = __webpack_require__(17); | ||
var PATH = 'js-accounts/'; | ||
var LOGIN = PATH + 'LOGIN'; | ||
var SET_USER = PATH + 'SET_USER'; | ||
var SET_TOKENS = PATH + 'SET_TOKENS'; | ||
var CLEAR_TOKENS = PATH + 'CLEAR_TOKENS'; | ||
var CLEAR_USER = PATH + 'CLEAR_USER'; | ||
var LOGGING_IN = PATH + 'LOGGING_IN'; | ||
var SET_ORIGINAL_TOKENS = PATH + 'SET_ORIGINAL_TOKENS'; | ||
var CLEAR_ORIGINAL_TOKENS = PATH + 'CLEAR_ORIGINAL_TOKENS'; | ||
var SET_IMPERSONATED = PATH + 'SET_IMPERSONATED'; | ||
var initialState = (0, _immutable.Map)({ | ||
isLoading: false, | ||
user: null, | ||
tokens: null, | ||
loggingIn: false, | ||
originalTokens: null, | ||
isImpersonated: false | ||
}); | ||
var reducer = function reducer() { | ||
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState; | ||
var action = arguments[1]; | ||
var nextState = state; | ||
switch (action.type) { | ||
case LOGIN: | ||
{ | ||
break; | ||
} | ||
case SET_USER: | ||
{ | ||
var user = action.payload.user; | ||
return state.set('user', (0, _immutable.Map)(user)); | ||
} | ||
case SET_TOKENS: | ||
{ | ||
var tokens = action.payload.tokens; | ||
return state.set('tokens', (0, _immutable.Map)(tokens)); | ||
} | ||
case CLEAR_TOKENS: | ||
{ | ||
state.set('originalTokens', null); | ||
return state.set('tokens', null); | ||
} | ||
case CLEAR_USER: | ||
{ | ||
return state.set('user', null); | ||
} | ||
case LOGGING_IN: | ||
{ | ||
var isLoggingIn = action.payload.isLoggingIn; | ||
return state.set('loggingIn', isLoggingIn); | ||
} | ||
case SET_ORIGINAL_TOKENS: | ||
{ | ||
var _tokens = action.payload.tokens; | ||
return state.set('originalTokens', (0, _immutable.Map)(_tokens)); | ||
} | ||
case CLEAR_ORIGINAL_TOKENS: | ||
{ | ||
return state.set('originalTokens', null); | ||
} | ||
case SET_IMPERSONATED: | ||
{ | ||
var isImpersonated = action.payload.isImpersonated; | ||
return state.set('isImpersonated', isImpersonated); | ||
} | ||
default: | ||
break; | ||
} | ||
return nextState; | ||
}; | ||
exports.default = reducer; | ||
var loggingIn = exports.loggingIn = function loggingIn(isLoggingIn) { | ||
return { | ||
type: LOGGING_IN, | ||
payload: { | ||
isLoggingIn: isLoggingIn | ||
} | ||
}; | ||
}; | ||
var setUser = exports.setUser = function setUser(user) { | ||
return { | ||
type: SET_USER, | ||
payload: { | ||
user: user | ||
} | ||
}; | ||
}; | ||
var setTokens = exports.setTokens = function setTokens(tokens) { | ||
return { | ||
type: SET_TOKENS, | ||
payload: { | ||
tokens: tokens | ||
} | ||
}; | ||
}; | ||
var clearTokens = exports.clearTokens = function clearTokens() { | ||
return { | ||
type: CLEAR_TOKENS | ||
}; | ||
}; | ||
var clearUser = exports.clearUser = function clearUser() { | ||
return { | ||
type: CLEAR_USER | ||
}; | ||
}; | ||
var setOriginalTokens = exports.setOriginalTokens = function setOriginalTokens(tokens) { | ||
return { | ||
type: SET_ORIGINAL_TOKENS, | ||
payload: { | ||
tokens: tokens | ||
} | ||
}; | ||
}; | ||
var clearOriginalTokens = exports.clearOriginalTokens = function clearOriginalTokens() { | ||
return { | ||
type: CLEAR_ORIGINAL_TOKENS | ||
}; | ||
}; | ||
var setImpersonated = exports.setImpersonated = function setImpersonated(isImpersonated) { | ||
return { | ||
type: SET_IMPERSONATED, | ||
payload: { | ||
isImpersonated: isImpersonated | ||
} | ||
}; | ||
}; | ||
/***/ }), | ||
/* 20 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.hashPassword = undefined; | ||
var _isString = __webpack_require__(21); | ||
var _isString2 = _interopRequireDefault(_isString); | ||
var _cryptoJs = __webpack_require__(22); | ||
var _cryptoJs2 = _interopRequireDefault(_cryptoJs); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var mapHashConstant = { | ||
sha: 'SHA', | ||
sha1: 'SHA1', | ||
sha224: 'SHA224', | ||
sha256: 'SHA256', | ||
sha384: 'SHA384', | ||
sha512: 'SHA512', | ||
md5: 'MD5', | ||
ripemd160: 'RIPEMD160' | ||
}; | ||
var hashPassword = exports.hashPassword = function hashPassword(password, algorithm) { | ||
if ((0, _isString2.default)(password)) { | ||
var cryptoAlgoKey = mapHashConstant[algorithm]; | ||
var cryptoFunction = _cryptoJs2.default[cryptoAlgoKey]; | ||
return { | ||
digest: cryptoFunction(password).toString(), | ||
algorithm: algorithm | ||
}; | ||
} | ||
// Prehashed password object | ||
return password; | ||
}; | ||
/***/ }), | ||
/* 21 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("lodash/isString"); | ||
/***/ }), | ||
/* 22 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("crypto-js"); | ||
/***/ }) | ||
/******/ ]) | ||
}); | ||
; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var accounts_client_1 = require("./accounts-client"); | ||
exports.AccountsClient = accounts_client_1.AccountsClient; | ||
var config_1 = require("./config"); | ||
exports.config = config_1.default; | ||
var module_1 = require("./module"); | ||
exports.reducer = module_1.default; | ||
exports.default = accounts_client_1.default; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@accounts/client", | ||
"version": "0.0.19", | ||
"version": "0.1.0-alpha.357173dd", | ||
"description": "Fullstack authentication and accounts-management", | ||
"main": "lib/index.js", | ||
"jsnext:main": "lib-es6/index.js", | ||
"typings": "lib/index.d.ts", | ||
"publishConfig": { | ||
@@ -12,8 +12,5 @@ "access": "public" | ||
"start": "webpack -p --config --progress --watch", | ||
"clean": "rimraf lib lib-es6", | ||
"clean": "rimraf lib", | ||
"precompile": "npm run clean", | ||
"compile": "npm run compile:es6 && npm run compile:umd", | ||
"compile:es6": "babel ./src --out-dir ./lib-es6", | ||
"compile:umd": "webpack", | ||
"postcompile": "npm run flow:prepublish", | ||
"compile": "tsc", | ||
"prepublish": "npm run compile", | ||
@@ -23,7 +20,2 @@ "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": "npm run flow:cplib && npm run flow:cplibes6", | ||
"flow:cplib": "for i in `ls ./src/*.js`; do cp $i `echo $i | sed \"s/src/lib/g\" | sed \"s/js/js\\.flow/g\"`; done", | ||
"flow:cplibes6": "for i in `ls ./src/*.js`; do cp $i `echo $i | sed \"s/src/lib-es6/g\" | sed \"s/js/js\\.flow/g\"`; done", | ||
"coverage": "npm run testonly -- --coverage", | ||
@@ -33,7 +25,12 @@ "coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage" | ||
"jest": { | ||
"testEnvironment": "node", | ||
"testRegex": "(/.*.(test|spec)).(js|jsx)$", | ||
"testPathDirs": [ | ||
"src" | ||
] | ||
"transform": { | ||
".(ts|tsx)": "<rootDir>/../../node_modules/ts-jest/preprocessor.js" | ||
}, | ||
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx)$", | ||
"moduleFileExtensions": [ | ||
"ts", | ||
"js" | ||
], | ||
"testEnvironment": "jsdom", | ||
"mapCoverage": true | ||
}, | ||
@@ -57,26 +54,14 @@ "repository": { | ||
"devDependencies": { | ||
"babel-cli": "^6.18.0", | ||
"babel-core": "^6.18.0", | ||
"babel-loader": "^6.2.7", | ||
"babel-plugin-syntax-async-functions": "^6.13.0", | ||
"babel-plugin-transform-async-to-generator": "^6.16.0", | ||
"babel-plugin-transform-flow-strip-types": "^6.21.0", | ||
"babel-plugin-transform-object-rest-spread": "^6.16.0", | ||
"babel-plugin-transform-regenerator": "^6.16.1", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-preset-es2015": "^6.18.0", | ||
"babel-preset-es2015-node4": "^2.1.0", | ||
"babel-preset-stage-0": "^6.22.0", | ||
"@types/jest": "^20.0.2", | ||
"coveralls": "^2.11.14", | ||
"flow-bin": "0.41.0", | ||
"jest": "^18.0.0", | ||
"jest": "^20.0.4", | ||
"jsonwebtoken": "^7.4.1", | ||
"lerna": "2.0.0-beta.32", | ||
"localstorage-polyfill": "^1.0.1", | ||
"regenerator-runtime": "^0.9.6", | ||
"rimraf": "^2.6.1", | ||
"webpack": "^1.13.3", | ||
"webpack-node-externals": "^1.5.4" | ||
"rimraf": "^2.6.1" | ||
}, | ||
"dependencies": { | ||
"@accounts/common": "^0.0.18", | ||
"@accounts/common": "^0.1.0-alpha.357173dd", | ||
"crypto-js": "^3.1.9-1", | ||
@@ -83,0 +68,0 @@ "immutable": "^3.8.1", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
9
72383
28
1151
1
+ Added@accounts/common@0.1.0-beta.14(transitive)
- Removed@accounts/common@0.0.18(transitive)