@open-mercato/cli 0.11.1-develop.8589.1.db1a76ea60 → 0.11.1-develop.8665.1.2455b2503c

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 (285) hide show
  1. package/.turbo/turbo-build.log +4 -2
  2. package/AGENTS.md +3 -0
  3. package/dist/agentic/guides/architecture.md +2 -2
  4. package/dist/agentic/guides/extensions.md +7 -2
  5. package/dist/agentic/guides/framework-extension-points.md +1 -0
  6. package/dist/agentic/guides/infrastructure-providers.md +20 -0
  7. package/dist/agentic/guides/integrations.md +2 -2
  8. package/dist/agentic/guides/module-facts.json +2564 -265
  9. package/dist/agentic/guides/module-facts.v2.json +2580 -265
  10. package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
  11. package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
  12. package/dist/agentic/guides/modules/api_docs/index.md +1 -1
  13. package/dist/agentic/guides/modules/api_keys/index.md +1 -1
  14. package/dist/agentic/guides/modules/assisted_selling/acl-features.md +16 -0
  15. package/dist/agentic/guides/modules/assisted_selling/contribution-resolutions.md +21 -0
  16. package/dist/agentic/guides/modules/assisted_selling/domain-commands.md +11 -0
  17. package/dist/agentic/guides/modules/assisted_selling/entities.md +11 -0
  18. package/dist/agentic/guides/modules/assisted_selling/events.md +22 -0
  19. package/dist/agentic/guides/modules/assisted_selling/exact-override-targets.md +17 -0
  20. package/dist/agentic/guides/modules/assisted_selling/index.md +21 -0
  21. package/dist/agentic/guides/modules/assisted_selling/owned-contract-module-metadata.md +11 -0
  22. package/dist/agentic/guides/modules/assisted_selling/setup.md +11 -0
  23. package/dist/agentic/guides/modules/assisted_selling/umes-contributions.md +21 -0
  24. package/dist/agentic/guides/modules/assisted_selling/umes-hosts.md +23 -0
  25. package/dist/agentic/guides/modules/attachments/exact-override-targets.md +1 -1
  26. package/dist/agentic/guides/modules/attachments/index.md +1 -1
  27. package/dist/agentic/guides/modules/attachments/workers.md +1 -1
  28. package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
  29. package/dist/agentic/guides/modules/auth/index.md +1 -1
  30. package/dist/agentic/guides/modules/availability/index.md +1 -1
  31. package/dist/agentic/guides/modules/backups/di-registrations-rich.md +11 -0
  32. package/dist/agentic/guides/modules/backups/di-service-tokens.md +11 -0
  33. package/dist/agentic/guides/modules/backups/exact-override-targets.md +11 -0
  34. package/dist/agentic/guides/modules/backups/index.md +5 -2
  35. package/dist/agentic/guides/modules/business_rules/index.md +1 -1
  36. package/dist/agentic/guides/modules/carrier_inpost/index.md +1 -1
  37. package/dist/agentic/guides/modules/cart/index.md +1 -1
  38. package/dist/agentic/guides/modules/catalog/acl-features.md +2 -1
  39. package/dist/agentic/guides/modules/catalog/active-extension-bindings.md +2 -0
  40. package/dist/agentic/guides/modules/catalog/backend-pages.md +1 -0
  41. package/dist/agentic/guides/modules/catalog/contribution-resolutions.md +5 -0
  42. package/dist/agentic/guides/modules/catalog/di-registrations-rich.md +8 -7
  43. package/dist/agentic/guides/modules/catalog/di-service-tokens.md +5 -4
  44. package/dist/agentic/guides/modules/catalog/domain-commands.md +2 -0
  45. package/dist/agentic/guides/modules/catalog/entities.md +1 -0
  46. package/dist/agentic/guides/modules/catalog/events.md +4 -1
  47. package/dist/agentic/guides/modules/catalog/exact-override-targets.md +13 -7
  48. package/dist/agentic/guides/modules/catalog/index.md +9 -9
  49. package/dist/agentic/guides/modules/catalog/umes-contributions.md +5 -0
  50. package/dist/agentic/guides/modules/catalog/umes-hosts.md +4 -0
  51. package/dist/agentic/guides/modules/catalog/workers.md +1 -0
  52. package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
  53. package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
  54. package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
  55. package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
  56. package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
  57. package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
  58. package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
  59. package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
  60. package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
  61. package/dist/agentic/guides/modules/checkout/index.md +1 -1
  62. package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
  63. package/dist/agentic/guides/modules/configs/index.md +1 -1
  64. package/dist/agentic/guides/modules/content/index.md +1 -1
  65. package/dist/agentic/guides/modules/currencies/index.md +1 -1
  66. package/dist/agentic/guides/modules/customer_accounts/active-extension-bindings.md +1 -1
  67. package/dist/agentic/guides/modules/customer_accounts/exact-override-targets.md +2 -0
  68. package/dist/agentic/guides/modules/customer_accounts/index.md +2 -2
  69. package/dist/agentic/guides/modules/customer_accounts/workers.md +2 -0
  70. package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
  71. package/dist/agentic/guides/modules/customers/active-extension-bindings.md +2 -1
  72. package/dist/agentic/guides/modules/customers/incoming-installed-contributions.md +1 -0
  73. package/dist/agentic/guides/modules/customers/index.md +3 -3
  74. package/dist/agentic/guides/modules/customers/umes-hosts.md +1 -0
  75. package/dist/agentic/guides/modules/dashboards/active-extension-bindings.md +0 -1
  76. package/dist/agentic/guides/modules/dashboards/cli-commands.md +1 -0
  77. package/dist/agentic/guides/modules/dashboards/exact-override-targets.md +1 -0
  78. package/dist/agentic/guides/modules/dashboards/index.md +2 -3
  79. package/dist/agentic/guides/modules/data_sync/index.md +1 -1
  80. package/dist/agentic/guides/modules/design_system/index.md +1 -1
  81. package/dist/agentic/guides/modules/devices/index.md +1 -1
  82. package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
  83. package/dist/agentic/guides/modules/directory/index.md +1 -1
  84. package/dist/agentic/guides/modules/documents/index.md +1 -1
  85. package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
  86. package/dist/agentic/guides/modules/entities/index.md +1 -1
  87. package/dist/agentic/guides/modules/eudr/index.md +1 -1
  88. package/dist/agentic/guides/modules/events/index.md +1 -1
  89. package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
  90. package/dist/agentic/guides/modules/forms/index.md +1 -1
  91. package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
  92. package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
  93. package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
  94. package/dist/agentic/guides/modules/generators/index.md +1 -1
  95. package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
  96. package/dist/agentic/guides/modules/integrations/di-registrations-rich.md +8 -8
  97. package/dist/agentic/guides/modules/integrations/di-service-tokens.md +4 -4
  98. package/dist/agentic/guides/modules/integrations/exact-override-targets.md +14 -12
  99. package/dist/agentic/guides/modules/integrations/index.md +2 -2
  100. package/dist/agentic/guides/modules/integrations/setup.md +1 -1
  101. package/dist/agentic/guides/modules/integrations/workers.md +3 -1
  102. package/dist/agentic/guides/modules/messages/index.md +1 -1
  103. package/dist/agentic/guides/modules/notifications/index.md +1 -1
  104. package/dist/agentic/guides/modules/onboarding/index.md +1 -1
  105. package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
  106. package/dist/agentic/guides/modules/perspectives/index.md +1 -1
  107. package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
  108. package/dist/agentic/guides/modules/planner/index.md +1 -1
  109. package/dist/agentic/guides/modules/portal/index.md +1 -1
  110. package/dist/agentic/guides/modules/progress/index.md +1 -1
  111. package/dist/agentic/guides/modules/promotions/index.md +1 -1
  112. package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
  113. package/dist/agentic/guides/modules/query_index/index.md +1 -1
  114. package/dist/agentic/guides/modules/record_locks/index.md +1 -1
  115. package/dist/agentic/guides/modules/resources/exact-override-targets.md +3 -3
  116. package/dist/agentic/guides/modules/resources/index.md +1 -1
  117. package/dist/agentic/guides/modules/resources/owned-contract-module-metadata.md +1 -1
  118. package/dist/agentic/guides/modules/resources/setup.md +1 -1
  119. package/dist/agentic/guides/modules/sales/contribution-resolutions.md +1 -0
  120. package/dist/agentic/guides/modules/sales/exact-override-targets.md +1 -0
  121. package/dist/agentic/guides/modules/sales/index.md +3 -3
  122. package/dist/agentic/guides/modules/sales/umes-contributions.md +1 -0
  123. package/dist/agentic/guides/modules/scheduler/index.md +1 -1
  124. package/dist/agentic/guides/modules/search/index.md +1 -1
  125. package/dist/agentic/guides/modules/security/index.md +1 -1
  126. package/dist/agentic/guides/modules/seeds/index.md +1 -1
  127. package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
  128. package/dist/agentic/guides/modules/sso/index.md +1 -1
  129. package/dist/agentic/guides/modules/staff/contribution-resolutions.md +1 -1
  130. package/dist/agentic/guides/modules/staff/exact-override-targets.md +1 -1
  131. package/dist/agentic/guides/modules/staff/index.md +1 -1
  132. package/dist/agentic/guides/modules/staff/workers.md +1 -1
  133. package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
  134. package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
  135. package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
  136. package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
  137. package/dist/agentic/guides/modules/telemetry/index.md +1 -1
  138. package/dist/agentic/guides/modules/tillio/index.md +1 -1
  139. package/dist/agentic/guides/modules/translations/index.md +1 -1
  140. package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
  141. package/dist/agentic/guides/modules/webhooks/index.md +1 -1
  142. package/dist/agentic/guides/modules/wms/index.md +1 -1
  143. package/dist/agentic/guides/modules/workflows/index.md +1 -1
  144. package/dist/agentic/guides/reference-module-facts.json +811 -21
  145. package/dist/agentic/guides/reference-modules/example/active-extension-bindings.md +1 -0
  146. package/dist/agentic/guides/reference-modules/example/backend-pages.md +2 -0
  147. package/dist/agentic/guides/reference-modules/example/contribution-resolutions.md +3 -1
  148. package/dist/agentic/guides/reference-modules/example/di-registrations-rich.md +3 -3
  149. package/dist/agentic/guides/reference-modules/example/di-service-tokens.md +1 -1
  150. package/dist/agentic/guides/reference-modules/example/entities.md +2 -0
  151. package/dist/agentic/guides/reference-modules/example/events.md +2 -1
  152. package/dist/agentic/guides/reference-modules/example/exact-override-targets.md +25 -8
  153. package/dist/agentic/guides/reference-modules/example/index.md +7 -7
  154. package/dist/agentic/guides/reference-modules/example/notifications.md +1 -0
  155. package/dist/agentic/guides/reference-modules/example/setup.md +1 -1
  156. package/dist/agentic/guides/reference-modules/example/umes-contributions.md +3 -1
  157. package/dist/agentic/guides/reference-modules/example/umes-hosts.md +4 -0
  158. package/dist/agentic/guides/upstream/AGENTS.md +5 -4
  159. package/dist/agentic/guides/upstream/BACKWARD_COMPATIBILITY.md +37 -20
  160. package/dist/agentic/guides/upstream/manifest.json +3 -3
  161. package/dist/agentic/shared/AGENTS.md.template +11 -15
  162. package/dist/agentic/shared/ai/harness/README.md +4 -2
  163. package/dist/agentic/shared/ai/harness/RELEASE.md +4 -4
  164. package/dist/agentic/shared/ai/harness/cases.json +1420 -41
  165. package/dist/agentic/shared/ai/harness/cases.schema.json +4 -4
  166. package/dist/agentic/shared/ai/harness/design-system-inventory.json +640 -142
  167. package/dist/agentic/shared/ai/harness/source-link-inventory.json +223 -16
  168. package/dist/agentic/shared/ai/harness/validators.json +1 -1
  169. package/dist/agentic/shared/ai/skills/om-system-extension/SKILL.md +1 -1
  170. package/dist/agentic/shared/ai/skills/om-system-extension/references/extension-branches.md +25 -0
  171. package/dist/agentic/shared/ai/skills/om-system-extension/references/mechanism-selector.md +1 -0
  172. package/dist/agentic/shared/ai/skills/om-system-extension/references/unified-overrides.md +2 -0
  173. package/dist/agentic/shared/scripts/run-agent-harness-release.mjs +21 -1
  174. package/dist/lib/cache-provider-manifest.js +9 -0
  175. package/dist/lib/cache-provider-manifest.js.map +7 -0
  176. package/dist/lib/generate-child-process.js +21 -3
  177. package/dist/lib/generate-child-process.js.map +2 -2
  178. package/dist/lib/generate-watch-events.js +135 -19
  179. package/dist/lib/generate-watch-events.js.map +2 -2
  180. package/dist/lib/generate-watch-plan.js +170 -0
  181. package/dist/lib/generate-watch-plan.js.map +7 -0
  182. package/dist/lib/generate-watch-runner.js +54 -0
  183. package/dist/lib/generate-watch-runner.js.map +7 -0
  184. package/dist/lib/generate-watch-structure.js +578 -203
  185. package/dist/lib/generate-watch-structure.js.map +3 -3
  186. package/dist/lib/generators/ast/writers.js +5 -1
  187. package/dist/lib/generators/ast/writers.js.map +2 -2
  188. package/dist/lib/generators/cache-providers.js +80 -0
  189. package/dist/lib/generators/cache-providers.js.map +7 -0
  190. package/dist/lib/generators/extensions/agent-files.js +1 -0
  191. package/dist/lib/generators/extensions/agent-files.js.map +2 -2
  192. package/dist/lib/generators/form-section-ast.js +156 -0
  193. package/dist/lib/generators/form-section-ast.js.map +7 -0
  194. package/dist/lib/generators/form-section-extension-compiler.js +568 -0
  195. package/dist/lib/generators/form-section-extension-compiler.js.map +7 -0
  196. package/dist/lib/generators/form-section-extension-source.js +245 -0
  197. package/dist/lib/generators/form-section-extension-source.js.map +7 -0
  198. package/dist/lib/generators/form-section-runtime-revisions.js +184 -0
  199. package/dist/lib/generators/form-section-runtime-revisions.js.map +7 -0
  200. package/dist/lib/generators/form-sections.js +773 -0
  201. package/dist/lib/generators/form-sections.js.map +7 -0
  202. package/dist/lib/generators/index.js +2 -0
  203. package/dist/lib/generators/index.js.map +2 -2
  204. package/dist/lib/generators/module-entities.js +21 -2
  205. package/dist/lib/generators/module-entities.js.map +2 -2
  206. package/dist/lib/generators/module-extension-facts.js +2 -1
  207. package/dist/lib/generators/module-extension-facts.js.map +2 -2
  208. package/dist/lib/generators/module-facts.js +30 -1
  209. package/dist/lib/generators/module-facts.js.map +2 -2
  210. package/dist/lib/generators/module-override-targets.js +24 -2
  211. package/dist/lib/generators/module-override-targets.js.map +2 -2
  212. package/dist/lib/generators/module-registry.js +223 -194
  213. package/dist/lib/generators/module-registry.js.map +3 -3
  214. package/dist/lib/generators/openapi.js +51 -18
  215. package/dist/lib/generators/openapi.js.map +2 -2
  216. package/dist/lib/generators/web-research-adapters.js +54 -22
  217. package/dist/lib/generators/web-research-adapters.js.map +2 -2
  218. package/dist/lib/in-process-generate-watcher.js +98 -75
  219. package/dist/lib/in-process-generate-watcher.js.map +2 -2
  220. package/dist/lib/post-generate-invalidation.js +20 -1
  221. package/dist/lib/post-generate-invalidation.js.map +2 -2
  222. package/dist/lib/resolver.js +195 -1
  223. package/dist/lib/resolver.js.map +3 -3
  224. package/dist/lib/single-instance-strategy-guard.js +26 -3
  225. package/dist/lib/single-instance-strategy-guard.js.map +2 -2
  226. package/dist/mercato.js +106 -50
  227. package/dist/mercato.js.map +2 -2
  228. package/jest.config.cjs +2 -0
  229. package/package.json +7 -7
  230. package/src/__tests__/mercato.test.ts +18 -0
  231. package/src/__tests__/rotation-json-output.test.ts +52 -0
  232. package/src/lib/__tests__/cache-provider-manifest.test.ts +76 -0
  233. package/src/lib/__tests__/generate-child-process.test.ts +30 -0
  234. package/src/lib/__tests__/generate-watch-events.test.ts +377 -8
  235. package/src/lib/__tests__/generate-watch-plan.test.ts +99 -0
  236. package/src/lib/__tests__/generate-watch-runner.test.ts +138 -0
  237. package/src/lib/__tests__/generate-watch-structure.test.ts +556 -1
  238. package/src/lib/__tests__/in-process-generate-watcher.test.ts +393 -6
  239. package/src/lib/__tests__/module-inspection.test.ts +17 -11
  240. package/src/lib/__tests__/post-generate-invalidation.test.ts +108 -0
  241. package/src/lib/__tests__/resolver.form-section-gates.test.ts +82 -0
  242. package/src/lib/__tests__/single-instance-strategy-guard.test.ts +129 -0
  243. package/src/lib/cache-provider-manifest.ts +8 -0
  244. package/src/lib/generate-child-process.ts +26 -3
  245. package/src/lib/generate-watch-events.ts +189 -17
  246. package/src/lib/generate-watch-plan.ts +180 -0
  247. package/src/lib/generate-watch-runner.ts +63 -0
  248. package/src/lib/generate-watch-structure.ts +670 -227
  249. package/src/lib/generators/__tests__/cache-providers.test.ts +102 -0
  250. package/src/lib/generators/__tests__/derived-crud-route-collisions.test.ts +85 -0
  251. package/src/lib/generators/__tests__/form-section-outbox.test.ts +53 -0
  252. package/src/lib/generators/__tests__/form-sections.test.ts +896 -0
  253. package/src/lib/generators/__tests__/incremental-registry.test.ts +262 -0
  254. package/src/lib/generators/__tests__/module-extension-facts.test.ts +1 -0
  255. package/src/lib/generators/__tests__/module-facts.bc-guard.test.ts +8 -6
  256. package/src/lib/generators/__tests__/module-facts.example-fact-coverage.test.ts +37 -13
  257. package/src/lib/generators/__tests__/module-facts.local-reference.test.ts +13 -0
  258. package/src/lib/generators/__tests__/module-override-targets.test.ts +2 -3
  259. package/src/lib/generators/__tests__/module-subset.test.ts +1 -1
  260. package/src/lib/generators/__tests__/openapi.test.ts +147 -10
  261. package/src/lib/generators/__tests__/structural-contracts.test.ts +2 -2
  262. package/src/lib/generators/__tests__/web-research-adapters.test.ts +298 -87
  263. package/src/lib/generators/ast/writers.ts +6 -1
  264. package/src/lib/generators/cache-providers.ts +111 -0
  265. package/src/lib/generators/extension.ts +2 -0
  266. package/src/lib/generators/extensions/agent-files.ts +1 -0
  267. package/src/lib/generators/form-section-ast.ts +166 -0
  268. package/src/lib/generators/form-section-extension-compiler.ts +632 -0
  269. package/src/lib/generators/form-section-extension-source.ts +308 -0
  270. package/src/lib/generators/form-section-runtime-revisions.ts +211 -0
  271. package/src/lib/generators/form-sections.ts +896 -0
  272. package/src/lib/generators/index.ts +1 -0
  273. package/src/lib/generators/module-entities.ts +22 -4
  274. package/src/lib/generators/module-extension-facts.ts +1 -0
  275. package/src/lib/generators/module-facts.ts +40 -0
  276. package/src/lib/generators/module-override-targets.ts +19 -0
  277. package/src/lib/generators/module-registry.ts +246 -202
  278. package/src/lib/generators/openapi.ts +65 -20
  279. package/src/lib/generators/web-research-adapters.ts +76 -21
  280. package/src/lib/in-process-generate-watcher.ts +151 -96
  281. package/src/lib/post-generate-invalidation.ts +28 -1
  282. package/src/lib/resolver.ts +218 -0
  283. package/src/lib/single-instance-strategy-guard.ts +51 -1
  284. package/src/mercato.ts +117 -57
  285. package/dist/agentic/guides/modules/dashboards/incoming-installed-contributions.md +0 -11
@@ -1,6 +1,13 @@
1
1
  import fs from 'node:fs'
2
2
  import path from 'node:path'
3
3
  import { purgeConfiguredCachePatternsAcrossTenantScopes } from '@open-mercato/shared/lib/cache/maintenance'
4
+ import {
5
+ CacheProviderError,
6
+ isCacheProviderError,
7
+ prepareCacheProviderSelection,
8
+ readSelectedCacheProviderId,
9
+ } from '@open-mercato/shared/lib/cache/providers'
10
+ import { loadCacheProviderManifest } from './cache-provider-manifest'
4
11
 
5
12
  const STRUCTURAL_CACHE_PATTERNS = [
6
13
  'nav:*',
@@ -36,6 +43,26 @@ function touchGeneratedFiles(appDir: string): string[] {
36
43
  return touched
37
44
  }
38
45
 
46
+ /**
47
+ * Purge the structural patterns through the effective cache selection. With a registered
48
+ * provider (`CACHE_PROVIDER`) the generated manifest is loaded and the same provider the app
49
+ * resolves is prepared first; the purge closes its maintenance client itself. Provider
50
+ * failures are reduced to a `CacheProviderError` so driver messages (which may embed
51
+ * endpoints or credentials) never reach the CLI diagnostics.
52
+ */
53
+ async function purgeStructuralCacheEntries(appDir: string): Promise<number> {
54
+ const providerId = readSelectedCacheProviderId(process.env)
55
+ if (!providerId) return purgeConfiguredCachePatternsAcrossTenantScopes(STRUCTURAL_CACHE_PATTERNS)
56
+ try {
57
+ await loadCacheProviderManifest(appDir)
58
+ await prepareCacheProviderSelection()
59
+ return await purgeConfiguredCachePatternsAcrossTenantScopes(STRUCTURAL_CACHE_PATTERNS)
60
+ } catch (error) {
61
+ if (isCacheProviderError(error)) throw error
62
+ throw new CacheProviderError('unavailable', 'Cache provider structural purge failed', { cause: error })
63
+ }
64
+ }
65
+
39
66
  export async function runPostGenerateStructuralInvalidation(
40
67
  appDir: string,
41
68
  ): Promise<PostGenerateStructuralInvalidationResult> {
@@ -51,7 +78,7 @@ export async function runPostGenerateStructuralInvalidation(
51
78
  }
52
79
 
53
80
  try {
54
- cacheEntriesDeleted = await purgeConfiguredCachePatternsAcrossTenantScopes(STRUCTURAL_CACHE_PATTERNS)
81
+ cacheEntriesDeleted = await purgeStructuralCacheEntries(appDir)
55
82
  } catch (error) {
56
83
  cacheError = error
57
84
  }
@@ -1,3 +1,4 @@
1
+ import type { FormSectionOverridesMap, FormSectionOverride } from '@open-mercato/shared/modules/overrides'
1
2
  import path from 'node:path'
2
3
  import fs from 'node:fs'
3
4
  import ts from 'typescript-js'
@@ -29,6 +30,7 @@ export type ModuleEntry = {
29
30
  locator?: string
30
31
  packageName?: string
31
32
  devSupervisorRequiresFullBootstrap?: boolean
33
+ formSectionOverrides?: Readonly<FormSectionOverridesMap>
32
34
  }
33
35
 
34
36
  export type PackageInfo = {
@@ -74,13 +76,91 @@ function pkgRootFor(rootDir: string, from?: string, isMonorepo = true, appDir =
74
76
  return resolveInstalledPackageRootWithRequire(packageName, appDir) ?? path.join(rootDir, 'node_modules', packageName)
75
77
  }
76
78
 
79
+ function staticFormSectionOverrides(expression: ts.Expression): FormSectionOverridesMap | undefined {
80
+ const initializers = new Map<string, ts.Expression>()
81
+ for (const statement of expression.getSourceFile().statements) {
82
+ if (!ts.isVariableStatement(statement) || !(statement.declarationList.flags & ts.NodeFlags.Const)) continue
83
+ for (const declaration of statement.declarationList.declarations) {
84
+ if (ts.isIdentifier(declaration.name) && declaration.initializer) initializers.set(declaration.name.text, declaration.initializer)
85
+ }
86
+ }
87
+ function unwrap(value: ts.Expression): ts.Expression {
88
+ const visited = new Set<string>()
89
+ while (true) {
90
+ if (ts.isAsExpression(value) || ts.isSatisfiesExpression(value) || ts.isParenthesizedExpression(value)) {
91
+ value = value.expression
92
+ continue
93
+ }
94
+ if (!ts.isIdentifier(value) || visited.has(value.text)) return value
95
+ const resolved = initializers.get(value.text)
96
+ if (!resolved) return value
97
+ visited.add(value.text)
98
+ value = resolved
99
+ }
100
+ }
101
+ function fields(value: ts.Expression | undefined, visited: ReadonlySet<ts.Expression> = new Set()): Map<string, ts.Expression> {
102
+ if (!value) return new Map()
103
+ const node = unwrap(value)
104
+ if (!ts.isObjectLiteralExpression(node) || visited.has(node)) return new Map()
105
+ const next = new Set([...visited, node])
106
+ const output = new Map<string, ts.Expression>()
107
+ for (const property of node.properties) {
108
+ if (ts.isSpreadAssignment(property)) for (const [key, entry] of fields(property.expression, next)) output.set(key, entry)
109
+ else if (ts.isShorthandPropertyAssignment(property)) output.set(property.name.text, property.name)
110
+ else if (ts.isPropertyAssignment(property) && (ts.isIdentifier(property.name) || ts.isStringLiteralLike(property.name))) {
111
+ output.set(property.name.text, property.initializer)
112
+ }
113
+ }
114
+ return output
115
+ }
116
+ const entries = fields(fields(fields(expression).get('forms')).get('sections'))
117
+ const result = new Map<string, FormSectionOverride | null>()
118
+ function text(input: ts.Expression | undefined): string | undefined {
119
+ const node = input ? unwrap(input) : undefined
120
+ return node && ts.isStringLiteralLike(node) ? node.text : undefined
121
+ }
122
+ for (const [key, value] of entries) {
123
+ if (unwrap(value).kind === ts.SyntaxKind.NullKeyword) {
124
+ result.set(key, null)
125
+ continue
126
+ }
127
+ const options = fields(value)
128
+ const operation = text(options.get('operation'))
129
+ const contributionId = text(options.get('contributionId'))
130
+ if (!contributionId || (operation !== 'add' && operation !== 'hide' && operation !== 'replace')) continue
131
+ if (operation !== 'add') {
132
+ result.set(key, { operation, contributionId })
133
+ continue
134
+ }
135
+ const placement = fields(options.get('placement'))
136
+ const rawPosition = placement.get('position')
137
+ const positionNode = rawPosition ? unwrap(rawPosition) : undefined
138
+ const position = positionNode && ts.isPropertyAccessExpression(positionNode)
139
+ && ts.isIdentifier(positionNode.expression) && positionNode.expression.text === 'InjectionPosition'
140
+ && ['First', 'Last', 'Before', 'After'].includes(positionNode.name.text)
141
+ ? positionNode.name.text.toLowerCase() : text(rawPosition)
142
+ const relativeTo = text(placement.get('relativeTo'))
143
+ const allowed: ReadonlySet<string> = new Set(['first', 'last', 'before', 'after'])
144
+ if (placement.size && (!position || !allowed.has(position))) continue
145
+ result.set(key, { operation, contributionId, ...(position ? {
146
+ placement: { position: position as NonNullable<Extract<FormSectionOverride, { operation: 'add' }>['placement']>['position'], relativeTo },
147
+ } : {}) })
148
+ }
149
+ return result.size ? Object.fromEntries(result) : undefined
150
+ }
151
+
77
152
  function parseModuleEntryFromObjectLiteral(node: ts.ObjectLiteralExpression): ModuleEntry | null {
78
153
  let id: string | null = null
79
154
  let from: string | null = null
80
155
  let locator: string | undefined
81
156
  let packageName: string | undefined
82
157
  let devSupervisorRequiresFullBootstrap = false
158
+ let formSectionOverrides: FormSectionOverridesMap | undefined
83
159
  for (const property of node.properties) {
160
+ if (ts.isShorthandPropertyAssignment(property) && property.name.text === 'overrides') {
161
+ formSectionOverrides = staticFormSectionOverrides(property.name)
162
+ continue
163
+ }
84
164
  if (!ts.isPropertyAssignment(property)) continue
85
165
  const key = ts.isIdentifier(property.name) || ts.isStringLiteralLike(property.name)
86
166
  ? property.name.text
@@ -98,6 +178,7 @@ function parseModuleEntryFromObjectLiteral(node: ts.ObjectLiteralExpression): Mo
98
178
  locator = property.initializer.text
99
179
  }
100
180
  if (key === 'overrides') {
181
+ formSectionOverrides = staticFormSectionOverrides(property.initializer)
101
182
  if (!ts.isObjectLiteralExpression(property.initializer)) {
102
183
  devSupervisorRequiresFullBootstrap = true
103
184
  continue
@@ -125,6 +206,7 @@ function parseModuleEntryFromObjectLiteral(node: ts.ObjectLiteralExpression): Mo
125
206
  ...(locator ? { locator } : {}),
126
207
  ...(packageName ? { packageName } : {}),
127
208
  ...(devSupervisorRequiresFullBootstrap ? { devSupervisorRequiresFullBootstrap: true } : {}),
209
+ ...(formSectionOverrides ? { formSectionOverrides } : {}),
128
210
  }
129
211
  }
130
212
 
@@ -289,10 +371,146 @@ function collectPushEntriesFromStatement(
289
371
  })
290
372
  }
291
373
 
374
+ function validateFormSectionGates(sourceFile: ts.SourceFile, targetVariableName: string): void {
375
+ const initializers = new Map<string, ts.Expression>()
376
+ for (const statement of sourceFile.statements) {
377
+ if (!ts.isVariableStatement(statement)) continue
378
+ for (const declaration of statement.declarationList.declarations) {
379
+ const initializer = declaration.initializer
380
+ if (!initializer) continue
381
+ function mapBinding(binding: ts.BindingName, value: ts.Expression): void {
382
+ if (ts.isIdentifier(binding)) initializers.set(binding.text, value)
383
+ else for (const element of binding.elements) if (ts.isBindingElement(element)) mapBinding(element.name, value)
384
+ }
385
+ mapBinding(declaration.name, initializer)
386
+ }
387
+ }
388
+
389
+ function serverEnvironmentReads(expression: ts.Expression): string[] {
390
+ const found = new Set<string>()
391
+ const seen = new Set<string>()
392
+ function visit(node: ts.Node): void {
393
+ if (ts.isIdentifier(node) && !seen.has(node.text)) {
394
+ seen.add(node.text)
395
+ const initializer = initializers.get(node.text)
396
+ if (initializer && node.text !== targetVariableName) visit(initializer)
397
+ }
398
+ if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression)
399
+ && node.expression.text === 'process' && node.name.text === 'env') {
400
+ found.add('<dynamic process.env>')
401
+ return
402
+ }
403
+ if (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) {
404
+ const target = node.expression
405
+ if (ts.isPropertyAccessExpression(target) && target.name.text === 'env'
406
+ && ts.isIdentifier(target.expression) && target.expression.text === 'process') {
407
+ const environmentKey = ts.isPropertyAccessExpression(node) ? node.name.text
408
+ : ts.isStringLiteralLike(node.argumentExpression) ? node.argumentExpression.text : '<dynamic process.env>'
409
+ if (!environmentKey.startsWith('NEXT_PUBLIC_')) found.add(environmentKey)
410
+ return
411
+ }
412
+ }
413
+ ts.forEachChild(node, visit)
414
+ }
415
+ visit(expression)
416
+ return [...found].sort((left, right) => left < right ? -1 : left > right ? 1 : 0)
417
+ }
418
+
419
+ function assertGates(gates: readonly ts.Expression[]): void {
420
+ const serverKeys = [...new Set(gates.flatMap(serverEnvironmentReads))].sort((left, right) => left < right ? -1 : left > right ? 1 : 0)
421
+ if (serverKeys.length) {
422
+ throw new Error(`[resolver] forms.sections in src/modules.ts requires browser-visible module gating; server-only: ${serverKeys.join(', ')}`)
423
+ }
424
+ }
425
+
426
+ function inspectOverride(
427
+ node: ts.Expression,
428
+ keys: readonly string[],
429
+ gates: readonly ts.Expression[],
430
+ seen: ReadonlySet<string> = new Set(),
431
+ ): void {
432
+ if (ts.isParenthesizedExpression(node) || ts.isSatisfiesExpression(node) || ts.isAsExpression(node)) {
433
+ inspectOverride(node.expression, keys, gates, seen)
434
+ } else if (ts.isConditionalExpression(node)) {
435
+ inspectOverride(node.whenTrue, keys, [...gates, node.condition], seen)
436
+ inspectOverride(node.whenFalse, keys, [...gates, node.condition], seen)
437
+ } else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken) {
438
+ inspectOverride(node.right, keys, [...gates, node.left], seen)
439
+ } else if (ts.isIdentifier(node) && !seen.has(node.text) && initializers.has(node.text)) {
440
+ const initializer = initializers.get(node.text)
441
+ if (initializer) inspectOverride(initializer, keys, gates, new Set([...seen, node.text]))
442
+ } else if (!keys.length) {
443
+ assertGates([...gates, node])
444
+ } else if (ts.isObjectLiteralExpression(node)) {
445
+ for (const property of node.properties) {
446
+ if (ts.isSpreadAssignment(property)) inspectOverride(property.expression, keys, gates, seen)
447
+ if (ts.isShorthandPropertyAssignment(property) && property.name.text === keys[0]) {
448
+ inspectOverride(property.name, keys.slice(1), gates, seen)
449
+ }
450
+ if (ts.isPropertyAssignment(property)
451
+ && (ts.isIdentifier(property.name) || ts.isStringLiteralLike(property.name))
452
+ && property.name.text === keys[0]) {
453
+ inspectOverride(property.initializer, keys.slice(1), gates, seen)
454
+ }
455
+ }
456
+ }
457
+ }
458
+
459
+ function inspectModules(node: ts.Node, gates: readonly ts.Expression[], seen: ReadonlySet<string> = new Set()): void {
460
+ if (ts.isIdentifier(node) && !seen.has(node.text)) {
461
+ const initializer = initializers.get(node.text)
462
+ if (initializer && node.text !== targetVariableName) inspectModules(initializer, gates, new Set([...seen, node.text]))
463
+ } else if (ts.isObjectLiteralExpression(node)) {
464
+ inspectOverride(node, ['overrides', 'forms', 'sections'], gates)
465
+ } else if (ts.isConditionalExpression(node)) {
466
+ inspectModules(node.whenTrue, [...gates, node.condition], seen)
467
+ inspectModules(node.whenFalse, [...gates, node.condition], seen)
468
+ } else {
469
+ ts.forEachChild(node, (child) => inspectModules(child, gates, seen))
470
+ }
471
+ }
472
+
473
+ function inspectStatement(statement: ts.Statement, gates: readonly ts.Expression[]): void {
474
+ if (ts.isBlock(statement)) {
475
+ for (const child of statement.statements) inspectStatement(child, gates)
476
+ return
477
+ }
478
+ if (ts.isIfStatement(statement)) {
479
+ const branchGates = [...gates, statement.expression]
480
+ inspectStatement(statement.thenStatement, branchGates)
481
+ if (statement.elseStatement) inspectStatement(statement.elseStatement, branchGates)
482
+ return
483
+ }
484
+ if (ts.isExpressionStatement(statement)) inspectPush(statement.expression, gates)
485
+ }
486
+
487
+ function inspectPush(node: ts.Expression, gates: readonly ts.Expression[]): void {
488
+ if (ts.isParenthesizedExpression(node)) inspectPush(node.expression, gates)
489
+ if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken) {
490
+ inspectPush(node.right, [...gates, node.left])
491
+ }
492
+ if (ts.isConditionalExpression(node)) {
493
+ inspectPush(node.whenTrue, [...gates, node.condition])
494
+ inspectPush(node.whenFalse, [...gates, node.condition])
495
+ }
496
+ if (!ts.isCallExpression(node)) return
497
+ const { expression, arguments: entries } = node
498
+ if (ts.isPropertyAccessExpression(expression) && expression.name.text === 'push'
499
+ && ts.isIdentifier(expression.expression) && expression.expression.text === targetVariableName) {
500
+ for (const entry of entries) inspectModules(entry, gates)
501
+ }
502
+ }
503
+
504
+ const enabled = initializers.get(targetVariableName)
505
+ if (enabled) inspectModules(enabled, [])
506
+ for (const statement of sourceFile.statements) inspectStatement(statement, [])
507
+ }
508
+
292
509
  function parseModulesFromSource(source: string, env: NodeJS.ProcessEnv = process.env): ModuleEntry[] {
293
510
  const sourceFile = ts.createSourceFile('modules.ts', source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS)
294
511
  const modules: ModuleEntry[] = []
295
512
  const variableName = 'enabledModules'
513
+ validateFormSectionGates(sourceFile, variableName)
296
514
  const scope = new Map<string, unknown>()
297
515
  let foundDeclaration = false
298
516
 
@@ -43,12 +43,26 @@ export type SingleInstanceGuardResult = {
43
43
  overridden: boolean
44
44
  }
45
45
 
46
+ export type InfraCacheProviderSnapshot = {
47
+ id: string
48
+ placement: 'local' | 'shared'
49
+ }
50
+
46
51
  export type InfraStrategySnapshot = {
47
52
  cacheStrategy: string
48
53
  queueStrategy: string
49
54
  rateLimitStrategy: string
55
+ /**
56
+ * Effective registered cache provider (`CACHE_PROVIDER`). When present it wins over
57
+ * `cacheStrategy`: the cache is multi-instance safe only when the provider's
58
+ * resolved placement is `shared`.
59
+ */
60
+ cacheProvider?: InfraCacheProviderSnapshot | null
50
61
  }
51
62
 
63
+ const CACHE_PROVIDER_ENV_VAR = 'CACHE_PROVIDER'
64
+ const CACHE_PROVIDER_SAFE_VALUES: readonly string[] = ['a provider with shared placement']
65
+
52
66
  const COMPONENT_ENV_VARS: Record<SingleInstanceGuardComponent, string> = {
53
67
  cache: 'CACHE_STRATEGY',
54
68
  queue: 'QUEUE_STRATEGY',
@@ -78,14 +92,39 @@ export class SingleInstanceStrategyError extends Error {
78
92
  * because the guard's safe-set policy — not the resolver default — decides what
79
93
  * counts as single-instance.
80
94
  */
81
- export function readInfraStrategySnapshot(env: NodeJS.ProcessEnv = process.env): InfraStrategySnapshot {
95
+ export function readInfraStrategySnapshot(
96
+ env: NodeJS.ProcessEnv = process.env,
97
+ options?: { cacheProvider?: InfraCacheProviderSnapshot | null },
98
+ ): InfraStrategySnapshot {
82
99
  return {
83
100
  cacheStrategy: env.CACHE_STRATEGY?.trim() || 'memory',
84
101
  queueStrategy: resolveQueueStrategy(),
85
102
  rateLimitStrategy: env.RATE_LIMIT_STRATEGY?.trim() || 'memory',
103
+ ...(options?.cacheProvider ? { cacheProvider: options.cacheProvider } : {}),
86
104
  }
87
105
  }
88
106
 
107
+ /**
108
+ * Resolve the effective registered cache provider for the guard. Stock deployments
109
+ * (no `CACHE_PROVIDER`) return null without loading the app's provider manifest. When a
110
+ * provider is selected the generated manifest is loaded and the selection is prepared
111
+ * exactly as the app bootstrap would, so a missing or invalid provider aborts the start
112
+ * instead of being judged by the legacy `CACHE_STRATEGY` value.
113
+ */
114
+ export async function resolveEffectiveCacheProviderSnapshot(
115
+ appDir: string,
116
+ env: NodeJS.ProcessEnv = process.env,
117
+ ): Promise<InfraCacheProviderSnapshot | null> {
118
+ const { readSelectedCacheProviderId, prepareCacheProviderSelection } = await import(
119
+ '@open-mercato/shared/lib/cache/providers'
120
+ )
121
+ if (!readSelectedCacheProviderId(env)) return null
122
+ const { loadCacheProviderManifest } = await import('./cache-provider-manifest')
123
+ await loadCacheProviderManifest(appDir)
124
+ const provider = await prepareCacheProviderSelection({ env })
125
+ return provider ? { id: provider.id, placement: provider.placement } : null
126
+ }
127
+
89
128
  function resolveMultiInstanceHint(env: NodeJS.ProcessEnv): boolean {
90
129
  if (parseBooleanWithDefault(env.OM_MULTI_INSTANCE, false)) return true
91
130
  const instanceCount = Number.parseInt(env.OM_INSTANCE_COUNT ?? '', 10)
@@ -104,6 +143,17 @@ export function evaluateSingleInstanceGuard(
104
143
 
105
144
  const offenders: SingleInstanceGuardOffender[] = []
106
145
  for (const component of Object.keys(configured) as SingleInstanceGuardComponent[]) {
146
+ if (component === 'cache' && snapshot.cacheProvider) {
147
+ if (snapshot.cacheProvider.placement !== 'shared') {
148
+ offenders.push({
149
+ component,
150
+ envVar: CACHE_PROVIDER_ENV_VAR,
151
+ configured: snapshot.cacheProvider.id,
152
+ safeValues: CACHE_PROVIDER_SAFE_VALUES,
153
+ })
154
+ }
155
+ continue
156
+ }
107
157
  const safeValues: readonly string[] = MULTI_INSTANCE_SAFE_STRATEGIES[component]
108
158
  if (!safeValues.includes(configured[component])) {
109
159
  offenders.push({