包详细信息

@itwin/imodels-client-authoring

iTwin47.9kMIT6.0.1

iModels API client wrapper for applications that author iModels.

Bentley, iModel, iTwin, iTwin platform

自述文件

@itwin/imodels-client-authoring

Copyright © Bentley Systems, Incorporated. All rights reserved. See LICENSE.md for license terms and full copyright notice.

About this package

This package contains an API client that exposes a subset of iModels API operations - it extends the client from the @itwin/imodels-client-management package and adds more operations that enable applications to author iModels - acquire Birefcases, manage Locks, etc. This library also adds the ability to perform iModel operations that include file transfer - create or download Changesets, create iModel from Baseline file.

Please see the list of key methods and types to discover what API operations are exposed by this client package.

Usage examples

Note: Since the @itwin/imodels-client-authoring package extends the @itwin/imodels-client-management package all usage examples presented for the @itwin/imodels-client-management package are valid for this one as well.

Storage Client

To use authoring IModelsClient a ClientStorage instance needs to be provided. If you are not including @itwin/imodels-access-backend, you can create an instance that fully supports iModels api in the following way:


import {
  GoogleClientStorage
} from "@itwin/object-storage-google/lib/client";
import {
  ClientStorageWrapperFactory,
} from "@itwin/object-storage-google/lib/client/wrappers";

import {
  AzureClientStorage,
  BlockBlobClientWrapperFactory,
} from "@itwin/object-storage-azure";
import {
  ClientStorage,
  StrategyClientStorage,
} from "@itwin/object-storage-core";

function createDefaultClientStorage(): ClientStorage {
  return new StrategyClientStorage([
    {
      instanceName: "azure",
      instance: new AzureClientStorage(new BlockBlobClientWrapperFactory()),
    },
    {
      instanceName: "google",
      instance: new GoogleClientStorage(new ClientStorageWrapperFactory()),
    }
  ]);
}

Authorization

IModelsClient expects the authorization info to be passed in a form of an asynchronous callback that returns authorization info. It is a common use case to consume IModelsClient in iTwin.js platform based applications which use IModelApp.getAccessToken or IModelHost.getAccessToken to get the authorization header value returned as a string. The authorization header value specifies the schema and access token e.g. Bearer ey.... To convert this value into the format that IModelsClients expect users can use AccessTokenAdapter class which is exported by both @itwin/imodels-access-frontend and @itwin/imodels-access-backend packages.

const iModelIterator: EntityListIterator<MinimalIModel> =
  iModelsClient.iModels.getMinimalList({
    authorization: AccessTokenAdapter.toAuthorizationCallback(IModelHost.getAccessToken),
    urlParams: {
      projectId: "8a1fcd73-8c23-460d-a392-8b4afc00affc",
    },
  });

Headers

To include custom headers in your requests, you have the option to provide additional headers or header factories. When constructing an instance of IModelsClient, any headers passed to the constructor will be automatically added to all requests made by the client. On the other hand, when invoking specific operations, you can pass headers through the operation parameters, which will be included only in the requests related to that particular operation. If a header with the same key is specified in both the constructor and operation parameters, the header from the operation parameters will overwrite the corresponding header from the constructor.

Note: Whitespace values, such as empty strings or spaces are treated as regular headers in our requests. This means that if you provide a whitespace header value it will be sent with the request.


const iModelsClient = new IModelsClient({
  cloudStorage: createDefaultClientStorage(),
  headers: {
    "X-Correlation-Id": () => "xCorrelationIdValue",
    "some-custom-header": "someCustomValue",
  },
});

iModelsClient.baselineFiles.getSingle({
  headers: {
    "X-Correlation-Id": "some value that overrides factory",
    "new-custom-header": "header that will be sent in this operation requests",
  },
});

Create iModel from Baseline File

import {
  Authorization,
  IModel,
  IModelsClient,
} from "@itwin/imodels-client-authoring";

/** Function that creates a new iModel from Baseline file and prints its id to the console. */
async function createIModelFromBaselineFile(): Promise<void> {
  const iModelsClient: IModelsClient = new IModelsClient({ cloudStorage: createDefaultClientStorage() });
  const iModel: IModel = await iModelsClient.iModels.createFromBaseline({
    authorization: () => getAuthorization(),
    iModelProperties: {
      projectId: "8a1fcd73-8c23-460d-a392-8b4afc00affc",
      name: "Sun City Renewable-energy Plant",
      description: "Overall model of wind and solar farms in Sun City",
      filePath: "D:\\imodels\\sun-city.bim",
    },
  });

  console.log(iModel.id);
}

/** Function that returns valid authorization information. */
async function getAuthorization(): Promise<Authorization> {
  return { scheme: "Bearer", token: "ey..." };
}

更新日志

Change Log - @itwin/imodels-client-authoring

This log was last generated on Thu, 26 Jun 2025 10:42:19 GMT and should not be manually modified.

6.0.1

Thu, 26 Jun 2025 10:42:19 GMT

Version update only

6.0.0

Wed, 28 May 2025 07:15:31 GMT

Breaking changes

  • Support google storage
  • Export ESM modules
  • Remove dependencies on object storage implementations
  • Remove reexports from @itwin/imodels-client-management
  • Change @itwin/imodels-client-management to be a peer dependency

Minor changes

  • Moved error parsing to OperationsBase
  • Update object-storage to 3.0.0
  • Drop support for Node.js versions older than 20.9.0.

5.10.0

Wed, 26 Mar 2025 11:41:32 GMT

Minor changes

  • Update documentation

5.9.0

Wed, 25 Sep 2024 14:09:09 GMT

Version update only

5.8.2

Mon, 19 Aug 2024 06:58:46 GMT

Updates

  • Add a documentation comment to inform users to not throw errors inside progress callback functions passed to operations that download files.

5.8.1

Wed, 14 Aug 2024 14:41:07 GMT

Updates

  • Update dependency to @itwin/object-storage-* and axios packages.

5.8.0

Mon, 01 Jul 2024 14:05:44 GMT

Minor changes

  • Add failed HTTP request retry policy.

Updates

  • Add originalError property to IModelsError

5.7.0

Tue, 18 Jun 2024 11:18:40 GMT

Minor changes

  • Add forkedFrom response property in CreateIModelOperationDetails.
  • Add fork iModel operation.
  • Add containersEnabled property.
  • Fix consumer provided timeOutInMs not being respected in iModel operations.
  • Add Named Version $search query parameter.
  • Add iModel $search query parameter.
  • Add HTTP status code to iModelsError.
  • Add Changeset Extended Data operations.
  • Add ordering by createdDateTime for Named Versions.
  • Add ordering by acquiredDateTime for Briefcases.
  • Add latest checkpoint link to Briefcase entity
  • Add Get Briefcase Checkpoint operation

5.0.0

Thu, 4 Apr 2024 13:39:29 GMT

Breaking changes

  • Update RestClient interface. Classes implementing RestClient interface must now return HTTP response headers in addition to the response body.
  • Update createFromTemplate iModel operation error handling. If iModel initialization times out, the error code of the thrown error will now be IModelFromTemplateInitializationTimedOut instead of IModelFromTemplateInitializationFailed.

4.0.0

Tue, 23 May 2023 15:57:54 GMT

Breaking changes

  • Drop support for Node.js versions older than 18.12.0.

3.0.0

Thu, 23 Feb 2023 16:27:30 GMT

Breaking changes

  • Update client to use iModels API V2 by default. All references to the term 'Project' were updated to use 'iTwin' (projectId -> iTwinId, ...).

2.0.0

Fri, 22 July 2022 14:42:36 GMT

Breaking changes

  • Remove internal code exports from the main index.ts file that should not be used directly by package users. The following components are no longer part of the public package API:
    • Operation classes (IModelOperations, ChangesetOperations, etc.)
    • Utility types (raw API response interfaces, etc.)
    • Default IModelsClient option implementations (AxiosRestClient)
    • Default iModels API parser class
  • Change _links property type in entity interfaces from Link to Link | null as per iModels API definition.

Minor changes

  • Surface more iModels API operations. Please see the package documentation for an updated list of supported operations and entities: link to docs.

1.0.0

Tue, 18 Jan 2022 14:43:04 GMT

Initial release