@wildo-ai/platform-config-lib 1.1.2 → 1.1.4
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/dist/esm/bootstrap/application-backend-env.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/bootstrap-planner.d.ts.map +1 -1
- package/dist/esm/bootstrap/bootstrap.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/bootstrap.schemas.d.ts +129 -1
- package/dist/esm/bootstrap/bootstrap.schemas.d.ts.map +1 -1
- package/dist/esm/bootstrap/bootstrap.schemas.js +105 -2
- package/dist/esm/bootstrap/bootstrap.schemas.js.map +1 -1
- package/dist/esm/bootstrap/platform-runtime-env.contracts.d.ts +6 -3
- package/dist/esm/bootstrap/platform-runtime-env.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/platform-runtime-env.contracts.js +18 -3
- package/dist/esm/bootstrap/platform-runtime-env.contracts.js.map +1 -1
- package/dist/esm/bootstrap/runtime-backing-service-access.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-network-policy.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-network-topology.d.ts +0 -1
- package/dist/esm/bootstrap/runtime-network-topology.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-network-topology.js +0 -2
- package/dist/esm/bootstrap/runtime-network-topology.js.map +1 -1
- package/dist/esm/bootstrap/runtime-platform-access.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-principal.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-topology.contracts.d.ts.map +1 -1
- package/dist/esm/config-authoring.entry.d.ts +1 -2
- package/dist/esm/config-authoring.entry.d.ts.map +1 -1
- package/dist/esm/config-authoring.entry.js +35 -2
- package/dist/esm/config-authoring.entry.js.map +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/lockfile/lockfile-io.d.ts.map +1 -1
- package/dist/esm/lockfile/materialize-infra-section.d.ts.map +1 -1
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.d.ts +0 -20
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.d.ts.map +1 -1
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.js +0 -1
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.js.map +1 -1
- package/dist/esm/project-config/define-framework-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-infra-env-config.d.ts +3 -39
- package/dist/esm/project-config/define-infra-env-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-infra-env-config.js +2 -2
- package/dist/esm/project-config/define-infra-env-config.js.map +1 -1
- package/dist/esm/project-config/define-minion-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-saas-config.d.ts +366 -14
- package/dist/esm/project-config/define-saas-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-saas-config.js +121 -11
- package/dist/esm/project-config/define-saas-config.js.map +1 -1
- package/dist/esm/project-config/define-worker-config.d.ts.map +1 -1
- package/dist/esm/project-config/index.d.ts.map +1 -1
- package/dist/esm/project-config/loader.d.ts.map +1 -1
- package/dist/esm/project-config/provider-catalog-types.d.ts.map +1 -1
- package/dist/esm/project-config/provider-companion-discovery.d.ts +88 -1
- package/dist/esm/project-config/provider-companion-discovery.d.ts.map +1 -1
- package/dist/esm/project-config/provider-companion-discovery.js +275 -6
- package/dist/esm/project-config/provider-companion-discovery.js.map +1 -1
- package/dist/esm/project-config/provider-runtime-artifacts.d.ts +42 -16
- package/dist/esm/project-config/provider-runtime-artifacts.d.ts.map +1 -1
- package/dist/esm/project-config/provider-runtime-artifacts.js +132 -12
- package/dist/esm/project-config/provider-runtime-artifacts.js.map +1 -1
- package/dist/esm/project-config/shared/application-creation-verification.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/application-modules.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/application-modules.utils.d.ts.map +1 -1
- package/dist/esm/project-config/shared/auth.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/backing-services.schemas.d.ts +32 -43
- package/dist/esm/project-config/shared/backing-services.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/backing-services.schemas.js +38 -30
- package/dist/esm/project-config/shared/backing-services.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/cdn.example.d.ts.map +1 -1
- package/dist/esm/project-config/shared/cdn.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/csp-defaults.d.ts.map +1 -1
- package/dist/esm/project-config/shared/csp-emit.d.ts +36 -5
- package/dist/esm/project-config/shared/csp-emit.d.ts.map +1 -1
- package/dist/esm/project-config/shared/csp-emit.js +65 -5
- package/dist/esm/project-config/shared/csp-emit.js.map +1 -1
- package/dist/esm/project-config/shared/csp.schemas.d.ts +46 -10
- package/dist/esm/project-config/shared/csp.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/csp.schemas.js +45 -10
- package/dist/esm/project-config/shared/csp.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/data-services.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/env-example-defaults.d.ts.map +1 -1
- package/dist/esm/project-config/shared/environment.schemas.d.ts +8 -6
- package/dist/esm/project-config/shared/environment.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/environment.schemas.js +7 -5
- package/dist/esm/project-config/shared/environment.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/infra-providers.schemas.d.ts +29 -3
- package/dist/esm/project-config/shared/infra-providers.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/infra-providers.schemas.js +34 -2
- package/dist/esm/project-config/shared/infra-providers.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/infra-service.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/infrastructure-defaults.schemas.d.ts +0 -2
- package/dist/esm/project-config/shared/infrastructure-defaults.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/infrastructure-defaults.schemas.js +0 -2
- package/dist/esm/project-config/shared/infrastructure-defaults.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/k8s-utils.d.ts +70 -10
- package/dist/esm/project-config/shared/k8s-utils.d.ts.map +1 -1
- package/dist/esm/project-config/shared/k8s-utils.js +75 -11
- package/dist/esm/project-config/shared/k8s-utils.js.map +1 -1
- package/dist/esm/project-config/shared/minion-platform-access.vocabulary.d.ts +15 -15
- package/dist/esm/project-config/shared/minion-platform-access.vocabulary.d.ts.map +1 -1
- package/dist/esm/project-config/shared/minion-platform-access.vocabulary.js +15 -15
- package/dist/esm/project-config/shared/minion-platform-access.vocabulary.js.map +1 -1
- package/dist/esm/project-config/shared/minion-resource-access.validation.d.ts +76 -0
- package/dist/esm/project-config/shared/minion-resource-access.validation.d.ts.map +1 -1
- package/dist/esm/project-config/shared/minion-resource-access.validation.js +76 -1
- package/dist/esm/project-config/shared/minion-resource-access.validation.js.map +1 -1
- package/dist/esm/project-config/shared/platform-services.schemas.d.ts +30 -0
- package/dist/esm/project-config/shared/platform-services.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/platform-services.schemas.js +31 -0
- package/dist/esm/project-config/shared/platform-services.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/schema-version.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/service-definitions.schemas.d.ts.map +1 -1
- package/dist/esm/registry/artifact-domain.schemas.d.ts.map +1 -1
- package/dist/esm/registry/companion-api.schemas.d.ts.map +1 -1
- package/dist/esm/registry/digest.schemas.d.ts.map +1 -1
- package/dist/esm/registry/index.d.ts.map +1 -1
- package/dist/esm/registry/lockfile-modules-section.schemas.d.ts.map +1 -1
- package/dist/esm/registry/module-artifact.schemas.d.ts.map +1 -1
- package/dist/esm/registry/module-manifest.schemas.d.ts.map +1 -1
- package/dist/esm/registry/registry-config.schemas.d.ts.map +1 -1
- package/dist/esm/registry/registry-section-schemas.constants.d.ts.map +1 -1
- package/dist/esm/release/framework-release.constants.d.ts.map +1 -1
- package/dist/esm/release/framework-release.constants.js.map +1 -1
- package/dist/esm/schemas/framework-info.schemas.d.ts.map +1 -1
- package/dist/esm/schemas/framework-secrets.schemas.d.ts.map +1 -1
- package/dist/esm/schemas/platform-application-config.schemas.d.ts.map +1 -1
- package/dist/esm/schemas/platform-application-secrets.schemas.d.ts.map +1 -1
- package/dist/esm/schemas/platform-config.schemas.d.ts.map +1 -1
- package/dist/esm/workspace-scope/application-subject-manifest.d.ts.map +1 -1
- package/dist/esm/workspace-scope/index.d.ts.map +1 -1
- package/dist/esm/workspace-scope/resolve-homes.d.ts.map +1 -1
- package/dist/esm/workspace-scope/workspace-homes.schemas.d.ts +14 -0
- package/dist/esm/workspace-scope/workspace-homes.schemas.d.ts.map +1 -1
- package/dist/esm/workspace-scope/workspace-homes.schemas.js +2 -0
- package/dist/esm/workspace-scope/workspace-homes.schemas.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +7 -7
|
@@ -25,7 +25,6 @@ export var BackingServiceKind;
|
|
|
25
25
|
BackingServiceKind["RABBITMQ"] = "rabbitmq";
|
|
26
26
|
BackingServiceKind["S3"] = "s3";
|
|
27
27
|
BackingServiceKind["POSTGRESQL"] = "postgresql";
|
|
28
|
-
BackingServiceKind["GOTENBERG"] = "gotenberg";
|
|
29
28
|
BackingServiceKind["CLAMAV"] = "clamav";
|
|
30
29
|
/**
|
|
31
30
|
* immudb — an immutable, cryptographically-verifiable database used as a
|
|
@@ -33,11 +32,6 @@ export var BackingServiceKind;
|
|
|
33
32
|
* A stateful DB: a data volume in dev, self-hosted or immudb Vault in prod.
|
|
34
33
|
*/
|
|
35
34
|
BackingServiceKind["IMMUDB"] = "immudb";
|
|
36
|
-
/**
|
|
37
|
-
* Metrics / telemetry sink (Prometheus, DataDog, OpenTelemetry, …).
|
|
38
|
-
* Stateless base for now.
|
|
39
|
-
*/
|
|
40
|
-
BackingServiceKind["METRICS"] = "metrics-telemetry";
|
|
41
35
|
/**
|
|
42
36
|
* Backup orchestration target. Stateless base for now.
|
|
43
37
|
*/
|
|
@@ -171,8 +165,6 @@ export const S3BackingServiceSchema = BackingServiceBaseSchema.extend({
|
|
|
171
165
|
endpoint: z.string().min(1).optional(),
|
|
172
166
|
bucket: z.string().min(1).optional(),
|
|
173
167
|
}).strict();
|
|
174
|
-
/** Gotenberg PDF service. Stateless, no database/vhost/bucket. */
|
|
175
|
-
export const GotenbergBackingServiceSchema = BackingServiceBaseSchema;
|
|
176
168
|
/** ClamAV anti-virus daemon. Stateless, no database/vhost/bucket. */
|
|
177
169
|
export const ClamAvBackingServiceSchema = BackingServiceBaseSchema;
|
|
178
170
|
/**
|
|
@@ -200,11 +192,6 @@ export const ClamAvBackingServiceSchema = BackingServiceBaseSchema;
|
|
|
200
192
|
export const ImmudbBackingServiceSchema = BackingServiceBaseSchema.extend({
|
|
201
193
|
database: z.string().min(1).optional(),
|
|
202
194
|
}).strict();
|
|
203
|
-
/**
|
|
204
|
-
* Metrics / telemetry sink (Prometheus / DataDog / OpenTelemetry / …).
|
|
205
|
-
* Stateless base for now.
|
|
206
|
-
*/
|
|
207
|
-
export const MetricsBackingServiceSchema = BackingServiceBaseSchema;
|
|
208
195
|
/**
|
|
209
196
|
* Backup orchestration target. Stateless base for now.
|
|
210
197
|
*/
|
|
@@ -224,10 +211,8 @@ export const BackingServicesEnvConfigSchema = z.object({
|
|
|
224
211
|
[BackingServiceKind.RABBITMQ]: RabbitBackingServiceSchema.optional(),
|
|
225
212
|
[BackingServiceKind.S3]: S3BackingServiceSchema.optional(),
|
|
226
213
|
[BackingServiceKind.POSTGRESQL]: PostgresBackingServiceSchema.optional(),
|
|
227
|
-
[BackingServiceKind.GOTENBERG]: GotenbergBackingServiceSchema.optional(),
|
|
228
214
|
[BackingServiceKind.CLAMAV]: ClamAvBackingServiceSchema.optional(),
|
|
229
215
|
[BackingServiceKind.IMMUDB]: ImmudbBackingServiceSchema.optional(),
|
|
230
|
-
[BackingServiceKind.METRICS]: MetricsBackingServiceSchema.optional(),
|
|
231
216
|
[BackingServiceKind.BACKUP]: BackupBackingServiceSchema.optional(),
|
|
232
217
|
}).strict();
|
|
233
218
|
/** @wildo_source:part:end platform.config.backing-services */
|
|
@@ -243,11 +228,14 @@ export const BackingServicesEnvConfigSchema = z.object({
|
|
|
243
228
|
// walks "what infra is selected per env"). The mappings below are the
|
|
244
229
|
// single source of truth for that projection — no other code may
|
|
245
230
|
// reconstruct them locally.
|
|
231
|
+
/** @wildo_source:part:start platform.config.infra-provider-resolution facet:layer:platform facet:audience:app-developer */
|
|
246
232
|
/**
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
233
|
+
* `BackingServiceKind` → `InfraCapability`. Every extension to `BackingServiceKind` MUST extend this
|
|
234
|
+
* map in the same commit, otherwise the planner cannot project the new kind to its capability slot.
|
|
235
|
+
*
|
|
236
|
+
* INJECTIVE, not bijective — and the difference is a real property of the model rather than a gap.
|
|
237
|
+
* A capability may be granted to a runtime without any environment declaring a backing service for
|
|
238
|
+
* it; see {@link RUNTIME_GRANTED_INFRA_CAPABILITIES} for the ones that are, and why.
|
|
251
239
|
*/
|
|
252
240
|
export const BackingServiceKindToInfraCapability = {
|
|
253
241
|
[BackingServiceKind.MONGODB]: InfraCapability.DOCUMENT_DATABASE,
|
|
@@ -255,10 +243,8 @@ export const BackingServiceKindToInfraCapability = {
|
|
|
255
243
|
[BackingServiceKind.RABBITMQ]: InfraCapability.QUEUING_SYSTEM,
|
|
256
244
|
[BackingServiceKind.REDIS]: InfraCapability.CACHE_MANAGER,
|
|
257
245
|
[BackingServiceKind.S3]: InfraCapability.OBJECT_STORAGE,
|
|
258
|
-
[BackingServiceKind.GOTENBERG]: InfraCapability.DOCUMENT_RENDERING,
|
|
259
246
|
[BackingServiceKind.CLAMAV]: InfraCapability.ANTIVIRUS_SCANNING,
|
|
260
247
|
[BackingServiceKind.IMMUDB]: InfraCapability.AUDIT_LOG_STORAGE,
|
|
261
|
-
[BackingServiceKind.METRICS]: InfraCapability.METRICS_TELEMETRY,
|
|
262
248
|
[BackingServiceKind.BACKUP]: InfraCapability.BACKUP_MANAGER,
|
|
263
249
|
};
|
|
264
250
|
/**
|
|
@@ -288,7 +274,7 @@ export const BackingServiceKindToInfraCapability = {
|
|
|
288
274
|
* | `S3` | `SELF` | (`'minio'` or unset) | `MINIO_SELF` |
|
|
289
275
|
* | `S3` | `MANAGED` | `'aws'` | `AWS_S3` |
|
|
290
276
|
* | `CLAMAV` | `SELF` | (any) | `CLAMAV_SELF` |
|
|
291
|
-
* | `
|
|
277
|
+
* | `IMMUDB` | `SELF` | (any) | `IMMUDB_SELF` |
|
|
292
278
|
*
|
|
293
279
|
* Returns `undefined` for combinations not in the table — for kinds
|
|
294
280
|
* whose `InfraProvider` catalog has no concrete entry yet (METRICS,
|
|
@@ -297,6 +283,28 @@ export const BackingServiceKindToInfraCapability = {
|
|
|
297
283
|
* unlike Postgres). Callers decide whether `undefined` is fail-closed
|
|
298
284
|
* (planner running with unknown infra catalog) or accepted (lockfile
|
|
299
285
|
* pre-declaration).
|
|
286
|
+
*
|
|
287
|
+
* ## What this means when you author an environment
|
|
288
|
+
*
|
|
289
|
+
* **`MANAGED` does not reach every kind.** The table above is the whole of it: a managed vendor
|
|
290
|
+
* resolves for the relational database (six named brands plus a generic fallback), the document
|
|
291
|
+
* database (`'atlas'` only) and object storage. Declaring `{ source: MANAGED }` on the cache, the
|
|
292
|
+
* broker, the antivirus scanner, the audit store or the backup target resolves to NOTHING — those
|
|
293
|
+
* kinds are self-hosted only until their vendor catalogue is built.
|
|
294
|
+
*
|
|
295
|
+
* **And nothing tells you.** A kind that resolves to no provider is SKIPPED when the lockfile's infra
|
|
296
|
+
* section is materialised, silently, because recording an entry with no provider would lie. So a
|
|
297
|
+
* managed declaration the catalogue cannot serve looks exactly like a correct one: `wildo config
|
|
298
|
+
* sync` succeeds, the file says `MANAGED`, and the environment has no managed anything. Read the
|
|
299
|
+
* lockfile's infra section to see which of your declarations were actually resolved.
|
|
300
|
+
*
|
|
301
|
+
* **An unrecognised brand is not the same failure on every kind.** On the relational database it
|
|
302
|
+
* falls back to the generic managed entry, so a typo still resolves. On the document database and on
|
|
303
|
+
* object storage there is no generic fallback, so a typo resolves to nothing and is skipped.
|
|
304
|
+
*
|
|
305
|
+
* **Declaring a service managed does not always stop the local one being rendered.** The inclusion
|
|
306
|
+
* gates in the Compose and Kubernetes lanes are separate from this resolution and cover different
|
|
307
|
+
* kinds, so a managed declaration can leave a local container in the rendered stack beside it.
|
|
300
308
|
*/
|
|
301
309
|
export function resolveInfraProvider(kind, source, provider) {
|
|
302
310
|
switch (kind) {
|
|
@@ -364,21 +372,21 @@ export function resolveInfraProvider(kind, source, provider) {
|
|
|
364
372
|
if (source === BackingServiceSource.SELF)
|
|
365
373
|
return InfraProvider.CLAMAV_SELF;
|
|
366
374
|
return undefined;
|
|
367
|
-
case BackingServiceKind.GOTENBERG:
|
|
368
|
-
if (source === BackingServiceSource.SELF)
|
|
369
|
-
return InfraProvider.GOTENBERG_SELF;
|
|
370
|
-
return undefined;
|
|
371
375
|
case BackingServiceKind.IMMUDB:
|
|
372
376
|
if (source === BackingServiceSource.SELF)
|
|
373
377
|
return InfraProvider.IMMUDB_SELF;
|
|
374
378
|
// Managed immudb (immudb Vault) — not catalogued yet; future expansion.
|
|
375
379
|
return undefined;
|
|
376
|
-
case BackingServiceKind.METRICS:
|
|
377
380
|
case BackingServiceKind.BACKUP:
|
|
378
|
-
// No concrete `InfraProvider` declared yet for
|
|
379
|
-
//
|
|
380
|
-
//
|
|
381
|
+
// No concrete `InfraProvider` declared yet for this kind. Extend the `InfraProvider` enum +
|
|
382
|
+
// this branch in the same slice that introduces the first concrete provider for it.
|
|
383
|
+
//
|
|
384
|
+
// `METRICS` was the other kind here and was WITHDRAWN 2026-09-09: telemetry is authored at
|
|
385
|
+
// `observability.telemetry` and its auth header derived from the selected
|
|
386
|
+
// `OBSERVABILITY_TELEMETRY` provider, so a backing-service kind was a third declaration
|
|
387
|
+
// surface that nothing read. See `RUNTIME_GRANTED_INFRA_CAPABILITIES`.
|
|
381
388
|
return undefined;
|
|
382
389
|
}
|
|
383
390
|
}
|
|
391
|
+
/** @wildo_source:part:end platform.config.infra-provider-resolution */
|
|
384
392
|
//# sourceMappingURL=backing-services.schemas.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backing-services.schemas.js","sourceRoot":"","sources":["../../../../../src/project-config/shared/backing-services.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,eAAe,EACf,aAAa,GACd,MAAM,2BAA2B,CAAC;AAEnC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAN,IAAY,kBAuBX;AAvBD,WAAY,kBAAkB;IAC5B,yCAAmB,CAAA;IACnB,qCAAe,CAAA;IACf,2CAAqB,CAAA;IACrB,+BAAS,CAAA;IACT,+CAAyB,CAAA;IACzB,6CAAuB,CAAA;IACvB,uCAAiB,CAAA;IACjB;;;;OAIG;IACH,uCAAiB,CAAA;IACjB;;;OAGG;IACH,mDAA6B,CAAA;IAC7B;;OAEG;IACH,uCAAiB,CAAA;AACnB,CAAC,EAvBW,kBAAkB,KAAlB,kBAAkB,QAuB7B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAN,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC9B,qCAAa,CAAA;IACb,2CAAmB,CAAA;AACrB,CAAC,EAHW,oBAAoB,KAApB,oBAAoB,QAG/B;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC;IACpC;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IACtC;;;;;;OAMG;IACH,IAAI,EAAE,CAAC,CAAC,MAAM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nB,KAAK,kBAAkB,CAAC,OAAO,CAAC;QAChC,KAAK,kBAAkB,CAAC,MAAM;YAC5B,4DAA4D;YAC5D,8DAA8D;YAC9D,6DAA6D;YAC7D,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC","sourcesContent":["import { z } from 'zod';\nimport {\n InfraCapability,\n InfraProvider,\n} from './infra-providers.schemas';\n\n/**\n * The backing-service authoring surface of `wildo.infra.<env>.config.ts`.\n *\n * Import from `@wildo-ai/platform-config-lib`. Everything below is what an\n * environment file may declare under `backingServices: { ... }` — the closed kind\n * vocabulary, the hosting-model axis, and the per-kind entry shape. The\n * `InfraCapability` / `InfraProvider` projections further down this file are\n * planner-internal and deliberately outside the anchor: an app author never writes\n * them.\n *\n * Declare a kind ONLY when the environment actually runs it — keys are optional so a\n * flattened app declaration stays truthful about what it enables. Omitting a kind an\n * enabled engine capability depends on is the classic silent-degradation bug: e.g.\n * `COMPLIANCE_AUDIT_TRAIL` without `immudb` leaves the tamper-evident audit store\n * unbacked, which `wildo config sync` reports as a warning per environment.\n *\n * @wildo_source:part:start platform.config.backing-services facet:layer:platform facet:family:infra\n */\nexport enum BackingServiceKind {\n MONGODB = 'mongodb',\n REDIS = 'redis',\n RABBITMQ = 'rabbitmq',\n S3 = 's3',\n POSTGRESQL = 'postgresql',\n GOTENBERG = 'gotenberg',\n CLAMAV = 'clamav',\n /**\n * immudb — an immutable, cryptographically-verifiable database used as a\n * tamper-evident audit-log store (fills the `AUDIT_LOG_STORAGE` capability).\n * A stateful DB: a data volume in dev, self-hosted or immudb Vault in prod.\n */\n IMMUDB = 'immudb',\n /**\n * Metrics / telemetry sink (Prometheus, DataDog, OpenTelemetry, …).\n * Stateless base for now.\n */\n METRICS = 'metrics-telemetry',\n /**\n * Backup orchestration target. Stateless base for now.\n */\n BACKUP = 'backup',\n}\n\n/**\n * Hosting model of a backing service instance — the orthogonal axis to\n * the **brand** (which is captured by the per-kind `provider` field).\n *\n * - `self`: self-hosted (Docker/K8s container managed by the platform,\n * or operator-managed on-prem). Brands here are open-source\n * software names (e.g. MinIO for S3, vanilla Postgres / MongoDB).\n * - `managed`: external vendor-managed service. Brands here are\n * vendor names (e.g. `'atlas'` for MongoDB Atlas, `'aws-rds'` for\n * AWS RDS, `'supabase'` for Supabase Postgres, `'aws'` for AWS S3).\n *\n * **Slice 4.B.0 reshape (2026-05-07)**: the `ATLAS` value was removed.\n * Pre-reshape `source: ATLAS` becomes `source: MANAGED, provider:\n * 'atlas'`. The reshape generalizes from \"Mongo + S3 are the only\n * brand-aware kinds\" to \"every kind can be brand-aware when the\n * managed market has multiple vendors\" — Postgres in particular\n * (RDS / GCP Cloud SQL / Supabase / Neon / Render / Azure).\n */\nexport enum BackingServiceSource {\n SELF = 'self',\n MANAGED = 'managed',\n}\n\n/**\n * Common fields every backing-service entry shares.\n *\n * Per-kind extensions add the fields that are SEMANTICALLY meaningful\n * for that kind only. Slice 3 closeout (M-4 + L-5): the previous shared\n * `BackingServiceEnvConfigSchema` collapsed `database` into a\n * `union(int, string)` and put `name` only on Mongo; both compromised\n * the framework-mindset rule that \"every field must carry its semantic\n * weight\". The split below means a typo like `redis: { database:\n * 'staging' }` (string on a kind that needs an integer DB index) is\n * rejected at parse time instead of crashing the runtime client at\n * connect time.\n */\nconst BackingServiceBaseSchema = z.object({\n source: z.enum(BackingServiceSource),\n /**\n * Brand of the backing service. Orthogonal to `source` (hosting\n * model). Required-in-spirit when `source === MANAGED` and the\n * managed market has multiple vendors (Mongo: `'atlas'` /\n * `'aws-documentdb'` / …; Postgres: `'aws-rds'` / `'gcp-cloud-sql'`\n * / `'supabase'` / `'neon'` / `'render'` / `'azure-database'`;\n * S3: `'aws'` / `'cloudflare-r2'` / …); optional when `source ===\n * SELF` (e.g. S3-self-hosted defaults to MinIO; `provider:\n * 'minio'` is allowed but redundant).\n *\n * Modeled as `z.string().optional()` rather than per-kind enum\n * unions to keep this base schema simple — the canonical brand\n * vocabulary lives in `resolveInfraProvider`'s dispatch table\n * (each kind documents which brand strings it recognizes; unknown\n * brands fall back to the kind's generic `<KIND>_MANAGED` /\n * `<KIND>_SELF` entry where one exists, otherwise return\n * `undefined`).\n *\n * Slice 4.B.0 (2026-05-07) generalized this from \"S3-only\" to\n * every brand-aware kind.\n */\n provider: z.string().min(1).optional(),\n /**\n * Override the catalog-derived hostname for this kind. Honored at\n * `HOST_FACING` perspective (always) and at `CONTAINER_INTERNAL` for\n * `MANAGED` sources. SELF + `CONTAINER_INTERNAL` keeps the catalog\n * container name because that is the only DNS the container network\n * can resolve.\n */\n host: z.string().min(1).optional(),\n /**\n * Override the catalog-derived listen port. Threaded into both\n * docker-compose `<authored>:<authored>` publish and the per-app\n * env-vars (`<KIND>_PORT`).\n */\n port: z.number().int().positive().optional(),\n}).strict();\n\n/**\n * MongoDB backing service. `database` is the database NAME (string).\n *\n * Mongo's connection URL has the shape `mongodb://host:port/<database>`\n * — this string corresponds to the path segment. Pre-3 the field was\n * `name`; renamed to `database` in Slice 3 closeout (L-5) so all\n * data-store kinds use the same property name for the same concept\n * (vs. Postgres which already used `database`).\n */\nexport const MongoBackingServiceSchema = BackingServiceBaseSchema.extend({\n database: z.string().min(1).optional(),\n}).strict();\nexport type MongoBackingService = z.infer<typeof MongoBackingServiceSchema>;\n\n/**\n * Redis backing service. `database` is the LOGICAL DB INDEX (integer).\n *\n * Redis exposes 16 logical databases (0–15) on a single connection.\n * Authoring a string here (e.g. `'staging'`) would silently parse on\n * the pre-3 union schema and crash ioredis at connect; the integer\n * constraint with `max(15)` fails loud at parse time.\n */\nexport const RedisBackingServiceSchema = BackingServiceBaseSchema.extend({\n database: z.number().int().min(0).max(15).optional(),\n}).strict();\nexport type RedisBackingService = z.infer<typeof RedisBackingServiceSchema>;\n\n/**\n * PostgreSQL backing service. `database` is the database NAME (string).\n *\n * Symmetric with `MongoBackingService.database` — both are the\n * database identifier in their respective connection URLs.\n */\nexport const PostgresBackingServiceSchema = BackingServiceBaseSchema.extend({\n database: z.string().min(1).optional(),\n}).strict();\nexport type PostgresBackingService = z.infer<typeof PostgresBackingServiceSchema>;\n\n/**\n * RabbitMQ backing service. `vhost` is the RabbitMQ virtual host.\n *\n * AMQP virtual hosts isolate exchange/queue namespaces inside a single\n * broker. NOT a database — RabbitMQ has no DB concept — so the field\n * is intentionally NOT named `database`.\n */\nexport const RabbitBackingServiceSchema = BackingServiceBaseSchema.extend({\n vhost: z.string().min(1).optional(),\n}).strict();\nexport type RabbitBackingService = z.infer<typeof RabbitBackingServiceSchema>;\n\n/**\n * S3-compatible backing service (MinIO, Scaleway Object Storage, AWS).\n *\n * `endpoint` is a URL (`http://localhost:9000`, `https://s3.eu-west.amazonaws.com`)\n * — the resolver parses it into host/port. `bucket` is the S3 bucket\n * name. NOT a database — S3 has no DB concept.\n */\nexport const S3BackingServiceSchema = BackingServiceBaseSchema.extend({\n endpoint: z.string().min(1).optional(),\n bucket: z.string().min(1).optional(),\n}).strict();\nexport type S3BackingService = z.infer<typeof S3BackingServiceSchema>;\n\n/** Gotenberg PDF service. Stateless, no database/vhost/bucket. */\nexport const GotenbergBackingServiceSchema = BackingServiceBaseSchema;\nexport type GotenbergBackingService = z.infer<typeof GotenbergBackingServiceSchema>;\n\n/** ClamAV anti-virus daemon. Stateless, no database/vhost/bucket. */\nexport const ClamAvBackingServiceSchema = BackingServiceBaseSchema;\nexport type ClamAvBackingService = z.infer<typeof ClamAvBackingServiceSchema>;\n\n/**\n * immudb backing service (tamper-evident audit-log store). A stateful DB —\n * `database` names the immudb database (defaults to `defaultdb` at runtime);\n * credentials come from the secrets pipeline like every other backing service.\n *\n * Declare this in EVERY environment where the `COMPLIANCE_AUDIT_TRAIL` engine\n * capability is enabled. `wildo config sync` warns per environment when the audit\n * capability is on but no environment declares an audit store, and the audit client\n * then has nowhere tamper-evident to write.\n *\n * You do NOT author the state-signing keypair that makes the store's\n * whole-server-substitution defense work. The framework provisions it (private half\n * mounted into a `source: SELF` immudb via `--signingKey`, public half pinned by the\n * audit client as `IMMUDB_STATE_PUBLIC_KEY`) — declaring the service is the whole job.\n *\n * @example\n * ```ts\n * backingServices: {\n * immudb: { source: BackingServiceSource.SELF },\n * }\n * ```\n */\nexport const ImmudbBackingServiceSchema = BackingServiceBaseSchema.extend({\n database: z.string().min(1).optional(),\n}).strict();\nexport type ImmudbBackingService = z.infer<typeof ImmudbBackingServiceSchema>;\n\n/**\n * Metrics / telemetry sink (Prometheus / DataDog / OpenTelemetry / …).\n * Stateless base for now.\n */\nexport const MetricsBackingServiceSchema = BackingServiceBaseSchema;\nexport type MetricsBackingService = z.infer<typeof MetricsBackingServiceSchema>;\n\n/**\n * Backup orchestration target. Stateless base for now.\n */\nexport const BackupBackingServiceSchema = BackingServiceBaseSchema;\nexport type BackupBackingService = z.infer<typeof BackupBackingServiceSchema>;\n\n/**\n * Discriminated UNION over all backing-service kinds. Used by the\n * `ServiceAddressResolver` and helpers that accept any kind and read\n * only base fields (`source`, `host`, `port`). Consumers that need\n * kind-specific fields MUST narrow first (e.g. via the per-kind type\n * exports above).\n */\nexport type BackingServiceEnvConfig =\n | MongoBackingService\n | RedisBackingService\n | PostgresBackingService\n | RabbitBackingService\n | S3BackingService\n | GotenbergBackingService\n | ClamAvBackingService\n | ImmudbBackingService\n | MetricsBackingService\n | BackupBackingService;\n\n/**\n * Per-environment backing services config (source for each service).\n * Used in environment-specific infra descriptors.\n *\n * Keys stay optional because an app-owned environment only needs to declare the\n * backing services it actually enables. Requiring the full enum-keyed record\n * would force disabled services (for example `postgresql`) into every env file\n * and breaks truthful flattened targeted-app declarations.\n */\nexport const BackingServicesEnvConfigSchema = z.object({\n [BackingServiceKind.MONGODB]: MongoBackingServiceSchema.optional(),\n [BackingServiceKind.REDIS]: RedisBackingServiceSchema.optional(),\n [BackingServiceKind.RABBITMQ]: RabbitBackingServiceSchema.optional(),\n [BackingServiceKind.S3]: S3BackingServiceSchema.optional(),\n [BackingServiceKind.POSTGRESQL]: PostgresBackingServiceSchema.optional(),\n [BackingServiceKind.GOTENBERG]: GotenbergBackingServiceSchema.optional(),\n [BackingServiceKind.CLAMAV]: ClamAvBackingServiceSchema.optional(),\n [BackingServiceKind.IMMUDB]: ImmudbBackingServiceSchema.optional(),\n [BackingServiceKind.METRICS]: MetricsBackingServiceSchema.optional(),\n [BackingServiceKind.BACKUP]: BackupBackingServiceSchema.optional(),\n}).strict();\nexport type BackingServicesEnvConfig = z.infer<typeof BackingServicesEnvConfigSchema>;\n/** @wildo_source:part:end platform.config.backing-services */\n\n// =============================================================================\n// BackingServiceKind ↔ InfraCapability / InfraProvider projections\n// =============================================================================\n//\n// Per `infra-provider-planner.md` R-B (locked 2026-05-06): `BackingServicesEnvConfig`\n// IS the canonical per-env infra-selection authoring surface. The\n// `InfraCapability` / `InfraProvider` enums are the planner's projection\n// vocabulary (used by `InfraProviderModule.supportedCapabilities`,\n// `wildo-saas.lock.json sections.infra` keying, and any tooling that\n// walks \"what infra is selected per env\"). The mappings below are the\n// single source of truth for that projection — no other code may\n// reconstruct them locally.\n\n/**\n * Bijective `BackingServiceKind` → `InfraCapability` mapping. Every\n * extension to `BackingServiceKind` MUST extend this map in the same\n * commit, otherwise the planner cannot project the new kind to its\n * capability slot.\n */\nexport const BackingServiceKindToInfraCapability: Record<BackingServiceKind, InfraCapability> = {\n [BackingServiceKind.MONGODB]: InfraCapability.DOCUMENT_DATABASE,\n [BackingServiceKind.POSTGRESQL]: InfraCapability.RELATIONAL_DATABASE,\n [BackingServiceKind.RABBITMQ]: InfraCapability.QUEUING_SYSTEM,\n [BackingServiceKind.REDIS]: InfraCapability.CACHE_MANAGER,\n [BackingServiceKind.S3]: InfraCapability.OBJECT_STORAGE,\n [BackingServiceKind.GOTENBERG]: InfraCapability.DOCUMENT_RENDERING,\n [BackingServiceKind.CLAMAV]: InfraCapability.ANTIVIRUS_SCANNING,\n [BackingServiceKind.IMMUDB]: InfraCapability.AUDIT_LOG_STORAGE,\n [BackingServiceKind.METRICS]: InfraCapability.METRICS_TELEMETRY,\n [BackingServiceKind.BACKUP]: InfraCapability.BACKUP_MANAGER,\n};\n\n/**\n * Project `(BackingServiceKind, source, provider?)` → `InfraProvider`.\n *\n * The three-axis dispatch (kind × hosting-model × brand) generalizes\n * the source/brand split across all kinds (Slice 4.B.0, 2026-05-07\n * — was source-only with Atlas as a special source value before).\n *\n * **Brand vocabulary** per kind (`provider` field on the authored\n * `BackingService<X>Schema`):\n *\n * | Kind | source | provider | InfraProvider |\n * |---|---|---|---|\n * | `MONGODB` | `SELF` | (any) | `MONGODB_SELF` |\n * | `MONGODB` | `MANAGED` | `'atlas'` | `MONGODB_ATLAS` |\n * | `POSTGRESQL` | `SELF` | (any) | `POSTGRES_SELF` |\n * | `POSTGRESQL` | `MANAGED` | `'aws-rds'` | `POSTGRES_AWS_RDS` |\n * | `POSTGRESQL` | `MANAGED` | `'gcp-cloud-sql'` | `POSTGRES_GCP_CLOUD_SQL` |\n * | `POSTGRESQL` | `MANAGED` | `'azure-database'` | `POSTGRES_AZURE_DATABASE` |\n * | `POSTGRESQL` | `MANAGED` | `'supabase'` | `POSTGRES_SUPABASE` |\n * | `POSTGRESQL` | `MANAGED` | `'neon'` | `POSTGRES_NEON` |\n * | `POSTGRESQL` | `MANAGED` | `'render'` | `POSTGRES_RENDER` |\n * | `POSTGRESQL` | `MANAGED` | (unset) | `POSTGRES_MANAGED` (generic fallback) |\n * | `REDIS` | `SELF` | (any) | `REDIS_SELF` |\n * | `RABBITMQ` | `SELF` | (any) | `RABBITMQ_SELF` |\n * | `S3` | `SELF` | (`'minio'` or unset) | `MINIO_SELF` |\n * | `S3` | `MANAGED` | `'aws'` | `AWS_S3` |\n * | `CLAMAV` | `SELF` | (any) | `CLAMAV_SELF` |\n * | `GOTENBERG` | `SELF` | (any) | `GOTENBERG_SELF` |\n *\n * Returns `undefined` for combinations not in the table — for kinds\n * whose `InfraProvider` catalog has no concrete entry yet (METRICS,\n * BACKUP) and for unrecognized brand strings on managed\n * Mongo / S3 (they don't have a generic `<KIND>_MANAGED` fallback,\n * unlike Postgres). Callers decide whether `undefined` is fail-closed\n * (planner running with unknown infra catalog) or accepted (lockfile\n * pre-declaration).\n */\nexport function resolveInfraProvider(\n kind: BackingServiceKind,\n source: BackingServiceSource,\n provider?: string,\n): InfraProvider | undefined {\n switch (kind) {\n case BackingServiceKind.MONGODB:\n if (source === BackingServiceSource.SELF) return InfraProvider.MONGODB_SELF;\n if (source === BackingServiceSource.MANAGED && provider === 'atlas') return InfraProvider.MONGODB_ATLAS;\n // Other Mongo managed brands (e.g., AWS DocumentDB) — extend\n // the `InfraProvider` enum + this branch in the same slice\n // that adds the first concrete consumer.\n return undefined;\n case BackingServiceKind.POSTGRESQL:\n if (source === BackingServiceSource.SELF) return InfraProvider.POSTGRES_SELF;\n if (source === BackingServiceSource.MANAGED) {\n switch (provider) {\n case 'aws-rds': return InfraProvider.POSTGRES_AWS_RDS;\n case 'gcp-cloud-sql': return InfraProvider.POSTGRES_GCP_CLOUD_SQL;\n case 'azure-database': return InfraProvider.POSTGRES_AZURE_DATABASE;\n case 'supabase': return InfraProvider.POSTGRES_SUPABASE;\n case 'neon': return InfraProvider.POSTGRES_NEON;\n case 'render': return InfraProvider.POSTGRES_RENDER;\n // Generic fallback when the operator has authored\n // `source: MANAGED` without naming a brand (or with an\n // unrecognized brand). Acceptable while the brand catalog\n // is incomplete — the lockfile records `POSTGRES_MANAGED`\n // and the planner can still emit env vars + compose\n // contributions; brand-specific runtime behavior is what\n // the named-brand modules (Slice 4.B+) layer on top.\n default: return InfraProvider.POSTGRES_MANAGED;\n }\n }\n return undefined;\n case BackingServiceKind.REDIS:\n if (source === BackingServiceSource.SELF) return InfraProvider.REDIS_SELF;\n // Managed Redis brands (ElastiCache, Upstash, Redis Cloud, …)\n // — not catalogued yet; future expansion.\n return undefined;\n case BackingServiceKind.RABBITMQ:\n if (source === BackingServiceSource.SELF) return InfraProvider.RABBITMQ_SELF;\n // Managed RabbitMQ brands (CloudAMQP, AWS MQ, …) —\n // not catalogued yet; future expansion.\n return undefined;\n case BackingServiceKind.S3:\n // S3 dispatch is brand-first because the protocol is\n // standardized (S3-compatible) and the same `source` can host\n // multiple software stacks — `source: SELF` could be MinIO or\n // a self-managed AWS S3 cluster (theoretically). The brand is\n // the canonical disambiguator.\n if (provider === 'minio') return InfraProvider.MINIO_SELF;\n if (provider === 'aws') return InfraProvider.AWS_S3;\n // Default source-based mapping for unbranded S3 — MinIO is\n // the canonical self-hosted; AWS is the canonical managed.\n if (source === BackingServiceSource.SELF) return InfraProvider.MINIO_SELF;\n if (source === BackingServiceSource.MANAGED) return InfraProvider.AWS_S3;\n return undefined;\n case BackingServiceKind.CLAMAV:\n if (source === BackingServiceSource.SELF) return InfraProvider.CLAMAV_SELF;\n return undefined;\n case BackingServiceKind.GOTENBERG:\n if (source === BackingServiceSource.SELF) return InfraProvider.GOTENBERG_SELF;\n return undefined;\n case BackingServiceKind.IMMUDB:\n if (source === BackingServiceSource.SELF) return InfraProvider.IMMUDB_SELF;\n // Managed immudb (immudb Vault) — not catalogued yet; future expansion.\n return undefined;\n case BackingServiceKind.METRICS:\n case BackingServiceKind.BACKUP:\n // No concrete `InfraProvider` declared yet for these kinds.\n // Extend `InfraProvider` enum + this branch in the same slice\n // that introduces the first concrete provider for each kind.\n return undefined;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"backing-services.schemas.js","sourceRoot":"","sources":["../../../../src/project-config/shared/backing-services.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,eAAe,EACf,aAAa,GACd,MAAM,2BAA2B,CAAC;AAEnC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAN,IAAY,kBAiBX;AAjBD,WAAY,kBAAkB;IAC5B,yCAAmB,CAAA;IACnB,qCAAe,CAAA;IACf,2CAAqB,CAAA;IACrB,+BAAS,CAAA;IACT,+CAAyB,CAAA;IACzB,uCAAiB,CAAA;IACjB;;;;OAIG;IACH,uCAAi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Aa,CAAC,WAAW,CAAC;YAC3E,wEAAwE;YACxE,OAAO,SAAS,CAAC;QACnB,KAAK,kBAAkB,CAAC,MAAM;YAC5B,4FAA4F;YAC5F,oFAAoF;YACpF,EAAE;YACF,2FAA2F;YAC3F,0EAA0E;YAC1E,wFAAwF;YACxF,uEAAuE;YACvE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC;AACD,uEAAuE","sourcesContent":["import { z } from 'zod';\nimport {\n InfraCapability,\n InfraProvider,\n} from './infra-providers.schemas';\n\n/**\n * The backing-service authoring surface of `wildo.infra.<env>.config.ts`.\n *\n * Import from `@wildo-ai/platform-config-lib`. Everything below is what an\n * environment file may declare under `backingServices: { ... }` — the closed kind\n * vocabulary, the hosting-model axis, and the per-kind entry shape. The\n * `InfraCapability` / `InfraProvider` projections further down this file are\n * planner-internal and deliberately outside the anchor: an app author never writes\n * them.\n *\n * Declare a kind ONLY when the environment actually runs it — keys are optional so a\n * flattened app declaration stays truthful about what it enables. Omitting a kind an\n * enabled engine capability depends on is the classic silent-degradation bug: e.g.\n * `COMPLIANCE_AUDIT_TRAIL` without `immudb` leaves the tamper-evident audit store\n * unbacked, which `wildo config sync` reports as a warning per environment.\n *\n * @wildo_source:part:start platform.config.backing-services facet:layer:platform facet:family:infra\n */\nexport enum BackingServiceKind {\n MONGODB = 'mongodb',\n REDIS = 'redis',\n RABBITMQ = 'rabbitmq',\n S3 = 's3',\n POSTGRESQL = 'postgresql',\n CLAMAV = 'clamav',\n /**\n * immudb — an immutable, cryptographically-verifiable database used as a\n * tamper-evident audit-log store (fills the `AUDIT_LOG_STORAGE` capability).\n * A stateful DB: a data volume in dev, self-hosted or immudb Vault in prod.\n */\n IMMUDB = 'immudb',\n /**\n * Backup orchestration target. Stateless base for now.\n */\n BACKUP = 'backup',\n}\n\n/**\n * Hosting model of a backing service instance — the orthogonal axis to\n * the **brand** (which is captured by the per-kind `provider` field).\n *\n * - `self`: self-hosted (Docker/K8s container managed by the platform,\n * or operator-managed on-prem). Brands here are open-source\n * software names (e.g. MinIO for S3, vanilla Postgres / MongoDB).\n * - `managed`: external vendor-managed service. Brands here are\n * vendor names (e.g. `'atlas'` for MongoDB Atlas, `'aws-rds'` for\n * AWS RDS, `'supabase'` for Supabase Postgres, `'aws'` for AWS S3).\n *\n * **Slice 4.B.0 reshape (2026-05-07)**: the `ATLAS` value was removed.\n * Pre-reshape `source: ATLAS` becomes `source: MANAGED, provider:\n * 'atlas'`. The reshape generalizes from \"Mongo + S3 are the only\n * brand-aware kinds\" to \"every kind can be brand-aware when the\n * managed market has multiple vendors\" — Postgres in particular\n * (RDS / GCP Cloud SQL / Supabase / Neon / Render / Azure).\n */\nexport enum BackingServiceSource {\n SELF = 'self',\n MANAGED = 'managed',\n}\n\n/**\n * Common fields every backing-service entry shares.\n *\n * Per-kind extensions add the fields that are SEMANTICALLY meaningful\n * for that kind only. Slice 3 closeout (M-4 + L-5): the previous shared\n * `BackingServiceEnvConfigSchema` collapsed `database` into a\n * `union(int, string)` and put `name` only on Mongo; both compromised\n * the framework-mindset rule that \"every field must carry its semantic\n * weight\". The split below means a typo like `redis: { database:\n * 'staging' }` (string on a kind that needs an integer DB index) is\n * rejected at parse time instead of crashing the runtime client at\n * connect time.\n */\nconst BackingServiceBaseSchema = z.object({\n source: z.enum(BackingServiceSource),\n /**\n * Brand of the backing service. Orthogonal to `source` (hosting\n * model). Required-in-spirit when `source === MANAGED` and the\n * managed market has multiple vendors (Mongo: `'atlas'` /\n * `'aws-documentdb'` / …; Postgres: `'aws-rds'` / `'gcp-cloud-sql'`\n * / `'supabase'` / `'neon'` / `'render'` / `'azure-database'`;\n * S3: `'aws'` / `'cloudflare-r2'` / …); optional when `source ===\n * SELF` (e.g. S3-self-hosted defaults to MinIO; `provider:\n * 'minio'` is allowed but redundant).\n *\n * Modeled as `z.string().optional()` rather than per-kind enum\n * unions to keep this base schema simple — the canonical brand\n * vocabulary lives in `resolveInfraProvider`'s dispatch table\n * (each kind documents which brand strings it recognizes; unknown\n * brands fall back to the kind's generic `<KIND>_MANAGED` /\n * `<KIND>_SELF` entry where one exists, otherwise return\n * `undefined`).\n *\n * Slice 4.B.0 (2026-05-07) generalized this from \"S3-only\" to\n * every brand-aware kind.\n */\n provider: z.string().min(1).optional(),\n /**\n * Override the catalog-derived hostname for this kind. Honored at\n * `HOST_FACING` perspective (always) and at `CONTAINER_INTERNAL` for\n * `MANAGED` sources. SELF + `CONTAINER_INTERNAL` keeps the catalog\n * container name because that is the only DNS the container network\n * can resolve.\n */\n host: z.string().min(1).optional(),\n /**\n * Override the catalog-derived listen port. Threaded into both\n * docker-compose `<authored>:<authored>` publish and the per-app\n * env-vars (`<KIND>_PORT`).\n */\n port: z.number().int().positive().optional(),\n}).strict();\n\n/**\n * MongoDB backing service. `database` is the database NAME (string).\n *\n * Mongo's connection URL has the shape `mongodb://host:port/<database>`\n * — this string corresponds to the path segment. Pre-3 the field was\n * `name`; renamed to `database` in Slice 3 closeout (L-5) so all\n * data-store kinds use the same property name for the same concept\n * (vs. Postgres which already used `database`).\n */\nexport const MongoBackingServiceSchema = BackingServiceBaseSchema.extend({\n database: z.string().min(1).optional(),\n}).strict();\nexport type MongoBackingService = z.infer<typeof MongoBackingServiceSchema>;\n\n/**\n * Redis backing service. `database` is the LOGICAL DB INDEX (integer).\n *\n * Redis exposes 16 logical databases (0–15) on a single connection.\n * Authoring a string here (e.g. `'staging'`) would silently parse on\n * the pre-3 union schema and crash ioredis at connect; the integer\n * constraint with `max(15)` fails loud at parse time.\n */\nexport const RedisBackingServiceSchema = BackingServiceBaseSchema.extend({\n database: z.number().int().min(0).max(15).optional(),\n}).strict();\nexport type RedisBackingService = z.infer<typeof RedisBackingServiceSchema>;\n\n/**\n * PostgreSQL backing service. `database` is the database NAME (string).\n *\n * Symmetric with `MongoBackingService.database` — both are the\n * database identifier in their respective connection URLs.\n */\nexport const PostgresBackingServiceSchema = BackingServiceBaseSchema.extend({\n database: z.string().min(1).optional(),\n}).strict();\nexport type PostgresBackingService = z.infer<typeof PostgresBackingServiceSchema>;\n\n/**\n * RabbitMQ backing service. `vhost` is the RabbitMQ virtual host.\n *\n * AMQP virtual hosts isolate exchange/queue namespaces inside a single\n * broker. NOT a database — RabbitMQ has no DB concept — so the field\n * is intentionally NOT named `database`.\n */\nexport const RabbitBackingServiceSchema = BackingServiceBaseSchema.extend({\n vhost: z.string().min(1).optional(),\n}).strict();\nexport type RabbitBackingService = z.infer<typeof RabbitBackingServiceSchema>;\n\n/**\n * S3-compatible backing service (MinIO, Scaleway Object Storage, AWS).\n *\n * `endpoint` is a URL (`http://localhost:9000`, `https://s3.eu-west.amazonaws.com`)\n * — the resolver parses it into host/port. `bucket` is the S3 bucket\n * name. NOT a database — S3 has no DB concept.\n */\nexport const S3BackingServiceSchema = BackingServiceBaseSchema.extend({\n endpoint: z.string().min(1).optional(),\n bucket: z.string().min(1).optional(),\n}).strict();\nexport type S3BackingService = z.infer<typeof S3BackingServiceSchema>;\n\n/** ClamAV anti-virus daemon. Stateless, no database/vhost/bucket. */\nexport const ClamAvBackingServiceSchema = BackingServiceBaseSchema;\nexport type ClamAvBackingService = z.infer<typeof ClamAvBackingServiceSchema>;\n\n/**\n * immudb backing service (tamper-evident audit-log store). A stateful DB —\n * `database` names the immudb database (defaults to `defaultdb` at runtime);\n * credentials come from the secrets pipeline like every other backing service.\n *\n * Declare this in EVERY environment where the `COMPLIANCE_AUDIT_TRAIL` engine\n * capability is enabled. `wildo config sync` warns per environment when the audit\n * capability is on but no environment declares an audit store, and the audit client\n * then has nowhere tamper-evident to write.\n *\n * You do NOT author the state-signing keypair that makes the store's\n * whole-server-substitution defense work. The framework provisions it (private half\n * mounted into a `source: SELF` immudb via `--signingKey`, public half pinned by the\n * audit client as `IMMUDB_STATE_PUBLIC_KEY`) — declaring the service is the whole job.\n *\n * @example\n * ```ts\n * backingServices: {\n * immudb: { source: BackingServiceSource.SELF },\n * }\n * ```\n */\nexport const ImmudbBackingServiceSchema = BackingServiceBaseSchema.extend({\n database: z.string().min(1).optional(),\n}).strict();\nexport type ImmudbBackingService = z.infer<typeof ImmudbBackingServiceSchema>;\n\n/**\n * Backup orchestration target. Stateless base for now.\n */\nexport const BackupBackingServiceSchema = BackingServiceBaseSchema;\nexport type BackupBackingService = z.infer<typeof BackupBackingServiceSchema>;\n\n/**\n * Discriminated UNION over all backing-service kinds. Used by the\n * `ServiceAddressResolver` and helpers that accept any kind and read\n * only base fields (`source`, `host`, `port`). Consumers that need\n * kind-specific fields MUST narrow first (e.g. via the per-kind type\n * exports above).\n */\nexport type BackingServiceEnvConfig =\n | MongoBackingService\n | RedisBackingService\n | PostgresBackingService\n | RabbitBackingService\n | S3BackingService\n | ClamAvBackingService\n | ImmudbBackingService\n | BackupBackingService;\n\n/**\n * Per-environment backing services config (source for each service).\n * Used in environment-specific infra descriptors.\n *\n * Keys stay optional because an app-owned environment only needs to declare the\n * backing services it actually enables. Requiring the full enum-keyed record\n * would force disabled services (for example `postgresql`) into every env file\n * and breaks truthful flattened targeted-app declarations.\n */\nexport const BackingServicesEnvConfigSchema = z.object({\n [BackingServiceKind.MONGODB]: MongoBackingServiceSchema.optional(),\n [BackingServiceKind.REDIS]: RedisBackingServiceSchema.optional(),\n [BackingServiceKind.RABBITMQ]: RabbitBackingServiceSchema.optional(),\n [BackingServiceKind.S3]: S3BackingServiceSchema.optional(),\n [BackingServiceKind.POSTGRESQL]: PostgresBackingServiceSchema.optional(),\n [BackingServiceKind.CLAMAV]: ClamAvBackingServiceSchema.optional(),\n [BackingServiceKind.IMMUDB]: ImmudbBackingServiceSchema.optional(),\n [BackingServiceKind.BACKUP]: BackupBackingServiceSchema.optional(),\n}).strict();\nexport type BackingServicesEnvConfig = z.infer<typeof BackingServicesEnvConfigSchema>;\n/** @wildo_source:part:end platform.config.backing-services */\n\n// =============================================================================\n// BackingServiceKind ↔ InfraCapability / InfraProvider projections\n// =============================================================================\n//\n// Per `infra-provider-planner.md` R-B (locked 2026-05-06): `BackingServicesEnvConfig`\n// IS the canonical per-env infra-selection authoring surface. The\n// `InfraCapability` / `InfraProvider` enums are the planner's projection\n// vocabulary (used by `InfraProviderModule.supportedCapabilities`,\n// `wildo-saas.lock.json sections.infra` keying, and any tooling that\n// walks \"what infra is selected per env\"). The mappings below are the\n// single source of truth for that projection — no other code may\n// reconstruct them locally.\n\n/** @wildo_source:part:start platform.config.infra-provider-resolution facet:layer:platform facet:audience:app-developer */\n/**\n * `BackingServiceKind` → `InfraCapability`. Every extension to `BackingServiceKind` MUST extend this\n * map in the same commit, otherwise the planner cannot project the new kind to its capability slot.\n *\n * INJECTIVE, not bijective — and the difference is a real property of the model rather than a gap.\n * A capability may be granted to a runtime without any environment declaring a backing service for\n * it; see {@link RUNTIME_GRANTED_INFRA_CAPABILITIES} for the ones that are, and why.\n */\nexport const BackingServiceKindToInfraCapability: Record<BackingServiceKind, InfraCapability> = {\n [BackingServiceKind.MONGODB]: InfraCapability.DOCUMENT_DATABASE,\n [BackingServiceKind.POSTGRESQL]: InfraCapability.RELATIONAL_DATABASE,\n [BackingServiceKind.RABBITMQ]: InfraCapability.QUEUING_SYSTEM,\n [BackingServiceKind.REDIS]: InfraCapability.CACHE_MANAGER,\n [BackingServiceKind.S3]: InfraCapability.OBJECT_STORAGE,\n [BackingServiceKind.CLAMAV]: InfraCapability.ANTIVIRUS_SCANNING,\n [BackingServiceKind.IMMUDB]: InfraCapability.AUDIT_LOG_STORAGE,\n [BackingServiceKind.BACKUP]: InfraCapability.BACKUP_MANAGER,\n};\n\n/**\n * Project `(BackingServiceKind, source, provider?)` → `InfraProvider`.\n *\n * The three-axis dispatch (kind × hosting-model × brand) generalizes\n * the source/brand split across all kinds (Slice 4.B.0, 2026-05-07\n * — was source-only with Atlas as a special source value before).\n *\n * **Brand vocabulary** per kind (`provider` field on the authored\n * `BackingService<X>Schema`):\n *\n * | Kind | source | provider | InfraProvider |\n * |---|---|---|---|\n * | `MONGODB` | `SELF` | (any) | `MONGODB_SELF` |\n * | `MONGODB` | `MANAGED` | `'atlas'` | `MONGODB_ATLAS` |\n * | `POSTGRESQL` | `SELF` | (any) | `POSTGRES_SELF` |\n * | `POSTGRESQL` | `MANAGED` | `'aws-rds'` | `POSTGRES_AWS_RDS` |\n * | `POSTGRESQL` | `MANAGED` | `'gcp-cloud-sql'` | `POSTGRES_GCP_CLOUD_SQL` |\n * | `POSTGRESQL` | `MANAGED` | `'azure-database'` | `POSTGRES_AZURE_DATABASE` |\n * | `POSTGRESQL` | `MANAGED` | `'supabase'` | `POSTGRES_SUPABASE` |\n * | `POSTGRESQL` | `MANAGED` | `'neon'` | `POSTGRES_NEON` |\n * | `POSTGRESQL` | `MANAGED` | `'render'` | `POSTGRES_RENDER` |\n * | `POSTGRESQL` | `MANAGED` | (unset) | `POSTGRES_MANAGED` (generic fallback) |\n * | `REDIS` | `SELF` | (any) | `REDIS_SELF` |\n * | `RABBITMQ` | `SELF` | (any) | `RABBITMQ_SELF` |\n * | `S3` | `SELF` | (`'minio'` or unset) | `MINIO_SELF` |\n * | `S3` | `MANAGED` | `'aws'` | `AWS_S3` |\n * | `CLAMAV` | `SELF` | (any) | `CLAMAV_SELF` |\n * | `IMMUDB` | `SELF` | (any) | `IMMUDB_SELF` |\n *\n * Returns `undefined` for combinations not in the table — for kinds\n * whose `InfraProvider` catalog has no concrete entry yet (METRICS,\n * BACKUP) and for unrecognized brand strings on managed\n * Mongo / S3 (they don't have a generic `<KIND>_MANAGED` fallback,\n * unlike Postgres). Callers decide whether `undefined` is fail-closed\n * (planner running with unknown infra catalog) or accepted (lockfile\n * pre-declaration).\n *\n * ## What this means when you author an environment\n *\n * **`MANAGED` does not reach every kind.** The table above is the whole of it: a managed vendor\n * resolves for the relational database (six named brands plus a generic fallback), the document\n * database (`'atlas'` only) and object storage. Declaring `{ source: MANAGED }` on the cache, the\n * broker, the antivirus scanner, the audit store or the backup target resolves to NOTHING — those\n * kinds are self-hosted only until their vendor catalogue is built.\n *\n * **And nothing tells you.** A kind that resolves to no provider is SKIPPED when the lockfile's infra\n * section is materialised, silently, because recording an entry with no provider would lie. So a\n * managed declaration the catalogue cannot serve looks exactly like a correct one: `wildo config\n * sync` succeeds, the file says `MANAGED`, and the environment has no managed anything. Read the\n * lockfile's infra section to see which of your declarations were actually resolved.\n *\n * **An unrecognised brand is not the same failure on every kind.** On the relational database it\n * falls back to the generic managed entry, so a typo still resolves. On the document database and on\n * object storage there is no generic fallback, so a typo resolves to nothing and is skipped.\n *\n * **Declaring a service managed does not always stop the local one being rendered.** The inclusion\n * gates in the Compose and Kubernetes lanes are separate from this resolution and cover different\n * kinds, so a managed declaration can leave a local container in the rendered stack beside it.\n */\nexport function resolveInfraProvider(\n kind: BackingServiceKind,\n source: BackingServiceSource,\n provider?: string,\n): InfraProvider | undefined {\n switch (kind) {\n case BackingServiceKind.MONGODB:\n if (source === BackingServiceSource.SELF) return InfraProvider.MONGODB_SELF;\n if (source === BackingServiceSource.MANAGED && provider === 'atlas') return InfraProvider.MONGODB_ATLAS;\n // Other Mongo managed brands (e.g., AWS DocumentDB) — extend\n // the `InfraProvider` enum + this branch in the same slice\n // that adds the first concrete consumer.\n return undefined;\n case BackingServiceKind.POSTGRESQL:\n if (source === BackingServiceSource.SELF) return InfraProvider.POSTGRES_SELF;\n if (source === BackingServiceSource.MANAGED) {\n switch (provider) {\n case 'aws-rds': return InfraProvider.POSTGRES_AWS_RDS;\n case 'gcp-cloud-sql': return InfraProvider.POSTGRES_GCP_CLOUD_SQL;\n case 'azure-database': return InfraProvider.POSTGRES_AZURE_DATABASE;\n case 'supabase': return InfraProvider.POSTGRES_SUPABASE;\n case 'neon': return InfraProvider.POSTGRES_NEON;\n case 'render': return InfraProvider.POSTGRES_RENDER;\n // Generic fallback when the operator has authored\n // `source: MANAGED` without naming a brand (or with an\n // unrecognized brand). Acceptable while the brand catalog\n // is incomplete — the lockfile records `POSTGRES_MANAGED`\n // and the planner can still emit env vars + compose\n // contributions; brand-specific runtime behavior is what\n // the named-brand modules (Slice 4.B+) layer on top.\n default: return InfraProvider.POSTGRES_MANAGED;\n }\n }\n return undefined;\n case BackingServiceKind.REDIS:\n if (source === BackingServiceSource.SELF) return InfraProvider.REDIS_SELF;\n // Managed Redis brands (ElastiCache, Upstash, Redis Cloud, …)\n // — not catalogued yet; future expansion.\n return undefined;\n case BackingServiceKind.RABBITMQ:\n if (source === BackingServiceSource.SELF) return InfraProvider.RABBITMQ_SELF;\n // Managed RabbitMQ brands (CloudAMQP, AWS MQ, …) —\n // not catalogued yet; future expansion.\n return undefined;\n case BackingServiceKind.S3:\n // S3 dispatch is brand-first because the protocol is\n // standardized (S3-compatible) and the same `source` can host\n // multiple software stacks — `source: SELF` could be MinIO or\n // a self-managed AWS S3 cluster (theoretically). The brand is\n // the canonical disambiguator.\n if (provider === 'minio') return InfraProvider.MINIO_SELF;\n if (provider === 'aws') return InfraProvider.AWS_S3;\n // Default source-based mapping for unbranded S3 — MinIO is\n // the canonical self-hosted; AWS is the canonical managed.\n if (source === BackingServiceSource.SELF) return InfraProvider.MINIO_SELF;\n if (source === BackingServiceSource.MANAGED) return InfraProvider.AWS_S3;\n return undefined;\n case BackingServiceKind.CLAMAV:\n if (source === BackingServiceSource.SELF) return InfraProvider.CLAMAV_SELF;\n return undefined;\n case BackingServiceKind.IMMUDB:\n if (source === BackingServiceSource.SELF) return InfraProvider.IMMUDB_SELF;\n // Managed immudb (immudb Vault) — not catalogued yet; future expansion.\n return undefined;\n case BackingServiceKind.BACKUP:\n // No concrete `InfraProvider` declared yet for this kind. Extend the `InfraProvider` enum +\n // this branch in the same slice that introduces the first concrete provider for it.\n //\n // `METRICS` was the other kind here and was WITHDRAWN 2026-09-09: telemetry is authored at\n // `observability.telemetry` and its auth header derived from the selected\n // `OBSERVABILITY_TELEMETRY` provider, so a backing-service kind was a third declaration\n // surface that nothing read. See `RUNTIME_GRANTED_INFRA_CAPABILITIES`.\n return undefined;\n }\n}\n/** @wildo_source:part:end platform.config.infra-provider-resolution */\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cdn.example.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"cdn.example.d.ts","sourceRoot":"","sources":["../../../../src/project-config/shared/cdn.example.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpE;;;;;GAKG;AAEH,kHAAkH;AAIlH,eAAO,MAAM,0BAA0B,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAY1E,CAAC;AACF,0DAA0D;AAE1D,+GAA+G;AAK/G,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAKvE,CAAC;AACF,uDAAuD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cdn.schemas.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"cdn.schemas.d.ts","sourceRoot":"","sources":["../../../../src/project-config/shared/cdn.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;GAWG;AAEH;;;;;;;;;;;;;;GAcG;AACH,oBAAY,SAAS;IACnB;;;;;;OAMG;IACH,OAAO,YAAY;IACnB;;;;;;;;OAQG;IACH,UAAU,eAAe;CAC1B;AAED;;;GAGG;AACH,eAAO,MAAM,4BAA4B;;kBAEvC,CAAC;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAElF;;;;;;;GAOG;AACH,eAAO,MAAM,+BAA+B;;IAE1C;;;OAGG;;IAEH;;;;OAIG;;kBAEH,CAAC;AACH,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAC;AAExF;;;;GAIG;AACH,eAAO,MAAM,qBAAqB;;;;IAnBhC;;;OAGG;;IAEH;;;;OAIG;;4BAaH,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,oBAAoB;IAC/B;;;;;;;OAOG;;IAEH;;;;;;OAMG;;IAEH;;;;OAIG;;IAEH;;;OAGG;;;;;QApFH;;;WAGG;;QAEH;;;;WAIG;;;kBA6EH,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACvE,iDAAiD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csp-defaults.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"csp-defaults.d.ts","sourceRoot":"","sources":["../../../../src/project-config/shared/csp-defaults.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAC5C,OAAO,CAAC,MAAM,CAAC,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CACrD,CAAC;AAgHF;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,EAAE,QAAQ,CAClC,MAAM,CAAC,eAAe,EAAE,uBAAuB,CAAC,CAKjD,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AppFrontendType } from '@wildo-ai/saas-models/public-runtime';
|
|
1
|
+
import { AppFrontendType, type ProviderFrontendCspFootprint } from '@wildo-ai/saas-models/public-runtime';
|
|
2
2
|
import { type CspDirectiveName, type EnvCspOverride, type WildoCspConfig } from './csp.schemas';
|
|
3
3
|
export type ResolvedCspDirectiveMap = Readonly<Partial<Record<CspDirectiveName, readonly string[]>>>;
|
|
4
4
|
export interface ResolvedCspPolicy {
|
|
@@ -22,6 +22,28 @@ export interface ResolveCspPolicyInput {
|
|
|
22
22
|
readonly frontendType: AppFrontendType;
|
|
23
23
|
readonly appCsp: WildoCspConfig | undefined;
|
|
24
24
|
readonly envOverride?: EnvCspOverride;
|
|
25
|
+
/**
|
|
26
|
+
* The CSP footprints of the providers DECLARED for this service — the fourth
|
|
27
|
+
* layer, added by #332.
|
|
28
|
+
*
|
|
29
|
+
* Without it, a marketing site that wants an embedded meeting or a SaaS app
|
|
30
|
+
* that wants a Drive picker means hand-editing script / frame / connect
|
|
31
|
+
* origins per application, per service, per environment; and getting it wrong
|
|
32
|
+
* is invisible until production, because development is report-only. The
|
|
33
|
+
* caller reads these from the service's materialized provider block, which is
|
|
34
|
+
* DATA precisely so that no frontend module has to be executed to obtain them.
|
|
35
|
+
*
|
|
36
|
+
* Providers declared for ANOTHER service must not appear here: the point of
|
|
37
|
+
* the layer is that a Zoom origin admitted for the marketing site is not
|
|
38
|
+
* thereby admitted for the SaaS app.
|
|
39
|
+
*
|
|
40
|
+
* A footprint's `derivedOrigins` must ALREADY BE RESOLVED into its buckets by
|
|
41
|
+
* the caller. This resolver sees no `publicConfig` — it composes a policy, it
|
|
42
|
+
* does not read a provider's configuration — and the one caller that has both
|
|
43
|
+
* halves is `CspSyncService`, which reads each entry out of the materialized
|
|
44
|
+
* block.
|
|
45
|
+
*/
|
|
46
|
+
readonly providerCspFootprints?: ReadonlyArray<ProviderFrontendCspFootprint>;
|
|
25
47
|
/**
|
|
26
48
|
* Environment id this CSP is being resolved for (e.g. `'local'`,
|
|
27
49
|
* `'staging'`, `'production'`, or any custom slug). Optional for
|
|
@@ -37,10 +59,19 @@ export interface ResolveCspPolicyInput {
|
|
|
37
59
|
export declare const NGINX_CSP_BEGIN_MARKER = "# >>> wildo csp begin";
|
|
38
60
|
export declare const NGINX_CSP_END_MARKER = "# <<< wildo csp end";
|
|
39
61
|
/**
|
|
40
|
-
* Resolves the generic
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
62
|
+
* Resolves the generic layered CSP model shared by all frontend surfaces:
|
|
63
|
+
* platform baseline, app-static config, env-selected overrides, then the
|
|
64
|
+
* declared providers' own footprints (#332).
|
|
65
|
+
*
|
|
66
|
+
* The provider layer is fourth on purpose. The first three describe what the
|
|
67
|
+
* APPLICATION decided; the fourth describes what the things the application
|
|
68
|
+
* declared actually need in order to work. Placing it last means a provider
|
|
69
|
+
* cannot be silently dropped by an app-level `REPLACE_BASELINE`, and placing it
|
|
70
|
+
* before the WebSocket derivation means a provider's `connect-src` origin gets
|
|
71
|
+
* its `wss://` companion exactly like the backend API's.
|
|
72
|
+
*
|
|
73
|
+
* This lives with the CSP schemas/defaults so consumers do not depend on any
|
|
74
|
+
* concrete frontend package to process security config.
|
|
44
75
|
*/
|
|
45
76
|
export declare function resolveCspPolicy(input: ResolveCspPolicyInput): ResolvedCspPolicy | null;
|
|
46
77
|
export declare function emitCspArtifacts(policy: ResolvedCspPolicy): CspEmitArtifacts;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csp-emit.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"csp-emit.d.ts","sourceRoot":"","sources":["../../../../src/project-config/shared/csp-emit.ts"],"names":[],"mappings":"AACA,OAAO,EACL,eAAe,EAEf,KAAK,4BAA4B,EAClC,MAAM,sCAAsC,CAAC;AAM9C,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,cAAc,EACpB,MAAM,eAAe,CAAC;AAGvB,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAC5C,OAAO,CAAC,MAAM,CAAC,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC,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;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAGzE;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,yBAAyB;IACxC,6DAA6D;IAC7D,QAAQ,CAAC,KAAK,EAAE,iCAAiC,CAAC;IAClD,wEAAwE;IACxE,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC;IAC1B,2EAA2E;IAC3E,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,iEAAiE;IACjE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,iBAAiB,GAAG,yBAAyB,CAQlG;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;CAC/B;AAED,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,GACpB,kBAAkB,CAkBpB;AAED,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,QAAQ,SAAgB,GACvB;IACD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B,CA4DA"}
|
|
@@ -1,8 +1,36 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { AppFrontendType } from '@wildo-ai/saas-models/public-runtime';
|
|
2
|
+
import { AppFrontendType, ProviderFrontendCspOriginBucket, } from '@wildo-ai/saas-models/public-runtime';
|
|
3
3
|
import { CSP_BASELINES, } from './csp-defaults.js';
|
|
4
4
|
import { CspMergeStrategy, } from './csp.schemas.js';
|
|
5
5
|
import { WildoEnvironment } from './environment.schemas.js';
|
|
6
|
+
/**
|
|
7
|
+
* Where each of a provider's declared origin buckets lands in the policy.
|
|
8
|
+
*
|
|
9
|
+
* THE ONE PLACE the mapping exists. A provider declares what it is REACHING
|
|
10
|
+
* — a script it loads, an API it calls, an iframe it embeds — and which
|
|
11
|
+
* directive grades that fetch is framework knowledge, so a provider author
|
|
12
|
+
* never has to learn the CSP directive taxonomy and a change to it is a change
|
|
13
|
+
* here rather than in every provider package.
|
|
14
|
+
*
|
|
15
|
+
* The bucket names are also why `ProviderFrontendCspFootprint` does not restate
|
|
16
|
+
* `CSP_DIRECTIVE_NAMES`: that vocabulary already has one named source, in this
|
|
17
|
+
* package, and `@wildo-ai/saas-models` — where the footprint has to live,
|
|
18
|
+
* because it rides on the wire — depends on nothing of ours.
|
|
19
|
+
*
|
|
20
|
+
* Total over the footprint's buckets: adding a bucket without deciding its
|
|
21
|
+
* directive is a compile error here, which is the coupling this shape exists
|
|
22
|
+
* for. A bucket with no mapping would be authored, serialized, read, and
|
|
23
|
+
* silently contribute nothing — in production only, since CSP is report-only
|
|
24
|
+
* in development.
|
|
25
|
+
*/
|
|
26
|
+
const PROVIDER_CSP_BUCKET_DIRECTIVES = {
|
|
27
|
+
[ProviderFrontendCspOriginBucket.SCRIPT]: 'script-src',
|
|
28
|
+
[ProviderFrontendCspOriginBucket.CONNECT]: 'connect-src',
|
|
29
|
+
[ProviderFrontendCspOriginBucket.FRAME]: 'frame-src',
|
|
30
|
+
[ProviderFrontendCspOriginBucket.IMG]: 'img-src',
|
|
31
|
+
[ProviderFrontendCspOriginBucket.STYLE]: 'style-src',
|
|
32
|
+
[ProviderFrontendCspOriginBucket.FONT]: 'font-src',
|
|
33
|
+
};
|
|
6
34
|
export const NGINX_CSP_BEGIN_MARKER = '# >>> wildo csp begin';
|
|
7
35
|
export const NGINX_CSP_END_MARKER = '# <<< wildo csp end';
|
|
8
36
|
const META_INVALID_DIRECTIVES = new Set([
|
|
@@ -80,10 +108,19 @@ function mergeSourceLists(a, b) {
|
|
|
80
108
|
return out;
|
|
81
109
|
}
|
|
82
110
|
/**
|
|
83
|
-
* Resolves the generic
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
111
|
+
* Resolves the generic layered CSP model shared by all frontend surfaces:
|
|
112
|
+
* platform baseline, app-static config, env-selected overrides, then the
|
|
113
|
+
* declared providers' own footprints (#332).
|
|
114
|
+
*
|
|
115
|
+
* The provider layer is fourth on purpose. The first three describe what the
|
|
116
|
+
* APPLICATION decided; the fourth describes what the things the application
|
|
117
|
+
* declared actually need in order to work. Placing it last means a provider
|
|
118
|
+
* cannot be silently dropped by an app-level `REPLACE_BASELINE`, and placing it
|
|
119
|
+
* before the WebSocket derivation means a provider's `connect-src` origin gets
|
|
120
|
+
* its `wss://` companion exactly like the backend API's.
|
|
121
|
+
*
|
|
122
|
+
* This lives with the CSP schemas/defaults so consumers do not depend on any
|
|
123
|
+
* concrete frontend package to process security config.
|
|
87
124
|
*/
|
|
88
125
|
export function resolveCspPolicy(input) {
|
|
89
126
|
const { frontendType, appCsp, envOverride } = input;
|
|
@@ -115,6 +152,29 @@ export function resolveCspPolicy(input) {
|
|
|
115
152
|
}
|
|
116
153
|
merged = out;
|
|
117
154
|
}
|
|
155
|
+
// Provider layer (#332) — the origins the providers DECLARED FOR THIS SERVICE
|
|
156
|
+
// need, merged after the app-static and env layers and before the WebSocket
|
|
157
|
+
// derivation below (so a provider's `connect-src` origin gets its `wss://`
|
|
158
|
+
// companion for free, exactly like the backend API's).
|
|
159
|
+
//
|
|
160
|
+
// Additive in every merge strategy, including REPLACE_BASELINE. That strategy
|
|
161
|
+
// exists so an app can discard the platform BASELINE when it is wrong for the
|
|
162
|
+
// surface; a provider the same app declared is a dependency it chose, not a
|
|
163
|
+
// default it is overriding, and silently dropping its origins would produce a
|
|
164
|
+
// policy that blocks a feature the app asked for — in production only.
|
|
165
|
+
const providerFootprints = input.providerCspFootprints ?? [];
|
|
166
|
+
if (providerFootprints.length > 0) {
|
|
167
|
+
const out = { ...merged };
|
|
168
|
+
for (const footprint of providerFootprints) {
|
|
169
|
+
for (const [bucket, directive] of Object.entries(PROVIDER_CSP_BUCKET_DIRECTIVES)) {
|
|
170
|
+
const origins = footprint[bucket];
|
|
171
|
+
if (origins.length === 0)
|
|
172
|
+
continue;
|
|
173
|
+
out[directive] = mergeSourceLists(out[directive], origins);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
merged = out;
|
|
177
|
+
}
|
|
118
178
|
// Vite dev-mode loosening (auto-applied for local SAAS_APP).
|
|
119
179
|
//
|
|
120
180
|
// Vite's dev server REQUIRES both `'unsafe-eval'` (lazy module +
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csp-emit.js","sourceRoot":"","sources":["../../../../../src/project-config/shared/csp-emit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAEvE,OAAO,EACL,aAAa,GAEd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,gBAAgB,GAIjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AA4CzD,MAAM,CAAC,MAAM,sBAAsB,GAAG,uBAAuB,CAAC;AAC9D,MAAM,CAAC,MAAM,oBAAoB,GAAG,qBAAqB,CAAC;AAE1D,MAAM,uBAAuB,GAAwB,IAAI,GAAG,CAAC;IAC3D,iBAAiB;IACjB,YAAY;IACZ,WAAW;IACX,SAAS;CACV,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,SAAS,qCAAqC,CAC5C,OAAsC;IAEtC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrC,OAAO,OAAO,CAAC;I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;QAClB,CAAC;IACH,CAAC;IAED,IAAI,cAAc,KAAK,IAAI,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CACb,cAAc,QAAQ,qBAAqB,sBAAsB,sBAAsB,cAAc,GAAG,CAAC,EAAE,CAC5G,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC;AACtE,CAAC","sourcesContent":["import { readFileSync, writeFileSync } from 'node:fs';\nimport { AppFrontendType } from '@wildo-ai/saas-models/public-runtime';\n\nimport {\n CSP_BASELINES,\n type CspBaselineDirectiveMap,\n} from './csp-defaults';\nimport {\n CspMergeStrategy,\n type CspDirectiveName,\n type EnvCspOverride,\n type WildoCspConfig,\n} from './csp.schemas';\nimport { WildoEnvironment } from './environment.schemas';\n\nexport type ResolvedCspDirectiveMap = Readonly<\n Partial<Record<CspDirectiveName, readonly string[]>>\n>;\n\nexport interface ResolvedCspPolicy {\n readonly directives: ResolvedCspDirectiveMap;\n readonly reportOnly: boolean;\n readonly reportUri: string | undefined;\n}\n\nexport interface CspEmitArtifacts {\n readonly nginxHeaderName: string;\n readonly nginxPolicyValue: string;\n readonly nginxAddHeaderLine: string;\n readonly metaTag:\n | {\n readonly tagName: 'meta';\n readonly attributes: {\n readonly 'http-equiv': string;\n readonly content: string;\n };\n }\n | null;\n}\n\nexport interface ResolveCspPolicyInput {\n readonly frontendType: AppFrontendType;\n readonly appCsp: WildoCspConfig | undefined;\n readonly envOverride?: EnvCspOverride;\n /**\n * Environment id this CSP is being resolved for (e.g. `'local'`,\n * `'staging'`, `'production'`, or any custom slug). Optional for\n * back-compat — when `undefined`, no env-aware auto-loosening applies\n * (the resolver behaves exactly as it did pre-`viteDevLoosening`).\n *\n * Required when the caller wants the framework to auto-apply\n * `viteDevLoosening` for `'local'` + `SAAS_APP`. The CLI's\n * `CspSyncService` already knows the env id and SHOULD pass it.\n */\n readonly environmentId?: string;\n}\n\nexport const NGINX_CSP_BEGIN_MARKER = '# >>> wildo csp begin';\nexport const NGINX_CSP_END_MARKER = '# <<< wildo csp end';\n\nconst META_INVALID_DIRECTIVES: ReadonlySet<string> = new Set([\n 'frame-ancestors',\n 'report-uri',\n 'report-to',\n 'sandbox',\n]);\n\n/**\n * Derives the WebSocket-scheme companion origins for every HTTP(S) origin\n * present in a `connect-src` source list, and returns the list widened to\n * include them.\n *\n * Why the framework ships this rather than making each app author it:\n * every Wildo backend serves its realtime channel (Socket.IO) on the SAME\n * origin as its HTTP API. Socket.IO opens the handshake over polling and\n * then UPGRADES to a raw `ws://` / `wss://` connection to that origin. The\n * CSP `connect-src` directive grades WebSocket connections by their `ws`/\n * `wss` scheme, and — per the CSP spec — an `http://host` source does NOT\n * authorize a `ws://host` connection (the schemes are distinct match\n * tokens). So an app that allow-lists `http://localhost:4241` for `fetch`/\n * `XHR` but not `ws://localhost:4241` will emit a `connect-src` violation\n * the instant the socket upgrades — exactly the trap every infra config\n * would otherwise have to remember to work around by hand.\n *\n * Transform (idempotent, dedupe-safe):\n * `http://host[:port]` → also allow `ws://host[:port]`\n * `https://host[:port]` → also allow `wss://host[:port]`\n * bare scheme `http:` → also allow `ws:`\n * bare scheme `https:` → also allow `wss:`\n *\n * Keyword / non-HTTP sources (`'self'`, `'none'`, `data:`, `blob:`, an\n * already-`ws://` origin, …) are passed through untouched. `'self'` is\n * deliberately NOT expanded: the browser tab is served from the frontend\n * origin, never the backend API origin, so a same-origin `ws` derivation\n * from `'self'` would authorize the wrong host. The backend origin is\n * always listed explicitly, which is what this widens.\n */\nfunction augmentConnectSrcWithWebSocketOrigins(\n sources: readonly string[] | undefined,\n): readonly string[] | undefined {\n if (!sources || sources.length === 0) {\n return sources;\n }\n\n const derived: string[] = [];\n for (const source of sources) {\n if (source.startsWith('https://')) {\n derived.push(`wss://${source.slice('https://'.length)}`);\n } else if (source.startsWith('http://')) {\n derived.push(`ws://${source.slice('http://'.length)}`);\n } else if (source === 'https:') {\n derived.push('wss:');\n } else if (source === 'http:') {\n derived.push('ws:');\n }\n }\n\n return mergeSourceLists(sources, derived);\n}\n\nfunction mergeSourceLists(\n a: readonly string[] | undefined,\n b: readonly string[] | undefined,\n): readonly string[] {\n if (!a || a.length === 0) {\n return b ?? [];\n }\n if (!b || b.length === 0) {\n return a;\n }\n\n const seen = new Set(a);\n const out: string[] = [...a];\n for (const source of b) {\n if (!seen.has(source)) {\n seen.add(source);\n out.push(source);\n }\n }\n return out;\n}\n\n/**\n * Resolves the generic three-layer CSP model shared by all frontend\n * surfaces: platform baseline, app-static config, then env-selected\n * overrides. This lives with the CSP schemas/defaults so consumers do\n * not depend on any concrete frontend package to process security config.\n */\nexport function resolveCspPolicy(\n input: ResolveCspPolicyInput,\n): ResolvedCspPolicy | null {\n const { frontendType, appCsp, envOverride } = input;\n\n if (!appCsp || !appCsp.enabled) {\n return null;\n }\n\n const baseline: CspBaselineDirectiveMap = CSP_BASELINES[frontendType];\n let merged: ResolvedCspDirectiveMap;\n\n if (appCsp.mergeStrategy === CspMergeStrategy.REPLACE_BASELINE) {\n merged = appCsp.directives;\n } else {\n const out: Partial<Record<CspDirectiveName, readonly string[]>> = {};\n const allKeys = new Set<CspDirectiveName>([\n ...(Object.keys(baseline) as CspDirectiveName[]),\n ...(Object.keys(appCsp.directives) as CspDirectiveName[]),\n ]);\n\n for (const key of allKeys) {\n out[key] = mergeSourceLists(baseline[key], appCsp.directives[key]);\n }\n\n merged = out;\n }\n\n if (envOverride?.extraDirectives) {\n const out: Partial<Record<CspDirectiveName, readonly string[]>> = {\n ...merged,\n };\n\n for (const key of Object.keys(envOverride.extraDirectives) as CspDirectiveName[]) {\n out[key] = mergeSourceLists(merged[key], envOverride.extraDirectives[key]);\n }\n\n merged = out;\n }\n\n // Vite dev-mode loosening (auto-applied for local SAAS_APP).\n //\n // Vite's dev server REQUIRES both `'unsafe-eval'` (lazy module +\n // sourcemap transforms) and `'unsafe-inline'` (HMR client bootstrap\n // injects a literal inline `<script>`) to function. Under the tight\n // SAAS_APP baseline (`script-src 'self'`), those produce ~120+ CSP\n // violations per page load that drown out real signal (e.g. the\n // Google-Fonts gotcha that the loosened style-src/font-src now allow).\n //\n // The framework SHIPS this knowledge — every Wildo SaaS app uses\n // Vite — so we auto-loosen for `'local'` + `SAAS_APP` here rather\n // than forcing every infra config to re-author the same opt-in. An\n // explicit `viteDevLoosening: false` override keeps tight `script-src`\n // when an author is actively debugging a real CSP issue and willing\n // to accept the Vite noise. Production builds emit `<script\n // type=\"module\">` only and never `eval()`, so production envs never\n // trigger the auto-loosening — `viteDevLoosening` defaults to FALSE\n // there even if the env id is non-`local`.\n const isViteDevAutoTarget =\n input.environmentId === WildoEnvironment.LOCAL &&\n frontendType === AppFrontendType.SAAS_APP;\n const viteDevLoosening = envOverride?.viteDevLoosening ?? isViteDevAutoTarget;\n if (viteDevLoosening) {\n merged = {\n ...merged,\n 'script-src': mergeSourceLists(\n merged['script-src'],\n [\"'unsafe-inline'\", \"'unsafe-eval'\"],\n ),\n };\n }\n\n // Auto-derive the `ws://` / `wss://` companion origins for every HTTP(S)\n // origin the app allow-listed in `connect-src`. Applied LAST so it covers\n // origins contributed by the baseline, app-static config, AND env override\n // alike (e.g. the local `http://localhost:4241` and the staging/prod\n // `https://api.<app>.wildo.app` backend origins). Without this, the\n // Socket.IO transport upgrade to a raw WebSocket against the backend origin\n // trips a `connect-src` violation on every surface. See the helper JSDoc for\n // the scheme-matching rationale.\n const connectSrcWithWs = augmentConnectSrcWithWebSocketOrigins(merged['connect-src']);\n if (connectSrcWithWs !== merged['connect-src']) {\n merged = {\n ...merged,\n 'connect-src': connectSrcWithWs,\n };\n }\n\n return {\n directives: merged,\n reportOnly: envOverride?.reportOnly ?? appCsp.reportOnly,\n reportUri: envOverride?.reportUri ?? appCsp.reportUri,\n };\n}\n\nfunction serializeDirectives(directives: ResolvedCspDirectiveMap): string {\n return Object.entries(directives)\n .filter(([, sources]) => sources && sources.length > 0)\n .map(([name, sources]) => `${name} ${(sources ?? []).join(' ')}`)\n .join('; ');\n}\n\nfunction stripMetaInvalidDirectives(\n directives: ResolvedCspDirectiveMap,\n): ResolvedCspDirectiveMap {\n const out: Partial<Record<CspDirectiveName, readonly string[]>> = {};\n\n for (const [name, sources] of Object.entries(directives)) {\n if (!META_INVALID_DIRECTIVES.has(name)) {\n out[name as CspDirectiveName] = sources;\n }\n }\n\n return out;\n}\n\nfunction withReportUri(\n directives: ResolvedCspDirectiveMap,\n reportUri: string | undefined,\n): ResolvedCspDirectiveMap {\n if (!reportUri) {\n return directives;\n }\n\n return {\n ...directives,\n ['report-uri' as CspDirectiveName]: [reportUri],\n };\n}\n\nexport function emitCspArtifacts(policy: ResolvedCspPolicy): CspEmitArtifacts {\n const nginxHeaderName = policy.reportOnly\n ? 'Content-Security-Policy-Report-Only'\n : 'Content-Security-Policy';\n const nginxPolicyValue = serializeDirectives(\n withReportUri(policy.directives, policy.reportUri),\n );\n\n return {\n nginxHeaderName,\n nginxPolicyValue,\n nginxAddHeaderLine: `add_header ${nginxHeaderName} \"${nginxPolicyValue}\" always;`,\n metaTag: policy.reportOnly\n ? null\n : {\n tagName: 'meta',\n attributes: {\n 'http-equiv': 'Content-Security-Policy',\n content: serializeDirectives(stripMetaInvalidDirectives(policy.directives)),\n },\n },\n };\n}\n\n/**\n * A single static-host `_headers` block that delivers the resolved CSP as a\n * real response header at the `/*` (all-paths) scope.\n *\n * Format matches the `_headers` convention consumed by Cloudflare Pages /\n * Netlify / Vercel (and the `saas-website` `X-Robots-Tag` `_headers` emitter):\n * a path line, then two-space-indented `Header-Name: value` lines. This is the\n * PORTABLE, provider-agnostic edge-CSP delivery — a CDN-served frontend (which\n * has no nginx to `add_header`) ships this file in its bucket and any\n * `_headers`-aware host applies it.\n *\n * Uses the FULL header value (including the header-only `frame-ancestors` and\n * `report-uri` directives) — a `_headers` line is a genuine response header, so\n * nothing is stripped (unlike the `<meta http-equiv>` fallback). Report-only\n * policies are honoured (the header name flips to\n * `Content-Security-Policy-Report-Only`, valid on a real header channel).\n *\n * The caller composes this block with any other `_headers` blocks (e.g. the\n * website's per-path `X-Robots-Tag`) into one file, separated by a blank line.\n */\nexport function emitCspHeadersFileBlock(policy: ResolvedCspPolicy): string {\n const { nginxHeaderName, nginxPolicyValue } = emitCspArtifacts(policy);\n return `/*\\n ${nginxHeaderName}: ${nginxPolicyValue}`;\n}\n\n/**\n * Provider-agnostic descriptor of the response-header MODIFICATION a CDN vendor\n * must install to deliver the resolved CSP at the edge. A concrete vendor\n * adapter (e.g. Cloudflare) maps this to its own API shape — for Cloudflare, a\n * `http_response_headers_transform` ruleset rule whose action sets\n * `headerName` to `value`.\n *\n * Same FULL header name + value as the nginx / `_headers` channels (a CDN sets\n * a real header, so `frame-ancestors` / `report-uri` are valid and retained).\n */\nexport interface CspEdgeHeaderModification {\n /** Cloudflare ruleset phase this modification belongs to. */\n readonly phase: 'http_response_headers_transform';\n /** The header operation — always `set` (overwrite any origin value). */\n readonly operation: 'set';\n /** Response-header name (report-only-aware, same as the nginx channel). */\n readonly headerName: string;\n /** Serialized policy value (identical to `nginxPolicyValue`). */\n readonly value: string;\n}\n\n/**\n * Derive the edge response-header modification carrying the resolved CSP, for a\n * CDN vendor's live-provisioning adapter to install. Thin over\n * {@link emitCspArtifacts} so the directive serialization is the single source\n * of truth across nginx / `_headers` / CDN channels.\n */\nexport function emitCspEdgeHeaderModification(policy: ResolvedCspPolicy): CspEdgeHeaderModification {\n const { nginxHeaderName, nginxPolicyValue } = emitCspArtifacts(policy);\n return {\n phase: 'http_response_headers_transform',\n operation: 'set',\n headerName: nginxHeaderName,\n value: nginxPolicyValue,\n };\n}\n\nexport interface RewriteNginxResult {\n readonly totalPairs: number;\n readonly pairsRewritten: number;\n readonly fileWritten: boolean;\n}\n\nexport function rewriteNginxCspMarkerPairs(\n filePath: string,\n addHeaderLine: string,\n): RewriteNginxResult {\n const original = readFileSync(filePath, 'utf-8');\n const { rewritten, totalPairs, pairsChanged } = rewriteNginxCspMarkerPairsString(\n original,\n addHeaderLine,\n filePath,\n );\n const fileWritten = rewritten !== original;\n\n if (fileWritten) {\n writeFileSync(filePath, rewritten, 'utf-8');\n }\n\n return {\n totalPairs,\n pairsRewritten: pairsChanged,\n fileWritten,\n };\n}\n\nexport function rewriteNginxCspMarkerPairsString(\n source: string,\n addHeaderLine: string,\n filePath = '<in-memory>',\n): {\n readonly rewritten: string;\n readonly totalPairs: number;\n readonly pairsChanged: number;\n} {\n const usesCrlf = source.includes('\\r\\n');\n const newline = usesCrlf ? '\\r\\n' : '\\n';\n const lines = source.split(newline);\n\n let totalPairs = 0;\n let pairsChanged = 0;\n let openBeginIndex: number | null = null;\n let openIndent = '';\n\n for (let index = 0; index < lines.length; index += 1) {\n const trimmed = lines[index].trim();\n\n if (trimmed === NGINX_CSP_BEGIN_MARKER) {\n if (openBeginIndex !== null) {\n throw new Error(\n `[csp-emit] ${filePath}:${index + 1} found a second '${NGINX_CSP_BEGIN_MARKER}' before the previous '${NGINX_CSP_END_MARKER}' (line ${openBeginIndex + 1})`,\n );\n }\n\n openBeginIndex = index;\n openIndent = lines[index].slice(0, lines[index].indexOf('#'));\n continue;\n }\n\n if (trimmed === NGINX_CSP_END_MARKER) {\n if (openBeginIndex === null) {\n throw new Error(\n `[csp-emit] ${filePath}:${index + 1} found '${NGINX_CSP_END_MARKER}' without a matching '${NGINX_CSP_BEGIN_MARKER}'`,\n );\n }\n\n totalPairs += 1;\n\n const existingBody = lines.slice(openBeginIndex + 1, index);\n const canonicalBody = [`${openIndent}${addHeaderLine}`];\n const existingNonBlank = existingBody.filter((line) => line.trim().length > 0);\n const canonicalNonBlank = canonicalBody.filter((line) => line.trim().length > 0);\n const bodyMatches =\n existingNonBlank.length === canonicalNonBlank.length &&\n existingNonBlank.every((line, bodyIndex) => line === canonicalNonBlank[bodyIndex]);\n\n if (!bodyMatches) {\n lines.splice(openBeginIndex + 1, index - openBeginIndex - 1, ...canonicalBody);\n index = openBeginIndex + canonicalBody.length + 1;\n pairsChanged += 1;\n }\n\n openBeginIndex = null;\n openIndent = '';\n }\n }\n\n if (openBeginIndex !== null) {\n throw new Error(\n `[csp-emit] ${filePath} has an unclosed '${NGINX_CSP_BEGIN_MARKER}' starting at line ${openBeginIndex + 1}`,\n );\n }\n\n return { rewritten: lines.join(newline), totalPairs, pairsChanged };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"csp-emit.js","sourceRoot":"","sources":["../../../../src/project-config/shared/csp-emit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EACL,eAAe,EACf,+BAA+B,GAEhC,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EACL,aAAa,GAEd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,gBAAgB,GAIjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AA2BzD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,8BAA8B,GAEhC;IACF,CAAC,+BAA+B,CAAC,MAAM,CAAC,EAAE,YAAY;IACtD,CAAC,+BAA+B,CAAC,OAAO,CAAC,EAAE,aAAa;IACxD,CAAC,+BAA+B,CAAC,KAAK,CAAC,EAAE,WAAW;IACpD,CAAC,+BAA+B,CAAC,GAAG,CAAC,EAAE,SAAS;IAChD,CAAC,+BAA+B,CAAC,KAAK,CAAC,EAAE,WAAW;IACpD,CAAC,+BAA+B,CAAC,IAAI,CAAC,EAAE,UAAU;CACnD,CAAC;AAyCF,MAAM,CAAC,MAAM,sBAAsB,GAAG,uBAAuB,CAAC;AAC9D,MAAM,CAAC,MAAM,oBAAoB,GAAG,qBAAqB,CAAC;AAE1D,MAAM,uBAAuB,GAAwB,IAAI,GAAG,CAAC;IAC3D,iBAAiB;IACjB,YAAY;IACZ,WAAW;IACX,SAAS;CACV,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;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ileSync, writeFileSync } from 'node:fs';\nimport {\n AppFrontendType,\n ProviderFrontendCspOriginBucket,\n type ProviderFrontendCspFootprint,\n} from '@wildo-ai/saas-models/public-runtime';\n\nimport {\n CSP_BASELINES,\n type CspBaselineDirectiveMap,\n} from './csp-defaults';\nimport {\n CspMergeStrategy,\n type CspDirectiveName,\n type EnvCspOverride,\n type WildoCspConfig,\n} from './csp.schemas';\nimport { WildoEnvironment } from './environment.schemas';\n\nexport type ResolvedCspDirectiveMap = Readonly<\n Partial<Record<CspDirectiveName, readonly string[]>>\n>;\n\nexport interface ResolvedCspPolicy {\n readonly directives: ResolvedCspDirectiveMap;\n readonly reportOnly: boolean;\n readonly reportUri: string | undefined;\n}\n\nexport interface CspEmitArtifacts {\n readonly nginxHeaderName: string;\n readonly nginxPolicyValue: string;\n readonly nginxAddHeaderLine: string;\n readonly metaTag:\n | {\n readonly tagName: 'meta';\n readonly attributes: {\n readonly 'http-equiv': string;\n readonly content: string;\n };\n }\n | null;\n}\n\n/**\n * Where each of a provider's declared origin buckets lands in the policy.\n *\n * THE ONE PLACE the mapping exists. A provider declares what it is REACHING\n * — a script it loads, an API it calls, an iframe it embeds — and which\n * directive grades that fetch is framework knowledge, so a provider author\n * never has to learn the CSP directive taxonomy and a change to it is a change\n * here rather than in every provider package.\n *\n * The bucket names are also why `ProviderFrontendCspFootprint` does not restate\n * `CSP_DIRECTIVE_NAMES`: that vocabulary already has one named source, in this\n * package, and `@wildo-ai/saas-models` — where the footprint has to live,\n * because it rides on the wire — depends on nothing of ours.\n *\n * Total over the footprint's buckets: adding a bucket without deciding its\n * directive is a compile error here, which is the coupling this shape exists\n * for. A bucket with no mapping would be authored, serialized, read, and\n * silently contribute nothing — in production only, since CSP is report-only\n * in development.\n */\nconst PROVIDER_CSP_BUCKET_DIRECTIVES: Readonly<\n Record<ProviderFrontendCspOriginBucket, CspDirectiveName>\n> = {\n [ProviderFrontendCspOriginBucket.SCRIPT]: 'script-src',\n [ProviderFrontendCspOriginBucket.CONNECT]: 'connect-src',\n [ProviderFrontendCspOriginBucket.FRAME]: 'frame-src',\n [ProviderFrontendCspOriginBucket.IMG]: 'img-src',\n [ProviderFrontendCspOriginBucket.STYLE]: 'style-src',\n [ProviderFrontendCspOriginBucket.FONT]: 'font-src',\n};\n\nexport interface ResolveCspPolicyInput {\n readonly frontendType: AppFrontendType;\n readonly appCsp: WildoCspConfig | undefined;\n readonly envOverride?: EnvCspOverride;\n /**\n * The CSP footprints of the providers DECLARED for this service — the fourth\n * layer, added by #332.\n *\n * Without it, a marketing site that wants an embedded meeting or a SaaS app\n * that wants a Drive picker means hand-editing script / frame / connect\n * origins per application, per service, per environment; and getting it wrong\n * is invisible until production, because development is report-only. The\n * caller reads these from the service's materialized provider block, which is\n * DATA precisely so that no frontend module has to be executed to obtain them.\n *\n * Providers declared for ANOTHER service must not appear here: the point of\n * the layer is that a Zoom origin admitted for the marketing site is not\n * thereby admitted for the SaaS app.\n *\n * A footprint's `derivedOrigins` must ALREADY BE RESOLVED into its buckets by\n * the caller. This resolver sees no `publicConfig` — it composes a policy, it\n * does not read a provider's configuration — and the one caller that has both\n * halves is `CspSyncService`, which reads each entry out of the materialized\n * block.\n */\n readonly providerCspFootprints?: ReadonlyArray<ProviderFrontendCspFootprint>;\n /**\n * Environment id this CSP is being resolved for (e.g. `'local'`,\n * `'staging'`, `'production'`, or any custom slug). Optional for\n * back-compat — when `undefined`, no env-aware auto-loosening applies\n * (the resolver behaves exactly as it did pre-`viteDevLoosening`).\n *\n * Required when the caller wants the framework to auto-apply\n * `viteDevLoosening` for `'local'` + `SAAS_APP`. The CLI's\n * `CspSyncService` already knows the env id and SHOULD pass it.\n */\n readonly environmentId?: string;\n}\n\nexport const NGINX_CSP_BEGIN_MARKER = '# >>> wildo csp begin';\nexport const NGINX_CSP_END_MARKER = '# <<< wildo csp end';\n\nconst META_INVALID_DIRECTIVES: ReadonlySet<string> = new Set([\n 'frame-ancestors',\n 'report-uri',\n 'report-to',\n 'sandbox',\n]);\n\n/**\n * Derives the WebSocket-scheme companion origins for every HTTP(S) origin\n * present in a `connect-src` source list, and returns the list widened to\n * include them.\n *\n * Why the framework ships this rather than making each app author it:\n * every Wildo backend serves its realtime channel (Socket.IO) on the SAME\n * origin as its HTTP API. Socket.IO opens the handshake over polling and\n * then UPGRADES to a raw `ws://` / `wss://` connection to that origin. The\n * CSP `connect-src` directive grades WebSocket connections by their `ws`/\n * `wss` scheme, and — per the CSP spec — an `http://host` source does NOT\n * authorize a `ws://host` connection (the schemes are distinct match\n * tokens). So an app that allow-lists `http://localhost:4241` for `fetch`/\n * `XHR` but not `ws://localhost:4241` will emit a `connect-src` violation\n * the instant the socket upgrades — exactly the trap every infra config\n * would otherwise have to remember to work around by hand.\n *\n * Transform (idempotent, dedupe-safe):\n * `http://host[:port]` → also allow `ws://host[:port]`\n * `https://host[:port]` → also allow `wss://host[:port]`\n * bare scheme `http:` → also allow `ws:`\n * bare scheme `https:` → also allow `wss:`\n *\n * Keyword / non-HTTP sources (`'self'`, `'none'`, `data:`, `blob:`, an\n * already-`ws://` origin, …) are passed through untouched. `'self'` is\n * deliberately NOT expanded: the browser tab is served from the frontend\n * origin, never the backend API origin, so a same-origin `ws` derivation\n * from `'self'` would authorize the wrong host. The backend origin is\n * always listed explicitly, which is what this widens.\n */\nfunction augmentConnectSrcWithWebSocketOrigins(\n sources: readonly string[] | undefined,\n): readonly string[] | undefined {\n if (!sources || sources.length === 0) {\n return sources;\n }\n\n const derived: string[] = [];\n for (const source of sources) {\n if (source.startsWith('https://')) {\n derived.push(`wss://${source.slice('https://'.length)}`);\n } else if (source.startsWith('http://')) {\n derived.push(`ws://${source.slice('http://'.length)}`);\n } else if (source === 'https:') {\n derived.push('wss:');\n } else if (source === 'http:') {\n derived.push('ws:');\n }\n }\n\n return mergeSourceLists(sources, derived);\n}\n\nfunction mergeSourceLists(\n a: readonly string[] | undefined,\n b: readonly string[] | undefined,\n): readonly string[] {\n if (!a || a.length === 0) {\n return b ?? [];\n }\n if (!b || b.length === 0) {\n return a;\n }\n\n const seen = new Set(a);\n const out: string[] = [...a];\n for (const source of b) {\n if (!seen.has(source)) {\n seen.add(source);\n out.push(source);\n }\n }\n return out;\n}\n\n/**\n * Resolves the generic layered CSP model shared by all frontend surfaces:\n * platform baseline, app-static config, env-selected overrides, then the\n * declared providers' own footprints (#332).\n *\n * The provider layer is fourth on purpose. The first three describe what the\n * APPLICATION decided; the fourth describes what the things the application\n * declared actually need in order to work. Placing it last means a provider\n * cannot be silently dropped by an app-level `REPLACE_BASELINE`, and placing it\n * before the WebSocket derivation means a provider's `connect-src` origin gets\n * its `wss://` companion exactly like the backend API's.\n *\n * This lives with the CSP schemas/defaults so consumers do not depend on any\n * concrete frontend package to process security config.\n */\nexport function resolveCspPolicy(\n input: ResolveCspPolicyInput,\n): ResolvedCspPolicy | null {\n const { frontendType, appCsp, envOverride } = input;\n\n if (!appCsp || !appCsp.enabled) {\n return null;\n }\n\n const baseline: CspBaselineDirectiveMap = CSP_BASELINES[frontendType];\n let merged: ResolvedCspDirectiveMap;\n\n if (appCsp.mergeStrategy === CspMergeStrategy.REPLACE_BASELINE) {\n merged = appCsp.directives;\n } else {\n const out: Partial<Record<CspDirectiveName, readonly string[]>> = {};\n const allKeys = new Set<CspDirectiveName>([\n ...(Object.keys(baseline) as CspDirectiveName[]),\n ...(Object.keys(appCsp.directives) as CspDirectiveName[]),\n ]);\n\n for (const key of allKeys) {\n out[key] = mergeSourceLists(baseline[key], appCsp.directives[key]);\n }\n\n merged = out;\n }\n\n if (envOverride?.extraDirectives) {\n const out: Partial<Record<CspDirectiveName, readonly string[]>> = {\n ...merged,\n };\n\n for (const key of Object.keys(envOverride.extraDirectives) as CspDirectiveName[]) {\n out[key] = mergeSourceLists(merged[key], envOverride.extraDirectives[key]);\n }\n\n merged = out;\n }\n\n // Provider layer (#332) — the origins the providers DECLARED FOR THIS SERVICE\n // need, merged after the app-static and env layers and before the WebSocket\n // derivation below (so a provider's `connect-src` origin gets its `wss://`\n // companion for free, exactly like the backend API's).\n //\n // Additive in every merge strategy, including REPLACE_BASELINE. That strategy\n // exists so an app can discard the platform BASELINE when it is wrong for the\n // surface; a provider the same app declared is a dependency it chose, not a\n // default it is overriding, and silently dropping its origins would produce a\n // policy that blocks a feature the app asked for — in production only.\n const providerFootprints = input.providerCspFootprints ?? [];\n if (providerFootprints.length > 0) {\n const out: Partial<Record<CspDirectiveName, readonly string[]>> = { ...merged };\n\n for (const footprint of providerFootprints) {\n for (const [bucket, directive] of Object.entries(PROVIDER_CSP_BUCKET_DIRECTIVES) as ReadonlyArray<\n readonly [ProviderFrontendCspOriginBucket, CspDirectiveName]\n >) {\n const origins = footprint[bucket];\n if (origins.length === 0) continue;\n out[directive] = mergeSourceLists(out[directive], origins);\n }\n }\n\n merged = out;\n }\n\n // Vite dev-mode loosening (auto-applied for local SAAS_APP).\n //\n // Vite's dev server REQUIRES both `'unsafe-eval'` (lazy module +\n // sourcemap transforms) and `'unsafe-inline'` (HMR client bootstrap\n // injects a literal inline `<script>`) to function. Under the tight\n // SAAS_APP baseline (`script-src 'self'`), those produce ~120+ CSP\n // violations per page load that drown out real signal (e.g. the\n // Google-Fonts gotcha that the loosened style-src/font-src now allow).\n //\n // The framework SHIPS this knowledge — every Wildo SaaS app uses\n // Vite — so we auto-loosen for `'local'` + `SAAS_APP` here rather\n // than forcing every infra config to re-author the same opt-in. An\n // explicit `viteDevLoosening: false` override keeps tight `script-src`\n // when an author is actively debugging a real CSP issue and willing\n // to accept the Vite noise. Production builds emit `<script\n // type=\"module\">` only and never `eval()`, so production envs never\n // trigger the auto-loosening — `viteDevLoosening` defaults to FALSE\n // there even if the env id is non-`local`.\n const isViteDevAutoTarget =\n input.environmentId === WildoEnvironment.LOCAL &&\n frontendType === AppFrontendType.SAAS_APP;\n const viteDevLoosening = envOverride?.viteDevLoosening ?? isViteDevAutoTarget;\n if (viteDevLoosening) {\n merged = {\n ...merged,\n 'script-src': mergeSourceLists(\n merged['script-src'],\n [\"'unsafe-inline'\", \"'unsafe-eval'\"],\n ),\n };\n }\n\n // Auto-derive the `ws://` / `wss://` companion origins for every HTTP(S)\n // origin the app allow-listed in `connect-src`. Applied LAST so it covers\n // origins contributed by the baseline, app-static config, AND env override\n // alike (e.g. the local `http://localhost:4241` and the staging/prod\n // `https://api.<app>.wildo.app` backend origins). Without this, the\n // Socket.IO transport upgrade to a raw WebSocket against the backend origin\n // trips a `connect-src` violation on every surface. See the helper JSDoc for\n // the scheme-matching rationale.\n const connectSrcWithWs = augmentConnectSrcWithWebSocketOrigins(merged['connect-src']);\n if (connectSrcWithWs !== merged['connect-src']) {\n merged = {\n ...merged,\n 'connect-src': connectSrcWithWs,\n };\n }\n\n return {\n directives: merged,\n reportOnly: envOverride?.reportOnly ?? appCsp.reportOnly,\n reportUri: envOverride?.reportUri ?? appCsp.reportUri,\n };\n}\n\nfunction serializeDirectives(directives: ResolvedCspDirectiveMap): string {\n return Object.entries(directives)\n .filter(([, sources]) => sources && sources.length > 0)\n .map(([name, sources]) => `${name} ${(sources ?? []).join(' ')}`)\n .join('; ');\n}\n\nfunction stripMetaInvalidDirectives(\n directives: ResolvedCspDirectiveMap,\n): ResolvedCspDirectiveMap {\n const out: Partial<Record<CspDirectiveName, readonly string[]>> = {};\n\n for (const [name, sources] of Object.entries(directives)) {\n if (!META_INVALID_DIRECTIVES.has(name)) {\n out[name as CspDirectiveName] = sources;\n }\n }\n\n return out;\n}\n\nfunction withReportUri(\n directives: ResolvedCspDirectiveMap,\n reportUri: string | undefined,\n): ResolvedCspDirectiveMap {\n if (!reportUri) {\n return directives;\n }\n\n return {\n ...directives,\n ['report-uri' as CspDirectiveName]: [reportUri],\n };\n}\n\nexport function emitCspArtifacts(policy: ResolvedCspPolicy): CspEmitArtifacts {\n const nginxHeaderName = policy.reportOnly\n ? 'Content-Security-Policy-Report-Only'\n : 'Content-Security-Policy';\n const nginxPolicyValue = serializeDirectives(\n withReportUri(policy.directives, policy.reportUri),\n );\n\n return {\n nginxHeaderName,\n nginxPolicyValue,\n nginxAddHeaderLine: `add_header ${nginxHeaderName} \"${nginxPolicyValue}\" always;`,\n metaTag: policy.reportOnly\n ? null\n : {\n tagName: 'meta',\n attributes: {\n 'http-equiv': 'Content-Security-Policy',\n content: serializeDirectives(stripMetaInvalidDirectives(policy.directives)),\n },\n },\n };\n}\n\n/**\n * A single static-host `_headers` block that delivers the resolved CSP as a\n * real response header at the `/*` (all-paths) scope.\n *\n * Format matches the `_headers` convention consumed by Cloudflare Pages /\n * Netlify / Vercel (and the `saas-website` `X-Robots-Tag` `_headers` emitter):\n * a path line, then two-space-indented `Header-Name: value` lines. This is the\n * PORTABLE, provider-agnostic edge-CSP delivery — a CDN-served frontend (which\n * has no nginx to `add_header`) ships this file in its bucket and any\n * `_headers`-aware host applies it.\n *\n * Uses the FULL header value (including the header-only `frame-ancestors` and\n * `report-uri` directives) — a `_headers` line is a genuine response header, so\n * nothing is stripped (unlike the `<meta http-equiv>` fallback). Report-only\n * policies are honoured (the header name flips to\n * `Content-Security-Policy-Report-Only`, valid on a real header channel).\n *\n * The caller composes this block with any other `_headers` blocks (e.g. the\n * website's per-path `X-Robots-Tag`) into one file, separated by a blank line.\n */\nexport function emitCspHeadersFileBlock(policy: ResolvedCspPolicy): string {\n const { nginxHeaderName, nginxPolicyValue } = emitCspArtifacts(policy);\n return `/*\\n ${nginxHeaderName}: ${nginxPolicyValue}`;\n}\n\n/**\n * Provider-agnostic descriptor of the response-header MODIFICATION a CDN vendor\n * must install to deliver the resolved CSP at the edge. A concrete vendor\n * adapter (e.g. Cloudflare) maps this to its own API shape — for Cloudflare, a\n * `http_response_headers_transform` ruleset rule whose action sets\n * `headerName` to `value`.\n *\n * Same FULL header name + value as the nginx / `_headers` channels (a CDN sets\n * a real header, so `frame-ancestors` / `report-uri` are valid and retained).\n */\nexport interface CspEdgeHeaderModification {\n /** Cloudflare ruleset phase this modification belongs to. */\n readonly phase: 'http_response_headers_transform';\n /** The header operation — always `set` (overwrite any origin value). */\n readonly operation: 'set';\n /** Response-header name (report-only-aware, same as the nginx channel). */\n readonly headerName: string;\n /** Serialized policy value (identical to `nginxPolicyValue`). */\n readonly value: string;\n}\n\n/**\n * Derive the edge response-header modification carrying the resolved CSP, for a\n * CDN vendor's live-provisioning adapter to install. Thin over\n * {@link emitCspArtifacts} so the directive serialization is the single source\n * of truth across nginx / `_headers` / CDN channels.\n */\nexport function emitCspEdgeHeaderModification(policy: ResolvedCspPolicy): CspEdgeHeaderModification {\n const { nginxHeaderName, nginxPolicyValue } = emitCspArtifacts(policy);\n return {\n phase: 'http_response_headers_transform',\n operation: 'set',\n headerName: nginxHeaderName,\n value: nginxPolicyValue,\n };\n}\n\nexport interface RewriteNginxResult {\n readonly totalPairs: number;\n readonly pairsRewritten: number;\n readonly fileWritten: boolean;\n}\n\nexport function rewriteNginxCspMarkerPairs(\n filePath: string,\n addHeaderLine: string,\n): RewriteNginxResult {\n const original = readFileSync(filePath, 'utf-8');\n const { rewritten, totalPairs, pairsChanged } = rewriteNginxCspMarkerPairsString(\n original,\n addHeaderLine,\n filePath,\n );\n const fileWritten = rewritten !== original;\n\n if (fileWritten) {\n writeFileSync(filePath, rewritten, 'utf-8');\n }\n\n return {\n totalPairs,\n pairsRewritten: pairsChanged,\n fileWritten,\n };\n}\n\nexport function rewriteNginxCspMarkerPairsString(\n source: string,\n addHeaderLine: string,\n filePath = '<in-memory>',\n): {\n readonly rewritten: string;\n readonly totalPairs: number;\n readonly pairsChanged: number;\n} {\n const usesCrlf = source.includes('\\r\\n');\n const newline = usesCrlf ? '\\r\\n' : '\\n';\n const lines = source.split(newline);\n\n let totalPairs = 0;\n let pairsChanged = 0;\n let openBeginIndex: number | null = null;\n let openIndent = '';\n\n for (let index = 0; index < lines.length; index += 1) {\n const trimmed = lines[index].trim();\n\n if (trimmed === NGINX_CSP_BEGIN_MARKER) {\n if (openBeginIndex !== null) {\n throw new Error(\n `[csp-emit] ${filePath}:${index + 1} found a second '${NGINX_CSP_BEGIN_MARKER}' before the previous '${NGINX_CSP_END_MARKER}' (line ${openBeginIndex + 1})`,\n );\n }\n\n openBeginIndex = index;\n openIndent = lines[index].slice(0, lines[index].indexOf('#'));\n continue;\n }\n\n if (trimmed === NGINX_CSP_END_MARKER) {\n if (openBeginIndex === null) {\n throw new Error(\n `[csp-emit] ${filePath}:${index + 1} found '${NGINX_CSP_END_MARKER}' without a matching '${NGINX_CSP_BEGIN_MARKER}'`,\n );\n }\n\n totalPairs += 1;\n\n const existingBody = lines.slice(openBeginIndex + 1, index);\n const canonicalBody = [`${openIndent}${addHeaderLine}`];\n const existingNonBlank = existingBody.filter((line) => line.trim().length > 0);\n const canonicalNonBlank = canonicalBody.filter((line) => line.trim().length > 0);\n const bodyMatches =\n existingNonBlank.length === canonicalNonBlank.length &&\n existingNonBlank.every((line, bodyIndex) => line === canonicalNonBlank[bodyIndex]);\n\n if (!bodyMatches) {\n lines.splice(openBeginIndex + 1, index - openBeginIndex - 1, ...canonicalBody);\n index = openBeginIndex + canonicalBody.length + 1;\n pairsChanged += 1;\n }\n\n openBeginIndex = null;\n openIndent = '';\n }\n }\n\n if (openBeginIndex !== null) {\n throw new Error(\n `[csp-emit] ${filePath} has an unclosed '${NGINX_CSP_BEGIN_MARKER}' starting at line ${openBeginIndex + 1}`,\n );\n }\n\n return { rewritten: lines.join(newline), totalPairs, pairsChanged };\n}\n"]}
|