Skip to main content

Document Service — Sync Contract

Status: populated Owner: TBD Last updated: 2026-04-18 Companion: Service Template · 16 offline-first-and-sync


1. Offline Posture

The document-service has a mixed offline posture depending on workflow type.


2. Per-Aggregate Conflict Policy

Aggregate / WorkflowConflict PolicyRationale
DocumentTemplateserver_authoritativeTemplate authoring is an admin workflow; no offline editing
DocumentTemplateVersionserver_authoritativePublish workflow requires server validation; immutable once published
DocumentRenderJob (sync generation)server_authoritativeRequires live FHIR binding resolution; cannot execute offline
DocumentRenderJob (async generation)append_onlyClient queues render request with clientMutationId; replays when online
DocumentUploadserver_authoritativeVirus scan mandatory; no offline upload path
DocumentArtifact (cached PDF read)lww (client TTL)Cached PDFs readable offline with encrypted local cache; TTL configurable per deployment

3. Offline Capabilities by Workflow

WorkflowOffline-capableNotes
Browse published templates (cached)Yes (read-only)Stale-while-revalidate when online
Design/edit templatesNoServer is authority for template catalog
Generate PDF (server render)NoQueue render request with clientMutationId; replay when online
View / download cached PDFYesEncrypted local cache; tenant-scoped; signed URL refreshed on next sync
Upload scanned documentNoVirus scan requires server
Print from cached PDFDevice-dependentAudit event emitted on next online sync

4. Render Request Offline Queue

When generating a document offline, the client creates a pending DocumentRenderJob record locally with status=queued and a clientMutationId. On reconnection:

  1. Client replays POST /v1/documents/render-jobs with the original clientMutationId.
  2. Service deduplicates by (tenantId, clientMutationId) in document_render_jobs.
  3. If the job already exists (duplicate), returns the existing job status.
  4. If new, enqueues normally.

5. Sync Framework

The @ghasi/sync-protocol package is not used by this service for document mutations. The offline queue pattern above is custom to render job idempotency. Read-only PDF caching is handled by the client SDK's cache layer.