@stackend/api
Version:
JS bindings to api.stackend.com
44 lines • 1.78 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.XCAP_SET_CONFIG = exports.XCAP_INITIAL_STORE_DATA_RECEIVED = void 0;
var get_1 = __importDefault(require("lodash/get"));
var index_1 = require("./index");
exports.XCAP_INITIAL_STORE_DATA_RECEIVED = 'XCAP_INITIAL_STORE_DATA_RECEIVED';
exports.XCAP_SET_CONFIG = 'XCAP_SET_CONFIG';
var configReducer = function (state, action) {
if (state === void 0) { state = {
apiUrl: index_1.STACKEND_DEFAULT_SERVER + index_1.STACKEND_DEFAULT_CONTEXT_PATH + '/api',
contextPath: index_1.STACKEND_DEFAULT_CONTEXT_PATH,
server: index_1.STACKEND_DEFAULT_SERVER,
deployProfile: index_1.DeployProfile.STACKEND,
gaKey: null,
recaptchaSiteKey: null
}; }
switch (action.type) {
case exports.XCAP_INITIAL_STORE_DATA_RECEIVED:
return (0, get_1.default)(action, 'json.xcapApiConfiguration', state);
case exports.XCAP_SET_CONFIG: {
var c = action.config;
if (c.server) {
var cp = c.contextPath;
if (typeof cp !== 'string') {
cp = state.contextPath || '';
}
if (c.server.endsWith('/')) {
cp = cp.replace(/^\//, '');
}
if (cp.endsWith('/'))
cp = cp.replace(/\/$/, '');
c.apiUrl = c.server + cp + '/api';
}
return Object.assign({}, state, c);
}
default:
return state;
}
};
exports.default = configReducer;
//# sourceMappingURL=configReducer.js.map