oauth-callback 2.0.0 → 2.1.1

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/mcp.js CHANGED
@@ -15,8 +15,660 @@ var __toESM = (mod, isNodeMode, target) => {
15
15
  });
16
16
  return to;
17
17
  };
18
+ var __export = (target, all) => {
19
+ for (var name in all)
20
+ __defProp(target, name, {
21
+ get: all[name],
22
+ enumerable: true,
23
+ configurable: true,
24
+ set: (newValue) => all[name] = () => newValue
25
+ });
26
+ };
27
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
18
28
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
19
29
 
30
+ // node_modules/is-docker/index.js
31
+ import fs2 from "node:fs";
32
+ function hasDockerEnv() {
33
+ try {
34
+ fs2.statSync("/.dockerenv");
35
+ return true;
36
+ } catch {
37
+ return false;
38
+ }
39
+ }
40
+ function hasDockerCGroup() {
41
+ try {
42
+ return fs2.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
43
+ } catch {
44
+ return false;
45
+ }
46
+ }
47
+ function isDocker() {
48
+ if (isDockerCached === undefined) {
49
+ isDockerCached = hasDockerEnv() || hasDockerCGroup();
50
+ }
51
+ return isDockerCached;
52
+ }
53
+ var isDockerCached;
54
+ var init_is_docker = () => {};
55
+
56
+ // node_modules/is-inside-container/index.js
57
+ import fs3 from "node:fs";
58
+ function isInsideContainer() {
59
+ if (cachedResult === undefined) {
60
+ cachedResult = hasContainerEnv() || isDocker();
61
+ }
62
+ return cachedResult;
63
+ }
64
+ var cachedResult, hasContainerEnv = () => {
65
+ try {
66
+ fs3.statSync("/run/.containerenv");
67
+ return true;
68
+ } catch {
69
+ return false;
70
+ }
71
+ };
72
+ var init_is_inside_container = __esm(() => {
73
+ init_is_docker();
74
+ });
75
+
76
+ // node_modules/is-wsl/index.js
77
+ import process from "node:process";
78
+ import os2 from "node:os";
79
+ import fs4 from "node:fs";
80
+ var isWsl = () => {
81
+ if (process.platform !== "linux") {
82
+ return false;
83
+ }
84
+ if (os2.release().toLowerCase().includes("microsoft")) {
85
+ if (isInsideContainer()) {
86
+ return false;
87
+ }
88
+ return true;
89
+ }
90
+ try {
91
+ return fs4.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft") ? !isInsideContainer() : false;
92
+ } catch {
93
+ return false;
94
+ }
95
+ }, is_wsl_default;
96
+ var init_is_wsl = __esm(() => {
97
+ init_is_inside_container();
98
+ is_wsl_default = process.env.__IS_WSL_TEST__ ? isWsl : isWsl();
99
+ });
100
+
101
+ // node_modules/powershell-utils/index.js
102
+ import process2 from "node:process";
103
+ import { Buffer } from "node:buffer";
104
+ import { promisify } from "node:util";
105
+ import childProcess from "node:child_process";
106
+ var execFile, powerShellPath = () => `${process2.env.SYSTEMROOT || process2.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`, executePowerShell = async (command, options = {}) => {
107
+ const {
108
+ powerShellPath: psPath,
109
+ ...execFileOptions
110
+ } = options;
111
+ const encodedCommand = executePowerShell.encodeCommand(command);
112
+ return execFile(psPath ?? powerShellPath(), [
113
+ ...executePowerShell.argumentsPrefix,
114
+ encodedCommand
115
+ ], {
116
+ encoding: "utf8",
117
+ ...execFileOptions
118
+ });
119
+ };
120
+ var init_powershell_utils = __esm(() => {
121
+ execFile = promisify(childProcess.execFile);
122
+ executePowerShell.argumentsPrefix = [
123
+ "-NoProfile",
124
+ "-NonInteractive",
125
+ "-ExecutionPolicy",
126
+ "Bypass",
127
+ "-EncodedCommand"
128
+ ];
129
+ executePowerShell.encodeCommand = (command) => Buffer.from(command, "utf16le").toString("base64");
130
+ executePowerShell.escapeArgument = (value) => `'${String(value).replaceAll("'", "''")}'`;
131
+ });
132
+
133
+ // node_modules/wsl-utils/utilities.js
134
+ function parseMountPointFromConfig(content) {
135
+ for (const line of content.split(`
136
+ `)) {
137
+ if (/^\s*#/.test(line)) {
138
+ continue;
139
+ }
140
+ const match = /^\s*root\s*=\s*(?<mountPoint>"[^"]*"|'[^']*'|[^#]*)/.exec(line);
141
+ if (!match) {
142
+ continue;
143
+ }
144
+ return match.groups.mountPoint.trim().replaceAll(/^["']|["']$/g, "");
145
+ }
146
+ }
147
+
148
+ // node_modules/wsl-utils/index.js
149
+ import { promisify as promisify2 } from "node:util";
150
+ import childProcess2 from "node:child_process";
151
+ import fs5, { constants as fsConstants } from "node:fs/promises";
152
+ var execFile2, wslDrivesMountPoint, powerShellPathFromWsl = async () => {
153
+ const mountPoint = await wslDrivesMountPoint();
154
+ return `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`;
155
+ }, powerShellPath2, canAccessPowerShellPromise, canAccessPowerShell = async () => {
156
+ canAccessPowerShellPromise ??= (async () => {
157
+ try {
158
+ const psPath = await powerShellPath2();
159
+ await fs5.access(psPath, fsConstants.X_OK);
160
+ return true;
161
+ } catch {
162
+ return false;
163
+ }
164
+ })();
165
+ return canAccessPowerShellPromise;
166
+ }, wslDefaultBrowser = async () => {
167
+ const psPath = await powerShellPath2();
168
+ const command = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`;
169
+ const { stdout } = await executePowerShell(command, { powerShellPath: psPath });
170
+ return stdout.trim();
171
+ }, convertWslPathToWindows = async (path2) => {
172
+ if (/^[a-z]+:\/\//i.test(path2)) {
173
+ return path2;
174
+ }
175
+ try {
176
+ const { stdout } = await execFile2("wslpath", ["-aw", path2], { encoding: "utf8" });
177
+ return stdout.trim();
178
+ } catch {
179
+ return path2;
180
+ }
181
+ };
182
+ var init_wsl_utils = __esm(() => {
183
+ init_is_wsl();
184
+ init_powershell_utils();
185
+ init_is_wsl();
186
+ execFile2 = promisify2(childProcess2.execFile);
187
+ wslDrivesMountPoint = (() => {
188
+ const defaultMountPoint = "/mnt/";
189
+ let mountPoint;
190
+ return async function() {
191
+ if (mountPoint) {
192
+ return mountPoint;
193
+ }
194
+ const configFilePath = "/etc/wsl.conf";
195
+ let isConfigFileExists = false;
196
+ try {
197
+ await fs5.access(configFilePath, fsConstants.F_OK);
198
+ isConfigFileExists = true;
199
+ } catch {}
200
+ if (!isConfigFileExists) {
201
+ return defaultMountPoint;
202
+ }
203
+ const configContent = await fs5.readFile(configFilePath, { encoding: "utf8" });
204
+ const parsedMountPoint = parseMountPointFromConfig(configContent);
205
+ if (parsedMountPoint === undefined) {
206
+ return defaultMountPoint;
207
+ }
208
+ mountPoint = parsedMountPoint;
209
+ mountPoint = mountPoint.endsWith("/") ? mountPoint : `${mountPoint}/`;
210
+ return mountPoint;
211
+ };
212
+ })();
213
+ powerShellPath2 = is_wsl_default ? powerShellPathFromWsl : powerShellPath;
214
+ });
215
+
216
+ // node_modules/define-lazy-prop/index.js
217
+ function defineLazyProperty(object, propertyName, valueGetter) {
218
+ const define = (value) => Object.defineProperty(object, propertyName, { value, enumerable: true, writable: true });
219
+ Object.defineProperty(object, propertyName, {
220
+ configurable: true,
221
+ enumerable: true,
222
+ get() {
223
+ const result = valueGetter();
224
+ define(result);
225
+ return result;
226
+ },
227
+ set(value) {
228
+ define(value);
229
+ }
230
+ });
231
+ return object;
232
+ }
233
+
234
+ // node_modules/default-browser-id/index.js
235
+ import { promisify as promisify3 } from "node:util";
236
+ import process3 from "node:process";
237
+ import { execFile as execFile3 } from "node:child_process";
238
+ async function defaultBrowserId() {
239
+ if (process3.platform !== "darwin") {
240
+ throw new Error("macOS only");
241
+ }
242
+ const { stdout } = await execFileAsync("defaults", ["read", "com.apple.LaunchServices/com.apple.launchservices.secure", "LSHandlers"]);
243
+ const match = /LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(stdout);
244
+ return match?.groups.id ?? "com.apple.Safari";
245
+ }
246
+ var execFileAsync;
247
+ var init_default_browser_id = __esm(() => {
248
+ execFileAsync = promisify3(execFile3);
249
+ });
250
+
251
+ // node_modules/run-applescript/index.js
252
+ import process4 from "node:process";
253
+ import { promisify as promisify4 } from "node:util";
254
+ import { execFile as execFile4, execFileSync } from "node:child_process";
255
+ async function runAppleScript(script, { humanReadableOutput = true } = {}) {
256
+ if (process4.platform !== "darwin") {
257
+ throw new Error("macOS only");
258
+ }
259
+ const outputArguments = humanReadableOutput ? [] : ["-ss"];
260
+ const { stdout } = await execFileAsync2("osascript", ["-e", script, outputArguments]);
261
+ return stdout.trim();
262
+ }
263
+ var execFileAsync2;
264
+ var init_run_applescript = __esm(() => {
265
+ execFileAsync2 = promisify4(execFile4);
266
+ });
267
+
268
+ // node_modules/bundle-name/index.js
269
+ async function bundleName(bundleId) {
270
+ return runAppleScript(`tell application "Finder" to set app_path to application file id "${bundleId}" as string
271
+ tell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`);
272
+ }
273
+ var init_bundle_name = __esm(() => {
274
+ init_run_applescript();
275
+ });
276
+
277
+ // node_modules/default-browser/windows.js
278
+ import { promisify as promisify5 } from "node:util";
279
+ import { execFile as execFile5 } from "node:child_process";
280
+ async function defaultBrowser(_execFileAsync = execFileAsync3) {
281
+ const { stdout } = await _execFileAsync("reg", [
282
+ "QUERY",
283
+ " HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice",
284
+ "/v",
285
+ "ProgId"
286
+ ]);
287
+ const match = /ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(stdout);
288
+ if (!match) {
289
+ throw new UnknownBrowserError(`Cannot find Windows browser in stdout: ${JSON.stringify(stdout)}`);
290
+ }
291
+ const { id } = match.groups;
292
+ const browser = windowsBrowserProgIds[id];
293
+ if (!browser) {
294
+ throw new UnknownBrowserError(`Unknown browser ID: ${id}`);
295
+ }
296
+ return browser;
297
+ }
298
+ var execFileAsync3, windowsBrowserProgIds, _windowsBrowserProgIdMap, UnknownBrowserError;
299
+ var init_windows = __esm(() => {
300
+ execFileAsync3 = promisify5(execFile5);
301
+ windowsBrowserProgIds = {
302
+ MSEdgeHTM: { name: "Edge", id: "com.microsoft.edge" },
303
+ MSEdgeBHTML: { name: "Edge Beta", id: "com.microsoft.edge.beta" },
304
+ MSEdgeDHTML: { name: "Edge Dev", id: "com.microsoft.edge.dev" },
305
+ AppXq0fevzme2pys62n3e0fbqa7peapykr8v: { name: "Edge", id: "com.microsoft.edge.old" },
306
+ ChromeHTML: { name: "Chrome", id: "com.google.chrome" },
307
+ ChromeBHTML: { name: "Chrome Beta", id: "com.google.chrome.beta" },
308
+ ChromeDHTML: { name: "Chrome Dev", id: "com.google.chrome.dev" },
309
+ ChromiumHTM: { name: "Chromium", id: "org.chromium.Chromium" },
310
+ BraveHTML: { name: "Brave", id: "com.brave.Browser" },
311
+ BraveBHTML: { name: "Brave Beta", id: "com.brave.Browser.beta" },
312
+ BraveDHTML: { name: "Brave Dev", id: "com.brave.Browser.dev" },
313
+ BraveSSHTM: { name: "Brave Nightly", id: "com.brave.Browser.nightly" },
314
+ FirefoxURL: { name: "Firefox", id: "org.mozilla.firefox" },
315
+ OperaStable: { name: "Opera", id: "com.operasoftware.Opera" },
316
+ VivaldiHTM: { name: "Vivaldi", id: "com.vivaldi.Vivaldi" },
317
+ "IE.HTTP": { name: "Internet Explorer", id: "com.microsoft.ie" }
318
+ };
319
+ _windowsBrowserProgIdMap = new Map(Object.entries(windowsBrowserProgIds));
320
+ UnknownBrowserError = class UnknownBrowserError extends Error {
321
+ };
322
+ });
323
+
324
+ // node_modules/default-browser/index.js
325
+ import { promisify as promisify6 } from "node:util";
326
+ import process5 from "node:process";
327
+ import { execFile as execFile6 } from "node:child_process";
328
+ async function defaultBrowser2() {
329
+ if (process5.platform === "darwin") {
330
+ const id = await defaultBrowserId();
331
+ const name = await bundleName(id);
332
+ return { name, id };
333
+ }
334
+ if (process5.platform === "linux") {
335
+ const { stdout } = await execFileAsync4("xdg-mime", ["query", "default", "x-scheme-handler/http"]);
336
+ const id = stdout.trim();
337
+ const name = titleize(id.replace(/.desktop$/, "").replace("-", " "));
338
+ return { name, id };
339
+ }
340
+ if (process5.platform === "win32") {
341
+ return defaultBrowser();
342
+ }
343
+ throw new Error("Only macOS, Linux, and Windows are supported");
344
+ }
345
+ var execFileAsync4, titleize = (string) => string.toLowerCase().replaceAll(/(?:^|\s|-)\S/g, (x) => x.toUpperCase());
346
+ var init_default_browser = __esm(() => {
347
+ init_default_browser_id();
348
+ init_bundle_name();
349
+ init_windows();
350
+ init_windows();
351
+ execFileAsync4 = promisify6(execFile6);
352
+ });
353
+
354
+ // node_modules/is-in-ssh/index.js
355
+ import process6 from "node:process";
356
+ var isInSsh, is_in_ssh_default;
357
+ var init_is_in_ssh = __esm(() => {
358
+ isInSsh = Boolean(process6.env.SSH_CONNECTION || process6.env.SSH_CLIENT || process6.env.SSH_TTY);
359
+ is_in_ssh_default = isInSsh;
360
+ });
361
+
362
+ // node_modules/open/index.js
363
+ var exports_open = {};
364
+ __export(exports_open, {
365
+ openApp: () => openApp,
366
+ default: () => open_default,
367
+ apps: () => apps
368
+ });
369
+ import process7 from "node:process";
370
+ import path2 from "node:path";
371
+ import { fileURLToPath } from "node:url";
372
+ import childProcess3 from "node:child_process";
373
+ import fs6, { constants as fsConstants2 } from "node:fs/promises";
374
+ function detectArchBinary(binary) {
375
+ if (typeof binary === "string" || Array.isArray(binary)) {
376
+ return binary;
377
+ }
378
+ const { [arch]: archBinary } = binary;
379
+ if (!archBinary) {
380
+ throw new Error(`${arch} is not supported`);
381
+ }
382
+ return archBinary;
383
+ }
384
+ function detectPlatformBinary({ [platform]: platformBinary }, { wsl } = {}) {
385
+ if (wsl && is_wsl_default) {
386
+ return detectArchBinary(wsl);
387
+ }
388
+ if (!platformBinary) {
389
+ throw new Error(`${platform} is not supported`);
390
+ }
391
+ return detectArchBinary(platformBinary);
392
+ }
393
+ var fallbackAttemptSymbol, __dirname2, localXdgOpenPath, platform, arch, tryEachApp = async (apps, opener) => {
394
+ if (apps.length === 0) {
395
+ return;
396
+ }
397
+ const errors = [];
398
+ for (const app of apps) {
399
+ try {
400
+ return await opener(app);
401
+ } catch (error) {
402
+ errors.push(error);
403
+ }
404
+ }
405
+ throw new AggregateError(errors, "Failed to open in all supported apps");
406
+ }, baseOpen = async (options) => {
407
+ options = {
408
+ wait: false,
409
+ background: false,
410
+ newInstance: false,
411
+ allowNonzeroExitCode: false,
412
+ ...options
413
+ };
414
+ const isFallbackAttempt = options[fallbackAttemptSymbol] === true;
415
+ delete options[fallbackAttemptSymbol];
416
+ if (Array.isArray(options.app)) {
417
+ return tryEachApp(options.app, (singleApp) => baseOpen({
418
+ ...options,
419
+ app: singleApp,
420
+ [fallbackAttemptSymbol]: true
421
+ }));
422
+ }
423
+ let { name: app, arguments: appArguments = [] } = options.app ?? {};
424
+ appArguments = [...appArguments];
425
+ if (Array.isArray(app)) {
426
+ return tryEachApp(app, (appName) => baseOpen({
427
+ ...options,
428
+ app: {
429
+ name: appName,
430
+ arguments: appArguments
431
+ },
432
+ [fallbackAttemptSymbol]: true
433
+ }));
434
+ }
435
+ if (app === "browser" || app === "browserPrivate") {
436
+ const ids = {
437
+ "com.google.chrome": "chrome",
438
+ "google-chrome.desktop": "chrome",
439
+ "com.brave.browser": "brave",
440
+ "org.mozilla.firefox": "firefox",
441
+ "firefox.desktop": "firefox",
442
+ "com.microsoft.msedge": "edge",
443
+ "com.microsoft.edge": "edge",
444
+ "com.microsoft.edgemac": "edge",
445
+ "microsoft-edge.desktop": "edge",
446
+ "com.apple.safari": "safari"
447
+ };
448
+ const flags = {
449
+ chrome: "--incognito",
450
+ brave: "--incognito",
451
+ firefox: "--private-window",
452
+ edge: "--inPrivate"
453
+ };
454
+ let browser;
455
+ if (is_wsl_default) {
456
+ const progId = await wslDefaultBrowser();
457
+ const browserInfo = _windowsBrowserProgIdMap.get(progId);
458
+ browser = browserInfo ?? {};
459
+ } else {
460
+ browser = await defaultBrowser2();
461
+ }
462
+ if (browser.id in ids) {
463
+ const browserName = ids[browser.id.toLowerCase()];
464
+ if (app === "browserPrivate") {
465
+ if (browserName === "safari") {
466
+ throw new Error("Safari doesn't support opening in private mode via command line");
467
+ }
468
+ appArguments.push(flags[browserName]);
469
+ }
470
+ return baseOpen({
471
+ ...options,
472
+ app: {
473
+ name: apps[browserName],
474
+ arguments: appArguments
475
+ }
476
+ });
477
+ }
478
+ throw new Error(`${browser.name} is not supported as a default browser`);
479
+ }
480
+ let command;
481
+ const cliArguments = [];
482
+ const childProcessOptions = {};
483
+ let shouldUseWindowsInWsl = false;
484
+ if (is_wsl_default && !isInsideContainer() && !is_in_ssh_default && !app) {
485
+ shouldUseWindowsInWsl = await canAccessPowerShell();
486
+ }
487
+ if (platform === "darwin") {
488
+ command = "open";
489
+ if (options.wait) {
490
+ cliArguments.push("--wait-apps");
491
+ }
492
+ if (options.background) {
493
+ cliArguments.push("--background");
494
+ }
495
+ if (options.newInstance) {
496
+ cliArguments.push("--new");
497
+ }
498
+ if (app) {
499
+ cliArguments.push("-a", app);
500
+ }
501
+ } else if (platform === "win32" || shouldUseWindowsInWsl) {
502
+ command = await powerShellPath2();
503
+ cliArguments.push(...executePowerShell.argumentsPrefix);
504
+ if (!is_wsl_default) {
505
+ childProcessOptions.windowsVerbatimArguments = true;
506
+ }
507
+ if (is_wsl_default && options.target) {
508
+ options.target = await convertWslPathToWindows(options.target);
509
+ }
510
+ const encodedArguments = ["$ProgressPreference = 'SilentlyContinue';", "Start"];
511
+ if (options.wait) {
512
+ encodedArguments.push("-Wait");
513
+ }
514
+ if (app) {
515
+ encodedArguments.push(executePowerShell.escapeArgument(app));
516
+ if (options.target) {
517
+ appArguments.push(options.target);
518
+ }
519
+ } else if (options.target) {
520
+ encodedArguments.push(executePowerShell.escapeArgument(options.target));
521
+ }
522
+ if (appArguments.length > 0) {
523
+ appArguments = appArguments.map((argument) => executePowerShell.escapeArgument(argument));
524
+ encodedArguments.push("-ArgumentList", appArguments.join(","));
525
+ }
526
+ options.target = executePowerShell.encodeCommand(encodedArguments.join(" "));
527
+ if (!options.wait) {
528
+ childProcessOptions.stdio = "ignore";
529
+ }
530
+ } else {
531
+ if (app) {
532
+ command = app;
533
+ } else {
534
+ const isBundled = !__dirname2 || __dirname2 === "/";
535
+ let exeLocalXdgOpen = false;
536
+ try {
537
+ await fs6.access(localXdgOpenPath, fsConstants2.X_OK);
538
+ exeLocalXdgOpen = true;
539
+ } catch {}
540
+ const useSystemXdgOpen = process7.versions.electron ?? (platform === "android" || isBundled || !exeLocalXdgOpen);
541
+ command = useSystemXdgOpen ? "xdg-open" : localXdgOpenPath;
542
+ }
543
+ if (appArguments.length > 0) {
544
+ cliArguments.push(...appArguments);
545
+ }
546
+ if (!options.wait) {
547
+ childProcessOptions.stdio = "ignore";
548
+ childProcessOptions.detached = true;
549
+ }
550
+ }
551
+ if (platform === "darwin" && appArguments.length > 0) {
552
+ cliArguments.push("--args", ...appArguments);
553
+ }
554
+ if (options.target) {
555
+ cliArguments.push(options.target);
556
+ }
557
+ const subprocess = childProcess3.spawn(command, cliArguments, childProcessOptions);
558
+ if (options.wait) {
559
+ return new Promise((resolve, reject) => {
560
+ subprocess.once("error", reject);
561
+ subprocess.once("close", (exitCode) => {
562
+ if (!options.allowNonzeroExitCode && exitCode !== 0) {
563
+ reject(new Error(`Exited with code ${exitCode}`));
564
+ return;
565
+ }
566
+ resolve(subprocess);
567
+ });
568
+ });
569
+ }
570
+ if (isFallbackAttempt) {
571
+ return new Promise((resolve, reject) => {
572
+ subprocess.once("error", reject);
573
+ subprocess.once("spawn", () => {
574
+ subprocess.once("close", (exitCode) => {
575
+ subprocess.off("error", reject);
576
+ if (exitCode !== 0) {
577
+ reject(new Error(`Exited with code ${exitCode}`));
578
+ return;
579
+ }
580
+ subprocess.unref();
581
+ resolve(subprocess);
582
+ });
583
+ });
584
+ });
585
+ }
586
+ subprocess.unref();
587
+ return new Promise((resolve, reject) => {
588
+ subprocess.once("error", reject);
589
+ subprocess.once("spawn", () => {
590
+ subprocess.off("error", reject);
591
+ resolve(subprocess);
592
+ });
593
+ });
594
+ }, open = (target, options) => {
595
+ if (typeof target !== "string") {
596
+ throw new TypeError("Expected a `target`");
597
+ }
598
+ return baseOpen({
599
+ ...options,
600
+ target
601
+ });
602
+ }, openApp = (name, options) => {
603
+ if (typeof name !== "string" && !Array.isArray(name)) {
604
+ throw new TypeError("Expected a valid `name`");
605
+ }
606
+ const { arguments: appArguments = [] } = options ?? {};
607
+ if (appArguments !== undefined && appArguments !== null && !Array.isArray(appArguments)) {
608
+ throw new TypeError("Expected `appArguments` as Array type");
609
+ }
610
+ return baseOpen({
611
+ ...options,
612
+ app: {
613
+ name,
614
+ arguments: appArguments
615
+ }
616
+ });
617
+ }, apps, open_default;
618
+ var init_open = __esm(() => {
619
+ init_wsl_utils();
620
+ init_powershell_utils();
621
+ init_default_browser();
622
+ init_is_inside_container();
623
+ init_is_in_ssh();
624
+ fallbackAttemptSymbol = Symbol("fallbackAttempt");
625
+ __dirname2 = import.meta.url ? path2.dirname(fileURLToPath(import.meta.url)) : "";
626
+ localXdgOpenPath = path2.join(__dirname2, "xdg-open");
627
+ ({ platform, arch } = process7);
628
+ apps = {
629
+ browser: "browser",
630
+ browserPrivate: "browserPrivate"
631
+ };
632
+ defineLazyProperty(apps, "chrome", () => detectPlatformBinary({
633
+ darwin: "google chrome",
634
+ win32: "chrome",
635
+ linux: ["google-chrome", "google-chrome-stable", "chromium", "chromium-browser"]
636
+ }, {
637
+ wsl: {
638
+ ia32: "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe",
639
+ x64: ["/mnt/c/Program Files/Google/Chrome/Application/chrome.exe", "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"]
640
+ }
641
+ }));
642
+ defineLazyProperty(apps, "brave", () => detectPlatformBinary({
643
+ darwin: "brave browser",
644
+ win32: "brave",
645
+ linux: ["brave-browser", "brave"]
646
+ }, {
647
+ wsl: {
648
+ ia32: "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe",
649
+ x64: ["/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe", "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe"]
650
+ }
651
+ }));
652
+ defineLazyProperty(apps, "firefox", () => detectPlatformBinary({
653
+ darwin: "firefox",
654
+ win32: String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`,
655
+ linux: "firefox"
656
+ }, {
657
+ wsl: "/mnt/c/Program Files/Mozilla Firefox/firefox.exe"
658
+ }));
659
+ defineLazyProperty(apps, "edge", () => detectPlatformBinary({
660
+ darwin: "microsoft edge",
661
+ win32: "msedge",
662
+ linux: ["microsoft-edge", "microsoft-edge-dev"]
663
+ }, {
664
+ wsl: "/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
665
+ }));
666
+ defineLazyProperty(apps, "safari", () => detectPlatformBinary({
667
+ darwin: "Safari"
668
+ }));
669
+ open_default = open;
670
+ });
671
+
20
672
  // src/auth/browser-auth.ts
21
673
  import { randomBytes } from "node:crypto";
22
674
 
@@ -354,19 +1006,24 @@ function fileStore(filepath) {
354
1006
  }
355
1007
 
356
1008
  // src/index.ts
1009
+ var DEFAULT_PORT = 3000;
1010
+ var DEFAULT_HOSTNAME = "localhost";
1011
+ var DEFAULT_CALLBACK_PATH = "/callback";
1012
+ async function authorizationUrlToOptions(input) {
1013
+ const open2 = await Promise.resolve().then(() => (init_open(), exports_open));
1014
+ return { authorizationUrl: input, launch: open2.default };
1015
+ }
357
1016
  async function getAuthCode(input) {
358
- const options = typeof input === "string" ? { authorizationUrl: input } : input;
1017
+ const options = typeof input === "string" ? await authorizationUrlToOptions(input) : input;
359
1018
  const {
360
- authorizationUrl,
361
- port = 3000,
362
- hostname = "localhost",
1019
+ port = DEFAULT_PORT,
1020
+ hostname = DEFAULT_HOSTNAME,
363
1021
  timeout = 30000,
364
- callbackPath = "/callback",
1022
+ callbackPath = DEFAULT_CALLBACK_PATH,
365
1023
  successHtml,
366
1024
  errorHtml,
367
1025
  signal,
368
- onRequest,
369
- launch
1026
+ onRequest
370
1027
  } = options;
371
1028
  const server = createCallbackServer();
372
1029
  try {
@@ -378,8 +1035,9 @@ async function getAuthCode(input) {
378
1035
  signal,
379
1036
  onRequest
380
1037
  });
381
- if (launch)
382
- Promise.resolve(launch(authorizationUrl)).catch(() => {});
1038
+ if ("authorizationUrl" in options && options.authorizationUrl && "launch" in options && typeof options.launch === "function") {
1039
+ Promise.resolve(options.launch(options.authorizationUrl)).catch(() => {});
1040
+ }
383
1041
  const result = await server.waitForCallback(callbackPath, timeout);
384
1042
  if (result.error) {
385
1043
  throw new OAuthError(result.error, result.error_description, result.error_uri);
@@ -557,17 +1215,20 @@ class BrowserOAuthProvider {
557
1215
  }
558
1216
  }
559
1217
  async _doAuthorization(authorizationUrl) {
560
- const result = await getAuthCode({
561
- authorizationUrl: authorizationUrl.href,
1218
+ const baseOptions = {
562
1219
  port: this._port,
563
1220
  hostname: this._hostname,
564
1221
  callbackPath: this._callbackPath,
565
1222
  timeout: this._authTimeout,
566
- launch: this._launch,
567
1223
  successHtml: this._successHtml,
568
1224
  errorHtml: this._errorHtml,
569
1225
  onRequest: this._onRequest
570
- });
1226
+ };
1227
+ const result = await getAuthCode(this._launch ? {
1228
+ ...baseOptions,
1229
+ authorizationUrl: authorizationUrl.href,
1230
+ launch: this._launch
1231
+ } : baseOptions);
571
1232
  this._pendingAuthCode = result.code;
572
1233
  this._pendingAuthState = result.state;
573
1234
  setTimeout(() => {