@liveblocks/node 2.22.1 → 2.22.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.cjs CHANGED
@@ -3,7 +3,7 @@ var _core = require('@liveblocks/core');
3
3
 
4
4
  // src/version.ts
5
5
  var PKG_NAME = "@liveblocks/node";
6
- var PKG_VERSION = "2.22.1";
6
+ var PKG_VERSION = "2.22.3";
7
7
  var PKG_FORMAT = "cjs";
8
8
 
9
9
  // src/client.ts
@@ -270,6 +270,15 @@ var Session = (_class = class {
270
270
  }, _class);
271
271
 
272
272
  // src/client.ts
273
+ function inflateRoomData(room) {
274
+ const createdAt = new Date(room.createdAt);
275
+ const lastConnectionAt = room.lastConnectionAt ? new Date(room.lastConnectionAt) : void 0;
276
+ return {
277
+ ...room,
278
+ createdAt,
279
+ lastConnectionAt
280
+ };
281
+ }
273
282
  var Liveblocks = class {
274
283
  #secret;
275
284
  #baseUrl;
@@ -477,15 +486,7 @@ var Liveblocks = class {
477
486
  throw await LiveblocksError.from(res);
478
487
  }
479
488
  const page = await res.json();
480
- const rooms = page.data.map((room) => {
481
- const lastConnectionAt = room.lastConnectionAt ? new Date(room.lastConnectionAt) : void 0;
482
- const createdAt = new Date(room.createdAt);
483
- return {
484
- ...room,
485
- createdAt,
486
- lastConnectionAt
487
- };
488
- });
489
+ const rooms = page.data.map(inflateRoomData);
489
490
  return {
490
491
  ...page,
491
492
  data: rooms
@@ -536,7 +537,7 @@ var Liveblocks = class {
536
537
  async createRoom(roomId, params, options) {
537
538
  const { defaultAccesses, groupsAccesses, usersAccesses, metadata } = params;
538
539
  const res = await this.#post(
539
- _core.url`/v2/rooms`,
540
+ _optionalChain([options, 'optionalAccess', _9 => _9.idempotent]) ? _core.url`/v2/rooms?idempotent` : _core.url`/v2/rooms`,
540
541
  {
541
542
  id: roomId,
542
543
  defaultAccesses,
@@ -550,13 +551,7 @@ var Liveblocks = class {
550
551
  throw await LiveblocksError.from(res);
551
552
  }
552
553
  const data = await res.json();
553
- const lastConnectionAt = data.lastConnectionAt ? new Date(data.lastConnectionAt) : void 0;
554
- const createdAt = new Date(data.createdAt);
555
- return {
556
- ...data,
557
- lastConnectionAt,
558
- createdAt
559
- };
554
+ return inflateRoomData(data);
560
555
  }
561
556
  /**
562
557
  * Returns a room with the given id, or creates one with the given creation
@@ -571,37 +566,31 @@ var Liveblocks = class {
571
566
  * @returns The room.
572
567
  */
573
568
  async getOrCreateRoom(roomId, params, options) {
574
- try {
575
- return await this.createRoom(roomId, params, options);
576
- } catch (err) {
577
- if (err instanceof LiveblocksError && err.status === 409) {
578
- return await this.getRoom(roomId, options);
579
- } else {
580
- throw err;
581
- }
582
- }
569
+ return await this.createRoom(roomId, params, {
570
+ ...options,
571
+ idempotent: true
572
+ });
583
573
  }
584
574
  /**
585
575
  * Updates or creates a new room with the given properties.
586
576
  *
587
577
  * @param roomId The id of the room to update or create.
588
- * @param params.defaultAccesses The default accesses for the room.
589
- * @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.
590
- * @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.
591
- * @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.
578
+ * @param update The fields to update. These values will be updated when the room exists, or set when the room does not exist and gets created. Must specify at least one key.
579
+ * @param create (optional) The fields to only use when the room does not exist and will be created. When the room already exists, these values are ignored.
592
580
  * @param options.signal (optional) An abort signal to cancel the request.
593
581
  * @returns The room.
594
582
  */
595
583
  async upsertRoom(roomId, params, options) {
596
- try {
597
- return await this.createRoom(roomId, params, options);
598
- } catch (err) {
599
- if (err instanceof LiveblocksError && err.status === 409) {
600
- return await this.updateRoom(roomId, params, options);
601
- } else {
602
- throw err;
603
- }
584
+ const res = await this.#post(
585
+ _core.url`/v2/rooms/${roomId}/upsert`,
586
+ params,
587
+ options
588
+ );
589
+ if (!res.ok) {
590
+ throw await LiveblocksError.from(res);
604
591
  }
592
+ const data = await res.json();
593
+ return inflateRoomData(data);
605
594
  }
606
595
  /**
607
596
  * Returns a room with the given id.
@@ -615,13 +604,7 @@ var Liveblocks = class {
615
604
  throw await LiveblocksError.from(res);
616
605
  }
617
606
  const data = await res.json();
618
- const lastConnectionAt = data.lastConnectionAt ? new Date(data.lastConnectionAt) : void 0;
619
- const createdAt = new Date(data.createdAt);
620
- return {
621
- ...data,
622
- createdAt,
623
- lastConnectionAt
624
- };
607
+ return inflateRoomData(data);
625
608
  }
626
609
  /**
627
610
  * Updates specific properties of a room. It’s not necessary to provide the entire room’s information.
@@ -650,13 +633,7 @@ var Liveblocks = class {
650
633
  throw await LiveblocksError.from(res);
651
634
  }
652
635
  const data = await res.json();
653
- const lastConnectionAt = data.lastConnectionAt ? new Date(data.lastConnectionAt) : void 0;
654
- const createdAt = new Date(data.createdAt);
655
- return {
656
- ...data,
657
- lastConnectionAt,
658
- createdAt
659
- };
636
+ return inflateRoomData(data);
660
637
  }
661
638
  /**
662
639
  * Deletes a room with the given id. A deleted room is no longer accessible from the API or the dashboard and it cannot be restored.
@@ -1078,7 +1055,7 @@ var Liveblocks = class {
1078
1055
  _core.url`/v2/rooms/${roomId}/threads/${threadId}/comments`,
1079
1056
  {
1080
1057
  ...data,
1081
- createdAt: _optionalChain([data, 'access', _9 => _9.createdAt, 'optionalAccess', _10 => _10.toISOString, 'call', _11 => _11()])
1058
+ createdAt: _optionalChain([data, 'access', _10 => _10.createdAt, 'optionalAccess', _11 => _11.toISOString, 'call', _12 => _12()])
1082
1059
  },
1083
1060
  options
1084
1061
  );
@@ -1101,7 +1078,7 @@ var Liveblocks = class {
1101
1078
  const { roomId, threadId, commentId, data } = params;
1102
1079
  const res = await this.#post(
1103
1080
  _core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}`,
1104
- { ...data, editedAt: _optionalChain([data, 'access', _12 => _12.editedAt, 'optionalAccess', _13 => _13.toISOString, 'call', _14 => _14()]) },
1081
+ { ...data, editedAt: _optionalChain([data, 'access', _13 => _13.editedAt, 'optionalAccess', _14 => _14.toISOString, 'call', _15 => _15()]) },
1105
1082
  options
1106
1083
  );
1107
1084
  if (!res.ok) {
@@ -1145,7 +1122,7 @@ var Liveblocks = class {
1145
1122
  ...data,
1146
1123
  comment: {
1147
1124
  ...data.comment,
1148
- createdAt: _optionalChain([data, 'access', _15 => _15.comment, 'access', _16 => _16.createdAt, 'optionalAccess', _17 => _17.toISOString, 'call', _18 => _18()])
1125
+ createdAt: _optionalChain([data, 'access', _16 => _16.comment, 'access', _17 => _17.createdAt, 'optionalAccess', _18 => _18.toISOString, 'call', _19 => _19()])
1149
1126
  }
1150
1127
  },
1151
1128
  options
@@ -1227,7 +1204,7 @@ var Liveblocks = class {
1227
1204
  _core.url`/v2/rooms/${roomId}/threads/${threadId}/metadata`,
1228
1205
  {
1229
1206
  ...data,
1230
- updatedAt: _optionalChain([data, 'access', _19 => _19.updatedAt, 'optionalAccess', _20 => _20.toISOString, 'call', _21 => _21()])
1207
+ updatedAt: _optionalChain([data, 'access', _20 => _20.updatedAt, 'optionalAccess', _21 => _21.toISOString, 'call', _22 => _22()])
1231
1208
  },
1232
1209
  options
1233
1210
  );
@@ -1253,7 +1230,7 @@ var Liveblocks = class {
1253
1230
  _core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}/add-reaction`,
1254
1231
  {
1255
1232
  ...data,
1256
- createdAt: _optionalChain([data, 'access', _22 => _22.createdAt, 'optionalAccess', _23 => _23.toISOString, 'call', _24 => _24()])
1233
+ createdAt: _optionalChain([data, 'access', _23 => _23.createdAt, 'optionalAccess', _24 => _24.toISOString, 'call', _25 => _25()])
1257
1234
  },
1258
1235
  options
1259
1236
  );
@@ -1279,7 +1256,7 @@ var Liveblocks = class {
1279
1256
  _core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${params.commentId}/remove-reaction`,
1280
1257
  {
1281
1258
  ...data,
1282
- removedAt: _optionalChain([data, 'access', _25 => _25.removedAt, 'optionalAccess', _26 => _26.toISOString, 'call', _27 => _27()])
1259
+ removedAt: _optionalChain([data, 'access', _26 => _26.removedAt, 'optionalAccess', _27 => _27.toISOString, 'call', _28 => _28()])
1283
1260
  },
1284
1261
  options
1285
1262
  );
@@ -1325,8 +1302,8 @@ var Liveblocks = class {
1325
1302
  _core.url`/v2/users/${userId}/inbox-notifications`,
1326
1303
  {
1327
1304
  query,
1328
- limit: _optionalChain([params, 'optionalAccess', _28 => _28.limit]),
1329
- startingAfter: _optionalChain([params, 'optionalAccess', _29 => _29.startingAfter])
1305
+ limit: _optionalChain([params, 'optionalAccess', _29 => _29.limit]),
1306
+ startingAfter: _optionalChain([params, 'optionalAccess', _30 => _30.startingAfter])
1330
1307
  },
1331
1308
  options
1332
1309
  );
@@ -1352,7 +1329,7 @@ var Liveblocks = class {
1352
1329
  */
1353
1330
  async *iterInboxNotifications(criteria, options) {
1354
1331
  const { signal } = _nullishCoalesce(options, () => ( {}));
1355
- const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess', _30 => _30.pageSize]), () => ( 50)), 10);
1332
+ const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess', _31 => _31.pageSize]), () => ( 50)), 10);
1356
1333
  let cursor = void 0;
1357
1334
  while (true) {
1358
1335
  const { nextCursor, data } = await this.getInboxNotifications(
@@ -1438,11 +1415,7 @@ var Liveblocks = class {
1438
1415
  throw await LiveblocksError.from(res);
1439
1416
  }
1440
1417
  const data = await res.json();
1441
- return {
1442
- ...data,
1443
- createdAt: new Date(data.createdAt),
1444
- lastConnectionAt: data.lastConnectionAt ? new Date(data.lastConnectionAt) : void 0
1445
- };
1418
+ return inflateRoomData(data);
1446
1419
  }
1447
1420
  async triggerInboxNotification(params, options) {
1448
1421
  const res = await this.#post(
@@ -1566,7 +1539,7 @@ var Liveblocks = class {
1566
1539
  async massMutateStorage(criteria, callback, massOptions) {
1567
1540
  const concurrency = _core.checkBounds.call(void 0,
1568
1541
  "concurrency",
1569
- _nullishCoalesce(_optionalChain([massOptions, 'optionalAccess', _31 => _31.concurrency]), () => ( 8)),
1542
+ _nullishCoalesce(_optionalChain([massOptions, 'optionalAccess', _32 => _32.concurrency]), () => ( 8)),
1570
1543
  1,
1571
1544
  20
1572
1545
  );
@@ -1582,7 +1555,7 @@ var Liveblocks = class {
1582
1555
  }
1583
1556
  async #_mutateOneRoom(roomId, room, callback, options) {
1584
1557
  const debounceInterval = 200;
1585
- const { signal, abort } = _core.makeAbortController.call(void 0, _optionalChain([options, 'optionalAccess', _32 => _32.signal]));
1558
+ const { signal, abort } = _core.makeAbortController.call(void 0, _optionalChain([options, 'optionalAccess', _33 => _33.signal]));
1586
1559
  let opsBuffer = [];
1587
1560
  let outstandingFlush$ = void 0;
1588
1561
  let lastFlush = performance.now();
@@ -1648,7 +1621,7 @@ var Liveblocks = class {
1648
1621
  const res = await this.#post(
1649
1622
  _core.url`/v2/rooms/${roomId}/send-message`,
1650
1623
  { messages },
1651
- { signal: _optionalChain([options, 'optionalAccess', _33 => _33.signal]) }
1624
+ { signal: _optionalChain([options, 'optionalAccess', _34 => _34.signal]) }
1652
1625
  );
1653
1626
  if (!res.ok) {
1654
1627
  throw await LiveblocksError.from(res);
@@ -1844,6 +1817,9 @@ function isCustomNotificationEvent(event) {
1844
1817
 
1845
1818
 
1846
1819
 
1820
+
1821
+
1822
+
1847
1823
  _core.detectDupes.call(void 0, PKG_NAME, PKG_VERSION, PKG_FORMAT);
1848
1824
 
1849
1825
 
@@ -1855,5 +1831,8 @@ _core.detectDupes.call(void 0, PKG_NAME, PKG_VERSION, PKG_FORMAT);
1855
1831
 
1856
1832
 
1857
1833
 
1858
- exports.Liveblocks = Liveblocks; exports.LiveblocksError = LiveblocksError; exports.WebhookHandler = WebhookHandler; exports.getMentionedIdsFromCommentBody = _core.getMentionedIdsFromCommentBody; exports.isCustomNotificationEvent = isCustomNotificationEvent; exports.isNotificationChannelEnabled = _core.isNotificationChannelEnabled; exports.isTextMentionNotificationEvent = isTextMentionNotificationEvent; exports.isThreadNotificationEvent = isThreadNotificationEvent; exports.stringifyCommentBody = _core.stringifyCommentBody;
1834
+
1835
+
1836
+
1837
+ exports.LiveList = _core.LiveList; exports.LiveMap = _core.LiveMap; exports.LiveObject = _core.LiveObject; exports.Liveblocks = Liveblocks; exports.LiveblocksError = LiveblocksError; exports.WebhookHandler = WebhookHandler; exports.getMentionedIdsFromCommentBody = _core.getMentionedIdsFromCommentBody; exports.isCustomNotificationEvent = isCustomNotificationEvent; exports.isNotificationChannelEnabled = _core.isNotificationChannelEnabled; exports.isTextMentionNotificationEvent = isTextMentionNotificationEvent; exports.isThreadNotificationEvent = isThreadNotificationEvent; exports.stringifyCommentBody = _core.stringifyCommentBody;
1859
1838
  //# sourceMappingURL=index.cjs.map