@liveblocks/node 2.0.0-alpha1 → 2.0.0-alpha2

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,4 +1,4 @@
1
- import { IUserInfo, Json, PlainLsonObject, JsonObject, BaseMetadata, DM, QueryMetadata, ThreadData, CommentData, CommentBody, CommentUserReaction, InboxNotificationData, RoomNotificationSettings, ActivityData } from '@liveblocks/core';
1
+ import { BaseUserMeta, PlainLsonObject, JsonObject, QueryMetadata, ThreadData, CommentData, CommentBody, Patchable, CommentUserReaction, InboxNotificationData, RoomNotificationSettings, ActivityData, LsonObject, ToImmutable, DU, BaseMetadata, DE, DM, DS } from '@liveblocks/core';
2
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
 
@@ -57,6 +57,7 @@ declare class Session {
57
57
  * @liveblocks/core has browser-specific code.
58
58
  */
59
59
 
60
+ declare type ToSimplifiedJson<S extends LsonObject> = LsonObject extends S ? JsonObject : ToImmutable<S>;
60
61
  declare type LiveblocksOptions = {
61
62
  /**
62
63
  * The Liveblocks secret key. Must start with "sk_".
@@ -64,11 +65,11 @@ declare type LiveblocksOptions = {
64
65
  */
65
66
  secret: string;
66
67
  };
67
- declare type Nullable<T> = {
68
- [P in keyof T]: T[P] | null;
68
+ declare type CreateSessionOptions<U extends BaseUserMeta = DU> = {
69
+ userInfo: U["info"];
69
70
  };
70
- declare type CreateSessionOptions = {
71
- userInfo: IUserInfo;
71
+ declare type IdentifyUserOptions<U extends BaseUserMeta = DU> = {
72
+ userInfo: U["info"];
72
73
  };
73
74
  declare type AuthResponse = {
74
75
  status: number;
@@ -82,13 +83,27 @@ declare type Identity = {
82
83
  declare type ThreadParticipants = {
83
84
  participantIds: string[];
84
85
  };
86
+ declare type CreateThreadOptions<M extends BaseMetadata> = {
87
+ roomId: string;
88
+ data: {
89
+ comment: {
90
+ userId: string;
91
+ createdAt?: Date;
92
+ body: CommentBody;
93
+ };
94
+ } & (Record<string, never> extends M ? {
95
+ metadata?: M;
96
+ } : {
97
+ metadata: M;
98
+ });
99
+ };
85
100
  declare type RoomPermission = [] | ["room:write"] | ["room:read", "room:presence:write"];
86
101
  declare type RoomAccesses = Record<string, [
87
102
  "room:write"
88
103
  ] | ["room:read", "room:presence:write"]>;
89
104
  declare type RoomMetadata = Record<string, string | string[]>;
90
105
  declare type QueryRoomMetadata = Record<string, string>;
91
- declare type RoomInfo = {
106
+ declare type RoomData = {
92
107
  type: "room";
93
108
  id: string;
94
109
  createdAt: Date;
@@ -98,11 +113,11 @@ declare type RoomInfo = {
98
113
  groupsAccesses: RoomAccesses;
99
114
  metadata: RoomMetadata;
100
115
  };
101
- declare type RoomUser<Info> = {
116
+ declare type RoomUser<U extends BaseUserMeta> = {
102
117
  type: "user";
103
118
  id: string | null;
104
119
  connectionId: number;
105
- info: Info;
120
+ info: U["info"];
106
121
  };
107
122
  declare type Schema = {
108
123
  id: string;
@@ -112,6 +127,10 @@ declare type Schema = {
112
127
  createdAt: Date;
113
128
  updatedAt: Date;
114
129
  };
130
+ declare type E = DE;
131
+ declare type M = DM;
132
+ declare type S = DS;
133
+ declare type U = DU;
115
134
  /**
116
135
  * Interact with the Liveblocks API from your Node.js backend.
117
136
  */
@@ -136,7 +155,7 @@ declare class Liveblocks {
136
155
  * `other.info` property.
137
156
  *
138
157
  */
139
- prepareSession(userId: string, options?: CreateSessionOptions): Session;
158
+ prepareSession(userId: string, options?: CreateSessionOptions<U>): Session;
140
159
  /**
141
160
  * Call this to authenticate the user as an actor you want to allow to use
142
161
  * Liveblocks.
@@ -169,9 +188,7 @@ declare class Liveblocks {
169
188
  * add here will be visible to all other clients in the room, through the
170
189
  * `other.info` property.
171
190
  */
172
- identifyUser(identity: string | Identity, options?: {
173
- userInfo: IUserInfo;
174
- }): Promise<AuthResponse>;
191
+ identifyUser(identity: string | Identity, options?: IdentifyUserOptions<U>): Promise<AuthResponse>;
175
192
  /**
176
193
  * 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.
177
194
  * @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.
@@ -223,7 +240,7 @@ declare class Liveblocks {
223
240
  }): Promise<{
224
241
  nextPage: string | null;
225
242
  nextCursor: string | null;
226
- data: RoomInfo[];
243
+ data: RoomData[];
227
244
  }>;
228
245
  /**
229
246
  * Creates a new room with the given id.
@@ -239,13 +256,13 @@ declare class Liveblocks {
239
256
  groupsAccesses?: RoomAccesses;
240
257
  usersAccesses?: RoomAccesses;
241
258
  metadata?: RoomMetadata;
242
- }): Promise<RoomInfo>;
259
+ }): Promise<RoomData>;
243
260
  /**
244
261
  * Returns a room with the given id.
245
262
  * @param roomId The id of the room to return.
246
263
  * @returns The room with the given id.
247
264
  */
248
- getRoom(roomId: string): Promise<RoomInfo>;
265
+ getRoom(roomId: string): Promise<RoomData>;
249
266
  /**
250
267
  * Updates specific properties of a room. It’s not necessary to provide the entire room’s information.
251
268
  * Setting a property to `null` means to delete this property.
@@ -265,7 +282,7 @@ declare class Liveblocks {
265
282
  "room:write"
266
283
  ] | ["room:read", "room:presence:write"] | null>;
267
284
  metadata?: Record<string, string | string[] | null>;
268
- }): Promise<RoomInfo>;
285
+ }): Promise<RoomData>;
269
286
  /**
270
287
  * 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.
271
288
  * @param roomId The id of the room to delete.
@@ -276,15 +293,15 @@ declare class Liveblocks {
276
293
  * @param roomId The id of the room to get the users from.
277
294
  * @returns A list of users currently present in the requested room.
278
295
  */
279
- getActiveUsers<T = unknown>(roomId: string): Promise<{
280
- data: RoomUser<T>[];
296
+ getActiveUsers(roomId: string): Promise<{
297
+ data: RoomUser<U>[];
281
298
  }>;
282
299
  /**
283
300
  * 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.
284
301
  * @param roomId The id of the room to broadcast the event to.
285
302
  * @param message The message to broadcast. It can be any JSON serializable value.
286
303
  */
287
- broadcastEvent(roomId: string, message: Json): Promise<void>;
304
+ broadcastEvent(roomId: string, message: E): Promise<void>;
288
305
  /**
289
306
  * Returns the contents of the room’s Storage tree.
290
307
  * The default outputted format is called “plain LSON”, which includes information on the Live data structures in the tree.
@@ -305,7 +322,7 @@ declare class Liveblocks {
305
322
  */
306
323
  getStorageDocument(roomId: string, format: "plain-lson"): Promise<PlainLsonObject>;
307
324
  getStorageDocument(roomId: string): Promise<PlainLsonObject>;
308
- getStorageDocument(roomId: string, format: "json"): Promise<JsonObject>;
325
+ getStorageDocument(roomId: string, format: "json"): Promise<ToSimplifiedJson<S>>;
309
326
  /**
310
327
  * Initializes a room’s Storage. The room must already exist and have an empty Storage.
311
328
  * Calling this endpoint will disconnect all users from the room if there are any.
@@ -405,7 +422,7 @@ declare class Liveblocks {
405
422
  * @param params.query The query to filter threads by. It is based on our query language and can filter by metadata.
406
423
  * @returns A list of threads.
407
424
  */
408
- getThreads<M extends BaseMetadata = DM>(params: {
425
+ getThreads(params: {
409
426
  roomId: string;
410
427
  /**
411
428
  * The query to filter threads by. It is based on our query language.
@@ -445,7 +462,7 @@ declare class Liveblocks {
445
462
  * @param params.threadId The thread ID.
446
463
  * @returns A thread.
447
464
  */
448
- getThread<M extends BaseMetadata = DM>(params: {
465
+ getThread(params: {
449
466
  roomId: string;
450
467
  threadId: string;
451
468
  }): Promise<ThreadData<M>>;
@@ -534,17 +551,7 @@ declare class Liveblocks {
534
551
  * @param params.thread.comment.body The body of the comment.
535
552
  * @returns The created thread. The thread will be created with the specified comment as its first comment.
536
553
  */
537
- createThread<M extends BaseMetadata = DM>(params: {
538
- roomId: string;
539
- data: {
540
- metadata?: [M] extends [never] ? Record<string, never> : M;
541
- comment: {
542
- userId: string;
543
- createdAt?: Date;
544
- body: CommentBody;
545
- };
546
- };
547
- }): Promise<ThreadData<M>>;
554
+ createThread(params: CreateThreadOptions<M>): Promise<ThreadData<M>>;
548
555
  /**
549
556
  * Updates the metadata of the specified thread in a room.
550
557
  * @param params.roomId The room ID to update the thread in.
@@ -554,11 +561,11 @@ declare class Liveblocks {
554
561
  * @param params.data.updatedAt (optional) The date the thread is set to be updated.
555
562
  * @returns The updated thread.
556
563
  */
557
- editThreadMetadata<M extends BaseMetadata = DM>(params: {
564
+ editThreadMetadata(params: {
558
565
  roomId: string;
559
566
  threadId: string;
560
567
  data: {
561
- metadata: Nullable<BaseMetadata>;
568
+ metadata: Patchable<M>;
562
569
  userId: string;
563
570
  updatedAt?: Date;
564
571
  };
@@ -648,7 +655,7 @@ declare class Liveblocks {
648
655
  updateRoomId(params: {
649
656
  currentRoomId: string;
650
657
  newRoomId: string;
651
- }): Promise<RoomInfo>;
658
+ }): Promise<RoomData>;
652
659
  triggerInboxNotification(params: {
653
660
  userId: string;
654
661
  kind: `$${string}`;
@@ -904,7 +911,7 @@ declare type ThreadCreatedEvent = {
904
911
  createdBy: string;
905
912
  };
906
913
  };
907
- declare type NotificationEvent = {
914
+ declare type ThreadNotificationEvent = {
908
915
  type: "notification";
909
916
  data: {
910
917
  channel: "email";
@@ -921,5 +928,48 @@ declare type NotificationEvent = {
921
928
  createdAt: string;
922
929
  };
923
930
  };
931
+ declare type TextMentionNotificationEvent = {
932
+ type: "notification";
933
+ data: {
934
+ channel: "email";
935
+ kind: "textMention";
936
+ projectId: string;
937
+ roomId: string;
938
+ userId: string;
939
+ mentionId: string;
940
+ inboxNotificationId: string;
941
+ /**
942
+ * ISO 8601 datestring
943
+ * @example "2021-03-01T12:00:00.000Z"
944
+ */
945
+ createdAt: string;
946
+ };
947
+ };
948
+ declare type CustomKind = `$${string}`;
949
+ declare type CustomNotificationEvent = {
950
+ type: "notification";
951
+ data: {
952
+ channel: "email";
953
+ kind: CustomKind;
954
+ projectId: string;
955
+ roomId: string | null;
956
+ userId: string;
957
+ subjectId: string;
958
+ inboxNotificationId: string;
959
+ /**
960
+ * ISO 8601 datestring
961
+ * @example "2021-03-01T12:00:00.000Z"
962
+ */
963
+ createdAt: string;
964
+ };
965
+ };
966
+ declare type NotificationEvent = ThreadNotificationEvent | TextMentionNotificationEvent | CustomNotificationEvent;
967
+
968
+ /**
969
+ * @deprecated RoomInfo was renamed to RoomData, to avoid
970
+ * confusion with the globally augmentable RoomInfo type. This
971
+ * alias will be removed in a future version.
972
+ */
973
+ declare type RoomInfo = RoomData;
924
974
 
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 };
975
+ export { type CommentCreatedEvent, type CommentDeletedEvent, type CommentEditedEvent, type CommentReactionAdded, type CommentReactionRemoved, Liveblocks, LiveblocksError, type LiveblocksOptions, type NotificationEvent, type RoomAccesses, type RoomCreatedEvent, type RoomData, 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 };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IUserInfo, Json, PlainLsonObject, JsonObject, BaseMetadata, DM, QueryMetadata, ThreadData, CommentData, CommentBody, CommentUserReaction, InboxNotificationData, RoomNotificationSettings, ActivityData } from '@liveblocks/core';
1
+ import { BaseUserMeta, PlainLsonObject, JsonObject, QueryMetadata, ThreadData, CommentData, CommentBody, Patchable, CommentUserReaction, InboxNotificationData, RoomNotificationSettings, ActivityData, LsonObject, ToImmutable, DU, BaseMetadata, DE, DM, DS } from '@liveblocks/core';
2
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
 
@@ -57,6 +57,7 @@ declare class Session {
57
57
  * @liveblocks/core has browser-specific code.
58
58
  */
59
59
 
60
+ declare type ToSimplifiedJson<S extends LsonObject> = LsonObject extends S ? JsonObject : ToImmutable<S>;
60
61
  declare type LiveblocksOptions = {
61
62
  /**
62
63
  * The Liveblocks secret key. Must start with "sk_".
@@ -64,11 +65,11 @@ declare type LiveblocksOptions = {
64
65
  */
65
66
  secret: string;
66
67
  };
67
- declare type Nullable<T> = {
68
- [P in keyof T]: T[P] | null;
68
+ declare type CreateSessionOptions<U extends BaseUserMeta = DU> = {
69
+ userInfo: U["info"];
69
70
  };
70
- declare type CreateSessionOptions = {
71
- userInfo: IUserInfo;
71
+ declare type IdentifyUserOptions<U extends BaseUserMeta = DU> = {
72
+ userInfo: U["info"];
72
73
  };
73
74
  declare type AuthResponse = {
74
75
  status: number;
@@ -82,13 +83,27 @@ declare type Identity = {
82
83
  declare type ThreadParticipants = {
83
84
  participantIds: string[];
84
85
  };
86
+ declare type CreateThreadOptions<M extends BaseMetadata> = {
87
+ roomId: string;
88
+ data: {
89
+ comment: {
90
+ userId: string;
91
+ createdAt?: Date;
92
+ body: CommentBody;
93
+ };
94
+ } & (Record<string, never> extends M ? {
95
+ metadata?: M;
96
+ } : {
97
+ metadata: M;
98
+ });
99
+ };
85
100
  declare type RoomPermission = [] | ["room:write"] | ["room:read", "room:presence:write"];
86
101
  declare type RoomAccesses = Record<string, [
87
102
  "room:write"
88
103
  ] | ["room:read", "room:presence:write"]>;
89
104
  declare type RoomMetadata = Record<string, string | string[]>;
90
105
  declare type QueryRoomMetadata = Record<string, string>;
91
- declare type RoomInfo = {
106
+ declare type RoomData = {
92
107
  type: "room";
93
108
  id: string;
94
109
  createdAt: Date;
@@ -98,11 +113,11 @@ declare type RoomInfo = {
98
113
  groupsAccesses: RoomAccesses;
99
114
  metadata: RoomMetadata;
100
115
  };
101
- declare type RoomUser<Info> = {
116
+ declare type RoomUser<U extends BaseUserMeta> = {
102
117
  type: "user";
103
118
  id: string | null;
104
119
  connectionId: number;
105
- info: Info;
120
+ info: U["info"];
106
121
  };
107
122
  declare type Schema = {
108
123
  id: string;
@@ -112,6 +127,10 @@ declare type Schema = {
112
127
  createdAt: Date;
113
128
  updatedAt: Date;
114
129
  };
130
+ declare type E = DE;
131
+ declare type M = DM;
132
+ declare type S = DS;
133
+ declare type U = DU;
115
134
  /**
116
135
  * Interact with the Liveblocks API from your Node.js backend.
117
136
  */
@@ -136,7 +155,7 @@ declare class Liveblocks {
136
155
  * `other.info` property.
137
156
  *
138
157
  */
139
- prepareSession(userId: string, options?: CreateSessionOptions): Session;
158
+ prepareSession(userId: string, options?: CreateSessionOptions<U>): Session;
140
159
  /**
141
160
  * Call this to authenticate the user as an actor you want to allow to use
142
161
  * Liveblocks.
@@ -169,9 +188,7 @@ declare class Liveblocks {
169
188
  * add here will be visible to all other clients in the room, through the
170
189
  * `other.info` property.
171
190
  */
172
- identifyUser(identity: string | Identity, options?: {
173
- userInfo: IUserInfo;
174
- }): Promise<AuthResponse>;
191
+ identifyUser(identity: string | Identity, options?: IdentifyUserOptions<U>): Promise<AuthResponse>;
175
192
  /**
176
193
  * 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.
177
194
  * @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.
@@ -223,7 +240,7 @@ declare class Liveblocks {
223
240
  }): Promise<{
224
241
  nextPage: string | null;
225
242
  nextCursor: string | null;
226
- data: RoomInfo[];
243
+ data: RoomData[];
227
244
  }>;
228
245
  /**
229
246
  * Creates a new room with the given id.
@@ -239,13 +256,13 @@ declare class Liveblocks {
239
256
  groupsAccesses?: RoomAccesses;
240
257
  usersAccesses?: RoomAccesses;
241
258
  metadata?: RoomMetadata;
242
- }): Promise<RoomInfo>;
259
+ }): Promise<RoomData>;
243
260
  /**
244
261
  * Returns a room with the given id.
245
262
  * @param roomId The id of the room to return.
246
263
  * @returns The room with the given id.
247
264
  */
248
- getRoom(roomId: string): Promise<RoomInfo>;
265
+ getRoom(roomId: string): Promise<RoomData>;
249
266
  /**
250
267
  * Updates specific properties of a room. It’s not necessary to provide the entire room’s information.
251
268
  * Setting a property to `null` means to delete this property.
@@ -265,7 +282,7 @@ declare class Liveblocks {
265
282
  "room:write"
266
283
  ] | ["room:read", "room:presence:write"] | null>;
267
284
  metadata?: Record<string, string | string[] | null>;
268
- }): Promise<RoomInfo>;
285
+ }): Promise<RoomData>;
269
286
  /**
270
287
  * 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.
271
288
  * @param roomId The id of the room to delete.
@@ -276,15 +293,15 @@ declare class Liveblocks {
276
293
  * @param roomId The id of the room to get the users from.
277
294
  * @returns A list of users currently present in the requested room.
278
295
  */
279
- getActiveUsers<T = unknown>(roomId: string): Promise<{
280
- data: RoomUser<T>[];
296
+ getActiveUsers(roomId: string): Promise<{
297
+ data: RoomUser<U>[];
281
298
  }>;
282
299
  /**
283
300
  * 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.
284
301
  * @param roomId The id of the room to broadcast the event to.
285
302
  * @param message The message to broadcast. It can be any JSON serializable value.
286
303
  */
287
- broadcastEvent(roomId: string, message: Json): Promise<void>;
304
+ broadcastEvent(roomId: string, message: E): Promise<void>;
288
305
  /**
289
306
  * Returns the contents of the room’s Storage tree.
290
307
  * The default outputted format is called “plain LSON”, which includes information on the Live data structures in the tree.
@@ -305,7 +322,7 @@ declare class Liveblocks {
305
322
  */
306
323
  getStorageDocument(roomId: string, format: "plain-lson"): Promise<PlainLsonObject>;
307
324
  getStorageDocument(roomId: string): Promise<PlainLsonObject>;
308
- getStorageDocument(roomId: string, format: "json"): Promise<JsonObject>;
325
+ getStorageDocument(roomId: string, format: "json"): Promise<ToSimplifiedJson<S>>;
309
326
  /**
310
327
  * Initializes a room’s Storage. The room must already exist and have an empty Storage.
311
328
  * Calling this endpoint will disconnect all users from the room if there are any.
@@ -405,7 +422,7 @@ declare class Liveblocks {
405
422
  * @param params.query The query to filter threads by. It is based on our query language and can filter by metadata.
406
423
  * @returns A list of threads.
407
424
  */
408
- getThreads<M extends BaseMetadata = DM>(params: {
425
+ getThreads(params: {
409
426
  roomId: string;
410
427
  /**
411
428
  * The query to filter threads by. It is based on our query language.
@@ -445,7 +462,7 @@ declare class Liveblocks {
445
462
  * @param params.threadId The thread ID.
446
463
  * @returns A thread.
447
464
  */
448
- getThread<M extends BaseMetadata = DM>(params: {
465
+ getThread(params: {
449
466
  roomId: string;
450
467
  threadId: string;
451
468
  }): Promise<ThreadData<M>>;
@@ -534,17 +551,7 @@ declare class Liveblocks {
534
551
  * @param params.thread.comment.body The body of the comment.
535
552
  * @returns The created thread. The thread will be created with the specified comment as its first comment.
536
553
  */
537
- createThread<M extends BaseMetadata = DM>(params: {
538
- roomId: string;
539
- data: {
540
- metadata?: [M] extends [never] ? Record<string, never> : M;
541
- comment: {
542
- userId: string;
543
- createdAt?: Date;
544
- body: CommentBody;
545
- };
546
- };
547
- }): Promise<ThreadData<M>>;
554
+ createThread(params: CreateThreadOptions<M>): Promise<ThreadData<M>>;
548
555
  /**
549
556
  * Updates the metadata of the specified thread in a room.
550
557
  * @param params.roomId The room ID to update the thread in.
@@ -554,11 +561,11 @@ declare class Liveblocks {
554
561
  * @param params.data.updatedAt (optional) The date the thread is set to be updated.
555
562
  * @returns The updated thread.
556
563
  */
557
- editThreadMetadata<M extends BaseMetadata = DM>(params: {
564
+ editThreadMetadata(params: {
558
565
  roomId: string;
559
566
  threadId: string;
560
567
  data: {
561
- metadata: Nullable<BaseMetadata>;
568
+ metadata: Patchable<M>;
562
569
  userId: string;
563
570
  updatedAt?: Date;
564
571
  };
@@ -648,7 +655,7 @@ declare class Liveblocks {
648
655
  updateRoomId(params: {
649
656
  currentRoomId: string;
650
657
  newRoomId: string;
651
- }): Promise<RoomInfo>;
658
+ }): Promise<RoomData>;
652
659
  triggerInboxNotification(params: {
653
660
  userId: string;
654
661
  kind: `$${string}`;
@@ -904,7 +911,7 @@ declare type ThreadCreatedEvent = {
904
911
  createdBy: string;
905
912
  };
906
913
  };
907
- declare type NotificationEvent = {
914
+ declare type ThreadNotificationEvent = {
908
915
  type: "notification";
909
916
  data: {
910
917
  channel: "email";
@@ -921,5 +928,48 @@ declare type NotificationEvent = {
921
928
  createdAt: string;
922
929
  };
923
930
  };
931
+ declare type TextMentionNotificationEvent = {
932
+ type: "notification";
933
+ data: {
934
+ channel: "email";
935
+ kind: "textMention";
936
+ projectId: string;
937
+ roomId: string;
938
+ userId: string;
939
+ mentionId: string;
940
+ inboxNotificationId: string;
941
+ /**
942
+ * ISO 8601 datestring
943
+ * @example "2021-03-01T12:00:00.000Z"
944
+ */
945
+ createdAt: string;
946
+ };
947
+ };
948
+ declare type CustomKind = `$${string}`;
949
+ declare type CustomNotificationEvent = {
950
+ type: "notification";
951
+ data: {
952
+ channel: "email";
953
+ kind: CustomKind;
954
+ projectId: string;
955
+ roomId: string | null;
956
+ userId: string;
957
+ subjectId: string;
958
+ inboxNotificationId: string;
959
+ /**
960
+ * ISO 8601 datestring
961
+ * @example "2021-03-01T12:00:00.000Z"
962
+ */
963
+ createdAt: string;
964
+ };
965
+ };
966
+ declare type NotificationEvent = ThreadNotificationEvent | TextMentionNotificationEvent | CustomNotificationEvent;
967
+
968
+ /**
969
+ * @deprecated RoomInfo was renamed to RoomData, to avoid
970
+ * confusion with the globally augmentable RoomInfo type. This
971
+ * alias will be removed in a future version.
972
+ */
973
+ declare type RoomInfo = RoomData;
924
974
 
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 };
975
+ export { type CommentCreatedEvent, type CommentDeletedEvent, type CommentEditedEvent, type CommentReactionAdded, type CommentReactionRemoved, Liveblocks, LiveblocksError, type LiveblocksOptions, type NotificationEvent, type RoomAccesses, type RoomCreatedEvent, type RoomData, 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 };
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ var _core = require('@liveblocks/core');
3
3
 
4
4
  // src/version.ts
5
5
  var PKG_NAME = "@liveblocks/node";
6
- var PKG_VERSION = "2.0.0-alpha1";
6
+ var PKG_VERSION = "2.0.0-alpha2";
7
7
  var PKG_FORMAT = "cjs";
8
8
 
9
9
  // src/client.ts
@@ -1113,10 +1113,8 @@ var _base64 = require('@stablelib/base64'); var base64 = _interopRequireWildcard
1113
1113
  var _fastsha256 = require('fast-sha256'); var sha256 = _interopRequireWildcard(_fastsha256);
1114
1114
  var _WebhookHandler = class _WebhookHandler {
1115
1115
  constructor(secret) {
1116
- if (!secret)
1117
- throw new Error("Secret is required");
1118
- if (typeof secret !== "string")
1119
- throw new Error("Secret must be a string");
1116
+ if (!secret) throw new Error("Secret is required");
1117
+ if (typeof secret !== "string") throw new Error("Secret must be a string");
1120
1118
  if (secret.startsWith(_WebhookHandler.secretPrefix) === false)
1121
1119
  throw new Error("Invalid secret, must start with whsec_");
1122
1120
  const secretKey = secret.slice(_WebhookHandler.secretPrefix.length);
@@ -1216,8 +1214,19 @@ var _WebhookHandler = class _WebhookHandler {
1216
1214
  "threadCreated",
1217
1215
  "ydocUpdated",
1218
1216
  "notification"
1219
- ].includes(event.type))
1217
+ ].includes(event.type)) {
1218
+ if (event.type === "notification") {
1219
+ const notification = event;
1220
+ if (notification.data.kind === "thread" || notification.data.kind === "textMention" || notification.data.kind.startsWith("$")) {
1221
+ return;
1222
+ } else {
1223
+ throw new Error(
1224
+ `Unknown notification kind: ${notification.data.kind}`
1225
+ );
1226
+ }
1227
+ }
1220
1228
  return;
1229
+ }
1221
1230
  throw new Error(
1222
1231
  "Unknown event type, please upgrade to a higher version of @liveblocks/node"
1223
1232
  );