@wildo-ai/platform-config-lib 1.1.4 → 1.1.6

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.
Files changed (230) hide show
  1. package/dist/esm/bootstrap/application-backend-env.contracts.d.ts.map +1 -1
  2. package/dist/esm/bootstrap/bootstrap-planner.d.ts.map +1 -1
  3. package/dist/esm/bootstrap/bootstrap.contracts.d.ts +24 -1
  4. package/dist/esm/bootstrap/bootstrap.contracts.d.ts.map +1 -1
  5. package/dist/esm/bootstrap/bootstrap.contracts.js +25 -0
  6. package/dist/esm/bootstrap/bootstrap.contracts.js.map +1 -1
  7. package/dist/esm/bootstrap/bootstrap.schemas.d.ts +117 -1
  8. package/dist/esm/bootstrap/bootstrap.schemas.d.ts.map +1 -1
  9. package/dist/esm/bootstrap/bootstrap.schemas.js +63 -4
  10. package/dist/esm/bootstrap/bootstrap.schemas.js.map +1 -1
  11. package/dist/esm/bootstrap/platform-runtime-env.contracts.d.ts +24 -1
  12. package/dist/esm/bootstrap/platform-runtime-env.contracts.d.ts.map +1 -1
  13. package/dist/esm/bootstrap/platform-runtime-env.contracts.js +24 -0
  14. package/dist/esm/bootstrap/platform-runtime-env.contracts.js.map +1 -1
  15. package/dist/esm/bootstrap/platform-store-preconnect.d.ts +37 -0
  16. package/dist/esm/bootstrap/platform-store-preconnect.d.ts.map +1 -0
  17. package/dist/esm/bootstrap/platform-store-preconnect.js +43 -0
  18. package/dist/esm/bootstrap/platform-store-preconnect.js.map +1 -0
  19. package/dist/esm/bootstrap/runtime-backing-service-access.d.ts.map +1 -1
  20. package/dist/esm/bootstrap/runtime-backing-service-access.js +8 -4
  21. package/dist/esm/bootstrap/runtime-backing-service-access.js.map +1 -1
  22. package/dist/esm/bootstrap/runtime-network-policy.d.ts.map +1 -1
  23. package/dist/esm/bootstrap/runtime-network-topology.d.ts.map +1 -1
  24. package/dist/esm/bootstrap/runtime-network-topology.js.map +1 -1
  25. package/dist/esm/bootstrap/runtime-platform-access.d.ts.map +1 -1
  26. package/dist/esm/bootstrap/runtime-principal.contracts.d.ts.map +1 -1
  27. package/dist/esm/bootstrap/runtime-topology.contracts.d.ts +36 -3
  28. package/dist/esm/bootstrap/runtime-topology.contracts.d.ts.map +1 -1
  29. package/dist/esm/bootstrap/runtime-topology.contracts.js +36 -13
  30. package/dist/esm/bootstrap/runtime-topology.contracts.js.map +1 -1
  31. package/dist/esm/bootstrap/wildo-owner-organization.contracts.d.ts +29 -0
  32. package/dist/esm/bootstrap/wildo-owner-organization.contracts.d.ts.map +1 -1
  33. package/dist/esm/bootstrap/wildo-owner-organization.contracts.js +39 -0
  34. package/dist/esm/bootstrap/wildo-owner-organization.contracts.js.map +1 -1
  35. package/dist/esm/config-authoring.entry.d.ts.map +1 -1
  36. package/dist/esm/config-authoring.entry.js.map +1 -1
  37. package/dist/esm/index.d.ts +2 -0
  38. package/dist/esm/index.d.ts.map +1 -1
  39. package/dist/esm/index.js +2 -0
  40. package/dist/esm/index.js.map +1 -1
  41. package/dist/esm/lockfile/build-parallelism.d.ts +40 -0
  42. package/dist/esm/lockfile/build-parallelism.d.ts.map +1 -0
  43. package/dist/esm/lockfile/build-parallelism.js +64 -0
  44. package/dist/esm/lockfile/build-parallelism.js.map +1 -0
  45. package/dist/esm/lockfile/lockfile-io.d.ts +7 -1
  46. package/dist/esm/lockfile/lockfile-io.d.ts.map +1 -1
  47. package/dist/esm/lockfile/lockfile-io.js +17 -3
  48. package/dist/esm/lockfile/lockfile-io.js.map +1 -1
  49. package/dist/esm/lockfile/materialize-infra-section.d.ts +28 -7
  50. package/dist/esm/lockfile/materialize-infra-section.d.ts.map +1 -1
  51. package/dist/esm/lockfile/materialize-infra-section.js +24 -11
  52. package/dist/esm/lockfile/materialize-infra-section.js.map +1 -1
  53. package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.d.ts +455 -6
  54. package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.d.ts.map +1 -1
  55. package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.js +27 -0
  56. package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.js.map +1 -1
  57. package/dist/esm/project-config/application-public-pricing-catalog.loader.d.ts +13 -0
  58. package/dist/esm/project-config/application-public-pricing-catalog.loader.d.ts.map +1 -0
  59. package/dist/esm/project-config/application-public-pricing-catalog.loader.js +56 -0
  60. package/dist/esm/project-config/application-public-pricing-catalog.loader.js.map +1 -0
  61. package/dist/esm/project-config/define-framework-config.d.ts.map +1 -1
  62. package/dist/esm/project-config/define-infra-env-config.d.ts +886 -29
  63. package/dist/esm/project-config/define-infra-env-config.d.ts.map +1 -1
  64. package/dist/esm/project-config/define-infra-env-config.js +395 -16
  65. package/dist/esm/project-config/define-infra-env-config.js.map +1 -1
  66. package/dist/esm/project-config/define-minion-config.d.ts.map +1 -1
  67. package/dist/esm/project-config/define-minion-config.js +1 -2
  68. package/dist/esm/project-config/define-minion-config.js.map +1 -1
  69. package/dist/esm/project-config/define-saas-config.d.ts +142 -25
  70. package/dist/esm/project-config/define-saas-config.d.ts.map +1 -1
  71. package/dist/esm/project-config/define-saas-config.js +229 -26
  72. package/dist/esm/project-config/define-saas-config.js.map +1 -1
  73. package/dist/esm/project-config/define-worker-config.d.ts.map +1 -1
  74. package/dist/esm/project-config/hosted-infra-env-config.d.ts +59 -0
  75. package/dist/esm/project-config/hosted-infra-env-config.d.ts.map +1 -0
  76. package/dist/esm/project-config/hosted-infra-env-config.js +187 -0
  77. package/dist/esm/project-config/hosted-infra-env-config.js.map +1 -0
  78. package/dist/esm/project-config/index.d.ts +6 -0
  79. package/dist/esm/project-config/index.d.ts.map +1 -1
  80. package/dist/esm/project-config/index.js +6 -0
  81. package/dist/esm/project-config/index.js.map +1 -1
  82. package/dist/esm/project-config/loader.d.ts +35 -0
  83. package/dist/esm/project-config/loader.d.ts.map +1 -1
  84. package/dist/esm/project-config/loader.js +148 -8
  85. package/dist/esm/project-config/loader.js.map +1 -1
  86. package/dist/esm/project-config/npm-version-range.d.ts +23 -0
  87. package/dist/esm/project-config/npm-version-range.d.ts.map +1 -0
  88. package/dist/esm/project-config/npm-version-range.js +175 -0
  89. package/dist/esm/project-config/npm-version-range.js.map +1 -0
  90. package/dist/esm/project-config/provider-catalog-types.d.ts.map +1 -1
  91. package/dist/esm/project-config/provider-companion-discovery.d.ts +288 -30
  92. package/dist/esm/project-config/provider-companion-discovery.d.ts.map +1 -1
  93. package/dist/esm/project-config/provider-companion-discovery.js +795 -46
  94. package/dist/esm/project-config/provider-companion-discovery.js.map +1 -1
  95. package/dist/esm/project-config/provider-runtime-artifacts.d.ts +192 -20
  96. package/dist/esm/project-config/provider-runtime-artifacts.d.ts.map +1 -1
  97. package/dist/esm/project-config/provider-runtime-artifacts.js +381 -42
  98. package/dist/esm/project-config/provider-runtime-artifacts.js.map +1 -1
  99. package/dist/esm/project-config/shared/application-creation-verification.schemas.d.ts.map +1 -1
  100. package/dist/esm/project-config/shared/application-modules.schemas.d.ts.map +1 -1
  101. package/dist/esm/project-config/shared/application-modules.utils.d.ts.map +1 -1
  102. package/dist/esm/project-config/shared/auth.schemas.d.ts +14 -35
  103. package/dist/esm/project-config/shared/auth.schemas.d.ts.map +1 -1
  104. package/dist/esm/project-config/shared/auth.schemas.js +14 -35
  105. package/dist/esm/project-config/shared/auth.schemas.js.map +1 -1
  106. package/dist/esm/project-config/shared/backing-service-servability.d.ts +157 -0
  107. package/dist/esm/project-config/shared/backing-service-servability.d.ts.map +1 -0
  108. package/dist/esm/project-config/shared/backing-service-servability.js +256 -0
  109. package/dist/esm/project-config/shared/backing-service-servability.js.map +1 -0
  110. package/dist/esm/project-config/shared/backing-services.schemas.d.ts +66 -66
  111. package/dist/esm/project-config/shared/backing-services.schemas.d.ts.map +1 -1
  112. package/dist/esm/project-config/shared/backing-services.schemas.js +75 -67
  113. package/dist/esm/project-config/shared/backing-services.schemas.js.map +1 -1
  114. package/dist/esm/project-config/shared/cdn.example.d.ts.map +1 -1
  115. package/dist/esm/project-config/shared/cdn.schemas.d.ts.map +1 -1
  116. package/dist/esm/project-config/shared/csp-defaults.d.ts.map +1 -1
  117. package/dist/esm/project-config/shared/csp-emit.d.ts.map +1 -1
  118. package/dist/esm/project-config/shared/csp-emit.js +41 -2
  119. package/dist/esm/project-config/shared/csp-emit.js.map +1 -1
  120. package/dist/esm/project-config/shared/csp.schemas.d.ts +11 -12
  121. package/dist/esm/project-config/shared/csp.schemas.d.ts.map +1 -1
  122. package/dist/esm/project-config/shared/csp.schemas.js +11 -12
  123. package/dist/esm/project-config/shared/csp.schemas.js.map +1 -1
  124. package/dist/esm/project-config/shared/data-services.schemas.d.ts.map +1 -1
  125. package/dist/esm/project-config/shared/env-example-defaults.d.ts.map +1 -1
  126. package/dist/esm/project-config/shared/environment.schemas.d.ts +152 -12
  127. package/dist/esm/project-config/shared/environment.schemas.d.ts.map +1 -1
  128. package/dist/esm/project-config/shared/environment.schemas.js +186 -9
  129. package/dist/esm/project-config/shared/environment.schemas.js.map +1 -1
  130. package/dist/esm/project-config/shared/infra-providers.schemas.d.ts +185 -10
  131. package/dist/esm/project-config/shared/infra-providers.schemas.d.ts.map +1 -1
  132. package/dist/esm/project-config/shared/infra-providers.schemas.js +40 -3
  133. package/dist/esm/project-config/shared/infra-providers.schemas.js.map +1 -1
  134. package/dist/esm/project-config/shared/infra-service.schemas.d.ts.map +1 -1
  135. package/dist/esm/project-config/shared/infrastructure-defaults.schemas.d.ts.map +1 -1
  136. package/dist/esm/project-config/shared/infrastructure-defaults.schemas.js.map +1 -1
  137. package/dist/esm/project-config/shared/k8s-utils.d.ts.map +1 -1
  138. package/dist/esm/project-config/shared/k8s-utils.js.map +1 -1
  139. package/dist/esm/project-config/shared/minion-platform-access.vocabulary.d.ts.map +1 -1
  140. package/dist/esm/project-config/shared/minion-platform-access.vocabulary.js.map +1 -1
  141. package/dist/esm/project-config/shared/minion-resource-access.validation.d.ts +77 -47
  142. package/dist/esm/project-config/shared/minion-resource-access.validation.d.ts.map +1 -1
  143. package/dist/esm/project-config/shared/minion-resource-access.validation.js +114 -52
  144. package/dist/esm/project-config/shared/minion-resource-access.validation.js.map +1 -1
  145. package/dist/esm/project-config/shared/platform-services.schemas.d.ts +50 -0
  146. package/dist/esm/project-config/shared/platform-services.schemas.d.ts.map +1 -1
  147. package/dist/esm/project-config/shared/platform-services.schemas.js +57 -0
  148. package/dist/esm/project-config/shared/platform-services.schemas.js.map +1 -1
  149. package/dist/esm/project-config/shared/platform-storage.schemas.d.ts +35 -0
  150. package/dist/esm/project-config/shared/platform-storage.schemas.d.ts.map +1 -0
  151. package/dist/esm/project-config/shared/platform-storage.schemas.js +37 -0
  152. package/dist/esm/project-config/shared/platform-storage.schemas.js.map +1 -0
  153. package/dist/esm/project-config/shared/schema-version.schemas.d.ts.map +1 -1
  154. package/dist/esm/project-config/shared/service-definitions.schemas.d.ts.map +1 -1
  155. package/dist/esm/project-config/shared/systems-of-record-env.schemas.d.ts +81 -0
  156. package/dist/esm/project-config/shared/systems-of-record-env.schemas.d.ts.map +1 -0
  157. package/dist/esm/project-config/shared/systems-of-record-env.schemas.js +74 -0
  158. package/dist/esm/project-config/shared/systems-of-record-env.schemas.js.map +1 -0
  159. package/dist/esm/project-config/static-asset-import-noop.d.ts +26 -0
  160. package/dist/esm/project-config/static-asset-import-noop.d.ts.map +1 -0
  161. package/dist/esm/project-config/static-asset-import-noop.js +49 -0
  162. package/dist/esm/project-config/static-asset-import-noop.js.map +1 -0
  163. package/dist/esm/registry/artifact-domain.schemas.d.ts +1 -1
  164. package/dist/esm/registry/artifact-domain.schemas.d.ts.map +1 -1
  165. package/dist/esm/registry/companion-api.schemas.d.ts +0 -176
  166. package/dist/esm/registry/companion-api.schemas.d.ts.map +0 -1
  167. package/dist/esm/registry/companion-api.schemas.js.map +0 -1
  168. package/dist/esm/registry/digest.schemas.d.ts.map +1 -1
  169. package/dist/esm/registry/index.d.ts +3 -1
  170. package/dist/esm/registry/index.d.ts.map +1 -1
  171. package/dist/esm/registry/index.js +3 -1
  172. package/dist/esm/registry/index.js.map +1 -1
  173. package/dist/esm/registry/local-checkout-source.d.ts +31 -0
  174. package/dist/esm/registry/local-checkout-source.d.ts.map +1 -0
  175. package/dist/esm/registry/local-checkout-source.js +45 -0
  176. package/dist/esm/registry/local-checkout-source.js.map +1 -0
  177. package/dist/esm/registry/lockfile-modules-section.schemas.d.ts +174 -14
  178. package/dist/esm/registry/lockfile-modules-section.schemas.d.ts.map +1 -1
  179. package/dist/esm/registry/lockfile-modules-section.schemas.js +120 -11
  180. package/dist/esm/registry/lockfile-modules-section.schemas.js.map +1 -1
  181. package/dist/esm/registry/module-artifact.schemas.d.ts +79 -0
  182. package/dist/esm/registry/module-artifact.schemas.d.ts.map +1 -1
  183. package/dist/esm/registry/module-artifact.schemas.js +36 -0
  184. package/dist/esm/registry/module-artifact.schemas.js.map +1 -1
  185. package/dist/esm/registry/module-manifest.schemas.d.ts +403 -23
  186. package/dist/esm/registry/module-manifest.schemas.d.ts.map +1 -1
  187. package/dist/esm/registry/module-manifest.schemas.js +502 -60
  188. package/dist/esm/registry/module-manifest.schemas.js.map +1 -1
  189. package/dist/esm/registry/module-search.schemas.d.ts +80 -0
  190. package/dist/esm/registry/module-search.schemas.d.ts.map +1 -0
  191. package/dist/esm/registry/module-search.schemas.js +112 -0
  192. package/dist/esm/registry/module-search.schemas.js.map +1 -0
  193. package/dist/esm/registry/registry-config.schemas.d.ts +16 -0
  194. package/dist/esm/registry/registry-config.schemas.d.ts.map +1 -1
  195. package/dist/esm/registry/registry-config.schemas.js +8 -0
  196. package/dist/esm/registry/registry-config.schemas.js.map +1 -1
  197. package/dist/esm/registry/registry-errors.d.ts +126 -2
  198. package/dist/esm/registry/registry-errors.d.ts.map +1 -1
  199. package/dist/esm/registry/registry-errors.js +183 -14
  200. package/dist/esm/registry/registry-errors.js.map +1 -1
  201. package/dist/esm/registry/registry-keys.schemas.d.ts +80 -0
  202. package/dist/esm/registry/registry-keys.schemas.d.ts.map +1 -0
  203. package/dist/esm/registry/registry-keys.schemas.js +68 -0
  204. package/dist/esm/registry/registry-keys.schemas.js.map +1 -0
  205. package/dist/esm/registry/registry-section-schemas.constants.d.ts +25 -3
  206. package/dist/esm/registry/registry-section-schemas.constants.d.ts.map +1 -1
  207. package/dist/esm/release/framework-release.constants.d.ts.map +1 -1
  208. package/dist/esm/release/framework-release.constants.js.map +1 -1
  209. package/dist/esm/schemas/framework-info.schemas.d.ts.map +1 -1
  210. package/dist/esm/schemas/framework-secrets.schemas.d.ts +12 -1
  211. package/dist/esm/schemas/framework-secrets.schemas.d.ts.map +1 -1
  212. package/dist/esm/schemas/framework-secrets.schemas.js +14 -1
  213. package/dist/esm/schemas/framework-secrets.schemas.js.map +1 -1
  214. package/dist/esm/schemas/platform-application-config.schemas.d.ts.map +1 -1
  215. package/dist/esm/schemas/platform-application-secrets.schemas.d.ts.map +1 -1
  216. package/dist/esm/schemas/platform-config.schemas.d.ts.map +1 -1
  217. package/dist/esm/workspace-scope/application-subject-manifest.d.ts.map +1 -1
  218. package/dist/esm/workspace-scope/index.d.ts.map +1 -1
  219. package/dist/esm/workspace-scope/resolve-homes.d.ts.map +1 -1
  220. package/dist/esm/workspace-scope/workspace-homes.schemas.d.ts +17 -14
  221. package/dist/esm/workspace-scope/workspace-homes.schemas.d.ts.map +1 -1
  222. package/dist/esm/workspace-scope/workspace-homes.schemas.js +8 -7
  223. package/dist/esm/workspace-scope/workspace-homes.schemas.js.map +1 -1
  224. package/dist/esm/workspace-scope/workspace-scope.schemas.d.ts +15 -6
  225. package/dist/esm/workspace-scope/workspace-scope.schemas.d.ts.map +1 -1
  226. package/dist/esm/workspace-scope/workspace-scope.schemas.js +23 -9
  227. package/dist/esm/workspace-scope/workspace-scope.schemas.js.map +1 -1
  228. package/package.json +7 -7
  229. package/dist/esm/registry/companion-api.schemas.js +0 -165
  230. package/dist/tsconfig.build.tsbuildinfo +0 -1
@@ -2,10 +2,11 @@ import { createHash } from 'node:crypto';
2
2
  import { existsSync, readFileSync } from 'node:fs';
3
3
  import { resolve as resolvePath } from 'node:path';
4
4
  import { z } from 'zod';
5
- import { FRONTEND_PROVIDER_PUBLIC_CONFIG_KEY, FrontendProviderPublicConfigError, FrontendProvidersBlockSchema, overlayFrontendProviderPublicConfig, } from '@wildo-ai/saas-models';
5
+ import { assertFrontendProvidersServeOnlyDeclaredKeys, assertNoSecretValueInFrontendProviders, FRONTEND_PROVIDER_PUBLIC_CONFIG_KEY, FrontendProviderPublicConfigError, FrontendProvidersBlockSchema, overlayFrontendProviderPublicConfig, resolveProviderConnectionRef, } from '@wildo-ai/saas-models';
6
6
  import { SaasLockfileProvidersSectionSchema, } from '../lockfile/wildo-saas-lock.shared.schemas.js';
7
7
  import { getDeclaredApplicationModuleIds, getServiceBoundApplicationModuleIds, } from './shared/application-modules.utils.js';
8
8
  import { SaasProvidersScopesSchema, SaasProviderScopeSelectionSchema, } from './define-saas-config.js';
9
+ import { resolveProviderBasePackage, selectOptedInProviderAugmentations, describeProviderRefClaimedByMoreThanOneImportPath, readSystemOfRecordFacetModuleSpecifier, } from './provider-companion-discovery.js';
9
10
  export const PROVIDER_RUNTIME_ARTIFACT_AUTOGENERATED_WARNING = 'AUTO-GENERATED FILE. DO NOT EDIT. Regenerate with `wildo config sync`.';
10
11
  export const PROVIDER_RUNTIME_ARTIFACT_GENERATOR = 'wildo provider-runtime-artifact';
11
12
  /**
@@ -86,7 +87,55 @@ const RuntimeProviderModulesArtifactSchema = z.strictObject({
86
87
  moduleIds: z.array(z.string().min(1)).default([]),
87
88
  moduleIdsByService: z.record(z.string(), z.array(z.string().min(1))).default({}),
88
89
  });
90
+ /**
91
+ * The per-service frontend bootstrap map, keyed by frontend service key.
92
+ *
93
+ * ## It was an ANNOTATED interface until 2026-09-12, and the workaround is gone (#356)
94
+ *
95
+ * `FrontendProvidersBlockSchema` transitively references three atoms — `ProviderFrontendCspOriginBucket`,
96
+ * `ProviderFrontendScriptCrossOrigin`, `ProviderFrontendSelectionDelivery` — that `@wildo-ai/saas-models`
97
+ * published from `/public-runtime` ALONE. While this artifact object stayed small TypeScript inlined the
98
+ * shape and nobody noticed; adding one member past the inline threshold made it reach for the NAME and
99
+ * refuse, here and in `saas-backend-lib` at the same time:
100
+ *
101
+ * `TS2742 … cannot be named without a reference to
102
+ * node_modules/@wildo-ai/saas-models/src/external-providers/provider-frontend-surface.shared.schemas`.
103
+ *
104
+ * #330 stopped the expansion with a locally declared interface, deliberately as a workaround: an
105
+ * interface is written BY NAME in the emitted declaration where a type alias expands structurally and
106
+ * takes the unnameable atoms with it. The boundary has since MOVED — the root barrel now exports that
107
+ * module — so the atoms are nameable through the package root and the workaround has nothing left to do.
108
+ *
109
+ * Verified with the probe `package-public-entrypoints.md` prescribes rather than by re-running the
110
+ * source-mapped packages: a consumer importing ONLY `@wildo-ai/saas-models`, deriving a record over
111
+ * `FrontendProvidersBlockSchema`, compiled with `declaration: true`. It names all three atoms through
112
+ * `import("@wildo-ai/saas-models")` and reaches no relative `node_modules` path at all.
113
+ */
89
114
  const FrontendProviderBootstrapsSchema = z.record(z.string().min(1), FrontendProvidersBlockSchema);
115
+ /**
116
+ * One opted-in AUGMENTATION of a provider, as the host's loader needs it (#1672).
117
+ *
118
+ * `operationIds` is recorded so the loader can refuse a package whose installed code delivers a different set
119
+ * from the one `wildo config sync` validated — a stale artifact, or a package upgraded without a resync —
120
+ * instead of admitting operations nobody checked for collisions.
121
+ *
122
+ * `basePackageName` / `basePackageVersion` record which base the augmentation was composed against. Nothing
123
+ * refuses on them here; declaring and enforcing a compatible base range is #1731's, and this is its seam.
124
+ */
125
+ export const RuntimeProviderAugmentationArtifactSchema = z.strictObject({
126
+ packageName: z.string().min(1),
127
+ packageVersion: z.string().min(1),
128
+ runtimeImportPath: z.string().min(1),
129
+ operationIds: z.array(z.string().min(1)).min(1),
130
+ /**
131
+ * Every vendor scope the augmentation's operations declare (#1671) — recorded so the loader can refuse installed code
132
+ * that needs scopes sync never validated, and so a connection asks a person to consent only to what an opted-in
133
+ * package declared. Absent when it declares none.
134
+ */
135
+ requiredScopes: z.array(z.string().min(1)).min(1).optional(),
136
+ basePackageName: z.string().min(1).optional(),
137
+ basePackageVersion: z.string().min(1).optional(),
138
+ });
90
139
  export const SaasRuntimeProvidersArtifactSchema = z.strictObject({
91
140
  __AUTOGENERATED__: z.literal(PROVIDER_RUNTIME_ARTIFACT_AUTOGENERATED_WARNING),
92
141
  generatedBy: z.literal(PROVIDER_RUNTIME_ARTIFACT_GENERATOR),
@@ -106,6 +155,28 @@ export const SaasRuntimeProvidersArtifactSchema = z.strictObject({
106
155
  * without consulting this record, so an un-resynced application is unaffected.
107
156
  */
108
157
  providerRuntimeImports: z.record(z.string().min(1), z.string().min(1)).optional(),
158
+ /**
159
+ * Package specifiers that ship SYSTEM-OF-RECORD VENDOR FACETS, in discovery order (#1057).
160
+ *
161
+ * A list rather than a `vendor -> specifier` map, because a facet module contributes a RECORD of
162
+ * vendors rather than one module per vendor: a map would restate the record's own keys in a
163
+ * generated artifact read by a different process, free to disagree with it. The backend imports
164
+ * each specifier in order and takes the first that answers for the vendor.
165
+ *
166
+ * Discovered from the MANIFEST — a package declaring an `./systems-of-record` export — never from
167
+ * loading it. Sync has no business evaluating a vendor facet, and the manifest is the same door
168
+ * `./companion` is found through.
169
+ */
170
+ systemOfRecordFacetModules: z.array(z.string().min(1)).optional(),
171
+ /**
172
+ * `baseRef` -> the opted-in augmentations the host applies to that provider, sorted by package name (#1672).
173
+ *
174
+ * Only refs in this artifact's scope, and only packages the application names under
175
+ * `providers.augmentations` — an installed augmentation that is not opted in never appears here, and the
176
+ * loader applies nothing this map does not name. Absent when nothing is augmented, which keeps every
177
+ * artifact of an application without augmentations byte-identical to what it was.
178
+ */
179
+ providerRuntimeAugmentations: z.record(z.string().min(1), z.array(RuntimeProviderAugmentationArtifactSchema).min(1)).optional(),
109
180
  providerGraphDigest: z.string().min(1),
110
181
  lockfileSectionDigest: z.string().min(1),
111
182
  artifactKind: z.enum([
@@ -131,19 +202,39 @@ config, options) {
131
202
  const frontendServiceTypes = Object.fromEntries(Object.entries(config.services ?? {})
132
203
  .filter(([, definition]) => definition.frontendType !== undefined)
133
204
  .map(([serviceKey, definition]) => [serviceKey, definition.frontendType]));
205
+ // Backend requests carry public service names; build-time consumers use declaration keys.
206
+ // Validate before publication so two scopes can never silently overwrite one another.
207
+ const frontendServiceNames = {};
208
+ const publicNames = new Set();
209
+ for (const serviceKey of Object.keys(frontendServiceTypes)) {
210
+ const name = config.services[serviceKey]?.serviceName;
211
+ if (!name?.trim() || publicNames.has(name)) {
212
+ throw new Error(`Frontend service "${serviceKey}" needs a unique non-empty public serviceName; received "${name ?? ''}".`);
213
+ }
214
+ publicNames.add(name);
215
+ frontendServiceNames[serviceKey] = name;
216
+ }
134
217
  const discoveryContext = buildProviderRuntimeDiscoveryContext({
135
218
  discoveredContributions: options?.discoveredContributions,
219
+ discoveredAugmentations: selectOptedInProviderAugmentations(config, options?.discoveredAugmentations ?? []),
136
220
  frontendServiceTypes,
221
+ sharedConnections: config.providers.sharedConnections,
222
+ ...(options?.discoveredSystemOfRecordFacetModules !== undefined ? { systemOfRecordFacetModules: options.discoveredSystemOfRecordFacetModules } : {}),
137
223
  });
224
+ const admittedPackages = [...(options?.admittedProviderPackages ?? [])]
225
+ .sort((left, right) => left.packageName.localeCompare(right.packageName));
138
226
  const lockSection = SaasLockfileProvidersSectionSchema.parse({
139
227
  runtimeScopes: materializeLockRuntimeScopes({
140
228
  scopes,
141
229
  discoveryContext,
142
230
  }),
231
+ // Absent when nothing is listed, so the lock of every application without a listing is byte-identical (#1676).
232
+ ...(admittedPackages.length > 0 ? { admittedPackages } : {}),
143
233
  });
144
234
  const artifactMetadata = buildArtifactMetadata({
145
235
  discoveryContext,
146
236
  frontendServiceTypes,
237
+ frontendServiceNames,
147
238
  lockSection,
148
239
  modules,
149
240
  nodeWorkerKeys: options?.nodeWorkerKeys,
@@ -154,6 +245,7 @@ config, options) {
154
245
  artifactMetadata,
155
246
  discoveryContext,
156
247
  frontendServiceTypes,
248
+ frontendServiceNames,
157
249
  generatedAt,
158
250
  modules,
159
251
  nodeWorkerKeys: options?.nodeWorkerKeys,
@@ -194,6 +286,8 @@ export function selectScopedProviderRuntimeArtifact(artifact, scopeKey) {
194
286
  // sibling's packages would tell this host it can load something it never declared.
195
287
  providerRuntimeImports: Object.fromEntries(Object.entries(artifact.providerRuntimeImports ?? {})
196
288
  .filter(([providerRef]) => projectedProviderRefs.includes(providerRef))),
289
+ // Narrowed for the same reason: a host applies augmentations only to the providers IT declares (#1672).
290
+ providerRuntimeAugmentations: narrowRuntimeAugmentations(artifact.providerRuntimeAugmentations, projectedProviderRefs),
197
291
  frontendProviderBootstraps: artifact.frontendProviderBootstraps?.[scopeKey]
198
292
  ? { [scopeKey]: artifact.frontendProviderBootstraps[scopeKey] }
199
293
  : undefined,
@@ -201,6 +295,14 @@ export function selectScopedProviderRuntimeArtifact(artifact, scopeKey) {
201
295
  scopes: undefined,
202
296
  });
203
297
  }
298
+ /**
299
+ * The augmentation map restricted to the given refs, or `undefined` when none remain — so a per-host projection
300
+ * of an artifact that augments only a sibling's provider carries no field at all.
301
+ */
302
+ export function narrowRuntimeAugmentations(augmentations, providerRefs) {
303
+ const narrowed = Object.entries(augmentations ?? {}).filter(([providerRef]) => providerRefs.includes(providerRef));
304
+ return narrowed.length === 0 ? undefined : Object.fromEntries(narrowed);
305
+ }
204
306
  /**
205
307
  * Resolve the absolute path to the canonical
206
308
  * `frontend-services.runtime-providers.generated.json` artifact under
@@ -250,6 +352,15 @@ export function loadMaterializedFrontendProviders(input) {
250
352
  if (!parsedBlock.success) {
251
353
  throw staleGeneratedArtifactError(artifactPath, parsedBlock.error.issues);
252
354
  }
355
+ // The website and documentation builds bake this block into pages served to every visitor (and
356
+ // `wildo dev sync-csp` composes their policy from it), and nothing re-runs the overlay here (#1705).
357
+ // An artifact a sync wrote before a schema was mandatory carries entries with no key list that no gate
358
+ // ever held — so the reader refuses it and names the remedy rather than publishing it. The secret-VALUE
359
+ // screen ran when the artifact was written, by its one writer; a build has no environment secrets.
360
+ assertFrontendProvidersServeOnlyDeclaredKeys({
361
+ producer: `Reading ${artifactPath} for frontend service "${serviceKey}"`,
362
+ providers: parsedBlock.data.providers,
363
+ });
253
364
  return parsedBlock.data;
254
365
  }
255
366
  /**
@@ -438,18 +549,21 @@ function materializeRuntimeArtifacts(input) {
438
549
  const nodeWorkerScopes = scopes.workers
439
550
  ? Object.fromEntries(Object.entries(scopes.workers).filter(([workerKey]) => nodeWorkerKeySet ? nodeWorkerKeySet.has(workerKey) : true))
440
551
  : undefined;
552
+ const backendBootstraps = materializeFrontendProviderBootstraps({
553
+ discoveredContributions: discoveryContext.contributions,
554
+ frontendServiceScopes: scopes.frontendServices ?? {},
555
+ frontendServiceTypes,
556
+ providerConfigurations,
557
+ });
441
558
  return pruneUndefined({
442
559
  backend: materializeRuntimeArtifactFile({
443
560
  artifactKind: 'backend',
444
561
  generatedAt,
445
562
  modules,
446
563
  metadata: artifactMetadata.backend,
447
- frontendProviderBootstraps: materializeFrontendProviderBootstraps({
448
- discoveredContributions: discoveryContext.contributions,
449
- frontendServiceScopes: scopes.frontendServices ?? {},
450
- frontendServiceTypes,
451
- providerConfigurations,
452
- }),
564
+ // Only the HTTP-facing backend map uses public names. Static artifacts below
565
+ // deliberately retain declaration keys for build-time scope selection.
566
+ frontendProviderBootstraps: backendBootstraps && Object.fromEntries(Object.entries(backendBootstraps).map(([serviceKey, block]) => [input.frontendServiceNames[serviceKey], block])),
453
567
  scope: materializeRuntimeScope(scopes.backend ?? { providers: {}, selection: {} }),
454
568
  }),
455
569
  companion: materializeRuntimeArtifactFile({
@@ -502,6 +616,8 @@ function materializeRuntimeArtifactFile(input) {
502
616
  sourceDigest: input.metadata.sourceDigest,
503
617
  providerRefs: input.metadata.providerRefs,
504
618
  providerRuntimeImports: input.metadata.providerRuntimeImports,
619
+ systemOfRecordFacetModules: input.metadata.systemOfRecordFacetModules,
620
+ providerRuntimeAugmentations: input.metadata.providerRuntimeAugmentations,
505
621
  providerGraphDigest: input.metadata.providerGraphDigest,
506
622
  lockfileSectionDigest: input.metadata.lockfileSectionDigest,
507
623
  artifactKind: input.artifactKind,
@@ -562,13 +678,17 @@ function materializeFrontendProviderBootstraps(input) {
562
678
  * function in `saas-models` so they cannot disagree about what crosses.
563
679
  *
564
680
  * The forbidden set is built from the SAME vendor's non-frontend contributions: a frontend provider
565
- * owns no secrets (`secretsContractShape: []` by construction), so the only secrets that could be
566
- * typed into its bag are the backend module's, and those are exactly what this walk has in hand.
681
+ * owns no secrets (`secretsContractShape: []` by construction), so the only secret NAMES that could
682
+ * be typed into its bag are the backend module's, and those are exactly what this walk has in hand.
683
+ *
684
+ * Runs for EVERY entry, supplied or not (#1705): the overlay is also where an entry with no readable
685
+ * key list is refused and where the module's own and any contribution-mapped keys are held to that
686
+ * list. Returning early when nothing was supplied skipped both. Secret VALUES are not compared here —
687
+ * this walk holds no secrets — but by the one publisher of these artifacts before it writes them
688
+ * ({@link assertFrontendProviderBootstrapsCarryNoSecretValue}).
567
689
  */
568
690
  function applyApplicationPublicConfig(input) {
569
691
  const { serviceKey, providerRef, entry, supplied, discoveredContributions } = input;
570
- if (supplied === undefined)
571
- return entry;
572
692
  const forbiddenKeys = new Set(discoveredContributions
573
693
  .filter((contribution) => contribution.ref === providerRef
574
694
  && contribution.runtimeTargets.some((target) => target.kind !== 'frontendService'))
@@ -581,7 +701,7 @@ function applyApplicationPublicConfig(input) {
581
701
  declaredKeys: entry.publicConfigKeys,
582
702
  forbiddenKeys,
583
703
  });
584
- return publicConfig === undefined ? entry : { ...entry, publicConfig };
704
+ return publicConfig === undefined || publicConfig === entry.publicConfig ? entry : { ...entry, publicConfig };
585
705
  }
586
706
  catch (error) {
587
707
  if (error instanceof FrontendProviderPublicConfigError) {
@@ -590,6 +710,35 @@ function applyApplicationPublicConfig(input) {
590
710
  throw error;
591
711
  }
592
712
  }
713
+ /**
714
+ * Refuses a set of materialized provider runtime artifacts when any frontend provider they would
715
+ * SERVE carries one of the environment's secret values (#1705).
716
+ *
717
+ * Walks every `frontendProviderBootstraps` block of every artifact kind — the backend artifact (whose
718
+ * blocks the backend serves on `/application-config` and bakes into its generated module) and the
719
+ * frontend-services artifact (which the website and documentation builds read) — so no served copy is
720
+ * screened while another is not. The comparison itself is the shared
721
+ * `assertNoSecretValueInFrontendProviders`, which the backend runs over what it serves too.
722
+ *
723
+ * Its one caller is the one writer of these artifacts, `wildo config sync`, and it must run BEFORE
724
+ * anything is written: a refused artifact that already reached disk would be picked up by a watcher
725
+ * and served.
726
+ */
727
+ export function assertFrontendProviderBootstrapsCarryNoSecretValue(input) {
728
+ for (const artifact of Object.values(input.artifacts)) {
729
+ for (const [serviceKey, block] of Object.entries(artifact?.frontendProviderBootstraps ?? {})) {
730
+ assertNoSecretValueInFrontendProviders({
731
+ producer: `${input.producer} (${artifact.artifactKind} artifact, frontend service "${serviceKey}")`,
732
+ providers: block.providers,
733
+ secrets: input.secrets,
734
+ });
735
+ }
736
+ }
737
+ }
738
+ /** Whether any materialized artifact would serve a frontend provider at all — the only case that needs secrets to screen. */
739
+ export function materializedArtifactsServeFrontendProviders(artifacts) {
740
+ return Object.values(artifacts).some((artifact) => Object.values(artifact?.frontendProviderBootstraps ?? {}).some((block) => Object.keys(block.providers).length > 0));
741
+ }
593
742
  function buildFrontendProviderBootstrapDigestInput(input) {
594
743
  const bootstraps = materializeFrontendProviderBootstraps(input);
595
744
  if (!bootstraps) {
@@ -599,12 +748,25 @@ function buildFrontendProviderBootstrapDigestInput(input) {
599
748
  serviceKey,
600
749
  Object.fromEntries(Object.entries(block.providers).map(([providerRef, providerEntry]) => [
601
750
  providerRef,
602
- {
603
- metadata: providerEntry.metadata,
751
+ /*
752
+ * The WHOLE served entry, not a hand-picked subset (#1743). This used to name four
753
+ * fields — metadata, capabilities, protocols, publicConfig — and so every field added to
754
+ * the entry later (the CSP footprint, scripts, the SDK descriptor, components, the
755
+ * declared public-config keys, the fronted storage, and now the vendor's compliance
756
+ * profile) changed the SERVED artifact without moving its digest: the exact "old artifact
757
+ * reported as current" the `providerConfigurations` note above exists to prevent, and a
758
+ * processor register reading such an artifact would name yesterday's regions. Spreading
759
+ * the entry makes a new field a digest input by default rather than by someone
760
+ * remembering. The two arrays are still sorted so their authoring order is not a change,
761
+ * and a key present as `undefined` is dropped because the artifact is written as JSON,
762
+ * where it does not exist — two producers that differ only in spelling "absent" must not
763
+ * differ in digest.
764
+ */
765
+ pruneUndefined({
766
+ ...providerEntry,
604
767
  providerCapabilities: [...providerEntry.providerCapabilities].sort(),
605
768
  protocols: [...providerEntry.protocols].sort(),
606
- publicConfig: providerEntry.publicConfig,
607
- },
769
+ }),
608
770
  ])),
609
771
  ]));
610
772
  }
@@ -623,30 +785,35 @@ function materializeLockRuntimeScopes(input) {
623
785
  const { scopes, discoveryContext } = input;
624
786
  return pruneUndefined({
625
787
  backend: scopes.backend
626
- ? materializeLockScope(scopes.backend.providers, discoveryContext.contributions, discoveryContext.backend.matchesRuntimeTarget)
788
+ ? materializeLockScope(scopes.backend.providers, discoveryContext, discoveryContext.backend.matchesRuntimeTarget, discoveryContext.augmentations)
627
789
  : undefined,
628
790
  companion: scopes.companion
629
- ? materializeLockScope(scopes.companion.providers, discoveryContext.contributions, discoveryContext.companion.matchesRuntimeTarget)
791
+ ? materializeLockScope(scopes.companion.providers, discoveryContext, discoveryContext.companion.matchesRuntimeTarget, discoveryContext.augmentations)
630
792
  : undefined,
631
793
  frontendServices: scopes.frontendServices
632
- ? mapRecord(scopes.frontendServices, (scope, serviceKey) => materializeLockScope(scope.providers, discoveryContext.contributions, discoveryContext.frontendServices.matchesRuntimeTarget(serviceKey)))
794
+ ? mapRecord(scopes.frontendServices, (scope, serviceKey) => materializeLockScope(scope.providers, discoveryContext, discoveryContext.frontendServices.matchesRuntimeTarget(serviceKey),
795
+ // A browser facet merges no augmentation (#1672): a browser reaches an augmented operation only through
796
+ // the backend's operation door, so recording one here would describe code this facet never loads.
797
+ []))
633
798
  : undefined,
634
799
  minions: scopes.minions
635
- ? mapRecord(scopes.minions, (scope, minionKey) => materializeLockScope(scope.providers, discoveryContext.contributions, discoveryContext.minions.matchesRuntimeTarget(minionKey)))
800
+ ? mapRecord(scopes.minions, (scope, minionKey) => materializeLockScope(scope.providers, discoveryContext, discoveryContext.minions.matchesRuntimeTarget(minionKey), discoveryContext.augmentations))
636
801
  : undefined,
637
802
  workers: scopes.workers
638
- ? mapRecord(scopes.workers, (scope, workerKey) => materializeLockScope(scope.providers, discoveryContext.contributions, discoveryContext.workers.matchesRuntimeTarget(workerKey)))
803
+ ? mapRecord(scopes.workers, (scope, workerKey) => materializeLockScope(scope.providers, discoveryContext, discoveryContext.workers.matchesRuntimeTarget(workerKey), discoveryContext.augmentations))
639
804
  : undefined,
640
805
  });
641
806
  }
642
- function materializeLockScope(providers, discoveredContributions, matchesRuntimeTarget) {
807
+ function materializeLockScope(providers, discoveryContext, matchesRuntimeTarget, augmentations) {
643
808
  return mapRecord(providers, (selection, ref) => {
644
809
  const matchingContributions = findMatchingDiscoveredContributions({
645
- discoveredContributions,
810
+ discoveredContributions: discoveryContext.contributions,
646
811
  matchesRuntimeTarget,
647
812
  providerRef: ref,
648
813
  });
649
814
  const secretsContractShape = resolveProviderSecretsContractShape(ref, matchingContributions);
815
+ const recordedAugmentations = buildRuntimeAugmentations([ref], matchingContributions, augmentations)[ref];
816
+ const connectionRef = resolveProviderConnectionRef(discoveryContext.sharedConnections, ref);
650
817
  return {
651
818
  ref,
652
819
  digest: digestJson({
@@ -659,6 +826,22 @@ function materializeLockScope(providers, discoveredContributions, matchesRuntime
659
826
  // assurance-control: WILDO.SECRETS.CONTRACT_INTEGRITY — lock drift
660
827
  // covers the values-free provider contract without persisting secret values.
661
828
  secretsContractDigest: digestJson({ ref, secretsContractShape }),
829
+ // Third-party code admitted to this provider's grant (#1672), recorded so a lock diff shows it ARRIVING —
830
+ // and moving: a new package, a new version or a changed operation set each change this entry. Absent
831
+ // when nothing is augmented, and deliberately NOT folded into `secretsContractDigest` (an augmentation
832
+ // changes no secret) or `digest` (which would re-key every provider's lock entry for a field most never carry).
833
+ // The connection whose grant this ref spends (#1725), only when it is ANOTHER ref's: a lock diff then shows a
834
+ // ref joining or leaving a shared connection, while every undeclared ref's entry keeps its bytes.
835
+ ...(connectionRef === ref ? {} : { connectionRef }),
836
+ ...(recordedAugmentations === undefined ? {} : {
837
+ augmentations: recordedAugmentations.map((augmentation) => ({
838
+ packageName: augmentation.packageName,
839
+ packageVersion: augmentation.packageVersion,
840
+ operationIdsDigest: digestJson(augmentation.operationIds),
841
+ // A package that starts asking for a new scope changes what a person is asked to consent to (#1671).
842
+ ...(augmentation.requiredScopes === undefined ? {} : { requiredScopesDigest: digestJson(augmentation.requiredScopes) }),
843
+ })),
844
+ }),
662
845
  };
663
846
  });
664
847
  }
@@ -711,6 +894,9 @@ function buildProviderRuntimeDiscoveryContext(input) {
711
894
  const { frontendServiceTypes } = input;
712
895
  return {
713
896
  contributions,
897
+ sharedConnections: input.sharedConnections,
898
+ augmentations: input.discoveredAugmentations,
899
+ systemOfRecordFacetModules: input.systemOfRecordFacetModules,
714
900
  backend: {
715
901
  matchesRuntimeTarget: (target) => target.kind === 'backend',
716
902
  },
@@ -736,25 +922,45 @@ function buildProviderRuntimeDiscoveryContext(input) {
736
922
  }
737
923
  function buildArtifactMetadata(input) {
738
924
  const { discoveryContext, frontendServiceTypes, lockSection, modules, nodeWorkerKeys, scopes, providerConfigurations } = input;
925
+ const augmentations = discoveryContext.augmentations;
926
+ /*
927
+ * Computed ONCE for every artifact kind, because a vendor facet is not scoped to a runtime the way
928
+ * a provider is: it says what a vendor NEEDS, which does not change between a backend and a
929
+ * minion. Only the backend reads it today (#1055 D2 gives the instance environment to that runtime
930
+ * alone), and recording it everywhere is what keeps that a policy of the RUNTIME rather than a
931
+ * property of the artifact.
932
+ */
933
+ const systemOfRecordFacetModules = discoveryContext.systemOfRecordFacetModules !== undefined
934
+ ? [...discoveryContext.systemOfRecordFacetModules].sort()
935
+ : discoverSystemOfRecordFacetModules(discoveryContext.contributions);
739
936
  const nodeWorkerKeySet = nodeWorkerKeys ? new Set(nodeWorkerKeys) : undefined;
740
937
  return {
741
938
  backend: buildSingleScopeArtifactMetadata({
939
+ runtimeLabel: 'the backend',
940
+ systemOfRecordFacetModules,
941
+ augmentations,
742
942
  modules,
743
943
  providers: scopes.backend?.providers ?? {},
744
944
  matchingContributions: findMatchingDiscoveredContributions({
745
945
  discoveredContributions: discoveryContext.contributions,
746
946
  matchesRuntimeTarget: discoveryContext.backend.matchesRuntimeTarget,
747
947
  }),
748
- extraArtifactState: buildFrontendProviderBootstrapDigestInput({
749
- discoveredContributions: discoveryContext.contributions,
750
- frontendServiceScopes: scopes.frontendServices ?? {},
751
- frontendServiceTypes,
752
- providerConfigurations,
753
- }),
948
+ extraArtifactState: {
949
+ frontendServiceNames: input.frontendServiceNames,
950
+ bootstraps: buildFrontendProviderBootstrapDigestInput({
951
+ discoveredContributions: discoveryContext.contributions,
952
+ frontendServiceScopes: scopes.frontendServices ?? {},
953
+ frontendServiceTypes,
954
+ providerConfigurations,
955
+ }),
956
+ },
754
957
  runtimeLockSection: lockSection.runtimeScopes.backend ?? {},
755
958
  scopes,
756
959
  }),
757
960
  companion: buildSingleScopeArtifactMetadata({
961
+ runtimeLabel: 'the companion',
962
+ systemOfRecordFacetModules,
963
+ augmentations,
758
964
  modules,
759
965
  providers: scopes.companion?.providers ?? {},
760
966
  matchingContributions: findMatchingDiscoveredContributions({
@@ -765,6 +971,16 @@ function buildArtifactMetadata(input) {
765
971
  scopes,
766
972
  }),
767
973
  frontendServices: buildMultiScopeArtifactMetadata({
974
+ runtimeKindLabel: 'frontend service',
975
+ /*
976
+ * Per service only: one ref legitimately has a different browser module per frontend type (posthog is
977
+ * `…-public/app` for the SaaS app and `…-public/website` for the site), and no runtime loads this
978
+ * artifact's merged import map — a browser receives its providers through its bootstrap entries.
979
+ */
980
+ oneImportPathAcrossScopes: false,
981
+ systemOfRecordFacetModules,
982
+ // No augmentation reaches a browser facet — see `materializeLockRuntimeScopes`.
983
+ augmentations: [],
768
984
  keyedProviders: Object.fromEntries(Object.entries(scopes.frontendServices ?? {}).map(([scopeKey, scope]) => [scopeKey, scope.providers])),
769
985
  matchingContributionsByScope: Object.fromEntries(Object.keys(scopes.frontendServices ?? {}).map((scopeKey) => [
770
986
  scopeKey,
@@ -784,6 +1000,11 @@ function buildArtifactMetadata(input) {
784
1000
  scopes,
785
1001
  }),
786
1002
  minions: buildMultiScopeArtifactMetadata({
1003
+ runtimeKindLabel: 'minion',
1004
+ // Every minion reads its ref's path from this one merged map, so two minions may not disagree either.
1005
+ oneImportPathAcrossScopes: true,
1006
+ systemOfRecordFacetModules,
1007
+ augmentations,
787
1008
  keyedProviders: Object.fromEntries(Object.entries(scopes.minions ?? {}).map(([scopeKey, scope]) => [scopeKey, scope.providers])),
788
1009
  matchingContributionsByScope: Object.fromEntries(Object.keys(scopes.minions ?? {}).map((scopeKey) => [
789
1010
  scopeKey,
@@ -797,6 +1018,11 @@ function buildArtifactMetadata(input) {
797
1018
  scopes,
798
1019
  }),
799
1020
  nodeWorkers: buildMultiScopeArtifactMetadata({
1021
+ runtimeKindLabel: 'worker',
1022
+ // Every worker reads its ref's path from this one merged map, so two workers may not disagree either.
1023
+ oneImportPathAcrossScopes: true,
1024
+ systemOfRecordFacetModules,
1025
+ augmentations,
800
1026
  keyedProviders: Object.fromEntries(Object.entries(scopes.workers ?? {})
801
1027
  .filter(([scopeKey]) => nodeWorkerKeySet ? nodeWorkerKeySet.has(scopeKey) : true)
802
1028
  .map(([scopeKey, scope]) => [scopeKey, scope.providers])),
@@ -819,12 +1045,14 @@ function buildArtifactMetadata(input) {
819
1045
  function buildSingleScopeArtifactMetadata(input) {
820
1046
  const providerRefs = Object.keys(input.providers).sort();
821
1047
  const normalizedContributions = normalizeDiscoveredContributionsForDigest(input.matchingContributions);
822
- const providerGraphDigestInput = input.extraArtifactState
1048
+ const providerRuntimeAugmentations = buildRuntimeAugmentations(providerRefs, input.matchingContributions, input.augmentations);
1049
+ const hasAugmentations = Object.keys(providerRuntimeAugmentations).length > 0;
1050
+ const providerGraphDigestInput = withAugmentationsForDigest(input.extraArtifactState
823
1051
  ? {
824
1052
  providerGraph: normalizedContributions,
825
1053
  extraArtifactState: input.extraArtifactState,
826
1054
  }
827
- : normalizedContributions;
1055
+ : normalizedContributions, providerRuntimeAugmentations);
828
1056
  return {
829
1057
  sourceDigest: digestJson({
830
1058
  modules: input.modules,
@@ -832,9 +1060,12 @@ function buildSingleScopeArtifactMetadata(input) {
832
1060
  providerGraph: normalizedContributions,
833
1061
  scopes: input.scopes,
834
1062
  extraArtifactState: input.extraArtifactState,
1063
+ ...(hasAugmentations ? { augmentations: providerRuntimeAugmentations } : {}),
835
1064
  }),
836
1065
  providerRefs,
837
- providerRuntimeImports: buildProviderRuntimeImports(providerRefs, input.matchingContributions),
1066
+ providerRuntimeImports: buildProviderRuntimeImports(providerRefs, input.matchingContributions, input.runtimeLabel),
1067
+ ...(hasAugmentations ? { providerRuntimeAugmentations } : {}),
1068
+ systemOfRecordFacetModules: input.systemOfRecordFacetModules,
838
1069
  providerGraphDigest: digestJson(providerGraphDigestInput),
839
1070
  lockfileSectionDigest: digestJson(input.runtimeLockSection),
840
1071
  };
@@ -845,12 +1076,15 @@ function buildMultiScopeArtifactMetadata(input) {
845
1076
  scopeKey,
846
1077
  normalizeDiscoveredContributionsForDigest(contributions),
847
1078
  ]));
848
- const providerGraphDigestInput = input.extraArtifactState
1079
+ const allMatchingContributions = Object.values(input.matchingContributionsByScope).flat();
1080
+ const providerRuntimeAugmentations = buildRuntimeAugmentations(providerRefs, allMatchingContributions, input.augmentations);
1081
+ const hasAugmentations = Object.keys(providerRuntimeAugmentations).length > 0;
1082
+ const providerGraphDigestInput = withAugmentationsForDigest(input.extraArtifactState
849
1083
  ? {
850
1084
  providerGraphByScope: normalizedContributionsByScope,
851
1085
  extraArtifactState: input.extraArtifactState,
852
1086
  }
853
- : normalizedContributionsByScope;
1087
+ : normalizedContributionsByScope, providerRuntimeAugmentations);
854
1088
  return {
855
1089
  sourceDigest: digestJson({
856
1090
  keyedProviders: input.keyedProviders,
@@ -858,13 +1092,70 @@ function buildMultiScopeArtifactMetadata(input) {
858
1092
  providerGraphByScope: normalizedContributionsByScope,
859
1093
  scopes: input.scopes,
860
1094
  extraArtifactState: input.extraArtifactState,
1095
+ ...(hasAugmentations ? { augmentations: providerRuntimeAugmentations } : {}),
861
1096
  }),
862
1097
  providerRefs,
863
- providerRuntimeImports: buildProviderRuntimeImports(providerRefs, Object.values(input.matchingContributionsByScope).flat()),
1098
+ providerRuntimeImports: buildMultiScopeProviderRuntimeImports(providerRefs, input),
1099
+ ...(hasAugmentations ? { providerRuntimeAugmentations } : {}),
1100
+ systemOfRecordFacetModules: input.systemOfRecordFacetModules,
864
1101
  providerGraphDigest: digestJson(providerGraphDigestInput),
865
1102
  lockfileSectionDigest: digestJson(input.runtimeLockSection),
866
1103
  };
867
1104
  }
1105
+ /**
1106
+ * Which packages ship SYSTEM-OF-RECORD VENDOR FACETS (#1057) — the FALLBACK used when a caller supplies no
1107
+ * walk answer (`discoveredSystemOfRecordFacetModules`).
1108
+ *
1109
+ * Derived from the contributions' package roots, so it is bounded by what the walk's RESULTS contain: a
1110
+ * package that ships facets or facet augmentations and NO provider contribution is not found here. That
1111
+ * package now exists (#1675), which is why discovery answers from its TARGETS
1112
+ * (`DiscoverSaasProviderCompanionContributionsResult.systemOfRecordFacetModules`) and every `wildo` caller
1113
+ * passes that answer. Kept for a caller that builds an artifact from contributions alone (tests, the proofs).
1114
+ *
1115
+ * Sorted, so the artifact does not churn on filesystem order, and de-duplicated because one package root
1116
+ * contributes hundreds of providers and exactly one facet module.
1117
+ */
1118
+ function discoverSystemOfRecordFacetModules(contributions) {
1119
+ const specifiers = new Set();
1120
+ const visitedRoots = new Set();
1121
+ for (const contribution of contributions) {
1122
+ const packageRoot = contribution.owner?.packageRoot;
1123
+ if (packageRoot === undefined || visitedRoots.has(packageRoot))
1124
+ continue;
1125
+ visitedRoots.add(packageRoot);
1126
+ const specifier = readSystemOfRecordFacetModuleSpecifier(packageRoot);
1127
+ if (specifier !== undefined)
1128
+ specifiers.add(specifier);
1129
+ }
1130
+ return [...specifiers].sort();
1131
+ }
1132
+ /**
1133
+ * The merged import map of a multi-scope artifact. Every scope is checked on its own first, so a refusal names the
1134
+ * scope that disagrees with itself; then, where the runtimes load from the merged map, across scopes.
1135
+ */
1136
+ function buildMultiScopeProviderRuntimeImports(providerRefs, input) {
1137
+ for (const [scopeKey, contributions] of Object.entries(input.matchingContributionsByScope).sort(([left], [right]) => left.localeCompare(right))) {
1138
+ buildProviderRuntimeImports(Object.keys(input.keyedProviders[scopeKey] ?? {}), contributions, `${input.runtimeKindLabel} "${scopeKey}"`);
1139
+ }
1140
+ const allMatchingContributions = Object.values(input.matchingContributionsByScope).flat();
1141
+ if (input.oneImportPathAcrossScopes) {
1142
+ return buildProviderRuntimeImports(providerRefs, allMatchingContributions, `every ${input.runtimeKindLabel}`);
1143
+ }
1144
+ /*
1145
+ * Not loaded by any runtime (see the caller), and each scope already has one path per ref: keep the historical
1146
+ * deterministic merge, the sorted-first path per ref, so the artifact does not churn.
1147
+ */
1148
+ const inScope = new Set(providerRefs);
1149
+ const candidatesByRef = new Map();
1150
+ for (const contribution of allMatchingContributions) {
1151
+ if (!inScope.has(contribution.ref))
1152
+ continue;
1153
+ candidatesByRef.set(contribution.ref, [...(candidatesByRef.get(contribution.ref) ?? []), contribution.runtimeImportPath]);
1154
+ }
1155
+ return Object.fromEntries([...candidatesByRef.entries()]
1156
+ .sort(([left], [right]) => left.localeCompare(right))
1157
+ .map(([ref, candidates]) => [ref, [...candidates].sort()[0]]));
1158
+ }
868
1159
  /**
869
1160
  * Project the per-ref runtime import path a host dynamic-imports.
870
1161
  *
@@ -873,13 +1164,15 @@ function buildMultiScopeArtifactMetadata(input) {
873
1164
  * engine's on-demand map, and the single fail-loud refusal in the backend registry names it if that
874
1165
  * map does not hold it either.
875
1166
  *
876
- * When several contributions claim one ref with DIFFERENT import paths, the sorted-first path wins
877
- * — deterministically, so the artifact does not churn. Divergence is possible today only between an
878
- * application's hand-authored engine projection (`@wildo-ai/saas-backend-lib`) and the engine's own
879
- * companion export, and neither is consulted for an engine-shipped ref, so the choice cannot change
880
- * which module a host loads. A package provider is contributed by exactly one package.
1167
+ * When several contributions claim one ref with DIFFERENT import paths, the artifact REFUSES (#2014): the
1168
+ * sorted-first path used to win silently, so a second package contributing a ref the application's own copy
1169
+ * (`@<app>/provider-asana`) also contributes decided which module loaded — the #2014 case was a leftover install of
1170
+ * the since-archived provider catalogue, whose `asana` subpath sorted first.
1171
+ * Discovery validation refuses the same case through the same predicate,
1172
+ * {@link describeProviderRefClaimedByMoreThanOneImportPath}; this is the second site, so an artifact can never
1173
+ * be built from contributions that skipped validation. `runtimeLabel` names the runtime in the refusal.
881
1174
  */
882
- function buildProviderRuntimeImports(providerRefs, contributions) {
1175
+ function buildProviderRuntimeImports(providerRefs, contributions, runtimeLabel) {
883
1176
  const inScope = new Set(providerRefs);
884
1177
  const candidatesByRef = new Map();
885
1178
  for (const contribution of contributions) {
@@ -890,9 +1183,55 @@ function buildProviderRuntimeImports(providerRefs, contributions) {
890
1183
  candidates.add(contribution.runtimeImportPath);
891
1184
  candidatesByRef.set(contribution.ref, candidates);
892
1185
  }
1186
+ const refusals = [...candidatesByRef.keys()]
1187
+ .sort()
1188
+ .map((ref) => describeProviderRefClaimedByMoreThanOneImportPath(ref, runtimeLabel, contributions))
1189
+ .filter((refusal) => refusal !== undefined);
1190
+ if (refusals.length > 0) {
1191
+ throw new Error(`Provider runtime artifact refused:\n- ${refusals.join('\n- ')}`);
1192
+ }
893
1193
  return Object.fromEntries([...candidatesByRef.entries()]
894
1194
  .sort(([left], [right]) => left.localeCompare(right))
895
- .map(([ref, candidates]) => [ref, [...candidates].sort()[0]]));
1195
+ .map(([ref, candidates]) => [ref, [...candidates][0]]));
1196
+ }
1197
+ /**
1198
+ * The opted-in augmentations of the given refs, per ref, sorted by package name (#1672).
1199
+ *
1200
+ * A ref no scope-matched contribution covers gets none: an augmentation applies to a provider the host actually
1201
+ * loads. The base package is read from the base's contribution — its runtime import path's package, and that
1202
+ * package's installed version when discovery walked it — and recorded for #1731; nothing here refuses on it.
1203
+ */
1204
+ function buildRuntimeAugmentations(providerRefs, matchingContributions, augmentations) {
1205
+ const result = {};
1206
+ for (const ref of [...providerRefs].sort()) {
1207
+ const base = [...matchingContributions]
1208
+ .filter((contribution) => contribution.ref === ref)
1209
+ .sort((left, right) => left.runtimeImportPath.localeCompare(right.runtimeImportPath))[0];
1210
+ if (base === undefined)
1211
+ continue;
1212
+ const entries = augmentations
1213
+ .filter((augmentation) => augmentation.augments === ref && augmentation.packageVersion !== undefined)
1214
+ .map((augmentation) => RuntimeProviderAugmentationArtifactSchema.parse({
1215
+ packageName: augmentation.packageName,
1216
+ packageVersion: augmentation.packageVersion,
1217
+ runtimeImportPath: augmentation.runtimeImportPath,
1218
+ operationIds: [...augmentation.operationIds],
1219
+ ...(augmentation.requiredScopes.length === 0 ? {} : { requiredScopes: [...augmentation.requiredScopes] }),
1220
+ ...resolveProviderBasePackage(base),
1221
+ }))
1222
+ .sort((left, right) => left.packageName.localeCompare(right.packageName));
1223
+ if (entries.length > 0)
1224
+ result[ref] = entries;
1225
+ }
1226
+ return result;
1227
+ }
1228
+ /**
1229
+ * Fold augmentations into a provider-graph digest input only when there are some, so the digest of every
1230
+ * artifact that augments nothing is byte-identical to what it was before augmentation existed — a running host
1231
+ * compares these digests, and an unrelated field must not read as drift.
1232
+ */
1233
+ function withAugmentationsForDigest(digestInput, augmentations) {
1234
+ return Object.keys(augmentations).length === 0 ? digestInput : { providerGraph: digestInput, augmentations };
896
1235
  }
897
1236
  function findMatchingDiscoveredContributions(input) {
898
1237
  return input.discoveredContributions.flatMap((contribution) => {