zenvx 0.2.2 → 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/README.md +11 -120
- package/dist/{chunk-3HCQKBTL.js → chunk-AUT6ZOMV.js} +6 -5
- package/dist/{chunk-R2XSSP2M.js → chunk-BPXBRFJ2.js} +9 -8
- package/dist/{chunk-ELPQSMQJ.js → chunk-LL4MFOXJ.js} +6 -5
- package/dist/core/define-env.cjs +38 -36
- package/dist/core/define-env.d.cts +2 -2
- package/dist/core/define-env.d.ts +2 -2
- package/dist/core/define-env.js +3 -3
- package/dist/core/parser.cjs +6 -5
- package/dist/core/parser.d.cts +5 -2
- package/dist/core/parser.d.ts +5 -2
- package/dist/core/parser.js +1 -1
- package/dist/core/types.d.cts +1 -1
- package/dist/core/types.d.ts +1 -1
- package/dist/index.cjs +40 -106
- package/dist/index.d.cts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +4 -8
- package/package.json +2 -23
- package/dist/adapters/next.cjs +0 -151
- package/dist/adapters/next.d.cts +0 -6
- package/dist/adapters/next.d.ts +0 -6
- package/dist/adapters/next.js +0 -32
- package/dist/adapters/node.cjs +0 -135
- package/dist/adapters/node.d.cts +0 -5
- package/dist/adapters/node.d.ts +0 -5
- package/dist/adapters/node.js +0 -17
- package/dist/adapters/vite.cjs +0 -135
- package/dist/adapters/vite.d.cts +0 -5
- package/dist/adapters/vite.d.ts +0 -5
- package/dist/adapters/vite.js +0 -16
- package/dist/chunk-E7OYVDFC.js +0 -67
- package/dist/core/tx.cjs +0 -91
- package/dist/core/tx.d.cts +0 -42
- package/dist/core/tx.d.ts +0 -42
- package/dist/core/tx.js +0 -6
package/dist/index.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
tx
|
|
3
|
-
} from "./chunk-E7OYVDFC.js";
|
|
4
1
|
import {
|
|
5
2
|
defineEnv
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-DX3SLVGQ.js";
|
|
3
|
+
} from "./chunk-LL4MFOXJ.js";
|
|
8
4
|
import "./chunk-KGVPNFG3.js";
|
|
9
|
-
import "./chunk-
|
|
5
|
+
import "./chunk-AUT6ZOMV.js";
|
|
6
|
+
import "./chunk-DX3SLVGQ.js";
|
|
10
7
|
export {
|
|
11
|
-
defineEnv
|
|
12
|
-
tx
|
|
8
|
+
defineEnv
|
|
13
9
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zenvx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -30,21 +30,6 @@
|
|
|
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"
|
|
48
33
|
}
|
|
49
34
|
},
|
|
50
35
|
"files": [
|
|
@@ -62,11 +47,6 @@
|
|
|
62
47
|
"peerDependencies": {
|
|
63
48
|
"zod": "^4.3.5"
|
|
64
49
|
},
|
|
65
|
-
"peerDependenciesMeta": {
|
|
66
|
-
"zod": {
|
|
67
|
-
"optional": true
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
50
|
"devDependencies": {
|
|
71
51
|
"@types/node": "^25.1.0",
|
|
72
52
|
"@typescript-eslint/eslint-plugin": "^8.53.1",
|
|
@@ -75,7 +55,6 @@
|
|
|
75
55
|
"eslint": "^9.39.2",
|
|
76
56
|
"rimraf": "^5.0.0",
|
|
77
57
|
"tsup": "^8.5.1",
|
|
78
|
-
"vitest": "^4.0.17"
|
|
79
|
-
"zod": "^4.3.5"
|
|
58
|
+
"vitest": "^4.0.17"
|
|
80
59
|
}
|
|
81
60
|
}
|
package/dist/adapters/next.cjs
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/adapters/next.ts
|
|
31
|
-
var next_exports = {};
|
|
32
|
-
__export(next_exports, {
|
|
33
|
-
loadClientEnv: () => loadClientEnv,
|
|
34
|
-
loadServerEnv: () => loadServerEnv
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(next_exports);
|
|
37
|
-
|
|
38
|
-
// src/core/define-env.ts
|
|
39
|
-
var import_zod3 = require("zod");
|
|
40
|
-
|
|
41
|
-
// src/core/parser.ts
|
|
42
|
-
var import_zod = require("zod");
|
|
43
|
-
function parseEnv(schema, source, mode = "runtime") {
|
|
44
|
-
const result = schema.safeParse(source);
|
|
45
|
-
if (!result.success) {
|
|
46
|
-
const issues = result.error.issues.map((i) => `\u274C ${i.path.join(".")}: ${i.message}`).join("\n");
|
|
47
|
-
const header = mode === "build" ? [
|
|
48
|
-
"\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",
|
|
49
|
-
"\u2502 \u274C INVALID ENVIRONMENT VARIABLES DETECTED \u2502",
|
|
50
|
-
"\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"
|
|
51
|
-
] : [
|
|
52
|
-
"\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",
|
|
53
|
-
"\u2502 \u26A0 WARNING INVALID ENVIRONMENT VARIABLES \u26A0 \u2502",
|
|
54
|
-
"\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"
|
|
55
|
-
];
|
|
56
|
-
const box = ["", ...header, issues, ""].join("\n");
|
|
57
|
-
if (mode === "build") {
|
|
58
|
-
throw new Error(box);
|
|
59
|
-
} else {
|
|
60
|
-
console.warn(box);
|
|
61
|
-
process.exit(1);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return result.success ? result.data : {};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// src/core/proxy.ts
|
|
68
|
-
function createTypedProxy(obj) {
|
|
69
|
-
return new Proxy(obj, {
|
|
70
|
-
get(target, prop) {
|
|
71
|
-
if (!(prop in target)) {
|
|
72
|
-
console.error(
|
|
73
|
-
`\u274C Tried to access undefined environment variable "${prop}"`
|
|
74
|
-
);
|
|
75
|
-
process.exit(1);
|
|
76
|
-
}
|
|
77
|
-
return target[prop];
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// src/core/generate-example.ts
|
|
83
|
-
var import_zod2 = require("zod");
|
|
84
|
-
var import_fs = __toESM(require("fs"), 1);
|
|
85
|
-
function getZodTypeName(schema) {
|
|
86
|
-
let type = "unknown";
|
|
87
|
-
if (schema instanceof import_zod2.ZodString) type = "string";
|
|
88
|
-
else if (schema instanceof import_zod2.ZodNumber) type = "number";
|
|
89
|
-
else if (schema instanceof import_zod2.ZodBoolean) type = "boolean";
|
|
90
|
-
return type;
|
|
91
|
-
}
|
|
92
|
-
function generateExample(schema, path = ".env.example") {
|
|
93
|
-
const header = [
|
|
94
|
-
"# Example environment variables",
|
|
95
|
-
"# Copy this file to .env and fill in the values",
|
|
96
|
-
""
|
|
97
|
-
];
|
|
98
|
-
const lines = Object.entries(schema.shape).map(([key, zodSchema]) => {
|
|
99
|
-
let placeholder = "";
|
|
100
|
-
let othertype = null;
|
|
101
|
-
let actualSchema = zodSchema;
|
|
102
|
-
if (zodSchema instanceof import_zod2.ZodOptional) actualSchema = zodSchema.unwrap();
|
|
103
|
-
if (zodSchema instanceof import_zod2.ZodDefault) {
|
|
104
|
-
actualSchema = zodSchema.def.innerType;
|
|
105
|
-
placeholder = zodSchema.def.defaultValue ?? "";
|
|
106
|
-
othertype = typeof zodSchema.def.defaultValue;
|
|
107
|
-
}
|
|
108
|
-
const type = getZodTypeName(actualSchema);
|
|
109
|
-
return `${key}=${placeholder ?? ""} # ${othertype ?? type}`;
|
|
110
|
-
});
|
|
111
|
-
const content = [...header, ...lines].join("\n") + "\n";
|
|
112
|
-
import_fs.default.writeFileSync(path, content);
|
|
113
|
-
console.log(`\u2705 .env.example generated at ${path}`);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// src/core/define-env.ts
|
|
117
|
-
function defineEnv(shape, source, options) {
|
|
118
|
-
const schema = import_zod3.z.object(shape);
|
|
119
|
-
const parsed = parseEnv(schema, source, options?.mode ?? "runtime");
|
|
120
|
-
if (options?.generateExample) {
|
|
121
|
-
generateExample(schema);
|
|
122
|
-
}
|
|
123
|
-
return createTypedProxy(parsed);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// src/adapters/next.ts
|
|
127
|
-
function loadServerEnv(shape) {
|
|
128
|
-
if (typeof window !== "undefined") {
|
|
129
|
-
throw new Error("Server env cannot be used in the browser");
|
|
130
|
-
}
|
|
131
|
-
return defineEnv(shape, process.env, {
|
|
132
|
-
mode: process.env.NEXT_PHASE === "phase-production-build" ? "build" : "runtime"
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
function loadClientEnv(shape) {
|
|
136
|
-
const clientEnv = {};
|
|
137
|
-
for (const key of Object.keys(shape)) {
|
|
138
|
-
if (!key.startsWith("NEXT_PUBLIC_")) {
|
|
139
|
-
throw new Error(`Client env "${key}" must start with NEXT_PUBLIC_`);
|
|
140
|
-
}
|
|
141
|
-
clientEnv[key] = process.env[key];
|
|
142
|
-
}
|
|
143
|
-
return defineEnv(shape, clientEnv, {
|
|
144
|
-
mode: "build"
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
148
|
-
0 && (module.exports = {
|
|
149
|
-
loadClientEnv,
|
|
150
|
-
loadServerEnv
|
|
151
|
-
});
|
package/dist/adapters/next.d.cts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import * as zod from 'zod';
|
|
2
|
-
|
|
3
|
-
declare function loadServerEnv<T extends Record<string, any>>(shape: T): { [K in keyof T]: zod.infer<T[K]>; };
|
|
4
|
-
declare function loadClientEnv<T extends Record<string, any>>(shape: T): { [K in keyof T]: zod.infer<T[K]>; };
|
|
5
|
-
|
|
6
|
-
export { loadClientEnv, loadServerEnv };
|
package/dist/adapters/next.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import * as zod from 'zod';
|
|
2
|
-
|
|
3
|
-
declare function loadServerEnv<T extends Record<string, any>>(shape: T): { [K in keyof T]: zod.infer<T[K]>; };
|
|
4
|
-
declare function loadClientEnv<T extends Record<string, any>>(shape: T): { [K in keyof T]: zod.infer<T[K]>; };
|
|
5
|
-
|
|
6
|
-
export { loadClientEnv, loadServerEnv };
|
package/dist/adapters/next.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
defineEnv
|
|
3
|
-
} from "../chunk-R2XSSP2M.js";
|
|
4
|
-
import "../chunk-DX3SLVGQ.js";
|
|
5
|
-
import "../chunk-KGVPNFG3.js";
|
|
6
|
-
import "../chunk-3HCQKBTL.js";
|
|
7
|
-
|
|
8
|
-
// src/adapters/next.ts
|
|
9
|
-
function loadServerEnv(shape) {
|
|
10
|
-
if (typeof window !== "undefined") {
|
|
11
|
-
throw new Error("Server env cannot be used in the browser");
|
|
12
|
-
}
|
|
13
|
-
return defineEnv(shape, process.env, {
|
|
14
|
-
mode: process.env.NEXT_PHASE === "phase-production-build" ? "build" : "runtime"
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
function loadClientEnv(shape) {
|
|
18
|
-
const clientEnv = {};
|
|
19
|
-
for (const key of Object.keys(shape)) {
|
|
20
|
-
if (!key.startsWith("NEXT_PUBLIC_")) {
|
|
21
|
-
throw new Error(`Client env "${key}" must start with NEXT_PUBLIC_`);
|
|
22
|
-
}
|
|
23
|
-
clientEnv[key] = process.env[key];
|
|
24
|
-
}
|
|
25
|
-
return defineEnv(shape, clientEnv, {
|
|
26
|
-
mode: "build"
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
export {
|
|
30
|
-
loadClientEnv,
|
|
31
|
-
loadServerEnv
|
|
32
|
-
};
|
package/dist/adapters/node.cjs
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/adapters/node.ts
|
|
31
|
-
var node_exports = {};
|
|
32
|
-
__export(node_exports, {
|
|
33
|
-
loadNodeEnv: () => loadNodeEnv
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(node_exports);
|
|
36
|
-
|
|
37
|
-
// src/core/define-env.ts
|
|
38
|
-
var import_zod3 = require("zod");
|
|
39
|
-
|
|
40
|
-
// src/core/parser.ts
|
|
41
|
-
var import_zod = require("zod");
|
|
42
|
-
function parseEnv(schema, source, mode = "runtime") {
|
|
43
|
-
const result = schema.safeParse(source);
|
|
44
|
-
if (!result.success) {
|
|
45
|
-
const issues = result.error.issues.map((i) => `\u274C ${i.path.join(".")}: ${i.message}`).join("\n");
|
|
46
|
-
const header = mode === "build" ? [
|
|
47
|
-
"\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",
|
|
48
|
-
"\u2502 \u274C INVALID ENVIRONMENT VARIABLES DETECTED \u2502",
|
|
49
|
-
"\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"
|
|
50
|
-
] : [
|
|
51
|
-
"\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",
|
|
52
|
-
"\u2502 \u26A0 WARNING INVALID ENVIRONMENT VARIABLES \u26A0 \u2502",
|
|
53
|
-
"\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"
|
|
54
|
-
];
|
|
55
|
-
const box = ["", ...header, issues, ""].join("\n");
|
|
56
|
-
if (mode === "build") {
|
|
57
|
-
throw new Error(box);
|
|
58
|
-
} else {
|
|
59
|
-
console.warn(box);
|
|
60
|
-
process.exit(1);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return result.success ? result.data : {};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// src/core/proxy.ts
|
|
67
|
-
function createTypedProxy(obj) {
|
|
68
|
-
return new Proxy(obj, {
|
|
69
|
-
get(target, prop) {
|
|
70
|
-
if (!(prop in target)) {
|
|
71
|
-
console.error(
|
|
72
|
-
`\u274C Tried to access undefined environment variable "${prop}"`
|
|
73
|
-
);
|
|
74
|
-
process.exit(1);
|
|
75
|
-
}
|
|
76
|
-
return target[prop];
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// src/core/generate-example.ts
|
|
82
|
-
var import_zod2 = require("zod");
|
|
83
|
-
var import_fs = __toESM(require("fs"), 1);
|
|
84
|
-
function getZodTypeName(schema) {
|
|
85
|
-
let type = "unknown";
|
|
86
|
-
if (schema instanceof import_zod2.ZodString) type = "string";
|
|
87
|
-
else if (schema instanceof import_zod2.ZodNumber) type = "number";
|
|
88
|
-
else if (schema instanceof import_zod2.ZodBoolean) type = "boolean";
|
|
89
|
-
return type;
|
|
90
|
-
}
|
|
91
|
-
function generateExample(schema, path = ".env.example") {
|
|
92
|
-
const header = [
|
|
93
|
-
"# Example environment variables",
|
|
94
|
-
"# Copy this file to .env and fill in the values",
|
|
95
|
-
""
|
|
96
|
-
];
|
|
97
|
-
const lines = Object.entries(schema.shape).map(([key, zodSchema]) => {
|
|
98
|
-
let placeholder = "";
|
|
99
|
-
let othertype = null;
|
|
100
|
-
let actualSchema = zodSchema;
|
|
101
|
-
if (zodSchema instanceof import_zod2.ZodOptional) actualSchema = zodSchema.unwrap();
|
|
102
|
-
if (zodSchema instanceof import_zod2.ZodDefault) {
|
|
103
|
-
actualSchema = zodSchema.def.innerType;
|
|
104
|
-
placeholder = zodSchema.def.defaultValue ?? "";
|
|
105
|
-
othertype = typeof zodSchema.def.defaultValue;
|
|
106
|
-
}
|
|
107
|
-
const type = getZodTypeName(actualSchema);
|
|
108
|
-
return `${key}=${placeholder ?? ""} # ${othertype ?? type}`;
|
|
109
|
-
});
|
|
110
|
-
const content = [...header, ...lines].join("\n") + "\n";
|
|
111
|
-
import_fs.default.writeFileSync(path, content);
|
|
112
|
-
console.log(`\u2705 .env.example generated at ${path}`);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// src/core/define-env.ts
|
|
116
|
-
function defineEnv(shape, source, options) {
|
|
117
|
-
const schema = import_zod3.z.object(shape);
|
|
118
|
-
const parsed = parseEnv(schema, source, options?.mode ?? "runtime");
|
|
119
|
-
if (options?.generateExample) {
|
|
120
|
-
generateExample(schema);
|
|
121
|
-
}
|
|
122
|
-
return createTypedProxy(parsed);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// src/adapters/node.ts
|
|
126
|
-
function loadNodeEnv(shape) {
|
|
127
|
-
return defineEnv(shape, process.env, {
|
|
128
|
-
mode: "runtime",
|
|
129
|
-
generateExample: true
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
133
|
-
0 && (module.exports = {
|
|
134
|
-
loadNodeEnv
|
|
135
|
-
});
|
package/dist/adapters/node.d.cts
DELETED
package/dist/adapters/node.d.ts
DELETED
package/dist/adapters/node.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
defineEnv
|
|
3
|
-
} from "../chunk-R2XSSP2M.js";
|
|
4
|
-
import "../chunk-DX3SLVGQ.js";
|
|
5
|
-
import "../chunk-KGVPNFG3.js";
|
|
6
|
-
import "../chunk-3HCQKBTL.js";
|
|
7
|
-
|
|
8
|
-
// src/adapters/node.ts
|
|
9
|
-
function loadNodeEnv(shape) {
|
|
10
|
-
return defineEnv(shape, process.env, {
|
|
11
|
-
mode: "runtime",
|
|
12
|
-
generateExample: true
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
export {
|
|
16
|
-
loadNodeEnv
|
|
17
|
-
};
|
package/dist/adapters/vite.cjs
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/adapters/vite.ts
|
|
31
|
-
var vite_exports = {};
|
|
32
|
-
__export(vite_exports, {
|
|
33
|
-
loadViteEnv: () => loadViteEnv
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(vite_exports);
|
|
36
|
-
|
|
37
|
-
// src/core/define-env.ts
|
|
38
|
-
var import_zod3 = require("zod");
|
|
39
|
-
|
|
40
|
-
// src/core/parser.ts
|
|
41
|
-
var import_zod = require("zod");
|
|
42
|
-
function parseEnv(schema, source, mode = "runtime") {
|
|
43
|
-
const result = schema.safeParse(source);
|
|
44
|
-
if (!result.success) {
|
|
45
|
-
const issues = result.error.issues.map((i) => `\u274C ${i.path.join(".")}: ${i.message}`).join("\n");
|
|
46
|
-
const header = mode === "build" ? [
|
|
47
|
-
"\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",
|
|
48
|
-
"\u2502 \u274C INVALID ENVIRONMENT VARIABLES DETECTED \u2502",
|
|
49
|
-
"\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"
|
|
50
|
-
] : [
|
|
51
|
-
"\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",
|
|
52
|
-
"\u2502 \u26A0 WARNING INVALID ENVIRONMENT VARIABLES \u26A0 \u2502",
|
|
53
|
-
"\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"
|
|
54
|
-
];
|
|
55
|
-
const box = ["", ...header, issues, ""].join("\n");
|
|
56
|
-
if (mode === "build") {
|
|
57
|
-
throw new Error(box);
|
|
58
|
-
} else {
|
|
59
|
-
console.warn(box);
|
|
60
|
-
process.exit(1);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return result.success ? result.data : {};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// src/core/proxy.ts
|
|
67
|
-
function createTypedProxy(obj) {
|
|
68
|
-
return new Proxy(obj, {
|
|
69
|
-
get(target, prop) {
|
|
70
|
-
if (!(prop in target)) {
|
|
71
|
-
console.error(
|
|
72
|
-
`\u274C Tried to access undefined environment variable "${prop}"`
|
|
73
|
-
);
|
|
74
|
-
process.exit(1);
|
|
75
|
-
}
|
|
76
|
-
return target[prop];
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// src/core/generate-example.ts
|
|
82
|
-
var import_zod2 = require("zod");
|
|
83
|
-
var import_fs = __toESM(require("fs"), 1);
|
|
84
|
-
function getZodTypeName(schema) {
|
|
85
|
-
let type = "unknown";
|
|
86
|
-
if (schema instanceof import_zod2.ZodString) type = "string";
|
|
87
|
-
else if (schema instanceof import_zod2.ZodNumber) type = "number";
|
|
88
|
-
else if (schema instanceof import_zod2.ZodBoolean) type = "boolean";
|
|
89
|
-
return type;
|
|
90
|
-
}
|
|
91
|
-
function generateExample(schema, path = ".env.example") {
|
|
92
|
-
const header = [
|
|
93
|
-
"# Example environment variables",
|
|
94
|
-
"# Copy this file to .env and fill in the values",
|
|
95
|
-
""
|
|
96
|
-
];
|
|
97
|
-
const lines = Object.entries(schema.shape).map(([key, zodSchema]) => {
|
|
98
|
-
let placeholder = "";
|
|
99
|
-
let othertype = null;
|
|
100
|
-
let actualSchema = zodSchema;
|
|
101
|
-
if (zodSchema instanceof import_zod2.ZodOptional) actualSchema = zodSchema.unwrap();
|
|
102
|
-
if (zodSchema instanceof import_zod2.ZodDefault) {
|
|
103
|
-
actualSchema = zodSchema.def.innerType;
|
|
104
|
-
placeholder = zodSchema.def.defaultValue ?? "";
|
|
105
|
-
othertype = typeof zodSchema.def.defaultValue;
|
|
106
|
-
}
|
|
107
|
-
const type = getZodTypeName(actualSchema);
|
|
108
|
-
return `${key}=${placeholder ?? ""} # ${othertype ?? type}`;
|
|
109
|
-
});
|
|
110
|
-
const content = [...header, ...lines].join("\n") + "\n";
|
|
111
|
-
import_fs.default.writeFileSync(path, content);
|
|
112
|
-
console.log(`\u2705 .env.example generated at ${path}`);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// src/core/define-env.ts
|
|
116
|
-
function defineEnv(shape, source, options) {
|
|
117
|
-
const schema = import_zod3.z.object(shape);
|
|
118
|
-
const parsed = parseEnv(schema, source, options?.mode ?? "runtime");
|
|
119
|
-
if (options?.generateExample) {
|
|
120
|
-
generateExample(schema);
|
|
121
|
-
}
|
|
122
|
-
return createTypedProxy(parsed);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// src/adapters/vite.ts
|
|
126
|
-
var import_meta = {};
|
|
127
|
-
function loadViteEnv(shape) {
|
|
128
|
-
return defineEnv(shape, import_meta.env, {
|
|
129
|
-
mode: "build"
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
133
|
-
0 && (module.exports = {
|
|
134
|
-
loadViteEnv
|
|
135
|
-
});
|
package/dist/adapters/vite.d.cts
DELETED
package/dist/adapters/vite.d.ts
DELETED
package/dist/adapters/vite.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
defineEnv
|
|
3
|
-
} from "../chunk-R2XSSP2M.js";
|
|
4
|
-
import "../chunk-DX3SLVGQ.js";
|
|
5
|
-
import "../chunk-KGVPNFG3.js";
|
|
6
|
-
import "../chunk-3HCQKBTL.js";
|
|
7
|
-
|
|
8
|
-
// src/adapters/vite.ts
|
|
9
|
-
function loadViteEnv(shape) {
|
|
10
|
-
return defineEnv(shape, import.meta.env, {
|
|
11
|
-
mode: "build"
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
export {
|
|
15
|
-
loadViteEnv
|
|
16
|
-
};
|
package/dist/chunk-E7OYVDFC.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
// src/core/tx.ts
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
var SEMVER_REGEX = /^\d+\.\d+\.\d+(-[0-9A-Za-z-.]+)?$/;
|
|
4
|
-
var tx = {
|
|
5
|
-
/**
|
|
6
|
-
* STRICT STRING:
|
|
7
|
-
* Rejects purely numeric strings (e.g. "12345").
|
|
8
|
-
* Good for API Keys.
|
|
9
|
-
*/
|
|
10
|
-
string: (message = "Value should be text, but looks like a number.") => z.string().trim().regex(/^(?!\d+$).+$/, { error: message }).describe("Non-numeric string"),
|
|
11
|
-
/**
|
|
12
|
-
* SMART NUMBER:
|
|
13
|
-
* Automatically converts "3000" -> 3000.
|
|
14
|
-
* Fails if the value is not a valid number (e.g. "abc").
|
|
15
|
-
*/
|
|
16
|
-
number: (message = "Must be a number") => z.coerce.number({ error: message }).finite().describe("Numeric value"),
|
|
17
|
-
/**
|
|
18
|
-
* PORT VALIDATOR:
|
|
19
|
-
* Coerces to number and ensures it is between 1 and 65535.
|
|
20
|
-
*/
|
|
21
|
-
port: (message = "Must be a valid port (1\u201365535)") => z.coerce.number({ error: message }).int().min(1).max(65535).describe("TCP/UDP port number (1\u201365535)"),
|
|
22
|
-
/**
|
|
23
|
-
* SMART BOOLEAN:
|
|
24
|
-
* Handles "true", "TRUE", "1" -> true
|
|
25
|
-
* Handles "false", "FALSE", "0" -> false
|
|
26
|
-
* Throws error on anything else.
|
|
27
|
-
*/
|
|
28
|
-
bool: (message) => {
|
|
29
|
-
return z.union([z.string(), z.boolean()]).transform((val, ctx) => {
|
|
30
|
-
if (typeof val === "boolean") return val;
|
|
31
|
-
const v = val.toLowerCase();
|
|
32
|
-
if (v === "true" || v === "1") return true;
|
|
33
|
-
if (v === "false" || v === "0") return false;
|
|
34
|
-
ctx.addIssue({
|
|
35
|
-
code: z.ZodIssueCode.custom,
|
|
36
|
-
message: message || 'Must be a boolean ("true"/"false"/"1"/"0")'
|
|
37
|
-
});
|
|
38
|
-
return z.NEVER;
|
|
39
|
-
});
|
|
40
|
-
},
|
|
41
|
-
/**
|
|
42
|
-
* URL:
|
|
43
|
-
* Strict URL checking.
|
|
44
|
-
*/
|
|
45
|
-
url: (message = "Must be a valid URL (e.g. https://...)") => z.url({ error: message }).describe("A valid URL including protocol"),
|
|
46
|
-
email: (message = "Must be a valid email address") => z.email({ error: message }).describe("A valid email address"),
|
|
47
|
-
positiveNumber: (message = "Must be > 0") => z.coerce.number().gt(0, { error: message }).describe("A positive number"),
|
|
48
|
-
nonEmptyString: (message = "Cannot be empty") => z.string().trim().min(1, { error: message }).describe("A non-empty string"),
|
|
49
|
-
semver: (message = "Must be valid semver") => z.string().regex(SEMVER_REGEX, { error: message }).describe("Semantic version (x.y.z)"),
|
|
50
|
-
path: (message = "Must be a valid path") => z.string().trim().min(1, { error: message }).describe("Filesystem path"),
|
|
51
|
-
enum: (values, message = `Must be one of: ${values.join(", ")}`) => z.enum(values, { error: message }).describe(`One of: ${values.join(", ")}`),
|
|
52
|
-
json: (message = "Must be valid JSON") => z.string().transform((val, ctx) => {
|
|
53
|
-
try {
|
|
54
|
-
return JSON.parse(val);
|
|
55
|
-
} catch {
|
|
56
|
-
ctx.addIssue({
|
|
57
|
-
code: "custom",
|
|
58
|
-
error: message
|
|
59
|
-
});
|
|
60
|
-
return z.NEVER;
|
|
61
|
-
}
|
|
62
|
-
}).describe("JSON-encoded value")
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export {
|
|
66
|
-
tx
|
|
67
|
-
};
|