tevrocsdk 0.1.83 → 0.1.85

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/tevroc-sdk.esm.js CHANGED
@@ -126,7 +126,22 @@ var init_debug = __esm({
126
126
  });
127
127
 
128
128
  // node_modules/@capacitor/core/dist/index.js
129
- var ExceptionCode, CapacitorException, getPlatformId, createCapacitor, initCapacitorGlobal, Capacitor, registerPlugin, WebPlugin, encode, decode, CapacitorCookiesPluginWeb, CapacitorCookies, readBlobAsBase64, normalizeHttpHeaders, buildUrlParams, buildRequestInit, CapacitorHttpPluginWeb, CapacitorHttp, SystemBarsStyle, SystemBarType, SystemBarsPluginWeb, SystemBars;
129
+ var dist_exports = {};
130
+ __export(dist_exports, {
131
+ Capacitor: () => Capacitor,
132
+ CapacitorCookies: () => CapacitorCookies,
133
+ CapacitorException: () => CapacitorException,
134
+ CapacitorHttp: () => CapacitorHttp,
135
+ ExceptionCode: () => ExceptionCode,
136
+ SystemBarType: () => SystemBarType,
137
+ SystemBars: () => SystemBars,
138
+ SystemBarsStyle: () => SystemBarsStyle,
139
+ WebPlugin: () => WebPlugin,
140
+ WebView: () => WebView,
141
+ buildRequestInit: () => buildRequestInit,
142
+ registerPlugin: () => registerPlugin
143
+ });
144
+ var ExceptionCode, CapacitorException, getPlatformId, createCapacitor, initCapacitorGlobal, Capacitor, registerPlugin, WebPlugin, WebView, encode, decode, CapacitorCookiesPluginWeb, CapacitorCookies, readBlobAsBase64, normalizeHttpHeaders, buildUrlParams, buildRequestInit, CapacitorHttpPluginWeb, CapacitorHttp, SystemBarsStyle, SystemBarType, SystemBarsPluginWeb, SystemBars;
130
145
  var init_dist = __esm({
131
146
  "node_modules/@capacitor/core/dist/index.js"() {
132
147
  (function(ExceptionCode2) {
@@ -396,6 +411,7 @@ var init_dist = __esm({
396
411
  });
397
412
  }
398
413
  };
414
+ WebView = /* @__PURE__ */ registerPlugin("WebView");
399
415
  encode = (str) => encodeURIComponent(str).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/[()]/g, escape);
400
416
  decode = (str) => str.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
401
417
  CapacitorCookiesPluginWeb = class extends WebPlugin {
@@ -782,13 +798,52 @@ var init_tslib_es6 = __esm({
782
798
  });
783
799
 
784
800
  // node_modules/@tauri-apps/api/core.js
801
+ var core_exports = {};
802
+ __export(core_exports, {
803
+ Channel: () => Channel,
804
+ PluginListener: () => PluginListener,
805
+ Resource: () => Resource,
806
+ SERIALIZE_TO_IPC_FN: () => SERIALIZE_TO_IPC_FN,
807
+ addPluginListener: () => addPluginListener,
808
+ checkPermissions: () => checkPermissions,
809
+ convertFileSrc: () => convertFileSrc,
810
+ invoke: () => invoke,
811
+ isTauri: () => isTauri2,
812
+ requestPermissions: () => requestPermissions,
813
+ transformCallback: () => transformCallback
814
+ });
785
815
  function transformCallback(callback, once2 = false) {
786
816
  return window.__TAURI_INTERNALS__.transformCallback(callback, once2);
787
817
  }
818
+ async function addPluginListener(plugin, event, cb) {
819
+ const handler = new Channel(cb);
820
+ try {
821
+ await invoke(`plugin:${plugin}|register_listener`, {
822
+ event,
823
+ handler
824
+ });
825
+ return new PluginListener(plugin, event, handler.id);
826
+ } catch {
827
+ await invoke(`plugin:${plugin}|registerListener`, { event, handler });
828
+ return new PluginListener(plugin, event, handler.id);
829
+ }
830
+ }
831
+ async function checkPermissions(plugin) {
832
+ return invoke(`plugin:${plugin}|check_permissions`);
833
+ }
834
+ async function requestPermissions(plugin) {
835
+ return invoke(`plugin:${plugin}|request_permissions`);
836
+ }
788
837
  async function invoke(cmd, args = {}, options) {
789
838
  return window.__TAURI_INTERNALS__.invoke(cmd, args, options);
790
839
  }
791
- var _Channel_onmessage, _Channel_nextMessageIndex, _Channel_pendingMessages, _Channel_messageEndIndex, _Resource_rid, SERIALIZE_TO_IPC_FN, Channel, Resource;
840
+ function convertFileSrc(filePath, protocol = "asset") {
841
+ return window.__TAURI_INTERNALS__.convertFileSrc(filePath, protocol);
842
+ }
843
+ function isTauri2() {
844
+ return !!(globalThis || window).isTauri;
845
+ }
846
+ var _Channel_onmessage, _Channel_nextMessageIndex, _Channel_pendingMessages, _Channel_messageEndIndex, _Resource_rid, SERIALIZE_TO_IPC_FN, Channel, PluginListener, Resource;
792
847
  var init_core = __esm({
793
848
  "node_modules/@tauri-apps/api/core.js"() {
794
849
  init_tslib_es6();
@@ -845,6 +900,19 @@ var init_core = __esm({
845
900
  return this[SERIALIZE_TO_IPC_FN]();
846
901
  }
847
902
  };
903
+ PluginListener = class {
904
+ constructor(plugin, event, channelId) {
905
+ this.plugin = plugin;
906
+ this.event = event;
907
+ this.channelId = channelId;
908
+ }
909
+ async unregister() {
910
+ return invoke(`plugin:${this.plugin}|remove_listener`, {
911
+ event: this.event,
912
+ channelId: this.channelId
913
+ });
914
+ }
915
+ };
848
916
  Resource = class {
849
917
  get rid() {
850
918
  return __classPrivateFieldGet(this, _Resource_rid, "f");
@@ -24569,15 +24637,15 @@ var init_web3 = __esm({
24569
24637
  }
24570
24638
  static doUpgrade(event) {
24571
24639
  const eventTarget = event.target;
24572
- const db = eventTarget.result;
24640
+ const db2 = eventTarget.result;
24573
24641
  switch (event.oldVersion) {
24574
24642
  case 0:
24575
24643
  case 1:
24576
24644
  default: {
24577
- if (db.objectStoreNames.contains("FileStorage")) {
24578
- db.deleteObjectStore("FileStorage");
24645
+ if (db2.objectStoreNames.contains("FileStorage")) {
24646
+ db2.deleteObjectStore("FileStorage");
24579
24647
  }
24580
- const store = db.createObjectStore("FileStorage", { keyPath: "path" });
24648
+ const store = db2.createObjectStore("FileStorage", { keyPath: "path" });
24581
24649
  store.createIndex("by_folder", "folder");
24582
24650
  }
24583
24651
  }
@@ -27354,9 +27422,9 @@ var init_dist_js3 = __esm({
27354
27422
  * ```
27355
27423
  * @param db - Optionally state the name of a database if you are managing more than one. Otherwise, all database pools will be in scope.
27356
27424
  */
27357
- async close(db) {
27425
+ async close(db2) {
27358
27426
  const success = await invoke("plugin:sql|close", {
27359
- db
27427
+ db: db2
27360
27428
  });
27361
27429
  return success;
27362
27430
  }
@@ -27474,6 +27542,134 @@ var init_esm6 = __esm({
27474
27542
  }
27475
27543
  });
27476
27544
 
27545
+ // node_modules/@capacitor/geolocation/dist/esm/definitions.js
27546
+ var init_definitions7 = __esm({
27547
+ "node_modules/@capacitor/geolocation/dist/esm/definitions.js"() {
27548
+ }
27549
+ });
27550
+
27551
+ // node_modules/@capacitor/geolocation/dist/esm/web.js
27552
+ var web_exports7 = {};
27553
+ __export(web_exports7, {
27554
+ Geolocation: () => Geolocation,
27555
+ GeolocationWeb: () => GeolocationWeb
27556
+ });
27557
+ var GeolocationWeb, Geolocation;
27558
+ var init_web7 = __esm({
27559
+ "node_modules/@capacitor/geolocation/dist/esm/web.js"() {
27560
+ init_dist();
27561
+ GeolocationWeb = class extends WebPlugin {
27562
+ constructor() {
27563
+ super();
27564
+ this.latestOrientation = null;
27565
+ if (typeof window !== "undefined") {
27566
+ const win = window;
27567
+ if ("ondeviceorientationabsolute" in win) {
27568
+ win.addEventListener("deviceorientationabsolute", (event) => this.updateOrientation(event, true), true);
27569
+ } else if ("ondeviceorientation" in win) {
27570
+ win.addEventListener("deviceorientation", (event) => this.updateOrientation(event, false), true);
27571
+ }
27572
+ }
27573
+ }
27574
+ updateOrientation(event, isAbsolute2) {
27575
+ let trueHeading = null;
27576
+ let magneticHeading = null;
27577
+ let headingAccuracy = null;
27578
+ if (isAbsolute2 && event.alpha !== null) {
27579
+ trueHeading = (360 - event.alpha) % 360;
27580
+ } else if (event.webkitCompassHeading !== void 0 && event.webkitCompassHeading !== null) {
27581
+ magneticHeading = event.webkitCompassHeading;
27582
+ headingAccuracy = event.webkitCompassAccuracy;
27583
+ } else if (event.alpha !== null && event.absolute === true) {
27584
+ trueHeading = (360 - event.alpha) % 360;
27585
+ } else if (event.alpha !== null) {
27586
+ magneticHeading = (360 - event.alpha) % 360;
27587
+ }
27588
+ if (trueHeading !== null || magneticHeading !== null) {
27589
+ this.latestOrientation = {
27590
+ trueHeading,
27591
+ magneticHeading,
27592
+ headingAccuracy
27593
+ };
27594
+ }
27595
+ }
27596
+ augmentPosition(pos, isWatch = false) {
27597
+ var _a2, _b2, _c, _d, _e2, _f, _g;
27598
+ const coords = pos.coords;
27599
+ const orientation = isWatch ? this.latestOrientation : null;
27600
+ const heading = (_c = (_b2 = (_a2 = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _a2 !== void 0 ? _a2 : orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _b2 !== void 0 ? _b2 : isWatch ? coords.heading : null) !== null && _c !== void 0 ? _c : null;
27601
+ return {
27602
+ timestamp: pos.timestamp,
27603
+ coords: {
27604
+ latitude: coords.latitude,
27605
+ longitude: coords.longitude,
27606
+ accuracy: coords.accuracy,
27607
+ altitude: coords.altitude,
27608
+ altitudeAccuracy: coords.altitudeAccuracy,
27609
+ speed: coords.speed,
27610
+ heading,
27611
+ magneticHeading: (_d = orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _d !== void 0 ? _d : null,
27612
+ trueHeading: (_e2 = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _e2 !== void 0 ? _e2 : null,
27613
+ headingAccuracy: (_f = orientation === null || orientation === void 0 ? void 0 : orientation.headingAccuracy) !== null && _f !== void 0 ? _f : null,
27614
+ course: (_g = isWatch ? coords.heading : null) !== null && _g !== void 0 ? _g : null
27615
+ }
27616
+ };
27617
+ }
27618
+ async getCurrentPosition(options) {
27619
+ return new Promise((resolve3, reject) => {
27620
+ navigator.geolocation.getCurrentPosition((pos) => {
27621
+ resolve3(this.augmentPosition(pos, false));
27622
+ }, (err2) => {
27623
+ reject(err2);
27624
+ }, Object.assign({ enableHighAccuracy: false, timeout: 1e4, maximumAge: 0 }, options));
27625
+ });
27626
+ }
27627
+ async watchPosition(options, callback) {
27628
+ const id = navigator.geolocation.watchPosition((pos) => {
27629
+ callback(this.augmentPosition(pos, true));
27630
+ }, (err2) => {
27631
+ callback(null, err2);
27632
+ }, Object.assign({ enableHighAccuracy: false, timeout: 1e4, maximumAge: 0, minimumUpdateInterval: 5e3 }, options));
27633
+ return `${id}`;
27634
+ }
27635
+ async clearWatch(options) {
27636
+ navigator.geolocation.clearWatch(parseInt(options.id, 10));
27637
+ }
27638
+ async checkPermissions() {
27639
+ if (typeof navigator === "undefined" || !navigator.permissions) {
27640
+ throw this.unavailable("Permissions API not available in this browser");
27641
+ }
27642
+ const permission = await navigator.permissions.query({
27643
+ name: "geolocation"
27644
+ });
27645
+ return { location: permission.state, coarseLocation: permission.state };
27646
+ }
27647
+ async requestPermissions() {
27648
+ throw this.unimplemented("Not implemented on web.");
27649
+ }
27650
+ };
27651
+ Geolocation = new GeolocationWeb();
27652
+ }
27653
+ });
27654
+
27655
+ // node_modules/@capacitor/geolocation/dist/esm/index.js
27656
+ var esm_exports7 = {};
27657
+ __export(esm_exports7, {
27658
+ Geolocation: () => Geolocation2
27659
+ });
27660
+ var Geolocation2;
27661
+ var init_esm7 = __esm({
27662
+ "node_modules/@capacitor/geolocation/dist/esm/index.js"() {
27663
+ init_dist();
27664
+ init_synapse();
27665
+ init_definitions7();
27666
+ Geolocation2 = registerPlugin("Geolocation", {
27667
+ web: () => Promise.resolve().then(() => (init_web7(), web_exports7)).then((m4) => new m4.GeolocationWeb())
27668
+ });
27669
+ f3();
27670
+ }
27671
+ });
27672
+
27477
27673
  // src/index.js
27478
27674
  init_useGoogleAuth();
27479
27675
  init_useFacebookAuth();
@@ -41686,19 +41882,19 @@ async function openSqlite(appId) {
41686
41882
  }
41687
41883
  debugWarn("[tevrocsdk][useEntities] opening SQLite connection for appId", { appId });
41688
41884
  const name = dbName(appId);
41689
- const db = await sqlite.createConnection(name, false, "no-encryption", 1, false);
41690
- debugWarn("[tevrocsdk][useEntities] SQLite connection created", { name, db });
41691
- await db.open();
41692
- debugWarn("[tevrocsdk][useEntities] SQLite connection opened", { name, db });
41693
- await db.execute("CREATE TABLE IF NOT EXISTS kv (key TEXT PRIMARY KEY, value TEXT NOT NULL)");
41885
+ const db2 = await sqlite.createConnection(name, false, "no-encryption", 1, false);
41886
+ debugWarn("[tevrocsdk][useEntities] SQLite connection created", { name, db: db2 });
41887
+ await db2.open();
41888
+ debugWarn("[tevrocsdk][useEntities] SQLite connection opened", { name, db: db2 });
41889
+ await db2.execute("CREATE TABLE IF NOT EXISTS kv (key TEXT PRIMARY KEY, value TEXT NOT NULL)");
41694
41890
  debugLog("[tevrocsdk][useEntities] mobile SQLite opened", { name });
41695
41891
  return {
41696
41892
  async get(key) {
41697
- const res = await db.query("SELECT value FROM kv WHERE key = ? LIMIT 1", [key]);
41893
+ const res = await db2.query("SELECT value FROM kv WHERE key = ? LIMIT 1", [key]);
41698
41894
  return res.values?.[0]?.value ?? null;
41699
41895
  },
41700
41896
  async set(key, value) {
41701
- await db.run("INSERT OR REPLACE INTO kv (key, value) VALUES (?, ?)", [key, value]);
41897
+ await db2.run("INSERT OR REPLACE INTO kv (key, value) VALUES (?, ?)", [key, value]);
41702
41898
  }
41703
41899
  };
41704
41900
  }
@@ -41706,16 +41902,16 @@ async function openSqlite(appId) {
41706
41902
  debugLog("[tevrocsdk][useEntities] opening desktop SQLite for appId", appId);
41707
41903
  const mod = await Promise.resolve().then(() => (init_dist_js3(), dist_js_exports3));
41708
41904
  const Database2 = mod.default || mod.Database;
41709
- const db = await Database2.load(`sqlite:${dbName(appId)}.db`);
41710
- await db.execute("CREATE TABLE IF NOT EXISTS kv (key TEXT PRIMARY KEY, value TEXT NOT NULL)");
41905
+ const db2 = await Database2.load(`sqlite:${dbName(appId)}.db`);
41906
+ await db2.execute("CREATE TABLE IF NOT EXISTS kv (key TEXT PRIMARY KEY, value TEXT NOT NULL)");
41711
41907
  debugLog("[tevrocsdk][useEntities] desktop SQLite opened", { dbFile: `${dbName(appId)}.db` });
41712
41908
  return {
41713
41909
  async get(key) {
41714
- const rows = await db.select("SELECT value FROM kv WHERE key = ? LIMIT 1", [key]);
41910
+ const rows = await db2.select("SELECT value FROM kv WHERE key = ? LIMIT 1", [key]);
41715
41911
  return rows?.[0]?.value ?? null;
41716
41912
  },
41717
41913
  async set(key, value) {
41718
- await db.execute("INSERT OR REPLACE INTO kv (key, value) VALUES (?, ?)", [key, value]);
41914
+ await db2.execute("INSERT OR REPLACE INTO kv (key, value) VALUES (?, ?)", [key, value]);
41719
41915
  }
41720
41916
  };
41721
41917
  }
@@ -41750,14 +41946,14 @@ async function openSqlite(appId) {
41750
41946
  return sqliteDb;
41751
41947
  }
41752
41948
  async function readDB(appId) {
41753
- const db = await openSqlite(appId);
41754
- const stored = await db.get("db");
41949
+ const db2 = await openSqlite(appId);
41950
+ const stored = await db2.get("db");
41755
41951
  return parseStoredJson(stored);
41756
41952
  }
41757
41953
  async function writeDB(appId, data) {
41758
41954
  const json = JSON.stringify(data || {}, null, 2);
41759
- const db = await openSqlite(appId);
41760
- await db.set("db", json);
41955
+ const db2 = await openSqlite(appId);
41956
+ await db2.set("db", json);
41761
41957
  }
41762
41958
  function parseStoredJson(value) {
41763
41959
  if (!value) return {};
@@ -41810,10 +42006,10 @@ function snap(value) {
41810
42006
  }
41811
42007
  function createNativeStore(appId = "default") {
41812
42008
  async function getValue(pathRef) {
41813
- const db = await readDB(appId);
42009
+ const db2 = await readDB(appId);
41814
42010
  const path = pathRef?.path || pathRef || "";
41815
42011
  const parts = String(path).split("/").filter(Boolean);
41816
- let value = db;
42012
+ let value = db2;
41817
42013
  for (const part of parts) {
41818
42014
  value = value?.[part];
41819
42015
  if (value === void 0) break;
@@ -41821,32 +42017,32 @@ function createNativeStore(appId = "default") {
41821
42017
  return snap(value);
41822
42018
  }
41823
42019
  async function setValue(pathRef, value) {
41824
- const db = await readDB(appId);
42020
+ const db2 = await readDB(appId);
41825
42021
  const path = pathRef?.path || pathRef || "";
41826
- const node2 = resolvePath(db, path, true);
42022
+ const node2 = resolvePath(db2, path, true);
41827
42023
  if (!node2) return;
41828
42024
  if (isEqual(node2.ref[node2.key], value)) return;
41829
42025
  node2.ref[node2.key] = value;
41830
- await writeDB(appId, db);
42026
+ await writeDB(appId, db2);
41831
42027
  }
41832
42028
  async function updateValue(pathRef, value) {
41833
- const db = await readDB(appId);
42029
+ const db2 = await readDB(appId);
41834
42030
  const path = pathRef?.path || pathRef || "";
41835
- const node2 = resolvePath(db, path, true);
42031
+ const node2 = resolvePath(db2, path, true);
41836
42032
  if (!node2) return;
41837
42033
  const prev = node2.ref[node2.key] || {};
41838
42034
  const next = deepMerge(structuredClone(prev), value);
41839
42035
  if (isEqual(prev, next)) return;
41840
42036
  node2.ref[node2.key] = next;
41841
- await writeDB(appId, db);
42037
+ await writeDB(appId, db2);
41842
42038
  }
41843
42039
  async function removeValue(pathRef) {
41844
- const db = await readDB(appId);
42040
+ const db2 = await readDB(appId);
41845
42041
  const path = pathRef?.path || pathRef || "";
41846
- const node2 = resolvePath(db, path);
42042
+ const node2 = resolvePath(db2, path);
41847
42043
  if (!node2 || node2.ref[node2.key] === void 0) return;
41848
42044
  delete node2.ref[node2.key];
41849
- await writeDB(appId, db);
42045
+ await writeDB(appId, db2);
41850
42046
  }
41851
42047
  function ref(_db, path) {
41852
42048
  return { path };
@@ -42631,6 +42827,343 @@ function createOfflineManager(client) {
42631
42827
  };
42632
42828
  }
42633
42829
 
42830
+ // src/native.js
42831
+ init_dist_js3();
42832
+ init_usePlatform();
42833
+ init_debug();
42834
+ var bluetoothBridgePromise;
42835
+ async function getBluetoothBridge() {
42836
+ if (bluetoothBridgePromise) return bluetoothBridgePromise;
42837
+ bluetoothBridgePromise = (async () => {
42838
+ if (isCapacitor) {
42839
+ try {
42840
+ const { registerPlugin: registerPlugin2 } = await Promise.resolve().then(() => (init_dist(), dist_exports));
42841
+ return registerPlugin2("Bluetooth");
42842
+ } catch {
42843
+ }
42844
+ }
42845
+ if (isTauri) return createTauriBluetoothBridge();
42846
+ if (typeof window !== "undefined") return window.__TEVROC_NATIVE_BLUETOOTH__ || window.__TEVROC_BLUETOOTH__ || null;
42847
+ return null;
42848
+ })();
42849
+ return bluetoothBridgePromise;
42850
+ }
42851
+ function createTauriBluetoothBridge() {
42852
+ let device = null;
42853
+ let characteristic = null;
42854
+ const invoke2 = async (command, args) => {
42855
+ const { invoke: call } = await Promise.resolve().then(() => (init_core(), core_exports));
42856
+ return call(command, args);
42857
+ };
42858
+ const browser = () => typeof navigator !== "undefined" && navigator.bluetooth;
42859
+ const browserScan = async () => {
42860
+ if (!browser()?.requestDevice) return [];
42861
+ const selected = await browser().requestDevice({ acceptAllDevices: true, optionalServices: [] });
42862
+ return [{ id: selected.id, name: selected.name || "Bluetooth device", native: true }];
42863
+ };
42864
+ const browserConnect = async (target) => {
42865
+ if (!browser()?.requestDevice) throw new Error("Tauri Bluetooth support is unavailable.");
42866
+ device = target?.id && device?.id === target.id ? device : await browser().requestDevice({ acceptAllDevices: true, optionalServices: [] });
42867
+ if (!device.gatt) throw new Error("Selected Bluetooth device does not expose GATT.");
42868
+ await device.gatt.connect();
42869
+ return { id: device.id, name: device.name, connected: true };
42870
+ };
42871
+ return {
42872
+ isAvailable: async () => {
42873
+ try {
42874
+ return Boolean(await invoke2("bluetooth_is_available"));
42875
+ } catch {
42876
+ return Boolean(browser()?.requestDevice);
42877
+ }
42878
+ },
42879
+ isEnabled: async () => {
42880
+ try {
42881
+ return Boolean(await invoke2("bluetooth_is_enabled"));
42882
+ } catch {
42883
+ return Boolean(browser());
42884
+ }
42885
+ },
42886
+ setEnabled: async (enabled) => {
42887
+ try {
42888
+ return await invoke2("bluetooth_set_enabled", { enabled });
42889
+ } catch {
42890
+ throw new Error("Tauri desktop Bluetooth power must be changed in operating system settings.");
42891
+ }
42892
+ },
42893
+ scan: async () => {
42894
+ try {
42895
+ return await invoke2("bluetooth_scan") || [];
42896
+ } catch {
42897
+ return browserScan();
42898
+ }
42899
+ },
42900
+ pair: async (target) => {
42901
+ try {
42902
+ return await invoke2("bluetooth_pair", { deviceId: target?.id || target?.address });
42903
+ } catch {
42904
+ return browserConnect(target);
42905
+ }
42906
+ },
42907
+ connect: async (target) => {
42908
+ try {
42909
+ return await invoke2("bluetooth_connect", { deviceId: target?.id || target?.address });
42910
+ } catch {
42911
+ return browserConnect(target);
42912
+ }
42913
+ },
42914
+ disconnect: async () => {
42915
+ try {
42916
+ await invoke2("bluetooth_disconnect");
42917
+ } catch {
42918
+ device?.gatt?.disconnect?.();
42919
+ }
42920
+ device = null;
42921
+ characteristic = null;
42922
+ },
42923
+ send: async (payload) => {
42924
+ const data = typeof payload === "string" ? payload : JSON.stringify(payload);
42925
+ try {
42926
+ return await invoke2("bluetooth_send", { data });
42927
+ } catch {
42928
+ if (!characteristic) throw new Error("Connect a Bluetooth device before sending data.");
42929
+ return characteristic.writeValue(new TextEncoder().encode(data));
42930
+ }
42931
+ },
42932
+ onMessage: (listener) => {
42933
+ let remove2;
42934
+ Promise.resolve().then(() => (init_event(), event_exports)).then(({ listen: listen2 }) => listen2("bluetooth-message", (event) => listener(event.payload))).then((unlisten) => {
42935
+ remove2 = unlisten;
42936
+ });
42937
+ return () => remove2?.();
42938
+ }
42939
+ };
42940
+ }
42941
+ function createGpsApi() {
42942
+ const capacitor = async () => {
42943
+ if (!isCapacitor) return null;
42944
+ const { Geolocation: Geolocation3 } = await Promise.resolve().then(() => (init_esm7(), esm_exports7));
42945
+ return Geolocation3;
42946
+ };
42947
+ const tauriInvoke = async (command, args) => {
42948
+ const { invoke: invoke2 } = await Promise.resolve().then(() => (init_core(), core_exports));
42949
+ return invoke2(command, args);
42950
+ };
42951
+ return {
42952
+ isAvailable: async () => {
42953
+ if (isCapacitor) return Boolean(await capacitor());
42954
+ if (isTauri) {
42955
+ try {
42956
+ return Boolean(await tauriInvoke("gps_is_available"));
42957
+ } catch {
42958
+ }
42959
+ }
42960
+ return typeof navigator !== "undefined" && Boolean(navigator.geolocation);
42961
+ },
42962
+ getCurrentPosition: async (options = {}) => {
42963
+ if (isCapacitor) return capacitor().then((api) => api.getCurrentPosition(options));
42964
+ if (isTauri) {
42965
+ try {
42966
+ return await tauriInvoke("gps_current_position", { options });
42967
+ } catch {
42968
+ }
42969
+ }
42970
+ return new Promise((resolve3, reject) => navigator.geolocation.getCurrentPosition(resolve3, reject, options));
42971
+ },
42972
+ watchPosition: async (callback, options = {}) => {
42973
+ if (isCapacitor) {
42974
+ const api = await capacitor();
42975
+ const handle = await api.watchPosition(options, callback);
42976
+ return { remove: () => api.clearWatch({ id: handle }) };
42977
+ }
42978
+ if (isTauri) {
42979
+ try {
42980
+ return await tauriInvoke("gps_watch_position", { options });
42981
+ } catch {
42982
+ }
42983
+ }
42984
+ return navigator.geolocation.watchPosition(callback, callback, options);
42985
+ },
42986
+ clearWatch: async (watchId) => {
42987
+ if (isCapacitor) return (await capacitor()).clearWatch({ id: watchId });
42988
+ if (isTauri) {
42989
+ try {
42990
+ return await tauriInvoke("gps_clear_watch", { watchId });
42991
+ } catch {
42992
+ }
42993
+ }
42994
+ return navigator.geolocation.clearWatch(watchId);
42995
+ },
42996
+ requestPermissions: async () => isCapacitor ? (await capacitor()).requestPermissions() : null
42997
+ };
42998
+ }
42999
+ function createBluetoothApi() {
43000
+ const call = async (method, ...args) => {
43001
+ const bridge = await getBluetoothBridge();
43002
+ return bridge?.[method]?.(...args);
43003
+ };
43004
+ return {
43005
+ isAvailable: async () => {
43006
+ const result = await call("isAvailable");
43007
+ return Boolean(result?.available ?? result);
43008
+ },
43009
+ isEnabled: async () => {
43010
+ const result = await call("isEnabled");
43011
+ return Boolean(result?.enabled ?? result);
43012
+ },
43013
+ setEnabled: async (enabled) => {
43014
+ const result = await call("setEnabled", Boolean(enabled));
43015
+ if (result === void 0 && !isCapacitor && !isTauri) throw new Error("Native Bluetooth power control is unavailable.");
43016
+ return result;
43017
+ },
43018
+ scan: async (options = {}) => {
43019
+ const result = await call("scan", options);
43020
+ return result?.devices || result || [];
43021
+ },
43022
+ connect: async (device) => {
43023
+ const result = await call("connect", isCapacitor ? { deviceId: device?.id || device?.address } : device);
43024
+ if (result === void 0) throw new Error("Native Bluetooth bridge is unavailable.");
43025
+ return result;
43026
+ },
43027
+ pair: async (device) => {
43028
+ const result = await call("pair", isCapacitor ? { deviceId: device?.id || device?.address } : device);
43029
+ if (result === void 0) throw new Error("Native Bluetooth pairing is unavailable.");
43030
+ return result;
43031
+ },
43032
+ disconnect: async (device) => call("disconnect", device),
43033
+ send: async (payload) => {
43034
+ const data = typeof payload === "string" ? payload : JSON.stringify(payload);
43035
+ const result = await call("send", isCapacitor ? { data } : payload);
43036
+ if (result === void 0) throw new Error("Native Bluetooth bridge is unavailable.");
43037
+ return result;
43038
+ },
43039
+ onMessage: (listener) => {
43040
+ let remove2;
43041
+ getBluetoothBridge().then((bridge) => {
43042
+ const subscription = bridge?.addListener ? bridge.addListener("message", listener) : bridge?.onMessage?.(listener);
43043
+ Promise.resolve(subscription).then((value) => {
43044
+ remove2 = value;
43045
+ });
43046
+ });
43047
+ return () => remove2?.remove?.() || remove2?.();
43048
+ }
43049
+ };
43050
+ }
43051
+ var db;
43052
+ async function getDb() {
43053
+ if (!db) {
43054
+ db = await Database.load("sqlite:app.db");
43055
+ }
43056
+ return db;
43057
+ }
43058
+ var unwrapData = (r2) => r2?.data ?? r2;
43059
+ var unwrapList = (r2) => Array.isArray(r2) ? r2 : r2?.data ?? [];
43060
+ function normalizeListArgs(o3, limit) {
43061
+ if (o3 && typeof o3 === "object") return o3;
43062
+ return { limit };
43063
+ }
43064
+ function createSQLiteEntity(table) {
43065
+ return {
43066
+ list: async (o3, l3) => {
43067
+ const db2 = await getDb();
43068
+ const res = await db2.select(
43069
+ `SELECT * FROM ${table} LIMIT ?`,
43070
+ [l3 || 100]
43071
+ );
43072
+ return unwrapList(res);
43073
+ },
43074
+ get: async (id) => {
43075
+ const db2 = await getDb();
43076
+ const res = await db2.select(
43077
+ `SELECT * FROM ${table} WHERE id = ? LIMIT 1`,
43078
+ [id]
43079
+ );
43080
+ return res?.[0] ?? null;
43081
+ },
43082
+ create: async (record) => {
43083
+ const db2 = await getDb();
43084
+ const keys = Object.keys(record);
43085
+ const values = Object.values(record);
43086
+ await db2.execute(
43087
+ `INSERT INTO ${table} (${keys.join(",")})
43088
+ VALUES (${keys.map(() => "?").join(",")})`,
43089
+ values
43090
+ );
43091
+ return record;
43092
+ },
43093
+ update: async (id, patch) => {
43094
+ const db2 = await getDb();
43095
+ const sets = Object.keys(patch).map((k2) => `${k2} = ?`).join(", ");
43096
+ await db2.execute(
43097
+ `UPDATE ${table} SET ${sets} WHERE id = ?`,
43098
+ [...Object.values(patch), id]
43099
+ );
43100
+ return { id, ...patch };
43101
+ },
43102
+ delete: async (id) => {
43103
+ const db2 = await getDb();
43104
+ await db2.execute(
43105
+ `DELETE FROM ${table} WHERE id = ?`,
43106
+ [id]
43107
+ );
43108
+ },
43109
+ query: async (sql, params = []) => {
43110
+ const db2 = await getDb();
43111
+ return await db2.select(sql, params);
43112
+ },
43113
+ bulkCreate: async (records) => {
43114
+ const db2 = await getDb();
43115
+ for (const r2 of records) {
43116
+ const keys = Object.keys(r2);
43117
+ const values = Object.values(r2);
43118
+ await db2.execute(
43119
+ `INSERT INTO ${table} (${keys.join(",")})
43120
+ VALUES (${keys.map(() => "?").join(",")})`,
43121
+ values
43122
+ );
43123
+ }
43124
+ return records;
43125
+ }
43126
+ };
43127
+ }
43128
+ function createUserEntityApi() {
43129
+ const table = "users";
43130
+ return {
43131
+ list: (o3, l3) => createSQLiteEntity(table).list(o3, l3),
43132
+ get: (id) => createSQLiteEntity(table).get(id),
43133
+ create: (r2) => createSQLiteEntity(table).create(r2),
43134
+ update: (id, p3) => createSQLiteEntity(table).update(id, p3),
43135
+ delete: (id) => createSQLiteEntity(table).delete(id),
43136
+ query: (sql, params) => createSQLiteEntity(table).query(sql, params)
43137
+ };
43138
+ }
43139
+ function createEntityApi(entityApi) {
43140
+ return {
43141
+ list: async (o3, l3) => unwrapList(await entityApi.list(normalizeListArgs(o3, l3))),
43142
+ get: async (id) => unwrapData(await entityApi.get(id)),
43143
+ create: async (r2) => unwrapData(await entityApi.create(r2)),
43144
+ update: async (id, p3) => unwrapData(await entityApi.update(id, p3)),
43145
+ delete: (id) => entityApi.delete(id),
43146
+ query: async (input) => unwrapList(await entityApi.query(input)),
43147
+ bulkCreate: (r2) => entityApi.bulkCreate(r2),
43148
+ bulkUpdate: (r2) => entityApi.bulkUpdate?.(r2),
43149
+ bulkDelete: (r2) => entityApi.bulkDelete?.(r2),
43150
+ import: (r2) => entityApi.import?.(r2)
43151
+ };
43152
+ }
43153
+ var entityRegistry = new Proxy(
43154
+ {},
43155
+ {
43156
+ get(_t2, entity) {
43157
+ if (typeof entity !== "string") return void 0;
43158
+ if (entity === "User") {
43159
+ return createUserEntityApi();
43160
+ }
43161
+ const table = entity.toLowerCase();
43162
+ return createEntityApi(createSQLiteEntity(table));
43163
+ }
43164
+ }
43165
+ );
43166
+
42634
43167
  // src/index.js
42635
43168
  var DEFAULT_TIMEOUT_MS = 3e4;
42636
43169
  var platformModule = null;
@@ -42683,6 +43216,41 @@ function buildRealtimeRoomName(value, appId = "") {
42683
43216
  }
42684
43217
  return `chat:${encoded}`;
42685
43218
  }
43219
+ function createBluetoothSessionApi(client) {
43220
+ let connection = null;
43221
+ let currentEmail = "";
43222
+ return {
43223
+ ...createBluetoothApi(),
43224
+ joinAccountRoom: (email, handlers = {}, options = {}) => {
43225
+ const normalizedEmail = String(email || "").trim().toLowerCase();
43226
+ if (!normalizedEmail) throw new TypeError("An account email is required to join the Bluetooth room.");
43227
+ connection?.close?.();
43228
+ currentEmail = normalizedEmail;
43229
+ connection = client.realtime.room(`bluetooth:${normalizedEmail}`, {
43230
+ ...handlers,
43231
+ message: (message2, event) => {
43232
+ if (message2?.type === "bluetooth:presence" && message2.email === normalizedEmail) handlers.peer?.(message2, event);
43233
+ handlers.message?.(message2, event);
43234
+ }
43235
+ }, options);
43236
+ return {
43237
+ publish: (payload) => connection.publish({ ...payload, email: normalizedEmail }),
43238
+ send: (payload) => connection.send({ ...payload, email: normalizedEmail }),
43239
+ close: () => {
43240
+ connection?.close?.();
43241
+ connection = null;
43242
+ },
43243
+ room: () => `bluetooth:${normalizedEmail}`
43244
+ };
43245
+ },
43246
+ leaveAccountRoom: () => {
43247
+ connection?.close?.();
43248
+ connection = null;
43249
+ currentEmail = "";
43250
+ },
43251
+ accountRoom: () => currentEmail ? `bluetooth:${currentEmail}` : null
43252
+ };
43253
+ }
42686
43254
  function createClient(options = {}) {
42687
43255
  return new TevrocClient(options);
42688
43256
  }
@@ -42720,6 +43288,21 @@ function createChatbotClient(options = {}) {
42720
43288
  sendMessage: (conversationId, input) => request(`/chatbot/conversations/${encodeURIComponent(conversationId)}/messages`, { method: "POST", body: input })
42721
43289
  };
42722
43290
  }
43291
+ function createStorefrontClient(options = {}) {
43292
+ if (!options.apiKey) throw new TevrocError("apiKey is required to create a storefront client");
43293
+ const client = new TevrocClient({
43294
+ ...options,
43295
+ appId: void 0,
43296
+ token: null,
43297
+ headers: { ...options.headers || {}, "x-api-key": options.apiKey }
43298
+ });
43299
+ const request = (path, requestOptions = {}) => client.request(path, { ...requestOptions, auth: false });
43300
+ return {
43301
+ getBusiness: () => request("/storefront/business"),
43302
+ listProducts: (query = {}) => request("/storefront/products", { query }),
43303
+ createOrder: (order) => request("/storefront/orders", { method: "POST", body: order })
43304
+ };
43305
+ }
42723
43306
  var TevrocClient = class {
42724
43307
  constructor(options = {}) {
42725
43308
  const baseUrl = options.baseUrl ?? options.url;
@@ -42731,6 +43314,7 @@ var TevrocClient = class {
42731
43314
  this.vpsUrl = normalizeBaseUrl(vpsUrl);
42732
43315
  this.vpsConfig = { ...options.vpsConfig || options.config || {} };
42733
43316
  this.appId = options.appId;
43317
+ this.appInstance = options.appInstance || null;
42734
43318
  this.appName = options.appName;
42735
43319
  this.payAccount = options.payAccount ?? "default";
42736
43320
  this.fetch = (options.fetch ?? globalThis.fetch).bind(globalThis);
@@ -42756,10 +43340,13 @@ var TevrocClient = class {
42756
43340
  this.sso = createSsoApi(this);
42757
43341
  this.files = createFileApi(this);
42758
43342
  this.native = {
43343
+ runtime: platform,
42759
43344
  store: createNativeStore(this.appId),
42760
43345
  files: createNativeFileApi(this.appId),
42761
43346
  googleDrive: createGoogleDriveApi(this.appId),
42762
- projects: createProjectStore(this.appId)
43347
+ projects: createProjectStore(this.appId),
43348
+ bluetooth: null,
43349
+ gps: createGpsApi()
42763
43350
  };
42764
43351
  this.offline = createOfflineManager(this);
42765
43352
  try {
@@ -42784,6 +43371,7 @@ var TevrocClient = class {
42784
43371
  this.payments = createPaymentApi(this);
42785
43372
  this.commerce = createCommerceApi(this);
42786
43373
  this.realtime = createRealtimeApi(this);
43374
+ this.native.bluetooth = createBluetoothSessionApi(this);
42787
43375
  this.notifications = createNotificationService();
42788
43376
  this.chatNotifications = createChatNotificationService(this);
42789
43377
  this.agentNotifications = createAgentNotificationService(this);
@@ -42800,6 +43388,10 @@ var TevrocClient = class {
42800
43388
  }
42801
43389
  return this;
42802
43390
  }
43391
+ setAppInstance(appInstance) {
43392
+ this.appInstance = appInstance || null;
43393
+ return this;
43394
+ }
42803
43395
  clearToken() {
42804
43396
  this.token = null;
42805
43397
  const storage = safeLocalStorage();
@@ -42832,7 +43424,9 @@ var TevrocClient = class {
42832
43424
  if (token && options.auth !== false) {
42833
43425
  headers.set("authorization", `Bearer ${token}`);
42834
43426
  }
42835
- if (this.appId) {
43427
+ if (this.appInstance && String(path).startsWith("/entities/")) {
43428
+ headers.set("x-app-instance", this.appInstance);
43429
+ } else if (this.appId && !this.appInstance) {
42836
43430
  headers.set("x-app-id", this.appId);
42837
43431
  }
42838
43432
  let body = options.body;
@@ -43116,11 +43710,11 @@ function createCommerceApi(client) {
43116
43710
  }
43117
43711
  function createPlatformApi(client) {
43118
43712
  return (async function() {
43119
- const { isNative: isNative2, isCapacitor: isCapacitor2, isTauri: isTauri2, platform: platform2 } = await getPlatformModule();
43713
+ const { isNative: isNative2, isCapacitor: isCapacitor2, isTauri: isTauri3, platform: platform2 } = await getPlatformModule();
43120
43714
  return {
43121
43715
  platform: platform2,
43122
43716
  isCapacitor: isCapacitor2,
43123
- isTauri: isTauri2,
43717
+ isTauri: isTauri3,
43124
43718
  isNative: isNative2
43125
43719
  };
43126
43720
  })();
@@ -43139,6 +43733,15 @@ function createPaymentApi(client) {
43139
43733
  createCheckout: async (payload = {}) => {
43140
43734
  return await client.request("/create-checkout", { method: "POST", body: payload, auth: false });
43141
43735
  },
43736
+ createStorefrontCheckout: async (payload = {}) => {
43737
+ const serviceBaseUrl = `${client.serviceUrl.replace(/\/$/, "")}/.netlify/functions/api`;
43738
+ return await client.request("/yoco/storefront-pay", {
43739
+ method: "POST",
43740
+ body: payload,
43741
+ auth: false,
43742
+ baseUrl: serviceBaseUrl
43743
+ });
43744
+ },
43142
43745
  onstatus: (callback) => {
43143
43746
  if (typeof callback !== "function") {
43144
43747
  throw new Error("onstatus requires a function");
@@ -43157,7 +43760,7 @@ function createAuthApi(client) {
43157
43760
  },
43158
43761
  // base44
43159
43762
  loginWithProvider: async (provider, redirectTo, setToken = async () => {
43160
- }) => {
43763
+ }, authInput = {}) => {
43161
43764
  debugLog2(client, "loginWithProvider called", { provider, redirectTo });
43162
43765
  if (provider === "google") {
43163
43766
  const { createGoogleLogin: createGoogleLogin2, subscribeGoogleLogin: subscribeGoogleLogin2 } = await getGoogleModule();
@@ -43173,7 +43776,7 @@ function createAuthApi(client) {
43173
43776
  if (!user) return;
43174
43777
  const result = await client.request("/auth/google", {
43175
43778
  method: "POST",
43176
- body: buildAuthPayload({ accessToken: user.accessToken }, client),
43779
+ body: buildAuthPayload({ ...authInput, accessToken: user.accessToken }, client),
43177
43780
  auth: false
43178
43781
  });
43179
43782
  debugLog2(client, result);
@@ -43213,7 +43816,7 @@ function createAuthApi(client) {
43213
43816
  if (!user) return;
43214
43817
  const result = await client.request("/auth/facebook", {
43215
43818
  method: "POST",
43216
- body: buildAuthPayload({ accessToken: user.accessToken }, client),
43819
+ body: buildAuthPayload({ ...authInput, accessToken: user.accessToken }, client),
43217
43820
  auth: false
43218
43821
  });
43219
43822
  debugLog2(client, result);
@@ -43253,7 +43856,7 @@ function createAuthApi(client) {
43253
43856
  if (!user) return;
43254
43857
  const result = await client.request("/auth/meta", {
43255
43858
  method: "POST",
43256
- body: buildAuthPayload({ accessToken: user.accessToken }, client),
43859
+ body: buildAuthPayload({ ...authInput, accessToken: user.accessToken }, client),
43257
43860
  auth: false
43258
43861
  });
43259
43862
  debugLog2(client, result);
@@ -43377,12 +43980,12 @@ function createEntityRegistry(client) {
43377
43980
  {
43378
43981
  get(_target, entity) {
43379
43982
  if (typeof entity !== "string") return void 0;
43380
- return createEntityApi(client, entity);
43983
+ return createEntityApi2(client, entity);
43381
43984
  }
43382
43985
  }
43383
43986
  );
43384
43987
  }
43385
- function createEntityApi(client, entity) {
43988
+ function createEntityApi2(client, entity) {
43386
43989
  const base = `/entities/${encodeURIComponent(entity)}`;
43387
43990
  async function cacheEntityRecord(record) {
43388
43991
  if (!client.native?.store || !isNative || !record || typeof record !== "object" || !record.id) return;
@@ -43641,6 +44244,7 @@ function createFunctionRegistry(client) {
43641
44244
  },
43642
44245
  {
43643
44246
  get(target, name) {
44247
+ if (name === "toJSON") return void 0;
43644
44248
  if (name in target) return target[name];
43645
44249
  if (typeof name !== "string") return void 0;
43646
44250
  return (payload) => target.invoke(name, payload);
@@ -44309,6 +44913,7 @@ export {
44309
44913
  TevrocError,
44310
44914
  createChatbotClient,
44311
44915
  createClient,
44916
+ createStorefrontClient,
44312
44917
  registerDebugHandler,
44313
44918
  unregisterDebugHandler
44314
44919
  };
@@ -44509,4 +45114,3 @@ jspdf/dist/jspdf.es.min.js:
44509
45114
  * ====================================================================
44510
45115
  *)
44511
45116
  */
44512
- //# sourceMappingURL=tevroc-sdk.esm.js.map