@limrun/ui 0.9.0-rc.8 → 0.13.3-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 (67) hide show
  1. package/README.md +25 -8
  2. package/dist/app-store-relay/index.cjs +9 -0
  3. package/dist/app-store-relay/index.d.ts +102 -0
  4. package/dist/app-store-relay/index.js +430 -0
  5. package/dist/app-store-relay/react.cjs +1 -0
  6. package/dist/app-store-relay/react.d.ts +15 -0
  7. package/dist/app-store-relay/react.js +65 -0
  8. package/dist/browser-storage-BJ__DGJ6.mjs +202 -0
  9. package/dist/browser-storage-C1jQLXat.js +1 -0
  10. package/dist/client-Bk1N3XIF.mjs +228 -0
  11. package/dist/client-CnbCWvCs.js +1 -0
  12. package/dist/components/device-install/index.d.ts +1 -2
  13. package/dist/core/device-install/apple/provisioning.d.ts +55 -4
  14. package/dist/core/device-install/operations/limbuild-client.d.ts +15 -1
  15. package/dist/core/device-install/storage/browser-storage.d.ts +9 -5
  16. package/dist/core/device-install/types.d.ts +4 -1
  17. package/dist/device-build/index.cjs +1 -0
  18. package/dist/device-build/index.d.ts +4 -0
  19. package/dist/device-build/index.js +84 -0
  20. package/dist/device-build/react.cjs +1 -0
  21. package/dist/device-build/react.d.ts +20 -0
  22. package/dist/device-build/react.js +66 -0
  23. package/dist/device-build/signing.d.ts +20 -0
  24. package/dist/device-install/index.cjs +1 -1
  25. package/dist/device-install/index.d.ts +18 -3
  26. package/dist/device-install/index.js +570 -76
  27. package/dist/device-install/react.cjs +1 -1
  28. package/dist/device-install/react.d.ts +23 -1
  29. package/dist/device-install/react.js +93 -2
  30. package/dist/hooks/index.d.ts +1 -1
  31. package/dist/index-BXg7HdIs.mjs +11547 -0
  32. package/dist/index-CMeQfhYy.js +22 -0
  33. package/dist/index.cjs +1 -1
  34. package/dist/index.d.ts +0 -2
  35. package/dist/index.js +502 -495
  36. package/dist/limbuild-client-CFJhYsRx.mjs +79 -0
  37. package/dist/limbuild-client-C_CMNLYV.js +1 -0
  38. package/dist/provisioning-CdseoMJQ.mjs +239 -0
  39. package/dist/provisioning-D2ZZQeyX.js +1 -0
  40. package/package.json +21 -1
  41. package/src/app-store-relay/index.test.ts +74 -0
  42. package/src/app-store-relay/index.ts +447 -0
  43. package/src/app-store-relay/react.ts +125 -0
  44. package/src/components/device-install/index.ts +1 -2
  45. package/src/core/device-install/apple/provisioning.test.ts +84 -0
  46. package/src/core/device-install/apple/provisioning.ts +91 -7
  47. package/src/core/device-install/operations/limbuild-client.ts +32 -2
  48. package/src/core/device-install/storage/browser-storage.ts +29 -14
  49. package/src/core/device-install/types.ts +5 -1
  50. package/src/device-build/index.ts +42 -0
  51. package/src/device-build/react.ts +128 -0
  52. package/src/device-build/signing.ts +94 -0
  53. package/src/device-install/index.ts +49 -3
  54. package/src/device-install/react.ts +180 -1
  55. package/src/hooks/index.ts +1 -1
  56. package/src/index.ts +1 -4
  57. package/vite.config.ts +4 -0
  58. package/dist/components/device-install/device-install-dialog.d.ts +0 -5
  59. package/dist/device-install-dialog-DGn2ZdBB.js +0 -2
  60. package/dist/device-install-dialog-DgWsZF6o.mjs +0 -443
  61. package/dist/device-install-dialog.css +0 -1
  62. package/dist/hooks/use-device-install.d.ts +0 -73
  63. package/dist/use-device-install-ByUSmeYz.js +0 -31
  64. package/dist/use-device-install-Y42p84we.mjs +0 -13624
  65. package/src/components/device-install/device-install-dialog.css +0 -325
  66. package/src/components/device-install/device-install-dialog.tsx +0 -495
  67. package/src/hooks/use-device-install.ts +0 -1219
@@ -1,78 +1,572 @@
1
- import { A as a, O as t, N as i, R as n, P as r, a0 as o, L as l, Z as p, q as c, d, j as g, V as u, S as R, U as D, v as S, M as f, i as m, k as A, Q as v, T as P, e as y, D as C, F as I, f as q, b as B, c as x, a as T, ac as b, $ as h, g as w, a1 as E, a9 as L, aa as F, a6 as U, m as O, a8 as _, l as W, a5 as Y, a4 as k, W as z, af as G, ag as J, ah as M, ad as H, ae as K, C as N, E as V, x as Z, w as j, B as Q, p as X, a7 as $, ab as ee, Y as se, r as ae, _ as te, I as ie, o as ne, X as re, s as oe, K as le, J as pe, G as ce, n as de, h as ge, t as ue, a3 as Re, a2 as De, z as Se, y as fe, u as me, H as Ae } from "../use-device-install-Y42p84we.mjs";
2
- import { D as Pe, D as ye } from "../device-install-dialog-DgWsZF6o.mjs";
1
+ import { j as ye, n as me, k as ge } from "../browser-storage-BJ__DGJ6.mjs";
2
+ const S = 1, u = 16, s = {
3
+ DeviceHello: 1,
4
+ OpenStream: 2,
5
+ OpenResult: 3,
6
+ StreamData: 4,
7
+ StreamClose: 5,
8
+ InstallProgress: 6,
9
+ Error: 7,
10
+ Ping: 8,
11
+ Pong: 9,
12
+ StartPairing: 10,
13
+ StartInstall: 11,
14
+ PairRecordReady: 12
15
+ };
16
+ function D(e) {
17
+ const t = new Uint8Array(u + e.payload.byteLength), n = new DataView(t.buffer);
18
+ return n.setUint8(0, S), 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
+ function A(e) {
21
+ if (e.byteLength < u)
22
+ 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 !== S)
25
+ throw new Error(`Unsupported relay protocol version ${n}`);
26
+ const r = t.getUint32(12);
27
+ if (e.byteLength !== u + r)
28
+ throw new Error(
29
+ `Relay frame length mismatch: got ${e.byteLength}, expected ${u + r}`
30
+ );
31
+ return {
32
+ type: t.getUint8(1),
33
+ requestId: t.getUint32(4),
34
+ streamId: t.getUint32(8),
35
+ payload: e.slice(u)
36
+ };
37
+ }
38
+ function c(e) {
39
+ return new TextEncoder().encode(JSON.stringify(e));
40
+ }
41
+ function w(e) {
42
+ return JSON.parse(new TextDecoder().decode(e));
43
+ }
44
+ async function C() {
45
+ if (!navigator.usb)
46
+ throw new Error("WebUSB is not available in this browser.");
47
+ return navigator.usb.requestDevice({ filters: [{ vendorId: 1452 }] });
48
+ }
49
+ function V(e) {
50
+ const t = [], n = e.configuration?.configurationValue, r = e.configurations.find(
51
+ (a) => a.configurationValue === n
52
+ );
53
+ r && t.push(...b(r));
54
+ for (const a of e.configurations)
55
+ a.configurationValue !== n && t.push(...b(a));
56
+ return t;
57
+ }
58
+ function b(e) {
59
+ 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({
63
+ configurationValue: e.configurationValue,
64
+ interfaceNumber: n.interfaceNumber,
65
+ alternateSetting: r.alternateSetting,
66
+ endpoints: r.endpoints
67
+ });
68
+ return t;
69
+ }
70
+ async function $(e, t) {
71
+ e.opened || await e.open(), (!e.configuration || e.configuration.configurationValue !== t.configurationValue) && await e.selectConfiguration(t.configurationValue), await e.claimInterface(t.interfaceNumber), t.alternateSetting !== 0 && await e.selectAlternateInterface(t.interfaceNumber, t.alternateSetting);
72
+ }
73
+ function L(e) {
74
+ 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"
78
+ );
79
+ if (!t || !n)
80
+ throw new Error("Could not find usbmux bulk endpoints.");
81
+ return { outEndpoint: t, inEndpoint: n };
82
+ }
83
+ async function v(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());
88
+ }
89
+ async function T(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);
94
+ }
95
+ const R = 0, W = 2, k = 6, B = 4277009102, h = 2, F = 4, f = 16, _ = 49152;
96
+ async function M(e, t) {
97
+ const { inEndpoint: n, outEndpoint: r } = L(t), a = new Uint8Array(12), i = new DataView(a.buffer);
98
+ i.setUint32(0, 2), i.setUint32(4, 0), i.setUint32(8, 0), await v(e, r, P(R, a));
99
+ const o = await I(e, n, 1), l = new DataView(o.payload.buffer, o.payload.byteOffset).getUint32(0), p = {
100
+ device: e,
101
+ candidate: t,
102
+ inEndpoint: n,
103
+ outEndpoint: r,
104
+ muxVersion: l,
105
+ txSeq: 0,
106
+ rxSeq: 65535,
107
+ nextSport: _,
108
+ streams: /* @__PURE__ */ new Map(),
109
+ writeChain: Promise.resolve(),
110
+ closed: !1
111
+ };
112
+ return l >= 2 && await x(p, W, new Uint8Array([7])), G(p), p;
113
+ }
114
+ async function j(e, t) {
115
+ if (e.closed)
116
+ throw new Error("usbmux session is closed.");
117
+ let n, r;
118
+ const a = {
119
+ session: e,
120
+ sport: e.nextSport++,
121
+ dport: t,
122
+ seq: 0,
123
+ ack: 0,
124
+ queue: [],
125
+ waiters: [],
126
+ opened: new Promise((i, o) => {
127
+ n = i, r = o;
128
+ }),
129
+ resolveOpened: n,
130
+ rejectOpened: r
131
+ };
132
+ return e.streams.set(y(t, a.sport), a), await d(a, h, new Uint8Array()), await a.opened, a;
133
+ }
134
+ async function H(e, t) {
135
+ if (e.session.closed)
136
+ throw new Error("usbmux session is closed.");
137
+ await d(e, f, t), e.seq += t.byteLength;
138
+ }
139
+ async function J(e) {
140
+ if (e.queue.length > 0)
141
+ return e.queue.shift();
142
+ if (e.error)
143
+ throw e.error;
144
+ return new Promise((t) => {
145
+ e.waiters.push(t);
146
+ });
147
+ }
148
+ function E(e) {
149
+ e.closed = !0;
150
+ for (const t of e.streams.values())
151
+ for (t.error = new Error("usbmux session closed"), t.rejectOpened(t.error); t.waiters.length > 0; )
152
+ t.waiters.shift()(new Uint8Array());
153
+ e.streams.clear();
154
+ }
155
+ async function d(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);
158
+ }
159
+ async function x(e, t, n) {
160
+ if (e.closed)
161
+ throw new Error("usbmux session is closed.");
162
+ return e.writeChain = e.writeChain.then(async () => {
163
+ if (e.closed) return;
164
+ const r = e.muxVersion >= 2 ? Y(t, n, e.txSeq++, e.rxSeq) : P(t, n);
165
+ await v(e.device, e.outEndpoint, r);
166
+ }), e.writeChain;
167
+ }
168
+ async function G(e) {
169
+ try {
170
+ for (; ; ) {
171
+ if (e.closed) return;
172
+ const t = await I(e.device, e.inEndpoint, e.muxVersion);
173
+ if (e.closed) return;
174
+ if (t.rxSeq !== void 0 && (e.rxSeq = t.rxSeq), t.protocol !== k)
175
+ continue;
176
+ const n = Q(t.payload), r = e.streams.get(y(n.sport, n.dport));
177
+ if (r) {
178
+ if (n.flags & F) {
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(y(r.dport, r.sport));
182
+ continue;
183
+ }
184
+ if ((n.flags & (h | f)) === (h | f)) {
185
+ r.seq += 1, r.ack = n.seq + 1, await d(r, f, new Uint8Array()), r.resolveOpened();
186
+ continue;
187
+ }
188
+ n.payload.byteLength !== 0 && (r.ack = n.seq + n.payload.byteLength, await d(r, f, new Uint8Array()), r.waiters.length > 0 ? r.waiters.shift()(n.payload) : r.queue.push(n.payload));
189
+ }
190
+ }
191
+ } catch {
192
+ e.closed || E(e);
193
+ }
194
+ }
195
+ async function I(e, t, n) {
196
+ for (; ; ) {
197
+ const r = await T(e, t), a = z(r, n);
198
+ if (!(n === 1 && a.protocol !== R))
199
+ return a;
200
+ }
201
+ }
202
+ function P(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;
205
+ }
206
+ function Y(e, t, n, r) {
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, B), i.setUint16(12, n), i.setUint16(14, r), a.set(t, 16), a;
209
+ }
210
+ function z(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
+ return {
213
+ protocol: r,
214
+ length: a,
215
+ rxSeq: t >= 2 ? n.getUint16(14) : void 0,
216
+ payload: e.slice(i, a)
217
+ };
218
+ }
219
+ function Q(e) {
220
+ const t = new DataView(e.buffer, e.byteOffset, e.byteLength), n = (t.getUint8(12) >> 4) * 4;
221
+ return {
222
+ sport: t.getUint16(0),
223
+ dport: t.getUint16(2),
224
+ seq: t.getUint32(4),
225
+ ack: t.getUint32(8),
226
+ flags: t.getUint8(13),
227
+ payload: e.slice(n)
228
+ };
229
+ }
230
+ function y(e, t) {
231
+ return `${e}:${t}`;
232
+ }
233
+ class K {
234
+ constructor(t, n, r, a) {
235
+ this.webSocketUrl = t, this.session = n, this.deviceHello = r, this.log = a;
236
+ }
237
+ socket;
238
+ streams = /* @__PURE__ */ new Map();
239
+ frameQueue = Promise.resolve();
240
+ closed = !1;
241
+ pairRecordWaiter;
242
+ async connect() {
243
+ const t = new WebSocket(this.webSocketUrl);
244
+ t.binaryType = "arraybuffer", this.socket = t, t.onclose = () => {
245
+ this.closed = !0, this.log("Relay socket closed"), this.pairRecordWaiter && (this.pairRecordWaiter.reject(new Error("Relay socket closed")), this.pairRecordWaiter = void 0);
246
+ }, await new Promise((n, r) => {
247
+ t.onopen = () => n(), t.onerror = () => r(new Error("WebSocket connection failed"));
248
+ }), t.onmessage = (n) => {
249
+ const r = n.data instanceof ArrayBuffer ? new Uint8Array(n.data) : new Uint8Array();
250
+ this.enqueueFrame(r);
251
+ }, await this.send({
252
+ type: s.DeviceHello,
253
+ requestId: 0,
254
+ streamId: 0,
255
+ payload: c(this.deviceHello)
256
+ }), this.log("Connected WebSocket relay");
257
+ }
258
+ async startPairing() {
259
+ const t = new Promise((n, r) => {
260
+ this.pairRecordWaiter = { resolve: n, reject: r };
261
+ });
262
+ return await this.send({
263
+ type: s.StartPairing,
264
+ requestId: 0,
265
+ streamId: 0,
266
+ payload: c({})
267
+ }), this.log("Pairing requested"), t;
268
+ }
269
+ async startInstall(t) {
270
+ await this.send({
271
+ type: s.StartInstall,
272
+ requestId: 0,
273
+ streamId: 0,
274
+ payload: c(t)
275
+ }), this.log("Installation requested");
276
+ }
277
+ close() {
278
+ this.closed = !0, this.socket?.close();
279
+ }
280
+ enqueueFrame(t) {
281
+ this.frameQueue = this.frameQueue.then(() => this.handleFrame(A(t))).catch((n) => {
282
+ this.log("Relay frame handling failed", n instanceof Error ? n.message : String(n));
283
+ });
284
+ }
285
+ async handleFrame(t) {
286
+ switch (t.type) {
287
+ case s.OpenStream:
288
+ await this.handleOpenStream(
289
+ t.requestId,
290
+ t.streamId,
291
+ w(t.payload).port
292
+ );
293
+ break;
294
+ case s.StreamData: {
295
+ const n = this.streams.get(t.streamId);
296
+ if (!n) throw new Error(`Unknown stream ${t.streamId}`);
297
+ await H(n, t.payload);
298
+ break;
299
+ }
300
+ case s.StreamClose:
301
+ this.streams.delete(t.streamId);
302
+ break;
303
+ case s.InstallProgress:
304
+ this.log(X(w(t.payload).message));
305
+ break;
306
+ case s.Error:
307
+ this.handleError(t.payload);
308
+ break;
309
+ case s.PairRecordReady:
310
+ this.handlePairRecordReady(w(t.payload));
311
+ break;
312
+ case s.Ping:
313
+ await this.send({
314
+ type: s.Pong,
315
+ requestId: t.requestId,
316
+ streamId: 0,
317
+ payload: new Uint8Array()
318
+ });
319
+ break;
320
+ }
321
+ }
322
+ handleError(t) {
323
+ const n = Z(t);
324
+ this.log("Server error", n), this.pairRecordWaiter && (this.pairRecordWaiter.reject(new Error(n)), this.pairRecordWaiter = void 0);
325
+ }
326
+ handlePairRecordReady(t) {
327
+ this.log("Pair record received", t.udid), this.pairRecordWaiter?.resolve(t), this.pairRecordWaiter = void 0;
328
+ }
329
+ async handleOpenStream(t, n, r) {
330
+ try {
331
+ const a = await j(this.session, r);
332
+ this.streams.set(n, a), await this.send({
333
+ type: s.OpenResult,
334
+ requestId: t,
335
+ streamId: n,
336
+ payload: c({ ok: !0 })
337
+ }), this.log(`Opened device stream ${n} to port ${r}`), this.pumpDeviceToServer(n, a);
338
+ } catch (a) {
339
+ this.log(`Open device stream ${n} failed`, a instanceof Error ? a.message : String(a)), await this.send({
340
+ type: s.OpenResult,
341
+ requestId: t,
342
+ streamId: n,
343
+ payload: c({
344
+ ok: !1,
345
+ error: a instanceof Error ? a.message : String(a)
346
+ })
347
+ });
348
+ }
349
+ }
350
+ async pumpDeviceToServer(t, n) {
351
+ try {
352
+ for (; ; ) {
353
+ const r = await J(n);
354
+ if (this.closed) return;
355
+ await this.send({
356
+ type: s.StreamData,
357
+ requestId: 0,
358
+ streamId: t,
359
+ payload: r
360
+ });
361
+ }
362
+ } catch (r) {
363
+ this.log(`Device stream ${t} closed`, r instanceof Error ? r.message : String(r)), await this.send({
364
+ type: s.StreamClose,
365
+ requestId: 0,
366
+ streamId: t,
367
+ payload: c({
368
+ reason: r instanceof Error ? r.message : String(r)
369
+ })
370
+ });
371
+ }
372
+ }
373
+ async send(t) {
374
+ if (!this.closed) {
375
+ if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {
376
+ this.closed = !0;
377
+ return;
378
+ }
379
+ this.socket.send(D(t));
380
+ }
381
+ }
382
+ }
383
+ function Z(e) {
384
+ const t = new TextDecoder().decode(e);
385
+ try {
386
+ const n = JSON.parse(t);
387
+ return U(n.error ?? t);
388
+ } catch {
389
+ return U(t);
390
+ }
391
+ }
392
+ function U(e) {
393
+ return e.replace(/libimobiledevice/g, "").trim();
394
+ }
395
+ function X(e) {
396
+ const t = "install status: ";
397
+ if (!e.startsWith(t))
398
+ return e;
399
+ const n = e.slice(t.length), a = new DOMParser().parseFromString(n, "application/xml").querySelector("plist > dict");
400
+ if (!a)
401
+ return e;
402
+ const i = ee(a), o = i.Status ?? "Unknown";
403
+ return `Install progress: ${i.PercentComplete ? `${i.PercentComplete}% ` : ""}${o}`;
404
+ }
405
+ function ee(e) {
406
+ const t = {}, n = Array.from(e.children);
407
+ for (let r = 0; r < n.length; r += 2) {
408
+ const a = n[r], i = n[r + 1];
409
+ !a || a.tagName !== "key" || !i || (t[a.textContent ?? ""] = i.textContent ?? "");
410
+ }
411
+ return t;
412
+ }
413
+ async function te({ log: e }) {
414
+ e("Selecting USB device");
415
+ const t = await C(), n = oe(t);
416
+ return e(
417
+ "Selected USB device",
418
+ `${t.manufacturerName ?? ""} ${t.productName ?? ""} ${t.serialNumber ?? ""}`.trim()
419
+ ), n;
420
+ }
421
+ async function ne({ limbuildApiUrl: e, token: t, log: n, target: r }) {
422
+ const a = N(e, t);
423
+ let i;
424
+ try {
425
+ i = await O(a, r, n);
426
+ const o = await i.startPairing();
427
+ return { relay: i, pairRecord: o, target: r };
428
+ } catch (o) {
429
+ throw i?.close(), o;
430
+ }
431
+ }
432
+ async function re({
433
+ limbuildApiUrl: e,
434
+ token: t,
435
+ log: n,
436
+ target: r,
437
+ pairRecord: a
438
+ }) {
439
+ const i = N(e, t);
440
+ let o;
441
+ try {
442
+ return o = await O(i, r, n), await o.startInstall(a), o;
443
+ } catch (l) {
444
+ throw o?.close(), l;
445
+ }
446
+ }
447
+ async function ae(e, t) {
448
+ if (e) {
449
+ if (e.session && (E(e.session), e.session = void 0), e.claimedInterfaceNumber !== void 0)
450
+ try {
451
+ await e.device.releaseInterface(e.claimedInterfaceNumber), t?.("Released usbmux interface");
452
+ } catch (n) {
453
+ t?.("USB interface release failed", m(n));
454
+ } finally {
455
+ e.claimedInterfaceNumber = void 0;
456
+ }
457
+ if (e.device.opened)
458
+ try {
459
+ await e.device.close(), t?.("Closed USB device");
460
+ } catch (n) {
461
+ t?.("USB device close failed", m(n));
462
+ }
463
+ }
464
+ }
465
+ async function O(e, t, n) {
466
+ await ie(t, n);
467
+ const r = new K(e, t.session, t.hello, n);
468
+ return await r.connect(), r;
469
+ }
470
+ async function ie(e, t) {
471
+ if (!e.session)
472
+ try {
473
+ e.candidate = await se(e, t), e.session = await M(e.device, e.candidate), t("Created usbmux session");
474
+ } catch (n) {
475
+ throw await ae(e, t), n;
476
+ }
477
+ }
478
+ function oe(e) {
479
+ return {
480
+ device: e,
481
+ candidate: ce(e),
482
+ hello: {
483
+ serialNumber: e.serialNumber,
484
+ productName: e.productName,
485
+ manufacturerName: e.manufacturerName,
486
+ productId: e.productId,
487
+ vendorId: e.vendorId
488
+ }
489
+ };
490
+ }
491
+ async function se(e, t) {
492
+ const n = q(e.device);
493
+ if (n.length === 0) throw new Error("No Apple usbmux interface found.");
494
+ let r;
495
+ for (const a of n)
496
+ for (const i of [1, 2])
497
+ try {
498
+ return e.device.opened || await e.device.open(), t(
499
+ "Claiming usbmux interface",
500
+ `configuration ${a.configurationValue}, interface ${a.interfaceNumber}, alternate ${a.alternateSetting}, attempt ${i}`
501
+ ), await $(e.device, a), e.claimedInterfaceNumber = a.interfaceNumber, t(
502
+ "Claimed usbmux interface",
503
+ `configuration ${a.configurationValue}, interface ${a.interfaceNumber}`
504
+ ), a;
505
+ } catch (o) {
506
+ r = o, t(
507
+ "USB interface claim failed",
508
+ `configuration ${a.configurationValue}, interface ${a.interfaceNumber}: ${m(o)}`
509
+ ), await ue(e), await le(250);
510
+ }
511
+ throw r instanceof Error ? r : new Error("Unable to claim any Apple usbmux interface.");
512
+ }
513
+ function ce(e) {
514
+ const t = q(e)[0];
515
+ if (!t) throw new Error("No Apple usbmux interface found.");
516
+ return t;
517
+ }
518
+ function q(e) {
519
+ const t = V(e), n = e.configuration?.configurationValue;
520
+ return [
521
+ ...t.filter((r) => r.configurationValue === n),
522
+ ...t.filter((r) => r.configurationValue !== n)
523
+ ];
524
+ }
525
+ function N(e, t) {
526
+ const n = new URL(e);
527
+ return n.protocol = n.protocol === "https:" ? "wss:" : "ws:", n.pathname = `${n.pathname.replace(/\/$/, "")}/device/ws`, t && n.searchParams.set("token", t), n.toString();
528
+ }
529
+ function m(e) {
530
+ return e instanceof Error ? e.message : String(e);
531
+ }
532
+ async function ue(e) {
533
+ if (e.claimedInterfaceNumber !== void 0) {
534
+ try {
535
+ await e.device.releaseInterface(e.claimedInterfaceNumber);
536
+ } catch {
537
+ }
538
+ e.claimedInterfaceNumber = void 0;
539
+ }
540
+ if (e.device.opened)
541
+ try {
542
+ await e.device.close();
543
+ } catch {
544
+ }
545
+ }
546
+ function le(e) {
547
+ return new Promise((t) => setTimeout(t, e));
548
+ }
549
+ async function fe(e = {}) {
550
+ return te({ log: e.log ?? g });
551
+ }
552
+ async function de(e) {
553
+ return ne({ ...e, log: e.log ?? g });
554
+ }
555
+ async function pe(e) {
556
+ return re({ ...e, log: e.log ?? g });
557
+ }
558
+ function g() {
559
+ }
3
560
  export {
4
- a as AppleGsaSrpClient,
5
- Pe as DeviceInstallDialog,
6
- ye as DeviceInstallRelay,
7
- t as RELAY_HEADER_BYTES,
8
- i as RELAY_PROTOCOL_VERSION,
9
- n as RelayClient,
10
- r as RelayMessageType,
11
- o as claimUsbmux,
12
- l as closeDeviceRelayTarget,
13
- p as closeUsbmuxSession,
14
- c as createAppleRelaySession,
15
- d as createBundleIDRequest,
16
- g as createDevelopmentProfileRequest,
17
- u as createUsbmuxSession,
18
- R as decodeFrame,
19
- D as decodeJson,
20
- S as deleteAppleRelaySession,
21
- f as deviceRelayWebSocketUrl,
22
- m as downloadCertificateRequest,
23
- A as downloadProfileRequest,
24
- v as encodeFrame,
25
- P as encodeJson,
26
- y as exportAppleCertificateP12,
27
- C as fetchAppleAccountSession,
28
- I as fetchLimbuildInfo,
29
- q as findBundleIDRequest,
30
- B as findDevelopmentCertificatesRequest,
31
- x as findDevelopmentProfilesRequest,
32
- T as findDeviceRequest,
33
- b as findSigningAssetsForBundle,
34
- h as findUsbmuxCandidates,
35
- w as generateAppleSigningKeyAndCSR,
36
- E as getBulkEndpoints,
37
- L as getLatestSigningAssets,
38
- F as getLatestSigningAssetsWithCertificate,
39
- U as getPairRecord,
40
- O as getReusableAppleSigningAssets,
41
- _ as getSigningAssets,
42
- W as listTeamsRequest,
43
- Y as normalizeBundleID,
44
- k as normalizeUDID,
45
- z as openStream,
46
- G as parseProvisioningProfile,
47
- J as parseProvisioningProfileBase64,
48
- M as parseProvisioningProfileBytes,
49
- H as profileContainsDevice,
50
- K as profileMatchesBundleID,
51
- N as proxyPhoneTwoFactorCode,
52
- V as proxyProvisioningRequest,
53
- Z as proxySrpComplete,
54
- j as proxySrpInit,
55
- Q as proxyTwoFactorCode,
56
- X as putAppleGeneratedSigningAssets,
57
- $ as putPairRecord,
58
- ee as putSigningAssets,
59
- se as receiveStreamData,
60
- ae as registerDeviceRequest,
61
- te as requestAppleDevice,
62
- ie as requestUSBAccess,
63
- ne as selectDeveloperPortalTeam,
64
- re as sendStreamData,
65
- oe as startBrowserOwnedAppleIDLogin,
66
- le as startInstallRelay,
67
- pe as startPairingRelay,
68
- ce as startSignedDeviceBuild,
69
- de as storedSigningAssetsReusable,
70
- ge as submitDevelopmentCSRRequest,
71
- ue as teamIDCandidates,
72
- Re as transferIn,
73
- De as transferOutWithZlp,
74
- Se as triggerPhoneTwoFactor,
75
- fe as triggerTrustedDeviceTwoFactor,
76
- me as useDeviceInstall,
77
- Ae as watchBuildLogEvents
561
+ K as RelayClient,
562
+ ae as closeDeviceRelayTarget,
563
+ N as deviceRelayWebSocketUrl,
564
+ ye as getPairRecord,
565
+ me as normalizeUDID,
566
+ de as pairDevice,
567
+ ge as putPairRecord,
568
+ fe as requestUSBAccess,
569
+ pe as startDeviceInstall,
570
+ re as startDeviceInstallRelay,
571
+ ne as startDevicePairingRelay
78
572
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../use-device-install-ByUSmeYz.js");exports.useDeviceInstall=e.useDeviceInstall;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),s=require("./index.cjs"),S=require("../browser-storage-C1jQLXat.js");function B({apiUrl:c,token:d,log:e=C}){const[t,h]=r.useState(),[l,y]=r.useState(),[w,u]=r.useState(),[p,n]=r.useState(),[D,v]=r.useState(!1),f=r.useRef(void 0),b=r.useRef(void 0),i=r.useCallback(async()=>{f.current?.close(),f.current=void 0,await s.closeDeviceRelayTarget(b.current,e)},[e]);r.useEffect(()=>{b.current=t},[t]),r.useEffect(()=>()=>{i()},[i]);const m=r.useCallback(async()=>{u("usb"),n(void 0),v(!1);let a;try{await i(),a=await s.requestUSBAccess({log:e});const o=await S.getPairRecord(a.hello.serialNumber);return h(a),y(o),e(o?"Pair record found":"No pair record found",a.hello.serialNumber),a}catch(o){await s.closeDeviceRelayTarget(a,e),h(void 0),y(void 0),n(R(o));return}finally{u(void 0)}},[i,e]),P=r.useCallback(async()=>{if(!c||!t)throw new Error("Select a USB device before pairing.");u("pair"),n(void 0),v(!1);try{await i();const a=await s.pairDevice({limbuildApiUrl:c,token:d,log:e,target:t}),o=await S.putPairRecord(a.pairRecord,{productName:t.hello.productName});return a.relay.close(),await s.closeDeviceRelayTarget(t,e),y(o),v(!1),e("Device paired","The pair record was stored locally in this browser."),o}catch(a){await s.closeDeviceRelayTarget(t,e),v(!0),n(R(a));return}finally{u(void 0)}},[c,i,t,e,d]),q=r.useCallback(async()=>{if(!c||!t||!l)throw new Error("Select and pair a USB device before starting installation.");u("install"),n(void 0);try{return await i(),f.current=await s.startDeviceInstall({limbuildApiUrl:c,token:d,log:e,target:t,pairRecord:l}),e("Device install started","Installation will continue through the connected iPhone."),f.current}catch(a){await s.closeDeviceRelayTarget(t,e),n(R(a));return}finally{u(void 0)}},[c,i,t,e,l,d]),A=r.useCallback(()=>{i(),e("Device relay stopped")},[i,e]);return{device:t,pairRecord:l,busyAction:w,error:p,pairConfirmationRequired:D,hasPairRecord:!!l,canPair:!!c&&!w&&!!t,canInstall:!!c&&!w&&!!t&&!!l,requestUSBAccess:m,pairBrowser:P,startInstallation:q,stopRelay:A,clearError:()=>n(void 0)}}function C(){}function R(c){return c instanceof Error?c.message:String(c)}exports.useDeviceInstallRelay=B;
@@ -1 +1,23 @@
1
- export { useDeviceInstall } from '../hooks/use-device-install';
1
+ import { DeviceInstallLog, DeviceRelayTarget, RelayClient, StoredPairRecord } from './index';
2
+ export type DeviceInstallRelayBusyAction = 'usb' | 'pair' | 'install';
3
+ export type UseDeviceInstallRelayOptions = {
4
+ apiUrl?: string;
5
+ token?: string;
6
+ log?: DeviceInstallLog;
7
+ };
8
+ export type UseDeviceInstallRelayResult = {
9
+ device?: DeviceRelayTarget;
10
+ pairRecord?: StoredPairRecord;
11
+ busyAction?: DeviceInstallRelayBusyAction;
12
+ error?: string;
13
+ pairConfirmationRequired: boolean;
14
+ hasPairRecord: boolean;
15
+ canPair: boolean;
16
+ canInstall: boolean;
17
+ requestUSBAccess: () => Promise<DeviceRelayTarget | undefined>;
18
+ pairBrowser: () => Promise<StoredPairRecord | undefined>;
19
+ startInstallation: () => Promise<RelayClient | undefined>;
20
+ stopRelay: () => void;
21
+ clearError: () => void;
22
+ };
23
+ export declare function useDeviceInstallRelay({ apiUrl, token, log, }: UseDeviceInstallRelayOptions): UseDeviceInstallRelayResult;