@limrun/ui 0.14.0-rc.4 → 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 (31) 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 +1 -1
  6. package/dist/apple-credentials/index.cjs +1 -1
  7. package/dist/apple-credentials/index.d.ts +59 -8
  8. package/dist/apple-credentials/index.js +197 -133
  9. package/dist/client-C9z_sgOf.js +1 -0
  10. package/dist/{client-DSuNtWDv.mjs → client-CFDB4mX5.mjs} +37 -30
  11. package/dist/core/device-install/apple/provisioning.d.ts +25 -0
  12. package/dist/core/device-install/apple/relay.d.ts +13 -0
  13. package/dist/core/device-install/storage/secret-store.d.ts +24 -1
  14. package/dist/device-build/index.cjs +1 -1
  15. package/dist/device-build/index.js +1 -1
  16. package/dist/device-install/index.cjs +1 -1
  17. package/dist/device-install/index.js +175 -172
  18. package/dist/{provisioning-B_DefBEp.mjs → provisioning-CDPvxd1h.mjs} +63 -32
  19. package/dist/provisioning-CbC4h--7.js +1 -0
  20. package/package.json +1 -1
  21. package/src/app-store-relay/index.ts +358 -23
  22. package/src/apple-credentials/index.test.ts +22 -0
  23. package/src/apple-credentials/index.ts +161 -14
  24. package/src/core/device-install/apple/client.ts +13 -6
  25. package/src/core/device-install/apple/provisioning.test.ts +30 -0
  26. package/src/core/device-install/apple/provisioning.ts +39 -0
  27. package/src/core/device-install/apple/relay.ts +20 -0
  28. package/src/core/device-install/operations/operations.ts +6 -1
  29. package/src/core/device-install/storage/secret-store.ts +36 -2
  30. package/dist/client-D1drDXxE.js +0 -1
  31. package/dist/provisioning-BlQMccX_.js +0 -1
@@ -1,6 +1,6 @@
1
- import { e as y } from "../errors-gy8yQJos.mjs";
1
+ import { e as w } from "../errors-gy8yQJos.mjs";
2
2
  import { j as Ue, n as Se, k as ve } from "../browser-storage-BnO-Ma-e.mjs";
3
- const v = 1, f = 16, s = {
3
+ const v = 1, d = 16, s = {
4
4
  DeviceHello: 1,
5
5
  OpenStream: 2,
6
6
  OpenResult: 3,
@@ -15,31 +15,31 @@ const v = 1, f = 16, s = {
15
15
  PairRecordReady: 12
16
16
  };
17
17
  function V(e) {
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;
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;
20
20
  }
21
21
  function A(e) {
22
- if (e.byteLength < f)
22
+ if (e.byteLength < d)
23
23
  throw new Error(`Relay frame too short: ${e.byteLength}`);
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)
24
+ const t = new DataView(e.buffer, e.byteOffset, e.byteLength), n = t.getUint8(0);
25
+ if (n !== v)
26
+ throw new Error(`Unsupported relay protocol version ${n}`);
27
+ const r = t.getUint32(12);
28
+ if (e.byteLength !== d + r)
29
29
  throw new Error(
30
- `Relay frame length mismatch: got ${e.byteLength}, expected ${f + n}`
30
+ `Relay frame length mismatch: got ${e.byteLength}, expected ${d + r}`
31
31
  );
32
32
  return {
33
33
  type: t.getUint8(1),
34
34
  requestId: t.getUint32(4),
35
35
  streamId: t.getUint32(8),
36
- payload: e.slice(f)
36
+ payload: e.slice(d)
37
37
  };
38
38
  }
39
39
  function l(e) {
40
40
  return new TextEncoder().encode(JSON.stringify(e));
41
41
  }
42
- function h(e) {
42
+ function y(e) {
43
43
  return JSON.parse(new TextDecoder().decode(e));
44
44
  }
45
45
  async function C() {
@@ -48,60 +48,60 @@ async function C() {
48
48
  return navigator.usb.requestDevice({ filters: [{ vendorId: 1452 }] });
49
49
  }
50
50
  function L(e) {
51
- const t = [], r = e.configuration?.configurationValue, n = e.configurations.find(
52
- (a) => a.configurationValue === r
51
+ const t = [], n = e.configuration?.configurationValue, r = e.configurations.find(
52
+ (a) => a.configurationValue === n
53
53
  );
54
- n && t.push(...U(n));
54
+ r && t.push(...U(r));
55
55
  for (const a of e.configurations)
56
- a.configurationValue !== r && t.push(...U(a));
56
+ a.configurationValue !== n && t.push(...U(a));
57
57
  return t;
58
58
  }
59
59
  function U(e) {
60
60
  const t = [];
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({
61
+ for (const n of e.interfaces)
62
+ for (const r of n.alternates)
63
+ r.interfaceClass === 255 && r.interfaceSubclass === 254 && r.interfaceProtocol === 2 && t.push({
64
64
  configurationValue: e.configurationValue,
65
- interfaceNumber: r.interfaceNumber,
66
- alternateSetting: n.alternateSetting,
67
- endpoints: n.endpoints
65
+ interfaceNumber: n.interfaceNumber,
66
+ alternateSetting: r.alternateSetting,
67
+ endpoints: r.endpoints
68
68
  });
69
69
  return t;
70
70
  }
71
71
  async function T(e, t) {
72
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);
73
73
  }
74
- function W(e) {
74
+ function B(e) {
75
75
  const t = e.endpoints.find(
76
- (n) => n.direction === "out" && n.type === "bulk"
77
- ), r = e.endpoints.find(
78
- (n) => n.direction === "in" && n.type === "bulk"
76
+ (r) => r.direction === "out" && r.type === "bulk"
77
+ ), n = e.endpoints.find(
78
+ (r) => r.direction === "in" && r.type === "bulk"
79
79
  );
80
- if (!t || !r)
80
+ if (!t || !n)
81
81
  throw new Error("Could not find usbmux bulk endpoints.");
82
- return { outEndpoint: t, inEndpoint: r };
82
+ return { outEndpoint: t, inEndpoint: n };
83
83
  }
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());
84
+ async function R(e, t, n) {
85
+ const r = await e.transferOut(t.endpointNumber, n);
86
+ if (r.status !== "ok")
87
+ throw new Error(`USB transferOut failed: ${r.status}`);
88
+ n.byteLength % t.packetSize === 0 && await e.transferOut(t.endpointNumber, new Uint8Array());
89
89
  }
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);
90
+ async function W(e, t, n = 16384) {
91
+ const r = await e.transferIn(t.endpointNumber, n);
92
+ if (r.status !== "ok" || !r.data)
93
+ throw new Error(`USB transferIn failed: ${r.status}`);
94
+ return new Uint8Array(r.data.buffer, r.data.byteOffset, r.data.byteLength);
95
95
  }
96
- const E = 0, F = 2, k = 6, _ = 4277009102, m = 2, M = 4, d = 16, j = 49152;
96
+ const E = 0, F = 2, k = 6, _ = 4277009102, m = 2, M = 4, f = 16, j = 49152;
97
97
  async function H(e, t) {
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 = {
98
+ const { inEndpoint: n, outEndpoint: r } = B(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, r, O(E, a));
100
+ const o = await x(e, n, 1), c = new DataView(o.payload.buffer, o.payload.byteOffset).getUint32(0), u = {
101
101
  device: e,
102
102
  candidate: t,
103
- inEndpoint: r,
104
- outEndpoint: n,
103
+ inEndpoint: n,
104
+ outEndpoint: r,
105
105
  muxVersion: c,
106
106
  txSeq: 0,
107
107
  rxSeq: 65535,
@@ -110,12 +110,12 @@ async function H(e, t) {
110
110
  writeChain: Promise.resolve(),
111
111
  closed: !1
112
112
  };
113
- 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;
114
114
  }
115
115
  async function J(e, t) {
116
116
  if (e.closed)
117
117
  throw new Error("usbmux session is closed.");
118
- let r, n;
118
+ let n, r;
119
119
  const a = {
120
120
  session: e,
121
121
  sport: e.nextSport++,
@@ -125,17 +125,17 @@ async function J(e, t) {
125
125
  queue: [],
126
126
  waiters: [],
127
127
  opened: new Promise((i, o) => {
128
- r = i, n = o;
128
+ n = i, r = o;
129
129
  }),
130
- resolveOpened: r,
131
- rejectOpened: n
130
+ resolveOpened: n,
131
+ rejectOpened: r
132
132
  };
133
- return e.streams.set(g(t, a.sport), a), await w(a, m, 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;
134
134
  }
135
135
  async function G(e, t) {
136
136
  if (e.session.closed)
137
137
  throw new Error("usbmux session is closed.");
138
- await w(e, d, t), e.seq += t.byteLength;
138
+ await h(e, f, t), e.seq += t.byteLength;
139
139
  }
140
140
  async function Q(e) {
141
141
  if (e.queue.length > 0)
@@ -146,94 +146,94 @@ async function Q(e) {
146
146
  e.waiters.push(t);
147
147
  });
148
148
  }
149
- function I(e) {
149
+ function P(e) {
150
150
  e.closed = !0;
151
151
  for (const t of e.streams.values())
152
152
  for (t.error = new Error("usbmux session closed"), t.rejectOpened(t.error); t.waiters.length > 0; )
153
153
  t.waiters.shift()(new Uint8Array());
154
154
  e.streams.clear();
155
155
  }
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);
156
+ async function h(e, t, n) {
157
+ const r = new Uint8Array(20 + n.byteLength), a = new DataView(r.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), r.set(n, 20), await I(e.session, k, r);
159
159
  }
160
- async function x(e, t, r) {
160
+ async function I(e, t, n) {
161
161
  if (e.closed)
162
162
  throw new Error("usbmux session is closed.");
163
163
  return e.writeChain = e.writeChain.then(async () => {
164
164
  if (e.closed) return;
165
- const n = e.muxVersion >= 2 ? z(t, r, e.txSeq++, e.rxSeq) : O(t, r);
166
- await R(e.device, e.outEndpoint, n);
165
+ const r = e.muxVersion >= 2 ? z(t, n, e.txSeq++, e.rxSeq) : O(t, n);
166
+ await R(e.device, e.outEndpoint, r);
167
167
  }), e.writeChain;
168
168
  }
169
169
  async function Y(e) {
170
170
  try {
171
171
  for (; ; ) {
172
172
  if (e.closed) return;
173
- const t = await P(e.device, e.inEndpoint, e.muxVersion);
173
+ const t = await x(e.device, e.inEndpoint, e.muxVersion);
174
174
  if (e.closed) return;
175
175
  if (t.rxSeq !== void 0 && (e.rxSeq = t.rxSeq), t.protocol !== k)
176
176
  continue;
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));
177
+ const n = X(t.payload), r = e.streams.get(g(n.sport, n.dport));
178
+ if (r) {
179
+ if (n.flags & M) {
180
+ for (r.error = new Error(`Device reset stream ${r.dport}`), r.rejectOpened(r.error); r.waiters.length > 0; )
181
+ r.waiters.shift()(new Uint8Array());
182
+ e.streams.delete(g(r.dport, r.sport));
183
183
  continue;
184
184
  }
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();
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();
187
187
  continue;
188
188
  }
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
+ 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));
190
190
  }
191
191
  }
192
192
  } catch {
193
- e.closed || I(e);
193
+ e.closed || P(e);
194
194
  }
195
195
  }
196
- async function P(e, t, r) {
196
+ async function x(e, t, n) {
197
197
  for (; ; ) {
198
- const n = await B(e, t), a = K(n, r);
199
- if (!(r === 1 && a.protocol !== E))
198
+ const r = await W(e, t), a = K(r, n);
199
+ if (!(n === 1 && a.protocol !== E))
200
200
  return a;
201
201
  }
202
202
  }
203
203
  function O(e, t) {
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;
204
+ const n = new Uint8Array(8 + t.byteLength), r = new DataView(n.buffer);
205
+ return r.setUint32(0, e), r.setUint32(4, n.byteLength), n.set(t, 8), n;
206
206
  }
207
- function z(e, t, r, n) {
207
+ function z(e, t, n, r) {
208
208
  const a = new Uint8Array(16 + t.byteLength), i = new DataView(a.buffer);
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
+ 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;
210
210
  }
211
211
  function K(e, t) {
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
+ const n = new DataView(e.buffer, e.byteOffset, e.byteLength), r = n.getUint32(0), a = n.getUint32(4), i = t >= 2 ? 16 : 8;
213
213
  return {
214
- protocol: n,
214
+ protocol: r,
215
215
  length: a,
216
- rxSeq: t >= 2 ? r.getUint16(14) : void 0,
216
+ rxSeq: t >= 2 ? n.getUint16(14) : void 0,
217
217
  payload: e.slice(i, a)
218
218
  };
219
219
  }
220
220
  function X(e) {
221
- const t = new DataView(e.buffer, e.byteOffset, e.byteLength), r = (t.getUint8(12) >> 4) * 4;
221
+ const t = new DataView(e.buffer, e.byteOffset, e.byteLength), n = (t.getUint8(12) >> 4) * 4;
222
222
  return {
223
223
  sport: t.getUint16(0),
224
224
  dport: t.getUint16(2),
225
225
  seq: t.getUint32(4),
226
226
  ack: t.getUint32(8),
227
227
  flags: t.getUint8(13),
228
- payload: e.slice(r)
228
+ payload: e.slice(n)
229
229
  };
230
230
  }
231
231
  function g(e, t) {
232
232
  return `${e}:${t}`;
233
233
  }
234
234
  class Z {
235
- constructor(t, r, n, a) {
236
- this.webSocketUrl = t, this.session = r, this.deviceHello = n, this.log = a;
235
+ constructor(t, n, r, a) {
236
+ this.webSocketUrl = t, this.session = n, this.deviceHello = r, this.log = a;
237
237
  }
238
238
  socket;
239
239
  streams = /* @__PURE__ */ new Map();
@@ -246,11 +246,11 @@ class Z {
246
246
  this.closed = !0, this.log("Relay socket closed"), this.frameQueue.finally(() => {
247
247
  this.pairRecordWaiter && (this.pairRecordWaiter.reject(new Error("Relay socket closed")), this.pairRecordWaiter = void 0);
248
248
  });
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);
249
+ }, await new Promise((n, r) => {
250
+ t.onopen = () => n(), t.onerror = () => r(new Error("WebSocket connection failed"));
251
+ }), t.onmessage = (n) => {
252
+ const r = n.data instanceof ArrayBuffer ? new Uint8Array(n.data) : new Uint8Array();
253
+ this.enqueueFrame(r);
254
254
  }, await this.send({
255
255
  type: s.DeviceHello,
256
256
  requestId: 0,
@@ -259,8 +259,8 @@ class Z {
259
259
  }), this.log("Connected WebSocket relay");
260
260
  }
261
261
  async startPairing() {
262
- const t = new Promise((r, n) => {
263
- this.pairRecordWaiter = { resolve: r, reject: n };
262
+ const t = new Promise((n, r) => {
263
+ this.pairRecordWaiter = { resolve: n, reject: r };
264
264
  });
265
265
  return await this.send({
266
266
  type: s.StartPairing,
@@ -269,20 +269,20 @@ class Z {
269
269
  payload: l({})
270
270
  }), this.log("Pairing requested"), t;
271
271
  }
272
- async startInstall(t, r) {
272
+ async startInstall(t, n) {
273
273
  await this.send({
274
274
  type: s.StartInstall,
275
275
  requestId: 0,
276
276
  streamId: 0,
277
- payload: l({ ...t, ...r })
277
+ payload: l({ ...t, ...n })
278
278
  }), this.log("Installation requested");
279
279
  }
280
280
  close() {
281
281
  this.closed = !0, this.socket?.close();
282
282
  }
283
283
  enqueueFrame(t) {
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));
284
+ this.frameQueue = this.frameQueue.then(() => this.handleFrame(A(t))).catch((n) => {
285
+ this.log("Relay frame handling failed", n instanceof Error ? n.message : String(n));
286
286
  });
287
287
  }
288
288
  async handleFrame(t) {
@@ -291,26 +291,26 @@ class Z {
291
291
  await this.handleOpenStream(
292
292
  t.requestId,
293
293
  t.streamId,
294
- h(t.payload).port
294
+ y(t.payload).port
295
295
  );
296
296
  break;
297
297
  case s.StreamData: {
298
- const r = this.streams.get(t.streamId);
299
- if (!r) throw new Error(`Unknown stream ${t.streamId}`);
300
- await G(r, t.payload);
298
+ const n = this.streams.get(t.streamId);
299
+ if (!n) throw new Error(`Unknown stream ${t.streamId}`);
300
+ await G(n, t.payload);
301
301
  break;
302
302
  }
303
303
  case s.StreamClose:
304
304
  this.streams.delete(t.streamId);
305
305
  break;
306
306
  case s.InstallProgress:
307
- this.log(te(h(t.payload).message));
307
+ this.log(te(y(t.payload).message));
308
308
  break;
309
309
  case s.Error:
310
310
  this.handleError(t.payload);
311
311
  break;
312
312
  case s.PairRecordReady:
313
- this.handlePairRecordReady(h(t.payload));
313
+ this.handlePairRecordReady(y(t.payload));
314
314
  break;
315
315
  case s.Ping:
316
316
  await this.send({
@@ -323,29 +323,29 @@ class Z {
323
323
  }
324
324
  }
325
325
  handleError(t) {
326
- const r = ee(t);
327
- this.log("Server error", r), this.pairRecordWaiter && (this.pairRecordWaiter.reject(new Error(r)), this.pairRecordWaiter = void 0);
326
+ const n = ee(t);
327
+ this.log("Server error", n), this.pairRecordWaiter && (this.pairRecordWaiter.reject(new Error(n)), this.pairRecordWaiter = void 0);
328
328
  }
329
329
  handlePairRecordReady(t) {
330
330
  this.log("Pair record received", t.udid), this.pairRecordWaiter?.resolve(t), this.pairRecordWaiter = void 0;
331
331
  }
332
- async handleOpenStream(t, r, n) {
332
+ async handleOpenStream(t, n, r) {
333
333
  try {
334
- const a = await J(this.session, n);
335
- this.streams.set(r, a), await this.send({
334
+ const a = await J(this.session, r);
335
+ this.streams.set(n, a), await this.send({
336
336
  type: s.OpenResult,
337
337
  requestId: t,
338
- streamId: r,
338
+ streamId: n,
339
339
  payload: l({ ok: !0 })
340
- }), this.log(`Opened device stream ${r} to port ${n}`), this.pumpDeviceToServer(r, a);
340
+ }), this.log(`Opened device stream ${n} to port ${r}`), this.pumpDeviceToServer(n, a);
341
341
  } catch (a) {
342
342
  this.log(
343
- `Open device stream ${r} failed`,
343
+ `Open device stream ${n} failed`,
344
344
  a instanceof Error ? a.message : String(a)
345
345
  ), await this.send({
346
346
  type: s.OpenResult,
347
347
  requestId: t,
348
- streamId: r,
348
+ streamId: n,
349
349
  payload: l({
350
350
  ok: !1,
351
351
  error: a instanceof Error ? a.message : String(a)
@@ -353,25 +353,25 @@ class Z {
353
353
  });
354
354
  }
355
355
  }
356
- async pumpDeviceToServer(t, r) {
356
+ async pumpDeviceToServer(t, n) {
357
357
  try {
358
358
  for (; ; ) {
359
- const n = await Q(r);
359
+ const r = await Q(n);
360
360
  if (this.closed) return;
361
361
  await this.send({
362
362
  type: s.StreamData,
363
363
  requestId: 0,
364
364
  streamId: t,
365
- payload: n
365
+ payload: r
366
366
  });
367
367
  }
368
- } catch (n) {
369
- this.log(`Device stream ${t} closed`, n instanceof Error ? n.message : String(n)), await this.send({
368
+ } catch (r) {
369
+ this.log(`Device stream ${t} closed`, r instanceof Error ? r.message : String(r)), await this.send({
370
370
  type: s.StreamClose,
371
371
  requestId: 0,
372
372
  streamId: t,
373
373
  payload: l({
374
- reason: n instanceof Error ? n.message : String(n)
374
+ reason: r instanceof Error ? r.message : String(r)
375
375
  })
376
376
  });
377
377
  }
@@ -389,8 +389,8 @@ class Z {
389
389
  function ee(e) {
390
390
  const t = new TextDecoder().decode(e);
391
391
  try {
392
- const r = JSON.parse(t);
393
- return S(r.error ?? t);
392
+ const n = JSON.parse(t);
393
+ return S(n.error ?? t);
394
394
  } catch {
395
395
  return S(t);
396
396
  }
@@ -402,47 +402,47 @@ function te(e) {
402
402
  const t = "install status: ";
403
403
  if (!e.startsWith(t))
404
404
  return e;
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}` : ""}`;
405
+ const n = e.slice(t.length), r = p(n, "Error");
406
+ if (r) {
407
+ const o = p(n, "ErrorDescription");
408
+ return `Install error: ${r}${o ? ` — ${o}` : ""}`;
409
409
  }
410
- const a = p(r, "Status") ?? "Unknown", i = p(r, "PercentComplete");
410
+ const a = p(n, "Status") ?? "Unknown", i = p(n, "PercentComplete");
411
411
  return `Install progress: ${i ? `${i}% ` : ""}${a}`;
412
412
  }
413
413
  function p(e, t) {
414
- const n = new RegExp(
415
- `<key>\\s*${re(
414
+ const r = new RegExp(
415
+ `<key>\\s*${ne(
416
416
  t
417
417
  )}\\s*</key>\\s*<(?:string|integer|real)>([\\s\\S]*?)</(?:string|integer|real)>`
418
418
  ).exec(e);
419
- return n ? ne(n[1].trim()) : void 0;
419
+ return r ? re(r[1].trim()) : void 0;
420
420
  }
421
- function re(e) {
421
+ function ne(e) {
422
422
  return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
423
423
  }
424
- function ne(e) {
424
+ function re(e) {
425
425
  return e.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&amp;/g, "&");
426
426
  }
427
427
  async function ae({ log: e }) {
428
428
  e("Selecting USB device");
429
- const t = await C(), r = ue(t);
429
+ const t = await C(), n = ue(t);
430
430
  return e(
431
431
  "Selected USB device",
432
432
  `${t.manufacturerName ?? ""} ${t.productName ?? ""} ${t.serialNumber ?? ""}`.trim()
433
- ), r;
433
+ ), n;
434
434
  }
435
435
  async function ie({
436
436
  registryApiUrl: e,
437
437
  token: t,
438
- organizationId: r,
439
- log: n,
438
+ organizationId: n,
439
+ log: r,
440
440
  target: a
441
441
  }) {
442
- const i = N(e, t, r);
442
+ const i = N(e, t, n);
443
443
  let o;
444
444
  try {
445
- o = await $(i, a, n);
445
+ o = await $(i, a, r);
446
446
  const c = await o.startPairing();
447
447
  return { relay: o, pairRecord: c, target: a };
448
448
  } catch (c) {
@@ -452,55 +452,55 @@ async function ie({
452
452
  async function oe({
453
453
  registryApiUrl: e,
454
454
  token: t,
455
- organizationId: r,
456
- log: n,
455
+ organizationId: n,
456
+ log: r,
457
457
  target: a,
458
458
  pairRecord: i,
459
459
  installSource: o
460
460
  }) {
461
- const c = N(e, t, r);
461
+ const c = N(e, t, n);
462
462
  let u;
463
463
  try {
464
- return u = await $(c, a, n), await u.startInstall(i, o), u;
464
+ return u = await $(c, a, r), await u.startInstall(i, o), u;
465
465
  } catch (D) {
466
466
  throw u?.close(), D;
467
467
  }
468
468
  }
469
469
  async function se(e, t) {
470
470
  if (e) {
471
- 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)
472
472
  try {
473
473
  await e.device.releaseInterface(e.claimedInterfaceNumber), t?.("Released usbmux interface");
474
- } catch (r) {
475
- t?.("USB interface release failed", y(r));
474
+ } catch (n) {
475
+ t?.("USB interface release failed", w(n));
476
476
  } finally {
477
477
  e.claimedInterfaceNumber = void 0;
478
478
  }
479
479
  if (e.device.opened)
480
480
  try {
481
481
  await e.device.close(), t?.("Closed USB device");
482
- } catch (r) {
483
- t?.("USB device close failed", y(r));
482
+ } catch (n) {
483
+ t?.("USB device close failed", w(n));
484
484
  }
485
485
  }
486
486
  }
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;
487
+ async function $(e, t, n) {
488
+ await ce(t, n);
489
+ const r = new Z(e, t.session, t.hello, n);
490
+ return await r.connect(), r;
491
491
  }
492
492
  async function ce(e, t) {
493
493
  if (!e.session)
494
494
  try {
495
495
  e.candidate = await le(e, t), e.session = await H(e.device, e.candidate), t("Created usbmux session");
496
- } catch (r) {
497
- throw await se(e, t), r;
496
+ } catch (n) {
497
+ throw await se(e, t), n;
498
498
  }
499
499
  }
500
500
  function ue(e) {
501
501
  return {
502
502
  device: e,
503
- candidate: fe(e),
503
+ candidate: de(e),
504
504
  hello: {
505
505
  serialNumber: e.serialNumber,
506
506
  productName: e.productName,
@@ -511,44 +511,47 @@ function ue(e) {
511
511
  };
512
512
  }
513
513
  async function le(e, t) {
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)
518
- for (const i of [1, 2])
514
+ const n = q(e.device);
515
+ if (n.length === 0) throw new Error("No Apple usbmux interface found.");
516
+ let r;
517
+ for (const i of n)
518
+ for (const o of [1, 2])
519
519
  try {
520
520
  return e.device.opened || await e.device.open(), t(
521
521
  "Claiming usbmux interface",
522
- `configuration ${a.configurationValue}, interface ${a.interfaceNumber}, alternate ${a.alternateSetting}, attempt ${i}`
523
- ), 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(
524
524
  "Claimed usbmux interface",
525
- `configuration ${a.configurationValue}, interface ${a.interfaceNumber}`
526
- ), a;
527
- } catch (o) {
528
- n = o, t(
525
+ `configuration ${i.configurationValue}, interface ${i.interfaceNumber}`
526
+ ), i;
527
+ } catch (c) {
528
+ r = c, t(
529
529
  "USB interface claim failed",
530
- `configuration ${a.configurationValue}, interface ${a.interfaceNumber}: ${y(o)}`
531
- ), await de(e), await pe(250);
530
+ `configuration ${i.configurationValue}, interface ${i.interfaceNumber}: ${w(c)}`
531
+ ), await fe(e), await pe(250);
532
532
  }
533
- throw n instanceof Error ? n : 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
+ );
534
537
  }
535
- function fe(e) {
538
+ function de(e) {
536
539
  const t = q(e)[0];
537
540
  if (!t) throw new Error("No Apple usbmux interface found.");
538
541
  return t;
539
542
  }
540
543
  function q(e) {
541
- const t = L(e), r = e.configuration?.configurationValue;
544
+ const t = L(e), n = e.configuration?.configurationValue;
542
545
  return [
543
- ...t.filter((n) => n.configurationValue === r),
544
- ...t.filter((n) => n.configurationValue !== r)
546
+ ...t.filter((r) => r.configurationValue === n),
547
+ ...t.filter((r) => r.configurationValue !== n)
545
548
  ];
546
549
  }
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();
550
+ function N(e, t, n) {
551
+ const r = new URL(e);
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();
550
553
  }
551
- async function de(e) {
554
+ async function fe(e) {
552
555
  if (e.claimedInterfaceNumber !== void 0) {
553
556
  try {
554
557
  await e.device.releaseInterface(e.claimedInterfaceNumber);