saturndocs 0.3.0 → 0.4.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/dist/{auth-OIEL34E4.js → auth-NKYU6ZSC.js} +4 -4
- package/dist/{chunk-3EW6ZPL6.js → chunk-22WNRYB7.js} +16 -18
- package/dist/{chunk-3X2NBWZN.js → chunk-2GBM6W4I.js} +5 -25
- package/dist/{chunk-RKM7YWPD.js → chunk-3JUP4HIA.js} +11 -5
- package/dist/{chunk-FUZE54DG.js → chunk-4B6PUKF5.js} +26 -16
- package/dist/{chunk-32ATWMIS.js → chunk-6JJEMNSP.js} +7 -6
- package/dist/{chunk-PU37LVIF.js → chunk-BB32XQJB.js} +9 -5
- package/dist/{chunk-IWIVHHZI.js → chunk-BRC7CU3J.js} +8 -7
- package/dist/{chunk-3KCCCMQY.js → chunk-EH6E45H4.js} +481 -112
- package/dist/{chunk-IJOYWJVM.js → chunk-GLB47CSE.js} +3 -3
- package/dist/{chunk-5ZYUBLEH.js → chunk-HHRZ3Y55.js} +1954 -1833
- package/dist/{chunk-T3MCJYSF.js → chunk-HJ7HRIAT.js} +1 -1
- package/dist/{chunk-6EKGBIUR.js → chunk-KEZAO7P5.js} +1 -1
- package/dist/{chunk-HBSJ4Z4S.js → chunk-KWEWL4MJ.js} +21 -21
- package/dist/{chunk-BOWRQKXR.js → chunk-N66SXAI5.js} +10 -8
- package/dist/{chunk-WMS6FUKK.js → chunk-QF5ELRAU.js} +20 -13
- package/dist/{chunk-VDGVERLX.js → chunk-QMA7433F.js} +3 -3
- package/dist/{chunk-TEYHAN2L.js → chunk-TRQCW5CZ.js} +2 -2
- package/dist/{chunk-YPWPLIEZ.js → chunk-UXCORL5H.js} +3 -3
- package/dist/{chunk-E3G56DR2.js → chunk-ZHYL7FYA.js} +589 -1
- package/dist/{chunk-WXLJZ7RD.js → chunk-ZXJ3Z3PR.js} +3 -3
- package/dist/cli.js +3 -3
- package/dist/{coverage-SRIA65FT.js → coverage-IUQLC2H6.js} +4 -4
- package/dist/{dist-LJSALT4X.js → dist-LZ5BC7HG.js} +8 -3
- package/dist/index.js +20 -21
- package/dist/{init-Y3GDNDWW.js → init-EFZZRZZM.js} +4 -5
- package/dist/{lint-XM26WIGE.js → lint-N7ENEJVU.js} +2 -2
- package/dist/{login-HIXLPRUI.js → login-34OM3PJ2.js} +4 -4
- package/dist/{manage-3HEBB3EQ.js → manage-2AOOCZE2.js} +4 -4
- package/dist/{nav-K43WZJ4J.js → nav-DKCGLENP.js} +4 -4
- package/dist/{openapiCheck-CL2AH3YC.js → openapiCheck-KEHPUZOD.js} +4 -6
- package/dist/pages-E73CUM6I.js +16 -0
- package/dist/{read-RKT6HUZ7.js → read-TQSSS7EJ.js} +25 -11
- package/dist/{read-DYGYUOFK.js → read-UGXFNEGJ.js} +11 -10
- package/dist/requests-OLCBRUAW.js +13 -0
- package/dist/{schema-QMJMGD5P.js → schema-3I6XJSCY.js} +3 -3
- package/dist/{sites-JKS25SEM.js → sites-6HKU6JP7.js} +5 -5
- package/dist/{status-FM2ALQUJ.js → status-DFAYOCC4.js} +4 -4
- package/dist/{suggestions-Z6XIHMFN.js → suggestions-JSTWOWRY.js} +26 -17
- package/dist/{unavailable-DVPNUO3J.js → unavailable-HVN65Q7D.js} +2 -2
- package/dist/validate-6RIKQWMI.js +11 -0
- package/package.json +2 -2
- package/dist/chunk-W3FZTCKV.js +0 -590
- package/dist/pages-4VWB7Z4S.js +0 -16
- package/dist/requests-CZYE6GI3.js +0 -13
- package/dist/validate-X42T4TJ6.js +0 -12
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
authStatusOf,
|
|
4
4
|
registerAuth,
|
|
5
5
|
savedLoginStatusOf
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-ZXJ3Z3PR.js";
|
|
7
|
+
import "./chunk-4B6PUKF5.js";
|
|
8
|
+
import "./chunk-HJ7HRIAT.js";
|
|
9
9
|
import "./chunk-M2BZEDAS.js";
|
|
10
|
-
import "./chunk-
|
|
10
|
+
import "./chunk-EH6E45H4.js";
|
|
11
11
|
export {
|
|
12
12
|
AUTH_METADATA,
|
|
13
13
|
authStatusOf,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
readTextInput
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KEZAO7P5.js";
|
|
4
4
|
import {
|
|
5
5
|
asCliError,
|
|
6
6
|
clientFor
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-4B6PUKF5.js";
|
|
8
8
|
import {
|
|
9
9
|
interruptSignal
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-HJ7HRIAT.js";
|
|
11
11
|
import {
|
|
12
12
|
applyCommandHelp
|
|
13
13
|
} from "./chunk-M2BZEDAS.js";
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
DEFAULT_REQUEST_WAIT_MS,
|
|
17
17
|
REQUEST_TEXT_LIMIT,
|
|
18
18
|
checkedRequestText,
|
|
19
|
+
checkedRequestThreadLimit,
|
|
19
20
|
checkedSubmissionId,
|
|
20
21
|
commandMetadata,
|
|
21
22
|
createRequest,
|
|
@@ -25,13 +26,14 @@ import {
|
|
|
25
26
|
listRequestThreads,
|
|
26
27
|
readRequestThread,
|
|
27
28
|
replyToRequest,
|
|
29
|
+
requestGrantLimitations,
|
|
28
30
|
requestWaitErrorCode,
|
|
29
31
|
resolveGlobalOptions,
|
|
30
32
|
resolveTarget,
|
|
31
33
|
retryRequest,
|
|
32
34
|
successResult,
|
|
33
35
|
waitForRequest
|
|
34
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-EH6E45H4.js";
|
|
35
37
|
|
|
36
38
|
// src/commands/requests/create.ts
|
|
37
39
|
var REQUESTS_CREATE_METADATA = Object.freeze([
|
|
@@ -117,7 +119,7 @@ var REQUESTS_READ_METADATA = Object.freeze([
|
|
|
117
119
|
output: {
|
|
118
120
|
fields: ["threads", "page_cursor", "next_cursor", "has_newer", "failed", "waiting"],
|
|
119
121
|
ids: [],
|
|
120
|
-
limitations: ["page_bounded"]
|
|
122
|
+
limitations: ["page_bounded", "field_omitted", "actor_relabeled", "row_visibility"]
|
|
121
123
|
},
|
|
122
124
|
errors: ["invalid_input", "unauthorized", "forbidden", "not_found", "rate_limited", "service_unavailable", "transport_failure", "interrupted"],
|
|
123
125
|
examples: [
|
|
@@ -133,7 +135,7 @@ var REQUESTS_READ_METADATA = Object.freeze([
|
|
|
133
135
|
output: {
|
|
134
136
|
fields: ["root", "thread_id", "site_id", "open", "latest_job", "entries"],
|
|
135
137
|
ids: ["thread_id", "job_id", "attempt", "suggestion_id"],
|
|
136
|
-
limitations: ["page_bounded"]
|
|
138
|
+
limitations: ["page_bounded", "field_omitted", "actor_relabeled"]
|
|
137
139
|
},
|
|
138
140
|
errors: ["invalid_input", "unauthorized", "forbidden", "not_found", "rate_limited", "service_unavailable", "transport_failure", "interrupted"],
|
|
139
141
|
examples: [
|
|
@@ -147,21 +149,16 @@ async function prepare(globals, environment) {
|
|
|
147
149
|
const target = await resolveTarget(client, globals.site === null ? {} : { site: globals.site });
|
|
148
150
|
return { client, siteId: target.site_id };
|
|
149
151
|
}
|
|
150
|
-
function integerFlag(value, name) {
|
|
151
|
-
if (value === void 0) return void 0;
|
|
152
|
-
const parsed = Number(value);
|
|
153
|
-
if (!Number.isInteger(parsed)) throw invalidInput(`${name} takes a whole number.`);
|
|
154
|
-
return parsed;
|
|
155
|
-
}
|
|
156
152
|
function registerList(group, environment) {
|
|
157
153
|
const metadata = REQUESTS_READ_METADATA[0];
|
|
158
154
|
const command = group.command("list").action(async (_options, self) => {
|
|
159
155
|
const globals = resolveGlobalOptions(self);
|
|
160
156
|
const writer = createResultWriter({ json: globals.json });
|
|
161
|
-
const context = { command: "requests list", siteId:
|
|
157
|
+
const context = { command: "requests list", siteId: globals.site };
|
|
162
158
|
try {
|
|
163
159
|
const flags = self.opts();
|
|
164
|
-
const limit =
|
|
160
|
+
const limit = checkedRequestThreadLimit(flags.limit === void 0 ? void 0 : Number(flags.limit));
|
|
161
|
+
context.siteId = null;
|
|
165
162
|
const run = await prepare(globals, environment);
|
|
166
163
|
context.siteId = run.siteId;
|
|
167
164
|
const page = await listRequestThreads(run.client, {
|
|
@@ -172,7 +169,7 @@ function registerList(group, environment) {
|
|
|
172
169
|
const bounded = {
|
|
173
170
|
...context,
|
|
174
171
|
siteId: run.siteId,
|
|
175
|
-
limitations: [{
|
|
172
|
+
limitations: [...run.client.grantAuthenticated ? requestGrantLimitations(page) : [], {
|
|
176
173
|
code: "page_bounded",
|
|
177
174
|
message: page.next_cursor === null ? "One page was read. The server reported no page after it." : "One page was read. Pass its next_cursor to read the page after it.",
|
|
178
175
|
at: "threads"
|
|
@@ -194,7 +191,7 @@ function idsOf(thread) {
|
|
|
194
191
|
attempt: thread.latest_job.attempt
|
|
195
192
|
};
|
|
196
193
|
if (thread.latest_job.suggestion_id !== null) ids.suggestion_id = thread.latest_job.suggestion_id;
|
|
197
|
-
if (thread.latest_job.pr_number
|
|
194
|
+
if (thread.latest_job.pr_number != null) ids.pr_number = thread.latest_job.pr_number;
|
|
198
195
|
return ids;
|
|
199
196
|
}
|
|
200
197
|
function registerGet(group, environment) {
|
|
@@ -212,7 +209,7 @@ function registerGet(group, environment) {
|
|
|
212
209
|
});
|
|
213
210
|
context.siteId = thread.site_id;
|
|
214
211
|
context.ids = idsOf(thread);
|
|
215
|
-
context.limitations = [{
|
|
212
|
+
context.limitations = [...run.client.grantAuthenticated ? requestGrantLimitations(thread) : [], {
|
|
216
213
|
code: "page_bounded",
|
|
217
214
|
message: "The server bounds this read to the newest 100 entries and supplies no total or cursor, so older entries may not be present.",
|
|
218
215
|
at: "entries"
|
|
@@ -362,7 +359,7 @@ var REQUESTS_WAIT_METADATA = Object.freeze([
|
|
|
362
359
|
output: {
|
|
363
360
|
fields: ["outcome", "state", "job_id", "attempt", "suggestion_id", "thread", "polls", "elapsed_ms"],
|
|
364
361
|
ids: ["thread_id", "job_id", "attempt", "suggestion_id"],
|
|
365
|
-
limitations: []
|
|
362
|
+
limitations: ["section_unavailable", "field_omitted", "actor_relabeled"]
|
|
366
363
|
},
|
|
367
364
|
errors: ["invalid_input", "unauthorized", "forbidden", "not_found", "rate_limited", "service_unavailable", "transport_failure", "remote_failure", "wait_timeout", "interrupted"],
|
|
368
365
|
examples: [
|
|
@@ -430,6 +427,7 @@ function registerRequestsWait(group, environment = {}) {
|
|
|
430
427
|
const resolved = {
|
|
431
428
|
...context,
|
|
432
429
|
ids: idsOf2(result),
|
|
430
|
+
limitations: result.thread && client.grantAuthenticated ? requestGrantLimitations(result.thread) : [],
|
|
433
431
|
recovery: recoveryFor3(result, job, target.site_id)
|
|
434
432
|
};
|
|
435
433
|
const code = requestWaitErrorCode(result.outcome);
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AGENT_INSTRUCTIONS
|
|
3
|
+
} from "./chunk-HHRZ3Y55.js";
|
|
1
4
|
import {
|
|
2
5
|
loadDocsConfig
|
|
3
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-ZHYL7FYA.js";
|
|
4
7
|
import {
|
|
5
8
|
createResultWriter,
|
|
6
9
|
failureResult,
|
|
7
10
|
invalidInput2 as invalidInput,
|
|
8
11
|
resolveGlobalOptions,
|
|
9
12
|
successResult
|
|
10
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-EH6E45H4.js";
|
|
11
14
|
|
|
12
15
|
// src/commands/init.ts
|
|
13
16
|
import { existsSync } from "fs";
|
|
@@ -2344,28 +2347,6 @@ async function writeScaffoldFiles(docsDir, config) {
|
|
|
2344
2347
|
}
|
|
2345
2348
|
return written;
|
|
2346
2349
|
}
|
|
2347
|
-
var AGENT_INSTRUCTIONS = `# Instructions for coding agents
|
|
2348
|
-
|
|
2349
|
-
This directory is the source of a SaturnDocs site. SaturnDocs builds and publishes the site from Git: a push to the connected repository starts a build.
|
|
2350
|
-
|
|
2351
|
-
## Layout
|
|
2352
|
-
|
|
2353
|
-
- \`docs.json\`: site settings and navigation.
|
|
2354
|
-
- \`pages/\`: one \`.md\` or \`.mdx\` file per page. Each page needs a \`title\` in its frontmatter.
|
|
2355
|
-
- \`public/\`: images and other files, served from the site root.
|
|
2356
|
-
- \`openapi/\`: OpenAPI specifications.
|
|
2357
|
-
|
|
2358
|
-
Any other file in this directory stops the publish. This file and \`CLAUDE.md\` are the exceptions: SaturnDocs accepts them and never publishes them.
|
|
2359
|
-
|
|
2360
|
-
## Before every commit
|
|
2361
|
-
|
|
2362
|
-
Run both checks from this directory and fix every error they report. Each error names a file, a line, a rule, and a fix.
|
|
2363
|
-
|
|
2364
|
-
\`\`\`sh
|
|
2365
|
-
npx saturndocs validate . --json
|
|
2366
|
-
npx saturndocs lint . --json
|
|
2367
|
-
\`\`\`
|
|
2368
|
-
`;
|
|
2369
2350
|
async function writeExtractedAssets(docsDir, extraction) {
|
|
2370
2351
|
const assets = [extraction.logo, extraction.favicon].filter(
|
|
2371
2352
|
(asset) => asset !== void 0
|
|
@@ -2531,6 +2512,5 @@ export {
|
|
|
2531
2512
|
registerInit,
|
|
2532
2513
|
scaffoldDocsProject,
|
|
2533
2514
|
buildDocsConfig,
|
|
2534
|
-
AGENT_INSTRUCTIONS,
|
|
2535
2515
|
printExtractionReport
|
|
2536
2516
|
};
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
environmentToken,
|
|
4
4
|
loginEnvironment,
|
|
5
5
|
resolveSavedLogin
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-4B6PUKF5.js";
|
|
7
7
|
import {
|
|
8
8
|
applyCommandHelp
|
|
9
9
|
} from "./chunk-M2BZEDAS.js";
|
|
@@ -17,10 +17,11 @@ import {
|
|
|
17
17
|
isManagementError,
|
|
18
18
|
parseOrigin,
|
|
19
19
|
requireCommitSha,
|
|
20
|
+
requiresManagementReceipt,
|
|
20
21
|
resolveGlobalOptions,
|
|
21
22
|
resolveTarget,
|
|
22
23
|
successResult
|
|
23
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-EH6E45H4.js";
|
|
24
25
|
|
|
25
26
|
// src/commands/manage.ts
|
|
26
27
|
import { readFile } from "fs/promises";
|
|
@@ -159,9 +160,10 @@ async function buildBody(current, options) {
|
|
|
159
160
|
if (data === null) return {};
|
|
160
161
|
return { body: data.value };
|
|
161
162
|
}
|
|
162
|
-
function requireJsonMedia(headers) {
|
|
163
|
+
function requireJsonMedia(headers, mutation) {
|
|
163
164
|
const media = (headers.get("content-type") ?? "").split(";")[0]?.trim().toLowerCase() ?? "";
|
|
164
165
|
if (media === "" || media === "application/json" || media.endsWith("+json")) return;
|
|
166
|
+
if (mutation) throw new CliError("unknown_outcome", `The write was accepted but its receipt uses unsupported media ${media}. Read the site state before writing again.`);
|
|
165
167
|
throw new CliError("transport_failure", `The management API answered ${media}, which this command does not read. Only JSON operations are supported here.`);
|
|
166
168
|
}
|
|
167
169
|
function classify(error) {
|
|
@@ -193,7 +195,11 @@ async function callManagement(method, path, options, token, fetchImpl = fetch) {
|
|
|
193
195
|
mutation: current.mutation,
|
|
194
196
|
anonymous: current.anonymous
|
|
195
197
|
});
|
|
196
|
-
|
|
198
|
+
if (response.emptyBody && current.mutation && requiresManagementReceipt(current.verb, current.route)) {
|
|
199
|
+
const read = current.route === "requests" ? "saturndocs requests list --site " + options.site : "the site's " + current.route.split("/")[0] + " state";
|
|
200
|
+
throw new CliError("unknown_outcome", `The service accepted the write and returned an empty receipt. Read ${read} before writing again.`);
|
|
201
|
+
}
|
|
202
|
+
requireJsonMedia(response.headers, current.mutation);
|
|
197
203
|
return response.data;
|
|
198
204
|
} catch (error) {
|
|
199
205
|
throw classify(error);
|
|
@@ -212,7 +218,7 @@ var MANAGE_METADATA = Object.freeze([
|
|
|
212
218
|
idempotency: "expected_review",
|
|
213
219
|
text_sources: ["--data"],
|
|
214
220
|
output: { fields: [], ids: [], limitations: [] },
|
|
215
|
-
errors: ["invalid_input", "unauthorized", "forbidden", "not_found", "stale_review", "conflict", "rate_limited", "service_unavailable", "transport_failure", "interrupted"],
|
|
221
|
+
errors: ["invalid_input", "unauthorized", "forbidden", "not_found", "stale_review", "conflict", "rate_limited", "service_unavailable", "transport_failure", "unknown_outcome", "interrupted"],
|
|
216
222
|
examples: [
|
|
217
223
|
{ command: "saturndocs manage GET requests --site acme", description: "Read one site's requests through the raw operation." },
|
|
218
224
|
{ command: "saturndocs manage POST requests --site acme --data @request.json --json", description: "Send a body read from a file and take the shared result envelope." },
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
interruptSignal
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-HJ7HRIAT.js";
|
|
4
4
|
import {
|
|
5
5
|
CliError,
|
|
6
6
|
createClient,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
invalidInput2 as invalidInput,
|
|
9
9
|
isManagementError,
|
|
10
10
|
parseOrigin
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-EH6E45H4.js";
|
|
12
12
|
|
|
13
13
|
// src/lib/credentials.ts
|
|
14
14
|
import { execFile } from "child_process";
|
|
@@ -597,6 +597,7 @@ async function send(ctx, path, init, deadlineAt = null) {
|
|
|
597
597
|
try {
|
|
598
598
|
return { status: response.status, body: await readBody(response), retryAfter: parseRetryAfter(response.headers.get("retry-after"), now()) };
|
|
599
599
|
} catch (error) {
|
|
600
|
+
if (init.method === "POST" && response.ok) throw new RequestFailure("The sign-in service accepted the request but its receipt could not be read. Check the grant in the dashboard before another login.", true, "unknown_outcome");
|
|
600
601
|
if (error instanceof RequestFailure) throw error;
|
|
601
602
|
if (ctx.signal?.aborted) throw new RequestFailure("Interrupted while the sign-in service was answering.", true, "interrupted");
|
|
602
603
|
throw new RequestFailure("The sign-in service's answer was cut off.", true);
|
|
@@ -628,11 +629,15 @@ async function startDevice(ctx, request, deadlineAt = null) {
|
|
|
628
629
|
method: "POST",
|
|
629
630
|
form: { client_id: CLIENT_ID, site: request.site ?? void 0, new_site: request.newSite ?? void 0, scope: request.scope?.join(" ") }
|
|
630
631
|
}, deadlineAt);
|
|
631
|
-
if (answer.status
|
|
632
|
+
if (answer.status >= 200 && answer.status < 300) {
|
|
632
633
|
const parsed = DeviceStart.safeParse(answer.body);
|
|
633
|
-
if (!parsed.success) throw new CliError("
|
|
634
|
-
|
|
635
|
-
|
|
634
|
+
if (!parsed.success) throw new CliError("unknown_outcome", "The sign-in service accepted the device request but its receipt could not be verified. Let the pending request expire before starting another login.");
|
|
635
|
+
try {
|
|
636
|
+
assertSameOrigin(ctx.origin, parsed.data.verification_uri, "verification link");
|
|
637
|
+
assertSameOrigin(ctx.origin, parsed.data.verification_uri_complete, "verification link");
|
|
638
|
+
} catch {
|
|
639
|
+
throw new CliError("unknown_outcome", "The accepted device request returned an invalid verification link. Let it expire before starting another login.");
|
|
640
|
+
}
|
|
636
641
|
return parsed.data;
|
|
637
642
|
}
|
|
638
643
|
const code = oauthError(answer);
|
|
@@ -651,9 +656,9 @@ async function pollDevice(ctx, pending, deadlineAt, onInterval = async () => voi
|
|
|
651
656
|
if (deadlineAt !== null && now() + interval > deadlineAt) return { kind: "timeout" };
|
|
652
657
|
await sleep(interval, ctx.signal);
|
|
653
658
|
const answer = await send(ctx, "/v1/auth/token", { method: "POST", form: { grant_type: DEVICE_GRANT, client_id: CLIENT_ID, device_code: pending.device_code } }, deadlineAt);
|
|
654
|
-
if (answer.status
|
|
659
|
+
if (answer.status >= 200 && answer.status < 300) {
|
|
655
660
|
const parsed = TokenPair.safeParse(answer.body);
|
|
656
|
-
if (!parsed.success) throw new CliError("
|
|
661
|
+
if (!parsed.success) throw new CliError("unknown_outcome", "The sign-in service accepted the token request but its tokens could not be verified. Check the grant in the dashboard before another login.");
|
|
657
662
|
return { kind: "approved", tokens: parsed.data };
|
|
658
663
|
}
|
|
659
664
|
const code = oauthError(answer);
|
|
@@ -684,9 +689,9 @@ async function refreshTokens(ctx, refreshToken, deadlineAt) {
|
|
|
684
689
|
if (error instanceof RequestFailure) return error.sent ? { kind: "ambiguous", error } : { kind: "not_rotated", error };
|
|
685
690
|
throw error;
|
|
686
691
|
}
|
|
687
|
-
if (answer.status
|
|
692
|
+
if (answer.status >= 200 && answer.status < 300) {
|
|
688
693
|
const parsed = TokenPair.safeParse(answer.body);
|
|
689
|
-
if (!parsed.success) return { kind: "ambiguous", error: new CliError("
|
|
694
|
+
if (!parsed.success) return { kind: "ambiguous", error: new CliError("unknown_outcome", "The sign-in service accepted the refresh but its tokens could not be verified.") };
|
|
690
695
|
return { kind: "refreshed", tokens: parsed.data };
|
|
691
696
|
}
|
|
692
697
|
const code = oauthError(answer);
|
|
@@ -816,7 +821,7 @@ async function resolveSavedLogin(origin, site, environment) {
|
|
|
816
821
|
throw new CliError(outcome.error.code, `${outcome.error.message} The refresh may have gone through, so the next command will end this login and ask for a new one.`, { mutation: "unknown", recovery: loginAgainRecovery(siteId) });
|
|
817
822
|
}
|
|
818
823
|
if (outcome.tokens.site_id !== siteId) {
|
|
819
|
-
throw new CliError("
|
|
824
|
+
throw new CliError("unknown_outcome", `The sign-in service refreshed the login for ${siteId} as another site; the answer was not saved.`, { mutation: "unknown" });
|
|
820
825
|
}
|
|
821
826
|
const refreshed = grantFromTokens(outcome.tokens, now());
|
|
822
827
|
await saveRecord(store, withGrant(markedRecord, refreshed));
|
|
@@ -845,12 +850,15 @@ function clientFor(globals, environment = {}) {
|
|
|
845
850
|
const signal = environment.signal ?? interruptSignal() ?? void 0;
|
|
846
851
|
const token = environmentToken(env);
|
|
847
852
|
const origin = parseOrigin(globals.api ?? void 0);
|
|
853
|
+
savedLoginSite = null;
|
|
854
|
+
let saved;
|
|
855
|
+
const login = () => saved ??= resolveSavedLogin(origin, globals.site, loginEnvironment(environment));
|
|
848
856
|
const config = {
|
|
849
857
|
...token !== void 0 ? { token } : {
|
|
850
858
|
tokenProvider: async () => {
|
|
851
|
-
const
|
|
852
|
-
savedLoginSite =
|
|
853
|
-
return
|
|
859
|
+
const resolved = await login();
|
|
860
|
+
savedLoginSite = resolved?.grant.site_id ?? null;
|
|
861
|
+
return resolved?.token;
|
|
854
862
|
}
|
|
855
863
|
},
|
|
856
864
|
...globals.api === null ? {} : { origin: globals.api },
|
|
@@ -858,7 +866,9 @@ function clientFor(globals, environment = {}) {
|
|
|
858
866
|
...signal === void 0 ? {} : { signal },
|
|
859
867
|
...globals.timeout === null ? {} : { deadlineMs: globals.timeout * 1e3 }
|
|
860
868
|
};
|
|
861
|
-
|
|
869
|
+
const client = createClient(config);
|
|
870
|
+
if (token !== void 0) return client;
|
|
871
|
+
return Object.assign(client, { savedLoginScope: async () => (await login())?.grant.scope });
|
|
862
872
|
}
|
|
863
873
|
function asCliError(error) {
|
|
864
874
|
if (!isManagementError(error)) return error;
|
|
@@ -869,7 +879,7 @@ function asCliError(error) {
|
|
|
869
879
|
mutation: error.detail.mutation,
|
|
870
880
|
exit: error.detail.exit,
|
|
871
881
|
cause: error,
|
|
872
|
-
|
|
882
|
+
recovery: error.recovery ?? (refused && savedLoginSite !== null ? loginAgainRecovery(savedLoginSite) : null)
|
|
873
883
|
});
|
|
874
884
|
}
|
|
875
885
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
asCliError,
|
|
3
3
|
clientFor
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-4B6PUKF5.js";
|
|
5
5
|
import {
|
|
6
6
|
applyCommandHelp
|
|
7
7
|
} from "./chunk-M2BZEDAS.js";
|
|
@@ -20,18 +20,18 @@ import {
|
|
|
20
20
|
statusRecovery,
|
|
21
21
|
statusSections,
|
|
22
22
|
successResult
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-EH6E45H4.js";
|
|
24
24
|
|
|
25
25
|
// src/commands/status.ts
|
|
26
26
|
var STATUS_METADATA = Object.freeze([
|
|
27
27
|
commandMetadata("status", {
|
|
28
|
-
description: "A bounded briefing on one site, composed from the reads that already exist: the site itself, one page of conversations, one page of the pending suggestion tab, and one page of activity. There is no status route on the server and nothing here pages on your behalf. Each section reports available, empty, or
|
|
28
|
+
description: "A bounded briefing on one site, composed from the reads that already exist: the site itself, one page of conversations, one page of the pending suggestion tab, and one page of activity. There is no status route on the server and nothing here pages on your behalf. Each section reports available, empty, unavailable, or not_granted on its own, so a route that answered 503 leaves the other sections' data and identities untouched instead of blanking them. Every number comes from a field the server sent \u2014 the request failed and waiting tallies and the suggestion counts \u2014 and never from the length of a page. A credential the server refuses fails the command rather than being reported as a quiet site.",
|
|
29
29
|
target: { arguments: [] },
|
|
30
30
|
effect: "Nothing. Four independent reads of one site.",
|
|
31
31
|
output: {
|
|
32
32
|
fields: ["site", "requests", "suggestions", "activity", "counts", "attention"],
|
|
33
33
|
ids: ["thread_id", "job_id", "attempt"],
|
|
34
|
-
limitations: ["section_unavailable", "page_bounded"]
|
|
34
|
+
limitations: ["section_unavailable", "page_bounded", "field_omitted", "actor_relabeled", "row_visibility", "value_redacted"]
|
|
35
35
|
},
|
|
36
36
|
errors: ["invalid_input", "unauthorized", "forbidden", "not_found", "rate_limited", "service_unavailable", "transport_failure", "interrupted"],
|
|
37
37
|
examples: [
|
|
@@ -41,6 +41,7 @@ var STATUS_METADATA = Object.freeze([
|
|
|
41
41
|
})
|
|
42
42
|
]);
|
|
43
43
|
function sectionLine(part) {
|
|
44
|
+
if (part.state === "not_granted") return `${part.section}: not_granted \u2014 ${part.reason}`;
|
|
44
45
|
if (part.state === "unavailable") {
|
|
45
46
|
return `${part.section}: unavailable \u2014 ${part.error?.message ?? "the read failed and said nothing."} ${part.recovery?.command ?? ""}`.trimEnd();
|
|
46
47
|
}
|
|
@@ -78,12 +79,12 @@ function registerStatus(program, _cliDir, environment = {}) {
|
|
|
78
79
|
const target = await resolveTarget(client, { site });
|
|
79
80
|
context.siteId = target.site_id;
|
|
80
81
|
const status = await readSiteStatus(client, target.site_id);
|
|
81
|
-
context.limitations = statusLimitations(status);
|
|
82
|
+
context.limitations = statusLimitations(status, client.grantAuthenticated === true);
|
|
82
83
|
context.ids = statusIds(status);
|
|
83
84
|
context.recovery = statusRecovery(status);
|
|
84
85
|
const blocker = statusBlocker(status);
|
|
85
86
|
if (blocker !== null) {
|
|
86
|
-
throw new CliError(blocker.code, blocker.message, { server: blocker.server, data: status });
|
|
87
|
+
throw new CliError(blocker.code, globals.json ? blocker.message : statusText(status), { server: blocker.server, data: status });
|
|
87
88
|
}
|
|
88
89
|
process.exitCode = writer.write(successResult(context, status), { text: statusText(status) });
|
|
89
90
|
} catch (error) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
requestedSite
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-N66SXAI5.js";
|
|
4
4
|
import {
|
|
5
5
|
asCliError,
|
|
6
6
|
clientFor
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-4B6PUKF5.js";
|
|
8
8
|
import {
|
|
9
9
|
applyCommandHelp
|
|
10
10
|
} from "./chunk-M2BZEDAS.js";
|
|
@@ -13,12 +13,14 @@ import {
|
|
|
13
13
|
commandMetadata,
|
|
14
14
|
createResultWriter,
|
|
15
15
|
failureResult,
|
|
16
|
+
grantFields,
|
|
17
|
+
grantLimitation,
|
|
16
18
|
listPages,
|
|
17
19
|
pagesUnavailable,
|
|
18
20
|
resolveGlobalOptions,
|
|
19
21
|
resolveTarget,
|
|
20
22
|
successResult
|
|
21
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-EH6E45H4.js";
|
|
22
24
|
|
|
23
25
|
// src/commands/pages.ts
|
|
24
26
|
import { InvalidArgumentError } from "commander";
|
|
@@ -27,7 +29,7 @@ var PAGES_METADATA = Object.freeze([
|
|
|
27
29
|
description: "Read the pages of the release readers are seeing, with where each one is read, where its source is, and how often it was read in the traffic window. A site with no live release answers unavailable: no_release and carries no page list at all, which this command reports as such rather than as a published site with nothing in it.",
|
|
28
30
|
target: { arguments: [{ name: "site-id", required: false, description: "The site to read. Defaults to the site the credential resolves to." }] },
|
|
29
31
|
effect: "Nothing. One read of the published page listing.",
|
|
30
|
-
output: { fields: ["site_id", "days", "release_id", "traffic", "pages", "unavailable"], ids: ["release_id"], limitations: ["page_bounded", "section_unavailable"] },
|
|
32
|
+
output: { fields: ["site_id", "days", "release_id", "traffic", "pages", "unavailable"], ids: ["release_id"], limitations: ["page_bounded", "section_unavailable", "field_omitted"] },
|
|
31
33
|
errors: ["invalid_input", "unauthorized", "forbidden", "not_found", "rate_limited", "service_unavailable", "transport_failure", "interrupted"],
|
|
32
34
|
examples: [
|
|
33
35
|
{ command: "saturndocs pages list", description: "Every published page of the live release, over the server's default window." },
|
|
@@ -45,12 +47,13 @@ function trafficWindow(value) {
|
|
|
45
47
|
}
|
|
46
48
|
function pagesLimitations(result) {
|
|
47
49
|
if (pagesUnavailable(result)) {
|
|
48
|
-
return [{
|
|
50
|
+
return [...result.days === void 0 ? [grantLimitation("pages", grantFields.pagesUnavailable)] : [], {
|
|
49
51
|
code: "section_unavailable",
|
|
50
52
|
message: "This site has no live release, so there is no published page list to read. That is not a site whose published list is empty.",
|
|
51
53
|
at: "pages"
|
|
52
54
|
}];
|
|
53
55
|
}
|
|
56
|
+
if (result.days === void 0) return [grantLimitation("pages", grantFields.pages)];
|
|
54
57
|
if (result.traffic === "partial") {
|
|
55
58
|
return [{ code: "page_bounded", message: "The edge returned as many address counts as one answer holds, so some reads are missing from the view and agent-read figures.", at: "pages" }];
|
|
56
59
|
}
|
|
@@ -67,6 +70,7 @@ function listText(result) {
|
|
|
67
70
|
if (pagesUnavailable(result)) {
|
|
68
71
|
return `${result.site_id}: no live release, so there is no published page list. Publish a release before reading pages.`;
|
|
69
72
|
}
|
|
73
|
+
if (result.days === void 0) return [`${result.site_id}: release ${result.release_id}, ${result.pages.length} published pages`, ...result.pages.map((page) => `${page.url} ${page.path}`)].join("\n");
|
|
70
74
|
const head = `${result.site_id}: release ${result.release_id}, ${result.pages.length} published pages, traffic ${result.traffic} over ${result.days} days`;
|
|
71
75
|
return [head, ...result.pages.map((page) => `${page.url} views ${page.views} agent reads ${page.agent_reads} ${page.path}`)].join("\n");
|
|
72
76
|
}
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
windowsUnsupported,
|
|
25
25
|
withCredentialLock,
|
|
26
26
|
withPollLock
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-4B6PUKF5.js";
|
|
28
28
|
import {
|
|
29
29
|
applyCommandHelp
|
|
30
30
|
} from "./chunk-M2BZEDAS.js";
|
|
@@ -37,12 +37,12 @@ import {
|
|
|
37
37
|
parseOrigin,
|
|
38
38
|
resolveGlobalOptions,
|
|
39
39
|
successResult
|
|
40
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-EH6E45H4.js";
|
|
41
41
|
|
|
42
42
|
// src/commands/login.ts
|
|
43
43
|
import { execFile } from "child_process";
|
|
44
44
|
import { createHash } from "crypto";
|
|
45
|
-
var LOGIN_ERRORS = ["invalid_input", "forbidden", "conflict", "rate_limited", "service_unavailable", "transport_failure", "wait_timeout", "interrupted"];
|
|
45
|
+
var LOGIN_ERRORS = ["invalid_input", "forbidden", "conflict", "rate_limited", "service_unavailable", "transport_failure", "unknown_outcome", "wait_timeout", "interrupted"];
|
|
46
46
|
var LOGIN_METADATA = Object.freeze([
|
|
47
47
|
commandMetadata("login", {
|
|
48
48
|
description: "Start the device approval flow: print a link and a code, wait while a person approves this agent for one site in the browser, then save the login. The person chooses the site and the permissions on the approval page; --site or --new-site only proposes one. The login is kept in the macOS Keychain when it answers, otherwise in a file only this user can read (on Linux, always the file; Windows is not supported yet), and every later command uses it when SATURNDOCS_MANAGEMENT_TOKEN is not set.",
|
|
@@ -65,7 +65,7 @@ var LOGOUT_METADATA = Object.freeze([
|
|
|
65
65
|
target: { arguments: [] },
|
|
66
66
|
effect: "Revokes one grant, or every saved grant with --all, and deletes the saved tokens.",
|
|
67
67
|
output: { fields: ["revoked", "failed", "remaining", "unchecked"], ids: [], limitations: [] },
|
|
68
|
-
errors: ["invalid_input", "service_unavailable", "transport_failure", "interrupted"],
|
|
68
|
+
errors: ["invalid_input", "service_unavailable", "transport_failure", "unknown_outcome", "interrupted"],
|
|
69
69
|
examples: [
|
|
70
70
|
{ command: "saturndocs logout", description: "Revoke and forget the default saved login." },
|
|
71
71
|
{ command: "saturndocs logout --site acme --json", description: "Revoke and forget the login for acme." },
|
|
@@ -370,7 +370,7 @@ function registerLogout(program, _cliDir, environment = {}) {
|
|
|
370
370
|
await revokeToken(flowContext(origin, login), grant.refresh_token);
|
|
371
371
|
revoked.push({ site_id: name, store: entry.store.label });
|
|
372
372
|
} catch (error) {
|
|
373
|
-
failed.push({ site_id: name, store: entry.store.label, reason: error instanceof Error ? error.message : String(error) });
|
|
373
|
+
failed.push({ site_id: name, store: entry.store.label, ...error instanceof CliError ? { code: error.code } : {}, reason: error instanceof Error ? error.message : String(error) });
|
|
374
374
|
}
|
|
375
375
|
delete record.grants[name];
|
|
376
376
|
}
|
|
@@ -399,11 +399,12 @@ function registerLogout(program, _cliDir, environment = {}) {
|
|
|
399
399
|
const environmentNote = environmentToken(login.env) === void 0 ? "" : `
|
|
400
400
|
${TOKEN_VARIABLE} is still set; logout does not change it.`;
|
|
401
401
|
const problems = [
|
|
402
|
-
...outcome.failed.map((entry) => entry.site_id === null ? `${entry.store}: ${entry.reason}` : `${entry.site_id} (${entry.store}): the server did not confirm revocation
|
|
402
|
+
...outcome.failed.map((entry) => entry.site_id === null ? `${entry.store}: ${entry.reason}` : `${entry.site_id} (${entry.store}): the server did not confirm revocation. Check the grant in the dashboard`),
|
|
403
403
|
...outcome.unchecked.map((entry) => `${entry.store} could not be read, so a login kept there may still work; run saturndocs logout again when it can be read`)
|
|
404
404
|
];
|
|
405
405
|
if (problems.length > 0) {
|
|
406
|
-
|
|
406
|
+
const code = outcome.failed.some((entry) => entry.code === "unknown_outcome") ? "unknown_outcome" : "service_unavailable";
|
|
407
|
+
throw new CliError(code, `Logout did not finish everywhere. ${problems.join(". ")}.`, { data: outcome, mutation: "unknown" });
|
|
407
408
|
}
|
|
408
409
|
process.exitCode = writer.write(successResult(context, outcome), {
|
|
409
410
|
text: `${outcome.revoked.length === 0 ? "Nothing to revoke." : `Revoked and deleted: ${[...new Set(outcome.revoked.map((entry) => entry.site_id))].join(", ")}.`}${environmentNote}`
|