sdk-environment 0.0.0 → 0.1.1
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 +21 -0
- package/dist/domain.objects/Environment.js +3 -0
- package/dist/domain.objects/Environment.js.map +1 -0
- package/dist/domain.objects/EnvironmentAccessTier.d.ts +5 -0
- package/dist/domain.objects/EnvironmentAccessTier.js +3 -0
- package/dist/domain.objects/EnvironmentAccessTier.js.map +1 -0
- package/dist/domain.objects/EnvironmentCommitSlug.d.ts +10 -0
- package/dist/domain.objects/EnvironmentCommitSlug.js +3 -0
- package/dist/domain.objects/EnvironmentCommitSlug.js.map +1 -0
- package/dist/domain.objects/EnvironmentServerTier.d.ts +9 -0
- package/dist/domain.objects/EnvironmentServerTier.js +3 -0
- package/dist/domain.objects/EnvironmentServerTier.js.map +1 -0
- package/dist/domain.operations/getEnvironment/getEnvironment.d.ts +60 -0
- package/dist/domain.operations/getEnvironment/getEnvironment.js +128 -0
- package/dist/domain.operations/getEnvironment/getEnvironment.js.map +1 -0
- package/dist/domain.operations/parsers/access/getEnvAccess.d.ts +14 -0
- package/dist/domain.operations/parsers/access/getEnvAccess.js +18 -0
- package/dist/domain.operations/parsers/access/getEnvAccess.js.map +1 -0
- package/dist/domain.operations/parsers/access/getEnvAccessFromAwsAccountAlias.d.ts +19 -0
- package/dist/domain.operations/parsers/access/getEnvAccessFromAwsAccountAlias.js +92 -0
- package/dist/domain.operations/parsers/access/getEnvAccessFromAwsAccountAlias.js.map +1 -0
- package/dist/domain.operations/parsers/access/getEnvAccessFromAwsAccountName.d.ts +21 -0
- package/dist/domain.operations/parsers/access/getEnvAccessFromAwsAccountName.js +92 -0
- package/dist/domain.operations/parsers/access/getEnvAccessFromAwsAccountName.js.map +1 -0
- package/dist/domain.operations/parsers/access/getEnvAccessFromEnvar.d.ts +6 -0
- package/dist/domain.operations/parsers/access/getEnvAccessFromEnvar.js +18 -0
- package/dist/domain.operations/parsers/access/getEnvAccessFromEnvar.js.map +1 -0
- package/dist/domain.operations/parsers/access/getEnvAccessFromNodeEnv.d.ts +12 -0
- package/dist/domain.operations/parsers/access/getEnvAccessFromNodeEnv.js +23 -0
- package/dist/domain.operations/parsers/access/getEnvAccessFromNodeEnv.js.map +1 -0
- package/dist/domain.operations/parsers/commit/getEnvCommit.d.ts +8 -0
- package/dist/domain.operations/parsers/commit/getEnvCommit.js +14 -0
- package/dist/domain.operations/parsers/commit/getEnvCommit.js.map +1 -0
- package/dist/domain.operations/parsers/commit/getEnvCommitFromEnvar.d.ts +6 -0
- package/dist/domain.operations/parsers/commit/getEnvCommitFromEnvar.js +18 -0
- package/dist/domain.operations/parsers/commit/getEnvCommitFromEnvar.js.map +1 -0
- package/dist/domain.operations/parsers/commit/getEnvCommitFromGit.d.ts +6 -0
- package/dist/domain.operations/parsers/commit/getEnvCommitFromGit.js +72 -0
- package/dist/domain.operations/parsers/commit/getEnvCommitFromGit.js.map +1 -0
- package/dist/domain.operations/parsers/factories.d.ts +44 -0
- package/dist/domain.operations/parsers/factories.js +81 -0
- package/dist/domain.operations/parsers/factories.js.map +1 -0
- package/dist/domain.operations/parsers/fromEnvar.d.ts +5 -0
- package/dist/domain.operations/parsers/fromEnvar.js +19 -0
- package/dist/domain.operations/parsers/fromEnvar.js.map +1 -0
- package/dist/domain.operations/parsers/server/getEnvServer.d.ts +10 -0
- package/dist/domain.operations/parsers/server/getEnvServer.js +18 -0
- package/dist/domain.operations/parsers/server/getEnvServer.js.map +1 -0
- package/dist/domain.operations/parsers/server/getEnvServerFromCiEnvar.d.ts +6 -0
- package/dist/domain.operations/parsers/server/getEnvServerFromCiEnvar.js +15 -0
- package/dist/domain.operations/parsers/server/getEnvServerFromCiEnvar.js.map +1 -0
- package/dist/domain.operations/parsers/server/getEnvServerFromEnvar.d.ts +6 -0
- package/dist/domain.operations/parsers/server/getEnvServerFromEnvar.js +18 -0
- package/dist/domain.operations/parsers/server/getEnvServerFromEnvar.js.map +1 -0
- package/dist/domain.operations/parsers/server/getEnvServerFromLambdaTaskRoot.d.ts +6 -0
- package/dist/domain.operations/parsers/server/getEnvServerFromLambdaTaskRoot.js +15 -0
- package/dist/domain.operations/parsers/server/getEnvServerFromLambdaTaskRoot.js.map +1 -0
- package/dist/domain.operations/parsers/server/getEnvServerFromUnixDesktop.d.ts +6 -0
- package/dist/domain.operations/parsers/server/getEnvServerFromUnixDesktop.js +16 -0
- package/dist/domain.operations/parsers/server/getEnvServerFromUnixDesktop.js.map +1 -0
- package/dist/domain.operations/validators/isEnvironmentAccessTier.d.ts +6 -0
- package/dist/domain.operations/validators/isEnvironmentAccessTier.js +14 -0
- package/dist/domain.operations/validators/isEnvironmentAccessTier.js.map +1 -0
- package/dist/domain.operations/validators/isEnvironmentCommitSlug.d.ts +1 -0
- package/dist/domain.operations/validators/isEnvironmentCommitSlug.js +18 -0
- package/dist/domain.operations/validators/isEnvironmentCommitSlug.js.map +1 -0
- package/dist/domain.operations/validators/isEnvironmentServerTier.d.ts +10 -0
- package/dist/domain.operations/validators/isEnvironmentServerTier.js +17 -0
- package/dist/domain.operations/validators/isEnvironmentServerTier.js.map +1 -0
- package/dist/index.d.ts +16 -1
- package/dist/index.js +30 -2
- package/dist/index.js.map +1 -1
- package/package.json +44 -45
- package/readme.md +8 -7
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { EnvironmentAccessTier } from './EnvironmentAccessTier';
|
|
2
|
+
import type { EnvironmentCommitSlug } from './EnvironmentCommitSlug';
|
|
3
|
+
import type { EnvironmentServerTier } from './EnvironmentServerTier';
|
|
4
|
+
/**
|
|
5
|
+
* .what = the environment your code runs in
|
|
6
|
+
* .why = enables environment-aware behavior without env var soup
|
|
7
|
+
*/
|
|
8
|
+
export interface Environment {
|
|
9
|
+
/**
|
|
10
|
+
* which tier of resources this process can access
|
|
11
|
+
*/
|
|
12
|
+
access: EnvironmentAccessTier;
|
|
13
|
+
/**
|
|
14
|
+
* where this process executes
|
|
15
|
+
*/
|
|
16
|
+
server: EnvironmentServerTier;
|
|
17
|
+
/**
|
|
18
|
+
* what code this process runs
|
|
19
|
+
*/
|
|
20
|
+
commit: EnvironmentCommitSlug;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Environment.js","sourceRoot":"","sources":["../../src/domain.objects/Environment.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnvironmentAccessTier.js","sourceRoot":"","sources":["../../src/domain.objects/EnvironmentAccessTier.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = what code this process runs
|
|
3
|
+
* .why = enables traceability and debug
|
|
4
|
+
*
|
|
5
|
+
* format: `$gitref@$hash` or `$gitref@$hash+` if dirty
|
|
6
|
+
* - gitref: tag or branch name
|
|
7
|
+
* - hash: short commit hash
|
|
8
|
+
* - '+' suffix: uncommitted changes exist
|
|
9
|
+
*/
|
|
10
|
+
export type EnvironmentCommitSlug = string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnvironmentCommitSlug.js","sourceRoot":"","sources":["../../src/domain.objects/EnvironmentCommitSlug.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = where this process executes
|
|
3
|
+
* .why = enables server-specific behavior (log format, cache strategy, etc.)
|
|
4
|
+
*
|
|
5
|
+
* format: `$tier@$platform`
|
|
6
|
+
* - tier: 'local' | 'cloud'
|
|
7
|
+
* - platform: string (e.g., 'unix', 'cicd', 'aws.lambda')
|
|
8
|
+
*/
|
|
9
|
+
export type EnvironmentServerTier = `local@${string}` | `cloud@${string}`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnvironmentServerTier.js","sourceRoot":"","sources":["../../src/domain.objects/EnvironmentServerTier.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Environment } from '../../domain.objects/Environment';
|
|
2
|
+
import type { EnvironmentAccessTier } from '../../domain.objects/EnvironmentAccessTier';
|
|
3
|
+
import type { EnvironmentCommitSlug } from '../../domain.objects/EnvironmentCommitSlug';
|
|
4
|
+
import type { EnvironmentServerTier } from '../../domain.objects/EnvironmentServerTier';
|
|
5
|
+
/**
|
|
6
|
+
* .what = parser function type
|
|
7
|
+
* .why = enables custom parser configuration
|
|
8
|
+
*/
|
|
9
|
+
export type SyncParser<T> = () => T | null;
|
|
10
|
+
export type AsyncParser<T> = () => T | null | Promise<T | null>;
|
|
11
|
+
/**
|
|
12
|
+
* .what = union parser type for public API
|
|
13
|
+
* .why = matches README: type Parser<T> = () => T | null | Promise<T | null>
|
|
14
|
+
*/
|
|
15
|
+
export type Parser<T> = () => T | null | Promise<T | null>;
|
|
16
|
+
/**
|
|
17
|
+
* .what = input for getEnvironment methods
|
|
18
|
+
* .why = allows custom parsers and cache control
|
|
19
|
+
*/
|
|
20
|
+
interface GetEnvironmentInput {
|
|
21
|
+
parsers?: {
|
|
22
|
+
access?: AsyncParser<EnvironmentAccessTier>[];
|
|
23
|
+
server?: AsyncParser<EnvironmentServerTier>[];
|
|
24
|
+
commit?: AsyncParser<EnvironmentCommitSlug>[];
|
|
25
|
+
};
|
|
26
|
+
cache?: 'skip';
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* .what = input for getEnvironment.static
|
|
30
|
+
* .why = sync parsers only
|
|
31
|
+
*/
|
|
32
|
+
interface GetEnvironmentStaticInput {
|
|
33
|
+
parsers?: {
|
|
34
|
+
access?: SyncParser<EnvironmentAccessTier>[];
|
|
35
|
+
server?: SyncParser<EnvironmentServerTier>[];
|
|
36
|
+
commit?: SyncParser<EnvironmentCommitSlug>[];
|
|
37
|
+
};
|
|
38
|
+
cache?: 'skip';
|
|
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;
|
|
50
|
+
/**
|
|
51
|
+
* .what = get environment - callable directly or via .filled()/.static()
|
|
52
|
+
* .why = main entry point for sdk-environment
|
|
53
|
+
*/
|
|
54
|
+
interface GetEnvironment {
|
|
55
|
+
(input?: GetEnvironmentInput): Promise<Environment>;
|
|
56
|
+
filled: typeof filled;
|
|
57
|
+
static: typeof staticEnv;
|
|
58
|
+
}
|
|
59
|
+
export declare const getEnvironment: GetEnvironment;
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEnvironment = void 0;
|
|
4
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
5
|
+
const getEnvAccess_1 = require("../parsers/access/getEnvAccess");
|
|
6
|
+
const getEnvCommit_1 = require("../parsers/commit/getEnvCommit");
|
|
7
|
+
const getEnvServer_1 = require("../parsers/server/getEnvServer");
|
|
8
|
+
const isEnvironmentAccessTier_1 = require("../validators/isEnvironmentAccessTier");
|
|
9
|
+
const isEnvironmentCommitSlug_1 = require("../validators/isEnvironmentCommitSlug");
|
|
10
|
+
const isEnvironmentServerTier_1 = require("../validators/isEnvironmentServerTier");
|
|
11
|
+
// default parsers
|
|
12
|
+
const DEFAULT_ACCESS_PARSERS = [
|
|
13
|
+
getEnvAccess_1.getEnvAccess.fromEnvar,
|
|
14
|
+
getEnvAccess_1.getEnvAccess.fromAwsAccountAlias,
|
|
15
|
+
getEnvAccess_1.getEnvAccess.fromAwsAccountName,
|
|
16
|
+
getEnvAccess_1.getEnvAccess.fromNodeEnv,
|
|
17
|
+
];
|
|
18
|
+
const DEFAULT_SERVER_PARSERS = [
|
|
19
|
+
getEnvServer_1.getEnvServer.fromEnvar,
|
|
20
|
+
getEnvServer_1.getEnvServer.fromLambdaTaskRoot,
|
|
21
|
+
getEnvServer_1.getEnvServer.fromCiEnvar,
|
|
22
|
+
getEnvServer_1.getEnvServer.fromUnixDesktop,
|
|
23
|
+
];
|
|
24
|
+
const DEFAULT_COMMIT_PARSERS = [
|
|
25
|
+
getEnvCommit_1.getEnvCommit.fromEnvar,
|
|
26
|
+
getEnvCommit_1.getEnvCommit.fromGit,
|
|
27
|
+
];
|
|
28
|
+
// sync-only default parsers (skip async)
|
|
29
|
+
const DEFAULT_ACCESS_PARSERS_SYNC = [
|
|
30
|
+
getEnvAccess_1.getEnvAccess.fromEnvar,
|
|
31
|
+
getEnvAccess_1.getEnvAccess.fromNodeEnv,
|
|
32
|
+
];
|
|
33
|
+
const DEFAULT_COMMIT_PARSERS_SYNC = [
|
|
34
|
+
getEnvCommit_1.getEnvCommit.fromEnvar,
|
|
35
|
+
];
|
|
36
|
+
// cache
|
|
37
|
+
let filledCache = null;
|
|
38
|
+
let staticCache = null;
|
|
39
|
+
/**
|
|
40
|
+
* .what = run parser chain until first non-null result
|
|
41
|
+
* .why = first-wins precedence
|
|
42
|
+
*/
|
|
43
|
+
const runParsers = async (parsers, parserNames, validate, attributeName) => {
|
|
44
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
45
|
+
const parser = parsers[i];
|
|
46
|
+
const result = await parser();
|
|
47
|
+
if (result !== null) {
|
|
48
|
+
if (!validate(result)) {
|
|
49
|
+
throw new helpful_errors_1.BadRequestError(`invalid ${attributeName} value: ${JSON.stringify(result)}. parser: ${parserNames[i]}`);
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
throw new helpful_errors_1.UnexpectedCodePathError(`could not derive ${attributeName}. tried parsers: ${parserNames.join(', ')}`);
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* .what = run sync parser chain until first non-null result
|
|
58
|
+
* .why = first-wins precedence, sync only
|
|
59
|
+
*/
|
|
60
|
+
const runParsersSync = (parsers, parserNames, validate, attributeName) => {
|
|
61
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
62
|
+
const parser = parsers[i];
|
|
63
|
+
const result = parser();
|
|
64
|
+
if (result !== null) {
|
|
65
|
+
if (!validate(result)) {
|
|
66
|
+
throw new helpful_errors_1.BadRequestError(`invalid ${attributeName} value: ${JSON.stringify(result)}. parser: ${parserNames[i]}`);
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
throw new helpful_errors_1.UnexpectedCodePathError(`could not derive ${attributeName}. tried parsers: ${parserNames.join(', ')}`);
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* .what = async environment parser - runs all parsers with aws and git
|
|
75
|
+
* .why = complete environment detection with full parser chain
|
|
76
|
+
*/
|
|
77
|
+
const filled = async (input) => {
|
|
78
|
+
// check cache
|
|
79
|
+
if (input?.cache !== 'skip' && filledCache)
|
|
80
|
+
return filledCache;
|
|
81
|
+
const accessParsers = input?.parsers?.access ?? DEFAULT_ACCESS_PARSERS;
|
|
82
|
+
const serverParsers = input?.parsers?.server ?? DEFAULT_SERVER_PARSERS;
|
|
83
|
+
const commitParsers = input?.parsers?.commit ?? DEFAULT_COMMIT_PARSERS;
|
|
84
|
+
const accessParserNames = accessParsers.map((p, i) => p.name || `parser[${i}]`);
|
|
85
|
+
const serverParserNames = serverParsers.map((p, i) => p.name || `parser[${i}]`);
|
|
86
|
+
const commitParserNames = commitParsers.map((p, i) => p.name || `parser[${i}]`);
|
|
87
|
+
const access = await runParsers(accessParsers, accessParserNames, isEnvironmentAccessTier_1.isEnvironmentAccessTier, 'access');
|
|
88
|
+
const server = await runParsers(serverParsers, serverParserNames, isEnvironmentServerTier_1.isEnvironmentServerTier, 'server');
|
|
89
|
+
const commit = await runParsers(commitParsers, commitParserNames, isEnvironmentCommitSlug_1.isEnvironmentCommitSlug, 'commit');
|
|
90
|
+
const environment = { access, server, commit };
|
|
91
|
+
filledCache = environment;
|
|
92
|
+
return environment;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* .what = sync environment parser - skips async parsers
|
|
96
|
+
* .why = sync access without await for contexts that need it
|
|
97
|
+
*/
|
|
98
|
+
const staticEnv = (input) => {
|
|
99
|
+
// check cache
|
|
100
|
+
if (input?.cache !== 'skip' && staticCache)
|
|
101
|
+
return staticCache;
|
|
102
|
+
const accessParsers = input?.parsers?.access ?? DEFAULT_ACCESS_PARSERS_SYNC;
|
|
103
|
+
const serverParsers = input?.parsers?.server ?? DEFAULT_SERVER_PARSERS;
|
|
104
|
+
const commitParsers = input?.parsers?.commit ?? DEFAULT_COMMIT_PARSERS_SYNC;
|
|
105
|
+
const accessParserNames = accessParsers.map((p, i) => p.name || `parser[${i}]`);
|
|
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;
|
|
114
|
+
};
|
|
115
|
+
const getEnvironmentFn = Object.assign(
|
|
116
|
+
// direct call delegates to filled
|
|
117
|
+
(input) => filled(input), {
|
|
118
|
+
/**
|
|
119
|
+
* async, runs all parsers (aws and git), cached
|
|
120
|
+
*/
|
|
121
|
+
filled,
|
|
122
|
+
/**
|
|
123
|
+
* sync, skips async parsers, cached independently
|
|
124
|
+
*/
|
|
125
|
+
static: staticEnv,
|
|
126
|
+
});
|
|
127
|
+
exports.getEnvironment = getEnvironmentFn;
|
|
128
|
+
//# sourceMappingURL=getEnvironment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getEnvironment.js","sourceRoot":"","sources":["../../../src/domain.operations/getEnvironment/getEnvironment.ts"],"names":[],"mappings":";;;AAAA,mDAA0E;AAM1E,iEAA8D;AAC9D,iEAA8D;AAC9D,iEAA8D;AAC9D,mFAAgF;AAChF,mFAAgF;AAChF,mFAAgF;AAyChF,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,kBAAkB;IAC/B,2BAAY,CAAC,WAAW;IACxB,2BAAY,CAAC,eAAe;CAC7B,CAAC;AAEF,MAAM,sBAAsB,GAAyC;IACnE,2BAAY,CAAC,SAAS;IACtB,2BAAY,CAAC,OAAO;CACrB,CAAC;AAEF,yCAAyC;AACzC,MAAM,2BAA2B,GAAwC;IACvE,2BAAY,CAAC,SAAS;IACtB,2BAAY,CAAC,WAAW;CACzB,CAAC;AAEF,MAAM,2BAA2B,GAAwC;IACvE,2BAAY,CAAC,SAAS;CACvB,CAAC;AAEF,QAAQ;AACR,IAAI,WAAW,GAAuB,IAAI,CAAC;AAC3C,IAAI,WAAW,GAAuB,IAAI,CAAC;AAE3C;;;GAGG;AACH,MAAM,UAAU,GAAG,KAAK,EACtB,OAAyB,EACzB,WAAqB,EACrB,QAAwC,EACxC,aAAqB,EACT,EAAE;IACd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,E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E,MAAM,EAAE,CAAC;IAC5D,WAAW,GAAG,WAAW,CAAC;IAC1B,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAYF,MAAM,gBAAgB,GAAmB,MAAM,CAAC,MAAM;AACpD,kCAAkC;AAClC,CAAC,KAA2B,EAAwB,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EACpE;IACE;;OAEG;IACH,MAAM;IAEN;;OAEG;IACH,MAAM,EAAE,SAAS;CAClB,CACF,CAAC;AAEW,QAAA,cAAc,GAAG,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = namespace for access tier parsers
|
|
3
|
+
* .why = enables dot notation: getEnvAccess.fromEnvar()
|
|
4
|
+
*/
|
|
5
|
+
export declare const getEnvAccess: {
|
|
6
|
+
fromEnvar: () => import("../../..").EnvironmentAccessTier | null;
|
|
7
|
+
fromAwsAccountAlias: (input?: {
|
|
8
|
+
map?: import("./getEnvAccessFromAwsAccountName").AwsAccountPatternMap | undefined;
|
|
9
|
+
} | undefined) => Promise<import("../../..").EnvironmentAccessTier | null>;
|
|
10
|
+
fromAwsAccountName: (input?: {
|
|
11
|
+
map?: import("./getEnvAccessFromAwsAccountName").AwsAccountPatternMap | undefined;
|
|
12
|
+
} | undefined) => Promise<import("../../..").EnvironmentAccessTier | null>;
|
|
13
|
+
fromNodeEnv: () => import("../../..").EnvironmentAccessTier | null;
|
|
14
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEnvAccess = void 0;
|
|
4
|
+
const getEnvAccessFromAwsAccountAlias_1 = require("./getEnvAccessFromAwsAccountAlias");
|
|
5
|
+
const getEnvAccessFromAwsAccountName_1 = require("./getEnvAccessFromAwsAccountName");
|
|
6
|
+
const getEnvAccessFromEnvar_1 = require("./getEnvAccessFromEnvar");
|
|
7
|
+
const getEnvAccessFromNodeEnv_1 = require("./getEnvAccessFromNodeEnv");
|
|
8
|
+
/**
|
|
9
|
+
* .what = namespace for access tier parsers
|
|
10
|
+
* .why = enables dot notation: getEnvAccess.fromEnvar()
|
|
11
|
+
*/
|
|
12
|
+
exports.getEnvAccess = {
|
|
13
|
+
fromEnvar: getEnvAccessFromEnvar_1.getEnvAccessFromEnvar,
|
|
14
|
+
fromAwsAccountAlias: getEnvAccessFromAwsAccountAlias_1.getEnvAccessFromAwsAccountAlias,
|
|
15
|
+
fromAwsAccountName: getEnvAccessFromAwsAccountName_1.getEnvAccessFromAwsAccountName,
|
|
16
|
+
fromNodeEnv: getEnvAccessFromNodeEnv_1.getEnvAccessFromNodeEnv,
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=getEnvAccess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getEnvAccess.js","sourceRoot":"","sources":["../../../../src/domain.operations/parsers/access/getEnvAccess.ts"],"names":[],"mappings":";;;AAAA,uFAAoF;AACpF,qFAAkF;AAClF,mEAAgE;AAChE,uEAAoE;AAEpE;;;GAGG;AACU,QAAA,YAAY,GAAG;IAC1B,SAAS,EAAE,6CAAqB;IAChC,mBAAmB,EAAE,iEAA+B;IACpD,kBAAkB,EAAE,+DAA8B;IAClD,WAAW,EAAE,iDAAuB;CACrC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { EnvironmentAccessTier } from '../../../domain.objects/EnvironmentAccessTier';
|
|
2
|
+
import type { AwsAccountPatternMap } from './getEnvAccessFromAwsAccountName';
|
|
3
|
+
/**
|
|
4
|
+
* .what = alias for canonical pattern map type
|
|
5
|
+
* .why = backwards compat for extant code
|
|
6
|
+
*/
|
|
7
|
+
export type AwsAccountAliasMap = AwsAccountPatternMap;
|
|
8
|
+
/**
|
|
9
|
+
* .what = match alias against pattern map
|
|
10
|
+
* .why = exact match wins, then glob match in order
|
|
11
|
+
*/
|
|
12
|
+
export declare const matchAliasToAccess: (alias: string, map: AwsAccountAliasMap) => EnvironmentAccessTier | null;
|
|
13
|
+
/**
|
|
14
|
+
* .what = parse access tier from aws account alias
|
|
15
|
+
* .why = infer from aws account alias (e.g., 'myorg-prod' → prod)
|
|
16
|
+
*/
|
|
17
|
+
export declare const getEnvAccessFromAwsAccountAlias: (input?: {
|
|
18
|
+
map?: AwsAccountAliasMap;
|
|
19
|
+
}) => Promise<EnvironmentAccessTier | null>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getEnvAccessFromAwsAccountAlias = exports.matchAliasToAccess = void 0;
|
|
27
|
+
const DEFAULT_MAP = {
|
|
28
|
+
'*-prod': 'prod',
|
|
29
|
+
'*-prep': 'prep',
|
|
30
|
+
'*-test': 'test',
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* .what = match alias against pattern map
|
|
34
|
+
* .why = exact match wins, then glob match in order
|
|
35
|
+
*/
|
|
36
|
+
const matchAliasToAccess = (alias, map) => {
|
|
37
|
+
// exact match first
|
|
38
|
+
if (map[alias])
|
|
39
|
+
return map[alias];
|
|
40
|
+
// glob match in order
|
|
41
|
+
for (const pattern of Object.keys(map)) {
|
|
42
|
+
if (pattern.includes('*')) {
|
|
43
|
+
const regex = new RegExp(`^${pattern.replace(/\*/g, '.*')}$`);
|
|
44
|
+
if (regex.test(alias))
|
|
45
|
+
return map[pattern];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
};
|
|
50
|
+
exports.matchAliasToAccess = matchAliasToAccess;
|
|
51
|
+
/**
|
|
52
|
+
* .what = parse access tier from aws account alias
|
|
53
|
+
* .why = infer from aws account alias (e.g., 'myorg-prod' → prod)
|
|
54
|
+
*/
|
|
55
|
+
const getEnvAccessFromAwsAccountAlias = async (input) => {
|
|
56
|
+
const map = input?.map ?? DEFAULT_MAP;
|
|
57
|
+
try {
|
|
58
|
+
// dynamic import to avoid bundle size when not used
|
|
59
|
+
const { IAMClient, ListAccountAliasesCommand } = await Promise.resolve().then(() => __importStar(require('@aws-sdk/client-iam')));
|
|
60
|
+
const client = new IAMClient({});
|
|
61
|
+
const response = await client.send(new ListAccountAliasesCommand({}));
|
|
62
|
+
const alias = response.AccountAliases?.[0];
|
|
63
|
+
if (!alias)
|
|
64
|
+
return null;
|
|
65
|
+
return (0, exports.matchAliasToAccess)(alias, map);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
// allowlist: config/credential/auth errors return null (parser should be skipped)
|
|
69
|
+
if (error instanceof Error) {
|
|
70
|
+
const message = error.message.toLowerCase();
|
|
71
|
+
const name = error.name.toLowerCase();
|
|
72
|
+
if (message.includes('region') ||
|
|
73
|
+
message.includes('could not load credentials') ||
|
|
74
|
+
message.includes('no credentials') ||
|
|
75
|
+
message.includes('credential') ||
|
|
76
|
+
message.includes('access denied') ||
|
|
77
|
+
message.includes('not authorized') ||
|
|
78
|
+
message.includes('security token') ||
|
|
79
|
+
message.includes('session') ||
|
|
80
|
+
message.includes('expired') ||
|
|
81
|
+
message.includes('reauthenticate') ||
|
|
82
|
+
name.includes('invalidclienttokenid') ||
|
|
83
|
+
name.includes('credentialsprovider')) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// rethrow unexpected errors
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
exports.getEnvAccessFromAwsAccountAlias = getEnvAccessFromAwsAccountAlias;
|
|
92
|
+
//# sourceMappingURL=getEnvAccessFromAwsAccountAlias.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getEnvAccessFromAwsAccountAlias.js","sourceRoot":"","sources":["../../../../src/domain.operations/parsers/access/getEnvAccessFromAwsAccountAlias.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAM,WAAW,GAAuB;IACtC,QAAQ,EAAE,MAAM;IAChB,QAAQ,EAAE,MAAM;IAChB,QAAQ,EAAE,MAAM;CACjB,CAAC;AAEF;;;GAGG;AACI,MAAM,kBAAkB,GAAG,CAChC,KAAa,EACb,GAAuB,EACO,EAAE;IAChC,oBAAoB;IACpB,IAAI,GAAG,CAAC,KAAK,CAAC;QAAE,OAAO,GAAG,CAAC,KAAK,CAAE,CAAC;IAEnC,sBAAsB;IACtB,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACvC,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,MAAM,KAAK,GA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C,gBAAgB,CAAC;gBAClC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;gBAC9B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC;gBACjC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC;gBAClC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC;gBAClC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;gBAC3B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;gBAC3B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC;gBAClC,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC;gBACrC,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC,EACpC,CAAC;gBACD,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QACD,4BAA4B;QAC5B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AA1CW,QAAA,+BAA+B,mCA0C1C"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { EnvironmentAccessTier } from '../../../domain.objects/EnvironmentAccessTier';
|
|
2
|
+
/**
|
|
3
|
+
* .what = account name pattern to access tier map
|
|
4
|
+
* .why = enables glob and exact pattern match
|
|
5
|
+
* .note = canonical name, reused by alias parser
|
|
6
|
+
*/
|
|
7
|
+
export interface AwsAccountPatternMap {
|
|
8
|
+
[pattern: string]: EnvironmentAccessTier;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* .what = match name against pattern map
|
|
12
|
+
* .why = exact match wins, then glob match in order
|
|
13
|
+
*/
|
|
14
|
+
export declare const matchNameToAccess: (name: string, map: AwsAccountPatternMap) => EnvironmentAccessTier | null;
|
|
15
|
+
/**
|
|
16
|
+
* .what = parse access tier from aws account name
|
|
17
|
+
* .why = fallback when alias not set (name is always present)
|
|
18
|
+
*/
|
|
19
|
+
export declare const getEnvAccessFromAwsAccountName: (input?: {
|
|
20
|
+
map?: AwsAccountPatternMap;
|
|
21
|
+
}) => Promise<EnvironmentAccessTier | null>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getEnvAccessFromAwsAccountName = exports.matchNameToAccess = void 0;
|
|
27
|
+
const DEFAULT_MAP = {
|
|
28
|
+
'*-prod': 'prod',
|
|
29
|
+
'*-prep': 'prep',
|
|
30
|
+
'*-test': 'test',
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* .what = match name against pattern map
|
|
34
|
+
* .why = exact match wins, then glob match in order
|
|
35
|
+
*/
|
|
36
|
+
const matchNameToAccess = (name, map) => {
|
|
37
|
+
// exact match first
|
|
38
|
+
if (map[name])
|
|
39
|
+
return map[name];
|
|
40
|
+
// glob match in order
|
|
41
|
+
for (const pattern of Object.keys(map)) {
|
|
42
|
+
if (pattern.includes('*')) {
|
|
43
|
+
const regex = new RegExp(`^${pattern.replace(/\*/g, '.*')}$`);
|
|
44
|
+
if (regex.test(name))
|
|
45
|
+
return map[pattern];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
};
|
|
50
|
+
exports.matchNameToAccess = matchNameToAccess;
|
|
51
|
+
/**
|
|
52
|
+
* .what = parse access tier from aws account name
|
|
53
|
+
* .why = fallback when alias not set (name is always present)
|
|
54
|
+
*/
|
|
55
|
+
const getEnvAccessFromAwsAccountName = async (input) => {
|
|
56
|
+
const map = input?.map ?? DEFAULT_MAP;
|
|
57
|
+
try {
|
|
58
|
+
// dynamic import to avoid bundle size when not used
|
|
59
|
+
const { AccountClient, GetAccountInformationCommand } = await Promise.resolve().then(() => __importStar(require('@aws-sdk/client-account')));
|
|
60
|
+
const client = new AccountClient({});
|
|
61
|
+
const response = await client.send(new GetAccountInformationCommand({}));
|
|
62
|
+
const accountName = response.AccountName;
|
|
63
|
+
if (!accountName)
|
|
64
|
+
return null;
|
|
65
|
+
return (0, exports.matchNameToAccess)(accountName, map);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
// allowlist: config/credential/auth errors return null (parser should be skipped)
|
|
69
|
+
if (error instanceof Error) {
|
|
70
|
+
const message = error.message.toLowerCase();
|
|
71
|
+
const errorName = error.name.toLowerCase();
|
|
72
|
+
if (message.includes('region') ||
|
|
73
|
+
message.includes('could not load credentials') ||
|
|
74
|
+
message.includes('no credentials') ||
|
|
75
|
+
message.includes('credential') ||
|
|
76
|
+
message.includes('access denied') ||
|
|
77
|
+
message.includes('not authorized') ||
|
|
78
|
+
message.includes('security token') ||
|
|
79
|
+
message.includes('session') ||
|
|
80
|
+
message.includes('expired') ||
|
|
81
|
+
message.includes('reauthenticate') ||
|
|
82
|
+
errorName.includes('invalidclienttokenid') ||
|
|
83
|
+
errorName.includes('credentialsprovider')) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// rethrow unexpected errors
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
exports.getEnvAccessFromAwsAccountName = getEnvAccessFromAwsAccountName;
|
|
92
|
+
//# sourceMappingURL=getEnvAccessFromAwsAccountName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getEnvAccessFromAwsAccountName.js","sourceRoot":"","sources":["../../../../src/domain.operations/parsers/access/getEnvAccessFromAwsAccountName.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,MAAM,WAAW,GAAyB;IACxC,QAAQ,EAAE,MAAM;IAChB,QAAQ,EAAE,MAAM;IAChB,QAAQ,EAAE,MAAM;CACjB,CAAC;AAEF;;;GAGG;AACI,MAAM,iBAAiB,GAAG,CAC/B,IAAY,EACZ,GAAyB,EACK,EAAE;IAChC,oBAAoB;IACpB,IAAI,GAAG,CAAC,IAAI,CAAC;QAAE,OAAO,GAAG,CAAC,IAAI,CAAE,CAAC;IAEjC,sBAAsB;IACtB,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACvC,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;YAC9D,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;gBAAE,OAAO,GAAG,CAAC,OAAO,CAAE,CAAC;QAC7C,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAhBW,QAAA,iBAAiB,qBAgB5B;AAEF;;;GAG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AAQ,CAAC,gBAAgB,CAAC;gBAClC,SAAS,CAAC,QAAQ,CAAC,sBAAsB,CAAC;gBAC1C,SAAS,CAAC,QAAQ,CAAC,qBAAqB,CAAC,EACzC,CAAC;gBACD,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QACD,4BAA4B;QAC5B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AA1CW,QAAA,8BAA8B,kCA0CzC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { EnvironmentAccessTier } from '../../../domain.objects/EnvironmentAccessTier';
|
|
2
|
+
/**
|
|
3
|
+
* .what = parse access tier from ACCESS environment variable
|
|
4
|
+
* .why = explicit override via ACCESS=prod
|
|
5
|
+
*/
|
|
6
|
+
export declare const getEnvAccessFromEnvar: () => EnvironmentAccessTier | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEnvAccessFromEnvar = void 0;
|
|
4
|
+
const isEnvironmentAccessTier_1 = require("../../validators/isEnvironmentAccessTier");
|
|
5
|
+
/**
|
|
6
|
+
* .what = parse access tier from ACCESS environment variable
|
|
7
|
+
* .why = explicit override via ACCESS=prod
|
|
8
|
+
*/
|
|
9
|
+
const getEnvAccessFromEnvar = () => {
|
|
10
|
+
const value = process.env.ACCESS;
|
|
11
|
+
if (!value || value === '')
|
|
12
|
+
return null;
|
|
13
|
+
if (!(0, isEnvironmentAccessTier_1.isEnvironmentAccessTier)(value))
|
|
14
|
+
return null;
|
|
15
|
+
return value;
|
|
16
|
+
};
|
|
17
|
+
exports.getEnvAccessFromEnvar = getEnvAccessFromEnvar;
|
|
18
|
+
//# sourceMappingURL=getEnvAccessFromEnvar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getEnvAccessFromEnvar.js","sourceRoot":"","sources":["../../../../src/domain.operations/parsers/access/getEnvAccessFromEnvar.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,12 @@
|
|
|
1
|
+
import type { EnvironmentAccessTier } from '../../../domain.objects/EnvironmentAccessTier';
|
|
2
|
+
/**
|
|
3
|
+
* .what = parse access tier from NODE_ENV environment variable
|
|
4
|
+
* .why = fallback: NODE_ENV=test → 'test', NODE_ENV=production → 'prod'
|
|
5
|
+
*
|
|
6
|
+
* mappings:
|
|
7
|
+
* - NODE_ENV=test → 'test'
|
|
8
|
+
* - NODE_ENV=production → 'prod'
|
|
9
|
+
* - NODE_ENV=development → null (no default)
|
|
10
|
+
* - other values → null
|
|
11
|
+
*/
|
|
12
|
+
export declare const getEnvAccessFromNodeEnv: () => EnvironmentAccessTier | null;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEnvAccessFromNodeEnv = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = parse access tier from NODE_ENV environment variable
|
|
6
|
+
* .why = fallback: NODE_ENV=test → 'test', NODE_ENV=production → 'prod'
|
|
7
|
+
*
|
|
8
|
+
* mappings:
|
|
9
|
+
* - NODE_ENV=test → 'test'
|
|
10
|
+
* - NODE_ENV=production → 'prod'
|
|
11
|
+
* - NODE_ENV=development → null (no default)
|
|
12
|
+
* - other values → null
|
|
13
|
+
*/
|
|
14
|
+
const getEnvAccessFromNodeEnv = () => {
|
|
15
|
+
const value = process.env.NODE_ENV;
|
|
16
|
+
if (value === 'test')
|
|
17
|
+
return 'test';
|
|
18
|
+
if (value === 'production')
|
|
19
|
+
return 'prod';
|
|
20
|
+
return null;
|
|
21
|
+
};
|
|
22
|
+
exports.getEnvAccessFromNodeEnv = getEnvAccessFromNodeEnv;
|
|
23
|
+
//# sourceMappingURL=getEnvAccessFromNodeEnv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getEnvAccessFromNodeEnv.js","sourceRoot":"","sources":["../../../../src/domain.operations/parsers/access/getEnvAccessFromNodeEnv.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;GASG;AACI,MAAM,uBAAuB,GAAG,GAAiC,EAAE;IACxE,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;IACnC,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,MAAM,CAAC;IACpC,IAAI,KAAK,KAAK,YAAY;QAAE,OAAO,MAAM,CAAC;IAC1C,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AALW,QAAA,uBAAuB,2BAKlC"}
|