@mcesystems/apple-kit 1.0.8 → 1.0.11

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
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
8
11
  var __export = (target, all) => {
9
12
  for (var name in all)
10
13
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -27,15 +30,780 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
30
  ));
28
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
32
 
33
+ // ../../node_modules/.pnpm/ms@2.1.3/node_modules/ms/index.js
34
+ var require_ms = __commonJS({
35
+ "../../node_modules/.pnpm/ms@2.1.3/node_modules/ms/index.js"(exports2, module2) {
36
+ var s = 1e3;
37
+ var m = s * 60;
38
+ var h = m * 60;
39
+ var d = h * 24;
40
+ var w = d * 7;
41
+ var y = d * 365.25;
42
+ module2.exports = function(val, options) {
43
+ options = options || {};
44
+ var type = typeof val;
45
+ if (type === "string" && val.length > 0) {
46
+ return parse(val);
47
+ } else if (type === "number" && isFinite(val)) {
48
+ return options.long ? fmtLong(val) : fmtShort(val);
49
+ }
50
+ throw new Error(
51
+ "val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
52
+ );
53
+ };
54
+ function parse(str) {
55
+ str = String(str);
56
+ if (str.length > 100) {
57
+ return;
58
+ }
59
+ var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
60
+ str
61
+ );
62
+ if (!match) {
63
+ return;
64
+ }
65
+ var n = parseFloat(match[1]);
66
+ var type = (match[2] || "ms").toLowerCase();
67
+ switch (type) {
68
+ case "years":
69
+ case "year":
70
+ case "yrs":
71
+ case "yr":
72
+ case "y":
73
+ return n * y;
74
+ case "weeks":
75
+ case "week":
76
+ case "w":
77
+ return n * w;
78
+ case "days":
79
+ case "day":
80
+ case "d":
81
+ return n * d;
82
+ case "hours":
83
+ case "hour":
84
+ case "hrs":
85
+ case "hr":
86
+ case "h":
87
+ return n * h;
88
+ case "minutes":
89
+ case "minute":
90
+ case "mins":
91
+ case "min":
92
+ case "m":
93
+ return n * m;
94
+ case "seconds":
95
+ case "second":
96
+ case "secs":
97
+ case "sec":
98
+ case "s":
99
+ return n * s;
100
+ case "milliseconds":
101
+ case "millisecond":
102
+ case "msecs":
103
+ case "msec":
104
+ case "ms":
105
+ return n;
106
+ default:
107
+ return void 0;
108
+ }
109
+ }
110
+ function fmtShort(ms) {
111
+ var msAbs = Math.abs(ms);
112
+ if (msAbs >= d) {
113
+ return Math.round(ms / d) + "d";
114
+ }
115
+ if (msAbs >= h) {
116
+ return Math.round(ms / h) + "h";
117
+ }
118
+ if (msAbs >= m) {
119
+ return Math.round(ms / m) + "m";
120
+ }
121
+ if (msAbs >= s) {
122
+ return Math.round(ms / s) + "s";
123
+ }
124
+ return ms + "ms";
125
+ }
126
+ function fmtLong(ms) {
127
+ var msAbs = Math.abs(ms);
128
+ if (msAbs >= d) {
129
+ return plural(ms, msAbs, d, "day");
130
+ }
131
+ if (msAbs >= h) {
132
+ return plural(ms, msAbs, h, "hour");
133
+ }
134
+ if (msAbs >= m) {
135
+ return plural(ms, msAbs, m, "minute");
136
+ }
137
+ if (msAbs >= s) {
138
+ return plural(ms, msAbs, s, "second");
139
+ }
140
+ return ms + " ms";
141
+ }
142
+ function plural(ms, msAbs, n, name) {
143
+ var isPlural = msAbs >= n * 1.5;
144
+ return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
145
+ }
146
+ }
147
+ });
148
+
149
+ // ../../node_modules/.pnpm/debug@4.4.3/node_modules/debug/src/common.js
150
+ var require_common = __commonJS({
151
+ "../../node_modules/.pnpm/debug@4.4.3/node_modules/debug/src/common.js"(exports2, module2) {
152
+ function setup(env) {
153
+ createDebug2.debug = createDebug2;
154
+ createDebug2.default = createDebug2;
155
+ createDebug2.coerce = coerce;
156
+ createDebug2.disable = disable;
157
+ createDebug2.enable = enable;
158
+ createDebug2.enabled = enabled;
159
+ createDebug2.humanize = require_ms();
160
+ createDebug2.destroy = destroy;
161
+ Object.keys(env).forEach((key) => {
162
+ createDebug2[key] = env[key];
163
+ });
164
+ createDebug2.names = [];
165
+ createDebug2.skips = [];
166
+ createDebug2.formatters = {};
167
+ function selectColor(namespace) {
168
+ let hash = 0;
169
+ for (let i = 0; i < namespace.length; i++) {
170
+ hash = (hash << 5) - hash + namespace.charCodeAt(i);
171
+ hash |= 0;
172
+ }
173
+ return createDebug2.colors[Math.abs(hash) % createDebug2.colors.length];
174
+ }
175
+ createDebug2.selectColor = selectColor;
176
+ function createDebug2(namespace) {
177
+ let prevTime;
178
+ let enableOverride = null;
179
+ let namespacesCache;
180
+ let enabledCache;
181
+ function debug2(...args) {
182
+ if (!debug2.enabled) {
183
+ return;
184
+ }
185
+ const self = debug2;
186
+ const curr = Number(/* @__PURE__ */ new Date());
187
+ const ms = curr - (prevTime || curr);
188
+ self.diff = ms;
189
+ self.prev = prevTime;
190
+ self.curr = curr;
191
+ prevTime = curr;
192
+ args[0] = createDebug2.coerce(args[0]);
193
+ if (typeof args[0] !== "string") {
194
+ args.unshift("%O");
195
+ }
196
+ let index = 0;
197
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
198
+ if (match === "%%") {
199
+ return "%";
200
+ }
201
+ index++;
202
+ const formatter = createDebug2.formatters[format];
203
+ if (typeof formatter === "function") {
204
+ const val = args[index];
205
+ match = formatter.call(self, val);
206
+ args.splice(index, 1);
207
+ index--;
208
+ }
209
+ return match;
210
+ });
211
+ createDebug2.formatArgs.call(self, args);
212
+ const logFn = self.log || createDebug2.log;
213
+ logFn.apply(self, args);
214
+ }
215
+ debug2.namespace = namespace;
216
+ debug2.useColors = createDebug2.useColors();
217
+ debug2.color = createDebug2.selectColor(namespace);
218
+ debug2.extend = extend;
219
+ debug2.destroy = createDebug2.destroy;
220
+ Object.defineProperty(debug2, "enabled", {
221
+ enumerable: true,
222
+ configurable: false,
223
+ get: () => {
224
+ if (enableOverride !== null) {
225
+ return enableOverride;
226
+ }
227
+ if (namespacesCache !== createDebug2.namespaces) {
228
+ namespacesCache = createDebug2.namespaces;
229
+ enabledCache = createDebug2.enabled(namespace);
230
+ }
231
+ return enabledCache;
232
+ },
233
+ set: (v) => {
234
+ enableOverride = v;
235
+ }
236
+ });
237
+ if (typeof createDebug2.init === "function") {
238
+ createDebug2.init(debug2);
239
+ }
240
+ return debug2;
241
+ }
242
+ function extend(namespace, delimiter) {
243
+ const newDebug = createDebug2(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
244
+ newDebug.log = this.log;
245
+ return newDebug;
246
+ }
247
+ function enable(namespaces) {
248
+ createDebug2.save(namespaces);
249
+ createDebug2.namespaces = namespaces;
250
+ createDebug2.names = [];
251
+ createDebug2.skips = [];
252
+ const split = (typeof namespaces === "string" ? namespaces : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean);
253
+ for (const ns of split) {
254
+ if (ns[0] === "-") {
255
+ createDebug2.skips.push(ns.slice(1));
256
+ } else {
257
+ createDebug2.names.push(ns);
258
+ }
259
+ }
260
+ }
261
+ function matchesTemplate(search, template) {
262
+ let searchIndex = 0;
263
+ let templateIndex = 0;
264
+ let starIndex = -1;
265
+ let matchIndex = 0;
266
+ while (searchIndex < search.length) {
267
+ if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) {
268
+ if (template[templateIndex] === "*") {
269
+ starIndex = templateIndex;
270
+ matchIndex = searchIndex;
271
+ templateIndex++;
272
+ } else {
273
+ searchIndex++;
274
+ templateIndex++;
275
+ }
276
+ } else if (starIndex !== -1) {
277
+ templateIndex = starIndex + 1;
278
+ matchIndex++;
279
+ searchIndex = matchIndex;
280
+ } else {
281
+ return false;
282
+ }
283
+ }
284
+ while (templateIndex < template.length && template[templateIndex] === "*") {
285
+ templateIndex++;
286
+ }
287
+ return templateIndex === template.length;
288
+ }
289
+ function disable() {
290
+ const namespaces = [
291
+ ...createDebug2.names,
292
+ ...createDebug2.skips.map((namespace) => "-" + namespace)
293
+ ].join(",");
294
+ createDebug2.enable("");
295
+ return namespaces;
296
+ }
297
+ function enabled(name) {
298
+ for (const skip of createDebug2.skips) {
299
+ if (matchesTemplate(name, skip)) {
300
+ return false;
301
+ }
302
+ }
303
+ for (const ns of createDebug2.names) {
304
+ if (matchesTemplate(name, ns)) {
305
+ return true;
306
+ }
307
+ }
308
+ return false;
309
+ }
310
+ function coerce(val) {
311
+ if (val instanceof Error) {
312
+ return val.stack || val.message;
313
+ }
314
+ return val;
315
+ }
316
+ function destroy() {
317
+ console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
318
+ }
319
+ createDebug2.enable(createDebug2.load());
320
+ return createDebug2;
321
+ }
322
+ module2.exports = setup;
323
+ }
324
+ });
325
+
326
+ // ../../node_modules/.pnpm/debug@4.4.3/node_modules/debug/src/browser.js
327
+ var require_browser = __commonJS({
328
+ "../../node_modules/.pnpm/debug@4.4.3/node_modules/debug/src/browser.js"(exports2, module2) {
329
+ exports2.formatArgs = formatArgs;
330
+ exports2.save = save;
331
+ exports2.load = load;
332
+ exports2.useColors = useColors;
333
+ exports2.storage = localstorage();
334
+ exports2.destroy = /* @__PURE__ */ (() => {
335
+ let warned = false;
336
+ return () => {
337
+ if (!warned) {
338
+ warned = true;
339
+ console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
340
+ }
341
+ };
342
+ })();
343
+ exports2.colors = [
344
+ "#0000CC",
345
+ "#0000FF",
346
+ "#0033CC",
347
+ "#0033FF",
348
+ "#0066CC",
349
+ "#0066FF",
350
+ "#0099CC",
351
+ "#0099FF",
352
+ "#00CC00",
353
+ "#00CC33",
354
+ "#00CC66",
355
+ "#00CC99",
356
+ "#00CCCC",
357
+ "#00CCFF",
358
+ "#3300CC",
359
+ "#3300FF",
360
+ "#3333CC",
361
+ "#3333FF",
362
+ "#3366CC",
363
+ "#3366FF",
364
+ "#3399CC",
365
+ "#3399FF",
366
+ "#33CC00",
367
+ "#33CC33",
368
+ "#33CC66",
369
+ "#33CC99",
370
+ "#33CCCC",
371
+ "#33CCFF",
372
+ "#6600CC",
373
+ "#6600FF",
374
+ "#6633CC",
375
+ "#6633FF",
376
+ "#66CC00",
377
+ "#66CC33",
378
+ "#9900CC",
379
+ "#9900FF",
380
+ "#9933CC",
381
+ "#9933FF",
382
+ "#99CC00",
383
+ "#99CC33",
384
+ "#CC0000",
385
+ "#CC0033",
386
+ "#CC0066",
387
+ "#CC0099",
388
+ "#CC00CC",
389
+ "#CC00FF",
390
+ "#CC3300",
391
+ "#CC3333",
392
+ "#CC3366",
393
+ "#CC3399",
394
+ "#CC33CC",
395
+ "#CC33FF",
396
+ "#CC6600",
397
+ "#CC6633",
398
+ "#CC9900",
399
+ "#CC9933",
400
+ "#CCCC00",
401
+ "#CCCC33",
402
+ "#FF0000",
403
+ "#FF0033",
404
+ "#FF0066",
405
+ "#FF0099",
406
+ "#FF00CC",
407
+ "#FF00FF",
408
+ "#FF3300",
409
+ "#FF3333",
410
+ "#FF3366",
411
+ "#FF3399",
412
+ "#FF33CC",
413
+ "#FF33FF",
414
+ "#FF6600",
415
+ "#FF6633",
416
+ "#FF9900",
417
+ "#FF9933",
418
+ "#FFCC00",
419
+ "#FFCC33"
420
+ ];
421
+ function useColors() {
422
+ if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) {
423
+ return true;
424
+ }
425
+ if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
426
+ return false;
427
+ }
428
+ let m;
429
+ return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
430
+ typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
431
+ // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
432
+ typeof navigator !== "undefined" && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
433
+ typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
434
+ }
435
+ function formatArgs(args) {
436
+ args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module2.exports.humanize(this.diff);
437
+ if (!this.useColors) {
438
+ return;
439
+ }
440
+ const c = "color: " + this.color;
441
+ args.splice(1, 0, c, "color: inherit");
442
+ let index = 0;
443
+ let lastC = 0;
444
+ args[0].replace(/%[a-zA-Z%]/g, (match) => {
445
+ if (match === "%%") {
446
+ return;
447
+ }
448
+ index++;
449
+ if (match === "%c") {
450
+ lastC = index;
451
+ }
452
+ });
453
+ args.splice(lastC, 0, c);
454
+ }
455
+ exports2.log = console.debug || console.log || (() => {
456
+ });
457
+ function save(namespaces) {
458
+ try {
459
+ if (namespaces) {
460
+ exports2.storage.setItem("debug", namespaces);
461
+ } else {
462
+ exports2.storage.removeItem("debug");
463
+ }
464
+ } catch (error) {
465
+ }
466
+ }
467
+ function load() {
468
+ let r;
469
+ try {
470
+ r = exports2.storage.getItem("debug") || exports2.storage.getItem("DEBUG");
471
+ } catch (error) {
472
+ }
473
+ if (!r && typeof process !== "undefined" && "env" in process) {
474
+ r = process.env.DEBUG;
475
+ }
476
+ return r;
477
+ }
478
+ function localstorage() {
479
+ try {
480
+ return localStorage;
481
+ } catch (error) {
482
+ }
483
+ }
484
+ module2.exports = require_common()(exports2);
485
+ var { formatters } = module2.exports;
486
+ formatters.j = function(v) {
487
+ try {
488
+ return JSON.stringify(v);
489
+ } catch (error) {
490
+ return "[UnexpectedJSONParseError]: " + error.message;
491
+ }
492
+ };
493
+ }
494
+ });
495
+
496
+ // ../../node_modules/.pnpm/has-flag@4.0.0/node_modules/has-flag/index.js
497
+ var require_has_flag = __commonJS({
498
+ "../../node_modules/.pnpm/has-flag@4.0.0/node_modules/has-flag/index.js"(exports2, module2) {
499
+ "use strict";
500
+ module2.exports = (flag, argv = process.argv) => {
501
+ const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
502
+ const position = argv.indexOf(prefix + flag);
503
+ const terminatorPosition = argv.indexOf("--");
504
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
505
+ };
506
+ }
507
+ });
508
+
509
+ // ../../node_modules/.pnpm/supports-color@7.2.0/node_modules/supports-color/index.js
510
+ var require_supports_color = __commonJS({
511
+ "../../node_modules/.pnpm/supports-color@7.2.0/node_modules/supports-color/index.js"(exports2, module2) {
512
+ "use strict";
513
+ var os = require("os");
514
+ var tty = require("tty");
515
+ var hasFlag = require_has_flag();
516
+ var { env } = process;
517
+ var forceColor;
518
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
519
+ forceColor = 0;
520
+ } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
521
+ forceColor = 1;
522
+ }
523
+ if ("FORCE_COLOR" in env) {
524
+ if (env.FORCE_COLOR === "true") {
525
+ forceColor = 1;
526
+ } else if (env.FORCE_COLOR === "false") {
527
+ forceColor = 0;
528
+ } else {
529
+ forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
530
+ }
531
+ }
532
+ function translateLevel(level) {
533
+ if (level === 0) {
534
+ return false;
535
+ }
536
+ return {
537
+ level,
538
+ hasBasic: true,
539
+ has256: level >= 2,
540
+ has16m: level >= 3
541
+ };
542
+ }
543
+ function supportsColor(haveStream, streamIsTTY) {
544
+ if (forceColor === 0) {
545
+ return 0;
546
+ }
547
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
548
+ return 3;
549
+ }
550
+ if (hasFlag("color=256")) {
551
+ return 2;
552
+ }
553
+ if (haveStream && !streamIsTTY && forceColor === void 0) {
554
+ return 0;
555
+ }
556
+ const min = forceColor || 0;
557
+ if (env.TERM === "dumb") {
558
+ return min;
559
+ }
560
+ if (process.platform === "win32") {
561
+ const osRelease = os.release().split(".");
562
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
563
+ return Number(osRelease[2]) >= 14931 ? 3 : 2;
564
+ }
565
+ return 1;
566
+ }
567
+ if ("CI" in env) {
568
+ if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
569
+ return 1;
570
+ }
571
+ return min;
572
+ }
573
+ if ("TEAMCITY_VERSION" in env) {
574
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
575
+ }
576
+ if (env.COLORTERM === "truecolor") {
577
+ return 3;
578
+ }
579
+ if ("TERM_PROGRAM" in env) {
580
+ const version = parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
581
+ switch (env.TERM_PROGRAM) {
582
+ case "iTerm.app":
583
+ return version >= 3 ? 3 : 2;
584
+ case "Apple_Terminal":
585
+ return 2;
586
+ }
587
+ }
588
+ if (/-256(color)?$/i.test(env.TERM)) {
589
+ return 2;
590
+ }
591
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
592
+ return 1;
593
+ }
594
+ if ("COLORTERM" in env) {
595
+ return 1;
596
+ }
597
+ return min;
598
+ }
599
+ function getSupportLevel(stream) {
600
+ const level = supportsColor(stream, stream && stream.isTTY);
601
+ return translateLevel(level);
602
+ }
603
+ module2.exports = {
604
+ supportsColor: getSupportLevel,
605
+ stdout: translateLevel(supportsColor(true, tty.isatty(1))),
606
+ stderr: translateLevel(supportsColor(true, tty.isatty(2)))
607
+ };
608
+ }
609
+ });
610
+
611
+ // ../../node_modules/.pnpm/debug@4.4.3/node_modules/debug/src/node.js
612
+ var require_node = __commonJS({
613
+ "../../node_modules/.pnpm/debug@4.4.3/node_modules/debug/src/node.js"(exports2, module2) {
614
+ var tty = require("tty");
615
+ var util = require("util");
616
+ exports2.init = init;
617
+ exports2.log = log;
618
+ exports2.formatArgs = formatArgs;
619
+ exports2.save = save;
620
+ exports2.load = load;
621
+ exports2.useColors = useColors;
622
+ exports2.destroy = util.deprecate(
623
+ () => {
624
+ },
625
+ "Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."
626
+ );
627
+ exports2.colors = [6, 2, 3, 4, 5, 1];
628
+ try {
629
+ const supportsColor = require_supports_color();
630
+ if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
631
+ exports2.colors = [
632
+ 20,
633
+ 21,
634
+ 26,
635
+ 27,
636
+ 32,
637
+ 33,
638
+ 38,
639
+ 39,
640
+ 40,
641
+ 41,
642
+ 42,
643
+ 43,
644
+ 44,
645
+ 45,
646
+ 56,
647
+ 57,
648
+ 62,
649
+ 63,
650
+ 68,
651
+ 69,
652
+ 74,
653
+ 75,
654
+ 76,
655
+ 77,
656
+ 78,
657
+ 79,
658
+ 80,
659
+ 81,
660
+ 92,
661
+ 93,
662
+ 98,
663
+ 99,
664
+ 112,
665
+ 113,
666
+ 128,
667
+ 129,
668
+ 134,
669
+ 135,
670
+ 148,
671
+ 149,
672
+ 160,
673
+ 161,
674
+ 162,
675
+ 163,
676
+ 164,
677
+ 165,
678
+ 166,
679
+ 167,
680
+ 168,
681
+ 169,
682
+ 170,
683
+ 171,
684
+ 172,
685
+ 173,
686
+ 178,
687
+ 179,
688
+ 184,
689
+ 185,
690
+ 196,
691
+ 197,
692
+ 198,
693
+ 199,
694
+ 200,
695
+ 201,
696
+ 202,
697
+ 203,
698
+ 204,
699
+ 205,
700
+ 206,
701
+ 207,
702
+ 208,
703
+ 209,
704
+ 214,
705
+ 215,
706
+ 220,
707
+ 221
708
+ ];
709
+ }
710
+ } catch (error) {
711
+ }
712
+ exports2.inspectOpts = Object.keys(process.env).filter((key) => {
713
+ return /^debug_/i.test(key);
714
+ }).reduce((obj, key) => {
715
+ const prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, (_, k) => {
716
+ return k.toUpperCase();
717
+ });
718
+ let val = process.env[key];
719
+ if (/^(yes|on|true|enabled)$/i.test(val)) {
720
+ val = true;
721
+ } else if (/^(no|off|false|disabled)$/i.test(val)) {
722
+ val = false;
723
+ } else if (val === "null") {
724
+ val = null;
725
+ } else {
726
+ val = Number(val);
727
+ }
728
+ obj[prop] = val;
729
+ return obj;
730
+ }, {});
731
+ function useColors() {
732
+ return "colors" in exports2.inspectOpts ? Boolean(exports2.inspectOpts.colors) : tty.isatty(process.stderr.fd);
733
+ }
734
+ function formatArgs(args) {
735
+ const { namespace: name, useColors: useColors2 } = this;
736
+ if (useColors2) {
737
+ const c = this.color;
738
+ const colorCode = "\x1B[3" + (c < 8 ? c : "8;5;" + c);
739
+ const prefix = ` ${colorCode};1m${name} \x1B[0m`;
740
+ args[0] = prefix + args[0].split("\n").join("\n" + prefix);
741
+ args.push(colorCode + "m+" + module2.exports.humanize(this.diff) + "\x1B[0m");
742
+ } else {
743
+ args[0] = getDate() + name + " " + args[0];
744
+ }
745
+ }
746
+ function getDate() {
747
+ if (exports2.inspectOpts.hideDate) {
748
+ return "";
749
+ }
750
+ return (/* @__PURE__ */ new Date()).toISOString() + " ";
751
+ }
752
+ function log(...args) {
753
+ return process.stderr.write(util.formatWithOptions(exports2.inspectOpts, ...args) + "\n");
754
+ }
755
+ function save(namespaces) {
756
+ if (namespaces) {
757
+ process.env.DEBUG = namespaces;
758
+ } else {
759
+ delete process.env.DEBUG;
760
+ }
761
+ }
762
+ function load() {
763
+ return process.env.DEBUG;
764
+ }
765
+ function init(debug2) {
766
+ debug2.inspectOpts = {};
767
+ const keys = Object.keys(exports2.inspectOpts);
768
+ for (let i = 0; i < keys.length; i++) {
769
+ debug2.inspectOpts[keys[i]] = exports2.inspectOpts[keys[i]];
770
+ }
771
+ }
772
+ module2.exports = require_common()(exports2);
773
+ var { formatters } = module2.exports;
774
+ formatters.o = function(v) {
775
+ this.inspectOpts.colors = this.useColors;
776
+ return util.inspect(v, this.inspectOpts).split("\n").map((str) => str.trim()).join(" ");
777
+ };
778
+ formatters.O = function(v) {
779
+ this.inspectOpts.colors = this.useColors;
780
+ return util.inspect(v, this.inspectOpts);
781
+ };
782
+ }
783
+ });
784
+
785
+ // ../../node_modules/.pnpm/debug@4.4.3/node_modules/debug/src/index.js
786
+ var require_src = __commonJS({
787
+ "../../node_modules/.pnpm/debug@4.4.3/node_modules/debug/src/index.js"(exports2, module2) {
788
+ if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) {
789
+ module2.exports = require_browser();
790
+ } else {
791
+ module2.exports = require_node();
792
+ }
793
+ }
794
+ });
795
+
30
796
  // src/index.ts
31
797
  var index_exports = {};
32
798
  __export(index_exports, {
33
- AppleDeviceKit: () => AppleDeviceKit
799
+ AppleDeviceKit: () => AppleDeviceKit,
800
+ PortManager: () => PortManager,
801
+ getSharedPortManager: () => getSharedPortManager
34
802
  });
35
803
  module.exports = __toCommonJS(index_exports);
36
804
 
37
805
  // src/utils/debug.ts
38
- var import_debug = __toESM(require("debug"));
806
+ var import_debug = __toESM(require_src());
39
807
  var debug = (0, import_debug.default)("apple-kit");
40
808
  var debugTask = (0, import_debug.default)("apple-kit:task");
41
809
  var debugWarning = (0, import_debug.default)("apple-kit:warning");
@@ -47,6 +815,134 @@ function logTask(message) {
47
815
  debugTask(message);
48
816
  }
49
817
 
818
+ // src/utils/portManager.ts
819
+ var import_node_net = require("node:net");
820
+ var PortManager = class {
821
+ allocations = /* @__PURE__ */ new Map();
822
+ basePort;
823
+ maxPortRange;
824
+ /**
825
+ * Create a new PortManager
826
+ *
827
+ * @param basePort Starting port number for allocation (default: 30000)
828
+ * @param maxPortRange Maximum range of ports to search (default: 1000)
829
+ */
830
+ constructor(basePort = 3e4, maxPortRange = 1e3) {
831
+ this.basePort = basePort;
832
+ this.maxPortRange = maxPortRange;
833
+ }
834
+ /**
835
+ * Find an available port starting from the given port number
836
+ */
837
+ async findAvailablePort(startPort) {
838
+ const maxPort = this.basePort + this.maxPortRange;
839
+ for (let port = startPort; port < maxPort; port++) {
840
+ const isAllocated = Array.from(this.allocations.values()).some(
841
+ (a) => a.localPort === port
842
+ );
843
+ if (isAllocated) {
844
+ continue;
845
+ }
846
+ const isAvailable = await this.isPortAvailable(port);
847
+ if (isAvailable) {
848
+ return port;
849
+ }
850
+ }
851
+ throw new Error(
852
+ `No available ports found in range ${startPort}-${maxPort}`
853
+ );
854
+ }
855
+ /**
856
+ * Check if a port is available for binding
857
+ */
858
+ isPortAvailable(port) {
859
+ return new Promise((resolve) => {
860
+ const server = (0, import_node_net.createServer)();
861
+ server.once("error", () => {
862
+ resolve(false);
863
+ });
864
+ server.once("listening", () => {
865
+ server.close(() => {
866
+ resolve(true);
867
+ });
868
+ });
869
+ server.listen(port, "127.0.0.1");
870
+ });
871
+ }
872
+ /**
873
+ * Allocate a local port for a logical port
874
+ *
875
+ * @param logicalPort The logical port number (USB hub position)
876
+ * @param devicePort The device port to forward to
877
+ * @returns The allocated port info
878
+ */
879
+ async allocate(logicalPort, devicePort) {
880
+ const existing = this.allocations.get(logicalPort);
881
+ if (existing) {
882
+ logTask(`Reusing existing port allocation for logical port ${logicalPort}: ${existing.localPort}`);
883
+ return existing;
884
+ }
885
+ const preferredPort = this.basePort + logicalPort;
886
+ let localPort;
887
+ const preferredAvailable = await this.isPortAvailable(preferredPort);
888
+ if (preferredAvailable) {
889
+ localPort = preferredPort;
890
+ } else {
891
+ localPort = await this.findAvailablePort(this.basePort);
892
+ }
893
+ const allocation = {
894
+ logicalPort,
895
+ localPort,
896
+ devicePort
897
+ };
898
+ this.allocations.set(logicalPort, allocation);
899
+ logTask(`Allocated port ${localPort} for logical port ${logicalPort} -> device port ${devicePort}`);
900
+ return allocation;
901
+ }
902
+ /**
903
+ * Release the port allocation for a logical port
904
+ */
905
+ release(logicalPort) {
906
+ const allocation = this.allocations.get(logicalPort);
907
+ if (allocation) {
908
+ logTask(`Released port ${allocation.localPort} for logical port ${logicalPort}`);
909
+ this.allocations.delete(logicalPort);
910
+ }
911
+ }
912
+ /**
913
+ * Get the current allocation for a logical port
914
+ */
915
+ getAllocation(logicalPort) {
916
+ return this.allocations.get(logicalPort);
917
+ }
918
+ /**
919
+ * Get all current allocations
920
+ */
921
+ getAllAllocations() {
922
+ return Array.from(this.allocations.values());
923
+ }
924
+ /**
925
+ * Release all allocations
926
+ */
927
+ releaseAll() {
928
+ logTask(`Releasing all port allocations (${this.allocations.size} ports)`);
929
+ this.allocations.clear();
930
+ }
931
+ /**
932
+ * Check if a logical port has an allocation
933
+ */
934
+ hasAllocation(logicalPort) {
935
+ return this.allocations.has(logicalPort);
936
+ }
937
+ };
938
+ var sharedPortManager = null;
939
+ function getSharedPortManager() {
940
+ if (!sharedPortManager) {
941
+ sharedPortManager = new PortManager();
942
+ }
943
+ return sharedPortManager;
944
+ }
945
+
50
946
  // src/logic/actions/device.ts
51
947
  var import_node_child_process = require("node:child_process");
52
948
  var import_node_fs = require("node:fs");
@@ -444,51 +1340,107 @@ async function launchAppWithPymobiledevice3(bundleId, args, udid) {
444
1340
  }
445
1341
 
446
1342
  // src/logic/actions/proxy.ts
447
- async function startPortForward(localPort, devicePort, udid) {
448
- logTask(`Starting port forward ${localPort} -> ${devicePort} for device ${udid}`);
449
- const result = await runIDeviceTool("iproxy", [
450
- localPort.toString(),
451
- devicePort.toString(),
452
- "-u",
453
- udid
454
- ]);
455
- return {
456
- localPort,
457
- devicePort,
458
- ...result
459
- };
460
- }
461
- async function startPortForwardAsync(localPort, devicePort, udid, _timeout = 5e3) {
462
- const result = await startPortForward(localPort, devicePort, udid);
463
- await new Promise((resolve) => setTimeout(resolve, 500));
464
- if (result.stdout.includes("error") || result.stderr.includes("error")) {
465
- throw new Error("Port forwarding failed to start");
1343
+ var import_node_child_process2 = require("node:child_process");
1344
+ var import_node_path2 = require("node:path");
1345
+ function getResourcesBinPath2() {
1346
+ const binPath = process.env.IDeviceBinPath;
1347
+ if (!binPath) {
1348
+ throw new Error("IDeviceBinPath is not set");
466
1349
  }
467
- return result;
1350
+ return binPath;
1351
+ }
1352
+ function startPortForward(localPort, devicePort, udid, startupTimeout = 500) {
1353
+ return new Promise((resolve, reject) => {
1354
+ logTask(`Starting port forward ${localPort} -> ${devicePort} for device ${udid}`);
1355
+ const binPath = getResourcesBinPath2();
1356
+ const toolPath = (0, import_node_path2.join)(binPath, `iproxy${process.platform === "win32" ? ".exe" : ""}`);
1357
+ const child = (0, import_node_child_process2.spawn)(
1358
+ toolPath,
1359
+ [localPort.toString(), devicePort.toString(), "-u", udid],
1360
+ {
1361
+ cwd: binPath,
1362
+ windowsHide: true,
1363
+ stdio: ["ignore", "pipe", "pipe"]
1364
+ }
1365
+ );
1366
+ let hasResolved = false;
1367
+ let stderrOutput = "";
1368
+ child.stderr?.on("data", (data) => {
1369
+ const msg = data.toString();
1370
+ stderrOutput += msg;
1371
+ if (msg.toLowerCase().includes("error") && !hasResolved) {
1372
+ hasResolved = true;
1373
+ child.kill();
1374
+ reject(new Error(`Port forwarding failed: ${msg}`));
1375
+ }
1376
+ });
1377
+ child.on("error", (error) => {
1378
+ if (!hasResolved) {
1379
+ hasResolved = true;
1380
+ reject(new Error(`Failed to start iproxy: ${error.message}`));
1381
+ }
1382
+ });
1383
+ child.on("exit", (code) => {
1384
+ if (!hasResolved) {
1385
+ hasResolved = true;
1386
+ if (code !== 0 && code !== null) {
1387
+ reject(new Error(`iproxy exited with code ${code}: ${stderrOutput}`));
1388
+ }
1389
+ }
1390
+ });
1391
+ setTimeout(() => {
1392
+ if (!hasResolved) {
1393
+ hasResolved = true;
1394
+ logTask(`Port forward started: ${localPort} -> ${devicePort} for device ${udid}`);
1395
+ resolve({
1396
+ result: {
1397
+ localPort,
1398
+ devicePort
1399
+ },
1400
+ process: child
1401
+ });
1402
+ }
1403
+ }, startupTimeout);
1404
+ });
468
1405
  }
469
- async function closePortForward(udid) {
470
- logTask(`Closing port forward for device ${udid}`);
471
- await runIDeviceTool("iproxy", ["-u", udid, "-c"]);
1406
+ function killPortForwardProcess(process2) {
1407
+ if (process2 && !process2.killed) {
1408
+ logTask("Killing port forward process");
1409
+ process2.kill();
1410
+ }
472
1411
  }
473
1412
 
474
1413
  // src/logic/appleDeviceKit.ts
475
1414
  var AppleDeviceKit = class {
476
- constructor(udid, port) {
477
- this.port = port;
1415
+ constructor(udid, logicalPort) {
1416
+ this.logicalPort = logicalPort;
478
1417
  this.deviceId = udid;
479
- logInfo(`AppleDeviceKit initialized for device: ${this.deviceId}`);
1418
+ logInfo(`AppleDeviceKit initialized for device: ${this.deviceId}, logical port: ${this.logicalPort}`);
480
1419
  }
481
1420
  deviceId;
1421
+ proxyProcess = null;
1422
+ portAllocation = null;
1423
+ isDisposed = false;
1424
+ /**
1425
+ * Throws if the kit has been disposed
1426
+ */
1427
+ ensureNotDisposed() {
1428
+ if (this.isDisposed) {
1429
+ throw new Error("AppleDeviceKit has been disposed");
1430
+ }
1431
+ }
482
1432
  /**
483
1433
  * Get detailed device information
484
1434
  */
485
1435
  async getDeviceInfo() {
1436
+ this.ensureNotDisposed();
486
1437
  return getDeviceInfo(this.deviceId);
487
1438
  }
488
1439
  /**
489
1440
  * Check if device is paired/trusted with this computer
490
1441
  */
491
1442
  async isPaired() {
1443
+ this.ensureNotDisposed();
492
1444
  return isPaired(this.deviceId);
493
1445
  }
494
1446
  /**
@@ -499,6 +1451,7 @@ var AppleDeviceKit = class {
499
1451
  * @param pollInterval Poll interval in milliseconds (default: 1000)
500
1452
  */
501
1453
  async waitForPairing(timeout = 12e4, pollInterval = 1e3) {
1454
+ this.ensureNotDisposed();
502
1455
  return waitForPairing(this.deviceId, timeout, pollInterval);
503
1456
  }
504
1457
  /**
@@ -506,6 +1459,7 @@ var AppleDeviceKit = class {
506
1459
  * User must accept the trust dialog on the device
507
1460
  */
508
1461
  async pair() {
1462
+ this.ensureNotDisposed();
509
1463
  return pair(this.deviceId);
510
1464
  }
511
1465
  /**
@@ -522,12 +1476,14 @@ var AppleDeviceKit = class {
522
1476
  * @returns true if device is now trusted
523
1477
  */
524
1478
  async trustDevice(timeout = 6e4, onWaitingForTrust) {
1479
+ this.ensureNotDisposed();
525
1480
  return trustDevice(this.deviceId, timeout, onWaitingForTrust);
526
1481
  }
527
1482
  /**
528
1483
  * Unpair/untrust the device
529
1484
  */
530
1485
  async unpair() {
1486
+ this.ensureNotDisposed();
531
1487
  return unpair(this.deviceId);
532
1488
  }
533
1489
  /**
@@ -536,6 +1492,7 @@ var AppleDeviceKit = class {
536
1492
  * @param ipaPath Path to the IPA file
537
1493
  */
538
1494
  async installApp(ipaPath) {
1495
+ this.ensureNotDisposed();
539
1496
  installApp(ipaPath, this.deviceId);
540
1497
  }
541
1498
  /**
@@ -544,6 +1501,7 @@ var AppleDeviceKit = class {
544
1501
  * @param bundleId Application bundle identifier
545
1502
  */
546
1503
  async uninstallApp(bundleId) {
1504
+ this.ensureNotDisposed();
547
1505
  uninstallApp(bundleId, this.deviceId);
548
1506
  }
549
1507
  /**
@@ -552,12 +1510,14 @@ var AppleDeviceKit = class {
552
1510
  * @param bundleId Application bundle identifier
553
1511
  */
554
1512
  async isAppInstalled(bundleId) {
1513
+ this.ensureNotDisposed();
555
1514
  return isAppInstalled(bundleId, this.deviceId);
556
1515
  }
557
1516
  /**
558
1517
  * List all installed user applications
559
1518
  */
560
1519
  async listApps() {
1520
+ this.ensureNotDisposed();
561
1521
  return listApps(this.deviceId);
562
1522
  }
563
1523
  /**
@@ -567,24 +1527,62 @@ var AppleDeviceKit = class {
567
1527
  * @param args Application arguments
568
1528
  */
569
1529
  async launchApp(bundleId, args = []) {
1530
+ this.ensureNotDisposed();
570
1531
  return launchApp(bundleId, args, this.deviceId);
571
1532
  }
572
1533
  /**
573
1534
  * Start port forwarding and wait for it to be ready.
574
- * we need port forwarding to be able to connect to the device from the computer
1535
+ * The local port is automatically allocated based on the logical port.
1536
+ *
1537
+ * We need port forwarding to be able to connect to the device from the computer
575
1538
  * and communicate with it using the local port.
576
1539
  *
577
- * @param localPort Local port to listen on
1540
+ * Note: Only one port forward can be active at a time per kit instance.
1541
+ * Starting a new port forward will kill any existing one.
1542
+ *
578
1543
  * @param devicePort Device port to forward to
579
- * @param _timeout Timeout in milliseconds (reserved for future use)
1544
+ * @param startupTimeout Time to wait for proxy to start (ms)
1545
+ * @returns The port forward result with the allocated local port
1546
+ */
1547
+ async startPortForwardAsync(devicePort, startupTimeout = 500) {
1548
+ this.ensureNotDisposed();
1549
+ this.killProxyProcess();
1550
+ const portManager = getSharedPortManager();
1551
+ this.portAllocation = await portManager.allocate(this.logicalPort, devicePort);
1552
+ const { result, process: process2 } = await startPortForward(
1553
+ this.portAllocation.localPort,
1554
+ devicePort,
1555
+ this.deviceId,
1556
+ startupTimeout
1557
+ );
1558
+ this.proxyProcess = process2;
1559
+ return result;
1560
+ }
1561
+ /**
1562
+ * Kill the current port forwarding process if running
580
1563
  */
581
- async startPortForwardAsync(localPort, devicePort, _timeout = 5e3) {
582
- return startPortForwardAsync(localPort, devicePort, this.deviceId);
1564
+ killProxyProcess() {
1565
+ if (this.proxyProcess) {
1566
+ killPortForwardProcess(this.proxyProcess);
1567
+ this.proxyProcess = null;
1568
+ }
1569
+ }
1570
+ /**
1571
+ * Close the current port forwarding session and release the port
1572
+ */
1573
+ closePortForward() {
1574
+ this.killProxyProcess();
1575
+ if (this.portAllocation) {
1576
+ const portManager = getSharedPortManager();
1577
+ portManager.release(this.logicalPort);
1578
+ this.portAllocation = null;
1579
+ }
583
1580
  }
584
1581
  /**
585
1582
  * Get the activation state of the device
586
1583
  */
587
1584
  async getActivationState() {
1585
+ this.ensureNotDisposed();
588
1586
  return getActivationState(this.deviceId);
589
1587
  }
590
1588
  /**
@@ -598,6 +1596,7 @@ var AppleDeviceKit = class {
598
1596
  * precondition: the device must be paired and trusted
599
1597
  */
600
1598
  async activate() {
1599
+ this.ensureNotDisposed();
601
1600
  return activate(this.deviceId);
602
1601
  }
603
1602
  /**
@@ -607,17 +1606,61 @@ var AppleDeviceKit = class {
607
1606
  return this.deviceId;
608
1607
  }
609
1608
  /**
610
- * Get the logical port number
1609
+ * Get the logical port number (USB hub position)
1610
+ */
1611
+ getLogicalPort() {
1612
+ return this.logicalPort;
1613
+ }
1614
+ /**
1615
+ * Get the currently allocated local port for forwarding
1616
+ * Returns undefined if no port forward is active
1617
+ */
1618
+ getAllocatedPort() {
1619
+ return this.portAllocation?.localPort;
1620
+ }
1621
+ /**
1622
+ * Get the current port allocation info
1623
+ */
1624
+ getPortAllocation() {
1625
+ return this.portAllocation;
1626
+ }
1627
+ /**
1628
+ * Check if this kit has been disposed
611
1629
  */
612
- getPort() {
613
- return this.port;
1630
+ get disposed() {
1631
+ return this.isDisposed;
614
1632
  }
615
- async closePortForward() {
616
- return closePortForward(this.deviceId);
1633
+ /**
1634
+ * Check if a port forward is currently active
1635
+ */
1636
+ get hasActivePortForward() {
1637
+ return this.proxyProcess !== null && !this.proxyProcess.killed;
1638
+ }
1639
+ /**
1640
+ * Dispose of the kit and clean up all resources.
1641
+ * This will kill any running proxy processes and release port allocations.
1642
+ *
1643
+ * After calling dispose(), the kit instance should not be used.
1644
+ */
1645
+ dispose() {
1646
+ if (this.isDisposed) {
1647
+ return;
1648
+ }
1649
+ logInfo(`Disposing AppleDeviceKit for device: ${this.deviceId}`);
1650
+ this.closePortForward();
1651
+ this.isDisposed = true;
1652
+ }
1653
+ /**
1654
+ * Symbol.dispose implementation for using with `using` keyword (TypeScript 5.2+)
1655
+ */
1656
+ [Symbol.dispose]() {
1657
+ this.dispose();
617
1658
  }
618
1659
  };
619
1660
  // Annotate the CommonJS export names for ESM import in node:
620
1661
  0 && (module.exports = {
621
- AppleDeviceKit
1662
+ AppleDeviceKit,
1663
+ PortManager,
1664
+ getSharedPortManager
622
1665
  });
623
1666
  //# sourceMappingURL=index.js.map