@voltro/env 0.85.0 → 0.87.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/CHANGELOG.md +5987 -0
- package/THIRD-PARTY-NOTICES.md +864 -253
- package/dist/define.js +7 -0
- package/dist/field.js +50 -0
- package/dist/index.d.ts +18 -1
- package/dist/index.js +7 -182
- package/dist/manifest.js +80 -0
- package/dist/pluginEnv.js +13 -0
- package/dist/server.d.ts +5 -2
- package/dist/server.js +9 -9
- package/dist/{snapshot-vq9tc5Zu.js → snapshot.js} +3 -6
- package/dist/validate.js +66 -0
- package/package.json +2 -2
package/dist/define.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/define.ts
|
|
2
|
+
var e = "VOLTRO_PUBLIC_", t = (e, t) => Object.freeze({
|
|
3
|
+
vars: Object.freeze({ ...e }),
|
|
4
|
+
publicPrefix: t?.publicPrefix ?? "VOLTRO_PUBLIC_"
|
|
5
|
+
}), n = (e) => typeof e == "object" && !!e && "vars" in e && typeof e.vars == "object" && e.vars !== null;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { e as DEFAULT_PUBLIC_PREFIX, t as defineEnv, n as isEnvContract };
|
package/dist/field.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Effect as e, Result as t, Schema as n, SchemaGetter as r, SchemaIssue as i } from "effect";
|
|
2
|
+
//#region src/field.ts
|
|
3
|
+
var a = (e, r, i, a) => ({
|
|
4
|
+
kind: e,
|
|
5
|
+
access: a.access,
|
|
6
|
+
schema: r,
|
|
7
|
+
decode: (e) => {
|
|
8
|
+
let i = n.decodeUnknownResult(r)(e);
|
|
9
|
+
return t.isSuccess(i) ? {
|
|
10
|
+
ok: !0,
|
|
11
|
+
value: i.success
|
|
12
|
+
} : {
|
|
13
|
+
ok: !1,
|
|
14
|
+
message: i.failure.message
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
tsType: i,
|
|
18
|
+
optional: a.optional ?? !1,
|
|
19
|
+
...a.default === void 0 ? {} : { default: a.default },
|
|
20
|
+
...a.description === void 0 ? {} : { description: a.description },
|
|
21
|
+
...a.example === void 0 ? {} : { example: a.example }
|
|
22
|
+
}), o = n.String.pipe(n.decodeTo(n.Boolean, {
|
|
23
|
+
decode: r.transformEffect((t) => {
|
|
24
|
+
let n = t.trim().toLowerCase();
|
|
25
|
+
return n === "true" || n === "1" || n === "yes" || n === "on" ? e.succeed(!0) : n === "false" || n === "0" || n === "no" || n === "off" || n === "" ? e.succeed(!1) : e.fail(new i.InvalidValue({ message: `expected a boolean (true/false/1/0/yes/no/on/off), got "${t}"` }, t));
|
|
26
|
+
}),
|
|
27
|
+
encode: r.transform((e) => e ? "true" : "false")
|
|
28
|
+
})), s = (e) => URL.canParse(e), c = {
|
|
29
|
+
string: (e) => a("string", n.String, "string", e),
|
|
30
|
+
number: (e) => a("number", n.NumberFromString.pipe(n.check(n.isFinite())), "number", e),
|
|
31
|
+
port: (e) => a("port", n.NumberFromString.pipe(n.check(n.isInt()), n.check(n.isBetween({
|
|
32
|
+
minimum: 1,
|
|
33
|
+
maximum: 65535
|
|
34
|
+
}))), "number", e),
|
|
35
|
+
boolean: (e) => a("boolean", o, "boolean", e),
|
|
36
|
+
secret: (e) => {
|
|
37
|
+
let t = e.minLength ?? 32;
|
|
38
|
+
return {
|
|
39
|
+
...a("secret", n.String.pipe(n.check(n.makeFilter((e) => e.trim().length >= t || `expected at least ${t} characters — this looks like a placeholder, not a secret. Generate one with \`voltro secret generate\``))), "string", {
|
|
40
|
+
...e,
|
|
41
|
+
access: "secret"
|
|
42
|
+
}),
|
|
43
|
+
...e.generate === void 0 ? {} : { generate: e.generate }
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
url: (e) => a("url", n.String.pipe(n.check(n.makeFilter((e) => s(e) || `expected a valid URL, got "${e}"`))), "string", e),
|
|
47
|
+
enum: (e, t) => a("enum", n.Literals(e), e.map((e) => `'${e}'`).join(" | "), t)
|
|
48
|
+
};
|
|
49
|
+
//#endregion
|
|
50
|
+
export { c as envVar };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,12 +5,13 @@ import { Schema } from 'effect';
|
|
|
5
5
|
* declared map, iteration). It is NOT `EnvFieldSpec<unknown>` because
|
|
6
6
|
* effect's `Schema` is invariant in its decoded type — a concrete
|
|
7
7
|
* `EnvFieldSpec<number>` would not widen to that. Typing the schema as
|
|
8
|
-
* `Schema.
|
|
8
|
+
* `Schema.Top` lets any concrete field assign here.
|
|
9
9
|
*/
|
|
10
10
|
export declare interface AnyEnvFieldSpec {
|
|
11
11
|
readonly kind: EnvFieldKind;
|
|
12
12
|
readonly access: EnvAccess;
|
|
13
13
|
readonly schema: Schema.Top;
|
|
14
|
+
readonly decode: (raw: string) => EnvDecodeOutcome;
|
|
14
15
|
readonly tsType: string;
|
|
15
16
|
readonly optional: boolean;
|
|
16
17
|
readonly default?: string | undefined;
|
|
@@ -121,6 +122,15 @@ export declare interface EnvContract<M extends EnvSchemaMap = EnvSchemaMap> {
|
|
|
121
122
|
readonly _public?: PublicEnvValues<M>;
|
|
122
123
|
}
|
|
123
124
|
|
|
125
|
+
/** What {@link EnvFieldSpec.decode} returns — plain data, no `effect` types. */
|
|
126
|
+
export declare type EnvDecodeOutcome<A = unknown> = {
|
|
127
|
+
readonly ok: true;
|
|
128
|
+
readonly value: A;
|
|
129
|
+
} | {
|
|
130
|
+
readonly ok: false;
|
|
131
|
+
readonly message: string;
|
|
132
|
+
};
|
|
133
|
+
|
|
124
134
|
/** The concrete coercion a field performs on the raw string env value. */
|
|
125
135
|
export declare type EnvFieldKind = 'string' | 'number' | 'boolean' | 'enum' | 'url' | 'port' | 'secret';
|
|
126
136
|
|
|
@@ -136,6 +146,13 @@ export declare interface EnvFieldSpec<A = unknown, Optional extends boolean = bo
|
|
|
136
146
|
readonly access: EnvAccess;
|
|
137
147
|
/** effect/Schema that decodes the RAW string env value → typed `A`. */
|
|
138
148
|
readonly schema: Schema.Codec<A, string>;
|
|
149
|
+
/**
|
|
150
|
+
* Decodes a raw value with the copy of `effect` that built `schema`. A boot
|
|
151
|
+
* path bundled with its own `effect` (a precompiled `voltro start`) must not
|
|
152
|
+
* run this schema through its parser: the two copies' internal sentinels
|
|
153
|
+
* differ. The outcome is a plain object, so it crosses copies unchanged.
|
|
154
|
+
*/
|
|
155
|
+
readonly decode: (raw: string) => EnvDecodeOutcome<A>;
|
|
139
156
|
/**
|
|
140
157
|
* TypeScript type literal for the codegen'd typed accessors — e.g.
|
|
141
158
|
* `"string"`, `"number"`, `"'dev' | 'prod'"`. Bounded to what the
|
package/dist/index.js
CHANGED
|
@@ -1,182 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
kind: e,
|
|
9
|
-
access: r.access,
|
|
10
|
-
schema: t,
|
|
11
|
-
tsType: n,
|
|
12
|
-
optional: r.optional ?? !1,
|
|
13
|
-
...r.default === void 0 ? {} : { default: r.default },
|
|
14
|
-
...r.description === void 0 ? {} : { description: r.description },
|
|
15
|
-
...r.example === void 0 ? {} : { example: r.example }
|
|
16
|
-
}), v = d.String.pipe(d.decodeTo(d.Boolean, {
|
|
17
|
-
decode: f.transformEffect((e) => {
|
|
18
|
-
let t = e.trim().toLowerCase();
|
|
19
|
-
return t === "true" || t === "1" || t === "yes" || t === "on" ? l.succeed(!0) : t === "false" || t === "0" || t === "no" || t === "off" || t === "" ? l.succeed(!1) : l.fail(new p.InvalidValue({ message: `expected a boolean (true/false/1/0/yes/no/on/off), got "${e}"` }, e));
|
|
20
|
-
}),
|
|
21
|
-
encode: f.transform((e) => e ? "true" : "false")
|
|
22
|
-
})), y = (e) => URL.canParse(e), b = {
|
|
23
|
-
string: (e) => _("string", d.String, "string", e),
|
|
24
|
-
number: (e) => _("number", d.NumberFromString.pipe(d.check(d.isFinite())), "number", e),
|
|
25
|
-
port: (e) => _("port", d.NumberFromString.pipe(d.check(d.isInt()), d.check(d.isBetween({
|
|
26
|
-
minimum: 1,
|
|
27
|
-
maximum: 65535
|
|
28
|
-
}))), "number", e),
|
|
29
|
-
boolean: (e) => _("boolean", v, "boolean", e),
|
|
30
|
-
secret: (e) => {
|
|
31
|
-
let t = e.minLength ?? 32;
|
|
32
|
-
return {
|
|
33
|
-
..._("secret", d.String.pipe(d.check(d.makeFilter((e) => e.trim().length >= t || `expected at least ${t} characters — this looks like a placeholder, not a secret. Generate one with \`voltro secret generate\``))), "string", {
|
|
34
|
-
...e,
|
|
35
|
-
access: "secret"
|
|
36
|
-
}),
|
|
37
|
-
...e.generate === void 0 ? {} : { generate: e.generate }
|
|
38
|
-
};
|
|
39
|
-
},
|
|
40
|
-
url: (e) => _("url", d.String.pipe(d.check(d.makeFilter((e) => y(e) || `expected a valid URL, got "${e}"`))), "string", e),
|
|
41
|
-
enum: (e, t) => _("enum", d.Literals(e), e.map((e) => `'${e}'`).join(" | "), t)
|
|
42
|
-
}, x = (e, t, n) => {
|
|
43
|
-
let r = t.schema, i = d.decodeUnknownResult(r)(n);
|
|
44
|
-
return u.mapError(i, (n) => ({
|
|
45
|
-
key: e,
|
|
46
|
-
access: t.access,
|
|
47
|
-
reason: "invalid",
|
|
48
|
-
message: n.message
|
|
49
|
-
}));
|
|
50
|
-
}, S = async (e) => {
|
|
51
|
-
let t = e.readEnv ?? ((e) => process.env[e]), n = e.resolveSecret ?? ((e) => Promise.resolve(t(e))), r = {}, i = {}, a = [], o = e.contract ? Object.entries(e.contract.vars) : [];
|
|
52
|
-
for (let [e, s] of o) {
|
|
53
|
-
let o = (s.access === "secret" ? await n(e) : t(e)) ?? s.default;
|
|
54
|
-
if (o === void 0) {
|
|
55
|
-
s.optional ? (r[e] = void 0, s.access === "public" && (i[e] = void 0)) : a.push({
|
|
56
|
-
key: e,
|
|
57
|
-
access: s.access,
|
|
58
|
-
reason: "missing",
|
|
59
|
-
message: `required ${s.access} env var "${e}" is unset` + (s.description ? ` — ${s.description}` : "")
|
|
60
|
-
});
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
let c = x(e, s, o);
|
|
64
|
-
if (u.isFailure(c)) {
|
|
65
|
-
a.push(c.failure);
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
r[e] = c.success, s.access === "public" && (i[e] = c.success);
|
|
69
|
-
}
|
|
70
|
-
return {
|
|
71
|
-
values: r,
|
|
72
|
-
publicValues: i,
|
|
73
|
-
errors: a,
|
|
74
|
-
ok: a.length === 0
|
|
75
|
-
};
|
|
76
|
-
}, C = (e, t) => {
|
|
77
|
-
let n = e?.publicPrefix;
|
|
78
|
-
if (!e || typeof n != "string") return [];
|
|
79
|
-
let r = [];
|
|
80
|
-
for (let [i, a] of Object.entries(e.vars)) a.access === "secret" && i.startsWith(n) && r.push({
|
|
81
|
-
key: i,
|
|
82
|
-
access: "secret",
|
|
83
|
-
reason: "invalid",
|
|
84
|
-
message: `secret env var "${i}" must NOT use the public prefix "${n}" — that prefix marks browser-exposed PUBLIC values; a secret carrying it is a contradiction.`
|
|
85
|
-
}), t === "web" && a.access === "public" && !i.startsWith(n) && r.push({
|
|
86
|
-
key: i,
|
|
87
|
-
access: "public",
|
|
88
|
-
reason: "invalid",
|
|
89
|
-
message: `public env var "${i}" on a web app ships to the browser and must be named "${n}…" (e.g. "${n}${i}"). Rename it, mark it access:'secret' to keep it server-only, or set publicPrefix:false in defineEnv to opt out.`
|
|
90
|
-
});
|
|
91
|
-
return r;
|
|
92
|
-
}, w = (e) => {
|
|
93
|
-
let t = e.map((e) => ` • ${e.key} (${e.access}, ${e.reason}): ${e.message}`);
|
|
94
|
-
return `environment validation failed (${e.length} ${e.length === 1 ? "error" : "errors"}):\n${t.join("\n")}`;
|
|
95
|
-
}, T = (e) => e ? Object.entries(e.vars).map(([e, t]) => ({
|
|
96
|
-
key: e,
|
|
97
|
-
owner: "app",
|
|
98
|
-
access: t.access,
|
|
99
|
-
required: !t.optional && t.default === void 0,
|
|
100
|
-
...t.description === void 0 ? {} : { description: t.description },
|
|
101
|
-
...t.example === void 0 ? {} : { example: t.example },
|
|
102
|
-
...t.default === void 0 ? {} : { default: t.default },
|
|
103
|
-
kind: t.kind
|
|
104
|
-
})) : [], E = (e, t) => t ? t.map((t) => ({
|
|
105
|
-
key: t.name,
|
|
106
|
-
owner: `plugin:${e}`,
|
|
107
|
-
access: t.secret ? "secret" : "public",
|
|
108
|
-
required: t.required,
|
|
109
|
-
...t.description === void 0 ? {} : { description: t.description },
|
|
110
|
-
...t.example === void 0 ? {} : { example: t.example }
|
|
111
|
-
})) : [], D = (e, t, n, r, i) => ({
|
|
112
|
-
key: e,
|
|
113
|
-
owner: "framework",
|
|
114
|
-
access: n,
|
|
115
|
-
required: !1,
|
|
116
|
-
description: r,
|
|
117
|
-
group: t,
|
|
118
|
-
...i === void 0 ? {} : { example: i }
|
|
119
|
-
}), O = [
|
|
120
|
-
D("NODE_ENV", "runtime", "public", "Node environment (development | production).", "development"),
|
|
121
|
-
D("PORT", "runtime", "public", "Port the api/web server binds to. Overrides app.config `port`.", "4000"),
|
|
122
|
-
D("VOLTRO_REGION", "runtime", "public", "Region tag for replica locality (else AWS_REGION/FLY_REGION/…).", "us-east-1"),
|
|
123
|
-
D("VOLTRO_AUTO_MIGRATE", "runtime", "public", "Set 0 to skip boot auto-migrate (CI-applied migrations).", "1"),
|
|
124
|
-
D("DB_DIALECT", "database", "public", "postgres | mysql | mariadb | mssql | sqlite | memory.", "postgres"),
|
|
125
|
-
D("DB_URL", "database", "secret", "Connection URL (carries credentials). Preferred over discrete DB_* fields.", "postgres://user:pw@localhost:5432/app"),
|
|
126
|
-
D("DB_HOST", "database", "public", "Database host (discrete-field form; DB_URL preferred).", "localhost"),
|
|
127
|
-
D("DB_PORT", "database", "public", "Database port.", "5432"),
|
|
128
|
-
D("DB_USER", "database", "public", "Database user.", "postgres"),
|
|
129
|
-
D("DB_PASSWORD", "database", "secret", "Database password."),
|
|
130
|
-
D("DB_DATABASE", "database", "public", "Database name.", "app"),
|
|
131
|
-
D("DB_MAX_CONNECTIONS", "database", "public", "Per-process connection pool cap.", "10"),
|
|
132
|
-
D("DB_REPLICA_URLS", "database", "secret", "Comma-separated read-replica URLs (carry credentials)."),
|
|
133
|
-
D("DB_REPLICA_REGIONS", "database", "public", "Comma-separated region tags matching DB_REPLICA_URLS order."),
|
|
134
|
-
D("RYW_STORE", "database", "public", "Read-your-writes position store: memory | redis.", "memory"),
|
|
135
|
-
D("CACHE_BACKEND", "cache", "public", "@voltro/cache backend: memory | redis.", "memory"),
|
|
136
|
-
D("CACHE_REDIS_URL", "cache", "secret", "Redis/Valkey/KeyDB/Dragonfly/Upstash URL (may carry credentials).", "redis://localhost:6379"),
|
|
137
|
-
D("CACHE_REDIS_DRIVER", "cache", "public", "resp (ioredis TCP) | http (Upstash REST, edge).", "resp"),
|
|
138
|
-
D("CACHE_REDIS_TOKEN", "cache", "secret", "Upstash REST token (http driver)."),
|
|
139
|
-
D("CACHE_KEY_PREFIX", "cache", "public", "Cache key namespace.", "voltro:cache"),
|
|
140
|
-
D("REDIS_URL", "cache", "secret", "Generic Redis URL fallback (cache / ryw / ratelimit).", "redis://localhost:6379"),
|
|
141
|
-
D("VOLTRO_SESSION_SECRET", "security", "secret", "HMAC signing key for session cookies. REQUIRED in production."),
|
|
142
|
-
D("VOLTRO_INSPECT", "security", "public", "Set off to disable the /_voltro/inspect surface entirely.", "on"),
|
|
143
|
-
D("VOLTRO_INSPECT_TOKEN", "security", "secret", "Bearer token gating /_voltro/inspect/* on public deploys."),
|
|
144
|
-
D("VOLTRO_WEB_REPLICA_GROUP", "observability", "public", "Deployment-specific Web/SSR replica discovery group in PostgreSQL. Use a distinct value per app and environment."),
|
|
145
|
-
D("VOLTRO_TENANT_ISOLATION", "security", "public", "shared-schema (default) | namespace (physical per-tenant)."),
|
|
146
|
-
D("FRAMEWORK_TRACING", "observability", "public", "off | console | otlp. Auto-otlp when OTEL_* is set."),
|
|
147
|
-
D("OTEL_EXPORTER_OTLP_ENDPOINT", "observability", "public", "OTLP/HTTP collector endpoint (traces + metrics).", "http://localhost:4318"),
|
|
148
|
-
D("OTEL_SERVICE_NAME", "observability", "public", "OTel service name.", "voltro-api"),
|
|
149
|
-
D("SSR_CACHE", "web", "public", "ISR cache backend for `voltro start`: memory | postgres.", "memory")
|
|
150
|
-
], k = () => O.map((e) => e.key), A = (e) => {
|
|
151
|
-
let t = [];
|
|
152
|
-
e.description && t.push(`# ${e.description}`);
|
|
153
|
-
let n = [
|
|
154
|
-
e.required ? "required" : "optional",
|
|
155
|
-
e.access,
|
|
156
|
-
...e.kind ? [e.kind] : []
|
|
157
|
-
].join(", ");
|
|
158
|
-
t.push(`# (${n})`);
|
|
159
|
-
let r = e.example ?? e.default ?? "";
|
|
160
|
-
return t.push(`${e.key}=${e.access === "secret" && !e.example ? "" : r}`), t.join("\n");
|
|
161
|
-
}, j = (e, t = {}) => {
|
|
162
|
-
let n = [], r = t.header ?? ["Environment for this app — generated from app.config.ts `env` + plugin declarations.", "Regenerate with `voltro env sync`. Copy to `.env` and fill in the blanks."];
|
|
163
|
-
n.push(...r.map((e) => `# ${e}`), "");
|
|
164
|
-
let i = e.filter((e) => e.owner === "app"), a = e.filter((e) => e.owner.startsWith("plugin:"));
|
|
165
|
-
if (i.length > 0 && (n.push("# ── App ──────────────────────────────────────────────", ""), n.push(...i.map(A).flatMap((e) => [e, ""]))), a.length > 0 && (n.push("# ── Plugins ──────────────────────────────────────────", ""), n.push(...a.map(A).flatMap((e) => [e, ""]))), t.includeFramework !== !1) {
|
|
166
|
-
let e = [...new Set(O.map((e) => e.group))];
|
|
167
|
-
n.push("# ── Framework ────────────────────────────────────────", "");
|
|
168
|
-
for (let t of e) n.push(`# [${t}]`), n.push(...O.filter((e) => e.group === t).map(A).flatMap((e) => [e, ""]));
|
|
169
|
-
}
|
|
170
|
-
return n.join("\n").replace(/\n{3,}/g, "\n\n").trimEnd() + "\n";
|
|
171
|
-
}, M = (e) => {
|
|
172
|
-
let t = new Set(e.map((e) => e.name));
|
|
173
|
-
return {
|
|
174
|
-
declared: e,
|
|
175
|
-
read: (e, n) => {
|
|
176
|
-
if (!t.has(e)) throw Error(`@voltro/env: plugin read of undeclared env var "${e}" — add it to the pluginEnv([...]) declaration so the manifest stays in sync.`);
|
|
177
|
-
return n ?? process.env[e];
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
};
|
|
181
|
-
//#endregion
|
|
182
|
-
export { m as DEFAULT_PUBLIC_PREFIX, O as FRAMEWORK_ENV_CATALOG, T as appEnvEntries, C as checkEnvNaming, h as defineEnv, b as envVar, w as formatEnvErrors, k as frameworkEnvNames, c as hasEnvSnapshot, i as hasLiveOverlap, o as installEnvSnapshot, g as isEnvContract, M as pluginEnv, E as pluginEnvEntries, n as readEnvValue, e as readEnvValuePrevious, a as refreshEnvValue, j as renderDotEnvExample, s as requireEnvValue, t as resetEnvSnapshot, S as resolveEnv, r as setEnvClock };
|
|
1
|
+
import { DEFAULT_PUBLIC_PREFIX as e, defineEnv as t, isEnvContract as n } from "./define.js";
|
|
2
|
+
import { envVar as r } from "./field.js";
|
|
3
|
+
import { checkEnvNaming as i, formatEnvErrors as a, resolveEnv as o } from "./validate.js";
|
|
4
|
+
import { hasEnvSnapshot as s, hasLiveOverlap as c, installEnvSnapshot as l, readEnvValue as u, readEnvValuePrevious as d, refreshEnvValue as f, requireEnvValue as p, resetEnvSnapshot as m, setEnvClock as h } from "./snapshot.js";
|
|
5
|
+
import { FRAMEWORK_ENV_CATALOG as g, appEnvEntries as _, frameworkEnvNames as v, pluginEnvEntries as y, renderDotEnvExample as b } from "./manifest.js";
|
|
6
|
+
import { pluginEnv as x } from "./pluginEnv.js";
|
|
7
|
+
export { e as DEFAULT_PUBLIC_PREFIX, g as FRAMEWORK_ENV_CATALOG, _ as appEnvEntries, i as checkEnvNaming, t as defineEnv, r as envVar, a as formatEnvErrors, v as frameworkEnvNames, s as hasEnvSnapshot, c as hasLiveOverlap, l as installEnvSnapshot, n as isEnvContract, x as pluginEnv, y as pluginEnvEntries, u as readEnvValue, d as readEnvValuePrevious, f as refreshEnvValue, b as renderDotEnvExample, p as requireEnvValue, m as resetEnvSnapshot, o as resolveEnv, h as setEnvClock };
|
package/dist/manifest.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
//#region src/manifest.ts
|
|
2
|
+
var e = (e) => e ? Object.entries(e.vars).map(([e, t]) => ({
|
|
3
|
+
key: e,
|
|
4
|
+
owner: "app",
|
|
5
|
+
access: t.access,
|
|
6
|
+
required: !t.optional && t.default === void 0,
|
|
7
|
+
...t.description === void 0 ? {} : { description: t.description },
|
|
8
|
+
...t.example === void 0 ? {} : { example: t.example },
|
|
9
|
+
...t.default === void 0 ? {} : { default: t.default },
|
|
10
|
+
kind: t.kind
|
|
11
|
+
})) : [], t = (e, t) => t ? t.map((t) => ({
|
|
12
|
+
key: t.name,
|
|
13
|
+
owner: `plugin:${e}`,
|
|
14
|
+
access: t.secret ? "secret" : "public",
|
|
15
|
+
required: t.required,
|
|
16
|
+
...t.description === void 0 ? {} : { description: t.description },
|
|
17
|
+
...t.example === void 0 ? {} : { example: t.example }
|
|
18
|
+
})) : [], n = (e, t, n, r, i) => ({
|
|
19
|
+
key: e,
|
|
20
|
+
owner: "framework",
|
|
21
|
+
access: n,
|
|
22
|
+
required: !1,
|
|
23
|
+
description: r,
|
|
24
|
+
group: t,
|
|
25
|
+
...i === void 0 ? {} : { example: i }
|
|
26
|
+
}), r = [
|
|
27
|
+
n("NODE_ENV", "runtime", "public", "Node environment (development | production).", "development"),
|
|
28
|
+
n("PORT", "runtime", "public", "Port the api/web server binds to. Overrides app.config `port`.", "4000"),
|
|
29
|
+
n("VOLTRO_REGION", "runtime", "public", "Region tag for replica locality (else AWS_REGION/FLY_REGION/…).", "us-east-1"),
|
|
30
|
+
n("VOLTRO_AUTO_MIGRATE", "runtime", "public", "Set 0 to skip boot auto-migrate (CI-applied migrations).", "1"),
|
|
31
|
+
n("DB_DIALECT", "database", "public", "postgres | mysql | mariadb | mssql | sqlite | memory.", "postgres"),
|
|
32
|
+
n("DB_URL", "database", "secret", "Connection URL (carries credentials). Preferred over discrete DB_* fields.", "postgres://user:pw@localhost:5432/app"),
|
|
33
|
+
n("DB_HOST", "database", "public", "Database host (discrete-field form; DB_URL preferred).", "localhost"),
|
|
34
|
+
n("DB_PORT", "database", "public", "Database port.", "5432"),
|
|
35
|
+
n("DB_USER", "database", "public", "Database user.", "postgres"),
|
|
36
|
+
n("DB_PASSWORD", "database", "secret", "Database password."),
|
|
37
|
+
n("DB_DATABASE", "database", "public", "Database name.", "app"),
|
|
38
|
+
n("DB_MAX_CONNECTIONS", "database", "public", "Per-process connection pool cap.", "10"),
|
|
39
|
+
n("DB_REPLICA_URLS", "database", "secret", "Comma-separated read-replica URLs (carry credentials)."),
|
|
40
|
+
n("DB_REPLICA_REGIONS", "database", "public", "Comma-separated region tags matching DB_REPLICA_URLS order."),
|
|
41
|
+
n("RYW_STORE", "database", "public", "Read-your-writes position store: memory | redis.", "memory"),
|
|
42
|
+
n("CACHE_BACKEND", "cache", "public", "@voltro/cache backend: memory | redis.", "memory"),
|
|
43
|
+
n("CACHE_REDIS_URL", "cache", "secret", "Redis/Valkey/KeyDB/Dragonfly/Upstash URL (may carry credentials).", "redis://localhost:6379"),
|
|
44
|
+
n("CACHE_REDIS_DRIVER", "cache", "public", "resp (ioredis TCP) | http (Upstash REST, edge).", "resp"),
|
|
45
|
+
n("CACHE_REDIS_TOKEN", "cache", "secret", "Upstash REST token (http driver)."),
|
|
46
|
+
n("CACHE_KEY_PREFIX", "cache", "public", "Cache key namespace.", "voltro:cache"),
|
|
47
|
+
n("REDIS_URL", "cache", "secret", "Generic Redis URL fallback (cache / ryw / ratelimit).", "redis://localhost:6379"),
|
|
48
|
+
n("VOLTRO_SESSION_SECRET", "security", "secret", "HMAC signing key for session cookies. REQUIRED in production."),
|
|
49
|
+
n("VOLTRO_INSPECT", "security", "public", "Set off to disable the /_voltro/inspect surface entirely.", "on"),
|
|
50
|
+
n("VOLTRO_INSPECT_TOKEN", "security", "secret", "Bearer token gating /_voltro/inspect/* on public deploys."),
|
|
51
|
+
n("VOLTRO_WEB_REPLICA_GROUP", "observability", "public", "Deployment-specific Web/SSR replica discovery group in PostgreSQL. Use a distinct value per app and environment."),
|
|
52
|
+
n("VOLTRO_TENANT_ISOLATION", "security", "public", "shared-schema (default) | namespace (physical per-tenant)."),
|
|
53
|
+
n("FRAMEWORK_TRACING", "observability", "public", "off | console | otlp. Auto-otlp when OTEL_* is set."),
|
|
54
|
+
n("OTEL_EXPORTER_OTLP_ENDPOINT", "observability", "public", "OTLP/HTTP collector endpoint (traces + metrics).", "http://localhost:4318"),
|
|
55
|
+
n("OTEL_SERVICE_NAME", "observability", "public", "OTel service name.", "voltro-api"),
|
|
56
|
+
n("SSR_CACHE", "web", "public", "ISR cache backend for `voltro start`: memory | postgres.", "memory")
|
|
57
|
+
], i = () => r.map((e) => e.key), a = (e) => {
|
|
58
|
+
let t = [];
|
|
59
|
+
e.description && t.push(`# ${e.description}`);
|
|
60
|
+
let n = [
|
|
61
|
+
e.required ? "required" : "optional",
|
|
62
|
+
e.access,
|
|
63
|
+
...e.kind ? [e.kind] : []
|
|
64
|
+
].join(", ");
|
|
65
|
+
t.push(`# (${n})`);
|
|
66
|
+
let r = e.example ?? e.default ?? "";
|
|
67
|
+
return t.push(`${e.key}=${e.access === "secret" && !e.example ? "" : r}`), t.join("\n");
|
|
68
|
+
}, o = (e, t = {}) => {
|
|
69
|
+
let n = [], i = t.header ?? ["Environment for this app — generated from app.config.ts `env` + plugin declarations.", "Regenerate with `voltro env sync`. Copy to `.env` and fill in the blanks."];
|
|
70
|
+
n.push(...i.map((e) => `# ${e}`), "");
|
|
71
|
+
let o = e.filter((e) => e.owner === "app"), s = e.filter((e) => e.owner.startsWith("plugin:"));
|
|
72
|
+
if (o.length > 0 && (n.push("# ── App ──────────────────────────────────────────────", ""), n.push(...o.map(a).flatMap((e) => [e, ""]))), s.length > 0 && (n.push("# ── Plugins ──────────────────────────────────────────", ""), n.push(...s.map(a).flatMap((e) => [e, ""]))), t.includeFramework !== !1) {
|
|
73
|
+
let e = [...new Set(r.map((e) => e.group))];
|
|
74
|
+
n.push("# ── Framework ────────────────────────────────────────", "");
|
|
75
|
+
for (let t of e) n.push(`# [${t}]`), n.push(...r.filter((e) => e.group === t).map(a).flatMap((e) => [e, ""]));
|
|
76
|
+
}
|
|
77
|
+
return n.join("\n").replace(/\n{3,}/g, "\n\n").trimEnd() + "\n";
|
|
78
|
+
};
|
|
79
|
+
//#endregion
|
|
80
|
+
export { r as FRAMEWORK_ENV_CATALOG, e as appEnvEntries, i as frameworkEnvNames, t as pluginEnvEntries, o as renderDotEnvExample };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/pluginEnv.ts
|
|
2
|
+
var e = (e) => {
|
|
3
|
+
let t = new Set(e.map((e) => e.name));
|
|
4
|
+
return {
|
|
5
|
+
declared: e,
|
|
6
|
+
read: (e, n) => {
|
|
7
|
+
if (!t.has(e)) throw Error(`@voltro/env: plugin read of undeclared env var "${e}" — add it to the pluginEnv([...]) declaration so the manifest stays in sync.`);
|
|
8
|
+
return n ?? process.env[e];
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { e as pluginEnv };
|
package/dist/server.d.ts
CHANGED
|
@@ -45,8 +45,11 @@ export declare const resolveSecretLive: (key: string) => Promise<string | undefi
|
|
|
45
45
|
* accept both during cutover reads `getSecretWithOverlap`.
|
|
46
46
|
*
|
|
47
47
|
* IMPORTANT — scope of "without a restart". This updates what CODE that reads a
|
|
48
|
-
* secret PER USE sees (an outbound API key,
|
|
49
|
-
*
|
|
48
|
+
* secret PER USE through `getSecret` sees (an outbound API key, an app's own
|
|
49
|
+
* verifier). It does not reach the framework's own secrets: the field keyring is
|
|
50
|
+
* built once at boot, and the session/storage/OG/token secrets are read from the
|
|
51
|
+
* environment — they rotate with `voltro secret rotate`. Nor does it
|
|
52
|
+
* re-establish a connection that captured the
|
|
50
53
|
* old value at construction — a live DB pool built with the old `DB_URL`
|
|
51
54
|
* password keeps that connection until it is rebuilt (still a restart, or a
|
|
52
55
|
* pool-level reconnect). Rotate connection credentials with that in mind.
|
package/dist/server.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readEnvValue as e, readEnvValuePrevious as t, refreshEnvValue as n, requireEnvValue as r } from "./snapshot.js";
|
|
2
2
|
import { resolveSecret as i } from "@voltro/runtime";
|
|
3
3
|
//#region src/server.ts
|
|
4
4
|
var a = new Proxy({}, {
|
|
5
5
|
get: (e, t) => typeof t == "string" ? r(t) : void 0,
|
|
6
|
-
has: (
|
|
6
|
+
has: (t, n) => typeof n == "string" && e(n) !== void 0
|
|
7
7
|
}), o = (e) => {
|
|
8
8
|
let t = r(e);
|
|
9
9
|
return t === void 0 ? void 0 : String(t);
|
|
10
|
-
}, s = (e) => i(e), c = async (
|
|
11
|
-
let a = r?.graceMs ?? 3e5, o = t
|
|
12
|
-
return n(
|
|
10
|
+
}, s = (e) => i(e), c = async (t, r) => {
|
|
11
|
+
let a = r?.graceMs ?? 3e5, o = e(t), s = o === void 0 ? void 0 : String(o), c = await i(t);
|
|
12
|
+
return n(t, c, {
|
|
13
13
|
...s === void 0 ? {} : { previous: s },
|
|
14
14
|
graceMs: a
|
|
15
15
|
}), {
|
|
16
|
-
key:
|
|
16
|
+
key: t,
|
|
17
17
|
current: c,
|
|
18
18
|
previous: s,
|
|
19
19
|
graceMs: a
|
|
20
20
|
};
|
|
21
|
-
}, l = (
|
|
22
|
-
let n = e
|
|
21
|
+
}, l = (e) => {
|
|
22
|
+
let n = t(e);
|
|
23
23
|
return {
|
|
24
|
-
current: o(
|
|
24
|
+
current: o(e),
|
|
25
25
|
previous: n === void 0 ? void 0 : String(n)
|
|
26
26
|
};
|
|
27
27
|
};
|
|
@@ -27,11 +27,8 @@ var e = Symbol.for("@voltro/env/state"), t = globalThis[e] ??= {
|
|
|
27
27
|
}, s = (e) => {
|
|
28
28
|
let n = t.live?.get(e);
|
|
29
29
|
if (n !== void 0 && n.previousExpiresAt !== void 0) {
|
|
30
|
-
if (t.clock() >= n.previousExpiresAt) {
|
|
31
|
-
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
return n.previous;
|
|
30
|
+
if (t.clock() >= n.previousExpiresAt) t.live.set(e, { value: n.value });
|
|
31
|
+
else return n.previous;
|
|
35
32
|
}
|
|
36
33
|
}, c = (e) => s(e) !== void 0, l = (e) => {
|
|
37
34
|
t.clock = e;
|
|
@@ -39,4 +36,4 @@ var e = Symbol.for("@voltro/env/state"), t = globalThis[e] ??= {
|
|
|
39
36
|
t.snapshot = null, t.live = null, t.clock = () => Date.now();
|
|
40
37
|
};
|
|
41
38
|
//#endregion
|
|
42
|
-
export {
|
|
39
|
+
export { r as hasEnvSnapshot, c as hasLiveOverlap, n as installEnvSnapshot, i as readEnvValue, s as readEnvValuePrevious, o as refreshEnvValue, a as requireEnvValue, u as resetEnvSnapshot, l as setEnvClock };
|
package/dist/validate.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Result as e } from "effect";
|
|
2
|
+
//#region src/validate.ts
|
|
3
|
+
var t = (e, n = /* @__PURE__ */ new Set()) => {
|
|
4
|
+
if (e === null || typeof e == "string" || typeof e == "boolean") return !0;
|
|
5
|
+
if (typeof e == "number") return Number.isFinite(e);
|
|
6
|
+
if (typeof e != "object" || n.has(e) || !Array.isArray(e) && Object.getPrototypeOf(e) !== Object.prototype && Object.getPrototypeOf(e) !== null) return !1;
|
|
7
|
+
n.add(e);
|
|
8
|
+
let r = Object.getOwnPropertySymbols(e).length === 0 && Object.values(e).every((e) => t(e, n));
|
|
9
|
+
return n.delete(e), r;
|
|
10
|
+
}, n = (n, r, i) => {
|
|
11
|
+
let a = r.decode(i);
|
|
12
|
+
return a.ok ? t(a.value) ? e.succeed(a.value) : e.fail({
|
|
13
|
+
key: n,
|
|
14
|
+
access: r.access,
|
|
15
|
+
reason: "invalid",
|
|
16
|
+
message: "decoded environment value is not JSON-serialisable; rebuild the app and CLI with matching environment field builders"
|
|
17
|
+
}) : e.fail({
|
|
18
|
+
key: n,
|
|
19
|
+
access: r.access,
|
|
20
|
+
reason: "invalid",
|
|
21
|
+
message: a.message
|
|
22
|
+
});
|
|
23
|
+
}, r = async (t) => {
|
|
24
|
+
let r = t.readEnv ?? ((e) => process.env[e]), i = t.resolveSecret ?? ((e) => Promise.resolve(r(e))), a = {}, o = {}, s = [], c = t.contract ? Object.entries(t.contract.vars) : [];
|
|
25
|
+
for (let [t, l] of c) {
|
|
26
|
+
let c = (l.access === "secret" ? await i(t) : r(t)) ?? l.default;
|
|
27
|
+
if (c === void 0) {
|
|
28
|
+
l.optional ? (a[t] = void 0, l.access === "public" && (o[t] = void 0)) : s.push({
|
|
29
|
+
key: t,
|
|
30
|
+
access: l.access,
|
|
31
|
+
reason: "missing",
|
|
32
|
+
message: `required ${l.access} env var "${t}" is unset` + (l.description ? ` — ${l.description}` : "")
|
|
33
|
+
});
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
let u = n(t, l, c);
|
|
37
|
+
e.isFailure(u) ? s.push(u.failure) : (a[t] = u.success, l.access === "public" && (o[t] = u.success));
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
values: a,
|
|
41
|
+
publicValues: o,
|
|
42
|
+
errors: s,
|
|
43
|
+
ok: s.length === 0
|
|
44
|
+
};
|
|
45
|
+
}, i = (e, t) => {
|
|
46
|
+
let n = e?.publicPrefix;
|
|
47
|
+
if (!e || typeof n != "string") return [];
|
|
48
|
+
let r = [];
|
|
49
|
+
for (let [i, a] of Object.entries(e.vars)) a.access === "secret" && i.startsWith(n) && r.push({
|
|
50
|
+
key: i,
|
|
51
|
+
access: "secret",
|
|
52
|
+
reason: "invalid",
|
|
53
|
+
message: `secret env var "${i}" must NOT use the public prefix "${n}" — that prefix marks browser-exposed PUBLIC values; a secret carrying it is a contradiction.`
|
|
54
|
+
}), t === "web" && a.access === "public" && !i.startsWith(n) && r.push({
|
|
55
|
+
key: i,
|
|
56
|
+
access: "public",
|
|
57
|
+
reason: "invalid",
|
|
58
|
+
message: `public env var "${i}" on a web app ships to the browser and must be named "${n}…" (e.g. "${n}${i}"). Rename it, mark it access:'secret' to keep it server-only, or set publicPrefix:false in defineEnv to opt out.`
|
|
59
|
+
});
|
|
60
|
+
return r;
|
|
61
|
+
}, a = (e) => {
|
|
62
|
+
let t = e.map((e) => ` • ${e.key} (${e.access}, ${e.reason}): ${e.message}`);
|
|
63
|
+
return `environment validation failed (${e.length} ${e.length === 1 ? "error" : "errors"}):\n${t.join("\n")}`;
|
|
64
|
+
};
|
|
65
|
+
//#endregion
|
|
66
|
+
export { i as checkEnvNaming, a as formatEnvErrors, r as resolveEnv };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltro/env",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.87.0",
|
|
4
4
|
"description": "Typed, schema-validated environment variables with a structural public/secret boundary. Declare once in app.config.ts; read public vars in the browser, secrets only on the server.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"voltro",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"node": ">=24.0.0"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@voltro/runtime": "0.
|
|
46
|
+
"@voltro/runtime": "0.87.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"effect": "4.0.1"
|