Add the notify and ntfy modules and scoped tokens
Breaking: a job with a raw element prints only with a token issued with uberbringer token --raw. Every other token, every existing one included, gets 403 token_scope for it, with the raw elements in details, and keeps every other route. The notify module prints a notification card from a title, message, priority and tags, with topic, click, up to three actions, image, markdown and time as options; it decodes strictly and refuses a payload over its length caps. The ntfy module takes one ntfy message as ntfy sends it, such as the ntfy client's $NTFY_RAW, ignores fields it does not know, cuts text over the caps, and answers 204 for other events and binary bodies. Both print every message plain: one message cannot tell the first of a sequence from a replacement, since a publisher may choose the sequence ID. internal/pkg/ntfy holds ntfy's message types. Both print the same card. The priority picks the form: a dark URGENT rule and a double box, a double box headed HIGH, a single box with the title in its border, or a rule with no box. Tags print as markers in front of the title, the rest on a Tags row; links print as QR codes with their labels; attached PNG, JPEG, GIF and WebP images print after the card. A line-level markdown subset is laid out without a dependency, keeping marks inside code spans and URLs, and emoji are removed after a few typed ones become markers. A card that cannot be laid out prints as a plain receipt, and the server logs the fault once at ERROR and reports it to Sentry once. [ntfy.format] and [ntfy.markers] shape the cards; the markers table is a setting with the user's own keys, also settable as UBERBRINGER_NTFY_MARKERS=name=value,... uberbringer token --modules issues a token limited to those modules' print and preview routes, job status and the module list; each route in the table says which tokens it takes, and a scope claim that could read as absent makes the token invalid. image elements take optional, which also shrinks a too-wide image to the paper; a QR code that could be too wide for the paper prints with smaller modules; box takes title_bold. Submit takes a Meta whose source shows in job status and, with a copy of the request ID, in every worker log line of the job. The four ntfy cards passed on the TM-T88IV, posted as the client recipe posts them, and their bytes are pinned in TestPaperReceipts. docs/api.md describes the modules, the card and the client recipe, with tokens read from a header file; docs/swagger.json is regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fa15cb27b1
commit
1335ed0687
119 files changed
+5626
-468
No files matched your search
+99
-4
@@ -105,6 +105,89 @@ client ─HTTPS─▶ Caddy ─▶ server ── validate ──▶ printqueue (
|
||||
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.
|
||||
- **Notifications print as one card.** The `notify` and `ntfy` modules turn
|
||||
their payloads into a `Notice` and lay it out with the same `Card`, which
|
||||
phase 4's subscriber will use too.
|
||||
- `ntfy` decodes leniently, so that messages from newer ntfy versions
|
||||
still print, while `notify`, which scripts write by hand, is strict like
|
||||
`note`. A message without an `event` counts as a message, so that a
|
||||
hand-made body does not silently print nothing.
|
||||
- The routes print every message plain, never marked `(updated)` and
|
||||
never skipped as an update (owner, 2026-11-30). A publisher may choose
|
||||
a message's sequence ID, so the first message of a sequence can carry
|
||||
one that differs from its ID, and one message cannot tell a first from
|
||||
a replacement. Only the subscriber, which remembers what it printed,
|
||||
can mark replacements.
|
||||
- The priority picks the form; `[ntfy.format] style` can force the box or
|
||||
the boxless form. The default form prints its title bold in the top
|
||||
border, so `box` has `title_bold`; it is a field of its own because
|
||||
making every box title bold would change receipts already checked on
|
||||
paper.
|
||||
- Emoji are removed on this path rather than printed as `?`, after a few
|
||||
typed ones become markers. `receipt.StripEmoji` keeps the symbols among
|
||||
the emoji ranges that some code page prints or folds (`■ → ✓`), since
|
||||
a module does not know the configured code page. A title or tag that
|
||||
is only emoji counts as missing.
|
||||
- The markdown subset is line by line and hand-written, with no
|
||||
dependency: a card needs bold lines, lists, dividers and links, not
|
||||
full CommonMark. Emphasis inside a word follows CommonMark, so `2*3*4`
|
||||
loses its stars; `_` inside a word stays, and so does every mark inside
|
||||
a code span or a bare URL, such as `__init__.py`. As in GitHub's
|
||||
autolinks, marks and punctuation at a URL's end are not part of it, so
|
||||
`**https://x.lan**` is bold around a whole URL.
|
||||
- A module lays out a job before it knows the printer, so its lengths are
|
||||
capped in characters, not lines: title 250, topic 64, 20 tags of 64,
|
||||
labels 64, file names 128, links 2000 bytes and the message 4096 bytes,
|
||||
ntfy's own default. `notify` refuses a payload over a cap. From an ntfy
|
||||
message a card cuts the text over a cap and leaves out the tags after
|
||||
the 20th and the links over 2000 bytes, and names an attachment with
|
||||
such a URL on a `File` row. A card then prints well inside the default
|
||||
`format.max_lines` of 2000, even on 58 mm paper; with a much lower
|
||||
limit a long card can still fail when it renders, which stays the
|
||||
backstop, as for `/print`. `ntfy.format.max_lines` counts the
|
||||
message's lines as written and is at most 400, so that a card stays
|
||||
under the 500-element limit.
|
||||
- Links print as QR codes, size 5, and the renderer narrows a code's
|
||||
modules until it fits the paper; a link over 500 bytes prints as text.
|
||||
Only view actions and the click URL become links; `http`, `broadcast`
|
||||
and `copy` actions can carry secrets in their headers, bodies and
|
||||
values and never print.
|
||||
- Only PNG, JPEG, GIF and WebP attachments print as images, the formats
|
||||
the renderer decodes; any other `image/*` type is named on a `File` row
|
||||
rather than printed as `[image unavailable]`. Attached images are
|
||||
`optional` images 384 dots wide, which the renderer shrinks to a
|
||||
narrower paper: an optional image never fails for its width. `optional`
|
||||
is an image-only field; the other older types refuse it as they refuse
|
||||
the block fields.
|
||||
- A card always prints: a layout that panics or builds an invalid job
|
||||
gives a plain receipt of title, message, topic and time. `Card` returns
|
||||
the fault with it, and the server logs it once at ERROR, with the
|
||||
panic's stack, and reports it to Sentry once, as for any unexpected
|
||||
error, without quoting the notification.
|
||||
- The card options travel in the module `Env`, and their zero value is
|
||||
the default, so a module built without config still prints sensibly.
|
||||
- **Tokens carry their scope (owner, 2026-11-30).** Integration tokens must
|
||||
not send printer commands, and the owner chose to fence raw ESC/POS off
|
||||
for every token rather than only for new ones.
|
||||
- A `mod` claim limits a token to the module routes it names, plus job
|
||||
status and the module list. Each route in the table says whether such
|
||||
tokens may use it, and the check runs before the handler.
|
||||
- Printing a job with a `raw` element needs a `raw: true` claim
|
||||
(`uberbringer token --raw`). Tokens without it, every older token
|
||||
included, keep every other route, so only clients that send raw hex
|
||||
need a new token. Previewing raw elements stays open, since a preview
|
||||
sends nothing to the printer.
|
||||
- A scope claim that could read as absent makes the token invalid
|
||||
(`401`): one of the wrong type, `mod` given as `null`, and `mod` or
|
||||
`raw` written in another letter case, which `encoding/json` would
|
||||
match. A malformed scope can therefore never widen access.
|
||||
- **Jobs remember their source.** `Submit` takes a `Meta`: the source
|
||||
(`print`, `module:<name>`, later `ntfy:<subscription>`) and a reference,
|
||||
the request ID on the HTTP routes. Job status shows the source and every
|
||||
worker log line of the job carries both, so a printed receipt can be
|
||||
traced to its request without logging what it says. The server copies
|
||||
both strings, since a request ID the client sent lives in a buffer that
|
||||
fasthttp reuses for the next request.
|
||||
- **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
|
||||
@@ -118,6 +201,13 @@ client ─HTTPS─▶ Caddy ─▶ server ── validate ──▶ printqueue (
|
||||
its own edge (`seve` / `ral`). A profile wider than the printer breaks
|
||||
words, while a narrower one only shortens lines. So `tm-t88` (512 dots, 42
|
||||
columns) is the default.
|
||||
- A QR code is fitted to the paper the same way. The printer encodes it
|
||||
and picks the mode, so its width is worked out from the bytes each QR
|
||||
version holds, byte mode being the least dense: a code that could be
|
||||
wider than the paper prints with smaller modules instead of running off
|
||||
the edge, and one of digits or capitals may shrink before it strictly
|
||||
has to. Data that only a denser mode holds counts as the largest
|
||||
version.
|
||||
- **Status is read in a way that tolerates a busy printer.** `/healthz` sends
|
||||
DLE EOT 1 to 4 over the same connection slot that sends use.
|
||||
- The DLE EOT 2 bits (cover open, paper-end stop) are cleared while DLE
|
||||
@@ -157,7 +247,8 @@ client ─HTTPS─▶ Caddy ─▶ server ── validate ──▶ printqueue (
|
||||
hand. The server gets the document in its config, so the generator does
|
||||
not build the package that embeds its own output.
|
||||
- **What stays compatible with 0.1.** The endpoint, the HS256 tokens and the
|
||||
config keys stay as they were. The 0.1 body and its plain-text answer do
|
||||
config keys stay as they were, though a job with raw elements now needs a
|
||||
token issued with `--raw`. The 0.1 body and its plain-text answer do
|
||||
not. A 0.1 body gets a `400` that points to the element format in
|
||||
`docs/api.md`, instead of being translated. Tokens are read only from the header, because tokens in
|
||||
query strings end up in proxy logs.
|
||||
@@ -172,6 +263,9 @@ client ─HTTPS─▶ Caddy ─▶ server ── validate ──▶ printqueue (
|
||||
variable, which wins over the file, so a container can run without one.
|
||||
Unknown keys in the file stay errors; unknown variables are ignored,
|
||||
because the environment holds much besides Überbringer's settings.
|
||||
A table whose keys are the user's own, such as `ntfy.markers`, is one
|
||||
setting: its variable holds `name=value` entries separated by commas,
|
||||
and in the file a name with a dot or a nested table is an unknown key.
|
||||
- `go.mod`'s go line is the latest Go release, with no separate toolchain
|
||||
line.
|
||||
- **Packaging.** The daemon serves no TLS itself and binds 127.0.0.1 by
|
||||
@@ -194,9 +288,10 @@ 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 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):
|
||||
blocks. The plan is `docs/plans/formatters.md`. Its first three phases are
|
||||
built: the blocks and the preview; the `list` block, the module layer and
|
||||
the `note` module; then the `notify` and `ntfy` modules and scoped tokens.
|
||||
Next is the built-in ntfy subscriber. 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
|
||||
|
||||
Reference in new issue
Block a user