@limrun/ui 0.9.0-rc.9 → 0.13.3

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 (80) 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 +486 -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-Cx9eW-bm.mjs +205 -0
  9. package/dist/browser-storage-jJaIht4K.js +1 -0
  10. package/dist/client-ASLtHFLh.js +1 -0
  11. package/dist/client-CGdh8yoJ.mjs +234 -0
  12. package/dist/components/device-install/index.d.ts +1 -2
  13. package/dist/core/device-install/apple/provisioning.d.ts +58 -7
  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 +68 -0
  23. package/dist/device-build/signing.d.ts +20 -0
  24. package/dist/device-install/demo/demo.d.ts +0 -0
  25. package/dist/device-install/index.cjs +1 -1
  26. package/dist/device-install/index.d.ts +18 -3
  27. package/dist/device-install/index.js +583 -76
  28. package/dist/device-install/react.cjs +1 -1
  29. package/dist/device-install/react.d.ts +23 -1
  30. package/dist/device-install/react.js +98 -2
  31. package/dist/hooks/index.d.ts +1 -1
  32. package/dist/index-CMeQfhYy.js +22 -0
  33. package/dist/index-DFdCvi2_.mjs +11543 -0
  34. package/dist/index.cjs +1 -1
  35. package/dist/index.d.ts +0 -2
  36. package/dist/index.js +502 -495
  37. package/dist/limbuild-client-CgEncrgx.js +1 -0
  38. package/dist/limbuild-client-D7U7w342.mjs +81 -0
  39. package/dist/provisioning-DKbkBO-p.mjs +239 -0
  40. package/dist/provisioning-Va0PH4Kk.js +1 -0
  41. package/package.json +21 -1
  42. package/src/app-store-relay/index.test.ts +70 -0
  43. package/src/app-store-relay/index.ts +514 -0
  44. package/src/app-store-relay/react.ts +129 -0
  45. package/src/components/device-install/index.ts +1 -2
  46. package/src/core/device-install/apple/client.ts +29 -22
  47. package/src/core/device-install/apple/crypto.ts +9 -6
  48. package/src/core/device-install/apple/gsa-srp.ts +3 -7
  49. package/src/core/device-install/apple/provisioning.test.ts +84 -0
  50. package/src/core/device-install/apple/provisioning.ts +98 -16
  51. package/src/core/device-install/apple/relay.ts +5 -1
  52. package/src/core/device-install/operations/limbuild-client.ts +41 -4
  53. package/src/core/device-install/operations/operations.ts +3 -1
  54. package/src/core/device-install/operations/relay-client.ts +57 -27
  55. package/src/core/device-install/operations/usbmux.ts +3 -3
  56. package/src/core/device-install/operations/webusb.ts +9 -4
  57. package/src/core/device-install/storage/browser-storage.ts +43 -14
  58. package/src/core/device-install/types.ts +6 -8
  59. package/src/device-build/index.ts +42 -0
  60. package/src/device-build/react.ts +131 -0
  61. package/src/device-build/signing.ts +94 -0
  62. package/src/device-install/README.md +423 -0
  63. package/src/device-install/demo/demo.css +493 -0
  64. package/src/device-install/demo/demo.tsx +1069 -0
  65. package/src/device-install/demo/index.html +12 -0
  66. package/src/device-install/index.ts +49 -3
  67. package/src/device-install/react.ts +189 -1
  68. package/src/hooks/index.ts +1 -1
  69. package/src/index.ts +0 -3
  70. package/vite.config.ts +4 -0
  71. package/dist/components/device-install/device-install-dialog.d.ts +0 -5
  72. package/dist/device-install-dialog-CqxDEH85.mjs +0 -443
  73. package/dist/device-install-dialog-jvqQ-fuo.js +0 -2
  74. package/dist/device-install-dialog.css +0 -1
  75. package/dist/hooks/use-device-install.d.ts +0 -73
  76. package/dist/use-device-install-CAPli9MR.js +0 -31
  77. package/dist/use-device-install-H8dqqvbR.mjs +0 -13624
  78. package/src/components/device-install/device-install-dialog.css +0 -325
  79. package/src/components/device-install/device-install-dialog.tsx +0 -495
  80. package/src/hooks/use-device-install.ts +0 -1219
@@ -1,78 +1,585 @@
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-H8dqqvbR.mjs";
2
- import { D as Pe, D as ye } from "../device-install-dialog-CqxDEH85.mjs";
1
+ import { j as ge, n as be, k as Ue } from "../browser-storage-Cx9eW-bm.mjs";
2
+ const v = 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, 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
+ function V(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 !== v)
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 h(e) {
42
+ return JSON.parse(new TextDecoder().decode(e));
43
+ }
44
+ async function A() {
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 C(e) {
50
+ const t = [], n = e.configuration?.configurationValue, r = e.configurations.find(
51
+ (a) => a.configurationValue === n
52
+ );
53
+ r && t.push(...U(r));
54
+ for (const a of e.configurations)
55
+ a.configurationValue !== n && t.push(...U(a));
56
+ return t;
57
+ }
58
+ function U(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 L(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), await e.selectAlternateInterface(t.interfaceNumber, t.alternateSetting);
72
+ }
73
+ function T(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 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());
88
+ }
89
+ async function W(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 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);
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 = {
100
+ device: e,
101
+ candidate: t,
102
+ inEndpoint: n,
103
+ outEndpoint: r,
104
+ muxVersion: f,
105
+ txSeq: 0,
106
+ rxSeq: 65535,
107
+ nextSport: M,
108
+ streams: /* @__PURE__ */ new Map(),
109
+ writeChain: Promise.resolve(),
110
+ closed: !1
111
+ };
112
+ return f >= 2 && await x(w, B, new Uint8Array([7])), Q(w), w;
113
+ }
114
+ async function H(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(m(t, a.sport), a), await p(a, y, new Uint8Array()), await a.opened, a;
133
+ }
134
+ async function J(e, t) {
135
+ if (e.session.closed)
136
+ throw new Error("usbmux session is closed.");
137
+ await p(e, l, t), e.seq += t.byteLength;
138
+ }
139
+ async function G(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 I(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 p(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) : O(t, n);
165
+ await R(e.device, e.outEndpoint, r);
166
+ }), e.writeChain;
167
+ }
168
+ async function Q(e) {
169
+ try {
170
+ for (; ; ) {
171
+ if (e.closed) return;
172
+ const t = await P(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 = K(t.payload), r = e.streams.get(m(n.sport, n.dport));
177
+ if (r) {
178
+ if (n.flags & _) {
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));
182
+ continue;
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();
186
+ continue;
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));
189
+ }
190
+ }
191
+ } catch {
192
+ e.closed || I(e);
193
+ }
194
+ }
195
+ async function P(e, t, n) {
196
+ for (; ; ) {
197
+ const r = await W(e, t), a = z(r, n);
198
+ if (!(n === 1 && a.protocol !== E))
199
+ return a;
200
+ }
201
+ }
202
+ 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;
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, F), 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 K(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 m(e, t) {
231
+ return `${e}:${t}`;
232
+ }
233
+ class X {
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.frameQueue.finally(() => {
246
+ this.pairRecordWaiter && (this.pairRecordWaiter.reject(new Error("Relay socket closed")), this.pairRecordWaiter = void 0);
247
+ });
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);
253
+ }, await this.send({
254
+ type: s.DeviceHello,
255
+ requestId: 0,
256
+ streamId: 0,
257
+ payload: c(this.deviceHello)
258
+ }), this.log("Connected WebSocket relay");
259
+ }
260
+ async startPairing() {
261
+ const t = new Promise((n, r) => {
262
+ this.pairRecordWaiter = { resolve: n, reject: r };
263
+ });
264
+ return await this.send({
265
+ type: s.StartPairing,
266
+ requestId: 0,
267
+ streamId: 0,
268
+ payload: c({})
269
+ }), this.log("Pairing requested"), t;
270
+ }
271
+ async startInstall(t) {
272
+ await this.send({
273
+ type: s.StartInstall,
274
+ requestId: 0,
275
+ streamId: 0,
276
+ payload: c(t)
277
+ }), this.log("Installation requested");
278
+ }
279
+ close() {
280
+ this.closed = !0, this.socket?.close();
281
+ }
282
+ enqueueFrame(t) {
283
+ this.frameQueue = this.frameQueue.then(() => this.handleFrame(V(t))).catch((n) => {
284
+ this.log("Relay frame handling failed", n instanceof Error ? n.message : String(n));
285
+ });
286
+ }
287
+ async handleFrame(t) {
288
+ switch (t.type) {
289
+ case s.OpenStream:
290
+ await this.handleOpenStream(
291
+ t.requestId,
292
+ t.streamId,
293
+ h(t.payload).port
294
+ );
295
+ break;
296
+ case s.StreamData: {
297
+ const n = this.streams.get(t.streamId);
298
+ if (!n) throw new Error(`Unknown stream ${t.streamId}`);
299
+ await J(n, t.payload);
300
+ break;
301
+ }
302
+ case s.StreamClose:
303
+ this.streams.delete(t.streamId);
304
+ break;
305
+ case s.InstallProgress:
306
+ this.log(ee(h(t.payload).message));
307
+ break;
308
+ case s.Error:
309
+ this.handleError(t.payload);
310
+ break;
311
+ case s.PairRecordReady:
312
+ this.handlePairRecordReady(h(t.payload));
313
+ break;
314
+ case s.Ping:
315
+ await this.send({
316
+ type: s.Pong,
317
+ requestId: t.requestId,
318
+ streamId: 0,
319
+ payload: new Uint8Array()
320
+ });
321
+ break;
322
+ }
323
+ }
324
+ handleError(t) {
325
+ const n = Z(t);
326
+ this.log("Server error", n), this.pairRecordWaiter && (this.pairRecordWaiter.reject(new Error(n)), this.pairRecordWaiter = void 0);
327
+ }
328
+ handlePairRecordReady(t) {
329
+ this.log("Pair record received", t.udid), this.pairRecordWaiter?.resolve(t), this.pairRecordWaiter = void 0;
330
+ }
331
+ async handleOpenStream(t, n, r) {
332
+ try {
333
+ const a = await H(this.session, r);
334
+ this.streams.set(n, a), await this.send({
335
+ type: s.OpenResult,
336
+ requestId: t,
337
+ streamId: n,
338
+ payload: c({ ok: !0 })
339
+ }), this.log(`Opened device stream ${n} to port ${r}`), this.pumpDeviceToServer(n, a);
340
+ } catch (a) {
341
+ this.log(
342
+ `Open device stream ${n} failed`,
343
+ a instanceof Error ? a.message : String(a)
344
+ ), await this.send({
345
+ type: s.OpenResult,
346
+ requestId: t,
347
+ streamId: n,
348
+ payload: c({
349
+ ok: !1,
350
+ error: a instanceof Error ? a.message : String(a)
351
+ })
352
+ });
353
+ }
354
+ }
355
+ async pumpDeviceToServer(t, n) {
356
+ try {
357
+ for (; ; ) {
358
+ const r = await G(n);
359
+ if (this.closed) return;
360
+ await this.send({
361
+ type: s.StreamData,
362
+ requestId: 0,
363
+ streamId: t,
364
+ payload: r
365
+ });
366
+ }
367
+ } catch (r) {
368
+ this.log(`Device stream ${t} closed`, r instanceof Error ? r.message : String(r)), await this.send({
369
+ type: s.StreamClose,
370
+ requestId: 0,
371
+ streamId: t,
372
+ payload: c({
373
+ reason: r instanceof Error ? r.message : String(r)
374
+ })
375
+ });
376
+ }
377
+ }
378
+ async send(t) {
379
+ if (!this.closed) {
380
+ if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {
381
+ this.closed = !0;
382
+ return;
383
+ }
384
+ this.socket.send(D(t));
385
+ }
386
+ }
387
+ }
388
+ function Z(e) {
389
+ const t = new TextDecoder().decode(e);
390
+ try {
391
+ const n = JSON.parse(t);
392
+ return S(n.error ?? t);
393
+ } catch {
394
+ return S(t);
395
+ }
396
+ }
397
+ function S(e) {
398
+ return e.replace(/libimobiledevice/g, "").trim();
399
+ }
400
+ function ee(e) {
401
+ const t = "install status: ";
402
+ if (!e.startsWith(t))
403
+ return e;
404
+ const n = e.slice(t.length), r = d(n, "Error");
405
+ if (r) {
406
+ const o = d(n, "ErrorDescription");
407
+ return `Install error: ${r}${o ? ` — ${o}` : ""}`;
408
+ }
409
+ const a = d(n, "Status") ?? "Unknown", i = d(n, "PercentComplete");
410
+ return `Install progress: ${i ? `${i}% ` : ""}${a}`;
411
+ }
412
+ function d(e, t) {
413
+ const r = new RegExp(
414
+ `<key>\\s*${te(
415
+ t
416
+ )}\\s*</key>\\s*<(?:string|integer|real)>([\\s\\S]*?)</(?:string|integer|real)>`
417
+ ).exec(e);
418
+ return r ? ne(r[1].trim()) : void 0;
419
+ }
420
+ function te(e) {
421
+ return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
422
+ }
423
+ function ne(e) {
424
+ return e.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&amp;/g, "&");
425
+ }
426
+ async function re({ log: e }) {
427
+ e("Selecting USB device");
428
+ const t = await A(), n = ce(t);
429
+ return e(
430
+ "Selected USB device",
431
+ `${t.manufacturerName ?? ""} ${t.productName ?? ""} ${t.serialNumber ?? ""}`.trim()
432
+ ), n;
433
+ }
434
+ async function ae({ limbuildApiUrl: e, token: t, log: n, target: r }) {
435
+ const a = N(e, t);
436
+ let i;
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;
443
+ }
444
+ }
445
+ async function ie({
446
+ limbuildApiUrl: e,
447
+ token: t,
448
+ log: n,
449
+ target: r,
450
+ pairRecord: a
451
+ }) {
452
+ const i = N(e, t);
453
+ let o;
454
+ try {
455
+ return o = await $(i, r, n), await o.startInstall(a), o;
456
+ } catch (f) {
457
+ throw o?.close(), f;
458
+ }
459
+ }
460
+ async function oe(e, t) {
461
+ if (e) {
462
+ if (e.session && (I(e.session), e.session = void 0), e.claimedInterfaceNumber !== void 0)
463
+ try {
464
+ await e.device.releaseInterface(e.claimedInterfaceNumber), t?.("Released usbmux interface");
465
+ } catch (n) {
466
+ t?.("USB interface release failed", g(n));
467
+ } finally {
468
+ e.claimedInterfaceNumber = void 0;
469
+ }
470
+ if (e.device.opened)
471
+ try {
472
+ await e.device.close(), t?.("Closed USB device");
473
+ } catch (n) {
474
+ t?.("USB device close failed", g(n));
475
+ }
476
+ }
477
+ }
478
+ async function $(e, t, n) {
479
+ await se(t, n);
480
+ const r = new X(e, t.session, t.hello, n);
481
+ return await r.connect(), r;
482
+ }
483
+ async function se(e, t) {
484
+ if (!e.session)
485
+ try {
486
+ e.candidate = await ue(e, t), e.session = await j(e.device, e.candidate), t("Created usbmux session");
487
+ } catch (n) {
488
+ throw await oe(e, t), n;
489
+ }
490
+ }
491
+ function ce(e) {
492
+ return {
493
+ device: e,
494
+ candidate: le(e),
495
+ hello: {
496
+ serialNumber: e.serialNumber,
497
+ productName: e.productName,
498
+ manufacturerName: e.manufacturerName,
499
+ productId: e.productId,
500
+ vendorId: e.vendorId
501
+ }
502
+ };
503
+ }
504
+ async function ue(e, t) {
505
+ const n = q(e.device);
506
+ if (n.length === 0) throw new Error("No Apple usbmux interface found.");
507
+ let r;
508
+ for (const a of n)
509
+ for (const i of [1, 2])
510
+ try {
511
+ return e.device.opened || await e.device.open(), t(
512
+ "Claiming usbmux interface",
513
+ `configuration ${a.configurationValue}, interface ${a.interfaceNumber}, alternate ${a.alternateSetting}, attempt ${i}`
514
+ ), await L(e.device, a), e.claimedInterfaceNumber = a.interfaceNumber, t(
515
+ "Claimed usbmux interface",
516
+ `configuration ${a.configurationValue}, interface ${a.interfaceNumber}`
517
+ ), a;
518
+ } catch (o) {
519
+ r = o, t(
520
+ "USB interface claim failed",
521
+ `configuration ${a.configurationValue}, interface ${a.interfaceNumber}: ${g(o)}`
522
+ ), await fe(e), await de(250);
523
+ }
524
+ throw r instanceof Error ? r : new Error("Unable to claim any Apple usbmux interface.");
525
+ }
526
+ function le(e) {
527
+ const t = q(e)[0];
528
+ if (!t) throw new Error("No Apple usbmux interface found.");
529
+ return t;
530
+ }
531
+ function q(e) {
532
+ const t = C(e), n = e.configuration?.configurationValue;
533
+ return [
534
+ ...t.filter((r) => r.configurationValue === n),
535
+ ...t.filter((r) => r.configurationValue !== n)
536
+ ];
537
+ }
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();
541
+ }
542
+ function g(e) {
543
+ return e instanceof Error ? e.message : String(e);
544
+ }
545
+ async function fe(e) {
546
+ if (e.claimedInterfaceNumber !== void 0) {
547
+ try {
548
+ await e.device.releaseInterface(e.claimedInterfaceNumber);
549
+ } catch {
550
+ }
551
+ e.claimedInterfaceNumber = void 0;
552
+ }
553
+ if (e.device.opened)
554
+ try {
555
+ await e.device.close();
556
+ } catch {
557
+ }
558
+ }
559
+ function de(e) {
560
+ return new Promise((t) => setTimeout(t, e));
561
+ }
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 });
567
+ }
568
+ async function he(e) {
569
+ return ie({ ...e, log: e.log ?? b });
570
+ }
571
+ function b() {
572
+ }
3
573
  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
574
+ X as RelayClient,
575
+ oe as closeDeviceRelayTarget,
576
+ 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
78
585
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../use-device-install-CAPli9MR.js");exports.useDeviceInstall=e.useDeviceInstall;
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 +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;