Merge dev into update-oauth-docs

This commit is contained in:
Konsti Wohlwend 2025-10-25 04:31:38 -07:00 committed by GitHub
commit 744186ae31
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
48 changed files with 1343 additions and 107 deletions

View File

@ -1,5 +1,23 @@
# @stackframe/stack-backend
## 2.8.47
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack@2.8.47
- @stackframe/stack-shared@2.8.47
## 2.8.46
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack@2.8.46
- @stackframe/stack-shared@2.8.46
## 2.8.45
### Patch Changes

View File

@ -1,6 +1,6 @@
{
"name": "@stackframe/stack-backend",
"version": "2.8.45",
"version": "2.8.47",
"private": true,
"scripts": {
"clean": "rimraf src/generated && rimraf .next && rimraf node_modules",

View File

@ -1,5 +1,25 @@
# @stackframe/stack-dashboard
## 2.8.47
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack@2.8.47
- @stackframe/stack-shared@2.8.47
- @stackframe/stack-ui@2.8.47
## 2.8.46
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack@2.8.46
- @stackframe/stack-shared@2.8.46
- @stackframe/stack-ui@2.8.46
## 2.8.45
### Patch Changes

View File

@ -1,6 +1,6 @@
{
"name": "@stackframe/stack-dashboard",
"version": "2.8.45",
"version": "2.8.47",
"private": true,
"scripts": {
"clean": "rimraf .next && rimraf node_modules",

View File

@ -1,37 +1,40 @@
"use client";
import { useAdminApp } from "@/app/(main)/(protected)/projects/[projectId]/use-admin-app";
import { getPublicEnvVar } from "@/lib/env";
import { StackAdminApp } from "@stackframe/stack";
import { throwErr } from "@stackframe/stack-shared/dist/utils/errors";
import { loadConnectAndInitialize } from "@stripe/connect-js";
import {
ConnectComponentsProvider,
} from "@stripe/react-connect-js";
import { useTheme } from "next-themes";
import { useEffect, useMemo } from "react";
import { useAdminApp } from "@/app/(main)/(protected)/projects/[projectId]/use-admin-app";
import { getPublicEnvVar } from "@/lib/env";
import { throwErr } from "@stackframe/stack-shared/dist/utils/errors";
import { useEffect } from "react";
import { appearanceVariablesForTheme } from "./stripe-theme-variables";
type StripeConnectProviderProps = {
children: React.ReactNode,
};
const stripeConnectInstances = new Map<string, ReturnType<typeof loadConnectAndInitialize>>();
export function getStripeConnectInstance(adminApp: StackAdminApp) {
if (!stripeConnectInstances.has(adminApp.projectId)) {
stripeConnectInstances.set(adminApp.projectId, loadConnectAndInitialize({
publishableKey: getPublicEnvVar("NEXT_PUBLIC_STACK_STRIPE_PUBLISHABLE_KEY") ?? throwErr("No Stripe publishable key found"),
fetchClientSecret: async () => {
const { client_secret } = await adminApp.createStripeWidgetAccountSession();
return client_secret;
},
}));
}
return stripeConnectInstances.get(adminApp.projectId)!;
}
export function StripeConnectProvider({ children }: StripeConnectProviderProps) {
const adminApp = useAdminApp();
const { resolvedTheme } = useTheme();
const stripeConnectInstance = useMemo(() => {
const publishableKey = getPublicEnvVar("NEXT_PUBLIC_STACK_STRIPE_PUBLISHABLE_KEY") ?? throwErr("No Stripe publishable key found");
const fetchClientSecret = async () => {
const { client_secret } = await adminApp.createStripeWidgetAccountSession();
return client_secret;
};
return loadConnectAndInitialize({
publishableKey,
fetchClientSecret,
appearance: { overlays: 'dialog' },
});
}, [adminApp]);
const stripeConnectInstance = getStripeConnectInstance(adminApp);
useEffect(() => {
stripeConnectInstance.update({

View File

@ -1,5 +1,17 @@
# @stackframe/dev-launchpad
## 2.8.47
### Patch Changes
- Various changes
## 2.8.46
### Patch Changes
- Various changes
## 2.8.45
### Patch Changes

View File

@ -1,6 +1,6 @@
{
"name": "@stackframe/dev-launchpad",
"version": "2.8.45",
"version": "2.8.47",
"private": true,
"scripts": {
"dev": "node scripts/write-env-config.js && serve -p ${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}00 -s public",

View File

@ -1,5 +1,23 @@
# @stackframe/e2e-tests
## 2.8.47
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/js@2.8.47
- @stackframe/stack-shared@2.8.47
## 2.8.46
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/js@2.8.46
- @stackframe/stack-shared@2.8.46
## 2.8.45
### Patch Changes

View File

@ -1,6 +1,6 @@
{
"name": "@stackframe/e2e-tests",
"version": "2.8.45",
"version": "2.8.47",
"private": true,
"type": "module",
"scripts": {

View File

@ -1,5 +1,17 @@
# @stackframe/mock-oauth-server
## 2.8.47
### Patch Changes
- Various changes
## 2.8.46
### Patch Changes
- Various changes
## 2.8.45
### Patch Changes

View File

@ -1,6 +1,6 @@
{
"name": "@stackframe/mock-oauth-server",
"version": "2.8.45",
"version": "2.8.47",
"private": true,
"main": "index.js",
"scripts": {

View File

@ -1,5 +1,23 @@
# @stackframe/stack-docs
## 2.8.47
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack@2.8.47
- @stackframe/stack-shared@2.8.47
## 2.8.46
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack@2.8.46
- @stackframe/stack-shared@2.8.46
## 2.8.45
### Patch Changes

View File

@ -1,6 +1,6 @@
{
"name": "@stackframe/stack-docs",
"version": "2.8.45",
"version": "2.8.47",
"description": "",
"main": "index.js",
"private": true,

View File

@ -1,5 +1,21 @@
# @stackframe/example-cjs-test
## 2.8.47
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack@2.8.47
## 2.8.46
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack@2.8.46
## 2.8.45
### Patch Changes

View File

@ -1,6 +1,6 @@
{
"name": "@stackframe/example-cjs-test",
"version": "2.8.45",
"version": "2.8.47",
"private": true,
"scripts": {
"dev": "next dev --port ${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}10",

View File

@ -1,5 +1,23 @@
# @stackframe/convex-example
## 2.8.47
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack@2.8.47
- @stackframe/stack-shared@2.8.47
## 2.8.46
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack@2.8.46
- @stackframe/stack-shared@2.8.46
## 2.8.45
### Patch Changes

View File

@ -1,6 +1,6 @@
{
"name": "@stackframe/convex-example",
"version": "2.8.45",
"version": "2.8.47",
"private": true,
"scripts": {
"convex": "convex",

View File

@ -1,5 +1,25 @@
# @stackframe/example-demo-app
## 2.8.47
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack@2.8.47
- @stackframe/stack-shared@2.8.47
- @stackframe/stack-ui@2.8.47
## 2.8.46
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack@2.8.46
- @stackframe/stack-shared@2.8.46
- @stackframe/stack-ui@2.8.46
## 2.8.45
### Patch Changes

View File

@ -1,6 +1,6 @@
{
"name": "@stackframe/example-demo-app",
"version": "2.8.45",
"version": "2.8.47",
"description": "",
"private": true,
"scripts": {

View File

@ -1,5 +1,25 @@
# @stackframe/docs-examples
## 2.8.47
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack@2.8.47
- @stackframe/stack-shared@2.8.47
- @stackframe/stack-ui@2.8.47
## 2.8.46
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack@2.8.46
- @stackframe/stack-shared@2.8.46
- @stackframe/stack-ui@2.8.46
## 2.8.45
### Patch Changes

View File

@ -1,6 +1,6 @@
{
"name": "@stackframe/docs-examples",
"version": "2.8.45",
"version": "2.8.47",
"description": "",
"private": true,
"scripts": {

View File

@ -1,5 +1,21 @@
# @stackframe/e-commerce-demo
## 2.8.47
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack@2.8.47
## 2.8.46
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack@2.8.46
## 2.8.45
### Patch Changes

View File

@ -1,6 +1,6 @@
{
"name": "@stackframe/e-commerce-demo",
"version": "2.8.45",
"version": "2.8.47",
"private": true,
"scripts": {
"dev": "next dev --port ${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}11",

View File

@ -1,5 +1,21 @@
# @stackframe/js-example
## 2.8.47
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/js@2.8.47
## 2.8.46
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/js@2.8.46
## 2.8.45
### Patch Changes

View File

@ -1,6 +1,6 @@
{
"name": "@stackframe/js-example",
"version": "2.8.45",
"version": "2.8.47",
"private": true,
"description": "",
"main": "index.js",

View File

@ -1,5 +1,21 @@
# @stackframe/example-middleware-demo
## 2.8.47
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack@2.8.47
## 2.8.46
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack@2.8.46
## 2.8.45
### Patch Changes

View File

@ -1,6 +1,6 @@
{
"name": "@stackframe/example-middleware-demo",
"version": "2.8.45",
"version": "2.8.47",
"private": true,
"scripts": {
"dev": "next dev --port ${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}12",

View File

@ -1,5 +1,21 @@
# react-example
## 2.8.47
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/react@2.8.47
## 2.8.46
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/react@2.8.46
## 2.8.45
### Patch Changes

View File

@ -1,7 +1,7 @@
{
"name": "react-example",
"private": true,
"version": "2.8.45",
"version": "2.8.47",
"type": "module",
"scripts": {
"dev": "vite --force --port ${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}20",

View File

@ -1,5 +1,21 @@
# @stackframe/example-supabase
## 2.8.47
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack@2.8.47
## 2.8.46
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack@2.8.46
## 2.8.45
### Patch Changes

View File

@ -1,6 +1,6 @@
{
"name": "@stackframe/example-supabase",
"version": "2.8.45",
"version": "2.8.47",
"private": true,
"scripts": {
"dev": "next dev --turbo --port ${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}15",

View File

@ -1,5 +1,21 @@
# @stackframe/init-stack
## 2.8.47
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack-shared@2.8.47
## 2.8.46
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack-shared@2.8.46
## 2.8.45
### Patch Changes

View File

@ -1,6 +1,6 @@
{
"name": "@stackframe/init-stack",
"version": "2.8.45",
"version": "2.8.47",
"description": "The setup wizard for Stack. https://stack-auth.com",
"main": "dist/index.js",
"type": "module",
@ -18,16 +18,16 @@
"ensure-neon": "grep -q '\"@neondatabase/serverless\"' ./test-run-output/package.json && echo 'Initialized Neon successfully!'",
"test-run-neon": "pnpm run test-run-node --neon && pnpm run ensure-neon",
"test-run-neon:manual": "pnpm run test-run-node:manual --neon && pnpm run ensure-neon",
"test-run-no-browser": "rimraf test-run-output && mkdir test-run-output && cd test-run-output && npm init --init-author-name example-author --init-license UNLICENSED --init-author-url http://example.com --init-module test-run-output --init-version 1.0.0 -y && cd .. && pnpm run init-stack:local test-run-output --on-question error --js --server --npm --no-browser",
"test-run-no-browser": "rimraf test-run-output && mkdir test-run-output && cd test-run-output && npm init --init-author-name example-author --init-license UNLICENSED --init-author-url http://example.com --init-module test-run-output --init-version 1.0.0 -y && cd .. && pnpm run init-stack:local test-run-output --on-question error --no-warn-uncommitted-changes --js --server --npm --no-browser",
"test-run-node:manual": "rimraf test-run-output && mkdir test-run-output && cd test-run-output && npm init && cd .. && pnpm run init-stack:local test-run-output",
"test-run-node": "rimraf test-run-output && mkdir test-run-output && cd test-run-output && npm init --init-author-name example-author --init-license UNLICENSED --init-author-url http://example.com --init-module test-run-output --init-version 1.0.0 -y && cd .. && pnpm run init-stack:local test-run-output --on-question error --js --server --npm --no-browser",
"test-run-node": "rimraf test-run-output && mkdir test-run-output && cd test-run-output && npm init --init-author-name example-author --init-license UNLICENSED --init-author-url http://example.com --init-module test-run-output --init-version 1.0.0 -y && cd .. && pnpm run init-stack:local test-run-output --on-question error --no-warn-uncommitted-changes --js --server --npm --no-browser",
"test-run-js:manual": "rimraf test-run-output && npx -y sv create test-run-output --no-install && pnpm run init-stack:local test-run-output",
"test-run-js": "rimraf test-run-output && npx -y sv create test-run-output --template minimal --types ts --no-add-ons --no-install && pnpm run init-stack:local test-run-output --on-question error --js --client --npm --no-browser",
"test-run-js": "rimraf test-run-output && npx -y sv create test-run-output --template minimal --types ts --no-add-ons --no-install && pnpm run init-stack:local test-run-output --on-question error --no-warn-uncommitted-changes --js --client --npm --no-browser",
"test-run-next:manual": "rimraf test-run-output && npx -y create-next-app@latest test-run-output && pnpm run init-stack:local test-run-output",
"test-run-next": "rimraf test-run-output && npx -y create-next-app@latest test-run-output --app --ts --no-src-dir --tailwind --use-npm --eslint --import-alias '##@#/*' --turbopack && pnpm run init-stack:local test-run-output --on-question error --no-browser",
"test-run-keys-next": "rimraf test-run-output && npx -y create-next-app@latest test-run-output --app --ts --no-src-dir --tailwind --use-npm --eslint --import-alias '##@#/*' --turbopack && pnpm run init-stack:local test-run-output --on-question error --project-id my-project-id --publishable-client-key my-publishable-client-key",
"test-run-keys-js": "rimraf test-run-output && npx -y sv create test-run-output --template minimal --types ts --no-add-ons --no-install && pnpm run init-stack:local test-run-output --on-question error --js --client --npm --project-id my-project-id --publishable-client-key my-publishable-client-key",
"test-run-react": "rimraf test-run-output && npx -y create-vite@latest test-run-output --template react-ts && pnpm run init-stack:local test-run-output --on-question error --no-browser --npm",
"test-run-next": "rimraf test-run-output && npx -y create-next-app@latest test-run-output --app --ts --no-src-dir --tailwind --use-npm --eslint --import-alias '##@#/*' --turbopack && pnpm run init-stack:local test-run-output --on-question error --no-warn-uncommitted-changes --no-browser",
"test-run-keys-next": "rimraf test-run-output && npx -y create-next-app@latest test-run-output --app --ts --no-src-dir --tailwind --use-npm --eslint --import-alias '##@#/*' --turbopack && pnpm run init-stack:local test-run-output --on-question error --no-warn-uncommitted-changes --project-id my-project-id --publishable-client-key my-publishable-client-key",
"test-run-keys-js": "rimraf test-run-output && npx -y sv create test-run-output --template minimal --types ts --no-add-ons --no-install && pnpm run init-stack:local test-run-output --on-question error --no-warn-uncommitted-changes --js --client --npm --project-id my-project-id --publishable-client-key my-publishable-client-key",
"test-run-react": "rimraf test-run-output && npx -y create-vite@latest test-run-output --template react-ts && pnpm run init-stack:local test-run-output --on-question error --no-warn-uncommitted-changes --no-browser --npm",
"test-run-react:manual": "rimraf test-run-output && npx -y create-vite@latest test-run-output --template react-ts && pnpm run init-stack:local test-run-output --react"
},
"files": [

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,405 @@
import type { SpawnSyncOptions } from "child_process";
import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import type { Colorize, JsonRecord } from "./util";
import { getCommandPath, logVerbose, shouldWriteConfigFile } from "./util";
const MCP_SERVER_NAME = "stack-auth";
const MCP_SERVER_URL = "https://mcp.stack-auth.com/";
const MCP_ACCEPT_HEADER = "application/json, text/event-stream";
type JsonUpdater = (current: JsonRecord) => JsonRecord | null | undefined;
type JsonTarget = { path: string, allowCreate?: boolean };
const VS_CODE_PAYLOAD = JSON.stringify({ type: "http", name: MCP_SERVER_NAME, url: MCP_SERVER_URL });
const CLAUDE_BASE_ARGS = ["mcp", "add", "--transport", "http", MCP_SERVER_NAME, MCP_SERVER_URL] as const;
type RunScheduledCommandMetadata = {
recordInCommandsExecuted?: boolean,
};
type McpSchedulerContext = {
projectPath: string,
isDryRun: boolean,
colorize: Colorize,
registerWriteHandler: (handler: () => Promise<void>) => void,
registerCommandHandler: (handler: () => Promise<void>) => void,
recordFileChange: (fullPath: string, existed: boolean) => Promise<void>,
runScheduledCommand: (
command: string,
args: string[],
options?: SpawnSyncOptions,
metadata?: RunScheduledCommandMetadata,
) => Promise<void>,
};
export function scheduleMcpConfiguration(ctx: McpSchedulerContext): void {
const workspaceRoot = path.resolve(ctx.projectPath);
const homeDir = os.homedir();
logMcpVerbose("scheduleMcpConfiguration invoked", { workspaceRoot, homeDir });
scheduleCursorConfigs(ctx, homeDir, workspaceRoot);
scheduleVsCodeConfigs(ctx, homeDir, workspaceRoot);
scheduleClaudeConfigs(ctx, workspaceRoot);
scheduleWindsurfConfigs(ctx, homeDir);
scheduleGeminiConfig(ctx, homeDir);
}
function scheduleCursorConfigs(ctx: McpSchedulerContext, homeDir: string, workspaceRoot: string): void {
const updater = createServerUpdater("mcpServers", { url: MCP_SERVER_URL });
logMcpVerbose("Scheduling Cursor MCP configs", { homeDir, workspaceRoot });
const targets = [
{ path: path.join(homeDir, ".cursor", "mcp.json"), allowCreate: false, scope: "home" },
{ path: path.join(workspaceRoot, ".cursor", "mcp.json"), allowCreate: true, scope: "workspace" },
];
for (const target of targets) {
logInvestigationStatus("Cursor", target.path, target.scope);
}
scheduleJsonTargets(
ctx,
targets.map(({ path: targetPath, allowCreate }) => ({ path: targetPath, allowCreate })),
updater,
);
}
function scheduleVsCodeConfigs(ctx: McpSchedulerContext, homeDir: string, workspaceRoot: string): void {
const updater = createServerUpdater("servers", { type: "http", url: MCP_SERVER_URL });
const paths = getVsCodeUserConfigPaths(homeDir);
logMcpVerbose("Scheduling VS Code MCP configs", { homeDir, paths });
paths.stable.forEach((configPath) => logInvestigationStatus("VS Code (stable)", configPath));
paths.insiders.forEach((configPath) => logInvestigationStatus("VS Code (insiders)", configPath));
const workspaceTarget = path.join(workspaceRoot, ".vscode", "mcp.json");
logInvestigationStatus("VS Code (workspace)", workspaceTarget);
const stableChanged = scheduleJsonTargets(
ctx,
paths.stable.map((configPath) => ({ path: configPath })),
updater,
);
const insidersChanged = scheduleJsonTargets(
ctx,
paths.insiders.map((configPath) => ({ path: configPath })),
updater,
);
const workspaceChanged = scheduleJsonTargets(
ctx,
[{ path: path.join(workspaceRoot, ".vscode", "mcp.json"), allowCreate: true }],
updater,
);
scheduleCliIfAvailable(ctx, "code", ["--add-mcp", VS_CODE_PAYLOAD], true);
scheduleCliIfAvailable(ctx, "code-insiders", ["--add-mcp", VS_CODE_PAYLOAD], true);
}
function findClaudeExecutable(): string {
// Check for local installations first
// (Claude installs itself via alias so it may not be in the system PATH)
const homeDir = os.homedir();
const localBinPath = path.join(homeDir, ".local", "bin", "claude");
const claudeLocalPath = path.join(homeDir, ".claude", "local", "claude");
if (fs.existsSync(localBinPath)) {
return localBinPath;
}
if (fs.existsSync(claudeLocalPath)) {
return claudeLocalPath;
}
// Fall back to system PATH
return "claude";
}
function scheduleClaudeConfigs(ctx: McpSchedulerContext, workspaceRoot: string): void {
const updater = createServerUpdater("mcpServers", { type: "http", url: MCP_SERVER_URL });
logMcpVerbose("Scheduling Claude MCP configs", { workspaceRoot });
const targetPath = path.join(workspaceRoot, ".mcp.json");
logInvestigationStatus("Claude (project)", targetPath);
const projectConfigChanged = scheduleJsonTargets(
ctx,
[{ path: targetPath, allowCreate: true }],
updater,
);
const claudeExecutable = findClaudeExecutable();
scheduleCliIfAvailable(ctx, claudeExecutable, [...CLAUDE_BASE_ARGS, "--scope", "user"], projectConfigChanged);
scheduleCliIfAvailable(
ctx,
claudeExecutable,
[...CLAUDE_BASE_ARGS, "--scope", "project"],
projectConfigChanged,
{ cwd: workspaceRoot },
);
}
function scheduleWindsurfConfigs(ctx: McpSchedulerContext, homeDir: string): void {
const updater = createServerUpdater("mcpServers", { serverUrl: MCP_SERVER_URL });
logMcpVerbose("Scheduling Windsurf MCP configs", { homeDir });
const paths = getWindsurfConfigPaths(homeDir);
paths.forEach((configPath) => logInvestigationStatus("Windsurf", configPath));
scheduleJsonTargets(ctx, paths.map((configPath) => ({ path: configPath })), updater);
}
function scheduleGeminiConfig(ctx: McpSchedulerContext, homeDir: string): void {
const updater = createServerUpdater("mcpServers", {
httpUrl: MCP_SERVER_URL,
headers: { Accept: MCP_ACCEPT_HEADER },
});
logMcpVerbose("Scheduling Gemini MCP configs", { homeDir });
const targetPath = path.join(homeDir, ".gemini", "settings.json");
logInvestigationStatus("Gemini", targetPath);
scheduleJsonTargets(
ctx,
[{ path: targetPath }],
updater,
);
}
function scheduleJsonFileUpdate(
ctx: McpSchedulerContext,
fullPath: string | null | undefined,
update: JsonUpdater,
options: { allowCreate?: boolean } = {}
): boolean {
logMcpVerbose("scheduleJsonFileUpdate invoked", { fullPath, allowCreate: options.allowCreate });
if (!fullPath) {
logMcpVerbose("scheduleJsonFileUpdate skipped: no path provided");
return false;
}
const allowCreate = options.allowCreate ?? false;
if (!shouldWriteConfigFile(fullPath, { allowCreate })) {
logMcpVerbose("scheduleJsonFileUpdate skipped: shouldWriteConfigFile returned false", { fullPath, allowCreate });
return false;
}
const absolutePath = path.resolve(fullPath);
const info = readJsonOrEmpty(absolutePath);
logMcpVerbose("scheduleJsonFileUpdate current file info", { absolutePath, existed: info.existed, parseError: info.parseError?.message });
const draft = cloneJsonRecord(info.data);
const updated = update(draft);
if (!updated) {
logMcpVerbose("scheduleJsonFileUpdate skipped: updater returned nullish", { absolutePath });
return false;
}
const nextContent = JSON.stringify(updated, null, 2) + "\n";
const currentContent = info.existed && !info.parseError ? JSON.stringify(info.data, null, 2) + "\n" : null;
if (!info.parseError && currentContent === nextContent) {
logMcpVerbose("scheduleJsonFileUpdate skipped: content unchanged", { absolutePath });
return false;
}
ctx.registerWriteHandler(async () => {
await writeJsonFile(ctx, absolutePath, update, { allowCreate });
});
logMcpVerbose("scheduleJsonFileUpdate scheduled write", { absolutePath });
return true;
}
type WriteJsonOptions = { allowCreate?: boolean };
async function writeJsonFile(
ctx: McpSchedulerContext,
absolutePath: string,
update: JsonUpdater,
options: WriteJsonOptions
): Promise<void> {
logMcpVerbose("writeJsonFile invoked", { absolutePath, allowCreate: options.allowCreate });
const allowCreate = options.allowCreate ?? false;
const info = readJsonOrEmpty(absolutePath);
if (!info.existed && !allowCreate) {
logMcpVerbose("writeJsonFile skipped: file missing and allowCreate false", { absolutePath });
return;
}
let current = info.data;
if (info.parseError) {
console.warn(
ctx.colorize.yellow`Warning: Unable to parse MCP config at ${absolutePath}. It will be replaced with a fresh configuration.`
);
current = {};
logMcpVerbose("writeJsonFile parse error encountered; falling back to empty object", { absolutePath, error: info.parseError.message });
}
const draft = cloneJsonRecord(current);
const updated = update(draft);
if (!updated) {
logMcpVerbose("writeJsonFile skipped: updater returned nullish", { absolutePath });
return;
}
const nextContent = JSON.stringify(updated, null, 2) + "\n";
const currentContent = info.existed && !info.parseError ? JSON.stringify(current, null, 2) + "\n" : null;
if (currentContent === nextContent && !info.parseError) {
logMcpVerbose("writeJsonFile skipped: current content matches desired content", { absolutePath });
return;
}
if (ctx.isDryRun) {
console.log(`[DRY-RUN] Would write ${absolutePath}`);
logMcpVerbose("writeJsonFile dry-run; write skipped", { absolutePath });
return;
}
fs.mkdirSync(path.dirname(absolutePath), { recursive: true });
if (info.existed) {
try {
fs.copyFileSync(absolutePath, `${absolutePath}.bak`);
} catch {
// Ignore backup failures; the write below is still valid.
}
}
fs.writeFileSync(absolutePath, nextContent, "utf-8");
await ctx.recordFileChange(absolutePath, info.existed);
logMcpVerbose("writeJsonFile completed write", { absolutePath, existed: info.existed });
}
function scheduleJsonTargets(ctx: McpSchedulerContext, targets: JsonTarget[], update: JsonUpdater): boolean {
let changed = false;
logMcpVerbose("scheduleJsonTargets invoked", { targetCount: targets.length });
for (const target of targets) {
if (!target.path) continue;
if (scheduleJsonFileUpdate(ctx, target.path, update, { allowCreate: target.allowCreate })) {
changed = true;
}
}
logMcpVerbose("scheduleJsonTargets completed", { changed });
return changed;
}
function scheduleCliIfAvailable(
ctx: McpSchedulerContext,
command: string,
args: string[],
shouldRun: boolean,
options?: SpawnSyncOptions,
): void {
logMcpVerbose("scheduleCliIfAvailable invoked", { command, args, shouldRun });
if (!shouldRun) {
logMcpVerbose("scheduleCliIfAvailable skipped: shouldRun false", { command });
return;
}
const commandPath = getCommandPath(command);
if (!commandPath) {
logMcpVerbose("scheduleCliIfAvailable skipped: command not available", { command });
return;
}
logMcpVerbose("scheduleCliIfAvailable scheduling CLI registration", { command });
scheduleCliRegistration(ctx, commandPath, args, options);
}
function createServerUpdater(containerKey: string, entry: JsonRecord): JsonUpdater {
logMcpVerbose("createServerUpdater invoked", { containerKey });
return (current: JsonRecord): JsonRecord => {
const next = { ...current };
const servers = { ...(next[containerKey] ?? {}) };
servers[MCP_SERVER_NAME] = cloneJsonRecord(entry);
next[containerKey] = servers;
return next;
};
}
function getVsCodeUserConfigPaths(homeDir: string): { stable: string[], insiders: string[] } {
const stable = new Set<string>();
const insiders = new Set<string>();
const platform = process.platform;
logMcpVerbose("getVsCodeUserConfigPaths invoked", { homeDir, platform });
if (platform === "darwin") {
stable.add(path.join(homeDir, "Library", "Application Support", "Code", "User", "mcp.json"));
insiders.add(path.join(homeDir, "Library", "Application Support", "Code - Insiders", "User", "mcp.json"));
} else if (platform === "win32") {
const appData = process.env.APPDATA;
if (appData) {
stable.add(path.join(appData, "Code", "User", "mcp.json"));
insiders.add(path.join(appData, "Code - Insiders", "User", "mcp.json"));
}
} else {
stable.add(path.join(homeDir, ".config", "Code", "User", "mcp.json"));
insiders.add(path.join(homeDir, ".config", "Code - Insiders", "User", "mcp.json"));
}
return {
stable: Array.from(stable),
insiders: Array.from(insiders),
};
}
function getWindsurfConfigPaths(homeDir: string): string[] {
const paths = new Set<string>();
logMcpVerbose("getWindsurfConfigPaths invoked", { homeDir, platform: process.platform });
if (process.platform === "darwin") {
paths.add(path.join(homeDir, ".codeium", "windsurf", "mcp_config.json"));
} else if (process.platform === "win32") {
const appData = process.env.APPDATA;
if (appData) {
paths.add(path.join(appData, "Codeium", "Windsurf", "mcp_config.json"));
}
} else {
paths.add(path.join(homeDir, ".config", "Codeium", "Windsurf", "mcp_config.json"));
paths.add(path.join(homeDir, ".codeium", "windsurf", "mcp_config.json"));
paths.add(path.join(homeDir, ".var", "app", "com.codeium.windsurf", "config", "Codeium", "Windsurf", "mcp_config.json"));
}
return Array.from(paths);
}
type JsonReadResult = { existed: boolean, data: JsonRecord, parseError: Error | null };
function readJsonOrEmpty(fullPath: string): JsonReadResult {
logMcpVerbose("readJsonOrEmpty invoked", { fullPath });
if (!fs.existsSync(fullPath)) {
logMcpVerbose("readJsonOrEmpty no file found", { fullPath });
return { existed: false, data: {}, parseError: null };
}
try {
const raw = fs.readFileSync(fullPath, "utf-8");
const data = raw.trim() ? JSON.parse(raw) : {};
logMcpVerbose("readJsonOrEmpty parsed file", { fullPath, hasContent: Boolean(raw.trim()) });
return { existed: true, data, parseError: null };
} catch (error) {
const parseError = error instanceof Error ? error : new Error(String(error));
logMcpVerbose("readJsonOrEmpty parse error", { fullPath, error: parseError.message });
return { existed: true, data: {}, parseError };
}
}
function cloneJsonRecord<T extends JsonRecord>(value: T): T {
return JSON.parse(JSON.stringify(value)) as T;
}
function scheduleCliRegistration(
ctx: McpSchedulerContext,
command: string,
args: string[],
options: SpawnSyncOptions = {}
): void {
logMcpVerbose("scheduleCliRegistration invoked", { command, args, options });
ctx.registerCommandHandler(async () => {
try {
await ctx.runScheduledCommand(command, args, options, {
recordInCommandsExecuted: false,
});
} catch (error) {
logMcpVerbose("scheduleCliRegistration encountered error. Ignoring.", { command, args, options, error: error instanceof Error ? { message: error.message, stack: error.stack } : error });
}
});
}
function logMcpVerbose(message: string, details?: unknown): void {
logVerbose(`[mcp] ${message}`, details);
}
function logInvestigationStatus(editorLabel: string, configPath: string, scope?: string): void {
const exists = fs.existsSync(configPath);
logMcpVerbose(`Investigating ${editorLabel} config${scope ? ` (${scope})` : ""}`, { path: configPath, exists });
}

View File

@ -0,0 +1,86 @@
import * as child_process from "child_process";
import * as fs from "fs";
import * as path from "path";
export type TemplateFunction = (strings: TemplateStringsArray, ...values: any[]) => string;
export type Colorize = {
red: TemplateFunction,
blue: TemplateFunction,
green: TemplateFunction,
yellow: TemplateFunction,
bold: TemplateFunction,
};
export type JsonRecord = Record<string, any>;
type VerboseFormatter = (message: string) => string;
let verboseLevelState = 0;
let verboseFormatterState: VerboseFormatter | null = null;
export function configureVerboseLogging(options: { level?: number, formatter?: VerboseFormatter }): void {
verboseLevelState = Math.max(0, options.level ?? 0);
verboseFormatterState = options.formatter ?? null;
}
export function getVerboseLevel(): number {
return verboseLevelState;
}
export function logVerbose(message: string, details?: unknown): void {
if (verboseLevelState <= 0) return;
const formattedMessage = verboseFormatterState ? verboseFormatterState(message) : `[verbose] ${message}`;
console.log(formattedMessage);
if (typeof details !== "undefined" && verboseLevelState >= 2) {
console.dir(details, { depth: null });
}
}
export function templateIdentity(strings: TemplateStringsArray, ...values: any[]): string {
if (strings.length === 0) return "";
if (values.length !== strings.length - 1) {
throw new Error("Invalid number of values; must be one less than strings");
}
return strings.slice(1).reduce(
(result, string, i) => `${result}${String(values[i])}${string}`,
strings[0]
);
}
export function omit(object: Record<string, any>, keys: string[]): Record<string, any> {
return Object.fromEntries(Object.entries(object).filter(([key]) => !keys.includes(key)));
}
export function getCommandPath(command: string): string | null {
if (!command) return null;
const checker = process.platform === "win32" ? "where" : "which";
const commands = [
[process.env.SHELL ?? "bash", ["-ic", `${checker} ${command}`]],
[checker, [command]],
] as const;
for (const spawnArgs of commands) {
const result = child_process.spawnSync(spawnArgs[0], spawnArgs[1], { stdio: "pipe" });
if (result.status === 0) {
return result.stdout.toString().trim().split('\n')[0];
}
}
return null;
}
export function shouldWriteConfigFile(
fullPath: string | null | undefined,
options: { allowCreate?: boolean } = {}
): boolean {
if (!fullPath) return false;
if (fs.existsSync(fullPath)) return true;
const dir = path.dirname(fullPath);
if (!options.allowCreate) {
return fs.existsSync(dir);
}
return true;
}

View File

@ -1,7 +1,7 @@
{
"//": "THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY",
"name": "@stackframe/js",
"version": "2.8.45",
"version": "2.8.47",
"sideEffects": false,
"main": "./dist/index.js",
"types": "./dist/index.d.ts",

View File

@ -1,7 +1,7 @@
{
"//": "THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY",
"name": "@stackframe/react",
"version": "2.8.45",
"version": "2.8.47",
"sideEffects": false,
"main": "./dist/index.js",
"types": "./dist/index.d.ts",

View File

@ -1,5 +1,17 @@
# @stackframe/stack-sc
## 2.8.47
### Patch Changes
- Various changes
## 2.8.46
### Patch Changes
- Various changes
## 2.8.45
## 2.8.44

View File

@ -1,6 +1,6 @@
{
"name": "@stackframe/stack-sc",
"version": "2.8.45",
"version": "2.8.47",
"exports": {
"./force-react-server": {
"types": "./dist/index.react-server.d.ts",

View File

@ -1,5 +1,17 @@
# @stackframe/stack-shared
## 2.8.47
### Patch Changes
- Various changes
## 2.8.46
### Patch Changes
- Various changes
## 2.8.45
### Patch Changes

View File

@ -1,6 +1,6 @@
{
"name": "@stackframe/stack-shared",
"version": "2.8.45",
"version": "2.8.47",
"scripts": {
"build": "rimraf dist && tsup-node",
"typecheck": "tsc --noEmit",

View File

@ -1,5 +1,21 @@
# @stackframe/stack-ui
## 2.8.47
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack-shared@2.8.47
## 2.8.46
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack-shared@2.8.46
## 2.8.45
### Patch Changes

View File

@ -1,6 +1,6 @@
{
"name": "@stackframe/stack-ui",
"version": "2.8.45",
"version": "2.8.47",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"sideEffects": false,

View File

@ -1,7 +1,7 @@
{
"//": "THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY",
"name": "@stackframe/stack",
"version": "2.8.45",
"version": "2.8.47",
"sideEffects": false,
"main": "./dist/index.js",
"types": "./dist/index.d.ts",

View File

@ -1,5 +1,25 @@
# @stackframe/stack
## 2.8.47
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack-sc@2.8.47
- @stackframe/stack-shared@2.8.47
- @stackframe/stack-ui@2.8.47
## 2.8.46
### Patch Changes
- Various changes
- Updated dependencies
- @stackframe/stack-sc@2.8.46
- @stackframe/stack-shared@2.8.46
- @stackframe/stack-ui@2.8.46
## 2.8.45
### Patch Changes

View File

@ -11,7 +11,7 @@
"//": "NEXT_LINE_PLATFORM template",
"private": true,
"version": "2.8.45",
"version": "2.8.47",
"sideEffects": false,
"main": "./dist/index.js",
"types": "./dist/index.d.ts",

View File

@ -2,7 +2,7 @@
"//": "THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY",
"name": "@stackframe/template",
"private": true,
"version": "2.8.45",
"version": "2.8.47",
"sideEffects": false,
"main": "./dist/index.js",
"types": "./dist/index.d.ts",