@mcesystems/apple-kit 1.0.53 → 1.0.55

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.mjs CHANGED
@@ -33355,19 +33355,46 @@ async function unpair(udid) {
33355
33355
  }
33356
33356
 
33357
33357
  // src/logic/actions/install.ts
33358
- async function installApp(ipaPath, udid, options) {
33359
- if (options?.installViaMdm) {
33360
- logTask(`Installing app on device ${udid} via MDM`);
33361
- const mdmClient = await resolveMdmClient(options.mdm);
33362
- const mdmInstallOptions = getMdmInstallOptions(options.mdm);
33363
- await mdmClient.installApp(udid, mdmInstallOptions);
33364
- }
33365
- await installLocalApp(ipaPath, udid);
33366
- }
33367
33358
  async function installLocalApp(ipaPath, udid) {
33368
33359
  logTask(`Installing app ${ipaPath} on device ${udid}`);
33369
33360
  await runIDeviceTool("ideviceinstaller", ["-u", udid, "install", ipaPath]);
33370
33361
  }
33362
+ function getMdmInstallOptionsFromEnv() {
33363
+ const appId = process.env.MDM_APP_ID;
33364
+ const url = process.env.MDM_APP_URL;
33365
+ const waitForInstalled = parseBooleanEnv(process.env.MDM_APP_WAIT_FOR_INSTALLED);
33366
+ if (!appId && !url) {
33367
+ throw new Error("MDM install requires MDM_APP_ID or MDM_APP_URL.");
33368
+ }
33369
+ return {
33370
+ appId,
33371
+ url,
33372
+ waitForInstalled
33373
+ };
33374
+ }
33375
+ function parseBooleanEnv(value) {
33376
+ if (!value) {
33377
+ return void 0;
33378
+ }
33379
+ const normalized = value.trim().toLowerCase();
33380
+ if (normalized === "true" || normalized === "1" || normalized === "yes") {
33381
+ return true;
33382
+ }
33383
+ if (normalized === "false" || normalized === "0" || normalized === "no") {
33384
+ return false;
33385
+ }
33386
+ return void 0;
33387
+ }
33388
+ async function installManagedApp(ipaPath, udid, timeBetweenInstalls) {
33389
+ await installLocalApp(ipaPath, udid);
33390
+ const mdmInstallOptions = getMdmInstallOptionsFromEnv();
33391
+ const client = await createMdmClientFromEnv();
33392
+ logTask("Installing app via MDM for management takeover");
33393
+ await new Promise((resolve5) => setTimeout(resolve5, timeBetweenInstalls));
33394
+ if (client) {
33395
+ client.installApp(udid, mdmInstallOptions);
33396
+ }
33397
+ }
33371
33398
  async function uninstallApp(bundleId, udid) {
33372
33399
  logTask(`Uninstalling app ${bundleId} from device ${udid}`);
33373
33400
  if (!await isPaired(udid)) {
@@ -33452,33 +33479,6 @@ async function launchApp(bundleId, args, udid) {
33452
33479
  throw error;
33453
33480
  }
33454
33481
  }
33455
- async function resolveMdmClient(options) {
33456
- if (options?.client) {
33457
- return options.client;
33458
- }
33459
- if (options?.clientConfig) {
33460
- return createMdmClient(options.clientConfig);
33461
- }
33462
- const envClient = await createMdmClientFromEnv();
33463
- if (!envClient) {
33464
- throw new Error(
33465
- "MDM client not configured. Set MDM_ENDPOINT and MDM_CRED_PATH or pass mdm.client."
33466
- );
33467
- }
33468
- return envClient;
33469
- }
33470
- function getMdmInstallOptions(options) {
33471
- const appId = options?.appId;
33472
- const url = options?.url;
33473
- if (!appId && !url) {
33474
- throw new Error("MDM install requires an appId or url.");
33475
- }
33476
- return {
33477
- appId,
33478
- url,
33479
- waitForInstalled: options?.waitForInstalled
33480
- };
33481
- }
33482
33482
  async function launchAppWithPymobiledevice3(bundleId, args, udid) {
33483
33483
  logTask(`Launching app ${bundleId} using pymobiledevice3`);
33484
33484
  const { exec } = await import("node:child_process");
@@ -33655,7 +33655,6 @@ function killPortForwardProcess(process2) {
33655
33655
  }
33656
33656
 
33657
33657
  // src/logic/activationFlow.ts
33658
- import { existsSync as existsSync4 } from "node:fs";
33659
33658
  import { unlink, writeFile } from "node:fs/promises";
33660
33659
  import { tmpdir } from "node:os";
33661
33660
  import { dirname as dirname3, join as join7, resolve as resolve4 } from "node:path";
@@ -33967,16 +33966,9 @@ function createIosCli(iosBinaryPath) {
33967
33966
  // src/logic/activationFlow.ts
33968
33967
  var DEFAULT_RETRIES = 150;
33969
33968
  var DEFAULT_RETRY_DELAY_MS = 1e3;
33970
- var TIME_BETWEEN_INSTALLS = 5e3;
33971
- var TIME_TO_WAIT_FOR_MANAGED_APP_INSTALL = 1e4;
33972
- function sleep(ms) {
33973
- return new Promise((resolve5) => setTimeout(resolve5, ms));
33974
- }
33975
33969
  var ActivationFlow = class {
33976
33970
  iosCli;
33977
33971
  mdmClientPromise;
33978
- // private readonly organizationName?: string;
33979
- resourcesDir;
33980
33972
  constructor(config) {
33981
33973
  const iosBinaryPath = resolveIosBinaryPath(config);
33982
33974
  if (!iosBinaryPath) {
@@ -33984,7 +33976,6 @@ var ActivationFlow = class {
33984
33976
  }
33985
33977
  this.iosCli = createIosCli(iosBinaryPath);
33986
33978
  this.mdmClientPromise = createMdmClientFromEnv({ resourcesDir: config.resourcesDir });
33987
- this.resourcesDir = config.resourcesDir;
33988
33979
  }
33989
33980
  async run(udid) {
33990
33981
  logTask(`Starting activation flow for device ${udid}`);
@@ -33994,15 +33985,12 @@ var ActivationFlow = class {
33994
33985
  await this.retryActivateCommand("activate device", () => this.iosCli.activate(udid));
33995
33986
  } else {
33996
33987
  await this.retryIosCommand("wipe", () => this.iosCli.wipe(udid));
33997
- return "wiped";
33988
+ return void 0;
33998
33989
  }
33999
33990
  const wifiProfileIdentifier = await this.installWifiProfile(udid);
34000
33991
  await this.installMdmProfile(udid);
34001
33992
  await this.retryIosCommand("skip steps", () => this.iosCli.skipSteps(udid));
34002
- await this.installManagedApp(udid);
34003
- await sleep(TIME_TO_WAIT_FOR_MANAGED_APP_INSTALL);
34004
- await this.removeWifiProfile(udid, wifiProfileIdentifier);
34005
- return "activated";
33993
+ return () => this.removeWifiProfile(udid, wifiProfileIdentifier);
34006
33994
  }
34007
33995
  async installWifiProfile(udid) {
34008
33996
  const wifiProfile = await generateWifiProfileFromEnv();
@@ -34044,39 +34032,6 @@ var ActivationFlow = class {
34044
34032
  );
34045
34033
  await removeTempFile(profilePath, "mdm profile");
34046
34034
  }
34047
- // private async installTrustProfile(udid: string): Promise<void> {
34048
- // const resourcesProfilePath = getResourcesTrustProfilePath(this.resourcesDir);
34049
- // if (existsSync(resourcesProfilePath)) {
34050
- // logTask("Installing trust profile from resources");
34051
- // await this.retryIosCommand("install trust profile", () =>
34052
- // this.iosCli.installProfile(udid, resourcesProfilePath)
34053
- // );
34054
- // return;
34055
- // }
34056
- // if (!this.organizationName) {
34057
- // logError("ORGANIZATION_NAME is required to generate trust profile");
34058
- // throw new Error("ORGANIZATION_NAME is required for trust profile generation");
34059
- // }
34060
- // const trustProfile = await generateTrustProfileFromEnv(this.organizationName);
34061
- // if (!trustProfile) {
34062
- // return;
34063
- // }
34064
- // logTask("Generating trust profile and saving to resources");
34065
- // await ensureResourcesDirExists(this.resourcesDir);
34066
- // await writeFile(resourcesProfilePath, trustProfile, "utf-8");
34067
- // await this.retryIosCommand("install trust profile", () =>
34068
- // this.iosCli.installProfile(udid, resourcesProfilePath)
34069
- // );
34070
- // }
34071
- async installManagedApp(udid) {
34072
- const ipaPath = resolveManagedAppPath(this.resourcesDir);
34073
- await installLocalApp(ipaPath, udid);
34074
- const mdmInstallOptions = getMdmInstallOptionsFromEnv();
34075
- const client = await this.requireMdmClient();
34076
- logTask("Installing app via MDM for management takeover");
34077
- await sleep(TIME_BETWEEN_INSTALLS);
34078
- client.installApp(udid, mdmInstallOptions);
34079
- }
34080
34035
  async removeWifiProfile(udid, profileIdentifier) {
34081
34036
  if (!profileIdentifier) {
34082
34037
  return;
@@ -34132,40 +34087,6 @@ async function removeTempFile(filePath, label) {
34132
34087
  logError(`Failed to remove ${label} temp file: ${errorMsg}`);
34133
34088
  }
34134
34089
  }
34135
- function resolveManagedAppPath(resourcesDir) {
34136
- const resolvedResourcesDir = resolveResourcesDir(resourcesDir);
34137
- const ipaPath = join7(resolvedResourcesDir, "deviceagent.ipa");
34138
- if (!existsSync4(ipaPath)) {
34139
- throw new Error(`Managed app IPA not found at ${ipaPath}`);
34140
- }
34141
- return ipaPath;
34142
- }
34143
- function getMdmInstallOptionsFromEnv() {
34144
- const appId = process.env.MDM_APP_ID;
34145
- const url = process.env.MDM_APP_URL;
34146
- const waitForInstalled = parseBooleanEnv(process.env.MDM_APP_WAIT_FOR_INSTALLED);
34147
- if (!appId && !url) {
34148
- throw new Error("MDM install requires MDM_APP_ID or MDM_APP_URL.");
34149
- }
34150
- return {
34151
- appId,
34152
- url,
34153
- waitForInstalled
34154
- };
34155
- }
34156
- function parseBooleanEnv(value) {
34157
- if (!value) {
34158
- return void 0;
34159
- }
34160
- const normalized = value.trim().toLowerCase();
34161
- if (normalized === "true" || normalized === "1" || normalized === "yes") {
34162
- return true;
34163
- }
34164
- if (normalized === "false" || normalized === "0" || normalized === "no") {
34165
- return false;
34166
- }
34167
- return void 0;
34168
- }
34169
34090
  function getProfileIdentifierFromProfile(profile) {
34170
34091
  const pattern = /<key>PayloadIdentifier<\/key>\s*<string>([^<]+)<\/string>/g;
34171
34092
  const matches = [];
@@ -34312,9 +34233,9 @@ var AppleDeviceKit = class {
34312
34233
  *
34313
34234
  * @param ipaPath Path to the IPA file
34314
34235
  */
34315
- async installApp(ipaPath, options) {
34236
+ async installApp(ipaPath, timeBetweenInstalls = 1e4) {
34316
34237
  this.ensureNotDisposed();
34317
- installApp(ipaPath, this.deviceId, options);
34238
+ return installManagedApp(ipaPath, this.deviceId, timeBetweenInstalls);
34318
34239
  }
34319
34240
  /**
34320
34241
  * Uninstall an app by bundle ID (uninstall agent)