# Class BimTwinfinityApiClient

Loads container and IFC data from the Twinfinity backend.

#### Implements

- TwinfinityApiClient

##### Index

### Constructors

constructor

### Properties

baseUrl
layers
mapBox
messages
settings
twins
upload

### Accessors

id

### Methods

canDelete
deleteChanges
get
getChanges
getContainerInfo
getContainers
getIfcChanges
getInfo
create
detectRootUrls

## Constructors

### constructor

- new BimTwinfinityApiClient(
  baseUrl: URL | URL[],
  options?: TwinfinityApiOptions,
  ): BimTwinfinityApiClient

  Constructor

  #### Parameters

  - baseUrl: URL | URL[]

    Url to twinfinity. Example: https://bim.demo.projektstruktur.se or https://bim.demo.projektstruktur.se/sites/portal/projects/projectA

  - `Optional` options: TwinfinityApiOptions

  #### Returns BimTwinfinityApiClient

## Properties

### `Readonly` baseUrl

baseUrl: URL

### `Readonly` layers

layers: LayerApiClient

Access to layer operations.

Implementation of TwinfinityApiClient.layers

### `Readonly` mapBox

mapBox: MapBoxApiClient

Access to MapBox operations.

Implementation of TwinfinityApiClient.mapBox

### `Readonly` messages

messages: MessageApiClient

Access to message operations.

Implementation of TwinfinityApiClient.messages

### `Readonly` settings

settings: SettingsApiClient

Access to settings operations.

Implementation of TwinfinityApiClient.settings

### `Readonly` twins

twins: TwinClient

Access to twin operations.

Implementation of TwinfinityApiClient.twins

### `Readonly` upload

upload: UploadApiClient

Access to upload operations.

Implementation of TwinfinityApiClient.upload

## Accessors

### id

- get id(): string

  Hostname of baseUrl.

  #### Returns string

  Implementation of TwinfinityApiClient.id

## Methods

### canDelete

- canDelete(__namedParameters: BimChange): boolean

  Determines whether a change can be deleted by calling deleteChanges.

  #### Parameters

  - __namedParameters: BimChange

    Change to check.

  #### Returns boolean

  `true` if it is possible to delete the change. Otherwise `false`.

  Implementation of TwinfinityApiClient.canDelete

### deleteChanges

- deleteChanges(changesToDelete: BimChange[]): Promise<TypedResponse<number>[]>

  #### Parameters

  - changesToDelete: BimChange[]

    Array of changes to delete

  #### Returns Promise<TypedResponse<number>[]>

  A response with TypedResponse.status `=== 200` and the number of changes that was deleted. In case of error appropriates TypedResponse.status code's are returned.

  Implementation of TwinfinityApiClient.deleteChanges

### get

- get<T>(
  absoluteUrl: string | URL,
  converter: (r: Response) => TypedResponse<T>,
  init?: RequestInit,
  ): Promise<TypedResponse<T>>

  Issues an HTTP GET specified url.

  #### Type Parameters

  - T

    The type of data the specified converter will convert the HTTP response body to.

  #### Parameters

  - absoluteUrl: string | URL

    Url to issue HTTP GET to.

  - converter: (r: Response) => TypedResponse<T>

    Converter for response. See HttpResponseType for predefined converters.

  - `Optional` init: RequestInit

    Optional settings for to HTTP GET (fetch).

  #### Returns Promise<TypedResponse<T>>

  a TypedResponse containing the status code and the response value that resulted from using the specified converter.

  #### Example

      // Gets a JSON object and convert it to the MyObj interface.
      const myObjResponse = this.get<MyObj>("http://foo.com/jsonendpoint", HttpResponseType.json)
      const myObj = myObjResponse.status === 200 ? (await myObjResponse.value) : undefined;
      // Gets a binary ArrayBuffer.
      const myArrayBufferResponse = this.get("http://foo.com/jsonendpoint", HttpResponseType.arrayBuffer)
      const myArrayBuffer = myArrayBufferResponse.status === 200 ? (await myArrayBufferResponse.value) : undefined;

  Implementation of TwinfinityApiClient.get

### getChanges

- getChanges<T extends BimChange = BimChange>(
  parentOrUrl: BimChange | BimContainer | URL,
  options: { id: string } | { query: string } | { query: "all" },
  ): Promise<TypedResponse<T[]>>

  Retrieves all changes in and below a specified parent change and that matches a specific query. Use typescript type inference cast directly to a specific BimChange type if you know exactly which types the query will return

  #### Type Parameters

  - T extends BimChange = BimChange

  #### Parameters

  - parentOrUrl: BimChange | BimContainer | URL

    Parent to get changes from.

  - options: { id: string } | { query: string } | { query: "all" }

    example: `ifc.status=processed`, `dwg.status=processed` or `_system.layers.format=sensors`

  #### Returns Promise<TypedResponse<T[]>>

  Changes in container that matched the filterQuery.

  #### Example: type inference by specifying return type.

      const dwgChanges: BimChangeDwg[] = api.getChanges(container, {query: "dwg.status=Processed"});

  #### Example: Predefined queries. Type is included in query so no need to specify on return value.

      const ifcFailures = api.getChanges(container, PredefinedBimChangeMetadataQuery.ifc(BimChangeStatus.Failed));

  #### Remarks

  It is expensive to get all changes in a container. Use a `query` to filter out only the changes you are interested in. Getting everything is discouraged as there can be 100k+ `changes` in a `container`. Be specific. As it is expensive DO NOT use this method to get the `changes` for many/all `containers` in the system. There can be many `containers` and many `changes` (like 100k+) in each `container`.

  Implementation of TwinfinityApiClient.getChanges

### getContainerInfo

- getContainerInfo(
  containerOrUrl?: BimContainer | URL,
  ): Promise<TypedResponse<BimContainerInfo>>

  #### Parameters

  - `Optional` containerOrUrl: BimContainer | URL

    If given returns info specified container. If not given, the root container is returned.

  #### Returns Promise<TypedResponse<BimContainerInfo>>

  TypedResponse with container information. If `container` is undefined, a root container is returned. If there are multiple root containers, only one can be returned using the following priority order: First ProjectNetwork and then Archive. Response will be 404 if no root container does exist. Resonse will be 401 response if user is not logged in.

  Implementation of TwinfinityApiClient.getContainerInfo

### getContainers

- getContainers(id?: string): Promise<BimContainer[]>

  Gets all containers (and workspaces) or just a specific one.

  #### Parameters

  - `Optional` id: string

    If given, only container with specific id is returned. Otherwise all containers are returned.

  #### Returns Promise<BimContainer[]>

  List of containers. May be empty if no containers were found or matched the specified id.

  Implementation of TwinfinityApiClient.getContainers

### getIfcChanges

- getIfcChanges(
  parentOrUrl: BimChange | BimContainer | URL,
  ): Promise<BimChangeIfc[]>

  Retrieves all (successfully processed) IFC changes located in and below a specified parent.

  #### Parameters

  - parentOrUrl: BimChange | BimContainer | URL

    Parent change to get IFC changes from.

  #### Returns Promise<BimChangeIfc[]>

  All successfully processed IFC changes in the specified container.

  #### Remarks

  As it is expensive DO NOT use this method to get the IFC `changes` for many/all `containers` in the system. It is however reasonable to use this method to get the `changes` for a few specific containers.

  Implementation of TwinfinityApiClient.getIfcChanges

### getInfo

- getInfo(): Promise<TwinfinityInfo>

  #### Returns Promise<TwinfinityInfo>

  TwinfinityInfo instance

  Implementation of TwinfinityApiClient.getInfo

### `Static` create

- create(
  hostnameOrUrl: string | URL,
  options?: TwinfinityApiOptions,
  ): Promise<undefined | BimTwinfinityApiClient>

  Creates a new instance of `BimTwinfinityApiClient` by detecting available root URLs for the current user.

  #### Parameters

  - hostnameOrUrl: string | URL

    Hostname of the Twinfinity installation. If the hostname does not start with `bim.` it will be added automatically. Its ok to pass a full URL too, but only the hostname is used. Scheme is always set to `https`.

  - `Optional` options: TwinfinityApiOptions

    Optional session used to get authorization header for requests.

  #### Returns Promise<undefined | BimTwinfinityApiClient>

  A promise that resolves to a new instance of `BimTwinfinityApiClient`. If no root URLs are detected, the promise resolves to `undefined`. `undefined` indicates that the user is not authorized or does not have access to any Twinfinity resources.

  #### Example

      const client = await BimTwinfinityApiClient.create('demo.projektstruktur.se');
      if (client == null) {
        console.log('User does not have access to any root URLs.');
        return;
      }
      const containers = await client.getContainers(); // Fetch containers from all available root URLs.
      console.log(containers);

### `Static` detectRootUrls

- detectRootUrls(baseUrl: URL, options?: TwinfinityApiOptions): Promise<URL[]>

  Detects the root URLs available for the current user given a base URL. The result depends on type of Twinfinity installation, how its configured and which resources the user has access to. The method will test the following root URLs:

  - {protocol}://{host}/sites/portal/
  - {protocol}://{host}/sites/archive/
  - {protocol}://{host}/workspaces/ Where {protocol} and {host} is taken from the provided `baseUrl`.

  #### Parameters

  - baseUrl: URL

    The base URL to detect root URLs for.

  - `Optional` options: TwinfinityApiOptions

    Optional session used to get authorization header for requests.

  #### Returns Promise<URL[]>

  A promise that resolves to an array of detected root URLs.

  #### Example

      const baseUrl = new URL('https://bim.demo.projektstruktur.se');
      const rootUrls = await BimTwinfinityApiClient.detectRootUrls(baseUrl);
      console.log(rootUrls); // [ 'https://bim.demo.projektstruktur.se/sites/portal/', 'https://bim.demo.projektstruktur.se/sites/archive/' ]