@secretenvs/cli 1.5.0 → 1.7.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 +154 -7
  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), 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. |
9
+ | Command | What it does |
10
+ | -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
11
+ | `secretenvs login [--url <baseUrl>] [--token]` | Prompts for email and password (hidden), plus a 2FA code if the account has it on; stores an API token. With `--token`, asks for an API token you created in the web app instead (for accounts that sign in through SIAM). |
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
@@ -46,6 +46,7 @@ var MAX_PASSWORD_LENGTH = 256;
46
46
  var MAX_VERSIONS_LIMIT = 100;
47
47
  var CSRF_HEADER_NAME = "x-requested-with";
48
48
  var CSRF_HEADER_VALUE = "secretenvs-web";
49
+ var TOKEN_PREFIX = "svt_";
49
50
  var MAX_AUTH_CODE_LENGTH = 32;
50
51
  var ProjectRole = z.enum(["OWNER", "ADMIN", "EDITOR", "VIEWER"]);
51
52
  var TokenAccess = z.enum(["READ", "READ_WRITE"]);
@@ -91,7 +92,20 @@ var UserDto = z2.object({
91
92
  createdAt: isoDate,
92
93
  twoFactorEnabled: z2.boolean(),
93
94
  // Name the user gave the authenticator app at setup; null while 2FA is off.
94
- twoFactorAppName: z2.string().nullable()
95
+ twoFactorAppName: z2.string().nullable(),
96
+ // Whether the account may use the /admin pages (set directly in the database).
97
+ isSuperAdmin: z2.boolean(),
98
+ // Linked to a SIAM account: name and email follow SIAM, so they are not edited here.
99
+ managedBySiam: z2.boolean(),
100
+ // Has a password of its own. Accounts created through SIAM do not, and SIAM handles their
101
+ // password and two-factor authentication.
102
+ hasPassword: z2.boolean()
103
+ }).strict();
104
+ var AuthOptionsDto = z2.object({
105
+ // Sign-in through SIAM is configured on this server.
106
+ siam: z2.boolean(),
107
+ // Where people manage their SIAM account; null when it is not configured or SIAM is off.
108
+ profileUrl: z2.string().nullable()
95
109
  }).strict();
96
110
  var TwoFactorSetupDto = z2.object({ secret: z2.string(), otpauthUri: z2.string() }).strict();
97
111
  var TwoFactorSetupInput = z2.object({ password: z2.string().min(1).max(MAX_PASSWORD_LENGTH) }).strict();
@@ -242,6 +256,36 @@ var SdkProjectDto = z2.object({
242
256
  role: ProjectRole,
243
257
  environments: z2.array(SdkEnvironmentDto)
244
258
  }).strict();
259
+ var adminPerson = z2.object({ id, name, email }).strict();
260
+ var AdminProjectDto = ProjectDto.extend({
261
+ owner: adminPerson.nullable(),
262
+ memberCount: z2.number().int().min(0),
263
+ environmentCount: z2.number().int().min(0)
264
+ });
265
+ var AdminUserDto = z2.object({
266
+ id,
267
+ email,
268
+ name,
269
+ createdAt: isoDate,
270
+ // Null while the account is enabled.
271
+ disabledAt: isoDate.nullable(),
272
+ isSuperAdmin: z2.boolean(),
273
+ // Linked to a SIAM account: its name and email belong to SIAM and cannot be edited here.
274
+ managedBySiam: z2.boolean(),
275
+ projectCount: z2.number().int().min(0)
276
+ }).strict();
277
+ var AdminUserDetailDto = AdminUserDto.extend({
278
+ // Every project the user is a member of, with their role there.
279
+ projects: z2.array(z2.object({ id, name, slug, role: ProjectRole }).strict())
280
+ });
281
+ var AdminUpdateUserInput = z2.object({
282
+ name: name.optional(),
283
+ email: email.optional(),
284
+ disabled: z2.boolean().optional()
285
+ }).strict().refine(
286
+ (input2) => input2.name !== void 0 || input2.email !== void 0 || input2.disabled !== void 0,
287
+ { message: "Provide name, email and/or disabled" }
288
+ );
245
289
  var CreateTokenInput = z2.object({
246
290
  name,
247
291
  access: TokenAccess,
@@ -294,10 +338,46 @@ var apiEnvironmentSchema = z3.object({
294
338
  TRUST_PROXY: z3.coerce.number().int().min(0).max(10).default(0),
295
339
  // Shared secret for the daily expiry-reminder call (see docs/DEPLOYMENT.md). Unset turns
296
340
  // that endpoint off.
297
- CRON_SECRET: z3.string().min(32).max(256).optional()
298
- }).strict().transform((environment) => ({
341
+ CRON_SECRET: z3.string().min(32).max(256).optional(),
342
+ // Sign-in through SIAM (https://siam.ankityadav.net.in/docs). The four IAM_* values go
343
+ // together: leave them all unset to keep SIAM sign-in off.
344
+ IAM_BASE_URL: z3.url().optional(),
345
+ IAM_CLIENT_ID: z3.string().min(1).max(256).optional(),
346
+ IAM_CLIENT_SECRET: z3.string().min(1).max(512).optional(),
347
+ IAM_REDIRECT_URI: z3.url().optional(),
348
+ // The page where people manage their SIAM account (name, email, password, two-factor). The
349
+ // account page links to it. Optional: without it the page just says to use SIAM.
350
+ IAM_PROFILE_URL: z3.url().refine(
351
+ (value) => ["http:", "https:"].includes(new URL(value).protocol),
352
+ "Expected an HTTP(S) URL"
353
+ ).optional(),
354
+ // A SIAM permission the user must hold to get in (e.g. `secretenvs.access`). Unset: any
355
+ // active SIAM account may sign in. A SIAM superadmin always may.
356
+ IAM_REQUIRED_PERMISSION: z3.string().min(1).max(128).optional(),
357
+ // Link a SIAM sign-in to an existing local account with the same email. Off by default,
358
+ // because it is only safe when SIAM verifies that people own the email they sign up with.
359
+ IAM_LINK_BY_EMAIL: z3.enum(["true", "false"]).optional()
360
+ }).strict().superRefine((environment, context) => {
361
+ const names = [
362
+ "IAM_BASE_URL",
363
+ "IAM_CLIENT_ID",
364
+ "IAM_CLIENT_SECRET",
365
+ "IAM_REDIRECT_URI"
366
+ ];
367
+ const missing = names.filter((name2) => environment[name2] === void 0);
368
+ if (missing.length > 0 && missing.length < names.length) {
369
+ for (const name2 of missing) {
370
+ context.addIssue({
371
+ code: "custom",
372
+ path: [name2],
373
+ message: "Required when any other IAM_* value is set"
374
+ });
375
+ }
376
+ }
377
+ }).transform((environment) => ({
299
378
  ...environment,
300
- COOKIE_SECURE: environment.COOKIE_SECURE === void 0 ? environment.NODE_ENV === "production" : environment.COOKIE_SECURE === "true"
379
+ COOKIE_SECURE: environment.COOKIE_SECURE === void 0 ? environment.NODE_ENV === "production" : environment.COOKIE_SECURE === "true",
380
+ IAM_LINK_BY_EMAIL: environment.IAM_LINK_BY_EMAIL === "true"
301
381
  }));
302
382
 
303
383
  // ../sdk/dist/index.js
@@ -624,6 +704,19 @@ async function send(fetchFn, baseUrl, request, parse) {
624
704
  if (status === 404) throw new SecretEnvsNotFoundError(message, status, code);
625
705
  throw new SecretEnvsApiError(message, status, code);
626
706
  }
707
+ async function siamOffered(options) {
708
+ try {
709
+ const result = await send(
710
+ options.fetch,
711
+ options.baseUrl,
712
+ { method: "GET", path: "/api/v1/auth/options" },
713
+ (body) => AuthOptionsDto.parse(body)
714
+ );
715
+ return result.siam;
716
+ } catch {
717
+ return false;
718
+ }
719
+ }
627
720
  function cliLogin(options) {
628
721
  return send(
629
722
  options.fetch,
@@ -965,6 +1058,41 @@ var out = (deps, text) => {
965
1058
  deps.stdout.write(`${text}
966
1059
  `);
967
1060
  };
1061
+ var MAX_TOKEN_LENGTH = 256;
1062
+ async function loginWithToken(deps, baseUrl) {
1063
+ out(
1064
+ deps,
1065
+ "Create an API token with read and write access in the web app (Settings > API tokens), then paste it here."
1066
+ );
1067
+ const token = (await deps.prompts.password({ message: "API token" })).trim();
1068
+ if (!token.startsWith(TOKEN_PREFIX) || token.length > MAX_TOKEN_LENGTH) {
1069
+ throw new CliError(
1070
+ `That does not look like a SecretEnvs API token (they start with ${TOKEN_PREFIX}).`
1071
+ );
1072
+ }
1073
+ const sdk = new SecretEnvs({ token, baseUrl, fetch: deps.fetch, env: {} });
1074
+ let projects;
1075
+ try {
1076
+ projects = await sdk.listProjects();
1077
+ } catch (error) {
1078
+ if (error instanceof SecretEnvsAuthError) {
1079
+ throw new CliError(
1080
+ "The server did not accept that token. Check that you copied all of it, and that it has not expired or been revoked."
1081
+ );
1082
+ }
1083
+ throw error;
1084
+ }
1085
+ const prefix = token.slice(0, 8);
1086
+ await writeCredentials(credentialsPath(deps.homeDir), {
1087
+ baseUrl,
1088
+ token,
1089
+ prefix
1090
+ });
1091
+ out(
1092
+ deps,
1093
+ `Logged in with API token ${prefix}... on ${baseUrl} (${projects.length} accessible ${projects.length === 1 ? "project" : "projects"})`
1094
+ );
1095
+ }
968
1096
  async function login(deps, options) {
969
1097
  if (!deps.interactive) {
970
1098
  throw new CliError("`secretenvs login` needs an interactive terminal.");
@@ -983,6 +1111,15 @@ async function login(deps, options) {
983
1111
  error instanceof SecretEnvsError ? error.message : "Invalid server URL"
984
1112
  );
985
1113
  }
1114
+ let useToken = options.token === true;
1115
+ const siam = useToken ? false : await siamOffered({ fetch: deps.fetch, baseUrl });
1116
+ if (siam) {
1117
+ useToken = await deps.prompts.confirm({
1118
+ message: "This server signs people in through SIAM. Log in with an API token instead of email and password? (Needed for SIAM accounts)",
1119
+ default: false
1120
+ });
1121
+ }
1122
+ if (useToken) return loginWithToken(deps, baseUrl);
986
1123
  const email2 = (await deps.prompts.input({ message: "Email" })).trim();
987
1124
  const password3 = await deps.prompts.password({ message: "Password" });
988
1125
  const attempt = (code) => cliLogin({
@@ -1002,7 +1139,10 @@ async function login(deps, options) {
1002
1139
  throw error;
1003
1140
  }).catch((error) => {
1004
1141
  if (error instanceof SecretEnvsAuthError) {
1005
- throw new CliError(error.message);
1142
+ throw new CliError(
1143
+ siam ? `${error.message}
1144
+ If you sign in to SecretEnvs through SIAM, run \`secretenvs login --token\` instead.` : error.message
1145
+ );
1006
1146
  }
1007
1147
  throw error;
1008
1148
  });
@@ -1297,14 +1437,21 @@ async function runCommand(deps, command, flags) {
1297
1437
  }
1298
1438
 
1299
1439
  // src/program.ts
1300
- var VERSION = true ? "1.5.0" : "dev";
1440
+ var VERSION = true ? "1.7.0" : "dev";
1301
1441
  function buildProgram(deps, setExitCode) {
1302
1442
  const program = new Command().name("secretenvs").description("Read and manage SecretEnvs variables from the terminal").version(VERSION).configureOutput({
1303
1443
  writeOut: (text) => deps.stdout.write(text),
1304
1444
  writeErr: (text) => deps.stderr.write(text)
1305
1445
  }).exitOverride();
1306
1446
  const target = (command) => command.option("-p, --project <slug>", "project slug (or SECRETENVS_PROJECT)").option("-e, --env <slug>", "environment slug (or SECRETENVS_ENV)");
1307
- program.command("login").description("Log in with email and password and store an API token").option("--url <baseUrl>", "server URL, e.g. https://vault.example.com").action((options) => login(deps, options));
1447
+ program.command("login").description(
1448
+ "Log in with email and password, or with an API token, and store it"
1449
+ ).option("--url <baseUrl>", "server URL, e.g. https://vault.example.com").option(
1450
+ "--token",
1451
+ "paste an API token created in the web app (for accounts that sign in through SIAM)"
1452
+ ).action(
1453
+ (options) => login(deps, options)
1454
+ );
1308
1455
  program.command("logout").description("Delete the stored credentials").action(() => logout(deps));
1309
1456
  program.command("whoami").description("Show the current server, account and token").action(() => whoami(deps));
1310
1457
  program.command("projects").description("List accessible projects").action(() => listProjects(deps));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secretenvs/cli",
3
- "version": "1.5.0",
3
+ "version": "1.7.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",
@@ -44,8 +44,8 @@
44
44
  "zod": "^4.1.0"
45
45
  },
46
46
  "devDependencies": {
47
- "@secretenvs/contracts": "1.5.0",
48
- "@secretenvs/sdk": "1.5.0",
47
+ "@secretenvs/contracts": "1.7.0",
48
+ "@secretenvs/sdk": "1.7.0",
49
49
  "@types/cross-spawn": "^6.0.6",
50
50
  "tsup": "^8.5.0",
51
51
  "typescript": "~5.9.3",