zenvx 0.1.3 → 0.2.1
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/README.md +128 -17
- package/dist/adapters/next.cjs +151 -0
- package/dist/adapters/next.d.cts +6 -0
- package/dist/adapters/next.d.ts +6 -0
- package/dist/adapters/next.js +32 -0
- package/dist/adapters/node.cjs +135 -0
- package/dist/adapters/node.d.cts +5 -0
- package/dist/adapters/node.d.ts +5 -0
- package/dist/adapters/node.js +17 -0
- package/dist/adapters/vite.cjs +135 -0
- package/dist/adapters/vite.d.cts +5 -0
- package/dist/adapters/vite.d.ts +5 -0
- package/dist/adapters/vite.js +16 -0
- package/dist/chunk-3HCQKBTL.js +29 -0
- package/dist/chunk-DX3SLVGQ.js +18 -0
- package/dist/chunk-E7OYVDFC.js +67 -0
- package/dist/chunk-ELPQSMQJ.js +24 -0
- package/dist/chunk-KGVPNFG3.js +43 -0
- package/dist/chunk-R2XSSP2M.js +24 -0
- package/dist/core/define-env.cjs +125 -0
- package/dist/core/define-env.d.cts +6 -0
- package/dist/core/define-env.d.ts +6 -0
- package/dist/core/define-env.js +9 -0
- package/dist/core/generate-example.cjs +71 -0
- package/dist/core/generate-example.d.cts +5 -0
- package/dist/core/generate-example.d.ts +5 -0
- package/dist/core/generate-example.js +6 -0
- package/dist/core/parser.cjs +53 -0
- package/dist/core/parser.d.cts +6 -0
- package/dist/core/parser.d.ts +6 -0
- package/dist/core/parser.js +6 -0
- package/dist/core/proxy.cjs +42 -0
- package/dist/core/proxy.d.cts +3 -0
- package/dist/core/proxy.d.ts +3 -0
- package/dist/core/proxy.js +6 -0
- package/dist/core/tx.cjs +91 -0
- package/dist/core/tx.d.cts +42 -0
- package/dist/core/tx.d.ts +42 -0
- package/dist/core/tx.js +6 -0
- package/dist/core/types.cjs +18 -0
- package/dist/core/types.d.cts +8 -0
- package/dist/core/types.d.ts +8 -0
- package/dist/core/types.js +0 -0
- package/dist/index.cjs +111 -117
- package/dist/index.d.cts +4 -50
- package/dist/index.d.ts +4 -50
- package/dist/index.js +9 -159
- package/dist/types/vite-env.d.cjs +1 -0
- package/dist/types/vite-env.d.d.cts +2 -0
- package/dist/types/vite-env.d.d.ts +2 -0
- package/dist/types/vite-env.d.js +0 -0
- package/package.json +18 -6
package/dist/index.js
CHANGED
|
@@ -1,162 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
`[envx] .env file not found at path "${path}"
|
|
11
|
-
Tip: Set { dotenv: false } if you manage environment variables yourself.`
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
const result = dotenv.config({ path });
|
|
15
|
-
if (result.error) {
|
|
16
|
-
throw result.error;
|
|
17
|
-
}
|
|
18
|
-
return result.parsed ?? {};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// src/core/parser.ts
|
|
22
|
-
import "zod";
|
|
23
|
-
function parseEnv(schema, source) {
|
|
24
|
-
const result = schema.safeParse(source);
|
|
25
|
-
if (!result.success) {
|
|
26
|
-
const issues = result.error.issues.map((i) => `\u274C ${i.path.join(".")}: ${i.message}`).join("\n");
|
|
27
|
-
throw new Error(
|
|
28
|
-
[
|
|
29
|
-
"",
|
|
30
|
-
"\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510",
|
|
31
|
-
"\u2502 \u274C INVALID ENVIRONMENT VARIABLES DETECTED \u2502",
|
|
32
|
-
"\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518",
|
|
33
|
-
issues,
|
|
34
|
-
""
|
|
35
|
-
].join("\n")
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
return result.data;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// src/core/proxy.ts
|
|
42
|
-
function createTypedProxy(obj) {
|
|
43
|
-
return new Proxy(obj, {
|
|
44
|
-
get(target, prop) {
|
|
45
|
-
if (!(prop in target)) {
|
|
46
|
-
console.error(
|
|
47
|
-
`\u274C Tried to access undefined environment variable "${prop}"`
|
|
48
|
-
);
|
|
49
|
-
process.exit(1);
|
|
50
|
-
}
|
|
51
|
-
return target[prop];
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// src/index.ts
|
|
57
|
-
var tx = {
|
|
58
|
-
/**
|
|
59
|
-
* STRICT STRING:
|
|
60
|
-
* Rejects purely numeric strings (e.g. "12345").
|
|
61
|
-
* Good for API Keys.
|
|
62
|
-
*/
|
|
63
|
-
string: (message) => {
|
|
64
|
-
return z2.string().refine((val) => !/^\d+$/.test(val), {
|
|
65
|
-
error: message || "Value should be text, but looks like a number."
|
|
66
|
-
});
|
|
67
|
-
},
|
|
68
|
-
/**
|
|
69
|
-
* SMART NUMBER:
|
|
70
|
-
* Automatically converts "3000" -> 3000.
|
|
71
|
-
* Fails if the value is not a valid number (e.g. "abc").
|
|
72
|
-
*/
|
|
73
|
-
number: (message) => {
|
|
74
|
-
return z2.coerce.number({ error: message || "Must be a number" });
|
|
75
|
-
},
|
|
76
|
-
/**
|
|
77
|
-
* PORT VALIDATOR:
|
|
78
|
-
* Coerces to number and ensures it is between 1 and 65535.
|
|
79
|
-
*/
|
|
80
|
-
port: (message) => {
|
|
81
|
-
return z2.coerce.number({
|
|
82
|
-
error: message || "Must be a valid port (1-65535)"
|
|
83
|
-
}).min(1, { error: message || "Port must be >= 1" }).max(65535, { error: message || "Port must be <= 65535" });
|
|
84
|
-
},
|
|
85
|
-
/**
|
|
86
|
-
* SMART BOOLEAN:
|
|
87
|
-
* Handles "true", "TRUE", "1" -> true
|
|
88
|
-
* Handles "false", "FALSE", "0" -> false
|
|
89
|
-
* Throws error on anything else.
|
|
90
|
-
*/
|
|
91
|
-
bool: (message) => {
|
|
92
|
-
return z2.union([z2.string(), z2.boolean()]).transform((val, ctx) => {
|
|
93
|
-
if (typeof val === "boolean") return val;
|
|
94
|
-
const v = val.toLowerCase();
|
|
95
|
-
if (v === "true" || v === "1") return true;
|
|
96
|
-
if (v === "false" || v === "0") return false;
|
|
97
|
-
ctx.addIssue({
|
|
98
|
-
code: z2.ZodIssueCode.custom,
|
|
99
|
-
message: message || 'Must be a boolean ("true"/"false"/"1"/"0")'
|
|
100
|
-
});
|
|
101
|
-
return z2.NEVER;
|
|
102
|
-
});
|
|
103
|
-
},
|
|
104
|
-
/**
|
|
105
|
-
* URL:
|
|
106
|
-
* Strict URL checking.
|
|
107
|
-
*/
|
|
108
|
-
url: (message) => {
|
|
109
|
-
return z2.url({
|
|
110
|
-
error: message || "Must be a valid URL (e.g. https://...)"
|
|
111
|
-
});
|
|
112
|
-
},
|
|
113
|
-
/**
|
|
114
|
-
* EMAIL:
|
|
115
|
-
* Strict Email checking.
|
|
116
|
-
*/
|
|
117
|
-
email: (message) => {
|
|
118
|
-
return z2.email({ error: message || "Must be a valid email address." });
|
|
119
|
-
},
|
|
120
|
-
positiveNumber: (message) => {
|
|
121
|
-
return z2.coerce.number().gt(0, { message: message || "Must be > 0" });
|
|
122
|
-
},
|
|
123
|
-
nonEmptyString: (message) => {
|
|
124
|
-
return z2.string().trim().min(1, { message: message || "Cannot be empty" });
|
|
125
|
-
},
|
|
126
|
-
semver: (message) => {
|
|
127
|
-
return z2.string().refine((val) => /^\d+\.\d+\.\d+(-[0-9A-Za-z-.]+)?$/.test(val), {
|
|
128
|
-
error: message || "Must be valid semver"
|
|
129
|
-
});
|
|
130
|
-
},
|
|
131
|
-
path: (message) => {
|
|
132
|
-
return z2.string().min(1, { error: message || "Must be a valid path" });
|
|
133
|
-
},
|
|
134
|
-
enum: (values, message) => {
|
|
135
|
-
return z2.string().refine((val) => values.includes(val), {
|
|
136
|
-
error: message || `Must be one of: ${values.join(", ")}`
|
|
137
|
-
});
|
|
138
|
-
},
|
|
139
|
-
json: (message) => {
|
|
140
|
-
return z2.string().transform((val, ctx) => {
|
|
141
|
-
try {
|
|
142
|
-
return JSON.parse(val);
|
|
143
|
-
} catch {
|
|
144
|
-
ctx.addIssue({
|
|
145
|
-
code: z2.ZodIssueCode.custom,
|
|
146
|
-
message: message || "Must be valid JSON"
|
|
147
|
-
});
|
|
148
|
-
return z2.NEVER;
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
function defineEnv(shape, options) {
|
|
154
|
-
const fileEnv = loadDotEnv(options?.path);
|
|
155
|
-
const merged = { ...fileEnv, ...process.env };
|
|
156
|
-
const schema = z2.object(shape);
|
|
157
|
-
const parsed = parseEnv(schema, merged);
|
|
158
|
-
return createTypedProxy(parsed);
|
|
159
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
tx
|
|
3
|
+
} from "./chunk-E7OYVDFC.js";
|
|
4
|
+
import {
|
|
5
|
+
defineEnv
|
|
6
|
+
} from "./chunk-ELPQSMQJ.js";
|
|
7
|
+
import "./chunk-KGVPNFG3.js";
|
|
8
|
+
import "./chunk-3HCQKBTL.js";
|
|
9
|
+
import "./chunk-DX3SLVGQ.js";
|
|
160
10
|
export {
|
|
161
11
|
defineEnv,
|
|
162
12
|
tx
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zenvx",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -30,13 +30,28 @@
|
|
|
30
30
|
"import": "./dist/index.js",
|
|
31
31
|
"require": "./dist/index.cjs",
|
|
32
32
|
"types": "./dist/index.d.ts"
|
|
33
|
+
},
|
|
34
|
+
"./node": {
|
|
35
|
+
"import": "./dist/adapters/node.js",
|
|
36
|
+
"require": "./dist/adapters/node.cjs",
|
|
37
|
+
"types": "./dist/adapters/node.d.ts"
|
|
38
|
+
},
|
|
39
|
+
"./vite": {
|
|
40
|
+
"import": "./dist/adapters/vite.js",
|
|
41
|
+
"require": "./dist/adapters/vite.cjs",
|
|
42
|
+
"types": "./dist/adapters/vite.d.ts"
|
|
43
|
+
},
|
|
44
|
+
"./next": {
|
|
45
|
+
"import": "./dist/adapters/next.js",
|
|
46
|
+
"require": "./dist/adapters/next.cjs",
|
|
47
|
+
"types": "./dist/adapters/next.d.ts"
|
|
33
48
|
}
|
|
34
49
|
},
|
|
35
50
|
"files": [
|
|
36
51
|
"dist"
|
|
37
52
|
],
|
|
38
53
|
"scripts": {
|
|
39
|
-
"build": "tsup src
|
|
54
|
+
"build": "tsup src --format esm,cjs --dts --external zod,dotenv",
|
|
40
55
|
"dev": "tsup src/index.ts --watch --external zod,dotenv",
|
|
41
56
|
"lint": "eslint .",
|
|
42
57
|
"lint:fix": "eslint . --fix",
|
|
@@ -47,16 +62,13 @@
|
|
|
47
62
|
"peerDependencies": {
|
|
48
63
|
"zod": "^4.3.5"
|
|
49
64
|
},
|
|
50
|
-
"dependencies": {
|
|
51
|
-
"dotenv": "^16.4.7"
|
|
52
|
-
},
|
|
53
65
|
"peerDependenciesMeta": {
|
|
54
66
|
"zod": {
|
|
55
67
|
"optional": true
|
|
56
68
|
}
|
|
57
69
|
},
|
|
58
70
|
"devDependencies": {
|
|
59
|
-
"@types/node": "^25.0
|
|
71
|
+
"@types/node": "^25.1.0",
|
|
60
72
|
"@typescript-eslint/eslint-plugin": "^8.53.1",
|
|
61
73
|
"@typescript-eslint/parser": "^8.53.1",
|
|
62
74
|
"dotenv": "^17.2.3",
|