UNPKG

@itwin/insights-client

Version:

Insights client for the iTwin platform

70 lines 3.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EC3ConfigurationsClient = void 0; const Errors_1 = require("../../common/Errors"); const EntityListIteratorImpl_1 = require("../../common/iterators/EntityListIteratorImpl"); const IteratorUtil_1 = require("../../common/iterators/IteratorUtil"); const OperationsBase_1 = require("../../common/OperationsBase"); class EC3ConfigurationsClient extends OperationsBase_1.OperationsBase { constructor(basePath) { super(basePath ?? OperationsBase_1.CARBON_CALCULATION_BASE_PATH); } async getConfigurations(accessToken, projectId, top) { const configurations = []; const configIterator = this.getConfigurationsIterator(accessToken, projectId, top); for await (const config of configIterator) { configurations.push(config); } return configurations; } getConfigurationsIterator(accessToken, projectId, top) { if (!this.topIsValid(top)) { throw new Errors_1.RequiredError("top", "Parameter top was outside of the valid range [1-1000]."); } let url = `${this.basePath}/ec3/configurations?iTwinId=${projectId}`; url += top ? `&$top=${top}` : ""; const request = this.createRequest("GET", accessToken); return new EntityListIteratorImpl_1.EntityListIteratorImpl(async () => (0, IteratorUtil_1.getEntityCollectionPage)(url, async (nextUrl) => { const response = await this.fetchJSON(nextUrl, request); return { values: response.configurations, // eslint-disable-next-line @typescript-eslint/naming-convention _links: response._links, }; })); } async getConfiguration(accessToken, configurationId) { const url = `${this.basePath}/ec3/configurations/${configurationId}`; const requestOptions = this.createRequest("GET", accessToken); return (await this.fetchJSON(url, requestOptions)).configuration; } async createConfiguration(accessToken, configuration) { if (configuration.labels.length === 0) { throw new Errors_1.RequiredError("configuration", "Required field labels was empty."); } if (configuration.labels.some((x) => x.materials.length === 0)) { throw new Errors_1.RequiredError("configuration", "Required field materials was empty."); } const url = `${this.basePath}/ec3/configurations`; const requestOptions = this.createRequest("POST", accessToken, JSON.stringify(configuration)); return (await this.fetchJSON(url, requestOptions)).configuration; } async updateConfiguration(accessToken, configurationId, configuration) { if (configuration.labels.length === 0) { throw new Errors_1.RequiredError("configuration", "Required field labels was empty."); } if (configuration.labels.some((x) => x.materials.length === 0)) { throw new Errors_1.RequiredError("configuration", "Required field materials was empty."); } const url = `${this.basePath}/ec3/configurations/${configurationId}`; const requestOptions = this.createRequest("PUT", accessToken, JSON.stringify(configuration)); return (await this.fetchJSON(url, requestOptions)).configuration; } async deleteConfiguration(accessToken, configurationId) { const url = `${this.basePath}/ec3/configurations/${configurationId}`; const requestOptions = this.createRequest("DELETE", accessToken); return this.fetchJSON(url, requestOptions); } } exports.EC3ConfigurationsClient = EC3ConfigurationsClient; //# sourceMappingURL=EC3ConfigurationsClient.js.map