varlock 0.5.0 → 0.6.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.
Files changed (94) hide show
  1. package/README.md +1 -1
  2. package/dist/auto-load.js +6 -6
  3. package/dist/{chunk-FR2ITGSD.js → chunk-2AGKN64R.js} +562 -248
  4. package/dist/chunk-2AGKN64R.js.map +1 -0
  5. package/dist/{chunk-I4RF33CD.js → chunk-3J7BFRB4.js} +372 -446
  6. package/dist/chunk-3J7BFRB4.js.map +1 -0
  7. package/dist/{chunk-NJ4ZGNLG.js → chunk-4JMFWK65.js} +5 -5
  8. package/dist/{chunk-NJ4ZGNLG.js.map → chunk-4JMFWK65.js.map} +1 -1
  9. package/dist/{chunk-TYIS6T2T.js → chunk-BC7LU4LG.js} +3 -3
  10. package/dist/{chunk-TYIS6T2T.js.map → chunk-BC7LU4LG.js.map} +1 -1
  11. package/dist/chunk-EXG5VPNZ.js +17 -0
  12. package/dist/chunk-EXG5VPNZ.js.map +1 -0
  13. package/dist/{chunk-PESGXOZ7.js → chunk-FYZ7LKLX.js} +27 -7
  14. package/dist/chunk-FYZ7LKLX.js.map +1 -0
  15. package/dist/{chunk-BMTZBDMN.js → chunk-G7FDCTNA.js} +8 -8
  16. package/dist/{chunk-BMTZBDMN.js.map → chunk-G7FDCTNA.js.map} +1 -1
  17. package/dist/{chunk-WAMBVZL2.js → chunk-IMB5QAZS.js} +38 -16
  18. package/dist/chunk-IMB5QAZS.js.map +1 -0
  19. package/dist/{chunk-2VSWBSVA.js → chunk-J7PA7B2U.js} +6 -81
  20. package/dist/chunk-J7PA7B2U.js.map +1 -0
  21. package/dist/{chunk-5XPR4NFR.js → chunk-JCJISIY6.js} +6 -6
  22. package/dist/{chunk-5XPR4NFR.js.map → chunk-JCJISIY6.js.map} +1 -1
  23. package/dist/{chunk-RTP55TZC.js → chunk-KKNNZWYD.js} +3 -3
  24. package/dist/{chunk-RTP55TZC.js.map → chunk-KKNNZWYD.js.map} +1 -1
  25. package/dist/{chunk-YWFNGAPT.js → chunk-KZNJYMRJ.js} +6 -6
  26. package/dist/{chunk-YWFNGAPT.js.map → chunk-KZNJYMRJ.js.map} +1 -1
  27. package/dist/{chunk-QQDWRXNU.js → chunk-LVZSZAKN.js} +3 -3
  28. package/dist/{chunk-QQDWRXNU.js.map → chunk-LVZSZAKN.js.map} +1 -1
  29. package/dist/{chunk-ZXJ4CEDK.js → chunk-MYHVSJ3X.js} +3 -3
  30. package/dist/{chunk-ZXJ4CEDK.js.map → chunk-MYHVSJ3X.js.map} +1 -1
  31. package/dist/{chunk-PZ7V7FPH.js → chunk-NPPZVF24.js} +4 -4
  32. package/dist/{chunk-PZ7V7FPH.js.map → chunk-NPPZVF24.js.map} +1 -1
  33. package/dist/{chunk-YO6TXNLA.js → chunk-PMBDCWD5.js} +6 -5
  34. package/dist/chunk-PMBDCWD5.js.map +1 -0
  35. package/dist/chunk-TLEEAUD7.js +68 -0
  36. package/dist/chunk-TLEEAUD7.js.map +1 -0
  37. package/dist/{chunk-Z4WJ7TLU.js → chunk-UVWLW5KD.js} +6 -6
  38. package/dist/{chunk-Z4WJ7TLU.js.map → chunk-UVWLW5KD.js.map} +1 -1
  39. package/dist/{chunk-MIBOBKI4.js → chunk-XLYSNOR3.js} +15 -3
  40. package/dist/chunk-XLYSNOR3.js.map +1 -0
  41. package/dist/{chunk-QC5HUCNV.js → chunk-ZLAUDWOL.js} +6 -6
  42. package/dist/{chunk-QC5HUCNV.js.map → chunk-ZLAUDWOL.js.map} +1 -1
  43. package/dist/cli/cli-executable.js +24 -24
  44. package/dist/cli/cli-executable.js.map +1 -1
  45. package/dist/config-item-NO5PKZRH.js +5 -0
  46. package/dist/{config-item-HIXQLW6F.js.map → config-item-NO5PKZRH.js.map} +1 -1
  47. package/dist/dotenv-compat.js +6 -6
  48. package/dist/{env-graph-BhsVU8Ff.d.ts → env-graph-Cz_c5P6Y.d.ts} +22 -1
  49. package/dist/index.d.ts +2 -2
  50. package/dist/index.js +11 -11
  51. package/dist/init.command-AV4EWYIT.js +12 -0
  52. package/dist/{init.command-RB2RCZ55.js.map → init.command-AV4EWYIT.js.map} +1 -1
  53. package/dist/load.command-5JQUW3H7.js +11 -0
  54. package/dist/{load.command-JQTHKY6V.js.map → load.command-5JQUW3H7.js.map} +1 -1
  55. package/dist/plugin-lib.d.ts +2 -2
  56. package/dist/printenv.command-SBB6GVC2.js +12 -0
  57. package/dist/{printenv.command-OVRM4WEM.js.map → printenv.command-SBB6GVC2.js.map} +1 -1
  58. package/dist/run.command-HTGTG6ER.js +12 -0
  59. package/dist/{run.command-NOA2YFUR.js.map → run.command-HTGTG6ER.js.map} +1 -1
  60. package/dist/runtime/env.d.ts +7 -2
  61. package/dist/runtime/env.js +2 -2
  62. package/dist/runtime/init-edge.cjs +297 -0
  63. package/dist/runtime/init-edge.d.cts +1 -0
  64. package/dist/runtime/init-server.cjs +370 -0
  65. package/dist/runtime/init-server.d.cts +20 -0
  66. package/dist/runtime/patch-console.js +3 -3
  67. package/dist/runtime/patch-response.js +3 -3
  68. package/dist/runtime/patch-server-response.js +3 -3
  69. package/dist/scan.command-ADKVWN5T.js +13 -0
  70. package/dist/{scan.command-64YQENRC.js.map → scan.command-ADKVWN5T.js.map} +1 -1
  71. package/dist/telemetry.command-CQFTGXPF.js +11 -0
  72. package/dist/{telemetry.command-VSKBB3B6.js.map → telemetry.command-CQFTGXPF.js.map} +1 -1
  73. package/dist/typegen.command-A544SFYM.js +12 -0
  74. package/dist/{typegen.command-TQ35B6WK.js.map → typegen.command-A544SFYM.js.map} +1 -1
  75. package/package.json +11 -1
  76. package/dist/chunk-2VSWBSVA.js.map +0 -1
  77. package/dist/chunk-4SXLKBVL.js +0 -17
  78. package/dist/chunk-4SXLKBVL.js.map +0 -1
  79. package/dist/chunk-FR2ITGSD.js.map +0 -1
  80. package/dist/chunk-I4RF33CD.js.map +0 -1
  81. package/dist/chunk-MIBOBKI4.js.map +0 -1
  82. package/dist/chunk-PESGXOZ7.js.map +0 -1
  83. package/dist/chunk-UHUZMCOL.js +0 -156
  84. package/dist/chunk-UHUZMCOL.js.map +0 -1
  85. package/dist/chunk-WAMBVZL2.js.map +0 -1
  86. package/dist/chunk-YO6TXNLA.js.map +0 -1
  87. package/dist/config-item-HIXQLW6F.js +0 -5
  88. package/dist/init.command-RB2RCZ55.js +0 -12
  89. package/dist/load.command-JQTHKY6V.js +0 -11
  90. package/dist/printenv.command-OVRM4WEM.js +0 -12
  91. package/dist/run.command-NOA2YFUR.js +0 -12
  92. package/dist/scan.command-64YQENRC.js +0 -13
  93. package/dist/telemetry.command-VSKBB3B6.js +0 -11
  94. package/dist/typegen.command-TQ35B6WK.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: (value: ValidateInputType) => MaybePromise<(true | undefined | void | Error | Array<Error>)>;
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 */
@@ -527,6 +527,7 @@ declare class VarlockPlugin {
527
527
  get icon(): string;
528
528
  set icon(val: string);
529
529
  loadingError?: Error;
530
+ warnings: Array<SchemaError>;
530
531
  readonly localPath?: string;
531
532
  /** reference to the `@plugin()` decorator instance(s) that installed the plugin */
532
533
  installDecoratorInstances: Array<DecoratorInstance>;
@@ -551,6 +552,26 @@ declare class VarlockPlugin {
551
552
  registerItemDecorator<T>(decoratorDef: ItemDecoratorDef<T>): void;
552
553
  readonly resolverFunctions?: Array<ResolverDef<any>>;
553
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;
554
575
  get pluginFilePath(): string;
555
576
  executePluginModule(): Promise<void>;
556
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-BhsVU8Ff.js';
2
- export { D as Debugger, S as SerializedEnvGraph, c as createDebug } from './env-graph-BhsVU8Ff.js';
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-QQDWRXNU.js';
2
- export { patchGlobalServerResponse } from './chunk-ZXJ4CEDK.js';
3
- import { checkBunVersion } from './chunk-RTP55TZC.js';
4
- import { checkForConfigErrors } from './chunk-PESGXOZ7.js';
5
- import { loadVarlockEnvGraph } from './chunk-4SXLKBVL.js';
6
- import { loadEnvGraph } from './chunk-2VSWBSVA.js';
7
- import { ResolutionError, CoercionError, ValidationError, SchemaError, ConfigLoadError, DotEnvFileDataSource, EnvGraph } from './chunk-FR2ITGSD.js';
1
+ export { patchGlobalServerResponse } from './chunk-MYHVSJ3X.js';
2
+ import { checkBunVersion } from './chunk-KKNNZWYD.js';
3
+ import { checkForConfigErrors } from './chunk-FYZ7LKLX.js';
4
+ import { loadVarlockEnvGraph } from './chunk-EXG5VPNZ.js';
5
+ import { loadEnvGraph } from './chunk-J7PA7B2U.js';
6
+ import { ResolutionError, CoercionError, ValidationError, SchemaError, ConfigLoadError, DotEnvFileDataSource, EnvGraph } from './chunk-2AGKN64R.js';
8
7
  export { createDebug } from './chunk-QZ6HBRJC.js';
9
- export { patchGlobalConsole } from './chunk-TYIS6T2T.js';
10
- import { initVarlockEnv } from './chunk-WAMBVZL2.js';
11
- export { ENV } from './chunk-WAMBVZL2.js';
12
- import './chunk-MIBOBKI4.js';
8
+ export { patchGlobalConsole } from './chunk-BC7LU4LG.js';
9
+ export { patchGlobalResponse } from './chunk-LVZSZAKN.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-RB2RCZ55.js"}
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-JQTHKY6V.js"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"load.command-5JQUW3H7.js"}
@@ -1,5 +1,5 @@
1
- import { V as VarlockPlugin } from './env-graph-BhsVU8Ff.js';
2
- export { D as Debugger, R as Resolver, c as createDebug } from './env-graph-BhsVU8Ff.js';
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-OVRM4WEM.js"}
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-NOA2YFUR.js"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"run.command-HTGTG6ER.js"}
@@ -1,8 +1,13 @@
1
- import { S as SerializedEnvGraph } from '../env-graph-BhsVU8Ff.js';
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 };
@@ -1,5 +1,5 @@
1
- export { ENV, initVarlockEnv, redactSensitiveConfig, resetRedactionMap, revealSensitiveConfig, scanForLeaks, varlockSettings } from '../chunk-WAMBVZL2.js';
2
- import '../chunk-MIBOBKI4.js';
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';