@ayronforge/envil 0.6.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 +111 -0
- package/dist/cli/dotenv-codec.d.ts +3 -0
- package/dist/cli/fs-utils.d.ts +7 -0
- package/dist/cli/generate-env-ts.d.ts +2 -0
- package/dist/cli/generate-example.d.ts +2 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/infer.d.ts +6 -0
- package/dist/cli/literals.d.ts +5 -0
- package/dist/cli/manifest-codec.d.ts +3 -0
- package/dist/cli/types.d.ts +61 -0
- package/dist/cli.d.ts +8 -0
- package/dist/cli.js +1249 -0
- package/dist/cli.js.map +18 -0
- package/dist/env.d.ts +14 -0
- package/dist/errors.d.ts +10 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +443 -0
- package/dist/index.js.map +17 -0
- package/dist/prefix.d.ts +6 -0
- package/dist/presets.d.ts +30 -0
- package/dist/presets.js +26 -0
- package/dist/presets.js.map +10 -0
- package/dist/resolvers/aws.d.ts +9 -0
- package/dist/resolvers/aws.js +146 -0
- package/dist/resolvers/aws.js.map +12 -0
- package/dist/resolvers/azure.d.ts +10 -0
- package/dist/resolvers/azure.js +85 -0
- package/dist/resolvers/azure.js.map +12 -0
- package/dist/resolvers/gcp.d.ts +10 -0
- package/dist/resolvers/gcp.js +88 -0
- package/dist/resolvers/gcp.js.map +12 -0
- package/dist/resolvers/onepassword.d.ts +9 -0
- package/dist/resolvers/onepassword.js +91 -0
- package/dist/resolvers/onepassword.js.map +12 -0
- package/dist/resolvers/remote.d.ts +9 -0
- package/dist/resolvers/types.d.ts +15 -0
- package/dist/resolvers/utils.d.ts +15 -0
- package/dist/safe-env.d.ts +23 -0
- package/dist/schemas.d.ts +30 -0
- package/dist/types.d.ts +41 -0
- package/package.json +109 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pedro Toledo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# @ayronforge/envil
|
|
2
|
+
|
|
3
|
+
Typesafe environment variables using [Effect Schema](https://effect.website/docs/schema/introduction).
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
Never deploy with invalid environment variables again. **envil** validates all your env vars at startup, gives you full TypeScript autocompletion, and keeps server secrets out of client bundles — powered by the [Effect](https://effect.website) ecosystem.
|
|
9
|
+
|
|
10
|
+
## Documentation
|
|
11
|
+
|
|
12
|
+
For schemas, helpers, prefix support, framework presets, composable envs, resolvers, and more — visit the **[documentation](https://ayronforge.com/envil)**.
|
|
13
|
+
|
|
14
|
+
## Highlights
|
|
15
|
+
|
|
16
|
+
- **Full type inference** — env vars are fully typed from your schemas, no manual annotations needed
|
|
17
|
+
- **Client / server separation** — server-only vars throw at runtime if accessed on the client
|
|
18
|
+
- **Eager validation** — all errors collected and reported at once on startup
|
|
19
|
+
- **Built-in schemas** — booleans, ports, URLs, database URLs, JSON, enums, and more
|
|
20
|
+
- **Secret manager resolvers** — fetch secrets from AWS, GCP, Azure Key Vault, and 1Password
|
|
21
|
+
|
|
22
|
+
## Requirements
|
|
23
|
+
|
|
24
|
+
- **Node.js** 18+
|
|
25
|
+
- **ESM only**
|
|
26
|
+
- [**effect**](https://effect.website) ^3.19.11
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# npm
|
|
32
|
+
npm install @ayronforge/envil effect
|
|
33
|
+
|
|
34
|
+
# pnpm
|
|
35
|
+
pnpm add @ayronforge/envil effect
|
|
36
|
+
|
|
37
|
+
# bun
|
|
38
|
+
bun add @ayronforge/envil effect
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## CLI (`envil`)
|
|
42
|
+
|
|
43
|
+
This package ships a CLI named `envil` with deterministic schema/example round-tripping:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# infer env.ts from .env.example
|
|
47
|
+
envil add env --input .env.example --output src/env.ts --force
|
|
48
|
+
|
|
49
|
+
# regenerate .env.example from env.ts manifest
|
|
50
|
+
envil add example --input src/env.ts --output .env.example --force
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`envil add env` supports:
|
|
54
|
+
|
|
55
|
+
- `--framework <nextjs|vite|expo|nuxt|sveltekit|astro>`
|
|
56
|
+
- `--client-prefix <prefix>`
|
|
57
|
+
- `--server-prefix <prefix>`
|
|
58
|
+
- `--shared-prefix <prefix>`
|
|
59
|
+
- `--force`
|
|
60
|
+
|
|
61
|
+
`envil add example` supports:
|
|
62
|
+
|
|
63
|
+
- `--force`
|
|
64
|
+
|
|
65
|
+
Both commands support `--help` for full usage output.
|
|
66
|
+
|
|
67
|
+
## Quick start
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import {
|
|
71
|
+
createEnv,
|
|
72
|
+
requiredString,
|
|
73
|
+
port,
|
|
74
|
+
withDefault,
|
|
75
|
+
boolean,
|
|
76
|
+
postgresUrl,
|
|
77
|
+
redacted,
|
|
78
|
+
} from "@ayronforge/envil";
|
|
79
|
+
|
|
80
|
+
export const env = createEnv({
|
|
81
|
+
server: {
|
|
82
|
+
DATABASE_URL: postgresUrl,
|
|
83
|
+
API_SECRET: redacted(requiredString),
|
|
84
|
+
PORT: withDefault(port, 3000),
|
|
85
|
+
DEBUG: withDefault(boolean, false),
|
|
86
|
+
},
|
|
87
|
+
client: {
|
|
88
|
+
PUBLIC_API_URL: requiredString,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
env.DATABASE_URL; // string — fully typed
|
|
93
|
+
env.API_SECRET; // Redacted<string> — unwrap with Redacted.value(env.API_SECRET)
|
|
94
|
+
env.PORT; // number — transformed from string
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
If any variable is missing or invalid, `createEnv()` throws immediately with detailed errors:
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
EnvValidationError: Invalid environment variables:
|
|
101
|
+
DATABASE_URL: Expected a valid PostgreSQL connection URL
|
|
102
|
+
API_SECRET: Expected a string with at least 1 character(s), actual ""
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Acknowledgements
|
|
106
|
+
|
|
107
|
+
This project is heavily inspired by [T3 Env](https://env.t3.gg) by [T3 OSS](https://github.com/t3-oss/t3-env). Thanks to the T3 team for their work and contributions to open source.
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
[MIT](./LICENSE)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function pathExists(filePath: string): Promise<boolean>;
|
|
2
|
+
export declare function resolveFromCwd(cwd: string, filePath: string): string;
|
|
3
|
+
export declare function getDefaultEnvOutputPath(cwd: string): Promise<string>;
|
|
4
|
+
export declare function getDefaultExampleInputPath(cwd: string): Promise<string>;
|
|
5
|
+
export declare function ensureWritableTarget(targetPath: string, force: boolean): Promise<void>;
|
|
6
|
+
export declare function readTextFileOrThrow(filePath: string, label: string): Promise<string>;
|
|
7
|
+
export declare function writeFileAtomic(targetPath: string, contents: string): Promise<void>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { decodeDotenvText, encodeDotenvText } from "./dotenv-codec.ts";
|
|
2
|
+
export { getDefaultEnvOutputPath, getDefaultExampleInputPath, resolveFromCwd } from "./fs-utils.ts";
|
|
3
|
+
export { generateExample } from "./generate-example.ts";
|
|
4
|
+
export { generateEnvTs } from "./generate-env-ts.ts";
|
|
5
|
+
export { inferModel } from "./infer.ts";
|
|
6
|
+
export { decodeManifestFromSource, encodeManifestBlock } from "./manifest-codec.ts";
|
|
7
|
+
export * from "./types.ts";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function parseLiteral(input: string): unknown;
|
|
2
|
+
export declare function toCodeLiteral(value: unknown): string;
|
|
3
|
+
export declare function toDirectiveLiteral(value: unknown): string;
|
|
4
|
+
export declare function toEnvValueLiteral(value: unknown): string;
|
|
5
|
+
export declare function parseBooleanDirective(value: string | undefined, defaultValue: boolean): boolean;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export declare const BUCKETS: readonly ["server", "client", "shared"];
|
|
2
|
+
export type Bucket = (typeof BUCKETS)[number];
|
|
3
|
+
export declare const SCHEMA_KINDS: readonly ["requiredString", "boolean", "integer", "number", "port", "url", "postgresUrl", "redisUrl", "mongoUrl", "mysqlUrl", "commaSeparated", "commaSeparatedNumbers", "commaSeparatedUrls", "json"];
|
|
4
|
+
export type SchemaKind = (typeof SCHEMA_KINDS)[number];
|
|
5
|
+
export declare const FRAMEWORKS: readonly ["nextjs", "vite", "expo", "nuxt", "sveltekit", "astro"];
|
|
6
|
+
export type Framework = (typeof FRAMEWORKS)[number];
|
|
7
|
+
export interface PrefixConfig {
|
|
8
|
+
readonly server: string;
|
|
9
|
+
readonly client: string;
|
|
10
|
+
readonly shared: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ParsedDirectives {
|
|
13
|
+
readonly type?: SchemaKind;
|
|
14
|
+
readonly optional?: boolean;
|
|
15
|
+
readonly hasDefault?: boolean;
|
|
16
|
+
readonly defaultValue?: unknown;
|
|
17
|
+
readonly redacted?: boolean;
|
|
18
|
+
readonly bucket?: Bucket;
|
|
19
|
+
}
|
|
20
|
+
export interface DotenvAssignment {
|
|
21
|
+
readonly key: string;
|
|
22
|
+
readonly value: string;
|
|
23
|
+
readonly line: number;
|
|
24
|
+
readonly sectionBucket?: Bucket;
|
|
25
|
+
readonly directives: ParsedDirectives;
|
|
26
|
+
}
|
|
27
|
+
export interface DotenvDocument {
|
|
28
|
+
readonly entries: ReadonlyArray<DotenvAssignment>;
|
|
29
|
+
}
|
|
30
|
+
export interface InferredVariable {
|
|
31
|
+
readonly schemaKey: string;
|
|
32
|
+
readonly runtimeKey: string;
|
|
33
|
+
readonly bucket: Bucket;
|
|
34
|
+
readonly kind: SchemaKind;
|
|
35
|
+
readonly optional: boolean;
|
|
36
|
+
readonly hasDefault: boolean;
|
|
37
|
+
readonly defaultValue?: unknown;
|
|
38
|
+
readonly redacted: boolean;
|
|
39
|
+
readonly sourceLine: number;
|
|
40
|
+
}
|
|
41
|
+
export interface InferredModel {
|
|
42
|
+
readonly prefix: PrefixConfig;
|
|
43
|
+
readonly variables: ReadonlyArray<InferredVariable>;
|
|
44
|
+
readonly runtimeEnv: Readonly<Record<string, string | undefined>>;
|
|
45
|
+
}
|
|
46
|
+
export interface ManifestVariable {
|
|
47
|
+
readonly name: string;
|
|
48
|
+
readonly bucket: Bucket;
|
|
49
|
+
readonly kind: SchemaKind;
|
|
50
|
+
readonly optional: boolean;
|
|
51
|
+
readonly hasDefault: boolean;
|
|
52
|
+
readonly defaultValue?: unknown;
|
|
53
|
+
readonly redacted: boolean;
|
|
54
|
+
}
|
|
55
|
+
export interface ManifestV1 {
|
|
56
|
+
readonly version: 1;
|
|
57
|
+
readonly prefix: PrefixConfig;
|
|
58
|
+
readonly variables: ReadonlyArray<ManifestVariable>;
|
|
59
|
+
}
|
|
60
|
+
export type Manifest = ManifestV1;
|
|
61
|
+
export declare const MANIFEST_VERSION: 1;
|
package/dist/cli.d.ts
ADDED