Repository navigation
Closed
Labels
area:backendBackend (Express/SQLite)area:frontendFrontend (React/Next.js)enhancementNew feature or request
Description
Refs: #438
Depends on: #447
Can parallel with: None
Related: —
Context
Issue I established versioned semantic merchant templates. Merchants and the community now need portable exchange: export a template as JSON, import someone else's — safely, offline, without any code-execution surface.
Treat every imported file as untrusted input. The merchant schema is declarative by construction (blocks + properties feeding PrintDocument), which makes a safe import pipeline possible; this issue owns enforcing that end to end.
Architectural Decisions Relevant to This Issue
- Declarative-only: no JavaScript, no eval/Function, no SQL/shell, no filesystem paths, no network fetches, no arbitrary remote URLs, no executable HTML. The payload vocabulary is exactly feat(printing): add versioned semantic merchant print template model #447's validated block set — nothing else round-trips.
- Versioned compatibility:
schemaVersionmajor must equal a supported major; minors migrate forward via explicit migration functions; unknown majors rejected with clear messaging; invalid templates never partially install. - Unknown-field policy on import = reject (stricter than render tolerance), so typos cannot silently change meaning.
- Integrity + rollback: checksum recorded; import creates a
draftfor preview-before-activate; activating archives previous payload (single-step rollback preserved from feat(printing): add versioned semantic merchant print template model #447). - Fully offline: no registry lookup, no telemetry requirement, no network validation pass.
Scope / What to do
- Export: owner-facing action per template → downloadable
.jsonenvelope{ format: 'flocafe-merchant-template', schemaVersion, exportedAt, appVersion?, template }(+ checksum field). Filename sanitization. - Import: upload → static validation pipeline (size cap ~256 KB envelope; UTF-8; single JSON document) → schema validation reusing feat(printing): add versioned semantic merchant print template model #447's validator (unknown fields reject) → checksum verify → land as
origin: importeddraft. - Migration hooks: forward-migrate older supported minors; record
migratedFromVersionin payload metadata. - UI: Export button (template list row) + Import flow (file picker → validation report → preview name/blocks summary → save as draft). Reuse existing settings-page modal patterns; error states actionable.
- Collision handling: duplicate name allowed (uuid identity), but offer rename suggestion; importing over an existing uuid = explicit replace-with-confirm only.
- Tests: positive round-trip (export→import→render parity), every rejection class, migration case, oversize/malformed/traversal-named files, offline guarantee (no network calls in code path — assertable by review + existing url-allowlist tooling).
Compatibility / Migration
- Envelope format is a public contract: document schemaVersion policy, stable semantic ids, and forward-compat promises in docs (docs(printing): document multilingual print architecture and template contribution workflow #449 finalizes).
- No impact on compliance packs or core templates.
What NOT to do
- Do NOT fetch anything during import/export.
- Do NOT accept zips/binaries/assets in v1 (text-only JSON).
- Do NOT auto-activate imports.
- Do NOT widen the schema beyond what feat(printing): add versioned semantic merchant print template model #447 validated.
- Do NOT build a visual editor here (future epic).
Acceptance Criteria
- Export/import round-trip preserves semantic render parity (harness mode from I).
- Every rejection path tested: bad version, unknown fields, oversized, malformed JSON, wrong root format, checksum mismatch.
- Import lands as draft; activate/archive/rollback lifecycle intact after import.
- Offline verified: zero network APIs in the feature path.
- Owner-role authorization enforced on both directions; audit entries written consistent with repo conventions.
Verification
npm run build && npm run lint
npx ts-node --transpile-only -P tests/tsconfig.json tests/<template-import-export-tests>.test.ts
npm run test:url-allowlist # confirms no new external endpointsDocumentation
Import/export format spec (public contract section) drafted in PR; finalized under docs issue #449.
Metadata
Metadata
Assignees
Labels
area:backendBackend (Express/SQLite)area:frontendFrontend (React/Next.js)enhancementNew feature or request
Activity
feat: add validated offline merchant template import/export (#477)
docs(printing): document multilingual print architecture and template…
docs(printing): document multilingual print architecture and template…
docs: document multilingual print architecture and contribution workf…