Skip to content

Commit 5161056

Browse 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>
1 parent 7f72b49 commit 5161056

29 files changed

Lines changed: 699 additions & 589 deletions
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
'@objectstack/service-print': patch
3+
---
4+
5+
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 -->

‎content/docs/permissions/system-context.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ One of the largest consumers of the flag;
197197
| 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` |
198198
| 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` |
199199
| 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` |
201201
| 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` |
202202
| 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` |
203203
| 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` |

‎content/docs/ui/print-pages.mdx‎

Lines changed: 36 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Print pages — printing a record to a PDF file
33
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
55
---
66

77
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
1010
from the `print` declaration, mapped to print CSS by the console.
1111

1212
`@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.
1617

1718
## Declare the print page
1819

1920
A print page is a `kind: 'full'` record page whose blocks are all from the
2021
printable subset (`PRINTABLE_PAGE_COMPONENT_TYPES` in `@objectstack/spec/ui`;
21-
`os validate` refuses anything else). The record's object must allow files.
22+
`os validate` refuses anything else).
2223

2324
```ts
2425
import { definePage } from '@objectstack/spec/ui';
@@ -35,8 +36,6 @@ export const InvoiceDocumentPage = definePage({
3536
{ name: 'main', components: [{ type: 'record:details' }] },
3637
],
3738
});
38-
39-
// …and on the object: enable: { files: true }
4039
```
4140

4241
A record prints on **any record page of its object that declares `print`**, so
@@ -141,11 +140,11 @@ const print = kernel.getService<IPrintService>('print');
141140
print.status();
142141
// { state: 'ready', placement: 'local', version: '141.0.7390.37' }
143142

144-
const file = await print.printRecordToFile(
143+
const printed = await print.printRecordToPdf(
145144
{ app: 'sales', object: 'invoice', recordId: 'inv_1', page: 'invoice_document' },
146145
context, // the requesting user's execution context
147146
);
148-
// { fileId, attachmentId, size, filename: 'INV-0001.pdf' }
147+
// { pdf: Uint8Array, size, filename: 'INV-0001.pdf', contentType: 'application/pdf' }
149148
```
150149

151150
With no `filename`, the PDF is named after the record: its display name — the
@@ -155,25 +154,29 @@ The name is made safe for a file: `/ \ : * ? " < > |` become `_`, control
155154
characters and runs of whitespace become one space, leading dots are dropped,
156155
and it is cut to 100 characters. A record with no display value keeps
157156
`<page>-<recordId>.pdf` (`invoice_document-inv_1.pdf`). A `filename` in the
158-
request is used exactly as given. Printing a record twice attaches two files
159-
of the same name; neither replaces the other.
157+
request is used exactly as given, up to 255 characters; a longer one, or one
158+
that is not well-formed text (it holds a lone UTF-16 surrogate), is refused
159+
`VALIDATION_ERROR` / 400 before anything is rendered.
160160

161161
The page is rendered as the requesting user — never as the system — through a
162162
short-lived session minted for that user and revoked as soon as the print ends,
163-
whether it succeeded or not. The PDF is archived as theirs: the attachment is
164-
written under their own permissions, and both the file and the attachment name
165-
them. A user can never archive a record they could not read, or attach a file
166-
where they could not attach one by hand.
163+
whether it succeeded or not. A print asks one permission: the user must be able
164+
to read the record. A user who may read a record but not edit it prints it as
165+
anyone else does; a user who cannot read it is refused, and never learns
166+
whether it exists.
167167

168168
## Print from the console
169169

170170
`PrintServicePlugin` also mounts one HTTP route on the kernel's HTTP server,
171171
`POST /api/v1/print/records`, so a user can print the record they are looking
172172
at. Its JSON body is the same request, `{ app, object, recordId, page,
173-
filename? }`, and it answers `201` with the stored file,
174-
`{ fileId, attachmentId, size, filename }`. The print runs as the signed-in
175-
caller, exactly as an in-process print with their context does, and the file is
176-
attached once, by the service.
173+
filename? }`, and it answers `200` with the **PDF itself** as the body:
174+
`Content-Type: application/pdf`, `Content-Disposition: attachment` naming the
175+
file (an ASCII `filename=` and the RFC 5987 `filename*=UTF-8''…` form, so a
176+
name such as `报价单.pdf` survives), and `Cache-Control: no-store`. A browser
177+
saves it as a download. The print runs as the signed-in caller, exactly as an
178+
in-process print with their context does. A refusal is the usual JSON error
179+
envelope.
177180
178181
A kernel that owns no HTTP server, such as an environment's kernel behind a
179182
shared host, reaches the same route through the runtime dispatcher: it forwards
@@ -185,43 +188,26 @@ the user's language saying the action needs a service this environment does
185188
not have, never the package name. A `SERVICE_UNAVAILABLE` / 503 keeps the
186189
route's own sentence, since it can clear on a retry.
187190
188-
Reach it from the console with an ordinary `type: 'api'` action on the object:
189-
190-
```ts
191-
import { defineAction } from '@objectstack/spec/ui';
192-
193-
export const GenerateInvoicePdf = defineAction({
194-
name: 'generate_invoice_pdf',
195-
label: 'Generate PDF',
196-
objectName: 'invoice',
197-
type: 'api',
198-
target: '/api/v1/print/records',
199-
method: 'POST',
200-
recordIdParam: 'recordId', // the clicked record's id
201-
bodyExtra: { app: 'sales', object: 'invoice', page: 'invoice_document' },
202-
locations: ['record_row'],
203-
refreshAfter: true,
204-
});
205-
```
206-
207-
The route above answers JSON, which the action reads as data. The REST action
208-
door also carries a file: a route that answers a PDF itself as an attachment
209-
(`Content-Disposition: attachment`, not JSON) is relayed byte for byte, and the
210-
console saves it under the name the header gives. The MCP action door does not
211-
carry a file and answers `502` instead. See
191+
A declared `type: 'api'` action whose `target` is this route (the clicked
192+
record's id under `recordIdParam: 'recordId'`, and `app`, `object` and `page`
193+
in `bodyExtra`) delivers the PDF: the REST action door relays the route's
194+
answer byte for byte, `Content-Type` and `Content-Disposition` included, and
195+
the console saves it as a download under the name that header gives. A PDF
196+
larger than the door's 32 MiB bound is the door's `502`. The MCP action door
197+
does not carry a file: `run_action` on such an action answers `502`. See
212198
[Call it over REST](/docs/ui/actions#call-it-over-rest).
213199
214200
The route refuses, before it asks the service anything: an anonymous request
215201
(`UNAUTHENTICATED` / 401); a sign-in held by an authentication policy (`403` with
216202
the policy's own code); a request from an **impersonation session** — an
217-
administrator signed in as the user — (`PERMISSION_DENIED` / 403: a print is
218-
archived in the user's name, so it is never made for them by someone else); and
203+
administrator signed in as the user — (`PERMISSION_DENIED` / 403: a print
204+
signs a session in under the user's name, so it is never made for them by
205+
someone else); and
219206
a query parameter or a body field outside the request (`VALIDATION_ERROR` /
220207
400). Every refusal below then reaches the caller with its own `code` and
221208
`status`; a 5xx answers with the route's own sentence, and the service's text is
222209
written to the server log. The route writes no audit row of its own: the print's
223-
session sign-in and sign-out are recorded as any sign-in is, and the file and
224-
the attachment name the caller.
210+
session sign-in and sign-out are recorded as any sign-in is.
225211
226212
## Refusals
227213
@@ -235,15 +221,11 @@ before a session is minted or a browser is started, in this order:
235221
| 3 | No such page | `RESOURCE_NOT_FOUND` / 404 |
236222
| 3 | The page is not a record page of the object (`type: 'record'`, that `object`), or declares no `print` | `VALIDATION_ERROR` / 400 |
237223
| 4 | The record does not exist, or the caller cannot read it | `RECORD_NOT_FOUND` / 404 |
238-
| 5 | The object does not declare `enable: { files: true }` | `FILES_DISABLED` / 403 |
239-
| 5 | The caller may not create attachments at all | `PERMISSION_DENIED` / 403 |
240-
| 5 | The caller may not attach a file to this record (attaching needs edit access to it) | `ATTACHMENT_PARENT_ACCESS` / 403 |
241224
242225
An engine that did not answer its last probe is probed once more only after
243-
step 5, so no browser is started before every refusal above has had its say.
226+
step 4, so no browser is started before every refusal above has had its say.
244227
245-
After those, a print can still fail as the render or the archive does: the page
246-
not rendering within the 30 s budget (`TIMEOUT` / 504), or the archive's own
247-
refusals, such as a file over the upload size limit (`PAYLOAD_TOO_LARGE` / 413).
228+
After those, a print can still fail as the render does: the page not rendering
229+
within the 30 s budget (`TIMEOUT` / 504).
248230
A failure to end the session afterwards never replaces the print's own outcome;
249231
it is logged, and the session expires on its own within 60 s.

‎examples/app-showcase/src/data/objects/invoice.object.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ export const Invoice = ObjectSchema.create({
6060
color: 'green',
6161
description: 'A customer invoice entered together with its line items.',
6262

63-
// Files on an invoice: its printed PDF is archived as an attachment of the
64-
// record (`showcase_invoice_document` is its print page).
63+
// Files on an invoice: users attach files to the record. A print stores
64+
// none: `@objectstack/service-print` answers the PDF as a download.
6565
enable: { files: true },
6666

6767
// A PAID invoice is closed (ADR-0162). The platform refuses a caller's

‎examples/app-showcase/src/system/translations/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ export const ShowcaseTranslationBundle = {
793793
_actions: {
794794
showcase_generate_invoice_pdf: {
795795
label: '生成 PDF',
796-
successMessage: 'PDF 已附加到发票。',
796+
successMessage: '发票已打印为 PDF。',
797797
},
798798
},
799799
},

0 commit comments

Comments
 (0)