Package reference
This page lists everything a protocol package declares. It also lists what the gateway checks when the package loads.
Writing packages shows how to put a package together. The host API lists the functions a package can call.
Layout
Section titled “Layout”packages/ brightlink/ cloud-1.0/ a package package.toml main.lua *.lua modules of this package tests/*.toml scenarios dev/seed.toml people for `hourd dev` (not in the bundle) zk/ a vendor folder zk.lua require("zk"): a module shared by every package below push-3.4/- A folder with
package.tomlis a package. Any other folder groups packages. Its*.luafiles are modules for every package beneath it. The packages folder’s own*.luafiles are not modules. - Folders whose names start with
_or.are never packages. Packages nest at most 8 folders deep. require(name)finds a module in the package folder, in the folders above it up to the packages folder, and in the shared library.- A module with the same name as one further up, or as a library module, fails the load (
zk.lua shadows a shared module of the same name). So shared code cannot be overridden by dropping in a file of the same name. - Two packages with the same name and version fail the load.
package.toml
Section titled “package.toml”name = "acme-cloud"version = "1.0.0"vendor = "Acme"description = "Acme cloud clocks: JSON over HTTP."transports = ["http"]delivery = "ack"host_api = 2
[requires]vars = ["acme_region"]secrets = ["acme_api_key"]| Field | Required | Default | |
|---|---|---|---|
name | yes | Letters, digits, -, _ and .. | |
version | yes | Dotted numbers (1.0.0). Its first two numbers make the package’s line ([email protected]). | |
host_api | yes | The host API the package is written for: 2. | |
vendor | no | "" | Shown in listings. |
description | no | "" | Shown in listings. |
transports | no | ["http"] | http and/or mqtt. These are the listener types an endpoint may bind the package to. At least one. |
delivery | no | ack | What happens when a message’s events cannot be stored (below). |
[commands] | no | How the device answers what it is handed ([commands], below). | |
[requires] | no | vars and secrets. These are the names the package cannot run without. |
Any other field fails the load.
delivery. A message’s events are stored before the device is answered. delivery says what happens when they cannot be:
| Value | |
|---|---|
ack | The message is refused and nothing it changed is kept. The device sends it again. |
cursor | The device gets its reply, but store writes are dropped. So the package asks for the same data again. |
none | The events are lost and everything else proceeds. |
[commands]. The gateway decides nothing from how long a device takes to answer. A command handed out stays in the device’s hand until it is answered, lost, or given up on. The engine keeps facts only: what was handed out, and what was answered. What counts as missed is for the package to say, as it handles a message (M.missed, below):
| Field | Default | |
|---|---|---|
resend | never | writes: a missed command that declares what it writes is handed out once more, with the same id. This happens when it was handed out once and carries no sensitive parameter. Missed again, it is unanswered. never: a missed command is unanswered at once. Some commands must not run twice. |
missed_on | none | Routes whose requests M.missed(req, in_hand, answered) is asked about, even with no result, while commands are in the device’s hand (a request that means the device restarted). A message that carries results is asked about whichever its route. Listing routes needs M.missed. results is gone: a package that still declares it is refused at load, because the order of answers is the package’s to judge. |
reply | none | What one reply carries of the device’s commands: reply = { max_count = 200, max_bytes = 40960, bytes_option = "max_command_bytes" }. Each key is optional. queue.pending cuts a reply at max_count and max_bytes when the call names no limit of its own. The package reads them as ctx.reply.max_count and ctx.reply.max_bytes. bytes_option names an endpoint option. The option is one of the package’s options, and is a whole number. It replaces max_bytes for that endpoint. It needs max_bytes. A package that syncs also has max_count as the most commands queued for one of its devices at a time (see sync). If such a package declares no count, it has 816. |
A lost command that is not handed out again is marked unanswered. A command.unanswered event is sent. An action it belongs to fails at it (a gate that goes unanswered holds the device). A result that comes later still completes the command. If the device is never coming back, a command in its hand ends when you cancel its action with give_up.
[requires]. A revision is not activated while a tenant whose endpoints use it lacks one of these vars or secrets. The refusal names each. A value a package in use requires cannot be deleted. A value that the tenant’s scope or the package’s own scope sets satisfies it (environments). Leave out values the package can do without. Names are letters, digits, _, - and ..
main.lua
Section titled “main.lua”main.lua returns a table, M. The gateway reads these fields:
| Field | Required | |
|---|---|---|
identify(req) | yes | The device’s id, and the key it presented (below). |
routes | yes | Every message kind the device sends. |
commands | no | Every command the gateway can send. |
actions | no | Standard actions done in steps, and the package’s own actions. |
options | no | The endpoint options the package reads. |
supports(name, info, kind) | no | Whether a device takes an action or command. |
set_key(key, ctx) | no | Queues the commands that give a device its key. |
verify(req, secret) | no | Checks a signed message against the device’s key. |
settings | no | The settings registry. |
sync | no | What the package’s devices take and report in a sync group. |
outbound(ctx) | no | For push transports (MQTT): messages to send now. |
The fields are read once, when the package loads. Every declaration is checked then. A package that fails a check does not load.
This example uses most of them. It is the acme-cloud package that the package.toml above describes:
local M = {}
-- The device's id and, when it presents one, its key.function M.identify(req) return req.headers["x-acme-device"], req.headers["x-acme-key"]end
-- Queues what gives a device its key (key == nil: what takes it away).function M.set_key(key, ctx) if key == nil then queue.add("clear_key") else queue.add("set_key", { key = key }) endend
M.options = { { name = "timezone", type = "timezone", required = true, description = "The zone of times the device sends without an offset." }, { name = "poll_seconds", type = "number", description = "How often the device polls." },}
M.routes = { { name = "punch", description = "A user punched.", match = function(req) return req.method == "POST" and req.path == "/acme/punch" end, handle = function(req, ctx) local ok, p = pcall(json.decode, req.body) local at = ok and type(p) == "table" and time.at(ctx.options.timezone, p.at or "") or nil if not at then emit("unparsed", { reason = "a punch without a readable time", raw = req.body }, req.body) return "OK" end emit("punch", { user_id = tostring(p.user), local_time = at["local"], utc_offset = at.offset, time = at.time, dst_ambiguous = at.ambiguous, time_zone = at.time_zone, zoned = at.zoned, state_name = p.direction == "in" and "check_in" or "check_out", vendor = { acme = { terminal = p.terminal } }, }, p.id) return "OK" end }, { name = "poll", description = "The device asks for commands.", match = function(req) return req.method == "GET" and req.path == "/acme/poll" end, handle = function(req, ctx) report({ region = vars.get("acme_region") }) local out, ids = {}, {} for _, c in ipairs(queue.pending {}) do out[#out + 1] = { id = c.id, command = json.decode(c.payload) } ids[#ids + 1] = c.id end queue.mark_sent(ids) return { status = 200, body = json.encode(json.array(out)), headers = { ["content-type"] = "application/json" } } end }, { name = "result", description = "The device reports a command's result.", match = function(req) return req.method == "POST" and req.path == "/acme/result" end, handle = function(req) local ok, r = pcall(json.decode, req.body) if not ok or type(r) ~= "table" then return { status = 400, body = "bad result" } end if r.busy then queue.retry(r.id, 10, "busy") else queue.result(r.id, r.ok and 0 or -1, r.error or "") end return "OK" end },}
M.commands = { delete_user = { title = "Delete user", implements = "delete_user", params = { "user_id!" }, quick = true, build = function(p) return json.encode({ op = "user.delete", id = p.user_id }) end, }, add_user = { title = "Add user", writes = { "people" }, params = { { name = "user_id", type = "string", required = true, pattern = "^[0-9]{1,9}$" }, { name = "name", type = "string", max_length = 24 }, { name = "code", type = "secret", max_length = 8 }, }, build = function(p) return json.encode({ op = "user.put", id = p.user_id, name = p.name or "", code = p.code or "" }) end, }, export = { title = "Export the device's database", writes = {}, success = "non_negative", sensitive_result = true, build = function() return json.encode({ op = "export" }) end, }, set_key = { title = "Set device key", writes = {}, internal = true, params = { { name = "key", type = "secret", required = true, max_length = 128 } }, build = function(p) return json.encode({ op = "key", key = p.key }) end, }, clear_key = { title = "Clear device key", writes = {}, internal = true, build = function() return json.encode({ op = "key", key = "" }) end, },}
M.actions = { upsert_user = { params = { "user_id", "name", "keypad_pin" }, expand = function(p) return { { action = "add_user", params = { user_id = p.user_id, name = p.name, code = p.keypad_pin } } } end },}
return Midentify
Section titled “identify”identify(req) returns the device’s id. It can also return the key the message carried. Both come from wherever the protocol puts them (a header, the query string, the body, an MQTT topic segment).
A device id is 1 to 64 printable ASCII characters. It has no spaces, /, + or #. For example, it can be a serial number, a MAC address or a cloud id. Returning nil or "" refuses the message with 400 unknown device. An id that breaks the rules gets 400 invalid device id.
When a key is registered for the device, the gateway compares the key identify returned with it. The gateway refuses a message without the right one (401). A protocol that signs its messages instead declares M.verify (device keys).
Requests and replies
Section titled “Requests and replies”req, the message as a route sees it:
| Field | |
|---|---|
method | The HTTP method. PUBLISH for MQTT. |
path | The path with the endpoint’s path prefix taken off. For MQTT, the whole topic. |
query | The query parameters, the first value of each name. |
headers | The headers, names in lower case. |
body | The body, byte for byte. |
remote_ip | The sender’s address. |
params | The values captured by {name} segments of the endpoint’s path or topic. |
ctx, handed to every package function that runs for a device:
| Field | |
|---|---|
endpoint | The endpoint’s id. |
options | The endpoint’s options. |
device | id, info (what the package has reported about it) and first_seen (RFC 3339, or nil). |
pending | The commands waiting for the device, in the order they are to go. Each has id, action, lane, offered (always false here) and payload. It has payload_base64 instead when what build returned is not text. The list holds every command waiting, as far as 256 KiB of payloads. It always holds at least one when any is queued. No count limits it. What a device takes in one message is for the package to say, to queue.pending. The zk package does this for its reply, with its protocol’s limits. |
biometrics_refused | When the device’s sync group refuses some people biometrics, their user ids. Read it with allow_biometrics. |
sync | In a route with a lookup: what the sync group answered (lookups). |
A handler returns:
| Return | Reply |
|---|---|
| a string | HTTP 200 with that body. |
{ status, body, headers } | That reply. status defaults to 200 and must be 100 to 599. |
| nil | HTTP 204. Nothing is published on MQTT. |
Routes
Section titled “Routes”M.routes is a list. Each route has a name, a description, match(req, ctx) and handle(req, ctx). The name is unique. It shows in the traffic log and in coverage. A route may also have lookup(req, ctx) (lookups). The first route whose match returns a true value handles the message.
There is no catch-all. A message no route matches gets 404 and is logged. Declare a route for every message the device sends.
What is in the device’s hand: ctx.in_hand()
Section titled “What is in the device’s hand: ctx.in_hand()”ctx.in_hand() returns the commands handed to the device that it has not answered. It returns them as a list of { id, action, writes }. M.missed is given the same list as in_hand, with writes on each command: whether it declares what it writes.
When a route asks, the engine reads the list under the device’s turn. The route is run again once, with the list. Nothing the first run did is kept (no log line, event, report or write). Only the rerun counts. A second call in a run returns the list with no further rerun. The rerun is counted in houradvantage_device_turn_reruns_total{package,cause="in_hand"}. A route that never asks pays nothing.
Use it to tell what a request means by what the device holds. For instance, an options request made with a CHECK in hand is that command’s answer and not a start-up.
A device that has been acknowledged moves on and forgets what it sent. So emit what the package cannot read as an unparsed event with the raw data. Do not drop it. The engine keeps a raw of more than 16 KiB to its start and a hash, whichever package emits it.
Endpoint options
Section titled “Endpoint options”M.options lists the endpoint options the package reads from ctx.options. Each entry is "name", "name!" (required), or a table:
| Field | |
|---|---|
name | The option’s name. |
type | boolean, number, string or timezone (a zone name such as America/Chicago or an offset such as -05:00). |
required | true means an endpoint must set it. An empty string counts as not set. |
description | What it is for. |
When a package declares options, the gateway refuses an endpoint in three cases:
- It leaves out a required option.
- It names an option that is not declared. The gateway lists the ones the package takes.
- It gives an option a value of the wrong type.
A package without M.options is handed whatever options the endpoint sets, unchecked.
The gateway reads two options itself, whatever the package:
biometrics = truemeans the endpoint collects biometric data and photos. Without it, the gateway dropsbiometric,biometric.photo,user.photo,photoandid_cardevents before they are stored. Readctx.options.biometricsto decide whether to ask devices for them.drop_events = ["photo", ...]means events of these types are dropped before they are stored.
A package whose devices send wall-clock times without an offset declares a required timezone option.
Commands
Section titled “Commands”M.commands maps each command’s name to its declaration:
| Field | |
|---|---|
build(params, ctx) | Required. Returns the payload. The payload is a string, which may hold any bytes. |
title | Shown to whoever sends it. The default is the name. |
description | What it does. |
params | Its parameters. |
writes | The sync domains it writes. Required unless it implements a standard action. |
implements | The standard action this command is. |
internal | true means only the package’s own actions, routes and set_key queue it. It is never sent by name. |
quick | true means it is worth a one-click button in a user interface. |
success | Which result codes are success. zero is the default. non_negative is for a device that answers with a size or count. positive is for a check that something exists. |
sensitive | A list of parameter names to mark sensitive (handy for commands built from templates). A name that is not one of its parameters fails the load. |
sensitive_result | true means what the device answers may be sensitive (a file of every user). The command keeps only its size once the command.result event is stored. |
Values reach build as they were given (an integer may arrive as "3", a boolean as "1"). So render them yourself. hourctl pkg render prints what build returns.
Use internal = true for a device primitive that the package reaches only through a declared action, such as writing one option for set_settings.
Parameters
Section titled “Parameters”Every parameter of a command or action has a type, and may narrow it. The gateway checks every request against the declarations before anything is queued or the package sees it. It refuses a request with HTTP 422 if a parameter is unknown, a required one is missing, or a value does not fit. The refusal names what is wrong with each field (command 'add_user': parameter 'privilege' must be one of 0, 2, 14).
A parameter is a table:
| Field | |
|---|---|
name | Its name. |
type | string, integer, boolean, enum, secret, binary, wall_time, rfc3339, cards or list. |
required | true means it must be given. An empty string counts as not given. |
description | What it is. |
sensitive | true means it is kept and shown only as its size (below). |
values | For enum: the values it may be, as text ({ "0", "2", "14" }). |
min, max | For integer: its range. |
max_length, pattern | For string and secret. max_length is the most characters. pattern is a regular expression (Rust syntax, not a Lua pattern) that the whole value must match. So anchor it: ^...$. |
max_bytes | For binary: the most bytes, decoded. |
items, max_items | For list: what each item is ({ type = "integer", min = 1, max = 50 }), and the most items. max_items also applies to cards. |
| Type | Takes |
|---|---|
string | Text. A number is taken as its digits. |
integer | A whole number, or one as text ("3"). |
boolean | true/false, "true"/"false", 1/0, "1"/"0". |
enum | One of values. |
secret | Text that is always sensitive (a password, a PIN, a key). |
binary | Base64 text. |
wall_time | Device wall-clock time, in one of these forms: "2026-10-01", "2026-10-01 08:30" or "2026-10-01 08:30:00". T may stand for the space. |
rfc3339 | An instant with its offset, like "2026-10-01T08:30:00-05:00". |
cards | A list of cards. Each is { number, format?, facility? }, or a number alone. |
list | A list of items, or text separated by commas. |
Each of these fails the load:
- A field that is not in the first table.
- A narrowing that does not fit the type (
max_lengthon an integer). - An enum without values.
minabovemax.- A pattern that does not compile.
- A parameter declared twice.
The shorthand "name" or "name!" (required) names a standard parameter. It is only for a command that implements a standard action, and for an M.actions entry of a standard action. Its type is the catalog’s. Such a command may narrow a standard parameter with a table without type ({ name = "name", max_length = 24 }). It cannot change the type. Every other parameter is typed, or the package fails to load.
Sensitive parameters. Mark every parameter that carries a secret or personal data: passwords, keypad PINs, card numbers, keys, biometric templates, photos. Mark it with sensitive = true, or the type secret. The device gets the payload built from them. Everywhere else the value is kept only as <redacted N bytes>. That means the stored command, the command history and stream, and the audit trail. Once the command has been handed to the device, its stored payload is replaced the same way.
A standard parameter the catalog marks sensitive stays sensitive. A command that implements the action and takes the parameter has it marked sensitive whether it says so or not. Wherever a step of the action carries its value, the value is redacted as the action runs.
What a command writes
Section titled “What a command writes”writes lists the sync domains the command changes on the device:
| Domain | |
|---|---|
people | Users, cards, PINs and passwords, templates, photos, per-user settings. |
access | Schedules, holidays, access groups. |
lists | Work codes and the other lists, messages. |
settings | Options of the settings registry. |
punches | The punch state a device enforces. |
writes = {} means one of three things:
- A read.
- An operation on the device (reboot, open a door, fetch a file, enrolment by someone at the device).
- Something the gateway manages itself (the device key).
A command that clears several kinds of data names every domain it clears.
While a device’s sync group keeps a domain, a command or action that writes it is refused (409). The group is the one place that data is changed. A command that implements a standard action writes what the catalog says the action writes. Leave writes out, or give exactly that. A command without either fails the load, naming it.
Standard actions
Section titled “Standard actions”The gateway owns a vocabulary of actions that mean the same on every device: upsert_user, delete_user, set_cards, change_user_id, set_biometric, reboot, open_door, wipe, set_settings and the rest. They have fixed parameter names and types (actions). user_id is always the user’s id. keypad_pin is the secret code a user keys in. A package offers each one its devices can do, in one of two ways:
- One to one: a command with
implements = "<action>"is the action. It takes the standard parameters by name. It may take fewer. A parameter it does not declare is refused when given. It must take the required ones. - In steps:
M.actions[name]is a function(params, ctx) -> steps, or a table{ params = {...}, expand = function, description = "..." }.paramslists the standard parameters it takes by name (default: all of them). It also types the package’s own (x_..., below).expand(params, ctx)gets them checked and normalized. Itswritesis the catalog’s.
steps is a list of { action = <command>, params = {...}, gate = true? } (at most 256). Each step names one of the package’s commands. It is checked against that command’s declaration in turn. A step may be built with commands.step and commands.gate.
At load, the gateway refuses each of these:
- An
implementsthat is not a standard action. - A standard action offered twice.
- A standard action that misses one of its required parameters.
- A standard action that says it writes other than the catalog.
A sensitive standard parameter is marked sensitive on the command that takes it. It is redacted as the action runs, wherever a step carries its value. Map the standard actions explains how steps and gates go to a device.
The package’s own parameters for a standard action start with x_ (x_verify_mode). So they never clash with standard parameters. They are typed tables like any command parameter ({ name = "x_hand", type = "enum", values = { "left", "right" } }). A standard parameter is named, never typed again.
The package’s own actions are M.actions entries whose name is not a standard action. They take the table form. They declare everything a command does: every parameter typed, and writes. The name is lower-case letters, digits and _. It starts with a letter. It is not also one of the package’s commands’ names (the package’s own actions).
Not every device takes every action. M.supports(name, info, kind) is called with an action’s or command’s name, the device’s reported info and kind ("action" or "command"). It returns true, or false and a reason (no face reader, say). A device’s page in the API and hourctl device actions list only what it takes. An action it does not take is refused with this device does not take '<name>': <reason>.
Handing out commands
Section titled “Handing out commands”A device takes only so much in one reply. The limit can be a count of commands, a number of bytes with each one’s framing, or nothing after a reboot. That is a fact of its protocol. So the package says it, and the engine does the fitting, in Rust, from what waits. The count and the bytes a reply carries are declared once, in the manifest ([commands] reply, above). A call that leaves them out takes them from there:
local batch = queue.pending { max_count = 200, -- the most commands in a reply (default: the manifest's `reply.max_count`, else no limit) max_bytes = 40960, -- the most bytes (default: the manifest's `reply.max_bytes`, else no limit) overhead = 4, -- the bytes each command takes besides its payload: its framing (default 0) id_digits = true, -- and the digits of its id (default false) separator = 0, -- the bytes between two commands (default 0) lane = "interactive", -- only the commands of this lane (default: every lane) ends_after = "REBOOT", -- a command whose payload starts with it ends the reply (a string, or a list) include_offered = false, -- also the commands offered before that have no result (default: no) no_line_breaks = { code = -1, text = "not sent: the command contains a line break" }, too_big = { code = -1006, text = "not sent: the command is larger than 40960 bytes" },}for _, c in ipairs(batch) do -- c.id, c.action, c.payload (its bytes), c.offered ids[#ids + 1] = c.idendqueue.mark_sent(ids)The call takes the commands that fit from the front, in order, never part of one. It stops at the first that does not fit (so order is kept) or after one that ends the reply.
Some commands can never be sent. One is larger than max_bytes with its framing alone (too_big). Another has a line break where the framing allows none (no_line_breaks). Such a command is answered as failed with that code and text, and left out. Without too_big, it is answered with code -1 saying it is larger than max_bytes. Leaving it out means it does not block the ones behind it. A mistyped option is an error. ctx.pending stays what waits, for a package that wants to look at it. This is how it hands out.
A command written into a reply is offered (queue.mark_sent). The engine does not guess from a closed connection whether the device had it. It stays offered until the device’s result comes, a loss rule applies, or it is given up on.
A package whose protocol can tell takes the commands offered before and not answered with include_offered = true. A device that polls again only after it has run what it was handed is an example. The engine allows this for the commands its resend lists (the ones that write: [commands] resend = "writes"). They come first, flagged offered, and queue.mark_sent offers them again.
Push transports
Section titled “Push transports”On MQTT the gateway can send a command the moment it is queued. M.outbound(ctx) returns the messages to publish now (a string, a list of strings, or nil). It builds them from queue.pending{}. It calls queue.mark_sent with the ids it sent. brightlink/cloud-1.0 is the worked example.
Settings registry
Section titled “Settings registry”M.settings registers every device option the package can set or read. set_settings and read_settings take these names and nothing else. They are the only way to change a device’s settings.
M.settings = { { name = "volume", type = "integer", min = 0, max = 100, native = "VOLUME", description = "Speaker volume, percent." }, { name = "face_threshold", type = "integer", min = 60, max = 99, native = "FaceMThreshold", reboot = true, description = "How close a face must match.", applies = function(info) return info.face_version ~= nil end }, { name = "admin_password", type = "string", max_length = 8, sensitive = true, access = "w", description = "The menu password." },}| Field | |
|---|---|
name | Required. The neutral name callers use, snake_case. |
description | Required. What it does. |
type | Required. boolean, integer, number, string, enum or table (a list). |
min, max | For integer and number: the range. Required. |
values | For enum: the values. Required. |
max_length, pattern | For string: at least one is required. |
title | A short label. |
native | The device’s own name for it. The default is name. |
reboot | true means the device takes it only after a restart. |
access | rw (default), w (set only, such as a password) or r (shown, never set). |
applies | true, false, or function(info). Only devices whose reported info has it list it and take it. |
sensitive | true means it is kept sealed and shown only as its size. |
standard | The standard setting it is: volume, language, date_format, time_format, screen_timeout_seconds, ntp_server or lock_seconds. A setting named one of these is that standard setting. |
Any bound, values and applies may be a function of the device’s info, if it depends on the device. Register only options the package sends, with the device’s real range. set_settings values are checked against the registry as it applies to the device before anything is queued (parameter 'values.volume' must be from 0 to 100).
Sync groups
Section titled “Sync groups”An endpoint may be in a sync group. A sync group is devices that keep chosen data the same (people, access, lists, settings, punches). The gateway does the syncing. M.sync says what the package’s devices take and report. Nothing undeclared is sent to them. A package without M.sync is never sent anything by a group.
M.sync = { people = { accept = { -- what a device takes of a person user_id = { pattern = "^[1-9][0-9]{0,8}$" }, -- a regular expression, not a Lua pattern fields = { name = { max_length = 24 }, role = true, enabled = false, valid_from = false, valid_to = false }, cards = { max = 1, max_bits = 32, formats = { "raw" } }, -- false: no cards keypad_pin = false, -- or { max_length = 8 } password = { max_length = 8 }, credentials = function(info) -- kind -> format tags it takes local c = { photo = { "jpeg" } } if info.fp_version then c.fingerprint = { "acme:fingerprint:" .. info.fp_version } end return c end, photo_max_bytes = 65536, rename = false, -- true: it offers rename_user settle = "count_punches", -- a command or action run before a replace verify = { present = "check_user", absent = "check_user_gone" }, delete_leaves_bytes = false, }, report = { user = true, deleted = true, biometric = true, photo = true, inventory = "query_users", counts = "user_count", inventory_complete = "count" }, }, access = { accept = { schedule = { slots = { 26, 50 }, intervals_per_day = 1 }, holiday = { slots = { 26, 50 } }, access_group = { slots = { 50, 99 }, schedules = 3, doors = 1 }, per_user = { access_groups = 1 } } }, lists = { accept = { work_code = { max = 1000, key = { pattern = "^[0-9]{1,8}$" }, name = { max_length = 24 } }, message = { text = { max_length = 320 }, user_ids = true } }, report = { work_code = true } }, settings = { class = "acme-tft", report = true }, punches = { mode = "pull", asks = { "last_punch" } },}| Key | |
|---|---|
people.accept.user_id | { pattern }: the ids a device takes. |
people.accept.fields | name, role, enabled, valid_from, valid_to: true, false, or { max_length }. |
people.accept.cards | false, true, or { max, max_bits (1 to 128), formats }. |
people.accept.keypad_pin, password | false or { max_length }. |
people.accept.credentials | Each kind (fingerprint, face, face_photo, palm, finger_vein, iris, photo) maps to the format tags it takes. A tag is <vendor>:<kind>:<version> (acme:face:12), exactly as the package’s biometric events carry them. For photo and face_photo, the tag is jpeg. |
people.accept.photo_max_bytes | The largest photo it takes. |
people.accept.rename | true means it renames users in place (rename_user). Otherwise an id change is a replace. |
people.accept.settle | A command or action run before a replace, to make sure of punches under the old id. |
people.accept.verify | For a device without an inventory. present and absent are actions or commands that take user_id. They succeed only when the device has (has not) the user. A package whose device can only upload its inventory cannot confirm a user is gone. This is because an upload without the user may be partial. An id change goes on unverified there. The daily inventory is the backstop. A firmware command that answers for one user, present or not, would let such a package declare absent and confirm. |
people.accept.delete_leaves_bytes | true means a deleted user’s data stays in the device’s memory until reused. |
people.report | user, deleted, biometric, photo: true means it emits user, user.deleted, biometric, user.photo events. inventory: an action that makes the device upload every user. counts: the info key holding how many users it holds. inventory_complete: how the engine knows an upload is complete. The value count means the number of users uploaded equals the counts value the device reports after the upload. So the inventory action must end with the step that reports it. Absent: the upload is never compared. The inventory is closed and counted (houradvantage_sync_inventory_uncompared_total{why="unverifiable"}). This is safer than guessing. counts_action (needs counts): an action that makes the device say its count of users now. The engine asks it of a member at the head of the log with nothing on its way to it, once for each log position. A count below what the member should hold calls for its inventory (once for each count and position). A package without counts_action is asked for its inventory once a day only (and on join and resync). A count the device happened to report with a message is not read, because it may have been said before its last batch was taken. |
access.accept | schedule (slots, intervals_per_day), holiday (slots), access_group (slots, schedules, doors), per_user.access_groups. |
lists.accept | work_code, job_code, tip_code, message: true, or { max, key = { pattern }, <field> = { max_length } or true }. |
lists.report | The lists it emits list.item events for. |
settings | class (default <name>@<major.minor>) and report (true means it reports settings with read_settings). |
punches | mode is pull (it asks the group with a lookup) or push (the group sends set_punch_state). Left out, punches are only marked. asks lists the lookups its routes make (last_punch, check). pull needs at least one. |
- Any value may be a function of the device’s
info, so one package can say what each model takes. The gateway resolves it per device, and again wheninfochanges. - A domain left out does not apply to the package’s devices. A field, card or credential kind left out (or
false) is not sent to them. A row that does not fit a device is reported unsupported for that device, and is not converted. Examples are an id the pattern refuses, a PIN too long, and a template in another format. Two things are sent in part instead. A name longer thanfields.name.max_lengthis cut to it. Cards pastcards.maxare left out. Each is listed as omitted in the member’s row. slots = { first, last }is the range of the device’s slots the group owns for that kind. It is required. The group’s first row of the kind goes infirst, the next infirst + 1, and so on. A row that would land pastlastis unsupported on that device. Pick the top of the device’s range. Slot 1 is usually a factory default, and installers number their own from the bottom.- Devices share settings only within a class. Give several packages one class only when their registries use the same names with the same meanings. Settings with a
standardname are shared across classes. - What it needs is checked at load.
people.acceptneeds the standard actionsupsert_useranddelete_user. Templates needset_biometricanddelete_biometrics. Photos needset_user_photo.rename = trueneedsrename_user.access.acceptneedsset_<kind>anddelete_<kind>.lists.acceptneedsset_list_itemanddelete_list_item.settingsneeds a registry andset_settings(report = truealso needsread_settings).punches.mode = "push"needsset_punch_state.asksneeds a route with alookup.settle,verifyandinventorymust name a command or an action it offers. Unknown keys fail the load, so a misspelt limit never reads as “no limit”. - Every action a group sends must give the same commands when built again from the same parameters (the gateway may send it twice). The scenario runner builds each such action twice and compares.
Lookups
Section titled “Lookups”A route may ask the sync group something before it answers:
{ name = "last_punch", description = "The clock asks for a user's last punch.", match = function(req) return req.path == "/acme/last" end, lookup = function(req) return { last_punch = req.query.user } end, handle = function(req, ctx) local p = ctx.sync and ctx.sync.last_punch -- nil: no group, or nothing recent if not p then return "NONE" end return json.encode(p) end }lookup(req, ctx) is called only when the endpoint is in a sync group that shares punches. It may ask only what punches.asks declares (last_punch = <user_id>, check = { user_id, reader, direction }). Returning nil asks nothing. The answer is in ctx.sync. Without a group, the route runs with no ctx.sync.
Effects
Section titled “Effects”Effects change state. They are allowed only where the table says. Anywhere else, calling one is an error. That includes identify, verify, supports, a command’s build, an action’s expand and package load.
| Call | Where | Effect |
|---|---|---|
emit(type, data, key?) | routes | Produces an event. key identifies the record. The same record must give the same key, and a changed record a different one (the whole line is usually right). Without a key the data is the identity. At most 10,000 events per call. |
report(fields) | routes | Merges facts into the device’s info (firmware, counts, capabilities). |
store.get(key), store.set(key, value) | routes | Per-device state that persists between messages. Writes are kept only if the message’s events were stored. |
queue.pending{ ... } | routes, outbound | The commands one reply carries, chosen by the engine from the device’s waiting commands (handing out commands). |
queue.mark_sent(ids) | routes, outbound | These commands were written into a reply to the device. They are offered. |
queue.result(id, code, text?, ok?) | routes | The device reported a command’s result. Without ok, the command’s success rule decides. text may be binary (a file the device was asked for). When it is not valid UTF-8 it reaches consumers whole, as result_base64. An id that is not a number is ignored. |
queue.retry(id, seconds, text?) | routes | Not done yet. The same command goes again no earlier than seconds later (1 to 86400), until its action expires. Its command.result event carries retry_in. A command with sensitive parameters fails instead. |
queue.add(action, params?) | routes, set_key | Queues one of the package’s own commands for the device (settings it must be given when it connects, say). It is checked and built like a command sent from outside. It is queued only if the message’s events were stored. At most 64 per call. |
A device’s messages are handled one at a time, so reading the store, changing a value and writing it back is safe.