@poli-page/cli 0.9.0 → 0.11.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 (164) hide show
  1. package/README.md +287 -134
  2. package/dist/api-client.d.ts +117 -93
  3. package/dist/api-client.d.ts.map +1 -1
  4. package/dist/api-client.js +99 -115
  5. package/dist/api-client.js.map +1 -1
  6. package/dist/api-origin.d.ts +28 -0
  7. package/dist/api-origin.d.ts.map +1 -0
  8. package/dist/api-origin.js +84 -0
  9. package/dist/api-origin.js.map +1 -0
  10. package/dist/auth.d.ts +14 -4
  11. package/dist/auth.d.ts.map +1 -1
  12. package/dist/auth.js +22 -13
  13. package/dist/auth.js.map +1 -1
  14. package/dist/cloud-context.d.ts +8 -2
  15. package/dist/cloud-context.d.ts.map +1 -1
  16. package/dist/cloud-context.js +16 -34
  17. package/dist/cloud-context.js.map +1 -1
  18. package/dist/cloud-link.d.ts +41 -0
  19. package/dist/cloud-link.d.ts.map +1 -0
  20. package/dist/cloud-link.js +112 -0
  21. package/dist/cloud-link.js.map +1 -0
  22. package/dist/commands/auth.d.ts +31 -8
  23. package/dist/commands/auth.d.ts.map +1 -1
  24. package/dist/commands/auth.js +77 -25
  25. package/dist/commands/auth.js.map +1 -1
  26. package/dist/commands/dev.d.ts +6 -6
  27. package/dist/commands/dev.d.ts.map +1 -1
  28. package/dist/commands/dev.js +55 -103
  29. package/dist/commands/dev.js.map +1 -1
  30. package/dist/commands/documents/delete.d.ts.map +1 -1
  31. package/dist/commands/documents/delete.js +2 -9
  32. package/dist/commands/documents/delete.js.map +1 -1
  33. package/dist/commands/documents/document-id.d.ts +2 -0
  34. package/dist/commands/documents/document-id.d.ts.map +1 -0
  35. package/dist/commands/documents/document-id.js +10 -0
  36. package/dist/commands/documents/document-id.js.map +1 -0
  37. package/dist/commands/documents/get.d.ts +4 -0
  38. package/dist/commands/documents/get.d.ts.map +1 -1
  39. package/dist/commands/documents/get.js +5 -14
  40. package/dist/commands/documents/get.js.map +1 -1
  41. package/dist/commands/documents/preview.d.ts +1 -0
  42. package/dist/commands/documents/preview.d.ts.map +1 -1
  43. package/dist/commands/documents/preview.js +89 -14
  44. package/dist/commands/documents/preview.js.map +1 -1
  45. package/dist/commands/documents/thumbnails.d.ts.map +1 -1
  46. package/dist/commands/documents/thumbnails.js +35 -20
  47. package/dist/commands/documents/thumbnails.js.map +1 -1
  48. package/dist/commands/env.d.ts +3 -0
  49. package/dist/commands/env.d.ts.map +1 -0
  50. package/dist/commands/env.js +212 -0
  51. package/dist/commands/env.js.map +1 -0
  52. package/dist/commands/init.d.ts.map +1 -1
  53. package/dist/commands/init.js +35 -37
  54. package/dist/commands/init.js.map +1 -1
  55. package/dist/commands/link.d.ts +6 -0
  56. package/dist/commands/link.d.ts.map +1 -1
  57. package/dist/commands/link.js +68 -35
  58. package/dist/commands/link.js.map +1 -1
  59. package/dist/commands/new.d.ts.map +1 -1
  60. package/dist/commands/new.js +13 -6
  61. package/dist/commands/new.js.map +1 -1
  62. package/dist/commands/publish.d.ts +22 -0
  63. package/dist/commands/publish.d.ts.map +1 -0
  64. package/dist/commands/publish.js +179 -0
  65. package/dist/commands/publish.js.map +1 -0
  66. package/dist/commands/render.d.ts +27 -11
  67. package/dist/commands/render.d.ts.map +1 -1
  68. package/dist/commands/render.js +140 -61
  69. package/dist/commands/render.js.map +1 -1
  70. package/dist/commands/watch.d.ts +3 -0
  71. package/dist/commands/watch.d.ts.map +1 -1
  72. package/dist/commands/watch.js +7 -1
  73. package/dist/commands/watch.js.map +1 -1
  74. package/dist/constants.d.ts +1 -0
  75. package/dist/constants.d.ts.map +1 -1
  76. package/dist/constants.js +1 -0
  77. package/dist/constants.js.map +1 -1
  78. package/dist/credentials.d.ts +10 -0
  79. package/dist/credentials.d.ts.map +1 -1
  80. package/dist/credentials.js +27 -15
  81. package/dist/credentials.js.map +1 -1
  82. package/dist/dev-page.d.ts +12 -5
  83. package/dist/dev-page.d.ts.map +1 -1
  84. package/dist/dev-page.js +30 -68
  85. package/dist/dev-page.js.map +1 -1
  86. package/dist/dev-server.d.ts +19 -0
  87. package/dist/dev-server.d.ts.map +1 -1
  88. package/dist/dev-server.js +70 -8
  89. package/dist/dev-server.js.map +1 -1
  90. package/dist/environment-name.d.ts +8 -0
  91. package/dist/environment-name.d.ts.map +1 -0
  92. package/dist/environment-name.js +21 -0
  93. package/dist/environment-name.js.map +1 -0
  94. package/dist/exit-codes.d.ts +4 -0
  95. package/dist/exit-codes.d.ts.map +1 -1
  96. package/dist/exit-codes.js +25 -15
  97. package/dist/exit-codes.js.map +1 -1
  98. package/dist/file-watcher.d.ts +4 -1
  99. package/dist/file-watcher.d.ts.map +1 -1
  100. package/dist/file-watcher.js +26 -11
  101. package/dist/file-watcher.js.map +1 -1
  102. package/dist/format-resolver.d.ts +6 -0
  103. package/dist/format-resolver.d.ts.map +1 -1
  104. package/dist/format-resolver.js +14 -6
  105. package/dist/format-resolver.js.map +1 -1
  106. package/dist/manifest.d.ts +16 -1
  107. package/dist/manifest.d.ts.map +1 -1
  108. package/dist/manifest.js +62 -6
  109. package/dist/manifest.js.map +1 -1
  110. package/dist/manifest.schema.d.ts +4 -4
  111. package/dist/manifest.schema.d.ts.map +1 -1
  112. package/dist/manifest.schema.js +40 -16
  113. package/dist/manifest.schema.js.map +1 -1
  114. package/dist/output.d.ts +5 -0
  115. package/dist/output.d.ts.map +1 -1
  116. package/dist/output.js +7 -0
  117. package/dist/output.js.map +1 -1
  118. package/dist/program.d.ts.map +1 -1
  119. package/dist/program.js +53 -27
  120. package/dist/program.js.map +1 -1
  121. package/dist/project-files.d.ts +30 -0
  122. package/dist/project-files.d.ts.map +1 -0
  123. package/dist/project-files.js +75 -0
  124. package/dist/project-files.js.map +1 -0
  125. package/dist/project-loader.d.ts +6 -3
  126. package/dist/project-loader.d.ts.map +1 -1
  127. package/dist/project-loader.js +36 -61
  128. package/dist/project-loader.js.map +1 -1
  129. package/dist/project-sync.d.ts +37 -3
  130. package/dist/project-sync.d.ts.map +1 -1
  131. package/dist/project-sync.js +170 -84
  132. package/dist/project-sync.js.map +1 -1
  133. package/dist/security/paths.d.ts +29 -0
  134. package/dist/security/paths.d.ts.map +1 -0
  135. package/dist/security/paths.js +109 -0
  136. package/dist/security/paths.js.map +1 -0
  137. package/dist/sync-engine.d.ts +3 -3
  138. package/dist/sync-engine.d.ts.map +1 -1
  139. package/dist/sync-engine.js +4 -3
  140. package/dist/sync-engine.js.map +1 -1
  141. package/dist/template-importer.d.ts.map +1 -1
  142. package/dist/template-importer.js +170 -59
  143. package/dist/template-importer.js.map +1 -1
  144. package/dist/template-prompt.d.ts +8 -0
  145. package/dist/template-prompt.d.ts.map +1 -1
  146. package/dist/template-prompt.js +4 -4
  147. package/dist/template-prompt.js.map +1 -1
  148. package/package.json +1 -1
  149. package/dist/commands/preview.d.ts +0 -30
  150. package/dist/commands/preview.d.ts.map +0 -1
  151. package/dist/commands/preview.js +0 -129
  152. package/dist/commands/preview.js.map +0 -1
  153. package/dist/commands/push.d.ts +0 -26
  154. package/dist/commands/push.d.ts.map +0 -1
  155. package/dist/commands/push.js +0 -139
  156. package/dist/commands/push.js.map +0 -1
  157. package/dist/commands/version-state.d.ts +0 -35
  158. package/dist/commands/version-state.d.ts.map +0 -1
  159. package/dist/commands/version-state.js +0 -179
  160. package/dist/commands/version-state.js.map +0 -1
  161. package/dist/commands/versions.d.ts +0 -11
  162. package/dist/commands/versions.d.ts.map +0 -1
  163. package/dist/commands/versions.js +0 -63
  164. 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
@@ -99,38 +98,45 @@ The CLI supports two authentication modes. Both flow through the same internal r
99
98
  ```bash
100
99
  poli login # device authorization flow — opens your browser
101
100
  poli whoami # show the current session and active org
102
- poli logout # clear ~/.polipage/credentials.json
101
+ poli logout # delete ~/.polipage/credentials, then revoke the session
103
102
  ```
104
103
 
105
- After `poli login`, the session token is stored at `~/.polipage/credentials.json` and used automatically by every subsequent command.
104
+ After `poli login`, the session token is stored at `~/.polipage/credentials` and used by every command that needs it (while `POLI_PAGE_API_KEY` is set, the commands that accept a key use the key instead: see [Precedence](#precedence)).
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`, with `POLI_PAGE_API_KEY` unset (see [Precedence](#precedence)).
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
 
123
- ### Precedence
124
+ Standard keys and service keys share the `pp_<environment>_…` format; the CLI asks `GET /v1/me` which one it holds:
124
125
 
125
- 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.
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
+
131
+ ### Precedence
126
132
 
127
- 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.
133
+ When **both** `~/.polipage/credentials` (a session) and `POLI_PAGE_API_KEY` are set, **the key wins** for every command that accepts either credential (`whoami`, `publish`, `render`, `documents`): a set key is an explicit choice, so exporting a `pp_sandbox_…` key makes those commands act as that key, not as your full session. The session-only commands (`link`, `watch`, `dev`, `env`) keep using your session. While the key wins, what it cannot do is refused even though a session is stored: `poli render <name>` (the draft), `poli render <name>@<environment>` for another environment than the key's, `poli publish` with a standard key, with an `--env` other than the key's or with a key of another organization than the linked one, and any of those commands with a malformed key fail, and their error says to unset `POLI_PAGE_API_KEY` to use the session. In a terminal, `poli whoami` says when the key is used instead of a stored session (its JSON is the `GET /v1/me` response, unchanged), and `poli publish` prints which credential it used (`Auth:` in its summary, `credential` in its JSON). `poli login` does not refuse if the env var is set — it shows an info-message and proceeds, but the key keeps winning until you unset it.
128
134
 
129
135
  ---
130
136
 
131
137
  ## Commands
132
138
 
133
- 24 commands grouped by category.
139
+ 17 commands grouped by category.
134
140
 
135
141
  ### Project lifecycle
136
142
 
@@ -151,7 +157,8 @@ Flags:
151
157
 
152
158
  - `--with-template <ref>` — pre-install a starter template, format `<collection>/<template>`. Skips the interactive prompt.
153
159
  - `--template-name <name>` — override the imported template's destination name
154
- - `--source <repo>` — source repo, format `github:<owner>/<repo>` (default: `github:poli-page/templates`)
160
+ - `--source <repo>` — source repo, format `github:<owner>/<repo>` (default: `github:poli-page/templates`); `<owner>` and `<repo>` are each one name of letters, digits, `.`, `_` and `-`, not `.` or `..`
161
+ A source's collection and template names, and the `template`, `mock`, `fonts[].src` and `images[]` paths of its template manifests, must be relative paths of letters, digits, `.`, `_` and `-` segments (no `..`, no leading `.` or `/`); the first one that is not refuses the whole import before anything is written. No imported file is written outside the project or the cache, including through a symlink that is there when the import starts, and no file of the project (the template files, fonts, images, `tailwind.css`, the files of `--starter` and its `poli-page.json`) is written through a symlink, even one that stays inside the project: each is written to a temp file and renamed into place; the paths are checked before the writes, so another process changing the project's folders during the import is not covered.
155
162
  - `--no-cache` — bypass the 24-hour template cache
156
163
 
157
164
  ##### `--starter getting-started` — start from your org's getting-started project
@@ -161,7 +168,7 @@ poli init --starter getting-started # writes ./getting-started
161
168
  poli init --starter getting-started my-start # writes ./my-start
162
169
  ```
163
170
 
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`.
171
+ 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
172
 
166
173
  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
174
 
@@ -169,13 +176,13 @@ A non-empty target directory is refused unless you pass `--force`. Then:
169
176
 
170
177
  ```bash
171
178
  cd getting-started
172
- poli watch # live sync of your edits to the cloud draft
173
- poli push # push a new sandbox version
179
+ poli watch # live sync of your edits to the cloud draft
180
+ poli publish --env sandbox # publish the project to the sandbox environment
174
181
  ```
175
182
 
176
183
  and re-run the dashboard snippet to see your change.
177
184
 
178
- Piped, or with `--json`, it prints `{ starter, projectDir, link }` as JSON instead (`link` is `{ status: "linked", orgSlug }` or `{ status: "unlinked", reason }`) and never prompts. `<name>` is one top-level folder of the source (no `/`).
185
+ Piped, or with `--json`, it prints `{ starter, projectDir, link }` as JSON instead (`link` is `{ status: "linked", orgSlug }` or `{ status: "unlinked", reason }`) and never prompts. `<name>` is one top-level folder of the source (no `/`). Every file path in that folder must be made of letters, digits, `.`, `_` and `-` segments (dotfiles allowed, no `.` or `..` segment); the first one that is not refuses the starter before any file is fetched.
179
186
 
180
187
  Flags: `--starter <name>`, `--org <slug>`, `--force`, `--json`, plus `--source` and `--no-cache` as above.
181
188
 
@@ -196,16 +203,19 @@ Flags:
196
203
  - `--from-template <ref>` — collection/template. Skips the interactive prompt.
197
204
  - `--source <repo>` — override the source
198
205
  - `--no-cache` — bypass cache
206
+ - `--format <format>`, `--orientation <orientation>` — set the template's page format and orientation (see [Manifest format](#manifest-format)); an unknown value exits `2` before anything is imported
199
207
 
200
208
  ### Authentication commands
201
209
 
202
210
  #### `poli login`
203
211
 
204
- Opens your browser for the device authorization flow and stores the session token at `~/.polipage/credentials.json`.
212
+ Opens your browser for the device authorization flow and stores the session token at `~/.polipage/credentials`.
213
+
214
+ It first prints the API host it logs into. The browser opens only an `https` page on the API's own site (`poli.page` or a subdomain; a local page when the API is local): any other verification URL the API sends is printed, not opened, and login exits `3`. The API URL is stored in the credentials file only when you chose it: `--api-url`, your own `POLI_API_URL`, or the `apiUrl` an earlier login stored. A `poli-page.json` `cloud.apiUrl` is never stored.
205
215
 
206
216
  #### `poli logout`
207
217
 
208
- Clears the local credentials file.
218
+ Deletes the local credentials file, then revokes the session it held on the API origin that issued it (`POST /api/auth/sign-out`), so the file is gone even if the revoke hangs or is interrupted. If the revoke fails (network error, API error, an origin the CLI does not trust), a warning says the session stays valid until it expires; the exit code is `0` either way. If the file cannot be deleted (for example a read-only `~/.polipage`), the CLI still tries to revoke the session (a failed revoke gets the same warning), an error asks you to delete the file by hand, and the exit code is `6`.
209
219
 
210
220
  #### `poli whoami`
211
221
 
@@ -214,7 +224,7 @@ Displays the active identity and organization. Calls `GET /v1/me` over hybrid au
214
224
  ```bash
215
225
  # Inside a linked project (session)
216
226
  $ poli whoami
217
- xavier@example.com @ acme (session)
227
+ xavier@example.com @ acme (session, role=owner)
218
228
 
219
229
  # Anywhere — fallback when no project is linked, lists the orgs the session can see
220
230
  $ poli whoami
@@ -224,6 +234,10 @@ xavier@example.com (session, 2 organizations: acme, demo-corp)
224
234
  # Programmatic (API key)
225
235
  $ POLI_PAGE_API_KEY=pp_live_xxx poli whoami
226
236
  pp_live_xxx…abcd @ acme (api-key, environment=live)
237
+
238
+ # A service key also shows its role (a session shows the member's role)
239
+ $ POLI_PAGE_API_KEY=pp_staging_xxx poli whoami
240
+ pp_staging_xxx…abcd @ acme (api-key, environment=staging, role=admin)
227
241
  ```
228
242
 
229
243
  Flag: `--json` to dump the raw `/v1/me` payload (or, in `session-no-org` mode, `{ mode, user, orgs }`).
@@ -232,15 +246,31 @@ Flag: `--json` to dump the raw `/v1/me` payload (or, in `session-no-org` mode, `
232
246
 
233
247
  #### `poli link`
234
248
 
235
- 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.
249
+ Pick 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. It also records the folder as a [confirmed link](#confirmed-links) on this machine, so `poli watch` and `poli dev` sync it without asking.
250
+
251
+ The organization is the one `--org <slug>` names; an unknown or empty slug fails with exit `2`, listing your organizations. Without `--org`, an account with a single organization uses it, and one with several asks in a terminal; when it cannot ask (stdin or stdout not a TTY, e.g. in CI or a script), it exits `2`, listing the slugs, and tells you to pass `--org <slug>`.
252
+
253
+ ```bash
254
+ poli link --org acme
255
+ ```
256
+
257
+ When the organization already has a project whose slug is the kebab-cased `project.name` (say, a teammate's), `poli link` links to it instead of creating one, and every later sync overwrites that project's draft. So it first names the project and organization and asks; a no leaves the folder unlinked (exit `1`). When it cannot ask (stdin or stdout not a TTY, e.g. its output piped), it refuses with exit `2` and writes nothing, unless you pass `--existing`, which links to that project without asking. In a script, pass both: `poli link --org <slug> --existing`. `poli init --starter` is not affected: it links only to the organization's existing starter project.
258
+
259
+ The new cloud project is created from the files [`poli publish`](#poli-publish) would send (regular files only, never a symlink), restricted to the templates and mocks the manifest names, `tailwind.css`, the image files under `assets/images/` and `assets/icons/` and the font files under `assets/fonts/`; partials and other files reach the project on the first sync or publish. A template or mock file the manifest names that is not in that set (missing, symlinked, outside `templates/<name>/`, or under a `node_modules`, `.git`, `output`, `dist` or `.poli` folder, e.g. a template named `output`) fails the link before the project is created.
260
+
261
+ #### Confirmed links
262
+
263
+ A `cloud:` block can come with a cloned repository, and every sync overwrites the cloud draft of the project it names. So `poli watch` and `poli dev` sync only a folder whose link you confirmed on this machine. The confirmed links are kept per user in `~/.polipage/links.json` (mode `0600`), keyed by the folder's real path and the project id; `poli link` and `poli init --starter` (when it links) write them, `poli unlink` removes the folder's. The first time you run `poli watch` or `poli dev` in a folder that is not there, or whose `projectId` changed, the command names the organization and project and asks once; a yes is recorded, a no stops the command before any sync. Without a terminal to ask in (stdin or stdout not a TTY), it refuses with exit `2`.
264
+
265
+ Before syncing, `poli watch` and `poli dev` also check with the API that the manifest's `orgSlug`, `orgId`, `projectId` and `projectSlug` all name the same project (sync writes to `projectId` in the `orgSlug` organization; render and publish address `projectSlug` with `orgId`). A manifest whose ids disagree, or whose `orgSlug` names none of your organizations, is refused before any write (exit `6`); `poli publish` with a session refuses it too.
236
266
 
237
267
  #### `poli unlink`
238
268
 
239
- Removes the `cloud:` section from `poli-page.json`. Local files are preserved.
269
+ Removes the `cloud:` section from `poli-page.json`, even one whose ids are invalid, and forgets the folder's [confirmed link](#confirmed-links), so a `cloud:` block that comes back later (a pull, a checkout) is asked about again. Local files are preserved.
240
270
 
241
271
  #### `poli watch`
242
272
 
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`.
273
+ 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
274
 
245
275
  ```bash
246
276
  poli watch
@@ -252,7 +282,7 @@ Resilience built in:
252
282
  - `503 ORGANIZATION_MIGRATING` → 5-second retry
253
283
  - Other API errors → logged, watch continues, next save retries
254
284
 
255
- Requires a TTY. Refused with exit `2` when run in a non-interactive context. If
285
+ Requires a TTY. Refused with exit `2` when run in a non-interactive context. Syncs only a [confirmed link](#confirmed-links): the first run in a cloned folder asks first. If
256
286
  you need the same sync inside a script or alongside a browser preview, use
257
287
  [`poli dev`](#poli-dev-template), which has no TTY requirement.
258
288
 
@@ -260,10 +290,13 @@ you need the same sync inside a script or alongside a browser preview, use
260
290
 
261
291
  #### `poli dev [template]`
262
292
 
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.
293
+ Live PDF preview server for template authors. On every save it syncs the
294
+ project to the cloud draft, renders the active template's draft to PDF through
295
+ `POST /v1/render/draft` with your signed-in session, and pushes a reload to every
296
+ connected browser over Server-Sent Events — no polling, no fixed delay. Draft
297
+ renders are session-only: they carry no watermark, are never stored as a
298
+ document, and are not counted. `POLI_PAGE_API_KEY` plays no part: an API key
299
+ cannot render the draft.
267
300
 
268
301
  ```bash
269
302
  poli dev # first template in the manifest
@@ -276,7 +309,7 @@ poli dev -d ./big.json # render every template against your own data
276
309
  | Flag | Default | Meaning |
277
310
  | -------------------- | ------------------ | ---------------------------------------------------------- |
278
311
  | `-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`. |
312
+ | `-d, --data <path>` | the template mock | JSON data file, same shape as `poli render -d`; saving it re-renders when it is inside the project. |
280
313
  | `--no-open` | opens the browser | Skip launching a browser on start. |
281
314
  | `[template]` | first in manifest | Which template to show first. |
282
315
 
@@ -290,13 +323,12 @@ The served page gives you:
290
323
  moves nothing: the current template stays on screen and is re-rendered.
291
324
  - **A pin.** Click *Pin* to freeze the view on the current template so an
292
325
  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`.
326
+ - **The real PDF.** Every render is the actual PDF of the draft — pagination,
327
+ page breaks, fonts — shown in the browser's PDF viewer and reloaded after each
328
+ successful sync. There is no separate HTML preview mode.
297
329
  - **An error overlay.** A failed compile or render is shown with its message
298
330
  (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
331
+ good PDF, which stays visible behind it. A render error clears on the next
300
332
  successful render; a failed sync stays shown until a sync succeeds, even when
301
333
  a render succeeds in between (the cloud draft is still out of date).
302
334
 
@@ -309,8 +341,14 @@ Notes:
309
341
  { "scripts": { "dev": "concurrently \"poli dev --no-open\" \"vite\"" } }
310
342
  ```
311
343
 
344
+ - It syncs only a [confirmed link](#confirmed-links). In a terminal the first
345
+ run in a cloned folder asks first; piped, an unconfirmed folder is refused
346
+ with exit `2`: run `poli dev` once in a terminal, or `poli unlink`, then `poli link`.
312
347
  - It binds to `127.0.0.1` only — the rendered draft is never exposed to the
313
348
  local network.
349
+ - Only its own page can change the view: a `POST` from another site (or from
350
+ any client that sends neither `Sec-Fetch-Site: same-origin` nor the server's
351
+ own `Origin`) gets a `403`, and no other site can frame the page.
314
352
  - On start it pushes the whole working tree to the draft, so the first render
315
353
  reflects your local files rather than whatever the draft last contained.
316
354
  - Failures are surfaced, not fatal: a render that errors, a rejected sync, a
@@ -319,122 +357,144 @@ Notes:
319
357
  - `Ctrl-C` (or `SIGTERM`) closes the watcher, every SSE connection, and the
320
358
  port.
321
359
 
322
- ### Versioning
323
-
324
- #### `poli push`
360
+ ### Environments
325
361
 
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):
362
+ #### `poli publish`
327
363
 
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.
364
+ Publishes the local project, the files on disk, to an environment of your organization: `POST /v1/projects/<projectSlug>/publish`, with a service key in `POLI_PAGE_API_KEY` when one is set (see below), or else with your `poli login` session and the manifest's `cloud.orgId`; with a session, a manifest whose `cloud` ids do not all name the same project is refused before the upload (exit `6`, see [confirmed links](#confirmed-links)). 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
365
 
331
366
  ```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)
367
+ poli publish --env sandbox
368
+ poli publish --env live -m "Invoice footer fix"
369
+ poli publish --env live --yes # protected environment, no prompt (scripts)
337
370
  ```
338
371
 
339
- > An explicit positional version is mutually exclusive with `--patch` / `--minor` / `--major` and with `--track`.
372
+ | Flag | Meaning |
373
+ | ---------------------- | ----------------------------------------------------------------------------------------- |
374
+ | `--env <name>` | Required. The target environment; there is no default, and `draft` is not an environment. |
375
+ | `-m, --message <text>` | Kept in the publish log with the date, author and bundle hash. 500 characters at most. |
376
+ | `-y, --yes` | Publish to a protected environment without the confirmation prompt. |
377
+ | `--json` | Print the API response as JSON (also the default when stdout is not a TTY). |
378
+
379
+ - **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`).
380
+ - **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/`, the `.png`, `.jpg`, `.jpeg`, `.gif`, `.webp` and `.svg` files under `assets/images/` and `assets/icons/` (the image types the engine renders), and the `.woff2`, `.woff`, `.ttf` and `.otf` files under `assets/fonts/`, extensions in any letter case. Anything else (`.gitignore`, `README.md`, `*.log`, `.DS_Store`) is left out, a file of another type under `assets/images/` or `assets/icons/` with a warning that names it (but not `.gitkeep`, `.keep`, `.DS_Store`, `Thumbs.db` or `desktop.ini`), and so is every `node_modules/`, `.git/`, `output/`, `dist/` and `.poli/` directory at any depth. 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`).
381
+ - **Limits.** Only `poli-page.json`, `tailwind.css`, `templates/`, `partials/` and `assets/` are walked, and every file's size is checked before any is read. A file over 4 MiB, more than 1000 files, or files adding up to more than 5 MiB fail the command before any call, naming the file or the limit (exit `2`); nothing is sent. These are the API's limits, and `poli link`, `poli watch` and `poli dev` apply them too.
382
+ - **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`. `CI=true` does not stand in for `--yes`. Without the role, the API refuses with `ENVIRONMENT_PROTECTED` (exit `5`).
383
+ - **With a service key** (`POLI_PAGE_API_KEY`; the key wins over a `poli login` session 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`). When the manifest has a `cloud.orgId`, the key must belong to that organization (the one `GET /v1/me` names), or the publish is refused before any upload, naming both organizations (exit `2`): the key would otherwise publish to a project of the same slug in its own organization. A standard key is refused with "Standard API keys can only render. Use a service key or `poli login`." (exit `5`); with a session stored, the standard-key, `--env` and organization refusals all say to unset `POLI_PAGE_API_KEY` to use the session instead. 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`).
384
+ - **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.
385
+
386
+ On success it prints the environment, the project, the short bundle hash, the file count, the publish log id and the credential used (`POLI_PAGE_API_KEY` or `session (poli login)`).
387
+
388
+ #### `poli env list`
340
389
 
341
- **Hotfix flow** — 1.0.1 LIVE in prod, 2.0.0 SANDBOX in dev:
390
+ Lists your organization's environments, with your `poli login` session (any member of the organization can run it).
342
391
 
343
392
  ```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
393
+ poli env list # in a linked folder: the project's state in each environment
394
+ poli env list --org acme # elsewhere, or for another organization
395
+ poli env list --json
348
396
  ```
349
397
 
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).
398
+ | Flag | Meaning |
399
+ | -------------- | ------------------------------------------------------------------------------------------- |
400
+ | `--org <slug>` | The organization to list. Default: the linked project's organization, else your only one. |
401
+ | `--json` | Print the API response as JSON (also the default when stdout is not a TTY). |
351
402
 
352
- #### `poli versions list` (alias `ls`)
403
+ 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.
353
404
 
354
- Display all versions of the linked project with their state badges.
355
-
356
- ```
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
405
  ```
406
+ Environments of acme, project invoices:
363
407
 
364
- #### `poli promote <version>`
408
+ ENVIRONMENT PROTECTED READ-ONLY PUBLISHED LAST PUBLISH
409
+ sandbox no no yes succeeded 2026-10-26 10:00 UTC Ada Lovelace 0123456789ab Invoice footer fix
410
+ live yes no no not published
411
+ ```
365
412
 
366
- Move a SANDBOX version to LIVE. Confirmation prompt unless `--yes`.
413
+ 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
414
 
368
- #### `poli unpromote <version>`
415
+ #### `poli env remove-project <environment>`
369
416
 
370
- Move a LIVE version back to SANDBOX. Shows a usage preview (calls in the last 24h, the next-latest LIVE) before confirming.
417
+ 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
418
 
372
419
  ```bash
373
- poli unpromote 1.0.5
374
- poli unpromote 1.0.5 --force # allow unpromoting the last LIVE version
420
+ poli env remove-project staging # asks you to type the project slug
421
+ poli env remove-project staging --yes # scripts: no prompt
375
422
  ```
376
423
 
377
- #### `poli versions deprecate <version>`
378
-
379
- Mark a SANDBOX version as DEPRECATED.
380
-
381
- #### `poli versions un-deprecate <version>`
424
+ | Flag | Meaning |
425
+ | ----------- | ---------------------------------------------------------------------------------- |
426
+ | `-y, --yes` | Remove without typing the project slug to confirm. |
427
+ | `--json` | Print `{ org, project, environment }` (also the default when stdout is not a TTY). |
382
428
 
383
- Move a DEPRECATED version back to SANDBOX.
429
+ - **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.
430
+ - **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
431
 
385
432
  ### Render
386
433
 
387
434
  #### `poli render <spec>`
388
435
 
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.
436
+ 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).
437
+
438
+ - **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.
439
+ - **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
440
 
391
441
  ```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
442
+ poli render invoice # the draft (session), downloads PDF
443
+ poli render invoice@sandbox # what is published in sandbox
444
+ poli render invoice@production --data ./mock.json # an environment + custom data
395
445
  poli render invoice -o ./out/invoice.pdf # custom path
396
- poli render invoice --no-download # JSON descriptor only
446
+ poli render invoice@sandbox --no-download # JSON descriptor only
397
447
  ```
398
448
 
399
449
  Spec rules:
400
450
 
401
451
  - `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.
452
+ - `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
453
 
404
454
  Flags:
405
455
 
406
456
  - `--data <file>` — JSON data overrides the mock
407
- - `-o <file>` — output PDF path. Incompatible with `--no-download`
408
- - `--no-download` — skip the presigned URL fetch (CI/CD pipelines)
457
+ - `-o <file>` — output PDF path. Incompatible with `--no-download`. Without it the PDF goes to `output/<name>/<format-orientation>/<name>.pdf` in the project, which is refused if it is a symlink or resolves outside the project through one; the PDF is written to a temp file and renamed into place. `-o` is written as given
458
+ - `--no-download` — skip the presigned URL fetch (CI/CD pipelines). Environment renders only
409
459
  - `--json` — force JSON output even in a TTY
410
460
 
461
+ 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" }`.
462
+
463
+ Errors:
464
+
465
+ - `404 PROJECT_NOT_IN_ENVIRONMENT` — the project was never published there: run `poli publish --env <environment>`. Exit code `2`.
466
+ - `404 ENVIRONMENT_NOT_FOUND` / `404 TEMPLATE_NOT_FOUND` — the environment does not exist, or the published copy has no such template. Exit code `2`.
467
+ - `503 PUBLISH_IN_PROGRESS` — a publish of that project and environment is running: the CLI waits `Retry-After` and retries once, then exits `3`.
468
+
411
469
  [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
470
 
413
471
  ```bash
414
- $ DOC_ID=$(poli render invoice | jq -r '.documentId')
472
+ $ DOC_ID=$(poli render invoice@sandbox | jq -r '.documentId')
415
473
  $ poli documents thumbnails "$DOC_ID" --width 400
416
474
  ```
417
475
 
418
- Resolved environment is exposed in the success line (TTY):
476
+ The success line (TTY) names what was rendered, and says `billed` when the render counts:
419
477
 
420
478
  ```
421
- ✓ Rendered invoice v1.0.5 (live, billed) → ./output/invoice/invoice.pdf
422
- ✓ Rendered invoice vdraft (sandbox) → ./output/invoice/invoice.pdf
479
+ ✓ Rendered invoice@production (billed) → ./output/invoice/a4-portrait/invoice.pdf
480
+ ✓ Rendered invoice@sandbox → ./output/invoice/a4-portrait/invoice.pdf
481
+ ✓ Rendered invoice@draft → ./output/invoice/a4-portrait/invoice.pdf
423
482
  ```
424
483
 
425
484
  Counter:
426
- - `version: draft` or `X.Y.Z` SANDBOX/DEPRECATED → unmetered
427
- - `version: X.Y.Z` LIVE → counts in monthly quota
485
+ - the draft → never counted
486
+ - `sandbox` → free, never counted (and the only watermarked environment)
487
+ - every other environment → counts in the monthly quota
428
488
 
429
489
  ### Documents
430
490
 
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.
491
+ 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
492
 
433
493
  There is intentionally **no `poli documents list`** — your application is responsible for tracking the `documentId` values it cares about.
434
494
 
435
495
  #### `poli documents get <id>`
436
496
 
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.
497
+ 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
498
 
439
499
  ```bash
440
500
  poli documents get doc_abc123
@@ -457,9 +517,11 @@ poli documents thumbnails doc_abc123 -o ./out
457
517
 
458
518
  Flags: `-w/--width`, `-f/--format png|jpeg`, `-q/--quality`, `--pages 1,3`, `-o/--output`, `--json`.
459
519
 
520
+ The default folder is `./output/thumbnails/<id>/`, with `page-<n>.<ext>` files. The `<id>` must be letters, digits, `.`, `_` and `-`, starting with a letter or digit, without `..`; another one is refused before any request (exit `2`). A page number from the API that is not a positive integer refuses the whole set before anything is written. A default file that is a symlink, or resolves outside the current directory through one, refuses the whole set before any page is written; `-o` is written as given.
521
+
460
522
  #### `poli documents preview <id>`
461
523
 
462
- 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.
524
+ 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: the `<id>` is checked as for `thumbnails` before any request, and that file is refused if it is a symlink or resolves outside the current directory through one (`-o` is written as given). The written file carries a Content-Security-Policy meta that blocks scripts, network loads, form submissions and `<base>` (inline styles and `data:` images and fonts still render; a `<meta http-equiv="refresh">` in the HTML can still navigate away, which CSP cannot block; a second meta turns off DNS prefetching of hyperlinks, which CSP does not cover, but a `<link rel="dns-prefetch">` can still resolve its hostname); `--json` prints the HTML as received.
463
525
 
464
526
  ```bash
465
527
  poli documents preview doc_abc123
@@ -476,8 +538,7 @@ poli documents preview doc_abc123 -o ./preview.html
476
538
  ```jsonc
477
539
  {
478
540
  "project": {
479
- "name": "my-invoices",
480
- "version": "1.0.0"
541
+ "name": "my-invoices"
481
542
  },
482
543
  "fonts": [
483
544
  {
@@ -489,8 +550,8 @@ poli documents preview doc_abc123 -o ./preview.html
489
550
  "templates": [
490
551
  {
491
552
  "name": "invoice",
492
- "template": "templates/invoice/invoice.html",
493
- "mock": "templates/invoice/invoice.json",
553
+ "template": "invoice.html",
554
+ "mock": "invoice.json",
494
555
  "format": "A4",
495
556
  "orientation": "portrait"
496
557
  }
@@ -504,8 +565,19 @@ poli documents preview doc_abc123 -o ./preview.html
504
565
  }
505
566
  ```
506
567
 
568
+ Each `templates[]` entry is checked when the manifest is read, and a bad value fails with the field it is in (`templates[0].mock: …`):
569
+
570
+ - `name` — the template's folder under `templates/`: lowercase letters, digits and inner `-`.
571
+ - `template`, `mock` — paths relative to `templates/<name>/`, made of segments of letters, digits, `.`, `_` and `-`, each starting with a letter or digit (no `..`, absolute path, `\`, `?`, `#` or `%`). The files are read only when they resolve inside the project, symlinks included.
572
+ - `format` (default `A4`) — one of `A3`, `A4`, `A5`, `A6`, `B4`, `B5`, `Letter`, `Legal`, `Tabloid`, `Statement`, `Executive`, `Folio`, in any letter case.
573
+ - `orientation` (default `portrait`) — `portrait` or `landscape`, in any letter case.
574
+
507
575
  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
576
 
577
+ `cloud.orgId` and `cloud.projectId` must be UUIDs (8-4-4-4-12 hex digits): any other value makes the manifest invalid (`Invalid poli-page.json — cloud.projectId: must be a UUID`, from every command that reads it), so a hand-edited id cannot change the API path the CLI calls with your session. `poli unlink` still removes such a block, and `poli init --starter` ignores the starter's own `cloud:` block. A `cloud.projectSlug` of `.` or `..` is refused by `poli publish` (`Invalid project ID.`).
578
+
579
+ 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`).
580
+
509
581
  ---
510
582
 
511
583
  ## Configuration
@@ -514,22 +586,23 @@ The `cloud:` block is written by `poli link`, removed by `poli unlink`. **No API
514
586
 
515
587
  | Variable | Effect |
516
588
  | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
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. |
518
- | `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. |
589
+ | `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 key wins for `whoami`, `publish`, `render` and `documents`. |
590
+ | `POLI_API_URL` | Override the API base URL (precedence: `--api-url` flag → `POLI_API_URL` → `poli-page.json` `cloud.apiUrl`, when allowed (see below) → `~/.polipage/credentials` `apiUrl` → default `https://api.poli.page`). The URL must be an origin only (no user, path, query or hash) on `https://poli.page` or `https://*.poli.page`; anything else exits `2` before any request. `poli-page.json` `cloud.apiUrl` is ignored, with a warning, unless it equals the stored `apiUrl` or the default: a cloned folder cannot choose where your credentials go. A session is only sent to the API origin that issued it; log in again to use another one. |
591
+ | `POLI_ALLOW_INSECURE_API` | Set to `1` to allow a local API URL (`http://localhost`, `http://127.0.0.1`), like `--allow-insecure-api`. |
520
592
  | `NO_COLOR` | Disable ANSI colors (Unix standard). |
521
- | `CI` | Auto-detected; equivalent to a global `--yes`. |
593
+ | `CI` | Not read. `CI=true` is not consent: without a TTY, a prompt needs `--yes`. |
522
594
 
523
595
  ### Common flags
524
596
 
525
- - `--api-url <url>` — override the API base URL for one invocation
597
+ - `--api-url <url>` — override the API base URL for one invocation (a Poli Page origin; see `POLI_API_URL`)
598
+ - `--allow-insecure-api` — allow a local API URL (`localhost`, `127.0.0.1`) for one invocation
526
599
  - `-y` / `--yes` — skip confirmation prompts
527
600
  - `-h` / `--help` — show help for any command or sub-command
528
601
  - `-v` / `--version` — print the CLI version and exit
529
602
 
530
603
  ### Output conventions
531
604
 
532
- Every command that returns a payload (renders, descriptors, lists, version mutations) follows the same output rule:
605
+ Every command that returns a payload (renders, descriptors, publishes) follows the same output rule:
533
606
 
534
607
  | Context | Stdout |
535
608
  | ------- | ------ |
@@ -539,7 +612,7 @@ Every command that returns a payload (renders, descriptors, lists, version mutat
539
612
 
540
613
  Either the summary **or** the JSON — never both at once. Errors always go to stderr with a clear message.
541
614
 
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`.
615
+ Commands that take this contract: `render`, `documents get`, `documents preview`, `documents thumbnails`, `whoami`, `publish`, `env list`, `env remove-project`, `init --starter`.
543
616
 
544
617
  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
618
 
@@ -549,13 +622,13 @@ Imperative commands (`init` without `--starter`, `new`, `link`, `unlink`, `logou
549
622
 
550
623
  | Code | Meaning |
551
624
  | ---- | ------------------------------------------------------------------------------------------------------ |
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) |
625
+ | `0` | Success |
626
+ | `1` | Recoverable inconsistency (already logged in, already linked) |
627
+ | `2` | Invalid usage (bad args, template not found, project not published in that environment, non-TTY context where TTY is required) |
555
628
  | `3` | Network / API error (timeout, 5xx, unspecified 4xx) |
556
- | `4` | Not authenticated — run `poli login` or set `POLI_PAGE_API_KEY` |
557
- | `5` | Not authorized (insufficient role, `THUMBNAILS_NOT_AVAILABLE`, system project locked) |
558
- | `6` | Invalid local state (no project, project not linked, empty folder where required) |
629
+ | `4` | Not authenticated: run `poli login` or set `POLI_PAGE_API_KEY`; or the API answered `MISSING_API_KEY`, `INVALID_API_KEY` or `API_KEY_EXPIRED` |
630
+ | `5` | Not authorized (insufficient role, protected environment, `PROJECT_OUT_OF_SCOPE`, `THUMBNAILS_NOT_AVAILABLE`) |
631
+ | `6` | Invalid local state (no project, invalid `poli-page.json`, project not linked, empty folder where required) |
559
632
 
560
633
  These map to the centralised `ExitCode` constants in `src/exit-codes.ts`. Every handler routes errors through `errorToExitCode(err)`.
561
634
 
@@ -563,6 +636,32 @@ These map to the centralised `ExitCode` constants in `src/exit-codes.ts`. Every
563
636
 
564
637
  ## CI / CD
565
638
 
639
+ ### Publish from CI with a service key
640
+
641
+ ```yaml
642
+ # .github/workflows/publish.yml
643
+ name: Publish templates
644
+
645
+ on:
646
+ push:
647
+ branches: [main]
648
+
649
+ jobs:
650
+ publish:
651
+ runs-on: ubuntu-latest
652
+ env:
653
+ POLI_PAGE_API_KEY: ${{ secrets.POLI_PAGE_SERVICE_KEY }} # a service key for `live`
654
+ steps:
655
+ - uses: actions/checkout@v4
656
+ - uses: actions/setup-node@v4
657
+ with:
658
+ node-version: '22'
659
+ - run: npm install -g @poli-page/cli
660
+ - run: poli publish --env live -m "Deploy ${{ github.sha }}"
661
+ ```
662
+
663
+ 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.
664
+
566
665
  ### GitHub Actions
567
666
 
568
667
  ```yaml
@@ -582,14 +681,14 @@ jobs:
582
681
  with:
583
682
  node-version: '22'
584
683
  - run: npm install -g @poli-page/cli
585
- - run: poli render invoice@1.0.5 -o ./artifacts/invoice.pdf
684
+ - run: poli render invoice@live -o ./artifacts/invoice.pdf
586
685
  - uses: actions/upload-artifact@v4
587
686
  with:
588
687
  name: invoice-pdf
589
688
  path: ./artifacts/invoice.pdf
590
689
  ```
591
690
 
592
- Recommended: use a **service account key** (`pp_sa_live_*`) so rotating it does not log out any developer.
691
+ 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
692
 
594
693
  ### GitLab CI
595
694
 
@@ -600,7 +699,7 @@ render:
600
699
  POLI_PAGE_API_KEY: $POLI_PAGE_API_KEY
601
700
  script:
602
701
  - npm install -g @poli-page/cli
603
- - poli render invoice@1.0.5 -o invoice.pdf
702
+ - poli render invoice@live -o invoice.pdf
604
703
  artifacts:
605
704
  paths:
606
705
  - invoice.pdf
@@ -611,10 +710,10 @@ render:
611
710
  ```bash
612
711
  # In a build script
613
712
  npm install -g @poli-page/cli
614
- POLI_PAGE_API_KEY=pp_sa_live_xxx poli render homepage-pdf -o ./public/welcome.pdf
713
+ POLI_PAGE_API_KEY=pp_live_xxx poli render homepage-pdf@live -o ./public/welcome.pdf
615
714
  ```
616
715
 
617
- Service accounts have a **fixed role and environment** at creation. The CLI does not try to switch them — the API enforces the permissions.
716
+ 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
717
 
619
718
  ---
620
719
 
@@ -624,17 +723,75 @@ Service accounts have a **fixed role and environment** at creation. The CLI does
624
723
 
625
724
  Either run `poli login` interactively, or export `POLI_PAGE_API_KEY` for CI use. Exit code `4`.
626
725
 
627
- ### `POLI_PAGE_API_KEY must start with \`pp_\`...`
726
+ ### `POLI_PAGE_API_KEY must be a Poli Page API key: \`pp_<environment>_…\`...`
727
+
728
+ 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. If you are logged in, the key wins over your session while it is set, so a malformed key is refused even then (the message then says so): fix it, or unset `POLI_PAGE_API_KEY` to use the session. Exit code `4`.
729
+
730
+ ### `Standard API keys can only render. Use a service key or \`poli login\`.`
731
+
732
+ `poli publish` with `POLI_PAGE_API_KEY` set to a standard key. Only a service key, or a `poli login` session, can publish. If you are already logged in, the key wins over your session while it is set (the message then says so): unset `POLI_PAGE_API_KEY` to publish with the session. Exit code `5`.
733
+
734
+ ### `This service key publishes to "<a>" only, not "<b>"...`
735
+
736
+ A service key publishes into its own environment only. Pass `--env <a>`, or use a service key for `<b>`. If you are logged in, the key wins over your session while it is set (the message then says so): unset `POLI_PAGE_API_KEY` to publish with the session. Exit code `2`.
737
+
738
+ ### `This API key belongs to organization "<name>" (<slug>, <id>), but this folder is linked to organization "<slug>" (<id>)...`
739
+
740
+ `poli publish` with `POLI_PAGE_API_KEY` set to a key of another organization than the manifest's `cloud.orgId`. Since a key publishes to `cloud.projectSlug` in its own organization, the CLI refuses before any upload rather than publish to a same-slug project there. Use a service key of the linked organization, or, if the folder belongs to the key's organization, run `poli unlink`, then `poli link`. If you are logged in to the linked organization, the key wins over your session while it is set (the message then says so): unset `POLI_PAGE_API_KEY` to publish with the session. Exit code `2`.
741
+
742
+ ### `Not authenticated: your session has expired or no API key was sent. Run \`poli login\`, or set POLI_PAGE_API_KEY...`
743
+
744
+ The API answered `MISSING_API_KEY`: it received no valid credential. Either your `poli login` session has expired (run `poli login` again), or no API key was sent (create a key on the dashboard's API keys page and export it as `POLI_PAGE_API_KEY`). Exit code `4`.
745
+
746
+ ### `This API key is not valid: it is unknown or was revoked, its environment was deleted, or its service account was disabled or deleted...`
747
+
748
+ The API does not accept the key (`INVALID_API_KEY`): it never existed, it was revoked, its environment was deleted, or its service account was disabled or deleted. Create a new key on the dashboard's API keys page and update `POLI_PAGE_API_KEY`. Exit code `4`.
628
749
 
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`.
750
+ ### `Your API key has expired. Create a new one in the dashboard (API keys) and update POLI_PAGE_API_KEY.`
751
+
752
+ The key passed its expiry date (`API_KEY_EXPIRED`). Create a new key on the dashboard's API keys page and update `POLI_PAGE_API_KEY`. Exit code `4`.
753
+
754
+ ### `This API key is restricted to other projects. Use a key that includes this project, or create one in the dashboard (API keys).`
755
+
756
+ The key is limited to some projects and this folder's project is not one of them (`PROJECT_OUT_OF_SCOPE`). Use a key that includes the project, or create one on the dashboard's API keys page. Exit code `5`.
630
757
 
631
758
  ### `This folder isn't linked to a cloud project. Run \`poli link\` first.`
632
759
 
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`.
760
+ 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`.
761
+
762
+ ### `This folder is linked to project "<name>" (<slug>) of organization "<name>" (<slug>), a link you have not confirmed on this machine...`
763
+
764
+ `poli watch` or `poli dev` found a `cloud:` block (from a clone, say) that is not in your `~/.polipage/links.json`, and had no terminal to ask in. Run the command once in a terminal and answer yes, or run `poli unlink`, then `poli link`. Exit code `2`. See [confirmed links](#confirmed-links).
765
+
766
+ ### `The cloud block of poli-page.json names more than one project: ...`
767
+
768
+ The manifest's `orgSlug`, `orgId`, `projectId` and `projectSlug` do not all name the same project, so sync and publish would write to different ones. The message names the id that disagrees. Run `poli unlink`, then `poli link`. Exit code `6`.
769
+
770
+ ### `API keys render a published environment: use \`name@<environment>\``
771
+
772
+ `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>`. If you are logged in, the key wins over your session while it is set (the message then says so): unset `POLI_PAGE_API_KEY` to render the draft. Exit code `2`.
773
+
774
+ ### `This API key renders the \`<a>\` environment, not \`<b>\``
634
775
 
635
- ### `\`latest\` was retired. Run \`poli versions list\` and pin an exact semver...`
776
+ A key renders only the environment in its prefix. Render `name@<a>`, or use a key for `<b>`. If you are logged in, the key wins over your session while it is set (the message then says so): unset `POLI_PAGE_API_KEY` to render `<b>` with the session. Exit code `2`.
636
777
 
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`.
778
+ ### `\`invoice@1.2.3\`: templates no longer have versions...`
779
+
780
+ Render specs name an environment, not a version: `poli render invoice@<environment>`, or `poli render invoice` for the draft. Exit code `2`.
781
+
782
+ ### `403 DRAFT_REQUIRES_SESSION`
783
+
784
+ 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`.
785
+
786
+ ### `Environment "<env>" is protected...` (`403 ENVIRONMENT_PROTECTED`)
787
+
788
+ `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`.
789
+
790
+ 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` does not count as `--yes`). Exit code `2`.
791
+
792
+ ### `PUBLISH_IN_PROGRESS`
793
+
794
+ 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
795
 
639
796
  ### `403 THUMBNAILS_NOT_AVAILABLE`
640
797
 
@@ -642,7 +799,7 @@ Thumbnails via `poli documents thumbnails` are a paid-tier feature. Upgrade to S
642
799
 
643
800
  ### `429 OVERAGE_CAP_EXCEEDED`
644
801
 
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`.
802
+ 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
803
 
647
804
  ### `503 ORGANIZATION_MIGRATING`
648
805
 
@@ -650,11 +807,7 @@ Your org is being migrated to a new tier. `poli watch` retries automatically aft
650
807
 
651
808
  ### `poli watch` doesn't fire on save
652
809
 
653
- 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
-
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.
810
+ Make sure the file is in the project file set, as [`poli publish`](#poli-publish) defines the bundle (only some file types count under each folder, e.g. `templates/<slug>/logo.svg` does not): no other file triggers a sync, except the `poli dev --data` file. The watcher does not follow symlinks: a file reached through a symlinked directory is not watched. 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.
658
811
 
659
812
  ---
660
813