@liveblocks/core 1.3.1 → 1.3.3

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
@@ -655,7 +655,7 @@ declare type AuthValue = {
655
655
  declare type BaseMetadata = Record<string, string | boolean | number>;
656
656
 
657
657
  declare type CommentBodyBlockElement = CommentBodyParagraph;
658
- declare type CommentBodyInlineElement = CommentBodyText | CommentBodyMention;
658
+ declare type CommentBodyInlineElement = CommentBodyText | CommentBodyMention | CommentBodyLink;
659
659
  declare type CommentBodyElement = CommentBodyBlockElement | CommentBodyInlineElement;
660
660
  declare type CommentBodyParagraph = {
661
661
  type: "paragraph";
@@ -665,6 +665,10 @@ declare type CommentBodyMention = {
665
665
  type: "mention";
666
666
  id: string;
667
667
  };
668
+ declare type CommentBodyLink = {
669
+ type: "link";
670
+ url: string;
671
+ };
668
672
  declare type CommentBodyText = {
669
673
  bold?: boolean;
670
674
  italic?: boolean;
@@ -1103,7 +1107,8 @@ declare type YDocUpdate = {
1103
1107
  declare type BroadcastedEventServerMsg<TRoomEvent extends Json> = {
1104
1108
  readonly type: ServerMsgCode.BROADCASTED_EVENT;
1105
1109
  /**
1106
- * The User who broadcasted the Event.
1110
+ * The User who broadcast the Event. Absent when this event is broadcast from
1111
+ * the REST API in the backend.
1107
1112
  */
1108
1113
  readonly actor: number;
1109
1114
  /**
@@ -1223,6 +1228,11 @@ declare type OthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUse
1223
1228
  };
1224
1229
 
1225
1230
  declare type CustomEvent<TRoomEvent extends Json> = {
1231
+ /**
1232
+ * The connection ID of the client that sent the event.
1233
+ * If this message was broadcast from the server (via the REST API), then
1234
+ * this value will be -1.
1235
+ */
1226
1236
  connectionId: number;
1227
1237
  event: TRoomEvent;
1228
1238
  };
@@ -2282,4 +2292,4 @@ declare type EnsureJson<T> = [
2282
2292
  [K in keyof T]: EnsureJson<T[K]>;
2283
2293
  };
2284
2294
 
2285
- export { AckOp, AsyncCache, AsyncState, AsyncStateError, AsyncStateInitial, AsyncStateLoading, AsyncStateResolved, AsyncStateSuccess, BaseAuthResult, BaseMetadata, BaseUserMeta, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CommentBody, CommentBodyElement, CommentBodyMention, CommentBodyParagraph, CommentData, CommentsApi, CrdtType, CreateChildOp, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CreateRootObjectOp, CustomAuthenticationResult, Delegates, DeleteCrdtOp, DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, EnsureJson, EventSource, FetchStorageClientMsg, FetchYDocClientMsg, History, IWebSocket, IWebSocketCloseEvent, IWebSocketEvent, IWebSocketInstance, IWebSocketMessageEvent, IdTuple, Immutable, InitialDocumentStateServerMsg, Json, JsonArray, JsonObject, JsonScalar, LegacyConnectionStatus, LiveList, LiveListUpdate, LiveMap, LiveMapUpdate, LiveNode, LiveObject, LiveObjectUpdate, LiveStructure, LostConnectionEvent, Lson, LsonObject, NodeMap, Op, OpCode, Others, ParentToChildNodeMap, PlainLson, PlainLsonFields, PlainLsonList, PlainLsonMap, PlainLsonObject, RejectedStorageOpServerMsg, Resolve, Room, RoomInitializers, RoomStateServerMsg, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, Status, StorageStatus, StorageUpdate, ThreadData, ToImmutable, ToJson, UnsubscribeCallback, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UpdateYDocClientMsg, User, UserJoinServerMsg, UserLeftServerMsg, WebsocketCloseCodes, asPos, assert, assertNever, b64decode, fancyConsole as console, createAsyncCache, createClient, createCommentsApi, deprecate, deprecateIf, detectDupes, errorIf, freeze, isChildCrdt, isJsonArray, isJsonObject, isJsonScalar, isPlainObject, isRootCrdt, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, nn, patchLiveObjectKey, shallow, throwUsageError, toPlainLson, tryParseJson, withTimeout };
2295
+ export { AckOp, AsyncCache, AsyncState, AsyncStateError, AsyncStateInitial, AsyncStateLoading, AsyncStateResolved, AsyncStateSuccess, BaseAuthResult, BaseMetadata, BaseUserMeta, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CommentBody, CommentBodyElement, CommentBodyLink, CommentBodyMention, CommentBodyParagraph, CommentData, CommentsApi, CrdtType, CreateChildOp, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CreateRootObjectOp, CustomAuthenticationResult, Delegates, DeleteCrdtOp, DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, EnsureJson, EventSource, FetchStorageClientMsg, FetchYDocClientMsg, History, IWebSocket, IWebSocketCloseEvent, IWebSocketEvent, IWebSocketInstance, IWebSocketMessageEvent, IdTuple, Immutable, InitialDocumentStateServerMsg, Json, JsonArray, JsonObject, JsonScalar, LegacyConnectionStatus, LiveList, LiveListUpdate, LiveMap, LiveMapUpdate, LiveNode, LiveObject, LiveObjectUpdate, LiveStructure, LostConnectionEvent, Lson, LsonObject, NodeMap, Op, OpCode, Others, ParentToChildNodeMap, PlainLson, PlainLsonFields, PlainLsonList, PlainLsonMap, PlainLsonObject, RejectedStorageOpServerMsg, Resolve, Room, RoomInitializers, RoomStateServerMsg, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, Status, StorageStatus, StorageUpdate, ThreadData, ToImmutable, ToJson, UnsubscribeCallback, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UpdateYDocClientMsg, User, UserJoinServerMsg, UserLeftServerMsg, WebsocketCloseCodes, asPos, assert, assertNever, b64decode, fancyConsole as console, createAsyncCache, createClient, createCommentsApi, deprecate, deprecateIf, detectDupes, errorIf, freeze, isChildCrdt, isJsonArray, isJsonObject, isJsonScalar, isPlainObject, isRootCrdt, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, nn, patchLiveObjectKey, shallow, throwUsageError, toPlainLson, tryParseJson, withTimeout };
package/dist/index.d.ts CHANGED
@@ -655,7 +655,7 @@ declare type AuthValue = {
655
655
  declare type BaseMetadata = Record<string, string | boolean | number>;
656
656
 
657
657
  declare type CommentBodyBlockElement = CommentBodyParagraph;
658
- declare type CommentBodyInlineElement = CommentBodyText | CommentBodyMention;
658
+ declare type CommentBodyInlineElement = CommentBodyText | CommentBodyMention | CommentBodyLink;
659
659
  declare type CommentBodyElement = CommentBodyBlockElement | CommentBodyInlineElement;
660
660
  declare type CommentBodyParagraph = {
661
661
  type: "paragraph";
@@ -665,6 +665,10 @@ declare type CommentBodyMention = {
665
665
  type: "mention";
666
666
  id: string;
667
667
  };
668
+ declare type CommentBodyLink = {
669
+ type: "link";
670
+ url: string;
671
+ };
668
672
  declare type CommentBodyText = {
669
673
  bold?: boolean;
670
674
  italic?: boolean;
@@ -1103,7 +1107,8 @@ declare type YDocUpdate = {
1103
1107
  declare type BroadcastedEventServerMsg<TRoomEvent extends Json> = {
1104
1108
  readonly type: ServerMsgCode.BROADCASTED_EVENT;
1105
1109
  /**
1106
- * The User who broadcasted the Event.
1110
+ * The User who broadcast the Event. Absent when this event is broadcast from
1111
+ * the REST API in the backend.
1107
1112
  */
1108
1113
  readonly actor: number;
1109
1114
  /**
@@ -1223,6 +1228,11 @@ declare type OthersEvent<TPresence extends JsonObject, TUserMeta extends BaseUse
1223
1228
  };
1224
1229
 
1225
1230
  declare type CustomEvent<TRoomEvent extends Json> = {
1231
+ /**
1232
+ * The connection ID of the client that sent the event.
1233
+ * If this message was broadcast from the server (via the REST API), then
1234
+ * this value will be -1.
1235
+ */
1226
1236
  connectionId: number;
1227
1237
  event: TRoomEvent;
1228
1238
  };
@@ -2282,4 +2292,4 @@ declare type EnsureJson<T> = [
2282
2292
  [K in keyof T]: EnsureJson<T[K]>;
2283
2293
  };
2284
2294
 
2285
- export { AckOp, AsyncCache, AsyncState, AsyncStateError, AsyncStateInitial, AsyncStateLoading, AsyncStateResolved, AsyncStateSuccess, BaseAuthResult, BaseMetadata, BaseUserMeta, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CommentBody, CommentBodyElement, CommentBodyMention, CommentBodyParagraph, CommentData, CommentsApi, CrdtType, CreateChildOp, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CreateRootObjectOp, CustomAuthenticationResult, Delegates, DeleteCrdtOp, DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, EnsureJson, EventSource, FetchStorageClientMsg, FetchYDocClientMsg, History, IWebSocket, IWebSocketCloseEvent, IWebSocketEvent, IWebSocketInstance, IWebSocketMessageEvent, IdTuple, Immutable, InitialDocumentStateServerMsg, Json, JsonArray, JsonObject, JsonScalar, LegacyConnectionStatus, LiveList, LiveListUpdate, LiveMap, LiveMapUpdate, LiveNode, LiveObject, LiveObjectUpdate, LiveStructure, LostConnectionEvent, Lson, LsonObject, NodeMap, Op, OpCode, Others, ParentToChildNodeMap, PlainLson, PlainLsonFields, PlainLsonList, PlainLsonMap, PlainLsonObject, RejectedStorageOpServerMsg, Resolve, Room, RoomInitializers, RoomStateServerMsg, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, Status, StorageStatus, StorageUpdate, ThreadData, ToImmutable, ToJson, UnsubscribeCallback, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UpdateYDocClientMsg, User, UserJoinServerMsg, UserLeftServerMsg, WebsocketCloseCodes, asPos, assert, assertNever, b64decode, fancyConsole as console, createAsyncCache, createClient, createCommentsApi, deprecate, deprecateIf, detectDupes, errorIf, freeze, isChildCrdt, isJsonArray, isJsonObject, isJsonScalar, isPlainObject, isRootCrdt, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, nn, patchLiveObjectKey, shallow, throwUsageError, toPlainLson, tryParseJson, withTimeout };
2295
+ export { AckOp, AsyncCache, AsyncState, AsyncStateError, AsyncStateInitial, AsyncStateLoading, AsyncStateResolved, AsyncStateSuccess, BaseAuthResult, BaseMetadata, BaseUserMeta, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CommentBody, CommentBodyElement, CommentBodyLink, CommentBodyMention, CommentBodyParagraph, CommentData, CommentsApi, CrdtType, CreateChildOp, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CreateRootObjectOp, CustomAuthenticationResult, Delegates, DeleteCrdtOp, DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, EnsureJson, EventSource, FetchStorageClientMsg, FetchYDocClientMsg, History, IWebSocket, IWebSocketCloseEvent, IWebSocketEvent, IWebSocketInstance, IWebSocketMessageEvent, IdTuple, Immutable, InitialDocumentStateServerMsg, Json, JsonArray, JsonObject, JsonScalar, LegacyConnectionStatus, LiveList, LiveListUpdate, LiveMap, LiveMapUpdate, LiveNode, LiveObject, LiveObjectUpdate, LiveStructure, LostConnectionEvent, Lson, LsonObject, NodeMap, Op, OpCode, Others, ParentToChildNodeMap, PlainLson, PlainLsonFields, PlainLsonList, PlainLsonMap, PlainLsonObject, RejectedStorageOpServerMsg, Resolve, Room, RoomInitializers, RoomStateServerMsg, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, Status, StorageStatus, StorageUpdate, ThreadData, ToImmutable, ToJson, UnsubscribeCallback, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UpdateYDocClientMsg, User, UserJoinServerMsg, UserLeftServerMsg, WebsocketCloseCodes, asPos, assert, assertNever, b64decode, fancyConsole as console, createAsyncCache, createClient, createCommentsApi, deprecate, deprecateIf, detectDupes, errorIf, freeze, isChildCrdt, isJsonArray, isJsonObject, isJsonScalar, isPlainObject, isRootCrdt, legacy_patchImmutableObject, lsonToJson, makeEventSource, makePoller, makePosition, nn, patchLiveObjectKey, shallow, throwUsageError, toPlainLson, tryParseJson, withTimeout };
package/dist/index.js 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 = "1.3.1";
9
+ var PKG_VERSION = "1.3.3";
10
10
  var PKG_FORMAT = "cjs";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -1281,6 +1281,7 @@ function parseAuthToken(rawTokenString) {
1281
1281
  // src/auth-manager.ts
1282
1282
  function createAuthManager(authOptions) {
1283
1283
  const authentication = prepareAuthentication(authOptions);
1284
+ const seenTokens = /* @__PURE__ */ new Set();
1284
1285
  const tokens = [];
1285
1286
  const expiryTimes = [];
1286
1287
  const requestPromises = /* @__PURE__ */ new Map();
@@ -1304,8 +1305,6 @@ function createAuthManager(authOptions) {
1304
1305
  }
1305
1306
  if (token.parsed.k === "id" /* ID_TOKEN */) {
1306
1307
  return token;
1307
- } else if (token.parsed.k === "sec-legacy" /* SECRET_LEGACY */) {
1308
- return void 0;
1309
1308
  } else if (token.parsed.k === "acc" /* ACCESS_TOKEN */) {
1310
1309
  for (const [resource, scopes] of Object.entries(token.parsed.perms)) {
1311
1310
  if (resource.includes("*") && roomId.startsWith(resource.replace("*", "")) || roomId === resource && hasCorrespondingScopes(requestedScope, scopes)) {
@@ -1327,7 +1326,13 @@ function createAuthManager(authOptions) {
1327
1326
  const response = await fetchAuthEndpoint(fetcher, authentication.url, {
1328
1327
  room: roomId
1329
1328
  });
1330
- return parseAuthToken(response.token);
1329
+ const parsed = parseAuthToken(response.token);
1330
+ if (seenTokens.has(parsed.raw)) {
1331
+ throw new StopRetrying(
1332
+ "The same Liveblocks auth token was issued from the backend before. Caching Liveblocks tokens is not supported."
1333
+ );
1334
+ }
1335
+ return parsed;
1331
1336
  }
1332
1337
  if (authentication.type === "custom") {
1333
1338
  const response = await authentication.callback(roomId);
@@ -1368,8 +1373,11 @@ function createAuthManager(authOptions) {
1368
1373
  const token = await currentPromise;
1369
1374
  const BUFFER = 30;
1370
1375
  const expiresAt = Math.floor(Date.now() / 1e3) + (token.parsed.exp - token.parsed.iat) - BUFFER;
1371
- tokens.push(token);
1372
- expiryTimes.push(expiresAt);
1376
+ seenTokens.add(token.raw);
1377
+ if (token.parsed.k !== "sec-legacy" /* SECRET_LEGACY */) {
1378
+ tokens.push(token);
1379
+ expiryTimes.push(expiresAt);
1380
+ }
1373
1381
  return { type: "secret", token };
1374
1382
  } finally {
1375
1383
  requestPromises.delete(roomId);
@@ -1703,7 +1711,9 @@ function createCommentsApi(roomId, getAuthValue, { serverEndpoint }) {
1703
1711
  }
1704
1712
  async function fetchApi(roomId2, endpoint, options) {
1705
1713
  const authValue = await getAuthValue();
1706
- const url = `${serverEndpoint}/c/rooms/${roomId2}${endpoint}`;
1714
+ const url = `${serverEndpoint}/c/rooms/${encodeURIComponent(
1715
+ roomId2
1716
+ )}${endpoint}`;
1707
1717
  return await fetch(url, {
1708
1718
  ...options,
1709
1719
  headers: {
@@ -1749,7 +1759,7 @@ function createCommentsApi(roomId, getAuthValue, { serverEndpoint }) {
1749
1759
  threadId
1750
1760
  }) {
1751
1761
  return fetchJson(
1752
- `/threads/${threadId}/metadata`,
1762
+ `/threads/${encodeURIComponent(threadId)}/metadata`,
1753
1763
  {
1754
1764
  method: "POST",
1755
1765
  headers: {
@@ -1764,16 +1774,19 @@ function createCommentsApi(roomId, getAuthValue, { serverEndpoint }) {
1764
1774
  commentId,
1765
1775
  body
1766
1776
  }) {
1767
- return fetchJson(`/threads/${threadId}/comments`, {
1768
- method: "POST",
1769
- headers: {
1770
- "Content-Type": "application/json"
1771
- },
1772
- body: JSON.stringify({
1773
- id: commentId,
1774
- body
1775
- })
1776
- });
1777
+ return fetchJson(
1778
+ `/threads/${encodeURIComponent(threadId)}/comments`,
1779
+ {
1780
+ method: "POST",
1781
+ headers: {
1782
+ "Content-Type": "application/json"
1783
+ },
1784
+ body: JSON.stringify({
1785
+ id: commentId,
1786
+ body
1787
+ })
1788
+ }
1789
+ );
1777
1790
  }
1778
1791
  function editComment({
1779
1792
  threadId,
@@ -1781,7 +1794,9 @@ function createCommentsApi(roomId, getAuthValue, { serverEndpoint }) {
1781
1794
  body
1782
1795
  }) {
1783
1796
  return fetchJson(
1784
- `/threads/${threadId}/comments/${commentId}`,
1797
+ `/threads/${encodeURIComponent(threadId)}/comments/${encodeURIComponent(
1798
+ commentId
1799
+ )}`,
1785
1800
  {
1786
1801
  method: "POST",
1787
1802
  headers: {
@@ -1797,9 +1812,14 @@ function createCommentsApi(roomId, getAuthValue, { serverEndpoint }) {
1797
1812
  threadId,
1798
1813
  commentId
1799
1814
  }) {
1800
- await fetchJson(`/threads/${threadId}/comments/${commentId}`, {
1801
- method: "DELETE"
1802
- });
1815
+ await fetchJson(
1816
+ `/threads/${encodeURIComponent(threadId)}/comments/${encodeURIComponent(
1817
+ commentId
1818
+ )}`,
1819
+ {
1820
+ method: "DELETE"
1821
+ }
1822
+ );
1803
1823
  }
1804
1824
  return {
1805
1825
  getThreads,