@voltro/env 0.84.0 → 0.86.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/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.Schema.Any` lets any concrete field assign here.
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
- readonly schema: Schema.Schema.Any;
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
 
@@ -135,7 +145,14 @@ export declare interface EnvFieldSpec<A = unknown, Optional extends boolean = bo
135
145
  /** Browser boundary classification — mandatory, no default. */
136
146
  readonly access: EnvAccess;
137
147
  /** effect/Schema that decodes the RAW string env value → typed `A`. */
138
- readonly schema: Schema.Schema<A, string>;
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,180 +1,7 @@
1
- import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c } from "./snapshot-AmznYBVm.js";
2
- import { Either as l, ParseResult as u, Schema as d } from "effect";
3
- //#region src/define.ts
4
- var f = "VOLTRO_PUBLIC_", p = (e, t) => Object.freeze({
5
- vars: Object.freeze({ ...e }),
6
- publicPrefix: t?.publicPrefix ?? "VOLTRO_PUBLIC_"
7
- }), m = (e) => typeof e == "object" && !!e && "vars" in e && typeof e.vars == "object" && e.vars !== null, h = (e, t, n, r) => ({
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
- }), g = d.transformOrFail(d.String, d.Boolean, {
17
- strict: !0,
18
- decode: (e, t, n) => {
19
- let r = e.trim().toLowerCase();
20
- return r === "true" || r === "1" || r === "yes" || r === "on" ? u.succeed(!0) : r === "false" || r === "0" || r === "no" || r === "off" || r === "" ? u.succeed(!1) : u.fail(new u.Type(n, e, `expected a boolean (true/false/1/0/yes/no/on/off), got "${e}"`));
21
- },
22
- encode: (e) => u.succeed(e ? "true" : "false")
23
- }), _ = (e) => URL.canParse(e), v = {
24
- string: (e) => h("string", d.String, "string", e),
25
- number: (e) => h("number", d.NumberFromString, "number", e),
26
- port: (e) => h("port", d.NumberFromString.pipe(d.int(), d.between(1, 65535)), "number", e),
27
- boolean: (e) => h("boolean", g, "boolean", e),
28
- secret: (e) => {
29
- let t = e.minLength ?? 32;
30
- return {
31
- ...h("secret", d.String.pipe(d.filter((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", {
32
- ...e,
33
- access: "secret"
34
- }),
35
- ...e.generate === void 0 ? {} : { generate: e.generate }
36
- };
37
- },
38
- url: (e) => h("url", d.String.pipe(d.filter((e) => _(e) || `expected a valid URL, got "${e}"`)), "string", e),
39
- enum: (e, t) => h("enum", d.Literal(...e), e.map((e) => `'${e}'`).join(" | "), t)
40
- }, y = (e, t, n) => {
41
- let r = t.schema, i = d.decodeUnknownEither(r)(n);
42
- return l.mapLeft(i, (n) => ({
43
- key: e,
44
- access: t.access,
45
- reason: "invalid",
46
- message: n.message
47
- }));
48
- }, b = async (e) => {
49
- 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) : [];
50
- for (let [e, s] of o) {
51
- let o = (s.access === "secret" ? await n(e) : t(e)) ?? s.default;
52
- if (o === void 0) {
53
- s.optional ? (r[e] = void 0, s.access === "public" && (i[e] = void 0)) : a.push({
54
- key: e,
55
- access: s.access,
56
- reason: "missing",
57
- message: `required ${s.access} env var "${e}" is unset` + (s.description ? ` — ${s.description}` : "")
58
- });
59
- continue;
60
- }
61
- let c = y(e, s, o);
62
- if (l.isLeft(c)) {
63
- a.push(c.left);
64
- continue;
65
- }
66
- r[e] = c.right, s.access === "public" && (i[e] = c.right);
67
- }
68
- return {
69
- values: r,
70
- publicValues: i,
71
- errors: a,
72
- ok: a.length === 0
73
- };
74
- }, x = (e, t) => {
75
- let n = e?.publicPrefix;
76
- if (!e || typeof n != "string") return [];
77
- let r = [];
78
- for (let [i, a] of Object.entries(e.vars)) a.access === "secret" && i.startsWith(n) && r.push({
79
- key: i,
80
- access: "secret",
81
- reason: "invalid",
82
- 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.`
83
- }), t === "web" && a.access === "public" && !i.startsWith(n) && r.push({
84
- key: i,
85
- access: "public",
86
- reason: "invalid",
87
- 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.`
88
- });
89
- return r;
90
- }, S = (e) => {
91
- let t = e.map((e) => ` • ${e.key} (${e.access}, ${e.reason}): ${e.message}`);
92
- return `environment validation failed (${e.length} ${e.length === 1 ? "error" : "errors"}):\n${t.join("\n")}`;
93
- }, C = (e) => e ? Object.entries(e.vars).map(([e, t]) => ({
94
- key: e,
95
- owner: "app",
96
- access: t.access,
97
- required: !t.optional && t.default === void 0,
98
- ...t.description === void 0 ? {} : { description: t.description },
99
- ...t.example === void 0 ? {} : { example: t.example },
100
- ...t.default === void 0 ? {} : { default: t.default },
101
- kind: t.kind
102
- })) : [], w = (e, t) => t ? t.map((t) => ({
103
- key: t.name,
104
- owner: `plugin:${e}`,
105
- access: t.secret ? "secret" : "public",
106
- required: t.required,
107
- ...t.description === void 0 ? {} : { description: t.description },
108
- ...t.example === void 0 ? {} : { example: t.example }
109
- })) : [], T = (e, t, n, r, i) => ({
110
- key: e,
111
- owner: "framework",
112
- access: n,
113
- required: !1,
114
- description: r,
115
- group: t,
116
- ...i === void 0 ? {} : { example: i }
117
- }), E = [
118
- T("NODE_ENV", "runtime", "public", "Node environment (development | production).", "development"),
119
- T("PORT", "runtime", "public", "Port the api/web server binds to. Overrides app.config `port`.", "4000"),
120
- T("VOLTRO_REGION", "runtime", "public", "Region tag for replica locality (else AWS_REGION/FLY_REGION/…).", "us-east-1"),
121
- T("VOLTRO_AUTO_MIGRATE", "runtime", "public", "Set 0 to skip boot auto-migrate (CI-applied migrations).", "1"),
122
- T("DB_DIALECT", "database", "public", "postgres | mysql | mariadb | mssql | sqlite | memory.", "postgres"),
123
- T("DB_URL", "database", "secret", "Connection URL (carries credentials). Preferred over discrete DB_* fields.", "postgres://user:pw@localhost:5432/app"),
124
- T("DB_HOST", "database", "public", "Database host (discrete-field form; DB_URL preferred).", "localhost"),
125
- T("DB_PORT", "database", "public", "Database port.", "5432"),
126
- T("DB_USER", "database", "public", "Database user.", "postgres"),
127
- T("DB_PASSWORD", "database", "secret", "Database password."),
128
- T("DB_DATABASE", "database", "public", "Database name.", "app"),
129
- T("DB_MAX_CONNECTIONS", "database", "public", "Per-process connection pool cap.", "10"),
130
- T("DB_REPLICA_URLS", "database", "secret", "Comma-separated read-replica URLs (carry credentials)."),
131
- T("DB_REPLICA_REGIONS", "database", "public", "Comma-separated region tags matching DB_REPLICA_URLS order."),
132
- T("RYW_STORE", "database", "public", "Read-your-writes position store: memory | redis.", "memory"),
133
- T("CACHE_BACKEND", "cache", "public", "@voltro/cache backend: memory | redis.", "memory"),
134
- T("CACHE_REDIS_URL", "cache", "secret", "Redis/Valkey/KeyDB/Dragonfly/Upstash URL (may carry credentials).", "redis://localhost:6379"),
135
- T("CACHE_REDIS_DRIVER", "cache", "public", "resp (ioredis TCP) | http (Upstash REST, edge).", "resp"),
136
- T("CACHE_REDIS_TOKEN", "cache", "secret", "Upstash REST token (http driver)."),
137
- T("CACHE_KEY_PREFIX", "cache", "public", "Cache key namespace.", "voltro:cache"),
138
- T("REDIS_URL", "cache", "secret", "Generic Redis URL fallback (cache / ryw / ratelimit).", "redis://localhost:6379"),
139
- T("VOLTRO_SESSION_SECRET", "security", "secret", "HMAC signing key for session cookies. REQUIRED in production."),
140
- T("VOLTRO_INSPECT", "security", "public", "Set off to disable the /_voltro/inspect surface entirely.", "on"),
141
- T("VOLTRO_INSPECT_TOKEN", "security", "secret", "Bearer token gating /_voltro/inspect/* on public deploys."),
142
- T("VOLTRO_WEB_REPLICA_GROUP", "observability", "public", "Deployment-specific Web/SSR replica discovery group in PostgreSQL. Use a distinct value per app and environment."),
143
- T("VOLTRO_TENANT_ISOLATION", "security", "public", "shared-schema (default) | namespace (physical per-tenant)."),
144
- T("FRAMEWORK_TRACING", "observability", "public", "off | console | otlp. Auto-otlp when OTEL_* is set."),
145
- T("OTEL_EXPORTER_OTLP_ENDPOINT", "observability", "public", "OTLP/HTTP collector endpoint (traces + metrics).", "http://localhost:4318"),
146
- T("OTEL_SERVICE_NAME", "observability", "public", "OTel service name.", "voltro-api"),
147
- T("SSR_CACHE", "web", "public", "ISR cache backend for `voltro start`: memory | postgres.", "memory")
148
- ], D = () => E.map((e) => e.key), O = (e) => {
149
- let t = [];
150
- e.description && t.push(`# ${e.description}`);
151
- let n = [
152
- e.required ? "required" : "optional",
153
- e.access,
154
- ...e.kind ? [e.kind] : []
155
- ].join(", ");
156
- t.push(`# (${n})`);
157
- let r = e.example ?? e.default ?? "";
158
- return t.push(`${e.key}=${e.access === "secret" && !e.example ? "" : r}`), t.join("\n");
159
- }, k = (e, t = {}) => {
160
- 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."];
161
- n.push(...r.map((e) => `# ${e}`), "");
162
- let i = e.filter((e) => e.owner === "app"), a = e.filter((e) => e.owner.startsWith("plugin:"));
163
- if (i.length > 0 && (n.push("# ── App ──────────────────────────────────────────────", ""), n.push(...i.map(O).flatMap((e) => [e, ""]))), a.length > 0 && (n.push("# ── Plugins ──────────────────────────────────────────", ""), n.push(...a.map(O).flatMap((e) => [e, ""]))), t.includeFramework !== !1) {
164
- let e = [...new Set(E.map((e) => e.group))];
165
- n.push("# ── Framework ────────────────────────────────────────", "");
166
- for (let t of e) n.push(`# [${t}]`), n.push(...E.filter((e) => e.group === t).map(O).flatMap((e) => [e, ""]));
167
- }
168
- return n.join("\n").replace(/\n{3,}/g, "\n\n").trimEnd() + "\n";
169
- }, A = (e) => {
170
- let t = new Set(e.map((e) => e.name));
171
- return {
172
- declared: e,
173
- read: (e, n) => {
174
- 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.`);
175
- return n ?? process.env[e];
176
- }
177
- };
178
- };
179
- //#endregion
180
- export { f as DEFAULT_PUBLIC_PREFIX, E as FRAMEWORK_ENV_CATALOG, C as appEnvEntries, x as checkEnvNaming, p as defineEnv, v as envVar, S as formatEnvErrors, D as frameworkEnvNames, c as hasEnvSnapshot, i as hasLiveOverlap, o as installEnvSnapshot, m as isEnvContract, A as pluginEnv, w as pluginEnvEntries, n as readEnvValue, e as readEnvValuePrevious, a as refreshEnvValue, k as renderDotEnvExample, s as requireEnvValue, t as resetEnvSnapshot, b 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 };
@@ -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.js CHANGED
@@ -1,27 +1,27 @@
1
- import { a as e, i as t, o as n, s as r } from "./snapshot-AmznYBVm.js";
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: (e, n) => typeof n == "string" && t(n) !== void 0
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 (e, r) => {
11
- let a = r?.graceMs ?? 3e5, o = t(e), s = o === void 0 ? void 0 : String(o), c = await i(e);
12
- return n(e, c, {
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: e,
16
+ key: t,
17
17
  current: c,
18
18
  previous: s,
19
19
  graceMs: a
20
20
  };
21
- }, l = (t) => {
22
- let n = e(t);
21
+ }, l = (e) => {
22
+ let n = t(e);
23
23
  return {
24
- current: o(t),
24
+ current: o(e),
25
25
  previous: n === void 0 ? void 0 : String(n)
26
26
  };
27
27
  };
@@ -0,0 +1,39 @@
1
+ //#region src/snapshot.ts
2
+ var e = Symbol.for("@voltro/env/state"), t = globalThis[e] ??= {
3
+ snapshot: null,
4
+ live: null,
5
+ clock: () => Date.now()
6
+ }, n = (e) => {
7
+ t.snapshot = Object.freeze({ ...e }), t.live = null;
8
+ }, r = () => t.snapshot !== null, i = (e) => {
9
+ let n = t.live?.get(e);
10
+ return n === void 0 ? t.snapshot === null ? void 0 : t.snapshot[e] : n.value;
11
+ }, a = (e) => {
12
+ let n = t.live?.get(e);
13
+ if (n !== void 0) return n.value;
14
+ if (t.snapshot === null) throw Error(`@voltro/env: read of "${e}" before the boot env gate ran. Env values are only available after the framework validates them at startup — read them inside a handler / loader / startup hook, not at module top-level.`);
15
+ return t.snapshot[e];
16
+ }, o = (e, n, r) => {
17
+ if (t.snapshot === null) throw Error(`@voltro/env: refreshEnvValue("${e}") before the boot env gate ran. A live secret rotation is a post-boot operation — it replaces a value the boot gate already resolved.`);
18
+ t.live === null && (t.live = /* @__PURE__ */ new Map());
19
+ let i = r?.previous !== void 0 && r.graceMs !== void 0 && r.graceMs > 0;
20
+ t.live.set(e, {
21
+ value: n,
22
+ ...i ? {
23
+ previous: r.previous,
24
+ previousExpiresAt: t.clock() + r.graceMs
25
+ } : {}
26
+ });
27
+ }, s = (e) => {
28
+ let n = t.live?.get(e);
29
+ if (n !== void 0 && n.previousExpiresAt !== void 0) {
30
+ if (t.clock() >= n.previousExpiresAt) t.live.set(e, { value: n.value });
31
+ else return n.previous;
32
+ }
33
+ }, c = (e) => s(e) !== void 0, l = (e) => {
34
+ t.clock = e;
35
+ }, u = () => {
36
+ t.snapshot = null, t.live = null, t.clock = () => Date.now();
37
+ };
38
+ //#endregion
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 };
@@ -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.84.0",
3
+ "version": "0.86.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,10 +43,10 @@
43
43
  "node": ">=24.0.0"
44
44
  },
45
45
  "dependencies": {
46
- "@voltro/runtime": "0.84.0"
46
+ "@voltro/runtime": "0.86.0"
47
47
  },
48
48
  "peerDependencies": {
49
- "effect": "^3.22.2"
49
+ "effect": "4.0.1"
50
50
  },
51
51
  "publishConfig": {
52
52
  "access": "public"
@@ -1,38 +0,0 @@
1
- //#region src/snapshot.ts
2
- var e = null, t = null, n = () => Date.now(), r = (n) => {
3
- e = Object.freeze({ ...n }), t = null;
4
- }, i = () => e !== null, a = (n) => {
5
- let r = t?.get(n);
6
- return r === void 0 ? e === null ? void 0 : e[n] : r.value;
7
- }, o = (n) => {
8
- let r = t?.get(n);
9
- if (r !== void 0) return r.value;
10
- if (e === null) throw Error(`@voltro/env: read of "${n}" before the boot env gate ran. Env values are only available after the framework validates them at startup — read them inside a handler / loader / startup hook, not at module top-level.`);
11
- return e[n];
12
- }, s = (r, i, a) => {
13
- if (e === null) throw Error(`@voltro/env: refreshEnvValue("${r}") before the boot env gate ran. A live secret rotation is a post-boot operation — it replaces a value the boot gate already resolved.`);
14
- t === null && (t = /* @__PURE__ */ new Map());
15
- let o = a?.previous !== void 0 && a.graceMs !== void 0 && a.graceMs > 0;
16
- t.set(r, {
17
- value: i,
18
- ...o ? {
19
- previous: a.previous,
20
- previousExpiresAt: n() + a.graceMs
21
- } : {}
22
- });
23
- }, c = (e) => {
24
- let r = t?.get(e);
25
- if (r !== void 0 && r.previousExpiresAt !== void 0) {
26
- if (n() >= r.previousExpiresAt) {
27
- t.set(e, { value: r.value });
28
- return;
29
- }
30
- return r.previous;
31
- }
32
- }, l = (e) => c(e) !== void 0, u = (e) => {
33
- n = e;
34
- }, d = () => {
35
- e = null, t = null, n = () => Date.now();
36
- };
37
- //#endregion
38
- export { c as a, d as c, a as i, u as l, l as n, s as o, r, o as s, i as t };