Skip to content

Labels: sheet media, start slot and media choice on the print endpoint - #3

Open
mgilardi wants to merge 8 commits into
mainfrom
co/labels-sheets
Open

mgilardi wants to merge 8 commits into
mainfrom
co/labels-sheets

Conversation

@mgilardi

Copy link
Copy Markdown
Contributor

Captive Origins task K6, following the plugin design (Printing and Outputs sections).

Stacks on #1 (co/labels-core) and is independent of #2.

  • renderPdf places labels on Letter sheets from a start slot, flowing onto new pages
  • Avery 5160 and 5163 presets, with measurements recorded in docs/decisions.md
  • Print endpoint takes media and a 1-based start slot, with plain refusals
  • Sets are not built: the design leaves them open

Tested: 54 tests, tsc, leak check. Not tested: preset measurements on a printed sheet.

🤖 Generated with Claude Code

mgilardi and others added 6 commits November 16, 2026 00:14
Starts the build of the first checkpoint: package files copied from the sibling plugin's shape, a Payload-free layout engine (tokens, fitting, sheet positions, the 4 x 6 in preset), the provider contract types, and a plugin that registers the three collections with writes closed by default.

Not tested: any database, PDF or SVG output, the print endpoint, the admin UI, site filtering for scopeField.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reads, creates, updates and deletes now stay inside the person's own scope when scopeField is set, with scopeOf resolving the scope and failing closed. Shared (no scope) templates are readable by all and changed only by a platform admin. Covered on an in-memory MongoDB with two made-up sites.

Not tested: the print endpoint's scope check (not built), a real site, a browser.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Both outputs draw the same marks, with barcodes, QR and Data Matrix as vectors from bwip-js (MIT) and the PDF written with pdfkit (MIT). The PDF writer is its own export so the plugin config does not load pdfkit.

Not tested: PDF in a viewer or printer, SVG in a browser, scanning a printed code, sheet pages, images.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
POST /api/labels/print renders a PDF for given documents and a template. It refuses signed-out requests, people with no scope, another scope's template, any document the person cannot read and more than 2,000 labels, and writes one log entry of ids and counts.

Not tested: over real HTTP, render time at 2,000 labels, sets, media choice, sheet pages.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The plugin now throws at config time unless access.manage or access.print is set, and no longer lets any signed-in person read templates or print. access.print decides printing, otherwise access.manage does. Template lookup tries the key, then the id as given, so numeric ids work on SQL databases.

Not tested: numeric ids on a real SQL database; the cost of reading documents at depth 3.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nd start slot

Sheet printing was missing: the PDF made one page per label and the endpoint
always used 4 x 6 in thermal. Now renderPdf fills the media's grid from a start
slot and flows onto new pages, the endpoint validates media and start slot and
refuses bad values plainly, and two Avery Letter presets are added.

Sets are not built (the design leaves their relationships open). Preset
measurements are published sizes, not checked on a printed sheet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main took the core branch by rebase, so the same changes sit under new
commit ids. Main's tree matches the core branch exactly, so this keeps the
branch tree. Nothing is rewritten. Tests: see pull request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mgilardi
mgilardi changed the base branch from co/labels-core to main November 16, 2026 16:43
@mgilardi

Copy link
Copy Markdown
Contributor Author

Security and privacy review (EXTANT APE, Head of Research for Simon)

Verdict: changes. One small fix: put upper bounds on sheet media.

Checked and fine: CI green. Local: 54 of 54 tests pass. No new dependencies.

  • media must be a string or number, and presets are matched with Object.hasOwn.
  • Stored media is read as the person, so scope applies. Unknown, broken or dangling media is refused.
  • start must be a whole number from 1 to columns × rows.
  • A template bigger than the sheet's label is refused, and the page count stays under MAX_LABELS.
  • The README matches the code.

Fix before merge

  1. parseMedia has no upper bounds (src/core/presets.ts). A manager can store a sheet with a 1e9 mm page and millions of slots. That makes huge PDF page boxes on the server. With Labels: print button and accessible print dialog #4 applied, the dialog draws one button per slot, so every printer who picks that media hangs their browser. Cap the page size (1 m or less, say) and the slots (1,000 or fewer, say), and add a test.

Worth doing
2. findMedia (src/print.ts:38) looks up key before id, and key isn't unique. A media whose key equals another record's id hides that record, and duplicates in one scope resolve unpredictably. A stored key equal to a preset name is silently ignored. Make key unique per scope and refuse preset names.
3. The print log (print.ts:127) doesn't record the media or start slot used. That would help the audit trail.
4. #3 and #5 both change the layout and renderPdf calls in print.ts. Whoever merges second should check that images still resolve on sheet media.

🤖 Generated with Claude Code

The review found that a manager could store a sheet with a 1e9 mm page and
millions of slots. Pages and rolls are capped at 1,000 mm and sheets at 1,000
labels per page.

Tested: 1 new test. Not tested: the media key uniqueness suggestion and
logging the media in the print log (left for a later change).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant