@conloca/cloud-astro 0.2.5 → 0.3.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 (226) hide show
  1. package/README.md +75 -24
  2. package/dist/.build-inputs.json +47 -29
  3. package/dist/src/component-manifest.d.ts +11 -0
  4. package/dist/src/component-manifest.d.ts.map +1 -1
  5. package/dist/src/component-manifest.js +20 -2
  6. package/dist/src/component-manifest.js.map +1 -1
  7. package/dist/src/constants.d.ts +4 -4
  8. package/dist/src/constants.js +4 -4
  9. package/dist/src/d3-build.d.ts +6 -2
  10. package/dist/src/d3-build.d.ts.map +1 -1
  11. package/dist/src/d3-build.js +15 -11
  12. package/dist/src/d3-build.js.map +1 -1
  13. package/dist/src/d8-adapters.d.ts +10 -0
  14. package/dist/src/d8-adapters.d.ts.map +1 -0
  15. package/dist/src/d8-adapters.js +19 -0
  16. package/dist/src/d8-adapters.js.map +1 -0
  17. package/dist/src/d8-build.d.ts +99 -0
  18. package/dist/src/d8-build.d.ts.map +1 -0
  19. package/dist/src/d8-build.js +265 -0
  20. package/dist/src/d8-build.js.map +1 -0
  21. package/dist/src/d8-guards.d.ts +29 -0
  22. package/dist/src/d8-guards.d.ts.map +1 -0
  23. package/dist/src/d8-guards.js +145 -0
  24. package/dist/src/d8-guards.js.map +1 -0
  25. package/dist/src/d8-middleware.d.ts +7 -0
  26. package/dist/src/d8-middleware.d.ts.map +1 -0
  27. package/dist/src/d8-middleware.js +15 -0
  28. package/dist/src/d8-middleware.js.map +1 -0
  29. package/dist/src/d8-render.d.ts +9 -0
  30. package/dist/src/d8-render.d.ts.map +1 -0
  31. package/dist/src/d8-render.js +52 -0
  32. package/dist/src/d8-render.js.map +1 -0
  33. package/dist/src/descriptors.d.ts.map +1 -1
  34. package/dist/src/descriptors.js +6 -2
  35. package/dist/src/descriptors.js.map +1 -1
  36. package/dist/src/doctor/ancestor-chain.d.ts +14 -0
  37. package/dist/src/doctor/ancestor-chain.d.ts.map +1 -0
  38. package/dist/src/doctor/ancestor-chain.js +57 -0
  39. package/dist/src/doctor/ancestor-chain.js.map +1 -0
  40. package/dist/src/doctor/checks-d8.d.ts +7 -0
  41. package/dist/src/doctor/checks-d8.d.ts.map +1 -0
  42. package/dist/src/doctor/checks-d8.js +240 -0
  43. package/dist/src/doctor/checks-d8.js.map +1 -0
  44. package/dist/src/doctor/checks-frames.d.ts +5 -0
  45. package/dist/src/doctor/checks-frames.d.ts.map +1 -0
  46. package/dist/src/doctor/checks-frames.js +78 -0
  47. package/dist/src/doctor/checks-frames.js.map +1 -0
  48. package/dist/src/doctor/checks-live.d.ts +5 -14
  49. package/dist/src/doctor/checks-live.d.ts.map +1 -1
  50. package/dist/src/doctor/checks-live.js +9 -21
  51. package/dist/src/doctor/checks-live.js.map +1 -1
  52. package/dist/src/doctor/checks-offline.d.ts +2 -0
  53. package/dist/src/doctor/checks-offline.d.ts.map +1 -1
  54. package/dist/src/doctor/checks-offline.js +17 -8
  55. package/dist/src/doctor/checks-offline.js.map +1 -1
  56. package/dist/src/doctor/checks-preview-live.d.ts +7 -2
  57. package/dist/src/doctor/checks-preview-live.d.ts.map +1 -1
  58. package/dist/src/doctor/checks-preview-live.js +107 -7
  59. package/dist/src/doctor/checks-preview-live.js.map +1 -1
  60. package/dist/src/doctor/checks-preview.d.ts.map +1 -1
  61. package/dist/src/doctor/checks-preview.js +9 -4
  62. package/dist/src/doctor/checks-preview.js.map +1 -1
  63. package/dist/src/doctor/config-scan.d.ts +24 -6
  64. package/dist/src/doctor/config-scan.d.ts.map +1 -1
  65. package/dist/src/doctor/config-scan.js +89 -18
  66. package/dist/src/doctor/config-scan.js.map +1 -1
  67. package/dist/src/doctor/request.d.ts +14 -0
  68. package/dist/src/doctor/request.d.ts.map +1 -0
  69. package/dist/src/doctor/request.js +17 -0
  70. package/dist/src/doctor/request.js.map +1 -0
  71. package/dist/src/doctor/run.d.ts.map +1 -1
  72. package/dist/src/doctor/run.js +2 -0
  73. package/dist/src/doctor/run.js.map +1 -1
  74. package/dist/src/doctor/types.d.ts +8 -0
  75. package/dist/src/doctor/types.d.ts.map +1 -1
  76. package/dist/src/doctor/types.js +8 -0
  77. package/dist/src/doctor/types.js.map +1 -1
  78. package/dist/src/editor-page/bundle.d.ts +4 -0
  79. package/dist/src/editor-page/bundle.d.ts.map +1 -1
  80. package/dist/src/editor-page/bundle.js +55 -7
  81. package/dist/src/editor-page/bundle.js.map +1 -1
  82. package/dist/src/editor-page/data-schemas.d.ts +19 -5
  83. package/dist/src/editor-page/data-schemas.d.ts.map +1 -1
  84. package/dist/src/editor-page/data-schemas.js +17 -13
  85. package/dist/src/editor-page/data-schemas.js.map +1 -1
  86. package/dist/src/editor-page/emit.d.ts +7 -3
  87. package/dist/src/editor-page/emit.d.ts.map +1 -1
  88. package/dist/src/editor-page/emit.js +36 -19
  89. package/dist/src/editor-page/emit.js.map +1 -1
  90. package/dist/src/editor-page/frame-chains.d.ts +51 -0
  91. package/dist/src/editor-page/frame-chains.d.ts.map +1 -0
  92. package/dist/src/editor-page/frame-chains.js +121 -0
  93. package/dist/src/editor-page/frame-chains.js.map +1 -0
  94. package/dist/src/editor-page/page.d.ts +1 -3
  95. package/dist/src/editor-page/page.d.ts.map +1 -1
  96. package/dist/src/editor-page/page.js +3 -5
  97. package/dist/src/editor-page/page.js.map +1 -1
  98. package/dist/src/integration.d.ts.map +1 -1
  99. package/dist/src/integration.js +231 -124
  100. package/dist/src/integration.js.map +1 -1
  101. package/dist/src/node.d.ts +2 -0
  102. package/dist/src/node.d.ts.map +1 -1
  103. package/dist/src/node.js +4 -0
  104. package/dist/src/node.js.map +1 -1
  105. package/dist/src/preview/_resolve-opts.d.ts +26 -1
  106. package/dist/src/preview/_resolve-opts.d.ts.map +1 -1
  107. package/dist/src/preview/_resolve-opts.js.map +1 -1
  108. package/dist/src/preview/banner.d.ts +3 -2
  109. package/dist/src/preview/banner.d.ts.map +1 -1
  110. package/dist/src/preview/banner.js +15 -6
  111. package/dist/src/preview/banner.js.map +1 -1
  112. package/dist/src/preview/content-api.d.ts +23 -1
  113. package/dist/src/preview/content-api.d.ts.map +1 -1
  114. package/dist/src/preview/content-api.js +73 -7
  115. package/dist/src/preview/content-api.js.map +1 -1
  116. package/dist/src/preview/d8-middleware.d.ts +25 -0
  117. package/dist/src/preview/d8-middleware.d.ts.map +1 -0
  118. package/dist/src/preview/d8-middleware.js +94 -0
  119. package/dist/src/preview/d8-middleware.js.map +1 -0
  120. package/dist/src/preview/dispatcher.d.ts +3 -16
  121. package/dist/src/preview/dispatcher.d.ts.map +1 -1
  122. package/dist/src/preview/dispatcher.js +54 -136
  123. package/dist/src/preview/dispatcher.js.map +1 -1
  124. package/dist/src/preview/headers.d.ts +3 -0
  125. package/dist/src/preview/headers.d.ts.map +1 -1
  126. package/dist/src/preview/headers.js +10 -1
  127. package/dist/src/preview/headers.js.map +1 -1
  128. package/dist/src/preview/links.d.ts +23 -0
  129. package/dist/src/preview/links.d.ts.map +1 -0
  130. package/dist/src/preview/links.js +168 -0
  131. package/dist/src/preview/links.js.map +1 -0
  132. package/dist/src/preview/middleware.d.ts +9 -3
  133. package/dist/src/preview/middleware.d.ts.map +1 -1
  134. package/dist/src/preview/middleware.js +36 -16
  135. package/dist/src/preview/middleware.js.map +1 -1
  136. package/dist/src/preview/prefix-router.d.ts +67 -0
  137. package/dist/src/preview/prefix-router.d.ts.map +1 -0
  138. package/dist/src/preview/prefix-router.js +153 -0
  139. package/dist/src/preview/prefix-router.js.map +1 -0
  140. package/dist/src/preview/preview-path.d.ts +8 -3
  141. package/dist/src/preview/preview-path.d.ts.map +1 -1
  142. package/dist/src/preview/preview-path.js +16 -4
  143. package/dist/src/preview/preview-path.js.map +1 -1
  144. package/dist/src/preview/site-middleware.d.ts +8 -2
  145. package/dist/src/preview/site-middleware.d.ts.map +1 -1
  146. package/dist/src/preview/site-middleware.js +95 -31
  147. package/dist/src/preview/site-middleware.js.map +1 -1
  148. package/dist/src/preview/site-page-sources.d.ts +21 -0
  149. package/dist/src/preview/site-page-sources.d.ts.map +1 -0
  150. package/dist/src/preview/site-page-sources.js +129 -0
  151. package/dist/src/preview/site-page-sources.js.map +1 -0
  152. package/dist/src/preview/site-pages.d.ts +18 -0
  153. package/dist/src/preview/site-pages.d.ts.map +1 -0
  154. package/dist/src/preview/site-pages.js +7 -0
  155. package/dist/src/preview/site-pages.js.map +1 -0
  156. package/dist/src/preview/unready-pages.d.ts +21 -0
  157. package/dist/src/preview/unready-pages.d.ts.map +1 -0
  158. package/dist/src/preview/unready-pages.js +54 -0
  159. package/dist/src/preview/unready-pages.js.map +1 -0
  160. package/dist/src/preview-build.d.ts +17 -16
  161. package/dist/src/preview-build.d.ts.map +1 -1
  162. package/dist/src/preview-build.js +37 -40
  163. package/dist/src/preview-build.js.map +1 -1
  164. package/dist/src/preview-image-endpoint.d.ts +8 -0
  165. package/dist/src/preview-image-endpoint.d.ts.map +1 -0
  166. package/dist/src/preview-image-endpoint.js +34 -0
  167. package/dist/src/preview-image-endpoint.js.map +1 -0
  168. package/dist/src/preview-render-seams.d.ts +7 -0
  169. package/dist/src/preview-render-seams.d.ts.map +1 -0
  170. package/dist/src/preview-render-seams.js +27 -0
  171. package/dist/src/preview-render-seams.js.map +1 -0
  172. package/dist/src/site-middleware.d.ts +2 -4
  173. package/dist/src/site-middleware.d.ts.map +1 -1
  174. package/dist/src/site-middleware.js +6 -22
  175. package/dist/src/site-middleware.js.map +1 -1
  176. package/dist/src/types.d.ts +15 -16
  177. package/dist/src/types.d.ts.map +1 -1
  178. package/package.json +138 -6
  179. package/src/component-manifest.ts +30 -4
  180. package/src/constants.ts +4 -4
  181. package/src/d3-build.ts +20 -14
  182. package/src/d8-adapters.ts +19 -0
  183. package/src/d8-build.ts +356 -0
  184. package/src/d8-guards.ts +177 -0
  185. package/src/d8-middleware.ts +17 -0
  186. package/src/d8-render.ts +61 -0
  187. package/src/descriptors.ts +6 -2
  188. package/src/doctor/ancestor-chain.ts +58 -0
  189. package/src/doctor/checks-d8.ts +256 -0
  190. package/src/doctor/checks-frames.ts +84 -0
  191. package/src/doctor/checks-live.ts +10 -39
  192. package/src/doctor/checks-offline.ts +21 -8
  193. package/src/doctor/checks-preview-live.ts +114 -8
  194. package/src/doctor/checks-preview.ts +9 -4
  195. package/src/doctor/config-scan.ts +86 -15
  196. package/src/doctor/request.ts +27 -0
  197. package/src/doctor/run.ts +2 -0
  198. package/src/doctor/types.ts +9 -0
  199. package/src/editor-page/bundle.ts +65 -7
  200. package/src/editor-page/data-schemas.ts +30 -16
  201. package/src/editor-page/emit.ts +52 -24
  202. package/src/editor-page/frame-chains.ts +143 -0
  203. package/src/editor-page/page.ts +3 -4
  204. package/src/integration.ts +277 -135
  205. package/src/node.ts +4 -0
  206. package/src/preview/_resolve-opts.ts +17 -1
  207. package/src/preview/banner.ts +17 -4
  208. package/src/preview/content-api.ts +78 -6
  209. package/src/preview/d8-middleware.ts +124 -0
  210. package/src/preview/dispatcher.ts +63 -153
  211. package/src/preview/headers.ts +10 -1
  212. package/src/preview/links.ts +175 -0
  213. package/src/preview/middleware.ts +41 -19
  214. package/src/preview/prefix-router.ts +197 -0
  215. package/src/preview/preview-path.ts +24 -6
  216. package/src/preview/site-middleware.ts +114 -38
  217. package/src/preview/site-page-sources.ts +146 -0
  218. package/src/preview/site-pages.ts +22 -0
  219. package/src/preview/unready-pages.ts +65 -0
  220. package/src/preview-build.ts +43 -42
  221. package/src/preview-image-endpoint.ts +35 -0
  222. package/src/preview-render-seams.ts +31 -0
  223. package/src/site-middleware.ts +6 -24
  224. package/src/skill/SKILL.md +25 -2
  225. package/src/types.ts +15 -16
  226. package/src/virtual-modules.d.ts +17 -2
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The image endpoint a d8 draft page uses, at `<base>_conloca/preview/_image` on Vercel, Netlify and Node: it answers
3
+ * with a redirect to the original image, so drafts get untransformed images and the site's own `/_image` stays as it
4
+ * was. It never fetches: only a same-origin path or a host the site's `image` config allows is redirected to.
5
+ */
6
+
7
+ import { imageConfig } from 'astro:assets';
8
+ import type { APIContext, APIRoute } from 'astro';
9
+ import { isRemoteAllowed } from 'astro/assets/utils';
10
+ import { applyPreviewHeaders } from './preview/headers.js';
11
+
12
+ export const GET = (({ url }: Pick<APIContext, 'url'>) => {
13
+ const href = url.searchParams.get('href') ?? '';
14
+ const target = URL.canParse(href, url.href) ? new URL(href, url) : null;
15
+ // `//host` and `/\host` resolve off-origin, so the origin check catches them; decoded, `%5Fimage` is our own route.
16
+ const local =
17
+ href.startsWith('/') && target?.origin === url.origin && safeDecode(target.pathname) !== safeDecode(url.pathname);
18
+ const remote = /^https?:\/\//iu.test(href) && isRemoteAllowed(href, imageConfig);
19
+ try {
20
+ // The Location comes from the parsed URL, so no raw input reaches the header.
21
+ const location = local ? `${target.pathname}${target.search}` : remote && target ? target.href : null;
22
+ if (location !== null) return applyPreviewHeaders(new Response(null, { status: 302, headers: { location } }));
23
+ } catch {
24
+ // An invalid header value: refused below.
25
+ }
26
+ return applyPreviewHeaders(new Response(null, { status: 403 }));
27
+ }) satisfies APIRoute;
28
+
29
+ function safeDecode(path: string): string | null {
30
+ try {
31
+ return decodeURIComponent(path);
32
+ } catch {
33
+ return null;
34
+ }
35
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The render seams a preview render takes from the site's own build graph: `astro:content` and the routing-config
3
+ * virtual module only resolve there, so the D2/D3 site middleware and the d8 render both build them here.
4
+ */
5
+
6
+ import { getCollection } from 'astro:content';
7
+ import routingConfig from 'virtual:conloca-routing-config';
8
+ import { createCollectionBackedContentAPI } from '@conloca/astro-cms';
9
+ import type { ContentAPI } from '@conloca/content-api';
10
+ import { resolveEndpointFetch } from './preview/_resolve-opts.js';
11
+ import type { PreviewRenderSeams } from './preview/site-middleware.js';
12
+
13
+ // One baseline per process: the built collections are immutable at runtime,
14
+ // and constructing the collection-backed reader walks every collection.
15
+ let baselinePromise: Promise<ContentAPI> | undefined;
16
+ function baselineApi(): Promise<ContentAPI> {
17
+ baselinePromise ??= createCollectionBackedContentAPI({
18
+ getCollection: (name) => getCollection(name),
19
+ routing: routingConfig,
20
+ });
21
+ return baselinePromise;
22
+ }
23
+
24
+ export async function previewRenderSeams(): Promise<PreviewRenderSeams> {
25
+ return {
26
+ baselineApi,
27
+ site: routingConfig.siteName,
28
+ locale: routingConfig.locale,
29
+ fetchFn: await resolveEndpointFetch(),
30
+ };
31
+ }
@@ -5,27 +5,22 @@
5
5
  * the integration resolves to this module, so it must export `onRequest` —
6
6
  * Astro's middleware contract. The verdict/render logic lives in
7
7
  * `./preview/site-middleware.ts`, which is env-free and unit-testable; this
8
- * file binds it to the runtime env resolution and to the site's own build
9
- * graph: `astro:content` and the routing-config virtual module only resolve
10
- * here, so the collection-backed baseline is constructed here and injected as
11
- * a seam.
8
+ * file binds it to the runtime env resolution and to the render seams built
9
+ * from the site's own build graph (`./preview-render-seams.ts`).
12
10
  *
13
11
  * Mounted ONLY inside the preview build (see `integration.ts`), never in the
14
12
  * site's production build.
15
13
  */
16
14
 
17
- import { getCollection } from 'astro:content';
18
15
  import baked from 'virtual:conloca-preview-opts';
19
- import routingConfig from 'virtual:conloca-routing-config';
20
- import { createCollectionBackedContentAPI } from '@conloca/astro-cms';
21
- import type { ContentAPI } from '@conloca/content-api';
22
- import { resolveEndpointFetch, resolveFromBaked } from './preview/_resolve-opts.js';
16
+ import { resolveFromBaked } from './preview/_resolve-opts.js';
23
17
  import {
24
18
  createPreviewSiteMiddleware,
25
19
  type PreviewMiddlewareContext,
26
20
  type PreviewMiddlewareNext,
27
21
  } from './preview/site-middleware.js';
28
22
  import { untagWorkerdProcess } from './preview/workerd-shim.js';
23
+ import { previewRenderSeams } from './preview-render-seams.js';
29
24
 
30
25
  // At Cloudflare Worker start-up, before any render: workerd's nodejs_compat
31
26
  // process can masquerade as Node's, sending Astro down a streaming branch whose
@@ -33,23 +28,10 @@ import { untagWorkerdProcess } from './preview/workerd-shim.js';
33
28
  // literal string "[object Object]". See the shim's doc for the full chain.
34
29
  untagWorkerdProcess();
35
30
 
36
- // One baseline per process: the built collections are immutable at runtime,
37
- // and constructing the collection-backed reader walks every collection.
38
- let baselinePromise: Promise<ContentAPI> | undefined;
39
- function baselineApi(): Promise<ContentAPI> {
40
- baselinePromise ??= createCollectionBackedContentAPI({
41
- getCollection: (name) => getCollection(name),
42
- routing: routingConfig,
43
- });
44
- return baselinePromise;
45
- }
46
-
47
31
  export async function onRequest(context: PreviewMiddlewareContext, next: PreviewMiddlewareNext): Promise<Response> {
48
32
  const handler = createPreviewSiteMiddleware(() => resolveFromBaked(baked, (name) => process.env[name]), {
49
- baselineApi,
50
- site: routingConfig.siteName,
51
- locale: routingConfig.locale,
52
- fetchFn: await resolveEndpointFetch(),
33
+ ...(await previewRenderSeams()),
34
+ baked,
53
35
  });
54
36
  return handler(context, next);
55
37
  }
@@ -36,7 +36,7 @@ conloca doctor --live # sends no credential: only your site's host and the e
36
36
  conloca doctor # offline: wiring, sites.json host, committed framing headers, key leftovers
37
37
  ```
38
38
 
39
- This package's checks are `CC1` and `CC8`–`CC24`:
39
+ This package's checks are `CC1` and `CC8`–`CC30`:
40
40
 
41
41
  - **CC9** — `sites.json`: the site named `default` (or the only one) has a bare host in `domains[defaultLocale]` and a
42
42
  valid `base`. The editor opens `https://<host><base>_conloca/editor/`; it refuses IPs, `localhost`, `*.conloca.com`.
@@ -59,12 +59,35 @@ This package's checks are `CC1` and `CC8`–`CC24`:
59
59
  `connect --yes --cf-plan paid` (or `free`). On Free with API routes, CC23 warns that previews and those routes share
60
60
  one daily request quota; Cloudflare Workers Paid removes the limit.
61
61
  - **CC24** (live) — a separate preview deploy's `conloca.json` answers as D4.
62
+ - **CC25–CC28** — draft previews in the site's own build (d8): one of the four official adapters, in the tested release
63
+ range, on an astro at or above its floor; nothing that turns preview off (`isr` without the preview route excluded,
64
+ edge middleware, `previewBuild.adapter`, `separate: true` under Vercel or Netlify); the host's routing (Vercel
65
+ `build.format: 'file'`, `site` on Vercel and Netlify, a static Cloudflare site's `run_worker_first` and `"404-page"`);
66
+ `security.allowedDomains` on `@astrojs/node`. Fix: `npx @conloca/cli connect` (adds the adapter and its options).
67
+ - **CC29** (live) — `<host><base>_conloca/preview/__exit` answers 302, uncached, as the configured mode. A failure names
68
+ where the host keeps logs; a 401/403/429 means something in front of the site blocks `/_conloca/preview/*`.
69
+ - **CC30** (live) — a routing entry with an `editorFrame`: for each route in `_conloca/editor/frames.json`, the
70
+ published page wraps its `data-conloca-page-root` element in the same elements and classes the frame renders. The
71
+ canvas renders fragments inline inside that frame, so a drift shows the editor's prose in a different wrapper than the
72
+ page. Fix: change the frame or the layout so both wrap the page root alike. Only warns.
73
+
74
+ ## Draft previews in the site's own build (d8)
75
+
76
+ - Updating `@conloca/cloud-astro` switches a D2 site (preview from its own server) and an `@astrojs/cloudflare`
77
+ server-rendered site to d8 on the next build. Run `npx @conloca/cli upgrade` for the edits: the start command moves to
78
+ `node dist/server/entry.mjs`, and the `previewBuild` options d8 ignores go.
79
+ - Read `Astro.locals.contentApi` inside each request. Never cache it, or anything read from it, at module level: on a
80
+ server-rendered site drafts and published pages share one warm function.
81
+ - A static Vercel site adds a `src/pages/404` page, or every miss runs the preview function.
82
+ - Vercel and Netlify sites set `site` in `astro.config` so their own pages stay inside the preview. `site` also changes
83
+ canonical, sitemap, RSS and Open Graph URLs on the live pages: ask the site owner first.
62
84
 
63
85
  ## Framing: only when the site forbids it
64
86
 
65
87
  A site sending no `X-Frame-Options` and no `frame-ancestors` needs nothing (GitHub Pages included). Otherwise
66
88
  `/_conloca/editor/*` needs `Content-Security-Policy: frame-ancestors 'self' https://*.conloca.com`, plus
67
- `/_conloca/editor/sandbox-frame.html` → `Content-Security-Policy: sandbox allow-scripts`. Cloudflare `_headers` also
89
+ `/_conloca/editor/sandbox-frame.html` → `Content-Security-Policy: sandbox allow-scripts` (the frame for a component's
90
+ raw HTML; its own CSP has no `unsafe-eval`, and fragments render inline in the editor page). Cloudflare `_headers` also
68
91
  detaches the site's headers on that path (`! X-Frame-Options`, `! Content-Security-Policy`); Netlify cannot detach;
69
92
  Vercel uses `source: "/_conloca/editor/:path*"`. A site-wide CSP with `frame-ancestors` must be narrowed by hand — a
70
93
  second policy cannot loosen it.
package/src/types.ts CHANGED
@@ -1,32 +1,31 @@
1
1
  import type { AstroIntegration } from 'astro';
2
2
 
3
3
  /**
4
- * The second build that serves draft previews. Off unless given as an object. A static site's preview server runs on
5
- * Cloudflare Workers under `/_conloca/preview/` next to the site (it needs `@astrojs/cloudflare` installed); a site
6
- * with an adapter serves drafts from its own server deploy; `separate: true` builds a separate preview deploy.
7
- * Refused under `@astrojs/vercel` and `@astrojs/netlify`.
4
+ * Draft previews. Off unless given as an object. A static site's preview server is a second build that runs on
5
+ * Cloudflare Workers under `/_conloca/preview/` next to the site (D3; it needs `@astrojs/cloudflare` installed); a site
6
+ * with an adapter renders drafts in its own build (D8); `separate: true` builds a separate preview deploy (D4).
7
+ * `config` and `outDir` belong to D3 and D4 only (a D8 build warns they have no effect); `required` is ignored in every
8
+ * mode, with a warning. `separate` is
9
+ * refused under `@astrojs/vercel` and `@astrojs/netlify`.
8
10
  */
9
11
  export interface PreviewBuildOptions {
10
- /**
11
- * Optional alternative Astro adapter to use for the preview build.
12
- * Falls back to the project's default adapter when omitted.
13
- */
12
+ /** Refused: drafts render through the adapter in astro.config. Kept in the type so the refusal can name it. */
14
13
  adapter?: AstroIntegration;
15
14
  /**
16
- * Adapter-specific config overrides forwarded to the recursive build.
15
+ * Adapter-specific config overrides forwarded to the D3 or D4 preview build.
17
16
  */
18
17
  config?: Record<string, unknown>;
19
18
  /**
20
- * Output directory for the preview build. Defaults to `.conloca/preview-server`
19
+ * Output directory for the D3 or D4 preview build. Defaults to `.conloca/preview-server`
21
20
  * — outside `dist/`, so the preview server can never ride a wholesale static
22
21
  * upload of the site and Astro's dist-clearing cannot wipe it.
23
22
  */
24
23
  outDir?: string;
25
24
  /**
26
- * If true, fail the site's build when a D2 preview build fails. Defaults to true; set false while setting up.
27
- * A failed D3 preview build fails the site's build only when its server also serves the live site (`run_worker_first`
28
- * lists routes beyond the preview route, or `not_found_handling` is `"none"`); otherwise the site ships and its
29
- * preview route answers "preview unavailable". This option changes neither.
25
+ * Ignored in every mode (the build warns). A failed D3 preview build fails the site's build only when its server also
26
+ * serves the live site (`run_worker_first` lists routes beyond the preview route, or `not_found_handling` is
27
+ * `"none"`); otherwise the site ships and its preview route answers "preview unavailable". A D4 build is its deploy's
28
+ * own.
30
29
  */
31
30
  required?: boolean;
32
31
  /**
@@ -79,8 +78,8 @@ export interface ConlocaCloudOptions {
79
78
  */
80
79
  siteStyles?: string | string[];
81
80
  /**
82
- * Off unless given as an object; the second build that serves draft
83
- * previews. Refused under @astrojs/vercel and @astrojs/netlify.
81
+ * Off unless given as an object: draft previews in the site's own build (d8, with an adapter), next to a static
82
+ * site (D3) or from a separate deploy (D4). `separate` is refused under @astrojs/vercel and @astrojs/netlify.
84
83
  */
85
84
  previewBuild?: PreviewBuildOptions | false;
86
85
  /**
@@ -6,8 +6,9 @@
6
6
  * augmenting an existing module rather than declaring a new ambient one.
7
7
  *
8
8
  * `virtual:conloca-preview-opts` carries the preview middleware's configuration
9
- * baked in during the recursive preview build, so a preview deployment needs no
10
- * runtime env vars. It resolves to `{}` outside that build.
9
+ * baked in during the preview build (or a d8 site's own build), so a preview
10
+ * deployment needs no runtime env vars. It resolves to `{}` outside those builds.
11
+ * Mirrors `BakedPreviewOpts`.
11
12
  */
12
13
  declare module 'virtual:conloca-preview-opts' {
13
14
  const baked: {
@@ -19,6 +20,15 @@ declare module 'virtual:conloca-preview-opts' {
19
20
  siteId?: string;
20
21
  branch?: string;
21
22
  base?: string;
23
+ mode?: 'd2' | 'd3' | 'd4' | 'd8';
24
+ domains?: string[];
25
+ trailingSlash?: 'always' | 'never' | 'ignore';
26
+ sitePages?:
27
+ | { kind: 'disk'; serverEntry: string }
28
+ | { kind: 'assets' }
29
+ | { kind: 'function'; serverEntry: string; origin: string | null }
30
+ | { kind: 'none' };
31
+ buildFormat?: 'directory' | 'file' | 'preserve';
22
32
  };
23
33
  export default baked;
24
34
  }
@@ -44,6 +54,11 @@ declare module 'astro:content' {
44
54
  export function getCollection(collection: string): Promise<{ data: Record<string, unknown> }[]>;
45
55
  }
46
56
 
57
+ /** Astro's assets module, resolvable only inside a site build: the image config the preview image endpoint checks. */
58
+ declare module 'astro:assets' {
59
+ export const imageConfig: import('astro').AstroConfig['image'];
60
+ }
61
+
47
62
  /**
48
63
  * The Cloudflare Workers runtime module (bindings live here since Astro v6
49
64
  * removed `locals.runtime.env`). Only resolvable inside workerd; the preview