@karmaniverous/get-dotenv 6.1.0 → 6.2.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.
Files changed (51) hide show
  1. package/README.md +20 -14
  2. package/dist/cli.d.ts +58 -2
  3. package/dist/cli.mjs +800 -364
  4. package/dist/cliHost.d.ts +216 -17
  5. package/dist/cliHost.mjs +178 -14
  6. package/dist/config.d.ts +12 -0
  7. package/dist/config.mjs +79 -2
  8. package/dist/env-overlay.d.ts +8 -0
  9. package/dist/getdotenv.cli.mjs +800 -364
  10. package/dist/index.d.ts +220 -35
  11. package/dist/index.mjs +851 -365
  12. package/dist/plugins-aws.d.ts +94 -6
  13. package/dist/plugins-aws.mjs +462 -184
  14. package/dist/plugins-batch.d.ts +85 -3
  15. package/dist/plugins-batch.mjs +203 -54
  16. package/dist/plugins-cmd.d.ts +85 -3
  17. package/dist/plugins-cmd.mjs +150 -28
  18. package/dist/plugins-init.d.ts +85 -3
  19. package/dist/plugins-init.mjs +270 -131
  20. package/dist/plugins.d.ts +85 -4
  21. package/dist/plugins.mjs +800 -364
  22. package/dist/templates/cli/plugins/hello/defaultAction.ts +27 -0
  23. package/dist/templates/cli/plugins/hello/index.ts +26 -0
  24. package/dist/templates/cli/plugins/hello/options.ts +31 -0
  25. package/dist/templates/cli/plugins/hello/strangerAction.ts +20 -0
  26. package/dist/templates/cli/plugins/hello/types.ts +13 -0
  27. package/dist/templates/defaultAction.ts +27 -0
  28. package/dist/templates/hello/defaultAction.ts +27 -0
  29. package/dist/templates/hello/index.ts +26 -0
  30. package/dist/templates/hello/options.ts +31 -0
  31. package/dist/templates/hello/strangerAction.ts +20 -0
  32. package/dist/templates/hello/types.ts +13 -0
  33. package/dist/templates/index.ts +23 -22
  34. package/dist/templates/options.ts +31 -0
  35. package/dist/templates/plugins/hello/defaultAction.ts +27 -0
  36. package/dist/templates/plugins/hello/index.ts +26 -0
  37. package/dist/templates/plugins/hello/options.ts +31 -0
  38. package/dist/templates/plugins/hello/strangerAction.ts +20 -0
  39. package/dist/templates/plugins/hello/types.ts +13 -0
  40. package/dist/templates/strangerAction.ts +20 -0
  41. package/dist/templates/types.ts +13 -0
  42. package/package.json +3 -4
  43. package/templates/cli/plugins/hello/defaultAction.ts +27 -0
  44. package/templates/cli/plugins/hello/index.ts +26 -0
  45. package/templates/cli/plugins/hello/options.ts +31 -0
  46. package/templates/cli/plugins/hello/strangerAction.ts +20 -0
  47. package/templates/cli/plugins/hello/types.ts +13 -0
  48. package/dist/templates/cli/plugins/hello.ts +0 -42
  49. package/dist/templates/hello.ts +0 -42
  50. package/dist/templates/plugins/hello.ts +0 -42
  51. package/templates/cli/plugins/hello.ts +0 -42
package/dist/config.mjs CHANGED
@@ -16,26 +16,58 @@ import { createHash } from 'crypto';
16
16
  * Minimal process env representation used by options and helpers.
17
17
  * Values may be `undefined` to indicate "unset".
18
18
  */
19
+ /**
20
+ * Schema for an env-like record.
21
+ *
22
+ * Keys are environment variable names and values are either strings or `undefined`
23
+ * (to represent “unset”).
24
+ *
25
+ * @public
26
+ */
19
27
  const processEnvSchema = z.record(z.string(), z.string().optional());
20
28
  // RAW: all fields optional — undefined means "inherit" from lower layers.
29
+ /**
30
+ * Programmatic options schema (raw).
31
+ *
32
+ * This schema is the canonical runtime source of truth for the `getDotenv()` programmatic API.
33
+ * All fields are optional; `undefined` generally means “inherit default/lower layer”.
34
+ *
35
+ * @public
36
+ */
21
37
  const getDotenvOptionsSchemaRaw = z.object({
38
+ /** Default environment name when `env` is not provided. */
22
39
  defaultEnv: z.string().optional(),
40
+ /** Base dotenv filename token (default `.env`). */
23
41
  dotenvToken: z.string().optional(),
42
+ /** Path to a dynamic variables module (JS/TS) to load and apply. */
24
43
  dynamicPath: z.string().optional(),
25
- // Dynamic map is intentionally wide for now; refine once sources are normalized.
44
+ /** Dynamic map is intentionally wide for now; refine once sources are normalized. */
26
45
  dynamic: z.record(z.string(), z.unknown()).optional(),
46
+ /** Selected environment name for this invocation (for env-scoped files and overlays). */
27
47
  env: z.string().optional(),
48
+ /** When true, skip applying dynamic variables. */
28
49
  excludeDynamic: z.boolean().optional(),
50
+ /** When true, skip environment-scoped dotenv files. */
29
51
  excludeEnv: z.boolean().optional(),
52
+ /** When true, skip global dotenv files. */
30
53
  excludeGlobal: z.boolean().optional(),
54
+ /** When true, skip private dotenv files. */
31
55
  excludePrivate: z.boolean().optional(),
56
+ /** When true, skip public dotenv files. */
32
57
  excludePublic: z.boolean().optional(),
58
+ /** When true, merge the final composed environment into `process.env`. */
33
59
  loadProcess: z.boolean().optional(),
60
+ /** When true, log the final environment map via `logger`. */
34
61
  log: z.boolean().optional(),
62
+ /** Logger used when `log` is enabled (console-compatible). */
35
63
  logger: z.unknown().default(console),
64
+ /** Optional output dotenv file path to write after composition. */
36
65
  outputPath: z.string().optional(),
66
+ /** Dotenv search paths (ordered). */
37
67
  paths: z.array(z.string()).optional(),
68
+ /** Private token suffix for private dotenv files (default `local`). */
38
69
  privateToken: z.string().optional(),
70
+ /** Explicit variables to overlay onto the composed dotenv map. */
39
71
  vars: processEnvSchema.optional(),
40
72
  });
41
73
 
@@ -46,27 +78,55 @@ const getDotenvOptionsSchemaRaw = z.object({
46
78
  * reflect normalized types (paths: string[], vars: ProcessEnv), applied in the
47
79
  * CLI resolution pipeline.
48
80
  */
81
+ /**
82
+ * CLI options schema (raw).
83
+ *
84
+ * Extends the programmatic options schema with CLI-only flags and stringly inputs
85
+ * which are normalized later by the host resolution pipeline.
86
+ *
87
+ * @public
88
+ */
49
89
  const getDotenvCliOptionsSchemaRaw = getDotenvOptionsSchemaRaw.extend({
50
90
  // CLI-specific fields (stringly inputs before preprocessing)
91
+ /** Enable verbose debug output (host-specific). */
51
92
  debug: z.boolean().optional(),
93
+ /** Fail on validation errors (schema/requiredKeys). */
52
94
  strict: z.boolean().optional(),
95
+ /** Capture child process stdio (useful for CI/tests). */
53
96
  capture: z.boolean().optional(),
97
+ /** Emit child env diagnostics (boolean or selected keys). */
54
98
  trace: z.union([z.boolean(), z.array(z.string())]).optional(),
99
+ /** Enable presentation-time redaction in trace/log output. */
55
100
  redact: z.boolean().optional(),
101
+ /** Enable entropy warnings in trace/log output. */
56
102
  warnEntropy: z.boolean().optional(),
103
+ /** Entropy threshold (bits/char) for warnings. */
57
104
  entropyThreshold: z.number().optional(),
105
+ /** Minimum value length to consider for entropy warnings. */
58
106
  entropyMinLength: z.number().optional(),
107
+ /** Regex patterns (strings) to suppress entropy warnings by key. */
59
108
  entropyWhitelist: z.array(z.string()).optional(),
109
+ /** Additional key-match patterns (strings) for redaction. */
60
110
  redactPatterns: z.array(z.string()).optional(),
111
+ /** Dotenv search paths provided as a single delimited string. */
61
112
  paths: z.string().optional(),
113
+ /** Delimiter string used to split `paths`. */
62
114
  pathsDelimiter: z.string().optional(),
115
+ /** Regex pattern used to split `paths` (takes precedence over delimiter). */
63
116
  pathsDelimiterPattern: z.string().optional(),
117
+ /** Scripts table in a permissive shape at parse time (validated elsewhere). */
64
118
  scripts: z.record(z.string(), z.unknown()).optional(),
119
+ /** Shell selection (`false` for shell-off, string for explicit shell). */
65
120
  shell: z.union([z.boolean(), z.string()]).optional(),
121
+ /** Extra variables expressed as a single delimited string of assignments. */
66
122
  vars: z.string().optional(),
123
+ /** Assignment operator used when parsing `vars`. */
67
124
  varsAssignor: z.string().optional(),
125
+ /** Regex pattern used as the assignment operator for `vars` parsing. */
68
126
  varsAssignorPattern: z.string().optional(),
127
+ /** Delimiter string used to split `vars`. */
69
128
  varsDelimiter: z.string().optional(),
129
+ /** Regex pattern used to split `vars` (takes precedence over delimiter). */
70
130
  varsDelimiterPattern: z.string().optional(),
71
131
  });
72
132
 
@@ -90,17 +150,34 @@ const envStringMap = z.record(z.string(), stringMap);
90
150
  * Raw configuration schema for get‑dotenv config files (JSON/YAML/JS/TS).
91
151
  * Validates allowed top‑level keys without performing path normalization.
92
152
  */
153
+ /**
154
+ * Config schema for discovered get-dotenv configuration documents (raw).
155
+ *
156
+ * This schema validates the allowed top-level keys for configuration files.
157
+ * It does not normalize paths or coerce types beyond Zod’s parsing.
158
+ *
159
+ * @public
160
+ */
93
161
  const getDotenvConfigSchemaRaw = z.object({
162
+ /** Root option defaults applied by the host (CLI-like, collapsed families). */
94
163
  rootOptionDefaults: getDotenvCliOptionsSchemaRaw.optional(),
164
+ /** Help-time visibility map for root flags (false hides). */
95
165
  rootOptionVisibility: visibilityMap.optional(),
96
- scripts: z.record(z.string(), z.unknown()).optional(), // Scripts validation left wide; generator validates elsewhere
166
+ /** Scripts table used by cmd/batch resolution (validation intentionally permissive here). */
167
+ scripts: z.record(z.string(), z.unknown()).optional(),
168
+ /** Keys required to be present in the final composed environment. */
97
169
  requiredKeys: z.array(z.string()).optional(),
170
+ /** Validation schema (JS/TS only; JSON/YAML loader rejects). */
98
171
  schema: z.unknown().optional(), // JS/TS-only; loader rejects in JSON/YAML
172
+ /** Public global variables (string-only). */
99
173
  vars: stringMap.optional(), // public, global
174
+ /** Public per-environment variables (string-only). */
100
175
  envVars: envStringMap.optional(), // public, per-env
101
176
  // Dynamic in config (JS/TS only). JSON/YAML loader will reject if set.
177
+ /** Dynamic variable definitions (JS/TS only). */
102
178
  dynamic: z.unknown().optional(),
103
179
  // Per-plugin config bag; validated by plugins/host when used.
180
+ /** Per-plugin config slices keyed by realized mount path (for example, `aws/whoami`). */
104
181
  plugins: z.record(z.string(), z.unknown()).optional(),
105
182
  });
106
183
  /**
@@ -104,6 +104,11 @@ type ScriptsTable<TShell extends string | boolean = string | boolean> = Record<s
104
104
  */
105
105
  type Scripts = ScriptsTable;
106
106
 
107
+ /**
108
+ * Resolved configuration object type returned by {@link getDotenvConfigSchemaResolved}.
109
+ *
110
+ * @public
111
+ */
107
112
  type GetDotenvConfigResolved = {
108
113
  /**
109
114
  * Help-time/runtime root defaults applied by the host (collapsed families; CLI‑like).
@@ -242,6 +247,9 @@ interface OverlayEnvOptionsBase<B extends Record<string, string | undefined> | R
242
247
  * @public
243
248
  */
244
249
  interface OverlayEnvOptionsWithProgrammatic<B extends Record<string, string | undefined> | Readonly<Record<string, string | undefined>>, P extends Record<string, string | undefined> | Readonly<Record<string, string | undefined>>> extends OverlayEnvOptionsBase<B> {
250
+ /**
251
+ * Explicit programmatic variables applied at the highest precedence tier.
252
+ */
245
253
  programmaticVars: P;
246
254
  }
247
255
  /**