@liveblocks/core 2.3.0 → 2.4.0-test1

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.mjs CHANGED
@@ -6,7 +6,7 @@ var __export = (target, all) => {
6
6
 
7
7
  // src/version.ts
8
8
  var PKG_NAME = "@liveblocks/core";
9
- var PKG_VERSION = "2.3.0";
9
+ var PKG_VERSION = "2.4.0-test1";
10
10
  var PKG_FORMAT = "esm";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -2078,25 +2078,32 @@ function createNotificationsApi({
2078
2078
  }
2079
2079
  return body;
2080
2080
  }
2081
- async function getInboxNotifications(options) {
2082
- const json = await fetchJson("/inbox-notifications", void 0, {
2083
- limit: options?.limit,
2084
- since: options?.since?.toISOString()
2085
- });
2081
+ async function getInboxNotifications() {
2082
+ const json = await fetchJson("/inbox-notifications", void 0, {});
2086
2083
  return {
2087
- threads: json.threads.map((thread) => convertToThreadData(thread)),
2084
+ threads: json.threads.map(convertToThreadData),
2088
2085
  inboxNotifications: json.inboxNotifications.map(
2089
- (notification) => convertToInboxNotificationData(notification)
2090
- ),
2091
- deletedThreads: json.deletedThreads.map(
2092
- (info) => convertToThreadDeleteInfo(info)
2093
- ),
2094
- deletedInboxNotifications: json.deletedInboxNotifications.map(
2095
- (info) => convertToInboxNotificationDeleteInfo(info)
2086
+ convertToInboxNotificationData
2096
2087
  ),
2097
- meta: {
2098
- requestedAt: new Date(json.meta.requestedAt)
2099
- }
2088
+ requestedAt: new Date(json.meta.requestedAt)
2089
+ };
2090
+ }
2091
+ async function getInboxNotificationsSince(options) {
2092
+ const json = await fetchJson("/inbox-notifications", void 0, {
2093
+ since: options.since.toISOString()
2094
+ });
2095
+ return {
2096
+ threads: {
2097
+ modified: json.threads.map(convertToThreadData),
2098
+ deleted: json.deletedThreads.map(convertToThreadDeleteInfo)
2099
+ },
2100
+ inboxNotifications: {
2101
+ modified: json.inboxNotifications.map(convertToInboxNotificationData),
2102
+ deleted: json.deletedInboxNotifications.map(
2103
+ convertToInboxNotificationDeleteInfo
2104
+ )
2105
+ },
2106
+ requestedAt: new Date(json.meta.requestedAt)
2100
2107
  };
2101
2108
  }
2102
2109
  async function getUnreadInboxNotificationsCount() {
@@ -2147,6 +2154,7 @@ function createNotificationsApi({
2147
2154
  }
2148
2155
  return {
2149
2156
  getInboxNotifications,
2157
+ getInboxNotificationsSince,
2150
2158
  getUnreadInboxNotificationsCount,
2151
2159
  markAllInboxNotificationsAsRead,
2152
2160
  markInboxNotificationAsRead,
@@ -2494,14 +2502,10 @@ function isChildCrdt(crdt) {
2494
2502
  }
2495
2503
 
2496
2504
  // src/lib/nanoid.ts
2497
- function nanoid(length = 7) {
2498
- const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789,./;[]~!@#$%&*()_+=-";
2499
- const len = alphabet.length;
2500
- return Array.from(
2501
- { length },
2502
- () => alphabet.charAt(Math.floor(Math.random() * len))
2503
- ).join("");
2504
- }
2505
+ var nanoid = (t = 21) => crypto.getRandomValues(new Uint8Array(t)).reduce(
2506
+ (t2, e) => t2 += (e &= 63) < 36 ? e.toString(36) : e < 62 ? (e - 26).toString(36).toUpperCase() : e < 63 ? "_" : "-",
2507
+ ""
2508
+ );
2505
2509
 
2506
2510
  // src/crdts/LiveRegister.ts
2507
2511
  var LiveRegister = class _LiveRegister extends AbstractCrdt {
@@ -4715,6 +4719,23 @@ function findNonSerializableValue(value, path = "") {
4715
4719
  return false;
4716
4720
  }
4717
4721
 
4722
+ // src/lib/createIds.ts
4723
+ var THREAD_ID_PREFIX = "th";
4724
+ var COMMENT_ID_PREFIX = "cm";
4725
+ var INBOX_NOTIFICATION_ID_PREFIX = "in";
4726
+ function createOptimisticId(prefix) {
4727
+ return `${prefix}_${nanoid()}`;
4728
+ }
4729
+ function createThreadId() {
4730
+ return createOptimisticId(THREAD_ID_PREFIX);
4731
+ }
4732
+ function createCommentId() {
4733
+ return createOptimisticId(COMMENT_ID_PREFIX);
4734
+ }
4735
+ function createInboxNotificationId() {
4736
+ return createOptimisticId(INBOX_NOTIFICATION_ID_PREFIX);
4737
+ }
4738
+
4718
4739
  // src/lib/debug.ts
4719
4740
  function captureStackTrace(msg, traceRoot) {
4720
4741
  const errorLike = { name: msg };
@@ -5152,6 +5173,49 @@ function createCommentsApi(roomId, getAuthValue, fetchClientApi) {
5152
5173
  }
5153
5174
  return body;
5154
5175
  }
5176
+ async function getThreadsSince(options) {
5177
+ const response = await fetchCommentsApi(
5178
+ "/threads",
5179
+ {
5180
+ since: options?.since?.toISOString()
5181
+ },
5182
+ {
5183
+ headers: {
5184
+ "Content-Type": "application/json"
5185
+ }
5186
+ }
5187
+ );
5188
+ if (response.ok) {
5189
+ const json = await response.json();
5190
+ return {
5191
+ threads: {
5192
+ modified: json.data.map(convertToThreadData),
5193
+ deleted: json.deletedThreads.map(convertToThreadDeleteInfo)
5194
+ },
5195
+ inboxNotifications: {
5196
+ modified: json.inboxNotifications.map(convertToInboxNotificationData),
5197
+ deleted: json.deletedInboxNotifications.map(
5198
+ convertToInboxNotificationDeleteInfo
5199
+ )
5200
+ },
5201
+ requestedAt: new Date(json.meta.requestedAt)
5202
+ };
5203
+ } else if (response.status === 404) {
5204
+ return {
5205
+ threads: {
5206
+ modified: [],
5207
+ deleted: []
5208
+ },
5209
+ inboxNotifications: {
5210
+ modified: [],
5211
+ deleted: []
5212
+ },
5213
+ requestedAt: /* @__PURE__ */ new Date()
5214
+ };
5215
+ } else {
5216
+ throw new Error("There was an error while getting threads.");
5217
+ }
5218
+ }
5155
5219
  async function getThreads(options) {
5156
5220
  let query;
5157
5221
  if (options?.query) {
@@ -5160,7 +5224,6 @@ function createCommentsApi(roomId, getAuthValue, fetchClientApi) {
5160
5224
  const response = await fetchCommentsApi(
5161
5225
  "/threads",
5162
5226
  {
5163
- since: options?.since?.toISOString(),
5164
5227
  query
5165
5228
  },
5166
5229
  {
@@ -5172,19 +5235,11 @@ function createCommentsApi(roomId, getAuthValue, fetchClientApi) {
5172
5235
  if (response.ok) {
5173
5236
  const json = await response.json();
5174
5237
  return {
5175
- threads: json.data.map((thread) => convertToThreadData(thread)),
5238
+ threads: json.data.map(convertToThreadData),
5176
5239
  inboxNotifications: json.inboxNotifications.map(
5177
- (notification) => convertToInboxNotificationData(notification)
5240
+ convertToInboxNotificationData
5178
5241
  ),
5179
- deletedThreads: json.deletedThreads.map(
5180
- (info) => convertToThreadDeleteInfo(info)
5181
- ),
5182
- deletedInboxNotifications: json.deletedInboxNotifications.map(
5183
- (info) => convertToInboxNotificationDeleteInfo(info)
5184
- ),
5185
- meta: {
5186
- requestedAt: new Date(json.meta.requestedAt)
5187
- }
5242
+ requestedAt: new Date(json.meta.requestedAt)
5188
5243
  };
5189
5244
  } else if (response.status === 404) {
5190
5245
  return {
@@ -5192,15 +5247,13 @@ function createCommentsApi(roomId, getAuthValue, fetchClientApi) {
5192
5247
  inboxNotifications: [],
5193
5248
  deletedThreads: [],
5194
5249
  deletedInboxNotifications: [],
5195
- meta: {
5196
- requestedAt: /* @__PURE__ */ new Date()
5197
- }
5250
+ requestedAt: /* @__PURE__ */ new Date()
5198
5251
  };
5199
5252
  } else {
5200
5253
  throw new Error("There was an error while getting threads.");
5201
5254
  }
5202
5255
  }
5203
- async function getThread({ threadId }) {
5256
+ async function getThread(threadId) {
5204
5257
  const response = await fetchCommentsApi(
5205
5258
  `/thread-with-notification/${threadId}`
5206
5259
  );
@@ -5211,7 +5264,10 @@ function createCommentsApi(roomId, getAuthValue, fetchClientApi) {
5211
5264
  inboxNotification: json.inboxNotification ? convertToInboxNotificationData(json.inboxNotification) : void 0
5212
5265
  };
5213
5266
  } else if (response.status === 404) {
5214
- return;
5267
+ return {
5268
+ thread: void 0,
5269
+ inboxNotification: void 0
5270
+ };
5215
5271
  } else {
5216
5272
  throw new Error(`There was an error while getting thread ${threadId}.`);
5217
5273
  }
@@ -5219,8 +5275,8 @@ function createCommentsApi(roomId, getAuthValue, fetchClientApi) {
5219
5275
  async function createThread({
5220
5276
  metadata,
5221
5277
  body,
5222
- commentId,
5223
- threadId
5278
+ commentId = createCommentId(),
5279
+ threadId = createThreadId()
5224
5280
  }) {
5225
5281
  const thread = await fetchJson("/threads", {
5226
5282
  method: "POST",
@@ -5238,7 +5294,7 @@ function createCommentsApi(roomId, getAuthValue, fetchClientApi) {
5238
5294
  });
5239
5295
  return convertToThreadData(thread);
5240
5296
  }
5241
- async function deleteThread({ threadId }) {
5297
+ async function deleteThread(threadId) {
5242
5298
  await fetchJson(`/threads/${encodeURIComponent(threadId)}`, {
5243
5299
  method: "DELETE"
5244
5300
  });
@@ -5258,7 +5314,7 @@ function createCommentsApi(roomId, getAuthValue, fetchClientApi) {
5258
5314
  }
5259
5315
  );
5260
5316
  }
5261
- async function markThreadAsResolved({ threadId }) {
5317
+ async function markThreadAsResolved(threadId) {
5262
5318
  await fetchJson(
5263
5319
  `/threads/${encodeURIComponent(threadId)}/mark-as-resolved`,
5264
5320
  {
@@ -5266,7 +5322,7 @@ function createCommentsApi(roomId, getAuthValue, fetchClientApi) {
5266
5322
  }
5267
5323
  );
5268
5324
  }
5269
- async function markThreadAsUnresolved({ threadId }) {
5325
+ async function markThreadAsUnresolved(threadId) {
5270
5326
  await fetchJson(
5271
5327
  `/threads/${encodeURIComponent(threadId)}/mark-as-unresolved`,
5272
5328
  {
@@ -5276,7 +5332,7 @@ function createCommentsApi(roomId, getAuthValue, fetchClientApi) {
5276
5332
  }
5277
5333
  async function createComment({
5278
5334
  threadId,
5279
- commentId,
5335
+ commentId = createCommentId(),
5280
5336
  body
5281
5337
  }) {
5282
5338
  const comment = await fetchJson(
@@ -5363,6 +5419,7 @@ function createCommentsApi(roomId, getAuthValue, fetchClientApi) {
5363
5419
  }
5364
5420
  return {
5365
5421
  getThreads,
5422
+ getThreadsSince,
5366
5423
  getThread,
5367
5424
  createThread,
5368
5425
  deleteThread,
@@ -6542,12 +6599,12 @@ ${Array.from(traces).join("\n\n")}`
6542
6599
  }
6543
6600
  return body;
6544
6601
  }
6545
- function getRoomNotificationSettings() {
6602
+ function getNotificationSettings() {
6546
6603
  return fetchNotificationsJson(
6547
6604
  "/notification-settings"
6548
6605
  );
6549
6606
  }
6550
- function updateRoomNotificationSettings(settings) {
6607
+ function updateNotificationSettings(settings) {
6551
6608
  return fetchNotificationsJson(
6552
6609
  "/notification-settings",
6553
6610
  {
@@ -6608,14 +6665,6 @@ ${Array.from(traces).join("\n\n")}`
6608
6665
  // These exist only for our E2E testing app
6609
6666
  explicitClose: (event) => managedSocket._privateSendMachineEvent({ type: "EXPLICIT_SOCKET_CLOSE", event }),
6610
6667
  rawSend: (data) => managedSocket.send(data)
6611
- },
6612
- comments: {
6613
- ...commentsApi
6614
- },
6615
- notifications: {
6616
- getRoomNotificationSettings,
6617
- updateRoomNotificationSettings,
6618
- markInboxNotificationAsRead
6619
6668
  }
6620
6669
  },
6621
6670
  id: config.roomId,
@@ -6656,7 +6705,11 @@ ${Array.from(traces).join("\n\n")}`
6656
6705
  getSelf: () => self.current,
6657
6706
  // Presence
6658
6707
  getPresence: () => context.myPresence.current,
6659
- getOthers: () => context.others.current
6708
+ getOthers: () => context.others.current,
6709
+ getNotificationSettings,
6710
+ updateNotificationSettings,
6711
+ markInboxNotificationAsRead,
6712
+ ...commentsApi
6660
6713
  },
6661
6714
  // Explictly make the internal field non-enumerable, to avoid aggressive
6662
6715
  // freezing when used with Immer
@@ -6718,6 +6771,10 @@ function makeClassicSubscribeFn(events) {
6718
6771
  return events.storageStatus.subscribe(
6719
6772
  callback
6720
6773
  );
6774
+ case "comments":
6775
+ return events.comments.subscribe(
6776
+ callback
6777
+ );
6721
6778
  default:
6722
6779
  return assertNever(
6723
6780
  first,
@@ -6750,7 +6807,7 @@ function makeClassicSubscribeFn(events) {
6750
6807
  return subscribe;
6751
6808
  }
6752
6809
  function isRoomEventName(value) {
6753
- return value === "my-presence" || value === "others" || value === "event" || value === "error" || value === "history" || value === "status" || value === "storage-status" || value === "lost-connection" || value === "connection";
6810
+ return value === "my-presence" || value === "others" || value === "event" || value === "error" || value === "history" || value === "status" || value === "storage-status" || value === "lost-connection" || value === "connection" || value === "comments";
6754
6811
  }
6755
6812
  function makeAuthDelegateForRoom(roomId, authManager) {
6756
6813
  return async () => {
@@ -7422,6 +7479,7 @@ function createClient(options) {
7422
7479
  const currentUserIdStore = createStore(null);
7423
7480
  const {
7424
7481
  getInboxNotifications,
7482
+ getInboxNotificationsSince,
7425
7483
  getUnreadInboxNotificationsCount,
7426
7484
  markAllInboxNotificationsAsRead,
7427
7485
  markInboxNotificationAsRead,
@@ -7468,16 +7526,15 @@ function createClient(options) {
7468
7526
  enterRoom,
7469
7527
  getRoom,
7470
7528
  logout,
7529
+ getInboxNotifications,
7530
+ getInboxNotificationsSince,
7531
+ getUnreadInboxNotificationsCount,
7532
+ markAllInboxNotificationsAsRead,
7533
+ markInboxNotificationAsRead,
7534
+ deleteAllInboxNotifications,
7535
+ deleteInboxNotification,
7471
7536
  // Internal
7472
7537
  [kInternal]: {
7473
- notifications: {
7474
- getInboxNotifications,
7475
- getUnreadInboxNotificationsCount,
7476
- markAllInboxNotificationsAsRead,
7477
- markInboxNotificationAsRead,
7478
- deleteAllInboxNotifications,
7479
- deleteInboxNotification
7480
- },
7481
7538
  currentUserIdStore,
7482
7539
  resolveMentionSuggestions: clientOptions.resolveMentionSuggestions,
7483
7540
  cacheStore,
@@ -8373,6 +8430,9 @@ export {
8373
8430
  convertToInboxNotificationData,
8374
8431
  convertToThreadData,
8375
8432
  createClient,
8433
+ createCommentId,
8434
+ createInboxNotificationId,
8435
+ createThreadId,
8376
8436
  deleteComment,
8377
8437
  deprecate,
8378
8438
  deprecateIf,
@@ -8394,6 +8454,7 @@ export {
8394
8454
  makePoller,
8395
8455
  makePosition,
8396
8456
  memoizeOnSuccess,
8457
+ nanoid,
8397
8458
  nn,
8398
8459
  objectToQuery,
8399
8460
  patchLiveObjectKey,