@mcesystems/apple-kit 1.0.51 → 1.0.53

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.
package/dist/index.js CHANGED
@@ -15027,19 +15027,19 @@ var require_printer = __commonJS({
15027
15027
  },
15028
15028
  // Document
15029
15029
  Document: function Document(node) {
15030
- return join10(node.definitions, "\n\n") + "\n";
15030
+ return join9(node.definitions, "\n\n") + "\n";
15031
15031
  },
15032
15032
  OperationDefinition: function OperationDefinition(node) {
15033
15033
  var op = node.operation;
15034
15034
  var name = node.name;
15035
- var varDefs = wrap("(", join10(node.variableDefinitions, ", "), ")");
15036
- var directives = join10(node.directives, " ");
15035
+ var varDefs = wrap("(", join9(node.variableDefinitions, ", "), ")");
15036
+ var directives = join9(node.directives, " ");
15037
15037
  var selectionSet = node.selectionSet;
15038
- return !name && !directives && !varDefs && op === "query" ? selectionSet : join10([op, join10([name, varDefs]), directives, selectionSet], " ");
15038
+ return !name && !directives && !varDefs && op === "query" ? selectionSet : join9([op, join9([name, varDefs]), directives, selectionSet], " ");
15039
15039
  },
15040
15040
  VariableDefinition: function VariableDefinition(_ref) {
15041
15041
  var variable = _ref.variable, type = _ref.type, defaultValue = _ref.defaultValue, directives = _ref.directives;
15042
- return variable + ": " + type + wrap(" = ", defaultValue) + wrap(" ", join10(directives, " "));
15042
+ return variable + ": " + type + wrap(" = ", defaultValue) + wrap(" ", join9(directives, " "));
15043
15043
  },
15044
15044
  SelectionSet: function SelectionSet(_ref2) {
15045
15045
  var selections = _ref2.selections;
@@ -15047,7 +15047,7 @@ var require_printer = __commonJS({
15047
15047
  },
15048
15048
  Field: function Field(_ref3) {
15049
15049
  var alias = _ref3.alias, name = _ref3.name, args = _ref3.arguments, directives = _ref3.directives, selectionSet = _ref3.selectionSet;
15050
- return join10([wrap("", alias, ": ") + name + wrap("(", join10(args, ", "), ")"), join10(directives, " "), selectionSet], " ");
15050
+ return join9([wrap("", alias, ": ") + name + wrap("(", join9(args, ", "), ")"), join9(directives, " "), selectionSet], " ");
15051
15051
  },
15052
15052
  Argument: function Argument(_ref4) {
15053
15053
  var name = _ref4.name, value = _ref4.value;
@@ -15056,18 +15056,18 @@ var require_printer = __commonJS({
15056
15056
  // Fragments
15057
15057
  FragmentSpread: function FragmentSpread(_ref5) {
15058
15058
  var name = _ref5.name, directives = _ref5.directives;
15059
- return "..." + name + wrap(" ", join10(directives, " "));
15059
+ return "..." + name + wrap(" ", join9(directives, " "));
15060
15060
  },
15061
15061
  InlineFragment: function InlineFragment(_ref6) {
15062
15062
  var typeCondition = _ref6.typeCondition, directives = _ref6.directives, selectionSet = _ref6.selectionSet;
15063
- return join10(["...", wrap("on ", typeCondition), join10(directives, " "), selectionSet], " ");
15063
+ return join9(["...", wrap("on ", typeCondition), join9(directives, " "), selectionSet], " ");
15064
15064
  },
15065
15065
  FragmentDefinition: function FragmentDefinition(_ref7) {
15066
15066
  var name = _ref7.name, typeCondition = _ref7.typeCondition, variableDefinitions = _ref7.variableDefinitions, directives = _ref7.directives, selectionSet = _ref7.selectionSet;
15067
15067
  return (
15068
15068
  // Note: fragment variable definitions are experimental and may be changed
15069
15069
  // or removed in the future.
15070
- "fragment ".concat(name).concat(wrap("(", join10(variableDefinitions, ", "), ")"), " ") + "on ".concat(typeCondition, " ").concat(wrap("", join10(directives, " "), " ")) + selectionSet
15070
+ "fragment ".concat(name).concat(wrap("(", join9(variableDefinitions, ", "), ")"), " ") + "on ".concat(typeCondition, " ").concat(wrap("", join9(directives, " "), " ")) + selectionSet
15071
15071
  );
15072
15072
  },
15073
15073
  // Value
@@ -15096,11 +15096,11 @@ var require_printer = __commonJS({
15096
15096
  },
15097
15097
  ListValue: function ListValue(_ref13) {
15098
15098
  var values = _ref13.values;
15099
- return "[" + join10(values, ", ") + "]";
15099
+ return "[" + join9(values, ", ") + "]";
15100
15100
  },
15101
15101
  ObjectValue: function ObjectValue(_ref14) {
15102
15102
  var fields = _ref14.fields;
15103
- return "{" + join10(fields, ", ") + "}";
15103
+ return "{" + join9(fields, ", ") + "}";
15104
15104
  },
15105
15105
  ObjectField: function ObjectField(_ref15) {
15106
15106
  var name = _ref15.name, value = _ref15.value;
@@ -15109,7 +15109,7 @@ var require_printer = __commonJS({
15109
15109
  // Directive
15110
15110
  Directive: function Directive(_ref16) {
15111
15111
  var name = _ref16.name, args = _ref16.arguments;
15112
- return "@" + name + wrap("(", join10(args, ", "), ")");
15112
+ return "@" + name + wrap("(", join9(args, ", "), ")");
15113
15113
  },
15114
15114
  // Type
15115
15115
  NamedType: function NamedType(_ref17) {
@@ -15127,7 +15127,7 @@ var require_printer = __commonJS({
15127
15127
  // Type System Definitions
15128
15128
  SchemaDefinition: function SchemaDefinition(_ref20) {
15129
15129
  var directives = _ref20.directives, operationTypes = _ref20.operationTypes;
15130
- return join10(["schema", join10(directives, " "), block(operationTypes)], " ");
15130
+ return join9(["schema", join9(directives, " "), block(operationTypes)], " ");
15131
15131
  },
15132
15132
  OperationTypeDefinition: function OperationTypeDefinition(_ref21) {
15133
15133
  var operation = _ref21.operation, type = _ref21.type;
@@ -15135,85 +15135,85 @@ var require_printer = __commonJS({
15135
15135
  },
15136
15136
  ScalarTypeDefinition: addDescription(function(_ref22) {
15137
15137
  var name = _ref22.name, directives = _ref22.directives;
15138
- return join10(["scalar", name, join10(directives, " ")], " ");
15138
+ return join9(["scalar", name, join9(directives, " ")], " ");
15139
15139
  }),
15140
15140
  ObjectTypeDefinition: addDescription(function(_ref23) {
15141
15141
  var name = _ref23.name, interfaces = _ref23.interfaces, directives = _ref23.directives, fields = _ref23.fields;
15142
- return join10(["type", name, wrap("implements ", join10(interfaces, " & ")), join10(directives, " "), block(fields)], " ");
15142
+ return join9(["type", name, wrap("implements ", join9(interfaces, " & ")), join9(directives, " "), block(fields)], " ");
15143
15143
  }),
15144
15144
  FieldDefinition: addDescription(function(_ref24) {
15145
15145
  var name = _ref24.name, args = _ref24.arguments, type = _ref24.type, directives = _ref24.directives;
15146
- return name + (hasMultilineItems(args) ? wrap("(\n", indent(join10(args, "\n")), "\n)") : wrap("(", join10(args, ", "), ")")) + ": " + type + wrap(" ", join10(directives, " "));
15146
+ return name + (hasMultilineItems(args) ? wrap("(\n", indent(join9(args, "\n")), "\n)") : wrap("(", join9(args, ", "), ")")) + ": " + type + wrap(" ", join9(directives, " "));
15147
15147
  }),
15148
15148
  InputValueDefinition: addDescription(function(_ref25) {
15149
15149
  var name = _ref25.name, type = _ref25.type, defaultValue = _ref25.defaultValue, directives = _ref25.directives;
15150
- return join10([name + ": " + type, wrap("= ", defaultValue), join10(directives, " ")], " ");
15150
+ return join9([name + ": " + type, wrap("= ", defaultValue), join9(directives, " ")], " ");
15151
15151
  }),
15152
15152
  InterfaceTypeDefinition: addDescription(function(_ref26) {
15153
15153
  var name = _ref26.name, directives = _ref26.directives, fields = _ref26.fields;
15154
- return join10(["interface", name, join10(directives, " "), block(fields)], " ");
15154
+ return join9(["interface", name, join9(directives, " "), block(fields)], " ");
15155
15155
  }),
15156
15156
  UnionTypeDefinition: addDescription(function(_ref27) {
15157
15157
  var name = _ref27.name, directives = _ref27.directives, types = _ref27.types;
15158
- return join10(["union", name, join10(directives, " "), types && types.length !== 0 ? "= " + join10(types, " | ") : ""], " ");
15158
+ return join9(["union", name, join9(directives, " "), types && types.length !== 0 ? "= " + join9(types, " | ") : ""], " ");
15159
15159
  }),
15160
15160
  EnumTypeDefinition: addDescription(function(_ref28) {
15161
15161
  var name = _ref28.name, directives = _ref28.directives, values = _ref28.values;
15162
- return join10(["enum", name, join10(directives, " "), block(values)], " ");
15162
+ return join9(["enum", name, join9(directives, " "), block(values)], " ");
15163
15163
  }),
15164
15164
  EnumValueDefinition: addDescription(function(_ref29) {
15165
15165
  var name = _ref29.name, directives = _ref29.directives;
15166
- return join10([name, join10(directives, " ")], " ");
15166
+ return join9([name, join9(directives, " ")], " ");
15167
15167
  }),
15168
15168
  InputObjectTypeDefinition: addDescription(function(_ref30) {
15169
15169
  var name = _ref30.name, directives = _ref30.directives, fields = _ref30.fields;
15170
- return join10(["input", name, join10(directives, " "), block(fields)], " ");
15170
+ return join9(["input", name, join9(directives, " "), block(fields)], " ");
15171
15171
  }),
15172
15172
  DirectiveDefinition: addDescription(function(_ref31) {
15173
15173
  var name = _ref31.name, args = _ref31.arguments, repeatable = _ref31.repeatable, locations = _ref31.locations;
15174
- return "directive @" + name + (hasMultilineItems(args) ? wrap("(\n", indent(join10(args, "\n")), "\n)") : wrap("(", join10(args, ", "), ")")) + (repeatable ? " repeatable" : "") + " on " + join10(locations, " | ");
15174
+ return "directive @" + name + (hasMultilineItems(args) ? wrap("(\n", indent(join9(args, "\n")), "\n)") : wrap("(", join9(args, ", "), ")")) + (repeatable ? " repeatable" : "") + " on " + join9(locations, " | ");
15175
15175
  }),
15176
15176
  SchemaExtension: function SchemaExtension(_ref32) {
15177
15177
  var directives = _ref32.directives, operationTypes = _ref32.operationTypes;
15178
- return join10(["extend schema", join10(directives, " "), block(operationTypes)], " ");
15178
+ return join9(["extend schema", join9(directives, " "), block(operationTypes)], " ");
15179
15179
  },
15180
15180
  ScalarTypeExtension: function ScalarTypeExtension(_ref33) {
15181
15181
  var name = _ref33.name, directives = _ref33.directives;
15182
- return join10(["extend scalar", name, join10(directives, " ")], " ");
15182
+ return join9(["extend scalar", name, join9(directives, " ")], " ");
15183
15183
  },
15184
15184
  ObjectTypeExtension: function ObjectTypeExtension(_ref34) {
15185
15185
  var name = _ref34.name, interfaces = _ref34.interfaces, directives = _ref34.directives, fields = _ref34.fields;
15186
- return join10(["extend type", name, wrap("implements ", join10(interfaces, " & ")), join10(directives, " "), block(fields)], " ");
15186
+ return join9(["extend type", name, wrap("implements ", join9(interfaces, " & ")), join9(directives, " "), block(fields)], " ");
15187
15187
  },
15188
15188
  InterfaceTypeExtension: function InterfaceTypeExtension(_ref35) {
15189
15189
  var name = _ref35.name, directives = _ref35.directives, fields = _ref35.fields;
15190
- return join10(["extend interface", name, join10(directives, " "), block(fields)], " ");
15190
+ return join9(["extend interface", name, join9(directives, " "), block(fields)], " ");
15191
15191
  },
15192
15192
  UnionTypeExtension: function UnionTypeExtension(_ref36) {
15193
15193
  var name = _ref36.name, directives = _ref36.directives, types = _ref36.types;
15194
- return join10(["extend union", name, join10(directives, " "), types && types.length !== 0 ? "= " + join10(types, " | ") : ""], " ");
15194
+ return join9(["extend union", name, join9(directives, " "), types && types.length !== 0 ? "= " + join9(types, " | ") : ""], " ");
15195
15195
  },
15196
15196
  EnumTypeExtension: function EnumTypeExtension(_ref37) {
15197
15197
  var name = _ref37.name, directives = _ref37.directives, values = _ref37.values;
15198
- return join10(["extend enum", name, join10(directives, " "), block(values)], " ");
15198
+ return join9(["extend enum", name, join9(directives, " "), block(values)], " ");
15199
15199
  },
15200
15200
  InputObjectTypeExtension: function InputObjectTypeExtension(_ref38) {
15201
15201
  var name = _ref38.name, directives = _ref38.directives, fields = _ref38.fields;
15202
- return join10(["extend input", name, join10(directives, " "), block(fields)], " ");
15202
+ return join9(["extend input", name, join9(directives, " "), block(fields)], " ");
15203
15203
  }
15204
15204
  };
15205
15205
  function addDescription(cb) {
15206
15206
  return function(node) {
15207
- return join10([node.description, cb(node)], "\n");
15207
+ return join9([node.description, cb(node)], "\n");
15208
15208
  };
15209
15209
  }
15210
- function join10(maybeArray, separator) {
15210
+ function join9(maybeArray, separator) {
15211
15211
  return maybeArray ? maybeArray.filter(function(x) {
15212
15212
  return x;
15213
15213
  }).join(separator || "") : "";
15214
15214
  }
15215
15215
  function block(array) {
15216
- return array && array.length !== 0 ? "{\n" + indent(join10(array, "\n")) + "\n}" : "";
15216
+ return array && array.length !== 0 ? "{\n" + indent(join9(array, "\n")) + "\n}" : "";
15217
15217
  }
15218
15218
  function wrap(start, maybeString, end) {
15219
15219
  return maybeString ? start + maybeString + (end || "") : "";
@@ -33375,12 +33375,11 @@ async function installApp(ipaPath, udid, options) {
33375
33375
  const mdmClient = await resolveMdmClient(options.mdm);
33376
33376
  const mdmInstallOptions = getMdmInstallOptions(options.mdm);
33377
33377
  await mdmClient.installApp(udid, mdmInstallOptions);
33378
- return;
33379
33378
  }
33379
+ await installLocalApp(ipaPath, udid);
33380
+ }
33381
+ async function installLocalApp(ipaPath, udid) {
33380
33382
  logTask(`Installing app ${ipaPath} on device ${udid}`);
33381
- if (!await isPaired(udid)) {
33382
- await waitForPairing(udid, 1e4);
33383
- }
33384
33383
  await runIDeviceTool("ideviceinstaller", ["-u", udid, "install", ipaPath]);
33385
33384
  }
33386
33385
  async function uninstallApp(bundleId, udid) {
@@ -33671,16 +33670,13 @@ function killPortForwardProcess(process2) {
33671
33670
 
33672
33671
  // src/logic/activationFlow.ts
33673
33672
  var import_node_fs4 = require("node:fs");
33674
- var import_promises3 = require("node:fs/promises");
33675
- var import_node_os3 = require("node:os");
33676
- var import_node_path8 = require("node:path");
33677
- var import_node_url2 = require("node:url");
33678
-
33679
- // src/utils/trustProfile.ts
33680
- var import_node_crypto2 = require("node:crypto");
33681
33673
  var import_promises2 = require("node:fs/promises");
33682
33674
  var import_node_os2 = require("node:os");
33683
33675
  var import_node_path7 = require("node:path");
33676
+ var import_node_url2 = require("node:url");
33677
+
33678
+ // src/utils/wifiProfile.ts
33679
+ var import_node_crypto2 = require("node:crypto");
33684
33680
 
33685
33681
  // src/utils/templateLoader.ts
33686
33682
  var import_node_fs3 = require("node:fs");
@@ -33770,56 +33766,7 @@ function escapeXml(str) {
33770
33766
  return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
33771
33767
  }
33772
33768
 
33773
- // src/utils/trustProfile.ts
33774
- async function generateTrustProfile(config, options) {
33775
- const {
33776
- organizationName,
33777
- certificateBase64,
33778
- certificateDisplayName = `${organizationName} Enterprise Certificate`,
33779
- profileDisplayName = `${organizationName} Enterprise Trust`
33780
- } = config;
33781
- const profileUuid = (0, import_node_crypto2.randomUUID)().toUpperCase();
33782
- const certificateUuid = (0, import_node_crypto2.randomUUID)().toUpperCase();
33783
- const orgShortName = organizationName.split(/\s+/)[0].toLowerCase();
33784
- const timestamp = Date.now();
33785
- const profileId = `com.${orgShortName}.enterprise.trust.${timestamp}`;
33786
- const payloadId = `${profileId}.cert`;
33787
- logInfo(`Generating trust profile for: ${organizationName}`);
33788
- const cleanCertBase64 = certificateBase64.replace(/-----BEGIN CERTIFICATE-----/g, "").replace(/-----END CERTIFICATE-----/g, "").replace(/\s/g, "");
33789
- const template = await loadTemplate("certificate-trust.xml", options?.plistDir);
33790
- const certificateFileName = `${orgShortName}_enterprise.cer`;
33791
- const variables = {
33792
- organizationName,
33793
- certificateBase64: cleanCertBase64,
33794
- certificateDescription: `Trusts ${organizationName} enterprise apps`,
33795
- certificateDisplayName,
33796
- profileDisplayName,
33797
- profileId,
33798
- profileUuid,
33799
- payloadId,
33800
- certificateUuid,
33801
- certificateFileName,
33802
- removalDisallowed: "false"
33803
- };
33804
- return processTemplate(template, variables);
33805
- }
33806
- async function generateTrustProfileFromEnv(organizationName, options) {
33807
- const certBase64 = process.env.TRUST_CERT_BASE64;
33808
- if (!certBase64) {
33809
- logInfo("TRUST_CERT_BASE64 environment variable not set, skipping trust profile generation.");
33810
- return void 0;
33811
- }
33812
- return generateTrustProfile(
33813
- {
33814
- organizationName,
33815
- certificateBase64: certBase64
33816
- },
33817
- options
33818
- );
33819
- }
33820
-
33821
33769
  // src/utils/wifiProfile.ts
33822
- var import_node_crypto3 = require("node:crypto");
33823
33770
  async function generateWifiProfile(config, options) {
33824
33771
  const {
33825
33772
  ssid,
@@ -33834,8 +33781,8 @@ async function generateWifiProfile(config, options) {
33834
33781
  eapType = "PEAP",
33835
33782
  acceptAnyCertificate = true
33836
33783
  } = config;
33837
- const profileUuid = (0, import_node_crypto3.randomUUID)().toUpperCase();
33838
- const payloadUuid = (0, import_node_crypto3.randomUUID)().toUpperCase();
33784
+ const profileUuid = (0, import_node_crypto2.randomUUID)().toUpperCase();
33785
+ const payloadUuid = (0, import_node_crypto2.randomUUID)().toUpperCase();
33839
33786
  const profileId = `com.mce.wifi.${ssid.replace(/[^a-zA-Z0-9]/g, "")}.${Date.now()}`;
33840
33787
  const payloadId = `${profileId}.payload`;
33841
33788
  logInfo(`Generating WiFi profile for SSID: ${ssid}, encryption: ${encryptionType}`);
@@ -34006,6 +33953,9 @@ function createIosCli(iosBinaryPath) {
34006
33953
  async installProfile(deviceId, profilePath) {
34007
33954
  return runIosCommand(iosBinaryPath, ["profile", "add", profilePath, "--udid", deviceId]);
34008
33955
  },
33956
+ async removeProfile(deviceId, profileName) {
33957
+ return runIosCommand(iosBinaryPath, ["profile", "remove", profileName, "--udid", deviceId]);
33958
+ },
34009
33959
  async skipSteps(deviceId) {
34010
33960
  return runIosCommand(iosBinaryPath, ["prepare", "--skip-all", "--udid", deviceId]);
34011
33961
  },
@@ -34032,11 +33982,16 @@ function createIosCli(iosBinaryPath) {
34032
33982
  // src/logic/activationFlow.ts
34033
33983
  var import_meta3 = {};
34034
33984
  var DEFAULT_RETRIES = 150;
34035
- var DEFAULT_RETRY_DELAY_MS = 2e3;
33985
+ var DEFAULT_RETRY_DELAY_MS = 1e3;
33986
+ var TIME_BETWEEN_INSTALLS = 5e3;
33987
+ var TIME_TO_WAIT_FOR_MANAGED_APP_INSTALL = 1e4;
33988
+ function sleep(ms) {
33989
+ return new Promise((resolve5) => setTimeout(resolve5, ms));
33990
+ }
34036
33991
  var ActivationFlow = class {
34037
33992
  iosCli;
34038
33993
  mdmClientPromise;
34039
- organizationName;
33994
+ // private readonly organizationName?: string;
34040
33995
  resourcesDir;
34041
33996
  constructor(config) {
34042
33997
  const iosBinaryPath = resolveIosBinaryPath(config);
@@ -34045,7 +34000,6 @@ var ActivationFlow = class {
34045
34000
  }
34046
34001
  this.iosCli = createIosCli(iosBinaryPath);
34047
34002
  this.mdmClientPromise = createMdmClientFromEnv({ resourcesDir: config.resourcesDir });
34048
- this.organizationName = config.organizationName ?? process.env.ORGANIZATION_NAME;
34049
34003
  this.resourcesDir = config.resourcesDir;
34050
34004
  }
34051
34005
  async run(udid) {
@@ -34058,25 +34012,27 @@ var ActivationFlow = class {
34058
34012
  await this.retryIosCommand("wipe", () => this.iosCli.wipe(udid));
34059
34013
  return "wiped";
34060
34014
  }
34061
- await this.installWifiProfile(udid);
34015
+ const wifiProfileIdentifier = await this.installWifiProfile(udid);
34062
34016
  await this.installMdmProfile(udid);
34063
- await this.installTrustProfile(udid);
34064
- await this.installResourcesIpa(udid);
34065
34017
  await this.retryIosCommand("skip steps", () => this.iosCli.skipSteps(udid));
34018
+ await this.installManagedApp(udid);
34019
+ await sleep(TIME_TO_WAIT_FOR_MANAGED_APP_INSTALL);
34020
+ await this.removeWifiProfile(udid, wifiProfileIdentifier);
34066
34021
  return "activated";
34067
34022
  }
34068
34023
  async installWifiProfile(udid) {
34069
- const plistDir = this.resourcesDir ? resolveResourcesPlistDir(this.resourcesDir) : void 0;
34070
- const wifiProfile = await generateWifiProfileFromEnv({ plistDir });
34024
+ const wifiProfile = await generateWifiProfileFromEnv();
34071
34025
  if (!wifiProfile) {
34072
- return;
34026
+ return void 0;
34073
34027
  }
34074
34028
  const wifiProfilePath = await saveWifiProfileToTemp(wifiProfile);
34029
+ const wifiProfileIdentifier = getProfileIdentifierFromProfile(wifiProfile);
34075
34030
  await this.retryIosCommand(
34076
34031
  "install wifi profile",
34077
34032
  () => this.iosCli.installProfile(udid, wifiProfilePath)
34078
34033
  );
34079
34034
  await removeTempFile(wifiProfilePath, "wifi profile");
34035
+ return wifiProfileIdentifier;
34080
34036
  }
34081
34037
  async getActivationState(udid) {
34082
34038
  const infoResult = await this.retryIosCommand("device info", () => this.iosCli.info(udid));
@@ -34087,15 +34043,6 @@ var ActivationFlow = class {
34087
34043
  return activationState;
34088
34044
  }
34089
34045
  async installMdmProfile(udid) {
34090
- const offlineProfilePath = getResourcesEnrollmentProfilePath(this.resourcesDir, udid);
34091
- if (offlineProfilePath) {
34092
- logTask("Installing MDM enrollment profile from resources");
34093
- await this.retryIosCommand(
34094
- "install mdm profile",
34095
- () => this.iosCli.installProfile(udid, offlineProfilePath)
34096
- );
34097
- return;
34098
- }
34099
34046
  const client = await this.requireMdmClient();
34100
34047
  logTask("Installing MDM enrollment profile");
34101
34048
  const enrollmentProfile = await this.retry(
@@ -34113,46 +34060,47 @@ var ActivationFlow = class {
34113
34060
  );
34114
34061
  await removeTempFile(profilePath, "mdm profile");
34115
34062
  }
34116
- async installTrustProfile(udid) {
34117
- const resourcesProfilePath = getResourcesTrustProfilePath(this.resourcesDir);
34118
- if ((0, import_node_fs4.existsSync)(resourcesProfilePath)) {
34119
- logTask("Installing trust profile from resources");
34120
- await this.retryIosCommand(
34121
- "install trust profile",
34122
- () => this.iosCli.installProfile(udid, resourcesProfilePath)
34123
- );
34124
- return;
34125
- }
34126
- if (!this.organizationName) {
34127
- logError("ORGANIZATION_NAME is required to generate trust profile");
34128
- throw new Error("ORGANIZATION_NAME is required for trust profile generation");
34129
- }
34130
- const plistDir = this.resourcesDir ? resolveResourcesPlistDir(this.resourcesDir) : void 0;
34131
- const trustProfile = await generateTrustProfileFromEnv(this.organizationName, { plistDir });
34132
- if (!trustProfile) {
34133
- return;
34134
- }
34135
- logTask("Generating trust profile and saving to resources");
34136
- await ensureResourcesDirExists(this.resourcesDir);
34137
- await (0, import_promises3.writeFile)(resourcesProfilePath, trustProfile, "utf-8");
34138
- await this.retryIosCommand(
34139
- "install trust profile",
34140
- () => this.iosCli.installProfile(udid, resourcesProfilePath)
34141
- );
34063
+ // private async installTrustProfile(udid: string): Promise<void> {
34064
+ // const resourcesProfilePath = getResourcesTrustProfilePath(this.resourcesDir);
34065
+ // if (existsSync(resourcesProfilePath)) {
34066
+ // logTask("Installing trust profile from resources");
34067
+ // await this.retryIosCommand("install trust profile", () =>
34068
+ // this.iosCli.installProfile(udid, resourcesProfilePath)
34069
+ // );
34070
+ // return;
34071
+ // }
34072
+ // if (!this.organizationName) {
34073
+ // logError("ORGANIZATION_NAME is required to generate trust profile");
34074
+ // throw new Error("ORGANIZATION_NAME is required for trust profile generation");
34075
+ // }
34076
+ // const trustProfile = await generateTrustProfileFromEnv(this.organizationName);
34077
+ // if (!trustProfile) {
34078
+ // return;
34079
+ // }
34080
+ // logTask("Generating trust profile and saving to resources");
34081
+ // await ensureResourcesDirExists(this.resourcesDir);
34082
+ // await writeFile(resourcesProfilePath, trustProfile, "utf-8");
34083
+ // await this.retryIosCommand("install trust profile", () =>
34084
+ // this.iosCli.installProfile(udid, resourcesProfilePath)
34085
+ // );
34086
+ // }
34087
+ async installManagedApp(udid) {
34088
+ const ipaPath = resolveManagedAppPath(this.resourcesDir);
34089
+ await installLocalApp(ipaPath, udid);
34090
+ const mdmInstallOptions = getMdmInstallOptionsFromEnv();
34091
+ const client = await this.requireMdmClient();
34092
+ logTask("Installing app via MDM for management takeover");
34093
+ await sleep(TIME_BETWEEN_INSTALLS);
34094
+ client.installApp(udid, mdmInstallOptions);
34142
34095
  }
34143
- async installResourcesIpa(udid) {
34144
- const ipaPath = await getResourcesIpaPath(this.resourcesDir);
34145
- if (!ipaPath) {
34096
+ async removeWifiProfile(udid, profileIdentifier) {
34097
+ if (!profileIdentifier) {
34146
34098
  return;
34147
34099
  }
34148
- logTask(`Installing IPA from resources: ${ipaPath}`);
34149
- await this.retry(
34150
- "install ipa",
34151
- async () => {
34152
- await installApp(ipaPath, udid);
34153
- return true;
34154
- },
34155
- (result) => result
34100
+ logTask("Removing WiFi profile");
34101
+ await this.retryIosCommand(
34102
+ "remove wifi profile",
34103
+ () => this.iosCli.removeProfile(udid, profileIdentifier)
34156
34104
  );
34157
34105
  }
34158
34106
  async requireMdmClient() {
@@ -34186,88 +34134,75 @@ var ActivationFlow = class {
34186
34134
  }
34187
34135
  };
34188
34136
  async function saveProfileToTemp(profile, prefix) {
34189
- const tempFilePath = (0, import_node_path8.join)((0, import_node_os3.tmpdir)(), `mce_${prefix}_${Date.now()}.mobileconfig`);
34190
- await (0, import_promises3.writeFile)(tempFilePath, profile, "utf-8");
34137
+ const tempFilePath = (0, import_node_path7.join)((0, import_node_os2.tmpdir)(), `mce_${prefix}_${Date.now()}.mobileconfig`);
34138
+ await (0, import_promises2.writeFile)(tempFilePath, profile, "utf-8");
34191
34139
  logInfo(`Profile saved to: ${tempFilePath}`);
34192
34140
  return tempFilePath;
34193
34141
  }
34194
34142
  async function removeTempFile(filePath, label) {
34195
34143
  try {
34196
- await (0, import_promises3.unlink)(filePath);
34144
+ await (0, import_promises2.unlink)(filePath);
34197
34145
  logInfo(`Removed ${label} temp file: ${filePath}`);
34198
34146
  } catch (error) {
34199
34147
  const errorMsg = error instanceof Error ? error.message : String(error);
34200
34148
  logError(`Failed to remove ${label} temp file: ${errorMsg}`);
34201
34149
  }
34202
34150
  }
34203
- function getResourcesTrustProfilePath(resourcesDir) {
34151
+ function resolveManagedAppPath(resourcesDir) {
34204
34152
  const resolvedResourcesDir = resolveResourcesDir(resourcesDir);
34205
- return (0, import_node_path8.join)(resolvedResourcesDir, "trust_profile.mobileconfig");
34206
- }
34207
- async function ensureResourcesDirExists(resourcesDir) {
34208
- const resolvedResourcesDir = resolveResourcesDir(resourcesDir);
34209
- await (0, import_promises3.mkdir)(resolvedResourcesDir, { recursive: true });
34210
- }
34211
- function resolveResourcesDir(resourcesDir) {
34212
- if (resourcesDir) {
34213
- return (0, import_node_path8.resolve)(resourcesDir);
34153
+ const ipaPath = (0, import_node_path7.join)(resolvedResourcesDir, "deviceagent.ipa");
34154
+ if (!(0, import_node_fs4.existsSync)(ipaPath)) {
34155
+ throw new Error(`Managed app IPA not found at ${ipaPath}`);
34214
34156
  }
34215
- const currentFile = (0, import_node_url2.fileURLToPath)(import_meta3.url);
34216
- const currentDir = (0, import_node_path8.dirname)(currentFile);
34217
- const packageRoot = (0, import_node_path8.join)(currentDir, "..", "..");
34218
- return (0, import_node_path8.join)(packageRoot, "resources");
34157
+ return ipaPath;
34219
34158
  }
34220
- function resolveResourcesPlistDir(resourcesDir) {
34221
- return (0, import_node_path8.join)(resolveResourcesDir(resourcesDir), "plist");
34159
+ function getMdmInstallOptionsFromEnv() {
34160
+ const appId = process.env.MDM_APP_ID;
34161
+ const url = process.env.MDM_APP_URL;
34162
+ const waitForInstalled = parseBooleanEnv(process.env.MDM_APP_WAIT_FOR_INSTALLED);
34163
+ if (!appId && !url) {
34164
+ throw new Error("MDM install requires MDM_APP_ID or MDM_APP_URL.");
34165
+ }
34166
+ return {
34167
+ appId,
34168
+ url,
34169
+ waitForInstalled
34170
+ };
34222
34171
  }
34223
- async function getResourcesIpaPath(resourcesDir) {
34224
- const resolvedResourcesDir = resolveResourcesDir(resourcesDir);
34225
- const candidateDirs = [resolvedResourcesDir, (0, import_node_path8.join)(resolvedResourcesDir, "apps")];
34226
- for (const dir of candidateDirs) {
34227
- const entries = await safeReadDir(dir);
34228
- if (!entries) {
34229
- continue;
34230
- }
34231
- for (const entry of entries) {
34232
- if (!entry.isFile()) {
34233
- continue;
34234
- }
34235
- const name = entry.name.toLowerCase();
34236
- if (name.endsWith(".ipa")) {
34237
- return (0, import_node_path8.join)(dir, entry.name);
34238
- }
34239
- }
34172
+ function parseBooleanEnv(value) {
34173
+ if (!value) {
34174
+ return void 0;
34175
+ }
34176
+ const normalized = value.trim().toLowerCase();
34177
+ if (normalized === "true" || normalized === "1" || normalized === "yes") {
34178
+ return true;
34179
+ }
34180
+ if (normalized === "false" || normalized === "0" || normalized === "no") {
34181
+ return false;
34240
34182
  }
34241
34183
  return void 0;
34242
34184
  }
34243
- function isErrorWithCode(error) {
34244
- return typeof error === "object" && error !== null && "code" in error;
34245
- }
34246
- async function safeReadDir(dir) {
34247
- try {
34248
- return await (0, import_promises3.readdir)(dir, { withFileTypes: true });
34249
- } catch (error) {
34250
- if (isErrorWithCode(error) && typeof error.code === "string" && error.code === "ENOENT") {
34251
- return void 0;
34252
- }
34253
- const errorMsg = error instanceof Error ? error.message : String(error);
34254
- logError(`Failed to read resources directory ${dir}: ${errorMsg}`);
34185
+ function getProfileIdentifierFromProfile(profile) {
34186
+ const pattern = /<key>PayloadIdentifier<\/key>\s*<string>([^<]+)<\/string>/g;
34187
+ const matches = [];
34188
+ let match = pattern.exec(profile);
34189
+ while (match) {
34190
+ matches.push(match[1].trim());
34191
+ match = pattern.exec(profile);
34192
+ }
34193
+ if (matches.length === 0) {
34255
34194
  return void 0;
34256
34195
  }
34196
+ return matches[matches.length - 1];
34257
34197
  }
34258
- function getResourcesEnrollmentProfilePath(resourcesDir, udid) {
34259
- const baseDir = resolveResourcesDir(resourcesDir);
34260
- const mdmDir = (0, import_node_path8.join)(baseDir, "mdm");
34261
- const candidates = [
34262
- udid ? (0, import_node_path8.join)(mdmDir, `enrollment_${udid}.mobileconfig`) : void 0,
34263
- (0, import_node_path8.join)(mdmDir, "enrollment.mobileconfig")
34264
- ];
34265
- for (const candidate of candidates) {
34266
- if (candidate && (0, import_node_fs4.existsSync)(candidate)) {
34267
- return candidate;
34268
- }
34198
+ function resolveResourcesDir(resourcesDir) {
34199
+ if (resourcesDir) {
34200
+ return (0, import_node_path7.resolve)(resourcesDir);
34269
34201
  }
34270
- return void 0;
34202
+ const currentFile = (0, import_node_url2.fileURLToPath)(import_meta3.url);
34203
+ const currentDir = (0, import_node_path7.dirname)(currentFile);
34204
+ const packageRoot = (0, import_node_path7.join)(currentDir, "..", "..");
34205
+ return (0, import_node_path7.join)(packageRoot, "resources");
34271
34206
  }
34272
34207
  function resolveIosBinaryPath(config) {
34273
34208
  if (config.iosBinaryPath) {
@@ -34278,7 +34213,7 @@ function resolveIosBinaryPath(config) {
34278
34213
  }
34279
34214
  const platform = process.platform;
34280
34215
  const binaryName = platform === "win32" ? "ios.exe" : "ios";
34281
- return (0, import_node_path8.join)(resolveResourcesDir(config.resourcesDir), "ios", "bin", platform, binaryName);
34216
+ return (0, import_node_path7.join)(resolveResourcesDir(config.resourcesDir), "ios", "bin", platform, binaryName);
34282
34217
  }
34283
34218
  function getActivationState2(output) {
34284
34219
  if (!Array.isArray(output) || output.length === 0) {
@@ -34553,7 +34488,7 @@ var AppleDeviceKit = class {
34553
34488
 
34554
34489
  // src/logic/actions/usbmuxd.ts
34555
34490
  var import_node_child_process4 = require("node:child_process");
34556
- var import_node_path9 = require("node:path");
34491
+ var import_node_path8 = require("node:path");
34557
34492
  var usbmuxdProcess = null;
34558
34493
  function startUsbmuxd(foreground = false, options) {
34559
34494
  const current = usbmuxdProcess;
@@ -34563,7 +34498,7 @@ function startUsbmuxd(foreground = false, options) {
34563
34498
  }
34564
34499
  const binPath = getResourcesBinPath({ resourcesDir: options?.resourcesDir });
34565
34500
  const ext = process.platform === "win32" ? ".exe" : "";
34566
- const toolPath = binPath ? (0, import_node_path9.join)(binPath, `usbmuxd${ext}`) : `usbmuxd${ext}`;
34501
+ const toolPath = binPath ? (0, import_node_path8.join)(binPath, `usbmuxd${ext}`) : `usbmuxd${ext}`;
34567
34502
  const args = foreground ? ["-f"] : [];
34568
34503
  const spawnOptions = {
34569
34504
  windowsHide: true,