@liveblocks/node
Advanced tools
Comparing version 1.19.0-test1 to 2.0.0-alpha1
@@ -1,93 +0,5 @@ | ||
import { IUserInfo, Json, PlainLsonObject, JsonObject, ThreadData, BaseMetadata, CommentData, CommentBody, CommentUserReaction } from '@liveblocks/core'; | ||
export { CommentBody, CommentBodyBlockElement, CommentBodyElement, CommentBodyInlineElement, CommentBodyLink, CommentBodyLinkElementArgs, CommentBodyMention, CommentBodyMentionElementArgs, CommentBodyParagraph, CommentBodyParagraphElementArgs, CommentBodyResolveUsersArgs, CommentBodyText, CommentBodyTextElementArgs, CommentData, CommentUserReaction, IUserInfo, Json, JsonArray, JsonObject, JsonScalar, Lson, LsonObject, PlainLsonObject, StringifyCommentBodyElements, StringifyCommentBodyOptions, ThreadData, User, getMentionedIdsFromCommentBody, stringifyCommentBody } from '@liveblocks/core'; | ||
import { IUserInfo, Json, PlainLsonObject, JsonObject, BaseMetadata, DM, QueryMetadata, ThreadData, CommentData, CommentBody, CommentUserReaction, InboxNotificationData, RoomNotificationSettings, ActivityData } from '@liveblocks/core'; | ||
export { CommentBody, CommentBodyBlockElement, CommentBodyElement, CommentBodyInlineElement, CommentBodyLink, CommentBodyLinkElementArgs, CommentBodyMention, CommentBodyMentionElementArgs, CommentBodyParagraph, CommentBodyParagraphElementArgs, CommentBodyText, CommentBodyTextElementArgs, CommentData, CommentUserReaction, IUserInfo, Json, JsonArray, JsonObject, JsonScalar, Lson, LsonObject, PlainLsonObject, ResolveUsersArgs, StringifyCommentBodyElements, StringifyCommentBodyOptions, ThreadData, User, getMentionedIdsFromCommentBody, stringifyCommentBody } from '@liveblocks/core'; | ||
import { IncomingHttpHeaders } from 'http'; | ||
/** | ||
* TODO Officially mark as DEPRECATED, point to migration guide. | ||
*/ | ||
declare type AuthorizeOptions = { | ||
/** | ||
* The secret API key for your Liveblocks account. You can find it on | ||
* https://liveblocks.io/dashboard/apikeys | ||
*/ | ||
secret: string; | ||
/** | ||
* The room ID for which to authorize the user. This will authorize the user | ||
* to enter the Liveblocks room. | ||
*/ | ||
room: string; | ||
/** | ||
* Associates a user ID to the session that is being authorized. The user ID | ||
* is typically set to the user ID from your own database. | ||
* | ||
* It can also be used to generate a token that gives access to a private | ||
* room where the userId is configured in the room accesses. | ||
* | ||
* This user ID will be used as the unique identifier to compute your | ||
* Liveblocks account's Monthly Active Users. | ||
*/ | ||
userId: string; | ||
/** | ||
* Arbitrary metadata associated to this user session. | ||
* | ||
* You can use it to store a small amount of static metadata for a user | ||
* session. It is public information, that will be visible to other users in | ||
* the same room, like name, avatar URL, etc. | ||
* | ||
* It's only suitable for static info that won't change during a session. If | ||
* you want to store dynamic metadata on a user session, don't keep that in | ||
* the session token, but use Presence instead. | ||
* | ||
* Can't exceed 1KB when serialized as JSON. | ||
*/ | ||
userInfo?: unknown; | ||
/** | ||
* Tell Liveblocks which group IDs this user belongs to. This will authorize | ||
* the user session to access private rooms that have at least one of these | ||
* group IDs listed in their room access configuration. | ||
* | ||
* See https://liveblocks.io/docs/guides/managing-rooms-users-permissions#permissions | ||
* for how to configure your room's permissions to use this feature. | ||
*/ | ||
groupIds?: string[]; | ||
}; | ||
/** | ||
* TODO Officially mark as DEPRECATED, point to migration guide. | ||
*/ | ||
declare type AuthorizeResponse = { | ||
status: number; | ||
body: string; | ||
error?: Error; | ||
}; | ||
/** | ||
* @deprecated Since 1.2, we’re deprecating single-room tokens in favor of | ||
* either access tokens or ID tokens. Single-room tokens are still supported, | ||
* but support for them will be dropped in the future. Please refer to our | ||
* Upgrade Guide to learn how to adopt the new-style authorization, see | ||
* https://liveblocks.io/docs/platform/upgrading/1.2 | ||
* | ||
* Tells Liveblocks that a user should be allowed access to a room, which user | ||
* this session is for, and what metadata to associate with the user (like | ||
* name, avatar, etc.) | ||
* | ||
* @example | ||
* export default async function auth(req, res) { | ||
* | ||
* // Implement your own security here. | ||
* | ||
* const room = req.body.room; | ||
* const response = await authorize({ | ||
* room, | ||
* secret, | ||
* userId: "123", | ||
* userInfo: { // Optional | ||
* name: "Ada Lovelace" | ||
* }, | ||
* groupIds: ["group1"] // Optional | ||
* }); | ||
* return res.status(response.status).end(response.body); | ||
* } | ||
*/ | ||
declare function authorize(options: AuthorizeOptions): Promise<AuthorizeResponse>; | ||
declare const ALL_PERMISSIONS: readonly ["room:write", "room:read", "room:presence:write", "comments:write", "comments:read"]; | ||
@@ -178,11 +90,12 @@ declare type Permission = (typeof ALL_PERMISSIONS)[number]; | ||
declare type RoomMetadata = Record<string, string | string[]>; | ||
declare type QueryRoomMetadata = Record<string, string>; | ||
declare type RoomInfo = { | ||
type: "room"; | ||
id: string; | ||
createdAt: Date; | ||
lastConnectionAt?: Date; | ||
defaultAccesses: RoomPermission; | ||
usersAccesses: RoomAccesses; | ||
groupsAccesses: RoomAccesses; | ||
metadata: RoomMetadata; | ||
groupsAccesses: RoomAccesses; | ||
usersAccesses: RoomAccesses; | ||
defaultAccesses: RoomPermission; | ||
lastConnectionAt?: Date; | ||
createdAt?: Date; | ||
}; | ||
@@ -270,2 +183,3 @@ declare type RoomUser<Info> = { | ||
* @param params.groupIds (optional) A filter on groups accesses. Multiple groups can be used. | ||
* @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. | ||
* @returns A list of rooms. | ||
@@ -276,7 +190,40 @@ */ | ||
startingAfter?: string; | ||
metadata?: RoomMetadata; | ||
/** | ||
* @deprecated Use `query` property instead. Support for the `metadata` | ||
* field will be removed in a future version. | ||
*/ | ||
metadata?: QueryRoomMetadata; | ||
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; | ||
}; | ||
}; | ||
}): Promise<{ | ||
nextPage: string | null; | ||
nextCursor: string | null; | ||
data: RoomInfo[]; | ||
@@ -395,6 +342,7 @@ }>; | ||
* @param roomId The id of the room to send the Yjs binary update to. | ||
* @param params The Yjs binary update to send. Read the [Yjs documentation](https://docs.yjs.dev/api/document-updates) to learn how to create a binary update. | ||
* @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. | ||
*/ | ||
sendYjsBinaryUpdate(roomId: string, params: { | ||
update: string; | ||
sendYjsBinaryUpdate(roomId: string, update: Uint8Array, params?: { | ||
guid?: string; | ||
}): Promise<void>; | ||
@@ -405,5 +353,8 @@ /** | ||
* @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. | ||
* @returns The room’s Yjs document encoded as a single binary update. | ||
*/ | ||
getYjsDocumentAsBinaryUpdate(roomId: string): Promise<ArrayBuffer>; | ||
getYjsDocumentAsBinaryUpdate(roomId: string, params?: { | ||
guid?: string; | ||
}): Promise<ArrayBuffer>; | ||
/** | ||
@@ -459,8 +410,37 @@ * Creates a new schema which can be referenced later to enforce a room’s Storage data structure. | ||
* @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. | ||
* @returns A list of threads. | ||
*/ | ||
getThreads(params: { | ||
getThreads<M extends BaseMetadata = DM>(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['resolved']:false AND metadata['priority']:3" | ||
* } | ||
* ``` | ||
* @example | ||
* ``` | ||
* { | ||
* query: { | ||
* metadata: { | ||
* status: "open", | ||
* resolved: false, | ||
* priority: 3, | ||
* organization: { | ||
* startsWith: "liveblocks:" | ||
* } | ||
* } | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
query?: string | { | ||
metadata?: Partial<QueryMetadata<M>>; | ||
}; | ||
}): Promise<{ | ||
data: ThreadData[]; | ||
data: ThreadData<M>[]; | ||
}>; | ||
@@ -474,6 +454,6 @@ /** | ||
*/ | ||
getThread<TThreadMetadata extends BaseMetadata = never>(params: { | ||
getThread<M extends BaseMetadata = DM>(params: { | ||
roomId: string; | ||
threadId: string; | ||
}): Promise<ThreadData<TThreadMetadata>>; | ||
}): Promise<ThreadData<M>>; | ||
/** | ||
@@ -564,6 +544,6 @@ * Gets a thread's participants. | ||
*/ | ||
createThread<TThreadMetadata extends BaseMetadata = never>(params: { | ||
createThread<M extends BaseMetadata = DM>(params: { | ||
roomId: string; | ||
data: { | ||
metadata?: [TThreadMetadata] extends [never] ? Record<string, never> : TThreadMetadata; | ||
metadata?: [M] extends [never] ? Record<string, never> : M; | ||
comment: { | ||
@@ -575,3 +555,3 @@ userId: string; | ||
}; | ||
}): Promise<ThreadData<TThreadMetadata>>; | ||
}): Promise<ThreadData<M>>; | ||
/** | ||
@@ -586,3 +566,3 @@ * Updates the metadata of the specified thread in a room. | ||
*/ | ||
editThreadMetadata<TThreadMetadata extends BaseMetadata = never>(params: { | ||
editThreadMetadata<M extends BaseMetadata = DM>(params: { | ||
roomId: string; | ||
@@ -595,3 +575,3 @@ threadId: string; | ||
}; | ||
}): Promise<TThreadMetadata>; | ||
}): Promise<M>; | ||
/** | ||
@@ -636,3 +616,61 @@ * Adds a new comment reaction to a comment. | ||
}): 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. | ||
*/ | ||
getInboxNotification(params: { | ||
userId: string; | ||
inboxNotificationId: string; | ||
}): Promise<InboxNotificationData>; | ||
/** | ||
* Gets the user's room notification settings. | ||
* @param params.userId The user ID to get the room notifications from. | ||
* @param params.roomId The room ID to get the room notification settings from. | ||
*/ | ||
getRoomNotificationSettings(params: { | ||
userId: string; | ||
roomId: string; | ||
}): Promise<RoomNotificationSettings>; | ||
/** | ||
* Updates the user's room notification settings. | ||
* @param params.userId The user ID to update the room notification settings for. | ||
* @param params.roomId The room ID to update the room notification settings for. | ||
* @param params.data The new room notification settings for the user. | ||
*/ | ||
updateRoomNotificationSettings(params: { | ||
userId: string; | ||
roomId: string; | ||
data: RoomNotificationSettings; | ||
}): Promise<RoomNotificationSettings>; | ||
/** | ||
* Delete the user's room notification settings. | ||
* @param params.userId The user ID to delete the room notification settings from. | ||
* @param params.roomId The room ID to delete the room notification settings from. | ||
*/ | ||
deleteRoomNotificationSettings(params: { | ||
userId: string; | ||
roomId: string; | ||
}): Promise<void>; | ||
/** | ||
* Update a room ID. | ||
* @param params.roomId The current ID of the room. | ||
* @param params.newRoomId The new room ID. | ||
*/ | ||
updateRoomId(params: { | ||
currentRoomId: string; | ||
newRoomId: string; | ||
}): Promise<RoomInfo>; | ||
triggerInboxNotification(params: { | ||
userId: string; | ||
kind: `$${string}`; | ||
roomId?: string; | ||
subjectId: string; | ||
activityData: ActivityData; | ||
}): Promise<void>; | ||
} | ||
declare class LiveblocksError extends Error { | ||
status: number; | ||
constructor(status: number, message?: string); | ||
} | ||
@@ -695,3 +733,3 @@ declare class WebhookHandler { | ||
}; | ||
declare type WebhookEvent = StorageUpdatedEvent | UserEnteredEvent | UserLeftEvent | RoomCreatedEvent | RoomDeletedEvent | CommentCreatedEvent | CommentEditedEvent | CommentDeletedEvent | CommentReactionAdded | CommentReactionRemoved | ThreadMetadataUpdatedEvent | ThreadCreatedEvent | YDocUpdatedEvent; | ||
declare type WebhookEvent = StorageUpdatedEvent | UserEnteredEvent | UserLeftEvent | RoomCreatedEvent | RoomDeletedEvent | CommentCreatedEvent | CommentEditedEvent | CommentDeletedEvent | CommentReactionAdded | CommentReactionRemoved | ThreadMetadataUpdatedEvent | NotificationEvent | ThreadCreatedEvent | YDocUpdatedEvent; | ||
declare type StorageUpdatedEvent = { | ||
@@ -847,2 +885,7 @@ type: "storageUpdated"; | ||
roomId: string; | ||
/** | ||
* ISO 8601 datestring | ||
* @example "2021-03-01T12:00:00.000Z" | ||
*/ | ||
updatedAt: string; | ||
}; | ||
@@ -878,3 +921,20 @@ }; | ||
}; | ||
declare type NotificationEvent = { | ||
type: "notification"; | ||
data: { | ||
channel: "email"; | ||
kind: "thread"; | ||
projectId: string; | ||
roomId: string; | ||
userId: string; | ||
threadId: string; | ||
inboxNotificationId: string; | ||
/** | ||
* ISO 8601 datestring | ||
* @example "2021-03-01T12:00:00.000Z" | ||
*/ | ||
createdAt: string; | ||
}; | ||
}; | ||
export { type CommentCreatedEvent, type CommentDeletedEvent, type CommentEditedEvent, type CommentReactionAdded, type CommentReactionRemoved, Liveblocks, type LiveblocksOptions, type RoomAccesses, type RoomCreatedEvent, type RoomDeletedEvent, type RoomInfo, type RoomPermission, type RoomUser, type Schema, type StorageUpdatedEvent, type ThreadCreatedEvent, type ThreadMetadataUpdatedEvent, type ThreadParticipants, type UserEnteredEvent, type UserLeftEvent, type WebhookEvent, WebhookHandler, type WebhookRequest, authorize }; | ||
export { type CommentCreatedEvent, type CommentDeletedEvent, type CommentEditedEvent, type CommentReactionAdded, type CommentReactionRemoved, Liveblocks, LiveblocksError, type LiveblocksOptions, type NotificationEvent, type RoomAccesses, type RoomCreatedEvent, type RoomDeletedEvent, type RoomInfo, type RoomPermission, type RoomUser, type Schema, type StorageUpdatedEvent, type ThreadCreatedEvent, type ThreadMetadataUpdatedEvent, type ThreadParticipants, type UserEnteredEvent, type UserLeftEvent, type WebhookEvent, WebhookHandler, type WebhookRequest }; |
@@ -6,7 +6,23 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/index.ts | ||
var PKG_NAME = "@liveblocks/node"; | ||
var PKG_VERSION = "1.19.0-test1"; | ||
var PKG_VERSION = "2.0.0-alpha1"; | ||
var PKG_FORMAT = "cjs"; | ||
// src/client.ts | ||
// src/utils.ts | ||
var DEFAULT_BASE_URL = "https://api.liveblocks.io"; | ||
function getBaseUrl(baseUrl) { | ||
if (typeof baseUrl === "string" && baseUrl.startsWith("http")) { | ||
return baseUrl; | ||
} else { | ||
return DEFAULT_BASE_URL; | ||
} | ||
} | ||
async function fetchPolyfill() { | ||
@@ -63,51 +79,2 @@ return typeof globalThis.fetch !== "undefined" ? globalThis.fetch : (await Promise.resolve().then(() => _interopRequireWildcard(require("node-fetch")))).default; | ||
// src/authorize.ts | ||
async function authorize(options) { | ||
let url2 = null; | ||
try { | ||
const { room, secret, userId, userInfo, groupIds } = ( | ||
// Ensure we'll validate inputs at runtime | ||
options | ||
); | ||
assertNonEmpty(secret, "secret"); | ||
assertNonEmpty(room, "room"); | ||
assertNonEmpty(userId, "userId"); | ||
url2 = buildLiveblocksAuthorizeEndpoint(options, room); | ||
const fetch = await fetchPolyfill(); | ||
const resp = await fetch(buildLiveblocksAuthorizeEndpoint(options, room), { | ||
method: "POST", | ||
headers: { | ||
Authorization: `Bearer ${secret}`, | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify({ | ||
userId, | ||
userInfo, | ||
groupIds | ||
}) | ||
}); | ||
return { | ||
status: normalizeStatusCode(resp.status), | ||
body: await resp.text() | ||
}; | ||
} catch (er) { | ||
return { | ||
status: 503, | ||
body: (url2 ? `Call to "${url2}" failed.` : "Invalid authorize request.") + ' See "error" for more information.', | ||
error: er | ||
}; | ||
} | ||
} | ||
function buildLiveblocksAuthorizeEndpoint(options, roomId) { | ||
const path = `/v2/rooms/${encodeURIComponent(roomId)}/authorize`; | ||
return urljoin(options.baseUrl || DEFAULT_BASE_URL, path); | ||
} | ||
// src/client.ts | ||
// src/Session.ts | ||
@@ -131,3 +98,3 @@ var ALL_PERMISSIONS = Object.freeze([ | ||
var FULL_ACCESS = Object.freeze(["room:write", "comments:write"]); | ||
var roomPatternRegex = /^[^*]{1,128}[*]?$/; | ||
var roomPatternRegex = /^([*]|[^*]{1,128}[*]?)$/; | ||
var Session = class { | ||
@@ -167,2 +134,5 @@ /** @internal */ | ||
allow(roomIdOrPattern, newPerms) { | ||
if (typeof roomIdOrPattern !== "string") { | ||
throw new Error("Room name or pattern must be a string"); | ||
} | ||
if (!roomPatternRegex.test(roomIdOrPattern)) { | ||
@@ -213,6 +183,5 @@ throw new Error("Invalid room name or pattern"); | ||
if (!this.hasPermissions()) { | ||
return { | ||
status: 403, | ||
body: "Forbidden" | ||
}; | ||
console.warn( | ||
"Access tokens without any permission will not be supported soon, you should use wildcards when the client requests a token for resources outside a room. See https://liveblocks.io/docs/errors/liveblocks-client/access-tokens-not-enough-permissions" | ||
); | ||
} | ||
@@ -251,3 +220,3 @@ try { | ||
this._secret = secret; | ||
this._baseUrl = new URL(_nullishCoalesce(options.baseUrl, () => ( DEFAULT_BASE_URL))); | ||
this._baseUrl = new URL(getBaseUrl(options.baseUrl)); | ||
} | ||
@@ -277,3 +246,3 @@ /** @internal */ | ||
const fetch = await fetchPolyfill(); | ||
const res = await fetch(url2, { | ||
return await fetch(url2, { | ||
method: "PUT", | ||
@@ -283,5 +252,14 @@ headers, | ||
}); | ||
return res; | ||
} | ||
/** @internal */ | ||
async putBinary(path, body, params) { | ||
const url2 = urljoin(this._baseUrl, path, params); | ||
const headers = { | ||
Authorization: `Bearer ${this._secret}`, | ||
"Content-Type": "application/octet-stream" | ||
}; | ||
const fetch = await fetchPolyfill(); | ||
return await fetch(url2, { method: "PUT", headers, body }); | ||
} | ||
/** @internal */ | ||
async delete(path) { | ||
@@ -299,3 +277,2 @@ const url2 = urljoin(this._baseUrl, path); | ||
const url2 = urljoin(this._baseUrl, path, params); | ||
console.log("url", url2); | ||
const headers = { | ||
@@ -400,2 +377,3 @@ Authorization: `Bearer ${this._secret}` | ||
* @param params.groupIds (optional) A filter on groups accesses. Multiple groups can be used. | ||
* @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. | ||
* @returns A list of rooms. | ||
@@ -405,2 +383,8 @@ */ | ||
const path = url`/v2/rooms`; | ||
let query; | ||
if (typeof params.query === "string") { | ||
query = params.query; | ||
} else if (typeof params.query === "object") { | ||
query = _core.objectToQuery.call(void 0, params.query); | ||
} | ||
const queryParams = { | ||
@@ -413,17 +397,22 @@ limit: params.limit, | ||
...Object.fromEntries( | ||
Object.entries(_nullishCoalesce(params.metadata, () => ( {}))).map(([key, val]) => { | ||
const value = Array.isArray(val) ? val.join(",") : val; | ||
return [`metadata.${key}`, value]; | ||
}) | ||
) | ||
Object.entries(_nullishCoalesce(params.metadata, () => ( {}))).map(([key, val]) => [ | ||
`metadata.${key}`, | ||
val | ||
]) | ||
), | ||
query | ||
}; | ||
const res = await this.get(path, queryParams); | ||
if (!res.ok) { | ||
const text = await res.text(); | ||
throw new LiveblocksError(res.status, text); | ||
} | ||
const data = await res.json(); | ||
const rooms = data.data.map((room) => { | ||
const lastConnectionAt = room.lastConnectionAt ? new Date(room.lastConnectionAt) : void 0; | ||
const createdAt = room.createdAt ? new Date(room.createdAt) : void 0; | ||
const createdAt = new Date(room.createdAt); | ||
return { | ||
...room, | ||
lastConnectionAt, | ||
createdAt | ||
createdAt, | ||
lastConnectionAt | ||
}; | ||
@@ -460,3 +449,3 @@ }); | ||
const lastConnectionAt = data.lastConnectionAt ? new Date(data.lastConnectionAt) : void 0; | ||
const createdAt = data.createdAt ? new Date(data.createdAt) : void 0; | ||
const createdAt = new Date(data.createdAt); | ||
return { | ||
@@ -481,7 +470,7 @@ ...data, | ||
const lastConnectionAt = data.lastConnectionAt ? new Date(data.lastConnectionAt) : void 0; | ||
const createdAt = data.createdAt ? new Date(data.createdAt) : void 0; | ||
const createdAt = new Date(data.createdAt); | ||
return { | ||
...data, | ||
lastConnectionAt, | ||
createdAt | ||
createdAt, | ||
lastConnectionAt | ||
}; | ||
@@ -513,3 +502,3 @@ } | ||
const lastConnectionAt = data.lastConnectionAt ? new Date(data.lastConnectionAt) : void 0; | ||
const createdAt = data.createdAt ? new Date(data.createdAt) : void 0; | ||
const createdAt = new Date(data.createdAt); | ||
return { | ||
@@ -623,8 +612,8 @@ ...data, | ||
* @param roomId The id of the room to send the Yjs binary update to. | ||
* @param params The Yjs binary update to send. Read the [Yjs documentation](https://docs.yjs.dev/api/document-updates) to learn how to create a binary update. | ||
* @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. | ||
*/ | ||
async sendYjsBinaryUpdate(roomId, params) { | ||
const { update } = params; | ||
const res = await this.put(url`/v2/rooms/${roomId}/ydoc`, { | ||
update | ||
async sendYjsBinaryUpdate(roomId, update, params = {}) { | ||
const res = await this.putBinary(url`/v2/rooms/${roomId}/ydoc`, update, { | ||
guid: params.guid | ||
}); | ||
@@ -640,6 +629,9 @@ if (!res.ok) { | ||
* @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. | ||
* @returns The room’s Yjs document encoded as a single binary update. | ||
*/ | ||
async getYjsDocumentAsBinaryUpdate(roomId) { | ||
const res = await this.get(url`/v2/rooms/${roomId}/ydoc-binary`); | ||
async getYjsDocumentAsBinaryUpdate(roomId, params = {}) { | ||
const res = await this.get(url`/v2/rooms/${roomId}/ydoc-binary`, { | ||
guid: params.guid | ||
}); | ||
if (!res.ok) { | ||
@@ -787,2 +779,3 @@ const text = await res.text(); | ||
* @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. | ||
* @returns A list of threads. | ||
@@ -792,4 +785,10 @@ */ | ||
const { roomId } = params; | ||
let query; | ||
if (typeof params.query === "string") { | ||
query = params.query; | ||
} else if (typeof params.query === "object") { | ||
query = _core.objectToQuery.call(void 0, params.query); | ||
} | ||
const res = await this.get(url`/v2/rooms/${roomId}/threads`, { | ||
"metadata.resolved": "false" | ||
query | ||
}); | ||
@@ -819,5 +818,3 @@ if (!res.ok) { | ||
} | ||
return _core.convertToThreadData.call(void 0, | ||
await res.json() | ||
); | ||
return _core.convertToThreadData.call(void 0, await res.json()); | ||
} | ||
@@ -952,5 +949,3 @@ /** | ||
} | ||
return _core.convertToThreadData.call(void 0, | ||
await res.json() | ||
); | ||
return _core.convertToThreadData.call(void 0, await res.json()); | ||
} | ||
@@ -1030,2 +1025,100 @@ /** | ||
} | ||
/** | ||
* 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. | ||
*/ | ||
async getInboxNotification(params) { | ||
const { userId, inboxNotificationId } = params; | ||
const res = await this.get( | ||
url`/v2/users/${userId}/inbox-notifications/${inboxNotificationId}` | ||
); | ||
if (!res.ok) { | ||
const text = await res.text(); | ||
throw new LiveblocksError(res.status, text); | ||
} | ||
return _core.convertToInboxNotificationData.call(void 0, | ||
await res.json() | ||
); | ||
} | ||
/** | ||
* Gets the user's room notification settings. | ||
* @param params.userId The user ID to get the room notifications from. | ||
* @param params.roomId The room ID to get the room notification settings from. | ||
*/ | ||
async getRoomNotificationSettings(params) { | ||
const { userId, roomId } = params; | ||
const res = await this.get( | ||
url`/v2/rooms/${roomId}/users/${userId}/notification-settings` | ||
); | ||
if (!res.ok) { | ||
const text = await res.text(); | ||
throw new LiveblocksError(res.status, text); | ||
} | ||
return await res.json(); | ||
} | ||
/** | ||
* Updates the user's room notification settings. | ||
* @param params.userId The user ID to update the room notification settings for. | ||
* @param params.roomId The room ID to update the room notification settings for. | ||
* @param params.data The new room notification settings for the user. | ||
*/ | ||
async updateRoomNotificationSettings(params) { | ||
const { userId, roomId, data } = params; | ||
const res = await this.post( | ||
url`/v2/rooms/${roomId}/users/${userId}/notification-settings`, | ||
data | ||
); | ||
if (!res.ok) { | ||
const text = await res.text(); | ||
throw new LiveblocksError(res.status, text); | ||
} | ||
return await res.json(); | ||
} | ||
/** | ||
* Delete the user's room notification settings. | ||
* @param params.userId The user ID to delete the room notification settings from. | ||
* @param params.roomId The room ID to delete the room notification settings from. | ||
*/ | ||
async deleteRoomNotificationSettings(params) { | ||
const { userId, roomId } = params; | ||
const res = await this.delete( | ||
url`/v2/rooms/${roomId}/users/${userId}/notification-settings` | ||
); | ||
if (!res.ok) { | ||
const text = await res.text(); | ||
throw new LiveblocksError(res.status, text); | ||
} | ||
} | ||
/** | ||
* Update a room ID. | ||
* @param params.roomId The current ID of the room. | ||
* @param params.newRoomId The new room ID. | ||
*/ | ||
async updateRoomId(params) { | ||
const { currentRoomId, newRoomId } = params; | ||
const res = await this.post( | ||
url`/v2/rooms/${currentRoomId}/update-room-id`, | ||
{ | ||
newRoomId | ||
} | ||
); | ||
if (!res.ok) { | ||
const text = await res.text(); | ||
throw new LiveblocksError(res.status, text); | ||
} | ||
const data = await res.json(); | ||
return { | ||
...data, | ||
createdAt: new Date(data.createdAt), | ||
lastConnectionAt: data.lastConnectionAt ? new Date(data.lastConnectionAt) : void 0 | ||
}; | ||
} | ||
async triggerInboxNotification(params) { | ||
const res = await this.post(url`/v2/inbox-notifications/trigger`, params); | ||
if (!res.ok) { | ||
const text = await res.text(); | ||
throw new LiveblocksError(res.status, text); | ||
} | ||
} | ||
}; | ||
@@ -1146,3 +1239,4 @@ var LiveblocksError = class extends Error { | ||
"threadCreated", | ||
"ydocUpdated" | ||
"ydocUpdated", | ||
"notification" | ||
].includes(event.type)) | ||
@@ -1172,3 +1266,3 @@ return; | ||
exports.Liveblocks = Liveblocks; exports.WebhookHandler = WebhookHandler; exports.authorize = authorize; exports.getMentionedIdsFromCommentBody = _core.getMentionedIdsFromCommentBody; exports.stringifyCommentBody = _core.stringifyCommentBody; | ||
exports.Liveblocks = Liveblocks; exports.LiveblocksError = LiveblocksError; exports.WebhookHandler = WebhookHandler; exports.getMentionedIdsFromCommentBody = _core.getMentionedIdsFromCommentBody; exports.stringifyCommentBody = _core.stringifyCommentBody; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@liveblocks/node", | ||
"version": "1.19.0-test1", | ||
"version": "2.0.0-alpha1", | ||
"description": "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.", | ||
"license": "Apache-2.0", | ||
"type": "commonjs", | ||
"main": "./dist/index.js", | ||
@@ -32,7 +33,7 @@ "types": "./dist/index.d.ts", | ||
"test": "jest --silent --verbose --color=always", | ||
"test:types": "tsd", | ||
"test:types": "ls test-d/* | xargs -n1 tsd --files", | ||
"test:watch": "jest --silent --verbose --color=always --watch" | ||
}, | ||
"dependencies": { | ||
"@liveblocks/core": "1.19.0-test1", | ||
"@liveblocks/core": "2.0.0-alpha1", | ||
"@stablelib/base64": "^1.0.1", | ||
@@ -39,0 +40,0 @@ "fast-sha256": "^1.3.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
361226
3382
+ Added@liveblocks/core@2.0.0-alpha1(transitive)
- Removed@liveblocks/core@1.19.0-test1(transitive)