@firstdraft.com/cli 0.4.0 → 0.7.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 +5 -4
- package/RELEASING.md +12 -5
- package/docs/commands.md +54 -18
- package/docs/errors.md +13 -1
- package/docs/release-history.md +16 -0
- package/package.json +1 -1
- package/src/api-authentication.js +53 -8
- package/src/api-response.js +8 -0
- package/src/cli.js +192 -66
- package/src/compilation-artifact.js +1 -1
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ install the CLI and Skill, then compile into your current folder with `firstdraf
|
|
|
9
9
|
clone or GitHub push is required. The [Drawing Board guide](https://github.com/firstdraft/drawing-board#build-an-app-with-first-draft)
|
|
10
10
|
is the Codespaces fallback.
|
|
11
11
|
|
|
12
|
-
CLI 0.4
|
|
12
|
+
CLI 0.4 and later make `--output .` the default. Keep the explicit flag with CLI 0.3, whose zero-flag command selects GitHub
|
|
13
13
|
publication.
|
|
14
14
|
|
|
15
15
|
## What this repository owns
|
|
@@ -75,9 +75,10 @@ To exercise the checkout directly:
|
|
|
75
75
|
node bin/firstdraft.js --help
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
Remote commands read FIRSTDRAFT_API_TOKEN
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
Remote commands default to production and read `FIRSTDRAFT_API_TOKEN`. Use `firstdraft --staging plan compile`
|
|
79
|
+
and a separate `FIRSTDRAFT_STAGING_API_TOKEN` for staging. Existing Projects retain their saved origin. See
|
|
80
|
+
[environment selection](docs/commands.md#select-an-environment-and-authenticate) for custom URLs and credential
|
|
81
|
+
isolation. Keep tokens out of arguments, shell history, fixtures, snapshots, and logs.
|
|
81
82
|
|
|
82
83
|
## Package contract
|
|
83
84
|
|
package/RELEASING.md
CHANGED
|
@@ -16,10 +16,15 @@ release tag. An unpublished, untagged candidate can retain its proposed version
|
|
|
16
16
|
The published version may remain in source during documentation and test maintenance; recording its release history
|
|
17
17
|
does not require preparing another version. Choose an unused version when preparing the next publication.
|
|
18
18
|
|
|
19
|
-
CLI `0.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
CLI `0.7.x` requires API `0.6.x` and Plan `firstdraft.foundation-plan.sketch/0.22`. CLI `0.7.0` adds `--staging`
|
|
20
|
+
and requires `FIRSTDRAFT_STAGING_API_TOKEN` for the staging origin, including existing pinned Projects. This token
|
|
21
|
+
configuration change warrants a new CLI minor version; the API and Plan contracts stay unchanged. Production
|
|
22
|
+
remains the default and uses `FIRSTDRAFT_API_TOKEN`, as do custom origins. No Project is migrated. The target stays
|
|
23
|
+
`rails-sketch/2026-09`.
|
|
24
|
+
|
|
25
|
+
Local output remains the default introduced in CLI `0.4.x`: `firstdraft plan compile` is equivalent to
|
|
26
|
+
`firstdraft plan compile --output .`, with GitHub publication selected by explicit `--github`. The root archive
|
|
27
|
+
remains `.firstdraft/design`. Existing applications and old Plans are not migrated.
|
|
23
28
|
|
|
24
29
|
`release/compatibility.json` declares the package version, accepted API-contract range, and accepted Plan formats.
|
|
25
30
|
It is source-only metadata, validated by the normal test suite and absent from the npm tarball. Coordinate the
|
|
@@ -30,7 +35,9 @@ not authorization or runtime proof. Its closed `firstdraft.release-compatibility
|
|
|
30
35
|
## Prepare before merge
|
|
31
36
|
|
|
32
37
|
1. Update `package.json`, `package-lock.json`, and `release/compatibility.json`, and align the Skills CLI requirement.
|
|
33
|
-
2. Update the command, error, and Skill guidance affected by the change.
|
|
38
|
+
2. Update the command, error, and Skill guidance affected by the change. When onboarding changes, coordinate the
|
|
39
|
+
[local guide](https://gist.github.com/raghubetina/3d424a97a1eaa6de8c406e67f32a237e) publication from the Service's
|
|
40
|
+
`docs/guides/local-app.md` before the new CLI reaches `latest`. Preserve dated release evidence.
|
|
34
41
|
3. Run focused checks while developing and the repository's required CI for the merge candidate. For a fresh
|
|
35
42
|
checkout, the complete local check is `npm ci --ignore-scripts`, `npm audit`, then `npm run check`.
|
|
36
43
|
4. Review and merge the change. Wait for the existing `CI` workflow to pass for the selected `main` SHA; publication
|
package/docs/commands.md
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
This page owns the detailed public semantics of the current command surface. Run `firstdraft --help` or a command
|
|
4
4
|
group's `--help` for concise executable syntax. See [Errors and recovery](errors.md) before retrying a failed mutation.
|
|
5
5
|
|
|
6
|
-
The current `0.
|
|
6
|
+
The current `0.7.x` source line contains the auditable command shell, local Foundation Plan initialization, local
|
|
7
7
|
application-key and UUID generation, conditional whole-document push, whole-graph analysis status polling, direct
|
|
8
|
-
Compile-and-materialize and private publish orchestration, and retained-Compilation inspection. CLI `0.
|
|
9
|
-
requires the service's `0.
|
|
8
|
+
Compile-and-materialize and private publish orchestration, and retained-Compilation inspection. CLI `0.7.x`
|
|
9
|
+
requires the service's `0.6.x` API contract. See the [release policy](../RELEASING.md) for versioning and channel
|
|
10
10
|
semantics and [release history](release-history.md) for the transition from prereleases.
|
|
11
11
|
|
|
12
12
|
## Command map
|
|
@@ -23,19 +23,49 @@ semantics and [release history](release-history.md) for the transition from prer
|
|
|
23
23
|
| `firstdraft compilation status` | Yes | Inspect a retained Compilation by ID |
|
|
24
24
|
| `firstdraft compilation download` | Yes | Verify and materialize a successful retained Compilation |
|
|
25
25
|
|
|
26
|
-
##
|
|
26
|
+
## Select an environment and authenticate
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
Production at `https://firstdraft.com` is the default. Create a token at
|
|
29
|
+
[First Draft](https://firstdraft.com/api-tokens) and provide it through `FIRSTDRAFT_API_TOKEN` when running a network
|
|
30
|
+
command. Keep token values out of shell history and command arguments.
|
|
29
31
|
|
|
30
32
|
```sh
|
|
31
|
-
export FIRSTDRAFT_API_TOKEN="your-token"
|
|
32
33
|
firstdraft plan push
|
|
33
34
|
```
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
For staging, create a separate token at [First Draft staging](https://staging.firstdraft.com/api-tokens), provide it
|
|
37
|
+
through `FIRSTDRAFT_STAGING_API_TOKEN`, and select staging on the first remote command:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
firstdraft --staging plan push
|
|
41
|
+
firstdraft plan compile --staging
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`--staging` may precede the command group or appear among a remote command's options. It selects
|
|
45
|
+
`https://staging.firstdraft.com`. `plan init` and `generate` remain local; a global flag on a local command does not
|
|
46
|
+
save an environment selection. The first successful push, including the push within `plan compile`, pins the API
|
|
47
|
+
origin in `.firstdraft/state.json`.
|
|
48
|
+
|
|
49
|
+
Existing Projects keep their pinned origin with or without the flag. A CLI upgrade does not migrate a Project or its
|
|
50
|
+
credentials. A staging flag that disagrees with a Project's pin stops before any request.
|
|
51
|
+
To work with another environment, initialize a separate project directory and submit the Plan there; do not edit
|
|
52
|
+
the existing Project's private state to redirect it.
|
|
53
|
+
|
|
54
|
+
`FIRSTDRAFT_API_URL` remains available for an initial custom HTTPS origin or loopback HTTP development server.
|
|
55
|
+
`--staging` together with a different URL is an error; the equivalent normalized staging URL is allowed. Later
|
|
56
|
+
pushes and compilation reject an override that differs from the pin. Read-only status and retained download
|
|
57
|
+
commands use the pin and ignore `FIRSTDRAFT_API_URL` unless checking its conflict with an explicit `--staging`.
|
|
58
|
+
|
|
59
|
+
Every remote command selects credentials from its effective origin: the exact `https://staging.firstdraft.com`
|
|
60
|
+
origin requires `FIRSTDRAFT_STAGING_API_TOKEN`; production and custom origins use `FIRSTDRAFT_API_TOKEN`. Neither
|
|
61
|
+
token is a fallback for the other. This includes existing staging Projects and retained status or artifact reads,
|
|
62
|
+
even when no flag is supplied. Upgrading from CLI `0.6.x` therefore requires moving the staging credential to
|
|
63
|
+
`FIRSTDRAFT_STAGING_API_TOKEN`; production tokens stay in `FIRSTDRAFT_API_TOKEN`.
|
|
64
|
+
|
|
65
|
+
The CLI sends the selected token as a Bearer credential on every API request. It does not save it in `.firstdraft`,
|
|
66
|
+
print it, or require it for local commands. Revoke a token in the environment that issued it if it is exposed. A
|
|
67
|
+
missing token, or First Draft's validated `401` problem response with the `authentication_required` code, produces
|
|
68
|
+
that stable CLI error.
|
|
39
69
|
|
|
40
70
|
## Start a Foundation Plan
|
|
41
71
|
|
|
@@ -45,7 +75,7 @@ From the project that the Plan describes:
|
|
|
45
75
|
firstdraft plan init --name "Oscar Party"
|
|
46
76
|
```
|
|
47
77
|
|
|
48
|
-
This creates an empty `firstdraft.foundation-plan.sketch/0.
|
|
78
|
+
This creates an empty `firstdraft.foundation-plan.sketch/0.22` Plan targeting `rails-sketch/2026-09` and a
|
|
49
79
|
client-generated Project ID under `.firstdraft/`. A nested ignore file keeps that local scratch area out of Git
|
|
50
80
|
without changing the project's own `.gitignore`. Initialization makes no network request and refuses to replace an
|
|
51
81
|
existing `.firstdraft` path.
|
|
@@ -54,6 +84,12 @@ Provide either `--name`, `--application-key`, or both. Name-only initialization
|
|
|
54
84
|
initialization derives a humanized display name. Supplying both preserves both values exactly after validating them
|
|
55
85
|
against the Foundation Plan schema.
|
|
56
86
|
|
|
87
|
+
The initialized Plan omits `application.pwa`, which uses the Rails target's default of `true` for basic online
|
|
88
|
+
installation and Add to Home Screen support. Set `"pwa": false` within `application` to omit generated installation
|
|
89
|
+
metadata, or use `true` explicitly. The CLI sends the authored bytes unchanged, preserving omission versus either
|
|
90
|
+
boolean. This choice does not add offline caching, Web Push, or a native build; a browser may still save an ordinary
|
|
91
|
+
site when it is disabled. The CLI does not qualify browser or device installation.
|
|
92
|
+
|
|
57
93
|
### Generate an application key
|
|
58
94
|
|
|
59
95
|
To inspect the name-to-key derivation without initializing a project, run:
|
|
@@ -95,9 +131,9 @@ The command sends the exact bytes in `.firstdraft/foundation-plan.json`. The fir
|
|
|
95
131
|
Project; later pushes replay the complete ETag saved in `.firstdraft/state.json` so a stale writer cannot replace a
|
|
96
132
|
newer Plan. Successful responses and server diagnostics are printed as JSON for an agent to inspect.
|
|
97
133
|
|
|
98
|
-
The
|
|
99
|
-
|
|
100
|
-
|
|
134
|
+
The first successful push pins the normalized API origin in local state. See
|
|
135
|
+
[environment selection and authentication](#select-an-environment-and-authenticate) for production, staging, custom
|
|
136
|
+
origins, and the credentials each requires.
|
|
101
137
|
|
|
102
138
|
If a failure happens after sending the request, the CLI leaves local state unchanged. It never constructs an ETag
|
|
103
139
|
from the Plan digest or trusts an ETag from a response it could not fully verify. Follow
|
|
@@ -145,7 +181,7 @@ This is equivalent to `firstdraft plan compile --output .`. Use `--output ./appl
|
|
|
145
181
|
directory, or `--github` to publish to a private GitHub repository. `--github` and `--output` are mutually exclusive.
|
|
146
182
|
No GitHub connection, repository clone, or push is required for local compilation. Compilation runs on the First
|
|
147
183
|
Draft service; output and the application runtime are local. CLI `0.3.x` used GitHub Publication as its default;
|
|
148
|
-
scripts that require that behavior must add `--github` when upgrading to `0.4.x
|
|
184
|
+
scripts that require that behavior must add `--github` when upgrading to `0.4.x` or later.
|
|
149
185
|
|
|
150
186
|
Both `plan compile` modes first push the exact current bytes in
|
|
151
187
|
`.firstdraft/foundation-plan.json`, even when those bytes are unchanged, and save the accepted ETag using the same
|
|
@@ -167,7 +203,7 @@ destination is checked again after analysis; root adoption instead holds its own
|
|
|
167
203
|
pre-move identity recheck described below. Other existing destinations remain invalid, so
|
|
168
204
|
`--output ./application` retains its absent-directory contract.
|
|
169
205
|
|
|
170
|
-
The nested archive layout below is shared by CLI `0.3.x` and
|
|
206
|
+
The nested archive layout below is shared by CLI `0.3.x` and later.
|
|
171
207
|
[Published CLI `0.2.2`](release-history.md#022-publication-and-registry-observation) archives at top-level `design/`;
|
|
172
208
|
existing applications are not migrated automatically.
|
|
173
209
|
|
|
@@ -296,7 +332,7 @@ local paths, or environment values. Success writes exactly the validated private
|
|
|
296
332
|
newline to stdout. If the command fails after progress has begun, its structured JSON error envelope is the final
|
|
297
333
|
stderr document after the progress lines.
|
|
298
334
|
|
|
299
|
-
The closed API `0.
|
|
335
|
+
The closed API `0.6.x` progress-reason allowlist is `github.configuration_missing`, `github.oauth_unavailable`,
|
|
300
336
|
`github.api_unavailable`, `github.reauthorization_required`, `github.account_mismatch`,
|
|
301
337
|
`github.installation_unavailable`, `github.installation_not_ready`, `github.preflight_unavailable`, the legacy-only
|
|
302
338
|
`github.preflight_unclassified`, and these stage-specific fallbacks: `github.preflight_unavailable.configuration`,
|
|
@@ -345,7 +381,7 @@ when a retained direct Compilation succeeded but an earlier root materialization
|
|
|
345
381
|
never starts replacement work. An incomplete rollback leaves `.firstdraft-root-output` and requires journal
|
|
346
382
|
reconciliation before this command can run again.
|
|
347
383
|
|
|
348
|
-
Artifact validation accepts only Plan format `firstdraft.foundation-plan.sketch/0.
|
|
384
|
+
Artifact validation accepts only Plan format `firstdraft.foundation-plan.sketch/0.22` and target profile
|
|
349
385
|
`rails-sketch/2026-09`, in addition to matching the retained Compilation's provenance and verifying file integrity.
|
|
350
386
|
An earlier format or profile is rejected before materialization, even when the retained status names that profile.
|
|
351
387
|
|
package/docs/errors.md
CHANGED
|
@@ -14,6 +14,18 @@ errors, or unvalidated response bodies. `local_state_not_saved` is the sole exce
|
|
|
14
14
|
its `recovery_state` is required to repair the accepted ETag locally. Root-level and command-group usage failures
|
|
15
15
|
remain human-readable text on standard error with exit 2. Unexpected programming defects remain loud.
|
|
16
16
|
|
|
17
|
+
## Environment and credential errors
|
|
18
|
+
|
|
19
|
+
`invalid_configuration` stops before a request when `--staging` conflicts with `FIRSTDRAFT_API_URL` or a Project's
|
|
20
|
+
saved origin. Push and Compile also reject any URL override that differs from that pin. Unset the conflicting
|
|
21
|
+
override or use a separate initialized project directory for the other environment; do not redirect existing
|
|
22
|
+
private Project state. Status and retained download commands continue using their pin.
|
|
23
|
+
|
|
24
|
+
`authentication_required` means the selected environment's token is missing or rejected. Staging requires
|
|
25
|
+
`FIRSTDRAFT_STAGING_API_TOKEN`, including old staging Projects with no flag. Production and custom origins require
|
|
26
|
+
`FIRSTDRAFT_API_TOKEN`. The CLI never substitutes one for the other. Obtain or refresh the credential from the
|
|
27
|
+
same environment, then follow the command's recovery instructions below.
|
|
28
|
+
|
|
17
29
|
## Ambiguous mutations
|
|
18
30
|
|
|
19
31
|
`plan compile` supplies `phase: "push" | "compilation" | "publication"` when `request_outcome_unknown` requires
|
|
@@ -110,7 +122,7 @@ stopped without following the replacement.
|
|
|
110
122
|
| -------------------------------------------- | -------------------------------------------------------------------------------------------------- | ---: | ------------------------------------------------------------------------------------------------------ |
|
|
111
123
|
| Any leaf command | `invalid_arguments` | 2 | Syntax was invalid; no request was made. |
|
|
112
124
|
| `plan init` | `local_initialization_failed` | 1 | Initialization failed without overwriting an existing path. |
|
|
113
|
-
|
|
|
125
|
+
| Network commands | `invalid_configuration` | 2 | API origin or saved Head state is incompatible. |
|
|
114
126
|
| Network commands | `authentication_required` | 1 | The token is missing or First Draft returned a validated authentication problem. |
|
|
115
127
|
| Plan commands, `compilation *` | `local_input_unreadable` | 1 | Required local Plan or private state could not be read. |
|
|
116
128
|
| Status, Compile, Compilation commands | `project_not_pushed` | 1 | No API origin is pinned for the local Project. |
|
package/docs/release-history.md
CHANGED
|
@@ -5,6 +5,22 @@ npm, GitHub, service, or qualification state. Before acting, recheck the registr
|
|
|
5
5
|
compatibility declarations, trusted-publisher relationship, and named release-specific qualification by following
|
|
6
6
|
the living [release policy and runbook](../RELEASING.md).
|
|
7
7
|
|
|
8
|
+
## 0.4.0 local-output release
|
|
9
|
+
|
|
10
|
+
- On September 23, 2026 UTC, protected tag `v0.4.0` published CLI `0.4.0` from
|
|
11
|
+
`a555f8d39862109b8c28b392c0439470e88f4ba8` directly to `latest` through
|
|
12
|
+
[GitHub trusted publishing](https://github.com/firstdraft/cli/actions/runs/35807891432).
|
|
13
|
+
- `plan compile` now defaults to current-folder output, equivalent to `--output .`. GitHub Publication requires
|
|
14
|
+
`--github`. API compatibility remains `0.4.x`; this is a breaking CLI-default change from `0.3.x`.
|
|
15
|
+
- npm SHA-1 is `65b6b960b9029cb8f2352273db9fb551132f2ac9`. Public exact-version installation reported `0.4.0`, and
|
|
16
|
+
registry signature and provenance verification passed. `latest` selected `0.4.0`; `next` remained `0.3.0`.
|
|
17
|
+
- The packed candidate compiled a reviewed Reading List Plan against service `2bfdf6bf`, materialized 360 files at
|
|
18
|
+
the local root, and passed local Rails boot, browser creation, and source-edit refresh. Existing warnings and gaps
|
|
19
|
+
remained disclosed. No Codespace, GitHub Publication, native build, or Revyl session was part of this release smoke.
|
|
20
|
+
- Plugin `0.4.0` bundles this exact CLI source. Its publication workflow matched all 27 files with the registry CLI.
|
|
21
|
+
The [plugin release record](https://github.com/firstdraft/skills/blob/main/evidence/2026-09-22-plugin-0.4.0-release.md)
|
|
22
|
+
records the companion package, catalog, and post-publication Drawing Board follow-up.
|
|
23
|
+
|
|
8
24
|
## 0.1.0 alpha publications
|
|
9
25
|
|
|
10
26
|
- On July 31, 2026, npm rejected the unscoped `firstdraft` name for `v0.1.0-alpha.1` as too similar to the existing
|
package/package.json
CHANGED
|
@@ -1,20 +1,65 @@
|
|
|
1
|
+
import { PlanStateConfigurationError, normalizeApiUrl } from "./plan-state.js";
|
|
2
|
+
|
|
3
|
+
export const STAGING_API_URL = "https://staging.firstdraft.com";
|
|
4
|
+
|
|
5
|
+
export class ApiAuthenticationRequiredError extends Error {}
|
|
6
|
+
|
|
1
7
|
/**
|
|
2
|
-
* @param {
|
|
3
|
-
* @param {
|
|
4
|
-
* @
|
|
8
|
+
* @param {object} options
|
|
9
|
+
* @param {typeof globalThis.fetch} [options.fetchFunction]
|
|
10
|
+
* @param {string} [options.apiToken]
|
|
11
|
+
* @param {string} [options.stagingApiToken]
|
|
12
|
+
* @param {string} [options.apiUrl]
|
|
13
|
+
* @param {boolean} [options.staging]
|
|
5
14
|
*/
|
|
6
|
-
export function
|
|
7
|
-
|
|
15
|
+
export function authenticateApiCommand({
|
|
16
|
+
fetchFunction,
|
|
17
|
+
apiToken,
|
|
18
|
+
stagingApiToken,
|
|
19
|
+
apiUrl,
|
|
20
|
+
staging = false,
|
|
21
|
+
}) {
|
|
22
|
+
if (
|
|
23
|
+
staging &&
|
|
24
|
+
apiUrl !== undefined &&
|
|
25
|
+
normalizeApiUrl(apiUrl) !== STAGING_API_URL
|
|
26
|
+
) {
|
|
27
|
+
throw new PlanStateConfigurationError(
|
|
28
|
+
"--staging conflicts with FIRSTDRAFT_API_URL. Unset it or select the staging origin.",
|
|
29
|
+
);
|
|
30
|
+
}
|
|
8
31
|
|
|
32
|
+
const configured = staging ? STAGING_API_URL : apiUrl;
|
|
33
|
+
if (!hasToken(apiToken) && !hasToken(stagingApiToken)) return null;
|
|
34
|
+
|
|
35
|
+
let selectedOrigin = staging ? STAGING_API_URL : undefined;
|
|
9
36
|
const request = fetchFunction ?? globalThis.fetch;
|
|
10
|
-
|
|
11
|
-
|
|
37
|
+
/** @type {typeof globalThis.fetch} */
|
|
38
|
+
const authorizedFetch = (input, init) => {
|
|
39
|
+
const endpoint = new URL(input instanceof Request ? input.url : input);
|
|
40
|
+
if (selectedOrigin !== undefined && endpoint.origin !== selectedOrigin) {
|
|
41
|
+
throw new PlanStateConfigurationError(
|
|
42
|
+
"The requested API environment does not match the Project origin. No request was made.",
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
const token =
|
|
46
|
+
endpoint.origin === STAGING_API_URL ? stagingApiToken : apiToken;
|
|
47
|
+
if (!hasToken(token)) throw new ApiAuthenticationRequiredError();
|
|
48
|
+
selectedOrigin = endpoint.origin;
|
|
49
|
+
return request(input, {
|
|
12
50
|
...init,
|
|
13
51
|
headers: {
|
|
14
52
|
...init?.headers,
|
|
15
|
-
Authorization: `Bearer ${
|
|
53
|
+
Authorization: `Bearer ${token}`,
|
|
16
54
|
},
|
|
17
55
|
});
|
|
56
|
+
};
|
|
57
|
+
return { apiUrl: configured, fetchFunction: authorizedFetch };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** @param {string | undefined} token */
|
|
61
|
+
function hasToken(token) {
|
|
62
|
+
return token !== undefined && token.trim().length > 0;
|
|
18
63
|
}
|
|
19
64
|
|
|
20
65
|
/**
|
package/src/api-response.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { ApiAuthenticationRequiredError } from "./api-authentication.js";
|
|
2
|
+
import { PlanStateConfigurationError } from "./plan-state.js";
|
|
3
|
+
|
|
1
4
|
const MAX_RESPONSE_BYTES = 2 * 1024 * 1024;
|
|
2
5
|
|
|
3
6
|
export class FirstDraftNetworkError extends Error {
|
|
@@ -28,6 +31,11 @@ export async function sendRequest(fetchFunction, endpoint, request) {
|
|
|
28
31
|
try {
|
|
29
32
|
return await fetchFunction(endpoint, request);
|
|
30
33
|
} catch (error) {
|
|
34
|
+
if (
|
|
35
|
+
error instanceof PlanStateConfigurationError ||
|
|
36
|
+
error instanceof ApiAuthenticationRequiredError
|
|
37
|
+
)
|
|
38
|
+
throw error;
|
|
31
39
|
if (!(error instanceof Error)) throw error;
|
|
32
40
|
|
|
33
41
|
throw new FirstDraftNetworkError("The First Draft request failed.", {
|
package/src/cli.js
CHANGED
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
isValidApplicationName,
|
|
8
8
|
} from "./application-identity.js";
|
|
9
9
|
import {
|
|
10
|
-
|
|
10
|
+
ApiAuthenticationRequiredError,
|
|
11
|
+
authenticateApiCommand,
|
|
11
12
|
isAuthenticationProblem,
|
|
12
13
|
} from "./api-authentication.js";
|
|
13
14
|
import {
|
|
@@ -78,7 +79,7 @@ import { VERSION } from "./version.js";
|
|
|
78
79
|
const ROOT_HELP = `First Draft CLI
|
|
79
80
|
|
|
80
81
|
Usage:
|
|
81
|
-
firstdraft <command> [options]
|
|
82
|
+
firstdraft [--staging] <command> [options]
|
|
82
83
|
firstdraft [options]
|
|
83
84
|
|
|
84
85
|
Commands:
|
|
@@ -87,6 +88,7 @@ Commands:
|
|
|
87
88
|
plan Work with Foundation Plans
|
|
88
89
|
|
|
89
90
|
Options:
|
|
91
|
+
--staging Use staging for API commands (production is the default)
|
|
90
92
|
-h, --help Show help
|
|
91
93
|
-V, --version Show version
|
|
92
94
|
`;
|
|
@@ -151,11 +153,13 @@ Usage:
|
|
|
151
153
|
firstdraft plan push
|
|
152
154
|
|
|
153
155
|
Options:
|
|
154
|
-
|
|
156
|
+
--staging Use staging; reject a different saved origin
|
|
157
|
+
-h, --help Show help
|
|
155
158
|
|
|
156
159
|
Environment:
|
|
157
|
-
FIRSTDRAFT_API_TOKEN
|
|
158
|
-
|
|
160
|
+
FIRSTDRAFT_API_TOKEN Authenticate production or custom API origins
|
|
161
|
+
FIRSTDRAFT_STAGING_API_TOKEN Authenticate staging.firstdraft.com
|
|
162
|
+
FIRSTDRAFT_API_URL Override the initial API origin
|
|
159
163
|
|
|
160
164
|
The first successful push saves its API origin in .firstdraft/state.json.
|
|
161
165
|
Later pushes reject a different origin.
|
|
@@ -167,11 +171,13 @@ Usage:
|
|
|
167
171
|
firstdraft plan status [--wait]
|
|
168
172
|
|
|
169
173
|
Options:
|
|
170
|
-
--
|
|
171
|
-
|
|
174
|
+
--staging Use staging; reject a different saved origin
|
|
175
|
+
--wait Poll until the current analysis reaches a terminal status
|
|
176
|
+
-h, --help Show help
|
|
172
177
|
|
|
173
178
|
Environment:
|
|
174
|
-
FIRSTDRAFT_API_TOKEN
|
|
179
|
+
FIRSTDRAFT_API_TOKEN Authenticate production or custom API origins
|
|
180
|
+
FIRSTDRAFT_STAGING_API_TOKEN Authenticate staging.firstdraft.com
|
|
175
181
|
|
|
176
182
|
The command uses only the API origin pinned by a successful plan push.
|
|
177
183
|
Without --wait, it makes exactly one status request.
|
|
@@ -185,13 +191,15 @@ Usage:
|
|
|
185
191
|
firstdraft plan compile --github
|
|
186
192
|
|
|
187
193
|
Options:
|
|
194
|
+
--staging Use staging; reject a different saved origin
|
|
188
195
|
--output <absent-directory|.> Materialize here (default: .)
|
|
189
|
-
--github
|
|
196
|
+
--github Publish to a private GitHub repository
|
|
190
197
|
-h, --help Show help
|
|
191
198
|
|
|
192
199
|
Environment:
|
|
193
|
-
FIRSTDRAFT_API_TOKEN
|
|
194
|
-
|
|
200
|
+
FIRSTDRAFT_API_TOKEN Authenticate production or custom API origins
|
|
201
|
+
FIRSTDRAFT_STAGING_API_TOKEN Authenticate staging.firstdraft.com
|
|
202
|
+
FIRSTDRAFT_API_URL Override the initial API origin
|
|
195
203
|
|
|
196
204
|
The command submits the exact current whole-file Plan, waits for its analysis,
|
|
197
205
|
and proceeds only when that analysis is valid. By default it materializes the
|
|
@@ -220,11 +228,13 @@ Usage:
|
|
|
220
228
|
firstdraft compilation status <compilation-id> [--wait]
|
|
221
229
|
|
|
222
230
|
Options:
|
|
223
|
-
--
|
|
224
|
-
|
|
231
|
+
--staging Use staging; reject a different saved origin
|
|
232
|
+
--wait Poll until the Compilation reaches a terminal status
|
|
233
|
+
-h, --help Show help
|
|
225
234
|
|
|
226
235
|
Environment:
|
|
227
|
-
FIRSTDRAFT_API_TOKEN
|
|
236
|
+
FIRSTDRAFT_API_TOKEN Authenticate production or custom API origins
|
|
237
|
+
FIRSTDRAFT_STAGING_API_TOKEN Authenticate staging.firstdraft.com
|
|
228
238
|
|
|
229
239
|
Without --wait, the command makes exactly one metadata-only GET. With --wait,
|
|
230
240
|
it polls the same retained Compilation for at most ten minutes. Failed and
|
|
@@ -237,11 +247,13 @@ Usage:
|
|
|
237
247
|
firstdraft compilation download <compilation-id> --output <absent-path|.>
|
|
238
248
|
|
|
239
249
|
Options:
|
|
250
|
+
--staging Use staging; reject a different saved origin
|
|
240
251
|
--output <absent-path|.> Materialize the generated application here
|
|
241
|
-
-h, --help
|
|
252
|
+
-h, --help Show help
|
|
242
253
|
|
|
243
254
|
Environment:
|
|
244
|
-
FIRSTDRAFT_API_TOKEN
|
|
255
|
+
FIRSTDRAFT_API_TOKEN Authenticate production or custom API origins
|
|
256
|
+
FIRSTDRAFT_STAGING_API_TOKEN Authenticate staging.firstdraft.com
|
|
245
257
|
|
|
246
258
|
The command reads the retained Compilation once, requires it to have
|
|
247
259
|
succeeded, downloads and verifies its exact artifact once, and atomically
|
|
@@ -286,15 +298,13 @@ const PLAN_INIT_FAILED_DETAIL =
|
|
|
286
298
|
const PLAN_INIT_SUCCESS = "Initialized .firstdraft/foundation-plan.json.\n";
|
|
287
299
|
const PLAN_PUSH_INVALID_ARGUMENTS_DETAIL =
|
|
288
300
|
"Invalid arguments. Run 'firstdraft plan push --help' for usage.";
|
|
289
|
-
const PLAN_PUSH_INVALID_CONFIGURATION_DETAIL =
|
|
290
|
-
"Invalid First Draft API configuration. Run 'firstdraft plan push --help' for usage.";
|
|
291
301
|
const PLAN_PUSH_LOCAL_INPUT_UNREADABLE_DETAIL =
|
|
292
302
|
"Could not read the local First Draft Plan or state. No network request was made. Preserve the local files for manual recovery.";
|
|
293
303
|
const PLAN_PUSH_REQUEST_OUTCOME_UNKNOWN_DETAIL =
|
|
294
304
|
"The Plan may have been accepted, but the response could not be verified. Stop and reconcile before pushing again; local state was not changed.";
|
|
295
305
|
const PLAN_PUSH_SERVER_REJECTED_DETAIL = "First Draft rejected the Plan.";
|
|
296
306
|
const AUTHENTICATION_REQUIRED_DETAIL =
|
|
297
|
-
"First Draft authentication is required. Set FIRSTDRAFT_API_TOKEN
|
|
307
|
+
"First Draft authentication is required. Set FIRSTDRAFT_API_TOKEN for production or custom origins, or FIRSTDRAFT_STAGING_API_TOKEN for staging.";
|
|
298
308
|
const PLAN_STATUS_INVALID_ARGUMENTS_DETAIL =
|
|
299
309
|
"Invalid arguments. Run 'firstdraft plan status --help' for usage.";
|
|
300
310
|
const PLAN_STATUS_LOCAL_INPUT_UNREADABLE_DETAIL =
|
|
@@ -315,8 +325,6 @@ const PLAN_COMPILE_INVALID_ARGUMENTS_DETAIL =
|
|
|
315
325
|
"Invalid arguments. Run 'firstdraft plan compile --help' for usage.";
|
|
316
326
|
const PLAN_COMPILE_LOCAL_INPUT_UNREADABLE_DETAIL =
|
|
317
327
|
"Could not read the local First Draft Plan or state. No network request was made. Preserve the local files for manual recovery.";
|
|
318
|
-
const PLAN_COMPILE_INCOMPATIBLE_STATE_DETAIL =
|
|
319
|
-
"The configured API origin or saved Foundation Plan state is incompatible with compilation. No network request was made.";
|
|
320
328
|
const PLAN_COMPILE_NOT_PUSHED_DETAIL =
|
|
321
329
|
"The current Foundation Plan could not be associated with a pushed Project.";
|
|
322
330
|
const PLAN_COMPILE_REQUEST_OUTCOME_UNKNOWN_DETAIL =
|
|
@@ -436,6 +444,7 @@ const GENERATE_APPLICATION_KEY_INVALID_ARGUMENTS_DETAIL =
|
|
|
436
444
|
* @property {typeof import("./commands/compilation.js").compileAndDownload} [planCompileDownload]
|
|
437
445
|
* @property {string} [apiUrl]
|
|
438
446
|
* @property {string} [apiToken]
|
|
447
|
+
* @property {string} [stagingApiToken]
|
|
439
448
|
*/
|
|
440
449
|
|
|
441
450
|
/**
|
|
@@ -465,6 +474,8 @@ const GENERATE_APPLICATION_KEY_INVALID_ARGUMENTS_DETAIL =
|
|
|
465
474
|
* @property {typeof import("./commands/compilation.js").compileAndDownload} [planCompileDownload]
|
|
466
475
|
* @property {string} [apiUrl]
|
|
467
476
|
* @property {string} [apiToken]
|
|
477
|
+
* @property {string} [stagingApiToken]
|
|
478
|
+
* @property {boolean} [staging]
|
|
468
479
|
*/
|
|
469
480
|
|
|
470
481
|
/**
|
|
@@ -476,7 +487,7 @@ const GENERATE_APPLICATION_KEY_INVALID_ARGUMENTS_DETAIL =
|
|
|
476
487
|
*/
|
|
477
488
|
|
|
478
489
|
/**
|
|
479
|
-
* @typedef {Omit<CommandOptions, "cwd" | "createProjectId" | "createUuid" | "fileSystem" | "createTemporaryId" | "planStatusSleep" | "planStatusNow" | "planCompileSleep" | "planCompileNow" | "planPublishSleep" | "planPublishNow" | "
|
|
490
|
+
* @typedef {Omit<CommandOptions, "cwd" | "createProjectId" | "createUuid" | "fileSystem" | "createTemporaryId" | "planStatusSleep" | "planStatusNow" | "planCompileSleep" | "planCompileNow" | "planPublishSleep" | "planPublishNow" | "planCompilePush" | "planCompileReadStatus" | "planCompilePublish" | "planCompileDownload"> & {cwd?: string, getCwd: () => string}} CompilationCommandOptions
|
|
480
491
|
*/
|
|
481
492
|
|
|
482
493
|
/** @param {RunOptions} options */
|
|
@@ -507,7 +518,11 @@ export async function run({
|
|
|
507
518
|
planCompileDownload,
|
|
508
519
|
apiUrl = process.env.FIRSTDRAFT_API_URL,
|
|
509
520
|
apiToken = process.env.FIRSTDRAFT_API_TOKEN,
|
|
521
|
+
stagingApiToken = process.env.FIRSTDRAFT_STAGING_API_TOKEN,
|
|
510
522
|
}) {
|
|
523
|
+
const staging = argv[0] === "--staging";
|
|
524
|
+
if (staging) argv = argv.slice(1);
|
|
525
|
+
|
|
511
526
|
if (argv[0] === "generate") {
|
|
512
527
|
return runGenerate({
|
|
513
528
|
argv: argv.slice(1),
|
|
@@ -544,6 +559,8 @@ export async function run({
|
|
|
544
559
|
planCompileDownload,
|
|
545
560
|
apiUrl,
|
|
546
561
|
apiToken,
|
|
562
|
+
stagingApiToken,
|
|
563
|
+
staging,
|
|
547
564
|
});
|
|
548
565
|
}
|
|
549
566
|
|
|
@@ -559,7 +576,10 @@ export async function run({
|
|
|
559
576
|
createRequestSignal,
|
|
560
577
|
compilationSleep,
|
|
561
578
|
compilationNow,
|
|
579
|
+
apiUrl,
|
|
562
580
|
apiToken,
|
|
581
|
+
stagingApiToken,
|
|
582
|
+
staging,
|
|
563
583
|
});
|
|
564
584
|
}
|
|
565
585
|
|
|
@@ -636,6 +656,8 @@ async function runPlan({
|
|
|
636
656
|
planCompileDownload,
|
|
637
657
|
apiUrl,
|
|
638
658
|
apiToken,
|
|
659
|
+
stagingApiToken,
|
|
660
|
+
staging,
|
|
639
661
|
}) {
|
|
640
662
|
if (argv[0] === "init") {
|
|
641
663
|
return runPlanInit({
|
|
@@ -660,6 +682,8 @@ async function runPlan({
|
|
|
660
682
|
createRequestSignal,
|
|
661
683
|
apiUrl,
|
|
662
684
|
apiToken,
|
|
685
|
+
stagingApiToken,
|
|
686
|
+
staging,
|
|
663
687
|
});
|
|
664
688
|
}
|
|
665
689
|
|
|
@@ -674,7 +698,10 @@ async function runPlan({
|
|
|
674
698
|
createRequestSignal,
|
|
675
699
|
planStatusSleep,
|
|
676
700
|
planStatusNow,
|
|
701
|
+
apiUrl,
|
|
677
702
|
apiToken,
|
|
703
|
+
stagingApiToken,
|
|
704
|
+
staging,
|
|
678
705
|
});
|
|
679
706
|
}
|
|
680
707
|
|
|
@@ -700,6 +727,8 @@ async function runPlan({
|
|
|
700
727
|
planCompileDownload,
|
|
701
728
|
apiUrl,
|
|
702
729
|
apiToken,
|
|
730
|
+
stagingApiToken,
|
|
731
|
+
staging,
|
|
703
732
|
});
|
|
704
733
|
}
|
|
705
734
|
|
|
@@ -743,7 +772,10 @@ async function runCompilation({
|
|
|
743
772
|
createRequestSignal,
|
|
744
773
|
compilationSleep,
|
|
745
774
|
compilationNow,
|
|
775
|
+
apiUrl,
|
|
746
776
|
apiToken,
|
|
777
|
+
stagingApiToken,
|
|
778
|
+
staging,
|
|
747
779
|
}) {
|
|
748
780
|
if (argv[0] === "status") {
|
|
749
781
|
return runCompilationStatus({
|
|
@@ -756,7 +788,10 @@ async function runCompilation({
|
|
|
756
788
|
createRequestSignal,
|
|
757
789
|
compilationSleep,
|
|
758
790
|
compilationNow,
|
|
791
|
+
apiUrl,
|
|
759
792
|
apiToken,
|
|
793
|
+
stagingApiToken,
|
|
794
|
+
staging,
|
|
760
795
|
});
|
|
761
796
|
}
|
|
762
797
|
|
|
@@ -769,7 +804,10 @@ async function runCompilation({
|
|
|
769
804
|
fetchFunction,
|
|
770
805
|
planPushFileSystem,
|
|
771
806
|
createRequestSignal,
|
|
807
|
+
apiUrl,
|
|
772
808
|
apiToken,
|
|
809
|
+
stagingApiToken,
|
|
810
|
+
staging,
|
|
773
811
|
});
|
|
774
812
|
}
|
|
775
813
|
|
|
@@ -802,7 +840,7 @@ async function runCompilation({
|
|
|
802
840
|
}
|
|
803
841
|
|
|
804
842
|
/**
|
|
805
|
-
* @param {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "cwd" | "fetchFunction" | "planPushFileSystem" | "createRequestSignal" | "compilationSleep" | "compilationNow" | "apiToken">} options
|
|
843
|
+
* @param {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "cwd" | "fetchFunction" | "planPushFileSystem" | "createRequestSignal" | "compilationSleep" | "compilationNow" | "apiUrl" | "apiToken" | "stagingApiToken" | "staging">} options
|
|
806
844
|
*/
|
|
807
845
|
async function runCompilationStatus({
|
|
808
846
|
argv,
|
|
@@ -814,12 +852,16 @@ async function runCompilationStatus({
|
|
|
814
852
|
createRequestSignal,
|
|
815
853
|
compilationSleep,
|
|
816
854
|
compilationNow,
|
|
855
|
+
apiUrl,
|
|
817
856
|
apiToken,
|
|
857
|
+
stagingApiToken,
|
|
858
|
+
staging,
|
|
818
859
|
}) {
|
|
819
860
|
const parsed = parseArguments(() =>
|
|
820
861
|
parseArgs({
|
|
821
862
|
args: [...argv],
|
|
822
863
|
options: {
|
|
864
|
+
staging: { type: "boolean" },
|
|
823
865
|
wait: { type: "boolean" },
|
|
824
866
|
help: { type: "boolean", short: "h" },
|
|
825
867
|
},
|
|
@@ -851,18 +893,23 @@ async function runCompilationStatus({
|
|
|
851
893
|
return 2;
|
|
852
894
|
}
|
|
853
895
|
|
|
854
|
-
const authorizedFetch = authenticatedFetch(fetchFunction, apiToken);
|
|
855
|
-
if (authorizedFetch === null) {
|
|
856
|
-
writeAuthenticationRequired(stderr);
|
|
857
|
-
return 1;
|
|
858
|
-
}
|
|
859
|
-
|
|
860
896
|
try {
|
|
897
|
+
const authentication = authenticateApiCommand({
|
|
898
|
+
fetchFunction,
|
|
899
|
+
apiUrl,
|
|
900
|
+
apiToken,
|
|
901
|
+
stagingApiToken,
|
|
902
|
+
staging: staging || parsed.values.staging,
|
|
903
|
+
});
|
|
904
|
+
if (authentication === null) {
|
|
905
|
+
writeAuthenticationRequired(stderr);
|
|
906
|
+
return 1;
|
|
907
|
+
}
|
|
861
908
|
const result = await readCompilation({
|
|
862
909
|
cwd,
|
|
863
910
|
compilationId,
|
|
864
911
|
wait: parsed.values.wait,
|
|
865
|
-
fetchFunction:
|
|
912
|
+
fetchFunction: authentication.fetchFunction,
|
|
866
913
|
fileSystem: planPushFileSystem,
|
|
867
914
|
createRequestSignal,
|
|
868
915
|
sleep: compilationSleep,
|
|
@@ -878,7 +925,7 @@ async function runCompilationStatus({
|
|
|
878
925
|
}
|
|
879
926
|
|
|
880
927
|
/**
|
|
881
|
-
* @param {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "cwd" | "fetchFunction" | "planPushFileSystem" | "createRequestSignal" | "apiToken">} options
|
|
928
|
+
* @param {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "cwd" | "fetchFunction" | "planPushFileSystem" | "createRequestSignal" | "apiUrl" | "apiToken" | "stagingApiToken" | "staging">} options
|
|
882
929
|
*/
|
|
883
930
|
async function runCompilationDownload({
|
|
884
931
|
argv,
|
|
@@ -888,12 +935,16 @@ async function runCompilationDownload({
|
|
|
888
935
|
fetchFunction,
|
|
889
936
|
planPushFileSystem,
|
|
890
937
|
createRequestSignal,
|
|
938
|
+
apiUrl,
|
|
891
939
|
apiToken,
|
|
940
|
+
stagingApiToken,
|
|
941
|
+
staging,
|
|
892
942
|
}) {
|
|
893
943
|
const parsed = parseArguments(() =>
|
|
894
944
|
parseArgs({
|
|
895
945
|
args: [...argv],
|
|
896
946
|
options: {
|
|
947
|
+
staging: { type: "boolean" },
|
|
897
948
|
output: { type: "string" },
|
|
898
949
|
help: { type: "boolean", short: "h" },
|
|
899
950
|
},
|
|
@@ -931,18 +982,23 @@ async function runCompilationDownload({
|
|
|
931
982
|
return 2;
|
|
932
983
|
}
|
|
933
984
|
|
|
934
|
-
const authorizedFetch = authenticatedFetch(fetchFunction, apiToken);
|
|
935
|
-
if (authorizedFetch === null) {
|
|
936
|
-
writeAuthenticationRequired(stderr);
|
|
937
|
-
return 1;
|
|
938
|
-
}
|
|
939
|
-
|
|
940
985
|
try {
|
|
986
|
+
const authentication = authenticateApiCommand({
|
|
987
|
+
fetchFunction,
|
|
988
|
+
apiUrl,
|
|
989
|
+
apiToken,
|
|
990
|
+
stagingApiToken,
|
|
991
|
+
staging: staging || parsed.values.staging,
|
|
992
|
+
});
|
|
993
|
+
if (authentication === null) {
|
|
994
|
+
writeAuthenticationRequired(stderr);
|
|
995
|
+
return 1;
|
|
996
|
+
}
|
|
941
997
|
const result = await downloadCompilation({
|
|
942
998
|
cwd,
|
|
943
999
|
compilationId,
|
|
944
1000
|
output,
|
|
945
|
-
fetchFunction:
|
|
1001
|
+
fetchFunction: authentication.fetchFunction,
|
|
946
1002
|
fileSystem: planPushFileSystem,
|
|
947
1003
|
createRequestSignal,
|
|
948
1004
|
});
|
|
@@ -1027,6 +1083,19 @@ function writeCompilationInvalidArguments(writer, detail) {
|
|
|
1027
1083
|
* @param {boolean} [throwUnknown]
|
|
1028
1084
|
*/
|
|
1029
1085
|
function writeCompilationReadError(writer, error, throwUnknown = true) {
|
|
1086
|
+
if (error instanceof ApiAuthenticationRequiredError) {
|
|
1087
|
+
writeAuthenticationRequired(writer);
|
|
1088
|
+
return 1;
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
if (error instanceof PlanPushConfigurationError) {
|
|
1092
|
+
writeJson(writer, {
|
|
1093
|
+
error: "invalid_configuration",
|
|
1094
|
+
detail: error.message,
|
|
1095
|
+
});
|
|
1096
|
+
return 2;
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1030
1099
|
if (error instanceof PlanPushLocalError) {
|
|
1031
1100
|
writeJson(writer, {
|
|
1032
1101
|
error: "local_input_unreadable",
|
|
@@ -1227,7 +1296,7 @@ function runGenerateApplicationKey({ argv, stdout, stderr }) {
|
|
|
1227
1296
|
}
|
|
1228
1297
|
|
|
1229
1298
|
/**
|
|
1230
|
-
* @param {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "cwd" | "fetchFunction" | "planPushFileSystem" | "createTemporaryId" | "createRequestSignal" | "apiUrl" | "apiToken">} options
|
|
1299
|
+
* @param {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "cwd" | "fetchFunction" | "planPushFileSystem" | "createTemporaryId" | "createRequestSignal" | "apiUrl" | "apiToken" | "stagingApiToken" | "staging">} options
|
|
1231
1300
|
*/
|
|
1232
1301
|
async function runPlanPush({
|
|
1233
1302
|
argv,
|
|
@@ -1240,11 +1309,16 @@ async function runPlanPush({
|
|
|
1240
1309
|
createRequestSignal,
|
|
1241
1310
|
apiUrl,
|
|
1242
1311
|
apiToken,
|
|
1312
|
+
stagingApiToken,
|
|
1313
|
+
staging,
|
|
1243
1314
|
}) {
|
|
1244
1315
|
const parsed = parseArguments(() =>
|
|
1245
1316
|
parseArgs({
|
|
1246
1317
|
args: [...argv],
|
|
1247
|
-
options: {
|
|
1318
|
+
options: {
|
|
1319
|
+
staging: { type: "boolean" },
|
|
1320
|
+
help: { type: "boolean", short: "h" },
|
|
1321
|
+
},
|
|
1248
1322
|
allowPositionals: false,
|
|
1249
1323
|
strict: true,
|
|
1250
1324
|
tokens: true,
|
|
@@ -1264,27 +1338,37 @@ async function runPlanPush({
|
|
|
1264
1338
|
return 0;
|
|
1265
1339
|
}
|
|
1266
1340
|
|
|
1267
|
-
const authorizedFetch = authenticatedFetch(fetchFunction, apiToken);
|
|
1268
|
-
if (authorizedFetch === null) {
|
|
1269
|
-
writeAuthenticationRequired(stderr);
|
|
1270
|
-
return 1;
|
|
1271
|
-
}
|
|
1272
|
-
|
|
1273
1341
|
let result;
|
|
1274
1342
|
try {
|
|
1343
|
+
const authentication = authenticateApiCommand({
|
|
1344
|
+
fetchFunction,
|
|
1345
|
+
apiUrl,
|
|
1346
|
+
apiToken,
|
|
1347
|
+
stagingApiToken,
|
|
1348
|
+
staging: staging || parsed.values.staging,
|
|
1349
|
+
});
|
|
1350
|
+
if (authentication === null) {
|
|
1351
|
+
writeAuthenticationRequired(stderr);
|
|
1352
|
+
return 1;
|
|
1353
|
+
}
|
|
1275
1354
|
result = await pushPlan({
|
|
1276
1355
|
cwd,
|
|
1277
|
-
apiUrl,
|
|
1278
|
-
fetchFunction:
|
|
1356
|
+
apiUrl: authentication.apiUrl,
|
|
1357
|
+
fetchFunction: authentication.fetchFunction,
|
|
1279
1358
|
fileSystem: planPushFileSystem,
|
|
1280
1359
|
createTemporaryId,
|
|
1281
1360
|
createRequestSignal,
|
|
1282
1361
|
});
|
|
1283
1362
|
} catch (error) {
|
|
1363
|
+
if (error instanceof ApiAuthenticationRequiredError) {
|
|
1364
|
+
writeAuthenticationRequired(stderr);
|
|
1365
|
+
return 1;
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1284
1368
|
if (error instanceof PlanPushConfigurationError) {
|
|
1285
1369
|
writeJson(stderr, {
|
|
1286
1370
|
error: "invalid_configuration",
|
|
1287
|
-
detail:
|
|
1371
|
+
detail: error.message,
|
|
1288
1372
|
});
|
|
1289
1373
|
return 2;
|
|
1290
1374
|
}
|
|
@@ -1357,7 +1441,7 @@ async function runPlanPush({
|
|
|
1357
1441
|
}
|
|
1358
1442
|
|
|
1359
1443
|
/**
|
|
1360
|
-
* @param {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "cwd" | "fetchFunction" | "planPushFileSystem" | "createRequestSignal" | "planStatusSleep" | "planStatusNow" | "apiToken">} options
|
|
1444
|
+
* @param {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "cwd" | "fetchFunction" | "planPushFileSystem" | "createRequestSignal" | "planStatusSleep" | "planStatusNow" | "apiUrl" | "apiToken" | "stagingApiToken" | "staging">} options
|
|
1361
1445
|
*/
|
|
1362
1446
|
async function runPlanStatus({
|
|
1363
1447
|
argv,
|
|
@@ -1369,12 +1453,16 @@ async function runPlanStatus({
|
|
|
1369
1453
|
createRequestSignal,
|
|
1370
1454
|
planStatusSleep,
|
|
1371
1455
|
planStatusNow,
|
|
1456
|
+
apiUrl,
|
|
1372
1457
|
apiToken,
|
|
1458
|
+
stagingApiToken,
|
|
1459
|
+
staging,
|
|
1373
1460
|
}) {
|
|
1374
1461
|
const parsed = parseArguments(() =>
|
|
1375
1462
|
parseArgs({
|
|
1376
1463
|
args: [...argv],
|
|
1377
1464
|
options: {
|
|
1465
|
+
staging: { type: "boolean" },
|
|
1378
1466
|
help: { type: "boolean", short: "h" },
|
|
1379
1467
|
wait: { type: "boolean" },
|
|
1380
1468
|
},
|
|
@@ -1397,24 +1485,42 @@ async function runPlanStatus({
|
|
|
1397
1485
|
return 0;
|
|
1398
1486
|
}
|
|
1399
1487
|
|
|
1400
|
-
const authorizedFetch = authenticatedFetch(fetchFunction, apiToken);
|
|
1401
|
-
if (authorizedFetch === null) {
|
|
1402
|
-
writeAuthenticationRequired(stderr);
|
|
1403
|
-
return 1;
|
|
1404
|
-
}
|
|
1405
|
-
|
|
1406
1488
|
let result;
|
|
1407
1489
|
try {
|
|
1490
|
+
const authentication = authenticateApiCommand({
|
|
1491
|
+
fetchFunction,
|
|
1492
|
+
apiUrl,
|
|
1493
|
+
apiToken,
|
|
1494
|
+
stagingApiToken,
|
|
1495
|
+
staging: staging || parsed.values.staging,
|
|
1496
|
+
});
|
|
1497
|
+
if (authentication === null) {
|
|
1498
|
+
writeAuthenticationRequired(stderr);
|
|
1499
|
+
return 1;
|
|
1500
|
+
}
|
|
1408
1501
|
result = await readPlanStatus({
|
|
1409
1502
|
cwd,
|
|
1410
1503
|
wait: parsed.values.wait,
|
|
1411
|
-
fetchFunction:
|
|
1504
|
+
fetchFunction: authentication.fetchFunction,
|
|
1412
1505
|
fileSystem: planPushFileSystem,
|
|
1413
1506
|
createRequestSignal,
|
|
1414
1507
|
sleep: planStatusSleep,
|
|
1415
1508
|
now: planStatusNow,
|
|
1416
1509
|
});
|
|
1417
1510
|
} catch (error) {
|
|
1511
|
+
if (error instanceof ApiAuthenticationRequiredError) {
|
|
1512
|
+
writeAuthenticationRequired(stderr);
|
|
1513
|
+
return 1;
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
if (error instanceof PlanPushConfigurationError) {
|
|
1517
|
+
writeJson(stderr, {
|
|
1518
|
+
error: "invalid_configuration",
|
|
1519
|
+
detail: error.message,
|
|
1520
|
+
});
|
|
1521
|
+
return 2;
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1418
1524
|
if (error instanceof PlanPushLocalError) {
|
|
1419
1525
|
writeJson(stderr, {
|
|
1420
1526
|
error: "local_input_unreadable",
|
|
@@ -1499,7 +1605,7 @@ async function runPlanStatus({
|
|
|
1499
1605
|
}
|
|
1500
1606
|
|
|
1501
1607
|
/**
|
|
1502
|
-
* @param {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "cwd" | "fetchFunction" | "planPushFileSystem" | "createTemporaryId" | "createRequestSignal" | "planCompileSleep" | "planCompileNow" | "planPublishSleep" | "planPublishNow" | "compilationSleep" | "compilationNow" | "planCompilePush" | "planCompileReadStatus" | "planCompilePublish" | "planCompileDownload" | "apiUrl" | "apiToken">} options
|
|
1608
|
+
* @param {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "cwd" | "fetchFunction" | "planPushFileSystem" | "createTemporaryId" | "createRequestSignal" | "planCompileSleep" | "planCompileNow" | "planPublishSleep" | "planPublishNow" | "compilationSleep" | "compilationNow" | "planCompilePush" | "planCompileReadStatus" | "planCompilePublish" | "planCompileDownload" | "apiUrl" | "apiToken" | "stagingApiToken" | "staging">} options
|
|
1503
1609
|
*/
|
|
1504
1610
|
async function runPlanCompile({
|
|
1505
1611
|
argv,
|
|
@@ -1522,11 +1628,14 @@ async function runPlanCompile({
|
|
|
1522
1628
|
planCompileDownload,
|
|
1523
1629
|
apiUrl,
|
|
1524
1630
|
apiToken,
|
|
1631
|
+
stagingApiToken,
|
|
1632
|
+
staging,
|
|
1525
1633
|
}) {
|
|
1526
1634
|
const parsed = parseArguments(() =>
|
|
1527
1635
|
parseArgs({
|
|
1528
1636
|
args: [...argv],
|
|
1529
1637
|
options: {
|
|
1638
|
+
staging: { type: "boolean" },
|
|
1530
1639
|
output: { type: "string" },
|
|
1531
1640
|
github: { type: "boolean" },
|
|
1532
1641
|
help: { type: "boolean", short: "h" },
|
|
@@ -1559,17 +1668,28 @@ async function runPlanCompile({
|
|
|
1559
1668
|
return 2;
|
|
1560
1669
|
}
|
|
1561
1670
|
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1671
|
+
let authentication;
|
|
1672
|
+
try {
|
|
1673
|
+
authentication = authenticateApiCommand({
|
|
1674
|
+
fetchFunction,
|
|
1675
|
+
apiUrl,
|
|
1676
|
+
apiToken,
|
|
1677
|
+
stagingApiToken,
|
|
1678
|
+
staging: staging || parsed.values.staging,
|
|
1679
|
+
});
|
|
1680
|
+
if (authentication === null) {
|
|
1681
|
+
writeAuthenticationRequired(stderr);
|
|
1682
|
+
return 1;
|
|
1683
|
+
}
|
|
1684
|
+
} catch (error) {
|
|
1685
|
+
return writePlanCompileError(stderr, error);
|
|
1566
1686
|
}
|
|
1567
1687
|
|
|
1568
1688
|
const reportProgress = createPlanCompileProgressReporter(stderr);
|
|
1569
1689
|
const shared = {
|
|
1570
1690
|
cwd,
|
|
1571
|
-
apiUrl,
|
|
1572
|
-
fetchFunction:
|
|
1691
|
+
apiUrl: authentication.apiUrl,
|
|
1692
|
+
fetchFunction: authentication.fetchFunction,
|
|
1573
1693
|
fileSystem: planPushFileSystem,
|
|
1574
1694
|
createTemporaryId,
|
|
1575
1695
|
createRequestSignal,
|
|
@@ -1615,10 +1735,15 @@ async function runPlanCompile({
|
|
|
1615
1735
|
|
|
1616
1736
|
/** @param {Writer} writer @param {unknown} error */
|
|
1617
1737
|
function writePlanCompileError(writer, error) {
|
|
1738
|
+
if (error instanceof ApiAuthenticationRequiredError) {
|
|
1739
|
+
writeAuthenticationRequired(writer);
|
|
1740
|
+
return 1;
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1618
1743
|
if (error instanceof PlanPushConfigurationError) {
|
|
1619
1744
|
writeJson(writer, {
|
|
1620
1745
|
error: "invalid_configuration",
|
|
1621
|
-
detail:
|
|
1746
|
+
detail: error.message,
|
|
1622
1747
|
});
|
|
1623
1748
|
return 2;
|
|
1624
1749
|
}
|
|
@@ -1766,7 +1891,8 @@ function writePlanCompileError(writer, error) {
|
|
|
1766
1891
|
if (compilationError instanceof CompilationLocalStateError) {
|
|
1767
1892
|
writeJson(writer, {
|
|
1768
1893
|
error: "invalid_configuration",
|
|
1769
|
-
detail:
|
|
1894
|
+
detail:
|
|
1895
|
+
"The configured API origin or saved Foundation Plan state is incompatible with compilation. No network request was made.",
|
|
1770
1896
|
});
|
|
1771
1897
|
return 2;
|
|
1772
1898
|
}
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
export const ARTIFACT_MEDIA_TYPE =
|
|
27
27
|
"application/vnd.firstdraft.compilation-artifact+json";
|
|
28
28
|
export const ARTIFACT_FORMAT = "firstdraft.compilation-artifact/1";
|
|
29
|
-
export const FOUNDATION_PLAN_FORMAT = "firstdraft.foundation-plan.sketch/0.
|
|
29
|
+
export const FOUNDATION_PLAN_FORMAT = "firstdraft.foundation-plan.sketch/0.22";
|
|
30
30
|
export const RAILS_TARGET_PROFILE = "rails-sketch/2026-09";
|
|
31
31
|
export const MAX_ARTIFACT_BYTES = 128 * 1024 * 1024;
|
|
32
32
|
|