@cogs/config 0.4.0 → 0.5.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/README.md +114 -6
- package/dist/cjs/dotenv-checkers.js +85 -23
- package/dist/cjs/dotenv-correlation.js +95 -0
- package/dist/cjs/dotenv-files.js +43 -0
- package/dist/cjs/dotenv-fixers.js +17 -20
- package/dist/cjs/envs.js +53 -26
- package/dist/cjs/redact.js +27 -0
- package/dist/cli-core.d.ts +72 -0
- package/dist/cli-core.d.ts.map +1 -0
- package/dist/cli-core.js +310 -0
- package/dist/cli-core.js.map +1 -0
- package/dist/cli.d.ts +9 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +17 -0
- package/dist/cli.js.map +1 -0
- package/dist/dotenv-checkers.d.ts +61 -11
- package/dist/dotenv-checkers.d.ts.map +1 -1
- package/dist/dotenv-checkers.js +84 -22
- package/dist/dotenv-checkers.js.map +1 -1
- package/dist/dotenv-correlation.d.ts +23 -0
- package/dist/dotenv-correlation.d.ts.map +1 -0
- package/dist/dotenv-correlation.js +92 -0
- package/dist/dotenv-correlation.js.map +1 -0
- package/dist/dotenv-files.d.ts +24 -0
- package/dist/dotenv-files.d.ts.map +1 -0
- package/dist/dotenv-files.js +40 -0
- package/dist/dotenv-files.js.map +1 -0
- package/dist/dotenv-fixers.d.ts.map +1 -1
- package/dist/dotenv-fixers.js +17 -20
- package/dist/dotenv-fixers.js.map +1 -1
- package/dist/envs.d.ts +9 -1
- package/dist/envs.d.ts.map +1 -1
- package/dist/envs.js +55 -28
- package/dist/envs.js.map +1 -1
- package/dist/redact.d.ts +18 -0
- package/dist/redact.d.ts.map +1 -0
- package/dist/redact.js +24 -0
- package/dist/redact.js.map +1 -0
- package/package.json +6 -3
package/dist/dotenv-checkers.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { maskLast4 } from './redact.js';
|
|
1
2
|
import { removeInvalidLeadingChars } from './utils.js';
|
|
2
3
|
/**
|
|
3
4
|
* Checks if a given key has incorrect delimiters. Delimiters should occur
|
|
@@ -47,22 +48,43 @@ export const lowercaseKeyChecker = (key) => {
|
|
|
47
48
|
return true;
|
|
48
49
|
};
|
|
49
50
|
/**
|
|
50
|
-
* Checks
|
|
51
|
-
*
|
|
51
|
+
* Checks whether a value carries quote characters it does not need — the
|
|
52
|
+
* copy-paste-a-shell-quoted-secret-verbatim mistake this package exists to catch
|
|
53
|
+
* at its source.
|
|
52
54
|
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
+
* Skips values whose quoting is load-bearing or whose semantics we cannot judge
|
|
56
|
+
* from the raw text: multiline values, values containing whitespace (where the
|
|
57
|
+
* quotes are what keep the value one token), `${VAR}` expansions, and values
|
|
58
|
+
* containing a `#`.
|
|
59
|
+
*
|
|
60
|
+
* `rawValue` must be the **raw pre-parse** value as captured from the `.env`
|
|
61
|
+
* source — wrapping quotes intact — not the post-`dotenv.parse` value, which has
|
|
62
|
+
* already had its wrapping quotes stripped and so can never exhibit the defect
|
|
63
|
+
* this checker looks for. See `dotenv-correlation.ts` for the contract.
|
|
64
|
+
*
|
|
65
|
+
* @param key - The key the value belongs to.
|
|
66
|
+
* @param rawValue - The raw captured value, quotes intact. `''` for `KEY=`.
|
|
67
|
+
* @returns A {@link Finding} when unnecessary quote characters are found,
|
|
68
|
+
* undefined otherwise.
|
|
55
69
|
*/
|
|
56
|
-
export const quoteCharacterChecker = (
|
|
57
|
-
if (
|
|
58
|
-
/[ \t\r\n\f]/.test(
|
|
59
|
-
|
|
60
|
-
|
|
70
|
+
export const quoteCharacterChecker = (key, rawValue) => {
|
|
71
|
+
if (rawValue.includes('\n') ||
|
|
72
|
+
/[ \t\r\n\f]/.test(rawValue) ||
|
|
73
|
+
rawValue.includes('$') ||
|
|
74
|
+
rawValue.includes('#')) {
|
|
61
75
|
return;
|
|
62
76
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
77
|
+
// Backtick is a third wrapping quote character dotenv supports
|
|
78
|
+
// (`node_modules/.pnpm/dotenv@16.6.1/node_modules/dotenv/lib/main.js:8`), so a
|
|
79
|
+
// backtick-wrapped secret is the same defect as a `'`- or `"`-wrapped one.
|
|
80
|
+
if (rawValue.includes('"') ||
|
|
81
|
+
rawValue.includes("'") ||
|
|
82
|
+
rawValue.includes('`')) {
|
|
83
|
+
return {
|
|
84
|
+
key,
|
|
85
|
+
rule: 'quote-character',
|
|
86
|
+
message: `'${key}' value ${maskLast4(rawValue)} contains quote characters.`,
|
|
87
|
+
};
|
|
66
88
|
}
|
|
67
89
|
};
|
|
68
90
|
/**
|
|
@@ -78,22 +100,40 @@ export const trailingWhitespaceChecker = (line) => {
|
|
|
78
100
|
}
|
|
79
101
|
};
|
|
80
102
|
/**
|
|
81
|
-
* Checks
|
|
82
|
-
*
|
|
103
|
+
* Checks whether a value contains whitespace but is not wrapped in quotes, which
|
|
104
|
+
* makes it fragile across shells and dotenv reimplementations.
|
|
83
105
|
*
|
|
84
|
-
* @
|
|
85
|
-
*
|
|
106
|
+
* Like {@link quoteCharacterChecker} this must be fed the raw pre-parse value,
|
|
107
|
+
* quotes intact: `dotenv.parse` strips wrapping quotes, so a correctly quoted
|
|
108
|
+
* multi-word value would look unquoted (and false-positive) after parsing.
|
|
109
|
+
*
|
|
110
|
+
* @param key - The key the value belongs to.
|
|
111
|
+
* @param rawValue - The raw captured value, quotes intact. `''` for `KEY=`.
|
|
112
|
+
* @returns A {@link Finding} when the value has whitespace without wrapping
|
|
113
|
+
* quotes, undefined otherwise.
|
|
86
114
|
*/
|
|
87
|
-
export const valueWithoutQuotesChecker = (
|
|
88
|
-
|
|
89
|
-
if (/[ \t\r\n\f]/.test(
|
|
90
|
-
!(
|
|
91
|
-
!(
|
|
92
|
-
|
|
115
|
+
export const valueWithoutQuotesChecker = (key, rawValue) => {
|
|
116
|
+
const value = rawValue.trim();
|
|
117
|
+
if (/[ \t\r\n\f]/.test(value) &&
|
|
118
|
+
!(value.startsWith("'") && value.endsWith("'")) &&
|
|
119
|
+
!(value.startsWith('"') && value.endsWith('"')) &&
|
|
120
|
+
// Backtick is a valid dotenv wrapping quote; without this a
|
|
121
|
+
// `TOK=\`multi word\`` line false-positives, and `valueWithoutQuotesFixer`
|
|
122
|
+
// would then re-wrap an already-quoted value.
|
|
123
|
+
!(value.startsWith('`') && value.endsWith('`'))) {
|
|
124
|
+
return {
|
|
125
|
+
key,
|
|
126
|
+
rule: 'value-without-quotes',
|
|
127
|
+
message: `'${key}' value ${maskLast4(value)} contains whitespace but is not quoted.`,
|
|
128
|
+
};
|
|
93
129
|
}
|
|
94
130
|
};
|
|
95
131
|
/**
|
|
96
132
|
* An array of functions for checking various aspects of .env file entries.
|
|
133
|
+
*
|
|
134
|
+
* @deprecated Use dotenvKeyCheckers / dotenvLineCheckers instead. Will be
|
|
135
|
+
* removed in a future 1.0.0. The two groupings distinguish checkers that take a
|
|
136
|
+
* key from checkers that take a raw value, which this flat array cannot express.
|
|
97
137
|
*/
|
|
98
138
|
export const dotenvCheckers = [
|
|
99
139
|
incorrectDelimiterChecker,
|
|
@@ -103,4 +143,26 @@ export const dotenvCheckers = [
|
|
|
103
143
|
trailingWhitespaceChecker,
|
|
104
144
|
valueWithoutQuotesChecker,
|
|
105
145
|
];
|
|
146
|
+
/**
|
|
147
|
+
* Checkers that take a `.env` **key**. Mirrors `dotenvKeyFixers`.
|
|
148
|
+
*/
|
|
149
|
+
export const dotenvKeyCheckers = [
|
|
150
|
+
incorrectDelimiterChecker,
|
|
151
|
+
leadingCharacterChecker,
|
|
152
|
+
lowercaseKeyChecker,
|
|
153
|
+
];
|
|
154
|
+
/**
|
|
155
|
+
* Checkers that take a `.env` **value**. Mirrors `dotenvLineFixers`.
|
|
156
|
+
*
|
|
157
|
+
* ⚠️ `trailingWhitespaceChecker` is a known, tracked exception: it was NOT
|
|
158
|
+
* fixed in the pass that corrected the other two, so it still binds its single
|
|
159
|
+
* parameter to whatever the caller passes first and its output should not be
|
|
160
|
+
* trusted. Its membership here reflects the family it belongs to, not a claim
|
|
161
|
+
* that it works. See the README's "Known limitations".
|
|
162
|
+
*/
|
|
163
|
+
export const dotenvLineCheckers = [
|
|
164
|
+
quoteCharacterChecker,
|
|
165
|
+
trailingWhitespaceChecker,
|
|
166
|
+
valueWithoutQuotesChecker,
|
|
167
|
+
];
|
|
106
168
|
//# sourceMappingURL=dotenv-checkers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dotenv-checkers.js","sourceRoot":"","sources":["../src/dotenv-checkers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"dotenv-checkers.js","sourceRoot":"","sources":["../src/dotenv-checkers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAgBtD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,GAAW,EAAE,IAAY,EAAE,EAAE;IACrE,0EAA0E;IAC1E,sEAAsE;IACtE,uBAAuB;IACvB,MAAM,UAAU,GAAG,yBAAyB,CAAC,GAAG,CAAC,CAAA;IACjD,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IACzC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;QACnD,OAAO,CAAC,GAAG,CAAC,aAAa,GAAG,uBAAuB,CAAC,CAAA;QACpD,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,GAAW,EAAE,EAAE;IACrD,IAAI,UAAU,CAAC,IAA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0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Correlates each key in a raw `.env` file's contents back to the value **as it
|
|
3
|
+
* literally appears in the file**, wrapping quotes intact.
|
|
4
|
+
*
|
|
5
|
+
* Why this module exists: `dotenv.parse` strips wrapping quotes at parse time
|
|
6
|
+
* (`dotenv-with-expand.ts:70`), so a checker fed a parsed value structurally
|
|
7
|
+
* cannot observe the quote-wrapping defect it exists to detect. The checkers
|
|
8
|
+
* need the pre-parse substring, and `dotenv` exports no line splitter to get it
|
|
9
|
+
* (its parser is a single module-private regex).
|
|
10
|
+
*
|
|
11
|
+
* Internal module — deliberately NOT re-exported from `index.ts`.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Map every key in `contents` to its raw pre-parse value.
|
|
15
|
+
*
|
|
16
|
+
* Duplicate keys resolve **last-match-wins**, matching `dotenv.parse`'s own
|
|
17
|
+
* behavior (verified: parsing `DUP=first\nDUP=second` returns `{DUP:'second'}`).
|
|
18
|
+
*
|
|
19
|
+
* @param contents - The raw text of a `.env` file.
|
|
20
|
+
* @returns Key → raw value, quotes intact. See {@link normalizeRawValue}.
|
|
21
|
+
*/
|
|
22
|
+
export declare const correlateRawValues: (contents: string) => Map<string, string>;
|
|
23
|
+
//# sourceMappingURL=dotenv-correlation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dotenv-correlation.d.ts","sourceRoot":"","sources":["../src/dotenv-correlation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA0DH;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,GAAI,UAAU,MAAM,KAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAoBvE,CAAA"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Correlates each key in a raw `.env` file's contents back to the value **as it
|
|
3
|
+
* literally appears in the file**, wrapping quotes intact.
|
|
4
|
+
*
|
|
5
|
+
* Why this module exists: `dotenv.parse` strips wrapping quotes at parse time
|
|
6
|
+
* (`dotenv-with-expand.ts:70`), so a checker fed a parsed value structurally
|
|
7
|
+
* cannot observe the quote-wrapping defect it exists to detect. The checkers
|
|
8
|
+
* need the pre-parse substring, and `dotenv` exports no line splitter to get it
|
|
9
|
+
* (its parser is a single module-private regex).
|
|
10
|
+
*
|
|
11
|
+
* Internal module — deliberately NOT re-exported from `index.ts`.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Vendored, version-pinned adaptation of `dotenv`'s `LINE` regex.
|
|
15
|
+
*
|
|
16
|
+
* Source: `node_modules/.pnpm/dotenv@16.6.1/node_modules/dotenv/lib/main.js:8`
|
|
17
|
+
* as of `dotenv@16.6.1`. Copied byte-for-byte — the whole point is to split
|
|
18
|
+
* lines exactly the way `dotenv` itself does, so `parse()`'s keys and this
|
|
19
|
+
* module's keys can never disagree.
|
|
20
|
+
*
|
|
21
|
+
* ⚠️ VERSION DRIFT: `package.json` depends on `dotenv` at the caret range
|
|
22
|
+
* `^16.6.1`, so a minor/patch bump can land without a code change here. On any
|
|
23
|
+
* `dotenv` version bump, re-read `lib/main.js`'s `LINE` constant and re-verify
|
|
24
|
+
* this copy against it. See
|
|
25
|
+
* `.omc/plans/2026-09-07-config-lint-prevention-at-source.md` (AC3).
|
|
26
|
+
*
|
|
27
|
+
* Structure, for readers who would rather not parse it by eye:
|
|
28
|
+
* - an optional leading `export ` is consumed *outside* both capture groups
|
|
29
|
+
* - group 1 is the key
|
|
30
|
+
* - group 2 is the value: either a quoted alternative (`'…'`, `"…"`, `` `…` ``,
|
|
31
|
+
* each using a `[^X]` character class that matches `\n`, which is what makes
|
|
32
|
+
* multiline quoted values correlate correctly in a single match) or the
|
|
33
|
+
* unquoted alternative `[^#\r\n]+`, which stops at a `#` and therefore already
|
|
34
|
+
* excludes any inline comment
|
|
35
|
+
* - group 2 is optional, so `KEY=` yields `undefined`
|
|
36
|
+
*/
|
|
37
|
+
const DOTENV_LINE_SOURCE = '(?:^|^)\\s*(?:export\\s+)?([\\w.-]+)(?:\\s*=\\s*?|:\\s+?)(\\s*\'(?:\\\\\'|[^\'])*\'|\\s*"(?:\\\\"|[^"])*"|\\s*`(?:\\\\`|[^`])*`|[^#\\r\\n]+)?\\s*(?:#.*)?(?:$|$)';
|
|
38
|
+
/** A value that is wrapped in a matched pair of `'`, `"`, or `` ` ``. */
|
|
39
|
+
const MATCHED_QUOTE_PAIR = /^(['"`])[\s\S]*\1$/;
|
|
40
|
+
/**
|
|
41
|
+
* Normalize one raw capture into the `rawValue` contract the value checkers
|
|
42
|
+
* expect.
|
|
43
|
+
*
|
|
44
|
+
* - a missing capture (`KEY=`) becomes `''`, mirroring `main.js:25`'s
|
|
45
|
+
* `(match[2] || '')` — never `undefined`, which would throw in the checkers
|
|
46
|
+
* - the leading whitespace the three quoted alternatives each absorb via their
|
|
47
|
+
* own `\s*` is a regex artifact, not part of the value, and is stripped
|
|
48
|
+
* - a quoted value is then returned **exactly as captured, quotes intact**, with
|
|
49
|
+
* no further trimming: the closing quote already bounds it precisely
|
|
50
|
+
* - an unquoted value has any trailing inline comment and the whitespace before
|
|
51
|
+
* it removed, mirroring `main.js:29`'s unconditional `.trim()` of unquoted
|
|
52
|
+
* captures. (The regex's `[^#\r\n]+` alternative already stops at the `#`, so
|
|
53
|
+
* in practice only the trailing whitespace is left to strip; the explicit
|
|
54
|
+
* comment strip below is belt-and-braces and cannot fire on a capture this
|
|
55
|
+
* regex produced.)
|
|
56
|
+
*/
|
|
57
|
+
const normalizeRawValue = (captured) => {
|
|
58
|
+
if (captured === undefined)
|
|
59
|
+
return '';
|
|
60
|
+
const value = captured.trimStart();
|
|
61
|
+
if (MATCHED_QUOTE_PAIR.test(value))
|
|
62
|
+
return value;
|
|
63
|
+
return value.replace(/\s*#[^\n]*$/, '').trimEnd();
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Map every key in `contents` to its raw pre-parse value.
|
|
67
|
+
*
|
|
68
|
+
* Duplicate keys resolve **last-match-wins**, matching `dotenv.parse`'s own
|
|
69
|
+
* behavior (verified: parsing `DUP=first\nDUP=second` returns `{DUP:'second'}`).
|
|
70
|
+
*
|
|
71
|
+
* @param contents - The raw text of a `.env` file.
|
|
72
|
+
* @returns Key → raw value, quotes intact. See {@link normalizeRawValue}.
|
|
73
|
+
*/
|
|
74
|
+
export const correlateRawValues = (contents) => {
|
|
75
|
+
// Built per call rather than hoisted: a `g`-flagged regex carries mutable
|
|
76
|
+
// `lastIndex`, and a shared instance would make concurrent or aborted scans
|
|
77
|
+
// silently skip entries.
|
|
78
|
+
const line = new RegExp(DOTENV_LINE_SOURCE, 'mg');
|
|
79
|
+
// Normalize line breaks exactly as `main.js:19` does before matching.
|
|
80
|
+
const normalized = contents.replace(/\r\n?/gm, '\n');
|
|
81
|
+
const rawValues = new Map();
|
|
82
|
+
let match = line.exec(normalized);
|
|
83
|
+
while (match !== null) {
|
|
84
|
+
const key = match[1];
|
|
85
|
+
if (key !== undefined) {
|
|
86
|
+
rawValues.set(key, normalizeRawValue(match[2]));
|
|
87
|
+
}
|
|
88
|
+
match = line.exec(normalized);
|
|
89
|
+
}
|
|
90
|
+
return rawValues;
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=dotenv-correlation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dotenv-correlation.js","sourceRoot":"","sources":["../src/dotenv-correlation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,kBAAkB,GACtB,kKAAkK,CAAA;AAEpK,yEAAyE;AACzE,MAAM,kBAAkB,GAAG,oBAAoB,CAAA;AAE/C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,iBAAiB,GAAG,CAAC,QAA4B,EAAU,EAAE;IACjE,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,EAAE,CAAA;IAErC,MAAM,KAAK,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAA;IAClC,IAAI,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IAEhD,OAAO,KAAK,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAA;AACnD,CAAC,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,QAAgB,EAAuB,EAAE;IAC1E,0EAA0E;IAC1E,4EAA4E;IAC5E,yBAAyB;IACzB,MAAM,IAAI,GAAG,IAAI,MAAM,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAA;IAEjD,sEAAsE;IACtE,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAA;IAEpD,MAAM,SAAS,GAAG,IAAI,GAAG,EAAkB,CAAA;IAC3C,IAAI,KAAK,GAA2B,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IACzD,OAAO,KAAK,KAAK,IAAI,EAAE,CAAC;QACtB,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;QACpB,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACtB,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QACjD,CAAC;QACD,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IAC/B,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve the canonical layered `.env*` file chain, low → high precedence.
|
|
3
|
+
*
|
|
4
|
+
* Extracted verbatim from `envs.ts` so the `config-lint` bin can lint exactly
|
|
5
|
+
* the files `envs()` would load, without reimplementing the precedence order.
|
|
6
|
+
*
|
|
7
|
+
* Internal module — deliberately NOT re-exported from `index.ts`.
|
|
8
|
+
*
|
|
9
|
+
* @param options.appDirectory - App root. Relative entries resolve against it;
|
|
10
|
+
* when empty the chain is empty, matching `envs()`'s existing behavior.
|
|
11
|
+
* @param options.secretsPath - Optional injected-secrets file, slotted between
|
|
12
|
+
* `.env.${env}` and `.env.${env}.local`.
|
|
13
|
+
* @param options.nodeEnv - `NODE_ENV`. `.env.local` is skipped when `'test'` so
|
|
14
|
+
* personal-machine overrides never leak into a deterministic test run.
|
|
15
|
+
* @param options.env - `ENV`, the stage selector.
|
|
16
|
+
* @returns Absolute paths in precedence order (later wins).
|
|
17
|
+
*/
|
|
18
|
+
export declare const resolveDotenvFileChain: ({ appDirectory, secretsPath, nodeEnv, env, }: {
|
|
19
|
+
appDirectory?: string;
|
|
20
|
+
secretsPath?: string;
|
|
21
|
+
nodeEnv?: string;
|
|
22
|
+
env?: string;
|
|
23
|
+
}) => string[];
|
|
24
|
+
//# sourceMappingURL=dotenv-files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dotenv-files.d.ts","sourceRoot":"","sources":["../src/dotenv-files.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,sBAAsB,GAAI,8CAKpC;IACD,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,KAAG,MAAM,EAqBT,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { isAbsolute } from 'node:path';
|
|
2
|
+
import { resolveApp } from './utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* Resolve the canonical layered `.env*` file chain, low → high precedence.
|
|
5
|
+
*
|
|
6
|
+
* Extracted verbatim from `envs.ts` so the `config-lint` bin can lint exactly
|
|
7
|
+
* the files `envs()` would load, without reimplementing the precedence order.
|
|
8
|
+
*
|
|
9
|
+
* Internal module — deliberately NOT re-exported from `index.ts`.
|
|
10
|
+
*
|
|
11
|
+
* @param options.appDirectory - App root. Relative entries resolve against it;
|
|
12
|
+
* when empty the chain is empty, matching `envs()`'s existing behavior.
|
|
13
|
+
* @param options.secretsPath - Optional injected-secrets file, slotted between
|
|
14
|
+
* `.env.${env}` and `.env.${env}.local`.
|
|
15
|
+
* @param options.nodeEnv - `NODE_ENV`. `.env.local` is skipped when `'test'` so
|
|
16
|
+
* personal-machine overrides never leak into a deterministic test run.
|
|
17
|
+
* @param options.env - `ENV`, the stage selector.
|
|
18
|
+
* @returns Absolute paths in precedence order (later wins).
|
|
19
|
+
*/
|
|
20
|
+
export const resolveDotenvFileChain = ({ appDirectory = '', secretsPath = '', nodeEnv, env, }) => {
|
|
21
|
+
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
|
|
22
|
+
const dotenvFiles = [
|
|
23
|
+
'.env',
|
|
24
|
+
// Don't include `.env.local` for `test` environment since normally you
|
|
25
|
+
// expect tests to produce the same results for everyone
|
|
26
|
+
nodeEnv !== 'test' && '.env.local',
|
|
27
|
+
env && `.env.${env}`,
|
|
28
|
+
secretsPath,
|
|
29
|
+
env && `.env.${env}.local`,
|
|
30
|
+
].filter(Boolean);
|
|
31
|
+
if (!appDirectory) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
return dotenvFiles.reduce((acc, dotenvFile) => {
|
|
35
|
+
return isAbsolute(dotenvFile)
|
|
36
|
+
? acc.concat(dotenvFile)
|
|
37
|
+
: acc.concat(resolveApp(dotenvFile, appDirectory));
|
|
38
|
+
}, []);
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=dotenv-files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dotenv-files.js","sourceRoot":"","sources":["../src/dotenv-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,E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","sources":["../src/dotenv-fixers.ts"],"names":[],"mappings":"AAUA;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,GAAI,KAAK,MAAM,EAAE,MAAM,MAAM,aAUhE,CAAA;AAGD,eAAO,MAAM,qBAAqB,GAAI,KAAK,MAAM,EAAE,MAAM,MAAM,aAO9D,CAAA;AAGD,eAAO,MAAM,iBAAiB,GAAI,KAAK,MAAM,EAAE,MAAM,MAAM,aAM1D,CAAA;AAOD,eAAO,MAAM,mBAAmB,GAAI,KAAK,MAAM,EAAE,MAAM,MAAM,aAS5D,CAAA;AAGD,eAAO,MAAM,uBAAuB,GAAI,KAAK,MAAM,EAAE,MAAM,MAAM,aAMhE,CAAA;AAOD,eAAO,MAAM,uBAAuB,GAAI,KAAK,MAAM,EAAE,MAAM,MAAM,aAUhE,CAAA;AAED,eAAO,MAAM,eAAe,SAzEiB,MAAM,QAAQ,MAAM,gBA6EhE,CAAA;AAED,eAAO,MAAM,gBAAgB,SA3CY,MAAM,QAAQ,MAAM,gBA+C5D,CAAA"}
|
package/dist/dotenv-fixers.js
CHANGED
|
@@ -32,15 +32,17 @@ export const lowercaseKeyFixer = (key, line) => {
|
|
|
32
32
|
}
|
|
33
33
|
return [key.toUpperCase(), line];
|
|
34
34
|
};
|
|
35
|
-
|
|
36
|
-
//
|
|
37
|
-
//
|
|
35
|
+
const WRAPPING_QUOTES = ["'", '"', '`'];
|
|
36
|
+
// Quote character: strips ONE outer matched pair (`'`, `"` or backtick), the
|
|
37
|
+
// same pair dotenv removes when parsing. A value with an unmatched or internal
|
|
38
|
+
// quote (`O'Brien`) has no safe fix and is left unchanged.
|
|
38
39
|
export const quoteCharacterFixer = (key, line) => {
|
|
39
|
-
if (!quoteCharacterChecker(line)) {
|
|
40
|
+
if (!quoteCharacterChecker(key, line)) {
|
|
40
41
|
return [key, line];
|
|
41
42
|
}
|
|
42
|
-
const
|
|
43
|
-
|
|
43
|
+
const wrapped = line.length >= 2 &&
|
|
44
|
+
WRAPPING_QUOTES.some((q) => line.startsWith(q) && line.endsWith(q));
|
|
45
|
+
return [key, wrapped ? line.slice(1, -1) : line];
|
|
44
46
|
};
|
|
45
47
|
// Fixes trailing whitespace.
|
|
46
48
|
export const trailingWhitespaceFixer = (key, line) => {
|
|
@@ -49,23 +51,18 @@ export const trailingWhitespaceFixer = (key, line) => {
|
|
|
49
51
|
}
|
|
50
52
|
return [key, line.trimEnd()];
|
|
51
53
|
};
|
|
52
|
-
// Value without quotes:
|
|
53
|
-
//
|
|
54
|
+
// Value without quotes: wraps a whitespace-containing unquoted value in a quote
|
|
55
|
+
// character the value does not contain, so dotenv parses it back unchanged.
|
|
56
|
+
// The trimmed value is wrapped because dotenv trims unquoted values. Double
|
|
57
|
+
// quotes are skipped when the value holds a literal `\n`, which dotenv would
|
|
58
|
+
// expand inside them. If no quote is safe, the value is left unchanged.
|
|
54
59
|
export const valueWithoutQuotesFixer = (key, line) => {
|
|
55
|
-
if (!valueWithoutQuotesChecker(line)) {
|
|
60
|
+
if (!valueWithoutQuotesChecker(key, line)) {
|
|
56
61
|
return [key, line];
|
|
57
62
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
else if (line.includes('"')) {
|
|
63
|
-
pureVal = `'${line}'`;
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
pureVal = `'${line}'`;
|
|
67
|
-
}
|
|
68
|
-
return [key, pureVal];
|
|
63
|
+
const value = line.trim();
|
|
64
|
+
const quote = WRAPPING_QUOTES.find((q) => !value.includes(q) && !(q === '"' && value.includes('\\n')));
|
|
65
|
+
return [key, quote ? `${quote}${value}${quote}` : line];
|
|
69
66
|
};
|
|
70
67
|
export const dotenvKeyFixers = [
|
|
71
68
|
incorrectDelimiterFixer,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dotenv-fixers.js","sourceRoot":"","sources":["../src/dotenv-fixers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAA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AAC,GAAG,EAAE,IAAI,CAAC,CAAA;IACpB,CAAC;IAED,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;AAC9B,CAAC,CAAA;AAED,gFAAgF;AAChF,4EAA4E;AAC5E,4EAA4E;AAC5E,6EAA6E;AAC7E,wEAAwE;AACxE,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,GAAW,EAAE,IAAY,EAAE,EAAE;IACnE,IAAI,CAAC,yBAAyB,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC;QAC1C,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IACpB,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAA;IACzB,MAAM,KAAK,GAAG,eAAe,CAAC,IAAI,CAChC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CACnE,CAAA;IACD,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;AACzD,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,uBAAuB;IACvB,qBAAqB;IACrB,iBAAiB;CAClB,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,mBAAmB;IACnB,uBAAuB;IACvB,uBAAuB;CACxB,CAAA"}
|
package/dist/envs.d.ts
CHANGED
|
@@ -9,7 +9,15 @@
|
|
|
9
9
|
* @param options - Configuration options.
|
|
10
10
|
* @param options.appDirectory - The directory of the app.
|
|
11
11
|
* @param options.secretsPath - The path to an injected secrets file.
|
|
12
|
-
* @param options.lint - Whether to perform linting on the loaded
|
|
12
|
+
* @param options.lint - Whether to perform `.env` hygiene linting on the loaded
|
|
13
|
+
* variables. **Defaults to `false`** — linting is opt-in. It used to default
|
|
14
|
+
* to `true` and ran on every consumer's boot via `./preload`, but its output
|
|
15
|
+
* was never correct (three of six checkers were fed the key where a value was
|
|
16
|
+
* expected, and the two quote checkers were fed post-parse values with the
|
|
17
|
+
* wrapping quotes already stripped, so they structurally could not observe the
|
|
18
|
+
* defect they exist to detect). Nothing could have correctly depended on the
|
|
19
|
+
* old default. Pass `lint: true` to run the checkers deliberately, or use the
|
|
20
|
+
* `config-lint` bin.
|
|
13
21
|
* @param options.override - Whether file values override existing process.env values.
|
|
14
22
|
* @returns An object containing the loaded environment variables.
|
|
15
23
|
*/
|
package/dist/envs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envs.d.ts","sourceRoot":"","sources":["../src/envs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"envs.d.ts","sourceRoot":"","sources":["../src/envs.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,IAAI,GAAI,iDAKlB;IACD,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;CACd,KAAG;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CAuE5C,CAAA"}
|
package/dist/envs.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { incorrectDelimiterChecker, leadingCharacterChecker, lowercaseKeyChecker, quoteCharacterChecker, trailingWhitespaceChecker, valueWithoutQuotesChecker, } from './dotenv-checkers.js';
|
|
3
|
+
import { correlateRawValues } from './dotenv-correlation.js';
|
|
4
|
+
import { resolveDotenvFileChain } from './dotenv-files.js';
|
|
4
5
|
import { parse, parseJSON } from './dotenv-with-expand.js';
|
|
5
|
-
import { mergeAssign, mergeDefaults
|
|
6
|
+
import { mergeAssign, mergeDefaults } from './utils.js';
|
|
6
7
|
/**
|
|
7
8
|
* Load environment variables from .env* files and optionally perform linting.
|
|
8
9
|
* Suppress warnings using silent if this file is missing. Dotenv files are
|
|
@@ -14,48 +15,74 @@ import { mergeAssign, mergeDefaults, resolveApp } from './utils.js';
|
|
|
14
15
|
* @param options - Configuration options.
|
|
15
16
|
* @param options.appDirectory - The directory of the app.
|
|
16
17
|
* @param options.secretsPath - The path to an injected secrets file.
|
|
17
|
-
* @param options.lint - Whether to perform linting on the loaded
|
|
18
|
+
* @param options.lint - Whether to perform `.env` hygiene linting on the loaded
|
|
19
|
+
* variables. **Defaults to `false`** — linting is opt-in. It used to default
|
|
20
|
+
* to `true` and ran on every consumer's boot via `./preload`, but its output
|
|
21
|
+
* was never correct (three of six checkers were fed the key where a value was
|
|
22
|
+
* expected, and the two quote checkers were fed post-parse values with the
|
|
23
|
+
* wrapping quotes already stripped, so they structurally could not observe the
|
|
24
|
+
* defect they exist to detect). Nothing could have correctly depended on the
|
|
25
|
+
* old default. Pass `lint: true` to run the checkers deliberately, or use the
|
|
26
|
+
* `config-lint` bin.
|
|
18
27
|
* @param options.override - Whether file values override existing process.env values.
|
|
19
28
|
* @returns An object containing the loaded environment variables.
|
|
20
29
|
*/
|
|
21
|
-
export const envs = ({ appDirectory = '', lint =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const ENV = process.env.ENV;
|
|
25
|
-
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
|
|
26
|
-
const dotenvFiles = [
|
|
27
|
-
'.env',
|
|
28
|
-
// Don't include `.env.local` for `test` environment since normally you
|
|
29
|
-
// expect tests to produce the same results for everyone
|
|
30
|
-
NODE_ENV !== 'test' && '.env.local',
|
|
31
|
-
ENV && `.env.${ENV}`,
|
|
30
|
+
export const envs = ({ appDirectory = '', lint = false, secretsPath = '', override = false, } = {}) => {
|
|
31
|
+
const absDotenvFiles = resolveDotenvFileChain({
|
|
32
|
+
appDirectory,
|
|
32
33
|
secretsPath,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return isAbsolute(dotenvFile)
|
|
38
|
-
? acc.concat(dotenvFile)
|
|
39
|
-
: acc.concat(resolveApp(dotenvFile, appDirectory));
|
|
40
|
-
}, []);
|
|
41
|
-
}
|
|
34
|
+
nodeEnv: process.env.NODE_ENV,
|
|
35
|
+
env: process.env.ENV,
|
|
36
|
+
});
|
|
37
|
+
const findings = [];
|
|
42
38
|
const resolvedEnv = absDotenvFiles.reduce((acc, dotenvFile) => {
|
|
43
39
|
if (!existsSync(dotenvFile)) {
|
|
44
40
|
return acc;
|
|
45
41
|
}
|
|
46
42
|
const contents = readFileSync(dotenvFile, { encoding: 'utf8' });
|
|
47
|
-
const
|
|
43
|
+
const isJson = dotenvFile.endsWith('.json');
|
|
44
|
+
const envs = isJson
|
|
48
45
|
? parseJSON(contents, false, {})
|
|
49
46
|
: parse(contents, false, {});
|
|
50
47
|
if (lint && envs) {
|
|
48
|
+
// Correlate against the `contents` already in scope — no second read.
|
|
49
|
+
// A `.json` secrets file is not dotenv syntax, so the raw-value line
|
|
50
|
+
// checkers do not apply to it; the key checkers still do.
|
|
51
|
+
const rawValues = isJson
|
|
52
|
+
? new Map()
|
|
53
|
+
: correlateRawValues(contents);
|
|
51
54
|
Object.entries(envs).forEach(([key, value]) => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
// Key checkers: unchanged call shape, unchanged `console.log` output.
|
|
56
|
+
incorrectDelimiterChecker(key, value);
|
|
57
|
+
leadingCharacterChecker(key);
|
|
58
|
+
lowercaseKeyChecker(key);
|
|
59
|
+
// UNCHANGED, deliberately. Under the previous uniform
|
|
60
|
+
// `checker(key, value)` call this single-parameter checker bound its
|
|
61
|
+
// `line` parameter to the *key*, never the value. Fixing that is an
|
|
62
|
+
// explicit, documented scope cut (see the plan's v3 changelog and
|
|
63
|
+
// follow-up 1), so its behavior is preserved exactly rather than
|
|
64
|
+
// quietly "improved" — zero regression in either direction.
|
|
65
|
+
trailingWhitespaceChecker(key);
|
|
66
|
+
if (isJson) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// Line checkers: fed the raw pre-parse value, wrapping quotes intact.
|
|
70
|
+
const rawValue = rawValues.get(key) ?? '';
|
|
71
|
+
const quoteFinding = quoteCharacterChecker(key, rawValue);
|
|
72
|
+
if (quoteFinding)
|
|
73
|
+
findings.push(quoteFinding);
|
|
74
|
+
const unquotedFinding = valueWithoutQuotesChecker(key, rawValue);
|
|
75
|
+
if (unquotedFinding)
|
|
76
|
+
findings.push(unquotedFinding);
|
|
55
77
|
});
|
|
56
78
|
}
|
|
57
79
|
return mergeAssign(acc, envs);
|
|
58
80
|
}, {});
|
|
81
|
+
// Sole formatting/printing point for findings. Every message already has its
|
|
82
|
+
// value masked to the last 4 characters by the checker that produced it.
|
|
83
|
+
for (const finding of findings) {
|
|
84
|
+
console.log(`warning: ${finding.message}`);
|
|
85
|
+
}
|
|
59
86
|
return override
|
|
60
87
|
? mergeAssign(process.env, resolvedEnv)
|
|
61
88
|
: mergeDefaults(process.env, resolvedEnv);
|
package/dist/envs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envs.js","sourceRoot":"","sources":["../src/envs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"envs.js","sourceRoot":"","sources":["../src/envs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAEL,yBAAyB,EACzB,uBAAuB,EACvB,mBAAmB,EACnB,qBAAqB,EACrB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,OAAO,CAAC,GAAG,CAAC,YAAY,OAAO,CAAC,OAAO,EAAE,CAAC,CAAA;IAC5C,CAAC;IAED,OAAO,QAAQ;QACb,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC;QACvC,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;AAC7C,CAAC,CAAA"}
|
package/dist/redact.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Value masking for lint findings.
|
|
3
|
+
*
|
|
4
|
+
* Local port of `packages/env-doctor/src/redact.ts`'s `maskLast4`, duplicated
|
|
5
|
+
* deliberately rather than imported across packages: `@cogs/config` is the
|
|
6
|
+
* published, dependency-light loader that every app preloads, and
|
|
7
|
+
* `@cogs/env-doctor` is a private tool. A cross-package import would invert that
|
|
8
|
+
* dependency direction for four lines of string slicing.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Mask a value to its last 4 characters so a finding can say *which* value it
|
|
12
|
+
* is about without printing a secret in full.
|
|
13
|
+
*
|
|
14
|
+
* Values of 4 characters or fewer are masked outright rather than shown, and an
|
|
15
|
+
* empty value renders as `(empty)` so a `KEY=` line is still legible.
|
|
16
|
+
*/
|
|
17
|
+
export declare const maskLast4: (value: string) => string;
|
|
18
|
+
//# sourceMappingURL=redact.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redact.d.ts","sourceRoot":"","sources":["../src/redact.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,KAAG,MAIzC,CAAA"}
|