@firstdraft.com/cli 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -6
- package/docs/README.md +1 -1
- package/docs/commands.md +591 -119
- package/docs/errors.md +171 -70
- package/package.json +4 -1
- package/src/agent-sentences.js +210 -0
- package/src/api-authentication.js +25 -6
- package/src/api-response.js +50 -5
- package/src/cli.js +3113 -1076
- package/src/commands/account.js +97 -0
- package/src/commands/login.js +246 -42
- package/src/commands/maintain.js +662 -0
- package/src/commands/note.js +204 -0
- package/src/commands/plan-compile.js +2 -56
- package/src/commands/report.js +469 -0
- package/src/commands/start.js +52 -0
- package/src/compilation-artifact.js +4 -1
- package/src/credentials.js +145 -7
- package/src/oauth.js +33 -25
- package/src/plan-compile-progress.js +8 -81
- package/src/plan-state.js +250 -1
- package/src/service-client.js +513 -0
- package/src/commands/plan-publish.js +0 -1146
|
@@ -35,6 +35,13 @@ export function environmentTokenFor(origin, { apiToken, stagingApiToken }) {
|
|
|
35
35
|
return hasToken(token) ? token : undefined;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/** The variable that holds the environment token for an origin. @param {string} origin */
|
|
39
|
+
export function environmentTokenVariable(origin) {
|
|
40
|
+
return origin === STAGING_API_URL
|
|
41
|
+
? "FIRSTDRAFT_STAGING_API_TOKEN"
|
|
42
|
+
: "FIRSTDRAFT_API_TOKEN";
|
|
43
|
+
}
|
|
44
|
+
|
|
38
45
|
/**
|
|
39
46
|
* @param {object} options
|
|
40
47
|
* @param {typeof globalThis.fetch} [options.fetchFunction]
|
|
@@ -66,6 +73,10 @@ export function authenticateApiCommand({
|
|
|
66
73
|
|
|
67
74
|
let selectedOrigin = staging ? STAGING_API_URL : undefined;
|
|
68
75
|
const request = fetchFunction ?? globalThis.fetch;
|
|
76
|
+
/** @param {string} origin */
|
|
77
|
+
const tokenFor = (origin) =>
|
|
78
|
+
environmentTokenFor(origin, { apiToken, stagingApiToken }) ??
|
|
79
|
+
storedTokenFor(readStoredTokens(), origin);
|
|
69
80
|
/** @type {typeof globalThis.fetch} */
|
|
70
81
|
const authorizedFetch = (input, init) => {
|
|
71
82
|
const endpoint = new URL(input instanceof Request ? input.url : input);
|
|
@@ -74,9 +85,7 @@ export function authenticateApiCommand({
|
|
|
74
85
|
"The requested API environment does not match the Project origin. No request was made.",
|
|
75
86
|
);
|
|
76
87
|
}
|
|
77
|
-
const token =
|
|
78
|
-
environmentTokenFor(endpoint.origin, { apiToken, stagingApiToken }) ??
|
|
79
|
-
storedToken(readStoredTokens(), endpoint.origin);
|
|
88
|
+
const token = tokenFor(endpoint.origin);
|
|
80
89
|
if (token === undefined) throw new ApiAuthenticationRequiredError();
|
|
81
90
|
selectedOrigin = endpoint.origin;
|
|
82
91
|
return request(input, {
|
|
@@ -87,11 +96,21 @@ export function authenticateApiCommand({
|
|
|
87
96
|
},
|
|
88
97
|
});
|
|
89
98
|
};
|
|
90
|
-
return {
|
|
99
|
+
return {
|
|
100
|
+
apiUrl: configured,
|
|
101
|
+
fetchFunction: authorizedFetch,
|
|
102
|
+
/** Whether a request to `origin` would carry a token. @param {string} origin */
|
|
103
|
+
hasTokenFor: (origin) => tokenFor(origin) !== undefined,
|
|
104
|
+
};
|
|
91
105
|
}
|
|
92
106
|
|
|
93
|
-
/**
|
|
94
|
-
|
|
107
|
+
/**
|
|
108
|
+
* The token a saved login holds for exactly this origin, if any.
|
|
109
|
+
*
|
|
110
|
+
* @param {Readonly<Record<string, string>>} tokens
|
|
111
|
+
* @param {string} origin
|
|
112
|
+
*/
|
|
113
|
+
export function storedTokenFor(tokens, origin) {
|
|
95
114
|
const token = Object.hasOwn(tokens, origin) ? tokens[origin] : undefined;
|
|
96
115
|
return hasToken(token) ? token : undefined;
|
|
97
116
|
}
|
package/src/api-response.js
CHANGED
|
@@ -51,13 +51,41 @@ export const SERVICE_ROUTES = {
|
|
|
51
51
|
method: "GET",
|
|
52
52
|
path: "/v1/projects/{project_id}/compilations/{compilation_id}/artifact",
|
|
53
53
|
},
|
|
54
|
-
|
|
55
|
-
method: "
|
|
56
|
-
path: "/v1/
|
|
54
|
+
readAccount: {
|
|
55
|
+
method: "GET",
|
|
56
|
+
path: "/v1/account",
|
|
57
|
+
},
|
|
58
|
+
sendProgressReport: {
|
|
59
|
+
method: "POST",
|
|
60
|
+
path: "/v1/projects/{project_id}/compilations/{compilation_id}/progress-reports",
|
|
61
|
+
},
|
|
62
|
+
sendFailureReport: {
|
|
63
|
+
method: "POST",
|
|
64
|
+
path: "/v1/projects/{project_id}/compilations/{compilation_id}/failure-reports",
|
|
57
65
|
},
|
|
58
|
-
|
|
66
|
+
sendNote: {
|
|
67
|
+
method: "POST",
|
|
68
|
+
path: "/v1/projects/{project_id}/notes",
|
|
69
|
+
},
|
|
70
|
+
listMaintenanceItems: {
|
|
59
71
|
method: "GET",
|
|
60
|
-
path: "/v1/projects/{project_id}/
|
|
72
|
+
path: "/v1/projects/{project_id}/environments/{environment_name}/items",
|
|
73
|
+
},
|
|
74
|
+
readMaintenanceItem: {
|
|
75
|
+
method: "GET",
|
|
76
|
+
path: "/v1/projects/{project_id}/environments/{environment_name}/items/{item_id}",
|
|
77
|
+
},
|
|
78
|
+
resolveMaintenanceItem: {
|
|
79
|
+
method: "POST",
|
|
80
|
+
path: "/v1/projects/{project_id}/environments/{environment_name}/items/{item_id}/resolution",
|
|
81
|
+
},
|
|
82
|
+
deferMaintenanceItem: {
|
|
83
|
+
method: "POST",
|
|
84
|
+
path: "/v1/projects/{project_id}/environments/{environment_name}/items/{item_id}/deferral",
|
|
85
|
+
},
|
|
86
|
+
askMaintenanceOwner: {
|
|
87
|
+
method: "POST",
|
|
88
|
+
path: "/v1/projects/{project_id}/environments/{environment_name}/items/{item_id}/owner-question",
|
|
61
89
|
},
|
|
62
90
|
requestOAuthToken: {
|
|
63
91
|
method: "POST",
|
|
@@ -164,6 +192,23 @@ export function isProblemBody(response, body) {
|
|
|
164
192
|
);
|
|
165
193
|
}
|
|
166
194
|
|
|
195
|
+
/**
|
|
196
|
+
* The fields of a problem that isProblemBody accepted, and nothing else.
|
|
197
|
+
*
|
|
198
|
+
* @param {unknown} body
|
|
199
|
+
*/
|
|
200
|
+
export function problemProjection(body) {
|
|
201
|
+
const problem = /** @type {Record<string, unknown>} */ (body);
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
...(problem.type === "about:blank" ? { type: problem.type } : {}),
|
|
205
|
+
title: problem.title,
|
|
206
|
+
status: problem.status,
|
|
207
|
+
code: problem.code,
|
|
208
|
+
detail: problem.detail,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
167
212
|
/**
|
|
168
213
|
* @param {unknown} value
|
|
169
214
|
* @returns {value is Record<string, unknown> & {severity: "error" | "warning"}}
|