@glw907/cairn-cms 0.50.0 → 0.52.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.
Files changed (80) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/dist/components/EditPage.svelte +125 -16
  3. package/dist/components/EditPage.svelte.d.ts +4 -1
  4. package/dist/components/EditorToolbar.svelte +135 -10
  5. package/dist/components/EditorToolbar.svelte.d.ts +19 -2
  6. package/dist/components/MarkdownEditor.svelte +112 -6
  7. package/dist/components/MarkdownEditor.svelte.d.ts +4 -0
  8. package/dist/components/cairn-admin.css +69 -9
  9. package/dist/components/editor-highlight.d.ts +2 -0
  10. package/dist/components/editor-highlight.js +79 -15
  11. package/dist/components/editor-modes.d.ts +26 -0
  12. package/dist/components/editor-modes.js +92 -0
  13. package/dist/components/fonts/iAWriterMono-OFL.txt +100 -0
  14. package/dist/components/fonts/ia-writer-mono-latin-400-italic.woff2 +0 -0
  15. package/dist/components/fonts/ia-writer-mono-latin-400-normal.woff2 +0 -0
  16. package/dist/components/fonts/ia-writer-mono-latin-700-italic.woff2 +0 -0
  17. package/dist/components/fonts/ia-writer-mono-latin-700-normal.woff2 +0 -0
  18. package/dist/components/markdown-directives.d.ts +51 -0
  19. package/dist/components/markdown-directives.js +130 -1
  20. package/dist/components/preview-doc.d.ts +27 -0
  21. package/dist/components/preview-doc.js +64 -0
  22. package/dist/content/compose.js +1 -0
  23. package/dist/content/types.d.ts +33 -0
  24. package/dist/diagnostics/conditions.js +24 -0
  25. package/dist/doctor/bin.js +30 -12
  26. package/dist/doctor/check-floors.d.ts +15 -0
  27. package/dist/doctor/check-floors.js +107 -0
  28. package/dist/doctor/check-probe.d.ts +3 -0
  29. package/dist/doctor/check-probe.js +123 -0
  30. package/dist/doctor/checks-github.js +1 -1
  31. package/dist/doctor/checks-local.d.ts +1 -0
  32. package/dist/doctor/checks-local.js +28 -2
  33. package/dist/doctor/cloudflare-api.js +2 -2
  34. package/dist/doctor/index.d.ts +28 -3
  35. package/dist/doctor/index.js +47 -6
  36. package/dist/doctor/types.d.ts +2 -0
  37. package/dist/doctor/wrangler-config.d.ts +4 -0
  38. package/dist/doctor/wrangler-config.js +11 -0
  39. package/dist/env.d.ts +2 -1
  40. package/dist/env.js +9 -4
  41. package/dist/index.d.ts +1 -1
  42. package/dist/sveltekit/content-routes.d.ts +5 -1
  43. package/dist/sveltekit/content-routes.js +25 -17
  44. package/dist/sveltekit/guard.d.ts +8 -2
  45. package/dist/sveltekit/guard.js +3 -1
  46. package/dist/sveltekit/nav-routes.js +3 -9
  47. package/dist/vite/index.d.ts +16 -0
  48. package/dist/vite/index.js +57 -13
  49. package/package.json +2 -2
  50. package/src/lib/components/EditPage.svelte +125 -16
  51. package/src/lib/components/EditorToolbar.svelte +135 -10
  52. package/src/lib/components/MarkdownEditor.svelte +112 -6
  53. package/src/lib/components/cairn-admin.css +95 -5
  54. package/src/lib/components/editor-highlight.ts +91 -14
  55. package/src/lib/components/editor-modes.ts +106 -0
  56. package/src/lib/components/fonts/iAWriterMono-OFL.txt +100 -0
  57. package/src/lib/components/fonts/ia-writer-mono-latin-400-italic.woff2 +0 -0
  58. package/src/lib/components/fonts/ia-writer-mono-latin-400-normal.woff2 +0 -0
  59. package/src/lib/components/fonts/ia-writer-mono-latin-700-italic.woff2 +0 -0
  60. package/src/lib/components/fonts/ia-writer-mono-latin-700-normal.woff2 +0 -0
  61. package/src/lib/components/markdown-directives.ts +151 -1
  62. package/src/lib/components/preview-doc.ts +82 -0
  63. package/src/lib/content/compose.ts +1 -0
  64. package/src/lib/content/types.ts +32 -0
  65. package/src/lib/diagnostics/conditions.ts +24 -0
  66. package/src/lib/doctor/bin.ts +35 -10
  67. package/src/lib/doctor/check-floors.ts +124 -0
  68. package/src/lib/doctor/check-probe.ts +138 -0
  69. package/src/lib/doctor/checks-github.ts +3 -1
  70. package/src/lib/doctor/checks-local.ts +28 -2
  71. package/src/lib/doctor/cloudflare-api.ts +4 -2
  72. package/src/lib/doctor/index.ts +67 -6
  73. package/src/lib/doctor/types.ts +2 -0
  74. package/src/lib/doctor/wrangler-config.ts +11 -0
  75. package/src/lib/env.ts +9 -4
  76. package/src/lib/index.ts +2 -0
  77. package/src/lib/sveltekit/content-routes.ts +29 -17
  78. package/src/lib/sveltekit/guard.ts +4 -2
  79. package/src/lib/sveltekit/nav-routes.ts +3 -10
  80. package/src/lib/vite/index.ts +71 -17
@@ -0,0 +1,107 @@
1
+ // The dependency-floors check. The engine's peer ranges have teeth only when something reads
2
+ // the consumer's lockfile, where a transitively pinned svelte can sit below the floor while
3
+ // package.json looks fine (the ecxc retrofit shipped svelte 5.56.0 that way). The check compares
4
+ // the resolved svelte and @sveltejs/kit versions in package-lock.json against the peer ranges
5
+ // the installed @glw907/cairn-cms declares, read at runtime so the floors live in one place.
6
+ import { createRequire } from 'node:module';
7
+ import { fail, pass, skip } from './types.js';
8
+ // Plain x.y.z only. A prerelease or build tag returns null, so the check skips rather than
9
+ // guessing how a tagged build orders against the floor.
10
+ function parseVersion(text) {
11
+ const m = text.match(/^(\d+)\.(\d+)\.(\d+)$/);
12
+ if (!m)
13
+ return null;
14
+ return { major: Number(m[1]), minor: Number(m[2]), patch: Number(m[3]) };
15
+ }
16
+ // The engine's peers are simple caret ranges (^x.y.z, or ^x.y like the kit floor ^2.12), so
17
+ // this handles the caret form only; anything else returns null and the check skips for that
18
+ // dependency instead of approximating a full semver implementation.
19
+ function caretFloor(range) {
20
+ const m = range.match(/^\^(\d+)(?:\.(\d+))?(?:\.(\d+))?$/);
21
+ if (!m)
22
+ return null;
23
+ return { major: Number(m[1]), minor: Number(m[2] ?? 0), patch: Number(m[3] ?? 0) };
24
+ }
25
+ function compareVersions(a, b) {
26
+ return a.major - b.major || a.minor - b.minor || a.patch - b.patch;
27
+ }
28
+ function lockedVersion(lock, dep) {
29
+ const version = lock.packages?.[`node_modules/${dep}`]?.version;
30
+ return typeof version === 'string' ? version : undefined;
31
+ }
32
+ /**
33
+ * Judge a lockfile's resolved framework versions against the engine's peer ranges. Pure, so the
34
+ * tests drive it table-style; the check object wires in the real lockfile and the real peers.
35
+ * A below-range version fails; a lockfile or entry the check cannot read skips, since a pnpm or
36
+ * yarn consumer carries no package-lock.json at all.
37
+ */
38
+ export function dependencyFloorsResult(lockText, peers) {
39
+ if (lockText === null) {
40
+ return skip('no package-lock.json found (a pnpm or yarn lockfile is not read)');
41
+ }
42
+ let lock;
43
+ try {
44
+ lock = JSON.parse(lockText);
45
+ }
46
+ catch {
47
+ // Like the wrangler reader: never echo file content into the report.
48
+ return fail('package-lock.json did not parse');
49
+ }
50
+ if (lock.packages === undefined) {
51
+ return skip('package-lock.json carries no packages map (lockfile v1; reinstall with a current npm)');
52
+ }
53
+ const failures = [];
54
+ const skips = [];
55
+ const passes = [];
56
+ for (const [dep, range] of Object.entries(peers)) {
57
+ const floor = caretFloor(range);
58
+ if (floor === null) {
59
+ skips.push(`${dep}: the engine range ${range} is not a simple caret range`);
60
+ continue;
61
+ }
62
+ const resolved = lockedVersion(lock, dep);
63
+ if (resolved === undefined) {
64
+ skips.push(`${dep}: no node_modules/${dep} entry in package-lock.json`);
65
+ continue;
66
+ }
67
+ const version = parseVersion(resolved);
68
+ if (version === null) {
69
+ skips.push(`${dep}: resolved ${resolved} is not a plain x.y.z version`);
70
+ continue;
71
+ }
72
+ // The caret bounds both ends: at or above the floor, same major. The engine's peers
73
+ // start at major 1 or higher, so the 0.x caret nuance never applies here.
74
+ if (compareVersions(version, floor) < 0) {
75
+ failures.push(`${dep} resolves to ${resolved}, below the engine floor ${range}`);
76
+ }
77
+ else if (version.major !== floor.major) {
78
+ failures.push(`${dep} resolves to ${resolved}, outside the engine peer range ${range}`);
79
+ }
80
+ else {
81
+ passes.push(`${dep} ${resolved}`);
82
+ }
83
+ }
84
+ if (failures.length > 0)
85
+ return fail(failures.join('; '));
86
+ if (skips.length > 0)
87
+ return skip(skips.join('; '));
88
+ return pass(`${passes.join(' and ')} satisfy the engine peer ranges`);
89
+ }
90
+ /**
91
+ * The engine's own declared peer ranges, read from the installed package.json at runtime so the
92
+ * floors are declared exactly once. The self-reference resolves through the consumer's
93
+ * node_modules in a real install and through the repo root during development.
94
+ */
95
+ export function readEnginePeers() {
96
+ const require = createRequire(import.meta.url);
97
+ const pkg = require('@glw907/cairn-cms/package.json');
98
+ return pkg.peerDependencies ?? {};
99
+ }
100
+ export const configDependencyFloors = {
101
+ id: 'config.dependency-floors',
102
+ conditionId: 'config.dependency-floors-unmet',
103
+ title: 'Dependency floors',
104
+ async run(ctx) {
105
+ return dependencyFloorsResult(await ctx.readFile('package-lock.json'), readEnginePeers());
106
+ },
107
+ };
@@ -0,0 +1,3 @@
1
+ import type { DoctorCheck } from './types.js';
2
+ /** Build the live-probe check. A missing url falls back to the PUBLIC_ORIGIN input at run time. */
3
+ export declare function liveProbeCheck(url?: string): DoctorCheck;
@@ -0,0 +1,123 @@
1
+ // The doctor's opt-in live probe (--probe): one GET and one POST against a deployed admin,
2
+ // asserting the envelope a working sign-in presents. Zero side effects by construction: the
3
+ // POST submits a random non-editor address, and the engine's non-leak design answers a
4
+ // non-editor with the identical sent body while sending no email and minting no token, so the
5
+ // probe leaves nothing behind on the site. A factory rather than a check constant, the same
6
+ // shape as the live send: the check exists only when the bin receives --probe.
7
+ import { fail, pass, skip } from './types.js';
8
+ import { csrfCookieName } from '../auth/crypto.js';
9
+ import { readWranglerConfig } from './wrangler-config.js';
10
+ const NO_URL = skip('pass --probe <url>, set PUBLIC_ORIGIN in the wrangler vars, or set PUBLIC_ORIGIN in the environment');
11
+ /** Build the live-probe check. A missing url falls back to the PUBLIC_ORIGIN input at run time. */
12
+ export function liveProbeCheck(url) {
13
+ return {
14
+ id: 'admin.login-probe',
15
+ conditionId: 'admin.login-probe-failed',
16
+ title: 'Live admin login probe',
17
+ async run(ctx) {
18
+ // The wrangler vars hold the value the deployed Worker reads, so they beat the local
19
+ // environment, the same precedence the public-origin check applies.
20
+ const base = url ?? (await readWranglerConfig(ctx.readFile))?.publicOrigin ?? ctx.publicOrigin;
21
+ if (base === undefined)
22
+ return NO_URL;
23
+ let origin;
24
+ try {
25
+ origin = new URL(base);
26
+ }
27
+ catch {
28
+ return fail(`probe URL does not parse: ${base}`);
29
+ }
30
+ try {
31
+ return await probe(ctx, origin);
32
+ }
33
+ catch (err) {
34
+ return fail(String(err));
35
+ }
36
+ },
37
+ };
38
+ }
39
+ /** GET /admin/login and assert the sign-in envelope, then hand the harvested token pair on. */
40
+ async function probe(ctx, origin) {
41
+ const res = await ctx.fetch(String(new URL('/admin/login', origin)));
42
+ if (res.status !== 200) {
43
+ return fail(`GET /admin/login returned ${res.status}, expected 200`);
44
+ }
45
+ const cookieName = csrfCookieName(origin.protocol === 'https:');
46
+ const cookieValue = setCookieValue(res.headers.getSetCookie(), cookieName);
47
+ if (cookieValue === undefined) {
48
+ return fail(`GET /admin/login set no ${cookieName} cookie`);
49
+ }
50
+ const html = await res.text();
51
+ const field = csrfFieldValue(html);
52
+ if (field === undefined) {
53
+ return fail('the login page carries no name="csrf" hidden field with a value');
54
+ }
55
+ if (!/<form[^>]*action="[^"]*\?\/request"/.test(html)) {
56
+ return fail('the login page carries no form posting the ?/request action');
57
+ }
58
+ return postRequestAction(ctx, origin, `${cookieName}=${cookieValue}`, field);
59
+ }
60
+ /** The named cookie's value from the Set-Cookie lines, or undefined when no line names it. */
61
+ function setCookieValue(lines, name) {
62
+ for (const line of lines) {
63
+ const eq = line.indexOf('=');
64
+ if (eq === -1 || line.slice(0, eq).trim() !== name)
65
+ continue;
66
+ const rest = line.slice(eq + 1);
67
+ const semi = rest.indexOf(';');
68
+ return semi === -1 ? rest : rest.slice(0, semi);
69
+ }
70
+ return undefined;
71
+ }
72
+ /** The csrf hidden field's value, tolerant of attribute order, or undefined when absent or empty. */
73
+ function csrfFieldValue(html) {
74
+ const input = (html.match(/<input[^>]*>/g) ?? []).find((tag) => /name="csrf"/.test(tag));
75
+ if (input === undefined)
76
+ return undefined;
77
+ return /value="([^"]+)"/.exec(input)?.[1];
78
+ }
79
+ /**
80
+ * POST the request action and read its serialized result. The address is random and non-editor
81
+ * at the reserved example.invalid domain, so even a delivery bug could send nothing anywhere,
82
+ * and the engine's non-leak design makes the response indistinguishable from a real send.
83
+ */
84
+ async function postRequestAction(ctx, origin, cookie, csrf) {
85
+ const email = `cairn-doctor-probe-${Math.random().toString(36).slice(2, 10)}@example.invalid`;
86
+ const res = await ctx.fetch(String(new URL('/admin/login?/request', origin)), {
87
+ method: 'POST',
88
+ headers: {
89
+ 'content-type': 'application/x-www-form-urlencoded',
90
+ cookie,
91
+ },
92
+ body: new URLSearchParams({ email, csrf }).toString(),
93
+ });
94
+ if (res.status !== 200) {
95
+ return fail(`POST ?/request returned ${res.status}, expected 200`);
96
+ }
97
+ // A no-Accept action POST answers with SvelteKit's serialized form-action JSON, shaped
98
+ // {"type":"success","status":200,"data":"<devalue array string>"}. The data field is a
99
+ // devalue encoding the probe reads by containment for the status literals, tolerant of
100
+ // encoding details it does not own, instead of pulling in a devalue parser.
101
+ let envelope;
102
+ try {
103
+ envelope = (await res.json());
104
+ }
105
+ catch {
106
+ return fail('POST ?/request did not answer with the serialized action JSON');
107
+ }
108
+ if (envelope.type !== 'success') {
109
+ return fail(`POST ?/request answered type ${String(envelope.type)}, expected success`);
110
+ }
111
+ const data = typeof envelope.data === 'string' ? envelope.data : '';
112
+ if (data.includes('"send_error"')) {
113
+ return fail('the request action answered send_error; the magic-link send path is failing (see the email checks and the auth.link.send_failed log records)');
114
+ }
115
+ // Every payload carries the "sent" field name, so the distinct status spellings go first.
116
+ if (data.includes('"throttled"')) {
117
+ return pass(`sign-in envelope verified at ${origin.origin}; the request action answered throttled (a real cooldown window is active), which still proves the path`);
118
+ }
119
+ if (data.includes('"sent"')) {
120
+ return pass(`sign-in envelope verified at ${origin.origin}; the request action answered sent for a non-editor probe address`);
121
+ }
122
+ return fail('POST ?/request answered success with an unrecognized payload');
123
+ }
@@ -17,7 +17,7 @@ export const githubApp = {
17
17
  return skip('set GITHUB_APP_ID, GITHUB_APP_INSTALLATION_ID, and GITHUB_APP_PRIVATE_KEY_B64 to run this check');
18
18
  }
19
19
  if (!ctx.repo) {
20
- return skip('pass --repo or set GITHUB_REPO to run this check');
20
+ return skip('pass --repo, set GITHUB_REPO, or configure the cairnManifest plugin so the doctor can read the adapter');
21
21
  }
22
22
  const creds = appCredentials({ appId: ctx.github.appId, installationId: ctx.github.installationId }, { GITHUB_APP_PRIVATE_KEY_B64: ctx.github.privateKeyB64 });
23
23
  // Stage 1: the key parse and sign, through the deploy-time self-test. Its detail is a
@@ -2,4 +2,5 @@ import type { DoctorCheck } from './types.js';
2
2
  export declare const configBindings: DoctorCheck;
3
3
  export declare const configObservability: DoctorCheck;
4
4
  export declare const configCsrfDisable: DoctorCheck;
5
+ export declare const configPublicOrigin: DoctorCheck;
5
6
  export declare const configSiteConfig: DoctorCheck;
@@ -1,8 +1,9 @@
1
1
  // The doctor's local-config checks: the wrangler bindings, the observability sink, the
2
- // svelte.config CSRF handoff, and the site-config validation. Every read goes through the
3
- // injected ctx.readFile, so the tests pass fixtures and the bin passes node:fs.
2
+ // svelte.config CSRF handoff, the site-config validation, and the public origin. Every read
3
+ // goes through the injected ctx.readFile, so the tests pass fixtures and the bin passes node:fs.
4
4
  import { fail, pass, skip } from './types.js';
5
5
  import { readWranglerConfig } from './wrangler-config.js';
6
+ import { requireOrigin } from '../env.js';
6
7
  import { parseSiteConfig, urlPolicyFrom } from '../nav/site-config.js';
7
8
  import { normalizeConcepts } from '../content/concepts.js';
8
9
  import { defineFields } from '../content/schema.js';
@@ -78,6 +79,31 @@ export const configCsrfDisable = {
78
79
  return pass('checkOrigin: false found and the hooks file wires the cairn guard (heuristic text read)');
79
80
  },
80
81
  };
82
+ export const configPublicOrigin = {
83
+ id: 'config.public-origin',
84
+ conditionId: 'config.public-origin-invalid',
85
+ title: 'Public origin',
86
+ async run(ctx) {
87
+ // The wrangler vars hold the value the deployed Worker reads, so they beat the local
88
+ // environment; the env fallback covers a dashboard-set var the file never carries.
89
+ const facts = await readWranglerConfig(ctx.readFile);
90
+ const fromVars = facts?.publicOrigin;
91
+ const origin = fromVars ?? ctx.publicOrigin;
92
+ if (facts === null && origin === undefined) {
93
+ return skip('no wrangler config found and PUBLIC_ORIGIN is not in the environment');
94
+ }
95
+ // requireOrigin is the runtime rule (unset, not a URL, http off localhost); reusing it
96
+ // keeps the doctor and the Worker on one judgment.
97
+ try {
98
+ requireOrigin({ PUBLIC_ORIGIN: origin });
99
+ }
100
+ catch (err) {
101
+ return fail(err instanceof Error ? err.message : String(err));
102
+ }
103
+ const source = fromVars !== undefined ? 'wrangler vars' : 'environment';
104
+ return pass(`PUBLIC_ORIGIN is ${origin} (${source})`);
105
+ },
106
+ };
81
107
  // Where sites keep site.config.yaml. The adapter's configPath is TypeScript the CLI cannot
82
108
  // evaluate, so the check probes the conventional spots instead (the repo root and the two
83
109
  // src locations the production sites use).
@@ -5,8 +5,8 @@
5
5
  import { skip } from './types.js';
6
6
  export const CF_API = 'https://api.cloudflare.com/client/v4';
7
7
  export const NO_TOKEN = skip('set CLOUDFLARE_API_TOKEN to run this check');
8
- export const NO_FROM = skip('pass --from or set CAIRN_FROM to run this check');
9
- export const NO_ACCOUNT = skip('set CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID to run this check');
8
+ export const NO_FROM = skip('pass --from, set CAIRN_FROM, or configure the cairnManifest plugin so the doctor can read the adapter');
9
+ export const NO_ACCOUNT = skip('set CLOUDFLARE_API_TOKEN, and CLOUDFLARE_ACCOUNT_ID or a wrangler account_id, to run this check');
10
10
  export function cfGet(ctx, path) {
11
11
  return ctx.fetch(`${CF_API}${path}`, {
12
12
  headers: { authorization: `Bearer ${ctx.cfToken}` },
@@ -5,6 +5,9 @@ export interface DoctorArgs {
5
5
  from?: string;
6
6
  repo?: string;
7
7
  sendTest?: string;
8
+ /** The live admin probe: a URL when --probe carried one, true for the bare flag (probe the
9
+ * PUBLIC_ORIGIN input), absent when the flag never appeared (the probe does not run). */
10
+ probe?: string | true;
8
11
  }
9
12
  /** Parse the bin's argv (long flags only). Throws with a usage line on anything unexpected. */
10
13
  export declare function parseArgs(argv: string[]): DoctorArgs;
@@ -15,9 +18,31 @@ export declare function parseArgs(argv: string[]): DoctorArgs;
15
18
  * readFile stay with the bin, which injects the real ones.
16
19
  */
17
20
  export declare function contextFromEnv(env: Record<string, string | undefined>, args: DoctorArgs, cwd: string): Omit<DoctorContext, 'fetch' | 'readFile'>;
21
+ /** The lazy derivation sources the bin wires up: the adapter read through the consumer's own
22
+ * Vite resolution and the wrangler config's account_id. Each runs only when an input it feeds
23
+ * is still missing, so a doctor run with full flags touches neither. */
24
+ export interface DerivationSources {
25
+ /** Returns { owner, repo, from } off the adapter, or null when nothing is derivable. */
26
+ adapterFacts: () => Promise<{
27
+ owner?: string;
28
+ repo?: string;
29
+ from?: string;
30
+ } | null>;
31
+ /** Returns the wrangler config's account_id, or undefined when none is declared. */
32
+ wranglerAccountId: () => Promise<string | undefined>;
33
+ }
34
+ /**
35
+ * Fill the context's missing inputs from the repo the doctor runs in: from and repo off the
36
+ * adapter, the account id off the wrangler config. An explicit flag or env value always wins
37
+ * (contextFromEnv already resolved those into ctx), each source runs lazily and only for
38
+ * inputs still missing, and a derivation failure leaves the input absent so its check skips
39
+ * with the usual remediation line instead of the doctor crashing. The API token is never
40
+ * derived; it stays env-only.
41
+ */
42
+ export declare function deriveMissingInputs(ctx: Omit<DoctorContext, 'fetch' | 'readFile'>, sources: DerivationSources): Promise<Omit<DoctorContext, 'fetch' | 'readFile'>>;
18
43
  /**
19
- * The default registry: the four local-config checks, the four Cloudflare checks, and the
20
- * GitHub App chain. The live send is opt-in (--send-test) and never sits here; the bin appends
21
- * it. A fresh array per call, so that append mutates nothing shared.
44
+ * The default registry: the six local checks, the four Cloudflare checks, and the GitHub App
45
+ * chain. The live send is opt-in (--send-test) and never sits here; the bin appends it. A
46
+ * fresh array per call, so that append mutates nothing shared.
22
47
  */
23
48
  export declare function defaultChecks(): DoctorCheck[];
@@ -1,9 +1,10 @@
1
- import { configBindings, configObservability, configCsrfDisable, configSiteConfig, } from './checks-local.js';
1
+ import { configBindings, configObservability, configCsrfDisable, configSiteConfig, configPublicOrigin, } from './checks-local.js';
2
+ import { configDependencyFloors } from './check-floors.js';
2
3
  import { emailSenderOnboarded, edgeHttpsForced, edgeHsts, authStore } from './checks-cloudflare.js';
3
4
  import { githubApp } from './checks-github.js';
4
5
  export { runDoctor } from './run.js';
5
6
  export { formatReport } from './report.js';
6
- const USAGE = 'Usage: cairn-doctor [--from <address>] [--repo <owner/name>] [--send-test <address>]';
7
+ const USAGE = 'Usage: cairn-doctor [--from <address>] [--repo <owner/name>] [--send-test <address>] [--probe [url]]';
7
8
  const FLAGS = {
8
9
  '--from': 'from',
9
10
  '--repo': 'repo',
@@ -12,8 +13,16 @@ const FLAGS = {
12
13
  /** Parse the bin's argv (long flags only). Throws with a usage line on anything unexpected. */
13
14
  export function parseArgs(argv) {
14
15
  const args = {};
15
- for (let i = 0; i < argv.length; i += 2) {
16
+ for (let i = 0; i < argv.length;) {
16
17
  const flag = argv[i];
18
+ // --probe alone is meaningful (probe the PUBLIC_ORIGIN input), so its value is optional.
19
+ if (flag === '--probe') {
20
+ const value = argv[i + 1];
21
+ const bare = value === undefined || value.startsWith('--');
22
+ args.probe = bare ? true : value;
23
+ i += bare ? 1 : 2;
24
+ continue;
25
+ }
17
26
  const key = FLAGS[flag];
18
27
  if (!key)
19
28
  throw new Error(`unknown argument ${flag}\n${USAGE}`);
@@ -22,6 +31,7 @@ export function parseArgs(argv) {
22
31
  throw new Error(`${flag} needs a value\n${USAGE}`);
23
32
  }
24
33
  args[key] = value;
34
+ i += 2;
25
35
  }
26
36
  return args;
27
37
  }
@@ -39,6 +49,7 @@ export function contextFromEnv(env, args, cwd) {
39
49
  repo: args.repo ?? env.GITHUB_REPO,
40
50
  cfToken: env.CLOUDFLARE_API_TOKEN,
41
51
  cfAccountId: env.CLOUDFLARE_ACCOUNT_ID,
52
+ publicOrigin: env.PUBLIC_ORIGIN,
42
53
  github: GITHUB_APP_ID && GITHUB_APP_INSTALLATION_ID && GITHUB_APP_PRIVATE_KEY_B64
43
54
  ? {
44
55
  appId: GITHUB_APP_ID,
@@ -49,9 +60,37 @@ export function contextFromEnv(env, args, cwd) {
49
60
  };
50
61
  }
51
62
  /**
52
- * The default registry: the four local-config checks, the four Cloudflare checks, and the
53
- * GitHub App chain. The live send is opt-in (--send-test) and never sits here; the bin appends
54
- * it. A fresh array per call, so that append mutates nothing shared.
63
+ * Fill the context's missing inputs from the repo the doctor runs in: from and repo off the
64
+ * adapter, the account id off the wrangler config. An explicit flag or env value always wins
65
+ * (contextFromEnv already resolved those into ctx), each source runs lazily and only for
66
+ * inputs still missing, and a derivation failure leaves the input absent so its check skips
67
+ * with the usual remediation line instead of the doctor crashing. The API token is never
68
+ * derived; it stays env-only.
69
+ */
70
+ export async function deriveMissingInputs(ctx, sources) {
71
+ const out = { ...ctx };
72
+ if (out.from === undefined || out.repo === undefined) {
73
+ const facts = await sources.adapterFacts().catch(() => null);
74
+ if (out.from === undefined && typeof facts?.from === 'string') {
75
+ out.from = facts.from;
76
+ }
77
+ if (out.repo === undefined &&
78
+ typeof facts?.owner === 'string' &&
79
+ typeof facts?.repo === 'string') {
80
+ out.repo = `${facts.owner}/${facts.repo}`;
81
+ }
82
+ }
83
+ if (out.cfAccountId === undefined) {
84
+ const accountId = await sources.wranglerAccountId().catch(() => undefined);
85
+ if (typeof accountId === 'string')
86
+ out.cfAccountId = accountId;
87
+ }
88
+ return out;
89
+ }
90
+ /**
91
+ * The default registry: the six local checks, the four Cloudflare checks, and the GitHub App
92
+ * chain. The live send is opt-in (--send-test) and never sits here; the bin appends it. A
93
+ * fresh array per call, so that append mutates nothing shared.
55
94
  */
56
95
  export function defaultChecks() {
57
96
  return [
@@ -59,6 +98,8 @@ export function defaultChecks() {
59
98
  configObservability,
60
99
  configCsrfDisable,
61
100
  configSiteConfig,
101
+ configPublicOrigin,
102
+ configDependencyFloors,
62
103
  emailSenderOnboarded,
63
104
  edgeHttpsForced,
64
105
  edgeHsts,
@@ -28,6 +28,8 @@ export interface DoctorContext {
28
28
  cfToken?: string;
29
29
  /** CLOUDFLARE_ACCOUNT_ID. */
30
30
  cfAccountId?: string;
31
+ /** PUBLIC_ORIGIN, the env fallback when the wrangler vars carry none. */
32
+ publicOrigin?: string;
31
33
  /** GITHUB_APP_ID / GITHUB_APP_INSTALLATION_ID / GITHUB_APP_PRIVATE_KEY_B64. */
32
34
  github?: {
33
35
  appId: string;
@@ -8,5 +8,9 @@ export interface WranglerFacts {
8
8
  authDbId?: string;
9
9
  /** observability.enabled is true. */
10
10
  observabilityEnabled: boolean;
11
+ /** vars.PUBLIC_ORIGIN, when declared; the public-origin check validates it. */
12
+ publicOrigin?: string;
13
+ /** The top-level account_id, when declared; a fallback for CLOUDFLARE_ACCOUNT_ID. */
14
+ accountId?: string;
11
15
  }
12
16
  export declare function readWranglerConfig(readFile: DoctorContext['readFile']): Promise<WranglerFacts | null>;
@@ -71,6 +71,11 @@ function factsFromJsonc(text) {
71
71
  };
72
72
  if (typeof authDb?.database_id === 'string')
73
73
  facts.authDbId = authDb.database_id;
74
+ const vars = config.vars;
75
+ if (typeof vars?.PUBLIC_ORIGIN === 'string')
76
+ facts.publicOrigin = vars.PUBLIC_ORIGIN;
77
+ if (typeof config.account_id === 'string')
78
+ facts.accountId = config.account_id;
74
79
  return facts;
75
80
  }
76
81
  // The toml read is deliberately shallow: line-anchored matching for the three facts, not a
@@ -119,6 +124,12 @@ function factsFromToml(text) {
119
124
  else if (section === '[observability]' && key === 'enabled' && value.startsWith('true')) {
120
125
  facts.observabilityEnabled = true;
121
126
  }
127
+ else if (section === '[vars]' && key === 'PUBLIC_ORIGIN' && str !== undefined) {
128
+ facts.publicOrigin = str;
129
+ }
130
+ else if (section === '' && key === 'account_id' && str !== undefined) {
131
+ facts.accountId = str;
132
+ }
122
133
  }
123
134
  flushD1();
124
135
  return facts;
package/dist/env.d.ts CHANGED
@@ -5,7 +5,8 @@ import type { D1Database } from '@cloudflare/workers-types';
5
5
  * The origin is always config-derived, never read from a request header, so a
6
6
  * forged Host header cannot redirect a magic link (spec 7.1, risk H3).
7
7
  *
8
- * @throws Error when `PUBLIC_ORIGIN` is unset or empty.
8
+ * @throws CairnError (`config.public-origin-invalid`) when `PUBLIC_ORIGIN` is unset or
9
+ * empty, fails to parse as a URL, or uses http on a non-local host.
9
10
  */
10
11
  export declare function requireOrigin(env: {
11
12
  PUBLIC_ORIGIN?: string;
package/dist/env.js CHANGED
@@ -5,26 +5,31 @@ import { CairnError } from './diagnostics/index.js';
5
5
  * The origin is always config-derived, never read from a request header, so a
6
6
  * forged Host header cannot redirect a magic link (spec 7.1, risk H3).
7
7
  *
8
- * @throws Error when `PUBLIC_ORIGIN` is unset or empty.
8
+ * @throws CairnError (`config.public-origin-invalid`) when `PUBLIC_ORIGIN` is unset or
9
+ * empty, fails to parse as a URL, or uses http on a non-local host.
9
10
  */
10
11
  export function requireOrigin(env) {
11
12
  const origin = env.PUBLIC_ORIGIN;
12
13
  if (!origin) {
13
- throw new Error('PUBLIC_ORIGIN is not configured');
14
+ throw new CairnError('config.public-origin-invalid', { message: 'PUBLIC_ORIGIN is not configured' });
14
15
  }
15
16
  let hostname;
16
17
  try {
17
18
  hostname = new URL(origin).hostname;
18
19
  }
19
20
  catch {
20
- throw new Error(`PUBLIC_ORIGIN is not a valid URL, got ${origin}`);
21
+ throw new CairnError('config.public-origin-invalid', {
22
+ message: `PUBLIC_ORIGIN is not a valid URL, got ${origin}`,
23
+ });
21
24
  }
22
25
  // The magic-link origin must be https in production so the link and the __Host- cookie are
23
26
  // origin-bound. http is allowed only for local dev on localhost or 127.0.0.1, matched exactly so
24
27
  // a lookalike host like localhost.example.com cannot skip the https requirement.
25
28
  const isLocal = hostname === 'localhost' || hostname === '127.0.0.1';
26
29
  if (!origin.startsWith('https://') && !isLocal) {
27
- throw new Error(`PUBLIC_ORIGIN must be https in production, got ${origin}`);
30
+ throw new CairnError('config.public-origin-invalid', {
31
+ message: `PUBLIC_ORIGIN must be https in production, got ${origin}`,
32
+ });
28
33
  }
29
34
  return origin;
30
35
  }
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { requireOrigin } from './env.js';
2
2
  export type { Role, Editor, AuthEnv } from './auth/types.js';
3
3
  export type { AuthBranding, MagicLinkMessage, SendMagicLink } from './email.js';
4
4
  export { buildMagicLinkMessage, cloudflareSend } from './email.js';
5
- export type { CairnAdapter, ConceptConfig, FrontmatterField, TextField, TextareaField, DateField, BooleanField, TagsField, FreeTagsField, ValidationResult, BackendConfig, SenderConfig, NavMenuConfig, AssetConfig, RoutingRule, ConceptDescriptor, ConceptUrlPolicy, CairnExtension, CairnRuntime, AdminPanel, FieldTypeDef, } from './content/types.js';
5
+ export type { CairnAdapter, ConceptConfig, FrontmatterField, TextField, TextareaField, DateField, BooleanField, TagsField, FreeTagsField, ValidationResult, BackendConfig, SenderConfig, NavMenuConfig, PreviewConfig, ResolvedPreview, AssetConfig, RoutingRule, ConceptDescriptor, ConceptUrlPolicy, CairnExtension, CairnRuntime, AdminPanel, FieldTypeDef, } from './content/types.js';
6
6
  export { CONCEPT_ROUTING, normalizeConcepts, findConcept } from './content/concepts.js';
7
7
  export { composeRuntime } from './content/compose.js';
8
8
  export type { ComposeInput } from './content/compose.js';
@@ -2,7 +2,7 @@ import { fail } from '@sveltejs/kit';
2
2
  import { type GithubKeyEnv } from '../github/credentials.js';
3
3
  import { type LinkTarget, type InboundLink } from '../content/manifest.js';
4
4
  import type { CookieJar, EventBase } from './types.js';
5
- import type { CairnRuntime, FrontmatterField } from '../content/types.js';
5
+ import type { CairnRuntime, FrontmatterField, ResolvedPreview } from '../content/types.js';
6
6
  import type { Role } from '../auth/types.js';
7
7
  /** A sidebar concept entry: just enough to render the nav without shipping validators to the client. */
8
8
  export interface NavConcept {
@@ -87,6 +87,10 @@ export interface EditData {
87
87
  publishedFlash: boolean;
88
88
  /** True after a discard redirect (`?discarded=1`), for the confirmation strip. */
89
89
  discardedFlash: boolean;
90
+ /** The adapter's preview knob resolved for this entry's concept (its `byConcept` override,
91
+ * when one exists, applied over the top-level values); null when the site sets none, which
92
+ * leaves the frame rendering unstyled markup behind a hint. */
93
+ preview: ResolvedPreview | null;
90
94
  }
91
95
  /** The structural event the content routes read; a real SvelteKit RequestEvent satisfies it. */
92
96
  export interface ContentEvent extends EventBase<GithubKeyEnv> {