@zean-chat/react-native 0.1.16 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
7
  var __export = (target, all) => {
7
8
  for (var name in all)
8
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,6 +17,7 @@ var __copyProps = (to, from, except, desc) => {
16
17
  return to;
17
18
  };
18
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
19
21
 
20
22
  // src/index.ts
21
23
  var index_exports = {};
@@ -28,7 +30,7 @@ __export(index_exports, {
28
30
  module.exports = __toCommonJS(index_exports);
29
31
 
30
32
  // src/components/ZeanChat.tsx
31
- var import_react18 = require("react");
33
+ var import_react19 = require("react");
32
34
 
33
35
  // ../shared/src/constants/app.ts
34
36
  var APP_NAME = "Zean";
@@ -79,6 +81,7 @@ var QUOTE_HIGHLIGHT_MS = 1600;
79
81
  var APP_PLATFORMS = ["web", "react_native"];
80
82
  var DEVICE_TYPES = ["phone", "tablet", "computer"];
81
83
  var DEVICE_DETAIL_MAX_LENGTH = 80;
84
+ var SDK_ERROR_MAX_LENGTH = { label: 64, message: 500, stack: 8e3 };
82
85
  var EXPO_GO_BUNDLE_ID = "host.exp.exponent";
83
86
  var DEFAULT_WIDGET_TEXTS = {
84
87
  fr: {
@@ -219,6 +222,22 @@ function minutesOf(clock) {
219
222
  const [hours, minutes] = clock.split(":").map(Number);
220
223
  return hours * 60 + minutes;
221
224
  }
225
+ function deviceStorageKey(appKey) {
226
+ return `zean:${appKey}:device`;
227
+ }
228
+ function sdkErrorReportOf(body) {
229
+ if (typeof body !== "object" || body === null) return null;
230
+ const { appKey, sdk, version: version2, os, method, name, message, stack } = body;
231
+ const labels = { appKey, sdk, version: version2, os, method, name };
232
+ if (Object.values(labels).some((value) => typeof value !== "string" || value === "")) return null;
233
+ if (typeof message !== "string" || stack !== void 0 && typeof stack !== "string") return null;
234
+ const cut = (value, max) => value.slice(0, max);
235
+ return {
236
+ ...Object.fromEntries(Object.entries(labels).map(([key, value]) => [key, cut(value, SDK_ERROR_MAX_LENGTH.label)])),
237
+ message: cut(message, SDK_ERROR_MAX_LENGTH.message),
238
+ ...stack ? { stack: cut(stack, SDK_ERROR_MAX_LENGTH.stack) } : {}
239
+ };
240
+ }
222
241
 
223
242
  // ../sdk-core/src/chat.ts
224
243
  var CLOCK_MS = 3e4;
@@ -234,8 +253,24 @@ var QUIET_CALLS = /* @__PURE__ */ new Set(["start", "reportInstall", "setTyping"
234
253
  function emailKey(offer) {
235
254
  return `${offer.kind}:${offer.email}`;
236
255
  }
256
+ function placeShowsApp(place) {
257
+ return place.app !== void 0;
258
+ }
259
+ function joinedSession(place, own) {
260
+ if (!placeShowsApp(place)) return place;
261
+ if (own.state === "not_found") return own;
262
+ const blocked = own.state === "blocked";
263
+ return {
264
+ state: place.state === "unavailable" ? "unavailable" : blocked ? "blocked" : "ready",
265
+ app: place.app,
266
+ contact: own.contact,
267
+ emailCode: place.state === "ready" && !blocked ? own.emailCode : null,
268
+ identity: own.identity,
269
+ report: place.report
270
+ };
271
+ }
237
272
  function createChatStore(backend, options) {
238
- const secretKey = `zean:${options.appKey}:device`;
273
+ const secretKey = deviceStorageKey(options.appKey);
239
274
  const outboxKey = `zean:${options.appKey}:outbox`;
240
275
  const attributesKey = `zean:${options.appKey}:attributes`;
241
276
  const keptKey = `zean:${options.appKey}:conversation`;
@@ -310,6 +345,8 @@ function createChatStore(backend, options) {
310
345
  ...options.deviceDetails ? { details: options.deviceDetails() } : {},
311
346
  timeZone
312
347
  });
348
+ let fingerprinted;
349
+ const fingerprint = (read) => fingerprinted ?? (fingerprinted = Promise.resolve().then(read).catch(() => null));
313
350
  const deviceWaiters = [];
314
351
  const useSecret = (secret) => {
315
352
  deviceSecret = secret;
@@ -348,30 +385,50 @@ function createChatStore(backend, options) {
348
385
  sessionWatch?.stop();
349
386
  const live = sessionLive();
350
387
  let stopped = false;
351
- let stop = null;
388
+ const watches = [];
352
389
  const entry = {
353
390
  live,
354
391
  // Once: the Convex client throws on a second unsubscribe.
355
392
  stop: () => {
356
393
  if (stopped) return;
357
394
  stopped = true;
358
- stop?.();
395
+ for (const stop of watches.splice(0)) stop();
359
396
  }
360
397
  };
361
398
  sessionWatch = entry;
362
- stop = backend.watch(
363
- "session",
364
- args(),
399
+ let place = null;
400
+ let own = null;
401
+ const handle = () => {
402
+ if (!place || !own) return;
403
+ handleSession(joinedSession(place, own));
404
+ if (!live && sessionWatch === entry) entry.stop();
405
+ };
406
+ const handleError = () => {
407
+ failedToLoad = true;
408
+ emit2();
409
+ };
410
+ const { deviceSecret: secret, ...where } = args();
411
+ const placeStop = backend.watch(
412
+ "place",
413
+ where,
365
414
  (result) => {
366
- handleSession(result);
367
- if (!live && sessionWatch === entry) entry.stop();
415
+ place = result;
416
+ handle();
368
417
  },
369
- () => {
370
- failedToLoad = true;
371
- emit2();
372
- }
418
+ handleError
373
419
  );
374
- if (stopped) stop();
420
+ watches.push(placeStop);
421
+ const deviceStop = backend.watch(
422
+ "device",
423
+ { ...where, deviceSecret: secret },
424
+ (result) => {
425
+ own = result;
426
+ handle();
427
+ },
428
+ handleError
429
+ );
430
+ if (stopped) deviceStop();
431
+ else watches.push(deviceStop);
375
432
  }
376
433
  function updateSessionLive() {
377
434
  if (!sessionWatch || sessionWatch.live === sessionLive()) return;
@@ -553,13 +610,16 @@ function createChatStore(backend, options) {
553
610
  );
554
611
  }
555
612
  function deliver(entry) {
556
- call("send", {
613
+ const input = {
557
614
  ...args(),
558
615
  body: entry.body,
559
616
  ...entry.attachments ? { attachments: entry.attachments } : {},
560
617
  clientId: entry.clientId,
561
618
  device: device()
562
- }).then(
619
+ };
620
+ const read = session && "app" in session && session.app.sendsFingerprint ? options.fingerprint : void 0;
621
+ const sent = read ? fingerprint(read).then((print) => call("send", print ? { ...input, fingerprint: print } : input)) : call("send", input);
622
+ sent.then(
563
623
  () => {
564
624
  outbox = outbox.filter((other) => other.clientId !== entry.clientId);
565
625
  saveOutbox();
@@ -1570,8 +1630,8 @@ function convexToJson(value) {
1570
1630
 
1571
1631
  // ../../node_modules/convex/dist/esm/values/validators.js
1572
1632
  var __defProp2 = Object.defineProperty;
1573
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1574
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1633
+ var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1634
+ var __publicField2 = (obj, key, value) => __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
1575
1635
  var UNDEFINED_VALIDATOR_ERROR_URL = "https://docs.convex.dev/error#undefined-validator";
1576
1636
  function throwUndefinedValidatorError(context, fieldName) {
1577
1637
  const fieldInfo = fieldName !== void 0 ? ` for field "${fieldName}"` : "";
@@ -1581,10 +1641,10 @@ function throwUndefinedValidatorError(context, fieldName) {
1581
1641
  }
1582
1642
  var BaseValidator = class {
1583
1643
  constructor({ isOptional }) {
1584
- __publicField(this, "type");
1585
- __publicField(this, "fieldPaths");
1586
- __publicField(this, "isOptional");
1587
- __publicField(this, "isConvexValidator");
1644
+ __publicField2(this, "type");
1645
+ __publicField2(this, "fieldPaths");
1646
+ __publicField2(this, "isOptional");
1647
+ __publicField2(this, "isConvexValidator");
1588
1648
  this.isOptional = isOptional;
1589
1649
  this.isConvexValidator = true;
1590
1650
  }
@@ -1598,8 +1658,8 @@ var VId = class _VId extends BaseValidator {
1598
1658
  tableName
1599
1659
  }) {
1600
1660
  super({ isOptional });
1601
- __publicField(this, "tableName");
1602
- __publicField(this, "kind", "id");
1661
+ __publicField2(this, "tableName");
1662
+ __publicField2(this, "kind", "id");
1603
1663
  if (typeof tableName !== "string") {
1604
1664
  throw new Error("v.id(tableName) requires a string");
1605
1665
  }
@@ -1624,7 +1684,7 @@ var VId = class _VId extends BaseValidator {
1624
1684
  var VFloat64 = class _VFloat64 extends BaseValidator {
1625
1685
  constructor() {
1626
1686
  super(...arguments);
1627
- __publicField(this, "kind", "float64");
1687
+ __publicField2(this, "kind", "float64");
1628
1688
  }
1629
1689
  /** @internal */
1630
1690
  get json() {
@@ -1644,7 +1704,7 @@ var VFloat64 = class _VFloat64 extends BaseValidator {
1644
1704
  var VInt64 = class _VInt64 extends BaseValidator {
1645
1705
  constructor() {
1646
1706
  super(...arguments);
1647
- __publicField(this, "kind", "int64");
1707
+ __publicField2(this, "kind", "int64");
1648
1708
  }
1649
1709
  /** @internal */
1650
1710
  get json() {
@@ -1662,7 +1722,7 @@ var VInt64 = class _VInt64 extends BaseValidator {
1662
1722
  var VCommitTs = class _VCommitTs extends BaseValidator {
1663
1723
  constructor() {
1664
1724
  super(...arguments);
1665
- __publicField(this, "kind", "commitTs");
1725
+ __publicField2(this, "kind", "commitTs");
1666
1726
  }
1667
1727
  /** @internal */
1668
1728
  get json() {
@@ -1682,7 +1742,7 @@ var VCommitTs = class _VCommitTs extends BaseValidator {
1682
1742
  var VBoolean = class _VBoolean extends BaseValidator {
1683
1743
  constructor() {
1684
1744
  super(...arguments);
1685
- __publicField(this, "kind", "boolean");
1745
+ __publicField2(this, "kind", "boolean");
1686
1746
  }
1687
1747
  /** @internal */
1688
1748
  get json() {
@@ -1702,7 +1762,7 @@ var VBoolean = class _VBoolean extends BaseValidator {
1702
1762
  var VBytes = class _VBytes extends BaseValidator {
1703
1763
  constructor() {
1704
1764
  super(...arguments);
1705
- __publicField(this, "kind", "bytes");
1765
+ __publicField2(this, "kind", "bytes");
1706
1766
  }
1707
1767
  /** @internal */
1708
1768
  get json() {
@@ -1720,7 +1780,7 @@ var VBytes = class _VBytes extends BaseValidator {
1720
1780
  var VString = class _VString extends BaseValidator {
1721
1781
  constructor() {
1722
1782
  super(...arguments);
1723
- __publicField(this, "kind", "string");
1783
+ __publicField2(this, "kind", "string");
1724
1784
  }
1725
1785
  /** @internal */
1726
1786
  get json() {
@@ -1740,7 +1800,7 @@ var VString = class _VString extends BaseValidator {
1740
1800
  var VNull = class _VNull extends BaseValidator {
1741
1801
  constructor() {
1742
1802
  super(...arguments);
1743
- __publicField(this, "kind", "null");
1803
+ __publicField2(this, "kind", "null");
1744
1804
  }
1745
1805
  /** @internal */
1746
1806
  get json() {
@@ -1758,7 +1818,7 @@ var VNull = class _VNull extends BaseValidator {
1758
1818
  var VAny = class _VAny extends BaseValidator {
1759
1819
  constructor() {
1760
1820
  super(...arguments);
1761
- __publicField(this, "kind", "any");
1821
+ __publicField2(this, "kind", "any");
1762
1822
  }
1763
1823
  /** @internal */
1764
1824
  get json() {
@@ -1786,8 +1846,8 @@ var VObject = class _VObject extends BaseValidator {
1786
1846
  fields
1787
1847
  }) {
1788
1848
  super({ isOptional });
1789
- __publicField(this, "fields");
1790
- __publicField(this, "kind", "object");
1849
+ __publicField2(this, "fields");
1850
+ __publicField2(this, "kind", "object");
1791
1851
  globalThis.Object.entries(fields).forEach(([fieldName, validator]) => {
1792
1852
  if (validator === void 0) {
1793
1853
  throwUndefinedValidatorError("v.object()", fieldName);
@@ -1882,8 +1942,8 @@ var VLiteral = class _VLiteral extends BaseValidator {
1882
1942
  */
1883
1943
  constructor({ isOptional, value }) {
1884
1944
  super({ isOptional });
1885
- __publicField(this, "value");
1886
- __publicField(this, "kind", "literal");
1945
+ __publicField2(this, "value");
1946
+ __publicField2(this, "kind", "literal");
1887
1947
  if (typeof value !== "string" && typeof value !== "boolean" && typeof value !== "number" && typeof value !== "bigint") {
1888
1948
  throw new Error("v.literal(value) must be a string, number, or boolean");
1889
1949
  }
@@ -1917,8 +1977,8 @@ var VArray = class _VArray extends BaseValidator {
1917
1977
  element
1918
1978
  }) {
1919
1979
  super({ isOptional });
1920
- __publicField(this, "element");
1921
- __publicField(this, "kind", "array");
1980
+ __publicField2(this, "element");
1981
+ __publicField2(this, "kind", "array");
1922
1982
  if (element === void 0) {
1923
1983
  throwUndefinedValidatorError("v.array()");
1924
1984
  }
@@ -1953,9 +2013,9 @@ var VRecord = class _VRecord extends BaseValidator {
1953
2013
  value
1954
2014
  }) {
1955
2015
  super({ isOptional });
1956
- __publicField(this, "key");
1957
- __publicField(this, "value");
1958
- __publicField(this, "kind", "record");
2016
+ __publicField2(this, "key");
2017
+ __publicField2(this, "value");
2018
+ __publicField2(this, "kind", "record");
1959
2019
  if (key === void 0) {
1960
2020
  throwUndefinedValidatorError("v.record()", "key");
1961
2021
  }
@@ -2005,8 +2065,8 @@ var VUnion = class _VUnion extends BaseValidator {
2005
2065
  */
2006
2066
  constructor({ isOptional, members }) {
2007
2067
  super({ isOptional });
2008
- __publicField(this, "members");
2009
- __publicField(this, "kind", "union");
2068
+ __publicField2(this, "members");
2069
+ __publicField2(this, "kind", "union");
2010
2070
  members.forEach((member, index) => {
2011
2071
  if (member === void 0) {
2012
2072
  throwUndefinedValidatorError("v.union()", `member at index ${index}`);
@@ -2314,17 +2374,17 @@ var v = {
2314
2374
 
2315
2375
  // ../../node_modules/convex/dist/esm/values/errors.js
2316
2376
  var __defProp3 = Object.defineProperty;
2317
- var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2318
- var __publicField2 = (obj, key, value) => __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
2377
+ var __defNormalProp3 = (obj, key, value) => key in obj ? __defProp3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2378
+ var __publicField3 = (obj, key, value) => __defNormalProp3(obj, typeof key !== "symbol" ? key + "" : key, value);
2319
2379
  var _a;
2320
2380
  var _b;
2321
2381
  var IDENTIFYING_FIELD = Symbol.for("ConvexError");
2322
2382
  var ConvexError = class extends (_b = Error, _a = IDENTIFYING_FIELD, _b) {
2323
2383
  constructor(data) {
2324
2384
  super(typeof data === "string" ? data : stringifyValueForError(data));
2325
- __publicField2(this, "name", "ConvexError");
2326
- __publicField2(this, "data");
2327
- __publicField2(this, _a, true);
2385
+ __publicField3(this, "name", "ConvexError");
2386
+ __publicField3(this, "data");
2387
+ __publicField3(this, _a, true);
2328
2388
  this.data = data;
2329
2389
  }
2330
2390
  };
@@ -2336,8 +2396,8 @@ var bBytes = arr();
2336
2396
 
2337
2397
  // ../../node_modules/convex/dist/esm/browser/logging.js
2338
2398
  var __defProp4 = Object.defineProperty;
2339
- var __defNormalProp3 = (obj, key, value) => key in obj ? __defProp4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2340
- var __publicField3 = (obj, key, value) => __defNormalProp3(obj, typeof key !== "symbol" ? key + "" : key, value);
2399
+ var __defNormalProp4 = (obj, key, value) => key in obj ? __defProp4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2400
+ var __publicField4 = (obj, key, value) => __defNormalProp4(obj, typeof key !== "symbol" ? key + "" : key, value);
2341
2401
  var INFO_COLOR = "color:rgb(0, 145, 255)";
2342
2402
  function prefix_for_source(source) {
2343
2403
  switch (source) {
@@ -2353,8 +2413,8 @@ function prefix_for_source(source) {
2353
2413
  }
2354
2414
  var DefaultLogger = class {
2355
2415
  constructor(options) {
2356
- __publicField3(this, "_onLogLineFuncs");
2357
- __publicField3(this, "_verbose");
2416
+ __publicField4(this, "_onLogLineFuncs");
2417
+ __publicField4(this, "_verbose");
2358
2418
  this._onLogLineFuncs = {};
2359
2419
  this._verbose = options.verbose;
2360
2420
  }
@@ -2495,20 +2555,20 @@ function serializedQueryTokenIsPaginated(token) {
2495
2555
 
2496
2556
  // ../../node_modules/convex/dist/esm/browser/sync/local_state.js
2497
2557
  var __defProp5 = Object.defineProperty;
2498
- var __defNormalProp4 = (obj, key, value) => key in obj ? __defProp5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2499
- var __publicField4 = (obj, key, value) => __defNormalProp4(obj, typeof key !== "symbol" ? key + "" : key, value);
2558
+ var __defNormalProp5 = (obj, key, value) => key in obj ? __defProp5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2559
+ var __publicField5 = (obj, key, value) => __defNormalProp5(obj, typeof key !== "symbol" ? key + "" : key, value);
2500
2560
  var LocalSyncState = class {
2501
2561
  constructor() {
2502
- __publicField4(this, "nextQueryId");
2503
- __publicField4(this, "querySetVersion");
2504
- __publicField4(this, "querySet");
2505
- __publicField4(this, "queryIdToToken");
2506
- __publicField4(this, "identityVersion");
2507
- __publicField4(this, "auth");
2508
- __publicField4(this, "outstandingQueriesOlderThanRestart");
2509
- __publicField4(this, "outstandingAuthOlderThanRestart");
2510
- __publicField4(this, "paused");
2511
- __publicField4(this, "pendingQuerySetModifications");
2562
+ __publicField5(this, "nextQueryId");
2563
+ __publicField5(this, "querySetVersion");
2564
+ __publicField5(this, "querySet");
2565
+ __publicField5(this, "queryIdToToken");
2566
+ __publicField5(this, "identityVersion");
2567
+ __publicField5(this, "auth");
2568
+ __publicField5(this, "outstandingQueriesOlderThanRestart");
2569
+ __publicField5(this, "outstandingAuthOlderThanRestart");
2570
+ __publicField5(this, "paused");
2571
+ __publicField5(this, "pendingQuerySetModifications");
2512
2572
  this.nextQueryId = 0;
2513
2573
  this.querySetVersion = 0;
2514
2574
  this.identityVersion = 0;
@@ -2784,16 +2844,16 @@ var LocalSyncState = class {
2784
2844
 
2785
2845
  // ../../node_modules/convex/dist/esm/browser/sync/request_manager.js
2786
2846
  var __defProp6 = Object.defineProperty;
2787
- var __defNormalProp5 = (obj, key, value) => key in obj ? __defProp6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2788
- var __publicField5 = (obj, key, value) => __defNormalProp5(obj, typeof key !== "symbol" ? key + "" : key, value);
2847
+ var __defNormalProp6 = (obj, key, value) => key in obj ? __defProp6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2848
+ var __publicField6 = (obj, key, value) => __defNormalProp6(obj, typeof key !== "symbol" ? key + "" : key, value);
2789
2849
  var RequestManager = class {
2790
2850
  constructor(logger, markConnectionStateDirty) {
2791
2851
  this.logger = logger;
2792
2852
  this.markConnectionStateDirty = markConnectionStateDirty;
2793
- __publicField5(this, "inflightRequests");
2794
- __publicField5(this, "requestsOlderThanRestart");
2795
- __publicField5(this, "inflightMutationsCount", 0);
2796
- __publicField5(this, "inflightActionsCount", 0);
2853
+ __publicField6(this, "inflightRequests");
2854
+ __publicField6(this, "requestsOlderThanRestart");
2855
+ __publicField6(this, "inflightMutationsCount", 0);
2856
+ __publicField6(this, "inflightActionsCount", 0);
2797
2857
  this.inflightRequests = /* @__PURE__ */ new Map();
2798
2858
  this.requestsOlderThanRestart = /* @__PURE__ */ new Set();
2799
2859
  }
@@ -3077,12 +3137,12 @@ var anyApi = createApi();
3077
3137
 
3078
3138
  // ../../node_modules/convex/dist/esm/browser/sync/optimistic_updates_impl.js
3079
3139
  var __defProp7 = Object.defineProperty;
3080
- var __defNormalProp6 = (obj, key, value) => key in obj ? __defProp7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3081
- var __publicField6 = (obj, key, value) => __defNormalProp6(obj, typeof key !== "symbol" ? key + "" : key, value);
3140
+ var __defNormalProp7 = (obj, key, value) => key in obj ? __defProp7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3141
+ var __publicField7 = (obj, key, value) => __defNormalProp7(obj, typeof key !== "symbol" ? key + "" : key, value);
3082
3142
  var OptimisticLocalStoreImpl = class _OptimisticLocalStoreImpl {
3083
3143
  constructor(queryResults) {
3084
- __publicField6(this, "queryResults");
3085
- __publicField6(this, "modifiedQueries");
3144
+ __publicField7(this, "queryResults");
3145
+ __publicField7(this, "modifiedQueries");
3086
3146
  this.queryResults = queryResults;
3087
3147
  this.modifiedQueries = [];
3088
3148
  }
@@ -3145,8 +3205,8 @@ var OptimisticLocalStoreImpl = class _OptimisticLocalStoreImpl {
3145
3205
  };
3146
3206
  var OptimisticQueryResults = class {
3147
3207
  constructor() {
3148
- __publicField6(this, "queryResults");
3149
- __publicField6(this, "optimisticUpdates");
3208
+ __publicField7(this, "queryResults");
3209
+ __publicField7(this, "optimisticUpdates");
3150
3210
  this.queryResults = /* @__PURE__ */ new Map();
3151
3211
  this.optimisticUpdates = [];
3152
3212
  }
@@ -3232,13 +3292,13 @@ var OptimisticQueryResults = class {
3232
3292
 
3233
3293
  // ../../node_modules/convex/dist/esm/vendor/long.js
3234
3294
  var __defProp8 = Object.defineProperty;
3235
- var __defNormalProp7 = (obj, key, value) => key in obj ? __defProp8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3236
- var __publicField7 = (obj, key, value) => __defNormalProp7(obj, typeof key !== "symbol" ? key + "" : key, value);
3295
+ var __defNormalProp8 = (obj, key, value) => key in obj ? __defProp8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3296
+ var __publicField8 = (obj, key, value) => __defNormalProp8(obj, typeof key !== "symbol" ? key + "" : key, value);
3237
3297
  var Long = class _Long {
3238
3298
  constructor(low, high) {
3239
- __publicField7(this, "low");
3240
- __publicField7(this, "high");
3241
- __publicField7(this, "__isUnsignedLong__");
3299
+ __publicField8(this, "low");
3300
+ __publicField8(this, "high");
3301
+ __publicField8(this, "__isUnsignedLong__");
3242
3302
  this.low = low | 0;
3243
3303
  this.high = high | 0;
3244
3304
  this.__isUnsignedLong__ = true;
@@ -3309,14 +3369,14 @@ var MAX_UNSIGNED_VALUE = new Long(4294967295 | 0, 4294967295 | 0);
3309
3369
 
3310
3370
  // ../../node_modules/convex/dist/esm/browser/sync/remote_query_set.js
3311
3371
  var __defProp9 = Object.defineProperty;
3312
- var __defNormalProp8 = (obj, key, value) => key in obj ? __defProp9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3313
- var __publicField8 = (obj, key, value) => __defNormalProp8(obj, typeof key !== "symbol" ? key + "" : key, value);
3372
+ var __defNormalProp9 = (obj, key, value) => key in obj ? __defProp9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3373
+ var __publicField9 = (obj, key, value) => __defNormalProp9(obj, typeof key !== "symbol" ? key + "" : key, value);
3314
3374
  var RemoteQuerySet = class {
3315
3375
  constructor(queryPath, logger) {
3316
- __publicField8(this, "version");
3317
- __publicField8(this, "remoteQuerySet");
3318
- __publicField8(this, "queryPath");
3319
- __publicField8(this, "logger");
3376
+ __publicField9(this, "version");
3377
+ __publicField9(this, "remoteQuerySet");
3378
+ __publicField9(this, "queryPath");
3379
+ __publicField9(this, "logger");
3320
3380
  this.version = { querySet: 0, ts: Long.fromNumber(0), identity: 0 };
3321
3381
  this.remoteQuerySet = /* @__PURE__ */ new Map();
3322
3382
  this.queryPath = queryPath;
@@ -3454,8 +3514,8 @@ function encodeClientMessage(message) {
3454
3514
 
3455
3515
  // ../../node_modules/convex/dist/esm/browser/sync/web_socket_manager.js
3456
3516
  var __defProp10 = Object.defineProperty;
3457
- var __defNormalProp9 = (obj, key, value) => key in obj ? __defProp10(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3458
- var __publicField9 = (obj, key, value) => __defNormalProp9(obj, typeof key !== "symbol" ? key + "" : key, value);
3517
+ var __defNormalProp10 = (obj, key, value) => key in obj ? __defProp10(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3518
+ var __publicField10 = (obj, key, value) => __defNormalProp10(obj, typeof key !== "symbol" ? key + "" : key, value);
3459
3519
  var CLOSE_NORMAL = 1e3;
3460
3520
  var CLOSE_GOING_AWAY = 1001;
3461
3521
  var CLOSE_NO_STATUS = 1005;
@@ -3508,26 +3568,26 @@ var WebSocketManager = class {
3508
3568
  constructor(uri, callbacks, webSocketConstructor, logger, markConnectionStateDirty, debug) {
3509
3569
  this.markConnectionStateDirty = markConnectionStateDirty;
3510
3570
  this.debug = debug;
3511
- __publicField9(this, "socket");
3512
- __publicField9(this, "connectionCount");
3513
- __publicField9(this, "_hasEverConnected", false);
3514
- __publicField9(this, "lastCloseReason");
3515
- __publicField9(this, "transitionChunkBuffer", null);
3516
- __publicField9(this, "defaultInitialBackoff");
3517
- __publicField9(this, "maxBackoff");
3518
- __publicField9(this, "retries");
3519
- __publicField9(this, "serverInactivityThreshold");
3520
- __publicField9(this, "reconnectDueToServerInactivityTimeout");
3521
- __publicField9(this, "scheduledReconnect", null);
3522
- __publicField9(this, "networkOnlineHandler", null);
3523
- __publicField9(this, "pendingNetworkRecoveryInfo", null);
3524
- __publicField9(this, "uri");
3525
- __publicField9(this, "onOpen");
3526
- __publicField9(this, "onResume");
3527
- __publicField9(this, "onMessage");
3528
- __publicField9(this, "webSocketConstructor");
3529
- __publicField9(this, "logger");
3530
- __publicField9(this, "onServerDisconnectError");
3571
+ __publicField10(this, "socket");
3572
+ __publicField10(this, "connectionCount");
3573
+ __publicField10(this, "_hasEverConnected", false);
3574
+ __publicField10(this, "lastCloseReason");
3575
+ __publicField10(this, "transitionChunkBuffer", null);
3576
+ __publicField10(this, "defaultInitialBackoff");
3577
+ __publicField10(this, "maxBackoff");
3578
+ __publicField10(this, "retries");
3579
+ __publicField10(this, "serverInactivityThreshold");
3580
+ __publicField10(this, "reconnectDueToServerInactivityTimeout");
3581
+ __publicField10(this, "scheduledReconnect", null);
3582
+ __publicField10(this, "networkOnlineHandler", null);
3583
+ __publicField10(this, "pendingNetworkRecoveryInfo", null);
3584
+ __publicField10(this, "uri");
3585
+ __publicField10(this, "onOpen");
3586
+ __publicField10(this, "onResume");
3587
+ __publicField10(this, "onMessage");
3588
+ __publicField10(this, "webSocketConstructor");
3589
+ __publicField10(this, "logger");
3590
+ __publicField10(this, "onServerDisconnectError");
3531
3591
  this.webSocketConstructor = webSocketConstructor;
3532
3592
  this.socket = { state: "disconnected" };
3533
3593
  this.connectionCount = 0;
@@ -4169,26 +4229,26 @@ function jwtDecode(token, options) {
4169
4229
 
4170
4230
  // ../../node_modules/convex/dist/esm/browser/sync/authentication_manager.js
4171
4231
  var __defProp11 = Object.defineProperty;
4172
- var __defNormalProp10 = (obj, key, value) => key in obj ? __defProp11(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4173
- var __publicField10 = (obj, key, value) => __defNormalProp10(obj, typeof key !== "symbol" ? key + "" : key, value);
4232
+ var __defNormalProp11 = (obj, key, value) => key in obj ? __defProp11(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4233
+ var __publicField11 = (obj, key, value) => __defNormalProp11(obj, typeof key !== "symbol" ? key + "" : key, value);
4174
4234
  var MAXIMUM_REFRESH_DELAY = 20 * 24 * 60 * 60 * 1e3;
4175
4235
  var MAX_TOKEN_CONFIRMATION_ATTEMPTS = 2;
4176
4236
  var AuthenticationManager = class {
4177
4237
  constructor(syncState, callbacks, config) {
4178
- __publicField10(this, "authState", { state: "noAuth" });
4179
- __publicField10(this, "configVersion", 0);
4180
- __publicField10(this, "syncState");
4181
- __publicField10(this, "authenticate");
4182
- __publicField10(this, "stopSocket");
4183
- __publicField10(this, "tryRestartSocket");
4184
- __publicField10(this, "pauseSocket");
4185
- __publicField10(this, "resumeSocket");
4186
- __publicField10(this, "clearAuth");
4187
- __publicField10(this, "logger");
4188
- __publicField10(this, "refreshTokenLeewaySeconds");
4189
- __publicField10(this, "initialAuthTokenReuse");
4190
- __publicField10(this, "lastRefreshChange");
4191
- __publicField10(this, "tokenConfirmationAttempts", 0);
4238
+ __publicField11(this, "authState", { state: "noAuth" });
4239
+ __publicField11(this, "configVersion", 0);
4240
+ __publicField11(this, "syncState");
4241
+ __publicField11(this, "authenticate");
4242
+ __publicField11(this, "stopSocket");
4243
+ __publicField11(this, "tryRestartSocket");
4244
+ __publicField11(this, "pauseSocket");
4245
+ __publicField11(this, "resumeSocket");
4246
+ __publicField11(this, "clearAuth");
4247
+ __publicField11(this, "logger");
4248
+ __publicField11(this, "refreshTokenLeewaySeconds");
4249
+ __publicField11(this, "initialAuthTokenReuse");
4250
+ __publicField11(this, "lastRefreshChange");
4251
+ __publicField11(this, "tokenConfirmationAttempts", 0);
4192
4252
  this.syncState = syncState;
4193
4253
  this.authenticate = callbacks.authenticate;
4194
4254
  this.stopSocket = callbacks.stopSocket;
@@ -4556,8 +4616,8 @@ function getMarksReport(sessionId) {
4556
4616
 
4557
4617
  // ../../node_modules/convex/dist/esm/browser/sync/client.js
4558
4618
  var __defProp12 = Object.defineProperty;
4559
- var __defNormalProp11 = (obj, key, value) => key in obj ? __defProp12(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4560
- var __publicField11 = (obj, key, value) => __defNormalProp11(obj, typeof key !== "symbol" ? key + "" : key, value);
4619
+ var __defNormalProp12 = (obj, key, value) => key in obj ? __defProp12(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4620
+ var __publicField12 = (obj, key, value) => __defNormalProp12(obj, typeof key !== "symbol" ? key + "" : key, value);
4561
4621
  var BaseConvexClient = class {
4562
4622
  /**
4563
4623
  * @param address - The url of your Convex deployment, often provided
@@ -4568,25 +4628,25 @@ var BaseConvexClient = class {
4568
4628
  * @param options - See {@link BaseConvexClientOptions} for a full description.
4569
4629
  */
4570
4630
  constructor(address, onTransition, options) {
4571
- __publicField11(this, "address");
4572
- __publicField11(this, "state");
4573
- __publicField11(this, "requestManager");
4574
- __publicField11(this, "webSocketManager");
4575
- __publicField11(this, "authenticationManager");
4576
- __publicField11(this, "remoteQuerySet");
4577
- __publicField11(this, "optimisticQueryResults");
4578
- __publicField11(this, "_transitionHandlerCounter", 0);
4579
- __publicField11(this, "_nextRequestId");
4580
- __publicField11(this, "_onTransitionFns", /* @__PURE__ */ new Map());
4581
- __publicField11(this, "_sessionId");
4582
- __publicField11(this, "firstMessageReceived", false);
4583
- __publicField11(this, "debug");
4584
- __publicField11(this, "logger");
4585
- __publicField11(this, "maxObservedTimestamp");
4586
- __publicField11(this, "connectionStateSubscribers", /* @__PURE__ */ new Map());
4587
- __publicField11(this, "nextConnectionStateSubscriberId", 0);
4588
- __publicField11(this, "_lastPublishedConnectionState");
4589
- __publicField11(this, "markConnectionStateDirty", () => {
4631
+ __publicField12(this, "address");
4632
+ __publicField12(this, "state");
4633
+ __publicField12(this, "requestManager");
4634
+ __publicField12(this, "webSocketManager");
4635
+ __publicField12(this, "authenticationManager");
4636
+ __publicField12(this, "remoteQuerySet");
4637
+ __publicField12(this, "optimisticQueryResults");
4638
+ __publicField12(this, "_transitionHandlerCounter", 0);
4639
+ __publicField12(this, "_nextRequestId");
4640
+ __publicField12(this, "_onTransitionFns", /* @__PURE__ */ new Map());
4641
+ __publicField12(this, "_sessionId");
4642
+ __publicField12(this, "firstMessageReceived", false);
4643
+ __publicField12(this, "debug");
4644
+ __publicField12(this, "logger");
4645
+ __publicField12(this, "maxObservedTimestamp");
4646
+ __publicField12(this, "connectionStateSubscribers", /* @__PURE__ */ new Map());
4647
+ __publicField12(this, "nextConnectionStateSubscriberId", 0);
4648
+ __publicField12(this, "_lastPublishedConnectionState");
4649
+ __publicField12(this, "markConnectionStateDirty", () => {
4590
4650
  void Promise.resolve().then(() => {
4591
4651
  const curConnectionState = this.connectionState();
4592
4652
  if (JSON.stringify(curConnectionState) !== JSON.stringify(this._lastPublishedConnectionState)) {
@@ -4597,7 +4657,7 @@ var BaseConvexClient = class {
4597
4657
  }
4598
4658
  });
4599
4659
  });
4600
- __publicField11(this, "mark", (name) => {
4660
+ __publicField12(this, "mark", (name) => {
4601
4661
  if (this.debug) {
4602
4662
  mark(name, this.sessionId);
4603
4663
  }
@@ -5274,14 +5334,14 @@ function asPaginationResult(value) {
5274
5334
 
5275
5335
  // ../../node_modules/convex/dist/esm/browser/sync/paginated_query_client.js
5276
5336
  var __defProp13 = Object.defineProperty;
5277
- var __defNormalProp12 = (obj, key, value) => key in obj ? __defProp13(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5278
- var __publicField12 = (obj, key, value) => __defNormalProp12(obj, typeof key !== "symbol" ? key + "" : key, value);
5337
+ var __defNormalProp13 = (obj, key, value) => key in obj ? __defProp13(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5338
+ var __publicField13 = (obj, key, value) => __defNormalProp13(obj, typeof key !== "symbol" ? key + "" : key, value);
5279
5339
  var PaginatedQueryClient = class {
5280
5340
  constructor(client, onTransition) {
5281
5341
  this.client = client;
5282
5342
  this.onTransition = onTransition;
5283
- __publicField12(this, "paginatedQuerySet", /* @__PURE__ */ new Map());
5284
- __publicField12(this, "lastTransitionTs");
5343
+ __publicField13(this, "paginatedQuerySet", /* @__PURE__ */ new Map());
5344
+ __publicField13(this, "lastTransitionTs");
5285
5345
  this.lastTransitionTs = Long.fromNumber(0);
5286
5346
  this.client.addOnTransitionHandler(
5287
5347
  (transition) => this.onBaseTransition(transition)
@@ -5641,8 +5701,8 @@ var PaginatedQueryClient = class {
5641
5701
 
5642
5702
  // ../../node_modules/convex/dist/esm/browser/simple_client.js
5643
5703
  var __defProp14 = Object.defineProperty;
5644
- var __defNormalProp13 = (obj, key, value) => key in obj ? __defProp14(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5645
- var __publicField13 = (obj, key, value) => __defNormalProp13(obj, typeof key !== "symbol" ? key + "" : key, value);
5704
+ var __defNormalProp14 = (obj, key, value) => key in obj ? __defProp14(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5705
+ var __publicField14 = (obj, key, value) => __defNormalProp14(obj, typeof key !== "symbol" ? key + "" : key, value);
5646
5706
  var defaultWebSocketConstructor;
5647
5707
  var ConvexClient = class {
5648
5708
  /**
@@ -5651,12 +5711,12 @@ var ConvexClient = class {
5651
5711
  * @public
5652
5712
  */
5653
5713
  constructor(address, options = {}) {
5654
- __publicField13(this, "listeners");
5655
- __publicField13(this, "_client");
5656
- __publicField13(this, "_paginatedClient");
5657
- __publicField13(this, "callNewListenersWithCurrentValuesTimer");
5658
- __publicField13(this, "_closed");
5659
- __publicField13(this, "_disabled");
5714
+ __publicField14(this, "listeners");
5715
+ __publicField14(this, "_client");
5716
+ __publicField14(this, "_paginatedClient");
5717
+ __publicField14(this, "callNewListenersWithCurrentValuesTimer");
5718
+ __publicField14(this, "_closed");
5719
+ __publicField14(this, "_disabled");
5660
5720
  if (options.skipConvexDeploymentUrlCheck !== true) {
5661
5721
  validateDeploymentUrl(address);
5662
5722
  }
@@ -6079,21 +6139,21 @@ var varNames = {
6079
6139
 
6080
6140
  // ../../node_modules/convex/dist/esm/server/schema.js
6081
6141
  var __defProp15 = Object.defineProperty;
6082
- var __defNormalProp14 = (obj, key, value) => key in obj ? __defProp15(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6083
- var __publicField14 = (obj, key, value) => __defNormalProp14(obj, typeof key !== "symbol" ? key + "" : key, value);
6142
+ var __defNormalProp15 = (obj, key, value) => key in obj ? __defProp15(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6143
+ var __publicField15 = (obj, key, value) => __defNormalProp15(obj, typeof key !== "symbol" ? key + "" : key, value);
6084
6144
  var TableDefinition = class {
6085
6145
  /**
6086
6146
  * @internal
6087
6147
  */
6088
6148
  constructor(documentType) {
6089
- __publicField14(this, "indexes");
6090
- __publicField14(this, "stagedDbIndexes");
6091
- __publicField14(this, "searchIndexes");
6092
- __publicField14(this, "stagedSearchIndexes");
6093
- __publicField14(this, "vectorIndexes");
6094
- __publicField14(this, "stagedVectorIndexes");
6095
- __publicField14(this, "validator");
6096
- __publicField14(this, "stagedValidator");
6149
+ __publicField15(this, "indexes");
6150
+ __publicField15(this, "stagedDbIndexes");
6151
+ __publicField15(this, "searchIndexes");
6152
+ __publicField15(this, "stagedSearchIndexes");
6153
+ __publicField15(this, "vectorIndexes");
6154
+ __publicField15(this, "stagedVectorIndexes");
6155
+ __publicField15(this, "validator");
6156
+ __publicField15(this, "stagedValidator");
6097
6157
  this.indexes = [];
6098
6158
  this.stagedDbIndexes = [];
6099
6159
  this.searchIndexes = [];
@@ -6286,9 +6346,9 @@ var SchemaDefinition = class {
6286
6346
  * @internal
6287
6347
  */
6288
6348
  constructor(tables, options) {
6289
- __publicField14(this, "tables");
6290
- __publicField14(this, "strictTableNameTypes");
6291
- __publicField14(this, "schemaValidation");
6349
+ __publicField15(this, "tables");
6350
+ __publicField15(this, "strictTableNameTypes");
6351
+ __publicField15(this, "schemaValidation");
6292
6352
  this.tables = tables;
6293
6353
  this.schemaValidation = options?.schemaValidation === void 0 ? true : options.schemaValidation;
6294
6354
  }
@@ -6391,6 +6451,10 @@ function convexBackend(url) {
6391
6451
  const client = new ConvexClient(url, { unsavedChangesWarning: false });
6392
6452
  const queries = api.features.widget.queries;
6393
6453
  const mutations = api.features.widget.mutations;
6454
+ const post = async (path, report) => {
6455
+ const response = await fetch(`${url.replace(/\/$/, "")}/http/widget/${path}`, { method: "POST", body: JSON.stringify(report) });
6456
+ if (!response.ok) throw new Error(`The ${path} report failed: ${response.status}`);
6457
+ };
6394
6458
  return {
6395
6459
  watch: (name, args, onResult, onError) => (
6396
6460
  // One reference per name: the generic index cannot be narrowed further.
@@ -6406,13 +6470,9 @@ function convexBackend(url) {
6406
6470
  });
6407
6471
  },
6408
6472
  // A WebSocket hides the connection from Convex functions: a plain request to an HTTP action, through Cloudflare.
6409
- reportCountry: async (report) => {
6410
- const response = await fetch(`${url.replace(/\/$/, "")}/http/widget/country`, {
6411
- method: "POST",
6412
- body: JSON.stringify(report)
6413
- });
6414
- if (!response.ok) throw new Error(`Country report failed: ${response.status}`);
6415
- },
6473
+ reportCountry: (report) => post("country", report),
6474
+ // Plain too: it still goes when the connection is what broke.
6475
+ reportError: (report) => post("error", report),
6416
6476
  watchConnection: (onChange) => {
6417
6477
  onChange(client.connectionState().isWebSocketConnected);
6418
6478
  return client.subscribeToConnectionState((state) => onChange(state.isWebSocketConnected));
@@ -6426,6 +6486,64 @@ function withCode(error) {
6426
6486
  return Object.assign(error instanceof Error ? error : new Error(String(error)), { code: code2 });
6427
6487
  }
6428
6488
 
6489
+ // ../sdk-core/src/errors.ts
6490
+ var MAX_REPORTS = 5;
6491
+ function isRefusal(error) {
6492
+ return typeof error?.code === "string";
6493
+ }
6494
+ function errorReporter(backend, appKey, source) {
6495
+ const sent = /* @__PURE__ */ new Set();
6496
+ return (where, error) => {
6497
+ if (sent.size >= MAX_REPORTS || isRefusal(error)) return;
6498
+ const failure = error instanceof Error ? error : new Error(String(error));
6499
+ const kind = `${where}:${failure.name}:${failure.message}`;
6500
+ if (sent.has(kind)) return;
6501
+ sent.add(kind);
6502
+ const report = sdkErrorReportOf({
6503
+ appKey,
6504
+ ...source,
6505
+ method: where,
6506
+ name: failure.name || "Error",
6507
+ message: failure.message,
6508
+ stack: failure.stack
6509
+ });
6510
+ if (report) backend.reportError(report).catch(() => {
6511
+ });
6512
+ };
6513
+ }
6514
+ function reportingBackend(backend, report) {
6515
+ const guarded = (where, read) => (value) => {
6516
+ try {
6517
+ read(value);
6518
+ } catch (error) {
6519
+ report(where, error);
6520
+ }
6521
+ };
6522
+ return {
6523
+ ...backend,
6524
+ watch: (name, args, onResult, onError) => backend.watch(name, args, guarded(`watch:${name}`, onResult), onError),
6525
+ watchConnection: (onChange) => backend.watchConnection(guarded("watchConnection", onChange))
6526
+ };
6527
+ }
6528
+ function reportingChat(chat2, report) {
6529
+ const methods = Object.entries(chat2).map(([name, method]) => [
6530
+ name,
6531
+ (...args) => {
6532
+ try {
6533
+ const result = method(...args);
6534
+ return result instanceof Promise ? result.catch((error) => {
6535
+ report(name, error);
6536
+ throw error;
6537
+ }) : result;
6538
+ } catch (error) {
6539
+ report(name, error);
6540
+ throw error;
6541
+ }
6542
+ }
6543
+ ]);
6544
+ return { ...Object.fromEntries(methods), reportError: report };
6545
+ }
6546
+
6429
6547
  // ../sdk-core/src/quotes.ts
6430
6548
  function quoteAuthorOf(quote, you, appName) {
6431
6549
  return quote.from === "contact" ? you : quote.sender?.name ?? appName;
@@ -6440,7 +6558,11 @@ function quoteStepOf(state, replyId) {
6440
6558
 
6441
6559
  // ../sdk-core/src/index.ts
6442
6560
  function createChat(options) {
6443
- return createChatStore(convexBackend(options.backendUrl), options);
6561
+ const backend = convexBackend(options.backendUrl);
6562
+ if (!options.errorSource) return { ...createChatStore(backend, options), reportError: () => {
6563
+ } };
6564
+ const report = errorReporter(backend, options.appKey, options.errorSource);
6565
+ return reportingChat(createChatStore(reportingBackend(backend, report), options), report);
6444
6566
  }
6445
6567
 
6446
6568
  // ../shared/src/utils/app-keys.ts
@@ -6540,6 +6662,8 @@ function hexOf({ l, c, h }) {
6540
6662
  var MAX_IMAGE_BYTES = 2 * 1024 * 1024;
6541
6663
  var MAX_FILE_BYTES = 10 * 1024 * 1024;
6542
6664
  var MAX_ATTACHMENTS = 6;
6665
+ var MAX_EMAIL_FILE_BYTES = 25 * 1024 * 1024;
6666
+ var MAX_EMAIL_SENT_BYTES = 20 * 1024 * 1024;
6543
6667
  var MAX_IMAGE_SIDE = 1600;
6544
6668
  var IMAGE_TYPES = ["image/jpeg", "image/png", "image/webp"];
6545
6669
 
@@ -6577,7 +6701,7 @@ function detailsFromUserAgent(userAgent, touchPoints = 0) {
6577
6701
  }
6578
6702
  const android = /Android (\d+(?:\.\d+)?)(?:; ([^;)]+?))?(?: Build\/[^;)]*)?[;)]/.exec(userAgent);
6579
6703
  if (android) {
6580
- const named = android[2]?.trim();
6704
+ const named = android.at(2)?.trim();
6581
6705
  const model = named && !HIDDEN_MODELS.has(named) ? named : void 0;
6582
6706
  const brand = model && brandOf(model);
6583
6707
  return {
@@ -6631,6 +6755,7 @@ function brandOf(model) {
6631
6755
  }
6632
6756
 
6633
6757
  // src/models/sdk.constants.ts
6758
+ var SDK_VERSION = "0.1.18";
6634
6759
  var OFFLINE_NOTICE_MS = 3e3;
6635
6760
  var ANDROID_NAVIGATION_BAR = 48;
6636
6761
  var DEFAULT_MAX_PHOTOS = 4;
@@ -6806,6 +6931,9 @@ function detail(read) {
6806
6931
  function text(value) {
6807
6932
  return typeof value === "string" && value.trim() !== "" && value !== "unknown" ? value : void 0;
6808
6933
  }
6934
+ function errorSource() {
6935
+ return { sdk: "react-native", version: SDK_VERSION, os: import_react_native.Platform.OS };
6936
+ }
6809
6937
  function isDevBuild() {
6810
6938
  return typeof __DEV__ !== "undefined" && __DEV__;
6811
6939
  }
@@ -7002,7 +7130,7 @@ function subscribeChatView(listener) {
7002
7130
  }
7003
7131
 
7004
7132
  // src/components/ChatModal.tsx
7005
- var import_react17 = require("react");
7133
+ var import_react18 = require("react");
7006
7134
  var import_react_native24 = require("react-native");
7007
7135
 
7008
7136
  // src/hooks/use-app-active.ts
@@ -7240,16 +7368,38 @@ var styles = import_react_native4.StyleSheet.create({
7240
7368
  count: { color: "#ffffff", fontSize: 15, fontWeight: "600" }
7241
7369
  });
7242
7370
 
7371
+ // src/components/ChatErrorBoundary.tsx
7372
+ var import_react4 = require("react");
7373
+ var ChatErrorBoundary = class extends import_react4.Component {
7374
+ constructor() {
7375
+ super(...arguments);
7376
+ __publicField(this, "state", { failed: false });
7377
+ }
7378
+ static getDerivedStateFromError() {
7379
+ return { failed: true };
7380
+ }
7381
+ componentDidCatch(error) {
7382
+ this.props.onError(error);
7383
+ }
7384
+ // iOS keeps a closing sheet's screens while it slides away: opened again meanwhile, they draw afresh.
7385
+ componentDidUpdate(previous) {
7386
+ if (this.state.failed && this.props.visible && !previous.visible) this.setState({ failed: false });
7387
+ }
7388
+ render() {
7389
+ return this.state.failed ? null : this.props.children;
7390
+ }
7391
+ };
7392
+
7243
7393
  // src/components/ChatScreen.tsx
7244
- var import_react16 = require("react");
7394
+ var import_react17 = require("react");
7245
7395
  var import_react_native23 = require("react-native");
7246
7396
 
7247
7397
  // src/hooks/use-connection-lost.ts
7248
- var import_react4 = require("react");
7398
+ var import_react5 = require("react");
7249
7399
  function useConnectionLost(connected) {
7250
- const [wasConnected, setWasConnected] = (0, import_react4.useState)(connected);
7251
- const [lost, setLost] = (0, import_react4.useState)(false);
7252
- (0, import_react4.useEffect)(() => {
7400
+ const [wasConnected, setWasConnected] = (0, import_react5.useState)(connected);
7401
+ const [lost, setLost] = (0, import_react5.useState)(false);
7402
+ (0, import_react5.useEffect)(() => {
7253
7403
  if (connected) {
7254
7404
  setWasConnected(true);
7255
7405
  setLost(false);
@@ -7263,11 +7413,11 @@ function useConnectionLost(connected) {
7263
7413
  }
7264
7414
 
7265
7415
  // src/hooks/use-keyboard-overlap.ts
7266
- var import_react5 = require("react");
7416
+ var import_react6 = require("react");
7267
7417
  var import_react_native5 = require("react-native");
7268
7418
  function useKeyboardOverlap(ref) {
7269
- const [overlap, setOverlap] = (0, import_react5.useState)(0);
7270
- (0, import_react5.useEffect)(() => {
7419
+ const [overlap, setOverlap] = (0, import_react6.useState)(0);
7420
+ (0, import_react6.useEffect)(() => {
7271
7421
  if (import_react_native5.Platform.OS === "ios") {
7272
7422
  const frame = import_react_native5.Keyboard.addListener("keyboardWillChangeFrame", (event) => {
7273
7423
  const next = Math.max(0, Math.round(import_react_native5.Dimensions.get("screen").height - event.endCoordinates.screenY));
@@ -7383,7 +7533,7 @@ var styles4 = import_react_native8.StyleSheet.create({
7383
7533
  });
7384
7534
 
7385
7535
  // src/components/ContactCodeCard.tsx
7386
- var import_react6 = require("react");
7536
+ var import_react7 = require("react");
7387
7537
  var import_react_native9 = require("react-native");
7388
7538
 
7389
7539
  // ../shared/src/constants/auth.ts
@@ -7397,9 +7547,9 @@ var MOBILE_AUTH_CODE_TTL_MS = 2 * 6e4;
7397
7547
  var import_jsx_runtime6 = require("react/jsx-runtime");
7398
7548
  function ContactCodeCard({ code: code2, onDismiss }) {
7399
7549
  const { chat: chat2, t, colors } = useChatContext();
7400
- const [value, setValue] = (0, import_react6.useState)("");
7401
- const [error, setError] = (0, import_react6.useState)(null);
7402
- const [busy, setBusy] = (0, import_react6.useState)(false);
7550
+ const [value, setValue] = (0, import_react7.useState)("");
7551
+ const [error, setError] = (0, import_react7.useState)(null);
7552
+ const [busy, setBusy] = (0, import_react7.useState)(false);
7403
7553
  const errorOf = (reason) => reason === "contact_code_invalid" ? t.code_invalid : reason === "contact_code_expired" ? t.code_expired : reason === "rate_limited" ? t.code_rate_limited : t.error;
7404
7554
  const handleSend = async () => {
7405
7555
  setBusy(true);
@@ -7496,11 +7646,11 @@ var styles5 = import_react_native9.StyleSheet.create({
7496
7646
  });
7497
7647
 
7498
7648
  // src/components/Composer.tsx
7499
- var import_react8 = require("react");
7649
+ var import_react9 = require("react");
7500
7650
  var import_react_native11 = require("react-native");
7501
7651
 
7502
7652
  // src/hooks/use-pending-photos.ts
7503
- var import_react7 = require("react");
7653
+ var import_react8 = require("react");
7504
7654
 
7505
7655
  // ../shared/src/utils/files.ts
7506
7656
  function isImage(type) {
@@ -7596,9 +7746,9 @@ var lastId = 0;
7596
7746
  var nextId = () => `photo_${++lastId}`;
7597
7747
  function usePendingPhotos() {
7598
7748
  const { chat: chat2, t, maxPhotos } = useChatContext();
7599
- const [photos, setPhotos] = (0, import_react7.useState)(() => pendingPhotosOfDraft(chat2.draft()?.files ?? [], nextId));
7600
- const [problem, setProblem] = (0, import_react7.useState)(null);
7601
- const [sending, setSending] = (0, import_react7.useState)(false);
7749
+ const [photos, setPhotos] = (0, import_react8.useState)(() => pendingPhotosOfDraft(chat2.draft()?.files ?? [], nextId));
7750
+ const [problem, setProblem] = (0, import_react8.useState)(null);
7751
+ const [sending, setSending] = (0, import_react8.useState)(false);
7602
7752
  const tooMany = maxPhotos === 1 ? t.too_many_one : format(t.too_many, { count: maxPhotos });
7603
7753
  const update = (id, patch) => setPhotos((current) => current.map((photo) => photo.id === id ? { ...photo, ...patch } : photo));
7604
7754
  const upload = async (photo) => {
@@ -7656,7 +7806,7 @@ function usePendingPhotos() {
7656
7806
  setPhotos([]);
7657
7807
  return attachments;
7658
7808
  };
7659
- const draftFiles = (0, import_react7.useMemo)(() => draftFilesOf(photos), [photos]);
7809
+ const draftFiles = (0, import_react8.useMemo)(() => draftFilesOf(photos), [photos]);
7660
7810
  return {
7661
7811
  photos,
7662
7812
  draftFiles,
@@ -7801,22 +7951,22 @@ var styles6 = import_react_native10.StyleSheet.create({
7801
7951
  var import_jsx_runtime8 = require("react/jsx-runtime");
7802
7952
  function Composer() {
7803
7953
  const { chat: chat2, t, colors } = useChatContext();
7804
- const [text2, setText] = (0, import_react8.useState)(() => chat2.draft()?.text ?? "");
7805
- const typed = (0, import_react8.useRef)(text2);
7954
+ const [text2, setText] = (0, import_react9.useState)(() => chat2.draft()?.text ?? "");
7955
+ const typed = (0, import_react9.useRef)(text2);
7806
7956
  const pending = usePendingPhotos();
7807
7957
  const picker = photoPicker();
7808
7958
  const canSend = !pending.sending && (text2.trim().length > 0 || pending.photos.length > 0);
7809
- const draft2 = (0, import_react8.useSyncExternalStore)(subscribeChatView, chatDraft);
7959
+ const draft2 = (0, import_react9.useSyncExternalStore)(subscribeChatView, chatDraft);
7810
7960
  const changeText = (value) => {
7811
7961
  typed.current = value;
7812
7962
  setText(value);
7813
7963
  };
7814
- (0, import_react8.useEffect)(() => {
7964
+ (0, import_react9.useEffect)(() => {
7815
7965
  if (draft2 === null) return;
7816
7966
  changeText(draft2);
7817
7967
  clearDraft();
7818
7968
  }, [draft2]);
7819
- (0, import_react8.useEffect)(() => {
7969
+ (0, import_react9.useEffect)(() => {
7820
7970
  chat2.saveDraft({ text: text2, files: pending.draftFiles });
7821
7971
  }, [chat2, text2, pending.draftFiles]);
7822
7972
  const handleSend = async () => {
@@ -7915,18 +8065,18 @@ var styles7 = import_react_native11.StyleSheet.create({
7915
8065
  });
7916
8066
 
7917
8067
  // src/components/MessageList.tsx
7918
- var import_react15 = require("react");
8068
+ var import_react16 = require("react");
7919
8069
  var import_react_native21 = require("react-native");
7920
8070
 
7921
8071
  // src/components/EmailForm.tsx
7922
- var import_react9 = require("react");
8072
+ var import_react10 = require("react");
7923
8073
  var import_react_native12 = require("react-native");
7924
8074
  var import_jsx_runtime9 = require("react/jsx-runtime");
7925
8075
  function EmailForm({ onSubmit }) {
7926
8076
  const { t, colors } = useChatContext();
7927
- const [email, setEmail] = (0, import_react9.useState)("");
7928
- const [error, setError] = (0, import_react9.useState)(null);
7929
- const [busy, setBusy] = (0, import_react9.useState)(false);
8077
+ const [email, setEmail] = (0, import_react10.useState)("");
8078
+ const [error, setError] = (0, import_react10.useState)(null);
8079
+ const [busy, setBusy] = (0, import_react10.useState)(false);
7930
8080
  const handleSubmit = async () => {
7931
8081
  const address = normaliseEmail(email);
7932
8082
  if (!isEmail(address)) {
@@ -7989,15 +8139,15 @@ var styles8 = import_react_native12.StyleSheet.create({
7989
8139
  });
7990
8140
 
7991
8141
  // src/components/MessageBubble.tsx
7992
- var import_react13 = require("react");
8142
+ var import_react14 = require("react");
7993
8143
  var import_react_native19 = require("react-native");
7994
8144
 
7995
8145
  // src/hooks/use-rise-in.ts
7996
- var import_react10 = require("react");
8146
+ var import_react11 = require("react");
7997
8147
  var import_react_native13 = require("react-native");
7998
8148
  function useRiseIn(fresh) {
7999
- const progress = (0, import_react10.useRef)(new import_react_native13.Animated.Value(fresh ? 0 : 1)).current;
8000
- (0, import_react10.useEffect)(() => {
8149
+ const progress = (0, import_react11.useRef)(new import_react_native13.Animated.Value(fresh ? 0 : 1)).current;
8150
+ (0, import_react11.useEffect)(() => {
8001
8151
  if (!fresh) return;
8002
8152
  import_react_native13.Animated.timing(progress, { toValue: 1, duration: ENTER_MS, useNativeDriver: true }).start();
8003
8153
  }, [fresh, progress]);
@@ -8018,15 +8168,15 @@ function withFileName(url, name) {
8018
8168
  }
8019
8169
 
8020
8170
  // src/hooks/use-attachment-links.ts
8021
- var import_react11 = require("react");
8171
+ var import_react12 = require("react");
8022
8172
  var signed = /* @__PURE__ */ new Map();
8023
8173
  function useAttachmentLinks(chat2, keys, stored) {
8024
- const [links, setLinks] = (0, import_react11.useState)(() => cachedLinks(keys));
8025
- const [attempt, setAttempt] = (0, import_react11.useState)(0);
8026
- const connected = (0, import_react11.useSyncExternalStore)(chat2.subscribe, () => chat2.getState().connected);
8027
- const failed = (0, import_react11.useRef)(false);
8174
+ const [links, setLinks] = (0, import_react12.useState)(() => cachedLinks(keys));
8175
+ const [attempt, setAttempt] = (0, import_react12.useState)(0);
8176
+ const connected = (0, import_react12.useSyncExternalStore)(chat2.subscribe, () => chat2.getState().connected);
8177
+ const failed = (0, import_react12.useRef)(false);
8028
8178
  const wanted = keys.join("|");
8029
- (0, import_react11.useEffect)(() => {
8179
+ (0, import_react12.useEffect)(() => {
8030
8180
  if (!stored) return;
8031
8181
  const list = wanted ? wanted.split("|") : [];
8032
8182
  const missing = list.filter((key) => (signed.get(key)?.until ?? 0) < Date.now());
@@ -8054,7 +8204,7 @@ function useAttachmentLinks(chat2, keys, stored) {
8054
8204
  clearTimeout(retry);
8055
8205
  };
8056
8206
  }, [chat2, wanted, attempt, stored]);
8057
- (0, import_react11.useEffect)(() => {
8207
+ (0, import_react12.useEffect)(() => {
8058
8208
  if (connected && failed.current) setAttempt((current) => current + 1);
8059
8209
  }, [connected]);
8060
8210
  return links;
@@ -8064,13 +8214,13 @@ function cachedLinks(keys) {
8064
8214
  }
8065
8215
 
8066
8216
  // src/components/Skeleton.tsx
8067
- var import_react12 = require("react");
8217
+ var import_react13 = require("react");
8068
8218
  var import_react_native14 = require("react-native");
8069
8219
  var import_jsx_runtime10 = require("react/jsx-runtime");
8070
8220
  function Skeleton({ style }) {
8071
8221
  const { colors } = useChatContext();
8072
- const opacity = (0, import_react12.useRef)(new import_react_native14.Animated.Value(1)).current;
8073
- (0, import_react12.useEffect)(() => {
8222
+ const opacity = (0, import_react13.useRef)(new import_react_native14.Animated.Value(1)).current;
8223
+ (0, import_react13.useEffect)(() => {
8074
8224
  const breathe = import_react_native14.Animated.loop(
8075
8225
  import_react_native14.Animated.sequence([
8076
8226
  import_react_native14.Animated.timing(opacity, { toValue: 0.5, duration: 700, useNativeDriver: true }),
@@ -8321,7 +8471,7 @@ var styles12 = import_react_native18.StyleSheet.create({
8321
8471
 
8322
8472
  // src/components/MessageBubble.tsx
8323
8473
  var import_jsx_runtime15 = require("react/jsx-runtime");
8324
- var MessageBubble = (0, import_react13.memo)(function MessageBubble2({ row, app, onRetry, onQuote, highlighted }) {
8474
+ var MessageBubble = (0, import_react14.memo)(function MessageBubble2({ row, app, onRetry, onQuote, highlighted }) {
8325
8475
  const { chat: chat2, t, locale, colors, openedAt } = useChatContext();
8326
8476
  const { message, startsRun, endsRun, startsDay } = row;
8327
8477
  const own = message.from === "contact";
@@ -8426,14 +8576,14 @@ var styles13 = import_react_native19.StyleSheet.create({
8426
8576
  });
8427
8577
 
8428
8578
  // src/components/TypingBubble.tsx
8429
- var import_react14 = require("react");
8579
+ var import_react15 = require("react");
8430
8580
  var import_react_native20 = require("react-native");
8431
8581
  var import_jsx_runtime16 = require("react/jsx-runtime");
8432
8582
  function TypingBubble({ app, sender }) {
8433
8583
  const { t, colors } = useChatContext();
8434
8584
  const rise = useRiseIn(true);
8435
- const dots = (0, import_react14.useRef)([0, 1, 2].map(() => new import_react_native20.Animated.Value(0))).current;
8436
- (0, import_react14.useEffect)(() => {
8585
+ const dots = (0, import_react15.useRef)([0, 1, 2].map(() => new import_react_native20.Animated.Value(0))).current;
8586
+ (0, import_react15.useEffect)(() => {
8437
8587
  const bounce = import_react_native20.Animated.loop(
8438
8588
  import_react_native20.Animated.stagger(
8439
8589
  150,
@@ -8485,14 +8635,14 @@ var styles14 = import_react_native20.StyleSheet.create({
8485
8635
  var import_jsx_runtime17 = require("react/jsx-runtime");
8486
8636
  function MessageList({ state }) {
8487
8637
  const { chat: chat2, t, colors, openedAt } = useChatContext();
8488
- const listRef = (0, import_react15.useRef)(null);
8489
- const [scrolledUp, setScrolledUp] = (0, import_react15.useState)(false);
8490
- const [highlighted, setHighlighted] = (0, import_react15.useState)(null);
8491
- const [seeking, setSeeking] = (0, import_react15.useState)(null);
8638
+ const listRef = (0, import_react16.useRef)(null);
8639
+ const [scrolledUp, setScrolledUp] = (0, import_react16.useState)(false);
8640
+ const [highlighted, setHighlighted] = (0, import_react16.useState)(null);
8641
+ const [seeking, setSeeking] = (0, import_react16.useState)(null);
8492
8642
  const app = state.app;
8493
8643
  const { messages, seen, atStart } = state;
8494
8644
  const welcomeText = state.texts.welcome;
8495
- const rows = (0, import_react15.useMemo)(() => {
8645
+ const rows = (0, import_react16.useMemo)(() => {
8496
8646
  const welcome = atStart ? {
8497
8647
  id: "welcome",
8498
8648
  from: "team",
@@ -8508,15 +8658,15 @@ function MessageList({ state }) {
8508
8658
  }, [messages, seen, atStart, welcomeText, openedAt]);
8509
8659
  const newest = rows.at(0)?.message;
8510
8660
  const sending = newest?.from === "contact" && newest.status === "sending" ? newest.id : null;
8511
- (0, import_react15.useEffect)(() => {
8661
+ (0, import_react16.useEffect)(() => {
8512
8662
  if (sending) listRef.current?.scrollToOffset({ offset: 0, animated: true });
8513
8663
  }, [sending]);
8514
- (0, import_react15.useEffect)(() => {
8664
+ (0, import_react16.useEffect)(() => {
8515
8665
  if (!highlighted) return;
8516
8666
  const timer = setTimeout(() => setHighlighted(null), QUOTE_HIGHLIGHT_MS);
8517
8667
  return () => clearTimeout(timer);
8518
8668
  }, [highlighted]);
8519
- (0, import_react15.useEffect)(() => {
8669
+ (0, import_react16.useEffect)(() => {
8520
8670
  if (!seeking) return;
8521
8671
  const step = quoteStepOf(state, seeking);
8522
8672
  if (step.kind === "older") chat2.loadOlder();
@@ -8527,9 +8677,9 @@ function MessageList({ state }) {
8527
8677
  listRef.current?.scrollToIndex({ index, animated: true, viewPosition: 0.5 });
8528
8678
  setHighlighted(step.id);
8529
8679
  }, [seeking, state, chat2, rows]);
8530
- const handleQuote = (0, import_react15.useCallback)((replyId) => setSeeking(replyId), []);
8531
- const handleRetry = (0, import_react15.useCallback)((messageId) => chat2.retry(messageId), [chat2]);
8532
- const renderItem = (0, import_react15.useCallback)(
8680
+ const handleQuote = (0, import_react16.useCallback)((replyId) => setSeeking(replyId), []);
8681
+ const handleRetry = (0, import_react16.useCallback)((messageId) => chat2.retry(messageId), [chat2]);
8682
+ const renderItem = (0, import_react16.useCallback)(
8533
8683
  ({ item }) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(MessageBubble, { row: item, app, onRetry: handleRetry, onQuote: handleQuote, highlighted: highlighted === item.message.id }),
8534
8684
  [app, handleRetry, handleQuote, highlighted]
8535
8685
  );
@@ -8650,7 +8800,7 @@ var styles16 = import_react_native22.StyleSheet.create({
8650
8800
  var import_jsx_runtime19 = require("react/jsx-runtime");
8651
8801
  function ChatScreen({ state, insets, onClose }) {
8652
8802
  const { chat: chat2, t, colors } = useChatContext();
8653
- const rootRef = (0, import_react16.useRef)(null);
8803
+ const rootRef = (0, import_react17.useRef)(null);
8654
8804
  const keyboard = useKeyboardOverlap(rootRef);
8655
8805
  const connectionLost = useConnectionLost(state.connected);
8656
8806
  const app = state.app;
@@ -8678,18 +8828,18 @@ var styles17 = import_react_native23.StyleSheet.create({
8678
8828
  var import_jsx_runtime20 = require("react/jsx-runtime");
8679
8829
  var STRINGS = { fr, en };
8680
8830
  function ChatModal({ chat: chat2, colorScheme, maxPhotos }) {
8681
- const state = (0, import_react17.useSyncExternalStore)(chat2.subscribe, chat2.getState);
8682
- const { open: open2 } = (0, import_react17.useSyncExternalStore)(subscribeChatView, chatView);
8831
+ const state = (0, import_react18.useSyncExternalStore)(chat2.subscribe, chat2.getState);
8832
+ const { open: open2 } = (0, import_react18.useSyncExternalStore)(subscribeChatView, chatView);
8683
8833
  const deviceScheme = (0, import_react_native24.useColorScheme)();
8684
8834
  const scheme = colorScheme ?? (deviceScheme === "dark" ? "dark" : "light");
8685
8835
  const active = useAppActive();
8686
8836
  const dimensions = (0, import_react_native24.useWindowDimensions)();
8687
- const [gallery, setGallery] = (0, import_react17.useState)(null);
8688
- const [openedAt, setOpenedAt] = (0, import_react17.useState)(Date.now);
8837
+ const [gallery, setGallery] = (0, import_react18.useState)(null);
8838
+ const [openedAt, setOpenedAt] = (0, import_react18.useState)(Date.now);
8689
8839
  const app = state.app;
8690
8840
  const visible = open2 && app !== null && state.status !== "loading" && state.status !== "hidden";
8691
8841
  const color = app?.color ?? ZEAN_ACCENT_HEX;
8692
- const context = (0, import_react17.useMemo)(
8842
+ const context = (0, import_react18.useMemo)(
8693
8843
  () => ({
8694
8844
  chat: chat2,
8695
8845
  t: STRINGS[state.locale],
@@ -8701,12 +8851,16 @@ function ChatModal({ chat: chat2, colorScheme, maxPhotos }) {
8701
8851
  }),
8702
8852
  [chat2, state.locale, color, scheme, openedAt, maxPhotos]
8703
8853
  );
8704
- const insets = (0, import_react17.useMemo)(screenInsets, [dimensions.width, dimensions.height]);
8705
- (0, import_react17.useEffect)(() => chat2.setOpen(open2 && active), [chat2, open2, active]);
8706
- (0, import_react17.useEffect)(() => {
8854
+ const insets = (0, import_react18.useMemo)(screenInsets, [dimensions.width, dimensions.height]);
8855
+ const handleScreenError = (error) => {
8856
+ chat2.reportError("screen", error);
8857
+ zean.close();
8858
+ };
8859
+ (0, import_react18.useEffect)(() => chat2.setOpen(open2 && active), [chat2, open2, active]);
8860
+ (0, import_react18.useEffect)(() => {
8707
8861
  if (visible && active && state.unread > 0) chat2.markRead();
8708
8862
  }, [chat2, visible, active, state.unread]);
8709
- (0, import_react17.useEffect)(() => {
8863
+ (0, import_react18.useEffect)(() => {
8710
8864
  if (visible) setOpenedAt(Date.now());
8711
8865
  else setGallery(null);
8712
8866
  }, [visible]);
@@ -8720,10 +8874,10 @@ function ChatModal({ chat: chat2, colorScheme, maxPhotos }) {
8720
8874
  statusBarTranslucent: true,
8721
8875
  navigationBarTranslucent: true,
8722
8876
  onRequestClose: () => import_react_native24.Platform.OS === "android" && gallery ? setGallery(null) : zean.close(),
8723
- children: app && /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(ChatContext, { value: context, children: [
8877
+ children: app && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(ChatErrorBoundary, { visible, onError: handleScreenError, children: /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(ChatContext, { value: context, children: [
8724
8878
  /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(ChatScreen, { state, insets, onClose: zean.close }),
8725
8879
  gallery && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(ImageViewer, { gallery, topInset: insets.top, onClose: () => setGallery(null) })
8726
- ] })
8880
+ ] }) })
8727
8881
  }
8728
8882
  );
8729
8883
  }
@@ -8740,12 +8894,12 @@ function ZeanChat({
8740
8894
  maxPhotos,
8741
8895
  backendUrl = backendUrlFor(appKey)
8742
8896
  }) {
8743
- const [chat2, setChat] = (0, import_react18.useState)(null);
8744
- const storageRef = (0, import_react18.useRef)(storage);
8897
+ const [chat2, setChat] = (0, import_react19.useState)(null);
8898
+ const storageRef = (0, import_react19.useRef)(storage);
8745
8899
  const userKey = user ? JSON.stringify(user) : null;
8746
- const identified = (0, import_react18.useRef)(false);
8900
+ const identified = (0, import_react19.useRef)(false);
8747
8901
  const attributesKey = attributes2 ? JSON.stringify(attributes2) : null;
8748
- (0, import_react18.useEffect)(() => {
8902
+ (0, import_react19.useEffect)(() => {
8749
8903
  const started = createChat({
8750
8904
  appKey,
8751
8905
  backendUrl,
@@ -8760,7 +8914,9 @@ function ZeanChat({
8760
8914
  // The Conversation stays on the phone: the next start shows it at once and asks only for newer messages.
8761
8915
  keep: true,
8762
8916
  // A development build: the phone becomes a Test device for App settings > Developers > Webhook.
8763
- dev: isDevBuild()
8917
+ dev: isDevBuild(),
8918
+ // The SDK's own errors go to our Sentry through the backend; the app's own Sentry, if any, is left alone.
8919
+ errorSource: errorSource()
8764
8920
  });
8765
8921
  const detach = attachChat(started);
8766
8922
  setChat(started);
@@ -8769,20 +8925,20 @@ function ZeanChat({
8769
8925
  started.destroy();
8770
8926
  };
8771
8927
  }, [appKey, backendUrl, locale]);
8772
- (0, import_react18.useEffect)(() => {
8928
+ (0, import_react19.useEffect)(() => {
8773
8929
  if (userKey) zean.identify(JSON.parse(userKey));
8774
8930
  else if (identified.current) zean.signOut();
8775
8931
  identified.current = userKey !== null;
8776
8932
  }, [userKey]);
8777
- (0, import_react18.useEffect)(() => {
8933
+ (0, import_react19.useEffect)(() => {
8778
8934
  if (attributesKey) zean.setAttributes(JSON.parse(attributesKey));
8779
8935
  }, [attributesKey, userKey]);
8780
8936
  return chat2 ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(ChatModal, { chat: chat2, colorScheme, maxPhotos }) : null;
8781
8937
  }
8782
8938
 
8783
8939
  // src/hooks/use-zean.ts
8784
- var import_react19 = require("react");
8940
+ var import_react20 = require("react");
8785
8941
  function useZean() {
8786
- const { unread } = (0, import_react19.useSyncExternalStore)(subscribeChatView, chatView);
8942
+ const { unread } = (0, import_react20.useSyncExternalStore)(subscribeChatView, chatView);
8787
8943
  return { ...zean, unreadCount: unread };
8788
8944
  }