Move the API reference from the README to docs/api.md
docs/api.md holds the routes, elements, blocks, glyphs and error codes. README keeps the overview, installing, configuration, the command line and development, with a pointer to the API reference. The 0.1 migration section is dropped; the changelog's Breaking entries cover the 0.1 changes. Release archives include docs/api.md, and the 400 for a 0.1 job body points to it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
15f63b6846
commit
9f7c5db923
9 files changed
+479
-488
No files matched your search
+6
-3
@@ -42,15 +42,18 @@ builds:
|
|||||||
archives:
|
archives:
|
||||||
- formats: [tar]
|
- formats: [tar]
|
||||||
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
|
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
|
||||||
# Listing files replaces goreleaser's defaults, so the license, README and
|
# Listing files replaces goreleaser's defaults, so the license, README,
|
||||||
# changelog are listed too. Each must exist; paths are kept, and install.sh
|
# API reference and changelog are listed too. Each must exist; paths are
|
||||||
# takes packaging/uberbringer.service from the unpacked archive.
|
# kept, and install.sh takes packaging/uberbringer.service from the
|
||||||
|
# unpacked archive.
|
||||||
files:
|
files:
|
||||||
- src: LICENSE.txt
|
- src: LICENSE.txt
|
||||||
info: &commit-mtime
|
info: &commit-mtime
|
||||||
mtime: "{{ .CommitDate }}"
|
mtime: "{{ .CommitDate }}"
|
||||||
- src: README.md
|
- src: README.md
|
||||||
info: *commit-mtime
|
info: *commit-mtime
|
||||||
|
- src: docs/api.md
|
||||||
|
info: *commit-mtime
|
||||||
- src: CHANGELOG.md
|
- src: CHANGELOG.md
|
||||||
info: *commit-mtime
|
info: *commit-mtime
|
||||||
- src: configs/config.example.toml
|
- src: configs/config.example.toml
|
||||||
|
|||||||
+9
-7
@@ -17,8 +17,8 @@ upgrade a 0.1 install.
|
|||||||
|
|
||||||
- `POST /api/v1/print` takes `{"elements": [...]}` instead of
|
- `POST /api/v1/print` takes `{"elements": [...]}` instead of
|
||||||
`{"data": [...]}`. A body in the old format is refused with `400`
|
`{"data": [...]}`. A body in the old format is refused with `400`
|
||||||
`invalid_job`, and its message points to the README. README § Migrating
|
`invalid_job`, and its message points to `docs/api.md`, which describes
|
||||||
from the old format maps each 0.1 item type to an element.
|
the elements.
|
||||||
- `POST /api/v1/print` answers `202 Accepted` with a `Location` header and a
|
- `POST /api/v1/print` answers `202 Accepted` with a `Location` header and a
|
||||||
JSON job (`id`, `status`, `created_at`). 0.1 answered `200` with the text
|
JSON job (`id`, `status`, `created_at`). 0.1 answered `200` with the text
|
||||||
`OK - <id>`. Job IDs are `job_` TypeIDs instead of numbers.
|
`OK - <id>`. Job IDs are `job_` TypeIDs instead of numbers.
|
||||||
@@ -77,7 +77,7 @@ upgrade a 0.1 install.
|
|||||||
answer.
|
answer.
|
||||||
- A printer that looks not ready is read again 750 ms later, so a printer
|
- A printer that looks not ready is read again 750 ms later, so a printer
|
||||||
that is busy cutting or feeding raises no false alarm.
|
that is busy cutting or feeding raises no false alarm.
|
||||||
- A stable `code` in every error response, listed in README § Errors.
|
- A stable `code` in every error response, listed in `docs/api.md` § Errors.
|
||||||
Examples are `job_not_found` and `not_found` for `404`, and `queue_full` and
|
Examples are `job_not_found` and `not_found` for `404`, and `queue_full` and
|
||||||
`shutting_down` for `503`. A `405` carries `Allow`, and a `429` carries
|
`shutting_down` for `503`. A `405` carries `Allow`, and a `429` carries
|
||||||
`Retry-After`.
|
`Retry-After`.
|
||||||
@@ -110,9 +110,11 @@ upgrade a 0.1 install.
|
|||||||
- takes the printer address as its third argument;
|
- takes the printer address as its third argument;
|
||||||
- installs a given release with `UBERBRINGER_VERSION=vX.Y.Z`;
|
- installs a given release with `UBERBRINGER_VERSION=vX.Y.Z`;
|
||||||
- installs on arm64, armv7 and armv6 as well as amd64.
|
- installs on arm64, armv7 and armv6 as well as amd64.
|
||||||
- Release archives contain `LICENSE.txt`, `README.md`,
|
- Release archives contain `LICENSE.txt`, `README.md`, `docs/api.md`,
|
||||||
`configs/config.example.toml` and `packaging/uberbringer.service` next to
|
`CHANGELOG.md`, `configs/config.example.toml` and
|
||||||
the binary.
|
`packaging/uberbringer.service` next to the binary.
|
||||||
|
- `docs/api.md`, the API reference: routes, elements, blocks and error
|
||||||
|
codes. README covers installing, configuration and the command line.
|
||||||
- A weekly govulncheck run (Mondays 06:00 UTC, and on every push to main), so
|
- A weekly govulncheck run (Mondays 06:00 UTC, and on every push to main), so
|
||||||
a new advisory against unchanged dependencies is reported.
|
a new advisory against unchanged dependencies is reported.
|
||||||
- A Makefile for development. `make check` runs the CI gate in the same order,
|
- A Makefile for development. `make check` runs the CI gate in the same order,
|
||||||
@@ -131,7 +133,7 @@ upgrade a 0.1 install.
|
|||||||
|
|
||||||
`size` (1–3) and `font` scale a block's borders and text together. On
|
`size` (1–3) and `font` scale a block's borders and text together. On
|
||||||
cp850, cp858 and cp1252, glyphs the code page lacks fall back to ones it
|
cp850, cp858 and cp1252, glyphs the code page lacks fall back to ones it
|
||||||
has. README § Blocks lists the fields.
|
has. `docs/api.md` § Blocks lists the fields.
|
||||||
- `POST /api/v1/preview` and `uberbringer preview [file.json|-]` show the
|
- `POST /api/v1/preview` and `uberbringer preview [file.json|-]` show the
|
||||||
lines a job would print, read back from its rendered bytes, without
|
lines a job would print, read back from its rendered bytes, without
|
||||||
printing it or fetching images. The route answers plain text, or JSON with
|
printing it or fetching images. The route answers plain text, or JSON with
|
||||||
|
|||||||
@@ -13,8 +13,9 @@ root `Dockerfile`.
|
|||||||
Every change follows it. `.gitea/workflows/`, `packaging/`, the root
|
Every change follows it. `.gitea/workflows/`, `packaging/`, the root
|
||||||
`Dockerfile` and `install.sh` take the place of the standards' `build/` and
|
`Dockerfile` and `install.sh` take the place of the standards' `build/` and
|
||||||
`scripts/`.
|
`scripts/`.
|
||||||
- `README.md` is the reference for the API, elements, error codes,
|
- `docs/api.md` is the reference for the API: routes, elements, blocks and
|
||||||
configuration, command line and package layout. There is no api.md or
|
error codes. `README.md` covers installing,
|
||||||
|
configuration, the command line and the package layout. There is no
|
||||||
OpenAPI document.
|
OpenAPI document.
|
||||||
- `docs/design.md` explains why the daemon is shaped as it is and lists what
|
- `docs/design.md` explains why the daemon is shaped as it is and lists what
|
||||||
is deferred. Change it in the same commit as any code that departs from it.
|
is deferred. Change it in the same commit as any code that departs from it.
|
||||||
@@ -59,8 +60,8 @@ pinned as tools in `go.mod`, so never install them separately.
|
|||||||
`.gitea/workflows/test.yml` runs the same gate, with `goreleaser check` in
|
`.gitea/workflows/test.yml` runs the same gate, with `goreleaser check` in
|
||||||
place of the snapshot, on every branch push. It builds no binaries: only
|
place of the snapshot, on every branch push. It builds no binaries: only
|
||||||
`release.yml` does, for `v*` tags on main. `security.yml` runs govulncheck
|
`release.yml` does, for `v*` tags on main. `security.yml` runs govulncheck
|
||||||
weekly and on pushes to main. A change is done
|
weekly and on pushes to main. A change is done when the gate passes and the
|
||||||
when the gate passes and README and CHANGELOG.md say what changed.
|
docs (`README.md` or `docs/api.md`) and CHANGELOG.md say what changed.
|
||||||
|
|
||||||
## Go version
|
## Go version
|
||||||
|
|
||||||
@@ -90,7 +91,8 @@ when the gate passes and README and CHANGELOG.md say what changed.
|
|||||||
is a timeout, never a printer fault. Anything that acts on status re-checks
|
is a timeout, never a printer fault. Anything that acts on status re-checks
|
||||||
first, as `/healthz` does.
|
first, as `/healthz` does.
|
||||||
- Every refusal is an `apiError` with a code from `server/errors.go`. A code is
|
- Every refusal is an `apiError` with a code from `server/errors.go`. A code is
|
||||||
part of the API: never rename one, and add a new code to the README table.
|
part of the API: never rename one, and add a new code to the table in
|
||||||
|
`docs/api.md`.
|
||||||
Refusals are not logged as failures. An unexpected error is logged and sent
|
Refusals are not logged as failures. An unexpected error is logged and sent
|
||||||
to Sentry once.
|
to Sentry once.
|
||||||
- Print contents, tokens and the API secret never reach logs or Sentry. The
|
- Print contents, tokens and the API secret never reach logs or Sentry. The
|
||||||
@@ -100,8 +102,8 @@ when the gate passes and README and CHANGELOG.md say what changed.
|
|||||||
- A config key: `internal/pkg/config` (the default and the validation),
|
- A config key: `internal/pkg/config` (the default and the validation),
|
||||||
`configs/config.example.toml` and README § Configuration.
|
`configs/config.example.toml` and README § Configuration.
|
||||||
- A route, element field, status or error code: its code, its tests and
|
- A route, element field, status or error code: its code, its tests and
|
||||||
README. A new route also needs its case in `TestRoutesConform`, which
|
`docs/api.md`. A new route also needs its case in `TestRoutesConform`,
|
||||||
fails for a route without one.
|
which fails for a route without one.
|
||||||
- Dependencies are at their latest stable release when added or bumped.
|
- Dependencies are at their latest stable release when added or bumped.
|
||||||
- Commit, push, tag or release only when the owner asks. Releases are
|
- Commit, push, tag or release only when the owner asks. Releases are
|
||||||
`vX.Y.Z` tags on `main`; `release.yml` refuses a tag whose commit is not on
|
`vX.Y.Z` tags on `main`; `release.yml` refuses a tag whose commit is not on
|
||||||
|
|||||||
@@ -32,10 +32,7 @@ REST API and prints them on an EPSON ESC/POS network receipt printer.
|
|||||||
## Contents
|
## Contents
|
||||||
|
|
||||||
- [Quick start](#quick-start)
|
- [Quick start](#quick-start)
|
||||||
- [API](#api)
|
- [API](#api), in [docs/api.md](docs/api.md)
|
||||||
- [Elements](#elements)
|
|
||||||
- [Blocks](#blocks)
|
|
||||||
- [Migrating from the old format](#migrating-from-the-old-format)
|
|
||||||
- [Configuration](#configuration)
|
- [Configuration](#configuration)
|
||||||
- [Command line](#command-line)
|
- [Command line](#command-line)
|
||||||
- [Development](#development)
|
- [Development](#development)
|
||||||
@@ -125,465 +122,8 @@ make run
|
|||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
All `/api/v1` routes need an `Authorization: Bearer <token>` header. Issue
|
[docs/api.md](docs/api.md) is the API reference: the routes, the print
|
||||||
tokens with `uberbringer token`. Tokens created by the old install script keep
|
elements and blocks, and the error codes.
|
||||||
working as long as the secret is unchanged. Tokens in query strings are not
|
|
||||||
accepted, because they leak into proxy logs.
|
|
||||||
|
|
||||||
Responses from `/healthz` and every `/api/v1` route, error responses
|
|
||||||
included, carry `Cache-Control: no-store`.
|
|
||||||
|
|
||||||
| Method | Path | Purpose |
|
|
||||||
|--------|--------------------|------------------------------------------|
|
|
||||||
| POST | `/api/v1/print` | Queue a print job |
|
|
||||||
| POST | `/api/v1/preview` | Show the lines a job prints, without printing it |
|
|
||||||
| GET | `/api/v1/jobs/:id` | Job status |
|
|
||||||
| GET | `/healthz` | Printer and queue health (no auth) |
|
|
||||||
| GET | `/` | Version information (no auth) |
|
|
||||||
|
|
||||||
### Print a receipt
|
|
||||||
|
|
||||||
```sh
|
|
||||||
curl -X POST https://printer.example.com/api/v1/print \
|
|
||||||
-H "Authorization: Bearer $TOKEN" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{
|
|
||||||
"elements": [
|
|
||||||
{"type": "rule", "style": "dark"},
|
|
||||||
{"type": "box", "fit": true, "padding": 3, "text": "!!! ACHTUNG !!!"},
|
|
||||||
{"type": "text", "text": "Überbringer", "size": 2, "bold": true, "align": "center"},
|
|
||||||
{"type": "feed"},
|
|
||||||
{"type": "text", "text": "Long paragraphs wrap at word boundaries for the paper width, so a word is never split across two lines."},
|
|
||||||
{"type": "text", "text": "Total: ", "newline": false},
|
|
||||||
{"type": "text", "text": "£12.50", "bold": true},
|
|
||||||
{"type": "qr", "data": "https://example.com", "align": "center"},
|
|
||||||
{"type": "feed", "lines": 3}
|
|
||||||
]
|
|
||||||
}'
|
|
||||||
```
|
|
||||||
|
|
||||||
The response is `202 Accepted` with a `Location` header:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{"id": "job_01kbx4n6m3ex8tq0wq3r5vrzq1", "status": "queued", "created_at": "2026-11-29T21:04:05Z"}
|
|
||||||
```
|
|
||||||
|
|
||||||
Job IDs are [TypeIDs](https://github.com/jetify-com/typeid): UUIDv7 values
|
|
||||||
with a `job_` prefix, so they sort by creation time.
|
|
||||||
|
|
||||||
### Job status
|
|
||||||
|
|
||||||
```sh
|
|
||||||
curl -H "Authorization: Bearer $TOKEN" https://printer.example.com/api/v1/jobs/job_01kbx4n6m3ex8tq0wq3r5vrzq1
|
|
||||||
```
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"id": "job_01kbx4n6m3ex8tq0wq3r5vrzq1",
|
|
||||||
"status": "done",
|
|
||||||
"attempts": 1,
|
|
||||||
"created_at": "2026-11-29T21:04:05Z",
|
|
||||||
"started_at": "2026-11-29T21:04:05Z",
|
|
||||||
"finished_at": "2026-11-29T21:04:06Z"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
`status` is `queued`, `printing`, `done` or `failed`. A failed job includes an
|
|
||||||
`error` field. The last `queue.history` finished jobs are kept.
|
|
||||||
|
|
||||||
### Preview a receipt
|
|
||||||
|
|
||||||
`POST /api/v1/preview` takes the same body as `/api/v1/print` and validates
|
|
||||||
it the same way, but prints nothing and fetches no images. It answers `200`
|
|
||||||
with the lines the printer would print, as `text/plain; charset=utf-8`:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
curl -X POST https://printer.example.com/api/v1/preview \
|
|
||||||
-H "Authorization: Bearer $TOKEN" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{"elements": [{"type": "box", "fit": true, "padding": 3, "text": "!!! ACHTUNG !!!"},
|
|
||||||
{"type": "qr", "data": "https://example.com"}]}'
|
|
||||||
```
|
|
||||||
|
|
||||||
```text
|
|
||||||
┌─────────────────────┐
|
|
||||||
│ !!! ACHTUNG !!! │
|
|
||||||
└─────────────────────┘
|
|
||||||
[qr: https://example.com]
|
|
||||||
- - - - - - - partial cut - - - - - - - -
|
|
||||||
```
|
|
||||||
|
|
||||||
- The preview is read back from the bytes the job renders to, so it shows
|
|
||||||
what the printer receives: wrapping, folded characters, `?` for missing
|
|
||||||
ones and the final cut.
|
|
||||||
- Centred and right-aligned text is indented as the printer places it,
|
|
||||||
counted in Font A columns. Text at a larger size shows each character
|
|
||||||
once.
|
|
||||||
- QR codes, barcodes, images, `raw` bytes and cuts print as placeholders
|
|
||||||
such as `[barcode ean13: 4006381333931]`, `[image 384 dots: logo.png]` and
|
|
||||||
`[raw 3 bytes]`.
|
|
||||||
|
|
||||||
With `Accept: application/json` the answer carries the styles too. For
|
|
||||||
`[{"type": "kv", "pairs": [{"key": "Total", "value": "£12.50", "bold": true}]},
|
|
||||||
{"type": "text", "text": "Thanks 🎉", "align": "center"},
|
|
||||||
{"type": "qr", "data": "https://example.com"}]`:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{"columns": 42, "codepage": "cp437", "line_count": 3,
|
|
||||||
"lines": [{"kind": "text", "text": "Total ............................. £12.50",
|
|
||||||
"runs": [{"from": 0, "to": 5, "bold": true}, {"from": 36, "to": 42, "bold": true}]},
|
|
||||||
{"kind": "text", "text": " Thanks ?"},
|
|
||||||
{"kind": "qr", "text": "[qr: https://example.com]", "data": "https://example.com"},
|
|
||||||
{"kind": "cut", "text": " - - - - - - - partial cut - - - - - - - -", "data": "partial"}],
|
|
||||||
"warnings": ["elements[1]: 1 character not in cp437 printed as ?"]}
|
|
||||||
```
|
|
||||||
|
|
||||||
| Field | Meaning |
|
|
||||||
|-------|---------|
|
|
||||||
| `columns` | Font A characters per line |
|
|
||||||
| `codepage` | The code page text is printed in |
|
|
||||||
| `line_count` | Lines the receipt prints, all copies counted: text lines, fed lines, and one for each QR code, barcode and image. [`format.max_lines`](#configuration) limits it |
|
|
||||||
| `lines[].kind` | `text`, `qr`, `barcode`, `image`, `raw` or `cut` |
|
|
||||||
| `lines[].text` | The line as it prints, or the placeholder |
|
|
||||||
| `lines[].runs` | Styled parts of `text`, in characters from `from` up to `to`: `bold`, `underline` (1 or 2), `invert`, `font` (`b`), and `width` and `height` when scaled. Plain Font A text at size 1 has no run |
|
|
||||||
| `lines[].data` | QR code or barcode data, the image URL (or `base64`), the number of raw bytes, or the cut mode |
|
|
||||||
| `warnings` | Elements with characters the code page lacks, and images wider than the paper |
|
|
||||||
|
|
||||||
A job that would print more than `format.max_lines` lines answers `422`
|
|
||||||
`too_many_lines`, for example `receipt would print 2412 lines, limit is
|
|
||||||
2000`. Sent to `/api/v1/print`, the same job is accepted and then fails
|
|
||||||
when the worker renders it, before anything is sent; its `error` reads
|
|
||||||
`rendering: receipt would print 2412 lines, limit is 2000`.
|
|
||||||
|
|
||||||
### Health
|
|
||||||
|
|
||||||
`GET /healthz` returns `200` when the printer is reachable and ready, and
|
|
||||||
`503` when it is unreachable or not ready (paper out, cover open, error).
|
|
||||||
|
|
||||||
```json
|
|
||||||
{"status": "ok", "printer": {"reachable": true, "status": "ready", "online": true, "cover_open": false, "paper": "near_end"}, "queue": {"pending": 0}}
|
|
||||||
```
|
|
||||||
|
|
||||||
A printer that accepts connections but does not answer status requests is
|
|
||||||
reported as `"status": "unknown"` with HTTP `200`.
|
|
||||||
|
|
||||||
Details:
|
|
||||||
|
|
||||||
- **Brief problems are re-checked.** A printer that looks not ready is read
|
|
||||||
again 750 ms later, and only a problem that is still there gives `503`.
|
|
||||||
While cutting or feeding, a printer can report a problem for a moment.
|
|
||||||
- **Timeouts.** The printer accepts one connection at a time. While it is still
|
|
||||||
taking in a large job, the 3-second health check can run out of time. That
|
|
||||||
gives `503` with printer status `"timeout"`, because the printer's state is
|
|
||||||
unknown.
|
|
||||||
- **The cover flag** is only reported while the printer is offline. Epson
|
|
||||||
printers always go offline when the cover opens.
|
|
||||||
- **Paper low on the TM-T88VII.** That model does not report paper near-end
|
|
||||||
through real-time status, so `"near_end"` never appears for it; paper out
|
|
||||||
is still reported.
|
|
||||||
|
|
||||||
### Errors
|
|
||||||
|
|
||||||
Errors are JSON:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{"error": "invalid job", "code": "invalid_job", "details": ["elements[2] (text): size, width and height must be 1-8"]}
|
|
||||||
```
|
|
||||||
|
|
||||||
- `code` is stable and meant for clients to match on.
|
|
||||||
- `error` is for people and may change. It never repeats the HTTP
|
|
||||||
framework's own text; for example, an unknown route answers `not found`.
|
|
||||||
- `details` appears only when an `invalid_job` fails validation. Each entry
|
|
||||||
names the element by its path, e.g.
|
|
||||||
`elements[0].children[3] (qr): not allowed inside a box; place it after the box`.
|
|
||||||
|
|
||||||
| Status | `code` | Meaning |
|
|
||||||
|--------|--------|---------|
|
|
||||||
| 400 | `invalid_job` | Malformed JSON, an unknown field, trailing data after the job, or invalid elements. When elements are invalid, `details` lists every problem. A `{"data": [...]}` body gets a message pointing to [the new format](#migrating-from-the-old-format) |
|
|
||||||
| 400 | `bad_request` | A malformed HTTP request, refused by the server itself |
|
|
||||||
| 401 | `unauthorized` | `missing bearer token`, or `invalid or expired token`. Sent with `WWW-Authenticate` |
|
|
||||||
| 404 | `not_found` | Unknown route |
|
|
||||||
| 404 | `job_not_found` | Unknown, expired or malformed job ID |
|
|
||||||
| 405 | `method_not_allowed` | Known route, wrong method, e.g. `DELETE /api/v1/print` with a valid token (without one, `/api/v1` answers `401` first). Sent with `Allow` |
|
|
||||||
| 408 | `request_timeout` | The request was not received in time |
|
|
||||||
| 413 | `body_too_large` | Body larger than `webserver.body_limit` |
|
|
||||||
| 422 | `too_many_lines` | From `/api/v1/preview`: the job would print more than `format.max_lines` lines |
|
|
||||||
| 429 | `rate_limited` | Rate limit exceeded. `Retry-After` gives the seconds to wait |
|
|
||||||
| 431 | `headers_too_large` | Request headers too large |
|
|
||||||
| 500 | `internal_error` | Unexpected failure. The cause is logged and reported to Sentry, never sent to the client |
|
|
||||||
| 501 | `not_implemented` | A request body with an unsupported transfer coding. An unknown HTTP method (e.g. `FOO /healthz`) is refused by the HTTP server itself with a plain-text `501` |
|
|
||||||
| 503 | `queue_full` | The print queue is full. Sent with `Retry-After: 10` |
|
|
||||||
| 503 | `shutting_down` | The server is shutting down |
|
|
||||||
|
|
||||||
Any other status that the HTTP layer produces itself gets the code
|
|
||||||
`http_<status>`, e.g. `http_502`. `/healthz` answers `503` with its own body,
|
|
||||||
shown under [Health](#health), not with this shape.
|
|
||||||
|
|
||||||
Validation happens before a job is queued. Images are fetched by the worker,
|
|
||||||
so a blocked or broken image URL shows up as a `failed` job. Nothing is sent
|
|
||||||
to the printer unless the whole receipt rendered.
|
|
||||||
|
|
||||||
## Elements
|
|
||||||
|
|
||||||
A job is `{"elements": [...], "copies": 1}`. `copies` is 1–5, and each copy is
|
|
||||||
cut separately. A partial cut is added after the last element unless that
|
|
||||||
element is already a `cut`. Boxes, rules and key-value rows are described
|
|
||||||
under [Blocks](#blocks).
|
|
||||||
|
|
||||||
### `text`
|
|
||||||
|
|
||||||
| Field | Default | Values |
|
|
||||||
|-------------|---------|--------|
|
|
||||||
| `text` | `""` | UTF-8 text. `\n` starts a new line |
|
|
||||||
| `size` | `1` | 1–8, sets width and height |
|
|
||||||
| `width`, `height` | `size` | 1–8 each, for stretched text |
|
|
||||||
| `bold` | `false` | |
|
|
||||||
| `underline` | `0` | 0, 1 (thin) or 2 (thick) |
|
|
||||||
| `invert` | `false` | white on black |
|
|
||||||
| `font` | `a` | `a`, or `b` (smaller: 56 instead of 42 columns on a TM-T88) |
|
|
||||||
| `align` | `left` | `left`, `center`, `right` |
|
|
||||||
| `newline` | `true` | `false` keeps the next element on the same line |
|
|
||||||
| `wrap` | `true` | `false` sends the text as-is and lets the printer wrap |
|
|
||||||
|
|
||||||
**Encoding.** Text is transcoded from UTF-8 to `printer.codepage`, CP437 by
|
|
||||||
default. Control characters are removed so text can never be read as printer
|
|
||||||
commands. Before that, the text is prepared for the code page:
|
|
||||||
|
|
||||||
- It is composed (Unicode NFC), so a decomposed `é` (an `e` and a combining
|
|
||||||
accent) prints as `é`.
|
|
||||||
- Characters the code page lacks fold to look-alikes: `“ ” „` print as `"`,
|
|
||||||
`‘ ’` as `'`, `–` as `-`, `—` as `--`, `…` as `...`, `•` as `·`, `→` as
|
|
||||||
`->`, `←` as `<-`, `✓ ✔` as `√` (or `x` without `√`), `×` as `x`, `€` as
|
|
||||||
`EUR` and `™` as `TM`. Where the code page has the character, as cp1252
|
|
||||||
has curly quotes and cp858 has `€`, it prints as itself.
|
|
||||||
- An emoji prints as one `?`, together with its skin tone, its variation
|
|
||||||
selector and any emoji joined to it, so `👨👩👧` is one `?`. Zero-width
|
|
||||||
spaces and joiners are removed.
|
|
||||||
- Any other character the code page lacks prints as `?`. The
|
|
||||||
[preview](#preview-a-receipt) lists the elements that have one.
|
|
||||||
|
|
||||||
**Word wrap.** The line width comes from the printer model and the character
|
|
||||||
size: on a TM-T88, 42 characters at size 1, 21 at size 2, and so on. Lines break at spaces,
|
|
||||||
and only a word longer than a whole line (a long URL, say) is split. The
|
|
||||||
renderer tracks the position across `"newline": false` elements, so mixed
|
|
||||||
sizes on one line still wrap correctly.
|
|
||||||
|
|
||||||
### `feed`
|
|
||||||
|
|
||||||
| Field | Default | Values |
|
|
||||||
|---------|---------|--------|
|
|
||||||
| `lines` | `1` | 1–255 |
|
|
||||||
|
|
||||||
### `qr`
|
|
||||||
|
|
||||||
| Field | Default | Values |
|
|
||||||
|--------------|---------|--------|
|
|
||||||
| `data` | | Required. Encoded as UTF-8, up to 7089 bytes |
|
|
||||||
| `size` | `6` | Module size in dots, 1–16 |
|
|
||||||
| `correction` | `M` | `L`, `M`, `Q`, `H` |
|
|
||||||
| `align` | `left` | |
|
|
||||||
|
|
||||||
### `barcode`
|
|
||||||
|
|
||||||
| Field | Default | Values |
|
|
||||||
|-------------|---------|--------|
|
|
||||||
| `symbology` | | Required. `ean13`, `ean8`, `upca`, `upce`, `code39`, `code128` |
|
|
||||||
| `data` | | Required. Digits for EAN/UPC, where a supplied check digit is verified. `A–Z 0–9 -.$/+%` and space for CODE39. Printable ASCII for CODE128 |
|
|
||||||
| `height` | `80` | Bar height in dots, 1–255 |
|
|
||||||
| `width` | `3` | Module width, 2–6 |
|
|
||||||
| `hri` | `below` | Human-readable text: `none`, `above`, `below`, `both` |
|
|
||||||
| `align` | `left` | |
|
|
||||||
|
|
||||||
### `image`
|
|
||||||
|
|
||||||
| Field | Default | Values |
|
|
||||||
|----------|---------|--------|
|
|
||||||
| `url` | | `http`/`https` URL, or use `base64` |
|
|
||||||
| `base64` | | Image data, or a `data:image/png;base64,...` URI |
|
|
||||||
| `width` | natural | Target width in dots, up to the model's print width (512 on a TM-T88) |
|
|
||||||
| `align` | `left` | |
|
|
||||||
|
|
||||||
PNG, JPEG, GIF and WebP are supported. Images wider than the paper are scaled
|
|
||||||
down to fit, and every image is dithered to black and white. URL fetches have
|
|
||||||
a timeout, a size cap and a pixel cap. URLs that resolve to loopback, private
|
|
||||||
or link-local addresses (including cloud metadata endpoints) are refused unless
|
|
||||||
`images.allow_private_networks` is true or the host is in
|
|
||||||
`images.allowed_hosts`.
|
|
||||||
|
|
||||||
### `raw`
|
|
||||||
|
|
||||||
| Field | Values |
|
|
||||||
|-------|--------|
|
|
||||||
| `hex` | ESC/POS bytes as hex, spaces allowed, e.g. `"1B 61 01"` |
|
|
||||||
|
|
||||||
### `cut`
|
|
||||||
|
|
||||||
| Field | Default | Values |
|
|
||||||
|--------|-----------|--------|
|
|
||||||
| `mode` | `partial` | `partial`, `full` |
|
|
||||||
|
|
||||||
## Blocks
|
|
||||||
|
|
||||||
`box`, `rule` and `kv` are blocks: they are laid out when the job prints, from
|
|
||||||
the printer model, so one job fits the TM-T88's 42 columns as well as the
|
|
||||||
TM-T20's 48. A block starts on a new line, and what follows it starts at the
|
|
||||||
left margin. These fields work on all three:
|
|
||||||
|
|
||||||
| Field | Default | Values |
|
|
||||||
|-----------|---------|--------|
|
|
||||||
| `size` | `1` | 1–3. Scales the borders and the text together: 42, 21 or 14 columns on a TM-T88 |
|
|
||||||
| `font` | `a` | `a`, or `b` (56 columns at size 1 on a TM-T88) |
|
|
||||||
| `columns` | the line | 1–255. A fixed width in characters of the block's own size and font. It is cut to the line, and a narrower block is centred |
|
|
||||||
|
|
||||||
Borders and fills are never bold, underlined or inverted. On the blocks, a
|
|
||||||
field that does not apply is an error, e.g.
|
|
||||||
`elements[3] (rule): field "pairs" does not apply to rule`. A long title,
|
|
||||||
footer or label is cut with `...` instead of failing.
|
|
||||||
|
|
||||||
### `box`
|
|
||||||
|
|
||||||
```json
|
|
||||||
{"type": "box", "style": "double", "title": "ACHTUNG", "title_style": "capped", "align": "center",
|
|
||||||
"text": "The coffee machine is being descaled.\nDo not use until 10:30."}
|
|
||||||
```
|
|
||||||
|
|
||||||
```text
|
|
||||||
╔═╡ ACHTUNG ╞════════════════════════════╗
|
|
||||||
║ The coffee machine is being descaled. ║
|
|
||||||
║ Do not use until 10:30. ║
|
|
||||||
╚════════════════════════════════════════╝
|
|
||||||
```
|
|
||||||
|
|
||||||
```json
|
|
||||||
{"type": "box", "fit": true, "padding": 3, "text": "!!! ACHTUNG !!!"}
|
|
||||||
```
|
|
||||||
|
|
||||||
```text
|
|
||||||
┌─────────────────────┐
|
|
||||||
│ !!! ACHTUNG !!! │
|
|
||||||
└─────────────────────┘
|
|
||||||
```
|
|
||||||
|
|
||||||
| Field | Default | Values |
|
|
||||||
|---------------|----------|--------|
|
|
||||||
| `text` | | The body. It wraps at word boundaries, and `\n` starts a new paragraph. Set `text` or `children`, not both |
|
|
||||||
| `children` | | The body as elements; see below |
|
|
||||||
| `style` | `single` | `single` ┌─┐, `double` ╔═╗, `double-h` ╒═╕ (double lines across, single down), `double-v` ╓─╖ (single across, double down), `ascii` +-+ |
|
|
||||||
| `title` | | Text set into the top border |
|
|
||||||
| `title_style` | `inline` | `inline` `┌─ Title ───┐`, or `capped` `╔═╡ Title ╞══╗` |
|
|
||||||
| `footer` | | Text set into the bottom border, on the right: `└──── footer ──┘` |
|
|
||||||
| `align` | `left` | Alignment of `text`, and the default for text children |
|
|
||||||
| `bold`, `underline`, `invert` | | Styles of `text`, as on a `text` element |
|
|
||||||
| `padding` | `1` | 0–3 spaces between the side borders and the body |
|
|
||||||
| `fit` | `false` | `true` shrinks the box to its widest line, title and footer included, and centres it. `columns` is then the most it may take |
|
|
||||||
|
|
||||||
**Children.** A box takes one level of these, and each prints inside the
|
|
||||||
borders:
|
|
||||||
|
|
||||||
| Type | Fields | Inside a box |
|
|
||||||
|--------|--------|--------------|
|
|
||||||
| `text` | `text`, `bold`, `underline`, `invert`, `align`, `wrap` | `size` and `font` come from the box. `"newline": false` is not allowed. `"wrap": false` splits lines at the box edge instead of at spaces |
|
|
||||||
| `feed` | `lines` | Empty lines between the borders |
|
|
||||||
| `rule` | `style` (`single` or `double`), `text`, `align`, `bold` | A divider joined to the side borders: `├──┤`, `╞══╡`, `╟──╢` or `╠══╣` to suit the box. A label reads `├── Label ───┤` |
|
|
||||||
| `kv` | `pairs`, `leader` | Key-value rows across the inside of the box |
|
|
||||||
|
|
||||||
`box`, `qr`, `barcode`, `image`, `raw` and `cut` cannot go inside a box;
|
|
||||||
place them after it. Children count toward the 500-element limit.
|
|
||||||
|
|
||||||
### `rule`
|
|
||||||
|
|
||||||
| Field | Default | Values |
|
|
||||||
|---------|----------|--------|
|
|
||||||
| `style` | `single` | `single` ─, `double` ═, `light` ░, `medium` ▒, `dark` ▓, `solid` █, `dashed` `- -`, `dotted` ·, `ascii` - |
|
|
||||||
| `text` | | A label set into the line |
|
|
||||||
| `align` | `center` | Where the label sits: `───── TODAY ─────`, or `── Notes ──────` at the left |
|
|
||||||
| `bold` | `false` | Prints the label bold |
|
|
||||||
|
|
||||||
### `kv`
|
|
||||||
|
|
||||||
```json
|
|
||||||
{"type": "kv", "pairs": [{"key": "Host", "value": "nas01"},
|
|
||||||
{"key": "Note", "value": "The scrub finished with 0 errors. Next scrub Sunday 03:00."},
|
|
||||||
{"key": "Used", "value": "94%", "bold": true}]}
|
|
||||||
```
|
|
||||||
|
|
||||||
```text
|
|
||||||
Host ............................... nas01
|
|
||||||
Note ... The scrub finished with 0 errors.
|
|
||||||
Next scrub Sunday 03:00.
|
|
||||||
Used ................................. 94%
|
|
||||||
```
|
|
||||||
|
|
||||||
| Field | Default | Values |
|
|
||||||
|----------|---------|--------|
|
|
||||||
| `pairs` | | Required. 1–100 rows of `{"key": "...", "value": "...", "bold": false}`. `key` is required; `bold` prints the key and the value bold |
|
|
||||||
| `leader` | `.` | The fill between key and value: `.`, `·`, `" "` (or `"space"`), `_`, `-` or `─` |
|
|
||||||
|
|
||||||
A value too long for its line wraps into the room after the key, and its
|
|
||||||
further lines are right-aligned. A key too long for the line is cut with
|
|
||||||
`...`.
|
|
||||||
|
|
||||||
### Glyphs and code pages
|
|
||||||
|
|
||||||
CP437, the default, has every glyph the blocks draw with. Other code pages
|
|
||||||
fall back, and the [preview](#preview-a-receipt) shows the result:
|
|
||||||
|
|
||||||
| Code page | Boxes | Rules |
|
|
||||||
|-----------|-------|-------|
|
|
||||||
| `cp437` | All styles as listed | All styles |
|
|
||||||
| `cp850`, `cp858` | `double-h` and `double-v` print as `double`. A divider whose junction the page lacks switches to the other line weight, so `╞══╡` prints as `├──┤` and `╟──╢` as `╠══╣`. A capped title on double lines uses `╣ ╠` | All styles |
|
|
||||||
| `cp1252` | Every box is `ascii`, drawn with `+`, `-` and `\|`, with `=` for double dividers | `─ ═` print as `- =`, shades as `#` |
|
|
||||||
|
|
||||||
For your own text on CP437:
|
|
||||||
|
|
||||||
- **Prints:** box drawing `┌─┐│└┘├┤┬┴┼ ╔═╗║╚╝╠╣╦╩╬ ╒╓╕╖╘╙╛╜╞╟╡╢╤╥╧╨╪╫`,
|
|
||||||
shades and blocks `░▒▓█▀▄▌▐■`, and `· ∙ √ ° ± » « £ ¥ ½ ¼` and accented
|
|
||||||
Latin letters.
|
|
||||||
- **Never prints as itself:** `•` and emoji, and `► ◄ → ←` and the other
|
|
||||||
symbols CP437 keeps at byte values below 0x20, which the printer reads as
|
|
||||||
commands. `•` folds to `·` and `→ ←` to `-> <-`; the rest print as `?`. Use
|
|
||||||
`· ∙ ■ » √ °` instead.
|
|
||||||
|
|
||||||
`examples/blocks.json` prints every style, padding, size and junction on one
|
|
||||||
receipt, for checking the borders on paper. Send it as the body of
|
|
||||||
`/api/v1/print`, or look at it first with
|
|
||||||
`uberbringer preview examples/blocks.json`.
|
|
||||||
|
|
||||||
## Migrating from the old format
|
|
||||||
|
|
||||||
The endpoint is still `POST /api/v1/print`, but the body changed from
|
|
||||||
`{"data": [...]}` to `{"elements": [...]}`. The response changed from the text
|
|
||||||
`OK - <id>` to the JSON shown above. Old-format bodies get a `400` that points
|
|
||||||
here.
|
|
||||||
|
|
||||||
| Old `type` | Old meaning | New element |
|
|
||||||
|------------|-------------|-------------|
|
|
||||||
| 1 | Text | `{"type": "text", "text": "...", "size": n, "newline": false}` |
|
|
||||||
| 2 | Bold text | `{"type": "text", "text": "...", "bold": true, "newline": false}` |
|
|
||||||
| 3 | QR code | `{"type": "qr", "data": "...", "size": n, "correction": "H"}` |
|
|
||||||
| 4 | Line feed | `{"type": "feed"}` |
|
|
||||||
| 5 | n line feeds | `{"type": "feed", "lines": n}` |
|
|
||||||
| 6 | Raw hex | `{"type": "raw", "hex": "..."}`, or plain UTF-8 `text` for CP437 art |
|
|
||||||
| 7 | Image URL | `{"type": "image", "url": "..."}` |
|
|
||||||
|
|
||||||
Old text items did not end the line, hence `"newline": false`. You can usually
|
|
||||||
drop it now and let each `text` element be a line. Hex-encoded CP437 box
|
|
||||||
drawing can become plain text: `B3 20 21 21 21` is `"│ !!!"`.
|
|
||||||
|
|
||||||
These changes also affect 0.1 clients and configs.
|
|
||||||
[CHANGELOG.md](CHANGELOG.md) lists every change.
|
|
||||||
|
|
||||||
- Tokens are read only from the `Authorization` header. A `?token=` query
|
|
||||||
string gets `401`.
|
|
||||||
- Errors have the [JSON shape above](#errors) instead of `{"message": "..."}`
|
|
||||||
or plain text.
|
|
||||||
- `printer.model` defaults to `tm-t88` (512 dots). On a TM-T20, set
|
|
||||||
`model = "tm-t20"` to use the full 576-dot width.
|
|
||||||
- A 0.1 config needs a `[printer]` section with `address` before 0.2
|
|
||||||
starts, because `printer.address` is now required. The 0.1 install script
|
|
||||||
did not write one.
|
|
||||||
- `install.sh` sets up a fresh host. It does not upgrade a server set up by
|
|
||||||
the 0.1 install script.
|
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
@@ -771,7 +311,8 @@ CI runs on the Gitea runner from `.gitea/workflows/`. The repository has no
|
|||||||
- `vX.Y.Z-rc.N` tags are published as prereleases, so they never become the
|
- `vX.Y.Z-rc.N` tags are published as prereleases, so they never become the
|
||||||
latest release that `install.sh` installs.
|
latest release that `install.sh` installs.
|
||||||
- Each archive holds the binary, `LICENSE.txt`, `README.md`,
|
- Each archive holds the binary, `LICENSE.txt`, `README.md`,
|
||||||
`configs/config.example.toml` and `packaging/uberbringer.service`.
|
`docs/api.md`, `CHANGELOG.md`, `configs/config.example.toml` and
|
||||||
|
`packaging/uberbringer.service`.
|
||||||
- The release notes link to `CHANGELOG.md` at the tag.
|
- The release notes link to `CHANGELOG.md` at the tag.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|||||||
+443
@@ -0,0 +1,443 @@
|
|||||||
|
# Überbringer API
|
||||||
|
|
||||||
|
The HTTP API, the print elements and blocks, and the error codes.
|
||||||
|
[README.md](../README.md) covers installing, configuring and running the
|
||||||
|
daemon.
|
||||||
|
|
||||||
|
## Contents
|
||||||
|
|
||||||
|
- [API](#api)
|
||||||
|
- [Print a receipt](#print-a-receipt)
|
||||||
|
- [Job status](#job-status)
|
||||||
|
- [Preview a receipt](#preview-a-receipt)
|
||||||
|
- [Health](#health)
|
||||||
|
- [Errors](#errors)
|
||||||
|
- [Elements](#elements)
|
||||||
|
- [Blocks](#blocks)
|
||||||
|
- [Glyphs and code pages](#glyphs-and-code-pages)
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
All `/api/v1` routes need an `Authorization: Bearer <token>` header. Issue
|
||||||
|
tokens with `uberbringer token`. Tokens created by the old install script keep
|
||||||
|
working as long as the secret is unchanged. Tokens in query strings are not
|
||||||
|
accepted, because they leak into proxy logs.
|
||||||
|
|
||||||
|
Responses from `/healthz` and every `/api/v1` route, error responses
|
||||||
|
included, carry `Cache-Control: no-store`.
|
||||||
|
|
||||||
|
| Method | Path | Purpose |
|
||||||
|
|--------|--------------------|------------------------------------------|
|
||||||
|
| POST | `/api/v1/print` | Queue a print job |
|
||||||
|
| POST | `/api/v1/preview` | Show the lines a job prints, without printing it |
|
||||||
|
| GET | `/api/v1/jobs/:id` | Job status |
|
||||||
|
| GET | `/healthz` | Printer and queue health (no auth) |
|
||||||
|
| GET | `/` | Version information (no auth) |
|
||||||
|
|
||||||
|
### Print a receipt
|
||||||
|
|
||||||
|
```sh
|
||||||
|
curl -X POST https://printer.example.com/api/v1/print \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"elements": [
|
||||||
|
{"type": "rule", "style": "dark"},
|
||||||
|
{"type": "box", "fit": true, "padding": 3, "text": "!!! ACHTUNG !!!"},
|
||||||
|
{"type": "text", "text": "Überbringer", "size": 2, "bold": true, "align": "center"},
|
||||||
|
{"type": "feed"},
|
||||||
|
{"type": "text", "text": "Long paragraphs wrap at word boundaries for the paper width, so a word is never split across two lines."},
|
||||||
|
{"type": "text", "text": "Total: ", "newline": false},
|
||||||
|
{"type": "text", "text": "£12.50", "bold": true},
|
||||||
|
{"type": "qr", "data": "https://example.com", "align": "center"},
|
||||||
|
{"type": "feed", "lines": 3}
|
||||||
|
]
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
The response is `202 Accepted` with a `Location` header:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{"id": "job_01kbx4n6m3ex8tq0wq3r5vrzq1", "status": "queued", "created_at": "2026-11-29T21:04:05Z"}
|
||||||
|
```
|
||||||
|
|
||||||
|
Job IDs are [TypeIDs](https://github.com/jetify-com/typeid): UUIDv7 values
|
||||||
|
with a `job_` prefix, so they sort by creation time.
|
||||||
|
|
||||||
|
### Job status
|
||||||
|
|
||||||
|
```sh
|
||||||
|
curl -H "Authorization: Bearer $TOKEN" https://printer.example.com/api/v1/jobs/job_01kbx4n6m3ex8tq0wq3r5vrzq1
|
||||||
|
```
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "job_01kbx4n6m3ex8tq0wq3r5vrzq1",
|
||||||
|
"status": "done",
|
||||||
|
"attempts": 1,
|
||||||
|
"created_at": "2026-11-29T21:04:05Z",
|
||||||
|
"started_at": "2026-11-29T21:04:05Z",
|
||||||
|
"finished_at": "2026-11-29T21:04:06Z"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`status` is `queued`, `printing`, `done` or `failed`. A failed job includes an
|
||||||
|
`error` field. The last `queue.history` finished jobs are kept.
|
||||||
|
|
||||||
|
### Preview a receipt
|
||||||
|
|
||||||
|
`POST /api/v1/preview` takes the same body as `/api/v1/print` and validates
|
||||||
|
it the same way, but prints nothing and fetches no images. It answers `200`
|
||||||
|
with the lines the printer would print, as `text/plain; charset=utf-8`:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
curl -X POST https://printer.example.com/api/v1/preview \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"elements": [{"type": "box", "fit": true, "padding": 3, "text": "!!! ACHTUNG !!!"},
|
||||||
|
{"type": "qr", "data": "https://example.com"}]}'
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
┌─────────────────────┐
|
||||||
|
│ !!! ACHTUNG !!! │
|
||||||
|
└─────────────────────┘
|
||||||
|
[qr: https://example.com]
|
||||||
|
- - - - - - - partial cut - - - - - - - -
|
||||||
|
```
|
||||||
|
|
||||||
|
- The preview is read back from the bytes the job renders to, so it shows
|
||||||
|
what the printer receives: wrapping, folded characters, `?` for missing
|
||||||
|
ones and the final cut.
|
||||||
|
- Centred and right-aligned text is indented as the printer places it,
|
||||||
|
counted in Font A columns. Text at a larger size shows each character
|
||||||
|
once.
|
||||||
|
- QR codes, barcodes, images, `raw` bytes and cuts print as placeholders
|
||||||
|
such as `[barcode ean13: 4006381333931]`, `[image 384 dots: logo.png]` and
|
||||||
|
`[raw 3 bytes]`.
|
||||||
|
|
||||||
|
With `Accept: application/json` the answer carries the styles too. For
|
||||||
|
`[{"type": "kv", "pairs": [{"key": "Total", "value": "£12.50", "bold": true}]},
|
||||||
|
{"type": "text", "text": "Thanks 🎉", "align": "center"},
|
||||||
|
{"type": "qr", "data": "https://example.com"}]`:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{"columns": 42, "codepage": "cp437", "line_count": 3,
|
||||||
|
"lines": [{"kind": "text", "text": "Total ............................. £12.50",
|
||||||
|
"runs": [{"from": 0, "to": 5, "bold": true}, {"from": 36, "to": 42, "bold": true}]},
|
||||||
|
{"kind": "text", "text": " Thanks ?"},
|
||||||
|
{"kind": "qr", "text": "[qr: https://example.com]", "data": "https://example.com"},
|
||||||
|
{"kind": "cut", "text": " - - - - - - - partial cut - - - - - - - -", "data": "partial"}],
|
||||||
|
"warnings": ["elements[1]: 1 character not in cp437 printed as ?"]}
|
||||||
|
```
|
||||||
|
|
||||||
|
| Field | Meaning |
|
||||||
|
|-------|---------|
|
||||||
|
| `columns` | Font A characters per line |
|
||||||
|
| `codepage` | The code page text is printed in |
|
||||||
|
| `line_count` | Lines the receipt prints, all copies counted: text lines, fed lines, and one for each QR code, barcode and image. [`format.max_lines`](../README.md#configuration) limits it |
|
||||||
|
| `lines[].kind` | `text`, `qr`, `barcode`, `image`, `raw` or `cut` |
|
||||||
|
| `lines[].text` | The line as it prints, or the placeholder |
|
||||||
|
| `lines[].runs` | Styled parts of `text`, in characters from `from` up to `to`: `bold`, `underline` (1 or 2), `invert`, `font` (`b`), and `width` and `height` when scaled. Plain Font A text at size 1 has no run |
|
||||||
|
| `lines[].data` | QR code or barcode data, the image URL (or `base64`), the number of raw bytes, or the cut mode |
|
||||||
|
| `warnings` | Elements with characters the code page lacks, and images wider than the paper |
|
||||||
|
|
||||||
|
A job that would print more than `format.max_lines` lines answers `422`
|
||||||
|
`too_many_lines`, for example `receipt would print 2412 lines, limit is
|
||||||
|
2000`. Sent to `/api/v1/print`, the same job is accepted and then fails
|
||||||
|
when the worker renders it, before anything is sent; its `error` reads
|
||||||
|
`rendering: receipt would print 2412 lines, limit is 2000`.
|
||||||
|
|
||||||
|
### Health
|
||||||
|
|
||||||
|
`GET /healthz` returns `200` when the printer is reachable and ready, and
|
||||||
|
`503` when it is unreachable or not ready (paper out, cover open, error).
|
||||||
|
|
||||||
|
```json
|
||||||
|
{"status": "ok", "printer": {"reachable": true, "status": "ready", "online": true, "cover_open": false, "paper": "near_end"}, "queue": {"pending": 0}}
|
||||||
|
```
|
||||||
|
|
||||||
|
A printer that accepts connections but does not answer status requests is
|
||||||
|
reported as `"status": "unknown"` with HTTP `200`.
|
||||||
|
|
||||||
|
Details:
|
||||||
|
|
||||||
|
- **Brief problems are re-checked.** A printer that looks not ready is read
|
||||||
|
again 750 ms later, and only a problem that is still there gives `503`.
|
||||||
|
While cutting or feeding, a printer can report a problem for a moment.
|
||||||
|
- **Timeouts.** The printer accepts one connection at a time. While it is still
|
||||||
|
taking in a large job, the 3-second health check can run out of time. That
|
||||||
|
gives `503` with printer status `"timeout"`, because the printer's state is
|
||||||
|
unknown.
|
||||||
|
- **The cover flag** is only reported while the printer is offline. Epson
|
||||||
|
printers always go offline when the cover opens.
|
||||||
|
- **Paper low on the TM-T88VII.** That model does not report paper near-end
|
||||||
|
through real-time status, so `"near_end"` never appears for it; paper out
|
||||||
|
is still reported.
|
||||||
|
|
||||||
|
### Errors
|
||||||
|
|
||||||
|
Errors are JSON:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{"error": "invalid job", "code": "invalid_job", "details": ["elements[2] (text): size, width and height must be 1-8"]}
|
||||||
|
```
|
||||||
|
|
||||||
|
- `code` is stable and meant for clients to match on.
|
||||||
|
- `error` is for people and may change. It never repeats the HTTP
|
||||||
|
framework's own text; for example, an unknown route answers `not found`.
|
||||||
|
- `details` appears only when an `invalid_job` fails validation. Each entry
|
||||||
|
names the element by its path, e.g.
|
||||||
|
`elements[0].children[3] (qr): not allowed inside a box; place it after the box`.
|
||||||
|
|
||||||
|
| Status | `code` | Meaning |
|
||||||
|
|--------|--------|---------|
|
||||||
|
| 400 | `invalid_job` | Malformed JSON, an unknown field, trailing data after the job, or invalid elements. When elements are invalid, `details` lists every problem. A `{"data": [...]}` body gets a message pointing to the [element format](#elements) |
|
||||||
|
| 400 | `bad_request` | A malformed HTTP request, refused by the server itself |
|
||||||
|
| 401 | `unauthorized` | `missing bearer token`, or `invalid or expired token`. Sent with `WWW-Authenticate` |
|
||||||
|
| 404 | `not_found` | Unknown route |
|
||||||
|
| 404 | `job_not_found` | Unknown, expired or malformed job ID |
|
||||||
|
| 405 | `method_not_allowed` | Known route, wrong method, e.g. `DELETE /api/v1/print` with a valid token (without one, `/api/v1` answers `401` first). Sent with `Allow` |
|
||||||
|
| 408 | `request_timeout` | The request was not received in time |
|
||||||
|
| 413 | `body_too_large` | Body larger than `webserver.body_limit` |
|
||||||
|
| 422 | `too_many_lines` | From `/api/v1/preview`: the job would print more than `format.max_lines` lines |
|
||||||
|
| 429 | `rate_limited` | Rate limit exceeded. `Retry-After` gives the seconds to wait |
|
||||||
|
| 431 | `headers_too_large` | Request headers too large |
|
||||||
|
| 500 | `internal_error` | Unexpected failure. The cause is logged and reported to Sentry, never sent to the client |
|
||||||
|
| 501 | `not_implemented` | A request body with an unsupported transfer coding. An unknown HTTP method (e.g. `FOO /healthz`) is refused by the HTTP server itself with a plain-text `501` |
|
||||||
|
| 503 | `queue_full` | The print queue is full. Sent with `Retry-After: 10` |
|
||||||
|
| 503 | `shutting_down` | The server is shutting down |
|
||||||
|
|
||||||
|
Any other status that the HTTP layer produces itself gets the code
|
||||||
|
`http_<status>`, e.g. `http_502`. `/healthz` answers `503` with its own body,
|
||||||
|
shown under [Health](#health), not with this shape.
|
||||||
|
|
||||||
|
Validation happens before a job is queued. Images are fetched by the worker,
|
||||||
|
so a blocked or broken image URL shows up as a `failed` job. Nothing is sent
|
||||||
|
to the printer unless the whole receipt rendered.
|
||||||
|
|
||||||
|
## Elements
|
||||||
|
|
||||||
|
A job is `{"elements": [...], "copies": 1}`. `copies` is 1–5, and each copy is
|
||||||
|
cut separately. A partial cut is added after the last element unless that
|
||||||
|
element is already a `cut`. Boxes, rules and key-value rows are described
|
||||||
|
under [Blocks](#blocks).
|
||||||
|
|
||||||
|
### `text`
|
||||||
|
|
||||||
|
| Field | Default | Values |
|
||||||
|
|-------------|---------|--------|
|
||||||
|
| `text` | `""` | UTF-8 text. `\n` starts a new line |
|
||||||
|
| `size` | `1` | 1–8, sets width and height |
|
||||||
|
| `width`, `height` | `size` | 1–8 each, for stretched text |
|
||||||
|
| `bold` | `false` | |
|
||||||
|
| `underline` | `0` | 0, 1 (thin) or 2 (thick) |
|
||||||
|
| `invert` | `false` | white on black |
|
||||||
|
| `font` | `a` | `a`, or `b` (smaller: 56 instead of 42 columns on a TM-T88) |
|
||||||
|
| `align` | `left` | `left`, `center`, `right` |
|
||||||
|
| `newline` | `true` | `false` keeps the next element on the same line |
|
||||||
|
| `wrap` | `true` | `false` sends the text as-is and lets the printer wrap |
|
||||||
|
|
||||||
|
**Encoding.** Text is transcoded from UTF-8 to `printer.codepage`, CP437 by
|
||||||
|
default. Control characters are removed so text can never be read as printer
|
||||||
|
commands. Before that, the text is prepared for the code page:
|
||||||
|
|
||||||
|
- It is composed (Unicode NFC), so a decomposed `é` (an `e` and a combining
|
||||||
|
accent) prints as `é`.
|
||||||
|
- Characters the code page lacks fold to look-alikes: `“ ” „` print as `"`,
|
||||||
|
`‘ ’` as `'`, `–` as `-`, `—` as `--`, `…` as `...`, `•` as `·`, `→` as
|
||||||
|
`->`, `←` as `<-`, `✓ ✔` as `√` (or `x` without `√`), `×` as `x`, `€` as
|
||||||
|
`EUR` and `™` as `TM`. Where the code page has the character, as cp1252
|
||||||
|
has curly quotes and cp858 has `€`, it prints as itself.
|
||||||
|
- An emoji prints as one `?`, together with its skin tone, its variation
|
||||||
|
selector and any emoji joined to it, so `👨👩👧` is one `?`. Zero-width
|
||||||
|
spaces and joiners are removed.
|
||||||
|
- Any other character the code page lacks prints as `?`. The
|
||||||
|
[preview](#preview-a-receipt) lists the elements that have one.
|
||||||
|
|
||||||
|
**Word wrap.** The line width comes from the printer model and the character
|
||||||
|
size: on a TM-T88, 42 characters at size 1, 21 at size 2, and so on. Lines break at spaces,
|
||||||
|
and only a word longer than a whole line (a long URL, say) is split. The
|
||||||
|
renderer tracks the position across `"newline": false` elements, so mixed
|
||||||
|
sizes on one line still wrap correctly.
|
||||||
|
|
||||||
|
### `feed`
|
||||||
|
|
||||||
|
| Field | Default | Values |
|
||||||
|
|---------|---------|--------|
|
||||||
|
| `lines` | `1` | 1–255 |
|
||||||
|
|
||||||
|
### `qr`
|
||||||
|
|
||||||
|
| Field | Default | Values |
|
||||||
|
|--------------|---------|--------|
|
||||||
|
| `data` | | Required. Encoded as UTF-8, up to 7089 bytes |
|
||||||
|
| `size` | `6` | Module size in dots, 1–16 |
|
||||||
|
| `correction` | `M` | `L`, `M`, `Q`, `H` |
|
||||||
|
| `align` | `left` | |
|
||||||
|
|
||||||
|
### `barcode`
|
||||||
|
|
||||||
|
| Field | Default | Values |
|
||||||
|
|-------------|---------|--------|
|
||||||
|
| `symbology` | | Required. `ean13`, `ean8`, `upca`, `upce`, `code39`, `code128` |
|
||||||
|
| `data` | | Required. Digits for EAN/UPC, where a supplied check digit is verified. `A–Z 0–9 -.$/+%` and space for CODE39. Printable ASCII for CODE128 |
|
||||||
|
| `height` | `80` | Bar height in dots, 1–255 |
|
||||||
|
| `width` | `3` | Module width, 2–6 |
|
||||||
|
| `hri` | `below` | Human-readable text: `none`, `above`, `below`, `both` |
|
||||||
|
| `align` | `left` | |
|
||||||
|
|
||||||
|
### `image`
|
||||||
|
|
||||||
|
| Field | Default | Values |
|
||||||
|
|----------|---------|--------|
|
||||||
|
| `url` | | `http`/`https` URL, or use `base64` |
|
||||||
|
| `base64` | | Image data, or a `data:image/png;base64,...` URI |
|
||||||
|
| `width` | natural | Target width in dots, up to the model's print width (512 on a TM-T88) |
|
||||||
|
| `align` | `left` | |
|
||||||
|
|
||||||
|
PNG, JPEG, GIF and WebP are supported. Images wider than the paper are scaled
|
||||||
|
down to fit, and every image is dithered to black and white. URL fetches have
|
||||||
|
a timeout, a size cap and a pixel cap. URLs that resolve to loopback, private
|
||||||
|
or link-local addresses (including cloud metadata endpoints) are refused unless
|
||||||
|
`images.allow_private_networks` is true or the host is in
|
||||||
|
`images.allowed_hosts`.
|
||||||
|
|
||||||
|
### `raw`
|
||||||
|
|
||||||
|
| Field | Values |
|
||||||
|
|-------|--------|
|
||||||
|
| `hex` | ESC/POS bytes as hex, spaces allowed, e.g. `"1B 61 01"` |
|
||||||
|
|
||||||
|
### `cut`
|
||||||
|
|
||||||
|
| Field | Default | Values |
|
||||||
|
|--------|-----------|--------|
|
||||||
|
| `mode` | `partial` | `partial`, `full` |
|
||||||
|
|
||||||
|
## Blocks
|
||||||
|
|
||||||
|
`box`, `rule` and `kv` are blocks: they are laid out when the job prints, from
|
||||||
|
the printer model, so one job fits the TM-T88's 42 columns as well as the
|
||||||
|
TM-T20's 48. A block starts on a new line, and what follows it starts at the
|
||||||
|
left margin. These fields work on all three:
|
||||||
|
|
||||||
|
| Field | Default | Values |
|
||||||
|
|-----------|---------|--------|
|
||||||
|
| `size` | `1` | 1–3. Scales the borders and the text together: 42, 21 or 14 columns on a TM-T88 |
|
||||||
|
| `font` | `a` | `a`, or `b` (56 columns at size 1 on a TM-T88) |
|
||||||
|
| `columns` | the line | 1–255. A fixed width in characters of the block's own size and font. It is cut to the line, and a narrower block is centred |
|
||||||
|
|
||||||
|
Borders and fills are never bold, underlined or inverted. On the blocks, a
|
||||||
|
field that does not apply is an error, e.g.
|
||||||
|
`elements[3] (rule): field "pairs" does not apply to rule`. A long title,
|
||||||
|
footer or label is cut with `...` instead of failing.
|
||||||
|
|
||||||
|
### `box`
|
||||||
|
|
||||||
|
```json
|
||||||
|
{"type": "box", "style": "double", "title": "ACHTUNG", "title_style": "capped", "align": "center",
|
||||||
|
"text": "The coffee machine is being descaled.\nDo not use until 10:30."}
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
╔═╡ ACHTUNG ╞════════════════════════════╗
|
||||||
|
║ The coffee machine is being descaled. ║
|
||||||
|
║ Do not use until 10:30. ║
|
||||||
|
╚════════════════════════════════════════╝
|
||||||
|
```
|
||||||
|
|
||||||
|
```json
|
||||||
|
{"type": "box", "fit": true, "padding": 3, "text": "!!! ACHTUNG !!!"}
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
┌─────────────────────┐
|
||||||
|
│ !!! ACHTUNG !!! │
|
||||||
|
└─────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
| Field | Default | Values |
|
||||||
|
|---------------|----------|--------|
|
||||||
|
| `text` | | The body. It wraps at word boundaries, and `\n` starts a new paragraph. Set `text` or `children`, not both |
|
||||||
|
| `children` | | The body as elements; see below |
|
||||||
|
| `style` | `single` | `single` ┌─┐, `double` ╔═╗, `double-h` ╒═╕ (double lines across, single down), `double-v` ╓─╖ (single across, double down), `ascii` +-+ |
|
||||||
|
| `title` | | Text set into the top border |
|
||||||
|
| `title_style` | `inline` | `inline` `┌─ Title ───┐`, or `capped` `╔═╡ Title ╞══╗` |
|
||||||
|
| `footer` | | Text set into the bottom border, on the right: `└──── footer ──┘` |
|
||||||
|
| `align` | `left` | Alignment of `text`, and the default for text children |
|
||||||
|
| `bold`, `underline`, `invert` | | Styles of `text`, as on a `text` element |
|
||||||
|
| `padding` | `1` | 0–3 spaces between the side borders and the body |
|
||||||
|
| `fit` | `false` | `true` shrinks the box to its widest line, title and footer included, and centres it. `columns` is then the most it may take |
|
||||||
|
|
||||||
|
**Children.** A box takes one level of these, and each prints inside the
|
||||||
|
borders:
|
||||||
|
|
||||||
|
| Type | Fields | Inside a box |
|
||||||
|
|--------|--------|--------------|
|
||||||
|
| `text` | `text`, `bold`, `underline`, `invert`, `align`, `wrap` | `size` and `font` come from the box. `"newline": false` is not allowed. `"wrap": false` splits lines at the box edge instead of at spaces |
|
||||||
|
| `feed` | `lines` | Empty lines between the borders |
|
||||||
|
| `rule` | `style` (`single` or `double`), `text`, `align`, `bold` | A divider joined to the side borders: `├──┤`, `╞══╡`, `╟──╢` or `╠══╣` to suit the box. A label reads `├── Label ───┤` |
|
||||||
|
| `kv` | `pairs`, `leader` | Key-value rows across the inside of the box |
|
||||||
|
|
||||||
|
`box`, `qr`, `barcode`, `image`, `raw` and `cut` cannot go inside a box;
|
||||||
|
place them after it. Children count toward the 500-element limit.
|
||||||
|
|
||||||
|
### `rule`
|
||||||
|
|
||||||
|
| Field | Default | Values |
|
||||||
|
|---------|----------|--------|
|
||||||
|
| `style` | `single` | `single` ─, `double` ═, `light` ░, `medium` ▒, `dark` ▓, `solid` █, `dashed` `- -`, `dotted` ·, `ascii` - |
|
||||||
|
| `text` | | A label set into the line |
|
||||||
|
| `align` | `center` | Where the label sits: `───── TODAY ─────`, or `── Notes ──────` at the left |
|
||||||
|
| `bold` | `false` | Prints the label bold |
|
||||||
|
|
||||||
|
### `kv`
|
||||||
|
|
||||||
|
```json
|
||||||
|
{"type": "kv", "pairs": [{"key": "Host", "value": "nas01"},
|
||||||
|
{"key": "Note", "value": "The scrub finished with 0 errors. Next scrub Sunday 03:00."},
|
||||||
|
{"key": "Used", "value": "94%", "bold": true}]}
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
Host ............................... nas01
|
||||||
|
Note ... The scrub finished with 0 errors.
|
||||||
|
Next scrub Sunday 03:00.
|
||||||
|
Used ................................. 94%
|
||||||
|
```
|
||||||
|
|
||||||
|
| Field | Default | Values |
|
||||||
|
|----------|---------|--------|
|
||||||
|
| `pairs` | | Required. 1–100 rows of `{"key": "...", "value": "...", "bold": false}`. `key` is required; `bold` prints the key and the value bold |
|
||||||
|
| `leader` | `.` | The fill between key and value: `.`, `·`, `" "` (or `"space"`), `_`, `-` or `─` |
|
||||||
|
|
||||||
|
A value too long for its line wraps into the room after the key, and its
|
||||||
|
further lines are right-aligned. A key too long for the line is cut with
|
||||||
|
`...`.
|
||||||
|
|
||||||
|
### Glyphs and code pages
|
||||||
|
|
||||||
|
CP437, the default, has every glyph the blocks draw with. Other code pages
|
||||||
|
fall back, and the [preview](#preview-a-receipt) shows the result:
|
||||||
|
|
||||||
|
| Code page | Boxes | Rules |
|
||||||
|
|-----------|-------|-------|
|
||||||
|
| `cp437` | All styles as listed | All styles |
|
||||||
|
| `cp850`, `cp858` | `double-h` and `double-v` print as `double`. A divider whose junction the page lacks switches to the other line weight, so `╞══╡` prints as `├──┤` and `╟──╢` as `╠══╣`. A capped title on double lines uses `╣ ╠` | All styles |
|
||||||
|
| `cp1252` | Every box is `ascii`, drawn with `+`, `-` and `\|`, with `=` for double dividers | `─ ═` print as `- =`, shades as `#` |
|
||||||
|
|
||||||
|
For your own text on CP437:
|
||||||
|
|
||||||
|
- **Prints:** box drawing `┌─┐│└┘├┤┬┴┼ ╔═╗║╚╝╠╣╦╩╬ ╒╓╕╖╘╙╛╜╞╟╡╢╤╥╧╨╪╫`,
|
||||||
|
shades and blocks `░▒▓█▀▄▌▐■`, and `· ∙ √ ° ± » « £ ¥ ½ ¼` and accented
|
||||||
|
Latin letters.
|
||||||
|
- **Never prints as itself:** `•` and emoji, and `► ◄ → ←` and the other
|
||||||
|
symbols CP437 keeps at byte values below 0x20, which the printer reads as
|
||||||
|
commands. `•` folds to `·` and `→ ←` to `-> <-`; the rest print as `?`. Use
|
||||||
|
`· ∙ ■ » √ °` instead.
|
||||||
|
|
||||||
|
`examples/blocks.json` prints every style, padding, size and junction on one
|
||||||
|
receipt, for checking the borders on paper. Send it as the body of
|
||||||
|
`/api/v1/print`, or look at it first with
|
||||||
|
`uberbringer preview examples/blocks.json`.
|
||||||
+3
-3
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Status: version 0.2.0, checked on paper on the TM-T88IV. Next is the
|
Status: version 0.2.0, checked on paper on the TM-T88IV. Next is the
|
||||||
formatters work in `docs/plans/formatters.md`. This page records why the
|
formatters work in `docs/plans/formatters.md`. This page records why the
|
||||||
daemon is shaped as it is. README.md describes how to use it.
|
daemon is shaped as it is. README.md and docs/api.md describe how to use it.
|
||||||
|
|
||||||
## Why
|
## Why
|
||||||
|
|
||||||
@@ -115,8 +115,8 @@ client ─HTTPS─▶ Caddy ─▶ server ── validate ──▶ printqueue (
|
|||||||
without the body or the `Authorization` header.
|
without the body or the `Authorization` header.
|
||||||
- **What stays compatible with 0.1.** The endpoint, the HS256 tokens and the
|
- **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. The 0.1 body and its plain-text answer do
|
||||||
not. A 0.1 body gets a `400` that points to the migration table, instead of
|
not. A 0.1 body gets a `400` that points to the element format in
|
||||||
being translated. Tokens are read only from the header, because tokens 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.
|
query strings end up in proxy logs.
|
||||||
- **Stack choices (owner, 2026-11-29):**
|
- **Stack choices (owner, 2026-11-29):**
|
||||||
- Fiber v3 instead of Echo.
|
- Fiber v3 instead of Echo.
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ func decodeValidJob(body []byte) (receipt.Job, error) {
|
|||||||
|
|
||||||
// decodeJob strictly decodes a job body. Unknown fields are rejected so that
|
// decodeJob strictly decodes a job body. Unknown fields are rejected so that
|
||||||
// typos fail loudly. A body with a top-level "data" key gets a message that
|
// typos fail loudly. A body with a top-level "data" key gets a message that
|
||||||
// points to "elements" and the README instead of the decoder's text.
|
// points to "elements" and the API reference instead of the decoder's text.
|
||||||
func decodeJob(body []byte) (receipt.Job, error) {
|
func decodeJob(body []byte) (receipt.Job, error) {
|
||||||
job, err := receipt.DecodeJob(body)
|
job, err := receipt.DecodeJob(body)
|
||||||
switch {
|
switch {
|
||||||
@@ -83,7 +83,7 @@ func decodeJob(body []byte) (receipt.Job, error) {
|
|||||||
case err != nil:
|
case err != nil:
|
||||||
msg := "request body is not a valid job: " + err.Error()
|
msg := "request body is not a valid job: " + err.Error()
|
||||||
if strings.Contains(err.Error(), `unknown field "data"`) && hasTopLevelData(body) {
|
if strings.Contains(err.Error(), `unknown field "data"`) && hasTopLevelData(body) {
|
||||||
msg = `the {"data": [...]} format was replaced by {"elements": [...]}; see the README for the element format`
|
msg = `the {"data": [...]} format was replaced by {"elements": [...]}; see docs/api.md for the element format`
|
||||||
}
|
}
|
||||||
return job, newAPIError(codeInvalidJob.withMessage(msg))
|
return job, newAPIError(codeInvalidJob.withMessage(msg))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -732,7 +732,7 @@ func TestRoutesConform(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
default:
|
default:
|
||||||
t.Errorf("%s has no conformance case: add one here and a row to the README's API table", key)
|
t.Errorf("%s has no conformance case: add one here and a row to the API table in docs/api.md", key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for key := range authenticated {
|
for key := range authenticated {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func expectLines(t *testing.T, got []string, want ...string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestMockups pins the boxes the README shows, each printed from one
|
// TestMockups pins the boxes docs/api.md shows, each printed from one
|
||||||
// element.
|
// element.
|
||||||
func TestMockups(t *testing.T) {
|
func TestMockups(t *testing.T) {
|
||||||
t.Run("double box, capped title, centred", func(t *testing.T) {
|
t.Run("double box, capped title, centred", func(t *testing.T) {
|
||||||
|
|||||||
Reference in new issue
Block a user