@poli-page/cli 0.9.0 → 0.10.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.
Files changed (98) hide show
  1. package/README.md +200 -113
  2. package/dist/api-client.d.ts +100 -96
  3. package/dist/api-client.d.ts.map +1 -1
  4. package/dist/api-client.js +45 -107
  5. package/dist/api-client.js.map +1 -1
  6. package/dist/auth.d.ts +10 -4
  7. package/dist/auth.d.ts.map +1 -1
  8. package/dist/auth.js +6 -3
  9. package/dist/auth.js.map +1 -1
  10. package/dist/cloud-context.d.ts +0 -2
  11. package/dist/cloud-context.d.ts.map +1 -1
  12. package/dist/cloud-context.js +2 -25
  13. package/dist/cloud-context.js.map +1 -1
  14. package/dist/commands/auth.d.ts.map +1 -1
  15. package/dist/commands/auth.js +5 -2
  16. package/dist/commands/auth.js.map +1 -1
  17. package/dist/commands/dev.d.ts +3 -6
  18. package/dist/commands/dev.d.ts.map +1 -1
  19. package/dist/commands/dev.js +24 -83
  20. package/dist/commands/dev.js.map +1 -1
  21. package/dist/commands/documents/get.d.ts +4 -0
  22. package/dist/commands/documents/get.d.ts.map +1 -1
  23. package/dist/commands/documents/get.js +3 -5
  24. package/dist/commands/documents/get.js.map +1 -1
  25. package/dist/commands/env.d.ts +3 -0
  26. package/dist/commands/env.d.ts.map +1 -0
  27. package/dist/commands/env.js +227 -0
  28. package/dist/commands/env.js.map +1 -0
  29. package/dist/commands/init.d.ts.map +1 -1
  30. package/dist/commands/init.js +3 -12
  31. package/dist/commands/init.js.map +1 -1
  32. package/dist/commands/link.d.ts.map +1 -1
  33. package/dist/commands/link.js +4 -23
  34. package/dist/commands/link.js.map +1 -1
  35. package/dist/commands/publish.d.ts +17 -0
  36. package/dist/commands/publish.d.ts.map +1 -0
  37. package/dist/commands/publish.js +163 -0
  38. package/dist/commands/publish.js.map +1 -0
  39. package/dist/commands/render.d.ts +27 -11
  40. package/dist/commands/render.d.ts.map +1 -1
  41. package/dist/commands/render.js +128 -60
  42. package/dist/commands/render.js.map +1 -1
  43. package/dist/dev-page.d.ts +5 -5
  44. package/dist/dev-page.d.ts.map +1 -1
  45. package/dist/dev-page.js +12 -68
  46. package/dist/dev-page.js.map +1 -1
  47. package/dist/environment-name.d.ts +8 -0
  48. package/dist/environment-name.d.ts.map +1 -0
  49. package/dist/environment-name.js +21 -0
  50. package/dist/environment-name.js.map +1 -0
  51. package/dist/exit-codes.d.ts +4 -0
  52. package/dist/exit-codes.d.ts.map +1 -1
  53. package/dist/exit-codes.js +13 -10
  54. package/dist/exit-codes.js.map +1 -1
  55. package/dist/manifest.d.ts +8 -1
  56. package/dist/manifest.d.ts.map +1 -1
  57. package/dist/manifest.js +28 -2
  58. package/dist/manifest.js.map +1 -1
  59. package/dist/manifest.schema.d.ts +0 -2
  60. package/dist/manifest.schema.d.ts.map +1 -1
  61. package/dist/manifest.schema.js +0 -9
  62. package/dist/manifest.schema.js.map +1 -1
  63. package/dist/program.d.ts.map +1 -1
  64. package/dist/program.js +4 -8
  65. package/dist/program.js.map +1 -1
  66. package/dist/project-files.d.ts +11 -0
  67. package/dist/project-files.d.ts.map +1 -0
  68. package/dist/project-files.js +57 -0
  69. package/dist/project-files.js.map +1 -0
  70. package/dist/project-sync.d.ts +4 -3
  71. package/dist/project-sync.d.ts.map +1 -1
  72. package/dist/project-sync.js +11 -57
  73. package/dist/project-sync.js.map +1 -1
  74. package/dist/sync-engine.d.ts +3 -3
  75. package/dist/sync-engine.d.ts.map +1 -1
  76. package/dist/sync-engine.js +4 -3
  77. package/dist/sync-engine.js.map +1 -1
  78. package/dist/template-prompt.d.ts +8 -0
  79. package/dist/template-prompt.d.ts.map +1 -1
  80. package/dist/template-prompt.js +4 -4
  81. package/dist/template-prompt.js.map +1 -1
  82. package/package.json +1 -1
  83. package/dist/commands/preview.d.ts +0 -30
  84. package/dist/commands/preview.d.ts.map +0 -1
  85. package/dist/commands/preview.js +0 -129
  86. package/dist/commands/preview.js.map +0 -1
  87. package/dist/commands/push.d.ts +0 -26
  88. package/dist/commands/push.d.ts.map +0 -1
  89. package/dist/commands/push.js +0 -139
  90. package/dist/commands/push.js.map +0 -1
  91. package/dist/commands/version-state.d.ts +0 -35
  92. package/dist/commands/version-state.d.ts.map +0 -1
  93. package/dist/commands/version-state.js +0 -179
  94. package/dist/commands/version-state.js.map +0 -1
  95. package/dist/commands/versions.d.ts +0 -11
  96. package/dist/commands/versions.d.ts.map +0 -1
  97. package/dist/commands/versions.js +0 -63
  98. package/dist/commands/versions.js.map +0 -1
package/README.md CHANGED
@@ -18,7 +18,7 @@ Command-line tool for [Poli Page](https://poli.page) — scaffold projects, mana
18
18
  - [Authentication commands](#authentication-commands)
19
19
  - [Cloud sync](#cloud-sync)
20
20
  - [Live development](#live-development)
21
- - [Versioning](#versioning)
21
+ - [Environments](#environments)
22
22
  - [Render](#render)
23
23
  - [Documents](#documents)
24
24
  - [Manifest format](#manifest-format)
@@ -66,15 +66,14 @@ poli new invoice --from-template showcase/invoice
66
66
  # 4. Link the project to your organization (writes the cloud manifest)
67
67
  poli link
68
68
 
69
- # 5. Render a PDF using the local template against the cloud engine
69
+ # 5. Render the draft (the files `poli link` uploaded) to a PDF
70
70
  poli render invoice -o invoice.pdf
71
71
 
72
- # 6. Push your work as a SANDBOX version
73
- poli push --message "Initial draft"
72
+ # 6. Publish the project to the sandbox environment
73
+ poli publish --env sandbox
74
74
 
75
- # 7. Promote to LIVE when ready
76
- poli versions list
77
- poli promote 1.0.0
75
+ # 7. Publish it to live when ready
76
+ poli publish --env live -m "First release"
78
77
  ```
79
78
 
80
79
  To iterate on a template with live feedback against the cloud:
@@ -82,7 +81,7 @@ To iterate on a template with live feedback against the cloud:
82
81
  ```bash
83
82
  poli dev
84
83
  # opens http://127.0.0.1:7654 — edit a template, save, and the browser
85
- # shows the freshly rendered document about a second later
84
+ # reloads the freshly rendered PDF of your draft
86
85
  ```
87
86
 
88
87
  `poli dev` is the code-first alternative to the desktop editor. If you only want
@@ -106,20 +105,29 @@ After `poli login`, the session token is stored at `~/.polipage/credentials.json
106
105
 
107
106
  ### Programmatic (CI / CD / scripts)
108
107
 
109
- Set the `POLI_PAGE_API_KEY` environment variable. The value must start with `pp_`:
108
+ Set the `POLI_PAGE_API_KEY` environment variable. Every key is bound to one environment and carries its name: `pp_<environment>_` followed by 32 lowercase hex characters. The CLI checks the whole key before any call.
110
109
 
111
- | Prefix | Use case |
112
- | ----------- | ----------------------------------------------------------------- |
113
- | `pp_test_*` | Sandbox renders (unmetered, no quota) |
114
- | `pp_live_*` | Live renders (counts in the monthly quota, billable) |
115
- | `pp_sa_*` | Service account — recommended for CI; rotates without breaking dev|
110
+ | Key | Renders |
111
+ | ----------------------- | ---------------------------------------------------------------- |
112
+ | `pp_sandbox_…` | `name@sandbox` — free, watermarked, not counted |
113
+ | `pp_live_…` | `name@live` — counted in the monthly quota |
114
+ | `pp_<environment>_…` | `name@<environment>` — counted in the monthly quota |
115
+
116
+ A key renders only its own environment, and never the draft: the draft (`poli render name`) needs `poli login`.
116
117
 
117
118
  ```bash
118
- export POLI_PAGE_API_KEY=pp_sa_live_xxx
119
- poli render invoice -o invoice.pdf
120
- poli push --message "Release v1.0.5"
119
+ export POLI_PAGE_API_KEY=pp_live_xxx
120
+ poli render invoice@live -o invoice.pdf
121
+ poli publish --env live -m "Release from CI" # service key only
121
122
  ```
122
123
 
124
+ Standard keys and service keys share the `pp_<environment>_…` format; the CLI asks `GET /v1/me` which one it holds:
125
+
126
+ - a **standard key** renders only. `poli publish` refuses it before any upload (exit `5`).
127
+ - a **service key** (recommended for CI) also publishes, into its own environment only: `--env` is still required and must name the environment in the key (exit `2` otherwise). Its role decides on a protected environment: an `admin` service key can publish to one, a `developer` one gets `ENVIRONMENT_PROTECTED` (exit `5`). Nothing prompts.
128
+
129
+ The other workspace commands (`link`, `watch`, `dev`) need `poli login`.
130
+
123
131
  ### Precedence
124
132
 
125
133
  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.
@@ -130,7 +138,7 @@ This means a developer can keep `POLI_PAGE_API_KEY` set in `.zshrc` for occasion
130
138
 
131
139
  ## Commands
132
140
 
133
- 24 commands grouped by category.
141
+ 17 commands grouped by category.
134
142
 
135
143
  ### Project lifecycle
136
144
 
@@ -161,7 +169,7 @@ poli init --starter getting-started # writes ./getting-started
161
169
  poli init --starter getting-started my-start # writes ./my-start
162
170
  ```
163
171
 
164
- Writes the whole `getting-started/` project of [`poli-page/templates`](https://github.com/poli-page/templates) (templates, mocks, `poli-page.json`, `tailwind.css`, fonts and images) into `dir` (default: `./getting-started`). The files come from the public templates repo — the same source your org's `getting-started` project was created from — nothing is downloaded from the cloud. The written `poli-page.json` has no `project.version`.
172
+ Writes the whole `getting-started/` project of [`poli-page/templates`](https://github.com/poli-page/templates) (templates, mocks, `poli-page.json`, `tailwind.css`, fonts and images) into `dir` (default: `./getting-started`). The files come from the public templates repo — the same source your org's `getting-started` project was created from — nothing is downloaded from the cloud.
165
173
 
166
174
  When you are logged in, the folder is linked to the **existing** `getting-started` project of your organization (it never creates a cloud project). If you belong to several organizations, pass `--org <slug>` (or pick one at the prompt). Logged out, or when the organization has no `getting-started` project, the starter is written unlinked and the command tells you how to link it (`poli login`, then `poli link`).
167
175
 
@@ -169,8 +177,8 @@ A non-empty target directory is refused unless you pass `--force`. Then:
169
177
 
170
178
  ```bash
171
179
  cd getting-started
172
- poli watch # live sync of your edits to the cloud draft
173
- poli push # push a new sandbox version
180
+ poli watch # live sync of your edits to the cloud draft
181
+ poli publish --env sandbox # publish the project to the sandbox environment
174
182
  ```
175
183
 
176
184
  and re-run the dashboard snippet to see your change.
@@ -214,7 +222,7 @@ Displays the active identity and organization. Calls `GET /v1/me` over hybrid au
214
222
  ```bash
215
223
  # Inside a linked project (session)
216
224
  $ poli whoami
217
- xavier@example.com @ acme (session)
225
+ xavier@example.com @ acme (session, role=owner)
218
226
 
219
227
  # Anywhere — fallback when no project is linked, lists the orgs the session can see
220
228
  $ poli whoami
@@ -224,6 +232,10 @@ xavier@example.com (session, 2 organizations: acme, demo-corp)
224
232
  # Programmatic (API key)
225
233
  $ POLI_PAGE_API_KEY=pp_live_xxx poli whoami
226
234
  pp_live_xxx…abcd @ acme (api-key, environment=live)
235
+
236
+ # A service key also shows its role (a session shows the member's role)
237
+ $ POLI_PAGE_API_KEY=pp_staging_xxx poli whoami
238
+ pp_staging_xxx…abcd @ acme (api-key, environment=staging, role=admin)
227
239
  ```
228
240
 
229
241
  Flag: `--json` to dump the raw `/v1/me` payload (or, in `session-no-org` mode, `{ mode, user, orgs }`).
@@ -240,7 +252,7 @@ Removes the `cloud:` section from `poli-page.json`. Local files are preserved.
240
252
 
241
253
  #### `poli watch`
242
254
 
243
- 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`.
255
+ 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`. It syncs the same file set as [`poli publish`](#poli-publish), each file with its encoding (`base64` for assets, `utf8` otherwise); other files are not tracked.
244
256
 
245
257
  ```bash
246
258
  poli watch
@@ -260,10 +272,13 @@ you need the same sync inside a script or alongside a browser preview, use
260
272
 
261
273
  #### `poli dev [template]`
262
274
 
263
- Live-reloading preview server for template authors. On every save it syncs the
264
- project to the cloud draft, re-renders the active template through
265
- `POST /v1/render/preview`, and pushes a reload to every connected browser over
266
- Server-Sent Events — no polling, no fixed delay.
275
+ Live PDF preview server for template authors. On every save it syncs the
276
+ project to the cloud draft, renders the active template's draft to PDF through
277
+ `POST /v1/render/draft` with your signed-in session, and pushes a reload to every
278
+ connected browser over Server-Sent Events — no polling, no fixed delay. Draft
279
+ renders are session-only: they carry no watermark, are never stored as a
280
+ document, and are not counted. `POLI_PAGE_API_KEY` plays no part: an API key
281
+ cannot render the draft.
267
282
 
268
283
  ```bash
269
284
  poli dev # first template in the manifest
@@ -276,7 +291,7 @@ poli dev -d ./big.json # render every template against your own data
276
291
  | Flag | Default | Meaning |
277
292
  | -------------------- | ------------------ | ---------------------------------------------------------- |
278
293
  | `-p, --port <n>` | `7654` | Port to bind on `127.0.0.1`. Walks upwards when it is busy. |
279
- | `-d, --data <path>` | the template mock | JSON data file, same shape as `poli preview -d`. |
294
+ | `-d, --data <path>` | the template mock | JSON data file, same shape as `poli render -d`. |
280
295
  | `--no-open` | opens the browser | Skip launching a browser on start. |
281
296
  | `[template]` | first in manifest | Which template to show first. |
282
297
 
@@ -290,13 +305,12 @@ The served page gives you:
290
305
  moves nothing: the current template stays on screen and is re-rendered.
291
306
  - **A pin.** Click *Pin* to freeze the view on the current template so an
292
307
  unrelated save cannot yank you away. Unpin to follow again.
293
- - **Render PDF.** The HTML preview is fast but approximate. This button runs the
294
- real `POST /v1/render` for the active template and shows the resulting PDF
295
- inline, so you can check the actual outcome — pagination, page breaks, fonts.
296
- It creates a stored document, exactly like `poli render`.
308
+ - **The real PDF.** Every render is the actual PDF of the draft — pagination,
309
+ page breaks, fonts — shown in the browser's PDF viewer and reloaded after each
310
+ successful sync. There is no separate HTML preview mode.
297
311
  - **An error overlay.** A failed compile or render is shown with its message
298
312
  (and `file:line:column` when the engine reports a position) on top of the last
299
- good render, which stays visible behind it. A render error clears on the next
313
+ good PDF, which stays visible behind it. A render error clears on the next
300
314
  successful render; a failed sync stays shown until a sync succeeds, even when
301
315
  a render succeeds in between (the cloud draft is still out of date).
302
316
 
@@ -319,122 +333,143 @@ Notes:
319
333
  - `Ctrl-C` (or `SIGTERM`) closes the watcher, every SSE connection, and the
320
334
  port.
321
335
 
322
- ### Versioning
323
-
324
- #### `poli push`
336
+ ### Environments
325
337
 
326
- Sync the current local draft and create a new SANDBOX version. The body shape is one of two mutually exclusive forms (api-spec §9.1):
338
+ #### `poli publish`
327
339
 
328
- - Bump-driven: `--patch` (default), `--minor`, or `--major`. Anchored on the manifest's `cloud.track` (set by the previous push, or by `--track`).
329
- - Explicit: pass an exact semver as a positional argument (`poli push 1.0.2`). The server returns 409 `VERSION_CONFLICT` if the version already exists in any state.
340
+ Publishes the local project, the files on disk, to an environment of your organization: `POST /v1/projects/<projectSlug>/publish`, with your `poli login` session and the manifest's `cloud.orgId`, or, without a session, with a service key in `POLI_PAGE_API_KEY` (see below). The environment's copy of the project is replaced in place. There is no rollback: to go back, check out the earlier state from your own version control and publish again.
330
341
 
331
342
  ```bash
332
- poli push --message "Tweaked invoice header" # patch (default), anchored on cloud.track
333
- poli push --major --message "BREAKING: new schema" # ignores track, picks max(major)+1
334
- poli push --minor
335
- poli push 1.0.2 # explicit version (no track logic)
336
- poli push --track 1.0 --patch # override the manifest track (CI)
343
+ poli publish --env sandbox
344
+ poli publish --env live -m "Invoice footer fix"
345
+ poli publish --env live --yes # protected environment, no prompt (scripts)
337
346
  ```
338
347
 
339
- > An explicit positional version is mutually exclusive with `--patch` / `--minor` / `--major` and with `--track`.
348
+ | Flag | Meaning |
349
+ | ---------------------- | ----------------------------------------------------------------------------------------- |
350
+ | `--env <name>` | Required. The target environment; there is no default, and `draft` is not an environment. |
351
+ | `-m, --message <text>` | Kept in the publish log with the date, author and bundle hash. 500 characters at most. |
352
+ | `-y, --yes` | Publish to a protected environment without the confirmation prompt. |
353
+ | `--json` | Print the API response as JSON (also the default when stdout is not a TTY). |
340
354
 
341
- **Hotfix flow** — 1.0.1 LIVE in prod, 2.0.0 SANDBOX in dev:
355
+ - **Environment names** are 1-20 characters: lowercase letters, digits and single inner hyphens, starting with a letter. A name that breaks this rule is refused before any call (exit `2`). An environment that does not exist in the organization is refused with the list of the ones that do (exit `2`).
356
+ - **The bundle** is the project file set: `poli-page.json`, `tailwind.css`, the `.html`, `.json` and `.css` files under `templates/<slug>/`, the `.html` files under `partials/`, everything under `assets/images/` and `assets/icons/`, and the `.woff2`, `.woff`, `.ttf` and `.otf` files under `assets/fonts/`. Anything else (`.gitignore`, `README.md`, `output/`, `node_modules/`) is left out. Assets are sent base64-encoded, every other file as UTF-8. A bundle over 5 MiB, or a message over 500 characters, is refused before any call (exit `2`).
357
+ - **Protected environments** (`live` by default) accept a publish from an owner or an admin only. In a terminal, `poli publish` asks for confirmation first; without a TTY it needs `--yes`, and `CI=true` counts as `--yes`. Without the role, the API refuses with `ENVIRONMENT_PROTECTED` (exit `5`).
358
+ - **With a service key** (`POLI_PAGE_API_KEY` and no `poli login` session; a session wins when both are there): the CLI calls `GET /v1/me`, then publishes to the manifest's `cloud.projectSlug` with no organization header, since the key carries its organization. `--env` must name the key's own environment, or the publish is refused before any upload, naming it (exit `2`). A standard key is refused with "Standard API keys can only render. Use a service key or `poli login`." (exit `5`). There is no prompt and no environment check on the CLI side: the API applies the protected-environment rule, and a service key without the `admin` role gets `ENVIRONMENT_PROTECTED` (exit `5`).
359
+ - **One publish at a time** per project and environment: while one runs, a second gets `PUBLISH_IN_PROGRESS` (exit `3`). It is not retried; run it again once the first one is done.
360
+
361
+ On success it prints the environment, the project, the short bundle hash, the file count and the publish log id.
362
+
363
+ #### `poli env list`
364
+
365
+ Lists your organization's environments, with your `poli login` session (any member of the organization can run it).
342
366
 
343
367
  ```bash
344
- git checkout v1.0.1 # restore 1.0.1 from your own history: the local project is the source of truth
345
- # fix the bug…
346
- poli push --track 1.0 --patch # produces 1.0.2 (anchored on track 1.0), not 2.0.1
347
- poli promote 1.0.2
368
+ poli env list # in a linked folder: the project's state in each environment
369
+ poli env list --org acme # elsewhere, or for another organization
370
+ poli env list --json
348
371
  ```
349
372
 
350
- After the push, `cloud.track` is updated to the major.minor of the version the server returned (no-op for patches on the same family).
351
-
352
- #### `poli versions list` (alias `ls`)
373
+ | Flag | Meaning |
374
+ | -------------- | ------------------------------------------------------------------------------------------- |
375
+ | `--org <slug>` | The organization to list. Default: the linked project's organization, else your only one. |
376
+ | `--json` | Print the API response as JSON (also the default when stdout is not a TTY). |
353
377
 
354
- Display all versions of the linked project with their state badges.
378
+ In a linked folder, each environment shows whether it is protected and read-only, whether the project is published there, and the project's last publish in it: its status (`succeeded`, `in-progress`, or `failed` with the API's error code), its date (UTC), its author, its short bundle hash and its message, or `not published`. The last publish is the latest attempt, so a failed one shows even when an earlier publish is still the one served.
355
379
 
356
380
  ```
357
- STATE VERSION PUSHED MESSAGE
358
- LIVE 2.0.0 3 days ago Major redesign
359
- LIVE 1.0.5 1 week ago Hotfix URSSAF
360
- SANDBOX 1.1.0 2 hours ago
361
- DEPRECATED 1.0.2 3 weeks ago
362
- ```
381
+ Environments of acme, project invoices:
363
382
 
364
- #### `poli promote <version>`
383
+ ENVIRONMENT PROTECTED READ-ONLY PUBLISHED LAST PUBLISH
384
+ sandbox no no yes succeeded 2026-10-26 10:00 UTC Ada Lovelace 0123456789ab Invoice footer fix
385
+ live yes no no not published
386
+ ```
365
387
 
366
- Move a SANDBOX version to LIVE. Confirmation prompt unless `--yes`.
388
+ Outside a linked folder, or with `--org` naming another organization, it lists the organization's environments with their protected and read-only flags and how many projects are published in each (`PROJECTS`). When you belong to several organizations and no project is linked, `--org` is required: without it the command exits `2` and lists your organizations' slugs. An environment is read-only when the organization's plan no longer covers it.
367
389
 
368
- #### `poli unpromote <version>`
390
+ #### `poli env remove-project <environment>`
369
391
 
370
- Move a LIVE version back to SANDBOX. Shows a usage preview (calls in the last 24h, the next-latest LIVE) before confirming.
392
+ Removes the linked project from an environment: the environment's copy of the project is deleted, and the documents rendered from it are kept. The draft and the other environments are untouched, nothing is written to the publish log, and renders of the project in that environment then get `PROJECT_NOT_IN_ENVIRONMENT` until a later `poli publish --env <environment>` adds it back. Only an owner or an admin of the organization can do it, in every environment.
371
393
 
372
394
  ```bash
373
- poli unpromote 1.0.5
374
- poli unpromote 1.0.5 --force # allow unpromoting the last LIVE version
395
+ poli env remove-project staging # asks you to type the project slug
396
+ poli env remove-project staging --yes # scripts: no prompt
375
397
  ```
376
398
 
377
- #### `poli versions deprecate <version>`
378
-
379
- Mark a SANDBOX version as DEPRECATED.
399
+ | Flag | Meaning |
400
+ | ----------- | ---------------------------------------------------------------------------------- |
401
+ | `-y, --yes` | Remove without typing the project slug to confirm. |
402
+ | `--json` | Print `{ org, project, environment }` (also the default when stdout is not a TTY). |
380
403
 
381
- #### `poli versions un-deprecate <version>`
382
-
383
- Move a DEPRECATED version back to SANDBOX.
404
+ - **Confirmation.** In a terminal, you type the project slug (`cloud.projectSlug` in `poli-page.json`); anything else aborts and nothing is sent. Without a TTY the command needs `--yes` and otherwise exits `2`; `CI=true` does not stand in for `--yes` here.
405
+ - **Errors.** A developer gets `INSUFFICIENT_ROLE` (exit `5`, owner or admin required). A project that is not published in the environment (`PROJECT_NOT_IN_ENVIRONMENT`) or an environment the organization does not have (`ENVIRONMENT_NOT_FOUND`) exits `2`. While a publish or another removal of the same project and environment runs (`PUBLISH_IN_PROGRESS`), while the project is being transferred (`TRANSFER_IN_PROGRESS`), or when the environment is read-only (`ENVIRONMENT_READ_ONLY`), it exits `3`.
384
406
 
385
407
  ### Render
386
408
 
387
409
  #### `poli render <spec>`
388
410
 
389
- Render a template against the cloud engine. The `<spec>` is either the bare template `name` (renders the draft) or `name@<X.Y.Z>` to pin an exact published version (npm-style). Every render produces a stored document (api-spec §11.3) — the CLI receives a JSON descriptor with `documentId`, `presignedPdfUrl`, `expiresAt`, and 13 other fields. By default it then fetches the URL and writes the PDF locally; pass `--no-download` to skip that step.
411
+ Render a template against the cloud engine. The `<spec>` is either the bare template `name` (the draft) or `name@<environment>` (what is published in that environment).
412
+
413
+ - **The draft** (`name`, or `name@draft`) renders through `POST /v1/render/draft` and needs a `poli login` session: an API key never renders the draft. The API answers the PDF itself, which the CLI writes locally. Nothing is stored, watermarked or counted, so there is no document and `--no-download` is refused.
414
+ - **An environment** (`name@<environment>`) renders through `POST /v1/render` with `environment: <environment>`. Every such render produces a stored document (api-spec §11.3): the CLI receives a JSON descriptor (`documentId`, `presignedPdfUrl`, `expiresAt`, `environment`, `diagnostics`, …), then fetches the URL and writes the PDF locally; pass `--no-download` to skip that step. With an API key, the environment must be the key's own; another one is refused before any call, naming the key's environment.
390
415
 
391
416
  ```bash
392
- poli render invoice # default: draft, downloads PDF
393
- poli render invoice@1.0.5 # exact semver pin
394
- poli render invoice@draft --data ./mock.json # explicit draft + custom data
417
+ poli render invoice # the draft (session), downloads PDF
418
+ poli render invoice@sandbox # what is published in sandbox
419
+ poli render invoice@production --data ./mock.json # an environment + custom data
395
420
  poli render invoice -o ./out/invoice.pdf # custom path
396
- poli render invoice --no-download # JSON descriptor only
421
+ poli render invoice@sandbox --no-download # JSON descriptor only
397
422
  ```
398
423
 
399
424
  Spec rules:
400
425
 
401
426
  - `name` → renders the draft (equivalent to `name@draft`).
402
- - `name@<X.Y.Z>` → exact semver only. `latest`, `1.0`, etc. are rejected with a friendly error.
427
+ - `name@<environment>` → an environment name: 1-20 characters, lowercase letters, digits and single inner hyphens, starting with a letter. `draft` is not an environment name: `name@draft` means the draft. Versions are gone: `name@1.2.3` and `name@latest` are refused with a pointer to `name@<environment>` (exit code `2`).
403
428
 
404
429
  Flags:
405
430
 
406
431
  - `--data <file>` — JSON data overrides the mock
407
432
  - `-o <file>` — output PDF path. Incompatible with `--no-download`
408
- - `--no-download` — skip the presigned URL fetch (CI/CD pipelines)
433
+ - `--no-download` — skip the presigned URL fetch (CI/CD pipelines). Environment renders only
409
434
  - `--json` — force JSON output even in a TTY
410
435
 
436
+ With `--json` (or piped), an environment render prints the API descriptor plus `outputPath`; a draft render, which has no descriptor, prints `{ "template", "environment": "draft", "outputPath" }`.
437
+
438
+ Errors:
439
+
440
+ - `404 PROJECT_NOT_IN_ENVIRONMENT` — the project was never published there: run `poli publish --env <environment>`. Exit code `2`.
441
+ - `404 ENVIRONMENT_NOT_FOUND` / `404 TEMPLATE_NOT_FOUND` — the environment does not exist, or the published copy has no such template. Exit code `2`.
442
+ - `503 PUBLISH_IN_PROGRESS` — a publish of that project and environment is running: the CLI waits `Retry-After` and retries once, then exits `3`.
443
+
411
444
  [Output rules](#output-conventions) apply: in a TTY you see only the `✓` line, in a pipe you see only the JSON descriptor, with `--json` you always see the JSON. Pipelines stay clean:
412
445
 
413
446
  ```bash
414
- $ DOC_ID=$(poli render invoice | jq -r '.documentId')
447
+ $ DOC_ID=$(poli render invoice@sandbox | jq -r '.documentId')
415
448
  $ poli documents thumbnails "$DOC_ID" --width 400
416
449
  ```
417
450
 
418
- Resolved environment is exposed in the success line (TTY):
451
+ The success line (TTY) names what was rendered, and says `billed` when the render counts:
419
452
 
420
453
  ```
421
- ✓ Rendered invoice v1.0.5 (live, billed) → ./output/invoice/invoice.pdf
422
- ✓ Rendered invoice vdraft (sandbox) → ./output/invoice/invoice.pdf
454
+ ✓ Rendered invoice@production (billed) → ./output/invoice/a4-portrait/invoice.pdf
455
+ ✓ Rendered invoice@sandbox → ./output/invoice/a4-portrait/invoice.pdf
456
+ ✓ Rendered invoice@draft → ./output/invoice/a4-portrait/invoice.pdf
423
457
  ```
424
458
 
425
459
  Counter:
426
- - `version: draft` or `X.Y.Z` SANDBOX/DEPRECATED → unmetered
427
- - `version: X.Y.Z` LIVE → counts in monthly quota
460
+ - the draft → never counted
461
+ - `sandbox` → free, never counted (and the only watermarked environment)
462
+ - every other environment → counts in the monthly quota
428
463
 
429
464
  ### Documents
430
465
 
431
- Documents are the cloud-stored output of every `poli render` invocation (or the same render endpoints called via the SDK or REST API). The CLI lets you inspect, delete, and re-derive thumbnails or preview HTML from them.
466
+ Documents are the cloud-stored output of every `poli render name@<environment>` invocation (or the same render endpoints called via the SDK or REST API); a draft render (`poli render name`) is never stored. The CLI lets you inspect, delete, and re-derive thumbnails or preview HTML from them.
432
467
 
433
468
  There is intentionally **no `poli documents list`** — your application is responsible for tracking the `documentId` values it cares about.
434
469
 
435
470
  #### `poli documents get <id>`
436
471
 
437
- Returns the document JSON descriptor — same 16-field shape as `poli render`. Output rules: in a TTY you see only the human-readable summary; in a pipe you see only the JSON descriptor; `--json` forces JSON. The CLI never downloads the PDF — `curl` the `presignedPdfUrl` or hand it to the browser yourself.
472
+ Returns the document JSON descriptor — the shape `poli render name@<environment>` prints, without the render's `diagnostics`. The summary shows the environment the document was rendered in. Output rules: in a TTY you see only the human-readable summary; in a pipe you see only the JSON descriptor; `--json` forces JSON. The CLI never downloads the PDF — `curl` the `presignedPdfUrl` or hand it to the browser yourself.
438
473
 
439
474
  ```bash
440
475
  poli documents get doc_abc123
@@ -476,8 +511,7 @@ poli documents preview doc_abc123 -o ./preview.html
476
511
  ```jsonc
477
512
  {
478
513
  "project": {
479
- "name": "my-invoices",
480
- "version": "1.0.0"
514
+ "name": "my-invoices"
481
515
  },
482
516
  "fonts": [
483
517
  {
@@ -506,6 +540,8 @@ poli documents preview doc_abc123 -o ./preview.html
506
540
 
507
541
  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.
508
542
 
543
+ A manifest from before environments may still carry `project.version` or `cloud.track`. Both are ignored, and dropped the next time the CLI writes the file (`poli link`, `poli unlink`, `poli new`).
544
+
509
545
  ---
510
546
 
511
547
  ## Configuration
@@ -514,11 +550,10 @@ The `cloud:` block is written by `poli link`, removed by `poli unlink`. **No API
514
550
 
515
551
  | Variable | Effect |
516
552
  | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
517
- | `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. |
553
+ | `POLI_PAGE_API_KEY` | Single env var for any API key in CI/CD: `pp_<environment>_` followed by 32 lowercase hex characters, checked in full before any call. The key renders only its own environment; a service key also publishes to it. **Precedence**: when a credentials file is also present, the session wins. |
518
554
  | `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`). |
519
- | `POLI_PAGE_ENV` | Default render env (`sandbox` or `live`) when commands accept an env hint. |
520
555
  | `NO_COLOR` | Disable ANSI colors (Unix standard). |
521
- | `CI` | Auto-detected; equivalent to a global `--yes`. |
556
+ | `CI` | Auto-detected; equivalent to a global `--yes`, except for `poli env remove-project`. |
522
557
 
523
558
  ### Common flags
524
559
 
@@ -529,7 +564,7 @@ The `cloud:` block is written by `poli link`, removed by `poli unlink`. **No API
529
564
 
530
565
  ### Output conventions
531
566
 
532
- Every command that returns a payload (renders, descriptors, lists, version mutations) follows the same output rule:
567
+ Every command that returns a payload (renders, descriptors, publishes) follows the same output rule:
533
568
 
534
569
  | Context | Stdout |
535
570
  | ------- | ------ |
@@ -539,7 +574,7 @@ Every command that returns a payload (renders, descriptors, lists, version mutat
539
574
 
540
575
  Either the summary **or** the JSON — never both at once. Errors always go to stderr with a clear message.
541
576
 
542
- Commands that take this contract: `render`, `documents get`, `documents preview`, `documents thumbnails`, `whoami`, `versions list`, `push`, `promote`, `unpromote`, `versions deprecate`, `versions un-deprecate`, `init --starter`.
577
+ Commands that take this contract: `render`, `documents get`, `documents preview`, `documents thumbnails`, `whoami`, `publish`, `env list`, `env remove-project`, `init --starter`.
543
578
 
544
579
  Imperative commands (`init` without `--starter`, `new`, `link`, `unlink`, `logout`, `documents delete`, `watch`, `login`) don't have a JSON payload to forward — they just acknowledge with a `✓` line on success.
545
580
 
@@ -549,12 +584,12 @@ Imperative commands (`init` without `--starter`, `new`, `link`, `unlink`, `logou
549
584
 
550
585
  | Code | Meaning |
551
586
  | ---- | ------------------------------------------------------------------------------------------------------ |
552
- | `0` | Success (or no-op, e.g. `promote` when nothing changes) |
553
- | `1` | Recoverable inconsistency (already logged in, already linked, version already live) |
554
- | `2` | Invalid usage (bad args, template not found, version not found, non-TTY context where TTY is required) |
587
+ | `0` | Success |
588
+ | `1` | Recoverable inconsistency (already logged in, already linked) |
589
+ | `2` | Invalid usage (bad args, template not found, project not published in that environment, non-TTY context where TTY is required) |
555
590
  | `3` | Network / API error (timeout, 5xx, unspecified 4xx) |
556
591
  | `4` | Not authenticated — run `poli login` or set `POLI_PAGE_API_KEY` |
557
- | `5` | Not authorized (insufficient role, `THUMBNAILS_NOT_AVAILABLE`, system project locked) |
592
+ | `5` | Not authorized (insufficient role, protected environment, `THUMBNAILS_NOT_AVAILABLE`) |
558
593
  | `6` | Invalid local state (no project, project not linked, empty folder where required) |
559
594
 
560
595
  These map to the centralised `ExitCode` constants in `src/exit-codes.ts`. Every handler routes errors through `errorToExitCode(err)`.
@@ -563,6 +598,32 @@ These map to the centralised `ExitCode` constants in `src/exit-codes.ts`. Every
563
598
 
564
599
  ## CI / CD
565
600
 
601
+ ### Publish from CI with a service key
602
+
603
+ ```yaml
604
+ # .github/workflows/publish.yml
605
+ name: Publish templates
606
+
607
+ on:
608
+ push:
609
+ branches: [main]
610
+
611
+ jobs:
612
+ publish:
613
+ runs-on: ubuntu-latest
614
+ env:
615
+ POLI_PAGE_API_KEY: ${{ secrets.POLI_PAGE_SERVICE_KEY }} # a service key for `live`
616
+ steps:
617
+ - uses: actions/checkout@v4
618
+ - uses: actions/setup-node@v4
619
+ with:
620
+ node-version: '22'
621
+ - run: npm install -g @poli-page/cli
622
+ - run: poli publish --env live -m "Deploy ${{ github.sha }}"
623
+ ```
624
+
625
+ The workflow runs in the linked project folder (the one with `poli-page.json` and its `cloud` block). The key decides the environment: `--env` must name it. `live` is protected, so the service key needs the `admin` role.
626
+
566
627
  ### GitHub Actions
567
628
 
568
629
  ```yaml
@@ -582,14 +643,14 @@ jobs:
582
643
  with:
583
644
  node-version: '22'
584
645
  - run: npm install -g @poli-page/cli
585
- - run: poli render invoice@1.0.5 -o ./artifacts/invoice.pdf
646
+ - run: poli render invoice@live -o ./artifacts/invoice.pdf
586
647
  - uses: actions/upload-artifact@v4
587
648
  with:
588
649
  name: invoice-pdf
589
650
  path: ./artifacts/invoice.pdf
590
651
  ```
591
652
 
592
- Recommended: use a **service account key** (`pp_sa_live_*`) so rotating it does not log out any developer.
653
+ The key decides the environment: a `pp_live_…` key renders `invoice@live` and nothing else. A standard key is enough to render; a service key also works, and rotating either one does not log out any developer.
593
654
 
594
655
  ### GitLab CI
595
656
 
@@ -600,7 +661,7 @@ render:
600
661
  POLI_PAGE_API_KEY: $POLI_PAGE_API_KEY
601
662
  script:
602
663
  - npm install -g @poli-page/cli
603
- - poli render invoice@1.0.5 -o invoice.pdf
664
+ - poli render invoice@live -o invoice.pdf
604
665
  artifacts:
605
666
  paths:
606
667
  - invoice.pdf
@@ -611,10 +672,10 @@ render:
611
672
  ```bash
612
673
  # In a build script
613
674
  npm install -g @poli-page/cli
614
- POLI_PAGE_API_KEY=pp_sa_live_xxx poli render homepage-pdf -o ./public/welcome.pdf
675
+ POLI_PAGE_API_KEY=pp_live_xxx poli render homepage-pdf@live -o ./public/welcome.pdf
615
676
  ```
616
677
 
617
- Service accounts have a **fixed role and environment** at creation. The CLI does not try to switch them — the API enforces the permissions.
678
+ A service key has a **fixed role and environment** from its creation. The CLI does not try to switch them — the API enforces the permissions.
618
679
 
619
680
  ---
620
681
 
@@ -624,17 +685,47 @@ Service accounts have a **fixed role and environment** at creation. The CLI does
624
685
 
625
686
  Either run `poli login` interactively, or export `POLI_PAGE_API_KEY` for CI use. Exit code `4`.
626
687
 
627
- ### `POLI_PAGE_API_KEY must start with \`pp_\`...`
688
+ ### `POLI_PAGE_API_KEY must be a Poli Page API key: \`pp_<environment>_…\`...`
689
+
690
+ You set the variable but its value is not a whole key: `pp_`, the environment name, `_`, then 32 lowercase hex characters. Copy the key again, or create one from the dashboard's API keys page. Exit code `4`.
691
+
692
+ ### `Standard API keys can only render. Use a service key or \`poli login\`.`
693
+
694
+ `poli publish` with `POLI_PAGE_API_KEY` set to a standard key. Only a service key, or a `poli login` session, can publish. Exit code `5`.
695
+
696
+ ### `This service key publishes to "<a>" only, not "<b>"...`
628
697
 
629
- 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`.
698
+ A service key publishes into its own environment only. Pass `--env <a>`, or use a service key for `<b>`. Exit code `2`.
630
699
 
631
700
  ### `This folder isn't linked to a cloud project. Run \`poli link\` first.`
632
701
 
633
- 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`.
702
+ 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_<environment>_…` (which carries the org context implicitly). Exit code `6`.
634
703
 
635
- ### `\`latest\` was retired. Run \`poli versions list\` and pin an exact semver...`
704
+ ### `API keys render a published environment: use \`name@<environment>\``
636
705
 
637
- 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`.
706
+ `poli render name` renders the draft, which only a `poli login` session can do. With an API key, render the key's environment: `poli render name@<environment>`. Exit code `2`.
707
+
708
+ ### `This API key renders the \`<a>\` environment, not \`<b>\``
709
+
710
+ A key renders only the environment in its prefix. Render `name@<a>`, or use a key for `<b>`. Exit code `2`.
711
+
712
+ ### `\`invoice@1.2.3\`: templates no longer have versions...`
713
+
714
+ Render specs name an environment, not a version: `poli render invoice@<environment>`, or `poli render invoice` for the draft. Exit code `2`.
715
+
716
+ ### `403 DRAFT_REQUIRES_SESSION`
717
+
718
+ The API renders the draft for a `poli login` session only. The CLI refuses a draft render with an API key before any call (see above), so this code comes back only from a draft render sent outside the CLI with a key. Render `name@<environment>` with the key, or render the draft after `poli login`.
719
+
720
+ ### `Environment "<env>" is protected...` (`403 ENVIRONMENT_PROTECTED`)
721
+
722
+ `poli publish --env <env>` to a protected environment (`live` by default) by someone who is not an owner or admin of the organization, or with a service key without the `admin` role. Ask an owner or admin to publish, or use an `admin` service key. Exit code `5`.
723
+
724
+ Without a terminal, `Environment "<env>" is protected. Pass --yes to publish to it without a prompt.` means the confirmation could not be asked: pass `--yes` (`CI=true` counts as `--yes`). Exit code `2`.
725
+
726
+ ### `PUBLISH_IN_PROGRESS`
727
+
728
+ A publish of the same project and environment is running. `poli render name@<env>` gets `503 PUBLISH_IN_PROGRESS`, waits `Retry-After` and retries once; if the publish is still running, it exits `3`: try again in a moment. `poli publish` and `poli env remove-project` get it while another publish or removal runs, and do not retry: run the command again once the other one is done. Exit code `3`.
638
729
 
639
730
  ### `403 THUMBNAILS_NOT_AVAILABLE`
640
731
 
@@ -642,7 +733,7 @@ Thumbnails via `poli documents thumbnails` are a paid-tier feature. Upgrade to S
642
733
 
643
734
  ### `429 OVERAGE_CAP_EXCEEDED`
644
735
 
645
- Your org has crossed the monthly cap on `live` PDF renders (counted across `poli render` against a LIVE version and `poli documents thumbnails` on a LIVE document). Wait until the next billing period or raise the cap from your dashboard. Exit code `3`.
736
+ Your org has crossed the monthly cap on `live` PDF renders (counted across `poli render` in any environment other than `sandbox` and `poli documents thumbnails` on a document of such an environment). Wait until the next billing period or raise the cap from your dashboard. Exit code `3`.
646
737
 
647
738
  ### `503 ORGANIZATION_MIGRATING`
648
739
 
@@ -652,10 +743,6 @@ Your org is being migrated to a new tier. `poli watch` retries automatically aft
652
743
 
653
744
  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.
654
745
 
655
- ### CI pipeline rejected with exit `5` on `poli promote`
656
-
657
- 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.
658
-
659
746
  ---
660
747
 
661
748
  ## License