@letterstory/cli 0.28.0 → 0.29.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -52
- package/lib/cli.mjs +55 -38
- package/lib/client.mjs +53 -0
- package/lib/commands/collection.mjs +279 -0
- package/lib/commands/collections.mjs +12 -42
- package/lib/commands/onboard.mjs +11 -11
- package/lib/commands/phantom.mjs +217 -0
- package/lib/commands/posts.mjs +22 -3
- package/lib/commands.mjs +4 -3
- package/lib/documents.mjs +141 -0
- package/package.json +1 -1
- package/lib/commands/deploy.mjs +0 -389
- package/lib/commands/phantom-job.mjs +0 -41
package/README.md
CHANGED
|
@@ -79,9 +79,9 @@ refresh automatically. Run `letterstory logout` to revoke the session and forget
|
|
|
79
79
|
|
|
80
80
|
**Or use a static API key** (for CI/automation, or when you want scoped-down access):
|
|
81
81
|
|
|
82
|
-
You need a Letterstory API key (starts with `ls_`; legacy `lb_` keys still work) with the `
|
|
83
|
-
`
|
|
84
|
-
Add `
|
|
82
|
+
You need a Letterstory API key (starts with `ls_`; legacy `lb_` keys still work) with the `phantom:read` and
|
|
83
|
+
`phantom:write` capabilities — mint one in the app under **Settings → API keys**.
|
|
84
|
+
Add `phantom:domain` too if you plan to buy custom domains.
|
|
85
85
|
|
|
86
86
|
```bash
|
|
87
87
|
letterstory login --key ls_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
@@ -95,82 +95,97 @@ Run `letterstory whoami` (alias `status`) any time to confirm which key/url (or
|
|
|
95
95
|
resolved and see your company profile. Run `letterstory config` to see the resolved url and
|
|
96
96
|
credential source without making a network call.
|
|
97
97
|
|
|
98
|
-
##
|
|
98
|
+
## Phantomstory — a collection Letterstory hosts as an independent publication
|
|
99
|
+
|
|
100
|
+
A phantom is a site we host that renders one of your collections; it never carries your
|
|
101
|
+
company's name. Phantoms are metered in SITES live at once (`phantom balance`), not posts.
|
|
99
102
|
|
|
100
103
|
```bash
|
|
101
|
-
#
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
#
|
|
106
|
-
# … provisioning ·
|
|
107
|
-
#
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
letterstory
|
|
111
|
-
letterstory
|
|
112
|
-
letterstory
|
|
113
|
-
letterstory
|
|
114
|
-
letterstory
|
|
104
|
+
# provision a site and follow it until it's live (then it configures itself in the background:
|
|
105
|
+
# strategy, visuals, writing kernel, cadence, topic map)
|
|
106
|
+
letterstory phantom new --name "Saved Query" --config '{"cadence":{"posts_per_week":6}}'
|
|
107
|
+
|
|
108
|
+
# Phantom 7c19c7… provisioning — following…
|
|
109
|
+
# … provisioning · deploy
|
|
110
|
+
# … provisioning · connect
|
|
111
|
+
# Live at https://saved-query-7c19c7.letterstory-staging.com. Configuration continues in the background
|
|
112
|
+
|
|
113
|
+
letterstory phantom list
|
|
114
|
+
letterstory phantom get <phantom-id>
|
|
115
|
+
letterstory phantom config <phantom-id> # the site's file joined to its collection's
|
|
116
|
+
letterstory phantom config <phantom-id> --theme commons # patch the site (identity/theme rebuild it)
|
|
117
|
+
letterstory phantom config <phantom-id> --collection-config '{"cadence":{"posts_per_week":4}}'
|
|
118
|
+
letterstory phantom config <phantom-id> --configure --dry-run # what re-configuring would decide, applying nothing
|
|
119
|
+
letterstory phantom rebuild <phantom-id> # after publishing outside a collection run
|
|
120
|
+
letterstory phantom diagnostics <phantom-id> # why is my site empty?
|
|
121
|
+
letterstory phantom balance # sites live / granted, and the cadence cap
|
|
122
|
+
letterstory phantom delete <phantom-id> --yes
|
|
115
123
|
```
|
|
116
124
|
|
|
117
|
-
Pass `--no-wait` to return immediately and poll later with `
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
### One-shot: bare `deploy`
|
|
125
|
+
Pass `--no-wait` to return immediately and poll later with `phantom get`, `--no-configure`
|
|
126
|
+
for a bare site, or `--dry-run` to see the plan without provisioning anything.
|
|
121
127
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
```bash
|
|
126
|
-
letterstory deploy --domain yourverticalreview.com --buy
|
|
127
|
-
# Reserved phantom blog "Yourverticalreview" (7c19c7…)
|
|
128
|
-
# Priced yourverticalreview.com
|
|
129
|
-
# Registered yourverticalreview.com
|
|
130
|
-
# SSL + DNS provisioned · sitemap + schema generated
|
|
131
|
-
#
|
|
132
|
-
# Your phantom blog is live at https://yourverticalreview.com.
|
|
133
|
-
|
|
134
|
-
letterstory deploy --blog 7c19c7… --rebuild # rebuild an existing blog instead of creating one
|
|
135
|
-
letterstory deploy --domain demo.com --dry-run # preview without calling the API
|
|
136
|
-
```
|
|
128
|
+
Publishing to the site is a **collection run** on its collection (below). Letterstory's own
|
|
129
|
+
launch recipe from a client domain — positioning inferred, a masthead proposed, the first
|
|
130
|
+
posts seeded — is `phantom-onboard` (see "Propose, then onboard a phantom").
|
|
137
131
|
|
|
138
132
|
## Custom domains
|
|
139
133
|
|
|
140
134
|
```bash
|
|
141
|
-
letterstory domain check myblog.com
|
|
142
|
-
letterstory domain buy <
|
|
135
|
+
letterstory phantom domain check myblog.com # price it (no charge)
|
|
136
|
+
letterstory phantom domain buy <phantom-id> myblog.com --yes # buys + attaches (spends money; phantom:domain)
|
|
137
|
+
letterstory phantom domain connect <phantom-id> myblog.com # attach one you already own
|
|
143
138
|
```
|
|
144
139
|
|
|
145
|
-
`blogs` and `domains` are aliases for `deploy` and `domain` — the exact same commands
|
|
146
|
-
under Phantomstory's vocabulary (`blogs ls`, `blogs new`, `blogs rm`, `blogs update`,
|
|
147
|
-
`domains buy`, etc. all call the identical handler as their `deploy`/`domain`
|
|
148
|
-
counterpart). Use whichever set of verbs you prefer; both are always available from
|
|
149
|
-
both `letterstory` and `phantom`.
|
|
150
|
-
|
|
151
140
|
## Content
|
|
152
141
|
|
|
153
142
|
```bash
|
|
154
143
|
letterstory posts list [--limit <n>] [--collection <uuid>]
|
|
155
144
|
letterstory posts show <article-id>
|
|
156
|
-
letterstory posts new --title "…" --collection <uuid> --body "…"
|
|
145
|
+
letterstory posts new --title "…" --collection <uuid> --body "…" [--article-id <uuid>] # or --file <path|->; --article-id updates that article instead of creating one
|
|
157
146
|
letterstory posts publish <article-id>
|
|
158
147
|
letterstory posts unpublish <article-id>
|
|
148
|
+
letterstory posts delete --id <uuid> [--id <uuid> ...] # permanent; content, history, and any published copy are all removed
|
|
159
149
|
|
|
160
150
|
letterstory published list [--limit <n>] [--collection <uuid>] [--format html|md]
|
|
161
151
|
letterstory published show --slug my-post-slug [--format html|md] # or --id <uuid>
|
|
162
152
|
```
|
|
163
153
|
|
|
164
|
-
## Collections
|
|
154
|
+
## Collections — the content engine, one door
|
|
155
|
+
|
|
156
|
+
A collection is a publication with a ONE-FILE configuration (identity, content, cadence,
|
|
157
|
+
publishing, targets, measurement) that produces and publishes posts on a cadence.
|
|
158
|
+
`collection run` produces ONE post: source → write → gate → publish → (hosted) rebuild.
|
|
165
159
|
|
|
166
160
|
```bash
|
|
167
|
-
letterstory
|
|
168
|
-
letterstory
|
|
161
|
+
letterstory collection list # public_id = the HTTP door's address
|
|
162
|
+
letterstory collection new --name "Launches" --config-file cfg.json
|
|
163
|
+
letterstory collection config <id> # print the one file
|
|
164
|
+
letterstory collection config <id> --config '{"targets":{"enabled":true,"tier":"ramping"}}' # patch it
|
|
165
|
+
|
|
166
|
+
# one post, followed to the end (20–60 min); stops at the gate under manual approval
|
|
167
|
+
letterstory collection run --collection <id> --spoke <topic-id>
|
|
168
|
+
letterstory collection run --collection <id> --topic "…" --approval manual --no-wait
|
|
169
|
+
letterstory collection run --collection <id> --at 2026-10-01T09:00:00Z # a future slot
|
|
170
|
+
letterstory collection run-status <run-id> # status, steps, constraints, verification
|
|
171
|
+
letterstory collection runs --collection <id> --status ready
|
|
172
|
+
letterstory collection approve <run-id> --now
|
|
173
|
+
letterstory collection cancel <run-id>
|
|
174
|
+
letterstory collection delete <id> --yes
|
|
175
|
+
|
|
176
|
+
# the legacy verbs still work under `collections`
|
|
169
177
|
letterstory collections update <id> --cadence-target 4 --cadence-period week
|
|
170
|
-
letterstory collections delete <id> --yes
|
|
171
178
|
letterstory collections assign <article-id> <collection-id>
|
|
179
|
+
letterstory collections activate <id> --cadence 6 --approval autopilot
|
|
180
|
+
letterstory collections autopen <id> --kernel-family gazette
|
|
172
181
|
```
|
|
173
182
|
|
|
183
|
+
A direct run spends one of the collection's weekly cadence slots (its `posts_per_week`,
|
|
184
|
+
capped by the org's cadence cap) and is refused — never queued silently — once the week is
|
|
185
|
+
spent; the planner's own slots are the budget being spent as designed. The same door over
|
|
186
|
+
HTTP: `POST /api/collection/ingest/{public_id}` (202 + `poll_url`), `GET …/runs/{run_id}`,
|
|
187
|
+
`POST …/runs/{run_id}/approve`.
|
|
188
|
+
|
|
174
189
|
## Landing pages
|
|
175
190
|
|
|
176
191
|
A landing page is a link plus context describing what lives there. Collections with
|
|
@@ -280,6 +295,7 @@ jq '.topicPlans[1]' proposal.json | letterstory phantom-onboard mastheads acme.c
|
|
|
280
295
|
# Then onboard with the plan (direction + pillars), the masthead and, if any, the domain.
|
|
281
296
|
letterstory phantom-onboard acme.com --plan-file proposal.json --plan-id plan-2 \
|
|
282
297
|
--name "The Compliance Wire" --domain compliancewire.com --domain-mode buy_now --real
|
|
298
|
+
# (drives plan_phantom; the seeded posts are collection runs — poll them with `collection run-status`)
|
|
283
299
|
```
|
|
284
300
|
|
|
285
301
|
`propose` reads the client's homepage and returns distinct editorial angles (`topicPlans`), the
|
|
@@ -385,8 +401,8 @@ letterstory shredder job <job-id> # poll it your
|
|
|
385
401
|
Both follow loops poll every 15–20 s. `LETTERSTORY_POLL_INTERVAL_MS` overrides that — set
|
|
386
402
|
it to `0` in CI so a test does not wait on a real interval.
|
|
387
403
|
|
|
388
|
-
`
|
|
389
|
-
end to end, with `
|
|
404
|
+
`collection run --topic "…" --collection <uuid>` runs topic → draft → publish → rebuild
|
|
405
|
+
end to end, with `collection run-status <job-id>` to follow it.
|
|
390
406
|
|
|
391
407
|
## Seers — event-driven signals
|
|
392
408
|
|
package/lib/cli.mjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// never throws for user-facing problems (those become a printed CliError + code 1).
|
|
4
4
|
|
|
5
5
|
import { LetterstoryClient, CliError, resolveConfig, readConfigFile, writeConfigFile } from "./client.mjs";
|
|
6
|
+
import { resolveDocumentFlags } from "./documents.mjs";
|
|
6
7
|
import { checkForUpdate } from "./update-check.mjs";
|
|
7
8
|
import {
|
|
8
9
|
cmdLogin,
|
|
@@ -13,10 +14,8 @@ import {
|
|
|
13
14
|
cmdCall,
|
|
14
15
|
cmdTool,
|
|
15
16
|
cmdMcp,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
cmdBlogs,
|
|
19
|
-
cmdDomains,
|
|
17
|
+
cmdCollection,
|
|
18
|
+
cmdPhantom,
|
|
20
19
|
cmdPosts,
|
|
21
20
|
cmdPublished,
|
|
22
21
|
cmdReviewers,
|
|
@@ -34,7 +33,6 @@ import {
|
|
|
34
33
|
cmdAutoPen,
|
|
35
34
|
cmdCovers,
|
|
36
35
|
cmdKernel,
|
|
37
|
-
cmdPhantomJob,
|
|
38
36
|
cmdOnboard,
|
|
39
37
|
cmdSeers,
|
|
40
38
|
cmdTemplates,
|
|
@@ -45,7 +43,7 @@ import {
|
|
|
45
43
|
} from "./commands.mjs";
|
|
46
44
|
|
|
47
45
|
// Keep in sync with cli/package.json.
|
|
48
|
-
export const VERSION = "0.
|
|
46
|
+
export const VERSION = "0.29.1";
|
|
49
47
|
|
|
50
48
|
// Flags that never take a value. Listing them explicitly means `deploy get --json <id>`
|
|
51
49
|
// can't accidentally swallow the id as --json's value.
|
|
@@ -167,32 +165,50 @@ Auth:
|
|
|
167
165
|
logout Forget saved credentials (revokes an OAuth session, if any)
|
|
168
166
|
config Show the resolved url + credential source
|
|
169
167
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
168
|
+
Collections (the content engine as a primitive — one door, 'collection run'):
|
|
169
|
+
collection list Your collections (public_id = the HTTP door's address)
|
|
170
|
+
collection new --name <n> [--description <t>] [--config '<json>'|--config-file cfg.json]
|
|
171
|
+
collection config <id> [--config '<json>'|--config-file cfg.json]
|
|
172
|
+
Print the ONE FILE (identity, content, cadence,
|
|
173
|
+
publishing, targets, measurement) — or PATCH it
|
|
174
|
+
collection run --collection <id> [--topic <t> | --spoke <topic-id> | --headline <suggestion-id>]
|
|
175
|
+
[--source <url> …] [--must-include <t> …] [--depth barebones|fleshed_out]
|
|
176
|
+
[--kernel <id>] [--no-verify] [--shred] [--mention off|subtle|woven]
|
|
177
|
+
[--approval autopilot|review_window|manual] [--no-publish] [--no-rebuild]
|
|
178
|
+
[--at <iso-datetime>] [--no-wait]
|
|
179
|
+
Produce ONE post: source → write → gate →
|
|
180
|
+
publish → (hosted) rebuild. Spends one of the
|
|
181
|
+
week's cadence slots. 20–60 min; followed unless
|
|
182
|
+
--no-wait; stops at the gate under manual approval.
|
|
183
|
+
collection run-status <run-id> Status, steps, constraints, verification
|
|
184
|
+
collection runs [--collection <id>] [--status <s>] [--limit <n>]
|
|
185
|
+
collection approve <run-id> [--now] Answer the gate (--now publishes immediately)
|
|
186
|
+
collection cancel <run-id>
|
|
187
|
+
collection delete <id> --yes
|
|
188
|
+
|
|
189
|
+
Phantomstory (a collection Letterstory hosts as an independent publication):
|
|
190
|
+
phantom list Your phantoms (metered in SITES live at once)
|
|
191
|
+
phantom new --name <n> [--description <t>] [--theme <t>] [--collection <id>] [--customer-ref <r>]
|
|
192
|
+
[--no-configure] [--config '<json>'] [--client-domain <d>] [--dry-run] [--no-wait]
|
|
193
|
+
Provision a site + configure it (strategy,
|
|
194
|
+
visuals, kernel, cadence, topic map). Then
|
|
195
|
+
'collection run --collection <its collection_id>'.
|
|
196
|
+
phantom get <phantom-id> Status, URL, domain, DNS
|
|
197
|
+
phantom config <phantom-id> [--name … --theme … --collection …] [--collection-config '<json>']
|
|
198
|
+
[--configure [--dry-run]]
|
|
199
|
+
The site's file joined to its collection's
|
|
200
|
+
phantom rebuild <phantom-id> · phantom diagnostics <phantom-id> · phantom balance
|
|
201
|
+
phantom domain check <domain> · phantom domain buy <phantom-id> <domain> --yes
|
|
202
|
+
phantom domain connect <phantom-id> <domain>
|
|
203
|
+
phantom delete <phantom-id> --yes
|
|
189
204
|
|
|
190
205
|
Content:
|
|
191
206
|
posts list [--limit <n>] [--collection <uuid>] List your articles
|
|
192
207
|
posts show <article-id> Show one article
|
|
193
|
-
posts new --title <t> --collection <uuid> (--body <text> | --file <path|->)
|
|
208
|
+
posts new --title <t> --collection <uuid> (--body <text> | --file <path|->) [--article-id <uuid>]
|
|
194
209
|
posts publish <article-id> Publish an article
|
|
195
210
|
posts unpublish <article-id> Unpublish an article
|
|
211
|
+
posts delete --id <uuid> [--id <uuid> ...] Permanently delete article(s)
|
|
196
212
|
published list [--limit <n>] [--collection <uuid>] [--format html|md]
|
|
197
213
|
published show (--id <uuid> | --slug <slug>) [--format html|md]
|
|
198
214
|
|
|
@@ -347,12 +363,7 @@ Writing kernels (kernels write the draft; they do not research — run research
|
|
|
347
363
|
kernel runs [--endpoint <id>] [--limit <n>] Recent endpoint writes (telemetry)
|
|
348
364
|
kernel balance Kernel runs left on this org
|
|
349
365
|
|
|
350
|
-
Phantom
|
|
351
|
-
phantom-job create --topic <text> --collection <uuid> [--kernel <uuid>]
|
|
352
|
-
Topic -> draft -> publish -> rebuild
|
|
353
|
-
phantom-job status <job-id> Check a job's stage
|
|
354
|
-
|
|
355
|
-
Phantom onboarding recipe (domain -> live phantom blog with first posts):
|
|
366
|
+
Phantom launch recipe (a CLIENT domain -> a live phantom with its first posts; drives plan_phantom):
|
|
356
367
|
${bin === "phantom" ? "onboard" : "phantom-onboard"} <domain> [--about "the beat"] [--name X]
|
|
357
368
|
[--posts N] [--cadence N] [--cover editorial_image|full_ai|line_art] [--theme T]
|
|
358
369
|
[--real] [--domain host] [--domain-mode subdomain|buy_now|connect_later]
|
|
@@ -607,11 +618,9 @@ const CLIENT_COMMANDS = {
|
|
|
607
618
|
// argument coercion (--arg/--json-args/--stdin) added on top.
|
|
608
619
|
tool: cmdTool,
|
|
609
620
|
mcp: cmdMcp,
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
blogs: cmdBlogs,
|
|
614
|
-
domains: cmdDomains,
|
|
621
|
+
// The Collections primitive (one door: `collection run`) and its hosted profile.
|
|
622
|
+
collection: cmdCollection,
|
|
623
|
+
phantom: cmdPhantom,
|
|
615
624
|
posts: cmdPosts,
|
|
616
625
|
published: cmdPublished,
|
|
617
626
|
reviewers: cmdReviewers,
|
|
@@ -629,7 +638,6 @@ const CLIENT_COMMANDS = {
|
|
|
629
638
|
autopen: cmdAutoPen,
|
|
630
639
|
covers: cmdCovers,
|
|
631
640
|
kernel: cmdKernel,
|
|
632
|
-
"phantom-job": cmdPhantomJob,
|
|
633
641
|
"phantom-onboard": cmdOnboard,
|
|
634
642
|
seers: cmdSeers,
|
|
635
643
|
templates: cmdTemplates,
|
|
@@ -708,6 +716,15 @@ export async function run(argv, io = defaultIo()) {
|
|
|
708
716
|
verboseLog: io.error,
|
|
709
717
|
bin,
|
|
710
718
|
});
|
|
719
|
+
// DOCUMENT `--*-file` FLAGS BECOME TEXT BEFORE THE COMMAND RUNS.
|
|
720
|
+
//
|
|
721
|
+
// One interception point rather than per-command handling: `readTextInput` prefers a
|
|
722
|
+
// flag's inline twin over its path, so resolving a document is setting that twin — no
|
|
723
|
+
// change to `argsFromFlags` (which is synchronous, and has 75 call sites) and no command
|
|
724
|
+
// that can forget. `--file notes.md` still reads locally; `--file report.docx` and
|
|
725
|
+
// `--file paper.pdf` go through the app's extractor, which is the only one there is.
|
|
726
|
+
await resolveDocumentFlags(client, flags);
|
|
727
|
+
|
|
711
728
|
const ctx = { client, config, positionals: positionals.slice(1), flags, io, bin };
|
|
712
729
|
return await handler(ctx);
|
|
713
730
|
} catch (err) {
|
package/lib/client.mjs
CHANGED
|
@@ -155,6 +155,59 @@ export class LetterstoryClient {
|
|
|
155
155
|
return body.result;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
+
/**
|
|
159
|
+
* One multipart POST to a REST route on the same host, for the routes that take BYTES.
|
|
160
|
+
*
|
|
161
|
+
* The MCP envelope is JSON, so a document would have to be base64'd into it — a 10MB PDF
|
|
162
|
+
* becomes ~13MB of base64 in a single JSON string. `POST /api/documents/extract` takes the
|
|
163
|
+
* file directly, so this exists for it (and any future byte-taking route). Same auth and
|
|
164
|
+
* the same one-shot refresh-and-retry as `rpc`, because an expired session should fail the
|
|
165
|
+
* same way whichever door the command happened to use.
|
|
166
|
+
*
|
|
167
|
+
* Deliberately no `content-type` header: `fetch` sets it from the FormData, including the
|
|
168
|
+
* multipart boundary, and overriding it produces a body the server cannot parse.
|
|
169
|
+
*
|
|
170
|
+
* @param {string} path Route path, e.g. `/api/documents/extract`
|
|
171
|
+
* @param {FormData} form
|
|
172
|
+
* @returns {Promise<any>} the parsed JSON body
|
|
173
|
+
*/
|
|
174
|
+
async postForm(path, form, { _retried = false } = {}) {
|
|
175
|
+
const authHeaders = this.authHeaders();
|
|
176
|
+
if (!authHeaders) {
|
|
177
|
+
throw new CliError(
|
|
178
|
+
`Not logged in. Run \`${this.bin} login\` (opens your browser) or \`${this.bin} login --key <ls_…>\`.`
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
const url = `${this.url}${path}`;
|
|
182
|
+
if (this.verbose) this.verboseLog(`» POST ${url} (multipart)`);
|
|
183
|
+
let res;
|
|
184
|
+
try {
|
|
185
|
+
res = await this.fetch(url, {
|
|
186
|
+
method: "POST",
|
|
187
|
+
headers: { accept: "application/json", ...authHeaders },
|
|
188
|
+
body: form,
|
|
189
|
+
});
|
|
190
|
+
} catch (err) {
|
|
191
|
+
throw new CliError(`Could not reach ${url}: ${err.message}`);
|
|
192
|
+
}
|
|
193
|
+
if (this.verbose) this.verboseLog(`« ${res.status}`);
|
|
194
|
+
if (res.status === 401 || res.status === 403) {
|
|
195
|
+
if (!_retried && this.oauth?.refresh_token && (await this.tryRefresh())) {
|
|
196
|
+
return this.postForm(path, form, { _retried: true });
|
|
197
|
+
}
|
|
198
|
+
const hint = this.oauth
|
|
199
|
+
? `Your session has expired. Run \`${this.bin} login\` again.`
|
|
200
|
+
: "Check your API key and its capabilities.";
|
|
201
|
+
throw new CliError(`Authentication failed (HTTP ${res.status}). ${hint}`);
|
|
202
|
+
}
|
|
203
|
+
const body = await res.json().catch(() => null);
|
|
204
|
+
if (!res.ok) {
|
|
205
|
+
throw new CliError(body?.error ? String(body.error) : `Request failed (HTTP ${res.status}) at ${url}`);
|
|
206
|
+
}
|
|
207
|
+
if (!body) throw new CliError(`Unexpected non-JSON response (HTTP ${res.status}) from ${url}`);
|
|
208
|
+
return body;
|
|
209
|
+
}
|
|
210
|
+
|
|
158
211
|
// Best-effort silent refresh. Returns false (never throws) so rpc() can
|
|
159
212
|
// fall through to its normal "please log in again" error on any failure.
|
|
160
213
|
async tryRefresh() {
|