tevrocsdk 0.1.47 → 0.1.49

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/tevroc-sdk.umd.js CHANGED
@@ -302,8 +302,8 @@ var Tevroc = (() => {
302
302
  registered: false,
303
303
  windowEventName,
304
304
  pluginEventName,
305
- handler: (event) => {
306
- this.notifyListeners(pluginEventName, event);
305
+ handler: (event2) => {
306
+ this.notifyListeners(pluginEventName, event2);
307
307
  }
308
308
  };
309
309
  }
@@ -1433,20 +1433,20 @@ var Tevroc = (() => {
1433
1433
  await customElements.whenDefined("jeep-sqlite");
1434
1434
  this.jeepSqliteElement = document.querySelector("jeep-sqlite");
1435
1435
  this.ensureJeepSqliteIsAvailable();
1436
- this.jeepSqliteElement.addEventListener("jeepSqliteImportProgress", (event) => {
1437
- this.notifyListeners("sqliteImportProgressEvent", event.detail);
1436
+ this.jeepSqliteElement.addEventListener("jeepSqliteImportProgress", (event2) => {
1437
+ this.notifyListeners("sqliteImportProgressEvent", event2.detail);
1438
1438
  });
1439
- this.jeepSqliteElement.addEventListener("jeepSqliteExportProgress", (event) => {
1440
- this.notifyListeners("sqliteExportProgressEvent", event.detail);
1439
+ this.jeepSqliteElement.addEventListener("jeepSqliteExportProgress", (event2) => {
1440
+ this.notifyListeners("sqliteExportProgressEvent", event2.detail);
1441
1441
  });
1442
- this.jeepSqliteElement.addEventListener("jeepSqliteHTTPRequestEnded", (event) => {
1443
- this.notifyListeners("sqliteHTTPRequestEndedEvent", event.detail);
1442
+ this.jeepSqliteElement.addEventListener("jeepSqliteHTTPRequestEnded", (event2) => {
1443
+ this.notifyListeners("sqliteHTTPRequestEndedEvent", event2.detail);
1444
1444
  });
1445
- this.jeepSqliteElement.addEventListener("jeepSqlitePickDatabaseEnded", (event) => {
1446
- this.notifyListeners("sqlitePickDatabaseEndedEvent", event.detail);
1445
+ this.jeepSqliteElement.addEventListener("jeepSqlitePickDatabaseEnded", (event2) => {
1446
+ this.notifyListeners("sqlitePickDatabaseEndedEvent", event2.detail);
1447
1447
  });
1448
- this.jeepSqliteElement.addEventListener("jeepSqliteSaveDatabaseToDisk", (event) => {
1449
- this.notifyListeners("sqliteSaveDatabaseToDiskEvent", event.detail);
1448
+ this.jeepSqliteElement.addEventListener("jeepSqliteSaveDatabaseToDisk", (event2) => {
1449
+ this.notifyListeners("sqliteSaveDatabaseToDiskEvent", event2.detail);
1450
1450
  });
1451
1451
  if (!this.isWebStoreOpen) {
1452
1452
  this.isWebStoreOpen = await this.jeepSqliteElement.isStoreOpen();
@@ -13189,8 +13189,8 @@ var Tevroc = (() => {
13189
13189
  run(id);
13190
13190
  };
13191
13191
  };
13192
- var eventListener = function(event) {
13193
- run(event.data);
13192
+ var eventListener = function(event2) {
13193
+ run(event2.data);
13194
13194
  };
13195
13195
  var globalPostMessageDefer = function(id) {
13196
13196
  globalThis2.postMessage(String2(id), $location.protocol + "//" + $location.host);
@@ -13589,15 +13589,15 @@ var Tevroc = (() => {
13589
13589
  });
13590
13590
  };
13591
13591
  var dispatchEvent = function(name, promise, reason) {
13592
- var event, handler;
13592
+ var event2, handler;
13593
13593
  if (DISPATCH_EVENT) {
13594
- event = document2.createEvent("Event");
13595
- event.promise = promise;
13596
- event.reason = reason;
13597
- event.initEvent(name, false, true);
13598
- globalThis2.dispatchEvent(event);
13599
- } else event = { promise, reason };
13600
- if (!NATIVE_PROMISE_REJECTION_EVENT && (handler = globalThis2["on" + name])) handler(event);
13594
+ event2 = document2.createEvent("Event");
13595
+ event2.promise = promise;
13596
+ event2.reason = reason;
13597
+ event2.initEvent(name, false, true);
13598
+ globalThis2.dispatchEvent(event2);
13599
+ } else event2 = { promise, reason };
13600
+ if (!NATIVE_PROMISE_REJECTION_EVENT && (handler = globalThis2["on" + name])) handler(event2);
13601
13601
  else if (name === UNHANDLED_REJECTION) hostReportErrors("Unhandled promise rejection", reason);
13602
13602
  };
13603
13603
  var onUnhandled = function(state) {
@@ -17654,11 +17654,11 @@ var Tevroc = (() => {
17654
17654
  }
17655
17655
  return point;
17656
17656
  }
17657
- onClick(event) {
17657
+ onClick(event2) {
17658
17658
  var {
17659
17659
  x: x3,
17660
17660
  y: y3
17661
- } = this.mapXY(event.clientX, event.clientY);
17661
+ } = this.mapXY(event2.clientX, event2.clientY);
17662
17662
  this.events.push({
17663
17663
  type: "onclick",
17664
17664
  x: x3,
@@ -17670,11 +17670,11 @@ var Tevroc = (() => {
17670
17670
  }
17671
17671
  });
17672
17672
  }
17673
- onMouseMove(event) {
17673
+ onMouseMove(event2) {
17674
17674
  var {
17675
17675
  x: x3,
17676
17676
  y: y3
17677
- } = this.mapXY(event.clientX, event.clientY);
17677
+ } = this.mapXY(event2.clientX, event2.clientY);
17678
17678
  this.events.push({
17679
17679
  type: "onmousemove",
17680
17680
  x: x3,
@@ -22291,10 +22291,10 @@ var Tevroc = (() => {
22291
22291
  };
22292
22292
  });
22293
22293
  }
22294
- static doUpgrade(event) {
22295
- const eventTarget = event.target;
22294
+ static doUpgrade(event2) {
22295
+ const eventTarget = event2.target;
22296
22296
  const db = eventTarget.result;
22297
- switch (event.oldVersion) {
22297
+ switch (event2.oldVersion) {
22298
22298
  case 0:
22299
22299
  case 1:
22300
22300
  default: {
@@ -23718,41 +23718,41 @@ var Tevroc = (() => {
23718
23718
  listen: () => listen,
23719
23719
  once: () => once
23720
23720
  });
23721
- async function _unlisten(event, eventId) {
23722
- window.__TAURI_EVENT_PLUGIN_INTERNALS__.unregisterListener(event, eventId);
23721
+ async function _unlisten(event2, eventId) {
23722
+ window.__TAURI_EVENT_PLUGIN_INTERNALS__.unregisterListener(event2, eventId);
23723
23723
  await invoke("plugin:event|unlisten", {
23724
- event,
23724
+ event: event2,
23725
23725
  eventId
23726
23726
  });
23727
23727
  }
23728
- async function listen(event, handler, options) {
23728
+ async function listen(event2, handler, options) {
23729
23729
  var _a2;
23730
23730
  const target = typeof (options === null || options === void 0 ? void 0 : options.target) === "string" ? { kind: "AnyLabel", label: options.target } : (_a2 = options === null || options === void 0 ? void 0 : options.target) !== null && _a2 !== void 0 ? _a2 : { kind: "Any" };
23731
23731
  return invoke("plugin:event|listen", {
23732
- event,
23732
+ event: event2,
23733
23733
  target,
23734
23734
  handler: transformCallback(handler)
23735
23735
  }).then((eventId) => {
23736
- return async () => _unlisten(event, eventId);
23736
+ return async () => _unlisten(event2, eventId);
23737
23737
  });
23738
23738
  }
23739
- async function once(event, handler, options) {
23740
- return listen(event, (eventData) => {
23741
- void _unlisten(event, eventData.id);
23739
+ async function once(event2, handler, options) {
23740
+ return listen(event2, (eventData) => {
23741
+ void _unlisten(event2, eventData.id);
23742
23742
  handler(eventData);
23743
23743
  }, options);
23744
23744
  }
23745
- async function emit(event, payload) {
23745
+ async function emit(event2, payload) {
23746
23746
  await invoke("plugin:event|emit", {
23747
- event,
23747
+ event: event2,
23748
23748
  payload
23749
23749
  });
23750
23750
  }
23751
- async function emitTo(target, event, payload) {
23751
+ async function emitTo(target, event2, payload) {
23752
23752
  const eventTarget = typeof target === "string" ? { kind: "AnyLabel", label: target } : target;
23753
23753
  await invoke("plugin:event|emit_to", {
23754
23754
  target: eventTarget,
23755
- event,
23755
+ event: event2,
23756
23756
  payload
23757
23757
  });
23758
23758
  }
@@ -23880,10 +23880,10 @@ var Tevroc = (() => {
23880
23880
  UserAttentionType2[UserAttentionType2["Informational"] = 2] = "Informational";
23881
23881
  })(UserAttentionType || (UserAttentionType = {}));
23882
23882
  CloseRequestedEvent = class {
23883
- constructor(event) {
23883
+ constructor(event2) {
23884
23884
  this._preventDefault = false;
23885
- this.event = event.event;
23886
- this.id = event.id;
23885
+ this.event = event2.event;
23886
+ this.id = event2.id;
23887
23887
  }
23888
23888
  preventDefault() {
23889
23889
  this._preventDefault = true;
@@ -23996,14 +23996,14 @@ var Tevroc = (() => {
23996
23996
  * @returns A promise resolving to a function to unlisten to the event.
23997
23997
  * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
23998
23998
  */
23999
- async listen(event, handler) {
24000
- if (this._handleTauriEvent(event, handler)) {
23999
+ async listen(event2, handler) {
24000
+ if (this._handleTauriEvent(event2, handler)) {
24001
24001
  return () => {
24002
- const listeners2 = this.listeners[event];
24002
+ const listeners2 = this.listeners[event2];
24003
24003
  listeners2.splice(listeners2.indexOf(handler), 1);
24004
24004
  };
24005
24005
  }
24006
- return listen(event, handler, {
24006
+ return listen(event2, handler, {
24007
24007
  target: { kind: "Window", label: this.label }
24008
24008
  });
24009
24009
  }
@@ -24026,14 +24026,14 @@ var Tevroc = (() => {
24026
24026
  * @returns A promise resolving to a function to unlisten to the event.
24027
24027
  * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
24028
24028
  */
24029
- async once(event, handler) {
24030
- if (this._handleTauriEvent(event, handler)) {
24029
+ async once(event2, handler) {
24030
+ if (this._handleTauriEvent(event2, handler)) {
24031
24031
  return () => {
24032
- const listeners2 = this.listeners[event];
24032
+ const listeners2 = this.listeners[event2];
24033
24033
  listeners2.splice(listeners2.indexOf(handler), 1);
24034
24034
  };
24035
24035
  }
24036
- return once(event, handler, {
24036
+ return once(event2, handler, {
24037
24037
  target: { kind: "Window", label: this.label }
24038
24038
  });
24039
24039
  }
@@ -24048,18 +24048,18 @@ var Tevroc = (() => {
24048
24048
  * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
24049
24049
  * @param payload Event payload.
24050
24050
  */
24051
- async emit(event, payload) {
24052
- if (localTauriEvents.includes(event)) {
24053
- for (const handler of this.listeners[event] || []) {
24051
+ async emit(event2, payload) {
24052
+ if (localTauriEvents.includes(event2)) {
24053
+ for (const handler of this.listeners[event2] || []) {
24054
24054
  handler({
24055
- event,
24055
+ event: event2,
24056
24056
  id: -1,
24057
24057
  payload
24058
24058
  });
24059
24059
  }
24060
24060
  return;
24061
24061
  }
24062
- return emit(event, payload);
24062
+ return emit(event2, payload);
24063
24063
  }
24064
24064
  /**
24065
24065
  * Emits an event to all {@link EventTarget|targets} matching the given target.
@@ -24073,26 +24073,26 @@ var Tevroc = (() => {
24073
24073
  * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
24074
24074
  * @param payload Event payload.
24075
24075
  */
24076
- async emitTo(target, event, payload) {
24077
- if (localTauriEvents.includes(event)) {
24078
- for (const handler of this.listeners[event] || []) {
24076
+ async emitTo(target, event2, payload) {
24077
+ if (localTauriEvents.includes(event2)) {
24078
+ for (const handler of this.listeners[event2] || []) {
24079
24079
  handler({
24080
- event,
24080
+ event: event2,
24081
24081
  id: -1,
24082
24082
  payload
24083
24083
  });
24084
24084
  }
24085
24085
  return;
24086
24086
  }
24087
- return emitTo(target, event, payload);
24087
+ return emitTo(target, event2, payload);
24088
24088
  }
24089
24089
  /** @ignore */
24090
- _handleTauriEvent(event, handler) {
24091
- if (localTauriEvents.includes(event)) {
24092
- if (!(event in this.listeners)) {
24093
- this.listeners[event] = [handler];
24090
+ _handleTauriEvent(event2, handler) {
24091
+ if (localTauriEvents.includes(event2)) {
24092
+ if (!(event2 in this.listeners)) {
24093
+ this.listeners[event2] = [handler];
24094
24094
  } else {
24095
- this.listeners[event].push(handler);
24095
+ this.listeners[event2].push(handler);
24096
24096
  }
24097
24097
  return true;
24098
24098
  }
@@ -25387,8 +25387,8 @@ var Tevroc = (() => {
25387
25387
  * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
25388
25388
  */
25389
25389
  async onCloseRequested(handler) {
25390
- return this.listen(TauriEvent.WINDOW_CLOSE_REQUESTED, async (event) => {
25391
- const evt = new CloseRequestedEvent(event);
25390
+ return this.listen(TauriEvent.WINDOW_CLOSE_REQUESTED, async (event2) => {
25391
+ const evt = new CloseRequestedEvent(event2);
25392
25392
  await handler(evt);
25393
25393
  if (!evt.isPreventDefault()) {
25394
25394
  await this.destroy();
@@ -25421,37 +25421,37 @@ var Tevroc = (() => {
25421
25421
  * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
25422
25422
  */
25423
25423
  async onDragDropEvent(handler) {
25424
- const unlistenDrag = await this.listen(TauriEvent.DRAG_ENTER, (event) => {
25424
+ const unlistenDrag = await this.listen(TauriEvent.DRAG_ENTER, (event2) => {
25425
25425
  handler({
25426
- ...event,
25426
+ ...event2,
25427
25427
  payload: {
25428
25428
  type: "enter",
25429
- paths: event.payload.paths,
25430
- position: new PhysicalPosition(event.payload.position)
25429
+ paths: event2.payload.paths,
25430
+ position: new PhysicalPosition(event2.payload.position)
25431
25431
  }
25432
25432
  });
25433
25433
  });
25434
- const unlistenDragOver = await this.listen(TauriEvent.DRAG_OVER, (event) => {
25434
+ const unlistenDragOver = await this.listen(TauriEvent.DRAG_OVER, (event2) => {
25435
25435
  handler({
25436
- ...event,
25436
+ ...event2,
25437
25437
  payload: {
25438
25438
  type: "over",
25439
- position: new PhysicalPosition(event.payload.position)
25439
+ position: new PhysicalPosition(event2.payload.position)
25440
25440
  }
25441
25441
  });
25442
25442
  });
25443
- const unlistenDrop = await this.listen(TauriEvent.DRAG_DROP, (event) => {
25443
+ const unlistenDrop = await this.listen(TauriEvent.DRAG_DROP, (event2) => {
25444
25444
  handler({
25445
- ...event,
25445
+ ...event2,
25446
25446
  payload: {
25447
25447
  type: "drop",
25448
- paths: event.payload.paths,
25449
- position: new PhysicalPosition(event.payload.position)
25448
+ paths: event2.payload.paths,
25449
+ position: new PhysicalPosition(event2.payload.position)
25450
25450
  }
25451
25451
  });
25452
25452
  });
25453
- const unlistenCancel = await this.listen(TauriEvent.DRAG_LEAVE, (event) => {
25454
- handler({ ...event, payload: { type: "leave" } });
25453
+ const unlistenCancel = await this.listen(TauriEvent.DRAG_LEAVE, (event2) => {
25454
+ handler({ ...event2, payload: { type: "leave" } });
25455
25455
  });
25456
25456
  return () => {
25457
25457
  unlistenDrag();
@@ -25478,11 +25478,11 @@ var Tevroc = (() => {
25478
25478
  * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
25479
25479
  */
25480
25480
  async onFocusChanged(handler) {
25481
- const unlistenFocus = await this.listen(TauriEvent.WINDOW_FOCUS, (event) => {
25482
- handler({ ...event, payload: true });
25481
+ const unlistenFocus = await this.listen(TauriEvent.WINDOW_FOCUS, (event2) => {
25482
+ handler({ ...event2, payload: true });
25483
25483
  });
25484
- const unlistenBlur = await this.listen(TauriEvent.WINDOW_BLUR, (event) => {
25485
- handler({ ...event, payload: false });
25484
+ const unlistenBlur = await this.listen(TauriEvent.WINDOW_BLUR, (event2) => {
25485
+ handler({ ...event2, payload: false });
25486
25486
  });
25487
25487
  return () => {
25488
25488
  unlistenFocus();
@@ -25695,14 +25695,14 @@ var Tevroc = (() => {
25695
25695
  * @returns A promise resolving to a function to unlisten to the event.
25696
25696
  * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
25697
25697
  */
25698
- async listen(event, handler) {
25699
- if (this._handleTauriEvent(event, handler)) {
25698
+ async listen(event2, handler) {
25699
+ if (this._handleTauriEvent(event2, handler)) {
25700
25700
  return () => {
25701
- const listeners2 = this.listeners[event];
25701
+ const listeners2 = this.listeners[event2];
25702
25702
  listeners2.splice(listeners2.indexOf(handler), 1);
25703
25703
  };
25704
25704
  }
25705
- return listen(event, handler, {
25705
+ return listen(event2, handler, {
25706
25706
  target: { kind: "Webview", label: this.label }
25707
25707
  });
25708
25708
  }
@@ -25725,14 +25725,14 @@ var Tevroc = (() => {
25725
25725
  * @returns A promise resolving to a function to unlisten to the event.
25726
25726
  * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
25727
25727
  */
25728
- async once(event, handler) {
25729
- if (this._handleTauriEvent(event, handler)) {
25728
+ async once(event2, handler) {
25729
+ if (this._handleTauriEvent(event2, handler)) {
25730
25730
  return () => {
25731
- const listeners2 = this.listeners[event];
25731
+ const listeners2 = this.listeners[event2];
25732
25732
  listeners2.splice(listeners2.indexOf(handler), 1);
25733
25733
  };
25734
25734
  }
25735
- return once(event, handler, {
25735
+ return once(event2, handler, {
25736
25736
  target: { kind: "Webview", label: this.label }
25737
25737
  });
25738
25738
  }
@@ -25748,18 +25748,18 @@ var Tevroc = (() => {
25748
25748
  * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
25749
25749
  * @param payload Event payload.
25750
25750
  */
25751
- async emit(event, payload) {
25752
- if (localTauriEvents2.includes(event)) {
25753
- for (const handler of this.listeners[event] || []) {
25751
+ async emit(event2, payload) {
25752
+ if (localTauriEvents2.includes(event2)) {
25753
+ for (const handler of this.listeners[event2] || []) {
25754
25754
  handler({
25755
- event,
25755
+ event: event2,
25756
25756
  id: -1,
25757
25757
  payload
25758
25758
  });
25759
25759
  }
25760
25760
  return;
25761
25761
  }
25762
- return emit(event, payload);
25762
+ return emit(event2, payload);
25763
25763
  }
25764
25764
  /**
25765
25765
  * Emits an event to all {@link EventTarget|targets} matching the given target.
@@ -25774,26 +25774,26 @@ var Tevroc = (() => {
25774
25774
  * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
25775
25775
  * @param payload Event payload.
25776
25776
  */
25777
- async emitTo(target, event, payload) {
25778
- if (localTauriEvents2.includes(event)) {
25779
- for (const handler of this.listeners[event] || []) {
25777
+ async emitTo(target, event2, payload) {
25778
+ if (localTauriEvents2.includes(event2)) {
25779
+ for (const handler of this.listeners[event2] || []) {
25780
25780
  handler({
25781
- event,
25781
+ event: event2,
25782
25782
  id: -1,
25783
25783
  payload
25784
25784
  });
25785
25785
  }
25786
25786
  return;
25787
25787
  }
25788
- return emitTo(target, event, payload);
25788
+ return emitTo(target, event2, payload);
25789
25789
  }
25790
25790
  /** @ignore */
25791
- _handleTauriEvent(event, handler) {
25792
- if (localTauriEvents2.includes(event)) {
25793
- if (!(event in this.listeners)) {
25794
- this.listeners[event] = [handler];
25791
+ _handleTauriEvent(event2, handler) {
25792
+ if (localTauriEvents2.includes(event2)) {
25793
+ if (!(event2 in this.listeners)) {
25794
+ this.listeners[event2] = [handler];
25795
25795
  } else {
25796
- this.listeners[event].push(handler);
25796
+ this.listeners[event2].push(handler);
25797
25797
  }
25798
25798
  return true;
25799
25799
  }
@@ -26034,37 +26034,37 @@ var Tevroc = (() => {
26034
26034
  * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
26035
26035
  */
26036
26036
  async onDragDropEvent(handler) {
26037
- const unlistenDragEnter = await this.listen(TauriEvent.DRAG_ENTER, (event) => {
26037
+ const unlistenDragEnter = await this.listen(TauriEvent.DRAG_ENTER, (event2) => {
26038
26038
  handler({
26039
- ...event,
26039
+ ...event2,
26040
26040
  payload: {
26041
26041
  type: "enter",
26042
- paths: event.payload.paths,
26043
- position: new PhysicalPosition(event.payload.position)
26042
+ paths: event2.payload.paths,
26043
+ position: new PhysicalPosition(event2.payload.position)
26044
26044
  }
26045
26045
  });
26046
26046
  });
26047
- const unlistenDragOver = await this.listen(TauriEvent.DRAG_OVER, (event) => {
26047
+ const unlistenDragOver = await this.listen(TauriEvent.DRAG_OVER, (event2) => {
26048
26048
  handler({
26049
- ...event,
26049
+ ...event2,
26050
26050
  payload: {
26051
26051
  type: "over",
26052
- position: new PhysicalPosition(event.payload.position)
26052
+ position: new PhysicalPosition(event2.payload.position)
26053
26053
  }
26054
26054
  });
26055
26055
  });
26056
- const unlistenDragDrop = await this.listen(TauriEvent.DRAG_DROP, (event) => {
26056
+ const unlistenDragDrop = await this.listen(TauriEvent.DRAG_DROP, (event2) => {
26057
26057
  handler({
26058
- ...event,
26058
+ ...event2,
26059
26059
  payload: {
26060
26060
  type: "drop",
26061
- paths: event.payload.paths,
26062
- position: new PhysicalPosition(event.payload.position)
26061
+ paths: event2.payload.paths,
26062
+ position: new PhysicalPosition(event2.payload.position)
26063
26063
  }
26064
26064
  });
26065
26065
  });
26066
- const unlistenDragLeave = await this.listen(TauriEvent.DRAG_LEAVE, (event) => {
26067
- handler({ ...event, payload: { type: "leave" } });
26066
+ const unlistenDragLeave = await this.listen(TauriEvent.DRAG_LEAVE, (event2) => {
26067
+ handler({ ...event2, payload: { type: "leave" } });
26068
26068
  });
26069
26069
  return () => {
26070
26070
  unlistenDragEnter();
@@ -26194,14 +26194,14 @@ var Tevroc = (() => {
26194
26194
  * @returns A promise resolving to a function to unlisten to the event.
26195
26195
  * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
26196
26196
  */
26197
- async listen(event, handler) {
26198
- if (this._handleTauriEvent(event, handler)) {
26197
+ async listen(event2, handler) {
26198
+ if (this._handleTauriEvent(event2, handler)) {
26199
26199
  return () => {
26200
- const listeners2 = this.listeners[event];
26200
+ const listeners2 = this.listeners[event2];
26201
26201
  listeners2.splice(listeners2.indexOf(handler), 1);
26202
26202
  };
26203
26203
  }
26204
- return listen(event, handler, {
26204
+ return listen(event2, handler, {
26205
26205
  target: { kind: "WebviewWindow", label: this.label }
26206
26206
  });
26207
26207
  }
@@ -26224,14 +26224,14 @@ var Tevroc = (() => {
26224
26224
  * @returns A promise resolving to a function to unlisten to the event.
26225
26225
  * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
26226
26226
  */
26227
- async once(event, handler) {
26228
- if (this._handleTauriEvent(event, handler)) {
26227
+ async once(event2, handler) {
26228
+ if (this._handleTauriEvent(event2, handler)) {
26229
26229
  return () => {
26230
- const listeners2 = this.listeners[event];
26230
+ const listeners2 = this.listeners[event2];
26231
26231
  listeners2.splice(listeners2.indexOf(handler), 1);
26232
26232
  };
26233
26233
  }
26234
- return once(event, handler, {
26234
+ return once(event2, handler, {
26235
26235
  target: { kind: "WebviewWindow", label: this.label }
26236
26236
  });
26237
26237
  }
@@ -26399,14 +26399,14 @@ var Tevroc = (() => {
26399
26399
  if (googleInitialized) return;
26400
26400
  googleInitialized = true;
26401
26401
  if (isCapacitor) {
26402
- App.addListener("appUrlOpen", (event) => {
26403
- handleCallback(event.url);
26402
+ App.addListener("appUrlOpen", (event2) => {
26403
+ handleCallback(event2.url);
26404
26404
  });
26405
26405
  }
26406
26406
  if (isTauri) {
26407
26407
  const { listen: listen2 } = await Promise.resolve().then(() => (init_event(), event_exports));
26408
- await listen2("deep-link://open-url", async (event) => {
26409
- let url = event.payload;
26408
+ await listen2("deep-link://open-url", async (event2) => {
26409
+ let url = event2.payload;
26410
26410
  if (typeof url === "object") {
26411
26411
  url = url?.url || url?.payload || null;
26412
26412
  }
@@ -26465,11 +26465,11 @@ var Tevroc = (() => {
26465
26465
  return;
26466
26466
  }
26467
26467
  authWindowRef = popup;
26468
- authMessageListener = async (event) => {
26468
+ authMessageListener = async (event2) => {
26469
26469
  const serviceOrigin = new URL(serviceUrl).origin;
26470
- if (event.origin !== serviceOrigin) return;
26471
- if (event.data?.type === "google-auth") {
26472
- const token = event.data?.token || null;
26470
+ if (event2.origin !== serviceOrigin) return;
26471
+ if (event2.data?.type === "google-auth") {
26472
+ const token = event2.data?.token || null;
26473
26473
  const url = token ? `${window.location.href}${window.location.href.includes("?") ? "&" : "?"}token=${token}` : window.location.href;
26474
26474
  await handleCallback(url);
26475
26475
  }
@@ -26551,17 +26551,17 @@ var Tevroc = (() => {
26551
26551
  if (paymentInitialized) return;
26552
26552
  paymentInitialized = true;
26553
26553
  if (isCapacitor) {
26554
- App.addListener("appUrlOpen", (event) => {
26554
+ App.addListener("appUrlOpen", (event2) => {
26555
26555
  handlePaymentCallback(
26556
- event.url,
26556
+ event2.url,
26557
26557
  externalCallback
26558
26558
  );
26559
26559
  });
26560
26560
  }
26561
26561
  if (isTauri) {
26562
26562
  const { listen: listen2 } = await Promise.resolve().then(() => (init_event(), event_exports));
26563
- await listen2("deep-link://open-url", async (event) => {
26564
- let url = event.payload;
26563
+ await listen2("deep-link://open-url", async (event2) => {
26564
+ let url = event2.payload;
26565
26565
  if (typeof url === "object") {
26566
26566
  url = url?.url || url?.payload || null;
26567
26567
  }
@@ -26628,12 +26628,12 @@ var Tevroc = (() => {
26628
26628
  }
26629
26629
  let listenerAttached = true;
26630
26630
  let timerRunning = true;
26631
- const listener = (event) => {
26631
+ const listener = (event2) => {
26632
26632
  try {
26633
26633
  const serviceOrigin = new URL(serviceUrl).origin;
26634
- if (event.origin !== serviceOrigin) return;
26635
- if (event.data?.type === "payment-result") {
26636
- const status = event.data?.status || null;
26634
+ if (event2.origin !== serviceOrigin) return;
26635
+ if (event2.data?.type === "payment-result") {
26636
+ const status = event2.data?.status || null;
26637
26637
  listenerAttached = false;
26638
26638
  timerRunning = false;
26639
26639
  window.removeEventListener("message", listener);
@@ -26677,6 +26677,7 @@ var Tevroc = (() => {
26677
26677
  __export(index_exports, {
26678
26678
  TevrocClient: () => TevrocClient,
26679
26679
  TevrocError: () => TevrocError,
26680
+ createChatbotClient: () => createChatbotClient,
26680
26681
  createClient: () => createClient
26681
26682
  });
26682
26683
 
@@ -27394,10 +27395,10 @@ var Tevroc = (() => {
27394
27395
  autoInterval = null;
27395
27396
  }
27396
27397
  }
27397
- function emit2(event, payload) {
27398
+ function emit2(event2, payload) {
27398
27399
  try {
27399
- if (!listeners2.has(event)) return;
27400
- for (const cb of listeners2.get(event)) {
27400
+ if (!listeners2.has(event2)) return;
27401
+ for (const cb of listeners2.get(event2)) {
27401
27402
  try {
27402
27403
  cb(payload);
27403
27404
  } catch (e2) {
@@ -27416,14 +27417,14 @@ var Tevroc = (() => {
27416
27417
  stopAutoSync,
27417
27418
  getQueue,
27418
27419
  // events
27419
- on: (event, cb) => {
27420
- if (!listeners2.has(event)) listeners2.set(event, /* @__PURE__ */ new Set());
27421
- listeners2.get(event).add(cb);
27422
- return () => listeners2.get(event).delete(cb);
27420
+ on: (event2, cb) => {
27421
+ if (!listeners2.has(event2)) listeners2.set(event2, /* @__PURE__ */ new Set());
27422
+ listeners2.get(event2).add(cb);
27423
+ return () => listeners2.get(event2).delete(cb);
27423
27424
  },
27424
- off: (event, cb) => {
27425
- if (!listeners2.has(event)) return;
27426
- listeners2.get(event).delete(cb);
27425
+ off: (event2, cb) => {
27426
+ if (!listeners2.has(event2)) return;
27427
+ listeners2.get(event2).delete(cb);
27427
27428
  },
27428
27429
  listConflicts: async () => {
27429
27430
  const snapshot = await store.get("conflicts");
@@ -41250,6 +41251,247 @@ var Tevroc = (() => {
41250
41251
  };
41251
41252
  }
41252
41253
 
41254
+ // src/services/agentNotifications.js
41255
+ var toList = (result) => Array.isArray(result) ? result : result?.data || [];
41256
+ var latestByTime = (records) => [...records].sort((a3, b2) => {
41257
+ const left = Number(a3.createdAt || a3.updatedAt || 0) || Date.parse(a3.createdAt || a3.updatedAt || 0) || 0;
41258
+ const right = Number(b2.createdAt || b2.updatedAt || 0) || Date.parse(b2.createdAt || b2.updatedAt || 0) || 0;
41259
+ return right - left;
41260
+ })[0] || null;
41261
+ function createAgentNotificationService(client) {
41262
+ let timer = null;
41263
+ let stopped = true;
41264
+ const seen = /* @__PURE__ */ new Map();
41265
+ const listeners2 = /* @__PURE__ */ new Set();
41266
+ const notify = (event2) => listeners2.forEach((listener) => listener(event2));
41267
+ const getSessionId = (session) => session.sessionId || session.session_id || session.id;
41268
+ const getMessages = async (sessionId, appId) => {
41269
+ const result = await client.entities.ChatMessage.query({ filter: { appId, sessionId }, limit: 100 });
41270
+ return toList(result);
41271
+ };
41272
+ const publish = (sessionId, payload) => {
41273
+ const connection = client.realtime.room(sessionId, {}, { maxReconnects: 2 });
41274
+ connection.publish({ type: "chat_message", sessionId, session_id: sessionId, message: payload, payload });
41275
+ setTimeout(() => connection.close(), 1e3);
41276
+ };
41277
+ const accept = async (session) => {
41278
+ const sessionId = getSessionId(session);
41279
+ await client.entities.ChatSession.update(session.id, {
41280
+ status: "agent_active",
41281
+ agent_email: client.agentIdentity || "agent",
41282
+ updatedAt: Date.now()
41283
+ });
41284
+ notify({ type: "accepted", sessionId, session });
41285
+ };
41286
+ const reject = async (session) => {
41287
+ const sessionId = getSessionId(session);
41288
+ await client.entities.ChatSession.update(session.id, { status: "agent_rejected", updatedAt: Date.now() });
41289
+ notify({ type: "rejected", sessionId, session });
41290
+ };
41291
+ const reply = async (session, content) => {
41292
+ const sessionId = getSessionId(session);
41293
+ if (!content?.trim()) throw new TypeError("A reply message is required.");
41294
+ const message2 = {
41295
+ id: `msg_${Date.now()}_${Math.random().toString(36).slice(2)}`,
41296
+ appId: session.appId || client.appId,
41297
+ userId: client.agentIdentity || "agent",
41298
+ sessionId,
41299
+ session_id: sessionId,
41300
+ role: "agent",
41301
+ content: content.trim(),
41302
+ createdAt: Date.now()
41303
+ };
41304
+ await client.entities.ChatMessage.create(message2);
41305
+ publish(sessionId, message2);
41306
+ notify({ type: "replied", sessionId, session, message: message2 });
41307
+ return message2;
41308
+ };
41309
+ const dispatchAction = async ({ action, sessionId, reply: text2 }) => {
41310
+ const appId = client.appId;
41311
+ const sessions = toList(await client.entities.ChatSession.query({ filter: { appId, sessionId }, limit: 1 }));
41312
+ const session = sessions[0];
41313
+ if (!session) return;
41314
+ if (action === "open") return notify({ type: "open", sessionId, session });
41315
+ if (action === "accept") return accept(session);
41316
+ if (action === "reject") return reject(session);
41317
+ if (action === "reply") return reply(session, text2);
41318
+ };
41319
+ const showNative = (request) => client.notifications.show({
41320
+ id: `agent-request-${request.sessionId}`,
41321
+ title: request.title,
41322
+ body: request.body,
41323
+ data: { sessionId: request.sessionId },
41324
+ channel: "agent_requests",
41325
+ actions: [
41326
+ { id: "accept", title: "Accept" },
41327
+ { id: "reject", title: "Reject" },
41328
+ { id: "reply", title: "Reply", input: true }
41329
+ ]
41330
+ });
41331
+ const check = async ({ appId = client.appId } = {}) => {
41332
+ const sessions = toList(await client.entities.ChatSession.query({ filter: { appId, status: "escalated" }, limit: 100 }));
41333
+ for (const session of sessions) {
41334
+ const sessionId = getSessionId(session);
41335
+ if (!sessionId) continue;
41336
+ const latest = latestByTime(await getMessages(sessionId, appId));
41337
+ const fingerprint = `${session.updatedAt || session.lastMessageAt || session.createdAt}:${latest?.id || latest?.content || ""}`;
41338
+ if (seen.get(sessionId) === fingerprint) continue;
41339
+ seen.set(sessionId, fingerprint);
41340
+ const request = {
41341
+ sessionId,
41342
+ title: `Support request from ${session.visitor_name || "a visitor"}`,
41343
+ body: latest?.content || "A visitor is requesting a human agent.",
41344
+ latestMessage: latest,
41345
+ session
41346
+ };
41347
+ await showNative(request);
41348
+ notify({ type: "request", ...request });
41349
+ }
41350
+ };
41351
+ const start = async ({ pollMs = 8e3, agentIdentity, ...options } = {}) => {
41352
+ if (agentIdentity) client.agentIdentity = agentIdentity;
41353
+ stopped = false;
41354
+ await check(options);
41355
+ clearInterval(timer);
41356
+ timer = setInterval(() => !stopped && check(options).catch((error) => notify({ type: "error", error })), pollMs);
41357
+ };
41358
+ const stop = () => {
41359
+ stopped = true;
41360
+ clearInterval(timer);
41361
+ timer = null;
41362
+ };
41363
+ const onEvent = (listener) => {
41364
+ listeners2.add(listener);
41365
+ return () => listeners2.delete(listener);
41366
+ };
41367
+ client.notifications.onAction(({ action, data, reply: text2 }) => {
41368
+ if (data?.sessionId) dispatchAction({ action, sessionId: data.sessionId, reply: text2 }).catch((error) => notify({ type: "error", error }));
41369
+ });
41370
+ return { start, stop, check, onEvent, accept, reject, reply, dispatchAction };
41371
+ }
41372
+
41373
+ // src/services/notifications.js
41374
+ var isBrowser = () => typeof window !== "undefined" && typeof Notification !== "undefined";
41375
+ function createNotificationService() {
41376
+ const listeners2 = /* @__PURE__ */ new Set();
41377
+ const scheduled = /* @__PURE__ */ new Map();
41378
+ let nativeListenerInstalled = false;
41379
+ const emit2 = (event2) => listeners2.forEach((listener) => listener(event2));
41380
+ const appPlugin = () => globalThis?.Capacitor?.Plugins?.AppNotifications;
41381
+ const installNativeListener = () => {
41382
+ if (nativeListenerInstalled) return;
41383
+ const plugin = appPlugin();
41384
+ if (!plugin?.addListener) return;
41385
+ nativeListenerInstalled = true;
41386
+ let data = event.data || {};
41387
+ if (typeof data === "string") {
41388
+ try {
41389
+ data = JSON.parse(data);
41390
+ } catch {
41391
+ data = {};
41392
+ }
41393
+ }
41394
+ plugin.addListener("notificationAction", (event2) => emit2({
41395
+ id: event2.id,
41396
+ action: event2.action || "open",
41397
+ reply: event2.reply || "",
41398
+ data,
41399
+ platform: "capacitor"
41400
+ }));
41401
+ plugin.consumePendingAction?.().catch?.(() => {
41402
+ });
41403
+ };
41404
+ const permission = async () => {
41405
+ const plugin = appPlugin();
41406
+ if (plugin?.checkPermissions) return plugin.checkPermissions();
41407
+ if (globalThis?.__TAURI_INTERNALS__) {
41408
+ try {
41409
+ const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
41410
+ return { display: await tauri.isPermissionGranted() ? "granted" : "prompt" };
41411
+ } catch {
41412
+ return { display: "denied" };
41413
+ }
41414
+ }
41415
+ return { display: isBrowser() ? Notification.permission : "denied" };
41416
+ };
41417
+ const requestPermission = async () => {
41418
+ const plugin = appPlugin();
41419
+ if (plugin?.requestPermissions) return plugin.requestPermissions();
41420
+ if (globalThis?.__TAURI_INTERNALS__) {
41421
+ try {
41422
+ const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
41423
+ return { display: await tauri.requestPermission() };
41424
+ } catch {
41425
+ return { display: "denied" };
41426
+ }
41427
+ }
41428
+ return { display: isBrowser() ? await Notification.requestPermission() : "denied" };
41429
+ };
41430
+ const show = async (options = {}) => {
41431
+ const id = String(options.id || `notification_${Date.now()}_${Math.random().toString(36).slice(2)}`);
41432
+ const request = {
41433
+ id,
41434
+ title: options.title || "Notification",
41435
+ body: options.body || "",
41436
+ data: options.data || {},
41437
+ actions: options.actions || [],
41438
+ silent: Boolean(options.silent),
41439
+ channel: options.channel || "general"
41440
+ };
41441
+ const plugin = appPlugin();
41442
+ if (plugin?.show) {
41443
+ installNativeListener();
41444
+ await plugin.show(request);
41445
+ return { id, platform: "capacitor" };
41446
+ }
41447
+ if (globalThis?.__TAURI_INTERNALS__) {
41448
+ try {
41449
+ const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
41450
+ const current = await tauri.isPermissionGranted() ? "granted" : await tauri.requestPermission();
41451
+ if (current === "granted") {
41452
+ tauri.sendNotification({ title: request.title, body: request.body, extra: request.data });
41453
+ return { id, platform: "tauri" };
41454
+ }
41455
+ } catch {
41456
+ }
41457
+ }
41458
+ if (!isBrowser()) throw new Error("Notifications are not supported on this platform.");
41459
+ const state = Notification.permission === "default" ? await Notification.requestPermission() : Notification.permission;
41460
+ if (state !== "granted") throw new Error("Notification permission was not granted.");
41461
+ const notification = new Notification(request.title, { body: request.body, tag: id, data: request.data, silent: request.silent });
41462
+ notification.onclick = () => emit2({ id, action: "open", data: request.data, platform: "web" });
41463
+ return { id, platform: "web", notification };
41464
+ };
41465
+ const schedule = async (options = {}) => {
41466
+ const at2 = new Date(options.at || Date.now()).getTime();
41467
+ const delay = Math.max(0, at2 - Date.now());
41468
+ const id = String(options.id || `notification_${at2}_${Math.random().toString(36).slice(2)}`);
41469
+ const timeout = setTimeout(() => {
41470
+ scheduled.delete(id);
41471
+ show({ ...options, id }).catch((error) => emit2({ type: "error", error }));
41472
+ }, delay);
41473
+ scheduled.set(id, timeout);
41474
+ return { id, at: at2 };
41475
+ };
41476
+ const cancel = async (id) => {
41477
+ const timeout = scheduled.get(String(id));
41478
+ if (timeout) clearTimeout(timeout);
41479
+ scheduled.delete(String(id));
41480
+ await appPlugin()?.cancel?.({ id: String(id) });
41481
+ };
41482
+ const cancelAll = async () => {
41483
+ for (const timeout of scheduled.values()) clearTimeout(timeout);
41484
+ scheduled.clear();
41485
+ await appPlugin()?.cancelAll?.();
41486
+ };
41487
+ const onAction = (listener) => {
41488
+ installNativeListener();
41489
+ listeners2.add(listener);
41490
+ return () => listeners2.delete(listener);
41491
+ };
41492
+ return { permission, requestPermission, show, schedule, cancel, cancelAll, onAction };
41493
+ }
41494
+
41253
41495
  // src/index.js
41254
41496
  init_useGoogleAuth();
41255
41497
  init_useYocoPayment();
@@ -41293,6 +41535,16 @@ var Tevroc = (() => {
41293
41535
  function createClient(options = {}) {
41294
41536
  return new TevrocClient(options);
41295
41537
  }
41538
+ function createChatbotClient(options = {}) {
41539
+ if (!options.apiKey) throw new TevrocError("apiKey is required to create a chatbot client");
41540
+ const client = new TevrocClient({ ...options, appId: void 0, token: null, headers: { ...options.headers || {}, "x-api-key": options.apiKey } });
41541
+ const request = (path, requestOptions = {}) => client.request(path, { ...requestOptions, auth: false });
41542
+ return {
41543
+ getConfig: () => request("/chatbot/config"),
41544
+ createConversation: (input = {}) => request("/chatbot/conversations", { method: "POST", body: input }),
41545
+ sendMessage: (conversationId, input) => request(`/chatbot/conversations/${encodeURIComponent(conversationId)}/messages`, { method: "POST", body: input })
41546
+ };
41547
+ }
41296
41548
  var TevrocClient = class {
41297
41549
  constructor(options = {}) {
41298
41550
  const baseUrl = options.baseUrl ?? options.url;
@@ -41331,6 +41583,8 @@ var Tevroc = (() => {
41331
41583
  this.payments = createPaymentApi(this);
41332
41584
  this.commerce = createCommerceApi(this);
41333
41585
  this.realtime = createRealtimeApi(this);
41586
+ this.notifications = createNotificationService();
41587
+ this.agentNotifications = createAgentNotificationService(this);
41334
41588
  this.shiplogic = createShiplogicApi(this);
41335
41589
  this.platform = createPlatformApi(this);
41336
41590
  this.pdf = createPdfApi(this);
@@ -41355,9 +41609,10 @@ var Tevroc = (() => {
41355
41609
  const query = options.query ? toSearchParams(options.query) : "";
41356
41610
  const url = `${this.baseUrl}${path.startsWith("/") ? path : `/${path}`}${query}`;
41357
41611
  const controller = new AbortController();
41358
- const timeout = setTimeout(() => controller.abort(), options.timeoutMs ?? this.timeoutMs);
41612
+ const timeoutMsActual = options.timeoutMs || this.timeoutMs || 2500;
41613
+ let timeout = null;
41359
41614
  const token = this.token || getStoredToken();
41360
- console.log(token, options);
41615
+ console.error(token, options);
41361
41616
  if (token && options.auth !== false) {
41362
41617
  headers.set("authorization", `Bearer ${token}`);
41363
41618
  }
@@ -41375,14 +41630,24 @@ var Tevroc = (() => {
41375
41630
  }
41376
41631
  }
41377
41632
  try {
41378
- const response = await this.fetch(url, {
41633
+ const fetchPromise = this.fetch(url, {
41379
41634
  method,
41380
41635
  headers,
41381
41636
  body,
41382
41637
  signal: options.signal ?? controller.signal
41383
41638
  });
41639
+ const timeoutPromise = new Promise((_3, reject) => {
41640
+ timeout = setTimeout(() => {
41641
+ try {
41642
+ controller.abort();
41643
+ } catch (e2) {
41644
+ }
41645
+ reject(new TevrocError("Request timed out", { code: "timeout" }));
41646
+ }, timeoutMsActual);
41647
+ });
41648
+ const response = await Promise.race([fetchPromise, timeoutPromise]);
41384
41649
  let ret = await parseResponse(response, options.parseAs);
41385
- console.log("Response from request:", ret);
41650
+ console.error("Response from request:", ret);
41386
41651
  return ret;
41387
41652
  } catch (error) {
41388
41653
  if (error?.name === "AbortError") throw new TevrocError("Request timed out", { code: "timeout" });
@@ -41411,67 +41676,88 @@ var Tevroc = (() => {
41411
41676
  const encryptRoomName = (room) => buildRealtimeRoomName(room, client.appId);
41412
41677
  const connect = (room, handlers = {}, options = {}) => {
41413
41678
  const roomName = encryptRoomName(room || options.room || "default");
41414
- const url = `${toWebSocketUrl(client.baseUrl)}/realtime/${encodeURIComponent(roomName || "default")}`;
41679
+ const encodedPath = encodeURIComponent(roomName || "default");
41680
+ const rawPath = roomName || "default";
41681
+ let url = `${toWebSocketUrl(client.baseUrl)}/realtime/${encodedPath}`;
41682
+ const rawUrl = `${toWebSocketUrl(client.baseUrl)}/realtime/${rawPath}`;
41415
41683
  const reconnectMs = options.reconnectMs ?? 3e3;
41416
41684
  const maxReconnects = options.maxReconnects ?? 5;
41417
- console.log("[tevrocsdk] realtime connect requested", { room, roomName, url, appId: client.appId, reconnectMs, maxReconnects });
41685
+ console.error("[tevrocsdk] realtime connect requested", { room, roomName, url, appId: client.appId, reconnectMs, maxReconnects });
41418
41686
  let socket = null;
41419
41687
  let reconnectTimer = null;
41420
41688
  let reconnectCount = 0;
41421
41689
  let closedByUser = false;
41690
+ const pendingMessages = [];
41691
+ const sendNow = (payload) => {
41692
+ if (socket?.readyState !== WebSocket.OPEN) return false;
41693
+ socket.send(typeof payload === "string" ? payload : JSON.stringify(payload));
41694
+ return true;
41695
+ };
41422
41696
  const cleanup = () => {
41423
41697
  if (reconnectTimer) {
41424
41698
  clearTimeout(reconnectTimer);
41425
41699
  reconnectTimer = null;
41426
41700
  }
41427
41701
  };
41702
+ let attemptedRawFallback = false;
41428
41703
  const openSocket = () => {
41429
41704
  cleanup();
41430
41705
  if (closedByUser) return;
41431
- console.log("[tevrocsdk] opening realtime socket", { room, roomName, url, appId: client.appId });
41706
+ console.error("[tevrocsdk] opening realtime socket", { room, roomName, url, appId: client.appId });
41432
41707
  socket = new WebSocket(url);
41433
- socket.addEventListener("open", (event) => {
41708
+ socket.addEventListener("open", (event2) => {
41434
41709
  reconnectCount = 0;
41435
- console.log("[tevrocsdk] realtime socket open", { room, roomName, readyState: socket.readyState, url });
41436
- handlers.open?.(event);
41710
+ console.error("[tevrocsdk] realtime socket open", { room, roomName, readyState: socket.readyState, url });
41711
+ handlers.open?.(event2);
41712
+ while (pendingMessages.length && sendNow(pendingMessages[0])) {
41713
+ pendingMessages.shift();
41714
+ }
41437
41715
  });
41438
- socket.addEventListener("message", (event) => {
41439
- let data = event.data;
41716
+ socket.addEventListener("message", (event2) => {
41717
+ let data = event2.data;
41440
41718
  try {
41441
- data = JSON.parse(event.data);
41719
+ data = JSON.parse(event2.data);
41442
41720
  } catch {
41443
41721
  }
41444
- console.log("[tevrocsdk] realtime socket message", { room, roomName, data });
41445
- handlers.message?.(data, event);
41722
+ console.error("[tevrocsdk] realtime socket message", { room, roomName, data });
41723
+ handlers.message?.(data, event2);
41446
41724
  });
41447
- socket.addEventListener("close", (event) => {
41448
- console.log("[tevrocsdk] realtime socket close", { room, roomName, code: event.code, reason: event.reason, wasClean: event.wasClean });
41449
- handlers.close?.(event);
41725
+ socket.addEventListener("close", (event2) => {
41726
+ console.log("[tevrocsdk] realtime socket close", { room, roomName, code: event2.code, reason: event2.reason, wasClean: event2.wasClean, url });
41727
+ handlers.close?.(event2);
41728
+ const wasNeverOpen = event2?.code === 1006 || socket?.readyState !== WebSocket.OPEN;
41729
+ if (wasNeverOpen && !attemptedRawFallback && rawUrl && rawUrl !== url) {
41730
+ attemptedRawFallback = true;
41731
+ console.warn("[tevrocsdk] realtime fallback to raw URL after failed encoded handshake", { encodedUrl: url, rawUrl });
41732
+ url = rawUrl;
41733
+ reconnectTimer = setTimeout(() => openSocket(), 500);
41734
+ return;
41735
+ }
41450
41736
  if (closedByUser || reconnectCount >= maxReconnects) return;
41451
41737
  reconnectTimer = setTimeout(() => {
41452
41738
  reconnectCount += 1;
41453
- console.log("[tevrocsdk] realtime retry", { room, roomName, attempt: reconnectCount, delayMs: reconnectMs });
41739
+ console.log("[tevrocsdk] realtime retry", { room, roomName, attempt: reconnectCount, delayMs: reconnectMs, url });
41454
41740
  openSocket();
41455
41741
  }, reconnectMs);
41456
41742
  });
41457
- socket.addEventListener("error", (event) => {
41458
- console.log("[tevrocsdk] realtime socket error", { room, roomName, event });
41459
- handlers.error?.(event);
41743
+ socket.addEventListener("error", (event2) => {
41744
+ console.log("[tevrocsdk] realtime socket error", { room, roomName, event: event2 });
41745
+ handlers.error?.(event2);
41460
41746
  });
41461
41747
  };
41462
41748
  openSocket();
41463
41749
  return {
41464
41750
  socket: () => socket,
41465
41751
  send: (payload) => {
41466
- const serialized = typeof payload === "string" ? payload : JSON.stringify(payload);
41467
- console.log("[tevrocsdk] realtime socket send", { room, roomName, payload, serialized, readyState: socket?.readyState });
41468
- const result = socket?.readyState === WebSocket.OPEN ? socket.send(serialized) : false;
41469
- console.log("[tevrocsdk] realtime socket send result", { room, roomName, result, readyState: socket?.readyState });
41470
- return result;
41752
+ if (sendNow(payload)) return true;
41753
+ pendingMessages.push(payload);
41754
+ console.log("[tevrocsdk] realtime message queued until the socket opens", { room, roomName, queued: pendingMessages.length });
41755
+ return true;
41471
41756
  },
41472
41757
  close: () => {
41473
41758
  closedByUser = true;
41474
41759
  cleanup();
41760
+ pendingMessages.length = 0;
41475
41761
  console.log("[tevrocsdk] realtime socket close requested", { room, roomName });
41476
41762
  socket?.close();
41477
41763
  },