@condorinst/mobile-bridge 0.22.0 → 0.23.1

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/dist/index.cjs CHANGED
@@ -35,6 +35,7 @@ __export(index_exports, {
35
35
  BridgeClient: () => BridgeClient,
36
36
  BridgeShell: () => BridgeShell,
37
37
  NATIVE_CHANNEL_NAME: () => NATIVE_CHANNEL_NAME,
38
+ createRequestId: () => createRequestId,
38
39
  versionAtLeast: () => versionAtLeast
39
40
  });
40
41
  module.exports = __toCommonJS(index_exports);
@@ -654,6 +655,11 @@ var Bridge = {
654
655
  };
655
656
 
656
657
  // src/bridge-client.ts
658
+ function createRequestId() {
659
+ const bytes = new Uint8Array(16);
660
+ crypto.getRandomValues(bytes);
661
+ return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
662
+ }
657
663
  var PROTOCOL_VERSION2 = "0.5.0";
658
664
  var HANDSHAKE_TIMEOUT_MS = 5e3;
659
665
  var SENSOR_LOG_TIMEOUT_MS = 1e4;
@@ -665,6 +671,11 @@ function insideShell() {
665
671
  }
666
672
  var subscribers2 = /* @__PURE__ */ new Map();
667
673
  var lastSystemStatus = null;
674
+ function trustedHasDevices(status) {
675
+ if (!status || typeof status.hasDevices !== "boolean") return null;
676
+ if (status.hasDevicesKnown === false) return null;
677
+ return status.hasDevices;
678
+ }
668
679
  var pendingHandshake2 = null;
669
680
  var messageListenerInstalled = false;
670
681
  function postToShell(msg) {
@@ -750,13 +761,18 @@ var BridgeClient = {
750
761
  if (remaining.length === 0) postToShell({ type: "unsubscribe", key });
751
762
  };
752
763
  },
753
- send(command, args = {}) {
764
+ send(command, ...rest) {
765
+ const args = rest[0] ?? {};
754
766
  postToShell({ type: "send", command, args });
755
767
  },
756
768
  openSettings() {
757
769
  this.send("openSettings");
758
770
  },
759
- fetchSensorLog(query, opts) {
771
+ fetchSensorLog(input, opts) {
772
+ const query = {
773
+ ...input,
774
+ requestId: input.requestId ?? createRequestId()
775
+ };
760
776
  const timeoutMs = opts?.timeoutMs ?? SENSOR_LOG_TIMEOUT_MS;
761
777
  return new Promise((resolve, reject) => {
762
778
  let settled = false;
@@ -794,18 +810,23 @@ var BridgeClient = {
794
810
  });
795
811
  },
796
812
  requestUserDevices(opts) {
797
- let hasDevices = typeof lastSystemStatus?.hasDevices === "boolean" ? lastSystemStatus.hasDevices : null;
813
+ let hasDevices = trustedHasDevices(lastSystemStatus);
798
814
  const getFromServer = opts?.getFromServer ?? false;
799
815
  return retryUntilReply({
800
816
  timeoutMs: opts?.timeoutMs ?? SERVICE_TIMEOUT_MS,
801
817
  send: () => this.send("userDevice", { getFromServer }),
802
818
  listen: (done, resend) => {
803
- const offDevices = this.on(
804
- BRIDGE_KEYS.userDevice,
805
- (devices) => done({ status: "ok", devices })
806
- );
819
+ const offDevices = this.on(BRIDGE_KEYS.userDevice, (devices) => {
820
+ if (devices.error === void 0 || devices.error === null) {
821
+ done({ status: "ok", devices });
822
+ } else if (devices.error === "NO_DEVICES") {
823
+ done({ status: "no-devices" });
824
+ } else {
825
+ done({ status: "error", code: String(devices.error) });
826
+ }
827
+ });
807
828
  const offStatus = this.on(BRIDGE_KEYS.systemStatus, (status) => {
808
- hasDevices = status.hasDevices;
829
+ hasDevices = trustedHasDevices(status);
809
830
  resend();
810
831
  });
811
832
  return () => {
@@ -1275,6 +1296,7 @@ function versionAtLeast(version, min) {
1275
1296
  BridgeClient,
1276
1297
  BridgeShell,
1277
1298
  NATIVE_CHANNEL_NAME,
1299
+ createRequestId,
1278
1300
  versionAtLeast
1279
1301
  });
1280
1302
  //# sourceMappingURL=index.cjs.map