Build a plugin
A code plugin is one file, kit-code.json. Kit runs its JavaScript in a sandbox, held to the databases someone gives it.
The smallest one
{
"kit": 1,
"name": "Dates in order",
"description": "Refuses an edit that would make a row end before it starts.",
"asks": { "rows": "read" },
"hooks": { "validate": true },
"code": "plugin.validate = (row) => (row.values.End?.start < row.values.Start?.start ? 'It would end before it starts.' : null);"
}
kit is always 1. name is what people see; description is one sentence, on its card. asks.rows is "read", or
"write" when it changes rows, with asks.why saying why in a sentence. hooks says when Kit calls it, and code sets
those hooks on plugin.
When Kit calls it
In hooks |
Kit calls | With |
|---|---|---|
"validate": true |
plugin.validate(row, before) before an edit is saved |
Return a reason to refuse it, or null |
"onChange": ["row.added", "row.changed", "row.deleted"] |
plugin.onChange(event) after each |
The row, and its changes ({ Name: [before, after] }) |
"every": "15m", "1h", "6h" or "1d" |
plugin.every() |
Nothing: read what it needs |
"onRequest": true |
plugin.onRequest({ body, text, headers, query }) |
What another app posted to the plugin’s own address |
A plugin can also add commands (in ⌘K, or on the selected rows’ bar), calling plugin.command(id, { database, rows });
formulas every formula can use, set on plugin.formulas; and kinds of property, set on plugin.cells, each with
show(value) answering { text, color?, bar? } and sort(value).
What its code can do
Inside, it has kit and nothing else:
kit.rows('Tickets'); // the rows of a database it was given: { id, title, values } with values by property name
kit.update(rowId, { Status: 'Done' }); // only when asks.rows is "write"
kit.add('Payments', { Customer: 'Mira', Amount: 49 });
kit.log('numbered', n); // shows in its recent runs
It reaches only the databases the person adding it picks. There’s no network, no files and no clock beyond Date. A
check has 50 ms; anything else has 500 ms and 16 to 32 MB. Five failures in a row turn it off.
Its page
readme is markdown, up to 20,000 characters: what it does, how to use it, an example. images are pictures of it at
work, up to 8, each { "src": "images/board.webp", "alt": "What it shows, in a sentence" }, kept beside the
kit-code.json. WebP, PNG or JPEG, 2 MB each. The first is its card.
Try it before you publish
In your own Kit: Plugins › Add another way › A code plugin’s link or file, and pick the file. Kit shows what it may do, and its code, before anything changes.
When it works, publish it.