UNPKG

contensis-management-api

Version:

Client for managing content using the Contensis Management API

60 lines (59 loc) 2.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ClientConfig = void 0; class ClientConfig { constructor(currentConfig, previousConfig) { this.currentConfig = currentConfig; this.previousConfig = previousConfig; this.rootUrl = null; this.clientType = null; this.clientDetails = null; this.defaultHeaders = null; this.projectId = null; this.language = null; this.versionStatus = 'latest'; this.pageIndex = 0; this.pageSize = 25; this.responseHandler = null; this.fetchFn = null; this.rootUrl = this.getValue((c) => c.rootUrl); this.clientType = this.getValue((c) => c.clientType); this.clientDetails = this.getValue((c) => c.clientDetails); this.defaultHeaders = this.getValue((c) => c.defaultHeaders); this.projectId = this.getValue((c) => c.projectId); this.language = this.getValue((c) => c.language); this.versionStatus = this.getValue((c) => c.versionStatus); this.pageIndex = this.getValue((c) => c.pageIndex); this.pageSize = this.getValue((c) => c.pageSize); this.responseHandler = this.getValue((c) => c.responseHandler); this.fetchFn = this.getValue((c) => c.fetchFn); while (this.rootUrl && this.rootUrl.substr(this.rootUrl.length - 1, 1) === '/') { this.rootUrl = this.rootUrl.substr(0, this.rootUrl.length - 1); } } toParams() { return { rootUrl: this.rootUrl, clientType: this.clientType, clientDetails: this.clientDetails, defaultHeaders: this.defaultHeaders, projectId: this.projectId, language: this.language, versionStatus: this.versionStatus, pageIndex: this.pageIndex, pageSize: this.pageSize, responseHandler: this.responseHandler }; } getValue(getter) { let result = null; if (this.currentConfig) { result = getter(this.currentConfig); } if (this.previousConfig && !result) { result = getter(this.previousConfig); } return result || getter(this); } } exports.ClientConfig = ClientConfig;