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
@@ -18,6 +18,12 @@ REST API and prints them on an EPSON ESC/POS network receipt printer.
|
||||
checkbox lists, sized to the paper when the job prints.
|
||||
- **Modules**: send a few plain fields, such as a note's title, text and
|
||||
checklist, and get a laid-out receipt back.
|
||||
- **Notifications**: print [ntfy](https://ntfy.sh) messages as they arrive,
|
||||
through the ntfy client with no other tools, or post a title, message,
|
||||
priority and tags from any script. Each prints as a card styled by its
|
||||
priority, with links as QR codes.
|
||||
- **Scoped tokens**: integration tokens reach only their modules, and only
|
||||
tokens issued for it can send raw ESC/POS.
|
||||
- **Preview**: see the exact lines a job prints, without using paper.
|
||||
- **Images that print well**: PNG, JPEG, GIF or WebP from a URL or base64,
|
||||
scaled to the paper and dithered. Image URLs can't reach internal network
|
||||
@@ -148,7 +154,9 @@ Every key can also be set by an environment variable named
|
||||
`false` for a flag, `5s` for a duration. Lists take comma-separated values,
|
||||
e.g. `UBERBRINGER_WEBSERVER_TRUSTED_PROXIES=127.0.0.1,::1`; an empty item,
|
||||
from a doubled or trailing comma, is an error. In the file, a number, flag
|
||||
or list may also be written as such a string.
|
||||
or list may also be written as such a string. A table of your own entries,
|
||||
`ntfy.markers`, takes `name=value` entries separated by commas, e.g.
|
||||
`UBERBRINGER_NTFY_MARKERS=backup=[B],nas01=`; a value cannot hold a comma.
|
||||
- An empty variable counts as unset, and one that holds only spaces is an
|
||||
error. Variables that name no key are ignored, but when the configuration
|
||||
fails to load, the error names them, since they are likely misspelt.
|
||||
@@ -193,6 +201,19 @@ Settings worth knowing:
|
||||
notation, in which `02 Jan 2006 15:04:05` stands for the parts of a date,
|
||||
e.g. `2006-01-02 15:04`. A layout that shows no part of a date is an
|
||||
error.
|
||||
- `[ntfy.format]` shapes the [notification cards](docs/api.md#notification-cards)
|
||||
of the `notify` and `ntfy` modules:
|
||||
|
||||
| Key | Default | Values |
|
||||
|-----|---------|--------|
|
||||
| `style` | `auto` | `auto` picks the form from the priority; `box` prints priorities 1 and 2 in a box too; `compact` prints every priority without a box |
|
||||
| `max_lines` | `40` | 1–400 lines of the message, as written, before `... N more lines` |
|
||||
| `qr` | `all` | Which links print as QR codes: `all`, `first` (the rest as text) or `none` |
|
||||
| `images` | `true` | `false` names attached images on a `File` row instead of printing them |
|
||||
| `markdown` | `true` | `false` prints markdown messages as written |
|
||||
- `[ntfy.markers]` adds or changes the [markers](docs/api.md#markers)
|
||||
printed for tags, at most 16 characters each, and `""` hides a tag:
|
||||
`backup = "[B]"`, `nas01 = ""`.
|
||||
- `webserver.trusted_proxies` / `proxy_header`: the real client IP for
|
||||
per-client rate limits comes from the `X-Real-IP` header set by the reverse
|
||||
proxy (Caddy, as `install.sh` configures it) on `127.0.0.1`.
|
||||
@@ -210,12 +231,18 @@ Settings worth knowing:
|
||||
`request_id`, and one Sentry event.
|
||||
- A recovered panic adds one ERROR `panic` line, with `panic` and `stack`,
|
||||
and one Sentry event.
|
||||
- A print job that fails after its retries is logged as ERROR `job failed`
|
||||
with its `job_id`, and is reported to Sentry.
|
||||
- The worker logs each job with its `job_id`, its `source` (`print` or
|
||||
`module:<name>`) and its `ref`, the ID of the request that sent it, never
|
||||
with what it prints. A job that fails after its retries is logged as
|
||||
ERROR `job failed` and is reported to Sentry.
|
||||
- A module that builds an invalid receipt (`422` `module_failed`) is
|
||||
logged as ERROR `module built an invalid receipt`, with the `module` and
|
||||
the number of `problems` but not the problems themselves, and is
|
||||
reported to Sentry once.
|
||||
- A notification card that cannot be laid out prints as a plain receipt,
|
||||
and is logged as ERROR `module printed its fallback receipt`, with the
|
||||
`module`, the cause in `err` and, after a panic, its `stack`, and is
|
||||
reported to Sentry once. Neither quotes the notification.
|
||||
- Refusals are never logged at ERROR and never go to Sentry. Refusals are
|
||||
4xx answers other than `module_failed`, the `queue_full` and
|
||||
`shutting_down` 503s, and 503s from `/healthz`.
|
||||
@@ -226,16 +253,27 @@ Settings worth knowing:
|
||||
uberbringer [--config config.toml] run the daemon (default command)
|
||||
uberbringer secret print a new random API secret
|
||||
uberbringer token [--subject s] [--ttl 720h] print a signed bearer token
|
||||
[--modules ntfy,notify] [--raw] ... limited to modules, or able to print raw ESC/POS
|
||||
uberbringer preview [file.json|-] show the lines a job would print
|
||||
uberbringer preview --module note [file|-] show the receipt a module builds
|
||||
uberbringer config get <key> print one setting, e.g. webserver.port
|
||||
uberbringer version print the version
|
||||
```
|
||||
|
||||
`token` signs a token with `api.secret`. Without flags, it may use every
|
||||
route but cannot print jobs with `raw` elements:
|
||||
|
||||
- `--raw` lets it print them. Give it only to clients that send ESC/POS
|
||||
bytes of their own.
|
||||
- `--modules ntfy,notify` limits it to those modules' print and preview
|
||||
routes, job status and the module list. Give integrations, such as the
|
||||
[ntfy client](docs/api.md#printing-from-the-ntfy-client), one of these.
|
||||
The names must be modules the daemon has, and `--raw` cannot be added.
|
||||
|
||||
`config get` prints a setting as the daemon would use it, from the file,
|
||||
`UBERBRINGER_*` variables and the defaults, and fails when the configuration
|
||||
does not load. Durations print as `15s`, lists comma-separated. It never
|
||||
prints `api.secret`.
|
||||
does not load. Durations print as `15s`, lists comma-separated, and tables
|
||||
as sorted `name=value` entries. It never prints `api.secret`.
|
||||
|
||||
Every command that reads the config takes `--config` (`-c`); see
|
||||
[Configuration](#configuration) for its default and for running without a
|
||||
@@ -313,7 +351,8 @@ internal/app/uberbringer/ CLI commands and wiring
|
||||
internal/pkg/config/ Config from TOML and UBERBRINGER_* variables (Viper): defaults, validation
|
||||
internal/pkg/escpos/ ESC/POS command builder, code pages, barcodes, QR, raster, status, interpreter
|
||||
internal/pkg/receipt/ Job format, validation, text folding, word wrap, blocks, rendering, preview
|
||||
internal/pkg/modules/ Modules that build jobs from plain payloads, such as note; strict payload decoding
|
||||
internal/pkg/modules/ Modules that build jobs from plain payloads: note, notify, ntfy; notification cards, markdown
|
||||
internal/pkg/ntfy/ ntfy's message types
|
||||
internal/pkg/raster/ Image decoding, scaling and dithering
|
||||
internal/pkg/safehttp/ SSRF-guarded image fetching
|
||||
internal/pkg/printer/ TCP printer client (port 9100) and status queries
|
||||
|
||||
Reference in new issue
Block a user