@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,10 +1,10 @@
1
1
  import {
2
- type EnvRecord,
3
- EnvironmentBuilder,
4
- type EnvironmentBuilderOptions,
5
- type EnvironmentResolver,
6
- type InputValue,
7
- type Resolvers,
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
- // 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',
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
- type: ResourceType.ApiGatewayV2 | ResourceType.SSTApiGatewayV2;
38
- url: string;
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
- type: ResourceType.Postgres | ResourceType.SSTPostgres;
47
- database: string;
48
- host: string;
49
- password: string;
50
- port: number;
51
- username: string;
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
- type: ResourceType.Function | ResourceType.SSTFunction;
59
- name: string;
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
- type: ResourceType.Bucket | ResourceType.SSTBucket;
67
- name: string;
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
- type: ResourceType.Vpc;
75
- bastion: string;
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
- type: ResourceType.Secret | ResourceType.SSTSecret;
83
- value: string;
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
- type: ResourceType.SnsTopic;
91
- arn: string;
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
- | ApiGatewayV2
99
- | Postgres
100
- | Function
101
- | Bucket
102
- | Vpc
103
- | Secret
104
- | SnsTopic;
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
- [name]: value.value,
125
+ [name]: value.value,
126
126
  });
127
127
 
128
128
  const postgresResolver = (key: string, value: PostgresValue) => ({
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,
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
- [`${name}Name`]: value.name,
137
+ [`${name}Name`]: value.name,
138
138
  });
139
139
 
140
140
  const topicResolver = (name: string, value: SnsTopicValue) => ({
141
- [`${name}Arn`]: value.arn,
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
- // 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,
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
- [K in keyof TRecord]: ExtractType<TRecord[K]>;
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
- AllTypeValues<TRecord>,
194
- SstResourceTypeString
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
- TRecord extends Record<string, InputValue>,
202
- TType extends string,
201
+ TRecord extends Record<string, InputValue>,
202
+ TType extends string,
203
203
  > = {
204
- [K in keyof TRecord]: TRecord[K] extends { type: TType }
205
- ? OmitType<TRecord[K]>
206
- : never;
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
- CustomTypeValues<TRecord> extends never
214
- ? Resolvers | undefined
215
- : {
216
- [TType in CustomTypeValues<TRecord>]: EnvironmentResolver<
217
- ValueForType<TRecord, TType>
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
- TRecord extends Record<string, SstResource | InputValue | string>,
251
+ TRecord extends Record<string, SstResource | InputValue | string>,
252
252
  > {
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
- }
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
- EnvRecord,
296
- EnvValue,
297
- EnvironmentBuilderOptions,
293
+ EnvironmentBuilderOptions,
294
+ EnvRecord,
295
+ EnvValue,
298
296
  } from './EnvironmentBuilder';
297
+ // Re-export useful types
298
+ export { environmentCase } from './EnvironmentBuilder';