morphix-env 0.7.1 → 0.9.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.
@@ -0,0 +1,182 @@
1
+ interface SourceBase {
2
+ /** A later source may replace keys supplied by an earlier source. */
3
+ override?: boolean;
4
+ /** Only a missing local file source may be optional. */
5
+ optional?: boolean;
6
+ }
7
+ interface InfisicalSource extends SourceBase {
8
+ provider: 'infisical';
9
+ paths: string[];
10
+ projectId?: string;
11
+ siteUrl?: string;
12
+ env?: string;
13
+ envPrefix?: string;
14
+ }
15
+ interface LocalSource extends SourceBase {
16
+ provider: 'local';
17
+ files: string[];
18
+ }
19
+ interface DotenvxSource extends SourceBase {
20
+ provider: 'dotenvx';
21
+ files: string[];
22
+ }
23
+ interface KeychainSource extends SourceBase {
24
+ provider: 'os-keychain';
25
+ service: string;
26
+ platform?: 'macos';
27
+ }
28
+ interface DopplerSource extends SourceBase {
29
+ provider: 'doppler';
30
+ project: string;
31
+ config: string;
32
+ }
33
+ /**
34
+ * External provider plugin: any executable named `mx-env-provider-<plugin>`
35
+ * found on PATH. It is invoked once per key with the key name as argv[1] and
36
+ * writes the value to stdout (one trailing line ending stripped). Provider
37
+ * login/bootstrap stays inside the plugin, never in repository config.
38
+ */
39
+ interface PluginSource extends SourceBase {
40
+ provider: 'plugin';
41
+ plugin: string;
42
+ keys: string[];
43
+ }
44
+ type SecretSource = InfisicalSource | LocalSource | DotenvxSource | KeychainSource | DopplerSource | PluginSource;
45
+ interface ProfileDefinition {
46
+ sources: string[];
47
+ extends?: string;
48
+ }
49
+ type ProfileInput = string[] | ProfileDefinition;
50
+ interface MxEnvConfig {
51
+ /** Legacy Infisical configuration retained for backwards compatibility. */
52
+ infisical?: {
53
+ projectId?: string;
54
+ paths: string[];
55
+ siteUrl?: string;
56
+ /** Automatically add a prefix (such as VITE_) to loaded keys. */
57
+ envPrefix?: string;
58
+ };
59
+ /** Legacy local override files retained for backwards compatibility. */
60
+ envFiles?: string[];
61
+ /** Client __env.js generation configuration. */
62
+ generate?: {
63
+ out?: string;
64
+ filter?: string;
65
+ };
66
+ /** Named whole-source collections. Source values never belong in this file. */
67
+ sources?: Record<string, SecretSource>;
68
+ /** Named ordered source profiles. */
69
+ profiles?: Record<string, ProfileInput>;
70
+ /** Profile selected when a caller does not pass --profile. */
71
+ defaultProfile?: string;
72
+ /**
73
+ * Commands that get a PATH shim via `mx-env shell-init` (global and project
74
+ * lists are unioned). Wiring only — never values. Deliberately excluded from
75
+ * validateConfig's hard errors: a convenience layer must not break the core
76
+ * injection path, so `shell-init` validates and hard-fails while composition
77
+ * paths only warn (see shims.ts validateShimList).
78
+ */
79
+ shims?: string[];
80
+ }
81
+ interface LoadedConfig {
82
+ config: MxEnvConfig;
83
+ path: string;
84
+ baseDir: string;
85
+ exists: boolean;
86
+ }
87
+ interface ConfigLayers {
88
+ global: LoadedConfig;
89
+ project: LoadedConfig;
90
+ globalEnvFile: string;
91
+ }
92
+ interface LoadConfigOptions {
93
+ cwd?: string;
94
+ homeDir?: string;
95
+ }
96
+ /**
97
+ * Loads the two intentional configuration discovery points. Values are never
98
+ * read here; ~/.mx-env/.env is represented as a source by composition later.
99
+ */
100
+ declare function loadConfigLayers(options?: LoadConfigOptions): ConfigLayers;
101
+ /**
102
+ * Returns human-readable validation problems without echoing provider values.
103
+ * Provider credentials deliberately have no place in the declared schema.
104
+ */
105
+ declare function validateConfig(config: MxEnvConfig, label?: string): string[];
106
+
107
+ type SourceAvailability = 'loaded' | 'missing-optional' | 'skipped';
108
+ interface SourceEntry {
109
+ name: string;
110
+ source: SecretSource;
111
+ baseDir: string;
112
+ /** Internal conventional source. Never emitted as a user configuration declaration. */
113
+ globalImplicit?: boolean;
114
+ /** Legacy compatibility sources are allowed to skip missing Infisical setup. */
115
+ legacy?: boolean;
116
+ }
117
+ interface LoadedSource {
118
+ name: string;
119
+ provider: SecretSource['provider'];
120
+ values: Record<string, string>;
121
+ availability: SourceAvailability;
122
+ }
123
+
124
+ interface ComposeOptions {
125
+ profile?: string | null;
126
+ noGlobal?: boolean;
127
+ noInfisical?: boolean;
128
+ envName?: string | null;
129
+ allowInsecureGlobal?: boolean;
130
+ envFiles?: string[];
131
+ baseEnvironment?: NodeJS.ProcessEnv;
132
+ homeDir?: string;
133
+ }
134
+ interface KeyProvenance {
135
+ key: string;
136
+ source: string;
137
+ provider: SecretSource['provider'];
138
+ precedence: number;
139
+ overriddenSources: string[];
140
+ }
141
+ interface SourceStatus {
142
+ name: string;
143
+ provider: SecretSource['provider'];
144
+ availability: LoadedSource['availability'];
145
+ keyCount: number;
146
+ }
147
+ interface EnvironmentComposition {
148
+ environment: NodeJS.ProcessEnv;
149
+ profileName: string;
150
+ sourceStatuses: SourceStatus[];
151
+ provenance: Record<string, KeyProvenance>;
152
+ /** Value-free source descriptors used by the one-shot editor. */
153
+ sourceEntries: SourceEntry[];
154
+ /** Kept only in memory for output redaction during this invocation. */
155
+ redactionValues: string[];
156
+ }
157
+ declare class CompositionError extends Error {
158
+ constructor(message: string);
159
+ }
160
+ /**
161
+ * Resolves sources in precedence order without mutating global process.env.
162
+ * A caller receives an environment object suitable for exactly one child run.
163
+ */
164
+ declare function composeEnvironment(layers: ConfigLayers, options?: ComposeOptions): Promise<EnvironmentComposition>;
165
+
166
+ /**
167
+ * Redacts exact in-memory values while preserving normal stream output. This is
168
+ * deliberately not an exfiltration boundary: a child process can transform a
169
+ * value before printing it. It prevents the common accidental direct echo.
170
+ */
171
+ declare class StreamingRedactor {
172
+ private readonly values;
173
+ private pending;
174
+ constructor(values: string[]);
175
+ write(chunk: Buffer | string): string;
176
+ flush(): string;
177
+ private incompletePrefixLength;
178
+ private redact;
179
+ private lastCompleteMatchEnd;
180
+ }
181
+
182
+ export { type ComposeOptions, CompositionError, type ConfigLayers, type EnvironmentComposition, type KeyProvenance, type LoadConfigOptions, type LoadedConfig, type MxEnvConfig, type ProfileDefinition, type ProfileInput, type SecretSource, type SourceEntry, type SourceStatus, StreamingRedactor, composeEnvironment, loadConfigLayers, validateConfig };