@conloca/cloud-astro 0.2.2 → 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 (176) hide show
  1. package/README.md +261 -208
  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 -408
  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/_resolve-opts.d.ts +16 -10
  73. package/dist/src/preview/_resolve-opts.d.ts.map +1 -1
  74. package/dist/src/preview/_resolve-opts.js +21 -10
  75. package/dist/src/preview/_resolve-opts.js.map +1 -1
  76. package/dist/src/preview/banner.d.ts.map +1 -1
  77. package/dist/src/preview/banner.js +2 -4
  78. package/dist/src/preview/banner.js.map +1 -1
  79. package/dist/src/preview/cookie.d.ts +5 -2
  80. package/dist/src/preview/cookie.d.ts.map +1 -1
  81. package/dist/src/preview/cookie.js +5 -2
  82. package/dist/src/preview/cookie.js.map +1 -1
  83. package/dist/src/preview/label.d.ts +8 -0
  84. package/dist/src/preview/label.d.ts.map +1 -0
  85. package/dist/src/preview/label.js +14 -0
  86. package/dist/src/preview/label.js.map +1 -0
  87. package/dist/src/preview/landing.d.ts +2 -2
  88. package/dist/src/preview/landing.js +2 -2
  89. package/dist/src/preview/middleware.d.ts +25 -20
  90. package/dist/src/preview/middleware.d.ts.map +1 -1
  91. package/dist/src/preview/middleware.js +56 -51
  92. package/dist/src/preview/middleware.js.map +1 -1
  93. package/dist/src/preview/preview-path.d.ts +18 -5
  94. package/dist/src/preview/preview-path.d.ts.map +1 -1
  95. package/dist/src/preview/preview-path.js +24 -8
  96. package/dist/src/preview/preview-path.js.map +1 -1
  97. package/dist/src/preview/site-middleware.d.ts +5 -5
  98. package/dist/src/preview/site-middleware.d.ts.map +1 -1
  99. package/dist/src/preview/site-middleware.js +16 -16
  100. package/dist/src/preview/site-middleware.js.map +1 -1
  101. package/dist/src/preview-build.d.ts +18 -15
  102. package/dist/src/preview-build.d.ts.map +1 -1
  103. package/dist/src/preview-build.js +36 -21
  104. package/dist/src/preview-build.js.map +1 -1
  105. package/dist/src/preview.d.ts +1 -1
  106. package/dist/src/preview.d.ts.map +1 -1
  107. package/dist/src/preview.js +1 -1
  108. package/dist/src/preview.js.map +1 -1
  109. package/dist/src/repository.d.ts +1 -1
  110. package/dist/src/repository.js +1 -1
  111. package/dist/src/resolve-options.d.ts +17 -0
  112. package/dist/src/resolve-options.d.ts.map +1 -0
  113. package/dist/src/resolve-options.js +21 -0
  114. package/dist/src/resolve-options.js.map +1 -0
  115. package/dist/src/site-id.d.ts +0 -2
  116. package/dist/src/site-id.d.ts.map +1 -1
  117. package/dist/src/site-id.js +2 -3
  118. package/dist/src/site-id.js.map +1 -1
  119. package/dist/src/types.d.ts +21 -69
  120. package/dist/src/types.d.ts.map +1 -1
  121. package/package.json +37 -13
  122. package/src/component-manifest.ts +11 -8
  123. package/src/constants.ts +5 -14
  124. package/src/descriptors.ts +2 -2
  125. package/src/doctor/checks-address.ts +190 -0
  126. package/src/doctor/checks-live.ts +256 -268
  127. package/src/doctor/checks-offline.ts +24 -262
  128. package/src/doctor/config-scan.ts +21 -9
  129. package/src/doctor/run.ts +14 -16
  130. package/src/doctor/types.ts +7 -7
  131. package/src/editor-page/bundle.ts +482 -0
  132. package/src/editor-page/emit.ts +246 -0
  133. package/src/editor-page/framing.ts +62 -0
  134. package/src/editor-page/page.ts +37 -0
  135. package/src/editor-page/site-base.ts +11 -0
  136. package/src/git.ts +29 -10
  137. package/src/index.ts +20 -6
  138. package/src/integration.ts +255 -461
  139. package/src/node.ts +18 -2
  140. package/src/preview/_resolve-opts.ts +29 -11
  141. package/src/preview/banner.ts +2 -4
  142. package/src/preview/cookie.ts +5 -2
  143. package/src/preview/label.ts +12 -0
  144. package/src/preview/landing.ts +2 -2
  145. package/src/preview/middleware.ts +77 -66
  146. package/src/preview/preview-path.ts +26 -8
  147. package/src/preview/site-middleware.ts +16 -21
  148. package/src/preview-build.ts +42 -26
  149. package/src/preview-handler.astro +10 -8
  150. package/src/preview.ts +0 -1
  151. package/src/repository.ts +1 -1
  152. package/src/resolve-options.ts +37 -0
  153. package/src/site-id.ts +2 -4
  154. package/src/skill/SKILL.md +51 -55
  155. package/src/types.ts +21 -70
  156. package/src/virtual-modules.d.ts +4 -1
  157. package/dist/src/build-commit.d.ts +0 -19
  158. package/dist/src/build-commit.d.ts.map +0 -1
  159. package/dist/src/build-commit.js +0 -6
  160. package/dist/src/build-commit.js.map +0 -1
  161. package/dist/src/bundle.d.ts +0 -181
  162. package/dist/src/bundle.d.ts.map +0 -1
  163. package/dist/src/bundle.js +0 -413
  164. package/dist/src/bundle.js.map +0 -1
  165. package/dist/src/discovery.d.ts +0 -58
  166. package/dist/src/discovery.d.ts.map +0 -1
  167. package/dist/src/discovery.js +0 -133
  168. package/dist/src/discovery.js.map +0 -1
  169. package/dist/src/register.d.ts +0 -98
  170. package/dist/src/register.d.ts.map +0 -1
  171. package/dist/src/register.js +0 -103
  172. package/dist/src/register.js.map +0 -1
  173. package/src/build-commit.ts +0 -22
  174. package/src/bundle.ts +0 -570
  175. package/src/discovery.ts +0 -183
  176. package/src/register.ts +0 -180
@@ -1,53 +1,23 @@
1
- import { BUILD_TOKEN_ENV_VAR } from '../constants.js';
2
1
  import type { RepositoryEnvironment } from '../repository.js';
3
- import { type ConfigScan, hasOption, optionLiteral, previewBuildSetting, type ReadScan } from './config-scan.js';
2
+ import { type ConfigScan, hasOption, optionLiteral, previewBuildSetting } from './config-scan.js';
4
3
  import { type CheckOutcome, outcomeOf, skipped } from './types.js';
5
4
 
6
5
  /** Doctor-only override for an endpoint the config computes (e.g. from an env var). */
7
6
  export const ENDPOINT_ENV_VAR = 'CONLOCA_ENDPOINT';
8
7
 
9
- /** conlocaCMS options only the local dev editor consumes; `templates` reaches the endpoint's editor through the descriptors channel. */
10
- const INERT_AT_ENDPOINT = ['editorStyles', 'editorCSS'] as const;
11
-
12
- /**
13
- * Mirror of the build-token grammar the endpoint issues, duplicated here
14
- * rather than depending on the endpoint's own code from the site side.
15
- */
16
- const BUILD_TOKEN_RE = /^cbt_([A-Za-z0-9:_-]+)\.([A-Za-z0-9_-]{43})$/;
17
-
18
- const ABSOLUTE_URL_HINT = 'set it to an absolute URL such as https://cms.example.com';
19
- /** Why CC2, CC3 and the live trio skip when the integration is not wired. */
8
+ /** Why the address, framing and live checks skip when the integration is not wired. */
20
9
  export const INTEGRATION_NOT_CALLED = 'conlocaCloud(...) is not called in the astro config';
21
10
 
22
- function buildTokenOrgId(token: string): string | null {
23
- return BUILD_TOKEN_RE.exec(token)?.[1] ?? null;
24
- }
25
-
26
- /** The build token as supplied — env first, then the config literal. CC2 judges its shape; CC5 only asks whether one exists. */
27
- export function suppliedBuildToken(scan: ConfigScan, env: RepositoryEnvironment): string | undefined {
28
- return env[BUILD_TOKEN_ENV_VAR] || optionLiteral(scan, 'buildToken') || undefined;
29
- }
30
-
31
- /** The endpoint as supplied — config literal first, then CONLOCA_ENDPOINT. CC3 judges its shape; CC5 only asks whether one exists. */
11
+ /** The endpoint as supplied — config literal first, then CONLOCA_ENDPOINT; undefined means the default editor. */
32
12
  export function suppliedEndpoint(scan: ConfigScan, env: RepositoryEnvironment): string | undefined {
33
13
  return optionLiteral(scan, 'endpoint') || env[ENDPOINT_ENV_VAR] || undefined;
34
14
  }
35
15
 
36
- function isCi(env: RepositoryEnvironment): boolean {
37
- const value = env.CI;
38
- return value !== undefined && value !== '' && value !== '0' && value.toLowerCase() !== 'false';
39
- }
40
-
41
- function validUrl(value: string): URL | null {
42
- try {
43
- return new URL(value);
44
- } catch {
45
- return null;
46
- }
47
- }
48
-
49
- /** CC1 — three states for the conlocaCloud call, and the both-integrations rule for conlocaCMS. */
50
- export function checkWiring(scan: ConfigScan): CheckOutcome {
16
+ /**
17
+ * CC1 — three states for the conlocaCloud call, and the both-integrations rule for conlocaCMS. A wired call also notes
18
+ * that the deployed conloca.json names the repository (`repoUri`: what the build will write, when known).
19
+ */
20
+ export function checkWiring(scan: ConfigScan, repoUri: string | undefined): CheckOutcome {
51
21
  const outcome = outcomeOf('CC1');
52
22
  if (scan.kind === 'none') return skipped('CC1', 'no astro.config found');
53
23
  if (scan.kind === 'unreadable') {
@@ -69,234 +39,24 @@ export function checkWiring(scan: ConfigScan): CheckOutcome {
69
39
  path: scan.config.path,
70
40
  });
71
41
  }
72
- outcome.detail =
73
- conlocaCloud === 'absent'
74
- ? '@conloca/cloud-astro is installed but conlocaCloud(...) is not detectably called — fine when it is gated off or conditionally spread'
75
- : conlocaCloud === 'dynamic'
76
- ? 'conlocaCloud(...) is called with options doctor cannot read as a plain object literal'
77
- : 'conlocaCloud(...) is called';
78
- return outcome;
79
- }
80
-
81
- /**
82
- * CC2 — severity by context: under CI a missing token is an error, locally an
83
- * info. A token literal in the config is always a warning, even when the env
84
- * var also carries one: the committed secret is the finding.
85
- */
86
- export function checkBuildToken(
87
- scan: ConfigScan,
88
- env: RepositoryEnvironment,
89
- ): { outcome: CheckOutcome; token?: string } {
90
- // A project that installed the package but never wired it gets no CI error about a missing token (CC1 covers the state).
91
- if (scan.kind === 'read' && scan.config.conlocaCloud === 'absent')
92
- return { outcome: skipped('CC2', INTEGRATION_NOT_CALLED) };
93
- const outcome = outcomeOf('CC2');
94
- const fromConfig = optionLiteral(scan, 'buildToken');
95
- if (fromConfig !== undefined) {
96
- outcome.problems.push({
97
- check: 'CC2',
98
- level: 'warn',
99
- message: `buildToken is written into the astro config — move it to the ${BUILD_TOKEN_ENV_VAR} environment variable so the secret is never committed`,
100
- });
101
- }
102
- const token = suppliedBuildToken(scan, env);
103
- if (!token) {
104
- if (isCi(env)) {
105
- outcome.problems.push({
106
- check: 'CC2',
107
- level: 'error',
108
- message: `no build token — set the ${BUILD_TOKEN_ENV_VAR} secret in CI (the endpoint issues it); without it the build skips registration and the editor at the endpoint never updates`,
109
- });
110
- } else {
111
- outcome.detail = 'no build token — a CI secret, not expected locally';
112
- }
113
- return { outcome };
114
- }
115
- const orgId = buildTokenOrgId(token);
116
- if (orgId === null) {
117
- // The endpoint shows and copies the token as a whole `NAME=value` line; pasted as a secret's value, the token
118
- // inside it is fine, so a new one would not help.
119
- const assignment = `${BUILD_TOKEN_ENV_VAR}=`;
120
- outcome.problems.push({
121
- check: 'CC2',
122
- level: 'error',
123
- message: token.startsWith(assignment)
124
- ? `the build token value starts with "${assignment}" — the whole NAME=value line went into the value; store only the part after "=", which starts with cbt_`
125
- : 'the build token is malformed — expected cbt_<id>.<43-character secret>; create a new token at the endpoint',
126
- });
127
- return { outcome };
128
- }
129
- outcome.detail = `token for ${orgId}`;
130
- return { outcome, token };
131
- }
132
-
133
- /** The endpoint from the config literal or CONLOCA_ENDPOINT, once it parses as a URL; a non-https one is advisory. */
134
- function checkEndpoint(
135
- scan: ReadScan,
136
- env: RepositoryEnvironment,
137
- outcome: CheckOutcome,
138
- details: string[],
139
- ): string | undefined {
140
- const literal = optionLiteral(scan, 'endpoint');
141
- const fromEnv = env[ENDPOINT_ENV_VAR];
142
- let endpoint: string;
143
- if (literal !== undefined) {
144
- endpoint = literal;
145
- details.push(`endpoint ${literal}`);
146
- } else if (fromEnv) {
147
- endpoint = fromEnv;
148
- details.push(`endpoint ${fromEnv} (from ${ENDPOINT_ENV_VAR})`);
149
- } else {
150
- outcome.problems.push({
151
- check: 'CC3',
152
- level: 'warn',
153
- message:
154
- scan.config.conlocaCloud === 'dynamic'
155
- ? `conlocaCloud(...) options are not a plain object literal — set ${ENDPOINT_ENV_VAR} so doctor can read the endpoint (live checks need it)`
156
- : `endpoint is not a plain string literal in conlocaCloud(...) — set ${ENDPOINT_ENV_VAR} so doctor can read it (live checks need it)`,
157
- });
158
- return undefined;
159
- }
160
- const url = validUrl(endpoint);
161
- if (url === null) {
162
- outcome.problems.push({
163
- check: 'CC3',
164
- level: 'error',
165
- message: `endpoint "${endpoint}" is not a valid URL — ${ABSOLUTE_URL_HINT}`,
166
- });
167
- return undefined;
168
- }
169
- // register.ts joins `${endpoint}/api/v1/registrations` verbatim, so a trailing slash requests `//api/...`.
170
- if (endpoint.endsWith('/')) {
171
- outcome.problems.push({
172
- check: 'CC3',
173
- level: 'error',
174
- message: `endpoint "${endpoint}" must not end with a slash — the build joins /api/v1/registrations verbatim and the endpoint answers 404, which fails the build; remove the trailing slash`,
175
- });
176
- return undefined;
177
- }
178
- if (url.protocol !== 'https:') {
179
- outcome.problems.push({
180
- check: 'CC3',
181
- level: 'warn',
182
- message: `endpoint ${endpoint} is not https — fine for a local backend, wrong for production`,
183
- });
184
- }
185
- return endpoint;
186
- }
187
-
188
- /**
189
- * publicBaseUrl/previewDomain are validated when set. When neither is visible,
190
- * a missing one is a warning under CI only (CF_PAGES_URL may stand in) — and
191
- * only when the options are readable: dynamic or spread options may set it
192
- * where the text does not show, so doctor says "not verified" instead.
193
- */
194
- function checkPublicBaseUrl(
195
- scan: ReadScan,
196
- env: RepositoryEnvironment,
197
- outcome: CheckOutcome,
198
- details: string[],
199
- ): void {
200
- const publicBaseUrl = optionLiteral(scan, 'publicBaseUrl');
201
- const previewDomain = optionLiteral(scan, 'previewDomain');
202
- if (publicBaseUrl !== undefined && validUrl(publicBaseUrl) === null) {
203
- outcome.problems.push({
204
- check: 'CC3',
205
- level: 'error',
206
- message: `publicBaseUrl "${publicBaseUrl}" is not a valid URL — ${ABSOLUTE_URL_HINT}`,
207
- });
208
- }
209
- // Mirrors the integration's own resolveDeploymentUrl (a bare hostname is
210
- // prefixed with https://), so doctor accepts exactly what the build accepts.
211
- if (
212
- previewDomain !== undefined &&
213
- validUrl(previewDomain.includes('://') ? previewDomain : `https://${previewDomain}`) === null
214
- ) {
215
- outcome.problems.push({
216
- check: 'CC3',
217
- level: 'error',
218
- message: `previewDomain "${previewDomain}" is not a hostname or URL — set it to a hostname such as preview.acme.com or an absolute URL`,
219
- });
220
- }
221
- if (hasOption(scan, 'publicBaseUrl') || hasOption(scan, 'previewDomain')) {
222
- if (publicBaseUrl === undefined && previewDomain === undefined) {
223
- details.push('public base URL is set dynamically — not verified');
224
- }
225
- return;
226
- }
227
- // 'absent' cannot reach here (checkEndpoints skips it); the string test is the same guard optionLiteral uses.
228
- const { conlocaCloud } = scan.config;
229
- const opaque =
230
- typeof conlocaCloud === 'string'
231
- ? 'are not a plain object literal'
232
- : conlocaCloud.spread
233
- ? 'use a spread'
234
- : undefined;
235
- if (opaque !== undefined) {
236
- details.push(`public base URL not verified — the conlocaCloud options ${opaque}`);
237
- } else if (!isCi(env)) {
238
- details.push('publicBaseUrl not set (checked under CI only)');
239
- } else if (env.CF_PAGES_URL) {
240
- details.push(`public base URL from CF_PAGES_URL (${env.CF_PAGES_URL})`);
241
- } else {
242
- outcome.problems.push({
243
- check: 'CC3',
244
- level: 'warn',
245
- message:
246
- 'no public base URL under CI — set publicBaseUrl or previewDomain (or CF_PAGES_URL); without one the build skips registration',
247
- });
248
- }
249
- }
250
-
251
- /** CC3 — the endpoint and the public base URL, each in its own helper; skipped when there is nothing to read. */
252
- export function checkEndpoints(
253
- scan: ConfigScan,
254
- env: RepositoryEnvironment,
255
- ): { outcome: CheckOutcome; endpoint?: string } {
256
- if (scan.kind !== 'read') {
257
- return {
258
- outcome: skipped('CC3', scan.kind === 'none' ? 'no astro.config found' : 'astro config could not be read'),
259
- };
260
- }
261
- // CC1 already calls an absent call "fine when deliberate"; a missing endpoint must not contradict it in the same run.
262
- if (scan.config.conlocaCloud === 'absent') return { outcome: skipped('CC3', INTEGRATION_NOT_CALLED) };
263
- const outcome = outcomeOf('CC3');
264
- const details: string[] = [];
265
- const endpoint = checkEndpoint(scan, env, outcome, details);
266
- checkPublicBaseUrl(scan, env, outcome, details);
267
- if (details.length > 0) outcome.detail = details.join('; ');
268
- return { outcome, ...(endpoint === undefined ? {} : { endpoint }) };
269
- }
270
-
271
- /** CC4 — each option the endpoint's editor ignores, warned when set. */
272
- export function checkInertCmsOptions(scan: ConfigScan): CheckOutcome {
273
- const outcome = outcomeOf('CC4');
274
- if (scan.kind !== 'read') {
275
- return skipped('CC4', scan.kind === 'none' ? 'no astro.config found' : 'astro config could not be read');
276
- }
277
- const conlocaCMS = scan.config.conlocaCMS;
278
- if (conlocaCMS === 'absent') return skipped('CC4', 'conlocaCMS is not called in the astro config');
279
- if (conlocaCMS === 'dynamic') {
280
- outcome.detail = 'conlocaCMS options are not a plain object literal — editorStyles/editorCSS not checked';
42
+ if (conlocaCloud === 'absent') {
43
+ outcome.detail =
44
+ '@conloca/cloud-astro is installed but conlocaCloud(...) is not detectably called — fine when it is gated off or conditionally spread';
281
45
  return outcome;
282
46
  }
283
- for (const key of INERT_AT_ENDPOINT) {
284
- if (conlocaCMS.keys.has(key)) {
285
- outcome.problems.push({
286
- check: 'CC4',
287
- level: 'warn',
288
- message: `${key} has no effect on the editor at the endpoint — it styles the local dev editor only; the endpoint's editor takes its canvas styles from conlocaCloud's siteStyles`,
289
- path: scan.config.path,
290
- });
291
- }
292
- }
47
+ const call =
48
+ conlocaCloud === 'dynamic'
49
+ ? 'conlocaCloud(...) is called with options doctor cannot read as a plain object literal'
50
+ : 'conlocaCloud(...) is called';
51
+ const name = repoUri === undefined ? "the repository's name" : `the repository name ${repoUri}`;
52
+ outcome.detail = `${call}; /_conloca/editor/conloca.json publishes ${name} and the build branch; if the repository is not public, its name becomes public on deploy`;
293
53
  return outcome;
294
54
  }
295
55
 
296
56
  /**
297
- * CC8 — unless previewBuild is false, every build that registers also runs the preview build, which needs an SSR
298
- * adapter: the project's own or previewBuild.adapter. A static project with neither stays green until its first
299
- * registering build, which then fails. Only what the config text shows is judged.
57
+ * CC8 — only a previewBuild given as an object starts the preview build, which needs an SSR adapter: the project's own
58
+ * or previewBuild.adapter. A static project with neither fails astro build at config time. Only what the config text
59
+ * shows is judged.
300
60
  */
301
61
  export function checkPreviewBuildAdapter(scan: ConfigScan): CheckOutcome {
302
62
  if (scan.kind !== 'read') {
@@ -307,7 +67,9 @@ export function checkPreviewBuildAdapter(scan: ConfigScan): CheckOutcome {
307
67
  const previewBuild = previewBuildSetting(scan);
308
68
  const { output, adapter } = scan.config.site;
309
69
  if (previewBuild === 'off') {
310
- outcome.detail = 'previewBuild: false — no preview build runs';
70
+ outcome.detail = hasOption(scan, 'previewBuild')
71
+ ? 'previewBuild: false — no preview build runs'
72
+ : 'previewBuild is not set — no preview build runs';
311
73
  } else if (previewBuild === 'adapter' || adapter) {
312
74
  outcome.detail = 'the preview build has an SSR adapter';
313
75
  } else if (previewBuild === 'unknown' || output !== 'static') {
@@ -317,7 +79,7 @@ export function checkPreviewBuildAdapter(scan: ConfigScan): CheckOutcome {
317
79
  check: 'CC8',
318
80
  level: 'error',
319
81
  message:
320
- 'previewBuild is on, but the project is static and has no SSR adapter, so every build that registers fails when it runs the preview build — set previewBuild: false in conlocaCloud(...)',
82
+ 'previewBuild is set, but the project is static and has no SSR adapter, so astro build fails at config time — add one (previewBuild: { adapter }) or remove previewBuild from conlocaCloud(...)',
321
83
  path: scan.config.path,
322
84
  });
323
85
  }
@@ -129,6 +129,9 @@ function callArgs(configText: string, name: string): CallArgs {
129
129
  interface SiteSettings {
130
130
  output: 'static' | 'server' | 'unknown';
131
131
  adapter: boolean;
132
+ /** Astro's `site` and `base` as plain string literals: undefined when absent, null when computed or spread in. */
133
+ url: string | null | undefined;
134
+ base: string | null | undefined;
132
135
  }
133
136
 
134
137
  interface ScannedConfig {
@@ -138,15 +141,24 @@ interface ScannedConfig {
138
141
  site: SiteSettings;
139
142
  }
140
143
 
141
- /** Astro's output and adapter, read without conlocaCloud's options: their previewBuild.adapter is not the site's. */
144
+ /** Astro's own settings, read without conlocaCloud's options: their previewBuild.adapter is not the site's. */
142
145
  function siteSettings(configText: string, conlocaCloud: CallArgs): SiteSettings {
143
146
  const text = typeof conlocaCloud === 'string' ? configText : configText.replace(conlocaCloud.text, '');
144
147
  const adapter = containsOutsideStrings(text, 'adapter');
145
- if (containsOutsideStrings(text, '...')) return { output: 'unknown', adapter };
148
+ const spread = containsOutsideStrings(text, '...');
149
+ // shortcut: the first `site:`/`base:` outside conlocaCloud's options counts, so a nested `vite: { base }` would read
150
+ // as Astro's; parse the top-level object if a real config trips it.
151
+ const setting = (key: string) => {
152
+ const match = new RegExp(`\\b${key}\\s*:\\s*(?:'([^'\\\\]*)'|"([^"\\\\]*)")?`).exec(text);
153
+ if (match === null) return spread ? null : undefined;
154
+ return match[1] ?? match[2] ?? null;
155
+ };
156
+ const strings = { url: setting('site'), base: setting('base') };
157
+ if (spread) return { output: 'unknown', adapter, ...strings };
146
158
  const key = /\boutput\s*:/.exec(text);
147
- if (key === null) return { output: 'static', adapter };
159
+ if (key === null) return { output: 'static', adapter, ...strings };
148
160
  const value = /^(['"])(static|server)\1/.exec(text.slice(key.index + key[0].length).trimStart())?.[2];
149
- return { output: value === 'static' || value === 'server' ? value : 'unknown', adapter };
161
+ return { output: value === 'static' || value === 'server' ? value : 'unknown', adapter, ...strings };
150
162
  }
151
163
 
152
164
  export type ConfigScan =
@@ -190,16 +202,16 @@ export function hasOption(scan: ConfigScan, key: string): boolean {
190
202
  }
191
203
 
192
204
  /**
193
- * conlocaCloud's previewBuild as the text shows it: 'off' when written as false, 'adapter' when the options name an
194
- * adapter (previewBuild.adapter, written out or as shorthand), 'on' when absent or an options object without one,
195
- * and 'unknown' when computed or when a spread could set it.
205
+ * conlocaCloud's previewBuild as the text shows it: 'off' when absent or written as false (the preview build is
206
+ * opt-in), 'adapter' when the options name an adapter (previewBuild.adapter, written out or as shorthand), 'on' for
207
+ * an options object without one, and 'unknown' when computed or when a spread could set it.
196
208
  */
197
209
  export function previewBuildSetting(scan: ConfigScan): 'off' | 'adapter' | 'on' | 'unknown' {
198
210
  if (scan.kind !== 'read' || typeof scan.config.conlocaCloud === 'string') return 'unknown';
199
211
  const { text, spread } = scan.config.conlocaCloud;
200
212
  const value = /\bpreviewBuild\s*:\s*(false\b|\{)?/.exec(text);
201
- if (value?.[1] === 'false') return 'off';
213
+ if (value === null) return spread || containsOutsideStrings(text, 'previewBuild') ? 'unknown' : 'off';
214
+ if (value[1] === 'false') return 'off';
202
215
  if (containsOutsideStrings(text, 'adapter')) return 'adapter';
203
- if (value === null) return spread || containsOutsideStrings(text, 'previewBuild') ? 'unknown' : 'on';
204
216
  return value[1] === '{' ? 'on' : 'unknown';
205
217
  }
package/src/doctor/run.ts CHANGED
@@ -1,14 +1,9 @@
1
1
  import { existsSync, readFileSync } from 'node:fs';
2
- import { gitOutput } from '../git.js';
2
+ import { gitOutput, resolveRepositoryUri } from '../git.js';
3
+ import { checkFramingHeaders, checkKeyLeftovers, checkSiteAddress } from './checks-address.js';
3
4
  import { runLiveChecks } from './checks-live.js';
4
- import {
5
- checkBuildToken,
6
- checkEndpoints,
7
- checkInertCmsOptions,
8
- checkPreviewBuildAdapter,
9
- checkWiring,
10
- } from './checks-offline.js';
11
- import { scanAstroConfig } from './config-scan.js';
5
+ import { checkPreviewBuildAdapter, checkWiring, suppliedEndpoint } from './checks-offline.js';
6
+ import { optionLiteral, scanAstroConfig } from './config-scan.js';
12
7
  import type { CloudDoctorContext, CloudDoctorResult, DoctorDeps } from './types.js';
13
8
 
14
9
  /** The doctor extension: offline checks always, live ones only under --live. Every side effect rides `deps`. */
@@ -25,15 +20,18 @@ export async function runDoctor(
25
20
  ...overrides,
26
21
  };
27
22
  const scan = scanAstroConfig(context.projectDir, deps);
28
- const token = checkBuildToken(scan, deps.env);
29
- const endpoints = checkEndpoints(scan, deps.env);
23
+ // The doctor diagnoses the project it was handed, not whatever checkout the CLI happens to be standing in.
24
+ const repoUri = resolveRepositoryUri(optionLiteral(scan, 'repoUri'), deps.env, (args) =>
25
+ deps.git(args, context.projectDir),
26
+ );
27
+ const site = checkSiteAddress(scan, context.contentRoot, deps);
30
28
  const checks = [
31
- checkWiring(scan),
32
- token.outcome,
33
- endpoints.outcome,
34
- checkInertCmsOptions(scan),
35
- ...(await runLiveChecks({ context, deps, scan, token: token.token, endpoint: endpoints.endpoint })),
29
+ checkWiring(scan, repoUri),
30
+ site.outcome,
31
+ await checkFramingHeaders(scan, context.projectDir, suppliedEndpoint(scan, deps.env), deps),
32
+ checkKeyLeftovers(scan, context.projectDir, deps),
36
33
  checkPreviewBuildAdapter(scan),
34
+ ...(await runLiveChecks({ context, deps, scan, address: site.address, repoUri })),
37
35
  ];
38
36
  return { contractVersion: 1, checks };
39
37
  }
@@ -50,13 +50,13 @@ export interface DoctorDeps {
50
50
  /** Insertion order is the report order. */
51
51
  const CHECK_LABELS = {
52
52
  CC1: 'conlocaCloud is wired next to conlocaCMS',
53
- CC2: 'build token is available and well-formed',
54
- CC3: 'endpoint and public base URL are usable',
55
- CC4: "conlocaCMS options the endpoint's editor ignores",
56
- CC5: 'the endpoint answers the build token',
57
- CC6: 'a registration serves this branch and site',
58
- CC7: 'the registered editor assets are still deployed',
59
- CC8: 'the preview build has an SSR adapter, or is off',
53
+ CC9: 'the site domain is declared in sites.json',
54
+ CC10: 'committed headers allow framing the editor page',
55
+ CC14: 'no build key leftovers',
56
+ CC8: 'the preview build, when previewBuild is set, has an SSR adapter',
57
+ CC11: 'the deployed editor page answers',
58
+ CC12: 'the deployed editor page may be framed',
59
+ CC13: "the editor speaks this page's protocol",
60
60
  } as const;
61
61
 
62
62
  /** A typo in a check id fails tsc here; the CLI would otherwise drop a label-less outcome silently. */