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