varlock 0.4.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto-load.js +6 -6
- package/dist/{chunk-PCRIVT4T.js → chunk-2AGKN64R.js} +663 -258
- package/dist/chunk-2AGKN64R.js.map +1 -0
- package/dist/{chunk-BGPQX6XO.js → chunk-3J7BFRB4.js} +372 -446
- package/dist/chunk-3J7BFRB4.js.map +1 -0
- package/dist/{chunk-3U2C5ACW.js → chunk-4JMFWK65.js} +5 -5
- package/dist/{chunk-3U2C5ACW.js.map → chunk-4JMFWK65.js.map} +1 -1
- package/dist/{chunk-TYIS6T2T.js → chunk-BC7LU4LG.js} +3 -3
- package/dist/{chunk-TYIS6T2T.js.map → chunk-BC7LU4LG.js.map} +1 -1
- package/dist/chunk-EXG5VPNZ.js +17 -0
- package/dist/chunk-EXG5VPNZ.js.map +1 -0
- package/dist/{chunk-P7WVEZYA.js → chunk-FYZ7LKLX.js} +27 -7
- package/dist/chunk-FYZ7LKLX.js.map +1 -0
- package/dist/{chunk-CBWJHW3M.js → chunk-G7FDCTNA.js} +8 -8
- package/dist/{chunk-CBWJHW3M.js.map → chunk-G7FDCTNA.js.map} +1 -1
- package/dist/{chunk-WAMBVZL2.js → chunk-IMB5QAZS.js} +38 -16
- package/dist/chunk-IMB5QAZS.js.map +1 -0
- package/dist/{chunk-NWY5IIPW.js → chunk-J7PA7B2U.js} +6 -81
- package/dist/chunk-J7PA7B2U.js.map +1 -0
- package/dist/{chunk-HS2NN4VF.js → chunk-JCJISIY6.js} +6 -6
- package/dist/{chunk-HS2NN4VF.js.map → chunk-JCJISIY6.js.map} +1 -1
- package/dist/{chunk-I4RYFNPM.js → chunk-KKNNZWYD.js} +3 -3
- package/dist/{chunk-I4RYFNPM.js.map → chunk-KKNNZWYD.js.map} +1 -1
- package/dist/{chunk-QQDWRXNU.js → chunk-LVZSZAKN.js} +3 -3
- package/dist/{chunk-QQDWRXNU.js.map → chunk-LVZSZAKN.js.map} +1 -1
- package/dist/{chunk-ZXJ4CEDK.js → chunk-MYHVSJ3X.js} +3 -3
- package/dist/{chunk-ZXJ4CEDK.js.map → chunk-MYHVSJ3X.js.map} +1 -1
- package/dist/{chunk-PIOJV2A7.js → chunk-NPPZVF24.js} +4 -4
- package/dist/{chunk-PIOJV2A7.js.map → chunk-NPPZVF24.js.map} +1 -1
- package/dist/{chunk-RQDMJMKL.js → chunk-PMBDCWD5.js} +6 -5
- package/dist/chunk-PMBDCWD5.js.map +1 -0
- package/dist/{chunk-YWFNGAPT.js → chunk-SHONHP24.js} +6 -6
- package/dist/{chunk-YWFNGAPT.js.map → chunk-SHONHP24.js.map} +1 -1
- package/dist/chunk-TLEEAUD7.js +68 -0
- package/dist/chunk-TLEEAUD7.js.map +1 -0
- package/dist/{chunk-LJTQEZE2.js → chunk-UVWLW5KD.js} +6 -6
- package/dist/{chunk-LJTQEZE2.js.map → chunk-UVWLW5KD.js.map} +1 -1
- package/dist/{chunk-MIBOBKI4.js → chunk-XLYSNOR3.js} +15 -3
- package/dist/chunk-XLYSNOR3.js.map +1 -0
- package/dist/{chunk-LFBK6MZU.js → chunk-ZLAUDWOL.js} +6 -6
- package/dist/{chunk-LFBK6MZU.js.map → chunk-ZLAUDWOL.js.map} +1 -1
- package/dist/cli/cli-executable.js +24 -24
- package/dist/cli/cli-executable.js.map +1 -1
- package/dist/config-item-NO5PKZRH.js +5 -0
- package/dist/{config-item-K7KWEJD2.js.map → config-item-NO5PKZRH.js.map} +1 -1
- package/dist/dotenv-compat.js +6 -6
- package/dist/{env-graph-COORmJlH.d.ts → env-graph-Cz_c5P6Y.d.ts} +24 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +11 -11
- package/dist/init.command-AV4EWYIT.js +12 -0
- package/dist/{init.command-SZPMB525.js.map → init.command-AV4EWYIT.js.map} +1 -1
- package/dist/load.command-5JQUW3H7.js +11 -0
- package/dist/{load.command-XSOTCSGA.js.map → load.command-5JQUW3H7.js.map} +1 -1
- package/dist/plugin-lib.d.ts +2 -2
- package/dist/printenv.command-SBB6GVC2.js +12 -0
- package/dist/{printenv.command-4HWCHHCY.js.map → printenv.command-SBB6GVC2.js.map} +1 -1
- package/dist/run.command-HTGTG6ER.js +12 -0
- package/dist/{run.command-2HLQ2AYT.js.map → run.command-HTGTG6ER.js.map} +1 -1
- package/dist/runtime/env.d.ts +7 -2
- package/dist/runtime/env.js +2 -2
- package/dist/runtime/init-edge.cjs +297 -0
- package/dist/runtime/init-edge.d.cts +1 -0
- package/dist/runtime/init-server.cjs +370 -0
- package/dist/runtime/init-server.d.cts +20 -0
- package/dist/runtime/patch-console.js +3 -3
- package/dist/runtime/patch-response.js +3 -3
- package/dist/runtime/patch-server-response.js +3 -3
- package/dist/scan.command-ADKVWN5T.js +13 -0
- package/dist/{scan.command-4J64EB4Z.js.map → scan.command-ADKVWN5T.js.map} +1 -1
- package/dist/telemetry.command-CQFTGXPF.js +11 -0
- package/dist/{telemetry.command-NLJFD63U.js.map → telemetry.command-CQFTGXPF.js.map} +1 -1
- package/dist/typegen.command-A544SFYM.js +12 -0
- package/dist/{typegen.command-7BE3K6PU.js.map → typegen.command-A544SFYM.js.map} +1 -1
- package/package.json +12 -2
- package/dist/chunk-6SS4YD2I.js +0 -156
- package/dist/chunk-6SS4YD2I.js.map +0 -1
- package/dist/chunk-BGPQX6XO.js.map +0 -1
- package/dist/chunk-MBYYRBL6.js +0 -17
- package/dist/chunk-MBYYRBL6.js.map +0 -1
- package/dist/chunk-MIBOBKI4.js.map +0 -1
- package/dist/chunk-NWY5IIPW.js.map +0 -1
- package/dist/chunk-P7WVEZYA.js.map +0 -1
- package/dist/chunk-PCRIVT4T.js.map +0 -1
- package/dist/chunk-RQDMJMKL.js.map +0 -1
- package/dist/chunk-WAMBVZL2.js.map +0 -1
- package/dist/config-item-K7KWEJD2.js +0 -5
- package/dist/init.command-SZPMB525.js +0 -12
- package/dist/load.command-XSOTCSGA.js +0 -11
- package/dist/printenv.command-4HWCHHCY.js +0 -12
- package/dist/run.command-2HLQ2AYT.js +0 -12
- package/dist/scan.command-4J64EB4Z.js +0 -13
- package/dist/telemetry.command-NLJFD63U.js +0 -11
- package/dist/typegen.command-7BE3K6PU.js +0 -12
|
@@ -101,7 +101,7 @@ type EnvGraphDataTypeDef<CoerceReturnType, ValidateInputType = FallbackIfUnknown
|
|
|
101
101
|
* - if validation passes, should return true
|
|
102
102
|
* - if validation fails, should return a ValidationError or array of errors - or throw an error
|
|
103
103
|
* */
|
|
104
|
-
validate
|
|
104
|
+
validate?: (value: ValidateInputType) => MaybePromise<(true | undefined | void | Error | Array<Error>)>;
|
|
105
105
|
/** will make items of this type sensitive, unless overridden specifically on that item */
|
|
106
106
|
sensitive?: boolean;
|
|
107
107
|
/** adds docs info for these */
|
|
@@ -389,6 +389,8 @@ declare class DotEnvFileDataSource extends FileBasedDataSource {
|
|
|
389
389
|
static validFileExtensions: never[];
|
|
390
390
|
parsedFile?: ParsedEnvSpecFile;
|
|
391
391
|
_parseContents(): Promise<void>;
|
|
392
|
+
private _validateDecoratorPlacement;
|
|
393
|
+
private _locationFromParsed;
|
|
392
394
|
}
|
|
393
395
|
|
|
394
396
|
type ConfigItemDef = {
|
|
@@ -525,6 +527,7 @@ declare class VarlockPlugin {
|
|
|
525
527
|
get icon(): string;
|
|
526
528
|
set icon(val: string);
|
|
527
529
|
loadingError?: Error;
|
|
530
|
+
warnings: Array<SchemaError>;
|
|
528
531
|
readonly localPath?: string;
|
|
529
532
|
/** reference to the `@plugin()` decorator instance(s) that installed the plugin */
|
|
530
533
|
installDecoratorInstances: Array<DecoratorInstance>;
|
|
@@ -549,6 +552,26 @@ declare class VarlockPlugin {
|
|
|
549
552
|
registerItemDecorator<T>(decoratorDef: ItemDecoratorDef<T>): void;
|
|
550
553
|
readonly resolverFunctions?: Array<ResolverDef<any>>;
|
|
551
554
|
registerResolverFunction<T>(resolverDef: ResolverDef<T>): void;
|
|
555
|
+
/**
|
|
556
|
+
* Declare standard env vars this plugin uses.
|
|
557
|
+
* Set during plugin init — the loading infrastructure will automatically
|
|
558
|
+
* check for these vars and generate warnings if they are detected but not wired up.
|
|
559
|
+
*
|
|
560
|
+
* `key` accepts a single env var name or an array of alternatives — the first match is used.
|
|
561
|
+
* `dataType` is used to generate `# @type=...` schema lines for vars not in the schema.
|
|
562
|
+
*/
|
|
563
|
+
standardVars?: {
|
|
564
|
+
initDecorator: string;
|
|
565
|
+
params: Record<string, {
|
|
566
|
+
key: string | Array<string>;
|
|
567
|
+
dataType?: string;
|
|
568
|
+
}>;
|
|
569
|
+
};
|
|
570
|
+
/** called by the loading infrastructure — checks declared standardVars against the graph */
|
|
571
|
+
_checkStandardVars(graph: {
|
|
572
|
+
overrideValues: Record<string, string | undefined>;
|
|
573
|
+
configSchema: Record<string, any>;
|
|
574
|
+
}): void;
|
|
552
575
|
get pluginFilePath(): string;
|
|
553
576
|
executePluginModule(): Promise<void>;
|
|
554
577
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as EnvGraph, a as DotEnvFileDataSource, C as ConfigLoadError, b as SchemaError, d as ValidationError, e as CoercionError, f as ResolutionError } from './env-graph-
|
|
2
|
-
export { D as Debugger, S as SerializedEnvGraph, c as createDebug } from './env-graph-
|
|
1
|
+
import { E as EnvGraph, a as DotEnvFileDataSource, C as ConfigLoadError, b as SchemaError, d as ValidationError, e as CoercionError, f as ResolutionError } from './env-graph-Cz_c5P6Y.js';
|
|
2
|
+
export { D as Debugger, S as SerializedEnvGraph, c as createDebug } from './env-graph-Cz_c5P6Y.js';
|
|
3
3
|
import { initVarlockEnv } from './runtime/env.js';
|
|
4
4
|
export { ENV } from './runtime/env.js';
|
|
5
5
|
export { patchGlobalConsole } from './runtime/patch-console.js';
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export { patchGlobalResponse } from './chunk-
|
|
2
|
-
export { patchGlobalServerResponse } from './chunk-
|
|
3
|
-
import { checkBunVersion } from './chunk-
|
|
4
|
-
import { checkForConfigErrors } from './chunk-
|
|
5
|
-
import { loadVarlockEnvGraph } from './chunk-
|
|
6
|
-
import { loadEnvGraph } from './chunk-
|
|
7
|
-
import { ResolutionError, CoercionError, ValidationError, SchemaError, ConfigLoadError, DotEnvFileDataSource, EnvGraph } from './chunk-
|
|
1
|
+
export { patchGlobalResponse } from './chunk-LVZSZAKN.js';
|
|
2
|
+
export { patchGlobalServerResponse } from './chunk-MYHVSJ3X.js';
|
|
3
|
+
import { checkBunVersion } from './chunk-KKNNZWYD.js';
|
|
4
|
+
import { checkForConfigErrors } from './chunk-FYZ7LKLX.js';
|
|
5
|
+
import { loadVarlockEnvGraph } from './chunk-EXG5VPNZ.js';
|
|
6
|
+
import { loadEnvGraph } from './chunk-J7PA7B2U.js';
|
|
7
|
+
import { ResolutionError, CoercionError, ValidationError, SchemaError, ConfigLoadError, DotEnvFileDataSource, EnvGraph } from './chunk-2AGKN64R.js';
|
|
8
8
|
export { createDebug } from './chunk-QZ6HBRJC.js';
|
|
9
|
-
export { patchGlobalConsole } from './chunk-
|
|
10
|
-
import { initVarlockEnv } from './chunk-
|
|
11
|
-
export { ENV } from './chunk-
|
|
12
|
-
import './chunk-
|
|
9
|
+
export { patchGlobalConsole } from './chunk-BC7LU4LG.js';
|
|
10
|
+
import { initVarlockEnv } from './chunk-IMB5QAZS.js';
|
|
11
|
+
export { ENV } from './chunk-IMB5QAZS.js';
|
|
12
|
+
import './chunk-XLYSNOR3.js';
|
|
13
13
|
import { __name } from './chunk-6PEHRAEP.js';
|
|
14
14
|
|
|
15
15
|
// src/index.ts
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { commandFn, commandSpec } from './chunk-3J7BFRB4.js';
|
|
2
|
+
import './chunk-Y3ITSQA4.js';
|
|
3
|
+
import './chunk-TLEEAUD7.js';
|
|
4
|
+
import './chunk-NPPZVF24.js';
|
|
5
|
+
import './chunk-4A54P4EM.js';
|
|
6
|
+
import './chunk-J7PA7B2U.js';
|
|
7
|
+
import './chunk-2AGKN64R.js';
|
|
8
|
+
import './chunk-QZ6HBRJC.js';
|
|
9
|
+
import './chunk-XLYSNOR3.js';
|
|
10
|
+
import './chunk-6PEHRAEP.js';
|
|
11
|
+
//# sourceMappingURL=init.command-AV4EWYIT.js.map
|
|
12
|
+
//# sourceMappingURL=init.command-AV4EWYIT.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"init.command-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"init.command-AV4EWYIT.js"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { commandFn, commandSpec } from './chunk-PMBDCWD5.js';
|
|
2
|
+
import './chunk-4A54P4EM.js';
|
|
3
|
+
import './chunk-FYZ7LKLX.js';
|
|
4
|
+
import './chunk-EXG5VPNZ.js';
|
|
5
|
+
import './chunk-J7PA7B2U.js';
|
|
6
|
+
import './chunk-2AGKN64R.js';
|
|
7
|
+
import './chunk-QZ6HBRJC.js';
|
|
8
|
+
import './chunk-XLYSNOR3.js';
|
|
9
|
+
import './chunk-6PEHRAEP.js';
|
|
10
|
+
//# sourceMappingURL=load.command-5JQUW3H7.js.map
|
|
11
|
+
//# sourceMappingURL=load.command-5JQUW3H7.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"load.command-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"load.command-5JQUW3H7.js"}
|
package/dist/plugin-lib.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { V as VarlockPlugin } from './env-graph-
|
|
2
|
-
export { D as Debugger, R as Resolver, c as createDebug } from './env-graph-
|
|
1
|
+
import { V as VarlockPlugin } from './env-graph-Cz_c5P6Y.js';
|
|
2
|
+
export { D as Debugger, R as Resolver, c as createDebug } from './env-graph-Cz_c5P6Y.js';
|
|
3
3
|
import '@env-spec/parser';
|
|
4
4
|
import '@env-spec/utils/type-utils';
|
|
5
5
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { commandFn, commandSpec } from './chunk-JCJISIY6.js';
|
|
2
|
+
import './chunk-NPPZVF24.js';
|
|
3
|
+
import './chunk-4A54P4EM.js';
|
|
4
|
+
import './chunk-FYZ7LKLX.js';
|
|
5
|
+
import './chunk-EXG5VPNZ.js';
|
|
6
|
+
import './chunk-J7PA7B2U.js';
|
|
7
|
+
import './chunk-2AGKN64R.js';
|
|
8
|
+
import './chunk-QZ6HBRJC.js';
|
|
9
|
+
import './chunk-XLYSNOR3.js';
|
|
10
|
+
import './chunk-6PEHRAEP.js';
|
|
11
|
+
//# sourceMappingURL=printenv.command-SBB6GVC2.js.map
|
|
12
|
+
//# sourceMappingURL=printenv.command-SBB6GVC2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"printenv.command-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"printenv.command-SBB6GVC2.js"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { commandFn, commandSpec } from './chunk-ZLAUDWOL.js';
|
|
2
|
+
import './chunk-4A54P4EM.js';
|
|
3
|
+
import './chunk-FYZ7LKLX.js';
|
|
4
|
+
import './chunk-EXG5VPNZ.js';
|
|
5
|
+
import './chunk-J7PA7B2U.js';
|
|
6
|
+
import './chunk-2AGKN64R.js';
|
|
7
|
+
import './chunk-QZ6HBRJC.js';
|
|
8
|
+
import './chunk-IMB5QAZS.js';
|
|
9
|
+
import './chunk-XLYSNOR3.js';
|
|
10
|
+
import './chunk-6PEHRAEP.js';
|
|
11
|
+
//# sourceMappingURL=run.command-HTGTG6ER.js.map
|
|
12
|
+
//# sourceMappingURL=run.command-HTGTG6ER.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"run.command-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"run.command-HTGTG6ER.js"}
|
package/dist/runtime/env.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { S as SerializedEnvGraph } from '../env-graph-
|
|
1
|
+
import { S as SerializedEnvGraph } from '../env-graph-Cz_c5P6Y.js';
|
|
2
2
|
import '@env-spec/parser';
|
|
3
3
|
import '@env-spec/utils/type-utils';
|
|
4
4
|
|
|
5
5
|
declare function resetRedactionMap(graph: SerializedEnvGraph): void;
|
|
6
|
+
/** Returns diagnostic info about the current redaction state (safe to expose — no secrets) */
|
|
7
|
+
declare function getRedactionMapInfo(): {
|
|
8
|
+
sensitiveItemCount: number;
|
|
9
|
+
hasRedactorRegex: boolean;
|
|
10
|
+
};
|
|
6
11
|
/**
|
|
7
12
|
* Redacts senstive config values from any string/array/object/etc
|
|
8
13
|
*
|
|
@@ -26,4 +31,4 @@ interface TypedEnvSchema {
|
|
|
26
31
|
}
|
|
27
32
|
declare const ENV: TypedEnvSchema;
|
|
28
33
|
|
|
29
|
-
export { ENV, type TypedEnvSchema, initVarlockEnv, redactSensitiveConfig, resetRedactionMap, revealSensitiveConfig, scanForLeaks, varlockSettings };
|
|
34
|
+
export { ENV, type TypedEnvSchema, getRedactionMapInfo, initVarlockEnv, redactSensitiveConfig, resetRedactionMap, revealSensitiveConfig, scanForLeaks, varlockSettings };
|
package/dist/runtime/env.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { ENV, initVarlockEnv, redactSensitiveConfig, resetRedactionMap, revealSensitiveConfig, scanForLeaks, varlockSettings } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
export { ENV, getRedactionMapInfo, initVarlockEnv, redactSensitiveConfig, resetRedactionMap, revealSensitiveConfig, scanForLeaks, varlockSettings } from '../chunk-IMB5QAZS.js';
|
|
2
|
+
import '../chunk-XLYSNOR3.js';
|
|
3
3
|
import '../chunk-6PEHRAEP.js';
|
|
4
4
|
//# sourceMappingURL=env.js.map
|
|
5
5
|
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/runtime/lib/redaction.ts
|
|
4
|
+
function redactString(valStr, modeOrOpts, hideLength = true) {
|
|
5
|
+
if (!valStr) return valStr;
|
|
6
|
+
let mode;
|
|
7
|
+
{
|
|
8
|
+
mode = modeOrOpts;
|
|
9
|
+
}
|
|
10
|
+
const hiddenLength = hideLength ? 5 : valStr.length - 2;
|
|
11
|
+
const hiddenStr = "\u2592".repeat(hiddenLength);
|
|
12
|
+
if (mode === "show_last_2") {
|
|
13
|
+
return `${hiddenStr}${valStr.substring(valStr.length - 2, valStr.length)}`;
|
|
14
|
+
} else if (mode === "show_first_last") {
|
|
15
|
+
return `${valStr.substring(0, 1)}${hiddenStr}${valStr.substring(valStr.length - 1, valStr.length)}`;
|
|
16
|
+
} else {
|
|
17
|
+
return `${valStr.substring(0, 2)}${hiddenStr}`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/lib/detect-runtime.ts
|
|
22
|
+
var versionsStr = "versions";
|
|
23
|
+
var processVersions = typeof process !== "undefined" && process[versionsStr];
|
|
24
|
+
processVersions && processVersions.node != null;
|
|
25
|
+
typeof window !== "undefined" && window.name === "nodejs" || typeof navigator !== "undefined" && "userAgent" in navigator && typeof navigator.userAgent === "string" && (navigator.userAgent.includes("Node.js") || navigator.userAgent.includes("jsdom"));
|
|
26
|
+
typeof Deno !== "undefined" && typeof Deno.version !== "undefined" && typeof Deno.version.deno !== "undefined";
|
|
27
|
+
processVersions && processVersions.bun != null;
|
|
28
|
+
var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement === "function" && typeof navigator !== "undefined" && typeof navigator.userAgent === "string";
|
|
29
|
+
|
|
30
|
+
// src/runtime/lib/debug.ts
|
|
31
|
+
function debug(...args) {
|
|
32
|
+
if (!globalThis.process?.env.DEBUG_VARLOCK) return;
|
|
33
|
+
console.log(...args);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/runtime/env.ts
|
|
37
|
+
function isString(s) {
|
|
38
|
+
return Object.prototype.toString.call(s) === "[object String]";
|
|
39
|
+
}
|
|
40
|
+
var UNMASK_STR = "\u{1F441}";
|
|
41
|
+
var REDACTION_STATE_KEY = "__varlockRedactionState";
|
|
42
|
+
function getRedactionState() {
|
|
43
|
+
if (!globalThis[REDACTION_STATE_KEY]) {
|
|
44
|
+
globalThis[REDACTION_STATE_KEY] = {
|
|
45
|
+
sensitiveSecretsMap: {},
|
|
46
|
+
redactorFindReplace: void 0
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return globalThis[REDACTION_STATE_KEY];
|
|
50
|
+
}
|
|
51
|
+
function resetRedactionMap(graph) {
|
|
52
|
+
const state = getRedactionState();
|
|
53
|
+
state.sensitiveSecretsMap = {};
|
|
54
|
+
for (const itemKey in graph.config) {
|
|
55
|
+
const item = graph.config[itemKey];
|
|
56
|
+
if (item.isSensitive && item.value && isString(item.value)) {
|
|
57
|
+
const redacted = redactString(item.value);
|
|
58
|
+
if (redacted) state.sensitiveSecretsMap[item.value] = { key: itemKey, redacted };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (!Object.keys(state.sensitiveSecretsMap).length) {
|
|
62
|
+
state.redactorFindReplace = void 0;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const findRegex = new RegExp(
|
|
66
|
+
[
|
|
67
|
+
`(${UNMASK_STR} )?`,
|
|
68
|
+
"(",
|
|
69
|
+
Object.keys(state.sensitiveSecretsMap).map((s) => s.replace(/[()[\]{}*+?^$|#.,/\\\s-]/g, "\\$&")).sort((a, b) => b.length - a.length).join("|"),
|
|
70
|
+
")",
|
|
71
|
+
`( ${UNMASK_STR})?`
|
|
72
|
+
].join(""),
|
|
73
|
+
"g"
|
|
74
|
+
);
|
|
75
|
+
const replaceFn = (match, pre, val, post) => {
|
|
76
|
+
if (pre && post) return match;
|
|
77
|
+
return state.sensitiveSecretsMap[val].redacted;
|
|
78
|
+
};
|
|
79
|
+
state.redactorFindReplace = { find: findRegex, replace: replaceFn };
|
|
80
|
+
}
|
|
81
|
+
function redactSensitiveConfig(o) {
|
|
82
|
+
const { redactorFindReplace } = getRedactionState();
|
|
83
|
+
if (!redactorFindReplace) return o;
|
|
84
|
+
if (!o) return o;
|
|
85
|
+
if (Array.isArray(o)) {
|
|
86
|
+
return o.map(redactSensitiveConfig);
|
|
87
|
+
}
|
|
88
|
+
if (o && typeof o === "object" && Object.getPrototypeOf(o) === Object.prototype) {
|
|
89
|
+
try {
|
|
90
|
+
return JSON.parse(redactSensitiveConfig(JSON.stringify(o)));
|
|
91
|
+
} catch (err) {
|
|
92
|
+
return o;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const type = typeof o;
|
|
96
|
+
if (type === "string" || type === "object" && Object.prototype.toString.call(o) === "[object String]") {
|
|
97
|
+
return o.replaceAll(redactorFindReplace.find, redactorFindReplace.replace);
|
|
98
|
+
}
|
|
99
|
+
return o;
|
|
100
|
+
}
|
|
101
|
+
function revealSensitiveConfig(secretStr) {
|
|
102
|
+
if (!globalThis._varlockOrigWriteToConsoleFn) return secretStr;
|
|
103
|
+
return `${UNMASK_STR} ${secretStr} ${UNMASK_STR}`;
|
|
104
|
+
}
|
|
105
|
+
function scanForLeaks(toScan, meta) {
|
|
106
|
+
debug("\u26A1\uFE0F varlock scanning for leaks");
|
|
107
|
+
if (!toScan) return toScan;
|
|
108
|
+
function scanStrForLeaks(strToScan) {
|
|
109
|
+
const { sensitiveSecretsMap } = getRedactionState();
|
|
110
|
+
for (const sensitiveValue in sensitiveSecretsMap) {
|
|
111
|
+
if (strToScan.includes(sensitiveValue)) {
|
|
112
|
+
const itemKey = sensitiveSecretsMap[sensitiveValue].key;
|
|
113
|
+
console.error([
|
|
114
|
+
"",
|
|
115
|
+
`\u{1F6A8} ${"DETECTED LEAKED SENSITIVE CONFIG"} \u{1F6A8}`,
|
|
116
|
+
`> Config item key: ${itemKey}`,
|
|
117
|
+
...meta?.method ? [`> Scan method: ${meta.method}`] : [],
|
|
118
|
+
...meta?.file ? [`> File: ${meta.file}`] : [],
|
|
119
|
+
""
|
|
120
|
+
].join("\n"));
|
|
121
|
+
throw new Error(`\u{1F6A8} DETECTED LEAKED SENSITIVE CONFIG - ${itemKey}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (isString(toScan)) {
|
|
126
|
+
scanStrForLeaks(toScan);
|
|
127
|
+
return toScan;
|
|
128
|
+
} else if (typeof Buffer !== "undefined" && toScan instanceof Buffer) {
|
|
129
|
+
scanStrForLeaks(toScan.toString());
|
|
130
|
+
return toScan;
|
|
131
|
+
} else if (toScan instanceof ReadableStream) {
|
|
132
|
+
if (toScan.locked) {
|
|
133
|
+
return toScan;
|
|
134
|
+
}
|
|
135
|
+
const chunkDecoder = new TextDecoder();
|
|
136
|
+
return toScan.pipeThrough(
|
|
137
|
+
new TransformStream({
|
|
138
|
+
transform(chunk, controller) {
|
|
139
|
+
const chunkStr = chunkDecoder.decode(chunk);
|
|
140
|
+
scanStrForLeaks(chunkStr);
|
|
141
|
+
controller.enqueue(chunk);
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
return toScan;
|
|
147
|
+
}
|
|
148
|
+
var initializedEnv = false;
|
|
149
|
+
var envValues = {};
|
|
150
|
+
var varlockSettings = {};
|
|
151
|
+
var processExists = !!globalThis.process;
|
|
152
|
+
var originalProcessEnv = { ...processExists && process.env };
|
|
153
|
+
var varlockInjectedProcessEnvKeys;
|
|
154
|
+
function initVarlockEnv(opts) {
|
|
155
|
+
debug("\u26A1\uFE0F INIT VARLOCK ENV!", initializedEnv, !!globalThis.__varlockLoadedEnv, !!globalThis.process?.env.__VARLOCK_ENV);
|
|
156
|
+
if (isBrowser && !globalThis.process?.env.__VARLOCK_ENV) {
|
|
157
|
+
initializedEnv = true;
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
let serializedEnvData;
|
|
161
|
+
if (globalThis.__varlockLoadedEnv) {
|
|
162
|
+
serializedEnvData = globalThis.__varlockLoadedEnv;
|
|
163
|
+
} else if (processExists && process.env.__VARLOCK_ENV) {
|
|
164
|
+
serializedEnvData = JSON.parse(process.env.__VARLOCK_ENV);
|
|
165
|
+
} else {
|
|
166
|
+
if (opts?.allowFail) return;
|
|
167
|
+
console.error([
|
|
168
|
+
"",
|
|
169
|
+
"\u{1F6A8} initVarlockEnv failed \u{1F6A8}",
|
|
170
|
+
"try rerunning your command via `varlock run`",
|
|
171
|
+
""
|
|
172
|
+
].join("\n"));
|
|
173
|
+
throw new Error("initVarlockEnv failed");
|
|
174
|
+
}
|
|
175
|
+
Object.assign(varlockSettings, serializedEnvData.settings);
|
|
176
|
+
resetRedactionMap(serializedEnvData);
|
|
177
|
+
const setProcessEnv = processExists;
|
|
178
|
+
if (setProcessEnv) {
|
|
179
|
+
if (varlockInjectedProcessEnvKeys) {
|
|
180
|
+
for (const key of varlockInjectedProcessEnvKeys) delete process.env[key];
|
|
181
|
+
for (const key of Object.keys(originalProcessEnv)) process.env[key] = originalProcessEnv[key];
|
|
182
|
+
}
|
|
183
|
+
varlockInjectedProcessEnvKeys = [];
|
|
184
|
+
}
|
|
185
|
+
for (const itemKey in serializedEnvData.config) {
|
|
186
|
+
const itemValue = serializedEnvData.config[itemKey].value;
|
|
187
|
+
envValues[itemKey] = itemValue;
|
|
188
|
+
if (setProcessEnv) {
|
|
189
|
+
varlockInjectedProcessEnvKeys?.push(itemKey);
|
|
190
|
+
process.env[itemKey] = itemValue === void 0 ? "" : String(itemValue);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
initializedEnv = true;
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
if (!initializedEnv) {
|
|
197
|
+
initVarlockEnv({ allowFail: true });
|
|
198
|
+
}
|
|
199
|
+
} catch (err) {
|
|
200
|
+
}
|
|
201
|
+
var IGNORED_PROXY_KEYS = [
|
|
202
|
+
// vue - see https://github.com/vuejs/core/blob/70773d00985135a50556c61fb9855ed6b930cb82/packages/reactivity/src/ref.ts#L101
|
|
203
|
+
"__v_isRef"
|
|
204
|
+
];
|
|
205
|
+
var EnvProxy = new Proxy({}, {
|
|
206
|
+
get(target, prop) {
|
|
207
|
+
if (typeof prop === "symbol") return;
|
|
208
|
+
if (IGNORED_PROXY_KEYS.includes(prop)) return;
|
|
209
|
+
if (!initializedEnv) {
|
|
210
|
+
throw new Error("varlock ENV not initialized");
|
|
211
|
+
}
|
|
212
|
+
if (prop in envValues) return envValues[prop];
|
|
213
|
+
if (globalThis.__varlockThrowOnMissingKeys) {
|
|
214
|
+
if (globalThis.__varlockValidKeys && globalThis.__varlockValidKeys.includes(prop)) {
|
|
215
|
+
throw new Error(`\`ENV.${prop}\` exists, but is not available in this environment`);
|
|
216
|
+
} else {
|
|
217
|
+
throw new Error(`\`ENV.${prop}\` does not exist`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return void 0;
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
var ENV = EnvProxy;
|
|
224
|
+
|
|
225
|
+
// src/runtime/patch-console.ts
|
|
226
|
+
function patchGlobalConsole() {
|
|
227
|
+
debug("\u26A1\uFE0F PATCHING global console methods");
|
|
228
|
+
if (console.log._varlockPatchedFn) {
|
|
229
|
+
debug("> already patched");
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (varlockSettings.redactLogs === false) {
|
|
233
|
+
debug("> disabled by settings");
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const kWriteToConsoleSymbol = Object.getOwnPropertySymbols(globalThis.console).find((s) => s.description === "kWriteToConsole");
|
|
237
|
+
globalThis._varlockOrigWriteToConsoleFn ||= globalThis.console[kWriteToConsoleSymbol];
|
|
238
|
+
globalThis.console[kWriteToConsoleSymbol] = function() {
|
|
239
|
+
globalThis._varlockOrigWriteToConsoleFn.apply(this, [
|
|
240
|
+
arguments[0],
|
|
241
|
+
redactSensitiveConfig(arguments[1]),
|
|
242
|
+
arguments[2]
|
|
243
|
+
]);
|
|
244
|
+
};
|
|
245
|
+
for (const logMethodName of ["trace", "debug", "info", "log", "info", "warn", "error"]) {
|
|
246
|
+
const originalLogMethod = globalThis.console[logMethodName];
|
|
247
|
+
const patchedFn = function() {
|
|
248
|
+
originalLogMethod.apply(this, Array.from(arguments).map(redactSensitiveConfig));
|
|
249
|
+
};
|
|
250
|
+
patchedFn._varlockPatchedFn = true;
|
|
251
|
+
globalThis.console[logMethodName] = patchedFn;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// src/runtime/patch-response.ts
|
|
256
|
+
function patchGlobalResponse() {
|
|
257
|
+
debug("\u26A1\uFE0F PATCHING global Response");
|
|
258
|
+
if (globalThis.Response._patchedByVarlock) {
|
|
259
|
+
debug("> already patched");
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (varlockSettings.preventLeaks === false) {
|
|
263
|
+
debug("> disabled by settings");
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const _UnpatchedResponse = globalThis.Response;
|
|
267
|
+
globalThis.Response = class VarlockPatchedResponse extends _UnpatchedResponse {
|
|
268
|
+
static _patchedByVarlock = true;
|
|
269
|
+
// Make native fetch() responses (which are instances of the original Response)
|
|
270
|
+
// pass instanceof checks against the patched globalThis.Response.
|
|
271
|
+
static [Symbol.hasInstance](instance) {
|
|
272
|
+
return instance instanceof _UnpatchedResponse;
|
|
273
|
+
}
|
|
274
|
+
constructor(body, init) {
|
|
275
|
+
debug("\u26A1\uFE0F patched Response constructor");
|
|
276
|
+
super(scanForLeaks(body, { method: "patched Response constructor" }), init);
|
|
277
|
+
}
|
|
278
|
+
static json(data, init) {
|
|
279
|
+
debug("\u26A1\uFE0F patched Response.json");
|
|
280
|
+
scanForLeaks(JSON.stringify(data), { method: "patched Response.json" });
|
|
281
|
+
const r = _UnpatchedResponse.json(data, init);
|
|
282
|
+
Object.setPrototypeOf(r, Response.prototype);
|
|
283
|
+
return r;
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// src/runtime/init-edge.ts
|
|
289
|
+
initVarlockEnv();
|
|
290
|
+
patchGlobalConsole();
|
|
291
|
+
patchGlobalResponse();
|
|
292
|
+
globalThis.__varlockPatchConsole = patchGlobalConsole;
|
|
293
|
+
|
|
294
|
+
exports.ENV = ENV;
|
|
295
|
+
exports.redactSensitiveConfig = redactSensitiveConfig;
|
|
296
|
+
exports.revealSensitiveConfig = revealSensitiveConfig;
|
|
297
|
+
exports.scanForLeaks = scanForLeaks;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ENV, redactSensitiveConfig, revealSensitiveConfig, scanForLeaks } from './init-server.cjs';
|