@limrun/ui 0.14.0-rc.5 → 0.14.0

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 (115) hide show
  1. package/README.md +9 -26
  2. package/dist/components/remote-control.d.ts +36 -0
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.js +1189 -1089
  6. package/package.json +10 -51
  7. package/src/components/remote-control.tsx +267 -0
  8. package/src/index.ts +1 -1
  9. package/vite.config.ts +0 -9
  10. package/dist/app-store-relay/index.cjs +0 -9
  11. package/dist/app-store-relay/index.d.ts +0 -204
  12. package/dist/app-store-relay/index.js +0 -677
  13. package/dist/app-store-relay/react.cjs +0 -1
  14. package/dist/app-store-relay/react.d.ts +0 -15
  15. package/dist/app-store-relay/react.js +0 -69
  16. package/dist/apple-credentials/index.cjs +0 -1
  17. package/dist/apple-credentials/index.d.ts +0 -110
  18. package/dist/apple-credentials/index.js +0 -291
  19. package/dist/browser-storage-BnO-Ma-e.mjs +0 -219
  20. package/dist/browser-storage-DLxIqZk5.js +0 -1
  21. package/dist/client-C9z_sgOf.js +0 -1
  22. package/dist/client-CFDB4mX5.mjs +0 -191
  23. package/dist/core/device-install/apple/client.d.ts +0 -18
  24. package/dist/core/device-install/apple/crypto.d.ts +0 -20
  25. package/dist/core/device-install/apple/gsa-srp.d.ts +0 -26
  26. package/dist/core/device-install/apple/index.d.ts +0 -5
  27. package/dist/core/device-install/apple/provisioning.d.ts +0 -237
  28. package/dist/core/device-install/apple/relay.d.ts +0 -53
  29. package/dist/core/device-install/index.d.ts +0 -4
  30. package/dist/core/device-install/operations/index.d.ts +0 -6
  31. package/dist/core/device-install/operations/limbuild-client.d.ts +0 -43
  32. package/dist/core/device-install/operations/operations.d.ts +0 -47
  33. package/dist/core/device-install/operations/relay-client.d.ts +0 -26
  34. package/dist/core/device-install/operations/relay-protocol.d.ts +0 -27
  35. package/dist/core/device-install/operations/usbmux.d.ts +0 -32
  36. package/dist/core/device-install/operations/webusb.d.ts +0 -21
  37. package/dist/core/device-install/storage/browser-storage.d.ts +0 -56
  38. package/dist/core/device-install/storage/index.d.ts +0 -2
  39. package/dist/core/device-install/storage/secret-store.d.ts +0 -124
  40. package/dist/core/device-install/types.d.ts +0 -57
  41. package/dist/core/errors.d.ts +0 -1
  42. package/dist/core/play-publish/google.d.ts +0 -13
  43. package/dist/core/play-publish/publish.d.ts +0 -34
  44. package/dist/device-build/index.cjs +0 -1
  45. package/dist/device-build/index.d.ts +0 -4
  46. package/dist/device-build/index.js +0 -85
  47. package/dist/device-build/react.cjs +0 -1
  48. package/dist/device-build/react.d.ts +0 -21
  49. package/dist/device-build/react.js +0 -68
  50. package/dist/device-build/signing.d.ts +0 -20
  51. package/dist/device-install/demo/demo.d.ts +0 -0
  52. package/dist/device-install/index.cjs +0 -1
  53. package/dist/device-install/index.d.ts +0 -18
  54. package/dist/device-install/index.js +0 -594
  55. package/dist/device-install/react.cjs +0 -1
  56. package/dist/device-install/react.d.ts +0 -24
  57. package/dist/device-install/react.js +0 -105
  58. package/dist/errors-BSkqS7U-.js +0 -1
  59. package/dist/errors-gy8yQJos.mjs +0 -6
  60. package/dist/gsa-srp-Bme3JLEi.mjs +0 -266
  61. package/dist/gsa-srp-CCIfUz7Y.js +0 -1
  62. package/dist/index-ChhtuQ7e.js +0 -22
  63. package/dist/index-YDu8K9a4.mjs +0 -11279
  64. package/dist/limbuild-client-BagK_FWE.mjs +0 -83
  65. package/dist/limbuild-client-CVDwq54z.js +0 -1
  66. package/dist/play-publish/index.cjs +0 -1
  67. package/dist/play-publish/index.d.ts +0 -2
  68. package/dist/play-publish/index.js +0 -109
  69. package/dist/play-publish/react.cjs +0 -1
  70. package/dist/play-publish/react.d.ts +0 -31
  71. package/dist/play-publish/react.js +0 -91
  72. package/dist/provisioning-CDPvxd1h.mjs +0 -270
  73. package/dist/provisioning-CbC4h--7.js +0 -1
  74. package/src/app-store-relay/index.test.ts +0 -60
  75. package/src/app-store-relay/index.ts +0 -846
  76. package/src/app-store-relay/react.ts +0 -131
  77. package/src/apple-credentials/index.test.ts +0 -180
  78. package/src/apple-credentials/index.ts +0 -388
  79. package/src/core/device-install/apple/client.ts +0 -150
  80. package/src/core/device-install/apple/crypto.ts +0 -205
  81. package/src/core/device-install/apple/gsa-srp.ts +0 -123
  82. package/src/core/device-install/apple/index.ts +0 -5
  83. package/src/core/device-install/apple/provisioning.test.ts +0 -114
  84. package/src/core/device-install/apple/provisioning.ts +0 -419
  85. package/src/core/device-install/apple/relay.ts +0 -202
  86. package/src/core/device-install/index.ts +0 -4
  87. package/src/core/device-install/operations/index.ts +0 -6
  88. package/src/core/device-install/operations/limbuild-client.ts +0 -144
  89. package/src/core/device-install/operations/operations.ts +0 -239
  90. package/src/core/device-install/operations/relay-client.ts +0 -286
  91. package/src/core/device-install/operations/relay-protocol.ts +0 -71
  92. package/src/core/device-install/operations/usbmux.ts +0 -270
  93. package/src/core/device-install/operations/webusb-dom.d.ts +0 -54
  94. package/src/core/device-install/operations/webusb.ts +0 -110
  95. package/src/core/device-install/storage/browser-storage.test.ts +0 -65
  96. package/src/core/device-install/storage/browser-storage.ts +0 -325
  97. package/src/core/device-install/storage/index.ts +0 -2
  98. package/src/core/device-install/storage/secret-store.ts +0 -332
  99. package/src/core/device-install/types.ts +0 -69
  100. package/src/core/errors.ts +0 -3
  101. package/src/core/play-publish/google.ts +0 -113
  102. package/src/core/play-publish/publish.test.ts +0 -68
  103. package/src/core/play-publish/publish.ts +0 -89
  104. package/src/device-build/index.ts +0 -42
  105. package/src/device-build/react.ts +0 -130
  106. package/src/device-build/signing.ts +0 -94
  107. package/src/device-install/README.md +0 -423
  108. package/src/device-install/demo/demo.css +0 -493
  109. package/src/device-install/demo/demo.tsx +0 -1061
  110. package/src/device-install/demo/index.html +0 -12
  111. package/src/device-install/index.ts +0 -50
  112. package/src/device-install/react.ts +0 -195
  113. package/src/play-publish/README.md +0 -66
  114. package/src/play-publish/index.ts +0 -12
  115. package/src/play-publish/react.ts +0 -208
@@ -1,594 +0,0 @@
1
- import { e as w } from "../errors-gy8yQJos.mjs";
2
- import { j as Ue, n as Se, k as ve } from "../browser-storage-BnO-Ma-e.mjs";
3
- const v = 1, d = 16, s = {
4
- DeviceHello: 1,
5
- OpenStream: 2,
6
- OpenResult: 3,
7
- StreamData: 4,
8
- StreamClose: 5,
9
- InstallProgress: 6,
10
- Error: 7,
11
- Ping: 8,
12
- Pong: 9,
13
- StartPairing: 10,
14
- StartInstall: 11,
15
- PairRecordReady: 12
16
- };
17
- function V(e) {
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
- }
21
- function A(e) {
22
- if (e.byteLength < d)
23
- throw new Error(`Relay frame too short: ${e.byteLength}`);
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
- throw new Error(
30
- `Relay frame length mismatch: got ${e.byteLength}, expected ${d + r}`
31
- );
32
- return {
33
- type: t.getUint8(1),
34
- requestId: t.getUint32(4),
35
- streamId: t.getUint32(8),
36
- payload: e.slice(d)
37
- };
38
- }
39
- function l(e) {
40
- return new TextEncoder().encode(JSON.stringify(e));
41
- }
42
- function y(e) {
43
- return JSON.parse(new TextDecoder().decode(e));
44
- }
45
- async function C() {
46
- if (!navigator.usb)
47
- throw new Error("WebUSB is not available in this browser.");
48
- return navigator.usb.requestDevice({ filters: [{ vendorId: 1452 }] });
49
- }
50
- function L(e) {
51
- const t = [], n = e.configuration?.configurationValue, r = e.configurations.find(
52
- (a) => a.configurationValue === n
53
- );
54
- r && t.push(...U(r));
55
- for (const a of e.configurations)
56
- a.configurationValue !== n && t.push(...U(a));
57
- return t;
58
- }
59
- function U(e) {
60
- const t = [];
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
- configurationValue: e.configurationValue,
65
- interfaceNumber: n.interfaceNumber,
66
- alternateSetting: r.alternateSetting,
67
- endpoints: r.endpoints
68
- });
69
- return t;
70
- }
71
- async function T(e, t) {
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
- }
74
- function B(e) {
75
- const t = e.endpoints.find(
76
- (r) => r.direction === "out" && r.type === "bulk"
77
- ), n = e.endpoints.find(
78
- (r) => r.direction === "in" && r.type === "bulk"
79
- );
80
- if (!t || !n)
81
- throw new Error("Could not find usbmux bulk endpoints.");
82
- return { outEndpoint: t, inEndpoint: n };
83
- }
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
- }
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
- }
96
- const E = 0, F = 2, k = 6, _ = 4277009102, m = 2, M = 4, f = 16, j = 49152;
97
- async function H(e, t) {
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
- device: e,
102
- candidate: t,
103
- inEndpoint: n,
104
- outEndpoint: r,
105
- muxVersion: c,
106
- txSeq: 0,
107
- rxSeq: 65535,
108
- nextSport: j,
109
- streams: /* @__PURE__ */ new Map(),
110
- writeChain: Promise.resolve(),
111
- closed: !1
112
- };
113
- return c >= 2 && await I(u, F, new Uint8Array([7])), Y(u), u;
114
- }
115
- async function J(e, t) {
116
- if (e.closed)
117
- throw new Error("usbmux session is closed.");
118
- let n, r;
119
- const a = {
120
- session: e,
121
- sport: e.nextSport++,
122
- dport: t,
123
- seq: 0,
124
- ack: 0,
125
- queue: [],
126
- waiters: [],
127
- opened: new Promise((i, o) => {
128
- n = i, r = o;
129
- }),
130
- resolveOpened: n,
131
- rejectOpened: r
132
- };
133
- return e.streams.set(g(t, a.sport), a), await h(a, m, new Uint8Array()), await a.opened, a;
134
- }
135
- async function G(e, t) {
136
- if (e.session.closed)
137
- throw new Error("usbmux session is closed.");
138
- await h(e, f, t), e.seq += t.byteLength;
139
- }
140
- async function Q(e) {
141
- if (e.queue.length > 0)
142
- return e.queue.shift();
143
- if (e.error)
144
- throw e.error;
145
- return new Promise((t) => {
146
- e.waiters.push(t);
147
- });
148
- }
149
- function P(e) {
150
- e.closed = !0;
151
- for (const t of e.streams.values())
152
- for (t.error = new Error("usbmux session closed"), t.rejectOpened(t.error); t.waiters.length > 0; )
153
- t.waiters.shift()(new Uint8Array());
154
- e.streams.clear();
155
- }
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
- }
160
- async function I(e, t, n) {
161
- if (e.closed)
162
- throw new Error("usbmux session is closed.");
163
- return e.writeChain = e.writeChain.then(async () => {
164
- if (e.closed) return;
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
- }), e.writeChain;
168
- }
169
- async function Y(e) {
170
- try {
171
- for (; ; ) {
172
- if (e.closed) return;
173
- const t = await x(e.device, e.inEndpoint, e.muxVersion);
174
- if (e.closed) return;
175
- if (t.rxSeq !== void 0 && (e.rxSeq = t.rxSeq), t.protocol !== k)
176
- continue;
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
- continue;
184
- }
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
- continue;
188
- }
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
- }
191
- }
192
- } catch {
193
- e.closed || P(e);
194
- }
195
- }
196
- async function x(e, t, n) {
197
- for (; ; ) {
198
- const r = await W(e, t), a = K(r, n);
199
- if (!(n === 1 && a.protocol !== E))
200
- return a;
201
- }
202
- }
203
- function O(e, t) {
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
- }
207
- function z(e, t, n, r) {
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, n), i.setUint16(14, r), a.set(t, 16), a;
210
- }
211
- function K(e, t) {
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
- return {
214
- protocol: r,
215
- length: a,
216
- rxSeq: t >= 2 ? n.getUint16(14) : void 0,
217
- payload: e.slice(i, a)
218
- };
219
- }
220
- function X(e) {
221
- const t = new DataView(e.buffer, e.byteOffset, e.byteLength), n = (t.getUint8(12) >> 4) * 4;
222
- return {
223
- sport: t.getUint16(0),
224
- dport: t.getUint16(2),
225
- seq: t.getUint32(4),
226
- ack: t.getUint32(8),
227
- flags: t.getUint8(13),
228
- payload: e.slice(n)
229
- };
230
- }
231
- function g(e, t) {
232
- return `${e}:${t}`;
233
- }
234
- class Z {
235
- constructor(t, n, r, a) {
236
- this.webSocketUrl = t, this.session = n, this.deviceHello = r, this.log = a;
237
- }
238
- socket;
239
- streams = /* @__PURE__ */ new Map();
240
- frameQueue = Promise.resolve();
241
- closed = !1;
242
- pairRecordWaiter;
243
- async connect() {
244
- const t = new WebSocket(this.webSocketUrl);
245
- t.binaryType = "arraybuffer", this.socket = t, t.onclose = () => {
246
- this.closed = !0, this.log("Relay socket closed"), this.frameQueue.finally(() => {
247
- this.pairRecordWaiter && (this.pairRecordWaiter.reject(new Error("Relay socket closed")), this.pairRecordWaiter = void 0);
248
- });
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
- }, await this.send({
255
- type: s.DeviceHello,
256
- requestId: 0,
257
- streamId: 0,
258
- payload: l(this.deviceHello)
259
- }), this.log("Connected WebSocket relay");
260
- }
261
- async startPairing() {
262
- const t = new Promise((n, r) => {
263
- this.pairRecordWaiter = { resolve: n, reject: r };
264
- });
265
- return await this.send({
266
- type: s.StartPairing,
267
- requestId: 0,
268
- streamId: 0,
269
- payload: l({})
270
- }), this.log("Pairing requested"), t;
271
- }
272
- async startInstall(t, n) {
273
- await this.send({
274
- type: s.StartInstall,
275
- requestId: 0,
276
- streamId: 0,
277
- payload: l({ ...t, ...n })
278
- }), this.log("Installation requested");
279
- }
280
- close() {
281
- this.closed = !0, this.socket?.close();
282
- }
283
- enqueueFrame(t) {
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
- });
287
- }
288
- async handleFrame(t) {
289
- switch (t.type) {
290
- case s.OpenStream:
291
- await this.handleOpenStream(
292
- t.requestId,
293
- t.streamId,
294
- y(t.payload).port
295
- );
296
- break;
297
- case s.StreamData: {
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
- break;
302
- }
303
- case s.StreamClose:
304
- this.streams.delete(t.streamId);
305
- break;
306
- case s.InstallProgress:
307
- this.log(te(y(t.payload).message));
308
- break;
309
- case s.Error:
310
- this.handleError(t.payload);
311
- break;
312
- case s.PairRecordReady:
313
- this.handlePairRecordReady(y(t.payload));
314
- break;
315
- case s.Ping:
316
- await this.send({
317
- type: s.Pong,
318
- requestId: t.requestId,
319
- streamId: 0,
320
- payload: new Uint8Array()
321
- });
322
- break;
323
- }
324
- }
325
- handleError(t) {
326
- const n = ee(t);
327
- this.log("Server error", n), this.pairRecordWaiter && (this.pairRecordWaiter.reject(new Error(n)), this.pairRecordWaiter = void 0);
328
- }
329
- handlePairRecordReady(t) {
330
- this.log("Pair record received", t.udid), this.pairRecordWaiter?.resolve(t), this.pairRecordWaiter = void 0;
331
- }
332
- async handleOpenStream(t, n, r) {
333
- try {
334
- const a = await J(this.session, r);
335
- this.streams.set(n, a), await this.send({
336
- type: s.OpenResult,
337
- requestId: t,
338
- streamId: n,
339
- payload: l({ ok: !0 })
340
- }), this.log(`Opened device stream ${n} to port ${r}`), this.pumpDeviceToServer(n, a);
341
- } catch (a) {
342
- this.log(
343
- `Open device stream ${n} failed`,
344
- a instanceof Error ? a.message : String(a)
345
- ), await this.send({
346
- type: s.OpenResult,
347
- requestId: t,
348
- streamId: n,
349
- payload: l({
350
- ok: !1,
351
- error: a instanceof Error ? a.message : String(a)
352
- })
353
- });
354
- }
355
- }
356
- async pumpDeviceToServer(t, n) {
357
- try {
358
- for (; ; ) {
359
- const r = await Q(n);
360
- if (this.closed) return;
361
- await this.send({
362
- type: s.StreamData,
363
- requestId: 0,
364
- streamId: t,
365
- payload: r
366
- });
367
- }
368
- } catch (r) {
369
- this.log(`Device stream ${t} closed`, r instanceof Error ? r.message : String(r)), await this.send({
370
- type: s.StreamClose,
371
- requestId: 0,
372
- streamId: t,
373
- payload: l({
374
- reason: r instanceof Error ? r.message : String(r)
375
- })
376
- });
377
- }
378
- }
379
- async send(t) {
380
- if (!this.closed) {
381
- if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {
382
- this.closed = !0;
383
- return;
384
- }
385
- this.socket.send(V(t));
386
- }
387
- }
388
- }
389
- function ee(e) {
390
- const t = new TextDecoder().decode(e);
391
- try {
392
- const n = JSON.parse(t);
393
- return S(n.error ?? t);
394
- } catch {
395
- return S(t);
396
- }
397
- }
398
- function S(e) {
399
- return e.replace(/libimobiledevice/g, "").trim();
400
- }
401
- function te(e) {
402
- const t = "install status: ";
403
- if (!e.startsWith(t))
404
- return e;
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
- }
410
- const a = p(n, "Status") ?? "Unknown", i = p(n, "PercentComplete");
411
- return `Install progress: ${i ? `${i}% ` : ""}${a}`;
412
- }
413
- function p(e, t) {
414
- const r = new RegExp(
415
- `<key>\\s*${ne(
416
- t
417
- )}\\s*</key>\\s*<(?:string|integer|real)>([\\s\\S]*?)</(?:string|integer|real)>`
418
- ).exec(e);
419
- return r ? re(r[1].trim()) : void 0;
420
- }
421
- function ne(e) {
422
- return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
423
- }
424
- function re(e) {
425
- return e.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&amp;/g, "&");
426
- }
427
- async function ae({ log: e }) {
428
- e("Selecting USB device");
429
- const t = await C(), n = ue(t);
430
- return e(
431
- "Selected USB device",
432
- `${t.manufacturerName ?? ""} ${t.productName ?? ""} ${t.serialNumber ?? ""}`.trim()
433
- ), n;
434
- }
435
- async function ie({
436
- registryApiUrl: e,
437
- token: t,
438
- organizationId: n,
439
- log: r,
440
- target: a
441
- }) {
442
- const i = N(e, t, n);
443
- let o;
444
- try {
445
- o = await $(i, a, r);
446
- const c = await o.startPairing();
447
- return { relay: o, pairRecord: c, target: a };
448
- } catch (c) {
449
- throw o?.close(), c;
450
- }
451
- }
452
- async function oe({
453
- registryApiUrl: e,
454
- token: t,
455
- organizationId: n,
456
- log: r,
457
- target: a,
458
- pairRecord: i,
459
- installSource: o
460
- }) {
461
- const c = N(e, t, n);
462
- let u;
463
- try {
464
- return u = await $(c, a, r), await u.startInstall(i, o), u;
465
- } catch (D) {
466
- throw u?.close(), D;
467
- }
468
- }
469
- async function se(e, t) {
470
- if (e) {
471
- if (e.session && (P(e.session), e.session = void 0), e.claimedInterfaceNumber !== void 0)
472
- try {
473
- await e.device.releaseInterface(e.claimedInterfaceNumber), t?.("Released usbmux interface");
474
- } catch (n) {
475
- t?.("USB interface release failed", w(n));
476
- } finally {
477
- e.claimedInterfaceNumber = void 0;
478
- }
479
- if (e.device.opened)
480
- try {
481
- await e.device.close(), t?.("Closed USB device");
482
- } catch (n) {
483
- t?.("USB device close failed", w(n));
484
- }
485
- }
486
- }
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
- }
492
- async function ce(e, t) {
493
- if (!e.session)
494
- try {
495
- e.candidate = await le(e, t), e.session = await H(e.device, e.candidate), t("Created usbmux session");
496
- } catch (n) {
497
- throw await se(e, t), n;
498
- }
499
- }
500
- function ue(e) {
501
- return {
502
- device: e,
503
- candidate: de(e),
504
- hello: {
505
- serialNumber: e.serialNumber,
506
- productName: e.productName,
507
- manufacturerName: e.manufacturerName,
508
- productId: e.productId,
509
- vendorId: e.vendorId
510
- }
511
- };
512
- }
513
- async function le(e, t) {
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
- try {
520
- return e.device.opened || await e.device.open(), t(
521
- "Claiming usbmux interface",
522
- `configuration ${i.configurationValue}, interface ${i.interfaceNumber}, alternate ${i.alternateSetting}, attempt ${o}`
523
- ), await T(e.device, i), e.claimedInterfaceNumber = i.interfaceNumber, t(
524
- "Claimed usbmux interface",
525
- `configuration ${i.configurationValue}, interface ${i.interfaceNumber}`
526
- ), i;
527
- } catch (c) {
528
- r = c, t(
529
- "USB interface claim failed",
530
- `configuration ${i.configurationValue}, interface ${i.interfaceNumber}: ${w(c)}`
531
- ), await fe(e), await pe(250);
532
- }
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
- );
537
- }
538
- function de(e) {
539
- const t = q(e)[0];
540
- if (!t) throw new Error("No Apple usbmux interface found.");
541
- return t;
542
- }
543
- function q(e) {
544
- const t = L(e), n = e.configuration?.configurationValue;
545
- return [
546
- ...t.filter((r) => r.configurationValue === n),
547
- ...t.filter((r) => r.configurationValue !== n)
548
- ];
549
- }
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();
553
- }
554
- async function fe(e) {
555
- if (e.claimedInterfaceNumber !== void 0) {
556
- try {
557
- await e.device.releaseInterface(e.claimedInterfaceNumber);
558
- } catch {
559
- }
560
- e.claimedInterfaceNumber = void 0;
561
- }
562
- if (e.device.opened)
563
- try {
564
- await e.device.close();
565
- } catch {
566
- }
567
- }
568
- function pe(e) {
569
- return new Promise((t) => setTimeout(t, e));
570
- }
571
- async function he(e = {}) {
572
- return ae({ log: e.log ?? b });
573
- }
574
- async function ye(e) {
575
- return ie({ ...e, log: e.log ?? b });
576
- }
577
- async function me(e) {
578
- return oe({ ...e, log: e.log ?? b });
579
- }
580
- function b() {
581
- }
582
- export {
583
- Z as RelayClient,
584
- se as closeDeviceRelayTarget,
585
- N as deviceRelayWebSocketUrl,
586
- Ue as getPairRecord,
587
- Se as normalizeUDID,
588
- ye as pairDevice,
589
- ve as putPairRecord,
590
- he as requestUSBAccess,
591
- me as startDeviceInstall,
592
- oe as startDeviceInstallRelay,
593
- ie as startDevicePairingRelay
594
- };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),i=require("./index.cjs"),w=require("../errors-BSkqS7U-.js"),D=require("../browser-storage-DLxIqZk5.js");function C({apiUrl:o,token:d,organizationId:v,log:h=T}){const[e,b]=r.useState(),[l,g]=r.useState(),[R,u]=r.useState(),[S,n]=r.useState(),[P,f]=r.useState(!1),y=r.useRef(void 0),p=r.useRef(void 0),t=r.useRef(h);t.current=h;const c=r.useCallback(async()=>{y.current?.close(),y.current=void 0,await i.closeDeviceRelayTarget(p.current,t.current)},[]);r.useEffect(()=>{p.current=e},[e]),r.useEffect(()=>()=>{c()},[c]);const q=r.useCallback(async()=>{u("usb"),n(void 0),f(!1);let a;try{await c(),a=await i.requestUSBAccess({log:t.current});const s=await D.getPairRecord(a.hello.serialNumber);return b(a),g(s),t.current(s?"Pair record found":"No pair record found",a.hello.serialNumber),a}catch(s){await i.closeDeviceRelayTarget(a,t.current),b(void 0),g(void 0),n(w.errorMessage(s));return}finally{u(void 0)}},[c]),m=r.useCallback(async()=>{if(!o||!e)throw new Error("Select a USB device before pairing.");u("pair"),n(void 0),f(!1);try{await c();const a=await i.pairDevice({registryApiUrl:o,token:d,organizationId:v,log:t.current,target:e}),s=await D.putPairRecord(a.pairRecord,{productName:e.hello.productName});return a.relay.close(),await i.closeDeviceRelayTarget(e,t.current),g(s),f(!1),t.current("Device paired","The pair record was stored locally in this browser."),s}catch(a){await i.closeDeviceRelayTarget(e,t.current),f(!0),n(w.errorMessage(a));return}finally{u(void 0)}},[o,c,e,v,d]),A=r.useCallback(async a=>{if(!o||!e||!l)throw new Error("Select and pair a USB device before starting installation.");u("install"),n(void 0);try{return await c(),y.current=await i.startDeviceInstall({registryApiUrl:o,token:d,organizationId:v,log:t.current,target:e,pairRecord:l,installSource:a}),t.current("Device install started","Installation will continue through the connected iPhone."),y.current}catch(s){await i.closeDeviceRelayTarget(e,t.current),n(w.errorMessage(s));return}finally{u(void 0)}},[o,c,e,v,l,d]),B=r.useCallback(()=>{c(),t.current("Device relay stopped")},[c]);return{device:e,pairRecord:l,busyAction:R,error:S,pairConfirmationRequired:P,hasPairRecord:!!l,canPair:!!o&&!R&&!!e,canInstall:!!o&&!R&&!!e&&!!l,requestUSBAccess:q,pairBrowser:m,startInstallation:A,stopRelay:B,clearError:()=>n(void 0)}}function T(){}exports.useDeviceInstallRelay=C;
@@ -1,24 +0,0 @@
1
- import { DeviceInstallLog, DeviceRelayTarget, InstallSource, RelayClient, StoredPairRecord } from './index';
2
- export type DeviceInstallRelayBusyAction = 'usb' | 'pair' | 'install';
3
- export type UseDeviceInstallRelayOptions = {
4
- apiUrl?: string;
5
- token?: string;
6
- organizationId?: string;
7
- log?: DeviceInstallLog;
8
- };
9
- export type UseDeviceInstallRelayResult = {
10
- device?: DeviceRelayTarget;
11
- pairRecord?: StoredPairRecord;
12
- busyAction?: DeviceInstallRelayBusyAction;
13
- error?: string;
14
- pairConfirmationRequired: boolean;
15
- hasPairRecord: boolean;
16
- canPair: boolean;
17
- canInstall: boolean;
18
- requestUSBAccess: () => Promise<DeviceRelayTarget | undefined>;
19
- pairBrowser: () => Promise<StoredPairRecord | undefined>;
20
- startInstallation: (installSource: InstallSource) => Promise<RelayClient | undefined>;
21
- stopRelay: () => void;
22
- clearError: () => void;
23
- };
24
- export declare function useDeviceInstallRelay({ apiUrl, token, organizationId, log, }: UseDeviceInstallRelayOptions): UseDeviceInstallRelayResult;