@geekmidas/envkit 0.0.4 → 0.0.5

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.
@@ -0,0 +1,108 @@
1
+ import { z } from "zod/v4";
2
+
3
+ //#region src/EnvironmentParser.d.ts
4
+
5
+ /**
6
+ * Parses and validates configuration objects against Zod schemas.
7
+ * Handles nested configurations and aggregates validation errors.
8
+ *
9
+ * @template TResponse - The shape of the configuration object
10
+ */
11
+ declare class ConfigParser<TResponse extends EmptyObject> {
12
+ private readonly config;
13
+ /**
14
+ * Creates a new ConfigParser instance.
15
+ *
16
+ * @param config - The configuration object to parse
17
+ */
18
+ constructor(config: TResponse);
19
+ /**
20
+ * Parses the config object and validates it against the Zod schemas
21
+ * @returns The parsed config object
22
+ */
23
+ parse(): InferConfig<TResponse>;
24
+ }
25
+ /**
26
+ * Parses environment variables with type-safe validation using Zod schemas.
27
+ * Provides a fluent API for defining environment variable schemas with automatic
28
+ * error context enrichment.
29
+ *
30
+ * @template T - The type of the configuration object (typically process.env)
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const config = new EnvironmentParser(process.env)
35
+ * .create((get) => ({
36
+ * port: get('PORT').string().transform(Number).default(3000),
37
+ * database: {
38
+ * url: get('DATABASE_URL').string().url()
39
+ * }
40
+ * }))
41
+ * .parse();
42
+ * ```
43
+ */
44
+ declare class EnvironmentParser<T extends EmptyObject> {
45
+ private readonly config;
46
+ /**
47
+ * Creates a new EnvironmentParser instance.
48
+ *
49
+ * @param config - The configuration object to parse (typically process.env)
50
+ */
51
+ constructor(config: T);
52
+ /**
53
+ * Wraps a Zod schema to intercept parse/safeParse calls and enrich error messages
54
+ * with environment variable context.
55
+ *
56
+ * @param schema - The Zod schema to wrap
57
+ * @param name - The environment variable name for error context
58
+ * @returns A wrapped Zod schema with enhanced error reporting
59
+ */
60
+ private wrapSchema;
61
+ /**
62
+ * Creates a proxied version of the Zod object that wraps all schema creators
63
+ * to provide enhanced error messages with environment variable context.
64
+ *
65
+ * @param name - The environment variable name
66
+ * @returns A proxied Zod object with wrapped schema creators
67
+ */
68
+ private getZodGetter;
69
+ /**
70
+ * Creates a new ConfigParser object that can be used to parse the config object
71
+ *
72
+ * @param builder - A function that takes a getter function and returns a config object
73
+ * @returns A ConfigParser object that can be used to parse the config object
74
+ */
75
+ create<TReturn extends EmptyObject>(builder: (get: EnvFetcher) => TReturn): ConfigParser<TReturn>;
76
+ }
77
+ /**
78
+ * Infers the TypeScript type of a configuration object based on its Zod schemas.
79
+ * Recursively processes nested objects and extracts types from Zod schemas.
80
+ *
81
+ * @template T - The configuration object type
82
+ */
83
+ type InferConfig<T extends EmptyObject> = { [K in keyof T]: T[K] extends z.ZodSchema ? z.infer<T[K]> : T[K] extends Record<string, unknown> ? InferConfig<T[K]> : T[K] };
84
+ /**
85
+ * Function type for fetching environment variables with Zod validation.
86
+ * Returns a Zod object scoped to a specific environment variable.
87
+ *
88
+ * @template TPath - The environment variable path type
89
+ * @param name - The environment variable name
90
+ * @returns A Zod object for defining the schema
91
+ */
92
+ type EnvFetcher<TPath extends string = string> = (name: TPath) => typeof z;
93
+ /**
94
+ * Function type for building environment configuration objects.
95
+ * Takes an EnvFetcher and returns a configuration object with Zod schemas.
96
+ *
97
+ * @template TResponse - The response configuration object type
98
+ * @param get - The environment variable fetcher function
99
+ * @returns The configuration object with Zod schemas
100
+ */
101
+ type EnvironmentBuilder<TResponse extends EmptyObject> = (get: EnvFetcher) => TResponse;
102
+ /**
103
+ * Type alias for a generic object with unknown values.
104
+ * Used as a constraint for configuration objects.
105
+ */
106
+ type EmptyObject = Record<string | number | symbol, unknown>;
107
+ //#endregion
108
+ export { ConfigParser, EmptyObject, EnvFetcher, EnvironmentBuilder, EnvironmentParser, InferConfig };
@@ -7,13 +7,13 @@ const zod_v4 = require_chunk.__toESM(require("zod/v4"));
7
7
  /**
8
8
  * Parses and validates configuration objects against Zod schemas.
9
9
  * Handles nested configurations and aggregates validation errors.
10
- *
10
+ *
11
11
  * @template TResponse - The shape of the configuration object
12
12
  */
13
13
  var ConfigParser = class {
14
14
  /**
15
15
  * Creates a new ConfigParser instance.
16
- *
16
+ *
17
17
  * @param config - The configuration object to parse
18
18
  */
19
19
  constructor(config) {
@@ -51,9 +51,9 @@ var ConfigParser = class {
51
51
  * Parses environment variables with type-safe validation using Zod schemas.
52
52
  * Provides a fluent API for defining environment variable schemas with automatic
53
53
  * error context enrichment.
54
- *
54
+ *
55
55
  * @template T - The type of the configuration object (typically process.env)
56
- *
56
+ *
57
57
  * @example
58
58
  * ```typescript
59
59
  * const config = new EnvironmentParser(process.env)
@@ -69,7 +69,7 @@ var ConfigParser = class {
69
69
  var EnvironmentParser = class {
70
70
  /**
71
71
  * Creates a new EnvironmentParser instance.
72
- *
72
+ *
73
73
  * @param config - The configuration object to parse (typically process.env)
74
74
  */
75
75
  constructor(config) {
@@ -78,7 +78,7 @@ var EnvironmentParser = class {
78
78
  /**
79
79
  * Wraps a Zod schema to intercept parse/safeParse calls and enrich error messages
80
80
  * with environment variable context.
81
- *
81
+ *
82
82
  * @param schema - The Zod schema to wrap
83
83
  * @param name - The environment variable name for error context
84
84
  * @returns A wrapped Zod schema with enhanced error reporting
@@ -129,7 +129,7 @@ var EnvironmentParser = class {
129
129
  /**
130
130
  * Creates a proxied version of the Zod object that wraps all schema creators
131
131
  * to provide enhanced error messages with environment variable context.
132
- *
132
+ *
133
133
  * @param name - The environment variable name
134
134
  * @returns A proxied Zod object with wrapped schema creators
135
135
  */
@@ -6,13 +6,13 @@ import { z } from "zod/v4";
6
6
  /**
7
7
  * Parses and validates configuration objects against Zod schemas.
8
8
  * Handles nested configurations and aggregates validation errors.
9
- *
9
+ *
10
10
  * @template TResponse - The shape of the configuration object
11
11
  */
12
12
  var ConfigParser = class {
13
13
  /**
14
14
  * Creates a new ConfigParser instance.
15
- *
15
+ *
16
16
  * @param config - The configuration object to parse
17
17
  */
18
18
  constructor(config) {
@@ -50,9 +50,9 @@ var ConfigParser = class {
50
50
  * Parses environment variables with type-safe validation using Zod schemas.
51
51
  * Provides a fluent API for defining environment variable schemas with automatic
52
52
  * error context enrichment.
53
- *
53
+ *
54
54
  * @template T - The type of the configuration object (typically process.env)
55
- *
55
+ *
56
56
  * @example
57
57
  * ```typescript
58
58
  * const config = new EnvironmentParser(process.env)
@@ -68,7 +68,7 @@ var ConfigParser = class {
68
68
  var EnvironmentParser = class {
69
69
  /**
70
70
  * Creates a new EnvironmentParser instance.
71
- *
71
+ *
72
72
  * @param config - The configuration object to parse (typically process.env)
73
73
  */
74
74
  constructor(config) {
@@ -77,7 +77,7 @@ var EnvironmentParser = class {
77
77
  /**
78
78
  * Wraps a Zod schema to intercept parse/safeParse calls and enrich error messages
79
79
  * with environment variable context.
80
- *
80
+ *
81
81
  * @param schema - The Zod schema to wrap
82
82
  * @param name - The environment variable name for error context
83
83
  * @returns A wrapped Zod schema with enhanced error reporting
@@ -128,7 +128,7 @@ var EnvironmentParser = class {
128
128
  /**
129
129
  * Creates a proxied version of the Zod object that wraps all schema creators
130
130
  * to provide enhanced error messages with environment variable context.
131
- *
131
+ *
132
132
  * @param name - The environment variable name
133
133
  * @returns A proxied Zod object with wrapped schema creators
134
134
  */
@@ -0,0 +1,108 @@
1
+ import { z } from "zod/v4";
2
+
3
+ //#region src/EnvironmentParser.d.ts
4
+
5
+ /**
6
+ * Parses and validates configuration objects against Zod schemas.
7
+ * Handles nested configurations and aggregates validation errors.
8
+ *
9
+ * @template TResponse - The shape of the configuration object
10
+ */
11
+ declare class ConfigParser<TResponse extends EmptyObject> {
12
+ private readonly config;
13
+ /**
14
+ * Creates a new ConfigParser instance.
15
+ *
16
+ * @param config - The configuration object to parse
17
+ */
18
+ constructor(config: TResponse);
19
+ /**
20
+ * Parses the config object and validates it against the Zod schemas
21
+ * @returns The parsed config object
22
+ */
23
+ parse(): InferConfig<TResponse>;
24
+ }
25
+ /**
26
+ * Parses environment variables with type-safe validation using Zod schemas.
27
+ * Provides a fluent API for defining environment variable schemas with automatic
28
+ * error context enrichment.
29
+ *
30
+ * @template T - The type of the configuration object (typically process.env)
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const config = new EnvironmentParser(process.env)
35
+ * .create((get) => ({
36
+ * port: get('PORT').string().transform(Number).default(3000),
37
+ * database: {
38
+ * url: get('DATABASE_URL').string().url()
39
+ * }
40
+ * }))
41
+ * .parse();
42
+ * ```
43
+ */
44
+ declare class EnvironmentParser<T extends EmptyObject> {
45
+ private readonly config;
46
+ /**
47
+ * Creates a new EnvironmentParser instance.
48
+ *
49
+ * @param config - The configuration object to parse (typically process.env)
50
+ */
51
+ constructor(config: T);
52
+ /**
53
+ * Wraps a Zod schema to intercept parse/safeParse calls and enrich error messages
54
+ * with environment variable context.
55
+ *
56
+ * @param schema - The Zod schema to wrap
57
+ * @param name - The environment variable name for error context
58
+ * @returns A wrapped Zod schema with enhanced error reporting
59
+ */
60
+ private wrapSchema;
61
+ /**
62
+ * Creates a proxied version of the Zod object that wraps all schema creators
63
+ * to provide enhanced error messages with environment variable context.
64
+ *
65
+ * @param name - The environment variable name
66
+ * @returns A proxied Zod object with wrapped schema creators
67
+ */
68
+ private getZodGetter;
69
+ /**
70
+ * Creates a new ConfigParser object that can be used to parse the config object
71
+ *
72
+ * @param builder - A function that takes a getter function and returns a config object
73
+ * @returns A ConfigParser object that can be used to parse the config object
74
+ */
75
+ create<TReturn extends EmptyObject>(builder: (get: EnvFetcher) => TReturn): ConfigParser<TReturn>;
76
+ }
77
+ /**
78
+ * Infers the TypeScript type of a configuration object based on its Zod schemas.
79
+ * Recursively processes nested objects and extracts types from Zod schemas.
80
+ *
81
+ * @template T - The configuration object type
82
+ */
83
+ type InferConfig<T extends EmptyObject> = { [K in keyof T]: T[K] extends z.ZodSchema ? z.infer<T[K]> : T[K] extends Record<string, unknown> ? InferConfig<T[K]> : T[K] };
84
+ /**
85
+ * Function type for fetching environment variables with Zod validation.
86
+ * Returns a Zod object scoped to a specific environment variable.
87
+ *
88
+ * @template TPath - The environment variable path type
89
+ * @param name - The environment variable name
90
+ * @returns A Zod object for defining the schema
91
+ */
92
+ type EnvFetcher<TPath extends string = string> = (name: TPath) => typeof z;
93
+ /**
94
+ * Function type for building environment configuration objects.
95
+ * Takes an EnvFetcher and returns a configuration object with Zod schemas.
96
+ *
97
+ * @template TResponse - The response configuration object type
98
+ * @param get - The environment variable fetcher function
99
+ * @returns The configuration object with Zod schemas
100
+ */
101
+ type EnvironmentBuilder<TResponse extends EmptyObject> = (get: EnvFetcher) => TResponse;
102
+ /**
103
+ * Type alias for a generic object with unknown values.
104
+ * Used as a constraint for configuration objects.
105
+ */
106
+ type EmptyObject = Record<string | number | symbol, unknown>;
107
+ //#endregion
108
+ export { ConfigParser, EmptyObject, EnvFetcher, EnvironmentBuilder, EnvironmentParser, InferConfig };
@@ -1,4 +1,4 @@
1
- const require_EnvironmentParser = require('./EnvironmentParser-Bo2CCl_K.cjs');
1
+ const require_EnvironmentParser = require('./EnvironmentParser-BDPDLv6i.cjs');
2
2
 
3
3
  exports.ConfigParser = require_EnvironmentParser.ConfigParser;
4
4
  exports.EnvironmentParser = require_EnvironmentParser.EnvironmentParser;
@@ -0,0 +1,2 @@
1
+ import { ConfigParser, EmptyObject, EnvFetcher, EnvironmentBuilder, EnvironmentParser, InferConfig } from "./EnvironmentParser-X4h2Vp4r.cjs";
2
+ export { ConfigParser, EmptyObject, EnvFetcher, EnvironmentBuilder, EnvironmentParser, InferConfig };
@@ -0,0 +1,2 @@
1
+ import { ConfigParser, EmptyObject, EnvFetcher, EnvironmentBuilder, EnvironmentParser, InferConfig } from "./EnvironmentParser-BD6NmvPR.mjs";
2
+ export { ConfigParser, EmptyObject, EnvFetcher, EnvironmentBuilder, EnvironmentParser, InferConfig };
@@ -1,3 +1,3 @@
1
- import { ConfigParser, EnvironmentParser } from "./EnvironmentParser-jKrGMBhP.mjs";
1
+ import { ConfigParser, EnvironmentParser } from "./EnvironmentParser-CQUOGqc0.mjs";
2
2
 
3
3
  export { ConfigParser, EnvironmentParser };
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require('../chunk-CUT6urMc.cjs');
2
- const require_EnvironmentParser = require('../EnvironmentParser-Bo2CCl_K.cjs');
2
+ const require_EnvironmentParser = require('../EnvironmentParser-BDPDLv6i.cjs');
3
3
  const zod_v4 = require_chunk.__toESM(require("zod/v4"));
4
4
  const vitest = require_chunk.__toESM(require("vitest"));
5
5
 
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -1,4 +1,4 @@
1
- import { ConfigParser } from "../EnvironmentParser-jKrGMBhP.mjs";
1
+ import { ConfigParser } from "../EnvironmentParser-CQUOGqc0.mjs";
2
2
  import { z } from "zod/v4";
3
3
  import { describe, expect, it } from "vitest";
4
4
 
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require('../chunk-CUT6urMc.cjs');
2
- const require_EnvironmentParser = require('../EnvironmentParser-Bo2CCl_K.cjs');
2
+ const require_EnvironmentParser = require('../EnvironmentParser-BDPDLv6i.cjs');
3
3
  const zod_v4 = require_chunk.__toESM(require("zod/v4"));
4
4
  const vitest = require_chunk.__toESM(require("vitest"));
5
5
 
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -1,4 +1,4 @@
1
- import { EnvironmentParser } from "../EnvironmentParser-jKrGMBhP.mjs";
1
+ import { EnvironmentParser } from "../EnvironmentParser-CQUOGqc0.mjs";
2
2
  import { z } from "zod/v4";
3
3
  import { describe, expect, it } from "vitest";
4
4
 
package/dist/index.cjs CHANGED
@@ -1,3 +1,3 @@
1
- const require_EnvironmentParser = require('./EnvironmentParser-Bo2CCl_K.cjs');
1
+ const require_EnvironmentParser = require('./EnvironmentParser-BDPDLv6i.cjs');
2
2
 
3
3
  exports.EnvironmentParser = require_EnvironmentParser.EnvironmentParser;
@@ -0,0 +1,2 @@
1
+ import { EnvironmentParser } from "./EnvironmentParser-X4h2Vp4r.cjs";
2
+ export { EnvironmentParser };
@@ -0,0 +1,2 @@
1
+ import { EnvironmentParser } from "./EnvironmentParser-BD6NmvPR.mjs";
2
+ export { EnvironmentParser };
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { EnvironmentParser } from "./EnvironmentParser-jKrGMBhP.mjs";
1
+ import { EnvironmentParser } from "./EnvironmentParser-CQUOGqc0.mjs";
2
2
 
3
3
  export { EnvironmentParser };
package/dist/sst.cjs CHANGED
@@ -5,10 +5,10 @@ const lodash_snakecase = require_chunk.__toESM(require("lodash.snakecase"));
5
5
  /**
6
6
  * Converts a string to environment variable case format (UPPER_SNAKE_CASE).
7
7
  * Numbers following underscores are preserved without the underscore.
8
- *
8
+ *
9
9
  * @param name - The string to convert
10
10
  * @returns The converted string in environment variable format
11
- *
11
+ *
12
12
  * @example
13
13
  * environmentCase('myVariable') // 'MY_VARIABLE'
14
14
  * environmentCase('api_v2') // 'APIV2'
@@ -38,7 +38,7 @@ let ResourceType = /* @__PURE__ */ function(ResourceType$1) {
38
38
  }({});
39
39
  /**
40
40
  * Processes a Secret resource into environment variables.
41
- *
41
+ *
42
42
  * @param name - The resource name
43
43
  * @param value - The Secret resource
44
44
  * @returns Object with environment variable mappings
@@ -47,7 +47,7 @@ const secret = (name, value) => ({ [environmentCase(name)]: value.value });
47
47
  /**
48
48
  * Processes a Postgres database resource into environment variables.
49
49
  * Creates multiple environment variables for database connection details.
50
- *
50
+ *
51
51
  * @param key - The resource key
52
52
  * @param value - The Postgres resource
53
53
  * @returns Object with database connection environment variables
@@ -64,7 +64,7 @@ const postgres = (key, value) => {
64
64
  };
65
65
  /**
66
66
  * Processes a Bucket resource into environment variables.
67
- *
67
+ *
68
68
  * @param name - The resource name
69
69
  * @param value - The Bucket resource
70
70
  * @returns Object with bucket name environment variable
@@ -75,7 +75,7 @@ const bucket = (name, value) => {
75
75
  };
76
76
  /**
77
77
  * No-operation processor for resources that don't require environment variables.
78
- *
78
+ *
79
79
  * @param name - The resource name (unused)
80
80
  * @param value - The resource value (unused)
81
81
  * @returns Empty object
@@ -101,10 +101,10 @@ const processors = {
101
101
  /**
102
102
  * Normalizes SST resources and plain strings into environment variables.
103
103
  * Processes resources based on their type and converts names to environment case.
104
- *
104
+ *
105
105
  * @param record - Object containing resources and/or string values
106
106
  * @returns Normalized environment variables object
107
- *
107
+ *
108
108
  * @example
109
109
  * normalizeResourceEnv({
110
110
  * apiUrl: 'https://api.example.com',
package/dist/sst.d.cts ADDED
@@ -0,0 +1,107 @@
1
+ //#region src/sst.d.ts
2
+ /**
3
+ * Converts a string to environment variable case format (UPPER_SNAKE_CASE).
4
+ * Numbers following underscores are preserved without the underscore.
5
+ *
6
+ * @param name - The string to convert
7
+ * @returns The converted string in environment variable format
8
+ *
9
+ * @example
10
+ * environmentCase('myVariable') // 'MY_VARIABLE'
11
+ * environmentCase('api_v2') // 'APIV2'
12
+ */
13
+ declare function environmentCase(name: string): string;
14
+ /**
15
+ * Enumeration of supported SST (Serverless Stack Toolkit) resource types.
16
+ * Used to identify and process different AWS and SST resources.
17
+ */
18
+ declare enum ResourceType {
19
+ ApiGatewayV2 = "sst.aws.ApiGatewayV2",
20
+ Postgres = "sst.aws.Postgres",
21
+ Function = "sst.aws.Function",
22
+ Bucket = "sst.aws.Bucket",
23
+ Vpc = "sst.aws.Vpc",
24
+ Secret = "sst.sst.Secret",
25
+ SSTSecret = "sst:sst:Secret",
26
+ SSTFunction = "sst:sst:Function",
27
+ SSTApiGatewayV2 = "sst:aws:ApiGatewayV2",
28
+ SSTPostgres = "sst:aws:Postgres",
29
+ SSTBucket = "sst:aws:Bucket",
30
+ }
31
+ /**
32
+ * Normalizes SST resources and plain strings into environment variables.
33
+ * Processes resources based on their type and converts names to environment case.
34
+ *
35
+ * @param record - Object containing resources and/or string values
36
+ * @returns Normalized environment variables object
37
+ *
38
+ * @example
39
+ * normalizeResourceEnv({
40
+ * apiUrl: 'https://api.example.com',
41
+ * database: { type: ResourceType.Postgres, ... }
42
+ * })
43
+ */
44
+ declare function normalizeResourceEnv(record: Record<string, Resource | string>): Record<string, string>;
45
+ /**
46
+ * AWS API Gateway V2 resource type.
47
+ * Represents an HTTP/WebSocket API.
48
+ */
49
+ type ApiGatewayV2 = {
50
+ type: ResourceType.ApiGatewayV2;
51
+ url: string;
52
+ };
53
+ /**
54
+ * PostgreSQL database resource type.
55
+ * Contains all connection details needed to connect to the database.
56
+ */
57
+ type Postgres = {
58
+ database: string;
59
+ host: string;
60
+ password: string;
61
+ port: number;
62
+ type: ResourceType.Postgres;
63
+ username: string;
64
+ };
65
+ /**
66
+ * AWS Lambda Function resource type.
67
+ */
68
+ type Function = {
69
+ name: string;
70
+ type: ResourceType.Function;
71
+ };
72
+ /**
73
+ * AWS S3 Bucket resource type.
74
+ */
75
+ type Bucket = {
76
+ name: string;
77
+ type: ResourceType.Bucket;
78
+ };
79
+ /**
80
+ * AWS VPC (Virtual Private Cloud) resource type.
81
+ */
82
+ type Vpc = {
83
+ bastion: string;
84
+ type: ResourceType.Vpc;
85
+ };
86
+ /**
87
+ * Secret resource type for storing sensitive values.
88
+ */
89
+ type Secret = {
90
+ type: ResourceType.Secret;
91
+ value: string;
92
+ };
93
+ /**
94
+ * Union type of all supported SST resource types.
95
+ */
96
+ type Resource = ApiGatewayV2 | Postgres | Function | Bucket | Vpc | Secret;
97
+ /**
98
+ * Function type for processing a specific resource type into environment variables.
99
+ *
100
+ * @template K - The specific resource type
101
+ * @param name - The resource name
102
+ * @param value - The resource value
103
+ * @returns Object mapping environment variable names to values
104
+ */
105
+ type ResourceProcessor<K extends Resource> = (name: string, value: K) => Record<string, string | number>;
106
+ //#endregion
107
+ export { ApiGatewayV2, Bucket, Function, Postgres, Resource, ResourceProcessor, ResourceType, Secret, Vpc, environmentCase, normalizeResourceEnv };
package/dist/sst.d.mts ADDED
@@ -0,0 +1,107 @@
1
+ //#region src/sst.d.ts
2
+ /**
3
+ * Converts a string to environment variable case format (UPPER_SNAKE_CASE).
4
+ * Numbers following underscores are preserved without the underscore.
5
+ *
6
+ * @param name - The string to convert
7
+ * @returns The converted string in environment variable format
8
+ *
9
+ * @example
10
+ * environmentCase('myVariable') // 'MY_VARIABLE'
11
+ * environmentCase('api_v2') // 'APIV2'
12
+ */
13
+ declare function environmentCase(name: string): string;
14
+ /**
15
+ * Enumeration of supported SST (Serverless Stack Toolkit) resource types.
16
+ * Used to identify and process different AWS and SST resources.
17
+ */
18
+ declare enum ResourceType {
19
+ ApiGatewayV2 = "sst.aws.ApiGatewayV2",
20
+ Postgres = "sst.aws.Postgres",
21
+ Function = "sst.aws.Function",
22
+ Bucket = "sst.aws.Bucket",
23
+ Vpc = "sst.aws.Vpc",
24
+ Secret = "sst.sst.Secret",
25
+ SSTSecret = "sst:sst:Secret",
26
+ SSTFunction = "sst:sst:Function",
27
+ SSTApiGatewayV2 = "sst:aws:ApiGatewayV2",
28
+ SSTPostgres = "sst:aws:Postgres",
29
+ SSTBucket = "sst:aws:Bucket",
30
+ }
31
+ /**
32
+ * Normalizes SST resources and plain strings into environment variables.
33
+ * Processes resources based on their type and converts names to environment case.
34
+ *
35
+ * @param record - Object containing resources and/or string values
36
+ * @returns Normalized environment variables object
37
+ *
38
+ * @example
39
+ * normalizeResourceEnv({
40
+ * apiUrl: 'https://api.example.com',
41
+ * database: { type: ResourceType.Postgres, ... }
42
+ * })
43
+ */
44
+ declare function normalizeResourceEnv(record: Record<string, Resource | string>): Record<string, string>;
45
+ /**
46
+ * AWS API Gateway V2 resource type.
47
+ * Represents an HTTP/WebSocket API.
48
+ */
49
+ type ApiGatewayV2 = {
50
+ type: ResourceType.ApiGatewayV2;
51
+ url: string;
52
+ };
53
+ /**
54
+ * PostgreSQL database resource type.
55
+ * Contains all connection details needed to connect to the database.
56
+ */
57
+ type Postgres = {
58
+ database: string;
59
+ host: string;
60
+ password: string;
61
+ port: number;
62
+ type: ResourceType.Postgres;
63
+ username: string;
64
+ };
65
+ /**
66
+ * AWS Lambda Function resource type.
67
+ */
68
+ type Function = {
69
+ name: string;
70
+ type: ResourceType.Function;
71
+ };
72
+ /**
73
+ * AWS S3 Bucket resource type.
74
+ */
75
+ type Bucket = {
76
+ name: string;
77
+ type: ResourceType.Bucket;
78
+ };
79
+ /**
80
+ * AWS VPC (Virtual Private Cloud) resource type.
81
+ */
82
+ type Vpc = {
83
+ bastion: string;
84
+ type: ResourceType.Vpc;
85
+ };
86
+ /**
87
+ * Secret resource type for storing sensitive values.
88
+ */
89
+ type Secret = {
90
+ type: ResourceType.Secret;
91
+ value: string;
92
+ };
93
+ /**
94
+ * Union type of all supported SST resource types.
95
+ */
96
+ type Resource = ApiGatewayV2 | Postgres | Function | Bucket | Vpc | Secret;
97
+ /**
98
+ * Function type for processing a specific resource type into environment variables.
99
+ *
100
+ * @template K - The specific resource type
101
+ * @param name - The resource name
102
+ * @param value - The resource value
103
+ * @returns Object mapping environment variable names to values
104
+ */
105
+ type ResourceProcessor<K extends Resource> = (name: string, value: K) => Record<string, string | number>;
106
+ //#endregion
107
+ export { ApiGatewayV2, Bucket, Function, Postgres, Resource, ResourceProcessor, ResourceType, Secret, Vpc, environmentCase, normalizeResourceEnv };
package/dist/sst.mjs CHANGED
@@ -4,10 +4,10 @@ import snakecase from "lodash.snakecase";
4
4
  /**
5
5
  * Converts a string to environment variable case format (UPPER_SNAKE_CASE).
6
6
  * Numbers following underscores are preserved without the underscore.
7
- *
7
+ *
8
8
  * @param name - The string to convert
9
9
  * @returns The converted string in environment variable format
10
- *
10
+ *
11
11
  * @example
12
12
  * environmentCase('myVariable') // 'MY_VARIABLE'
13
13
  * environmentCase('api_v2') // 'APIV2'
@@ -37,7 +37,7 @@ let ResourceType = /* @__PURE__ */ function(ResourceType$1) {
37
37
  }({});
38
38
  /**
39
39
  * Processes a Secret resource into environment variables.
40
- *
40
+ *
41
41
  * @param name - The resource name
42
42
  * @param value - The Secret resource
43
43
  * @returns Object with environment variable mappings
@@ -46,7 +46,7 @@ const secret = (name, value) => ({ [environmentCase(name)]: value.value });
46
46
  /**
47
47
  * Processes a Postgres database resource into environment variables.
48
48
  * Creates multiple environment variables for database connection details.
49
- *
49
+ *
50
50
  * @param key - The resource key
51
51
  * @param value - The Postgres resource
52
52
  * @returns Object with database connection environment variables
@@ -63,7 +63,7 @@ const postgres = (key, value) => {
63
63
  };
64
64
  /**
65
65
  * Processes a Bucket resource into environment variables.
66
- *
66
+ *
67
67
  * @param name - The resource name
68
68
  * @param value - The Bucket resource
69
69
  * @returns Object with bucket name environment variable
@@ -74,7 +74,7 @@ const bucket = (name, value) => {
74
74
  };
75
75
  /**
76
76
  * No-operation processor for resources that don't require environment variables.
77
- *
77
+ *
78
78
  * @param name - The resource name (unused)
79
79
  * @param value - The resource value (unused)
80
80
  * @returns Empty object
@@ -100,10 +100,10 @@ const processors = {
100
100
  /**
101
101
  * Normalizes SST resources and plain strings into environment variables.
102
102
  * Processes resources based on their type and converts names to environment case.
103
- *
103
+ *
104
104
  * @param record - Object containing resources and/or string values
105
105
  * @returns Normalized environment variables object
106
- *
106
+ *
107
107
  * @example
108
108
  * normalizeResourceEnv({
109
109
  * apiUrl: 'https://api.example.com',
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@geekmidas/envkit",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
8
+ "types": "./dist/index.d.ts",
8
9
  "import": "./dist/index.mjs",
9
- "require": "./dist/index.cjs",
10
- "types": "./src/index.ts"
10
+ "require": "./dist/index.cjs"
11
11
  },
12
12
  "./sst": {
13
+ "types": "./dist/sst.d.ts",
13
14
  "import": "./dist/sst.mjs",
14
- "require": "./dist/sst.cjs",
15
- "types": "./src/sst.ts"
15
+ "require": "./dist/sst.cjs"
16
16
  }
17
17
  },
18
18
  "publishConfig": {
@@ -5,13 +5,13 @@ import { z } from 'zod/v4';
5
5
  /**
6
6
  * Parses and validates configuration objects against Zod schemas.
7
7
  * Handles nested configurations and aggregates validation errors.
8
- *
8
+ *
9
9
  * @template TResponse - The shape of the configuration object
10
10
  */
11
11
  export class ConfigParser<TResponse extends EmptyObject> {
12
12
  /**
13
13
  * Creates a new ConfigParser instance.
14
- *
14
+ *
15
15
  * @param config - The configuration object to parse
16
16
  */
17
17
  constructor(private readonly config: TResponse) {}
@@ -71,9 +71,9 @@ export class ConfigParser<TResponse extends EmptyObject> {
71
71
  * Parses environment variables with type-safe validation using Zod schemas.
72
72
  * Provides a fluent API for defining environment variable schemas with automatic
73
73
  * error context enrichment.
74
- *
74
+ *
75
75
  * @template T - The type of the configuration object (typically process.env)
76
- *
76
+ *
77
77
  * @example
78
78
  * ```typescript
79
79
  * const config = new EnvironmentParser(process.env)
@@ -89,7 +89,7 @@ export class ConfigParser<TResponse extends EmptyObject> {
89
89
  export class EnvironmentParser<T extends EmptyObject> {
90
90
  /**
91
91
  * Creates a new EnvironmentParser instance.
92
- *
92
+ *
93
93
  * @param config - The configuration object to parse (typically process.env)
94
94
  */
95
95
  constructor(private readonly config: T) {}
@@ -97,7 +97,7 @@ export class EnvironmentParser<T extends EmptyObject> {
97
97
  /**
98
98
  * Wraps a Zod schema to intercept parse/safeParse calls and enrich error messages
99
99
  * with environment variable context.
100
- *
100
+ *
101
101
  * @param schema - The Zod schema to wrap
102
102
  * @param name - The environment variable name for error context
103
103
  * @returns A wrapped Zod schema with enhanced error reporting
@@ -172,7 +172,7 @@ export class EnvironmentParser<T extends EmptyObject> {
172
172
  /**
173
173
  * Creates a proxied version of the Zod object that wraps all schema creators
174
174
  * to provide enhanced error messages with environment variable context.
175
- *
175
+ *
176
176
  * @param name - The environment variable name
177
177
  * @returns A proxied Zod object with wrapped schema creators
178
178
  */
@@ -234,7 +234,7 @@ export class EnvironmentParser<T extends EmptyObject> {
234
234
  /**
235
235
  * Infers the TypeScript type of a configuration object based on its Zod schemas.
236
236
  * Recursively processes nested objects and extracts types from Zod schemas.
237
- *
237
+ *
238
238
  * @template T - The configuration object type
239
239
  */
240
240
  export type InferConfig<T extends EmptyObject> = {
@@ -248,7 +248,7 @@ export type InferConfig<T extends EmptyObject> = {
248
248
  /**
249
249
  * Function type for fetching environment variables with Zod validation.
250
250
  * Returns a Zod object scoped to a specific environment variable.
251
- *
251
+ *
252
252
  * @template TPath - The environment variable path type
253
253
  * @param name - The environment variable name
254
254
  * @returns A Zod object for defining the schema
@@ -260,7 +260,7 @@ export type EnvFetcher<TPath extends string = string> = (
260
260
  /**
261
261
  * Function type for building environment configuration objects.
262
262
  * Takes an EnvFetcher and returns a configuration object with Zod schemas.
263
- *
263
+ *
264
264
  * @template TResponse - The response configuration object type
265
265
  * @param get - The environment variable fetcher function
266
266
  * @returns The configuration object with Zod schemas
package/src/sst.ts CHANGED
@@ -3,10 +3,10 @@ import snakecase from 'lodash.snakecase';
3
3
  /**
4
4
  * Converts a string to environment variable case format (UPPER_SNAKE_CASE).
5
5
  * Numbers following underscores are preserved without the underscore.
6
- *
6
+ *
7
7
  * @param name - The string to convert
8
8
  * @returns The converted string in environment variable format
9
- *
9
+ *
10
10
  * @example
11
11
  * environmentCase('myVariable') // 'MY_VARIABLE'
12
12
  * environmentCase('api_v2') // 'APIV2'
@@ -39,7 +39,7 @@ export enum ResourceType {
39
39
 
40
40
  /**
41
41
  * Processes a Secret resource into environment variables.
42
- *
42
+ *
43
43
  * @param name - The resource name
44
44
  * @param value - The Secret resource
45
45
  * @returns Object with environment variable mappings
@@ -50,7 +50,7 @@ const secret = (name: string, value: Secret) => ({
50
50
  /**
51
51
  * Processes a Postgres database resource into environment variables.
52
52
  * Creates multiple environment variables for database connection details.
53
- *
53
+ *
54
54
  * @param key - The resource key
55
55
  * @param value - The Postgres resource
56
56
  * @returns Object with database connection environment variables
@@ -68,7 +68,7 @@ const postgres = (key: string, value: Postgres) => {
68
68
 
69
69
  /**
70
70
  * Processes a Bucket resource into environment variables.
71
- *
71
+ *
72
72
  * @param name - The resource name
73
73
  * @param value - The Bucket resource
74
74
  * @returns Object with bucket name environment variable
@@ -82,7 +82,7 @@ const bucket = (name: string, value: Bucket) => {
82
82
 
83
83
  /**
84
84
  * No-operation processor for resources that don't require environment variables.
85
- *
85
+ *
86
86
  * @param name - The resource name (unused)
87
87
  * @param value - The resource value (unused)
88
88
  * @returns Empty object
@@ -111,10 +111,10 @@ const processors: Record<ResourceType, ResourceProcessor<any>> = {
111
111
  /**
112
112
  * Normalizes SST resources and plain strings into environment variables.
113
113
  * Processes resources based on their type and converts names to environment case.
114
- *
114
+ *
115
115
  * @param record - Object containing resources and/or string values
116
116
  * @returns Normalized environment variables object
117
- *
117
+ *
118
118
  * @example
119
119
  * normalizeResourceEnv({
120
120
  * apiUrl: 'https://api.example.com',
@@ -209,7 +209,7 @@ export type Resource =
209
209
 
210
210
  /**
211
211
  * Function type for processing a specific resource type into environment variables.
212
- *
212
+ *
213
213
  * @template K - The specific resource type
214
214
  * @param name - The resource name
215
215
  * @param value - The resource value