Repository navigation
Description
Refs: #438
Depends on: #442
Can parallel with: E, F, G (schema work only; UI lands after D)
Related: #284
Context
Merchants eventually need custom receipt layouts. Today the only extensibility is compliance templates in installed_print_templates — rows that exist solely as denormalized children of signed country-pack artifacts (Ed25519-verified at install, re-verified at activation, revocation-aware reads). That table must never become generic storage for tenant JSON: its trust model depends on every row tracing to a verified pack version.
This issue establishes the renderer-independent semantic merchant template model: versioned storage, provenance, validation, and selection identity — built on PrintDocument block vocabulary, deliberately independent of HTML/ESC-POS specifics so one template can feed every renderer.
Architectural Decisions Relevant to This Issue
- Four provenance classes stay distinct: core / compliance-pack / merchant-created / imported.
- Merchant schema describes semantic structure (ordered blocks from the PrintDocument v1 vocabulary + presentation options like visibility/order/label-variants), never printer commands or HTML.
- Compliance cloning:
derivedFrommay reference a pack template id for user information; no compliance trust transfers — required legal blocks in compliance templates are enforced by the compliance system itself, and merchant copies are ordinary editable documents (with a documented warning when derived from a tax-invoice template). - Selection identity is structured, not concatenated strings:
bill_templatemigrates to structured JSON{ source: 'core' | 'pack' | 'merchant', id }(pack ids remain globally unique today —template_idis the table PK — but persisted semantics should not rely on that accident). - Schema is versioned from day one with explicit compatibility policy (this becomes a public-facing contract per epic principle; stable semantic field names; internal i18n keys never exposed).
Scope / What to do
- DB migration:
merchant_print_templatestable —id(uuid),business_idscoping consistent with multi-tenant patterns used elsewhere,name,origin(created|imported|cloned),derived_fromnullable structured ref,document_type(receiptv1),schema_version,payload_json,status(draft|active|archived),previous_payload_json(single-step rollback),checksum, audit timestamps/actor columns. - Validation layer: schema-version gate (fail-closed unknown major versions), allowed-blocks whitelist matching PrintDocument v1, property whitelists per block, size cap (~256 KB payload), unknown-field policy = reject on write/import (stricter than render-time tolerance elsewhere).
- Selection identity refactor: settings reader/writer accepts legacy bare values (
classic,compact,<pack-template-id>) and upgrades transparently on next save;isAvailableBillTemplateextended to merchant source; template-picker UI lists core/pack/merchant with provenance badges. - CRUD API (owner role): create/draft → activate → archive with rollback-to-previous; render path resolves merchant templates through the document pipeline (works because D made classic document-driven; compact/KOT rendering of merchant docs follows their owning issues if not yet migrated).
- Golden fixtures: sample JSON template exercising each block type; negative fixtures per validation rule.
Compatibility / Migration
- One-time settings migration for
bill_templatevalues (idempotent; legacy strings keep resolving during transition). - Pack/compliance flows untouched; no change to
installed_print_templates.
What NOT to do
- Do NOT store anything in
installed_print_templates. - Do NOT base the merchant schema on ESC-POS tokens/commands or embed renderer snippets.
- Do NOT expose internal translation keys as template fields (stable semantic label identifiers only).
- Do NOT implement file import/export UX here (feat(printing): add validated offline import/export for merchant templates #448) — this issue defines the model those use.
- Do NOT add a visual editor (future epic).
Acceptance Criteria
- Migration creates the table; fresh-install schema matches (both paths tested per repo migration conventions).
- CRUD lifecycle works: draft→active→archive→rollback with checksum verification.
- Structured selection identity live; legacy values auto-upgrade; pack/core resolution unchanged.
- Validation rejects: unknown schema major, unknown blocks/fields, oversized payloads, non-object roots — with actionable errors.
- A merchant receipt renders via document pipeline identically across available renderers (parity harness extended with a merchant-template mode).
- Provenance badges visible in picker; cloned-from-compliance shows informational origin without trust claims.
Verification
npm run build && npm run lint && npm run audit:db
npx ts-node --transpile-only -P tests/tsconfig.json tests/<merchant-template-tests>.test.ts
npx ts-node --transpile-only -P tests/tsconfig.json tests/print-parity.test.tsDocumentation
Schema + trust/provenance section drafted in PR (docs issue #449 finalizes placement).
Activity
feat(printing): add versioned semantic merchant print template model
feat(printing): localized labels for escpos-line-template-v1 complian…
feat(printing): add versioned semantic merchant print template model
feat(printing): add versioned semantic merchant print template model
feat(printing): add versioned semantic merchant print template model (#…
feat: add validated offline merchant template import/export (#477)
Merge origin/main into main
fix(frontend): match bill template highlights by source (#479)
docs(printing): document multilingual print architecture and template…
docs(printing): document multilingual print architecture and template…
docs: document multilingual print architecture and contribution workf…