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.cjs.js CHANGED
@@ -764,13 +764,52 @@ var init_tslib_es6 = __esm({
764
764
  });
765
765
 
766
766
  // node_modules/@tauri-apps/api/core.js
767
+ var core_exports = {};
768
+ __export(core_exports, {
769
+ Channel: () => Channel,
770
+ PluginListener: () => PluginListener,
771
+ Resource: () => Resource,
772
+ SERIALIZE_TO_IPC_FN: () => SERIALIZE_TO_IPC_FN,
773
+ addPluginListener: () => addPluginListener,
774
+ checkPermissions: () => checkPermissions,
775
+ convertFileSrc: () => convertFileSrc,
776
+ invoke: () => invoke,
777
+ isTauri: () => isTauri2,
778
+ requestPermissions: () => requestPermissions,
779
+ transformCallback: () => transformCallback
780
+ });
767
781
  function transformCallback(callback, once2 = false) {
768
782
  return window.__TAURI_INTERNALS__.transformCallback(callback, once2);
769
783
  }
784
+ async function addPluginListener(plugin, event, cb) {
785
+ const handler = new Channel(cb);
786
+ try {
787
+ await invoke(`plugin:${plugin}|register_listener`, {
788
+ event,
789
+ handler
790
+ });
791
+ return new PluginListener(plugin, event, handler.id);
792
+ } catch {
793
+ await invoke(`plugin:${plugin}|registerListener`, { event, handler });
794
+ return new PluginListener(plugin, event, handler.id);
795
+ }
796
+ }
797
+ async function checkPermissions(plugin) {
798
+ return invoke(`plugin:${plugin}|check_permissions`);
799
+ }
800
+ async function requestPermissions(plugin) {
801
+ return invoke(`plugin:${plugin}|request_permissions`);
802
+ }
770
803
  async function invoke(cmd, args = {}, options) {
771
804
  return window.__TAURI_INTERNALS__.invoke(cmd, args, options);
772
805
  }
773
- var _Channel_onmessage, _Channel_nextMessageIndex, _Channel_pendingMessages, _Channel_messageEndIndex, _Resource_rid, SERIALIZE_TO_IPC_FN, Channel, Resource;
806
+ function convertFileSrc(filePath, protocol = "asset") {
807
+ return window.__TAURI_INTERNALS__.convertFileSrc(filePath, protocol);
808
+ }
809
+ function isTauri2() {
810
+ return !!(globalThis || window).isTauri;
811
+ }
812
+ var _Channel_onmessage, _Channel_nextMessageIndex, _Channel_pendingMessages, _Channel_messageEndIndex, _Resource_rid, SERIALIZE_TO_IPC_FN, Channel, PluginListener, Resource;
774
813
  var init_core = __esm({
775
814
  "node_modules/@tauri-apps/api/core.js"() {
776
815
  init_tslib_es6();
@@ -827,6 +866,19 @@ var init_core = __esm({
827
866
  return this[SERIALIZE_TO_IPC_FN]();
828
867
  }
829
868
  };
869
+ PluginListener = class {
870
+ constructor(plugin, event, channelId) {
871
+ this.plugin = plugin;
872
+ this.event = event;
873
+ this.channelId = channelId;
874
+ }
875
+ async unregister() {
876
+ return invoke(`plugin:${this.plugin}|remove_listener`, {
877
+ event: this.event,
878
+ channelId: this.channelId
879
+ });
880
+ }
881
+ };
830
882
  Resource = class {
831
883
  get rid() {
832
884
  return __classPrivateFieldGet(this, _Resource_rid, "f");
@@ -44594,15 +44646,15 @@ var require_plugin_cjs3 = __commonJS({
44594
44646
  }
44595
44647
  static doUpgrade(event) {
44596
44648
  const eventTarget = event.target;
44597
- const db = eventTarget.result;
44649
+ const db2 = eventTarget.result;
44598
44650
  switch (event.oldVersion) {
44599
44651
  case 0:
44600
44652
  case 1:
44601
44653
  default: {
44602
- if (db.objectStoreNames.contains("FileStorage")) {
44603
- db.deleteObjectStore("FileStorage");
44654
+ if (db2.objectStoreNames.contains("FileStorage")) {
44655
+ db2.deleteObjectStore("FileStorage");
44604
44656
  }
44605
- const store = db.createObjectStore("FileStorage", { keyPath: "path" });
44657
+ const store = db2.createObjectStore("FileStorage", { keyPath: "path" });
44606
44658
  store.createIndex("by_folder", "folder");
44607
44659
  }
44608
44660
  }
@@ -47331,9 +47383,9 @@ var init_dist_js3 = __esm({
47331
47383
  * ```
47332
47384
  * @param db - Optionally state the name of a database if you are managing more than one. Otherwise, all database pools will be in scope.
47333
47385
  */
47334
- async close(db) {
47386
+ async close(db2) {
47335
47387
  const success = await invoke("plugin:sql|close", {
47336
- db
47388
+ db: db2
47337
47389
  });
47338
47390
  return success;
47339
47391
  }
@@ -47432,6 +47484,117 @@ var require_plugin_cjs6 = __commonJS({
47432
47484
  }
47433
47485
  });
47434
47486
 
47487
+ // node_modules/@capacitor/geolocation/dist/plugin.cjs.js
47488
+ var require_plugin_cjs7 = __commonJS({
47489
+ "node_modules/@capacitor/geolocation/dist/plugin.cjs.js"(exports2) {
47490
+ "use strict";
47491
+ var core = require_index_cjs();
47492
+ var synapse = require_synapse();
47493
+ var Geolocation = core.registerPlugin("Geolocation", {
47494
+ web: () => Promise.resolve().then(function() {
47495
+ return web;
47496
+ }).then((m) => new m.GeolocationWeb())
47497
+ });
47498
+ synapse.exposeSynapse();
47499
+ var GeolocationWeb = class extends core.WebPlugin {
47500
+ constructor() {
47501
+ super();
47502
+ this.latestOrientation = null;
47503
+ if (typeof window !== "undefined") {
47504
+ const win = window;
47505
+ if ("ondeviceorientationabsolute" in win) {
47506
+ win.addEventListener("deviceorientationabsolute", (event) => this.updateOrientation(event, true), true);
47507
+ } else if ("ondeviceorientation" in win) {
47508
+ win.addEventListener("deviceorientation", (event) => this.updateOrientation(event, false), true);
47509
+ }
47510
+ }
47511
+ }
47512
+ updateOrientation(event, isAbsolute2) {
47513
+ let trueHeading = null;
47514
+ let magneticHeading = null;
47515
+ let headingAccuracy = null;
47516
+ if (isAbsolute2 && event.alpha !== null) {
47517
+ trueHeading = (360 - event.alpha) % 360;
47518
+ } else if (event.webkitCompassHeading !== void 0 && event.webkitCompassHeading !== null) {
47519
+ magneticHeading = event.webkitCompassHeading;
47520
+ headingAccuracy = event.webkitCompassAccuracy;
47521
+ } else if (event.alpha !== null && event.absolute === true) {
47522
+ trueHeading = (360 - event.alpha) % 360;
47523
+ } else if (event.alpha !== null) {
47524
+ magneticHeading = (360 - event.alpha) % 360;
47525
+ }
47526
+ if (trueHeading !== null || magneticHeading !== null) {
47527
+ this.latestOrientation = {
47528
+ trueHeading,
47529
+ magneticHeading,
47530
+ headingAccuracy
47531
+ };
47532
+ }
47533
+ }
47534
+ augmentPosition(pos, isWatch = false) {
47535
+ var _a, _b, _c, _d, _e, _f, _g;
47536
+ const coords = pos.coords;
47537
+ const orientation = isWatch ? this.latestOrientation : null;
47538
+ const heading = (_c = (_b = (_a = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _a !== void 0 ? _a : orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _b !== void 0 ? _b : isWatch ? coords.heading : null) !== null && _c !== void 0 ? _c : null;
47539
+ return {
47540
+ timestamp: pos.timestamp,
47541
+ coords: {
47542
+ latitude: coords.latitude,
47543
+ longitude: coords.longitude,
47544
+ accuracy: coords.accuracy,
47545
+ altitude: coords.altitude,
47546
+ altitudeAccuracy: coords.altitudeAccuracy,
47547
+ speed: coords.speed,
47548
+ heading,
47549
+ magneticHeading: (_d = orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _d !== void 0 ? _d : null,
47550
+ trueHeading: (_e = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _e !== void 0 ? _e : null,
47551
+ headingAccuracy: (_f = orientation === null || orientation === void 0 ? void 0 : orientation.headingAccuracy) !== null && _f !== void 0 ? _f : null,
47552
+ course: (_g = isWatch ? coords.heading : null) !== null && _g !== void 0 ? _g : null
47553
+ }
47554
+ };
47555
+ }
47556
+ async getCurrentPosition(options) {
47557
+ return new Promise((resolve2, reject) => {
47558
+ navigator.geolocation.getCurrentPosition((pos) => {
47559
+ resolve2(this.augmentPosition(pos, false));
47560
+ }, (err) => {
47561
+ reject(err);
47562
+ }, Object.assign({ enableHighAccuracy: false, timeout: 1e4, maximumAge: 0 }, options));
47563
+ });
47564
+ }
47565
+ async watchPosition(options, callback) {
47566
+ const id = navigator.geolocation.watchPosition((pos) => {
47567
+ callback(this.augmentPosition(pos, true));
47568
+ }, (err) => {
47569
+ callback(null, err);
47570
+ }, Object.assign({ enableHighAccuracy: false, timeout: 1e4, maximumAge: 0, minimumUpdateInterval: 5e3 }, options));
47571
+ return `${id}`;
47572
+ }
47573
+ async clearWatch(options) {
47574
+ navigator.geolocation.clearWatch(parseInt(options.id, 10));
47575
+ }
47576
+ async checkPermissions() {
47577
+ if (typeof navigator === "undefined" || !navigator.permissions) {
47578
+ throw this.unavailable("Permissions API not available in this browser");
47579
+ }
47580
+ const permission = await navigator.permissions.query({
47581
+ name: "geolocation"
47582
+ });
47583
+ return { location: permission.state, coarseLocation: permission.state };
47584
+ }
47585
+ async requestPermissions() {
47586
+ throw this.unimplemented("Not implemented on web.");
47587
+ }
47588
+ };
47589
+ new GeolocationWeb();
47590
+ var web = /* @__PURE__ */ Object.freeze({
47591
+ __proto__: null,
47592
+ GeolocationWeb
47593
+ });
47594
+ exports2.Geolocation = Geolocation;
47595
+ }
47596
+ });
47597
+
47435
47598
  // src/index.js
47436
47599
  var index_exports = {};
47437
47600
  __export(index_exports, {
@@ -47439,6 +47602,7 @@ __export(index_exports, {
47439
47602
  TevrocError: () => TevrocError,
47440
47603
  createChatbotClient: () => createChatbotClient,
47441
47604
  createClient: () => createClient,
47605
+ createStorefrontClient: () => createStorefrontClient,
47442
47606
  registerDebugHandler: () => registerDebugHandler,
47443
47607
  unregisterDebugHandler: () => unregisterDebugHandler
47444
47608
  });
@@ -48167,19 +48331,19 @@ async function openSqlite(appId) {
48167
48331
  }
48168
48332
  debugWarn("[tevrocsdk][useEntities] opening SQLite connection for appId", { appId });
48169
48333
  const name = dbName(appId);
48170
- const db = await sqlite.createConnection(name, false, "no-encryption", 1, false);
48171
- debugWarn("[tevrocsdk][useEntities] SQLite connection created", { name, db });
48172
- await db.open();
48173
- debugWarn("[tevrocsdk][useEntities] SQLite connection opened", { name, db });
48174
- await db.execute("CREATE TABLE IF NOT EXISTS kv (key TEXT PRIMARY KEY, value TEXT NOT NULL)");
48334
+ const db2 = await sqlite.createConnection(name, false, "no-encryption", 1, false);
48335
+ debugWarn("[tevrocsdk][useEntities] SQLite connection created", { name, db: db2 });
48336
+ await db2.open();
48337
+ debugWarn("[tevrocsdk][useEntities] SQLite connection opened", { name, db: db2 });
48338
+ await db2.execute("CREATE TABLE IF NOT EXISTS kv (key TEXT PRIMARY KEY, value TEXT NOT NULL)");
48175
48339
  debugLog("[tevrocsdk][useEntities] mobile SQLite opened", { name });
48176
48340
  return {
48177
48341
  async get(key) {
48178
- const res = await db.query("SELECT value FROM kv WHERE key = ? LIMIT 1", [key]);
48342
+ const res = await db2.query("SELECT value FROM kv WHERE key = ? LIMIT 1", [key]);
48179
48343
  return res.values?.[0]?.value ?? null;
48180
48344
  },
48181
48345
  async set(key, value) {
48182
- await db.run("INSERT OR REPLACE INTO kv (key, value) VALUES (?, ?)", [key, value]);
48346
+ await db2.run("INSERT OR REPLACE INTO kv (key, value) VALUES (?, ?)", [key, value]);
48183
48347
  }
48184
48348
  };
48185
48349
  }
@@ -48187,16 +48351,16 @@ async function openSqlite(appId) {
48187
48351
  debugLog("[tevrocsdk][useEntities] opening desktop SQLite for appId", appId);
48188
48352
  const mod = await Promise.resolve().then(() => (init_dist_js3(), dist_js_exports3));
48189
48353
  const Database2 = mod.default || mod.Database;
48190
- const db = await Database2.load(`sqlite:${dbName(appId)}.db`);
48191
- await db.execute("CREATE TABLE IF NOT EXISTS kv (key TEXT PRIMARY KEY, value TEXT NOT NULL)");
48354
+ const db2 = await Database2.load(`sqlite:${dbName(appId)}.db`);
48355
+ await db2.execute("CREATE TABLE IF NOT EXISTS kv (key TEXT PRIMARY KEY, value TEXT NOT NULL)");
48192
48356
  debugLog("[tevrocsdk][useEntities] desktop SQLite opened", { dbFile: `${dbName(appId)}.db` });
48193
48357
  return {
48194
48358
  async get(key) {
48195
- const rows = await db.select("SELECT value FROM kv WHERE key = ? LIMIT 1", [key]);
48359
+ const rows = await db2.select("SELECT value FROM kv WHERE key = ? LIMIT 1", [key]);
48196
48360
  return rows?.[0]?.value ?? null;
48197
48361
  },
48198
48362
  async set(key, value) {
48199
- await db.execute("INSERT OR REPLACE INTO kv (key, value) VALUES (?, ?)", [key, value]);
48363
+ await db2.execute("INSERT OR REPLACE INTO kv (key, value) VALUES (?, ?)", [key, value]);
48200
48364
  }
48201
48365
  };
48202
48366
  }
@@ -48231,14 +48395,14 @@ async function openSqlite(appId) {
48231
48395
  return sqliteDb;
48232
48396
  }
48233
48397
  async function readDB(appId) {
48234
- const db = await openSqlite(appId);
48235
- const stored = await db.get("db");
48398
+ const db2 = await openSqlite(appId);
48399
+ const stored = await db2.get("db");
48236
48400
  return parseStoredJson(stored);
48237
48401
  }
48238
48402
  async function writeDB(appId, data) {
48239
48403
  const json = JSON.stringify(data || {}, null, 2);
48240
- const db = await openSqlite(appId);
48241
- await db.set("db", json);
48404
+ const db2 = await openSqlite(appId);
48405
+ await db2.set("db", json);
48242
48406
  }
48243
48407
  function parseStoredJson(value) {
48244
48408
  if (!value) return {};
@@ -48291,10 +48455,10 @@ function snap(value) {
48291
48455
  }
48292
48456
  function createNativeStore(appId = "default") {
48293
48457
  async function getValue(pathRef) {
48294
- const db = await readDB(appId);
48458
+ const db2 = await readDB(appId);
48295
48459
  const path = pathRef?.path || pathRef || "";
48296
48460
  const parts = String(path).split("/").filter(Boolean);
48297
- let value = db;
48461
+ let value = db2;
48298
48462
  for (const part of parts) {
48299
48463
  value = value?.[part];
48300
48464
  if (value === void 0) break;
@@ -48302,32 +48466,32 @@ function createNativeStore(appId = "default") {
48302
48466
  return snap(value);
48303
48467
  }
48304
48468
  async function setValue(pathRef, value) {
48305
- const db = await readDB(appId);
48469
+ const db2 = await readDB(appId);
48306
48470
  const path = pathRef?.path || pathRef || "";
48307
- const node = resolvePath(db, path, true);
48471
+ const node = resolvePath(db2, path, true);
48308
48472
  if (!node) return;
48309
48473
  if (isEqual(node.ref[node.key], value)) return;
48310
48474
  node.ref[node.key] = value;
48311
- await writeDB(appId, db);
48475
+ await writeDB(appId, db2);
48312
48476
  }
48313
48477
  async function updateValue(pathRef, value) {
48314
- const db = await readDB(appId);
48478
+ const db2 = await readDB(appId);
48315
48479
  const path = pathRef?.path || pathRef || "";
48316
- const node = resolvePath(db, path, true);
48480
+ const node = resolvePath(db2, path, true);
48317
48481
  if (!node) return;
48318
48482
  const prev = node.ref[node.key] || {};
48319
48483
  const next = deepMerge(structuredClone(prev), value);
48320
48484
  if (isEqual(prev, next)) return;
48321
48485
  node.ref[node.key] = next;
48322
- await writeDB(appId, db);
48486
+ await writeDB(appId, db2);
48323
48487
  }
48324
48488
  async function removeValue(pathRef) {
48325
- const db = await readDB(appId);
48489
+ const db2 = await readDB(appId);
48326
48490
  const path = pathRef?.path || pathRef || "";
48327
- const node = resolvePath(db, path);
48491
+ const node = resolvePath(db2, path);
48328
48492
  if (!node || node.ref[node.key] === void 0) return;
48329
48493
  delete node.ref[node.key];
48330
- await writeDB(appId, db);
48494
+ await writeDB(appId, db2);
48331
48495
  }
48332
48496
  function ref(_db, path) {
48333
48497
  return { path };
@@ -49112,6 +49276,343 @@ function createOfflineManager(client) {
49112
49276
  };
49113
49277
  }
49114
49278
 
49279
+ // src/native.js
49280
+ init_dist_js3();
49281
+ init_usePlatform();
49282
+ init_debug();
49283
+ var bluetoothBridgePromise;
49284
+ async function getBluetoothBridge() {
49285
+ if (bluetoothBridgePromise) return bluetoothBridgePromise;
49286
+ bluetoothBridgePromise = (async () => {
49287
+ if (isCapacitor) {
49288
+ try {
49289
+ const { registerPlugin } = await Promise.resolve().then(() => __toESM(require_index_cjs(), 1));
49290
+ return registerPlugin("Bluetooth");
49291
+ } catch {
49292
+ }
49293
+ }
49294
+ if (isTauri) return createTauriBluetoothBridge();
49295
+ if (typeof window !== "undefined") return window.__TEVROC_NATIVE_BLUETOOTH__ || window.__TEVROC_BLUETOOTH__ || null;
49296
+ return null;
49297
+ })();
49298
+ return bluetoothBridgePromise;
49299
+ }
49300
+ function createTauriBluetoothBridge() {
49301
+ let device = null;
49302
+ let characteristic = null;
49303
+ const invoke2 = async (command, args) => {
49304
+ const { invoke: call } = await Promise.resolve().then(() => (init_core(), core_exports));
49305
+ return call(command, args);
49306
+ };
49307
+ const browser = () => typeof navigator !== "undefined" && navigator.bluetooth;
49308
+ const browserScan = async () => {
49309
+ if (!browser()?.requestDevice) return [];
49310
+ const selected = await browser().requestDevice({ acceptAllDevices: true, optionalServices: [] });
49311
+ return [{ id: selected.id, name: selected.name || "Bluetooth device", native: true }];
49312
+ };
49313
+ const browserConnect = async (target) => {
49314
+ if (!browser()?.requestDevice) throw new Error("Tauri Bluetooth support is unavailable.");
49315
+ device = target?.id && device?.id === target.id ? device : await browser().requestDevice({ acceptAllDevices: true, optionalServices: [] });
49316
+ if (!device.gatt) throw new Error("Selected Bluetooth device does not expose GATT.");
49317
+ await device.gatt.connect();
49318
+ return { id: device.id, name: device.name, connected: true };
49319
+ };
49320
+ return {
49321
+ isAvailable: async () => {
49322
+ try {
49323
+ return Boolean(await invoke2("bluetooth_is_available"));
49324
+ } catch {
49325
+ return Boolean(browser()?.requestDevice);
49326
+ }
49327
+ },
49328
+ isEnabled: async () => {
49329
+ try {
49330
+ return Boolean(await invoke2("bluetooth_is_enabled"));
49331
+ } catch {
49332
+ return Boolean(browser());
49333
+ }
49334
+ },
49335
+ setEnabled: async (enabled) => {
49336
+ try {
49337
+ return await invoke2("bluetooth_set_enabled", { enabled });
49338
+ } catch {
49339
+ throw new Error("Tauri desktop Bluetooth power must be changed in operating system settings.");
49340
+ }
49341
+ },
49342
+ scan: async () => {
49343
+ try {
49344
+ return await invoke2("bluetooth_scan") || [];
49345
+ } catch {
49346
+ return browserScan();
49347
+ }
49348
+ },
49349
+ pair: async (target) => {
49350
+ try {
49351
+ return await invoke2("bluetooth_pair", { deviceId: target?.id || target?.address });
49352
+ } catch {
49353
+ return browserConnect(target);
49354
+ }
49355
+ },
49356
+ connect: async (target) => {
49357
+ try {
49358
+ return await invoke2("bluetooth_connect", { deviceId: target?.id || target?.address });
49359
+ } catch {
49360
+ return browserConnect(target);
49361
+ }
49362
+ },
49363
+ disconnect: async () => {
49364
+ try {
49365
+ await invoke2("bluetooth_disconnect");
49366
+ } catch {
49367
+ device?.gatt?.disconnect?.();
49368
+ }
49369
+ device = null;
49370
+ characteristic = null;
49371
+ },
49372
+ send: async (payload) => {
49373
+ const data = typeof payload === "string" ? payload : JSON.stringify(payload);
49374
+ try {
49375
+ return await invoke2("bluetooth_send", { data });
49376
+ } catch {
49377
+ if (!characteristic) throw new Error("Connect a Bluetooth device before sending data.");
49378
+ return characteristic.writeValue(new TextEncoder().encode(data));
49379
+ }
49380
+ },
49381
+ onMessage: (listener) => {
49382
+ let remove2;
49383
+ Promise.resolve().then(() => (init_event(), event_exports)).then(({ listen: listen2 }) => listen2("bluetooth-message", (event) => listener(event.payload))).then((unlisten) => {
49384
+ remove2 = unlisten;
49385
+ });
49386
+ return () => remove2?.();
49387
+ }
49388
+ };
49389
+ }
49390
+ function createGpsApi() {
49391
+ const capacitor = async () => {
49392
+ if (!isCapacitor) return null;
49393
+ const { Geolocation } = await Promise.resolve().then(() => __toESM(require_plugin_cjs7(), 1));
49394
+ return Geolocation;
49395
+ };
49396
+ const tauriInvoke = async (command, args) => {
49397
+ const { invoke: invoke2 } = await Promise.resolve().then(() => (init_core(), core_exports));
49398
+ return invoke2(command, args);
49399
+ };
49400
+ return {
49401
+ isAvailable: async () => {
49402
+ if (isCapacitor) return Boolean(await capacitor());
49403
+ if (isTauri) {
49404
+ try {
49405
+ return Boolean(await tauriInvoke("gps_is_available"));
49406
+ } catch {
49407
+ }
49408
+ }
49409
+ return typeof navigator !== "undefined" && Boolean(navigator.geolocation);
49410
+ },
49411
+ getCurrentPosition: async (options = {}) => {
49412
+ if (isCapacitor) return capacitor().then((api) => api.getCurrentPosition(options));
49413
+ if (isTauri) {
49414
+ try {
49415
+ return await tauriInvoke("gps_current_position", { options });
49416
+ } catch {
49417
+ }
49418
+ }
49419
+ return new Promise((resolve2, reject) => navigator.geolocation.getCurrentPosition(resolve2, reject, options));
49420
+ },
49421
+ watchPosition: async (callback, options = {}) => {
49422
+ if (isCapacitor) {
49423
+ const api = await capacitor();
49424
+ const handle = await api.watchPosition(options, callback);
49425
+ return { remove: () => api.clearWatch({ id: handle }) };
49426
+ }
49427
+ if (isTauri) {
49428
+ try {
49429
+ return await tauriInvoke("gps_watch_position", { options });
49430
+ } catch {
49431
+ }
49432
+ }
49433
+ return navigator.geolocation.watchPosition(callback, callback, options);
49434
+ },
49435
+ clearWatch: async (watchId) => {
49436
+ if (isCapacitor) return (await capacitor()).clearWatch({ id: watchId });
49437
+ if (isTauri) {
49438
+ try {
49439
+ return await tauriInvoke("gps_clear_watch", { watchId });
49440
+ } catch {
49441
+ }
49442
+ }
49443
+ return navigator.geolocation.clearWatch(watchId);
49444
+ },
49445
+ requestPermissions: async () => isCapacitor ? (await capacitor()).requestPermissions() : null
49446
+ };
49447
+ }
49448
+ function createBluetoothApi() {
49449
+ const call = async (method, ...args) => {
49450
+ const bridge = await getBluetoothBridge();
49451
+ return bridge?.[method]?.(...args);
49452
+ };
49453
+ return {
49454
+ isAvailable: async () => {
49455
+ const result = await call("isAvailable");
49456
+ return Boolean(result?.available ?? result);
49457
+ },
49458
+ isEnabled: async () => {
49459
+ const result = await call("isEnabled");
49460
+ return Boolean(result?.enabled ?? result);
49461
+ },
49462
+ setEnabled: async (enabled) => {
49463
+ const result = await call("setEnabled", Boolean(enabled));
49464
+ if (result === void 0 && !isCapacitor && !isTauri) throw new Error("Native Bluetooth power control is unavailable.");
49465
+ return result;
49466
+ },
49467
+ scan: async (options = {}) => {
49468
+ const result = await call("scan", options);
49469
+ return result?.devices || result || [];
49470
+ },
49471
+ connect: async (device) => {
49472
+ const result = await call("connect", isCapacitor ? { deviceId: device?.id || device?.address } : device);
49473
+ if (result === void 0) throw new Error("Native Bluetooth bridge is unavailable.");
49474
+ return result;
49475
+ },
49476
+ pair: async (device) => {
49477
+ const result = await call("pair", isCapacitor ? { deviceId: device?.id || device?.address } : device);
49478
+ if (result === void 0) throw new Error("Native Bluetooth pairing is unavailable.");
49479
+ return result;
49480
+ },
49481
+ disconnect: async (device) => call("disconnect", device),
49482
+ send: async (payload) => {
49483
+ const data = typeof payload === "string" ? payload : JSON.stringify(payload);
49484
+ const result = await call("send", isCapacitor ? { data } : payload);
49485
+ if (result === void 0) throw new Error("Native Bluetooth bridge is unavailable.");
49486
+ return result;
49487
+ },
49488
+ onMessage: (listener) => {
49489
+ let remove2;
49490
+ getBluetoothBridge().then((bridge) => {
49491
+ const subscription = bridge?.addListener ? bridge.addListener("message", listener) : bridge?.onMessage?.(listener);
49492
+ Promise.resolve(subscription).then((value) => {
49493
+ remove2 = value;
49494
+ });
49495
+ });
49496
+ return () => remove2?.remove?.() || remove2?.();
49497
+ }
49498
+ };
49499
+ }
49500
+ var db;
49501
+ async function getDb() {
49502
+ if (!db) {
49503
+ db = await Database.load("sqlite:app.db");
49504
+ }
49505
+ return db;
49506
+ }
49507
+ var unwrapData = (r) => r?.data ?? r;
49508
+ var unwrapList = (r) => Array.isArray(r) ? r : r?.data ?? [];
49509
+ function normalizeListArgs(o, limit) {
49510
+ if (o && typeof o === "object") return o;
49511
+ return { limit };
49512
+ }
49513
+ function createSQLiteEntity(table) {
49514
+ return {
49515
+ list: async (o, l) => {
49516
+ const db2 = await getDb();
49517
+ const res = await db2.select(
49518
+ `SELECT * FROM ${table} LIMIT ?`,
49519
+ [l || 100]
49520
+ );
49521
+ return unwrapList(res);
49522
+ },
49523
+ get: async (id) => {
49524
+ const db2 = await getDb();
49525
+ const res = await db2.select(
49526
+ `SELECT * FROM ${table} WHERE id = ? LIMIT 1`,
49527
+ [id]
49528
+ );
49529
+ return res?.[0] ?? null;
49530
+ },
49531
+ create: async (record) => {
49532
+ const db2 = await getDb();
49533
+ const keys = Object.keys(record);
49534
+ const values = Object.values(record);
49535
+ await db2.execute(
49536
+ `INSERT INTO ${table} (${keys.join(",")})
49537
+ VALUES (${keys.map(() => "?").join(",")})`,
49538
+ values
49539
+ );
49540
+ return record;
49541
+ },
49542
+ update: async (id, patch) => {
49543
+ const db2 = await getDb();
49544
+ const sets = Object.keys(patch).map((k) => `${k} = ?`).join(", ");
49545
+ await db2.execute(
49546
+ `UPDATE ${table} SET ${sets} WHERE id = ?`,
49547
+ [...Object.values(patch), id]
49548
+ );
49549
+ return { id, ...patch };
49550
+ },
49551
+ delete: async (id) => {
49552
+ const db2 = await getDb();
49553
+ await db2.execute(
49554
+ `DELETE FROM ${table} WHERE id = ?`,
49555
+ [id]
49556
+ );
49557
+ },
49558
+ query: async (sql, params = []) => {
49559
+ const db2 = await getDb();
49560
+ return await db2.select(sql, params);
49561
+ },
49562
+ bulkCreate: async (records) => {
49563
+ const db2 = await getDb();
49564
+ for (const r of records) {
49565
+ const keys = Object.keys(r);
49566
+ const values = Object.values(r);
49567
+ await db2.execute(
49568
+ `INSERT INTO ${table} (${keys.join(",")})
49569
+ VALUES (${keys.map(() => "?").join(",")})`,
49570
+ values
49571
+ );
49572
+ }
49573
+ return records;
49574
+ }
49575
+ };
49576
+ }
49577
+ function createUserEntityApi() {
49578
+ const table = "users";
49579
+ return {
49580
+ list: (o, l) => createSQLiteEntity(table).list(o, l),
49581
+ get: (id) => createSQLiteEntity(table).get(id),
49582
+ create: (r) => createSQLiteEntity(table).create(r),
49583
+ update: (id, p) => createSQLiteEntity(table).update(id, p),
49584
+ delete: (id) => createSQLiteEntity(table).delete(id),
49585
+ query: (sql, params) => createSQLiteEntity(table).query(sql, params)
49586
+ };
49587
+ }
49588
+ function createEntityApi(entityApi) {
49589
+ return {
49590
+ list: async (o, l) => unwrapList(await entityApi.list(normalizeListArgs(o, l))),
49591
+ get: async (id) => unwrapData(await entityApi.get(id)),
49592
+ create: async (r) => unwrapData(await entityApi.create(r)),
49593
+ update: async (id, p) => unwrapData(await entityApi.update(id, p)),
49594
+ delete: (id) => entityApi.delete(id),
49595
+ query: async (input) => unwrapList(await entityApi.query(input)),
49596
+ bulkCreate: (r) => entityApi.bulkCreate(r),
49597
+ bulkUpdate: (r) => entityApi.bulkUpdate?.(r),
49598
+ bulkDelete: (r) => entityApi.bulkDelete?.(r),
49599
+ import: (r) => entityApi.import?.(r)
49600
+ };
49601
+ }
49602
+ var entityRegistry = new Proxy(
49603
+ {},
49604
+ {
49605
+ get(_t, entity) {
49606
+ if (typeof entity !== "string") return void 0;
49607
+ if (entity === "User") {
49608
+ return createUserEntityApi();
49609
+ }
49610
+ const table = entity.toLowerCase();
49611
+ return createEntityApi(createSQLiteEntity(table));
49612
+ }
49613
+ }
49614
+ );
49615
+
49115
49616
  // src/index.js
49116
49617
  var DEFAULT_TIMEOUT_MS = 3e4;
49117
49618
  var platformModule = null;
@@ -49164,6 +49665,41 @@ function buildRealtimeRoomName(value, appId = "") {
49164
49665
  }
49165
49666
  return `chat:${encoded}`;
49166
49667
  }
49668
+ function createBluetoothSessionApi(client) {
49669
+ let connection = null;
49670
+ let currentEmail = "";
49671
+ return {
49672
+ ...createBluetoothApi(),
49673
+ joinAccountRoom: (email, handlers = {}, options = {}) => {
49674
+ const normalizedEmail = String(email || "").trim().toLowerCase();
49675
+ if (!normalizedEmail) throw new TypeError("An account email is required to join the Bluetooth room.");
49676
+ connection?.close?.();
49677
+ currentEmail = normalizedEmail;
49678
+ connection = client.realtime.room(`bluetooth:${normalizedEmail}`, {
49679
+ ...handlers,
49680
+ message: (message2, event) => {
49681
+ if (message2?.type === "bluetooth:presence" && message2.email === normalizedEmail) handlers.peer?.(message2, event);
49682
+ handlers.message?.(message2, event);
49683
+ }
49684
+ }, options);
49685
+ return {
49686
+ publish: (payload) => connection.publish({ ...payload, email: normalizedEmail }),
49687
+ send: (payload) => connection.send({ ...payload, email: normalizedEmail }),
49688
+ close: () => {
49689
+ connection?.close?.();
49690
+ connection = null;
49691
+ },
49692
+ room: () => `bluetooth:${normalizedEmail}`
49693
+ };
49694
+ },
49695
+ leaveAccountRoom: () => {
49696
+ connection?.close?.();
49697
+ connection = null;
49698
+ currentEmail = "";
49699
+ },
49700
+ accountRoom: () => currentEmail ? `bluetooth:${currentEmail}` : null
49701
+ };
49702
+ }
49167
49703
  function createClient(options = {}) {
49168
49704
  return new TevrocClient(options);
49169
49705
  }
@@ -49201,6 +49737,21 @@ function createChatbotClient(options = {}) {
49201
49737
  sendMessage: (conversationId, input) => request(`/chatbot/conversations/${encodeURIComponent(conversationId)}/messages`, { method: "POST", body: input })
49202
49738
  };
49203
49739
  }
49740
+ function createStorefrontClient(options = {}) {
49741
+ if (!options.apiKey) throw new TevrocError("apiKey is required to create a storefront client");
49742
+ const client = new TevrocClient({
49743
+ ...options,
49744
+ appId: void 0,
49745
+ token: null,
49746
+ headers: { ...options.headers || {}, "x-api-key": options.apiKey }
49747
+ });
49748
+ const request = (path, requestOptions = {}) => client.request(path, { ...requestOptions, auth: false });
49749
+ return {
49750
+ getBusiness: () => request("/storefront/business"),
49751
+ listProducts: (query = {}) => request("/storefront/products", { query }),
49752
+ createOrder: (order) => request("/storefront/orders", { method: "POST", body: order })
49753
+ };
49754
+ }
49204
49755
  var TevrocClient = class {
49205
49756
  constructor(options = {}) {
49206
49757
  const baseUrl = options.baseUrl ?? options.url;
@@ -49237,10 +49788,13 @@ var TevrocClient = class {
49237
49788
  this.sso = createSsoApi(this);
49238
49789
  this.files = createFileApi(this);
49239
49790
  this.native = {
49791
+ runtime: platform,
49240
49792
  store: createNativeStore(this.appId),
49241
49793
  files: createNativeFileApi(this.appId),
49242
49794
  googleDrive: createGoogleDriveApi(this.appId),
49243
- projects: createProjectStore(this.appId)
49795
+ projects: createProjectStore(this.appId),
49796
+ bluetooth: null,
49797
+ gps: createGpsApi()
49244
49798
  };
49245
49799
  this.offline = createOfflineManager(this);
49246
49800
  try {
@@ -49265,6 +49819,7 @@ var TevrocClient = class {
49265
49819
  this.payments = createPaymentApi(this);
49266
49820
  this.commerce = createCommerceApi(this);
49267
49821
  this.realtime = createRealtimeApi(this);
49822
+ this.native.bluetooth = createBluetoothSessionApi(this);
49268
49823
  this.notifications = createNotificationService();
49269
49824
  this.chatNotifications = createChatNotificationService(this);
49270
49825
  this.agentNotifications = createAgentNotificationService(this);
@@ -49597,11 +50152,11 @@ function createCommerceApi(client) {
49597
50152
  }
49598
50153
  function createPlatformApi(client) {
49599
50154
  return (async function() {
49600
- const { isNative: isNative2, isCapacitor: isCapacitor2, isTauri: isTauri2, platform: platform2 } = await getPlatformModule();
50155
+ const { isNative: isNative2, isCapacitor: isCapacitor2, isTauri: isTauri3, platform: platform2 } = await getPlatformModule();
49601
50156
  return {
49602
50157
  platform: platform2,
49603
50158
  isCapacitor: isCapacitor2,
49604
- isTauri: isTauri2,
50159
+ isTauri: isTauri3,
49605
50160
  isNative: isNative2
49606
50161
  };
49607
50162
  })();
@@ -49638,7 +50193,7 @@ function createAuthApi(client) {
49638
50193
  },
49639
50194
  // base44
49640
50195
  loginWithProvider: async (provider, redirectTo, setToken = async () => {
49641
- }) => {
50196
+ }, authInput = {}) => {
49642
50197
  debugLog2(client, "loginWithProvider called", { provider, redirectTo });
49643
50198
  if (provider === "google") {
49644
50199
  const { createGoogleLogin: createGoogleLogin2, subscribeGoogleLogin: subscribeGoogleLogin2 } = await getGoogleModule();
@@ -49654,7 +50209,7 @@ function createAuthApi(client) {
49654
50209
  if (!user) return;
49655
50210
  const result = await client.request("/auth/google", {
49656
50211
  method: "POST",
49657
- body: buildAuthPayload({ accessToken: user.accessToken }, client),
50212
+ body: buildAuthPayload({ ...authInput, accessToken: user.accessToken }, client),
49658
50213
  auth: false
49659
50214
  });
49660
50215
  debugLog2(client, result);
@@ -49694,7 +50249,7 @@ function createAuthApi(client) {
49694
50249
  if (!user) return;
49695
50250
  const result = await client.request("/auth/facebook", {
49696
50251
  method: "POST",
49697
- body: buildAuthPayload({ accessToken: user.accessToken }, client),
50252
+ body: buildAuthPayload({ ...authInput, accessToken: user.accessToken }, client),
49698
50253
  auth: false
49699
50254
  });
49700
50255
  debugLog2(client, result);
@@ -49734,7 +50289,7 @@ function createAuthApi(client) {
49734
50289
  if (!user) return;
49735
50290
  const result = await client.request("/auth/meta", {
49736
50291
  method: "POST",
49737
- body: buildAuthPayload({ accessToken: user.accessToken }, client),
50292
+ body: buildAuthPayload({ ...authInput, accessToken: user.accessToken }, client),
49738
50293
  auth: false
49739
50294
  });
49740
50295
  debugLog2(client, result);
@@ -49858,12 +50413,12 @@ function createEntityRegistry(client) {
49858
50413
  {
49859
50414
  get(_target, entity) {
49860
50415
  if (typeof entity !== "string") return void 0;
49861
- return createEntityApi(client, entity);
50416
+ return createEntityApi2(client, entity);
49862
50417
  }
49863
50418
  }
49864
50419
  );
49865
50420
  }
49866
- function createEntityApi(client, entity) {
50421
+ function createEntityApi2(client, entity) {
49867
50422
  const base = `/entities/${encodeURIComponent(entity)}`;
49868
50423
  async function cacheEntityRecord(record) {
49869
50424
  if (!client.native?.store || !isNative || !record || typeof record !== "object" || !record.id) return;
@@ -50122,6 +50677,7 @@ function createFunctionRegistry(client) {
50122
50677
  },
50123
50678
  {
50124
50679
  get(target, name) {
50680
+ if (name === "toJSON") return void 0;
50125
50681
  if (name in target) return target[name];
50126
50682
  if (typeof name !== "string") return void 0;
50127
50683
  return (payload) => target.invoke(name, payload);
@@ -50791,6 +51347,7 @@ function isJsonBody(body) {
50791
51347
  TevrocError,
50792
51348
  createChatbotClient,
50793
51349
  createClient,
51350
+ createStorefrontClient,
50794
51351
  registerDebugHandler,
50795
51352
  unregisterDebugHandler
50796
51353
  });