@dasch-swiss/dsp-js
Version:
TypeScript client library for DSP-API
41 lines • 1.59 kB
JavaScript
/**
* Configuration to instantiate a `KnoraApiConnection`.
*
* @category Config
*/
export class KnoraApiConfig {
static { this.PROTOCOL_HTTP = 'http'; }
static { this.PROTOCOL_HTTPS = 'https'; }
static { this.DEFAULT_PORT_HTTP = 80; }
static { this.DEFAULT_PORT_HTTPS = 443; }
/**
* The full API URL
*/
get apiUrl() {
return `${this.apiProtocol}://${this.apiHost}${this.apiPort !== null ? `:${this.apiPort}` : ''}${this.apiPath}`;
}
/**
* @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
*/
constructor(apiProtocol, apiHost, apiPort = null, apiPath = '', jsonWebToken = '', 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;
}
}
}
//# sourceMappingURL=knora-api-config.js.map