@acoustic-content-sdk/redux-feature-url-config
Version:
> TODO: description
277 lines (263 loc) • 10.2 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@acoustic-content-sdk/utils'), require('redux-actions'), require('@acoustic-content-sdk/redux-store')) :
typeof define === 'function' && define.amd ? define('@acoustic-content-sdk/redux-feature-url-config', ['exports', '@acoustic-content-sdk/utils', 'redux-actions', '@acoustic-content-sdk/redux-store'], factory) :
(global = global || self, factory((global['acoustic-content-sdk'] = global['acoustic-content-sdk'] || {}, global['acoustic-content-sdk']['redux-feature-url-config'] = {}), global['acoustic-content-sdk'].utils, global.ReduxActions, global['acoustic-content-sdk']['redux-store']));
}(this, (function (exports, utils, reduxActions, reduxStore) { 'use strict';
/**
* @fileoverview added by tsickle
* Generated from: utils/predicates.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Tests if a value is a provider
*
* @param {?} aValue - the value
* @return {?} true if the value is a provider, else false
*/
function isStaticHubInfoUrlProvider(aValue) {
return utils.isURL(aValue) || utils.isString(aValue) || utils.isFunction(aValue);
}
/**
* @fileoverview added by tsickle
* Generated from: state/url-config/url.config.actions.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var ACTION_SET_URL_CONFIG = 'ACTION_SET_URL_CONFIG';
/** @type {?} */
var ACTION_CLEAR_URL_CONFIG = 'ACTION_CLEAR_URL_CONFIG';
/** @type {?} */
var clearUrlConfigAction = reduxActions.createAction(ACTION_CLEAR_URL_CONFIG);
/** @type {?} */
var _setUrlConfigAction = reduxActions.createAction(ACTION_SET_URL_CONFIG);
/** @type {?} */
var setUrlConfigAction = (/**
* @param {?} provider
* @return {?}
*/
function (provider) {
return _setUrlConfigAction(isStaticHubInfoUrlProvider(provider)
? utils.urlToString(utils.urlFromProvider(provider))
: provider);
});
/**
* @fileoverview added by tsickle
* Generated from: state/url-config/url.config.id.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var URL_CONFIG_FEATURE = 'urlConfig';
var _a;
// default
/** @type {?} */
var DEFAULT_CONFIG = {
apiUrl: null,
resourceUrl: null,
isPreviewMode: false,
baseUrl: null
};
/*
* Makes sure our path ends with a proper trailing slash
*/
/**
* @param {?} aUrl
* @return {?}
*/
function _guaranteeTrailingSlash(aUrl) {
return aUrl.endsWith('/') ? aUrl : aUrl + '/';
}
/**
* @param {?} aUrl
* @return {?}
*/
function createBaseURL(aUrl) {
/** @type {?} */
var url = utils.parseURL(aUrl);
return utils.isNotNil(url)
? _guaranteeTrailingSlash("" + url.origin + url.pathname)
: undefined;
}
/** @type {?} */
var HAS_DOCUMENT = typeof document !== utils.UNDEFINED_TYPE;
/**
* Returns the global document if it exists
* @return {?}
*/
function getDocument() {
return HAS_DOCUMENT ? document : undefined;
}
/**
* Decodes the URL configuration from a URL provider
*
* @param {?} aApiUrl - the API URL
* @param {?=} aDocument - optionally the document
*
* @return {?} the configuration
*/
function wchGetUrlConfig(aApiUrl, aDocument) {
/**
* Decode the resource base
*/
// const resourceBaseUrl = getBaseUrlFromDocument(aDocument);
// const resourceBaseUrl = getBaseUrlFromDocument(aDocument);
/**
* Decode the base URL from the configuration or fall back to the global window
* @type {?}
*/
var baseUrl = utils.parseURL(createBaseURL(utils.wchGetBaseURL(aDocument)));
// decode the fallback
/** @type {?} */
var cfgFallback = utils.mergeHubInfo(utils.wchGetHubInfoFromBaseURL(baseUrl), utils.wchGetHubInfoFromLinks(aDocument));
/** @type {?} */
var infoApiUrl = utils.urlFromProvider(aApiUrl) || utils.parseURL(cfgFallback.apiUrl);
/** @type {?} */
var apiRoot = createBaseURL(infoApiUrl);
/** @type {?} */
var resourceRoot = createBaseURL(utils.wchGetResourceUrlFromApiURL(infoApiUrl));
// convert
/** @type {?} */
var apiUrl = utils.parseURL(apiRoot);
/** @type {?} */
var resourceUrl = utils.parseURL(resourceRoot);
/** @type {?} */
var isPreviewMode = utils.wchIsPreviewMode(apiUrl);
// ok
return {
apiUrl: apiUrl,
resourceUrl: resourceUrl,
baseUrl: baseUrl,
isPreviewMode: isPreviewMode
};
}
/**
* reducers for config settings
* @type {?}
*/
var urlConfigReducer = reduxActions.handleActions((_a = {},
_a[ACTION_SET_URL_CONFIG] = (/**
* @param {?} state
* @param {?} action
* @return {?}
*/
function (state, action) {
// extract the payload
/** @type {?} */
var payload = reduxStore.selectPayload(action);
return utils.isString(payload)
? wchGetUrlConfig(payload, getDocument())
: payload;
}),
_a[ACTION_CLEAR_URL_CONFIG] = (/**
* @param {?} state
* @param {?} action
* @return {?}
*/
function (state, action) { return DEFAULT_CONFIG; }),
_a), DEFAULT_CONFIG);
var _a$1;
/**
* Represents the {\@link UrlConfigState | configuration} of the URLs to be used
* when working with {\@link https://developer.ibm.com/api/view/dx-prod:ibm-watson-content-hub:title-IBM_Watson_Content_Hub | WCH REST} services.
* @record
*/
function UrlConfigFeatureState() { }
if (false) {
/* Skipping unnamed member:
[URL_CONFIG_FEATURE]: UrlConfigState;*/
}
/**
*
* @type {?}
*/
var urlConfigFeatureReducer = (_a$1 = {},
_a$1[URL_CONFIG_FEATURE] = urlConfigReducer,
_a$1);
/**
* Select the URL config feature
*
* \@param aState - the feature state
* \@return the URL configuration object
* @type {?}
*/
var selectUrlConfigFeature = reduxStore.selectFeature(URL_CONFIG_FEATURE);
/**
* @fileoverview added by tsickle
* Generated from: state/url-config/url.config.module.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Exposes the feature module selector
* @type {?}
*/
var urlConfigFeature = reduxStore.createReduxFeatureModule(URL_CONFIG_FEATURE, urlConfigReducer);
/**
* @fileoverview added by tsickle
* Generated from: utils/general.selectors.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Tests if a value is a valid URL
*
* @param {?} aValue - the value to test
* @return {?} true if the value is a valid URL
*/
function isValidUrl(aValue) {
return (utils.isNotNil(aValue) && utils.isNotNil(aValue.href) && utils.isAbsoluteURL(aValue.href));
}
/**
* @fileoverview added by tsickle
* Generated from: state/url-config/url.config.selectors.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var selectIsPreviewMode = utils.pluckProperty('isPreviewMode');
/** @type {?} */
var selectApiUrl = utils.pluckProperty('apiUrl');
/** @type {?} */
var selectResourceUrl = utils.pluckProperty('resourceUrl');
/**
* Tests if an object is a valid {\@link UrlConfigState} object
*
* @param {?} aState - the object to test
* @return {?} true if the state is valid else false
*/
function isValidUrlConfig(aState) {
return (utils.isNotNil(aState) &&
isValidUrl(selectApiUrl(aState)) &&
isValidUrl(selectResourceUrl(aState)));
}
/**
* @fileoverview added by tsickle
* Generated from: state/url-config/index.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* Generated from: version.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Version and build number of the package
* @type {?}
*/
var VERSION = { version: { major: '9', minor: '0', patch: '10076', branch: 'master' }, build: new Date(1585229427693) };
/**
* Module name
* @type {?}
*/
var MODULE = '@acoustic-content-sdk/redux-feature-url-config';
exports.URL_CONFIG_FEATURE = URL_CONFIG_FEATURE;
exports.VERSION = VERSION;
exports.isValidUrl = isValidUrl;
exports.isValidUrlConfig = isValidUrlConfig;
exports.selectApiUrl = selectApiUrl;
exports.selectIsPreviewMode = selectIsPreviewMode;
exports.selectResourceUrl = selectResourceUrl;
exports.selectUrlConfigFeature = selectUrlConfigFeature;
exports.setUrlConfigAction = setUrlConfigAction;
exports.urlConfigFeature = urlConfigFeature;
exports.urlConfigFeatureReducer = urlConfigFeatureReducer;
exports.urlConfigReducer = urlConfigReducer;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=acoustic-content-sdk-redux-feature-url-config.umd.js.map