@mcesystems/apple-kit 1.0.78 → 1.0.80

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 (76) hide show
  1. package/dist/index.js +235 -143
  2. package/dist/index.js.map +4 -4
  3. package/dist/index.mjs +231 -143
  4. package/dist/index.mjs.map +4 -4
  5. package/dist/types/index.d.ts +622 -10
  6. package/package.json +9 -7
  7. package/dist/resources/plist/ddm-managed-app.xml +0 -55
  8. package/dist/types/graphql/queries.d.ts +0 -9
  9. package/dist/types/graphql/queries.d.ts.map +0 -1
  10. package/dist/types/index.d.ts.map +0 -1
  11. package/dist/types/logic/actions/activation.d.ts +0 -12
  12. package/dist/types/logic/actions/activation.d.ts.map +0 -1
  13. package/dist/types/logic/actions/appState.d.ts +0 -2
  14. package/dist/types/logic/actions/appState.d.ts.map +0 -1
  15. package/dist/types/logic/actions/device.d.ts +0 -24
  16. package/dist/types/logic/actions/device.d.ts.map +0 -1
  17. package/dist/types/logic/actions/install.d.ts +0 -15
  18. package/dist/types/logic/actions/install.d.ts.map +0 -1
  19. package/dist/types/logic/actions/pair.d.ts +0 -6
  20. package/dist/types/logic/actions/pair.d.ts.map +0 -1
  21. package/dist/types/logic/actions/proxy.d.ts +0 -11
  22. package/dist/types/logic/actions/proxy.d.ts.map +0 -1
  23. package/dist/types/logic/actions/restore.d.ts +0 -36
  24. package/dist/types/logic/actions/restore.d.ts.map +0 -1
  25. package/dist/types/logic/actions/tool.d.ts +0 -8
  26. package/dist/types/logic/actions/tool.d.ts.map +0 -1
  27. package/dist/types/logic/actions/usbmuxd.d.ts +0 -10
  28. package/dist/types/logic/actions/usbmuxd.d.ts.map +0 -1
  29. package/dist/types/logic/activationFlow.d.ts +0 -16
  30. package/dist/types/logic/activationFlow.d.ts.map +0 -1
  31. package/dist/types/logic/appleDeviceKit.d.ts +0 -165
  32. package/dist/types/logic/appleDeviceKit.d.ts.map +0 -1
  33. package/dist/types/logic/dataParser.d.ts +0 -23
  34. package/dist/types/logic/dataParser.d.ts.map +0 -1
  35. package/dist/types/logic/iosCli.d.ts +0 -6
  36. package/dist/types/logic/iosCli.d.ts.map +0 -1
  37. package/dist/types/logic/iosClient.d.ts +0 -50
  38. package/dist/types/logic/iosClient.d.ts.map +0 -1
  39. package/dist/types/logic/profileParser.d.ts +0 -13
  40. package/dist/types/logic/profileParser.d.ts.map +0 -1
  41. package/dist/types/logic/utils/resolvePath.d.ts +0 -13
  42. package/dist/types/logic/utils/resolvePath.d.ts.map +0 -1
  43. package/dist/types/types/activation.d.ts +0 -28
  44. package/dist/types/types/activation.d.ts.map +0 -1
  45. package/dist/types/types/auth.d.ts +0 -13
  46. package/dist/types/types/auth.d.ts.map +0 -1
  47. package/dist/types/types/install.d.ts +0 -13
  48. package/dist/types/types/install.d.ts.map +0 -1
  49. package/dist/types/types/ios.d.ts +0 -166
  50. package/dist/types/types/ios.d.ts.map +0 -1
  51. package/dist/types/types/mdm.d.ts +0 -33
  52. package/dist/types/types/mdm.d.ts.map +0 -1
  53. package/dist/types/types/trust.d.ts +0 -10
  54. package/dist/types/types/trust.d.ts.map +0 -1
  55. package/dist/types/types/types.d.ts +0 -47
  56. package/dist/types/types/types.d.ts.map +0 -1
  57. package/dist/types/types/wifi.d.ts +0 -19
  58. package/dist/types/types/wifi.d.ts.map +0 -1
  59. package/dist/types/types.d.ts +0 -173
  60. package/dist/types/types.d.ts.map +0 -1
  61. package/dist/types/utils/authClient.d.ts +0 -7
  62. package/dist/types/utils/authClient.d.ts.map +0 -1
  63. package/dist/types/utils/ddmDeclaration.d.ts +0 -8
  64. package/dist/types/utils/ddmDeclaration.d.ts.map +0 -1
  65. package/dist/types/utils/debug.d.ts +0 -17
  66. package/dist/types/utils/debug.d.ts.map +0 -1
  67. package/dist/types/utils/installRawProfileRetry.d.ts +0 -7
  68. package/dist/types/utils/installRawProfileRetry.d.ts.map +0 -1
  69. package/dist/types/utils/mdmClient.d.ts +0 -7
  70. package/dist/types/utils/mdmClient.d.ts.map +0 -1
  71. package/dist/types/utils/templateLoader.d.ts +0 -8
  72. package/dist/types/utils/templateLoader.d.ts.map +0 -1
  73. package/dist/types/utils/trustProfile.d.ts +0 -12
  74. package/dist/types/utils/trustProfile.d.ts.map +0 -1
  75. package/dist/types/utils/wifiProfile.d.ts +0 -14
  76. package/dist/types/utils/wifiProfile.d.ts.map +0 -1
package/dist/index.mjs CHANGED
@@ -836,24 +836,24 @@ var require_src = __commonJS({
836
836
  var import_debug = __toESM(require_src());
837
837
  function createLoggers(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
838
838
  const logInfo8 = (0, import_debug.default)(`${namespace}:info`);
839
- const logTask4 = (0, import_debug.default)(`${namespace}:task`);
840
- const logError4 = (0, import_debug.default)(`${namespace}:error`);
841
- const logDetail3 = (0, import_debug.default)(`${namespace}:detail`);
839
+ const logTask5 = (0, import_debug.default)(`${namespace}:task`);
840
+ const logError3 = (0, import_debug.default)(`${namespace}:error`);
841
+ const logDetail2 = (0, import_debug.default)(`${namespace}:detail`);
842
842
  const logDebug = (0, import_debug.default)(`${namespace}:debug`);
843
843
  const logWarning2 = (0, import_debug.default)(`${namespace}:warning`);
844
844
  const logColor = (0, import_debug.default)(`${namespace}:color`);
845
845
  logInfo8.color = "19";
846
- logTask4.color = "25";
847
- logError4.color = "1";
848
- logDetail3.color = "199";
846
+ logTask5.color = "25";
847
+ logError3.color = "1";
848
+ logDetail2.color = "199";
849
849
  logWarning2.color = "186";
850
850
  logDebug.color = "211";
851
851
  logColor.enabled = true;
852
852
  function setNamespace7(namespace2) {
853
853
  logInfo8.namespace = `${namespace2}:info`;
854
- logTask4.namespace = `${namespace2}:task`;
855
- logError4.namespace = `${namespace2}:error`;
856
- logDetail3.namespace = `${namespace2}:detail`;
854
+ logTask5.namespace = `${namespace2}:task`;
855
+ logError3.namespace = `${namespace2}:error`;
856
+ logDetail2.namespace = `${namespace2}:detail`;
857
857
  logWarning2.namespace = `${namespace2}:warning`;
858
858
  logDebug.namespace = `${namespace2}:debug`;
859
859
  }
@@ -861,26 +861,26 @@ function createLoggers(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
861
861
  switch (level) {
862
862
  case "info":
863
863
  logInfo8.enabled = true;
864
- logTask4.enabled = true;
865
- logError4.enabled = true;
864
+ logTask5.enabled = true;
865
+ logError3.enabled = true;
866
866
  logWarning2.enabled = true;
867
- logDetail3.enabled = false;
867
+ logDetail2.enabled = false;
868
868
  logDebug.enabled = false;
869
869
  break;
870
870
  case "debug":
871
871
  logInfo8.enabled = true;
872
- logTask4.enabled = true;
873
- logError4.enabled = true;
872
+ logTask5.enabled = true;
873
+ logError3.enabled = true;
874
874
  logWarning2.enabled = true;
875
- logDetail3.enabled = true;
875
+ logDetail2.enabled = true;
876
876
  logDebug.enabled = true;
877
877
  break;
878
878
  case "none":
879
879
  logInfo8.enabled = false;
880
- logTask4.enabled = false;
881
- logError4.enabled = false;
880
+ logTask5.enabled = false;
881
+ logError3.enabled = false;
882
882
  logWarning2.enabled = false;
883
- logDetail3.enabled = false;
883
+ logDetail2.enabled = false;
884
884
  logDebug.enabled = false;
885
885
  break;
886
886
  }
@@ -892,13 +892,13 @@ function createLoggers(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
892
892
  logInfo8.color = color;
893
893
  break;
894
894
  case "task":
895
- logTask4.color = color;
895
+ logTask5.color = color;
896
896
  break;
897
897
  case "error":
898
- logError4.color = color;
898
+ logError3.color = color;
899
899
  break;
900
900
  case "detail":
901
- logDetail3.color = color;
901
+ logDetail2.color = color;
902
902
  break;
903
903
  case "warning":
904
904
  logWarning2.color = color;
@@ -965,7 +965,7 @@ ${" ".repeat(padding)}${"=".repeat(80)}`;
965
965
  const functionName = functionMatch ? functionMatch[1] : "<anonymous>";
966
966
  callerDetails = `${functionName}`;
967
967
  }
968
- logDetail3(`${header(`*${title}* ${callerDetails}`)}
968
+ logDetail2(`${header(`*${title}* ${callerDetails}`)}
969
969
  ${args.reduce((acc, arg) => `${acc}
970
970
  ${logDataDetail(arg)}`, "")}
971
971
 
@@ -973,22 +973,22 @@ ${"=".repeat(80)}`);
973
973
  }
974
974
  function logErrorObject(error, extraDetails) {
975
975
  if (error instanceof Error) {
976
- logError4(`${extraDetails ? header(extraDetails, 1) : header(error.message, 1)}
976
+ logError3(`${extraDetails ? header(extraDetails, 1) : header(error.message, 1)}
977
977
  Error Message:
978
978
  ${error.message}
979
979
  Error Stack:
980
980
  ${error.stack}
981
981
  ${"=".repeat(80)}`);
982
982
  } else {
983
- logError4(`${extraDetails ? header(extraDetails, 1) : header(String(error), 1)}
983
+ logError3(`${extraDetails ? header(extraDetails, 1) : header(String(error), 1)}
984
984
  ${"=".repeat(80)}`);
985
985
  }
986
986
  }
987
987
  return {
988
988
  logInfo: logInfo8,
989
- logTask: logTask4,
990
- logError: logError4,
991
- logDetail: logDetail3,
989
+ logTask: logTask5,
990
+ logError: logError3,
991
+ logDetail: logDetail2,
992
992
  logDebug,
993
993
  logWarning: logWarning2,
994
994
  logColor,
@@ -1141,7 +1141,12 @@ function portNumbers(from, to) {
1141
1141
  import { existsSync } from "node:fs";
1142
1142
  import { rmSync } from "node:fs";
1143
1143
  import { join } from "node:path";
1144
- var { logTask, logInfo, logDetail, setNamespace, logDataObject } = createLoggers("apple-kit:device");
1144
+ function throwIfAborted(signal) {
1145
+ if (signal?.aborted) {
1146
+ throw new DOMException("Device action was cancelled", "AbortError");
1147
+ }
1148
+ }
1149
+ var { logTask, logInfo, setNamespace } = createLoggers("apple-kit:device");
1145
1150
  function getAppleLockdownPath() {
1146
1151
  if (process.platform === "win32") {
1147
1152
  return join(process.env.ProgramData ?? "C:\\ProgramData", "Apple", "Lockdown");
@@ -1163,7 +1168,7 @@ var DeviceActions = class {
1163
1168
  async info() {
1164
1169
  logInfo(`Getting device info for ${this.udid}`);
1165
1170
  const result = await this.iosClient.info();
1166
- if (!result) {
1171
+ if (result.exitCode !== 0) {
1167
1172
  throw new Error("Failed to get device info");
1168
1173
  }
1169
1174
  return result.output[0];
@@ -1190,55 +1195,49 @@ var DeviceActions = class {
1190
1195
  if (!result) {
1191
1196
  return false;
1192
1197
  }
1193
- logDataObject("IOS pair results", { result });
1194
1198
  return result.raw.stderr.includes("Successfully paired");
1195
1199
  }
1196
- async isPaired() {
1197
- logInfo(`Checking if device ${this.udid} is paired`);
1198
- try {
1199
- const deviceInfo = await this.info();
1200
- const trusted = deviceInfo.TrustedHostAttached === true;
1201
- logDetail(`Device ${this.udid} TrustedHostAttached: ${trusted}`);
1202
- return trusted;
1203
- } catch (error) {
1204
- logDetail(`Device ${this.udid} info failed (not paired or unreachable): ${error}`);
1205
- return false;
1206
- }
1207
- }
1208
1200
  async trustDevice({
1209
1201
  timeout: timeout2 = 6e4,
1210
- onWaitingForTrust
1202
+ pollInterval = 1e3,
1203
+ onWaitingForTrust,
1204
+ signal
1211
1205
  }) {
1212
- logInfo(`Trusting device ${this.udid}`);
1213
- if (await this.isPaired()) {
1214
- logInfo(`Device ${this.udid} is already trusted (lockdown file exists)`);
1206
+ try {
1207
+ const info = await this.info();
1208
+ if (info?.ActivationState !== void 0) {
1209
+ return true;
1210
+ }
1211
+ } catch {
1212
+ logInfo(`Trusting device ${this.udid}`);
1213
+ }
1214
+ if (await this.pair()) {
1215
1215
  return true;
1216
1216
  }
1217
- logInfo("Initiating pairing to show trust dialog on device...");
1218
- await this.pair();
1219
1217
  logInfo("Please accept the trust dialog on the device...");
1220
1218
  onWaitingForTrust?.();
1221
1219
  try {
1222
- await this.waitForPairing({ timeout: timeout2, pollInterval: 1e3 });
1220
+ await this.waitForPairing({ timeout: timeout2, pollInterval, signal });
1223
1221
  logInfo(`Device ${this.udid} is now trusted`);
1224
1222
  return true;
1225
1223
  } catch {
1226
1224
  logInfo(`Timeout waiting for trust acceptance on device ${this.udid}`);
1227
- return false;
1225
+ throw new Error(`Timeout waiting for trust acceptance on device ${this.udid}`);
1228
1226
  }
1229
1227
  }
1230
1228
  async waitForPairing({
1231
1229
  timeout: timeout2 = 12e4,
1232
- pollInterval = 1e3
1230
+ pollInterval = 1e3,
1231
+ signal
1233
1232
  }) {
1234
1233
  logTask(`Waiting for pairing on device ${this.udid}`);
1235
1234
  const startTime = Date.now();
1236
1235
  while (Date.now() - startTime < timeout2) {
1237
- if (await this.isPaired()) {
1238
- logInfo(`Device ${this.udid} is now paired`);
1236
+ throwIfAborted(signal);
1237
+ await new Promise((resolve2) => setTimeout(resolve2, pollInterval));
1238
+ if (await this.pair()) {
1239
1239
  return true;
1240
1240
  }
1241
- await new Promise((resolve2) => setTimeout(resolve2, pollInterval));
1242
1241
  }
1243
1242
  throw new Error(`Timeout waiting for device pairing after ${timeout2}ms`);
1244
1243
  }
@@ -36574,24 +36573,24 @@ var require_src2 = __commonJS22({
36574
36573
  var import_debug2 = __toESM22(require_src2());
36575
36574
  function createLoggers2(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
36576
36575
  const logInfo222 = (0, import_debug2.default)(`${namespace}:info`);
36577
- const logTask4 = (0, import_debug2.default)(`${namespace}:task`);
36576
+ const logTask5 = (0, import_debug2.default)(`${namespace}:task`);
36578
36577
  const logError22 = (0, import_debug2.default)(`${namespace}:error`);
36579
- const logDetail3 = (0, import_debug2.default)(`${namespace}:detail`);
36578
+ const logDetail2 = (0, import_debug2.default)(`${namespace}:detail`);
36580
36579
  const logDebug = (0, import_debug2.default)(`${namespace}:debug`);
36581
36580
  const logWarning2 = (0, import_debug2.default)(`${namespace}:warning`);
36582
36581
  const logColor = (0, import_debug2.default)(`${namespace}:color`);
36583
36582
  logInfo222.color = "19";
36584
- logTask4.color = "25";
36583
+ logTask5.color = "25";
36585
36584
  logError22.color = "1";
36586
- logDetail3.color = "199";
36585
+ logDetail2.color = "199";
36587
36586
  logWarning2.color = "186";
36588
36587
  logDebug.color = "211";
36589
36588
  logColor.enabled = true;
36590
36589
  function setNamespace7(namespace2) {
36591
36590
  logInfo222.namespace = `${namespace2}:info`;
36592
- logTask4.namespace = `${namespace2}:task`;
36591
+ logTask5.namespace = `${namespace2}:task`;
36593
36592
  logError22.namespace = `${namespace2}:error`;
36594
- logDetail3.namespace = `${namespace2}:detail`;
36593
+ logDetail2.namespace = `${namespace2}:detail`;
36595
36594
  logWarning2.namespace = `${namespace2}:warning`;
36596
36595
  logDebug.namespace = `${namespace2}:debug`;
36597
36596
  }
@@ -36599,26 +36598,26 @@ function createLoggers2(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
36599
36598
  switch (level) {
36600
36599
  case "info":
36601
36600
  logInfo222.enabled = true;
36602
- logTask4.enabled = true;
36601
+ logTask5.enabled = true;
36603
36602
  logError22.enabled = true;
36604
36603
  logWarning2.enabled = true;
36605
- logDetail3.enabled = false;
36604
+ logDetail2.enabled = false;
36606
36605
  logDebug.enabled = false;
36607
36606
  break;
36608
36607
  case "debug":
36609
36608
  logInfo222.enabled = true;
36610
- logTask4.enabled = true;
36609
+ logTask5.enabled = true;
36611
36610
  logError22.enabled = true;
36612
36611
  logWarning2.enabled = true;
36613
- logDetail3.enabled = true;
36612
+ logDetail2.enabled = true;
36614
36613
  logDebug.enabled = true;
36615
36614
  break;
36616
36615
  case "none":
36617
36616
  logInfo222.enabled = false;
36618
- logTask4.enabled = false;
36617
+ logTask5.enabled = false;
36619
36618
  logError22.enabled = false;
36620
36619
  logWarning2.enabled = false;
36621
- logDetail3.enabled = false;
36620
+ logDetail2.enabled = false;
36622
36621
  logDebug.enabled = false;
36623
36622
  break;
36624
36623
  }
@@ -36630,13 +36629,13 @@ function createLoggers2(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
36630
36629
  logInfo222.color = color;
36631
36630
  break;
36632
36631
  case "task":
36633
- logTask4.color = color;
36632
+ logTask5.color = color;
36634
36633
  break;
36635
36634
  case "error":
36636
36635
  logError22.color = color;
36637
36636
  break;
36638
36637
  case "detail":
36639
- logDetail3.color = color;
36638
+ logDetail2.color = color;
36640
36639
  break;
36641
36640
  case "warning":
36642
36641
  logWarning2.color = color;
@@ -36703,7 +36702,7 @@ ${" ".repeat(padding)}${"=".repeat(80)}`;
36703
36702
  const functionName = functionMatch ? functionMatch[1] : "<anonymous>";
36704
36703
  callerDetails = `${functionName}`;
36705
36704
  }
36706
- logDetail3(`${header(`*${title}* ${callerDetails}`)}
36705
+ logDetail2(`${header(`*${title}* ${callerDetails}`)}
36707
36706
  ${args.reduce((acc, arg) => `${acc}
36708
36707
  ${logDataDetail(arg)}`, "")}
36709
36708
 
@@ -36724,9 +36723,9 @@ ${"=".repeat(80)}`);
36724
36723
  }
36725
36724
  return {
36726
36725
  logInfo: logInfo222,
36727
- logTask: logTask4,
36726
+ logTask: logTask5,
36728
36727
  logError: logError22,
36729
- logDetail: logDetail3,
36728
+ logDetail: logDetail2,
36730
36729
  logDebug,
36731
36730
  logWarning: logWarning2,
36732
36731
  logColor,
@@ -37671,24 +37670,24 @@ var require_src22 = __commonJS3({
37671
37670
  var import_debug22 = __toESM3(require_src22());
37672
37671
  function createLoggers22(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
37673
37672
  const logInfo32 = (0, import_debug22.default)(`${namespace}:info`);
37674
- const logTask4 = (0, import_debug22.default)(`${namespace}:task`);
37673
+ const logTask5 = (0, import_debug22.default)(`${namespace}:task`);
37675
37674
  const logError22 = (0, import_debug22.default)(`${namespace}:error`);
37676
- const logDetail3 = (0, import_debug22.default)(`${namespace}:detail`);
37675
+ const logDetail2 = (0, import_debug22.default)(`${namespace}:detail`);
37677
37676
  const logDebug = (0, import_debug22.default)(`${namespace}:debug`);
37678
37677
  const logWarning2 = (0, import_debug22.default)(`${namespace}:warning`);
37679
37678
  const logColor = (0, import_debug22.default)(`${namespace}:color`);
37680
37679
  logInfo32.color = "19";
37681
- logTask4.color = "25";
37680
+ logTask5.color = "25";
37682
37681
  logError22.color = "1";
37683
- logDetail3.color = "199";
37682
+ logDetail2.color = "199";
37684
37683
  logWarning2.color = "186";
37685
37684
  logDebug.color = "211";
37686
37685
  logColor.enabled = true;
37687
37686
  function setNamespace7(namespace2) {
37688
37687
  logInfo32.namespace = `${namespace2}:info`;
37689
- logTask4.namespace = `${namespace2}:task`;
37688
+ logTask5.namespace = `${namespace2}:task`;
37690
37689
  logError22.namespace = `${namespace2}:error`;
37691
- logDetail3.namespace = `${namespace2}:detail`;
37690
+ logDetail2.namespace = `${namespace2}:detail`;
37692
37691
  logWarning2.namespace = `${namespace2}:warning`;
37693
37692
  logDebug.namespace = `${namespace2}:debug`;
37694
37693
  }
@@ -37696,26 +37695,26 @@ function createLoggers22(namespace, logLevel = process.env.LOG_LEVEL ?? "none")
37696
37695
  switch (level) {
37697
37696
  case "info":
37698
37697
  logInfo32.enabled = true;
37699
- logTask4.enabled = true;
37698
+ logTask5.enabled = true;
37700
37699
  logError22.enabled = true;
37701
37700
  logWarning2.enabled = true;
37702
- logDetail3.enabled = false;
37701
+ logDetail2.enabled = false;
37703
37702
  logDebug.enabled = false;
37704
37703
  break;
37705
37704
  case "debug":
37706
37705
  logInfo32.enabled = true;
37707
- logTask4.enabled = true;
37706
+ logTask5.enabled = true;
37708
37707
  logError22.enabled = true;
37709
37708
  logWarning2.enabled = true;
37710
- logDetail3.enabled = true;
37709
+ logDetail2.enabled = true;
37711
37710
  logDebug.enabled = true;
37712
37711
  break;
37713
37712
  case "none":
37714
37713
  logInfo32.enabled = false;
37715
- logTask4.enabled = false;
37714
+ logTask5.enabled = false;
37716
37715
  logError22.enabled = false;
37717
37716
  logWarning2.enabled = false;
37718
- logDetail3.enabled = false;
37717
+ logDetail2.enabled = false;
37719
37718
  logDebug.enabled = false;
37720
37719
  break;
37721
37720
  }
@@ -37727,13 +37726,13 @@ function createLoggers22(namespace, logLevel = process.env.LOG_LEVEL ?? "none")
37727
37726
  logInfo32.color = color;
37728
37727
  break;
37729
37728
  case "task":
37730
- logTask4.color = color;
37729
+ logTask5.color = color;
37731
37730
  break;
37732
37731
  case "error":
37733
37732
  logError22.color = color;
37734
37733
  break;
37735
37734
  case "detail":
37736
- logDetail3.color = color;
37735
+ logDetail2.color = color;
37737
37736
  break;
37738
37737
  case "warning":
37739
37738
  logWarning2.color = color;
@@ -37800,7 +37799,7 @@ ${" ".repeat(padding)}${"=".repeat(80)}`;
37800
37799
  const functionName = functionMatch ? functionMatch[1] : "<anonymous>";
37801
37800
  callerDetails = `${functionName}`;
37802
37801
  }
37803
- logDetail3(`${header(`*${title}* ${callerDetails}`)}
37802
+ logDetail2(`${header(`*${title}* ${callerDetails}`)}
37804
37803
  ${args.reduce((acc, arg) => `${acc}
37805
37804
  ${logDataDetail(arg)}`, "")}
37806
37805
 
@@ -37821,9 +37820,9 @@ ${"=".repeat(80)}`);
37821
37820
  }
37822
37821
  return {
37823
37822
  logInfo: logInfo32,
37824
- logTask: logTask4,
37823
+ logTask: logTask5,
37825
37824
  logError: logError22,
37826
- logDetail: logDetail3,
37825
+ logDetail: logDetail2,
37827
37826
  logDebug,
37828
37827
  logWarning: logWarning2,
37829
37828
  logColor,
@@ -37836,11 +37835,11 @@ ${"=".repeat(80)}`);
37836
37835
  setNamespace: setNamespace7
37837
37836
  };
37838
37837
  }
37839
- var { logInfo: logInfo22, logError, logWarning, logDataObject: logDataObject2 } = createLoggers22("mdm-client");
37838
+ var { logInfo: logInfo22, logError, logWarning, logDataObject } = createLoggers22("mdm-client");
37840
37839
  var MdmClient = class {
37841
37840
  constructor(config) {
37842
37841
  this.config = config;
37843
- logDataObject2("MDM Client Config", { config });
37842
+ logDataObject("MDM Client Config", { config });
37844
37843
  if (!config.endpoint) {
37845
37844
  throw new Error("MDM endpoint is required");
37846
37845
  }
@@ -37908,7 +37907,7 @@ async function createMDMClient() {
37908
37907
  const credPath = process.env.CREDENTIALS_PATH;
37909
37908
  if (!endpoint || !credPath) {
37910
37909
  logWarning("MDM endpoint or credentials path is not set");
37911
- logDataObject2("Environment variables", { endpoint, credPath });
37910
+ logDataObject("Environment variables", { endpoint, credPath });
37912
37911
  return void 0;
37913
37912
  }
37914
37913
  const credentials = await readCredentialsFromFile(credPath);
@@ -38007,10 +38006,17 @@ var ProxyActions = class {
38007
38006
  };
38008
38007
 
38009
38008
  // src/logic/activationFlow.ts
38009
+ import { EventEmitter } from "node:events";
38010
38010
  import { unlink, writeFile } from "node:fs/promises";
38011
38011
  import { tmpdir } from "node:os";
38012
38012
  import { join as join4 } from "node:path";
38013
38013
 
38014
+ // src/types/activation.ts
38015
+ var ACTIVATION_FLOW_EVENT_ACTIVATION_DONE = "activationDone";
38016
+ var ACTIVATION_FLOW_EVENT_WIFI_INSTALLED = "wifiInstalled";
38017
+ var ACTIVATION_FLOW_EVENT_MDM_PROFILE_INSTALLED = "mdmProfileInstalled";
38018
+ var ACTIVATION_FLOW_EVENT_STEPS_SKIPPED = "stepsSkipped";
38019
+
38014
38020
  // src/utils/wifiProfile.ts
38015
38021
  import { randomUUID } from "node:crypto";
38016
38022
 
@@ -38287,6 +38293,22 @@ function parseWifiEapType(value) {
38287
38293
  var DEFAULT_RETRIES = 150;
38288
38294
  var DEFAULT_RETRY_DELAY_MS = 1e3;
38289
38295
  var { logTask: logTask3, logInfo: logInfo6, logError: logError2, setNamespace: setNamespace4 } = createLoggers("apple-kit:activation");
38296
+ function throwIfAborted2(signal) {
38297
+ if (signal?.aborted) {
38298
+ throw new DOMException("Activation flow was cancelled", "AbortError");
38299
+ }
38300
+ }
38301
+ function sleep(ms, signal) {
38302
+ return new Promise((resolve2, reject) => {
38303
+ throwIfAborted2(signal);
38304
+ const id = setTimeout(resolve2, ms);
38305
+ const onAbort = () => {
38306
+ clearTimeout(id);
38307
+ reject(new DOMException("Activation flow was cancelled", "AbortError"));
38308
+ };
38309
+ signal?.addEventListener("abort", onAbort, { once: true });
38310
+ });
38311
+ }
38290
38312
  var ActivationFlow = class {
38291
38313
  constructor(udid, iosClient) {
38292
38314
  this.udid = udid;
@@ -38294,32 +38316,62 @@ var ActivationFlow = class {
38294
38316
  setNamespace4(`${udid}`);
38295
38317
  }
38296
38318
  mdmClient;
38297
- async run(steps) {
38319
+ run(steps, signal) {
38320
+ const events = new EventEmitter();
38321
+ const promise = this.runInternal(steps, events, signal);
38322
+ return { promise, events };
38323
+ }
38324
+ async runInternal(steps, events, signal) {
38325
+ throwIfAborted2(signal);
38298
38326
  this.mdmClient = await createMDMClient();
38299
38327
  logTask3(`Starting activation flow for device ${this.udid}`);
38300
- await this.retryActivateCommand("activate device", () => this.iosClient.activate());
38301
- const wifiProfileIdentifier = await this.installWifiProfile();
38302
- await this.installMdmProfile();
38303
- await this.retryIosCommand("skip steps", () => this.iosClient.skipSteps(steps));
38328
+ throwIfAborted2(signal);
38329
+ const infoResult = await this.iosClient.info();
38330
+ if (infoResult.exitCode !== 0) {
38331
+ const pairResult = await this.iosClient.pair();
38332
+ if (pairResult.exitCode !== 0) {
38333
+ if (!(await this.iosClient.listDevices()).udids.includes(this.udid)) {
38334
+ throw new Error("Usbmuxd is not running or incorrectly configured");
38335
+ }
38336
+ throw new Error("Failed to pair device");
38337
+ }
38338
+ }
38339
+ const { attempt } = await this.retryActivateCommand(
38340
+ "activate device",
38341
+ () => this.iosClient.activate(),
38342
+ signal
38343
+ );
38344
+ events.emit(ACTIVATION_FLOW_EVENT_ACTIVATION_DONE, { attempt: attempt + 1 });
38345
+ throwIfAborted2(signal);
38346
+ const wifiProfileIdentifier = await this.installWifiProfile(events, signal);
38347
+ throwIfAborted2(signal);
38348
+ await this.installMdmProfile(events, signal);
38349
+ throwIfAborted2(signal);
38350
+ await this.retryIosCommand("skip steps", () => this.iosClient.skipSteps(steps), signal);
38351
+ events.emit(ACTIVATION_FLOW_EVENT_STEPS_SKIPPED, { steps: steps ?? [] });
38304
38352
  return () => this.removeWifiProfile(wifiProfileIdentifier);
38305
38353
  }
38306
- async installWifiProfile() {
38354
+ async installWifiProfile(events, signal) {
38355
+ throwIfAborted2(signal);
38307
38356
  const wifiProfile = await generateWifiProfileFromEnv();
38308
38357
  if (!wifiProfile) {
38309
38358
  return void 0;
38310
38359
  }
38311
38360
  const wifiProfilePath = await saveWifiProfileToTemp(wifiProfile);
38312
38361
  const wifiProfileIdentifier = getProfileIdentifierFromProfile(wifiProfile);
38313
- await this.retryIosCommand(
38362
+ const { attempt } = await this.retryIosCommand(
38314
38363
  "install wifi profile",
38315
- () => this.iosClient.installProfile(wifiProfilePath)
38364
+ () => this.iosClient.installProfile(wifiProfilePath),
38365
+ signal
38316
38366
  );
38367
+ events.emit(ACTIVATION_FLOW_EVENT_WIFI_INSTALLED, { retries: attempt });
38317
38368
  await removeTempFile(wifiProfilePath, "wifi profile");
38318
38369
  return wifiProfileIdentifier;
38319
38370
  }
38320
- async installMdmProfile() {
38371
+ async installMdmProfile(events, signal) {
38372
+ throwIfAborted2(signal);
38321
38373
  logTask3("Installing MDM enrollment profile");
38322
- const enrollmentProfile = await this.retry(
38374
+ const { result: enrollmentProfile } = await this.retry(
38323
38375
  "generate mdm enrollment profile",
38324
38376
  () => {
38325
38377
  if (!this.mdmClient) {
@@ -38327,16 +38379,21 @@ var ActivationFlow = class {
38327
38379
  }
38328
38380
  return this.mdmClient.generateEnrollmentProfile(this.udid);
38329
38381
  },
38330
- (result) => result.status === "OK" && Boolean(result.profile)
38382
+ (result) => result.status === "OK" && Boolean(result.profile),
38383
+ void 0,
38384
+ void 0,
38385
+ signal
38331
38386
  );
38332
38387
  if (!enrollmentProfile.profile) {
38333
38388
  throw new Error("MDM enrollment profile missing from response");
38334
38389
  }
38335
38390
  const profilePath = await saveProfileToTemp(enrollmentProfile.profile, "mdm_profile");
38336
- await this.retryIosCommand(
38391
+ const { attempt } = await this.retryIosCommand(
38337
38392
  "install mdm profile",
38338
- () => this.iosClient.installProfile(profilePath)
38393
+ () => this.iosClient.installProfile(profilePath),
38394
+ signal
38339
38395
  );
38396
+ events.emit(ACTIVATION_FLOW_EVENT_MDM_PROFILE_INSTALLED, { retries: attempt });
38340
38397
  await removeTempFile(profilePath, "mdm profile");
38341
38398
  }
38342
38399
  async removeWifiProfile(profileIdentifier) {
@@ -38349,25 +38406,41 @@ var ActivationFlow = class {
38349
38406
  () => this.iosClient.removeProfile(profileIdentifier)
38350
38407
  );
38351
38408
  }
38352
- async retryIosCommand(label, command) {
38353
- return this.retry(label, command, (result) => result.exitCode === 0);
38409
+ async retryIosCommand(label, command, signal) {
38410
+ return this.retry(
38411
+ label,
38412
+ command,
38413
+ (result) => result.exitCode === 0,
38414
+ void 0,
38415
+ void 0,
38416
+ signal
38417
+ );
38354
38418
  }
38355
- async retryActivateCommand(label, command) {
38356
- return this.retry(label, command, (result) => isActivationSuccess(result));
38419
+ async retryActivateCommand(label, command, signal) {
38420
+ return this.retry(
38421
+ label,
38422
+ command,
38423
+ (result) => isActivationSuccess(result),
38424
+ void 0,
38425
+ void 0,
38426
+ signal
38427
+ );
38357
38428
  }
38358
- async retry(label, command, isSuccess, retries = +(process.env.DEFAULT_RETRIES ?? DEFAULT_RETRIES), retryDelayMs = +(process.env.DEFAULT_RETRY_DELAY_MS ?? DEFAULT_RETRY_DELAY_MS)) {
38429
+ async retry(label, command, isSuccess, retries = +(process.env.DEFAULT_RETRIES ?? DEFAULT_RETRIES), retryDelayMs = +(process.env.DEFAULT_RETRY_DELAY_MS ?? DEFAULT_RETRY_DELAY_MS), signal) {
38359
38430
  for (let attempt = 0; attempt < retries; attempt += 1) {
38431
+ throwIfAborted2(signal);
38360
38432
  try {
38361
38433
  const result = await command();
38362
38434
  if (isSuccess(result)) {
38363
- return result;
38435
+ return { result, attempt };
38364
38436
  }
38365
38437
  } catch (error) {
38366
38438
  const errorMsg = error instanceof Error ? error.message : String(error);
38367
38439
  logError2(`${label} failed: ${errorMsg}`);
38368
38440
  }
38441
+ throwIfAborted2(signal);
38369
38442
  logInfo6(`Retrying ${label}... ${attempt + 1} of ${retries}`);
38370
- await new Promise((resolve2) => setTimeout(resolve2, retryDelayMs));
38443
+ await sleep(retryDelayMs, signal);
38371
38444
  }
38372
38445
  throw new Error(`Failed to ${label} after ${retries} attempts`);
38373
38446
  }
@@ -38517,14 +38590,17 @@ var ProfileParser = class {
38517
38590
  };
38518
38591
 
38519
38592
  // src/logic/iosClient.ts
38520
- var { logDetail: logDetail2, setNamespace: setNamespace5 } = createLoggers("");
38593
+ var { logDetail, setNamespace: setNamespace5, logTask: logTask4 } = createLoggers("");
38521
38594
  var IosClient = class {
38522
- constructor(iosPath, udid, usbmuxdAddress) {
38595
+ constructor(iosPath, udid, _usbmuxdAddress) {
38523
38596
  this.iosPath = iosPath;
38524
38597
  this.udid = udid;
38525
- this.usbmuxdAddress = usbmuxdAddress;
38598
+ this._usbmuxdAddress = _usbmuxdAddress;
38526
38599
  setNamespace5(`apple-${this.udid}`);
38527
38600
  }
38601
+ get usbmuxdAddress() {
38602
+ return this._usbmuxdAddress;
38603
+ }
38528
38604
  safeParseJson(line) {
38529
38605
  try {
38530
38606
  const parsed = JSON.parse(line);
@@ -38540,8 +38616,7 @@ var IosClient = class {
38540
38616
  return output.split("\n").map((line) => line.trim()).filter((line) => line.length > 0).map((line) => this.safeParseJson(line)).filter((item) => Boolean(item));
38541
38617
  }
38542
38618
  spawnIosCommand(args) {
38543
- logDetail2(`Running command: ${this.iosPath} ${args.join(" ")}`);
38544
- logDetail2(`USBMUXD_SOCKET_ADDRESS: ${this.usbmuxdAddress}`);
38619
+ logTask4(`Running command: ${this.iosPath} ${args.join(" ")}`);
38545
38620
  const child = spawn(this.iosPath, args, {
38546
38621
  windowsHide: true,
38547
38622
  stdio: ["ignore", "pipe", "pipe"],
@@ -38561,32 +38636,31 @@ var IosClient = class {
38561
38636
  stdout += data.toString();
38562
38637
  });
38563
38638
  child.stderr?.on("data", (data) => {
38564
- logDetail2(`Command data: ${data.toString()}`);
38565
38639
  stderr += data.toString();
38566
38640
  });
38567
38641
  child.on("error", (error) => {
38568
- logDetail2(`Command error: ${error.message}`);
38569
38642
  reject(error);
38570
38643
  });
38571
38644
  child.on("close", (code) => {
38572
- logDetail2(`Command closed: ${code}`);
38573
38645
  const output = this.parseIosOutput(stdout);
38574
38646
  const logMessages = this.parseIosOutput(stderr).map((item) => ({
38575
38647
  level: item.level,
38576
38648
  msg: item.msg,
38577
- timestamp: item.timestamp
38649
+ time: item.time,
38650
+ err: item.err
38578
38651
  }));
38579
- resolve2({
38652
+ const result = {
38580
38653
  command: this.iosPath,
38581
38654
  args,
38582
- output,
38583
38655
  logMessages,
38656
+ output,
38584
38657
  exitCode: code ?? 0,
38585
38658
  raw: {
38586
38659
  stdout,
38587
38660
  stderr
38588
38661
  }
38589
- });
38662
+ };
38663
+ resolve2(result);
38590
38664
  });
38591
38665
  });
38592
38666
  }
@@ -38676,7 +38750,7 @@ var IosClient = class {
38676
38750
  }
38677
38751
  async tunnelStart(userspace = false) {
38678
38752
  const args = ["tunnel", "start", "--udid", this.udid, ...userspace ? ["--userspace"] : []];
38679
- logDetail2(`Spawning tunnel: ${this.iosPath} ${args.join(" ")}`);
38753
+ logDetail(`Spawning tunnel: ${this.iosPath} ${args.join(" ")}`);
38680
38754
  const child = spawn(this.iosPath, args, {
38681
38755
  windowsHide: true,
38682
38756
  env: {
@@ -38771,10 +38845,30 @@ var IosClient = class {
38771
38845
  };
38772
38846
 
38773
38847
  // src/logic/appleDeviceKit.ts
38774
- var { logInfo: logInfo7, logError: logError3, setNamespace: setNamespace6 } = createLoggers("apple-kit");
38848
+ var { logInfo: logInfo7, setNamespace: setNamespace6, logDataObject: logDataObject2 } = createLoggers("apple-kit");
38775
38849
  var AppleDeviceKit = class {
38776
38850
  constructor(udid, logicalPort, usbmuxdAddress) {
38777
38851
  this.logicalPort = logicalPort;
38852
+ const requiredEnvVars = {
38853
+ USBIPD_PATH: process.env.USBIPD_PATH,
38854
+ LOCKDOWN_WINDOWS_PATH: process.env.LOCKDOWN_WINDOWS_PATH,
38855
+ MDM_ENDPOINT: process.env.MDM_ENDPOINT,
38856
+ AUTH_API_URL: process.env.AUTH_API_URL,
38857
+ CREDENTIALS_PATH: process.env.CREDENTIALS_PATH,
38858
+ RESOURCES_PATH: process.env.RESOURCES_PATH,
38859
+ WIFI_SSID: process.env.WIFI_SSID,
38860
+ WIFI_PASSWORD: process.env.WIFI_PASSWORD,
38861
+ WIFI_ENCRYPTION: process.env.WIFI_ENCRYPTION,
38862
+ WIFI_HIDDEN: process.env.WIFI_HIDDEN,
38863
+ WIFI_ENTERPRISE: process.env.WIFI_ENTERPRISE,
38864
+ WIFI_EAP_TYPE: process.env.WIFI_EAP_TYPE,
38865
+ CERT_FILE: process.env.CERT_FILE,
38866
+ ORGANIZATION_NAME: process.env.ORGANIZATION_NAME
38867
+ };
38868
+ if (Object.values(requiredEnvVars).some((value) => !value)) {
38869
+ logDataObject2("Required environment variables are not set", requiredEnvVars);
38870
+ throw new Error("Required environment variables are not set");
38871
+ }
38778
38872
  this.deviceId = udid;
38779
38873
  setNamespace6(`apple-${udid}`);
38780
38874
  logInfo7(
@@ -38789,11 +38883,6 @@ var AppleDeviceKit = class {
38789
38883
  this.installActions = new InstallActions(this.deviceId, this.iosClient);
38790
38884
  this.activationFlow = new ActivationFlow(this.deviceId, this.iosClient);
38791
38885
  this.proxyActions = new ProxyActions(this.deviceId, this.iosClient);
38792
- this.iosClient.tunnelStart(true).then((process3) => {
38793
- this.tunnelProcess = process3;
38794
- }).catch((error) => {
38795
- logError3(`Failed to start tunnel: ${error.message}`);
38796
- });
38797
38886
  }
38798
38887
  deviceId;
38799
38888
  proxyProcess = null;
@@ -38824,13 +38913,6 @@ var AppleDeviceKit = class {
38824
38913
  this.ensureNotDisposed();
38825
38914
  return this.deviceActions.listDevices();
38826
38915
  }
38827
- /**
38828
- * Check if device is paired/trusted with this computer
38829
- */
38830
- async isPaired() {
38831
- this.ensureNotDisposed();
38832
- return this.deviceActions.isPaired();
38833
- }
38834
38916
  /**
38835
38917
  * Wait for device to be paired
38836
38918
  * Polls the pairing status until successful or timeout
@@ -38838,9 +38920,9 @@ var AppleDeviceKit = class {
38838
38920
  * @param timeout Timeout in milliseconds (default: 120000)
38839
38921
  * @param pollInterval Poll interval in milliseconds (default: 1000)
38840
38922
  */
38841
- async waitForPairing(timeout2 = 12e4, pollInterval = 1e3) {
38923
+ async waitForPairing(timeout2 = 12e4, pollInterval = 1e3, signal) {
38842
38924
  this.ensureNotDisposed();
38843
- return this.deviceActions.waitForPairing({ timeout: timeout2, pollInterval });
38925
+ return this.deviceActions.waitForPairing({ timeout: timeout2, pollInterval, signal });
38844
38926
  }
38845
38927
  /**
38846
38928
  * Attempt to pair/trust the device
@@ -38863,8 +38945,8 @@ var AppleDeviceKit = class {
38863
38945
  * @param onWaitingForTrust Callback when waiting for user to accept trust dialog
38864
38946
  * @returns true if device is now trusted
38865
38947
  */
38866
- async trustDevice(timeout2 = 6e4, onWaitingForTrust) {
38867
- return this.deviceActions.trustDevice({ timeout: timeout2, onWaitingForTrust });
38948
+ async trustDevice(timeout2 = 6e4, pollInterval = 1e3, onWaitingForTrust, signal) {
38949
+ return this.deviceActions.trustDevice({ timeout: timeout2, pollInterval, onWaitingForTrust, signal });
38868
38950
  }
38869
38951
  /**
38870
38952
  * Unpair/untrust the device
@@ -38962,14 +39044,16 @@ var AppleDeviceKit = class {
38962
39044
  * Activate the device using the activation flow.
38963
39045
  *
38964
39046
  * This flow can install WiFi/MDM/trust profiles and skip setup steps.
39047
+ * Returns { promise, events } so callers can attach listeners before the flow completes.
39048
+ * Pass an AbortSignal to cancel the flow (on each retry or between steps).
38965
39049
  *
38966
39050
  * Note: This requires a valid activation record or Apple server access.
38967
39051
  *
38968
39052
  * Precondition: the device must be paired and trusted.
38969
39053
  */
38970
- async activate() {
39054
+ activate(signal) {
38971
39055
  this.ensureNotDisposed();
38972
- return this.activationFlow.run();
39056
+ return this.activationFlow.run(void 0, signal);
38973
39057
  }
38974
39058
  /**
38975
39059
  * Get the device UDID
@@ -39025,6 +39109,10 @@ var AppleDeviceKit = class {
39025
39109
  }
39026
39110
  };
39027
39111
  export {
39112
+ ACTIVATION_FLOW_EVENT_ACTIVATION_DONE,
39113
+ ACTIVATION_FLOW_EVENT_MDM_PROFILE_INSTALLED,
39114
+ ACTIVATION_FLOW_EVENT_STEPS_SKIPPED,
39115
+ ACTIVATION_FLOW_EVENT_WIFI_INSTALLED,
39028
39116
  ActivationFlow,
39029
39117
  AppleDeviceKit,
39030
39118
  IosClient