@happyvertical/smrt-config 0.51.31 → 0.51.33

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,161 @@
1
+ /**
2
+ * Config export utilities for static site generation
3
+ *
4
+ * These utilities enable exporting database-backed agent configurations
5
+ * to static files for SSG sites.
6
+ *
7
+ * @module
8
+ */
9
+ /**
10
+ * Deep-clone a config object, removing every key that looks like a secret.
11
+ *
12
+ * Keys are tested (case-insensitively, across camelCase / snake_case / kebab /
13
+ * UPPER variants) against {@link SECRET_PATTERNS}, which cover secrets such as
14
+ * `apiKey`/`api_key`, `password`, `secret`, `token`, `credential`, `private`,
15
+ * `auth`/`authorization`/`oauth`, `accessKey`, `signingKey`, `encryptionKey`,
16
+ * `connectionString`, and `dbUrl`. The policy biases toward over-redaction
17
+ * because these exports are typically published as static, publicly served
18
+ * assets — see {@link SECRET_PATTERNS} for the full rationale.
19
+ *
20
+ * Nested objects are recursively sanitized; arrays are mapped element-by-element.
21
+ * `number` / `boolean` primitives pass through unchanged; `string` values are
22
+ * additionally run through value-level redaction that masks credentials embedded
23
+ * in a URL (`scheme://user:pass@host` → `scheme://***@host`) as well as
24
+ * high-confidence secret-token shapes pasted into otherwise-benign keys
25
+ * (OpenAI/Anthropic `sk-...`, AWS `AKIA...` access key IDs, GitHub/Slack/Google
26
+ * tokens, `Bearer ...` headers, and PEM private-key blocks) — catching secrets
27
+ * stored under a benign key the key-based patterns don't match.
28
+ *
29
+ * Own `__proto__` / `constructor` / `prototype` keys are dropped to prevent the
30
+ * cloned result's prototype from being reassigned via the `__proto__` setter.
31
+ *
32
+ * This function is called automatically by {@link exportConfig} unless
33
+ * `includeSecrets: true` is passed.
34
+ *
35
+ * @param config - Value to sanitize. Accepts any JSON-serializable structure.
36
+ * @returns A new value with all secret keys omitted. `null` / `undefined` are
37
+ * returned as-is.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * const sanitized = sanitizeConfig({
42
+ * apiEndpoint: 'https://api.example.com',
43
+ * apiKey: 'sk-secret-123',
44
+ * nested: { password: 'hunter2', name: 'test' },
45
+ * });
46
+ * // => { apiEndpoint: 'https://api.example.com', nested: { name: 'test' } }
47
+ * ```
48
+ *
49
+ * @see {@link exportConfig}
50
+ */
51
+ export declare function sanitizeConfig(config: unknown): unknown;
52
+ /**
53
+ * Options accepted by {@link exportConfig}.
54
+ */
55
+ export interface ExportConfigOptions {
56
+ /**
57
+ * Include secrets in the export (use with caution!)
58
+ * @default false
59
+ */
60
+ includeSecrets?: boolean;
61
+ /**
62
+ * Output format
63
+ * - 'json': Plain JSON format
64
+ * - 'js': ES module format (export default)
65
+ * @default 'json'
66
+ */
67
+ format?: 'json' | 'js';
68
+ /**
69
+ * Number of spaces for indentation
70
+ * @default 2
71
+ */
72
+ indent?: number;
73
+ }
74
+ /**
75
+ * Serialize a configuration object to a formatted string for SSG file output.
76
+ *
77
+ * By default, {@link sanitizeConfig} is applied before serialization to strip
78
+ * any keys that match secret patterns (API keys, passwords, tokens, etc.).
79
+ * Pass `includeSecrets: true` only in secured server-side contexts.
80
+ *
81
+ * @param config - Configuration object to export. Any JSON-serializable value.
82
+ * @param options - Format, indentation, and secret-inclusion options.
83
+ * @returns A JSON string, or an ES module string (`export default {...};\n`)
84
+ * when `format: 'js'`.
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * // Write a sanitized JSON export file for SSG
89
+ * const json = exportConfig(agentConfig);
90
+ * await fs.writeFile('./public/config.json', json);
91
+ * ```
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * // ES module format (importable via `import config from './config.js'`)
96
+ * const js = exportConfig(agentConfig, { format: 'js' });
97
+ * ```
98
+ *
99
+ * @see {@link sanitizeConfig}
100
+ * @see {@link parseExportedConfig}
101
+ * @see {@link ExportConfigOptions}
102
+ */
103
+ export declare function exportConfig(config: unknown, options?: ExportConfigOptions): string;
104
+ /**
105
+ * Parse a config string previously produced by {@link exportConfig} back into
106
+ * a plain JavaScript object.
107
+ *
108
+ * Handles both output formats:
109
+ * - **JSON** — standard `JSON.parse`.
110
+ * - **JS module** — strips the `export default` prefix and trailing semicolon
111
+ * before parsing as JSON.
112
+ *
113
+ * Throws a `SyntaxError` if the content is not valid JSON after stripping.
114
+ *
115
+ * @param content - Exported config string (`'json'` or `'js'` format).
116
+ * @returns Parsed configuration value.
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * const raw = await fs.readFile('./smrt.exported.json', 'utf8');
121
+ * const config = parseExportedConfig(raw);
122
+ * ```
123
+ *
124
+ * @see {@link exportConfig}
125
+ * @see {@link mergeExportedConfig}
126
+ */
127
+ export declare function parseExportedConfig(content: string): unknown;
128
+ /**
129
+ * Shallow-merge an exported (DB-backed) config into a base (file-backed) config.
130
+ *
131
+ * Object values are deep-merged recursively. Primitive values and arrays from
132
+ * `exportedConfig` replace their counterparts in `baseConfig`. This is a
133
+ * one-level-smarter spread that lets file-based env overrides win when placed
134
+ * after the spread.
135
+ *
136
+ * Intended for the SSG pattern where an agent exports its runtime config to a
137
+ * static JSON file and `smrt.config.js` imports it as a base:
138
+ *
139
+ * @example
140
+ * ```js
141
+ * // smrt.config.js
142
+ * import exported from './smrt.exported.json' with { type: 'json' };
143
+ *
144
+ * export default defineConfig({
145
+ * modules: {
146
+ * praeco: mergeExportedConfig(exported, {
147
+ * apiEndpoint: process.env.API_URL, // env override wins
148
+ * }),
149
+ * },
150
+ * });
151
+ * ```
152
+ *
153
+ * @param baseConfig - Lower-priority base (typically from the DB export file).
154
+ * @param exportedConfig - Higher-priority overrides (typically env / file-based).
155
+ * @returns A new merged object of type `T`.
156
+ *
157
+ * @see {@link exportConfig}
158
+ * @see {@link parseExportedConfig}
159
+ */
160
+ export declare function mergeExportedConfig<T extends Record<string, unknown>>(baseConfig: T, exportedConfig: Partial<T>): T;
161
+ //# sourceMappingURL=export.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../src/export.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAqKH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAyCvD;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,OAAO,EACf,OAAO,GAAE,mBAAwB,GAChC,MAAM,CAaR;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAY5D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnE,UAAU,EAAE,CAAC,EACb,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC,GACzB,CAAC,CA6BH"}