Add the list block and the module layer with the note module
Security / Vulnerability check (push) Successful in 41s
Test / Lint and test (push) Successful in 1m50s

The list block prints items with a dot, dash, number or checkbox bullet,
wrapping a long item with a hanging indent; a checkbox list ticks its
done items as [√], or [x] on code pages without √. It stands alone or
inside a box, and its items, bullet and done fields carry their enums
and limits as jsonschema tags.

internal/pkg/modules holds modules that build ordinary jobs from their
own payloads: a registry by name, an Env with the clock, time zone and
time layout, strict payload decoding that reports every problem, ErrSkip
and PayloadError. The note module prints a boxed note with an optional
checklist and a time stamp in the footer.

Three routes join the route table: POST /api/v1/print/{module} and
POST /api/v1/preview/{module}, which take ?copies and a reserved
?printer, and GET /api/v1/modules. Print and the module route share one
submit path, and preview shares one too. New error codes:
invalid_payload, invalid_query, unknown_printer, module_not_found and
module_failed; a module that builds an invalid receipt is logged and
reported to Sentry once. [format] gains timezone and time_layout, the
binary embeds the time zone database, and uberbringer preview takes
--module.

The note receipt passed on the TM-T88IV, and its bytes are pinned in
TestPaperReceipts. docs/api.md describes the list block, the module
routes and the note payload; docs/swagger.json is regenerated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
57_WolveandClaude Opus 5.5 committed 2026-11-30 10:55:50 -06:00
1 parent 6b2e402f1a
commit 3e9779f71a
69 files changed
+3092 -262

No files matched your search

+35 -2
View File
@@ -73,6 +73,38 @@ client ─HTTPS─▶ Caddy ─▶ server ── validate ──▶ printqueue (
(owner, 2026-11-30), so `printer.box_line_spacing` stays 0 by default.
The bytes of that calibration receipt, `examples/blocks.json`, are
pinned in a receipt test.
- A `list` follows the same rules. `done` is a set of indexes into
`items`, so an index out of range or given twice is a validation
problem, and so is an empty item. A done item's `√` prints as `x` where
the code page lacks it.
- **Modules build ordinary jobs.** A module (`internal/pkg/modules`) turns a
plain payload into a `receipt.Job` made of the existing elements and
blocks, which then takes the same path as a `/print` job: validation, the
queue and the renderer. Payload text only lands in string fields of
elements, so a module cannot send printer commands.
- Payloads are decoded strictly and report every problem at once. Field
names match exactly, not case-insensitively as `encoding/json` would.
Decoding problems are reported before the module's own checks, because a
field of the wrong type would otherwise also be reported as missing.
- A module checks its payload for everything the blocks would refuse, and
words the problems in the payload's terms (`done[0]: index 5 is out of
range`). A built job that still fails validation is a bug in the module:
the client gets `422` `module_failed` with the problems, and it is
logged and reported to Sentry once, without the problems, which can
quote the payload.
- A module never reads the clock. It gets the time, zone and layout in an
`Env`, from `format.timezone` and `format.time_layout`, so its output is
reproducible in tests. The binary embeds the zone database, because
Windows and slim containers have none.
- Module routes take `copies` and the reserved `printer` (only `default`
until a second printer is configured) in the query. Any other parameter
is refused, for the same reason unknown config keys are: a typo must
not be ignored.
- The registry lists modules sorted by name.
- The module routes are entries in the route table like any other. The
OpenAPI document describes their body as a JSON object whose fields the
module defines, not as a strict schema: one route serves every module,
and each module checks its own payload.
- **The preview reads the bytes back.** `escpos.Interpret` parses the stream
the renderer produced, so the preview and the tests show what the printer
receives rather than what the layout meant. It simulates the printer's own
@@ -162,8 +194,9 @@ client ─HTTPS─▶ Caddy ─▶ server ── validate ──▶ printqueue (
## Planned: formatters
Modules, ntfy among them, that turn plain input into receipts built from the
blocks. The plan is `docs/plans/formatters.md`; its first phase, the blocks
and the preview, is built. Decided so far (owner, 2026-11-29):
blocks. The plan is `docs/plans/formatters.md`. Its first two phases are
built: the blocks and the preview, then the `list` block, the module layer
and the `note` module. Decided so far (owner, 2026-11-29):
- ntfy is an input: its notifications are printed. The server is
self-hosted at a public URL, the subscriber authenticates with a token, and