@limrun/ui 0.13.3-rc.1 → 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 (50) hide show
  1. package/dist/app-store-relay/index.cjs +4 -4
  2. package/dist/app-store-relay/index.js +175 -119
  3. package/dist/app-store-relay/react.cjs +1 -1
  4. package/dist/app-store-relay/react.js +2 -2
  5. package/dist/{browser-storage-BJ__DGJ6.mjs → browser-storage-Cx9eW-bm.mjs} +48 -45
  6. package/dist/browser-storage-jJaIht4K.js +1 -0
  7. package/dist/{client-CnbCWvCs.js → client-ASLtHFLh.js} +1 -1
  8. package/dist/{client-Bk1N3XIF.mjs → client-CGdh8yoJ.mjs} +33 -27
  9. package/dist/core/device-install/apple/provisioning.d.ts +4 -4
  10. package/dist/device-build/index.cjs +1 -1
  11. package/dist/device-build/index.js +5 -5
  12. package/dist/device-build/react.cjs +1 -1
  13. package/dist/device-build/react.js +15 -13
  14. package/dist/device-install/demo/demo.d.ts +0 -0
  15. package/dist/device-install/index.cjs +1 -1
  16. package/dist/device-install/index.d.ts +1 -1
  17. package/dist/device-install/index.js +134 -121
  18. package/dist/device-install/react.cjs +1 -1
  19. package/dist/device-install/react.js +55 -50
  20. package/dist/{index-BXg7HdIs.mjs → index-DFdCvi2_.mjs} +3 -7
  21. package/dist/limbuild-client-CgEncrgx.js +1 -0
  22. package/dist/{limbuild-client-CFJhYsRx.mjs → limbuild-client-D7U7w342.mjs} +4 -2
  23. package/dist/{provisioning-CdseoMJQ.mjs → provisioning-DKbkBO-p.mjs} +11 -11
  24. package/dist/{provisioning-D2ZZQeyX.js → provisioning-Va0PH4Kk.js} +1 -1
  25. package/package.json +1 -1
  26. package/src/app-store-relay/index.test.ts +1 -5
  27. package/src/app-store-relay/index.ts +109 -42
  28. package/src/app-store-relay/react.ts +6 -2
  29. package/src/core/device-install/apple/client.ts +29 -22
  30. package/src/core/device-install/apple/crypto.ts +9 -6
  31. package/src/core/device-install/apple/gsa-srp.ts +3 -7
  32. package/src/core/device-install/apple/provisioning.ts +16 -18
  33. package/src/core/device-install/apple/relay.ts +5 -1
  34. package/src/core/device-install/operations/limbuild-client.ts +8 -1
  35. package/src/core/device-install/operations/operations.ts +3 -1
  36. package/src/core/device-install/operations/relay-client.ts +57 -27
  37. package/src/core/device-install/operations/usbmux.ts +3 -3
  38. package/src/core/device-install/operations/webusb.ts +9 -4
  39. package/src/core/device-install/storage/browser-storage.ts +20 -6
  40. package/src/core/device-install/types.ts +1 -7
  41. package/src/device-build/react.ts +4 -1
  42. package/src/device-install/README.md +423 -0
  43. package/src/device-install/demo/demo.css +493 -0
  44. package/src/device-install/demo/demo.tsx +1069 -0
  45. package/src/device-install/demo/index.html +12 -0
  46. package/src/device-install/index.ts +7 -7
  47. package/src/device-install/react.ts +26 -17
  48. package/src/index.ts +1 -1
  49. package/dist/browser-storage-C1jQLXat.js +0 -1
  50. package/dist/limbuild-client-C_CMNLYV.js +0 -1
@@ -1,5 +1,5 @@
1
1
  const v = "limbuild-device-pairing";
2
- const d = "pairRecords", m = "limbuild-device-signing";
2
+ const d = "pairRecords", w = "limbuild-device-signing";
3
3
  const c = "signingAssets";
4
4
  function l(e) {
5
5
  return (e ?? "").replace(/-/g, "").replace(/[^a-fA-F0-9]/g, "");
@@ -10,8 +10,8 @@ function f(e) {
10
10
  async function R(e) {
11
11
  const n = l(e);
12
12
  if (!n) return;
13
- const r = await g(v, 1, d, "udid");
14
- return p(
13
+ const r = await p(v, 1, d, "udid");
14
+ return g(
15
15
  r.transaction(d, "readonly").objectStore(d).get(n)
16
16
  );
17
17
  }
@@ -23,8 +23,8 @@ async function G(e, n = {}) {
23
23
  udid: r,
24
24
  productName: n.productName,
25
25
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
26
- }, i = await g(v, 1, d, "udid");
27
- return await p(
26
+ }, i = await p(v, 1, d, "udid");
27
+ return await g(
28
28
  i.transaction(d, "readwrite").objectStore(d).put(t)
29
29
  ), t;
30
30
  }
@@ -35,41 +35,41 @@ async function O({
35
35
  }) {
36
36
  const t = f(n);
37
37
  if (!t) return;
38
- const i = l(e), s = await S(I("bundle", t, r));
38
+ const i = l(e), s = await S(D("bundle", t, r));
39
39
  if (s) return s;
40
40
  if (i) {
41
- const o = await S(I(i, t, r));
41
+ const o = await S(D(i, t, r));
42
42
  if (o) return o;
43
43
  }
44
- return (await B(t, r))[0];
44
+ return (await h(t, r))[0];
45
45
  }
46
- async function V(e = "development") {
47
- return (await w()).filter((r) => (r.signingMode ?? "development") === e).sort(
48
- (r, t) => new Date(t.updatedAt).getTime() - new Date(r.updatedAt).getTime()
49
- )[0];
46
+ async function T(e = "development") {
47
+ return (await m()).filter((r) => (r.signingMode ?? "development") === e).sort((r, t) => new Date(t.updatedAt).getTime() - new Date(r.updatedAt).getTime())[0];
50
48
  }
51
- async function z(e, n = "development") {
52
- return (await w()).filter((t) => !t.certificateID || !t.certificateP12Base64 || (t.signingMode ?? "development") !== n ? !1 : !e || !t.teamID || t.teamID === e).sort((t, i) => new Date(i.updatedAt).getTime() - new Date(t.updatedAt).getTime())[0];
49
+ async function V(e, n = "development") {
50
+ return (await m()).filter((t) => !t.certificateID || !t.certificateP12Base64 || (t.signingMode ?? "development") !== n ? !1 : !e || !t.teamID || t.teamID === e).sort((t, i) => new Date(i.updatedAt).getTime() - new Date(t.updatedAt).getTime())[0];
53
51
  }
54
- async function T(e) {
52
+ async function z(e) {
55
53
  const n = f(e.bundleID);
56
54
  if (!n)
57
55
  throw new Error("Cannot store signing assets without a bundle ID.");
58
- const r = l(e.deviceUDID), t = e.signingMode ?? "development", i = I("bundle", n, t), s = {
56
+ const r = l(e.deviceUDID), t = e.signingMode ?? "development", i = D("bundle", n, t), s = {
59
57
  ...e,
60
58
  id: i,
61
59
  deviceUDID: r || void 0,
62
60
  signingMode: t,
63
61
  bundleID: n,
64
62
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
65
- }, a = await g(m, 1, c, "id");
66
- return await p(
63
+ }, a = await p(w, 1, c, "id");
64
+ return await g(
67
65
  a.transaction(c, "readwrite").objectStore(c).put(s)
68
66
  ), s;
69
67
  }
70
- async function B(e, n = "development") {
68
+ async function h(e, n = "development") {
71
69
  const r = f(e);
72
- return r ? (await w()).filter((i) => i.bundleID === r && (i.signingMode ?? "development") === n) : [];
70
+ return r ? (await m()).filter(
71
+ (i) => i.bundleID === r && (i.signingMode ?? "development") === n
72
+ ) : [];
73
73
  }
74
74
  function U(e, n) {
75
75
  const r = l(n);
@@ -84,56 +84,59 @@ function j(e, n) {
84
84
  return r.startsWith(i);
85
85
  }
86
86
  async function M(e) {
87
- return P(new Uint8Array(await e.arrayBuffer()));
87
+ return E(new Uint8Array(await e.arrayBuffer()));
88
88
  }
89
89
  function C(e) {
90
90
  const n = atob(e), r = new Uint8Array(n.length);
91
91
  for (let t = 0; t < n.length; t += 1)
92
92
  r[t] = n.charCodeAt(t);
93
- return P(r);
93
+ return E(r);
94
94
  }
95
- function P(e) {
95
+ function E(e) {
96
96
  const n = new TextDecoder("latin1").decode(e), r = n.indexOf("<?xml"), t = n.indexOf("</plist>");
97
97
  if (r < 0 || t < r)
98
98
  throw new Error("Provisioning profile plist not found.");
99
- const i = n.slice(r, t + 8), s = new DOMParser().parseFromString(i, "application/xml");
99
+ const i = n.slice(r, t + 8);
100
+ if (/<!ENTITY/i.test(i))
101
+ throw new Error("Provisioning profile plist contains a disallowed ENTITY declaration.");
102
+ const s = new DOMParser().parseFromString(i, "application/xml");
100
103
  if (s.querySelector("parsererror"))
101
104
  throw new Error("Provisioning profile plist could not be parsed.");
102
105
  const a = s.querySelector("plist > dict");
103
106
  if (!a)
104
107
  throw new Error("Provisioning profile plist dictionary not found.");
105
108
  const o = A(a);
106
- if (!N(o))
109
+ if (!b(o))
107
110
  throw new Error("Provisioning profile plist has an unexpected shape.");
108
- const D = N(o.Entitlements) ? o.Entitlements : {}, y = u(D["application-identifier"]), h = E(y);
111
+ const I = b(o.Entitlements) ? o.Entitlements : {}, y = u(I["application-identifier"]), P = B(y);
109
112
  return {
110
113
  name: u(o.Name),
111
114
  uuid: u(o.UUID),
112
- teamID: u(D["com.apple.developer.team-identifier"]) ?? b(o.TeamIdentifier)[0],
115
+ teamID: u(I["com.apple.developer.team-identifier"]) ?? N(o.TeamIdentifier)[0],
113
116
  applicationIdentifier: y,
114
- bundleID: h,
115
- provisionedDevices: b(o.ProvisionedDevices),
116
- getTaskAllow: _(D["get-task-allow"]),
117
+ bundleID: P,
118
+ provisionedDevices: N(o.ProvisionedDevices),
119
+ getTaskAllow: _(I["get-task-allow"]),
117
120
  expirationDate: u(o.ExpirationDate)
118
121
  };
119
122
  }
120
123
  async function S(e) {
121
124
  if (!e) return;
122
- const n = await g(m, 1, c, "id");
123
- return p(
125
+ const n = await p(w, 1, c, "id");
126
+ return g(
124
127
  n.transaction(c, "readonly").objectStore(c).get(e)
125
128
  );
126
129
  }
127
- async function w() {
128
- const e = await g(m, 1, c, "id");
129
- return p(
130
+ async function m() {
131
+ const e = await p(w, 1, c, "id");
132
+ return g(
130
133
  e.transaction(c, "readonly").objectStore(c).getAll()
131
134
  );
132
135
  }
133
- function I(e, n, r) {
136
+ function D(e, n, r) {
134
137
  return `${r}:${e}:${n}`;
135
138
  }
136
- function E(e) {
139
+ function B(e) {
137
140
  if (!e) return;
138
141
  const n = e.indexOf(".");
139
142
  return n >= 0 ? e.slice(n + 1) : void 0;
@@ -162,16 +165,16 @@ function x(e) {
162
165
  function u(e) {
163
166
  return typeof e == "string" && e ? e : void 0;
164
167
  }
165
- function b(e) {
168
+ function N(e) {
166
169
  return Array.isArray(e) ? e.filter((n) => typeof n == "string") : [];
167
170
  }
168
171
  function _(e) {
169
172
  return typeof e == "boolean" ? e : void 0;
170
173
  }
171
- function N(e) {
174
+ function b(e) {
172
175
  return typeof e == "object" && e !== null && !Array.isArray(e);
173
176
  }
174
- function g(e, n, r, t) {
177
+ function p(e, n, r, t) {
175
178
  return new Promise((i, s) => {
176
179
  const a = indexedDB.open(e, n);
177
180
  a.onupgradeneeded = () => {
@@ -180,20 +183,20 @@ function g(e, n, r, t) {
180
183
  }, a.onsuccess = () => i(a.result), a.onerror = () => s(a.error ?? new Error("Open IndexedDB failed"));
181
184
  });
182
185
  }
183
- function p(e) {
186
+ function g(e) {
184
187
  return new Promise((n, r) => {
185
188
  e.onsuccess = () => n(e.result), e.onerror = () => r(e.error ?? new Error("IndexedDB request failed"));
186
189
  });
187
190
  }
188
191
  export {
189
- T as a,
192
+ z as a,
190
193
  j as b,
191
194
  U as c,
192
- z as d,
195
+ V as d,
193
196
  O as e,
194
197
  C as f,
195
- V as g,
196
- P as h,
198
+ T as g,
199
+ E as h,
197
200
  f as i,
198
201
  R as j,
199
202
  G as k,
@@ -0,0 +1 @@
1
+ "use strict";const b="limbuild-device-pairing";const l="pairRecords",w="limbuild-device-signing";const c="signingAssets";function d(e){return(e??"").replace(/-/g,"").replace(/[^a-fA-F0-9]/g,"")}function u(e){return(e??"").trim()}async function E(e){const n=d(e);if(!n)return;const r=await g(b,1,l,"udid");return p(r.transaction(l,"readonly").objectStore(l).get(n))}async function h(e,n={}){const r=d(e.udid);if(!r)throw new Error("Cannot store pair record without a UDID.");const t={...e,udid:r,productName:n.productName,updatedAt:new Date().toISOString()},i=await g(b,1,l,"udid");return await p(i.transaction(l,"readwrite").objectStore(l).put(t)),t}async function x({deviceUDID:e,bundleID:n,signingMode:r="development"}){const t=u(n);if(!t)return;const i=d(e),s=await v(I("bundle",t,r));if(s)return s;if(i){const o=await v(I(i,t,r));if(o)return o}return(await O(t,r))[0]}async function _(e="development"){return(await A()).filter(r=>(r.signingMode??"development")===e).sort((r,t)=>new Date(t.updatedAt).getTime()-new Date(r.updatedAt).getTime())[0]}async function R(e,n="development"){return(await A()).filter(t=>!t.certificateID||!t.certificateP12Base64||(t.signingMode??"development")!==n?!1:!e||!t.teamID||t.teamID===e).sort((t,i)=>new Date(i.updatedAt).getTime()-new Date(t.updatedAt).getTime())[0]}async function G(e){const n=u(e.bundleID);if(!n)throw new Error("Cannot store signing assets without a bundle ID.");const r=d(e.deviceUDID),t=e.signingMode??"development",i=I("bundle",n,t),s={...e,id:i,deviceUDID:r||void 0,signingMode:t,bundleID:n,updatedAt:new Date().toISOString()},a=await g(w,1,c,"id");return await p(a.transaction(c,"readwrite").objectStore(c).put(s)),s}async function O(e,n="development"){const r=u(e);return r?(await A()).filter(i=>i.bundleID===r&&(i.signingMode??"development")===n):[]}function T(e,n){const r=d(n);return!!r&&e.provisionedDevices.some(t=>d(t)===r)}function z(e,n){const r=u(n),t=u(e.bundleID);if(!r||!t)return!1;if(t===r||t==="*")return!0;if(!t.endsWith(".*"))return!1;const i=t.slice(0,-1);return r.startsWith(i)}async function U(e){return m(new Uint8Array(await e.arrayBuffer()))}function V(e){const n=atob(e),r=new Uint8Array(n.length);for(let t=0;t<n.length;t+=1)r[t]=n.charCodeAt(t);return m(r)}function m(e){const n=new TextDecoder("latin1").decode(e),r=n.indexOf("<?xml"),t=n.indexOf("</plist>");if(r<0||t<r)throw new Error("Provisioning profile plist not found.");const i=n.slice(r,t+8);if(/<!ENTITY/i.test(i))throw new Error("Provisioning profile plist contains a disallowed ENTITY declaration.");const s=new DOMParser().parseFromString(i,"application/xml");if(s.querySelector("parsererror"))throw new Error("Provisioning profile plist could not be parsed.");const a=s.querySelector("plist > dict");if(!a)throw new Error("Provisioning profile plist dictionary not found.");const o=S(a);if(!P(o))throw new Error("Provisioning profile plist has an unexpected shape.");const D=P(o.Entitlements)?o.Entitlements:{},y=f(D["application-identifier"]),B=C(y);return{name:f(o.Name),uuid:f(o.UUID),teamID:f(D["com.apple.developer.team-identifier"])??N(o.TeamIdentifier)[0],applicationIdentifier:y,bundleID:B,provisionedDevices:N(o.ProvisionedDevices),getTaskAllow:j(D["get-task-allow"]),expirationDate:f(o.ExpirationDate)}}async function v(e){if(!e)return;const n=await g(w,1,c,"id");return p(n.transaction(c,"readonly").objectStore(c).get(e))}async function A(){const e=await g(w,1,c,"id");return p(e.transaction(c,"readonly").objectStore(c).getAll())}function I(e,n,r){return`${r}:${e}:${n}`}function C(e){if(!e)return;const n=e.indexOf(".");return n>=0?e.slice(n+1):void 0}function S(e){switch(e.tagName){case"dict":return M(e);case"array":return Array.from(e.children).map(S);case"string":case"date":return e.textContent??"";default:return e.textContent??""}}function M(e){const n={},r=Array.from(e.children);for(let t=0;t<r.length;t+=2){const i=r[t],s=r[t+1];!i||i.tagName!=="key"||!s||(n[i.textContent??""]=S(s))}return n}function f(e){return typeof e=="string"&&e?e:void 0}function N(e){return Array.isArray(e)?e.filter(n=>typeof n=="string"):[]}function j(e){return typeof e=="boolean"?e:void 0}function P(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function g(e,n,r,t){return new Promise((i,s)=>{const a=indexedDB.open(e,n);a.onupgradeneeded=()=>{const o=a.result;o.objectStoreNames.contains(r)||o.createObjectStore(r,{keyPath:t})},a.onsuccess=()=>i(a.result),a.onerror=()=>s(a.error??new Error("Open IndexedDB failed"))})}function p(e){return new Promise((n,r)=>{e.onsuccess=()=>n(e.result),e.onerror=()=>r(e.error??new Error("IndexedDB request failed"))})}exports.getLatestSigningAssets=_;exports.getLatestSigningAssetsWithCertificate=R;exports.getPairRecord=E;exports.getSigningAssets=x;exports.normalizeBundleID=u;exports.normalizeUDID=d;exports.parseProvisioningProfile=U;exports.parseProvisioningProfileBase64=V;exports.parseProvisioningProfileBytes=m;exports.profileContainsDevice=T;exports.profileMatchesBundleID=z;exports.putPairRecord=h;exports.putSigningAssets=G;
@@ -1 +1 @@
1
- "use strict";const E=require("./index-CMeQfhYy.js");async function P(e,s){const r=await fetch(c(e,"/apple/auth/session",s),{method:"POST",headers:R(s)});if(!r.ok)throw new Error(`Apple relay session failed: HTTP ${r.status} ${await r.text()}`);return await r.json()}async function y(e,s,r){const t=await fetch(c(e,"/apple/auth/session/delete",r),{method:"POST",headers:u(r),body:JSON.stringify({appleSessionId:s})});if(!t.ok)throw new Error(`Apple relay session delete failed: HTTP ${t.status} ${await t.text()}`)}async function g(e,s,r,t){return N(e,"/apple/auth/srp/init",s,r,t)}async function m(e,s,r,t){return N(e,"/apple/auth/srp/complete",s,r,t)}async function S(e,s,r){const t=await fetch(c(e,"/apple/auth/2fa/trigger",r),{method:"POST",headers:u(r),body:JSON.stringify({appleSessionId:s})});if(!t.ok)throw new Error(`Apple 2FA trigger failed: HTTP ${t.status} ${await t.text()}`);return await t.json()}async function $(e,s,r,t="sms",o){const a=await fetch(c(e,"/apple/auth/2fa/phone/trigger",o),{method:"POST",headers:u(o),body:JSON.stringify({appleSessionId:s,phoneNumberId:r,mode:t})});if(!a.ok)throw new Error(`Apple phone 2FA trigger failed: HTTP ${a.status} ${await a.text()}`);return await a.json()}async function x(e,s,r,t){const o=await fetch(c(e,"/apple/auth/2fa",t),{method:"POST",headers:u(t),body:JSON.stringify({appleSessionId:s,code:r})});if(!o.ok)throw new Error(`Apple 2FA proxy failed: HTTP ${o.status} ${await o.text()}`);return await o.json()}async function A(e,s,r,t,o="sms",a){const n=await fetch(c(e,"/apple/auth/2fa/phone",a),{method:"POST",headers:u(a),body:JSON.stringify({appleSessionId:s,phoneNumberId:r,mode:o,code:t})});if(!n.ok)throw new Error(`Apple phone 2FA proxy failed: HTTP ${n.status} ${await n.text()}`);return await n.json()}async function O(e,s,r){const t=await fetch(c(e,"/apple/auth/finalize",r),{method:"POST",headers:u(r),body:JSON.stringify({appleSessionId:s})});if(!t.ok)throw new Error(`Apple session finalization failed: HTTP ${t.status} ${await t.text()}`);return await t.json()}async function H(e,s,r,t){const o=await fetch(c(e,"/apple/provisioning",t),{method:"POST",headers:u(t),body:JSON.stringify({appleSessionId:s,...r})});if(!o.ok)throw new Error(`Apple provisioning proxy failed: HTTP ${o.status} ${await o.text()}`);return F(await o.json())}async function N(e,s,r,t,o){const a=await fetch(c(e,s,o),{method:"POST",headers:u(o),body:JSON.stringify({appleSessionId:r,payload:t})});if(!a.ok)throw new Error(`Apple proxy ${s} failed: HTTP ${a.status} ${await a.text()}`);return F(await a.json())}function F(e){if(e.body!==void 0||!e.rawBody)return e;try{return{...e,body:JSON.parse(e.rawBody)}}catch{return e}}function c(e,s,r){const t=e.replace(/\/$/,""),o=s.startsWith("/")?s:`/${s}`,a=new URL(`${t}${o}`);return r&&a.searchParams.set("token",r),a}function u(e){return{"Content-Type":"application/json",...R(e)}}function R(e){return e?{Authorization:`Bearer ${e}`}:{}}async function v({limbuildApiUrl:e,accountName:s,password:r,token:t}){const{appleSessionId:o}=await P(e,t);try{const a=new E.AppleGsaSrpClient(s),n=await g(e,o,await a.init(),t);if(n.status<200||n.status>=300)throw new Error(`Apple SRP init failed: HTTP ${n.status} ${n.rawBody??""}`.trim());if(!n.body)throw new Error("Apple SRP init response did not include a body.");const b=await a.complete(r,n.body),f=await m(e,o,{...b,rememberMe:!1,trustTokens:[]},t),T=f.status===409;let i,d={type:"trustedDevice"};if(T){i=await S(e,o,t);const p=j(i.body);if(p&&(d={type:"phone",phoneNumberId:p.id,mode:p.pushMode??"sms"}),i.status===412){if(!p)throw new Error("Apple requested phone verification but did not include a trusted phone number.");i=await $(e,o,p.id,p.pushMode??"sms",t)}if(i.status<200||i.status>=300)throw new Error(`Apple two-factor challenge failed: HTTP ${i.status} ${i.rawBody??""}`.trim())}else if(f.status<200||f.status>=300)throw new Error(`Apple SRP complete failed: HTTP ${f.status} ${f.rawBody??""}`.trim());return{appleSessionId:o,completeResponse:f,twoFactorChallengeResponse:i,requiresTwoFactor:T,finishTwoFactor:async p=>{const w=d.type==="phone"?await A(e,o,d.phoneNumberId,p,d.mode,t):await x(e,o,p,t);if(w.status<200||w.status>=300)throw new Error(`Apple two-factor code failed: HTTP ${w.status} ${w.rawBody??""}`.trim());return w},finalize:async()=>O(e,o,t),close:()=>y(e,o,t)}}catch(a){throw await y(e,o,t).catch(()=>{}),a}}function j(e){if(!l(e))return;const s=l(e.phoneNumberVerification)?e.phoneNumberVerification:void 0,r=h(s?.trustedPhoneNumber)??h(e.trustedPhoneNumber)??h(e.phoneNumber);if(!r)return;const t=r.id;if(typeof t!="number")return;const o=typeof r.pushMode=="string"?r.pushMode:typeof e.mode=="string"?e.mode:void 0;return{id:t,pushMode:o}}function h(e){return l(e)?e:void 0}function l(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}exports.createAppleRelaySession=P;exports.deleteAppleRelaySession=y;exports.fetchAppleAccountSession=O;exports.proxyPhoneTwoFactorCode=A;exports.proxyProvisioningRequest=H;exports.proxySrpComplete=m;exports.proxySrpInit=g;exports.proxyTwoFactorCode=x;exports.startBrowserOwnedAppleIDLogin=v;exports.triggerPhoneTwoFactor=$;exports.triggerTrustedDeviceTwoFactor=S;
1
+ "use strict";const E=require("./index-CMeQfhYy.js");async function P(e,s){const r=await fetch(p(e,"/apple/auth/session",s),{method:"POST",headers:R(s)});if(!r.ok)throw new Error(`Apple relay session failed: HTTP ${r.status} ${await r.text()}`);return await r.json()}async function y(e,s,r){const t=await fetch(p(e,"/apple/auth/session/delete",r),{method:"POST",headers:u(r),body:JSON.stringify({appleSessionId:s})});if(!t.ok)throw new Error(`Apple relay session delete failed: HTTP ${t.status} ${await t.text()}`)}async function g(e,s,r,t){return N(e,"/apple/auth/srp/init",s,r,t)}async function m(e,s,r,t){return N(e,"/apple/auth/srp/complete",s,r,t)}async function S(e,s,r){const t=await fetch(p(e,"/apple/auth/2fa/trigger",r),{method:"POST",headers:u(r),body:JSON.stringify({appleSessionId:s})});if(!t.ok)throw new Error(`Apple 2FA trigger failed: HTTP ${t.status} ${await t.text()}`);return await t.json()}async function $(e,s,r,t="sms",o){const a=await fetch(p(e,"/apple/auth/2fa/phone/trigger",o),{method:"POST",headers:u(o),body:JSON.stringify({appleSessionId:s,phoneNumberId:r,mode:t})});if(!a.ok)throw new Error(`Apple phone 2FA trigger failed: HTTP ${a.status} ${await a.text()}`);return await a.json()}async function x(e,s,r,t){const o=await fetch(p(e,"/apple/auth/2fa",t),{method:"POST",headers:u(t),body:JSON.stringify({appleSessionId:s,code:r})});if(!o.ok)throw new Error(`Apple 2FA proxy failed: HTTP ${o.status} ${await o.text()}`);return await o.json()}async function A(e,s,r,t,o="sms",a){const n=await fetch(p(e,"/apple/auth/2fa/phone",a),{method:"POST",headers:u(a),body:JSON.stringify({appleSessionId:s,phoneNumberId:r,mode:o,code:t})});if(!n.ok)throw new Error(`Apple phone 2FA proxy failed: HTTP ${n.status} ${await n.text()}`);return await n.json()}async function O(e,s,r){const t=await fetch(p(e,"/apple/auth/finalize",r),{method:"POST",headers:u(r),body:JSON.stringify({appleSessionId:s})});if(!t.ok)throw new Error(`Apple session finalization failed: HTTP ${t.status} ${await t.text()}`);return await t.json()}async function H(e,s,r,t){const o=await fetch(p(e,"/apple/provisioning",t),{method:"POST",headers:u(t),body:JSON.stringify({appleSessionId:s,...r})});if(!o.ok)throw new Error(`Apple provisioning proxy failed: HTTP ${o.status} ${await o.text()}`);return F(await o.json())}async function N(e,s,r,t,o){const a=await fetch(p(e,s,o),{method:"POST",headers:u(o),body:JSON.stringify({appleSessionId:r,payload:t})});if(!a.ok)throw new Error(`Apple proxy ${s} failed: HTTP ${a.status} ${await a.text()}`);return F(await a.json())}function F(e){if(e.body!==void 0||!e.rawBody)return e;try{return{...e,body:JSON.parse(e.rawBody)}}catch{return e}}function p(e,s,r){const t=e.replace(/\/$/,""),o=s.startsWith("/")?s:`/${s}`,a=new URL(`${t}${o}`);return r&&a.searchParams.set("token",r),a}function u(e){return{"Content-Type":"application/json",...R(e)}}function R(e){return e?{Authorization:`Bearer ${e}`}:{}}async function v({limbuildApiUrl:e,accountName:s,password:r,token:t}){const{appleSessionId:o}=await P(e,t);try{const a=new E.AppleGsaSrpClient(s),n=await g(e,o,await a.init(),t);if(n.status<200||n.status>=300)throw new Error(`Apple SRP init failed: HTTP ${n.status} ${n.rawBody??""}`.trim());if(!n.body)throw new Error("Apple SRP init response did not include a body.");const b=await a.complete(r,n.body),f=await m(e,o,{...b,rememberMe:!1,trustTokens:[]},t),T=f.status===409;let i,d={type:"trustedDevice"};if(T){i=await S(e,o,t);const c=j(i.body);if(i.status===412){if(!c)throw new Error("Apple requested phone verification but did not include a trusted phone number.");d={type:"phone",phoneNumberId:c.id,mode:c.pushMode??"sms"},i=await $(e,o,c.id,c.pushMode??"sms",t)}if(i.status<200||i.status>=300)throw new Error(`Apple two-factor challenge failed: HTTP ${i.status} ${i.rawBody??""}`.trim())}else if(f.status<200||f.status>=300)throw new Error(`Apple SRP complete failed: HTTP ${f.status} ${f.rawBody??""}`.trim());return{appleSessionId:o,completeResponse:f,twoFactorChallengeResponse:i,requiresTwoFactor:T,finishTwoFactor:async c=>{const w=d.type==="phone"?await A(e,o,d.phoneNumberId,c,d.mode,t):await x(e,o,c,t);if(w.status<200||w.status>=300)throw new Error(`Apple two-factor code failed: HTTP ${w.status} ${w.rawBody??""}`.trim());return w},finalize:async()=>O(e,o,t),close:()=>y(e,o,t)}}catch(a){throw await y(e,o,t).catch(()=>{}),a}}function j(e){if(!l(e))return;const s=l(e.phoneNumberVerification)?e.phoneNumberVerification:void 0,r=h(s?.trustedPhoneNumber)??h(e.trustedPhoneNumber)??h(e.phoneNumber);if(!r)return;const t=r.id;if(typeof t!="number")return;const o=typeof r.pushMode=="string"?r.pushMode:typeof e.mode=="string"?e.mode:void 0;return{id:t,pushMode:o}}function h(e){return l(e)?e:void 0}function l(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}exports.createAppleRelaySession=P;exports.deleteAppleRelaySession=y;exports.fetchAppleAccountSession=O;exports.proxyPhoneTwoFactorCode=A;exports.proxyProvisioningRequest=H;exports.proxySrpComplete=m;exports.proxySrpInit=g;exports.proxyTwoFactorCode=x;exports.startBrowserOwnedAppleIDLogin=v;exports.triggerPhoneTwoFactor=$;exports.triggerTrustedDeviceTwoFactor=S;
@@ -1,6 +1,6 @@
1
- import { A as S } from "./index-BXg7HdIs.mjs";
1
+ import { A as S } from "./index-DFdCvi2_.mjs";
2
2
  async function x(t, a) {
3
- const r = await fetch(c(t, "/apple/auth/session", a), {
3
+ const r = await fetch(p(t, "/apple/auth/session", a), {
4
4
  method: "POST",
5
5
  headers: $(a)
6
6
  });
@@ -9,7 +9,7 @@ async function x(t, a) {
9
9
  return await r.json();
10
10
  }
11
11
  async function T(t, a, r) {
12
- const e = await fetch(c(t, "/apple/auth/session/delete", r), {
12
+ const e = await fetch(p(t, "/apple/auth/session/delete", r), {
13
13
  method: "POST",
14
14
  headers: u(r),
15
15
  body: JSON.stringify({ appleSessionId: a })
@@ -30,7 +30,7 @@ async function O(t, a, r, e) {
30
30
  return m(t, "/apple/auth/srp/complete", a, r, e);
31
31
  }
32
32
  async function N(t, a, r) {
33
- const e = await fetch(c(t, "/apple/auth/2fa/trigger", r), {
33
+ const e = await fetch(p(t, "/apple/auth/2fa/trigger", r), {
34
34
  method: "POST",
35
35
  headers: u(r),
36
36
  body: JSON.stringify({ appleSessionId: a })
@@ -40,7 +40,7 @@ async function N(t, a, r) {
40
40
  return await e.json();
41
41
  }
42
42
  async function b(t, a, r, e = "sms", o) {
43
- const s = await fetch(c(t, "/apple/auth/2fa/phone/trigger", o), {
43
+ const s = await fetch(p(t, "/apple/auth/2fa/phone/trigger", o), {
44
44
  method: "POST",
45
45
  headers: u(o),
46
46
  body: JSON.stringify({ appleSessionId: a, phoneNumberId: r, mode: e })
@@ -50,7 +50,7 @@ async function b(t, a, r, e = "sms", o) {
50
50
  return await s.json();
51
51
  }
52
52
  async function E(t, a, r, e) {
53
- const o = await fetch(c(t, "/apple/auth/2fa", e), {
53
+ const o = await fetch(p(t, "/apple/auth/2fa", e), {
54
54
  method: "POST",
55
55
  headers: u(e),
56
56
  body: JSON.stringify({ appleSessionId: a, code: r })
@@ -60,7 +60,7 @@ async function E(t, a, r, e) {
60
60
  return await o.json();
61
61
  }
62
62
  async function H(t, a, r, e, o = "sms", s) {
63
- const n = await fetch(c(t, "/apple/auth/2fa/phone", s), {
63
+ const n = await fetch(p(t, "/apple/auth/2fa/phone", s), {
64
64
  method: "POST",
65
65
  headers: u(s),
66
66
  body: JSON.stringify({ appleSessionId: a, phoneNumberId: r, mode: o, code: e })
@@ -70,7 +70,7 @@ async function H(t, a, r, e, o = "sms", s) {
70
70
  return await n.json();
71
71
  }
72
72
  async function F(t, a, r) {
73
- const e = await fetch(c(t, "/apple/auth/finalize", r), {
73
+ const e = await fetch(p(t, "/apple/auth/finalize", r), {
74
74
  method: "POST",
75
75
  headers: u(r),
76
76
  body: JSON.stringify({ appleSessionId: a })
@@ -80,7 +80,7 @@ async function F(t, a, r) {
80
80
  return await e.json();
81
81
  }
82
82
  async function j(t, a, r, e) {
83
- const o = await fetch(c(t, "/apple/provisioning", e), {
83
+ const o = await fetch(p(t, "/apple/provisioning", e), {
84
84
  method: "POST",
85
85
  headers: u(e),
86
86
  body: JSON.stringify({ appleSessionId: a, ...r })
@@ -90,7 +90,7 @@ async function j(t, a, r, e) {
90
90
  return P(await o.json());
91
91
  }
92
92
  async function m(t, a, r, e, o) {
93
- const s = await fetch(c(t, a, o), {
93
+ const s = await fetch(p(t, a, o), {
94
94
  method: "POST",
95
95
  headers: u(o),
96
96
  body: JSON.stringify({ appleSessionId: r, payload: e })
@@ -111,7 +111,7 @@ function P(t) {
111
111
  return t;
112
112
  }
113
113
  }
114
- function c(t, a, r) {
114
+ function p(t, a, r) {
115
115
  const e = t.replace(/\/$/, ""), o = a.startsWith("/") ? a : `/${a}`, s = new URL(`${e}${o}`);
116
116
  return r && s.searchParams.set("token", r), s;
117
117
  }
@@ -134,7 +134,9 @@ async function J({
134
134
  try {
135
135
  const s = new S(a), n = await A(t, o, await s.init(), e);
136
136
  if (n.status < 200 || n.status >= 300)
137
- throw new Error(`Apple SRP init failed: HTTP ${n.status} ${n.rawBody ?? ""}`.trim());
137
+ throw new Error(
138
+ `Apple SRP init failed: HTTP ${n.status} ${n.rawBody ?? ""}`.trim()
139
+ );
138
140
  if (!n.body)
139
141
  throw new Error("Apple SRP init response did not include a body.");
140
142
  const g = await s.complete(r, n.body), f = await O(
@@ -150,19 +152,19 @@ async function J({
150
152
  let i, d = { type: "trustedDevice" };
151
153
  if (l) {
152
154
  i = await N(t, o, e);
153
- const p = R(i.body);
154
- if (p && (d = {
155
- type: "phone",
156
- phoneNumberId: p.id,
157
- mode: p.pushMode ?? "sms"
158
- }), i.status === 412) {
159
- if (!p)
155
+ const c = R(i.body);
156
+ if (i.status === 412) {
157
+ if (!c)
160
158
  throw new Error("Apple requested phone verification but did not include a trusted phone number.");
161
- i = await b(
159
+ d = {
160
+ type: "phone",
161
+ phoneNumberId: c.id,
162
+ mode: c.pushMode ?? "sms"
163
+ }, i = await b(
162
164
  t,
163
165
  o,
164
- p.id,
165
- p.pushMode ?? "sms",
166
+ c.id,
167
+ c.pushMode ?? "sms",
166
168
  e
167
169
  );
168
170
  }
@@ -171,23 +173,27 @@ async function J({
171
173
  `Apple two-factor challenge failed: HTTP ${i.status} ${i.rawBody ?? ""}`.trim()
172
174
  );
173
175
  } else if (f.status < 200 || f.status >= 300)
174
- throw new Error(`Apple SRP complete failed: HTTP ${f.status} ${f.rawBody ?? ""}`.trim());
176
+ throw new Error(
177
+ `Apple SRP complete failed: HTTP ${f.status} ${f.rawBody ?? ""}`.trim()
178
+ );
175
179
  return {
176
180
  appleSessionId: o,
177
181
  completeResponse: f,
178
182
  twoFactorChallengeResponse: i,
179
183
  requiresTwoFactor: l,
180
- finishTwoFactor: async (p) => {
184
+ finishTwoFactor: async (c) => {
181
185
  const h = d.type === "phone" ? await H(
182
186
  t,
183
187
  o,
184
188
  d.phoneNumberId,
185
- p,
189
+ c,
186
190
  d.mode,
187
191
  e
188
- ) : await E(t, o, p, e);
192
+ ) : await E(t, o, c, e);
189
193
  if (h.status < 200 || h.status >= 300)
190
- throw new Error(`Apple two-factor code failed: HTTP ${h.status} ${h.rawBody ?? ""}`.trim());
194
+ throw new Error(
195
+ `Apple two-factor code failed: HTTP ${h.status} ${h.rawBody ?? ""}`.trim()
196
+ );
191
197
  return h;
192
198
  },
193
199
  finalize: async () => F(t, o, e),
@@ -64,12 +64,12 @@ export type PutAppleGeneratedSigningAssetsInput = {
64
64
  profile: ProvisioningProfileInfo;
65
65
  };
66
66
  export declare function listTeamsRequest(): AppleProvisioningRequest;
67
- export declare function findBundleIDRequest({ bundleID, teamID }: Pick<AppleProvisioningContext, 'bundleID' | 'teamID'>): {
67
+ export declare function findBundleIDRequest({ bundleID, teamID, }: Pick<AppleProvisioningContext, 'bundleID' | 'teamID'>): {
68
68
  method: "POST";
69
69
  path: string;
70
70
  payload: Record<string, unknown>;
71
71
  };
72
- export declare function findDeviceRequest({ deviceUDID, teamID }: Pick<AppleProvisioningContext, 'deviceUDID' | 'teamID'>): {
72
+ export declare function findDeviceRequest({ deviceUDID, teamID, }: Pick<AppleProvisioningContext, 'deviceUDID' | 'teamID'>): {
73
73
  method: "POST";
74
74
  path: string;
75
75
  payload: Record<string, unknown>;
@@ -119,7 +119,7 @@ export declare function createBundleIDRequest({ bundleID, teamID, name, }: Pick<
119
119
  type: string;
120
120
  };
121
121
  };
122
- export declare function submitDevelopmentCSRRequest({ csrPEM, teamID, }: {
122
+ export declare function submitDevelopmentCSRRequest({ csrPEM, teamID }: {
123
123
  csrPEM: string;
124
124
  teamID?: string;
125
125
  }): {
@@ -131,7 +131,7 @@ export declare function submitDevelopmentCSRRequest({ csrPEM, teamID, }: {
131
131
  csrContent: string;
132
132
  };
133
133
  };
134
- export declare function submitDistributionCSRRequest({ csrPEM, teamID, }: {
134
+ export declare function submitDistributionCSRRequest({ csrPEM, teamID }: {
135
135
  csrPEM: string;
136
136
  teamID?: string;
137
137
  }): {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../limbuild-client-C_CMNLYV.js");require("../index-CMeQfhYy.js");const c=require("../provisioning-D2ZZQeyX.js"),i=require("../browser-storage-C1jQLXat.js");async function v({certificateFile:t,provisioningProfileFile:e,certificatePassword:n,bundleId:s,deviceUDID:r,teamId:d,signingMode:f="development",certificateId:p}){const[u,A,o]=await Promise.all([l(t),l(e),i.parseProvisioningProfile(e)]);return g({profile:o,bundleId:s,deviceUDID:r,signingMode:f}),i.putSigningAssets({bundleID:s??o.bundleID??o.applicationIdentifier??e.name,deviceUDID:r,teamID:d??o.teamID,signingMode:f,certificateID:p,certificateP12Base64:u,certificateFileName:t.name,certificatePassword:n||void 0,provisioningProfileBase64:A,profileFileName:e.name,profile:o})}function S(t,e={}){g({profile:t.profile,bundleId:e.bundleId,deviceUDID:e.deviceUDID,signingMode:e.signingMode??t.signingMode})}function g({profile:t,bundleId:e,deviceUDID:n,signingMode:s}){if(e&&!i.profileMatchesBundleID(t,e))throw new Error(`Provisioning profile does not match bundle ID ${e}.`);if(n&&!i.profileContainsDevice(t,n))throw new Error("Provisioning profile does not include the selected iPhone.");if(s==="adhoc"&&t.getTaskAllow)throw new Error("Ad Hoc mode requires an Ad Hoc provisioning profile, not a development profile.")}async function l(t){const e=await t.arrayBuffer();let n="";const s=new Uint8Array(e);for(const r of s)n+=String.fromCharCode(r);return btoa(n)}exports.fetchLimbuildInfo=a.fetchLimbuildInfo;exports.getIOSOTAInstall=a.getIOSOTAInstall;exports.startSignedDeviceBuild=a.startSignedDeviceBuild;exports.watchBuildLogEvents=a.watchBuildLogEvents;exports.getReusableAppleSigningAssets=c.getReusableAppleSigningAssets;exports.putAppleGeneratedSigningAssets=c.putAppleGeneratedSigningAssets;exports.getLatestSigningAssets=i.getLatestSigningAssets;exports.getLatestSigningAssetsWithCertificate=i.getLatestSigningAssetsWithCertificate;exports.getSigningAssets=i.getSigningAssets;exports.parseProvisioningProfile=i.parseProvisioningProfile;exports.parseProvisioningProfileBase64=i.parseProvisioningProfileBase64;exports.parseProvisioningProfileBytes=i.parseProvisioningProfileBytes;exports.profileContainsDevice=i.profileContainsDevice;exports.profileMatchesBundleID=i.profileMatchesBundleID;exports.putSigningAssets=i.putSigningAssets;exports.fileToBase64=l;exports.importSigningAssetsFromFiles=v;exports.validateProvisioningProfileForInstall=g;exports.validateSigningAssetsForInstall=S;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../limbuild-client-CgEncrgx.js");require("../index-CMeQfhYy.js");const c=require("../provisioning-Va0PH4Kk.js"),i=require("../browser-storage-jJaIht4K.js");async function v({certificateFile:t,provisioningProfileFile:e,certificatePassword:n,bundleId:s,deviceUDID:r,teamId:d,signingMode:f="development",certificateId:p}){const[u,A,o]=await Promise.all([l(t),l(e),i.parseProvisioningProfile(e)]);return g({profile:o,bundleId:s,deviceUDID:r,signingMode:f}),i.putSigningAssets({bundleID:s??o.bundleID??o.applicationIdentifier??e.name,deviceUDID:r,teamID:d??o.teamID,signingMode:f,certificateID:p,certificateP12Base64:u,certificateFileName:t.name,certificatePassword:n||void 0,provisioningProfileBase64:A,profileFileName:e.name,profile:o})}function S(t,e={}){g({profile:t.profile,bundleId:e.bundleId,deviceUDID:e.deviceUDID,signingMode:e.signingMode??t.signingMode})}function g({profile:t,bundleId:e,deviceUDID:n,signingMode:s}){if(e&&!i.profileMatchesBundleID(t,e))throw new Error(`Provisioning profile does not match bundle ID ${e}.`);if(n&&!i.profileContainsDevice(t,n))throw new Error("Provisioning profile does not include the selected iPhone.");if(s==="adhoc"&&t.getTaskAllow)throw new Error("Ad Hoc mode requires an Ad Hoc provisioning profile, not a development profile.")}async function l(t){const e=await t.arrayBuffer();let n="";const s=new Uint8Array(e);for(const r of s)n+=String.fromCharCode(r);return btoa(n)}exports.fetchLimbuildInfo=a.fetchLimbuildInfo;exports.getIOSOTAInstall=a.getIOSOTAInstall;exports.startSignedDeviceBuild=a.startSignedDeviceBuild;exports.watchBuildLogEvents=a.watchBuildLogEvents;exports.getReusableAppleSigningAssets=c.getReusableAppleSigningAssets;exports.putAppleGeneratedSigningAssets=c.putAppleGeneratedSigningAssets;exports.getLatestSigningAssets=i.getLatestSigningAssets;exports.getLatestSigningAssetsWithCertificate=i.getLatestSigningAssetsWithCertificate;exports.getSigningAssets=i.getSigningAssets;exports.parseProvisioningProfile=i.parseProvisioningProfile;exports.parseProvisioningProfileBase64=i.parseProvisioningProfileBase64;exports.parseProvisioningProfileBytes=i.parseProvisioningProfileBytes;exports.profileContainsDevice=i.profileContainsDevice;exports.profileMatchesBundleID=i.profileMatchesBundleID;exports.putSigningAssets=i.putSigningAssets;exports.fileToBase64=l;exports.importSigningAssetsFromFiles=v;exports.validateProvisioningProfileForInstall=g;exports.validateSigningAssetsForInstall=S;
@@ -1,8 +1,8 @@
1
- import { f as b, g as B, s as D, w as y } from "../limbuild-client-CFJhYsRx.mjs";
2
- import "../index-BXg7HdIs.mjs";
3
- import { o as C, p as E } from "../provisioning-CdseoMJQ.mjs";
4
- import { p as d, a as m, b as u, c as A } from "../browser-storage-BJ__DGJ6.mjs";
5
- import { g as M, d as T, e as F, f as H, h as N } from "../browser-storage-BJ__DGJ6.mjs";
1
+ import { f as b, g as B, s as D, w as y } from "../limbuild-client-D7U7w342.mjs";
2
+ import "../index-DFdCvi2_.mjs";
3
+ import { o as C, p as E } from "../provisioning-DKbkBO-p.mjs";
4
+ import { p as d, a as m, b as u, c as A } from "../browser-storage-Cx9eW-bm.mjs";
5
+ import { g as M, d as T, e as F, f as H, h as N } from "../browser-storage-Cx9eW-bm.mjs";
6
6
  async function w({
7
7
  certificateFile: i,
8
8
  provisioningProfileFile: e,
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),f=require("../limbuild-client-C_CMNLYV.js");require("../index-CMeQfhYy.js");function P({apiUrl:e,token:o,signingAssets:g,loadOTAInstall:I=!1}){const[b,n]=t.useState("idle"),[w,d]=t.useState([]),[B,a]=t.useState(),[h,l]=t.useState(),[x,c]=t.useState(),i=t.useRef(void 0);t.useEffect(()=>()=>{i.current?.(),i.current=void 0},[]);const E=t.useCallback(()=>{i.current?.(),i.current=void 0,n("idle"),d([]),a(void 0),l(void 0),c(void 0)},[]),m=t.useCallback(async(q={})=>{if(!e)throw new Error("apiUrl is required to start a device build.");const u=q.signingAssets??g;if(!u)throw new Error("Signing assets are required to start a device build.");i.current?.(),n("queued"),d([]),a(void 0),l(void 0),c(void 0);try{const r=await f.startSignedDeviceBuild({limbuildApiUrl:e,token:o,certificateP12Base64:u.certificateP12Base64,certificatePassword:u.certificatePassword,provisioningProfileBase64:u.provisioningProfileBase64});if(!r.execId)throw new Error("Build request did not return an exec ID.");return a(r.execId),i.current=f.watchBuildLogEvents({limbuildApiUrl:e,token:o,execId:r.execId,onLine:s=>d(v=>[...v,s]),onStatus:s=>{n(s),s==="succeeded"&&I&&f.getIOSOTAInstall({limbuildApiUrl:e,token:o,execId:r.execId}).then(l).catch(v=>c(S(v)))},onError:s=>c(s.message)}),r.execId}catch(r){n("failed"),c(S(r));return}},[e,I,g,o]);return{status:b,logs:w,execId:B,otaInstall:h,error:x,startBuild:m,reset:E}}function S(e){return e instanceof Error?e.message:String(e)}exports.useDeviceBuild=P;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),v=require("../limbuild-client-CgEncrgx.js");require("../index-CMeQfhYy.js");function P({apiUrl:e,token:n,signingAssets:g,loadOTAInstall:I=!1}){const[b,c]=t.useState("idle"),[w,d]=t.useState([]),[B,a]=t.useState(),[h,l]=t.useState(),[x,o]=t.useState(),i=t.useRef(void 0);t.useEffect(()=>()=>{i.current?.(),i.current=void 0},[]);const E=t.useCallback(()=>{i.current?.(),i.current=void 0,c("idle"),d([]),a(void 0),l(void 0),o(void 0)},[]),m=t.useCallback(async(q={})=>{if(!e)throw new Error("apiUrl is required to start a device build.");const u=q.signingAssets??g;if(!u)throw new Error("Signing assets are required to start a device build.");i.current?.(),c("queued"),d([]),a(void 0),l(void 0),o(void 0);try{const r=await v.startSignedDeviceBuild({limbuildApiUrl:e,token:n,certificateP12Base64:u.certificateP12Base64,certificatePassword:u.certificatePassword,provisioningProfileBase64:u.provisioningProfileBase64});if(!r.execId)throw new Error("Build request did not return an exec ID.");return a(r.execId),i.current=v.watchBuildLogEvents({limbuildApiUrl:e,token:n,execId:r.execId,onLine:s=>d(f=>[...f,s]),onStatus:s=>{c(s),s==="succeeded"&&I&&v.getIOSOTAInstall({limbuildApiUrl:e,token:n,execId:r.execId}).then(l).catch(f=>o(S(f)))},onError:s=>{c("failed"),o(s.message)}}),r.execId}catch(r){c("failed"),o(S(r));return}},[e,I,g,n]);return{status:b,logs:w,execId:B,otaInstall:h,error:x,startBuild:m,reset:E}}function S(e){return e instanceof Error?e.message:String(e)}exports.useDeviceBuild=P;
@@ -1,18 +1,18 @@
1
- import { useState as c, useRef as P, useEffect as A, useCallback as I } from "react";
2
- import { s as q, w as D, g as L } from "../limbuild-client-CFJhYsRx.mjs";
3
- import "../index-BXg7HdIs.mjs";
1
+ import { useState as o, useRef as P, useEffect as A, useCallback as I } from "react";
2
+ import { s as q, w as D, g as L } from "../limbuild-client-D7U7w342.mjs";
3
+ import "../index-DFdCvi2_.mjs";
4
4
  function C({
5
5
  apiUrl: e,
6
- token: o,
6
+ token: n,
7
7
  signingAssets: v,
8
8
  loadOTAInstall: g = !1
9
9
  }) {
10
- const [m, n] = c("idle"), [x, a] = c([]), [h, u] = c(), [B, l] = c(), [E, s] = c(), r = P(void 0);
10
+ const [m, s] = o("idle"), [x, a] = o([]), [h, u] = o(), [B, l] = o(), [E, c] = o(), r = P(void 0);
11
11
  A(() => () => {
12
12
  r.current?.(), r.current = void 0;
13
13
  }, []);
14
14
  const p = I(() => {
15
- r.current?.(), r.current = void 0, n("idle"), a([]), u(void 0), l(void 0), s(void 0);
15
+ r.current?.(), r.current = void 0, s("idle"), a([]), u(void 0), l(void 0), c(void 0);
16
16
  }, []), S = I(
17
17
  async (b = {}) => {
18
18
  if (!e)
@@ -20,11 +20,11 @@ function C({
20
20
  const d = b.signingAssets ?? v;
21
21
  if (!d)
22
22
  throw new Error("Signing assets are required to start a device build.");
23
- r.current?.(), n("queued"), a([]), u(void 0), l(void 0), s(void 0);
23
+ r.current?.(), s("queued"), a([]), u(void 0), l(void 0), c(void 0);
24
24
  try {
25
25
  const t = await q({
26
26
  limbuildApiUrl: e,
27
- token: o,
27
+ token: n,
28
28
  certificateP12Base64: d.certificateP12Base64,
29
29
  certificatePassword: d.certificatePassword,
30
30
  provisioningProfileBase64: d.provisioningProfileBase64
@@ -33,20 +33,22 @@ function C({
33
33
  throw new Error("Build request did not return an exec ID.");
34
34
  return u(t.execId), r.current = D({
35
35
  limbuildApiUrl: e,
36
- token: o,
36
+ token: n,
37
37
  execId: t.execId,
38
38
  onLine: (i) => a((f) => [...f, i]),
39
39
  onStatus: (i) => {
40
- n(i), i === "succeeded" && g && L({ limbuildApiUrl: e, token: o, execId: t.execId }).then(l).catch((f) => s(w(f)));
40
+ s(i), i === "succeeded" && g && L({ limbuildApiUrl: e, token: n, execId: t.execId }).then(l).catch((f) => c(w(f)));
41
41
  },
42
- onError: (i) => s(i.message)
42
+ onError: (i) => {
43
+ s("failed"), c(i.message);
44
+ }
43
45
  }), t.execId;
44
46
  } catch (t) {
45
- n("failed"), s(w(t));
47
+ s("failed"), c(w(t));
46
48
  return;
47
49
  }
48
50
  },
49
- [e, g, v, o]
51
+ [e, g, v, n]
50
52
  );
51
53
  return {
52
54
  status: m,
File without changes
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("../browser-storage-C1jQLXat.js"),R=1,u=16,s={DeviceHello:1,OpenStream:2,OpenResult:3,StreamData:4,StreamClose:5,InstallProgress:6,Error:7,Ping:8,Pong:9,StartPairing:10,StartInstall:11,PairRecordReady:12};function L(e){const t=new Uint8Array(u+e.payload.byteLength),n=new DataView(t.buffer);return n.setUint8(0,R),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}function T(e){if(e.byteLength<u)throw new Error(`Relay frame too short: ${e.byteLength}`);const t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint8(0);if(n!==R)throw new Error(`Unsupported relay protocol version ${n}`);const r=t.getUint32(12);if(e.byteLength!==u+r)throw new Error(`Relay frame length mismatch: got ${e.byteLength}, expected ${u+r}`);return{type:t.getUint8(1),requestId:t.getUint32(4),streamId:t.getUint32(8),payload:e.slice(u)}}function c(e){return new TextEncoder().encode(JSON.stringify(e))}function w(e){return JSON.parse(new TextDecoder().decode(e))}async function W(){if(!navigator.usb)throw new Error("WebUSB is not available in this browser.");return navigator.usb.requestDevice({filters:[{vendorId:1452}]})}function B(e){const t=[],n=e.configuration?.configurationValue,r=e.configurations.find(a=>a.configurationValue===n);r&&t.push(...U(r));for(const a of e.configurations)a.configurationValue!==n&&t.push(...U(a));return t}function U(e){const t=[];for(const n of e.interfaces)for(const r of n.alternates)r.interfaceClass===255&&r.interfaceSubclass===254&&r.interfaceProtocol===2&&t.push({configurationValue:e.configurationValue,interfaceNumber:n.interfaceNumber,alternateSetting:r.alternateSetting,endpoints:r.endpoints});return t}async function F(e,t){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)}function _(e){const t=e.endpoints.find(r=>r.direction==="out"&&r.type==="bulk"),n=e.endpoints.find(r=>r.direction==="in"&&r.type==="bulk");if(!t||!n)throw new Error("Could not find usbmux bulk endpoints.");return{outEndpoint:t,inEndpoint:n}}async function k(e,t,n){const r=await e.transferOut(t.endpointNumber,n);if(r.status!=="ok")throw new Error(`USB transferOut failed: ${r.status}`);n.byteLength%t.packetSize===0&&await e.transferOut(t.endpointNumber,new Uint8Array)}async function M(e,t,n=16384){const r=await e.transferIn(t.endpointNumber,n);if(r.status!=="ok"||!r.data)throw new Error(`USB transferIn failed: ${r.status}`);return new Uint8Array(r.data.buffer,r.data.byteOffset,r.data.byteLength)}const I=0,j=2,P=6,H=4277009102,y=2,J=4,d=16,z=49152;async function G(e,t){const{inEndpoint:n,outEndpoint:r}=_(t),a=new Uint8Array(12),i=new DataView(a.buffer);i.setUint32(0,2),i.setUint32(4,0),i.setUint32(8,0),await k(e,r,D(I,a));const o=await O(e,n,1),l=new DataView(o.payload.buffer,o.payload.byteOffset).getUint32(0),p={device:e,candidate:t,inEndpoint:n,outEndpoint:r,muxVersion:l,txSeq:0,rxSeq:65535,nextSport:z,streams:new Map,writeChain:Promise.resolve(),closed:!1};return l>=2&&await x(p,j,new Uint8Array([7])),Z(p),p}async function Y(e,t){if(e.closed)throw new Error("usbmux session is closed.");let n,r;const a={session:e,sport:e.nextSport++,dport:t,seq:0,ack:0,queue:[],waiters:[],opened:new Promise((i,o)=>{n=i,r=o}),resolveOpened:n,rejectOpened:r};return e.streams.set(h(t,a.sport),a),await f(a,y,new Uint8Array),await a.opened,a}async function Q(e,t){if(e.session.closed)throw new Error("usbmux session is closed.");await f(e,d,t),e.seq+=t.byteLength}async function K(e){if(e.queue.length>0)return e.queue.shift();if(e.error)throw e.error;return new Promise(t=>{e.waiters.push(t)})}function E(e){e.closed=!0;for(const t of e.streams.values())for(t.error=new Error("usbmux session closed"),t.rejectOpened(t.error);t.waiters.length>0;)t.waiters.shift()(new Uint8Array);e.streams.clear()}async function f(e,t,n){const r=new Uint8Array(20+n.byteLength),a=new DataView(r.buffer);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,P,r)}async function x(e,t,n){if(e.closed)throw new Error("usbmux session is closed.");return e.writeChain=e.writeChain.then(async()=>{if(e.closed)return;const r=e.muxVersion>=2?X(t,n,e.txSeq++,e.rxSeq):D(t,n);await k(e.device,e.outEndpoint,r)}),e.writeChain}async function Z(e){try{for(;;){if(e.closed)return;const t=await O(e.device,e.inEndpoint,e.muxVersion);if(e.closed)return;if(t.rxSeq!==void 0&&(e.rxSeq=t.rxSeq),t.protocol!==P)continue;const n=te(t.payload),r=e.streams.get(h(n.sport,n.dport));if(r){if(n.flags&J){for(r.error=new Error(`Device reset stream ${r.dport}`),r.rejectOpened(r.error);r.waiters.length>0;)r.waiters.shift()(new Uint8Array);e.streams.delete(h(r.dport,r.sport));continue}if((n.flags&(y|d))===(y|d)){r.seq+=1,r.ack=n.seq+1,await f(r,d,new Uint8Array),r.resolveOpened();continue}n.payload.byteLength!==0&&(r.ack=n.seq+n.payload.byteLength,await f(r,d,new Uint8Array),r.waiters.length>0?r.waiters.shift()(n.payload):r.queue.push(n.payload))}}}catch{e.closed||E(e)}}async function O(e,t,n){for(;;){const r=await M(e,t),a=ee(r,n);if(!(n===1&&a.protocol!==I))return a}}function D(e,t){const n=new Uint8Array(8+t.byteLength),r=new DataView(n.buffer);return r.setUint32(0,e),r.setUint32(4,n.byteLength),n.set(t,8),n}function X(e,t,n,r){const a=new Uint8Array(16+t.byteLength),i=new DataView(a.buffer);return i.setUint32(0,e),i.setUint32(4,a.byteLength),i.setUint32(8,H),i.setUint16(12,n),i.setUint16(14,r),a.set(t,16),a}function ee(e,t){const n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=n.getUint32(0),a=n.getUint32(4),i=t>=2?16:8;return{protocol:r,length:a,rxSeq:t>=2?n.getUint16(14):void 0,payload:e.slice(i,a)}}function te(e){const t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=(t.getUint8(12)>>4)*4;return{sport:t.getUint16(0),dport:t.getUint16(2),seq:t.getUint32(4),ack:t.getUint32(8),flags:t.getUint8(13),payload:e.slice(n)}}function h(e,t){return`${e}:${t}`}class q{constructor(t,n,r,a){this.webSocketUrl=t,this.session=n,this.deviceHello=r,this.log=a}socket;streams=new Map;frameQueue=Promise.resolve();closed=!1;pairRecordWaiter;async connect(){const t=new WebSocket(this.webSocketUrl);t.binaryType="arraybuffer",this.socket=t,t.onclose=()=>{this.closed=!0,this.log("Relay socket closed"),this.pairRecordWaiter&&(this.pairRecordWaiter.reject(new Error("Relay socket closed")),this.pairRecordWaiter=void 0)},await new Promise((n,r)=>{t.onopen=()=>n(),t.onerror=()=>r(new Error("WebSocket connection failed"))}),t.onmessage=n=>{const r=n.data instanceof ArrayBuffer?new Uint8Array(n.data):new Uint8Array;this.enqueueFrame(r)},await this.send({type:s.DeviceHello,requestId:0,streamId:0,payload:c(this.deviceHello)}),this.log("Connected WebSocket relay")}async startPairing(){const t=new Promise((n,r)=>{this.pairRecordWaiter={resolve:n,reject:r}});return await this.send({type:s.StartPairing,requestId:0,streamId:0,payload:c({})}),this.log("Pairing requested"),t}async startInstall(t){await this.send({type:s.StartInstall,requestId:0,streamId:0,payload:c(t)}),this.log("Installation requested")}close(){this.closed=!0,this.socket?.close()}enqueueFrame(t){this.frameQueue=this.frameQueue.then(()=>this.handleFrame(T(t))).catch(n=>{this.log("Relay frame handling failed",n instanceof Error?n.message:String(n))})}async handleFrame(t){switch(t.type){case s.OpenStream:await this.handleOpenStream(t.requestId,t.streamId,w(t.payload).port);break;case s.StreamData:{const n=this.streams.get(t.streamId);if(!n)throw new Error(`Unknown stream ${t.streamId}`);await Q(n,t.payload);break}case s.StreamClose:this.streams.delete(t.streamId);break;case s.InstallProgress:this.log(re(w(t.payload).message));break;case s.Error:this.handleError(t.payload);break;case s.PairRecordReady:this.handlePairRecordReady(w(t.payload));break;case s.Ping:await this.send({type:s.Pong,requestId:t.requestId,streamId:0,payload:new Uint8Array});break}}handleError(t){const n=ne(t);this.log("Server error",n),this.pairRecordWaiter&&(this.pairRecordWaiter.reject(new Error(n)),this.pairRecordWaiter=void 0)}handlePairRecordReady(t){this.log("Pair record received",t.udid),this.pairRecordWaiter?.resolve(t),this.pairRecordWaiter=void 0}async handleOpenStream(t,n,r){try{const a=await Y(this.session,r);this.streams.set(n,a),await this.send({type:s.OpenResult,requestId:t,streamId:n,payload:c({ok:!0})}),this.log(`Opened device stream ${n} to port ${r}`),this.pumpDeviceToServer(n,a)}catch(a){this.log(`Open device stream ${n} failed`,a instanceof Error?a.message:String(a)),await this.send({type:s.OpenResult,requestId:t,streamId:n,payload:c({ok:!1,error:a instanceof Error?a.message:String(a)})})}}async pumpDeviceToServer(t,n){try{for(;;){const r=await K(n);if(this.closed)return;await this.send({type:s.StreamData,requestId:0,streamId:t,payload:r})}}catch(r){this.log(`Device stream ${t} closed`,r instanceof Error?r.message:String(r)),await this.send({type:s.StreamClose,requestId:0,streamId:t,payload:c({reason:r instanceof Error?r.message:String(r)})})}}async send(t){if(!this.closed){if(!this.socket||this.socket.readyState!==WebSocket.OPEN){this.closed=!0;return}this.socket.send(L(t))}}}function ne(e){const t=new TextDecoder().decode(e);try{const n=JSON.parse(t);return v(n.error??t)}catch{return v(t)}}function v(e){return e.replace(/libimobiledevice/g,"").trim()}function re(e){const t="install status: ";if(!e.startsWith(t))return e;const n=e.slice(t.length),a=new DOMParser().parseFromString(n,"application/xml").querySelector("plist > dict");if(!a)return e;const i=ae(a),o=i.Status??"Unknown";return`Install progress: ${i.PercentComplete?`${i.PercentComplete}% `:""}${o}`}function ae(e){const t={},n=Array.from(e.children);for(let r=0;r<n.length;r+=2){const a=n[r],i=n[r+1];!a||a.tagName!=="key"||!i||(t[a.textContent??""]=i.textContent??"")}return t}async function ie({log:e}){e("Selecting USB device");const t=await W(),n=se(t);return e("Selected USB device",`${t.manufacturerName??""} ${t.productName??""} ${t.serialNumber??""}`.trim()),n}async function N({limbuildApiUrl:e,token:t,log:n,target:r}){const a=b(e,t);let i;try{i=await V(a,r,n);const o=await i.startPairing();return{relay:i,pairRecord:o,target:r}}catch(o){throw i?.close(),o}}async function A({limbuildApiUrl:e,token:t,log:n,target:r,pairRecord:a}){const i=b(e,t);let o;try{return o=await V(i,r,n),await o.startInstall(a),o}catch(l){throw o?.close(),l}}async function C(e,t){if(e){if(e.session&&(E(e.session),e.session=void 0),e.claimedInterfaceNumber!==void 0)try{await e.device.releaseInterface(e.claimedInterfaceNumber),t?.("Released usbmux interface")}catch(n){t?.("USB interface release failed",m(n))}finally{e.claimedInterfaceNumber=void 0}if(e.device.opened)try{await e.device.close(),t?.("Closed USB device")}catch(n){t?.("USB device close failed",m(n))}}}async function V(e,t,n){await oe(t,n);const r=new q(e,t.session,t.hello,n);return await r.connect(),r}async function oe(e,t){if(!e.session)try{e.candidate=await ce(e,t),e.session=await G(e.device,e.candidate),t("Created usbmux session")}catch(n){throw await C(e,t),n}}function se(e){return{device:e,candidate:ue(e),hello:{serialNumber:e.serialNumber,productName:e.productName,manufacturerName:e.manufacturerName,productId:e.productId,vendorId:e.vendorId}}}async function ce(e,t){const n=$(e.device);if(n.length===0)throw new Error("No Apple usbmux interface found.");let r;for(const a of n)for(const i of[1,2])try{return e.device.opened||await e.device.open(),t("Claiming usbmux interface",`configuration ${a.configurationValue}, interface ${a.interfaceNumber}, alternate ${a.alternateSetting}, attempt ${i}`),await F(e.device,a),e.claimedInterfaceNumber=a.interfaceNumber,t("Claimed usbmux interface",`configuration ${a.configurationValue}, interface ${a.interfaceNumber}`),a}catch(o){r=o,t("USB interface claim failed",`configuration ${a.configurationValue}, interface ${a.interfaceNumber}: ${m(o)}`),await le(e),await de(250)}throw r instanceof Error?r:new Error("Unable to claim any Apple usbmux interface.")}function ue(e){const t=$(e)[0];if(!t)throw new Error("No Apple usbmux interface found.");return t}function $(e){const t=B(e),n=e.configuration?.configurationValue;return[...t.filter(r=>r.configurationValue===n),...t.filter(r=>r.configurationValue!==n)]}function b(e,t){const n=new URL(e);return n.protocol=n.protocol==="https:"?"wss:":"ws:",n.pathname=`${n.pathname.replace(/\/$/,"")}/device/ws`,t&&n.searchParams.set("token",t),n.toString()}function m(e){return e instanceof Error?e.message:String(e)}async function le(e){if(e.claimedInterfaceNumber!==void 0){try{await e.device.releaseInterface(e.claimedInterfaceNumber)}catch{}e.claimedInterfaceNumber=void 0}if(e.device.opened)try{await e.device.close()}catch{}}function de(e){return new Promise(t=>setTimeout(t,e))}async function fe(e={}){return ie({log:e.log??S})}async function pe(e){return N({...e,log:e.log??S})}async function we(e){return A({...e,log:e.log??S})}function S(){}exports.getPairRecord=g.getPairRecord;exports.normalizeUDID=g.normalizeUDID;exports.putPairRecord=g.putPairRecord;exports.RelayClient=q;exports.closeDeviceRelayTarget=C;exports.deviceRelayWebSocketUrl=b;exports.pairDevice=pe;exports.requestUSBAccess=fe;exports.startDeviceInstall=we;exports.startDeviceInstallRelay=A;exports.startDevicePairingRelay=N;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("../browser-storage-jJaIht4K.js"),E=1,u=16,s={DeviceHello:1,OpenStream:2,OpenResult:3,StreamData:4,StreamClose:5,InstallProgress:6,Error:7,Ping:8,Pong:9,StartPairing:10,StartInstall:11,PairRecordReady:12};function T(e){const t=new Uint8Array(u+e.payload.byteLength),r=new DataView(t.buffer);return r.setUint8(0,E),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,u),t}function W(e){if(e.byteLength<u)throw new Error(`Relay frame too short: ${e.byteLength}`);const t=new DataView(e.buffer,e.byteOffset,e.byteLength),r=t.getUint8(0);if(r!==E)throw new Error(`Unsupported relay protocol version ${r}`);const n=t.getUint32(12);if(e.byteLength!==u+n)throw new Error(`Relay frame length mismatch: got ${e.byteLength}, expected ${u+n}`);return{type:t.getUint8(1),requestId:t.getUint32(4),streamId:t.getUint32(8),payload:e.slice(u)}}function c(e){return new TextEncoder().encode(JSON.stringify(e))}function y(e){return JSON.parse(new TextDecoder().decode(e))}async function B(){if(!navigator.usb)throw new Error("WebUSB is not available in this browser.");return navigator.usb.requestDevice({filters:[{vendorId:1452}]})}function F(e){const t=[],r=e.configuration?.configurationValue,n=e.configurations.find(a=>a.configurationValue===r);n&&t.push(...v(n));for(const a of e.configurations)a.configurationValue!==r&&t.push(...v(a));return t}function v(e){const t=[];for(const r of e.interfaces)for(const n of r.alternates)n.interfaceClass===255&&n.interfaceSubclass===254&&n.interfaceProtocol===2&&t.push({configurationValue:e.configurationValue,interfaceNumber:r.interfaceNumber,alternateSetting:n.alternateSetting,endpoints:n.endpoints});return t}async function _(e,t){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)}function M(e){const t=e.endpoints.find(n=>n.direction==="out"&&n.type==="bulk"),r=e.endpoints.find(n=>n.direction==="in"&&n.type==="bulk");if(!t||!r)throw new Error("Could not find usbmux bulk endpoints.");return{outEndpoint:t,inEndpoint:r}}async function I(e,t,r){const n=await e.transferOut(t.endpointNumber,r);if(n.status!=="ok")throw new Error(`USB transferOut failed: ${n.status}`);r.byteLength%t.packetSize===0&&await e.transferOut(t.endpointNumber,new Uint8Array)}async function j(e,t,r=16384){const n=await e.transferIn(t.endpointNumber,r);if(n.status!=="ok"||!n.data)throw new Error(`USB transferIn failed: ${n.status}`);return new Uint8Array(n.data.buffer,n.data.byteOffset,n.data.byteLength)}const k=0,H=2,P=6,J=4277009102,h=2,z=4,l=16,G=49152;async function Q(e,t){const{inEndpoint:r,outEndpoint:n}=M(t),a=new Uint8Array(12),i=new DataView(a.buffer);i.setUint32(0,2),i.setUint32(4,0),i.setUint32(8,0),await I(e,n,q(k,a));const o=await D(e,r,1),d=new DataView(o.payload.buffer,o.payload.byteOffset).getUint32(0),w={device:e,candidate:t,inEndpoint:r,outEndpoint:n,muxVersion:d,txSeq:0,rxSeq:65535,nextSport:G,streams:new Map,writeChain:Promise.resolve(),closed:!1};return d>=2&&await O(w,H,new Uint8Array([7])),Z(w),w}async function Y(e,t){if(e.closed)throw new Error("usbmux session is closed.");let r,n;const a={session:e,sport:e.nextSport++,dport:t,seq:0,ack:0,queue:[],waiters:[],opened:new Promise((i,o)=>{r=i,n=o}),resolveOpened:r,rejectOpened:n};return e.streams.set(m(t,a.sport),a),await p(a,h,new Uint8Array),await a.opened,a}async function K(e,t){if(e.session.closed)throw new Error("usbmux session is closed.");await p(e,l,t),e.seq+=t.byteLength}async function X(e){if(e.queue.length>0)return e.queue.shift();if(e.error)throw e.error;return new Promise(t=>{e.waiters.push(t)})}function x(e){e.closed=!0;for(const t of e.streams.values())for(t.error=new Error("usbmux session closed"),t.rejectOpened(t.error);t.waiters.length>0;)t.waiters.shift()(new Uint8Array);e.streams.clear()}async function p(e,t,r){const n=new Uint8Array(20+r.byteLength),a=new DataView(n.buffer);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 O(e.session,P,n)}async function O(e,t,r){if(e.closed)throw new Error("usbmux session is closed.");return e.writeChain=e.writeChain.then(async()=>{if(e.closed)return;const n=e.muxVersion>=2?ee(t,r,e.txSeq++,e.rxSeq):q(t,r);await I(e.device,e.outEndpoint,n)}),e.writeChain}async function Z(e){try{for(;;){if(e.closed)return;const t=await D(e.device,e.inEndpoint,e.muxVersion);if(e.closed)return;if(t.rxSeq!==void 0&&(e.rxSeq=t.rxSeq),t.protocol!==P)continue;const r=re(t.payload),n=e.streams.get(m(r.sport,r.dport));if(n){if(r.flags&z){for(n.error=new Error(`Device reset stream ${n.dport}`),n.rejectOpened(n.error);n.waiters.length>0;)n.waiters.shift()(new Uint8Array);e.streams.delete(m(n.dport,n.sport));continue}if((r.flags&(h|l))===(h|l)){n.seq+=1,n.ack=r.seq+1,await p(n,l,new Uint8Array),n.resolveOpened();continue}r.payload.byteLength!==0&&(n.ack=r.seq+r.payload.byteLength,await p(n,l,new Uint8Array),n.waiters.length>0?n.waiters.shift()(r.payload):n.queue.push(r.payload))}}}catch{e.closed||x(e)}}async function D(e,t,r){for(;;){const n=await j(e,t),a=te(n,r);if(!(r===1&&a.protocol!==k))return a}}function q(e,t){const r=new Uint8Array(8+t.byteLength),n=new DataView(r.buffer);return n.setUint32(0,e),n.setUint32(4,r.byteLength),r.set(t,8),r}function ee(e,t,r,n){const a=new Uint8Array(16+t.byteLength),i=new DataView(a.buffer);return i.setUint32(0,e),i.setUint32(4,a.byteLength),i.setUint32(8,J),i.setUint16(12,r),i.setUint16(14,n),a.set(t,16),a}function te(e,t){const r=new DataView(e.buffer,e.byteOffset,e.byteLength),n=r.getUint32(0),a=r.getUint32(4),i=t>=2?16:8;return{protocol:n,length:a,rxSeq:t>=2?r.getUint16(14):void 0,payload:e.slice(i,a)}}function re(e){const t=new DataView(e.buffer,e.byteOffset,e.byteLength),r=(t.getUint8(12)>>4)*4;return{sport:t.getUint16(0),dport:t.getUint16(2),seq:t.getUint32(4),ack:t.getUint32(8),flags:t.getUint8(13),payload:e.slice(r)}}function m(e,t){return`${e}:${t}`}class ${constructor(t,r,n,a){this.webSocketUrl=t,this.session=r,this.deviceHello=n,this.log=a}socket;streams=new Map;frameQueue=Promise.resolve();closed=!1;pairRecordWaiter;async connect(){const t=new WebSocket(this.webSocketUrl);t.binaryType="arraybuffer",this.socket=t,t.onclose=()=>{this.closed=!0,this.log("Relay socket closed"),this.frameQueue.finally(()=>{this.pairRecordWaiter&&(this.pairRecordWaiter.reject(new Error("Relay socket closed")),this.pairRecordWaiter=void 0)})},await new Promise((r,n)=>{t.onopen=()=>r(),t.onerror=()=>n(new Error("WebSocket connection failed"))}),t.onmessage=r=>{const n=r.data instanceof ArrayBuffer?new Uint8Array(r.data):new Uint8Array;this.enqueueFrame(n)},await this.send({type:s.DeviceHello,requestId:0,streamId:0,payload:c(this.deviceHello)}),this.log("Connected WebSocket relay")}async startPairing(){const t=new Promise((r,n)=>{this.pairRecordWaiter={resolve:r,reject:n}});return await this.send({type:s.StartPairing,requestId:0,streamId:0,payload:c({})}),this.log("Pairing requested"),t}async startInstall(t){await this.send({type:s.StartInstall,requestId:0,streamId:0,payload:c(t)}),this.log("Installation requested")}close(){this.closed=!0,this.socket?.close()}enqueueFrame(t){this.frameQueue=this.frameQueue.then(()=>this.handleFrame(W(t))).catch(r=>{this.log("Relay frame handling failed",r instanceof Error?r.message:String(r))})}async handleFrame(t){switch(t.type){case s.OpenStream:await this.handleOpenStream(t.requestId,t.streamId,y(t.payload).port);break;case s.StreamData:{const r=this.streams.get(t.streamId);if(!r)throw new Error(`Unknown stream ${t.streamId}`);await K(r,t.payload);break}case s.StreamClose:this.streams.delete(t.streamId);break;case s.InstallProgress:this.log(ae(y(t.payload).message));break;case s.Error:this.handleError(t.payload);break;case s.PairRecordReady:this.handlePairRecordReady(y(t.payload));break;case s.Ping:await this.send({type:s.Pong,requestId:t.requestId,streamId:0,payload:new Uint8Array});break}}handleError(t){const r=ne(t);this.log("Server error",r),this.pairRecordWaiter&&(this.pairRecordWaiter.reject(new Error(r)),this.pairRecordWaiter=void 0)}handlePairRecordReady(t){this.log("Pair record received",t.udid),this.pairRecordWaiter?.resolve(t),this.pairRecordWaiter=void 0}async handleOpenStream(t,r,n){try{const a=await Y(this.session,n);this.streams.set(r,a),await this.send({type:s.OpenResult,requestId:t,streamId:r,payload:c({ok:!0})}),this.log(`Opened device stream ${r} to port ${n}`),this.pumpDeviceToServer(r,a)}catch(a){this.log(`Open device stream ${r} failed`,a instanceof Error?a.message:String(a)),await this.send({type:s.OpenResult,requestId:t,streamId:r,payload:c({ok:!1,error:a instanceof Error?a.message:String(a)})})}}async pumpDeviceToServer(t,r){try{for(;;){const n=await X(r);if(this.closed)return;await this.send({type:s.StreamData,requestId:0,streamId:t,payload:n})}}catch(n){this.log(`Device stream ${t} closed`,n instanceof Error?n.message:String(n)),await this.send({type:s.StreamClose,requestId:0,streamId:t,payload:c({reason:n instanceof Error?n.message:String(n)})})}}async send(t){if(!this.closed){if(!this.socket||this.socket.readyState!==WebSocket.OPEN){this.closed=!0;return}this.socket.send(T(t))}}}function ne(e){const t=new TextDecoder().decode(e);try{const r=JSON.parse(t);return R(r.error??t)}catch{return R(t)}}function R(e){return e.replace(/libimobiledevice/g,"").trim()}function ae(e){const t="install status: ";if(!e.startsWith(t))return e;const r=e.slice(t.length),n=f(r,"Error");if(n){const o=f(r,"ErrorDescription");return`Install error: ${n}${o?` — ${o}`:""}`}const a=f(r,"Status")??"Unknown",i=f(r,"PercentComplete");return`Install progress: ${i?`${i}% `:""}${a}`}function f(e,t){const n=new RegExp(`<key>\\s*${ie(t)}\\s*</key>\\s*<(?:string|integer|real)>([\\s\\S]*?)</(?:string|integer|real)>`).exec(e);return n?oe(n[1].trim()):void 0}function ie(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function oe(e){return e.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&apos;/g,"'").replace(/&amp;/g,"&")}async function se({log:e}){e("Selecting USB device");const t=await B(),r=ue(t);return e("Selected USB device",`${t.manufacturerName??""} ${t.productName??""} ${t.serialNumber??""}`.trim()),r}async function N({limbuildApiUrl:e,token:t,log:r,target:n}){const a=U(e,t);let i;try{i=await C(a,n,r);const o=await i.startPairing();return{relay:i,pairRecord:o,target:n}}catch(o){throw i?.close(),o}}async function V({limbuildApiUrl:e,token:t,log:r,target:n,pairRecord:a}){const i=U(e,t);let o;try{return o=await C(i,n,r),await o.startInstall(a),o}catch(d){throw o?.close(),d}}async function A(e,t){if(e){if(e.session&&(x(e.session),e.session=void 0),e.claimedInterfaceNumber!==void 0)try{await e.device.releaseInterface(e.claimedInterfaceNumber),t?.("Released usbmux interface")}catch(r){t?.("USB interface release failed",g(r))}finally{e.claimedInterfaceNumber=void 0}if(e.device.opened)try{await e.device.close(),t?.("Closed USB device")}catch(r){t?.("USB device close failed",g(r))}}}async function C(e,t,r){await ce(t,r);const n=new $(e,t.session,t.hello,r);return await n.connect(),n}async function ce(e,t){if(!e.session)try{e.candidate=await le(e,t),e.session=await Q(e.device,e.candidate),t("Created usbmux session")}catch(r){throw await A(e,t),r}}function ue(e){return{device:e,candidate:de(e),hello:{serialNumber:e.serialNumber,productName:e.productName,manufacturerName:e.manufacturerName,productId:e.productId,vendorId:e.vendorId}}}async function le(e,t){const r=L(e.device);if(r.length===0)throw new Error("No Apple usbmux interface found.");let n;for(const a of r)for(const i of[1,2])try{return e.device.opened||await e.device.open(),t("Claiming usbmux interface",`configuration ${a.configurationValue}, interface ${a.interfaceNumber}, alternate ${a.alternateSetting}, attempt ${i}`),await _(e.device,a),e.claimedInterfaceNumber=a.interfaceNumber,t("Claimed usbmux interface",`configuration ${a.configurationValue}, interface ${a.interfaceNumber}`),a}catch(o){n=o,t("USB interface claim failed",`configuration ${a.configurationValue}, interface ${a.interfaceNumber}: ${g(o)}`),await fe(e),await pe(250)}throw n instanceof Error?n:new Error("Unable to claim any Apple usbmux interface.")}function de(e){const t=L(e)[0];if(!t)throw new Error("No Apple usbmux interface found.");return t}function L(e){const t=F(e),r=e.configuration?.configurationValue;return[...t.filter(n=>n.configurationValue===r),...t.filter(n=>n.configurationValue!==r)]}function U(e,t){const r=new URL(e);return r.protocol=r.protocol==="https:"?"wss:":"ws:",r.pathname=`${r.pathname.replace(/\/$/,"")}/device/ws`,t&&r.searchParams.set("token",t),r.toString()}function g(e){return e instanceof Error?e.message:String(e)}async function fe(e){if(e.claimedInterfaceNumber!==void 0){try{await e.device.releaseInterface(e.claimedInterfaceNumber)}catch{}e.claimedInterfaceNumber=void 0}if(e.device.opened)try{await e.device.close()}catch{}}function pe(e){return new Promise(t=>setTimeout(t,e))}async function we(e={}){return se({log:e.log??S})}async function ye(e){return N({...e,log:e.log??S})}async function he(e){return V({...e,log:e.log??S})}function S(){}exports.getPairRecord=b.getPairRecord;exports.normalizeUDID=b.normalizeUDID;exports.putPairRecord=b.putPairRecord;exports.RelayClient=$;exports.closeDeviceRelayTarget=A;exports.deviceRelayWebSocketUrl=U;exports.pairDevice=ye;exports.requestUSBAccess=we;exports.startDeviceInstall=he;exports.startDeviceInstallRelay=V;exports.startDevicePairingRelay=N;
@@ -1,7 +1,7 @@
1
1
  import { RequestUSBAccessOptions as CoreRequestUSBAccessOptions, StartInstallRelayOptions, StartPairingRelayOptions } from '../core/device-install/operations';
2
2
  import { DeviceInstallLog } from '../core/device-install/types';
3
3
  export { closeDeviceRelayTarget, deviceRelayWebSocketUrl, startInstallRelay as startDeviceInstallRelay, startPairingRelay as startDevicePairingRelay, type DeviceRelayTarget, type StartInstallRelayOptions, type StartPairingRelayOptions, } from '../core/device-install/operations';
4
- export { getPairRecord, normalizeUDID, putPairRecord, } from '../core/device-install/storage';
4
+ export { getPairRecord, normalizeUDID, putPairRecord } from '../core/device-install/storage';
5
5
  export type { DeviceHello, DeviceInstallLog, PairRecordPayload, StoredPairRecord, } from '../core/device-install/types';
6
6
  export { RelayClient } from '../core/device-install/operations';
7
7
  export type RequestUSBAccessOptions = Partial<CoreRequestUSBAccessOptions>;