@writedocs/generator 0.4.1 → 0.4.3
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@writedocs/generator",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Static site generator for docs — a writedocs.json + MDX folder in, a static site out.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -84,4 +84,4 @@
|
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"esbuild": "0.28.2"
|
|
86
86
|
}
|
|
87
|
-
}
|
|
87
|
+
}
|
package/src/cli/build-auth.js
CHANGED
|
@@ -1,53 +1,69 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `writedocs build` produces the artifact that actually gets deployed, so
|
|
3
|
-
* unlike `dev`/`init` it isn't freely runnable by anyone who installs the
|
|
4
|
-
* package - it's gated behind a key that a separate service (`key-server/`
|
|
5
|
-
* in this repo) actually decides the validity of.
|
|
6
|
-
*
|
|
7
|
-
* This deliberately isn't a local check. An earlier version compared the
|
|
8
|
-
* supplied key against an env var set on the same machine
|
|
9
|
-
* (WRITEDOCS_BUILD_SECRET) - but since writedocs ships its full source to
|
|
10
|
-
* everyone who installs it, anyone could read that check and satisfy it
|
|
11
|
-
* with a value they made up themselves. Calling out to a server that
|
|
12
|
-
* actually holds the set of issued keys means a key's validity is decided
|
|
13
|
-
* by whoever runs that server, not by whoever is running `build`.
|
|
14
|
-
*
|
|
15
|
-
* See docs/dev/docs/deploy.mdx for how to deploy key-server/ and issue
|
|
16
|
-
* keys, and key-server/README.md for the service's own endpoints.
|
|
17
|
-
*/
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
console.error(
|
|
51
|
-
process.exit(
|
|
52
|
-
}
|
|
53
|
-
|
|
1
|
+
/**
|
|
2
|
+
* `writedocs build` produces the artifact that actually gets deployed, so
|
|
3
|
+
* unlike `dev`/`init` it isn't freely runnable by anyone who installs the
|
|
4
|
+
* package - it's gated behind a key that a separate service (`key-server/`
|
|
5
|
+
* in this repo) actually decides the validity of.
|
|
6
|
+
*
|
|
7
|
+
* This deliberately isn't a local check. An earlier version compared the
|
|
8
|
+
* supplied key against an env var set on the same machine
|
|
9
|
+
* (WRITEDOCS_BUILD_SECRET) - but since writedocs ships its full source to
|
|
10
|
+
* everyone who installs it, anyone could read that check and satisfy it
|
|
11
|
+
* with a value they made up themselves. Calling out to a server that
|
|
12
|
+
* actually holds the set of issued keys means a key's validity is decided
|
|
13
|
+
* by whoever runs that server, not by whoever is running `build`.
|
|
14
|
+
*
|
|
15
|
+
* See docs/dev/docs/deploy.mdx for how to deploy key-server/ and issue
|
|
16
|
+
* keys, and key-server/README.md for the service's own endpoints.
|
|
17
|
+
*/
|
|
18
|
+
export const EX_TEMPFAIL = 75;
|
|
19
|
+
|
|
20
|
+
export async function requireBuildKey(providedKey) {
|
|
21
|
+
const serverUrl = process.env.WRITEDOCS_KEY_SERVER_URL;
|
|
22
|
+
if (!serverUrl) {
|
|
23
|
+
console.error('[writedocs] build is not available.');
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
if (!providedKey) {
|
|
27
|
+
console.error('[writedocs] build requires a valid --key (or WRITEDOCS_API_KEY).');
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// The exit code is a contract with whoever runs `build` - the WriteDocs
|
|
32
|
+
// platform retries on it, never on the message text:
|
|
33
|
+
// 1 - the key was not accepted: missing URL/key, a 4xx, `valid: false`.
|
|
34
|
+
// Trying again with the same key gives the same answer.
|
|
35
|
+
// 75 - EX_TEMPFAIL (sysexits.h): the authorization server couldn't be
|
|
36
|
+
// asked - network error, timeout or 5xx. Still fails closed (no build
|
|
37
|
+
// happens); it only tells the caller that trying later may work.
|
|
38
|
+
let res;
|
|
39
|
+
try {
|
|
40
|
+
res = await fetch(new URL('/v1/validate', serverUrl), {
|
|
41
|
+
method: 'POST',
|
|
42
|
+
headers: { 'content-type': 'application/json' },
|
|
43
|
+
body: JSON.stringify({ key: providedKey }),
|
|
44
|
+
signal: AbortSignal.timeout(10_000),
|
|
45
|
+
});
|
|
46
|
+
} catch (err) {
|
|
47
|
+
// Fails closed on a network error/timeout too, same as an explicit
|
|
48
|
+
// rejection - an unreachable authorization server is not treated as
|
|
49
|
+
// "no opinion, let it through".
|
|
50
|
+
console.error(`[writedocs] Could not reach the build authorization server: ${err.message}`);
|
|
51
|
+
process.exit(EX_TEMPFAIL);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (res.status >= 500) {
|
|
55
|
+
console.error(`[writedocs] The build authorization server failed (HTTP ${res.status}) - try again later.`);
|
|
56
|
+
process.exit(EX_TEMPFAIL);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let valid = false;
|
|
60
|
+
if (res.ok) {
|
|
61
|
+
const body = await res.json().catch(() => null);
|
|
62
|
+
valid = body?.valid === true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!valid) {
|
|
66
|
+
console.error('[writedocs] build requires a valid --key (or WRITEDOCS_API_KEY) - the server rejected this one.');
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -25,11 +25,17 @@ interface Props {
|
|
|
25
25
|
const { config } = Astro.props as Props;
|
|
26
26
|
|
|
27
27
|
const askAiLoaderScript = `window.DocsBotAI=window.DocsBotAI||{},DocsBotAI.init=function(e){return new Promise((t,r)=>{var n=document.createElement("script");n.type="text/javascript",n.async=!0,n.src="https://widget.docsbot.ai/chat.js";let o=document.getElementsByTagName("script")[0];o.parentNode.insertBefore(n,o),n.addEventListener("load",()=>{let n;Promise.all([new Promise((t,r)=>{window.DocsBotAI.mount(Object.assign({}, e)).then(t).catch(r)}),(n=function e(t){return new Promise(e=>{if(document.querySelector(t))return e(document.querySelector(t));let r=new MutationObserver(n=>{if(document.querySelector(t))return e(document.querySelector(t)),r.disconnect()});r.observe(document.body,{childList:!0,subtree:!0})})})("#docsbotai-root"),]).then(()=>t()).catch(r)}),n.addEventListener("error",e=>{r(e.message)})})};`;
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
// WRITEDOCS_ASK_AI_ID tem precedência sobre o writedocs.json, pelo mesmo
|
|
29
|
+
// motivo do WRITEDOCS_DISABLE_WATERMARK em Sidebar.astro: quem roda o build
|
|
30
|
+
// (CI, env da hospedagem) define o bot sem mexer no conteúdo versionado.
|
|
31
|
+
// Não é segredo - o id sai em texto puro no HTML de toda página. String
|
|
32
|
+
// vazia conta como não definida e cai no valor do JSON.
|
|
33
|
+
const askAiId = process.env.WRITEDOCS_ASK_AI_ID || config.integrations.askAi?.id;
|
|
34
|
+
const askAiInitScript = askAiId
|
|
35
|
+
? `DocsBotAI.init(${JSON.stringify({ id: askAiId })});`
|
|
30
36
|
: null;
|
|
31
37
|
---
|
|
32
|
-
{
|
|
38
|
+
{askAiId && (
|
|
33
39
|
<>
|
|
34
40
|
<script is:inline set:html={askAiLoaderScript} />
|
|
35
41
|
{askAiInitScript && <script is:inline set:html={askAiInitScript} />}
|