sdk-environment 0.1.1 → 0.1.3
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/domain.objects/Environment.d.ts +5 -0
- package/dist/domain.objects/EnvironmentConfigSlug.d.ts +6 -0
- package/dist/domain.objects/EnvironmentConfigSlug.js +3 -0
- package/dist/domain.objects/EnvironmentConfigSlug.js.map +1 -0
- package/dist/domain.operations/getEnvironment/getEnvironment.d.ts +25 -29
- package/dist/domain.operations/getEnvironment/getEnvironment.js +129 -45
- package/dist/domain.operations/getEnvironment/getEnvironment.js.map +1 -1
- package/dist/domain.operations/parsers/commit/getEnvCommit.d.ts +5 -2
- package/dist/domain.operations/parsers/commit/getEnvCommit.js +1 -1
- package/dist/domain.operations/parsers/commit/getEnvCommitFromGit.d.ts +14 -3
- package/dist/domain.operations/parsers/commit/getEnvCommitFromGit.js +121 -36
- package/dist/domain.operations/parsers/commit/getEnvCommitFromGit.js.map +1 -1
- package/dist/domain.operations/parsers/config/getEnvConfig.d.ts +9 -0
- package/dist/domain.operations/parsers/config/getEnvConfig.js +16 -0
- package/dist/domain.operations/parsers/config/getEnvConfig.js.map +1 -0
- package/dist/domain.operations/parsers/config/getEnvConfigFromAccess.d.ts +7 -0
- package/dist/domain.operations/parsers/config/getEnvConfigFromAccess.js +14 -0
- package/dist/domain.operations/parsers/config/getEnvConfigFromAccess.js.map +1 -0
- package/dist/domain.operations/parsers/config/getEnvConfigFromEnvar.d.ts +6 -0
- package/dist/domain.operations/parsers/config/getEnvConfigFromEnvar.js +18 -0
- package/dist/domain.operations/parsers/config/getEnvConfigFromEnvar.js.map +1 -0
- package/dist/domain.operations/parsers/config/getEnvConfigFromNodeEnv.d.ts +8 -0
- package/dist/domain.operations/parsers/config/getEnvConfigFromNodeEnv.js +22 -0
- package/dist/domain.operations/parsers/config/getEnvConfigFromNodeEnv.js.map +1 -0
- package/dist/domain.operations/parsers/factories.d.ts +13 -3
- package/dist/domain.operations/parsers/factories.js +23 -5
- package/dist/domain.operations/parsers/factories.js.map +1 -1
- package/dist/domain.operations/validators/isEnvironmentAccessTier.d.ts +1 -0
- package/dist/domain.operations/validators/isEnvironmentAccessTier.js +7 -3
- package/dist/domain.operations/validators/isEnvironmentAccessTier.js.map +1 -1
- package/dist/domain.operations/validators/isEnvironmentConfigSlug.d.ts +6 -0
- package/dist/domain.operations/validators/isEnvironmentConfigSlug.js +27 -0
- package/dist/domain.operations/validators/isEnvironmentConfigSlug.js.map +1 -0
- package/dist/domain.operations/validators/isValidConfigForAccess.d.ts +10 -0
- package/dist/domain.operations/validators/isValidConfigForAccess.js +20 -0
- package/dist/domain.operations/validators/isValidConfigForAccess.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { EnvironmentAccessTier } from './EnvironmentAccessTier';
|
|
2
2
|
import type { EnvironmentCommitSlug } from './EnvironmentCommitSlug';
|
|
3
|
+
import type { EnvironmentConfigSlug } from './EnvironmentConfigSlug';
|
|
3
4
|
import type { EnvironmentServerTier } from './EnvironmentServerTier';
|
|
4
5
|
/**
|
|
5
6
|
* .what = the environment your code runs in
|
|
@@ -10,6 +11,10 @@ export interface Environment {
|
|
|
10
11
|
* which tier of resources this process can access
|
|
11
12
|
*/
|
|
12
13
|
access: EnvironmentAccessTier;
|
|
14
|
+
/**
|
|
15
|
+
* which config/secrets to load
|
|
16
|
+
*/
|
|
17
|
+
config: EnvironmentConfigSlug;
|
|
13
18
|
/**
|
|
14
19
|
* where this process executes
|
|
15
20
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnvironmentConfigSlug.js","sourceRoot":"","sources":["../../src/domain.objects/EnvironmentConfigSlug.ts"],"names":[],"mappings":""}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { type SimpleInMemoryCache } from 'simple-in-memory-cache';
|
|
1
2
|
import type { Environment } from '../../domain.objects/Environment';
|
|
2
3
|
import type { EnvironmentAccessTier } from '../../domain.objects/EnvironmentAccessTier';
|
|
3
4
|
import type { EnvironmentCommitSlug } from '../../domain.objects/EnvironmentCommitSlug';
|
|
5
|
+
import type { EnvironmentConfigSlug } from '../../domain.objects/EnvironmentConfigSlug';
|
|
4
6
|
import type { EnvironmentServerTier } from '../../domain.objects/EnvironmentServerTier';
|
|
5
7
|
/**
|
|
6
8
|
* .what = parser function type
|
|
@@ -14,45 +16,39 @@ export type AsyncParser<T> = () => T | null | Promise<T | null>;
|
|
|
14
16
|
*/
|
|
15
17
|
export type Parser<T> = () => T | null | Promise<T | null>;
|
|
16
18
|
/**
|
|
17
|
-
* .what =
|
|
18
|
-
* .why =
|
|
19
|
+
* .what = cached version of _filled
|
|
20
|
+
* .why = avoid repeated parser invocations
|
|
21
|
+
* .note = callers can supply their own cache via input
|
|
19
22
|
*/
|
|
20
|
-
|
|
23
|
+
declare const filled: (input?: {
|
|
21
24
|
parsers?: {
|
|
22
|
-
access?: AsyncParser<EnvironmentAccessTier>[];
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
access?: AsyncParser<EnvironmentAccessTier>[] | null;
|
|
26
|
+
config?: ((access: EnvironmentAccessTier) => SyncParser<EnvironmentConfigSlug>[]) | null;
|
|
27
|
+
server?: AsyncParser<EnvironmentServerTier>[] | null;
|
|
28
|
+
commit?: AsyncParser<EnvironmentCommitSlug>[] | null;
|
|
29
|
+
} | null;
|
|
30
|
+
cache?: SimpleInMemoryCache<Promise<Environment>> | 'skip' | null;
|
|
31
|
+
} | null) => Promise<Environment>;
|
|
28
32
|
/**
|
|
29
|
-
* .what =
|
|
30
|
-
* .why =
|
|
33
|
+
* .what = cached version of _staticEnv
|
|
34
|
+
* .why = avoid repeated parser invocations
|
|
35
|
+
* .note = callers can supply their own cache via input
|
|
31
36
|
*/
|
|
32
|
-
|
|
37
|
+
declare const staticEnv: (input?: {
|
|
33
38
|
parsers?: {
|
|
34
|
-
access?: SyncParser<EnvironmentAccessTier>[];
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
* .what = async environment parser - runs all parsers with aws and git
|
|
42
|
-
* .why = complete environment detection with full parser chain
|
|
43
|
-
*/
|
|
44
|
-
declare const filled: (input?: GetEnvironmentInput) => Promise<Environment>;
|
|
45
|
-
/**
|
|
46
|
-
* .what = sync environment parser - skips async parsers
|
|
47
|
-
* .why = sync access without await for contexts that need it
|
|
48
|
-
*/
|
|
49
|
-
declare const staticEnv: (input?: GetEnvironmentStaticInput) => Environment;
|
|
39
|
+
access?: SyncParser<EnvironmentAccessTier>[] | null;
|
|
40
|
+
config?: ((access: EnvironmentAccessTier) => SyncParser<EnvironmentConfigSlug>[]) | null;
|
|
41
|
+
server?: SyncParser<EnvironmentServerTier>[] | null;
|
|
42
|
+
commit?: SyncParser<EnvironmentCommitSlug>[] | null;
|
|
43
|
+
} | null;
|
|
44
|
+
cache?: SimpleInMemoryCache<Environment> | 'skip' | null;
|
|
45
|
+
} | null) => Environment;
|
|
50
46
|
/**
|
|
51
47
|
* .what = get environment - callable directly or via .filled()/.static()
|
|
52
48
|
* .why = main entry point for sdk-environment
|
|
53
49
|
*/
|
|
54
50
|
interface GetEnvironment {
|
|
55
|
-
(input?:
|
|
51
|
+
(input?: Parameters<typeof filled>[0]): Promise<Environment>;
|
|
56
52
|
filled: typeof filled;
|
|
57
53
|
static: typeof staticEnv;
|
|
58
54
|
}
|
|
@@ -2,12 +2,35 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getEnvironment = void 0;
|
|
4
4
|
const helpful_errors_1 = require("helpful-errors");
|
|
5
|
+
const simple_in_memory_cache_1 = require("simple-in-memory-cache");
|
|
6
|
+
const with_simple_cache_1 = require("with-simple-cache");
|
|
5
7
|
const getEnvAccess_1 = require("../parsers/access/getEnvAccess");
|
|
6
8
|
const getEnvCommit_1 = require("../parsers/commit/getEnvCommit");
|
|
9
|
+
const getEnvConfig_1 = require("../parsers/config/getEnvConfig");
|
|
7
10
|
const getEnvServer_1 = require("../parsers/server/getEnvServer");
|
|
8
11
|
const isEnvironmentAccessTier_1 = require("../validators/isEnvironmentAccessTier");
|
|
9
12
|
const isEnvironmentCommitSlug_1 = require("../validators/isEnvironmentCommitSlug");
|
|
13
|
+
const isEnvironmentConfigSlug_1 = require("../validators/isEnvironmentConfigSlug");
|
|
10
14
|
const isEnvironmentServerTier_1 = require("../validators/isEnvironmentServerTier");
|
|
15
|
+
const isValidConfigForAccess_1 = require("../validators/isValidConfigForAccess");
|
|
16
|
+
/**
|
|
17
|
+
* .what = compute display name for a parser function
|
|
18
|
+
* .why = use function.name if available, fallback to index-based name
|
|
19
|
+
*/
|
|
20
|
+
const computeParserName = (input) => input.parser.name || `parser[${input.index}]`;
|
|
21
|
+
/**
|
|
22
|
+
* .what = pair parsers with their display names
|
|
23
|
+
* .why = enables iteration without positional array access
|
|
24
|
+
*/
|
|
25
|
+
const asParsersNamed = (parsers) => parsers.map((parser, index) => ({
|
|
26
|
+
parser,
|
|
27
|
+
name: computeParserName({ parser, index }),
|
|
28
|
+
}));
|
|
29
|
+
/**
|
|
30
|
+
* .what = extract names from named parsers
|
|
31
|
+
* .why = format parser names for error messages
|
|
32
|
+
*/
|
|
33
|
+
const asParserNames = (parsers) => parsers.map((p) => p.name);
|
|
11
34
|
// default parsers
|
|
12
35
|
const DEFAULT_ACCESS_PARSERS = [
|
|
13
36
|
getEnvAccess_1.getEnvAccess.fromEnvar,
|
|
@@ -25,6 +48,15 @@ const DEFAULT_COMMIT_PARSERS = [
|
|
|
25
48
|
getEnvCommit_1.getEnvCommit.fromEnvar,
|
|
26
49
|
getEnvCommit_1.getEnvCommit.fromGit,
|
|
27
50
|
];
|
|
51
|
+
/**
|
|
52
|
+
* .what = default config parsers factory
|
|
53
|
+
* .why = config parsers depend on access tier
|
|
54
|
+
*/
|
|
55
|
+
const DEFAULT_CONFIG_PARSERS = (access) => [
|
|
56
|
+
getEnvConfig_1.getEnvConfig.fromEnvar,
|
|
57
|
+
getEnvConfig_1.getEnvConfig.fromNodeEnv(access),
|
|
58
|
+
getEnvConfig_1.getEnvConfig.fromAccess(access),
|
|
59
|
+
];
|
|
28
60
|
// sync-only default parsers (skip async)
|
|
29
61
|
const DEFAULT_ACCESS_PARSERS_SYNC = [
|
|
30
62
|
getEnvAccess_1.getEnvAccess.fromEnvar,
|
|
@@ -32,86 +64,138 @@ const DEFAULT_ACCESS_PARSERS_SYNC = [
|
|
|
32
64
|
];
|
|
33
65
|
const DEFAULT_COMMIT_PARSERS_SYNC = [
|
|
34
66
|
getEnvCommit_1.getEnvCommit.fromEnvar,
|
|
67
|
+
getEnvCommit_1.getEnvCommit.fromGit.sync,
|
|
35
68
|
];
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
69
|
+
/**
|
|
70
|
+
* .what = module-level default caches for environment results
|
|
71
|
+
* .why = avoid repeated parser invocations within same process
|
|
72
|
+
* callers can supply their own cache to override
|
|
73
|
+
*/
|
|
74
|
+
const defaultFilledCache = (0, simple_in_memory_cache_1.createCache)();
|
|
75
|
+
const defaultStaticCache = (0, simple_in_memory_cache_1.createCache)();
|
|
76
|
+
/**
|
|
77
|
+
* .what = create cache that skips reads but writes to target
|
|
78
|
+
* .why = used when callers pass 'skip' to bypass cache lookup
|
|
79
|
+
* but still populate cache for subsequent calls
|
|
80
|
+
*/
|
|
81
|
+
const createCacheSkipRead = (target) => ({
|
|
82
|
+
get: () => undefined,
|
|
83
|
+
set: (key, value) => target.set(key, value),
|
|
84
|
+
});
|
|
39
85
|
/**
|
|
40
86
|
* .what = run parser chain until first non-null result
|
|
41
87
|
* .why = first-wins precedence
|
|
42
88
|
*/
|
|
43
|
-
const
|
|
44
|
-
for (
|
|
45
|
-
const parser = parsers[i];
|
|
89
|
+
const getOneFromParsersAsync = async (parsers, validate, attributeName) => {
|
|
90
|
+
for (const { parser, name } of parsers) {
|
|
46
91
|
const result = await parser();
|
|
47
92
|
if (result !== null) {
|
|
48
93
|
if (!validate(result)) {
|
|
49
|
-
throw new helpful_errors_1.BadRequestError(`invalid ${attributeName} value: ${JSON.stringify(result)}. parser: ${
|
|
94
|
+
throw new helpful_errors_1.BadRequestError(`invalid ${attributeName} value: ${JSON.stringify(result)}. parser: ${name}`);
|
|
50
95
|
}
|
|
51
96
|
return result;
|
|
52
97
|
}
|
|
53
98
|
}
|
|
54
|
-
throw new helpful_errors_1.UnexpectedCodePathError(`could not derive ${attributeName}. tried parsers: ${
|
|
99
|
+
throw new helpful_errors_1.UnexpectedCodePathError(`could not derive ${attributeName}. tried parsers: ${asParserNames(parsers).join(', ')}`);
|
|
55
100
|
};
|
|
56
101
|
/**
|
|
57
102
|
* .what = run sync parser chain until first non-null result
|
|
58
103
|
* .why = first-wins precedence, sync only
|
|
59
104
|
*/
|
|
60
|
-
const
|
|
61
|
-
for (
|
|
62
|
-
const parser = parsers[i];
|
|
105
|
+
const getOneFromParsersSync = (parsers, validate, attributeName) => {
|
|
106
|
+
for (const { parser, name } of parsers) {
|
|
63
107
|
const result = parser();
|
|
64
108
|
if (result !== null) {
|
|
65
109
|
if (!validate(result)) {
|
|
66
|
-
throw new helpful_errors_1.BadRequestError(`invalid ${attributeName} value: ${JSON.stringify(result)}. parser: ${
|
|
110
|
+
throw new helpful_errors_1.BadRequestError(`invalid ${attributeName} value: ${JSON.stringify(result)}. parser: ${name}`);
|
|
67
111
|
}
|
|
68
112
|
return result;
|
|
69
113
|
}
|
|
70
114
|
}
|
|
71
|
-
throw new helpful_errors_1.UnexpectedCodePathError(`could not derive ${attributeName}. tried parsers: ${
|
|
115
|
+
throw new helpful_errors_1.UnexpectedCodePathError(`could not derive ${attributeName}. tried parsers: ${asParserNames(parsers).join(', ')}`);
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* .what = internal async environment parser
|
|
119
|
+
* .why = separated to enable cache wrapper
|
|
120
|
+
*/
|
|
121
|
+
const computeFilledEnvironment = async (input) => {
|
|
122
|
+
const access = await getOneFromParsersAsync(asParsersNamed(input.accessParsers), isEnvironmentAccessTier_1.isEnvironmentAccessTier, 'access');
|
|
123
|
+
// config depends on access
|
|
124
|
+
const configParsers = input.configParsersFactory(access);
|
|
125
|
+
const config = getOneFromParsersSync(asParsersNamed(configParsers), isEnvironmentConfigSlug_1.isEnvironmentConfigSlug, 'config');
|
|
126
|
+
(0, isValidConfigForAccess_1.isValidConfigForAccess)({ config, access });
|
|
127
|
+
const server = await getOneFromParsersAsync(asParsersNamed(input.serverParsers), isEnvironmentServerTier_1.isEnvironmentServerTier, 'server');
|
|
128
|
+
const commit = await getOneFromParsersAsync(asParsersNamed(input.commitParsers), isEnvironmentCommitSlug_1.isEnvironmentCommitSlug, 'commit');
|
|
129
|
+
return { access, config, server, commit };
|
|
72
130
|
};
|
|
73
131
|
/**
|
|
74
132
|
* .what = async environment parser - runs all parsers with aws and git
|
|
75
133
|
* .why = complete environment detection with full parser chain
|
|
76
134
|
*/
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
135
|
+
const _filled = async (input) => {
|
|
136
|
+
const parsersConfig = {
|
|
137
|
+
accessParsers: input?.parsers?.access ?? DEFAULT_ACCESS_PARSERS,
|
|
138
|
+
configParsersFactory: input?.parsers?.config ?? DEFAULT_CONFIG_PARSERS,
|
|
139
|
+
serverParsers: input?.parsers?.server ?? DEFAULT_SERVER_PARSERS,
|
|
140
|
+
commitParsers: input?.parsers?.commit ?? DEFAULT_COMMIT_PARSERS,
|
|
141
|
+
};
|
|
142
|
+
return computeFilledEnvironment(parsersConfig);
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* .what = cached version of _filled
|
|
146
|
+
* .why = avoid repeated parser invocations
|
|
147
|
+
* .note = callers can supply their own cache via input
|
|
148
|
+
*/
|
|
149
|
+
const filled = (0, with_simple_cache_1.withSimpleCache)(_filled, {
|
|
150
|
+
cache: ({ fromInput }) => {
|
|
151
|
+
const inputCache = fromInput[0]?.cache;
|
|
152
|
+
if (inputCache === 'skip')
|
|
153
|
+
return createCacheSkipRead(defaultFilledCache);
|
|
154
|
+
return inputCache ?? defaultFilledCache;
|
|
155
|
+
},
|
|
156
|
+
serialize: { key: () => 'filled' },
|
|
157
|
+
});
|
|
158
|
+
/**
|
|
159
|
+
* .what = internal sync environment parser
|
|
160
|
+
* .why = separated to enable cache wrapper
|
|
161
|
+
*/
|
|
162
|
+
const computeStaticEnvironment = (input) => {
|
|
163
|
+
const access = getOneFromParsersSync(asParsersNamed(input.accessParsers), isEnvironmentAccessTier_1.isEnvironmentAccessTier, 'access');
|
|
164
|
+
// config depends on access
|
|
165
|
+
const configParsers = input.configParsersFactory(access);
|
|
166
|
+
const config = getOneFromParsersSync(asParsersNamed(configParsers), isEnvironmentConfigSlug_1.isEnvironmentConfigSlug, 'config');
|
|
167
|
+
(0, isValidConfigForAccess_1.isValidConfigForAccess)({ config, access });
|
|
168
|
+
const server = getOneFromParsersSync(asParsersNamed(input.serverParsers), isEnvironmentServerTier_1.isEnvironmentServerTier, 'server');
|
|
169
|
+
const commit = getOneFromParsersSync(asParsersNamed(input.commitParsers), isEnvironmentCommitSlug_1.isEnvironmentCommitSlug, 'commit');
|
|
170
|
+
return { access, config, server, commit };
|
|
93
171
|
};
|
|
94
172
|
/**
|
|
95
173
|
* .what = sync environment parser - skips async parsers
|
|
96
174
|
* .why = sync access without await for contexts that need it
|
|
97
175
|
*/
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const serverParserNames = serverParsers.map((p, i) => p.name || `parser[${i}]`);
|
|
107
|
-
const commitParserNames = commitParsers.map((p, i) => p.name || `parser[${i}]`);
|
|
108
|
-
const access = runParsersSync(accessParsers, accessParserNames, isEnvironmentAccessTier_1.isEnvironmentAccessTier, 'access');
|
|
109
|
-
const server = runParsersSync(serverParsers, serverParserNames, isEnvironmentServerTier_1.isEnvironmentServerTier, 'server');
|
|
110
|
-
const commit = runParsersSync(commitParsers, commitParserNames, isEnvironmentCommitSlug_1.isEnvironmentCommitSlug, 'commit');
|
|
111
|
-
const environment = { access, server, commit };
|
|
112
|
-
staticCache = environment;
|
|
113
|
-
return environment;
|
|
176
|
+
const _staticEnv = (input) => {
|
|
177
|
+
const parsersConfig = {
|
|
178
|
+
accessParsers: input?.parsers?.access ?? DEFAULT_ACCESS_PARSERS_SYNC,
|
|
179
|
+
configParsersFactory: input?.parsers?.config ?? DEFAULT_CONFIG_PARSERS,
|
|
180
|
+
serverParsers: input?.parsers?.server ?? DEFAULT_SERVER_PARSERS,
|
|
181
|
+
commitParsers: input?.parsers?.commit ?? DEFAULT_COMMIT_PARSERS_SYNC,
|
|
182
|
+
};
|
|
183
|
+
return computeStaticEnvironment(parsersConfig);
|
|
114
184
|
};
|
|
185
|
+
/**
|
|
186
|
+
* .what = cached version of _staticEnv
|
|
187
|
+
* .why = avoid repeated parser invocations
|
|
188
|
+
* .note = callers can supply their own cache via input
|
|
189
|
+
*/
|
|
190
|
+
const staticEnv = (0, with_simple_cache_1.withSimpleCache)(_staticEnv, {
|
|
191
|
+
cache: ({ fromInput }) => {
|
|
192
|
+
const inputCache = fromInput[0]?.cache;
|
|
193
|
+
if (inputCache === 'skip')
|
|
194
|
+
return createCacheSkipRead(defaultStaticCache);
|
|
195
|
+
return inputCache ?? defaultStaticCache;
|
|
196
|
+
},
|
|
197
|
+
serialize: { key: () => 'static' },
|
|
198
|
+
});
|
|
115
199
|
const getEnvironmentFn = Object.assign(
|
|
116
200
|
// direct call delegates to filled
|
|
117
201
|
(input) => filled(input), {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEnvironment.js","sourceRoot":"","sources":["../../../src/domain.operations/getEnvironment/getEnvironment.ts"],"names":[],"mappings":";;;AAAA,mDAA0E;
|
|
1
|
+
{"version":3,"file":"getEnvironment.js","sourceRoot":"","sources":["../../../src/domain.operations/getEnvironment/getEnvironment.ts"],"names":[],"mappings":";;;AAAA,mDAA0E;AAC1E,mEAA+E;AAC/E,yDAAoD;AAOpD,iEAA8D;AAC9D,iEAA8D;AAC9D,iEAA8D;AAC9D,iEAA8D;AAC9D,mFAAgF;AAChF,mFAAgF;AAChF,mFAAgF;AAChF,mFAAgF;AAChF,iFAA8E;AAe9E;;;GAGG;AACH,MAAM,iBAAiB,GAAG,CAAC,KAG1B,EAAU,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,IAAI,UAAU,KAAK,CAAC,KAAK,GAAG,CAAC;AAE5D;;;GAGG;AACH,MAAM,cAAc,GAAG,CACrB,OAAuB,EACmB,EAAE,CAC5C,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;IAC9B,MAAM;IACN,IAAI,EAAE,iBAAiB,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;CAC3C,CAAC,CAAC,CAAC;AAEN;;;GAGG;AACH,MAAM,aAAa,GAAG,CACpB,OAAiD,EACvC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAE1C,kBAAkB;AAClB,MAAM,sBAAsB,GAAyC;IACnE,2BAAY,CAAC,SAAS;IACtB,2BAAY,CAAC,mBAAmB;IAChC,2BAAY,CAAC,kBAAkB;IAC/B,2BAAY,CAAC,WAAW;CACzB,CAAC;AAEF,MAAM,sBAAsB,GAAwC;IAClE,2BAAY,CAAC,SAAS;IACtB,2BAAY,CAAC,kBA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,CAAC;AACjD,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,SAAS,GAAG,IAAA,mCAAe,EAAC,UAAU,EAAE;IAC5C,KAAK,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE;QACvB,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC;QACvC,IAAI,UAAU,KAAK,MAAM;YAAE,OAAO,mBAAmB,CAAC,kBAAkB,CAAC,CAAC;QAC1E,OAAO,UAAU,IAAI,kBAAkB,CAAC;IAC1C,CAAC;IACD,SAAS,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE;CACnC,CAAC,CAAC;AAYH,MAAM,gBAAgB,GAAmB,MAAM,CAAC,MAAM;AACpD,kCAAkC;AAClC,CAAC,KAAoC,EAAwB,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAC7E;IACE;;OAEG;IACH,MAAM;IAEN;;OAEG;IACH,MAAM,EAAE,SAAS;CAClB,CACF,CAAC;AAEW,QAAA,cAAc,GAAG,gBAAgB,CAAC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* .what = namespace for commit slug parsers
|
|
3
|
-
* .why = enables dot notation: getEnvCommit.fromEnvar()
|
|
3
|
+
* .why = enables dot notation: getEnvCommit.fromEnvar(), getEnvCommit.fromGit.sync()
|
|
4
4
|
*/
|
|
5
5
|
export declare const getEnvCommit: {
|
|
6
6
|
fromEnvar: () => string | null;
|
|
7
|
-
fromGit: () => Promise<string | null
|
|
7
|
+
fromGit: (() => Promise<string | null>) & {
|
|
8
|
+
sync: () => string | null;
|
|
9
|
+
async: () => Promise<string | null>;
|
|
10
|
+
};
|
|
8
11
|
};
|
|
@@ -5,7 +5,7 @@ const getEnvCommitFromEnvar_1 = require("./getEnvCommitFromEnvar");
|
|
|
5
5
|
const getEnvCommitFromGit_1 = require("./getEnvCommitFromGit");
|
|
6
6
|
/**
|
|
7
7
|
* .what = namespace for commit slug parsers
|
|
8
|
-
* .why = enables dot notation: getEnvCommit.fromEnvar()
|
|
8
|
+
* .why = enables dot notation: getEnvCommit.fromEnvar(), getEnvCommit.fromGit.sync()
|
|
9
9
|
*/
|
|
10
10
|
exports.getEnvCommit = {
|
|
11
11
|
fromEnvar: getEnvCommitFromEnvar_1.getEnvCommitFromEnvar,
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import type { EnvironmentCommitSlug } from '../../../domain.objects/EnvironmentCommitSlug';
|
|
2
2
|
/**
|
|
3
|
-
* .what =
|
|
4
|
-
* .why =
|
|
3
|
+
* .what = check if error is expected git failure
|
|
4
|
+
* .why = enables reuse in both sync and async variants
|
|
5
|
+
*
|
|
6
|
+
* .note = expected errors: not a repo, no tag, command not found, etc.
|
|
5
7
|
*/
|
|
6
|
-
export declare const
|
|
8
|
+
export declare const isExpectedGitError: (error: unknown) => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* .what = getEnvCommitFromGit with .sync and .async methods
|
|
11
|
+
* .why = enables symmetric API: fromGit(), fromGit.sync(), fromGit.async()
|
|
12
|
+
*/
|
|
13
|
+
declare const getEnvCommitFromGitWithMethods: (() => Promise<EnvironmentCommitSlug | null>) & {
|
|
14
|
+
sync: () => EnvironmentCommitSlug | null;
|
|
15
|
+
async: () => Promise<EnvironmentCommitSlug | null>;
|
|
16
|
+
};
|
|
17
|
+
export { getEnvCommitFromGitWithMethods as getEnvCommitFromGit };
|
|
@@ -1,60 +1,115 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getEnvCommitFromGit = void 0;
|
|
3
|
+
exports.getEnvCommitFromGit = exports.isExpectedGitError = void 0;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
5
6
|
const util_1 = require("util");
|
|
6
|
-
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
7
7
|
/**
|
|
8
|
-
* .what =
|
|
8
|
+
* .what = default exec implementations
|
|
9
|
+
* .why = enables dependency injection for testability with sensible defaults
|
|
10
|
+
*/
|
|
11
|
+
const defaultExecAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
12
|
+
const defaultExecSync = child_process_1.execSync;
|
|
13
|
+
/**
|
|
14
|
+
* .what = check if error is expected git failure
|
|
15
|
+
* .why = enables reuse in both sync and async variants
|
|
16
|
+
*
|
|
17
|
+
* .note = expected errors: not a repo, no tag, command not found, etc.
|
|
18
|
+
*/
|
|
19
|
+
const isExpectedGitError = (error) => {
|
|
20
|
+
// extract message from error (handles both Error instances and error-like objects)
|
|
21
|
+
const errorMessage = error instanceof Error
|
|
22
|
+
? error.message
|
|
23
|
+
: typeof error === 'object' &&
|
|
24
|
+
error !== null &&
|
|
25
|
+
'message' in error &&
|
|
26
|
+
typeof error.message === 'string'
|
|
27
|
+
? error.message
|
|
28
|
+
: String(error);
|
|
29
|
+
const message = errorMessage.toLowerCase();
|
|
30
|
+
// check for git-specific errors
|
|
31
|
+
const isGitError = message.includes('not a git repository') ||
|
|
32
|
+
message.includes('fatal:') ||
|
|
33
|
+
message.includes('command not found') ||
|
|
34
|
+
message.includes('enoent');
|
|
35
|
+
// check for generic command failure (exit code non-zero)
|
|
36
|
+
// this is expected for commands like `git describe --exact-match` when no tag exists
|
|
37
|
+
const isCommandFailure = message.includes('command failed') && message.includes('git');
|
|
38
|
+
return isGitError || isCommandFailure;
|
|
39
|
+
};
|
|
40
|
+
exports.isExpectedGitError = isExpectedGitError;
|
|
41
|
+
/**
|
|
42
|
+
* .what = run git command async and return stdout
|
|
9
43
|
* .why = abstracts shell exec for git commands
|
|
10
44
|
*
|
|
11
45
|
* .note = returns null only for expected git failures (not a repo, no tag, etc.)
|
|
12
46
|
* rethrows unexpected errors
|
|
13
47
|
*/
|
|
14
|
-
const runGit = async (command) => {
|
|
48
|
+
const runGit = async (command, execFn = defaultExecAsync) => {
|
|
15
49
|
try {
|
|
16
|
-
const { stdout } = await
|
|
50
|
+
const { stdout } = await execFn(command);
|
|
17
51
|
return stdout.trim();
|
|
18
52
|
}
|
|
19
53
|
catch (error) {
|
|
20
54
|
// allowlist: expected git/exec failures return null
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
55
|
+
if ((0, exports.isExpectedGitError)(error))
|
|
56
|
+
return null;
|
|
57
|
+
// wrap unexpected errors with context
|
|
58
|
+
throw new helpful_errors_1.UnexpectedCodePathError('unexpected git command error', {
|
|
59
|
+
command,
|
|
60
|
+
error: error instanceof Error ? error.message : String(error),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* .what = run git command sync and return stdout
|
|
66
|
+
* .why = enables sync commit resolver for static() contexts
|
|
67
|
+
*
|
|
68
|
+
* .note = returns null only for expected git failures (not a repo, no tag, etc.)
|
|
69
|
+
* rethrows unexpected errors
|
|
70
|
+
*/
|
|
71
|
+
const runGitSync = (command, execFn = defaultExecSync) => {
|
|
72
|
+
try {
|
|
73
|
+
const stdout = execFn(command, { encoding: 'utf8' });
|
|
74
|
+
return stdout.trim();
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
// allowlist: expected git/exec failures return null
|
|
78
|
+
if ((0, exports.isExpectedGitError)(error))
|
|
41
79
|
return null;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
80
|
+
// wrap unexpected errors with context
|
|
81
|
+
throw new helpful_errors_1.UnexpectedCodePathError('unexpected git command error', {
|
|
82
|
+
command,
|
|
83
|
+
error: error instanceof Error ? error.message : String(error),
|
|
84
|
+
});
|
|
45
85
|
}
|
|
46
86
|
};
|
|
87
|
+
/**
|
|
88
|
+
* .what = pick git ref from tag or branch
|
|
89
|
+
* .why = tag takes precedence over branch for commit slug
|
|
90
|
+
*/
|
|
91
|
+
const computeGitRef = (input) => input.tag ?? input.branch ?? null;
|
|
92
|
+
/**
|
|
93
|
+
* .what = determine if working tree has uncommitted changes
|
|
94
|
+
* .why = dirty state affects commit slug format
|
|
95
|
+
*/
|
|
96
|
+
const computeIsDirty = (input) => input.status !== null && input.status.length > 0;
|
|
97
|
+
/**
|
|
98
|
+
* .what = format commit slug from ref, hash, and dirty state
|
|
99
|
+
* .why = consistent format: '$gitref@$hash' or '$gitref@$hash+' if dirty
|
|
100
|
+
*/
|
|
101
|
+
const computeCommitSlug = (input) => `${input.ref}@${input.hash}${input.dirty ? '+' : ''}`;
|
|
47
102
|
/**
|
|
48
103
|
* .what = parse commit slug from git repository
|
|
49
104
|
* .why = format: '$gitref@$hash' or '$gitref@$hash+' if dirty
|
|
50
105
|
*/
|
|
51
|
-
const
|
|
106
|
+
const _getEnvCommitFromGit = async () => {
|
|
52
107
|
// get exact tag (if HEAD is tagged)
|
|
53
108
|
const tag = await runGit('git describe --tags --exact-match 2>/dev/null');
|
|
54
109
|
// get branch name (fallback if no tag)
|
|
55
110
|
const branch = await runGit('git rev-parse --abbrev-ref HEAD 2>/dev/null');
|
|
56
|
-
//
|
|
57
|
-
const ref = tag
|
|
111
|
+
// pick ref (tag or branch)
|
|
112
|
+
const ref = computeGitRef({ tag, branch });
|
|
58
113
|
if (!ref)
|
|
59
114
|
return null;
|
|
60
115
|
// get short hash
|
|
@@ -63,10 +118,40 @@ const getEnvCommitFromGit = async () => {
|
|
|
63
118
|
return null;
|
|
64
119
|
// check if dirty
|
|
65
120
|
const status = await runGit('git status --porcelain 2>/dev/null');
|
|
66
|
-
const dirty =
|
|
67
|
-
// format
|
|
68
|
-
|
|
69
|
-
|
|
121
|
+
const dirty = computeIsDirty({ status });
|
|
122
|
+
// format slug
|
|
123
|
+
return computeCommitSlug({ ref, hash, dirty });
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* .what = parse commit slug from git repository (sync)
|
|
127
|
+
* .why = format: '$gitref@$hash' or '$gitref@$hash+' if dirty
|
|
128
|
+
*/
|
|
129
|
+
const getEnvCommitFromGitSync = () => {
|
|
130
|
+
// get exact tag (if HEAD is tagged)
|
|
131
|
+
const tag = runGitSync('git describe --tags --exact-match 2>/dev/null');
|
|
132
|
+
// get branch name (fallback if no tag)
|
|
133
|
+
const branch = runGitSync('git rev-parse --abbrev-ref HEAD 2>/dev/null');
|
|
134
|
+
// pick ref (tag or branch)
|
|
135
|
+
const ref = computeGitRef({ tag, branch });
|
|
136
|
+
if (!ref)
|
|
137
|
+
return null;
|
|
138
|
+
// get short hash
|
|
139
|
+
const hash = runGitSync('git rev-parse --short HEAD 2>/dev/null');
|
|
140
|
+
if (!hash)
|
|
141
|
+
return null;
|
|
142
|
+
// check if dirty
|
|
143
|
+
const status = runGitSync('git status --porcelain 2>/dev/null');
|
|
144
|
+
const dirty = computeIsDirty({ status });
|
|
145
|
+
// format slug
|
|
146
|
+
return computeCommitSlug({ ref, hash, dirty });
|
|
70
147
|
};
|
|
71
|
-
|
|
148
|
+
/**
|
|
149
|
+
* .what = getEnvCommitFromGit with .sync and .async methods
|
|
150
|
+
* .why = enables symmetric API: fromGit(), fromGit.sync(), fromGit.async()
|
|
151
|
+
*/
|
|
152
|
+
const getEnvCommitFromGitWithMethods = Object.assign(_getEnvCommitFromGit, {
|
|
153
|
+
sync: getEnvCommitFromGitSync,
|
|
154
|
+
async: _getEnvCommitFromGit,
|
|
155
|
+
});
|
|
156
|
+
exports.getEnvCommitFromGit = getEnvCommitFromGitWithMethods;
|
|
72
157
|
//# sourceMappingURL=getEnvCommitFromGit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEnvCommitFromGit.js","sourceRoot":"","sources":["../../../../src/domain.operations/parsers/commit/getEnvCommitFromGit.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"getEnvCommitFromGit.js","sourceRoot":"","sources":["../../../../src/domain.operations/parsers/commit/getEnvCommitFromGit.ts"],"names":[],"mappings":";;;AAAA,iDAA+C;AAC/C,mDAAyD;AACzD,+BAAiC;AAIjC;;;GAGG;AACH,MAAM,gBAAgB,GAAG,IAAA,gBAAS,EAAC,oBAAI,CAAC,CAAC;AACzC,MAAM,eAAe,GAAG,wBAAQ,CAAC;AAEjC;;;;;GAKG;AACI,MAAM,kBAAkB,GAAG,CAAC,KAAc,EAAW,EAAE;IAC5D,mFAAmF;IACnF,MAAM,YAAY,GAChB,KAAK,YAAY,KAAK;QACpB,CAAC,CAAC,KAAK,CAAC,OAAO;QACf,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ;YACvB,KAAK,KAAK,IAAI;YACd,SAAS,IAAI,KAAK;YAClB,OAAQ,KAA8B,CAAC,OAAO,KAAK,QAAQ;YAC7D,CAAC,CAAE,KAA6B,CAAC,OAAO;YACxC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,MAAM,OAAO,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC;IAE3C,gCAAgC;IAChC,MAAM,UAAU,GACd,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAC;QACxC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAC1B,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC;QACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAE7B,yDAAyD;IACzD,qFAAqF;IACrF,MAAM,gBAAgB,GACpB,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEhE,OAAO,UAAU,IAAI,gBAAgB,CAAC;AACxC,CAAC,CAAC;AA1BW,QAAA,kBAAkB,sBA0B7B;AAUF;;;;;;GAMG;AACH,MAAM,MAAM,G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U,CAAC,+CAA+C,CAAC,CAAC;IAExE,uCAAuC;IACvC,MAAM,MAAM,GAAG,UAAU,CAAC,6CAA6C,CAAC,CAAC;IAEzE,2BAA2B;IAC3B,MAAM,GAAG,GAAG,aAAa,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3C,IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAC;IAEtB,iBAAiB;IACjB,MAAM,IAAI,GAAG,UAAU,CAAC,wCAAwC,CAAC,CAAC;IAClE,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IAEvB,iBAAiB;IACjB,MAAM,MAAM,GAAG,UAAU,CAAC,oCAAoC,CAAC,CAAC;IAChE,MAAM,KAAK,GAAG,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IAEzC,cAAc;IACd,OAAO,iBAAiB,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AACjD,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,8BAA8B,GAAG,MAAM,CAAC,MAAM,CAAC,oBAAoB,EAAE;IACzE,IAAI,EAAE,uBAAuB;IAC7B,KAAK,EAAE,oBAAoB;CAC5B,CAAC,CAAC;AAEwC,6DAAmB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = namespace for config parsers
|
|
3
|
+
* .why = enables getEnvConfig.fromEnvar, getEnvConfig.fromNodeEnv(access), etc.
|
|
4
|
+
*/
|
|
5
|
+
export declare const getEnvConfig: {
|
|
6
|
+
fromEnvar: () => `test${string}` | `prep${string}` | `prod${string}` | null;
|
|
7
|
+
fromNodeEnv: (access: import("../../..").EnvironmentAccessTier) => () => `test${string}` | `prep${string}` | `prod${string}` | null;
|
|
8
|
+
fromAccess: (access: import("../../..").EnvironmentAccessTier) => () => `test${string}` | `prep${string}` | `prod${string}`;
|
|
9
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEnvConfig = void 0;
|
|
4
|
+
const getEnvConfigFromAccess_1 = require("./getEnvConfigFromAccess");
|
|
5
|
+
const getEnvConfigFromEnvar_1 = require("./getEnvConfigFromEnvar");
|
|
6
|
+
const getEnvConfigFromNodeEnv_1 = require("./getEnvConfigFromNodeEnv");
|
|
7
|
+
/**
|
|
8
|
+
* .what = namespace for config parsers
|
|
9
|
+
* .why = enables getEnvConfig.fromEnvar, getEnvConfig.fromNodeEnv(access), etc.
|
|
10
|
+
*/
|
|
11
|
+
exports.getEnvConfig = {
|
|
12
|
+
fromEnvar: getEnvConfigFromEnvar_1.getEnvConfigFromEnvar,
|
|
13
|
+
fromNodeEnv: getEnvConfigFromNodeEnv_1.getEnvConfigFromNodeEnv,
|
|
14
|
+
fromAccess: getEnvConfigFromAccess_1.getEnvConfigFromAccess,
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=getEnvConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getEnvConfig.js","sourceRoot":"","sources":["../../../../src/domain.operations/parsers/config/getEnvConfig.ts"],"names":[],"mappings":";;;AAAA,qEAAkE;AAClE,mEAAgE;AAChE,uEAAoE;AAEpE;;;GAGG;AACU,QAAA,YAAY,GAAG;IAC1B,SAAS,EAAE,6CAAqB;IAChC,WAAW,EAAE,iDAAuB;IACpC,UAAU,EAAE,+CAAsB;CACnC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { EnvironmentAccessTier } from '../../../domain.objects/EnvironmentAccessTier';
|
|
2
|
+
import type { EnvironmentConfigSlug } from '../../../domain.objects/EnvironmentConfigSlug';
|
|
3
|
+
/**
|
|
4
|
+
* .what = factory to create default config parser from access
|
|
5
|
+
* .why = config defaults to access when no explicit signal
|
|
6
|
+
*/
|
|
7
|
+
export declare const getEnvConfigFromAccess: (access: EnvironmentAccessTier) => (() => EnvironmentConfigSlug);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEnvConfigFromAccess = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = factory to create default config parser from access
|
|
6
|
+
* .why = config defaults to access when no explicit signal
|
|
7
|
+
*/
|
|
8
|
+
const getEnvConfigFromAccess = (access) => {
|
|
9
|
+
const parser = () => access;
|
|
10
|
+
Object.defineProperty(parser, 'name', { value: 'fromAccess()' });
|
|
11
|
+
return parser;
|
|
12
|
+
};
|
|
13
|
+
exports.getEnvConfigFromAccess = getEnvConfigFromAccess;
|
|
14
|
+
//# sourceMappingURL=getEnvConfigFromAccess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getEnvConfigFromAccess.js","sourceRoot":"","sources":["../../../../src/domain.operations/parsers/config/getEnvConfigFromAccess.ts"],"names":[],"mappings":";;;AAGA;;;GAGG;AACI,MAAM,sBAAsB,GAAG,CACpC,MAA6B,EACE,EAAE;IACjC,MAAM,MAAM,GAAG,GAA0B,EAAE,CAAC,MAAM,CAAC;IACnD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC;IACjE,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AANW,QAAA,sBAAsB,0BAMjC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { EnvironmentConfigSlug } from '../../../domain.objects/EnvironmentConfigSlug';
|
|
2
|
+
/**
|
|
3
|
+
* .what = parse config from CONFIG environment variable
|
|
4
|
+
* .why = explicit config override
|
|
5
|
+
*/
|
|
6
|
+
export declare const getEnvConfigFromEnvar: () => EnvironmentConfigSlug | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEnvConfigFromEnvar = void 0;
|
|
4
|
+
const isEnvironmentConfigSlug_1 = require("../../validators/isEnvironmentConfigSlug");
|
|
5
|
+
/**
|
|
6
|
+
* .what = parse config from CONFIG environment variable
|
|
7
|
+
* .why = explicit config override
|
|
8
|
+
*/
|
|
9
|
+
const getEnvConfigFromEnvar = () => {
|
|
10
|
+
const value = process.env.CONFIG;
|
|
11
|
+
if (!value || value === '')
|
|
12
|
+
return null;
|
|
13
|
+
if (!(0, isEnvironmentConfigSlug_1.isEnvironmentConfigSlug)(value))
|
|
14
|
+
return null;
|
|
15
|
+
return value;
|
|
16
|
+
};
|
|
17
|
+
exports.getEnvConfigFromEnvar = getEnvConfigFromEnvar;
|
|
18
|
+
//# sourceMappingURL=getEnvConfigFromEnvar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getEnvConfigFromEnvar.js","sourceRoot":"","sources":["../../../../src/domain.operations/parsers/config/getEnvConfigFromEnvar.ts"],"names":[],"mappings":";;;AACA,sFAAmF;AAEnF;;;GAGG;AACI,MAAM,qBAAqB,GAAG,GAAiC,EAAE;IACtE,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC;IACjC,IAAI,CAAC,KAAK,IAAI,KAAK,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC;IACxC,IAAI,CAAC,IAAA,iDAAuB,EAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACjD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AALW,QAAA,qBAAqB,yBAKhC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { EnvironmentAccessTier } from '../../../domain.objects/EnvironmentAccessTier';
|
|
2
|
+
import type { EnvironmentConfigSlug } from '../../../domain.objects/EnvironmentConfigSlug';
|
|
3
|
+
/**
|
|
4
|
+
* .what = factory to create NODE_ENV parser for given access
|
|
5
|
+
* .why = NODE_ENV=test signals test config only for prep access.
|
|
6
|
+
* prod/test access ignore NODE_ENV (it's a signal, not an override).
|
|
7
|
+
*/
|
|
8
|
+
export declare const getEnvConfigFromNodeEnv: (access: EnvironmentAccessTier) => (() => EnvironmentConfigSlug | null);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEnvConfigFromNodeEnv = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = factory to create NODE_ENV parser for given access
|
|
6
|
+
* .why = NODE_ENV=test signals test config only for prep access.
|
|
7
|
+
* prod/test access ignore NODE_ENV (it's a signal, not an override).
|
|
8
|
+
*/
|
|
9
|
+
const getEnvConfigFromNodeEnv = (access) => {
|
|
10
|
+
const parser = () => {
|
|
11
|
+
// NODE_ENV only signals config for prep access
|
|
12
|
+
if (access !== 'prep')
|
|
13
|
+
return null;
|
|
14
|
+
if (process.env.NODE_ENV === 'test')
|
|
15
|
+
return 'test';
|
|
16
|
+
return null;
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(parser, 'name', { value: 'fromNodeEnv()' });
|
|
19
|
+
return parser;
|
|
20
|
+
};
|
|
21
|
+
exports.getEnvConfigFromNodeEnv = getEnvConfigFromNodeEnv;
|
|
22
|
+
//# sourceMappingURL=getEnvConfigFromNodeEnv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getEnvConfigFromNodeEnv.js","sourceRoot":"","sources":["../../../../src/domain.operations/parsers/config/getEnvConfigFromNodeEnv.ts"],"names":[],"mappings":";;;AAGA;;;;GAIG;AACI,MAAM,uBAAuB,GAAG,CACrC,MAA6B,EACS,EAAE;IACxC,MAAM,MAAM,GAAG,GAAiC,EAAE;QAChD,+CAA+C;QAC/C,IAAI,MAAM,KAAK,MAAM;YAAE,OAAO,IAAI,CAAC;QACnC,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM;YAAE,OAAO,MAAM,CAAC;QACnD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IACF,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC,CAAC;IAClE,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAXW,QAAA,uBAAuB,2BAWlC"}
|
|
@@ -38,7 +38,17 @@ export declare const fromCiEnvar: () => (() => EnvironmentServerTier | null);
|
|
|
38
38
|
*/
|
|
39
39
|
export declare const fromUnixDesktop: () => (() => EnvironmentServerTier | null);
|
|
40
40
|
/**
|
|
41
|
-
* .what = factory for fromGit parser
|
|
42
|
-
* .why =
|
|
41
|
+
* .what = factory for fromGit.async parser
|
|
42
|
+
* .why = returns async parser for filled() contexts
|
|
43
43
|
*/
|
|
44
|
-
|
|
44
|
+
declare const fromGitAsync: () => (() => Promise<EnvironmentCommitSlug | null>);
|
|
45
|
+
/**
|
|
46
|
+
* .what = factory for fromGit.sync parser
|
|
47
|
+
* .why = returns sync parser for static() contexts
|
|
48
|
+
*/
|
|
49
|
+
declare const fromGitSync: () => (() => EnvironmentCommitSlug | null);
|
|
50
|
+
export declare const fromGit: (() => (() => Promise<EnvironmentCommitSlug | null>)) & {
|
|
51
|
+
sync: typeof fromGitSync;
|
|
52
|
+
async: typeof fromGitAsync;
|
|
53
|
+
};
|
|
54
|
+
export {};
|
|
@@ -69,13 +69,31 @@ const fromUnixDesktop = () => {
|
|
|
69
69
|
};
|
|
70
70
|
exports.fromUnixDesktop = fromUnixDesktop;
|
|
71
71
|
/**
|
|
72
|
-
* .what = factory for fromGit parser
|
|
73
|
-
* .why =
|
|
72
|
+
* .what = factory for fromGit.async parser
|
|
73
|
+
* .why = returns async parser for filled() contexts
|
|
74
74
|
*/
|
|
75
|
-
const
|
|
75
|
+
const fromGitAsync = () => {
|
|
76
76
|
const parser = () => (0, getEnvCommitFromGit_1.getEnvCommitFromGit)();
|
|
77
|
-
Object.defineProperty(parser, 'name', { value: 'fromGit' });
|
|
77
|
+
Object.defineProperty(parser, 'name', { value: 'fromGit.async' });
|
|
78
78
|
return parser;
|
|
79
79
|
};
|
|
80
|
-
|
|
80
|
+
/**
|
|
81
|
+
* .what = factory for fromGit.sync parser
|
|
82
|
+
* .why = returns sync parser for static() contexts
|
|
83
|
+
*/
|
|
84
|
+
const fromGitSync = () => {
|
|
85
|
+
const parser = () => getEnvCommitFromGit_1.getEnvCommitFromGit.sync();
|
|
86
|
+
Object.defineProperty(parser, 'name', { value: 'fromGit.sync' });
|
|
87
|
+
return parser;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* .what = factory for fromGit parser with .sync() and .async() methods
|
|
91
|
+
* .why = README contract: fromGit() returns async parser (backwards compat)
|
|
92
|
+
* fromGit.sync() returns sync parser
|
|
93
|
+
* fromGit.async() returns async parser (explicit)
|
|
94
|
+
*/
|
|
95
|
+
const fromGitFactory = fromGitAsync;
|
|
96
|
+
fromGitFactory.sync = fromGitSync;
|
|
97
|
+
fromGitFactory.async = fromGitAsync;
|
|
98
|
+
exports.fromGit = fromGitFactory;
|
|
81
99
|
//# sourceMappingURL=factories.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factories.js","sourceRoot":"","sources":["../../../src/domain.operations/parsers/factories.ts"],"names":[],"mappings":";;;AAGA,8FAGkD;AAClD,4FAGiD;AACjD,8EAA2E;AAC3E,sEAAmE;AACnE,8EAA2E;AAC3E,4FAAyF;AACzF,sFAAmF;AAEnF;;;GAGG;AACI,MAAM,mBAAmB,GAAG,CAAC,KAEnC,EAAiD,EAAE;IAClD,MAAM,MAAM,GAAG,GAA0C,EAAE,CACzD,IAAA,iEAA+B,EAAC,KAAK,CAAC,CAAC;IACzC,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,qBAAqB,EAAE,CAAC,CAAC;IACxE,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAPW,QAAA,mBAAmB,uBAO9B;AAEF;;;GAGG;AACI,MA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AiC,EAAE,CAChD,IAAA,yDAA2B,GAAE,CAAC;IAChC,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC,CAAC;IACpE,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AALW,QAAA,eAAe,mBAK1B;AAEF;;;GAGG;
|
|
1
|
+
{"version":3,"file":"factories.js","sourceRoot":"","sources":["../../../src/domain.operations/parsers/factories.ts"],"names":[],"mappings":";;;AAGA,8FAGkD;AAClD,4FAGiD;AACjD,8EAA2E;AAC3E,sEAAmE;AACnE,8EAA2E;AAC3E,4FAAyF;AACzF,sFAAmF;AAEnF;;;GAGG;AACI,MAAM,mBAAmB,GAAG,CAAC,KAEnC,EAAiD,EAAE;IAClD,MAAM,MAAM,GAAG,GAA0C,EAAE,CACzD,IAAA,iEAA+B,EAAC,KAAK,CAAC,CAAC;IACzC,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,qBAAqB,EAAE,CAAC,CAAC;IACxE,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAPW,QAAA,mBAAmB,uBAO9B;AAEF;;;GAGG;AACI,MAAM,kBAAkB,GAAG,CAAC,KAElC,EAAiD,EAAE;IAClD,MAAM,MAAM,GAAG,GAA0C,EAAE,CACzD,IAAA,+DAA8B,EAAC,KAAK,CAAC,CAAC;IACxC,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,oBAAoB,EAAE,CAAC,CAAC;IACvE,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAPW,QAAA,kBAAkB,sBAO7B;AAEF;;;GAGG;AACI,MAAM,WAAW,GAAG,GAAyC,EAAE;IACpE,MAAM,MAAM,GAAG,GAAiC,EAAE,CAAC,IAAA,iDAAuB,GAAE,CAAC;IAC7E,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE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;GAGG;AACH,MAAM,WAAW,GAAG,GAAyC,EAAE;IAC7D,MAAM,MAAM,GAAG,GAAiC,EAAE,CAAC,yCAAmB,CAAC,IAAI,EAAE,CAAC;IAC9E,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC;IACjE,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,cAAc,GAAG,YAGtB,CAAC;AACF,cAAc,CAAC,IAAI,GAAG,WAAW,CAAC;AAClC,cAAc,CAAC,KAAK,GAAG,YAAY,CAAC;AAEvB,QAAA,OAAO,GAAG,cAAc,CAAC"}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isEnvironmentAccessTier = void 0;
|
|
4
|
-
|
|
3
|
+
exports.isEnvironmentAccessTier = exports.ACCESS_TIERS = void 0;
|
|
4
|
+
exports.ACCESS_TIERS = [
|
|
5
|
+
'test',
|
|
6
|
+
'prep',
|
|
7
|
+
'prod',
|
|
8
|
+
];
|
|
5
9
|
/**
|
|
6
10
|
* .what = type guard for EnvironmentAccessTier
|
|
7
11
|
* .why = validates parser output at runtime
|
|
8
12
|
*/
|
|
9
13
|
const isEnvironmentAccessTier = (value) => {
|
|
10
14
|
return (typeof value === 'string' &&
|
|
11
|
-
ACCESS_TIERS.includes(value));
|
|
15
|
+
exports.ACCESS_TIERS.includes(value));
|
|
12
16
|
};
|
|
13
17
|
exports.isEnvironmentAccessTier = isEnvironmentAccessTier;
|
|
14
18
|
//# sourceMappingURL=isEnvironmentAccessTier.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isEnvironmentAccessTier.js","sourceRoot":"","sources":["../../../src/domain.operations/validators/isEnvironmentAccessTier.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"isEnvironmentAccessTier.js","sourceRoot":"","sources":["../../../src/domain.operations/validators/isEnvironmentAccessTier.ts"],"names":[],"mappings":";;;AAEa,QAAA,YAAY,GAAqC;IAC5D,MAAM;IACN,MAAM;IACN,MAAM;CACP,CAAC;AAEF;;;GAGG;AACI,MAAM,uBAAuB,GAAG,CACrC,KAAc,EACkB,EAAE;IAClC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,oBAAY,CAAC,QAAQ,CAAC,KAA8B,CAAC,CACtD,CAAC;AACJ,CAAC,CAAC;AAPW,QAAA,uBAAuB,2BAOlC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = type guard for EnvironmentConfigSlug
|
|
3
|
+
* .why = validates config slug is exact tier or tier + non-alphanumeric suffix
|
|
4
|
+
* e.g., 'prod' valid, 'prod:v2023' valid, 'production' invalid
|
|
5
|
+
*/
|
|
6
|
+
export declare const isEnvironmentConfigSlug: (value: unknown) => value is `test${string}` | `prep${string}` | `prod${string}`;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEnvironmentConfigSlug = void 0;
|
|
4
|
+
const isEnvironmentAccessTier_1 = require("./isEnvironmentAccessTier");
|
|
5
|
+
/**
|
|
6
|
+
* .what = type guard for EnvironmentConfigSlug
|
|
7
|
+
* .why = validates config slug is exact tier or tier + non-alphanumeric suffix
|
|
8
|
+
* e.g., 'prod' valid, 'prod:v2023' valid, 'production' invalid
|
|
9
|
+
*/
|
|
10
|
+
const isEnvironmentConfigSlug = (value) => {
|
|
11
|
+
if (typeof value !== 'string')
|
|
12
|
+
return false;
|
|
13
|
+
for (const prefix of isEnvironmentAccessTier_1.ACCESS_TIERS) {
|
|
14
|
+
if (!value.startsWith(prefix))
|
|
15
|
+
continue;
|
|
16
|
+
// exact match
|
|
17
|
+
if (value === prefix)
|
|
18
|
+
return true;
|
|
19
|
+
// prefix + non-alphanumeric (e.g., 'prod:v2023', 'test:local')
|
|
20
|
+
const charAfterPrefix = value[prefix.length];
|
|
21
|
+
if (charAfterPrefix && !/[a-zA-Z0-9]/.test(charAfterPrefix))
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
};
|
|
26
|
+
exports.isEnvironmentConfigSlug = isEnvironmentConfigSlug;
|
|
27
|
+
//# sourceMappingURL=isEnvironmentConfigSlug.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isEnvironmentConfigSlug.js","sourceRoot":"","sources":["../../../src/domain.operations/validators/isEnvironmentConfigSlug.ts"],"names":[],"mappings":";;;AACA,uEAAyD;AAEzD;;;;GAIG;AACI,MAAM,uBAAuB,GAAG,CACrC,KAAc,EACkB,EAAE;IAClC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAE5C,KAAK,MAAM,MAAM,IAAI,sCAAY,EAAE,CAAC;QAClC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC;YAAE,SAAS;QAExC,cAAc;QACd,IAAI,KAAK,KAAK,MAAM;YAAE,OAAO,IAAI,CAAC;QAElC,+DAA+D;QAC/D,MAAM,eAAe,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC7C,IAAI,eAAe,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,eAAe,CAAC;YAAE,OAAO,IAAI,CAAC;IAC3E,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAjBW,QAAA,uBAAuB,2BAiBlC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { EnvironmentAccessTier } from '../../domain.objects/EnvironmentAccessTier';
|
|
2
|
+
import type { EnvironmentConfigSlug } from '../../domain.objects/EnvironmentConfigSlug';
|
|
3
|
+
/**
|
|
4
|
+
* .what = validate config matches access tier constraints
|
|
5
|
+
* .why = prod/test access force config to match. prep allows any config.
|
|
6
|
+
*/
|
|
7
|
+
export declare const isValidConfigForAccess: (input: {
|
|
8
|
+
config: EnvironmentConfigSlug;
|
|
9
|
+
access: EnvironmentAccessTier;
|
|
10
|
+
}) => boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidConfigForAccess = void 0;
|
|
4
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
5
|
+
/**
|
|
6
|
+
* .what = validate config matches access tier constraints
|
|
7
|
+
* .why = prod/test access force config to match. prep allows any config.
|
|
8
|
+
*/
|
|
9
|
+
const isValidConfigForAccess = (input) => {
|
|
10
|
+
// prep allows any config
|
|
11
|
+
if (input.access === 'prep')
|
|
12
|
+
return true;
|
|
13
|
+
// prod/test: config must start with access tier
|
|
14
|
+
if (!input.config.startsWith(input.access)) {
|
|
15
|
+
throw new helpful_errors_1.BadRequestError(`config must start with '${input.access}' when access is '${input.access}'. got: ${JSON.stringify(input.config)}`, { access: input.access, config: input.config });
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
};
|
|
19
|
+
exports.isValidConfigForAccess = isValidConfigForAccess;
|
|
20
|
+
//# sourceMappingURL=isValidConfigForAccess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isValidConfigForAccess.js","sourceRoot":"","sources":["../../../src/domain.operations/validators/isValidConfigForAccess.ts"],"names":[],"mappings":";;;AAAA,mDAAiD;AAKjD;;;GAGG;AACI,MAAM,sBAAsB,GAAG,CAAC,KAGtC,EAAW,EAAE;IACZ,yBAAyB;IACzB,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IAEzC,gDAAgD;IAChD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,gCAAe,CACvB,2BAA2B,KAAK,CAAC,MAAM,qBAAqB,KAAK,CAAC,MAAM,WAAW,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,EACjH,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAC/C,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAhBW,QAAA,sBAAsB,0BAgBjC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export type { Environment } from './domain.objects/Environment';
|
|
2
2
|
export type { EnvironmentAccessTier } from './domain.objects/EnvironmentAccessTier';
|
|
3
3
|
export type { EnvironmentCommitSlug } from './domain.objects/EnvironmentCommitSlug';
|
|
4
|
+
export type { EnvironmentConfigSlug } from './domain.objects/EnvironmentConfigSlug';
|
|
4
5
|
export type { EnvironmentServerTier } from './domain.objects/EnvironmentServerTier';
|
|
5
6
|
export type { AsyncParser, Parser, SyncParser, } from './domain.operations/getEnvironment/getEnvironment';
|
|
6
7
|
export { getEnvironment } from './domain.operations/getEnvironment/getEnvironment';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,aAAa;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,aAAa;;;AAcb,mBAAmB;AACnB,oFAAmF;AAA1E,gHAAA,cAAc,OAAA;AACvB,oCAAoC;AACpC,gFAA+E;AAAtE,4GAAA,YAAY,OAAA;AAIrB,gFAA+E;AAAtE,4GAAA,YAAY,OAAA;AACrB,mEAQ+C;AAP7C,gHAAA,mBAAmB,OAAA;AACnB,+GAAA,kBAAkB,OAAA;AAClB,wGAAA,WAAW,OAAA;AACX,oGAAA,OAAO,OAAA;AACP,+GAAA,kBAAkB,OAAA;AAClB,wGAAA,WAAW,OAAA;AACX,4GAAA,eAAe,OAAA;AAEjB,qCAAqC;AACrC,mEAAkE;AAAzD,sGAAA,SAAS,OAAA;AAClB,gFAA+E;AAAtE,4GAAA,YAAY,OAAA;AACrB,aAAa;AACb,kGAAiG;AAAxF,kIAAA,uBAAuB,OAAA;AAChC,kGAAiG;AAAxF,kIAAA,uBAAuB,OAAA;AAChC,kGAAiG;AAAxF,kIAAA,uBAAuB,OAAA"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "sdk-environment",
|
|
3
3
|
"author": "ehmpathy",
|
|
4
4
|
"description": "parse and expose the environment your code runs in",
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.3",
|
|
6
6
|
"repository": "ehmpathy/sdk-environment",
|
|
7
7
|
"homepage": "https://github.com/ehmpathy/sdk-environment",
|
|
8
8
|
"keywords": [
|
|
@@ -60,7 +60,9 @@
|
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"@aws-sdk/client-account": "3.1042.0",
|
|
63
|
-
"@aws-sdk/client-iam": "3.1042.0"
|
|
63
|
+
"@aws-sdk/client-iam": "3.1042.0",
|
|
64
|
+
"simple-in-memory-cache": "0.4.0",
|
|
65
|
+
"with-simple-cache": "0.15.3"
|
|
64
66
|
},
|
|
65
67
|
"devDependencies": {
|
|
66
68
|
"@biomejs/biome": "2.3.8",
|