poli-page 0.9.1 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b1d39c7b75c9164a55a5531d76ba33d6558fa47f7ddeb790ac5d79e8fe47599
4
- data.tar.gz: f69604f045148201ba67ad64adbd39c1309e942cb2b16c00da1ee08d16cd4dee
3
+ metadata.gz: f6e6c0236a43dbf8ecc971781a63e99e6e878f045f4ebf9b9c86f589618f69fc
4
+ data.tar.gz: d4b0dc1776a2090b1dd57c5623a819048050f1188fcf8ad519a78d2c03ca481e
5
5
  SHA512:
6
- metadata.gz: 8b58efa2166055f4b7b444f99e0647115bdd228ec6380e69761828a0d9a0c7bcc059da9da6a088a743c4895b8813d7511e52e3d3b086b07c96e9d11b6270aa32
7
- data.tar.gz: 007ba35923396a0bbcec3a6189fab9a61079fd2bce40516c9c684689bd7cfb1f86891139fdbdfc7a7e9f470024587272dc767ef72961665b82de73ddbacf79da
6
+ metadata.gz: 9325ac500f8e8dff0f9049b14214285d877f58b01123fc8dc061fcec54db51329aaa7bc4a771ed56ee94dc987e20a84d88789bb865bb61c2df7089bf4605c259
7
+ data.tar.gz: 6b97af27df67085ea10b23d334a683a8f85535f454bc51ab122dd2dcb68c996f16d51f7e073f918cf9c595b71eb26b75557decf968830492dae9f4e1f48bfa12
data/CHANGELOG.md CHANGED
@@ -5,11 +5,308 @@ here.
5
5
 
6
6
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
7
7
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8
- Breaking changes between major versions are summarized in
8
+ Breaking releases (minor bumps while on 0.x) are summarized in
9
9
  [MIGRATION.md](MIGRATION.md).
10
10
 
11
11
  ## [Unreleased]
12
12
 
13
+ ## [0.13.0] - 2026-11-02
14
+
15
+ Conformance with the Poli Page API contract v0.13.0
16
+ ([poli-page/api-contract](https://github.com/poli-page/api-contract)). The
17
+ SDK now shares its major.minor with the Poli Page API, so it moves from 0.11
18
+ to 0.13. See [MIGRATION.md](MIGRATION.md#from-0110-to-0130).
19
+
20
+ ### Added
21
+
22
+ - `invalid_response`: a 2xx answer whose body is not JSON, from a method that
23
+ expects JSON (the API call of `render.document`, `render.pdf` and
24
+ `render.pdf_stream`, `documents.get`, `documents.thumbnails`), raises
25
+ `PoliPage::InvalidResponseError` with the code `invalid_response`, the
26
+ message `Invalid response: HTTP <status> body is not JSON`, the real 2xx as
27
+ `status`, the answer's `x-request-id` as `request_id`, and the JSON
28
+ parser's error as `cause`. It is never retried, `retryable?` is `false`,
29
+ and `on_error` fires with it. Such a body usually comes from a proxy or a
30
+ captive portal between the SDK and the API.
31
+ - `io_error`: `render_to_file` raises `PoliPage::FileWriteError` when it
32
+ cannot write the file (creating a parent directory, opening, writing or
33
+ moving it into place). No status, the message
34
+ `Failed to write PDF: <reason>` with Ruby's own error text, that error as
35
+ `cause`, never retried.
36
+ - `to_payload` answers `status` 502 for `invalid_response`. The error's own
37
+ `status` keeps the real 2xx.
38
+ - `scripts/release.sh` and the release workflow check that the API contract
39
+ pinned for the tests has the release's major.minor (see
40
+ [RELEASING.md](RELEASING.md)).
41
+
42
+ ### Changed
43
+
44
+ - **BREAKING**: `Error#to_payload` returns `{ code:, message:, status:,
45
+ requestId: }`: the `:request_id` key is renamed `:requestId`, the key every
46
+ Poli Page SDK uses, so every framework integration answers the same JSON
47
+ body (`"requestId"`). Read `payload[:requestId]` instead of
48
+ `payload[:request_id]`. The other keys are unchanged.
49
+ - **BREAKING**: a 2xx whose body is not JSON (an empty body included) was
50
+ `PoliPage::InternalError` (`INTERNAL_ERROR`,
51
+ `response body was not valid JSON: …`); it is now `invalid_response`
52
+ (above). A 2xx JSON value that is not an object stays `INTERNAL_ERROR`.
53
+ - **BREAKING**: `render_to_file` failures to write the file are now
54
+ `io_error`, whatever the error. Before, `EACCES`, `ENOSPC`, `EISDIR`,
55
+ `ENOENT` and `EROFS` were `PoliPage::InvalidOptionsError`
56
+ (`invalid_options`, `failed to write to <path>: …`), and any other error
57
+ (`ENOTDIR`, `EPERM`, `IOError`…) escaped as the raw Ruby exception.
58
+ - `render_to_file` writes to a temporary file in the target's directory and
59
+ renames it over the target only once the PDF is complete. When anything
60
+ fails (the render, the download or the write), the target is left as it
61
+ was: an existing file keeps its content and a missing one is not created
62
+ (before, a failure deleted the target). The directory and the temporary
63
+ file are prepared before the render, so a path that cannot be written
64
+ costs no render. A new file gets the usual mode (`0666` minus the umask);
65
+ a replaced file keeps its own. When the target is a symbolic link, the file
66
+ it points to gets the PDF and the link stays a link. An existing target
67
+ that is not a regular file (a directory, a FIFO, a device, a socket)
68
+ raises `io_error` with the message
69
+ `Failed to write PDF: <path>: not a regular file`, and one that is not
70
+ writable raises `io_error` too; both fail before any render and are not
71
+ replaced. Because the PDF is renamed into place, `render_to_file` needs
72
+ write permission on the target's directory, and a replaced file is a new
73
+ file: it is owned by the user that runs the SDK, and a hard link to the
74
+ old file keeps the old content.
75
+ - The presigned-URL download is bounded by the client's `timeout:`. For
76
+ `render.pdf` and `download_pdf` it bounds the whole download, from the
77
+ connection to the last byte. For `render.pdf_stream` and `render_to_file`
78
+ it bounds the wait for the first byte of the PDF (connection, answer and
79
+ first chunk together), then each wait for the next chunk (an idle
80
+ timeout), so a large PDF read at the caller's pace is not cut off.
81
+ Before, `timeout:` only bounded each socket operation of the download, so
82
+ a slow storage could keep `render.pdf` going well past it.
83
+ - A download that outlasts its timeout raises `DOWNLOAD_FAILED` with the
84
+ message `Failed to download PDF: timeout` (was
85
+ `Failed to download PDF: network error`). No status, not retryable. A
86
+ download whose connection closes before the announced `Content-Length`
87
+ still raises `Failed to download PDF: network error`.
88
+ - A `timeout:` of zero or less makes the download fail at once with the
89
+ timeout message, as it already made every API call time out.
90
+
91
+ ## [0.11.0] - 2026-10-30
92
+
93
+ Conformance with the Poli Page API contract v1.3.0
94
+ ([poli-page/api-contract](https://github.com/poli-page/api-contract)). See
95
+ [MIGRATION.md](MIGRATION.md#from-0100-to-0110).
96
+
97
+ ### Changed
98
+
99
+ - **BREAKING**: the keys inside `data:` and `metadata:` are no longer
100
+ renamed. They are sent exactly as you write them, at every depth: before,
101
+ every key was camelized (`data: { invoice_number: 1 }` reached the template
102
+ as `invoiceNumber`). `DocumentDescriptor#metadata` is returned exactly as
103
+ the API stored it, with its String keys: before, every key was snake_cased
104
+ and symbolized (`{ "customerId" => "c" }` came back as
105
+ `{ customer_id: "c" }`), and two keys such as `someKey` and `some_key`
106
+ collided. The SDK's own names (`project`, `template`, the descriptor's
107
+ readers, the thumbnail options…) keep their Ruby spelling. See
108
+ [MIGRATION.md](MIGRATION.md#payload-keys-are-no-longer-renamed).
109
+ - **BREAKING**: `QUOTA_EXCEEDED` and `OVERAGE_CAP_EXCEEDED` (429) and
110
+ `STORAGE_ACCESS_DENIED` (502) are no longer retried, even with a
111
+ `Retry-After` header, and `retryable?` returns `false` for them (it
112
+ returned `true` for any 429 or 5xx). They last until the monthly reset or
113
+ until the bucket access is restored, so the SDK used to wait up to 30 s per
114
+ retry for nothing. `RATE_LIMIT_EXCEEDED` and every other 429 and 5xx are
115
+ still retried. Code that requeues on `retryable?` stops requeueing these
116
+ three.
117
+ - **BREAKING**: `retryable?` is `false` for every `DOWNLOAD_FAILED`
118
+ (`PoliPage::DownloadError`), whatever the storage status: it was `true`
119
+ with a storage 5xx or 429. The SDK never retried the download itself, and
120
+ still does not.
121
+ - **BREAKING**: the error predicates read `status` and `code`, as the SDK
122
+ specification defines them, instead of the error class: `auth_error?` is
123
+ `status` 401 or 403, `rate_limit_error?` 429, `validation_error?` 400, and
124
+ `network_error?` is `code` `network_error` or `timeout`. For API errors
125
+ only the never-retried codes above change. A `DownloadError` now follows
126
+ the storage's status: a 401 or 403 is an auth error (an expired presigned
127
+ URL gets 403), a 429 a rate-limit error and a 400 a validation error; all
128
+ three were `false` before.
129
+ - **BREAKING**: SDK error messages are the exact texts of the SDK
130
+ specification, the same in every Poli Page SDK:
131
+ - `invalid_options`: `apiKey is required` (was `api_key is required`).
132
+ - `network_error` (`ConnectionError`): `Network request failed` (was the
133
+ HTTP library's exception text, which stays available as `cause`).
134
+ - `timeout` (`TimeoutError`): `Request timed out after <ms>ms`, the
135
+ client's `timeout` in milliseconds (was `request timed out after <s>s`).
136
+ `TimeoutError#timeout` is still in seconds.
137
+ - `DOWNLOAD_FAILED`: `Failed to download PDF: HTTP <status>` (was
138
+ `Failed to download: <status> <reason phrase>`), and
139
+ `Failed to download PDF: network error` when the download gets no
140
+ complete answer (was the HTTP library's text, now `cause`).
141
+ - An error answer whose body is not JSON: `HTTP <status>` (was
142
+ `HTTP <status>: response body was not valid JSON`); the code is still
143
+ `INTERNAL_ERROR` with the real status.
144
+ - `DownloadError.new` takes `status:` and `cause:` and builds its message
145
+ from them; `message:` is optional. `ConnectionError.new`'s `message:` is
146
+ optional too.
147
+ - **BREAKING**: `format:` and `orientation:` are no longer checked before the
148
+ request (SDK specification §5.4: the SDK validates nothing else
149
+ client-side). A value outside `PoliPage::PageFormat::FORMATS` or
150
+ `portrait`/`landscape` is sent as given, and the API answers it with
151
+ `PoliPage::ValidationError` (`400 VALIDATION_ERROR`) instead of the SDK
152
+ raising `PoliPage::InvalidOptionsError` (`invalid_options`, which the
153
+ specification keeps for the constructor). `PageFormat.valid?` and
154
+ `Orientation.valid?` stay for callers who check their own input.
155
+ - `render.document`, `render.pdf`, `render.pdf_stream` and `render_to_file`
156
+ raise `PoliPage::InvalidOptionsError` with code
157
+ `PROJECT_REQUIRED_FOR_DOCUMENT` and message `project is required` before
158
+ any request when `project:` is nil or empty (it was sent, and the API
159
+ answered `400`).
160
+ - `Retry-After` is read as integer seconds or an HTTP-date (IMF-fixdate,
161
+ RFC 850 or asctime) only, clamped to 0–30 s; a date's delay keeps its
162
+ sub-second rest instead of being rounded down to whole seconds. Any other
163
+ value (`1.5`, `-1`, `soon`) falls back to the backoff. `Retry-After-Ms` is
164
+ ignored, as before.
165
+ - The client's `timeout` is one deadline for each whole attempt: opening the
166
+ connection (DNS, TCP, a proxy's `CONNECT`, the TLS handshake), the request
167
+ and the answer, body included. Before, it applied to each phase and each
168
+ socket operation on its own, so a slow connection followed by a slow TLS
169
+ handshake, or an answer that kept sending a byte now and then, could
170
+ outlive it while the error still named `timeout`. The connection phase is
171
+ now bounded by the time left, and a per-attempt watchdog thread closes the
172
+ connection at the deadline.
173
+ - An answer's whole body is read inside its attempt. A 2xx cut mid-body is a
174
+ `network_error` (`Network request failed`, the read error as `cause`), and
175
+ one that stalls past `timeout` a `timeout`; both are retried. A 2xx body
176
+ shorter than its `Content-Length` used to be accepted, then failed as
177
+ `INTERNAL_ERROR` ("response body was not valid JSON"). A render whose 2xx
178
+ answer is cut was already stored by the API, so its retry can store a
179
+ second document.
180
+ - An error answer whose body fails while it is read is handled as a body
181
+ that is not JSON: `INTERNAL_ERROR`, `HTTP <status>`, the real status and
182
+ `x-request-id`, the read error as `cause`, and retried by its status (a 503
183
+ yes, a 400 no). It never takes a code from the bytes received so far.
184
+ - `on_response` fires once the 2xx body is read, and never for a 2xx whose
185
+ body failed.
186
+ - `PoliPage::Error#initialize` takes `cause:`; `Error#cause` returns it even
187
+ when the error is raised outside the `rescue` that caught the original.
188
+ Network errors, timeouts and download failures carry the HTTP library's
189
+ exception there.
190
+ - `documents.preview` returns its HTML as a UTF-8 string, read in the
191
+ `charset` of its `Content-Type` (UTF-8 when there is none). It was binary,
192
+ `ASCII-8BIT`, so any non-ASCII character compared unequal to a UTF-8
193
+ string.
194
+ - A 2xx whose body is not a JSON object (not JSON, empty, absent, or another
195
+ JSON value) still raises `INTERNAL_ERROR`, not retried, but now fires
196
+ `on_error` first, like every error the SDK raises, and keeps the parser's
197
+ error as `cause`. An absent body raised a raw `TypeError` and a JSON array a
198
+ raw `NoMethodError`.
199
+ - `documents.thumbnails` ignores thumbnail fields the SDK does not know,
200
+ instead of raising `ArgumentError`, so the API can add fields.
201
+
202
+ ### Fixed
203
+
204
+ - A GET or DELETE (`documents.get`, `documents.preview`, `documents.delete`)
205
+ and the presigned-URL download are never sent again behind the SDK's
206
+ back. `Net::HTTP` resends an idempotent request once by itself
207
+ (`max_retries`, default 1) after a dropped connection, a read error or a
208
+ read timeout: that attempt was not counted by the SDK's `max_retries` nor
209
+ reported to `on_request`, a timed-out attempt lasted twice the `timeout`
210
+ its error named, and the download, which must not be retried, could be
211
+ fetched twice. The SDK now sets `max_retries = 0` on every connection.
212
+ `Net::HTTP` never resent a POST by itself.
213
+ - A dropped connection (`EOFError`, `IOError`, `Errno::EPIPE`, …) was not
214
+ translated and escaped as the raw Ruby exception, outside the retry loop;
215
+ it is now a retried `network_error`. A dropped or timed-out download is
216
+ `DOWNLOAD_FAILED`.
217
+ - A retry wait is never shorter than its delay: when `sleep` returns early,
218
+ the SDK sleeps again for the rest, on the monotonic clock.
219
+ - An error raised by the caller's `pdf_stream` block (for example
220
+ `Errno::ENOSPC` from writing the chunk) propagates unchanged instead of
221
+ being wrapped.
222
+ - Docs: the retries page no longer claims the API deduplicates on
223
+ `Idempotency-Key`. It does not: the key is stable across the retries of one
224
+ call, and a render retried after a late 5xx, a `timeout` or a
225
+ `network_error` can store a second document. The errors docs no longer
226
+ list `QUOTA_EXCEEDED`, `OVERAGE_CAP_EXCEEDED` and `STORAGE_ACCESS_DENIED`
227
+ as retried.
228
+
229
+ ### Added
230
+
231
+ - Known error code `TEMPLATE_UNSAFE` (400: the template, a partial or an SVG
232
+ asset holds an injection attempt; the message names it; not retried), next
233
+ to `TEMPLATE_ERROR`.
234
+ - `spec/contract` runs every SDK case of the API contract against a local
235
+ mock server over real sockets; CI pins the contract by commit
236
+ (`poli-page/api-contract` action) and Dependabot proposes each new version.
237
+ Run it locally with `POLI_CONTRACT=<path to contract.json> bundle exec rspec`.
238
+
239
+ ## [0.10.0] - 2026-10-27
240
+
241
+ Environments contract: an API key carries its environment (`pp_{env}_…`,
242
+ e.g. `pp_sandbox_…`, `pp_live_…`, `pp_staging_…`) and a render uses the
243
+ project's copy published in that environment. Breaking, with no deprecation
244
+ window.
245
+
246
+ ### Removed
247
+
248
+ - **BREAKING**: **`render.preview`** and its **`PreviewResult`** type. The
249
+ API removed `POST /v1/render/preview` (a call now gets `404`).
250
+ `documents.preview(id)` stays.
251
+ - **BREAKING**: **Inline mode**: the `InlineModeInput` type and raw HTML in
252
+ `template:`. `template:` is always a slug.
253
+ - **BREAKING**: The **`version:`** keyword of `render.document`,
254
+ `render.pdf`, `render.pdf_stream` and `render_to_file`, and with it draft
255
+ rendering by an API key. Passing `version:` now raises `ArgumentError`.
256
+ - **BREAKING**: The **`version`** field of `DocumentDescriptor`.
257
+ - **BREAKING**: From `PoliPage::ErrorCodes`: `VERSION_NOT_FOUND`,
258
+ `INVALID_VERSION_FORMAT`, `VERSION_REQUIRED`, `INVALID_VERSION_FOR_KEY_ENV`,
259
+ `MISSING_PROJECT_OR_TEMPLATE`, `GONE` (the API answers `410 DOCUMENT_GONE`)
260
+ and `PAYMENT_REQUIRED` (payment grace is `403 ORGANIZATION_PAYMENT_GRACE`).
261
+
262
+ ### Changed
263
+
264
+ - **BREAKING**: `ProjectModeInput` is renamed **`RenderInput`** and is the
265
+ only input type.
266
+ - The render body is built from the seven documented fields only
267
+ (`project`, `template`, `data`, `metadata`, `format`, `orientation`,
268
+ `locale`); unset optional fields are omitted. The SDK never sends an
269
+ environment: the API resolves it from the key.
270
+ - `DocumentDescriptor#environment` is any environment name (`sandbox`,
271
+ `live`, `staging`, …), returned unchanged. Response fields the SDK does not
272
+ know are ignored instead of failing the `Data.define` constructor.
273
+ - `documents.thumbnails(id)` takes optional options: `width:` is no longer
274
+ required (API default 400) and `format:` accepts `"webp"` (API default
275
+ `"jpeg"`). With no option set the body is `{}`. `ThumbnailOptions.new`
276
+ takes every field as optional.
277
+ - **BREAKING**: `documents.thumbnails(id)` no longer pre-checks `width`,
278
+ `format`, `quality` or `pages`: an out-of-bounds option raises
279
+ `PoliPage::ValidationError` (the API's `400 VALIDATION_ERROR`) instead of
280
+ `PoliPage::InvalidOptionsError` before the request.
281
+ - `documents.delete` is documented as idempotent: the API answers `204` again
282
+ for an already-deleted document, so a re-delete returns `nil`.
283
+ - README, docs site and `examples/demo.rb` follow the environments contract:
284
+ the quick start and the demo render `getting-started`/`welcome` with a
285
+ `sandbox` key and no version, "Authentication & environments" carries the
286
+ key table and the key regex, and previews point to the playground
287
+ (<https://play.poli.page>). The demo checks a pasted key against the key
288
+ regex only and its last step is `not-found` (`404 TEMPLATE_NOT_FOUND`).
289
+ - The nightly integration workflow no longer passes a template version; it
290
+ renders `getting-started`/`welcome` with the `POLI_PAGE_API_KEY` secret (a
291
+ `pp_sandbox_` key).
292
+ - `MIGRATION.md` has a "From 0.9.x to 0.10.0" entry.
293
+
294
+ ### Added
295
+
296
+ - `PoliPage::ErrorCodes`: `PUBLISH_IN_PROGRESS` (503, retried),
297
+ `ENVIRONMENT_MISMATCH` (400), `PROJECT_NOT_IN_ENVIRONMENT` (404),
298
+ `TEMPLATE_NOT_FOUND` (404), `DOCUMENT_GONE` (410), `ENVIRONMENT_PROTECTED`
299
+ (403), `ORGANIZATION_PAYMENT_GRACE` (403), `EMPTY_DOCUMENT` (400),
300
+ `STORAGE_ACCESS_DENIED` (502), `ORGANIZATION_MIGRATING` (503),
301
+ `PROJECT_NOT_FOUND` (404), `TEMPLATE_ERROR` (400),
302
+ `THUMBNAILS_NOT_AVAILABLE` (403), `RATE_LIMIT_EXCEEDED` (429),
303
+ `RENDER_BODY_TOO_LARGE` (413), `DOCUMENT_TOO_LARGE` (413) and
304
+ `RENDER_TIMEOUT` (504): 31 known API codes in all. The list stays open:
305
+ `Error#code` is whatever string the API returns.
306
+ - A render held by a publish of the same project and environment gets
307
+ `503 PUBLISH_IN_PROGRESS` with `Retry-After`; the existing retry policy
308
+ retries it after that delay.
309
+
13
310
  ## [0.9.1] - 2026-06-22
14
311
 
15
312
  ### Fixed
data/MIGRATION.md CHANGED
@@ -1,14 +1,266 @@
1
1
  # Migration Guide
2
2
 
3
- This file documents breaking changes between major versions of `poli-page`
3
+ This file documents breaking changes between releases of `poli-page`
4
4
  (the Poli Page SDK for Ruby). The SDK follows
5
- [Semantic Versioning](https://semver.org/spec/v2.0.0.html): breaking changes
6
- only ship in major version bumps and always come with an entry here.
5
+ [Semantic Versioning](https://semver.org/spec/v2.0.0.html): while it is on
6
+ 0.x, a breaking change bumps the minor version; from 1.0 on, only a major
7
+ version does. Every breaking release comes with an entry here.
7
8
 
8
- ## 1.0
9
+ ## From 0.11.0 to 0.13.0
9
10
 
10
- The first stable release. No prior versions of `poli-page` were published to
11
- RubyGems — treat `1.0.0` as the starting point.
11
+ The SDK now shares its major.minor with the Poli Page API, so there is no
12
+ 0.12. This release follows the API contract v0.13.0. No method or option is
13
+ renamed; error handling and framework integrations may need a change.
14
+
15
+ ### `to_payload` names its request id `requestId`
16
+
17
+ `Error#to_payload` returns the body a framework integration answers with,
18
+ and every Poli Page SDK now spells it the same way: exactly the keys
19
+ `code:`, `message:`, `status:` and `requestId:`. Its `:request_id` key is
20
+ renamed `:requestId`; the other keys are unchanged.
21
+
22
+ ```ruby
23
+ # 0.11.0
24
+ payload = e.to_payload
25
+ payload[:request_id] # => "req_..."
26
+ render json: payload # answered {"code":…,"request_id":"req_…"}
27
+
28
+ # 0.13.0
29
+ payload = e.to_payload
30
+ payload[:requestId] # => "req_..."
31
+ render json: payload # answers {"code":…,"requestId":"req_…"}
32
+ ```
33
+
34
+ If your integration renamed `request_id` to `requestId` itself, drop the
35
+ rename. Its `:status` is 502 for the new `invalid_response` (below).
36
+
37
+ ### A 2xx whose body is not JSON is `invalid_response`
38
+
39
+ It was `PoliPage::InternalError` (`INTERNAL_ERROR`,
40
+ `response body was not valid JSON: …`). It is now
41
+ `PoliPage::InvalidResponseError`, code `invalid_response`, message
42
+ `Invalid response: HTTP <status> body is not JSON`, with the real 2xx as
43
+ `status` and the answer's request id. It is not retried.
44
+
45
+ ```ruby
46
+ # 0.11.0
47
+ rescue PoliPage::InternalError => e
48
+ # a proxy answered instead of the API, if e.status is a 2xx
49
+
50
+ # 0.13.0
51
+ rescue PoliPage::InvalidResponseError => e
52
+ # a proxy answered instead of the API; e.status is its 2xx
53
+ ```
54
+
55
+ ### `render_to_file` raises `io_error`
56
+
57
+ A file that cannot be written was `PoliPage::InvalidOptionsError` for
58
+ `EACCES`, `ENOSPC`, `EISDIR`, `ENOENT` and `EROFS`, and the raw Ruby
59
+ exception for anything else; it is now always `PoliPage::FileWriteError`,
60
+ code `io_error`, with the message
61
+ `Failed to write PDF: <reason>` and Ruby's error as `cause`. The target is
62
+ left untouched on any failure: it is no longer deleted when the render
63
+ fails.
64
+
65
+ ```ruby
66
+ # 0.13.0
67
+ rescue PoliPage::FileWriteError => e
68
+ # disk full, permissions, a missing mount...
69
+ logger.error(e.cause)
70
+ ```
71
+
72
+ ### The PDF download is bounded by `timeout:`
73
+
74
+ The presigned-URL download now uses the client's `timeout:` (60 s by
75
+ default). `render.pdf` and `download_pdf` bound the whole download, so raise
76
+ `timeout:` if your PDFs take longer than that to download.
77
+ `render.pdf_stream` and `render_to_file` use it as an idle timeout, the wait
78
+ for the first byte of the PDF and each gap between two chunks, and are never cut off for
79
+ their total length. Past the timeout the error is `DOWNLOAD_FAILED` with the
80
+ message `Failed to download PDF: timeout` (was
81
+ `Failed to download PDF: network error`).
82
+
83
+ ## From 0.10.0 to 0.11.0
84
+
85
+ The SDK now follows the Poli Page API contract v1.3.0, the same retry policy,
86
+ error predicates and messages as every other Poli Page SDK. No method or
87
+ option is renamed. Code may need a change where it relied on the renaming
88
+ of `data` / `metadata` keys, and in error handling.
89
+
90
+ ### Payload keys are no longer renamed
91
+
92
+ The SDK specification says `metadata` is sent as is and returned unchanged,
93
+ and `data` is the template's own data. The SDK used to camelize every key of
94
+ both on the way out and snake_case (and symbolize) every key of `metadata` on
95
+ the way back. It no longer touches them; only its own names (`project:`,
96
+ `template:`, `doc.page_count`, …) keep their Ruby spelling.
97
+
98
+ - **`data:`** — write the keys your template uses. If it reads
99
+ `invoiceNumber` and you relied on the conversion, send `invoiceNumber`:
100
+
101
+ ```ruby
102
+ # before (converted to invoiceNumber on the wire)
103
+ client.render.pdf(project: "billing", template: "invoice", data: { invoice_number: "INV-001" })
104
+
105
+ # now (sent as written)
106
+ client.render.pdf(project: "billing", template: "invoice", data: { invoiceNumber: "INV-001" })
107
+ ```
108
+
109
+ - **`metadata:`** — sent as written too; send the keys you want stored.
110
+ Reads use the API's String keys:
111
+
112
+ ```ruby
113
+ # before
114
+ doc.metadata[:customer_id]
115
+
116
+ # now
117
+ doc.metadata["customerId"]
118
+ ```
119
+
120
+ Documents rendered before the upgrade keep the keys they were stored with
121
+ (camelCase, since the old SDK converted them).
122
+
123
+ ### Codes that are no longer retried
124
+
125
+ `QUOTA_EXCEEDED`, `OVERAGE_CAP_EXCEEDED` (429) and `STORAGE_ACCESS_DENIED`
126
+ (502) reach you after the first attempt, and `retryable?` is `false` for
127
+ them. `DOWNLOAD_FAILED` is never `retryable?`, whatever the storage status.
128
+ If you requeued on `retryable?`, these no longer requeue: surface the quota
129
+ and the bucket errors instead.
130
+
131
+ ```ruby
132
+ rescue PoliPage::Error => e
133
+ case e.code
134
+ when "QUOTA_EXCEEDED", "OVERAGE_CAP_EXCEEDED" then show_banner("Monthly quota reached.")
135
+ when "STORAGE_ACCESS_DENIED" then alert_ops("Bucket access revoked.")
136
+ else raise unless e.retryable?
137
+ end
138
+ end
139
+ ```
140
+
141
+ ### Predicates read `status` and `code`
142
+
143
+ `auth_error?` (401/403), `rate_limit_error?` (429), `validation_error?` (400)
144
+ and `network_error?` (`network_error`/`timeout`) no longer look at the class.
145
+ The answer only changes for `PoliPage::DownloadError`: a storage 403 (an
146
+ expired presigned URL) is now `auth_error?`. Rescuing by class works as
147
+ before.
148
+
149
+ ### Messages
150
+
151
+ Matching on an SDK error's message needs updating; prefer `code`:
152
+
153
+ | Error | Before | Now |
154
+ | --- | --- | --- |
155
+ | `InvalidOptionsError` (no key) | `api_key is required` | `apiKey is required` |
156
+ | `ConnectionError` | the HTTP library's text | `Network request failed` (`cause` keeps the original) |
157
+ | `TimeoutError` | `request timed out after 60s` | `Request timed out after 60000ms` |
158
+ | `DownloadError` (status) | `Failed to download: 403 Forbidden` | `Failed to download PDF: HTTP 403` |
159
+ | `DownloadError` (no answer) | the HTTP library's text | `Failed to download PDF: network error` |
160
+ | non-JSON error body | `HTTP 502: response body was not valid JSON` | `HTTP 502` |
161
+
162
+ ### `format:` and `orientation:` are checked by the API
163
+
164
+ An unknown `format:` or `orientation:` is no longer refused by the SDK
165
+ before the request: the API answers it with `400 VALIDATION_ERROR`.
166
+
167
+ ```ruby
168
+ # before
169
+ rescue PoliPage::InvalidOptionsError # "invalid format: ..."
170
+
171
+ # now
172
+ rescue PoliPage::ValidationError => e # e.code == "VALIDATION_ERROR", e.status == 400
173
+ ```
174
+
175
+ To refuse a bad value before any request, check it yourself with
176
+ `PoliPage::PageFormat.valid?(format)` and `PoliPage::Orientation.valid?(orientation)`.
177
+
178
+ ### `project:` nil or empty
179
+
180
+ `render.*` and `render_to_file` raise `InvalidOptionsError` with code
181
+ `PROJECT_REQUIRED_FOR_DOCUMENT` before any request, instead of sending the
182
+ render and getting a `ValidationError` from the API.
183
+
184
+ ## From 0.9.x to 0.10.0
185
+
186
+ 0.10.0 follows the environments contract: an API key belongs to exactly one
187
+ environment of your organization, its text names that environment
188
+ (`pp_{env}_{32 lowercase hex}`: `pp_sandbox_…`, `pp_live_…`,
189
+ `pp_staging_…`), and a render uses the project's copy published in that
190
+ environment. Nobody used the new contract before this release, so every
191
+ removal ships at once with no deprecation window.
192
+
193
+ ### API keys
194
+
195
+ The `pp_test_` and `pp_sa_` prefixes are gone; standard and service keys
196
+ share the one format above. Create a key in the environment you render in:
197
+ a `sandbox` key replaces a test key (watermarked, not counted toward the
198
+ monthly PDF quota, documents expire after 30 days), a `live` key renders
199
+ unwatermarked, counted documents. The SDK passes the key through unchanged
200
+ and never sends an environment.
201
+
202
+ ### `version:` is removed
203
+
204
+ `render.pdf`, `render.pdf_stream`, `render.document` and `render_to_file`
205
+ no longer take `version:`; passing it raises `ArgumentError` (unknown
206
+ keyword) before any request. Publish the project to the key's environment
207
+ instead of pinning a version. `DocumentDescriptor#version` is removed too.
208
+
209
+ ```ruby
210
+ # 0.9.x
211
+ client.render.pdf(project: "billing", template: "invoice", version: "1.0.0", data: data)
212
+
213
+ # 0.10.0
214
+ client.render.pdf(project: "billing", template: "invoice", data: data)
215
+ ```
216
+
217
+ ### `render.preview` and inline HTML are removed
218
+
219
+ `render.preview`, `PreviewResult` and `InlineModeInput` are gone: the API
220
+ renders published templates only. Preview a template or render inline HTML
221
+ in the playground, <https://play.poli.page>. `documents.preview(id)`, the
222
+ stored HTML of a document you already rendered, stays.
223
+
224
+ ### Types
225
+
226
+ | 0.9.x | 0.10.0 |
227
+ | -------------------------------------- | ---------------------------------------- |
228
+ | `PoliPage::ProjectModeInput` | `PoliPage::RenderInput` |
229
+ | `PoliPage::InlineModeInput` | removed |
230
+ | `PoliPage::PreviewResult` | removed |
231
+ | `DocumentDescriptor#version` | removed |
232
+ | `DocumentDescriptor#environment` (`"sandbox"` or `"live"`) | any environment name (`"sandbox"`, `"live"`, `"staging"`, …) |
233
+
234
+ ### Error codes
235
+
236
+ | 0.9.x code | 0.10.0 |
237
+ | -------------------------------------------------------------- | ------------------------------------------------------------- |
238
+ | `GONE` | `DOCUMENT_GONE` (410) |
239
+ | `PAYMENT_REQUIRED` | `ORGANIZATION_PAYMENT_GRACE` (403) |
240
+ | `VERSION_NOT_FOUND`, `INVALID_VERSION_FORMAT`, `VERSION_REQUIRED`, `INVALID_VERSION_FOR_KEY_ENV` | removed (there is no version); a project or template missing from the key's environment answers `PROJECT_NOT_IN_ENVIRONMENT` or `TEMPLATE_NOT_FOUND` (404) |
241
+ | `MISSING_PROJECT_OR_TEMPLATE` | removed |
242
+
243
+ `PoliPage::ErrorCodes` gains `PROJECT_NOT_FOUND`, `PROJECT_NOT_IN_ENVIRONMENT`,
244
+ `TEMPLATE_NOT_FOUND`, `DOCUMENT_GONE`, `ENVIRONMENT_PROTECTED`,
245
+ `PUBLISH_IN_PROGRESS` and the other codes listed in the CHANGELOG. Code that
246
+ matches on `e.code` should switch to the new names; code that rescues by
247
+ class (`PoliPage::GoneError`, `PoliPage::NotFoundError`, …) keeps working.
248
+
249
+ ### Stored documents
250
+
251
+ - `documents.thumbnails(id)` no longer checks its options on the client: an
252
+ out-of-bounds `width`, `format`, `quality` or `pages` raises
253
+ `PoliPage::ValidationError` (the API's `400 VALIDATION_ERROR`) instead of
254
+ `PoliPage::InvalidOptionsError`. Every option is optional, and
255
+ `format: "webp"` is accepted.
256
+ - `documents.delete(id)` is idempotent: deleting an already-deleted document
257
+ returns `nil` instead of raising `PoliPage::GoneError`. A later
258
+ `documents.get(id)` raises `PoliPage::GoneError` with code `DOCUMENT_GONE`.
259
+
260
+ ## 0.9.0
261
+
262
+ The first release, published to RubyGems on 2026-06-18. The surface below is
263
+ 0.9.x's; see [From 0.9.x to 0.10.0](#from-09x-to-0100) for what changed since.
12
264
 
13
265
  ### Surface
14
266