@amplience/dc-cli
Version:
Dynamic Content CLI Tool
37 lines (36 loc) • 1.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContentHub = void 0;
const ApiClient_1 = require("./api/services/ApiClient");
const AxiosHttpClient_1 = require("./http/AxiosHttpClient");
const OAuth2Client_1 = require("./oauth2/services/OAuth2Client");
class ContentHub {
constructor(clientCredentials, damConfig, httpClient) {
damConfig = damConfig || {};
damConfig.apiUrl = damConfig.apiUrl || 'https://dam-api.amplience.net/v1.5.0';
damConfig.authUrl = damConfig.authUrl || 'https://auth.amplience.net';
let httpClientInstance;
if (httpClient !== undefined && 'request' in httpClient) {
httpClientInstance = httpClient;
}
else {
httpClientInstance = new AxiosHttpClient_1.AxiosHttpClient(httpClient === undefined ? {} : httpClient);
}
const tokenClient = this.createTokenClient(damConfig, clientCredentials, httpClientInstance);
this.client = this.createResourceClient(damConfig, tokenClient, httpClientInstance);
this.initEndpoints();
}
createTokenClient(damConfig, clientCredentials, httpClient) {
return new OAuth2Client_1.OAuth2Client(clientCredentials, {
authUrl: damConfig.authUrl
}, httpClient);
}
createResourceClient(damConfig, tokenProvider, httpClient) {
return new ApiClient_1.DefaultApiClient(damConfig.apiUrl, httpClient, tokenProvider);
}
initEndpoints() {
this.assets = this.client.endpoints.assets;
this.settings = this.client.endpoints.settings;
}
}
exports.ContentHub = ContentHub;