@itwin/itwins-client
Version:
iTwins client for the iTwin platform
189 lines • 7.78 kB
JavaScript
import { BaseClient } from "./BaseClient";
/** Client API to access the itwins service.
* @beta
*/
export class ITwinsAccessClient extends BaseClient {
constructor(url) {
super(url);
}
/** Get itwins accessible to the user
* @param accessToken The client access token string
* @param subClass Optional parameter to search a specific iTwin subClass
* @param arg Optional query arguments, for paging, searching, and filtering
* @returns Array of projects, may be empty
*/
async queryAsync(accessToken,
/**
* @deprecated in 2.0 This property is deprecated, and will be removed in the next major release. Please use `arg` to provide subClass instead.
*/
subClass, arg) {
const headers = this.getHeaders(arg);
let url = this._baseUrl;
// eslint-disable-next-line deprecation/deprecation
const query = this.getQueryStringArg(arg, subClass);
if (query !== "")
url += `?${query}`;
return this.sendGenericAPIRequest(accessToken, "GET", url, undefined, "iTwins", headers);
}
/** Create a new iTwin
* @param accessToken The client access token string
* @param iTwin The iTwin to be created
* @returns ITwin
*/
async createiTwin(accessToken, iTwin) {
const url = `${this._baseUrl}/`;
return this.sendGenericAPIRequest(accessToken, "POST", url, iTwin, "iTwin");
}
/** Update the specified iTwin
* @param accessToken The client access token string
* @param iTwinId The id of the iTwin
* @param iTwin The iTwin to be created
* @returns ITwin
*/
async updateiTwin(accessToken, iTwinId, iTwin) {
const url = `${this._baseUrl}/${iTwinId}`;
return this.sendGenericAPIRequest(accessToken, "PATCH", url, iTwin, "iTwin");
}
/** Delete the specified iTwin
* @param accessToken The client access token string
* @param iTwinId The id of the iTwin
* @returns No Content
*/
async deleteiTwin(accessToken, iTwinId) {
const url = `${this._baseUrl}/${iTwinId}`;
return this.sendGenericAPIRequest(accessToken, "DELETE", url);
}
/** Create a new iTwin Repository
* @param accessToken The client access token string
* @param iTwinId The id of the iTwin
* @param repository The Repository to be created
* @return Repository
*/
async createRepository(accessToken, iTwinId, repository) {
const url = `${this._baseUrl}/${iTwinId}/repositories`;
return this.sendGenericAPIRequest(accessToken, "POST", url, repository, "repository");
}
/** Delete the specified iTwin Repository
* @param accessToken The client access token string
* @param iTwinId The id of the iTwin
* @param repositoryId The id of the Repository
* @return No Content
*/
async deleteRepository(accessToken, iTwinId, repositoryId) {
const url = `${this._baseUrl}/${iTwinId}/repositories/${repositoryId}`;
return this.sendGenericAPIRequest(accessToken, "DELETE", url);
}
/** Get Repositories accessible to user
* @param accessToken The client access token string
* @param iTwinId The id of the iTwin
* @param arg Optional query arguments, for class and subclass
* @returns Array of Repositories, may be empty
*/
async queryRepositoriesAsync(accessToken, iTwinId, arg) {
let url = `${this._baseUrl}/${iTwinId}/repositories`;
const query = this.getRepositoryQueryString(arg);
if (query !== "") {
url += `?${query}`;
}
return this.sendGenericAPIRequest(accessToken, "GET", url, undefined, "repositories");
}
/** Get itwin accessible to the user
* @param accessToken The client access token string
* @param iTwinId The id of the iTwin
* @param resultMode (Optional) iTwin result mode: minimal or representation
* @returns Array of projects, may be empty
*/
async getAsync(accessToken, iTwinId, resultMode) {
const headers = this.getResultModeHeaders(resultMode);
const url = `${this._baseUrl}/${iTwinId}`;
return this.sendGenericAPIRequest(accessToken, "GET", url, undefined, "iTwin", headers);
}
/** Get itwins accessible to the user
* @param accessToken The client access token string
* @param subClass Optional parameter to search a specific iTwin subClass
* @param arg Optional query arguments, for paging, searching, and filtering
* @returns Array of projects, may be empty
*/
async queryFavoritesAsync(accessToken,
/**
* @deprecated in 2.0 This property is deprecated, and will be removed in the next major release. Please use `arg` to provide subClass instead.
*/
subClass, arg) {
const headers = this.getHeaders(arg);
let url = `${this._baseUrl}/favorites`;
// eslint-disable-next-line deprecation/deprecation
const query = this.getQueryStringArgBase(arg, subClass);
if (query !== "")
url += `?${query}`;
return this.sendGenericAPIRequest(accessToken, "GET", url, undefined, "iTwins", headers);
}
/** Get itwins accessible to the user
* @param accessToken The client access token string
* @param subClass Optional parameter to search a specific iTwin subClass
* @param arg Optional query arguments, for paging, searching, and filtering
* @returns Array of projects, may be empty
*/
async queryRecentsAsync(accessToken,
/**
* @deprecated in 2.0 This property is deprecated, and will be removed in the next major release. Please use `arg` to provide subClass instead.
*/
subClass, arg) {
const headers = this.getHeaders(arg);
let url = `${this._baseUrl}/recents`;
// eslint-disable-next-line deprecation/deprecation
const query = this.getQueryStringArgBase(arg, subClass);
if (query !== "")
url += `?${query}`;
return this.sendGenericAPIRequest(accessToken, "GET", url, undefined, "iTwins", headers);
}
/** Get primary account accessible to the user
* @returns Primary account
*/
async getPrimaryAccountAsync(accessToken) {
const url = `${this._baseUrl}/myprimaryaccount`;
return this.sendGenericAPIRequest(accessToken, "GET", url, undefined, "iTwin");
}
/**
* Gets the Account for the specified iTwin.
* @param accessToken The client access token string
* @param iTwinId The id of the iTwin
* @returns Account
*/
async getAccountAsync(accessToken, iTwinId, resultMode) {
const headers = this.getResultModeHeaders(resultMode);
const url = `${this._baseUrl}/${iTwinId}/account`;
return this.sendGenericAPIRequest(accessToken, "GET", url, undefined, "iTwin", headers);
}
/**
* Format headers from query arguments
* @param arg (Optional) iTwin query arguments
* @protected
*/
getHeaders(arg) {
return {
...this.getQueryScopeHeaders(arg && arg.queryScope),
...this.getResultModeHeaders(arg && arg.resultMode),
};
}
/**
* Format result mode parameter into a headers entry
* @param resultMode (Optional) iTwin result mode
* @protected
*/
getResultModeHeaders(resultMode = "minimal") {
return {
prefer: `return=${resultMode}`,
};
}
/**
* Format query scope parameter into a headers entry
* @param queryScope (Optional) iTwin query scope
* @protected
*/
getQueryScopeHeaders(queryScope = "memberOfItwin") {
return {
"x-itwin-query-scope": queryScope,
};
}
}
//# sourceMappingURL=iTwinsClient.js.map