@open-mercato/cli 0.11.1-develop.8665.1.2455b2503c → 0.11.1-develop.8724.1.beb07a9e96

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 (170) hide show
  1. package/.turbo/turbo-build.log +4 -2
  2. package/dist/agentic/guides/module-facts.json +1884 -195
  3. package/dist/agentic/guides/module-facts.v2.json +1884 -195
  4. package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
  5. package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
  6. package/dist/agentic/guides/modules/api_docs/index.md +1 -1
  7. package/dist/agentic/guides/modules/api_keys/index.md +1 -1
  8. package/dist/agentic/guides/modules/assisted_selling/index.md +1 -1
  9. package/dist/agentic/guides/modules/attachments/index.md +1 -1
  10. package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
  11. package/dist/agentic/guides/modules/auth/index.md +1 -1
  12. package/dist/agentic/guides/modules/availability/index.md +1 -1
  13. package/dist/agentic/guides/modules/backups/index.md +1 -1
  14. package/dist/agentic/guides/modules/business_rules/index.md +1 -1
  15. package/dist/agentic/guides/modules/carrier_inpost/index.md +1 -1
  16. package/dist/agentic/guides/modules/cart/index.md +1 -1
  17. package/dist/agentic/guides/modules/catalog/index.md +1 -1
  18. package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
  19. package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
  20. package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
  21. package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
  22. package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
  23. package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
  24. package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
  25. package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
  26. package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
  27. package/dist/agentic/guides/modules/checkout/index.md +1 -1
  28. package/dist/agentic/guides/modules/communication_channels/exact-override-targets.md +1 -1
  29. package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
  30. package/dist/agentic/guides/modules/communication_channels/workers.md +1 -1
  31. package/dist/agentic/guides/modules/configs/index.md +1 -1
  32. package/dist/agentic/guides/modules/content/index.md +1 -1
  33. package/dist/agentic/guides/modules/currencies/active-extension-bindings.md +11 -0
  34. package/dist/agentic/guides/modules/currencies/di-registrations-rich.md +1 -1
  35. package/dist/agentic/guides/modules/currencies/di-service-tokens.md +1 -1
  36. package/dist/agentic/guides/modules/currencies/exact-override-targets.md +1 -1
  37. package/dist/agentic/guides/modules/currencies/index.md +3 -2
  38. package/dist/agentic/guides/modules/customer_accounts/index.md +1 -1
  39. package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
  40. package/dist/agentic/guides/modules/customers/index.md +1 -1
  41. package/dist/agentic/guides/modules/dashboards/index.md +1 -1
  42. package/dist/agentic/guides/modules/data_sync/index.md +1 -1
  43. package/dist/agentic/guides/modules/design_system/index.md +1 -1
  44. package/dist/agentic/guides/modules/devices/index.md +1 -1
  45. package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
  46. package/dist/agentic/guides/modules/directory/index.md +1 -1
  47. package/dist/agentic/guides/modules/documents/index.md +1 -1
  48. package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
  49. package/dist/agentic/guides/modules/entities/index.md +1 -1
  50. package/dist/agentic/guides/modules/eudr/index.md +1 -1
  51. package/dist/agentic/guides/modules/events/exact-override-targets.md +1 -1
  52. package/dist/agentic/guides/modules/events/index.md +1 -1
  53. package/dist/agentic/guides/modules/events/workers.md +1 -1
  54. package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
  55. package/dist/agentic/guides/modules/forms/index.md +1 -1
  56. package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
  57. package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
  58. package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
  59. package/dist/agentic/guides/modules/generators/index.md +1 -1
  60. package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
  61. package/dist/agentic/guides/modules/integrations/index.md +1 -1
  62. package/dist/agentic/guides/modules/ledger/acl-features.md +16 -0
  63. package/dist/agentic/guides/modules/ledger/active-extension-bindings.md +11 -0
  64. package/dist/agentic/guides/modules/ledger/backend-pages.md +21 -0
  65. package/dist/agentic/guides/modules/ledger/domain-commands.md +22 -0
  66. package/dist/agentic/guides/modules/ledger/encryption.md +11 -0
  67. package/dist/agentic/guides/modules/ledger/entities.md +17 -0
  68. package/dist/agentic/guides/modules/ledger/events.md +19 -0
  69. package/dist/agentic/guides/modules/ledger/exact-override-targets.md +30 -0
  70. package/dist/agentic/guides/modules/ledger/index.md +22 -0
  71. package/dist/agentic/guides/modules/ledger/owned-contract-module-metadata.md +11 -0
  72. package/dist/agentic/guides/modules/ledger/setup.md +11 -0
  73. package/dist/agentic/guides/modules/ledger/umes-hosts.md +26 -0
  74. package/dist/agentic/guides/modules/messages/index.md +1 -1
  75. package/dist/agentic/guides/modules/notifications/index.md +1 -1
  76. package/dist/agentic/guides/modules/onboarding/index.md +1 -1
  77. package/dist/agentic/guides/modules/payment_gateways/active-extension-bindings.md +1 -1
  78. package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
  79. package/dist/agentic/guides/modules/perspectives/index.md +1 -1
  80. package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
  81. package/dist/agentic/guides/modules/planner/index.md +1 -1
  82. package/dist/agentic/guides/modules/portal/index.md +1 -1
  83. package/dist/agentic/guides/modules/progress/index.md +1 -1
  84. package/dist/agentic/guides/modules/promotions/index.md +1 -1
  85. package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
  86. package/dist/agentic/guides/modules/query_index/index.md +1 -1
  87. package/dist/agentic/guides/modules/record_locks/index.md +1 -1
  88. package/dist/agentic/guides/modules/resources/index.md +1 -1
  89. package/dist/agentic/guides/modules/sales/index.md +1 -1
  90. package/dist/agentic/guides/modules/scheduler/index.md +1 -1
  91. package/dist/agentic/guides/modules/search/index.md +1 -1
  92. package/dist/agentic/guides/modules/security/index.md +1 -1
  93. package/dist/agentic/guides/modules/seeds/index.md +1 -1
  94. package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
  95. package/dist/agentic/guides/modules/sso/index.md +1 -1
  96. package/dist/agentic/guides/modules/staff/index.md +1 -1
  97. package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
  98. package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
  99. package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
  100. package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
  101. package/dist/agentic/guides/modules/telemetry/index.md +1 -1
  102. package/dist/agentic/guides/modules/tillio/index.md +1 -1
  103. package/dist/agentic/guides/modules/translations/index.md +1 -1
  104. package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
  105. package/dist/agentic/guides/modules/webhooks/index.md +1 -1
  106. package/dist/agentic/guides/modules/wms/index.md +1 -1
  107. package/dist/agentic/guides/modules/workflows/di-registrations-rich.md +11 -10
  108. package/dist/agentic/guides/modules/workflows/di-service-tokens.md +11 -10
  109. package/dist/agentic/guides/modules/workflows/exact-override-targets.md +11 -10
  110. package/dist/agentic/guides/modules/workflows/index.md +1 -1
  111. package/dist/agentic/guides/reference-module-facts.json +2 -2
  112. package/dist/agentic/guides/reference-modules/example/index.md +1 -1
  113. package/dist/agentic/guides/upstream/AGENTS.md +4 -4
  114. package/dist/agentic/guides/upstream/manifest.json +2 -2
  115. package/dist/agentic/shared/AGENTS.md.template +1 -1
  116. package/dist/agentic/shared/ai/harness/cases.json +1 -1
  117. package/dist/lib/scaffold/field-dsl.js +393 -0
  118. package/dist/lib/scaffold/field-dsl.js.map +7 -0
  119. package/dist/lib/scaffold/index.js +412 -0
  120. package/dist/lib/scaffold/index.js.map +7 -0
  121. package/dist/lib/scaffold/targets.js +42 -0
  122. package/dist/lib/scaffold/targets.js.map +7 -0
  123. package/dist/lib/scaffold/templates/create-page.js +52 -0
  124. package/dist/lib/scaffold/templates/create-page.js.map +7 -0
  125. package/dist/lib/scaffold/templates/detail-page.js +186 -0
  126. package/dist/lib/scaffold/templates/detail-page.js.map +7 -0
  127. package/dist/lib/scaffold/templates/form-config.js +42 -0
  128. package/dist/lib/scaffold/templates/form-config.js.map +7 -0
  129. package/dist/lib/scaffold/templates/index.js +27 -0
  130. package/dist/lib/scaffold/templates/index.js.map +7 -0
  131. package/dist/lib/scaffold/templates/list-page.js +190 -0
  132. package/dist/lib/scaffold/templates/list-page.js.map +7 -0
  133. package/dist/lib/scaffold/templates/metas.js +47 -0
  134. package/dist/lib/scaffold/templates/metas.js.map +7 -0
  135. package/dist/lib/scaffold/templates/module-files.js +85 -0
  136. package/dist/lib/scaffold/templates/module-files.js.map +7 -0
  137. package/dist/lib/testing/integration-discovery.js +32 -3
  138. package/dist/lib/testing/integration-discovery.js.map +2 -2
  139. package/dist/lib/testing/integration.js +232 -8
  140. package/dist/lib/testing/integration.js.map +2 -2
  141. package/dist/lib/worker-job-handler.js +7 -1
  142. package/dist/lib/worker-job-handler.js.map +2 -2
  143. package/dist/mercato.js +6 -1
  144. package/dist/mercato.js.map +2 -2
  145. package/package.json +7 -7
  146. package/src/lib/__tests__/agentic-workflows-ownership.test.ts +79 -0
  147. package/src/lib/__tests__/worker-job-handler.test.ts +30 -0
  148. package/src/lib/scaffold/__tests__/__snapshots__/scaffold-golden.test.ts.snap +1742 -0
  149. package/src/lib/scaffold/__tests__/fixtures/typescript-toolchain.cjs +5 -0
  150. package/src/lib/scaffold/__tests__/helpers.ts +75 -0
  151. package/src/lib/scaffold/__tests__/scaffold-ds-contract.test.ts +275 -0
  152. package/src/lib/scaffold/__tests__/scaffold-golden.test.ts +267 -0
  153. package/src/lib/scaffold/__tests__/scaffold-runtime.test.tsx +193 -0
  154. package/src/lib/scaffold/field-dsl.ts +491 -0
  155. package/src/lib/scaffold/index.ts +531 -0
  156. package/src/lib/scaffold/targets.ts +68 -0
  157. package/src/lib/scaffold/templates/create-page.ts +52 -0
  158. package/src/lib/scaffold/templates/detail-page.ts +190 -0
  159. package/src/lib/scaffold/templates/form-config.ts +42 -0
  160. package/src/lib/scaffold/templates/index.ts +27 -0
  161. package/src/lib/scaffold/templates/list-page.ts +190 -0
  162. package/src/lib/scaffold/templates/metas.ts +48 -0
  163. package/src/lib/scaffold/templates/module-files.ts +87 -0
  164. package/src/lib/testing/__tests__/integration-app-only-playwright.test.ts +225 -0
  165. package/src/lib/testing/__tests__/integration-app-only.test.ts +320 -0
  166. package/src/lib/testing/__tests__/integration-discovery.test.ts +45 -1
  167. package/src/lib/testing/integration-discovery.ts +32 -2
  168. package/src/lib/testing/integration.ts +293 -11
  169. package/src/lib/worker-job-handler.ts +17 -1
  170. package/src/mercato.ts +7 -1
@@ -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
+ `