Skip to content

PluginAudit

Reads the audit trail of an outline. The audit trail is a signed record of who changed what. Each device keeps a list of the changes that it made, signs every entry of that list, and keeps copies of the lists of the other devices. A list can only grow, so the app detects a list that was altered, cut short or split into two.

The trail that a call reads is the trail of the share that the outline belongs to. When the outline is not shared, it is the trail of the devices of the person. Reading requires the audit permission.

A plugin can also write a note in the trail with record, which requires the audit:write permission. To record who received the key of a shared outline, run ctx.commands.core.audit.grant(…) with ctx.dispatch. This requires the audit:grant permission.

Write a note in the trail of the outline of a row

await ctx.audit.record(row.outline, 'Agreed to open "' + row.title + '"');

List the entries of every device, and check each list

const heads = await ctx.audit.heads(outlineId);
for (const head of heads) {
const entries = await ctx.audit.entries(outlineId, head.device, { after: -1, limit: 100 });
const check = await ctx.audit.verify(outlineId, head.device);
ctx.log('info', `${head.device}: ${entries.length} entries, list ${check.ok ? 'sound' : 'broken at ' + check.seq}`);
}
entries(
outline,
device,
options?
): Promise<readonly EntryView[]>;

Reads entries of the list of one device, in order. The call starts after the entry that has the number after, and it returns at most limit entries.

An entry has verified: true, and holds the change itself in deltas, when the device showed the content of the change and that content matched the signed fingerprint of the entry. A change that is too large, or that the device never showed, is signed but has neither of the two.

Parameter Type Description
outline string the id of the outline whose trail is read
device string the id of the device whose list is read
options? { after?: number; limit?: number; } after is the number of the entry after which to start, and -1 starts at the first entry. limit is the maximum number of entries to return, and it cannot exceed 500
options.after? number -
options.limit? number -

Promise<readonly EntryView[]>

the entries, in order


heads(outline): Promise<readonly object[]>;

Returns the last entry of the list of each device, in the trail of the outline.

Parameter Type Description
outline string the id of the outline whose trail is read

Promise<readonly object[]>

for each device, its id, the number of its last entry (seq) and the id of that entry


record(outline, text): Promise<Outcome>;

Writes a note in the trail of an outline: a short text that says what the plugin did, for example that the person agreed to open a letter. The device signs the note in its own list, like the changes that it makes, so the note cannot be changed or removed afterwards, and the other devices of the trail receive it.

The app writes the name of the plugin in the note, as bundled/<id> for a plugin that ships with the app, <publisher>/<id> for a plugin that names its publisher, core/<id> for a feature of the app, and the id alone otherwise. A plugin cannot write a note in the name of another. The entry has kind: 'note' and v: 2, and ctx.audit.entries returns it with its note: the plugin, the text and the outline. History shows the note under the outline, with the person who wrote it.

The note is written in the list of the device that makes the call, and only once this device belongs to a group: before that, the call does nothing visible. Requires audit:write.

Parameter Type Description
outline string the id of the outline whose trail receives the note
text string what the plugin writes, from 1 to 500 characters

Promise<Outcome>

the outcome of the change that carries the note; committed when it was written

an error when the outline does not exist or the text is empty or longer than 500 characters

await ctx.audit.record(row.outline, 'Agreed to open "' + row.title + '"');

verify(outline, device): Promise<VerifyView>;

Checks the whole list of one device against the devices that are allowed in the trail.

Parameter Type Description
outline string the id of the outline whose trail is checked
device string the id of the device whose list is checked

Promise<VerifyView>

{ ok: true, head } with the last entry of the list when the list is sound. Otherwise { ok: false, seq, reason }, where seq is the number of the entry at which the list breaks and reason says why