@mcesystems/apple-kit 1.0.96 → 1.0.98

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 (79) hide show
  1. package/README.md +258 -258
  2. package/dist/index.js +140 -64
  3. package/dist/index.js.map +2 -2
  4. package/dist/index.mjs +140 -64
  5. package/dist/index.mjs.map +2 -2
  6. package/dist/resources/bin/darwin/idevice_id +0 -0
  7. package/dist/resources/bin/darwin/idevicedebug +0 -0
  8. package/dist/resources/bin/darwin/idevicediagnostics +0 -0
  9. package/dist/resources/bin/darwin/ideviceinfo +0 -0
  10. package/dist/resources/bin/darwin/ideviceinstaller +0 -0
  11. package/dist/resources/bin/darwin/idevicename +0 -0
  12. package/dist/resources/bin/darwin/idevicepair +0 -0
  13. package/dist/resources/bin/darwin/idevicescreenshot +0 -0
  14. package/dist/resources/bin/darwin/idevicesyslog +0 -0
  15. package/dist/resources/bin/darwin/iproxy +0 -0
  16. package/dist/resources/bin/darwin/libcrypto.3.dylib +0 -0
  17. package/dist/resources/bin/darwin/libimobiledevice-1.0.6.dylib +0 -0
  18. package/dist/resources/bin/darwin/libimobiledevice-glue-1.0.0.dylib +0 -0
  19. package/dist/resources/bin/darwin/liblzma.5.dylib +0 -0
  20. package/dist/resources/bin/darwin/libplist-2.0.4.dylib +0 -0
  21. package/dist/resources/bin/darwin/libssl.3.dylib +0 -0
  22. package/dist/resources/bin/darwin/libusbmuxd-2.0.7.dylib +0 -0
  23. package/dist/resources/bin/darwin/libzip.5.dylib +0 -0
  24. package/dist/resources/bin/darwin/libzstd.1.dylib +0 -0
  25. package/dist/resources/licenses/LGPL-2.1.txt +33 -0
  26. package/dist/resources/plist/certificate-trust.xml +43 -43
  27. package/dist/resources/plist/wifi-enterprise.xml +59 -59
  28. package/dist/resources/plist/wifi-standard.xml +50 -50
  29. package/dist/types/index.d.ts +111 -35
  30. package/dist/types/index.d.ts.map +1 -0
  31. package/dist/types/logic/actions/activation.d.ts +12 -0
  32. package/dist/types/logic/actions/activation.d.ts.map +1 -0
  33. package/dist/types/logic/actions/device.d.ts +15 -0
  34. package/dist/types/logic/actions/device.d.ts.map +1 -0
  35. package/dist/types/logic/actions/install.d.ts +10 -0
  36. package/dist/types/logic/actions/install.d.ts.map +1 -0
  37. package/dist/types/logic/actions/pair.d.ts +6 -0
  38. package/dist/types/logic/actions/pair.d.ts.map +1 -0
  39. package/dist/types/logic/actions/proxy.d.ts +23 -0
  40. package/dist/types/logic/actions/proxy.d.ts.map +1 -0
  41. package/dist/types/logic/actions/restore.d.ts +36 -0
  42. package/dist/types/logic/actions/restore.d.ts.map +1 -0
  43. package/dist/types/logic/actions/tool.d.ts +8 -0
  44. package/dist/types/logic/actions/tool.d.ts.map +1 -0
  45. package/dist/types/logic/activationFlow.d.ts +15 -0
  46. package/dist/types/logic/activationFlow.d.ts.map +1 -0
  47. package/dist/types/logic/appleDeviceKit.d.ts +164 -0
  48. package/dist/types/logic/appleDeviceKit.d.ts.map +1 -0
  49. package/dist/types/logic/dataParser.d.ts +23 -0
  50. package/dist/types/logic/dataParser.d.ts.map +1 -0
  51. package/dist/types/logic/iosCli.d.ts +6 -0
  52. package/dist/types/logic/iosCli.d.ts.map +1 -0
  53. package/dist/types/logic/utils/resolvePath.d.ts +13 -0
  54. package/dist/types/logic/utils/resolvePath.d.ts.map +1 -0
  55. package/dist/types/types/activation.d.ts +28 -0
  56. package/dist/types/types/activation.d.ts.map +1 -0
  57. package/dist/types/types/ios.d.ts +152 -0
  58. package/dist/types/types/ios.d.ts.map +1 -0
  59. package/dist/types/types/trust.d.ts +10 -0
  60. package/dist/types/types/trust.d.ts.map +1 -0
  61. package/dist/types/types/types.d.ts +47 -0
  62. package/dist/types/types/types.d.ts.map +1 -0
  63. package/dist/types/types/wifi.d.ts +19 -0
  64. package/dist/types/types/wifi.d.ts.map +1 -0
  65. package/dist/types/types.d.ts +140 -0
  66. package/dist/types/types.d.ts.map +1 -0
  67. package/dist/types/utils/debug.d.ts +17 -0
  68. package/dist/types/utils/debug.d.ts.map +1 -0
  69. package/dist/types/utils/templateLoader.d.ts +8 -0
  70. package/dist/types/utils/templateLoader.d.ts.map +1 -0
  71. package/dist/types/utils/wifiProfile.d.ts +14 -0
  72. package/dist/types/utils/wifiProfile.d.ts.map +1 -0
  73. package/package.json +3 -3
  74. package/scripts/README.md +209 -209
  75. package/scripts/build-windows.sh.template +222 -222
  76. package/scripts/prepare-ios.ts +9 -1
  77. package/resources/ios.exe +0 -0
  78. package/resources/wintun-LICENSE.txt +0 -84
  79. package/resources/wintun.dll +0 -0
package/dist/index.mjs CHANGED
@@ -1577,6 +1577,38 @@ var DeviceActions = class {
1577
1577
  }
1578
1578
  return result.output[0];
1579
1579
  }
1580
+ async batteryInfo() {
1581
+ logInfo(`Getting device info for ${this.udid}`);
1582
+ const result = await this.iosClient.batteryInfo();
1583
+ if (result.exitCode !== 0) {
1584
+ throw new Error("Failed to get battery info");
1585
+ }
1586
+ return result.output[0];
1587
+ }
1588
+ async capacityInfo() {
1589
+ logInfo(`Getting device info for ${this.udid}`);
1590
+ const result = await this.iosClient.capacityInfo();
1591
+ if (result.exitCode !== 0) {
1592
+ throw new Error("Failed to get capacity info");
1593
+ }
1594
+ return result.output[0];
1595
+ }
1596
+ async cloudConfigInfo() {
1597
+ logInfo(`Getting device info for ${this.udid}`);
1598
+ const result = await this.iosClient.cloudConfigInfo();
1599
+ if (result.exitCode !== 0) {
1600
+ throw new Error("Failed to get cloud config info");
1601
+ }
1602
+ return result.output[0];
1603
+ }
1604
+ async regularModelNumber() {
1605
+ logInfo(`Getting device info for ${this.udid}`);
1606
+ const result = await this.iosClient.regularModelNumber();
1607
+ if (result.exitCode !== 0) {
1608
+ throw new Error("Failed to get regular model number");
1609
+ }
1610
+ return result.output[0];
1611
+ }
1580
1612
  async listDevices() {
1581
1613
  logInfo("Listing devices");
1582
1614
  return this.iosClient.listDevices();
@@ -38606,31 +38638,34 @@ function escapeXml(str) {
38606
38638
  var { logInfo: logInfo5 } = createLoggers("apple-kit:wifi-profile");
38607
38639
  async function generateWifiProfile(config, options) {
38608
38640
  const {
38609
- ssid,
38610
38641
  encryptionType,
38611
38642
  password,
38612
38643
  autoJoin = true,
38613
38644
  organizationName = "MCE Systems",
38614
- displayName = `WiFi - ${ssid}`,
38615
38645
  enterprise = false,
38616
38646
  username,
38617
38647
  acceptAnyCertificate = true
38618
38648
  } = config;
38649
+ const resolvedSsid = config.ssid ?? process.env.WIFI_SSID ?? "";
38650
+ if (!resolvedSsid) {
38651
+ throw new Error("WiFi SSID is required. Set config.ssid or WIFI_SSID environment variable.");
38652
+ }
38619
38653
  const profileUuid = randomUUID().toUpperCase();
38620
38654
  const payloadUuid = randomUUID().toUpperCase();
38621
- const profileId = `com.mce.wifi.${ssid.replace(/[^a-zA-Z0-9]/g, "")}.${Date.now()}`;
38655
+ const profileId = `com.mce.wifi.${resolvedSsid.replace(/[^a-zA-Z0-9]/g, "")}.${Date.now()}`;
38622
38656
  const payloadId = `${profileId}.payload`;
38623
- logInfo5(`Generating WiFi profile for SSID: ${ssid}, encryption: ${encryptionType}`);
38657
+ const displayNameToUse = config.displayName ?? `WiFi - ${resolvedSsid}`;
38658
+ logInfo5(`Generating WiFi profile for SSID: ${resolvedSsid}, encryption: ${encryptionType}`);
38624
38659
  const templateName = enterprise ? "wifi-enterprise.xml" : "wifi-standard.xml";
38625
38660
  const template = await loadTemplate(templateName, options?.plistDir);
38626
38661
  const variables = {
38627
- ssid: config.ssid ?? process.env.WIFI_SSID,
38662
+ ssid: resolvedSsid,
38628
38663
  password: config.password ?? process.env.WIFI_PASSWORD,
38629
38664
  encryptionType: parseWifiEncryptionType(config.encryptionType ?? process.env.WIFI_ENCRYPTION),
38630
38665
  autoJoin: autoJoin ? "true" : "false",
38631
38666
  hiddenNetwork: config.hiddenNetwork ?? process.env.WIFI_HIDDEN === "true",
38632
38667
  organizationName,
38633
- displayName,
38668
+ displayName: displayNameToUse,
38634
38669
  profileId,
38635
38670
  profileUuid,
38636
38671
  payloadId,
@@ -38725,10 +38760,9 @@ function isAbortError(error) {
38725
38760
  return error instanceof DOMException && error.name === "AbortError";
38726
38761
  }
38727
38762
  var ActivationFlow = class {
38728
- constructor(udid, iosClient, deviceActions) {
38763
+ constructor(udid, iosClient) {
38729
38764
  this.udid = udid;
38730
38765
  this.iosClient = iosClient;
38731
- this.deviceActions = deviceActions;
38732
38766
  setNamespace4(`${udid}`);
38733
38767
  }
38734
38768
  mdmClient;
@@ -38764,14 +38798,6 @@ var ActivationFlow = class {
38764
38798
  signal
38765
38799
  );
38766
38800
  throwIfAborted2(signal);
38767
- const expectedSsid = config.wifiProfileConfig?.ssid;
38768
- if (expectedSsid) {
38769
- if (await this.deviceActions.isWifiConnected(15e3) !== expectedSsid) {
38770
- throw new Error(
38771
- `WiFi profile not installed correctly, expected ${expectedSsid} but got ${await this.deviceActions.isWifiConnected(15e3)}`
38772
- );
38773
- }
38774
- }
38775
38801
  await this.installMdmProfile(events, signal);
38776
38802
  throwIfAborted2(signal);
38777
38803
  }
@@ -39149,6 +39175,24 @@ var IosClient = class {
39149
39175
  async info() {
39150
39176
  return this.runIosCommand(["info", "--udid", this.udid]);
39151
39177
  }
39178
+ async batteryInfo() {
39179
+ return this.runIosCommand(["batteryregistry", "--udid", this.udid]);
39180
+ }
39181
+ async capacityInfo() {
39182
+ return this.runIosCommand([
39183
+ "lockdown",
39184
+ "get",
39185
+ "--domain=com.apple.disk_usage",
39186
+ "--udid",
39187
+ this.udid
39188
+ ]);
39189
+ }
39190
+ async cloudConfigInfo() {
39191
+ return this.runIosCommand(["prepare", "cloudconfig", "--udid", this.udid]);
39192
+ }
39193
+ async regularModelNumber() {
39194
+ return this.runIosCommand(["lockdown", "get", "RegulatoryModelNumber", "--udid", this.udid]);
39195
+ }
39152
39196
  async installApp(ipaPath) {
39153
39197
  return this.runIosCommand(["install", `--path=${ipaPath}`, "--udid", this.udid]);
39154
39198
  }
@@ -39175,45 +39219,59 @@ var IosClient = class {
39175
39219
  return this.runIosCommand(["devmode", "enable", "--udid", this.udid]);
39176
39220
  }
39177
39221
  async tunnelStart(userspace = false, pairRecordPath) {
39178
- const args = ["tunnel", "start", `--pair-record-path=${pairRecordPath ?? "default"}`, "--udid", this.udid, ...userspace ? ["--userspace"] : []];
39179
- logDetail(`Spawning tunnel: ${this.iosPath} ${args.join(" ")}`);
39180
- const child = spawn(this.iosPath, args, {
39181
- windowsHide: true,
39182
- env: {
39183
- ...process.env,
39184
- USBMUXD_SOCKET_ADDRESS: this.usbmuxdAddress
39185
- },
39186
- stdio: ["ignore", "pipe", "pipe"]
39222
+ return new Promise((resolve2, reject) => {
39223
+ const args = [
39224
+ "tunnel",
39225
+ "start",
39226
+ `--pair-record-path=${pairRecordPath ?? "default"}`,
39227
+ "--udid",
39228
+ this.udid,
39229
+ ...userspace ? ["--userspace"] : []
39230
+ ];
39231
+ logDetail(`Spawning tunnel: ${this.iosPath} ${args.join(" ")}`);
39232
+ const child = spawn(this.iosPath, args, {
39233
+ windowsHide: true,
39234
+ env: {
39235
+ ...process.env,
39236
+ USBMUXD_SOCKET_ADDRESS: this.usbmuxdAddress
39237
+ },
39238
+ stdio: ["ignore", "pipe", "pipe"]
39239
+ });
39240
+ let settled = false;
39241
+ const cleanup = () => {
39242
+ child.off("error", onError);
39243
+ child.off("exit", onExit);
39244
+ child.stdout?.off("data", onReadyCheck);
39245
+ child.stderr?.off("data", onReadyCheck);
39246
+ clearTimeout(readyTimeout);
39247
+ };
39248
+ const finish = (result) => {
39249
+ if (settled) {
39250
+ return;
39251
+ }
39252
+ settled = true;
39253
+ cleanup();
39254
+ if (result.reject) {
39255
+ reject(result.reject);
39256
+ return;
39257
+ }
39258
+ if (result.resolve !== void 0) {
39259
+ resolve2(result.resolve);
39260
+ }
39261
+ };
39262
+ const onError = (err) => finish({ reject: err });
39263
+ const onExit = (code) => finish({ reject: new Error(`Tunnel exited early (code=${code})`) });
39264
+ const onReadyCheck = (data) => {
39265
+ const line = data.toString();
39266
+ const isReady = line.includes("Tunnel server started") || line.includes("tunnel") && (line.includes("listening") || line.includes("connected"));
39267
+ if (isReady) finish({ resolve: child });
39268
+ };
39269
+ const readyTimeout = setTimeout(() => finish({ resolve: child }), 1e4);
39270
+ child.once("error", onError);
39271
+ child.once("exit", onExit);
39272
+ child.stdout?.on("data", onReadyCheck);
39273
+ child.stderr?.on("data", onReadyCheck);
39187
39274
  });
39188
- let settled = false;
39189
- const cleanup = () => {
39190
- child.off("error", onError);
39191
- child.off("exit", onExit);
39192
- child.stdout?.off("data", onReadyCheck);
39193
- child.stderr?.off("data", onReadyCheck);
39194
- clearTimeout(readyTimeout);
39195
- };
39196
- const finish = (result) => {
39197
- if (settled) return;
39198
- settled = true;
39199
- cleanup();
39200
- if (result.reject) throw result.reject;
39201
- if (result.resolve !== void 0) return result.resolve;
39202
- throw new Error("Tunnel process not found");
39203
- };
39204
- const onError = (err) => finish({ reject: err });
39205
- const onExit = (code) => finish({ reject: new Error(`Tunnel exited early (code=${code})`) });
39206
- const onReadyCheck = (data) => {
39207
- const line = data.toString();
39208
- const isReady = line.includes("Tunnel server started") || line.includes("tunnel") && (line.includes("listening") || line.includes("connected"));
39209
- if (isReady) finish({ resolve: child });
39210
- };
39211
- const readyTimeout = setTimeout(() => finish({ resolve: child }), 1e4);
39212
- child.once("error", onError);
39213
- child.once("exit", onExit);
39214
- child.stdout?.on("data", onReadyCheck);
39215
- child.stderr?.on("data", onReadyCheck);
39216
- return child;
39217
39275
  }
39218
39276
  async fsyncPull({
39219
39277
  app,
@@ -39335,9 +39393,9 @@ var AppleDeviceKit = class _AppleDeviceKit {
39335
39393
  this.iosClient = new IosClient(iosBinaryPath, udid, usbmuxdAddress);
39336
39394
  this.deviceActions = new DeviceActions(this.deviceId, this.iosClient);
39337
39395
  this.installActions = new InstallActions(this.deviceId, this.iosClient);
39338
- this.activationFlow = new ActivationFlow(this.deviceId, this.iosClient, this.deviceActions);
39396
+ this.activationFlow = new ActivationFlow(this.deviceId, this.iosClient);
39339
39397
  this.proxyActions = new ProxyActions(this.deviceId, this.iosClient);
39340
- this.ensureTunnel();
39398
+ this.getTunnelReady();
39341
39399
  }
39342
39400
  deviceId;
39343
39401
  proxyProcess = null;
@@ -39349,7 +39407,18 @@ var AppleDeviceKit = class _AppleDeviceKit {
39349
39407
  activationFlow;
39350
39408
  proxyActions;
39351
39409
  tunnelProcess = null;
39410
+ tunnelReadyPromise = null;
39352
39411
  static IOS_17_VERSION = 17;
39412
+ /**
39413
+ * Returns a promise that resolves when the tunnel is ready (or immediately if not needed).
39414
+ * Reuses the same in-flight promise so constructor and methods don't race.
39415
+ */
39416
+ getTunnelReady() {
39417
+ if (!this.tunnelReadyPromise) {
39418
+ this.tunnelReadyPromise = this.runEnsureTunnel();
39419
+ }
39420
+ return this.tunnelReadyPromise;
39421
+ }
39353
39422
  /**
39354
39423
  * Check if iOS version requires tunneling (iOS 17+)
39355
39424
  */
@@ -39367,9 +39436,15 @@ var AppleDeviceKit = class _AppleDeviceKit {
39367
39436
  }
39368
39437
  }
39369
39438
  /**
39370
- * Ensure tunnel is started for iOS 17+ devices
39439
+ * Ensure tunnel is started for iOS 17+ devices. Safe to call multiple times; reuses in-flight setup.
39371
39440
  */
39372
39441
  async ensureTunnel() {
39442
+ await this.getTunnelReady();
39443
+ }
39444
+ /**
39445
+ * Internal tunnel startup. Called once per tunnel lifecycle; getTunnelReady() caches this promise.
39446
+ */
39447
+ async runEnsureTunnel() {
39373
39448
  const requiresTunnel = await this.requiresTunneling();
39374
39449
  if (!requiresTunnel) {
39375
39450
  logDetail2(`Device ${this.deviceId} does not require tunneling (iOS < 17)`);
@@ -39382,21 +39457,28 @@ var AppleDeviceKit = class _AppleDeviceKit {
39382
39457
  }
39383
39458
  logInfo7(`Starting tunnel for device ${this.deviceId} (iOS 17+)`);
39384
39459
  try {
39385
- const pairRecordPath = join5(this.deviceActions.getLockdownPath() ?? "", "RemotePairing", `${this.deviceId}`);
39460
+ const pairRecordPath = join5(
39461
+ this.deviceActions.getLockdownPath() ?? "",
39462
+ "RemotePairing",
39463
+ `${this.deviceId}`
39464
+ );
39386
39465
  await mkdir(pairRecordPath, { recursive: true });
39387
39466
  const tunnelProcess = await this.iosClient.tunnelStart(true, pairRecordPath);
39388
39467
  this.tunnelProcess = tunnelProcess;
39389
39468
  tunnelProcess.on("exit", (code) => {
39390
39469
  logError3(`Tunnel process for device ${this.deviceId} exited with code ${code}`);
39391
39470
  this.tunnelProcess = null;
39471
+ this.tunnelReadyPromise = null;
39392
39472
  });
39393
39473
  tunnelProcess.on("error", (error) => {
39394
39474
  logError3(`Tunnel process error for device ${this.deviceId}: ${error.message}`);
39395
39475
  this.tunnelProcess = null;
39476
+ this.tunnelReadyPromise = null;
39396
39477
  });
39397
39478
  await new Promise((resolve2) => setTimeout(resolve2, 1e3));
39398
39479
  logInfo7(`Tunnel started successfully for device ${this.deviceId}`);
39399
39480
  } catch (error) {
39481
+ this.tunnelReadyPromise = null;
39400
39482
  logError3(
39401
39483
  `Failed to start tunnel for device ${this.deviceId}: ${error instanceof Error ? error.message : String(error)}`
39402
39484
  );
@@ -39634,9 +39716,6 @@ var AppleDeviceKit = class _AppleDeviceKit {
39634
39716
  }
39635
39717
  logInfo7(`File ${fileName} pushed to device ${this.deviceId}`);
39636
39718
  } finally {
39637
- if (requiresTunnel) {
39638
- this.stopTunnel();
39639
- }
39640
39719
  try {
39641
39720
  unlinkSync(tmpFilePath);
39642
39721
  } catch (_error) {
@@ -39673,9 +39752,6 @@ var AppleDeviceKit = class _AppleDeviceKit {
39673
39752
  logInfo7(`File ${fileName} pulled from device ${this.deviceId}`);
39674
39753
  return fileData;
39675
39754
  } finally {
39676
- if (requiresTunnel) {
39677
- this.stopTunnel();
39678
- }
39679
39755
  try {
39680
39756
  unlinkSync(tmpFilePath);
39681
39757
  } catch (_error) {