@conloca/cloud-astro 0.2.1 → 0.2.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.
Files changed (181) hide show
  1. package/README.md +261 -207
  2. package/dist/.build-inputs.json +60 -0
  3. package/dist/src/component-manifest.d.ts +5 -3
  4. package/dist/src/component-manifest.d.ts.map +1 -1
  5. package/dist/src/component-manifest.js +7 -7
  6. package/dist/src/component-manifest.js.map +1 -1
  7. package/dist/src/constants.d.ts +5 -13
  8. package/dist/src/constants.d.ts.map +1 -1
  9. package/dist/src/constants.js +5 -13
  10. package/dist/src/constants.js.map +1 -1
  11. package/dist/src/descriptors.d.ts +2 -2
  12. package/dist/src/descriptors.d.ts.map +1 -1
  13. package/dist/src/doctor/checks-address.d.ts +18 -0
  14. package/dist/src/doctor/checks-address.d.ts.map +1 -0
  15. package/dist/src/doctor/checks-address.js +163 -0
  16. package/dist/src/doctor/checks-address.js.map +1 -0
  17. package/dist/src/doctor/checks-live.d.ts +8 -5
  18. package/dist/src/doctor/checks-live.d.ts.map +1 -1
  19. package/dist/src/doctor/checks-live.js +220 -188
  20. package/dist/src/doctor/checks-live.js.map +1 -1
  21. package/dist/src/doctor/checks-offline.d.ts +8 -23
  22. package/dist/src/doctor/checks-offline.d.ts.map +1 -1
  23. package/dist/src/doctor/checks-offline.js +22 -239
  24. package/dist/src/doctor/checks-offline.js.map +1 -1
  25. package/dist/src/doctor/config-scan.d.ts +6 -3
  26. package/dist/src/doctor/config-scan.d.ts.map +1 -1
  27. package/dist/src/doctor/config-scan.js +21 -11
  28. package/dist/src/doctor/config-scan.js.map +1 -1
  29. package/dist/src/doctor/run.d.ts.map +1 -1
  30. package/dist/src/doctor/run.js +12 -10
  31. package/dist/src/doctor/run.js.map +1 -1
  32. package/dist/src/doctor/types.d.ts +7 -7
  33. package/dist/src/doctor/types.d.ts.map +1 -1
  34. package/dist/src/doctor/types.js +7 -7
  35. package/dist/src/doctor/types.js.map +1 -1
  36. package/dist/src/editor-page/bundle.d.ts +88 -0
  37. package/dist/src/editor-page/bundle.d.ts.map +1 -0
  38. package/dist/src/editor-page/bundle.js +370 -0
  39. package/dist/src/editor-page/bundle.js.map +1 -0
  40. package/dist/src/editor-page/emit.d.ts +33 -0
  41. package/dist/src/editor-page/emit.d.ts.map +1 -0
  42. package/dist/src/editor-page/emit.js +183 -0
  43. package/dist/src/editor-page/emit.js.map +1 -0
  44. package/dist/src/editor-page/framing.d.ts +23 -0
  45. package/dist/src/editor-page/framing.d.ts.map +1 -0
  46. package/dist/src/editor-page/framing.js +39 -0
  47. package/dist/src/editor-page/framing.js.map +1 -0
  48. package/dist/src/editor-page/page.d.ts +9 -0
  49. package/dist/src/editor-page/page.d.ts.map +1 -0
  50. package/dist/src/editor-page/page.js +31 -0
  51. package/dist/src/editor-page/page.js.map +1 -0
  52. package/dist/src/editor-page/site-base.d.ts +4 -0
  53. package/dist/src/editor-page/site-base.d.ts.map +1 -0
  54. package/dist/src/editor-page/site-base.js +13 -0
  55. package/dist/src/editor-page/site-base.js.map +1 -0
  56. package/dist/src/git.d.ts +11 -8
  57. package/dist/src/git.d.ts.map +1 -1
  58. package/dist/src/git.js +25 -8
  59. package/dist/src/git.js.map +1 -1
  60. package/dist/src/index.d.ts +3 -1
  61. package/dist/src/index.d.ts.map +1 -1
  62. package/dist/src/index.js +9 -6
  63. package/dist/src/index.js.map +1 -1
  64. package/dist/src/integration.d.ts +1 -1
  65. package/dist/src/integration.d.ts.map +1 -1
  66. package/dist/src/integration.js +245 -396
  67. package/dist/src/integration.js.map +1 -1
  68. package/dist/src/node.d.ts +3 -1
  69. package/dist/src/node.d.ts.map +1 -1
  70. package/dist/src/node.js +7 -2
  71. package/dist/src/node.js.map +1 -1
  72. package/dist/src/preview/_dispatch.d.ts +5 -2
  73. package/dist/src/preview/_dispatch.d.ts.map +1 -1
  74. package/dist/src/preview/_dispatch.js +2 -0
  75. package/dist/src/preview/_dispatch.js.map +1 -1
  76. package/dist/src/preview/_resolve-opts.d.ts +18 -10
  77. package/dist/src/preview/_resolve-opts.d.ts.map +1 -1
  78. package/dist/src/preview/_resolve-opts.js +24 -10
  79. package/dist/src/preview/_resolve-opts.js.map +1 -1
  80. package/dist/src/preview/banner.d.ts.map +1 -1
  81. package/dist/src/preview/banner.js +2 -4
  82. package/dist/src/preview/banner.js.map +1 -1
  83. package/dist/src/preview/cookie.d.ts +5 -2
  84. package/dist/src/preview/cookie.d.ts.map +1 -1
  85. package/dist/src/preview/cookie.js +5 -2
  86. package/dist/src/preview/cookie.js.map +1 -1
  87. package/dist/src/preview/label.d.ts +8 -0
  88. package/dist/src/preview/label.d.ts.map +1 -0
  89. package/dist/src/preview/label.js +14 -0
  90. package/dist/src/preview/label.js.map +1 -0
  91. package/dist/src/preview/landing.d.ts +2 -2
  92. package/dist/src/preview/landing.js +2 -2
  93. package/dist/src/preview/middleware.d.ts +31 -20
  94. package/dist/src/preview/middleware.d.ts.map +1 -1
  95. package/dist/src/preview/middleware.js +56 -51
  96. package/dist/src/preview/middleware.js.map +1 -1
  97. package/dist/src/preview/preview-path.d.ts +18 -5
  98. package/dist/src/preview/preview-path.d.ts.map +1 -1
  99. package/dist/src/preview/preview-path.js +24 -8
  100. package/dist/src/preview/preview-path.js.map +1 -1
  101. package/dist/src/preview/site-middleware.d.ts +5 -5
  102. package/dist/src/preview/site-middleware.d.ts.map +1 -1
  103. package/dist/src/preview/site-middleware.js +17 -16
  104. package/dist/src/preview/site-middleware.js.map +1 -1
  105. package/dist/src/preview-build.d.ts +18 -15
  106. package/dist/src/preview-build.d.ts.map +1 -1
  107. package/dist/src/preview-build.js +36 -21
  108. package/dist/src/preview-build.js.map +1 -1
  109. package/dist/src/preview.d.ts +1 -1
  110. package/dist/src/preview.d.ts.map +1 -1
  111. package/dist/src/preview.js +1 -1
  112. package/dist/src/preview.js.map +1 -1
  113. package/dist/src/repository.d.ts +1 -1
  114. package/dist/src/repository.js +1 -1
  115. package/dist/src/resolve-options.d.ts +17 -0
  116. package/dist/src/resolve-options.d.ts.map +1 -0
  117. package/dist/src/resolve-options.js +21 -0
  118. package/dist/src/resolve-options.js.map +1 -0
  119. package/dist/src/site-id.d.ts +0 -2
  120. package/dist/src/site-id.d.ts.map +1 -1
  121. package/dist/src/site-id.js +2 -3
  122. package/dist/src/site-id.js.map +1 -1
  123. package/dist/src/types.d.ts +21 -59
  124. package/dist/src/types.d.ts.map +1 -1
  125. package/package.json +44 -15
  126. package/src/component-manifest.ts +11 -8
  127. package/src/constants.ts +5 -14
  128. package/src/descriptors.ts +2 -2
  129. package/src/doctor/checks-address.ts +190 -0
  130. package/src/doctor/checks-live.ts +256 -268
  131. package/src/doctor/checks-offline.ts +24 -262
  132. package/src/doctor/config-scan.ts +21 -9
  133. package/src/doctor/run.ts +14 -16
  134. package/src/doctor/types.ts +7 -7
  135. package/src/editor-page/bundle.ts +482 -0
  136. package/src/editor-page/emit.ts +246 -0
  137. package/src/editor-page/framing.ts +62 -0
  138. package/src/editor-page/page.ts +37 -0
  139. package/src/editor-page/site-base.ts +11 -0
  140. package/src/git.ts +29 -10
  141. package/src/index.ts +20 -6
  142. package/src/integration.ts +255 -449
  143. package/src/node.ts +18 -2
  144. package/src/preview/_dispatch.ts +6 -2
  145. package/src/preview/_resolve-opts.ts +34 -11
  146. package/src/preview/banner.ts +2 -4
  147. package/src/preview/cookie.ts +5 -2
  148. package/src/preview/label.ts +12 -0
  149. package/src/preview/landing.ts +2 -2
  150. package/src/preview/middleware.ts +83 -66
  151. package/src/preview/preview-path.ts +26 -8
  152. package/src/preview/site-middleware.ts +17 -21
  153. package/src/preview-build.ts +42 -26
  154. package/src/preview-handler.astro +10 -8
  155. package/src/preview.ts +0 -1
  156. package/src/repository.ts +1 -1
  157. package/src/resolve-options.ts +37 -0
  158. package/src/site-id.ts +2 -4
  159. package/src/skill/SKILL.md +51 -55
  160. package/src/types.ts +21 -60
  161. package/src/virtual-modules.d.ts +5 -1
  162. package/dist/src/build-commit.d.ts +0 -19
  163. package/dist/src/build-commit.d.ts.map +0 -1
  164. package/dist/src/build-commit.js +0 -6
  165. package/dist/src/build-commit.js.map +0 -1
  166. package/dist/src/bundle.d.ts +0 -173
  167. package/dist/src/bundle.d.ts.map +0 -1
  168. package/dist/src/bundle.js +0 -413
  169. package/dist/src/bundle.js.map +0 -1
  170. package/dist/src/discovery.d.ts +0 -58
  171. package/dist/src/discovery.d.ts.map +0 -1
  172. package/dist/src/discovery.js +0 -133
  173. package/dist/src/discovery.js.map +0 -1
  174. package/dist/src/register.d.ts +0 -98
  175. package/dist/src/register.d.ts.map +0 -1
  176. package/dist/src/register.js +0 -103
  177. package/dist/src/register.js.map +0 -1
  178. package/src/build-commit.ts +0 -22
  179. package/src/bundle.ts +0 -563
  180. package/src/discovery.ts +0 -183
  181. package/src/register.ts +0 -180
@@ -0,0 +1,190 @@
1
+ import { join, relative } from 'node:path';
2
+ import { addressSiteName, isValidSiteBase, type SitesConfig } from '@conloca/content-api';
3
+ import { isRecord } from '@conloca/content-api/component-vocabulary';
4
+ import { EDITOR_PAGE_PATH, editorUiOrigin, parentRoot } from '@conloca/content-api/editor-host';
5
+ import { findFramingBlockers, framingSnippets } from '../editor-page/framing.js';
6
+ import { baseMismatch } from '../editor-page/site-base.js';
7
+ import { INTEGRATION_NOT_CALLED } from './checks-offline.js';
8
+ import type { ConfigScan } from './config-scan.js';
9
+ import { type CheckOutcome, type DoctorDeps, outcomeOf, skipped } from './types.js';
10
+
11
+ /** The server's bare-host rule: lowercase dot-separated labels of letters, digits and inner hyphens; no scheme, port or path. */
12
+ const PLAIN_HOST = /^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/;
13
+
14
+ /**
15
+ * Why the editor's address rule refuses a bare host, else undefined.
16
+ * shortcut: the editor also refuses its own login host and private names; those surface only in the editor's setup
17
+ * list, since doctor cannot tell them without the editor's settings.
18
+ */
19
+ function refusedHost(host: string): string | undefined {
20
+ // WHATWG rewrites IPv4 shorthands (`127.1`) and refuses a host ending in a number that is no IPv4.
21
+ const parsed = URL.canParse(`https://${host}/`) ? new URL(`https://${host}/`).hostname : null;
22
+ if (parsed !== host || /^\d+(\.\d+){3}$/.test(host)) return 'an IP address';
23
+ if (host === 'localhost' || host.endsWith('.localhost')) return 'localhost';
24
+ // Bare `conloca.com` is Conloca's own website, which the rule allows for that one repository.
25
+ if (host.endsWith('.conloca.com')) return 'a conloca.com host';
26
+ return undefined;
27
+ }
28
+
29
+ /** What the build key setup left behind: its environment variable and the options that went with it. */
30
+ const LEFTOVER_KEY_NAMES = [
31
+ 'CONLOCA_BUILD_TOKEN',
32
+ 'buildToken',
33
+ 'publicBaseUrl',
34
+ 'previewDomain',
35
+ 'requireRegistration',
36
+ ] as const;
37
+ const LEFTOVER_RE = new RegExp(`\\b(?:${LEFTOVER_KEY_NAMES.join('|')})\\b`, 'g');
38
+
39
+ /** The fields of sites.json the address reads; the rest is the editor's business. */
40
+ function isSitesConfig(value: unknown): value is SitesConfig {
41
+ return (
42
+ isRecord(value) &&
43
+ isRecord(value.sites) &&
44
+ Object.values(value.sites).every(
45
+ (site) =>
46
+ isRecord(site) &&
47
+ typeof site.defaultLocale === 'string' &&
48
+ (site.domains === undefined || isRecord(site.domains)) &&
49
+ (site.base === undefined || typeof site.base === 'string'),
50
+ )
51
+ );
52
+ }
53
+
54
+ /** CC9's outcome and, when it passed, the address the live checks contact. */
55
+ interface SiteAddressCheck {
56
+ outcome: CheckOutcome;
57
+ address?: string;
58
+ }
59
+
60
+ /**
61
+ * CC9 — the address the editor frames, `https://<domains[defaultLocale]><base>` of the site `addressSiteName` picks,
62
+ * by the same rule the server applies. Astro's own `site` and `base`, when the config text shows them, must agree.
63
+ */
64
+ export function checkSiteAddress(
65
+ scan: ConfigScan,
66
+ contentRoot: string,
67
+ deps: Pick<DoctorDeps, 'readFile'>,
68
+ ): SiteAddressCheck {
69
+ if (scan.kind === 'read' && scan.config.conlocaCloud === 'absent') {
70
+ return { outcome: skipped('CC9', INTEGRATION_NOT_CALLED) };
71
+ }
72
+ const outcome = outcomeOf('CC9');
73
+ const sitesPath = join(contentRoot, 'sites.json');
74
+ const fail = (message: string) => {
75
+ outcome.problems.push({ check: 'CC9', level: 'error', message, path: sitesPath });
76
+ return { outcome };
77
+ };
78
+ let sites: unknown;
79
+ try {
80
+ sites = JSON.parse(deps.readFile(sitesPath));
81
+ } catch {
82
+ return fail(`${sitesPath} is missing or not JSON — run conloca connect`);
83
+ }
84
+ if (!isSitesConfig(sites)) return fail(`${sitesPath} has no readable sites map`);
85
+ const name = addressSiteName(sites);
86
+ const site = name === null ? undefined : sites.sites[name];
87
+ if (name === null || site === undefined) {
88
+ return fail(
89
+ 'sites.json lists several sites and none is named default, so the editor cannot tell which one gives the address',
90
+ );
91
+ }
92
+ const locale = site.defaultLocale;
93
+ const host = site.domains?.[locale];
94
+ if (host === undefined) {
95
+ return fail(
96
+ `site "${name}" in sites.json has no domains.${locale} — run conloca connect, or add your site's host there`,
97
+ );
98
+ }
99
+ if (typeof host !== 'string' || !PLAIN_HOST.test(host)) {
100
+ return fail(`site "${name}" has domains.${locale} "${host}", which is not a bare host such as www.example.com`);
101
+ }
102
+ const refused = refusedHost(host);
103
+ if (refused !== undefined) {
104
+ return fail(
105
+ `site "${name}" has domains.${locale} "${host}", which is ${refused}: the editor never frames a page there — use your site's public host`,
106
+ );
107
+ }
108
+ const base = site.base ?? '/';
109
+ if (!isValidSiteBase(base)) return fail(`site "${name}" has base "${base}", which is not a path such as /docs/`);
110
+ const address = `https://${host}${base}`;
111
+ outcome.detail = address;
112
+
113
+ if (scan.kind === 'read') {
114
+ const { url, base: astroBase } = scan.config.site;
115
+ const warn = (message: string) =>
116
+ outcome.problems.push({ check: 'CC9', level: 'warn', message, path: scan.config.path });
117
+ const astroHost = typeof url === 'string' && URL.canParse(url) ? new URL(url).hostname : undefined;
118
+ if (astroHost !== undefined && astroHost !== host) {
119
+ warn(
120
+ `Astro's site is ${url} but sites.json gives the site "${name}" the host ${host}: the workspace editor opens ${address}${EDITOR_PAGE_PATH.slice(1)}. Make them match.`,
121
+ );
122
+ }
123
+ // An absent Astro base is `/`; a computed one is not judged.
124
+ const mismatch = astroBase === null ? undefined : baseMismatch(sites, astroBase ?? '/');
125
+ if (mismatch !== undefined) warn(mismatch);
126
+ }
127
+ return { outcome, address };
128
+ }
129
+
130
+ /** CC10 — a committed header rule that keeps the workspace editor from framing /_conloca/editor/, with the fix. */
131
+ export async function checkFramingHeaders(
132
+ scan: ConfigScan,
133
+ projectDir: string,
134
+ endpoint: string | undefined,
135
+ deps: Pick<DoctorDeps, 'exists'>,
136
+ ): Promise<CheckOutcome> {
137
+ if (scan.kind === 'read' && scan.config.conlocaCloud === 'absent') return skipped('CC10', INTEGRATION_NOT_CALLED);
138
+ const origin = editorUiOrigin(endpoint);
139
+ const editorRoot = origin === null ? null : parentRoot(origin);
140
+ if (editorRoot === null) return skipped('CC10', 'no editor UI origin');
141
+ const outcome = outcomeOf('CC10');
142
+ const snippets = framingSnippets(editorRoot);
143
+ // Netlify reads public/_headers too, but has no syntax for removing a header.
144
+ const headersRule = deps.exists(join(projectDir, 'netlify.toml'))
145
+ ? snippets.netlifyHeaders
146
+ : snippets.cloudflareHeaders;
147
+ for (const { file, header } of await findFramingBlockers(projectDir)) {
148
+ const snippet = file === 'vercel.json' ? JSON.stringify(snippets.vercelHeaders, null, 2) : headersRule;
149
+ // A second header cannot loosen a site-wide frame-ancestors, so connect never writes around that one.
150
+ const fix =
151
+ header === 'frame-ancestors' ? 'exclude /_conloca/editor/ from it, then add' : 'run conloca connect, or add';
152
+ outcome.problems.push({
153
+ check: 'CC10',
154
+ level: 'error',
155
+ message: `${file} sets ${header} for the whole site, so the workspace editor cannot frame /_conloca/editor/ — ${fix}:\n${snippet}`,
156
+ path: join(projectDir, file),
157
+ });
158
+ }
159
+ return outcome;
160
+ }
161
+
162
+ /** CC14 — each line of a tracked workflow or the astro config that still names the build key or one of its options. */
163
+ export function checkKeyLeftovers(scan: ConfigScan, projectDir: string, deps: DoctorDeps): CheckOutcome {
164
+ const outcome = outcomeOf('CC14');
165
+ // `:(top)` finds the repository's workflows from a project in a subfolder; git answers paths relative to projectDir.
166
+ const tracked = deps.git(['ls-files', '--', ':(top).github/workflows'], projectDir)?.split('\n') ?? [];
167
+ const paths = [
168
+ ...tracked.filter((path) => /\.ya?ml$/.test(path)).map((path) => join(projectDir, path)),
169
+ ...(scan.kind === 'read' ? [scan.config.path] : []),
170
+ ];
171
+ for (const path of paths) {
172
+ let text: string;
173
+ try {
174
+ text = deps.readFile(path);
175
+ } catch {
176
+ continue;
177
+ }
178
+ for (const [index, line] of text.split('\n').entries()) {
179
+ const names = [...new Set(line.match(LEFTOVER_RE))];
180
+ if (names.length === 0) continue;
181
+ outcome.problems.push({
182
+ check: 'CC14',
183
+ level: 'warn',
184
+ message: `${relative(projectDir, path)}:${index + 1} still names ${names.join(', ')}, left from the build key the editor page no longer needs — remove it`,
185
+ path,
186
+ });
187
+ }
188
+ }
189
+ return outcome;
190
+ }