@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekmidas/envkit",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -18,6 +18,11 @@
18
18
  "types": "./dist/SnifferEnvironmentParser.d.ts",
19
19
  "import": "./dist/SnifferEnvironmentParser.mjs",
20
20
  "require": "./dist/SnifferEnvironmentParser.cjs"
21
+ },
22
+ "./credentials": {
23
+ "types": "./dist/credentials.d.ts",
24
+ "import": "./dist/credentials.mjs",
25
+ "require": "./dist/credentials.cjs"
21
26
  }
22
27
  },
23
28
  "repository": {
@@ -12,11 +12,11 @@ import snakecase from 'lodash.snakecase';
12
12
  * environmentCase('apiV2') // 'APIV2'
13
13
  */
14
14
  export function environmentCase(name: string): string {
15
- return snakecase(name)
16
- .toUpperCase()
17
- .replace(/_\d+/g, (r) => {
18
- return r.replace('_', '');
19
- });
15
+ return snakecase(name)
16
+ .toUpperCase()
17
+ .replace(/_\d+/g, (r) => {
18
+ return r.replace('_', '');
19
+ });
20
20
  }
21
21
 
22
22
  /**
@@ -24,7 +24,7 @@ export function environmentCase(name: string): string {
24
24
  * Values can be primitives or nested records.
25
25
  */
26
26
  export interface EnvRecord {
27
- [key: string]: EnvValue;
27
+ [key: string]: EnvValue;
28
28
  }
29
29
 
30
30
  /**
@@ -52,11 +52,11 @@ export type Resolvers = Record<string, EnvironmentResolver<any>>;
52
52
  * Options for configuring the EnvironmentBuilder.
53
53
  */
54
54
  export interface EnvironmentBuilderOptions {
55
- /**
56
- * Handler called when a value's type doesn't match any registered resolver.
57
- * Defaults to console.warn.
58
- */
59
- onUnmatchedValue?: (key: string, value: unknown) => void;
55
+ /**
56
+ * Handler called when a value's type doesn't match any registered resolver.
57
+ * Defaults to console.warn.
58
+ */
59
+ onUnmatchedValue?: (key: string, value: unknown) => void;
60
60
  }
61
61
 
62
62
  /**
@@ -68,8 +68,8 @@ export type InputValue = string | { type: string; [key: string]: unknown };
68
68
  * Base type for typed input values with a specific type discriminator.
69
69
  */
70
70
  export type TypedInputValue<TType extends string = string> = {
71
- type: TType;
72
- [key: string]: unknown;
71
+ type: TType;
72
+ [key: string]: unknown;
73
73
  };
74
74
 
75
75
  /**
@@ -86,19 +86,19 @@ type OmitType<T> = T extends { type: string } ? Omit<T, 'type'> : never;
86
86
  * Extracts all unique `type` values from a record (excluding plain strings).
87
87
  */
88
88
  type AllTypeValues<TRecord extends Record<string, InputValue>> = {
89
- [K in keyof TRecord]: ExtractType<TRecord[K]>;
89
+ [K in keyof TRecord]: ExtractType<TRecord[K]>;
90
90
  }[keyof TRecord];
91
91
 
92
92
  /**
93
93
  * For a given type value, finds the corresponding value type (without `type` key).
94
94
  */
95
95
  type ValueForType<
96
- TRecord extends Record<string, InputValue>,
97
- TType extends string,
96
+ TRecord extends Record<string, InputValue>,
97
+ TType extends string,
98
98
  > = {
99
- [K in keyof TRecord]: TRecord[K] extends { type: TType }
100
- ? OmitType<TRecord[K]>
101
- : never;
99
+ [K in keyof TRecord]: TRecord[K] extends { type: TType }
100
+ ? OmitType<TRecord[K]>
101
+ : never;
102
102
  }[keyof TRecord];
103
103
 
104
104
  /**
@@ -106,9 +106,9 @@ type ValueForType<
106
106
  * Keys are the `type` values, values are resolver functions receiving the value without `type`.
107
107
  */
108
108
  export type TypedResolvers<TRecord extends Record<string, InputValue>> = {
109
- [TType in AllTypeValues<TRecord>]: EnvironmentResolver<
110
- ValueForType<TRecord, TType>
111
- >;
109
+ [TType in AllTypeValues<TRecord>]: EnvironmentResolver<
110
+ ValueForType<TRecord, TType>
111
+ >;
112
112
  };
113
113
 
114
114
  /**
@@ -134,63 +134,59 @@ export type TypedResolvers<TRecord extends Record<string, InputValue>> = {
134
134
  * ```
135
135
  */
136
136
  export class EnvironmentBuilder<
137
- TRecord extends Record<string, InputValue> = Record<string, InputValue>,
138
- TResolvers extends Resolvers = TypedResolvers<TRecord>,
137
+ TRecord extends Record<string, InputValue> = Record<string, InputValue>,
138
+ TResolvers extends Resolvers = TypedResolvers<TRecord>,
139
139
  > {
140
- private readonly record: TRecord;
141
- private readonly resolvers: TResolvers;
142
- private readonly options: Required<EnvironmentBuilderOptions>;
143
-
144
- constructor(
145
- record: TRecord,
146
- resolvers: TResolvers,
147
- options: EnvironmentBuilderOptions = {},
148
- ) {
149
- this.record = record;
150
- this.resolvers = resolvers;
151
- this.options = {
152
- onUnmatchedValue:
153
- options.onUnmatchedValue ??
154
- ((key, value) => {
155
- console.warn(`No resolver found for key "${key}":`, { value });
156
- }),
157
- };
158
- }
159
-
160
- /**
161
- * Build environment variables from the input record.
162
- *
163
- * - Plain string values are passed through with key transformation
164
- * - Object values with a `type` property are matched against resolvers
165
- * - Resolvers receive values without the `type` key
166
- * - Only root-level keys are transformed to UPPER_SNAKE_CASE
167
- *
168
- * @returns A record of environment variables
169
- */
170
- build(): EnvRecord {
171
- const env: EnvRecord = {};
172
-
173
- for (const [key, value] of Object.entries(this.record)) {
174
- // Handle plain string values
175
- if (typeof value === 'string') {
176
- env[environmentCase(key)] = value;
177
- continue;
178
- }
179
-
180
- // Handle objects with type discriminator
181
- const { type, ...rest } = value;
182
- const resolver = this.resolvers[type];
183
- if (resolver) {
184
- const resolved = resolver(key, rest);
185
- // Transform only root-level keys from resolver output
186
- for (const [resolvedKey, resolvedValue] of Object.entries(resolved)) {
187
- env[environmentCase(resolvedKey)] = resolvedValue;
188
- }
189
- } else {
190
- this.options.onUnmatchedValue(key, value);
191
- }
192
- }
193
-
194
- return env;
195
- }
140
+ private readonly record: TRecord;
141
+ private readonly resolvers: TResolvers;
142
+ private readonly options: Required<EnvironmentBuilderOptions>;
143
+
144
+ constructor(
145
+ record: TRecord,
146
+ resolvers: TResolvers,
147
+ options: EnvironmentBuilderOptions = {},
148
+ ) {
149
+ this.record = record;
150
+ this.resolvers = resolvers;
151
+ this.options = {
152
+ onUnmatchedValue: options.onUnmatchedValue ?? ((_key, _value) => {}),
153
+ };
154
+ }
155
+
156
+ /**
157
+ * Build environment variables from the input record.
158
+ *
159
+ * - Plain string values are passed through with key transformation
160
+ * - Object values with a `type` property are matched against resolvers
161
+ * - Resolvers receive values without the `type` key
162
+ * - Only root-level keys are transformed to UPPER_SNAKE_CASE
163
+ *
164
+ * @returns A record of environment variables
165
+ */
166
+ build(): EnvRecord {
167
+ const env: EnvRecord = {};
168
+
169
+ for (const [key, value] of Object.entries(this.record)) {
170
+ // Handle plain string values
171
+ if (typeof value === 'string') {
172
+ env[environmentCase(key)] = value;
173
+ continue;
174
+ }
175
+
176
+ // Handle objects with type discriminator
177
+ const { type, ...rest } = value;
178
+ const resolver = this.resolvers[type];
179
+ if (resolver) {
180
+ const resolved = resolver(key, rest);
181
+ // Transform only root-level keys from resolver output
182
+ for (const [resolvedKey, resolvedValue] of Object.entries(resolved)) {
183
+ env[environmentCase(resolvedKey)] = resolvedValue;
184
+ }
185
+ } else {
186
+ this.options.onUnmatchedValue(key, value);
187
+ }
188
+ }
189
+
190
+ return env;
191
+ }
196
192
  }