Work offline
Use client.offline to read the offline lease, see drafts and settle them on reconnect. Where a tenant enables it for a role and a worklist, the SDK asks for an offline lease while reachable. It renews the offline lease on its own. Under an offline lease, an open works as usual. The SDK keeps a save made while unreachable as a draft until the Seald Healthcare Cloud is back. Only this device can open the draft.
Watch reachability and the offline lease
client.on('reachable', ({ reachable }) => { banner(reachable ? undefined : `Offline: the worklist opens until ${client.offline.lease?.expiresAt}`);});for await event in client.on(.reachable) { banner(event.reachable ? nil : "Offline: the worklist opens until \(client.offline.lease?.expiresAt)")}client.on<ClientEvent.Reachable>().collect { event -> banner(if (event.reachable) null else "Offline: the worklist opens until ${client.offline.lease?.expiresAt}")}client.offline.reachable is the current value. While the device holds an offline lease, client.offline.lease is a LeaseState. It carries expiresAt, grantedAt and the number of objects the offline lease covers. The SDK renews the offline lease on its own while reachable. It raises the lease event whenever the state changes.
Read and settle drafts
drafts() lists every Draft this device holds. Each draft carries:
draftIdlocator: where it would save. A draft for a new object has nolocator. It carries the destinationfolderinstead.baseVersion: the version it was made frommadeAtandname
const pending = await client.offline.drafts();render(pending);let pending = try await client.offline.drafts()render(pending)val pending = client.offline.drafts()render(pending)On reconnect, the SDK first sends the record of what this device opened offline. It then raises the drafts event. Handle it with saveDrafts. Pass a function that chooses 'save-anyway' or 'keep' for each draft whose base is no longer current. An ordinary save conflict asks for the same choice.
client.on('drafts', async () => { const outcome = await client.offline.saveDrafts(async (draft, currentVersion) => (await askPerson(`${draft.name}: version ${currentVersion} was saved meanwhile. Save anyway?`)) ? 'save-anyway' : 'keep'); render(outcome.saved, outcome.kept);});for await _ in client.on(.drafts) { let outcome = try await client.offline.saveDrafts { draft, currentVersion in await askPerson("\(draft.name): version \(currentVersion) was saved meanwhile. Save anyway?") ? .saveAnyway : .keep } render(outcome.saved, outcome.kept)}client.on<ClientEvent.Drafts>().collect { val outcome = client.offline.saveDrafts { draft, currentVersion -> if (askPerson("${draft.name}: version $currentVersion was saved meanwhile. Save anyway?")) DraftChoice.SAVE_ANYWAY else DraftChoice.KEEP } render(outcome.saved, outcome.kept)}saveDrafts resolves with two lists:
saved: theSavedoutcomes that went throughkept: the drafts left untouched
The SDK keeps a draft when the person chooses to work from the current version instead. To discard a draft without saving it, call discardDraft with its draftId.
await client.offline.discardDraft(draft.draftId);try await client.offline.discardDraft(draft.draftId)client.offline.discardDraft(draft.draftId)What the SDK does for you
- Asks for and renews the offline lease on its own, wherever the tenant enabled it.
- Fetches every stored object the offline lease covers while reachable. Only this device can open them.
- Keeps an edit made while unreachable as a draft, with no data loss.
- Sends the record of what this device opened offline before any other request on reconnect, then raises
drafts.
Decisions and errors you may see
Outcome or ErrorCode | When | What to do |
|---|---|---|
unreachable | The Seald Healthcare Cloud cannot be reached for something the offline lease does not cover. | Retry later. What the offline lease covers still opens. |
journal-refused | The Seald Healthcare Cloud refused the record of what this device opened offline. | The device gets no offline lease until an Owner reviews it from the worklist. Tell the person their offline edits are paused. |
Next
- Save and handle conflicts for the same base-moved choice an online save asks.
- Worklist and events for the full list of events, including
reachable,leaseanddrafts. - Restore a lost device for what a new device still waits on.
- Sessions for the
offlinesession state.