@liveblocks/node 3.23.0-file2 → 3.23.0-file4

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 = "3.23.0-file2";
6
+ var PKG_VERSION = "3.23.0-file4";
7
7
  var PKG_FORMAT = "cjs";
8
8
 
9
9
  // src/client.ts
@@ -326,10 +326,7 @@ async function uploadStorageFile({
326
326
  if (_optionalChain([signal, 'optionalAccess', _3 => _3.aborted])) {
327
327
  throw abortError;
328
328
  }
329
- if (err instanceof LiveblocksError && err.status === 413) {
330
- throw err;
331
- }
332
- return false;
329
+ return err instanceof LiveblocksError && err.status >= 400 && err.status < 500;
333
330
  };
334
331
  if (file.size <= STORAGE_FILE_PART_SIZE) {
335
332
  return _core.autoRetry.call(void 0,
@@ -347,41 +344,84 @@ async function uploadStorageFile({
347
344
  STORAGE_FILE_RETRY_DELAYS,
348
345
  handleRetryError
349
346
  );
347
+ const partUploadController = new AbortController();
348
+ const partUploadSignal = partUploadController.signal;
349
+ const abortPartUploads = (reason) => {
350
+ partUploadController.abort(reason);
351
+ };
352
+ const handleExternalAbort = () => abortPartUploads();
353
+ if (_optionalChain([signal, 'optionalAccess', _4 => _4.aborted])) {
354
+ handleExternalAbort();
355
+ } else {
356
+ _optionalChain([signal, 'optionalAccess', _5 => _5.addEventListener, 'call', _6 => _6("abort", handleExternalAbort, { once: true })]);
357
+ }
350
358
  try {
351
359
  uploadId = multipartUpload.uploadId;
352
- if (_optionalChain([signal, 'optionalAccess', _4 => _4.aborted])) {
360
+ if (_optionalChain([signal, 'optionalAccess', _7 => _7.aborted])) {
353
361
  throw abortError;
354
362
  }
355
363
  const batches = _core.chunk.call(void 0, splitStorageFileIntoParts(file), 5);
356
364
  for (const parts of batches) {
357
- const uploadedPartPromises = [];
365
+ const firstPartUploadFailure = {};
366
+ const partUploads$ = [];
358
367
  for (const { part, partNumber } of parts) {
359
- uploadedPartPromises.push(
368
+ partUploads$.push(
360
369
  _core.autoRetry.call(void 0,
361
- () => uploadMultipartPart(multipartUpload.uploadId, partNumber, part),
370
+ () => uploadMultipartPart(
371
+ multipartUpload.uploadId,
372
+ partNumber,
373
+ part,
374
+ partUploadSignal
375
+ ),
362
376
  STORAGE_FILE_RETRY_ATTEMPTS,
363
377
  STORAGE_FILE_RETRY_DELAYS,
364
- handleRetryError
365
- )
378
+ (error) => {
379
+ if (_optionalChain([signal, 'optionalAccess', _8 => _8.aborted])) {
380
+ throw abortError;
381
+ }
382
+ return partUploadSignal.aborted || handleRetryError(error);
383
+ }
384
+ ).catch((error) => {
385
+ if (firstPartUploadFailure.value === void 0) {
386
+ firstPartUploadFailure.value = { error };
387
+ abortPartUploads(error);
388
+ }
389
+ throw error;
390
+ })
366
391
  );
367
392
  }
368
- uploadedParts.push(...await Promise.all(uploadedPartPromises));
393
+ const settledPartUploads = await Promise.allSettled(partUploads$);
394
+ if (firstPartUploadFailure.value !== void 0) {
395
+ throw firstPartUploadFailure.value.error;
396
+ }
397
+ for (const settledPartUpload of settledPartUploads) {
398
+ if (settledPartUpload.status === "fulfilled") {
399
+ uploadedParts.push(settledPartUpload.value);
400
+ }
401
+ }
369
402
  }
370
- if (_optionalChain([signal, 'optionalAccess', _5 => _5.aborted])) {
403
+ if (_optionalChain([signal, 'optionalAccess', _9 => _9.aborted])) {
371
404
  throw abortError;
372
405
  }
373
- return completeMultipartUpload(
374
- multipartUpload.uploadId,
375
- uploadedParts.sort((a, b) => a.partNumber - b.partNumber)
406
+ const sortedParts = uploadedParts.sort(
407
+ (a, b) => a.partNumber - b.partNumber
408
+ );
409
+ return _core.autoRetry.call(void 0,
410
+ () => completeMultipartUpload(multipartUpload.uploadId, sortedParts),
411
+ STORAGE_FILE_RETRY_ATTEMPTS,
412
+ STORAGE_FILE_RETRY_DELAYS,
413
+ handleRetryError
376
414
  );
377
415
  } catch (err) {
378
- if (uploadId && isAbortOrTimeoutError(err)) {
416
+ if (uploadId) {
379
417
  try {
380
418
  await abortMultipartUpload(uploadId);
381
419
  } catch (e2) {
382
420
  }
383
421
  }
384
422
  throw err;
423
+ } finally {
424
+ _optionalChain([signal, 'optionalAccess', _10 => _10.removeEventListener, 'call', _11 => _11("abort", handleExternalAbort)]);
385
425
  }
386
426
  }
387
427
  function splitStorageFileIntoParts(file) {
@@ -397,9 +437,6 @@ function splitStorageFileIntoParts(file) {
397
437
  }
398
438
  return parts;
399
439
  }
400
- function isAbortOrTimeoutError(err) {
401
- return err instanceof Error && (err.name === "AbortError" || err.name === "TimeoutError");
402
- }
403
440
  function createAbortError(message) {
404
441
  if (typeof DOMException === "function") {
405
442
  return new DOMException(message, "AbortError");
@@ -489,7 +526,7 @@ var Liveblocks = class {
489
526
  method: "POST",
490
527
  headers,
491
528
  body: JSON.stringify(json),
492
- signal: _optionalChain([options, 'optionalAccess', _6 => _6.signal])
529
+ signal: _optionalChain([options, 'optionalAccess', _12 => _12.signal])
493
530
  });
494
531
  xwarn(res, "POST", path);
495
532
  return res;
@@ -511,7 +548,7 @@ var Liveblocks = class {
511
548
  method: "PATCH",
512
549
  headers,
513
550
  body: JSON.stringify(json),
514
- signal: _optionalChain([options, 'optionalAccess', _7 => _7.signal])
551
+ signal: _optionalChain([options, 'optionalAccess', _13 => _13.signal])
515
552
  });
516
553
  xwarn(res, "PATCH", path);
517
554
  return res;
@@ -527,7 +564,7 @@ var Liveblocks = class {
527
564
  method: "PUT",
528
565
  headers,
529
566
  body,
530
- signal: _optionalChain([options, 'optionalAccess', _8 => _8.signal])
567
+ signal: _optionalChain([options, 'optionalAccess', _14 => _14.signal])
531
568
  });
532
569
  xwarn(res, "PUT", path);
533
570
  return res;
@@ -543,7 +580,7 @@ var Liveblocks = class {
543
580
  method: "PUT",
544
581
  headers,
545
582
  body,
546
- signal: _optionalChain([options, 'optionalAccess', _9 => _9.signal])
583
+ signal: _optionalChain([options, 'optionalAccess', _15 => _15.signal])
547
584
  });
548
585
  xwarn(res, "PUT", path);
549
586
  return res;
@@ -557,7 +594,7 @@ var Liveblocks = class {
557
594
  const res = await fetch(url3, {
558
595
  method: "DELETE",
559
596
  headers,
560
- signal: _optionalChain([options, 'optionalAccess', _10 => _10.signal])
597
+ signal: _optionalChain([options, 'optionalAccess', _16 => _16.signal])
561
598
  });
562
599
  xwarn(res, "DELETE", path);
563
600
  return res;
@@ -571,7 +608,7 @@ var Liveblocks = class {
571
608
  const res = await fetch(url3, {
572
609
  method: "GET",
573
610
  headers,
574
- signal: _optionalChain([options, 'optionalAccess', _11 => _11.signal])
611
+ signal: _optionalChain([options, 'optionalAccess', _17 => _17.signal])
575
612
  });
576
613
  xwarn(res, "GET", path);
577
614
  return res;
@@ -602,8 +639,8 @@ var Liveblocks = class {
602
639
  return new Session(
603
640
  this.#post.bind(this),
604
641
  userId,
605
- _optionalChain([options, 'optionalAccess', _12 => _12.userInfo]),
606
- _nullishCoalesce(_optionalChain([options, 'optionalAccess', _13 => _13.organizationId]), () => ( _optionalChain([options, 'optionalAccess', _14 => _14.tenantId]))),
642
+ _optionalChain([options, 'optionalAccess', _18 => _18.userInfo]),
643
+ _nullishCoalesce(_optionalChain([options, 'optionalAccess', _19 => _19.organizationId]), () => ( _optionalChain([options, 'optionalAccess', _20 => _20.tenantId]))),
607
644
  this.#localDev
608
645
  );
609
646
  }
@@ -653,7 +690,7 @@ var Liveblocks = class {
653
690
  const body = {
654
691
  userId,
655
692
  groupIds,
656
- userInfo: _optionalChain([options, 'optionalAccess', _15 => _15.userInfo])
693
+ userInfo: _optionalChain([options, 'optionalAccess', _21 => _21.userInfo])
657
694
  };
658
695
  if (organizationId !== void 0) {
659
696
  body.organizationId = organizationId;
@@ -739,7 +776,7 @@ var Liveblocks = class {
739
776
  */
740
777
  async *iterRooms(criteria, options) {
741
778
  const { signal } = _nullishCoalesce(options, () => ( {}));
742
- const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess', _16 => _16.pageSize]), () => ( 40)), 20);
779
+ const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess', _22 => _22.pageSize]), () => ( 40)), 20);
743
780
  let cursor = void 0;
744
781
  while (true) {
745
782
  const { nextCursor, data } = await this.getRooms(
@@ -789,7 +826,7 @@ var Liveblocks = class {
789
826
  body.organizationId = tenantId;
790
827
  }
791
828
  const res = await this.#post(
792
- _optionalChain([options, 'optionalAccess', _17 => _17.idempotent]) ? _core.url`/v2/rooms?idempotent` : _core.url`/v2/rooms`,
829
+ _optionalChain([options, 'optionalAccess', _23 => _23.idempotent]) ? _core.url`/v2/rooms?idempotent` : _core.url`/v2/rooms`,
793
830
  body,
794
831
  options
795
832
  );
@@ -1325,7 +1362,7 @@ var Liveblocks = class {
1325
1362
  _core.url`/v2/rooms/${roomId}/threads/${threadId}/comments`,
1326
1363
  {
1327
1364
  ...data,
1328
- createdAt: _optionalChain([data, 'access', _18 => _18.createdAt, 'optionalAccess', _19 => _19.toISOString, 'call', _20 => _20()])
1365
+ createdAt: _optionalChain([data, 'access', _24 => _24.createdAt, 'optionalAccess', _25 => _25.toISOString, 'call', _26 => _26()])
1329
1366
  },
1330
1367
  options
1331
1368
  );
@@ -1351,7 +1388,7 @@ var Liveblocks = class {
1351
1388
  _core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}`,
1352
1389
  {
1353
1390
  body: data.body,
1354
- editedAt: _optionalChain([data, 'access', _21 => _21.editedAt, 'optionalAccess', _22 => _22.toISOString, 'call', _23 => _23()]),
1391
+ editedAt: _optionalChain([data, 'access', _27 => _27.editedAt, 'optionalAccess', _28 => _28.toISOString, 'call', _29 => _29()]),
1355
1392
  metadata: data.metadata
1356
1393
  },
1357
1394
  options
@@ -1404,7 +1441,7 @@ var Liveblocks = class {
1404
1441
  const fileId = _core.createStorageFileId.call(void 0, );
1405
1442
  const fileData = await uploadStorageFile({
1406
1443
  file,
1407
- signal: _optionalChain([options, 'optionalAccess', _24 => _24.signal]),
1444
+ signal: _optionalChain([options, 'optionalAccess', _30 => _30.signal]),
1408
1445
  abortErrorMessage: `Upload of file ${fileId} was aborted.`,
1409
1446
  uploadSingle: async () => {
1410
1447
  const res = await this.#putBlob(
@@ -1424,12 +1461,12 @@ var Liveblocks = class {
1424
1461
  );
1425
1462
  return await this.#readJsonResponse(res);
1426
1463
  },
1427
- uploadMultipartPart: async (uploadId, partNumber, part) => {
1464
+ uploadMultipartPart: async (uploadId, partNumber, part, signal) => {
1428
1465
  const res = await this.#putBlob(
1429
1466
  _core.url`/v2/rooms/${roomId}/storage/files/${fileId}/multipart/${uploadId}/${String(partNumber)}`,
1430
1467
  part,
1431
1468
  void 0,
1432
- options
1469
+ { signal }
1433
1470
  );
1434
1471
  return await this.#readJsonResponse(res);
1435
1472
  },
@@ -1486,7 +1523,7 @@ var Liveblocks = class {
1486
1523
  ...data,
1487
1524
  comment: {
1488
1525
  ...data.comment,
1489
- createdAt: _optionalChain([data, 'access', _25 => _25.comment, 'access', _26 => _26.createdAt, 'optionalAccess', _27 => _27.toISOString, 'call', _28 => _28()])
1526
+ createdAt: _optionalChain([data, 'access', _31 => _31.comment, 'access', _32 => _32.createdAt, 'optionalAccess', _33 => _33.toISOString, 'call', _34 => _34()])
1490
1527
  }
1491
1528
  },
1492
1529
  options
@@ -1609,7 +1646,7 @@ var Liveblocks = class {
1609
1646
  _core.url`/v2/rooms/${roomId}/threads/${threadId}/metadata`,
1610
1647
  {
1611
1648
  ...data,
1612
- updatedAt: _optionalChain([data, 'access', _29 => _29.updatedAt, 'optionalAccess', _30 => _30.toISOString, 'call', _31 => _31()])
1649
+ updatedAt: _optionalChain([data, 'access', _35 => _35.updatedAt, 'optionalAccess', _36 => _36.toISOString, 'call', _37 => _37()])
1613
1650
  },
1614
1651
  options
1615
1652
  );
@@ -1635,7 +1672,7 @@ var Liveblocks = class {
1635
1672
  _core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}/metadata`,
1636
1673
  {
1637
1674
  ...data,
1638
- updatedAt: _optionalChain([data, 'access', _32 => _32.updatedAt, 'optionalAccess', _33 => _33.toISOString, 'call', _34 => _34()])
1675
+ updatedAt: _optionalChain([data, 'access', _38 => _38.updatedAt, 'optionalAccess', _39 => _39.toISOString, 'call', _40 => _40()])
1639
1676
  },
1640
1677
  options
1641
1678
  );
@@ -1661,7 +1698,7 @@ var Liveblocks = class {
1661
1698
  _core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}/add-reaction`,
1662
1699
  {
1663
1700
  ...data,
1664
- createdAt: _optionalChain([data, 'access', _35 => _35.createdAt, 'optionalAccess', _36 => _36.toISOString, 'call', _37 => _37()])
1701
+ createdAt: _optionalChain([data, 'access', _41 => _41.createdAt, 'optionalAccess', _42 => _42.toISOString, 'call', _43 => _43()])
1665
1702
  },
1666
1703
  options
1667
1704
  );
@@ -1687,7 +1724,7 @@ var Liveblocks = class {
1687
1724
  _core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${params.commentId}/remove-reaction`,
1688
1725
  {
1689
1726
  ...data,
1690
- removedAt: _optionalChain([data, 'access', _38 => _38.removedAt, 'optionalAccess', _39 => _39.toISOString, 'call', _40 => _40()])
1727
+ removedAt: _optionalChain([data, 'access', _44 => _44.removedAt, 'optionalAccess', _45 => _45.toISOString, 'call', _46 => _46()])
1691
1728
  },
1692
1729
  options
1693
1730
  );
@@ -1768,7 +1805,7 @@ var Liveblocks = class {
1768
1805
  */
1769
1806
  async *iterInboxNotifications(criteria, options) {
1770
1807
  const { signal } = _nullishCoalesce(options, () => ( {}));
1771
- const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess', _41 => _41.pageSize]), () => ( 50)), 10);
1808
+ const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess', _47 => _47.pageSize]), () => ( 50)), 10);
1772
1809
  let cursor = void 0;
1773
1810
  while (true) {
1774
1811
  const { nextCursor, data } = await this.getInboxNotifications(
@@ -2115,7 +2152,7 @@ var Liveblocks = class {
2115
2152
  async getGroups(params, options) {
2116
2153
  const res = await this.#get(
2117
2154
  _core.url`/v2/groups`,
2118
- { startingAfter: _optionalChain([params, 'optionalAccess', _42 => _42.startingAfter]), limit: _optionalChain([params, 'optionalAccess', _43 => _43.limit]) },
2155
+ { startingAfter: _optionalChain([params, 'optionalAccess', _48 => _48.startingAfter]), limit: _optionalChain([params, 'optionalAccess', _49 => _49.limit]) },
2119
2156
  options
2120
2157
  );
2121
2158
  if (!res.ok) {
@@ -2177,7 +2214,7 @@ var Liveblocks = class {
2177
2214
  async massMutateStorage(criteria, callback, massOptions) {
2178
2215
  const concurrency = _core.checkBounds.call(void 0,
2179
2216
  "concurrency",
2180
- _nullishCoalesce(_optionalChain([massOptions, 'optionalAccess', _44 => _44.concurrency]), () => ( 8)),
2217
+ _nullishCoalesce(_optionalChain([massOptions, 'optionalAccess', _50 => _50.concurrency]), () => ( 8)),
2181
2218
  1,
2182
2219
  20
2183
2220
  );
@@ -2193,7 +2230,7 @@ var Liveblocks = class {
2193
2230
  }
2194
2231
  async #_mutateOneRoom(roomId, room, callback, options) {
2195
2232
  const debounceInterval = 200;
2196
- const { signal, abort } = _core.makeAbortController.call(void 0, _optionalChain([options, 'optionalAccess', _45 => _45.signal]));
2233
+ const { signal, abort } = _core.makeAbortController.call(void 0, _optionalChain([options, 'optionalAccess', _51 => _51.signal]));
2197
2234
  let opsBuffer = [];
2198
2235
  let outstandingFlush$ = void 0;
2199
2236
  let lastFlush = performance.now();
@@ -2259,7 +2296,7 @@ var Liveblocks = class {
2259
2296
  const res = await this.#post(
2260
2297
  _core.url`/v2/rooms/${roomId}/send-message`,
2261
2298
  { messages },
2262
- { signal: _optionalChain([options, 'optionalAccess', _46 => _46.signal]) }
2299
+ { signal: _optionalChain([options, 'optionalAccess', _52 => _52.signal]) }
2263
2300
  );
2264
2301
  if (!res.ok) {
2265
2302
  throw await LiveblocksError.from(res);
@@ -2396,7 +2433,7 @@ var Liveblocks = class {
2396
2433
  "Content-Type": params.file.type,
2397
2434
  "Content-Length": String(params.file.size)
2398
2435
  },
2399
- signal: _optionalChain([options, 'optionalAccess', _47 => _47.signal])
2436
+ signal: _optionalChain([options, 'optionalAccess', _53 => _53.signal])
2400
2437
  }
2401
2438
  );
2402
2439
  if (!res.ok) {
@@ -2772,7 +2809,7 @@ var WHITESPACE_REGEX = /\s/;
2772
2809
  var MarkedCustomTokenizer = class extends _marked.Tokenizer {
2773
2810
  url(src) {
2774
2811
  const token = super.url(src);
2775
- if (_optionalChain([token, 'optionalAccess', _48 => _48.href, 'access', _49 => _49.startsWith, 'call', _50 => _50("mailto:")])) {
2812
+ if (_optionalChain([token, 'optionalAccess', _54 => _54.href, 'access', _55 => _55.startsWith, 'call', _56 => _56("mailto:")])) {
2776
2813
  return void 0;
2777
2814
  }
2778
2815
  return token;
@@ -2952,7 +2989,7 @@ function tokensToCommentBodyInlines(tokens, formatting = {}) {
2952
2989
  case "escape":
2953
2990
  case "html":
2954
2991
  case "text": {
2955
- if (token.type === "text" && _optionalChain([token, 'access', _51 => _51.tokens, 'optionalAccess', _52 => _52.length])) {
2992
+ if (token.type === "text" && _optionalChain([token, 'access', _57 => _57.tokens, 'optionalAccess', _58 => _58.length])) {
2956
2993
  appendFormattedInlinesFromTokens(inlines, token.tokens, formatting);
2957
2994
  } else {
2958
2995
  appendTextWithMentions(inlines, token.text, formatting);