@geekmidas/envkit 0.2.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,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
EnvironmentBuilder,
|
|
3
|
+
type EnvironmentBuilderOptions,
|
|
4
|
+
type EnvironmentResolver,
|
|
5
|
+
type EnvRecord,
|
|
6
|
+
type InputValue,
|
|
7
|
+
type Resolvers,
|
|
8
8
|
} from './EnvironmentBuilder';
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -12,21 +12,21 @@ import {
|
|
|
12
12
|
* Used to identify and process different AWS and SST resources.
|
|
13
13
|
*/
|
|
14
14
|
export enum ResourceType {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
// Legacy format (dot notation)
|
|
16
|
+
ApiGatewayV2 = 'sst.aws.ApiGatewayV2',
|
|
17
|
+
Postgres = 'sst.aws.Postgres',
|
|
18
|
+
Function = 'sst.aws.Function',
|
|
19
|
+
Bucket = 'sst.aws.Bucket',
|
|
20
|
+
Vpc = 'sst.aws.Vpc',
|
|
21
|
+
Secret = 'sst.sst.Secret',
|
|
22
|
+
|
|
23
|
+
// Modern format (colon notation)
|
|
24
|
+
SSTSecret = 'sst:sst:Secret',
|
|
25
|
+
SSTFunction = 'sst:sst:Function',
|
|
26
|
+
SSTApiGatewayV2 = 'sst:aws:ApiGatewayV2',
|
|
27
|
+
SSTPostgres = 'sst:aws:Postgres',
|
|
28
|
+
SSTBucket = 'sst:aws:Bucket',
|
|
29
|
+
SnsTopic = 'sst:aws:SnsTopic',
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
@@ -34,8 +34,8 @@ export enum ResourceType {
|
|
|
34
34
|
* Represents an HTTP/WebSocket API.
|
|
35
35
|
*/
|
|
36
36
|
export type ApiGatewayV2 = {
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
type: ResourceType.ApiGatewayV2 | ResourceType.SSTApiGatewayV2;
|
|
38
|
+
url: string;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
/**
|
|
@@ -43,65 +43,65 @@ export type ApiGatewayV2 = {
|
|
|
43
43
|
* Contains all connection details needed to connect to the database.
|
|
44
44
|
*/
|
|
45
45
|
export type Postgres = {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
type: ResourceType.Postgres | ResourceType.SSTPostgres;
|
|
47
|
+
database: string;
|
|
48
|
+
host: string;
|
|
49
|
+
password: string;
|
|
50
|
+
port: number;
|
|
51
|
+
username: string;
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
55
|
* AWS Lambda Function resource type.
|
|
56
56
|
*/
|
|
57
57
|
export type Function = {
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
type: ResourceType.Function | ResourceType.SSTFunction;
|
|
59
|
+
name: string;
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* AWS S3 Bucket resource type.
|
|
64
64
|
*/
|
|
65
65
|
export type Bucket = {
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
type: ResourceType.Bucket | ResourceType.SSTBucket;
|
|
67
|
+
name: string;
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* AWS VPC (Virtual Private Cloud) resource type.
|
|
72
72
|
*/
|
|
73
73
|
export type Vpc = {
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
type: ResourceType.Vpc;
|
|
75
|
+
bastion: string;
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
79
|
* Secret resource type for storing sensitive values.
|
|
80
80
|
*/
|
|
81
81
|
export type Secret = {
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
type: ResourceType.Secret | ResourceType.SSTSecret;
|
|
83
|
+
value: string;
|
|
84
84
|
};
|
|
85
85
|
|
|
86
86
|
/**
|
|
87
87
|
* AWS SNS Topic resource type.
|
|
88
88
|
*/
|
|
89
89
|
export type SnsTopic = {
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
type: ResourceType.SnsTopic;
|
|
91
|
+
arn: string;
|
|
92
92
|
};
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
95
|
* Union type of all supported SST resource types.
|
|
96
96
|
*/
|
|
97
97
|
export type SstResource =
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
98
|
+
| ApiGatewayV2
|
|
99
|
+
| Postgres
|
|
100
|
+
| Function
|
|
101
|
+
| Bucket
|
|
102
|
+
| Vpc
|
|
103
|
+
| Secret
|
|
104
|
+
| SnsTopic;
|
|
105
105
|
|
|
106
106
|
// Value types without the `type` key (for resolver parameters)
|
|
107
107
|
type SecretValue = Omit<Secret, 'type'>;
|
|
@@ -122,23 +122,23 @@ export type ResourceProcessor<K> = (name: string, value: K) => EnvRecord;
|
|
|
122
122
|
// SST Resource Resolvers (receive values without `type` key)
|
|
123
123
|
|
|
124
124
|
const secretResolver = (name: string, value: SecretValue) => ({
|
|
125
|
-
|
|
125
|
+
[name]: value.value,
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
const postgresResolver = (key: string, value: PostgresValue) => ({
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
129
|
+
[`${key}Name`]: value.database,
|
|
130
|
+
[`${key}Host`]: value.host,
|
|
131
|
+
[`${key}Password`]: value.password,
|
|
132
|
+
[`${key}Port`]: value.port,
|
|
133
|
+
[`${key}Username`]: value.username,
|
|
134
134
|
});
|
|
135
135
|
|
|
136
136
|
const bucketResolver = (name: string, value: BucketValue) => ({
|
|
137
|
-
|
|
137
|
+
[`${name}Name`]: value.name,
|
|
138
138
|
});
|
|
139
139
|
|
|
140
140
|
const topicResolver = (name: string, value: SnsTopicValue) => ({
|
|
141
|
-
|
|
141
|
+
[`${name}Arn`]: value.arn,
|
|
142
142
|
});
|
|
143
143
|
|
|
144
144
|
const noopResolver = () => ({});
|
|
@@ -147,21 +147,21 @@ const noopResolver = () => ({});
|
|
|
147
147
|
* Pre-configured resolvers for all SST resource types.
|
|
148
148
|
*/
|
|
149
149
|
export const sstResolvers: Resolvers = {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
150
|
+
// Legacy format
|
|
151
|
+
[ResourceType.ApiGatewayV2]: noopResolver,
|
|
152
|
+
[ResourceType.Function]: noopResolver,
|
|
153
|
+
[ResourceType.Vpc]: noopResolver,
|
|
154
|
+
[ResourceType.Secret]: secretResolver,
|
|
155
|
+
[ResourceType.Postgres]: postgresResolver,
|
|
156
|
+
[ResourceType.Bucket]: bucketResolver,
|
|
157
|
+
|
|
158
|
+
// Modern format
|
|
159
|
+
[ResourceType.SSTSecret]: secretResolver,
|
|
160
|
+
[ResourceType.SSTBucket]: bucketResolver,
|
|
161
|
+
[ResourceType.SSTFunction]: noopResolver,
|
|
162
|
+
[ResourceType.SSTPostgres]: postgresResolver,
|
|
163
|
+
[ResourceType.SSTApiGatewayV2]: noopResolver,
|
|
164
|
+
[ResourceType.SnsTopic]: topicResolver,
|
|
165
165
|
};
|
|
166
166
|
|
|
167
167
|
/**
|
|
@@ -183,40 +183,40 @@ type OmitType<T> = T extends { type: string } ? Omit<T, 'type'> : never;
|
|
|
183
183
|
* Extracts all unique `type` values from a record (excluding plain strings).
|
|
184
184
|
*/
|
|
185
185
|
type AllTypeValues<TRecord extends Record<string, InputValue>> = {
|
|
186
|
-
|
|
186
|
+
[K in keyof TRecord]: ExtractType<TRecord[K]>;
|
|
187
187
|
}[keyof TRecord];
|
|
188
188
|
|
|
189
189
|
/**
|
|
190
190
|
* Extracts only the custom (non-SST) type values from a record.
|
|
191
191
|
*/
|
|
192
192
|
type CustomTypeValues<TRecord extends Record<string, InputValue>> = Exclude<
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
AllTypeValues<TRecord>,
|
|
194
|
+
SstResourceTypeString
|
|
195
195
|
>;
|
|
196
196
|
|
|
197
197
|
/**
|
|
198
198
|
* For a given type value, finds the corresponding value type (without `type` key).
|
|
199
199
|
*/
|
|
200
200
|
type ValueForType<
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
TRecord extends Record<string, InputValue>,
|
|
202
|
+
TType extends string,
|
|
203
203
|
> = {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
204
|
+
[K in keyof TRecord]: TRecord[K] extends { type: TType }
|
|
205
|
+
? OmitType<TRecord[K]>
|
|
206
|
+
: never;
|
|
207
207
|
}[keyof TRecord];
|
|
208
208
|
|
|
209
209
|
/**
|
|
210
210
|
* Generates typed resolvers for custom (non-SST) types in the input record.
|
|
211
211
|
*/
|
|
212
212
|
type CustomResolvers<TRecord extends Record<string, InputValue>> =
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
213
|
+
CustomTypeValues<TRecord> extends never
|
|
214
|
+
? Resolvers | undefined
|
|
215
|
+
: {
|
|
216
|
+
[TType in CustomTypeValues<TRecord>]: EnvironmentResolver<
|
|
217
|
+
ValueForType<TRecord, TType>
|
|
218
|
+
>;
|
|
219
|
+
};
|
|
220
220
|
|
|
221
221
|
/**
|
|
222
222
|
* SST-specific environment builder with built-in resolvers for all known
|
|
@@ -248,51 +248,51 @@ type CustomResolvers<TRecord extends Record<string, InputValue>> =
|
|
|
248
248
|
* ```
|
|
249
249
|
*/
|
|
250
250
|
export class SstEnvironmentBuilder<
|
|
251
|
-
|
|
251
|
+
TRecord extends Record<string, SstResource | InputValue | string>,
|
|
252
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
|
-
|
|
253
|
+
private readonly builder: EnvironmentBuilder<
|
|
254
|
+
Record<string, InputValue>,
|
|
255
|
+
Resolvers
|
|
256
|
+
>;
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Create a new SST environment builder.
|
|
260
|
+
*
|
|
261
|
+
* @param record - Object containing SST resources, custom resources, and/or string values
|
|
262
|
+
* @param additionalResolvers - Optional custom resolvers (typed based on custom types in record)
|
|
263
|
+
* @param options - Optional configuration options
|
|
264
|
+
*/
|
|
265
|
+
constructor(
|
|
266
|
+
record: TRecord,
|
|
267
|
+
additionalResolvers?: CustomResolvers<TRecord>,
|
|
268
|
+
options?: EnvironmentBuilderOptions,
|
|
269
|
+
) {
|
|
270
|
+
// Merge resolvers with custom ones taking precedence
|
|
271
|
+
const mergedResolvers: Resolvers = additionalResolvers
|
|
272
|
+
? { ...sstResolvers, ...additionalResolvers }
|
|
273
|
+
: sstResolvers;
|
|
274
|
+
|
|
275
|
+
this.builder = new EnvironmentBuilder(
|
|
276
|
+
record as Record<string, InputValue>,
|
|
277
|
+
mergedResolvers,
|
|
278
|
+
options,
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Build environment variables from the input record.
|
|
284
|
+
*
|
|
285
|
+
* @returns A record of environment variables
|
|
286
|
+
*/
|
|
287
|
+
build(): EnvRecord {
|
|
288
|
+
return this.builder.build();
|
|
289
|
+
}
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
-
// Re-export useful types
|
|
293
|
-
export { environmentCase } from './EnvironmentBuilder';
|
|
294
292
|
export type {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
293
|
+
EnvironmentBuilderOptions,
|
|
294
|
+
EnvRecord,
|
|
295
|
+
EnvValue,
|
|
298
296
|
} from './EnvironmentBuilder';
|
|
297
|
+
// Re-export useful types
|
|
298
|
+
export { environmentCase } from './EnvironmentBuilder';
|