learn-secrets-sdk 1.6.8 → 1.6.9
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/cli/index.mjs +92 -7
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
|
@@ -1045,19 +1045,104 @@ Configuration saved to: ${configFile}`);
|
|
|
1045
1045
|
|
|
1046
1046
|
// src/cli/commands/deploy.ts
|
|
1047
1047
|
import fs5 from "fs";
|
|
1048
|
-
async function deployCommand() {
|
|
1048
|
+
async function deployCommand(options = {}) {
|
|
1049
|
+
if (!hasValidCredentials()) {
|
|
1050
|
+
console.error('Error: Not authenticated. Run "learn-secrets login" first.');
|
|
1051
|
+
process.exit(1);
|
|
1052
|
+
}
|
|
1049
1053
|
const configFile = "secrets-config.json";
|
|
1050
1054
|
if (!fs5.existsSync(configFile)) {
|
|
1051
|
-
console.error("
|
|
1052
|
-
|
|
1055
|
+
console.error("Error: Configuration file not found.");
|
|
1056
|
+
console.error('Run "learn-secrets init" first to create config.');
|
|
1057
|
+
process.exit(1);
|
|
1053
1058
|
}
|
|
1054
1059
|
const config = JSON.parse(fs5.readFileSync(configFile, "utf8"));
|
|
1055
|
-
|
|
1060
|
+
if (!config.project) {
|
|
1061
|
+
console.error("Error: No project ID in config.");
|
|
1062
|
+
console.error('Run "learn-secrets config --project <appid>" to set project.');
|
|
1063
|
+
process.exit(1);
|
|
1064
|
+
}
|
|
1065
|
+
if (!config.origins || config.origins.length === 0) {
|
|
1066
|
+
console.error("Error: No origins in config.");
|
|
1067
|
+
console.error('Run "learn-secrets config --origins domain1.com,domain2.com" to set origins.');
|
|
1068
|
+
process.exit(1);
|
|
1069
|
+
}
|
|
1070
|
+
console.log(`
|
|
1071
|
+
Deploying secrets to project: ${config.project}`);
|
|
1072
|
+
console.log(`Origins: ${config.origins.join(", ")}
|
|
1073
|
+
`);
|
|
1074
|
+
const envFile = options.env || ".env";
|
|
1075
|
+
let secrets;
|
|
1076
|
+
try {
|
|
1077
|
+
console.log(`Reading ${envFile}...`);
|
|
1078
|
+
const envVars = parseEnvFile(envFile);
|
|
1079
|
+
secrets = detectApiKeys(envVars);
|
|
1080
|
+
if (secrets.length === 0) {
|
|
1081
|
+
console.log("\nNo API keys detected in .env file.");
|
|
1082
|
+
console.log("Make sure your .env contains variables like:");
|
|
1083
|
+
console.log(" OPENAI_API_KEY=sk-...");
|
|
1084
|
+
console.log(" ANTHROPIC_API_KEY=sk-ant-...");
|
|
1085
|
+
process.exit(0);
|
|
1086
|
+
}
|
|
1087
|
+
console.log("\n" + summarizeDetectedSecrets(secrets));
|
|
1088
|
+
console.log("");
|
|
1089
|
+
} catch (error) {
|
|
1090
|
+
console.error(`Error reading ${envFile}:`, error.message);
|
|
1091
|
+
process.exit(1);
|
|
1092
|
+
}
|
|
1093
|
+
if (!options.yes) {
|
|
1094
|
+
const readline = await import("readline");
|
|
1095
|
+
const rl = readline.createInterface({
|
|
1096
|
+
input: process.stdin,
|
|
1097
|
+
output: process.stdout
|
|
1098
|
+
});
|
|
1099
|
+
const answer = await new Promise((resolve2) => {
|
|
1100
|
+
rl.question("Deploy these secrets? (y/N): ", resolve2);
|
|
1101
|
+
});
|
|
1102
|
+
rl.close();
|
|
1103
|
+
if (answer.toLowerCase() !== "y" && answer.toLowerCase() !== "yes") {
|
|
1104
|
+
console.log("Cancelled.");
|
|
1105
|
+
process.exit(0);
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
console.log("\nUploading secrets...");
|
|
1109
|
+
const mgmt = new SecretsManagement({
|
|
1110
|
+
appId: config.project,
|
|
1111
|
+
baseUrl: options.baseUrl
|
|
1112
|
+
});
|
|
1113
|
+
try {
|
|
1114
|
+
const result = await mgmt.importSecrets({
|
|
1115
|
+
version: "1.0",
|
|
1116
|
+
origins: config.origins,
|
|
1117
|
+
secrets
|
|
1118
|
+
});
|
|
1119
|
+
console.log("\nSuccess!");
|
|
1120
|
+
console.log(` Created: ${result.results.created} secrets`);
|
|
1121
|
+
console.log(` Updated: ${result.results.updated} secrets`);
|
|
1122
|
+
if (result.results.failed > 0) {
|
|
1123
|
+
console.log(` Failed: ${result.results.failed} secrets`);
|
|
1124
|
+
for (const failure of result.results.details.failed) {
|
|
1125
|
+
console.log(` - ${failure.name}: ${failure.error}`);
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
const dashboardUrl = options.baseUrl || "https://cloudprototype.org";
|
|
1129
|
+
console.log(`
|
|
1130
|
+
Secrets deployed! View them at: ${dashboardUrl}/dashboard/secrets/api_keys`);
|
|
1131
|
+
} catch (error) {
|
|
1132
|
+
console.error("\nDeploy failed:", error.message);
|
|
1133
|
+
if (error.status === 401) {
|
|
1134
|
+
console.error('Your session may have expired. Try running "learn-secrets login" again.');
|
|
1135
|
+
}
|
|
1136
|
+
if (error.status === 404) {
|
|
1137
|
+
console.error(`Project "${config.project}" not found. Check your project ID.`);
|
|
1138
|
+
}
|
|
1139
|
+
process.exit(1);
|
|
1140
|
+
}
|
|
1056
1141
|
}
|
|
1057
1142
|
|
|
1058
1143
|
// src/cli/index.ts
|
|
1059
1144
|
var program = new Command();
|
|
1060
|
-
program.name("learn-secrets").description("CLI tool for managing API secrets in static sites").version("1.6.
|
|
1145
|
+
program.name("learn-secrets").description("CLI tool for managing API secrets in static sites").version("1.6.9");
|
|
1061
1146
|
program.command("setup").description("Complete setup: create project, generate token, upload secrets").requiredOption("-e, --email <email>", "Your Learn account email").requiredOption("-p, --password <password>", "Your Learn account password").requiredOption("-o, --origin <domain>", "Your site origin (e.g., mysite.com)").option("--project-name <name>", 'Project name (default: "Project - <origin>")').option("--env <file>", "Path to .env file (default: .env)", ".env").option("--base-url <url>", "Custom base URL for API").option("-y, --yes", "Skip confirmation prompt").action(async (options) => {
|
|
1062
1147
|
await setupCommand(options);
|
|
1063
1148
|
});
|
|
@@ -1070,8 +1155,8 @@ program.command("init").description("Initialize secrets for a new site").require
|
|
|
1070
1155
|
program.command("config").description("View or update project configuration").option("-p, --project <appid>", "Change project ID").option("--origins <origins>", "Comma separated origins").action(async (options) => {
|
|
1071
1156
|
await configCommand(options);
|
|
1072
1157
|
});
|
|
1073
|
-
program.command("deploy").description("Deploy secrets
|
|
1074
|
-
await deployCommand();
|
|
1158
|
+
program.command("deploy").description("Deploy secrets from .env to dashboard").option("-e, --env <file>", "Path to .env file (default: .env)", ".env").option("--base-url <url>", "Custom base URL for API").option("-y, --yes", "Skip confirmation prompt").action(async (options) => {
|
|
1159
|
+
await deployCommand(options);
|
|
1075
1160
|
});
|
|
1076
1161
|
program.parse(process.argv);
|
|
1077
1162
|
if (!process.argv.slice(2).length) {
|