Skip to content

feat(printing): add validated offline import/export for merchant templates #448

Closed

Description

@khaira777

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: schemaVersion major 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 draft for 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

  1. Export: owner-facing action per template → downloadable .json envelope { format: 'flocafe-merchant-template', schemaVersion, exportedAt, appVersion?, template } (+ checksum field). Filename sanitization.
  2. 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: imported draft.
  3. Migration hooks: forward-migrate older supported minors; record migratedFromVersion in payload metadata.
  4. 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.
  5. Collision handling: duplicate name allowed (uuid identity), but offer rename suggestion; importing over an existing uuid = explicit replace-with-confirm only.
  6. 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

What NOT to do

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 endpoints

Documentation

Import/export format spec (public contract section) drafted in PR; finalized under docs issue #449.

Metadata

Metadata

Assignees

Labels

area:backendarea:frontendenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions