Skip to content

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}`);
});

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:

  • draftId
  • locator: where it would save. A draft for a new object has no locator. It carries the destination folder instead.
  • baseVersion: the version it was made from
  • madeAt and name
const pending = await 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);
});

saveDrafts resolves with two lists:

  • saved: the Saved outcomes that went through
  • kept: 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);

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 ErrorCodeWhenWhat to do
unreachableThe Seald Healthcare Cloud cannot be reached for something the offline lease does not cover.Retry later. What the offline lease covers still opens.
journal-refusedThe 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