@liveblocks/node
Version:
A server-side utility that lets you set up a Liveblocks authentication endpoint. Liveblocks is the all-in-one toolkit to build collaborative products like Figma, Notion, and more.
1,150 lines (1,147 loc) • 72 kB
TypeScript
import { BaseUserMeta, DU, LiveObject, Awaitable, DS, OptionalTupleUnless, PlainLsonObject, JsonObject, QueryMetadata, ThreadData, UserSubscriptionData, CommentData, CommentBody, SubscriptionData, Patchable, CommentUserReaction, InboxNotificationData, UserRoomSubscriptionSettings, RoomSubscriptionSettings, KDAD, DAD, NotificationSettings, PartialNotificationSettings, GroupScopes, GroupData, LsonObject, ToImmutable, PartialUnless, BaseMetadata, DE, DM, NotificationChannel } from '@liveblocks/core';
export { CommentBody, CommentBodyBlockElement, CommentBodyElement, CommentBodyInlineElement, CommentBodyLink, CommentBodyLinkElementArgs, CommentBodyMention, CommentBodyMentionElementArgs, CommentBodyParagraph, CommentBodyParagraphElementArgs, CommentBodyText, CommentBodyTextElementArgs, CommentData, CommentUserReaction, IUserInfo, Json, JsonArray, JsonObject, JsonScalar, LiveList, LiveMap, LiveObject, LiveStructure, Lson, LsonObject, PlainLsonObject, ResolveUsersArgs, StringifyCommentBodyElements, StringifyCommentBodyOptions, ThreadData, User, getMentionsFromCommentBody, isNotificationChannelEnabled, stringifyCommentBody } from '@liveblocks/core';
import { IncomingHttpHeaders } from 'http';
declare const ALL_PERMISSIONS: readonly ["room:write", "room:read", "room:presence:write", "comments:write", "comments:read"];
type Permission = (typeof ALL_PERMISSIONS)[number];
/**
* Class to help you construct the exact permission set to grant a user, used
* when making `.authorizeUser()` calls.
*
* Usage:
*
* const session = liveblocks.prepareSession();
* session.allow(roomId, permissions) // or...
*
* For the `permissions` argument, you can pass a list of specific permissions,
* or use one of our presets:
*
* session.allow('my-room', session.FULL_ACCESS) // Read + write access to room storage and comments
* session.allow('my-room', session.READ_ACCESS) // Read-only access to room storage and comments
*
* Rooms can be specified with a prefix match, if the name ends in an asterisk.
* In that case, access is granted to *all* rooms that start with that prefix:
*
* // Read + write access to *all* rooms that start with "abc:"
* session.allow('abc:*', session.FULL_ACCESS)
*
* You can define at most 10 room IDs (or patterns) in a single token,
* otherwise the token would become too large and unwieldy.
*
* All permissions granted are additive. You cannot "remove" permissions once
* you grant them. For example:
*
* session
* .allow('abc:*', session.FULL_ACCESS)
* .allow('abc:123', session.READ_ACCESS)
*
* Here, room `abc:123` would have full access. The second .allow() call only
* _adds_ read permissions, but that has no effect since full access
* permissions were already added to the set.
*/
declare class Session {
#private;
readonly FULL_ACCESS: readonly ["room:write", "comments:write"];
readonly READ_ACCESS: readonly ["room:read", "room:presence:write", "comments:read"];
allow(roomIdOrPattern: string, newPerms: readonly Permission[]): this;
/**
* Call this to authorize the session to access Liveblocks. Note that this
* will return a Liveblocks "access token". Anyone that obtains such access
* token will have access to the allowed resources.
*/
authorize(): Promise<AuthResponse>;
}
/**
* NOTE: only types should be imported from @liveblocks/core.
* This is because this package is made to be used in Node.js, and
* @liveblocks/core has browser-specific code.
*/
type SerializeMaps<T> = T extends ReadonlyMap<infer K, infer V> ? K extends string ? {
readonly [P in K]: SerializeMaps<V>;
} : {
readonly [key: string]: SerializeMaps<V>;
} : T extends object ? {
readonly [P in keyof T]: SerializeMaps<T[P]>;
} : T;
type ToSimplifiedJson<S extends LsonObject> = LsonObject extends S ? JsonObject : SerializeMaps<ToImmutable<S>>;
type LiveblocksOptions = {
/**
* The Liveblocks secret key. Must start with "sk_".
* Get it from https://liveblocks.io/dashboard/apikeys
*/
secret: string;
};
type CreateSessionOptions<U extends BaseUserMeta = DU> = PartialUnless<U["info"], {
userInfo: U["info"];
}> & {
tenantId?: string;
};
type IdentifyUserOptions<U extends BaseUserMeta = DU> = PartialUnless<U["info"], {
userInfo: U["info"];
}>;
type AuthResponse = {
status: number;
body: string;
error?: Error;
};
type Identity = {
userId: string;
groupIds: string[];
tenantId?: string;
};
type ThreadParticipants = {
participantIds: string[];
};
type CreateThreadOptions<M extends BaseMetadata> = {
roomId: string;
data: {
comment: {
userId: string;
createdAt?: Date;
body: CommentBody;
};
} & PartialUnless<M, {
metadata: M;
}>;
};
type RoomPermission = [] | ["room:write"] | ["room:read", "room:presence:write"];
type RoomAccesses = Record<string, ["room:write"] | ["room:read", "room:presence:write"] | ["room:read", "room:presence:write", "comments:write"]>;
type RoomMetadata = Record<string, string | string[]>;
type QueryRoomMetadata = Record<string, string>;
type RoomData = {
type: "room";
id: string;
createdAt: Date;
lastConnectionAt?: Date;
defaultAccesses: RoomPermission;
usersAccesses: RoomAccesses;
groupsAccesses: RoomAccesses;
metadata: RoomMetadata;
};
type AiCopilotProviderSettings = {
maxTokens?: number;
temperature?: number;
topP?: number;
topK?: number;
frequencyPenalty?: number;
presencePenalty?: number;
stopSequences?: string[];
seed?: number;
maxRetries?: number;
};
type OpenAiModel = "o1" | "o1-mini" | "o3" | "o3-mini" | "o4-mini" | "gpt-4.1" | "gpt-4.1-mini" | "gpt-4.1-nano" | "gpt-4o" | "gpt-4o-mini" | "gpt-4-turbo" | "gpt-4" | "gpt-5" | "gpt-5-mini" | "gpt-5-nano" | "gpt-5-chat-latest" | "gpt-5.1" | "gpt-5.1-mini" | "gpt-5.1-chat-latest";
type OpenAiProviderOptions = {
openai: {
reasoningEffort?: "low" | "medium" | "high";
webSearch?: {
allowedDomains?: string[];
};
};
};
type AnthropicModel = "claude-sonnet-4-5-20250929" | "claude-haiku-4-5-20251001" | "claude-opus-4-1-20250805" | "claude-4-opus-20250514" | "claude-4-sonnet-20250514" | "claude-3-7-sonnet-20250219" | "claude-3-5-sonnet-latest" | "claude-3-5-haiku-latest" | "claude-3-opus-latest";
type AnthropicProviderOptions = {
anthropic: {
thinking?: {
type: "enabled";
budgetTokens: number;
} | {
type: "disabled";
};
webSearch?: {
allowedDomains?: string[];
};
};
};
type GoogleModel = "gemini-2.5-flash" | "gemini-2.5-pro" | "gemini-2.0-flash-001" | "gemini-1.5-flash" | "gemini-1.5-pro";
type GoogleProviderOptions = {
google: {
thinkingConfig?: {
thinkingBudget?: number;
};
};
};
type AiCopilot = {
type: "copilot";
id: string;
name: string;
description?: string;
systemPrompt: string;
knowledgePrompt?: string;
createdAt: Date;
updatedAt: Date;
lastUsedAt?: Date;
settings?: AiCopilotProviderSettings;
} & ({
provider: "openai";
providerModel: OpenAiModel;
providerOptions?: OpenAiProviderOptions;
} | {
provider: "anthropic";
providerModel: AnthropicModel;
providerOptions?: AnthropicProviderOptions;
} | {
provider: "google";
providerModel: GoogleModel;
providerOptions?: GoogleProviderOptions;
} | {
provider: "openai-compatible";
providerModel: string;
compatibleProviderName: string;
providerBaseUrl: string;
});
type RoomUser<U extends BaseUserMeta = DU> = {
type: "user";
id: string | null;
connectionId: number;
info: U["info"];
};
type MutateStorageCallback = (context: {
root: LiveObject<S>;
}) => Awaitable<void>;
type MutateStorageOptions = RequestOptions;
type MassMutateStorageCallback = (context: {
room: RoomData;
root: LiveObject<S>;
}) => Awaitable<void>;
type MassMutateStorageOptions = MutateStorageOptions & {
concurrency?: number;
};
type E = DE;
type M = DM;
type S = DS;
type U = DU;
type RoomsQueryCriteria = {
userId?: string;
groupIds?: string[];
/**
* The query to filter rooms by. It is based on our query language.
* @example
* ```
* {
* query: 'metadata["status"]:"open" AND roomId^"liveblocks:"'
* }
* ```
* @example
* ```
* {
* query: {
* metadata: {
* status: "open",
* },
* roomId: {
* startsWith: "liveblocks:"
* }
* }
* }
* ```
*/
query?: string | {
metadata?: QueryRoomMetadata;
roomId?: {
startsWith: string;
};
};
};
type InboxNotificationsQueryCriteria = {
userId: string;
tenantId?: string;
/**
* The query to filter inbox notifications by. It is based on our query language.
*
* @example
* ```
* {
* query: "unread:true"
* }
* ```
*
* @example
* ```
* {
* query: {
* unread: true
* }
* }
* ```
*
*/
query?: string | {
unread: boolean;
};
};
type PaginationOptions = {
limit?: number;
startingAfter?: string;
};
type Page<T> = {
nextCursor: string | null;
data: T[];
};
type GetRoomsOptions = RoomsQueryCriteria & PaginationOptions;
type GetInboxNotificationsOptions = InboxNotificationsQueryCriteria & PaginationOptions;
type CreateRoomOptions = {
defaultAccesses: RoomPermission;
groupsAccesses?: RoomAccesses;
usersAccesses?: RoomAccesses;
metadata?: RoomMetadata;
tenantId?: string;
};
type UpdateRoomOptions = {
defaultAccesses?: RoomPermission | null;
groupsAccesses?: Record<string, [
"room:write"
] | ["room:read", "room:presence:write"] | null>;
usersAccesses?: Record<string, [
"room:write"
] | ["room:read", "room:presence:write"] | null>;
metadata?: Record<string, string | string[] | null>;
};
type UpsertRoomOptions = {
update: UpdateRoomOptions;
create?: CreateRoomOptions;
};
type GetAiCopilotsOptions = PaginationOptions;
type CreateAiCopilotOptions = {
name: string;
description?: string;
systemPrompt: string;
knowledgePrompt?: string;
settings?: AiCopilotProviderSettings;
providerApiKey: string;
} & ({
provider: "openai";
providerModel: OpenAiModel;
providerOptions?: OpenAiProviderOptions;
} | {
provider: "anthropic";
providerModel: AnthropicModel;
providerOptions?: AnthropicProviderOptions;
} | {
provider: "google";
providerModel: GoogleModel;
providerOptions?: GoogleProviderOptions;
} | {
provider: "openai-compatible";
providerModel: string;
compatibleProviderName: string;
providerBaseUrl: string;
});
type UpdateAiCopilotOptions = {
name?: string;
description?: string | null;
systemPrompt?: string;
knowledgePrompt?: string | null;
settings?: AiCopilotProviderSettings | null;
providerApiKey?: string;
} & ({
provider?: "openai";
/**
* The provider model to use.
*/
providerModel?: OpenAiModel;
/**
* The provider options to use. Replaces the entire existing provider options; no deep merge of the nested fields occurs.
*/
providerOptions?: OpenAiProviderOptions | null;
compatibleProviderName?: never;
providerBaseUrl?: never;
} | {
provider?: "anthropic";
/**
* The provider model to use.
*/
providerModel?: AnthropicModel;
/**
* The provider options to use. Replaces the entire existing provider options; no deep merge of the nested fields occurs..
*/
providerOptions?: AnthropicProviderOptions | null;
compatibleProviderName?: never;
providerBaseUrl?: never;
} | {
provider?: "google";
/**
* The provider model to use.
*/
providerModel?: GoogleModel;
/**
* The provider options to use. Replaces the entire existing provider options; no deep merge of the nested fields occurs.
*/
providerOptions?: GoogleProviderOptions | null;
compatibleProviderName?: never;
providerBaseUrl?: never;
} | {
provider?: "openai-compatible";
/**
* The provider model to use.
*/
providerModel?: string;
compatibleProviderName?: string;
providerBaseUrl?: string;
providerOptions?: never;
});
type CreateWebKnowledgeSourceOptions = {
copilotId: string;
url: string;
type: "individual_link" | "crawl" | "sitemap";
};
type CreateFileKnowledgeSourceOptions = {
copilotId: string;
file: File;
};
type GetKnowledgeSourcesOptions = {
copilotId: string;
} & PaginationOptions;
type GetWebKnowledgeSourceLinksOptions = {
copilotId: string;
knowledgeSourceId: string;
} & PaginationOptions;
type KnowledgeSource = ({
type: "ai-knowledge-web-source";
link: {
url: string;
type: "individual_link" | "crawl" | "sitemap";
};
} | {
type: "ai-knowledge-file-source";
file: {
name: string;
mimeType: string;
};
}) & {
id: string;
createdAt: Date;
updatedAt: Date;
lastIndexedAt: Date;
} & ({
status: "ingesting" | "ready";
} | {
status: "error";
errorMessage: string;
});
type WebKnowledgeSourceLink = {
id: string;
url: string;
status: "ingesting" | "ready" | "error";
createdAt: Date;
lastIndexedAt: Date;
};
type RequestOptions = {
signal?: AbortSignal;
};
/**
* Interact with the Liveblocks API from your Node.js backend.
*/
declare class Liveblocks {
#private;
/**
* Interact with the Liveblocks API from your Node.js backend.
*/
constructor(options: LiveblocksOptions);
/**
* Prepares a new session to authorize a user to access Liveblocks.
*
* IMPORTANT:
* Always make sure that you trust the user making the request to your
* backend before calling .prepareSession()!
*
* @param userId Tell Liveblocks the user ID of the user to authorize. Must
* uniquely identify the user account in your system. The uniqueness of this
* value will determine how many MAUs will be counted/billed.
*
* @param tenantId (optional) The tenant ID to authorize the user for.
*
* @param options.userInfo Custom metadata to attach to this user. Data you
* add here will be visible to all other clients in the room, through the
* `other.info` property.
*
*/
prepareSession(userId: string, ...rest: OptionalTupleUnless<CreateSessionOptions<U>, [
options: CreateSessionOptions<U>
]>): Session;
/**
* Call this to authenticate the user as an actor you want to allow to use
* Liveblocks.
*
* You should use this method only if you want to manage your permissions
* through the Liveblocks Permissions API. This method is more complicated to
* set up, but allows for finer-grained specification of permissions.
*
* Calling `.identifyUser()` only lets you securely identify a user (and what
* groups they belong to). What permissions this user will end up having is
* determined by whatever permissions you assign the user/group in your
* Liveblocks account, through the Permissions API:
* https://liveblocks.io/docs/rooms/permissions
*
* IMPORTANT:
* Always verify that you trust the user making the request before calling
* .identifyUser()!
*
* @param identity Tell Liveblocks the user ID of the user to authenticate.
* Must uniquely identify the user account in your system. The uniqueness of
* this value will determine how many MAUs will be counted/billed.
*
* If you also want to assign which groups this user belongs to, use the
* object form and specify the `groupIds` property. Those `groupIds` should
* match the groupIds you assigned permissions to via the Liveblocks
* Permissions API, see
* https://liveblocks.io/docs/rooms/permissions#permissions-levels-groups-accesses-example
*
* @param options.userInfo Custom metadata to attach to this user. Data you
* add here will be visible to all other clients in the room, through the
* `other.info` property.
*/
identifyUser(identity: string | Identity, ...rest: OptionalTupleUnless<IdentifyUserOptions<U>, [
options: IdentifyUserOptions<U>
]>): Promise<AuthResponse>;
/**
* Returns a list of your rooms. The rooms are returned sorted by creation date, from newest to oldest. You can filter rooms by metadata, users accesses and groups accesses.
* @param params.limit (optional) A limit on the number of rooms to be returned. The limit can range between 1 and 100, and defaults to 20.
* @param params.startingAfter (optional) A cursor used for pagination. You get the value from the response of the previous page.
* @param params.userId (optional) A filter on users accesses.
* @param params.metadata (optional) A filter on metadata. Multiple metadata keys can be used to filter rooms.
* @param params.groupIds (optional) A filter on groups accesses. Multiple groups can be used.
* @param params.tenantId (optional) A filter on tenant ID.
* @param params.query (optional) A query to filter rooms by. It is based on our query language. You can filter by metadata and room ID.
* @param options.signal (optional) An abort signal to cancel the request.
* @returns A list of rooms.
*/
getRooms(params?: GetRoomsOptions, options?: RequestOptions): Promise<Page<RoomData>>;
/**
* Iterates over all rooms that match the given criteria.
*
* The difference with .getRooms() is that pagination will happen
* automatically under the hood, using the given `pageSize`.
*
* @param criteria.userId (optional) A filter on users accesses.
* @param criteria.groupIds (optional) A filter on groups accesses. Multiple groups can be used.
* @param criteria.query.roomId (optional) A filter by room ID.
* @param criteria.query.metadata (optional) A filter by metadata.
*
* @param options.pageSize (optional) The page size to use for each request.
* @param options.signal (optional) An abort signal to cancel the request.
*/
iterRooms(criteria: RoomsQueryCriteria, options?: RequestOptions & {
pageSize?: number;
}): AsyncGenerator<RoomData>;
/**
* Creates a new room with the given id.
* @param roomId The id of the room to create.
* @param params.defaultAccesses The default accesses for the room.
* @param params.groupsAccesses (optional) The group accesses for the room. Can contain a maximum of 100 entries. Key length has a limit of 40 characters.
* @param params.usersAccesses (optional) The user accesses for the room. Can contain a maximum of 100 entries. Key length has a limit of 40 characters.
* @param params.metadata (optional) The metadata for the room. Supports upto a maximum of 50 entries. Key length has a limit of 40 characters. Value length has a limit of 256 characters.
* @param params.tenantId (optional) The tenant ID to create the room for.
* @param options.signal (optional) An abort signal to cancel the request.
* @returns The created room.
*/
createRoom(roomId: string, params: CreateRoomOptions, options?: RequestOptions & {
idempotent?: boolean;
}): Promise<RoomData>;
/**
* Returns a room with the given id, or creates one with the given creation
* options if it doesn't exist yet.
*
* @param roomId The id of the room.
* @param params.defaultAccesses The default accesses for the room if the room will be created.
* @param params.groupsAccesses (optional) The group accesses for the room if the room will be created. Can contain a maximum of 100 entries. Key length has a limit of 40 characters.
* @param params.usersAccesses (optional) The user accesses for the room if the room will be created. Can contain a maximum of 100 entries. Key length has a limit of 40 characters.
* @param params.metadata (optional) The metadata for the room if the room will be created. Supports upto a maximum of 50 entries. Key length has a limit of 40 characters. Value length has a limit of 256 characters.
* @param params.tenantId (optional) The tenant ID to create the room for.
* @param options.signal (optional) An abort signal to cancel the request.
* @returns The room.
*/
getOrCreateRoom(roomId: string, params: CreateRoomOptions, options?: RequestOptions): Promise<RoomData>;
/**
* Updates or creates a new room with the given properties.
*
* @param roomId The id of the room to update or create.
* @param update The fields to update. These values will be updated when the room exists, or set when the room does not exist and gets created. Must specify at least one key.
* @param create (optional) The fields to only use when the room does not exist and will be created. When the room already exists, these values are ignored.
* @param options.signal (optional) An abort signal to cancel the request.
* @returns The room.
*/
upsertRoom(roomId: string, params: UpsertRoomOptions, options?: RequestOptions): Promise<RoomData>;
/**
* Returns a room with the given id.
* @param roomId The id of the room to return.
* @returns The room with the given id.
* @param options.signal (optional) An abort signal to cancel the request.
*/
getRoom(roomId: string, options?: RequestOptions): Promise<RoomData>;
/**
* Updates specific properties of a room. It’s not necessary to provide the entire room’s information.
* Setting a property to `null` means to delete this property.
* @param roomId The id of the room to update.
* @param params.defaultAccesses (optional) The default accesses for the room.
* @param params.groupsAccesses (optional) The group accesses for the room. Can contain a maximum of 100 entries. Key length has a limit of 40 characters.
* @param params.usersAccesses (optional) The user accesses for the room. Can contain a maximum of 100 entries. Key length has a limit of 40 characters.
* @param params.metadata (optional) The metadata for the room. Supports upto a maximum of 50 entries. Key length has a limit of 40 characters. Value length has a limit of 256 characters.
* @param options.signal (optional) An abort signal to cancel the request.
* @returns The updated room.
*/
updateRoom(roomId: string, params: UpdateRoomOptions, options?: RequestOptions): Promise<RoomData>;
/**
* Deletes a room with the given id. A deleted room is no longer accessible from the API or the dashboard and it cannot be restored.
* @param roomId The id of the room to delete.
* @param options.signal (optional) An abort signal to cancel the request.
*/
deleteRoom(roomId: string, options?: RequestOptions): Promise<void>;
/**
* Prepares a room for connectivity, making the eventual connection faster. Use this when you know you'll be loading a room but are not yet connected to it.
* @param roomId The id of the room to prewarm.
* @param options.signal (optional) An abort signal to cancel the request.
*/
prewarmRoom(roomId: string, options?: RequestOptions): Promise<void>;
/**
* Returns a list of users currently present in the requested room. For better performance, we recommand to call this endpoint every 10 seconds maximum. Duplicates can happen if a user is in the requested room with multiple browser tabs opened.
* @param roomId The id of the room to get the users from.
* @param options.signal (optional) An abort signal to cancel the request.
* @returns A list of users currently present in the requested room.
*/
getActiveUsers(roomId: string, options?: RequestOptions): Promise<{
data: RoomUser<U>[];
}>;
/**
* Boadcasts an event to a room without having to connect to it via the client from @liveblocks/client. The connectionId passed to event listeners is -1 when using this API.
* @param roomId The id of the room to broadcast the event to.
* @param message The message to broadcast. It can be any JSON serializable value.
* @param options.signal (optional) An abort signal to cancel the request.
*/
broadcastEvent(roomId: string, message: E, options?: RequestOptions): Promise<void>;
/**
* Returns the contents of the room’s Storage tree.
* The default outputted format is called “plain LSON”, which includes information on the Live data structures in the tree.
* These nodes show up in the output as objects with two properties:
*
* ```json
* {
* "liveblocksType": "LiveObject",
* "data": ...
* }
* ```
*
* If you’re not interested in this information, you can use the `format` parameter to get a more compact output.
*
* @param roomId The id of the room to get the storage from.
* @param format (optional) Set to return `plan-lson` representation by default. If set to `json`, the output will be formatted as a simplified JSON representation of the Storage tree.
* @param options.signal (optional) An abort signal to cancel the request.
* In that format, each LiveObject and LiveMap will be formatted as a simple JSON object, and each LiveList will be formatted as a simple JSON array. This is a lossy format because information about the original data structures is not retained, but it may be easier to work with.
*/
getStorageDocument(roomId: string, format: "plain-lson", options?: RequestOptions): Promise<PlainLsonObject>;
getStorageDocument(roomId: string): Promise<PlainLsonObject>;
getStorageDocument(roomId: string, format: "json", options?: RequestOptions): Promise<ToSimplifiedJson<S>>;
/**
* Initializes a room’s Storage. The room must already exist and have an empty Storage.
* Calling this endpoint will disconnect all users from the room if there are any.
*
* @param roomId The id of the room to initialize the storage from.
* @param document The document to initialize the storage with.
* @param options.signal (optional) An abort signal to cancel the request.
* @returns The initialized storage document. It is of the same format as the one passed in.
*/
initializeStorageDocument(roomId: string, document: PlainLsonObject, options?: RequestOptions): Promise<PlainLsonObject>;
/**
* Deletes all of the room’s Storage data and disconnect all users from the room if there are any. Note that this does not delete the Yjs document in the room if one exists.
* @param roomId The id of the room to delete the storage from.
* @param options.signal (optional) An abort signal to cancel the request.
*/
deleteStorageDocument(roomId: string, options?: RequestOptions): Promise<void>;
/**
* Returns a JSON representation of the room’s Yjs document.
* @param roomId The id of the room to get the Yjs document from.
* @param params.format (optional) If true, YText will return formatting.
* @param params.key (optional) If provided, returns only a single key’s value, e.g. doc.get(key).toJSON().
* @param params.type (optional) Used with key to override the inferred type, i.e. "ymap" will return doc.get(key, Y.Map).
* @param options.signal (optional) An abort signal to cancel the request.
* @returns A JSON representation of the room’s Yjs document.
*/
getYjsDocument(roomId: string, params?: {
format?: boolean;
key?: string;
type?: string;
}, options?: RequestOptions): Promise<JsonObject>;
/**
* Send a Yjs binary update to the room’s Yjs document. You can use this endpoint to initialize Yjs data for the room or to update the room’s Yjs document.
* @param roomId The id of the room to send the Yjs binary update to.
* @param update The Yjs update to send. Typically the result of calling `Yjs.encodeStateAsUpdate(doc)`. Read the [Yjs documentation](https://docs.yjs.dev/api/document-updates) to learn how to create a binary update.
* @param params.guid (optional) If provided, the binary update will be applied to the Yjs subdocument with the given guid. If not provided, the binary update will be applied to the root Yjs document.
* @param options.signal (optional) An abort signal to cancel the request.
*/
sendYjsBinaryUpdate(roomId: string, update: Uint8Array, params?: {
guid?: string;
}, options?: RequestOptions): Promise<void>;
/**
* Returns the room’s Yjs document encoded as a single binary update. This can be used by Y.applyUpdate(responseBody) to get a copy of the document in your backend.
* See [Yjs documentation](https://docs.yjs.dev/api/document-updates) for more information on working with updates.
* @param roomId The id of the room to get the Yjs document from.
* @param params.guid (optional) If provided, returns the binary update of the Yjs subdocument with the given guid. If not provided, returns the binary update of the root Yjs document.
* @param options.signal (optional) An abort signal to cancel the request.
* @returns The room’s Yjs document encoded as a single binary update.
*/
getYjsDocumentAsBinaryUpdate(roomId: string, params?: {
guid?: string;
}, options?: RequestOptions): Promise<ArrayBuffer>;
/**
* Gets all the threads in a room.
*
* @param params.roomId The room ID to get the threads from.
* @param params.query The query to filter threads by. It is based on our query language and can filter by metadata.
* @param options.signal (optional) An abort signal to cancel the request.
* @returns A list of threads.
*/
getThreads(params: {
roomId: string;
/**
* The query to filter threads by. It is based on our query language.
*
* @example
* ```
* {
* query: "metadata['organization']^'liveblocks:' AND metadata['status']:'open' AND metadata['pinned']:false AND metadata['priority']:3 AND resolved:true"
* }
* ```
* @example
* ```
* {
* query: {
* metadata: {
* status: "open",
* pinned: false,
* priority: 3,
* organization: {
* startsWith: "liveblocks:"
* }
* },
* resolved: true
* }
* }
* ```
*/
query?: string | {
metadata?: Partial<QueryMetadata<M>>;
resolved?: boolean;
};
}, options?: RequestOptions): Promise<{
data: ThreadData<M>[];
}>;
/**
* Gets a thread.
*
* @param params.roomId The room ID to get the thread from.
* @param params.threadId The thread ID.
* @param options.signal (optional) An abort signal to cancel the request.
* @returns A thread.
*/
getThread(params: {
roomId: string;
threadId: string;
}, options?: RequestOptions): Promise<ThreadData<M>>;
/**
* @deprecated Prefer using `getMentionsFromCommentBody` to extract mentions
* from comments and threads, or `Liveblocks.getThreadSubscriptions` to get
* the list of users who are subscribed to a thread.
*
* Gets a thread's participants.
*
* Participants are users who have commented on the thread
* or users that have been mentioned in a comment.
*
* @param params.roomId The room ID to get the thread participants from.
* @param params.threadId The thread ID to get the participants from.
* @param options.signal (optional) An abort signal to cancel the request.
* @returns An object containing an array of participant IDs.
*/
getThreadParticipants(params: {
roomId: string;
threadId: string;
}, options?: RequestOptions): Promise<ThreadParticipants>;
/**
* Gets a thread's subscriptions.
*
* @param params.roomId The room ID to get the thread subscriptions from.
* @param params.threadId The thread ID to get the subscriptions from.
* @param options.signal (optional) An abort signal to cancel the request.
* @returns An array of subscriptions.
*/
getThreadSubscriptions(params: {
roomId: string;
threadId: string;
}, options?: RequestOptions): Promise<{
data: UserSubscriptionData[];
}>;
/**
* Gets a thread's comment.
*
* @param params.roomId The room ID to get the comment from.
* @param params.threadId The thread ID to get the comment from.
* @param params.commentId The comment ID.
* @param options.signal (optional) An abort signal to cancel the request.
* @returns A comment.
*/
getComment(params: {
roomId: string;
threadId: string;
commentId: string;
}, options?: RequestOptions): Promise<CommentData>;
/**
* Creates a comment.
*
* @param params.roomId The room ID to create the comment in.
* @param params.threadId The thread ID to create the comment in.
* @param params.data.userId The user ID of the user who is set to create the comment.
* @param params.data.createdAt (optional) The date the comment is set to be created.
* @param params.data.body The body of the comment.
* @param options.signal (optional) An abort signal to cancel the request.
* @returns The created comment.
*/
createComment(params: {
roomId: string;
threadId: string;
data: {
userId: string;
createdAt?: Date;
body: CommentBody;
};
}, options?: RequestOptions): Promise<CommentData>;
/**
* Edits a comment.
* @param params.roomId The room ID to edit the comment in.
* @param params.threadId The thread ID to edit the comment in.
* @param params.commentId The comment ID to edit.
* @param params.data.body The body of the comment.
* @param params.data.editedAt (optional) The date the comment was edited.
* @param options.signal (optional) An abort signal to cancel the request.
* @returns The edited comment.
*/
editComment(params: {
roomId: string;
threadId: string;
commentId: string;
data: {
body: CommentBody;
editedAt?: Date;
};
}, options?: RequestOptions): Promise<CommentData>;
/**
* Deletes a comment. Deletes a comment. If there are no remaining comments in the thread, the thread is also deleted.
* @param params.roomId The room ID to delete the comment in.
* @param params.threadId The thread ID to delete the comment in.
* @param params.commentId The comment ID to delete.
* @param options.signal (optional) An abort signal to cancel the request.
*/
deleteComment(params: {
roomId: string;
threadId: string;
commentId: string;
}, options?: RequestOptions): Promise<void>;
/**
* Creates a new thread. The thread will be created with the specified comment as its first comment.
* If the thread already exists, a `LiveblocksError` will be thrown with status code 409.
* @param params.roomId The room ID to create the thread in.
* @param params.thread.metadata (optional) The metadata for the thread. Supports upto a maximum of 10 entries. Value must be a string, boolean or number
* @param params.thread.comment.userId The user ID of the user who created the comment.
* @param params.thread.comment.createdAt (optional) The date the comment was created.
* @param params.thread.comment.body The body of the comment.
* @param options.signal (optional) An abort signal to cancel the request.
* @returns The created thread. The thread will be created with the specified comment as its first comment.
*/
createThread(params: CreateThreadOptions<M>, options?: RequestOptions): Promise<ThreadData<M>>;
/**
* Deletes a thread and all of its comments.
* @param params.roomId The room ID to delete the thread in.
* @param params.threadId The thread ID to delete.
* @param options.signal (optional) An abort signal to cancel the request.
*/
deleteThread(params: {
roomId: string;
threadId: string;
}, options?: RequestOptions): Promise<void>;
/**
* Mark a thread as resolved.
* @param params.roomId The room ID of the thread.
* @param params.threadId The thread ID to mark as resolved.
* @param params.data.userId The user ID of the user who marked the thread as resolved.
* @param options.signal (optional) An abort signal to cancel the request.
* @returns The thread marked as resolved.
*/
markThreadAsResolved(params: {
roomId: string;
threadId: string;
data: {
userId: string;
};
}, options?: RequestOptions): Promise<ThreadData<M>>;
/**
* Mark a thread as unresolved.
* @param params.roomId The room ID of the thread.
* @param params.threadId The thread ID to mark as unresolved.
* @param params.data.userId The user ID of the user who marked the thread as unresolved.
* @param options.signal (optional) An abort signal to cancel the request.
* @returns The thread marked as unresolved.
*/
markThreadAsUnresolved(params: {
roomId: string;
threadId: string;
data: {
userId: string;
};
}, options?: RequestOptions): Promise<ThreadData<M>>;
/**
* Subscribes a user to a thread.
* @param params.roomId The room ID of the thread.
* @param params.threadId The thread ID to subscribe to.
* @param params.data.userId The user ID of the user to subscribe to the thread.
* @param options.signal (optional) An abort signal to cancel the request.
* @returns The thread subscription.
*/
subscribeToThread(params: {
roomId: string;
threadId: string;
data: {
userId: string;
};
}, options?: RequestOptions): Promise<SubscriptionData>;
/**
* Unsubscribes a user from a thread.
* @param params.roomId The room ID of the thread.
* @param params.threadId The thread ID to unsubscribe from.
* @param params.data.userId The user ID of the user to unsubscribe from the thread.
* @param options.signal (optional) An abort signal to cancel the request.
*/
unsubscribeFromThread(params: {
roomId: string;
threadId: string;
data: {
userId: string;
};
}, options?: RequestOptions): Promise<void>;
/**
* Updates the metadata of the specified thread in a room.
* @param params.roomId The room ID to update the thread in.
* @param params.threadId The thread ID to update.
* @param params.data.metadata The metadata for the thread. Value must be a string, boolean or number
* @param params.data.userId The user ID of the user who updated the thread.
* @param params.data.updatedAt (optional) The date the thread is set to be updated.
* @param options.signal (optional) An abort signal to cancel the request.
* @returns The updated thread metadata.
*/
editThreadMetadata(params: {
roomId: string;
threadId: string;
data: {
metadata: Patchable<M>;
userId: string;
updatedAt?: Date;
};
}, options?: RequestOptions): Promise<M>;
/**
* Adds a new comment reaction to a comment.
* @param params.roomId The room ID to add the comment reaction in.
* @param params.threadId The thread ID to add the comment reaction in.
* @param params.commentId The comment ID to add the reaction in.
* @param params.data.emoji The (emoji) reaction to add.
* @param params.data.userId The user ID of the user associated with the reaction.
* @param params.data.createdAt (optional) The date the reaction is set to be created.
* @param options.signal (optional) An abort signal to cancel the request.
* @returns The created comment reaction.
*/
addCommentReaction(params: {
roomId: string;
threadId: string;
commentId: string;
data: {
emoji: string;
userId: string;
createdAt?: Date;
};
}, options?: RequestOptions): Promise<CommentUserReaction>;
/**
* Removes a reaction from a comment.
* @param params.roomId The room ID to remove the comment reaction from.
* @param params.threadId The thread ID to remove the comment reaction from.
* @param params.commentId The comment ID to remove the reaction from.
* @param params.data.emoji The (emoji) reaction to remove.
* @param params.data.userId The user ID of the user associated with the reaction.
* @param params.data.removedAt (optional) The date the reaction is set to be removed.
* @param options.signal (optional) An abort signal to cancel the request.
*/
removeCommentReaction(params: {
roomId: string;
threadId: string;
commentId: string;
data: {
emoji: string;
userId: string;
removedAt?: Date;
};
}, options?: RequestOptions): Promise<void>;
/**
* Returns the inbox notifications for a user.
* @param params.userId The user ID to get the inbox notifications from.
* @param params.inboxNotificationId The ID of the inbox notification to get.
* @param options.signal (optional) An abort signal to cancel the request.
*/
getInboxNotification(params: {
userId: string;
inboxNotificationId: string;
}, options?: RequestOptions): Promise<InboxNotificationData>;
/**
* Returns the inbox notifications for a user.
* @param params.userId The user ID to get the inbox notifications from.
* @param params.query The query to filter inbox notifications by. It is based on our query language and can filter by unread.
* @param params.tenantId (optional) The tenant ID to get the inbox notifications for.
* @param options.signal (optional) An abort signal to cancel the request.
*/
getInboxNotifications(params: GetInboxNotificationsOptions, options?: RequestOptions): Promise<Page<InboxNotificationData>>;
/**
* Iterates over all inbox notifications for a user.
*
* The difference with .getInboxNotifications() is that pagination will
* happen automatically under the hood, using the given `pageSize`.
*
* @param criteria.userId The user ID to get the inbox notifications from.
* @param criteria.query The query to filter inbox notifications by. It is based on our query language and can filter by unread.
* @param criteria.tenantId (optional) The tenant ID to get the inbox notifications for.
* @param options.pageSize (optional) The page size to use for each request.
* @param options.signal (optional) An abort signal to cancel the request.
*/
iterInboxNotifications(criteria: InboxNotificationsQueryCriteria, options?: RequestOptions & {
pageSize?: number;
}): AsyncGenerator<InboxNotificationData>;
/**
* Returns all room subscription settings for a user.
* @param params.userId The user ID to get the room subscription settings from.
* @param params.tenantId (optional) The tenant ID to get the room subscription settings for.
* @param params.startingAfter (optional) The cursor to start the pagination from.
* @param params.limit (optional) The number of items to return.
* @param options.signal (optional) An abort signal to cancel the request.
*/
getUserRoomSubscriptionSettings(params: {
userId: string;
tenantId?: string;
} & PaginationOptions, options?: RequestOptions): Promise<Page<UserRoomSubscriptionSettings>>;
/**
* Gets the user's room subscription settings.
* @param params.userId The user ID to get the room subscription settings from.
* @param params.roomId The room ID to get the room subscription settings from.
* @param options.signal (optional) An abort signal to cancel the request.
*/
getRoomSubscriptionSettings(params: {
userId: string;
roomId: string;
}, options?: RequestOptions): Promise<RoomSubscriptionSettings>;
/**
* Updates the user's room subscription settings.
* @param params.userId The user ID to update the room subscription settings for.
* @param params.roomId The room ID to update the room subscription settings for.
* @param params.data The new room subscription settings for the user.
* @param options.signal (optional) An abort signal to cancel the request.
*/
updateRoomSubscriptionSettings(params: {
userId: string;
roomId: string;
data: Partial<RoomSubscriptionSettings>;
}, options?: RequestOptions): Promise<RoomSubscriptionSettings>;
/**
* Delete the user's room subscription settings.
* @param params.userId The user ID to delete the room subscription settings from.
* @param params.roomId The room ID to delete the room subscription settings from.
* @param options.signal (optional) An abort signal to cancel the request.
*/
deleteRoomSubscriptionSettings(params: {
userId: string;
roomId: string;
}, options?: RequestOptions): Promise<void>;
/**
* Update a room ID.
* @param params.roomId The current ID of the room.
* @param params.newRoomId The new room ID.
* @param options.signal (optional) An abort signal to cancel the request.
*/
updateRoomId(params: {
currentRoomId: string;
newRoomId: string;
}, options?: RequestOptions): Promise<RoomData>;
/**
* Triggers an inbox notification for a user.
* @param params.userId The user ID to trigger the inbox notification for.
* @param params.kind The kind of inbox notification to trigger.
* @param params.subjectId The subject ID of the triggered inbox notification.
* @param params.activityData The activity data of the triggered inbox notification.
* @param params.roomId (optional) The room ID to trigger the inbox notification for.
* @param params.tenantId (optional) The tenant ID to trigger the inbox notification for.
* @param options.signal (optional) An abort signal to cancel the request.
*/
triggerInboxNotification<K extends KDAD>(params: {
userId: string;
kind: K;
roomId?: string;
tenantId?: string;
subjectId: string;
activityData: DAD[K];
}, options?: RequestOptions): Promise<void>;
/**
* Deletes an inbox notification for a user.
* @param params.userId The user ID for which to delete the inbox notification.
* @param params.inboxNotificationId The ID of the inbox notification to delete.
* @param options.signal (optional) An abort signal to cancel the request.
*/
deleteInboxNotification(params: {
userId: string;
inboxNotificationId: string;
}, options?: RequestOptions): Promise<void>;
/**
* Deletes all inbox notifications for a user.
* @param params.userId The user ID for which to delete all the inbox notifications.
* @param params.tenantId (optional) The tenant ID to delete the inbox notifications for.
* @param options.signal (optional) An abort signal to cancel the request.
*/
deleteAllInboxNotifications(params: {
userId: string;
tenantId?: string;
}, options?: RequestOptions): Promise<void>;
/**
* Get notification settings for a user for a project.
* @param params.userId The user ID to get the notifications settings for.
* @param options.signal (optional) An abort signal to cancel the request.
*/
getNotificationSettings(params: {
userId: string;
}, options?: RequestOptions): Promise<NotificationSettings>;
/**
* Update the user's notification settings.
* @param params.userId The user ID to update the notification settings for.
* @param params.data The new notification settings for the user.
* @param options.signal (optional) An abort signal to cancel the request.
*/
updateNotificationSettings(params: {
userId: string;
data: PartialNotificationSettings;
}, options?: RequestOptions): Promise<NotificationSettings>;
/**
* Delete the user's notification settings
* @param params.userId The user ID to update the notification settings for.
* @param options.signal (optional) An abort signal to cancel the request.
*/
deleteNotificationSettings(params: {
userId: string;
}, options?: RequestOptions): Promise<void>;
/**
* Create a group
* @param params.groupId The ID of the group to create.
* @param params.memberIds The IDs of the members to add to the group.
* @param params.tenantId (optional) The tenant ID to create the group for.
* @param params.scopes (optional) The scopes to grant to the group. The default is `{ mention: true }`.
* @param options.signal (optional) An abort signal to cancel the request.
*/
createGroup(params: {
groupId: string;
memberIds?: string[];
tenantId?: string;
scopes?: GroupScopes;
}, options?: RequestOptions): Promise<GroupData>;
/**
* Get a group
* @param params.groupId The ID of the group to get.
* @param options.signal (optional) An abort signal to cancel the request.
*/
getGro