@mcesystems/apple-kit 1.0.71 → 1.0.73

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
@@ -865,55 +865,172 @@ var require_src = __commonJS({
865
865
  }
866
866
  });
867
867
  var import_debug = __toESM2(require_src());
868
- var logInfo = (0, import_debug.default)("info");
869
- var logTask = (0, import_debug.default)("task");
870
- var logError = (0, import_debug.default)("error");
871
- var logDetail = (0, import_debug.default)("detail");
872
- var logDebug = (0, import_debug.default)("debug");
873
- var logWarning = (0, import_debug.default)("warning");
874
- var logColor = (0, import_debug.default)("color");
875
- logInfo.color = "19";
876
- logTask.color = "25";
877
- logError.color = "1";
878
- logDetail.color = "199";
879
- logWarning.color = "186";
880
- logDebug.color = "211";
881
- logColor.enabled = true;
882
- function logNamespace(namespace) {
883
- logInfo.namespace = `${namespace}:info`;
884
- logTask.namespace = `${namespace}:task`;
885
- logError.namespace = `${namespace}:error`;
886
- logDetail.namespace = `${namespace}:detail`;
887
- logWarning.namespace = `${namespace}:warning`;
888
- logDebug.namespace = `${namespace}:debug`;
889
- }
890
- function setLogLevel(level) {
891
- switch (level) {
892
- case "info":
893
- logInfo.enabled = true;
894
- logTask.enabled = true;
895
- logError.enabled = true;
896
- logWarning.enabled = true;
897
- logDetail.enabled = false;
898
- logDebug.enabled = false;
899
- break;
900
- case "debug":
901
- logInfo.enabled = true;
902
- logTask.enabled = true;
903
- logError.enabled = true;
904
- logWarning.enabled = true;
905
- logDetail.enabled = true;
906
- logDebug.enabled = true;
907
- break;
908
- case "none":
909
- logInfo.enabled = false;
910
- logTask.enabled = false;
911
- logError.enabled = false;
912
- logWarning.enabled = false;
913
- logDetail.enabled = false;
914
- logDebug.enabled = false;
915
- break;
868
+ function createLoggers(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
869
+ const logInfo9 = (0, import_debug.default)(`${namespace}:info`);
870
+ const logTask6 = (0, import_debug.default)(`${namespace}:task`);
871
+ const logError5 = (0, import_debug.default)(`${namespace}:error`);
872
+ const logDetail2 = (0, import_debug.default)(`${namespace}:detail`);
873
+ const logDebug = (0, import_debug.default)(`${namespace}:debug`);
874
+ const logWarning2 = (0, import_debug.default)(`${namespace}:warning`);
875
+ const logColor = (0, import_debug.default)(`${namespace}:color`);
876
+ logInfo9.color = "19";
877
+ logTask6.color = "25";
878
+ logError5.color = "1";
879
+ logDetail2.color = "199";
880
+ logWarning2.color = "186";
881
+ logDebug.color = "211";
882
+ logColor.enabled = true;
883
+ function setNamespace2(namespace2) {
884
+ logInfo9.namespace = `${namespace2}:info`;
885
+ logTask6.namespace = `${namespace2}:task`;
886
+ logError5.namespace = `${namespace2}:error`;
887
+ logDetail2.namespace = `${namespace2}:detail`;
888
+ logWarning2.namespace = `${namespace2}:warning`;
889
+ logDebug.namespace = `${namespace2}:debug`;
890
+ }
891
+ function setLogLevel(level) {
892
+ switch (level) {
893
+ case "info":
894
+ logInfo9.enabled = true;
895
+ logTask6.enabled = true;
896
+ logError5.enabled = true;
897
+ logWarning2.enabled = true;
898
+ logDetail2.enabled = false;
899
+ logDebug.enabled = false;
900
+ break;
901
+ case "debug":
902
+ logInfo9.enabled = true;
903
+ logTask6.enabled = true;
904
+ logError5.enabled = true;
905
+ logWarning2.enabled = true;
906
+ logDetail2.enabled = true;
907
+ logDebug.enabled = true;
908
+ break;
909
+ case "none":
910
+ logInfo9.enabled = false;
911
+ logTask6.enabled = false;
912
+ logError5.enabled = false;
913
+ logWarning2.enabled = false;
914
+ logDetail2.enabled = false;
915
+ logDebug.enabled = false;
916
+ break;
917
+ }
918
+ }
919
+ setLogLevel(logLevel);
920
+ function setColors(type, color) {
921
+ switch (type) {
922
+ case "info":
923
+ logInfo9.color = color;
924
+ break;
925
+ case "task":
926
+ logTask6.color = color;
927
+ break;
928
+ case "error":
929
+ logError5.color = color;
930
+ break;
931
+ case "detail":
932
+ logDetail2.color = color;
933
+ break;
934
+ case "warning":
935
+ logWarning2.color = color;
936
+ break;
937
+ case "debug":
938
+ logDebug.color = color;
939
+ break;
940
+ default:
941
+ throw new Error(`Invalid log type: ${type}`);
942
+ }
943
+ }
944
+ function printColors() {
945
+ for (let i = 0; i < 256; i++) {
946
+ logColor.color = `${i}`;
947
+ logColor(`${i}: ${i}`);
948
+ }
949
+ }
950
+ function logDataDetail(data, prefix = "# ") {
951
+ if (data === null || data === void 0) {
952
+ return `${prefix}<null or undefined>`;
953
+ }
954
+ if (typeof data !== "object") {
955
+ return `${prefix}${String(data)}`;
956
+ }
957
+ const keys = Object.keys(data);
958
+ let result = "";
959
+ for (const key of keys) {
960
+ result += `${prefix}${key}: `;
961
+ if (key in data) {
962
+ let dataKey = key;
963
+ if (key in data) {
964
+ dataKey = key;
965
+ const value = data[dataKey];
966
+ if (value === null || value === void 0) {
967
+ result += `<${value === null ? "null" : "undefined"}>
968
+ `;
969
+ } else if (typeof value === "object") {
970
+ result += `
971
+ ${logDataDetail(value, `${prefix} `)}
972
+ `;
973
+ } else {
974
+ result += `${value}
975
+ `;
976
+ }
977
+ }
978
+ }
979
+ }
980
+ return result.trim();
981
+ }
982
+ function header(title, padding = 0) {
983
+ return `${" ".repeat(padding)}${"=".repeat(80)}
984
+ ${" ".repeat(40 - title.length / 2)}${title}
985
+ ${" ".repeat(padding)}${"=".repeat(80)}`;
986
+ }
987
+ function logHeader(title) {
988
+ logInfo9(`${header(title, 2)}`);
989
+ }
990
+ function logDataObject2(title, ...args) {
991
+ const stack = new Error().stack?.split("\n")[2] || "";
992
+ const stackMatch = stack.match(/\((.*):(\d+):(\d+)\)$/) || stack.match(/at (.*):(\d+):(\d+)$/);
993
+ let callerDetails = "";
994
+ if (stackMatch) {
995
+ const functionMatch = stack.match(/at (.+) \(/);
996
+ const functionName = functionMatch ? functionMatch[1] : "<anonymous>";
997
+ callerDetails = `${functionName}`;
998
+ }
999
+ logDetail2(`${header(`*${title}* ${callerDetails}`)}
1000
+ ${args.reduce((acc, arg) => `${acc}
1001
+ ${logDataDetail(arg)}`, "")}
1002
+
1003
+ ${"=".repeat(80)}`);
916
1004
  }
1005
+ function logErrorObject(error, extraDetails) {
1006
+ if (error instanceof Error) {
1007
+ logError5(`${extraDetails ? header(extraDetails, 1) : header(error.message, 1)}
1008
+ Error Message:
1009
+ ${error.message}
1010
+ Error Stack:
1011
+ ${error.stack}
1012
+ ${"=".repeat(80)}`);
1013
+ } else {
1014
+ logError5(`${extraDetails ? header(extraDetails, 1) : header(String(error), 1)}
1015
+ ${"=".repeat(80)}`);
1016
+ }
1017
+ }
1018
+ return {
1019
+ logInfo: logInfo9,
1020
+ logTask: logTask6,
1021
+ logError: logError5,
1022
+ logDetail: logDetail2,
1023
+ logDebug,
1024
+ logWarning: logWarning2,
1025
+ logColor,
1026
+ setColors,
1027
+ printColors,
1028
+ logHeader,
1029
+ logDataObject: logDataObject2,
1030
+ logErrorObject,
1031
+ setLogLevel,
1032
+ setNamespace: setNamespace2
1033
+ };
917
1034
  }
918
1035
 
919
1036
  // ../../node_modules/.pnpm/get-port@7.1.0/node_modules/get-port/index.js
@@ -1052,6 +1169,7 @@ function portNumbers(from, to) {
1052
1169
  }
1053
1170
 
1054
1171
  // src/logic/actions/device.ts
1172
+ var { logTask } = createLoggers("apple-kit:device");
1055
1173
  async function info(udid, iosCli2) {
1056
1174
  logTask(`Getting device info for ${udid}`);
1057
1175
  const result = await iosCli2.info(udid);
@@ -11083,14 +11201,14 @@ var require_form_data = __commonJS2({
11083
11201
  this._error(new Error("Arrays are not supported."));
11084
11202
  return;
11085
11203
  }
11086
- var header2 = this._multiPartHeader(field, value, options);
11204
+ var header = this._multiPartHeader(field, value, options);
11087
11205
  var footer = this._multiPartFooter();
11088
- append(header2);
11206
+ append(header);
11089
11207
  append(value);
11090
11208
  append(footer);
11091
- this._trackLength(header2, value, options);
11209
+ this._trackLength(header, value, options);
11092
11210
  };
11093
- FormData2.prototype._trackLength = function(header2, value, options) {
11211
+ FormData2.prototype._trackLength = function(header, value, options) {
11094
11212
  var valueLength = 0;
11095
11213
  if (options.knownLength != null) {
11096
11214
  valueLength += Number(options.knownLength);
@@ -11100,7 +11218,7 @@ var require_form_data = __commonJS2({
11100
11218
  valueLength = Buffer.byteLength(value);
11101
11219
  }
11102
11220
  this._valueLength += valueLength;
11103
- this._overheadLength += Buffer.byteLength(header2) + FormData2.LINE_BREAK.length;
11221
+ this._overheadLength += Buffer.byteLength(header) + FormData2.LINE_BREAK.length;
11104
11222
  if (!value || !value.path && !(value.readable && hasOwn(value, "httpVersion")) && !(value instanceof Stream)) {
11105
11223
  return;
11106
11224
  }
@@ -11150,18 +11268,18 @@ var require_form_data = __commonJS2({
11150
11268
  if (typeof options.header === "object") {
11151
11269
  populate(headers, options.header);
11152
11270
  }
11153
- var header2;
11271
+ var header;
11154
11272
  for (var prop in headers) {
11155
11273
  if (hasOwn(headers, prop)) {
11156
- header2 = headers[prop];
11157
- if (header2 == null) {
11274
+ header = headers[prop];
11275
+ if (header == null) {
11158
11276
  continue;
11159
11277
  }
11160
- if (!Array.isArray(header2)) {
11161
- header2 = [header2];
11278
+ if (!Array.isArray(header)) {
11279
+ header = [header];
11162
11280
  }
11163
- if (header2.length) {
11164
- contents += prop + ": " + header2.join("; ") + FormData2.LINE_BREAK;
11281
+ if (header.length) {
11282
+ contents += prop + ": " + header.join("; ") + FormData2.LINE_BREAK;
11165
11283
  }
11166
11284
  }
11167
11285
  }
@@ -11213,13 +11331,13 @@ var require_form_data = __commonJS2({
11213
11331
  return "--" + this.getBoundary() + "--" + FormData2.LINE_BREAK;
11214
11332
  };
11215
11333
  FormData2.prototype.getHeaders = function(userHeaders) {
11216
- var header2;
11334
+ var header;
11217
11335
  var formHeaders = {
11218
11336
  "content-type": "multipart/form-data; boundary=" + this.getBoundary()
11219
11337
  };
11220
- for (header2 in userHeaders) {
11221
- if (hasOwn(userHeaders, header2)) {
11222
- formHeaders[header2.toLowerCase()] = userHeaders[header2];
11338
+ for (header in userHeaders) {
11339
+ if (hasOwn(userHeaders, header)) {
11340
+ formHeaders[header.toLowerCase()] = userHeaders[header];
11223
11341
  }
11224
11342
  }
11225
11343
  return formHeaders;
@@ -36395,55 +36513,172 @@ var require_src2 = __commonJS22({
36395
36513
  }
36396
36514
  });
36397
36515
  var import_debug2 = __toESM22(require_src2());
36398
- var logInfo2 = (0, import_debug2.default)("info");
36399
- var logTask2 = (0, import_debug2.default)("task");
36400
- var logError2 = (0, import_debug2.default)("error");
36401
- var logDetail2 = (0, import_debug2.default)("detail");
36402
- var logDebug2 = (0, import_debug2.default)("debug");
36403
- var logWarning2 = (0, import_debug2.default)("warning");
36404
- var logColor2 = (0, import_debug2.default)("color");
36405
- logInfo2.color = "19";
36406
- logTask2.color = "25";
36407
- logError2.color = "1";
36408
- logDetail2.color = "199";
36409
- logWarning2.color = "186";
36410
- logDebug2.color = "211";
36411
- logColor2.enabled = true;
36412
- function logNamespace2(namespace) {
36413
- logInfo2.namespace = `${namespace}:info`;
36414
- logTask2.namespace = `${namespace}:task`;
36415
- logError2.namespace = `${namespace}:error`;
36416
- logDetail2.namespace = `${namespace}:detail`;
36417
- logWarning2.namespace = `${namespace}:warning`;
36418
- logDebug2.namespace = `${namespace}:debug`;
36419
- }
36420
- function setLogLevel2(level) {
36421
- switch (level) {
36422
- case "info":
36423
- logInfo2.enabled = true;
36424
- logTask2.enabled = true;
36425
- logError2.enabled = true;
36426
- logWarning2.enabled = true;
36427
- logDetail2.enabled = false;
36428
- logDebug2.enabled = false;
36429
- break;
36430
- case "debug":
36431
- logInfo2.enabled = true;
36432
- logTask2.enabled = true;
36433
- logError2.enabled = true;
36434
- logWarning2.enabled = true;
36435
- logDetail2.enabled = true;
36436
- logDebug2.enabled = true;
36437
- break;
36438
- case "none":
36439
- logInfo2.enabled = false;
36440
- logTask2.enabled = false;
36441
- logError2.enabled = false;
36442
- logWarning2.enabled = false;
36443
- logDetail2.enabled = false;
36444
- logDebug2.enabled = false;
36445
- break;
36516
+ function createLoggers2(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
36517
+ const logInfo22 = (0, import_debug2.default)(`${namespace}:info`);
36518
+ const logTask6 = (0, import_debug2.default)(`${namespace}:task`);
36519
+ const logError22 = (0, import_debug2.default)(`${namespace}:error`);
36520
+ const logDetail2 = (0, import_debug2.default)(`${namespace}:detail`);
36521
+ const logDebug = (0, import_debug2.default)(`${namespace}:debug`);
36522
+ const logWarning2 = (0, import_debug2.default)(`${namespace}:warning`);
36523
+ const logColor = (0, import_debug2.default)(`${namespace}:color`);
36524
+ logInfo22.color = "19";
36525
+ logTask6.color = "25";
36526
+ logError22.color = "1";
36527
+ logDetail2.color = "199";
36528
+ logWarning2.color = "186";
36529
+ logDebug.color = "211";
36530
+ logColor.enabled = true;
36531
+ function setNamespace2(namespace2) {
36532
+ logInfo22.namespace = `${namespace2}:info`;
36533
+ logTask6.namespace = `${namespace2}:task`;
36534
+ logError22.namespace = `${namespace2}:error`;
36535
+ logDetail2.namespace = `${namespace2}:detail`;
36536
+ logWarning2.namespace = `${namespace2}:warning`;
36537
+ logDebug.namespace = `${namespace2}:debug`;
36538
+ }
36539
+ function setLogLevel(level) {
36540
+ switch (level) {
36541
+ case "info":
36542
+ logInfo22.enabled = true;
36543
+ logTask6.enabled = true;
36544
+ logError22.enabled = true;
36545
+ logWarning2.enabled = true;
36546
+ logDetail2.enabled = false;
36547
+ logDebug.enabled = false;
36548
+ break;
36549
+ case "debug":
36550
+ logInfo22.enabled = true;
36551
+ logTask6.enabled = true;
36552
+ logError22.enabled = true;
36553
+ logWarning2.enabled = true;
36554
+ logDetail2.enabled = true;
36555
+ logDebug.enabled = true;
36556
+ break;
36557
+ case "none":
36558
+ logInfo22.enabled = false;
36559
+ logTask6.enabled = false;
36560
+ logError22.enabled = false;
36561
+ logWarning2.enabled = false;
36562
+ logDetail2.enabled = false;
36563
+ logDebug.enabled = false;
36564
+ break;
36565
+ }
36566
+ }
36567
+ setLogLevel(logLevel);
36568
+ function setColors(type, color) {
36569
+ switch (type) {
36570
+ case "info":
36571
+ logInfo22.color = color;
36572
+ break;
36573
+ case "task":
36574
+ logTask6.color = color;
36575
+ break;
36576
+ case "error":
36577
+ logError22.color = color;
36578
+ break;
36579
+ case "detail":
36580
+ logDetail2.color = color;
36581
+ break;
36582
+ case "warning":
36583
+ logWarning2.color = color;
36584
+ break;
36585
+ case "debug":
36586
+ logDebug.color = color;
36587
+ break;
36588
+ default:
36589
+ throw new Error(`Invalid log type: ${type}`);
36590
+ }
36591
+ }
36592
+ function printColors() {
36593
+ for (let i = 0; i < 256; i++) {
36594
+ logColor.color = `${i}`;
36595
+ logColor(`${i}: ${i}`);
36596
+ }
36597
+ }
36598
+ function logDataDetail(data, prefix = "# ") {
36599
+ if (data === null || data === void 0) {
36600
+ return `${prefix}<null or undefined>`;
36601
+ }
36602
+ if (typeof data !== "object") {
36603
+ return `${prefix}${String(data)}`;
36604
+ }
36605
+ const keys = Object.keys(data);
36606
+ let result = "";
36607
+ for (const key of keys) {
36608
+ result += `${prefix}${key}: `;
36609
+ if (key in data) {
36610
+ let dataKey = key;
36611
+ if (key in data) {
36612
+ dataKey = key;
36613
+ const value = data[dataKey];
36614
+ if (value === null || value === void 0) {
36615
+ result += `<${value === null ? "null" : "undefined"}>
36616
+ `;
36617
+ } else if (typeof value === "object") {
36618
+ result += `
36619
+ ${logDataDetail(value, `${prefix} `)}
36620
+ `;
36621
+ } else {
36622
+ result += `${value}
36623
+ `;
36624
+ }
36625
+ }
36626
+ }
36627
+ }
36628
+ return result.trim();
36629
+ }
36630
+ function header(title, padding = 0) {
36631
+ return `${" ".repeat(padding)}${"=".repeat(80)}
36632
+ ${" ".repeat(40 - title.length / 2)}${title}
36633
+ ${" ".repeat(padding)}${"=".repeat(80)}`;
36634
+ }
36635
+ function logHeader(title) {
36636
+ logInfo22(`${header(title, 2)}`);
36446
36637
  }
36638
+ function logDataObject2(title, ...args) {
36639
+ const stack = new Error().stack?.split("\n")[2] || "";
36640
+ const stackMatch = stack.match(/\((.*):(\d+):(\d+)\)$/) || stack.match(/at (.*):(\d+):(\d+)$/);
36641
+ let callerDetails = "";
36642
+ if (stackMatch) {
36643
+ const functionMatch = stack.match(/at (.+) \(/);
36644
+ const functionName = functionMatch ? functionMatch[1] : "<anonymous>";
36645
+ callerDetails = `${functionName}`;
36646
+ }
36647
+ logDetail2(`${header(`*${title}* ${callerDetails}`)}
36648
+ ${args.reduce((acc, arg) => `${acc}
36649
+ ${logDataDetail(arg)}`, "")}
36650
+
36651
+ ${"=".repeat(80)}`);
36652
+ }
36653
+ function logErrorObject(error, extraDetails) {
36654
+ if (error instanceof Error) {
36655
+ logError22(`${extraDetails ? header(extraDetails, 1) : header(error.message, 1)}
36656
+ Error Message:
36657
+ ${error.message}
36658
+ Error Stack:
36659
+ ${error.stack}
36660
+ ${"=".repeat(80)}`);
36661
+ } else {
36662
+ logError22(`${extraDetails ? header(extraDetails, 1) : header(String(error), 1)}
36663
+ ${"=".repeat(80)}`);
36664
+ }
36665
+ }
36666
+ return {
36667
+ logInfo: logInfo22,
36668
+ logTask: logTask6,
36669
+ logError: logError22,
36670
+ logDetail: logDetail2,
36671
+ logDebug,
36672
+ logWarning: logWarning2,
36673
+ logColor,
36674
+ setColors,
36675
+ printColors,
36676
+ logHeader,
36677
+ logDataObject: logDataObject2,
36678
+ logErrorObject,
36679
+ setLogLevel,
36680
+ setNamespace: setNamespace2
36681
+ };
36447
36682
  }
36448
36683
  var AUTHORIZE_QUERY = `
36449
36684
  query Authorize($input: AuthorizeInput!) {
@@ -36462,8 +36697,7 @@ var TOKEN_QUERY = `
36462
36697
  }
36463
36698
  }
36464
36699
  `;
36465
- setLogLevel2(process.env.LOG_LEVEL ?? "none");
36466
- logNamespace2("auth");
36700
+ var { logInfo } = createLoggers2("auth");
36467
36701
  var random = (0, import_node_util.promisify)(import_node_crypto.randomBytes);
36468
36702
  async function getAuthToken(credentials, apiUrl) {
36469
36703
  const authApiUrl = apiUrl || process.env.AUTH_API_URL;
@@ -36472,7 +36706,7 @@ async function getAuthToken(credentials, apiUrl) {
36472
36706
  }
36473
36707
  const { clientDecorator, variantConfigurationKey } = credentials;
36474
36708
  const frameworkId = credentials.frameworkId || `apple-kit-${Date.now()}`;
36475
- logInfo2(`Getting auth token for identifiers: ${variantConfigurationKey}`);
36709
+ logInfo(`Getting auth token for identifiers: ${variantConfigurationKey}`);
36476
36710
  const randomSecret = (await random(8)).toString("hex");
36477
36711
  const timestamp = (/* @__PURE__ */ new Date()).toISOString();
36478
36712
  const hash = (0, import_node_crypto.createHash)("sha256");
@@ -36543,7 +36777,7 @@ async function getAuthToken(credentials, apiUrl) {
36543
36777
  }
36544
36778
  async function readCredentialsFromFile(filePath) {
36545
36779
  const fs = await import("node:fs/promises");
36546
- logInfo2(`Reading credentials from: ${filePath}`);
36780
+ logInfo(`Reading credentials from: ${filePath}`);
36547
36781
  const content = await fs.readFile(filePath, "utf-8");
36548
36782
  const credentials = JSON.parse(content);
36549
36783
  if (!credentials.clientDecorator || !credentials.variantConfigurationKey) {
@@ -37376,113 +37610,177 @@ var require_src22 = __commonJS3({
37376
37610
  }
37377
37611
  });
37378
37612
  var import_debug22 = __toESM32(require_src22());
37379
- var logInfo22 = (0, import_debug22.default)("info");
37380
- var logTask22 = (0, import_debug22.default)("task");
37381
- var logError22 = (0, import_debug22.default)("error");
37382
- var logDetail22 = (0, import_debug22.default)("detail");
37383
- var logDebug22 = (0, import_debug22.default)("debug");
37384
- var logWarning22 = (0, import_debug22.default)("warning");
37385
- var logColor22 = (0, import_debug22.default)("color");
37386
- logInfo22.color = "19";
37387
- logTask22.color = "25";
37388
- logError22.color = "1";
37389
- logDetail22.color = "199";
37390
- logWarning22.color = "186";
37391
- logDebug22.color = "211";
37392
- logColor22.enabled = true;
37393
- function logNamespace22(namespace) {
37394
- logInfo22.namespace = `${namespace}:info`;
37395
- logTask22.namespace = `${namespace}:task`;
37396
- logError22.namespace = `${namespace}:error`;
37397
- logDetail22.namespace = `${namespace}:detail`;
37398
- logWarning22.namespace = `${namespace}:warning`;
37399
- logDebug22.namespace = `${namespace}:debug`;
37400
- }
37401
- function setLogLevel22(level) {
37402
- switch (level) {
37403
- case "info":
37404
- logInfo22.enabled = true;
37405
- logTask22.enabled = true;
37406
- logError22.enabled = true;
37407
- logWarning22.enabled = true;
37408
- logDetail22.enabled = false;
37409
- logDebug22.enabled = false;
37410
- break;
37411
- case "debug":
37412
- logInfo22.enabled = true;
37413
- logTask22.enabled = true;
37414
- logError22.enabled = true;
37415
- logWarning22.enabled = true;
37416
- logDetail22.enabled = true;
37417
- logDebug22.enabled = true;
37418
- break;
37419
- case "none":
37420
- logInfo22.enabled = false;
37421
- logTask22.enabled = false;
37422
- logError22.enabled = false;
37423
- logWarning22.enabled = false;
37424
- logDetail22.enabled = false;
37425
- logDebug22.enabled = false;
37426
- break;
37427
- }
37428
- }
37429
- function logDataDetail(data, prefix = "# ") {
37430
- if (data === null || data === void 0) {
37431
- return `${prefix}<null or undefined>`;
37432
- }
37433
- if (typeof data !== "object") {
37434
- return `${prefix}${String(data)}`;
37435
- }
37436
- const keys = Object.keys(data);
37437
- let result = "";
37438
- for (const key of keys) {
37439
- result += `${prefix}${key}: `;
37440
- if (key in data) {
37441
- let dataKey = key;
37613
+ function createLoggers22(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
37614
+ const logInfo32 = (0, import_debug22.default)(`${namespace}:info`);
37615
+ const logTask6 = (0, import_debug22.default)(`${namespace}:task`);
37616
+ const logError22 = (0, import_debug22.default)(`${namespace}:error`);
37617
+ const logDetail2 = (0, import_debug22.default)(`${namespace}:detail`);
37618
+ const logDebug = (0, import_debug22.default)(`${namespace}:debug`);
37619
+ const logWarning2 = (0, import_debug22.default)(`${namespace}:warning`);
37620
+ const logColor = (0, import_debug22.default)(`${namespace}:color`);
37621
+ logInfo32.color = "19";
37622
+ logTask6.color = "25";
37623
+ logError22.color = "1";
37624
+ logDetail2.color = "199";
37625
+ logWarning2.color = "186";
37626
+ logDebug.color = "211";
37627
+ logColor.enabled = true;
37628
+ function setNamespace2(namespace2) {
37629
+ logInfo32.namespace = `${namespace2}:info`;
37630
+ logTask6.namespace = `${namespace2}:task`;
37631
+ logError22.namespace = `${namespace2}:error`;
37632
+ logDetail2.namespace = `${namespace2}:detail`;
37633
+ logWarning2.namespace = `${namespace2}:warning`;
37634
+ logDebug.namespace = `${namespace2}:debug`;
37635
+ }
37636
+ function setLogLevel(level) {
37637
+ switch (level) {
37638
+ case "info":
37639
+ logInfo32.enabled = true;
37640
+ logTask6.enabled = true;
37641
+ logError22.enabled = true;
37642
+ logWarning2.enabled = true;
37643
+ logDetail2.enabled = false;
37644
+ logDebug.enabled = false;
37645
+ break;
37646
+ case "debug":
37647
+ logInfo32.enabled = true;
37648
+ logTask6.enabled = true;
37649
+ logError22.enabled = true;
37650
+ logWarning2.enabled = true;
37651
+ logDetail2.enabled = true;
37652
+ logDebug.enabled = true;
37653
+ break;
37654
+ case "none":
37655
+ logInfo32.enabled = false;
37656
+ logTask6.enabled = false;
37657
+ logError22.enabled = false;
37658
+ logWarning2.enabled = false;
37659
+ logDetail2.enabled = false;
37660
+ logDebug.enabled = false;
37661
+ break;
37662
+ }
37663
+ }
37664
+ setLogLevel(logLevel);
37665
+ function setColors(type, color) {
37666
+ switch (type) {
37667
+ case "info":
37668
+ logInfo32.color = color;
37669
+ break;
37670
+ case "task":
37671
+ logTask6.color = color;
37672
+ break;
37673
+ case "error":
37674
+ logError22.color = color;
37675
+ break;
37676
+ case "detail":
37677
+ logDetail2.color = color;
37678
+ break;
37679
+ case "warning":
37680
+ logWarning2.color = color;
37681
+ break;
37682
+ case "debug":
37683
+ logDebug.color = color;
37684
+ break;
37685
+ default:
37686
+ throw new Error(`Invalid log type: ${type}`);
37687
+ }
37688
+ }
37689
+ function printColors() {
37690
+ for (let i = 0; i < 256; i++) {
37691
+ logColor.color = `${i}`;
37692
+ logColor(`${i}: ${i}`);
37693
+ }
37694
+ }
37695
+ function logDataDetail(data, prefix = "# ") {
37696
+ if (data === null || data === void 0) {
37697
+ return `${prefix}<null or undefined>`;
37698
+ }
37699
+ if (typeof data !== "object") {
37700
+ return `${prefix}${String(data)}`;
37701
+ }
37702
+ const keys = Object.keys(data);
37703
+ let result = "";
37704
+ for (const key of keys) {
37705
+ result += `${prefix}${key}: `;
37442
37706
  if (key in data) {
37443
- dataKey = key;
37444
- const value = data[dataKey];
37445
- if (value === null || value === void 0) {
37446
- result += `<${value === null ? "null" : "undefined"}>
37707
+ let dataKey = key;
37708
+ if (key in data) {
37709
+ dataKey = key;
37710
+ const value = data[dataKey];
37711
+ if (value === null || value === void 0) {
37712
+ result += `<${value === null ? "null" : "undefined"}>
37447
37713
  `;
37448
- } else if (typeof value === "object") {
37449
- result += `
37450
- ${logDataDetail(value, `${prefix} `)}
37714
+ } else if (typeof value === "object") {
37715
+ result += `
37716
+ ${logDataDetail(value, `${prefix} `)}
37451
37717
  `;
37452
- } else {
37453
- result += `${value}
37718
+ } else {
37719
+ result += `${value}
37454
37720
  `;
37721
+ }
37455
37722
  }
37456
37723
  }
37457
37724
  }
37725
+ return result.trim();
37458
37726
  }
37459
- return result.trim();
37460
- }
37461
- function header(title, padding = 0) {
37462
- return `${" ".repeat(padding)}${"=".repeat(80)}
37727
+ function header(title, padding = 0) {
37728
+ return `${" ".repeat(padding)}${"=".repeat(80)}
37463
37729
  ${" ".repeat(40 - title.length / 2)}${title}
37464
37730
  ${" ".repeat(padding)}${"=".repeat(80)}`;
37465
- }
37466
- function logDataObject(title, ...args) {
37467
- const stack = new Error().stack?.split("\n")[2] || "";
37468
- const stackMatch = stack.match(/\((.*):(\d+):(\d+)\)$/) || stack.match(/at (.*):(\d+):(\d+)$/);
37469
- let callerDetails = "";
37470
- if (stackMatch) {
37471
- const functionMatch = stack.match(/at (.+) \(/);
37472
- const functionName = functionMatch ? functionMatch[1] : "<anonymous>";
37473
- callerDetails = `${functionName}`;
37474
- }
37475
- logDetail22(`${header(`*${title}* ${callerDetails}`)}
37731
+ }
37732
+ function logHeader(title) {
37733
+ logInfo32(`${header(title, 2)}`);
37734
+ }
37735
+ function logDataObject2(title, ...args) {
37736
+ const stack = new Error().stack?.split("\n")[2] || "";
37737
+ const stackMatch = stack.match(/\((.*):(\d+):(\d+)\)$/) || stack.match(/at (.*):(\d+):(\d+)$/);
37738
+ let callerDetails = "";
37739
+ if (stackMatch) {
37740
+ const functionMatch = stack.match(/at (.+) \(/);
37741
+ const functionName = functionMatch ? functionMatch[1] : "<anonymous>";
37742
+ callerDetails = `${functionName}`;
37743
+ }
37744
+ logDetail2(`${header(`*${title}* ${callerDetails}`)}
37476
37745
  ${args.reduce((acc, arg) => `${acc}
37477
37746
  ${logDataDetail(arg)}`, "")}
37478
-
37747
+
37479
37748
  ${"=".repeat(80)}`);
37749
+ }
37750
+ function logErrorObject(error, extraDetails) {
37751
+ if (error instanceof Error) {
37752
+ logError22(`${extraDetails ? header(extraDetails, 1) : header(error.message, 1)}
37753
+ Error Message:
37754
+ ${error.message}
37755
+ Error Stack:
37756
+ ${error.stack}
37757
+ ${"=".repeat(80)}`);
37758
+ } else {
37759
+ logError22(`${extraDetails ? header(extraDetails, 1) : header(String(error), 1)}
37760
+ ${"=".repeat(80)}`);
37761
+ }
37762
+ }
37763
+ return {
37764
+ logInfo: logInfo32,
37765
+ logTask: logTask6,
37766
+ logError: logError22,
37767
+ logDetail: logDetail2,
37768
+ logDebug,
37769
+ logWarning: logWarning2,
37770
+ logColor,
37771
+ setColors,
37772
+ printColors,
37773
+ logHeader,
37774
+ logDataObject: logDataObject2,
37775
+ logErrorObject,
37776
+ setLogLevel,
37777
+ setNamespace: setNamespace2
37778
+ };
37480
37779
  }
37780
+ var { logInfo: logInfo2, logError, logWarning, logDataObject } = createLoggers22("mdm-client");
37481
37781
  var MdmClient = class {
37482
37782
  constructor(config) {
37483
37783
  this.config = config;
37484
- setLogLevel22(process.env.LOG_LEVEL ?? "none");
37485
- logNamespace22("mdm-client");
37486
37784
  logDataObject("MDM Client Config", { config });
37487
37785
  if (!config.endpoint) {
37488
37786
  throw new Error("MDM endpoint is required");
@@ -37503,7 +37801,7 @@ var MdmClient = class {
37503
37801
  }
37504
37802
  client;
37505
37803
  async generateEnrollmentProfile(deviceId) {
37506
- logInfo22(`Generating enrollment profile for device ${deviceId}`);
37804
+ logInfo2(`Generating enrollment profile for device ${deviceId}`);
37507
37805
  const result = await this.client.request(GENERATE_ENROLLMENT_PROFILE, {
37508
37806
  input: {
37509
37807
  deviceId,
@@ -37513,7 +37811,7 @@ var MdmClient = class {
37513
37811
  return result.generateEnrollmentProfile;
37514
37812
  }
37515
37813
  async waitForDeviceToEnroll(deviceId, previousOpRef) {
37516
- logInfo22(`Waiting for device ${deviceId} to enroll...`);
37814
+ logInfo2(`Waiting for device ${deviceId} to enroll...`);
37517
37815
  const result = await this.client.request(WAIT_FOR_DEVICE_TO_ENROLL, {
37518
37816
  input: {
37519
37817
  deviceId,
@@ -37523,7 +37821,7 @@ var MdmClient = class {
37523
37821
  return result.waitForDeviceToEnroll;
37524
37822
  }
37525
37823
  async installApp(deviceId, options) {
37526
- logInfo22(`Installing app on device ${deviceId}`);
37824
+ logInfo2(`Installing app on device ${deviceId}`);
37527
37825
  try {
37528
37826
  const result = await this.client.request(INSTALL_APP, {
37529
37827
  input: {
@@ -37541,7 +37839,7 @@ var MdmClient = class {
37541
37839
  return result.installApp;
37542
37840
  } catch (error) {
37543
37841
  const errorMsg = error instanceof Error ? error.message : String(error);
37544
- logError22(`Failed to install app: ${errorMsg}`);
37842
+ logError(`Failed to install app: ${errorMsg}`);
37545
37843
  throw error;
37546
37844
  }
37547
37845
  }
@@ -37550,7 +37848,7 @@ async function createMDMClient() {
37550
37848
  const endpoint = process.env.MDM_ENDPOINT;
37551
37849
  const credPath = process.env.CREDENTIALS_PATH;
37552
37850
  if (!endpoint || !credPath) {
37553
- logWarning22("MDM endpoint or credentials path is not set");
37851
+ logWarning("MDM endpoint or credentials path is not set");
37554
37852
  logDataObject("Environment variables", { endpoint, credPath });
37555
37853
  return void 0;
37556
37854
  }
@@ -37668,8 +37966,9 @@ async function execIDevice(command, options = {}) {
37668
37966
  }
37669
37967
 
37670
37968
  // src/logic/actions/pair.ts
37969
+ var { logTask: logTask2, logInfo: logInfo3, logError: logError2 } = createLoggers("apple-kit:pair");
37671
37970
  async function isPaired(udid) {
37672
- logTask(`Checking pairing status for ${udid}`);
37971
+ logTask2(`Checking pairing status for ${udid}`);
37673
37972
  try {
37674
37973
  const result = await runIDeviceTool("idevicepair", ["-u", udid, "validate"]);
37675
37974
  if (!result) {
@@ -37681,38 +37980,38 @@ async function isPaired(udid) {
37681
37980
  }
37682
37981
  }
37683
37982
  async function trustDevice(udid, timeout2 = 6e4, onWaitingForTrust) {
37684
- logTask(`Trusting device ${udid}`);
37983
+ logTask2(`Trusting device ${udid}`);
37685
37984
  if (await isPaired(udid)) {
37686
- logInfo(`Device ${udid} is already trusted`);
37985
+ logInfo3(`Device ${udid} is already trusted`);
37687
37986
  return true;
37688
37987
  }
37689
- logInfo(`Initiating pairing for device ${udid}`);
37988
+ logInfo3(`Initiating pairing for device ${udid}`);
37690
37989
  try {
37691
37990
  const pairResult = await pair(udid);
37692
37991
  if (pairResult) {
37693
- logInfo(`Device ${udid} paired successfully`);
37992
+ logInfo3(`Device ${udid} paired successfully`);
37694
37993
  return true;
37695
37994
  }
37696
37995
  } catch (error) {
37697
- logError(`Pairing failed with ${udid}: ${error}`);
37996
+ logError2(`Pairing failed with ${udid}: ${error}`);
37698
37997
  }
37699
- logInfo("Please accept the trust dialog on the device...");
37998
+ logInfo3("Please accept the trust dialog on the device...");
37700
37999
  onWaitingForTrust?.();
37701
38000
  try {
37702
38001
  await waitForPairing(udid, timeout2, 1e3);
37703
- logInfo(`Device ${udid} is now trusted`);
38002
+ logInfo3(`Device ${udid} is now trusted`);
37704
38003
  return true;
37705
38004
  } catch {
37706
- logInfo(`Timeout waiting for trust acceptance on device ${udid}`);
38005
+ logInfo3(`Timeout waiting for trust acceptance on device ${udid}`);
37707
38006
  return false;
37708
38007
  }
37709
38008
  }
37710
38009
  async function waitForPairing(udid, timeout2 = 12e4, pollInterval = 1e3) {
37711
- logTask(`Waiting for pairing on device ${udid}`);
38010
+ logTask2(`Waiting for pairing on device ${udid}`);
37712
38011
  const startTime = Date.now();
37713
38012
  while (Date.now() - startTime < timeout2) {
37714
38013
  if (await isPaired(udid)) {
37715
- logInfo(`Device ${udid} is now paired`);
38014
+ logInfo3(`Device ${udid} is now paired`);
37716
38015
  return true;
37717
38016
  }
37718
38017
  await new Promise((resolve2) => setTimeout(resolve2, pollInterval));
@@ -37720,7 +38019,7 @@ async function waitForPairing(udid, timeout2 = 12e4, pollInterval = 1e3) {
37720
38019
  throw new Error(`Timeout waiting for device pairing after ${timeout2}ms`);
37721
38020
  }
37722
38021
  async function pair(udid) {
37723
- logTask(`Initiating pairing for device ${udid}`);
38022
+ logTask2(`Initiating pairing for device ${udid}`);
37724
38023
  try {
37725
38024
  const result = await runIDeviceTool("idevicepair", ["-u", udid, "pair"]);
37726
38025
  if (!result) {
@@ -37736,7 +38035,7 @@ async function pair(udid) {
37736
38035
  }
37737
38036
  }
37738
38037
  async function unpair(udid) {
37739
- logTask(`Un-pairing device ${udid}`);
38038
+ logTask2(`Un-pairing device ${udid}`);
37740
38039
  try {
37741
38040
  const result = await runIDeviceTool("idevicepair", ["-u", udid, "unpair"]);
37742
38041
  if (!result) {
@@ -37749,24 +38048,25 @@ async function unpair(udid) {
37749
38048
  }
37750
38049
 
37751
38050
  // src/logic/actions/install.ts
38051
+ var { logTask: logTask3, logInfo: logInfo4 } = createLoggers("apple-kit:install");
37752
38052
  async function installManagedApp(ipaPath, udid, iosCli2, options) {
37753
38053
  const result = await iosCli2.installApp(udid, ipaPath);
37754
38054
  const client = await createMDMClient();
37755
- logTask("Installing app via MDM for management takeover");
38055
+ logTask3("Installing app via MDM for management takeover");
37756
38056
  if (client) {
37757
38057
  await client.installApp(udid, options);
37758
38058
  }
37759
38059
  return result;
37760
38060
  }
37761
38061
  async function uninstallApp(bundleId, udid) {
37762
- logTask(`Uninstalling app ${bundleId} from device ${udid}`);
38062
+ logTask3(`Uninstalling app ${bundleId} from device ${udid}`);
37763
38063
  if (!await isPaired(udid)) {
37764
38064
  await waitForPairing(udid, 1e4);
37765
38065
  }
37766
38066
  await runIDeviceTool("ideviceinstaller", ["-u", udid, "uninstall", bundleId]);
37767
38067
  }
37768
38068
  async function listApps(udid) {
37769
- logTask(`Listing apps on device ${udid}`);
38069
+ logTask3(`Listing apps on device ${udid}`);
37770
38070
  if (!await isPaired(udid)) {
37771
38071
  await waitForPairing(udid, 1e4);
37772
38072
  }
@@ -37782,7 +38082,7 @@ async function listApps(udid) {
37782
38082
  }
37783
38083
  }
37784
38084
  async function isAppInstalled(bundleId, udid) {
37785
- logTask(`Checking if app ${bundleId} is installed on device ${udid}`);
38085
+ logTask3(`Checking if app ${bundleId} is installed on device ${udid}`);
37786
38086
  const apps = await listApps(udid);
37787
38087
  return apps.some((app) => app.bundleId === bundleId);
37788
38088
  }
@@ -37790,9 +38090,10 @@ async function isAppInstalled(bundleId, udid) {
37790
38090
  // src/logic/actions/proxy.ts
37791
38091
  var import_node_child_process2 = require("node:child_process");
37792
38092
  var import_node_path3 = require("node:path");
38093
+ var { logTask: logTask4, logInfo: logInfo5, logError: logError3 } = createLoggers("apple-kit:proxy");
37793
38094
  function startPortForward(localPort, devicePort, udid, startupTimeout = 500) {
37794
38095
  return new Promise((resolve2, reject) => {
37795
- logTask(`Starting port forward ${localPort} -> ${devicePort} for device ${udid}`);
38096
+ logTask4(`Starting port forward ${localPort} -> ${devicePort} for device ${udid}`);
37796
38097
  const binPath = getResourcesBinPath();
37797
38098
  const ext = process.platform === "win32" ? ".exe" : "";
37798
38099
  const toolPath = binPath ? (0, import_node_path3.join)(binPath, `iproxy${ext}`) : `iproxy${ext}`;
@@ -37803,9 +38104,9 @@ function startPortForward(localPort, devicePort, udid, startupTimeout = 500) {
37803
38104
  if (binPath) {
37804
38105
  spawnOptions.cwd = binPath;
37805
38106
  }
37806
- logInfo(`Spawning iproxy with path: ${toolPath}`);
37807
- logInfo(`Arguments: ${[localPort.toString(), devicePort.toString(), "-u", udid].join(" ")}`);
37808
- logInfo(`Options: ${JSON.stringify(spawnOptions)}`);
38107
+ logInfo5(`Spawning iproxy with path: ${toolPath}`);
38108
+ logInfo5(`Arguments: ${[localPort.toString(), devicePort.toString(), "-u", udid].join(" ")}`);
38109
+ logInfo5(`Options: ${JSON.stringify(spawnOptions)}`);
37809
38110
  const child = (0, import_node_child_process2.spawn)(
37810
38111
  toolPath,
37811
38112
  [localPort.toString(), devicePort.toString(), "-u", udid],
@@ -37814,10 +38115,10 @@ function startPortForward(localPort, devicePort, udid, startupTimeout = 500) {
37814
38115
  let hasResolved = false;
37815
38116
  let stderrOutput = "";
37816
38117
  child.stdout?.on("data", (data) => {
37817
- logTask(`${data.toString()}`);
38118
+ logTask4(`${data.toString()}`);
37818
38119
  });
37819
38120
  child.stderr?.on("data", (data) => {
37820
- logError(`${data.toString()}`);
38121
+ logError3(`${data.toString()}`);
37821
38122
  const msg = data.toString();
37822
38123
  stderrOutput += msg;
37823
38124
  if (msg.toLowerCase().includes("error") && !hasResolved) {
@@ -37843,7 +38144,7 @@ function startPortForward(localPort, devicePort, udid, startupTimeout = 500) {
37843
38144
  setTimeout(() => {
37844
38145
  if (!hasResolved) {
37845
38146
  hasResolved = true;
37846
- logTask(`Port forward started: ${localPort} -> ${devicePort} for device ${udid}`);
38147
+ logTask4(`Port forward started: ${localPort} -> ${devicePort} for device ${udid}`);
37847
38148
  resolve2({
37848
38149
  result: {
37849
38150
  localPort,
@@ -37857,7 +38158,7 @@ function startPortForward(localPort, devicePort, udid, startupTimeout = 500) {
37857
38158
  }
37858
38159
  function killPortForwardProcess(process3) {
37859
38160
  if (process3 && !process3.killed) {
37860
- logTask("Killing port forward process");
38161
+ logTask4("Killing port forward process");
37861
38162
  process3.kill();
37862
38163
  }
37863
38164
  }
@@ -37959,6 +38260,7 @@ function escapeXml(str) {
37959
38260
  }
37960
38261
 
37961
38262
  // src/utils/wifiProfile.ts
38263
+ var { logInfo: logInfo6 } = createLoggers("apple-kit:wifi-profile");
37962
38264
  async function generateWifiProfile(config, options) {
37963
38265
  const {
37964
38266
  ssid,
@@ -37977,7 +38279,7 @@ async function generateWifiProfile(config, options) {
37977
38279
  const payloadUuid = (0, import_node_crypto2.randomUUID)().toUpperCase();
37978
38280
  const profileId = `com.mce.wifi.${ssid.replace(/[^a-zA-Z0-9]/g, "")}.${Date.now()}`;
37979
38281
  const payloadId = `${profileId}.payload`;
37980
- logInfo(`Generating WiFi profile for SSID: ${ssid}, encryption: ${encryptionType}`);
38282
+ logInfo6(`Generating WiFi profile for SSID: ${ssid}, encryption: ${encryptionType}`);
37981
38283
  const templateName = enterprise ? "wifi-enterprise.xml" : "wifi-standard.xml";
37982
38284
  const template = await loadTemplate(templateName, options?.plistDir);
37983
38285
  const variables = {
@@ -38016,7 +38318,7 @@ async function generateWifiProfile(config, options) {
38016
38318
  async function generateWifiProfileFromEnv(options) {
38017
38319
  const ssid = process.env.WIFI_SSID;
38018
38320
  if (!ssid) {
38019
- logInfo("WIFI_SSID not set, skipping WiFi profile generation");
38321
+ logInfo6("WIFI_SSID not set, skipping WiFi profile generation");
38020
38322
  return null;
38021
38323
  }
38022
38324
  const config = {
@@ -38028,7 +38330,7 @@ async function generateWifiProfileFromEnv(options) {
38028
38330
  username: process.env.WIFI_USERNAME,
38029
38331
  eapType: parseWifiEapType(process.env.WIFI_EAP_TYPE)
38030
38332
  };
38031
- logInfo(`Generating WiFi profile from env: SSID=${ssid}, enterprise=${config.enterprise}`);
38333
+ logInfo6(`Generating WiFi profile from env: SSID=${ssid}, enterprise=${config.enterprise}`);
38032
38334
  return generateWifiProfile(config, options);
38033
38335
  }
38034
38336
  async function saveWifiProfileToTemp(profile) {
@@ -38039,7 +38341,7 @@ async function saveWifiProfileToTemp(profile) {
38039
38341
  const fileName = `mce_wifi_${Date.now()}.mobileconfig`;
38040
38342
  const filePath = path.join(tempDir, fileName);
38041
38343
  await fs.writeFile(filePath, profile, "utf-8");
38042
- logInfo(`WiFi profile saved to: ${filePath}`);
38344
+ logInfo6(`WiFi profile saved to: ${filePath}`);
38043
38345
  return filePath;
38044
38346
  }
38045
38347
  function getEapTypeNumber(eapType) {
@@ -38085,6 +38387,7 @@ function parseWifiEapType(value) {
38085
38387
  // src/logic/activationFlow.ts
38086
38388
  var DEFAULT_RETRIES = 150;
38087
38389
  var DEFAULT_RETRY_DELAY_MS = 1e3;
38390
+ var { logTask: logTask5, logInfo: logInfo7, logError: logError4 } = createLoggers("apple-kit:activation");
38088
38391
  var ActivationFlow = class {
38089
38392
  iosCli;
38090
38393
  mdmClient;
@@ -38093,7 +38396,7 @@ var ActivationFlow = class {
38093
38396
  }
38094
38397
  async run(udid, steps) {
38095
38398
  this.mdmClient = await createMDMClient();
38096
- logTask(`Starting activation flow for device ${udid}`);
38399
+ logTask5(`Starting activation flow for device ${udid}`);
38097
38400
  await this.retryActivateCommand("activate device", () => this.iosCli.activate(udid));
38098
38401
  const wifiProfileIdentifier = await this.installWifiProfile(udid);
38099
38402
  await this.installMdmProfile(udid);
@@ -38115,7 +38418,7 @@ var ActivationFlow = class {
38115
38418
  return wifiProfileIdentifier;
38116
38419
  }
38117
38420
  async installMdmProfile(udid) {
38118
- logTask("Installing MDM enrollment profile");
38421
+ logTask5("Installing MDM enrollment profile");
38119
38422
  const enrollmentProfile = await this.retry(
38120
38423
  "generate mdm enrollment profile",
38121
38424
  () => {
@@ -38140,7 +38443,7 @@ var ActivationFlow = class {
38140
38443
  if (!profileIdentifier) {
38141
38444
  return;
38142
38445
  }
38143
- logTask("Removing WiFi profile");
38446
+ logTask5("Removing WiFi profile");
38144
38447
  await this.retryIosCommand(
38145
38448
  "remove wifi profile",
38146
38449
  () => this.iosCli.removeProfile(udid, profileIdentifier)
@@ -38161,9 +38464,9 @@ var ActivationFlow = class {
38161
38464
  }
38162
38465
  } catch (error) {
38163
38466
  const errorMsg = error instanceof Error ? error.message : String(error);
38164
- logError(`${label} failed: ${errorMsg}`);
38467
+ logError4(`${label} failed: ${errorMsg}`);
38165
38468
  }
38166
- logInfo(`Retrying ${label}... ${attempt + 1} of ${retries}`);
38469
+ logInfo7(`Retrying ${label}... ${attempt + 1} of ${retries}`);
38167
38470
  await new Promise((resolve2) => setTimeout(resolve2, retryDelayMs));
38168
38471
  }
38169
38472
  throw new Error(`Failed to ${label} after ${retries} attempts`);
@@ -38172,16 +38475,16 @@ var ActivationFlow = class {
38172
38475
  async function saveProfileToTemp(profile, prefix) {
38173
38476
  const tempFilePath = (0, import_node_path5.join)((0, import_node_os5.tmpdir)(), `mce_${prefix}_${Date.now()}.mobileconfig`);
38174
38477
  await (0, import_promises2.writeFile)(tempFilePath, profile, "utf-8");
38175
- logInfo(`Profile saved to: ${tempFilePath}`);
38478
+ logInfo7(`Profile saved to: ${tempFilePath}`);
38176
38479
  return tempFilePath;
38177
38480
  }
38178
38481
  async function removeTempFile(filePath, label) {
38179
38482
  try {
38180
38483
  await (0, import_promises2.unlink)(filePath);
38181
- logInfo(`Removed ${label} temp file: ${filePath}`);
38484
+ logInfo7(`Removed ${label} temp file: ${filePath}`);
38182
38485
  } catch (error) {
38183
38486
  const errorMsg = error instanceof Error ? error.message : String(error);
38184
- logError(`Failed to remove ${label} temp file: ${errorMsg}`);
38487
+ logError4(`Failed to remove ${label} temp file: ${errorMsg}`);
38185
38488
  }
38186
38489
  }
38187
38490
  function getProfileIdentifierFromProfile(profile) {
@@ -38216,6 +38519,7 @@ function isActivationSuccess(result) {
38216
38519
  // src/logic/iosCli.ts
38217
38520
  var import_node_child_process3 = require("node:child_process");
38218
38521
  var import_node_path6 = require("node:path");
38522
+ var { logDetail } = createLoggers("apple-kit:ios-cli");
38219
38523
  var ios;
38220
38524
  function iosCli() {
38221
38525
  const iosBinaryPath = resolveIosBinaryPath();
@@ -38363,6 +38667,44 @@ function parseProfileListOutput(output) {
38363
38667
  }
38364
38668
  return profiles;
38365
38669
  }
38670
+ function parseFsyncTreeStdout(stdout) {
38671
+ return stdout.split(/\r?\n/).map((line) => line.trim()).filter((line) => line.length > 0).map((line) => line.replace(/^\|\s*\|-\s*/, "").replace(/^\|-\s*/, "")).filter((name) => name.length > 0);
38672
+ }
38673
+ function runIosCommandWithRawStdout(iosBinaryPath, args) {
38674
+ return new Promise((resolve2, reject) => {
38675
+ logDetail(`Running command: ${iosBinaryPath} ${args.join(" ")}`);
38676
+ const child = (0, import_node_child_process3.spawn)(iosBinaryPath, args, {
38677
+ windowsHide: true,
38678
+ stdio: ["ignore", "pipe", "pipe"]
38679
+ });
38680
+ let stdout = "";
38681
+ let stderr = "";
38682
+ child.stdout?.on("data", (data) => {
38683
+ stdout += data.toString();
38684
+ });
38685
+ child.stderr?.on("data", (data) => {
38686
+ stderr += data.toString();
38687
+ });
38688
+ child.on("error", (error) => {
38689
+ reject(error);
38690
+ });
38691
+ child.on("close", (code) => {
38692
+ const logMessages = stderr.split("\n").map((line) => line.trim()).filter((line) => line.length > 0).map((line) => safeParseJson(line)).filter((item) => Boolean(item)).map((lineJson) => ({
38693
+ level: lineJson.level,
38694
+ msg: lineJson.msg,
38695
+ timestamp: lineJson.timestamp
38696
+ }));
38697
+ const raw = {
38698
+ command: iosBinaryPath,
38699
+ args,
38700
+ output: [],
38701
+ logMessages,
38702
+ exitCode: code ?? 0
38703
+ };
38704
+ resolve2({ stdout, stderr, exitCode: code ?? 0, raw });
38705
+ });
38706
+ });
38707
+ }
38366
38708
  function createIosCli(iosBinaryPath) {
38367
38709
  return {
38368
38710
  async listDevices() {
@@ -38425,18 +38767,97 @@ function createIosCli(iosBinaryPath) {
38425
38767
  },
38426
38768
  async installApp(deviceId, ipaPath) {
38427
38769
  return runIosCommand(iosBinaryPath, ["install", `--path=${ipaPath}`, "--udid", deviceId]);
38770
+ },
38771
+ async tunnelStart(deviceId, userspace = false) {
38772
+ const args = ["tunnel", "start", "--udid", deviceId, ...userspace ? ["--userspace"] : []];
38773
+ logDetail(`Spawning tunnel: ${iosBinaryPath} ${args.join(" ")}`);
38774
+ const child = (0, import_node_child_process3.spawn)(iosBinaryPath, args, {
38775
+ windowsHide: true,
38776
+ stdio: ["ignore", "pipe", "pipe"]
38777
+ });
38778
+ return new Promise((resolve2, reject) => {
38779
+ let settled = false;
38780
+ const cleanup = () => {
38781
+ child.off("error", onError);
38782
+ child.off("exit", onExit);
38783
+ child.stdout?.off("data", onReadyCheck);
38784
+ child.stderr?.off("data", onReadyCheck);
38785
+ clearTimeout(readyTimeout);
38786
+ };
38787
+ const finish = (result) => {
38788
+ if (settled) return;
38789
+ settled = true;
38790
+ cleanup();
38791
+ if (result.reject) reject(result.reject);
38792
+ else if (result.resolve !== void 0) resolve2(result.resolve);
38793
+ };
38794
+ const onError = (err) => finish({ reject: err });
38795
+ const onExit = (code) => finish({ reject: new Error(`Tunnel exited early (code=${code})`) });
38796
+ const onReadyCheck = (data) => {
38797
+ const line = data.toString();
38798
+ const isReady = line.includes("Tunnel server started") || line.includes("tunnel") && (line.includes("listening") || line.includes("connected"));
38799
+ if (isReady) finish({ resolve: child });
38800
+ };
38801
+ const readyTimeout = setTimeout(() => finish({ resolve: child }), 1e4);
38802
+ child.once("error", onError);
38803
+ child.once("exit", onExit);
38804
+ child.stdout?.on("data", onReadyCheck);
38805
+ child.stderr?.on("data", onReadyCheck);
38806
+ });
38807
+ },
38808
+ async fsyncPull(deviceId, app, srcPath, dstPath) {
38809
+ return runIosCommand(iosBinaryPath, [
38810
+ "fsync",
38811
+ "--app",
38812
+ app,
38813
+ "pull",
38814
+ "--srcPath",
38815
+ srcPath,
38816
+ "--dstPath",
38817
+ dstPath,
38818
+ "--udid",
38819
+ deviceId
38820
+ ]);
38821
+ },
38822
+ async fsyncPush(deviceId, app, srcPath, dstPath) {
38823
+ return runIosCommand(iosBinaryPath, [
38824
+ "fsync",
38825
+ "--app",
38826
+ app,
38827
+ "push",
38828
+ "--srcPath",
38829
+ srcPath,
38830
+ "--dstPath",
38831
+ dstPath,
38832
+ "--udid",
38833
+ deviceId
38834
+ ]);
38835
+ },
38836
+ async fsyncTree(deviceId, app, path) {
38837
+ const args = [
38838
+ "fsync",
38839
+ "--app",
38840
+ app,
38841
+ "tree",
38842
+ "--udid",
38843
+ deviceId,
38844
+ ...path !== void 0 && path !== "" ? ["--path", path] : []
38845
+ ];
38846
+ const { stdout, raw } = await runIosCommandWithRawStdout(iosBinaryPath, args);
38847
+ const entries = parseFsyncTreeStdout(stdout);
38848
+ return { entries, raw };
38428
38849
  }
38429
38850
  };
38430
38851
  }
38431
38852
 
38432
38853
  // src/logic/appleDeviceKit.ts
38854
+ var { logInfo: logInfo8, setNamespace } = createLoggers("apple-kit");
38433
38855
  var AppleDeviceKit = class {
38434
38856
  constructor(udid, logicalPort) {
38435
38857
  this.logicalPort = logicalPort;
38436
38858
  this.deviceId = udid;
38437
- setLogLevel(process.env.LOG_LEVEL ?? "none");
38438
- logNamespace(`apple:${udid}`);
38439
- logInfo(
38859
+ setNamespace(`apple-kit:${udid}`);
38860
+ logInfo8(
38440
38861
  `AppleDeviceKit initialized for device: ${this.deviceId}, logical port: ${this.logicalPort}`
38441
38862
  );
38442
38863
  const iosBinaryPath = resolveIosBinaryPath();
@@ -38668,7 +39089,7 @@ var AppleDeviceKit = class {
38668
39089
  if (this.isDisposed) {
38669
39090
  return;
38670
39091
  }
38671
- logInfo(`Disposing AppleDeviceKit for device: ${this.deviceId}`);
39092
+ logInfo8(`Disposing AppleDeviceKit for device: ${this.deviceId}`);
38672
39093
  this.closePortForward();
38673
39094
  this.isDisposed = true;
38674
39095
  }