@bakers-build/core 0.10.1-next.10 → 0.10.1-next.12

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,9 @@
1
+ export type Secrets = Readonly<Record<string, string>>;
2
+ /** `~/.bakers/.bakers.env`, beside `machine.config.js`; `BAKERS_HOME` applies. */
3
+ export declare function secretsFilePath(home?: string): string;
4
+ /** Throws naming each bad line by number, never its text: it may hold a value. */
5
+ export declare function parseSecretsFile(text: string): Record<string, string>;
6
+ /** The file's values; `{}` when it does not exist. Refuses a file others can read. */
7
+ export declare function loadSecretsFile(path?: string): Record<string, string>;
8
+ /** The declared `names` a run gets: a non-empty shell value wins over the file. */
9
+ export declare function pickSecrets(names: readonly string[], file: Secrets, env?: Readonly<Record<string, string | undefined>>): Record<string, string>;
@@ -0,0 +1,62 @@
1
+ // The machine's secrets file: `KEY=value` lines a conductor reads at start
2
+ // and hands to a run only for names an agent declares. Parsed, never sourced.
3
+ import { readFileSync, statSync } from 'node:fs';
4
+ import { join } from 'node:path';
5
+ import { homeBbDir } from '../cli/bakers-dir.js';
6
+ /** `~/.bakers/.bakers.env`, beside `machine.config.js`; `BAKERS_HOME` applies. */
7
+ export function secretsFilePath(home) {
8
+ return join(homeBbDir(home), '.bakers.env');
9
+ }
10
+ const LINE = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)=(.*)$/;
11
+ /** Throws naming each bad line by number, never its text: it may hold a value. */
12
+ export function parseSecretsFile(text) {
13
+ const values = {};
14
+ const bad = [];
15
+ text.split(/\r?\n/).forEach((line, index) => {
16
+ if (line.trim() === '' || line.trimStart().startsWith('#'))
17
+ return;
18
+ const match = LINE.exec(line);
19
+ if (!match) {
20
+ bad.push(index + 1);
21
+ return;
22
+ }
23
+ const raw = match[2].trim();
24
+ const quoted = raw.length >= 2 &&
25
+ (raw[0] === "'" || raw[0] === '"') &&
26
+ raw.endsWith(raw[0]);
27
+ values[match[1]] = quoted ? raw.slice(1, -1) : raw;
28
+ });
29
+ if (bad.length)
30
+ throw new Error(bad.map((n) => `line ${n}: expected KEY=value`).join('; '));
31
+ return values;
32
+ }
33
+ /** The file's values; `{}` when it does not exist. Refuses a file others can read. */
34
+ export function loadSecretsFile(path = secretsFilePath()) {
35
+ let mode;
36
+ try {
37
+ mode = statSync(path).mode;
38
+ }
39
+ catch (err) {
40
+ if (err.code === 'ENOENT')
41
+ return {};
42
+ throw err;
43
+ }
44
+ if (mode & 0o077)
45
+ throw new Error(`${path} is readable by group or others; not loaded. Fix it with: chmod 600 ${path}`);
46
+ try {
47
+ return parseSecretsFile(readFileSync(path, 'utf8'));
48
+ }
49
+ catch (err) {
50
+ throw new Error(`${path}: ${err.message}`);
51
+ }
52
+ }
53
+ /** The declared `names` a run gets: a non-empty shell value wins over the file. */
54
+ export function pickSecrets(names, file, env = process.env) {
55
+ const picked = {};
56
+ for (const name of names) {
57
+ const value = env[name] || file[name];
58
+ if (value)
59
+ picked[name] = value;
60
+ }
61
+ return picked;
62
+ }
@@ -28,6 +28,7 @@ export { protectedProjectPaths } from './core/protected-project-paths.js';
28
28
  export { normalizeRepoUrl } from './core/repo-url.js';
29
29
  export { createRunClone, loadRunClone, type RunClone, type RunCloneOptions, registerRunCloneWorktree, removeRunClone, runCloneGitDir, saveRunClone, } from './core/run-clone.js';
30
30
  export { cliRootOf } from './core/runtime-paths.js';
31
+ export { loadSecretsFile, parseSecretsFile, pickSecrets, type Secrets, secretsFilePath, } from './core/secrets-file.js';
31
32
  export { shellQuote } from './core/shell.js';
32
33
  export { DEFAULT_SLUG_MAX_LENGTH, slugify } from './core/slug.js';
33
34
  export { bumpUiRefresh, UI_REFRESH_FILE } from './core/ui-refresh.js';
package/dist/src/index.js CHANGED
@@ -29,6 +29,7 @@ export { protectedProjectPaths } from './core/protected-project-paths.js';
29
29
  export { normalizeRepoUrl } from './core/repo-url.js';
30
30
  export { createRunClone, loadRunClone, registerRunCloneWorktree, removeRunClone, runCloneGitDir, saveRunClone, } from './core/run-clone.js';
31
31
  export { cliRootOf } from './core/runtime-paths.js';
32
+ export { loadSecretsFile, parseSecretsFile, pickSecrets, secretsFilePath, } from './core/secrets-file.js';
32
33
  export { shellQuote } from './core/shell.js';
33
34
  export { DEFAULT_SLUG_MAX_LENGTH, slugify } from './core/slug.js';
34
35
  export { bumpUiRefresh, UI_REFRESH_FILE } from './core/ui-refresh.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/core",
3
- "version": "0.10.1-next.10",
3
+ "version": "0.10.1-next.12",
4
4
  "description": "bakers.build surface-agnostic kernel: host contract, split-config helpers, addon preset/discovery machinery, shared primitives.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -40,7 +40,7 @@
40
40
  "yaml": "^2.7.0"
41
41
  },
42
42
  "bakersBuild": {
43
- "commit": "d0f650fbe4c44eda2a26be62d28d30c22c56c386",
43
+ "commit": "460f5570442a0b09af52a1d4450b879075302e57",
44
44
  "channel": "next"
45
45
  }
46
46
  }