@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.js CHANGED
@@ -30,6 +30,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ ACTIVATION_FLOW_EVENT_ACTIVATION_DONE: () => ACTIVATION_FLOW_EVENT_ACTIVATION_DONE,
34
+ ACTIVATION_FLOW_EVENT_MDM_PROFILE_INSTALLED: () => ACTIVATION_FLOW_EVENT_MDM_PROFILE_INSTALLED,
35
+ ACTIVATION_FLOW_EVENT_STEPS_SKIPPED: () => ACTIVATION_FLOW_EVENT_STEPS_SKIPPED,
36
+ ACTIVATION_FLOW_EVENT_WIFI_INSTALLED: () => ACTIVATION_FLOW_EVENT_WIFI_INSTALLED,
33
37
  ActivationFlow: () => ActivationFlow,
34
38
  AppleDeviceKit: () => AppleDeviceKit,
35
39
  IosClient: () => IosClient
@@ -867,24 +871,24 @@ var require_src = __commonJS({
867
871
  var import_debug = __toESM2(require_src());
868
872
  function createLoggers(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
869
873
  const logInfo8 = (0, import_debug.default)(`${namespace}:info`);
870
- const logTask4 = (0, import_debug.default)(`${namespace}:task`);
871
- const logError4 = (0, import_debug.default)(`${namespace}:error`);
872
- const logDetail3 = (0, import_debug.default)(`${namespace}:detail`);
874
+ const logTask5 = (0, import_debug.default)(`${namespace}:task`);
875
+ const logError3 = (0, import_debug.default)(`${namespace}:error`);
876
+ const logDetail2 = (0, import_debug.default)(`${namespace}:detail`);
873
877
  const logDebug = (0, import_debug.default)(`${namespace}:debug`);
874
878
  const logWarning2 = (0, import_debug.default)(`${namespace}:warning`);
875
879
  const logColor = (0, import_debug.default)(`${namespace}:color`);
876
880
  logInfo8.color = "19";
877
- logTask4.color = "25";
878
- logError4.color = "1";
879
- logDetail3.color = "199";
881
+ logTask5.color = "25";
882
+ logError3.color = "1";
883
+ logDetail2.color = "199";
880
884
  logWarning2.color = "186";
881
885
  logDebug.color = "211";
882
886
  logColor.enabled = true;
883
887
  function setNamespace7(namespace2) {
884
888
  logInfo8.namespace = `${namespace2}:info`;
885
- logTask4.namespace = `${namespace2}:task`;
886
- logError4.namespace = `${namespace2}:error`;
887
- logDetail3.namespace = `${namespace2}:detail`;
889
+ logTask5.namespace = `${namespace2}:task`;
890
+ logError3.namespace = `${namespace2}:error`;
891
+ logDetail2.namespace = `${namespace2}:detail`;
888
892
  logWarning2.namespace = `${namespace2}:warning`;
889
893
  logDebug.namespace = `${namespace2}:debug`;
890
894
  }
@@ -892,26 +896,26 @@ function createLoggers(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
892
896
  switch (level) {
893
897
  case "info":
894
898
  logInfo8.enabled = true;
895
- logTask4.enabled = true;
896
- logError4.enabled = true;
899
+ logTask5.enabled = true;
900
+ logError3.enabled = true;
897
901
  logWarning2.enabled = true;
898
- logDetail3.enabled = false;
902
+ logDetail2.enabled = false;
899
903
  logDebug.enabled = false;
900
904
  break;
901
905
  case "debug":
902
906
  logInfo8.enabled = true;
903
- logTask4.enabled = true;
904
- logError4.enabled = true;
907
+ logTask5.enabled = true;
908
+ logError3.enabled = true;
905
909
  logWarning2.enabled = true;
906
- logDetail3.enabled = true;
910
+ logDetail2.enabled = true;
907
911
  logDebug.enabled = true;
908
912
  break;
909
913
  case "none":
910
914
  logInfo8.enabled = false;
911
- logTask4.enabled = false;
912
- logError4.enabled = false;
915
+ logTask5.enabled = false;
916
+ logError3.enabled = false;
913
917
  logWarning2.enabled = false;
914
- logDetail3.enabled = false;
918
+ logDetail2.enabled = false;
915
919
  logDebug.enabled = false;
916
920
  break;
917
921
  }
@@ -923,13 +927,13 @@ function createLoggers(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
923
927
  logInfo8.color = color;
924
928
  break;
925
929
  case "task":
926
- logTask4.color = color;
930
+ logTask5.color = color;
927
931
  break;
928
932
  case "error":
929
- logError4.color = color;
933
+ logError3.color = color;
930
934
  break;
931
935
  case "detail":
932
- logDetail3.color = color;
936
+ logDetail2.color = color;
933
937
  break;
934
938
  case "warning":
935
939
  logWarning2.color = color;
@@ -996,7 +1000,7 @@ ${" ".repeat(padding)}${"=".repeat(80)}`;
996
1000
  const functionName = functionMatch ? functionMatch[1] : "<anonymous>";
997
1001
  callerDetails = `${functionName}`;
998
1002
  }
999
- logDetail3(`${header(`*${title}* ${callerDetails}`)}
1003
+ logDetail2(`${header(`*${title}* ${callerDetails}`)}
1000
1004
  ${args.reduce((acc, arg) => `${acc}
1001
1005
  ${logDataDetail(arg)}`, "")}
1002
1006
 
@@ -1004,22 +1008,22 @@ ${"=".repeat(80)}`);
1004
1008
  }
1005
1009
  function logErrorObject(error, extraDetails) {
1006
1010
  if (error instanceof Error) {
1007
- logError4(`${extraDetails ? header(extraDetails, 1) : header(error.message, 1)}
1011
+ logError3(`${extraDetails ? header(extraDetails, 1) : header(error.message, 1)}
1008
1012
  Error Message:
1009
1013
  ${error.message}
1010
1014
  Error Stack:
1011
1015
  ${error.stack}
1012
1016
  ${"=".repeat(80)}`);
1013
1017
  } else {
1014
- logError4(`${extraDetails ? header(extraDetails, 1) : header(String(error), 1)}
1018
+ logError3(`${extraDetails ? header(extraDetails, 1) : header(String(error), 1)}
1015
1019
  ${"=".repeat(80)}`);
1016
1020
  }
1017
1021
  }
1018
1022
  return {
1019
1023
  logInfo: logInfo8,
1020
- logTask: logTask4,
1021
- logError: logError4,
1022
- logDetail: logDetail3,
1024
+ logTask: logTask5,
1025
+ logError: logError3,
1026
+ logDetail: logDetail2,
1023
1027
  logDebug,
1024
1028
  logWarning: logWarning2,
1025
1029
  logColor,
@@ -1172,7 +1176,12 @@ function portNumbers(from, to) {
1172
1176
  var import_node_fs = require("node:fs");
1173
1177
  var import_node_fs2 = require("node:fs");
1174
1178
  var import_node_path = require("node:path");
1175
- var { logTask, logInfo, logDetail, setNamespace, logDataObject } = createLoggers("apple-kit:device");
1179
+ function throwIfAborted(signal) {
1180
+ if (signal?.aborted) {
1181
+ throw new DOMException("Device action was cancelled", "AbortError");
1182
+ }
1183
+ }
1184
+ var { logTask, logInfo, setNamespace } = createLoggers("apple-kit:device");
1176
1185
  function getAppleLockdownPath() {
1177
1186
  if (process.platform === "win32") {
1178
1187
  return (0, import_node_path.join)(process.env.ProgramData ?? "C:\\ProgramData", "Apple", "Lockdown");
@@ -1194,7 +1203,7 @@ var DeviceActions = class {
1194
1203
  async info() {
1195
1204
  logInfo(`Getting device info for ${this.udid}`);
1196
1205
  const result = await this.iosClient.info();
1197
- if (!result) {
1206
+ if (result.exitCode !== 0) {
1198
1207
  throw new Error("Failed to get device info");
1199
1208
  }
1200
1209
  return result.output[0];
@@ -1221,55 +1230,49 @@ var DeviceActions = class {
1221
1230
  if (!result) {
1222
1231
  return false;
1223
1232
  }
1224
- logDataObject("IOS pair results", { result });
1225
1233
  return result.raw.stderr.includes("Successfully paired");
1226
1234
  }
1227
- async isPaired() {
1228
- logInfo(`Checking if device ${this.udid} is paired`);
1229
- try {
1230
- const deviceInfo = await this.info();
1231
- const trusted = deviceInfo.TrustedHostAttached === true;
1232
- logDetail(`Device ${this.udid} TrustedHostAttached: ${trusted}`);
1233
- return trusted;
1234
- } catch (error) {
1235
- logDetail(`Device ${this.udid} info failed (not paired or unreachable): ${error}`);
1236
- return false;
1237
- }
1238
- }
1239
1235
  async trustDevice({
1240
1236
  timeout: timeout2 = 6e4,
1241
- onWaitingForTrust
1237
+ pollInterval = 1e3,
1238
+ onWaitingForTrust,
1239
+ signal
1242
1240
  }) {
1243
- logInfo(`Trusting device ${this.udid}`);
1244
- if (await this.isPaired()) {
1245
- logInfo(`Device ${this.udid} is already trusted (lockdown file exists)`);
1241
+ try {
1242
+ const info = await this.info();
1243
+ if (info?.ActivationState !== void 0) {
1244
+ return true;
1245
+ }
1246
+ } catch {
1247
+ logInfo(`Trusting device ${this.udid}`);
1248
+ }
1249
+ if (await this.pair()) {
1246
1250
  return true;
1247
1251
  }
1248
- logInfo("Initiating pairing to show trust dialog on device...");
1249
- await this.pair();
1250
1252
  logInfo("Please accept the trust dialog on the device...");
1251
1253
  onWaitingForTrust?.();
1252
1254
  try {
1253
- await this.waitForPairing({ timeout: timeout2, pollInterval: 1e3 });
1255
+ await this.waitForPairing({ timeout: timeout2, pollInterval, signal });
1254
1256
  logInfo(`Device ${this.udid} is now trusted`);
1255
1257
  return true;
1256
1258
  } catch {
1257
1259
  logInfo(`Timeout waiting for trust acceptance on device ${this.udid}`);
1258
- return false;
1260
+ throw new Error(`Timeout waiting for trust acceptance on device ${this.udid}`);
1259
1261
  }
1260
1262
  }
1261
1263
  async waitForPairing({
1262
1264
  timeout: timeout2 = 12e4,
1263
- pollInterval = 1e3
1265
+ pollInterval = 1e3,
1266
+ signal
1264
1267
  }) {
1265
1268
  logTask(`Waiting for pairing on device ${this.udid}`);
1266
1269
  const startTime = Date.now();
1267
1270
  while (Date.now() - startTime < timeout2) {
1268
- if (await this.isPaired()) {
1269
- logInfo(`Device ${this.udid} is now paired`);
1271
+ throwIfAborted(signal);
1272
+ await new Promise((resolve2) => setTimeout(resolve2, pollInterval));
1273
+ if (await this.pair()) {
1270
1274
  return true;
1271
1275
  }
1272
- await new Promise((resolve2) => setTimeout(resolve2, pollInterval));
1273
1276
  }
1274
1277
  throw new Error(`Timeout waiting for device pairing after ${timeout2}ms`);
1275
1278
  }
@@ -36605,24 +36608,24 @@ var require_src2 = __commonJS22({
36605
36608
  var import_debug2 = __toESM22(require_src2());
36606
36609
  function createLoggers2(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
36607
36610
  const logInfo222 = (0, import_debug2.default)(`${namespace}:info`);
36608
- const logTask4 = (0, import_debug2.default)(`${namespace}:task`);
36611
+ const logTask5 = (0, import_debug2.default)(`${namespace}:task`);
36609
36612
  const logError22 = (0, import_debug2.default)(`${namespace}:error`);
36610
- const logDetail3 = (0, import_debug2.default)(`${namespace}:detail`);
36613
+ const logDetail2 = (0, import_debug2.default)(`${namespace}:detail`);
36611
36614
  const logDebug = (0, import_debug2.default)(`${namespace}:debug`);
36612
36615
  const logWarning2 = (0, import_debug2.default)(`${namespace}:warning`);
36613
36616
  const logColor = (0, import_debug2.default)(`${namespace}:color`);
36614
36617
  logInfo222.color = "19";
36615
- logTask4.color = "25";
36618
+ logTask5.color = "25";
36616
36619
  logError22.color = "1";
36617
- logDetail3.color = "199";
36620
+ logDetail2.color = "199";
36618
36621
  logWarning2.color = "186";
36619
36622
  logDebug.color = "211";
36620
36623
  logColor.enabled = true;
36621
36624
  function setNamespace7(namespace2) {
36622
36625
  logInfo222.namespace = `${namespace2}:info`;
36623
- logTask4.namespace = `${namespace2}:task`;
36626
+ logTask5.namespace = `${namespace2}:task`;
36624
36627
  logError22.namespace = `${namespace2}:error`;
36625
- logDetail3.namespace = `${namespace2}:detail`;
36628
+ logDetail2.namespace = `${namespace2}:detail`;
36626
36629
  logWarning2.namespace = `${namespace2}:warning`;
36627
36630
  logDebug.namespace = `${namespace2}:debug`;
36628
36631
  }
@@ -36630,26 +36633,26 @@ function createLoggers2(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
36630
36633
  switch (level) {
36631
36634
  case "info":
36632
36635
  logInfo222.enabled = true;
36633
- logTask4.enabled = true;
36636
+ logTask5.enabled = true;
36634
36637
  logError22.enabled = true;
36635
36638
  logWarning2.enabled = true;
36636
- logDetail3.enabled = false;
36639
+ logDetail2.enabled = false;
36637
36640
  logDebug.enabled = false;
36638
36641
  break;
36639
36642
  case "debug":
36640
36643
  logInfo222.enabled = true;
36641
- logTask4.enabled = true;
36644
+ logTask5.enabled = true;
36642
36645
  logError22.enabled = true;
36643
36646
  logWarning2.enabled = true;
36644
- logDetail3.enabled = true;
36647
+ logDetail2.enabled = true;
36645
36648
  logDebug.enabled = true;
36646
36649
  break;
36647
36650
  case "none":
36648
36651
  logInfo222.enabled = false;
36649
- logTask4.enabled = false;
36652
+ logTask5.enabled = false;
36650
36653
  logError22.enabled = false;
36651
36654
  logWarning2.enabled = false;
36652
- logDetail3.enabled = false;
36655
+ logDetail2.enabled = false;
36653
36656
  logDebug.enabled = false;
36654
36657
  break;
36655
36658
  }
@@ -36661,13 +36664,13 @@ function createLoggers2(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
36661
36664
  logInfo222.color = color;
36662
36665
  break;
36663
36666
  case "task":
36664
- logTask4.color = color;
36667
+ logTask5.color = color;
36665
36668
  break;
36666
36669
  case "error":
36667
36670
  logError22.color = color;
36668
36671
  break;
36669
36672
  case "detail":
36670
- logDetail3.color = color;
36673
+ logDetail2.color = color;
36671
36674
  break;
36672
36675
  case "warning":
36673
36676
  logWarning2.color = color;
@@ -36734,7 +36737,7 @@ ${" ".repeat(padding)}${"=".repeat(80)}`;
36734
36737
  const functionName = functionMatch ? functionMatch[1] : "<anonymous>";
36735
36738
  callerDetails = `${functionName}`;
36736
36739
  }
36737
- logDetail3(`${header(`*${title}* ${callerDetails}`)}
36740
+ logDetail2(`${header(`*${title}* ${callerDetails}`)}
36738
36741
  ${args.reduce((acc, arg) => `${acc}
36739
36742
  ${logDataDetail(arg)}`, "")}
36740
36743
 
@@ -36755,9 +36758,9 @@ ${"=".repeat(80)}`);
36755
36758
  }
36756
36759
  return {
36757
36760
  logInfo: logInfo222,
36758
- logTask: logTask4,
36761
+ logTask: logTask5,
36759
36762
  logError: logError22,
36760
- logDetail: logDetail3,
36763
+ logDetail: logDetail2,
36761
36764
  logDebug,
36762
36765
  logWarning: logWarning2,
36763
36766
  logColor,
@@ -37702,24 +37705,24 @@ var require_src22 = __commonJS3({
37702
37705
  var import_debug22 = __toESM32(require_src22());
37703
37706
  function createLoggers22(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
37704
37707
  const logInfo32 = (0, import_debug22.default)(`${namespace}:info`);
37705
- const logTask4 = (0, import_debug22.default)(`${namespace}:task`);
37708
+ const logTask5 = (0, import_debug22.default)(`${namespace}:task`);
37706
37709
  const logError22 = (0, import_debug22.default)(`${namespace}:error`);
37707
- const logDetail3 = (0, import_debug22.default)(`${namespace}:detail`);
37710
+ const logDetail2 = (0, import_debug22.default)(`${namespace}:detail`);
37708
37711
  const logDebug = (0, import_debug22.default)(`${namespace}:debug`);
37709
37712
  const logWarning2 = (0, import_debug22.default)(`${namespace}:warning`);
37710
37713
  const logColor = (0, import_debug22.default)(`${namespace}:color`);
37711
37714
  logInfo32.color = "19";
37712
- logTask4.color = "25";
37715
+ logTask5.color = "25";
37713
37716
  logError22.color = "1";
37714
- logDetail3.color = "199";
37717
+ logDetail2.color = "199";
37715
37718
  logWarning2.color = "186";
37716
37719
  logDebug.color = "211";
37717
37720
  logColor.enabled = true;
37718
37721
  function setNamespace7(namespace2) {
37719
37722
  logInfo32.namespace = `${namespace2}:info`;
37720
- logTask4.namespace = `${namespace2}:task`;
37723
+ logTask5.namespace = `${namespace2}:task`;
37721
37724
  logError22.namespace = `${namespace2}:error`;
37722
- logDetail3.namespace = `${namespace2}:detail`;
37725
+ logDetail2.namespace = `${namespace2}:detail`;
37723
37726
  logWarning2.namespace = `${namespace2}:warning`;
37724
37727
  logDebug.namespace = `${namespace2}:debug`;
37725
37728
  }
@@ -37727,26 +37730,26 @@ function createLoggers22(namespace, logLevel = process.env.LOG_LEVEL ?? "none")
37727
37730
  switch (level) {
37728
37731
  case "info":
37729
37732
  logInfo32.enabled = true;
37730
- logTask4.enabled = true;
37733
+ logTask5.enabled = true;
37731
37734
  logError22.enabled = true;
37732
37735
  logWarning2.enabled = true;
37733
- logDetail3.enabled = false;
37736
+ logDetail2.enabled = false;
37734
37737
  logDebug.enabled = false;
37735
37738
  break;
37736
37739
  case "debug":
37737
37740
  logInfo32.enabled = true;
37738
- logTask4.enabled = true;
37741
+ logTask5.enabled = true;
37739
37742
  logError22.enabled = true;
37740
37743
  logWarning2.enabled = true;
37741
- logDetail3.enabled = true;
37744
+ logDetail2.enabled = true;
37742
37745
  logDebug.enabled = true;
37743
37746
  break;
37744
37747
  case "none":
37745
37748
  logInfo32.enabled = false;
37746
- logTask4.enabled = false;
37749
+ logTask5.enabled = false;
37747
37750
  logError22.enabled = false;
37748
37751
  logWarning2.enabled = false;
37749
- logDetail3.enabled = false;
37752
+ logDetail2.enabled = false;
37750
37753
  logDebug.enabled = false;
37751
37754
  break;
37752
37755
  }
@@ -37758,13 +37761,13 @@ function createLoggers22(namespace, logLevel = process.env.LOG_LEVEL ?? "none")
37758
37761
  logInfo32.color = color;
37759
37762
  break;
37760
37763
  case "task":
37761
- logTask4.color = color;
37764
+ logTask5.color = color;
37762
37765
  break;
37763
37766
  case "error":
37764
37767
  logError22.color = color;
37765
37768
  break;
37766
37769
  case "detail":
37767
- logDetail3.color = color;
37770
+ logDetail2.color = color;
37768
37771
  break;
37769
37772
  case "warning":
37770
37773
  logWarning2.color = color;
@@ -37831,7 +37834,7 @@ ${" ".repeat(padding)}${"=".repeat(80)}`;
37831
37834
  const functionName = functionMatch ? functionMatch[1] : "<anonymous>";
37832
37835
  callerDetails = `${functionName}`;
37833
37836
  }
37834
- logDetail3(`${header(`*${title}* ${callerDetails}`)}
37837
+ logDetail2(`${header(`*${title}* ${callerDetails}`)}
37835
37838
  ${args.reduce((acc, arg) => `${acc}
37836
37839
  ${logDataDetail(arg)}`, "")}
37837
37840
 
@@ -37852,9 +37855,9 @@ ${"=".repeat(80)}`);
37852
37855
  }
37853
37856
  return {
37854
37857
  logInfo: logInfo32,
37855
- logTask: logTask4,
37858
+ logTask: logTask5,
37856
37859
  logError: logError22,
37857
- logDetail: logDetail3,
37860
+ logDetail: logDetail2,
37858
37861
  logDebug,
37859
37862
  logWarning: logWarning2,
37860
37863
  logColor,
@@ -37867,11 +37870,11 @@ ${"=".repeat(80)}`);
37867
37870
  setNamespace: setNamespace7
37868
37871
  };
37869
37872
  }
37870
- var { logInfo: logInfo22, logError, logWarning, logDataObject: logDataObject2 } = createLoggers22("mdm-client");
37873
+ var { logInfo: logInfo22, logError, logWarning, logDataObject } = createLoggers22("mdm-client");
37871
37874
  var MdmClient = class {
37872
37875
  constructor(config) {
37873
37876
  this.config = config;
37874
- logDataObject2("MDM Client Config", { config });
37877
+ logDataObject("MDM Client Config", { config });
37875
37878
  if (!config.endpoint) {
37876
37879
  throw new Error("MDM endpoint is required");
37877
37880
  }
@@ -37939,7 +37942,7 @@ async function createMDMClient() {
37939
37942
  const credPath = process.env.CREDENTIALS_PATH;
37940
37943
  if (!endpoint || !credPath) {
37941
37944
  logWarning("MDM endpoint or credentials path is not set");
37942
- logDataObject2("Environment variables", { endpoint, credPath });
37945
+ logDataObject("Environment variables", { endpoint, credPath });
37943
37946
  return void 0;
37944
37947
  }
37945
37948
  const credentials = await readCredentialsFromFile(credPath);
@@ -38038,10 +38041,17 @@ var ProxyActions = class {
38038
38041
  };
38039
38042
 
38040
38043
  // src/logic/activationFlow.ts
38044
+ var import_node_events = require("node:events");
38041
38045
  var import_promises2 = require("node:fs/promises");
38042
38046
  var import_node_os5 = require("node:os");
38043
38047
  var import_node_path4 = require("node:path");
38044
38048
 
38049
+ // src/types/activation.ts
38050
+ var ACTIVATION_FLOW_EVENT_ACTIVATION_DONE = "activationDone";
38051
+ var ACTIVATION_FLOW_EVENT_WIFI_INSTALLED = "wifiInstalled";
38052
+ var ACTIVATION_FLOW_EVENT_MDM_PROFILE_INSTALLED = "mdmProfileInstalled";
38053
+ var ACTIVATION_FLOW_EVENT_STEPS_SKIPPED = "stepsSkipped";
38054
+
38045
38055
  // src/utils/wifiProfile.ts
38046
38056
  var import_node_crypto2 = require("node:crypto");
38047
38057
 
@@ -38319,6 +38329,22 @@ function parseWifiEapType(value) {
38319
38329
  var DEFAULT_RETRIES = 150;
38320
38330
  var DEFAULT_RETRY_DELAY_MS = 1e3;
38321
38331
  var { logTask: logTask3, logInfo: logInfo6, logError: logError2, setNamespace: setNamespace4 } = createLoggers("apple-kit:activation");
38332
+ function throwIfAborted2(signal) {
38333
+ if (signal?.aborted) {
38334
+ throw new DOMException("Activation flow was cancelled", "AbortError");
38335
+ }
38336
+ }
38337
+ function sleep(ms, signal) {
38338
+ return new Promise((resolve2, reject) => {
38339
+ throwIfAborted2(signal);
38340
+ const id = setTimeout(resolve2, ms);
38341
+ const onAbort = () => {
38342
+ clearTimeout(id);
38343
+ reject(new DOMException("Activation flow was cancelled", "AbortError"));
38344
+ };
38345
+ signal?.addEventListener("abort", onAbort, { once: true });
38346
+ });
38347
+ }
38322
38348
  var ActivationFlow = class {
38323
38349
  constructor(udid, iosClient) {
38324
38350
  this.udid = udid;
@@ -38326,32 +38352,62 @@ var ActivationFlow = class {
38326
38352
  setNamespace4(`${udid}`);
38327
38353
  }
38328
38354
  mdmClient;
38329
- async run(steps) {
38355
+ run(steps, signal) {
38356
+ const events = new import_node_events.EventEmitter();
38357
+ const promise = this.runInternal(steps, events, signal);
38358
+ return { promise, events };
38359
+ }
38360
+ async runInternal(steps, events, signal) {
38361
+ throwIfAborted2(signal);
38330
38362
  this.mdmClient = await createMDMClient();
38331
38363
  logTask3(`Starting activation flow for device ${this.udid}`);
38332
- await this.retryActivateCommand("activate device", () => this.iosClient.activate());
38333
- const wifiProfileIdentifier = await this.installWifiProfile();
38334
- await this.installMdmProfile();
38335
- await this.retryIosCommand("skip steps", () => this.iosClient.skipSteps(steps));
38364
+ throwIfAborted2(signal);
38365
+ const infoResult = await this.iosClient.info();
38366
+ if (infoResult.exitCode !== 0) {
38367
+ const pairResult = await this.iosClient.pair();
38368
+ if (pairResult.exitCode !== 0) {
38369
+ if (!(await this.iosClient.listDevices()).udids.includes(this.udid)) {
38370
+ throw new Error("Usbmuxd is not running or incorrectly configured");
38371
+ }
38372
+ throw new Error("Failed to pair device");
38373
+ }
38374
+ }
38375
+ const { attempt } = await this.retryActivateCommand(
38376
+ "activate device",
38377
+ () => this.iosClient.activate(),
38378
+ signal
38379
+ );
38380
+ events.emit(ACTIVATION_FLOW_EVENT_ACTIVATION_DONE, { attempt: attempt + 1 });
38381
+ throwIfAborted2(signal);
38382
+ const wifiProfileIdentifier = await this.installWifiProfile(events, signal);
38383
+ throwIfAborted2(signal);
38384
+ await this.installMdmProfile(events, signal);
38385
+ throwIfAborted2(signal);
38386
+ await this.retryIosCommand("skip steps", () => this.iosClient.skipSteps(steps), signal);
38387
+ events.emit(ACTIVATION_FLOW_EVENT_STEPS_SKIPPED, { steps: steps ?? [] });
38336
38388
  return () => this.removeWifiProfile(wifiProfileIdentifier);
38337
38389
  }
38338
- async installWifiProfile() {
38390
+ async installWifiProfile(events, signal) {
38391
+ throwIfAborted2(signal);
38339
38392
  const wifiProfile = await generateWifiProfileFromEnv();
38340
38393
  if (!wifiProfile) {
38341
38394
  return void 0;
38342
38395
  }
38343
38396
  const wifiProfilePath = await saveWifiProfileToTemp(wifiProfile);
38344
38397
  const wifiProfileIdentifier = getProfileIdentifierFromProfile(wifiProfile);
38345
- await this.retryIosCommand(
38398
+ const { attempt } = await this.retryIosCommand(
38346
38399
  "install wifi profile",
38347
- () => this.iosClient.installProfile(wifiProfilePath)
38400
+ () => this.iosClient.installProfile(wifiProfilePath),
38401
+ signal
38348
38402
  );
38403
+ events.emit(ACTIVATION_FLOW_EVENT_WIFI_INSTALLED, { retries: attempt });
38349
38404
  await removeTempFile(wifiProfilePath, "wifi profile");
38350
38405
  return wifiProfileIdentifier;
38351
38406
  }
38352
- async installMdmProfile() {
38407
+ async installMdmProfile(events, signal) {
38408
+ throwIfAborted2(signal);
38353
38409
  logTask3("Installing MDM enrollment profile");
38354
- const enrollmentProfile = await this.retry(
38410
+ const { result: enrollmentProfile } = await this.retry(
38355
38411
  "generate mdm enrollment profile",
38356
38412
  () => {
38357
38413
  if (!this.mdmClient) {
@@ -38359,16 +38415,21 @@ var ActivationFlow = class {
38359
38415
  }
38360
38416
  return this.mdmClient.generateEnrollmentProfile(this.udid);
38361
38417
  },
38362
- (result) => result.status === "OK" && Boolean(result.profile)
38418
+ (result) => result.status === "OK" && Boolean(result.profile),
38419
+ void 0,
38420
+ void 0,
38421
+ signal
38363
38422
  );
38364
38423
  if (!enrollmentProfile.profile) {
38365
38424
  throw new Error("MDM enrollment profile missing from response");
38366
38425
  }
38367
38426
  const profilePath = await saveProfileToTemp(enrollmentProfile.profile, "mdm_profile");
38368
- await this.retryIosCommand(
38427
+ const { attempt } = await this.retryIosCommand(
38369
38428
  "install mdm profile",
38370
- () => this.iosClient.installProfile(profilePath)
38429
+ () => this.iosClient.installProfile(profilePath),
38430
+ signal
38371
38431
  );
38432
+ events.emit(ACTIVATION_FLOW_EVENT_MDM_PROFILE_INSTALLED, { retries: attempt });
38372
38433
  await removeTempFile(profilePath, "mdm profile");
38373
38434
  }
38374
38435
  async removeWifiProfile(profileIdentifier) {
@@ -38381,25 +38442,41 @@ var ActivationFlow = class {
38381
38442
  () => this.iosClient.removeProfile(profileIdentifier)
38382
38443
  );
38383
38444
  }
38384
- async retryIosCommand(label, command) {
38385
- return this.retry(label, command, (result) => result.exitCode === 0);
38445
+ async retryIosCommand(label, command, signal) {
38446
+ return this.retry(
38447
+ label,
38448
+ command,
38449
+ (result) => result.exitCode === 0,
38450
+ void 0,
38451
+ void 0,
38452
+ signal
38453
+ );
38386
38454
  }
38387
- async retryActivateCommand(label, command) {
38388
- return this.retry(label, command, (result) => isActivationSuccess(result));
38455
+ async retryActivateCommand(label, command, signal) {
38456
+ return this.retry(
38457
+ label,
38458
+ command,
38459
+ (result) => isActivationSuccess(result),
38460
+ void 0,
38461
+ void 0,
38462
+ signal
38463
+ );
38389
38464
  }
38390
- async retry(label, command, isSuccess, retries = +(process.env.DEFAULT_RETRIES ?? DEFAULT_RETRIES), retryDelayMs = +(process.env.DEFAULT_RETRY_DELAY_MS ?? DEFAULT_RETRY_DELAY_MS)) {
38465
+ async retry(label, command, isSuccess, retries = +(process.env.DEFAULT_RETRIES ?? DEFAULT_RETRIES), retryDelayMs = +(process.env.DEFAULT_RETRY_DELAY_MS ?? DEFAULT_RETRY_DELAY_MS), signal) {
38391
38466
  for (let attempt = 0; attempt < retries; attempt += 1) {
38467
+ throwIfAborted2(signal);
38392
38468
  try {
38393
38469
  const result = await command();
38394
38470
  if (isSuccess(result)) {
38395
- return result;
38471
+ return { result, attempt };
38396
38472
  }
38397
38473
  } catch (error) {
38398
38474
  const errorMsg = error instanceof Error ? error.message : String(error);
38399
38475
  logError2(`${label} failed: ${errorMsg}`);
38400
38476
  }
38477
+ throwIfAborted2(signal);
38401
38478
  logInfo6(`Retrying ${label}... ${attempt + 1} of ${retries}`);
38402
- await new Promise((resolve2) => setTimeout(resolve2, retryDelayMs));
38479
+ await sleep(retryDelayMs, signal);
38403
38480
  }
38404
38481
  throw new Error(`Failed to ${label} after ${retries} attempts`);
38405
38482
  }
@@ -38549,14 +38626,17 @@ var ProfileParser = class {
38549
38626
  };
38550
38627
 
38551
38628
  // src/logic/iosClient.ts
38552
- var { logDetail: logDetail2, setNamespace: setNamespace5 } = createLoggers("");
38629
+ var { logDetail, setNamespace: setNamespace5, logTask: logTask4 } = createLoggers("");
38553
38630
  var IosClient = class {
38554
- constructor(iosPath, udid, usbmuxdAddress) {
38631
+ constructor(iosPath, udid, _usbmuxdAddress) {
38555
38632
  this.iosPath = iosPath;
38556
38633
  this.udid = udid;
38557
- this.usbmuxdAddress = usbmuxdAddress;
38634
+ this._usbmuxdAddress = _usbmuxdAddress;
38558
38635
  setNamespace5(`apple-${this.udid}`);
38559
38636
  }
38637
+ get usbmuxdAddress() {
38638
+ return this._usbmuxdAddress;
38639
+ }
38560
38640
  safeParseJson(line) {
38561
38641
  try {
38562
38642
  const parsed = JSON.parse(line);
@@ -38572,8 +38652,7 @@ var IosClient = class {
38572
38652
  return output.split("\n").map((line) => line.trim()).filter((line) => line.length > 0).map((line) => this.safeParseJson(line)).filter((item) => Boolean(item));
38573
38653
  }
38574
38654
  spawnIosCommand(args) {
38575
- logDetail2(`Running command: ${this.iosPath} ${args.join(" ")}`);
38576
- logDetail2(`USBMUXD_SOCKET_ADDRESS: ${this.usbmuxdAddress}`);
38655
+ logTask4(`Running command: ${this.iosPath} ${args.join(" ")}`);
38577
38656
  const child = (0, import_node_child_process.spawn)(this.iosPath, args, {
38578
38657
  windowsHide: true,
38579
38658
  stdio: ["ignore", "pipe", "pipe"],
@@ -38593,32 +38672,31 @@ var IosClient = class {
38593
38672
  stdout += data.toString();
38594
38673
  });
38595
38674
  child.stderr?.on("data", (data) => {
38596
- logDetail2(`Command data: ${data.toString()}`);
38597
38675
  stderr += data.toString();
38598
38676
  });
38599
38677
  child.on("error", (error) => {
38600
- logDetail2(`Command error: ${error.message}`);
38601
38678
  reject(error);
38602
38679
  });
38603
38680
  child.on("close", (code) => {
38604
- logDetail2(`Command closed: ${code}`);
38605
38681
  const output = this.parseIosOutput(stdout);
38606
38682
  const logMessages = this.parseIosOutput(stderr).map((item) => ({
38607
38683
  level: item.level,
38608
38684
  msg: item.msg,
38609
- timestamp: item.timestamp
38685
+ time: item.time,
38686
+ err: item.err
38610
38687
  }));
38611
- resolve2({
38688
+ const result = {
38612
38689
  command: this.iosPath,
38613
38690
  args,
38614
- output,
38615
38691
  logMessages,
38692
+ output,
38616
38693
  exitCode: code ?? 0,
38617
38694
  raw: {
38618
38695
  stdout,
38619
38696
  stderr
38620
38697
  }
38621
- });
38698
+ };
38699
+ resolve2(result);
38622
38700
  });
38623
38701
  });
38624
38702
  }
@@ -38708,7 +38786,7 @@ var IosClient = class {
38708
38786
  }
38709
38787
  async tunnelStart(userspace = false) {
38710
38788
  const args = ["tunnel", "start", "--udid", this.udid, ...userspace ? ["--userspace"] : []];
38711
- logDetail2(`Spawning tunnel: ${this.iosPath} ${args.join(" ")}`);
38789
+ logDetail(`Spawning tunnel: ${this.iosPath} ${args.join(" ")}`);
38712
38790
  const child = (0, import_node_child_process.spawn)(this.iosPath, args, {
38713
38791
  windowsHide: true,
38714
38792
  env: {
@@ -38803,10 +38881,30 @@ var IosClient = class {
38803
38881
  };
38804
38882
 
38805
38883
  // src/logic/appleDeviceKit.ts
38806
- var { logInfo: logInfo7, logError: logError3, setNamespace: setNamespace6 } = createLoggers("apple-kit");
38884
+ var { logInfo: logInfo7, setNamespace: setNamespace6, logDataObject: logDataObject2 } = createLoggers("apple-kit");
38807
38885
  var AppleDeviceKit = class {
38808
38886
  constructor(udid, logicalPort, usbmuxdAddress) {
38809
38887
  this.logicalPort = logicalPort;
38888
+ const requiredEnvVars = {
38889
+ USBIPD_PATH: process.env.USBIPD_PATH,
38890
+ LOCKDOWN_WINDOWS_PATH: process.env.LOCKDOWN_WINDOWS_PATH,
38891
+ MDM_ENDPOINT: process.env.MDM_ENDPOINT,
38892
+ AUTH_API_URL: process.env.AUTH_API_URL,
38893
+ CREDENTIALS_PATH: process.env.CREDENTIALS_PATH,
38894
+ RESOURCES_PATH: process.env.RESOURCES_PATH,
38895
+ WIFI_SSID: process.env.WIFI_SSID,
38896
+ WIFI_PASSWORD: process.env.WIFI_PASSWORD,
38897
+ WIFI_ENCRYPTION: process.env.WIFI_ENCRYPTION,
38898
+ WIFI_HIDDEN: process.env.WIFI_HIDDEN,
38899
+ WIFI_ENTERPRISE: process.env.WIFI_ENTERPRISE,
38900
+ WIFI_EAP_TYPE: process.env.WIFI_EAP_TYPE,
38901
+ CERT_FILE: process.env.CERT_FILE,
38902
+ ORGANIZATION_NAME: process.env.ORGANIZATION_NAME
38903
+ };
38904
+ if (Object.values(requiredEnvVars).some((value) => !value)) {
38905
+ logDataObject2("Required environment variables are not set", requiredEnvVars);
38906
+ throw new Error("Required environment variables are not set");
38907
+ }
38810
38908
  this.deviceId = udid;
38811
38909
  setNamespace6(`apple-${udid}`);
38812
38910
  logInfo7(
@@ -38821,11 +38919,6 @@ var AppleDeviceKit = class {
38821
38919
  this.installActions = new InstallActions(this.deviceId, this.iosClient);
38822
38920
  this.activationFlow = new ActivationFlow(this.deviceId, this.iosClient);
38823
38921
  this.proxyActions = new ProxyActions(this.deviceId, this.iosClient);
38824
- this.iosClient.tunnelStart(true).then((process3) => {
38825
- this.tunnelProcess = process3;
38826
- }).catch((error) => {
38827
- logError3(`Failed to start tunnel: ${error.message}`);
38828
- });
38829
38922
  }
38830
38923
  deviceId;
38831
38924
  proxyProcess = null;
@@ -38856,13 +38949,6 @@ var AppleDeviceKit = class {
38856
38949
  this.ensureNotDisposed();
38857
38950
  return this.deviceActions.listDevices();
38858
38951
  }
38859
- /**
38860
- * Check if device is paired/trusted with this computer
38861
- */
38862
- async isPaired() {
38863
- this.ensureNotDisposed();
38864
- return this.deviceActions.isPaired();
38865
- }
38866
38952
  /**
38867
38953
  * Wait for device to be paired
38868
38954
  * Polls the pairing status until successful or timeout
@@ -38870,9 +38956,9 @@ var AppleDeviceKit = class {
38870
38956
  * @param timeout Timeout in milliseconds (default: 120000)
38871
38957
  * @param pollInterval Poll interval in milliseconds (default: 1000)
38872
38958
  */
38873
- async waitForPairing(timeout2 = 12e4, pollInterval = 1e3) {
38959
+ async waitForPairing(timeout2 = 12e4, pollInterval = 1e3, signal) {
38874
38960
  this.ensureNotDisposed();
38875
- return this.deviceActions.waitForPairing({ timeout: timeout2, pollInterval });
38961
+ return this.deviceActions.waitForPairing({ timeout: timeout2, pollInterval, signal });
38876
38962
  }
38877
38963
  /**
38878
38964
  * Attempt to pair/trust the device
@@ -38895,8 +38981,8 @@ var AppleDeviceKit = class {
38895
38981
  * @param onWaitingForTrust Callback when waiting for user to accept trust dialog
38896
38982
  * @returns true if device is now trusted
38897
38983
  */
38898
- async trustDevice(timeout2 = 6e4, onWaitingForTrust) {
38899
- return this.deviceActions.trustDevice({ timeout: timeout2, onWaitingForTrust });
38984
+ async trustDevice(timeout2 = 6e4, pollInterval = 1e3, onWaitingForTrust, signal) {
38985
+ return this.deviceActions.trustDevice({ timeout: timeout2, pollInterval, onWaitingForTrust, signal });
38900
38986
  }
38901
38987
  /**
38902
38988
  * Unpair/untrust the device
@@ -38994,14 +39080,16 @@ var AppleDeviceKit = class {
38994
39080
  * Activate the device using the activation flow.
38995
39081
  *
38996
39082
  * This flow can install WiFi/MDM/trust profiles and skip setup steps.
39083
+ * Returns { promise, events } so callers can attach listeners before the flow completes.
39084
+ * Pass an AbortSignal to cancel the flow (on each retry or between steps).
38997
39085
  *
38998
39086
  * Note: This requires a valid activation record or Apple server access.
38999
39087
  *
39000
39088
  * Precondition: the device must be paired and trusted.
39001
39089
  */
39002
- async activate() {
39090
+ activate(signal) {
39003
39091
  this.ensureNotDisposed();
39004
- return this.activationFlow.run();
39092
+ return this.activationFlow.run(void 0, signal);
39005
39093
  }
39006
39094
  /**
39007
39095
  * Get the device UDID
@@ -39058,6 +39146,10 @@ var AppleDeviceKit = class {
39058
39146
  };
39059
39147
  // Annotate the CommonJS export names for ESM import in node:
39060
39148
  0 && (module.exports = {
39149
+ ACTIVATION_FLOW_EVENT_ACTIVATION_DONE,
39150
+ ACTIVATION_FLOW_EVENT_MDM_PROFILE_INSTALLED,
39151
+ ACTIVATION_FLOW_EVENT_STEPS_SKIPPED,
39152
+ ACTIVATION_FLOW_EVENT_WIFI_INSTALLED,
39061
39153
  ActivationFlow,
39062
39154
  AppleDeviceKit,
39063
39155
  IosClient