@limrun/ui 0.14.0-rc.3 → 0.14.0-rc.5

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.
Files changed (76) hide show
  1. package/dist/app-store-relay/index.cjs +3 -3
  2. package/dist/app-store-relay/index.d.ts +108 -4
  3. package/dist/app-store-relay/index.js +353 -160
  4. package/dist/app-store-relay/react.cjs +1 -1
  5. package/dist/app-store-relay/react.js +32 -33
  6. package/dist/apple-credentials/index.cjs +1 -0
  7. package/dist/apple-credentials/index.d.ts +110 -0
  8. package/dist/apple-credentials/index.js +291 -0
  9. package/dist/browser-storage-BnO-Ma-e.mjs +219 -0
  10. package/dist/browser-storage-DLxIqZk5.js +1 -0
  11. package/dist/client-C9z_sgOf.js +1 -0
  12. package/dist/{client-C8ZDEjtD.mjs → client-CFDB4mX5.mjs} +38 -31
  13. package/dist/components/remote-control.d.ts +156 -0
  14. package/dist/core/device-install/apple/provisioning.d.ts +25 -0
  15. package/dist/core/device-install/apple/relay.d.ts +13 -0
  16. package/dist/core/device-install/storage/browser-storage.d.ts +8 -0
  17. package/dist/core/device-install/storage/index.d.ts +1 -0
  18. package/dist/core/device-install/storage/secret-store.d.ts +124 -0
  19. package/dist/core/device-install/types.d.ts +6 -0
  20. package/dist/core/errors.d.ts +1 -0
  21. package/dist/core/play-publish/google.d.ts +1 -1
  22. package/dist/device-build/index.cjs +1 -1
  23. package/dist/device-build/index.js +21 -20
  24. package/dist/device-build/react.cjs +1 -1
  25. package/dist/device-build/react.js +42 -43
  26. package/dist/device-install/index.cjs +1 -1
  27. package/dist/device-install/index.js +64 -63
  28. package/dist/device-install/react.cjs +1 -1
  29. package/dist/device-install/react.js +47 -49
  30. package/dist/errors-BSkqS7U-.js +1 -0
  31. package/dist/errors-gy8yQJos.mjs +6 -0
  32. package/dist/gsa-srp-Bme3JLEi.mjs +266 -0
  33. package/dist/gsa-srp-CCIfUz7Y.js +1 -0
  34. package/dist/index-ChhtuQ7e.js +22 -0
  35. package/dist/index-YDu8K9a4.mjs +11279 -0
  36. package/dist/index.cjs +1 -1
  37. package/dist/index.css +1 -1
  38. package/dist/index.js +1405 -1125
  39. package/dist/play-publish/index.cjs +1 -1
  40. package/dist/play-publish/index.js +27 -24
  41. package/dist/play-publish/react.cjs +1 -1
  42. package/dist/play-publish/react.d.ts +12 -2
  43. package/dist/play-publish/react.js +70 -60
  44. package/dist/{provisioning-BmsEnF6X.mjs → provisioning-CDPvxd1h.mjs} +64 -33
  45. package/dist/provisioning-CbC4h--7.js +1 -0
  46. package/package.json +6 -1
  47. package/src/app-store-relay/index.ts +358 -23
  48. package/src/app-store-relay/react.ts +1 -4
  49. package/src/apple-credentials/index.test.ts +180 -0
  50. package/src/apple-credentials/index.ts +388 -0
  51. package/src/components/remote-control.css +32 -0
  52. package/src/components/remote-control.tsx +865 -5
  53. package/src/core/device-install/apple/client.ts +13 -6
  54. package/src/core/device-install/apple/provisioning.test.ts +30 -0
  55. package/src/core/device-install/apple/provisioning.ts +39 -0
  56. package/src/core/device-install/apple/relay.ts +20 -0
  57. package/src/core/device-install/operations/operations.ts +7 -5
  58. package/src/core/device-install/storage/browser-storage.test.ts +65 -0
  59. package/src/core/device-install/storage/browser-storage.ts +33 -0
  60. package/src/core/device-install/storage/index.ts +1 -0
  61. package/src/core/device-install/storage/secret-store.ts +332 -0
  62. package/src/core/device-install/types.ts +6 -0
  63. package/src/core/errors.ts +3 -0
  64. package/src/core/play-publish/google.ts +11 -2
  65. package/src/device-build/react.ts +1 -4
  66. package/src/device-install/demo/demo.tsx +1 -4
  67. package/src/device-install/react.ts +1 -4
  68. package/src/play-publish/README.md +5 -4
  69. package/src/play-publish/react.ts +72 -32
  70. package/vite.config.ts +1 -0
  71. package/dist/browser-storage-Cx9eW-bm.mjs +0 -205
  72. package/dist/browser-storage-jJaIht4K.js +0 -1
  73. package/dist/client-BtC4n_qf.js +0 -1
  74. package/dist/index-CMeQfhYy.js +0 -22
  75. package/dist/index-DFdCvi2_.mjs +0 -11543
  76. package/dist/provisioning-Va0PH4Kk.js +0 -1
@@ -1,5 +1,6 @@
1
- import { j as be, n as Ue, k as Se } from "../browser-storage-Cx9eW-bm.mjs";
2
- const v = 1, f = 16, s = {
1
+ import { e as w } from "../errors-gy8yQJos.mjs";
2
+ import { j as Ue, n as Se, k as ve } from "../browser-storage-BnO-Ma-e.mjs";
3
+ const v = 1, d = 16, s = {
3
4
  DeviceHello: 1,
4
5
  OpenStream: 2,
5
6
  OpenResult: 3,
@@ -14,31 +15,31 @@ const v = 1, f = 16, s = {
14
15
  PairRecordReady: 12
15
16
  };
16
17
  function V(e) {
17
- const t = new Uint8Array(f + e.payload.byteLength), n = new DataView(t.buffer);
18
- return n.setUint8(0, v), n.setUint8(1, e.type), n.setUint8(2, 0), n.setUint8(3, 0), n.setUint32(4, e.requestId), n.setUint32(8, e.streamId), n.setUint32(12, e.payload.byteLength), t.set(e.payload, f), t;
18
+ const t = new Uint8Array(d + e.payload.byteLength), n = new DataView(t.buffer);
19
+ return n.setUint8(0, v), n.setUint8(1, e.type), n.setUint8(2, 0), n.setUint8(3, 0), n.setUint32(4, e.requestId), n.setUint32(8, e.streamId), n.setUint32(12, e.payload.byteLength), t.set(e.payload, d), t;
19
20
  }
20
21
  function A(e) {
21
- if (e.byteLength < f)
22
+ if (e.byteLength < d)
22
23
  throw new Error(`Relay frame too short: ${e.byteLength}`);
23
24
  const t = new DataView(e.buffer, e.byteOffset, e.byteLength), n = t.getUint8(0);
24
25
  if (n !== v)
25
26
  throw new Error(`Unsupported relay protocol version ${n}`);
26
27
  const r = t.getUint32(12);
27
- if (e.byteLength !== f + r)
28
+ if (e.byteLength !== d + r)
28
29
  throw new Error(
29
- `Relay frame length mismatch: got ${e.byteLength}, expected ${f + r}`
30
+ `Relay frame length mismatch: got ${e.byteLength}, expected ${d + r}`
30
31
  );
31
32
  return {
32
33
  type: t.getUint8(1),
33
34
  requestId: t.getUint32(4),
34
35
  streamId: t.getUint32(8),
35
- payload: e.slice(f)
36
+ payload: e.slice(d)
36
37
  };
37
38
  }
38
39
  function l(e) {
39
40
  return new TextEncoder().encode(JSON.stringify(e));
40
41
  }
41
- function h(e) {
42
+ function y(e) {
42
43
  return JSON.parse(new TextDecoder().decode(e));
43
44
  }
44
45
  async function C() {
@@ -70,7 +71,7 @@ function U(e) {
70
71
  async function T(e, t) {
71
72
  e.opened || await e.open(), (!e.configuration || e.configuration.configurationValue !== t.configurationValue) && await e.selectConfiguration(t.configurationValue), await e.claimInterface(t.interfaceNumber), await e.selectAlternateInterface(t.interfaceNumber, t.alternateSetting);
72
73
  }
73
- function W(e) {
74
+ function B(e) {
74
75
  const t = e.endpoints.find(
75
76
  (r) => r.direction === "out" && r.type === "bulk"
76
77
  ), n = e.endpoints.find(
@@ -86,17 +87,17 @@ async function R(e, t, n) {
86
87
  throw new Error(`USB transferOut failed: ${r.status}`);
87
88
  n.byteLength % t.packetSize === 0 && await e.transferOut(t.endpointNumber, new Uint8Array());
88
89
  }
89
- async function B(e, t, n = 16384) {
90
+ async function W(e, t, n = 16384) {
90
91
  const r = await e.transferIn(t.endpointNumber, n);
91
92
  if (r.status !== "ok" || !r.data)
92
93
  throw new Error(`USB transferIn failed: ${r.status}`);
93
94
  return new Uint8Array(r.data.buffer, r.data.byteOffset, r.data.byteLength);
94
95
  }
95
- const E = 0, F = 2, k = 6, _ = 4277009102, y = 2, M = 4, d = 16, j = 49152;
96
+ const E = 0, F = 2, k = 6, _ = 4277009102, m = 2, M = 4, f = 16, j = 49152;
96
97
  async function H(e, t) {
97
- const { inEndpoint: n, outEndpoint: r } = W(t), a = new Uint8Array(12), i = new DataView(a.buffer);
98
+ const { inEndpoint: n, outEndpoint: r } = B(t), a = new Uint8Array(12), i = new DataView(a.buffer);
98
99
  i.setUint32(0, 2), i.setUint32(4, 0), i.setUint32(8, 0), await R(e, r, O(E, a));
99
- const o = await P(e, n, 1), c = new DataView(o.payload.buffer, o.payload.byteOffset).getUint32(0), u = {
100
+ const o = await x(e, n, 1), c = new DataView(o.payload.buffer, o.payload.byteOffset).getUint32(0), u = {
100
101
  device: e,
101
102
  candidate: t,
102
103
  inEndpoint: n,
@@ -109,7 +110,7 @@ async function H(e, t) {
109
110
  writeChain: Promise.resolve(),
110
111
  closed: !1
111
112
  };
112
- return c >= 2 && await x(u, F, new Uint8Array([7])), Y(u), u;
113
+ return c >= 2 && await I(u, F, new Uint8Array([7])), Y(u), u;
113
114
  }
114
115
  async function J(e, t) {
115
116
  if (e.closed)
@@ -129,12 +130,12 @@ async function J(e, t) {
129
130
  resolveOpened: n,
130
131
  rejectOpened: r
131
132
  };
132
- return e.streams.set(m(t, a.sport), a), await w(a, y, new Uint8Array()), await a.opened, a;
133
+ return e.streams.set(g(t, a.sport), a), await h(a, m, new Uint8Array()), await a.opened, a;
133
134
  }
134
135
  async function G(e, t) {
135
136
  if (e.session.closed)
136
137
  throw new Error("usbmux session is closed.");
137
- await w(e, d, t), e.seq += t.byteLength;
138
+ await h(e, f, t), e.seq += t.byteLength;
138
139
  }
139
140
  async function Q(e) {
140
141
  if (e.queue.length > 0)
@@ -145,18 +146,18 @@ async function Q(e) {
145
146
  e.waiters.push(t);
146
147
  });
147
148
  }
148
- function I(e) {
149
+ function P(e) {
149
150
  e.closed = !0;
150
151
  for (const t of e.streams.values())
151
152
  for (t.error = new Error("usbmux session closed"), t.rejectOpened(t.error); t.waiters.length > 0; )
152
153
  t.waiters.shift()(new Uint8Array());
153
154
  e.streams.clear();
154
155
  }
155
- async function w(e, t, n) {
156
+ async function h(e, t, n) {
156
157
  const r = new Uint8Array(20 + n.byteLength), a = new DataView(r.buffer);
157
- a.setUint16(0, e.sport), a.setUint16(2, e.dport), a.setUint32(4, e.seq), a.setUint32(8, e.ack), a.setUint8(12, 80), a.setUint8(13, t), a.setUint16(14, 512), r.set(n, 20), await x(e.session, k, r);
158
+ a.setUint16(0, e.sport), a.setUint16(2, e.dport), a.setUint32(4, e.seq), a.setUint32(8, e.ack), a.setUint8(12, 80), a.setUint8(13, t), a.setUint16(14, 512), r.set(n, 20), await I(e.session, k, r);
158
159
  }
159
- async function x(e, t, n) {
160
+ async function I(e, t, n) {
160
161
  if (e.closed)
161
162
  throw new Error("usbmux session is closed.");
162
163
  return e.writeChain = e.writeChain.then(async () => {
@@ -169,32 +170,32 @@ async function Y(e) {
169
170
  try {
170
171
  for (; ; ) {
171
172
  if (e.closed) return;
172
- const t = await P(e.device, e.inEndpoint, e.muxVersion);
173
+ const t = await x(e.device, e.inEndpoint, e.muxVersion);
173
174
  if (e.closed) return;
174
175
  if (t.rxSeq !== void 0 && (e.rxSeq = t.rxSeq), t.protocol !== k)
175
176
  continue;
176
- const n = X(t.payload), r = e.streams.get(m(n.sport, n.dport));
177
+ const n = X(t.payload), r = e.streams.get(g(n.sport, n.dport));
177
178
  if (r) {
178
179
  if (n.flags & M) {
179
180
  for (r.error = new Error(`Device reset stream ${r.dport}`), r.rejectOpened(r.error); r.waiters.length > 0; )
180
181
  r.waiters.shift()(new Uint8Array());
181
- e.streams.delete(m(r.dport, r.sport));
182
+ e.streams.delete(g(r.dport, r.sport));
182
183
  continue;
183
184
  }
184
- if ((n.flags & (y | d)) === (y | d)) {
185
- r.seq += 1, r.ack = n.seq + 1, await w(r, d, new Uint8Array()), r.resolveOpened();
185
+ if ((n.flags & (m | f)) === (m | f)) {
186
+ r.seq += 1, r.ack = n.seq + 1, await h(r, f, new Uint8Array()), r.resolveOpened();
186
187
  continue;
187
188
  }
188
- n.payload.byteLength !== 0 && (r.ack = n.seq + n.payload.byteLength, await w(r, d, new Uint8Array()), r.waiters.length > 0 ? r.waiters.shift()(n.payload) : r.queue.push(n.payload));
189
+ n.payload.byteLength !== 0 && (r.ack = n.seq + n.payload.byteLength, await h(r, f, new Uint8Array()), r.waiters.length > 0 ? r.waiters.shift()(n.payload) : r.queue.push(n.payload));
189
190
  }
190
191
  }
191
192
  } catch {
192
- e.closed || I(e);
193
+ e.closed || P(e);
193
194
  }
194
195
  }
195
- async function P(e, t, n) {
196
+ async function x(e, t, n) {
196
197
  for (; ; ) {
197
- const r = await B(e, t), a = K(r, n);
198
+ const r = await W(e, t), a = K(r, n);
198
199
  if (!(n === 1 && a.protocol !== E))
199
200
  return a;
200
201
  }
@@ -227,7 +228,7 @@ function X(e) {
227
228
  payload: e.slice(n)
228
229
  };
229
230
  }
230
- function m(e, t) {
231
+ function g(e, t) {
231
232
  return `${e}:${t}`;
232
233
  }
233
234
  class Z {
@@ -290,7 +291,7 @@ class Z {
290
291
  await this.handleOpenStream(
291
292
  t.requestId,
292
293
  t.streamId,
293
- h(t.payload).port
294
+ y(t.payload).port
294
295
  );
295
296
  break;
296
297
  case s.StreamData: {
@@ -303,13 +304,13 @@ class Z {
303
304
  this.streams.delete(t.streamId);
304
305
  break;
305
306
  case s.InstallProgress:
306
- this.log(te(h(t.payload).message));
307
+ this.log(te(y(t.payload).message));
307
308
  break;
308
309
  case s.Error:
309
310
  this.handleError(t.payload);
310
311
  break;
311
312
  case s.PairRecordReady:
312
- this.handlePairRecordReady(h(t.payload));
313
+ this.handlePairRecordReady(y(t.payload));
313
314
  break;
314
315
  case s.Ping:
315
316
  await this.send({
@@ -467,11 +468,11 @@ async function oe({
467
468
  }
468
469
  async function se(e, t) {
469
470
  if (e) {
470
- if (e.session && (I(e.session), e.session = void 0), e.claimedInterfaceNumber !== void 0)
471
+ if (e.session && (P(e.session), e.session = void 0), e.claimedInterfaceNumber !== void 0)
471
472
  try {
472
473
  await e.device.releaseInterface(e.claimedInterfaceNumber), t?.("Released usbmux interface");
473
474
  } catch (n) {
474
- t?.("USB interface release failed", g(n));
475
+ t?.("USB interface release failed", w(n));
475
476
  } finally {
476
477
  e.claimedInterfaceNumber = void 0;
477
478
  }
@@ -479,7 +480,7 @@ async function se(e, t) {
479
480
  try {
480
481
  await e.device.close(), t?.("Closed USB device");
481
482
  } catch (n) {
482
- t?.("USB device close failed", g(n));
483
+ t?.("USB device close failed", w(n));
483
484
  }
484
485
  }
485
486
  }
@@ -499,7 +500,7 @@ async function ce(e, t) {
499
500
  function ue(e) {
500
501
  return {
501
502
  device: e,
502
- candidate: fe(e),
503
+ candidate: de(e),
503
504
  hello: {
504
505
  serialNumber: e.serialNumber,
505
506
  productName: e.productName,
@@ -513,25 +514,28 @@ async function le(e, t) {
513
514
  const n = q(e.device);
514
515
  if (n.length === 0) throw new Error("No Apple usbmux interface found.");
515
516
  let r;
516
- for (const a of n)
517
- for (const i of [1, 2])
517
+ for (const i of n)
518
+ for (const o of [1, 2])
518
519
  try {
519
520
  return e.device.opened || await e.device.open(), t(
520
521
  "Claiming usbmux interface",
521
- `configuration ${a.configurationValue}, interface ${a.interfaceNumber}, alternate ${a.alternateSetting}, attempt ${i}`
522
- ), await T(e.device, a), e.claimedInterfaceNumber = a.interfaceNumber, t(
522
+ `configuration ${i.configurationValue}, interface ${i.interfaceNumber}, alternate ${i.alternateSetting}, attempt ${o}`
523
+ ), await T(e.device, i), e.claimedInterfaceNumber = i.interfaceNumber, t(
523
524
  "Claimed usbmux interface",
524
- `configuration ${a.configurationValue}, interface ${a.interfaceNumber}`
525
- ), a;
526
- } catch (o) {
527
- r = o, t(
525
+ `configuration ${i.configurationValue}, interface ${i.interfaceNumber}`
526
+ ), i;
527
+ } catch (c) {
528
+ r = c, t(
528
529
  "USB interface claim failed",
529
- `configuration ${a.configurationValue}, interface ${a.interfaceNumber}: ${g(o)}`
530
- ), await de(e), await pe(250);
530
+ `configuration ${i.configurationValue}, interface ${i.interfaceNumber}: ${w(c)}`
531
+ ), await fe(e), await pe(250);
531
532
  }
532
- throw r instanceof Error ? r : new Error("Unable to claim any Apple usbmux interface.");
533
+ const a = r ? ` (${w(r)})` : "";
534
+ throw new Error(
535
+ `Could not get exclusive USB access to the iPhone${a}. Another app on this computer is likely connected to it. Close other browser tabs that use this device, quit iPhone Mirroring, Xcode, eject iPhone in Finder windows showing the phone and try again.`
536
+ );
533
537
  }
534
- function fe(e) {
538
+ function de(e) {
535
539
  const t = q(e)[0];
536
540
  if (!t) throw new Error("No Apple usbmux interface found.");
537
541
  return t;
@@ -547,10 +551,7 @@ function N(e, t, n) {
547
551
  const r = new URL(e);
548
552
  return r.protocol = r.protocol === "https:" ? "wss:" : "ws:", r.pathname = `${r.pathname.replace(/\/$/, "")}/ios/device/ws`, t && r.searchParams.set("token", t), n && r.searchParams.set("organization", n), r.toString();
549
553
  }
550
- function g(e) {
551
- return e instanceof Error ? e.message : String(e);
552
- }
553
- async function de(e) {
554
+ async function fe(e) {
554
555
  if (e.claimedInterfaceNumber !== void 0) {
555
556
  try {
556
557
  await e.device.releaseInterface(e.claimedInterfaceNumber);
@@ -567,13 +568,13 @@ async function de(e) {
567
568
  function pe(e) {
568
569
  return new Promise((t) => setTimeout(t, e));
569
570
  }
570
- async function we(e = {}) {
571
+ async function he(e = {}) {
571
572
  return ae({ log: e.log ?? b });
572
573
  }
573
- async function he(e) {
574
+ async function ye(e) {
574
575
  return ie({ ...e, log: e.log ?? b });
575
576
  }
576
- async function ye(e) {
577
+ async function me(e) {
577
578
  return oe({ ...e, log: e.log ?? b });
578
579
  }
579
580
  function b() {
@@ -582,12 +583,12 @@ export {
582
583
  Z as RelayClient,
583
584
  se as closeDeviceRelayTarget,
584
585
  N as deviceRelayWebSocketUrl,
585
- be as getPairRecord,
586
- Ue as normalizeUDID,
587
- he as pairDevice,
588
- Se as putPairRecord,
589
- we as requestUSBAccess,
590
- ye as startDeviceInstall,
586
+ Ue as getPairRecord,
587
+ Se as normalizeUDID,
588
+ ye as pairDevice,
589
+ ve as putPairRecord,
590
+ he as requestUSBAccess,
591
+ me as startDeviceInstall,
591
592
  oe as startDeviceInstallRelay,
592
593
  ie as startDevicePairingRelay
593
594
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),o=require("./index.cjs"),p=require("../browser-storage-jJaIht4K.js");function C({apiUrl:c,token:d,organizationId:v,log:h=E}){const[e,S]=r.useState(),[l,g]=r.useState(),[R,u]=r.useState(),[D,n]=r.useState(),[P,f]=r.useState(!1),y=r.useRef(void 0),b=r.useRef(void 0),t=r.useRef(h);t.current=h;const s=r.useCallback(async()=>{y.current?.close(),y.current=void 0,await o.closeDeviceRelayTarget(b.current,t.current)},[]);r.useEffect(()=>{b.current=e},[e]),r.useEffect(()=>()=>{s()},[s]);const m=r.useCallback(async()=>{u("usb"),n(void 0),f(!1);let a;try{await s(),a=await o.requestUSBAccess({log:t.current});const i=await p.getPairRecord(a.hello.serialNumber);return S(a),g(i),t.current(i?"Pair record found":"No pair record found",a.hello.serialNumber),a}catch(i){await o.closeDeviceRelayTarget(a,t.current),S(void 0),g(void 0),n(w(i));return}finally{u(void 0)}},[s]),q=r.useCallback(async()=>{if(!c||!e)throw new Error("Select a USB device before pairing.");u("pair"),n(void 0),f(!1);try{await s();const a=await o.pairDevice({registryApiUrl:c,token:d,organizationId:v,log:t.current,target:e}),i=await p.putPairRecord(a.pairRecord,{productName:e.hello.productName});return a.relay.close(),await o.closeDeviceRelayTarget(e,t.current),g(i),f(!1),t.current("Device paired","The pair record was stored locally in this browser."),i}catch(a){await o.closeDeviceRelayTarget(e,t.current),f(!0),n(w(a));return}finally{u(void 0)}},[c,s,e,v,d]),A=r.useCallback(async a=>{if(!c||!e||!l)throw new Error("Select and pair a USB device before starting installation.");u("install"),n(void 0);try{return await s(),y.current=await o.startDeviceInstall({registryApiUrl:c,token:d,organizationId:v,log:t.current,target:e,pairRecord:l,installSource:a}),t.current("Device install started","Installation will continue through the connected iPhone."),y.current}catch(i){await o.closeDeviceRelayTarget(e,t.current),n(w(i));return}finally{u(void 0)}},[c,s,e,v,l,d]),B=r.useCallback(()=>{s(),t.current("Device relay stopped")},[s]);return{device:e,pairRecord:l,busyAction:R,error:D,pairConfirmationRequired:P,hasPairRecord:!!l,canPair:!!c&&!R&&!!e,canInstall:!!c&&!R&&!!e&&!!l,requestUSBAccess:m,pairBrowser:q,startInstallation:A,stopRelay:B,clearError:()=>n(void 0)}}function E(){}function w(c){return c instanceof Error?c.message:String(c)}exports.useDeviceInstallRelay=C;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),i=require("./index.cjs"),w=require("../errors-BSkqS7U-.js"),D=require("../browser-storage-DLxIqZk5.js");function C({apiUrl:o,token:d,organizationId:v,log:h=T}){const[e,b]=r.useState(),[l,g]=r.useState(),[R,u]=r.useState(),[S,n]=r.useState(),[P,f]=r.useState(!1),y=r.useRef(void 0),p=r.useRef(void 0),t=r.useRef(h);t.current=h;const c=r.useCallback(async()=>{y.current?.close(),y.current=void 0,await i.closeDeviceRelayTarget(p.current,t.current)},[]);r.useEffect(()=>{p.current=e},[e]),r.useEffect(()=>()=>{c()},[c]);const q=r.useCallback(async()=>{u("usb"),n(void 0),f(!1);let a;try{await c(),a=await i.requestUSBAccess({log:t.current});const s=await D.getPairRecord(a.hello.serialNumber);return b(a),g(s),t.current(s?"Pair record found":"No pair record found",a.hello.serialNumber),a}catch(s){await i.closeDeviceRelayTarget(a,t.current),b(void 0),g(void 0),n(w.errorMessage(s));return}finally{u(void 0)}},[c]),m=r.useCallback(async()=>{if(!o||!e)throw new Error("Select a USB device before pairing.");u("pair"),n(void 0),f(!1);try{await c();const a=await i.pairDevice({registryApiUrl:o,token:d,organizationId:v,log:t.current,target:e}),s=await D.putPairRecord(a.pairRecord,{productName:e.hello.productName});return a.relay.close(),await i.closeDeviceRelayTarget(e,t.current),g(s),f(!1),t.current("Device paired","The pair record was stored locally in this browser."),s}catch(a){await i.closeDeviceRelayTarget(e,t.current),f(!0),n(w.errorMessage(a));return}finally{u(void 0)}},[o,c,e,v,d]),A=r.useCallback(async a=>{if(!o||!e||!l)throw new Error("Select and pair a USB device before starting installation.");u("install"),n(void 0);try{return await c(),y.current=await i.startDeviceInstall({registryApiUrl:o,token:d,organizationId:v,log:t.current,target:e,pairRecord:l,installSource:a}),t.current("Device install started","Installation will continue through the connected iPhone."),y.current}catch(s){await i.closeDeviceRelayTarget(e,t.current),n(w.errorMessage(s));return}finally{u(void 0)}},[o,c,e,v,l,d]),B=r.useCallback(()=>{c(),t.current("Device relay stopped")},[c]);return{device:e,pairRecord:l,busyAction:R,error:S,pairConfirmationRequired:P,hasPairRecord:!!l,canPair:!!o&&!R&&!!e,canInstall:!!o&&!R&&!!e&&!!l,requestUSBAccess:q,pairBrowser:m,startInstallation:A,stopRelay:B,clearError:()=>n(void 0)}}function T(){}exports.useDeviceInstallRelay=C;
@@ -1,95 +1,96 @@
1
- import { useState as u, useRef as g, useCallback as l, useEffect as S } from "react";
1
+ import { useState as u, useRef as R, useCallback as l, useEffect as b } from "react";
2
2
  import { closeDeviceRelayTarget as d, requestUSBAccess as C, pairDevice as I, startDeviceInstall as T } from "./index.js";
3
- import { j, k as x } from "../browser-storage-Cx9eW-bm.mjs";
4
- function H({
5
- apiUrl: c,
3
+ import { e as g } from "../errors-gy8yQJos.mjs";
4
+ import { j, k as x } from "../browser-storage-BnO-Ma-e.mjs";
5
+ function J({
6
+ apiUrl: o,
6
7
  token: v,
7
8
  organizationId: f,
8
9
  log: m = L
9
10
  }) {
10
- const [e, D] = u(), [n, h] = u(), [p, s] = u(), [b, i] = u(), [A, w] = u(!1), y = g(void 0), P = g(void 0), r = g(m);
11
+ const [e, D] = u(), [s, p] = u(), [h, n] = u(), [S, i] = u(), [A, w] = u(!1), y = R(void 0), P = R(void 0), r = R(m);
11
12
  r.current = m;
12
- const a = l(async () => {
13
+ const c = l(async () => {
13
14
  y.current?.close(), y.current = void 0, await d(P.current, r.current);
14
15
  }, []);
15
- S(() => {
16
+ b(() => {
16
17
  P.current = e;
17
- }, [e]), S(() => () => {
18
- a();
19
- }, [a]);
18
+ }, [e]), b(() => () => {
19
+ c();
20
+ }, [c]);
20
21
  const B = l(async () => {
21
- s("usb"), i(void 0), w(!1);
22
+ n("usb"), i(void 0), w(!1);
22
23
  let t;
23
24
  try {
24
- await a(), t = await C({ log: r.current });
25
- const o = await j(t.hello.serialNumber);
26
- return D(t), h(o), r.current(
27
- o ? "Pair record found" : "No pair record found",
25
+ await c(), t = await C({ log: r.current });
26
+ const a = await j(t.hello.serialNumber);
27
+ return D(t), p(a), r.current(
28
+ a ? "Pair record found" : "No pair record found",
28
29
  t.hello.serialNumber
29
30
  ), t;
30
- } catch (o) {
31
- await d(t, r.current), D(void 0), h(void 0), i(R(o));
31
+ } catch (a) {
32
+ await d(t, r.current), D(void 0), p(void 0), i(g(a));
32
33
  return;
33
34
  } finally {
34
- s(void 0);
35
+ n(void 0);
35
36
  }
36
- }, [a]), E = l(async () => {
37
- if (!c || !e)
37
+ }, [c]), E = l(async () => {
38
+ if (!o || !e)
38
39
  throw new Error("Select a USB device before pairing.");
39
- s("pair"), i(void 0), w(!1);
40
+ n("pair"), i(void 0), w(!1);
40
41
  try {
41
- await a();
42
+ await c();
42
43
  const t = await I({
43
- registryApiUrl: c,
44
+ registryApiUrl: o,
44
45
  token: v,
45
46
  organizationId: f,
46
47
  log: r.current,
47
48
  target: e
48
- }), o = await x(t.pairRecord, {
49
+ }), a = await x(t.pairRecord, {
49
50
  productName: e.hello.productName
50
51
  });
51
- return t.relay.close(), await d(e, r.current), h(o), w(!1), r.current("Device paired", "The pair record was stored locally in this browser."), o;
52
+ return t.relay.close(), await d(e, r.current), p(a), w(!1), r.current("Device paired", "The pair record was stored locally in this browser."), a;
52
53
  } catch (t) {
53
- await d(e, r.current), w(!0), i(R(t));
54
+ await d(e, r.current), w(!0), i(g(t));
54
55
  return;
55
56
  } finally {
56
- s(void 0);
57
+ n(void 0);
57
58
  }
58
- }, [c, a, e, f, v]), N = l(
59
+ }, [o, c, e, f, v]), N = l(
59
60
  async (t) => {
60
- if (!c || !e || !n)
61
+ if (!o || !e || !s)
61
62
  throw new Error("Select and pair a USB device before starting installation.");
62
- s("install"), i(void 0);
63
+ n("install"), i(void 0);
63
64
  try {
64
- return await a(), y.current = await T({
65
- registryApiUrl: c,
65
+ return await c(), y.current = await T({
66
+ registryApiUrl: o,
66
67
  token: v,
67
68
  organizationId: f,
68
69
  log: r.current,
69
70
  target: e,
70
- pairRecord: n,
71
+ pairRecord: s,
71
72
  installSource: t
72
73
  }), r.current("Device install started", "Installation will continue through the connected iPhone."), y.current;
73
- } catch (o) {
74
- await d(e, r.current), i(R(o));
74
+ } catch (a) {
75
+ await d(e, r.current), i(g(a));
75
76
  return;
76
77
  } finally {
77
- s(void 0);
78
+ n(void 0);
78
79
  }
79
80
  },
80
- [c, a, e, f, n, v]
81
+ [o, c, e, f, s, v]
81
82
  ), q = l(() => {
82
- a(), r.current("Device relay stopped");
83
- }, [a]);
83
+ c(), r.current("Device relay stopped");
84
+ }, [c]);
84
85
  return {
85
86
  device: e,
86
- pairRecord: n,
87
- busyAction: p,
88
- error: b,
87
+ pairRecord: s,
88
+ busyAction: h,
89
+ error: S,
89
90
  pairConfirmationRequired: A,
90
- hasPairRecord: !!n,
91
- canPair: !!c && !p && !!e,
92
- canInstall: !!c && !p && !!e && !!n,
91
+ hasPairRecord: !!s,
92
+ canPair: !!o && !h && !!e,
93
+ canInstall: !!o && !h && !!e && !!s,
93
94
  requestUSBAccess: B,
94
95
  pairBrowser: E,
95
96
  startInstallation: N,
@@ -99,9 +100,6 @@ function H({
99
100
  }
100
101
  function L() {
101
102
  }
102
- function R(c) {
103
- return c instanceof Error ? c.message : String(c);
104
- }
105
103
  export {
106
- H as useDeviceInstallRelay
104
+ J as useDeviceInstallRelay
107
105
  };
@@ -0,0 +1 @@
1
+ "use strict";function s(e){return e instanceof Error?e.message:String(e)}exports.errorMessage=s;
@@ -0,0 +1,6 @@
1
+ function n(e) {
2
+ return e instanceof Error ? e.message : String(e);
3
+ }
4
+ export {
5
+ n as e
6
+ };