tevrocsdk 0.1.48 → 0.1.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/tevroc-sdk.cjs.js +471 -184
- package/tevroc-sdk.cjs.js.map +4 -4
- package/tevroc-sdk.esm.js +11 -0
- package/tevroc-sdk.esm.js.map +4 -4
- package/tevroc-sdk.min.js +31 -31
- package/tevroc-sdk.umd.js +11 -0
package/tevroc-sdk.cjs.js
CHANGED
|
@@ -303,8 +303,8 @@ var require_index_cjs = __commonJS({
|
|
|
303
303
|
registered: false,
|
|
304
304
|
windowEventName,
|
|
305
305
|
pluginEventName,
|
|
306
|
-
handler: (
|
|
307
|
-
this.notifyListeners(pluginEventName,
|
|
306
|
+
handler: (event2) => {
|
|
307
|
+
this.notifyListeners(pluginEventName, event2);
|
|
308
308
|
}
|
|
309
309
|
};
|
|
310
310
|
}
|
|
@@ -1441,20 +1441,20 @@ var require_plugin_cjs = __commonJS({
|
|
|
1441
1441
|
await customElements.whenDefined("jeep-sqlite");
|
|
1442
1442
|
this.jeepSqliteElement = document.querySelector("jeep-sqlite");
|
|
1443
1443
|
this.ensureJeepSqliteIsAvailable();
|
|
1444
|
-
this.jeepSqliteElement.addEventListener("jeepSqliteImportProgress", (
|
|
1445
|
-
this.notifyListeners("sqliteImportProgressEvent",
|
|
1444
|
+
this.jeepSqliteElement.addEventListener("jeepSqliteImportProgress", (event2) => {
|
|
1445
|
+
this.notifyListeners("sqliteImportProgressEvent", event2.detail);
|
|
1446
1446
|
});
|
|
1447
|
-
this.jeepSqliteElement.addEventListener("jeepSqliteExportProgress", (
|
|
1448
|
-
this.notifyListeners("sqliteExportProgressEvent",
|
|
1447
|
+
this.jeepSqliteElement.addEventListener("jeepSqliteExportProgress", (event2) => {
|
|
1448
|
+
this.notifyListeners("sqliteExportProgressEvent", event2.detail);
|
|
1449
1449
|
});
|
|
1450
|
-
this.jeepSqliteElement.addEventListener("jeepSqliteHTTPRequestEnded", (
|
|
1451
|
-
this.notifyListeners("sqliteHTTPRequestEndedEvent",
|
|
1450
|
+
this.jeepSqliteElement.addEventListener("jeepSqliteHTTPRequestEnded", (event2) => {
|
|
1451
|
+
this.notifyListeners("sqliteHTTPRequestEndedEvent", event2.detail);
|
|
1452
1452
|
});
|
|
1453
|
-
this.jeepSqliteElement.addEventListener("jeepSqlitePickDatabaseEnded", (
|
|
1454
|
-
this.notifyListeners("sqlitePickDatabaseEndedEvent",
|
|
1453
|
+
this.jeepSqliteElement.addEventListener("jeepSqlitePickDatabaseEnded", (event2) => {
|
|
1454
|
+
this.notifyListeners("sqlitePickDatabaseEndedEvent", event2.detail);
|
|
1455
1455
|
});
|
|
1456
|
-
this.jeepSqliteElement.addEventListener("jeepSqliteSaveDatabaseToDisk", (
|
|
1457
|
-
this.notifyListeners("sqliteSaveDatabaseToDiskEvent",
|
|
1456
|
+
this.jeepSqliteElement.addEventListener("jeepSqliteSaveDatabaseToDisk", (event2) => {
|
|
1457
|
+
this.notifyListeners("sqliteSaveDatabaseToDiskEvent", event2.detail);
|
|
1458
1458
|
});
|
|
1459
1459
|
if (!this.isWebStoreOpen) {
|
|
1460
1460
|
this.isWebStoreOpen = await this.jeepSqliteElement.isStoreOpen();
|
|
@@ -21749,8 +21749,8 @@ var require_task = __commonJS({
|
|
|
21749
21749
|
run(id);
|
|
21750
21750
|
};
|
|
21751
21751
|
};
|
|
21752
|
-
var eventListener = function(
|
|
21753
|
-
run(
|
|
21752
|
+
var eventListener = function(event2) {
|
|
21753
|
+
run(event2.data);
|
|
21754
21754
|
};
|
|
21755
21755
|
var globalPostMessageDefer = function(id) {
|
|
21756
21756
|
globalThis2.postMessage(String2(id), $location.protocol + "//" + $location.host);
|
|
@@ -22149,15 +22149,15 @@ var require_es_promise_constructor = __commonJS({
|
|
|
22149
22149
|
});
|
|
22150
22150
|
};
|
|
22151
22151
|
var dispatchEvent = function(name, promise, reason) {
|
|
22152
|
-
var
|
|
22152
|
+
var event2, handler;
|
|
22153
22153
|
if (DISPATCH_EVENT) {
|
|
22154
|
-
|
|
22155
|
-
|
|
22156
|
-
|
|
22157
|
-
|
|
22158
|
-
globalThis2.dispatchEvent(
|
|
22159
|
-
} else
|
|
22160
|
-
if (!NATIVE_PROMISE_REJECTION_EVENT && (handler = globalThis2["on" + name])) handler(
|
|
22154
|
+
event2 = document2.createEvent("Event");
|
|
22155
|
+
event2.promise = promise;
|
|
22156
|
+
event2.reason = reason;
|
|
22157
|
+
event2.initEvent(name, false, true);
|
|
22158
|
+
globalThis2.dispatchEvent(event2);
|
|
22159
|
+
} else event2 = { promise, reason };
|
|
22160
|
+
if (!NATIVE_PROMISE_REJECTION_EVENT && (handler = globalThis2["on" + name])) handler(event2);
|
|
22161
22161
|
else if (name === UNHANDLED_REJECTION) hostReportErrors("Unhandled promise rejection", reason);
|
|
22162
22162
|
};
|
|
22163
22163
|
var onUnhandled = function(state) {
|
|
@@ -28125,8 +28125,8 @@ var require_lib2 = __commonJS({
|
|
|
28125
28125
|
}
|
|
28126
28126
|
}, {
|
|
28127
28127
|
key: "onClick",
|
|
28128
|
-
value: function onClick(
|
|
28129
|
-
var _this$mapXY = this.mapXY(
|
|
28128
|
+
value: function onClick(event2) {
|
|
28129
|
+
var _this$mapXY = this.mapXY(event2.clientX, event2.clientY), x = _this$mapXY.x, y = _this$mapXY.y;
|
|
28130
28130
|
this.events.push({
|
|
28131
28131
|
type: "onclick",
|
|
28132
28132
|
x,
|
|
@@ -28140,8 +28140,8 @@ var require_lib2 = __commonJS({
|
|
|
28140
28140
|
}
|
|
28141
28141
|
}, {
|
|
28142
28142
|
key: "onMouseMove",
|
|
28143
|
-
value: function onMouseMove(
|
|
28144
|
-
var _this$mapXY2 = this.mapXY(
|
|
28143
|
+
value: function onMouseMove(event2) {
|
|
28144
|
+
var _this$mapXY2 = this.mapXY(event2.clientX, event2.clientY), x = _this$mapXY2.x, y = _this$mapXY2.y;
|
|
28145
28145
|
this.events.push({
|
|
28146
28146
|
type: "onmousemove",
|
|
28147
28147
|
x,
|
|
@@ -42295,10 +42295,10 @@ var require_plugin_cjs4 = __commonJS({
|
|
|
42295
42295
|
};
|
|
42296
42296
|
});
|
|
42297
42297
|
}
|
|
42298
|
-
static doUpgrade(
|
|
42299
|
-
const eventTarget =
|
|
42298
|
+
static doUpgrade(event2) {
|
|
42299
|
+
const eventTarget = event2.target;
|
|
42300
42300
|
const db = eventTarget.result;
|
|
42301
|
-
switch (
|
|
42301
|
+
switch (event2.oldVersion) {
|
|
42302
42302
|
case 0:
|
|
42303
42303
|
case 1:
|
|
42304
42304
|
default: {
|
|
@@ -43678,41 +43678,41 @@ __export(event_exports, {
|
|
|
43678
43678
|
listen: () => listen,
|
|
43679
43679
|
once: () => once
|
|
43680
43680
|
});
|
|
43681
|
-
async function _unlisten(
|
|
43682
|
-
window.__TAURI_EVENT_PLUGIN_INTERNALS__.unregisterListener(
|
|
43681
|
+
async function _unlisten(event2, eventId) {
|
|
43682
|
+
window.__TAURI_EVENT_PLUGIN_INTERNALS__.unregisterListener(event2, eventId);
|
|
43683
43683
|
await invoke("plugin:event|unlisten", {
|
|
43684
|
-
event,
|
|
43684
|
+
event: event2,
|
|
43685
43685
|
eventId
|
|
43686
43686
|
});
|
|
43687
43687
|
}
|
|
43688
|
-
async function listen(
|
|
43688
|
+
async function listen(event2, handler, options) {
|
|
43689
43689
|
var _a;
|
|
43690
43690
|
const target = typeof (options === null || options === void 0 ? void 0 : options.target) === "string" ? { kind: "AnyLabel", label: options.target } : (_a = options === null || options === void 0 ? void 0 : options.target) !== null && _a !== void 0 ? _a : { kind: "Any" };
|
|
43691
43691
|
return invoke("plugin:event|listen", {
|
|
43692
|
-
event,
|
|
43692
|
+
event: event2,
|
|
43693
43693
|
target,
|
|
43694
43694
|
handler: transformCallback(handler)
|
|
43695
43695
|
}).then((eventId) => {
|
|
43696
|
-
return async () => _unlisten(
|
|
43696
|
+
return async () => _unlisten(event2, eventId);
|
|
43697
43697
|
});
|
|
43698
43698
|
}
|
|
43699
|
-
async function once(
|
|
43700
|
-
return listen(
|
|
43701
|
-
void _unlisten(
|
|
43699
|
+
async function once(event2, handler, options) {
|
|
43700
|
+
return listen(event2, (eventData) => {
|
|
43701
|
+
void _unlisten(event2, eventData.id);
|
|
43702
43702
|
handler(eventData);
|
|
43703
43703
|
}, options);
|
|
43704
43704
|
}
|
|
43705
|
-
async function emit(
|
|
43705
|
+
async function emit(event2, payload) {
|
|
43706
43706
|
await invoke("plugin:event|emit", {
|
|
43707
|
-
event,
|
|
43707
|
+
event: event2,
|
|
43708
43708
|
payload
|
|
43709
43709
|
});
|
|
43710
43710
|
}
|
|
43711
|
-
async function emitTo(target,
|
|
43711
|
+
async function emitTo(target, event2, payload) {
|
|
43712
43712
|
const eventTarget = typeof target === "string" ? { kind: "AnyLabel", label: target } : target;
|
|
43713
43713
|
await invoke("plugin:event|emit_to", {
|
|
43714
43714
|
target: eventTarget,
|
|
43715
|
-
event,
|
|
43715
|
+
event: event2,
|
|
43716
43716
|
payload
|
|
43717
43717
|
});
|
|
43718
43718
|
}
|
|
@@ -43840,10 +43840,10 @@ var init_window = __esm({
|
|
|
43840
43840
|
UserAttentionType2[UserAttentionType2["Informational"] = 2] = "Informational";
|
|
43841
43841
|
})(UserAttentionType || (UserAttentionType = {}));
|
|
43842
43842
|
CloseRequestedEvent = class {
|
|
43843
|
-
constructor(
|
|
43843
|
+
constructor(event2) {
|
|
43844
43844
|
this._preventDefault = false;
|
|
43845
|
-
this.event =
|
|
43846
|
-
this.id =
|
|
43845
|
+
this.event = event2.event;
|
|
43846
|
+
this.id = event2.id;
|
|
43847
43847
|
}
|
|
43848
43848
|
preventDefault() {
|
|
43849
43849
|
this._preventDefault = true;
|
|
@@ -43956,14 +43956,14 @@ var init_window = __esm({
|
|
|
43956
43956
|
* @returns A promise resolving to a function to unlisten to the event.
|
|
43957
43957
|
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
|
|
43958
43958
|
*/
|
|
43959
|
-
async listen(
|
|
43960
|
-
if (this._handleTauriEvent(
|
|
43959
|
+
async listen(event2, handler) {
|
|
43960
|
+
if (this._handleTauriEvent(event2, handler)) {
|
|
43961
43961
|
return () => {
|
|
43962
|
-
const listeners2 = this.listeners[
|
|
43962
|
+
const listeners2 = this.listeners[event2];
|
|
43963
43963
|
listeners2.splice(listeners2.indexOf(handler), 1);
|
|
43964
43964
|
};
|
|
43965
43965
|
}
|
|
43966
|
-
return listen(
|
|
43966
|
+
return listen(event2, handler, {
|
|
43967
43967
|
target: { kind: "Window", label: this.label }
|
|
43968
43968
|
});
|
|
43969
43969
|
}
|
|
@@ -43986,14 +43986,14 @@ var init_window = __esm({
|
|
|
43986
43986
|
* @returns A promise resolving to a function to unlisten to the event.
|
|
43987
43987
|
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
|
|
43988
43988
|
*/
|
|
43989
|
-
async once(
|
|
43990
|
-
if (this._handleTauriEvent(
|
|
43989
|
+
async once(event2, handler) {
|
|
43990
|
+
if (this._handleTauriEvent(event2, handler)) {
|
|
43991
43991
|
return () => {
|
|
43992
|
-
const listeners2 = this.listeners[
|
|
43992
|
+
const listeners2 = this.listeners[event2];
|
|
43993
43993
|
listeners2.splice(listeners2.indexOf(handler), 1);
|
|
43994
43994
|
};
|
|
43995
43995
|
}
|
|
43996
|
-
return once(
|
|
43996
|
+
return once(event2, handler, {
|
|
43997
43997
|
target: { kind: "Window", label: this.label }
|
|
43998
43998
|
});
|
|
43999
43999
|
}
|
|
@@ -44008,18 +44008,18 @@ var init_window = __esm({
|
|
|
44008
44008
|
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
|
|
44009
44009
|
* @param payload Event payload.
|
|
44010
44010
|
*/
|
|
44011
|
-
async emit(
|
|
44012
|
-
if (localTauriEvents.includes(
|
|
44013
|
-
for (const handler of this.listeners[
|
|
44011
|
+
async emit(event2, payload) {
|
|
44012
|
+
if (localTauriEvents.includes(event2)) {
|
|
44013
|
+
for (const handler of this.listeners[event2] || []) {
|
|
44014
44014
|
handler({
|
|
44015
|
-
event,
|
|
44015
|
+
event: event2,
|
|
44016
44016
|
id: -1,
|
|
44017
44017
|
payload
|
|
44018
44018
|
});
|
|
44019
44019
|
}
|
|
44020
44020
|
return;
|
|
44021
44021
|
}
|
|
44022
|
-
return emit(
|
|
44022
|
+
return emit(event2, payload);
|
|
44023
44023
|
}
|
|
44024
44024
|
/**
|
|
44025
44025
|
* Emits an event to all {@link EventTarget|targets} matching the given target.
|
|
@@ -44033,26 +44033,26 @@ var init_window = __esm({
|
|
|
44033
44033
|
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
|
|
44034
44034
|
* @param payload Event payload.
|
|
44035
44035
|
*/
|
|
44036
|
-
async emitTo(target,
|
|
44037
|
-
if (localTauriEvents.includes(
|
|
44038
|
-
for (const handler of this.listeners[
|
|
44036
|
+
async emitTo(target, event2, payload) {
|
|
44037
|
+
if (localTauriEvents.includes(event2)) {
|
|
44038
|
+
for (const handler of this.listeners[event2] || []) {
|
|
44039
44039
|
handler({
|
|
44040
|
-
event,
|
|
44040
|
+
event: event2,
|
|
44041
44041
|
id: -1,
|
|
44042
44042
|
payload
|
|
44043
44043
|
});
|
|
44044
44044
|
}
|
|
44045
44045
|
return;
|
|
44046
44046
|
}
|
|
44047
|
-
return emitTo(target,
|
|
44047
|
+
return emitTo(target, event2, payload);
|
|
44048
44048
|
}
|
|
44049
44049
|
/** @ignore */
|
|
44050
|
-
_handleTauriEvent(
|
|
44051
|
-
if (localTauriEvents.includes(
|
|
44052
|
-
if (!(
|
|
44053
|
-
this.listeners[
|
|
44050
|
+
_handleTauriEvent(event2, handler) {
|
|
44051
|
+
if (localTauriEvents.includes(event2)) {
|
|
44052
|
+
if (!(event2 in this.listeners)) {
|
|
44053
|
+
this.listeners[event2] = [handler];
|
|
44054
44054
|
} else {
|
|
44055
|
-
this.listeners[
|
|
44055
|
+
this.listeners[event2].push(handler);
|
|
44056
44056
|
}
|
|
44057
44057
|
return true;
|
|
44058
44058
|
}
|
|
@@ -45347,8 +45347,8 @@ var init_window = __esm({
|
|
|
45347
45347
|
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
|
|
45348
45348
|
*/
|
|
45349
45349
|
async onCloseRequested(handler) {
|
|
45350
|
-
return this.listen(TauriEvent.WINDOW_CLOSE_REQUESTED, async (
|
|
45351
|
-
const evt = new CloseRequestedEvent(
|
|
45350
|
+
return this.listen(TauriEvent.WINDOW_CLOSE_REQUESTED, async (event2) => {
|
|
45351
|
+
const evt = new CloseRequestedEvent(event2);
|
|
45352
45352
|
await handler(evt);
|
|
45353
45353
|
if (!evt.isPreventDefault()) {
|
|
45354
45354
|
await this.destroy();
|
|
@@ -45381,37 +45381,37 @@ var init_window = __esm({
|
|
|
45381
45381
|
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
|
|
45382
45382
|
*/
|
|
45383
45383
|
async onDragDropEvent(handler) {
|
|
45384
|
-
const unlistenDrag = await this.listen(TauriEvent.DRAG_ENTER, (
|
|
45384
|
+
const unlistenDrag = await this.listen(TauriEvent.DRAG_ENTER, (event2) => {
|
|
45385
45385
|
handler({
|
|
45386
|
-
...
|
|
45386
|
+
...event2,
|
|
45387
45387
|
payload: {
|
|
45388
45388
|
type: "enter",
|
|
45389
|
-
paths:
|
|
45390
|
-
position: new PhysicalPosition(
|
|
45389
|
+
paths: event2.payload.paths,
|
|
45390
|
+
position: new PhysicalPosition(event2.payload.position)
|
|
45391
45391
|
}
|
|
45392
45392
|
});
|
|
45393
45393
|
});
|
|
45394
|
-
const unlistenDragOver = await this.listen(TauriEvent.DRAG_OVER, (
|
|
45394
|
+
const unlistenDragOver = await this.listen(TauriEvent.DRAG_OVER, (event2) => {
|
|
45395
45395
|
handler({
|
|
45396
|
-
...
|
|
45396
|
+
...event2,
|
|
45397
45397
|
payload: {
|
|
45398
45398
|
type: "over",
|
|
45399
|
-
position: new PhysicalPosition(
|
|
45399
|
+
position: new PhysicalPosition(event2.payload.position)
|
|
45400
45400
|
}
|
|
45401
45401
|
});
|
|
45402
45402
|
});
|
|
45403
|
-
const unlistenDrop = await this.listen(TauriEvent.DRAG_DROP, (
|
|
45403
|
+
const unlistenDrop = await this.listen(TauriEvent.DRAG_DROP, (event2) => {
|
|
45404
45404
|
handler({
|
|
45405
|
-
...
|
|
45405
|
+
...event2,
|
|
45406
45406
|
payload: {
|
|
45407
45407
|
type: "drop",
|
|
45408
|
-
paths:
|
|
45409
|
-
position: new PhysicalPosition(
|
|
45408
|
+
paths: event2.payload.paths,
|
|
45409
|
+
position: new PhysicalPosition(event2.payload.position)
|
|
45410
45410
|
}
|
|
45411
45411
|
});
|
|
45412
45412
|
});
|
|
45413
|
-
const unlistenCancel = await this.listen(TauriEvent.DRAG_LEAVE, (
|
|
45414
|
-
handler({ ...
|
|
45413
|
+
const unlistenCancel = await this.listen(TauriEvent.DRAG_LEAVE, (event2) => {
|
|
45414
|
+
handler({ ...event2, payload: { type: "leave" } });
|
|
45415
45415
|
});
|
|
45416
45416
|
return () => {
|
|
45417
45417
|
unlistenDrag();
|
|
@@ -45438,11 +45438,11 @@ var init_window = __esm({
|
|
|
45438
45438
|
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
|
|
45439
45439
|
*/
|
|
45440
45440
|
async onFocusChanged(handler) {
|
|
45441
|
-
const unlistenFocus = await this.listen(TauriEvent.WINDOW_FOCUS, (
|
|
45442
|
-
handler({ ...
|
|
45441
|
+
const unlistenFocus = await this.listen(TauriEvent.WINDOW_FOCUS, (event2) => {
|
|
45442
|
+
handler({ ...event2, payload: true });
|
|
45443
45443
|
});
|
|
45444
|
-
const unlistenBlur = await this.listen(TauriEvent.WINDOW_BLUR, (
|
|
45445
|
-
handler({ ...
|
|
45444
|
+
const unlistenBlur = await this.listen(TauriEvent.WINDOW_BLUR, (event2) => {
|
|
45445
|
+
handler({ ...event2, payload: false });
|
|
45446
45446
|
});
|
|
45447
45447
|
return () => {
|
|
45448
45448
|
unlistenFocus();
|
|
@@ -45655,14 +45655,14 @@ var init_webview = __esm({
|
|
|
45655
45655
|
* @returns A promise resolving to a function to unlisten to the event.
|
|
45656
45656
|
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
|
|
45657
45657
|
*/
|
|
45658
|
-
async listen(
|
|
45659
|
-
if (this._handleTauriEvent(
|
|
45658
|
+
async listen(event2, handler) {
|
|
45659
|
+
if (this._handleTauriEvent(event2, handler)) {
|
|
45660
45660
|
return () => {
|
|
45661
|
-
const listeners2 = this.listeners[
|
|
45661
|
+
const listeners2 = this.listeners[event2];
|
|
45662
45662
|
listeners2.splice(listeners2.indexOf(handler), 1);
|
|
45663
45663
|
};
|
|
45664
45664
|
}
|
|
45665
|
-
return listen(
|
|
45665
|
+
return listen(event2, handler, {
|
|
45666
45666
|
target: { kind: "Webview", label: this.label }
|
|
45667
45667
|
});
|
|
45668
45668
|
}
|
|
@@ -45685,14 +45685,14 @@ var init_webview = __esm({
|
|
|
45685
45685
|
* @returns A promise resolving to a function to unlisten to the event.
|
|
45686
45686
|
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
|
|
45687
45687
|
*/
|
|
45688
|
-
async once(
|
|
45689
|
-
if (this._handleTauriEvent(
|
|
45688
|
+
async once(event2, handler) {
|
|
45689
|
+
if (this._handleTauriEvent(event2, handler)) {
|
|
45690
45690
|
return () => {
|
|
45691
|
-
const listeners2 = this.listeners[
|
|
45691
|
+
const listeners2 = this.listeners[event2];
|
|
45692
45692
|
listeners2.splice(listeners2.indexOf(handler), 1);
|
|
45693
45693
|
};
|
|
45694
45694
|
}
|
|
45695
|
-
return once(
|
|
45695
|
+
return once(event2, handler, {
|
|
45696
45696
|
target: { kind: "Webview", label: this.label }
|
|
45697
45697
|
});
|
|
45698
45698
|
}
|
|
@@ -45708,18 +45708,18 @@ var init_webview = __esm({
|
|
|
45708
45708
|
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
|
|
45709
45709
|
* @param payload Event payload.
|
|
45710
45710
|
*/
|
|
45711
|
-
async emit(
|
|
45712
|
-
if (localTauriEvents2.includes(
|
|
45713
|
-
for (const handler of this.listeners[
|
|
45711
|
+
async emit(event2, payload) {
|
|
45712
|
+
if (localTauriEvents2.includes(event2)) {
|
|
45713
|
+
for (const handler of this.listeners[event2] || []) {
|
|
45714
45714
|
handler({
|
|
45715
|
-
event,
|
|
45715
|
+
event: event2,
|
|
45716
45716
|
id: -1,
|
|
45717
45717
|
payload
|
|
45718
45718
|
});
|
|
45719
45719
|
}
|
|
45720
45720
|
return;
|
|
45721
45721
|
}
|
|
45722
|
-
return emit(
|
|
45722
|
+
return emit(event2, payload);
|
|
45723
45723
|
}
|
|
45724
45724
|
/**
|
|
45725
45725
|
* Emits an event to all {@link EventTarget|targets} matching the given target.
|
|
@@ -45734,26 +45734,26 @@ var init_webview = __esm({
|
|
|
45734
45734
|
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
|
|
45735
45735
|
* @param payload Event payload.
|
|
45736
45736
|
*/
|
|
45737
|
-
async emitTo(target,
|
|
45738
|
-
if (localTauriEvents2.includes(
|
|
45739
|
-
for (const handler of this.listeners[
|
|
45737
|
+
async emitTo(target, event2, payload) {
|
|
45738
|
+
if (localTauriEvents2.includes(event2)) {
|
|
45739
|
+
for (const handler of this.listeners[event2] || []) {
|
|
45740
45740
|
handler({
|
|
45741
|
-
event,
|
|
45741
|
+
event: event2,
|
|
45742
45742
|
id: -1,
|
|
45743
45743
|
payload
|
|
45744
45744
|
});
|
|
45745
45745
|
}
|
|
45746
45746
|
return;
|
|
45747
45747
|
}
|
|
45748
|
-
return emitTo(target,
|
|
45748
|
+
return emitTo(target, event2, payload);
|
|
45749
45749
|
}
|
|
45750
45750
|
/** @ignore */
|
|
45751
|
-
_handleTauriEvent(
|
|
45752
|
-
if (localTauriEvents2.includes(
|
|
45753
|
-
if (!(
|
|
45754
|
-
this.listeners[
|
|
45751
|
+
_handleTauriEvent(event2, handler) {
|
|
45752
|
+
if (localTauriEvents2.includes(event2)) {
|
|
45753
|
+
if (!(event2 in this.listeners)) {
|
|
45754
|
+
this.listeners[event2] = [handler];
|
|
45755
45755
|
} else {
|
|
45756
|
-
this.listeners[
|
|
45756
|
+
this.listeners[event2].push(handler);
|
|
45757
45757
|
}
|
|
45758
45758
|
return true;
|
|
45759
45759
|
}
|
|
@@ -45994,37 +45994,37 @@ var init_webview = __esm({
|
|
|
45994
45994
|
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
|
|
45995
45995
|
*/
|
|
45996
45996
|
async onDragDropEvent(handler) {
|
|
45997
|
-
const unlistenDragEnter = await this.listen(TauriEvent.DRAG_ENTER, (
|
|
45997
|
+
const unlistenDragEnter = await this.listen(TauriEvent.DRAG_ENTER, (event2) => {
|
|
45998
45998
|
handler({
|
|
45999
|
-
...
|
|
45999
|
+
...event2,
|
|
46000
46000
|
payload: {
|
|
46001
46001
|
type: "enter",
|
|
46002
|
-
paths:
|
|
46003
|
-
position: new PhysicalPosition(
|
|
46002
|
+
paths: event2.payload.paths,
|
|
46003
|
+
position: new PhysicalPosition(event2.payload.position)
|
|
46004
46004
|
}
|
|
46005
46005
|
});
|
|
46006
46006
|
});
|
|
46007
|
-
const unlistenDragOver = await this.listen(TauriEvent.DRAG_OVER, (
|
|
46007
|
+
const unlistenDragOver = await this.listen(TauriEvent.DRAG_OVER, (event2) => {
|
|
46008
46008
|
handler({
|
|
46009
|
-
...
|
|
46009
|
+
...event2,
|
|
46010
46010
|
payload: {
|
|
46011
46011
|
type: "over",
|
|
46012
|
-
position: new PhysicalPosition(
|
|
46012
|
+
position: new PhysicalPosition(event2.payload.position)
|
|
46013
46013
|
}
|
|
46014
46014
|
});
|
|
46015
46015
|
});
|
|
46016
|
-
const unlistenDragDrop = await this.listen(TauriEvent.DRAG_DROP, (
|
|
46016
|
+
const unlistenDragDrop = await this.listen(TauriEvent.DRAG_DROP, (event2) => {
|
|
46017
46017
|
handler({
|
|
46018
|
-
...
|
|
46018
|
+
...event2,
|
|
46019
46019
|
payload: {
|
|
46020
46020
|
type: "drop",
|
|
46021
|
-
paths:
|
|
46022
|
-
position: new PhysicalPosition(
|
|
46021
|
+
paths: event2.payload.paths,
|
|
46022
|
+
position: new PhysicalPosition(event2.payload.position)
|
|
46023
46023
|
}
|
|
46024
46024
|
});
|
|
46025
46025
|
});
|
|
46026
|
-
const unlistenDragLeave = await this.listen(TauriEvent.DRAG_LEAVE, (
|
|
46027
|
-
handler({ ...
|
|
46026
|
+
const unlistenDragLeave = await this.listen(TauriEvent.DRAG_LEAVE, (event2) => {
|
|
46027
|
+
handler({ ...event2, payload: { type: "leave" } });
|
|
46028
46028
|
});
|
|
46029
46029
|
return () => {
|
|
46030
46030
|
unlistenDragEnter();
|
|
@@ -46154,14 +46154,14 @@ var init_webviewWindow = __esm({
|
|
|
46154
46154
|
* @returns A promise resolving to a function to unlisten to the event.
|
|
46155
46155
|
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
|
|
46156
46156
|
*/
|
|
46157
|
-
async listen(
|
|
46158
|
-
if (this._handleTauriEvent(
|
|
46157
|
+
async listen(event2, handler) {
|
|
46158
|
+
if (this._handleTauriEvent(event2, handler)) {
|
|
46159
46159
|
return () => {
|
|
46160
|
-
const listeners2 = this.listeners[
|
|
46160
|
+
const listeners2 = this.listeners[event2];
|
|
46161
46161
|
listeners2.splice(listeners2.indexOf(handler), 1);
|
|
46162
46162
|
};
|
|
46163
46163
|
}
|
|
46164
|
-
return listen(
|
|
46164
|
+
return listen(event2, handler, {
|
|
46165
46165
|
target: { kind: "WebviewWindow", label: this.label }
|
|
46166
46166
|
});
|
|
46167
46167
|
}
|
|
@@ -46184,14 +46184,14 @@ var init_webviewWindow = __esm({
|
|
|
46184
46184
|
* @returns A promise resolving to a function to unlisten to the event.
|
|
46185
46185
|
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
|
|
46186
46186
|
*/
|
|
46187
|
-
async once(
|
|
46188
|
-
if (this._handleTauriEvent(
|
|
46187
|
+
async once(event2, handler) {
|
|
46188
|
+
if (this._handleTauriEvent(event2, handler)) {
|
|
46189
46189
|
return () => {
|
|
46190
|
-
const listeners2 = this.listeners[
|
|
46190
|
+
const listeners2 = this.listeners[event2];
|
|
46191
46191
|
listeners2.splice(listeners2.indexOf(handler), 1);
|
|
46192
46192
|
};
|
|
46193
46193
|
}
|
|
46194
|
-
return once(
|
|
46194
|
+
return once(event2, handler, {
|
|
46195
46195
|
target: { kind: "WebviewWindow", label: this.label }
|
|
46196
46196
|
});
|
|
46197
46197
|
}
|
|
@@ -46359,14 +46359,14 @@ var init_useGoogleAuth = __esm({
|
|
|
46359
46359
|
if (googleInitialized) return;
|
|
46360
46360
|
googleInitialized = true;
|
|
46361
46361
|
if (isCapacitor) {
|
|
46362
|
-
import_app.App.addListener("appUrlOpen", (
|
|
46363
|
-
handleCallback(
|
|
46362
|
+
import_app.App.addListener("appUrlOpen", (event2) => {
|
|
46363
|
+
handleCallback(event2.url);
|
|
46364
46364
|
});
|
|
46365
46365
|
}
|
|
46366
46366
|
if (isTauri) {
|
|
46367
46367
|
const { listen: listen2 } = await Promise.resolve().then(() => (init_event(), event_exports));
|
|
46368
|
-
await listen2("deep-link://open-url", async (
|
|
46369
|
-
let url =
|
|
46368
|
+
await listen2("deep-link://open-url", async (event2) => {
|
|
46369
|
+
let url = event2.payload;
|
|
46370
46370
|
if (typeof url === "object") {
|
|
46371
46371
|
url = url?.url || url?.payload || null;
|
|
46372
46372
|
}
|
|
@@ -46425,11 +46425,11 @@ var init_useGoogleAuth = __esm({
|
|
|
46425
46425
|
return;
|
|
46426
46426
|
}
|
|
46427
46427
|
authWindowRef = popup;
|
|
46428
|
-
authMessageListener = async (
|
|
46428
|
+
authMessageListener = async (event2) => {
|
|
46429
46429
|
const serviceOrigin = new URL(serviceUrl).origin;
|
|
46430
|
-
if (
|
|
46431
|
-
if (
|
|
46432
|
-
const token =
|
|
46430
|
+
if (event2.origin !== serviceOrigin) return;
|
|
46431
|
+
if (event2.data?.type === "google-auth") {
|
|
46432
|
+
const token = event2.data?.token || null;
|
|
46433
46433
|
const url = token ? `${window.location.href}${window.location.href.includes("?") ? "&" : "?"}token=${token}` : window.location.href;
|
|
46434
46434
|
await handleCallback(url);
|
|
46435
46435
|
}
|
|
@@ -46511,17 +46511,17 @@ var init_useYocoPayment = __esm({
|
|
|
46511
46511
|
if (paymentInitialized) return;
|
|
46512
46512
|
paymentInitialized = true;
|
|
46513
46513
|
if (isCapacitor) {
|
|
46514
|
-
import_app2.App.addListener("appUrlOpen", (
|
|
46514
|
+
import_app2.App.addListener("appUrlOpen", (event2) => {
|
|
46515
46515
|
handlePaymentCallback(
|
|
46516
|
-
|
|
46516
|
+
event2.url,
|
|
46517
46517
|
externalCallback
|
|
46518
46518
|
);
|
|
46519
46519
|
});
|
|
46520
46520
|
}
|
|
46521
46521
|
if (isTauri) {
|
|
46522
46522
|
const { listen: listen2 } = await Promise.resolve().then(() => (init_event(), event_exports));
|
|
46523
|
-
await listen2("deep-link://open-url", async (
|
|
46524
|
-
let url =
|
|
46523
|
+
await listen2("deep-link://open-url", async (event2) => {
|
|
46524
|
+
let url = event2.payload;
|
|
46525
46525
|
if (typeof url === "object") {
|
|
46526
46526
|
url = url?.url || url?.payload || null;
|
|
46527
46527
|
}
|
|
@@ -46588,12 +46588,12 @@ var init_useYocoPayment = __esm({
|
|
|
46588
46588
|
}
|
|
46589
46589
|
let listenerAttached = true;
|
|
46590
46590
|
let timerRunning = true;
|
|
46591
|
-
const listener = (
|
|
46591
|
+
const listener = (event2) => {
|
|
46592
46592
|
try {
|
|
46593
46593
|
const serviceOrigin = new URL(serviceUrl).origin;
|
|
46594
|
-
if (
|
|
46595
|
-
if (
|
|
46596
|
-
const status =
|
|
46594
|
+
if (event2.origin !== serviceOrigin) return;
|
|
46595
|
+
if (event2.data?.type === "payment-result") {
|
|
46596
|
+
const status = event2.data?.status || null;
|
|
46597
46597
|
listenerAttached = false;
|
|
46598
46598
|
timerRunning = false;
|
|
46599
46599
|
window.removeEventListener("message", listener);
|
|
@@ -46637,6 +46637,7 @@ var index_exports = {};
|
|
|
46637
46637
|
__export(index_exports, {
|
|
46638
46638
|
TevrocClient: () => TevrocClient,
|
|
46639
46639
|
TevrocError: () => TevrocError,
|
|
46640
|
+
createChatbotClient: () => createChatbotClient,
|
|
46640
46641
|
createClient: () => createClient
|
|
46641
46642
|
});
|
|
46642
46643
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -47355,10 +47356,10 @@ function createOfflineManager(client) {
|
|
|
47355
47356
|
autoInterval = null;
|
|
47356
47357
|
}
|
|
47357
47358
|
}
|
|
47358
|
-
function emit2(
|
|
47359
|
+
function emit2(event2, payload) {
|
|
47359
47360
|
try {
|
|
47360
|
-
if (!listeners2.has(
|
|
47361
|
-
for (const cb of listeners2.get(
|
|
47361
|
+
if (!listeners2.has(event2)) return;
|
|
47362
|
+
for (const cb of listeners2.get(event2)) {
|
|
47362
47363
|
try {
|
|
47363
47364
|
cb(payload);
|
|
47364
47365
|
} catch (e) {
|
|
@@ -47377,14 +47378,14 @@ function createOfflineManager(client) {
|
|
|
47377
47378
|
stopAutoSync,
|
|
47378
47379
|
getQueue,
|
|
47379
47380
|
// events
|
|
47380
|
-
on: (
|
|
47381
|
-
if (!listeners2.has(
|
|
47382
|
-
listeners2.get(
|
|
47383
|
-
return () => listeners2.get(
|
|
47381
|
+
on: (event2, cb) => {
|
|
47382
|
+
if (!listeners2.has(event2)) listeners2.set(event2, /* @__PURE__ */ new Set());
|
|
47383
|
+
listeners2.get(event2).add(cb);
|
|
47384
|
+
return () => listeners2.get(event2).delete(cb);
|
|
47384
47385
|
},
|
|
47385
|
-
off: (
|
|
47386
|
-
if (!listeners2.has(
|
|
47387
|
-
listeners2.get(
|
|
47386
|
+
off: (event2, cb) => {
|
|
47387
|
+
if (!listeners2.has(event2)) return;
|
|
47388
|
+
listeners2.get(event2).delete(cb);
|
|
47388
47389
|
},
|
|
47389
47390
|
listConflicts: async () => {
|
|
47390
47391
|
const snapshot = await store.get("conflicts");
|
|
@@ -47724,6 +47725,247 @@ function createPdfApi() {
|
|
|
47724
47725
|
};
|
|
47725
47726
|
}
|
|
47726
47727
|
|
|
47728
|
+
// src/services/agentNotifications.js
|
|
47729
|
+
var toList = (result) => Array.isArray(result) ? result : result?.data || [];
|
|
47730
|
+
var latestByTime = (records) => [...records].sort((a, b) => {
|
|
47731
|
+
const left = Number(a.createdAt || a.updatedAt || 0) || Date.parse(a.createdAt || a.updatedAt || 0) || 0;
|
|
47732
|
+
const right = Number(b.createdAt || b.updatedAt || 0) || Date.parse(b.createdAt || b.updatedAt || 0) || 0;
|
|
47733
|
+
return right - left;
|
|
47734
|
+
})[0] || null;
|
|
47735
|
+
function createAgentNotificationService(client) {
|
|
47736
|
+
let timer = null;
|
|
47737
|
+
let stopped = true;
|
|
47738
|
+
const seen = /* @__PURE__ */ new Map();
|
|
47739
|
+
const listeners2 = /* @__PURE__ */ new Set();
|
|
47740
|
+
const notify = (event2) => listeners2.forEach((listener) => listener(event2));
|
|
47741
|
+
const getSessionId = (session) => session.sessionId || session.session_id || session.id;
|
|
47742
|
+
const getMessages = async (sessionId, appId) => {
|
|
47743
|
+
const result = await client.entities.ChatMessage.query({ filter: { appId, sessionId }, limit: 100 });
|
|
47744
|
+
return toList(result);
|
|
47745
|
+
};
|
|
47746
|
+
const publish = (sessionId, payload) => {
|
|
47747
|
+
const connection = client.realtime.room(sessionId, {}, { maxReconnects: 2 });
|
|
47748
|
+
connection.publish({ type: "chat_message", sessionId, session_id: sessionId, message: payload, payload });
|
|
47749
|
+
setTimeout(() => connection.close(), 1e3);
|
|
47750
|
+
};
|
|
47751
|
+
const accept = async (session) => {
|
|
47752
|
+
const sessionId = getSessionId(session);
|
|
47753
|
+
await client.entities.ChatSession.update(session.id, {
|
|
47754
|
+
status: "agent_active",
|
|
47755
|
+
agent_email: client.agentIdentity || "agent",
|
|
47756
|
+
updatedAt: Date.now()
|
|
47757
|
+
});
|
|
47758
|
+
notify({ type: "accepted", sessionId, session });
|
|
47759
|
+
};
|
|
47760
|
+
const reject = async (session) => {
|
|
47761
|
+
const sessionId = getSessionId(session);
|
|
47762
|
+
await client.entities.ChatSession.update(session.id, { status: "agent_rejected", updatedAt: Date.now() });
|
|
47763
|
+
notify({ type: "rejected", sessionId, session });
|
|
47764
|
+
};
|
|
47765
|
+
const reply = async (session, content) => {
|
|
47766
|
+
const sessionId = getSessionId(session);
|
|
47767
|
+
if (!content?.trim()) throw new TypeError("A reply message is required.");
|
|
47768
|
+
const message2 = {
|
|
47769
|
+
id: `msg_${Date.now()}_${Math.random().toString(36).slice(2)}`,
|
|
47770
|
+
appId: session.appId || client.appId,
|
|
47771
|
+
userId: client.agentIdentity || "agent",
|
|
47772
|
+
sessionId,
|
|
47773
|
+
session_id: sessionId,
|
|
47774
|
+
role: "agent",
|
|
47775
|
+
content: content.trim(),
|
|
47776
|
+
createdAt: Date.now()
|
|
47777
|
+
};
|
|
47778
|
+
await client.entities.ChatMessage.create(message2);
|
|
47779
|
+
publish(sessionId, message2);
|
|
47780
|
+
notify({ type: "replied", sessionId, session, message: message2 });
|
|
47781
|
+
return message2;
|
|
47782
|
+
};
|
|
47783
|
+
const dispatchAction = async ({ action, sessionId, reply: text }) => {
|
|
47784
|
+
const appId = client.appId;
|
|
47785
|
+
const sessions = toList(await client.entities.ChatSession.query({ filter: { appId, sessionId }, limit: 1 }));
|
|
47786
|
+
const session = sessions[0];
|
|
47787
|
+
if (!session) return;
|
|
47788
|
+
if (action === "open") return notify({ type: "open", sessionId, session });
|
|
47789
|
+
if (action === "accept") return accept(session);
|
|
47790
|
+
if (action === "reject") return reject(session);
|
|
47791
|
+
if (action === "reply") return reply(session, text);
|
|
47792
|
+
};
|
|
47793
|
+
const showNative = (request) => client.notifications.show({
|
|
47794
|
+
id: `agent-request-${request.sessionId}`,
|
|
47795
|
+
title: request.title,
|
|
47796
|
+
body: request.body,
|
|
47797
|
+
data: { sessionId: request.sessionId },
|
|
47798
|
+
channel: "agent_requests",
|
|
47799
|
+
actions: [
|
|
47800
|
+
{ id: "accept", title: "Accept" },
|
|
47801
|
+
{ id: "reject", title: "Reject" },
|
|
47802
|
+
{ id: "reply", title: "Reply", input: true }
|
|
47803
|
+
]
|
|
47804
|
+
});
|
|
47805
|
+
const check = async ({ appId = client.appId } = {}) => {
|
|
47806
|
+
const sessions = toList(await client.entities.ChatSession.query({ filter: { appId, status: "escalated" }, limit: 100 }));
|
|
47807
|
+
for (const session of sessions) {
|
|
47808
|
+
const sessionId = getSessionId(session);
|
|
47809
|
+
if (!sessionId) continue;
|
|
47810
|
+
const latest = latestByTime(await getMessages(sessionId, appId));
|
|
47811
|
+
const fingerprint = `${session.updatedAt || session.lastMessageAt || session.createdAt}:${latest?.id || latest?.content || ""}`;
|
|
47812
|
+
if (seen.get(sessionId) === fingerprint) continue;
|
|
47813
|
+
seen.set(sessionId, fingerprint);
|
|
47814
|
+
const request = {
|
|
47815
|
+
sessionId,
|
|
47816
|
+
title: `Support request from ${session.visitor_name || "a visitor"}`,
|
|
47817
|
+
body: latest?.content || "A visitor is requesting a human agent.",
|
|
47818
|
+
latestMessage: latest,
|
|
47819
|
+
session
|
|
47820
|
+
};
|
|
47821
|
+
await showNative(request);
|
|
47822
|
+
notify({ type: "request", ...request });
|
|
47823
|
+
}
|
|
47824
|
+
};
|
|
47825
|
+
const start = async ({ pollMs = 8e3, agentIdentity, ...options } = {}) => {
|
|
47826
|
+
if (agentIdentity) client.agentIdentity = agentIdentity;
|
|
47827
|
+
stopped = false;
|
|
47828
|
+
await check(options);
|
|
47829
|
+
clearInterval(timer);
|
|
47830
|
+
timer = setInterval(() => !stopped && check(options).catch((error) => notify({ type: "error", error })), pollMs);
|
|
47831
|
+
};
|
|
47832
|
+
const stop = () => {
|
|
47833
|
+
stopped = true;
|
|
47834
|
+
clearInterval(timer);
|
|
47835
|
+
timer = null;
|
|
47836
|
+
};
|
|
47837
|
+
const onEvent = (listener) => {
|
|
47838
|
+
listeners2.add(listener);
|
|
47839
|
+
return () => listeners2.delete(listener);
|
|
47840
|
+
};
|
|
47841
|
+
client.notifications.onAction(({ action, data, reply: text }) => {
|
|
47842
|
+
if (data?.sessionId) dispatchAction({ action, sessionId: data.sessionId, reply: text }).catch((error) => notify({ type: "error", error }));
|
|
47843
|
+
});
|
|
47844
|
+
return { start, stop, check, onEvent, accept, reject, reply, dispatchAction };
|
|
47845
|
+
}
|
|
47846
|
+
|
|
47847
|
+
// src/services/notifications.js
|
|
47848
|
+
var isBrowser = () => typeof window !== "undefined" && typeof Notification !== "undefined";
|
|
47849
|
+
function createNotificationService() {
|
|
47850
|
+
const listeners2 = /* @__PURE__ */ new Set();
|
|
47851
|
+
const scheduled = /* @__PURE__ */ new Map();
|
|
47852
|
+
let nativeListenerInstalled = false;
|
|
47853
|
+
const emit2 = (event2) => listeners2.forEach((listener) => listener(event2));
|
|
47854
|
+
const appPlugin = () => globalThis?.Capacitor?.Plugins?.AppNotifications;
|
|
47855
|
+
const installNativeListener = () => {
|
|
47856
|
+
if (nativeListenerInstalled) return;
|
|
47857
|
+
const plugin = appPlugin();
|
|
47858
|
+
if (!plugin?.addListener) return;
|
|
47859
|
+
nativeListenerInstalled = true;
|
|
47860
|
+
let data = event.data || {};
|
|
47861
|
+
if (typeof data === "string") {
|
|
47862
|
+
try {
|
|
47863
|
+
data = JSON.parse(data);
|
|
47864
|
+
} catch {
|
|
47865
|
+
data = {};
|
|
47866
|
+
}
|
|
47867
|
+
}
|
|
47868
|
+
plugin.addListener("notificationAction", (event2) => emit2({
|
|
47869
|
+
id: event2.id,
|
|
47870
|
+
action: event2.action || "open",
|
|
47871
|
+
reply: event2.reply || "",
|
|
47872
|
+
data,
|
|
47873
|
+
platform: "capacitor"
|
|
47874
|
+
}));
|
|
47875
|
+
plugin.consumePendingAction?.().catch?.(() => {
|
|
47876
|
+
});
|
|
47877
|
+
};
|
|
47878
|
+
const permission = async () => {
|
|
47879
|
+
const plugin = appPlugin();
|
|
47880
|
+
if (plugin?.checkPermissions) return plugin.checkPermissions();
|
|
47881
|
+
if (globalThis?.__TAURI_INTERNALS__) {
|
|
47882
|
+
try {
|
|
47883
|
+
const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
|
|
47884
|
+
return { display: await tauri.isPermissionGranted() ? "granted" : "prompt" };
|
|
47885
|
+
} catch {
|
|
47886
|
+
return { display: "denied" };
|
|
47887
|
+
}
|
|
47888
|
+
}
|
|
47889
|
+
return { display: isBrowser() ? Notification.permission : "denied" };
|
|
47890
|
+
};
|
|
47891
|
+
const requestPermission = async () => {
|
|
47892
|
+
const plugin = appPlugin();
|
|
47893
|
+
if (plugin?.requestPermissions) return plugin.requestPermissions();
|
|
47894
|
+
if (globalThis?.__TAURI_INTERNALS__) {
|
|
47895
|
+
try {
|
|
47896
|
+
const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
|
|
47897
|
+
return { display: await tauri.requestPermission() };
|
|
47898
|
+
} catch {
|
|
47899
|
+
return { display: "denied" };
|
|
47900
|
+
}
|
|
47901
|
+
}
|
|
47902
|
+
return { display: isBrowser() ? await Notification.requestPermission() : "denied" };
|
|
47903
|
+
};
|
|
47904
|
+
const show = async (options = {}) => {
|
|
47905
|
+
const id = String(options.id || `notification_${Date.now()}_${Math.random().toString(36).slice(2)}`);
|
|
47906
|
+
const request = {
|
|
47907
|
+
id,
|
|
47908
|
+
title: options.title || "Notification",
|
|
47909
|
+
body: options.body || "",
|
|
47910
|
+
data: options.data || {},
|
|
47911
|
+
actions: options.actions || [],
|
|
47912
|
+
silent: Boolean(options.silent),
|
|
47913
|
+
channel: options.channel || "general"
|
|
47914
|
+
};
|
|
47915
|
+
const plugin = appPlugin();
|
|
47916
|
+
if (plugin?.show) {
|
|
47917
|
+
installNativeListener();
|
|
47918
|
+
await plugin.show(request);
|
|
47919
|
+
return { id, platform: "capacitor" };
|
|
47920
|
+
}
|
|
47921
|
+
if (globalThis?.__TAURI_INTERNALS__) {
|
|
47922
|
+
try {
|
|
47923
|
+
const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
|
|
47924
|
+
const current = await tauri.isPermissionGranted() ? "granted" : await tauri.requestPermission();
|
|
47925
|
+
if (current === "granted") {
|
|
47926
|
+
tauri.sendNotification({ title: request.title, body: request.body, extra: request.data });
|
|
47927
|
+
return { id, platform: "tauri" };
|
|
47928
|
+
}
|
|
47929
|
+
} catch {
|
|
47930
|
+
}
|
|
47931
|
+
}
|
|
47932
|
+
if (!isBrowser()) throw new Error("Notifications are not supported on this platform.");
|
|
47933
|
+
const state = Notification.permission === "default" ? await Notification.requestPermission() : Notification.permission;
|
|
47934
|
+
if (state !== "granted") throw new Error("Notification permission was not granted.");
|
|
47935
|
+
const notification = new Notification(request.title, { body: request.body, tag: id, data: request.data, silent: request.silent });
|
|
47936
|
+
notification.onclick = () => emit2({ id, action: "open", data: request.data, platform: "web" });
|
|
47937
|
+
return { id, platform: "web", notification };
|
|
47938
|
+
};
|
|
47939
|
+
const schedule = async (options = {}) => {
|
|
47940
|
+
const at = new Date(options.at || Date.now()).getTime();
|
|
47941
|
+
const delay = Math.max(0, at - Date.now());
|
|
47942
|
+
const id = String(options.id || `notification_${at}_${Math.random().toString(36).slice(2)}`);
|
|
47943
|
+
const timeout = setTimeout(() => {
|
|
47944
|
+
scheduled.delete(id);
|
|
47945
|
+
show({ ...options, id }).catch((error) => emit2({ type: "error", error }));
|
|
47946
|
+
}, delay);
|
|
47947
|
+
scheduled.set(id, timeout);
|
|
47948
|
+
return { id, at };
|
|
47949
|
+
};
|
|
47950
|
+
const cancel = async (id) => {
|
|
47951
|
+
const timeout = scheduled.get(String(id));
|
|
47952
|
+
if (timeout) clearTimeout(timeout);
|
|
47953
|
+
scheduled.delete(String(id));
|
|
47954
|
+
await appPlugin()?.cancel?.({ id: String(id) });
|
|
47955
|
+
};
|
|
47956
|
+
const cancelAll = async () => {
|
|
47957
|
+
for (const timeout of scheduled.values()) clearTimeout(timeout);
|
|
47958
|
+
scheduled.clear();
|
|
47959
|
+
await appPlugin()?.cancelAll?.();
|
|
47960
|
+
};
|
|
47961
|
+
const onAction = (listener) => {
|
|
47962
|
+
installNativeListener();
|
|
47963
|
+
listeners2.add(listener);
|
|
47964
|
+
return () => listeners2.delete(listener);
|
|
47965
|
+
};
|
|
47966
|
+
return { permission, requestPermission, show, schedule, cancel, cancelAll, onAction };
|
|
47967
|
+
}
|
|
47968
|
+
|
|
47727
47969
|
// src/index.js
|
|
47728
47970
|
init_useGoogleAuth();
|
|
47729
47971
|
init_useYocoPayment();
|
|
@@ -47767,6 +48009,16 @@ function buildRealtimeRoomName(value, appId = "") {
|
|
|
47767
48009
|
function createClient(options = {}) {
|
|
47768
48010
|
return new TevrocClient(options);
|
|
47769
48011
|
}
|
|
48012
|
+
function createChatbotClient(options = {}) {
|
|
48013
|
+
if (!options.apiKey) throw new TevrocError("apiKey is required to create a chatbot client");
|
|
48014
|
+
const client = new TevrocClient({ ...options, appId: void 0, token: null, headers: { ...options.headers || {}, "x-api-key": options.apiKey } });
|
|
48015
|
+
const request = (path, requestOptions = {}) => client.request(path, { ...requestOptions, auth: false });
|
|
48016
|
+
return {
|
|
48017
|
+
getConfig: () => request("/chatbot/config"),
|
|
48018
|
+
createConversation: (input = {}) => request("/chatbot/conversations", { method: "POST", body: input }),
|
|
48019
|
+
sendMessage: (conversationId, input) => request(`/chatbot/conversations/${encodeURIComponent(conversationId)}/messages`, { method: "POST", body: input })
|
|
48020
|
+
};
|
|
48021
|
+
}
|
|
47770
48022
|
var TevrocClient = class {
|
|
47771
48023
|
constructor(options = {}) {
|
|
47772
48024
|
const baseUrl = options.baseUrl ?? options.url;
|
|
@@ -47805,6 +48057,8 @@ var TevrocClient = class {
|
|
|
47805
48057
|
this.payments = createPaymentApi(this);
|
|
47806
48058
|
this.commerce = createCommerceApi(this);
|
|
47807
48059
|
this.realtime = createRealtimeApi(this);
|
|
48060
|
+
this.notifications = createNotificationService();
|
|
48061
|
+
this.agentNotifications = createAgentNotificationService(this);
|
|
47808
48062
|
this.shiplogic = createShiplogicApi(this);
|
|
47809
48063
|
this.platform = createPlatformApi(this);
|
|
47810
48064
|
this.pdf = createPdfApi(this);
|
|
@@ -47829,9 +48083,10 @@ var TevrocClient = class {
|
|
|
47829
48083
|
const query = options.query ? toSearchParams(options.query) : "";
|
|
47830
48084
|
const url = `${this.baseUrl}${path.startsWith("/") ? path : `/${path}`}${query}`;
|
|
47831
48085
|
const controller = new AbortController();
|
|
47832
|
-
const
|
|
48086
|
+
const timeoutMsActual = options.timeoutMs || this.timeoutMs || 2500;
|
|
48087
|
+
let timeout = null;
|
|
47833
48088
|
const token = this.token || getStoredToken();
|
|
47834
|
-
console.
|
|
48089
|
+
console.error(token, options);
|
|
47835
48090
|
if (token && options.auth !== false) {
|
|
47836
48091
|
headers.set("authorization", `Bearer ${token}`);
|
|
47837
48092
|
}
|
|
@@ -47849,14 +48104,24 @@ var TevrocClient = class {
|
|
|
47849
48104
|
}
|
|
47850
48105
|
}
|
|
47851
48106
|
try {
|
|
47852
|
-
const
|
|
48107
|
+
const fetchPromise = this.fetch(url, {
|
|
47853
48108
|
method,
|
|
47854
48109
|
headers,
|
|
47855
48110
|
body,
|
|
47856
48111
|
signal: options.signal ?? controller.signal
|
|
47857
48112
|
});
|
|
48113
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
48114
|
+
timeout = setTimeout(() => {
|
|
48115
|
+
try {
|
|
48116
|
+
controller.abort();
|
|
48117
|
+
} catch (e) {
|
|
48118
|
+
}
|
|
48119
|
+
reject(new TevrocError("Request timed out", { code: "timeout" }));
|
|
48120
|
+
}, timeoutMsActual);
|
|
48121
|
+
});
|
|
48122
|
+
const response = await Promise.race([fetchPromise, timeoutPromise]);
|
|
47858
48123
|
let ret = await parseResponse(response, options.parseAs);
|
|
47859
|
-
console.
|
|
48124
|
+
console.error("Response from request:", ret);
|
|
47860
48125
|
return ret;
|
|
47861
48126
|
} catch (error) {
|
|
47862
48127
|
if (error?.name === "AbortError") throw new TevrocError("Request timed out", { code: "timeout" });
|
|
@@ -47885,67 +48150,88 @@ function createRealtimeApi(client) {
|
|
|
47885
48150
|
const encryptRoomName = (room) => buildRealtimeRoomName(room, client.appId);
|
|
47886
48151
|
const connect = (room, handlers = {}, options = {}) => {
|
|
47887
48152
|
const roomName = encryptRoomName(room || options.room || "default");
|
|
47888
|
-
const
|
|
48153
|
+
const encodedPath = encodeURIComponent(roomName || "default");
|
|
48154
|
+
const rawPath = roomName || "default";
|
|
48155
|
+
let url = `${toWebSocketUrl(client.baseUrl)}/realtime/${encodedPath}`;
|
|
48156
|
+
const rawUrl = `${toWebSocketUrl(client.baseUrl)}/realtime/${rawPath}`;
|
|
47889
48157
|
const reconnectMs = options.reconnectMs ?? 3e3;
|
|
47890
48158
|
const maxReconnects = options.maxReconnects ?? 5;
|
|
47891
|
-
console.
|
|
48159
|
+
console.error("[tevrocsdk] realtime connect requested", { room, roomName, url, appId: client.appId, reconnectMs, maxReconnects });
|
|
47892
48160
|
let socket = null;
|
|
47893
48161
|
let reconnectTimer = null;
|
|
47894
48162
|
let reconnectCount = 0;
|
|
47895
48163
|
let closedByUser = false;
|
|
48164
|
+
const pendingMessages = [];
|
|
48165
|
+
const sendNow = (payload) => {
|
|
48166
|
+
if (socket?.readyState !== WebSocket.OPEN) return false;
|
|
48167
|
+
socket.send(typeof payload === "string" ? payload : JSON.stringify(payload));
|
|
48168
|
+
return true;
|
|
48169
|
+
};
|
|
47896
48170
|
const cleanup = () => {
|
|
47897
48171
|
if (reconnectTimer) {
|
|
47898
48172
|
clearTimeout(reconnectTimer);
|
|
47899
48173
|
reconnectTimer = null;
|
|
47900
48174
|
}
|
|
47901
48175
|
};
|
|
48176
|
+
let attemptedRawFallback = false;
|
|
47902
48177
|
const openSocket = () => {
|
|
47903
48178
|
cleanup();
|
|
47904
48179
|
if (closedByUser) return;
|
|
47905
|
-
console.
|
|
48180
|
+
console.error("[tevrocsdk] opening realtime socket", { room, roomName, url, appId: client.appId });
|
|
47906
48181
|
socket = new WebSocket(url);
|
|
47907
|
-
socket.addEventListener("open", (
|
|
48182
|
+
socket.addEventListener("open", (event2) => {
|
|
47908
48183
|
reconnectCount = 0;
|
|
47909
|
-
console.
|
|
47910
|
-
handlers.open?.(
|
|
48184
|
+
console.error("[tevrocsdk] realtime socket open", { room, roomName, readyState: socket.readyState, url });
|
|
48185
|
+
handlers.open?.(event2);
|
|
48186
|
+
while (pendingMessages.length && sendNow(pendingMessages[0])) {
|
|
48187
|
+
pendingMessages.shift();
|
|
48188
|
+
}
|
|
47911
48189
|
});
|
|
47912
|
-
socket.addEventListener("message", (
|
|
47913
|
-
let data =
|
|
48190
|
+
socket.addEventListener("message", (event2) => {
|
|
48191
|
+
let data = event2.data;
|
|
47914
48192
|
try {
|
|
47915
|
-
data = JSON.parse(
|
|
48193
|
+
data = JSON.parse(event2.data);
|
|
47916
48194
|
} catch {
|
|
47917
48195
|
}
|
|
47918
|
-
console.
|
|
47919
|
-
handlers.message?.(data,
|
|
48196
|
+
console.error("[tevrocsdk] realtime socket message", { room, roomName, data });
|
|
48197
|
+
handlers.message?.(data, event2);
|
|
47920
48198
|
});
|
|
47921
|
-
socket.addEventListener("close", (
|
|
47922
|
-
console.log("[tevrocsdk] realtime socket close", { room, roomName, code:
|
|
47923
|
-
handlers.close?.(
|
|
48199
|
+
socket.addEventListener("close", (event2) => {
|
|
48200
|
+
console.log("[tevrocsdk] realtime socket close", { room, roomName, code: event2.code, reason: event2.reason, wasClean: event2.wasClean, url });
|
|
48201
|
+
handlers.close?.(event2);
|
|
48202
|
+
const wasNeverOpen = event2?.code === 1006 || socket?.readyState !== WebSocket.OPEN;
|
|
48203
|
+
if (wasNeverOpen && !attemptedRawFallback && rawUrl && rawUrl !== url) {
|
|
48204
|
+
attemptedRawFallback = true;
|
|
48205
|
+
console.warn("[tevrocsdk] realtime fallback to raw URL after failed encoded handshake", { encodedUrl: url, rawUrl });
|
|
48206
|
+
url = rawUrl;
|
|
48207
|
+
reconnectTimer = setTimeout(() => openSocket(), 500);
|
|
48208
|
+
return;
|
|
48209
|
+
}
|
|
47924
48210
|
if (closedByUser || reconnectCount >= maxReconnects) return;
|
|
47925
48211
|
reconnectTimer = setTimeout(() => {
|
|
47926
48212
|
reconnectCount += 1;
|
|
47927
|
-
console.log("[tevrocsdk] realtime retry", { room, roomName, attempt: reconnectCount, delayMs: reconnectMs });
|
|
48213
|
+
console.log("[tevrocsdk] realtime retry", { room, roomName, attempt: reconnectCount, delayMs: reconnectMs, url });
|
|
47928
48214
|
openSocket();
|
|
47929
48215
|
}, reconnectMs);
|
|
47930
48216
|
});
|
|
47931
|
-
socket.addEventListener("error", (
|
|
47932
|
-
console.log("[tevrocsdk] realtime socket error", { room, roomName, event });
|
|
47933
|
-
handlers.error?.(
|
|
48217
|
+
socket.addEventListener("error", (event2) => {
|
|
48218
|
+
console.log("[tevrocsdk] realtime socket error", { room, roomName, event: event2 });
|
|
48219
|
+
handlers.error?.(event2);
|
|
47934
48220
|
});
|
|
47935
48221
|
};
|
|
47936
48222
|
openSocket();
|
|
47937
48223
|
return {
|
|
47938
48224
|
socket: () => socket,
|
|
47939
48225
|
send: (payload) => {
|
|
47940
|
-
|
|
47941
|
-
|
|
47942
|
-
|
|
47943
|
-
|
|
47944
|
-
return result;
|
|
48226
|
+
if (sendNow(payload)) return true;
|
|
48227
|
+
pendingMessages.push(payload);
|
|
48228
|
+
console.log("[tevrocsdk] realtime message queued until the socket opens", { room, roomName, queued: pendingMessages.length });
|
|
48229
|
+
return true;
|
|
47945
48230
|
},
|
|
47946
48231
|
close: () => {
|
|
47947
48232
|
closedByUser = true;
|
|
47948
48233
|
cleanup();
|
|
48234
|
+
pendingMessages.length = 0;
|
|
47949
48235
|
console.log("[tevrocsdk] realtime socket close requested", { room, roomName });
|
|
47950
48236
|
socket?.close();
|
|
47951
48237
|
},
|
|
@@ -48388,6 +48674,7 @@ function isJsonBody(body) {
|
|
|
48388
48674
|
0 && (module.exports = {
|
|
48389
48675
|
TevrocClient,
|
|
48390
48676
|
TevrocError,
|
|
48677
|
+
createChatbotClient,
|
|
48391
48678
|
createClient
|
|
48392
48679
|
});
|
|
48393
48680
|
/*! Bundled license information:
|