@poli-page/cli 0.1.2 → 0.4.1

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.
Files changed (120) hide show
  1. package/README.md +502 -39
  2. package/dist/api-client.d.ts +162 -3
  3. package/dist/api-client.d.ts.map +1 -1
  4. package/dist/api-client.js +338 -36
  5. package/dist/api-client.js.map +1 -1
  6. package/dist/auth.d.ts +11 -0
  7. package/dist/auth.d.ts.map +1 -0
  8. package/dist/auth.js +27 -0
  9. package/dist/auth.js.map +1 -0
  10. package/dist/cloud-context.d.ts +18 -0
  11. package/dist/cloud-context.d.ts.map +1 -0
  12. package/dist/cloud-context.js +51 -0
  13. package/dist/cloud-context.js.map +1 -0
  14. package/dist/commands/auth.d.ts +38 -15
  15. package/dist/commands/auth.d.ts.map +1 -1
  16. package/dist/commands/auth.js +99 -46
  17. package/dist/commands/auth.js.map +1 -1
  18. package/dist/commands/checkout.d.ts +13 -0
  19. package/dist/commands/checkout.d.ts.map +1 -0
  20. package/dist/commands/checkout.js +93 -0
  21. package/dist/commands/checkout.js.map +1 -0
  22. package/dist/commands/documents/delete.d.ts +14 -0
  23. package/dist/commands/documents/delete.d.ts.map +1 -0
  24. package/dist/commands/documents/delete.js +61 -0
  25. package/dist/commands/documents/delete.js.map +1 -0
  26. package/dist/commands/documents/get.d.ts +10 -0
  27. package/dist/commands/documents/get.d.ts.map +1 -0
  28. package/dist/commands/documents/get.js +81 -0
  29. package/dist/commands/documents/get.js.map +1 -0
  30. package/dist/commands/documents/index.d.ts +3 -0
  31. package/dist/commands/documents/index.d.ts.map +1 -0
  32. package/dist/commands/documents/index.js +14 -0
  33. package/dist/commands/documents/index.js.map +1 -0
  34. package/dist/commands/documents/preview.d.ts +19 -0
  35. package/dist/commands/documents/preview.d.ts.map +1 -0
  36. package/dist/commands/documents/preview.js +73 -0
  37. package/dist/commands/documents/preview.js.map +1 -0
  38. package/dist/commands/documents/thumbnails.d.ts +22 -0
  39. package/dist/commands/documents/thumbnails.d.ts.map +1 -0
  40. package/dist/commands/documents/thumbnails.js +108 -0
  41. package/dist/commands/documents/thumbnails.js.map +1 -0
  42. package/dist/commands/init.d.ts +8 -0
  43. package/dist/commands/init.d.ts.map +1 -1
  44. package/dist/commands/init.js +38 -4
  45. package/dist/commands/init.js.map +1 -1
  46. package/dist/commands/link.d.ts.map +1 -1
  47. package/dist/commands/link.js +33 -33
  48. package/dist/commands/link.js.map +1 -1
  49. package/dist/commands/new.d.ts +7 -2
  50. package/dist/commands/new.d.ts.map +1 -1
  51. package/dist/commands/new.js +47 -77
  52. package/dist/commands/new.js.map +1 -1
  53. package/dist/commands/push.d.ts +14 -0
  54. package/dist/commands/push.d.ts.map +1 -0
  55. package/dist/commands/push.js +73 -0
  56. package/dist/commands/push.js.map +1 -0
  57. package/dist/commands/render.d.ts +18 -0
  58. package/dist/commands/render.d.ts.map +1 -0
  59. package/dist/commands/render.js +83 -0
  60. package/dist/commands/render.js.map +1 -0
  61. package/dist/commands/thumbnail.d.ts +2 -22
  62. package/dist/commands/thumbnail.d.ts.map +1 -1
  63. package/dist/commands/thumbnail.js +39 -98
  64. package/dist/commands/thumbnail.js.map +1 -1
  65. package/dist/commands/version-state.d.ts +35 -0
  66. package/dist/commands/version-state.d.ts.map +1 -0
  67. package/dist/commands/version-state.js +153 -0
  68. package/dist/commands/version-state.js.map +1 -0
  69. package/dist/commands/versions.d.ts +1 -0
  70. package/dist/commands/versions.d.ts.map +1 -1
  71. package/dist/commands/versions.js +26 -29
  72. package/dist/commands/versions.js.map +1 -1
  73. package/dist/commands/watch.d.ts +26 -0
  74. package/dist/commands/watch.d.ts.map +1 -0
  75. package/dist/commands/watch.js +177 -0
  76. package/dist/commands/watch.js.map +1 -0
  77. package/dist/exit-codes.d.ts +32 -0
  78. package/dist/exit-codes.d.ts.map +1 -0
  79. package/dist/exit-codes.js +77 -0
  80. package/dist/exit-codes.js.map +1 -0
  81. package/dist/file-watcher.d.ts +17 -0
  82. package/dist/file-watcher.d.ts.map +1 -0
  83. package/dist/file-watcher.js +74 -0
  84. package/dist/file-watcher.js.map +1 -0
  85. package/dist/format-resolver.d.ts.map +1 -1
  86. package/dist/format-resolver.js +4 -0
  87. package/dist/format-resolver.js.map +1 -1
  88. package/dist/index.js +0 -0
  89. package/dist/manifest.d.ts +3 -30
  90. package/dist/manifest.d.ts.map +1 -1
  91. package/dist/manifest.js +4 -1
  92. package/dist/manifest.js.map +1 -1
  93. package/dist/manifest.schema.d.ts +44 -0
  94. package/dist/manifest.schema.d.ts.map +1 -0
  95. package/dist/manifest.schema.js +88 -0
  96. package/dist/manifest.schema.js.map +1 -0
  97. package/dist/program.d.ts.map +1 -1
  98. package/dist/program.js +11 -3
  99. package/dist/program.js.map +1 -1
  100. package/dist/sync-engine.d.ts +16 -0
  101. package/dist/sync-engine.d.ts.map +1 -0
  102. package/dist/sync-engine.js +65 -0
  103. package/dist/sync-engine.js.map +1 -0
  104. package/dist/template-importer.d.ts +69 -0
  105. package/dist/template-importer.d.ts.map +1 -0
  106. package/dist/template-importer.js +206 -0
  107. package/dist/template-importer.js.map +1 -0
  108. package/package.json +63 -63
  109. package/templates/blank/blank.html +0 -6
  110. package/templates/blank/blank.json +0 -6
  111. package/templates/header-main-footer/header-main-footer.html +0 -16
  112. package/templates/header-main-footer/header-main-footer.json +0 -6
  113. package/templates/header-main-footer-sidebar/header-main-footer-sidebar.html +0 -23
  114. package/templates/header-main-footer-sidebar/header-main-footer-sidebar.json +0 -6
  115. package/templates/header-main-sidebar-footer/header-main-sidebar-footer.html +0 -23
  116. package/templates/header-main-sidebar-footer/header-main-sidebar-footer.json +0 -6
  117. package/templates/header-sidebar-main-footer/header-sidebar-main-footer.html +0 -23
  118. package/templates/header-sidebar-main-footer/header-sidebar-main-footer.json +0 -6
  119. package/templates/sidebar-header-main-footer/sidebar-header-main-footer.html +0 -23
  120. package/templates/sidebar-header-main-footer/sidebar-header-main-footer.json +0 -6
package/README.md CHANGED
@@ -1,9 +1,32 @@
1
1
  # Poli Page CLI
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@poli-page/cli.svg)](https://www.npmjs.com/package/@poli-page/cli)
4
+ [![CI](https://github.com/poli-page/cli/actions/workflows/ci.yml/badge.svg)](https://github.com/poli-page/cli/actions/workflows/ci.yml)
4
5
  [![license](https://img.shields.io/npm/l/@poli-page/cli.svg)](LICENSE)
5
6
 
6
- Command-line tool for [Poli Page](https://poli.page) — scaffold projects, create templates, and render PDFs from the terminal.
7
+ Command-line tool for [Poli Page](https://poli.page) — scaffold projects, manage cloud-hosted templates, render PDFs, and operate document storage from your terminal or your CI pipeline.
8
+
9
+ ---
10
+
11
+ ## Table of contents
12
+
13
+ - [Install](#install)
14
+ - [Quickstart](#quickstart)
15
+ - [Authentication](#authentication)
16
+ - [Commands](#commands)
17
+ - [Project lifecycle](#project-lifecycle)
18
+ - [Authentication commands](#authentication-commands)
19
+ - [Cloud sync](#cloud-sync)
20
+ - [Versioning](#versioning)
21
+ - [Render](#render)
22
+ - [Documents](#documents)
23
+ - [Manifest format](#manifest-format)
24
+ - [Configuration](#configuration)
25
+ - [Exit codes](#exit-codes)
26
+ - [CI / CD](#ci--cd)
27
+ - [Troubleshooting](#troubleshooting)
28
+
29
+ ---
7
30
 
8
31
  ## Install
9
32
 
@@ -11,72 +34,512 @@ Command-line tool for [Poli Page](https://poli.page) — scaffold projects, crea
11
34
  npm install -g @poli-page/cli
12
35
  # or
13
36
  pnpm add -g @poli-page/cli
37
+ # or
38
+ bun add -g @poli-page/cli
14
39
  ```
15
40
 
16
- Requires Node.js 22 or later.
41
+ **Requirements**: Node.js 22.13 or later.
17
42
 
18
- ## Quick start
43
+ Verify the install:
19
44
 
20
45
  ```bash
21
- # Authenticate (opens browser for device flow)
46
+ poli --version
47
+ poli --help
48
+ ```
49
+
50
+ ---
51
+
52
+ ## Quickstart
53
+
54
+ ```bash
55
+ # 1. Authenticate (opens your browser for the device flow)
22
56
  poli login
23
57
 
24
- # Scaffold a new project
58
+ # 2. Scaffold a new project
25
59
  poli init my-invoices
26
60
  cd my-invoices
27
61
 
28
- # Create a template from a layout model
29
- poli new invoice --model header-main-footer
62
+ # 3. Add a template from the Poli Page starter collection
63
+ poli new invoice --from-template showcase/invoice
30
64
 
31
- # Link the project to your Poli Page organization
65
+ # 4. Link the project to your organization (writes the cloud manifest)
32
66
  poli link
33
67
 
34
- # Render a PDF
68
+ # 5. Render a PDF using the local template against the cloud engine
35
69
  poli render invoice -o invoice.pdf
70
+
71
+ # 6. Push your work as a SANDBOX version
72
+ poli push --message "Initial draft"
73
+
74
+ # 7. Promote to LIVE when ready
75
+ poli versions list
76
+ poli promote 1.0.0
36
77
  ```
37
78
 
79
+ To iterate on a template with live feedback against the cloud:
80
+
81
+ ```bash
82
+ poli watch
83
+ # edit your template files; each save syncs to the cloud draft within 2 seconds
84
+ ```
85
+
86
+ ---
87
+
88
+ ## Authentication
89
+
90
+ The CLI supports two authentication modes. Both flow through the same internal resolver.
91
+
92
+ ### Interactive (developers)
93
+
94
+ ```bash
95
+ poli login # device authorization flow — opens your browser
96
+ poli whoami # show the current session and active org
97
+ poli logout # clear ~/.polipage/credentials.json
98
+ ```
99
+
100
+ After `poli login`, the session token is stored at `~/.polipage/credentials.json` and used automatically by every subsequent command.
101
+
102
+ ### Programmatic (CI / CD / scripts)
103
+
104
+ Set the `POLI_PAGE_API_KEY` environment variable. The value must start with `pp_`:
105
+
106
+ | Prefix | Use case |
107
+ | ----------- | ----------------------------------------------------------------- |
108
+ | `pp_test_*` | Sandbox renders (unmetered, no quota) |
109
+ | `pp_live_*` | Live renders (counts in the monthly quota, billable) |
110
+ | `pp_sa_*` | Service account — recommended for CI; rotates without breaking dev|
111
+
112
+ ```bash
113
+ export POLI_PAGE_API_KEY=pp_sa_live_xxx
114
+ poli render invoice -o invoice.pdf
115
+ poli push --message "Release v1.0.5"
116
+ ```
117
+
118
+ ### Precedence
119
+
120
+ When **both** `~/.polipage/credentials.json` (a session) and `POLI_PAGE_API_KEY` are set, **the session wins**. `poli login` does not refuse if the env var is set — it shows an info-message and proceeds, after which the new session takes precedence.
121
+
122
+ This means a developer can keep `POLI_PAGE_API_KEY` set in `.zshrc` for occasional CI-style commands without it interfering with their interactive workflow.
123
+
124
+ ---
125
+
38
126
  ## Commands
39
127
 
40
- | Command | Description |
41
- | -------------------------------- | ----------------------------------------- |
42
- | `poli init <name>` | Scaffold a new project |
43
- | `poli new <name>` | Create a template from a layout model |
44
- | `poli render <name>` | Generate a PDF from a template |
45
- | `poli thumbnail <name>` | Generate thumbnail images from a template |
46
- | `poli login` | Authenticate via device flow |
47
- | `poli logout` | Clear local credentials |
48
- | `poli whoami` | Show current user and organizations |
49
- | `poli link` | Link the project to a cloud organization |
50
- | `poli unlink` | Remove the cloud association |
51
- | `poli publish` | Sync and publish a new version |
52
- | `poli versions list` | List published versions |
53
- | `poli versions download <ver>` | Download a published version |
54
-
55
- Run `poli <command> --help` for full options.
128
+ 24 commands grouped by category.
129
+
130
+ ### Project lifecycle
131
+
132
+ #### `poli init <name>`
133
+
134
+ Scaffold a new Poli Page project. Creates the directory, the `poli-page.json` manifest, `templates/`, `partials/`, `assets/{fonts,images}/`, `tailwind.css`, and `.gitignore`.
135
+
136
+ ```bash
137
+ poli init my-invoices
138
+ poli init . --with-template showcase/invoice # init in cwd + import a starter
139
+ poli init my-app --with-template showcase/quote --template-name custom-quote
140
+ poli init my-app --source github:my-org/my-templates --with-template internal/cover
141
+ ```
142
+
143
+ Flags:
144
+
145
+ - `--with-template <ref>` — pre-install a starter template, format `<collection>/<template>`
146
+ - `--template-name <name>` — override the imported template's destination name
147
+ - `--source <repo>` — source repo, format `github:<owner>/<repo>` (default: `github:poli-page/templates`)
148
+ - `--no-cache` — bypass the 24-hour template cache
149
+
150
+ #### `poli new <name>`
151
+
152
+ Create a new template inside an existing project from a remote starter.
153
+
154
+ ```bash
155
+ poli new invoice --from-template showcase/invoice
156
+ poli new quote --from-template structures/blank
157
+ ```
158
+
159
+ Flags:
160
+
161
+ - `--from-template <ref>` (required) — collection/template
162
+ - `--source <repo>` — override the source
163
+ - `--no-cache` — bypass cache
164
+
165
+ ### Authentication commands
166
+
167
+ #### `poli login`
168
+
169
+ Opens your browser for the device authorization flow and stores the session token at `~/.polipage/credentials.json`.
170
+
171
+ #### `poli logout`
172
+
173
+ Clears the local credentials file.
174
+
175
+ #### `poli whoami`
176
+
177
+ Displays the active identity and organization. Calls `GET /v1/me` over hybrid auth (session or API key).
178
+
179
+ ```bash
180
+ # Inside a linked project (session)
181
+ $ poli whoami
182
+ xavier@example.com @ acme (session)
183
+
184
+ # Anywhere — fallback when no project is linked, lists the orgs the session can see
185
+ $ poli whoami
186
+ xavier@example.com (session, 2 organizations: acme, demo-corp)
187
+ Run `poli link` inside a project to bind it to an organization.
188
+
189
+ # Programmatic (API key)
190
+ $ POLI_PAGE_API_KEY=pp_live_xxx poli whoami
191
+ pp_live_xxx…abcd @ acme (api-key, environment=live)
192
+ ```
193
+
194
+ Flag: `--json` to dump the raw `/v1/me` payload (or, in `session-no-org` mode, `{ mode, user, orgs }`).
195
+
196
+ ### Cloud sync
197
+
198
+ #### `poli link`
199
+
200
+ Interactively select an organization, create the cloud project, and write the `cloud:` section into `poli-page.json` with the four fields the API needs (`orgSlug`, `orgId`, `projectSlug`, `projectId`). No API key is stored in the manifest — the file is safe to commit.
201
+
202
+ #### `poli unlink`
203
+
204
+ Removes the `cloud:` section from `poli-page.json`. Local files are preserved.
205
+
206
+ #### `poli watch`
207
+
208
+ Auto-syncs the local project to the cloud draft on every save. Debounce 2s. Each batch sends only the SHA-256 delta via `PATCH /api/organizations/:orgId/projects/:projectId/files`.
209
+
210
+ ```bash
211
+ poli watch
212
+ ```
213
+
214
+ Resilience built in:
215
+
216
+ - Network errors → exponential backoff (1s, 2s, 4s, 8s, 16s, 30s capped, reset on success)
217
+ - `503 ORGANIZATION_MIGRATING` → 5-second retry
218
+ - `403 SYSTEM_PROJECT_LOCKED` (the `getting-started` system project) → friendly error + exit
219
+ - Other API errors → logged, watch continues, next save retries
220
+
221
+ Requires a TTY. Refused with exit `2` when run in a non-interactive context.
222
+
223
+ #### `poli checkout <version>`
224
+
225
+ Restore a specific published version locally. **Destructive** — overwrites any local file with the same path. Always commit your work before running.
226
+
227
+ ```bash
228
+ poli checkout 1.0.5 # exact semver only
229
+ ```
230
+
231
+ `latest` and partial semver (`1.0`, `1`) are rejected with a friendly hint.
232
+
233
+ ### Versioning
234
+
235
+ #### `poli push`
236
+
237
+ Sync the current local draft and create a new SANDBOX version.
238
+
239
+ ```bash
240
+ poli push --message "Tweaked invoice header"
241
+ poli push --major --message "BREAKING: new schema"
242
+ poli push --minor
243
+ poli push --patch # default
244
+ ```
245
+
246
+ #### `poli versions list` (alias `ls`)
247
+
248
+ Display all versions of the linked project with their state badges.
249
+
250
+ ```
251
+ STATE VERSION PUSHED MESSAGE
252
+ LIVE 2.0.0 3 days ago Major redesign
253
+ LIVE 1.0.5 1 week ago Hotfix URSSAF
254
+ SANDBOX 1.1.0 2 hours ago
255
+ DEPRECATED 1.0.2 3 weeks ago
256
+ ```
257
+
258
+ #### `poli promote <version>`
259
+
260
+ Move a SANDBOX version to LIVE. Confirmation prompt unless `--yes`.
261
+
262
+ #### `poli unpromote <version>`
263
+
264
+ Move a LIVE version back to SANDBOX. Shows a usage preview (calls in the last 24h, the next-latest LIVE) before confirming.
265
+
266
+ ```bash
267
+ poli unpromote 1.0.5
268
+ poli unpromote 1.0.5 --force # allow unpromoting the last LIVE version
269
+ ```
270
+
271
+ #### `poli versions deprecate <version>`
272
+
273
+ Mark a SANDBOX version as DEPRECATED.
274
+
275
+ #### `poli versions un-deprecate <version>`
276
+
277
+ Move a DEPRECATED version back to SANDBOX.
278
+
279
+ #### `poli versions download <version> [-o <dir>]`
280
+
281
+ Download a published version's content to a local directory (read-only inspection or hotfix base).
282
+
283
+ ### Render
284
+
285
+ #### `poli render <name>`
286
+
287
+ Generate a PDF from a local template against the cloud engine.
288
+
289
+ ```bash
290
+ poli render invoice # default: draft
291
+ poli render invoice --version 1.0.5 # exact semver pin
292
+ poli render invoice --version draft --data ./mock.json # custom data
293
+ poli render invoice -o ./out/invoice.pdf
294
+ ```
295
+
296
+ Flags:
297
+
298
+ - `--version <draft|X.Y.Z>` — exact semver only (`latest` is rejected)
299
+ - `--data <file>` — JSON data overrides the template's mock
300
+ - `-o <file>` — output path
301
+
302
+ The CLI surfaces the resolved environment in the success line:
303
+
304
+ ```
305
+ ✓ Rendered invoice v1.0.5 (live, billed)
306
+ ✓ Rendered invoice (draft, sandbox)
307
+ ```
308
+
309
+ ### Documents
310
+
311
+ Documents are the cloud-stored output of `render document` calls (made via the SDK or directly via the API). The CLI lets you inspect, delete, and re-derive thumbnails or preview HTML from them.
312
+
313
+ There is intentionally **no `poli documents list`** — your application is responsible for tracking the `documentId` values it cares about.
314
+
315
+ #### `poli documents get <id>`
316
+
317
+ Returns a JSON descriptor with metadata + a 15-minute presigned PDF URL. The CLI does not download the PDF — `curl` the URL or hand it to the browser yourself.
318
+
319
+ ```bash
320
+ poli documents get doc_abc123
321
+ poli documents get doc_abc123 --json
322
+ ```
323
+
324
+ #### `poli documents delete <id>`
325
+
326
+ Soft-deletes a document. Idempotent: returns success if already deleted. Confirmation unless `--yes`.
327
+
328
+ #### `poli documents thumbnails <id>`
329
+
330
+ Regenerate page thumbnails from the document's stored canonical HTML. Counts as one billable render in the monthly quota when the auth env is `live`. Free tier returns `403 THUMBNAILS_NOT_AVAILABLE`.
331
+
332
+ ```bash
333
+ poli documents thumbnails doc_abc123 --width 400
334
+ poli documents thumbnails doc_abc123 --pages 1,3 --format jpeg --quality 85
335
+ poli documents thumbnails doc_abc123 -o ./out
336
+ ```
337
+
338
+ Flags: `-w/--width`, `-f/--format png|jpeg`, `-q/--quality`, `--pages 1,3`, `-o/--output`, `--json`.
339
+
340
+ #### `poli documents preview <id>`
341
+
342
+ Fetch the stored canonical HTML re-wrapped as preview-mode (free, no quota cost). Default writes the file at `./output/documents/<id>.preview.html` and opens the browser.
343
+
344
+ ```bash
345
+ poli documents preview doc_abc123
346
+ poli documents preview doc_abc123 --no-open
347
+ poli documents preview doc_abc123 -o ./preview.html
348
+ ```
349
+
350
+ #### `poli thumbnail <documentId>` (alias)
351
+
352
+ Light alias for `poli documents thumbnails`. Accepts the same flags.
353
+
354
+ ```bash
355
+ poli thumbnail doc_abc123 --width 200 --format png
356
+ ```
357
+
358
+ Without arguments, prints a friendly hint pointing at `poli render document` to produce a `documentId` first.
359
+
360
+ ---
361
+
362
+ ## Manifest format
363
+
364
+ `poli-page.json` is the per-project manifest. Committed to git (no secrets).
365
+
366
+ ```jsonc
367
+ {
368
+ "project": {
369
+ "name": "my-invoices",
370
+ "version": "1.0.0"
371
+ },
372
+ "fonts": [
373
+ {
374
+ "family": "Inter",
375
+ "src": "assets/fonts/Inter.woff2",
376
+ "weight": 400
377
+ }
378
+ ],
379
+ "templates": [
380
+ {
381
+ "name": "invoice",
382
+ "template": "templates/invoice/invoice.html",
383
+ "mock": "templates/invoice/invoice.json",
384
+ "format": "A4",
385
+ "orientation": "portrait"
386
+ }
387
+ ],
388
+ "cloud": {
389
+ "orgSlug": "acme",
390
+ "orgId": "0e89d99e-1516-4b48-baa1-f49e660ad1c1",
391
+ "projectSlug": "invoices",
392
+ "projectId": "8274f64d-4ea2-4f96-b596-5727a7b17268"
393
+ }
394
+ }
395
+ ```
396
+
397
+ The `cloud:` block is written by `poli link`, removed by `poli unlink`. **No API keys here** — the credentials file (or `POLI_PAGE_API_KEY`) carries the secret.
398
+
399
+ ---
56
400
 
57
401
  ## Configuration
58
402
 
59
- | Option | Description |
60
- | ------------------ | -------------------------------------------------------------------- |
61
- | `--api-url <url>` | Override the API base URL (precedence over `POLI_API_URL`). |
62
- | `-v, --version` | Display the CLI version. |
403
+ ### Environment variables
404
+
405
+ | Variable | Effect |
406
+ | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
407
+ | `POLI_PAGE_API_KEY` | Single env var for any API key in CI/CD. Accepts `pp_test_*`, `pp_live_*`, or `pp_sa_*`. Must start with `pp_`. **Precedence**: when a credentials file is also present, the session wins. |
408
+ | `POLI_API_URL` | Override the API base URL (precedence: `--api-url` flag → `POLI_API_URL` → `poli-page.json` `cloud.apiUrl` → `~/.polipage/credentials.json` `apiUrl` → default `https://api.poli.page`). |
409
+ | `POLI_PAGE_ENV` | Default render env (`sandbox` or `live`) when commands accept an env hint. |
410
+ | `NO_COLOR` | Disable ANSI colors (Unix standard). |
411
+ | `CI` | Auto-detected; equivalent to a global `--yes`. |
412
+
413
+ ### Common flags
414
+
415
+ - `--api-url <url>` — override the API base URL for one invocation
416
+ - `--json` — structured JSON output (where supported)
417
+ - `-y` / `--yes` — skip confirmation prompts
418
+ - `-h` / `--help` — show help for any command or sub-command
419
+ - `-v` / `--version` — print the CLI version and exit
420
+
421
+ ---
422
+
423
+ ## Exit codes
424
+
425
+ | Code | Meaning |
426
+ | ---- | ------------------------------------------------------------------------------------------------------ |
427
+ | `0` | Success (or no-op, e.g. `promote` when nothing changes) |
428
+ | `1` | Recoverable inconsistency (already logged in, already linked, version already live) |
429
+ | `2` | Invalid usage (bad args, template not found, version not found, non-TTY context where TTY is required) |
430
+ | `3` | Network / API error (timeout, 5xx, unspecified 4xx) |
431
+ | `4` | Not authenticated — run `poli login` or set `POLI_PAGE_API_KEY` |
432
+ | `5` | Not authorized (insufficient role, `THUMBNAILS_NOT_AVAILABLE`, system project locked) |
433
+ | `6` | Invalid local state (no project, project not linked, empty folder where required) |
434
+
435
+ These map to the centralised `ExitCode` constants in `src/exit-codes.ts`. Every handler routes errors through `errorToExitCode(err)`.
436
+
437
+ ---
438
+
439
+ ## CI / CD
440
+
441
+ ### GitHub Actions
442
+
443
+ ```yaml
444
+ # .github/workflows/render.yml
445
+ name: Render PDFs
446
+
447
+ on: workflow_dispatch
448
+
449
+ jobs:
450
+ render:
451
+ runs-on: ubuntu-latest
452
+ env:
453
+ POLI_PAGE_API_KEY: ${{ secrets.POLI_PAGE_API_KEY }}
454
+ steps:
455
+ - uses: actions/checkout@v4
456
+ - uses: actions/setup-node@v4
457
+ with:
458
+ node-version: '22'
459
+ - run: npm install -g @poli-page/cli
460
+ - run: poli render invoice -o ./artifacts/invoice.pdf --version 1.0.5
461
+ - uses: actions/upload-artifact@v4
462
+ with:
463
+ name: invoice-pdf
464
+ path: ./artifacts/invoice.pdf
465
+ ```
466
+
467
+ Recommended: use a **service account key** (`pp_sa_live_*`) so rotating it does not log out any developer.
468
+
469
+ ### GitLab CI
63
470
 
64
- Environment variables:
471
+ ```yaml
472
+ render:
473
+ image: node:22-alpine
474
+ variables:
475
+ POLI_PAGE_API_KEY: $POLI_PAGE_API_KEY
476
+ script:
477
+ - npm install -g @poli-page/cli
478
+ - poli render invoice -o invoice.pdf --version 1.0.5
479
+ artifacts:
480
+ paths:
481
+ - invoice.pdf
482
+ ```
483
+
484
+ ### Vercel / Netlify build hook
485
+
486
+ ```bash
487
+ # In a build script
488
+ npm install -g @poli-page/cli
489
+ POLI_PAGE_API_KEY=pp_sa_live_xxx poli render homepage-pdf -o ./public/welcome.pdf
490
+ ```
491
+
492
+ Service accounts have a **fixed role and environment** at creation. The CLI does not try to switch them — the API enforces the permissions.
493
+
494
+ ---
495
+
496
+ ## Troubleshooting
497
+
498
+ ### `Not logged in. Run \`poli login\` or set POLI_PAGE_API_KEY.`
499
+
500
+ Either run `poli login` interactively, or export `POLI_PAGE_API_KEY` for CI use. Exit code `4`.
501
+
502
+ ### `POLI_PAGE_API_KEY must start with \`pp_\`...`
65
503
 
66
- | Variable | Default | Description |
67
- | --------------- | ------------------------ | -------------- |
68
- | `POLI_API_URL` | `https://api.poli.page` | API base URL |
504
+ You set the variable but its value does not match the `pp_*` prefix. Rotate the key from the dashboard's API keys page. Exit code `4`.
69
505
 
70
- The API URL is resolved in this order: `--api-url` flag → `POLI_API_URL` env var → `poli-page.json` (`cloud.apiUrl`) → `~/.polipage/credentials.json` (`apiUrl`) → default.
506
+ ### `This folder isn't linked to a cloud project. Run \`poli link\` first.`
71
507
 
72
- ## Credentials
508
+ You're in session mode and the local manifest has no `cloud:` block. Either run `poli link`, or switch to api-key mode with `POLI_PAGE_API_KEY=pp_*` (which carries the org context implicitly). Exit code `6`.
73
509
 
74
- Credentials are stored in `~/.polipage/credentials.json`. The file holds the session token and per-organization API keys. The file is never committed.
510
+ ### `\`latest\` was retired. Run \`poli versions list\` and pin an exact semver...`
75
511
 
76
- ## Documentation
512
+ The CLI now requires an exact `X.Y.Z` semver when pinning a version. List the published versions with `poli versions list` and pick one. Exit code `2`.
77
513
 
78
- Full documentation: [docs.poli.page](https://docs.poli.page)
514
+ ### `403 THUMBNAILS_NOT_AVAILABLE`
515
+
516
+ Thumbnails (whether via `poli documents thumbnails` or `poli thumbnail`) are a paid-tier feature. Upgrade to Starter from the dashboard. Exit code `5`.
517
+
518
+ ### `429 OVERAGE_CAP_EXCEEDED`
519
+
520
+ Your org has crossed the monthly cap on `live` PDF renders (counted across `render`, `render document`, and `documents thumbnails` calls). Wait until the next billing period or raise the cap from your dashboard. Exit code `3`.
521
+
522
+ ### `503 ORGANIZATION_MIGRATING`
523
+
524
+ Your org is being migrated to a new tier. `poli watch` retries automatically after 5s. Other commands surface the error — retry by hand once the migration completes (typically under a minute).
525
+
526
+ ### `poli watch` doesn't fire on save
527
+
528
+ Make sure you're not editing inside an ignored directory. Default ignores: `node_modules/`, `.git/`, `output/`, `dist/`, `*.log`, `.DS_Store`. The watcher uses `chokidar` v5; if your editor saves via "atomic write + rename" (some Vim setups), the rename event fires within the debounce window and triggers a sync.
529
+
530
+ ### CI pipeline rejected with exit `5` on `poli promote`
531
+
532
+ Service-account `developer` keys cannot promote. Either use an `admin` SA, or run `poli promote` from a developer's interactive session. Service-account roles are fixed at creation.
533
+
534
+ ---
79
535
 
80
536
  ## License
81
537
 
82
- [MIT](LICENSE) © Poli Page
538
+ MIT — see [LICENSE](LICENSE).
539
+
540
+ ## Links
541
+
542
+ - [Documentation](https://docs.poli.page)
543
+ - [Dashboard](https://app.poli.page)
544
+ - [Issue tracker](https://github.com/poli-page/cli/issues)
545
+ - [Changelog](CHANGELOG.md)