@liveblocks/node 1.19.0-test1 → 2.0.0-alpha1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,95 +1,7 @@
1
- import { IUserInfo, Json, PlainLsonObject, JsonObject, ThreadData, BaseMetadata, CommentData, CommentBody, CommentUserReaction } from '@liveblocks/core';
2
- 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';
1
+ import { IUserInfo, Json, PlainLsonObject, JsonObject, BaseMetadata, DM, QueryMetadata, ThreadData, CommentData, CommentBody, CommentUserReaction, InboxNotificationData, RoomNotificationSettings, ActivityData } from '@liveblocks/core';
2
+ 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';
3
3
  import { IncomingHttpHeaders } from 'http';
4
4
 
5
- /**
6
- * TODO Officially mark as DEPRECATED, point to migration guide.
7
- */
8
- declare type AuthorizeOptions = {
9
- /**
10
- * The secret API key for your Liveblocks account. You can find it on
11
- * https://liveblocks.io/dashboard/apikeys
12
- */
13
- secret: string;
14
- /**
15
- * The room ID for which to authorize the user. This will authorize the user
16
- * to enter the Liveblocks room.
17
- */
18
- room: string;
19
- /**
20
- * Associates a user ID to the session that is being authorized. The user ID
21
- * is typically set to the user ID from your own database.
22
- *
23
- * It can also be used to generate a token that gives access to a private
24
- * room where the userId is configured in the room accesses.
25
- *
26
- * This user ID will be used as the unique identifier to compute your
27
- * Liveblocks account's Monthly Active Users.
28
- */
29
- userId: string;
30
- /**
31
- * Arbitrary metadata associated to this user session.
32
- *
33
- * You can use it to store a small amount of static metadata for a user
34
- * session. It is public information, that will be visible to other users in
35
- * the same room, like name, avatar URL, etc.
36
- *
37
- * It's only suitable for static info that won't change during a session. If
38
- * you want to store dynamic metadata on a user session, don't keep that in
39
- * the session token, but use Presence instead.
40
- *
41
- * Can't exceed 1KB when serialized as JSON.
42
- */
43
- userInfo?: unknown;
44
- /**
45
- * Tell Liveblocks which group IDs this user belongs to. This will authorize
46
- * the user session to access private rooms that have at least one of these
47
- * group IDs listed in their room access configuration.
48
- *
49
- * See https://liveblocks.io/docs/guides/managing-rooms-users-permissions#permissions
50
- * for how to configure your room's permissions to use this feature.
51
- */
52
- groupIds?: string[];
53
- };
54
- /**
55
- * TODO Officially mark as DEPRECATED, point to migration guide.
56
- */
57
- declare type AuthorizeResponse = {
58
- status: number;
59
- body: string;
60
- error?: Error;
61
- };
62
- /**
63
- * @deprecated Since 1.2, we’re deprecating single-room tokens in favor of
64
- * either access tokens or ID tokens. Single-room tokens are still supported,
65
- * but support for them will be dropped in the future. Please refer to our
66
- * Upgrade Guide to learn how to adopt the new-style authorization, see
67
- * https://liveblocks.io/docs/platform/upgrading/1.2
68
- *
69
- * Tells Liveblocks that a user should be allowed access to a room, which user
70
- * this session is for, and what metadata to associate with the user (like
71
- * name, avatar, etc.)
72
- *
73
- * @example
74
- * export default async function auth(req, res) {
75
- *
76
- * // Implement your own security here.
77
- *
78
- * const room = req.body.room;
79
- * const response = await authorize({
80
- * room,
81
- * secret,
82
- * userId: "123",
83
- * userInfo: { // Optional
84
- * name: "Ada Lovelace"
85
- * },
86
- * groupIds: ["group1"] // Optional
87
- * });
88
- * return res.status(response.status).end(response.body);
89
- * }
90
- */
91
- declare function authorize(options: AuthorizeOptions): Promise<AuthorizeResponse>;
92
-
93
5
  declare const ALL_PERMISSIONS: readonly ["room:write", "room:read", "room:presence:write", "comments:write", "comments:read"];
94
6
  declare type Permission = (typeof ALL_PERMISSIONS)[number];
95
7
  /**
@@ -175,15 +87,16 @@ declare type RoomAccesses = Record<string, [
175
87
  "room:write"
176
88
  ] | ["room:read", "room:presence:write"]>;
177
89
  declare type RoomMetadata = Record<string, string | string[]>;
90
+ declare type QueryRoomMetadata = Record<string, string>;
178
91
  declare type RoomInfo = {
179
92
  type: "room";
180
93
  id: string;
181
- metadata: RoomMetadata;
182
- groupsAccesses: RoomAccesses;
183
- usersAccesses: RoomAccesses;
184
- defaultAccesses: RoomPermission;
94
+ createdAt: Date;
185
95
  lastConnectionAt?: Date;
186
- createdAt?: Date;
96
+ defaultAccesses: RoomPermission;
97
+ usersAccesses: RoomAccesses;
98
+ groupsAccesses: RoomAccesses;
99
+ metadata: RoomMetadata;
187
100
  };
188
101
  declare type RoomUser<Info> = {
189
102
  type: "user";
@@ -266,16 +179,50 @@ declare class Liveblocks {
266
179
  * @param params.userId (optional) A filter on users accesses.
267
180
  * @param params.metadata (optional) A filter on metadata. Multiple metadata keys can be used to filter rooms.
268
181
  * @param params.groupIds (optional) A filter on groups accesses. Multiple groups can be used.
182
+ * @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.
269
183
  * @returns A list of rooms.
270
184
  */
271
185
  getRooms(params?: {
272
186
  limit?: number;
273
187
  startingAfter?: string;
274
- metadata?: RoomMetadata;
188
+ /**
189
+ * @deprecated Use `query` property instead. Support for the `metadata`
190
+ * field will be removed in a future version.
191
+ */
192
+ metadata?: QueryRoomMetadata;
275
193
  userId?: string;
276
194
  groupIds?: string[];
195
+ /**
196
+ * The query to filter rooms by. It is based on our query language.
197
+ * @example
198
+ * ```
199
+ * {
200
+ * query: 'metadata["status"]:"open" AND roomId^"liveblocks:"'
201
+ * }
202
+ * ```
203
+ * @example
204
+ * ```
205
+ * {
206
+ * query: {
207
+ * metadata: {
208
+ * status: "open",
209
+ * },
210
+ * roomId: {
211
+ * startsWith: "liveblocks:"
212
+ * }
213
+ * }
214
+ * }
215
+ * ```
216
+ */
217
+ query?: string | {
218
+ metadata?: QueryRoomMetadata;
219
+ roomId?: {
220
+ startsWith: string;
221
+ };
222
+ };
277
223
  }): Promise<{
278
224
  nextPage: string | null;
225
+ nextCursor: string | null;
279
226
  data: RoomInfo[];
280
227
  }>;
281
228
  /**
@@ -389,18 +336,22 @@ declare class Liveblocks {
389
336
  /**
390
337
  * 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.
391
338
  * @param roomId The id of the room to send the Yjs binary update to.
392
- * @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.
339
+ * @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.
340
+ * @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.
393
341
  */
394
- sendYjsBinaryUpdate(roomId: string, params: {
395
- update: string;
342
+ sendYjsBinaryUpdate(roomId: string, update: Uint8Array, params?: {
343
+ guid?: string;
396
344
  }): Promise<void>;
397
345
  /**
398
346
  * 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.
399
347
  * See [Yjs documentation](https://docs.yjs.dev/api/document-updates) for more information on working with updates.
400
348
  * @param roomId The id of the room to get the Yjs document from.
349
+ * @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.
401
350
  * @returns The room’s Yjs document encoded as a single binary update.
402
351
  */
403
- getYjsDocumentAsBinaryUpdate(roomId: string): Promise<ArrayBuffer>;
352
+ getYjsDocumentAsBinaryUpdate(roomId: string, params?: {
353
+ guid?: string;
354
+ }): Promise<ArrayBuffer>;
404
355
  /**
405
356
  * Creates a new schema which can be referenced later to enforce a room’s Storage data structure.
406
357
  * @param name The name used to reference the schema. Must be a non-empty string with less than 65 characters and only contain lowercase letters, numbers and dashes
@@ -451,12 +402,41 @@ declare class Liveblocks {
451
402
  * Gets all the threads in a room.
452
403
  *
453
404
  * @param params.roomId The room ID to get the threads from.
405
+ * @param params.query The query to filter threads by. It is based on our query language and can filter by metadata.
454
406
  * @returns A list of threads.
455
407
  */
456
- getThreads(params: {
408
+ getThreads<M extends BaseMetadata = DM>(params: {
457
409
  roomId: string;
410
+ /**
411
+ * The query to filter threads by. It is based on our query language.
412
+ *
413
+ * @example
414
+ * ```
415
+ * {
416
+ * query: "metadata['organization']^'liveblocks:' AND metadata['status']:'open' AND metadata['resolved']:false AND metadata['priority']:3"
417
+ * }
418
+ * ```
419
+ * @example
420
+ * ```
421
+ * {
422
+ * query: {
423
+ * metadata: {
424
+ * status: "open",
425
+ * resolved: false,
426
+ * priority: 3,
427
+ * organization: {
428
+ * startsWith: "liveblocks:"
429
+ * }
430
+ * }
431
+ * }
432
+ * }
433
+ * ```
434
+ */
435
+ query?: string | {
436
+ metadata?: Partial<QueryMetadata<M>>;
437
+ };
458
438
  }): Promise<{
459
- data: ThreadData[];
439
+ data: ThreadData<M>[];
460
440
  }>;
461
441
  /**
462
442
  * Gets a thread.
@@ -465,10 +445,10 @@ declare class Liveblocks {
465
445
  * @param params.threadId The thread ID.
466
446
  * @returns A thread.
467
447
  */
468
- getThread<TThreadMetadata extends BaseMetadata = never>(params: {
448
+ getThread<M extends BaseMetadata = DM>(params: {
469
449
  roomId: string;
470
450
  threadId: string;
471
- }): Promise<ThreadData<TThreadMetadata>>;
451
+ }): Promise<ThreadData<M>>;
472
452
  /**
473
453
  * Gets a thread's participants.
474
454
  *
@@ -554,17 +534,17 @@ declare class Liveblocks {
554
534
  * @param params.thread.comment.body The body of the comment.
555
535
  * @returns The created thread. The thread will be created with the specified comment as its first comment.
556
536
  */
557
- createThread<TThreadMetadata extends BaseMetadata = never>(params: {
537
+ createThread<M extends BaseMetadata = DM>(params: {
558
538
  roomId: string;
559
539
  data: {
560
- metadata?: [TThreadMetadata] extends [never] ? Record<string, never> : TThreadMetadata;
540
+ metadata?: [M] extends [never] ? Record<string, never> : M;
561
541
  comment: {
562
542
  userId: string;
563
543
  createdAt?: Date;
564
544
  body: CommentBody;
565
545
  };
566
546
  };
567
- }): Promise<ThreadData<TThreadMetadata>>;
547
+ }): Promise<ThreadData<M>>;
568
548
  /**
569
549
  * Updates the metadata of the specified thread in a room.
570
550
  * @param params.roomId The room ID to update the thread in.
@@ -574,7 +554,7 @@ declare class Liveblocks {
574
554
  * @param params.data.updatedAt (optional) The date the thread is set to be updated.
575
555
  * @returns The updated thread.
576
556
  */
577
- editThreadMetadata<TThreadMetadata extends BaseMetadata = never>(params: {
557
+ editThreadMetadata<M extends BaseMetadata = DM>(params: {
578
558
  roomId: string;
579
559
  threadId: string;
580
560
  data: {
@@ -582,7 +562,7 @@ declare class Liveblocks {
582
562
  userId: string;
583
563
  updatedAt?: Date;
584
564
  };
585
- }): Promise<TThreadMetadata>;
565
+ }): Promise<M>;
586
566
  /**
587
567
  * Adds a new comment reaction to a comment.
588
568
  * @param params.roomId The room ID to add the comment reaction in.
@@ -622,6 +602,64 @@ declare class Liveblocks {
622
602
  removedAt?: Date;
623
603
  };
624
604
  }): Promise<void>;
605
+ /**
606
+ * Returns the inbox notifications for a user.
607
+ * @param params.userId The user ID to get the inbox notifications from.
608
+ * @param params.inboxNotificationId The ID of the inbox notification to get.
609
+ */
610
+ getInboxNotification(params: {
611
+ userId: string;
612
+ inboxNotificationId: string;
613
+ }): Promise<InboxNotificationData>;
614
+ /**
615
+ * Gets the user's room notification settings.
616
+ * @param params.userId The user ID to get the room notifications from.
617
+ * @param params.roomId The room ID to get the room notification settings from.
618
+ */
619
+ getRoomNotificationSettings(params: {
620
+ userId: string;
621
+ roomId: string;
622
+ }): Promise<RoomNotificationSettings>;
623
+ /**
624
+ * Updates the user's room notification settings.
625
+ * @param params.userId The user ID to update the room notification settings for.
626
+ * @param params.roomId The room ID to update the room notification settings for.
627
+ * @param params.data The new room notification settings for the user.
628
+ */
629
+ updateRoomNotificationSettings(params: {
630
+ userId: string;
631
+ roomId: string;
632
+ data: RoomNotificationSettings;
633
+ }): Promise<RoomNotificationSettings>;
634
+ /**
635
+ * Delete the user's room notification settings.
636
+ * @param params.userId The user ID to delete the room notification settings from.
637
+ * @param params.roomId The room ID to delete the room notification settings from.
638
+ */
639
+ deleteRoomNotificationSettings(params: {
640
+ userId: string;
641
+ roomId: string;
642
+ }): Promise<void>;
643
+ /**
644
+ * Update a room ID.
645
+ * @param params.roomId The current ID of the room.
646
+ * @param params.newRoomId The new room ID.
647
+ */
648
+ updateRoomId(params: {
649
+ currentRoomId: string;
650
+ newRoomId: string;
651
+ }): Promise<RoomInfo>;
652
+ triggerInboxNotification(params: {
653
+ userId: string;
654
+ kind: `$${string}`;
655
+ roomId?: string;
656
+ subjectId: string;
657
+ activityData: ActivityData;
658
+ }): Promise<void>;
659
+ }
660
+ declare class LiveblocksError extends Error {
661
+ status: number;
662
+ constructor(status: number, message?: string);
625
663
  }
626
664
 
627
665
  declare class WebhookHandler {
@@ -680,7 +718,7 @@ declare type WebhookRequest = {
680
718
  */
681
719
  rawBody: string;
682
720
  };
683
- declare type WebhookEvent = StorageUpdatedEvent | UserEnteredEvent | UserLeftEvent | RoomCreatedEvent | RoomDeletedEvent | CommentCreatedEvent | CommentEditedEvent | CommentDeletedEvent | CommentReactionAdded | CommentReactionRemoved | ThreadMetadataUpdatedEvent | ThreadCreatedEvent | YDocUpdatedEvent;
721
+ declare type WebhookEvent = StorageUpdatedEvent | UserEnteredEvent | UserLeftEvent | RoomCreatedEvent | RoomDeletedEvent | CommentCreatedEvent | CommentEditedEvent | CommentDeletedEvent | CommentReactionAdded | CommentReactionRemoved | ThreadMetadataUpdatedEvent | NotificationEvent | ThreadCreatedEvent | YDocUpdatedEvent;
684
722
  declare type StorageUpdatedEvent = {
685
723
  type: "storageUpdated";
686
724
  data: {
@@ -831,6 +869,11 @@ declare type YDocUpdatedEvent = {
831
869
  data: {
832
870
  projectId: string;
833
871
  roomId: string;
872
+ /**
873
+ * ISO 8601 datestring
874
+ * @example "2021-03-01T12:00:00.000Z"
875
+ */
876
+ updatedAt: string;
834
877
  };
835
878
  };
836
879
  declare type ThreadMetadataUpdatedEvent = {
@@ -861,5 +904,22 @@ declare type ThreadCreatedEvent = {
861
904
  createdBy: string;
862
905
  };
863
906
  };
907
+ declare type NotificationEvent = {
908
+ type: "notification";
909
+ data: {
910
+ channel: "email";
911
+ kind: "thread";
912
+ projectId: string;
913
+ roomId: string;
914
+ userId: string;
915
+ threadId: string;
916
+ inboxNotificationId: string;
917
+ /**
918
+ * ISO 8601 datestring
919
+ * @example "2021-03-01T12:00:00.000Z"
920
+ */
921
+ createdAt: string;
922
+ };
923
+ };
864
924
 
865
- 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 };
925
+ 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 };