@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.
- package/dist/{EnvironmentBuilder-DfmYRBm-.mjs → EnvironmentBuilder-BSuHZm0y.mjs} +2 -4
- package/dist/EnvironmentBuilder-BSuHZm0y.mjs.map +1 -0
- package/dist/EnvironmentBuilder-DHfDXJUm.d.mts.map +1 -0
- package/dist/{EnvironmentBuilder-W2wku49g.cjs → EnvironmentBuilder-Djr1VsWM.cjs} +2 -4
- package/dist/EnvironmentBuilder-Djr1VsWM.cjs.map +1 -0
- package/dist/EnvironmentBuilder-Xuf2Dd9u.d.cts.map +1 -0
- package/dist/EnvironmentBuilder.cjs +1 -1
- package/dist/EnvironmentBuilder.mjs +1 -1
- package/dist/EnvironmentParser-Bt246UeP.cjs.map +1 -1
- package/dist/{EnvironmentParser-CVWU1ooT.d.mts → EnvironmentParser-CY8TosTN.d.mts} +2 -1
- package/dist/EnvironmentParser-CY8TosTN.d.mts.map +1 -0
- package/dist/{EnvironmentParser-tV-JjCg7.d.cts → EnvironmentParser-DtOL86NU.d.cts} +2 -1
- package/dist/EnvironmentParser-DtOL86NU.d.cts.map +1 -0
- package/dist/EnvironmentParser-c06agx31.mjs.map +1 -1
- package/dist/EnvironmentParser.d.cts +1 -1
- package/dist/EnvironmentParser.d.mts +1 -1
- package/dist/SnifferEnvironmentParser.cjs.map +1 -1
- package/dist/SnifferEnvironmentParser.d.cts +3 -2
- package/dist/SnifferEnvironmentParser.d.cts.map +1 -0
- package/dist/SnifferEnvironmentParser.d.mts +3 -2
- package/dist/SnifferEnvironmentParser.d.mts.map +1 -0
- package/dist/SnifferEnvironmentParser.mjs.map +1 -1
- package/dist/{SstEnvironmentBuilder-DEa3lTUB.mjs → SstEnvironmentBuilder-BEBFSUYr.mjs} +2 -2
- package/dist/SstEnvironmentBuilder-BEBFSUYr.mjs.map +1 -0
- package/dist/SstEnvironmentBuilder-CjURMGjW.d.mts.map +1 -0
- package/dist/SstEnvironmentBuilder-D4oSo_KX.d.cts.map +1 -0
- package/dist/{SstEnvironmentBuilder-BuFw1hCe.cjs → SstEnvironmentBuilder-wFnN2M5O.cjs} +2 -2
- package/dist/SstEnvironmentBuilder-wFnN2M5O.cjs.map +1 -0
- package/dist/SstEnvironmentBuilder.cjs +2 -2
- package/dist/SstEnvironmentBuilder.mjs +2 -2
- package/dist/credentials.cjs +66 -0
- package/dist/credentials.cjs.map +1 -0
- package/dist/credentials.d.cts +31 -0
- package/dist/credentials.d.cts.map +1 -0
- package/dist/credentials.d.mts +31 -0
- package/dist/credentials.d.mts.map +1 -0
- package/dist/credentials.mjs +62 -0
- package/dist/credentials.mjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/sst.cjs +2 -2
- package/dist/sst.cjs.map +1 -1
- package/dist/sst.d.cts +1 -0
- package/dist/sst.d.cts.map +1 -0
- package/dist/sst.d.mts +1 -0
- package/dist/sst.d.mts.map +1 -0
- package/dist/sst.mjs +2 -2
- package/dist/sst.mjs.map +1 -1
- package/examples/basic-usage.ts +329 -333
- package/package.json +6 -1
- package/src/EnvironmentBuilder.ts +76 -80
- package/src/EnvironmentParser.ts +231 -231
- package/src/SnifferEnvironmentParser.ts +178 -178
- package/src/SstEnvironmentBuilder.ts +127 -127
- package/src/__tests__/ConfigParser.spec.ts +388 -388
- package/src/__tests__/EnvironmentBuilder.spec.ts +245 -265
- package/src/__tests__/EnvironmentParser.spec.ts +828 -828
- package/src/__tests__/SnifferEnvironmentParser.spec.ts +380 -326
- package/src/__tests__/SstEnvironmentBuilder.spec.ts +347 -367
- package/src/__tests__/credentials.integration.spec.ts +239 -0
- package/src/__tests__/credentials.spec.ts +136 -0
- package/src/__tests__/sst.spec.ts +390 -413
- package/src/credentials.ts +99 -0
- package/src/index.ts +11 -11
- package/src/sst.ts +24 -24
- package/sst-env.d.ts +0 -1
- package/tsconfig.json +9 -0
- package/dist/EnvironmentBuilder-DfmYRBm-.mjs.map +0 -1
- package/dist/EnvironmentBuilder-W2wku49g.cjs.map +0 -1
- package/dist/SstEnvironmentBuilder-BuFw1hCe.cjs.map +0 -1
- package/dist/SstEnvironmentBuilder-DEa3lTUB.mjs.map +0 -1
|
@@ -1,373 +1,353 @@
|
|
|
1
|
-
import { describe, expect, it
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
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
|
});
|