@mcesystems/auth-g4 1.0.65

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 ADDED
@@ -0,0 +1,1037 @@
1
+ var __importMetaUrl = require("url").pathToFileURL(__filename).href;
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/index.ts
32
+ var index_exports = {};
33
+ __export(index_exports, {
34
+ getAuthToken: () => getAuthToken,
35
+ readCredentialsFromFile: () => readCredentialsFromFile
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+
39
+ // src/logic/authClient.ts
40
+ var import_node_crypto = require("node:crypto");
41
+ var import_node_util = require("node:util");
42
+
43
+ // ../tool-debug/dist/index.mjs
44
+ var import_node_process = __toESM(require("node:process"), 1);
45
+ var import_node_os = __toESM(require("node:os"), 1);
46
+ var import_node_tty = __toESM(require("node:tty"), 1);
47
+ var __create2 = Object.create;
48
+ var __defProp2 = Object.defineProperty;
49
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
50
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
51
+ var __getProtoOf2 = Object.getPrototypeOf;
52
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
53
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
54
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
55
+ }) : x)(function(x) {
56
+ if (typeof require !== "undefined") return require.apply(this, arguments);
57
+ throw Error('Dynamic require of "' + x + '" is not supported');
58
+ });
59
+ var __esm = (fn, res) => function __init() {
60
+ return fn && (res = (0, fn[__getOwnPropNames2(fn)[0]])(fn = 0)), res;
61
+ };
62
+ var __commonJS = (cb, mod) => function __require2() {
63
+ return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
64
+ };
65
+ var __export2 = (target, all) => {
66
+ for (var name in all)
67
+ __defProp2(target, name, { get: all[name], enumerable: true });
68
+ };
69
+ var __copyProps2 = (to, from, except, desc) => {
70
+ if (from && typeof from === "object" || typeof from === "function") {
71
+ for (let key of __getOwnPropNames2(from))
72
+ if (!__hasOwnProp2.call(to, key) && key !== except)
73
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
74
+ }
75
+ return to;
76
+ };
77
+ var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
78
+ // If the importer is in node compatibility mode or this is not an ESM
79
+ // file that has been converted to a CommonJS file using a Babel-
80
+ // compatible transform (i.e. "__esModule" has not been set), then set
81
+ // "default" to the CommonJS "module.exports" for node compatibility.
82
+ isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
83
+ mod
84
+ ));
85
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
86
+ var require_ms = __commonJS({
87
+ "../../node_modules/.pnpm/ms@2.1.3/node_modules/ms/index.js"(exports2, module2) {
88
+ var s = 1e3;
89
+ var m = s * 60;
90
+ var h = m * 60;
91
+ var d = h * 24;
92
+ var w = d * 7;
93
+ var y = d * 365.25;
94
+ module2.exports = function(val, options) {
95
+ options = options || {};
96
+ var type = typeof val;
97
+ if (type === "string" && val.length > 0) {
98
+ return parse(val);
99
+ } else if (type === "number" && isFinite(val)) {
100
+ return options.long ? fmtLong(val) : fmtShort(val);
101
+ }
102
+ throw new Error(
103
+ "val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
104
+ );
105
+ };
106
+ function parse(str) {
107
+ str = String(str);
108
+ if (str.length > 100) {
109
+ return;
110
+ }
111
+ 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(
112
+ str
113
+ );
114
+ if (!match) {
115
+ return;
116
+ }
117
+ var n = parseFloat(match[1]);
118
+ var type = (match[2] || "ms").toLowerCase();
119
+ switch (type) {
120
+ case "years":
121
+ case "year":
122
+ case "yrs":
123
+ case "yr":
124
+ case "y":
125
+ return n * y;
126
+ case "weeks":
127
+ case "week":
128
+ case "w":
129
+ return n * w;
130
+ case "days":
131
+ case "day":
132
+ case "d":
133
+ return n * d;
134
+ case "hours":
135
+ case "hour":
136
+ case "hrs":
137
+ case "hr":
138
+ case "h":
139
+ return n * h;
140
+ case "minutes":
141
+ case "minute":
142
+ case "mins":
143
+ case "min":
144
+ case "m":
145
+ return n * m;
146
+ case "seconds":
147
+ case "second":
148
+ case "secs":
149
+ case "sec":
150
+ case "s":
151
+ return n * s;
152
+ case "milliseconds":
153
+ case "millisecond":
154
+ case "msecs":
155
+ case "msec":
156
+ case "ms":
157
+ return n;
158
+ default:
159
+ return void 0;
160
+ }
161
+ }
162
+ function fmtShort(ms) {
163
+ var msAbs = Math.abs(ms);
164
+ if (msAbs >= d) {
165
+ return Math.round(ms / d) + "d";
166
+ }
167
+ if (msAbs >= h) {
168
+ return Math.round(ms / h) + "h";
169
+ }
170
+ if (msAbs >= m) {
171
+ return Math.round(ms / m) + "m";
172
+ }
173
+ if (msAbs >= s) {
174
+ return Math.round(ms / s) + "s";
175
+ }
176
+ return ms + "ms";
177
+ }
178
+ function fmtLong(ms) {
179
+ var msAbs = Math.abs(ms);
180
+ if (msAbs >= d) {
181
+ return plural(ms, msAbs, d, "day");
182
+ }
183
+ if (msAbs >= h) {
184
+ return plural(ms, msAbs, h, "hour");
185
+ }
186
+ if (msAbs >= m) {
187
+ return plural(ms, msAbs, m, "minute");
188
+ }
189
+ if (msAbs >= s) {
190
+ return plural(ms, msAbs, s, "second");
191
+ }
192
+ return ms + " ms";
193
+ }
194
+ function plural(ms, msAbs, n, name) {
195
+ var isPlural = msAbs >= n * 1.5;
196
+ return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
197
+ }
198
+ }
199
+ });
200
+ var require_common = __commonJS({
201
+ "../../node_modules/.pnpm/debug@4.4.3_supports-color@10.2.2/node_modules/debug/src/common.js"(exports2, module2) {
202
+ function setup(env2) {
203
+ createDebug2.debug = createDebug2;
204
+ createDebug2.default = createDebug2;
205
+ createDebug2.coerce = coerce;
206
+ createDebug2.disable = disable;
207
+ createDebug2.enable = enable;
208
+ createDebug2.enabled = enabled;
209
+ createDebug2.humanize = require_ms();
210
+ createDebug2.destroy = destroy;
211
+ Object.keys(env2).forEach((key) => {
212
+ createDebug2[key] = env2[key];
213
+ });
214
+ createDebug2.names = [];
215
+ createDebug2.skips = [];
216
+ createDebug2.formatters = {};
217
+ function selectColor(namespace) {
218
+ let hash = 0;
219
+ for (let i = 0; i < namespace.length; i++) {
220
+ hash = (hash << 5) - hash + namespace.charCodeAt(i);
221
+ hash |= 0;
222
+ }
223
+ return createDebug2.colors[Math.abs(hash) % createDebug2.colors.length];
224
+ }
225
+ createDebug2.selectColor = selectColor;
226
+ function createDebug2(namespace) {
227
+ let prevTime;
228
+ let enableOverride = null;
229
+ let namespacesCache;
230
+ let enabledCache;
231
+ function debug(...args) {
232
+ if (!debug.enabled) {
233
+ return;
234
+ }
235
+ const self = debug;
236
+ const curr = Number(/* @__PURE__ */ new Date());
237
+ const ms = curr - (prevTime || curr);
238
+ self.diff = ms;
239
+ self.prev = prevTime;
240
+ self.curr = curr;
241
+ prevTime = curr;
242
+ args[0] = createDebug2.coerce(args[0]);
243
+ if (typeof args[0] !== "string") {
244
+ args.unshift("%O");
245
+ }
246
+ let index = 0;
247
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
248
+ if (match === "%%") {
249
+ return "%";
250
+ }
251
+ index++;
252
+ const formatter = createDebug2.formatters[format];
253
+ if (typeof formatter === "function") {
254
+ const val = args[index];
255
+ match = formatter.call(self, val);
256
+ args.splice(index, 1);
257
+ index--;
258
+ }
259
+ return match;
260
+ });
261
+ createDebug2.formatArgs.call(self, args);
262
+ const logFn = self.log || createDebug2.log;
263
+ logFn.apply(self, args);
264
+ }
265
+ debug.namespace = namespace;
266
+ debug.useColors = createDebug2.useColors();
267
+ debug.color = createDebug2.selectColor(namespace);
268
+ debug.extend = extend;
269
+ debug.destroy = createDebug2.destroy;
270
+ Object.defineProperty(debug, "enabled", {
271
+ enumerable: true,
272
+ configurable: false,
273
+ get: () => {
274
+ if (enableOverride !== null) {
275
+ return enableOverride;
276
+ }
277
+ if (namespacesCache !== createDebug2.namespaces) {
278
+ namespacesCache = createDebug2.namespaces;
279
+ enabledCache = createDebug2.enabled(namespace);
280
+ }
281
+ return enabledCache;
282
+ },
283
+ set: (v) => {
284
+ enableOverride = v;
285
+ }
286
+ });
287
+ if (typeof createDebug2.init === "function") {
288
+ createDebug2.init(debug);
289
+ }
290
+ return debug;
291
+ }
292
+ function extend(namespace, delimiter) {
293
+ const newDebug = createDebug2(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
294
+ newDebug.log = this.log;
295
+ return newDebug;
296
+ }
297
+ function enable(namespaces) {
298
+ createDebug2.save(namespaces);
299
+ createDebug2.namespaces = namespaces;
300
+ createDebug2.names = [];
301
+ createDebug2.skips = [];
302
+ const split = (typeof namespaces === "string" ? namespaces : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean);
303
+ for (const ns of split) {
304
+ if (ns[0] === "-") {
305
+ createDebug2.skips.push(ns.slice(1));
306
+ } else {
307
+ createDebug2.names.push(ns);
308
+ }
309
+ }
310
+ }
311
+ function matchesTemplate(search, template) {
312
+ let searchIndex = 0;
313
+ let templateIndex = 0;
314
+ let starIndex = -1;
315
+ let matchIndex = 0;
316
+ while (searchIndex < search.length) {
317
+ if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) {
318
+ if (template[templateIndex] === "*") {
319
+ starIndex = templateIndex;
320
+ matchIndex = searchIndex;
321
+ templateIndex++;
322
+ } else {
323
+ searchIndex++;
324
+ templateIndex++;
325
+ }
326
+ } else if (starIndex !== -1) {
327
+ templateIndex = starIndex + 1;
328
+ matchIndex++;
329
+ searchIndex = matchIndex;
330
+ } else {
331
+ return false;
332
+ }
333
+ }
334
+ while (templateIndex < template.length && template[templateIndex] === "*") {
335
+ templateIndex++;
336
+ }
337
+ return templateIndex === template.length;
338
+ }
339
+ function disable() {
340
+ const namespaces = [
341
+ ...createDebug2.names,
342
+ ...createDebug2.skips.map((namespace) => "-" + namespace)
343
+ ].join(",");
344
+ createDebug2.enable("");
345
+ return namespaces;
346
+ }
347
+ function enabled(name) {
348
+ for (const skip of createDebug2.skips) {
349
+ if (matchesTemplate(name, skip)) {
350
+ return false;
351
+ }
352
+ }
353
+ for (const ns of createDebug2.names) {
354
+ if (matchesTemplate(name, ns)) {
355
+ return true;
356
+ }
357
+ }
358
+ return false;
359
+ }
360
+ function coerce(val) {
361
+ if (val instanceof Error) {
362
+ return val.stack || val.message;
363
+ }
364
+ return val;
365
+ }
366
+ function destroy() {
367
+ console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
368
+ }
369
+ createDebug2.enable(createDebug2.load());
370
+ return createDebug2;
371
+ }
372
+ module2.exports = setup;
373
+ }
374
+ });
375
+ var require_browser = __commonJS({
376
+ "../../node_modules/.pnpm/debug@4.4.3_supports-color@10.2.2/node_modules/debug/src/browser.js"(exports2, module2) {
377
+ exports2.formatArgs = formatArgs;
378
+ exports2.save = save;
379
+ exports2.load = load;
380
+ exports2.useColors = useColors;
381
+ exports2.storage = localstorage();
382
+ exports2.destroy = /* @__PURE__ */ (() => {
383
+ let warned = false;
384
+ return () => {
385
+ if (!warned) {
386
+ warned = true;
387
+ console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
388
+ }
389
+ };
390
+ })();
391
+ exports2.colors = [
392
+ "#0000CC",
393
+ "#0000FF",
394
+ "#0033CC",
395
+ "#0033FF",
396
+ "#0066CC",
397
+ "#0066FF",
398
+ "#0099CC",
399
+ "#0099FF",
400
+ "#00CC00",
401
+ "#00CC33",
402
+ "#00CC66",
403
+ "#00CC99",
404
+ "#00CCCC",
405
+ "#00CCFF",
406
+ "#3300CC",
407
+ "#3300FF",
408
+ "#3333CC",
409
+ "#3333FF",
410
+ "#3366CC",
411
+ "#3366FF",
412
+ "#3399CC",
413
+ "#3399FF",
414
+ "#33CC00",
415
+ "#33CC33",
416
+ "#33CC66",
417
+ "#33CC99",
418
+ "#33CCCC",
419
+ "#33CCFF",
420
+ "#6600CC",
421
+ "#6600FF",
422
+ "#6633CC",
423
+ "#6633FF",
424
+ "#66CC00",
425
+ "#66CC33",
426
+ "#9900CC",
427
+ "#9900FF",
428
+ "#9933CC",
429
+ "#9933FF",
430
+ "#99CC00",
431
+ "#99CC33",
432
+ "#CC0000",
433
+ "#CC0033",
434
+ "#CC0066",
435
+ "#CC0099",
436
+ "#CC00CC",
437
+ "#CC00FF",
438
+ "#CC3300",
439
+ "#CC3333",
440
+ "#CC3366",
441
+ "#CC3399",
442
+ "#CC33CC",
443
+ "#CC33FF",
444
+ "#CC6600",
445
+ "#CC6633",
446
+ "#CC9900",
447
+ "#CC9933",
448
+ "#CCCC00",
449
+ "#CCCC33",
450
+ "#FF0000",
451
+ "#FF0033",
452
+ "#FF0066",
453
+ "#FF0099",
454
+ "#FF00CC",
455
+ "#FF00FF",
456
+ "#FF3300",
457
+ "#FF3333",
458
+ "#FF3366",
459
+ "#FF3399",
460
+ "#FF33CC",
461
+ "#FF33FF",
462
+ "#FF6600",
463
+ "#FF6633",
464
+ "#FF9900",
465
+ "#FF9933",
466
+ "#FFCC00",
467
+ "#FFCC33"
468
+ ];
469
+ function useColors() {
470
+ if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) {
471
+ return true;
472
+ }
473
+ if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
474
+ return false;
475
+ }
476
+ let m;
477
+ return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
478
+ typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
479
+ // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
480
+ 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
481
+ typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
482
+ }
483
+ function formatArgs(args) {
484
+ args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module2.exports.humanize(this.diff);
485
+ if (!this.useColors) {
486
+ return;
487
+ }
488
+ const c = "color: " + this.color;
489
+ args.splice(1, 0, c, "color: inherit");
490
+ let index = 0;
491
+ let lastC = 0;
492
+ args[0].replace(/%[a-zA-Z%]/g, (match) => {
493
+ if (match === "%%") {
494
+ return;
495
+ }
496
+ index++;
497
+ if (match === "%c") {
498
+ lastC = index;
499
+ }
500
+ });
501
+ args.splice(lastC, 0, c);
502
+ }
503
+ exports2.log = console.debug || console.log || (() => {
504
+ });
505
+ function save(namespaces) {
506
+ try {
507
+ if (namespaces) {
508
+ exports2.storage.setItem("debug", namespaces);
509
+ } else {
510
+ exports2.storage.removeItem("debug");
511
+ }
512
+ } catch (error) {
513
+ }
514
+ }
515
+ function load() {
516
+ let r;
517
+ try {
518
+ r = exports2.storage.getItem("debug") || exports2.storage.getItem("DEBUG");
519
+ } catch (error) {
520
+ }
521
+ if (!r && typeof process !== "undefined" && "env" in process) {
522
+ r = process.env.DEBUG;
523
+ }
524
+ return r;
525
+ }
526
+ function localstorage() {
527
+ try {
528
+ return localStorage;
529
+ } catch (error) {
530
+ }
531
+ }
532
+ module2.exports = require_common()(exports2);
533
+ var { formatters } = module2.exports;
534
+ formatters.j = function(v) {
535
+ try {
536
+ return JSON.stringify(v);
537
+ } catch (error) {
538
+ return "[UnexpectedJSONParseError]: " + error.message;
539
+ }
540
+ };
541
+ }
542
+ });
543
+ var supports_color_exports = {};
544
+ __export2(supports_color_exports, {
545
+ createSupportsColor: () => createSupportsColor,
546
+ default: () => supports_color_default
547
+ });
548
+ function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : import_node_process.default.argv) {
549
+ const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
550
+ const position = argv.indexOf(prefix + flag);
551
+ const terminatorPosition = argv.indexOf("--");
552
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
553
+ }
554
+ function envForceColor() {
555
+ if (!("FORCE_COLOR" in env)) {
556
+ return;
557
+ }
558
+ if (env.FORCE_COLOR === "true") {
559
+ return 1;
560
+ }
561
+ if (env.FORCE_COLOR === "false") {
562
+ return 0;
563
+ }
564
+ if (env.FORCE_COLOR.length === 0) {
565
+ return 1;
566
+ }
567
+ const level = Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
568
+ if (![0, 1, 2, 3].includes(level)) {
569
+ return;
570
+ }
571
+ return level;
572
+ }
573
+ function translateLevel(level) {
574
+ if (level === 0) {
575
+ return false;
576
+ }
577
+ return {
578
+ level,
579
+ hasBasic: true,
580
+ has256: level >= 2,
581
+ has16m: level >= 3
582
+ };
583
+ }
584
+ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
585
+ const noFlagForceColor = envForceColor();
586
+ if (noFlagForceColor !== void 0) {
587
+ flagForceColor = noFlagForceColor;
588
+ }
589
+ const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
590
+ if (forceColor === 0) {
591
+ return 0;
592
+ }
593
+ if (sniffFlags) {
594
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
595
+ return 3;
596
+ }
597
+ if (hasFlag("color=256")) {
598
+ return 2;
599
+ }
600
+ }
601
+ if ("TF_BUILD" in env && "AGENT_NAME" in env) {
602
+ return 1;
603
+ }
604
+ if (haveStream && !streamIsTTY && forceColor === void 0) {
605
+ return 0;
606
+ }
607
+ const min = forceColor || 0;
608
+ if (env.TERM === "dumb") {
609
+ return min;
610
+ }
611
+ if (import_node_process.default.platform === "win32") {
612
+ const osRelease = import_node_os.default.release().split(".");
613
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
614
+ return Number(osRelease[2]) >= 14931 ? 3 : 2;
615
+ }
616
+ return 1;
617
+ }
618
+ if ("CI" in env) {
619
+ if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => key in env)) {
620
+ return 3;
621
+ }
622
+ if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
623
+ return 1;
624
+ }
625
+ return min;
626
+ }
627
+ if ("TEAMCITY_VERSION" in env) {
628
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
629
+ }
630
+ if (env.COLORTERM === "truecolor") {
631
+ return 3;
632
+ }
633
+ if (env.TERM === "xterm-kitty") {
634
+ return 3;
635
+ }
636
+ if (env.TERM === "xterm-ghostty") {
637
+ return 3;
638
+ }
639
+ if (env.TERM === "wezterm") {
640
+ return 3;
641
+ }
642
+ if ("TERM_PROGRAM" in env) {
643
+ const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
644
+ switch (env.TERM_PROGRAM) {
645
+ case "iTerm.app": {
646
+ return version >= 3 ? 3 : 2;
647
+ }
648
+ case "Apple_Terminal": {
649
+ return 2;
650
+ }
651
+ }
652
+ }
653
+ if (/-256(color)?$/i.test(env.TERM)) {
654
+ return 2;
655
+ }
656
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
657
+ return 1;
658
+ }
659
+ if ("COLORTERM" in env) {
660
+ return 1;
661
+ }
662
+ return min;
663
+ }
664
+ function createSupportsColor(stream, options = {}) {
665
+ const level = _supportsColor(stream, {
666
+ streamIsTTY: stream && stream.isTTY,
667
+ ...options
668
+ });
669
+ return translateLevel(level);
670
+ }
671
+ var env;
672
+ var flagForceColor;
673
+ var supportsColor;
674
+ var supports_color_default;
675
+ var init_supports_color = __esm({
676
+ "../../node_modules/.pnpm/supports-color@10.2.2/node_modules/supports-color/index.js"() {
677
+ ({ env } = import_node_process.default);
678
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
679
+ flagForceColor = 0;
680
+ } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
681
+ flagForceColor = 1;
682
+ }
683
+ supportsColor = {
684
+ stdout: createSupportsColor({ isTTY: import_node_tty.default.isatty(1) }),
685
+ stderr: createSupportsColor({ isTTY: import_node_tty.default.isatty(2) })
686
+ };
687
+ supports_color_default = supportsColor;
688
+ }
689
+ });
690
+ var require_node = __commonJS({
691
+ "../../node_modules/.pnpm/debug@4.4.3_supports-color@10.2.2/node_modules/debug/src/node.js"(exports2, module2) {
692
+ var tty2 = __require("tty");
693
+ var util = __require("util");
694
+ exports2.init = init;
695
+ exports2.log = log;
696
+ exports2.formatArgs = formatArgs;
697
+ exports2.save = save;
698
+ exports2.load = load;
699
+ exports2.useColors = useColors;
700
+ exports2.destroy = util.deprecate(
701
+ () => {
702
+ },
703
+ "Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."
704
+ );
705
+ exports2.colors = [6, 2, 3, 4, 5, 1];
706
+ try {
707
+ const supportsColor2 = (init_supports_color(), __toCommonJS2(supports_color_exports));
708
+ if (supportsColor2 && (supportsColor2.stderr || supportsColor2).level >= 2) {
709
+ exports2.colors = [
710
+ 20,
711
+ 21,
712
+ 26,
713
+ 27,
714
+ 32,
715
+ 33,
716
+ 38,
717
+ 39,
718
+ 40,
719
+ 41,
720
+ 42,
721
+ 43,
722
+ 44,
723
+ 45,
724
+ 56,
725
+ 57,
726
+ 62,
727
+ 63,
728
+ 68,
729
+ 69,
730
+ 74,
731
+ 75,
732
+ 76,
733
+ 77,
734
+ 78,
735
+ 79,
736
+ 80,
737
+ 81,
738
+ 92,
739
+ 93,
740
+ 98,
741
+ 99,
742
+ 112,
743
+ 113,
744
+ 128,
745
+ 129,
746
+ 134,
747
+ 135,
748
+ 148,
749
+ 149,
750
+ 160,
751
+ 161,
752
+ 162,
753
+ 163,
754
+ 164,
755
+ 165,
756
+ 166,
757
+ 167,
758
+ 168,
759
+ 169,
760
+ 170,
761
+ 171,
762
+ 172,
763
+ 173,
764
+ 178,
765
+ 179,
766
+ 184,
767
+ 185,
768
+ 196,
769
+ 197,
770
+ 198,
771
+ 199,
772
+ 200,
773
+ 201,
774
+ 202,
775
+ 203,
776
+ 204,
777
+ 205,
778
+ 206,
779
+ 207,
780
+ 208,
781
+ 209,
782
+ 214,
783
+ 215,
784
+ 220,
785
+ 221
786
+ ];
787
+ }
788
+ } catch (error) {
789
+ }
790
+ exports2.inspectOpts = Object.keys(process.env).filter((key) => {
791
+ return /^debug_/i.test(key);
792
+ }).reduce((obj, key) => {
793
+ const prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, (_, k) => {
794
+ return k.toUpperCase();
795
+ });
796
+ let val = process.env[key];
797
+ if (/^(yes|on|true|enabled)$/i.test(val)) {
798
+ val = true;
799
+ } else if (/^(no|off|false|disabled)$/i.test(val)) {
800
+ val = false;
801
+ } else if (val === "null") {
802
+ val = null;
803
+ } else {
804
+ val = Number(val);
805
+ }
806
+ obj[prop] = val;
807
+ return obj;
808
+ }, {});
809
+ function useColors() {
810
+ return "colors" in exports2.inspectOpts ? Boolean(exports2.inspectOpts.colors) : tty2.isatty(process.stderr.fd);
811
+ }
812
+ function formatArgs(args) {
813
+ const { namespace: name, useColors: useColors2 } = this;
814
+ if (useColors2) {
815
+ const c = this.color;
816
+ const colorCode = "\x1B[3" + (c < 8 ? c : "8;5;" + c);
817
+ const prefix = ` ${colorCode};1m${name} \x1B[0m`;
818
+ args[0] = prefix + args[0].split("\n").join("\n" + prefix);
819
+ args.push(colorCode + "m+" + module2.exports.humanize(this.diff) + "\x1B[0m");
820
+ } else {
821
+ args[0] = getDate() + name + " " + args[0];
822
+ }
823
+ }
824
+ function getDate() {
825
+ if (exports2.inspectOpts.hideDate) {
826
+ return "";
827
+ }
828
+ return (/* @__PURE__ */ new Date()).toISOString() + " ";
829
+ }
830
+ function log(...args) {
831
+ return process.stderr.write(util.formatWithOptions(exports2.inspectOpts, ...args) + "\n");
832
+ }
833
+ function save(namespaces) {
834
+ if (namespaces) {
835
+ process.env.DEBUG = namespaces;
836
+ } else {
837
+ delete process.env.DEBUG;
838
+ }
839
+ }
840
+ function load() {
841
+ return process.env.DEBUG;
842
+ }
843
+ function init(debug) {
844
+ debug.inspectOpts = {};
845
+ const keys = Object.keys(exports2.inspectOpts);
846
+ for (let i = 0; i < keys.length; i++) {
847
+ debug.inspectOpts[keys[i]] = exports2.inspectOpts[keys[i]];
848
+ }
849
+ }
850
+ module2.exports = require_common()(exports2);
851
+ var { formatters } = module2.exports;
852
+ formatters.o = function(v) {
853
+ this.inspectOpts.colors = this.useColors;
854
+ return util.inspect(v, this.inspectOpts).split("\n").map((str) => str.trim()).join(" ");
855
+ };
856
+ formatters.O = function(v) {
857
+ this.inspectOpts.colors = this.useColors;
858
+ return util.inspect(v, this.inspectOpts);
859
+ };
860
+ }
861
+ });
862
+ var require_src = __commonJS({
863
+ "../../node_modules/.pnpm/debug@4.4.3_supports-color@10.2.2/node_modules/debug/src/index.js"(exports2, module2) {
864
+ if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) {
865
+ module2.exports = require_browser();
866
+ } else {
867
+ module2.exports = require_node();
868
+ }
869
+ }
870
+ });
871
+ var import_debug = __toESM2(require_src());
872
+ var logInfo = (0, import_debug.default)("info");
873
+ var logTask = (0, import_debug.default)("task");
874
+ var logError = (0, import_debug.default)("error");
875
+ var logDetail = (0, import_debug.default)("detail");
876
+ var logDebug = (0, import_debug.default)("debug");
877
+ var logWarning = (0, import_debug.default)("warning");
878
+ var logColor = (0, import_debug.default)("color");
879
+ logInfo.color = "19";
880
+ logTask.color = "25";
881
+ logError.color = "1";
882
+ logDetail.color = "199";
883
+ logWarning.color = "186";
884
+ logDebug.color = "211";
885
+ logColor.enabled = true;
886
+ function logNamespace(namespace) {
887
+ logInfo.namespace = `${namespace}:info`;
888
+ logTask.namespace = `${namespace}:task`;
889
+ logError.namespace = `${namespace}:error`;
890
+ logDetail.namespace = `${namespace}:detail`;
891
+ logWarning.namespace = `${namespace}:warning`;
892
+ logDebug.namespace = `${namespace}:debug`;
893
+ }
894
+ function setLogLevel(level) {
895
+ switch (level) {
896
+ case "info":
897
+ logInfo.enabled = true;
898
+ logTask.enabled = true;
899
+ logError.enabled = true;
900
+ logWarning.enabled = true;
901
+ logDetail.enabled = false;
902
+ logDebug.enabled = false;
903
+ break;
904
+ case "debug":
905
+ logInfo.enabled = true;
906
+ logTask.enabled = true;
907
+ logError.enabled = true;
908
+ logWarning.enabled = true;
909
+ logDetail.enabled = true;
910
+ logDebug.enabled = true;
911
+ break;
912
+ case "none":
913
+ logInfo.enabled = false;
914
+ logTask.enabled = false;
915
+ logError.enabled = false;
916
+ logWarning.enabled = false;
917
+ logDetail.enabled = false;
918
+ logDebug.enabled = false;
919
+ break;
920
+ }
921
+ }
922
+
923
+ // src/graphql/queries.ts
924
+ var AUTHORIZE_QUERY = `
925
+ query Authorize($input: AuthorizeInput!) {
926
+ authorize(input: $input) {
927
+ status
928
+ authorization_code
929
+ }
930
+ }
931
+ `;
932
+ var TOKEN_QUERY = `
933
+ query Token($input: TokenInput!) {
934
+ token(input: $input) {
935
+ status
936
+ access_token
937
+ expires_in
938
+ }
939
+ }
940
+ `;
941
+
942
+ // src/logic/authClient.ts
943
+ setLogLevel(process.env.LOG_LEVEL ?? "none");
944
+ logNamespace("auth");
945
+ var random = (0, import_node_util.promisify)(import_node_crypto.randomBytes);
946
+ async function getAuthToken(credentials, apiUrl) {
947
+ const authApiUrl = apiUrl || process.env.AUTH_API_URL;
948
+ if (!authApiUrl) {
949
+ throw new Error("AUTH_API_URL is required. Set it in your env or pass apiUrl.");
950
+ }
951
+ const { clientDecorator, variantConfigurationKey } = credentials;
952
+ const frameworkId = credentials.frameworkId || `apple-kit-${Date.now()}`;
953
+ logInfo(`Getting auth token for identifiers: ${variantConfigurationKey}`);
954
+ const randomSecret = (await random(8)).toString("hex");
955
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
956
+ const hash = (0, import_node_crypto.createHash)("sha256");
957
+ hash.update(
958
+ `${variantConfigurationKey}${frameworkId}${timestamp}${clientDecorator}${randomSecret}`
959
+ );
960
+ const codeChallenge = hash.digest("hex");
961
+ const authorizeResponse = await fetch(authApiUrl, {
962
+ method: "POST",
963
+ headers: {
964
+ "Content-Type": "application/json"
965
+ },
966
+ body: JSON.stringify({
967
+ query: AUTHORIZE_QUERY,
968
+ variables: {
969
+ input: {
970
+ identifiers: variantConfigurationKey,
971
+ framework_id: frameworkId,
972
+ timestamp,
973
+ code_challenge: codeChallenge
974
+ }
975
+ }
976
+ })
977
+ });
978
+ if (!authorizeResponse.ok) {
979
+ throw new Error(
980
+ `Authorize request failed: ${authorizeResponse.status} ${authorizeResponse.statusText}`
981
+ );
982
+ }
983
+ const authorizeData = await authorizeResponse.json();
984
+ if (authorizeData.errors?.length) {
985
+ throw new Error(`Authorize error: ${authorizeData.errors.map((e) => e.message).join(", ")}`);
986
+ }
987
+ const authorizeResult = authorizeData.data?.authorize;
988
+ if (authorizeResult?.status !== "OK" || !authorizeResult.authorization_code) {
989
+ throw new Error(`Authorize failed: ${JSON.stringify(authorizeResult)}`);
990
+ }
991
+ const tokenResponse = await fetch(authApiUrl, {
992
+ method: "POST",
993
+ headers: {
994
+ "Content-Type": "application/json"
995
+ },
996
+ body: JSON.stringify({
997
+ query: TOKEN_QUERY,
998
+ variables: {
999
+ input: {
1000
+ authorization_code: authorizeResult.authorization_code,
1001
+ code_verifier: randomSecret
1002
+ }
1003
+ }
1004
+ })
1005
+ });
1006
+ if (!tokenResponse.ok) {
1007
+ throw new Error(`Token request failed: ${tokenResponse.status} ${tokenResponse.statusText}`);
1008
+ }
1009
+ const tokenData = await tokenResponse.json();
1010
+ if (tokenData.errors?.length) {
1011
+ throw new Error(`Token error: ${tokenData.errors.map((e) => e.message).join(", ")}`);
1012
+ }
1013
+ const tokenResult = tokenData.data?.token;
1014
+ if (tokenResult?.status !== "OK" || !tokenResult.access_token) {
1015
+ throw new Error(`Token failed: ${JSON.stringify(tokenResult)}`);
1016
+ }
1017
+ return {
1018
+ accessToken: tokenResult.access_token,
1019
+ expiresIn: tokenResult.expires_in ?? 3600
1020
+ };
1021
+ }
1022
+ async function readCredentialsFromFile(filePath) {
1023
+ const fs = await import("node:fs/promises");
1024
+ logInfo(`Reading credentials from: ${filePath}`);
1025
+ const content = await fs.readFile(filePath, "utf-8");
1026
+ const credentials = JSON.parse(content);
1027
+ if (!credentials.clientDecorator || !credentials.variantConfigurationKey) {
1028
+ throw new Error("Invalid credentials file: missing clientDecorator or variantConfigurationKey");
1029
+ }
1030
+ return credentials;
1031
+ }
1032
+ // Annotate the CommonJS export names for ESM import in node:
1033
+ 0 && (module.exports = {
1034
+ getAuthToken,
1035
+ readCredentialsFromFile
1036
+ });
1037
+ //# sourceMappingURL=index.js.map