@vibesdotdev/infra-core 0.0.1
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/README.md +78 -0
- package/SPEC.md +169 -0
- package/dist/bootstrap/index.d.ts +5 -0
- package/dist/bootstrap/index.d.ts.map +1 -0
- package/dist/bootstrap/index.js +4 -0
- package/dist/bootstrap/index.js.map +1 -0
- package/dist/bootstrap/seed.descriptor.d.ts +31 -0
- package/dist/bootstrap/seed.descriptor.d.ts.map +1 -0
- package/dist/bootstrap/seed.descriptor.js +18 -0
- package/dist/bootstrap/seed.descriptor.js.map +1 -0
- package/dist/bootstrap/seed.impl-shape.d.ts +5 -0
- package/dist/bootstrap/seed.impl-shape.d.ts.map +1 -0
- package/dist/bootstrap/seed.impl-shape.js +2 -0
- package/dist/bootstrap/seed.impl-shape.js.map +1 -0
- package/dist/bootstrap/seed.kind.d.ts +5 -0
- package/dist/bootstrap/seed.kind.d.ts.map +1 -0
- package/dist/bootstrap/seed.kind.js +14 -0
- package/dist/bootstrap/seed.kind.js.map +1 -0
- package/dist/bootstrap/seed.runner.d.ts +18 -0
- package/dist/bootstrap/seed.runner.d.ts.map +1 -0
- package/dist/bootstrap/seed.runner.js +59 -0
- package/dist/bootstrap/seed.runner.js.map +1 -0
- package/dist/credentials/resolve.d.ts +80 -0
- package/dist/credentials/resolve.d.ts.map +1 -0
- package/dist/credentials/resolve.js +128 -0
- package/dist/credentials/resolve.js.map +1 -0
- package/dist/deployment.d.ts +9 -0
- package/dist/deployment.d.ts.map +1 -0
- package/dist/deployment.js +25 -0
- package/dist/deployment.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/infra.plugin.d.ts +18 -0
- package/dist/infra.plugin.d.ts.map +1 -0
- package/dist/infra.plugin.js +52 -0
- package/dist/infra.plugin.js.map +1 -0
- package/dist/kinds/alerts.kind.d.ts +192 -0
- package/dist/kinds/alerts.kind.d.ts.map +1 -0
- package/dist/kinds/alerts.kind.js +116 -0
- package/dist/kinds/alerts.kind.js.map +1 -0
- package/dist/kinds/artifact.kind.d.ts +96 -0
- package/dist/kinds/artifact.kind.d.ts.map +1 -0
- package/dist/kinds/artifact.kind.js +53 -0
- package/dist/kinds/artifact.kind.js.map +1 -0
- package/dist/kinds/cache.kind.d.ts +128 -0
- package/dist/kinds/cache.kind.d.ts.map +1 -0
- package/dist/kinds/cache.kind.js +90 -0
- package/dist/kinds/cache.kind.js.map +1 -0
- package/dist/kinds/database.kind.d.ts +141 -0
- package/dist/kinds/database.kind.d.ts.map +1 -0
- package/dist/kinds/database.kind.js +103 -0
- package/dist/kinds/database.kind.js.map +1 -0
- package/dist/kinds/discovery.d.ts +20 -0
- package/dist/kinds/discovery.d.ts.map +1 -0
- package/dist/kinds/discovery.js +25 -0
- package/dist/kinds/discovery.js.map +1 -0
- package/dist/kinds/git-hosting.kind.d.ts +98 -0
- package/dist/kinds/git-hosting.kind.d.ts.map +1 -0
- package/dist/kinds/git-hosting.kind.js +81 -0
- package/dist/kinds/git-hosting.kind.js.map +1 -0
- package/dist/kinds/index.d.ts +16 -0
- package/dist/kinds/index.d.ts.map +1 -0
- package/dist/kinds/index.js +16 -0
- package/dist/kinds/index.js.map +1 -0
- package/dist/kinds/logs.kind.d.ts +91 -0
- package/dist/kinds/logs.kind.d.ts.map +1 -0
- package/dist/kinds/logs.kind.js +73 -0
- package/dist/kinds/logs.kind.js.map +1 -0
- package/dist/kinds/object-storage.kind.d.ts +85 -0
- package/dist/kinds/object-storage.kind.d.ts.map +1 -0
- package/dist/kinds/object-storage.kind.js +81 -0
- package/dist/kinds/object-storage.kind.js.map +1 -0
- package/dist/kinds/observability.kind.d.ts +176 -0
- package/dist/kinds/observability.kind.d.ts.map +1 -0
- package/dist/kinds/observability.kind.js +120 -0
- package/dist/kinds/observability.kind.js.map +1 -0
- package/dist/kinds/package-registry.kind.d.ts +89 -0
- package/dist/kinds/package-registry.kind.d.ts.map +1 -0
- package/dist/kinds/package-registry.kind.js +78 -0
- package/dist/kinds/package-registry.kind.js.map +1 -0
- package/dist/kinds/queue.kind.d.ts +113 -0
- package/dist/kinds/queue.kind.d.ts.map +1 -0
- package/dist/kinds/queue.kind.js +86 -0
- package/dist/kinds/queue.kind.js.map +1 -0
- package/dist/kinds/rum.kind.d.ts +113 -0
- package/dist/kinds/rum.kind.d.ts.map +1 -0
- package/dist/kinds/rum.kind.js +80 -0
- package/dist/kinds/rum.kind.js.map +1 -0
- package/dist/kinds/sandbox.kind.d.ts +111 -0
- package/dist/kinds/sandbox.kind.d.ts.map +1 -0
- package/dist/kinds/sandbox.kind.js +94 -0
- package/dist/kinds/sandbox.kind.js.map +1 -0
- package/dist/kinds/web-app.kind.d.ts +99 -0
- package/dist/kinds/web-app.kind.d.ts.map +1 -0
- package/dist/kinds/web-app.kind.js +86 -0
- package/dist/kinds/web-app.kind.js.map +1 -0
- package/dist/kinds/worker.kind.d.ts +244 -0
- package/dist/kinds/worker.kind.d.ts.map +1 -0
- package/dist/kinds/worker.kind.js +171 -0
- package/dist/kinds/worker.kind.js.map +1 -0
- package/dist/schemas.d.ts +125 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +102 -0
- package/dist/schemas.js.map +1 -0
- package/package.json +92 -0
- package/src/bootstrap/index.ts +15 -0
- package/src/bootstrap/seed.descriptor.ts +24 -0
- package/src/bootstrap/seed.impl-shape.ts +5 -0
- package/src/bootstrap/seed.kind.ts +26 -0
- package/src/bootstrap/seed.runner.ts +87 -0
- package/src/credentials/resolve.ts +205 -0
- package/src/deployment.ts +57 -0
- package/src/index.ts +149 -0
- package/src/infra.plugin.ts +54 -0
- package/src/kinds/alerts.kind.ts +164 -0
- package/src/kinds/artifact.kind.ts +96 -0
- package/src/kinds/cache.kind.ts +104 -0
- package/src/kinds/database.kind.ts +120 -0
- package/src/kinds/discovery.ts +26 -0
- package/src/kinds/git-hosting.kind.ts +100 -0
- package/src/kinds/index.ts +139 -0
- package/src/kinds/logs.kind.ts +104 -0
- package/src/kinds/object-storage.kind.ts +101 -0
- package/src/kinds/observability.kind.ts +178 -0
- package/src/kinds/package-registry.kind.ts +95 -0
- package/src/kinds/queue.kind.ts +102 -0
- package/src/kinds/rum.kind.ts +135 -0
- package/src/kinds/sandbox.kind.ts +115 -0
- package/src/kinds/web-app.kind.ts +103 -0
- package/src/kinds/worker.kind.ts +203 -0
- package/src/schemas.ts +127 -0
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# @vibesdotdev/infra-core
|
|
2
|
+
|
|
3
|
+
Provider-agnostic contract for deployable infrastructure. Defines runtime
|
|
4
|
+
kinds, descriptor schemas, and deployment factories shared by adapter packages
|
|
5
|
+
(`infra-cloudflare`, `infra-doks`) and consuming apps.
|
|
6
|
+
|
|
7
|
+
See [`SPEC.md`](./SPEC.md) for the contract.
|
|
8
|
+
|
|
9
|
+
## What's in here
|
|
10
|
+
|
|
11
|
+
- `src/schemas.ts` — atomic Zod schemas (provider, runtime, origin, build,
|
|
12
|
+
env requirement, dependency, upstream) plus the assembled
|
|
13
|
+
`appDeploymentSchema`.
|
|
14
|
+
- `src/kinds/` — one file per runtime kind: `infra/web-app`, `infra/worker`,
|
|
15
|
+
`infra/database`, `infra/queue`, `infra/cache`, `infra/object-storage`,
|
|
16
|
+
`infra/sandbox`. Each kind ships a Zod descriptor schema and a pass-through
|
|
17
|
+
default `Implementation` class.
|
|
18
|
+
- `src/deployment.ts` — factory functions that produce validated deployment
|
|
19
|
+
objects from authored input (`createAppDeployment` and friends).
|
|
20
|
+
- `src/infra.plugin.ts` — `infraPlugin` registers all 7 kinds with the
|
|
21
|
+
runtime under `discoveryPattern: "**/*.infra.ts"`.
|
|
22
|
+
|
|
23
|
+
## Common usage
|
|
24
|
+
|
|
25
|
+
Authoring a per-app deployment config (in `apps/<app>-web/deployment.config.ts`):
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { createAppDeployment } from '@vibesdotdev/infra-core/deployment';
|
|
29
|
+
import { createCloudflarePagesDeployment } from '@vibesdotdev/infra-cloudflare/pages';
|
|
30
|
+
|
|
31
|
+
const deployment = createAppDeployment({
|
|
32
|
+
appId: 'my-app',
|
|
33
|
+
appName: 'My App',
|
|
34
|
+
provider: 'cloudflare-workers',
|
|
35
|
+
runtime: 'edge',
|
|
36
|
+
build: { /* ... */ },
|
|
37
|
+
origins: [/* ... */],
|
|
38
|
+
env: [/* ... */]
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export default createCloudflarePagesDeployment({ deployment, /* ... */ });
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Declaring a discoverable infra resource (in any `*.infra.ts` file):
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import type { WebAppDescriptor } from '@vibesdotdev/infra-core/kinds';
|
|
48
|
+
|
|
49
|
+
export default {
|
|
50
|
+
id: 'my-app',
|
|
51
|
+
kind: 'infra/web-app',
|
|
52
|
+
domain: 'my-app.vibes.dev',
|
|
53
|
+
appDir: 'apps/my-app-web',
|
|
54
|
+
outputDir: 'apps/my-app-web/.svelte-kit/cloudflare',
|
|
55
|
+
adapter: 'cloudflare-pages',
|
|
56
|
+
runtime: 'edge',
|
|
57
|
+
env: []
|
|
58
|
+
} satisfies WebAppDescriptor;
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Real provider behavior comes from adapter packages registering against the
|
|
62
|
+
same kinds. Core never imports adapters.
|
|
63
|
+
|
|
64
|
+
## Verification
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
cd packages/infra-core
|
|
68
|
+
bun test
|
|
69
|
+
bun --bun tsc -p tsconfig.json --noEmit
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Links
|
|
73
|
+
|
|
74
|
+
- [SPEC.md](./SPEC.md)
|
|
75
|
+
- [PROD-CHECKLIST.md](./PROD-CHECKLIST.md)
|
|
76
|
+
- [`infra-cloudflare`](../infra-cloudflare/SPEC.md)
|
|
77
|
+
- [`infra-doks`](../infra-doks/SPEC.md)
|
|
78
|
+
- [`deploy`](../deploy/SPEC.md)
|
package/SPEC.md
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# @vibesdotdev/infra-core
|
|
2
|
+
|
|
3
|
+
Provider-agnostic contract for deployable infrastructure. Defines the runtime
|
|
4
|
+
kinds, descriptor schemas, and deployment factories that adapter packages and
|
|
5
|
+
consuming apps share. Adapter packages
|
|
6
|
+
([`infra-cloudflare`](../infra-cloudflare/SPEC.md),
|
|
7
|
+
[`infra-doks`](../infra-doks/SPEC.md)) implement provider-specific behavior
|
|
8
|
+
against these kinds; consumed by per-app `deployment.config.ts` files, by
|
|
9
|
+
`*.infra.ts` resource declarations under workspace `infra/`, by
|
|
10
|
+
[`secrets`](../secrets/SPEC.md) for env-requirement resolution, and by
|
|
11
|
+
[`deploy`](../deploy/SPEC.md) for orchestration.
|
|
12
|
+
|
|
13
|
+
## Owns
|
|
14
|
+
|
|
15
|
+
- **Runtime kinds:** `infra/web-app`, `infra/worker`, `infra/database`,
|
|
16
|
+
`infra/queue`, `infra/cache`, `infra/object-storage`, `infra/sandbox`,
|
|
17
|
+
`infra/git-hosting`, `infra/package-registry`.
|
|
18
|
+
- **Plugin descriptors registered by the plugin:** `infraPlugin` (id `infra`)
|
|
19
|
+
registers all 9 kinds with `discoveryPattern: "**/*.infra.ts"` and
|
|
20
|
+
pass-through default implementations exposing the validated descriptor as
|
|
21
|
+
`config`.
|
|
22
|
+
- **Schemas** (`./schemas`): atomic Zod schemas — provider enum, runtime enum,
|
|
23
|
+
origin, build, env requirement, dependency, upstream — and the assembled
|
|
24
|
+
`appDeploymentSchema`. Single source of truth for cross-cutting shapes;
|
|
25
|
+
kind descriptor schemas compose from these primitives.
|
|
26
|
+
- **Kind descriptors** (`./kinds`): one file per kind, each defining a Zod
|
|
27
|
+
descriptor schema (composed from `./schemas`) and a pass-through default
|
|
28
|
+
`Implementation` class wired through `createRuntimeKind`.
|
|
29
|
+
- **Deployment factories** (`./deployment`): `createAppDeployment`,
|
|
30
|
+
`createDeploymentOrigin`, `createDeploymentEnvRequirement`,
|
|
31
|
+
`createDeploymentDependency`, `getPrimaryOrigin`, `getUpstreamOriginEnv`.
|
|
32
|
+
These produce the validated objects authored in per-app
|
|
33
|
+
`deployment.config.ts` files.
|
|
34
|
+
|
|
35
|
+
## Does not own
|
|
36
|
+
|
|
37
|
+
- Cloudflare Workers / Workers / Queues / R2 / KV implementations →
|
|
38
|
+
[`infra-cloudflare`](../infra-cloudflare/SPEC.md).
|
|
39
|
+
- DigitalOcean App Platform / DOKS / Spaces / Managed DB / Managed Redis
|
|
40
|
+
implementations → [`infra-doks`](../infra-doks/SPEC.md).
|
|
41
|
+
- Standalone Kubernetes / Docker / DO Droplet implementations — no adapter
|
|
42
|
+
package exists yet (see migration debt).
|
|
43
|
+
- Deployment orchestration, manifest generation, env materialization, and the
|
|
44
|
+
`infra/` workspace tree (`infra/manifest.ts`, `infra/generate.ts`,
|
|
45
|
+
`infra/resources/`) → [`deploy`](../deploy/SPEC.md). Per-app
|
|
46
|
+
`deployment.config.ts` files live in `apps/<app>-web/`.
|
|
47
|
+
- Env-requirement resolution against descriptors →
|
|
48
|
+
[`secrets`](../secrets/SPEC.md).
|
|
49
|
+
- AI inference selection. Inference is an `ai/provider` + `ai/adapter`
|
|
50
|
+
concern — see [`ai`](../ai/SPEC.md) and
|
|
51
|
+
[`ai-providers`](../ai-providers/SPEC.md). No `infra/inference` kind exists
|
|
52
|
+
or should be added.
|
|
53
|
+
|
|
54
|
+
## Hard rules
|
|
55
|
+
|
|
56
|
+
- Core never imports adapter packages. Dependencies are exactly
|
|
57
|
+
`@vibesdotdev/runtime` + `zod`.
|
|
58
|
+
- Shared shapes live in `./schemas`. Kind descriptor schemas compose from
|
|
59
|
+
`./schemas`. Do not redeclare an env-requirement schema or any other
|
|
60
|
+
primitive inside a kind file.
|
|
61
|
+
- New deployable resource types are added as new kinds in `src/kinds/`.
|
|
62
|
+
Provider-specific concepts (Wrangler bindings, Helm values, Spaces CORS,
|
|
63
|
+
CF Sandbox outbound proxy specifics, etc.) belong in adapter packages
|
|
64
|
+
registering implementations against the existing kinds.
|
|
65
|
+
- Inference is not an infra kind. New inference strategies (CF Unified
|
|
66
|
+
Inference, Agents bindings, etc.) are added as `ai/provider` descriptors +
|
|
67
|
+
adapters in [`ai-providers`](../ai-providers/SPEC.md).
|
|
68
|
+
- Default implementations are inert pass-throughs that expose the validated
|
|
69
|
+
descriptor as `config`. Real provider behavior must come from an adapter
|
|
70
|
+
package registering an implementation for the same kind.
|
|
71
|
+
- Kind discovery pattern is `**/*.infra.ts` for every kind. Apps and the
|
|
72
|
+
`infra/` workspace declare concrete resources in `*.infra.ts` files; do
|
|
73
|
+
not change the pattern per kind.
|
|
74
|
+
- Pure TypeScript only. No `$env`, `$server`, `$app`, `@sveltejs/kit`,
|
|
75
|
+
Svelte, Drizzle, or filesystem APIs in this package.
|
|
76
|
+
- `deploymentProviderSchema` enumerates exactly the providers backed by an
|
|
77
|
+
active adapter package. Adding a provider value without a corresponding
|
|
78
|
+
adapter is a contract lie — add the adapter or omit the value.
|
|
79
|
+
- `appDeploymentSchema` cross-validates provider against runtime and origin
|
|
80
|
+
hostnames (e.g. `cloudflare-workers` requires `edge`; `digitalocean-app`
|
|
81
|
+
requires `node` or `worker`). Nonsense combinations fail at parse time,
|
|
82
|
+
not deploy time.
|
|
83
|
+
|
|
84
|
+
## Migration debt (completed)
|
|
85
|
+
|
|
86
|
+
- [x] `envRequirementSchema` is locally redeclared in
|
|
87
|
+
`src/kinds/web-app.kind.ts`, `src/kinds/worker.kind.ts`, and
|
|
88
|
+
`src/kinds/sandbox.kind.ts` instead of imported from `./schemas`.
|
|
89
|
+
**Resolution:** Kinds now import `deploymentEnvRequirementSchema` from `./schemas`.
|
|
90
|
+
All kind files use `import { z } from 'zod/v4'` style for consistency.
|
|
91
|
+
- [x] `package.json#exports` includes `"./kinds/*": "./src/kinds/*.ts"`.
|
|
92
|
+
**Resolution:** Wildcard removed. All 26 consumers updated to use `./kinds`
|
|
93
|
+
aggregate subpath instead of deep imports.
|
|
94
|
+
- [x] `deploymentProviderSchema` declares `digitalocean-droplet`,
|
|
95
|
+
`digitalocean-kubernetes`, `kubernetes`, and `docker`, but only
|
|
96
|
+
`digitalocean-app` (via `infra-doks`) and `cloudflare-workers` (via
|
|
97
|
+
`infra-cloudflare`) have active adapter implementations.
|
|
98
|
+
**Resolution:** Trimmed to only `cloudflare-workers` and `digitalocean-app`.
|
|
99
|
+
- [x] `appDeploymentSchema` does not cross-validate provider against runtime.
|
|
100
|
+
**Resolution:** Added `.refine()` enforcing provider × runtime matrix:
|
|
101
|
+
- `cloudflare-workers`: `edge`, `worker`
|
|
102
|
+
- `digitalocean-app`: `node`, `worker`
|
|
103
|
+
- [x] `discoveryPattern` and `extractStem` are duplicated identically across all
|
|
104
|
+
9 kind files.
|
|
105
|
+
**Resolution:** Extracted shared helper in `src/kinds/discovery.ts` with
|
|
106
|
+
`INFRA_DISCOVERY_PATTERN` constant and `extractStem()` function. All 7
|
|
107
|
+
kind files now import and reuse.
|
|
108
|
+
- [x] `WebAppDescriptor` and `appDeploymentSchema` describe overlapping concepts
|
|
109
|
+
(`appDir`, `outputDir`, `runtime`, `env`).
|
|
110
|
+
**Resolution:** The parallel surfaces are **intentional**:
|
|
111
|
+
- `WebAppDescriptor` (runtime-discovered resource) lives at `infra/web-app`
|
|
112
|
+
kind with `adapter`, `domain`, `env`, etc. Used by runtime discovery.
|
|
113
|
+
- `appDeploymentSchema` (authored deployment config) lives in `./schemas` and
|
|
114
|
+
is used by `deployment.config.ts` files with `provider`, `build`, `origins`,
|
|
115
|
+
etc. Both shapes reference similar fields but serve different consumers.
|
|
116
|
+
No merging; keep parallel with potential future composition via shared
|
|
117
|
+
fragment schemas if divergence becomes problematic.
|
|
118
|
+
|
|
119
|
+
## Migration debt
|
|
120
|
+
|
|
121
|
+
- [x] **`adapter` discriminator → `config` field migration.** All 7 original
|
|
122
|
+
infra kinds declare `adapter: z.string()` as a top-level discriminator field.
|
|
123
|
+
This field is not in `RuntimeDescriptorSchema` and `createRuntimeAsset` could not
|
|
124
|
+
validate it. Every infra kind has moved `adapter` and all adapter-specific
|
|
125
|
+
fields into a `config` object validated against the kind's registered
|
|
126
|
+
`descriptorSchema`. **Affected kinds:** `infra/web-app`, `infra/worker`,
|
|
127
|
+
`infra/database`, `infra/queue`, `infra/cache`, `infra/object-storage`,
|
|
128
|
+
`infra/sandbox`, `infra/git-hosting`, `infra/package-registry`.
|
|
129
|
+
- [x] `infra/web-app`: added `WebAppConfigSchema` union
|
|
130
|
+
(cloudflare-workers, digitalocean-apps)
|
|
131
|
+
- [x] `infra/worker`: added `WorkerConfigSchema` union
|
|
132
|
+
(doks-deployment, cloudflare-workers)
|
|
133
|
+
- [x] `infra/database`: added `DatabaseConfigSchema` union
|
|
134
|
+
(doks-statefulset, do-managed-postgres, turso)
|
|
135
|
+
- [x] `infra/queue`: added `QueueConfigSchema` union
|
|
136
|
+
(doks-statefulset, cloudflare-queues)
|
|
137
|
+
- [x] `infra/cache`: added `CacheConfigSchema` union
|
|
138
|
+
(do-managed-redis, cloudflare-kv, doks-redis)
|
|
139
|
+
- [x] `infra/object-storage`: added `ObjectStorageConfigSchema` union
|
|
140
|
+
(do-spaces, cloudflare-r2)
|
|
141
|
+
- [x] `infra/sandbox`: already had all variants (cloudflare-sandbox, docker,
|
|
142
|
+
digitalocean-droplet)
|
|
143
|
+
- [x] `infra/git-hosting`: added `GitHostingConfigSchema` union (gitea-doks)
|
|
144
|
+
- [x] `infra/package-registry`: added `PackageRegistryConfigSchema` union
|
|
145
|
+
(verdaccio-doks)
|
|
146
|
+
|
|
147
|
+
## Public entrypoints
|
|
148
|
+
|
|
149
|
+
`.`, `./schemas`, `./kinds`, `./deployment`, `./plugin`.
|
|
150
|
+
|
|
151
|
+
Wildcard / migration-era subpaths: `./kinds/*` — do not normalize new code
|
|
152
|
+
against this.
|
|
153
|
+
|
|
154
|
+
## Verification
|
|
155
|
+
|
|
156
|
+
`bun test` from `packages/infra-core`. Covers all 9 schemas (accept-valid +
|
|
157
|
+
reject-invalid), all 9 kind descriptor structures, plugin registration shape
|
|
158
|
+
(id, kinds count, kind IDs, discovery pattern, no dependencies, no lifecycle
|
|
159
|
+
hooks), and all 6 factory functions. `bun --bun tsc -p tsconfig.json
|
|
160
|
+
--noEmit` is the type gate.
|
|
161
|
+
|
|
162
|
+
## Links
|
|
163
|
+
|
|
164
|
+
- [infra-cloudflare/SPEC.md](../infra-cloudflare/SPEC.md)
|
|
165
|
+
- [infra-doks/SPEC.md](../infra-doks/SPEC.md)
|
|
166
|
+
- [deploy/SPEC.md](../deploy/SPEC.md)
|
|
167
|
+
- [secrets/SPEC.md](../secrets/SPEC.md)
|
|
168
|
+
- [runtime/SPEC.md](../runtime/SPEC.md)
|
|
169
|
+
- [ai/SPEC.md](../ai/SPEC.md), [ai-providers/SPEC.md](../ai-providers/SPEC.md)
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { bootstrapSeedKind } from './seed.kind.ts';
|
|
2
|
+
export { bootstrapSeedConditionSchema, bootstrapSeedDescriptorSchema, bootstrapSeedModeSchema, type BootstrapSeedCondition, type BootstrapSeedDescriptor, type BootstrapSeedMode } from './seed.descriptor.ts';
|
|
3
|
+
export type { BootstrapSeedImpl } from './seed.impl-shape.ts';
|
|
4
|
+
export { runBootstrapSeeds, type BootstrapSeedRunOptions, type BootstrapSeedRunResult } from './seed.runner.ts';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bootstrap/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EACN,4BAA4B,EAC5B,6BAA6B,EAC7B,uBAAuB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EACtB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EACN,iBAAiB,EACjB,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bootstrap/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EACN,4BAA4B,EAC5B,6BAA6B,EAC7B,uBAAuB,EAIvB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACN,iBAAiB,EAGjB,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const bootstrapSeedModeSchema: z.ZodEnum<{
|
|
3
|
+
"cold-start": "cold-start";
|
|
4
|
+
deploy: "deploy";
|
|
5
|
+
}>;
|
|
6
|
+
export type BootstrapSeedMode = z.infer<typeof bootstrapSeedModeSchema>;
|
|
7
|
+
export declare const bootstrapSeedConditionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
8
|
+
kind: z.ZodLiteral<"always">;
|
|
9
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
10
|
+
kind: z.ZodLiteral<"env-keys-present">;
|
|
11
|
+
keys: z.ZodArray<z.ZodString>;
|
|
12
|
+
}, z.core.$strip>], "kind">;
|
|
13
|
+
export type BootstrapSeedCondition = z.infer<typeof bootstrapSeedConditionSchema>;
|
|
14
|
+
export declare const bootstrapSeedDescriptorSchema: z.ZodObject<{
|
|
15
|
+
kind: z.ZodLiteral<"bootstrap/seed">;
|
|
16
|
+
id: z.ZodString;
|
|
17
|
+
description: z.ZodOptional<z.ZodString>;
|
|
18
|
+
executeOn: z.ZodArray<z.ZodEnum<{
|
|
19
|
+
"cold-start": "cold-start";
|
|
20
|
+
deploy: "deploy";
|
|
21
|
+
}>>;
|
|
22
|
+
condition: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
23
|
+
kind: z.ZodLiteral<"always">;
|
|
24
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
25
|
+
kind: z.ZodLiteral<"env-keys-present">;
|
|
26
|
+
keys: z.ZodArray<z.ZodString>;
|
|
27
|
+
}, z.core.$strip>], "kind">>;
|
|
28
|
+
priority: z.ZodOptional<z.ZodNumber>;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
export type BootstrapSeedDescriptor = z.infer<typeof bootstrapSeedDescriptorSchema>;
|
|
31
|
+
//# sourceMappingURL=seed.descriptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed.descriptor.d.ts","sourceRoot":"","sources":["../../src/bootstrap/seed.descriptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,uBAAuB;;;EAAmC,CAAC;AACxE,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE,eAAO,MAAM,4BAA4B;;;;;2BAMvC,CAAC;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAElF,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;iBAOxC,CAAC;AAEH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const bootstrapSeedModeSchema = z.enum(['cold-start', 'deploy']);
|
|
3
|
+
export const bootstrapSeedConditionSchema = z.discriminatedUnion('kind', [
|
|
4
|
+
z.object({ kind: z.literal('always') }),
|
|
5
|
+
z.object({
|
|
6
|
+
kind: z.literal('env-keys-present'),
|
|
7
|
+
keys: z.array(z.string().min(1)).min(1)
|
|
8
|
+
})
|
|
9
|
+
]);
|
|
10
|
+
export const bootstrapSeedDescriptorSchema = z.object({
|
|
11
|
+
kind: z.literal('bootstrap/seed'),
|
|
12
|
+
id: z.string().min(1),
|
|
13
|
+
description: z.string().optional(),
|
|
14
|
+
executeOn: z.array(bootstrapSeedModeSchema).min(1),
|
|
15
|
+
condition: bootstrapSeedConditionSchema.optional(),
|
|
16
|
+
priority: z.number().int().optional()
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=seed.descriptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed.descriptor.js","sourceRoot":"","sources":["../../src/bootstrap/seed.descriptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC;AAGxE,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE;IACxE,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;IACvC,CAAC,CAAC,MAAM,CAAC;QACR,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC;QACnC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;KACvC,CAAC;CACF,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAC,MAAM,CAAC;IACrD,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC;IACjC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACrB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAClD,SAAS,EAAE,4BAA4B,CAAC,QAAQ,EAAE;IAClD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;CACrC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed.impl-shape.d.ts","sourceRoot":"","sources":["../../src/bootstrap/seed.impl-shape.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,MAAM,WAAW,iBAAiB;IACjC,GAAG,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed.impl-shape.js","sourceRoot":"","sources":["../../src/bootstrap/seed.impl-shape.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RuntimeKindDescriptor } from '@vibesdotdev/runtime/schemas/kind';
|
|
2
|
+
import { type BootstrapSeedDescriptor } from './seed.descriptor.ts';
|
|
3
|
+
import type { BootstrapSeedImpl } from './seed.impl-shape.ts';
|
|
4
|
+
export declare const bootstrapSeedKind: RuntimeKindDescriptor<BootstrapSeedDescriptor, BootstrapSeedImpl, never>;
|
|
5
|
+
//# sourceMappingURL=seed.kind.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed.kind.d.ts","sourceRoot":"","sources":["../../src/bootstrap/seed.kind.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAqB,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAClG,OAAO,EAEN,KAAK,uBAAuB,EAC5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAS9D,eAAO,MAAM,iBAAiB,EAAE,qBAAqB,CACpD,uBAAuB,EACvB,iBAAiB,EACjB,KAAK,CAQL,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { bootstrapSeedDescriptorSchema } from "./seed.descriptor.js";
|
|
2
|
+
class UnregisteredBootstrapSeed {
|
|
3
|
+
constructor(_descriptor) { }
|
|
4
|
+
async run() {
|
|
5
|
+
// No-op when no impl loader is registered for this descriptor id.
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export const bootstrapSeedKind = {
|
|
9
|
+
id: 'bootstrap/seed',
|
|
10
|
+
descriptorSchema: bootstrapSeedDescriptorSchema,
|
|
11
|
+
defaultImplementation: UnregisteredBootstrapSeed,
|
|
12
|
+
contexts: []
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=seed.kind.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed.kind.js","sourceRoot":"","sources":["../../src/bootstrap/seed.kind.ts"],"names":[],"mappings":"AACA,OAAO,EACN,6BAA6B,EAE7B,MAAM,sBAAsB,CAAC;AAG9B,MAAM,yBAAyB;IAC9B,YAAY,WAA8B,IAAG,CAAC;IAC9C,KAAK,CAAC,GAAG;QACR,kEAAkE;IACnE,CAAC;CACD;AAED,MAAM,CAAC,MAAM,iBAAiB,GAI1B;IACH,EAAE,EAAE,gBAAgB;IACpB,gBAAgB,EAAE,6BAA6B;IAC/C,qBAAqB,EAAE,yBAED;IACtB,QAAQ,EAAE,EAAE;CACZ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { VibesRuntime } from '@vibesdotdev/runtime';
|
|
2
|
+
import type { BootstrapSeedMode } from './seed.descriptor.ts';
|
|
3
|
+
export interface BootstrapSeedRunResult {
|
|
4
|
+
ran: string[];
|
|
5
|
+
skipped: Array<{
|
|
6
|
+
id: string;
|
|
7
|
+
reason: string;
|
|
8
|
+
}>;
|
|
9
|
+
failed: Array<{
|
|
10
|
+
id: string;
|
|
11
|
+
error: string;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
14
|
+
export interface BootstrapSeedRunOptions {
|
|
15
|
+
env: Record<string, string | undefined>;
|
|
16
|
+
}
|
|
17
|
+
export declare function runBootstrapSeeds(runtime: VibesRuntime, mode: BootstrapSeedMode, options: BootstrapSeedRunOptions): Promise<BootstrapSeedRunResult>;
|
|
18
|
+
//# sourceMappingURL=seed.runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed.runner.d.ts","sourceRoot":"","sources":["../../src/bootstrap/seed.runner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,KAAK,EAGX,iBAAiB,EACjB,MAAM,sBAAsB,CAAC;AAK9B,MAAM,WAAW,sBAAsB;IACtC,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,OAAO,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,MAAM,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,uBAAuB;IACvC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CACxC;AAED,wBAAsB,iBAAiB,CACtC,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,iBAAiB,EACvB,OAAO,EAAE,uBAAuB,GAC9B,OAAO,CAAC,sBAAsB,CAAC,CAiDjC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { getLogger } from '@vibesdotdev/logging';
|
|
2
|
+
const log = getLogger('infra.bootstrap.seed');
|
|
3
|
+
export async function runBootstrapSeeds(runtime, mode, options) {
|
|
4
|
+
const allDescriptors = runtime
|
|
5
|
+
.assets('bootstrap/seed')
|
|
6
|
+
.descriptors();
|
|
7
|
+
const result = { ran: [], skipped: [], failed: [] };
|
|
8
|
+
const runnable = [];
|
|
9
|
+
for (const descriptor of allDescriptors) {
|
|
10
|
+
if (!descriptor.executeOn.includes(mode)) {
|
|
11
|
+
result.skipped.push({
|
|
12
|
+
id: descriptor.id,
|
|
13
|
+
reason: `mode ${mode} not in executeOn`
|
|
14
|
+
});
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (!evaluateCondition(descriptor.condition, options.env)) {
|
|
18
|
+
result.skipped.push({
|
|
19
|
+
id: descriptor.id,
|
|
20
|
+
reason: 'condition not met'
|
|
21
|
+
});
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
runnable.push(descriptor);
|
|
25
|
+
}
|
|
26
|
+
runnable.sort((a, b) => (a.priority ?? 100) - (b.priority ?? 100));
|
|
27
|
+
for (const descriptor of runnable) {
|
|
28
|
+
try {
|
|
29
|
+
const impl = (await runtime
|
|
30
|
+
.query('bootstrap/seed')
|
|
31
|
+
.withId(descriptor.id)
|
|
32
|
+
.resolve());
|
|
33
|
+
await impl.run(runtime, options.env);
|
|
34
|
+
result.ran.push(descriptor.id);
|
|
35
|
+
log.info('bootstrap seed completed', {
|
|
36
|
+
id: descriptor.id,
|
|
37
|
+
mode,
|
|
38
|
+
priority: descriptor.priority ?? 100
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
const error = err instanceof Error ? err.message : String(err);
|
|
43
|
+
result.failed.push({ id: descriptor.id, error });
|
|
44
|
+
log.error('bootstrap seed failed', { id: descriptor.id, mode, error });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
function evaluateCondition(condition, env) {
|
|
50
|
+
if (!condition)
|
|
51
|
+
return true;
|
|
52
|
+
if (condition.kind === 'always')
|
|
53
|
+
return true;
|
|
54
|
+
if (condition.kind === 'env-keys-present') {
|
|
55
|
+
return condition.keys.every((key) => Boolean(env[key]));
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=seed.runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed.runner.js","sourceRoot":"","sources":["../../src/bootstrap/seed.runner.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider-agnostic credential resolution for infra/* adapters.
|
|
3
|
+
*
|
|
4
|
+
* Routes through the `secrets/store` runtime kind so every adapter
|
|
5
|
+
* (alerts, RUM, observability, …) reads from the same credential chain
|
|
6
|
+
* the rest of the platform uses. The chain (highest precedence first):
|
|
7
|
+
*
|
|
8
|
+
* 1. process.env (CI / explicit overrides)
|
|
9
|
+
* 2. The tier-resolved secrets/store implementation
|
|
10
|
+
* - local tier → encrypted-local → env-file
|
|
11
|
+
* - production → cloudflare-secrets-store → cloudflare-api
|
|
12
|
+
*
|
|
13
|
+
* Adapters declare the secret KEY NAMES (e.g. CLOUDFLARE_API_TOKEN) on
|
|
14
|
+
* their descriptor's `adapterConfig` and use this helper to resolve
|
|
15
|
+
* the values. The helper supports `keyCandidates` for fallback chains
|
|
16
|
+
* (e.g. prefer a scoped CLOUDFLARE_NOTIFICATIONS_API_TOKEN, fall back
|
|
17
|
+
* to the broad CLOUDFLARE_API_TOKEN).
|
|
18
|
+
*
|
|
19
|
+
* Why a helper instead of inlining the secrets/store query: provider
|
|
20
|
+
* adapters live in different packages and shouldn't all duplicate the
|
|
21
|
+
* tier-walk + env-overlay logic. Keeping it in infra-core makes the
|
|
22
|
+
* abstraction explicit ("infra/* adapters route credentials through
|
|
23
|
+
* vibes secrets") and gives us one place to evolve the chain (e.g.
|
|
24
|
+
* adding 1Password CLI as a backend).
|
|
25
|
+
*/
|
|
26
|
+
export type EnvironmentTier = 'local' | 'dev' | 'staging' | 'production';
|
|
27
|
+
export interface ResolveAdapterCredentialOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Ordered list of candidate keys. First one that resolves to a
|
|
30
|
+
* non-empty value wins. Useful for scoped → fallback patterns:
|
|
31
|
+
* ['CLOUDFLARE_NOTIFICATIONS_API_TOKEN', 'CLOUDFLARE_API_TOKEN']
|
|
32
|
+
*/
|
|
33
|
+
keyCandidates: readonly string[];
|
|
34
|
+
/**
|
|
35
|
+
* Environment name to read from the secrets store (default: 'local').
|
|
36
|
+
* Maps onto vault.environments[name] in encrypted-local.
|
|
37
|
+
*/
|
|
38
|
+
environment?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Tier hint for runtime store selection. Defaults to inferring from
|
|
41
|
+
* the environment name when it matches a known tier; falls back to
|
|
42
|
+
* 'local' otherwise.
|
|
43
|
+
*/
|
|
44
|
+
tier?: EnvironmentTier;
|
|
45
|
+
/**
|
|
46
|
+
* Whether to consult process.env first. Defaults true — CI/CD and
|
|
47
|
+
* explicit shell overrides should win. Pass false to force
|
|
48
|
+
* store-only resolution.
|
|
49
|
+
*/
|
|
50
|
+
includeProcessEnv?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Optional human-readable name for the credential, used in error
|
|
53
|
+
* messages when no candidate resolves (e.g. "Cloudflare API token").
|
|
54
|
+
*/
|
|
55
|
+
humanName?: string;
|
|
56
|
+
}
|
|
57
|
+
export interface ResolvedAdapterCredential {
|
|
58
|
+
/** The KEY that resolved (one of keyCandidates). Useful for audit. */
|
|
59
|
+
key: string;
|
|
60
|
+
/** The resolved secret value. Never logged. */
|
|
61
|
+
value: string;
|
|
62
|
+
/** Where the value came from: 'process.env' or the store backend id. */
|
|
63
|
+
source: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Resolve a single credential by walking the candidate keys against
|
|
67
|
+
* process.env then the active secrets store. Returns the first match.
|
|
68
|
+
*
|
|
69
|
+
* Throws when no candidate resolves — adapters should let this bubble
|
|
70
|
+
* up so the CLI surfaces a clean "missing credentials" message rather
|
|
71
|
+
* than a vague "401 Unauthorized" downstream.
|
|
72
|
+
*/
|
|
73
|
+
export declare function resolveAdapterCredential(options: ResolveAdapterCredentialOptions): Promise<ResolvedAdapterCredential>;
|
|
74
|
+
/**
|
|
75
|
+
* Convenience wrapper for resolving multiple credentials at once.
|
|
76
|
+
* Each key gets a candidate list of one (the key itself). Use the
|
|
77
|
+
* single-credential form when you need fallback chains.
|
|
78
|
+
*/
|
|
79
|
+
export declare function resolveAdapterCredentials(keys: readonly string[], options?: Omit<ResolveAdapterCredentialOptions, 'keyCandidates' | 'humanName'>): Promise<Record<string, ResolvedAdapterCredential>>;
|
|
80
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/credentials/resolve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAIH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,KAAK,GAAG,SAAS,GAAG,YAAY,CAAC;AAEzE,MAAM,WAAW,+BAA+B;IAC/C;;;;OAIG;IACH,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,yBAAyB;IACzC,sEAAsE;IACtE,GAAG,EAAE,MAAM,CAAC;IACZ,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,wEAAwE;IACxE,MAAM,EAAE,MAAM,CAAC;CACf;AAqCD;;;;;;;GAOG;AACH,wBAAsB,wBAAwB,CAC7C,OAAO,EAAE,+BAA+B,GACtC,OAAO,CAAC,yBAAyB,CAAC,CAsEpC;AAED;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC9C,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,IAAI,CAAC,+BAA+B,EAAE,eAAe,GAAG,WAAW,CAAC,GAC5E,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAC,CASpD"}
|