@dasch-swiss/dsp-js
Version:
JavaScript library that handles API requests to Knora
53 lines • 2.06 kB
JavaScript
/**
* Configuration to instantiate a `KnoraApiConnection`.
*
* @category Config
*/
var KnoraApiConfig = /** @class */ (function () {
/**
* @param apiProtocol the protocol of the API (http or https)
* @param apiHost the DSP-API base URL
* @param apiPort the port of DSP-API
* @param apiPath the base path following host and port, if any.
* @param jsonWebToken token to identify the user
* @param logErrors determines whether errors should be logged to the console
*/
function KnoraApiConfig(apiProtocol, apiHost, apiPort, apiPath, jsonWebToken, logErrors) {
if (apiPort === void 0) { apiPort = null; }
if (apiPath === void 0) { apiPath = ""; }
if (jsonWebToken === void 0) { jsonWebToken = ""; }
if (logErrors === void 0) { logErrors = false; }
this.apiProtocol = apiProtocol;
this.apiHost = apiHost;
this.apiPort = apiPort;
this.apiPath = apiPath;
this.jsonWebToken = jsonWebToken;
this.logErrors = logErrors;
// Remove port in case it's the default one
if (apiProtocol === KnoraApiConfig.PROTOCOL_HTTP && apiPort === KnoraApiConfig.DEFAULT_PORT_HTTP) {
this.apiPort = null;
}
else if (apiProtocol === KnoraApiConfig.PROTOCOL_HTTPS && apiPort === KnoraApiConfig.DEFAULT_PORT_HTTPS) {
this.apiPort = null;
}
}
Object.defineProperty(KnoraApiConfig.prototype, "apiUrl", {
/**
* The full API URL
*/
get: function () {
return ((this.apiProtocol + "://" + this.apiHost) +
(this.apiPort !== null ? ":" + this.apiPort : "") +
this.apiPath);
},
enumerable: false,
configurable: true
});
KnoraApiConfig.PROTOCOL_HTTP = "http";
KnoraApiConfig.PROTOCOL_HTTPS = "https";
KnoraApiConfig.DEFAULT_PORT_HTTP = 80;
KnoraApiConfig.DEFAULT_PORT_HTTPS = 443;
return KnoraApiConfig;
}());
export { KnoraApiConfig };
//# sourceMappingURL=knora-api-config.js.map