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,91 @@
1
+ import {
2
+ writeFile
3
+ } from "./chunk-3VYXPTYV.js";
4
+
5
+ // src/typegen/declaration.ts
6
+ var DEFAULT_HEADER = "// Auto-generated by ultraenv \u2014 DO NOT EDIT";
7
+ function schemaTypeToTsType(schema) {
8
+ const r = schema;
9
+ const schemaType = r.type;
10
+ if (schemaType === "string" && Array.isArray(r.enum) && r.enum.length > 0) {
11
+ return r.enum.map((v) => `'${v}'`).join(" | ");
12
+ }
13
+ if (schemaType === "enum" && Array.isArray(r.values) && r.values.length > 0) {
14
+ return r.values.map((v) => `'${v}'`).join(" | ");
15
+ }
16
+ return "string";
17
+ }
18
+ function generateJSDoc(key, schema) {
19
+ const r = schema;
20
+ const lines = ["/**"];
21
+ if (schema.description !== void 0) {
22
+ lines.push(` * ${schema.description}`);
23
+ } else {
24
+ lines.push(` * ${key}`);
25
+ }
26
+ if (r.isSecret === true) {
27
+ lines.push(" * @secret");
28
+ }
29
+ const hasDefault = schema.default !== void 0 || r.hasDefault === true;
30
+ if (hasDefault) {
31
+ const rawDefault = r.rawDefaultValue;
32
+ const defaultVal = r.isSecret === true ? "[REDACTED]" : rawDefault ?? String(schema.default ?? "");
33
+ lines.push(` * @default ${defaultVal}`);
34
+ }
35
+ if (r.isDeprecated === true) {
36
+ const msg = r.deprecationMessage;
37
+ lines.push(` * @deprecated ${msg ?? "This variable is deprecated"}`);
38
+ }
39
+ lines.push(" */");
40
+ return lines.join("\n");
41
+ }
42
+ async function generateDeclaration(vars, schema, outputPath, options) {
43
+ const content = generateDeclarationContent(vars, schema, options);
44
+ if (outputPath !== void 0) {
45
+ await writeFile(outputPath, content);
46
+ }
47
+ return content;
48
+ }
49
+ function generateDeclarationContent(vars, schema, options) {
50
+ const includeJSDoc = options?.jsdoc ?? true;
51
+ const indent = options?.indent ?? 4;
52
+ const indentStr = " ".repeat(indent);
53
+ const header = options?.header ?? DEFAULT_HEADER;
54
+ const lines = [];
55
+ lines.push(header);
56
+ lines.push("");
57
+ const allKeys = /* @__PURE__ */ new Set();
58
+ for (const key of Object.keys(vars)) {
59
+ allKeys.add(key);
60
+ }
61
+ if (schema !== void 0) {
62
+ for (const key of Object.keys(schema)) {
63
+ allKeys.add(key);
64
+ }
65
+ }
66
+ const sortedKeys = Array.from(allKeys).sort();
67
+ lines.push("declare namespace NodeJS {");
68
+ lines.push(`${indentStr}interface ProcessEnv {`);
69
+ for (const key of sortedKeys) {
70
+ const schemaEntry = schema !== void 0 ? schema[key] : void 0;
71
+ if (includeJSDoc && schemaEntry !== void 0) {
72
+ lines.push("");
73
+ lines.push(`${indentStr}${indentStr}${generateJSDoc(key, schemaEntry)}`);
74
+ }
75
+ const tsType = schemaEntry !== void 0 ? schemaTypeToTsType(schemaEntry) : "string";
76
+ const r = schemaEntry;
77
+ const isOptional = schemaEntry === void 0 || schemaEntry.optional === true || schemaEntry.default !== void 0 || r?.hasDefault === true;
78
+ const optionalMarker = isOptional ? "?" : "";
79
+ lines.push(`${indentStr}${indentStr}${key}${optionalMarker}: ${tsType};`);
80
+ }
81
+ lines.push(`${indentStr}}`);
82
+ lines.push("}");
83
+ lines.push("");
84
+ lines.push("export {};");
85
+ return lines.join("\n");
86
+ }
87
+
88
+ export {
89
+ generateDeclaration,
90
+ generateDeclarationContent
91
+ };
@@ -0,0 +1,78 @@
1
+ // src/middleware/express.ts
2
+ function ultraenvMiddleware(options = {}) {
3
+ const {
4
+ exposePublic = true,
5
+ prefix = "PUBLIC_",
6
+ additionalPrefixes = [],
7
+ allowList = [],
8
+ denyList = [],
9
+ exposeNodeEnv = true,
10
+ source = process.env
11
+ } = options;
12
+ const allPrefixes = [prefix];
13
+ for (const p of additionalPrefixes) {
14
+ allPrefixes.push(p);
15
+ }
16
+ const allowSet = new Set(allowList.map((k) => k.toUpperCase()));
17
+ const denySet = new Set(denyList.map((k) => k.toUpperCase()));
18
+ const filteredEnv = buildFilteredEnv(
19
+ source,
20
+ allPrefixes,
21
+ allowSet,
22
+ denySet,
23
+ exposePublic,
24
+ exposeNodeEnv
25
+ );
26
+ return (_req, _res, next) => {
27
+ _req.env = filteredEnv;
28
+ next();
29
+ };
30
+ }
31
+ function buildFilteredEnv(source, prefixes, allowSet, denySet, exposePublic, exposeNodeEnv) {
32
+ if (!exposePublic) {
33
+ return {};
34
+ }
35
+ const env = {};
36
+ for (const [key, value] of Object.entries(source)) {
37
+ if (value === void 0 || value === "") continue;
38
+ const upperKey = key.toUpperCase();
39
+ if (denySet.has(upperKey)) continue;
40
+ if (allowSet.has(upperKey)) {
41
+ env[key] = value;
42
+ continue;
43
+ }
44
+ if (exposeNodeEnv && upperKey === "NODE_ENV") {
45
+ env[key] = value;
46
+ continue;
47
+ }
48
+ for (const p of prefixes) {
49
+ if (upperKey.startsWith(p.toUpperCase())) {
50
+ env[key] = value;
51
+ break;
52
+ }
53
+ }
54
+ }
55
+ return env;
56
+ }
57
+ function healthCheckRoute(options = {}) {
58
+ const { source = process.env, metadata = {} } = options;
59
+ return (_req, res) => {
60
+ const envKeys = Object.keys(source).filter(
61
+ (k) => source[k] !== void 0 && source[k] !== ""
62
+ );
63
+ const nodeEnv = source["NODE_ENV"] ?? "unknown";
64
+ const response = {
65
+ status: "ok",
66
+ loaded: envKeys.length,
67
+ environment: nodeEnv,
68
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
69
+ ...metadata
70
+ };
71
+ res.status(200).json(response);
72
+ };
73
+ }
74
+
75
+ export {
76
+ ultraenvMiddleware,
77
+ healthCheckRoute
78
+ };
@@ -0,0 +1,66 @@
1
+ // src/middleware/fastify.ts
2
+ function ultraenvPlugin(fastify, options = {}, done) {
3
+ const {
4
+ expose = true,
5
+ prefix = "PUBLIC_",
6
+ additionalPrefixes = [],
7
+ allowList = [],
8
+ denyList = [],
9
+ exposeNodeEnv = true,
10
+ source = process.env,
11
+ schema: _schema
12
+ } = options;
13
+ if (!expose) {
14
+ done();
15
+ return;
16
+ }
17
+ const allPrefixes = [prefix];
18
+ for (const p of additionalPrefixes) {
19
+ allPrefixes.push(p);
20
+ }
21
+ const allowSet = new Set(allowList.map((k) => k.toUpperCase()));
22
+ const denySet = new Set(denyList.map((k) => k.toUpperCase()));
23
+ const filteredEnv = buildFastifyEnv(
24
+ source,
25
+ allPrefixes,
26
+ allowSet,
27
+ denySet,
28
+ exposeNodeEnv
29
+ );
30
+ fastify.decorate("env", filteredEnv);
31
+ done();
32
+ }
33
+ function buildFastifyEnv(source, prefixes, allowSet, denySet, exposeNodeEnv) {
34
+ const env = {};
35
+ for (const [key, value] of Object.entries(source)) {
36
+ if (value === void 0 || value === "") continue;
37
+ const upperKey = key.toUpperCase();
38
+ if (denySet.has(upperKey)) continue;
39
+ if (allowSet.has(upperKey)) {
40
+ env[key] = value;
41
+ continue;
42
+ }
43
+ if (exposeNodeEnv && upperKey === "NODE_ENV") {
44
+ env[key] = value;
45
+ continue;
46
+ }
47
+ for (const p of prefixes) {
48
+ if (upperKey.startsWith(p.toUpperCase())) {
49
+ env[key] = value;
50
+ break;
51
+ }
52
+ }
53
+ }
54
+ return env;
55
+ }
56
+ function createUltraenvPlugin(_opts = {}) {
57
+ return {
58
+ name: "ultraenv",
59
+ handler: ultraenvPlugin
60
+ };
61
+ }
62
+
63
+ export {
64
+ ultraenvPlugin,
65
+ createUltraenvPlugin
66
+ };