@writedocs/generator 0.4.0 → 0.4.2

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.0",
3
+ "version": "0.4.2",
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": {
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@apidevtools/swagger-parser": "^12.1.0",
48
- "@astrojs/markdown-remark": "7.2.2",
48
+ "@astrojs/markdown-remark": "7.2.4",
49
49
  "@astrojs/mdx": "^7.0.5",
50
50
  "@astrojs/react": "^6.0.2",
51
51
  "@astrojs/sitemap": "^3.7.3",
@@ -61,7 +61,7 @@
61
61
  "@iconify-json/tabler": "^1.2.35",
62
62
  "@shikijs/transformers": "^4.3.1",
63
63
  "@tailwindcss/vite": "^4.3.2",
64
- "astro": "7.2.2",
64
+ "astro": "7.2.9",
65
65
  "astro-icon": "^1.1.5",
66
66
  "commander": "^15.0.0",
67
67
  "dotenv": "^17.4.2",
@@ -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 async function requireBuildKey(providedKey) {
19
- const serverUrl = process.env.WRITEDOCS_KEY_SERVER_URL;
20
- if (!serverUrl) {
21
- console.error('[writedocs] build is not available.');
22
- process.exit(1);
23
- }
24
- if (!providedKey) {
25
- console.error('[writedocs] build requires a valid --key (or WRITEDOCS_API_KEY).');
26
- process.exit(1);
27
- }
28
-
29
- let valid = false;
30
- try {
31
- const res = await fetch(new URL('/v1/validate', serverUrl), {
32
- method: 'POST',
33
- headers: { 'content-type': 'application/json' },
34
- body: JSON.stringify({ key: providedKey }),
35
- signal: AbortSignal.timeout(10_000),
36
- });
37
- if (res.ok) {
38
- const body = await res.json();
39
- valid = body?.valid === true;
40
- }
41
- } catch (err) {
42
- // Fails closed on a network error/timeout too, same as an explicit
43
- // rejection - an unreachable authorization server is not treated as
44
- // "no opinion, let it through".
45
- console.error(`[writedocs] Could not reach the build authorization server: ${err.message}`);
46
- process.exit(1);
47
- }
48
-
49
- if (!valid) {
50
- console.error('[writedocs] build requires a valid --key (or WRITEDOCS_API_KEY) - the server rejected this one.');
51
- process.exit(1);
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
+ }