@liveblocks/node 1.8.1 → 1.8.3-oss1
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 +131 -256
- package/dist/index.d.ts +131 -256
- package/dist/index.js +204 -311
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +200 -307
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
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
3
|
import { IncomingHttpHeaders } from 'http';
|
|
2
4
|
|
|
3
5
|
/**
|
|
@@ -88,174 +90,6 @@ declare type AuthorizeResponse = {
|
|
|
88
90
|
*/
|
|
89
91
|
declare function authorize(options: AuthorizeOptions): Promise<AuthorizeResponse>;
|
|
90
92
|
|
|
91
|
-
/**
|
|
92
|
-
* Represents an indefinitely deep arbitrary JSON data structure. There are
|
|
93
|
-
* four types that make up the Json family:
|
|
94
|
-
*
|
|
95
|
-
* - Json any legal JSON value
|
|
96
|
-
* - JsonScalar any legal JSON leaf value (no lists or objects)
|
|
97
|
-
* - JsonArray a JSON value whose outer type is an array
|
|
98
|
-
* - JsonObject a JSON value whose outer type is an object
|
|
99
|
-
*
|
|
100
|
-
*/
|
|
101
|
-
declare type Json = JsonScalar | JsonArray | JsonObject;
|
|
102
|
-
declare type JsonScalar = string | number | boolean | null;
|
|
103
|
-
declare type JsonArray = Json[];
|
|
104
|
-
declare type JsonObject = {
|
|
105
|
-
[key: string]: Json | undefined;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* "Plain LSON" is a JSON-based format that's used when serializing Live structures
|
|
110
|
-
* to send them over HTTP (e.g. in the API endpoint to let users upload their initial
|
|
111
|
-
* Room storage, in the API endpoint to fetch a Room's storage, ...).
|
|
112
|
-
*
|
|
113
|
-
* In the client, you would typically create LSON values using:
|
|
114
|
-
*
|
|
115
|
-
* new LiveObject({ x: 0, y: 0 })
|
|
116
|
-
*
|
|
117
|
-
* But over HTTP, this has to be serialized somehow. The "Plain LSON" format
|
|
118
|
-
* is what's used in the POST /init-storage-new endpoint, to allow users to
|
|
119
|
-
* control which parts of their data structure should be considered "Live"
|
|
120
|
-
* objects, and which parts are "normal" objects.
|
|
121
|
-
*
|
|
122
|
-
* So if they have a structure like:
|
|
123
|
-
*
|
|
124
|
-
* { x: 0, y: 0 }
|
|
125
|
-
*
|
|
126
|
-
* And want to make it a Live object, they can serialize it by wrapping it in
|
|
127
|
-
* a special "annotation":
|
|
128
|
-
*
|
|
129
|
-
* {
|
|
130
|
-
* "liveblocksType": "LiveObject",
|
|
131
|
-
* "data": { x: 0, y: 0 },
|
|
132
|
-
* }
|
|
133
|
-
*
|
|
134
|
-
* This "Plain LSON" data format defines exactly those wrappings.
|
|
135
|
-
*
|
|
136
|
-
* To summarize:
|
|
137
|
-
*
|
|
138
|
-
* LSON value | Plain LSON equivalent
|
|
139
|
-
* ----------------------+----------------------------------------------
|
|
140
|
-
* 42 | 42
|
|
141
|
-
* [1, 2, 3] | [1, 2, 3]
|
|
142
|
-
* { x: 0, y: 0 } | { x: 0, y: 0 }
|
|
143
|
-
* ----------------------+----------------------------------------------
|
|
144
|
-
* new LiveList(...) | { liveblocksType: "LiveList", data: ... }
|
|
145
|
-
* new LiveMap(...) | { liveblocksType: "LiveMap", data: ... }
|
|
146
|
-
* new LiveObject(...) | { liveblocksType: "LiveObject", data: ... }
|
|
147
|
-
*
|
|
148
|
-
*/
|
|
149
|
-
|
|
150
|
-
declare type PlainLsonFields = Record<string, PlainLson>;
|
|
151
|
-
declare type PlainLsonObject = {
|
|
152
|
-
liveblocksType: "LiveObject";
|
|
153
|
-
data: PlainLsonFields;
|
|
154
|
-
};
|
|
155
|
-
declare type PlainLsonMap = {
|
|
156
|
-
liveblocksType: "LiveMap";
|
|
157
|
-
data: PlainLsonFields;
|
|
158
|
-
};
|
|
159
|
-
declare type PlainLsonList = {
|
|
160
|
-
liveblocksType: "LiveList";
|
|
161
|
-
data: PlainLson[];
|
|
162
|
-
};
|
|
163
|
-
declare type PlainLson = PlainLsonObject | PlainLsonMap | PlainLsonList | Json;
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Represents some constraints for user info. Basically read this as: "any JSON
|
|
167
|
-
* object is fine, but _if_ it has a name field, it _must_ be a string."
|
|
168
|
-
* (Ditto for avatar.)
|
|
169
|
-
*/
|
|
170
|
-
declare type IUserInfo = {
|
|
171
|
-
[key: string]: Json | undefined;
|
|
172
|
-
name?: string;
|
|
173
|
-
avatar?: string;
|
|
174
|
-
};
|
|
175
|
-
/**
|
|
176
|
-
* This type is used by clients to define the metadata for a user.
|
|
177
|
-
*/
|
|
178
|
-
declare type BaseUserMeta = {
|
|
179
|
-
/**
|
|
180
|
-
* The id of the user that has been set in the authentication endpoint.
|
|
181
|
-
* Useful to get additional information about the connected user.
|
|
182
|
-
*/
|
|
183
|
-
id?: string;
|
|
184
|
-
/**
|
|
185
|
-
* Additional user information that has been set in the authentication endpoint.
|
|
186
|
-
*/
|
|
187
|
-
info?: IUserInfo;
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
declare type BaseMetadata = Record<string, string | boolean | number>;
|
|
191
|
-
|
|
192
|
-
declare type CommentBodyBlockElement = CommentBodyParagraph;
|
|
193
|
-
declare type CommentBodyInlineElement = CommentBodyText | CommentBodyMention | CommentBodyLink;
|
|
194
|
-
declare type CommentBodyParagraph = {
|
|
195
|
-
type: "paragraph";
|
|
196
|
-
children: CommentBodyInlineElement[];
|
|
197
|
-
};
|
|
198
|
-
declare type CommentBodyMention = {
|
|
199
|
-
type: "mention";
|
|
200
|
-
id: string;
|
|
201
|
-
};
|
|
202
|
-
declare type CommentBodyLink = {
|
|
203
|
-
type: "link";
|
|
204
|
-
url: string;
|
|
205
|
-
};
|
|
206
|
-
declare type CommentBodyText = {
|
|
207
|
-
bold?: boolean;
|
|
208
|
-
italic?: boolean;
|
|
209
|
-
strikethrough?: boolean;
|
|
210
|
-
code?: boolean;
|
|
211
|
-
text: string;
|
|
212
|
-
};
|
|
213
|
-
declare type CommentBody = {
|
|
214
|
-
version: 1;
|
|
215
|
-
content: CommentBodyBlockElement[];
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
declare type CommentReactionUser = {
|
|
219
|
-
id: string;
|
|
220
|
-
};
|
|
221
|
-
declare type CommentReaction = {
|
|
222
|
-
emoji: string;
|
|
223
|
-
createdAt: string;
|
|
224
|
-
users: CommentReactionUser[];
|
|
225
|
-
};
|
|
226
|
-
/**
|
|
227
|
-
* Represents a comment.
|
|
228
|
-
*/
|
|
229
|
-
declare type CommentData = {
|
|
230
|
-
type: "comment";
|
|
231
|
-
id: string;
|
|
232
|
-
threadId: string;
|
|
233
|
-
roomId: string;
|
|
234
|
-
userId: string;
|
|
235
|
-
createdAt: string;
|
|
236
|
-
editedAt?: string;
|
|
237
|
-
reactions: CommentReaction[];
|
|
238
|
-
} & ({
|
|
239
|
-
body: CommentBody;
|
|
240
|
-
deletedAt?: never;
|
|
241
|
-
} | {
|
|
242
|
-
body?: never;
|
|
243
|
-
deletedAt: string;
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Represents a thread of comments.
|
|
248
|
-
*/
|
|
249
|
-
declare type ThreadData<TThreadMetadata extends BaseMetadata = never> = {
|
|
250
|
-
type: "thread";
|
|
251
|
-
id: string;
|
|
252
|
-
roomId: string;
|
|
253
|
-
createdAt: string;
|
|
254
|
-
updatedAt?: string;
|
|
255
|
-
comments: CommentData[];
|
|
256
|
-
metadata: [TThreadMetadata] extends [never] ? Record<string, never> : TThreadMetadata;
|
|
257
|
-
};
|
|
258
|
-
|
|
259
93
|
declare const ALL_PERMISSIONS: readonly ["room:write", "room:read", "room:presence:write", "comments:write", "comments:read"];
|
|
260
94
|
declare type Permission = (typeof ALL_PERMISSIONS)[number];
|
|
261
95
|
/**
|
|
@@ -318,6 +152,9 @@ declare type LiveblocksOptions = {
|
|
|
318
152
|
*/
|
|
319
153
|
secret: string;
|
|
320
154
|
};
|
|
155
|
+
declare type Nullable<T> = {
|
|
156
|
+
[P in keyof T]: T[P] | null;
|
|
157
|
+
};
|
|
321
158
|
declare type CreateSessionOptions = {
|
|
322
159
|
userInfo: IUserInfo;
|
|
323
160
|
};
|
|
@@ -492,7 +329,9 @@ declare class Liveblocks {
|
|
|
492
329
|
* @param roomId The id of the room to get the users from.
|
|
493
330
|
* @returns A list of users currently present in the requested room.
|
|
494
331
|
*/
|
|
495
|
-
getActiveUsers<T = unknown>(roomId: string): Promise<
|
|
332
|
+
getActiveUsers<T = unknown>(roomId: string): Promise<{
|
|
333
|
+
data: RoomUser<T>[];
|
|
334
|
+
}>;
|
|
496
335
|
/**
|
|
497
336
|
* 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.
|
|
498
337
|
* @param roomId The id of the room to broadcast the event to.
|
|
@@ -626,10 +465,10 @@ declare class Liveblocks {
|
|
|
626
465
|
* @param params.threadId The thread ID.
|
|
627
466
|
* @returns A thread.
|
|
628
467
|
*/
|
|
629
|
-
getThread(params: {
|
|
468
|
+
getThread<TThreadMetadata extends BaseMetadata = never>(params: {
|
|
630
469
|
roomId: string;
|
|
631
470
|
threadId: string;
|
|
632
|
-
}): Promise<ThreadData
|
|
471
|
+
}): Promise<ThreadData<TThreadMetadata>>;
|
|
633
472
|
/**
|
|
634
473
|
* Gets a thread's participants.
|
|
635
474
|
*
|
|
@@ -657,97 +496,133 @@ declare class Liveblocks {
|
|
|
657
496
|
threadId: string;
|
|
658
497
|
commentId: string;
|
|
659
498
|
}): Promise<CommentData>;
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
declare type PromiseOrNot<T> = T | Promise<T>;
|
|
663
|
-
declare type CommentBodyResolveUsersArgs = {
|
|
664
499
|
/**
|
|
665
|
-
*
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
* The
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
element: CommentBodyText;
|
|
684
|
-
};
|
|
685
|
-
declare type CommentBodyLinkElementArgs = {
|
|
686
|
-
/**
|
|
687
|
-
* The link element.
|
|
688
|
-
*/
|
|
689
|
-
element: CommentBodyLink;
|
|
690
|
-
/**
|
|
691
|
-
* The absolute URL of the link.
|
|
692
|
-
*/
|
|
693
|
-
href: string;
|
|
694
|
-
};
|
|
695
|
-
declare type CommentBodyMentionElementArgs<TUserMeta extends BaseUserMeta = BaseUserMeta> = {
|
|
696
|
-
/**
|
|
697
|
-
* The mention element.
|
|
698
|
-
*/
|
|
699
|
-
element: CommentBodyMention;
|
|
700
|
-
/**
|
|
701
|
-
* The mention's user info, if the `resolvedUsers` option was provided.
|
|
702
|
-
*/
|
|
703
|
-
user?: TUserMeta["info"];
|
|
704
|
-
};
|
|
705
|
-
declare type StringifyCommentBodyElements<TUserMeta extends BaseUserMeta = BaseUserMeta> = {
|
|
706
|
-
/**
|
|
707
|
-
* The element used to display paragraphs.
|
|
708
|
-
*/
|
|
709
|
-
paragraph: (args: CommentBodyParagraphElementArgs, index: number) => string;
|
|
710
|
-
/**
|
|
711
|
-
* The element used to display text elements.
|
|
712
|
-
*/
|
|
713
|
-
text: (args: CommentBodyTextElementArgs, index: number) => string;
|
|
714
|
-
/**
|
|
715
|
-
* The element used to display links.
|
|
716
|
-
*/
|
|
717
|
-
link: (args: CommentBodyLinkElementArgs, index: number) => string;
|
|
718
|
-
/**
|
|
719
|
-
* The element used to display mentions.
|
|
720
|
-
*/
|
|
721
|
-
mention: (args: CommentBodyMentionElementArgs<TUserMeta>, index: number) => string;
|
|
722
|
-
};
|
|
723
|
-
declare type StringifyCommentBodyOptions<TUserMeta extends BaseUserMeta = BaseUserMeta> = {
|
|
724
|
-
/**
|
|
725
|
-
* Which format to convert the comment to.
|
|
726
|
-
*/
|
|
727
|
-
format?: "plain" | "html" | "markdown";
|
|
500
|
+
* Creates a comment.
|
|
501
|
+
*
|
|
502
|
+
* @param params.roomId The room ID to create the comment in.
|
|
503
|
+
* @param params.threadId The thread ID to create the comment in.
|
|
504
|
+
* @param params.data.userId The user ID of the user who is set to create the comment.
|
|
505
|
+
* @param params.data.createdAt (optional) The date the comment is set to be created.
|
|
506
|
+
* @param params.data.body The body of the comment.
|
|
507
|
+
* @returns The created comment.
|
|
508
|
+
*/
|
|
509
|
+
createComment(params: {
|
|
510
|
+
roomId: string;
|
|
511
|
+
threadId: string;
|
|
512
|
+
data: {
|
|
513
|
+
userId: string;
|
|
514
|
+
createdAt?: Date;
|
|
515
|
+
body: CommentBody;
|
|
516
|
+
};
|
|
517
|
+
}): Promise<CommentData>;
|
|
728
518
|
/**
|
|
729
|
-
*
|
|
730
|
-
*
|
|
519
|
+
* Edits a comment.
|
|
520
|
+
* @param params.roomId The room ID to edit the comment in.
|
|
521
|
+
* @param params.threadId The thread ID to edit the comment in.
|
|
522
|
+
* @param params.commentId The comment ID to edit.
|
|
523
|
+
* @param params.data.body The body of the comment.
|
|
524
|
+
* @param params.data.editedAt (optional) The date the comment was edited.
|
|
525
|
+
* @returns The edited comment.
|
|
731
526
|
*/
|
|
732
|
-
|
|
527
|
+
editComment(params: {
|
|
528
|
+
roomId: string;
|
|
529
|
+
threadId: string;
|
|
530
|
+
commentId: string;
|
|
531
|
+
data: {
|
|
532
|
+
body: CommentBody;
|
|
533
|
+
editedAt?: Date;
|
|
534
|
+
};
|
|
535
|
+
}): Promise<CommentData>;
|
|
733
536
|
/**
|
|
734
|
-
*
|
|
537
|
+
* Deletes a comment. Deletes a comment. If there are no remaining comments in the thread, the thread is also deleted.
|
|
538
|
+
* @param params.roomId The room ID to delete the comment in.
|
|
539
|
+
* @param params.threadId The thread ID to delete the comment in.
|
|
540
|
+
* @param params.commentId The comment ID to delete.
|
|
735
541
|
*/
|
|
736
|
-
|
|
542
|
+
deleteComment(params: {
|
|
543
|
+
roomId: string;
|
|
544
|
+
threadId: string;
|
|
545
|
+
commentId: string;
|
|
546
|
+
}): Promise<void>;
|
|
737
547
|
/**
|
|
738
|
-
*
|
|
548
|
+
* Creates a new thread. The thread will be created with the specified comment as its first comment.
|
|
549
|
+
* If the thread already exists, a `LiveblocksError` will be thrown with status code 409.
|
|
550
|
+
* @param params.roomId The room ID to create the thread in.
|
|
551
|
+
* @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
|
|
552
|
+
* @param params.thread.comment.userId The user ID of the user who created the comment.
|
|
553
|
+
* @param params.thread.comment.createdAt (optional) The date the comment was created.
|
|
554
|
+
* @param params.thread.comment.body The body of the comment.
|
|
555
|
+
* @returns The created thread. The thread will be created with the specified comment as its first comment.
|
|
739
556
|
*/
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
557
|
+
createThread<TThreadMetadata extends BaseMetadata = never>(params: {
|
|
558
|
+
roomId: string;
|
|
559
|
+
data: {
|
|
560
|
+
metadata?: [TThreadMetadata] extends [never] ? Record<string, never> : TThreadMetadata;
|
|
561
|
+
comment: {
|
|
562
|
+
userId: string;
|
|
563
|
+
createdAt?: Date;
|
|
564
|
+
body: CommentBody;
|
|
565
|
+
};
|
|
566
|
+
};
|
|
567
|
+
}): Promise<ThreadData<TThreadMetadata>>;
|
|
568
|
+
/**
|
|
569
|
+
* Updates the metadata of the specified thread in a room.
|
|
570
|
+
* @param params.roomId The room ID to update the thread in.
|
|
571
|
+
* @param params.threadId The thread ID to update.
|
|
572
|
+
* @param params.data.metadata The metadata for the thread. Value must be a string, boolean or number
|
|
573
|
+
* @param params.data.userId The user ID of the user who updated the thread.
|
|
574
|
+
* @param params.data.updatedAt (optional) The date the thread is set to be updated.
|
|
575
|
+
* @returns The updated thread.
|
|
576
|
+
*/
|
|
577
|
+
editThreadMetadata<TThreadMetadata extends BaseMetadata = never>(params: {
|
|
578
|
+
roomId: string;
|
|
579
|
+
threadId: string;
|
|
580
|
+
data: {
|
|
581
|
+
metadata: Nullable<BaseMetadata>;
|
|
582
|
+
userId: string;
|
|
583
|
+
updatedAt?: Date;
|
|
584
|
+
};
|
|
585
|
+
}): Promise<TThreadMetadata>;
|
|
586
|
+
/**
|
|
587
|
+
* Adds a new comment reaction to a comment.
|
|
588
|
+
* @param params.roomId The room ID to add the comment reaction in.
|
|
589
|
+
* @param params.threadId The thread ID to add the comment reaction in.
|
|
590
|
+
* @param params.commentId The comment ID to add the reaction in.
|
|
591
|
+
* @param params.data.emoji The (emoji) reaction to add.
|
|
592
|
+
* @param params.data.userId The user ID of the user associated with the reaction.
|
|
593
|
+
* @param params.data.createdAt (optional) The date the reaction is set to be created.
|
|
594
|
+
* @returns The created comment reaction.
|
|
595
|
+
*/
|
|
596
|
+
addCommentReaction(params: {
|
|
597
|
+
roomId: string;
|
|
598
|
+
threadId: string;
|
|
599
|
+
commentId: string;
|
|
600
|
+
data: {
|
|
601
|
+
emoji: string;
|
|
602
|
+
userId: string;
|
|
603
|
+
createdAt?: Date;
|
|
604
|
+
};
|
|
605
|
+
}): Promise<CommentUserReaction>;
|
|
606
|
+
/**
|
|
607
|
+
* Removes a reaction from a comment.
|
|
608
|
+
* @param params.roomId The room ID to remove the comment reaction from.
|
|
609
|
+
* @param params.threadId The thread ID to remove the comment reaction from.
|
|
610
|
+
* @param params.commentId The comment ID to remove the reaction from.
|
|
611
|
+
* @param params.data.emoji The (emoji) reaction to remove.
|
|
612
|
+
* @param params.data.userId The user ID of the user associated with the reaction.
|
|
613
|
+
* @param params.data.removedAt (optional) The date the reaction is set to be removed.
|
|
614
|
+
*/
|
|
615
|
+
removeCommentReaction(params: {
|
|
616
|
+
roomId: string;
|
|
617
|
+
threadId: string;
|
|
618
|
+
commentId: string;
|
|
619
|
+
data: {
|
|
620
|
+
emoji: string;
|
|
621
|
+
userId: string;
|
|
622
|
+
removedAt?: Date;
|
|
623
|
+
};
|
|
624
|
+
}): Promise<void>;
|
|
625
|
+
}
|
|
751
626
|
|
|
752
627
|
declare class WebhookHandler {
|
|
753
628
|
private secretBuffer;
|
|
@@ -987,4 +862,4 @@ declare type ThreadCreatedEvent = {
|
|
|
987
862
|
};
|
|
988
863
|
};
|
|
989
864
|
|
|
990
|
-
export {
|
|
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 };
|