@secretenvs/cli 1.0.1 → 1.2.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.
Files changed (3) hide show
  1. package/README.md +13 -13
  2. package/dist/index.js +46 -6
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -6,19 +6,19 @@ are bundled into the build, so the packed tarball installs on its own.
6
6
 
7
7
  ## Commands
8
8
 
9
- | Command | What it does |
10
- | -------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
11
- | `secretenvs login [--url <baseUrl>]` | Prompts for email and password (hidden), stores an API token. |
12
- | `secretenvs logout` | Deletes the stored credentials. |
13
- | `secretenvs whoami` | Shows the server, account and token prefix, and checks the token still works. |
14
- | `secretenvs projects` | Lists accessible projects (slug, role, name). |
15
- | `secretenvs envs -p <project>` | Lists the environments of a project. |
16
- | `secretenvs list -p <project> -e <env> [--reveal]` | Lists keys and their source (`env` / `shared`). Values are masked. |
17
- | `secretenvs set KEY=VALUE -p <project> -e <env>` | Creates or updates an environment variable (needs EDITOR). |
18
- | `secretenvs history KEY -p <project> -e <env> [--shared] [--limit]` | Lists versions: number, change, author, time. Values are never shown. |
19
- | `secretenvs rollback KEY --to <n> -p <project> -e <env> [--shared] [--yes]` | Restores version `n` as a **new** version (needs EDITOR). Asks to confirm. |
20
- | `secretenvs pull -p <project> -e <env> [--out .env] [--format dotenv\|json] [--force]` | Writes the resolved variables to a file (mode `0600`). |
21
- | `secretenvs run -p <project> -e <env> -- <command...>` | Runs a command with the variables injected into its environment. |
9
+ | Command | What it does |
10
+ | -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
11
+ | `secretenvs login [--url <baseUrl>]` | Prompts for email and password (hidden), plus a 2FA code if the account has it on; stores an API token. |
12
+ | `secretenvs logout` | Deletes the stored credentials. |
13
+ | `secretenvs whoami` | Shows the server, account and token prefix, and checks the token still works. |
14
+ | `secretenvs projects` | Lists accessible projects (slug, role, name). |
15
+ | `secretenvs envs -p <project>` | Lists the environments of a project. |
16
+ | `secretenvs list -p <project> -e <env> [--reveal]` | Lists keys and their source (`env` / `shared`). Values are masked. |
17
+ | `secretenvs set KEY=VALUE -p <project> -e <env>` | Creates or updates an environment variable (needs EDITOR). |
18
+ | `secretenvs history KEY -p <project> -e <env> [--shared] [--limit]` | Lists versions: number, change, author, time. Values are never shown. |
19
+ | `secretenvs rollback KEY --to <n> -p <project> -e <env> [--shared] [--yes]` | Restores version `n` as a **new** version (needs EDITOR). Asks to confirm. |
20
+ | `secretenvs pull -p <project> -e <env> [--out .env] [--format dotenv\|json] [--force]` | Writes the resolved variables to a file (mode `0600`). |
21
+ | `secretenvs run -p <project> -e <env> -- <command...>` | Runs a command with the variables injected into its environment. |
22
22
 
23
23
  Every command supports `--help`. Failures print a message to stderr and exit
24
24
  with a non-zero code. `run` exits with the code of the command it started.
package/dist/index.js CHANGED
@@ -45,6 +45,7 @@ var MAX_PASSWORD_LENGTH = 256;
45
45
  var MAX_VERSIONS_LIMIT = 100;
46
46
  var CSRF_HEADER_NAME = "x-requested-with";
47
47
  var CSRF_HEADER_VALUE = "secretenvs-web";
48
+ var MAX_AUTH_CODE_LENGTH = 32;
48
49
  var ProjectRole = z.enum(["OWNER", "ADMIN", "EDITOR", "VIEWER"]);
49
50
  var TokenAccess = z.enum(["READ", "READ_WRITE"]);
50
51
  var VersionChangeType = z.enum(["CREATED", "UPDATED", "ROLLBACK"]);
@@ -52,6 +53,7 @@ var ErrorCode = z.enum([
52
53
  "VALIDATION_ERROR",
53
54
  "BAD_REQUEST",
54
55
  "UNAUTHENTICATED",
56
+ "MFA_REQUIRED",
55
57
  "FORBIDDEN",
56
58
  "NOT_FOUND",
57
59
  "CONFLICT",
@@ -72,8 +74,32 @@ var variableValue = z2.string().refine(
72
74
  );
73
75
  var password2 = z2.string().min(MIN_PASSWORD_LENGTH).max(MAX_PASSWORD_LENGTH);
74
76
  var RegisterInput = z2.object({ email, name, password: password2 }).strict();
75
- var LoginInput = z2.object({ email, password: z2.string().min(1).max(MAX_PASSWORD_LENGTH) }).strict();
76
- var UserDto = z2.object({ id, email, name, createdAt: isoDate }).strict();
77
+ var authCode = z2.string().trim().min(1, "Enter your code").max(MAX_AUTH_CODE_LENGTH);
78
+ var LoginInput = z2.object({
79
+ email,
80
+ password: z2.string().min(1).max(MAX_PASSWORD_LENGTH),
81
+ code: authCode.optional()
82
+ }).strict();
83
+ var UserDto = z2.object({
84
+ id,
85
+ email,
86
+ name,
87
+ createdAt: isoDate,
88
+ twoFactorEnabled: z2.boolean(),
89
+ // Name the user gave the authenticator app at setup; null while 2FA is off.
90
+ twoFactorAppName: z2.string().nullable()
91
+ }).strict();
92
+ var TwoFactorSetupDto = z2.object({ secret: z2.string(), otpauthUri: z2.string() }).strict();
93
+ var TwoFactorSetupInput = z2.object({ password: z2.string().min(1).max(MAX_PASSWORD_LENGTH) }).strict();
94
+ var TwoFactorEnableInput = z2.object({
95
+ appName: z2.string().trim().min(1, "Enter the app name").max(MAX_NAME_LENGTH),
96
+ code: z2.string().trim().regex(/^\d{6}$/, "Enter the 6-digit code")
97
+ }).strict();
98
+ var TwoFactorConfirmInput = z2.object({
99
+ password: z2.string().min(1).max(MAX_PASSWORD_LENGTH),
100
+ code: authCode
101
+ }).strict();
102
+ var RecoveryCodesDto = z2.object({ recoveryCodes: z2.array(z2.string()) }).strict();
77
103
  var CreateProjectInput = z2.object({ name, slug, description: z2.string().max(500).optional() }).strict();
78
104
  var UpdateProjectInput = z2.object({
79
105
  name: name.optional(),
@@ -557,7 +583,11 @@ function cliLogin(options) {
557
583
  method: "POST",
558
584
  path: "/api/v1/auth/cli-login",
559
585
  headers: { [CSRF_HEADER_NAME]: CSRF_HEADER_VALUE },
560
- body: { email: options.email, password: options.password }
586
+ body: {
587
+ email: options.email,
588
+ password: options.password,
589
+ ...options.code !== void 0 && { code: options.code }
590
+ }
561
591
  },
562
592
  (body) => CreatedTokenDto.parse(body)
563
593
  );
@@ -906,11 +936,21 @@ async function login(deps, options) {
906
936
  }
907
937
  const email2 = (await deps.prompts.input({ message: "Email" })).trim();
908
938
  const password3 = await deps.prompts.password({ message: "Password" });
909
- const created = await cliLogin({
939
+ const attempt = (code) => cliLogin({
910
940
  fetch: deps.fetch,
911
941
  baseUrl,
912
942
  email: email2,
913
- password: password3
943
+ password: password3,
944
+ ...code !== void 0 && { code }
945
+ });
946
+ const created = await attempt().catch(async (error) => {
947
+ if (error instanceof SecretEnvsAuthError && error.code === "MFA_REQUIRED") {
948
+ const code = (await deps.prompts.input({
949
+ message: "Authentication code (or a recovery code)"
950
+ })).trim();
951
+ return attempt(code);
952
+ }
953
+ throw error;
914
954
  }).catch((error) => {
915
955
  if (error instanceof SecretEnvsAuthError) {
916
956
  throw new CliError(error.message);
@@ -1208,7 +1248,7 @@ async function runCommand(deps, command, flags) {
1208
1248
  }
1209
1249
 
1210
1250
  // src/program.ts
1211
- var VERSION = true ? "1.0.1" : "dev";
1251
+ var VERSION = true ? "1.2.0" : "dev";
1212
1252
  function buildProgram(deps, setExitCode) {
1213
1253
  const program = new Command().name("secretenvs").description("Read and manage SecretEnvs variables from the terminal").version(VERSION).configureOutput({
1214
1254
  writeOut: (text) => deps.stdout.write(text),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secretenvs/cli",
3
- "version": "1.0.1",
3
+ "version": "1.2.0",
4
4
  "description": "Command-line client for reading and managing SecretEnvs variables.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/ankityadavpurson/secretenvs#readme",
@@ -43,8 +43,8 @@
43
43
  "zod": "^4.1.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@secretenvs/contracts": "1.0.1",
47
- "@secretenvs/sdk": "1.0.1",
46
+ "@secretenvs/contracts": "1.2.0",
47
+ "@secretenvs/sdk": "1.2.0",
48
48
  "tsup": "^8.5.0",
49
49
  "typescript": "~5.9.3",
50
50
  "vitest": "^3.2.4"