@happyvertical/smrt-config 0.60.15 → 0.60.17
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 +43 -0
- package/README.md +39 -0
- package/dist/browser.js +2 -2
- package/dist/chunks/{shared-D9LcDpJo.js → shared-Cr921uFJ.js} +25 -3
- package/dist/chunks/{shared-D9LcDpJo.js.map → shared-Cr921uFJ.js.map} +1 -1
- package/dist/deployment/chart-values.d.ts +120 -0
- package/dist/deployment/chart-values.d.ts.map +1 -0
- package/dist/deployment/compose-contract.d.ts +141 -0
- package/dist/deployment/compose-contract.d.ts.map +1 -0
- package/dist/deployment.d.ts +11 -0
- package/dist/deployment.d.ts.map +1 -0
- package/dist/deployment.js +720 -0
- package/dist/deployment.js.map +1 -0
- package/dist/export.d.ts +7 -0
- package/dist/export.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/shared.d.ts +8 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/smrt-knowledge.okf.md +4 -2
- package/package.json +10 -3
- package/schemas/x-happyvertical.v1.schema.json +200 -0
package/AGENTS.md
CHANGED
|
@@ -27,6 +27,49 @@ Configuration management with cosmiconfig, secret sanitization, and SSG export.
|
|
|
27
27
|
| `getApplicationRuntimePreset(profile)` | Inspect a profile's safe provider defaults |
|
|
28
28
|
| `resolveCliDatabaseConfig(env?)` | CLI database precedence shared by `smrt` and `smrt-dev-mcp`: declared `packages.cli.database.url` > `DATABASE_URL` (engine: config type > `DATABASE_TYPE` > scheme); read-only (`src/database-environment.ts`) |
|
|
29
29
|
|
|
30
|
+
## Compose deployment contract (`./deployment`, #4789)
|
|
31
|
+
|
|
32
|
+
`@happyvertical/smrt-config/deployment` is a separate entry, not part of the
|
|
33
|
+
root export: the `x-happyvertical` contract (version 1) that makes a Compose
|
|
34
|
+
file an application's deployment declaration. Guide:
|
|
35
|
+
`docs/content/deployment-compose.md`.
|
|
36
|
+
|
|
37
|
+
- `schemas/x-happyvertical.v1.schema.json` is the published JSON Schema
|
|
38
|
+
(`exports['./schemas/*']`, shipped through `files`). Other repositories
|
|
39
|
+
vendor it: keep it free of regex lookarounds (RE2 consumers) and clean under
|
|
40
|
+
Ajv strict mode. `src/deployment/schema.test.ts` holds its version, presets,
|
|
41
|
+
roles and bindings equal to the constants in `compose-contract.ts` and proves
|
|
42
|
+
every annotation shape error is refused by both.
|
|
43
|
+
- `src/deployment/compose-contract.ts`: `validateComposeDeployment()` (stages
|
|
44
|
+
`declare` and `deploy`), the resolved declaration, and the plain-text
|
|
45
|
+
report. Pure and browser-safe: the caller parses YAML. Every rule has an
|
|
46
|
+
issue code and a test in `compose-contract.test.ts`; messages are for
|
|
47
|
+
non-experts and always carry a `fix`. The document is untrusted: the
|
|
48
|
+
validator must never throw (format values with `describe()`, never
|
|
49
|
+
`String()`/`JSON.stringify()`), fails closed on spellings it cannot tell
|
|
50
|
+
apart, refuses a `<<` key anywhere (the caller parsed without merge keys),
|
|
51
|
+
and refuses `$` in what a platform would run or mount (`command`,
|
|
52
|
+
`entrypoint`, `migrate.command`, `health`, volume targets), because Compose
|
|
53
|
+
interpolates the whole file; `name` and a declare-stage `image` are carried
|
|
54
|
+
only when literal. The schema carries the same `$` patterns.
|
|
55
|
+
- `entrypoint`/`command` keep Compose meaning in the declaration: absent =
|
|
56
|
+
the image's own runs; `[]` (or '') = discarded. Never collapse the two.
|
|
57
|
+
- `src/deployment/chart-values.ts`: `renderSmrtAppChartValues()` renders a
|
|
58
|
+
`deploy`-stage declaration plus environment-owned inputs into `smrt-app`
|
|
59
|
+
chart values. It invents no defaults for Secrets, resources or ingress,
|
|
60
|
+
validates the inputs (hand-written JSON), renders `target` only (`current`
|
|
61
|
+
is passed through, never synthesized), and requires an explicit
|
|
62
|
+
`entrypoint` because the chart's `command` replaces the image's.
|
|
63
|
+
- `charts/smrt-app/fixtures/starter.json` is generated from
|
|
64
|
+
`packages/template-sveltekit/template/compose.yaml` by
|
|
65
|
+
`scripts/compose-contract-fixture.mjs --write`; `scripts/compose-contract.test.mjs`
|
|
66
|
+
fails on drift. Change the contract, the template annotations and the
|
|
67
|
+
fixture together.
|
|
68
|
+
- Version 1 changes by addition only (new binding kind, preset or optional
|
|
69
|
+
field). Changing the meaning of a field is a new `v2` schema file and a new
|
|
70
|
+
version constant, never an edit to v1.
|
|
71
|
+
- Environment values are deliberately not part of the declaration.
|
|
72
|
+
|
|
30
73
|
## Key Files
|
|
31
74
|
|
|
32
75
|
- `src/index.ts` — Node entry: `src/shared.ts` plus `loadConfig()`; `src/browser.ts` — `exports['.'].browser` entry, same surface with a `loadConfig()` that rejects (model roots bundle for browsers, #3625)
|
package/README.md
CHANGED
|
@@ -114,6 +114,45 @@ not a runtime block (`null`, `false`, `0`, `''`) throws the same
|
|
|
114
114
|
`RuntimeProfileValidationError` instead of selecting `local`; `setConfig()`
|
|
115
115
|
rejects such a `runtime` override with that error before storing anything.
|
|
116
116
|
|
|
117
|
+
### Compose deployment contract
|
|
118
|
+
|
|
119
|
+
`@happyvertical/smrt-config/deployment` reads an application's Compose file as
|
|
120
|
+
its deployment declaration. The file carries `x-happyvertical` extension fields
|
|
121
|
+
(contract version 1): a top-level block with `preset`, `domain` and `migrate`,
|
|
122
|
+
`role: web|worker` with a `health` check on the services the application runs,
|
|
123
|
+
and `binding: postgres|bucket|email|ai` on local stand-ins for platform
|
|
124
|
+
services. See the
|
|
125
|
+
[compose deployment contract](https://github.com/happyvertical/smrt/blob/main/docs/content/deployment-compose.md)
|
|
126
|
+
for the fields and the supported platform subset.
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
import { parse } from 'yaml';
|
|
130
|
+
import {
|
|
131
|
+
formatComposeDeploymentReport,
|
|
132
|
+
renderSmrtAppChartValues,
|
|
133
|
+
validateComposeDeployment,
|
|
134
|
+
} from '@happyvertical/smrt-config/deployment';
|
|
135
|
+
|
|
136
|
+
// The entry does no I/O: parse the YAML yourself, with merge keys enabled.
|
|
137
|
+
const document = parse(composeText, { merge: true });
|
|
138
|
+
|
|
139
|
+
// `declare` checks the file as written; `deploy` also requires image digests.
|
|
140
|
+
const result = validateComposeDeployment(document, {
|
|
141
|
+
stage: 'deploy',
|
|
142
|
+
images: { web: webDigest, worker: workerDigest },
|
|
143
|
+
});
|
|
144
|
+
if (!result.ok) throw new Error(formatComposeDeploymentReport(result));
|
|
145
|
+
|
|
146
|
+
// Self-host rendering: values for the smrt-app chart.
|
|
147
|
+
const values = renderSmrtAppChartValues(result.declaration, inputs);
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Each issue has a `code`, a `path` into the file, a plain-language `message`
|
|
151
|
+
and a `fix`. Unannotated services are reported as warnings: they run locally
|
|
152
|
+
and are never deployed. The JSON Schema for the annotations is published as
|
|
153
|
+
`@happyvertical/smrt-config/schemas/x-happyvertical.v1.schema.json`. From a
|
|
154
|
+
terminal, use `smrt deploy:check` and `smrt deploy:chart-values`.
|
|
155
|
+
|
|
117
156
|
### Use config in code
|
|
118
157
|
|
|
119
158
|
```typescript
|
package/dist/browser.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as canonicalizeAIConfig, C as mergeConfigs, D as AIProviderNotConfiguredError, E as resolveApplicationRuntime, F as resolveAIProviderConfig, I as toAIClientOptions, L as tryResolveAIProviderConfig, M as getDefaultAIKeyEnvName, N as mergeAIConfigObjects, O as AI_PROVIDER_KEY_ENV, P as redactBaseUrl, R as withAIAliases, S as getRuntimeConfig, T as getApplicationRuntimePreset, _ as mergeExportedConfig, a as getConfig, b as sanitizeConfig, c as getSiteConfig, d as resolveConfiguredAIProvider, f as resolveConfiguredApplicationRuntime, g as exportConfig, h as tryResolveConfiguredAIProvider, i as getAIConfigBlock, j as describeAIProviderConfig, k as DEFAULT_AI_ENV_PREFIXES, l as mergeAIConfigLayers, m as setConfig, n as clearCache, o as getModuleConfig, p as resolveEffectiveApplicationRuntime, r as defineConfig, s as getPackageConfig, t as RUNTIME_ENVIRONMENT_SETTINGS, u as resolveCliDatabaseConfig, v as parseExportedConfig, w as RuntimeProfileValidationError, x as clearRuntimeConfig, y as redactValueSecrets } from "./chunks/shared-Cr921uFJ.js";
|
|
2
2
|
//#region src/browser.ts
|
|
3
3
|
async function loadConfig(_options) {
|
|
4
4
|
throw new Error("@happyvertical/smrt-config: loadConfig() reads smrt.config.* from the filesystem and is not available in a browser build. Provide configuration with setConfig() instead.");
|
|
5
5
|
}
|
|
6
6
|
//#endregion
|
|
7
|
-
export { AIProviderNotConfiguredError, AI_PROVIDER_KEY_ENV, DEFAULT_AI_ENV_PREFIXES, RuntimeProfileValidationError, canonicalizeAIConfig, clearCache, clearRuntimeConfig, defineConfig, describeAIProviderConfig, exportConfig, getAIConfigBlock, getApplicationRuntimePreset, getConfig, getDefaultAIKeyEnvName, getModuleConfig, getPackageConfig, getRuntimeConfig, getSiteConfig, loadConfig, mergeAIConfigLayers, mergeAIConfigObjects, mergeConfigs, mergeExportedConfig, parseExportedConfig, redactBaseUrl, resolveAIProviderConfig, resolveApplicationRuntime, resolveCliDatabaseConfig, resolveConfiguredAIProvider, resolveConfiguredApplicationRuntime, resolveEffectiveApplicationRuntime, sanitizeConfig, setConfig, toAIClientOptions, tryResolveAIProviderConfig, tryResolveConfiguredAIProvider, withAIAliases };
|
|
7
|
+
export { AIProviderNotConfiguredError, AI_PROVIDER_KEY_ENV, DEFAULT_AI_ENV_PREFIXES, RUNTIME_ENVIRONMENT_SETTINGS, RuntimeProfileValidationError, canonicalizeAIConfig, clearCache, clearRuntimeConfig, defineConfig, describeAIProviderConfig, exportConfig, getAIConfigBlock, getApplicationRuntimePreset, getConfig, getDefaultAIKeyEnvName, getModuleConfig, getPackageConfig, getRuntimeConfig, getSiteConfig, loadConfig, mergeAIConfigLayers, mergeAIConfigObjects, mergeConfigs, mergeExportedConfig, parseExportedConfig, redactBaseUrl, redactValueSecrets as redactSecretValues, resolveAIProviderConfig, resolveApplicationRuntime, resolveCliDatabaseConfig, resolveConfiguredAIProvider, resolveConfiguredApplicationRuntime, resolveEffectiveApplicationRuntime, sanitizeConfig, setConfig, toAIClientOptions, tryResolveAIProviderConfig, tryResolveConfiguredAIProvider, withAIAliases };
|
|
8
8
|
|
|
9
9
|
//# sourceMappingURL=browser.js.map
|
|
@@ -950,9 +950,31 @@ function resolveConfiguredApplicationRuntime() {
|
|
|
950
950
|
return resolveRuntimeLayers(getLoadedConfig());
|
|
951
951
|
}
|
|
952
952
|
function resolveEffectiveApplicationRuntime(config) {
|
|
953
|
-
if (!declaresRuntime(config ?? null) && !declaresRuntime(getRuntimeConfig())) return resolveApplicationRuntime(
|
|
953
|
+
if (!declaresRuntime(config ?? null) && !declaresRuntime(getRuntimeConfig())) return resolveApplicationRuntime(runtimeFromEnvironment(typeof process === "undefined" ? {} : process.env));
|
|
954
954
|
return resolveRuntimeLayers(config ?? null);
|
|
955
955
|
}
|
|
956
|
+
var RUNTIME_ENVIRONMENT_SETTINGS = Object.freeze({
|
|
957
|
+
profile: "SMRT_RUNTIME_PROFILE",
|
|
958
|
+
authentication: "SMRT_AUTHENTICATION_PROVIDER",
|
|
959
|
+
assets: "SMRT_ASSETS_PROVIDER",
|
|
960
|
+
secrets: "SMRT_SECRETS_PROVIDER"
|
|
961
|
+
});
|
|
962
|
+
function runtimeFromEnvironment(env) {
|
|
963
|
+
const setting = (name) => env[name]?.trim() || void 0;
|
|
964
|
+
const profile = setting(RUNTIME_ENVIRONMENT_SETTINGS.profile);
|
|
965
|
+
if (!profile) return { profile: "local" };
|
|
966
|
+
const authentication = setting(RUNTIME_ENVIRONMENT_SETTINGS.authentication);
|
|
967
|
+
const assets = setting(RUNTIME_ENVIRONMENT_SETTINGS.assets);
|
|
968
|
+
const secrets = setting(RUNTIME_ENVIRONMENT_SETTINGS.secrets);
|
|
969
|
+
const providers = {};
|
|
970
|
+
if (authentication) providers.authentication = { provider: authentication };
|
|
971
|
+
if (assets) providers.assets = { provider: assets };
|
|
972
|
+
if (secrets) providers.secrets = { provider: secrets };
|
|
973
|
+
return {
|
|
974
|
+
profile,
|
|
975
|
+
...Object.keys(providers).length > 0 ? { providers } : {}
|
|
976
|
+
};
|
|
977
|
+
}
|
|
956
978
|
function declaresRuntime(layer) {
|
|
957
979
|
return layer !== null && Object.hasOwn(layer, "runtime") && layer.runtime !== void 0;
|
|
958
980
|
}
|
|
@@ -1065,6 +1087,6 @@ function tryResolveConfiguredAIProvider(options = {}) {
|
|
|
1065
1087
|
});
|
|
1066
1088
|
}
|
|
1067
1089
|
//#endregion
|
|
1068
|
-
export {
|
|
1090
|
+
export { canonicalizeAIConfig as A, getExplorer as B, mergeConfigs as C, AIProviderNotConfiguredError as D, resolveApplicationRuntime as E, resolveAIProviderConfig as F, setExplorer as H, toAIClientOptions as I, tryResolveAIProviderConfig as L, getDefaultAIKeyEnvName as M, mergeAIConfigObjects as N, AI_PROVIDER_KEY_ENV as O, redactBaseUrl as P, withAIAliases as R, getRuntimeConfig as S, getApplicationRuntimePreset as T, setLoadedConfig as U, setCachedConfig as V, mergeExportedConfig as _, getConfig as a, sanitizeConfig as b, getSiteConfig as c, resolveConfiguredAIProvider as d, resolveConfiguredApplicationRuntime as f, exportConfig as g, tryResolveConfiguredAIProvider as h, getAIConfigBlock as i, describeAIProviderConfig as j, DEFAULT_AI_ENV_PREFIXES as k, mergeAIConfigLayers as l, setConfig as m, clearCache as n, getModuleConfig as o, resolveEffectiveApplicationRuntime as p, defineConfig as r, getPackageConfig as s, RUNTIME_ENVIRONMENT_SETTINGS as t, resolveCliDatabaseConfig as u, parseExportedConfig as v, RuntimeProfileValidationError as w, clearRuntimeConfig as x, redactValueSecrets as y, getCachedConfig as z };
|
|
1069
1091
|
|
|
1070
|
-
//# sourceMappingURL=shared-
|
|
1092
|
+
//# sourceMappingURL=shared-Cr921uFJ.js.map
|