@happyvertical/smrt-config 0.30.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.
- package/AGENTS.md +35 -0
- package/CLAUDE.md +1 -0
- package/LICENSE +7 -0
- package/README.md +138 -0
- package/dist/index.d.ts +1098 -0
- package/dist/index.js +336 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +665 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +53 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# @happyvertical/smrt-config
|
|
2
|
+
|
|
3
|
+
Configuration management with cosmiconfig, secret sanitization, and SSG export.
|
|
4
|
+
|
|
5
|
+
## How It Works
|
|
6
|
+
|
|
7
|
+
1. **cosmiconfig loader** searches for `smrt.config.{js,ts,json}` (via `loadConfig()`)
|
|
8
|
+
2. **Priority**: runtime (highest) > file config > defaults
|
|
9
|
+
3. **globalThis caching**: `globalThis.__smrtConfigCache` — all modules share one config instance
|
|
10
|
+
|
|
11
|
+
## Key Functions
|
|
12
|
+
|
|
13
|
+
| Function | Purpose |
|
|
14
|
+
|----------|---------|
|
|
15
|
+
| `loadConfig()` | Async load from file (cosmiconfig) |
|
|
16
|
+
| `getConfig()` | Get full merged config |
|
|
17
|
+
| `getModuleConfig(name)` | Module-scoped config section |
|
|
18
|
+
| `getPackageConfig(name)` | Package-scoped config section |
|
|
19
|
+
| `setConfig(overrides)` | Runtime overrides (highest priority) |
|
|
20
|
+
| `clearCache()` | Reset cached config — affects all modules |
|
|
21
|
+
| `exportConfig({ includeSecrets })` | SSG-safe export (defaults to no secrets) |
|
|
22
|
+
| `sanitizeConfig(config)` | Strips keys matching: apiKey, password, secret, token, credential, private, auth, key |
|
|
23
|
+
|
|
24
|
+
## Key Files
|
|
25
|
+
|
|
26
|
+
- `src/loader.ts` — cosmiconfig integration and file discovery
|
|
27
|
+
- `src/merge.ts` — deep merge logic, runtime config store
|
|
28
|
+
- `src/export.ts` — sanitization and export formatting (JSON/JS)
|
|
29
|
+
- `src/types.ts` — full config schema (~800 lines)
|
|
30
|
+
|
|
31
|
+
## Gotchas
|
|
32
|
+
|
|
33
|
+
- **clearCache() is global**: affects all modules sharing the config instance
|
|
34
|
+
- **SSG export defaults to no secrets**: must explicitly set `includeSecrets: true` to include them
|
|
35
|
+
- **Deep merge**: later values override earlier ones at each key level
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@AGENTS.md
|
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright <2025> <Happy Vertical Corporation>
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# @happyvertical/smrt-config
|
|
2
|
+
|
|
3
|
+
Centralized configuration management for the SMRT framework. Uses [cosmiconfig](https://github.com/cosmiconfig/cosmiconfig) to load `smrt.config.{js,ts,json}` files, with secret sanitization and SSG-safe export.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @happyvertical/smrt-config
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Create a config file
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
// smrt.config.js
|
|
17
|
+
export default {
|
|
18
|
+
smrt: {
|
|
19
|
+
cacheDir: '.cache',
|
|
20
|
+
logLevel: 'info',
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
packages: {
|
|
24
|
+
ai: {
|
|
25
|
+
defaultProvider: 'anthropic',
|
|
26
|
+
defaultModel: 'claude-sonnet-4-20250514',
|
|
27
|
+
apiKeys: {
|
|
28
|
+
anthropic: process.env.ANTHROPIC_API_KEY,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
modules: {
|
|
34
|
+
'town-scraper': {
|
|
35
|
+
cronSchedule: '0 0 * * *',
|
|
36
|
+
maxPages: 100,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Use config in code
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { loadConfig, getPackageConfig, getModuleConfig, setConfig } from '@happyvertical/smrt-config';
|
|
46
|
+
|
|
47
|
+
// Load config from file (cosmiconfig auto-discovery)
|
|
48
|
+
await loadConfig();
|
|
49
|
+
|
|
50
|
+
// Get package-scoped config with defaults
|
|
51
|
+
const aiConfig = getPackageConfig('ai', {
|
|
52
|
+
defaultProvider: 'openai',
|
|
53
|
+
defaultModel: 'gpt-4',
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Get module-scoped config with defaults
|
|
57
|
+
const scraperConfig = getModuleConfig('town-scraper', {
|
|
58
|
+
cronSchedule: '0 0 * * *',
|
|
59
|
+
maxPages: 50,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Runtime overrides (highest priority)
|
|
63
|
+
setConfig({
|
|
64
|
+
packages: {
|
|
65
|
+
ai: { defaultModel: 'gpt-4-turbo' },
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Type-safe config files
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { defineConfig } from '@happyvertical/smrt-config';
|
|
74
|
+
|
|
75
|
+
export default defineConfig({
|
|
76
|
+
smrt: {
|
|
77
|
+
logLevel: 'info',
|
|
78
|
+
},
|
|
79
|
+
packages: {
|
|
80
|
+
ai: {
|
|
81
|
+
defaultProvider: 'anthropic',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### SSG-safe export
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { loadConfig, exportConfig, sanitizeConfig } from '@happyvertical/smrt-config';
|
|
91
|
+
|
|
92
|
+
const config = await loadConfig();
|
|
93
|
+
|
|
94
|
+
// Export config without secrets (safe for static site generation)
|
|
95
|
+
const safeJson = exportConfig(config, { includeSecrets: false });
|
|
96
|
+
|
|
97
|
+
// Or manually sanitize — strips secret-bearing keys (case-insensitive, across
|
|
98
|
+
// camelCase / snake_case / kebab / UPPER variants): apiKey, password, secret,
|
|
99
|
+
// token, credential, private, oauth, authorization, accessKey, signingKey, encryptionKey,
|
|
100
|
+
// connectionString, dbUrl, cookie, salt, cert, and similar. Biases toward
|
|
101
|
+
// over-redaction; pass `{ includeSecrets: true }` to opt out.
|
|
102
|
+
const sanitized = sanitizeConfig(config);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## API
|
|
106
|
+
|
|
107
|
+
### Functions
|
|
108
|
+
|
|
109
|
+
| Export | Description |
|
|
110
|
+
|--------|------------|
|
|
111
|
+
| `loadConfig(options?)` | Async load from file via cosmiconfig |
|
|
112
|
+
| `getConfig()` | Get full merged config |
|
|
113
|
+
| `getPackageConfig(name, defaults?)` | Get package-scoped config section |
|
|
114
|
+
| `getModuleConfig(name, defaults?)` | Get module-scoped config section |
|
|
115
|
+
| `getSiteConfig()` | Get site-level config |
|
|
116
|
+
| `setConfig(overrides)` | Runtime overrides (highest priority) |
|
|
117
|
+
| `clearCache()` | Reset cached config (global — affects all modules) |
|
|
118
|
+
| `defineConfig(config)` | Type-safe config file helper |
|
|
119
|
+
| `exportConfig(config, options?)` | SSG-safe export (defaults to no secrets) |
|
|
120
|
+
| `sanitizeConfig(config)` | Strip secret-matching keys |
|
|
121
|
+
| `mergeExportedConfig(baseConfig, exportedConfig)` | Merge an exported config over a base |
|
|
122
|
+
| `parseExportedConfig(raw)` | Parse an exported config string |
|
|
123
|
+
|
|
124
|
+
### Priority Order
|
|
125
|
+
|
|
126
|
+
Configuration merging (highest to lowest):
|
|
127
|
+
|
|
128
|
+
1. Runtime overrides via `setConfig()`
|
|
129
|
+
2. Config file (`smrt.config.{js,ts,json}`)
|
|
130
|
+
3. Package/module defaults
|
|
131
|
+
|
|
132
|
+
### Key Types
|
|
133
|
+
|
|
134
|
+
`SmrtConfig`, `SmrtGlobalConfig`, `DatabaseConfig`, `SiteConfig`, `MigrationsConfig`, `LoadConfigOptions`, `ExportConfig`, `ExportConfigOptions`
|
|
135
|
+
|
|
136
|
+
## Dependencies
|
|
137
|
+
|
|
138
|
+
No sibling package dependencies. This is a foundation-layer package.
|