@geekmidas/envkit 0.1.0 → 0.3.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 (73) hide show
  1. package/dist/{EnvironmentBuilder-DfmYRBm-.mjs → EnvironmentBuilder-BSuHZm0y.mjs} +2 -4
  2. package/dist/EnvironmentBuilder-BSuHZm0y.mjs.map +1 -0
  3. package/dist/EnvironmentBuilder-DHfDXJUm.d.mts.map +1 -0
  4. package/dist/{EnvironmentBuilder-W2wku49g.cjs → EnvironmentBuilder-Djr1VsWM.cjs} +2 -4
  5. package/dist/EnvironmentBuilder-Djr1VsWM.cjs.map +1 -0
  6. package/dist/EnvironmentBuilder-Xuf2Dd9u.d.cts.map +1 -0
  7. package/dist/EnvironmentBuilder.cjs +1 -1
  8. package/dist/EnvironmentBuilder.mjs +1 -1
  9. package/dist/EnvironmentParser-Bt246UeP.cjs.map +1 -1
  10. package/dist/{EnvironmentParser-CVWU1ooT.d.mts → EnvironmentParser-CY8TosTN.d.mts} +2 -1
  11. package/dist/EnvironmentParser-CY8TosTN.d.mts.map +1 -0
  12. package/dist/{EnvironmentParser-tV-JjCg7.d.cts → EnvironmentParser-DtOL86NU.d.cts} +2 -1
  13. package/dist/EnvironmentParser-DtOL86NU.d.cts.map +1 -0
  14. package/dist/EnvironmentParser-c06agx31.mjs.map +1 -1
  15. package/dist/EnvironmentParser.d.cts +1 -1
  16. package/dist/EnvironmentParser.d.mts +1 -1
  17. package/dist/SnifferEnvironmentParser.cjs.map +1 -1
  18. package/dist/SnifferEnvironmentParser.d.cts +3 -2
  19. package/dist/SnifferEnvironmentParser.d.cts.map +1 -0
  20. package/dist/SnifferEnvironmentParser.d.mts +3 -2
  21. package/dist/SnifferEnvironmentParser.d.mts.map +1 -0
  22. package/dist/SnifferEnvironmentParser.mjs.map +1 -1
  23. package/dist/{SstEnvironmentBuilder-DEa3lTUB.mjs → SstEnvironmentBuilder-BEBFSUYr.mjs} +2 -2
  24. package/dist/SstEnvironmentBuilder-BEBFSUYr.mjs.map +1 -0
  25. package/dist/SstEnvironmentBuilder-CjURMGjW.d.mts.map +1 -0
  26. package/dist/SstEnvironmentBuilder-D4oSo_KX.d.cts.map +1 -0
  27. package/dist/{SstEnvironmentBuilder-BuFw1hCe.cjs → SstEnvironmentBuilder-wFnN2M5O.cjs} +2 -2
  28. package/dist/SstEnvironmentBuilder-wFnN2M5O.cjs.map +1 -0
  29. package/dist/SstEnvironmentBuilder.cjs +2 -2
  30. package/dist/SstEnvironmentBuilder.mjs +2 -2
  31. package/dist/credentials.cjs +66 -0
  32. package/dist/credentials.cjs.map +1 -0
  33. package/dist/credentials.d.cts +31 -0
  34. package/dist/credentials.d.cts.map +1 -0
  35. package/dist/credentials.d.mts +31 -0
  36. package/dist/credentials.d.mts.map +1 -0
  37. package/dist/credentials.mjs +62 -0
  38. package/dist/credentials.mjs.map +1 -0
  39. package/dist/index.cjs +1 -1
  40. package/dist/index.d.cts +1 -1
  41. package/dist/index.d.mts +1 -1
  42. package/dist/index.mjs +1 -1
  43. package/dist/sst.cjs +2 -2
  44. package/dist/sst.cjs.map +1 -1
  45. package/dist/sst.d.cts +1 -0
  46. package/dist/sst.d.cts.map +1 -0
  47. package/dist/sst.d.mts +1 -0
  48. package/dist/sst.d.mts.map +1 -0
  49. package/dist/sst.mjs +2 -2
  50. package/dist/sst.mjs.map +1 -1
  51. package/examples/basic-usage.ts +329 -333
  52. package/package.json +6 -1
  53. package/src/EnvironmentBuilder.ts +76 -80
  54. package/src/EnvironmentParser.ts +231 -231
  55. package/src/SnifferEnvironmentParser.ts +178 -178
  56. package/src/SstEnvironmentBuilder.ts +127 -127
  57. package/src/__tests__/ConfigParser.spec.ts +388 -388
  58. package/src/__tests__/EnvironmentBuilder.spec.ts +245 -265
  59. package/src/__tests__/EnvironmentParser.spec.ts +828 -828
  60. package/src/__tests__/SnifferEnvironmentParser.spec.ts +380 -326
  61. package/src/__tests__/SstEnvironmentBuilder.spec.ts +347 -367
  62. package/src/__tests__/credentials.integration.spec.ts +239 -0
  63. package/src/__tests__/credentials.spec.ts +136 -0
  64. package/src/__tests__/sst.spec.ts +390 -413
  65. package/src/credentials.ts +99 -0
  66. package/src/index.ts +11 -11
  67. package/src/sst.ts +24 -24
  68. package/sst-env.d.ts +0 -1
  69. package/tsconfig.json +9 -0
  70. package/dist/EnvironmentBuilder-DfmYRBm-.mjs.map +0 -1
  71. package/dist/EnvironmentBuilder-W2wku49g.cjs.map +0 -1
  72. package/dist/SstEnvironmentBuilder-BuFw1hCe.cjs.map +0 -1
  73. package/dist/SstEnvironmentBuilder-DEa3lTUB.mjs.map +0 -1
@@ -1,373 +1,353 @@
1
- import { describe, expect, it, vi } from 'vitest';
1
+ import { describe, expect, it } from 'vitest';
2
2
 
3
3
  import {
4
- type Bucket,
5
- type Postgres,
6
- ResourceType,
7
- type Secret,
8
- type SnsTopic,
9
- SstEnvironmentBuilder,
10
- sstResolvers,
4
+ type Bucket,
5
+ type Postgres,
6
+ ResourceType,
7
+ type Secret,
8
+ type SnsTopic,
9
+ SstEnvironmentBuilder,
10
+ sstResolvers,
11
11
  } from '../SstEnvironmentBuilder';
12
12
 
13
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
- });
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 handle resources with special characters in keys', () => {
292
+ const secret: Secret = {
293
+ type: ResourceType.Secret,
294
+ value: 'value',
295
+ };
296
+
297
+ const env = new SstEnvironmentBuilder({
298
+ 'my-secret-key': secret,
299
+ 'another.secret': secret,
300
+ }).build();
301
+
302
+ expect(env).toEqual({
303
+ MY_SECRET_KEY: 'value',
304
+ ANOTHER_SECRET: 'value',
305
+ });
306
+ });
307
+
308
+ it('should preserve numeric values for postgres port', () => {
309
+ const postgres: Postgres = {
310
+ type: ResourceType.Postgres,
311
+ database: 'test',
312
+ host: 'localhost',
313
+ password: 'pass',
314
+ port: 5432,
315
+ username: 'user',
316
+ };
317
+
318
+ const env = new SstEnvironmentBuilder({
319
+ db: postgres,
320
+ }).build();
321
+
322
+ expect(env.DB_PORT).toBe(5432);
323
+ expect(typeof env.DB_PORT).toBe('number');
324
+ });
325
+ });
326
+
327
+ describe('sstResolvers export', () => {
328
+ it('should export pre-configured SST resolvers', () => {
329
+ expect(sstResolvers).toBeDefined();
330
+ expect(typeof sstResolvers[ResourceType.Secret]).toBe('function');
331
+ expect(typeof sstResolvers[ResourceType.Postgres]).toBe('function');
332
+ expect(typeof sstResolvers[ResourceType.Bucket]).toBe('function');
333
+ expect(typeof sstResolvers[ResourceType.SnsTopic]).toBe('function');
334
+ });
335
+ });
336
+
337
+ describe('ResourceType enum', () => {
338
+ it('should have all expected resource types', () => {
339
+ expect(ResourceType.ApiGatewayV2).toBe('sst.aws.ApiGatewayV2');
340
+ expect(ResourceType.Postgres).toBe('sst.aws.Postgres');
341
+ expect(ResourceType.Function).toBe('sst.aws.Function');
342
+ expect(ResourceType.Bucket).toBe('sst.aws.Bucket');
343
+ expect(ResourceType.Vpc).toBe('sst.aws.Vpc');
344
+ expect(ResourceType.Secret).toBe('sst.sst.Secret');
345
+ expect(ResourceType.SSTSecret).toBe('sst:sst:Secret');
346
+ expect(ResourceType.SSTFunction).toBe('sst:sst:Function');
347
+ expect(ResourceType.SSTApiGatewayV2).toBe('sst:aws:ApiGatewayV2');
348
+ expect(ResourceType.SSTPostgres).toBe('sst:aws:Postgres');
349
+ expect(ResourceType.SSTBucket).toBe('sst:aws:Bucket');
350
+ expect(ResourceType.SnsTopic).toBe('sst:aws:SnsTopic');
351
+ });
352
+ });
373
353
  });