learn-secrets-sdk 1.6.7 → 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.
Files changed (2) hide show
  1. package/dist/cli/index.mjs +121 -13
  2. package/package.json +1 -1
@@ -1009,32 +1009,140 @@ import fs4 from "fs";
1009
1009
  async function configCommand(options) {
1010
1010
  const configFile = "secrets-config.json";
1011
1011
  if (!fs4.existsSync(configFile)) {
1012
- console.error("Run learn-secrets init first to generate config.");
1013
- return;
1012
+ console.error("Error: Configuration file not found.");
1013
+ console.error('Run "learn-secrets login" first to create config.');
1014
+ process.exit(1);
1014
1015
  }
1015
1016
  const config = JSON.parse(fs4.readFileSync(configFile, "utf8"));
1017
+ if (!options.project && !options.origins) {
1018
+ console.log("\nCurrent configuration:");
1019
+ console.log(` Project ID: ${config.project || "(not set)"}`);
1020
+ console.log(` Origins: ${config.origins?.length > 0 ? config.origins.join(", ") : "(not set)"}`);
1021
+ console.log(`
1022
+ Config file: ${configFile}`);
1023
+ console.log("\nTo update:");
1024
+ console.log(" learn-secrets config --project <appid>");
1025
+ console.log(" learn-secrets config --origins domain1.com,domain2.com");
1026
+ return;
1027
+ }
1028
+ let updated = false;
1029
+ if (options.project) {
1030
+ config.project = options.project;
1031
+ console.log(`Updated project ID: ${options.project}`);
1032
+ updated = true;
1033
+ }
1016
1034
  if (options.origins) {
1017
- config.origins = options.origins.split(",").map((o) => o.trim());
1018
- console.log("Updated origins:", config.origins);
1035
+ config.origins = options.origins.split(",").map((o) => o.trim()).filter(Boolean);
1036
+ console.log(`Updated origins: ${config.origins.join(", ")}`);
1037
+ updated = true;
1038
+ }
1039
+ if (updated) {
1040
+ fs4.writeFileSync(configFile, JSON.stringify(config, null, 2));
1041
+ console.log(`
1042
+ Configuration saved to: ${configFile}`);
1019
1043
  }
1020
- fs4.writeFileSync(configFile, JSON.stringify(config, null, 2));
1021
1044
  }
1022
1045
 
1023
1046
  // src/cli/commands/deploy.ts
1024
1047
  import fs5 from "fs";
1025
- 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
+ }
1026
1053
  const configFile = "secrets-config.json";
1027
1054
  if (!fs5.existsSync(configFile)) {
1028
- console.error("No config found.");
1029
- return;
1055
+ console.error("Error: Configuration file not found.");
1056
+ console.error('Run "learn-secrets init" first to create config.');
1057
+ process.exit(1);
1030
1058
  }
1031
1059
  const config = JSON.parse(fs5.readFileSync(configFile, "utf8"));
1032
- console.log("Deploying secrets config to backend:", config);
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
+ }
1033
1141
  }
1034
1142
 
1035
1143
  // src/cli/index.ts
1036
1144
  var program = new Command();
1037
- program.name("learn-secrets").description("CLI tool for managing API secrets in static sites").version("1.6.0");
1145
+ program.name("learn-secrets").description("CLI tool for managing API secrets in static sites").version("1.6.9");
1038
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) => {
1039
1147
  await setupCommand(options);
1040
1148
  });
@@ -1044,11 +1152,11 @@ program.command("login").description("Authenticate with Learn Secrets via browse
1044
1152
  program.command("init").description("Initialize secrets for a new site").requiredOption("-o, --origins <domains>", "Comma-separated list of allowed origins (e.g., mysite.com,localhost)").option("-p, --project <appid>", "Project app ID (auto-detected from login if not specified)").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) => {
1045
1153
  await initCommand(options);
1046
1154
  });
1047
- program.command("config").description("Configure allowed origins").option("--origins <origins>", "Comma separated origins").action(async (options) => {
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) => {
1048
1156
  await configCommand(options);
1049
1157
  });
1050
- program.command("deploy").description("Deploy secrets config live").action(async () => {
1051
- 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);
1052
1160
  });
1053
1161
  program.parse(process.argv);
1054
1162
  if (!process.argv.slice(2).length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "learn-secrets-sdk",
3
- "version": "1.6.7",
3
+ "version": "1.6.9",
4
4
  "description": "Secure API proxy SDK for static sites with domain-scoped tokens",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",