@stackable-labs/mcp-app-extension 0.23.0 → 1.0.0
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 +1406 -78
- package/dist/server.js +735 -71
- package/package.json +1 -1
- package/dist/auth-DWIWIJNN.js +0 -629
- package/dist/auth-WHLYYSCQ.js +0 -630
- package/dist/chunk-DCPV7HMV.js +0 -108
- package/dist/chunk-HOOVB46Z.js +0 -107
package/dist/auth-WHLYYSCQ.js
DELETED
|
@@ -1,630 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { deriveClientId, STANDALONE_CLIENT, getNonce, writeAuthState, STANDALONE_CLIENT_AUTH_FILE, getVerifier, getDigest } from './chunk-DCPV7HMV.js';
|
|
3
|
-
import { createServer } from 'http';
|
|
4
|
-
import process5 from 'process';
|
|
5
|
-
import { Buffer as Buffer$1 } from 'buffer';
|
|
6
|
-
import path from 'path';
|
|
7
|
-
import { fileURLToPath } from 'url';
|
|
8
|
-
import { promisify } from 'util';
|
|
9
|
-
import childProcess, { execFile } from 'child_process';
|
|
10
|
-
import fs4, { constants } from 'fs/promises';
|
|
11
|
-
import os from 'os';
|
|
12
|
-
import fs3 from 'fs';
|
|
13
|
-
|
|
14
|
-
var isDockerCached;
|
|
15
|
-
function hasDockerEnv() {
|
|
16
|
-
try {
|
|
17
|
-
fs3.statSync("/.dockerenv");
|
|
18
|
-
return true;
|
|
19
|
-
} catch {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function hasDockerCGroup() {
|
|
24
|
-
try {
|
|
25
|
-
return fs3.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
|
|
26
|
-
} catch {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function isDocker() {
|
|
31
|
-
if (isDockerCached === void 0) {
|
|
32
|
-
isDockerCached = hasDockerEnv() || hasDockerCGroup();
|
|
33
|
-
}
|
|
34
|
-
return isDockerCached;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// ../../../node_modules/.pnpm/is-inside-container@1.0.0/node_modules/is-inside-container/index.js
|
|
38
|
-
var cachedResult;
|
|
39
|
-
var hasContainerEnv = () => {
|
|
40
|
-
try {
|
|
41
|
-
fs3.statSync("/run/.containerenv");
|
|
42
|
-
return true;
|
|
43
|
-
} catch {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
function isInsideContainer() {
|
|
48
|
-
if (cachedResult === void 0) {
|
|
49
|
-
cachedResult = hasContainerEnv() || isDocker();
|
|
50
|
-
}
|
|
51
|
-
return cachedResult;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// ../../../node_modules/.pnpm/is-wsl@3.1.1/node_modules/is-wsl/index.js
|
|
55
|
-
var isWsl = () => {
|
|
56
|
-
if (process5.platform !== "linux") {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
if (os.release().toLowerCase().includes("microsoft")) {
|
|
60
|
-
if (isInsideContainer()) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
try {
|
|
66
|
-
if (fs3.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft")) {
|
|
67
|
-
return !isInsideContainer();
|
|
68
|
-
}
|
|
69
|
-
} catch {
|
|
70
|
-
}
|
|
71
|
-
if (fs3.existsSync("/proc/sys/fs/binfmt_misc/WSLInterop") || fs3.existsSync("/run/WSL")) {
|
|
72
|
-
return !isInsideContainer();
|
|
73
|
-
}
|
|
74
|
-
return false;
|
|
75
|
-
};
|
|
76
|
-
var is_wsl_default = process5.env.__IS_WSL_TEST__ ? isWsl : isWsl();
|
|
77
|
-
|
|
78
|
-
// ../../../node_modules/.pnpm/wsl-utils@0.1.0/node_modules/wsl-utils/index.js
|
|
79
|
-
var wslDrivesMountPoint = /* @__PURE__ */ (() => {
|
|
80
|
-
const defaultMountPoint = "/mnt/";
|
|
81
|
-
let mountPoint;
|
|
82
|
-
return async function() {
|
|
83
|
-
if (mountPoint) {
|
|
84
|
-
return mountPoint;
|
|
85
|
-
}
|
|
86
|
-
const configFilePath = "/etc/wsl.conf";
|
|
87
|
-
let isConfigFileExists = false;
|
|
88
|
-
try {
|
|
89
|
-
await fs4.access(configFilePath, constants.F_OK);
|
|
90
|
-
isConfigFileExists = true;
|
|
91
|
-
} catch {
|
|
92
|
-
}
|
|
93
|
-
if (!isConfigFileExists) {
|
|
94
|
-
return defaultMountPoint;
|
|
95
|
-
}
|
|
96
|
-
const configContent = await fs4.readFile(configFilePath, { encoding: "utf8" });
|
|
97
|
-
const configMountPoint = /(?<!#.*)root\s*=\s*(?<mountPoint>.*)/g.exec(configContent);
|
|
98
|
-
if (!configMountPoint) {
|
|
99
|
-
return defaultMountPoint;
|
|
100
|
-
}
|
|
101
|
-
mountPoint = configMountPoint.groups.mountPoint.trim();
|
|
102
|
-
mountPoint = mountPoint.endsWith("/") ? mountPoint : `${mountPoint}/`;
|
|
103
|
-
return mountPoint;
|
|
104
|
-
};
|
|
105
|
-
})();
|
|
106
|
-
var powerShellPathFromWsl = async () => {
|
|
107
|
-
const mountPoint = await wslDrivesMountPoint();
|
|
108
|
-
return `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`;
|
|
109
|
-
};
|
|
110
|
-
var powerShellPath = async () => {
|
|
111
|
-
if (is_wsl_default) {
|
|
112
|
-
return powerShellPathFromWsl();
|
|
113
|
-
}
|
|
114
|
-
return `${process5.env.SYSTEMROOT || process5.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
// ../../../node_modules/.pnpm/define-lazy-prop@3.0.0/node_modules/define-lazy-prop/index.js
|
|
118
|
-
function defineLazyProperty(object, propertyName, valueGetter) {
|
|
119
|
-
const define = (value) => Object.defineProperty(object, propertyName, { value, enumerable: true, writable: true });
|
|
120
|
-
Object.defineProperty(object, propertyName, {
|
|
121
|
-
configurable: true,
|
|
122
|
-
enumerable: true,
|
|
123
|
-
get() {
|
|
124
|
-
const result = valueGetter();
|
|
125
|
-
define(result);
|
|
126
|
-
return result;
|
|
127
|
-
},
|
|
128
|
-
set(value) {
|
|
129
|
-
define(value);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
return object;
|
|
133
|
-
}
|
|
134
|
-
var execFileAsync = promisify(execFile);
|
|
135
|
-
async function defaultBrowserId() {
|
|
136
|
-
if (process5.platform !== "darwin") {
|
|
137
|
-
throw new Error("macOS only");
|
|
138
|
-
}
|
|
139
|
-
const { stdout } = await execFileAsync("defaults", ["read", "com.apple.LaunchServices/com.apple.launchservices.secure", "LSHandlers"]);
|
|
140
|
-
const match = /LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(stdout);
|
|
141
|
-
const browserId = match?.groups.id ?? "com.apple.Safari";
|
|
142
|
-
if (browserId === "com.apple.safari") {
|
|
143
|
-
return "com.apple.Safari";
|
|
144
|
-
}
|
|
145
|
-
return browserId;
|
|
146
|
-
}
|
|
147
|
-
var execFileAsync2 = promisify(execFile);
|
|
148
|
-
async function runAppleScript(script, { humanReadableOutput = true, signal } = {}) {
|
|
149
|
-
if (process5.platform !== "darwin") {
|
|
150
|
-
throw new Error("macOS only");
|
|
151
|
-
}
|
|
152
|
-
const outputArguments = humanReadableOutput ? [] : ["-ss"];
|
|
153
|
-
const execOptions = {};
|
|
154
|
-
if (signal) {
|
|
155
|
-
execOptions.signal = signal;
|
|
156
|
-
}
|
|
157
|
-
const { stdout } = await execFileAsync2("osascript", ["-e", script, outputArguments], execOptions);
|
|
158
|
-
return stdout.trim();
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// ../../../node_modules/.pnpm/bundle-name@4.1.0/node_modules/bundle-name/index.js
|
|
162
|
-
async function bundleName(bundleId) {
|
|
163
|
-
return runAppleScript(`tell application "Finder" to set app_path to application file id "${bundleId}" as string
|
|
164
|
-
tell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`);
|
|
165
|
-
}
|
|
166
|
-
var execFileAsync3 = promisify(execFile);
|
|
167
|
-
var windowsBrowserProgIds = {
|
|
168
|
-
MSEdgeHTM: { name: "Edge", id: "com.microsoft.edge" },
|
|
169
|
-
// The missing `L` is correct.
|
|
170
|
-
MSEdgeBHTML: { name: "Edge Beta", id: "com.microsoft.edge.beta" },
|
|
171
|
-
MSEdgeDHTML: { name: "Edge Dev", id: "com.microsoft.edge.dev" },
|
|
172
|
-
AppXq0fevzme2pys62n3e0fbqa7peapykr8v: { name: "Edge", id: "com.microsoft.edge.old" },
|
|
173
|
-
ChromeHTML: { name: "Chrome", id: "com.google.chrome" },
|
|
174
|
-
ChromeBHTML: { name: "Chrome Beta", id: "com.google.chrome.beta" },
|
|
175
|
-
ChromeDHTML: { name: "Chrome Dev", id: "com.google.chrome.dev" },
|
|
176
|
-
ChromiumHTM: { name: "Chromium", id: "org.chromium.Chromium" },
|
|
177
|
-
BraveHTML: { name: "Brave", id: "com.brave.Browser" },
|
|
178
|
-
BraveBHTML: { name: "Brave Beta", id: "com.brave.Browser.beta" },
|
|
179
|
-
BraveDHTML: { name: "Brave Dev", id: "com.brave.Browser.dev" },
|
|
180
|
-
BraveSSHTM: { name: "Brave Nightly", id: "com.brave.Browser.nightly" },
|
|
181
|
-
FirefoxURL: { name: "Firefox", id: "org.mozilla.firefox" },
|
|
182
|
-
OperaStable: { name: "Opera", id: "com.operasoftware.Opera" },
|
|
183
|
-
VivaldiHTM: { name: "Vivaldi", id: "com.vivaldi.Vivaldi" },
|
|
184
|
-
"IE.HTTP": { name: "Internet Explorer", id: "com.microsoft.ie" }
|
|
185
|
-
};
|
|
186
|
-
new Map(Object.entries(windowsBrowserProgIds));
|
|
187
|
-
var UnknownBrowserError = class extends Error {
|
|
188
|
-
};
|
|
189
|
-
async function defaultBrowser(_execFileAsync = execFileAsync3) {
|
|
190
|
-
const { stdout } = await _execFileAsync("reg", [
|
|
191
|
-
"QUERY",
|
|
192
|
-
" HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice",
|
|
193
|
-
"/v",
|
|
194
|
-
"ProgId"
|
|
195
|
-
]);
|
|
196
|
-
const match = /ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(stdout);
|
|
197
|
-
if (!match) {
|
|
198
|
-
throw new UnknownBrowserError(`Cannot find Windows browser in stdout: ${JSON.stringify(stdout)}`);
|
|
199
|
-
}
|
|
200
|
-
const { id } = match.groups;
|
|
201
|
-
const dotIndex = id.lastIndexOf(".");
|
|
202
|
-
const hyphenIndex = id.lastIndexOf("-");
|
|
203
|
-
const baseIdByDot = dotIndex === -1 ? void 0 : id.slice(0, dotIndex);
|
|
204
|
-
const baseIdByHyphen = hyphenIndex === -1 ? void 0 : id.slice(0, hyphenIndex);
|
|
205
|
-
return windowsBrowserProgIds[id] ?? windowsBrowserProgIds[baseIdByDot] ?? windowsBrowserProgIds[baseIdByHyphen] ?? { name: id, id };
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// ../../../node_modules/.pnpm/default-browser@5.5.0/node_modules/default-browser/index.js
|
|
209
|
-
var execFileAsync4 = promisify(execFile);
|
|
210
|
-
var titleize = (string) => string.toLowerCase().replaceAll(/(?:^|\s|-)\S/g, (x) => x.toUpperCase());
|
|
211
|
-
async function defaultBrowser2() {
|
|
212
|
-
if (process5.platform === "darwin") {
|
|
213
|
-
const id = await defaultBrowserId();
|
|
214
|
-
const name = await bundleName(id);
|
|
215
|
-
return { name, id };
|
|
216
|
-
}
|
|
217
|
-
if (process5.platform === "linux") {
|
|
218
|
-
const { stdout } = await execFileAsync4("xdg-mime", ["query", "default", "x-scheme-handler/http"]);
|
|
219
|
-
const id = stdout.trim();
|
|
220
|
-
const name = titleize(id.replace(/.desktop$/, "").replace("-", " "));
|
|
221
|
-
return { name, id };
|
|
222
|
-
}
|
|
223
|
-
if (process5.platform === "win32") {
|
|
224
|
-
return defaultBrowser();
|
|
225
|
-
}
|
|
226
|
-
throw new Error("Only macOS, Linux, and Windows are supported");
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// ../../../node_modules/.pnpm/open@10.2.0/node_modules/open/index.js
|
|
230
|
-
var execFile5 = promisify(childProcess.execFile);
|
|
231
|
-
var __dirname$1 = path.dirname(fileURLToPath(import.meta.url));
|
|
232
|
-
var localXdgOpenPath = path.join(__dirname$1, "xdg-open");
|
|
233
|
-
var { platform, arch } = process5;
|
|
234
|
-
async function getWindowsDefaultBrowserFromWsl() {
|
|
235
|
-
const powershellPath = await powerShellPath();
|
|
236
|
-
const rawCommand = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`;
|
|
237
|
-
const encodedCommand = Buffer$1.from(rawCommand, "utf16le").toString("base64");
|
|
238
|
-
const { stdout } = await execFile5(
|
|
239
|
-
powershellPath,
|
|
240
|
-
[
|
|
241
|
-
"-NoProfile",
|
|
242
|
-
"-NonInteractive",
|
|
243
|
-
"-ExecutionPolicy",
|
|
244
|
-
"Bypass",
|
|
245
|
-
"-EncodedCommand",
|
|
246
|
-
encodedCommand
|
|
247
|
-
],
|
|
248
|
-
{ encoding: "utf8" }
|
|
249
|
-
);
|
|
250
|
-
const progId = stdout.trim();
|
|
251
|
-
const browserMap = {
|
|
252
|
-
ChromeHTML: "com.google.chrome",
|
|
253
|
-
BraveHTML: "com.brave.Browser",
|
|
254
|
-
MSEdgeHTM: "com.microsoft.edge",
|
|
255
|
-
FirefoxURL: "org.mozilla.firefox"
|
|
256
|
-
};
|
|
257
|
-
return browserMap[progId] ? { id: browserMap[progId] } : {};
|
|
258
|
-
}
|
|
259
|
-
var pTryEach = async (array, mapper) => {
|
|
260
|
-
let latestError;
|
|
261
|
-
for (const item of array) {
|
|
262
|
-
try {
|
|
263
|
-
return await mapper(item);
|
|
264
|
-
} catch (error) {
|
|
265
|
-
latestError = error;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
throw latestError;
|
|
269
|
-
};
|
|
270
|
-
var baseOpen = async (options) => {
|
|
271
|
-
options = {
|
|
272
|
-
wait: false,
|
|
273
|
-
background: false,
|
|
274
|
-
newInstance: false,
|
|
275
|
-
allowNonzeroExitCode: false,
|
|
276
|
-
...options
|
|
277
|
-
};
|
|
278
|
-
if (Array.isArray(options.app)) {
|
|
279
|
-
return pTryEach(options.app, (singleApp) => baseOpen({
|
|
280
|
-
...options,
|
|
281
|
-
app: singleApp
|
|
282
|
-
}));
|
|
283
|
-
}
|
|
284
|
-
let { name: app, arguments: appArguments = [] } = options.app ?? {};
|
|
285
|
-
appArguments = [...appArguments];
|
|
286
|
-
if (Array.isArray(app)) {
|
|
287
|
-
return pTryEach(app, (appName) => baseOpen({
|
|
288
|
-
...options,
|
|
289
|
-
app: {
|
|
290
|
-
name: appName,
|
|
291
|
-
arguments: appArguments
|
|
292
|
-
}
|
|
293
|
-
}));
|
|
294
|
-
}
|
|
295
|
-
if (app === "browser" || app === "browserPrivate") {
|
|
296
|
-
const ids = {
|
|
297
|
-
"com.google.chrome": "chrome",
|
|
298
|
-
"google-chrome.desktop": "chrome",
|
|
299
|
-
"com.brave.Browser": "brave",
|
|
300
|
-
"org.mozilla.firefox": "firefox",
|
|
301
|
-
"firefox.desktop": "firefox",
|
|
302
|
-
"com.microsoft.msedge": "edge",
|
|
303
|
-
"com.microsoft.edge": "edge",
|
|
304
|
-
"com.microsoft.edgemac": "edge",
|
|
305
|
-
"microsoft-edge.desktop": "edge"
|
|
306
|
-
};
|
|
307
|
-
const flags = {
|
|
308
|
-
chrome: "--incognito",
|
|
309
|
-
brave: "--incognito",
|
|
310
|
-
firefox: "--private-window",
|
|
311
|
-
edge: "--inPrivate"
|
|
312
|
-
};
|
|
313
|
-
const browser = is_wsl_default ? await getWindowsDefaultBrowserFromWsl() : await defaultBrowser2();
|
|
314
|
-
if (browser.id in ids) {
|
|
315
|
-
const browserName = ids[browser.id];
|
|
316
|
-
if (app === "browserPrivate") {
|
|
317
|
-
appArguments.push(flags[browserName]);
|
|
318
|
-
}
|
|
319
|
-
return baseOpen({
|
|
320
|
-
...options,
|
|
321
|
-
app: {
|
|
322
|
-
name: apps[browserName],
|
|
323
|
-
arguments: appArguments
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
throw new Error(`${browser.name} is not supported as a default browser`);
|
|
328
|
-
}
|
|
329
|
-
let command;
|
|
330
|
-
const cliArguments = [];
|
|
331
|
-
const childProcessOptions = {};
|
|
332
|
-
if (platform === "darwin") {
|
|
333
|
-
command = "open";
|
|
334
|
-
if (options.wait) {
|
|
335
|
-
cliArguments.push("--wait-apps");
|
|
336
|
-
}
|
|
337
|
-
if (options.background) {
|
|
338
|
-
cliArguments.push("--background");
|
|
339
|
-
}
|
|
340
|
-
if (options.newInstance) {
|
|
341
|
-
cliArguments.push("--new");
|
|
342
|
-
}
|
|
343
|
-
if (app) {
|
|
344
|
-
cliArguments.push("-a", app);
|
|
345
|
-
}
|
|
346
|
-
} else if (platform === "win32" || is_wsl_default && !isInsideContainer() && !app) {
|
|
347
|
-
command = await powerShellPath();
|
|
348
|
-
cliArguments.push(
|
|
349
|
-
"-NoProfile",
|
|
350
|
-
"-NonInteractive",
|
|
351
|
-
"-ExecutionPolicy",
|
|
352
|
-
"Bypass",
|
|
353
|
-
"-EncodedCommand"
|
|
354
|
-
);
|
|
355
|
-
if (!is_wsl_default) {
|
|
356
|
-
childProcessOptions.windowsVerbatimArguments = true;
|
|
357
|
-
}
|
|
358
|
-
const encodedArguments = ["Start"];
|
|
359
|
-
if (options.wait) {
|
|
360
|
-
encodedArguments.push("-Wait");
|
|
361
|
-
}
|
|
362
|
-
if (app) {
|
|
363
|
-
encodedArguments.push(`"\`"${app}\`""`);
|
|
364
|
-
if (options.target) {
|
|
365
|
-
appArguments.push(options.target);
|
|
366
|
-
}
|
|
367
|
-
} else if (options.target) {
|
|
368
|
-
encodedArguments.push(`"${options.target}"`);
|
|
369
|
-
}
|
|
370
|
-
if (appArguments.length > 0) {
|
|
371
|
-
appArguments = appArguments.map((argument) => `"\`"${argument}\`""`);
|
|
372
|
-
encodedArguments.push("-ArgumentList", appArguments.join(","));
|
|
373
|
-
}
|
|
374
|
-
options.target = Buffer$1.from(encodedArguments.join(" "), "utf16le").toString("base64");
|
|
375
|
-
} else {
|
|
376
|
-
if (app) {
|
|
377
|
-
command = app;
|
|
378
|
-
} else {
|
|
379
|
-
const isBundled = !__dirname$1 || __dirname$1 === "/";
|
|
380
|
-
let exeLocalXdgOpen = false;
|
|
381
|
-
try {
|
|
382
|
-
await fs4.access(localXdgOpenPath, constants.X_OK);
|
|
383
|
-
exeLocalXdgOpen = true;
|
|
384
|
-
} catch {
|
|
385
|
-
}
|
|
386
|
-
const useSystemXdgOpen = process5.versions.electron ?? (platform === "android" || isBundled || !exeLocalXdgOpen);
|
|
387
|
-
command = useSystemXdgOpen ? "xdg-open" : localXdgOpenPath;
|
|
388
|
-
}
|
|
389
|
-
if (appArguments.length > 0) {
|
|
390
|
-
cliArguments.push(...appArguments);
|
|
391
|
-
}
|
|
392
|
-
if (!options.wait) {
|
|
393
|
-
childProcessOptions.stdio = "ignore";
|
|
394
|
-
childProcessOptions.detached = true;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
if (platform === "darwin" && appArguments.length > 0) {
|
|
398
|
-
cliArguments.push("--args", ...appArguments);
|
|
399
|
-
}
|
|
400
|
-
if (options.target) {
|
|
401
|
-
cliArguments.push(options.target);
|
|
402
|
-
}
|
|
403
|
-
const subprocess = childProcess.spawn(command, cliArguments, childProcessOptions);
|
|
404
|
-
if (options.wait) {
|
|
405
|
-
return new Promise((resolve, reject) => {
|
|
406
|
-
subprocess.once("error", reject);
|
|
407
|
-
subprocess.once("close", (exitCode) => {
|
|
408
|
-
if (!options.allowNonzeroExitCode && exitCode > 0) {
|
|
409
|
-
reject(new Error(`Exited with code ${exitCode}`));
|
|
410
|
-
return;
|
|
411
|
-
}
|
|
412
|
-
resolve(subprocess);
|
|
413
|
-
});
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
subprocess.unref();
|
|
417
|
-
return subprocess;
|
|
418
|
-
};
|
|
419
|
-
var open = (target, options) => {
|
|
420
|
-
if (typeof target !== "string") {
|
|
421
|
-
throw new TypeError("Expected a `target`");
|
|
422
|
-
}
|
|
423
|
-
return baseOpen({
|
|
424
|
-
...options,
|
|
425
|
-
target
|
|
426
|
-
});
|
|
427
|
-
};
|
|
428
|
-
function detectArchBinary(binary) {
|
|
429
|
-
if (typeof binary === "string" || Array.isArray(binary)) {
|
|
430
|
-
return binary;
|
|
431
|
-
}
|
|
432
|
-
const { [arch]: archBinary } = binary;
|
|
433
|
-
if (!archBinary) {
|
|
434
|
-
throw new Error(`${arch} is not supported`);
|
|
435
|
-
}
|
|
436
|
-
return archBinary;
|
|
437
|
-
}
|
|
438
|
-
function detectPlatformBinary({ [platform]: platformBinary }, { wsl }) {
|
|
439
|
-
if (wsl && is_wsl_default) {
|
|
440
|
-
return detectArchBinary(wsl);
|
|
441
|
-
}
|
|
442
|
-
if (!platformBinary) {
|
|
443
|
-
throw new Error(`${platform} is not supported`);
|
|
444
|
-
}
|
|
445
|
-
return detectArchBinary(platformBinary);
|
|
446
|
-
}
|
|
447
|
-
var apps = {};
|
|
448
|
-
defineLazyProperty(apps, "chrome", () => detectPlatformBinary({
|
|
449
|
-
darwin: "google chrome",
|
|
450
|
-
win32: "chrome",
|
|
451
|
-
linux: ["google-chrome", "google-chrome-stable", "chromium"]
|
|
452
|
-
}, {
|
|
453
|
-
wsl: {
|
|
454
|
-
ia32: "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe",
|
|
455
|
-
x64: ["/mnt/c/Program Files/Google/Chrome/Application/chrome.exe", "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"]
|
|
456
|
-
}
|
|
457
|
-
}));
|
|
458
|
-
defineLazyProperty(apps, "brave", () => detectPlatformBinary({
|
|
459
|
-
darwin: "brave browser",
|
|
460
|
-
win32: "brave",
|
|
461
|
-
linux: ["brave-browser", "brave"]
|
|
462
|
-
}, {
|
|
463
|
-
wsl: {
|
|
464
|
-
ia32: "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe",
|
|
465
|
-
x64: ["/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe", "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe"]
|
|
466
|
-
}
|
|
467
|
-
}));
|
|
468
|
-
defineLazyProperty(apps, "firefox", () => detectPlatformBinary({
|
|
469
|
-
darwin: "firefox",
|
|
470
|
-
win32: String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`,
|
|
471
|
-
linux: "firefox"
|
|
472
|
-
}, {
|
|
473
|
-
wsl: "/mnt/c/Program Files/Mozilla Firefox/firefox.exe"
|
|
474
|
-
}));
|
|
475
|
-
defineLazyProperty(apps, "edge", () => detectPlatformBinary({
|
|
476
|
-
darwin: "microsoft edge",
|
|
477
|
-
win32: "msedge",
|
|
478
|
-
linux: ["microsoft-edge", "microsoft-edge-dev"]
|
|
479
|
-
}, {
|
|
480
|
-
wsl: "/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
|
|
481
|
-
}));
|
|
482
|
-
defineLazyProperty(apps, "browser", () => "browser");
|
|
483
|
-
defineLazyProperty(apps, "browserPrivate", () => "browserPrivate");
|
|
484
|
-
var open_default = open;
|
|
485
|
-
|
|
486
|
-
// src/auth.ts
|
|
487
|
-
var LOGIN_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
488
|
-
var generatePKCE = async () => {
|
|
489
|
-
const codeVerifier = getVerifier();
|
|
490
|
-
const codeChallenge = await getDigest(codeVerifier, "base64url");
|
|
491
|
-
return { codeVerifier, codeChallenge };
|
|
492
|
-
};
|
|
493
|
-
var fetchDiscovery = async (discoveryUrl) => {
|
|
494
|
-
const res = await fetch(discoveryUrl);
|
|
495
|
-
if (!res.ok) {
|
|
496
|
-
throw new Error(`Failed to fetch OAuth discovery: ${res.status} ${res.statusText}`);
|
|
497
|
-
}
|
|
498
|
-
return res.json();
|
|
499
|
-
};
|
|
500
|
-
var registerClient = async (registrationEndpoint) => {
|
|
501
|
-
const res = await fetch(registrationEndpoint, {
|
|
502
|
-
method: "POST",
|
|
503
|
-
headers: { "content-type": "application/json" },
|
|
504
|
-
body: JSON.stringify({
|
|
505
|
-
client_name: STANDALONE_CLIENT.MCP,
|
|
506
|
-
redirect_uris: ["http://127.0.0.1/callback"]
|
|
507
|
-
})
|
|
508
|
-
});
|
|
509
|
-
if (!res.ok) {
|
|
510
|
-
throw new Error(`Client registration failed: ${res.status}`);
|
|
511
|
-
}
|
|
512
|
-
const data = await res.json();
|
|
513
|
-
return data.client_id;
|
|
514
|
-
};
|
|
515
|
-
var exchangeCodeForToken = async (tokenEndpoint, code, codeVerifier, clientId, redirectUri) => {
|
|
516
|
-
const res = await fetch(tokenEndpoint, {
|
|
517
|
-
method: "POST",
|
|
518
|
-
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
519
|
-
body: new URLSearchParams({
|
|
520
|
-
grant_type: "authorization_code",
|
|
521
|
-
code,
|
|
522
|
-
code_verifier: codeVerifier,
|
|
523
|
-
client_id: clientId,
|
|
524
|
-
redirect_uri: redirectUri
|
|
525
|
-
}).toString()
|
|
526
|
-
});
|
|
527
|
-
if (!res.ok) {
|
|
528
|
-
const error = await res.json().catch(() => ({}));
|
|
529
|
-
throw new Error(error.error_description ?? error.error ?? `Token exchange failed: ${res.status}`);
|
|
530
|
-
}
|
|
531
|
-
return res.json();
|
|
532
|
-
};
|
|
533
|
-
var decodeJwtPayload = (token) => {
|
|
534
|
-
const [, payload] = token.split(".");
|
|
535
|
-
if (!payload) {
|
|
536
|
-
throw new Error("Invalid JWT format");
|
|
537
|
-
}
|
|
538
|
-
return JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
539
|
-
};
|
|
540
|
-
var performOAuthFlow = async (discoveryUrl) => {
|
|
541
|
-
const discovery = await fetchDiscovery(discoveryUrl);
|
|
542
|
-
let clientId = await deriveClientId(STANDALONE_CLIENT.MCP);
|
|
543
|
-
if (discovery.registration_endpoint) {
|
|
544
|
-
clientId = await registerClient(discovery.registration_endpoint);
|
|
545
|
-
}
|
|
546
|
-
const { codeVerifier, codeChallenge } = await generatePKCE();
|
|
547
|
-
const state = getNonce();
|
|
548
|
-
let resolveCode;
|
|
549
|
-
let rejectCode;
|
|
550
|
-
const codePromise = new Promise((resolve, reject) => {
|
|
551
|
-
resolveCode = resolve;
|
|
552
|
-
rejectCode = reject;
|
|
553
|
-
});
|
|
554
|
-
let server;
|
|
555
|
-
server = createServer((req, res) => {
|
|
556
|
-
const url = new URL(req.url, "http://localhost");
|
|
557
|
-
if (url.pathname === "/callback") {
|
|
558
|
-
const error = url.searchParams.get("error");
|
|
559
|
-
if (error) {
|
|
560
|
-
res.writeHead(200, { "content-type": "text/html; charset=utf-8" });
|
|
561
|
-
res.end("<html><body><h2>Authentication failed</h2><p>You can close this tab.</p></body></html>");
|
|
562
|
-
rejectCode(new Error(url.searchParams.get("error_description") ?? error));
|
|
563
|
-
return;
|
|
564
|
-
}
|
|
565
|
-
const code2 = url.searchParams.get("code");
|
|
566
|
-
const returnedState = url.searchParams.get("state");
|
|
567
|
-
if (!code2) {
|
|
568
|
-
res.writeHead(400, { "content-type": "text/plain" });
|
|
569
|
-
res.end("Missing authorization code");
|
|
570
|
-
return;
|
|
571
|
-
}
|
|
572
|
-
if (returnedState !== state) {
|
|
573
|
-
res.writeHead(400, { "content-type": "text/plain" });
|
|
574
|
-
res.end("State mismatch");
|
|
575
|
-
rejectCode(new Error("OAuth state mismatch \u2014 possible CSRF attack"));
|
|
576
|
-
return;
|
|
577
|
-
}
|
|
578
|
-
res.writeHead(200, { "content-type": "text/html; charset=utf-8" });
|
|
579
|
-
res.end("<html><body><h2>Authenticated</h2><p>You can return to your terminal.</p></body></html>");
|
|
580
|
-
resolveCode(code2);
|
|
581
|
-
} else {
|
|
582
|
-
res.writeHead(404);
|
|
583
|
-
res.end();
|
|
584
|
-
}
|
|
585
|
-
});
|
|
586
|
-
await new Promise((r) => server.listen(0, "127.0.0.1", r));
|
|
587
|
-
const port = server.address().port;
|
|
588
|
-
const redirectUri = `http://127.0.0.1:${port}/callback`;
|
|
589
|
-
const authUrl = new URL(discovery.authorization_endpoint);
|
|
590
|
-
authUrl.searchParams.set("client_id", clientId);
|
|
591
|
-
authUrl.searchParams.set("redirect_uri", redirectUri);
|
|
592
|
-
authUrl.searchParams.set("code_challenge", codeChallenge);
|
|
593
|
-
authUrl.searchParams.set("code_challenge_method", "S256");
|
|
594
|
-
authUrl.searchParams.set("state", state);
|
|
595
|
-
authUrl.searchParams.set("response_type", "code");
|
|
596
|
-
await open_default(authUrl.toString());
|
|
597
|
-
const timeout = setTimeout(() => {
|
|
598
|
-
server.close();
|
|
599
|
-
rejectCode(new Error("Authentication timed out. Please try again."));
|
|
600
|
-
}, LOGIN_TIMEOUT_MS);
|
|
601
|
-
let code;
|
|
602
|
-
try {
|
|
603
|
-
code = await codePromise;
|
|
604
|
-
} catch (err) {
|
|
605
|
-
clearTimeout(timeout);
|
|
606
|
-
server.close();
|
|
607
|
-
throw err;
|
|
608
|
-
}
|
|
609
|
-
clearTimeout(timeout);
|
|
610
|
-
server.close();
|
|
611
|
-
const tokenResponse = await exchangeCodeForToken(
|
|
612
|
-
discovery.token_endpoint,
|
|
613
|
-
code,
|
|
614
|
-
codeVerifier,
|
|
615
|
-
clientId,
|
|
616
|
-
redirectUri
|
|
617
|
-
);
|
|
618
|
-
const payload = decodeJwtPayload(tokenResponse.access_token);
|
|
619
|
-
await writeAuthState(
|
|
620
|
-
{
|
|
621
|
-
token: tokenResponse.access_token,
|
|
622
|
-
orgId: payload.orgId,
|
|
623
|
-
userId: payload.sub
|
|
624
|
-
},
|
|
625
|
-
STANDALONE_CLIENT_AUTH_FILE.MCP
|
|
626
|
-
);
|
|
627
|
-
return tokenResponse.access_token;
|
|
628
|
-
};
|
|
629
|
-
|
|
630
|
-
export { performOAuthFlow };
|