@limrun/ui 0.13.8 → 0.14.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/app-store-relay/index.cjs +3 -3
  2. package/dist/app-store-relay/index.d.ts +3 -5
  3. package/dist/app-store-relay/index.js +56 -58
  4. package/dist/app-store-relay/react.cjs +1 -1
  5. package/dist/app-store-relay/react.d.ts +2 -2
  6. package/dist/app-store-relay/react.js +35 -34
  7. package/dist/client-BtC4n_qf.js +1 -0
  8. package/dist/client-CBX-hLnL.mjs +189 -0
  9. package/dist/core/device-install/apple/client.d.ts +5 -4
  10. package/dist/core/device-install/apple/relay.d.ts +24 -13
  11. package/dist/core/device-install/operations/limbuild-client.d.ts +2 -1
  12. package/dist/core/device-install/operations/operations.d.ts +19 -4
  13. package/dist/core/device-install/operations/relay-client.d.ts +2 -1
  14. package/dist/device-build/index.cjs +1 -1
  15. package/dist/device-build/index.js +1 -1
  16. package/dist/device-build/react.cjs +1 -1
  17. package/dist/device-build/react.d.ts +1 -0
  18. package/dist/device-build/react.js +34 -33
  19. package/dist/device-install/index.cjs +1 -1
  20. package/dist/device-install/index.d.ts +1 -1
  21. package/dist/device-install/index.js +121 -119
  22. package/dist/device-install/react.cjs +1 -1
  23. package/dist/device-install/react.d.ts +4 -3
  24. package/dist/device-install/react.js +58 -54
  25. package/dist/limbuild-client-BagK_FWE.mjs +83 -0
  26. package/dist/limbuild-client-CVDwq54z.js +1 -0
  27. package/package.json +1 -1
  28. package/src/app-store-relay/index.test.ts +19 -29
  29. package/src/app-store-relay/index.ts +6 -9
  30. package/src/app-store-relay/react.ts +5 -4
  31. package/src/core/device-install/apple/client.ts +22 -33
  32. package/src/core/device-install/apple/relay.ts +108 -148
  33. package/src/core/device-install/operations/limbuild-client.ts +3 -0
  34. package/src/core/device-install/operations/operations.ts +21 -9
  35. package/src/core/device-install/operations/relay-client.ts +3 -2
  36. package/src/device-build/react.ts +2 -0
  37. package/src/device-install/README.md +5 -5
  38. package/src/device-install/demo/demo.tsx +26 -28
  39. package/src/device-install/index.ts +1 -0
  40. package/src/device-install/react.ts +12 -6
  41. package/dist/client-ASLtHFLh.js +0 -1
  42. package/dist/client-CGdh8yoJ.mjs +0 -234
  43. package/dist/limbuild-client-CgEncrgx.js +0 -1
  44. package/dist/limbuild-client-D7U7w342.mjs +0 -81
@@ -1,5 +1,5 @@
1
- import { j as ge, n as be, k as Ue } from "../browser-storage-Cx9eW-bm.mjs";
2
- const v = 1, u = 16, s = {
1
+ import { j as be, n as Ue, k as Se } from "../browser-storage-Cx9eW-bm.mjs";
2
+ const v = 1, f = 16, s = {
3
3
  DeviceHello: 1,
4
4
  OpenStream: 2,
5
5
  OpenResult: 3,
@@ -13,40 +13,40 @@ const v = 1, u = 16, s = {
13
13
  StartInstall: 11,
14
14
  PairRecordReady: 12
15
15
  };
16
- function D(e) {
17
- const t = new Uint8Array(u + 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, u), t;
19
- }
20
16
  function V(e) {
21
- if (e.byteLength < u)
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;
19
+ }
20
+ function A(e) {
21
+ if (e.byteLength < f)
22
22
  throw new Error(`Relay frame too short: ${e.byteLength}`);
23
23
  const t = new DataView(e.buffer, e.byteOffset, e.byteLength), n = t.getUint8(0);
24
24
  if (n !== v)
25
25
  throw new Error(`Unsupported relay protocol version ${n}`);
26
26
  const r = t.getUint32(12);
27
- if (e.byteLength !== u + r)
27
+ if (e.byteLength !== f + r)
28
28
  throw new Error(
29
- `Relay frame length mismatch: got ${e.byteLength}, expected ${u + r}`
29
+ `Relay frame length mismatch: got ${e.byteLength}, expected ${f + r}`
30
30
  );
31
31
  return {
32
32
  type: t.getUint8(1),
33
33
  requestId: t.getUint32(4),
34
34
  streamId: t.getUint32(8),
35
- payload: e.slice(u)
35
+ payload: e.slice(f)
36
36
  };
37
37
  }
38
- function c(e) {
38
+ function l(e) {
39
39
  return new TextEncoder().encode(JSON.stringify(e));
40
40
  }
41
41
  function h(e) {
42
42
  return JSON.parse(new TextDecoder().decode(e));
43
43
  }
44
- async function A() {
44
+ async function C() {
45
45
  if (!navigator.usb)
46
46
  throw new Error("WebUSB is not available in this browser.");
47
47
  return navigator.usb.requestDevice({ filters: [{ vendorId: 1452 }] });
48
48
  }
49
- function C(e) {
49
+ function L(e) {
50
50
  const t = [], n = e.configuration?.configurationValue, r = e.configurations.find(
51
51
  (a) => a.configurationValue === n
52
52
  );
@@ -67,10 +67,10 @@ function U(e) {
67
67
  });
68
68
  return t;
69
69
  }
70
- async function L(e, t) {
70
+ async function T(e, t) {
71
71
  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
72
  }
73
- function T(e) {
73
+ function W(e) {
74
74
  const t = e.endpoints.find(
75
75
  (r) => r.direction === "out" && r.type === "bulk"
76
76
  ), n = e.endpoints.find(
@@ -86,32 +86,32 @@ async function R(e, t, n) {
86
86
  throw new Error(`USB transferOut failed: ${r.status}`);
87
87
  n.byteLength % t.packetSize === 0 && await e.transferOut(t.endpointNumber, new Uint8Array());
88
88
  }
89
- async function W(e, t, n = 16384) {
89
+ async function B(e, t, n = 16384) {
90
90
  const r = await e.transferIn(t.endpointNumber, n);
91
91
  if (r.status !== "ok" || !r.data)
92
92
  throw new Error(`USB transferIn failed: ${r.status}`);
93
93
  return new Uint8Array(r.data.buffer, r.data.byteOffset, r.data.byteLength);
94
94
  }
95
- const E = 0, B = 2, k = 6, F = 4277009102, y = 2, _ = 4, l = 16, M = 49152;
96
- async function j(e, t) {
97
- const { inEndpoint: n, outEndpoint: r } = T(t), a = new Uint8Array(12), i = new DataView(a.buffer);
95
+ const E = 0, F = 2, k = 6, _ = 4277009102, y = 2, M = 4, d = 16, j = 49152;
96
+ async function H(e, t) {
97
+ const { inEndpoint: n, outEndpoint: r } = W(t), a = new Uint8Array(12), i = new DataView(a.buffer);
98
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), f = new DataView(o.payload.buffer, o.payload.byteOffset).getUint32(0), w = {
99
+ const o = await P(e, n, 1), c = new DataView(o.payload.buffer, o.payload.byteOffset).getUint32(0), u = {
100
100
  device: e,
101
101
  candidate: t,
102
102
  inEndpoint: n,
103
103
  outEndpoint: r,
104
- muxVersion: f,
104
+ muxVersion: c,
105
105
  txSeq: 0,
106
106
  rxSeq: 65535,
107
- nextSport: M,
107
+ nextSport: j,
108
108
  streams: /* @__PURE__ */ new Map(),
109
109
  writeChain: Promise.resolve(),
110
110
  closed: !1
111
111
  };
112
- return f >= 2 && await x(w, B, new Uint8Array([7])), Q(w), w;
112
+ return c >= 2 && await x(u, F, new Uint8Array([7])), Y(u), u;
113
113
  }
114
- async function H(e, t) {
114
+ async function J(e, t) {
115
115
  if (e.closed)
116
116
  throw new Error("usbmux session is closed.");
117
117
  let n, r;
@@ -129,14 +129,14 @@ async function H(e, t) {
129
129
  resolveOpened: n,
130
130
  rejectOpened: r
131
131
  };
132
- return e.streams.set(m(t, a.sport), a), await p(a, y, new Uint8Array()), await a.opened, a;
132
+ return e.streams.set(m(t, a.sport), a), await w(a, y, new Uint8Array()), await a.opened, a;
133
133
  }
134
- async function J(e, t) {
134
+ async function G(e, t) {
135
135
  if (e.session.closed)
136
136
  throw new Error("usbmux session is closed.");
137
- await p(e, l, t), e.seq += t.byteLength;
137
+ await w(e, d, t), e.seq += t.byteLength;
138
138
  }
139
- async function G(e) {
139
+ async function Q(e) {
140
140
  if (e.queue.length > 0)
141
141
  return e.queue.shift();
142
142
  if (e.error)
@@ -152,7 +152,7 @@ function I(e) {
152
152
  t.waiters.shift()(new Uint8Array());
153
153
  e.streams.clear();
154
154
  }
155
- async function p(e, t, n) {
155
+ async function w(e, t, n) {
156
156
  const r = new Uint8Array(20 + n.byteLength), a = new DataView(r.buffer);
157
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
158
  }
@@ -161,11 +161,11 @@ async function x(e, t, n) {
161
161
  throw new Error("usbmux session is closed.");
162
162
  return e.writeChain = e.writeChain.then(async () => {
163
163
  if (e.closed) return;
164
- const r = e.muxVersion >= 2 ? Y(t, n, e.txSeq++, e.rxSeq) : O(t, n);
164
+ const r = e.muxVersion >= 2 ? z(t, n, e.txSeq++, e.rxSeq) : O(t, n);
165
165
  await R(e.device, e.outEndpoint, r);
166
166
  }), e.writeChain;
167
167
  }
168
- async function Q(e) {
168
+ async function Y(e) {
169
169
  try {
170
170
  for (; ; ) {
171
171
  if (e.closed) return;
@@ -173,19 +173,19 @@ async function Q(e) {
173
173
  if (e.closed) return;
174
174
  if (t.rxSeq !== void 0 && (e.rxSeq = t.rxSeq), t.protocol !== k)
175
175
  continue;
176
- const n = K(t.payload), r = e.streams.get(m(n.sport, n.dport));
176
+ const n = X(t.payload), r = e.streams.get(m(n.sport, n.dport));
177
177
  if (r) {
178
- if (n.flags & _) {
178
+ if (n.flags & M) {
179
179
  for (r.error = new Error(`Device reset stream ${r.dport}`), r.rejectOpened(r.error); r.waiters.length > 0; )
180
180
  r.waiters.shift()(new Uint8Array());
181
181
  e.streams.delete(m(r.dport, r.sport));
182
182
  continue;
183
183
  }
184
- if ((n.flags & (y | l)) === (y | l)) {
185
- r.seq += 1, r.ack = n.seq + 1, await p(r, l, new Uint8Array()), r.resolveOpened();
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();
186
186
  continue;
187
187
  }
188
- n.payload.byteLength !== 0 && (r.ack = n.seq + n.payload.byteLength, await p(r, l, new Uint8Array()), r.waiters.length > 0 ? r.waiters.shift()(n.payload) : r.queue.push(n.payload));
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
189
  }
190
190
  }
191
191
  } catch {
@@ -194,7 +194,7 @@ async function Q(e) {
194
194
  }
195
195
  async function P(e, t, n) {
196
196
  for (; ; ) {
197
- const r = await W(e, t), a = z(r, n);
197
+ const r = await B(e, t), a = K(r, n);
198
198
  if (!(n === 1 && a.protocol !== E))
199
199
  return a;
200
200
  }
@@ -203,11 +203,11 @@ function O(e, t) {
203
203
  const n = new Uint8Array(8 + t.byteLength), r = new DataView(n.buffer);
204
204
  return r.setUint32(0, e), r.setUint32(4, n.byteLength), n.set(t, 8), n;
205
205
  }
206
- function Y(e, t, n, r) {
206
+ function z(e, t, n, r) {
207
207
  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, F), i.setUint16(12, n), i.setUint16(14, r), a.set(t, 16), a;
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
209
  }
210
- function z(e, t) {
210
+ function K(e, t) {
211
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
212
  return {
213
213
  protocol: r,
@@ -216,7 +216,7 @@ function z(e, t) {
216
216
  payload: e.slice(i, a)
217
217
  };
218
218
  }
219
- function K(e) {
219
+ function X(e) {
220
220
  const t = new DataView(e.buffer, e.byteOffset, e.byteLength), n = (t.getUint8(12) >> 4) * 4;
221
221
  return {
222
222
  sport: t.getUint16(0),
@@ -230,7 +230,7 @@ function K(e) {
230
230
  function m(e, t) {
231
231
  return `${e}:${t}`;
232
232
  }
233
- class X {
233
+ class Z {
234
234
  constructor(t, n, r, a) {
235
235
  this.webSocketUrl = t, this.session = n, this.deviceHello = r, this.log = a;
236
236
  }
@@ -254,7 +254,7 @@ class X {
254
254
  type: s.DeviceHello,
255
255
  requestId: 0,
256
256
  streamId: 0,
257
- payload: c(this.deviceHello)
257
+ payload: l(this.deviceHello)
258
258
  }), this.log("Connected WebSocket relay");
259
259
  }
260
260
  async startPairing() {
@@ -265,22 +265,22 @@ class X {
265
265
  type: s.StartPairing,
266
266
  requestId: 0,
267
267
  streamId: 0,
268
- payload: c({})
268
+ payload: l({})
269
269
  }), this.log("Pairing requested"), t;
270
270
  }
271
- async startInstall(t) {
271
+ async startInstall(t, n) {
272
272
  await this.send({
273
273
  type: s.StartInstall,
274
274
  requestId: 0,
275
275
  streamId: 0,
276
- payload: c(t)
276
+ payload: l({ ...t, ...n })
277
277
  }), this.log("Installation requested");
278
278
  }
279
279
  close() {
280
280
  this.closed = !0, this.socket?.close();
281
281
  }
282
282
  enqueueFrame(t) {
283
- this.frameQueue = this.frameQueue.then(() => this.handleFrame(V(t))).catch((n) => {
283
+ this.frameQueue = this.frameQueue.then(() => this.handleFrame(A(t))).catch((n) => {
284
284
  this.log("Relay frame handling failed", n instanceof Error ? n.message : String(n));
285
285
  });
286
286
  }
@@ -296,14 +296,14 @@ class X {
296
296
  case s.StreamData: {
297
297
  const n = this.streams.get(t.streamId);
298
298
  if (!n) throw new Error(`Unknown stream ${t.streamId}`);
299
- await J(n, t.payload);
299
+ await G(n, t.payload);
300
300
  break;
301
301
  }
302
302
  case s.StreamClose:
303
303
  this.streams.delete(t.streamId);
304
304
  break;
305
305
  case s.InstallProgress:
306
- this.log(ee(h(t.payload).message));
306
+ this.log(te(h(t.payload).message));
307
307
  break;
308
308
  case s.Error:
309
309
  this.handleError(t.payload);
@@ -322,7 +322,7 @@ class X {
322
322
  }
323
323
  }
324
324
  handleError(t) {
325
- const n = Z(t);
325
+ const n = ee(t);
326
326
  this.log("Server error", n), this.pairRecordWaiter && (this.pairRecordWaiter.reject(new Error(n)), this.pairRecordWaiter = void 0);
327
327
  }
328
328
  handlePairRecordReady(t) {
@@ -330,12 +330,12 @@ class X {
330
330
  }
331
331
  async handleOpenStream(t, n, r) {
332
332
  try {
333
- const a = await H(this.session, r);
333
+ const a = await J(this.session, r);
334
334
  this.streams.set(n, a), await this.send({
335
335
  type: s.OpenResult,
336
336
  requestId: t,
337
337
  streamId: n,
338
- payload: c({ ok: !0 })
338
+ payload: l({ ok: !0 })
339
339
  }), this.log(`Opened device stream ${n} to port ${r}`), this.pumpDeviceToServer(n, a);
340
340
  } catch (a) {
341
341
  this.log(
@@ -345,7 +345,7 @@ class X {
345
345
  type: s.OpenResult,
346
346
  requestId: t,
347
347
  streamId: n,
348
- payload: c({
348
+ payload: l({
349
349
  ok: !1,
350
350
  error: a instanceof Error ? a.message : String(a)
351
351
  })
@@ -355,7 +355,7 @@ class X {
355
355
  async pumpDeviceToServer(t, n) {
356
356
  try {
357
357
  for (; ; ) {
358
- const r = await G(n);
358
+ const r = await Q(n);
359
359
  if (this.closed) return;
360
360
  await this.send({
361
361
  type: s.StreamData,
@@ -369,7 +369,7 @@ class X {
369
369
  type: s.StreamClose,
370
370
  requestId: 0,
371
371
  streamId: t,
372
- payload: c({
372
+ payload: l({
373
373
  reason: r instanceof Error ? r.message : String(r)
374
374
  })
375
375
  });
@@ -381,11 +381,11 @@ class X {
381
381
  this.closed = !0;
382
382
  return;
383
383
  }
384
- this.socket.send(D(t));
384
+ this.socket.send(V(t));
385
385
  }
386
386
  }
387
387
  }
388
- function Z(e) {
388
+ function ee(e) {
389
389
  const t = new TextDecoder().decode(e);
390
390
  try {
391
391
  const n = JSON.parse(t);
@@ -397,67 +397,69 @@ function Z(e) {
397
397
  function S(e) {
398
398
  return e.replace(/libimobiledevice/g, "").trim();
399
399
  }
400
- function ee(e) {
400
+ function te(e) {
401
401
  const t = "install status: ";
402
402
  if (!e.startsWith(t))
403
403
  return e;
404
- const n = e.slice(t.length), r = d(n, "Error");
404
+ const n = e.slice(t.length), r = p(n, "Error");
405
405
  if (r) {
406
- const o = d(n, "ErrorDescription");
406
+ const o = p(n, "ErrorDescription");
407
407
  return `Install error: ${r}${o ? ` — ${o}` : ""}`;
408
408
  }
409
- const a = d(n, "Status") ?? "Unknown", i = d(n, "PercentComplete");
409
+ const a = p(n, "Status") ?? "Unknown", i = p(n, "PercentComplete");
410
410
  return `Install progress: ${i ? `${i}% ` : ""}${a}`;
411
411
  }
412
- function d(e, t) {
412
+ function p(e, t) {
413
413
  const r = new RegExp(
414
- `<key>\\s*${te(
414
+ `<key>\\s*${ne(
415
415
  t
416
416
  )}\\s*</key>\\s*<(?:string|integer|real)>([\\s\\S]*?)</(?:string|integer|real)>`
417
417
  ).exec(e);
418
- return r ? ne(r[1].trim()) : void 0;
418
+ return r ? re(r[1].trim()) : void 0;
419
419
  }
420
- function te(e) {
420
+ function ne(e) {
421
421
  return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
422
422
  }
423
- function ne(e) {
423
+ function re(e) {
424
424
  return e.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&amp;/g, "&");
425
425
  }
426
- async function re({ log: e }) {
426
+ async function ae({ log: e }) {
427
427
  e("Selecting USB device");
428
- const t = await A(), n = ce(t);
428
+ const t = await C(), n = ue(t);
429
429
  return e(
430
430
  "Selected USB device",
431
431
  `${t.manufacturerName ?? ""} ${t.productName ?? ""} ${t.serialNumber ?? ""}`.trim()
432
432
  ), n;
433
433
  }
434
- async function ae({ limbuildApiUrl: e, token: t, log: n, target: r }) {
435
- const a = N(e, t);
436
- let i;
434
+ async function ie({ registryApiUrl: e, token: t, organizationId: n, log: r, target: a }) {
435
+ const i = N(e, t, n);
436
+ let o;
437
437
  try {
438
- i = await $(a, r, n);
439
- const o = await i.startPairing();
440
- return { relay: i, pairRecord: o, target: r };
441
- } catch (o) {
442
- throw i?.close(), o;
438
+ o = await $(i, a, r);
439
+ const c = await o.startPairing();
440
+ return { relay: o, pairRecord: c, target: a };
441
+ } catch (c) {
442
+ throw o?.close(), c;
443
443
  }
444
444
  }
445
- async function ie({
446
- limbuildApiUrl: e,
445
+ async function oe({
446
+ registryApiUrl: e,
447
447
  token: t,
448
- log: n,
449
- target: r,
450
- pairRecord: a
448
+ organizationId: n,
449
+ log: r,
450
+ target: a,
451
+ pairRecord: i,
452
+ installSource: o
451
453
  }) {
452
- const i = N(e, t);
453
- let o;
454
+ const c = N(e, t, n);
455
+ let u;
454
456
  try {
455
- return o = await $(i, r, n), await o.startInstall(a), o;
456
- } catch (f) {
457
- throw o?.close(), f;
457
+ return u = await $(c, a, r), await u.startInstall(i, o), u;
458
+ } catch (D) {
459
+ throw u?.close(), D;
458
460
  }
459
461
  }
460
- async function oe(e, t) {
462
+ async function se(e, t) {
461
463
  if (e) {
462
464
  if (e.session && (I(e.session), e.session = void 0), e.claimedInterfaceNumber !== void 0)
463
465
  try {
@@ -476,22 +478,22 @@ async function oe(e, t) {
476
478
  }
477
479
  }
478
480
  async function $(e, t, n) {
479
- await se(t, n);
480
- const r = new X(e, t.session, t.hello, n);
481
+ await ce(t, n);
482
+ const r = new Z(e, t.session, t.hello, n);
481
483
  return await r.connect(), r;
482
484
  }
483
- async function se(e, t) {
485
+ async function ce(e, t) {
484
486
  if (!e.session)
485
487
  try {
486
- e.candidate = await ue(e, t), e.session = await j(e.device, e.candidate), t("Created usbmux session");
488
+ e.candidate = await le(e, t), e.session = await H(e.device, e.candidate), t("Created usbmux session");
487
489
  } catch (n) {
488
- throw await oe(e, t), n;
490
+ throw await se(e, t), n;
489
491
  }
490
492
  }
491
- function ce(e) {
493
+ function ue(e) {
492
494
  return {
493
495
  device: e,
494
- candidate: le(e),
496
+ candidate: fe(e),
495
497
  hello: {
496
498
  serialNumber: e.serialNumber,
497
499
  productName: e.productName,
@@ -501,7 +503,7 @@ function ce(e) {
501
503
  }
502
504
  };
503
505
  }
504
- async function ue(e, t) {
506
+ async function le(e, t) {
505
507
  const n = q(e.device);
506
508
  if (n.length === 0) throw new Error("No Apple usbmux interface found.");
507
509
  let r;
@@ -511,7 +513,7 @@ async function ue(e, t) {
511
513
  return e.device.opened || await e.device.open(), t(
512
514
  "Claiming usbmux interface",
513
515
  `configuration ${a.configurationValue}, interface ${a.interfaceNumber}, alternate ${a.alternateSetting}, attempt ${i}`
514
- ), await L(e.device, a), e.claimedInterfaceNumber = a.interfaceNumber, t(
516
+ ), await T(e.device, a), e.claimedInterfaceNumber = a.interfaceNumber, t(
515
517
  "Claimed usbmux interface",
516
518
  `configuration ${a.configurationValue}, interface ${a.interfaceNumber}`
517
519
  ), a;
@@ -519,30 +521,30 @@ async function ue(e, t) {
519
521
  r = o, t(
520
522
  "USB interface claim failed",
521
523
  `configuration ${a.configurationValue}, interface ${a.interfaceNumber}: ${g(o)}`
522
- ), await fe(e), await de(250);
524
+ ), await de(e), await pe(250);
523
525
  }
524
526
  throw r instanceof Error ? r : new Error("Unable to claim any Apple usbmux interface.");
525
527
  }
526
- function le(e) {
528
+ function fe(e) {
527
529
  const t = q(e)[0];
528
530
  if (!t) throw new Error("No Apple usbmux interface found.");
529
531
  return t;
530
532
  }
531
533
  function q(e) {
532
- const t = C(e), n = e.configuration?.configurationValue;
534
+ const t = L(e), n = e.configuration?.configurationValue;
533
535
  return [
534
536
  ...t.filter((r) => r.configurationValue === n),
535
537
  ...t.filter((r) => r.configurationValue !== n)
536
538
  ];
537
539
  }
538
- function N(e, t) {
539
- const n = new URL(e);
540
- return n.protocol = n.protocol === "https:" ? "wss:" : "ws:", n.pathname = `${n.pathname.replace(/\/$/, "")}/device/ws`, t && n.searchParams.set("token", t), n.toString();
540
+ function N(e, t, n) {
541
+ const r = new URL(e);
542
+ 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();
541
543
  }
542
544
  function g(e) {
543
545
  return e instanceof Error ? e.message : String(e);
544
546
  }
545
- async function fe(e) {
547
+ async function de(e) {
546
548
  if (e.claimedInterfaceNumber !== void 0) {
547
549
  try {
548
550
  await e.device.releaseInterface(e.claimedInterfaceNumber);
@@ -556,30 +558,30 @@ async function fe(e) {
556
558
  } catch {
557
559
  }
558
560
  }
559
- function de(e) {
561
+ function pe(e) {
560
562
  return new Promise((t) => setTimeout(t, e));
561
563
  }
562
- async function pe(e = {}) {
563
- return re({ log: e.log ?? b });
564
- }
565
- async function we(e) {
566
- return ae({ ...e, log: e.log ?? b });
564
+ async function we(e = {}) {
565
+ return ae({ log: e.log ?? b });
567
566
  }
568
567
  async function he(e) {
569
568
  return ie({ ...e, log: e.log ?? b });
570
569
  }
570
+ async function ye(e) {
571
+ return oe({ ...e, log: e.log ?? b });
572
+ }
571
573
  function b() {
572
574
  }
573
575
  export {
574
- X as RelayClient,
575
- oe as closeDeviceRelayTarget,
576
+ Z as RelayClient,
577
+ se as closeDeviceRelayTarget,
576
578
  N as deviceRelayWebSocketUrl,
577
- ge as getPairRecord,
578
- be as normalizeUDID,
579
- we as pairDevice,
580
- Ue as putPairRecord,
581
- pe as requestUSBAccess,
582
- he as startDeviceInstall,
583
- ie as startDeviceInstallRelay,
584
- ae as startDevicePairingRelay
579
+ be as getPairRecord,
580
+ Ue as normalizeUDID,
581
+ he as pairDevice,
582
+ Se as putPairRecord,
583
+ we as requestUSBAccess,
584
+ ye as startDeviceInstall,
585
+ oe as startDeviceInstallRelay,
586
+ ie as startDevicePairingRelay
585
587
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),o=require("./index.cjs"),S=require("../browser-storage-jJaIht4K.js");function B({apiUrl:c,token:d,log:w=C}){const[e,h]=r.useState(),[l,y]=r.useState(),[g,u]=r.useState(),[p,s]=r.useState(),[D,v]=r.useState(!1),f=r.useRef(void 0),b=r.useRef(void 0),t=r.useRef(w);t.current=w;const i=r.useCallback(async()=>{f.current?.close(),f.current=void 0,await o.closeDeviceRelayTarget(b.current,t.current)},[]);r.useEffect(()=>{b.current=e},[e]),r.useEffect(()=>()=>{i()},[i]);const m=r.useCallback(async()=>{u("usb"),s(void 0),v(!1);let a;try{await i(),a=await o.requestUSBAccess({log:t.current});const n=await S.getPairRecord(a.hello.serialNumber);return h(a),y(n),t.current(n?"Pair record found":"No pair record found",a.hello.serialNumber),a}catch(n){await o.closeDeviceRelayTarget(a,t.current),h(void 0),y(void 0),s(R(n));return}finally{u(void 0)}},[i]),P=r.useCallback(async()=>{if(!c||!e)throw new Error("Select a USB device before pairing.");u("pair"),s(void 0),v(!1);try{await i();const a=await o.pairDevice({limbuildApiUrl:c,token:d,log:t.current,target:e}),n=await S.putPairRecord(a.pairRecord,{productName:e.hello.productName});return a.relay.close(),await o.closeDeviceRelayTarget(e,t.current),y(n),v(!1),t.current("Device paired","The pair record was stored locally in this browser."),n}catch(a){await o.closeDeviceRelayTarget(e,t.current),v(!0),s(R(a));return}finally{u(void 0)}},[c,i,e,d]),q=r.useCallback(async()=>{if(!c||!e||!l)throw new Error("Select and pair a USB device before starting installation.");u("install"),s(void 0);try{return await i(),f.current=await o.startDeviceInstall({limbuildApiUrl:c,token:d,log:t.current,target:e,pairRecord:l}),t.current("Device install started","Installation will continue through the connected iPhone."),f.current}catch(a){await o.closeDeviceRelayTarget(e,t.current),s(R(a));return}finally{u(void 0)}},[c,i,e,l,d]),A=r.useCallback(()=>{i(),t.current("Device relay stopped")},[i]);return{device:e,pairRecord:l,busyAction:g,error:p,pairConfirmationRequired:D,hasPairRecord:!!l,canPair:!!c&&!g&&!!e,canInstall:!!c&&!g&&!!e&&!!l,requestUSBAccess:m,pairBrowser:P,startInstallation:q,stopRelay:A,clearError:()=>s(void 0)}}function C(){}function R(c){return c instanceof Error?c.message:String(c)}exports.useDeviceInstallRelay=B;
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,8 +1,9 @@
1
- import { DeviceInstallLog, DeviceRelayTarget, RelayClient, StoredPairRecord } from './index';
1
+ import { DeviceInstallLog, DeviceRelayTarget, InstallSource, RelayClient, StoredPairRecord } from './index';
2
2
  export type DeviceInstallRelayBusyAction = 'usb' | 'pair' | 'install';
3
3
  export type UseDeviceInstallRelayOptions = {
4
4
  apiUrl?: string;
5
5
  token?: string;
6
+ organizationId?: string;
6
7
  log?: DeviceInstallLog;
7
8
  };
8
9
  export type UseDeviceInstallRelayResult = {
@@ -16,8 +17,8 @@ export type UseDeviceInstallRelayResult = {
16
17
  canInstall: boolean;
17
18
  requestUSBAccess: () => Promise<DeviceRelayTarget | undefined>;
18
19
  pairBrowser: () => Promise<StoredPairRecord | undefined>;
19
- startInstallation: () => Promise<RelayClient | undefined>;
20
+ startInstallation: (installSource: InstallSource) => Promise<RelayClient | undefined>;
20
21
  stopRelay: () => void;
21
22
  clearError: () => void;
22
23
  };
23
- export declare function useDeviceInstallRelay({ apiUrl, token, log, }: UseDeviceInstallRelayOptions): UseDeviceInstallRelayResult;
24
+ export declare function useDeviceInstallRelay({ apiUrl, token, organizationId, log, }: UseDeviceInstallRelayOptions): UseDeviceInstallRelayResult;