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.
- package/LICENSE +21 -0
- package/README.md +2058 -0
- package/bin/ultraenv.mjs +3 -0
- package/dist/chunk-2USZPWLZ.js +288 -0
- package/dist/chunk-3UV2QNJL.js +270 -0
- package/dist/chunk-3VYXPTYV.js +179 -0
- package/dist/chunk-4XUYMRK5.js +366 -0
- package/dist/chunk-5G2DU52U.js +189 -0
- package/dist/chunk-6KS56D6E.js +172 -0
- package/dist/chunk-AWN6ADV7.js +328 -0
- package/dist/chunk-CHVO6NWI.js +203 -0
- package/dist/chunk-CIFMBJ4H.js +3975 -0
- package/dist/chunk-GC7RXHLA.js +253 -0
- package/dist/chunk-HFXQGJY3.js +445 -0
- package/dist/chunk-IGFVP24Q.js +91 -0
- package/dist/chunk-IKPTKALB.js +78 -0
- package/dist/chunk-JB7RKV3C.js +66 -0
- package/dist/chunk-MNVFG7H4.js +611 -0
- package/dist/chunk-MSXMESFP.js +1910 -0
- package/dist/chunk-N5PAV4NM.js +127 -0
- package/dist/chunk-NBOABPHM.js +158 -0
- package/dist/chunk-OMAOROL4.js +49 -0
- package/dist/chunk-R7PZRSZ7.js +105 -0
- package/dist/chunk-TE7HPLA6.js +73 -0
- package/dist/chunk-TMT5KCO3.js +101 -0
- package/dist/chunk-UEWYFN6A.js +189 -0
- package/dist/chunk-WMHN5RW2.js +128 -0
- package/dist/chunk-XC65ORJ5.js +70 -0
- package/dist/chunk-YMMP4VQL.js +118 -0
- package/dist/chunk-YN2KGTCB.js +33 -0
- package/dist/chunk-YTICOB5M.js +65 -0
- package/dist/chunk-YVWLXFUT.js +107 -0
- package/dist/ci-check-sync-VBMSVWIV.js +48 -0
- package/dist/ci-scan-24MT5XGS.js +41 -0
- package/dist/ci-setup-C2NKEFRD.js +135 -0
- package/dist/ci-validate-7AW24LSQ.js +57 -0
- package/dist/cli/index.cjs +9217 -0
- package/dist/cli/index.d.cts +9 -0
- package/dist/cli/index.d.ts +9 -0
- package/dist/cli/index.js +339 -0
- package/dist/comparator-RDKX3OI7.js +13 -0
- package/dist/completion-MW35C2XO.js +168 -0
- package/dist/config-O5YRQP5Z.js +13 -0
- package/dist/debug-PTPXAF3K.js +131 -0
- package/dist/declaration-LEME4AFZ.js +10 -0
- package/dist/doctor-FZAUPKHS.js +129 -0
- package/dist/envs-compare-5K3HESX5.js +49 -0
- package/dist/envs-create-2XXHXMGA.js +58 -0
- package/dist/envs-list-NQM5252B.js +59 -0
- package/dist/envs-switch-6L2AQYID.js +50 -0
- package/dist/envs-validate-FL73Q76T.js +89 -0
- package/dist/fs-VH7ATUS3.js +31 -0
- package/dist/generator-LFZBMZZS.js +14 -0
- package/dist/git-BZS4DPAI.js +30 -0
- package/dist/help-3XJBXEHE.js +121 -0
- package/dist/index.cjs +12907 -0
- package/dist/index.d.cts +2562 -0
- package/dist/index.d.ts +2562 -0
- package/dist/index.js +3212 -0
- package/dist/init-Y7JQ2KYJ.js +146 -0
- package/dist/install-hook-SKXIV6NV.js +111 -0
- package/dist/json-schema-I26YNQBH.js +10 -0
- package/dist/key-manager-O3G55WPU.js +25 -0
- package/dist/middleware/express.cjs +103 -0
- package/dist/middleware/express.d.cts +115 -0
- package/dist/middleware/express.d.ts +115 -0
- package/dist/middleware/express.js +8 -0
- package/dist/middleware/fastify.cjs +91 -0
- package/dist/middleware/fastify.d.cts +111 -0
- package/dist/middleware/fastify.d.ts +111 -0
- package/dist/middleware/fastify.js +8 -0
- package/dist/module-IDIZPP4M.js +10 -0
- package/dist/protect-NCWPM6VC.js +161 -0
- package/dist/scan-TRLY36TT.js +58 -0
- package/dist/schema/index.cjs +4074 -0
- package/dist/schema/index.d.cts +1244 -0
- package/dist/schema/index.d.ts +1244 -0
- package/dist/schema/index.js +152 -0
- package/dist/sync-TMHMTLH2.js +186 -0
- package/dist/typegen-SQOSXBWM.js +80 -0
- package/dist/validate-IOAM5HWS.js +100 -0
- package/dist/vault-decrypt-U6HJZNBV.js +111 -0
- package/dist/vault-diff-B3ZOQTWI.js +132 -0
- package/dist/vault-encrypt-GUSLCSKS.js +112 -0
- package/dist/vault-init-GUBOTOUL.js +106 -0
- package/dist/vault-rekey-DAHT7JCN.js +132 -0
- package/dist/vault-status-GDLRU2OK.js +90 -0
- package/dist/vault-verify-CD76FJSF.js +102 -0
- 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
|
+
};
|