@datenkraft/bb-base-api-ts-client
Version:
The Base API TS Client package enables you to work with other Backbone TS Client packages.
69 lines (68 loc) • 2.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Config = void 0;
class Config {
constructor(configOptions) {
this._configOptions = configOptions;
this.verify();
}
get configOptions() {
return this._configOptions;
}
get clientId() {
return this.configOptions.clientId;
}
get clientSecret() {
return this.configOptions.clientSecret;
}
get oAuthTokenHost() {
var _a, _b;
return ((_b = (_a = this.configOptions.oAuthTokenHost) !== null && _a !== void 0 ? _a : process.env.X_DATENKRAFT_OAUTH_TOKEN_HOST) !== null && _b !== void 0 ? _b : 'https://authentication-api.conqore.niceshops.com');
}
get authenticationApiUrl() {
var _a, _b;
return ((_b = (_a = this.configOptions.authenticationApiUrl) !== null && _a !== void 0 ? _a : process.env.X_DATENKRAFT_AUTHENTICATION_API_URL) !== null && _b !== void 0 ? _b : 'https://authentication-api.conqore.niceshops.com/v1');
}
get tokenTradeInPath() {
var _a;
return (_a = this.configOptions.tokenTradeInPath) !== null && _a !== void 0 ? _a : '/auth/token-trade-in';
}
get externalIdToken() {
return this.configOptions.externalIdToken;
}
get useExternalIdToken() {
var _a;
return (_a = this.configOptions.useExternalIdToken) !== null && _a !== void 0 ? _a : false;
}
get authToken() {
return this.configOptions.authToken;
}
get useAuthToken() {
var _a;
return (_a = this.configOptions.useAuthToken) !== null && _a !== void 0 ? _a : false;
}
verify() {
if (this.useAuthToken) {
if (this.useExternalIdToken) {
throw new Error('Cannot use authToken and externalIdToken together.');
}
if (!this.authToken) {
throw new Error('Missing the authToken option.');
}
}
else if (this.useExternalIdToken) {
if (!this.externalIdToken) {
throw new Error('Missing the externalIdToken option.');
}
}
else {
if (!this.clientId) {
throw new Error('Missing the clientId option.');
}
if (!this.clientSecret) {
throw new Error('Missing the clientSecret option.');
}
}
}
}
exports.Config = Config;