UNPKG

@ema/js-base-library

Version:

This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 7.2.0.

1,778 lines (1,769 loc) 114 kB
import { __awaiter, __generator, __assign, __extends, __spread } from 'tslib'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var BaseApi = /** @class */ (function () { function BaseApi() { this.headers = {}; this.routes = {}; this.baseUrl = '/api'; this.idField = 'id'; this.requestCredentials = 'same-origin'; // include, same-origin, *omit (default) // include, same-origin, *omit (default) this.corsMode = 'same-origin'; // no-cors, cors, *same-origin (default) // no-cors, cors, *same-origin (default) this.cachePolicy = 'no-cache'; // *default, no-cache, reload, force-cache, only-if-cached this.entities = {}; this.hasDebugger = false; } /** * @param {?} settings * @return {?} */ BaseApi.prototype.init = /** * @param {?} settings * @return {?} */ function (settings) { var _this = this; this.settings = settings; if (this.settings.host) { this.baseUrl = settings.host; } if (this.settings.routes) { this.initApiRoutes(this.settings.routes); } if (this.settings.headers) { /** @type {?} */ var self_1 = this; this.settings.headers.forEach((/** * @param {?} obj * @return {?} */ function (obj) { for (var k in obj) { self_1.headers[k] = obj[k]; } })); } if (this['httpHeaders']) { // AngularJs only Object.keys(this.headers).forEach((/** * @param {?} k * @return {?} */ function (k) { _this['httpHeaders'].set(k, _this.headers[k]); })); } // if ('withCredentials' in new XMLHttpRequest) { // this.cors = true; // } }; /** * @param {?} url * @return {?} */ BaseApi.prototype.route = /** * @param {?} url * @return {?} */ function (url) { var _this = this; /** @type {?} */ var mappedUrl; Object.keys(this.routes).forEach((/** * @param {?} k * @return {?} */ function (k) { if (k === url) { mappedUrl = _this.routes[k]; } })); if (mappedUrl) { return mappedUrl; } else { return url; } }; // CRUD // CRUD /** * @param {?} path * @param {?} data * @return {?} */ BaseApi.prototype.post = // CRUD /** * @param {?} path * @param {?} data * @return {?} */ function (path, data) { return __awaiter(this, void 0, void 0, function () { var result; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, fetch("" + this.baseUrl + path, { body: JSON.stringify(data), // must match 'Content-Type' header cache: this.cachePolicy, credentials: this.requestCredentials, headers: this.headers, mode: this.corsMode, method: 'POST', }) .then((/** * @param {?} response * @return {?} */ function (response) { if (response.status >= 400) { console.log(response); console.error('Bad response from server'); return response; } return response.json(); })) .catch(this.errorHandler) .then((/** * @param {?} data * @return {?} */ function (data) { return data; }))]; case 1: result = _a.sent(); return [2 /*return*/, result]; } }); }); }; /** * @param {?} path * @param {?=} params * @return {?} */ BaseApi.prototype.get = /** * @param {?} path * @param {?=} params * @return {?} */ function (path, params) { if (params === void 0) { params = undefined; } return __awaiter(this, void 0, void 0, function () { var result; return __generator(this, function (_a) { switch (_a.label) { case 0: if (params) { path += '?'; Object.keys(params).forEach((/** * @param {?} key * @return {?} */ function (key) { return path += key + '=' + params[key] + '&'; })); } return [4 /*yield*/, fetch("" + this.baseUrl + path, { cache: this.cachePolicy, credentials: this.requestCredentials, headers: this.headers, mode: this.corsMode, method: 'GET', }).then((/** * @param {?} response * @return {?} */ function (response) { if (response.status >= 400) { console.log(response); console.log('Bad response from server'); return response; } return response.json(); })) .catch(this.errorHandler) .then((/** * @param {?} data * @return {?} */ function (data) { return data; }))]; case 1: result = _a.sent(); return [2 /*return*/, result]; } }); }); }; // todo: patch // todo: patch /** * @param {?} path * @param {?} id * @param {?} data * @return {?} */ BaseApi.prototype.patch = // todo: patch /** * @param {?} path * @param {?} id * @param {?} data * @return {?} */ function (path, id, data) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, fetch("" + this.baseUrl + path + "/" + id, { headers: this.headers, // method: 'PATCH', method: 'patch', body: JSON.stringify(data) })]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }; // fixme: causes php server error on drupal content page // fixme: causes php server error on drupal content page /** * @param {?} path * @param {?} id * @return {?} */ BaseApi.prototype.delete = // fixme: causes php server error on drupal content page /** * @param {?} path * @param {?} id * @return {?} */ function (path, id) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { console.log(path, id); return [2 /*return*/]; }); }); }; /** * @param {?} username * @param {?} password * @return {?} */ BaseApi.prototype.login = /** * @param {?} username * @param {?} password * @return {?} */ function (username, password) { console.log(username, password.length); }; /** * @param {?=} namespace * @param {?=} refresh * @return {?} */ BaseApi.prototype.logout = /** * @param {?=} namespace * @param {?=} refresh * @return {?} */ function (namespace, refresh) { if (namespace === void 0) { namespace = 'app:authData'; } if (refresh === void 0) { refresh = false; } this.clearCredentials(namespace); this.settings.authenticated = false; if (refresh) { // location.href = location.origin; location.href = location.href; } }; // todo: use btoa + atob // todo: use btoa + atob /** * @param {?} credentials * @param {?=} namespace * @return {?} */ BaseApi.prototype.setCredentials = // todo: use btoa + atob /** * @param {?} credentials * @param {?=} namespace * @return {?} */ function (credentials, namespace) { if (namespace === void 0) { namespace = 'app-auth'; } this.credentials = credentials; // window.localStorage.setItem(namespace, btoa(JSON.stringify(credentials))); if (typeof window !== 'undefined' && window.localStorage) { window.localStorage.setItem(namespace, JSON.stringify(credentials)); } }; /** * @param {?=} namespace * @return {?} */ BaseApi.prototype.getCredentials = /** * @param {?=} namespace * @return {?} */ function (namespace) { if (namespace === void 0) { namespace = 'app:authData'; } if (typeof window !== 'undefined' && window.localStorage && window.localStorage.getItem(namespace)) { // return JSON.parse(atob(window.localStorage.getItem(namespace))); return JSON.parse(window.localStorage.getItem(namespace)); } }; /** * @param {?=} namespace * @return {?} */ BaseApi.prototype.clearCredentials = /** * @param {?=} namespace * @return {?} */ function (namespace) { if (namespace === void 0) { namespace = 'app:authData'; } if (typeof window !== 'undefined' && window.localStorage.getItem(namespace)) { window.localStorage.removeItem(namespace); } }; /** * @param {?} routes * @return {?} */ BaseApi.prototype.initApiRoutes = /** * @param {?} routes * @return {?} */ function (routes) { /** @type {?} */ var self = this; routes.forEach((/** * @param {?} obj * @return {?} */ function (obj) { for (var k in obj) { self.routes[k] = obj[k]; } })); if (self.settings.dev && self.settings.routes_dev) { self.settings.routes_dev.forEach((/** * @param {?} obj * @return {?} */ function (obj) { for (var k in obj) { self.routes[k] = obj[k]; } })); } }; // todo // todo /** * @param {?} error * @return {?} */ BaseApi.prototype.errorHandler = // todo /** * @param {?} error * @return {?} */ function (error) { // AppService.scope.$broadcast('formError', error); console.error(error); if (!error) { return; } // if(error.data === "token expired"){ //     toastr.warning($filter('translate')('LOGIN EXPIRED')+'.'); //     service.logOut(); //     return; // } // if (error.statusText === 'Bad Request' || error.status == 400) { //     if (error.data.message) { //         toastr.warning($filter('translate')(error.data.message)); //     } else { //         toastr.warning($filter('translate')('ERROR BAD REQUEST') + '.'); //     } // } // if(error.statusText === 'Unauthorized' || error.status == 401){ //     toastr.warning($filter('translate')('UNAUTHORIZED ERROR')+'.'); //     service.logOut(); //     return; // } // if(error.statusText === 'Not found' || error.status == 404){ //     toastr.warning($filter('translate')('ERROR NOT FOUND')+'.'); // } }; // entities local storage todo: move to storage.js // entities local storage todo: move to storage.js /** * @param {?} resource * @return {?} */ BaseApi.prototype.saveLocalResource = // entities local storage todo: move to storage.js /** * @param {?} resource * @return {?} */ function (resource) { localStorage.setItem(resource[this.idField], resource); }; /** * @param {?} ID * @return {?} */ BaseApi.prototype.loadLocalResource = /** * @param {?} ID * @return {?} */ function (ID) { if (localStorage.getItem(ID)) { localStorage.getItem(ID); } }; /** * @param {?} ID * @return {?} */ BaseApi.prototype.flushLocalResource = /** * @param {?} ID * @return {?} */ function (ID) { if (localStorage.getItem(ID)) { localStorage.removeItem(ID); } }; return BaseApi; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /* base class for vanilla-js webcomponents */ var /* base class for vanilla-js webcomponents */ BaseWebComponent = /** @class */ (function (_super) { __extends(BaseWebComponent, _super); function BaseWebComponent() { var _this = _super.call(this) || this; _this.data = {}; return _this; } /** * @return {?} */ BaseWebComponent.prototype.init = /** * @return {?} */ function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/]; }); }); }; /** * @return {?} */ BaseWebComponent.prototype.render = /** * @return {?} */ function () { }; /** * @return {?} */ BaseWebComponent.prototype.definePublicMethods = /** * @return {?} */ function () { }; /** * @return {?} */ BaseWebComponent.prototype.remove = /** * @return {?} */ function () { }; /** * @param {?} name * @param {?} oldVal * @param {?} newVal * @return {?} */ BaseWebComponent.prototype.attributeChangedCallback = /** * @param {?} name * @param {?} oldVal * @param {?} newVal * @return {?} */ function (name, oldVal, newVal) { }; /** * @return {?} */ BaseWebComponent.prototype.connectedCallback = /** * @return {?} */ function () { var _this = this; /** @type {?} */ var shadowRoot; this.data = {}; if (!this.shadowRoot) { shadowRoot = this.root = this.attachShadow({ mode: 'open' }); } else { shadowRoot = this.root = this.shadowRoot; } this.el = shadowRoot.appendChild(this.template.content.cloneNode(true)); this.setState = this.setState.bind(this); this.getState = this.getState.bind(this); this.removeState = this.removeState.bind(this); this.getData = this.getData.bind(this); this.setData = this.setData.bind(this); if (this.definePublicMethods) { this.definePublicMethods(); } if (this.init) { this.init = this.init.bind(this); } if (this.dataJson) { this.data = JSON.parse(this.dataJson); } if (this.init) { this.init().then((/** * @return {?} */ function () { _this.preRender(); })); } else { this.preRender(); } }; Object.defineProperty(BaseWebComponent.prototype, "template", { get: /** * @return {?} */ function () { if (this._template) { return this._template; } this._template = document.createElement('template'); /** @type {?} */ var styles = document.createElement('style'); /** @type {?} */ var content = document.createElement('div'); /** @type {?} */ var imports = document.createElement('head'); imports.innerHTML = this.imports || ""; styles.innerHTML = this.styles || ""; content.innerHTML = this.htmlTemplate || ""; content.className = 'content'; this._template.content.appendChild(styles); this._template.content.appendChild(imports); this._template.content.appendChild(content); return this._template; }, enumerable: true, configurable: true }); /** * @param {?} propName * @param {?} getFn * @param {?} setFn * @return {?} */ BaseWebComponent.prototype.declareProp = /** * @param {?} propName * @param {?} getFn * @param {?} setFn * @return {?} */ function (propName, getFn, setFn) { var _this = this; /** @type {?} */ var obj = {}; // default getters / setters if (!getFn) { getFn = (/** * @return {?} */ function () { if (this.getAttribute(propName) !== null) { return this.getAttribute(propName); } else { return ''; } }); } if (!setFn) { setFn = (/** * @param {?} value * @return {?} */ function (value) { this.setAttribute(propName, value); }); } // current-state: getter / setter if (propName === 'current-state') { // getFn = () => { // return this.getAttribute(propName); // }; setFn = (/** * @param {?} value * @return {?} */ function (value) { if (_this.isJson(value)) { _this.setState(JSON.parse(value)); } else { _this.setState({ value: value }); } // 2 way state if (_this.sharedState) { _this.setAttribute(propName, JSON.stringify(_this.state)); } else { _this.setAttribute(propName, value); } }); } // current-state: getter / setter if (propName === 'data-json') { // getFn = () => { // return this.getAttribute(propName); // }; setFn = (/** * @param {?} value * @return {?} */ function (value) { /** @type {?} */ var data = JSON.parse(value); Object.keys(data).forEach((/** * @param {?} k * @return {?} */ function (k) { _this.data[k] = data[k]; })); _this.setAttribute(propName, value); }); } // obj[propName] = {get: getFn, set: setFn}; obj[this.kebabToLowerCamelCase(propName)] = { get: getFn, set: setFn }; Object.defineProperties(this, obj); }; /** * @param {?} eventName * @param {?} detail * @return {?} */ BaseWebComponent.prototype.dispatch = /** * @param {?} eventName * @param {?} detail * @return {?} */ function (eventName, detail) { this.dispatchEvent(new CustomEvent(eventName, { bubbles: true, detail: detail })); }; // state management // state management /** * @param {?} state * @return {?} */ BaseWebComponent.prototype.setState = // state management /** * @param {?} state * @return {?} */ function (state) { if (typeof state === 'string' && !this.isJson(state)) { console.error('setState only accepts an object as argument'); return; } if (typeof state === 'string' && this.isJson(state)) { state = JSON.parse(state); } this.state = __assign({}, this.state, state); }; /** * @param {?} key * @return {?} */ BaseWebComponent.prototype.getState = /** * @param {?} key * @return {?} */ function (key) { if (key && this.state[key]) { return JSON.parse(JSON.stringify(this.state[key])); } else { return JSON.parse(JSON.stringify(this.state)); } }; /** * @param {?} key * @return {?} */ BaseWebComponent.prototype.removeState = /** * @param {?} key * @return {?} */ function (key) { if (!key) { this.state = {}; this.currentState = '{}'; this.preRender(); } else { delete this.state[key]; } }; // data management // data management /** * @param {?} object * @param {?} extend * @return {?} */ BaseWebComponent.prototype.setData = // data management /** * @param {?} object * @param {?} extend * @return {?} */ function (object, extend) { var _this = this; if (extend) { Object.keys(object).forEach((/** * @param {?} k * @param {?} i * @return {?} */ function (k, i) { _this.data[k] = object[k]; })); } else { this.data = object; } this.preRender(); }; /** * @return {?} */ BaseWebComponent.prototype.getData = /** * @return {?} */ function () { return this.data; }; /** * @return {?} */ BaseWebComponent.prototype.preRender = /** * @return {?} */ function () { if (this.root) { this.root.querySelector('.content')['innerHTML'] = this.render(); } }; // utils // utils /** * @param {?} jsonString * @return {?} */ BaseWebComponent.prototype.isJson = // utils /** * @param {?} jsonString * @return {?} */ function (jsonString) { try { /** @type {?} */ var o = JSON.parse(jsonString); if (o && typeof o === "object") { return o; } } catch (e) { } return false; }; /** * @param {?} str * @return {?} */ BaseWebComponent.prototype.kebabToLowerCamelCase = /** * @param {?} str * @return {?} */ function (str) { /** @type {?} */ var string = str.charAt(0).toLowerCase() + str.slice(1); return string.replace(/(\-\w)/g, (/** * @param {?} m * @return {?} */ function (m) { return m[1].toUpperCase(); })); }; return BaseWebComponent; }(HTMLElement)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var Util = /** @class */ (function () { function Util() { } /** * @param {?} arr * @param {?} value * @return {?} */ Util.arrayRemoveValue = /** * @param {?} arr * @param {?} value * @return {?} */ function (arr, value) { // todo: implement for complex objects /** @type {?} */ var arr2 = arr.filter((/** * @param {?} ele * @return {?} */ function (ele) { return ele != value; })); return arr2; // ex: var result = arrayRemove(array, 'myRemoveString'); }; /** * @param {?} arr * @return {?} */ Util.arraySetUnique = /** * @param {?} arr * @return {?} */ function (arr) { /** @type {?} */ var obj = {}; for (var a = 0; a < arr.length; a++) obj[arr[a]] = true; /** @type {?} */ var resultarr = []; for (var o in obj) resultarr.push(o); return resultarr; }; /** * @param {?} o * @return {?} */ Util.castToType = /** * @param {?} o * @return {?} */ function (o) { /** @type {?} */ var value = o; if (Number(value) && value !== "true" && value !== "false") { value = Number(value); } if (value === "0") { value = 0; } if (value === "true") { value = true; } if (value === "false") { value = false; } return value; }; /** * @param {?} obj * @return {?} */ Util.copy = /** * @param {?} obj * @return {?} */ function (obj) { return JSON.parse(JSON.stringify(obj)); }; /** * @param {?} url * @return {?} */ Util.fetchJson = /** * @param {?} url * @return {?} */ function (url) { return __awaiter(this, void 0, void 0, function () { var response, json; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, fetch(url).catch((/** * @param {?} error * @return {?} */ function (error) { console.error(error); }))]; case 1: response = _a.sent(); return [4 /*yield*/, response.json()]; case 2: json = _a.sent(); return [2 /*return*/, json]; } }); }); }; /** * @param {?} jsonString * @return {?} */ Util.tryParseJSON = /** * @param {?} jsonString * @return {?} */ function (jsonString) { try { /** @type {?} */ var o = JSON.parse(jsonString); if (o && typeof o === "object") { return o; } } catch (e) { } return false; }; /** * Returns the global object of the environment the application is running in (browser, node, web worker, or frame) */ /** * Returns the global object of the environment the application is running in (browser, node, web worker, or frame) * @return {?} */ Util.getGlobal = /** * Returns the global object of the environment the application is running in (browser, node, web worker, or frame) * @return {?} */ function () { // the only reliable means to get the global object is // `Function('return this')()` // However, this causes CSP violations in Chrome apps. if (typeof self !== 'undefined') { return self; } if (typeof window !== 'undefined') { return window; } // @ts-ignore if (typeof global !== 'undefined') { return global; } throw new Error('unable to locate global object'); }; /** * Returns the current date as milliseconds since midnight Jan 1, 1970. */ /** * Returns the current date as milliseconds since midnight Jan 1, 1970. * @param {?=} date * @return {?} */ Util.getTimeStamp = /** * Returns the current date as milliseconds since midnight Jan 1, 1970. * @param {?=} date * @return {?} */ function (date) { if (date === void 0) { date = null; } if (date) { if (typeof date === 'string') { return Math.round(+new Date(date)); } else { return Math.round(+date); } } else { return Math.round(+new Date()); } }; /** * Returns the current date as seconds since midnight Jan 1, 1970. */ /** * Returns the current date as seconds since midnight Jan 1, 1970. * @param {?=} date * @return {?} */ Util.getUnixTimeStamp = /** * Returns the current date as seconds since midnight Jan 1, 1970. * @param {?=} date * @return {?} */ function (date) { if (date === void 0) { date = null; } return Math.floor(Util.getTimeStamp(date) / 1000); }; /** * Returns a UUID. */ /** * Returns a UUID. * @return {?} */ Util.getUUID = /** * Returns a UUID. * @return {?} */ function () { /** @type {?} */ var d = new Date().getTime(); /** @type {?} */ var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (/** * @param {?} c * @return {?} */ function (c) { /** @type {?} */ var r = (d + Math.random() * 16) % 16 | 0; d = Math.floor(d / 16); return (c === 'x' ? r : (r & 0x7 | 0x8)).toString(16); })); return uuid; }; /** * Checks if the application is running in a browser. */ /** * Checks if the application is running in a browser. * @return {?} */ Util.isBrowser = /** * Checks if the application is running in a browser. * @return {?} */ function () { return typeof window !== 'undefined'; }; /** * Checks if the application is running in a browser and online. */ /** * Checks if the application is running in a browser and online. * @return {?} */ Util.isOnline = /** * Checks if the application is running in a browser and online. * @return {?} */ function () { if (typeof window !== 'undefined' && window.navigator.onLine) { return true; } else { return false; } }; return Util; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var ObjectUtil = /** @class */ (function () { function ObjectUtil() { } /** * @param {?} target * @param {...?} sources * @return {?} */ ObjectUtil.deepAssign = /** * @param {?} target * @param {...?} sources * @return {?} */ function (target) { var sources = []; for (var _i = 1; _i < arguments.length; _i++) { sources[_i - 1] = arguments[_i]; } if (!sources.length) { return target; } /** @type {?} */ var source = sources.shift(); if (source === undefined) { return target; } if (ObjectUtil.isMergebleObject(target) && ObjectUtil.isMergebleObject(source)) { Object.keys(source).forEach((/** * @param {?} key * @return {?} */ function (key) { if (ObjectUtil.isMergebleObject(source[key])) { if (!target[key]) { target[key] = {}; } ObjectUtil.deepAssign(target[key], source[key]); } else { target[key] = source[key]; } })); } return ObjectUtil.deepAssign.apply(ObjectUtil, __spread([target], sources)); }; /** * @param {?} item * @return {?} */ ObjectUtil.isMergebleObject = /** * @param {?} item * @return {?} */ function (item) { return ObjectUtil.isObject(item) && !Array.isArray(item); }; /** * @param {?} item * @return {?} */ ObjectUtil.isObject = /** * @param {?} item * @return {?} */ function (item) { return item !== null && typeof item === 'object'; }; return ObjectUtil; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var Storage = /** @class */ (function () { function Storage() { } /** * @param {?} model * @param {?=} modelName * @return {?} */ Storage.saveLocalModel = /** * @param {?} model * @param {?=} modelName * @return {?} */ function (model, modelName) { if (modelName === void 0) { modelName = 'model'; } if (typeof window !== 'undefined' && window.localStorage) { // window.localStorage.setItem(modelName , btoa(JSON.stringify(model))); window.localStorage.setItem(modelName, JSON.stringify(model)); window.localStorage.setItem(modelName + '-changed', String(Math.round(+new Date() / 1000))); } else { console.error('localStorage not available: not running in a browser'); } }; /** * @param {?=} modelName * @return {?} */ Storage.restoreLocalModel = /** * @param {?=} modelName * @return {?} */ function (modelName) { if (modelName === void 0) { modelName = 'model'; } if (typeof window !== 'undefined' && window.localStorage) { if (localStorage.getItem(modelName)) { // return JSON.parse(atob(localStorage.getItem(modelName))); return JSON.parse(localStorage.getItem(modelName)); } } else { console.error('localStorage not available: not running in a browser'); } }; /** * @param {?=} modelName * @return {?} */ Storage.flushLocalModel = /** * @param {?=} modelName * @return {?} */ function (modelName) { if (modelName === void 0) { modelName = 'model'; } if (typeof window !== 'undefined' && window.localStorage) { if (localStorage.getItem(modelName)) { localStorage.removeItem(modelName); } if (localStorage.getItem(modelName + '-changed')) { localStorage.removeItem(modelName + '-changed'); } } else { console.error('localStorage not available: not running in a browser'); } }; return Storage; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var Config = /** @class */ (function () { function Config() { this._config = {}; this._locked = ['_config', '_defaults']; } /** * @param {?} key * @return {?} */ Config.prototype.get = /** * @param {?} key * @return {?} */ function (key) { return this._config[key]; }; /** * @param {?} key * @param {?} value * @param {?=} castToType * @return {?} */ Config.prototype.set = /** * @param {?} key * @param {?} value * @param {?=} castToType * @return {?} */ function (key, value, castToType) { if (castToType === void 0) { castToType = false; } if (!this.islocked(key)) { if (castToType) { value = Util.castToType(value); } return this._config[key] = value; } else { console.error('Config: property "' + key + '" can not be changed.'); } }; /** * @param {?} object * @param {?=} extend * @param {?=} castToType * @return {?} */ Config.prototype.add = /** * @param {?} object * @param {?=} extend * @param {?=} castToType * @return {?} */ function (object, extend, castToType) { if (extend === void 0) { extend = false; } if (castToType === void 0) { castToType = false; } /** @type {?} */ var self = this; if (!extend) { Object.keys(object).forEach((/** * @param {?} key * @return {?} */ function (key) { self.set(key, object[key], castToType); })); } else { this.extend(object); } }; /** * @param {?} url * @param {?=} extend * @return {?} */ Config.prototype.fetch = /** * @param {?} url * @param {?=} extend * @return {?} */ function (url, extend) { if (extend === void 0) { extend = false; } return __awaiter(this, void 0, void 0, function () { var self, config; return __generator(this, function (_a) { switch (_a.label) { case 0: self = this; // if(self.getVar('api_headers')){ // // } // let config = await fetch(url, {headers: self.getVar('api_headers')}) return [4 /*yield*/, fetch(url) .then((/** * @param {?} response * @return {?} */ function (response) { return response.json(); })) .catch((/** * @param {?} error * @return {?} */ function (error) { console.log('config fetch error:', error.message); }))]; case 1: config = _a.sent(); if (extend) { this.extend(config); } else { Object.keys(config).forEach((/** * @param {?} k * @param {?} i * @return {?} */ function (k, i) { self.set(k, config[k]); })); } return [2 /*return*/, config]; } }); }); }; /** * @param {?} object * @param {?=} target * @return {?} */ Config.prototype.extend = /** * @param {?} object * @param {?=} target * @return {?} */ function (object, target) { if (target === void 0) { target = this._config; } ObjectUtil.deepAssign(target, object); }; /** * @return {?} */ Config.prototype.all = /** * @return {?} */ function () { return this._config; }; /** * @param {?} id * @return {?} */ Config.prototype.getLocalSettings = /** * @param {?} id * @return {?} */ function (id) { if (typeof window !== 'undefined') { if (window.localStorage && window.localStorage.getItem(id)) { this.add(Storage.restoreLocalModel(id)); } } }; /** * @param {?} id * @param {?=} settings * @return {?} */ Config.prototype.setLocalSettings = /** * @param {?} id * @param {?=} settings * @return {?} */ function (id, settings) { if (settings === void 0) { settings = this._config; } if (typeof window !== 'undefined') { if (window.localStorage) { Storage.saveLocalModel(settings, id); } } }; /** * @param {?} configDefaults * @return {?} */ Config.prototype.setDefaults = /** * @param {?} configDefaults * @return {?} */ function (configDefaults) { /** @type {?} */ var self = this; self._defaults = configDefaults; Object.keys(configDefaults).forEach((/** * @param {?} k * @return {?} */ function (k) { self.set(k, Util.copy(configDefaults[k])); })); }; /** * @return {?} */ Config.prototype.restoreDefaults = /** * @return {?} */ function () { /** @type {?} */ var self = this; Object.keys(self._defaults).forEach((/** * @param {?} k * @return {?} */ function (k) { self.set(k, self._defaults[k]); })); }; /** * @param {?} key * @return {?} */ Config.prototype.islocked = /** * @param {?} key * @return {?} */ function (key) { /** @type {?} */ var boolean = false; this._locked.forEach((/** * @param {?} k * @return {?} */ function (k) { if (k === key) { boolean = true; } })); return boolean; }; // todo // todo /** * @param {?} key * @return {?} */ Config.prototype.lock = // todo /** * @param {?} key * @return {?} */ function (key) { // todo: return false; // this._locked.forEach((k) => { // // }) }; /** * @param {?} key * @return {?} */ Config.prototype.unLock = /** * @param {?} key * @return {?} */ function (key) { // todo: // this._locked.forEach((k) => { // // }) }; /** * @param {?} object * @return {?} */ Config.prototype.initXdomain = /** * @param {?} object * @return {?} */ function (object) { if (typeof window !== 'undefined' && window['xdomain']) { window['xdomain'].masters(object.masters); window['xdomain'].slaves(object.slaves); } }; return Config; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ var singleton = Symbol(); /** @type {?} */ var singletonEnforcer = Symbol(); var ConfigService = /** @class */ (function (_super) { __extends(ConfigService, _super); function ConfigService(enforcer) { var _this = _super.call(this) || this; if (enforcer !== singletonEnforcer) { throw new Error('Cannot construct singleton'); } _this._type = 'ConfigService'; return _this; } Object.defineProperty(ConfigService, "instance", { get: /** * @return {?} */ function () { if (!this[singleton]) { this[singleton] = new ConfigService(singletonEnforcer); } return this[singleton]; }, enumerable: true, configurable: true }); Object.defineProperty(ConfigService.prototype, "type", { get: /** * @return {?} */ function () { return this._type; }, set: /** * @param {?} value * @return {?} */ function (value) { this._type = value; }, enumerable: true, configurable: true }); return ConfigService; }(Config)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ var configDefaults = { id: 'ema-js-base', name: 'ema-js-base', authenticated: false, version: '0.1.1', domain: 'ema-js-base.firebaseapp.com', baseUrl: 'https://ema-js-base.firebaseapp.com/', baseRoot: 'https://ema-js-base.firebaseapp.com', api_headers: [ { 'Content-Type': 'application/json;charset=utf-8' } ], language: 'en', languages: [ { key: 'nl', value: 'Nederlands' }, { key: 'en', value: 'English' }, ], roles: { ANONYMOUS: [ { "actions": ["read"], "subject": ["all"] }, { "actions": ["login"], "subject": ["user"] } ], AUTHENTICATED: [ { "actions": ["logout"], "subject": ["user"] } ], EDITOR: [ { "actions": ["create", "read", "update", "delete"], "subject": ["all"] } ], DEVELOPER: [ { "actions": ["create", "read", "update", "delete", "debug"], "subject": ["all"] } ], ADMINISTRATOR: [ { "actions": ["create", "read", "update", "delete", "administrate"], "subject": ["all"] }, { "actions": ["create", "read", "update", "delete"], "subject": ["user"] } ], OWNER: [ { "actions": ["create", "read", "update", "delete", "administrate", "debug", "autoLogin", "fetchCredentials"], "subject": ["all"] }, { "actions": ["create", "read", "update", "delete"], "subject": ["user"] } ] }, firebaseApps: { 'ema-js-base': { apiKey: "AIzaSyDQuSusOA5HNwIUoyViVOPwEWbGXWt91p4", authDomain: "ema-js-base.firebaseapp.com", databaseURL: "https://ema-js-base.firebaseio.com", projectId: "ema-js-base", storageBucket: "ema-js-base.appspot.com", messagingSenderId: "419979785648" }, 'app-base': { apiKey: "AIzaSyDds578OH_xcxGw7QiTDOCdweLRSBEyxng", authDomain: "app-base.firebaseapp.com", databaseURL: "https://app-base.firebaseio.com", projectId: "app-base-dce3f", storageBucket: "app-base-dce3f.appspot.com", messagingSenderId: "271464035830" } }, drupal: { domain: 'local.streamer.nl:8888', protocol: 'http:', app_uuid: '319e0e50-5f1b-4b76-8798-3f89da31dd12', }, wordpress: { host: 'wordpress-dev:8888', protocol: 'http:', base_path: '/', }, }; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ var en = { "ADD": "Add", "ADDRESS": "Address", "ADMIN": "Administration", "CANCEL": "Cancel", "CHANGE LANGUAGE": "Change language", "CLOSE": "Close", "CONFIRM": "Confirm", "CONFIRM WARNING": "This action cannot be undone", "CONTACT": "Contact", "COUNTRY": "Country", "CREATE": "Create", "CURRENT": "Current", "DATA": "Data", "DATE": "Date", "DATE_NTH": { "1": "{day} January {year}", "2": "{day} February {year}", "3": "{day} March {year}", "4": "{day} April {year}", "5": "{day} May {year}", "6": "{day} June {year}", "7": "{day} July {year}", "8": "{day} August {year}", "9": "{day} September {year}", "10": "{day} October {year}", "11": "{day} November {year}", "12": "{day} December {year}" }, "DATE_MONTH_NTH": { "1": "January", "2": "February", "3": "March", "4": "April", "5": "May", "6": "June", "7": "July", "8": "August", "9": "September", "10": "October", "11": "November", "12": "December" }, "DELETE": "Delete", "DELETE CONFIRM": "Are you sure you want to delete this item", "DELETE CONFIRM MULTIPLE": "Are you sure you want to delete these items", "DETAIL": "Detail", "DETAILS": "Details", "EDIT": "Edit", "EMAIL": "E-mail", "EMAIL ADDRESS": "E-mail address", "EMAIL ERROR": "This is not a valid email address", "ERROR": "Error", "FIELD": "Field", "FIELD REQUIRED": "This field is required", "FORM INVALID": "The form can not be submitted yet. Please fill in the required fields", "FORM SUCCESS": "The data have been stored", "LANGUAGE": "Language", "LOGIN": "Login", "LOGIN ERROR": "The credentials you provided are not valid", "LOGIN EXPIRED": "Your autho