veritone-redux-common
Advanced tools
Comparing version 3.1.0 to 3.2.0
@@ -48,2 +48,5 @@ # veritone-redux-common changelog | ||
* Implement the oauth implicit grant flow | ||
* remove `credentials: include` on user.fetchEnabledApps, which does not work cross-domain. | ||
* remove `credentials: include` on user.fetchEnabledApps, which does not work cross-domain. | ||
## 3.2.0 | ||
* The CJS bundle is now transpiled to >0.5% in babel-preset-env (compared to >5% previously), for wider compatibility with old browsers and tools. |
@@ -23,2 +23,45 @@ 'use strict'; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
var defineProperty = function (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; | ||
}; | ||
var _extends = Object.assign || function (target) { | ||
@@ -38,4 +81,43 @@ for (var i = 1; i < arguments.length; i++) { | ||
var inherits = function (subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; | ||
}; | ||
var possibleConstructorReturn = function (self, call) { | ||
if (!self) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return call && (typeof call === "object" || typeof call === "function") ? call : self; | ||
}; | ||
function createReducer(initialState, handlers) { | ||
return function reducer(state = initialState, action) { | ||
return function reducer() { | ||
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState; | ||
var action = arguments[1]; | ||
if (handlers.hasOwnProperty(action.type)) { | ||
@@ -49,6 +131,10 @@ return handlers[action.type](state, action); | ||
function reduceReducers(...reducers) { | ||
return (state, action) => { | ||
let isInitial = !state; | ||
return reducers.reduce((newState, reducer) => { | ||
function reduceReducers() { | ||
for (var _len = arguments.length, reducers = Array(_len), _key = 0; _key < _len; _key++) { | ||
reducers[_key] = arguments[_key]; | ||
} | ||
return function (state, action) { | ||
var isInitial = !state; | ||
return reducers.reduce(function (newState, reducer) { | ||
if (isInitial) { | ||
@@ -63,3 +149,3 @@ return _extends({}, newState, reducer(undefined, action)); | ||
const fetchingStatus = { | ||
var fetchingStatus = { | ||
fetching: 'FETCHING', | ||
@@ -79,27 +165,23 @@ failure: 'FAILURE', | ||
var _createReducer; | ||
// reducer supporting shared-components/withUIState decorator | ||
// import { } from 'lodash'; | ||
const namespace = 'ui-state'; | ||
var namespace = 'ui-state'; | ||
const SET_STATE = 'vtn/ui-state/SET_STATE'; | ||
const CLEAR_STATE = 'vtn/ui-state/CLEAR_STATE'; | ||
var SET_STATE = 'vtn/ui-state/SET_STATE'; | ||
var CLEAR_STATE = 'vtn/ui-state/CLEAR_STATE'; | ||
const defaultState = {}; | ||
var defaultState = {}; | ||
const reducer = createReducer(defaultState, { | ||
[SET_STATE](state, action) { | ||
return _extends({}, state, { | ||
[action.meta.key]: _extends({}, state[action.meta.key], action.payload) | ||
}); | ||
}, | ||
var reducer = createReducer(defaultState, (_createReducer = {}, defineProperty(_createReducer, SET_STATE, function (state, action) { | ||
return _extends({}, state, defineProperty({}, action.meta.key, _extends({}, state[action.meta.key], action.payload))); | ||
}), defineProperty(_createReducer, CLEAR_STATE, function (state, action) { | ||
var newState = _extends({}, state); | ||
delete newState[action.meta.key]; | ||
[CLEAR_STATE](state, action) { | ||
let newState = _extends({}, state); | ||
delete newState[action.meta.key]; | ||
return newState; | ||
}), _createReducer)); | ||
return newState; | ||
} | ||
}); | ||
function local(state) { | ||
@@ -113,3 +195,3 @@ return state[namespace]; | ||
meta: { | ||
key | ||
key: key | ||
}, | ||
@@ -128,3 +210,3 @@ payload: _extends({}, mergeState) | ||
meta: { | ||
key | ||
key: key | ||
} | ||
@@ -146,21 +228,21 @@ }; | ||
const FETCH_USER = 'vtn/user/FETCH_USER'; | ||
const FETCH_USER_SUCCESS = 'vtn/user/FETCH_USER_SUCCESS'; | ||
const FETCH_USER_FAILURE = 'vtn/user/FETCH_USER_FAILURE'; | ||
var FETCH_USER = 'vtn/user/FETCH_USER'; | ||
var FETCH_USER_SUCCESS = 'vtn/user/FETCH_USER_SUCCESS'; | ||
var FETCH_USER_FAILURE = 'vtn/user/FETCH_USER_FAILURE'; | ||
const LOGIN = 'vtn/user/LOGIN'; | ||
const LOGIN_SUCCESS = 'vtn/user/LOGIN_SUCCESS'; | ||
const LOGIN_FAILURE = 'vtn/user/LOGIN_FAILURE'; | ||
var LOGIN = 'vtn/user/LOGIN'; | ||
var LOGIN_SUCCESS = 'vtn/user/LOGIN_SUCCESS'; | ||
var LOGIN_FAILURE = 'vtn/user/LOGIN_FAILURE'; | ||
const LOGOUT = 'vtn/user/LOGOUT'; | ||
const LOGOUT_SUCCESS = 'vtn/user/LOGOUT_SUCCESS'; | ||
const LOGOUT_FAILURE = 'vtn/user/LOGOUT_FAILURE'; | ||
var LOGOUT = 'vtn/user/LOGOUT'; | ||
var LOGOUT_SUCCESS = 'vtn/user/LOGOUT_SUCCESS'; | ||
var LOGOUT_FAILURE = 'vtn/user/LOGOUT_FAILURE'; | ||
const REFRESH_TOKEN = 'vtn/user/REFRESH_TOKEN'; | ||
const REFRESH_TOKEN_SUCCESS = 'vtn/user/REFRESH_TOKEN_SUCCESS'; | ||
const REFRESH_TOKEN_FAILURE = 'vtn/user/REFRESH_TOKEN_FAILURE'; | ||
var REFRESH_TOKEN = 'vtn/user/REFRESH_TOKEN'; | ||
var REFRESH_TOKEN_SUCCESS = 'vtn/user/REFRESH_TOKEN_SUCCESS'; | ||
var REFRESH_TOKEN_FAILURE = 'vtn/user/REFRESH_TOKEN_FAILURE'; | ||
const FETCH_USER_APPLICATIONS = 'vtn/user/FETCH_USER_APPLICATIONS'; | ||
const FETCH_USER_APPLICATIONS_SUCCESS = 'vtn/user/FETCH_USER_APPLICATIONS_SUCCESS'; | ||
const FETCH_USER_APPLICATIONS_FAILURE = 'vtn/user/FETCH_USER_APPLICATIONS_FAILURE'; | ||
var FETCH_USER_APPLICATIONS = 'vtn/user/FETCH_USER_APPLICATIONS'; | ||
var FETCH_USER_APPLICATIONS_SUCCESS = 'vtn/user/FETCH_USER_APPLICATIONS_SUCCESS'; | ||
var FETCH_USER_APPLICATIONS_FAILURE = 'vtn/user/FETCH_USER_APPLICATIONS_FAILURE'; | ||
@@ -185,8 +267,8 @@ var userConstants = Object.freeze({ | ||
const REQUEST_OAUTH_GRANT = 'REQUEST_OAUTH_GRANT'; | ||
const REQUEST_OAUTH_GRANT_IMPLICIT = 'REQUEST_OAUTH_GRANT_IMPLICIT'; | ||
const OAUTH_GRANT_FLOW_FAILED = 'OAUTH_GRANT_FLOW_FAILED'; | ||
const OAUTH_GRANT_FLOW_SUCCESS = 'OAUTH_GRANT_FLOW_SUCCESS'; | ||
const SET_SESSION_TOKEN = 'vtn/user/SET_SESSION_TOKEN'; | ||
const SET_OAUTH_TOKEN = 'vtn/user/SET_OAUTH_TOKEN'; | ||
var REQUEST_OAUTH_GRANT = 'REQUEST_OAUTH_GRANT'; | ||
var REQUEST_OAUTH_GRANT_IMPLICIT = 'REQUEST_OAUTH_GRANT_IMPLICIT'; | ||
var OAUTH_GRANT_FLOW_FAILED = 'OAUTH_GRANT_FLOW_FAILED'; | ||
var OAUTH_GRANT_FLOW_SUCCESS = 'OAUTH_GRANT_FLOW_SUCCESS'; | ||
var SET_SESSION_TOKEN = 'vtn/user/SET_SESSION_TOKEN'; | ||
var SET_OAUTH_TOKEN = 'vtn/user/SET_OAUTH_TOKEN'; | ||
@@ -202,5 +284,7 @@ var authConstants = Object.freeze({ | ||
const namespace$1 = 'auth'; | ||
var _createReducer$1; | ||
const defaultState$1 = { | ||
var namespace$1 = 'auth'; | ||
var defaultState$1 = { | ||
OAuthToken: null, | ||
@@ -210,40 +294,34 @@ sessionToken: null | ||
const reducer$1 = createReducer(defaultState$1, { | ||
[OAUTH_GRANT_FLOW_SUCCESS](state, { payload: { OAuthToken } }) { | ||
return _extends({}, state, { | ||
OAuthToken | ||
}); | ||
}, | ||
var reducer$1 = createReducer(defaultState$1, (_createReducer$1 = {}, defineProperty(_createReducer$1, OAUTH_GRANT_FLOW_SUCCESS, function (state, _ref) { | ||
var OAuthToken = _ref.payload.OAuthToken; | ||
[LOGIN_SUCCESS](state, action) { | ||
return _extends({}, state, { | ||
sessionToken: action.payload.token | ||
}); | ||
}, | ||
return _extends({}, state, { | ||
OAuthToken: OAuthToken | ||
}); | ||
}), defineProperty(_createReducer$1, LOGIN_SUCCESS, function (state, action) { | ||
return _extends({}, state, { | ||
sessionToken: action.payload.token | ||
}); | ||
}), defineProperty(_createReducer$1, FETCH_USER_SUCCESS, function (state, action) { | ||
return _extends({}, state, { | ||
sessionToken: action.payload.token | ||
}); | ||
}), defineProperty(_createReducer$1, REFRESH_TOKEN_SUCCESS, function (state, action) { | ||
return _extends({}, state, { | ||
sessionToken: action.payload.token | ||
}); | ||
}), defineProperty(_createReducer$1, SET_SESSION_TOKEN, function (state, _ref2) { | ||
var payload = _ref2.payload; | ||
[FETCH_USER_SUCCESS](state, action) { | ||
return _extends({}, state, { | ||
sessionToken: action.payload.token | ||
}); | ||
}, | ||
return _extends({}, state, { | ||
sessionToken: payload | ||
}); | ||
}), defineProperty(_createReducer$1, SET_OAUTH_TOKEN, function (state, _ref3) { | ||
var payload = _ref3.payload; | ||
[REFRESH_TOKEN_SUCCESS](state, action) { | ||
return _extends({}, state, { | ||
sessionToken: action.payload.token | ||
}); | ||
}, | ||
return _extends({}, state, { | ||
OAuthToken: payload | ||
}); | ||
}), _createReducer$1)); | ||
[SET_SESSION_TOKEN](state, { payload }) { | ||
return _extends({}, state, { | ||
sessionToken: payload | ||
}); | ||
}, | ||
[SET_OAUTH_TOKEN](state, { payload }) { | ||
return _extends({}, state, { | ||
OAuthToken: payload | ||
}); | ||
} | ||
}); | ||
function local$1(state) { | ||
@@ -272,28 +350,34 @@ return state[namespace$1]; | ||
function requestOAuthGrant({ OAuthURI, onSuccess, onFailure }) { | ||
function requestOAuthGrant(_ref4) { | ||
var OAuthURI = _ref4.OAuthURI, | ||
onSuccess = _ref4.onSuccess, | ||
onFailure = _ref4.onFailure; | ||
return { | ||
type: REQUEST_OAUTH_GRANT, | ||
payload: { OAuthURI, onSuccess, onFailure } | ||
payload: { OAuthURI: OAuthURI, onSuccess: onSuccess, onFailure: onFailure } | ||
}; | ||
} | ||
function requestOAuthGrantImplicit({ | ||
OAuthURI, | ||
responseType = 'token', | ||
scope = 'all', | ||
clientId, | ||
redirectUri, | ||
onSuccess, | ||
onFailure | ||
}) { | ||
function requestOAuthGrantImplicit(_ref5) { | ||
var OAuthURI = _ref5.OAuthURI, | ||
_ref5$responseType = _ref5.responseType, | ||
responseType = _ref5$responseType === undefined ? 'token' : _ref5$responseType, | ||
_ref5$scope = _ref5.scope, | ||
scope = _ref5$scope === undefined ? 'all' : _ref5$scope, | ||
clientId = _ref5.clientId, | ||
redirectUri = _ref5.redirectUri, | ||
onSuccess = _ref5.onSuccess, | ||
onFailure = _ref5.onFailure; | ||
return { | ||
type: REQUEST_OAUTH_GRANT_IMPLICIT, | ||
payload: { | ||
OAuthURI, | ||
responseType, | ||
scope, | ||
clientId, | ||
redirectUri, | ||
onSuccess, | ||
onFailure | ||
OAuthURI: OAuthURI, | ||
responseType: responseType, | ||
scope: scope, | ||
clientId: clientId, | ||
redirectUri: redirectUri, | ||
onSuccess: onSuccess, | ||
onFailure: onFailure | ||
} | ||
@@ -303,13 +387,17 @@ }; | ||
function OAuthGrantSuccess({ OAuthToken }) { | ||
function OAuthGrantSuccess(_ref6) { | ||
var OAuthToken = _ref6.OAuthToken; | ||
return { | ||
type: OAUTH_GRANT_FLOW_SUCCESS, | ||
payload: { OAuthToken } | ||
payload: { OAuthToken: OAuthToken } | ||
}; | ||
} | ||
function OAuthGrantFailure({ error }) { | ||
function OAuthGrantFailure(_ref7) { | ||
var error = _ref7.error; | ||
return { | ||
type: OAUTH_GRANT_FLOW_FAILED, | ||
payload: { error }, | ||
payload: { error: error }, | ||
error: true | ||
@@ -343,6 +431,6 @@ }; | ||
function commonHeaders(state) { | ||
const OAuthToken = selectOAuthToken(state); | ||
const sessionToken = selectSessionToken(state); | ||
var OAuthToken = selectOAuthToken(state); | ||
var sessionToken = selectSessionToken(state); | ||
let headers = { | ||
var headers = { | ||
Accept: 'application/json', | ||
@@ -353,3 +441,3 @@ 'Content-Type': 'application/json' | ||
if (OAuthToken || sessionToken) { | ||
headers.Authorization = `Bearer ${OAuthToken || sessionToken}`; | ||
headers.Authorization = 'Bearer ' + (OAuthToken || sessionToken); | ||
} | ||
@@ -360,11 +448,9 @@ | ||
const namespace$2 = 'config'; | ||
const SET_CONFIG = 'vtn/config/SET_CONFIG'; | ||
const defaultState$2 = {}; | ||
var namespace$2 = 'config'; | ||
var SET_CONFIG = 'vtn/config/SET_CONFIG'; | ||
var defaultState$2 = {}; | ||
const reducer$2 = createReducer(defaultState$2, { | ||
[SET_CONFIG](state, action) { | ||
return _extends({}, state, action.payload); | ||
} | ||
}); | ||
var reducer$2 = createReducer(defaultState$2, defineProperty({}, SET_CONFIG, function (state, action) { | ||
return _extends({}, state, action.payload); | ||
})); | ||
@@ -375,3 +461,5 @@ function local$2(state) { | ||
function setConfig(obj = {}) { | ||
function setConfig() { | ||
var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return { | ||
@@ -397,5 +485,7 @@ type: SET_CONFIG, | ||
const namespace$3 = 'user'; | ||
var _createReducer$2; | ||
const defaultState$3 = { | ||
var namespace$3 = 'user'; | ||
var defaultState$3 = { | ||
user: {}, | ||
@@ -416,107 +506,87 @@ | ||
const reducer$3 = createReducer(defaultState$3, { | ||
[FETCH_USER](state, action) { | ||
const requestSuccessState = _extends({}, state, { | ||
isFetching: true, | ||
fetchingFailed: false | ||
}); | ||
var reducer$3 = createReducer(defaultState$3, (_createReducer$2 = {}, defineProperty(_createReducer$2, FETCH_USER, function (state, action) { | ||
var requestSuccessState = _extends({}, state, { | ||
isFetching: true, | ||
fetchingFailed: false | ||
}); | ||
return action.error ? // handle requestError ie. offline | ||
this[FETCH_USER_FAILURE](state, action) : requestSuccessState; | ||
}, | ||
return action.error ? // handle requestError ie. offline | ||
this[FETCH_USER_FAILURE](state, action) : requestSuccessState; | ||
}), defineProperty(_createReducer$2, FETCH_USER_SUCCESS, function (state, action) { | ||
return _extends({}, state, { | ||
isFetching: false, | ||
fetchingFailed: false, | ||
user: action.payload | ||
}); | ||
}), defineProperty(_createReducer$2, FETCH_USER_FAILURE, function (state, action) { | ||
return _extends({}, state, { | ||
isFetching: false, | ||
fetchingFailed: true, | ||
user: {} | ||
}); | ||
}), defineProperty(_createReducer$2, LOGIN, function (state, action) { | ||
var requestSuccessState = _extends({}, state, { | ||
isLoggingIn: true, | ||
loginFailed: false, | ||
loginFailureMessage: null | ||
}); | ||
[FETCH_USER_SUCCESS](state, action) { | ||
return _extends({}, state, { | ||
isFetching: false, | ||
fetchingFailed: false, | ||
user: action.payload | ||
}); | ||
}, | ||
return action.error ? this[LOGIN_FAILURE](state, action) : requestSuccessState; | ||
}), defineProperty(_createReducer$2, LOGIN_SUCCESS, function (state, action) { | ||
return _extends({}, state, { | ||
isLoggingIn: false, | ||
loginFailed: false, | ||
user: action.payload, | ||
loginFailureMessage: null | ||
}); | ||
}), defineProperty(_createReducer$2, LOGIN_FAILURE, function (state, action) { | ||
var statusErrors = { | ||
404: "Couldn't login, please double check your username and password.", | ||
default: "Couldn't login, please try again." | ||
}; | ||
[FETCH_USER_FAILURE](state, action) { | ||
return _extends({}, state, { | ||
isFetching: false, | ||
fetchingFailed: true, | ||
user: {} | ||
}); | ||
}, | ||
var failureMessage = action.payload.name === 'ApiError' ? statusErrors[action.payload.status] || statusErrors.default : action.payload.name === 'RequestError' ? 'There was an error while logging in, please try again.' : statusErrors.default; | ||
[LOGIN](state, action) { | ||
const requestSuccessState = _extends({}, state, { | ||
isLoggingIn: true, | ||
loginFailed: false, | ||
loginFailureMessage: null | ||
}); | ||
return _extends({}, state, { | ||
isLoggingIn: false, | ||
loginFailed: true, | ||
loginFailureMessage: failureMessage, | ||
user: {} | ||
}); | ||
}), defineProperty(_createReducer$2, FETCH_USER_APPLICATIONS, function (state, action) { | ||
var requestSuccessState = _extends({}, state, { | ||
isFetchingApplications: true, | ||
fetchApplicationsFailed: false, | ||
fetchApplicationsFailureMessage: null, | ||
enabledApps: [] | ||
}); | ||
return action.error ? this[LOGIN_FAILURE](state, action) : requestSuccessState; | ||
}, | ||
return action.error ? this[FETCH_USER_APPLICATIONS_FAILURE](state, action) : requestSuccessState; | ||
}), defineProperty(_createReducer$2, FETCH_USER_APPLICATIONS_SUCCESS, function (state, action) { | ||
return _extends({}, state, { | ||
isFetchingApplications: false, | ||
fetchApplicationsFailed: false, | ||
enabledApps: action.payload.results, | ||
fetchApplicationsFailureMessage: null | ||
}); | ||
}), defineProperty(_createReducer$2, FETCH_USER_APPLICATIONS_FAILURE, function (state, action) { | ||
var statusErrors = { | ||
404: "Couldn't get application list.", | ||
default: "Couldn't get application list. Please login." | ||
}; | ||
[LOGIN_SUCCESS](state, action) { | ||
return _extends({}, state, { | ||
isLoggingIn: false, | ||
loginFailed: false, | ||
user: action.payload, | ||
loginFailureMessage: null | ||
}); | ||
}, | ||
var failureMessage = action.payload.name === 'ApiError' ? statusErrors[action.payload.status] || statusErrors.default : action.payload.name === 'RequestError' ? 'There was an error when fetching application list, please try again.' : statusErrors.default; | ||
[LOGIN_FAILURE](state, action) { | ||
const statusErrors = { | ||
404: "Couldn't login, please double check your username and password.", | ||
default: "Couldn't login, please try again." | ||
}; | ||
return _extends({}, state, { | ||
isFetchingApplications: false, | ||
fetchApplicationsFailed: true, | ||
fetchApplicationsFailureMessage: failureMessage, | ||
enabledApps: [] | ||
}); | ||
}), defineProperty(_createReducer$2, REFRESH_TOKEN_SUCCESS, function (state, action) { | ||
return _extends({}, state, { | ||
user: action.payload | ||
}); | ||
}), _createReducer$2)); | ||
const failureMessage = action.payload.name === 'ApiError' ? statusErrors[action.payload.status] || statusErrors.default : action.payload.name === 'RequestError' ? 'There was an error while logging in, please try again.' : statusErrors.default; | ||
return _extends({}, state, { | ||
isLoggingIn: false, | ||
loginFailed: true, | ||
loginFailureMessage: failureMessage, | ||
user: {} | ||
}); | ||
}, | ||
[FETCH_USER_APPLICATIONS](state, action) { | ||
const requestSuccessState = _extends({}, state, { | ||
isFetchingApplications: true, | ||
fetchApplicationsFailed: false, | ||
fetchApplicationsFailureMessage: null, | ||
enabledApps: [] | ||
}); | ||
return action.error ? this[FETCH_USER_APPLICATIONS_FAILURE](state, action) : requestSuccessState; | ||
}, | ||
[FETCH_USER_APPLICATIONS_SUCCESS](state, action) { | ||
return _extends({}, state, { | ||
isFetchingApplications: false, | ||
fetchApplicationsFailed: false, | ||
enabledApps: action.payload.results, | ||
fetchApplicationsFailureMessage: null | ||
}); | ||
}, | ||
[FETCH_USER_APPLICATIONS_FAILURE](state, action) { | ||
const statusErrors = { | ||
404: "Couldn't get application list.", | ||
default: "Couldn't get application list. Please login." | ||
}; | ||
const failureMessage = action.payload.name === 'ApiError' ? statusErrors[action.payload.status] || statusErrors.default : action.payload.name === 'RequestError' ? 'There was an error when fetching application list, please try again.' : statusErrors.default; | ||
return _extends({}, state, { | ||
isFetchingApplications: false, | ||
fetchApplicationsFailed: true, | ||
fetchApplicationsFailureMessage: failureMessage, | ||
enabledApps: [] | ||
}); | ||
}, | ||
[REFRESH_TOKEN_SUCCESS](state, action) { | ||
return _extends({}, state, { | ||
user: action.payload | ||
}); | ||
} | ||
}); | ||
function local$3(state) { | ||
@@ -527,66 +597,71 @@ return state[namespace$3]; | ||
function fetchUser() { | ||
return { | ||
[reduxApiMiddlewareFixed.CALL_API]: { | ||
types: [FETCH_USER, FETCH_USER_SUCCESS, FETCH_USER_FAILURE], | ||
endpoint: state => `${getConfig(state).apiRoot}/v1/admin/current-user`, | ||
method: 'GET', | ||
headers: commonHeaders | ||
} | ||
}; | ||
return defineProperty({}, reduxApiMiddlewareFixed.CALL_API, { | ||
types: [FETCH_USER, FETCH_USER_SUCCESS, FETCH_USER_FAILURE], | ||
endpoint: function endpoint(state) { | ||
return getConfig(state).apiRoot + '/v1/admin/current-user'; | ||
}, | ||
method: 'GET', | ||
headers: commonHeaders | ||
}); | ||
} | ||
function login({ userName, password }) { | ||
return { | ||
[reduxApiMiddlewareFixed.CALL_API]: { | ||
types: [LOGIN, LOGIN_SUCCESS, LOGIN_FAILURE], | ||
endpoint: state => `${getConfig(state).apiRoot}/v1/admin/login`, | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
userName, | ||
password | ||
}), | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json' | ||
}, | ||
credentials: 'include' | ||
} | ||
}; | ||
function login(_ref2) { | ||
var userName = _ref2.userName, | ||
password = _ref2.password; | ||
return defineProperty({}, reduxApiMiddlewareFixed.CALL_API, { | ||
types: [LOGIN, LOGIN_SUCCESS, LOGIN_FAILURE], | ||
endpoint: function endpoint(state) { | ||
return getConfig(state).apiRoot + '/v1/admin/login'; | ||
}, | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
userName: userName, | ||
password: password | ||
}), | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json' | ||
}, | ||
credentials: 'include' | ||
}); | ||
} | ||
function logout() { | ||
return { | ||
[reduxApiMiddlewareFixed.CALL_API]: { | ||
types: [LOGOUT, LOGOUT_SUCCESS, LOGOUT_FAILURE], | ||
endpoint: state => | ||
// prettier-ignore | ||
`${getConfig(state).apiRoot}/v1/admin/token/${selectSessionToken(state)}/logout`, | ||
method: 'GET', | ||
headers: commonHeaders | ||
} | ||
}; | ||
return defineProperty({}, reduxApiMiddlewareFixed.CALL_API, { | ||
types: [LOGOUT, LOGOUT_SUCCESS, LOGOUT_FAILURE], | ||
endpoint: function endpoint(state) { | ||
return ( | ||
// prettier-ignore | ||
getConfig(state).apiRoot + '/v1/admin/token/' + selectSessionToken(state) + '/logout' | ||
); | ||
}, | ||
method: 'GET', | ||
headers: commonHeaders | ||
}); | ||
} | ||
function refreshApiToken() { | ||
return { | ||
[reduxApiMiddlewareFixed.CALL_API]: { | ||
types: [REFRESH_TOKEN, REFRESH_TOKEN_SUCCESS, REFRESH_TOKEN_FAILURE], | ||
endpoint: state => | ||
// prettier-ignore | ||
`${getConfig(state).apiRoot}/v1/admin/token/${selectSessionToken(state)}/refresh`, | ||
method: 'GET', | ||
headers: commonHeaders | ||
} | ||
}; | ||
return defineProperty({}, reduxApiMiddlewareFixed.CALL_API, { | ||
types: [REFRESH_TOKEN, REFRESH_TOKEN_SUCCESS, REFRESH_TOKEN_FAILURE], | ||
endpoint: function endpoint(state) { | ||
return ( | ||
// prettier-ignore | ||
getConfig(state).apiRoot + '/v1/admin/token/' + selectSessionToken(state) + '/refresh' | ||
); | ||
}, | ||
method: 'GET', | ||
headers: commonHeaders | ||
}); | ||
} | ||
function fetchEnabledApps() { | ||
return { | ||
[reduxApiMiddlewareFixed.CALL_API]: { | ||
types: [FETCH_USER_APPLICATIONS, FETCH_USER_APPLICATIONS_SUCCESS, FETCH_USER_APPLICATIONS_FAILURE], | ||
endpoint: state => `${getConfig(state).apiRoot}/v1/admin/current-user/applications`, | ||
method: 'GET', | ||
headers: commonHeaders | ||
} | ||
}; | ||
return defineProperty({}, reduxApiMiddlewareFixed.CALL_API, { | ||
types: [FETCH_USER_APPLICATIONS, FETCH_USER_APPLICATIONS_SUCCESS, FETCH_USER_APPLICATIONS_FAILURE], | ||
endpoint: function endpoint(state) { | ||
return getConfig(state).apiRoot + '/v1/admin/current-user/applications'; | ||
}, | ||
method: 'GET', | ||
headers: commonHeaders | ||
}); | ||
} | ||
@@ -636,7 +711,7 @@ | ||
// fixme: how should migrations work without the cookie in external apps? | ||
const apps = local$3(state).enabledApps; | ||
var apps = local$3(state).enabledApps; | ||
// let migrated = cookie.get('veritone-migrated-to-discovery') === 'true'; | ||
return apps.map(app => { | ||
const migrations = { | ||
return apps.map(function (app) { | ||
var migrations = { | ||
// advertiser: migrated ? 'Discovery' : 'Advertiser', | ||
@@ -649,3 +724,3 @@ // broadcaster: migrated ? 'Discovery' : 'Media' | ||
}); | ||
}).filter(app => { | ||
}).filter(function (app) { | ||
if (app.applicationCheckPermissions === false) { | ||
@@ -655,3 +730,3 @@ return true; | ||
const appAccessPermissionId = _get(veritoneFunctionalPermissions.permissions, [app.applicationKey, 'access']); | ||
var appAccessPermissionId = _get(veritoneFunctionalPermissions.permissions, [app.applicationKey, 'access']); | ||
@@ -690,83 +765,196 @@ return appAccessPermissionId && veritoneFunctionalPermissions.util.hasAccessTo(appAccessPermissionId, selectUser(state).permissionMasks); | ||
function* requestOAuthGrant$1({ | ||
payload: { OAuthURI, onSuccess = _noop, onFailure = _noop } | ||
}) { | ||
let token; | ||
var _marked = /*#__PURE__*/regeneratorRuntime.mark(requestOAuthGrant$1); | ||
var _marked2 = /*#__PURE__*/regeneratorRuntime.mark(requestOAuthGrantImplicit$1); | ||
var _marked3 = /*#__PURE__*/regeneratorRuntime.mark(watchOAuthGrantRequest); | ||
var _marked4 = /*#__PURE__*/regeneratorRuntime.mark(root); | ||
try { | ||
let { OAuthToken } = yield effects.call(veritoneOauthHelpers.login, OAuthURI); | ||
token = OAuthToken; | ||
} catch (e) { | ||
console.log('oauth flow error', e); | ||
yield effects.put(OAuthGrantFailure(e)); | ||
yield effects.call(onFailure, e); | ||
return; | ||
} | ||
function requestOAuthGrant$1(_ref) { | ||
var _ref$payload = _ref.payload, | ||
OAuthURI = _ref$payload.OAuthURI, | ||
_ref$payload$onSucces = _ref$payload.onSuccess, | ||
onSuccess = _ref$payload$onSucces === undefined ? _noop : _ref$payload$onSucces, | ||
_ref$payload$onFailur = _ref$payload.onFailure, | ||
onFailure = _ref$payload$onFailur === undefined ? _noop : _ref$payload$onFailur; | ||
yield effects.put(OAuthGrantSuccess({ OAuthToken: token })); | ||
yield effects.call(onSuccess, { OAuthToken: token }); | ||
} | ||
var token, _ref2, OAuthToken; | ||
function* requestOAuthGrantImplicit$1({ | ||
payload: { | ||
OAuthURI, | ||
responseType, | ||
clientId, | ||
redirectUri, | ||
scope, | ||
onSuccess = _noop, | ||
onFailure = _noop | ||
} | ||
}) { | ||
const authWindow = yield effects.call(window.open, `${OAuthURI}?response_type=${responseType}&client_id=${clientId}&redirect_uri=${redirectUri}&scope=${scope}`, '_auth', 'width=550px,height=650px'); | ||
return regeneratorRuntime.wrap(function requestOAuthGrant$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
token = void 0; | ||
_context.prev = 1; | ||
_context.next = 4; | ||
return effects.call(veritoneOauthHelpers.login, OAuthURI); | ||
const windowEventChannel = reduxSaga.eventChannel(emitter => { | ||
function handleEvent(e) { | ||
if (e.data.OAuthToken || e.data.error) { | ||
emitter({ OAuthToken: e.data.OAuthToken, error: e.data.error }); | ||
emitter(reduxSaga.END); | ||
case 4: | ||
_ref2 = _context.sent; | ||
OAuthToken = _ref2.OAuthToken; | ||
token = OAuthToken; | ||
_context.next = 17; | ||
break; | ||
case 9: | ||
_context.prev = 9; | ||
_context.t0 = _context['catch'](1); | ||
console.log('oauth flow error', _context.t0); | ||
_context.next = 14; | ||
return effects.put(OAuthGrantFailure(_context.t0)); | ||
case 14: | ||
_context.next = 16; | ||
return effects.call(onFailure, _context.t0); | ||
case 16: | ||
return _context.abrupt('return'); | ||
case 17: | ||
_context.next = 19; | ||
return effects.put(OAuthGrantSuccess({ OAuthToken: token })); | ||
case 19: | ||
_context.next = 21; | ||
return effects.call(onSuccess, { OAuthToken: token }); | ||
case 21: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _marked, this, [[1, 9]]); | ||
} | ||
window.addEventListener('message', handleEvent, false); | ||
function requestOAuthGrantImplicit$1(_ref3) { | ||
var _ref3$payload = _ref3.payload, | ||
OAuthURI = _ref3$payload.OAuthURI, | ||
responseType = _ref3$payload.responseType, | ||
clientId = _ref3$payload.clientId, | ||
redirectUri = _ref3$payload.redirectUri, | ||
scope = _ref3$payload.scope, | ||
_ref3$payload$onSucce = _ref3$payload.onSuccess, | ||
onSuccess = _ref3$payload$onSucce === undefined ? _noop : _ref3$payload$onSucce, | ||
_ref3$payload$onFailu = _ref3$payload.onFailure, | ||
onFailure = _ref3$payload$onFailu === undefined ? _noop : _ref3$payload$onFailu; | ||
return () => { | ||
// unsubscribe | ||
window.removeEventListener('message', handleEvent); | ||
}; | ||
}); | ||
var authWindow, windowEventChannel, _ref4, OAuthToken, error; | ||
const { OAuthToken, error } = yield effects.take(windowEventChannel); | ||
yield effects.call([authWindow, authWindow.close]); | ||
return regeneratorRuntime.wrap(function requestOAuthGrantImplicit$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return effects.call(window.open, OAuthURI + '?response_type=' + responseType + '&client_id=' + clientId + '&redirect_uri=' + redirectUri + '&scope=' + scope, '_auth', 'width=550px,height=650px'); | ||
if (OAuthToken) { | ||
yield effects.put(OAuthGrantSuccess({ OAuthToken })); | ||
yield effects.call(onSuccess, { OAuthToken }); | ||
} else if (error) { | ||
yield effects.put(OAuthGrantFailure({ error })); | ||
yield effects.call(onFailure, error); | ||
} | ||
case 2: | ||
authWindow = _context2.sent; | ||
windowEventChannel = reduxSaga.eventChannel(function (emitter) { | ||
function handleEvent(e) { | ||
if (e.data.OAuthToken || e.data.error) { | ||
emitter({ OAuthToken: e.data.OAuthToken, error: e.data.error }); | ||
emitter(reduxSaga.END); | ||
} | ||
} | ||
window.addEventListener('message', handleEvent, false); | ||
return function () { | ||
// unsubscribe | ||
window.removeEventListener('message', handleEvent); | ||
}; | ||
}); | ||
_context2.next = 6; | ||
return effects.take(windowEventChannel); | ||
case 6: | ||
_ref4 = _context2.sent; | ||
OAuthToken = _ref4.OAuthToken; | ||
error = _ref4.error; | ||
_context2.next = 11; | ||
return effects.call([authWindow, authWindow.close]); | ||
case 11: | ||
if (!OAuthToken) { | ||
_context2.next = 18; | ||
break; | ||
} | ||
_context2.next = 14; | ||
return effects.put(OAuthGrantSuccess({ OAuthToken: OAuthToken })); | ||
case 14: | ||
_context2.next = 16; | ||
return effects.call(onSuccess, { OAuthToken: OAuthToken }); | ||
case 16: | ||
_context2.next = 23; | ||
break; | ||
case 18: | ||
if (!error) { | ||
_context2.next = 23; | ||
break; | ||
} | ||
_context2.next = 21; | ||
return effects.put(OAuthGrantFailure({ error: error })); | ||
case 21: | ||
_context2.next = 23; | ||
return effects.call(onFailure, error); | ||
case 23: | ||
case 'end': | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _marked2, this); | ||
} | ||
function* watchOAuthGrantRequest() { | ||
yield effects.all([effects.takeLatest(REQUEST_OAUTH_GRANT, requestOAuthGrant$1), effects.takeLatest(REQUEST_OAUTH_GRANT_IMPLICIT, requestOAuthGrantImplicit$1)]); | ||
function watchOAuthGrantRequest() { | ||
return regeneratorRuntime.wrap(function watchOAuthGrantRequest$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
_context3.next = 2; | ||
return effects.all([effects.takeLatest(REQUEST_OAUTH_GRANT, requestOAuthGrant$1), effects.takeLatest(REQUEST_OAUTH_GRANT_IMPLICIT, requestOAuthGrantImplicit$1)]); | ||
case 2: | ||
case 'end': | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _marked3, this); | ||
} | ||
function* root() { | ||
yield effects.all([effects.fork(watchOAuthGrantRequest)]); | ||
function root() { | ||
return regeneratorRuntime.wrap(function root$(_context4) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
_context4.next = 2; | ||
return effects.all([effects.fork(watchOAuthGrantRequest)]); | ||
case 2: | ||
case 'end': | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _marked4, this); | ||
} | ||
const uiState = _extends({ | ||
var uiState = _extends({ | ||
reducer: reducer | ||
}, uiStateModule); | ||
const user = _extends({ | ||
var user = _extends({ | ||
reducer: reducer$3 | ||
}, userModule, userConstants); | ||
const config = _extends({ | ||
var config = _extends({ | ||
reducer: reducer$2 | ||
}, configModule); | ||
const auth = _extends({ | ||
var auth = _extends({ | ||
reducer: reducer$1 | ||
@@ -796,14 +984,25 @@ }, authModule, authConstants, { | ||
// top level component | ||
let Sagas = (_temp = _class = class Sagas extends React.Component { | ||
var Sagas = (_temp = _class = function (_Component) { | ||
inherits(Sagas, _Component); | ||
getChildContext() { | ||
return { | ||
sagas: this.props.middleware | ||
}; | ||
function Sagas() { | ||
classCallCheck(this, Sagas); | ||
return possibleConstructorReturn(this, (Sagas.__proto__ || Object.getPrototypeOf(Sagas)).apply(this, arguments)); | ||
} | ||
render() { | ||
return React.Children.only(this.props.children); | ||
} | ||
}, _class.propTypes = { | ||
createClass(Sagas, [{ | ||
key: 'getChildContext', | ||
value: function getChildContext() { | ||
return { | ||
sagas: this.props.middleware | ||
}; | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
return React.Children.only(this.props.children); | ||
} | ||
}]); | ||
return Sagas; | ||
}(React.Component), _class.propTypes = { | ||
// as returned from redux-saga:createSagaMiddleware | ||
@@ -817,26 +1016,39 @@ middleware: PropTypes__default.func.isRequired | ||
// simple! | ||
let Saga = (_temp2 = _class2 = class Saga extends React.Component { | ||
var Saga = (_temp2 = _class2 = function (_Component2) { | ||
inherits(Saga, _Component2); | ||
componentDidMount() { | ||
if (!this.context.sagas) { | ||
throw new Error('did you forget to include <Sagas/>?'); | ||
} | ||
this.runningSaga = this.context.sagas.run(this.props.saga, this.props); | ||
function Saga() { | ||
classCallCheck(this, Saga); | ||
return possibleConstructorReturn(this, (Saga.__proto__ || Object.getPrototypeOf(Saga)).apply(this, arguments)); | ||
} | ||
componentWillReceiveProps() { | ||
// ?? | ||
} | ||
render() { | ||
return !this.props.children ? null : React.Children.only(this.props.children); | ||
} | ||
componentWillUnmount() { | ||
if (this.runningSaga) { | ||
this.runningSaga.cancel(); | ||
delete this.runningSaga; | ||
createClass(Saga, [{ | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
if (!this.context.sagas) { | ||
throw new Error('did you forget to include <Sagas/>?'); | ||
} | ||
this.runningSaga = this.context.sagas.run(this.props.saga, this.props); | ||
} | ||
} | ||
}, _class2.propTypes = { | ||
}, { | ||
key: 'componentWillReceiveProps', | ||
value: function componentWillReceiveProps() { | ||
// ?? | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
return !this.props.children ? null : React.Children.only(this.props.children); | ||
} | ||
}, { | ||
key: 'componentWillUnmount', | ||
value: function componentWillUnmount() { | ||
if (this.runningSaga) { | ||
this.runningSaga.cancel(); | ||
delete this.runningSaga; | ||
} | ||
} | ||
}]); | ||
return Saga; | ||
}(React.Component), _class2.propTypes = { | ||
saga: PropTypes__default.func.isRequired | ||
@@ -852,12 +1064,22 @@ }, _class2.contextTypes = { | ||
return _temp3 = _class3 = class SagaDecorator extends React.Component { | ||
return _temp3 = _class3 = function (_Component3) { | ||
inherits(SagaDecorator, _Component3); | ||
render() { | ||
return React__default.createElement( | ||
Saga, | ||
_extends({ saga: run }, this.props), | ||
React__default.createElement(Target, this.props) | ||
); | ||
function SagaDecorator() { | ||
classCallCheck(this, SagaDecorator); | ||
return possibleConstructorReturn(this, (SagaDecorator.__proto__ || Object.getPrototypeOf(SagaDecorator)).apply(this, arguments)); | ||
} | ||
}, _class3.displayName = 'saga:' + (Target.displayName || Target.name), _temp3; | ||
createClass(SagaDecorator, [{ | ||
key: 'render', | ||
value: function render() { | ||
return React__default.createElement( | ||
Saga, | ||
_extends({ saga: run }, this.props), | ||
React__default.createElement(Target, this.props) | ||
); | ||
} | ||
}]); | ||
return SagaDecorator; | ||
}(React.Component), _class3.displayName = 'saga:' + (Target.displayName || Target.name), _temp3; | ||
}; | ||
@@ -887,92 +1109,109 @@ } | ||
return `${s4()}-${s4()}-${s4()}`; | ||
return s4() + "-" + s4() + "-" + s4(); | ||
} | ||
const withUIState = ({ | ||
// specify a key here to use the same key for every instance of this component. | ||
// (careful, this won't work if multiple instances exist at the same time! | ||
// It's meant for ie. wrapping an entire page container) | ||
// otherwise, specify it on the component itself <Component uiStateKey="my-key" /> | ||
// if no key is specified, a random one will be assigned for every instance. | ||
key = null, | ||
// persist state across unmount/mount? rendered component must be passed a | ||
// `uiStateKey` prop for persistence to work | ||
persist = false, // todo: allow config of persistance from a prop | ||
defaultState = {} | ||
} = {}, connect = reactRedux.connect) => WrappedComponent => { | ||
var _dec, _class, _class2, _temp2; | ||
var withUIState = function withUIState() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
_ref$key = _ref.key, | ||
key = _ref$key === undefined ? null : _ref$key, | ||
_ref$persist = _ref.persist, | ||
persist = _ref$persist === undefined ? false : _ref$persist, | ||
_ref$defaultState = _ref.defaultState, | ||
defaultState = _ref$defaultState === undefined ? {} : _ref$defaultState; | ||
let WrappedWithUIState = (_dec = connect(() => { | ||
const randomKey = guid(); | ||
var connect = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : reactRedux.connect; | ||
return function (WrappedComponent) { | ||
var _dec, _class, _class2, _temp2; | ||
return function mapStateToProps(state, ownProps) { | ||
const stateKey = ownProps.uiStateKey || key || randomKey; | ||
var WrappedWithUIState = (_dec = connect(function () { | ||
var randomKey = guid(); | ||
return { | ||
uiStateKey: stateKey, | ||
uiState: getStateForKey(state, stateKey), | ||
defaultState: _isFunction(defaultState) ? defaultState(ownProps) : defaultState | ||
return function mapStateToProps(state, ownProps) { | ||
var stateKey = ownProps.uiStateKey || key || randomKey; | ||
return { | ||
uiStateKey: stateKey, | ||
uiState: getStateForKey(state, stateKey), | ||
defaultState: _isFunction(defaultState) ? defaultState(ownProps) : defaultState | ||
}; | ||
}; | ||
}; | ||
}, { | ||
setStateForKey, | ||
clearStateForKey | ||
}), _dec(_class = (_temp2 = _class2 = class WrappedWithUIState extends React__default.Component { | ||
constructor(...args) { | ||
var _temp; | ||
}, { | ||
setStateForKey: setStateForKey, | ||
clearStateForKey: clearStateForKey | ||
}), _dec(_class = (_temp2 = _class2 = function (_React$Component) { | ||
inherits(WrappedWithUIState, _React$Component); | ||
return _temp = super(...args), this.setUIState = state => { | ||
this.props.setStateForKey(this.props.uiStateKey, state); | ||
}, this.resetUIState = () => { | ||
this.props.setStateForKey(this.props.uiStateKey, this.props.defaultState); | ||
}, _temp; | ||
} | ||
function WrappedWithUIState() { | ||
var _ref2; | ||
componentWillMount() { | ||
this.isMounting = true; | ||
var _temp, _this, _ret; | ||
if (persist) { | ||
return this.props.setStateForKey(this.props.uiStateKey, _isEmpty(this.props.uiState) ? this.props.defaultState : this.props.uiState); | ||
classCallCheck(this, WrappedWithUIState); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref2 = WrappedWithUIState.__proto__ || Object.getPrototypeOf(WrappedWithUIState)).call.apply(_ref2, [this].concat(args))), _this), _this.setUIState = function (state) { | ||
_this.props.setStateForKey(_this.props.uiStateKey, state); | ||
}, _this.resetUIState = function () { | ||
_this.props.setStateForKey(_this.props.uiStateKey, _this.props.defaultState); | ||
}, _temp), possibleConstructorReturn(_this, _ret); | ||
} | ||
this.resetUIState(); | ||
} | ||
createClass(WrappedWithUIState, [{ | ||
key: 'componentWillMount', | ||
value: function componentWillMount() { | ||
this.isMounting = true; | ||
componentDidMount() { | ||
this.isMounting = false; | ||
} | ||
if (persist) { | ||
return this.props.setStateForKey(this.props.uiStateKey, _isEmpty(this.props.uiState) ? this.props.defaultState : this.props.uiState); | ||
} | ||
componentWillUnmount() { | ||
if (!persist) { | ||
this.props.clearStateForKey(this.props.uiStateKey); | ||
} | ||
} | ||
this.resetUIState(); | ||
} | ||
}, { | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
this.isMounting = false; | ||
} | ||
}, { | ||
key: 'componentWillUnmount', | ||
value: function componentWillUnmount() { | ||
if (!persist) { | ||
this.props.clearStateForKey(this.props.uiStateKey); | ||
} | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
var restProps = _omit(this.props, ['setStateForKey', 'clearStateForKey', 'defaultState']); | ||
render() { | ||
const restProps = _omit(this.props, ['setStateForKey', 'clearStateForKey', 'defaultState']); | ||
return React__default.createElement(WrappedComponent, _extends({}, restProps, { | ||
uiState: | ||
// ensure child never sees empty state | ||
// (it renders once before the intitial store | ||
// state gets set) | ||
this.isMounting ? this.props.defaultState : this.props.uiState, | ||
setUIState: this.setUIState, | ||
resetUIState: this.resetUIState | ||
})); | ||
} | ||
}]); | ||
return WrappedWithUIState; | ||
}(React__default.Component), _class2.propTypes = { | ||
uiStateKey: PropTypes.string.isRequired, | ||
uiState: PropTypes.objectOf(PropTypes.any), | ||
setStateForKey: PropTypes.func, | ||
clearStateForKey: PropTypes.func, | ||
defaultState: PropTypes.objectOf(PropTypes.any) | ||
}, _class2.defaultProps = { | ||
uiState: {}, | ||
setStateForKey: _noop, | ||
clearStateForKey: _noop | ||
}, _temp2)) || _class); | ||
return React__default.createElement(WrappedComponent, _extends({}, restProps, { | ||
uiState: | ||
// ensure child never sees empty state | ||
// (it renders once before the intitial store | ||
// state gets set) | ||
this.isMounting ? this.props.defaultState : this.props.uiState, | ||
setUIState: this.setUIState, | ||
resetUIState: this.resetUIState | ||
})); | ||
} | ||
}, _class2.propTypes = { | ||
uiStateKey: PropTypes.string.isRequired, | ||
uiState: PropTypes.objectOf(PropTypes.any), | ||
setStateForKey: PropTypes.func, | ||
clearStateForKey: PropTypes.func, | ||
defaultState: PropTypes.objectOf(PropTypes.any) | ||
}, _class2.defaultProps = { | ||
uiState: {}, | ||
setStateForKey: _noop, | ||
clearStateForKey: _noop | ||
}, _temp2)) || _class); | ||
return WrappedWithUIState; | ||
return WrappedWithUIState; | ||
}; | ||
}; | ||
@@ -979,0 +1218,0 @@ |
{ | ||
"name": "veritone-redux-common", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"dependencies": { | ||
@@ -26,3 +26,5 @@ "lodash": "^4.17.4", | ||
"prebuild": "npm run clean:build", | ||
"build": "NODE_ENV=production rollup -c", | ||
"build": "yarn run build:es && yarn run build:cjs", | ||
"build:es": "cross-env NODE_ENV=production BABEL_ENV=production-es rollup -c rollup.config.es.js", | ||
"build:cjs": "cross-env NODE_ENV=production BABEL_ENV=production-cjs rollup -c rollup.config.cjs.js", | ||
"build:watch": "NODE_ENV=production rollup -c --watch", | ||
@@ -43,2 +45,3 @@ "prepublishOnly": "npm run test && npm run lint && npm run build" | ||
"babel-preset-env": "^1.6.1", | ||
"cross-env": "^5.1.4", | ||
"enzyme": "^3.1.0", | ||
@@ -45,0 +48,0 @@ "enzyme-adapter-react-16": "^1.0.2", |
Sorry, the diff of this file is not supported yet
116227
37
3150
33