@liveblocks/core 2.17.0-channels1 → 2.17.0-usrnotsettings1

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
@@ -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.17.0-channels1";
9
+ var PKG_VERSION = "2.17.0-usrnotsettings1";
10
10
  var PKG_FORMAT = "cjs";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -166,6 +166,14 @@ function wrapWithTitle(method) {
166
166
  var warnWithTitle = wrapWithTitle("warn");
167
167
  var errorWithTitle = wrapWithTitle("error");
168
168
 
169
+ // src/lib/guards.ts
170
+ function isPlainObject(blob) {
171
+ return blob !== null && typeof blob === "object" && Object.prototype.toString.call(blob) === "[object Object]";
172
+ }
173
+ function isStartsWithOperator(blob) {
174
+ return isPlainObject(blob) && typeof blob.startsWith === "string";
175
+ }
176
+
169
177
  // src/lib/utils.ts
170
178
  function raise(msg) {
171
179
  throw new Error(msg);
@@ -257,13 +265,48 @@ function memoizeOnSuccess(factoryFn) {
257
265
  }
258
266
 
259
267
  // src/lib/autoRetry.ts
260
- var HttpError = class extends Error {
261
- constructor(message, status, details) {
268
+ var HttpError = class _HttpError extends Error {
269
+
270
+
271
+ constructor(message, response, details) {
262
272
  super(message);
263
- this.message = message;
264
- this.status = status;
273
+ this.name = "HttpError";
274
+ this.response = response;
265
275
  this.details = details;
266
276
  }
277
+ static async fromResponse(response) {
278
+ let bodyAsText;
279
+ try {
280
+ bodyAsText = await response.text();
281
+ } catch (e2) {
282
+ }
283
+ const bodyAsJson = bodyAsText ? tryParseJson(bodyAsText) : void 0;
284
+ let bodyAsJsonObject;
285
+ if (isPlainObject(bodyAsJson)) {
286
+ bodyAsJsonObject = bodyAsJson;
287
+ }
288
+ let message = "";
289
+ message ||= typeof _optionalChain([bodyAsJsonObject, 'optionalAccess', _2 => _2.message]) === "string" ? bodyAsJsonObject.message : "";
290
+ message ||= typeof _optionalChain([bodyAsJsonObject, 'optionalAccess', _3 => _3.error]) === "string" ? bodyAsJsonObject.error : "";
291
+ if (bodyAsJson === void 0) {
292
+ message ||= bodyAsText || "";
293
+ }
294
+ message ||= response.statusText;
295
+ let path;
296
+ try {
297
+ path = new URL(response.url).pathname;
298
+ } catch (e3) {
299
+ }
300
+ message += path !== void 0 ? ` (got status ${response.status} from ${path})` : ` (got status ${response.status})`;
301
+ const details = bodyAsJsonObject;
302
+ return new _HttpError(message, response, details);
303
+ }
304
+ /**
305
+ * Convenience accessor for response.status.
306
+ */
307
+ get status() {
308
+ return this.response.status;
309
+ }
267
310
  };
268
311
  var DONT_RETRY_4XX = (x) => x instanceof HttpError && x.status >= 400 && x.status < 500;
269
312
  async function autoRetry(promiseFn, maxTries, backoff, shouldStopRetrying = DONT_RETRY_4XX) {
@@ -326,10 +369,15 @@ function makeEventSource() {
326
369
  res(event);
327
370
  }
328
371
  });
329
- }).finally(() => _optionalChain([unsub, 'optionalCall', _2 => _2()]));
372
+ }).finally(() => _optionalChain([unsub, 'optionalCall', _4 => _4()]));
330
373
  }
331
374
  function notify(event) {
332
- _observers.forEach((callback) => callback(event));
375
+ let called = false;
376
+ for (const callback of _observers) {
377
+ callback(event);
378
+ called = true;
379
+ }
380
+ return called;
333
381
  }
334
382
  function count() {
335
383
  return _observers.size;
@@ -370,8 +418,9 @@ function makeBufferableEventSource() {
370
418
  function notifyOrBuffer(event) {
371
419
  if (_buffer !== null) {
372
420
  _buffer.push(event);
421
+ return false;
373
422
  } else {
374
- eventSource2.notify(event);
423
+ return eventSource2.notify(event);
375
424
  }
376
425
  }
377
426
  return {
@@ -511,7 +560,7 @@ var Signal = class extends AbstractSignal {
511
560
  this.#value = "(disposed)";
512
561
  }
513
562
  get() {
514
- _optionalChain([trackedReads, 'optionalAccess', _3 => _3.add, 'call', _4 => _4(this)]);
563
+ _optionalChain([trackedReads, 'optionalAccess', _5 => _5.add, 'call', _6 => _6(this)]);
515
564
  return this.#value;
516
565
  }
517
566
  set(newValue) {
@@ -621,7 +670,7 @@ var DerivedSignal = class _DerivedSignal extends AbstractSignal {
621
670
  if (this.#dirty) {
622
671
  this.#recompute();
623
672
  }
624
- _optionalChain([trackedReads, 'optionalAccess', _5 => _5.add, 'call', _6 => _6(this)]);
673
+ _optionalChain([trackedReads, 'optionalAccess', _7 => _7.add, 'call', _8 => _8(this)]);
625
674
  return this.#prevValue;
626
675
  }
627
676
  /**
@@ -651,7 +700,7 @@ var MutableSignal = class extends AbstractSignal {
651
700
  this.#state = "(disposed)";
652
701
  }
653
702
  get() {
654
- _optionalChain([trackedReads, 'optionalAccess', _7 => _7.add, 'call', _8 => _8(this)]);
703
+ _optionalChain([trackedReads, 'optionalAccess', _9 => _9.add, 'call', _10 => _10(this)]);
655
704
  return this.#state;
656
705
  }
657
706
  /**
@@ -676,32 +725,15 @@ var MutableSignal = class extends AbstractSignal {
676
725
  };
677
726
 
678
727
  // src/lib/stringify.ts
679
- var EXPLICIT_UNDEFINED_PLACEHOLDER = "_explicit_undefined";
680
728
  function replacer(_key, value) {
681
729
  return value !== null && typeof value === "object" && !Array.isArray(value) ? Object.keys(value).sort().reduce((sorted, key) => {
682
730
  sorted[key] = value[key];
683
731
  return sorted;
684
- }, {}) : value === void 0 ? EXPLICIT_UNDEFINED_PLACEHOLDER : value;
685
- }
686
- function reviver(key, value) {
687
- if (!key && value === EXPLICIT_UNDEFINED_PLACEHOLDER) {
688
- return void 0;
689
- }
690
- if (value && typeof value === "object") {
691
- for (const k in value) {
692
- if (value[k] === EXPLICIT_UNDEFINED_PLACEHOLDER) {
693
- Object.defineProperty(value, k, { value: void 0 });
694
- }
695
- }
696
- }
697
- return value;
732
+ }, {}) : value;
698
733
  }
699
734
  function stringify(value) {
700
735
  return JSON.stringify(value, replacer);
701
736
  }
702
- function unstringify(value) {
703
- return JSON.parse(value, reviver);
704
- }
705
737
 
706
738
  // src/lib/batch.ts
707
739
  var DEFAULT_SIZE = 50;
@@ -754,7 +786,7 @@ var Batch = (_class = class {
754
786
  const results = await this.#callback(inputs);
755
787
  this.error = false;
756
788
  calls.forEach((call, index) => {
757
- const result = _optionalChain([results, 'optionalAccess', _9 => _9[index]]);
789
+ const result = _optionalChain([results, 'optionalAccess', _11 => _11[index]]);
758
790
  if (!Array.isArray(results)) {
759
791
  call.reject(new Error("Callback must return an array."));
760
792
  } else if (calls.length !== results.length) {
@@ -917,14 +949,6 @@ var DefaultMap = class extends Map {
917
949
  }
918
950
  };
919
951
 
920
- // src/lib/guards.ts
921
- function isPlainObject(blob) {
922
- return blob !== null && typeof blob === "object" && Object.prototype.toString.call(blob) === "[object Object]";
923
- }
924
- function isStartsWithOperator(blob) {
925
- return isPlainObject(blob) && typeof blob.startsWith === "string";
926
- }
927
-
928
952
  // src/lib/objectToQuery.ts
929
953
  var identifierRegex = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
930
954
  function objectToQuery(obj) {
@@ -974,9 +998,7 @@ function objectToQuery(obj) {
974
998
  ...getFiltersFromKeyValuePairsWithOperator(nKeyValuePairsWithOperator)
975
999
  ];
976
1000
  });
977
- return filterList.map(
978
- ({ key, operator, value }) => formatFilter(key, operator, formatFilterValue(value))
979
- ).join(" AND ");
1001
+ return filterList.map(({ key, operator, value }) => `${key}${operator}${quote(value)}`).join(" ");
980
1002
  }
981
1003
  var getFiltersFromKeyValuePairs = (keyValuePairs) => {
982
1004
  const filters = [];
@@ -1003,29 +1025,27 @@ var getFiltersFromKeyValuePairsWithOperator = (keyValuePairsWithOperator) => {
1003
1025
  return filters;
1004
1026
  };
1005
1027
  var isSimpleValue = (value) => {
1006
- return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
1007
- };
1008
- var formatFilter = (key, operator, value) => {
1009
- return `${key}${operator}${value}`;
1028
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null;
1010
1029
  };
1011
1030
  var formatFilterKey = (key, nestedKey) => {
1012
1031
  if (nestedKey) {
1013
- return `${key}[${JSON.stringify(nestedKey)}]`;
1032
+ return `${key}[${quote(nestedKey)}]`;
1014
1033
  }
1015
1034
  return key;
1016
1035
  };
1017
- var formatFilterValue = (value) => {
1018
- if (typeof value === "string") {
1019
- if (isStringEmpty(value)) {
1020
- throw new Error("Value cannot be empty");
1021
- }
1022
- return JSON.stringify(value);
1023
- }
1024
- return value.toString();
1025
- };
1026
1036
  var isStringEmpty = (value) => {
1027
1037
  return !value || value.toString().trim() === "";
1028
1038
  };
1039
+ function quote(input) {
1040
+ const result = JSON.stringify(input);
1041
+ if (typeof input !== "string") {
1042
+ return result;
1043
+ }
1044
+ if (result.includes("'")) {
1045
+ return result;
1046
+ }
1047
+ return `'${result.slice(1, -1).replace(/\\"/g, '"')}'`;
1048
+ }
1029
1049
 
1030
1050
  // src/lib/url.ts
1031
1051
  function toURLSearchParams(params) {
@@ -1283,11 +1303,11 @@ function createApiClient({
1283
1303
  `Upload of attachment ${options.attachment.id} was aborted.`,
1284
1304
  "AbortError"
1285
1305
  ) : void 0;
1286
- if (_optionalChain([abortSignal, 'optionalAccess', _10 => _10.aborted])) {
1306
+ if (_optionalChain([abortSignal, 'optionalAccess', _12 => _12.aborted])) {
1287
1307
  throw abortError;
1288
1308
  }
1289
1309
  const handleRetryError = (err) => {
1290
- if (_optionalChain([abortSignal, 'optionalAccess', _11 => _11.aborted])) {
1310
+ if (_optionalChain([abortSignal, 'optionalAccess', _13 => _13.aborted])) {
1291
1311
  throw abortError;
1292
1312
  }
1293
1313
  if (err instanceof HttpError && err.status === 413) {
@@ -1359,7 +1379,7 @@ function createApiClient({
1359
1379
  try {
1360
1380
  uploadId = createMultiPartUpload.uploadId;
1361
1381
  const parts = splitFileIntoParts(attachment.file);
1362
- if (_optionalChain([abortSignal, 'optionalAccess', _12 => _12.aborted])) {
1382
+ if (_optionalChain([abortSignal, 'optionalAccess', _14 => _14.aborted])) {
1363
1383
  throw abortError;
1364
1384
  }
1365
1385
  const batches = chunk(parts, 5);
@@ -1386,7 +1406,7 @@ function createApiClient({
1386
1406
  }
1387
1407
  uploadedParts.push(...await Promise.all(uploadedPartsPromises));
1388
1408
  }
1389
- if (_optionalChain([abortSignal, 'optionalAccess', _13 => _13.aborted])) {
1409
+ if (_optionalChain([abortSignal, 'optionalAccess', _15 => _15.aborted])) {
1390
1410
  throw abortError;
1391
1411
  }
1392
1412
  const sortedUploadedParts = uploadedParts.sort(
@@ -1402,7 +1422,7 @@ function createApiClient({
1402
1422
  { signal: abortSignal }
1403
1423
  );
1404
1424
  } catch (error3) {
1405
- if (uploadId && _optionalChain([error3, 'optionalAccess', _14 => _14.name]) && (error3.name === "AbortError" || error3.name === "TimeoutError")) {
1425
+ if (uploadId && _optionalChain([error3, 'optionalAccess', _16 => _16.name]) && (error3.name === "AbortError" || error3.name === "TimeoutError")) {
1406
1426
  try {
1407
1427
  await httpClient.rawDelete(
1408
1428
  url`/v2/c/rooms/${roomId}/attachments/${attachment.id}/multipart/${uploadId}`,
@@ -1609,7 +1629,7 @@ function createApiClient({
1609
1629
  url`/v2/c/inbox-notifications`,
1610
1630
  await authManager.getAuthValue({ requestedScope: "comments:read" }),
1611
1631
  {
1612
- cursor: _optionalChain([options, 'optionalAccess', _15 => _15.cursor]),
1632
+ cursor: _optionalChain([options, 'optionalAccess', _17 => _17.cursor]),
1613
1633
  limit: PAGE_SIZE
1614
1634
  }
1615
1635
  );
@@ -1691,24 +1711,24 @@ function createApiClient({
1691
1711
  await authManager.getAuthValue({ requestedScope: "comments:read" })
1692
1712
  );
1693
1713
  }
1694
- async function getChannelsNotificationSettings(options) {
1714
+ async function getUserNotificationSettings(options) {
1695
1715
  return httpClient.get(
1696
- url`/v2/c/channels-notification-settings`,
1716
+ url`/v2/c/notification-settings`,
1697
1717
  await authManager.getAuthValue({ requestedScope: "comments:read" }),
1698
1718
  void 0,
1699
- { signal: _optionalChain([options, 'optionalAccess', _16 => _16.signal]) }
1719
+ { signal: _optionalChain([options, 'optionalAccess', _18 => _18.signal]) }
1700
1720
  );
1701
1721
  }
1702
- async function updateChannelsNotificationSettings(settings) {
1722
+ async function updateUserNotificationSettings(settings) {
1703
1723
  return httpClient.post(
1704
- url`/v2/c/channels-notification-settings`,
1724
+ url`/v2/c/notification-settings`,
1705
1725
  await authManager.getAuthValue({ requestedScope: "comments:read" }),
1706
1726
  settings
1707
1727
  );
1708
1728
  }
1709
1729
  async function getUserThreads_experimental(options) {
1710
1730
  let query;
1711
- if (_optionalChain([options, 'optionalAccess', _17 => _17.query])) {
1731
+ if (_optionalChain([options, 'optionalAccess', _19 => _19.query])) {
1712
1732
  query = objectToQuery(options.query);
1713
1733
  }
1714
1734
  const PAGE_SIZE = 50;
@@ -1716,7 +1736,7 @@ function createApiClient({
1716
1736
  url`/v2/c/threads`,
1717
1737
  await authManager.getAuthValue({ requestedScope: "comments:read" }),
1718
1738
  {
1719
- cursor: _optionalChain([options, 'optionalAccess', _18 => _18.cursor]),
1739
+ cursor: _optionalChain([options, 'optionalAccess', _20 => _20.cursor]),
1720
1740
  query,
1721
1741
  limit: PAGE_SIZE
1722
1742
  }
@@ -1768,12 +1788,10 @@ function createApiClient({
1768
1788
  removeReaction,
1769
1789
  markThreadAsResolved,
1770
1790
  markThreadAsUnresolved,
1771
- // Room notifications
1772
1791
  markRoomInboxNotificationAsRead,
1773
- updateNotificationSettings,
1774
- // Channel notification settings
1792
+ // Room notifications
1775
1793
  getNotificationSettings,
1776
- updateChannelsNotificationSettings,
1794
+ updateNotificationSettings,
1777
1795
  // Room text editor
1778
1796
  createTextMention,
1779
1797
  deleteTextMention,
@@ -1797,7 +1815,8 @@ function createApiClient({
1797
1815
  markInboxNotificationAsRead,
1798
1816
  deleteAllInboxNotifications,
1799
1817
  deleteInboxNotification,
1800
- getChannelsNotificationSettings,
1818
+ getUserNotificationSettings,
1819
+ updateUserNotificationSettings,
1801
1820
  // User threads
1802
1821
  getUserThreads_experimental,
1803
1822
  getUserThreadsSince_experimental
@@ -1844,7 +1863,7 @@ var HttpClient = class {
1844
1863
  // These headers are default, but can be overriden by custom headers
1845
1864
  "Content-Type": "application/json; charset=utf-8",
1846
1865
  // Possible header overrides
1847
- ..._optionalChain([options, 'optionalAccess', _19 => _19.headers]),
1866
+ ..._optionalChain([options, 'optionalAccess', _21 => _21.headers]),
1848
1867
  // Cannot be overriden by custom headers
1849
1868
  Authorization: `Bearer ${getBearerTokenFromAuthValue(authValue)}`,
1850
1869
  "X-LB-Client": PKG_VERSION || "dev"
@@ -1868,19 +1887,12 @@ var HttpClient = class {
1868
1887
  async #fetch(endpoint, authValue, options, params) {
1869
1888
  const response = await this.#rawFetch(endpoint, authValue, options, params);
1870
1889
  if (!response.ok) {
1871
- let error3;
1872
- try {
1873
- const errorBody = await response.json();
1874
- error3 = new HttpError(errorBody.message, response.status, errorBody);
1875
- } catch (e2) {
1876
- error3 = new HttpError(response.statusText, response.status);
1877
- }
1878
- throw error3;
1890
+ throw await HttpError.fromResponse(response);
1879
1891
  }
1880
1892
  let body;
1881
1893
  try {
1882
1894
  body = await response.json();
1883
- } catch (e3) {
1895
+ } catch (e4) {
1884
1896
  body = {};
1885
1897
  }
1886
1898
  return body;
@@ -2326,7 +2338,7 @@ var FSM = class {
2326
2338
  });
2327
2339
  }
2328
2340
  #getTargetFn(eventName) {
2329
- return _optionalChain([this, 'access', _20 => _20.#allowedTransitions, 'access', _21 => _21.get, 'call', _22 => _22(this.currentState), 'optionalAccess', _23 => _23.get, 'call', _24 => _24(eventName)]);
2341
+ return _optionalChain([this, 'access', _22 => _22.#allowedTransitions, 'access', _23 => _23.get, 'call', _24 => _24(this.currentState), 'optionalAccess', _25 => _25.get, 'call', _26 => _26(eventName)]);
2330
2342
  }
2331
2343
  /**
2332
2344
  * Exits the current state, and executes any necessary cleanup functions.
@@ -2343,7 +2355,7 @@ var FSM = class {
2343
2355
  this.#currentContext.allowPatching((patchableContext) => {
2344
2356
  levels = _nullishCoalesce(levels, () => ( this.#cleanupStack.length));
2345
2357
  for (let i = 0; i < levels; i++) {
2346
- _optionalChain([this, 'access', _25 => _25.#cleanupStack, 'access', _26 => _26.pop, 'call', _27 => _27(), 'optionalCall', _28 => _28(patchableContext)]);
2358
+ _optionalChain([this, 'access', _27 => _27.#cleanupStack, 'access', _28 => _28.pop, 'call', _29 => _29(), 'optionalCall', _30 => _30(patchableContext)]);
2347
2359
  }
2348
2360
  });
2349
2361
  }
@@ -2359,7 +2371,7 @@ var FSM = class {
2359
2371
  this.#currentContext.allowPatching((patchableContext) => {
2360
2372
  for (const pattern of enterPatterns) {
2361
2373
  const enterFn = this.#enterFns.get(pattern);
2362
- const cleanupFn = _optionalChain([enterFn, 'optionalCall', _29 => _29(patchableContext)]);
2374
+ const cleanupFn = _optionalChain([enterFn, 'optionalCall', _31 => _31(patchableContext)]);
2363
2375
  if (typeof cleanupFn === "function") {
2364
2376
  this.#cleanupStack.push(cleanupFn);
2365
2377
  } else {
@@ -2519,13 +2531,6 @@ var StopRetrying = class extends Error {
2519
2531
  super(reason);
2520
2532
  }
2521
2533
  };
2522
- var LiveblocksError = class extends Error {
2523
- /** @internal */
2524
- constructor(message, code) {
2525
- super(message);
2526
- this.code = code;
2527
- }
2528
- };
2529
2534
  function nextBackoffDelay(currentDelay, delays) {
2530
2535
  return _nullishCoalesce(delays.find((delay) => delay > currentDelay), () => ( delays[delays.length - 1]));
2531
2536
  }
@@ -2635,11 +2640,10 @@ var assign = (patch) => (ctx) => ctx.patch(patch);
2635
2640
  function createConnectionStateMachine(delegates, options) {
2636
2641
  const onMessage = makeBufferableEventSource();
2637
2642
  onMessage.pause();
2638
- const onLiveblocksError = makeEventSource();
2639
- function fireErrorEvent(errmsg, errcode) {
2643
+ const onConnectionError = makeEventSource();
2644
+ function fireErrorEvent(message, code) {
2640
2645
  return () => {
2641
- const err = new LiveblocksError(errmsg, errcode);
2642
- onLiveblocksError.notify(err);
2646
+ onConnectionError.notify({ message, code });
2643
2647
  };
2644
2648
  }
2645
2649
  const initialContext = {
@@ -2761,7 +2765,7 @@ function createConnectionStateMachine(delegates, options) {
2761
2765
  }
2762
2766
  function waitForActorId(event) {
2763
2767
  const serverMsg = tryParseJson(event.data);
2764
- if (_optionalChain([serverMsg, 'optionalAccess', _30 => _30.type]) === 104 /* ROOM_STATE */) {
2768
+ if (_optionalChain([serverMsg, 'optionalAccess', _32 => _32.type]) === 104 /* ROOM_STATE */) {
2765
2769
  didReceiveActor();
2766
2770
  }
2767
2771
  }
@@ -2870,12 +2874,12 @@ function createConnectionStateMachine(delegates, options) {
2870
2874
  const sendHeartbeat = {
2871
2875
  target: "@ok.awaiting-pong",
2872
2876
  effect: (ctx) => {
2873
- _optionalChain([ctx, 'access', _31 => _31.socket, 'optionalAccess', _32 => _32.send, 'call', _33 => _33("ping")]);
2877
+ _optionalChain([ctx, 'access', _33 => _33.socket, 'optionalAccess', _34 => _34.send, 'call', _35 => _35("ping")]);
2874
2878
  }
2875
2879
  };
2876
2880
  const maybeHeartbeat = () => {
2877
2881
  const doc = typeof document !== "undefined" ? document : void 0;
2878
- const canZombie = _optionalChain([doc, 'optionalAccess', _34 => _34.visibilityState]) === "hidden" && delegates.canZombie();
2882
+ const canZombie = _optionalChain([doc, 'optionalAccess', _36 => _36.visibilityState]) === "hidden" && delegates.canZombie();
2879
2883
  return canZombie ? "@idle.zombie" : sendHeartbeat;
2880
2884
  };
2881
2885
  machine.addTimedTransition("@ok.connected", HEARTBEAT_INTERVAL, maybeHeartbeat).addTransitions("@ok.connected", {
@@ -2914,7 +2918,7 @@ function createConnectionStateMachine(delegates, options) {
2914
2918
  // socket, or not. So always check to see if the socket is still OPEN or
2915
2919
  // not. When still OPEN, don't transition.
2916
2920
  EXPLICIT_SOCKET_ERROR: (_, context) => {
2917
- if (_optionalChain([context, 'access', _35 => _35.socket, 'optionalAccess', _36 => _36.readyState]) === 1) {
2921
+ if (_optionalChain([context, 'access', _37 => _37.socket, 'optionalAccess', _38 => _38.readyState]) === 1) {
2918
2922
  return null;
2919
2923
  }
2920
2924
  return {
@@ -2966,17 +2970,17 @@ function createConnectionStateMachine(delegates, options) {
2966
2970
  machine.send({ type: "NAVIGATOR_ONLINE" });
2967
2971
  }
2968
2972
  function onVisibilityChange() {
2969
- if (_optionalChain([doc, 'optionalAccess', _37 => _37.visibilityState]) === "visible") {
2973
+ if (_optionalChain([doc, 'optionalAccess', _39 => _39.visibilityState]) === "visible") {
2970
2974
  machine.send({ type: "WINDOW_GOT_FOCUS" });
2971
2975
  }
2972
2976
  }
2973
- _optionalChain([win, 'optionalAccess', _38 => _38.addEventListener, 'call', _39 => _39("online", onNetworkBackOnline)]);
2974
- _optionalChain([win, 'optionalAccess', _40 => _40.addEventListener, 'call', _41 => _41("offline", onNetworkOffline)]);
2975
- _optionalChain([root, 'optionalAccess', _42 => _42.addEventListener, 'call', _43 => _43("visibilitychange", onVisibilityChange)]);
2977
+ _optionalChain([win, 'optionalAccess', _40 => _40.addEventListener, 'call', _41 => _41("online", onNetworkBackOnline)]);
2978
+ _optionalChain([win, 'optionalAccess', _42 => _42.addEventListener, 'call', _43 => _43("offline", onNetworkOffline)]);
2979
+ _optionalChain([root, 'optionalAccess', _44 => _44.addEventListener, 'call', _45 => _45("visibilitychange", onVisibilityChange)]);
2976
2980
  return () => {
2977
- _optionalChain([root, 'optionalAccess', _44 => _44.removeEventListener, 'call', _45 => _45("visibilitychange", onVisibilityChange)]);
2978
- _optionalChain([win, 'optionalAccess', _46 => _46.removeEventListener, 'call', _47 => _47("online", onNetworkBackOnline)]);
2979
- _optionalChain([win, 'optionalAccess', _48 => _48.removeEventListener, 'call', _49 => _49("offline", onNetworkOffline)]);
2981
+ _optionalChain([root, 'optionalAccess', _46 => _46.removeEventListener, 'call', _47 => _47("visibilitychange", onVisibilityChange)]);
2982
+ _optionalChain([win, 'optionalAccess', _48 => _48.removeEventListener, 'call', _49 => _49("online", onNetworkBackOnline)]);
2983
+ _optionalChain([win, 'optionalAccess', _50 => _50.removeEventListener, 'call', _51 => _51("offline", onNetworkOffline)]);
2980
2984
  teardownSocket(ctx.socket);
2981
2985
  };
2982
2986
  });
@@ -2997,7 +3001,7 @@ function createConnectionStateMachine(delegates, options) {
2997
3001
  didConnect,
2998
3002
  didDisconnect,
2999
3003
  onMessage: onMessage.observable,
3000
- onLiveblocksError: onLiveblocksError.observable
3004
+ onConnectionError: onConnectionError.observable
3001
3005
  }
3002
3006
  };
3003
3007
  }
@@ -3017,7 +3021,7 @@ var ManagedSocket = class {
3017
3021
  getStatus() {
3018
3022
  try {
3019
3023
  return toNewConnectionStatus(this.#machine);
3020
- } catch (e4) {
3024
+ } catch (e5) {
3021
3025
  return "initial";
3022
3026
  }
3023
3027
  }
@@ -3065,7 +3069,7 @@ var ManagedSocket = class {
3065
3069
  * message if this is somehow impossible.
3066
3070
  */
3067
3071
  send(data) {
3068
- const socket = _optionalChain([this, 'access', _50 => _50.#machine, 'access', _51 => _51.context, 'optionalAccess', _52 => _52.socket]);
3072
+ const socket = _optionalChain([this, 'access', _52 => _52.#machine, 'access', _53 => _53.context, 'optionalAccess', _54 => _54.socket]);
3069
3073
  if (socket === null) {
3070
3074
  warn("Cannot send: not connected yet", data);
3071
3075
  } else if (socket.readyState !== 1) {
@@ -3169,7 +3173,7 @@ function createAuthManager(authOptions, onAuthenticate) {
3169
3173
  return void 0;
3170
3174
  }
3171
3175
  async function makeAuthRequest(options) {
3172
- const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _53 => _53.polyfills, 'optionalAccess', _54 => _54.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
3176
+ const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _55 => _55.polyfills, 'optionalAccess', _56 => _56.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
3173
3177
  if (authentication.type === "private") {
3174
3178
  if (fetcher === void 0) {
3175
3179
  throw new StopRetrying(
@@ -3185,7 +3189,7 @@ function createAuthManager(authOptions, onAuthenticate) {
3185
3189
  "The same Liveblocks auth token was issued from the backend before. Caching Liveblocks tokens is not supported."
3186
3190
  );
3187
3191
  }
3188
- _optionalChain([onAuthenticate, 'optionalCall', _55 => _55(parsed.parsed)]);
3192
+ _optionalChain([onAuthenticate, 'optionalCall', _57 => _57(parsed.parsed)]);
3189
3193
  return parsed;
3190
3194
  }
3191
3195
  if (authentication.type === "custom") {
@@ -3193,7 +3197,7 @@ function createAuthManager(authOptions, onAuthenticate) {
3193
3197
  if (response && typeof response === "object") {
3194
3198
  if (typeof response.token === "string") {
3195
3199
  const parsed = parseAuthToken(response.token);
3196
- _optionalChain([onAuthenticate, 'optionalCall', _56 => _56(parsed.parsed)]);
3200
+ _optionalChain([onAuthenticate, 'optionalCall', _58 => _58(parsed.parsed)]);
3197
3201
  return parsed;
3198
3202
  } else if (typeof response.error === "string") {
3199
3203
  const reason = `Authentication failed: ${"reason" in response && typeof response.reason === "string" ? response.reason : "Forbidden"}`;
@@ -3354,7 +3358,7 @@ function sendToPanel(message, options) {
3354
3358
  ...message,
3355
3359
  source: "liveblocks-devtools-client"
3356
3360
  };
3357
- if (!(_optionalChain([options, 'optionalAccess', _57 => _57.force]) || _bridgeActive)) {
3361
+ if (!(_optionalChain([options, 'optionalAccess', _59 => _59.force]) || _bridgeActive)) {
3358
3362
  return;
3359
3363
  }
3360
3364
  window.postMessage(fullMsg, "*");
@@ -3362,7 +3366,7 @@ function sendToPanel(message, options) {
3362
3366
  var eventSource = makeEventSource();
3363
3367
  if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
3364
3368
  window.addEventListener("message", (event) => {
3365
- if (event.source === window && _optionalChain([event, 'access', _58 => _58.data, 'optionalAccess', _59 => _59.source]) === "liveblocks-devtools-panel") {
3369
+ if (event.source === window && _optionalChain([event, 'access', _60 => _60.data, 'optionalAccess', _61 => _61.source]) === "liveblocks-devtools-panel") {
3366
3370
  eventSource.notify(event.data);
3367
3371
  } else {
3368
3372
  }
@@ -3504,7 +3508,7 @@ function fullSync(room) {
3504
3508
  msg: "room::sync::full",
3505
3509
  roomId: room.id,
3506
3510
  status: room.getStatus(),
3507
- storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _60 => _60.toTreeNode, 'call', _61 => _61("root"), 'access', _62 => _62.payload]), () => ( null)),
3511
+ storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _62 => _62.toTreeNode, 'call', _63 => _63("root"), 'access', _64 => _64.payload]), () => ( null)),
3508
3512
  me,
3509
3513
  others
3510
3514
  });
@@ -3928,7 +3932,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
3928
3932
  return [
3929
3933
  {
3930
3934
  type: 8 /* CREATE_REGISTER */,
3931
- opId: _optionalChain([pool, 'optionalAccess', _63 => _63.generateOpId, 'call', _64 => _64()]),
3935
+ opId: _optionalChain([pool, 'optionalAccess', _65 => _65.generateOpId, 'call', _66 => _66()]),
3932
3936
  id: this._id,
3933
3937
  parentId,
3934
3938
  parentKey,
@@ -4034,7 +4038,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4034
4038
  const ops = [];
4035
4039
  const op = {
4036
4040
  id: this._id,
4037
- opId: _optionalChain([pool, 'optionalAccess', _65 => _65.generateOpId, 'call', _66 => _66()]),
4041
+ opId: _optionalChain([pool, 'optionalAccess', _67 => _67.generateOpId, 'call', _68 => _68()]),
4038
4042
  type: 2 /* CREATE_LIST */,
4039
4043
  parentId,
4040
4044
  parentKey
@@ -4305,7 +4309,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4305
4309
  #applyInsertUndoRedo(op) {
4306
4310
  const { id, parentKey: key } = op;
4307
4311
  const child = creationOpToLiveNode(op);
4308
- if (_optionalChain([this, 'access', _67 => _67._pool, 'optionalAccess', _68 => _68.getNode, 'call', _69 => _69(id)]) !== void 0) {
4312
+ if (_optionalChain([this, 'access', _69 => _69._pool, 'optionalAccess', _70 => _70.getNode, 'call', _71 => _71(id)]) !== void 0) {
4309
4313
  return { modified: false };
4310
4314
  }
4311
4315
  child._attach(id, nn(this._pool));
@@ -4313,8 +4317,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
4313
4317
  const existingItemIndex = this._indexOfPosition(key);
4314
4318
  let newKey = key;
4315
4319
  if (existingItemIndex !== -1) {
4316
- const before2 = _optionalChain([this, 'access', _70 => _70.#items, 'access', _71 => _71[existingItemIndex], 'optionalAccess', _72 => _72._parentPos]);
4317
- const after2 = _optionalChain([this, 'access', _73 => _73.#items, 'access', _74 => _74[existingItemIndex + 1], 'optionalAccess', _75 => _75._parentPos]);
4320
+ const before2 = _optionalChain([this, 'access', _72 => _72.#items, 'access', _73 => _73[existingItemIndex], 'optionalAccess', _74 => _74._parentPos]);
4321
+ const after2 = _optionalChain([this, 'access', _75 => _75.#items, 'access', _76 => _76[existingItemIndex + 1], 'optionalAccess', _77 => _77._parentPos]);
4318
4322
  newKey = makePosition(before2, after2);
4319
4323
  child._setParentLink(this, newKey);
4320
4324
  }
@@ -4328,7 +4332,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4328
4332
  #applySetUndoRedo(op) {
4329
4333
  const { id, parentKey: key } = op;
4330
4334
  const child = creationOpToLiveNode(op);
4331
- if (_optionalChain([this, 'access', _76 => _76._pool, 'optionalAccess', _77 => _77.getNode, 'call', _78 => _78(id)]) !== void 0) {
4335
+ if (_optionalChain([this, 'access', _78 => _78._pool, 'optionalAccess', _79 => _79.getNode, 'call', _80 => _80(id)]) !== void 0) {
4332
4336
  return { modified: false };
4333
4337
  }
4334
4338
  this.#unacknowledgedSets.set(key, nn(op.opId));
@@ -4449,7 +4453,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4449
4453
  } else {
4450
4454
  this.#items[existingItemIndex]._setParentLink(
4451
4455
  this,
4452
- makePosition(newKey, _optionalChain([this, 'access', _79 => _79.#items, 'access', _80 => _80[existingItemIndex + 1], 'optionalAccess', _81 => _81._parentPos]))
4456
+ makePosition(newKey, _optionalChain([this, 'access', _81 => _81.#items, 'access', _82 => _82[existingItemIndex + 1], 'optionalAccess', _83 => _83._parentPos]))
4453
4457
  );
4454
4458
  const previousIndex = this.#items.indexOf(child);
4455
4459
  child._setParentLink(this, newKey);
@@ -4474,7 +4478,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4474
4478
  if (existingItemIndex !== -1) {
4475
4479
  this.#items[existingItemIndex]._setParentLink(
4476
4480
  this,
4477
- makePosition(newKey, _optionalChain([this, 'access', _82 => _82.#items, 'access', _83 => _83[existingItemIndex + 1], 'optionalAccess', _84 => _84._parentPos]))
4481
+ makePosition(newKey, _optionalChain([this, 'access', _84 => _84.#items, 'access', _85 => _85[existingItemIndex + 1], 'optionalAccess', _86 => _86._parentPos]))
4478
4482
  );
4479
4483
  }
4480
4484
  child._setParentLink(this, newKey);
@@ -4493,7 +4497,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4493
4497
  if (existingItemIndex !== -1) {
4494
4498
  this.#items[existingItemIndex]._setParentLink(
4495
4499
  this,
4496
- makePosition(newKey, _optionalChain([this, 'access', _85 => _85.#items, 'access', _86 => _86[existingItemIndex + 1], 'optionalAccess', _87 => _87._parentPos]))
4500
+ makePosition(newKey, _optionalChain([this, 'access', _87 => _87.#items, 'access', _88 => _88[existingItemIndex + 1], 'optionalAccess', _89 => _89._parentPos]))
4497
4501
  );
4498
4502
  }
4499
4503
  child._setParentLink(this, newKey);
@@ -4520,7 +4524,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4520
4524
  if (existingItemIndex !== -1) {
4521
4525
  this.#items[existingItemIndex]._setParentLink(
4522
4526
  this,
4523
- makePosition(newKey, _optionalChain([this, 'access', _88 => _88.#items, 'access', _89 => _89[existingItemIndex + 1], 'optionalAccess', _90 => _90._parentPos]))
4527
+ makePosition(newKey, _optionalChain([this, 'access', _90 => _90.#items, 'access', _91 => _91[existingItemIndex + 1], 'optionalAccess', _92 => _92._parentPos]))
4524
4528
  );
4525
4529
  }
4526
4530
  child._setParentLink(this, newKey);
@@ -4578,7 +4582,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4578
4582
  * @param element The element to add to the end of the LiveList.
4579
4583
  */
4580
4584
  push(element) {
4581
- _optionalChain([this, 'access', _91 => _91._pool, 'optionalAccess', _92 => _92.assertStorageIsWritable, 'call', _93 => _93()]);
4585
+ _optionalChain([this, 'access', _93 => _93._pool, 'optionalAccess', _94 => _94.assertStorageIsWritable, 'call', _95 => _95()]);
4582
4586
  return this.insert(element, this.length);
4583
4587
  }
4584
4588
  /**
@@ -4587,7 +4591,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4587
4591
  * @param index The index at which you want to insert the element.
4588
4592
  */
4589
4593
  insert(element, index) {
4590
- _optionalChain([this, 'access', _94 => _94._pool, 'optionalAccess', _95 => _95.assertStorageIsWritable, 'call', _96 => _96()]);
4594
+ _optionalChain([this, 'access', _96 => _96._pool, 'optionalAccess', _97 => _97.assertStorageIsWritable, 'call', _98 => _98()]);
4591
4595
  if (index < 0 || index > this.#items.length) {
4592
4596
  throw new Error(
4593
4597
  `Cannot insert list item at index "${index}". index should be between 0 and ${this.#items.length}`
@@ -4617,7 +4621,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4617
4621
  * @param targetIndex The index where the element should be after moving.
4618
4622
  */
4619
4623
  move(index, targetIndex) {
4620
- _optionalChain([this, 'access', _97 => _97._pool, 'optionalAccess', _98 => _98.assertStorageIsWritable, 'call', _99 => _99()]);
4624
+ _optionalChain([this, 'access', _99 => _99._pool, 'optionalAccess', _100 => _100.assertStorageIsWritable, 'call', _101 => _101()]);
4621
4625
  if (targetIndex < 0) {
4622
4626
  throw new Error("targetIndex cannot be less than 0");
4623
4627
  }
@@ -4675,7 +4679,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4675
4679
  * @param index The index of the element to delete
4676
4680
  */
4677
4681
  delete(index) {
4678
- _optionalChain([this, 'access', _100 => _100._pool, 'optionalAccess', _101 => _101.assertStorageIsWritable, 'call', _102 => _102()]);
4682
+ _optionalChain([this, 'access', _102 => _102._pool, 'optionalAccess', _103 => _103.assertStorageIsWritable, 'call', _104 => _104()]);
4679
4683
  if (index < 0 || index >= this.#items.length) {
4680
4684
  throw new Error(
4681
4685
  `Cannot delete list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
@@ -4708,7 +4712,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4708
4712
  }
4709
4713
  }
4710
4714
  clear() {
4711
- _optionalChain([this, 'access', _103 => _103._pool, 'optionalAccess', _104 => _104.assertStorageIsWritable, 'call', _105 => _105()]);
4715
+ _optionalChain([this, 'access', _105 => _105._pool, 'optionalAccess', _106 => _106.assertStorageIsWritable, 'call', _107 => _107()]);
4712
4716
  if (this._pool) {
4713
4717
  const ops = [];
4714
4718
  const reverseOps = [];
@@ -4742,7 +4746,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4742
4746
  }
4743
4747
  }
4744
4748
  set(index, item) {
4745
- _optionalChain([this, 'access', _106 => _106._pool, 'optionalAccess', _107 => _107.assertStorageIsWritable, 'call', _108 => _108()]);
4749
+ _optionalChain([this, 'access', _108 => _108._pool, 'optionalAccess', _109 => _109.assertStorageIsWritable, 'call', _110 => _110()]);
4746
4750
  if (index < 0 || index >= this.#items.length) {
4747
4751
  throw new Error(
4748
4752
  `Cannot set list item at index "${index}". index should be between 0 and ${this.#items.length - 1}`
@@ -4888,7 +4892,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
4888
4892
  #shiftItemPosition(index, key) {
4889
4893
  const shiftedPosition = makePosition(
4890
4894
  key,
4891
- this.#items.length > index + 1 ? _optionalChain([this, 'access', _109 => _109.#items, 'access', _110 => _110[index + 1], 'optionalAccess', _111 => _111._parentPos]) : void 0
4895
+ this.#items.length > index + 1 ? _optionalChain([this, 'access', _111 => _111.#items, 'access', _112 => _112[index + 1], 'optionalAccess', _113 => _113._parentPos]) : void 0
4892
4896
  );
4893
4897
  this.#items[index]._setParentLink(this, shiftedPosition);
4894
4898
  }
@@ -5013,7 +5017,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
5013
5017
  const ops = [];
5014
5018
  const op = {
5015
5019
  id: this._id,
5016
- opId: _optionalChain([pool, 'optionalAccess', _112 => _112.generateOpId, 'call', _113 => _113()]),
5020
+ opId: _optionalChain([pool, 'optionalAccess', _114 => _114.generateOpId, 'call', _115 => _115()]),
5017
5021
  type: 7 /* CREATE_MAP */,
5018
5022
  parentId,
5019
5023
  parentKey
@@ -5148,7 +5152,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
5148
5152
  * @param value The value of the element to add. Should be serializable to JSON.
5149
5153
  */
5150
5154
  set(key, value) {
5151
- _optionalChain([this, 'access', _114 => _114._pool, 'optionalAccess', _115 => _115.assertStorageIsWritable, 'call', _116 => _116()]);
5155
+ _optionalChain([this, 'access', _116 => _116._pool, 'optionalAccess', _117 => _117.assertStorageIsWritable, 'call', _118 => _118()]);
5152
5156
  const oldValue = this.#map.get(key);
5153
5157
  if (oldValue) {
5154
5158
  oldValue._detach();
@@ -5194,7 +5198,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
5194
5198
  * @returns true if an element existed and has been removed, or false if the element does not exist.
5195
5199
  */
5196
5200
  delete(key) {
5197
- _optionalChain([this, 'access', _117 => _117._pool, 'optionalAccess', _118 => _118.assertStorageIsWritable, 'call', _119 => _119()]);
5201
+ _optionalChain([this, 'access', _119 => _119._pool, 'optionalAccess', _120 => _120.assertStorageIsWritable, 'call', _121 => _121()]);
5198
5202
  const item = this.#map.get(key);
5199
5203
  if (item === void 0) {
5200
5204
  return false;
@@ -5373,7 +5377,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
5373
5377
  if (this._id === void 0) {
5374
5378
  throw new Error("Cannot serialize item is not attached");
5375
5379
  }
5376
- const opId = _optionalChain([pool, 'optionalAccess', _120 => _120.generateOpId, 'call', _121 => _121()]);
5380
+ const opId = _optionalChain([pool, 'optionalAccess', _122 => _122.generateOpId, 'call', _123 => _123()]);
5377
5381
  const ops = [];
5378
5382
  const op = {
5379
5383
  type: 4 /* CREATE_OBJECT */,
@@ -5645,7 +5649,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
5645
5649
  * @param value The value of the property to add
5646
5650
  */
5647
5651
  set(key, value) {
5648
- _optionalChain([this, 'access', _122 => _122._pool, 'optionalAccess', _123 => _123.assertStorageIsWritable, 'call', _124 => _124()]);
5652
+ _optionalChain([this, 'access', _124 => _124._pool, 'optionalAccess', _125 => _125.assertStorageIsWritable, 'call', _126 => _126()]);
5649
5653
  this.update({ [key]: value });
5650
5654
  }
5651
5655
  /**
@@ -5660,7 +5664,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
5660
5664
  * @param key The key of the property to delete
5661
5665
  */
5662
5666
  delete(key) {
5663
- _optionalChain([this, 'access', _125 => _125._pool, 'optionalAccess', _126 => _126.assertStorageIsWritable, 'call', _127 => _127()]);
5667
+ _optionalChain([this, 'access', _127 => _127._pool, 'optionalAccess', _128 => _128.assertStorageIsWritable, 'call', _129 => _129()]);
5664
5668
  const keyAsString = key;
5665
5669
  const oldValue = this.#map.get(keyAsString);
5666
5670
  if (oldValue === void 0) {
@@ -5713,7 +5717,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
5713
5717
  * @param patch The object used to overrides properties
5714
5718
  */
5715
5719
  update(patch) {
5716
- _optionalChain([this, 'access', _128 => _128._pool, 'optionalAccess', _129 => _129.assertStorageIsWritable, 'call', _130 => _130()]);
5720
+ _optionalChain([this, 'access', _130 => _130._pool, 'optionalAccess', _131 => _131.assertStorageIsWritable, 'call', _132 => _132()]);
5717
5721
  if (this._pool === void 0 || this._id === void 0) {
5718
5722
  for (const key in patch) {
5719
5723
  const newValue = patch[key];
@@ -6261,6 +6265,83 @@ var ManagedOthers = class {
6261
6265
  }
6262
6266
  };
6263
6267
 
6268
+ // src/types/LiveblocksError.ts
6269
+ var LiveblocksError = class _LiveblocksError extends Error {
6270
+
6271
+ constructor(message, context, cause) {
6272
+ super(message, { cause });
6273
+ this.context = context;
6274
+ this.name = "LiveblocksError";
6275
+ }
6276
+ /** Convenience accessor for error.context.roomId (if available) */
6277
+ get roomId() {
6278
+ return this.context.roomId;
6279
+ }
6280
+ /** @deprecated Prefer using `context.code` instead, to enable type narrowing */
6281
+ get code() {
6282
+ return this.context.code;
6283
+ }
6284
+ /**
6285
+ * Creates a LiveblocksError from a generic error, by attaching Liveblocks
6286
+ * contextual information like room ID, thread ID, etc.
6287
+ */
6288
+ static from(context, cause) {
6289
+ return new _LiveblocksError(
6290
+ defaultMessageFromContext(context),
6291
+ context,
6292
+ cause
6293
+ );
6294
+ }
6295
+ };
6296
+ function defaultMessageFromContext(context) {
6297
+ switch (context.type) {
6298
+ case "ROOM_CONNECTION_ERROR": {
6299
+ switch (context.code) {
6300
+ case 4001:
6301
+ return "Not allowed to connect to the room";
6302
+ case 4005:
6303
+ return "Room is already full";
6304
+ case 4006:
6305
+ return "Kicked out of the room, because the room ID changed";
6306
+ default:
6307
+ return "Could not connect to the room";
6308
+ }
6309
+ }
6310
+ case "CREATE_THREAD_ERROR":
6311
+ return "Could not create new thread";
6312
+ case "DELETE_THREAD_ERROR":
6313
+ return "Could not delete thread";
6314
+ case "EDIT_THREAD_METADATA_ERROR":
6315
+ return "Could not edit thread metadata";
6316
+ case "MARK_THREAD_AS_RESOLVED_ERROR":
6317
+ return "Could not mark thread as resolved";
6318
+ case "MARK_THREAD_AS_UNRESOLVED_ERROR":
6319
+ return "Could not mark thread as unresolved";
6320
+ case "CREATE_COMMENT_ERROR":
6321
+ return "Could not create new comment";
6322
+ case "EDIT_COMMENT_ERROR":
6323
+ return "Could not edit comment";
6324
+ case "DELETE_COMMENT_ERROR":
6325
+ return "Could not delete comment";
6326
+ case "ADD_REACTION_ERROR":
6327
+ return "Could not add reaction";
6328
+ case "REMOVE_REACTION_ERROR":
6329
+ return "Could not remove reaction";
6330
+ case "MARK_INBOX_NOTIFICATION_AS_READ_ERROR":
6331
+ return "Could not mark inbox notification as read";
6332
+ case "DELETE_INBOX_NOTIFICATION_ERROR":
6333
+ return "Could not delete inbox notification";
6334
+ case "MARK_ALL_INBOX_NOTIFICATIONS_AS_READ_ERROR":
6335
+ return "Could not mark all inbox notifications as read";
6336
+ case "DELETE_ALL_INBOX_NOTIFICATIONS_ERROR":
6337
+ return "Could not delete all inbox notifications";
6338
+ case "UPDATE_NOTIFICATION_SETTINGS_ERROR":
6339
+ return "Could not update notification settings";
6340
+ default:
6341
+ return assertNever(context, "Unhandled case");
6342
+ }
6343
+ }
6344
+
6264
6345
  // src/room.ts
6265
6346
  var MAX_SOCKET_MESSAGE_SIZE = 1024 * 1024 - 1024;
6266
6347
  function makeIdFactory(connectionId) {
@@ -6285,15 +6366,15 @@ function installBackgroundTabSpy() {
6285
6366
  const doc = typeof document !== "undefined" ? document : void 0;
6286
6367
  const inBackgroundSince = { current: null };
6287
6368
  function onVisibilityChange() {
6288
- if (_optionalChain([doc, 'optionalAccess', _131 => _131.visibilityState]) === "hidden") {
6369
+ if (_optionalChain([doc, 'optionalAccess', _133 => _133.visibilityState]) === "hidden") {
6289
6370
  inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
6290
6371
  } else {
6291
6372
  inBackgroundSince.current = null;
6292
6373
  }
6293
6374
  }
6294
- _optionalChain([doc, 'optionalAccess', _132 => _132.addEventListener, 'call', _133 => _133("visibilitychange", onVisibilityChange)]);
6375
+ _optionalChain([doc, 'optionalAccess', _134 => _134.addEventListener, 'call', _135 => _135("visibilitychange", onVisibilityChange)]);
6295
6376
  const unsub = () => {
6296
- _optionalChain([doc, 'optionalAccess', _134 => _134.removeEventListener, 'call', _135 => _135("visibilitychange", onVisibilityChange)]);
6377
+ _optionalChain([doc, 'optionalAccess', _136 => _136.removeEventListener, 'call', _137 => _137("visibilitychange", onVisibilityChange)]);
6297
6378
  };
6298
6379
  return [inBackgroundSince, unsub];
6299
6380
  }
@@ -6425,13 +6506,17 @@ function createRoom(options, config) {
6425
6506
  managedSocket.events.statusDidChange.subscribe(handleConnectionLossEvent);
6426
6507
  managedSocket.events.didConnect.subscribe(onDidConnect);
6427
6508
  managedSocket.events.didDisconnect.subscribe(onDidDisconnect);
6428
- managedSocket.events.onLiveblocksError.subscribe((err) => {
6429
- if (process.env.NODE_ENV !== "production") {
6430
- error2(
6431
- `Connection to websocket server closed. Reason: ${err.message} (code: ${err.code}).`
6432
- );
6509
+ managedSocket.events.onConnectionError.subscribe(({ message, code }) => {
6510
+ const type = "ROOM_CONNECTION_ERROR";
6511
+ const err = new LiveblocksError(message, { type, code, roomId });
6512
+ const didNotify = config.errorEventSource.notify(err);
6513
+ if (!didNotify) {
6514
+ if (process.env.NODE_ENV !== "production") {
6515
+ error2(
6516
+ `Connection to websocket server closed. Reason: ${message} (code: ${code}).`
6517
+ );
6518
+ }
6433
6519
  }
6434
- eventHub.error.notify(err);
6435
6520
  });
6436
6521
  const pool = {
6437
6522
  roomId: config.roomId,
@@ -6474,7 +6559,7 @@ function createRoom(options, config) {
6474
6559
  }
6475
6560
  },
6476
6561
  assertStorageIsWritable: () => {
6477
- const scopes = _optionalChain([context, 'access', _136 => _136.dynamicSessionInfoSig, 'access', _137 => _137.get, 'call', _138 => _138(), 'optionalAccess', _139 => _139.scopes]);
6562
+ const scopes = _optionalChain([context, 'access', _138 => _138.dynamicSessionInfoSig, 'access', _139 => _139.get, 'call', _140 => _140(), 'optionalAccess', _141 => _141.scopes]);
6478
6563
  if (scopes === void 0) {
6479
6564
  return;
6480
6565
  }
@@ -6494,7 +6579,6 @@ function createRoom(options, config) {
6494
6579
  self: makeEventSource(),
6495
6580
  myPresence: makeEventSource(),
6496
6581
  others: makeEventSource(),
6497
- error: makeEventSource(),
6498
6582
  storageBatch: makeEventSource(),
6499
6583
  history: makeEventSource(),
6500
6584
  storageDidLoad: makeEventSource(),
@@ -6530,7 +6614,7 @@ function createRoom(options, config) {
6530
6614
  }
6531
6615
  function sendMessages(messages) {
6532
6616
  const serializedPayload = JSON.stringify(messages);
6533
- const nonce = _optionalChain([context, 'access', _140 => _140.dynamicSessionInfoSig, 'access', _141 => _141.get, 'call', _142 => _142(), 'optionalAccess', _143 => _143.nonce]);
6617
+ const nonce = _optionalChain([context, 'access', _142 => _142.dynamicSessionInfoSig, 'access', _143 => _143.get, 'call', _144 => _144(), 'optionalAccess', _145 => _145.nonce]);
6534
6618
  if (config.unstable_fallbackToHTTP && nonce) {
6535
6619
  const size = new TextEncoder().encode(serializedPayload).length;
6536
6620
  if (size > MAX_SOCKET_MESSAGE_SIZE) {
@@ -6588,7 +6672,7 @@ function createRoom(options, config) {
6588
6672
  } else {
6589
6673
  context.root = LiveObject._fromItems(message.items, pool);
6590
6674
  }
6591
- const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _144 => _144.get, 'call', _145 => _145(), 'optionalAccess', _146 => _146.canWrite]), () => ( true));
6675
+ const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _146 => _146.get, 'call', _147 => _147(), 'optionalAccess', _148 => _148.canWrite]), () => ( true));
6592
6676
  const stackSizeBefore = context.undoStack.length;
6593
6677
  for (const key in context.initialStorage) {
6594
6678
  if (context.root.get(key) === void 0) {
@@ -6791,7 +6875,7 @@ function createRoom(options, config) {
6791
6875
  }
6792
6876
  context.myPresence.patch(patch);
6793
6877
  if (context.activeBatch) {
6794
- if (_optionalChain([options2, 'optionalAccess', _147 => _147.addToHistory])) {
6878
+ if (_optionalChain([options2, 'optionalAccess', _149 => _149.addToHistory])) {
6795
6879
  context.activeBatch.reverseOps.unshift({
6796
6880
  type: "presence",
6797
6881
  data: oldValues
@@ -6800,7 +6884,7 @@ function createRoom(options, config) {
6800
6884
  context.activeBatch.updates.presence = true;
6801
6885
  } else {
6802
6886
  flushNowOrSoon();
6803
- if (_optionalChain([options2, 'optionalAccess', _148 => _148.addToHistory])) {
6887
+ if (_optionalChain([options2, 'optionalAccess', _150 => _150.addToHistory])) {
6804
6888
  addToUndoStack([{ type: "presence", data: oldValues }]);
6805
6889
  }
6806
6890
  notify({ presence: true });
@@ -6997,7 +7081,7 @@ function createRoom(options, config) {
6997
7081
  if (process.env.NODE_ENV !== "production") {
6998
7082
  const traces = /* @__PURE__ */ new Set();
6999
7083
  for (const opId of message.opIds) {
7000
- const trace = _optionalChain([context, 'access', _149 => _149.opStackTraces, 'optionalAccess', _150 => _150.get, 'call', _151 => _151(opId)]);
7084
+ const trace = _optionalChain([context, 'access', _151 => _151.opStackTraces, 'optionalAccess', _152 => _152.get, 'call', _153 => _153(opId)]);
7001
7085
  if (trace) {
7002
7086
  traces.add(trace);
7003
7087
  }
@@ -7131,7 +7215,7 @@ ${Array.from(traces).join("\n\n")}`
7131
7215
  const unacknowledgedOps = new Map(context.unacknowledgedOps);
7132
7216
  createOrUpdateRootFromMessage(message);
7133
7217
  applyAndSendOps(unacknowledgedOps);
7134
- _optionalChain([_resolveStoragePromise, 'optionalCall', _152 => _152()]);
7218
+ _optionalChain([_resolveStoragePromise, 'optionalCall', _154 => _154()]);
7135
7219
  notifyStorageStatus();
7136
7220
  eventHub.storageDidLoad.notify();
7137
7221
  }
@@ -7334,7 +7418,6 @@ ${Array.from(traces).join("\n\n")}`
7334
7418
  others: eventHub.others.observable,
7335
7419
  self: eventHub.self.observable,
7336
7420
  myPresence: eventHub.myPresence.observable,
7337
- error: eventHub.error.observable,
7338
7421
  /** @deprecated */
7339
7422
  storage: eventHub.storageBatch.observable,
7340
7423
  storageBatch: eventHub.storageBatch.observable,
@@ -7354,8 +7437,8 @@ ${Array.from(traces).join("\n\n")}`
7354
7437
  async function getThreads(options2) {
7355
7438
  return httpClient.getThreads({
7356
7439
  roomId,
7357
- query: _optionalChain([options2, 'optionalAccess', _153 => _153.query]),
7358
- cursor: _optionalChain([options2, 'optionalAccess', _154 => _154.cursor])
7440
+ query: _optionalChain([options2, 'optionalAccess', _155 => _155.query]),
7441
+ cursor: _optionalChain([options2, 'optionalAccess', _156 => _156.cursor])
7359
7442
  });
7360
7443
  }
7361
7444
  async function getThread(threadId) {
@@ -7456,7 +7539,7 @@ ${Array.from(traces).join("\n\n")}`
7456
7539
  function getNotificationSettings(options2) {
7457
7540
  return httpClient.getNotificationSettings({
7458
7541
  roomId,
7459
- signal: _optionalChain([options2, 'optionalAccess', _155 => _155.signal])
7542
+ signal: _optionalChain([options2, 'optionalAccess', _157 => _157.signal])
7460
7543
  });
7461
7544
  }
7462
7545
  function updateNotificationSettings(settings) {
@@ -7478,7 +7561,7 @@ ${Array.from(traces).join("\n\n")}`
7478
7561
  {
7479
7562
  [kInternal]: {
7480
7563
  get presenceBuffer() {
7481
- return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _156 => _156.buffer, 'access', _157 => _157.presenceUpdates, 'optionalAccess', _158 => _158.data]), () => ( null)));
7564
+ return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _158 => _158.buffer, 'access', _159 => _159.presenceUpdates, 'optionalAccess', _160 => _160.data]), () => ( null)));
7482
7565
  },
7483
7566
  // prettier-ignore
7484
7567
  get undoStack() {
@@ -7493,9 +7576,9 @@ ${Array.from(traces).join("\n\n")}`
7493
7576
  return context.yjsProvider;
7494
7577
  },
7495
7578
  setYjsProvider(newProvider) {
7496
- _optionalChain([context, 'access', _159 => _159.yjsProvider, 'optionalAccess', _160 => _160.off, 'call', _161 => _161("status", yjsStatusDidChange)]);
7579
+ _optionalChain([context, 'access', _161 => _161.yjsProvider, 'optionalAccess', _162 => _162.off, 'call', _163 => _163("status", yjsStatusDidChange)]);
7497
7580
  context.yjsProvider = newProvider;
7498
- _optionalChain([newProvider, 'optionalAccess', _162 => _162.on, 'call', _163 => _163("status", yjsStatusDidChange)]);
7581
+ _optionalChain([newProvider, 'optionalAccess', _164 => _164.on, 'call', _165 => _165("status", yjsStatusDidChange)]);
7499
7582
  context.yjsProviderDidChange.notify();
7500
7583
  },
7501
7584
  yjsProviderDidChange: context.yjsProviderDidChange.observable,
@@ -7525,13 +7608,17 @@ ${Array.from(traces).join("\n\n")}`
7525
7608
  attachmentUrlsStore: httpClient.getOrCreateAttachmentUrlsStore(roomId)
7526
7609
  },
7527
7610
  id: config.roomId,
7528
- subscribe: makeClassicSubscribeFn(events),
7611
+ subscribe: makeClassicSubscribeFn(
7612
+ config.roomId,
7613
+ events,
7614
+ config.errorEventSource
7615
+ ),
7529
7616
  connect: () => managedSocket.connect(),
7530
7617
  reconnect: () => managedSocket.reconnect(),
7531
7618
  disconnect: () => managedSocket.disconnect(),
7532
7619
  destroy: () => {
7533
7620
  syncSourceForStorage.destroy();
7534
- _optionalChain([context, 'access', _164 => _164.yjsProvider, 'optionalAccess', _165 => _165.off, 'call', _166 => _166("status", yjsStatusDidChange)]);
7621
+ _optionalChain([context, 'access', _166 => _166.yjsProvider, 'optionalAccess', _167 => _167.off, 'call', _168 => _168("status", yjsStatusDidChange)]);
7535
7622
  syncSourceForYjs.destroy();
7536
7623
  uninstallBgTabSpy();
7537
7624
  managedSocket.destroy();
@@ -7594,7 +7681,7 @@ ${Array.from(traces).join("\n\n")}`
7594
7681
  { enumerable: false }
7595
7682
  );
7596
7683
  }
7597
- function makeClassicSubscribeFn(events) {
7684
+ function makeClassicSubscribeFn(roomId, events, errorEvents) {
7598
7685
  function subscribeToLiveStructureDeeply(node, callback) {
7599
7686
  return events.storageBatch.subscribe((updates) => {
7600
7687
  const relatedUpdates = updates.filter(
@@ -7634,8 +7721,13 @@ function makeClassicSubscribeFn(events) {
7634
7721
  return cb(others, internalEvent);
7635
7722
  });
7636
7723
  }
7637
- case "error":
7638
- return events.error.subscribe(callback);
7724
+ case "error": {
7725
+ return errorEvents.subscribe((err) => {
7726
+ if (err.roomId === roomId) {
7727
+ return callback(err);
7728
+ }
7729
+ });
7730
+ }
7639
7731
  case "status":
7640
7732
  return events.status.subscribe(callback);
7641
7733
  case "lost-connection":
@@ -7670,7 +7762,7 @@ function makeClassicSubscribeFn(events) {
7670
7762
  }
7671
7763
  if (isLiveNode(first)) {
7672
7764
  const node = first;
7673
- if (_optionalChain([options, 'optionalAccess', _167 => _167.isDeep])) {
7765
+ if (_optionalChain([options, 'optionalAccess', _169 => _169.isDeep])) {
7674
7766
  const storageCallback = second;
7675
7767
  return subscribeToLiveStructureDeeply(node, storageCallback);
7676
7768
  } else {
@@ -7749,8 +7841,8 @@ function createClient(options) {
7749
7841
  const userId = token.k === "sec-legacy" /* SECRET_LEGACY */ ? token.id : token.uid;
7750
7842
  currentUserId.set(() => userId);
7751
7843
  });
7752
- const fetchPolyfill = _optionalChain([clientOptions, 'access', _168 => _168.polyfills, 'optionalAccess', _169 => _169.fetch]) || /* istanbul ignore next */
7753
- _optionalChain([globalThis, 'access', _170 => _170.fetch, 'optionalAccess', _171 => _171.bind, 'call', _172 => _172(globalThis)]);
7844
+ const fetchPolyfill = _optionalChain([clientOptions, 'access', _170 => _170.polyfills, 'optionalAccess', _171 => _171.fetch]) || /* istanbul ignore next */
7845
+ _optionalChain([globalThis, 'access', _172 => _172.fetch, 'optionalAccess', _173 => _173.bind, 'call', _174 => _174(globalThis)]);
7754
7846
  const httpClient = createApiClient({
7755
7847
  baseUrl,
7756
7848
  fetchPolyfill,
@@ -7801,12 +7893,13 @@ function createClient(options) {
7801
7893
  createSocket: makeCreateSocketDelegateForRoom(
7802
7894
  roomId,
7803
7895
  baseUrl,
7804
- _optionalChain([clientOptions, 'access', _173 => _173.polyfills, 'optionalAccess', _174 => _174.WebSocket])
7896
+ _optionalChain([clientOptions, 'access', _175 => _175.polyfills, 'optionalAccess', _176 => _176.WebSocket])
7805
7897
  ),
7806
7898
  authenticate: makeAuthDelegateForRoom(roomId, authManager)
7807
7899
  })),
7808
7900
  enableDebugLogging: clientOptions.enableDebugLogging,
7809
7901
  baseUrl,
7902
+ errorEventSource: liveblocksErrorSource,
7810
7903
  unstable_fallbackToHTTP: !!clientOptions.unstable_fallbackToHTTP,
7811
7904
  unstable_streamData: !!clientOptions.unstable_streamData,
7812
7905
  roomHttpClient: httpClient,
@@ -7823,7 +7916,7 @@ function createClient(options) {
7823
7916
  const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
7824
7917
  if (shouldConnect) {
7825
7918
  if (typeof atob === "undefined") {
7826
- if (_optionalChain([clientOptions, 'access', _175 => _175.polyfills, 'optionalAccess', _176 => _176.atob]) === void 0) {
7919
+ if (_optionalChain([clientOptions, 'access', _177 => _177.polyfills, 'optionalAccess', _178 => _178.atob]) === void 0) {
7827
7920
  throw new Error(
7828
7921
  "You need to polyfill atob to use the client in your environment. Please follow the instructions at https://liveblocks.io/docs/errors/liveblocks-client/atob-polyfill"
7829
7922
  );
@@ -7835,7 +7928,7 @@ function createClient(options) {
7835
7928
  return leaseRoom(newRoomDetails);
7836
7929
  }
7837
7930
  function getRoom(roomId) {
7838
- const room = _optionalChain([roomsById, 'access', _177 => _177.get, 'call', _178 => _178(roomId), 'optionalAccess', _179 => _179.room]);
7931
+ const room = _optionalChain([roomsById, 'access', _179 => _179.get, 'call', _180 => _180(roomId), 'optionalAccess', _181 => _181.room]);
7839
7932
  return room ? room : null;
7840
7933
  }
7841
7934
  function logout() {
@@ -7855,7 +7948,7 @@ function createClient(options) {
7855
7948
  const batchedResolveUsers = new Batch(
7856
7949
  async (batchedUserIds) => {
7857
7950
  const userIds = batchedUserIds.flat();
7858
- const users = await _optionalChain([resolveUsers, 'optionalCall', _180 => _180({ userIds })]);
7951
+ const users = await _optionalChain([resolveUsers, 'optionalCall', _182 => _182({ userIds })]);
7859
7952
  warnIfNoResolveUsers();
7860
7953
  return _nullishCoalesce(users, () => ( userIds.map(() => void 0)));
7861
7954
  },
@@ -7873,7 +7966,7 @@ function createClient(options) {
7873
7966
  const batchedResolveRoomsInfo = new Batch(
7874
7967
  async (batchedRoomIds) => {
7875
7968
  const roomIds = batchedRoomIds.flat();
7876
- const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _181 => _181({ roomIds })]);
7969
+ const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _183 => _183({ roomIds })]);
7877
7970
  warnIfNoResolveRoomsInfo();
7878
7971
  return _nullishCoalesce(roomsInfo, () => ( roomIds.map(() => void 0)));
7879
7972
  },
@@ -7889,6 +7982,7 @@ function createClient(options) {
7889
7982
  }
7890
7983
  const syncStatusSources = [];
7891
7984
  const syncStatusSignal = new Signal("synchronized");
7985
+ const liveblocksErrorSource = makeEventSource();
7892
7986
  function getSyncStatus() {
7893
7987
  const status = syncStatusSignal.get();
7894
7988
  return status === "synchronizing" ? status : "synchronized";
@@ -7925,7 +8019,7 @@ function createClient(options) {
7925
8019
  }
7926
8020
  };
7927
8021
  const win = typeof window !== "undefined" ? window : void 0;
7928
- _optionalChain([win, 'optionalAccess', _182 => _182.addEventListener, 'call', _183 => _183("beforeunload", maybePreventClose)]);
8022
+ _optionalChain([win, 'optionalAccess', _184 => _184.addEventListener, 'call', _185 => _185("beforeunload", maybePreventClose)]);
7929
8023
  }
7930
8024
  const client = Object.defineProperty(
7931
8025
  {
@@ -7941,8 +8035,8 @@ function createClient(options) {
7941
8035
  deleteAllInboxNotifications: httpClient.deleteAllInboxNotifications,
7942
8036
  deleteInboxNotification: httpClient.deleteInboxNotification,
7943
8037
  // Public channel notification settings API
7944
- getChannelsNotificationSettings: httpClient.getChannelsNotificationSettings,
7945
- updateChannelsNotificationSettings: httpClient.updateChannelsNotificationSettings,
8038
+ getNotificationSettings: httpClient.getUserNotificationSettings,
8039
+ updateNotificationSettings: httpClient.updateUserNotificationSettings,
7946
8040
  // Advanced resolvers APIs
7947
8041
  resolvers: {
7948
8042
  invalidateUsers: invalidateResolvedUsers,
@@ -7951,6 +8045,7 @@ function createClient(options) {
7951
8045
  },
7952
8046
  getSyncStatus,
7953
8047
  events: {
8048
+ error: liveblocksErrorSource,
7954
8049
  syncStatus: syncStatusSignal
7955
8050
  },
7956
8051
  // Internal
@@ -7966,7 +8061,14 @@ function createClient(options) {
7966
8061
  httpClient,
7967
8062
  // Type-level helper only, it's effectively only an identity-function at runtime
7968
8063
  as: () => client,
7969
- createSyncSource
8064
+ createSyncSource,
8065
+ emitError: (context, cause) => {
8066
+ const error3 = LiveblocksError.from(context, cause);
8067
+ const didNotify = liveblocksErrorSource.notify(error3);
8068
+ if (!didNotify) {
8069
+ error2(error3.message);
8070
+ }
8071
+ }
7970
8072
  }
7971
8073
  },
7972
8074
  kInternal,
@@ -8045,7 +8147,7 @@ var commentBodyElementsTypes = {
8045
8147
  mention: "inline"
8046
8148
  };
8047
8149
  function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
8048
- if (!body || !_optionalChain([body, 'optionalAccess', _184 => _184.content])) {
8150
+ if (!body || !_optionalChain([body, 'optionalAccess', _186 => _186.content])) {
8049
8151
  return;
8050
8152
  }
8051
8153
  const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
@@ -8055,13 +8157,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
8055
8157
  for (const block of body.content) {
8056
8158
  if (type === "all" || type === "block") {
8057
8159
  if (guard(block)) {
8058
- _optionalChain([visitor, 'optionalCall', _185 => _185(block)]);
8160
+ _optionalChain([visitor, 'optionalCall', _187 => _187(block)]);
8059
8161
  }
8060
8162
  }
8061
8163
  if (type === "all" || type === "inline") {
8062
8164
  for (const inline of block.children) {
8063
8165
  if (guard(inline)) {
8064
- _optionalChain([visitor, 'optionalCall', _186 => _186(inline)]);
8166
+ _optionalChain([visitor, 'optionalCall', _188 => _188(inline)]);
8065
8167
  }
8066
8168
  }
8067
8169
  }
@@ -8086,7 +8188,7 @@ async function resolveUsersInCommentBody(body, resolveUsers) {
8086
8188
  userIds
8087
8189
  });
8088
8190
  for (const [index, userId] of userIds.entries()) {
8089
- const user = _optionalChain([users, 'optionalAccess', _187 => _187[index]]);
8191
+ const user = _optionalChain([users, 'optionalAccess', _189 => _189[index]]);
8090
8192
  if (user) {
8091
8193
  resolvedUsers.set(userId, user);
8092
8194
  }
@@ -8213,7 +8315,7 @@ var stringifyCommentBodyPlainElements = {
8213
8315
  text: ({ element }) => element.text,
8214
8316
  link: ({ element }) => _nullishCoalesce(element.text, () => ( element.url)),
8215
8317
  mention: ({ element, user }) => {
8216
- return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _188 => _188.name]), () => ( element.id))}`;
8318
+ return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _190 => _190.name]), () => ( element.id))}`;
8217
8319
  }
8218
8320
  };
8219
8321
  var stringifyCommentBodyHtmlElements = {
@@ -8243,7 +8345,7 @@ var stringifyCommentBodyHtmlElements = {
8243
8345
  return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${_nullishCoalesce(element.text, () => ( element.url))}</a>`;
8244
8346
  },
8245
8347
  mention: ({ element, user }) => {
8246
- return html`<span data-mention>@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _189 => _189.name]), () => ( element.id))}</span>`;
8348
+ return html`<span data-mention>@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _191 => _191.name]), () => ( element.id))}</span>`;
8247
8349
  }
8248
8350
  };
8249
8351
  var stringifyCommentBodyMarkdownElements = {
@@ -8273,19 +8375,19 @@ var stringifyCommentBodyMarkdownElements = {
8273
8375
  return markdown`[${_nullishCoalesce(element.text, () => ( element.url))}](${href})`;
8274
8376
  },
8275
8377
  mention: ({ element, user }) => {
8276
- return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _190 => _190.name]), () => ( element.id))}`;
8378
+ return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _192 => _192.name]), () => ( element.id))}`;
8277
8379
  }
8278
8380
  };
8279
8381
  async function stringifyCommentBody(body, options) {
8280
- const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _191 => _191.format]), () => ( "plain"));
8281
- const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _192 => _192.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
8382
+ const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _193 => _193.format]), () => ( "plain"));
8383
+ const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _194 => _194.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
8282
8384
  const elements = {
8283
8385
  ...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
8284
- ..._optionalChain([options, 'optionalAccess', _193 => _193.elements])
8386
+ ..._optionalChain([options, 'optionalAccess', _195 => _195.elements])
8285
8387
  };
8286
8388
  const resolvedUsers = await resolveUsersInCommentBody(
8287
8389
  body,
8288
- _optionalChain([options, 'optionalAccess', _194 => _194.resolveUsers])
8390
+ _optionalChain([options, 'optionalAccess', _196 => _196.resolveUsers])
8289
8391
  );
8290
8392
  const blocks = body.content.flatMap((block, blockIndex) => {
8291
8393
  switch (block.type) {
@@ -8576,12 +8678,12 @@ function legacy_patchImmutableNode(state, path, update) {
8576
8678
  }
8577
8679
  const newState = Object.assign({}, state);
8578
8680
  for (const key in update.updates) {
8579
- if (_optionalChain([update, 'access', _195 => _195.updates, 'access', _196 => _196[key], 'optionalAccess', _197 => _197.type]) === "update") {
8681
+ if (_optionalChain([update, 'access', _197 => _197.updates, 'access', _198 => _198[key], 'optionalAccess', _199 => _199.type]) === "update") {
8580
8682
  const val = update.node.get(key);
8581
8683
  if (val !== void 0) {
8582
8684
  newState[key] = lsonToJson(val);
8583
8685
  }
8584
- } else if (_optionalChain([update, 'access', _198 => _198.updates, 'access', _199 => _199[key], 'optionalAccess', _200 => _200.type]) === "delete") {
8686
+ } else if (_optionalChain([update, 'access', _200 => _200.updates, 'access', _201 => _201[key], 'optionalAccess', _202 => _202.type]) === "delete") {
8585
8687
  delete newState[key];
8586
8688
  }
8587
8689
  }
@@ -8642,12 +8744,12 @@ function legacy_patchImmutableNode(state, path, update) {
8642
8744
  }
8643
8745
  const newState = Object.assign({}, state);
8644
8746
  for (const key in update.updates) {
8645
- if (_optionalChain([update, 'access', _201 => _201.updates, 'access', _202 => _202[key], 'optionalAccess', _203 => _203.type]) === "update") {
8747
+ if (_optionalChain([update, 'access', _203 => _203.updates, 'access', _204 => _204[key], 'optionalAccess', _205 => _205.type]) === "update") {
8646
8748
  const value = update.node.get(key);
8647
8749
  if (value !== void 0) {
8648
8750
  newState[key] = lsonToJson(value);
8649
8751
  }
8650
- } else if (_optionalChain([update, 'access', _204 => _204.updates, 'access', _205 => _205[key], 'optionalAccess', _206 => _206.type]) === "delete") {
8752
+ } else if (_optionalChain([update, 'access', _206 => _206.updates, 'access', _207 => _207[key], 'optionalAccess', _208 => _208.type]) === "delete") {
8651
8753
  delete newState[key];
8652
8754
  }
8653
8755
  }
@@ -8718,9 +8820,9 @@ function makePoller(callback, intervalMs, options) {
8718
8820
  const startTime = performance.now();
8719
8821
  const doc = typeof document !== "undefined" ? document : void 0;
8720
8822
  const win = typeof window !== "undefined" ? window : void 0;
8721
- const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _207 => _207.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
8823
+ const maxStaleTimeMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _209 => _209.maxStaleTimeMs]), () => ( Number.POSITIVE_INFINITY));
8722
8824
  const context = {
8723
- inForeground: _optionalChain([doc, 'optionalAccess', _208 => _208.visibilityState]) !== "hidden",
8825
+ inForeground: _optionalChain([doc, 'optionalAccess', _210 => _210.visibilityState]) !== "hidden",
8724
8826
  lastSuccessfulPollAt: startTime,
8725
8827
  count: 0,
8726
8828
  backoff: 0
@@ -8798,10 +8900,11 @@ function makePoller(callback, intervalMs, options) {
8798
8900
  pollNowIfStale();
8799
8901
  }
8800
8902
  function onVisibilityChange() {
8801
- setInForeground(_optionalChain([doc, 'optionalAccess', _209 => _209.visibilityState]) !== "hidden");
8903
+ setInForeground(_optionalChain([doc, 'optionalAccess', _211 => _211.visibilityState]) !== "hidden");
8802
8904
  }
8803
- _optionalChain([doc, 'optionalAccess', _210 => _210.addEventListener, 'call', _211 => _211("visibilitychange", onVisibilityChange)]);
8804
- _optionalChain([win, 'optionalAccess', _212 => _212.addEventListener, 'call', _213 => _213("online", onVisibilityChange)]);
8905
+ _optionalChain([doc, 'optionalAccess', _212 => _212.addEventListener, 'call', _213 => _213("visibilitychange", onVisibilityChange)]);
8906
+ _optionalChain([win, 'optionalAccess', _214 => _214.addEventListener, 'call', _215 => _215("online", onVisibilityChange)]);
8907
+ _optionalChain([win, 'optionalAccess', _216 => _216.addEventListener, 'call', _217 => _217("focus", pollNowIfStale)]);
8805
8908
  fsm.start();
8806
8909
  return {
8807
8910
  inc,
@@ -8923,9 +9026,9 @@ var SortedList = class _SortedList {
8923
9026
  }
8924
9027
  };
8925
9028
 
8926
- // src/protocol/ChannelsNotificationSettings.ts
8927
- function isChannelNotificationSettingEnabled(setting) {
8928
- return values(setting).every((enabled) => enabled === true);
9029
+ // src/protocol/UserNotificationSettings.ts
9030
+ function isNotificationChannelEnabled(settings) {
9031
+ return values(settings).every((enabled) => enabled === true);
8929
9032
  }
8930
9033
 
8931
9034
  // src/types/Others.ts
@@ -9028,5 +9131,5 @@ var NotificationsApiError = HttpError;
9028
9131
 
9029
9132
 
9030
9133
 
9031
- exports.ClientMsgCode = ClientMsgCode; exports.CommentsApiError = CommentsApiError; exports.CrdtType = CrdtType; exports.DefaultMap = DefaultMap; exports.DerivedSignal = DerivedSignal; exports.HttpError = HttpError; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.MutableSignal = MutableSignal; exports.NotificationsApiError = NotificationsApiError; exports.OpCode = OpCode; exports.Permission = Permission; exports.Promise_withResolvers = Promise_withResolvers; exports.ServerMsgCode = ServerMsgCode; exports.Signal = Signal; exports.SortedList = SortedList; exports.TextEditorType = TextEditorType; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.ackOp = ackOp; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.autoRetry = autoRetry; exports.b64decode = b64decode; exports.batch = batch; exports.chunk = chunk; exports.cloneLson = cloneLson; exports.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToThreadData = convertToThreadData; exports.createClient = createClient; exports.createCommentAttachmentId = createCommentAttachmentId; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createThreadId = createThreadId; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.entries = entries; exports.errorIf = errorIf; exports.freeze = freeze; exports.generateCommentUrl = generateCommentUrl; exports.getMentionedIdsFromCommentBody = getMentionedIdsFromCommentBody; exports.html = html; exports.htmlSafe = htmlSafe; exports.isChannelNotificationSettingEnabled = isChannelNotificationSettingEnabled; exports.isChildCrdt = isChildCrdt; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.isStartsWithOperator = isStartsWithOperator; exports.kInternal = kInternal; exports.keys = keys; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.mapValues = mapValues; exports.memoizeOnSuccess = memoizeOnSuccess; exports.nanoid = nanoid; exports.nn = nn; exports.objectToQuery = objectToQuery; exports.patchLiveObjectKey = patchLiveObjectKey; exports.raise = raise; exports.resolveUsersInCommentBody = resolveUsersInCommentBody; exports.shallow = shallow; exports.stringify = stringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toAbsoluteUrl = toAbsoluteUrl; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.unstringify = unstringify; exports.url = url; exports.urljoin = urljoin; exports.wait = wait; exports.withTimeout = withTimeout;
9134
+ exports.ClientMsgCode = ClientMsgCode; exports.CommentsApiError = CommentsApiError; exports.CrdtType = CrdtType; exports.DefaultMap = DefaultMap; exports.DerivedSignal = DerivedSignal; exports.HttpError = HttpError; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.LiveblocksError = LiveblocksError; exports.MutableSignal = MutableSignal; exports.NotificationsApiError = NotificationsApiError; exports.OpCode = OpCode; exports.Permission = Permission; exports.Promise_withResolvers = Promise_withResolvers; exports.ServerMsgCode = ServerMsgCode; exports.Signal = Signal; exports.SortedList = SortedList; exports.TextEditorType = TextEditorType; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.ackOp = ackOp; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.autoRetry = autoRetry; exports.b64decode = b64decode; exports.batch = batch; exports.chunk = chunk; exports.cloneLson = cloneLson; exports.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToThreadData = convertToThreadData; exports.createClient = createClient; exports.createCommentAttachmentId = createCommentAttachmentId; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createThreadId = createThreadId; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.entries = entries; exports.errorIf = errorIf; exports.freeze = freeze; exports.generateCommentUrl = generateCommentUrl; exports.getMentionedIdsFromCommentBody = getMentionedIdsFromCommentBody; exports.html = html; exports.htmlSafe = htmlSafe; exports.isChildCrdt = isChildCrdt; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isNotificationChannelEnabled = isNotificationChannelEnabled; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.isStartsWithOperator = isStartsWithOperator; exports.kInternal = kInternal; exports.keys = keys; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.mapValues = mapValues; exports.memoizeOnSuccess = memoizeOnSuccess; exports.nanoid = nanoid; exports.nn = nn; exports.objectToQuery = objectToQuery; exports.patchLiveObjectKey = patchLiveObjectKey; exports.raise = raise; exports.resolveUsersInCommentBody = resolveUsersInCommentBody; exports.shallow = shallow; exports.stringify = stringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toAbsoluteUrl = toAbsoluteUrl; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.url = url; exports.urljoin = urljoin; exports.wait = wait; exports.withTimeout = withTimeout;
9032
9135
  //# sourceMappingURL=index.js.map