@geekmidas/envkit 0.0.8 → 0.1.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.
Files changed (57) hide show
  1. package/README.md +228 -174
  2. package/dist/EnvironmentBuilder-DHfDXJUm.d.mts +131 -0
  3. package/dist/EnvironmentBuilder-DfmYRBm-.mjs +83 -0
  4. package/dist/EnvironmentBuilder-DfmYRBm-.mjs.map +1 -0
  5. package/dist/EnvironmentBuilder-W2wku49g.cjs +95 -0
  6. package/dist/EnvironmentBuilder-W2wku49g.cjs.map +1 -0
  7. package/dist/EnvironmentBuilder-Xuf2Dd9u.d.cts +131 -0
  8. package/dist/EnvironmentBuilder.cjs +4 -0
  9. package/dist/EnvironmentBuilder.d.cts +2 -0
  10. package/dist/EnvironmentBuilder.d.mts +2 -0
  11. package/dist/EnvironmentBuilder.mjs +3 -0
  12. package/dist/{EnvironmentParser-cnxuy7lw.cjs → EnvironmentParser-Bt246UeP.cjs} +1 -1
  13. package/dist/{EnvironmentParser-cnxuy7lw.cjs.map → EnvironmentParser-Bt246UeP.cjs.map} +1 -1
  14. package/dist/{EnvironmentParser-B8--woiB.d.cts → EnvironmentParser-CVWU1ooT.d.mts} +1 -1
  15. package/dist/{EnvironmentParser-STvN_RCc.mjs → EnvironmentParser-c06agx31.mjs} +1 -1
  16. package/dist/{EnvironmentParser-STvN_RCc.mjs.map → EnvironmentParser-c06agx31.mjs.map} +1 -1
  17. package/dist/{EnvironmentParser-C_9v2BDw.d.mts → EnvironmentParser-tV-JjCg7.d.cts} +1 -1
  18. package/dist/EnvironmentParser.cjs +1 -1
  19. package/dist/EnvironmentParser.d.cts +1 -1
  20. package/dist/EnvironmentParser.d.mts +1 -1
  21. package/dist/EnvironmentParser.mjs +1 -1
  22. package/dist/SnifferEnvironmentParser.cjs +1 -1
  23. package/dist/SnifferEnvironmentParser.cjs.map +1 -1
  24. package/dist/SnifferEnvironmentParser.d.cts +1 -1
  25. package/dist/SnifferEnvironmentParser.d.mts +1 -1
  26. package/dist/SnifferEnvironmentParser.mjs +1 -1
  27. package/dist/SnifferEnvironmentParser.mjs.map +1 -1
  28. package/dist/SstEnvironmentBuilder-BuFw1hCe.cjs +125 -0
  29. package/dist/SstEnvironmentBuilder-BuFw1hCe.cjs.map +1 -0
  30. package/dist/SstEnvironmentBuilder-CjURMGjW.d.mts +177 -0
  31. package/dist/SstEnvironmentBuilder-D4oSo_KX.d.cts +177 -0
  32. package/dist/SstEnvironmentBuilder-DEa3lTUB.mjs +108 -0
  33. package/dist/SstEnvironmentBuilder-DEa3lTUB.mjs.map +1 -0
  34. package/dist/SstEnvironmentBuilder.cjs +7 -0
  35. package/dist/SstEnvironmentBuilder.d.cts +3 -0
  36. package/dist/SstEnvironmentBuilder.d.mts +3 -0
  37. package/dist/SstEnvironmentBuilder.mjs +4 -0
  38. package/dist/index.cjs +5 -2
  39. package/dist/index.d.cts +3 -2
  40. package/dist/index.d.mts +3 -2
  41. package/dist/index.mjs +3 -2
  42. package/dist/sst.cjs +13 -114
  43. package/dist/sst.cjs.map +1 -1
  44. package/dist/sst.d.cts +14 -93
  45. package/dist/sst.d.mts +14 -93
  46. package/dist/sst.mjs +10 -112
  47. package/dist/sst.mjs.map +1 -1
  48. package/docs/async-secrets-design.md +355 -0
  49. package/package.json +6 -2
  50. package/src/EnvironmentBuilder.ts +196 -0
  51. package/src/SnifferEnvironmentParser.ts +7 -5
  52. package/src/SstEnvironmentBuilder.ts +298 -0
  53. package/src/__tests__/EnvironmentBuilder.spec.ts +274 -0
  54. package/src/__tests__/SstEnvironmentBuilder.spec.ts +373 -0
  55. package/src/__tests__/sst.spec.ts +1 -1
  56. package/src/index.ts +12 -0
  57. package/src/sst.ts +45 -207
@@ -0,0 +1,373 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+
3
+ import {
4
+ type Bucket,
5
+ type Postgres,
6
+ ResourceType,
7
+ type Secret,
8
+ type SnsTopic,
9
+ SstEnvironmentBuilder,
10
+ sstResolvers,
11
+ } from '../SstEnvironmentBuilder';
12
+
13
+ describe('SstEnvironmentBuilder', () => {
14
+ describe('basic functionality', () => {
15
+ it('should pass through plain string values with key transformation', () => {
16
+ const env = new SstEnvironmentBuilder({
17
+ appName: 'my-app',
18
+ nodeEnv: 'production',
19
+ }).build();
20
+
21
+ expect(env).toEqual({
22
+ APP_NAME: 'my-app',
23
+ NODE_ENV: 'production',
24
+ });
25
+ });
26
+
27
+ it('should handle empty input', () => {
28
+ const env = new SstEnvironmentBuilder({}).build();
29
+ expect(env).toEqual({});
30
+ });
31
+ });
32
+
33
+ describe('Secret resource', () => {
34
+ it('should process Secret resource correctly', () => {
35
+ const secret: Secret = {
36
+ type: ResourceType.Secret,
37
+ value: 'super-secret-value',
38
+ };
39
+
40
+ const env = new SstEnvironmentBuilder({
41
+ mySecret: secret,
42
+ }).build();
43
+
44
+ expect(env).toEqual({
45
+ MY_SECRET: 'super-secret-value',
46
+ });
47
+ });
48
+
49
+ it('should process SSTSecret resource correctly', () => {
50
+ const secret: Secret = {
51
+ type: ResourceType.SSTSecret,
52
+ value: 'another-secret',
53
+ };
54
+
55
+ const env = new SstEnvironmentBuilder({
56
+ appSecret: secret,
57
+ }).build();
58
+
59
+ expect(env).toEqual({
60
+ APP_SECRET: 'another-secret',
61
+ });
62
+ });
63
+ });
64
+
65
+ describe('Postgres resource', () => {
66
+ it('should process Postgres resource correctly', () => {
67
+ const postgres: Postgres = {
68
+ type: ResourceType.Postgres,
69
+ database: 'myapp',
70
+ host: 'localhost',
71
+ password: 'password123',
72
+ port: 5432,
73
+ username: 'postgres',
74
+ };
75
+
76
+ const env = new SstEnvironmentBuilder({
77
+ database: postgres,
78
+ }).build();
79
+
80
+ expect(env).toEqual({
81
+ DATABASE_NAME: 'myapp',
82
+ DATABASE_HOST: 'localhost',
83
+ DATABASE_PASSWORD: 'password123',
84
+ DATABASE_PORT: 5432,
85
+ DATABASE_USERNAME: 'postgres',
86
+ });
87
+ });
88
+
89
+ it('should process SSTPostgres resource correctly', () => {
90
+ const postgres: Postgres = {
91
+ type: ResourceType.SSTPostgres,
92
+ database: 'prod_db',
93
+ host: 'prod.example.com',
94
+ password: 'prod-password',
95
+ port: 5433,
96
+ username: 'prod_user',
97
+ };
98
+
99
+ const env = new SstEnvironmentBuilder({
100
+ mainDb: postgres,
101
+ }).build();
102
+
103
+ expect(env).toEqual({
104
+ MAIN_DB_NAME: 'prod_db',
105
+ MAIN_DB_HOST: 'prod.example.com',
106
+ MAIN_DB_PASSWORD: 'prod-password',
107
+ MAIN_DB_PORT: 5433,
108
+ MAIN_DB_USERNAME: 'prod_user',
109
+ });
110
+ });
111
+ });
112
+
113
+ describe('Bucket resource', () => {
114
+ it('should process Bucket resource correctly', () => {
115
+ const bucket: Bucket = {
116
+ type: ResourceType.Bucket,
117
+ name: 'my-s3-bucket',
118
+ };
119
+
120
+ const env = new SstEnvironmentBuilder({
121
+ uploadBucket: bucket,
122
+ }).build();
123
+
124
+ expect(env).toEqual({
125
+ UPLOAD_BUCKET_NAME: 'my-s3-bucket',
126
+ });
127
+ });
128
+
129
+ it('should process SSTBucket resource correctly', () => {
130
+ const bucket: Bucket = {
131
+ type: ResourceType.SSTBucket,
132
+ name: 'assets-bucket-prod',
133
+ };
134
+
135
+ const env = new SstEnvironmentBuilder({
136
+ assetStorage: bucket,
137
+ }).build();
138
+
139
+ expect(env).toEqual({
140
+ ASSET_STORAGE_NAME: 'assets-bucket-prod',
141
+ });
142
+ });
143
+ });
144
+
145
+ describe('SnsTopic resource', () => {
146
+ it('should process SnsTopic resource correctly', () => {
147
+ const topic: SnsTopic = {
148
+ type: ResourceType.SnsTopic,
149
+ arn: 'arn:aws:sns:us-east-1:123456789:my-topic',
150
+ };
151
+
152
+ const env = new SstEnvironmentBuilder({
153
+ eventsTopic: topic,
154
+ }).build();
155
+
156
+ expect(env).toEqual({
157
+ EVENTS_TOPIC_ARN: 'arn:aws:sns:us-east-1:123456789:my-topic',
158
+ });
159
+ });
160
+ });
161
+
162
+ describe('noop resources', () => {
163
+ it('should not add environment variables for ApiGatewayV2', () => {
164
+ const env = new SstEnvironmentBuilder({
165
+ api: {
166
+ type: ResourceType.ApiGatewayV2,
167
+ url: 'https://api.example.com',
168
+ },
169
+ }).build();
170
+
171
+ expect(env).toEqual({});
172
+ });
173
+
174
+ it('should not add environment variables for Function', () => {
175
+ const env = new SstEnvironmentBuilder({
176
+ handler: {
177
+ type: ResourceType.Function,
178
+ name: 'my-lambda',
179
+ },
180
+ }).build();
181
+
182
+ expect(env).toEqual({});
183
+ });
184
+
185
+ it('should not add environment variables for Vpc', () => {
186
+ const env = new SstEnvironmentBuilder({
187
+ network: {
188
+ type: ResourceType.Vpc,
189
+ bastion: 'bastion-host',
190
+ },
191
+ }).build();
192
+
193
+ expect(env).toEqual({});
194
+ });
195
+ });
196
+
197
+ describe('mixed resources', () => {
198
+ it('should handle mix of strings and resources', () => {
199
+ const postgres: Postgres = {
200
+ type: ResourceType.Postgres,
201
+ database: 'app_db',
202
+ host: 'db.example.com',
203
+ password: 'db-pass',
204
+ port: 5432,
205
+ username: 'app_user',
206
+ };
207
+
208
+ const secret: Secret = {
209
+ type: ResourceType.Secret,
210
+ value: 'jwt-secret',
211
+ };
212
+
213
+ const bucket: Bucket = {
214
+ type: ResourceType.Bucket,
215
+ name: 'uploads-bucket',
216
+ };
217
+
218
+ const topic: SnsTopic = {
219
+ type: ResourceType.SnsTopic,
220
+ arn: 'arn:aws:sns:us-east-1:123456789:events',
221
+ };
222
+
223
+ const env = new SstEnvironmentBuilder({
224
+ nodeEnv: 'production',
225
+ appName: 'My App',
226
+ database: postgres,
227
+ jwtSecret: secret,
228
+ uploads: bucket,
229
+ events: topic,
230
+ apiVersion: 'v2',
231
+ }).build();
232
+
233
+ expect(env).toEqual({
234
+ NODE_ENV: 'production',
235
+ APP_NAME: 'My App',
236
+ DATABASE_NAME: 'app_db',
237
+ DATABASE_HOST: 'db.example.com',
238
+ DATABASE_PASSWORD: 'db-pass',
239
+ DATABASE_PORT: 5432,
240
+ DATABASE_USERNAME: 'app_user',
241
+ JWT_SECRET: 'jwt-secret',
242
+ UPLOADS_NAME: 'uploads-bucket',
243
+ EVENTS_ARN: 'arn:aws:sns:us-east-1:123456789:events',
244
+ API_VERSION: 'v2',
245
+ });
246
+ });
247
+ });
248
+
249
+ describe('additional resolvers', () => {
250
+ it('should allow custom resolvers', () => {
251
+ const env = new SstEnvironmentBuilder(
252
+ {
253
+ custom: { type: 'my-custom-type' as const, data: 'custom-data' },
254
+ secret: { type: ResourceType.Secret, value: 'secret-value' },
255
+ },
256
+ {
257
+ 'my-custom-type': (key: string, value: { data: string }) => ({
258
+ [`${key}Data`]: value.data,
259
+ }),
260
+ },
261
+ ).build();
262
+
263
+ expect(env).toEqual({
264
+ CUSTOM_DATA: 'custom-data',
265
+ SECRET: 'secret-value',
266
+ });
267
+ });
268
+
269
+ it('should allow custom resolvers to override built-in resolvers', () => {
270
+ const env = new SstEnvironmentBuilder(
271
+ {
272
+ mySecret: { type: ResourceType.Secret, value: 'original-value' },
273
+ },
274
+ {
275
+ [ResourceType.Secret]: (
276
+ key: string,
277
+ value: { type: string; value: string },
278
+ ) => ({
279
+ [`${key}Custom`]: `modified-${value.value}`,
280
+ }),
281
+ },
282
+ ).build();
283
+
284
+ expect(env).toEqual({
285
+ MY_SECRET_CUSTOM: 'modified-original-value',
286
+ });
287
+ });
288
+ });
289
+
290
+ describe('edge cases', () => {
291
+ it('should warn for unknown resource types', () => {
292
+ const consoleWarnSpy = vi
293
+ .spyOn(console, 'warn')
294
+ .mockImplementation(() => {});
295
+
296
+ const unknownResource = {
297
+ type: 'unknown.resource.Type',
298
+ value: 'something',
299
+ };
300
+
301
+ const env = new SstEnvironmentBuilder({
302
+ unknown: unknownResource,
303
+ }).build();
304
+
305
+ expect(env).toEqual({});
306
+ expect(consoleWarnSpy).toHaveBeenCalled();
307
+
308
+ consoleWarnSpy.mockRestore();
309
+ });
310
+
311
+ it('should handle resources with special characters in keys', () => {
312
+ const secret: Secret = {
313
+ type: ResourceType.Secret,
314
+ value: 'value',
315
+ };
316
+
317
+ const env = new SstEnvironmentBuilder({
318
+ 'my-secret-key': secret,
319
+ 'another.secret': secret,
320
+ }).build();
321
+
322
+ expect(env).toEqual({
323
+ MY_SECRET_KEY: 'value',
324
+ ANOTHER_SECRET: 'value',
325
+ });
326
+ });
327
+
328
+ it('should preserve numeric values for postgres port', () => {
329
+ const postgres: Postgres = {
330
+ type: ResourceType.Postgres,
331
+ database: 'test',
332
+ host: 'localhost',
333
+ password: 'pass',
334
+ port: 5432,
335
+ username: 'user',
336
+ };
337
+
338
+ const env = new SstEnvironmentBuilder({
339
+ db: postgres,
340
+ }).build();
341
+
342
+ expect(env.DB_PORT).toBe(5432);
343
+ expect(typeof env.DB_PORT).toBe('number');
344
+ });
345
+ });
346
+
347
+ describe('sstResolvers export', () => {
348
+ it('should export pre-configured SST resolvers', () => {
349
+ expect(sstResolvers).toBeDefined();
350
+ expect(typeof sstResolvers[ResourceType.Secret]).toBe('function');
351
+ expect(typeof sstResolvers[ResourceType.Postgres]).toBe('function');
352
+ expect(typeof sstResolvers[ResourceType.Bucket]).toBe('function');
353
+ expect(typeof sstResolvers[ResourceType.SnsTopic]).toBe('function');
354
+ });
355
+ });
356
+
357
+ describe('ResourceType enum', () => {
358
+ it('should have all expected resource types', () => {
359
+ expect(ResourceType.ApiGatewayV2).toBe('sst.aws.ApiGatewayV2');
360
+ expect(ResourceType.Postgres).toBe('sst.aws.Postgres');
361
+ expect(ResourceType.Function).toBe('sst.aws.Function');
362
+ expect(ResourceType.Bucket).toBe('sst.aws.Bucket');
363
+ expect(ResourceType.Vpc).toBe('sst.aws.Vpc');
364
+ expect(ResourceType.Secret).toBe('sst.sst.Secret');
365
+ expect(ResourceType.SSTSecret).toBe('sst:sst:Secret');
366
+ expect(ResourceType.SSTFunction).toBe('sst:sst:Function');
367
+ expect(ResourceType.SSTApiGatewayV2).toBe('sst:aws:ApiGatewayV2');
368
+ expect(ResourceType.SSTPostgres).toBe('sst:aws:Postgres');
369
+ expect(ResourceType.SSTBucket).toBe('sst:aws:Bucket');
370
+ expect(ResourceType.SnsTopic).toBe('sst:aws:SnsTopic');
371
+ });
372
+ });
373
+ });
@@ -321,7 +321,7 @@ describe('sst', () => {
321
321
 
322
322
  expect(result).toEqual({});
323
323
  expect(consoleWarnSpy).toHaveBeenCalledWith(
324
- 'No processor found for resource type: ',
324
+ 'No resolver found for key "unknown":',
325
325
  { value: unknownResource },
326
326
  );
327
327
 
package/src/index.ts CHANGED
@@ -1 +1,13 @@
1
1
  export { EnvironmentParser, ConfigParser } from './EnvironmentParser';
2
+ export {
3
+ EnvironmentBuilder,
4
+ environmentCase,
5
+ type EnvRecord,
6
+ type EnvValue,
7
+ type EnvironmentResolver,
8
+ type Resolvers,
9
+ type EnvironmentBuilderOptions,
10
+ type InputValue,
11
+ type TypedInputValue,
12
+ type TypedResolvers,
13
+ } from './EnvironmentBuilder';
package/src/sst.ts CHANGED
@@ -1,114 +1,38 @@
1
- import snakecase from 'lodash.snakecase';
2
-
3
- /**
4
- * Converts a string to environment variable case format (UPPER_SNAKE_CASE).
5
- * Numbers following underscores are preserved without the underscore.
6
- *
7
- * @param name - The string to convert
8
- * @returns The converted string in environment variable format
9
- *
10
- * @example
11
- * environmentCase('myVariable') // 'MY_VARIABLE'
12
- * environmentCase('api_v2') // 'APIV2'
13
- */
14
- export function environmentCase(name: string) {
15
- return snakecase(name)
16
- .toUpperCase()
17
- .replace(/_\d+/g, (r) => {
18
- return r.replace('_', '');
19
- });
20
- }
21
-
22
- /**
23
- * Enumeration of supported SST (Serverless Stack Toolkit) resource types.
24
- * Used to identify and process different AWS and SST resources.
25
- */
26
- export enum ResourceType {
27
- ApiGatewayV2 = 'sst.aws.ApiGatewayV2',
28
- Postgres = 'sst.aws.Postgres',
29
- Function = 'sst.aws.Function',
30
- Bucket = 'sst.aws.Bucket',
31
- Vpc = 'sst.aws.Vpc',
32
- Secret = 'sst.sst.Secret',
33
- SSTSecret = 'sst:sst:Secret',
34
- SSTFunction = 'sst:sst:Function',
35
- SSTApiGatewayV2 = 'sst:aws:ApiGatewayV2',
36
- SSTPostgres = 'sst:aws:Postgres',
37
- SSTBucket = 'sst:aws:Bucket',
38
- }
39
-
40
- /**
41
- * Processes a Secret resource into environment variables.
42
- *
43
- * @param name - The resource name
44
- * @param value - The Secret resource
45
- * @returns Object with environment variable mappings
46
- */
47
- const secret = (name: string, value: Secret) => ({
48
- [environmentCase(name)]: value.value,
49
- });
50
- /**
51
- * Processes a Postgres database resource into environment variables.
52
- * Creates multiple environment variables for database connection details.
53
- *
54
- * @param key - The resource key
55
- * @param value - The Postgres resource
56
- * @returns Object with database connection environment variables
57
- */
58
- const postgres = (key: string, value: Postgres) => {
59
- const prefix = `${environmentCase(key)}`;
60
- return {
61
- [`${prefix}_NAME`]: value.database,
62
- [`${prefix}_HOST`]: value.host,
63
- [`${prefix}_PASSWORD`]: value.password,
64
- [`${prefix}_PORT`]: value.port,
65
- [`${prefix}_USERNAME`]: value.username,
66
- };
67
- };
68
-
69
- /**
70
- * Processes a Bucket resource into environment variables.
71
- *
72
- * @param name - The resource name
73
- * @param value - The Bucket resource
74
- * @returns Object with bucket name environment variable
75
- */
76
- const bucket = (name: string, value: Bucket) => {
77
- const prefix = `${environmentCase(name)}`;
78
- return {
79
- [`${prefix}_NAME`]: value.name,
80
- };
81
- };
82
-
83
- /**
84
- * No-operation processor for resources that don't require environment variables.
1
+ // Re-export everything from SstEnvironmentBuilder
2
+ export {
3
+ SstEnvironmentBuilder,
4
+ sstResolvers,
5
+ ResourceType,
6
+ type ApiGatewayV2,
7
+ type Postgres,
8
+ type Function,
9
+ type Bucket,
10
+ type Vpc,
11
+ type Secret,
12
+ type SnsTopic,
13
+ type SstResource,
14
+ type ResourceProcessor,
15
+ } from './SstEnvironmentBuilder';
16
+
17
+ // Re-export environmentCase from EnvironmentBuilder
18
+ export { environmentCase } from './EnvironmentBuilder';
19
+
20
+ // Re-export types from EnvironmentBuilder
21
+ export type {
22
+ EnvRecord,
23
+ EnvValue,
24
+ EnvironmentBuilderOptions,
25
+ } from './EnvironmentBuilder';
26
+
27
+ // Import for deprecated function
28
+ import {
29
+ SstEnvironmentBuilder,
30
+ type SstResource,
31
+ } from './SstEnvironmentBuilder';
32
+
33
+ /**
34
+ * @deprecated Use `new SstEnvironmentBuilder(record).build()` instead.
85
35
  *
86
- * @param name - The resource name (unused)
87
- * @param value - The resource value (unused)
88
- * @returns Empty object
89
- */
90
- const noop = (name: string, value: any) => ({});
91
-
92
- /**
93
- * Map of resource types to their corresponding processor functions.
94
- * Each processor converts resource data into environment variables.
95
- */
96
- const processors: Record<ResourceType, ResourceProcessor<any>> = {
97
- [ResourceType.ApiGatewayV2]: noop,
98
- [ResourceType.Function]: noop,
99
- [ResourceType.Vpc]: noop,
100
- [ResourceType.Secret]: secret,
101
- [ResourceType.Postgres]: postgres,
102
- [ResourceType.Bucket]: bucket,
103
-
104
- [ResourceType.SSTSecret]: secret,
105
- [ResourceType.SSTBucket]: bucket,
106
- [ResourceType.SSTFunction]: noop,
107
- [ResourceType.SSTPostgres]: postgres,
108
- [ResourceType.SSTApiGatewayV2]: noop,
109
- };
110
-
111
- /**
112
36
  * Normalizes SST resources and plain strings into environment variables.
113
37
  * Processes resources based on their type and converts names to environment case.
114
38
  *
@@ -116,106 +40,20 @@ const processors: Record<ResourceType, ResourceProcessor<any>> = {
116
40
  * @returns Normalized environment variables object
117
41
  *
118
42
  * @example
119
- * normalizeResourceEnv({
120
- * apiUrl: 'https://api.example.com',
121
- * database: { type: ResourceType.Postgres, ... }
122
- * })
43
+ * // Old usage (deprecated):
44
+ * normalizeResourceEnv({ database: postgresResource })
45
+ *
46
+ * // New usage:
47
+ * new SstEnvironmentBuilder({ database: postgresResource }).build()
123
48
  */
124
49
  export function normalizeResourceEnv(
125
- record: Record<string, Resource | string>,
126
- ): Record<string, string> {
127
- const env: Record<string, string> = {};
128
- for (const [k, value] of Object.entries(record)) {
129
- if (typeof value === 'string') {
130
- env[environmentCase(k)] = value;
131
- continue;
132
- }
133
-
134
- const processor = processors[value.type];
135
- if (processor) {
136
- Object.assign(env, processor(k, value));
137
- } else {
138
- console.warn(`No processor found for resource type: `, { value });
139
- }
140
- }
141
-
142
- return env;
50
+ record: Record<string, SstResource | string>,
51
+ ): Record<string, string | number | boolean | Record<string, unknown>> {
52
+ return new SstEnvironmentBuilder(record).build();
143
53
  }
144
54
 
55
+ // Keep Resource type as deprecated alias for backwards compatibility
145
56
  /**
146
- * AWS API Gateway V2 resource type.
147
- * Represents an HTTP/WebSocket API.
148
- */
149
- export type ApiGatewayV2 = {
150
- type: ResourceType.ApiGatewayV2;
151
- url: string;
152
- };
153
-
154
- /**
155
- * PostgreSQL database resource type.
156
- * Contains all connection details needed to connect to the database.
157
- */
158
- export type Postgres = {
159
- database: string;
160
- host: string;
161
- password: string;
162
- port: number;
163
- type: ResourceType.Postgres;
164
- username: string;
165
- };
166
-
167
- /**
168
- * AWS Lambda Function resource type.
169
- */
170
- export type Function = {
171
- name: string;
172
- type: ResourceType.Function;
173
- };
174
-
175
- /**
176
- * AWS S3 Bucket resource type.
177
- */
178
- export type Bucket = {
179
- name: string;
180
- type: ResourceType.Bucket;
181
- };
182
-
183
- /**
184
- * AWS VPC (Virtual Private Cloud) resource type.
185
- */
186
- export type Vpc = {
187
- bastion: string;
188
- type: ResourceType.Vpc;
189
- };
190
-
191
- /**
192
- * Secret resource type for storing sensitive values.
193
- */
194
- export type Secret = {
195
- type: ResourceType.Secret;
196
- value: string;
197
- };
198
-
199
- /**
200
- * Union type of all supported SST resource types.
201
- */
202
- export type Resource =
203
- | ApiGatewayV2
204
- | Postgres
205
- | Function
206
- | Bucket
207
- | Vpc
208
- | Secret;
209
-
210
- /**
211
- * Function type for processing a specific resource type into environment variables.
212
- *
213
- * @template K - The specific resource type
214
- * @param name - The resource name
215
- * @param value - The resource value
216
- * @returns Object mapping environment variable names to values
57
+ * @deprecated Use `SstResource` instead.
217
58
  */
218
- export type ResourceProcessor<K extends Resource> = (
219
- name: string,
220
- value: K,
221
- ) => Record<string, string | number>;
59
+ export type Resource = SstResource;