@geekmidas/envkit 0.0.4 → 0.0.6
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/{EnvironmentParser-Bo2CCl_K.cjs → EnvironmentParser-BDPDLv6i.cjs} +7 -7
- package/dist/EnvironmentParser-C-arQEHQ.d.mts +108 -0
- package/dist/{EnvironmentParser-jKrGMBhP.mjs → EnvironmentParser-CQUOGqc0.mjs} +7 -7
- package/dist/EnvironmentParser-X4h2Vp4r.d.cts +108 -0
- package/dist/EnvironmentParser.cjs +1 -1
- package/dist/EnvironmentParser.d.cts +2 -0
- package/dist/EnvironmentParser.d.mts +2 -0
- package/dist/EnvironmentParser.mjs +1 -1
- package/dist/__tests__/ConfigParser.spec.cjs +1 -1
- package/dist/__tests__/ConfigParser.spec.d.cts +1 -0
- package/dist/__tests__/ConfigParser.spec.d.mts +1 -0
- package/dist/__tests__/ConfigParser.spec.mjs +1 -1
- package/dist/__tests__/EnvironmentParser.spec.cjs +1 -1
- package/dist/__tests__/EnvironmentParser.spec.d.cts +1 -0
- package/dist/__tests__/EnvironmentParser.spec.d.mts +1 -0
- package/dist/__tests__/EnvironmentParser.spec.mjs +1 -1
- package/dist/__tests__/sst.spec.cjs +305 -0
- package/dist/__tests__/sst.spec.d.cts +1 -0
- package/dist/__tests__/sst.spec.d.mts +1 -0
- package/dist/__tests__/sst.spec.mjs +304 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1 -1
- package/dist/sst-BSxwaAdz.cjs +146 -0
- package/dist/sst-CQhO0S6y.mjs +128 -0
- package/dist/sst.cjs +4 -130
- package/dist/sst.d.cts +107 -0
- package/dist/sst.d.mts +107 -0
- package/dist/sst.mjs +1 -126
- package/package.json +5 -5
- package/src/EnvironmentParser.ts +10 -10
- package/src/__tests__/sst.spec.ts +415 -0
- package/src/sst.ts +9 -9
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
const require_chunk = require('../chunk-CUT6urMc.cjs');
|
|
2
|
+
const require_sst = require('../sst-BSxwaAdz.cjs');
|
|
3
|
+
const vitest = require_chunk.__toESM(require("vitest"));
|
|
4
|
+
|
|
5
|
+
//#region src/__tests__/sst.spec.ts
|
|
6
|
+
(0, vitest.describe)("sst", () => {
|
|
7
|
+
(0, vitest.describe)("environmentCase", () => {
|
|
8
|
+
(0, vitest.it)("should convert camelCase to UPPER_SNAKE_CASE", () => {
|
|
9
|
+
(0, vitest.expect)(require_sst.environmentCase("myVariable")).toBe("MY_VARIABLE");
|
|
10
|
+
(0, vitest.expect)(require_sst.environmentCase("somePropertyName")).toBe("SOME_PROPERTY_NAME");
|
|
11
|
+
(0, vitest.expect)(require_sst.environmentCase("APIKey")).toBe("API_KEY");
|
|
12
|
+
});
|
|
13
|
+
(0, vitest.it)("should convert snake_case to UPPER_SNAKE_CASE", () => {
|
|
14
|
+
(0, vitest.expect)(require_sst.environmentCase("my_variable")).toBe("MY_VARIABLE");
|
|
15
|
+
(0, vitest.expect)(require_sst.environmentCase("some_property_name")).toBe("SOME_PROPERTY_NAME");
|
|
16
|
+
});
|
|
17
|
+
(0, vitest.it)("should handle numbers correctly", () => {
|
|
18
|
+
(0, vitest.expect)(require_sst.environmentCase("api_v2")).toBe("API_V2");
|
|
19
|
+
(0, vitest.expect)(require_sst.environmentCase("value_123")).toBe("VALUE123");
|
|
20
|
+
(0, vitest.expect)(require_sst.environmentCase("test_1_thing")).toBe("TEST1_THING");
|
|
21
|
+
(0, vitest.expect)(require_sst.environmentCase("api_2")).toBe("API2");
|
|
22
|
+
});
|
|
23
|
+
(0, vitest.it)("should handle already uppercase strings", () => {
|
|
24
|
+
(0, vitest.expect)(require_sst.environmentCase("ALREADY_UPPER")).toBe("ALREADY_UPPER");
|
|
25
|
+
(0, vitest.expect)(require_sst.environmentCase("TEST")).toBe("TEST");
|
|
26
|
+
});
|
|
27
|
+
(0, vitest.it)("should handle kebab-case", () => {
|
|
28
|
+
(0, vitest.expect)(require_sst.environmentCase("my-variable")).toBe("MY_VARIABLE");
|
|
29
|
+
(0, vitest.expect)(require_sst.environmentCase("kebab-case-example")).toBe("KEBAB_CASE_EXAMPLE");
|
|
30
|
+
});
|
|
31
|
+
(0, vitest.it)("should handle mixed cases", () => {
|
|
32
|
+
(0, vitest.expect)(require_sst.environmentCase("MixedCASE")).toBe("MIXED_CASE");
|
|
33
|
+
(0, vitest.expect)(require_sst.environmentCase("XMLParser")).toBe("XML_PARSER");
|
|
34
|
+
(0, vitest.expect)(require_sst.environmentCase("IOStream")).toBe("IO_STREAM");
|
|
35
|
+
});
|
|
36
|
+
(0, vitest.it)("should handle empty string", () => {
|
|
37
|
+
(0, vitest.expect)(require_sst.environmentCase("")).toBe("");
|
|
38
|
+
});
|
|
39
|
+
(0, vitest.it)("should handle single character", () => {
|
|
40
|
+
(0, vitest.expect)(require_sst.environmentCase("a")).toBe("A");
|
|
41
|
+
(0, vitest.expect)(require_sst.environmentCase("A")).toBe("A");
|
|
42
|
+
});
|
|
43
|
+
(0, vitest.it)("should handle strings with special characters", () => {
|
|
44
|
+
(0, vitest.expect)(require_sst.environmentCase("my.variable")).toBe("MY_VARIABLE");
|
|
45
|
+
(0, vitest.expect)(require_sst.environmentCase("my@variable")).toBe("MY_VARIABLE");
|
|
46
|
+
(0, vitest.expect)(require_sst.environmentCase("my#variable")).toBe("MY_VARIABLE");
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
(0, vitest.describe)("normalizeResourceEnv", () => {
|
|
50
|
+
(0, vitest.describe)("string values", () => {
|
|
51
|
+
(0, vitest.it)("should convert string values to environment case", () => {
|
|
52
|
+
const input = {
|
|
53
|
+
apiUrl: "https://api.example.com",
|
|
54
|
+
secretKey: "my-secret-key",
|
|
55
|
+
NODE_ENV: "production"
|
|
56
|
+
};
|
|
57
|
+
const result = require_sst.normalizeResourceEnv(input);
|
|
58
|
+
(0, vitest.expect)(result).toEqual({
|
|
59
|
+
API_URL: "https://api.example.com",
|
|
60
|
+
SECRET_KEY: "my-secret-key",
|
|
61
|
+
NODE_ENV: "production"
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
(0, vitest.it)("should handle empty object", () => {
|
|
65
|
+
(0, vitest.expect)(require_sst.normalizeResourceEnv({})).toEqual({});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
(0, vitest.describe)("Secret resource", () => {
|
|
69
|
+
(0, vitest.it)("should process Secret resource correctly", () => {
|
|
70
|
+
const secret = {
|
|
71
|
+
type: require_sst.ResourceType.Secret,
|
|
72
|
+
value: "super-secret-value"
|
|
73
|
+
};
|
|
74
|
+
const result = require_sst.normalizeResourceEnv({ mySecret: secret });
|
|
75
|
+
(0, vitest.expect)(result).toEqual({ MY_SECRET: "super-secret-value" });
|
|
76
|
+
});
|
|
77
|
+
(0, vitest.it)("should process SSTSecret resource correctly", () => {
|
|
78
|
+
const secret = {
|
|
79
|
+
type: require_sst.ResourceType.SSTSecret,
|
|
80
|
+
value: "another-secret"
|
|
81
|
+
};
|
|
82
|
+
const result = require_sst.normalizeResourceEnv({ appSecret: secret });
|
|
83
|
+
(0, vitest.expect)(result).toEqual({ APP_SECRET: "another-secret" });
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
(0, vitest.describe)("Postgres resource", () => {
|
|
87
|
+
(0, vitest.it)("should process Postgres resource correctly", () => {
|
|
88
|
+
const postgres = {
|
|
89
|
+
type: require_sst.ResourceType.Postgres,
|
|
90
|
+
database: "myapp",
|
|
91
|
+
host: "localhost",
|
|
92
|
+
password: "password123",
|
|
93
|
+
port: 5432,
|
|
94
|
+
username: "postgres"
|
|
95
|
+
};
|
|
96
|
+
const result = require_sst.normalizeResourceEnv({ database: postgres });
|
|
97
|
+
(0, vitest.expect)(result).toEqual({
|
|
98
|
+
DATABASE_NAME: "myapp",
|
|
99
|
+
DATABASE_HOST: "localhost",
|
|
100
|
+
DATABASE_PASSWORD: "password123",
|
|
101
|
+
DATABASE_PORT: 5432,
|
|
102
|
+
DATABASE_USERNAME: "postgres"
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
(0, vitest.it)("should process SSTPostgres resource correctly", () => {
|
|
106
|
+
const postgres = {
|
|
107
|
+
type: require_sst.ResourceType.SSTPostgres,
|
|
108
|
+
database: "prod_db",
|
|
109
|
+
host: "prod.example.com",
|
|
110
|
+
password: "prod-password",
|
|
111
|
+
port: 5433,
|
|
112
|
+
username: "prod_user"
|
|
113
|
+
};
|
|
114
|
+
const result = require_sst.normalizeResourceEnv({ mainDb: postgres });
|
|
115
|
+
(0, vitest.expect)(result).toEqual({
|
|
116
|
+
MAIN_DB_NAME: "prod_db",
|
|
117
|
+
MAIN_DB_HOST: "prod.example.com",
|
|
118
|
+
MAIN_DB_PASSWORD: "prod-password",
|
|
119
|
+
MAIN_DB_PORT: 5433,
|
|
120
|
+
MAIN_DB_USERNAME: "prod_user"
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
(0, vitest.describe)("Bucket resource", () => {
|
|
125
|
+
(0, vitest.it)("should process Bucket resource correctly", () => {
|
|
126
|
+
const bucket = {
|
|
127
|
+
type: require_sst.ResourceType.Bucket,
|
|
128
|
+
name: "my-s3-bucket"
|
|
129
|
+
};
|
|
130
|
+
const result = require_sst.normalizeResourceEnv({ uploadBucket: bucket });
|
|
131
|
+
(0, vitest.expect)(result).toEqual({ UPLOAD_BUCKET_NAME: "my-s3-bucket" });
|
|
132
|
+
});
|
|
133
|
+
(0, vitest.it)("should process SSTBucket resource correctly", () => {
|
|
134
|
+
const bucket = {
|
|
135
|
+
type: require_sst.ResourceType.SSTBucket,
|
|
136
|
+
name: "assets-bucket-prod"
|
|
137
|
+
};
|
|
138
|
+
const result = require_sst.normalizeResourceEnv({ assetStorage: bucket });
|
|
139
|
+
(0, vitest.expect)(result).toEqual({ ASSET_STORAGE_NAME: "assets-bucket-prod" });
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
(0, vitest.describe)("noop resources", () => {
|
|
143
|
+
(0, vitest.it)("should not add environment variables for ApiGatewayV2", () => {
|
|
144
|
+
const api = {
|
|
145
|
+
type: require_sst.ResourceType.ApiGatewayV2,
|
|
146
|
+
url: "https://api.example.com"
|
|
147
|
+
};
|
|
148
|
+
const result = require_sst.normalizeResourceEnv({ api });
|
|
149
|
+
(0, vitest.expect)(result).toEqual({});
|
|
150
|
+
});
|
|
151
|
+
(0, vitest.it)("should not add environment variables for Function", () => {
|
|
152
|
+
const fn = {
|
|
153
|
+
type: require_sst.ResourceType.Function,
|
|
154
|
+
name: "my-lambda"
|
|
155
|
+
};
|
|
156
|
+
const result = require_sst.normalizeResourceEnv({ handler: fn });
|
|
157
|
+
(0, vitest.expect)(result).toEqual({});
|
|
158
|
+
});
|
|
159
|
+
(0, vitest.it)("should not add environment variables for Vpc", () => {
|
|
160
|
+
const vpc = {
|
|
161
|
+
type: require_sst.ResourceType.Vpc,
|
|
162
|
+
bastion: "bastion-host"
|
|
163
|
+
};
|
|
164
|
+
const result = require_sst.normalizeResourceEnv({ network: vpc });
|
|
165
|
+
(0, vitest.expect)(result).toEqual({});
|
|
166
|
+
});
|
|
167
|
+
(0, vitest.it)("should handle all SST noop resource types", () => {
|
|
168
|
+
const api = {
|
|
169
|
+
type: require_sst.ResourceType.SSTApiGatewayV2,
|
|
170
|
+
url: "https://api.example.com"
|
|
171
|
+
};
|
|
172
|
+
const fn = {
|
|
173
|
+
type: require_sst.ResourceType.SSTFunction,
|
|
174
|
+
name: "my-function"
|
|
175
|
+
};
|
|
176
|
+
const result = require_sst.normalizeResourceEnv({
|
|
177
|
+
api,
|
|
178
|
+
function: fn
|
|
179
|
+
});
|
|
180
|
+
(0, vitest.expect)(result).toEqual({});
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
(0, vitest.describe)("mixed resources", () => {
|
|
184
|
+
(0, vitest.it)("should handle mix of strings and resources", () => {
|
|
185
|
+
const postgres = {
|
|
186
|
+
type: require_sst.ResourceType.Postgres,
|
|
187
|
+
database: "app_db",
|
|
188
|
+
host: "db.example.com",
|
|
189
|
+
password: "db-pass",
|
|
190
|
+
port: 5432,
|
|
191
|
+
username: "app_user"
|
|
192
|
+
};
|
|
193
|
+
const secret = {
|
|
194
|
+
type: require_sst.ResourceType.Secret,
|
|
195
|
+
value: "jwt-secret"
|
|
196
|
+
};
|
|
197
|
+
const bucket = {
|
|
198
|
+
type: require_sst.ResourceType.Bucket,
|
|
199
|
+
name: "uploads-bucket"
|
|
200
|
+
};
|
|
201
|
+
const result = require_sst.normalizeResourceEnv({
|
|
202
|
+
nodeEnv: "production",
|
|
203
|
+
appName: "My App",
|
|
204
|
+
database: postgres,
|
|
205
|
+
jwtSecret: secret,
|
|
206
|
+
uploads: bucket,
|
|
207
|
+
apiVersion: "v2"
|
|
208
|
+
});
|
|
209
|
+
(0, vitest.expect)(result).toEqual({
|
|
210
|
+
NODE_ENV: "production",
|
|
211
|
+
APP_NAME: "My App",
|
|
212
|
+
DATABASE_NAME: "app_db",
|
|
213
|
+
DATABASE_HOST: "db.example.com",
|
|
214
|
+
DATABASE_PASSWORD: "db-pass",
|
|
215
|
+
DATABASE_PORT: 5432,
|
|
216
|
+
DATABASE_USERNAME: "app_user",
|
|
217
|
+
JWT_SECRET: "jwt-secret",
|
|
218
|
+
UPLOADS_NAME: "uploads-bucket",
|
|
219
|
+
API_VERSION: "v2"
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
(0, vitest.describe)("edge cases", () => {
|
|
224
|
+
(0, vitest.it)("should warn for unknown resource types", () => {
|
|
225
|
+
const consoleWarnSpy = vitest.vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
226
|
+
const unknownResource = {
|
|
227
|
+
type: "unknown.resource.Type",
|
|
228
|
+
value: "something"
|
|
229
|
+
};
|
|
230
|
+
const result = require_sst.normalizeResourceEnv({ unknown: unknownResource });
|
|
231
|
+
(0, vitest.expect)(result).toEqual({});
|
|
232
|
+
(0, vitest.expect)(consoleWarnSpy).toHaveBeenCalledWith("No processor found for resource type: ", { value: unknownResource });
|
|
233
|
+
consoleWarnSpy.mockRestore();
|
|
234
|
+
});
|
|
235
|
+
(0, vitest.it)("should handle resources with special characters in keys", () => {
|
|
236
|
+
const secret = {
|
|
237
|
+
type: require_sst.ResourceType.Secret,
|
|
238
|
+
value: "value"
|
|
239
|
+
};
|
|
240
|
+
const result = require_sst.normalizeResourceEnv({
|
|
241
|
+
"my-secret-key": secret,
|
|
242
|
+
"another.secret": secret,
|
|
243
|
+
"secret@123": secret
|
|
244
|
+
});
|
|
245
|
+
(0, vitest.expect)(result).toEqual({
|
|
246
|
+
MY_SECRET_KEY: "value",
|
|
247
|
+
ANOTHER_SECRET: "value",
|
|
248
|
+
SECRET123: "value"
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
(0, vitest.it)("should handle numeric values in postgres port", () => {
|
|
252
|
+
const postgres = {
|
|
253
|
+
type: require_sst.ResourceType.Postgres,
|
|
254
|
+
database: "test",
|
|
255
|
+
host: "localhost",
|
|
256
|
+
password: "pass",
|
|
257
|
+
port: 5432,
|
|
258
|
+
username: "user"
|
|
259
|
+
};
|
|
260
|
+
const result = require_sst.normalizeResourceEnv({ db: postgres });
|
|
261
|
+
(0, vitest.expect)(result.DB_PORT).toBe(5432);
|
|
262
|
+
(0, vitest.expect)(typeof result.DB_PORT).toBe("number");
|
|
263
|
+
});
|
|
264
|
+
(0, vitest.it)("should handle very long keys", () => {
|
|
265
|
+
const secret = {
|
|
266
|
+
type: require_sst.ResourceType.Secret,
|
|
267
|
+
value: "value"
|
|
268
|
+
};
|
|
269
|
+
const result = require_sst.normalizeResourceEnv({ thisIsAVeryLongKeyNameThatShouldBeConvertedProperly: secret });
|
|
270
|
+
(0, vitest.expect)(result).toEqual({ THIS_IS_A_VERY_LONG_KEY_NAME_THAT_SHOULD_BE_CONVERTED_PROPERLY: "value" });
|
|
271
|
+
});
|
|
272
|
+
(0, vitest.it)("should handle multiple underscores and numbers", () => {
|
|
273
|
+
const bucket = {
|
|
274
|
+
type: require_sst.ResourceType.Bucket,
|
|
275
|
+
name: "test-bucket"
|
|
276
|
+
};
|
|
277
|
+
const result = require_sst.normalizeResourceEnv({
|
|
278
|
+
"s3_bucket_v2_1": bucket,
|
|
279
|
+
"bucket_123_456": bucket
|
|
280
|
+
});
|
|
281
|
+
(0, vitest.expect)(result).toEqual({
|
|
282
|
+
S3_BUCKET_V21_NAME: "test-bucket",
|
|
283
|
+
BUCKET123456_NAME: "test-bucket"
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
(0, vitest.describe)("ResourceType enum", () => {
|
|
289
|
+
(0, vitest.it)("should have all expected resource types", () => {
|
|
290
|
+
(0, vitest.expect)(require_sst.ResourceType.ApiGatewayV2).toBe("sst.aws.ApiGatewayV2");
|
|
291
|
+
(0, vitest.expect)(require_sst.ResourceType.Postgres).toBe("sst.aws.Postgres");
|
|
292
|
+
(0, vitest.expect)(require_sst.ResourceType.Function).toBe("sst.aws.Function");
|
|
293
|
+
(0, vitest.expect)(require_sst.ResourceType.Bucket).toBe("sst.aws.Bucket");
|
|
294
|
+
(0, vitest.expect)(require_sst.ResourceType.Vpc).toBe("sst.aws.Vpc");
|
|
295
|
+
(0, vitest.expect)(require_sst.ResourceType.Secret).toBe("sst.sst.Secret");
|
|
296
|
+
(0, vitest.expect)(require_sst.ResourceType.SSTSecret).toBe("sst:sst:Secret");
|
|
297
|
+
(0, vitest.expect)(require_sst.ResourceType.SSTFunction).toBe("sst:sst:Function");
|
|
298
|
+
(0, vitest.expect)(require_sst.ResourceType.SSTApiGatewayV2).toBe("sst:aws:ApiGatewayV2");
|
|
299
|
+
(0, vitest.expect)(require_sst.ResourceType.SSTPostgres).toBe("sst:aws:Postgres");
|
|
300
|
+
(0, vitest.expect)(require_sst.ResourceType.SSTBucket).toBe("sst:aws:Bucket");
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { ResourceType, environmentCase, normalizeResourceEnv } from "../sst-CQhO0S6y.mjs";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
|
|
4
|
+
//#region src/__tests__/sst.spec.ts
|
|
5
|
+
describe("sst", () => {
|
|
6
|
+
describe("environmentCase", () => {
|
|
7
|
+
it("should convert camelCase to UPPER_SNAKE_CASE", () => {
|
|
8
|
+
expect(environmentCase("myVariable")).toBe("MY_VARIABLE");
|
|
9
|
+
expect(environmentCase("somePropertyName")).toBe("SOME_PROPERTY_NAME");
|
|
10
|
+
expect(environmentCase("APIKey")).toBe("API_KEY");
|
|
11
|
+
});
|
|
12
|
+
it("should convert snake_case to UPPER_SNAKE_CASE", () => {
|
|
13
|
+
expect(environmentCase("my_variable")).toBe("MY_VARIABLE");
|
|
14
|
+
expect(environmentCase("some_property_name")).toBe("SOME_PROPERTY_NAME");
|
|
15
|
+
});
|
|
16
|
+
it("should handle numbers correctly", () => {
|
|
17
|
+
expect(environmentCase("api_v2")).toBe("API_V2");
|
|
18
|
+
expect(environmentCase("value_123")).toBe("VALUE123");
|
|
19
|
+
expect(environmentCase("test_1_thing")).toBe("TEST1_THING");
|
|
20
|
+
expect(environmentCase("api_2")).toBe("API2");
|
|
21
|
+
});
|
|
22
|
+
it("should handle already uppercase strings", () => {
|
|
23
|
+
expect(environmentCase("ALREADY_UPPER")).toBe("ALREADY_UPPER");
|
|
24
|
+
expect(environmentCase("TEST")).toBe("TEST");
|
|
25
|
+
});
|
|
26
|
+
it("should handle kebab-case", () => {
|
|
27
|
+
expect(environmentCase("my-variable")).toBe("MY_VARIABLE");
|
|
28
|
+
expect(environmentCase("kebab-case-example")).toBe("KEBAB_CASE_EXAMPLE");
|
|
29
|
+
});
|
|
30
|
+
it("should handle mixed cases", () => {
|
|
31
|
+
expect(environmentCase("MixedCASE")).toBe("MIXED_CASE");
|
|
32
|
+
expect(environmentCase("XMLParser")).toBe("XML_PARSER");
|
|
33
|
+
expect(environmentCase("IOStream")).toBe("IO_STREAM");
|
|
34
|
+
});
|
|
35
|
+
it("should handle empty string", () => {
|
|
36
|
+
expect(environmentCase("")).toBe("");
|
|
37
|
+
});
|
|
38
|
+
it("should handle single character", () => {
|
|
39
|
+
expect(environmentCase("a")).toBe("A");
|
|
40
|
+
expect(environmentCase("A")).toBe("A");
|
|
41
|
+
});
|
|
42
|
+
it("should handle strings with special characters", () => {
|
|
43
|
+
expect(environmentCase("my.variable")).toBe("MY_VARIABLE");
|
|
44
|
+
expect(environmentCase("my@variable")).toBe("MY_VARIABLE");
|
|
45
|
+
expect(environmentCase("my#variable")).toBe("MY_VARIABLE");
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
describe("normalizeResourceEnv", () => {
|
|
49
|
+
describe("string values", () => {
|
|
50
|
+
it("should convert string values to environment case", () => {
|
|
51
|
+
const input = {
|
|
52
|
+
apiUrl: "https://api.example.com",
|
|
53
|
+
secretKey: "my-secret-key",
|
|
54
|
+
NODE_ENV: "production"
|
|
55
|
+
};
|
|
56
|
+
const result = normalizeResourceEnv(input);
|
|
57
|
+
expect(result).toEqual({
|
|
58
|
+
API_URL: "https://api.example.com",
|
|
59
|
+
SECRET_KEY: "my-secret-key",
|
|
60
|
+
NODE_ENV: "production"
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
it("should handle empty object", () => {
|
|
64
|
+
expect(normalizeResourceEnv({})).toEqual({});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
describe("Secret resource", () => {
|
|
68
|
+
it("should process Secret resource correctly", () => {
|
|
69
|
+
const secret = {
|
|
70
|
+
type: ResourceType.Secret,
|
|
71
|
+
value: "super-secret-value"
|
|
72
|
+
};
|
|
73
|
+
const result = normalizeResourceEnv({ mySecret: secret });
|
|
74
|
+
expect(result).toEqual({ MY_SECRET: "super-secret-value" });
|
|
75
|
+
});
|
|
76
|
+
it("should process SSTSecret resource correctly", () => {
|
|
77
|
+
const secret = {
|
|
78
|
+
type: ResourceType.SSTSecret,
|
|
79
|
+
value: "another-secret"
|
|
80
|
+
};
|
|
81
|
+
const result = normalizeResourceEnv({ appSecret: secret });
|
|
82
|
+
expect(result).toEqual({ APP_SECRET: "another-secret" });
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe("Postgres resource", () => {
|
|
86
|
+
it("should process Postgres resource correctly", () => {
|
|
87
|
+
const postgres = {
|
|
88
|
+
type: ResourceType.Postgres,
|
|
89
|
+
database: "myapp",
|
|
90
|
+
host: "localhost",
|
|
91
|
+
password: "password123",
|
|
92
|
+
port: 5432,
|
|
93
|
+
username: "postgres"
|
|
94
|
+
};
|
|
95
|
+
const result = normalizeResourceEnv({ database: postgres });
|
|
96
|
+
expect(result).toEqual({
|
|
97
|
+
DATABASE_NAME: "myapp",
|
|
98
|
+
DATABASE_HOST: "localhost",
|
|
99
|
+
DATABASE_PASSWORD: "password123",
|
|
100
|
+
DATABASE_PORT: 5432,
|
|
101
|
+
DATABASE_USERNAME: "postgres"
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
it("should process SSTPostgres resource correctly", () => {
|
|
105
|
+
const postgres = {
|
|
106
|
+
type: ResourceType.SSTPostgres,
|
|
107
|
+
database: "prod_db",
|
|
108
|
+
host: "prod.example.com",
|
|
109
|
+
password: "prod-password",
|
|
110
|
+
port: 5433,
|
|
111
|
+
username: "prod_user"
|
|
112
|
+
};
|
|
113
|
+
const result = normalizeResourceEnv({ mainDb: postgres });
|
|
114
|
+
expect(result).toEqual({
|
|
115
|
+
MAIN_DB_NAME: "prod_db",
|
|
116
|
+
MAIN_DB_HOST: "prod.example.com",
|
|
117
|
+
MAIN_DB_PASSWORD: "prod-password",
|
|
118
|
+
MAIN_DB_PORT: 5433,
|
|
119
|
+
MAIN_DB_USERNAME: "prod_user"
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
describe("Bucket resource", () => {
|
|
124
|
+
it("should process Bucket resource correctly", () => {
|
|
125
|
+
const bucket = {
|
|
126
|
+
type: ResourceType.Bucket,
|
|
127
|
+
name: "my-s3-bucket"
|
|
128
|
+
};
|
|
129
|
+
const result = normalizeResourceEnv({ uploadBucket: bucket });
|
|
130
|
+
expect(result).toEqual({ UPLOAD_BUCKET_NAME: "my-s3-bucket" });
|
|
131
|
+
});
|
|
132
|
+
it("should process SSTBucket resource correctly", () => {
|
|
133
|
+
const bucket = {
|
|
134
|
+
type: ResourceType.SSTBucket,
|
|
135
|
+
name: "assets-bucket-prod"
|
|
136
|
+
};
|
|
137
|
+
const result = normalizeResourceEnv({ assetStorage: bucket });
|
|
138
|
+
expect(result).toEqual({ ASSET_STORAGE_NAME: "assets-bucket-prod" });
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
describe("noop resources", () => {
|
|
142
|
+
it("should not add environment variables for ApiGatewayV2", () => {
|
|
143
|
+
const api = {
|
|
144
|
+
type: ResourceType.ApiGatewayV2,
|
|
145
|
+
url: "https://api.example.com"
|
|
146
|
+
};
|
|
147
|
+
const result = normalizeResourceEnv({ api });
|
|
148
|
+
expect(result).toEqual({});
|
|
149
|
+
});
|
|
150
|
+
it("should not add environment variables for Function", () => {
|
|
151
|
+
const fn = {
|
|
152
|
+
type: ResourceType.Function,
|
|
153
|
+
name: "my-lambda"
|
|
154
|
+
};
|
|
155
|
+
const result = normalizeResourceEnv({ handler: fn });
|
|
156
|
+
expect(result).toEqual({});
|
|
157
|
+
});
|
|
158
|
+
it("should not add environment variables for Vpc", () => {
|
|
159
|
+
const vpc = {
|
|
160
|
+
type: ResourceType.Vpc,
|
|
161
|
+
bastion: "bastion-host"
|
|
162
|
+
};
|
|
163
|
+
const result = normalizeResourceEnv({ network: vpc });
|
|
164
|
+
expect(result).toEqual({});
|
|
165
|
+
});
|
|
166
|
+
it("should handle all SST noop resource types", () => {
|
|
167
|
+
const api = {
|
|
168
|
+
type: ResourceType.SSTApiGatewayV2,
|
|
169
|
+
url: "https://api.example.com"
|
|
170
|
+
};
|
|
171
|
+
const fn = {
|
|
172
|
+
type: ResourceType.SSTFunction,
|
|
173
|
+
name: "my-function"
|
|
174
|
+
};
|
|
175
|
+
const result = normalizeResourceEnv({
|
|
176
|
+
api,
|
|
177
|
+
function: fn
|
|
178
|
+
});
|
|
179
|
+
expect(result).toEqual({});
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
describe("mixed resources", () => {
|
|
183
|
+
it("should handle mix of strings and resources", () => {
|
|
184
|
+
const postgres = {
|
|
185
|
+
type: ResourceType.Postgres,
|
|
186
|
+
database: "app_db",
|
|
187
|
+
host: "db.example.com",
|
|
188
|
+
password: "db-pass",
|
|
189
|
+
port: 5432,
|
|
190
|
+
username: "app_user"
|
|
191
|
+
};
|
|
192
|
+
const secret = {
|
|
193
|
+
type: ResourceType.Secret,
|
|
194
|
+
value: "jwt-secret"
|
|
195
|
+
};
|
|
196
|
+
const bucket = {
|
|
197
|
+
type: ResourceType.Bucket,
|
|
198
|
+
name: "uploads-bucket"
|
|
199
|
+
};
|
|
200
|
+
const result = normalizeResourceEnv({
|
|
201
|
+
nodeEnv: "production",
|
|
202
|
+
appName: "My App",
|
|
203
|
+
database: postgres,
|
|
204
|
+
jwtSecret: secret,
|
|
205
|
+
uploads: bucket,
|
|
206
|
+
apiVersion: "v2"
|
|
207
|
+
});
|
|
208
|
+
expect(result).toEqual({
|
|
209
|
+
NODE_ENV: "production",
|
|
210
|
+
APP_NAME: "My App",
|
|
211
|
+
DATABASE_NAME: "app_db",
|
|
212
|
+
DATABASE_HOST: "db.example.com",
|
|
213
|
+
DATABASE_PASSWORD: "db-pass",
|
|
214
|
+
DATABASE_PORT: 5432,
|
|
215
|
+
DATABASE_USERNAME: "app_user",
|
|
216
|
+
JWT_SECRET: "jwt-secret",
|
|
217
|
+
UPLOADS_NAME: "uploads-bucket",
|
|
218
|
+
API_VERSION: "v2"
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
describe("edge cases", () => {
|
|
223
|
+
it("should warn for unknown resource types", () => {
|
|
224
|
+
const consoleWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
225
|
+
const unknownResource = {
|
|
226
|
+
type: "unknown.resource.Type",
|
|
227
|
+
value: "something"
|
|
228
|
+
};
|
|
229
|
+
const result = normalizeResourceEnv({ unknown: unknownResource });
|
|
230
|
+
expect(result).toEqual({});
|
|
231
|
+
expect(consoleWarnSpy).toHaveBeenCalledWith("No processor found for resource type: ", { value: unknownResource });
|
|
232
|
+
consoleWarnSpy.mockRestore();
|
|
233
|
+
});
|
|
234
|
+
it("should handle resources with special characters in keys", () => {
|
|
235
|
+
const secret = {
|
|
236
|
+
type: ResourceType.Secret,
|
|
237
|
+
value: "value"
|
|
238
|
+
};
|
|
239
|
+
const result = normalizeResourceEnv({
|
|
240
|
+
"my-secret-key": secret,
|
|
241
|
+
"another.secret": secret,
|
|
242
|
+
"secret@123": secret
|
|
243
|
+
});
|
|
244
|
+
expect(result).toEqual({
|
|
245
|
+
MY_SECRET_KEY: "value",
|
|
246
|
+
ANOTHER_SECRET: "value",
|
|
247
|
+
SECRET123: "value"
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
it("should handle numeric values in postgres port", () => {
|
|
251
|
+
const postgres = {
|
|
252
|
+
type: ResourceType.Postgres,
|
|
253
|
+
database: "test",
|
|
254
|
+
host: "localhost",
|
|
255
|
+
password: "pass",
|
|
256
|
+
port: 5432,
|
|
257
|
+
username: "user"
|
|
258
|
+
};
|
|
259
|
+
const result = normalizeResourceEnv({ db: postgres });
|
|
260
|
+
expect(result.DB_PORT).toBe(5432);
|
|
261
|
+
expect(typeof result.DB_PORT).toBe("number");
|
|
262
|
+
});
|
|
263
|
+
it("should handle very long keys", () => {
|
|
264
|
+
const secret = {
|
|
265
|
+
type: ResourceType.Secret,
|
|
266
|
+
value: "value"
|
|
267
|
+
};
|
|
268
|
+
const result = normalizeResourceEnv({ thisIsAVeryLongKeyNameThatShouldBeConvertedProperly: secret });
|
|
269
|
+
expect(result).toEqual({ THIS_IS_A_VERY_LONG_KEY_NAME_THAT_SHOULD_BE_CONVERTED_PROPERLY: "value" });
|
|
270
|
+
});
|
|
271
|
+
it("should handle multiple underscores and numbers", () => {
|
|
272
|
+
const bucket = {
|
|
273
|
+
type: ResourceType.Bucket,
|
|
274
|
+
name: "test-bucket"
|
|
275
|
+
};
|
|
276
|
+
const result = normalizeResourceEnv({
|
|
277
|
+
"s3_bucket_v2_1": bucket,
|
|
278
|
+
"bucket_123_456": bucket
|
|
279
|
+
});
|
|
280
|
+
expect(result).toEqual({
|
|
281
|
+
S3_BUCKET_V21_NAME: "test-bucket",
|
|
282
|
+
BUCKET123456_NAME: "test-bucket"
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
describe("ResourceType enum", () => {
|
|
288
|
+
it("should have all expected resource types", () => {
|
|
289
|
+
expect(ResourceType.ApiGatewayV2).toBe("sst.aws.ApiGatewayV2");
|
|
290
|
+
expect(ResourceType.Postgres).toBe("sst.aws.Postgres");
|
|
291
|
+
expect(ResourceType.Function).toBe("sst.aws.Function");
|
|
292
|
+
expect(ResourceType.Bucket).toBe("sst.aws.Bucket");
|
|
293
|
+
expect(ResourceType.Vpc).toBe("sst.aws.Vpc");
|
|
294
|
+
expect(ResourceType.Secret).toBe("sst.sst.Secret");
|
|
295
|
+
expect(ResourceType.SSTSecret).toBe("sst:sst:Secret");
|
|
296
|
+
expect(ResourceType.SSTFunction).toBe("sst:sst:Function");
|
|
297
|
+
expect(ResourceType.SSTApiGatewayV2).toBe("sst:aws:ApiGatewayV2");
|
|
298
|
+
expect(ResourceType.SSTPostgres).toBe("sst:aws:Postgres");
|
|
299
|
+
expect(ResourceType.SSTBucket).toBe("sst:aws:Bucket");
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
//#endregion
|
package/dist/index.cjs
CHANGED
package/dist/index.d.cts
ADDED
package/dist/index.d.mts
ADDED
package/dist/index.mjs
CHANGED