You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 5161056
Browse filesBrowse the repository at this point in the historyBrowse files
fix(service-print)!: the record print downloads the PDF and stores no attachment (#39076)
Part of #38894 — this PR is the service and route half of the ruling (a
print writes no attachment and the route answers the PDF). The delivery
half, the REST action door relaying a file and the console saving it
(ruling A, record 7344041246), merged first in #39141 (`0fff9ae00b`);
this branch carries it through a merge of `origin/main`.
Clause-②: yes (narrowing)
Metadata-protocol: none
Skills-docs: none — no published skill teaches the print service or its
door (git grep over skills/ for print/records, printRecordToFile and
service-print: zero hits; control: attachment has hits)
## 维护者速读
- 用户点"生成 PDF"(或直接调用打印接口)拿到的是 PDF 下载,记录上不再存附件;只能查看、不能编辑这条记录的人也能打印。
- 按维护者在该卡上的裁决做:生成 PDF 是导出而不是存档,这取代了旧打印存档卡里"把 PDF 存到记录上"的那一半。
- 若出错:只影响打印本身(点按钮会看到报错、拿不到文件),不会写坏任何数据,改动可以整体撤回;AI 助手那条入口仍然拿不到文件,会报错。
- 要你做的:审批并合入本 PR。按钮报错的空窗已经关闭:让动作入口把文件交给浏览器下载的那一半已先合入主干。
## What changes
- `IPrintService.printRecordToFile` becomes `printRecordToPdf` and
returns the PDF itself (`pdf`, `size`, `filename`, `contentType:
'application/pdf'`). It no longer calls the files service, writes no
`sys_attachment` row, and carries no `source` / `print_page` marker.
- Permission: the READ check (plus the existing re-probe) is now the
whole gate. The edit/attach gate (`assertMayAttach`) and the
`FILES_DISABLED` refusal are gone, so a user who can read but not edit
the record can print it.
- `POST /api/v1/print/records` and the print door member answer `200`
with the PDF bytes: `Content-Type: application/pdf`,
`Content-Disposition: attachment; filename="ascii-fallback";
filename*=UTF-8''percent-encoded` (RFC 6266 / RFC 5987), `Cache-Control:
no-store`, `X-Content-Type-Options: nosniff`. Refusals keep the JSON
error envelope.
- A request's own `filename` is refused `VALIDATION_ERROR` / 400 before
anything is rendered when it is over 255 characters
(`PRINT_FILENAME_MAX_CHARS`) or holds a lone UTF-16 surrogate. The
header builder is also total: a lone surrogate in any other name (a
record's display value) is written as U+FFFD instead of throwing.
- `@objectstack/service-storage` is no longer a dependency of
service-print (and the plugin no longer wires the attachments service).
- **A declared print action delivers the PDF.** With #39141 on `main`,
the REST action door relays a non-JSON `2xx` answer that carries
`Content-Disposition: attachment` byte for byte and the console saves
it, so a declared `type: 'api'` action that targets the route (showcase
`GenerateInvoicePdfAction`, HotCRM Print Quote) downloads the PDF under
the print's file name. MCP `run_action` still answers a file `502`. The
changeset, `content/docs/ui/print-pages.mdx`, both route-ledger notes,
the plugin jsdoc and the showcase action's jsdoc say so.
- Showcase: the print action's jsdoc, `successMessage` and its zh-CN
translation, and the comments on the invoice page and object no longer
promise an attachment; the jsdoc says the console downloads the PDF
through the REST action door. The action's wiring is unchanged.
- Contract prose only:
`packages/spec/src/contracts/print-door-service.ts` and
`packages/runtime/src/domains/print.ts` jsdoc now say "download". No
type moves.
- BREAKING changeset with FROM / TO for the service, the wire answer and
an app that declares a print action, the HotCRM migration line
(`quote_print_presented` becomes an explicit "mark presented" action),
and one ADR-0087 marker.
Risk-first reading order:
1. `packages/services/service-print/src/print-service.ts` — the removed
attach path and `validateRequest`; the read check and the session revoke
in `finally` must remain.
2. `packages/services/service-print/src/print-routes.ts` — `sendPdf` and
`pdfContentDisposition` (header quoting, encoding, the lone-surrogate
replacement).
3. `.changeset/38894-print-downloads-no-attachment.md` — what an
upgrading app reads about a declared print action (REST door downloads,
MCP `502`).
## Tests
- Unit (`print-routes.test.ts`): the success case is a 200 PDF with the
four headers. A non-ASCII name `报价单 "Q1".pdf` gives `filename="___
_Q1_.pdf"` plus a UTF-8 `filename*`. A name holding a lone surrogate
(`\ud83d.pdf`, `a\udc00.pdf`) is `VALIDATION_ERROR` / 400 with nothing
minted, read or rendered. `pdfContentDisposition` writes a lone
surrogate as `%EF%BF%BD` and keeps a paired one. The engine double traps
every insert/update/delete/upsert (`expectNothingWritten`).
- Unit (`print-door-member.test.ts`): the door member answers the same
PDF bytes as the mounted route.
- Unit (`print-service.test.ts`): "read access is the whole permission;
nothing is stored"; a 255-character name prints and a 256-character one
is refused; a paired surrogate prints (control) and a lone one is
refused, both before anything starts; a display value holding a lone
surrogate names the file with U+FFFD.
- Dogfood, real stack (`print-service-archive`):
- an auditor who can read but not edit prints;
- no `sys_attachment` row is written;
- two prints write nothing;
- an attacher prints and still writes nothing;
- a caller who cannot read the record (hidden by RLS) is refused
`RECORD_NOT_FOUND` / 404.
- Dogfood `print-service-named-page` / `print-service-render`: a render
failure is forced by dropping the renderer's connections and asserts a
status of 500 or above.
- Conformance, end to end
(`action-door-attachment-38894.conformance.test.ts`, both transports):
the real `PrintServicePlugin` mounts its route; a declared print action
(`recordIdParam` plus `bodyExtra`, as the showcase declares it) sent to
`POST /api/v1/actions/c38894_doc/print_pdf` answers `200` with the PDF
bytes, `Content-Type: application/pdf`, the route's own
`Content-Disposition: attachment; filename="__ INV-1.pdf";
filename*=UTF-8''%E5%8F%91%E7%A5%A8%20INV-1.pdf`, `no-store` and
`nosniff`; the print service received exactly the assembled request, as
the caller. Only the renderer (`printRecordToPdf`) is replaced, since no
browser runs there.
## Acceptance notes
- **Delivery: decided and landed.** The maintainer ruled A (record
7344041246): the REST action door relays a file and the console saves
it; the MCP door keeps refusing. #39141 shipped it and merged first
(`0fff9ae00b`), so `main` never had the `502` window. This branch merged
`origin/main` at `a0a9d699` (K = 39; no conflict) and then restated
every text that described the window (commit `3510e8a6`).
- Files touched outside the claimed surface, each forced by the change:
- `print-service-plugin.ts` and its two tests (the attachments wiring
was removed);
- `package.json` and `pnpm-lock.yaml` (the dependency was dropped);
- `packages/runtime/src/domains/print.ts` (jsdoc) and
`packages/runtime/src/route-ledger.ts` (the print row's note);
- `packages/services/service-print/src/print-route-ledger.ts` (the row's
note);
- `content/docs/permissions/system-context.mdx` (row 47d);
- the showcase print action's texts (four files);
- `packages/qa/dogfood/test/authz-conformance.matrix.ts` (row text);
- four dogfood tests;
- the changeset;
-
`packages/qa/http-conformance/src/action-door-attachment-38894.conformance.test.ts`
(one end-to-end pin added to #39141's suite, as the dispatch ordered).
- `packages/spec/src/contracts/print-door-service.ts` was edited for
jsdoc only. The result type lives in service-print, not spec.
- The `Content-Disposition` builder duplicates service-storage's, which
is not exported. Sharing it is a possible follow-up, not done here.
- The `print-service-render` dogfood is SKIPPED locally because no
console is built: NOT MEASURED locally, so CI is the reading.
## Verification
Two-minute check: `pnpm --filter @objectstack/service-print exec vitest
run --maxWorkers=2 src/print-routes.test.ts` — expect all tests to pass,
including "a file name holding a lone UTF-16 surrogate: VALIDATION_ERROR
/ 400, before anything is minted or rendered".
<details><summary>Readings at 3510e8a</summary>
- `os-regen-merge.sh`: merge `a0a9d699`, no conflict, no `os-regen` path
taken from `main`; `@objectstack/spec check:generated` after the build:
all 14 generated artifacts up to date (no regeneration commit). The
sibling's body is intact at the head (`isRelayableAttachmentAnswer`,
`saveAttachmentAnswer`: same counts at `origin/main` and HEAD).
- `@objectstack/service-print` `vitest run`: 9 files / 143 tests passed.
`typecheck`: exit 0.
- `@objectstack/http-conformance`: `action-door-attachment-38894` +
`hono-print-door`: 2 files / 14 tests passed (2 new, one per transport).
`typecheck` (tsc + `check:test-typecheck`): exit 0.
- `@objectstack/runtime`: `route-ledger.conformance`, `own-door-bridge`,
`api-action-forward`: 3 files / 193 tests passed.
- showcase `test/invoice-generate-pdf-action.test.ts`: 4 passed.
- Local gate subset narrowed to this round's delta (changeset, docs,
ledgers, the test file): 24 commands, all exit 0. `dispatch-gates
--ran`: 115 of 139 derived families left to CI (declared narrowing).
- No ablation this round: the reconciliation changes no tested behaviour
(texts plus one added pin).
- Earlier readings (ablations of `sendPdf`, the edit gate, the
lone-surrogate refusal and the header builder; the four print dogfood
files) were taken at `2125d13975` and are in the contract review
7340628991; no print code changed since.
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01QSeKYnrQ7UMtHofKQVjcH2
<!-- signed: repo:objectstack@os-justin · os-justin ·
session_01QSeKYnxn6m1nQaRrNvdiLw -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix!: a record print answers the PDF itself and writes no attachment
6
+
7
+
Clause-②: yes (narrowing)
8
+
Metadata-protocol: none
9
+
10
+
**BREAKING — a print no longer attaches the PDF to the record; it hands the PDF back as a download.**`POST /api/v1/print/records` now answers the PDF itself and stores nothing; keeping the PDF on the record is a separate, explicit act. A declared `type: 'api'` action that targets the route, which is how an app put "Generate PDF" on a record page, now downloads the PDF in the console: see "Apps that declare a print action" below.
11
+
12
+
-**The door's answer.**`POST /api/v1/print/records` used to answer `201` with JSON naming the stored file (`fileId`, `attachmentId`, `size`, `filename`). It now answers `200` with the PDF itself as the body: `Content-Type: application/pdf`, `Content-Disposition: attachment` (an ASCII `filename=` and the RFC 5987 `filename*=UTF-8''…` form, so a name such as `报价单.pdf` survives), `Cache-Control: no-store`. Refusals keep the JSON error envelope.
13
+
-**Nothing is stored.** A print used to write one `sys_file` and one `sys_attachment` on the record, as the caller. It now writes nothing.
14
+
-**Read access is the whole permission.** Printing used to need `enable: { files: true }` on the object (`FILES_DISABLED` / 403) and the attach rule, edit access to the record (`ATTACHMENT_PARENT_ACCESS` / 403). It now needs read access to the record and nothing else: a user who can read a record but not edit it can print it, on any object.
15
+
-**No storage dependency.** The `print` service was `unavailable` without a `file-attachments` service; it now needs none, and the package no longer depends on `@objectstack/service-storage`.
16
+
- A request's own `filename` is bounded at 255 characters (`PRINT_FILENAME_MAX_CHARS`) and must be well-formed text (a lone UTF-16 surrogate is refused); either refusal is `VALIDATION_ERROR` / 400, before anything is rendered.
17
+
18
+
The in-process verb is renamed with its result, so a caller that still reads the stored file's ids fails at its own call instead of reading `undefined`:
19
+
20
+
- FROM `IPrintService.printRecordToFile` TO `IPrintService.printRecordToPdf`, which takes the same request and context and resolves to the PDF.
21
+
- FROM `PrintedRecordFile` TO `PrintedRecordPdf`, `{ pdf, size, filename, contentType }`: read `pdf` where the code read `fileId` or `attachmentId`.
22
+
23
+
**Apps that declare a print action.** The route's answer is now a file, and the REST action door (`POST /api/v1/actions/...`) relays a target's non-JSON `2xx` answer that carries `Content-Disposition: attachment` byte for byte:
24
+
25
+
-**Through the REST action door and the console**, a declared `type: 'api'` action whose `target` is `/api/v1/print/records` (the showcase's `GenerateInvoicePdfAction`, HotCRM's Print Quote) delivers the PDF: the door answers the route's bytes with its `Content-Type: application/pdf` and `Content-Disposition: attachment`, and the console saves the file under the name that header gives. A PDF larger than the door's 32 MiB bound is the door's `502`.
26
+
-**MCP `run_action`** still answers a file with its own `502`: a tool result cannot carry one. A caller that ran the action over MCP to archive a PDF has no replacement there.
27
+
- FROM → TO for an app that declares such an action: it used to answer the stored file's ids (`fileId`, `attachmentId`, `size`, `filename`) and leave the PDF on the record's Attachments; a click now downloads the PDF, and nothing is on the record. A success message that promised an attachment should say the PDF was printed.
28
+
29
+
The one-line fix for an app that wants the PDF kept on the record: save it with an explicit act of its own (an upload to the record's attachments, or an app action). An automation keyed on the attachment a print used to write no longer fires on a print: HotCRM's `quote_print_presented` flow, which matched the printed attachment's file name, must become an explicit "mark presented" action.
30
+
31
+
<!-- adr-0087: not-required (runtime-export-retired @objectstack/service-print#PrintedRecordFile, @objectstack/service-print#IPrintService.printRecordToFile) a TypeScript consumer of the print service meets the break at its own import or call; no metadata names the print service, so objectstack migrate meta has nothing to rewrite -->
Copy file name to clipboardExpand all lines: content/docs/permissions/system-context.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -197,7 +197,7 @@ One of the largest consumers of the flag;
197
197
| 47 | The inbound-mail read gates return early (the read AST) | service-mailbox | Get: every `sys_mail_message` and `sys_mail_association` row on `find` / `findOne` — the ingest writer and each gate's own pre-scan, which read the association and mailbox rows a decision needs. Lose: the narrowing of a message to callers who can read a record it is associated with or who own its mailbox (so the unassociated pool is restricted), and of an association to callers who can read the record it names (on `count` and `aggregate` too, so a total agrees with the rows) |`gateMiddleware`|
198
198
| 47b | The inbound-mail ingest seam: `ingest` admits the system context ALONE, and `rematch` admits it without the organization, owner or `manage_mailboxes` check | service-mailbox | Get: a mail source hands a mailbox its messages, and server code re-matches any mailbox. Lose: nothing a user held — every other caller of `ingest` is refused (`PERMISSION_DENIED`), because an ingested message is shown on every record its correspondents' addresses match and a user who could hand the seam a message could write one in a correspondent's name; every other caller of `rematch` must be in the mailbox's organization and own the mailbox or hold `manage_mailboxes`|`ingest`, `authorizeRematch`|
199
199
| 47c | The inbound-mail IMAP sync: `syncMailbox` and `syncAll` admit the system context ALONE | service-mailbox | Get: the sync job reads every mailbox row (its organization, address and IMAP cursor), writes the cursor back, and hands each fetched message to `ingest` under the system context. Lose: nothing a user held — every other caller is refused (`PERMISSION_DENIED`), because a sync stores a mailbox's mail and moves its cursor |`syncMailbox`, `syncAll`|
200
-
| 47d | The print service REFUSES the system context: `printRecordToFile` admits a human user acting for themselves alone | service-print | Get: nothing — a system caller is refused (`PERMISSION_DENIED`) before any page is read, session minted or browser started. Lose: nothing a user held — the PDF is rendered as the requesting user and never as the system, so a record is archived only by someone who could read it |`refuseUnlessHumanCaller`|
200
+
| 47d | The print service REFUSES the system context: `printRecordToPdf` admits a human user acting for themselves alone | service-print | Get: nothing — a system caller is refused (`PERMISSION_DENIED`) before any page is read, session minted or browser started. Lose: nothing a user held — the PDF is rendered as the requesting user and never as the system, and handed back to that user only, so a record's PDF reaches only someone who could read it; a print stores nothing|`refuseUnlessHumanCaller`|
201
201
| 47e | The caller-scoped attach verbs REFUSE the system context: `attachFileAs` and `assertMayAttach` admit a signed-in user alone, and so do the caller-scoped record-file verbs the MCP `read_file` and `create_upload_link` tools call (`listRecordFilesAs`, `readRecordFileAs`, `createUploadLinkAs`, `createUploadLinkForNewRecordAs`) | service-storage | Get: nothing — a system caller is refused (`PERMISSION_DENIED`); the system attaches through `attachFile`, whose rows name no user. Lose: nothing a user held — the caller-scoped verbs insert the attachment under the caller's context so every insert gate judges that user and both rows name them, and the record-file verbs read the record and judge the file as that user, and bind an upload link to them; `createUploadLinkForNewRecordAs` names no record, so it asks the object's create verdict and the field's writability as that user instead | `packages/services/service-storage/src/file-attachment-service.ts#requireUserContext`, `packages/services/service-storage/src/record-file-access.ts#requireUserContext` |
202
202
| 47f | The file-reference claim path asks no read verdict of a system write: a record write claims or copies a referenced file only as its caller may read it (the download door's verdict), and a system write carries no caller to ask | service-storage | Get: a system write claims or copies any file the organization-scoped lookup reaches, as before #25692; a deliberate server-side copy between records runs this way. The exception is a file uploaded through an upload link that names no record (#32686), and the ids such a link answers before its upload (its own, and those it reserves for a several-file upload): until a record has held the file, only its uploader's own write takes it, so a system write naming it is refused at the field. Once a record holds it, a system write copies it as any; once a record lets it go, it is judged as any released file. Lose: nothing a user held — a user write is judged by the download door's verdict, and a context-less programmatic write is not asked either | `referencingCallerOf` |
203
203
| 47g | The `sys_file` storage-owned columns guard returns early on create: a system insert keeps the `key`, `mime_type`, `size`, `status` and `etag` it writes | service-storage | Get: the storage service's own inserts (the upload doors, the field-file copy and backfill) write those five columns. Lose: nothing a user held — a non-system create has them dropped and starts `pending`, and on update the same columns are `readonly`, so the UPDATE `readonly` strip keeps them for every non-system caller |`installSysFileStorageOwnedColumnsGuard`|
Copy file name to clipboardExpand all lines: content/docs/ui/print-pages.mdx
+36-54Lines changed: 36 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Print pages — printing a record to a PDF file
3
3
navTitle: Print Pages
4
-
description: Declare print on a record page, then archive a record's PDF as an attachment with the print service, rendered in headless Chromium as the requesting user
4
+
description: Declare print on a record page, then download a record's PDF from the print service, rendered in headless Chromium as the requesting user
5
5
---
6
6
7
7
A **print page** is an ordinary page with one more key, `print`. The console
@@ -10,15 +10,16 @@ paper: the sheet size, margins, page numbers and repeated header and footer come
10
10
from the `print` declaration, mapped to print CSS by the console.
11
11
12
12
`@objectstack/service-print` prints the same page on the server. It renders the
13
-
record's print page in **headless Chromium**, as the requesting user, and
14
-
archives the PDF as a file attached to the record — downloadable from the
15
-
record's attachments, and usable wherever a file is.
13
+
record's print page in **headless Chromium**, as the requesting user, and hands
14
+
the PDF back as a **download**. A print stores nothing: no file, and no
15
+
attachment on the record. Keeping a PDF on the record is a separate, explicit
16
+
act — an upload to the record's attachments, or an action of the app's own.
16
17
17
18
## Declare the print page
18
19
19
20
A print page is a `kind: 'full'` record page whose blocks are all from the
20
21
printable subset (`PRINTABLE_PAGE_COMPONENT_TYPES` in `@objectstack/spec/ui`;
21
-
`os validate` refuses anything else). The record's object must allow files.
0 commit comments