@liveblocks/node 3.6.0 → 3.7.0-preview1

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.js CHANGED
@@ -3,7 +3,7 @@ import { detectDupes } from "@liveblocks/core";
3
3
 
4
4
  // src/version.ts
5
5
  var PKG_NAME = "@liveblocks/node";
6
- var PKG_VERSION = "3.6.0";
6
+ var PKG_VERSION = "3.7.0-preview1";
7
7
  var PKG_FORMAT = "esm";
8
8
 
9
9
  // src/client.ts
@@ -12,6 +12,7 @@ import {
12
12
  ClientMsgCode,
13
13
  convertToCommentData,
14
14
  convertToCommentUserReaction,
15
+ convertToGroupData,
15
16
  convertToInboxNotificationData,
16
17
  convertToSubscriptionData,
17
18
  convertToThreadData,
@@ -170,14 +171,16 @@ var Session = class {
170
171
  #postFn;
171
172
  #userId;
172
173
  #userInfo;
174
+ #tenantId;
173
175
  #sealed = false;
174
176
  #permissions = /* @__PURE__ */ new Map();
175
177
  /** @internal */
176
- constructor(postFn, userId, userInfo) {
178
+ constructor(postFn, userId, userInfo, tenantId) {
177
179
  assertNonEmpty(userId, "userId");
178
180
  this.#postFn = postFn;
179
181
  this.#userId = userId;
180
182
  this.#userInfo = userInfo;
183
+ this.#tenantId = tenantId;
181
184
  }
182
185
  #getOrCreate(roomId) {
183
186
  if (this.#sealed) {
@@ -256,7 +259,8 @@ var Session = class {
256
259
  userId: this.#userId,
257
260
  permissions: this.serializePermissions(),
258
261
  // Optional metadata
259
- userInfo: this.#userInfo
262
+ userInfo: this.#userInfo,
263
+ tenantId: this.#tenantId
260
264
  });
261
265
  return {
262
266
  status: normalizeStatusCode(resp.status),
@@ -361,8 +365,8 @@ var Liveblocks = class {
361
365
  signal: options?.signal
362
366
  });
363
367
  }
364
- async #delete(path, options) {
365
- const url3 = urljoin(this.#baseUrl, path);
368
+ async #delete(path, params, options) {
369
+ const url3 = urljoin(this.#baseUrl, path, params);
366
370
  const headers = {
367
371
  Authorization: `Bearer ${this.#secret}`
368
372
  };
@@ -401,6 +405,8 @@ var Liveblocks = class {
401
405
  * uniquely identify the user account in your system. The uniqueness of this
402
406
  * value will determine how many MAUs will be counted/billed.
403
407
  *
408
+ * @param tenantId (optional) The tenant ID to authorize the user for.
409
+ *
404
410
  * @param options.userInfo Custom metadata to attach to this user. Data you
405
411
  * add here will be visible to all other clients in the room, through the
406
412
  * `other.info` property.
@@ -408,7 +414,12 @@ var Liveblocks = class {
408
414
  */
409
415
  prepareSession(userId, ...rest) {
410
416
  const options = rest[0];
411
- return new Session(this.#post.bind(this), userId, options?.userInfo);
417
+ return new Session(
418
+ this.#post.bind(this),
419
+ userId,
420
+ options?.userInfo,
421
+ options?.tenantId
422
+ );
412
423
  }
413
424
  /**
414
425
  * Call this to authenticate the user as an actor you want to allow to use
@@ -481,6 +492,7 @@ var Liveblocks = class {
481
492
  * @param params.userId (optional) A filter on users accesses.
482
493
  * @param params.metadata (optional) A filter on metadata. Multiple metadata keys can be used to filter rooms.
483
494
  * @param params.groupIds (optional) A filter on groups accesses. Multiple groups can be used.
495
+ * @param params.tenantId (optional) A filter on tenant ID.
484
496
  * @param params.query (optional) A query to filter rooms by. It is based on our query language. You can filter by metadata and room ID.
485
497
  * @param options.signal (optional) An abort signal to cancel the request.
486
498
  * @returns A list of rooms.
@@ -550,6 +562,7 @@ var Liveblocks = class {
550
562
  * @param params.groupsAccesses (optional) The group accesses for the room. Can contain a maximum of 100 entries. Key length has a limit of 40 characters.
551
563
  * @param params.usersAccesses (optional) The user accesses for the room. Can contain a maximum of 100 entries. Key length has a limit of 40 characters.
552
564
  * @param params.metadata (optional) The metadata for the room. Supports upto a maximum of 50 entries. Key length has a limit of 40 characters. Value length has a limit of 256 characters.
565
+ * @param params.tenantId (optional) The tenant ID to create the room for.
553
566
  * @param options.signal (optional) An abort signal to cancel the request.
554
567
  * @returns The created room.
555
568
  */
@@ -581,6 +594,7 @@ var Liveblocks = class {
581
594
  * @param params.groupsAccesses (optional) The group accesses for the room if the room will be created. Can contain a maximum of 100 entries. Key length has a limit of 40 characters.
582
595
  * @param params.usersAccesses (optional) The user accesses for the room if the room will be created. Can contain a maximum of 100 entries. Key length has a limit of 40 characters.
583
596
  * @param params.metadata (optional) The metadata for the room if the room will be created. Supports upto a maximum of 50 entries. Key length has a limit of 40 characters. Value length has a limit of 256 characters.
597
+ * @param params.tenantId (optional) The tenant ID to create the room for.
584
598
  * @param options.signal (optional) An abort signal to cancel the request.
585
599
  * @returns The room.
586
600
  */
@@ -660,7 +674,11 @@ var Liveblocks = class {
660
674
  * @param options.signal (optional) An abort signal to cancel the request.
661
675
  */
662
676
  async deleteRoom(roomId, options) {
663
- const res = await this.#delete(url2`/v2/rooms/${roomId}`, options);
677
+ const res = await this.#delete(
678
+ url2`/v2/rooms/${roomId}`,
679
+ void 0,
680
+ options
681
+ );
664
682
  if (!res.ok) {
665
683
  throw await LiveblocksError.from(res);
666
684
  }
@@ -759,7 +777,11 @@ var Liveblocks = class {
759
777
  * @param options.signal (optional) An abort signal to cancel the request.
760
778
  */
761
779
  async deleteStorageDocument(roomId, options) {
762
- const res = await this.#delete(url2`/v2/rooms/${roomId}/storage`, options);
780
+ const res = await this.#delete(
781
+ url2`/v2/rooms/${roomId}/storage`,
782
+ void 0,
783
+ options
784
+ );
763
785
  if (!res.ok) {
764
786
  throw await LiveblocksError.from(res);
765
787
  }
@@ -905,7 +927,11 @@ var Liveblocks = class {
905
927
  * @param options.signal (optional) An abort signal to cancel the request.
906
928
  */
907
929
  async deleteSchema(schemaId, options) {
908
- const res = await this.#delete(url2`/v2/schemas/${schemaId}`, options);
930
+ const res = await this.#delete(
931
+ url2`/v2/schemas/${schemaId}`,
932
+ void 0,
933
+ options
934
+ );
909
935
  if (!res.ok) {
910
936
  throw await LiveblocksError.from(res);
911
937
  }
@@ -959,7 +985,11 @@ var Liveblocks = class {
959
985
  * @param options.signal (optional) An abort signal to cancel the request.
960
986
  */
961
987
  async detachSchemaFromRoom(roomId, options) {
962
- const res = await this.#delete(url2`/v2/rooms/${roomId}/schema`, options);
988
+ const res = await this.#delete(
989
+ url2`/v2/rooms/${roomId}/schema`,
990
+ void 0,
991
+ options
992
+ );
963
993
  if (!res.ok) {
964
994
  throw await LiveblocksError.from(res);
965
995
  }
@@ -1017,10 +1047,14 @@ var Liveblocks = class {
1017
1047
  return convertToThreadData(await res.json());
1018
1048
  }
1019
1049
  /**
1050
+ * @deprecated Prefer using `getMentionsFromCommentBody` to extract mentions
1051
+ * from comments and threads, or `Liveblocks.getThreadSubscriptions` to get
1052
+ * the list of users who are subscribed to a thread.
1053
+ *
1020
1054
  * Gets a thread's participants.
1021
1055
  *
1022
1056
  * Participants are users who have commented on the thread
1023
- * or users and groups that have been mentioned in a comment.
1057
+ * or users that have been mentioned in a comment.
1024
1058
  *
1025
1059
  * @param params.roomId The room ID to get the thread participants from.
1026
1060
  * @param params.threadId The thread ID to get the participants from.
@@ -1142,6 +1176,7 @@ var Liveblocks = class {
1142
1176
  const { roomId, threadId, commentId } = params;
1143
1177
  const res = await this.#delete(
1144
1178
  url2`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}`,
1179
+ void 0,
1145
1180
  options
1146
1181
  );
1147
1182
  if (!res.ok) {
@@ -1187,6 +1222,7 @@ var Liveblocks = class {
1187
1222
  const { roomId, threadId } = params;
1188
1223
  const res = await this.#delete(
1189
1224
  url2`/v2/rooms/${roomId}/threads/${threadId}`,
1225
+ void 0,
1190
1226
  options
1191
1227
  );
1192
1228
  if (!res.ok) {
@@ -1373,10 +1409,11 @@ var Liveblocks = class {
1373
1409
  * Returns the inbox notifications for a user.
1374
1410
  * @param params.userId The user ID to get the inbox notifications from.
1375
1411
  * @param params.query The query to filter inbox notifications by. It is based on our query language and can filter by unread.
1412
+ * @param params.tenantId (optional) The tenant ID to get the inbox notifications for.
1376
1413
  * @param options.signal (optional) An abort signal to cancel the request.
1377
1414
  */
1378
1415
  async getInboxNotifications(params, options) {
1379
- const { userId } = params;
1416
+ const { userId, tenantId, limit, startingAfter } = params;
1380
1417
  let query;
1381
1418
  if (typeof params.query === "string") {
1382
1419
  query = params.query;
@@ -1387,8 +1424,9 @@ var Liveblocks = class {
1387
1424
  url2`/v2/users/${userId}/inbox-notifications`,
1388
1425
  {
1389
1426
  query,
1390
- limit: params?.limit,
1391
- startingAfter: params?.startingAfter
1427
+ limit,
1428
+ startingAfter,
1429
+ tenantId
1392
1430
  },
1393
1431
  options
1394
1432
  );
@@ -1409,6 +1447,7 @@ var Liveblocks = class {
1409
1447
  *
1410
1448
  * @param criteria.userId The user ID to get the inbox notifications from.
1411
1449
  * @param criteria.query The query to filter inbox notifications by. It is based on our query language and can filter by unread.
1450
+ * @param criteria.tenantId (optional) The tenant ID to get the inbox notifications for.
1412
1451
  * @param options.pageSize (optional) The page size to use for each request.
1413
1452
  * @param options.signal (optional) An abort signal to cancel the request.
1414
1453
  */
@@ -1433,15 +1472,17 @@ var Liveblocks = class {
1433
1472
  /**
1434
1473
  * Returns all room subscription settings for a user.
1435
1474
  * @param params.userId The user ID to get the room subscription settings from.
1475
+ * @param params.tenantId (optional) The tenant ID to get the room subscription settings for.
1436
1476
  * @param params.startingAfter (optional) The cursor to start the pagination from.
1437
1477
  * @param params.limit (optional) The number of items to return.
1438
1478
  * @param options.signal (optional) An abort signal to cancel the request.
1439
1479
  */
1440
1480
  async getUserRoomSubscriptionSettings(params, options) {
1441
- const { userId, startingAfter, limit } = params;
1481
+ const { userId, tenantId, startingAfter, limit } = params;
1442
1482
  const res = await this.#get(
1443
1483
  url2`/v2/users/${userId}/room-subscription-settings`,
1444
1484
  {
1485
+ tenantId,
1445
1486
  startingAfter,
1446
1487
  limit
1447
1488
  },
@@ -1499,6 +1540,7 @@ var Liveblocks = class {
1499
1540
  const { userId, roomId } = params;
1500
1541
  const res = await this.#delete(
1501
1542
  url2`/v2/rooms/${roomId}/users/${userId}/subscription-settings`,
1543
+ void 0,
1502
1544
  options
1503
1545
  );
1504
1546
  if (!res.ok) {
@@ -1524,6 +1566,16 @@ var Liveblocks = class {
1524
1566
  const data = await res.json();
1525
1567
  return inflateRoomData(data);
1526
1568
  }
1569
+ /**
1570
+ * Triggers an inbox notification for a user.
1571
+ * @param params.userId The user ID to trigger the inbox notification for.
1572
+ * @param params.kind The kind of inbox notification to trigger.
1573
+ * @param params.subjectId The subject ID of the triggered inbox notification.
1574
+ * @param params.activityData The activity data of the triggered inbox notification.
1575
+ * @param params.roomId (optional) The room ID to trigger the inbox notification for.
1576
+ * @param params.tenantId (optional) The tenant ID to trigger the inbox notification for.
1577
+ * @param options.signal (optional) An abort signal to cancel the request.
1578
+ */
1527
1579
  async triggerInboxNotification(params, options) {
1528
1580
  const res = await this.#post(
1529
1581
  url2`/v2/inbox-notifications/trigger`,
@@ -1544,6 +1596,7 @@ var Liveblocks = class {
1544
1596
  const { userId, inboxNotificationId } = params;
1545
1597
  const res = await this.#delete(
1546
1598
  url2`/v2/users/${userId}/inbox-notifications/${inboxNotificationId}`,
1599
+ void 0,
1547
1600
  options
1548
1601
  );
1549
1602
  if (!res.ok) {
@@ -1553,12 +1606,14 @@ var Liveblocks = class {
1553
1606
  /**
1554
1607
  * Deletes all inbox notifications for a user.
1555
1608
  * @param params.userId The user ID for which to delete all the inbox notifications.
1609
+ * @param params.tenantId (optional) The tenant ID to delete the inbox notifications for.
1556
1610
  * @param options.signal (optional) An abort signal to cancel the request.
1557
1611
  */
1558
1612
  async deleteAllInboxNotifications(params, options) {
1559
- const { userId } = params;
1613
+ const { userId, tenantId } = params;
1560
1614
  const res = await this.#delete(
1561
1615
  url2`/v2/users/${userId}/inbox-notifications`,
1616
+ { tenantId },
1562
1617
  options
1563
1618
  );
1564
1619
  if (!res.ok) {
@@ -1613,11 +1668,149 @@ var Liveblocks = class {
1613
1668
  const { userId } = params;
1614
1669
  const res = await this.#delete(
1615
1670
  url2`/v2/users/${userId}/notification-settings`,
1671
+ void 0,
1672
+ options
1673
+ );
1674
+ if (!res.ok) {
1675
+ throw await LiveblocksError.from(res);
1676
+ }
1677
+ }
1678
+ /**
1679
+ * Create a group
1680
+ * @param params.groupId The ID of the group to create.
1681
+ * @param params.memberIds The IDs of the members to add to the group.
1682
+ * @param params.tenantId (optional) The tenant ID to create the group for.
1683
+ * @param params.scopes (optional) The scopes to grant to the group. The default is `{ mention: true }`.
1684
+ * @param options.signal (optional) An abort signal to cancel the request.
1685
+ */
1686
+ async createGroup(params, options) {
1687
+ const res = await this.#post(
1688
+ url2`/v2/groups`,
1689
+ {
1690
+ ...params,
1691
+ // The REST API uses `id` since a group is a resource,
1692
+ // but we use `groupId` here for consistency with the other methods.
1693
+ id: params.groupId
1694
+ },
1616
1695
  options
1617
1696
  );
1618
1697
  if (!res.ok) {
1619
1698
  throw await LiveblocksError.from(res);
1620
1699
  }
1700
+ const group = await res.json();
1701
+ return convertToGroupData(group);
1702
+ }
1703
+ /**
1704
+ * Get a group
1705
+ * @param params.groupId The ID of the group to get.
1706
+ * @param options.signal (optional) An abort signal to cancel the request.
1707
+ */
1708
+ async getGroup(params, options) {
1709
+ const res = await this.#get(
1710
+ url2`/v2/groups/${params.groupId}`,
1711
+ void 0,
1712
+ options
1713
+ );
1714
+ if (!res.ok) {
1715
+ throw await LiveblocksError.from(res);
1716
+ }
1717
+ const group = await res.json();
1718
+ return convertToGroupData(group);
1719
+ }
1720
+ /**
1721
+ * Add members to a group
1722
+ * @param params.groupId The ID of the group to add members to.
1723
+ * @param params.memberIds The IDs of the members to add to the group.
1724
+ * @param options.signal (optional) An abort signal to cancel the request.
1725
+ */
1726
+ async addGroupMembers(params, options) {
1727
+ const res = await this.#post(
1728
+ url2`/v2/groups/${params.groupId}/add-members`,
1729
+ { memberIds: params.memberIds },
1730
+ options
1731
+ );
1732
+ if (!res.ok) {
1733
+ throw await LiveblocksError.from(res);
1734
+ }
1735
+ const group = await res.json();
1736
+ return convertToGroupData(group);
1737
+ }
1738
+ /**
1739
+ * Remove members from a group
1740
+ * @param params.groupId The ID of the group to remove members from.
1741
+ * @param params.memberIds The IDs of the members to remove from the group.
1742
+ * @param options.signal (optional) An abort signal to cancel the request.
1743
+ */
1744
+ async removeGroupMembers(params, options) {
1745
+ const res = await this.#post(
1746
+ url2`/v2/groups/${params.groupId}/remove-members`,
1747
+ { memberIds: params.memberIds },
1748
+ options
1749
+ );
1750
+ if (!res.ok) {
1751
+ throw await LiveblocksError.from(res);
1752
+ }
1753
+ const group = await res.json();
1754
+ return convertToGroupData(group);
1755
+ }
1756
+ /**
1757
+ * Delete a group
1758
+ * @param params.groupId The ID of the group to delete.
1759
+ * @param options.signal (optional) An abort signal to cancel the request.
1760
+ */
1761
+ async deleteGroup(params, options) {
1762
+ const res = await this.#delete(
1763
+ url2`/v2/groups/${params.groupId}`,
1764
+ void 0,
1765
+ options
1766
+ );
1767
+ if (!res.ok) {
1768
+ throw await LiveblocksError.from(res);
1769
+ }
1770
+ }
1771
+ /**
1772
+ * Get all groups
1773
+ * @param params.limit (optional) The number of groups to return.
1774
+ * @param params.startingAfter (optional) The cursor to start the pagination from.
1775
+ * @param options.signal (optional) An abort signal to cancel the request.
1776
+ */
1777
+ async getGroups(params, options) {
1778
+ const res = await this.#get(
1779
+ url2`/v2/groups`,
1780
+ { startingAfter: params?.startingAfter, limit: params?.limit },
1781
+ options
1782
+ );
1783
+ if (!res.ok) {
1784
+ throw await LiveblocksError.from(res);
1785
+ }
1786
+ const page = await res.json();
1787
+ return {
1788
+ ...page,
1789
+ data: page.data.map(convertToGroupData)
1790
+ };
1791
+ }
1792
+ /**
1793
+ * Returns all groups a user is a member of.
1794
+ * @param params.userId The user ID to get the groups for.
1795
+ * @param params.startingAfter (optional) The cursor to start the pagination from.
1796
+ * @param params.limit (optional) The number of items to return.
1797
+ * @param options.signal (optional) An abort signal to cancel the request.
1798
+ */
1799
+ async getUserGroups(params, options) {
1800
+ const { userId, startingAfter, limit } = params;
1801
+ const res = await this.#get(
1802
+ url2`/v2/users/${userId}/groups`,
1803
+ { startingAfter, limit },
1804
+ options
1805
+ );
1806
+ if (!res.ok) {
1807
+ throw await LiveblocksError.from(res);
1808
+ }
1809
+ const page = await res.json();
1810
+ return {
1811
+ ...page,
1812
+ data: page.data.map(convertToGroupData)
1813
+ };
1621
1814
  }
1622
1815
  /**
1623
1816
  * Retrieves the current Storage contents for the given room ID and calls the
@@ -1814,7 +2007,11 @@ var Liveblocks = class {
1814
2007
  * @param options.signal (optional) An abort signal to cancel the request.
1815
2008
  */
1816
2009
  async deleteAiCopilot(copilotId, options) {
1817
- const res = await this.#delete(url2`/v2/ai/copilots/${copilotId}`, options);
2010
+ const res = await this.#delete(
2011
+ url2`/v2/ai/copilots/${copilotId}`,
2012
+ void 0,
2013
+ options
2014
+ );
1818
2015
  if (!res.ok) {
1819
2016
  throw await LiveblocksError.from(res);
1820
2017
  }
@@ -1879,6 +2076,7 @@ var Liveblocks = class {
1879
2076
  async deleteFileKnowledgeSource(params, options) {
1880
2077
  const res = await this.#delete(
1881
2078
  url2`/v2/ai/copilots/${params.copilotId}/knowledge/file/${params.knowledgeSourceId}`,
2079
+ void 0,
1882
2080
  options
1883
2081
  );
1884
2082
  if (!res.ok) {
@@ -1894,6 +2092,7 @@ var Liveblocks = class {
1894
2092
  async deleteWebKnowledgeSource(params, options) {
1895
2093
  const res = await this.#delete(
1896
2094
  url2`/v2/ai/copilots/${params.copilotId}/knowledge/web/${params.knowledgeSourceId}`,
2095
+ void 0,
1897
2096
  options
1898
2097
  );
1899
2098
  if (!res.ok) {