@open-mercato/cli 0.11.1-develop.8593.1.50784dae35 → 0.11.1-develop.8687.1.adb16f62b3

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 (327) hide show
  1. package/.turbo/turbo-build.log +6 -2
  2. package/AGENTS.md +2 -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 +11067 -7122
  9. package/dist/agentic/guides/module-facts.v2.json +11055 -7094
  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/exact-override-targets.md +1 -1
  63. package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
  64. package/dist/agentic/guides/modules/communication_channels/workers.md +1 -1
  65. package/dist/agentic/guides/modules/configs/index.md +1 -1
  66. package/dist/agentic/guides/modules/content/index.md +1 -1
  67. package/dist/agentic/guides/modules/currencies/active-extension-bindings.md +11 -0
  68. package/dist/agentic/guides/modules/currencies/di-registrations-rich.md +1 -1
  69. package/dist/agentic/guides/modules/currencies/di-service-tokens.md +1 -1
  70. package/dist/agentic/guides/modules/currencies/exact-override-targets.md +1 -1
  71. package/dist/agentic/guides/modules/currencies/index.md +3 -2
  72. package/dist/agentic/guides/modules/customer_accounts/active-extension-bindings.md +1 -1
  73. package/dist/agentic/guides/modules/customer_accounts/exact-override-targets.md +2 -0
  74. package/dist/agentic/guides/modules/customer_accounts/index.md +2 -2
  75. package/dist/agentic/guides/modules/customer_accounts/workers.md +2 -0
  76. package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
  77. package/dist/agentic/guides/modules/customers/active-extension-bindings.md +2 -1
  78. package/dist/agentic/guides/modules/customers/incoming-installed-contributions.md +1 -0
  79. package/dist/agentic/guides/modules/customers/index.md +3 -3
  80. package/dist/agentic/guides/modules/customers/umes-hosts.md +1 -0
  81. package/dist/agentic/guides/modules/dashboards/active-extension-bindings.md +0 -1
  82. package/dist/agentic/guides/modules/dashboards/cli-commands.md +1 -0
  83. package/dist/agentic/guides/modules/dashboards/exact-override-targets.md +1 -0
  84. package/dist/agentic/guides/modules/dashboards/index.md +2 -3
  85. package/dist/agentic/guides/modules/data_sync/index.md +1 -1
  86. package/dist/agentic/guides/modules/design_system/index.md +1 -1
  87. package/dist/agentic/guides/modules/devices/index.md +1 -1
  88. package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
  89. package/dist/agentic/guides/modules/directory/index.md +1 -1
  90. package/dist/agentic/guides/modules/documents/index.md +1 -1
  91. package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
  92. package/dist/agentic/guides/modules/entities/index.md +1 -1
  93. package/dist/agentic/guides/modules/eudr/index.md +1 -1
  94. package/dist/agentic/guides/modules/events/index.md +1 -1
  95. package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
  96. package/dist/agentic/guides/modules/forms/index.md +1 -1
  97. package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
  98. package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
  99. package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
  100. package/dist/agentic/guides/modules/generators/index.md +1 -1
  101. package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
  102. package/dist/agentic/guides/modules/integrations/di-registrations-rich.md +8 -8
  103. package/dist/agentic/guides/modules/integrations/di-service-tokens.md +4 -4
  104. package/dist/agentic/guides/modules/integrations/exact-override-targets.md +14 -12
  105. package/dist/agentic/guides/modules/integrations/index.md +2 -2
  106. package/dist/agentic/guides/modules/integrations/setup.md +1 -1
  107. package/dist/agentic/guides/modules/integrations/workers.md +3 -1
  108. package/dist/agentic/guides/modules/ledger/acl-features.md +16 -0
  109. package/dist/agentic/guides/modules/ledger/active-extension-bindings.md +11 -0
  110. package/dist/agentic/guides/modules/ledger/backend-pages.md +21 -0
  111. package/dist/agentic/guides/modules/ledger/domain-commands.md +22 -0
  112. package/dist/agentic/guides/modules/ledger/encryption.md +11 -0
  113. package/dist/agentic/guides/modules/ledger/entities.md +17 -0
  114. package/dist/agentic/guides/modules/ledger/events.md +19 -0
  115. package/dist/agentic/guides/modules/ledger/exact-override-targets.md +30 -0
  116. package/dist/agentic/guides/modules/ledger/index.md +22 -0
  117. package/dist/agentic/guides/modules/ledger/owned-contract-module-metadata.md +11 -0
  118. package/dist/agentic/guides/modules/ledger/setup.md +11 -0
  119. package/dist/agentic/guides/modules/ledger/umes-hosts.md +26 -0
  120. package/dist/agentic/guides/modules/messages/index.md +1 -1
  121. package/dist/agentic/guides/modules/notifications/index.md +1 -1
  122. package/dist/agentic/guides/modules/onboarding/index.md +1 -1
  123. package/dist/agentic/guides/modules/payment_gateways/active-extension-bindings.md +1 -1
  124. package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
  125. package/dist/agentic/guides/modules/perspectives/index.md +1 -1
  126. package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
  127. package/dist/agentic/guides/modules/planner/index.md +1 -1
  128. package/dist/agentic/guides/modules/portal/index.md +1 -1
  129. package/dist/agentic/guides/modules/progress/index.md +1 -1
  130. package/dist/agentic/guides/modules/promotions/index.md +1 -1
  131. package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
  132. package/dist/agentic/guides/modules/query_index/index.md +1 -1
  133. package/dist/agentic/guides/modules/record_locks/index.md +1 -1
  134. package/dist/agentic/guides/modules/resources/exact-override-targets.md +3 -3
  135. package/dist/agentic/guides/modules/resources/index.md +1 -1
  136. package/dist/agentic/guides/modules/resources/owned-contract-module-metadata.md +1 -1
  137. package/dist/agentic/guides/modules/resources/setup.md +1 -1
  138. package/dist/agentic/guides/modules/sales/contribution-resolutions.md +1 -0
  139. package/dist/agentic/guides/modules/sales/exact-override-targets.md +1 -0
  140. package/dist/agentic/guides/modules/sales/index.md +3 -3
  141. package/dist/agentic/guides/modules/sales/umes-contributions.md +1 -0
  142. package/dist/agentic/guides/modules/scheduler/index.md +1 -1
  143. package/dist/agentic/guides/modules/search/index.md +1 -1
  144. package/dist/agentic/guides/modules/security/index.md +1 -1
  145. package/dist/agentic/guides/modules/seeds/index.md +1 -1
  146. package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
  147. package/dist/agentic/guides/modules/sso/index.md +1 -1
  148. package/dist/agentic/guides/modules/staff/contribution-resolutions.md +1 -1
  149. package/dist/agentic/guides/modules/staff/exact-override-targets.md +1 -1
  150. package/dist/agentic/guides/modules/staff/index.md +1 -1
  151. package/dist/agentic/guides/modules/staff/workers.md +1 -1
  152. package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
  153. package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
  154. package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
  155. package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
  156. package/dist/agentic/guides/modules/telemetry/index.md +1 -1
  157. package/dist/agentic/guides/modules/tillio/index.md +1 -1
  158. package/dist/agentic/guides/modules/translations/index.md +1 -1
  159. package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
  160. package/dist/agentic/guides/modules/webhooks/index.md +1 -1
  161. package/dist/agentic/guides/modules/wms/index.md +1 -1
  162. package/dist/agentic/guides/modules/workflows/index.md +1 -1
  163. package/dist/agentic/guides/reference-module-facts.json +811 -21
  164. package/dist/agentic/guides/reference-modules/example/active-extension-bindings.md +1 -0
  165. package/dist/agentic/guides/reference-modules/example/backend-pages.md +2 -0
  166. package/dist/agentic/guides/reference-modules/example/contribution-resolutions.md +3 -1
  167. package/dist/agentic/guides/reference-modules/example/di-registrations-rich.md +3 -3
  168. package/dist/agentic/guides/reference-modules/example/di-service-tokens.md +1 -1
  169. package/dist/agentic/guides/reference-modules/example/entities.md +2 -0
  170. package/dist/agentic/guides/reference-modules/example/events.md +2 -1
  171. package/dist/agentic/guides/reference-modules/example/exact-override-targets.md +25 -8
  172. package/dist/agentic/guides/reference-modules/example/index.md +7 -7
  173. package/dist/agentic/guides/reference-modules/example/notifications.md +1 -0
  174. package/dist/agentic/guides/reference-modules/example/setup.md +1 -1
  175. package/dist/agentic/guides/reference-modules/example/umes-contributions.md +3 -1
  176. package/dist/agentic/guides/reference-modules/example/umes-hosts.md +4 -0
  177. package/dist/agentic/guides/upstream/AGENTS.md +5 -4
  178. package/dist/agentic/guides/upstream/BACKWARD_COMPATIBILITY.md +37 -20
  179. package/dist/agentic/guides/upstream/manifest.json +3 -3
  180. package/dist/agentic/shared/AGENTS.md.template +12 -16
  181. package/dist/agentic/shared/ai/harness/README.md +4 -2
  182. package/dist/agentic/shared/ai/harness/RELEASE.md +4 -4
  183. package/dist/agentic/shared/ai/harness/cases.json +1420 -41
  184. package/dist/agentic/shared/ai/harness/cases.schema.json +4 -4
  185. package/dist/agentic/shared/ai/harness/design-system-inventory.json +640 -142
  186. package/dist/agentic/shared/ai/harness/source-link-inventory.json +223 -16
  187. package/dist/agentic/shared/ai/harness/validators.json +1 -1
  188. package/dist/agentic/shared/ai/skills/om-system-extension/SKILL.md +1 -1
  189. package/dist/agentic/shared/ai/skills/om-system-extension/references/extension-branches.md +25 -0
  190. package/dist/agentic/shared/ai/skills/om-system-extension/references/mechanism-selector.md +1 -0
  191. package/dist/agentic/shared/ai/skills/om-system-extension/references/unified-overrides.md +2 -0
  192. package/dist/agentic/shared/scripts/run-agent-harness-release.mjs +21 -1
  193. package/dist/lib/cache-provider-manifest.js +9 -0
  194. package/dist/lib/cache-provider-manifest.js.map +7 -0
  195. package/dist/lib/generate-watch-plan.js +4 -0
  196. package/dist/lib/generate-watch-plan.js.map +2 -2
  197. package/dist/lib/generate-watch-runner.js +1 -0
  198. package/dist/lib/generate-watch-runner.js.map +2 -2
  199. package/dist/lib/generate-watch-structure.js +2 -0
  200. package/dist/lib/generate-watch-structure.js.map +2 -2
  201. package/dist/lib/generators/ast/writers.js +5 -1
  202. package/dist/lib/generators/ast/writers.js.map +2 -2
  203. package/dist/lib/generators/cache-providers.js +80 -0
  204. package/dist/lib/generators/cache-providers.js.map +7 -0
  205. package/dist/lib/generators/form-section-ast.js +156 -0
  206. package/dist/lib/generators/form-section-ast.js.map +7 -0
  207. package/dist/lib/generators/form-section-extension-compiler.js +568 -0
  208. package/dist/lib/generators/form-section-extension-compiler.js.map +7 -0
  209. package/dist/lib/generators/form-section-extension-source.js +245 -0
  210. package/dist/lib/generators/form-section-extension-source.js.map +7 -0
  211. package/dist/lib/generators/form-section-runtime-revisions.js +184 -0
  212. package/dist/lib/generators/form-section-runtime-revisions.js.map +7 -0
  213. package/dist/lib/generators/form-sections.js +773 -0
  214. package/dist/lib/generators/form-sections.js.map +7 -0
  215. package/dist/lib/generators/index.js +2 -0
  216. package/dist/lib/generators/index.js.map +2 -2
  217. package/dist/lib/generators/module-entities.js +21 -2
  218. package/dist/lib/generators/module-entities.js.map +2 -2
  219. package/dist/lib/generators/module-extension-facts.js +2 -1
  220. package/dist/lib/generators/module-extension-facts.js.map +2 -2
  221. package/dist/lib/generators/module-facts.js +30 -1
  222. package/dist/lib/generators/module-facts.js.map +2 -2
  223. package/dist/lib/generators/module-override-targets.js +24 -2
  224. package/dist/lib/generators/module-override-targets.js.map +2 -2
  225. package/dist/lib/generators/module-registry.js +75 -3
  226. package/dist/lib/generators/module-registry.js.map +2 -2
  227. package/dist/lib/generators/openapi.js +27 -17
  228. package/dist/lib/generators/openapi.js.map +2 -2
  229. package/dist/lib/post-generate-invalidation.js +20 -1
  230. package/dist/lib/post-generate-invalidation.js.map +2 -2
  231. package/dist/lib/resolver.js +195 -1
  232. package/dist/lib/resolver.js.map +3 -3
  233. package/dist/lib/scaffold/field-dsl.js +393 -0
  234. package/dist/lib/scaffold/field-dsl.js.map +7 -0
  235. package/dist/lib/scaffold/index.js +412 -0
  236. package/dist/lib/scaffold/index.js.map +7 -0
  237. package/dist/lib/scaffold/targets.js +42 -0
  238. package/dist/lib/scaffold/targets.js.map +7 -0
  239. package/dist/lib/scaffold/templates/create-page.js +52 -0
  240. package/dist/lib/scaffold/templates/create-page.js.map +7 -0
  241. package/dist/lib/scaffold/templates/detail-page.js +186 -0
  242. package/dist/lib/scaffold/templates/detail-page.js.map +7 -0
  243. package/dist/lib/scaffold/templates/form-config.js +42 -0
  244. package/dist/lib/scaffold/templates/form-config.js.map +7 -0
  245. package/dist/lib/scaffold/templates/index.js +27 -0
  246. package/dist/lib/scaffold/templates/index.js.map +7 -0
  247. package/dist/lib/scaffold/templates/list-page.js +190 -0
  248. package/dist/lib/scaffold/templates/list-page.js.map +7 -0
  249. package/dist/lib/scaffold/templates/metas.js +47 -0
  250. package/dist/lib/scaffold/templates/metas.js.map +7 -0
  251. package/dist/lib/scaffold/templates/module-files.js +85 -0
  252. package/dist/lib/scaffold/templates/module-files.js.map +7 -0
  253. package/dist/lib/single-instance-strategy-guard.js +26 -3
  254. package/dist/lib/single-instance-strategy-guard.js.map +2 -2
  255. package/dist/lib/testing/integration-discovery.js +32 -3
  256. package/dist/lib/testing/integration-discovery.js.map +2 -2
  257. package/dist/lib/testing/integration.js +232 -8
  258. package/dist/lib/testing/integration.js.map +2 -2
  259. package/dist/mercato.js +40 -7
  260. package/dist/mercato.js.map +2 -2
  261. package/jest.config.cjs +2 -0
  262. package/package.json +7 -7
  263. package/src/__tests__/mercato.test.ts +18 -0
  264. package/src/__tests__/rotation-json-output.test.ts +52 -0
  265. package/src/lib/__tests__/agentic-workflows-ownership.test.ts +79 -0
  266. package/src/lib/__tests__/cache-provider-manifest.test.ts +76 -0
  267. package/src/lib/__tests__/generate-watch-plan.test.ts +3 -2
  268. package/src/lib/__tests__/generate-watch-runner.test.ts +13 -1
  269. package/src/lib/__tests__/generate-watch-structure.test.ts +34 -0
  270. package/src/lib/__tests__/post-generate-invalidation.test.ts +108 -0
  271. package/src/lib/__tests__/resolver.form-section-gates.test.ts +82 -0
  272. package/src/lib/__tests__/single-instance-strategy-guard.test.ts +129 -0
  273. package/src/lib/cache-provider-manifest.ts +8 -0
  274. package/src/lib/generate-watch-plan.ts +6 -3
  275. package/src/lib/generate-watch-runner.ts +1 -0
  276. package/src/lib/generate-watch-structure.ts +5 -1
  277. package/src/lib/generators/__tests__/cache-providers.test.ts +102 -0
  278. package/src/lib/generators/__tests__/derived-crud-route-collisions.test.ts +85 -0
  279. package/src/lib/generators/__tests__/form-section-outbox.test.ts +53 -0
  280. package/src/lib/generators/__tests__/form-sections.test.ts +896 -0
  281. package/src/lib/generators/__tests__/module-extension-facts.test.ts +1 -0
  282. package/src/lib/generators/__tests__/module-facts.bc-guard.test.ts +8 -6
  283. package/src/lib/generators/__tests__/module-facts.example-fact-coverage.test.ts +37 -13
  284. package/src/lib/generators/__tests__/module-facts.local-reference.test.ts +13 -0
  285. package/src/lib/generators/__tests__/module-override-targets.test.ts +2 -3
  286. package/src/lib/generators/__tests__/module-subset.test.ts +1 -1
  287. package/src/lib/generators/__tests__/openapi.test.ts +60 -13
  288. package/src/lib/generators/__tests__/structural-contracts.test.ts +2 -2
  289. package/src/lib/generators/ast/writers.ts +6 -1
  290. package/src/lib/generators/cache-providers.ts +111 -0
  291. package/src/lib/generators/form-section-ast.ts +166 -0
  292. package/src/lib/generators/form-section-extension-compiler.ts +632 -0
  293. package/src/lib/generators/form-section-extension-source.ts +308 -0
  294. package/src/lib/generators/form-section-runtime-revisions.ts +211 -0
  295. package/src/lib/generators/form-sections.ts +896 -0
  296. package/src/lib/generators/index.ts +1 -0
  297. package/src/lib/generators/module-entities.ts +22 -4
  298. package/src/lib/generators/module-extension-facts.ts +1 -0
  299. package/src/lib/generators/module-facts.ts +40 -0
  300. package/src/lib/generators/module-override-targets.ts +19 -0
  301. package/src/lib/generators/module-registry.ts +80 -4
  302. package/src/lib/generators/openapi.ts +31 -20
  303. package/src/lib/post-generate-invalidation.ts +28 -1
  304. package/src/lib/resolver.ts +218 -0
  305. package/src/lib/scaffold/__tests__/__snapshots__/scaffold-golden.test.ts.snap +1742 -0
  306. package/src/lib/scaffold/__tests__/helpers.ts +75 -0
  307. package/src/lib/scaffold/__tests__/scaffold-ds-contract.test.ts +248 -0
  308. package/src/lib/scaffold/__tests__/scaffold-golden.test.ts +267 -0
  309. package/src/lib/scaffold/__tests__/scaffold-runtime.test.tsx +193 -0
  310. package/src/lib/scaffold/field-dsl.ts +491 -0
  311. package/src/lib/scaffold/index.ts +531 -0
  312. package/src/lib/scaffold/targets.ts +68 -0
  313. package/src/lib/scaffold/templates/create-page.ts +52 -0
  314. package/src/lib/scaffold/templates/detail-page.ts +190 -0
  315. package/src/lib/scaffold/templates/form-config.ts +42 -0
  316. package/src/lib/scaffold/templates/index.ts +27 -0
  317. package/src/lib/scaffold/templates/list-page.ts +190 -0
  318. package/src/lib/scaffold/templates/metas.ts +48 -0
  319. package/src/lib/scaffold/templates/module-files.ts +87 -0
  320. package/src/lib/single-instance-strategy-guard.ts +51 -1
  321. package/src/lib/testing/__tests__/integration-app-only-playwright.test.ts +225 -0
  322. package/src/lib/testing/__tests__/integration-app-only.test.ts +320 -0
  323. package/src/lib/testing/__tests__/integration-discovery.test.ts +45 -1
  324. package/src/lib/testing/integration-discovery.ts +32 -2
  325. package/src/lib/testing/integration.ts +293 -11
  326. package/src/mercato.ts +39 -5
  327. package/dist/agentic/guides/modules/dashboards/incoming-installed-contributions.md +0 -11
@@ -0,0 +1,190 @@
1
+ /**
2
+ * Detail page template (lineage: om-ds-guardian page-templates.md §Detail Page,
3
+ * upgraded to the shipped primitives: FormHeader mode="detail" + Tabs
4
+ * variant="underline", optimistic locking via initialValues.updatedAt).
5
+ *
6
+ * Deliberately stays on public primitives — the customers module's
7
+ * DetailTabsLayout is module-internal and MUST NOT be copied here.
8
+ */
9
+ export const detailPageTemplate = `"use client"
10
+
11
+ import * as React from 'react'
12
+ import { useRouter } from 'next/navigation'
13
+ import { Page, PageBody } from '@open-mercato/ui/backend/Page'
14
+ import { CrudForm } from '@open-mercato/ui/backend/CrudForm'
15
+ import { FormHeader } from '@open-mercato/ui/backend/forms/FormHeader'
16
+ import { Tabs, TabsContent, TabsList, TabsTrigger } from '@open-mercato/ui/primitives/tabs'
17
+ import { LoadingMessage, ErrorMessage } from '@open-mercato/ui/backend/detail'
18
+ import { apiCall, withScopedApiRequestHeaders } from '@open-mercato/ui/backend/utils/apiCall'
19
+ import { updateCrud, deleteCrud } from '@open-mercato/ui/backend/utils/crud'
20
+ import { buildOptimisticLockHeader } from '@open-mercato/ui/backend/utils/optimisticLock'
21
+ import { useGuardedMutation } from '@open-mercato/ui/backend/injection/useGuardedMutation'
22
+ import { flash } from '@open-mercato/ui/backend/FlashMessages'
23
+ import { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'
24
+ import { useT } from '@open-mercato/shared/lib/i18n/context'
25
+ import { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'
26
+ import { {{entityCamel}}UpdateSchema, type {{entityPascal}}UpdateInput } from '../../../data/validators'
27
+ {{statusImports}}import {
28
+ {{entityUpperSnake}}_ENTITY_ID,
29
+ create{{entityPascal}}FormFields,
30
+ create{{entityPascal}}FormGroups,
31
+ } from '../../../components/formConfig'
32
+
33
+ type {{entityPascal}}Record = {
34
+ id: string
35
+ updatedAt?: string | null
36
+ {{rowTypeFields}}
37
+ }
38
+
39
+ type {{entityPascal}}ListResponse = {
40
+ items: {{entityPascal}}Record[]
41
+ }
42
+
43
+ export default function {{entityPascal}}DetailPage({ params }: { params?: { id?: string } }) {
44
+ const t = useT()
45
+ const router = useRouter()
46
+ const id = typeof params?.id === 'string' ? params.id : null
47
+ const { confirm, ConfirmDialogElement } = useConfirmDialog()
48
+ const { runMutation, retryLastMutation } = useGuardedMutation({ contextId: '{{moduleId}}.detail' })
49
+ const [record, setRecord] = React.useState<{{entityPascal}}Record | null>(null)
50
+ const [isLoading, setIsLoading] = React.useState(true)
51
+ const [loadError, setLoadError] = React.useState<string | null>(null)
52
+ const [reloadToken, setReloadToken] = React.useState(0)
53
+
54
+ React.useEffect(() => {
55
+ let cancelled = false
56
+ async function load() {
57
+ if (!id) {
58
+ setLoadError(t('{{moduleId}}.detail.notFound', '{{entityTitle}} not found'))
59
+ setIsLoading(false)
60
+ return
61
+ }
62
+ setIsLoading(true)
63
+ setLoadError(null)
64
+ try {
65
+ const query = new URLSearchParams({ ids: id, pageSize: '1' })
66
+ const call = await apiCall<{{entityPascal}}ListResponse>('/api/{{moduleId}}?' + query.toString())
67
+ if (cancelled) return
68
+ if (!call.ok) {
69
+ setLoadError(t('{{moduleId}}.detail.loadError', 'Failed to load {{entityLower}}'))
70
+ return
71
+ }
72
+ const item = call.result?.items?.[0] ?? null
73
+ if (!item) {
74
+ setLoadError(t('{{moduleId}}.detail.notFound', '{{entityTitle}} not found'))
75
+ return
76
+ }
77
+ setRecord(item)
78
+ } catch (error) {
79
+ if (cancelled) return
80
+ getTelemetryRuntime()?.reportError(error, { module: '{{moduleId}}', code: '{{moduleId}}.detail_load_failed' })
81
+ setLoadError(t('{{moduleId}}.detail.loadError', 'Failed to load {{entityLower}}'))
82
+ } finally {
83
+ if (!cancelled) setIsLoading(false)
84
+ }
85
+ }
86
+ void load()
87
+ return () => { cancelled = true }
88
+ }, [id, reloadToken, t])
89
+
90
+ const fields = React.useMemo(() => create{{entityPascal}}FormFields(t), [t])
91
+ const groups = React.useMemo(() => create{{entityPascal}}FormGroups(t), [t])
92
+
93
+ // updatedAt MUST stay in initialValues: CrudForm auto-derives the
94
+ // x-om-ext-optimistic-lock-expected-updated-at header from it on submit AND delete.
95
+ const initialValues = React.useMemo<Partial<{{entityPascal}}UpdateInput> | undefined>(() => {
96
+ if (!record) return undefined
97
+ return {
98
+ id: record.id,
99
+ updatedAt: record.updatedAt ?? undefined,
100
+ {{initialValueLines}}
101
+ }
102
+ }, [record])
103
+
104
+ const handleDelete = React.useCallback(async () => {
105
+ if (!record) return
106
+ const confirmed = await confirm({
107
+ title: t('{{moduleId}}.delete.confirmTitle', 'Delete {{entityLower}}?'),
108
+ description: t('{{moduleId}}.delete.confirmDescription', 'This action cannot be undone.'),
109
+ variant: 'destructive',
110
+ })
111
+ if (!confirmed) return
112
+ try {
113
+ await runMutation({
114
+ operation: () =>
115
+ withScopedApiRequestHeaders(
116
+ buildOptimisticLockHeader(record.updatedAt ?? undefined),
117
+ () => deleteCrud('{{moduleId}}', record.id),
118
+ ),
119
+ context: {
120
+ formId: '{{moduleId}}.detail',
121
+ resourceKind: '{{moduleId}}.{{entitySnake}}',
122
+ resourceId: record.id,
123
+ retryLastMutation,
124
+ },
125
+ mutationPayload: { id: record.id },
126
+ })
127
+ flash(t('{{moduleId}}.delete.success', '{{entityTitle}} deleted'), 'success')
128
+ router.push('/backend/{{moduleId}}')
129
+ } catch {
130
+ flash(t('{{moduleId}}.delete.error', 'Failed to delete {{entityLower}}'), 'error')
131
+ }
132
+ }, [confirm, record, retryLastMutation, router, runMutation, t])
133
+
134
+ if (isLoading) {
135
+ return (
136
+ <Page>
137
+ <PageBody>
138
+ <LoadingMessage label={t('{{moduleId}}.detail.loading', 'Loading {{entityLower}}')} />
139
+ </PageBody>
140
+ </Page>
141
+ )
142
+ }
143
+
144
+ if (loadError || !record) {
145
+ return (
146
+ <Page>
147
+ <PageBody>
148
+ <ErrorMessage label={loadError ?? t('{{moduleId}}.detail.notFound', '{{entityTitle}} not found')} />
149
+ </PageBody>
150
+ </Page>
151
+ )
152
+ }
153
+
154
+ return (
155
+ <Page>
156
+ <PageBody>
157
+ <FormHeader
158
+ mode="detail"
159
+ backHref="/backend/{{moduleId}}"
160
+ title={{{detailTitleExpr}}}
161
+ {{statusBadgeProp}} onDelete={() => { void handleDelete() }}
162
+ deleteLabel={t('{{moduleId}}.detail.actions.delete', 'Delete')}
163
+ />
164
+ <Tabs defaultValue="overview" variant="underline" className="mt-4">
165
+ <TabsList aria-label={t('{{moduleId}}.detail.tabs.label', '{{entityTitle}} sections')}>
166
+ <TabsTrigger value="overview">{t('{{moduleId}}.detail.tabs.overview', 'Overview')}</TabsTrigger>
167
+ {/* Extension point: add related-entity tabs here (activity, attachments, ...). */}
168
+ </TabsList>
169
+ <TabsContent value="overview">
170
+ <CrudForm<{{entityPascal}}UpdateInput>
171
+ schema={{{entityCamel}}UpdateSchema}
172
+ fields={fields}
173
+ groups={groups}
174
+ initialValues={initialValues}
175
+ entityIds={[{{entityUpperSnake}}_ENTITY_ID]}
176
+ submitLabel={t('{{moduleId}}.form.submit', 'Save')}
177
+ onSubmit={async (values) => {
178
+ await updateCrud('{{moduleId}}', values)
179
+ flash(t('{{moduleId}}.detail.updateSuccess', '{{entityTitle}} updated'), 'success')
180
+ setReloadToken((token) => token + 1)
181
+ }}
182
+ />
183
+ </TabsContent>
184
+ </Tabs>
185
+ </PageBody>
186
+ {ConfirmDialogElement}
187
+ </Page>
188
+ )
189
+ }
190
+ `
@@ -0,0 +1,42 @@
1
+ /**
2
+ * components/formConfig.ts template (customers formConfig pattern: zod schema +
3
+ * CrudField[] + groups from one place so create/detail can never disagree).
4
+ */
5
+ export const formConfigTemplate = `import { z } from 'zod'
6
+ import type { CrudField, CrudFormGroup } from '@open-mercato/ui/backend/CrudForm'
7
+ import type { TranslateFn } from '@open-mercato/shared/lib/i18n/context'
8
+ import { {{entityCamel}}CreateSchema } from '../data/validators'
9
+
10
+ /** Entity id used to load custom-field sets once the module declares \`ce.ts\`. */
11
+ export const {{entityUpperSnake}}_ENTITY_ID = '{{moduleId}}:{{entitySnake}}'
12
+
13
+ export type {{entityPascal}}FormValues = z.infer<typeof {{entityCamel}}CreateSchema>
14
+
15
+ export function create{{entityPascal}}FormSchema() {
16
+ return {{entityCamel}}CreateSchema
17
+ }
18
+
19
+ export function create{{entityPascal}}FormFields(t: TranslateFn): CrudField[] {
20
+ return [
21
+ {{crudFields}}
22
+ ]
23
+ }
24
+
25
+ export function create{{entityPascal}}FormGroups(t: TranslateFn): CrudFormGroup[] {
26
+ return [
27
+ {
28
+ id: 'details',
29
+ title: t('{{moduleId}}.form.groups.details', 'Details'),
30
+ column: 1,
31
+ fields: [{{fieldIdList}}],
32
+ },
33
+ // Custom-field sets registered for {{entityUpperSnake}}_ENTITY_ID render here.
34
+ {
35
+ id: 'attributes',
36
+ title: t('{{moduleId}}.form.groups.attributes', 'Attributes'),
37
+ column: 2,
38
+ kind: 'customFields',
39
+ },
40
+ ]
41
+ }
42
+ `
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Executable template source of truth for `mercato module scaffold --with-ui`
3
+ * (spec: .ai/specs/2026-07-05-ds-module-ui-scaffold.md §Template source of truth).
4
+ *
5
+ * Templates are embedded as TypeScript string constants (not loose `.tpl`
6
+ * assets) because `packages/cli/build.mjs` bundles `src/**\/*.ts` only — this
7
+ * way the templates ship inside the published `@open-mercato/cli` dist with no
8
+ * extra copy step, and standalone apps get byte-identical templates versioned
9
+ * with the CLI. Interpolation is `{{placeholder}}` substitution only — no
10
+ * template engine (see `renderTemplate` in `../index.ts`).
11
+ *
12
+ * These templates are pinned by `__tests__/scaffold-golden.test.ts` (golden
13
+ * files) and `__tests__/scaffold-ds-contract.test.ts` (DS lint + guardian
14
+ * checklist): a template edit can never ship invisibly.
15
+ */
16
+ export { listPageTemplate } from './list-page'
17
+ export { createPageTemplate } from './create-page'
18
+ export { detailPageTemplate } from './detail-page'
19
+ export { listMetaTemplate, createMetaTemplate, detailMetaTemplate } from './metas'
20
+ export { formConfigTemplate } from './form-config'
21
+ export {
22
+ validatorsTemplate,
23
+ statusMapTemplate,
24
+ aclTemplate,
25
+ setupTemplate,
26
+ moduleIndexTemplate,
27
+ } from './module-files'
@@ -0,0 +1,190 @@
1
+ /**
2
+ * List page template (lineage: om-ds-guardian page-templates.md §List Page,
3
+ * trimmed from packages/core/src/modules/customers/backend/customers/people/page.tsx).
4
+ */
5
+ export const listPageTemplate = `"use client"
6
+
7
+ import * as React from 'react'
8
+ import Link from 'next/link'
9
+ import { useRouter } from 'next/navigation'
10
+ import { Page, PageBody } from '@open-mercato/ui/backend/Page'
11
+ import { DataTable, type DataTableExportFormat } from '@open-mercato/ui/backend/DataTable'
12
+ import type { LegacyColumnDef as ColumnDef } from '@tanstack/react-table/legacy'
13
+ import { Button } from '@open-mercato/ui/primitives/button'
14
+ import { EmptyState } from '@open-mercato/ui/primitives/empty-state'
15
+ import { RowActions } from '@open-mercato/ui/backend/RowActions'
16
+ import { apiCall, withScopedApiRequestHeaders } from '@open-mercato/ui/backend/utils/apiCall'
17
+ import { buildCrudExportUrl, deleteCrud } from '@open-mercato/ui/backend/utils/crud'
18
+ import { buildOptimisticLockHeader } from '@open-mercato/ui/backend/utils/optimisticLock'
19
+ import { useGuardedMutation } from '@open-mercato/ui/backend/injection/useGuardedMutation'
20
+ import { flash } from '@open-mercato/ui/backend/FlashMessages'
21
+ import { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'
22
+ import { useT } from '@open-mercato/shared/lib/i18n/context'
23
+ import { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'
24
+ {{dateImport}}{{filterTypeImport}}{{statusImports}}
25
+ type {{entityPascal}}Row = {
26
+ id: string
27
+ updatedAt?: string | null
28
+ {{rowTypeFields}}
29
+ }
30
+
31
+ type {{entityPascal}}ListResponse = {
32
+ items: {{entityPascal}}Row[]
33
+ total: number
34
+ totalPages: number
35
+ totalIsCapped?: boolean
36
+ }
37
+
38
+ // DS guardrail: keep pageSize at or below 100.
39
+ const PAGE_SIZE = 25
40
+
41
+ export default function {{entityPascal}}ListPage() {
42
+ const t = useT()
43
+ const router = useRouter()
44
+ const { confirm, ConfirmDialogElement } = useConfirmDialog()
45
+ const { runMutation, retryLastMutation } = useGuardedMutation({ contextId: '{{moduleId}}.list' })
46
+ const [rows, setRows] = React.useState<{{entityPascal}}Row[]>([])
47
+ const [isLoading, setIsLoading] = React.useState(true)
48
+ const [loadError, setLoadError] = React.useState<string | null>(null)
49
+ const [page, setPage] = React.useState(1)
50
+ const [total, setTotal] = React.useState(0)
51
+ const [totalPages, setTotalPages] = React.useState(1)
52
+ const [totalIsCapped, setTotalIsCapped] = React.useState(false)
53
+ const [search, setSearch] = React.useState('')
54
+ {{filterStateLine}} const [reloadToken, setReloadToken] = React.useState(0)
55
+
56
+ const listParams = React.useMemo(() => {
57
+ const params: Record<string, string | number> = { page, pageSize: PAGE_SIZE }
58
+ if (search) params.search = search
59
+ {{filterParamLines}} return params
60
+ }, {{listParamsDeps}})
61
+
62
+ React.useEffect(() => {
63
+ let cancelled = false
64
+ async function load() {
65
+ setIsLoading(true)
66
+ setLoadError(null)
67
+ try {
68
+ const query = new URLSearchParams()
69
+ for (const [key, value] of Object.entries(listParams)) query.set(key, String(value))
70
+ const fallback: {{entityPascal}}ListResponse = { items: [], total: 0, totalPages: 1 }
71
+ const call = await apiCall<{{entityPascal}}ListResponse>('/api/{{moduleId}}?' + query.toString(), undefined, { fallback })
72
+ if (cancelled) return
73
+ if (!call.ok) {
74
+ setLoadError(t('{{moduleId}}.list.loadError', 'Failed to load {{moduleTitleLower}}'))
75
+ flash(t('{{moduleId}}.list.loadError', 'Failed to load {{moduleTitleLower}}'), 'error')
76
+ return
77
+ }
78
+ const result = call.result ?? fallback
79
+ setRows(result.items)
80
+ setTotal(result.total)
81
+ setTotalPages(result.totalPages)
82
+ setTotalIsCapped(result.totalIsCapped === true)
83
+ } catch (error) {
84
+ if (cancelled) return
85
+ getTelemetryRuntime()?.reportError(error, { module: '{{moduleId}}', code: '{{moduleId}}.list_load_failed' })
86
+ setLoadError(t('{{moduleId}}.list.loadError', 'Failed to load {{moduleTitleLower}}'))
87
+ } finally {
88
+ if (!cancelled) setIsLoading(false)
89
+ }
90
+ }
91
+ void load()
92
+ return () => { cancelled = true }
93
+ }, [listParams, reloadToken, t])
94
+
95
+ const handleDelete = React.useCallback(async (row: {{entityPascal}}Row) => {
96
+ const confirmed = await confirm({
97
+ title: t('{{moduleId}}.delete.confirmTitle', 'Delete {{entityLower}}?'),
98
+ description: t('{{moduleId}}.delete.confirmDescription', 'This action cannot be undone.'),
99
+ variant: 'destructive',
100
+ })
101
+ if (!confirmed) return
102
+ try {
103
+ // Optimistic locking is ON by default: derive the expected-updated-at
104
+ // header from the row the user acted on.
105
+ await runMutation({
106
+ operation: () =>
107
+ withScopedApiRequestHeaders(
108
+ buildOptimisticLockHeader(row.updatedAt ?? undefined),
109
+ () => deleteCrud('{{moduleId}}', row.id),
110
+ ),
111
+ context: {
112
+ formId: '{{moduleId}}.list',
113
+ resourceKind: '{{moduleId}}.{{entitySnake}}',
114
+ resourceId: row.id,
115
+ retryLastMutation,
116
+ },
117
+ mutationPayload: { id: row.id },
118
+ })
119
+ flash(t('{{moduleId}}.delete.success', '{{entityTitle}} deleted'), 'success')
120
+ setReloadToken((token) => token + 1)
121
+ } catch {
122
+ flash(t('{{moduleId}}.delete.error', 'Failed to delete {{entityLower}}'), 'error')
123
+ }
124
+ }, [confirm, retryLastMutation, runMutation, t])
125
+
126
+ const columns = React.useMemo<ColumnDef<{{entityPascal}}Row>[]>(() => [
127
+ {{columnsBlock}}
128
+ ], [t])
129
+
130
+ {{filtersMemo}} const exporter = React.useMemo(() => ({
131
+ getUrl: (format: DataTableExportFormat) => buildCrudExportUrl('{{moduleId}}', { ...listParams, exportScope: 'view' }, format),
132
+ filename: (format: DataTableExportFormat) => '{{moduleId}}.' + format,
133
+ }), [listParams])
134
+
135
+ return (
136
+ <Page>
137
+ <PageBody>
138
+ <DataTable<{{entityPascal}}Row>
139
+ title={t('{{moduleId}}.list.title', '{{moduleTitle}}')}
140
+ actions={(
141
+ <Button asChild>
142
+ <Link href="/backend/{{moduleId}}/create">{t('{{moduleId}}.list.actions.create', 'Create {{entityLower}}')}</Link>
143
+ </Button>
144
+ )}
145
+ columns={columns}
146
+ data={rows}
147
+ isLoading={isLoading}
148
+ error={loadError}
149
+ searchValue={search}
150
+ onSearchChange={(value) => { setSearch(value); setPage(1) }}
151
+ searchPlaceholder={t('{{moduleId}}.list.searchPlaceholder', 'Search {{moduleTitleLower}}')}
152
+ {{filterProps}} exporter={exporter}
153
+ extensionTableId="{{moduleId}}.list"
154
+ onRowClick={(row) => router.push('/backend/{{moduleId}}/' + row.id)}
155
+ rowActions={(row) => (
156
+ <RowActions
157
+ items={[
158
+ {
159
+ id: 'edit',
160
+ label: t('{{moduleId}}.list.actions.edit', 'Edit'),
161
+ onSelect: () => { router.push('/backend/{{moduleId}}/' + row.id) },
162
+ },
163
+ {
164
+ id: 'delete',
165
+ label: t('{{moduleId}}.list.actions.delete', 'Delete'),
166
+ destructive: true,
167
+ onSelect: () => { void handleDelete(row) },
168
+ },
169
+ ]}
170
+ />
171
+ )}
172
+ emptyState={(
173
+ <EmptyState
174
+ title={t('{{moduleId}}.list.empty.title', 'No {{moduleTitleLower}} yet')}
175
+ description={t('{{moduleId}}.list.empty.description', 'Create your first {{entityLower}} to get started.')}
176
+ actions={(
177
+ <Button asChild>
178
+ <Link href="/backend/{{moduleId}}/create">{t('{{moduleId}}.list.actions.create', 'Create {{entityLower}}')}</Link>
179
+ </Button>
180
+ )}
181
+ />
182
+ )}
183
+ pagination={{ page, pageSize: PAGE_SIZE, total, totalPages, totalIsCapped, onPageChange: setPage }}
184
+ />
185
+ </PageBody>
186
+ {ConfirmDialogElement}
187
+ </Page>
188
+ )
189
+ }
190
+ `
@@ -0,0 +1,48 @@
1
+ /**
2
+ * page.meta.ts templates — nav + RBAC contract copied from
3
+ * packages/core/src/modules/customers/backend/customers/people/page.meta.ts.
4
+ */
5
+
6
+ export const listMetaTemplate = `export const metadata = {
7
+ requireAuth: true,
8
+ requireFeatures: ['{{featuresPrefix}}.view'],
9
+ pageTitle: '{{moduleTitle}}',
10
+ pageTitleKey: '{{moduleId}}.nav.title',
11
+ pageGroup: '{{moduleTitle}}',
12
+ pageGroupKey: '{{moduleId}}.nav.group',
13
+ pageOrder: 100,
14
+ icon: 'list',
15
+ breadcrumb: [{ label: '{{moduleTitle}}', labelKey: '{{moduleId}}.nav.title' }],
16
+ }
17
+ `
18
+
19
+ export const createMetaTemplate = `export const metadata = {
20
+ requireAuth: true,
21
+ requireFeatures: ['{{featuresPrefix}}.create'],
22
+ pageTitle: 'Create {{entityLower}}',
23
+ pageTitleKey: '{{moduleId}}.create.title',
24
+ pageGroup: '{{moduleTitle}}',
25
+ pageGroupKey: '{{moduleId}}.nav.group',
26
+ pageOrder: 101,
27
+ icon: 'plus',
28
+ breadcrumb: [
29
+ { label: '{{moduleTitle}}', labelKey: '{{moduleId}}.nav.title', href: '/backend/{{moduleId}}' },
30
+ { label: 'Create', labelKey: '{{moduleId}}.create.title' },
31
+ ],
32
+ }
33
+ `
34
+
35
+ export const detailMetaTemplate = `export const metadata = {
36
+ requireAuth: true,
37
+ requireFeatures: ['{{featuresPrefix}}.view'],
38
+ pageTitle: '{{entityTitle}} details',
39
+ pageTitleKey: '{{moduleId}}.detail.title',
40
+ pageGroup: '{{moduleTitle}}',
41
+ pageGroupKey: '{{moduleId}}.nav.group',
42
+ navHidden: true,
43
+ breadcrumb: [
44
+ { label: '{{moduleTitle}}', labelKey: '{{moduleId}}.nav.title', href: '/backend/{{moduleId}}' },
45
+ { label: 'Details', labelKey: '{{moduleId}}.detail.title' },
46
+ ],
47
+ }
48
+ `
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Module backbone templates (data/validators.ts, components/statusMap.ts,
3
+ * acl.ts, setup.ts, index.ts). acl/setup/index are generated only when absent —
4
+ * the UI slice must reference real feature IDs.
5
+ */
6
+
7
+ export const validatorsTemplate = `import { z } from 'zod'
8
+
9
+ // Optimistic locking is ON by default for CrudForm edit flows: the {{entityLower}}
10
+ // API responses MUST return \`updatedAt\` and the backing table MUST carry an
11
+ // \`updated_at\` column so \`initialValues.updatedAt\` can drive the
12
+ // x-om-ext-optimistic-lock-expected-updated-at header on update and delete.
13
+ export const {{entityCamel}}CreateSchema = z.object({
14
+ {{zodFields}}
15
+ })
16
+
17
+ export const {{entityCamel}}UpdateSchema = {{entityCamel}}CreateSchema.extend({
18
+ id: z.string().uuid(),
19
+ updatedAt: z.string().optional(),
20
+ })
21
+
22
+ export type {{entityPascal}}CreateInput = z.infer<typeof {{entityCamel}}CreateSchema>
23
+ export type {{entityPascal}}UpdateInput = z.infer<typeof {{entityCamel}}UpdateSchema>
24
+ `
25
+
26
+ export const statusMapTemplate = `import type { StatusMap } from '@open-mercato/ui/primitives/status-badge'
27
+
28
+ export type {{entityPascal}}Status = {{statusUnion}}
29
+
30
+ // Shared status → semantic-variant mapping (DS rule: status colors come from
31
+ // StatusBadge variants, never hardcoded palette classes).
32
+ export const {{entityCamel}}StatusMap: StatusMap<{{entityPascal}}Status> = {
33
+ {{statusMapEntries}}
34
+ }
35
+ `
36
+
37
+ export const aclTemplate = `export const features = [
38
+ { id: '{{featuresPrefix}}.view', title: 'View {{moduleTitleLower}}', module: '{{moduleId}}' },
39
+ {
40
+ id: '{{featuresPrefix}}.create',
41
+ title: 'Create {{moduleTitleLower}}',
42
+ module: '{{moduleId}}',
43
+ dependsOn: ['{{featuresPrefix}}.view'],
44
+ },
45
+ {
46
+ id: '{{featuresPrefix}}.edit',
47
+ title: 'Edit {{moduleTitleLower}}',
48
+ module: '{{moduleId}}',
49
+ dependsOn: ['{{featuresPrefix}}.view'],
50
+ },
51
+ {
52
+ id: '{{featuresPrefix}}.delete',
53
+ title: 'Delete {{moduleTitleLower}}',
54
+ module: '{{moduleId}}',
55
+ dependsOn: ['{{featuresPrefix}}.view'],
56
+ },
57
+ ]
58
+
59
+ export default features
60
+ `
61
+
62
+ export const setupTemplate = `import type { ModuleSetupConfig } from '@open-mercato/shared/modules/setup'
63
+
64
+ export const setup: ModuleSetupConfig = {
65
+ defaultRoleFeatures: {
66
+ superadmin: ['{{featuresPrefix}}.*'],
67
+ admin: ['{{featuresPrefix}}.*'],
68
+ employee: ['{{featuresPrefix}}.view'],
69
+ },
70
+ }
71
+
72
+ export default setup
73
+ `
74
+
75
+ export const moduleIndexTemplate = `import type { ModuleInfo } from '@open-mercato/shared/modules/registry'
76
+
77
+ export const metadata: ModuleInfo = {
78
+ name: '{{moduleId}}',
79
+ title: '{{moduleTitle}}',
80
+ version: '0.1.0',
81
+ description: '{{moduleTitle}} module scaffolded with mercato module scaffold.',
82
+ author: 'Open Mercato Team',
83
+ license: 'MIT',
84
+ }
85
+
86
+ export { features } from './acl'
87
+ `
@@ -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({