@solvapay/init 0.4.5 → 0.4.6

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.cjs CHANGED
@@ -313,6 +313,15 @@ var parseEnvValue = (raw) => {
313
313
  };
314
314
  var normalizeTrailingNewline = (content) => content.endsWith("\n") ? content : `${content}
315
315
  `;
316
+ var confirmOverwriteOrExit = async () => {
317
+ if (!import_node_process.stdin.isTTY) {
318
+ console.error(
319
+ "SOLVAPAY_SECRET_KEY already set in .env; re-run with --yes to overwrite"
320
+ );
321
+ process.exit(1);
322
+ }
323
+ return askOverwrite();
324
+ };
316
325
  var askOverwrite = async () => {
317
326
  const rl = import_promises2.default.createInterface({ input: import_node_process.stdin, output: import_node_process.stdout });
318
327
  try {
@@ -365,7 +374,7 @@ var writeSolvaPaySecretToEnv = async (secretKey, options = {}) => {
365
374
  await (0, import_promises.writeFile)(envPath, next, "utf8");
366
375
  return { filePath: envPath, action: "appended" };
367
376
  }
368
- const shouldOverwrite = options.confirmOverwrite ? await options.confirmOverwrite() : await askOverwrite();
377
+ const shouldOverwrite = options.confirmOverwrite ? await options.confirmOverwrite() : await confirmOverwriteOrExit();
369
378
  if (!shouldOverwrite) {
370
379
  return { filePath: envPath, action: "unchanged" };
371
380
  }
@@ -726,7 +735,7 @@ var pickProductInteractive = async (apiBaseUrl, secretKey, options) => {
726
735
  const nonInteractive = options.yes || !process.stdin.isTTY || !process.stdout.isTTY;
727
736
  if (nonInteractive) {
728
737
  process.stdout.write(
729
- "Skipped product auto-selection in non-interactive mode. Set SOLVAPAY_PRODUCT_REF in .env or pass --product <prd_...> when you are ready.\n"
738
+ "Skipped product auto-selection in non-interactive mode. Set SOLVAPAY_PRODUCT_REF in .env or pass --product <prd_...> when you are ready. .env still has the placeholder and deploy will fail until it is set.\n"
730
739
  );
731
740
  return { action: "skipped", reason: "non_interactive_requires_product" };
732
741
  }
@@ -1091,7 +1100,21 @@ var runInitInDirectory = async ({
1091
1100
  `
1092
1101
  );
1093
1102
  }
1094
- const envWrite = await writeSolvaPaySecretToEnv(exchange.secretKey, { cwd });
1103
+ if (exchange.environment === "live") {
1104
+ process.stdout.write(
1105
+ [
1106
+ "",
1107
+ "\u26A0\uFE0F LIVE key. Real charges apply.",
1108
+ " Init follows the environment currently selected in the SolvaPay Console.",
1109
+ " Switch the Console to sandbox and re-run `npx solvapay init` if that was not intended.",
1110
+ ""
1111
+ ].join("\n")
1112
+ );
1113
+ }
1114
+ const envWrite = await writeSolvaPaySecretToEnv(exchange.secretKey, {
1115
+ cwd,
1116
+ ...options.yes ? { confirmOverwrite: async () => true } : {}
1117
+ });
1095
1118
  const environmentLabel = exchange.environment ? ` (${exchange.environment})` : "";
1096
1119
  if (envWrite.action === "created" || envWrite.action === "appended" || envWrite.action === "updated") {
1097
1120
  process.stdout.write(`\u{1F4DD} Secret key saved to .env${environmentLabel}
package/dist/index.js CHANGED
@@ -253,6 +253,15 @@ var parseEnvValue = (raw) => {
253
253
  };
254
254
  var normalizeTrailingNewline = (content) => content.endsWith("\n") ? content : `${content}
255
255
  `;
256
+ var confirmOverwriteOrExit = async () => {
257
+ if (!stdin.isTTY) {
258
+ console.error(
259
+ "SOLVAPAY_SECRET_KEY already set in .env; re-run with --yes to overwrite"
260
+ );
261
+ process.exit(1);
262
+ }
263
+ return askOverwrite();
264
+ };
256
265
  var askOverwrite = async () => {
257
266
  const rl = readline.createInterface({ input: stdin, output: stdout });
258
267
  try {
@@ -305,7 +314,7 @@ var writeSolvaPaySecretToEnv = async (secretKey, options = {}) => {
305
314
  await writeFile(envPath, next, "utf8");
306
315
  return { filePath: envPath, action: "appended" };
307
316
  }
308
- const shouldOverwrite = options.confirmOverwrite ? await options.confirmOverwrite() : await askOverwrite();
317
+ const shouldOverwrite = options.confirmOverwrite ? await options.confirmOverwrite() : await confirmOverwriteOrExit();
309
318
  if (!shouldOverwrite) {
310
319
  return { filePath: envPath, action: "unchanged" };
311
320
  }
@@ -666,7 +675,7 @@ var pickProductInteractive = async (apiBaseUrl, secretKey, options) => {
666
675
  const nonInteractive = options.yes || !process.stdin.isTTY || !process.stdout.isTTY;
667
676
  if (nonInteractive) {
668
677
  process.stdout.write(
669
- "Skipped product auto-selection in non-interactive mode. Set SOLVAPAY_PRODUCT_REF in .env or pass --product <prd_...> when you are ready.\n"
678
+ "Skipped product auto-selection in non-interactive mode. Set SOLVAPAY_PRODUCT_REF in .env or pass --product <prd_...> when you are ready. .env still has the placeholder and deploy will fail until it is set.\n"
670
679
  );
671
680
  return { action: "skipped", reason: "non_interactive_requires_product" };
672
681
  }
@@ -1031,7 +1040,21 @@ var runInitInDirectory = async ({
1031
1040
  `
1032
1041
  );
1033
1042
  }
1034
- const envWrite = await writeSolvaPaySecretToEnv(exchange.secretKey, { cwd });
1043
+ if (exchange.environment === "live") {
1044
+ process.stdout.write(
1045
+ [
1046
+ "",
1047
+ "\u26A0\uFE0F LIVE key. Real charges apply.",
1048
+ " Init follows the environment currently selected in the SolvaPay Console.",
1049
+ " Switch the Console to sandbox and re-run `npx solvapay init` if that was not intended.",
1050
+ ""
1051
+ ].join("\n")
1052
+ );
1053
+ }
1054
+ const envWrite = await writeSolvaPaySecretToEnv(exchange.secretKey, {
1055
+ cwd,
1056
+ ...options.yes ? { confirmOverwrite: async () => true } : {}
1057
+ });
1035
1058
  const environmentLabel = exchange.environment ? ` (${exchange.environment})` : "";
1036
1059
  if (envWrite.action === "created" || envWrite.action === "appended" || envWrite.action === "updated") {
1037
1060
  process.stdout.write(`\u{1F4DD} Secret key saved to .env${environmentLabel}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solvapay/init",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "description": "Shared primitives for SolvaPay CLI tooling (browser auth, env writers, product picker, install runner). Consumed by `solvapay` and `create-solvapay`.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",