@itwin/clash-detection-client
Version:
Clash Detection client for the iTwin platform
67 lines • 2.73 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { Constants } from "../Constants";
export class OperationsBase {
constructor(_options) {
this._options = _options;
}
async sendGetRequest(params) {
return this._options.restClient.sendGetRequest({
url: params.url,
headers: await this.formHeaders(params),
});
}
async sendPostRequest(params) {
return this._options.restClient.sendPostRequest({
url: params.url,
body: params.body,
headers: await this.formHeaders({ ...params, containsBody: true }),
});
}
async sendPutRequest(params) {
return this._options.restClient.sendPutRequest({
url: params.url,
body: params.body,
headers: await this.formHeaders({ ...params, containsBody: true }),
});
}
async sendDeleteRequest(params) {
return this._options.restClient.sendDeleteRequest({
url: params.url,
headers: await this.formHeaders(params),
});
}
async getEntityCollectionPage(params) {
const response = await this.sendGetRequest(params);
return {
entities: params.entityCollectionAccessor(response),
next: response._links.next
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
? async () => this.getEntityCollectionPage({ ...params, url: response._links.next.href })
: undefined,
};
}
async formHeaders(params) {
const headers = {};
if (params.accessToken) {
headers[Constants.headers.authorization] = params.accessToken;
}
else if (this._options.accessTokenCallback) {
headers[Constants.headers.authorization] = await this._options.accessTokenCallback();
}
headers[Constants.headers.accept] = `application/vnd.bentley.${this._options.api.version}+json`;
if (params.preferReturn) {
headers[Constants.headers.prefer] = `return=${params.preferReturn}`;
}
if (params.containsBody) {
headers[Constants.headers.contentType] = Constants.headers.values.contentType;
}
if (params.userMetadata) {
headers[Constants.headers.userMetadata] = "true";
}
return headers;
}
}
//# sourceMappingURL=OperationsBase.js.map