tevrocsdk 0.1.46 → 0.1.48
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/package.json +1 -1
- package/tevroc-sdk.cjs.js +20 -3
- package/tevroc-sdk.cjs.js.map +2 -2
- package/tevroc-sdk.esm.js +464 -182
- package/tevroc-sdk.esm.js.map +2 -2
- package/tevroc-sdk.min.js +56 -56
- package/tevroc-sdk.umd.js +464 -182
package/tevroc-sdk.umd.js
CHANGED
|
@@ -302,8 +302,8 @@ var Tevroc = (() => {
|
|
|
302
302
|
registered: false,
|
|
303
303
|
windowEventName,
|
|
304
304
|
pluginEventName,
|
|
305
|
-
handler: (
|
|
306
|
-
this.notifyListeners(pluginEventName,
|
|
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", (
|
|
1437
|
-
this.notifyListeners("sqliteImportProgressEvent",
|
|
1436
|
+
this.jeepSqliteElement.addEventListener("jeepSqliteImportProgress", (event2) => {
|
|
1437
|
+
this.notifyListeners("sqliteImportProgressEvent", event2.detail);
|
|
1438
1438
|
});
|
|
1439
|
-
this.jeepSqliteElement.addEventListener("jeepSqliteExportProgress", (
|
|
1440
|
-
this.notifyListeners("sqliteExportProgressEvent",
|
|
1439
|
+
this.jeepSqliteElement.addEventListener("jeepSqliteExportProgress", (event2) => {
|
|
1440
|
+
this.notifyListeners("sqliteExportProgressEvent", event2.detail);
|
|
1441
1441
|
});
|
|
1442
|
-
this.jeepSqliteElement.addEventListener("jeepSqliteHTTPRequestEnded", (
|
|
1443
|
-
this.notifyListeners("sqliteHTTPRequestEndedEvent",
|
|
1442
|
+
this.jeepSqliteElement.addEventListener("jeepSqliteHTTPRequestEnded", (event2) => {
|
|
1443
|
+
this.notifyListeners("sqliteHTTPRequestEndedEvent", event2.detail);
|
|
1444
1444
|
});
|
|
1445
|
-
this.jeepSqliteElement.addEventListener("jeepSqlitePickDatabaseEnded", (
|
|
1446
|
-
this.notifyListeners("sqlitePickDatabaseEndedEvent",
|
|
1445
|
+
this.jeepSqliteElement.addEventListener("jeepSqlitePickDatabaseEnded", (event2) => {
|
|
1446
|
+
this.notifyListeners("sqlitePickDatabaseEndedEvent", event2.detail);
|
|
1447
1447
|
});
|
|
1448
|
-
this.jeepSqliteElement.addEventListener("jeepSqliteSaveDatabaseToDisk", (
|
|
1449
|
-
this.notifyListeners("sqliteSaveDatabaseToDiskEvent",
|
|
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(
|
|
13193
|
-
run(
|
|
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
|
|
13592
|
+
var event2, handler;
|
|
13593
13593
|
if (DISPATCH_EVENT) {
|
|
13594
|
-
|
|
13595
|
-
|
|
13596
|
-
|
|
13597
|
-
|
|
13598
|
-
globalThis2.dispatchEvent(
|
|
13599
|
-
} else
|
|
13600
|
-
if (!NATIVE_PROMISE_REJECTION_EVENT && (handler = globalThis2["on" + name])) handler(
|
|
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(
|
|
17657
|
+
onClick(event2) {
|
|
17658
17658
|
var {
|
|
17659
17659
|
x: x3,
|
|
17660
17660
|
y: y3
|
|
17661
|
-
} = this.mapXY(
|
|
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(
|
|
17673
|
+
onMouseMove(event2) {
|
|
17674
17674
|
var {
|
|
17675
17675
|
x: x3,
|
|
17676
17676
|
y: y3
|
|
17677
|
-
} = this.mapXY(
|
|
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(
|
|
22295
|
-
const eventTarget =
|
|
22294
|
+
static doUpgrade(event2) {
|
|
22295
|
+
const eventTarget = event2.target;
|
|
22296
22296
|
const db = eventTarget.result;
|
|
22297
|
-
switch (
|
|
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(
|
|
23722
|
-
window.__TAURI_EVENT_PLUGIN_INTERNALS__.unregisterListener(
|
|
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(
|
|
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(
|
|
23736
|
+
return async () => _unlisten(event2, eventId);
|
|
23737
23737
|
});
|
|
23738
23738
|
}
|
|
23739
|
-
async function once(
|
|
23740
|
-
return listen(
|
|
23741
|
-
void _unlisten(
|
|
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(
|
|
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,
|
|
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(
|
|
23883
|
+
constructor(event2) {
|
|
23884
23884
|
this._preventDefault = false;
|
|
23885
|
-
this.event =
|
|
23886
|
-
this.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(
|
|
24000
|
-
if (this._handleTauriEvent(
|
|
23999
|
+
async listen(event2, handler) {
|
|
24000
|
+
if (this._handleTauriEvent(event2, handler)) {
|
|
24001
24001
|
return () => {
|
|
24002
|
-
const listeners2 = this.listeners[
|
|
24002
|
+
const listeners2 = this.listeners[event2];
|
|
24003
24003
|
listeners2.splice(listeners2.indexOf(handler), 1);
|
|
24004
24004
|
};
|
|
24005
24005
|
}
|
|
24006
|
-
return listen(
|
|
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(
|
|
24030
|
-
if (this._handleTauriEvent(
|
|
24029
|
+
async once(event2, handler) {
|
|
24030
|
+
if (this._handleTauriEvent(event2, handler)) {
|
|
24031
24031
|
return () => {
|
|
24032
|
-
const listeners2 = this.listeners[
|
|
24032
|
+
const listeners2 = this.listeners[event2];
|
|
24033
24033
|
listeners2.splice(listeners2.indexOf(handler), 1);
|
|
24034
24034
|
};
|
|
24035
24035
|
}
|
|
24036
|
-
return once(
|
|
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(
|
|
24052
|
-
if (localTauriEvents.includes(
|
|
24053
|
-
for (const handler of this.listeners[
|
|
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(
|
|
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,
|
|
24077
|
-
if (localTauriEvents.includes(
|
|
24078
|
-
for (const handler of this.listeners[
|
|
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,
|
|
24087
|
+
return emitTo(target, event2, payload);
|
|
24088
24088
|
}
|
|
24089
24089
|
/** @ignore */
|
|
24090
|
-
_handleTauriEvent(
|
|
24091
|
-
if (localTauriEvents.includes(
|
|
24092
|
-
if (!(
|
|
24093
|
-
this.listeners[
|
|
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[
|
|
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 (
|
|
25391
|
-
const evt = new CloseRequestedEvent(
|
|
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, (
|
|
25424
|
+
const unlistenDrag = await this.listen(TauriEvent.DRAG_ENTER, (event2) => {
|
|
25425
25425
|
handler({
|
|
25426
|
-
...
|
|
25426
|
+
...event2,
|
|
25427
25427
|
payload: {
|
|
25428
25428
|
type: "enter",
|
|
25429
|
-
paths:
|
|
25430
|
-
position: new PhysicalPosition(
|
|
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, (
|
|
25434
|
+
const unlistenDragOver = await this.listen(TauriEvent.DRAG_OVER, (event2) => {
|
|
25435
25435
|
handler({
|
|
25436
|
-
...
|
|
25436
|
+
...event2,
|
|
25437
25437
|
payload: {
|
|
25438
25438
|
type: "over",
|
|
25439
|
-
position: new PhysicalPosition(
|
|
25439
|
+
position: new PhysicalPosition(event2.payload.position)
|
|
25440
25440
|
}
|
|
25441
25441
|
});
|
|
25442
25442
|
});
|
|
25443
|
-
const unlistenDrop = await this.listen(TauriEvent.DRAG_DROP, (
|
|
25443
|
+
const unlistenDrop = await this.listen(TauriEvent.DRAG_DROP, (event2) => {
|
|
25444
25444
|
handler({
|
|
25445
|
-
...
|
|
25445
|
+
...event2,
|
|
25446
25446
|
payload: {
|
|
25447
25447
|
type: "drop",
|
|
25448
|
-
paths:
|
|
25449
|
-
position: new PhysicalPosition(
|
|
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, (
|
|
25454
|
-
handler({ ...
|
|
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, (
|
|
25482
|
-
handler({ ...
|
|
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, (
|
|
25485
|
-
handler({ ...
|
|
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(
|
|
25699
|
-
if (this._handleTauriEvent(
|
|
25698
|
+
async listen(event2, handler) {
|
|
25699
|
+
if (this._handleTauriEvent(event2, handler)) {
|
|
25700
25700
|
return () => {
|
|
25701
|
-
const listeners2 = this.listeners[
|
|
25701
|
+
const listeners2 = this.listeners[event2];
|
|
25702
25702
|
listeners2.splice(listeners2.indexOf(handler), 1);
|
|
25703
25703
|
};
|
|
25704
25704
|
}
|
|
25705
|
-
return listen(
|
|
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(
|
|
25729
|
-
if (this._handleTauriEvent(
|
|
25728
|
+
async once(event2, handler) {
|
|
25729
|
+
if (this._handleTauriEvent(event2, handler)) {
|
|
25730
25730
|
return () => {
|
|
25731
|
-
const listeners2 = this.listeners[
|
|
25731
|
+
const listeners2 = this.listeners[event2];
|
|
25732
25732
|
listeners2.splice(listeners2.indexOf(handler), 1);
|
|
25733
25733
|
};
|
|
25734
25734
|
}
|
|
25735
|
-
return once(
|
|
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(
|
|
25752
|
-
if (localTauriEvents2.includes(
|
|
25753
|
-
for (const handler of this.listeners[
|
|
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(
|
|
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,
|
|
25778
|
-
if (localTauriEvents2.includes(
|
|
25779
|
-
for (const handler of this.listeners[
|
|
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,
|
|
25788
|
+
return emitTo(target, event2, payload);
|
|
25789
25789
|
}
|
|
25790
25790
|
/** @ignore */
|
|
25791
|
-
_handleTauriEvent(
|
|
25792
|
-
if (localTauriEvents2.includes(
|
|
25793
|
-
if (!(
|
|
25794
|
-
this.listeners[
|
|
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[
|
|
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, (
|
|
26037
|
+
const unlistenDragEnter = await this.listen(TauriEvent.DRAG_ENTER, (event2) => {
|
|
26038
26038
|
handler({
|
|
26039
|
-
...
|
|
26039
|
+
...event2,
|
|
26040
26040
|
payload: {
|
|
26041
26041
|
type: "enter",
|
|
26042
|
-
paths:
|
|
26043
|
-
position: new PhysicalPosition(
|
|
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, (
|
|
26047
|
+
const unlistenDragOver = await this.listen(TauriEvent.DRAG_OVER, (event2) => {
|
|
26048
26048
|
handler({
|
|
26049
|
-
...
|
|
26049
|
+
...event2,
|
|
26050
26050
|
payload: {
|
|
26051
26051
|
type: "over",
|
|
26052
|
-
position: new PhysicalPosition(
|
|
26052
|
+
position: new PhysicalPosition(event2.payload.position)
|
|
26053
26053
|
}
|
|
26054
26054
|
});
|
|
26055
26055
|
});
|
|
26056
|
-
const unlistenDragDrop = await this.listen(TauriEvent.DRAG_DROP, (
|
|
26056
|
+
const unlistenDragDrop = await this.listen(TauriEvent.DRAG_DROP, (event2) => {
|
|
26057
26057
|
handler({
|
|
26058
|
-
...
|
|
26058
|
+
...event2,
|
|
26059
26059
|
payload: {
|
|
26060
26060
|
type: "drop",
|
|
26061
|
-
paths:
|
|
26062
|
-
position: new PhysicalPosition(
|
|
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, (
|
|
26067
|
-
handler({ ...
|
|
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(
|
|
26198
|
-
if (this._handleTauriEvent(
|
|
26197
|
+
async listen(event2, handler) {
|
|
26198
|
+
if (this._handleTauriEvent(event2, handler)) {
|
|
26199
26199
|
return () => {
|
|
26200
|
-
const listeners2 = this.listeners[
|
|
26200
|
+
const listeners2 = this.listeners[event2];
|
|
26201
26201
|
listeners2.splice(listeners2.indexOf(handler), 1);
|
|
26202
26202
|
};
|
|
26203
26203
|
}
|
|
26204
|
-
return listen(
|
|
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(
|
|
26228
|
-
if (this._handleTauriEvent(
|
|
26227
|
+
async once(event2, handler) {
|
|
26228
|
+
if (this._handleTauriEvent(event2, handler)) {
|
|
26229
26229
|
return () => {
|
|
26230
|
-
const listeners2 = this.listeners[
|
|
26230
|
+
const listeners2 = this.listeners[event2];
|
|
26231
26231
|
listeners2.splice(listeners2.indexOf(handler), 1);
|
|
26232
26232
|
};
|
|
26233
26233
|
}
|
|
26234
|
-
return once(
|
|
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", (
|
|
26403
|
-
handleCallback(
|
|
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 (
|
|
26409
|
-
let url =
|
|
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 (
|
|
26468
|
+
authMessageListener = async (event2) => {
|
|
26469
26469
|
const serviceOrigin = new URL(serviceUrl).origin;
|
|
26470
|
-
if (
|
|
26471
|
-
if (
|
|
26472
|
-
const token =
|
|
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", (
|
|
26554
|
+
App.addListener("appUrlOpen", (event2) => {
|
|
26555
26555
|
handlePaymentCallback(
|
|
26556
|
-
|
|
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 (
|
|
26564
|
-
let url =
|
|
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 = (
|
|
26631
|
+
const listener = (event2) => {
|
|
26632
26632
|
try {
|
|
26633
26633
|
const serviceOrigin = new URL(serviceUrl).origin;
|
|
26634
|
-
if (
|
|
26635
|
-
if (
|
|
26636
|
-
const status =
|
|
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);
|
|
@@ -27394,10 +27394,10 @@ var Tevroc = (() => {
|
|
|
27394
27394
|
autoInterval = null;
|
|
27395
27395
|
}
|
|
27396
27396
|
}
|
|
27397
|
-
function emit2(
|
|
27397
|
+
function emit2(event2, payload) {
|
|
27398
27398
|
try {
|
|
27399
|
-
if (!listeners2.has(
|
|
27400
|
-
for (const cb of listeners2.get(
|
|
27399
|
+
if (!listeners2.has(event2)) return;
|
|
27400
|
+
for (const cb of listeners2.get(event2)) {
|
|
27401
27401
|
try {
|
|
27402
27402
|
cb(payload);
|
|
27403
27403
|
} catch (e2) {
|
|
@@ -27416,14 +27416,14 @@ var Tevroc = (() => {
|
|
|
27416
27416
|
stopAutoSync,
|
|
27417
27417
|
getQueue,
|
|
27418
27418
|
// events
|
|
27419
|
-
on: (
|
|
27420
|
-
if (!listeners2.has(
|
|
27421
|
-
listeners2.get(
|
|
27422
|
-
return () => listeners2.get(
|
|
27419
|
+
on: (event2, cb) => {
|
|
27420
|
+
if (!listeners2.has(event2)) listeners2.set(event2, /* @__PURE__ */ new Set());
|
|
27421
|
+
listeners2.get(event2).add(cb);
|
|
27422
|
+
return () => listeners2.get(event2).delete(cb);
|
|
27423
27423
|
},
|
|
27424
|
-
off: (
|
|
27425
|
-
if (!listeners2.has(
|
|
27426
|
-
listeners2.get(
|
|
27424
|
+
off: (event2, cb) => {
|
|
27425
|
+
if (!listeners2.has(event2)) return;
|
|
27426
|
+
listeners2.get(event2).delete(cb);
|
|
27427
27427
|
},
|
|
27428
27428
|
listConflicts: async () => {
|
|
27429
27429
|
const snapshot = await store.get("conflicts");
|
|
@@ -41250,6 +41250,247 @@ var Tevroc = (() => {
|
|
|
41250
41250
|
};
|
|
41251
41251
|
}
|
|
41252
41252
|
|
|
41253
|
+
// src/services/agentNotifications.js
|
|
41254
|
+
var toList = (result) => Array.isArray(result) ? result : result?.data || [];
|
|
41255
|
+
var latestByTime = (records) => [...records].sort((a3, b2) => {
|
|
41256
|
+
const left = Number(a3.createdAt || a3.updatedAt || 0) || Date.parse(a3.createdAt || a3.updatedAt || 0) || 0;
|
|
41257
|
+
const right = Number(b2.createdAt || b2.updatedAt || 0) || Date.parse(b2.createdAt || b2.updatedAt || 0) || 0;
|
|
41258
|
+
return right - left;
|
|
41259
|
+
})[0] || null;
|
|
41260
|
+
function createAgentNotificationService(client) {
|
|
41261
|
+
let timer = null;
|
|
41262
|
+
let stopped = true;
|
|
41263
|
+
const seen = /* @__PURE__ */ new Map();
|
|
41264
|
+
const listeners2 = /* @__PURE__ */ new Set();
|
|
41265
|
+
const notify = (event2) => listeners2.forEach((listener) => listener(event2));
|
|
41266
|
+
const getSessionId = (session) => session.sessionId || session.session_id || session.id;
|
|
41267
|
+
const getMessages = async (sessionId, appId) => {
|
|
41268
|
+
const result = await client.entities.ChatMessage.query({ filter: { appId, sessionId }, limit: 100 });
|
|
41269
|
+
return toList(result);
|
|
41270
|
+
};
|
|
41271
|
+
const publish = (sessionId, payload) => {
|
|
41272
|
+
const connection = client.realtime.room(sessionId, {}, { maxReconnects: 2 });
|
|
41273
|
+
connection.publish({ type: "chat_message", sessionId, session_id: sessionId, message: payload, payload });
|
|
41274
|
+
setTimeout(() => connection.close(), 1e3);
|
|
41275
|
+
};
|
|
41276
|
+
const accept = async (session) => {
|
|
41277
|
+
const sessionId = getSessionId(session);
|
|
41278
|
+
await client.entities.ChatSession.update(session.id, {
|
|
41279
|
+
status: "agent_active",
|
|
41280
|
+
agent_email: client.agentIdentity || "agent",
|
|
41281
|
+
updatedAt: Date.now()
|
|
41282
|
+
});
|
|
41283
|
+
notify({ type: "accepted", sessionId, session });
|
|
41284
|
+
};
|
|
41285
|
+
const reject = async (session) => {
|
|
41286
|
+
const sessionId = getSessionId(session);
|
|
41287
|
+
await client.entities.ChatSession.update(session.id, { status: "agent_rejected", updatedAt: Date.now() });
|
|
41288
|
+
notify({ type: "rejected", sessionId, session });
|
|
41289
|
+
};
|
|
41290
|
+
const reply = async (session, content) => {
|
|
41291
|
+
const sessionId = getSessionId(session);
|
|
41292
|
+
if (!content?.trim()) throw new TypeError("A reply message is required.");
|
|
41293
|
+
const message2 = {
|
|
41294
|
+
id: `msg_${Date.now()}_${Math.random().toString(36).slice(2)}`,
|
|
41295
|
+
appId: session.appId || client.appId,
|
|
41296
|
+
userId: client.agentIdentity || "agent",
|
|
41297
|
+
sessionId,
|
|
41298
|
+
session_id: sessionId,
|
|
41299
|
+
role: "agent",
|
|
41300
|
+
content: content.trim(),
|
|
41301
|
+
createdAt: Date.now()
|
|
41302
|
+
};
|
|
41303
|
+
await client.entities.ChatMessage.create(message2);
|
|
41304
|
+
publish(sessionId, message2);
|
|
41305
|
+
notify({ type: "replied", sessionId, session, message: message2 });
|
|
41306
|
+
return message2;
|
|
41307
|
+
};
|
|
41308
|
+
const dispatchAction = async ({ action, sessionId, reply: text2 }) => {
|
|
41309
|
+
const appId = client.appId;
|
|
41310
|
+
const sessions = toList(await client.entities.ChatSession.query({ filter: { appId, sessionId }, limit: 1 }));
|
|
41311
|
+
const session = sessions[0];
|
|
41312
|
+
if (!session) return;
|
|
41313
|
+
if (action === "open") return notify({ type: "open", sessionId, session });
|
|
41314
|
+
if (action === "accept") return accept(session);
|
|
41315
|
+
if (action === "reject") return reject(session);
|
|
41316
|
+
if (action === "reply") return reply(session, text2);
|
|
41317
|
+
};
|
|
41318
|
+
const showNative = (request) => client.notifications.show({
|
|
41319
|
+
id: `agent-request-${request.sessionId}`,
|
|
41320
|
+
title: request.title,
|
|
41321
|
+
body: request.body,
|
|
41322
|
+
data: { sessionId: request.sessionId },
|
|
41323
|
+
channel: "agent_requests",
|
|
41324
|
+
actions: [
|
|
41325
|
+
{ id: "accept", title: "Accept" },
|
|
41326
|
+
{ id: "reject", title: "Reject" },
|
|
41327
|
+
{ id: "reply", title: "Reply", input: true }
|
|
41328
|
+
]
|
|
41329
|
+
});
|
|
41330
|
+
const check = async ({ appId = client.appId } = {}) => {
|
|
41331
|
+
const sessions = toList(await client.entities.ChatSession.query({ filter: { appId, status: "escalated" }, limit: 100 }));
|
|
41332
|
+
for (const session of sessions) {
|
|
41333
|
+
const sessionId = getSessionId(session);
|
|
41334
|
+
if (!sessionId) continue;
|
|
41335
|
+
const latest = latestByTime(await getMessages(sessionId, appId));
|
|
41336
|
+
const fingerprint = `${session.updatedAt || session.lastMessageAt || session.createdAt}:${latest?.id || latest?.content || ""}`;
|
|
41337
|
+
if (seen.get(sessionId) === fingerprint) continue;
|
|
41338
|
+
seen.set(sessionId, fingerprint);
|
|
41339
|
+
const request = {
|
|
41340
|
+
sessionId,
|
|
41341
|
+
title: `Support request from ${session.visitor_name || "a visitor"}`,
|
|
41342
|
+
body: latest?.content || "A visitor is requesting a human agent.",
|
|
41343
|
+
latestMessage: latest,
|
|
41344
|
+
session
|
|
41345
|
+
};
|
|
41346
|
+
await showNative(request);
|
|
41347
|
+
notify({ type: "request", ...request });
|
|
41348
|
+
}
|
|
41349
|
+
};
|
|
41350
|
+
const start = async ({ pollMs = 8e3, agentIdentity, ...options } = {}) => {
|
|
41351
|
+
if (agentIdentity) client.agentIdentity = agentIdentity;
|
|
41352
|
+
stopped = false;
|
|
41353
|
+
await check(options);
|
|
41354
|
+
clearInterval(timer);
|
|
41355
|
+
timer = setInterval(() => !stopped && check(options).catch((error) => notify({ type: "error", error })), pollMs);
|
|
41356
|
+
};
|
|
41357
|
+
const stop = () => {
|
|
41358
|
+
stopped = true;
|
|
41359
|
+
clearInterval(timer);
|
|
41360
|
+
timer = null;
|
|
41361
|
+
};
|
|
41362
|
+
const onEvent = (listener) => {
|
|
41363
|
+
listeners2.add(listener);
|
|
41364
|
+
return () => listeners2.delete(listener);
|
|
41365
|
+
};
|
|
41366
|
+
client.notifications.onAction(({ action, data, reply: text2 }) => {
|
|
41367
|
+
if (data?.sessionId) dispatchAction({ action, sessionId: data.sessionId, reply: text2 }).catch((error) => notify({ type: "error", error }));
|
|
41368
|
+
});
|
|
41369
|
+
return { start, stop, check, onEvent, accept, reject, reply, dispatchAction };
|
|
41370
|
+
}
|
|
41371
|
+
|
|
41372
|
+
// src/services/notifications.js
|
|
41373
|
+
var isBrowser = () => typeof window !== "undefined" && typeof Notification !== "undefined";
|
|
41374
|
+
function createNotificationService() {
|
|
41375
|
+
const listeners2 = /* @__PURE__ */ new Set();
|
|
41376
|
+
const scheduled = /* @__PURE__ */ new Map();
|
|
41377
|
+
let nativeListenerInstalled = false;
|
|
41378
|
+
const emit2 = (event2) => listeners2.forEach((listener) => listener(event2));
|
|
41379
|
+
const appPlugin = () => globalThis?.Capacitor?.Plugins?.AppNotifications;
|
|
41380
|
+
const installNativeListener = () => {
|
|
41381
|
+
if (nativeListenerInstalled) return;
|
|
41382
|
+
const plugin = appPlugin();
|
|
41383
|
+
if (!plugin?.addListener) return;
|
|
41384
|
+
nativeListenerInstalled = true;
|
|
41385
|
+
let data = event.data || {};
|
|
41386
|
+
if (typeof data === "string") {
|
|
41387
|
+
try {
|
|
41388
|
+
data = JSON.parse(data);
|
|
41389
|
+
} catch {
|
|
41390
|
+
data = {};
|
|
41391
|
+
}
|
|
41392
|
+
}
|
|
41393
|
+
plugin.addListener("notificationAction", (event2) => emit2({
|
|
41394
|
+
id: event2.id,
|
|
41395
|
+
action: event2.action || "open",
|
|
41396
|
+
reply: event2.reply || "",
|
|
41397
|
+
data,
|
|
41398
|
+
platform: "capacitor"
|
|
41399
|
+
}));
|
|
41400
|
+
plugin.consumePendingAction?.().catch?.(() => {
|
|
41401
|
+
});
|
|
41402
|
+
};
|
|
41403
|
+
const permission = async () => {
|
|
41404
|
+
const plugin = appPlugin();
|
|
41405
|
+
if (plugin?.checkPermissions) return plugin.checkPermissions();
|
|
41406
|
+
if (globalThis?.__TAURI_INTERNALS__) {
|
|
41407
|
+
try {
|
|
41408
|
+
const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
|
|
41409
|
+
return { display: await tauri.isPermissionGranted() ? "granted" : "prompt" };
|
|
41410
|
+
} catch {
|
|
41411
|
+
return { display: "denied" };
|
|
41412
|
+
}
|
|
41413
|
+
}
|
|
41414
|
+
return { display: isBrowser() ? Notification.permission : "denied" };
|
|
41415
|
+
};
|
|
41416
|
+
const requestPermission = async () => {
|
|
41417
|
+
const plugin = appPlugin();
|
|
41418
|
+
if (plugin?.requestPermissions) return plugin.requestPermissions();
|
|
41419
|
+
if (globalThis?.__TAURI_INTERNALS__) {
|
|
41420
|
+
try {
|
|
41421
|
+
const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
|
|
41422
|
+
return { display: await tauri.requestPermission() };
|
|
41423
|
+
} catch {
|
|
41424
|
+
return { display: "denied" };
|
|
41425
|
+
}
|
|
41426
|
+
}
|
|
41427
|
+
return { display: isBrowser() ? await Notification.requestPermission() : "denied" };
|
|
41428
|
+
};
|
|
41429
|
+
const show = async (options = {}) => {
|
|
41430
|
+
const id = String(options.id || `notification_${Date.now()}_${Math.random().toString(36).slice(2)}`);
|
|
41431
|
+
const request = {
|
|
41432
|
+
id,
|
|
41433
|
+
title: options.title || "Notification",
|
|
41434
|
+
body: options.body || "",
|
|
41435
|
+
data: options.data || {},
|
|
41436
|
+
actions: options.actions || [],
|
|
41437
|
+
silent: Boolean(options.silent),
|
|
41438
|
+
channel: options.channel || "general"
|
|
41439
|
+
};
|
|
41440
|
+
const plugin = appPlugin();
|
|
41441
|
+
if (plugin?.show) {
|
|
41442
|
+
installNativeListener();
|
|
41443
|
+
await plugin.show(request);
|
|
41444
|
+
return { id, platform: "capacitor" };
|
|
41445
|
+
}
|
|
41446
|
+
if (globalThis?.__TAURI_INTERNALS__) {
|
|
41447
|
+
try {
|
|
41448
|
+
const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
|
|
41449
|
+
const current = await tauri.isPermissionGranted() ? "granted" : await tauri.requestPermission();
|
|
41450
|
+
if (current === "granted") {
|
|
41451
|
+
tauri.sendNotification({ title: request.title, body: request.body, extra: request.data });
|
|
41452
|
+
return { id, platform: "tauri" };
|
|
41453
|
+
}
|
|
41454
|
+
} catch {
|
|
41455
|
+
}
|
|
41456
|
+
}
|
|
41457
|
+
if (!isBrowser()) throw new Error("Notifications are not supported on this platform.");
|
|
41458
|
+
const state = Notification.permission === "default" ? await Notification.requestPermission() : Notification.permission;
|
|
41459
|
+
if (state !== "granted") throw new Error("Notification permission was not granted.");
|
|
41460
|
+
const notification = new Notification(request.title, { body: request.body, tag: id, data: request.data, silent: request.silent });
|
|
41461
|
+
notification.onclick = () => emit2({ id, action: "open", data: request.data, platform: "web" });
|
|
41462
|
+
return { id, platform: "web", notification };
|
|
41463
|
+
};
|
|
41464
|
+
const schedule = async (options = {}) => {
|
|
41465
|
+
const at2 = new Date(options.at || Date.now()).getTime();
|
|
41466
|
+
const delay = Math.max(0, at2 - Date.now());
|
|
41467
|
+
const id = String(options.id || `notification_${at2}_${Math.random().toString(36).slice(2)}`);
|
|
41468
|
+
const timeout = setTimeout(() => {
|
|
41469
|
+
scheduled.delete(id);
|
|
41470
|
+
show({ ...options, id }).catch((error) => emit2({ type: "error", error }));
|
|
41471
|
+
}, delay);
|
|
41472
|
+
scheduled.set(id, timeout);
|
|
41473
|
+
return { id, at: at2 };
|
|
41474
|
+
};
|
|
41475
|
+
const cancel = async (id) => {
|
|
41476
|
+
const timeout = scheduled.get(String(id));
|
|
41477
|
+
if (timeout) clearTimeout(timeout);
|
|
41478
|
+
scheduled.delete(String(id));
|
|
41479
|
+
await appPlugin()?.cancel?.({ id: String(id) });
|
|
41480
|
+
};
|
|
41481
|
+
const cancelAll = async () => {
|
|
41482
|
+
for (const timeout of scheduled.values()) clearTimeout(timeout);
|
|
41483
|
+
scheduled.clear();
|
|
41484
|
+
await appPlugin()?.cancelAll?.();
|
|
41485
|
+
};
|
|
41486
|
+
const onAction = (listener) => {
|
|
41487
|
+
installNativeListener();
|
|
41488
|
+
listeners2.add(listener);
|
|
41489
|
+
return () => listeners2.delete(listener);
|
|
41490
|
+
};
|
|
41491
|
+
return { permission, requestPermission, show, schedule, cancel, cancelAll, onAction };
|
|
41492
|
+
}
|
|
41493
|
+
|
|
41253
41494
|
// src/index.js
|
|
41254
41495
|
init_useGoogleAuth();
|
|
41255
41496
|
init_useYocoPayment();
|
|
@@ -41331,6 +41572,8 @@ var Tevroc = (() => {
|
|
|
41331
41572
|
this.payments = createPaymentApi(this);
|
|
41332
41573
|
this.commerce = createCommerceApi(this);
|
|
41333
41574
|
this.realtime = createRealtimeApi(this);
|
|
41575
|
+
this.notifications = createNotificationService();
|
|
41576
|
+
this.agentNotifications = createAgentNotificationService(this);
|
|
41334
41577
|
this.shiplogic = createShiplogicApi(this);
|
|
41335
41578
|
this.platform = createPlatformApi(this);
|
|
41336
41579
|
this.pdf = createPdfApi(this);
|
|
@@ -41355,9 +41598,10 @@ var Tevroc = (() => {
|
|
|
41355
41598
|
const query = options.query ? toSearchParams(options.query) : "";
|
|
41356
41599
|
const url = `${this.baseUrl}${path.startsWith("/") ? path : `/${path}`}${query}`;
|
|
41357
41600
|
const controller = new AbortController();
|
|
41358
|
-
const
|
|
41601
|
+
const timeoutMsActual = options.timeoutMs || this.timeoutMs || 2500;
|
|
41602
|
+
let timeout = null;
|
|
41359
41603
|
const token = this.token || getStoredToken();
|
|
41360
|
-
console.
|
|
41604
|
+
console.error(token, options);
|
|
41361
41605
|
if (token && options.auth !== false) {
|
|
41362
41606
|
headers.set("authorization", `Bearer ${token}`);
|
|
41363
41607
|
}
|
|
@@ -41375,14 +41619,24 @@ var Tevroc = (() => {
|
|
|
41375
41619
|
}
|
|
41376
41620
|
}
|
|
41377
41621
|
try {
|
|
41378
|
-
const
|
|
41622
|
+
const fetchPromise = this.fetch(url, {
|
|
41379
41623
|
method,
|
|
41380
41624
|
headers,
|
|
41381
41625
|
body,
|
|
41382
41626
|
signal: options.signal ?? controller.signal
|
|
41383
41627
|
});
|
|
41628
|
+
const timeoutPromise = new Promise((_3, reject) => {
|
|
41629
|
+
timeout = setTimeout(() => {
|
|
41630
|
+
try {
|
|
41631
|
+
controller.abort();
|
|
41632
|
+
} catch (e2) {
|
|
41633
|
+
}
|
|
41634
|
+
reject(new TevrocError("Request timed out", { code: "timeout" }));
|
|
41635
|
+
}, timeoutMsActual);
|
|
41636
|
+
});
|
|
41637
|
+
const response = await Promise.race([fetchPromise, timeoutPromise]);
|
|
41384
41638
|
let ret = await parseResponse(response, options.parseAs);
|
|
41385
|
-
console.
|
|
41639
|
+
console.error("Response from request:", ret);
|
|
41386
41640
|
return ret;
|
|
41387
41641
|
} catch (error) {
|
|
41388
41642
|
if (error?.name === "AbortError") throw new TevrocError("Request timed out", { code: "timeout" });
|
|
@@ -41411,64 +41665,88 @@ var Tevroc = (() => {
|
|
|
41411
41665
|
const encryptRoomName = (room) => buildRealtimeRoomName(room, client.appId);
|
|
41412
41666
|
const connect = (room, handlers = {}, options = {}) => {
|
|
41413
41667
|
const roomName = encryptRoomName(room || options.room || "default");
|
|
41414
|
-
const
|
|
41668
|
+
const encodedPath = encodeURIComponent(roomName || "default");
|
|
41669
|
+
const rawPath = roomName || "default";
|
|
41670
|
+
let url = `${toWebSocketUrl(client.baseUrl)}/realtime/${encodedPath}`;
|
|
41671
|
+
const rawUrl = `${toWebSocketUrl(client.baseUrl)}/realtime/${rawPath}`;
|
|
41415
41672
|
const reconnectMs = options.reconnectMs ?? 3e3;
|
|
41416
41673
|
const maxReconnects = options.maxReconnects ?? 5;
|
|
41674
|
+
console.error("[tevrocsdk] realtime connect requested", { room, roomName, url, appId: client.appId, reconnectMs, maxReconnects });
|
|
41417
41675
|
let socket = null;
|
|
41418
41676
|
let reconnectTimer = null;
|
|
41419
41677
|
let reconnectCount = 0;
|
|
41420
41678
|
let closedByUser = false;
|
|
41679
|
+
const pendingMessages = [];
|
|
41680
|
+
const sendNow = (payload) => {
|
|
41681
|
+
if (socket?.readyState !== WebSocket.OPEN) return false;
|
|
41682
|
+
socket.send(typeof payload === "string" ? payload : JSON.stringify(payload));
|
|
41683
|
+
return true;
|
|
41684
|
+
};
|
|
41421
41685
|
const cleanup = () => {
|
|
41422
41686
|
if (reconnectTimer) {
|
|
41423
41687
|
clearTimeout(reconnectTimer);
|
|
41424
41688
|
reconnectTimer = null;
|
|
41425
41689
|
}
|
|
41426
41690
|
};
|
|
41691
|
+
let attemptedRawFallback = false;
|
|
41427
41692
|
const openSocket = () => {
|
|
41428
41693
|
cleanup();
|
|
41429
41694
|
if (closedByUser) return;
|
|
41430
|
-
console.
|
|
41695
|
+
console.error("[tevrocsdk] opening realtime socket", { room, roomName, url, appId: client.appId });
|
|
41431
41696
|
socket = new WebSocket(url);
|
|
41432
|
-
socket.addEventListener("open", (
|
|
41697
|
+
socket.addEventListener("open", (event2) => {
|
|
41433
41698
|
reconnectCount = 0;
|
|
41434
|
-
console.
|
|
41435
|
-
handlers.open?.(
|
|
41699
|
+
console.error("[tevrocsdk] realtime socket open", { room, roomName, readyState: socket.readyState, url });
|
|
41700
|
+
handlers.open?.(event2);
|
|
41701
|
+
while (pendingMessages.length && sendNow(pendingMessages[0])) {
|
|
41702
|
+
pendingMessages.shift();
|
|
41703
|
+
}
|
|
41436
41704
|
});
|
|
41437
|
-
socket.addEventListener("message", (
|
|
41438
|
-
let data =
|
|
41705
|
+
socket.addEventListener("message", (event2) => {
|
|
41706
|
+
let data = event2.data;
|
|
41439
41707
|
try {
|
|
41440
|
-
data = JSON.parse(
|
|
41708
|
+
data = JSON.parse(event2.data);
|
|
41441
41709
|
} catch {
|
|
41442
41710
|
}
|
|
41443
|
-
console.
|
|
41444
|
-
handlers.message?.(data,
|
|
41711
|
+
console.error("[tevrocsdk] realtime socket message", { room, roomName, data });
|
|
41712
|
+
handlers.message?.(data, event2);
|
|
41445
41713
|
});
|
|
41446
|
-
socket.addEventListener("close", (
|
|
41447
|
-
console.log("[tevrocsdk] realtime socket close", { room, roomName, code:
|
|
41448
|
-
handlers.close?.(
|
|
41714
|
+
socket.addEventListener("close", (event2) => {
|
|
41715
|
+
console.log("[tevrocsdk] realtime socket close", { room, roomName, code: event2.code, reason: event2.reason, wasClean: event2.wasClean, url });
|
|
41716
|
+
handlers.close?.(event2);
|
|
41717
|
+
const wasNeverOpen = event2?.code === 1006 || socket?.readyState !== WebSocket.OPEN;
|
|
41718
|
+
if (wasNeverOpen && !attemptedRawFallback && rawUrl && rawUrl !== url) {
|
|
41719
|
+
attemptedRawFallback = true;
|
|
41720
|
+
console.warn("[tevrocsdk] realtime fallback to raw URL after failed encoded handshake", { encodedUrl: url, rawUrl });
|
|
41721
|
+
url = rawUrl;
|
|
41722
|
+
reconnectTimer = setTimeout(() => openSocket(), 500);
|
|
41723
|
+
return;
|
|
41724
|
+
}
|
|
41449
41725
|
if (closedByUser || reconnectCount >= maxReconnects) return;
|
|
41450
41726
|
reconnectTimer = setTimeout(() => {
|
|
41451
41727
|
reconnectCount += 1;
|
|
41452
|
-
console.log("[tevrocsdk] realtime retry", { room, roomName, attempt: reconnectCount, delayMs: reconnectMs });
|
|
41728
|
+
console.log("[tevrocsdk] realtime retry", { room, roomName, attempt: reconnectCount, delayMs: reconnectMs, url });
|
|
41453
41729
|
openSocket();
|
|
41454
41730
|
}, reconnectMs);
|
|
41455
41731
|
});
|
|
41456
|
-
socket.addEventListener("error", (
|
|
41457
|
-
console.log("[tevrocsdk] realtime socket error", { room, roomName, event });
|
|
41458
|
-
handlers.error?.(
|
|
41732
|
+
socket.addEventListener("error", (event2) => {
|
|
41733
|
+
console.log("[tevrocsdk] realtime socket error", { room, roomName, event: event2 });
|
|
41734
|
+
handlers.error?.(event2);
|
|
41459
41735
|
});
|
|
41460
41736
|
};
|
|
41461
41737
|
openSocket();
|
|
41462
41738
|
return {
|
|
41463
41739
|
socket: () => socket,
|
|
41464
41740
|
send: (payload) => {
|
|
41465
|
-
|
|
41466
|
-
|
|
41467
|
-
|
|
41741
|
+
if (sendNow(payload)) return true;
|
|
41742
|
+
pendingMessages.push(payload);
|
|
41743
|
+
console.log("[tevrocsdk] realtime message queued until the socket opens", { room, roomName, queued: pendingMessages.length });
|
|
41744
|
+
return true;
|
|
41468
41745
|
},
|
|
41469
41746
|
close: () => {
|
|
41470
41747
|
closedByUser = true;
|
|
41471
41748
|
cleanup();
|
|
41749
|
+
pendingMessages.length = 0;
|
|
41472
41750
|
console.log("[tevrocsdk] realtime socket close requested", { room, roomName });
|
|
41473
41751
|
socket?.close();
|
|
41474
41752
|
},
|
|
@@ -41484,9 +41762,13 @@ var Tevroc = (() => {
|
|
|
41484
41762
|
connect,
|
|
41485
41763
|
room: (room, handlers = {}, options = {}) => {
|
|
41486
41764
|
const connection = connect(room, handlers, options);
|
|
41765
|
+
console.log("[tevrocsdk] realtime room created", { room, options });
|
|
41487
41766
|
return {
|
|
41488
41767
|
...connection,
|
|
41489
|
-
publish: (payload) =>
|
|
41768
|
+
publish: (payload) => {
|
|
41769
|
+
console.log("[tevrocsdk] realtime publish requested", { room, payload });
|
|
41770
|
+
return connection.send(payload);
|
|
41771
|
+
}
|
|
41490
41772
|
};
|
|
41491
41773
|
},
|
|
41492
41774
|
iceServers: (config = {}) => {
|