@twinfinity/core
    Preparing search index...

    Class TwinClient

    Implements

    Index

    Constructors

    Accessors

    • get baseUrl(): string

      Rooted twins base URL — typically <host>/sites/<container>/_ps/twins. Exposed so callers that want to build content URLs in the same auth scope as the metadata calls can derive them from here. The bare <host>/_ps/twins/... variant is not necessarily an authorized route on all deployments.

      Returns string

    Methods

    • Executes a batch of asset operations (upsert, delete, restore) atomically. All operations succeed or all are rolled back.

      Parameters

      • twinId: string
      • operations: AssetBatchOperation[]

        Array of batch operations (max 1000).

      • Optionalsignal: AbortSignal

      Returns Promise<AssetBatchResponse>

      On validation failure (400).

      On insufficient permissions (403).

      On conflict (409) or not found (404). The error's response has per-item results with reverted statuses.

    • Retrieves multiple assets by ID in a single request.

      Parameters

      • twinId: string
      • ids: string[]

        Array of asset IDs (max 1000).

      • Optionalsignal: AbortSignal

      Returns Promise<AssetBatchGetResponse>

      On validation failure (400).

    • Parameters

      • twinId: string
      • assets: AssetPost[]
      • Optionalsignal: AbortSignal

      Returns Promise<AssetGet[]>

      On invalid request body (400). The error's errorBody has structured detail.

    • Creates a new twin or updates an existing one (upsert). Provide etag in the twin body to update.

      Parameters

      • twinId: string
      • twin: TwinPut
      • Optionalsignal: AbortSignal

      Returns Promise<TwinGet>

      On invalid request body (400).

      On etag mismatch (409). The error's currentTwin contains the server's current state.

    • Parameters

      • twinId: string
      • fileId: string
      • twinFile: TwinFilePut
      • Optionalsignal: AbortSignal

      Returns Promise<TwinFileGet>

      On invalid request body (400).

      On etag mismatch (409). The error's currentTwinFile contains the server's current state.

    • Parameters

      • twinId: string
      • fileId: string
      • twinFile: unknown
      • Optionalsignal: AbortSignal

      Returns Promise<Response>

    • Parameters

      • twinId: string
      • twin: unknown
      • Optionalsignal: AbortSignal

      Returns Promise<Response>

    • Parameters

      • twinId: string
      • assetId: string
      • etag: string
      • Optionalsignal: AbortSignal

      Returns Promise<AssetGet>

      When the asset does not exist (404).

      On etag mismatch (409). The error's currentAsset contains the server's current state.

    • Soft-deletes an attachment.

      Parameters

      • twinId: string
      • assetId: string
      • attachmentId: string
      • etag: string
      • Optionalsignal: AbortSignal

      Returns Promise<AttachmentGet>

      On etag mismatch (409).

      When the attachment does not exist (404).

    • Soft-deletes a category. Inserts a new asset_category_versions row with is_deleted=true; the previous version is retained as an audit trail.

      Parameters

      • categoryId: string
      • etag: string
      • Optionalsignal: AbortSignal

      Returns Promise<AssetCategoryGet>

      When the category does not exist (404).

      On etag mismatch (409).

    • Soft-deletes a type. Inserts a new asset_type_versions row with is_deleted=true; the previous version is retained as an audit trail.

      Parameters

      • categoryId: string
      • typeId: string
      • etag: string
      • Optionalsignal: AbortSignal

      Returns Promise<AssetTypeGet>

      When the type does not exist (404).

      On etag mismatch (409).

    • Parameters

      • twinId: string
      • etag: string
      • Optionalsignal: AbortSignal

      Returns Promise<TwinGet>

      When the twin does not exist (404).

      On etag mismatch (409). The error's currentTwin contains the server's current state.

    • Parameters

      • twinId: string
      • fileId: string
      • deleteRequest: TwinFileDelete
      • Optionalsignal: AbortSignal

      Returns Promise<TwinFileGet>

      When the file does not exist (404).

      On etag mismatch (409). The error's currentTwinFile contains the server's current state.

      On invalid request (400).

    • Parameters

      • twinId: string
      • assetId: string
      • Optionalsignal: AbortSignal

      Returns Promise<AssetGet>

      When the asset does not exist (404).

    • Downloads an attachment's blob as a Response. The caller decides whether to consume it as text, ArrayBuffer, or Blob.

      Parameters

      • twinId: string
      • assetId: string
      • attachmentId: string
      • Optionalsignal: AbortSignal

      Returns Promise<Response>

      When the attachment does not exist (404).

    • Polls the in-memory upload-session cache for an attachment that's being uploaded.

      Parameters

      • twinId: string
      • assetId: string
      • token: string
      • Optionalsignal: AbortSignal

      Returns Promise<UploadStatusGet>

    • Parameters

      • categoryId: string
      • typeId: string
      • Optionalsignal: AbortSignal

      Returns Promise<AssetTypeGet>

      When the category or type does not exist (404).

    • Returns the customer's asset-type catalog: categories nested with their latest non-deleted types and full metadata schemas inline. One round-trip is enough to populate a picker dropdown and render any per-type metadata form.

      Parameters

      • Optionalsignal: AbortSignal

      Returns Promise<AssetCatalogResponse>

    • Returns the Twinfinity meta-schema document — the JSON Schema describing valid asset-type metadata schemas. The bytes the backend itself validates against, served verbatim. Power-user tools (Monaco-backed JSON editors, schema-aware tooling) fetch this at runtime so their in-editor diagnostics line up with what the server will accept, decoupled from the FE bundle's build time.

      Parameters

      • Optionalsignal: AbortSignal

      Returns Promise<Record<string, unknown>>

    • Returns the caller's named, customer-scoped capabilities against the Twin service (e.g. ViewAssetTypes, EditAssetTypes). The admin app uses this to enable or disable buttons instead of letting the user click through to a 403.

      No client-side cache — every call hits the wire. Underlying scope grants don't shift within a session, so callers are expected to memoise the result themselves (e.g. via React Query / a once-on-mount fetch) rather than calling this on every render.

      Throws TwinUnauthenticatedError on 401 (no valid auth context; caller should redirect to login). Returns an empty permissions array on 403 (authenticated but no Twin-service capabilities). Unknown capability strings should be ignored — adding a new capability is a non-breaking change.

      Parameters

      • Optionalsignal: AbortSignal

      Returns Promise<MyPermissions>

    • Parameters

      • twinId: string
      • twinVersion: number
      • processorId: string
      • Optionaloffset: number
      • Optionallimit: number
      • Optionalsignal: AbortSignal

      Returns Promise<PaginatedResponse<TwinProcessorEvent>>

      On invalid query parameters (400).

      When the processor does not exist for this twin version (404).

    • Parameters

      • twin: string | { id: string; version: number }

        Twin ID string, or {id, version} to fetch a specific version.

      • Optionalsignal: AbortSignal

      Returns Promise<TwinGet>

      When the twin or version does not exist (404).

    • Parameters

      • twinId: string
      • fileId: string
      • Optionalsignal: AbortSignal

      Returns Promise<TwinFileGet>

      When the file does not exist (404).

      On invalid request (400).

    • Parameters

      • twinId: string
      • fileId: string
      • Optionalsignal: AbortSignal

      Returns Promise<Blob>

      When the file does not exist (404).

    • Parameters

      • twinId: string
      • fileId: string
      • version: number
      • Optionalsignal: AbortSignal

      Returns Promise<TwinFileGet>

      When the file or version does not exist (404).

    • Parameters

      • twinId: string
      • fileId: string
      • version: number
      • Optionalsignal: AbortSignal

      Returns Promise<Blob>

      When the file or version does not exist (404).

    • Parameters

      • twinId: string
      • twinVersion: number
      • Optionaloffset: number
      • Optionallimit: number
      • Optionalsignal: AbortSignal

      Returns Promise<PaginatedResponse<TwinProcessorEvent>>

      On invalid query parameters (400).

      When the twin or version does not exist (404).

    • Fetches all twins by auto-paginating through listTwins. Caps at 1000 pages.

      Parameters

      • OptionalrelatedTo: string

        Filter twins by container ID.

      • Optionalsignal: AbortSignal

      Returns Promise<ListTwinItem[]>

    • Lists attachments for a single asset.

      Parameters

      • twinId: string
      • assetId: string
      • Optionaloptions: { includeDeleted?: boolean; limit?: number; offset?: number; page?: string }
      • Optionalsignal: AbortSignal

      Returns Promise<PaginatedResponse<AttachmentGet>>

    • Returns every version of a single asset category, newest first. Mirrors listAssetTypeVersions and twin.get_twin_versions.

      Parameters

      • categoryId: string
      • Optionaloptions: { includeDeleted?: boolean; limit?: number; page?: string }
      • Optionalsignal: AbortSignal

      Returns Promise<PaginatedResponse<AssetCategoryGet>>

      When the category's header row does not exist (404).

    • Parameters

      • twinId: string
      • Optionaloffset: number
      • Optionallimit: number
      • Optionaloptions: { includeDeleted?: boolean }
      • Optionalsignal: AbortSignal

      Returns Promise<PaginatedResponse<AssetListItem>>

      On invalid query parameters (400).

      When the twin does not exist (404).

    • Parameters

      • categoryId: string
      • Optionaloptions: { includeDeleted?: boolean; limit?: number; page?: string }
      • Optionalsignal: AbortSignal

      Returns Promise<PaginatedResponse<AssetTypeGet>>

      On invalid query parameters (400).

    • Returns every version of a single asset type, newest first. Mirrors twin.get_twin_versions.

      Parameters

      • categoryId: string
      • typeId: string
      • Optionaloptions: { includeDeleted?: boolean; limit?: number; page?: string }
      • Optionalsignal: AbortSignal

      Returns Promise<PaginatedResponse<AssetTypeGet>>

      When the type's header row does not exist (404).

    • Parameters

      • OptionalrelatedTo: string

        Filter twins by container ID.

      • Optionalpage: string
      • Optionallimit: number
      • Optionalsignal: AbortSignal

      Returns Promise<PaginatedResponse<ListTwinItem>>

      On invalid query parameters (400).

    • Parameters

      • id: string
      • Optionaloptions: { includeDeleted?: boolean; limit?: number; page: undefined | string }
      • Optionalsignal: AbortSignal

      Returns Promise<PaginatedResponse<ListTwinItem>>

      On invalid query parameters (400).

    • Updates an attachment's description / soft-delete flag. documentId is immutable — rebinding is rejected.

      Parameters

      • twinId: string
      • assetId: string
      • attachmentId: string
      • body: AssetAttachmentPut
      • Optionalsignal: AbortSignal

      Returns Promise<AttachmentGet>

      On etag mismatch (409). The error's currentAttachment carries the server's current state.

      When the attachment does not exist (404).

    • Upserts an asset category. Provide an empty/missing etag for first writes and the existing etag to update.

      Parameters

      Returns Promise<AssetCategoryGet>

      On invalid request body (400).

      On etag mismatch (409). The error's currentCategory contains the server's current state.

    • Upserts an asset type. The metadata schema is validated against the Twinfinity meta-schema at the API boundary; invalid schemas surface as a 400 with cause: MetadataSchemaInvalid.

      Parameters

      • categoryId: string
      • typeId: string
      • body: AssetTypePut
      • Optionalsignal: AbortSignal

      Returns Promise<AssetTypeGet>

      On invalid request body (400). The error's errorBody carries the structured cause.

      On etag mismatch (409). The error's currentType contains the server's current state.

    • Parameters

      • twinId: string
      • assetId: string
      • etag: string

      Returns Promise<AssetGet>

      When the asset does not exist (404).

      On etag mismatch (409). The error's currentAsset contains the server's current state.

    • Restores a soft-deleted attachment.

      Parameters

      • twinId: string
      • assetId: string
      • attachmentId: string
      • etag: string
      • Optionalsignal: AbortSignal

      Returns Promise<AttachmentGet>

      On etag mismatch (409).

      When the attachment does not exist (404).

    • Restores a soft-deleted category. Inserts a new asset_category_versions row with is_deleted=false; mirrors twin restore.

      Parameters

      • categoryId: string
      • etag: string
      • Optionalsignal: AbortSignal

      Returns Promise<AssetCategoryGet>

      When the category does not exist (404).

      On etag mismatch (409).

    • Restores a soft-deleted type. Inserts a new asset_type_versions row with is_deleted=false; mirrors twin restore.

      Parameters

      • categoryId: string
      • typeId: string
      • etag: string
      • Optionalsignal: AbortSignal

      Returns Promise<AssetTypeGet>

      When the type does not exist (404).

      On etag mismatch (409).

    • Parameters

      • twinId: string
      • etag: string
      • Optionalsignal: AbortSignal

      Returns Promise<TwinGet>

      When the twin does not exist (404).

      On etag mismatch (409). The error's currentTwin contains the server's current state.

    • Parameters

      • twinId: string
      • fileId: string
      • etag: string
      • Optionalsignal: AbortSignal

      Returns Promise<TwinFileGet>

      When the file does not exist (404).

      On etag mismatch (409). The error's currentTwinFile contains the server's current state.

      On invalid request (400).

    • Parameters

      • twinId: string
      • assetId: string
      • asset: AssetPut
      • Optionalsignal: AbortSignal

      Returns Promise<AssetGet>

      On invalid request body (400). The error's errorBody has structured detail.

      On etag mismatch (409). The error's currentAsset contains the server's current state.