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

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 (67) hide show
  1. package/dist/app-store-relay/index.cjs +3 -3
  2. package/dist/app-store-relay/index.js +5 -5
  3. package/dist/app-store-relay/react.cjs +1 -1
  4. package/dist/app-store-relay/react.js +32 -33
  5. package/dist/apple-credentials/index.cjs +1 -0
  6. package/dist/apple-credentials/index.d.ts +59 -0
  7. package/dist/apple-credentials/index.js +227 -0
  8. package/dist/browser-storage-BnO-Ma-e.mjs +219 -0
  9. package/dist/browser-storage-DLxIqZk5.js +1 -0
  10. package/dist/client-D1drDXxE.js +1 -0
  11. package/dist/{client-C8ZDEjtD.mjs → client-DSuNtWDv.mjs} +1 -1
  12. package/dist/components/remote-control.d.ts +156 -0
  13. package/dist/core/device-install/storage/browser-storage.d.ts +8 -0
  14. package/dist/core/device-install/storage/index.d.ts +1 -0
  15. package/dist/core/device-install/storage/secret-store.d.ts +101 -0
  16. package/dist/core/device-install/types.d.ts +6 -0
  17. package/dist/core/errors.d.ts +1 -0
  18. package/dist/core/play-publish/google.d.ts +1 -1
  19. package/dist/device-build/index.cjs +1 -1
  20. package/dist/device-build/index.js +21 -20
  21. package/dist/device-build/react.cjs +1 -1
  22. package/dist/device-build/react.js +42 -43
  23. package/dist/device-install/index.cjs +1 -1
  24. package/dist/device-install/index.js +159 -161
  25. package/dist/device-install/react.cjs +1 -1
  26. package/dist/device-install/react.js +47 -49
  27. package/dist/errors-BSkqS7U-.js +1 -0
  28. package/dist/errors-gy8yQJos.mjs +6 -0
  29. package/dist/gsa-srp-Bme3JLEi.mjs +266 -0
  30. package/dist/gsa-srp-CCIfUz7Y.js +1 -0
  31. package/dist/index-ChhtuQ7e.js +22 -0
  32. package/dist/index-YDu8K9a4.mjs +11279 -0
  33. package/dist/index.cjs +1 -1
  34. package/dist/index.css +1 -1
  35. package/dist/index.js +1405 -1125
  36. package/dist/play-publish/index.cjs +1 -1
  37. package/dist/play-publish/index.js +27 -24
  38. package/dist/play-publish/react.cjs +1 -1
  39. package/dist/play-publish/react.d.ts +12 -2
  40. package/dist/play-publish/react.js +70 -60
  41. package/dist/{provisioning-BmsEnF6X.mjs → provisioning-B_DefBEp.mjs} +1 -1
  42. package/dist/{provisioning-Va0PH4Kk.js → provisioning-BlQMccX_.js} +1 -1
  43. package/package.json +6 -1
  44. package/src/app-store-relay/react.ts +1 -4
  45. package/src/apple-credentials/index.test.ts +158 -0
  46. package/src/apple-credentials/index.ts +241 -0
  47. package/src/components/remote-control.css +32 -0
  48. package/src/components/remote-control.tsx +865 -5
  49. package/src/core/device-install/operations/operations.ts +1 -4
  50. package/src/core/device-install/storage/browser-storage.test.ts +65 -0
  51. package/src/core/device-install/storage/browser-storage.ts +33 -0
  52. package/src/core/device-install/storage/index.ts +1 -0
  53. package/src/core/device-install/storage/secret-store.ts +298 -0
  54. package/src/core/device-install/types.ts +6 -0
  55. package/src/core/errors.ts +3 -0
  56. package/src/core/play-publish/google.ts +11 -2
  57. package/src/device-build/react.ts +1 -4
  58. package/src/device-install/demo/demo.tsx +1 -4
  59. package/src/device-install/react.ts +1 -4
  60. package/src/play-publish/README.md +5 -4
  61. package/src/play-publish/react.ts +72 -32
  62. package/vite.config.ts +1 -0
  63. package/dist/browser-storage-Cx9eW-bm.mjs +0 -205
  64. package/dist/browser-storage-jJaIht4K.js +0 -1
  65. package/dist/client-BtC4n_qf.js +0 -1
  66. package/dist/index-CMeQfhYy.js +0 -22
  67. package/dist/index-DFdCvi2_.mjs +0 -11543
@@ -1,4 +1,5 @@
1
- import { j as be, n as Ue, k as Se } from "../browser-storage-Cx9eW-bm.mjs";
1
+ import { e as y } from "../errors-gy8yQJos.mjs";
2
+ import { j as Ue, n as Se, k as ve } from "../browser-storage-BnO-Ma-e.mjs";
2
3
  const v = 1, f = 16, s = {
3
4
  DeviceHello: 1,
4
5
  OpenStream: 2,
@@ -14,19 +15,19 @@ 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(f + e.payload.byteLength), r = new DataView(t.buffer);
19
+ return r.setUint8(0, v), r.setUint8(1, e.type), r.setUint8(2, 0), r.setUint8(3, 0), r.setUint32(4, e.requestId), r.setUint32(8, e.streamId), r.setUint32(12, e.payload.byteLength), t.set(e.payload, f), t;
19
20
  }
20
21
  function A(e) {
21
22
  if (e.byteLength < f)
22
23
  throw new Error(`Relay frame too short: ${e.byteLength}`);
23
- const t = new DataView(e.buffer, e.byteOffset, e.byteLength), n = t.getUint8(0);
24
- if (n !== v)
25
- throw new Error(`Unsupported relay protocol version ${n}`);
26
- const r = t.getUint32(12);
27
- if (e.byteLength !== f + r)
24
+ const t = new DataView(e.buffer, e.byteOffset, e.byteLength), r = t.getUint8(0);
25
+ if (r !== v)
26
+ throw new Error(`Unsupported relay protocol version ${r}`);
27
+ const n = t.getUint32(12);
28
+ if (e.byteLength !== f + n)
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 ${f + n}`
30
31
  );
31
32
  return {
32
33
  type: t.getUint8(1),
@@ -47,23 +48,23 @@ async function C() {
47
48
  return navigator.usb.requestDevice({ filters: [{ vendorId: 1452 }] });
48
49
  }
49
50
  function L(e) {
50
- const t = [], n = e.configuration?.configurationValue, r = e.configurations.find(
51
- (a) => a.configurationValue === n
51
+ const t = [], r = e.configuration?.configurationValue, n = e.configurations.find(
52
+ (a) => a.configurationValue === r
52
53
  );
53
- r && t.push(...U(r));
54
+ n && t.push(...U(n));
54
55
  for (const a of e.configurations)
55
- a.configurationValue !== n && t.push(...U(a));
56
+ a.configurationValue !== r && t.push(...U(a));
56
57
  return t;
57
58
  }
58
59
  function U(e) {
59
60
  const t = [];
60
- for (const n of e.interfaces)
61
- for (const r of n.alternates)
62
- r.interfaceClass === 255 && r.interfaceSubclass === 254 && r.interfaceProtocol === 2 && t.push({
61
+ for (const r of e.interfaces)
62
+ for (const n of r.alternates)
63
+ n.interfaceClass === 255 && n.interfaceSubclass === 254 && n.interfaceProtocol === 2 && t.push({
63
64
  configurationValue: e.configurationValue,
64
- interfaceNumber: n.interfaceNumber,
65
- alternateSetting: r.alternateSetting,
66
- endpoints: r.endpoints
65
+ interfaceNumber: r.interfaceNumber,
66
+ alternateSetting: n.alternateSetting,
67
+ endpoints: n.endpoints
67
68
  });
68
69
  return t;
69
70
  }
@@ -72,35 +73,35 @@ async function T(e, t) {
72
73
  }
73
74
  function W(e) {
74
75
  const t = e.endpoints.find(
75
- (r) => r.direction === "out" && r.type === "bulk"
76
- ), n = e.endpoints.find(
77
- (r) => r.direction === "in" && r.type === "bulk"
76
+ (n) => n.direction === "out" && n.type === "bulk"
77
+ ), r = e.endpoints.find(
78
+ (n) => n.direction === "in" && n.type === "bulk"
78
79
  );
79
- if (!t || !n)
80
+ if (!t || !r)
80
81
  throw new Error("Could not find usbmux bulk endpoints.");
81
- return { outEndpoint: t, inEndpoint: n };
82
+ return { outEndpoint: t, inEndpoint: r };
82
83
  }
83
- async function R(e, t, n) {
84
- const r = await e.transferOut(t.endpointNumber, n);
85
- if (r.status !== "ok")
86
- throw new Error(`USB transferOut failed: ${r.status}`);
87
- n.byteLength % t.packetSize === 0 && await e.transferOut(t.endpointNumber, new Uint8Array());
84
+ async function R(e, t, r) {
85
+ const n = await e.transferOut(t.endpointNumber, r);
86
+ if (n.status !== "ok")
87
+ throw new Error(`USB transferOut failed: ${n.status}`);
88
+ r.byteLength % t.packetSize === 0 && await e.transferOut(t.endpointNumber, new Uint8Array());
88
89
  }
89
- async function B(e, t, n = 16384) {
90
- const r = await e.transferIn(t.endpointNumber, n);
91
- if (r.status !== "ok" || !r.data)
92
- throw new Error(`USB transferIn failed: ${r.status}`);
93
- return new Uint8Array(r.data.buffer, r.data.byteOffset, r.data.byteLength);
90
+ async function B(e, t, r = 16384) {
91
+ const n = await e.transferIn(t.endpointNumber, r);
92
+ if (n.status !== "ok" || !n.data)
93
+ throw new Error(`USB transferIn failed: ${n.status}`);
94
+ return new Uint8Array(n.data.buffer, n.data.byteOffset, n.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, d = 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
- 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 = {
98
+ const { inEndpoint: r, outEndpoint: n } = W(t), a = new Uint8Array(12), i = new DataView(a.buffer);
99
+ i.setUint32(0, 2), i.setUint32(4, 0), i.setUint32(8, 0), await R(e, n, O(E, a));
100
+ const o = await P(e, r, 1), c = new DataView(o.payload.buffer, o.payload.byteOffset).getUint32(0), u = {
100
101
  device: e,
101
102
  candidate: t,
102
- inEndpoint: n,
103
- outEndpoint: r,
103
+ inEndpoint: r,
104
+ outEndpoint: n,
104
105
  muxVersion: c,
105
106
  txSeq: 0,
106
107
  rxSeq: 65535,
@@ -114,7 +115,7 @@ async function H(e, t) {
114
115
  async function J(e, t) {
115
116
  if (e.closed)
116
117
  throw new Error("usbmux session is closed.");
117
- let n, r;
118
+ let r, n;
118
119
  const a = {
119
120
  session: e,
120
121
  sport: e.nextSport++,
@@ -124,12 +125,12 @@ async function J(e, t) {
124
125
  queue: [],
125
126
  waiters: [],
126
127
  opened: new Promise((i, o) => {
127
- n = i, r = o;
128
+ r = i, n = o;
128
129
  }),
129
- resolveOpened: n,
130
- rejectOpened: r
130
+ resolveOpened: r,
131
+ rejectOpened: n
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 w(a, m, new Uint8Array()), await a.opened, a;
133
134
  }
134
135
  async function G(e, t) {
135
136
  if (e.session.closed)
@@ -152,17 +153,17 @@ function I(e) {
152
153
  t.waiters.shift()(new Uint8Array());
153
154
  e.streams.clear();
154
155
  }
155
- async function w(e, t, n) {
156
- 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);
156
+ async function w(e, t, r) {
157
+ const n = new Uint8Array(20 + r.byteLength), a = new DataView(n.buffer);
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), n.set(r, 20), await x(e.session, k, n);
158
159
  }
159
- async function x(e, t, n) {
160
+ async function x(e, t, r) {
160
161
  if (e.closed)
161
162
  throw new Error("usbmux session is closed.");
162
163
  return e.writeChain = e.writeChain.then(async () => {
163
164
  if (e.closed) return;
164
- const r = e.muxVersion >= 2 ? z(t, n, e.txSeq++, e.rxSeq) : O(t, n);
165
- await R(e.device, e.outEndpoint, r);
165
+ const n = e.muxVersion >= 2 ? z(t, r, e.txSeq++, e.rxSeq) : O(t, r);
166
+ await R(e.device, e.outEndpoint, n);
166
167
  }), e.writeChain;
167
168
  }
168
169
  async function Y(e) {
@@ -173,66 +174,66 @@ async function Y(e) {
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
- if (r) {
178
- if (n.flags & M) {
179
- for (r.error = new Error(`Device reset stream ${r.dport}`), r.rejectOpened(r.error); r.waiters.length > 0; )
180
- r.waiters.shift()(new Uint8Array());
181
- e.streams.delete(m(r.dport, r.sport));
177
+ const r = X(t.payload), n = e.streams.get(g(r.sport, r.dport));
178
+ if (n) {
179
+ if (r.flags & M) {
180
+ for (n.error = new Error(`Device reset stream ${n.dport}`), n.rejectOpened(n.error); n.waiters.length > 0; )
181
+ n.waiters.shift()(new Uint8Array());
182
+ e.streams.delete(g(n.dport, n.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 ((r.flags & (m | d)) === (m | d)) {
186
+ n.seq += 1, n.ack = r.seq + 1, await w(n, d, new Uint8Array()), n.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
+ r.payload.byteLength !== 0 && (n.ack = r.seq + r.payload.byteLength, await w(n, d, new Uint8Array()), n.waiters.length > 0 ? n.waiters.shift()(r.payload) : n.queue.push(r.payload));
189
190
  }
190
191
  }
191
192
  } catch {
192
193
  e.closed || I(e);
193
194
  }
194
195
  }
195
- async function P(e, t, n) {
196
+ async function P(e, t, r) {
196
197
  for (; ; ) {
197
- const r = await B(e, t), a = K(r, n);
198
- if (!(n === 1 && a.protocol !== E))
198
+ const n = await B(e, t), a = K(n, r);
199
+ if (!(r === 1 && a.protocol !== E))
199
200
  return a;
200
201
  }
201
202
  }
202
203
  function O(e, t) {
203
- const n = new Uint8Array(8 + t.byteLength), r = new DataView(n.buffer);
204
- return r.setUint32(0, e), r.setUint32(4, n.byteLength), n.set(t, 8), n;
204
+ const r = new Uint8Array(8 + t.byteLength), n = new DataView(r.buffer);
205
+ return n.setUint32(0, e), n.setUint32(4, r.byteLength), r.set(t, 8), r;
205
206
  }
206
- function z(e, t, n, r) {
207
+ function z(e, t, r, n) {
207
208
  const a = new Uint8Array(16 + t.byteLength), i = new DataView(a.buffer);
208
- return i.setUint32(0, e), i.setUint32(4, a.byteLength), i.setUint32(8, _), i.setUint16(12, n), i.setUint16(14, r), a.set(t, 16), a;
209
+ return i.setUint32(0, e), i.setUint32(4, a.byteLength), i.setUint32(8, _), i.setUint16(12, r), i.setUint16(14, n), a.set(t, 16), a;
209
210
  }
210
211
  function K(e, t) {
211
- const n = new DataView(e.buffer, e.byteOffset, e.byteLength), r = n.getUint32(0), a = n.getUint32(4), i = t >= 2 ? 16 : 8;
212
+ const r = new DataView(e.buffer, e.byteOffset, e.byteLength), n = r.getUint32(0), a = r.getUint32(4), i = t >= 2 ? 16 : 8;
212
213
  return {
213
- protocol: r,
214
+ protocol: n,
214
215
  length: a,
215
- rxSeq: t >= 2 ? n.getUint16(14) : void 0,
216
+ rxSeq: t >= 2 ? r.getUint16(14) : void 0,
216
217
  payload: e.slice(i, a)
217
218
  };
218
219
  }
219
220
  function X(e) {
220
- const t = new DataView(e.buffer, e.byteOffset, e.byteLength), n = (t.getUint8(12) >> 4) * 4;
221
+ const t = new DataView(e.buffer, e.byteOffset, e.byteLength), r = (t.getUint8(12) >> 4) * 4;
221
222
  return {
222
223
  sport: t.getUint16(0),
223
224
  dport: t.getUint16(2),
224
225
  seq: t.getUint32(4),
225
226
  ack: t.getUint32(8),
226
227
  flags: t.getUint8(13),
227
- payload: e.slice(n)
228
+ payload: e.slice(r)
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 {
234
- constructor(t, n, r, a) {
235
- this.webSocketUrl = t, this.session = n, this.deviceHello = r, this.log = a;
235
+ constructor(t, r, n, a) {
236
+ this.webSocketUrl = t, this.session = r, this.deviceHello = n, this.log = a;
236
237
  }
237
238
  socket;
238
239
  streams = /* @__PURE__ */ new Map();
@@ -245,11 +246,11 @@ class Z {
245
246
  this.closed = !0, this.log("Relay socket closed"), this.frameQueue.finally(() => {
246
247
  this.pairRecordWaiter && (this.pairRecordWaiter.reject(new Error("Relay socket closed")), this.pairRecordWaiter = void 0);
247
248
  });
248
- }, await new Promise((n, r) => {
249
- t.onopen = () => n(), t.onerror = () => r(new Error("WebSocket connection failed"));
250
- }), t.onmessage = (n) => {
251
- const r = n.data instanceof ArrayBuffer ? new Uint8Array(n.data) : new Uint8Array();
252
- this.enqueueFrame(r);
249
+ }, await new Promise((r, n) => {
250
+ t.onopen = () => r(), t.onerror = () => n(new Error("WebSocket connection failed"));
251
+ }), t.onmessage = (r) => {
252
+ const n = r.data instanceof ArrayBuffer ? new Uint8Array(r.data) : new Uint8Array();
253
+ this.enqueueFrame(n);
253
254
  }, await this.send({
254
255
  type: s.DeviceHello,
255
256
  requestId: 0,
@@ -258,8 +259,8 @@ class Z {
258
259
  }), this.log("Connected WebSocket relay");
259
260
  }
260
261
  async startPairing() {
261
- const t = new Promise((n, r) => {
262
- this.pairRecordWaiter = { resolve: n, reject: r };
262
+ const t = new Promise((r, n) => {
263
+ this.pairRecordWaiter = { resolve: r, reject: n };
263
264
  });
264
265
  return await this.send({
265
266
  type: s.StartPairing,
@@ -268,20 +269,20 @@ class Z {
268
269
  payload: l({})
269
270
  }), this.log("Pairing requested"), t;
270
271
  }
271
- async startInstall(t, n) {
272
+ async startInstall(t, r) {
272
273
  await this.send({
273
274
  type: s.StartInstall,
274
275
  requestId: 0,
275
276
  streamId: 0,
276
- payload: l({ ...t, ...n })
277
+ payload: l({ ...t, ...r })
277
278
  }), this.log("Installation requested");
278
279
  }
279
280
  close() {
280
281
  this.closed = !0, this.socket?.close();
281
282
  }
282
283
  enqueueFrame(t) {
283
- this.frameQueue = this.frameQueue.then(() => this.handleFrame(A(t))).catch((n) => {
284
- this.log("Relay frame handling failed", n instanceof Error ? n.message : String(n));
284
+ this.frameQueue = this.frameQueue.then(() => this.handleFrame(A(t))).catch((r) => {
285
+ this.log("Relay frame handling failed", r instanceof Error ? r.message : String(r));
285
286
  });
286
287
  }
287
288
  async handleFrame(t) {
@@ -294,9 +295,9 @@ class Z {
294
295
  );
295
296
  break;
296
297
  case s.StreamData: {
297
- const n = this.streams.get(t.streamId);
298
- if (!n) throw new Error(`Unknown stream ${t.streamId}`);
299
- await G(n, t.payload);
298
+ const r = this.streams.get(t.streamId);
299
+ if (!r) throw new Error(`Unknown stream ${t.streamId}`);
300
+ await G(r, t.payload);
300
301
  break;
301
302
  }
302
303
  case s.StreamClose:
@@ -322,29 +323,29 @@ class Z {
322
323
  }
323
324
  }
324
325
  handleError(t) {
325
- const n = ee(t);
326
- this.log("Server error", n), this.pairRecordWaiter && (this.pairRecordWaiter.reject(new Error(n)), this.pairRecordWaiter = void 0);
326
+ const r = ee(t);
327
+ this.log("Server error", r), this.pairRecordWaiter && (this.pairRecordWaiter.reject(new Error(r)), this.pairRecordWaiter = void 0);
327
328
  }
328
329
  handlePairRecordReady(t) {
329
330
  this.log("Pair record received", t.udid), this.pairRecordWaiter?.resolve(t), this.pairRecordWaiter = void 0;
330
331
  }
331
- async handleOpenStream(t, n, r) {
332
+ async handleOpenStream(t, r, n) {
332
333
  try {
333
- const a = await J(this.session, r);
334
- this.streams.set(n, a), await this.send({
334
+ const a = await J(this.session, n);
335
+ this.streams.set(r, a), await this.send({
335
336
  type: s.OpenResult,
336
337
  requestId: t,
337
- streamId: n,
338
+ streamId: r,
338
339
  payload: l({ ok: !0 })
339
- }), this.log(`Opened device stream ${n} to port ${r}`), this.pumpDeviceToServer(n, a);
340
+ }), this.log(`Opened device stream ${r} to port ${n}`), this.pumpDeviceToServer(r, a);
340
341
  } catch (a) {
341
342
  this.log(
342
- `Open device stream ${n} failed`,
343
+ `Open device stream ${r} failed`,
343
344
  a instanceof Error ? a.message : String(a)
344
345
  ), await this.send({
345
346
  type: s.OpenResult,
346
347
  requestId: t,
347
- streamId: n,
348
+ streamId: r,
348
349
  payload: l({
349
350
  ok: !1,
350
351
  error: a instanceof Error ? a.message : String(a)
@@ -352,25 +353,25 @@ class Z {
352
353
  });
353
354
  }
354
355
  }
355
- async pumpDeviceToServer(t, n) {
356
+ async pumpDeviceToServer(t, r) {
356
357
  try {
357
358
  for (; ; ) {
358
- const r = await Q(n);
359
+ const n = await Q(r);
359
360
  if (this.closed) return;
360
361
  await this.send({
361
362
  type: s.StreamData,
362
363
  requestId: 0,
363
364
  streamId: t,
364
- payload: r
365
+ payload: n
365
366
  });
366
367
  }
367
- } catch (r) {
368
- this.log(`Device stream ${t} closed`, r instanceof Error ? r.message : String(r)), await this.send({
368
+ } catch (n) {
369
+ this.log(`Device stream ${t} closed`, n instanceof Error ? n.message : String(n)), await this.send({
369
370
  type: s.StreamClose,
370
371
  requestId: 0,
371
372
  streamId: t,
372
373
  payload: l({
373
- reason: r instanceof Error ? r.message : String(r)
374
+ reason: n instanceof Error ? n.message : String(n)
374
375
  })
375
376
  });
376
377
  }
@@ -388,8 +389,8 @@ class Z {
388
389
  function ee(e) {
389
390
  const t = new TextDecoder().decode(e);
390
391
  try {
391
- const n = JSON.parse(t);
392
- return S(n.error ?? t);
392
+ const r = JSON.parse(t);
393
+ return S(r.error ?? t);
393
394
  } catch {
394
395
  return S(t);
395
396
  }
@@ -401,47 +402,47 @@ function te(e) {
401
402
  const t = "install status: ";
402
403
  if (!e.startsWith(t))
403
404
  return e;
404
- const n = e.slice(t.length), r = p(n, "Error");
405
- if (r) {
406
- const o = p(n, "ErrorDescription");
407
- return `Install error: ${r}${o ? ` — ${o}` : ""}`;
405
+ const r = e.slice(t.length), n = p(r, "Error");
406
+ if (n) {
407
+ const o = p(r, "ErrorDescription");
408
+ return `Install error: ${n}${o ? ` — ${o}` : ""}`;
408
409
  }
409
- const a = p(n, "Status") ?? "Unknown", i = p(n, "PercentComplete");
410
+ const a = p(r, "Status") ?? "Unknown", i = p(r, "PercentComplete");
410
411
  return `Install progress: ${i ? `${i}% ` : ""}${a}`;
411
412
  }
412
413
  function p(e, t) {
413
- const r = new RegExp(
414
- `<key>\\s*${ne(
414
+ const n = new RegExp(
415
+ `<key>\\s*${re(
415
416
  t
416
417
  )}\\s*</key>\\s*<(?:string|integer|real)>([\\s\\S]*?)</(?:string|integer|real)>`
417
418
  ).exec(e);
418
- return r ? re(r[1].trim()) : void 0;
419
+ return n ? ne(n[1].trim()) : void 0;
419
420
  }
420
- function ne(e) {
421
+ function re(e) {
421
422
  return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
422
423
  }
423
- function re(e) {
424
+ function ne(e) {
424
425
  return e.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&amp;/g, "&");
425
426
  }
426
427
  async function ae({ log: e }) {
427
428
  e("Selecting USB device");
428
- const t = await C(), n = ue(t);
429
+ const t = await C(), r = ue(t);
429
430
  return e(
430
431
  "Selected USB device",
431
432
  `${t.manufacturerName ?? ""} ${t.productName ?? ""} ${t.serialNumber ?? ""}`.trim()
432
- ), n;
433
+ ), r;
433
434
  }
434
435
  async function ie({
435
436
  registryApiUrl: e,
436
437
  token: t,
437
- organizationId: n,
438
- log: r,
438
+ organizationId: r,
439
+ log: n,
439
440
  target: a
440
441
  }) {
441
- const i = N(e, t, n);
442
+ const i = N(e, t, r);
442
443
  let o;
443
444
  try {
444
- o = await $(i, a, r);
445
+ o = await $(i, a, n);
445
446
  const c = await o.startPairing();
446
447
  return { relay: o, pairRecord: c, target: a };
447
448
  } catch (c) {
@@ -451,16 +452,16 @@ async function ie({
451
452
  async function oe({
452
453
  registryApiUrl: e,
453
454
  token: t,
454
- organizationId: n,
455
- log: r,
455
+ organizationId: r,
456
+ log: n,
456
457
  target: a,
457
458
  pairRecord: i,
458
459
  installSource: o
459
460
  }) {
460
- const c = N(e, t, n);
461
+ const c = N(e, t, r);
461
462
  let u;
462
463
  try {
463
- return u = await $(c, a, r), await u.startInstall(i, o), u;
464
+ return u = await $(c, a, n), await u.startInstall(i, o), u;
464
465
  } catch (D) {
465
466
  throw u?.close(), D;
466
467
  }
@@ -470,30 +471,30 @@ async function se(e, t) {
470
471
  if (e.session && (I(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
- } catch (n) {
474
- t?.("USB interface release failed", g(n));
474
+ } catch (r) {
475
+ t?.("USB interface release failed", y(r));
475
476
  } finally {
476
477
  e.claimedInterfaceNumber = void 0;
477
478
  }
478
479
  if (e.device.opened)
479
480
  try {
480
481
  await e.device.close(), t?.("Closed USB device");
481
- } catch (n) {
482
- t?.("USB device close failed", g(n));
482
+ } catch (r) {
483
+ t?.("USB device close failed", y(r));
483
484
  }
484
485
  }
485
486
  }
486
- async function $(e, t, n) {
487
- await ce(t, n);
488
- const r = new Z(e, t.session, t.hello, n);
489
- return await r.connect(), r;
487
+ async function $(e, t, r) {
488
+ await ce(t, r);
489
+ const n = new Z(e, t.session, t.hello, r);
490
+ return await n.connect(), n;
490
491
  }
491
492
  async function ce(e, t) {
492
493
  if (!e.session)
493
494
  try {
494
495
  e.candidate = await le(e, t), e.session = await H(e.device, e.candidate), t("Created usbmux session");
495
- } catch (n) {
496
- throw await se(e, t), n;
496
+ } catch (r) {
497
+ throw await se(e, t), r;
497
498
  }
498
499
  }
499
500
  function ue(e) {
@@ -510,10 +511,10 @@ function ue(e) {
510
511
  };
511
512
  }
512
513
  async function le(e, t) {
513
- const n = q(e.device);
514
- if (n.length === 0) throw new Error("No Apple usbmux interface found.");
515
- let r;
516
- for (const a of n)
514
+ const r = q(e.device);
515
+ if (r.length === 0) throw new Error("No Apple usbmux interface found.");
516
+ let n;
517
+ for (const a of r)
517
518
  for (const i of [1, 2])
518
519
  try {
519
520
  return e.device.opened || await e.device.open(), t(
@@ -524,12 +525,12 @@ async function le(e, t) {
524
525
  `configuration ${a.configurationValue}, interface ${a.interfaceNumber}`
525
526
  ), a;
526
527
  } catch (o) {
527
- r = o, t(
528
+ n = o, t(
528
529
  "USB interface claim failed",
529
- `configuration ${a.configurationValue}, interface ${a.interfaceNumber}: ${g(o)}`
530
+ `configuration ${a.configurationValue}, interface ${a.interfaceNumber}: ${y(o)}`
530
531
  ), await de(e), await pe(250);
531
532
  }
532
- throw r instanceof Error ? r : new Error("Unable to claim any Apple usbmux interface.");
533
+ throw n instanceof Error ? n : new Error("Unable to claim any Apple usbmux interface.");
533
534
  }
534
535
  function fe(e) {
535
536
  const t = q(e)[0];
@@ -537,18 +538,15 @@ function fe(e) {
537
538
  return t;
538
539
  }
539
540
  function q(e) {
540
- const t = L(e), n = e.configuration?.configurationValue;
541
+ const t = L(e), r = e.configuration?.configurationValue;
541
542
  return [
542
- ...t.filter((r) => r.configurationValue === n),
543
- ...t.filter((r) => r.configurationValue !== n)
543
+ ...t.filter((n) => n.configurationValue === r),
544
+ ...t.filter((n) => n.configurationValue !== r)
544
545
  ];
545
546
  }
546
- function N(e, t, n) {
547
- const r = new URL(e);
548
- 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
- }
550
- function g(e) {
551
- return e instanceof Error ? e.message : String(e);
547
+ function N(e, t, r) {
548
+ const n = new URL(e);
549
+ return n.protocol = n.protocol === "https:" ? "wss:" : "ws:", n.pathname = `${n.pathname.replace(/\/$/, "")}/ios/device/ws`, t && n.searchParams.set("token", t), r && n.searchParams.set("organization", r), n.toString();
552
550
  }
553
551
  async function de(e) {
554
552
  if (e.claimedInterfaceNumber !== void 0) {
@@ -567,13 +565,13 @@ async function de(e) {
567
565
  function pe(e) {
568
566
  return new Promise((t) => setTimeout(t, e));
569
567
  }
570
- async function we(e = {}) {
568
+ async function he(e = {}) {
571
569
  return ae({ log: e.log ?? b });
572
570
  }
573
- async function he(e) {
571
+ async function ye(e) {
574
572
  return ie({ ...e, log: e.log ?? b });
575
573
  }
576
- async function ye(e) {
574
+ async function me(e) {
577
575
  return oe({ ...e, log: e.log ?? b });
578
576
  }
579
577
  function b() {
@@ -582,12 +580,12 @@ export {
582
580
  Z as RelayClient,
583
581
  se as closeDeviceRelayTarget,
584
582
  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,
583
+ Ue as getPairRecord,
584
+ Se as normalizeUDID,
585
+ ye as pairDevice,
586
+ ve as putPairRecord,
587
+ he as requestUSBAccess,
588
+ me as startDeviceInstall,
591
589
  oe as startDeviceInstallRelay,
592
590
  ie as startDevicePairingRelay
593
591
  };
@@ -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;