Skip to content

Packages and Lua

Both engines keep what varies between customers out of their code. They keep it in Lua packages. Connect speaks every vendor’s protocol through protocol packages. Connect takes each tenant’s decisions at the clock through Connect policy packages. Time and Attendance applies every employer’s rules through policy packages of its own. These are layers of the standard steps, with Lua only where a rule needs steps of its own. This page compares the three kinds and what they share.

Protocol packagesConnect policy packagesTime and Attendance policy packages
EngineConnectConnectTime and Attendance
What one holdsA device protocol. It holds the messages a device sends (routes) and the commands it takes, translated both ways.A tenant’s decisions at its hooks. They cover routing a punch, a clock joining, moving or coming back, and a person enrolled at a clock.Rules. They are layers of steps such as rounding, thresholds, premiums and accruals. Each step declares its stage.
WhoseThe install’s.A tenant’s own, or a shared one it adopted.A tenant’s own, or a shared one it adopted. Also the standard package the engine ships.
Chosen byAn endpoint (package = "[email protected]").An endpoint (policy = "clock-lifecycle@1").Its layers, in the tenant’s policy (uses = "standard/threshold").
Configured byThe endpoint’s options.Its own code. Also the labels and routes it reads.The step’s parameters, layer by layer.
Host functionsParsing and encoding (time, bytes, text, xml, csv, crypto…). Also a shared library.What a hook is given. What it returns.time, and the ctx of each stage.
Limits per call500 ms, 32 MB.The package limits, as for protocol packages.2 s per step and window, 64 MB.
Tested byScenarios. Device messages go in. Events and replies come out (hourctl pkg test).Scenarios. A hook’s arguments go in. Its decision comes out (hourctl pkg test).Scenarios. Facts go in. Ledgers come out (hourctl attend test).
Official onesZKTeco PUSH, and others.The recipes.The standard steps and the cookbook.
GuidesWriting, developing.Connect policy packages.Writing policy steps.

A package’s package.toml says which kind it is. A Connect policy package has kind = "policy". A protocol package has none.

Every kind runs in the same sandboxed Luau runtime. Each engine adds only its own host functions.

  • Checked when added. Source that does not compile is refused when the package is added. The refusal gives the file and line.
  • Sandboxed. No files, no network, no os, no access to another call’s state. A package does what its host functions let it and nothing else.
  • Limited. Every call has a time limit, checked while it runs. Every VM has a memory limit. A call that runs over is stopped with an error naming it.
  • Isolated. No call ever sees what another call left behind. A policy step that changes what its package holds fails the ledger.

Neither engine trusts a package it cannot test offline. Neither takes one whose scenarios fail. A protocol package carries scenarios. Every route and command must be covered by one. A Connect policy package’s scenarios call each of its hooks. An untested hook fails the run, as an untested route does.

Time and Attendance’s rules are pinned the same way. Each scenario is one person’s facts and policy, with the ledger they must come to. Every package’s scenarios run again on the server when it is pushed. A package whose scenarios fail is kept as a failed revision. It is refused and never activated.

Every kind is kept in the database as revisions. Revisions are pushed as bundles. A revision is activated (or published) only once its scenarios pass.

  • Protocol packages are the install’s. They are activated per line (name and major.minor version). Endpoints name them (packages).
  • Policy packages of either engine are a tenant’s own, or shared. Whoever runs the install publishes a shared package once for the whole install. A state’s rules kept up to date as the law changes, or a franchisor’s pay rules, are examples. Each tenant that wants a shared package adopts it. The tenant follows a major version, so each version of it published reaches the tenant. Or the tenant pins one. A version published never changes. A fix is a new version. Each tenant that takes another version is told with package.updated (Connect, Time and Attendance).

Connect’s packages, shared versions and adoptions move between environments with the setup. The commands are hourctl promote --policy, --shared and --adoption. hourctl diff lists what differs (environments, hourctl promote).