saturndocs 0.3.0 → 0.5.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-47SI6KTG.js} +4 -4
- package/dist/broken-links-EOEGVH4F.js +275 -0
- package/dist/build-OLTD5RJQ.js +139 -0
- package/dist/{chunk-32ATWMIS.js → chunk-27ARMXM2.js} +7 -6
- package/dist/{chunk-RKM7YWPD.js → chunk-33MGV73K.js} +11 -5
- package/dist/{chunk-BOWRQKXR.js → chunk-4MJYA6R5.js} +10 -8
- package/dist/{chunk-VDGVERLX.js → chunk-7QGSIPAS.js} +3 -3
- package/dist/{chunk-T3MCJYSF.js → chunk-ATM2LU6H.js} +1 -1
- package/dist/{chunk-WXLJZ7RD.js → chunk-C62AROBZ.js} +3 -3
- package/dist/chunk-CM2ONKCQ.js +1650 -0
- package/dist/{chunk-3KCCCMQY.js → chunk-F5G7PDQJ.js} +556 -117
- package/dist/{chunk-3EW6ZPL6.js → chunk-FIFAZLRQ.js} +19 -21
- package/dist/{chunk-5ZYUBLEH.js → chunk-GNR5NWNR.js} +2012 -1878
- package/dist/{chunk-3X2NBWZN.js → chunk-JFYMBFDW.js} +5 -25
- package/dist/{chunk-WMS6FUKK.js → chunk-JSKBT765.js} +86 -109
- package/dist/{chunk-IJOYWJVM.js → chunk-L6EE6XS2.js} +7 -7
- package/dist/chunk-LDE53VKA.js +146 -0
- package/dist/chunk-LLRWUKIR.js +62 -0
- package/dist/{chunk-E3G56DR2.js → chunk-MXJOVTOT.js} +606 -3
- package/dist/chunk-NE6SDXXB.js +52 -0
- package/dist/chunk-OWKBGNGZ.js +72 -0
- package/dist/{chunk-TEYHAN2L.js → chunk-RI5COFYL.js} +2 -2
- package/dist/{chunk-6EKGBIUR.js → chunk-RNRRFICE.js} +1 -1
- package/dist/{chunk-PU37LVIF.js → chunk-SDNJSBGO.js} +9 -5
- package/dist/{chunk-IWIVHHZI.js → chunk-SIGMRKFJ.js} +8 -7
- package/dist/{chunk-YPWPLIEZ.js → chunk-UJCRJ4XU.js} +3 -3
- package/dist/chunk-WDOLOQAV.js +259 -0
- package/dist/{chunk-FUZE54DG.js → chunk-X2YU7MAC.js} +26 -16
- package/dist/cli.js +3 -3
- package/dist/{coverage-SRIA65FT.js → coverage-I3FWCRWG.js} +4 -4
- package/dist/dev-PXZCETLB.js +243 -0
- package/dist/{dist-LJSALT4X.js → dist-RJ3HLSC7.js} +8 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +60 -110
- package/dist/{init-Y3GDNDWW.js → init-GQELTILS.js} +4 -5
- package/dist/{lint-XM26WIGE.js → lint-MR7LHMLU.js} +2 -2
- package/dist/{login-HIXLPRUI.js → login-QW5GZLWK.js} +4 -4
- package/dist/{manage-3HEBB3EQ.js → manage-OTGX2SGZ.js} +4 -4
- package/dist/{nav-K43WZJ4J.js → nav-3GHG5U5B.js} +4 -4
- package/dist/{openapiCheck-CL2AH3YC.js → openapiCheck-XAZ6FOF2.js} +4 -6
- package/dist/pages-BA3MMNSL.js +16 -0
- package/dist/{read-RKT6HUZ7.js → read-6RAHFNPS.js} +25 -11
- package/dist/{read-DYGYUOFK.js → read-UCTHVWS2.js} +11 -10
- package/dist/renderer-76D7VFQ3.js +441 -0
- package/dist/requests-6OIP4LGE.js +13 -0
- package/dist/{schema-QMJMGD5P.js → schema-OEKCGF6Y.js} +3 -3
- package/dist/{sites-JKS25SEM.js → sites-L6DPTMX6.js} +5 -5
- package/dist/{status-FM2ALQUJ.js → status-PMVNHRK6.js} +4 -4
- package/dist/{suggestions-Z6XIHMFN.js → suggestions-WBWQP2UN.js} +29 -20
- package/dist/validate-LY3ZSHSV.js +12 -0
- package/package.json +10 -4
- package/dist/chunk-HBSJ4Z4S.js +0 -53
- package/dist/chunk-W3FZTCKV.js +0 -590
- package/dist/pages-4VWB7Z4S.js +0 -16
- package/dist/requests-CZYE6GI3.js +0 -13
- package/dist/unavailable-DVPNUO3J.js +0 -40
- 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-T3MCJYSF.js";
|
|
6
|
+
} from "./chunk-C62AROBZ.js";
|
|
7
|
+
import "./chunk-X2YU7MAC.js";
|
|
9
8
|
import "./chunk-M2BZEDAS.js";
|
|
10
|
-
import "./chunk-
|
|
9
|
+
import "./chunk-ATM2LU6H.js";
|
|
10
|
+
import "./chunk-F5G7PDQJ.js";
|
|
11
11
|
export {
|
|
12
12
|
AUTH_METADATA,
|
|
13
13
|
authStatusOf,
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import {
|
|
2
|
+
documentLinks
|
|
3
|
+
} from "./chunk-OWKBGNGZ.js";
|
|
4
|
+
import {
|
|
5
|
+
releaseRoute,
|
|
6
|
+
siteRoutes
|
|
7
|
+
} from "./chunk-WDOLOQAV.js";
|
|
8
|
+
import {
|
|
9
|
+
buildGeneration
|
|
10
|
+
} from "./chunk-CM2ONKCQ.js";
|
|
11
|
+
import "./chunk-JSKBT765.js";
|
|
12
|
+
import "./chunk-GNR5NWNR.js";
|
|
13
|
+
import {
|
|
14
|
+
isRedirectPattern
|
|
15
|
+
} from "./chunk-MXJOVTOT.js";
|
|
16
|
+
import {
|
|
17
|
+
createResultWriter,
|
|
18
|
+
failureResult,
|
|
19
|
+
invalidInput2 as invalidInput,
|
|
20
|
+
resolveGlobalOptions,
|
|
21
|
+
successResult
|
|
22
|
+
} from "./chunk-F5G7PDQJ.js";
|
|
23
|
+
|
|
24
|
+
// src/lib/preview/check-links.ts
|
|
25
|
+
import { mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync } from "fs";
|
|
26
|
+
import { tmpdir } from "os";
|
|
27
|
+
import { join, relative, sep } from "path";
|
|
28
|
+
|
|
29
|
+
// ../release-abi/src/canonical.ts
|
|
30
|
+
var textEncoder = new TextEncoder();
|
|
31
|
+
function isWellFormedUnicode(value) {
|
|
32
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
33
|
+
const code = value.charCodeAt(index);
|
|
34
|
+
if (code >= 55296 && code <= 56319) {
|
|
35
|
+
const next = value.charCodeAt(index + 1);
|
|
36
|
+
if (!Number.isInteger(next) || next < 56320 || next > 57343) return false;
|
|
37
|
+
index += 1;
|
|
38
|
+
} else if (code >= 56320 && code <= 57343) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
function utf8(value) {
|
|
45
|
+
const encoded = textEncoder.encode(value);
|
|
46
|
+
const copy = new Uint8Array(encoded.byteLength);
|
|
47
|
+
copy.set(encoded);
|
|
48
|
+
return copy;
|
|
49
|
+
}
|
|
50
|
+
function lowercaseHex(bytes) {
|
|
51
|
+
return Array.from(new Uint8Array(bytes), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ../release-abi/src/nav-variant.ts
|
|
55
|
+
var NAV_VARIANT_DIRECTORY = "__gs-variants";
|
|
56
|
+
var NAV_VARIANT_INDEX_FILE = `${NAV_VARIANT_DIRECTORY}/index.json`;
|
|
57
|
+
var VARIANT_KEY_PATTERN = /^[0-9a-f]{64}$/;
|
|
58
|
+
function compareGroupNames(left, right) {
|
|
59
|
+
if (left < right) return -1;
|
|
60
|
+
if (left > right) return 1;
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
function isSortedGroupList(groups) {
|
|
64
|
+
for (let index = 1; index < groups.length; index += 1) {
|
|
65
|
+
if (compareGroupNames(groups[index - 1], groups[index]) >= 0) return false;
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
async function variantKey(groups) {
|
|
70
|
+
const digest = await crypto.subtle.digest("SHA-256", utf8(JSON.stringify([...groups])));
|
|
71
|
+
return lowercaseHex(digest);
|
|
72
|
+
}
|
|
73
|
+
async function parseVariantIndex(text) {
|
|
74
|
+
let value;
|
|
75
|
+
try {
|
|
76
|
+
value = JSON.parse(text);
|
|
77
|
+
} catch {
|
|
78
|
+
return { error: "variant index is not valid JSON" };
|
|
79
|
+
}
|
|
80
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
81
|
+
return { error: "variant index must be an object" };
|
|
82
|
+
}
|
|
83
|
+
const record = value;
|
|
84
|
+
const keys = Object.keys(record).sort();
|
|
85
|
+
if (keys.length !== 3 || keys[0] !== "groups" || keys[1] !== "variants" || keys[2] !== "version") {
|
|
86
|
+
return { error: "variant index must contain exactly version, groups, and variants" };
|
|
87
|
+
}
|
|
88
|
+
if (record.version !== 1) return { error: "variant index version must be 1" };
|
|
89
|
+
const groups = groupList(record.groups);
|
|
90
|
+
if (typeof groups === "string") return { error: `variant index groups are invalid: ${groups}` };
|
|
91
|
+
if (!Array.isArray(record.variants)) return { error: "variant index variants must be an array" };
|
|
92
|
+
const known = new Set(groups);
|
|
93
|
+
const seen = /* @__PURE__ */ new Set();
|
|
94
|
+
const variants = [];
|
|
95
|
+
for (const entry of record.variants) {
|
|
96
|
+
if (entry === null || typeof entry !== "object" || Array.isArray(entry)) {
|
|
97
|
+
return { error: "variant index entry must be an object" };
|
|
98
|
+
}
|
|
99
|
+
const variant = entry;
|
|
100
|
+
const entryKeys = Object.keys(variant).sort();
|
|
101
|
+
if (entryKeys.length !== 2 || entryKeys[0] !== "groups" || entryKeys[1] !== "key") {
|
|
102
|
+
return { error: "variant index entry must contain exactly key and groups" };
|
|
103
|
+
}
|
|
104
|
+
if (typeof variant.key !== "string" || !VARIANT_KEY_PATTERN.test(variant.key)) {
|
|
105
|
+
return { error: "variant key must be 64 lowercase hexadecimal characters" };
|
|
106
|
+
}
|
|
107
|
+
const entryGroups = groupList(variant.groups);
|
|
108
|
+
if (typeof entryGroups === "string") {
|
|
109
|
+
return { error: `variant ${variant.key} groups are invalid: ${entryGroups}` };
|
|
110
|
+
}
|
|
111
|
+
if (entryGroups.length === 0) {
|
|
112
|
+
return { error: `variant ${variant.key} must name at least one group` };
|
|
113
|
+
}
|
|
114
|
+
for (const group of entryGroups) {
|
|
115
|
+
if (!known.has(group)) {
|
|
116
|
+
return { error: `variant ${variant.key} names a group the index does not declare` };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (await variantKey(entryGroups) !== variant.key) {
|
|
120
|
+
return { error: `variant ${variant.key} does not hash its own groups` };
|
|
121
|
+
}
|
|
122
|
+
if (seen.has(variant.key)) return { error: `variant ${variant.key} is listed twice` };
|
|
123
|
+
seen.add(variant.key);
|
|
124
|
+
variants.push({ key: variant.key, groups: entryGroups });
|
|
125
|
+
}
|
|
126
|
+
return { version: 1, groups, variants };
|
|
127
|
+
}
|
|
128
|
+
function resolveVariantFile(relativePath, index) {
|
|
129
|
+
if (relativePath === "" || relativePath.startsWith("/")) {
|
|
130
|
+
return { error: `dist path is invalid: ${relativePath}` };
|
|
131
|
+
}
|
|
132
|
+
if (relativePath !== NAV_VARIANT_DIRECTORY && !relativePath.startsWith(`${NAV_VARIANT_DIRECTORY}/`)) {
|
|
133
|
+
return { canonicalPath: relativePath };
|
|
134
|
+
}
|
|
135
|
+
const rest = relativePath.slice(`${NAV_VARIANT_DIRECTORY}/`.length);
|
|
136
|
+
const separator = rest.indexOf("/");
|
|
137
|
+
const key = separator === -1 ? "" : rest.slice(0, separator);
|
|
138
|
+
const canonicalPath = separator === -1 ? "" : rest.slice(separator + 1);
|
|
139
|
+
if (!VARIANT_KEY_PATTERN.test(key) || canonicalPath === "") {
|
|
140
|
+
return { error: `navigation variant path is malformed: ${relativePath}` };
|
|
141
|
+
}
|
|
142
|
+
if (canonicalPath === NAV_VARIANT_DIRECTORY || canonicalPath.startsWith(`${NAV_VARIANT_DIRECTORY}/`)) {
|
|
143
|
+
return { error: `navigation variant path is nested: ${relativePath}` };
|
|
144
|
+
}
|
|
145
|
+
if (index === null) {
|
|
146
|
+
return { error: `navigation variant index is missing for ${relativePath}` };
|
|
147
|
+
}
|
|
148
|
+
const variant = index.variants.find((entry) => entry.key === key);
|
|
149
|
+
if (variant === void 0) {
|
|
150
|
+
return { error: `navigation variant key is not in the index: ${key}` };
|
|
151
|
+
}
|
|
152
|
+
return { canonicalPath, navVariant: [...variant.groups] };
|
|
153
|
+
}
|
|
154
|
+
function groupList(value) {
|
|
155
|
+
if (!Array.isArray(value)) return "expected an array of group names";
|
|
156
|
+
const groups = [];
|
|
157
|
+
for (const group of value) {
|
|
158
|
+
if (typeof group !== "string" || group === "") return "expected non-empty group names";
|
|
159
|
+
if (!isWellFormedUnicode(group)) return "expected well-formed Unicode without lone surrogates";
|
|
160
|
+
groups.push(group);
|
|
161
|
+
}
|
|
162
|
+
if (!isSortedGroupList(groups)) return "expected sorted, unique group names";
|
|
163
|
+
return groups;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/lib/preview/check-links.ts
|
|
167
|
+
function diagnostic({ source, href }, reason) {
|
|
168
|
+
return { file: source, link: href, reason };
|
|
169
|
+
}
|
|
170
|
+
function leavesRoot(raw, base) {
|
|
171
|
+
const path = decodeURIComponent(raw.split(/[?#]/, 1)[0]).replace(/^(?:[a-z][a-z0-9+.-]*:)?\/\/[^/]*/i, "");
|
|
172
|
+
let depth = path.startsWith("/") ? 0 : base.pathname.split("/").slice(1, -1).length;
|
|
173
|
+
for (const segment of path.split("/")) {
|
|
174
|
+
if (segment === "..") {
|
|
175
|
+
if (--depth < 0) return true;
|
|
176
|
+
} else if (segment && segment !== ".") depth++;
|
|
177
|
+
}
|
|
178
|
+
return path.includes("\\") || path.includes("\0");
|
|
179
|
+
}
|
|
180
|
+
async function scanRenderedSite(site, policy, siteUrl) {
|
|
181
|
+
const misses = [];
|
|
182
|
+
let routes;
|
|
183
|
+
try {
|
|
184
|
+
routes = siteRoutes(site, policy);
|
|
185
|
+
} catch (error) {
|
|
186
|
+
return [diagnostic({ source: "site/", href: "" }, String(error))];
|
|
187
|
+
}
|
|
188
|
+
const origin = new URL(siteUrl).origin;
|
|
189
|
+
const documents = [...routes.files].filter(([, f]) => f.type === "text/html").map(([route, f]) => ({ route, file: f.file, source: f.path }));
|
|
190
|
+
const variantDir = join(site, "__gs-variants");
|
|
191
|
+
let entries;
|
|
192
|
+
try {
|
|
193
|
+
entries = readdirSync(variantDir, { recursive: true, withFileTypes: true });
|
|
194
|
+
} catch (error) {
|
|
195
|
+
if (error.code !== "ENOENT") throw error;
|
|
196
|
+
}
|
|
197
|
+
if (entries) {
|
|
198
|
+
const index = await parseVariantIndex(readFileSync(join(site, NAV_VARIANT_INDEX_FILE), "utf8"));
|
|
199
|
+
if ("error" in index) return [{ file: NAV_VARIANT_INDEX_FILE, link: "", reason: index.error }];
|
|
200
|
+
for (const entry of entries.filter((e) => e.isFile() && e.name.endsWith(".html"))) {
|
|
201
|
+
const file = join(entry.parentPath, entry.name);
|
|
202
|
+
const source = relative(site, file).split(sep).join("/");
|
|
203
|
+
const variant = resolveVariantFile(source, index);
|
|
204
|
+
if ("error" in variant) return [{ file: source, link: "", reason: variant.error }];
|
|
205
|
+
const route = releaseRoute(variant.canonicalPath);
|
|
206
|
+
if (!routes.files.has(route)) return [{ file: source, link: route, reason: "Missing base route for variant" }];
|
|
207
|
+
documents.push({ route, source, file });
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function check(href, base) {
|
|
211
|
+
if (!href || href.startsWith("#")) return;
|
|
212
|
+
const visited = /* @__PURE__ */ new Set();
|
|
213
|
+
for (; ; ) {
|
|
214
|
+
let target;
|
|
215
|
+
try {
|
|
216
|
+
target = new URL(href, base);
|
|
217
|
+
if (target.protocol === "file:") return "Target is outside the build";
|
|
218
|
+
if (target.origin !== origin) return;
|
|
219
|
+
if (leavesRoot(href, base)) return "Target is outside the build";
|
|
220
|
+
} catch {
|
|
221
|
+
return "Invalid URL";
|
|
222
|
+
}
|
|
223
|
+
if (visited.has(target.pathname)) return "Redirect cycle";
|
|
224
|
+
visited.add(target.pathname);
|
|
225
|
+
const hit = routes.resolve(target.pathname, target.search);
|
|
226
|
+
if (!hit) return "No generated route, asset, or Worker handler";
|
|
227
|
+
if (!hit.redirect) return;
|
|
228
|
+
href = hit.redirect.headers.get("location");
|
|
229
|
+
base = target;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
for (const { source, destination } of policy.redirects) {
|
|
233
|
+
if (isRedirectPattern(source)) continue;
|
|
234
|
+
const reason = check(destination, new URL(source, origin));
|
|
235
|
+
if (reason) misses.push(diagnostic({ source, href: destination }, reason));
|
|
236
|
+
}
|
|
237
|
+
for (const { source, route, file } of documents) {
|
|
238
|
+
for (const href of documentLinks(readFileSync(file, "utf8"))) {
|
|
239
|
+
const reason = check(href, new URL(route, origin));
|
|
240
|
+
if (reason) misses.push(diagnostic({ source, href }, reason));
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return misses;
|
|
244
|
+
}
|
|
245
|
+
async function checkLinks(docs, cache, provide, siteUrl) {
|
|
246
|
+
const dir = mkdtempSync(join(tmpdir(), "saturndocs-links-"));
|
|
247
|
+
try {
|
|
248
|
+
const generation = await buildGeneration(realpathSync(docs), dir, cache, await provide({}), siteUrl, void 0, void 0, "rendered");
|
|
249
|
+
const diagnostics = await scanRenderedSite(generation.out, generation.policy, generation.report.site_url);
|
|
250
|
+
return { ...generation.report, diagnostics };
|
|
251
|
+
} finally {
|
|
252
|
+
rmSync(dir, { recursive: true, force: true });
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// src/commands/broken-links.ts
|
|
257
|
+
function registerBrokenLinks(program, provide, cache) {
|
|
258
|
+
program.command("broken-links [docs-dir]").option("--site-url <url>", "Override the production site URL").action(async (dir, options, self) => {
|
|
259
|
+
const writer = createResultWriter({ json: resolveGlobalOptions(self).json });
|
|
260
|
+
const context = { command: "broken-links", siteId: null };
|
|
261
|
+
try {
|
|
262
|
+
const report = await checkLinks(dir ?? process.cwd(), cache, provide, options.siteUrl);
|
|
263
|
+
if (report.diagnostics.length) {
|
|
264
|
+
const message = report.diagnostics.map((d) => `${d.file}: ${d.link} \u2014 ${d.reason}`).join("\n");
|
|
265
|
+
throw invalidInput(message, { data: report });
|
|
266
|
+
}
|
|
267
|
+
process.exitCode = writer.write(successResult(context, report), { text: "Author preview has no broken internal links." });
|
|
268
|
+
} catch (error) {
|
|
269
|
+
process.exitCode = writer.write(failureResult(error, context));
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
export {
|
|
274
|
+
registerBrokenLinks
|
|
275
|
+
};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cachePath
|
|
3
|
+
} from "./chunk-LDE53VKA.js";
|
|
4
|
+
import {
|
|
5
|
+
buildGeneration
|
|
6
|
+
} from "./chunk-CM2ONKCQ.js";
|
|
7
|
+
import "./chunk-JSKBT765.js";
|
|
8
|
+
import "./chunk-GNR5NWNR.js";
|
|
9
|
+
import "./chunk-MXJOVTOT.js";
|
|
10
|
+
import {
|
|
11
|
+
createResultWriter,
|
|
12
|
+
failureResult,
|
|
13
|
+
resolveGlobalOptions,
|
|
14
|
+
successResult
|
|
15
|
+
} from "./chunk-F5G7PDQJ.js";
|
|
16
|
+
|
|
17
|
+
// src/lib/preview/output.ts
|
|
18
|
+
import { createHash, randomUUID } from "crypto";
|
|
19
|
+
import { lstatSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, renameSync, rmdirSync, rmSync, writeFileSync } from "fs";
|
|
20
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "path";
|
|
21
|
+
var marker = ".saturndocs-author-preview";
|
|
22
|
+
function canonical(file) {
|
|
23
|
+
try {
|
|
24
|
+
return realpathSync(file);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
if (error.code !== "ENOENT") throw error;
|
|
27
|
+
return join(canonical(dirname(file)), basename(file));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function contains(left, right) {
|
|
31
|
+
const path = relative(left.toLowerCase(), right.toLowerCase());
|
|
32
|
+
return path === "" || !isAbsolute(path) && path !== ".." && !path.startsWith(".." + sep);
|
|
33
|
+
}
|
|
34
|
+
function identity(path, out) {
|
|
35
|
+
const info = lstatSync(path, { bigint: true });
|
|
36
|
+
return JSON.stringify({ out, dev: String(info.dev), ino: String(info.ino), birth: String(info.birthtimeNs) });
|
|
37
|
+
}
|
|
38
|
+
function owned(out, record, directory = out) {
|
|
39
|
+
const info = lstatSync(directory, { throwIfNoEntry: false });
|
|
40
|
+
if (!info) return false;
|
|
41
|
+
if (info.isDirectory() && lstatSync(record, { throwIfNoEntry: false })?.isFile() && readFileSync(record, "utf8") === identity(directory, out)) return true;
|
|
42
|
+
throw new Error(`Output is not owned by the CLI: ${out}. Choose a new directory.`);
|
|
43
|
+
}
|
|
44
|
+
function repositoryRoot(start) {
|
|
45
|
+
for (let dir = start; ; dir = dirname(dir)) {
|
|
46
|
+
if (lstatSync(join(dir, ".git"), { throwIfNoEntry: false })) return dir;
|
|
47
|
+
if (dirname(dir) === dir) return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function rejectProjectSymlinks(requested, docs) {
|
|
51
|
+
const repository = repositoryRoot(docs);
|
|
52
|
+
const roots = [docs, realpathSync(process.cwd()), ...repository ? [repository] : []];
|
|
53
|
+
for (let path = requested; dirname(path) !== path; path = dirname(path)) {
|
|
54
|
+
if (lstatSync(path, { throwIfNoEntry: false })?.isSymbolicLink() && roots.some((root) => contains(root, canonical(dirname(path))))) {
|
|
55
|
+
throw new Error(`Output crosses a project symlink: ${path}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function exportBuild(docsDir, outDir, siteUrl, cacheDir, provide) {
|
|
60
|
+
const docs = realpathSync(resolve(docsDir));
|
|
61
|
+
const requested = resolve(outDir);
|
|
62
|
+
rejectProjectSymlinks(requested, docs);
|
|
63
|
+
const out = join(canonical(dirname(requested)), basename(requested));
|
|
64
|
+
const destinations = [requested, out, canonical(requested)];
|
|
65
|
+
const site = new URL(siteUrl);
|
|
66
|
+
if (!["https:", "http:"].includes(site.protocol) || site.username || site.password) throw new Error("Expected an HTTP(S) site URL");
|
|
67
|
+
const renderer = await provide({});
|
|
68
|
+
for (const dir of [resolve(docsDir), docs, resolve(cacheDir), canonical(resolve(cacheDir)), resolve(renderer.root), realpathSync(renderer.root)]) {
|
|
69
|
+
if (destinations.some((path) => contains(dir, path) || contains(path, dir))) throw new Error(`Output overlaps protected directory: ${dir}`);
|
|
70
|
+
}
|
|
71
|
+
if (contains(docs, canonical(resolve(cacheDir)))) throw new Error("Preview cache overlaps the docs directory.");
|
|
72
|
+
const state = await cachePath(cacheDir, ["output-ownership"]);
|
|
73
|
+
const record = join(state, createHash("sha256").update(out).digest("hex"));
|
|
74
|
+
owned(out, record);
|
|
75
|
+
mkdirSync(dirname(out), { recursive: true });
|
|
76
|
+
const controller = new AbortController();
|
|
77
|
+
const interrupt = () => controller.abort(new Error("Build interrupted"));
|
|
78
|
+
process.on("SIGTERM", interrupt);
|
|
79
|
+
process.on("SIGINT", interrupt);
|
|
80
|
+
const stage = mkdtempSync(join(dirname(out), ".saturndocs-build-"));
|
|
81
|
+
try {
|
|
82
|
+
const { report, out: siteDir } = await buildGeneration(docs, stage, cacheDir, renderer, site.href, void 0, controller.signal);
|
|
83
|
+
controller.signal.throwIfAborted();
|
|
84
|
+
writeFileSync(join(siteDir, marker), JSON.stringify({ version: 1, out }), { flag: "wx" });
|
|
85
|
+
const lock = out + ".saturndocs-lock";
|
|
86
|
+
mkdirSync(lock, { mode: 448 });
|
|
87
|
+
try {
|
|
88
|
+
const backup = join(lock, "previous");
|
|
89
|
+
const replace = owned(out, record);
|
|
90
|
+
const pending = record + "." + randomUUID();
|
|
91
|
+
writeFileSync(pending, identity(siteDir, out), { flag: "wx", mode: 384 });
|
|
92
|
+
try {
|
|
93
|
+
if (replace) {
|
|
94
|
+
renameSync(out, backup);
|
|
95
|
+
owned(out, record, backup);
|
|
96
|
+
}
|
|
97
|
+
renameSync(siteDir, out);
|
|
98
|
+
try {
|
|
99
|
+
renameSync(pending, record);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
renameSync(out, siteDir);
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (lstatSync(backup, { throwIfNoEntry: false })) renameSync(backup, out);
|
|
106
|
+
throw error;
|
|
107
|
+
} finally {
|
|
108
|
+
rmSync(pending, { force: true });
|
|
109
|
+
}
|
|
110
|
+
if (replace) rmSync(backup, { recursive: true });
|
|
111
|
+
} finally {
|
|
112
|
+
if (!lstatSync(join(lock, "previous"), { throwIfNoEntry: false })) rmdirSync(lock);
|
|
113
|
+
}
|
|
114
|
+
return { ...report, output_path: out };
|
|
115
|
+
} finally {
|
|
116
|
+
process.off("SIGTERM", interrupt);
|
|
117
|
+
process.off("SIGINT", interrupt);
|
|
118
|
+
rmSync(stage, { recursive: true, force: true });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// src/commands/build.ts
|
|
123
|
+
function registerBuild(program, provider, cache) {
|
|
124
|
+
program.command("build [docs-dir]").requiredOption("--out-dir <path>").option("--site-url <url>", "Site URL", "http://localhost").action(async (dir, options, self) => {
|
|
125
|
+
const writer = createResultWriter({ json: resolveGlobalOptions(self).json });
|
|
126
|
+
const context = { command: "build", siteId: null };
|
|
127
|
+
try {
|
|
128
|
+
const report = await exportBuild(dir ?? process.cwd(), options.outDir, options.siteUrl, cache, provider);
|
|
129
|
+
process.exitCode = writer.write(successResult(context, report), {
|
|
130
|
+
text: [`Built author preview at ${report.output_path}`, ...report.warnings].join("\n")
|
|
131
|
+
});
|
|
132
|
+
} catch (error) {
|
|
133
|
+
process.exitCode = writer.write(failureResult(error, context));
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
export {
|
|
138
|
+
registerBuild
|
|
139
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
asCliError,
|
|
3
3
|
clientFor
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-X2YU7MAC.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-F5G7PDQJ.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,
|
|
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, beta_off, 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: ["beta_off", "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) {
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
environmentToken,
|
|
4
4
|
loginEnvironment,
|
|
5
5
|
resolveSavedLogin
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-X2YU7MAC.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-F5G7PDQJ.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,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SITES_CREATE_METADATA,
|
|
3
3
|
registerSitesCreate
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-SIGMRKFJ.js";
|
|
5
5
|
import {
|
|
6
6
|
asCliError,
|
|
7
7
|
clientFor
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-X2YU7MAC.js";
|
|
9
9
|
import {
|
|
10
10
|
applyCommandHelp
|
|
11
11
|
} from "./chunk-M2BZEDAS.js";
|
|
@@ -13,13 +13,15 @@ import {
|
|
|
13
13
|
commandMetadata,
|
|
14
14
|
createResultWriter,
|
|
15
15
|
failureResult,
|
|
16
|
+
grantFields,
|
|
17
|
+
grantLimitation,
|
|
16
18
|
invalidInput2 as invalidInput,
|
|
17
19
|
listSites,
|
|
18
20
|
readSiteDetail,
|
|
19
21
|
resolveGlobalOptions,
|
|
20
22
|
resolveTarget,
|
|
21
23
|
successResult
|
|
22
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-F5G7PDQJ.js";
|
|
23
25
|
|
|
24
26
|
// src/commands/sites.ts
|
|
25
27
|
var SITES_METADATA = Object.freeze([
|
|
@@ -41,7 +43,7 @@ var SITES_METADATA = Object.freeze([
|
|
|
41
43
|
output: {
|
|
42
44
|
fields: ["site_id", "site.hostnames", "site.active_release", "site.reader_status", "site.latest_job", "site.usage", "connections.docs_repo", "connections.product_connections"],
|
|
43
45
|
ids: ["release_id"],
|
|
44
|
-
limitations: []
|
|
46
|
+
limitations: ["section_unavailable", "field_omitted"]
|
|
45
47
|
},
|
|
46
48
|
errors: ["invalid_input", "unauthorized", "forbidden", "not_found", "rate_limited", "service_unavailable", "transport_failure", "interrupted"],
|
|
47
49
|
examples: [
|
|
@@ -68,11 +70,11 @@ function detailText(detail) {
|
|
|
68
70
|
const release = site.active_release;
|
|
69
71
|
const lines = [
|
|
70
72
|
`site: ${detail.site_id}`,
|
|
71
|
-
`hostnames: ${site.hostnames.length === 0 ? "none returned" : site.hostnames.join(", ")}
|
|
73
|
+
...site.hostnames === void 0 ? [] : [`hostnames: ${site.hostnames.length === 0 ? "none returned" : site.hostnames.join(", ")}`],
|
|
72
74
|
`reader status: ${site.reader_status ?? "not reported"}`,
|
|
73
75
|
release === null ? "active release: none" : `active release: ${release.release_id} (${release.state}), activated ${release.activated_at ?? "at an unrecorded time"}`,
|
|
74
|
-
site.latest_job === null ? "latest job: none" : `latest job: ${site.latest_job.state}${site.latest_job.error_code
|
|
75
|
-
`usage: ${site.usage === void 0 || Object.keys(site.usage).length === 0 ? "nothing measured" : Object.entries(site.usage).map(([name, meter]) => `${name} ${JSON.stringify(meter)}`).join("; ")}`
|
|
76
|
+
site.latest_job === null ? "latest job: none" : `latest job: ${site.latest_job.state}${site.latest_job.error_code == null ? "" : ` (${site.latest_job.error_code})`}`,
|
|
77
|
+
...site.hostnames === void 0 ? [] : [`usage: ${site.usage === void 0 || Object.keys(site.usage).length === 0 ? "nothing measured" : Object.entries(site.usage).map(([name, meter]) => `${name} ${JSON.stringify(meter)}`).join("; ")}`]
|
|
76
78
|
];
|
|
77
79
|
if (detail.connections !== null) {
|
|
78
80
|
const docs = detail.connections.docs_repo;
|
|
@@ -110,7 +112,7 @@ function registerSites(program, _cliDir, environment = {}) {
|
|
|
110
112
|
context.siteId = target.site_id;
|
|
111
113
|
const detail = await readSiteDetail(client, target.site_id, { connections: options.connections === true });
|
|
112
114
|
if (detail.site.active_release !== null) context.ids = { release_id: detail.site.active_release.release_id };
|
|
113
|
-
process.exitCode = writer.write(successResult(context, detail), { text: detailText(detail) });
|
|
115
|
+
process.exitCode = writer.write(successResult({ ...context, limitations: detail.site.hostnames === void 0 ? [grantLimitation("site", grantFields.site)] : [] }, detail), { text: detailText(detail) });
|
|
114
116
|
} catch (error) {
|
|
115
117
|
process.exitCode = writer.write(failureResult(asCliError(error), context));
|
|
116
118
|
}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-YGVC4N4V.js";
|
|
4
4
|
import {
|
|
5
5
|
asCliError
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-X2YU7MAC.js";
|
|
7
7
|
import {
|
|
8
8
|
applyCommandHelp
|
|
9
9
|
} from "./chunk-M2BZEDAS.js";
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
messageOf,
|
|
16
16
|
resolveGlobalOptions,
|
|
17
17
|
successResult
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-F5G7PDQJ.js";
|
|
19
19
|
|
|
20
20
|
// src/commands/coverage.ts
|
|
21
21
|
import { existsSync } from "fs";
|
|
@@ -49,7 +49,7 @@ async function runCoverage(docsDir, outlinePath) {
|
|
|
49
49
|
} catch (error) {
|
|
50
50
|
throw invalidInput(`Cannot read the outline file ${outlinePath}: ${messageOf(error)}`);
|
|
51
51
|
}
|
|
52
|
-
const { parseOutline, outlineCoverage } = await import("./dist-
|
|
52
|
+
const { parseOutline, outlineCoverage } = await import("./dist-RJ3HLSC7.js");
|
|
53
53
|
let outline;
|
|
54
54
|
try {
|
|
55
55
|
outline = parseOutline(JSON.parse(raw));
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
loginAgainRecovery,
|
|
8
8
|
loginEnvironment,
|
|
9
9
|
resolveSavedLogin
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-X2YU7MAC.js";
|
|
11
11
|
import {
|
|
12
12
|
applyCommandHelp
|
|
13
13
|
} from "./chunk-M2BZEDAS.js";
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
parseOrigin,
|
|
22
22
|
resolveGlobalOptions,
|
|
23
23
|
successResult
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-F5G7PDQJ.js";
|
|
25
25
|
|
|
26
26
|
// src/commands/auth.ts
|
|
27
27
|
var AUTH_METADATA = Object.freeze([
|
|
@@ -30,7 +30,7 @@ var AUTH_METADATA = Object.freeze([
|
|
|
30
30
|
target: { arguments: [] },
|
|
31
31
|
effect: "Nothing. One read of the site listing.",
|
|
32
32
|
output: { fields: ["current", "sites", "read_verified", "credential"], ids: [], limitations: [] },
|
|
33
|
-
errors: ["invalid_input", "unauthorized", "forbidden", "rate_limited", "service_unavailable", "transport_failure", "interrupted"],
|
|
33
|
+
errors: ["invalid_input", "unauthorized", "forbidden", "rate_limited", "service_unavailable", "transport_failure", "unknown_outcome", "interrupted"],
|
|
34
34
|
examples: [
|
|
35
35
|
{ command: "saturndocs auth status", description: "Check that the credential in the environment can read, and see which site it acts on." },
|
|
36
36
|
{ command: "saturndocs auth status --json --no-input", description: "The same check as one result object, for an agent." }
|