@hasna/connectors 0.3.13 → 0.3.15
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/bin/index.js +189 -16
- package/bin/mcp.js +83 -1
- package/connectors/connect-mistral/src/utils/config.ts +47 -15
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -6833,7 +6833,7 @@ var PRESETS = {
|
|
|
6833
6833
|
commerce: { description: "Commerce and finance", connectors: ["stripe", "shopify", "revolut", "mercury", "pandadoc"] }
|
|
6834
6834
|
};
|
|
6835
6835
|
var program2 = new Command;
|
|
6836
|
-
program2.name("connectors").description("Install API connectors for your project").version("0.3.
|
|
6836
|
+
program2.name("connectors").description("Install API connectors for your project").version("0.3.15").enablePositionalOptions();
|
|
6837
6837
|
program2.command("interactive", { isDefault: true }).alias("i").description("Interactive connector browser").action(() => {
|
|
6838
6838
|
if (!isTTY) {
|
|
6839
6839
|
console.log(`Non-interactive environment detected. Use a subcommand:
|
|
@@ -7951,27 +7951,48 @@ program2.command("export").option("-o, --output <file>", "Write to file instead
|
|
|
7951
7951
|
if (!statSync3(entryPath).isDirectory() || !entry.startsWith("connect-"))
|
|
7952
7952
|
continue;
|
|
7953
7953
|
const connectorName = entry.replace(/^connect-/, "");
|
|
7954
|
+
let credentials = undefined;
|
|
7955
|
+
const credentialsPath = join6(entryPath, "credentials.json");
|
|
7956
|
+
if (existsSync6(credentialsPath)) {
|
|
7957
|
+
try {
|
|
7958
|
+
credentials = JSON.parse(readFileSync5(credentialsPath, "utf-8"));
|
|
7959
|
+
} catch {}
|
|
7960
|
+
}
|
|
7954
7961
|
const profilesDir = join6(entryPath, "profiles");
|
|
7955
|
-
if (!existsSync6(profilesDir))
|
|
7962
|
+
if (!existsSync6(profilesDir) && !credentials)
|
|
7956
7963
|
continue;
|
|
7957
7964
|
const profiles = {};
|
|
7958
|
-
|
|
7959
|
-
const
|
|
7960
|
-
|
|
7961
|
-
|
|
7962
|
-
profiles[pEntry.replace(/\.json$/, "")] = JSON.parse(readFileSync5(pPath, "utf-8"));
|
|
7963
|
-
} catch {}
|
|
7964
|
-
} else if (statSync3(pPath).isDirectory()) {
|
|
7965
|
-
const configPath = join6(pPath, "config.json");
|
|
7966
|
-
if (existsSync6(configPath)) {
|
|
7965
|
+
if (existsSync6(profilesDir)) {
|
|
7966
|
+
for (const pEntry of readdirSync4(profilesDir)) {
|
|
7967
|
+
const pPath = join6(profilesDir, pEntry);
|
|
7968
|
+
if (statSync3(pPath).isFile() && pEntry.endsWith(".json")) {
|
|
7967
7969
|
try {
|
|
7968
|
-
profiles[pEntry] = JSON.parse(readFileSync5(
|
|
7970
|
+
profiles[pEntry.replace(/\.json$/, "")] = JSON.parse(readFileSync5(pPath, "utf-8"));
|
|
7969
7971
|
} catch {}
|
|
7972
|
+
} else if (statSync3(pPath).isDirectory()) {
|
|
7973
|
+
const configPath = join6(pPath, "config.json");
|
|
7974
|
+
const tokensPath = join6(pPath, "tokens.json");
|
|
7975
|
+
let merged = {};
|
|
7976
|
+
if (existsSync6(configPath)) {
|
|
7977
|
+
try {
|
|
7978
|
+
merged = { ...merged, ...JSON.parse(readFileSync5(configPath, "utf-8")) };
|
|
7979
|
+
} catch {}
|
|
7980
|
+
}
|
|
7981
|
+
if (existsSync6(tokensPath)) {
|
|
7982
|
+
try {
|
|
7983
|
+
merged = { ...merged, ...JSON.parse(readFileSync5(tokensPath, "utf-8")) };
|
|
7984
|
+
} catch {}
|
|
7985
|
+
}
|
|
7986
|
+
if (Object.keys(merged).length > 0)
|
|
7987
|
+
profiles[pEntry] = merged;
|
|
7970
7988
|
}
|
|
7971
7989
|
}
|
|
7972
7990
|
}
|
|
7973
|
-
|
|
7974
|
-
|
|
7991
|
+
const connectorData = { profiles };
|
|
7992
|
+
if (credentials)
|
|
7993
|
+
connectorData.credentials = credentials;
|
|
7994
|
+
if (Object.keys(profiles).length > 0 || credentials)
|
|
7995
|
+
result[connectorName] = connectorData;
|
|
7975
7996
|
}
|
|
7976
7997
|
}
|
|
7977
7998
|
const exportPayload = options.includeSecrets ? { connectors: result, exportedAt: new Date().toISOString() } : { connectors: redactSecrets(result), exportedAt: new Date().toISOString(), redacted: true };
|
|
@@ -8031,9 +8052,15 @@ program2.command("import").argument("<file>", "JSON backup file to import (use -
|
|
|
8031
8052
|
for (const [connectorName, connData] of Object.entries(data.connectors)) {
|
|
8032
8053
|
if (!/^[a-z0-9-]+$/.test(connectorName))
|
|
8033
8054
|
continue;
|
|
8055
|
+
const connectorDir = join6(connectDir, `connect-${connectorName}`);
|
|
8056
|
+
if (connData.credentials && typeof connData.credentials === "object") {
|
|
8057
|
+
mkdirSync4(connectorDir, { recursive: true });
|
|
8058
|
+
writeFileSync4(join6(connectorDir, "credentials.json"), JSON.stringify(connData.credentials, null, 2));
|
|
8059
|
+
imported++;
|
|
8060
|
+
}
|
|
8034
8061
|
if (!connData.profiles || typeof connData.profiles !== "object")
|
|
8035
8062
|
continue;
|
|
8036
|
-
const profilesDir = join6(
|
|
8063
|
+
const profilesDir = join6(connectorDir, "profiles");
|
|
8037
8064
|
for (const [profileName, config] of Object.entries(connData.profiles)) {
|
|
8038
8065
|
if (!config || typeof config !== "object")
|
|
8039
8066
|
continue;
|
|
@@ -8049,7 +8076,7 @@ program2.command("import").argument("<file>", "JSON backup file to import (use -
|
|
|
8049
8076
|
}
|
|
8050
8077
|
});
|
|
8051
8078
|
program2.command("upgrade").alias("self-update").option("--check", "Only check for updates, don't install", false).option("--json", "Output as JSON", false).description("Check for updates and upgrade to the latest version").action(async (options) => {
|
|
8052
|
-
const currentVersion =
|
|
8079
|
+
const currentVersion = program2.version();
|
|
8053
8080
|
try {
|
|
8054
8081
|
const res = await fetch("https://registry.npmjs.org/@hasna/connectors/latest");
|
|
8055
8082
|
if (!res.ok)
|
|
@@ -8542,4 +8569,150 @@ program2.command("run").description("Execute an API operation on a connector").a
|
|
|
8542
8569
|
}
|
|
8543
8570
|
process.exit(result.exitCode);
|
|
8544
8571
|
});
|
|
8572
|
+
program2.command("setup").argument("<name>", "Connector name to set up").option("-k, --key <value>", "API key or bearer token value").option("-f, --field <field>", "Which field to set (for multi-field connectors)").option("-o, --overwrite", "Overwrite existing installation", false).option("--json", "Output as JSON", false).description("Install, configure auth, and verify a connector in one step").action(async (name, options) => {
|
|
8573
|
+
const meta = getConnector(name);
|
|
8574
|
+
if (!meta) {
|
|
8575
|
+
if (options.json) {
|
|
8576
|
+
console.log(JSON.stringify({ error: `Connector '${name}' not found` }));
|
|
8577
|
+
} else {
|
|
8578
|
+
console.log(chalk2.red(`Connector '${name}' not found`));
|
|
8579
|
+
}
|
|
8580
|
+
process.exit(1);
|
|
8581
|
+
return;
|
|
8582
|
+
}
|
|
8583
|
+
if (!options.json) {
|
|
8584
|
+
console.log(chalk2.bold(`
|
|
8585
|
+
Setting up ${meta.displayName}...
|
|
8586
|
+
`));
|
|
8587
|
+
}
|
|
8588
|
+
const installed = getInstalledConnectors();
|
|
8589
|
+
const alreadyInstalled = installed.includes(meta.name);
|
|
8590
|
+
let installResult;
|
|
8591
|
+
if (alreadyInstalled && !options.overwrite) {
|
|
8592
|
+
installResult = { success: true, path: join6(process.cwd(), ".connectors", `connect-${meta.name}`) };
|
|
8593
|
+
if (!options.json) {
|
|
8594
|
+
console.log(` ${chalk2.green("\u2713")} Already installed`);
|
|
8595
|
+
}
|
|
8596
|
+
} else {
|
|
8597
|
+
const result = installConnector(name, { overwrite: options.overwrite });
|
|
8598
|
+
installResult = { success: result.success, path: result.path, error: result.error };
|
|
8599
|
+
if (!options.json) {
|
|
8600
|
+
if (result.success) {
|
|
8601
|
+
console.log(` ${chalk2.green("\u2713")} Installed \u2192 ${chalk2.dim(result.path)}`);
|
|
8602
|
+
} else {
|
|
8603
|
+
console.log(` ${chalk2.red("\u2717")} Install failed: ${result.error}`);
|
|
8604
|
+
process.exit(1);
|
|
8605
|
+
return;
|
|
8606
|
+
}
|
|
8607
|
+
} else if (!result.success) {
|
|
8608
|
+
console.log(JSON.stringify({ error: `Install failed: ${result.error}` }));
|
|
8609
|
+
process.exit(1);
|
|
8610
|
+
return;
|
|
8611
|
+
}
|
|
8612
|
+
}
|
|
8613
|
+
const authType = getAuthType(name);
|
|
8614
|
+
let authConfigured = false;
|
|
8615
|
+
if (authType === "oauth") {
|
|
8616
|
+
if (options.key) {
|
|
8617
|
+
saveApiKey(name, options.key, options.field || undefined);
|
|
8618
|
+
authConfigured = true;
|
|
8619
|
+
if (!options.json) {
|
|
8620
|
+
console.log(` ${chalk2.green("\u2713")} Token saved`);
|
|
8621
|
+
}
|
|
8622
|
+
} else {
|
|
8623
|
+
const statusBefore = getAuthStatus(name);
|
|
8624
|
+
if (statusBefore.configured) {
|
|
8625
|
+
authConfigured = true;
|
|
8626
|
+
if (!options.json) {
|
|
8627
|
+
console.log(` ${chalk2.green("\u2713")} OAuth already configured`);
|
|
8628
|
+
}
|
|
8629
|
+
} else {
|
|
8630
|
+
if (options.json) {
|
|
8631
|
+
const summary = {
|
|
8632
|
+
connector: name,
|
|
8633
|
+
displayName: meta.displayName,
|
|
8634
|
+
installed: installResult.success,
|
|
8635
|
+
path: installResult.path,
|
|
8636
|
+
authType: "oauth",
|
|
8637
|
+
authConfigured: false,
|
|
8638
|
+
message: "OAuth requires browser-based authentication. Use 'connectors serve' or pass --key to set tokens manually."
|
|
8639
|
+
};
|
|
8640
|
+
console.log(JSON.stringify(summary, null, 2));
|
|
8641
|
+
process.exit(0);
|
|
8642
|
+
return;
|
|
8643
|
+
}
|
|
8644
|
+
console.log(` ${chalk2.yellow("\u27F3")} OAuth authentication required \u2014 starting server...`);
|
|
8645
|
+
try {
|
|
8646
|
+
const port = 19426;
|
|
8647
|
+
const { startServer: startServer2 } = await Promise.resolve().then(() => (init_serve(), exports_serve));
|
|
8648
|
+
await startServer2(port, { open: false });
|
|
8649
|
+
const oauthUrl = `http://localhost:${port}/oauth/${name}/start`;
|
|
8650
|
+
console.log(`
|
|
8651
|
+
${chalk2.bold("Open this URL to authenticate:")}`);
|
|
8652
|
+
console.log(` ${chalk2.cyan(oauthUrl)}
|
|
8653
|
+
`);
|
|
8654
|
+
try {
|
|
8655
|
+
const { exec } = await import("child_process");
|
|
8656
|
+
const openCmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
|
|
8657
|
+
exec(`${openCmd} "${oauthUrl}"`);
|
|
8658
|
+
console.log(chalk2.dim(` Browser opened. Complete the OAuth flow, then press Ctrl+C.
|
|
8659
|
+
`));
|
|
8660
|
+
} catch {
|
|
8661
|
+
console.log(chalk2.dim(` Open the URL above in your browser.
|
|
8662
|
+
`));
|
|
8663
|
+
}
|
|
8664
|
+
await new Promise(() => {});
|
|
8665
|
+
} catch (err) {
|
|
8666
|
+
console.log(` ${chalk2.red("\u2717")} OAuth flow failed: ${err}`);
|
|
8667
|
+
console.log(chalk2.dim(" Try 'connectors serve' to use the full dashboard."));
|
|
8668
|
+
}
|
|
8669
|
+
process.exit(0);
|
|
8670
|
+
return;
|
|
8671
|
+
}
|
|
8672
|
+
}
|
|
8673
|
+
} else {
|
|
8674
|
+
if (options.key) {
|
|
8675
|
+
saveApiKey(name, options.key, options.field || undefined);
|
|
8676
|
+
authConfigured = true;
|
|
8677
|
+
if (!options.json) {
|
|
8678
|
+
console.log(` ${chalk2.green("\u2713")} ${authType === "bearer" ? "Bearer token" : "API key"} saved`);
|
|
8679
|
+
}
|
|
8680
|
+
} else {
|
|
8681
|
+
const statusBefore = getAuthStatus(name);
|
|
8682
|
+
if (statusBefore.configured) {
|
|
8683
|
+
authConfigured = true;
|
|
8684
|
+
if (!options.json) {
|
|
8685
|
+
console.log(` ${chalk2.green("\u2713")} Auth already configured (${authType === "bearer" ? "bearer token" : "API key"})`);
|
|
8686
|
+
}
|
|
8687
|
+
} else {
|
|
8688
|
+
if (!options.json) {
|
|
8689
|
+
console.log(` ${chalk2.yellow("\u26A0")} No API key provided. Use --key <value> to configure auth.`);
|
|
8690
|
+
}
|
|
8691
|
+
}
|
|
8692
|
+
}
|
|
8693
|
+
}
|
|
8694
|
+
const finalStatus = getAuthStatus(name);
|
|
8695
|
+
if (options.json) {
|
|
8696
|
+
const summary = {
|
|
8697
|
+
connector: name,
|
|
8698
|
+
displayName: meta.displayName,
|
|
8699
|
+
installed: installResult.success,
|
|
8700
|
+
path: installResult.path,
|
|
8701
|
+
authType: finalStatus.type,
|
|
8702
|
+
authConfigured: finalStatus.configured,
|
|
8703
|
+
envVars: finalStatus.envVars,
|
|
8704
|
+
tokenExpiry: finalStatus.tokenExpiry
|
|
8705
|
+
};
|
|
8706
|
+
console.log(JSON.stringify(summary, null, 2));
|
|
8707
|
+
} else {
|
|
8708
|
+
console.log();
|
|
8709
|
+
console.log(chalk2.bold(" Summary"));
|
|
8710
|
+
console.log(` \u251C\u2500 Connector: ${meta.displayName}`);
|
|
8711
|
+
console.log(` \u251C\u2500 Installed: ${chalk2.green("yes")}`);
|
|
8712
|
+
console.log(` \u251C\u2500 Auth type: ${finalStatus.type === "oauth" ? "OAuth" : finalStatus.type === "apikey" ? "API Key" : "Bearer Token"}`);
|
|
8713
|
+
console.log(` \u2514\u2500 Auth: ${finalStatus.configured ? chalk2.green("configured") : chalk2.red("not configured")}`);
|
|
8714
|
+
console.log();
|
|
8715
|
+
}
|
|
8716
|
+
process.exit(0);
|
|
8717
|
+
});
|
|
8545
8718
|
program2.parse();
|
package/bin/mcp.js
CHANGED
|
@@ -20315,7 +20315,7 @@ async function getConnectorCommandHelp(name, command) {
|
|
|
20315
20315
|
loadConnectorVersions();
|
|
20316
20316
|
var server = new McpServer({
|
|
20317
20317
|
name: "connectors",
|
|
20318
|
-
version: "0.3.
|
|
20318
|
+
version: "0.3.15"
|
|
20319
20319
|
});
|
|
20320
20320
|
server.registerTool("search_connectors", {
|
|
20321
20321
|
title: "Search Connectors",
|
|
@@ -20671,6 +20671,86 @@ ${result.stderr}`;
|
|
|
20671
20671
|
]
|
|
20672
20672
|
};
|
|
20673
20673
|
});
|
|
20674
|
+
server.registerTool("setup_connector", {
|
|
20675
|
+
title: "Setup Connector",
|
|
20676
|
+
description: "Install a connector and configure auth in one step. Installs if not already present, saves API key if provided, and returns install + auth status.",
|
|
20677
|
+
inputSchema: {
|
|
20678
|
+
name: exports_external.string().describe("Connector name (e.g. stripe, gmail, anthropic)"),
|
|
20679
|
+
key: exports_external.string().optional().describe("API key or bearer token to save"),
|
|
20680
|
+
field: exports_external.string().optional().describe("Which field to save the key as (for multi-field connectors)"),
|
|
20681
|
+
overwrite: exports_external.boolean().optional().describe("Overwrite existing installation (default: false)")
|
|
20682
|
+
}
|
|
20683
|
+
}, async ({ name, key, field, overwrite }) => {
|
|
20684
|
+
const meta = getConnector(name);
|
|
20685
|
+
if (!meta) {
|
|
20686
|
+
return {
|
|
20687
|
+
content: [{ type: "text", text: `Connector '${name}' not found.` }],
|
|
20688
|
+
isError: true
|
|
20689
|
+
};
|
|
20690
|
+
}
|
|
20691
|
+
const installed = getInstalledConnectors();
|
|
20692
|
+
const alreadyInstalled = installed.includes(meta.name);
|
|
20693
|
+
let installStatus;
|
|
20694
|
+
if (alreadyInstalled && !overwrite) {
|
|
20695
|
+
installStatus = { installed: true, path: `.connectors/connect-${meta.name}` };
|
|
20696
|
+
} else {
|
|
20697
|
+
const result = installConnector(name, { overwrite: overwrite ?? false });
|
|
20698
|
+
if (!result.success) {
|
|
20699
|
+
return {
|
|
20700
|
+
content: [
|
|
20701
|
+
{
|
|
20702
|
+
type: "text",
|
|
20703
|
+
text: JSON.stringify({
|
|
20704
|
+
connector: name,
|
|
20705
|
+
installed: false,
|
|
20706
|
+
error: result.error
|
|
20707
|
+
}, null, 2)
|
|
20708
|
+
}
|
|
20709
|
+
],
|
|
20710
|
+
isError: true
|
|
20711
|
+
};
|
|
20712
|
+
}
|
|
20713
|
+
installStatus = { installed: true, path: result.path };
|
|
20714
|
+
}
|
|
20715
|
+
if (key) {
|
|
20716
|
+
try {
|
|
20717
|
+
saveApiKey(name, key, field);
|
|
20718
|
+
} catch (error2) {
|
|
20719
|
+
return {
|
|
20720
|
+
content: [
|
|
20721
|
+
{
|
|
20722
|
+
type: "text",
|
|
20723
|
+
text: JSON.stringify({
|
|
20724
|
+
connector: name,
|
|
20725
|
+
installed: installStatus.installed,
|
|
20726
|
+
path: installStatus.path,
|
|
20727
|
+
authError: error2 instanceof Error ? error2.message : String(error2)
|
|
20728
|
+
}, null, 2)
|
|
20729
|
+
}
|
|
20730
|
+
],
|
|
20731
|
+
isError: true
|
|
20732
|
+
};
|
|
20733
|
+
}
|
|
20734
|
+
}
|
|
20735
|
+
const authStatus = getAuthStatus(name);
|
|
20736
|
+
return {
|
|
20737
|
+
content: [
|
|
20738
|
+
{
|
|
20739
|
+
type: "text",
|
|
20740
|
+
text: JSON.stringify({
|
|
20741
|
+
connector: name,
|
|
20742
|
+
displayName: meta.displayName,
|
|
20743
|
+
installed: installStatus.installed,
|
|
20744
|
+
path: installStatus.path,
|
|
20745
|
+
authType: authStatus.type,
|
|
20746
|
+
authConfigured: authStatus.configured,
|
|
20747
|
+
tokenExpiry: authStatus.tokenExpiry,
|
|
20748
|
+
envVars: authStatus.envVars
|
|
20749
|
+
}, null, 2)
|
|
20750
|
+
}
|
|
20751
|
+
]
|
|
20752
|
+
};
|
|
20753
|
+
});
|
|
20674
20754
|
server.registerTool("search_tools", {
|
|
20675
20755
|
title: "Search Tools",
|
|
20676
20756
|
description: "List tool names, optionally filtered by keyword.",
|
|
@@ -20686,6 +20766,7 @@ server.registerTool("search_tools", {
|
|
|
20686
20766
|
"connector_info",
|
|
20687
20767
|
"connector_auth_status",
|
|
20688
20768
|
"configure_auth",
|
|
20769
|
+
"setup_connector",
|
|
20689
20770
|
"list_categories",
|
|
20690
20771
|
"list_connector_operations",
|
|
20691
20772
|
"run_connector_operation",
|
|
@@ -20710,6 +20791,7 @@ server.registerTool("describe_tools", {
|
|
|
20710
20791
|
connector_info: "Get metadata and install status. Params: name",
|
|
20711
20792
|
connector_auth_status: "Check auth status and env vars. Params: name",
|
|
20712
20793
|
configure_auth: "Save API key or token. Params: name, key, field?",
|
|
20794
|
+
setup_connector: "Install + configure auth + verify in one call. Params: name, key?, field?, overwrite?",
|
|
20713
20795
|
list_categories: "List connector categories with counts.",
|
|
20714
20796
|
list_connector_operations: "Discover available API operations for a connector. Params: name, command?",
|
|
20715
20797
|
run_connector_operation: "Execute an API operation on a connector. Params: name, args[], format?, timeout?"
|
|
@@ -77,10 +77,10 @@ export function setCurrentProfile(profile: string): void {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
* Check if a profile exists
|
|
80
|
+
* Check if a profile exists (flat file or directory pattern)
|
|
81
81
|
*/
|
|
82
82
|
export function profileExists(profile: string): boolean {
|
|
83
|
-
return existsSync(getProfilePath(profile));
|
|
83
|
+
return existsSync(getProfilePath(profile)) || existsSync(join(PROFILES_DIR, profile));
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
/**
|
|
@@ -93,10 +93,16 @@ export function listProfiles(): string[] {
|
|
|
93
93
|
return [];
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
.
|
|
96
|
+
const seen = new Set<string>();
|
|
97
|
+
const entries = readdirSync(PROFILES_DIR, { withFileTypes: true });
|
|
98
|
+
for (const entry of entries) {
|
|
99
|
+
if (entry.isDirectory()) {
|
|
100
|
+
seen.add(entry.name);
|
|
101
|
+
} else if (entry.name.endsWith('.json')) {
|
|
102
|
+
seen.add(entry.name.replace('.json', ''));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return Array.from(seen).sort();
|
|
100
106
|
}
|
|
101
107
|
|
|
102
108
|
/**
|
|
@@ -135,27 +141,53 @@ export function deleteProfile(profile: string): boolean {
|
|
|
135
141
|
setCurrentProfile(DEFAULT_PROFILE);
|
|
136
142
|
}
|
|
137
143
|
|
|
138
|
-
|
|
144
|
+
// Remove flat file pattern
|
|
145
|
+
const flatPath = getProfilePath(profile);
|
|
146
|
+
if (existsSync(flatPath)) {
|
|
147
|
+
rmSync(flatPath);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Remove directory pattern
|
|
151
|
+
const dirPath = join(PROFILES_DIR, profile);
|
|
152
|
+
if (existsSync(dirPath)) {
|
|
153
|
+
rmSync(dirPath, { recursive: true });
|
|
154
|
+
}
|
|
155
|
+
|
|
139
156
|
return true;
|
|
140
157
|
}
|
|
141
158
|
|
|
142
159
|
/**
|
|
143
|
-
* Load profile config
|
|
160
|
+
* Load profile config.
|
|
161
|
+
* Checks both flat (profiles/<name>.json) and directory (profiles/<name>/config.json)
|
|
162
|
+
* patterns. Flat pattern takes precedence when both exist.
|
|
144
163
|
*/
|
|
145
164
|
export function loadProfile(profile?: string): ProfileConfig {
|
|
146
165
|
ensureConfigDir();
|
|
147
166
|
const profileName = profile || getCurrentProfile();
|
|
148
|
-
const profilePath = getProfilePath(profileName);
|
|
149
167
|
|
|
150
|
-
|
|
151
|
-
|
|
168
|
+
let config: ProfileConfig = {};
|
|
169
|
+
|
|
170
|
+
// Pattern 2: profiles/<name>/config.json (directory pattern, used by dashboard)
|
|
171
|
+
const dirConfigPath = join(PROFILES_DIR, profileName, 'config.json');
|
|
172
|
+
if (existsSync(dirConfigPath)) {
|
|
173
|
+
try {
|
|
174
|
+
config = JSON.parse(readFileSync(dirConfigPath, 'utf-8'));
|
|
175
|
+
} catch {
|
|
176
|
+
// ignore
|
|
177
|
+
}
|
|
152
178
|
}
|
|
153
179
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
180
|
+
// Pattern 1: profiles/<name>.json (flat pattern, used by CLI)
|
|
181
|
+
const profilePath = getProfilePath(profileName);
|
|
182
|
+
if (existsSync(profilePath)) {
|
|
183
|
+
try {
|
|
184
|
+
config = { ...config, ...JSON.parse(readFileSync(profilePath, 'utf-8')) };
|
|
185
|
+
} catch {
|
|
186
|
+
// ignore
|
|
187
|
+
}
|
|
158
188
|
}
|
|
189
|
+
|
|
190
|
+
return config;
|
|
159
191
|
}
|
|
160
192
|
|
|
161
193
|
/**
|