ultraenv 1.0.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 (89) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2058 -0
  3. package/bin/ultraenv.mjs +3 -0
  4. package/dist/chunk-2USZPWLZ.js +288 -0
  5. package/dist/chunk-3UV2QNJL.js +270 -0
  6. package/dist/chunk-3VYXPTYV.js +179 -0
  7. package/dist/chunk-4XUYMRK5.js +366 -0
  8. package/dist/chunk-5G2DU52U.js +189 -0
  9. package/dist/chunk-6KS56D6E.js +172 -0
  10. package/dist/chunk-AWN6ADV7.js +328 -0
  11. package/dist/chunk-CHVO6NWI.js +203 -0
  12. package/dist/chunk-CIFMBJ4H.js +3975 -0
  13. package/dist/chunk-GC7RXHLA.js +253 -0
  14. package/dist/chunk-HFXQGJY3.js +445 -0
  15. package/dist/chunk-IGFVP24Q.js +91 -0
  16. package/dist/chunk-IKPTKALB.js +78 -0
  17. package/dist/chunk-JB7RKV3C.js +66 -0
  18. package/dist/chunk-MNVFG7H4.js +611 -0
  19. package/dist/chunk-MSXMESFP.js +1910 -0
  20. package/dist/chunk-N5PAV4NM.js +127 -0
  21. package/dist/chunk-NBOABPHM.js +158 -0
  22. package/dist/chunk-OMAOROL4.js +49 -0
  23. package/dist/chunk-R7PZRSZ7.js +105 -0
  24. package/dist/chunk-TE7HPLA6.js +73 -0
  25. package/dist/chunk-TMT5KCO3.js +101 -0
  26. package/dist/chunk-UEWYFN6A.js +189 -0
  27. package/dist/chunk-WMHN5RW2.js +128 -0
  28. package/dist/chunk-XC65ORJ5.js +70 -0
  29. package/dist/chunk-YMMP4VQL.js +118 -0
  30. package/dist/chunk-YN2KGTCB.js +33 -0
  31. package/dist/chunk-YTICOB5M.js +65 -0
  32. package/dist/chunk-YVWLXFUT.js +107 -0
  33. package/dist/ci-check-sync-VBMSVWIV.js +48 -0
  34. package/dist/ci-scan-24MT5XGS.js +41 -0
  35. package/dist/ci-setup-C2NKEFRD.js +135 -0
  36. package/dist/ci-validate-7AW24LSQ.js +57 -0
  37. package/dist/cli/index.cjs +9217 -0
  38. package/dist/cli/index.d.cts +9 -0
  39. package/dist/cli/index.d.ts +9 -0
  40. package/dist/cli/index.js +339 -0
  41. package/dist/comparator-RDKX3OI7.js +13 -0
  42. package/dist/completion-MW35C2XO.js +168 -0
  43. package/dist/config-O5YRQP5Z.js +13 -0
  44. package/dist/debug-PTPXAF3K.js +131 -0
  45. package/dist/declaration-LEME4AFZ.js +10 -0
  46. package/dist/doctor-FZAUPKHS.js +129 -0
  47. package/dist/envs-compare-5K3HESX5.js +49 -0
  48. package/dist/envs-create-2XXHXMGA.js +58 -0
  49. package/dist/envs-list-NQM5252B.js +59 -0
  50. package/dist/envs-switch-6L2AQYID.js +50 -0
  51. package/dist/envs-validate-FL73Q76T.js +89 -0
  52. package/dist/fs-VH7ATUS3.js +31 -0
  53. package/dist/generator-LFZBMZZS.js +14 -0
  54. package/dist/git-BZS4DPAI.js +30 -0
  55. package/dist/help-3XJBXEHE.js +121 -0
  56. package/dist/index.cjs +12907 -0
  57. package/dist/index.d.cts +2562 -0
  58. package/dist/index.d.ts +2562 -0
  59. package/dist/index.js +3212 -0
  60. package/dist/init-Y7JQ2KYJ.js +146 -0
  61. package/dist/install-hook-SKXIV6NV.js +111 -0
  62. package/dist/json-schema-I26YNQBH.js +10 -0
  63. package/dist/key-manager-O3G55WPU.js +25 -0
  64. package/dist/middleware/express.cjs +103 -0
  65. package/dist/middleware/express.d.cts +115 -0
  66. package/dist/middleware/express.d.ts +115 -0
  67. package/dist/middleware/express.js +8 -0
  68. package/dist/middleware/fastify.cjs +91 -0
  69. package/dist/middleware/fastify.d.cts +111 -0
  70. package/dist/middleware/fastify.d.ts +111 -0
  71. package/dist/middleware/fastify.js +8 -0
  72. package/dist/module-IDIZPP4M.js +10 -0
  73. package/dist/protect-NCWPM6VC.js +161 -0
  74. package/dist/scan-TRLY36TT.js +58 -0
  75. package/dist/schema/index.cjs +4074 -0
  76. package/dist/schema/index.d.cts +1244 -0
  77. package/dist/schema/index.d.ts +1244 -0
  78. package/dist/schema/index.js +152 -0
  79. package/dist/sync-TMHMTLH2.js +186 -0
  80. package/dist/typegen-SQOSXBWM.js +80 -0
  81. package/dist/validate-IOAM5HWS.js +100 -0
  82. package/dist/vault-decrypt-U6HJZNBV.js +111 -0
  83. package/dist/vault-diff-B3ZOQTWI.js +132 -0
  84. package/dist/vault-encrypt-GUSLCSKS.js +112 -0
  85. package/dist/vault-init-GUBOTOUL.js +106 -0
  86. package/dist/vault-rekey-DAHT7JCN.js +132 -0
  87. package/dist/vault-status-GDLRU2OK.js +90 -0
  88. package/dist/vault-verify-CD76FJSF.js +102 -0
  89. package/package.json +106 -0
@@ -0,0 +1,152 @@
1
+ import {
2
+ ArraySchemaBuilder,
3
+ BigIntSchemaBuilder,
4
+ BooleanSchemaBuilder,
5
+ DateSchemaBuilder,
6
+ EnumSchemaBuilder,
7
+ JsonSchemaBuilder,
8
+ NumberSchemaBuilder,
9
+ RegexSchemaBuilder,
10
+ SchemaBuilder,
11
+ StringSchemaBuilder,
12
+ allOf,
13
+ applyAlias,
14
+ applyConditional,
15
+ applyCustom,
16
+ applyDefault,
17
+ applyDeprecated,
18
+ applyDescription,
19
+ applyOptional,
20
+ applyRequired,
21
+ applySecret,
22
+ applyTransform,
23
+ check,
24
+ composeTransforms,
25
+ createArraySchema,
26
+ createBase64Schema,
27
+ createBigIntSchema,
28
+ createBooleanSchema,
29
+ createBytesSchema,
30
+ createColorSchema,
31
+ createCountrySchema,
32
+ createCronSchema,
33
+ createCurrencySchema,
34
+ createDateSchema,
35
+ createDurationSchema,
36
+ createEmailSchema,
37
+ createEnumSchema,
38
+ createHexSchema,
39
+ createHostnameSchema,
40
+ createIpSchema,
41
+ createIpv4Schema,
42
+ createIpv6Schema,
43
+ createJsonSchema,
44
+ createLocaleSchema,
45
+ createNumberSchema,
46
+ createPathSchema,
47
+ createPortSchema,
48
+ createRegexSchema,
49
+ createSemverSchema,
50
+ createStringSchema,
51
+ createTimezoneSchema,
52
+ createUrlSchema,
53
+ createUuidSchema,
54
+ defineEnv,
55
+ formatSchemaDescription,
56
+ formatValidationResult,
57
+ getAliases,
58
+ getDefaultValue,
59
+ getDeprecationMessage,
60
+ getDescription,
61
+ hasConditional,
62
+ hasDefault,
63
+ isAlias,
64
+ isDeprecated,
65
+ isOptional,
66
+ isRequired,
67
+ isSecret,
68
+ maskValue,
69
+ maxLength,
70
+ minLength,
71
+ shouldApply,
72
+ t,
73
+ tryDefineEnv,
74
+ validate,
75
+ validateValue
76
+ } from "../chunk-CIFMBJ4H.js";
77
+ export {
78
+ ArraySchemaBuilder,
79
+ BigIntSchemaBuilder,
80
+ BooleanSchemaBuilder,
81
+ DateSchemaBuilder,
82
+ EnumSchemaBuilder,
83
+ JsonSchemaBuilder,
84
+ NumberSchemaBuilder,
85
+ RegexSchemaBuilder,
86
+ SchemaBuilder,
87
+ StringSchemaBuilder,
88
+ allOf,
89
+ applyAlias,
90
+ applyConditional,
91
+ applyCustom,
92
+ applyDefault,
93
+ applyDeprecated,
94
+ applyDescription,
95
+ applyOptional,
96
+ applyRequired,
97
+ applySecret,
98
+ applyTransform,
99
+ check,
100
+ composeTransforms,
101
+ createArraySchema,
102
+ createBase64Schema,
103
+ createBigIntSchema,
104
+ createBooleanSchema,
105
+ createBytesSchema,
106
+ createColorSchema,
107
+ createCountrySchema,
108
+ createCronSchema,
109
+ createCurrencySchema,
110
+ createDateSchema,
111
+ createDurationSchema,
112
+ createEmailSchema,
113
+ createEnumSchema,
114
+ createHexSchema,
115
+ createHostnameSchema,
116
+ createIpSchema,
117
+ createIpv4Schema,
118
+ createIpv6Schema,
119
+ createJsonSchema,
120
+ createLocaleSchema,
121
+ createNumberSchema,
122
+ createPathSchema,
123
+ createPortSchema,
124
+ createRegexSchema,
125
+ createSemverSchema,
126
+ createStringSchema,
127
+ createTimezoneSchema,
128
+ createUrlSchema,
129
+ createUuidSchema,
130
+ maxLength as customMaxLength,
131
+ minLength as customMinLength,
132
+ defineEnv,
133
+ formatSchemaDescription,
134
+ formatValidationResult,
135
+ getAliases,
136
+ getDeprecationMessage,
137
+ getDescription,
138
+ getDefaultValue as getModDefault,
139
+ hasConditional,
140
+ hasDefault,
141
+ isAlias,
142
+ isDeprecated,
143
+ isOptional,
144
+ isRequired,
145
+ isSecret,
146
+ maskValue,
147
+ shouldApply,
148
+ t,
149
+ tryDefineEnv,
150
+ validate,
151
+ validateValue
152
+ };
@@ -0,0 +1,186 @@
1
+ import {
2
+ drawBox
3
+ } from "./chunk-TMT5KCO3.js";
4
+ import {
5
+ bold,
6
+ cyan,
7
+ green,
8
+ red,
9
+ yellow
10
+ } from "./chunk-OMAOROL4.js";
11
+ import {
12
+ writeError,
13
+ writeJson,
14
+ writeLine
15
+ } from "./chunk-YN2KGTCB.js";
16
+ import {
17
+ exists
18
+ } from "./chunk-3VYXPTYV.js";
19
+ import "./chunk-5G2DU52U.js";
20
+
21
+ // src/cli/commands/sync.ts
22
+ import { resolve, join } from "path";
23
+ import { watch } from "fs";
24
+ async function run(args, ctx) {
25
+ try {
26
+ const cwd = args.flags["--cwd"] ?? ctx.cwd;
27
+ const baseDir = resolve(cwd);
28
+ const envPath = args.flags["--file"] ?? join(baseDir, ".env");
29
+ const examplePath = args.flags["--out"] ?? join(baseDir, ".env.example");
30
+ const mode = args.flags["--mode"] ?? "check";
31
+ if (mode === "check") {
32
+ return await checkSync(envPath, examplePath, ctx);
33
+ }
34
+ if (mode === "generate") {
35
+ return await generateSync(envPath, examplePath);
36
+ }
37
+ if (mode === "interactive") {
38
+ return await interactiveSync(envPath, examplePath);
39
+ }
40
+ if (mode === "watch") {
41
+ return await watchSync(envPath, examplePath);
42
+ }
43
+ writeError(red(` Unknown sync mode: ${mode}`));
44
+ writeError(yellow(" Available modes: generate, check, interactive, watch"));
45
+ return 1;
46
+ } catch (error) {
47
+ const msg = error instanceof Error ? error.message : String(error);
48
+ writeError(red(` Sync error: ${msg}`));
49
+ return 1;
50
+ }
51
+ }
52
+ async function checkSync(envPath, examplePath, ctx) {
53
+ const envExists = await exists(envPath);
54
+ const exampleExists = await exists(examplePath);
55
+ if (!envExists) {
56
+ if (ctx.outputFormat === "json") {
57
+ writeJson({ inSync: false, error: ".env file not found" });
58
+ } else {
59
+ writeError(yellow(' \u26A0 .env file not found. Run "ultraenv sync --mode generate" to create .env.example.'));
60
+ }
61
+ return 1;
62
+ }
63
+ if (!exampleExists) {
64
+ if (ctx.outputFormat === "json") {
65
+ writeJson({ inSync: false, error: ".env.example not found" });
66
+ } else {
67
+ writeError(yellow(' \u26A0 .env.example not found. Run "ultraenv sync --mode generate" to create it.'));
68
+ }
69
+ return 1;
70
+ }
71
+ const { compareSync, formatSyncDiff } = await import("./comparator-RDKX3OI7.js");
72
+ const diff = await compareSync(envPath, examplePath);
73
+ if (ctx.outputFormat === "json") {
74
+ writeJson({
75
+ inSync: diff.inSync,
76
+ missing: diff.missing,
77
+ extra: diff.extra,
78
+ different: diff.different,
79
+ same: diff.same
80
+ });
81
+ return diff.inSync ? 0 : 1;
82
+ }
83
+ writeLine(bold("\u{1F504} .env Sync Check"));
84
+ writeLine("");
85
+ writeLine(formatSyncDiff(diff));
86
+ writeLine("");
87
+ if (!diff.inSync) {
88
+ const box = drawBox([
89
+ "Your .env is out of sync with .env.example.",
90
+ 'Run "ultraenv sync --mode generate" to update .env.example',
91
+ 'or "ultraenv sync --mode interactive" to review changes.'
92
+ ], { title: "ACTION NEEDED", border: "rounded" });
93
+ writeLine(box);
94
+ writeLine("");
95
+ return 1;
96
+ }
97
+ writeLine(green(bold(" \u2705 .env is in sync with .env.example")));
98
+ writeLine("");
99
+ return 0;
100
+ }
101
+ async function generateSync(envPath, examplePath) {
102
+ const envExists = await exists(envPath);
103
+ if (!envExists) {
104
+ writeError(yellow(" \u26A0 .env file not found. Create a .env file first."));
105
+ return 1;
106
+ }
107
+ const { generateExampleFile } = await import("./generator-LFZBMZZS.js");
108
+ await generateExampleFile(envPath, examplePath, {
109
+ includeDescriptions: true,
110
+ includeTypes: true,
111
+ includeDefaults: true
112
+ });
113
+ writeLine(bold("\u{1F4DD} Generating .env.example..."));
114
+ writeLine("");
115
+ writeLine(green(` \u2713 Generated ${examplePath}`));
116
+ writeLine("");
117
+ return 0;
118
+ }
119
+ async function interactiveSync(envPath, examplePath) {
120
+ const { compareSync } = await import("./comparator-RDKX3OI7.js");
121
+ const envExists = await exists(envPath);
122
+ if (!envExists) {
123
+ writeError(yellow(" \u26A0 .env file not found."));
124
+ return 1;
125
+ }
126
+ const diff = await compareSync(envPath, examplePath);
127
+ if (diff.inSync) {
128
+ writeLine(green(" \u2713 Already in sync."));
129
+ return 0;
130
+ }
131
+ writeLine(bold("\u{1F4CB} Differences found:"));
132
+ writeLine("");
133
+ if (diff.missing.length > 0) {
134
+ writeLine(yellow(" Missing in .env:"));
135
+ for (const key of diff.missing) {
136
+ writeLine(` - ${key}`);
137
+ }
138
+ writeLine("");
139
+ }
140
+ if (diff.extra.length > 0) {
141
+ writeLine(yellow(" Extra in .env (not in .env.example):"));
142
+ for (const key of diff.extra) {
143
+ writeLine(` + ${key}`);
144
+ }
145
+ writeLine("");
146
+ }
147
+ const { generateExampleFile } = await import("./generator-LFZBMZZS.js");
148
+ await generateExampleFile(envPath, examplePath);
149
+ writeLine(green(` \u2713 Updated ${examplePath}`));
150
+ writeLine("");
151
+ return 0;
152
+ }
153
+ async function watchSync(envPath, examplePath) {
154
+ const { generateExampleFile } = await import("./generator-LFZBMZZS.js");
155
+ writeLine(bold("\u{1F441}\uFE0F Watching for .env changes..."));
156
+ writeLine(cyan(" Press Ctrl+C to stop."));
157
+ writeLine("");
158
+ await generateExampleFile(envPath, examplePath);
159
+ writeLine(green(` \u2713 Generated ${examplePath}`));
160
+ return new Promise((resolvePromise) => {
161
+ let debounceTimer = null;
162
+ let watcher = null;
163
+ watcher = watch(envPath, (eventType) => {
164
+ if (eventType !== "change") return;
165
+ if (debounceTimer !== null) clearTimeout(debounceTimer);
166
+ debounceTimer = setTimeout(async () => {
167
+ try {
168
+ await generateExampleFile(envPath, examplePath);
169
+ writeLine(green(` \u2713 Updated ${examplePath} (${(/* @__PURE__ */ new Date()).toLocaleTimeString()})`));
170
+ } catch (err) {
171
+ const msg = err instanceof Error ? err.message : String(err);
172
+ writeError(red(` \u2717 Failed to update: ${msg}`));
173
+ }
174
+ }, 200);
175
+ });
176
+ process.on("SIGINT", () => {
177
+ if (watcher !== null) watcher.close();
178
+ writeLine("");
179
+ writeLine(cyan(" Watcher stopped."));
180
+ resolvePromise(0);
181
+ });
182
+ });
183
+ }
184
+ export {
185
+ run
186
+ };
@@ -0,0 +1,80 @@
1
+ import {
2
+ loadWithResult
3
+ } from "./chunk-MNVFG7H4.js";
4
+ import "./chunk-HFXQGJY3.js";
5
+ import {
6
+ bold,
7
+ cyan,
8
+ green,
9
+ red,
10
+ yellow
11
+ } from "./chunk-OMAOROL4.js";
12
+ import {
13
+ writeError,
14
+ writeLine
15
+ } from "./chunk-YN2KGTCB.js";
16
+ import "./chunk-3VYXPTYV.js";
17
+ import "./chunk-XC65ORJ5.js";
18
+ import "./chunk-5G2DU52U.js";
19
+
20
+ // src/cli/commands/typegen.ts
21
+ import { resolve } from "path";
22
+ async function run(args, ctx) {
23
+ try {
24
+ const cwd = args.flags["--cwd"] ?? ctx.cwd;
25
+ const envDir = resolve(cwd);
26
+ const format = args.flags["--format"] ?? "declaration";
27
+ const outFlag = args.flags["--out"];
28
+ const defaultOutPaths = {
29
+ "declaration": "src/env.d.ts",
30
+ "module": "src/env.ts",
31
+ "json-schema": "env.schema.json"
32
+ };
33
+ const outputPath = outFlag ? resolve(cwd, outFlag) : resolve(cwd, defaultOutPaths[format] ?? "src/env.d.ts");
34
+ const interfaceName = args.flags["--interface"] ?? "Env";
35
+ const result = loadWithResult({ envDir, overrideProcessEnv: false });
36
+ writeLine(bold(`\u{1F4DD} Generating ${format} types...`));
37
+ writeLine("");
38
+ const schema = ctx.config.schema?.definitions;
39
+ let content = "";
40
+ if (format === "declaration") {
41
+ const { generateDeclarationContent } = await import("./declaration-LEME4AFZ.js");
42
+ content = generateDeclarationContent(
43
+ result.env,
44
+ schema,
45
+ { interfaceName, jsdoc: true, indent: 4 }
46
+ );
47
+ } else if (format === "module") {
48
+ const { generateModuleContent } = await import("./module-IDIZPP4M.js");
49
+ if (!schema) {
50
+ writeError(yellow(" Warning: No schema defined. Generating empty module."));
51
+ writeError(yellow(" Add a schema to your .ultraenvrc.json for typed output."));
52
+ }
53
+ content = generateModuleContent(
54
+ schema ?? {},
55
+ { interfaceName, jsdoc: true, indent: 2 }
56
+ );
57
+ } else if (format === "json-schema") {
58
+ const { generateJsonSchemaContent } = await import("./json-schema-I26YNQBH.js");
59
+ content = generateJsonSchemaContent(
60
+ schema ?? {},
61
+ { includeDescriptions: true, indent: 2 }
62
+ );
63
+ }
64
+ const { writeFile, ensureDir } = await import("./fs-VH7ATUS3.js");
65
+ await ensureDir(resolve(outputPath, ".."));
66
+ await writeFile(outputPath, content);
67
+ writeLine(green(` \u2713 Generated ${format} types`));
68
+ writeLine(cyan(` Output: ${outputPath}`));
69
+ writeLine(cyan(` Variables: ${Object.keys(result.env).length}`));
70
+ writeLine("");
71
+ return 0;
72
+ } catch (error) {
73
+ const msg = error instanceof Error ? error.message : String(error);
74
+ writeError(red(` Type generation error: ${msg}`));
75
+ return 1;
76
+ }
77
+ }
78
+ export {
79
+ run
80
+ };
@@ -0,0 +1,100 @@
1
+ import {
2
+ drawTable
3
+ } from "./chunk-WMHN5RW2.js";
4
+ import {
5
+ loadWithResult
6
+ } from "./chunk-MNVFG7H4.js";
7
+ import "./chunk-HFXQGJY3.js";
8
+ import {
9
+ bold,
10
+ cyan,
11
+ green,
12
+ red,
13
+ yellow
14
+ } from "./chunk-OMAOROL4.js";
15
+ import {
16
+ writeError,
17
+ writeJson,
18
+ writeLine
19
+ } from "./chunk-YN2KGTCB.js";
20
+ import "./chunk-3VYXPTYV.js";
21
+ import "./chunk-XC65ORJ5.js";
22
+ import "./chunk-5G2DU52U.js";
23
+
24
+ // src/cli/commands/validate.ts
25
+ import { resolve } from "path";
26
+ async function run(args, ctx) {
27
+ try {
28
+ const cwd = args.flags["--cwd"] ?? ctx.cwd;
29
+ const envDir = resolve(cwd);
30
+ const result = loadWithResult({
31
+ envDir,
32
+ expandVariables: ctx.config.expandVariables,
33
+ overrideProcessEnv: false,
34
+ mergeStrategy: ctx.config.mergeStrategy
35
+ });
36
+ if (ctx.outputFormat === "json") {
37
+ writeJson({
38
+ valid: true,
39
+ metadata: result.metadata,
40
+ variables: Object.keys(result.env).length,
41
+ env: result.env
42
+ });
43
+ return 0;
44
+ }
45
+ writeLine(bold("\u{1F50D} Environment Validation"));
46
+ writeLine("");
47
+ writeLine(cyan(" Files parsed: ") + `${result.metadata.filesParsed}`);
48
+ writeLine(cyan(" Total variables: ") + `${result.metadata.totalVars}`);
49
+ writeLine(cyan(" Load time: ") + `${result.metadata.loadTimeMs}ms`);
50
+ writeLine(cyan(" Had overrides: ") + `${result.metadata.hadOverrides ? "yes" : "no"}`);
51
+ writeLine("");
52
+ if (result.metadata.totalVars === 0) {
53
+ writeLine(yellow(" \u26A0 No environment variables found."));
54
+ writeLine(yellow(" Create a .env file in your project directory."));
55
+ return 1;
56
+ }
57
+ if (result.parsed.length > 0) {
58
+ writeLine(bold(" Loaded files:"));
59
+ for (const file of result.parsed) {
60
+ const status = file.exists ? green("\u2713") : red("\u2717");
61
+ const varCount = `${file.vars.length} var(s)`;
62
+ writeLine(` ${status} ${file.path} (${varCount})`);
63
+ }
64
+ writeLine("");
65
+ }
66
+ const vars = Object.entries(result.env);
67
+ if (vars.length > 0 && !args.flags["--quiet"]) {
68
+ const maxShow = 50;
69
+ const shownVars = vars.slice(0, maxShow);
70
+ const headers = ["Variable", "Value", "Source"];
71
+ const rows = shownVars.map(([key, value]) => {
72
+ let source = "unknown";
73
+ for (const pf of result.parsed) {
74
+ const found = pf.vars.find((v) => v.key === key);
75
+ if (found) {
76
+ source = pf.path.replace(envDir + "/", "");
77
+ break;
78
+ }
79
+ }
80
+ const displayValue = value.length > 40 ? value.slice(0, 37) + "..." : value;
81
+ return [key, displayValue, source];
82
+ });
83
+ writeLine(drawTable(headers, rows, { maxWidth: 100 }));
84
+ if (vars.length > maxShow) {
85
+ writeLine(yellow(` ... and ${vars.length - maxShow} more variables`));
86
+ }
87
+ }
88
+ writeLine("");
89
+ writeLine(green(bold(" \u2705 Environment validated successfully")));
90
+ writeLine("");
91
+ return 0;
92
+ } catch (error) {
93
+ const msg = error instanceof Error ? error.message : String(error);
94
+ writeError(red(` Validation error: ${msg}`));
95
+ return 1;
96
+ }
97
+ }
98
+ export {
99
+ run
100
+ };
@@ -0,0 +1,111 @@
1
+ import {
2
+ readVaultFile
3
+ } from "./chunk-NBOABPHM.js";
4
+ import {
5
+ bold,
6
+ cyan,
7
+ green,
8
+ red,
9
+ yellow
10
+ } from "./chunk-OMAOROL4.js";
11
+ import {
12
+ writeError,
13
+ writeLine
14
+ } from "./chunk-YN2KGTCB.js";
15
+ import {
16
+ exists,
17
+ readFile
18
+ } from "./chunk-3VYXPTYV.js";
19
+ import {
20
+ parseKey
21
+ } from "./chunk-UEWYFN6A.js";
22
+ import {
23
+ decryptValue,
24
+ isEncryptedValue
25
+ } from "./chunk-2USZPWLZ.js";
26
+ import "./chunk-XC65ORJ5.js";
27
+ import {
28
+ getErrorMessage
29
+ } from "./chunk-5G2DU52U.js";
30
+
31
+ // src/cli/commands/vault-decrypt.ts
32
+ import { resolve, join } from "path";
33
+ async function run(args, ctx) {
34
+ try {
35
+ const cwd = args.flags["--cwd"] ?? ctx.cwd;
36
+ const baseDir = resolve(cwd);
37
+ const envName = args.flags["--env"] ?? "production";
38
+ const keyInput = args.flags["--key"];
39
+ writeLine(bold(`\u{1F513} Decrypting vault \u2192 "${envName}" environment`));
40
+ writeLine("");
41
+ const vaultPath = join(baseDir, ".env.vault");
42
+ if (!await exists(vaultPath)) {
43
+ writeError(red(" .env.vault not found."));
44
+ return 1;
45
+ }
46
+ const vault = await readVaultFile(vaultPath);
47
+ const entry = vault.get(envName.toLowerCase());
48
+ if (!entry) {
49
+ writeError(red(` Environment "${envName}" not found in vault.`));
50
+ writeError(yellow(` Available: ${[...vault.keys()].join(", ") || "none"}`));
51
+ return 1;
52
+ }
53
+ let rawKey;
54
+ if (keyInput) {
55
+ rawKey = parseKey(keyInput);
56
+ } else {
57
+ const keysPath = join(baseDir, ".env.keys");
58
+ if (!await exists(keysPath)) {
59
+ writeError(red(" No encryption key provided and .env.keys not found."));
60
+ return 1;
61
+ }
62
+ const keysContent = await readFile(keysPath);
63
+ const { parseKeysFile } = await import("./key-manager-O3G55WPU.js");
64
+ const keys = parseKeysFile(keysContent);
65
+ const envKey = keys.get(envName.toLowerCase());
66
+ if (!envKey) {
67
+ writeError(red(` No key found for environment "${envName}"`));
68
+ return 1;
69
+ }
70
+ rawKey = parseKey(envKey);
71
+ }
72
+ writeLine(cyan(" Decrypting variables..."));
73
+ const decryptedLines = [];
74
+ const encryptedContent = entry.encrypted;
75
+ for (const line of encryptedContent.split("\n")) {
76
+ const eqIdx = line.indexOf("=");
77
+ if (eqIdx === -1) {
78
+ decryptedLines.push(line);
79
+ continue;
80
+ }
81
+ const key = line.slice(0, eqIdx);
82
+ const value = line.slice(eqIdx + 1);
83
+ if (isEncryptedValue(value)) {
84
+ try {
85
+ const decrypted = decryptValue(value, rawKey);
86
+ decryptedLines.push(`${key}=${decrypted}`);
87
+ } catch {
88
+ writeError(yellow(` \u26A0 Failed to decrypt "${key}" (wrong key?)`));
89
+ decryptedLines.push(`${key}=<DECRYPTION_FAILED>`);
90
+ }
91
+ } else {
92
+ decryptedLines.push(line);
93
+ }
94
+ }
95
+ const outputPath = join(baseDir, `.env.${envName}`);
96
+ const { writeFile } = await import("./fs-VH7ATUS3.js");
97
+ await writeFile(outputPath, decryptedLines.join("\n"));
98
+ writeLine(green(` \u2713 Decrypted to ${outputPath}`));
99
+ writeLine(green(` \u2713 Variables: ${entry.varCount}`));
100
+ writeLine("");
101
+ writeLine(green(bold(" \u2705 Decryption complete!")));
102
+ writeLine("");
103
+ return 0;
104
+ } catch (error) {
105
+ writeError(red(` Decrypt error: ${getErrorMessage(error)}`));
106
+ return 1;
107
+ }
108
+ }
109
+ export {
110
+ run
111
+ };