import { EngineServicesClient, EngineServicesClientProps } from './client'; import { Permission, Project, ProjectData, ProjectDataMember, ProjectInvitation, ProjectPermissionMatrixRow, ProjectRole, ProjectWithRole } from '../types/projects'; import { AccessToken, NewAccessToken } from '../types/tokens'; import { ChannelClient } from './channel'; import { MarkNotificationsReadResultDto, NotificationPageDto, NotificationSubscriptionView } from '../types/notifications'; /** * What arrived on the socket. One callback for all three because a bell * reacts the same way to each: refresh the badge, and the list if open. * * `allRead` is one event for the whole sweep rather than one per * notification, so do not expect an id on it. */ export type LiveNotificationEvent = { type: 'created'; id: string; } | { type: 'read'; id: string; } | { type: 'allRead'; batch: number; }; /** Per-automation opt-in. `failures` skips started events entirely. */ export type NotificationSubscriptionFilterInput = 'all' | 'failures'; export interface NotificationSubscriptionInput { filter?: NotificationSubscriptionFilterInput; /** Overrides the account-level channel setting for this automation only. */ channels?: { email?: boolean; }; } /** Scope by which a permission was granted (or `'none'` if denied). */ export type PermissionScope = 'global' | 'project' | 'entity' | 'none'; /** Result of a single permission check. */ export interface PermissionCheckResult { hasPermission: boolean; scope: PermissionScope; } /** One entry in a batch permission check. */ export interface PermissionCheckEntry { resourceType: string; action: string; resourceId?: string; projectId?: string; } /** * Accepts either a static JWT string or a provider function that returns the * current JWT. Use a provider to keep refresh in the caller's hands — the * client calls it on every request so expired tokens never stick. * * @example Static token (simplest): * ```ts * new PlatformClient(jwt, apiUrl) * ``` * * @example Auth0 React: * ```ts * const { getAccessTokenSilently } = useAuth0(); * new PlatformClient(() => getAccessTokenSilently(), apiUrl) * ``` */ export type BearerTokenSource = string | (() => string | Promise); /** * Client for apps, frontends, and any caller authenticating with a user JWT. * Extends `EngineServicesClient` — the full API-token-compatible surface is * inherited. On top, it exposes the JWT-only routes `getProject`, * `getProjectData`, `checkPermission`, and `checkPermissionBatch`. Those hit * `ProjectController` which is guarded by `AccountActiveGuard + * ProjectAccessGuard` and is not reachable via an access token. * * **Token refresh.** The constructor accepts a function that returns a JWT * (sync or async); the client calls it before every request, so an Auth0 * SDK's `getAccessTokenSilently()` or similar refreshing source Just Works. * * Use `EngineServicesClient` for components (API-token auth, local server, * WebSocket progress). Use `PlatformClient` when you have a user JWT and * need project-level reads or permission introspection. * * @example * ```ts * const client = new PlatformClient( * () => auth0.getAccessTokenSilently(), * 'https://api.thatopen.com', * ); * const project = await client.getProject(projectId); * ``` */ export declare class PlatformClient extends EngineServicesClient { #private; /** * @param token - A bearer JWT, OR a function returning the current JWT * (sync or async). When a function is passed, it's invoked before every * request — ideal for token-refreshing sources like Auth0. * @param apiUrl - Base URL of the API (e.g. `https://api.thatopen.com`). * @param props - Optional client configuration. `useBearer` is forced to * `true` and cannot be overridden. */ constructor(token: BearerTokenSource, apiUrl: string, props?: Omit); protected resolveAccessToken(): Promise; /** * Creates a client from the platform context injected into * `window.__THATOPEN_CONTEXT__` by the That Open Platform. Recommended * entry point for apps running inside the platform's iframe — the context * carries a fresh JWT on every navigation. */ static fromPlatformContext(props?: Omit): PlatformClient; /** * The platform channel, from inside an app: a collaboration room shared with * other users of the app, and rooms for commands from external tools (a CLI, * an MCP server, a Revit plugin). Typed, and built on the `postMessage` * contract with the platform shell — the app never opens a socket. * * Only available in an app running in the platform's iframe; reading it * anywhere else throws. Created on first use. * * @example * ```ts * type McpCommands = { * 'select-by-category': { payload: { category: string }; reply: { count: number } }; * }; * * const mcp = client.channel.external('mcp'); * mcp.on('select-by-category', async ({ category }) => ({ count: 3 })); * await mcp.join(); * * const collab = client.channel.collab(); * collab.onPeerLeft(({ from }) => removeAvatar(from)); * await collab.join(); * ``` */ get channel(): ChannelClient; /** * Lists the caller's projects, each with their role in it. The discovery * call: everything else on this surface takes a projectId, and until this * method there was no way to find out which ids exist — a portfolio * dashboard had to be configured by hand. `ProjectWithRole` existed as a * type with no producer; this is the producer. * * @example * ```ts * const projects = await client.listProjects(); * for (const { project, role } of projects) { * console.log(project.title, role?.name ?? 'no role'); * } * ``` */ listProjects(): Promise; /** * Gets a project by ID. JWT-only — lives here because * `GET /project/:id` is guarded by `AccountActiveGuard + ProjectAccessGuard`. */ getProject(projectId: string): Promise; /** * Gets the full project data (users, roles, files, folders) for a project. * User data is stripped of sensitive fields server-side. */ getProjectData(projectId: string): Promise; /** Every other request this client makes to the project routes may change what `getProjectData` answers. */ protected request(method: string, path: string, requestData?: { body?: BodyInit; query?: object; contentType?: 'application/json' | 'multipart/form-data' | 'application/x-www-form-urlencoded'; retries?: number; responseType?: 'json' | 'blob'; }): Promise; /** The project's members, each with their role. */ listMembers(projectId: string): Promise; /** Adds an existing account to the project, with a role (the project's default when not given). */ addMember(projectId: string, accountId: string, roleId?: string): Promise; /** Gives a member another role (`null`: the project's default). `projectUserId` is the member's, from {@link listMembers}. */ setMemberRole(projectId: string, projectUserId: string, roleId: string | null): Promise; /** Takes a member out of the project. */ removeMember(projectId: string, projectUserId: string): Promise; /** * Invites a person to the project by email, with a role. They get the * platform's invitation; on accepting it they join with that role, whether * or not they had an account. */ inviteMember(projectId: string, email: string, roleId?: string): Promise; /** The project's invitations. */ listInvitations(projectId: string): Promise; /** Withdraws an invitation that has not been accepted. */ cancelInvitation(projectId: string, invitationId: string): Promise; /** The project's roles, each with its permissions. */ listRoles(projectId: string): Promise; /** * Makes a role. Its `permissions` are subject × action, each optionally * narrowed or widened on given files and folders (`resourcePermissions`): * the grant a role has on one folder and what is under it. * * @example A role that only reads one folder and everything in it * ```ts * await client.createRole(projectId, { * name: 'Observer — structure', * permissions: [ * { subject: 'STORAGE', action: 'READ', * resourcePermissions: [{ resourceId: structureFolderId, appliesToDescendants: true }] }, * ], * }); * ``` */ createRole(projectId: string, role: { name: string; description?: string; permissions: Permission[]; }): Promise; /** Changes a role: its name, description or permissions (grants and revocations alike). */ updateRole(roleId: string, changes: { name?: string; description?: string; permissions?: Permission[]; }): Promise; /** Deletes a role. */ deleteRole(roleId: string): Promise; /** * The project's permission matrix in one call: every role, what it may do * (folder grants included) and who has it — for an admin screen that shows * and changes it, instead of probing permission by permission. */ getPermissionMatrix(projectId: string): Promise; /** The caller's API tokens (without their secret). */ listTokens(): Promise; /** A token's secret, to hand to the integration that will use it. */ getTokenSecret(tokenId: string): Promise; /** * Creates an API token. `projectIds` limits it to those projects; without * them it may act on every project its owner can reach. */ createToken(token: NewAccessToken): Promise; /** Changes a token. `projectIds: []` lifts its project limit; leaving it out keeps it. */ updateToken(tokenId: string, changes: Partial): Promise; /** Revokes a token: it stops working at once. */ revokeToken(tokenId: string): Promise; /** * Fetches a user's profile picture as raw image bytes, for showing member * avatars inside an app. The route is bearer-authed, so it can't be used as * an `` — turn the blob into an object URL with * `URL.createObjectURL(blob)`. Rejects when the account has no avatar. */ getAvatar(accountId: string): Promise; /** * Checks whether the caller has a specific permission within a project. * Returns `{ hasPermission, scope }` where `scope` is `'global'` for * admin/owner, `'project'` for a role broad grant, `'entity'` for a * per-entity override, `'none'` for denied. */ checkPermission(params: { resourceId?: string; resourceType: string; action: string; projectId?: string; }): Promise; /** * Batch variant of {@link checkPermission}. Evaluates multiple checks in a * single round-trip; results come back in the same order as `checks`. */ checkPermissionBatch(checks: PermissionCheckEntry[]): Promise; /** * Lists the signed-in user's notifications, newest first. * * Scoped to whoever the bearer token belongs to — an app cannot read * anyone else's. Muted notifications are included: muting silences the * badge and the delivery channels, it does not hide the record. * * Paginate by passing the previous response's `nextCursor` back in; it is * opaque, so do not build one by hand. A null `nextCursor` means the last * page. * * @example Walk every page: * ```ts * let cursor: string | undefined; * do { * const page = await client.getNotifications({ cursor }); * render(page.items); * cursor = page.nextCursor ?? undefined; * } while (cursor); * ``` */ getNotifications(params?: { cursor?: string; limit?: number; }): Promise; /** * Number of unread notifications, excluding muted ones. This is the bell * badge count, so it is cheap to poll. */ getUnreadNotificationCount(): Promise; /** * Marks specific notifications as read. Ids the caller does not own are * ignored rather than rejected, so `updated` can be lower than the number * passed in. */ markNotificationsRead(notificationIds: string[]): Promise; /** Marks every unread notification as read in one call. */ markAllNotificationsRead(): Promise; /** * The automations this user has subscribed to. Nobody is subscribed by * default, so an empty list is the normal state. */ getNotificationSubscriptions(): Promise; /** * Removes this user's subscription to one automation. * * Unlike subscribing, which happens through the project routes, this works * for any automation the user is subscribed to and keeps working after the * automation itself is gone — opting out must never be the thing that * fails. */ unsubscribeFromAutomation(hookId: string): Promise<{ unsubscribed: boolean; }>; /** * Subscribes the signed-in user to one project automation's runs. * * Nobody is subscribed by default, so this is what makes an automation * produce notifications for this user at all. Subscribing again is * harmless: it updates the existing subscription rather than duplicating. * * Read-level access to the project is enough. Someone who can see an * automation can follow it without being able to change it. * * @example Follow only the failures, and email me about them: * ```ts * await client.subscribeToAutomation(projectId, hookId, { * filter: 'failures', * channels: { email: true }, * }); * ``` */ subscribeToAutomation(projectId: string, hookId: string, input?: NotificationSubscriptionInput): Promise<{ subscribed: true; }>; /** * Changes an existing subscription. Only the fields passed are touched, so * sending `channels` alone leaves the filter as it was. * * Throws if the user is not subscribed; use {@link subscribeToAutomation} * to create one. */ updateAutomationSubscription(projectId: string, hookId: string, changes: NotificationSubscriptionInput): Promise<{ updated: true; }>; /** * Listens for this user's notifications in real time. * * Unlike {@link EngineServicesClient.onExecutionProgress}, which follows one * execution and closes when it ends, this stays connected for the session: * the server puts the socket in a room for the signed-in account and pushes * anything addressed to them. * * The events carry ids rather than the notifications themselves, so treat * them as a signal to refresh. That keeps a burst cheap and means the * server is never the source of a stale render. * * Requires a user JWT. An API access token is rejected by the gateway, * because it identifies a token rather than a person. * * @returns a function that disconnects. Call it on unmount. * * @example * ```ts * const stop = await client.onNotification((event) => { * if (event.type === 'created') refreshBell(); * }); * // later * stop(); * ``` */ onNotification(onEvent: (event: LiveNotificationEvent) => void): Promise<() => void>; }