@poli-page/cli 0.11.0 → 0.12.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.
- package/README.md +91 -30
- package/dist/api-client.d.ts +42 -2
- package/dist/api-client.d.ts.map +1 -1
- package/dist/api-client.js +117 -4
- package/dist/api-client.js.map +1 -1
- package/dist/cloud-context.d.ts +1 -1
- package/dist/cloud-context.js +1 -1
- package/dist/commands/clone.d.ts +32 -0
- package/dist/commands/clone.d.ts.map +1 -0
- package/dist/commands/clone.js +266 -0
- package/dist/commands/clone.js.map +1 -0
- package/dist/commands/dev.d.ts +55 -3
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +307 -46
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +8 -8
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/link.d.ts +9 -0
- package/dist/commands/link.d.ts.map +1 -1
- package/dist/commands/link.js +25 -10
- package/dist/commands/link.js.map +1 -1
- package/dist/commands/new.d.ts.map +1 -1
- package/dist/commands/new.js +1 -7
- package/dist/commands/new.js.map +1 -1
- package/dist/commands/publish.js +1 -1
- package/dist/commands/publish.js.map +1 -1
- package/dist/commands/sync.d.ts +52 -0
- package/dist/commands/sync.d.ts.map +1 -0
- package/dist/commands/sync.js +224 -0
- package/dist/commands/sync.js.map +1 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +1 -0
- package/dist/constants.js.map +1 -1
- package/dist/credentials.d.ts +6 -1
- package/dist/credentials.d.ts.map +1 -1
- package/dist/credentials.js +28 -10
- package/dist/credentials.js.map +1 -1
- package/dist/dev-page.d.ts.map +1 -1
- package/dist/dev-page.js +24 -0
- package/dist/dev-page.js.map +1 -1
- package/dist/draft-bases.d.ts +54 -0
- package/dist/draft-bases.d.ts.map +1 -0
- package/dist/draft-bases.js +253 -0
- package/dist/draft-bases.js.map +1 -0
- package/dist/draft-files.d.ts +96 -0
- package/dist/draft-files.d.ts.map +1 -0
- package/dist/draft-files.js +447 -0
- package/dist/draft-files.js.map +1 -0
- package/dist/exit-codes.d.ts +3 -1
- package/dist/exit-codes.d.ts.map +1 -1
- package/dist/exit-codes.js +3 -1
- package/dist/exit-codes.js.map +1 -1
- package/dist/program.d.ts.map +1 -1
- package/dist/program.js +6 -3
- package/dist/program.js.map +1 -1
- package/dist/project-files.d.ts +8 -1
- package/dist/project-files.d.ts.map +1 -1
- package/dist/project-files.js +22 -1
- package/dist/project-files.js.map +1 -1
- package/dist/project-sync.d.ts +88 -16
- package/dist/project-sync.d.ts.map +1 -1
- package/dist/project-sync.js +283 -46
- package/dist/project-sync.js.map +1 -1
- package/dist/slug.d.ts +8 -0
- package/dist/slug.d.ts.map +1 -0
- package/dist/slug.js +15 -0
- package/dist/slug.js.map +1 -0
- package/dist/sync-engine.d.ts +14 -9
- package/dist/sync-engine.d.ts.map +1 -1
- package/dist/sync-engine.js +26 -29
- package/dist/sync-engine.js.map +1 -1
- package/package.json +1 -1
- package/dist/commands/watch.d.ts +0 -29
- package/dist/commands/watch.d.ts.map +0 -1
- package/dist/commands/watch.js +0 -108
- package/dist/commands/watch.js.map +0 -1
package/README.md
CHANGED
|
@@ -85,7 +85,8 @@ poli dev
|
|
|
85
85
|
```
|
|
86
86
|
|
|
87
87
|
`poli dev` is the code-first alternative to the desktop editor. If you only want
|
|
88
|
-
the sync half, without a browser, use `poli
|
|
88
|
+
the sync half, without a browser, use `poli dev --no-preview`. To start from a
|
|
89
|
+
project that already exists in the cloud, `poli clone <org>/<project>`.
|
|
89
90
|
|
|
90
91
|
---
|
|
91
92
|
|
|
@@ -126,11 +127,11 @@ Standard keys and service keys share the `pp_<environment>_…` format; the CLI
|
|
|
126
127
|
- a **standard key** renders only. `poli publish` refuses it before any upload (exit `5`).
|
|
127
128
|
- 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
|
|
|
129
|
-
The other workspace commands (`link`, `
|
|
130
|
+
The other workspace commands (`link`, `clone`, `sync`, `dev`) need `poli login`.
|
|
130
131
|
|
|
131
132
|
### Precedence
|
|
132
133
|
|
|
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`, `
|
|
134
|
+
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`, `clone`, `sync`, `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.
|
|
134
135
|
|
|
135
136
|
---
|
|
136
137
|
|
|
@@ -170,13 +171,13 @@ poli init --starter getting-started my-start # writes ./my-start
|
|
|
170
171
|
|
|
171
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.
|
|
172
173
|
|
|
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`).
|
|
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). Linking forgets the folder's [draft bases](#draft-bases), so the first `poli dev` or `poli sync` compares the starter with that project's draft and reports each file that differs as a [conflict](#conflicts) instead of sending the starter over it. 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`).
|
|
174
175
|
|
|
175
176
|
A non-empty target directory is refused unless you pass `--force`. Then:
|
|
176
177
|
|
|
177
178
|
```bash
|
|
178
179
|
cd getting-started
|
|
179
|
-
poli
|
|
180
|
+
poli dev --no-preview # sync each save to the cloud draft
|
|
180
181
|
poli publish --env sandbox # publish the project to the sandbox environment
|
|
181
182
|
```
|
|
182
183
|
|
|
@@ -186,6 +187,26 @@ Piped, or with `--json`, it prints `{ starter, projectDir, link }` as JSON inste
|
|
|
186
187
|
|
|
187
188
|
Flags: `--starter <name>`, `--org <slug>`, `--force`, `--json`, plus `--source` and `--no-cache` as above.
|
|
188
189
|
|
|
190
|
+
#### `poli clone <org>/<project> [dir]`
|
|
191
|
+
|
|
192
|
+
Write the cloud draft of an existing project into a new folder, linked to it and ready for `poli dev`. `<org>` and `<project>` are slugs, as in the editor's URL; `dir` defaults to the project slug.
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
poli clone acme/invoices # writes ./invoices
|
|
196
|
+
poli clone acme/invoices my-invoices # writes ./my-invoices
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
- The target must not exist, or be an empty directory (dot files such as `.git` are allowed). A symbolic link is refused.
|
|
200
|
+
- The target must not be inside a Poli Page project: when its parent folder, or any folder above it, holds a `poli-page.json`, the clone is refused (exit `2`) rather than nesting one project in another. When that project, or the target folder itself, already is a clone of `<org>/<project>`, it says so: run `poli sync` there instead.
|
|
201
|
+
- It needs `poli login` and edit access to the project: a project you can only view exits `5`; one that does not exist or that you cannot see exits `2`.
|
|
202
|
+
- Every path of the draft is checked before anything is written: a path outside the project file set, or one some systems cannot hold (`:`, a reserved name such as `con`, a name ending in `.` or a space), refuses the clone. A draft over 1000 files or 20 MiB is refused too.
|
|
203
|
+
- Every file is downloaded and checked against the size and SHA-256 the draft lists before the first write. Any failure removes what the clone wrote (the folder, when it created it), so you can run it again.
|
|
204
|
+
- A listing it refuses (an unsafe path, over the caps) or a download that fails or does not match exits `3`.
|
|
205
|
+
- The written `poli-page.json` gets the `cloud:` block, the folder is recorded as a [confirmed link](#confirmed-links), and every file gets its [draft base](#draft-bases): `poli dev` syncs it without asking and without overwriting anyone's change.
|
|
206
|
+
- Piped, or with `--json`, it prints `{ dir, orgSlug, projectSlug, files }`.
|
|
207
|
+
|
|
208
|
+
Stopping a clone while it writes the files (Ctrl-C) can leave a partial folder: delete it before you run `poli clone` again.
|
|
209
|
+
|
|
189
210
|
#### `poli new <name>`
|
|
190
211
|
|
|
191
212
|
Create a new template inside an existing project from a remote starter.
|
|
@@ -246,7 +267,7 @@ Flag: `--json` to dump the raw `/v1/me` payload (or, in `session-no-org` mode, `
|
|
|
246
267
|
|
|
247
268
|
#### `poli link`
|
|
248
269
|
|
|
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
|
|
270
|
+
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 dev` and `poli sync` sync it without asking, and forgets the folder's [draft bases](#draft-bases): linking never sends the folder over a draft.
|
|
250
271
|
|
|
251
272
|
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
273
|
|
|
@@ -254,37 +275,69 @@ The organization is the one `--org <slug>` names; an unknown or empty slug fails
|
|
|
254
275
|
poli link --org acme
|
|
255
276
|
```
|
|
256
277
|
|
|
257
|
-
When the organization already has a project whose slug is the
|
|
278
|
+
When the organization already has a project whose slug is the one `project.name` gives (say, a teammate's), `poli link` links to it instead of creating one. Its draft is someone's work, 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. Linking to an existing project sends nothing: the first `poli dev` or `poli sync` compares the folder with its draft, sends only the files the draft does not have, and reports each file that differs as a [conflict](#conflicts).
|
|
279
|
+
|
|
280
|
+
The slug `project.name` gives is the API's: accents dropped, lowercase letters and digits, every run of anything else one `-` (`Société Générale` gives `societe-generale`). For a project whose slug is not that one, name it: `poli link --org <slug> --project <project-slug>` links to that existing project without asking and never creates one. A slug that is none of the organization's projects you can see exits `2`; a project you can only view exits `5`.
|
|
258
281
|
|
|
259
282
|
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
283
|
|
|
261
284
|
#### Confirmed links
|
|
262
285
|
|
|
263
|
-
A `cloud:` block can come with a cloned repository, and every sync
|
|
286
|
+
A `cloud:` block can come with a cloned repository, and every sync writes to the cloud draft of the project it names. So `poli dev` and `poli sync` 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 dev` or `poli sync` 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`.
|
|
287
|
+
|
|
288
|
+
Before syncing, `poli dev` and `poli sync` 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.
|
|
264
289
|
|
|
265
|
-
|
|
290
|
+
#### Draft bases
|
|
291
|
+
|
|
292
|
+
Next to the confirmed links, `~/.polipage/draft-bases.json` (mode `0600`) keeps, per folder (its real path) and project id, the SHA-256 of each file's bytes as the draft and the folder last agreed on it, and the [conflicts](#conflicts) not resolved yet. Every sync sends each change with that base, and the API refuses the whole sync when a file changed in the draft since (someone else's change is never overwritten). `poli clone` writes the folder's bases; `poli link`, `poli init --starter` and `poli unlink` forget them. A linked folder with none (just linked, or linked by an older CLI) is reconciled by the next `poli dev` or `poli sync` before anything is sent: a file with the draft's bytes (for `poli-page.json`, the same content the API stores, whatever its formatting and `cloud:` block) gets its base, a file only the folder has is sent as new, and a file that differs, or one only the draft has, is a conflict. Deleting the file is safe: the next sync reconciles.
|
|
266
293
|
|
|
267
294
|
#### `poli unlink`
|
|
268
295
|
|
|
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.
|
|
296
|
+
Removes the `cloud:` section from `poli-page.json`, even one whose ids are invalid, and forgets the folder's [confirmed link](#confirmed-links) and [draft bases](#draft-bases), so a `cloud:` block that comes back later (a pull, a checkout) is asked about again. Local files are preserved.
|
|
297
|
+
|
|
298
|
+
#### `poli dev --no-preview`
|
|
270
299
|
|
|
271
|
-
|
|
300
|
+
Syncs each save to the cloud draft, with no server, no browser and no render: [`poli dev`](#poli-dev-template)'s sync, start-up and conflict handling, for when the editor or another tool shows the result. It needs no TTY, so it runs in a script or next to another dev server. A template argument, `--port`, `--data` or `--no-open` with it exits `2`: they only configure the preview.
|
|
272
301
|
|
|
273
|
-
|
|
302
|
+
```bash
|
|
303
|
+
poli dev --no-preview
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
It syncs the same file set as [`poli publish`](#poli-publish), each file with its encoding (`base64` for assets, `utf8` otherwise), 300 ms after the last save. A file whose name some systems cannot hold (`:`, a reserved name such as `con`, a name ending in `.` or a space) is named once and never sent nor deleted. Network errors are retried with an exponential backoff (1s up to 30s), `503 ORGANIZATION_MIGRATING` after 5 seconds; other errors are shown and the next save retries.
|
|
307
|
+
|
|
308
|
+
#### `poli sync`
|
|
309
|
+
|
|
310
|
+
Syncs the folder with its cloud draft once, and settles [conflicts](#conflicts). A folder with no [draft bases](#draft-bases) is reconciled first.
|
|
274
311
|
|
|
275
312
|
```bash
|
|
276
|
-
poli
|
|
313
|
+
poli sync # send what changed since the last sync
|
|
314
|
+
poli sync --keep-mine -- templates/invoice/invoice.html # settle a conflict with your file
|
|
315
|
+
poli sync --take-theirs -- tailwind.css # settle it with the draft's file
|
|
277
316
|
```
|
|
278
317
|
|
|
279
|
-
|
|
318
|
+
- `--keep-mine <path...>`: your files win: each is sent over the draft's (a file the draft deleted is sent as new, and a file you do not have is deleted from the draft).
|
|
319
|
+
- `--take-theirs <path...>`: the draft's files win: each replaces yours (for `poli-page.json`, the fields the API stores; your `cloud:` block and other keys stay), or your file is deleted when the draft deleted it. A file that changed again, in the draft or here, since the conflict was reported is not written and stays in conflict.
|
|
320
|
+
- Put `--` before the paths so none is read as a flag. Every path must be an open conflict: one that is not, or a path given to both flags, exits `2` with no flag applied.
|
|
321
|
+
- Conflicts left: printed with the two commands that settle them, exit `7`.
|
|
322
|
+
- Piped, or with `--json`, it prints `{ synced, conflicts }` (`synced`: the files sent; `conflicts`: `{ path, remoteSha256 }`, `remoteSha256` `null` when the draft deleted the file).
|
|
323
|
+
- Network errors are retried 4 times (1, 2, 4 then 8 s apart), then it exits `3`, so a script or a CI job never hangs on a network that is down. Ctrl-C stops it between requests and during a wait, with exit `130` (`143` on SIGTERM), the shell's codes for an interrupted command; a second Ctrl-C exits at once.
|
|
324
|
+
|
|
325
|
+
#### Conflicts
|
|
280
326
|
|
|
281
|
-
|
|
282
|
-
- `503 ORGANIZATION_MIGRATING` → 5-second retry
|
|
283
|
-
- Other API errors → logged, watch continues, next save retries
|
|
327
|
+
A file changed both here and in the cloud draft since the last sync (by a teammate, the editor or another machine) is a conflict: nothing is overwritten, `poli sync` still sends every other change, and the file stays out of every sync until it is settled. A file whose bytes are the same on both sides is not one. A file found by the reconciliation of a folder with no [draft bases](#draft-bases) is said to differ from the cloud draft: nobody knows which side changed it.
|
|
284
328
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
329
|
+
- `poli dev` in a terminal asks for each file: **Keep mine**, **Take the cloud's** or **Skip for now** (left out for the session, listed in the status line and on the preview page). A file the draft has and this folder does not (deleted here, or never synced) is asked with **Keep mine (delete it from the draft)**, and **Skip for now** as the default.
|
|
330
|
+
- In the printed list, such a file is marked `(not in this folder: keep-mine deletes it from the draft)`.
|
|
331
|
+
- `poli dev` without a terminal (piped, `concurrently`, a Procfile) and `poli sync` print the files and the commands that settle them, then exit `7`:
|
|
332
|
+
|
|
333
|
+
```
|
|
334
|
+
1 file(s) changed both here and in the cloud draft since the last sync:
|
|
335
|
+
templates/invoice/invoice.html
|
|
336
|
+
Keep your version:
|
|
337
|
+
poli sync --keep-mine -- templates/invoice/invoice.html
|
|
338
|
+
Or take the cloud's:
|
|
339
|
+
poli sync --take-theirs -- templates/invoice/invoice.html
|
|
340
|
+
```
|
|
288
341
|
|
|
289
342
|
### Live development
|
|
290
343
|
|
|
@@ -311,6 +364,7 @@ poli dev -d ./big.json # render every template against your own data
|
|
|
311
364
|
| `-p, --port <n>` | `7654` | Port to bind on `127.0.0.1`. Walks upwards when it is busy. |
|
|
312
365
|
| `-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. |
|
|
313
366
|
| `--no-open` | opens the browser | Skip launching a browser on start. |
|
|
367
|
+
| `--no-preview` | preview | Only sync: see [`poli dev --no-preview`](#poli-dev---no-preview). |
|
|
314
368
|
| `[template]` | first in manifest | Which template to show first. |
|
|
315
369
|
|
|
316
370
|
The served page gives you:
|
|
@@ -334,8 +388,8 @@ The served page gives you:
|
|
|
334
388
|
|
|
335
389
|
Notes:
|
|
336
390
|
|
|
337
|
-
- **No TTY required.**
|
|
338
|
-
|
|
391
|
+
- **No TTY required.** `poli dev` is a server and runs happily with its stdout
|
|
392
|
+
piped, so you can compose it into your own dev script:
|
|
339
393
|
|
|
340
394
|
```json
|
|
341
395
|
{ "scripts": { "dev": "concurrently \"poli dev --no-open\" \"vite\"" } }
|
|
@@ -349,8 +403,10 @@ Notes:
|
|
|
349
403
|
- Only its own page can change the view: a `POST` from another site (or from
|
|
350
404
|
any client that sends neither `Sec-Fetch-Site: same-origin` nor the server's
|
|
351
405
|
own `Origin`) gets a `403`, and no other site can frame the page.
|
|
352
|
-
- On start it
|
|
353
|
-
|
|
406
|
+
- On start it sends the files changed since the last sync, including those
|
|
407
|
+
changed while it was stopped, so the first render reflects your local files.
|
|
408
|
+
A folder with no [draft bases](#draft-bases) is reconciled first: nothing is
|
|
409
|
+
sent over the draft, and each file that differs is a [conflict](#conflicts).
|
|
354
410
|
- Failures are surfaced, not fatal: a render that errors, a rejected sync, a
|
|
355
411
|
broken `poli-page.json`, or a dropped connection leave the server up and the
|
|
356
412
|
page serving.
|
|
@@ -378,7 +434,7 @@ poli publish --env live --yes # protected environment, no prompt (scripts)
|
|
|
378
434
|
|
|
379
435
|
- **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
436
|
- **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
|
|
437
|
+
- **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 dev` and `poli sync` apply them too.
|
|
382
438
|
- **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
439
|
- **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
440
|
- **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.
|
|
@@ -612,9 +668,9 @@ Every command that returns a payload (renders, descriptors, publishes) follows t
|
|
|
612
668
|
|
|
613
669
|
Either the summary **or** the JSON — never both at once. Errors always go to stderr with a clear message.
|
|
614
670
|
|
|
615
|
-
Commands that take this contract: `render`, `documents get`, `documents preview`, `documents thumbnails`, `whoami`, `publish`, `env list`, `env remove-project`, `init --starter`.
|
|
671
|
+
Commands that take this contract: `render`, `documents get`, `documents preview`, `documents thumbnails`, `whoami`, `publish`, `env list`, `env remove-project`, `init --starter`, `clone`, `sync`.
|
|
616
672
|
|
|
617
|
-
Imperative commands (`init` without `--starter`, `new`, `link`, `unlink`, `logout`, `documents delete`, `
|
|
673
|
+
Imperative commands (`init` without `--starter`, `new`, `link`, `unlink`, `logout`, `documents delete`, `login`) don't have a JSON payload to forward: they just acknowledge with a `✓` line on success.
|
|
618
674
|
|
|
619
675
|
---
|
|
620
676
|
|
|
@@ -629,6 +685,7 @@ Imperative commands (`init` without `--starter`, `new`, `link`, `unlink`, `logou
|
|
|
629
685
|
| `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
686
|
| `5` | Not authorized (insufficient role, protected environment, `PROJECT_OUT_OF_SCOPE`, `THUMBNAILS_NOT_AVAILABLE`) |
|
|
631
687
|
| `6` | Invalid local state (no project, invalid `poli-page.json`, project not linked, empty folder where required) |
|
|
688
|
+
| `7` | Conflict: files changed both here and in the cloud draft, not settled (see [conflicts](#conflicts)) |
|
|
632
689
|
|
|
633
690
|
These map to the centralised `ExitCode` constants in `src/exit-codes.ts`. Every handler routes errors through `errorToExitCode(err)`.
|
|
634
691
|
|
|
@@ -761,7 +818,7 @@ You're in session mode and the local manifest has no `cloud:` block. Either run
|
|
|
761
818
|
|
|
762
819
|
### `This folder is linked to project "<name>" (<slug>) of organization "<name>" (<slug>), a link you have not confirmed on this machine...`
|
|
763
820
|
|
|
764
|
-
`poli
|
|
821
|
+
`poli dev` or `poli sync` found a `cloud:` block (from a cloned repository, 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
822
|
|
|
766
823
|
### `The cloud block of poli-page.json names more than one project: ...`
|
|
767
824
|
|
|
@@ -801,11 +858,15 @@ Thumbnails via `poli documents thumbnails` are a paid-tier feature. Upgrade to S
|
|
|
801
858
|
|
|
802
859
|
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`.
|
|
803
860
|
|
|
861
|
+
### `N file(s) changed both here and in the cloud draft since the last sync`
|
|
862
|
+
|
|
863
|
+
Someone changed these files in the cloud draft since your last sync, and you changed them too. Nothing was overwritten. Keep yours or take the draft's with the `poli sync` command printed under the message, or run `poli dev` in a terminal to be asked. Exit code `7`. See [conflicts](#conflicts).
|
|
864
|
+
|
|
804
865
|
### `503 ORGANIZATION_MIGRATING`
|
|
805
866
|
|
|
806
|
-
Your org is being migrated to a new tier. `poli
|
|
867
|
+
Your org is being migrated to a new tier. `poli dev` and `poli sync` retry automatically after 5s. Other commands surface the error: retry by hand once the migration completes (typically under a minute).
|
|
807
868
|
|
|
808
|
-
### `poli
|
|
869
|
+
### `poli dev` doesn't sync on save
|
|
809
870
|
|
|
810
871
|
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.
|
|
811
872
|
|
package/dist/api-client.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ export declare class ApiError extends Error {
|
|
|
3
3
|
readonly code: string;
|
|
4
4
|
readonly httpStatus: number;
|
|
5
5
|
readonly retryAfter?: number | undefined;
|
|
6
|
-
|
|
6
|
+
/** The parsed response body of an error answer, kept as received (never trusted). */
|
|
7
|
+
body: unknown;
|
|
8
|
+
constructor(code: string, httpStatus: number, message: string, retryAfter?: number | undefined, body?: unknown);
|
|
7
9
|
}
|
|
8
10
|
export declare class QuotaExceededError extends ApiError {
|
|
9
11
|
constructor(message: string, retryAfter?: number);
|
|
@@ -68,6 +70,20 @@ export declare class ApiKeyExpiredError extends ApiError {
|
|
|
68
70
|
export declare class ProjectOutOfScopeError extends ApiError {
|
|
69
71
|
constructor(_message?: string, retryAfter?: number);
|
|
70
72
|
}
|
|
73
|
+
export interface DraftConflict {
|
|
74
|
+
path: string;
|
|
75
|
+
/** The cloud's current hash of the file, or `null` when it no longer exists there. */
|
|
76
|
+
remoteSha256: string | null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* `409 DRAFT_CONFLICT`: the sync touched files someone else changed since
|
|
80
|
+
* their base. Nothing was written. Exits 7.
|
|
81
|
+
*/
|
|
82
|
+
export declare class DraftConflictError extends ApiError {
|
|
83
|
+
readonly exitCode = 7;
|
|
84
|
+
readonly conflicts: DraftConflict[];
|
|
85
|
+
constructor(message: string, retryAfter?: number, body?: unknown);
|
|
86
|
+
}
|
|
71
87
|
export interface DeviceRequestResult {
|
|
72
88
|
deviceCode: string;
|
|
73
89
|
userCode: string;
|
|
@@ -105,11 +121,17 @@ export interface ProjectFileEntry {
|
|
|
105
121
|
path: string;
|
|
106
122
|
encoding: 'utf8' | 'base64';
|
|
107
123
|
content: string;
|
|
124
|
+
/** The hash the CLI last saw on the cloud; `null` = the file was absent. Omitted = unconditional. */
|
|
125
|
+
baseSha256?: string | null;
|
|
108
126
|
}
|
|
109
127
|
export interface PatchFilesBody {
|
|
110
128
|
added: ProjectFileEntry[];
|
|
111
129
|
modified: ProjectFileEntry[];
|
|
112
|
-
|
|
130
|
+
/** A path is an unconditional delete; the object form carries the base the CLI last saw. */
|
|
131
|
+
deleted: Array<string | {
|
|
132
|
+
path: string;
|
|
133
|
+
baseSha256: string | null;
|
|
134
|
+
}>;
|
|
113
135
|
}
|
|
114
136
|
/** `POST /v1/projects/:project/publish` body: the whole local project. */
|
|
115
137
|
export interface PublishBody {
|
|
@@ -165,6 +187,20 @@ export interface ProjectEnvironmentState {
|
|
|
165
187
|
}
|
|
166
188
|
export interface PatchFilesResult {
|
|
167
189
|
syncedAt: string;
|
|
190
|
+
/** The cloud's hash of every file this sync wrote. */
|
|
191
|
+
files: Array<{
|
|
192
|
+
path: string;
|
|
193
|
+
sha256: string;
|
|
194
|
+
}>;
|
|
195
|
+
}
|
|
196
|
+
/** One file of the cloud draft, with a short-lived presigned download URL. */
|
|
197
|
+
export interface DraftFile {
|
|
198
|
+
path: string;
|
|
199
|
+
size: number;
|
|
200
|
+
sha256: string;
|
|
201
|
+
/** Presigned: never log or print it. */
|
|
202
|
+
url: string;
|
|
203
|
+
expiresAt: string;
|
|
168
204
|
}
|
|
169
205
|
export interface DocumentDescriptor {
|
|
170
206
|
documentId: string;
|
|
@@ -255,11 +291,15 @@ export interface ApiClient {
|
|
|
255
291
|
id: string;
|
|
256
292
|
name: string;
|
|
257
293
|
slug: string;
|
|
294
|
+
access?: string;
|
|
295
|
+
role?: string;
|
|
258
296
|
}>>;
|
|
259
297
|
createProject(session: string, orgId: string, payload: Record<string, unknown>): Promise<{
|
|
260
298
|
id: string;
|
|
261
299
|
}>;
|
|
262
300
|
patchFiles(session: string, orgId: string, projectId: string, body: PatchFilesBody): Promise<PatchFilesResult>;
|
|
301
|
+
/** `GET …/projects/:id/files`: the draft's files with presigned download URLs. */
|
|
302
|
+
listDraftFiles(session: string, orgId: string, projectId: string): Promise<DraftFile[]>;
|
|
263
303
|
listEnvironments(authorization: string, orgId: string): Promise<EnvironmentInfo[]>;
|
|
264
304
|
getProjectEnvironments(session: string, orgId: string, projectId: string): Promise<ProjectEnvironmentState[]>;
|
|
265
305
|
/**
|
package/dist/api-client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAIjD,qBAAa,QAAS,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAIjD,qBAAa,QAAS,SAAQ,KAAK;aAKjB,IAAI,EAAE,MAAM;aACZ,UAAU,EAAE,MAAM;aAElB,UAAU,CAAC,EAAE,MAAM;IAPpC,qFAAqF;IACrF,IAAI,EAAE,OAAO,CAAC;gBAGG,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClC,OAAO,EAAE,MAAM,EACC,UAAU,CAAC,EAAE,MAAM,YAAA,EACnC,IAAI,CAAC,EAAE,OAAO;CAMf;AAED,qBAAa,kBAAmB,SAAQ,QAAQ;gBACnC,OAAO,EAAE,MAAM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,MAAM,GAAG,SAAS,EAC/B,EAAE,EAAE,MAAM,GACR,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,kBAAkB,CACjB,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,wBAAwB,GAC/B,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;IAC9B,eAAe,CACd,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,EAAE,EAAE,MAAM,GACR,OAAO,CAAC,qBAAqB,CAAC,CAAC;CAClC;AAED,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAuU3D"}
|
package/dist/api-client.js
CHANGED
|
@@ -4,12 +4,15 @@ export class ApiError extends Error {
|
|
|
4
4
|
code;
|
|
5
5
|
httpStatus;
|
|
6
6
|
retryAfter;
|
|
7
|
-
|
|
7
|
+
/** The parsed response body of an error answer, kept as received (never trusted). */
|
|
8
|
+
body;
|
|
9
|
+
constructor(code, httpStatus, message, retryAfter, body) {
|
|
8
10
|
super(message);
|
|
9
11
|
this.code = code;
|
|
10
12
|
this.httpStatus = httpStatus;
|
|
11
13
|
this.retryAfter = retryAfter;
|
|
12
14
|
this.name = new.target.name;
|
|
15
|
+
this.body = body;
|
|
13
16
|
}
|
|
14
17
|
}
|
|
15
18
|
export class QuotaExceededError extends ApiError {
|
|
@@ -117,6 +120,35 @@ export class ProjectOutOfScopeError extends ApiError {
|
|
|
117
120
|
super('PROJECT_OUT_OF_SCOPE', 403, API_KEY_MESSAGES.PROJECT_OUT_OF_SCOPE, retryAfter);
|
|
118
121
|
}
|
|
119
122
|
}
|
|
123
|
+
const HEX64 = /^[0-9a-f]{64}$/;
|
|
124
|
+
/**
|
|
125
|
+
* `409 DRAFT_CONFLICT`: the sync touched files someone else changed since
|
|
126
|
+
* their base. Nothing was written. Exits 7.
|
|
127
|
+
*/
|
|
128
|
+
export class DraftConflictError extends ApiError {
|
|
129
|
+
exitCode = 7;
|
|
130
|
+
conflicts;
|
|
131
|
+
constructor(message, retryAfter, body) {
|
|
132
|
+
super('DRAFT_CONFLICT', 409, message, retryAfter, body);
|
|
133
|
+
const raw = body?.conflicts;
|
|
134
|
+
if (!Array.isArray(raw))
|
|
135
|
+
throw unexpectedAnswer('the draft conflict list');
|
|
136
|
+
this.conflicts = raw.map((item) => {
|
|
137
|
+
const c = item;
|
|
138
|
+
if (typeof c !== 'object' ||
|
|
139
|
+
c === null ||
|
|
140
|
+
typeof c.path !== 'string' ||
|
|
141
|
+
!(c.remoteSha256 === null || (typeof c.remoteSha256 === 'string' && HEX64.test(c.remoteSha256)))) {
|
|
142
|
+
throw unexpectedAnswer('the draft conflict list');
|
|
143
|
+
}
|
|
144
|
+
return { path: c.path, remoteSha256: c.remoteSha256 };
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/** A well-formed status but a body the CLI cannot trust; never quotes the body. */
|
|
149
|
+
function unexpectedAnswer(what) {
|
|
150
|
+
return new ApiError('INVALID_RESPONSE', 502, `The API answered with unexpected data for ${what}.`);
|
|
151
|
+
}
|
|
120
152
|
const TYPED_ERROR_REGISTRY = {
|
|
121
153
|
QUOTA_EXCEEDED: QuotaExceededError,
|
|
122
154
|
OVERAGE_CAP_EXCEEDED: OverageCapError,
|
|
@@ -137,7 +169,10 @@ const TYPED_ERROR_REGISTRY = {
|
|
|
137
169
|
INVALID_API_KEY: InvalidApiKeyError,
|
|
138
170
|
API_KEY_EXPIRED: ApiKeyExpiredError,
|
|
139
171
|
PROJECT_OUT_OF_SCOPE: ProjectOutOfScopeError,
|
|
172
|
+
DRAFT_CONFLICT: DraftConflictError,
|
|
140
173
|
};
|
|
174
|
+
/** The API's cap on one project file. */
|
|
175
|
+
const MAX_DRAFT_FILE_BYTES = 5 * 1024 * 1024;
|
|
141
176
|
export function createApiClient(baseUrl) {
|
|
142
177
|
const origin = baseUrl === undefined ? apiOrigin() : assertTrustedApiOrigin(baseUrl);
|
|
143
178
|
async function request(path, options = {}) {
|
|
@@ -364,7 +399,11 @@ export function createApiClient(baseUrl) {
|
|
|
364
399
|
},
|
|
365
400
|
body: JSON.stringify(body),
|
|
366
401
|
});
|
|
367
|
-
return response.json();
|
|
402
|
+
return parsePatchFilesResult(await response.json());
|
|
403
|
+
},
|
|
404
|
+
async listDraftFiles(session, orgId, projectId) {
|
|
405
|
+
const response = await request(`/api/organizations/${idSegment(orgId, 'organization')}/projects/${idSegment(projectId, 'project')}/files`, { headers: { Authorization: `Bearer ${session}` } });
|
|
406
|
+
return parseDraftFiles(await response.json(), origin);
|
|
368
407
|
},
|
|
369
408
|
async listEnvironments(authorization, orgId) {
|
|
370
409
|
const response = await request(`/api/organizations/${idSegment(orgId, 'organization')}/environments`, {
|
|
@@ -416,11 +455,85 @@ async function buildApiError(response) {
|
|
|
416
455
|
const { code, message: serverText } = parseErrorBody(text, response.status);
|
|
417
456
|
// Command error handlers print the message to stderr as is.
|
|
418
457
|
const message = oneLine(serverText);
|
|
458
|
+
let body;
|
|
459
|
+
try {
|
|
460
|
+
body = JSON.parse(text);
|
|
461
|
+
}
|
|
462
|
+
catch {
|
|
463
|
+
body = undefined;
|
|
464
|
+
}
|
|
419
465
|
const typed = code ? TYPED_ERROR_REGISTRY[code] : undefined;
|
|
420
466
|
if (typed) {
|
|
421
|
-
|
|
467
|
+
const error = new typed(message, retryAfter, body);
|
|
468
|
+
error.body = body;
|
|
469
|
+
return error;
|
|
470
|
+
}
|
|
471
|
+
return new ApiError(code ?? 'UNKNOWN', response.status, message, retryAfter, body);
|
|
472
|
+
}
|
|
473
|
+
function parsePatchFilesResult(raw) {
|
|
474
|
+
const body = raw;
|
|
475
|
+
if (typeof body !== 'object' || body === null || typeof body.syncedAt !== 'string') {
|
|
476
|
+
throw unexpectedAnswer('the sync result');
|
|
477
|
+
}
|
|
478
|
+
const files = body.files ?? [];
|
|
479
|
+
if (!Array.isArray(files))
|
|
480
|
+
throw unexpectedAnswer('the sync result');
|
|
481
|
+
return {
|
|
482
|
+
syncedAt: body.syncedAt,
|
|
483
|
+
files: files.map((item) => {
|
|
484
|
+
const f = item;
|
|
485
|
+
if (typeof f !== 'object' ||
|
|
486
|
+
f === null ||
|
|
487
|
+
typeof f.path !== 'string' ||
|
|
488
|
+
typeof f.sha256 !== 'string' ||
|
|
489
|
+
!HEX64.test(f.sha256)) {
|
|
490
|
+
throw unexpectedAnswer('the sync result');
|
|
491
|
+
}
|
|
492
|
+
return { path: f.path, sha256: f.sha256 };
|
|
493
|
+
}),
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
/** The listing is untrusted: every entry is checked, none is quoted in an error. */
|
|
497
|
+
function parseDraftFiles(raw, apiOrigin) {
|
|
498
|
+
const files = raw?.files;
|
|
499
|
+
if (!Array.isArray(files))
|
|
500
|
+
throw unexpectedAnswer('the draft listing');
|
|
501
|
+
const originHost = new URL(apiOrigin).hostname;
|
|
502
|
+
const localApi = originHost === 'localhost' || originHost === '127.0.0.1';
|
|
503
|
+
return files.map((item) => {
|
|
504
|
+
const f = item;
|
|
505
|
+
if (typeof f !== 'object' ||
|
|
506
|
+
f === null ||
|
|
507
|
+
typeof f.path !== 'string' ||
|
|
508
|
+
typeof f.size !== 'number' ||
|
|
509
|
+
!Number.isInteger(f.size) ||
|
|
510
|
+
f.size < 0 ||
|
|
511
|
+
f.size > MAX_DRAFT_FILE_BYTES ||
|
|
512
|
+
typeof f.sha256 !== 'string' ||
|
|
513
|
+
!HEX64.test(f.sha256) ||
|
|
514
|
+
typeof f.url !== 'string' ||
|
|
515
|
+
typeof f.expiresAt !== 'string' ||
|
|
516
|
+
!isAllowedDownloadUrl(f.url, localApi)) {
|
|
517
|
+
throw unexpectedAnswer('the draft listing');
|
|
518
|
+
}
|
|
519
|
+
return {
|
|
520
|
+
path: f.path,
|
|
521
|
+
size: f.size,
|
|
522
|
+
sha256: f.sha256,
|
|
523
|
+
url: f.url,
|
|
524
|
+
expiresAt: f.expiresAt,
|
|
525
|
+
};
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
function isAllowedDownloadUrl(value, localApi) {
|
|
529
|
+
let url;
|
|
530
|
+
try {
|
|
531
|
+
url = new URL(value);
|
|
532
|
+
}
|
|
533
|
+
catch {
|
|
534
|
+
return false;
|
|
422
535
|
}
|
|
423
|
-
return
|
|
536
|
+
return url.protocol === 'https:' || (localApi && url.protocol === 'http:');
|
|
424
537
|
}
|
|
425
538
|
/**
|
|
426
539
|
* Read the code and a human-readable message from an error response body.
|