@conloca/cloud-astro 0.2.2 → 0.2.4

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 (241) hide show
  1. package/README.md +378 -207
  2. package/dist/.build-inputs.json +69 -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 +14 -13
  8. package/dist/src/constants.d.ts.map +1 -1
  9. package/dist/src/constants.js +14 -13
  10. package/dist/src/constants.js.map +1 -1
  11. package/dist/src/d3-build.d.ts +70 -0
  12. package/dist/src/d3-build.d.ts.map +1 -0
  13. package/dist/src/d3-build.js +272 -0
  14. package/dist/src/d3-build.js.map +1 -0
  15. package/dist/src/descriptors.d.ts +2 -2
  16. package/dist/src/descriptors.d.ts.map +1 -1
  17. package/dist/src/descriptors.js +4 -2
  18. package/dist/src/descriptors.js.map +1 -1
  19. package/dist/src/doctor/checks-address.d.ts +18 -0
  20. package/dist/src/doctor/checks-address.d.ts.map +1 -0
  21. package/dist/src/doctor/checks-address.js +163 -0
  22. package/dist/src/doctor/checks-address.js.map +1 -0
  23. package/dist/src/doctor/checks-live.d.ts +8 -5
  24. package/dist/src/doctor/checks-live.d.ts.map +1 -1
  25. package/dist/src/doctor/checks-live.js +226 -188
  26. package/dist/src/doctor/checks-live.js.map +1 -1
  27. package/dist/src/doctor/checks-offline.d.ts +6 -25
  28. package/dist/src/doctor/checks-offline.d.ts.map +1 -1
  29. package/dist/src/doctor/checks-offline.js +30 -259
  30. package/dist/src/doctor/checks-offline.js.map +1 -1
  31. package/dist/src/doctor/checks-preview-limits.d.ts +11 -0
  32. package/dist/src/doctor/checks-preview-limits.d.ts.map +1 -0
  33. package/dist/src/doctor/checks-preview-limits.js +133 -0
  34. package/dist/src/doctor/checks-preview-limits.js.map +1 -0
  35. package/dist/src/doctor/checks-preview-live.d.ts +14 -0
  36. package/dist/src/doctor/checks-preview-live.d.ts.map +1 -0
  37. package/dist/src/doctor/checks-preview-live.js +72 -0
  38. package/dist/src/doctor/checks-preview-live.js.map +1 -0
  39. package/dist/src/doctor/checks-preview.d.ts +7 -0
  40. package/dist/src/doctor/checks-preview.d.ts.map +1 -0
  41. package/dist/src/doctor/checks-preview.js +287 -0
  42. package/dist/src/doctor/checks-preview.js.map +1 -0
  43. package/dist/src/doctor/config-scan.d.ts +12 -3
  44. package/dist/src/doctor/config-scan.d.ts.map +1 -1
  45. package/dist/src/doctor/config-scan.js +38 -11
  46. package/dist/src/doctor/config-scan.js.map +1 -1
  47. package/dist/src/doctor/run.d.ts.map +1 -1
  48. package/dist/src/doctor/run.js +16 -10
  49. package/dist/src/doctor/run.js.map +1 -1
  50. package/dist/src/doctor/types.d.ts +17 -7
  51. package/dist/src/doctor/types.d.ts.map +1 -1
  52. package/dist/src/doctor/types.js +17 -7
  53. package/dist/src/doctor/types.js.map +1 -1
  54. package/dist/src/editor-page/bundle.d.ts +90 -0
  55. package/dist/src/editor-page/bundle.d.ts.map +1 -0
  56. package/dist/src/editor-page/bundle.js +373 -0
  57. package/dist/src/editor-page/bundle.js.map +1 -0
  58. package/dist/src/editor-page/data-schemas.d.ts +16 -0
  59. package/dist/src/editor-page/data-schemas.d.ts.map +1 -0
  60. package/dist/src/editor-page/data-schemas.js +39 -0
  61. package/dist/src/editor-page/data-schemas.js.map +1 -0
  62. package/dist/src/editor-page/emit.d.ts +69 -0
  63. package/dist/src/editor-page/emit.d.ts.map +1 -0
  64. package/dist/src/editor-page/emit.js +254 -0
  65. package/dist/src/editor-page/emit.js.map +1 -0
  66. package/dist/src/editor-page/framing.d.ts +23 -0
  67. package/dist/src/editor-page/framing.d.ts.map +1 -0
  68. package/dist/src/editor-page/framing.js +39 -0
  69. package/dist/src/editor-page/framing.js.map +1 -0
  70. package/dist/src/editor-page/page.d.ts +9 -0
  71. package/dist/src/editor-page/page.d.ts.map +1 -0
  72. package/dist/src/editor-page/page.js +31 -0
  73. package/dist/src/editor-page/page.js.map +1 -0
  74. package/dist/src/editor-page/site-base.d.ts +4 -0
  75. package/dist/src/editor-page/site-base.d.ts.map +1 -0
  76. package/dist/src/editor-page/site-base.js +13 -0
  77. package/dist/src/editor-page/site-base.js.map +1 -0
  78. package/dist/src/git.d.ts +11 -8
  79. package/dist/src/git.d.ts.map +1 -1
  80. package/dist/src/git.js +25 -8
  81. package/dist/src/git.js.map +1 -1
  82. package/dist/src/index.d.ts +4 -1
  83. package/dist/src/index.d.ts.map +1 -1
  84. package/dist/src/index.js +11 -6
  85. package/dist/src/index.js.map +1 -1
  86. package/dist/src/integration.d.ts +1 -1
  87. package/dist/src/integration.d.ts.map +1 -1
  88. package/dist/src/integration.js +377 -416
  89. package/dist/src/integration.js.map +1 -1
  90. package/dist/src/node.d.ts +3 -1
  91. package/dist/src/node.d.ts.map +1 -1
  92. package/dist/src/node.js +7 -2
  93. package/dist/src/node.js.map +1 -1
  94. package/dist/src/preview/_dispatch.d.ts +12 -0
  95. package/dist/src/preview/_dispatch.d.ts.map +1 -1
  96. package/dist/src/preview/_dispatch.js +31 -0
  97. package/dist/src/preview/_dispatch.js.map +1 -1
  98. package/dist/src/preview/_resolve-opts.d.ts +19 -10
  99. package/dist/src/preview/_resolve-opts.d.ts.map +1 -1
  100. package/dist/src/preview/_resolve-opts.js +24 -11
  101. package/dist/src/preview/_resolve-opts.js.map +1 -1
  102. package/dist/src/preview/banner.d.ts +12 -9
  103. package/dist/src/preview/banner.d.ts.map +1 -1
  104. package/dist/src/preview/banner.js +46 -43
  105. package/dist/src/preview/banner.js.map +1 -1
  106. package/dist/src/preview/cloudflare-adapter.d.ts +35 -0
  107. package/dist/src/preview/cloudflare-adapter.d.ts.map +1 -0
  108. package/dist/src/preview/cloudflare-adapter.js +92 -0
  109. package/dist/src/preview/cloudflare-adapter.js.map +1 -0
  110. package/dist/src/preview/cookie.d.ts +13 -14
  111. package/dist/src/preview/cookie.d.ts.map +1 -1
  112. package/dist/src/preview/cookie.js +19 -26
  113. package/dist/src/preview/cookie.js.map +1 -1
  114. package/dist/src/preview/dispatcher.d.ts +73 -0
  115. package/dist/src/preview/dispatcher.d.ts.map +1 -0
  116. package/dist/src/preview/dispatcher.js +329 -0
  117. package/dist/src/preview/dispatcher.js.map +1 -0
  118. package/dist/src/preview/entry-code.d.ts +33 -0
  119. package/dist/src/preview/entry-code.d.ts.map +1 -0
  120. package/dist/src/preview/entry-code.js +33 -0
  121. package/dist/src/preview/entry-code.js.map +1 -0
  122. package/dist/src/preview/headers.d.ts +24 -4
  123. package/dist/src/preview/headers.d.ts.map +1 -1
  124. package/dist/src/preview/headers.js +35 -7
  125. package/dist/src/preview/headers.js.map +1 -1
  126. package/dist/src/preview/label.d.ts +8 -0
  127. package/dist/src/preview/label.d.ts.map +1 -0
  128. package/dist/src/preview/label.js +14 -0
  129. package/dist/src/preview/label.js.map +1 -0
  130. package/dist/src/preview/landing.d.ts +23 -2
  131. package/dist/src/preview/landing.d.ts.map +1 -1
  132. package/dist/src/preview/landing.js +105 -37
  133. package/dist/src/preview/landing.js.map +1 -1
  134. package/dist/src/preview/middleware.d.ts +49 -22
  135. package/dist/src/preview/middleware.d.ts.map +1 -1
  136. package/dist/src/preview/middleware.js +259 -100
  137. package/dist/src/preview/middleware.js.map +1 -1
  138. package/dist/src/preview/preview-path.d.ts +47 -5
  139. package/dist/src/preview/preview-path.d.ts.map +1 -1
  140. package/dist/src/preview/preview-path.js +65 -8
  141. package/dist/src/preview/preview-path.js.map +1 -1
  142. package/dist/src/preview/redeem-url.d.ts +7 -0
  143. package/dist/src/preview/redeem-url.d.ts.map +1 -0
  144. package/dist/src/preview/redeem-url.js +14 -0
  145. package/dist/src/preview/redeem-url.js.map +1 -0
  146. package/dist/src/preview/site-middleware.d.ts +5 -5
  147. package/dist/src/preview/site-middleware.d.ts.map +1 -1
  148. package/dist/src/preview/site-middleware.js +53 -26
  149. package/dist/src/preview/site-middleware.js.map +1 -1
  150. package/dist/src/preview-build.d.ts +29 -15
  151. package/dist/src/preview-build.d.ts.map +1 -1
  152. package/dist/src/preview-build.js +66 -25
  153. package/dist/src/preview-build.js.map +1 -1
  154. package/dist/src/preview.d.ts +1 -1
  155. package/dist/src/preview.d.ts.map +1 -1
  156. package/dist/src/preview.js +1 -1
  157. package/dist/src/preview.js.map +1 -1
  158. package/dist/src/repository.d.ts +1 -1
  159. package/dist/src/repository.js +1 -1
  160. package/dist/src/resolve-options.d.ts +17 -0
  161. package/dist/src/resolve-options.d.ts.map +1 -0
  162. package/dist/src/resolve-options.js +21 -0
  163. package/dist/src/resolve-options.js.map +1 -0
  164. package/dist/src/site-id.d.ts +0 -2
  165. package/dist/src/site-id.d.ts.map +1 -1
  166. package/dist/src/site-id.js +2 -3
  167. package/dist/src/site-id.js.map +1 -1
  168. package/dist/src/skill.d.ts +11 -0
  169. package/dist/src/skill.d.ts.map +1 -1
  170. package/dist/src/skill.js +32 -9
  171. package/dist/src/skill.js.map +1 -1
  172. package/dist/src/types.d.ts +33 -78
  173. package/dist/src/types.d.ts.map +1 -1
  174. package/package.json +63 -13
  175. package/src/component-manifest.ts +11 -8
  176. package/src/constants.ts +15 -13
  177. package/src/d3-build.ts +315 -0
  178. package/src/descriptors.ts +6 -4
  179. package/src/doctor/checks-address.ts +190 -0
  180. package/src/doctor/checks-live.ts +262 -268
  181. package/src/doctor/checks-offline.ts +32 -279
  182. package/src/doctor/checks-preview-limits.ts +137 -0
  183. package/src/doctor/checks-preview-live.ts +77 -0
  184. package/src/doctor/checks-preview.ts +302 -0
  185. package/src/doctor/config-scan.ts +35 -9
  186. package/src/doctor/run.ts +18 -16
  187. package/src/doctor/types.ts +17 -7
  188. package/src/editor-page/bundle.ts +487 -0
  189. package/src/editor-page/data-schemas.ts +47 -0
  190. package/src/editor-page/emit.ts +362 -0
  191. package/src/editor-page/framing.ts +62 -0
  192. package/src/editor-page/page.ts +37 -0
  193. package/src/editor-page/site-base.ts +11 -0
  194. package/src/git.ts +29 -10
  195. package/src/index.ts +22 -6
  196. package/src/integration.ts +399 -469
  197. package/src/node.ts +18 -2
  198. package/src/preview/_dispatch.ts +36 -1
  199. package/src/preview/_resolve-opts.ts +35 -12
  200. package/src/preview/banner.ts +61 -43
  201. package/src/preview/cloudflare-adapter.ts +103 -0
  202. package/src/preview/cookie.ts +18 -24
  203. package/src/preview/dispatcher.ts +407 -0
  204. package/src/preview/entry-code.ts +51 -0
  205. package/src/preview/headers.ts +35 -7
  206. package/src/preview/label.ts +12 -0
  207. package/src/preview/landing.ts +117 -39
  208. package/src/preview/middleware.ts +302 -115
  209. package/src/preview/preview-path.ts +83 -8
  210. package/src/preview/redeem-url.ts +14 -0
  211. package/src/preview/site-middleware.ts +60 -30
  212. package/src/preview-build.ts +85 -26
  213. package/src/preview-handler.astro +12 -9
  214. package/src/preview.ts +0 -1
  215. package/src/repository.ts +1 -1
  216. package/src/resolve-options.ts +37 -0
  217. package/src/site-id.ts +2 -4
  218. package/src/skill/SKILL.md +63 -55
  219. package/src/skill.ts +36 -8
  220. package/src/types.ts +33 -79
  221. package/src/virtual-modules.d.ts +4 -1
  222. package/dist/src/build-commit.d.ts +0 -19
  223. package/dist/src/build-commit.d.ts.map +0 -1
  224. package/dist/src/build-commit.js +0 -6
  225. package/dist/src/build-commit.js.map +0 -1
  226. package/dist/src/bundle.d.ts +0 -181
  227. package/dist/src/bundle.d.ts.map +0 -1
  228. package/dist/src/bundle.js +0 -413
  229. package/dist/src/bundle.js.map +0 -1
  230. package/dist/src/discovery.d.ts +0 -58
  231. package/dist/src/discovery.d.ts.map +0 -1
  232. package/dist/src/discovery.js +0 -133
  233. package/dist/src/discovery.js.map +0 -1
  234. package/dist/src/register.d.ts +0 -98
  235. package/dist/src/register.d.ts.map +0 -1
  236. package/dist/src/register.js +0 -103
  237. package/dist/src/register.js.map +0 -1
  238. package/src/build-commit.ts +0 -22
  239. package/src/bundle.ts +0 -570
  240. package/src/discovery.ts +0 -183
  241. package/src/register.ts +0 -180
@@ -0,0 +1,14 @@
1
+ /** The org id as unpadded base64url: the form share links, entry codes and the grant cookie carry it in. */
2
+ export function orgToken(org: string): string {
3
+ let binary = '';
4
+ for (const byte of new TextEncoder().encode(org)) binary += String.fromCharCode(byte);
5
+ return btoa(binary).replace(/\+/gu, '-').replace(/\//gu, '_').replace(/=+$/u, '');
6
+ }
7
+
8
+ /** `<orgToken>.<grantId>`: names one share link without naming the org in clear. */
9
+ export function grantRef(org: string, grantId: string): string {
10
+ return `${orgToken(org)}.${grantId}`;
11
+ }
12
+
13
+ /** A grant reference as the grant cookie holds it. */
14
+ export const GRANT_REF_RE = /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]{22}$/u;
@@ -2,15 +2,15 @@
2
2
  * Site-wide preview middleware for the recursive preview build — the SERVING
3
3
  * SURFACE of draft preview.
4
4
  *
5
- * WHY THIS EXISTS — the secret path prefix is an entry door, not the serving
5
+ * WHY THIS EXISTS — the fixed preview route is an entry door, not the serving
6
6
  * surface. Without this, preview survives exactly one page view: the visitor
7
- * lands on `/conloca_preview_<secret>/about`, clicks a link, and the
8
- * root-absolute `/blog` the site's template emitted drops the prefix and
9
- * silently serves the PUBLISHED page. The preview cookie is already `Path=/`,
7
+ * lands on `/_conloca/preview/about`, clicks a link, and the root-absolute
8
+ * `/blog` the site's template emitted drops the route and silently serves the
9
+ * PUBLISHED page. The preview cookie is already `Path=/`,
10
10
  * so the browser is sending the credential on that request — this listens.
11
11
  *
12
12
  * WHY THE RENDER HAPPENS HERE, VIA `next()` — a middleware rewrite onto the
13
- * secret-prefixed handler (the previous design) forced the render through
13
+ * preview route's handler (an earlier design) forced the render through
14
14
  * `Astro.rewrite`, whose route matching does not fall through prerendered
15
15
  * routes: with two root catch-alls (the CMS pages route on demand, a docs
16
16
  * integration's route prerendered) the rewrite matched the prerendered one
@@ -27,17 +27,19 @@
27
27
  */
28
28
 
29
29
  import type { ContentAPI } from '@conloca/content-api';
30
- import { fetchPageStatus, type PageStatus } from './_dispatch.js';
30
+ import { fetchPageStatus, isShareEndedKind, type PageStatus } from './_dispatch.js';
31
31
  import { injectPreviewBanner } from './banner.js';
32
32
  import { PreviewContentAPI } from './content-api.js';
33
- import { applyPreviewHeaders } from './headers.js';
33
+ import { applyPreviewHeaders, PREVIEW_CACHE_HEADERS } from './headers.js';
34
+ import { renderPreviewUnavailable, renderShareEnded } from './landing.js';
35
+ import { handlePreviewRequest, type PreviewContext, type PreviewMiddlewareOptions } from './middleware.js';
34
36
  import {
35
- handlePreviewRequest,
36
- type PreviewContext,
37
- type PreviewMiddlewareOptions,
38
- previewParamName,
39
- } from './middleware.js';
40
- import { normalizeTrailingSlash, stripPreviewPrefix } from './preview-path.js';
37
+ normalizeTrailingSlash,
38
+ PREVIEW_SLUG_HEADER,
39
+ pathUnderBase,
40
+ previewScope,
41
+ stripPreviewPrefix,
42
+ } from './preview-path.js';
41
43
 
42
44
  /** The subset of Astro's middleware context this middleware touches. */
43
45
  export interface PreviewMiddlewareContext {
@@ -86,8 +88,8 @@ export function createPreviewSiteMiddleware(resolveOpts: () => PreviewMiddleware
86
88
  // ALSO at build time, where Astro runs middleware while prerendering pages
87
89
  // and the deployer's runtime vars do not exist yet. Neither is a reason to
88
90
  // break the site's build or the whole site over a feature it may
89
- // not use, so pass through and warn once. The secret-prefixed entry route
90
- // still fails loudly: reaching it means someone explicitly asked to preview.
91
+ // not use, so pass through and warn once. The preview entry route still
92
+ // fails loudly: reaching it means someone explicitly asked to preview.
91
93
  let opts: PreviewMiddlewareOptions;
92
94
  try {
93
95
  opts = resolveOpts();
@@ -96,30 +98,38 @@ export function createPreviewSiteMiddleware(resolveOpts: () => PreviewMiddleware
96
98
  return next();
97
99
  }
98
100
 
101
+ // Under D3 the dispatcher names the requested branch's slug, after stripping any the browser sent.
102
+ const slug = opts.mode === 'd3' ? (context.request.headers.get(PREVIEW_SLUG_HEADER) ?? undefined) : undefined;
99
103
  const verdict = await handlePreviewRequest(context.request, {
100
104
  ...opts,
101
- onMiss: 'pass-through',
105
+ ...(slug === undefined ? {} : { slug }),
106
+ // No silent fallback: under the slug, a pass that doesn't verify gets the landing page, never the
107
+ // published page at the draft URL. Only the live site's own requests (no slug) pass through.
108
+ onMiss: slug === undefined ? 'pass-through' : 'landing',
102
109
  fetchFn: opts.fetchFn ?? seams.fetchFn,
103
110
  });
104
111
  if (verdict.kind === 'response') return verdict.response;
105
112
  if (verdict.kind !== 'preview') return next();
113
+ // A preview verdict under D3 means the slug was named, so the scope always resolves.
114
+ const exitPath = `${previewScope(opts.mode ?? 'd2', opts.base, slug).route}/__exit`;
106
115
 
107
- // A valid credential on the LITERAL secret-prefixed URL: canonicalize to
108
- // the clean site path instead of rendering under the prefix — links,
109
- // assets and the page lookup all assume clean paths.
116
+ // A valid credential on the preview route itself: canonicalize to the
117
+ // clean site path instead of rendering under the route — links, assets
118
+ // and the page lookup all assume clean paths.
110
119
  const rawPath = context.url.pathname;
111
- const path = normalizeTrailingSlash(stripPreviewPrefix(rawPath));
112
- if (stripPreviewPrefix(rawPath) !== rawPath) {
120
+ const path = normalizeTrailingSlash(stripPreviewPrefix(rawPath, opts.base));
121
+ if (stripPreviewPrefix(rawPath, opts.base) !== rawPath) {
113
122
  return new Response(null, {
114
123
  status: 302,
115
- headers: { location: path, 'cache-control': 'private, no-store' },
124
+ headers: { location: path, ...PREVIEW_CACHE_HEADERS },
116
125
  });
117
126
  }
118
127
 
119
128
  context.locals.conlocaPreview = verdict.ctx;
120
- // An endpoint failure (5xx mid-deploy, auth envelope, network) must not 500
121
- // the whole site for a visitor holding the HttpOnly cookie they cannot
122
- // remove — degrade to published bytes, keeping the preview headers.
129
+ // An endpoint failure (5xx mid-deploy, auth envelope, network) must neither
130
+ // 500 the site nor pass published bytes off as the draft: answer with a
131
+ // retry page that also offers Exit, since the visitor can't remove the
132
+ // HttpOnly cookie.
123
133
  let status: PageStatus;
124
134
  try {
125
135
  status = await fetchPageStatus({
@@ -133,10 +143,21 @@ export function createPreviewSiteMiddleware(resolveOpts: () => PreviewMiddleware
133
143
  });
134
144
  } catch (error) {
135
145
  console.warn(
136
- `[@conloca/cloud-astro] preview page-status failed for ${path} — serving the published page instead: ` +
146
+ `[@conloca/cloud-astro] preview page-status failed for ${path} — showing the retry page: ` +
137
147
  `${error instanceof Error ? error.message : String(error)}`,
138
148
  );
139
- return applyPreviewHeaders(await next());
149
+ return renderPreviewUnavailable({
150
+ // Collapse leading slashes: `//evil.test/x` would otherwise be a cross-origin link.
151
+ retryHref: `/${rawPath.replace(/^\/+/u, '')}${context.url.search}`,
152
+ exitHref: `${exitPath}?to=${encodeURIComponent(rawPath)}`,
153
+ });
154
+ }
155
+
156
+ if (isShareEndedKind(status.kind) && 'sharedBy' in status) {
157
+ return renderShareEnded(status.kind, {
158
+ sharedBy: status.sharedBy,
159
+ liveHref: `${exitPath}?to=${encodeURIComponent(path)}`,
160
+ });
140
161
  }
141
162
 
142
163
  if (status.kind === 'unchanged') {
@@ -151,7 +172,7 @@ export function createPreviewSiteMiddleware(resolveOpts: () => PreviewMiddleware
151
172
  // redirect can never be cached by intermediaries.
152
173
  return new Response(null, {
153
174
  status: 302,
154
- headers: { location: status.target, 'cache-control': 'private, no-store' },
175
+ headers: { location: status.target, ...PREVIEW_CACHE_HEADERS },
155
176
  });
156
177
  }
157
178
 
@@ -180,11 +201,20 @@ export function createPreviewSiteMiddleware(resolveOpts: () => PreviewMiddleware
180
201
  // through with the preview headers only.
181
202
  return applyPreviewHeaders(rendered);
182
203
  }
204
+ let shareUrl: string | undefined;
205
+ if (verdict.ctx.editorUrl !== undefined) {
206
+ const url = new URL(verdict.ctx.editorUrl);
207
+ url.searchParams.set('share', pathUnderBase(path, opts.base));
208
+ shareUrl = url.toString();
209
+ }
183
210
  const html = injectPreviewBanner(
184
211
  await rendered.text(),
185
212
  verdict.ctx,
186
213
  opts.saasEndpoint,
187
- `/${previewParamName(opts.secret)}/__exit`,
214
+ exitPath,
215
+ shareUrl,
216
+ // The page's own path: under D3 the address bar holds the route, which Edit and Exit must not carry.
217
+ rawPath,
188
218
  );
189
219
  return applyPreviewHeaders(new Response(html, { status: rendered.status, headers: rendered.headers }));
190
220
  };
@@ -204,7 +234,7 @@ function warnUnconfiguredOnce(error: unknown): void {
204
234
  console.warn(
205
235
  `[@conloca/cloud-astro] draft preview is INERT — ${detail}\n` +
206
236
  ' Requests are being served as the ordinary published site.\n' +
207
- ' Draft previews on your own deployment are not available yet: keep previewBuild: false ' +
237
+ ' The preview server is missing its baked settings: rebuild with previewBuild given as an object ' +
208
238
  '(see the cloud-astro README "Draft previews").',
209
239
  );
210
240
  }
@@ -1,10 +1,65 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { existsSync } from 'node:fs';
3
3
  import { join } from 'node:path';
4
- import { PACKAGE_NAME, PREVIEW_BUILD_ENV_FLAG, PREVIEW_SECRET_ENV_FLAG } from './constants.js';
4
+ import {
5
+ PACKAGE_NAME,
6
+ PREVIEW_BUILD_ENV_FLAG,
7
+ PREVIEW_MODE_ENV,
8
+ PREVIEW_PRERENDERED_ENV,
9
+ REFUSED_PREVIEW_ADAPTERS,
10
+ } from './constants.js';
11
+ import type { PreviewServeMode } from './preview/preview-path.js';
5
12
  import type { PreviewBuildOptions } from './types.js';
6
13
 
7
- export { PREVIEW_SECRET_ENV_FLAG };
14
+ /**
15
+ * How the preview build serves, from the options and the adapter the preview server would build with
16
+ * (`previewBuild.adapter`, else the project's own): off unless `previewBuild` is given as an object; D4 with
17
+ * `separate: true`; D3 for a static site, whose preview server runs next to it on Cloudflare Workers; D2 when an
18
+ * adapter is named, since the site's own server deploy serves the drafts. Throws for a refused adapter, so the build
19
+ * fails before it deploys anything.
20
+ */
21
+ export function previewBuildMode(
22
+ previewBuild: PreviewBuildOptions | false | undefined,
23
+ adapterName: string | undefined,
24
+ ): 'off' | PreviewServeMode {
25
+ if (!previewBuild) return 'off';
26
+ if (adapterName !== undefined && REFUSED_PREVIEW_ADAPTERS.includes(adapterName)) {
27
+ throw new Error(
28
+ `${PACKAGE_NAME}: previewBuild is not supported with ${adapterName} yet: that adapter writes its deployable ` +
29
+ 'output at the project root, so the preview build could replace the live site. ' +
30
+ 'Remove previewBuild from conlocaCloud(...).',
31
+ );
32
+ }
33
+ if (previewBuild.separate === true) return 'd4';
34
+ return adapterName === undefined ? 'd3' : 'd2';
35
+ }
36
+
37
+ /** The mode a preview build serves in: the site's build names D2 or D3; the flag alone is a separate preview deploy (D4). */
38
+ export function previewChildMode(env: NodeJS.ProcessEnv): PreviewServeMode {
39
+ const named = env[PREVIEW_MODE_ENV];
40
+ return named === 'd2' || named === 'd3' ? named : 'd4';
41
+ }
42
+
43
+ /**
44
+ * One route the site's build prerendered, as a D3 child matches it: pattern and component together, since one
45
+ * entrypoint can be injected at two patterns, one published and one only the preview build has.
46
+ */
47
+ export function prerenderedKey(pattern: string, component: string): string {
48
+ return JSON.stringify([pattern, component]);
49
+ }
50
+
51
+ /** The routes (`prerenderedKey`) a D3 child's site build prerendered (`buildPreviewChildEnv`); none for any other child. */
52
+ export function previewChildPrerendered(env: NodeJS.ProcessEnv): Set<string> {
53
+ const text = env[PREVIEW_PRERENDERED_ENV];
54
+ if (previewChildMode(env) !== 'd3' || text === undefined) return new Set();
55
+ let value: unknown;
56
+ try {
57
+ value = JSON.parse(text);
58
+ } catch {
59
+ return new Set();
60
+ }
61
+ return new Set(Array.isArray(value) ? value.filter((item) => typeof item === 'string') : []);
62
+ }
8
63
 
9
64
  /**
10
65
  * The minimal child-process surface this module relies on. Letting
@@ -25,19 +80,24 @@ export type PreviewBuildSpawn = (
25
80
 
26
81
  /**
27
82
  * Pure constructor for the child-process environment passed to the recursive
28
- * preview build. Extracted so tests can verify the contract (env flag + secret
29
- * + parent-env inheritance) without spinning up a child process — and so the
83
+ * preview build. Extracted so tests can verify the contract (env flag +
84
+ * parent-env inheritance) without spinning up a child process — and so the
30
85
  * real-process smoke test can call it the same way the integration does.
31
86
  *
32
87
  * Inherits the parent environment so PATH, credentials, and any host-specific
33
- * build vars (CF_PAGES_*, GITHUB_*) reach the child.
88
+ * build vars (CF_PAGES_*, WORKERS_CI_*, GITHUB_*) reach the child, which reads
89
+ * the branch and commit it serves from them.
34
90
  */
35
- export function buildPreviewChildEnv(parentEnv: NodeJS.ProcessEnv, previewSecret: string): NodeJS.ProcessEnv {
36
- return {
37
- ...parentEnv,
38
- [PREVIEW_BUILD_ENV_FLAG]: '1',
39
- [PREVIEW_SECRET_ENV_FLAG]: previewSecret,
40
- };
91
+ export function buildPreviewChildEnv(
92
+ parentEnv: NodeJS.ProcessEnv,
93
+ mode: 'd2' | 'd3' = 'd2',
94
+ prerendered: readonly string[] = [],
95
+ ): NodeJS.ProcessEnv {
96
+ const env: NodeJS.ProcessEnv = { ...parentEnv, [PREVIEW_BUILD_ENV_FLAG]: '1', [PREVIEW_MODE_ENV]: mode };
97
+ // Only a D3 child reads it; a stale one from the environment must not reach a D2 child.
98
+ delete env[PREVIEW_PRERENDERED_ENV];
99
+ if (mode === 'd3') env[PREVIEW_PRERENDERED_ENV] = JSON.stringify(prerendered);
100
+ return env;
41
101
  }
42
102
 
43
103
  /**
@@ -71,13 +131,10 @@ export function resolveAstroBin(cwd: string = process.cwd()): string {
71
131
  * Spawns the recursive preview `astro build` from the primary build's
72
132
  * `astro:build:done` hook.
73
133
  *
74
- * The child process inherits the parent environment and additionally receives:
75
- * - {@link PREVIEW_BUILD_ENV_FLAG} set to `'1'` so the integration's own
76
- * `astro:build:done` short-circuits inside the child (recursion guard
77
- * contract).
78
- * - {@link PREVIEW_SECRET_ENV_FLAG} set to the per-branch secret so the
79
- * child's `astro:config:setup` can inject the literal secret-scoped
80
- * preview route (`/conloca_preview_${SECRET}/[...path]`).
134
+ * The child process inherits the parent environment and additionally receives
135
+ * {@link PREVIEW_BUILD_ENV_FLAG} set to `'1'`: the child's `astro:config:setup`
136
+ * mounts the preview route on it, and its `astro:build:done` short-circuits
137
+ * on it (recursion guard contract).
81
138
  *
82
139
  * If this function is itself called from within a recursive build (i.e. the
83
140
  * env flag is already set to `'1'`), it returns immediately without spawning,
@@ -88,8 +145,12 @@ export function resolveAstroBin(cwd: string = process.cwd()): string {
88
145
  * - `false` → resolves and logs a warning so onboarding setups can continue
89
146
  * when the preview build is not yet wired correctly.
90
147
  */
91
- export async function spawnPreviewBuild(previewSecret: string, opts: PreviewBuildOptions): Promise<void> {
92
- await _spawnPreviewBuildWith(spawn, previewSecret, opts);
148
+ export async function spawnPreviewBuild(
149
+ opts: PreviewBuildOptions,
150
+ mode: 'd2' | 'd3' = 'd2',
151
+ prerendered: readonly string[] = [],
152
+ ): Promise<void> {
153
+ await _spawnPreviewBuildWith(spawn, opts, mode, prerendered);
93
154
  }
94
155
 
95
156
  /**
@@ -100,10 +161,12 @@ export async function spawnPreviewBuild(previewSecret: string, opts: PreviewBuil
100
161
  * and not part of the package's public surface; it is not re-exported from
101
162
  * `src/index.ts` or `src/node.ts`.
102
163
  */
164
+ // oxlint-disable-next-line no-underscore-dangle -- the internal test seam.
103
165
  export async function _spawnPreviewBuildWith(
104
166
  spawnFn: PreviewBuildSpawn,
105
- previewSecret: string,
106
167
  opts: PreviewBuildOptions,
168
+ mode: 'd2' | 'd3' = 'd2',
169
+ prerendered: readonly string[] = [],
107
170
  ): Promise<void> {
108
171
  // Recursion guard: bail out before doing any work if we're already inside
109
172
  // a recursive preview build. This matches the short-circuit in the
@@ -112,15 +175,11 @@ export async function _spawnPreviewBuildWith(
112
175
  return;
113
176
  }
114
177
 
115
- if (!previewSecret) {
116
- throw new Error(`${PACKAGE_NAME}: preview secret is required to spawn the preview build`);
117
- }
118
-
119
178
  const required = opts.required ?? true;
120
179
 
121
180
  const astroBin = resolveAstroBin();
122
181
  const child = spawnFn(astroBin, ['build'], {
123
- env: buildPreviewChildEnv(process.env, previewSecret),
182
+ env: buildPreviewChildEnv(process.env, mode, prerendered),
124
183
  stdio: 'inherit',
125
184
  });
126
185
 
@@ -1,19 +1,21 @@
1
1
  ---
2
2
  import bakedPreviewOpts from 'virtual:conloca-preview-opts';
3
3
  import { resolveEndpointFetch, resolveFromBaked } from './preview/_resolve-opts.js';
4
+ import { PREVIEW_CACHE_HEADERS } from './preview/headers.js';
4
5
  import { stripPreviewPrefix } from './preview/preview-path.js';
5
6
  /**
6
- * Secret-prefixed entry route injected by the recursive preview build at
7
- * `/conloca_preview_${SECRET}/[...path]`. The secret in the path is a
8
- * load guard — JWT validation is the actual auth boundary.
7
+ * Entry route injected by the recursive preview build at the fixed, public
8
+ * `/_conloca/preview/[...path]` (under Astro's `base`). The route guards
9
+ * nothing: the signed pass is the lock, checked against the repository, site
10
+ * and branch this build was made from.
9
11
  *
10
12
  * This route is the ENTRY DOOR only; the site-wide middleware
11
13
  * (`./site-middleware.ts`) is the serving surface. Three verdicts:
12
14
  *
13
15
  * 1. `response` — the query-token init hop (302 that sets the preview
14
16
  * cookie and points at the clean path) or the no-preview landing page.
15
- * 2. `preview` — a valid cookie on the literal prefixed URL: canonicalize
16
- * with a 302 to the clean path. Rendering under the prefix is never
17
+ * 2. `preview` — a valid cookie on the preview route itself: canonicalize
18
+ * with a 302 to the clean path. Rendering under the route is never
17
19
  * correct (links/assets assume clean paths), and after the redirect the
18
20
  * middleware serves the draft. Normally the middleware canonicalizes
19
21
  * before this route runs — this branch is the defense-in-depth for an
@@ -25,8 +27,9 @@ import { stripPreviewPrefix } from './preview/preview-path.js';
25
27
  import { handlePreviewRequest } from './preview.js';
26
28
 
27
29
  // Same baked-then-env resolution the middleware uses, so the entry route and
28
- // the serving surface can never disagree about the secret. Throws loudly on a
29
- // missing var: reaching this route means someone explicitly asked to preview.
30
+ // the serving surface can never disagree about what this build serves. Throws
31
+ // loudly on a missing value: reaching this route means someone explicitly
32
+ // asked to preview.
30
33
  const opts = resolveFromBaked(bakedPreviewOpts, (name) => process.env[name]);
31
34
  const verdict = await handlePreviewRequest(Astro.request, {
32
35
  ...opts,
@@ -46,10 +49,10 @@ if (verdict.kind === 'pass-through') {
46
49
  }
47
50
 
48
51
  // verdict.kind === 'preview' — canonicalize to the clean site path.
49
- const cleanPath = stripPreviewPrefix(Astro.originPathname ?? Astro.url.pathname);
52
+ const cleanPath = stripPreviewPrefix(Astro.originPathname ?? Astro.url.pathname, opts.base);
50
53
  const canonical: Response = new Response(null, {
51
54
  status: 302,
52
- headers: { location: cleanPath, 'cache-control': 'private, no-store' },
55
+ headers: { location: cleanPath, ...PREVIEW_CACHE_HEADERS },
53
56
  });
54
57
  return canonical;
55
58
  ---
package/src/preview.ts CHANGED
@@ -18,5 +18,4 @@ export {
18
18
  type PreviewContext,
19
19
  type PreviewMiddlewareOptions,
20
20
  type PreviewVerdict,
21
- previewParamName,
22
21
  } from './preview/middleware.js';
package/src/repository.ts CHANGED
@@ -13,7 +13,7 @@ const REPO_SEGMENT = /^[A-Za-z0-9_.-]+$/;
13
13
 
14
14
  /**
15
15
  * Normalize a provider full_name or common Git remote into `owner/repo`.
16
- * Deliberately rejects local paths and nested groups: a registration names
16
+ * Deliberately rejects local paths and nested groups: the editor page names
17
17
  * its repository GitHub-style, as two segments.
18
18
  */
19
19
  export function normalizeRepositoryUri(input: string | undefined): string | undefined {
@@ -0,0 +1,37 @@
1
+ import type { EditorDescriptorChannel } from '@conloca/astro-cms/node';
2
+ import { PACKAGE_NAME } from './constants.js';
3
+ import type { ConlocaCloudOptions } from './types.js';
4
+
5
+ /** The editor options `conlocaCMS` already holds, settled for this build. */
6
+ export interface InheritedOptions {
7
+ puckConfigPath: string;
8
+ siteStyles?: string[];
9
+ editorStyles?: string[];
10
+ editorCss?: string;
11
+ }
12
+
13
+ /**
14
+ * Each option given to `conlocaCloud()` wins; the channel `conlocaCMS`
15
+ * published fills the rest. `editorStyles` and `editorCss` come from the
16
+ * channel only. Only `puckConfigPath` is mandatory: without it there is no
17
+ * editor to build.
18
+ */
19
+ export function resolveInheritedOptions(
20
+ options: Pick<ConlocaCloudOptions, 'puckConfigPath' | 'siteStyles'>,
21
+ channel: Pick<EditorDescriptorChannel, 'puckConfigPath' | 'siteStyles' | 'editorStyles' | 'editorCSS'> | undefined,
22
+ ): InheritedOptions {
23
+ const puckConfigPath = options.puckConfigPath ?? channel?.puckConfigPath;
24
+ if (!puckConfigPath) {
25
+ throw new Error(
26
+ `${PACKAGE_NAME}: puckConfigPath is required: add it to conlocaCloud(), or add conlocaCMS() to this site's integrations`,
27
+ );
28
+ }
29
+ const siteStyles =
30
+ typeof options.siteStyles === 'string' ? [options.siteStyles] : (options.siteStyles ?? channel?.siteStyles);
31
+ return {
32
+ puckConfigPath,
33
+ ...(siteStyles === undefined ? {} : { siteStyles }),
34
+ ...(channel?.editorStyles === undefined ? {} : { editorStyles: channel.editorStyles }),
35
+ ...(channel?.editorCSS === undefined ? {} : { editorCss: channel.editorCSS }),
36
+ };
37
+ }
package/src/site-id.ts CHANGED
@@ -1,10 +1,8 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
+ import { SITE_ID_RE } from '@conloca/content-api/editor-host';
3
4
  import { PACKAGE_NAME } from './constants.js';
4
5
 
5
- /** The site-id grammar: lowercase alphanumerics and dashes, 1-64 chars, alphanumeric first. */
6
- export const SITE_ID_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
7
-
8
6
  /**
9
7
  * Resolve the build's deployable-site id. STRICT: malformed input fails the
10
8
  * build — a silent mis-attach is the same "deployed, but the editor points at
@@ -55,7 +53,7 @@ export function resolveBuildSiteId(opts: {
55
53
  typeof record.sites !== 'object' ||
56
54
  Array.isArray(record.sites)
57
55
  ) {
58
- throw new Error(`${PACKAGE_NAME}: ${path} has no "sites" object — refusing to register a broken content model`);
56
+ throw new Error(`${PACKAGE_NAME}: ${path} has no "sites" object — refusing to build on a broken content model`);
59
57
  }
60
58
 
61
59
  let resolved: string;
@@ -1,69 +1,77 @@
1
1
  ---
2
2
  name: conloca-cloud
3
- description: Load when a Conloca site uses @conloca/cloud-astro — editor endpoint, build token, registrations, preview.
3
+ description: Load when a Conloca site uses @conloca/cloud-astro — conloca connect, the editor page, framing, doctor.
4
4
  ---
5
5
 
6
- # Connecting a site to an editor endpoint
6
+ # Connecting a site to the workspace editor
7
7
 
8
- `conlocaCloud(...)` from `@conloca/cloud-astro` is an add-on to `conlocaCMS(...)` — keep both in `integrations`. It
9
- hooks the site's `astro build` to compile the Puck config into an editor bundle, register that build at `endpoint`, and
10
- produce a draft-preview app. Nothing from it runs on the published site.
8
+ `conlocaCloud()` from `@conloca/cloud-astro` is an add-on to `conlocaCMS(...)` — keep both in `integrations`, after
9
+ `react()`. It needs no options: it takes `puckConfigPath` and `siteStyles` from `conlocaCMS` and builds for the
10
+ workspace editor at `https://app.conloca.com`. Each `astro build` adds the editor page under `_conloca/editor/` in the
11
+ output; the workspace editor at `<slug>.conloca.com` opens the deployed page in a frame. Nothing else of it runs on the
12
+ published site. There is no build key, secret or environment variable.
11
13
 
12
- ## First move: `conloca doctor --live`
13
-
14
- For any question about the editor at `endpoint` — editor not loading, a stale editor after a deploy, "is this branch
15
- registered?" — run this before reading source:
14
+ ## Set up: connect → commit → push → deploy → open
16
15
 
17
16
  ```bash
18
- CONLOCA_BUILD_TOKEN=cbt_... conloca doctor --live # add CONLOCA_ENDPOINT=https://... when the config computes endpoint
19
- conloca doctor # offline: config, token, endpoint, inert options
17
+ npx @conloca/cli connect # in the site's folder; add --yes when no terminal can answer
20
18
  ```
21
19
 
22
- This package's checks are `CC1`–`CC8`. Offline: the wiring, the build token, the endpoint and public base URL,
23
- `conlocaCMS` options the endpoint's editor ignores, and (CC8) whether a static project keeps the preview build off. With
24
- `--live` (the token goes only to the configured endpoint): the endpoint answers the token, a registration serves this
25
- branch and site, and the editor bundle that registration names is still deployed.
26
-
27
- ## The one secret: the build token
28
-
29
- `CONLOCA_BUILD_TOKEN=cbt_<id>.<secret>` is issued by the endpoint and set as a CI secret. It authenticates the build —
30
- no other setup, no OIDC. Repository identity comes from CI metadata (`GITHUB_REPOSITORY`, Vercel, GitLab) or the git
31
- remote; `repoUri` is only for non-standard checkouts. The `endpoint` is an https URL with no trailing slash.
32
-
33
- **Whole-line gotcha:** the endpoint shows and copies the token as the line `CONLOCA_BUILD_TOKEN=cbt_…`. Pasted whole
34
- into a secret's value, doctor CC2 reports it and the build's registration answers `401`; the token is fine — store only
35
- the part from `cbt_`.
36
-
37
- **Rotation gotcha:** creating a new token invalidates the old one. A `401` from the endpoint for a value that does start
38
- with `cbt_` (doctor CC5) means the CI secret still holds a rotated token — create a new one and update the secret.
39
-
40
- ## The pipeline: build → register → editor
20
+ `connect` installs the packages, wires `astro.config` (writing `repoUri` from a GitHub `origin`), writes the site's host
21
+ into `sites.json`, adds a framing rule only where a committed header file forbids framing, builds once to check the
22
+ editor page, and removes old build key lines from workflows. It shows diffs first, keeps values you set (`differs`), and
23
+ exits `2` with the lines to add when a step needs a person (`--site-url https://…` when `astro.config` has no `site`).
24
+ It never commits, pushes or deploys: commit, push to the default branch, deploy as usual, then open the workspace
25
+ editor. Editing needs the deployed site; before that, `astro dev` serves the local editor at `/__cms`. Package updates
26
+ go through `npx @conloca/cli@latest upgrade` (or the exact version a Conloca prompt gave), never by editing `@conloca/*`
27
+ versions.
41
28
 
42
- 1. `astro build` with the token compiles `dist/_conloca/editor-bundle.<hash>.js` and POSTs a registration naming the
43
- repo, git sha, branch, site id, and the bundle URL + hash.
44
- 2. The editor at `endpoint`, opened on a branch, loads the NEWEST registration for `(branch, site)`.
45
- 3. A build without a prerequisite (token, repo identity, sha/branch, public base URL) does not register; it warns and
46
- ends with a summary block. Set `requireRegistration: true` in CI to fail such builds. A registration the endpoint
47
- REJECTS always fails the build.
48
-
49
- ## Three states of a branch (doctor CC6)
50
-
51
- - **Own registration** — the branch was built with the token; the editor loads its bundle.
52
- - **Inherited** — no registration for this branch, but the default branch has one: the editor works from that bundle and
53
- draft preview is degraded. Build the branch with the token to register it.
54
- - **None** — neither: the editor will not load for this branch. Build it with the token.
55
-
56
- Doctor may also report older registrations that are not active yet. They become active the next time the editor opens,
57
- so a branch served only by them is a warning rather than "will not load" — it fails only if that branch has since grown
58
- a second site.
59
-
60
- ## A deleted bundle (CC7)
29
+ ## First move: `conloca doctor --live`
61
30
 
62
- A registration can outlive its bytes: a later deploy from another branch replaces `dist/`, and the registration still
63
- points at a bundle URL that now 404s. Nothing else notices — the editor just fails to load. `conloca doctor --live`
64
- probes the bundle URL the registration names and says so: rebuild and deploy from that branch.
31
+ For any question about the workspace editor — "Connect this site" stays, the frame stays blank, old components after a
32
+ deploy — run this before reading source:
65
33
 
66
- ## Options with no effect on the endpoint's editor
34
+ ```bash
35
+ conloca doctor --live # sends no credential: only your site's host and the editor's /host/protocols.json
36
+ conloca doctor # offline: wiring, sites.json host, committed framing headers, key leftovers
37
+ ```
67
38
 
68
- `conlocaCMS`'s `editorStyles` and `editorCSS` configure the local dev editor only. `templates`, `schemasPath`, and
69
- `mdxComponentFolders` reach the endpoint's editor automatically.
39
+ This package's checks are `CC1` and `CC8`–`CC24`:
40
+
41
+ - **CC9** — `sites.json`: the site named `default` (or the only one) has a bare host in `domains[defaultLocale]` and a
42
+ valid `base`. The editor opens `https://<host><base>_conloca/editor/`; it refuses IPs, `localhost`, `*.conloca.com`.
43
+ - **CC10** — a committed `public/_headers`, `netlify.toml` or `vercel.json` sets `X-Frame-Options` or `frame-ancestors`
44
+ site-wide with no `/_conloca/editor/` rule. Fix: `connect`, or the rule the error prints.
45
+ - **CC11** (live) — `conloca.json` is deployed, public, and names this repository and site. "names no repository" → set
46
+ `repoUri` in `conlocaCloud(...)`. Serving an older commit than HEAD is a warning: deploy.
47
+ - **CC12** (live) — the deployed page may be framed by `https://*.conloca.com`, and its `script-src` allows the editor's
48
+ origin. Headers from host settings or a proxy show up only here.
49
+ - **CC13** (live) — the page's protocol is in the editor's range; too old → rebuild with a newer `@conloca/cloud-astro`.
50
+ - **CC14** — a workflow or the config still names `CONLOCA_BUILD_TOKEN`, `buildToken`, `publicBaseUrl`, `previewDomain`
51
+ or `requireRegistration`. Remove them; nothing reads them for the editor page.
52
+ - **CC15–CC21** — draft previews on a static site: `wrangler.jsonc` on Cloudflare Workers, wrangler ≥ 4.36, the
53
+ dispatcher `main`, `run_worker_first` covering the preview route and every on-demand route, no deploy redirect into
54
+ `.conloca/preview-server`, a 404 page, middleware negotiation, no tag manager. Fix:
55
+ `npx @conloca/cli connect --update --yes`, then deploy. A `wrangler.toml` must be converted to `wrangler.jsonc` first.
56
+ - **CC22–CC23** — the preview rate-limit binding (`conlocaPreviewLimit`, 60 per 10 s, in every env block) on the Paid
57
+ plan, none on the Free plan, and the Cloudflare plan recorded in `package.json` (`conloca.cfPlan`). Fix:
58
+ `connect --update --yes`; for the plan, ask the site's owner which plan the Cloudflare account is on and run
59
+ `connect --yes --cf-plan paid` (or `free`). On Free with API routes, CC23 warns that previews and those routes share
60
+ one daily request quota; Cloudflare Workers Paid removes the limit.
61
+ - **CC24** (live) — a separate preview deploy's `conloca.json` answers as D4.
62
+
63
+ ## Framing: only when the site forbids it
64
+
65
+ A site sending no `X-Frame-Options` and no `frame-ancestors` needs nothing (GitHub Pages included). Otherwise
66
+ `/_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
68
+ detaches the site's headers on that path (`! X-Frame-Options`, `! Content-Security-Policy`); Netlify cannot detach;
69
+ Vercel uses `source: "/_conloca/editor/:path*"`. A site-wide CSP with `frame-ancestors` must be narrowed by hand — a
70
+ second policy cannot loosen it.
71
+
72
+ ## Components come from the branch's deploy
73
+
74
+ On other branches the editor offers the components of the deploy whose code is closest to the branch's latest commit:
75
+ the branch's own deploy, the default branch's, or a build of the branch it was created from (labelled in the editor), on
76
+ a tie in that order, with a warning when the components may differ from the branch's code. Doctor's CC11 warning still
77
+ says which commit is live.