@limrun/ui 0.14.0-rc.4 → 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 -100
  12. package/dist/app-store-relay/index.js +0 -484
  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 -59
  18. package/dist/apple-credentials/index.js +0 -227
  19. package/dist/browser-storage-BnO-Ma-e.mjs +0 -219
  20. package/dist/browser-storage-DLxIqZk5.js +0 -1
  21. package/dist/client-D1drDXxE.js +0 -1
  22. package/dist/client-DSuNtWDv.mjs +0 -184
  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 -212
  28. package/dist/core/device-install/apple/relay.d.ts +0 -40
  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 -101
  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 -591
  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-B_DefBEp.mjs +0 -239
  73. package/dist/provisioning-BlQMccX_.js +0 -1
  74. package/src/app-store-relay/index.test.ts +0 -60
  75. package/src/app-store-relay/index.ts +0 -511
  76. package/src/app-store-relay/react.ts +0 -131
  77. package/src/apple-credentials/index.test.ts +0 -158
  78. package/src/apple-credentials/index.ts +0 -241
  79. package/src/core/device-install/apple/client.ts +0 -143
  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 -84
  84. package/src/core/device-install/apple/provisioning.ts +0 -380
  85. package/src/core/device-install/apple/relay.ts +0 -182
  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 -234
  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 -298
  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,591 +0,0 @@
1
- import { e as y } 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, f = 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(f + e.payload.byteLength), r = new DataView(t.buffer);
19
- return r.setUint8(0, v), r.setUint8(1, e.type), r.setUint8(2, 0), r.setUint8(3, 0), r.setUint32(4, e.requestId), r.setUint32(8, e.streamId), r.setUint32(12, e.payload.byteLength), t.set(e.payload, f), t;
20
- }
21
- function A(e) {
22
- if (e.byteLength < f)
23
- throw new Error(`Relay frame too short: ${e.byteLength}`);
24
- const t = new DataView(e.buffer, e.byteOffset, e.byteLength), r = t.getUint8(0);
25
- if (r !== v)
26
- throw new Error(`Unsupported relay protocol version ${r}`);
27
- const n = t.getUint32(12);
28
- if (e.byteLength !== f + n)
29
- throw new Error(
30
- `Relay frame length mismatch: got ${e.byteLength}, expected ${f + n}`
31
- );
32
- return {
33
- type: t.getUint8(1),
34
- requestId: t.getUint32(4),
35
- streamId: t.getUint32(8),
36
- payload: e.slice(f)
37
- };
38
- }
39
- function l(e) {
40
- return new TextEncoder().encode(JSON.stringify(e));
41
- }
42
- function h(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 = [], r = e.configuration?.configurationValue, n = e.configurations.find(
52
- (a) => a.configurationValue === r
53
- );
54
- n && t.push(...U(n));
55
- for (const a of e.configurations)
56
- a.configurationValue !== r && t.push(...U(a));
57
- return t;
58
- }
59
- function U(e) {
60
- const t = [];
61
- for (const r of e.interfaces)
62
- for (const n of r.alternates)
63
- n.interfaceClass === 255 && n.interfaceSubclass === 254 && n.interfaceProtocol === 2 && t.push({
64
- configurationValue: e.configurationValue,
65
- interfaceNumber: r.interfaceNumber,
66
- alternateSetting: n.alternateSetting,
67
- endpoints: n.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 W(e) {
75
- const t = e.endpoints.find(
76
- (n) => n.direction === "out" && n.type === "bulk"
77
- ), r = e.endpoints.find(
78
- (n) => n.direction === "in" && n.type === "bulk"
79
- );
80
- if (!t || !r)
81
- throw new Error("Could not find usbmux bulk endpoints.");
82
- return { outEndpoint: t, inEndpoint: r };
83
- }
84
- async function R(e, t, r) {
85
- const n = await e.transferOut(t.endpointNumber, r);
86
- if (n.status !== "ok")
87
- throw new Error(`USB transferOut failed: ${n.status}`);
88
- r.byteLength % t.packetSize === 0 && await e.transferOut(t.endpointNumber, new Uint8Array());
89
- }
90
- async function B(e, t, r = 16384) {
91
- const n = await e.transferIn(t.endpointNumber, r);
92
- if (n.status !== "ok" || !n.data)
93
- throw new Error(`USB transferIn failed: ${n.status}`);
94
- return new Uint8Array(n.data.buffer, n.data.byteOffset, n.data.byteLength);
95
- }
96
- const E = 0, F = 2, k = 6, _ = 4277009102, m = 2, M = 4, d = 16, j = 49152;
97
- async function H(e, t) {
98
- const { inEndpoint: r, outEndpoint: n } = W(t), a = new Uint8Array(12), i = new DataView(a.buffer);
99
- i.setUint32(0, 2), i.setUint32(4, 0), i.setUint32(8, 0), await R(e, n, O(E, a));
100
- const o = await P(e, r, 1), c = new DataView(o.payload.buffer, o.payload.byteOffset).getUint32(0), u = {
101
- device: e,
102
- candidate: t,
103
- inEndpoint: r,
104
- outEndpoint: n,
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 x(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 r, n;
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
- r = i, n = o;
129
- }),
130
- resolveOpened: r,
131
- rejectOpened: n
132
- };
133
- return e.streams.set(g(t, a.sport), a), await w(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 w(e, d, 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 I(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 w(e, t, r) {
157
- const n = new Uint8Array(20 + r.byteLength), a = new DataView(n.buffer);
158
- a.setUint16(0, e.sport), a.setUint16(2, e.dport), a.setUint32(4, e.seq), a.setUint32(8, e.ack), a.setUint8(12, 80), a.setUint8(13, t), a.setUint16(14, 512), n.set(r, 20), await x(e.session, k, n);
159
- }
160
- async function x(e, t, r) {
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 n = e.muxVersion >= 2 ? z(t, r, e.txSeq++, e.rxSeq) : O(t, r);
166
- await R(e.device, e.outEndpoint, n);
167
- }), e.writeChain;
168
- }
169
- async function Y(e) {
170
- try {
171
- for (; ; ) {
172
- if (e.closed) return;
173
- const t = await P(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 r = X(t.payload), n = e.streams.get(g(r.sport, r.dport));
178
- if (n) {
179
- if (r.flags & M) {
180
- for (n.error = new Error(`Device reset stream ${n.dport}`), n.rejectOpened(n.error); n.waiters.length > 0; )
181
- n.waiters.shift()(new Uint8Array());
182
- e.streams.delete(g(n.dport, n.sport));
183
- continue;
184
- }
185
- if ((r.flags & (m | d)) === (m | d)) {
186
- n.seq += 1, n.ack = r.seq + 1, await w(n, d, new Uint8Array()), n.resolveOpened();
187
- continue;
188
- }
189
- r.payload.byteLength !== 0 && (n.ack = r.seq + r.payload.byteLength, await w(n, d, new Uint8Array()), n.waiters.length > 0 ? n.waiters.shift()(r.payload) : n.queue.push(r.payload));
190
- }
191
- }
192
- } catch {
193
- e.closed || I(e);
194
- }
195
- }
196
- async function P(e, t, r) {
197
- for (; ; ) {
198
- const n = await B(e, t), a = K(n, r);
199
- if (!(r === 1 && a.protocol !== E))
200
- return a;
201
- }
202
- }
203
- function O(e, t) {
204
- const r = new Uint8Array(8 + t.byteLength), n = new DataView(r.buffer);
205
- return n.setUint32(0, e), n.setUint32(4, r.byteLength), r.set(t, 8), r;
206
- }
207
- function z(e, t, r, n) {
208
- const a = new Uint8Array(16 + t.byteLength), i = new DataView(a.buffer);
209
- return i.setUint32(0, e), i.setUint32(4, a.byteLength), i.setUint32(8, _), i.setUint16(12, r), i.setUint16(14, n), a.set(t, 16), a;
210
- }
211
- function K(e, t) {
212
- const r = new DataView(e.buffer, e.byteOffset, e.byteLength), n = r.getUint32(0), a = r.getUint32(4), i = t >= 2 ? 16 : 8;
213
- return {
214
- protocol: n,
215
- length: a,
216
- rxSeq: t >= 2 ? r.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), r = (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(r)
229
- };
230
- }
231
- function g(e, t) {
232
- return `${e}:${t}`;
233
- }
234
- class Z {
235
- constructor(t, r, n, a) {
236
- this.webSocketUrl = t, this.session = r, this.deviceHello = n, 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((r, n) => {
250
- t.onopen = () => r(), t.onerror = () => n(new Error("WebSocket connection failed"));
251
- }), t.onmessage = (r) => {
252
- const n = r.data instanceof ArrayBuffer ? new Uint8Array(r.data) : new Uint8Array();
253
- this.enqueueFrame(n);
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((r, n) => {
263
- this.pairRecordWaiter = { resolve: r, reject: n };
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, r) {
273
- await this.send({
274
- type: s.StartInstall,
275
- requestId: 0,
276
- streamId: 0,
277
- payload: l({ ...t, ...r })
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((r) => {
285
- this.log("Relay frame handling failed", r instanceof Error ? r.message : String(r));
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
- h(t.payload).port
295
- );
296
- break;
297
- case s.StreamData: {
298
- const r = this.streams.get(t.streamId);
299
- if (!r) throw new Error(`Unknown stream ${t.streamId}`);
300
- await G(r, t.payload);
301
- break;
302
- }
303
- case s.StreamClose:
304
- this.streams.delete(t.streamId);
305
- break;
306
- case s.InstallProgress:
307
- this.log(te(h(t.payload).message));
308
- break;
309
- case s.Error:
310
- this.handleError(t.payload);
311
- break;
312
- case s.PairRecordReady:
313
- this.handlePairRecordReady(h(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 r = ee(t);
327
- this.log("Server error", r), this.pairRecordWaiter && (this.pairRecordWaiter.reject(new Error(r)), 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, r, n) {
333
- try {
334
- const a = await J(this.session, n);
335
- this.streams.set(r, a), await this.send({
336
- type: s.OpenResult,
337
- requestId: t,
338
- streamId: r,
339
- payload: l({ ok: !0 })
340
- }), this.log(`Opened device stream ${r} to port ${n}`), this.pumpDeviceToServer(r, a);
341
- } catch (a) {
342
- this.log(
343
- `Open device stream ${r} failed`,
344
- a instanceof Error ? a.message : String(a)
345
- ), await this.send({
346
- type: s.OpenResult,
347
- requestId: t,
348
- streamId: r,
349
- payload: l({
350
- ok: !1,
351
- error: a instanceof Error ? a.message : String(a)
352
- })
353
- });
354
- }
355
- }
356
- async pumpDeviceToServer(t, r) {
357
- try {
358
- for (; ; ) {
359
- const n = await Q(r);
360
- if (this.closed) return;
361
- await this.send({
362
- type: s.StreamData,
363
- requestId: 0,
364
- streamId: t,
365
- payload: n
366
- });
367
- }
368
- } catch (n) {
369
- this.log(`Device stream ${t} closed`, n instanceof Error ? n.message : String(n)), await this.send({
370
- type: s.StreamClose,
371
- requestId: 0,
372
- streamId: t,
373
- payload: l({
374
- reason: n instanceof Error ? n.message : String(n)
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 r = JSON.parse(t);
393
- return S(r.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 r = e.slice(t.length), n = p(r, "Error");
406
- if (n) {
407
- const o = p(r, "ErrorDescription");
408
- return `Install error: ${n}${o ? ` — ${o}` : ""}`;
409
- }
410
- const a = p(r, "Status") ?? "Unknown", i = p(r, "PercentComplete");
411
- return `Install progress: ${i ? `${i}% ` : ""}${a}`;
412
- }
413
- function p(e, t) {
414
- const n = new RegExp(
415
- `<key>\\s*${re(
416
- t
417
- )}\\s*</key>\\s*<(?:string|integer|real)>([\\s\\S]*?)</(?:string|integer|real)>`
418
- ).exec(e);
419
- return n ? ne(n[1].trim()) : void 0;
420
- }
421
- function re(e) {
422
- return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
423
- }
424
- function ne(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(), r = ue(t);
430
- return e(
431
- "Selected USB device",
432
- `${t.manufacturerName ?? ""} ${t.productName ?? ""} ${t.serialNumber ?? ""}`.trim()
433
- ), r;
434
- }
435
- async function ie({
436
- registryApiUrl: e,
437
- token: t,
438
- organizationId: r,
439
- log: n,
440
- target: a
441
- }) {
442
- const i = N(e, t, r);
443
- let o;
444
- try {
445
- o = await $(i, a, n);
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: r,
456
- log: n,
457
- target: a,
458
- pairRecord: i,
459
- installSource: o
460
- }) {
461
- const c = N(e, t, r);
462
- let u;
463
- try {
464
- return u = await $(c, a, n), 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 && (I(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 (r) {
475
- t?.("USB interface release failed", y(r));
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 (r) {
483
- t?.("USB device close failed", y(r));
484
- }
485
- }
486
- }
487
- async function $(e, t, r) {
488
- await ce(t, r);
489
- const n = new Z(e, t.session, t.hello, r);
490
- return await n.connect(), n;
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 (r) {
497
- throw await se(e, t), r;
498
- }
499
- }
500
- function ue(e) {
501
- return {
502
- device: e,
503
- candidate: fe(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 r = q(e.device);
515
- if (r.length === 0) throw new Error("No Apple usbmux interface found.");
516
- let n;
517
- for (const a of r)
518
- for (const i of [1, 2])
519
- try {
520
- return e.device.opened || await e.device.open(), t(
521
- "Claiming usbmux interface",
522
- `configuration ${a.configurationValue}, interface ${a.interfaceNumber}, alternate ${a.alternateSetting}, attempt ${i}`
523
- ), await T(e.device, a), e.claimedInterfaceNumber = a.interfaceNumber, t(
524
- "Claimed usbmux interface",
525
- `configuration ${a.configurationValue}, interface ${a.interfaceNumber}`
526
- ), a;
527
- } catch (o) {
528
- n = o, t(
529
- "USB interface claim failed",
530
- `configuration ${a.configurationValue}, interface ${a.interfaceNumber}: ${y(o)}`
531
- ), await de(e), await pe(250);
532
- }
533
- throw n instanceof Error ? n : new Error("Unable to claim any Apple usbmux interface.");
534
- }
535
- function fe(e) {
536
- const t = q(e)[0];
537
- if (!t) throw new Error("No Apple usbmux interface found.");
538
- return t;
539
- }
540
- function q(e) {
541
- const t = L(e), r = e.configuration?.configurationValue;
542
- return [
543
- ...t.filter((n) => n.configurationValue === r),
544
- ...t.filter((n) => n.configurationValue !== r)
545
- ];
546
- }
547
- function N(e, t, r) {
548
- const n = new URL(e);
549
- return n.protocol = n.protocol === "https:" ? "wss:" : "ws:", n.pathname = `${n.pathname.replace(/\/$/, "")}/ios/device/ws`, t && n.searchParams.set("token", t), r && n.searchParams.set("organization", r), n.toString();
550
- }
551
- async function de(e) {
552
- if (e.claimedInterfaceNumber !== void 0) {
553
- try {
554
- await e.device.releaseInterface(e.claimedInterfaceNumber);
555
- } catch {
556
- }
557
- e.claimedInterfaceNumber = void 0;
558
- }
559
- if (e.device.opened)
560
- try {
561
- await e.device.close();
562
- } catch {
563
- }
564
- }
565
- function pe(e) {
566
- return new Promise((t) => setTimeout(t, e));
567
- }
568
- async function he(e = {}) {
569
- return ae({ log: e.log ?? b });
570
- }
571
- async function ye(e) {
572
- return ie({ ...e, log: e.log ?? b });
573
- }
574
- async function me(e) {
575
- return oe({ ...e, log: e.log ?? b });
576
- }
577
- function b() {
578
- }
579
- export {
580
- Z as RelayClient,
581
- se as closeDeviceRelayTarget,
582
- N as deviceRelayWebSocketUrl,
583
- Ue as getPairRecord,
584
- Se as normalizeUDID,
585
- ye as pairDevice,
586
- ve as putPairRecord,
587
- he as requestUSBAccess,
588
- me as startDeviceInstall,
589
- oe as startDeviceInstallRelay,
590
- ie as startDevicePairingRelay
591
- };
@@ -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;