@geekmidas/envkit 0.0.7 → 0.0.8

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.
Files changed (46) hide show
  1. package/dist/{EnvironmentParser-C-arQEHQ.d.mts → EnvironmentParser-B8--woiB.d.cts} +40 -2
  2. package/dist/{EnvironmentParser-X4h2Vp4r.d.cts → EnvironmentParser-C_9v2BDw.d.mts} +40 -2
  3. package/dist/{EnvironmentParser-CQUOGqc0.mjs → EnvironmentParser-STvN_RCc.mjs} +46 -3
  4. package/dist/EnvironmentParser-STvN_RCc.mjs.map +1 -0
  5. package/dist/{EnvironmentParser-BDPDLv6i.cjs → EnvironmentParser-cnxuy7lw.cjs} +46 -3
  6. package/dist/EnvironmentParser-cnxuy7lw.cjs.map +1 -0
  7. package/dist/EnvironmentParser.cjs +1 -1
  8. package/dist/EnvironmentParser.d.cts +1 -1
  9. package/dist/EnvironmentParser.d.mts +1 -1
  10. package/dist/EnvironmentParser.mjs +1 -1
  11. package/dist/SnifferEnvironmentParser.cjs +140 -0
  12. package/dist/SnifferEnvironmentParser.cjs.map +1 -0
  13. package/dist/SnifferEnvironmentParser.d.cts +50 -0
  14. package/dist/SnifferEnvironmentParser.d.mts +50 -0
  15. package/dist/SnifferEnvironmentParser.mjs +139 -0
  16. package/dist/SnifferEnvironmentParser.mjs.map +1 -0
  17. package/dist/index.cjs +2 -1
  18. package/dist/index.d.cts +2 -2
  19. package/dist/index.d.mts +2 -2
  20. package/dist/index.mjs +2 -2
  21. package/dist/sst.cjs +131 -4
  22. package/dist/sst.cjs.map +1 -0
  23. package/dist/sst.d.cts +2 -1
  24. package/dist/sst.d.mts +2 -1
  25. package/dist/sst.mjs +128 -2
  26. package/dist/sst.mjs.map +1 -0
  27. package/package.json +6 -1
  28. package/src/EnvironmentParser.ts +51 -2
  29. package/src/SnifferEnvironmentParser.ts +207 -0
  30. package/src/__tests__/EnvironmentParser.spec.ts +147 -0
  31. package/src/__tests__/SnifferEnvironmentParser.spec.ts +332 -0
  32. package/src/index.ts +1 -1
  33. package/dist/__tests__/ConfigParser.spec.cjs +0 -323
  34. package/dist/__tests__/ConfigParser.spec.d.cts +0 -1
  35. package/dist/__tests__/ConfigParser.spec.d.mts +0 -1
  36. package/dist/__tests__/ConfigParser.spec.mjs +0 -322
  37. package/dist/__tests__/EnvironmentParser.spec.cjs +0 -422
  38. package/dist/__tests__/EnvironmentParser.spec.d.cts +0 -1
  39. package/dist/__tests__/EnvironmentParser.spec.d.mts +0 -1
  40. package/dist/__tests__/EnvironmentParser.spec.mjs +0 -421
  41. package/dist/__tests__/sst.spec.cjs +0 -305
  42. package/dist/__tests__/sst.spec.d.cts +0 -1
  43. package/dist/__tests__/sst.spec.d.mts +0 -1
  44. package/dist/__tests__/sst.spec.mjs +0 -304
  45. package/dist/sst-BSxwaAdz.cjs +0 -146
  46. package/dist/sst-CQhO0S6y.mjs +0 -128
@@ -1,422 +0,0 @@
1
- const require_chunk = require('../chunk-CUT6urMc.cjs');
2
- const require_EnvironmentParser = require('../EnvironmentParser-BDPDLv6i.cjs');
3
- const zod_v4 = require_chunk.__toESM(require("zod/v4"));
4
- const vitest = require_chunk.__toESM(require("vitest"));
5
-
6
- //#region src/__tests__/EnvironmentParser.spec.ts
7
- (0, vitest.describe)("EnvironmentParser", () => {
8
- (0, vitest.describe)("Basic parsing functionality", () => {
9
- (0, vitest.it)("should parse simple string values", () => {
10
- const env = { APP_NAME: "Test App" };
11
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
12
- const config = parser.create((get) => ({ appName: get("APP_NAME").string() })).parse();
13
- (0, vitest.expect)(config).toEqual({ appName: "Test App" });
14
- });
15
- (0, vitest.it)("should parse with default values when env var is missing", () => {
16
- const env = {};
17
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
18
- const config = parser.create((get) => ({
19
- appName: get("APP_NAME").string().default("Default App"),
20
- port: get("PORT").string().transform(Number).default(3e3)
21
- })).parse();
22
- (0, vitest.expect)(config).toEqual({
23
- appName: "Default App",
24
- port: 3e3
25
- });
26
- });
27
- (0, vitest.it)("should transform string to number", () => {
28
- const env = { PORT: "8080" };
29
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
30
- const config = parser.create((get) => ({ port: get("PORT").string().transform(Number) })).parse();
31
- (0, vitest.expect)(config).toEqual({ port: 8080 });
32
- });
33
- (0, vitest.it)("should transform string to boolean", () => {
34
- const env = {
35
- FEATURE_ENABLED: "true",
36
- FEATURE_DISABLED: "false",
37
- FEATURE_TRUTHY: "yes"
38
- };
39
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
40
- const config = parser.create((get) => ({
41
- enabled: get("FEATURE_ENABLED").string().transform((v) => v === "true"),
42
- disabled: get("FEATURE_DISABLED").string().transform((v) => v === "true"),
43
- truthy: get("FEATURE_TRUTHY").string().transform((v) => v === "true")
44
- })).parse();
45
- (0, vitest.expect)(config).toEqual({
46
- enabled: true,
47
- disabled: false,
48
- truthy: false
49
- });
50
- });
51
- (0, vitest.it)("should handle optional values", () => {
52
- const env = { REQUIRED: "value" };
53
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
54
- const config = parser.create((get) => ({
55
- required: get("REQUIRED").string(),
56
- optional: get("OPTIONAL").string().optional()
57
- })).parse();
58
- (0, vitest.expect)(config).toEqual({
59
- required: "value",
60
- optional: void 0
61
- });
62
- });
63
- (0, vitest.it)("should validate URLs", () => {
64
- const env = {
65
- VALID_URL: "https://example.com",
66
- DATABASE_URL: "postgresql://user:pass@localhost:5432/db"
67
- };
68
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
69
- const config = parser.create((get) => ({
70
- apiUrl: get("VALID_URL").string().url(),
71
- dbUrl: get("DATABASE_URL").string().url()
72
- })).parse();
73
- (0, vitest.expect)(config).toEqual({
74
- apiUrl: "https://example.com",
75
- dbUrl: "postgresql://user:pass@localhost:5432/db"
76
- });
77
- });
78
- (0, vitest.it)("should validate email addresses", () => {
79
- const env = { ADMIN_EMAIL: "admin@example.com" };
80
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
81
- const config = parser.create((get) => ({ adminEmail: get("ADMIN_EMAIL").string().email() })).parse();
82
- (0, vitest.expect)(config).toEqual({ adminEmail: "admin@example.com" });
83
- });
84
- (0, vitest.it)("should validate enums", () => {
85
- const env = { NODE_ENV: "production" };
86
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
87
- const config = parser.create((get) => ({ env: get("NODE_ENV").enum([
88
- "development",
89
- "staging",
90
- "production"
91
- ]) })).parse();
92
- (0, vitest.expect)(config).toEqual({ env: "production" });
93
- });
94
- });
95
- (0, vitest.describe)("Nested configuration", () => {
96
- (0, vitest.it)("should handle nested objects", () => {
97
- const env = {
98
- DB_HOST: "localhost",
99
- DB_PORT: "5432",
100
- DB_NAME: "myapp",
101
- API_KEY: "secret123",
102
- API_URL: "https://api.example.com"
103
- };
104
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
105
- const config = parser.create((get) => ({
106
- database: {
107
- host: get("DB_HOST").string(),
108
- port: get("DB_PORT").string().transform(Number),
109
- name: get("DB_NAME").string()
110
- },
111
- api: {
112
- key: get("API_KEY").string(),
113
- url: get("API_URL").string().url()
114
- }
115
- })).parse();
116
- (0, vitest.expect)(config).toEqual({
117
- database: {
118
- host: "localhost",
119
- port: 5432,
120
- name: "myapp"
121
- },
122
- api: {
123
- key: "secret123",
124
- url: "https://api.example.com"
125
- }
126
- });
127
- });
128
- (0, vitest.it)("should handle deeply nested objects", () => {
129
- const env = {
130
- FEATURE_AUTH_ENABLED: "true",
131
- FEATURE_AUTH_PROVIDER: "oauth",
132
- FEATURE_CACHE_ENABLED: "false",
133
- FEATURE_CACHE_TTL: "3600"
134
- };
135
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
136
- const config = parser.create((get) => ({ features: {
137
- authentication: {
138
- enabled: get("FEATURE_AUTH_ENABLED").string().transform((v) => v === "true"),
139
- provider: get("FEATURE_AUTH_PROVIDER").string()
140
- },
141
- cache: {
142
- enabled: get("FEATURE_CACHE_ENABLED").string().transform((v) => v === "true"),
143
- ttl: get("FEATURE_CACHE_TTL").string().transform(Number)
144
- }
145
- } })).parse();
146
- (0, vitest.expect)(config).toEqual({ features: {
147
- authentication: {
148
- enabled: true,
149
- provider: "oauth"
150
- },
151
- cache: {
152
- enabled: false,
153
- ttl: 3600
154
- }
155
- } });
156
- });
157
- (0, vitest.it)("should handle mixed nested objects with defaults", () => {
158
- const env = {
159
- DB_HOST: "custom-host",
160
- REDIS_TTL: "7200"
161
- };
162
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
163
- const config = parser.create((get) => ({
164
- database: {
165
- host: get("DB_HOST").string(),
166
- port: get("DB_PORT").string().transform(Number).default(5432),
167
- ssl: get("DB_SSL").string().transform((v) => v === "true").default(false)
168
- },
169
- cache: { redis: {
170
- host: get("REDIS_HOST").string().default("localhost"),
171
- port: get("REDIS_PORT").string().transform(Number).default(6379),
172
- ttl: get("REDIS_TTL").string().transform(Number)
173
- } }
174
- })).parse();
175
- (0, vitest.expect)(config).toEqual({
176
- database: {
177
- host: "custom-host",
178
- port: 5432,
179
- ssl: false
180
- },
181
- cache: { redis: {
182
- host: "localhost",
183
- port: 6379,
184
- ttl: 7200
185
- } }
186
- });
187
- });
188
- });
189
- (0, vitest.describe)("Error handling and validation", () => {
190
- (0, vitest.it)("should throw ZodError for missing required values", () => {
191
- const env = {};
192
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
193
- (0, vitest.expect)(() => {
194
- parser.create((get) => ({ required: get("REQUIRED_VAR").string() })).parse();
195
- }).toThrow(zod_v4.z.ZodError);
196
- });
197
- (0, vitest.it)("should throw ZodError with descriptive error messages", () => {
198
- const env = {};
199
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
200
- try {
201
- parser.create((get) => ({
202
- apiKey: get("API_KEY").string().min(32),
203
- dbUrl: get("DATABASE_URL").string().url()
204
- })).parse();
205
- } catch (error) {
206
- (0, vitest.expect)(error).toBeInstanceOf(zod_v4.z.ZodError);
207
- const zodError = error;
208
- (0, vitest.expect)(zodError.issues).toHaveLength(2);
209
- (0, vitest.expect)(zodError.issues[0].message).toContain("Environment variable \"API_KEY\"");
210
- (0, vitest.expect)(zodError.issues[1].message).toContain("Environment variable \"DATABASE_URL\"");
211
- }
212
- });
213
- (0, vitest.it)("should validate minimum string length", () => {
214
- const env = { API_KEY: "short" };
215
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
216
- (0, vitest.expect)(() => {
217
- parser.create((get) => ({ apiKey: get("API_KEY").string().min(32) })).parse();
218
- }).toThrow(zod_v4.z.ZodError);
219
- });
220
- (0, vitest.it)("should validate maximum string length", () => {
221
- const env = { SHORT_TEXT: "a".repeat(100) };
222
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
223
- (0, vitest.expect)(() => {
224
- parser.create((get) => ({ shortText: get("SHORT_TEXT").string().max(50) })).parse();
225
- }).toThrow(zod_v4.z.ZodError);
226
- });
227
- (0, vitest.it)("should validate exact string length", () => {
228
- const env = {
229
- VALID_KEY: "a".repeat(32),
230
- INVALID_KEY: "short"
231
- };
232
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
233
- const validConfig = parser.create((get) => ({ key: get("VALID_KEY").string().length(32) })).parse();
234
- (0, vitest.expect)(validConfig).toEqual({ key: "a".repeat(32) });
235
- (0, vitest.expect)(() => {
236
- parser.create((get) => ({ key: get("INVALID_KEY").string().length(32) })).parse();
237
- }).toThrow(zod_v4.z.ZodError);
238
- });
239
- (0, vitest.it)("should validate invalid URLs", () => {
240
- const env = { INVALID_URL: "not-a-url" };
241
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
242
- (0, vitest.expect)(() => {
243
- parser.create((get) => ({ url: get("INVALID_URL").string().url() })).parse();
244
- }).toThrow(zod_v4.z.ZodError);
245
- });
246
- (0, vitest.it)("should validate invalid email addresses", () => {
247
- const env = { INVALID_EMAIL: "not-an-email" };
248
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
249
- (0, vitest.expect)(() => {
250
- parser.create((get) => ({ email: get("INVALID_EMAIL").string().email() })).parse();
251
- }).toThrow(zod_v4.z.ZodError);
252
- });
253
- (0, vitest.it)("should validate invalid enum values", () => {
254
- const env = { NODE_ENV: "invalid" };
255
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
256
- (0, vitest.expect)(() => {
257
- parser.create((get) => ({ env: get("NODE_ENV").enum([
258
- "development",
259
- "staging",
260
- "production"
261
- ]) })).parse();
262
- }).toThrow(zod_v4.z.ZodError);
263
- });
264
- (0, vitest.it)("should validate number ranges", () => {
265
- const env = {
266
- VALID_PORT: "8080",
267
- INVALID_PORT_LOW: "0",
268
- INVALID_PORT_HIGH: "70000"
269
- };
270
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
271
- const validConfig = parser.create((get) => ({ port: get("VALID_PORT").coerce.number().min(1).max(65535) })).parse();
272
- (0, vitest.expect)(validConfig).toEqual({ port: 8080 });
273
- (0, vitest.expect)(() => {
274
- parser.create((get) => ({ port: get("INVALID_PORT_LOW").coerce.number().min(1).max(65535) })).parse();
275
- }).toThrow(zod_v4.z.ZodError);
276
- (0, vitest.expect)(() => {
277
- parser.create((get) => ({ port: get("INVALID_PORT_HIGH").coerce.number().min(1).max(65535) })).parse();
278
- }).toThrow(zod_v4.z.ZodError);
279
- });
280
- (0, vitest.it)("should handle transformation errors", () => {
281
- const env = { INVALID_NUMBER: "not-a-number" };
282
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
283
- (0, vitest.expect)(() => {
284
- parser.create((get) => ({ number: get("INVALID_NUMBER").string().transform((v) => {
285
- const num = Number(v);
286
- if (isNaN(num)) throw new Error("Invalid number");
287
- return num;
288
- }) })).parse();
289
- }).toThrow();
290
- });
291
- });
292
- (0, vitest.describe)("Complex scenarios", () => {
293
- (0, vitest.it)("should handle array transformations", () => {
294
- const env = {
295
- ALLOWED_ORIGINS: "http://localhost:3000,https://example.com,https://app.example.com",
296
- FEATURE_FLAGS: "auth,cache,notifications"
297
- };
298
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
299
- const config = parser.create((get) => ({
300
- cors: { origins: get("ALLOWED_ORIGINS").string().transform((origins) => origins.split(",").map((o) => o.trim())) },
301
- features: get("FEATURE_FLAGS").string().transform((flags) => flags.split(",").map((f) => f.trim()))
302
- })).parse();
303
- (0, vitest.expect)(config).toEqual({
304
- cors: { origins: [
305
- "http://localhost:3000",
306
- "https://example.com",
307
- "https://app.example.com"
308
- ] },
309
- features: [
310
- "auth",
311
- "cache",
312
- "notifications"
313
- ]
314
- });
315
- });
316
- (0, vitest.it)("should handle JSON parsing", () => {
317
- const env = {
318
- FEATURE_CONFIG: "{\"auth\":true,\"cache\":false,\"debug\":true}",
319
- RATE_LIMITS: "{\"requests\":100,\"window\":60000}"
320
- };
321
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
322
- const config = parser.create((get) => ({
323
- features: get("FEATURE_CONFIG").string().transform((str) => JSON.parse(str)).pipe(zod_v4.z.record(zod_v4.z.string(), zod_v4.z.boolean())),
324
- rateLimits: get("RATE_LIMITS").string().transform((str) => JSON.parse(str)).pipe(zod_v4.z.object({
325
- requests: zod_v4.z.number(),
326
- window: zod_v4.z.number()
327
- }))
328
- })).parse();
329
- (0, vitest.expect)(config).toEqual({
330
- features: {
331
- auth: true,
332
- cache: false,
333
- debug: true
334
- },
335
- rateLimits: {
336
- requests: 100,
337
- window: 6e4
338
- }
339
- });
340
- });
341
- (0, vitest.it)("should handle custom refinements", () => {
342
- const env = {
343
- CORS_ORIGINS: "https://example.com,https://app.example.com",
344
- API_KEYS: "key1234567890123456789012345678901,key2345678901234567890123456789012"
345
- };
346
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
347
- const config = parser.create((get) => ({
348
- cors: { origins: get("CORS_ORIGINS").string().transform((origins) => origins.split(",").map((o) => o.trim())).refine((origins) => origins.every((o) => o.startsWith("https://")), { message: "All CORS origins must use HTTPS" }) },
349
- apiKeys: get("API_KEYS").string().transform((keys) => keys.split(",").map((k) => k.trim())).pipe(zod_v4.z.array(zod_v4.z.string().min(32)))
350
- })).parse();
351
- (0, vitest.expect)(config).toEqual({
352
- cors: { origins: ["https://example.com", "https://app.example.com"] },
353
- apiKeys: ["key1234567890123456789012345678901", "key2345678901234567890123456789012"]
354
- });
355
- });
356
- (0, vitest.it)("should fail refinements with descriptive errors", () => {
357
- const env = { CORS_ORIGINS: "http://example.com,https://app.example.com" };
358
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
359
- (0, vitest.expect)(() => {
360
- parser.create((get) => ({ cors: { origins: get("CORS_ORIGINS").string().transform((origins) => origins.split(",").map((o) => o.trim())).refine((origins) => origins.every((o) => o.startsWith("https://")), { message: "All CORS origins must use HTTPS" }) } })).parse();
361
- }).toThrow(zod_v4.z.ZodError);
362
- });
363
- });
364
- (0, vitest.describe)("Type inference", () => {
365
- (0, vitest.it)("should correctly infer string types", () => {
366
- const env = { APP_NAME: "Test App" };
367
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
368
- const config = parser.create((get) => ({ appName: get("APP_NAME").string() })).parse();
369
- const _typeCheck = true;
370
- const _typeCheck2 = true;
371
- (0, vitest.expect)(_typeCheck).toBe(true);
372
- (0, vitest.expect)(_typeCheck2).toBe(true);
373
- });
374
- (0, vitest.it)("should correctly infer number types after transformation", () => {
375
- const env = { PORT: "3000" };
376
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
377
- const config = parser.create((get) => ({ port: get("PORT").string().transform(Number) })).parse();
378
- const _typeCheck = true;
379
- const _typeCheck2 = true;
380
- (0, vitest.expect)(_typeCheck).toBe(true);
381
- (0, vitest.expect)(_typeCheck2).toBe(true);
382
- });
383
- (0, vitest.it)("should correctly infer boolean types after transformation", () => {
384
- const env = { FEATURE_ENABLED: "true" };
385
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
386
- const config = parser.create((get) => ({ enabled: get("FEATURE_ENABLED").string().transform((v) => v === "true") })).parse();
387
- const _typeCheck = true;
388
- const _typeCheck2 = true;
389
- (0, vitest.expect)(_typeCheck).toBe(true);
390
- (0, vitest.expect)(_typeCheck2).toBe(true);
391
- });
392
- (0, vitest.it)("should correctly infer optional types", () => {
393
- const env = { REQUIRED: "value" };
394
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
395
- const config = parser.create((get) => ({
396
- required: get("REQUIRED").string(),
397
- optional: get("OPTIONAL").string().optional()
398
- })).parse();
399
- });
400
- (0, vitest.it)("should correctly infer nested object types", () => {
401
- const env = {
402
- DB_HOST: "localhost",
403
- DB_PORT: "5432",
404
- API_KEY: "secret"
405
- };
406
- const parser = new require_EnvironmentParser.EnvironmentParser(env);
407
- const config = parser.create((get) => ({
408
- database: {
409
- host: get("DB_HOST").string(),
410
- port: get("DB_PORT").string().transform(Number)
411
- },
412
- api: { key: get("API_KEY").string() }
413
- })).parse();
414
- const _typeCheck = true;
415
- const _typeCheck2 = true;
416
- (0, vitest.expect)(_typeCheck).toBe(true);
417
- (0, vitest.expect)(_typeCheck2).toBe(true);
418
- });
419
- });
420
- });
421
-
422
- //#endregion
@@ -1 +0,0 @@
1
- export { };
@@ -1 +0,0 @@
1
- export { };