@liveblocks/node 3.23.0-exp2 → 3.23.0-exp4

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.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { Permission, Json, DFMD, FeedCreateMetadata, RoomPermissions, RoomAccesses, OptionalTupleUnless, BaseUserMeta, DU, PartialUnless, UpdateRoomAccesses, DE, JsonObject, PlainLsonObject, ToJson, DS, QueryMetadata, DTM, ThreadVisibility, ThreadData, DCM, UserSubscriptionData, CommentData, BaseMetadata, CommentBody, Patchable, SubscriptionData, CommentUserReaction, InboxNotificationData, UserRoomSubscriptionSettings, RoomSubscriptionSettings, KDAD, DAD, NotificationSettings, PartialNotificationSettings, GroupScopes, GroupData, LiveObject, Awaitable, DFM, Feed, FeedUpdateMetadata, FeedMessage, NotificationChannel } from '@liveblocks/core';
2
- export { CommentBody, CommentBodyBlockElement, CommentBodyElement, CommentBodyInlineElement, CommentBodyLink, CommentBodyLinkElementArgs, CommentBodyMention, CommentBodyMentionElementArgs, CommentBodyParagraph, CommentBodyParagraphElementArgs, CommentBodyText, CommentBodyTextElementArgs, CommentData, CommentUserReaction, IUserInfo, Json, JsonArray, JsonObject, JsonScalar, LiveList, LiveMap, LiveObject, LiveStructure, Lson, LsonObject, PlainLsonObject, ResolveUsersArgs, RoomAccesses, RoomPermissions, StringifyCommentBodyElements, StringifyCommentBodyOptions, ThreadData, User, getMentionsFromCommentBody, isNotificationChannelEnabled, stringifyCommentBody } from '@liveblocks/core';
1
+ import { Permission, Json, DFMD, FeedCreateMetadata, RoomPermissions, RoomAccesses, OptionalTupleUnless, BaseUserMeta, DU, PartialUnless, UpdateRoomAccesses, DE, JsonObject, PlainLsonObject, ToJson, DS, QueryMetadata, DTM, ThreadVisibility, ThreadData, DCM, UserSubscriptionData, CommentData, BaseMetadata, CommentBody, Patchable, CommentAttachment, LiveFile, LiveFileReference, SubscriptionData, CommentUserReaction, InboxNotificationData, UserRoomSubscriptionSettings, RoomSubscriptionSettings, KDAD, DAD, NotificationSettings, PartialNotificationSettings, GroupScopes, GroupData, LiveObject, Awaitable, DFM, Feed, FeedUpdateMetadata, FeedMessage, NotificationChannel } from '@liveblocks/core';
2
+ export { CommentAttachment, CommentBody, CommentBodyBlockElement, CommentBodyElement, CommentBodyInlineElement, CommentBodyLink, CommentBodyLinkElementArgs, CommentBodyMention, CommentBodyMentionElementArgs, CommentBodyParagraph, CommentBodyParagraphElementArgs, CommentBodyText, CommentBodyTextElementArgs, CommentData, CommentUserReaction, IUserInfo, Json, JsonArray, JsonObject, JsonScalar, LiveFile, LiveFileData, LiveList, LiveMap, LiveObject, LiveStructure, Lson, LsonObject, PlainLsonObject, ResolveUsersArgs, RoomAccesses, RoomPermissions, StringifyCommentBodyElements, StringifyCommentBodyOptions, ThreadData, User, getMentionsFromCommentBody, isNotificationChannelEnabled, stringifyCommentBody } from '@liveblocks/core';
3
3
  import { IncomingHttpHeaders } from 'http';
4
4
 
5
5
  /**
@@ -102,6 +102,10 @@ type AttachmentWithUrl = {
102
102
  url: string;
103
103
  expiresAt: string;
104
104
  };
105
+ type StorageFileUrl = {
106
+ url: string;
107
+ expiresAt: string;
108
+ };
105
109
  type CreateThreadOptions<TM extends BaseMetadata, CM extends BaseMetadata> = {
106
110
  roomId: string;
107
111
  data: {
@@ -110,6 +114,7 @@ type CreateThreadOptions<TM extends BaseMetadata, CM extends BaseMetadata> = {
110
114
  userId: string;
111
115
  createdAt?: Date;
112
116
  body: CommentBody;
117
+ attachmentIds?: string[];
113
118
  } & PartialUnless<CM, {
114
119
  metadata: CM;
115
120
  }>;
@@ -124,6 +129,7 @@ type CreateCommentOptions<CM extends BaseMetadata> = {
124
129
  userId: string;
125
130
  createdAt?: Date;
126
131
  body: CommentBody;
132
+ attachmentIds?: string[];
127
133
  } & PartialUnless<CM, {
128
134
  metadata: CM;
129
135
  }>;
@@ -926,6 +932,7 @@ declare class Liveblocks {
926
932
  * @param params.data.userId The user ID of the user who is set to create the comment.
927
933
  * @param params.data.createdAt (optional) The date the comment is set to be created.
928
934
  * @param params.data.body The body of the comment.
935
+ * @param params.data.attachmentIds (optional) The attachment IDs to add to the comment.
929
936
  * @param params.data.metadata (optional) The metadata for the comment.
930
937
  * @param options.signal (optional) An abort signal to cancel the request.
931
938
  * @returns The created comment.
@@ -937,6 +944,7 @@ declare class Liveblocks {
937
944
  * @param params.threadId The thread ID to edit the comment in.
938
945
  * @param params.commentId The comment ID to edit.
939
946
  * @param params.data.body The body of the comment.
947
+ * @param params.data.attachmentIds (optional) The IDs of every attachment that should remain on the comment.
940
948
  * @param params.data.metadata (optional) The metadata for the comment. Value must be a string, boolean or number. Use null to delete a key.
941
949
  * @param params.data.editedAt (optional) The date the comment was edited.
942
950
  * @param options.signal (optional) An abort signal to cancel the request.
@@ -948,6 +956,7 @@ declare class Liveblocks {
948
956
  commentId: string;
949
957
  data: {
950
958
  body: CommentBody;
959
+ attachmentIds?: string[];
951
960
  metadata?: Patchable<CM>;
952
961
  editedAt?: Date;
953
962
  };
@@ -976,6 +985,28 @@ declare class Liveblocks {
976
985
  roomId: string;
977
986
  attachmentId: string;
978
987
  }, options?: RequestOptions): Promise<AttachmentWithUrl>;
988
+ /**
989
+ * Uploads an attachment that can be added to a comment.
990
+ *
991
+ * @param params.roomId The room ID to upload the attachment to.
992
+ * @param params.userId The user ID of the user uploading the attachment.
993
+ * @param params.file The file to upload.
994
+ * @param options.signal (optional) An abort signal to cancel the upload.
995
+ * @returns The uploaded attachment.
996
+ */
997
+ uploadAttachment(params: {
998
+ roomId: string;
999
+ userId: string;
1000
+ file: File;
1001
+ }, options?: RequestOptions): Promise<CommentAttachment>;
1002
+ uploadFile(params: {
1003
+ roomId: string;
1004
+ file: File;
1005
+ }, options?: RequestOptions): Promise<LiveFile>;
1006
+ getFileUrl(params: {
1007
+ roomId: string;
1008
+ file: LiveFileReference;
1009
+ }, options?: RequestOptions): Promise<StorageFileUrl>;
979
1010
  /**
980
1011
  * Creates a new thread. The thread will be created with the specified comment as its first comment.
981
1012
  * If the thread already exists, a `LiveblocksError` will be thrown with status code 409.
@@ -984,6 +1015,7 @@ declare class Liveblocks {
984
1015
  * @param params.thread.comment.userId The user ID of the user who created the comment.
985
1016
  * @param params.thread.comment.createdAt (optional) The date the comment was created.
986
1017
  * @param params.thread.comment.body The body of the comment.
1018
+ * @param params.thread.comment.attachmentIds (optional) The attachment IDs to add to the comment.
987
1019
  * @param params.thread.comment.metadata (optional) The metadata for the comment.
988
1020
  * @param options.signal (optional) An abort signal to cancel the request.
989
1021
  * @returns The created thread. The thread will be created with the specified comment as its first comment.
@@ -2048,4 +2080,4 @@ declare function isCustomNotificationEvent(event: WebhookEvent): event is Custom
2048
2080
  */
2049
2081
  type RoomPermission = RoomPermissions;
2050
2082
 
2051
- export { type AiCopilot, type CommentCreatedEvent, type CommentDeletedEvent, type CommentEditedEvent, type CommentReactionAdded, type CommentReactionRemoved, type CreateAiCopilotOptions, type CreateFeedMessageOptions, type CreateFeedOptions, type CreateFileKnowledgeSourceOptions, type CreateRoomOptions, type CreateVersionHistorySnapshotResponse, type CreateWebKnowledgeSourceOptions, type CustomNotificationEvent, type GetAiCopilotsOptions, type GetInboxNotificationsOptions, type GetKnowledgeSourcesOptions, type GetRoomsOptions, type GetVersionHistoryOptions, type GetWebKnowledgeSourceLinksOptions, type HistoryVersion, type InboxNotificationsQueryCriteria, type KnowledgeSource, Liveblocks, LiveblocksError, type LiveblocksOptions, type MassMutateStorageCallback, type MassMutateStorageOptions, type MutateStorageCallback, type MutateStorageOptions, type NotificationEvent, type Page, type PaginationOptions, type RoomCreatedEvent, type RoomData, type RoomDeletedEvent, type RoomPermission, type RoomUser, type RoomsQueryCriteria, type SetPresenceOptions, type StorageUpdatedEvent, type TextMentionNotificationEvent, type ThreadCreatedEvent, type ThreadDeletedEvent, type ThreadMarkedAsResolvedEvent, type ThreadMarkedAsUnresolvedEvent, type ThreadMetadataUpdatedEvent, type ThreadNotificationEvent, type ThreadParticipants, type UpdateAiCopilotOptions, type UpdateFeedMessageOptions, type UpdateFeedOptions, type UpdateRoomOptions, type UpsertRoomOptions, type UserEnteredEvent, type UserLeftEvent, type WebKnowledgeSourceLink, type WebhookEvent, WebhookHandler, type WebhookRequest, type YDocUpdatedEvent, isCustomNotificationEvent, isTextMentionNotificationEvent, isThreadNotificationEvent, markdownToCommentBody };
2083
+ export { type AiCopilot, type CommentCreatedEvent, type CommentDeletedEvent, type CommentEditedEvent, type CommentReactionAdded, type CommentReactionRemoved, type CreateAiCopilotOptions, type CreateFeedMessageOptions, type CreateFeedOptions, type CreateFileKnowledgeSourceOptions, type CreateRoomOptions, type CreateVersionHistorySnapshotResponse, type CreateWebKnowledgeSourceOptions, type CustomNotificationEvent, type GetAiCopilotsOptions, type GetInboxNotificationsOptions, type GetKnowledgeSourcesOptions, type GetRoomsOptions, type GetVersionHistoryOptions, type GetWebKnowledgeSourceLinksOptions, type HistoryVersion, type InboxNotificationsQueryCriteria, type KnowledgeSource, Liveblocks, LiveblocksError, type LiveblocksOptions, type MassMutateStorageCallback, type MassMutateStorageOptions, type MutateStorageCallback, type MutateStorageOptions, type NotificationEvent, type Page, type PaginationOptions, type RoomCreatedEvent, type RoomData, type RoomDeletedEvent, type RoomPermission, type RoomUser, type RoomsQueryCriteria, type SetPresenceOptions, type StorageFileUrl, type StorageUpdatedEvent, type TextMentionNotificationEvent, type ThreadCreatedEvent, type ThreadDeletedEvent, type ThreadMarkedAsResolvedEvent, type ThreadMarkedAsUnresolvedEvent, type ThreadMetadataUpdatedEvent, type ThreadNotificationEvent, type ThreadParticipants, type UpdateAiCopilotOptions, type UpdateFeedMessageOptions, type UpdateFeedOptions, type UpdateRoomOptions, type UpsertRoomOptions, type UserEnteredEvent, type UserLeftEvent, type WebKnowledgeSourceLink, type WebhookEvent, WebhookHandler, type WebhookRequest, type YDocUpdatedEvent, isCustomNotificationEvent, isTextMentionNotificationEvent, isThreadNotificationEvent, markdownToCommentBody };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Permission, Json, DFMD, FeedCreateMetadata, RoomPermissions, RoomAccesses, OptionalTupleUnless, BaseUserMeta, DU, PartialUnless, UpdateRoomAccesses, DE, JsonObject, PlainLsonObject, ToJson, DS, QueryMetadata, DTM, ThreadVisibility, ThreadData, DCM, UserSubscriptionData, CommentData, BaseMetadata, CommentBody, Patchable, SubscriptionData, CommentUserReaction, InboxNotificationData, UserRoomSubscriptionSettings, RoomSubscriptionSettings, KDAD, DAD, NotificationSettings, PartialNotificationSettings, GroupScopes, GroupData, LiveObject, Awaitable, DFM, Feed, FeedUpdateMetadata, FeedMessage, NotificationChannel } from '@liveblocks/core';
2
- export { CommentBody, CommentBodyBlockElement, CommentBodyElement, CommentBodyInlineElement, CommentBodyLink, CommentBodyLinkElementArgs, CommentBodyMention, CommentBodyMentionElementArgs, CommentBodyParagraph, CommentBodyParagraphElementArgs, CommentBodyText, CommentBodyTextElementArgs, CommentData, CommentUserReaction, IUserInfo, Json, JsonArray, JsonObject, JsonScalar, LiveList, LiveMap, LiveObject, LiveStructure, Lson, LsonObject, PlainLsonObject, ResolveUsersArgs, RoomAccesses, RoomPermissions, StringifyCommentBodyElements, StringifyCommentBodyOptions, ThreadData, User, getMentionsFromCommentBody, isNotificationChannelEnabled, stringifyCommentBody } from '@liveblocks/core';
1
+ import { Permission, Json, DFMD, FeedCreateMetadata, RoomPermissions, RoomAccesses, OptionalTupleUnless, BaseUserMeta, DU, PartialUnless, UpdateRoomAccesses, DE, JsonObject, PlainLsonObject, ToJson, DS, QueryMetadata, DTM, ThreadVisibility, ThreadData, DCM, UserSubscriptionData, CommentData, BaseMetadata, CommentBody, Patchable, CommentAttachment, LiveFile, LiveFileReference, SubscriptionData, CommentUserReaction, InboxNotificationData, UserRoomSubscriptionSettings, RoomSubscriptionSettings, KDAD, DAD, NotificationSettings, PartialNotificationSettings, GroupScopes, GroupData, LiveObject, Awaitable, DFM, Feed, FeedUpdateMetadata, FeedMessage, NotificationChannel } from '@liveblocks/core';
2
+ export { CommentAttachment, CommentBody, CommentBodyBlockElement, CommentBodyElement, CommentBodyInlineElement, CommentBodyLink, CommentBodyLinkElementArgs, CommentBodyMention, CommentBodyMentionElementArgs, CommentBodyParagraph, CommentBodyParagraphElementArgs, CommentBodyText, CommentBodyTextElementArgs, CommentData, CommentUserReaction, IUserInfo, Json, JsonArray, JsonObject, JsonScalar, LiveFile, LiveFileData, LiveList, LiveMap, LiveObject, LiveStructure, Lson, LsonObject, PlainLsonObject, ResolveUsersArgs, RoomAccesses, RoomPermissions, StringifyCommentBodyElements, StringifyCommentBodyOptions, ThreadData, User, getMentionsFromCommentBody, isNotificationChannelEnabled, stringifyCommentBody } from '@liveblocks/core';
3
3
  import { IncomingHttpHeaders } from 'http';
4
4
 
5
5
  /**
@@ -102,6 +102,10 @@ type AttachmentWithUrl = {
102
102
  url: string;
103
103
  expiresAt: string;
104
104
  };
105
+ type StorageFileUrl = {
106
+ url: string;
107
+ expiresAt: string;
108
+ };
105
109
  type CreateThreadOptions<TM extends BaseMetadata, CM extends BaseMetadata> = {
106
110
  roomId: string;
107
111
  data: {
@@ -110,6 +114,7 @@ type CreateThreadOptions<TM extends BaseMetadata, CM extends BaseMetadata> = {
110
114
  userId: string;
111
115
  createdAt?: Date;
112
116
  body: CommentBody;
117
+ attachmentIds?: string[];
113
118
  } & PartialUnless<CM, {
114
119
  metadata: CM;
115
120
  }>;
@@ -124,6 +129,7 @@ type CreateCommentOptions<CM extends BaseMetadata> = {
124
129
  userId: string;
125
130
  createdAt?: Date;
126
131
  body: CommentBody;
132
+ attachmentIds?: string[];
127
133
  } & PartialUnless<CM, {
128
134
  metadata: CM;
129
135
  }>;
@@ -926,6 +932,7 @@ declare class Liveblocks {
926
932
  * @param params.data.userId The user ID of the user who is set to create the comment.
927
933
  * @param params.data.createdAt (optional) The date the comment is set to be created.
928
934
  * @param params.data.body The body of the comment.
935
+ * @param params.data.attachmentIds (optional) The attachment IDs to add to the comment.
929
936
  * @param params.data.metadata (optional) The metadata for the comment.
930
937
  * @param options.signal (optional) An abort signal to cancel the request.
931
938
  * @returns The created comment.
@@ -937,6 +944,7 @@ declare class Liveblocks {
937
944
  * @param params.threadId The thread ID to edit the comment in.
938
945
  * @param params.commentId The comment ID to edit.
939
946
  * @param params.data.body The body of the comment.
947
+ * @param params.data.attachmentIds (optional) The IDs of every attachment that should remain on the comment.
940
948
  * @param params.data.metadata (optional) The metadata for the comment. Value must be a string, boolean or number. Use null to delete a key.
941
949
  * @param params.data.editedAt (optional) The date the comment was edited.
942
950
  * @param options.signal (optional) An abort signal to cancel the request.
@@ -948,6 +956,7 @@ declare class Liveblocks {
948
956
  commentId: string;
949
957
  data: {
950
958
  body: CommentBody;
959
+ attachmentIds?: string[];
951
960
  metadata?: Patchable<CM>;
952
961
  editedAt?: Date;
953
962
  };
@@ -976,6 +985,28 @@ declare class Liveblocks {
976
985
  roomId: string;
977
986
  attachmentId: string;
978
987
  }, options?: RequestOptions): Promise<AttachmentWithUrl>;
988
+ /**
989
+ * Uploads an attachment that can be added to a comment.
990
+ *
991
+ * @param params.roomId The room ID to upload the attachment to.
992
+ * @param params.userId The user ID of the user uploading the attachment.
993
+ * @param params.file The file to upload.
994
+ * @param options.signal (optional) An abort signal to cancel the upload.
995
+ * @returns The uploaded attachment.
996
+ */
997
+ uploadAttachment(params: {
998
+ roomId: string;
999
+ userId: string;
1000
+ file: File;
1001
+ }, options?: RequestOptions): Promise<CommentAttachment>;
1002
+ uploadFile(params: {
1003
+ roomId: string;
1004
+ file: File;
1005
+ }, options?: RequestOptions): Promise<LiveFile>;
1006
+ getFileUrl(params: {
1007
+ roomId: string;
1008
+ file: LiveFileReference;
1009
+ }, options?: RequestOptions): Promise<StorageFileUrl>;
979
1010
  /**
980
1011
  * Creates a new thread. The thread will be created with the specified comment as its first comment.
981
1012
  * If the thread already exists, a `LiveblocksError` will be thrown with status code 409.
@@ -984,6 +1015,7 @@ declare class Liveblocks {
984
1015
  * @param params.thread.comment.userId The user ID of the user who created the comment.
985
1016
  * @param params.thread.comment.createdAt (optional) The date the comment was created.
986
1017
  * @param params.thread.comment.body The body of the comment.
1018
+ * @param params.thread.comment.attachmentIds (optional) The attachment IDs to add to the comment.
987
1019
  * @param params.thread.comment.metadata (optional) The metadata for the comment.
988
1020
  * @param options.signal (optional) An abort signal to cancel the request.
989
1021
  * @returns The created thread. The thread will be created with the specified comment as its first comment.
@@ -2048,4 +2080,4 @@ declare function isCustomNotificationEvent(event: WebhookEvent): event is Custom
2048
2080
  */
2049
2081
  type RoomPermission = RoomPermissions;
2050
2082
 
2051
- export { type AiCopilot, type CommentCreatedEvent, type CommentDeletedEvent, type CommentEditedEvent, type CommentReactionAdded, type CommentReactionRemoved, type CreateAiCopilotOptions, type CreateFeedMessageOptions, type CreateFeedOptions, type CreateFileKnowledgeSourceOptions, type CreateRoomOptions, type CreateVersionHistorySnapshotResponse, type CreateWebKnowledgeSourceOptions, type CustomNotificationEvent, type GetAiCopilotsOptions, type GetInboxNotificationsOptions, type GetKnowledgeSourcesOptions, type GetRoomsOptions, type GetVersionHistoryOptions, type GetWebKnowledgeSourceLinksOptions, type HistoryVersion, type InboxNotificationsQueryCriteria, type KnowledgeSource, Liveblocks, LiveblocksError, type LiveblocksOptions, type MassMutateStorageCallback, type MassMutateStorageOptions, type MutateStorageCallback, type MutateStorageOptions, type NotificationEvent, type Page, type PaginationOptions, type RoomCreatedEvent, type RoomData, type RoomDeletedEvent, type RoomPermission, type RoomUser, type RoomsQueryCriteria, type SetPresenceOptions, type StorageUpdatedEvent, type TextMentionNotificationEvent, type ThreadCreatedEvent, type ThreadDeletedEvent, type ThreadMarkedAsResolvedEvent, type ThreadMarkedAsUnresolvedEvent, type ThreadMetadataUpdatedEvent, type ThreadNotificationEvent, type ThreadParticipants, type UpdateAiCopilotOptions, type UpdateFeedMessageOptions, type UpdateFeedOptions, type UpdateRoomOptions, type UpsertRoomOptions, type UserEnteredEvent, type UserLeftEvent, type WebKnowledgeSourceLink, type WebhookEvent, WebhookHandler, type WebhookRequest, type YDocUpdatedEvent, isCustomNotificationEvent, isTextMentionNotificationEvent, isThreadNotificationEvent, markdownToCommentBody };
2083
+ export { type AiCopilot, type CommentCreatedEvent, type CommentDeletedEvent, type CommentEditedEvent, type CommentReactionAdded, type CommentReactionRemoved, type CreateAiCopilotOptions, type CreateFeedMessageOptions, type CreateFeedOptions, type CreateFileKnowledgeSourceOptions, type CreateRoomOptions, type CreateVersionHistorySnapshotResponse, type CreateWebKnowledgeSourceOptions, type CustomNotificationEvent, type GetAiCopilotsOptions, type GetInboxNotificationsOptions, type GetKnowledgeSourcesOptions, type GetRoomsOptions, type GetVersionHistoryOptions, type GetWebKnowledgeSourceLinksOptions, type HistoryVersion, type InboxNotificationsQueryCriteria, type KnowledgeSource, Liveblocks, LiveblocksError, type LiveblocksOptions, type MassMutateStorageCallback, type MassMutateStorageOptions, type MutateStorageCallback, type MutateStorageOptions, type NotificationEvent, type Page, type PaginationOptions, type RoomCreatedEvent, type RoomData, type RoomDeletedEvent, type RoomPermission, type RoomUser, type RoomsQueryCriteria, type SetPresenceOptions, type StorageFileUrl, type StorageUpdatedEvent, type TextMentionNotificationEvent, type ThreadCreatedEvent, type ThreadDeletedEvent, type ThreadMarkedAsResolvedEvent, type ThreadMarkedAsUnresolvedEvent, type ThreadMetadataUpdatedEvent, type ThreadNotificationEvent, type ThreadParticipants, type UpdateAiCopilotOptions, type UpdateFeedMessageOptions, type UpdateFeedOptions, type UpdateRoomOptions, type UpsertRoomOptions, type UserEnteredEvent, type UserLeftEvent, type WebKnowledgeSourceLink, type WebhookEvent, WebhookHandler, type WebhookRequest, type YDocUpdatedEvent, isCustomNotificationEvent, isTextMentionNotificationEvent, isThreadNotificationEvent, markdownToCommentBody };
package/dist/index.js CHANGED
@@ -3,12 +3,14 @@ import { detectDupes } from "@liveblocks/core";
3
3
 
4
4
  // src/version.ts
5
5
  var PKG_NAME = "@liveblocks/node";
6
- var PKG_VERSION = "3.23.0-exp2";
6
+ var PKG_VERSION = "3.23.0-exp4";
7
7
  var PKG_FORMAT = "esm";
8
8
 
9
9
  // src/client.ts
10
10
  import {
11
+ autoRetry,
11
12
  checkBounds,
13
+ chunk,
12
14
  ClientMsgCode,
13
15
  convertToCommentData,
14
16
  convertToCommentUserReaction,
@@ -17,9 +19,13 @@ import {
17
19
  convertToSubscriptionData,
18
20
  convertToThreadData,
19
21
  convertToUserSubscriptionData,
22
+ createCommentAttachmentId,
20
23
  createManagedPool,
21
24
  createNotificationSettings,
25
+ createStorageFileId,
26
+ getLiveFileId,
22
27
  isPlainObject,
28
+ LiveFile,
23
29
  LiveObject,
24
30
  makeAbortController,
25
31
  normalizeRoomAccesses,
@@ -64,8 +70,8 @@ var LineStream = class extends TransformStream {
64
70
  constructor() {
65
71
  let buffer = "";
66
72
  super({
67
- transform(chunk, controller) {
68
- buffer += chunk;
73
+ transform(chunk2, controller) {
74
+ buffer += chunk2;
69
75
  if (buffer.includes("\n")) {
70
76
  const lines = buffer.split("\n");
71
77
  for (let i = 0; i < lines.length - 1; i++) {
@@ -289,6 +295,158 @@ var Session = class {
289
295
  };
290
296
 
291
297
  // src/client.ts
298
+ var ROOM_FILE_PART_SIZE = 5 * 1024 * 1024;
299
+ var ROOM_FILE_RETRY_ATTEMPTS = 10;
300
+ var ROOM_FILE_RETRY_DELAYS = [
301
+ 2e3,
302
+ 2e3,
303
+ 2e3,
304
+ 2e3,
305
+ 2e3,
306
+ 2e3,
307
+ 2e3,
308
+ 2e3,
309
+ 2e3,
310
+ 2e3
311
+ ];
312
+ async function uploadRoomFile({
313
+ file,
314
+ signal,
315
+ abortErrorMessage,
316
+ retryMultipartCompletion,
317
+ uploadSingle,
318
+ createMultipartUpload,
319
+ uploadMultipartPart,
320
+ completeMultipartUpload,
321
+ abortMultipartUpload
322
+ }) {
323
+ const abortError = createAbortError(abortErrorMessage);
324
+ if (signal?.aborted) {
325
+ throw abortError;
326
+ }
327
+ const handleRetryError = (err) => {
328
+ if (signal?.aborted) {
329
+ throw abortError;
330
+ }
331
+ return err instanceof LiveblocksError && err.status >= 400 && err.status < 500;
332
+ };
333
+ if (file.size <= ROOM_FILE_PART_SIZE) {
334
+ return autoRetry(
335
+ uploadSingle,
336
+ ROOM_FILE_RETRY_ATTEMPTS,
337
+ ROOM_FILE_RETRY_DELAYS,
338
+ handleRetryError
339
+ );
340
+ }
341
+ let uploadId;
342
+ const uploadedParts = [];
343
+ const multipartUpload = await autoRetry(
344
+ createMultipartUpload,
345
+ ROOM_FILE_RETRY_ATTEMPTS,
346
+ ROOM_FILE_RETRY_DELAYS,
347
+ handleRetryError
348
+ );
349
+ const partUploadController = new AbortController();
350
+ const partUploadSignal = partUploadController.signal;
351
+ const abortPartUploads = (reason) => {
352
+ partUploadController.abort(reason);
353
+ };
354
+ const handleExternalAbort = () => abortPartUploads();
355
+ if (signal?.aborted) {
356
+ handleExternalAbort();
357
+ } else {
358
+ signal?.addEventListener("abort", handleExternalAbort, { once: true });
359
+ }
360
+ try {
361
+ uploadId = multipartUpload.uploadId;
362
+ if (signal?.aborted) {
363
+ throw abortError;
364
+ }
365
+ const batches = chunk(splitRoomFileIntoParts(file), 5);
366
+ for (const parts of batches) {
367
+ const firstPartUploadFailure = {};
368
+ const partUploads$ = [];
369
+ for (const { part, partNumber } of parts) {
370
+ partUploads$.push(
371
+ autoRetry(
372
+ () => uploadMultipartPart(
373
+ multipartUpload.uploadId,
374
+ partNumber,
375
+ part,
376
+ partUploadSignal
377
+ ),
378
+ ROOM_FILE_RETRY_ATTEMPTS,
379
+ ROOM_FILE_RETRY_DELAYS,
380
+ (error) => {
381
+ if (signal?.aborted) {
382
+ throw abortError;
383
+ }
384
+ return partUploadSignal.aborted || handleRetryError(error);
385
+ }
386
+ ).catch((error) => {
387
+ if (firstPartUploadFailure.value === void 0) {
388
+ firstPartUploadFailure.value = { error };
389
+ abortPartUploads(error);
390
+ }
391
+ throw error;
392
+ })
393
+ );
394
+ }
395
+ const settledPartUploads = await Promise.allSettled(partUploads$);
396
+ if (firstPartUploadFailure.value !== void 0) {
397
+ throw firstPartUploadFailure.value.error;
398
+ }
399
+ for (const settledPartUpload of settledPartUploads) {
400
+ if (settledPartUpload.status === "fulfilled") {
401
+ uploadedParts.push(settledPartUpload.value);
402
+ }
403
+ }
404
+ }
405
+ if (signal?.aborted) {
406
+ throw abortError;
407
+ }
408
+ const sortedParts = uploadedParts.sort(
409
+ (a, b) => a.partNumber - b.partNumber
410
+ );
411
+ return retryMultipartCompletion ? autoRetry(
412
+ () => completeMultipartUpload(multipartUpload.uploadId, sortedParts),
413
+ ROOM_FILE_RETRY_ATTEMPTS,
414
+ ROOM_FILE_RETRY_DELAYS,
415
+ handleRetryError
416
+ ) : completeMultipartUpload(uploadId, sortedParts);
417
+ } catch (err) {
418
+ if (uploadId) {
419
+ try {
420
+ await abortMultipartUpload(uploadId);
421
+ } catch {
422
+ }
423
+ }
424
+ throw err;
425
+ } finally {
426
+ signal?.removeEventListener("abort", handleExternalAbort);
427
+ }
428
+ }
429
+ function splitRoomFileIntoParts(file) {
430
+ const parts = [];
431
+ let start = 0;
432
+ while (start < file.size) {
433
+ const end = Math.min(start + ROOM_FILE_PART_SIZE, file.size);
434
+ parts.push({
435
+ partNumber: parts.length + 1,
436
+ part: file.slice(start, end)
437
+ });
438
+ start = end;
439
+ }
440
+ return parts;
441
+ }
442
+ function createAbortError(message) {
443
+ if (typeof DOMException === "function") {
444
+ return new DOMException(message, "AbortError");
445
+ }
446
+ const err = new Error(message);
447
+ err.name = "AbortError";
448
+ return err;
449
+ }
292
450
  function inflateRoomData(room) {
293
451
  const createdAt = new Date(room.createdAt);
294
452
  const lastConnectionAt = room.lastConnectionAt ? new Date(room.lastConnectionAt) : void 0;
@@ -359,8 +517,8 @@ var Liveblocks = class {
359
517
  this.#baseUrl = new URL(getBaseUrl(options.baseUrl));
360
518
  this.#localDev = !!options.baseUrl && /^https?:\/\/localhost[:/]/.test(options.baseUrl);
361
519
  }
362
- async #post(path, json, options) {
363
- const url3 = urljoin(this.#baseUrl, path);
520
+ async #post(path, json, options, params) {
521
+ const url3 = urljoin(this.#baseUrl, path, params);
364
522
  const headers = {
365
523
  Authorization: `Bearer ${this.#secret}`,
366
524
  "Content-Type": "application/json"
@@ -375,6 +533,12 @@ var Liveblocks = class {
375
533
  xwarn(res, "POST", path);
376
534
  return res;
377
535
  }
536
+ async #readJsonResponse(res) {
537
+ if (!res.ok) {
538
+ throw await LiveblocksError.from(res);
539
+ }
540
+ return await res.json();
541
+ }
378
542
  async #patch(path, json, options) {
379
543
  const url3 = urljoin(this.#baseUrl, path);
380
544
  const headers = {
@@ -407,6 +571,22 @@ var Liveblocks = class {
407
571
  xwarn(res, "PUT", path);
408
572
  return res;
409
573
  }
574
+ async #putBlob(path, body, params, options) {
575
+ const url3 = urljoin(this.#baseUrl, path, params);
576
+ const headers = {
577
+ Authorization: `Bearer ${this.#secret}`,
578
+ "Content-Type": "application/octet-stream"
579
+ };
580
+ const fetch = await fetchPolyfill();
581
+ const res = await fetch(url3, {
582
+ method: "PUT",
583
+ headers,
584
+ body,
585
+ signal: options?.signal
586
+ });
587
+ xwarn(res, "PUT", path);
588
+ return res;
589
+ }
410
590
  async #delete(path, params, options) {
411
591
  const url3 = urljoin(this.#baseUrl, path, params);
412
592
  const headers = {
@@ -1174,6 +1354,7 @@ var Liveblocks = class {
1174
1354
  * @param params.data.userId The user ID of the user who is set to create the comment.
1175
1355
  * @param params.data.createdAt (optional) The date the comment is set to be created.
1176
1356
  * @param params.data.body The body of the comment.
1357
+ * @param params.data.attachmentIds (optional) The attachment IDs to add to the comment.
1177
1358
  * @param params.data.metadata (optional) The metadata for the comment.
1178
1359
  * @param options.signal (optional) An abort signal to cancel the request.
1179
1360
  * @returns The created comment.
@@ -1199,6 +1380,7 @@ var Liveblocks = class {
1199
1380
  * @param params.threadId The thread ID to edit the comment in.
1200
1381
  * @param params.commentId The comment ID to edit.
1201
1382
  * @param params.data.body The body of the comment.
1383
+ * @param params.data.attachmentIds (optional) The IDs of every attachment that should remain on the comment.
1202
1384
  * @param params.data.metadata (optional) The metadata for the comment. Value must be a string, boolean or number. Use null to delete a key.
1203
1385
  * @param params.data.editedAt (optional) The date the comment was edited.
1204
1386
  * @param options.signal (optional) An abort signal to cancel the request.
@@ -1211,6 +1393,7 @@ var Liveblocks = class {
1211
1393
  {
1212
1394
  body: data.body,
1213
1395
  editedAt: data.editedAt?.toISOString(),
1396
+ attachmentIds: data.attachmentIds,
1214
1397
  metadata: data.metadata
1215
1398
  },
1216
1399
  options
@@ -1258,6 +1441,137 @@ var Liveblocks = class {
1258
1441
  }
1259
1442
  return await res.json();
1260
1443
  }
1444
+ /**
1445
+ * Uploads an attachment that can be added to a comment.
1446
+ *
1447
+ * @param params.roomId The room ID to upload the attachment to.
1448
+ * @param params.userId The user ID of the user uploading the attachment.
1449
+ * @param params.file The file to upload.
1450
+ * @param options.signal (optional) An abort signal to cancel the upload.
1451
+ * @returns The uploaded attachment.
1452
+ */
1453
+ async uploadAttachment(params, options) {
1454
+ const { roomId, userId, file } = params;
1455
+ const attachmentId = createCommentAttachmentId();
1456
+ return await uploadRoomFile({
1457
+ file,
1458
+ signal: options?.signal,
1459
+ abortErrorMessage: `Upload of attachment ${attachmentId} was aborted.`,
1460
+ retryMultipartCompletion: false,
1461
+ uploadSingle: async () => {
1462
+ const res = await this.#putBlob(
1463
+ url2`/v2/rooms/${roomId}/attachments/${attachmentId}/upload/${file.name}`,
1464
+ file,
1465
+ { fileSize: file.size, userId },
1466
+ options
1467
+ );
1468
+ return await this.#readJsonResponse(res);
1469
+ },
1470
+ createMultipartUpload: async () => {
1471
+ const res = await this.#post(
1472
+ url2`/v2/rooms/${roomId}/attachments/${attachmentId}/multipart/${file.name}`,
1473
+ void 0,
1474
+ options,
1475
+ { fileSize: file.size }
1476
+ );
1477
+ return await this.#readJsonResponse(res);
1478
+ },
1479
+ uploadMultipartPart: async (uploadId, partNumber, part, signal) => {
1480
+ const res = await this.#putBlob(
1481
+ url2`/v2/rooms/${roomId}/attachments/${attachmentId}/multipart/${uploadId}/${String(partNumber)}`,
1482
+ part,
1483
+ void 0,
1484
+ { signal }
1485
+ );
1486
+ return await this.#readJsonResponse(res);
1487
+ },
1488
+ completeMultipartUpload: async (uploadId, parts) => {
1489
+ const res = await this.#post(
1490
+ url2`/v2/rooms/${roomId}/attachments/${attachmentId}/multipart/${uploadId}/complete`,
1491
+ { parts },
1492
+ options,
1493
+ { userId }
1494
+ );
1495
+ return await this.#readJsonResponse(res);
1496
+ },
1497
+ abortMultipartUpload: async (uploadId) => {
1498
+ const res = await this.#delete(
1499
+ url2`/v2/rooms/${roomId}/attachments/${attachmentId}/multipart/${uploadId}`
1500
+ );
1501
+ if (!res.ok) {
1502
+ throw await LiveblocksError.from(res);
1503
+ }
1504
+ }
1505
+ });
1506
+ }
1507
+ async uploadFile(params, options) {
1508
+ const { roomId, file } = params;
1509
+ const fileId = createStorageFileId();
1510
+ const fileData = await uploadRoomFile({
1511
+ file,
1512
+ signal: options?.signal,
1513
+ abortErrorMessage: `Upload of file ${fileId} was aborted.`,
1514
+ retryMultipartCompletion: true,
1515
+ uploadSingle: async () => {
1516
+ const res = await this.#putBlob(
1517
+ url2`/v2/rooms/${roomId}/storage/files/${fileId}/upload/${file.name}`,
1518
+ file,
1519
+ { fileSize: file.size },
1520
+ options
1521
+ );
1522
+ return await this.#readJsonResponse(res);
1523
+ },
1524
+ createMultipartUpload: async () => {
1525
+ const res = await this.#post(
1526
+ url2`/v2/rooms/${roomId}/storage/files/${fileId}/multipart/${file.name}`,
1527
+ void 0,
1528
+ options,
1529
+ { fileSize: file.size }
1530
+ );
1531
+ return await this.#readJsonResponse(res);
1532
+ },
1533
+ uploadMultipartPart: async (uploadId, partNumber, part, signal) => {
1534
+ const res = await this.#putBlob(
1535
+ url2`/v2/rooms/${roomId}/storage/files/${fileId}/multipart/${uploadId}/${String(partNumber)}`,
1536
+ part,
1537
+ void 0,
1538
+ { signal }
1539
+ );
1540
+ return await this.#readJsonResponse(res);
1541
+ },
1542
+ completeMultipartUpload: async (uploadId, parts) => {
1543
+ const res = await this.#post(
1544
+ url2`/v2/rooms/${roomId}/storage/files/${fileId}/multipart/${uploadId}/complete`,
1545
+ { parts },
1546
+ options
1547
+ );
1548
+ return await this.#readJsonResponse(res);
1549
+ },
1550
+ abortMultipartUpload: async (uploadId) => {
1551
+ const res = await this.#delete(
1552
+ url2`/v2/rooms/${roomId}/storage/files/${fileId}/multipart/${uploadId}`
1553
+ );
1554
+ if (!res.ok) {
1555
+ throw await LiveblocksError.from(res);
1556
+ }
1557
+ }
1558
+ });
1559
+ return new LiveFile(fileData);
1560
+ }
1561
+ async getFileUrl(params, options) {
1562
+ const { roomId, file } = params;
1563
+ const fileId = getLiveFileId(file);
1564
+ const res = await this.#get(
1565
+ url2`/v2/rooms/${roomId}/storage/files/${fileId}`,
1566
+ void 0,
1567
+ options
1568
+ );
1569
+ const storageFile = await this.#readJsonResponse(res);
1570
+ return {
1571
+ url: storageFile.url,
1572
+ expiresAt: storageFile.expiresAt
1573
+ };
1574
+ }
1261
1575
  /**
1262
1576
  * Creates a new thread. The thread will be created with the specified comment as its first comment.
1263
1577
  * If the thread already exists, a `LiveblocksError` will be thrown with status code 409.
@@ -1266,6 +1580,7 @@ var Liveblocks = class {
1266
1580
  * @param params.thread.comment.userId The user ID of the user who created the comment.
1267
1581
  * @param params.thread.comment.createdAt (optional) The date the comment was created.
1268
1582
  * @param params.thread.comment.body The body of the comment.
1583
+ * @param params.thread.comment.attachmentIds (optional) The attachment IDs to add to the comment.
1269
1584
  * @param params.thread.comment.metadata (optional) The metadata for the comment.
1270
1585
  * @param options.signal (optional) An abort signal to cancel the request.
1271
1586
  * @returns The created thread. The thread will be created with the specified comment as its first comment.
@@ -3078,6 +3393,7 @@ function isCustomNotificationEvent(event) {
3078
3393
  import {
3079
3394
  getMentionsFromCommentBody,
3080
3395
  isNotificationChannelEnabled,
3396
+ LiveFile as LiveFile2,
3081
3397
  LiveList,
3082
3398
  LiveMap,
3083
3399
  LiveObject as LiveObject2,
@@ -3085,6 +3401,7 @@ import {
3085
3401
  } from "@liveblocks/core";
3086
3402
  detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
3087
3403
  export {
3404
+ LiveFile2 as LiveFile,
3088
3405
  LiveList,
3089
3406
  LiveMap,
3090
3407
  LiveObject2 as LiveObject,