@mp-lb/doctrine-secrets 0.0.0 → 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ export type ParsedCliArgs = {
2
+ command: string | null;
3
+ filePath: string | null;
4
+ help: boolean;
5
+ secret: string | null;
6
+ };
7
+ export declare const parseCliArgs: (args: string[]) => ParsedCliArgs;
@@ -0,0 +1,34 @@
1
+ export const parseCliArgs = (args) => {
2
+ const parsed = {
3
+ command: null,
4
+ filePath: null,
5
+ help: false,
6
+ secret: null,
7
+ };
8
+ for (let index = 0; index < args.length; index += 1) {
9
+ const arg = args[index];
10
+ if (arg === "--help" || arg === "-h") {
11
+ parsed.help = true;
12
+ continue;
13
+ }
14
+ if (arg === "--secret") {
15
+ parsed.secret = args[index + 1] ?? null;
16
+ index += 1;
17
+ continue;
18
+ }
19
+ if (arg.startsWith("--secret=")) {
20
+ parsed.secret = arg.slice("--secret=".length);
21
+ continue;
22
+ }
23
+ if (!parsed.command) {
24
+ parsed.command = arg;
25
+ continue;
26
+ }
27
+ if (!parsed.filePath) {
28
+ parsed.filePath = arg;
29
+ continue;
30
+ }
31
+ throw new Error(`Unknown argument: ${arg}`);
32
+ }
33
+ return parsed;
34
+ };
@@ -0,0 +1 @@
1
+ export declare const readRecipientSecret: (secretArg: string | null) => string;
@@ -0,0 +1,7 @@
1
+ export const readRecipientSecret = (secretArg) => {
2
+ const recipientSecret = secretArg ?? process.env.DOCTRINE_RECIPIENT_SECRET;
3
+ if (!recipientSecret) {
4
+ throw new Error("Recipient secret is required. Pass --secret or set DOCTRINE_RECIPIENT_SECRET.");
5
+ }
6
+ return recipientSecret;
7
+ };
package/dist/runCli.js CHANGED
@@ -1,19 +1,20 @@
1
1
  import { decryptDoctrineEncryptedFileText } from "./decryptDoctrineEncryptedFileText.js";
2
+ import { parseCliArgs } from "./parseCliArgs.js";
2
3
  import { readEncryptedFile } from "./readEncryptedFile.js";
3
- import { readRecipientSecretFromEnv } from "./readRecipientSecretFromEnv.js";
4
+ import { readRecipientSecret } from "./readRecipientSecret.js";
4
5
  import { usage } from "./usage.js";
5
6
  export const runCli = async (args) => {
6
- const [command, filePath] = args;
7
- if (command === "--help" || command === "-h") {
7
+ const parsed = parseCliArgs(args);
8
+ if (parsed.help) {
8
9
  process.stdout.write(usage);
9
10
  return;
10
11
  }
11
- if (command !== "decrypt" || !filePath) {
12
+ if (parsed.command !== "decrypt" || !parsed.filePath) {
12
13
  throw new Error(usage);
13
14
  }
14
15
  const plaintext = await decryptDoctrineEncryptedFileText({
15
- encryptedText: await readEncryptedFile(filePath),
16
- recipientSecret: readRecipientSecretFromEnv(),
16
+ encryptedText: await readEncryptedFile(parsed.filePath),
17
+ recipientSecret: readRecipientSecret(parsed.secret),
17
18
  });
18
19
  process.stdout.write(plaintext);
19
20
  };
package/dist/usage.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const usage = "Doctrine Secrets\n\nUsage:\n doctrine-secrets decrypt <secrets.enc.json>\n\nEnvironment:\n DOCTRINE_RECIPIENT_SECRET External recipient secret for the encrypted file\n";
1
+ export declare const usage = "Doctrine Secrets\n\nUsage:\n doctrine-secrets decrypt <secrets.enc.json> [--secret <recipient-secret>]\n\nEnvironment:\n DOCTRINE_RECIPIENT_SECRET External recipient secret fallback\n";
package/dist/usage.js CHANGED
@@ -1,8 +1,8 @@
1
1
  export const usage = `Doctrine Secrets
2
2
 
3
3
  Usage:
4
- doctrine-secrets decrypt <secrets.enc.json>
4
+ doctrine-secrets decrypt <secrets.enc.json> [--secret <recipient-secret>]
5
5
 
6
6
  Environment:
7
- DOCTRINE_RECIPIENT_SECRET External recipient secret for the encrypted file
7
+ DOCTRINE_RECIPIENT_SECRET External recipient secret fallback
8
8
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mp-lb/doctrine-secrets",
3
- "version": "0.0.0",
3
+ "version": "0.1.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1 +0,0 @@
1
- export declare const readRecipientSecretFromEnv: () => string;
@@ -1,7 +0,0 @@
1
- export const readRecipientSecretFromEnv = () => {
2
- const recipientSecret = process.env.DOCTRINE_RECIPIENT_SECRET;
3
- if (!recipientSecret) {
4
- throw new Error("DOCTRINE_RECIPIENT_SECRET is required.");
5
- }
6
- return recipientSecret;
7
- };