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,203 @@
1
+ import {
2
+ isSecretKey,
3
+ isSecretLike,
4
+ maskValue
5
+ } from "./chunk-TE7HPLA6.js";
6
+ import {
7
+ parseEnvFile
8
+ } from "./chunk-HFXQGJY3.js";
9
+ import {
10
+ exists,
11
+ readFile,
12
+ writeFile
13
+ } from "./chunk-3VYXPTYV.js";
14
+
15
+ // src/sync/generator.ts
16
+ var HEADER = [
17
+ "# ============================================================",
18
+ "# Auto-generated by ultraenv \u2014 DO NOT EDIT",
19
+ "# Copy this file to .env and fill in the values",
20
+ "# ============================================================",
21
+ ""
22
+ ].join("\n");
23
+ function schemaTypeToString(schema) {
24
+ const schemaRecord = schema;
25
+ if ("type" in schemaRecord) {
26
+ const schemaType = schemaRecord.type;
27
+ switch (schemaType) {
28
+ case "string":
29
+ return "string";
30
+ case "number":
31
+ return "number";
32
+ case "boolean":
33
+ return "boolean";
34
+ case "enum":
35
+ return "enum";
36
+ case "array":
37
+ return "array (comma-separated)";
38
+ case "json":
39
+ return "json";
40
+ case "date":
41
+ return "date (ISO 8601)";
42
+ case "bigint":
43
+ return "bigint";
44
+ default:
45
+ return "string";
46
+ }
47
+ }
48
+ return "string";
49
+ }
50
+ function extractEnumValues(schema) {
51
+ const schemaRecord = schema;
52
+ if (schemaRecord.type === "enum") {
53
+ const values = schemaRecord.values;
54
+ if (values !== void 0 && Array.isArray(values)) {
55
+ return [...values];
56
+ }
57
+ }
58
+ if (schemaRecord.type === "string") {
59
+ const enumValues = schemaRecord.enum;
60
+ if (enumValues !== void 0 && Array.isArray(enumValues)) {
61
+ return [...enumValues];
62
+ }
63
+ }
64
+ return null;
65
+ }
66
+ function isSecretVariable(key, value, schema) {
67
+ if (schema !== void 0) {
68
+ const schemaRecord = schema;
69
+ if (schemaRecord.isSecret === true) {
70
+ return true;
71
+ }
72
+ }
73
+ if (isSecretKey(key)) {
74
+ return true;
75
+ }
76
+ if (value.length > 0 && isSecretLike(value)) {
77
+ return true;
78
+ }
79
+ return false;
80
+ }
81
+ async function generateExampleFile(envPath, outputPath, options) {
82
+ const includeDescriptions = options?.includeDescriptions ?? true;
83
+ const includeTypes = options?.includeTypes ?? true;
84
+ const includeDefaults = options?.includeDefaults ?? true;
85
+ const content = await readFile(envPath);
86
+ const schema = options?.schemaPath !== void 0 ? await loadSchema(options.schemaPath) : void 0;
87
+ const parsed = parseEnvFile(content, envPath);
88
+ const generated = generateExampleContent(parsed.vars, schema, {
89
+ includeDescriptions,
90
+ includeTypes,
91
+ includeDefaults
92
+ });
93
+ await writeFile(outputPath, generated);
94
+ }
95
+ function generateExampleContent(vars, schema, options) {
96
+ const includeDescriptions = options?.includeDescriptions ?? true;
97
+ const includeTypes = options?.includeTypes ?? true;
98
+ const includeDefaults = options?.includeDefaults ?? true;
99
+ const lines = [];
100
+ let order = 0;
101
+ const emittedKeys = /* @__PURE__ */ new Set();
102
+ lines.push({ content: HEADER, order: order++ });
103
+ for (const envVar of vars) {
104
+ if (emittedKeys.has(envVar.key)) continue;
105
+ emittedKeys.add(envVar.key);
106
+ const schemaEntry = schema !== void 0 ? schema[envVar.key] : void 0;
107
+ const schemaRecord = schemaEntry !== void 0 ? schemaEntry : void 0;
108
+ const isRequired = schemaEntry === void 0 || schemaEntry.optional !== true;
109
+ const isSecret = isSecretVariable(envVar.key, envVar.value, schemaEntry);
110
+ const commentLines = [];
111
+ if (includeDescriptions && schemaEntry?.description !== void 0) {
112
+ commentLines.push(`# ${schemaEntry.description}`);
113
+ }
114
+ if (includeTypes && schemaEntry !== void 0) {
115
+ const typeStr = schemaTypeToString(schemaEntry);
116
+ commentLines.push(`# type: ${typeStr}`);
117
+ const enumValues = extractEnumValues(schemaEntry);
118
+ if (enumValues !== null) {
119
+ commentLines.push(`# values: ${enumValues.join(", ")}`);
120
+ }
121
+ }
122
+ if (isSecret) {
123
+ commentLines.push("# [SECRET]");
124
+ }
125
+ if (includeDescriptions) {
126
+ if (isRequired && schemaRecord?.default === void 0) {
127
+ commentLines.push("# required");
128
+ } else if (schemaRecord?.default !== void 0) {
129
+ commentLines.push("# optional");
130
+ } else if (schemaEntry?.optional === true) {
131
+ commentLines.push("# optional");
132
+ }
133
+ }
134
+ if (includeDefaults) {
135
+ if (schemaRecord?.default !== void 0) {
136
+ const defaultDisplay = isSecret ? "[REDACTED]" : String(schemaRecord.default);
137
+ commentLines.push(`# default: ${defaultDisplay}`);
138
+ } else if (schemaRecord?.hasDefault === true && typeof schemaRecord.rawDefaultValue === "string") {
139
+ const defaultDisplay = isSecret ? "[REDACTED]" : schemaRecord.rawDefaultValue;
140
+ commentLines.push(`# default: ${defaultDisplay}`);
141
+ }
142
+ }
143
+ for (const commentLine of commentLines) {
144
+ lines.push({ content: commentLine, order: order++ });
145
+ }
146
+ const exampleValue = buildExampleValue(envVar.value, isSecret, schemaEntry);
147
+ lines.push({
148
+ content: `${envVar.key}=${exampleValue}`,
149
+ order: order++
150
+ });
151
+ lines.push({ content: "", order: order++ });
152
+ }
153
+ lines.sort((a, b) => a.order - b.order);
154
+ return lines.map((line) => line.content).join("\n");
155
+ }
156
+ function buildExampleValue(value, isSecret, schema) {
157
+ if (isSecret) {
158
+ return "<your-secret-here>";
159
+ }
160
+ if (schema !== void 0) {
161
+ const enumValues = extractEnumValues(schema);
162
+ if (enumValues !== null && enumValues.length > 0) {
163
+ return enumValues[0] ?? "";
164
+ }
165
+ }
166
+ if (value === "") {
167
+ return "";
168
+ }
169
+ if (value.length <= 20 && !isSecretLike(value)) {
170
+ return maskValue(value, { visibleStart: 0, visibleEnd: 0, minLength: 1 });
171
+ }
172
+ return maskValue(value, { visibleStart: 0, visibleEnd: 0, minLength: 1 });
173
+ }
174
+ async function loadSchema(_schemaPath) {
175
+ void _schemaPath;
176
+ return void 0;
177
+ }
178
+ async function needsUpdate(envPath, examplePath, options) {
179
+ const envExists = await exists(envPath);
180
+ const exampleExists = await exists(examplePath);
181
+ if (envExists && !exampleExists) {
182
+ return true;
183
+ }
184
+ if (!envExists) {
185
+ return false;
186
+ }
187
+ const content = await readFile(envPath);
188
+ const schema = options?.schemaPath !== void 0 ? await loadSchema(options.schemaPath) : void 0;
189
+ const parsed = parseEnvFile(content, envPath);
190
+ const generated = generateExampleContent(parsed.vars, schema, {
191
+ includeDescriptions: options?.includeDescriptions ?? true,
192
+ includeTypes: options?.includeTypes ?? true,
193
+ includeDefaults: options?.includeDefaults ?? true
194
+ });
195
+ const existing = await readFile(examplePath);
196
+ return generated.trim() !== existing.trim();
197
+ }
198
+
199
+ export {
200
+ generateExampleFile,
201
+ generateExampleContent,
202
+ needsUpdate
203
+ };