UNPKG

@itwin/itwins-client

Version:

iTwins client for the iTwin platform

692 lines 34.5 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module iTwinsClient */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ITwinsClient = void 0; const BaseITwinsApiClient_js_1 = require("./BaseITwinsApiClient.js"); /** Client API to access the iTwins service. * @beta */ class ITwinsClient extends BaseITwinsApiClient_js_1.BaseITwinsApiClient { constructor(url, maxRedirects) { super(url, maxRedirects); } /** Get a list of iTwin exports for the current user * @param accessToken The client access token string * @returns Promise that resolves with an array of export operations */ async getExports(accessToken) { const url = `${this._baseUrl}/exports`; return this.sendGenericAPIRequest(accessToken, "GET", url); } /** Get details of a specific iTwin export operation * @param accessToken The client access token string * @param id The id of the export operation to retrieve * @returns Promise that resolves with the export operation details */ async getExport(accessToken, id) { const url = `${this._baseUrl}/exports/${id}`; return this.sendGenericAPIRequest(accessToken, "GET", url); } /** * Create a new iTwin export * @param accessToken The client access token string * @param args Export query arguments including scope, filters, and output format * @returns Export response with operation details */ async createExport(accessToken, args) { const url = `${this._baseUrl}/exports`; return this.sendGenericAPIRequest(accessToken, "POST", url, args, undefined); } /** Get favorites iTwins accessible to the user * @param accessToken The client access token string * @param arg Optional query arguments, for paging, searching, and filtering * @returns Array of iTwins, may be empty, if no favorites * @example * ```typescript * // Returns MultiITwinMinimalResponse * const minimal = await client.getFavoritesITwins(token, { resultMode: "minimal" }); * * // Returns MultiITwinRepresentationResponse * const detailed = await client.getFavoritesITwins(token, { resultMode: "representation" }); * * // Defaults to minimal when no resultMode specified * const defaultResult = await client.getFavoritesITwins(token); * ``` */ async getFavoritesITwins(accessToken, arg) { const headers = this.getHeaders(arg); const url = `${this._baseUrl}/favorites/?${this.getQueryStringArg(ITwinsClient.iTwinsQueryParamMapping, arg !== null && arg !== void 0 ? arg : {})}`; return this.sendGenericAPIRequest(accessToken, "GET", url, undefined, headers); } /** Add the specified iTwin to the user's favorites list * @param accessToken The client access token string * @param iTwinId The id of the iTwin to add to favorites * @returns Promise that resolves when the iTwin is successfully added to favorites */ async addITwinToFavorites(accessToken, iTwinId) { const url = `${this._baseUrl}/favorites/${iTwinId}`; return this.sendGenericAPIRequest(accessToken, "POST", url); } /** Remove the specified iTwin from the user's favorites list * @param accessToken The client access token string * @param iTwinId The id of the iTwin to remove from favorites * @returns Promise that resolves when the iTwin is successfully removed from favorites */ async removeITwinFromFavorites(accessToken, iTwinId) { const url = `${this._baseUrl}/favorites/${iTwinId}`; return this.sendGenericAPIRequest(accessToken, "DELETE", url); } /** Upload an image to the specified iTwin * @param accessToken The client access token string * @param iTwinId The id of the iTwin to upload the image to * @param imageBlob The image file as a Blob (must be PNG or JPEG) * @param contentType The content type of the image ("image/png" | "image/jpeg") * @returns Promise that resolves with the uploaded image details including URLs for small and large versions */ async uploadITwinImage(accessToken, iTwinId, imageBlob, contentType) { const url = `${this._baseUrl}/${iTwinId}/image`; return this.sendGenericAPIRequest(accessToken, "PUT", url, imageBlob, { contentType, }); } /** Get the image associated with the specified iTwin * @param accessToken The client access token string * @param iTwinId The id of the iTwin to retrieve the image from * @returns Promise that resolves with the image details including URLs for small and large versions */ async getITwinImage(accessToken, iTwinId) { const url = `${this._baseUrl}/${iTwinId}/image`; return this.sendGenericAPIRequest(accessToken, "GET", url); } /** Delete the image associated with the specified iTwin * @param accessToken The client access token string * @param iTwinId The id of the iTwin to delete the image from * @returns Promise that resolves when the image is successfully deleted */ async deleteITwinImage(accessToken, iTwinId) { const url = `${this._baseUrl}/${iTwinId}/image`; return this.sendGenericAPIRequest(accessToken, "DELETE", url); } /** Add the specified iTwin to the user's recently used list * @param accessToken The client access token string * @param iTwinId The id of the iTwin to add to the recently used list * @returns Promise that resolves when the iTwin is successfully added to the recently used list */ async addITwinToMyRecents(accessToken, iTwinId) { const url = `${this._baseUrl}/recents/${iTwinId}`; return this.sendGenericAPIRequest(accessToken, "POST", url); } /** Get recently used iTwins for the current user * * Retrieves a list of recently used iTwins for the calling user. A user can only have 25 recently used iTwins. * They are returned in order with the most recently used iTwin first in the list. * * iTwins with status=Inactive are not returned by default. This improves query performance and reduces clutter * in user interfaces by filtering out unused iTwins. You should still provide a way for users to see their * Inactive iTwins if they request them. In the API, you can do this by setting the status parameter or by * using the includeInactive parameter. * * @param accessToken The client access token string * @param arg Optional query arguments, for paging, searching, and filtering (including status and includeInactive) * @returns Promise that resolves with an array of recently used iTwins (maximum 25), ordered by most recent first * @example * ```typescript * // Returns MultiITwinMinimalResponse * const minimal = await client.getRecentUsedITwins(token, { resultMode: "minimal" }); * * // Returns MultiITwinRepresentationResponse * const detailed = await client.getRecentUsedITwins(token, { resultMode: "representation" }); * * // Defaults to minimal when no resultMode specified * const defaultResult = await client.getRecentUsedITwins(token); * ``` */ async getRecentUsedITwins(accessToken, arg) { const headers = this.getHeaders(arg); let url = `${this._baseUrl}/recents`; const query = this.getQueryStringArg(ITwinsClient.iTwinsQueryParamMapping, arg !== null && arg !== void 0 ? arg : {}); if (query !== "") url += `?${query}`; return this.sendGenericAPIRequest(accessToken, "GET", url, undefined, headers); } /** Get global repositories accessible to user with optional filtering * @param accessToken The client access token string * @param arg Optional query arguments for repository class and subClass identifiers. If subClass is specified, class is also required. * @returns Promise that resolves with an array of global repositories, may be empty * @beta */ async getGlobalRepositories(accessToken, arg) { let url = `${this._baseUrl}/repositories`; const query = this.getQueryStringArg(ITwinsClient.repositoryParamMapping, arg); if (query !== "") { url += `?${query}`; } return this.sendGenericAPIRequest(accessToken, "GET", url); } /** Get a specific global repository by ID * @param accessToken The client access token string * @param repositoryId The id of the global repository * @returns Promise that resolves with the global repository details * @beta */ async getGlobalRepository(accessToken, repositoryId) { const url = `${this._baseUrl}/repositories/${repositoryId}`; return this.sendGenericAPIRequest(accessToken, "GET", url); } /** Get a specific global repository resource by ID * @param accessToken The client access token string for authorization * @param repositoryId The id of the global repository containing the resource * @param resourceId The unique id of the global repository resource to retrieve * @param resultMode Optional result mode controlling the level of detail returned (minimal or representation) * @returns Promise that resolves with the global repository resource details in the requested format * @example * ```typescript * // Returns GetRepositoryResourceMinimalResponse * const minimal = await client.getGlobalRepositoryResource(token, "1234", "3954", "minimal"); * * // Returns GetRepositoryResourceRepresentationResponse * const detailed = await client.getGlobalRepositoryResource(token, "1234", "3954", "representation"); * * // Defaults to minimal when no resultMode specified * const defaultResult = await client.getGlobalRepositoryResource(token, "1234", "3954"); * ``` * @beta */ async getGlobalRepositoryResource(accessToken, repositoryId, resourceId, resultMode) { const headers = this.getResultModeHeaders(resultMode); const url = `${this._baseUrl}/repositories/${repositoryId}/resources/${resourceId}`; return this.sendGenericAPIRequest(accessToken, "GET", url, undefined, headers, true); } /** Get multiple global repository resources with optional filtering and pagination * @param accessToken The client access token string for authorization * @param repositoryId The id of the global repository containing the resources * @param args Optional query parameters for search, pagination (skip, top) * @param resultMode Optional result mode controlling the level of detail returned (minimal or representation) * @returns Promise that resolves with an array of global repository resources in the requested format * @example * ```typescript * // Returns GetMultiRepositoryResourceMinimalResponse * const minimal = await client.getGlobalRepositoryResources(token, "cesium", undefined, "minimal"); * * // Returns GetMultiRepositoryResourceRepresentationResponse * const detailed = await client.getGlobalRepositoryResources(token, "cesium", { top: 10 }, "representation"); * * // Defaults to minimal when no resultMode specified * const defaultResult = await client.getGlobalRepositoryResources(token, "cesium"); * ``` * @beta */ async getGlobalRepositoryResources(accessToken, repositoryId, args, resultMode) { const headers = this.getResultModeHeaders(resultMode); let url = `${this._baseUrl}/repositories/${repositoryId}/resources`; const query = this.getQueryStringArg(ITwinsClient.ODataParamMapping, args); if (query !== "") { url += `?${query}`; } return this.sendGenericAPIRequest(accessToken, "GET", url, undefined, headers, true); } /** Get graphics metadata for a global repository resource * @param accessToken The client access token string for authorization * @param repositoryId The global repository identifier * @param resourceId The resource identifier * @returns Promise that resolves with graphics metadata including content type, URI, and authentication * @example * ```typescript * const graphics = await client.getGlobalResourceGraphics(token, "cesium", "3954"); * ``` * @beta */ async getGlobalResourceGraphics(accessToken, repositoryId, resourceId) { const url = `${this._baseUrl}/repositories/${repositoryId}/resources/${resourceId}/graphics`; return this.sendGenericAPIRequest(accessToken, "GET", url, undefined, undefined, true); } /** Create a new iTwin Repository * @param accessToken The client access token string * @param iTwinId The id of the iTwin * @param repository The Repository data to be created * @returns Promise that resolves with the created repository details * @beta */ async createRepository(accessToken, iTwinId, repository) { const url = `${this._baseUrl}/${iTwinId}/repositories`; return this.sendGenericAPIRequest(accessToken, "POST", url, 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 to delete * @returns Promise that resolves when the repository is successfully deleted */ async deleteRepository(accessToken, iTwinId, repositoryId) { const url = `${this._baseUrl}/${iTwinId}/repositories/${repositoryId}`; return this.sendGenericAPIRequest(accessToken, "DELETE", url); } /** Get repositories accessible to user with optional filtering * @param accessToken The client access token string * @param iTwinId The id of the iTwin * @param arg Optional query arguments for repository class and subClass identifiers. If subClass is specified, class is also required. * @returns Promise that resolves with an array of repositories, may be empty */ async getRepositories(accessToken, iTwinId, arg) { const url = `${this._baseUrl}/${iTwinId}/repositories/?${this.getQueryStringArg(ITwinsClient.repositoryParamMapping, arg)}`; return this.sendGenericAPIRequest(accessToken, "GET", url); } /** Get a specific repository by ID * @param accessToken The client access token string * @param iTwinId The id of the iTwin * @param repositoryId The id of the Repository * @returns Promise that resolves with the repository details * @beta */ async getRepository(accessToken, iTwinId, repositoryId) { const url = `${this._baseUrl}/${iTwinId}/repositories/${repositoryId}`; return this.sendGenericAPIRequest(accessToken, "GET", url); } /** Update 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 * @param repository Updated repository data (excluding id, class, and subClass) * @returns Promise that resolves with the updated repository * @beta */ async updateRepository(accessToken, iTwinId, repositoryId, repository) { const url = `${this._baseUrl}/${iTwinId}/repositories/${repositoryId}`; return this.sendGenericAPIRequest(accessToken, "PATCH", url, repository); } /** * Create a repository resource for a repository that exposes a resources collection * @param accessToken - The client access token string for authorization * @param iTwinId - The id of the iTwin that contains the repository * @param repositoryId - The id of the repository to add the resource to * @param repositoryResource - The repository resource to create with required id and displayName properties * @returns Promise that resolves with the created repository resource details * * @beta */ async createRepositoryResource(accessToken, iTwinId, repositoryId, repositoryResource) { const url = `${this._baseUrl}/${iTwinId}/repositories/${repositoryId}/resources`; return this.sendGenericAPIRequest(accessToken, "POST", url, repositoryResource); } /** * Delete a repository resource * @param accessToken - The client access token string for authorization * @param iTwinId - The id of the iTwin that contains the repository * @param repositoryId - The id of the repository that contains the resource * @param resourceId - The id repository resource to delete * @returns Promise that resolves when the iTwin is successfully deleted * * @beta */ async deleteRepositoryResource(accessToken, iTwinId, repositoryId, resourceId) { const url = `${this._baseUrl}/${iTwinId}/repositories/${repositoryId}/resources/${resourceId}`; return this.sendGenericAPIRequest(accessToken, "DELETE", url); } /** * Get a specific repository resource by ID * * Automatically follows 302 redirects to federated repository endpoints when the repository * uses a federated architecture. Authentication headers are forwarded transparently. * * @param accessToken - The client access token string for authorization * @param iTwinId - The id of the iTwin that contains the repository * @param repositoryId - The id of the repository containing the resource * @param resourceId - The unique id of the repository resource to retrieve * @param resultMode - Optional result mode controlling the level of detail returned (minimal or representation) * @returns Promise that resolves with the repository resource details in the requested format * @example * ```typescript * // Returns GetRepositoryResourceMinimalResponse * const minimal = await client.getRepositoryResource(token, "iTwinId", "repoId", "resourceId", "minimal"); * * // Returns GetRepositoryResourceRepresentationResponse * const detailed = await client.getRepositoryResource(token, "iTwinId", "repoId", "resourceId", "representation"); * * // Defaults to minimal when no resultMode specified * const defaultResult = await client.getRepositoryResource(token, "iTwinId", "repoId", "resourceId"); * ``` * @beta */ async getRepositoryResource(accessToken, iTwinId, repositoryId, resourceId, resultMode) { const headers = this.getResultModeHeaders(resultMode); const url = `${this._baseUrl}/${iTwinId}/repositories/${repositoryId}/resources/${resourceId}`; return this.sendGenericAPIRequest(accessToken, "GET", url, undefined, headers, true); } /** * Get multiple repository resources with optional filtering and pagination * * Automatically follows 302 redirects to federated repository endpoints when the repository * uses a federated architecture. Authentication headers are forwarded transparently. * * @param accessToken - The client access token string for authorization * @param iTwinId - The id of the iTwin that contains the repository * @param repositoryId - The id of the repository containing the resources * @param args - Optional query parameters for search, pagination (skip, top) * @param resultMode - Optional result mode controlling the level of detail returned (minimal or representation) * @returns Promise that resolves with an array of repository resources in the requested format * @example * ```typescript * // Returns GetMultiRepositoryResourceMinimalResponse * const minimal = await client.getRepositoryResources(token, "iTwinId", "repoId", undefined, "minimal"); * * // Returns GetMultiRepositoryResourceRepresentationResponse * const detailed = await client.getRepositoryResources(token, "iTwinId", "repoId", { search: "test" }, "representation"); * * // Defaults to minimal when no resultMode specified * const defaultResult = await client.getRepositoryResources(token, "iTwinId", "repoId"); * ``` * @beta */ async getRepositoryResources(accessToken, iTwinId, repositoryId, args, resultMode) { const headers = this.getResultModeHeaders(resultMode); const url = `${this._baseUrl}/${iTwinId}/repositories/${repositoryId}/resources?${this.getQueryStringArg(ITwinsClient.ODataParamMapping, args)}`; return this.sendGenericAPIRequest(accessToken, "GET", url, undefined, headers, true); } /** * Get a list of resources from a repository using a capability URI * * This method enables direct calls to federated repository endpoints using URIs from * repository capabilities. * * @param accessToken - The client access token string for authorization * @param uri - The capability URI from repository.capabilities.resources.uri * @param args - Optional OData query parameters for filtering and pagination * @param resultMode - Optional result mode controlling the level of detail returned (minimal or representation) * @returns Promise that resolves with the list of repository resources in the requested format * @example * ```typescript * // Get repository with capabilities * const repo = await client.getRepository(token, iTwinId, repositoryId); * * // Extract capability URI * const resourcesUri = repo.data?.repository.capabilities?.resources?.uri; * * if (resourcesUri) { * // Returns GetMultiRepositoryResourceMinimalResponse * const minimal = await client.getRepositoryResourcesByUri(token, resourcesUri, undefined, "minimal"); * * // Returns GetMultiRepositoryResourceRepresentationResponse * const detailed = await client.getRepositoryResourcesByUri(token, resourcesUri, undefined, "representation"); * * // Defaults to minimal when no resultMode specified * const defaultResult = await client.getRepositoryResourcesByUri(token, resourcesUri); * } * ``` * @beta */ async getRepositoryResourcesByUri(accessToken, uri, args, resultMode) { const headers = this.getResultModeHeaders(resultMode); const urlWithQuery = args ? `${uri}?${this.getQueryStringArg(ITwinsClient.ODataParamMapping, args)}` : uri; return this.sendGenericAPIRequest(accessToken, "GET", urlWithQuery, undefined, headers, true); } /** * Get a specific resource from a repository using a capability URI * * This method enables direct calls to federated repository endpoints using URIs from * repository capabilities. * * @param accessToken - The client access token string for authorization * @param uri - The capability URI from repository.capabilities.resources.uri for a specific resource * @param resultMode - Optional result mode controlling the level of detail returned (minimal or representation) * @returns Promise that resolves with the repository resource details in the requested format * @example * ```typescript * // Get repository with capabilities * const repo = await client.getRepository(token, iTwinId, repositoryId); * * // Construct resource URI (typically from a previous query or known resource ID) * const baseUri = repo.data?.repository.capabilities?.resources?.uri; * const resourceUri = `${baseUri}/resourceId`; * * if (resourceUri) { * // Returns GetRepositoryResourceMinimalResponse * const minimal = await client.getRepositoryResourceByUri(token, resourceUri, "minimal"); * * // Returns GetRepositoryResourceRepresentationResponse * const detailed = await client.getRepositoryResourceByUri(token, resourceUri, "representation"); * * // Defaults to minimal when no resultMode specified * const defaultResult = await client.getRepositoryResourceByUri(token, resourceUri); * } * ``` * @beta */ async getRepositoryResourceByUri(accessToken, uri, resultMode) { const headers = this.getResultModeHeaders(resultMode); return this.sendGenericAPIRequest(accessToken, "GET", uri, undefined, headers, true); } /** * Retrieves graphics metadata for a specific repository resource using ID-based parameters. * * * Returns graphics content URIs and authentication information needed to access visualization data * for a resource. The response includes content type, access URI, optional authentication credentials, * and CesiumJS provider configuration when applicable. This method supports redirect-based routing to * federated graphics services. * * For federated architecture support, consider using getResourceGraphicsByUri with the URI * from resource.capabilities.graphics.uri instead. * * @param accessToken - The client access token string for authorization * @param iTwinId - The iTwin identifier * @param repositoryId - The repository identifier * @param resourceId - The resource identifier * @returns Promise that resolves with graphics metadata including content type, URI, and authentication * @example * ```typescript * // Get graphics for a specific resource * const graphics = await client.getResourceGraphics( * token, * 'itwin-id', * 'imodels', * 'imodel-resource-id' * ); * * if (graphics.data) { * graphics.data.graphics.forEach(graphic => { * console.log('Content type:', graphic.type); * console.log('Graphics URI:', graphic.uri); * * // Handle authentication if present * if (graphic.authentication) { * switch (graphic.authentication.type) { * case 'Header': * case 'QueryParameter': * console.log('Auth key:', graphic.authentication.key); * break; * case 'Basic': * console.log('Username:', graphic.authentication.username); * break; * } * } * }); * } * ``` * @beta */ async getResourceGraphics(accessToken, iTwinId, repositoryId, resourceId) { const url = `${this._baseUrl}/${iTwinId}/repositories/${repositoryId}/resources/${resourceId}/graphics`; return this.sendGenericAPIRequest(accessToken, "GET", url, undefined, undefined, true); } /** * Get graphics metadata for a repository resource using a capability URI * * This method enables direct calls to federated graphics endpoints using URIs from * resource capabilities. Instead of constructing URLs from iTwinId, repositoryId, and * resourceId, it accepts the URI directly from capabilities.graphics.uri. * * Note: This method requires that the resource supports graphics capabilities and that * the access token has appropriate permissions for the target graphics service. * * @param accessToken - The client access token string for authorization * @param uri - The capability URI from resource.capabilities.graphics.uri * @returns Promise that resolves with the graphics metadata including authentication and provider information * @example * ```typescript * // Get resource with graphics capability * const resource = await client.getRepositoryResource(token, iTwinId, repositoryId, resourceId); * * // Extract graphics capability URI * const graphicsUri = resource.data?.resource.capabilities?.graphics?.uri; * * if (graphicsUri) { * const graphics = await client.getResourceGraphicsByUri(token, graphicsUri); * * if (graphics.data) { * console.log('Graphics content type:', graphics.data.graphics.contentType); * console.log('Graphics URI:', graphics.data.graphics.uri); * } * } * ``` * @beta */ async getResourceGraphicsByUri(accessToken, uri) { return this.sendGenericAPIRequest(accessToken, "GET", uri, undefined, undefined, true); } /** Get a specific iTwin by ID * @param accessToken The client access token string * @param iTwinId The id of the iTwin * @param resultMode (Optional) iTwin result mode: minimal or representation * @returns Promise that resolves with the iTwin details * @example * ```typescript * // Returns ITwinMinimalResponse * const minimal = await client.getITwin(token, "id", "minimal"); * * // Returns ITwinRepresentationResponse * const detailed = await client.getITwin(token, "id", "representation"); * * // Defaults to minimal when no resultMode specified * const defaultResult = await client.getITwin(token, "id"); * ``` */ async getITwin(accessToken, iTwinId, resultMode) { const headers = this.getResultModeHeaders(resultMode); const url = `${this._baseUrl}/${iTwinId}`; return this.sendGenericAPIRequest(accessToken, "GET", url, undefined, headers); } /** Get iTwins accessible to the user with optional filtering and pagination * @param accessToken The client access token string * @param arg Optional query arguments for paging, searching, filtering, ordering, and field selection * @returns Promise that resolves with an array of iTwins, may be empty * @example * ```typescript * // Returns MultiITwinMinimalResponse * const minimal = await client.getITwins(token, { resultMode: "minimal", search: "test" }); * * // Returns MultiITwinRepresentationResponse * const detailed = await client.getITwins(token, { resultMode: "representation", filter: "type eq 'Project'" }); * * // Defaults to minimal when no resultMode specified * const defaultResult = await client.getITwins(token); * ``` */ async getITwins(accessToken, arg) { const headers = this.getHeaders(arg); const url = `${this._baseUrl}/?${this.getQueryStringArg(ITwinsClient.ITwinsGetQueryParamMapping, arg !== null && arg !== void 0 ? arg : {})}`; return this.sendGenericAPIRequest(accessToken, "GET", url, undefined, headers); } /** Create a new iTwin * @param accessToken The client access token string * @param iTwin The iTwin data to be created * @returns Promise that resolves with the created iTwin details */ async createITwin(accessToken, iTwin) { const url = `${this._baseUrl}/`; return this.sendGenericAPIRequest(accessToken, "POST", url, iTwin); } /** Update the specified iTwin * @param accessToken The client access token string * @param iTwinId The id of the iTwin to update * @param iTwin The iTwin data to be updated (partial update supported) * @returns Promise that resolves with the updated iTwin details */ async updateItwin(accessToken, iTwinId, iTwin) { const url = `${this._baseUrl}/${iTwinId}`; return this.sendGenericAPIRequest(accessToken, "PATCH", url, iTwin); } /** Delete the specified iTwin * @param accessToken The client access token string * @param iTwinId The id of the iTwin to delete * @returns Promise that resolves when the iTwin is successfully deleted */ async deleteItwin(accessToken, iTwinId) { const url = `${this._baseUrl}/${iTwinId}`; return this.sendGenericAPIRequest(accessToken, "DELETE", url); } /** Get the primary account accessible to the user * @param accessToken The client access token string * @returns Promise that resolves with the primary account details */ async getPrimaryAccount(accessToken) { const url = `${this._baseUrl}/myprimaryaccount`; return this.sendGenericAPIRequest(accessToken, "GET", url, undefined); } /** * Get the account for the specified iTwin * @param accessToken The client access token string * @param iTwinId The id of the iTwin * @param resultMode (Optional) Result mode: minimal or representation * @returns Promise that resolves with the account details * @example * ```typescript * // Returns ITwinMinimalResponse * const minimal = await client.getITwinAccount(token, "id", "minimal"); * * // Returns ITwinRepresentationResponse * const detailed = await client.getITwinAccount(token, "id", "representation"); * * // Defaults to minimal when no resultMode specified * const defaultResult = await client.getITwinAccount(token, "id"); * ``` */ async getITwinAccount(accessToken, iTwinId, resultMode) { const headers = this.getResultModeHeaders(resultMode); const url = `${this._baseUrl}/${iTwinId}/account`; return this.sendGenericAPIRequest(accessToken, "GET", url, undefined, headers); } /** * Format headers from query arguments including query scope and result mode * @param arg (Optional) iTwin query arguments * @returns Headers object with formatted query scope and result mode headers * @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, defaults to "minimal" * @returns Headers object with prefer header for result mode * @protected */ getResultModeHeaders(resultMode = "minimal") { return { prefer: `return=${resultMode}`, }; } /** * Format query scope parameter into a headers entry * @param queryScope (Optional) iTwin query scope, defaults to "memberOfItwin" * @returns Headers object with x-itwin-query-scope header * @protected */ getQueryScopeHeaders(queryScope = "memberOfItwin") { return { "x-itwin-query-scope": queryScope, }; } } exports.ITwinsClient = ITwinsClient; //# sourceMappingURL=iTwinsClient.js.map