@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
package/README.md CHANGED
@@ -1,42 +1,54 @@
1
1
  # `@conloca/cloud-astro`
2
2
 
3
- Astro integration that connects a Conloca CMS site to an editor endpoint. Add it to the site's `astro.config.mjs` next
4
- to `conlocaCMS` to:
5
-
6
- 1. Compile the site's Puck config into a single editor bundle under `_conloca/` in the build output
7
- (react/react-dom/jsx-runtime/`@puckeditor/core` stay external — the editor supplies them at runtime) and register the
8
- build at `endpoint`, so the editor there loads this build's bundle for the branch it was built from.
9
- 2. Run a recursive preview build that emits SSR routes for draft content.
10
- 3. Wire preview SSR middleware that checks `/conloca_preview_<secret>/*` requests against the endpoint's token issuer
11
- and serves draft pages.
3
+ Astro integration that adds the editor page for Conloca's workspace editor to a site's build. Add it to the site's
4
+ `astro.config.mjs` next to `conlocaCMS` to:
5
+
6
+ 1. Write the editor page to `/_conloca/editor/` in every build: the site's Puck config compiled into one bundle
7
+ (react/react-dom/jsx-runtime/`@puckeditor/core` stay external — the workspace editor supplies them at runtime), its
8
+ styles, the MDX sandbox frame and `conloca.json`. The page carries no credential.
9
+ 2. When `previewBuild` is given as an object, build the preview server that renders drafts: next to a static site on
10
+ Cloudflare Workers (under `/_conloca/preview/<branch>/`), on the site's own server deploy, or as a separate deploy.
11
+ 3. Wire preview middleware that admits only passes signed by the endpoint, for the repository, site and branch the
12
+ preview build was made from.
12
13
  4. Expose `PreviewContentAPI` for `.astro` pages to fetch draft content.
14
+ 5. Show share links: a viewer sees who shared the draft and when the link expires; an expired, turned-off, published or
15
+ discarded link shows its own page.
13
16
 
14
- Items 2 to 4 serve draft previews, which are not available on your own deployment yet. The setup below keeps them off
15
- with `previewBuild: false` (see [Draft previews](#draft-previews)).
17
+ Items 2 to 5 stay off unless `previewBuild` is given as an object (see [Draft previews](#draft-previews)).
16
18
 
17
19
  ## Setup
18
20
 
19
21
  Before you start you need:
20
22
 
21
- - An Astro site that already runs `@conloca/astro-cms` (its README covers that), in a GitHub repository.
22
- - The repository connected to the editor at `endpoint`: sign in there with **Continue with GitHub**, choose **Connect
23
- GitHub**, and pick the repository on GitHub's installation screen. If a GitHub organization owns the repository and
24
- you are not one of its owners, an owner has to approve the installation; until then the editor shows **Waiting for
25
- approval**.
26
- - An owner or admin role in the editor's workspace: only they can create the build token in step 3. Whoever sets the
27
- workspace up becomes its first owner.
23
+ - An Astro site in a GitHub repository.
24
+ - The repository connected to your workspace editor at `<slug>.conloca.com`: sign in there with **Continue with
25
+ GitHub**, choose **Connect GitHub**, and pick the repository on GitHub's installation screen. If a GitHub organization
26
+ owns the repository and you are not one of its owners, an owner has to approve the installation; until then the editor
27
+ shows **Waiting for approval**.
28
+ - A place the site is deployed to, at an address visitors reach without signing in. The workspace editor edits the
29
+ deployed site: it opens the editor page your build adds under `/_conloca/editor/`, so editing starts after the first
30
+ deploy. For editing before that, `astro dev` keeps the local editor at `/__cms`.
28
31
 
29
- ### 1. Install
32
+ ### 1. Run `conloca connect`
33
+
34
+ In the site's folder, or the repository holding it:
30
35
 
31
36
  ```sh
32
- bun add @conloca/cloud-astro
37
+ npx @conloca/cli connect
33
38
  ```
34
39
 
35
- It needs Astro 7.3.1 or a later 7.x release, and `@conloca/astro-cms` at its own version: the `@conloca/*` packages are
36
- released together, so keep them on one version and update them together. Its other peers (`@astrojs/react`, `vite`) are
37
- already in a site that runs `@conloca/astro-cms`.
40
+ A coding agent can do the whole setup from one line:
41
+ `In my Astro site's folder, run npx @conloca/cli@<version> connect, then commit, push and deploy.`
42
+
43
+ `connect` adds `@conloca/astro-cms`, `@conloca/cloud-astro`, `@astrojs/react` and `@vitejs/plugin-react` with the
44
+ package manager of the nearest lockfile, wires `astro.config`, writes the site's host into `sites.json` (step 2), adds a
45
+ framing rule only where a committed header file forbids framing (step 3), builds the site once to check that the editor
46
+ page is there, and removes old build key lines from workflows. Every change is shown as a diff first: in a terminal it
47
+ asks once, `--yes` accepts without asking, and `--dry-run` writes nothing. A value you set yourself is kept and reported
48
+ as `differs`. It exits `2` with the lines to add when a step needs you, such as a config that is not a plain
49
+ `defineConfig({ integrations: [...] })`. `npx @conloca/cli connect --help` lists every option.
38
50
 
39
- ### 2. Add it next to `conlocaCMS`
51
+ The config it wires:
40
52
 
41
53
  ```js
42
54
  // astro.config.mjs
@@ -46,6 +58,7 @@ import { conlocaCloud } from '@conloca/cloud-astro';
46
58
  import { defineConfig } from 'astro/config';
47
59
 
48
60
  export default defineConfig({
61
+ site: 'https://www.example.com',
49
62
  // Keep your existing settings (output, adapter, ...) as they are.
50
63
  integrations: [
51
64
  react(),
@@ -54,124 +67,127 @@ export default defineConfig({
54
67
  puckConfigPath: './src/puck.config.tsx',
55
68
  layout: './src/layouts/Layout.astro',
56
69
  }),
57
- conlocaCloud({
58
- endpoint: 'https://cms.example.com',
59
- puckConfigPath: './src/puck.config.tsx',
60
- publicBaseUrl: 'https://www.example.com',
61
- previewBuild: false,
62
- }),
70
+ conlocaCloud({ repoUri: 'your-org/your-site' }),
63
71
  ],
64
72
  });
65
73
  ```
66
74
 
75
+ - `conlocaCloud()` needs no options. It takes `puckConfigPath` and `siteStyles` from `conlocaCMS`, and builds for the
76
+ workspace editor at `https://app.conloca.com` (`endpoint`'s default).
77
+ - `connect` writes `repoUri` when the checkout's `origin` is on GitHub, so the editor page names its repository even
78
+ where the build has no git remote. Without it, the build reads the repository from GitHub Actions, Vercel or GitLab,
79
+ else from the checkout's `remote.origin.url`.
67
80
  - `conlocaCloud` is an add-on to `conlocaCMS`, not a replacement: keep both, with `react()` first. Doctor reports a
68
81
  config without `conlocaCMS` as an error.
69
- - `endpoint` is only the scheme and host of the address you open the editor at, such as `https://cms.example.com`. Leave
70
- out any path the browser's address bar shows after the host, and the trailing slash.
71
- - `puckConfigPath` is the value you already gave `conlocaCMS`. If your `conlocaCMS` options also set `siteStyles` or
72
- `fragmentPreviewRoute`, give `conlocaCloud` the same values, so the editor renders your pages with your site's styles.
73
- - `publicBaseUrl` is the address your deployed site is served from: the editor loads this build's editor files from
74
- there. The integration does **not** read Astro's `site` option, so set `publicBaseUrl` even when `site` holds the same
75
- address. Its only fallback is `CF_PAGES_URL`, which Cloudflare Pages sets when it runs the build itself. Without
76
- either, the build succeeds but does not register, and the editor never updates.
77
- - `previewBuild: false` keeps off the second build, the one that serves draft previews. Draft previews on your own
78
- deployment are not available yet, so keep this line: without it, every build that registers also runs that second
79
- build, which fails on a static site that has no SSR adapter.
80
-
81
- ### 3. Give the build a token
82
-
83
- In the editor at `endpoint`, open the account menu (the round button with your initial), choose **Workspace settings**,
84
- and go to **Build token**. The **Connect this site** screen of a site that has no build yet shows the same section.
85
- Choose **Create build token**. The token is shown once, as the line `CONLOCA_BUILD_TOKEN=cbt_…`, and **Copy environment
86
- variable** copies that whole line. Store it wherever `astro build` runs:
87
-
88
- - Where the name and the value are separate fields — a GitHub Actions secret, a Cloudflare Pages variable, most hosts'
89
- settings — the name is `CONLOCA_BUILD_TOKEN` and the value is **only** the part after `CONLOCA_BUILD_TOKEN=`, starting
90
- with `cbt_`. Do not paste the whole copied line as the value.
91
- - Where the input takes `NAME=value` lines, like a `.env` file, paste the whole line.
92
-
93
- Give the secret only to the steps that need it: `conloca doctor` and the build (see the
94
- [CI example](#ci-example-github-actions)), not to install scripts or deploy actions. Never write it into the config:
95
- doctor warns when `buildToken` is committed.
96
-
97
- One token serves the whole workspace. **Replace build token** creates a new one, and the old one stops working at once,
98
- so update every place that holds it.
99
-
100
- No Conloca-specific GitHub Action or OIDC setup is required. GitHub Actions, Vercel and GitLab provide the repository
101
- automatically; elsewhere the integration reads the checkout's `remote.origin.url`. Use `repoUri` only for a checkout
102
- where neither is available.
103
-
104
- A build without the token still succeeds; it only skips registration (see
105
- [When registration is skipped](#when-registration-is-skipped)). Once your CI is wired, set `requireRegistration: true`
106
- so a deploy can never silently leave the editor behind.
107
-
108
- ### 4. Push, then build
109
-
110
- A build registers the exact commit it was built from, and the endpoint refuses a commit it has not received from GitHub
111
- yet. Push first, then build the pushed commit; a CI build that starts on push does this for you. A build of a commit the
112
- endpoint does not have retries for about two and a half minutes and then fails with an error that says the commit
113
- `is not ingested`. A local `astro build` of an unpushed commit with the token set fails the same way.
114
-
115
- If you also build pull requests on GitHub Actions, give `actions/checkout` the pull request's own commit
116
- (`ref: ${{ github.event.pull_request.head.sha || github.sha }}`). By default it checks out a merge commit that GitHub
117
- makes for the pull request and never pushes, so the endpoint never receives it and the registration fails.
118
-
119
- A pull-request build deployed somewhere other than `publicBaseUrl`, such as a host's preview deploy, must set
120
- `publicBaseUrl` to the address that build is served from, for example from your host's deploy-URL variable (a full
121
- `https://` address). The editor on that branch loads the build's editor files from `publicBaseUrl`, and your production
122
- site does not serve the files only a pull request's build produced, so the editor would report that the bundle could not
123
- be loaded or verified.
124
-
125
- ### 5. Deploy, and serve `/_conloca/*` cross-origin
126
-
127
- The build writes the editor files under `_conloca/` in its output: `dist/_conloca/` for a static site, or the client
128
- folder such as `dist/client/_conloca/` for a server-rendered one. Deploy the build the way you already do, to the
129
- `publicBaseUrl` address.
130
-
131
- The editor runs on another origin and fetches those files from your site, so every `/_conloca/*` response must be public
132
- and carry `Access-Control-Allow-Origin: *`. Without the header the editor reports that this build's editor bundle could
133
- not be loaded or verified, and rebuilding does not help.
134
-
135
- The build writes that rule to a `_headers` file next to `_conloca/` (`dist/_headers`, or `dist/client/_headers` for a
136
- server-rendered site): one rule for `/_conloca/*`, plus one for each folder of fonts and images your site styles
137
- reference.
138
-
139
- - **Cloudflare Pages and Netlify** apply `_headers` themselves. Nothing else to do.
140
- - **Everywhere else**, `_headers` is ignored — including a Node server built with `@astrojs/node`, which has no setting
141
- for headers on static files. Set the header for every path the generated `_headers` lists, in whatever serves the
142
- site. A site made by `conloca create` is such a Node server: add the header in a proxy in front of it, or switch the
143
- site to static output (remove `output: 'server'` and the adapter from `astro.config.mjs`) and deploy it to Cloudflare
144
- Pages or Netlify. With Caddy in front of the Node server:
145
-
146
- ```caddyfile
147
- www.example.com {
148
- header /_conloca/* Access-Control-Allow-Origin *
149
- reverse_proxy localhost:4321
150
- }
82
+ - Nothing changes `output` or adds an adapter: a static site stays static.
83
+
84
+ By hand: on a site without `conlocaCMS`, run `npx @conloca/cli astro setup` first. Then
85
+ `bun add @conloca/astro-cms @conloca/cloud-astro` (plus the React peers), add `conlocaCloud()` right after
86
+ `conlocaCMS(...)`, and follow steps 2 and 3. `@conloca/cloud-astro` needs Astro 7.3.1 or a later 7.x release, and a
87
+ matching `@conloca/astro-cms`: each `@conloca/*` package has its own version, so use `conloca upgrade` to move them to
88
+ the versions one CLI release pins.
89
+
90
+ ### 2. Your site's host in `sites.json`
91
+
92
+ The workspace editor opens `https://<host><base>_conloca/editor/`. `<host>` is `domains[defaultLocale]` of the site
93
+ named `default` in `sites.json` (or of the only site), and `<base>` is that site's `base`, `/` when unset:
94
+
95
+ ```json
96
+ "default": {
97
+ "locales": ["en"],
98
+ "defaultLocale": "en",
99
+ "domains": { "en": "www.example.com" }
100
+ }
101
+ ```
102
+
103
+ - `connect` writes `domains` from Astro's `site`, and `base` from Astro's `base` when it is not `/`. When `astro.config`
104
+ sets no plain `site`, pass the address: `npx @conloca/cli connect --site-url https://www.example.com`. `connect` never
105
+ writes Astro's `site` itself, since that changes canonical URLs and sitemaps.
106
+ - The host is a bare host such as `www.example.com`: no scheme, port or path. The editor never opens an IP address,
107
+ `localhost` or a host under `conloca.com`.
108
+ - Use the address visitors reach. A deploy that asks visitors to sign in, such as a Vercel preview behind Deployment
109
+ Protection, cannot be opened by the editor.
110
+
111
+ ### 3. Framing headers, only if your site forbids framing
112
+
113
+ The workspace editor shows `/_conloca/editor/` in a frame. A site that sends no `X-Frame-Options` and no
114
+ `frame-ancestors` can already be framed, so there is nothing to do; GitHub Pages sends neither. When a committed
115
+ `public/_headers`, `netlify.toml` or `vercel.json` sets one of them for the whole site, `connect` adds a rule for
116
+ `/_conloca/editor/`, and until one exists the build warns and `conloca doctor` reports CC10. The rules:
117
+
118
+ - **Cloudflare Pages and Cloudflare Workers static assets**, in `public/_headers` after any site-wide `/*` rule:
119
+
120
+ ```plain
121
+ /_conloca/editor/*
122
+ ! X-Frame-Options
123
+ ! Content-Security-Policy
124
+ Content-Security-Policy: frame-ancestors 'self' https://*.conloca.com
125
+
126
+ /_conloca/editor/sandbox-frame.html
127
+ Content-Security-Policy: sandbox allow-scripts
151
128
  ```
152
129
 
153
- With nginx in front of it:
130
+ `! Name` removes a header an earlier rule set. The site's own policy has to come off this path: two policies are both
131
+ enforced, and the editor page carries its own.
132
+
133
+ - **Netlify**, in `public/_headers`. Netlify cannot remove a header, so the rule only adds the policy; a site-wide
134
+ `X-Frame-Options` is then ignored by browsers, because `frame-ancestors` wins:
135
+
136
+ ```plain
137
+ /_conloca/editor/*
138
+ Content-Security-Policy: frame-ancestors 'self' https://*.conloca.com
139
+
140
+ /_conloca/editor/sandbox-frame.html
141
+ Content-Security-Policy: sandbox allow-scripts
142
+ ```
154
143
 
155
- ```nginx
156
- location /_conloca/ {
157
- add_header Access-Control-Allow-Origin * always;
158
- proxy_pass http://127.0.0.1:4321;
159
- }
144
+ - **Vercel**, in the `headers` list of `vercel.json`:
145
+
146
+ ```json
147
+ [
148
+ {
149
+ "source": "/_conloca/editor/:path*",
150
+ "headers": [{ "key": "Content-Security-Policy", "value": "frame-ancestors 'self' https://*.conloca.com" }]
151
+ },
152
+ {
153
+ "source": "/_conloca/editor/sandbox-frame.html",
154
+ "headers": [{ "key": "Content-Security-Policy", "value": "sandbox allow-scripts" }]
155
+ }
156
+ ]
160
157
  ```
161
158
 
162
- If nginx serves the files itself, keep your `root` or `try_files` lines in that `location` instead of `proxy_pass`. A
163
- `location` with its own `add_header` drops the ones it would inherit from the `server` block, so repeat any you rely
164
- on.
159
+ - **A site-wide `Content-Security-Policy` with `frame-ancestors`**, on any host: a second policy cannot loosen it.
160
+ Narrow it yourself so it does not cover `/_conloca/editor/`, then add the rule above. `connect` reports this case
161
+ instead of editing a policy.
162
+ - **Headers set in host settings or by a server**, such as a proxy in front of an `@astrojs/node` server: exempt
163
+ `/_conloca/editor/` there the same way. `connect` cannot see them; `conloca doctor --live` reads the deployed page's
164
+ real headers (CC12).
165
165
 
166
- Check it after the deploy, with the file name from the build log line
167
- `editor bundle written: /_conloca/editor-bundle.<hash>.js`:
166
+ ### 4. Commit, push and deploy
168
167
 
169
- ```sh
170
- curl -sI -H 'Origin: https://cms.example.com' https://www.example.com/_conloca/editor-bundle.<hash>.js
171
- ```
168
+ `connect` never commits, pushes or deploys. Commit its changes, push to the default branch, and deploy the way you
169
+ always do. The build writes the editor page under `_conloca/editor/` in its output (`dist/_conloca/editor/` for a static
170
+ site, the client folder such as `dist/client/_conloca/editor/` for a server-rendered one) and logs
171
+ `editor page written: /_conloca/editor/`. It needs no secret and no environment variable.
172
+
173
+ On the default branch the workspace editor uses the components of the default branch's deploy. On any other branch it
174
+ uses the deploy whose code is closest to the branch's latest commit, among the branch's own deploys, the default
175
+ branch's and a build of the branch it was created from (on a tie, in that order), and the editor says which; see
176
+ [Branch deploys](#branch-deploys).
177
+
178
+ `/_conloca/editor/conloca.json` publishes the repository's name, the build's branch and commit, and whether the build
179
+ serves draft previews with the preview protocol it speaks (`preview`: `{ "mode": "d3", "protocol": 2 }` for a static
180
+ site with `previewBuild`, `d2` with an adapter, `d4` with `separate: true`, else `off`). If the repository is not
181
+ public, its name becomes public with the deploy. Protocol 2 opens a preview with a single-use `conloca_code` link that
182
+ the preview server trades for the pass with Conloca; a link that carries the pass itself (`conloca_preview`, protocol 1)
183
+ still opens in this release and stops opening in the next.
184
+
185
+ `conloca.json` also lists the build's prerendered page routes (`routes`, at most 500 and within 16 KiB for the whole
186
+ file), which the workspace editor offers when a site has no Conloca pages yet; they are public with the deploy, like the
187
+ pages themselves.
172
188
 
173
- The answer must be `200` and include `access-control-allow-origin: *`. `conloca doctor --live` checks that the file is
174
- deployed, not this header.
189
+ `/_conloca/editor/data-schemas.json` publishes the JSON schema of each `dataSchemas` collection, the metadata the
190
+ editor's entry forms already use, so agents can write data entries that match.
175
191
 
176
192
  ### CI example (GitHub Actions)
177
193
 
@@ -190,75 +206,140 @@ jobs:
190
206
  - uses: actions/checkout@v4
191
207
  - uses: oven-sh/setup-bun@v2
192
208
  - run: bun install --frozen-lockfile
193
- # The token goes to doctor and the build only, not to install scripts or the deploy.
194
209
  - run: bunx @conloca/cli doctor
195
- env:
196
- CONLOCA_BUILD_TOKEN: ${{ secrets.CONLOCA_BUILD_TOKEN }}
197
210
  - run: bun run build
198
- env:
199
- CONLOCA_BUILD_TOKEN: ${{ secrets.CONLOCA_BUILD_TOKEN }}
200
211
  # Deploy the build the way you already do.
201
212
  ```
202
213
 
214
+ ### Branch deploys
215
+
216
+ On a branch other than the default one, the editor looks for that branch's own build: through the host's records on
217
+ GitHub (deployments, commit statuses, Cloudflare check runs) or its branch address. The deploy must be public for the
218
+ editor to frame it. Reading the records needs Conloca's GitHub App to have **Deployments**, **Commit statuses** and
219
+ **Checks** read access; an organization owner accepts that update on GitHub. Until then only the records go unread: a
220
+ Cloudflare Pages branch address still works. When no build of the branch is found, the editor uses an earlier build from
221
+ the branch's history (labelled as such), else the default branch's deploy, and says so.
222
+
223
+ | Host | Works when | By default | Found through |
224
+ | -------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------- |
225
+ | Cloudflare Pages | previews public (Access off) and branch builds not excluded | **works** | check-run summary (needs permissions) or branch address (no permission) |
226
+ | Netlify | an open pull request from the same repository; previews public | PR deploy previews only, through commit statuses (needs permissions). Branch deploys are off; credit-based plans can make previews private | commit statuses (needs permissions) |
227
+ | Vercel | Deployment Protection off for previews | **protected**: the editor uses the default branch's deploy. Protection has been on by default since 2023-11 | Deployment (needs permissions) |
228
+ | Cloudflare Workers Builds | previews enabled, an open pull request from the same repository, preview URL on Cloudflare's own preview domain | PR only | bot PR comment (needs permissions) |
229
+ | Render | PR previews enabled | off (manual trigger by default) | Deployment created by a person (needs permissions) |
230
+ | S3, your own server or other static hosting with a public address per branch | an opt-in Actions job that posts a Deployment **on push**, for the built commit | the default branch's deploy | Deployment by `github-actions` |
231
+ | GitHub Pages (no per-branch deploys), Amplify, Cloudflare Workers Previews on custom domains | — | the default branch's deploy | not supported |
232
+
233
+ **Cloudflare Pages not connected to a Git repository** (`wrangler pages deploy`): set `CONLOCA_PAGES_PROJECT` to the
234
+ first label of the site's `pages.dev` address (`my-site-4k2` for `my-site-4k2.pages.dev`) in the production build's
235
+ environment, so branch addresses are found. Use the address label, not the project name you gave `wrangler`: when that
236
+ name is taken, Cloudflare adds a suffix to the address, and setting the project name then silently finds no branch
237
+ address.
238
+
239
+ When two branch names clean up to the same Cloudflare Pages branch address, Pages gives the second one a random suffix.
240
+ The editor can't predict that address, so that branch shows the default branch's components unless its deploy is also
241
+ reported to GitHub (the Deployment step below).
242
+
243
+ **Vercel:** Deployment Protection has been on for previews by default since 2023-11. Turn it off for previews to let the
244
+ editor frame them, knowing that anyone with a preview URL can then see it.
245
+
246
+ **Any other host:** the editor frames a branch build at its own address with the site's production base, so a preview
247
+ under a subpath of one site can't work. Publish each branch build at its own public address (a second host or bucket
248
+ works), then add a step that posts a GitHub Deployment for the built commit, on `push`, with `GITHUB_TOKEN` and no other
249
+ secret:
250
+
251
+ ```yaml
252
+ on: push
253
+ permissions:
254
+ contents: read
255
+ deployments: write
256
+ jobs:
257
+ deploy:
258
+ runs-on: ubuntu-latest
259
+ steps:
260
+ # … your build and deploy steps; the step with id `deploy` outputs `url` (https)
261
+ - uses: actions/github-script@v7
262
+ env:
263
+ PREVIEW_URL: ${{ steps.deploy.outputs.url }}
264
+ with:
265
+ script: |
266
+ const { owner, repo } = context.repo;
267
+ const { data } = await github.rest.repos.createDeployment({
268
+ owner, repo, ref: context.sha, environment: `preview/${context.ref_name}`,
269
+ auto_merge: false, required_contexts: [],
270
+ });
271
+ await github.rest.repos.createDeploymentStatus({
272
+ owner, repo, deployment_id: data.id, state: 'success', environment_url: process.env.PREVIEW_URL,
273
+ });
274
+ ```
275
+
276
+ A `pull_request` build checks out a merge commit, which never matches the branch's commit: build on `push`, or check out
277
+ `github.event.pull_request.head.sha` and pass that commit as `ref` instead of `context.sha`.
278
+
203
279
  ### Check it
204
280
 
205
- After the deploy finishes, run this in your repository, on the branch you built:
281
+ After the deploy finishes, run this in your repository:
206
282
 
207
283
  ```sh
208
- CONLOCA_BUILD_TOKEN=cbt_... bunx @conloca/cli doctor --live
284
+ npx @conloca/cli doctor --live
209
285
  ```
210
286
 
211
- `--live` asks the endpoint what it knows about this repository: whether it accepts the token, which commit registered
212
- the editor for this branch and site and which version of this package built it, and whether that editor bundle is still
213
- deployed. The token goes only to the `endpoint` in your config. If you did not keep a copy of the token, skip this step
214
- rather than replacing the token (that stops the CI secret working at once); reloading the editor is enough.
287
+ `--live` reads the deployed `<host><base>_conloca/editor/conloca.json` and the page's headers, and the protocol range
288
+ the editor publishes at `https://app.conloca.com/host/protocols.json`, and judges them by the same rules the workspace
289
+ editor applies. It sends no credential, so it runs anywhere, pull requests from forks included.
215
290
 
216
- Then reload the editor: it opens your site instead of **Connect this site**, and the **Build registration** row under
217
- **Workspace settings → Build token** turns from **Waiting for Astro build** to **Connected**.
291
+ Then open your workspace editor at `<slug>.conloca.com`. Until the editor page is live, **Connect this site** lists the
292
+ steps the site still needs: each row says what is done, whom it waits on, or what failed and how to fix it.
218
293
 
219
294
  ### Troubleshooting
220
295
 
221
- - **The build log ends with `editor at … NOT updated by this build`.** Prerequisites were missing, and each `missing:`
222
- line names one: `public base URL` means `publicBaseUrl` is not set (step 2), `build token` means the
223
- `CONLOCA_BUILD_TOKEN` secret does not reach the build (step 3). See
224
- [When registration is skipped](#when-registration-is-skipped).
225
- - **Doctor says the build token value starts with `"CONLOCA_BUILD_TOKEN="`, or the build fails with
226
- `registration rejected: HTTP 401` and the secret holds the whole copied line.** Change the value to the part starting
227
- with `cbt_` and rebuild. The token itself is fine; you do not need a new one.
228
- - **`registration rejected: HTTP 401` with a `cbt_…` value.** The token was replaced, which invalidates the old one at
229
- once. Put the new token in the `CONLOCA_BUILD_TOKEN` secret everywhere the site builds, then rebuild.
230
- - **The build fails with an error that says the commit `is not ingested`.** It built a commit the endpoint has not
231
- received. Push the commit, then rebuild (step 4).
232
- - **`registration rejected: HTTP 403` saying the repository is not covered by the workspace's GitHub installation.** Add
233
- the repository to that installation in your GitHub settings, then rebuild.
234
- - **The build log shows `registration complete`, but the editor still shows Connect this site.** Wait for the deploy to
235
- finish, then reload the editor.
236
- - **The editor says the editor bundle could not be loaded or verified.** `/_conloca/*` lacks the cross-origin header,
237
- `publicBaseUrl` does not serve this build's files, or the deploy has not finished (step 5).
296
+ Doctor names each check; the checklist in the workspace editor reports the same causes.
297
+
298
+ - **`sites.json` has no `domains` for the default locale, or not a bare host** (CC9). Run `connect`, or add your site's
299
+ host there (step 2). A host under `conloca.com`, an IP address or `localhost` is refused.
300
+ - **A committed header file sets `X-Frame-Options` or `frame-ancestors` for the whole site** (CC10). Run `connect`, or
301
+ add the rule from step 3.
302
+ - **The address cannot be reached, or answers 5xx or 429** (CC11). The site is down or limiting requests: check that it
303
+ is deployed and serving, then try again later.
304
+ - **`conloca.json` is not deployed** (CC11). The address answers 404 or an HTML page: deploy the commit that adds
305
+ `conlocaCloud()`, and check that `domains` names the address it is deployed to.
306
+ - **The address asks visitors to sign in** (CC11), for example Vercel Deployment Protection. Put the public production
307
+ address in `sites.json`, or let visitors through.
308
+ - **The page names no repository** (CC11). The build could not read the git remote: set `repoUri` in `conlocaCloud(...)`
309
+ (`connect` writes it from a checkout with a GitHub `origin`).
310
+ - **The address serves another repository's editor page, or another site** (CC11). Check `domains` and `siteId` in
311
+ `sites.json`.
312
+ - **`conloca.json` is not one the editor can read** (CC11). The host changed the built file; serve it unchanged.
313
+ - **The page is serving an older commit than your checkout** (CC11, a warning). Deploy to see your latest components.
314
+ - **The deployed page sends `X-Frame-Options`, or a `frame-ancestors` that leaves out `https://*.conloca.com`** (CC12).
315
+ Run `connect` again, or exempt `/_conloca/editor/` in your host settings (step 3).
316
+ - **The deployed page sends a `script-src` that does not allow `https://app.conloca.com`** (CC12). The page cannot load
317
+ the editor, and the workspace editor stops waiting for it. Detach the site's policy on `/_conloca/editor/` (step 3),
318
+ or add `https://app.conloca.com` to its `script-src` there.
319
+ - **The page's protocol is outside the range the editor speaks** (CC13). Rebuild with a newer `@conloca/cloud-astro` and
320
+ deploy; if the page is newer than the editor, the editor does not speak that version yet.
321
+ - **A workflow or the config still names `CONLOCA_BUILD_TOKEN`, `buildToken`, `publicBaseUrl`, `previewDomain` or
322
+ `requireRegistration`** (CC14). The editor page needs none of them: remove those lines. `connect` removes the workflow
323
+ lines that only pass the key.
238
324
 
239
325
  ## Options
240
326
 
241
- | Name | Required | Description |
242
- | ---------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------ |
243
- | `endpoint` | yes | Editor endpoint, scheme and host only, e.g. `https://cms.example.com`: no path, no trailing slash. URL-shape validated. |
244
- | `puckConfigPath` | yes | Puck config entry to compile (same option name and value as in `@conloca/astro-cms`). |
245
- | `publicBaseUrl` | no | Where the deployed site is served; the editor loads the bundle from there. Astro's `site` is not read. Falls back to `CF_PAGES_URL`. |
246
- | `repoUri` | no | Advanced `owner/repo` override; normally detected from CI or the Git remote. |
247
- | `siteId` | no | Advanced site-id override for CMS-less builds; sites.json is authoritative. |
248
- | `buildToken` | no | Build token issued by the endpoint; use the `CONLOCA_BUILD_TOKEN` environment variable instead, so it is never committed. |
249
- | `siteStyles` | no | Site CSS compiled into the canvas stylesheet, as in `conlocaCMS`. |
250
- | `editorBundlePlugins` | no | esbuild plugins for the editor bundle, which is built outside Vite: pass e.g. the Typia transform your page schemas need. |
251
- | `fragmentPreviewRoute` | no | Content route for build-time style discovery, as in `conlocaCMS`. |
252
- | `previewDomain` | no | Dedicated preview domain. When set, switches to `preview-domain` mode and is used instead of `publicBaseUrl`. |
253
- | `previewBuild` | no | `PreviewBuildOptions` or `false`. On by default; set `false`, since draft previews on your own deployment are not available yet. |
254
- | `saasIssuer` | no | Draft previews only. JWT `iss` the preview middleware pins (the endpoint's token issuer). Baked in; else set at runtime. |
255
- | `requireRegistration` | no | Fail the build when registration is skipped for a missing prerequisite. Recommended in CI once setup is done. |
256
-
257
- The `conlocaCMS` options `schemasPath` and `mdxComponentFolders` reach the editor at `endpoint` automatically: the CMS
258
- publishes what it resolved and this integration compiles the schemas and the discovered MDX components into the editor
259
- bundle each build registers. The `conlocaCMS` options `editorStyles` and `editorCSS` have no effect on the editor at
260
- `endpoint` (they configure the local dev editor only); `templates` and the `routing` data bindings reach it through the
261
- same channel as `schemasPath`.
327
+ | Name | Required | Description |
328
+ | ---------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
329
+ | `endpoint` | no | The workspace editor's address, scheme and host only, no trailing slash; its host must start with `app.`. Defaults to `https://app.conloca.com`. |
330
+ | `puckConfigPath` | no | Puck config entry to compile. Defaults to the value `conlocaCMS` was given. |
331
+ | `repoUri` | no | Advanced `owner/repo` override; normally detected from CI or the Git remote. |
332
+ | `siteId` | no | Advanced site-id override for CMS-less builds; sites.json is authoritative. |
333
+ | `siteStyles` | no | Site CSS compiled into the canvas stylesheet, as in `conlocaCMS`. |
334
+ | `previewBuild` | no | `PreviewBuildOptions` or `false`. Off unless given as an object. See [Draft previews](#draft-previews). Refused under `@astrojs/vercel` and `@astrojs/netlify`. |
335
+ | `saasIssuer` | no | Draft previews only. Pins the JWT `iss` every pass must name; unset, passes are checked against the endpoint's keys alone. |
336
+
337
+ The `conlocaCMS` options `schemasPath`, `mdxComponentFolders`, `templates`, the `routing` data bindings, `editorStyles`
338
+ and `editorCSS` reach the editor page automatically: the CMS publishes what it resolved, and the editor page renders
339
+ your pages with them as the local editor at `/__cms` does.
340
+
341
+ `buildToken`, `requireRegistration`, `publicBaseUrl`, `previewDomain`, `editorBundlePlugins` and `fragmentPreviewRoute`
342
+ were removed: a config that still names one fails at load. Run `npx @conloca/cli connect` to update it.
262
343
 
263
344
  ## Public render path
264
345
 
@@ -268,49 +349,139 @@ they did before.
268
349
 
269
350
  ## Draft previews
270
351
 
271
- Draft previews on your own deployment are not available yet. Keep `previewBuild: false` in your config: the preview
272
- build stays off, and a build produces only your normal site.
352
+ The editor's Preview button opens the draft on your site. How depends on the site:
353
+
354
+ | Your site | `previewBuild` | Where drafts render |
355
+ | ---------------------------------------------------------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
356
+ | Static, deployed to Cloudflare Workers | `{}` | Next to the site: a dispatcher runs only on `/_conloca/preview/*` and your on-demand routes. Every other page stays a static file, and no visitor to it starts a Worker |
357
+ | Static, on another host, or on Cloudflare without a domain of your own | `{ separate: true }` | A separate preview deploy; its address goes in `sites.json` `previewUrl` |
358
+ | Server-rendered (`@astrojs/cloudflare`, `@astrojs/node`) | `{}` | Your own deploy |
359
+
360
+ ### Next to a static site on Cloudflare Workers
361
+
362
+ Install `@astrojs/cloudflare` and add `previewBuild: {}` to `conlocaCloud(...)`, then run `npx @conloca/cli connect`. It
363
+ asks once whether your account is on the Cloudflare Workers Paid plan (pass `--cf-plan free` or `--cf-plan paid` when no
364
+ one is at the terminal) and records the answer in `package.json` (`"conloca": { "cfPlan": "paid" }`). It writes
365
+ `wrangler.jsonc`; on the Paid plan it adds the `ratelimits` entry below (Wrangler 4.36 or newer), on the Free plan it
366
+ leaves it out:
367
+
368
+ ```jsonc
369
+ {
370
+ "main": ".conloca/dispatcher/index.mjs",
371
+ "compatibility_flags": ["nodejs_compat"],
372
+ "assets": {
373
+ "directory": "./dist",
374
+ "binding": "ASSETS",
375
+ "not_found_handling": "404-page",
376
+ "run_worker_first": ["/_conloca/preview", "/_conloca/preview/*"],
377
+ },
378
+ "ratelimits": [
379
+ { "name": "conlocaPreviewLimit", "namespace_id": "<chosen by connect>", "simple": { "limit": 60, "period": 10 } },
380
+ ],
381
+ }
382
+ ```
383
+
384
+ `run_worker_first` also lists every route the preview build renders on demand (API routes, Actions, and `/_image` for
385
+ draft images). Every build checks the list, and on the Paid plan the rate limit, and fails with "run
386
+ `conloca connect --update --yes`" when one is missing, so an API route can never silently 404 in production. A
387
+ `wrangler.toml` can't carry these settings: convert it to `wrangler.jsonc` first. Keep `main` and `assets` out of
388
+ `env.<name>` blocks; both are inherited from the top level. To try previews locally, run
389
+ `wrangler dev --local-protocol https`: Safari refuses the preview's `Secure` cookies on plain-http `localhost`.
273
390
 
274
- ## When registration is skipped
391
+ A static site can't hold an on-demand route itself: Astro refuses `export const prerender = false` without an adapter,
392
+ and an adapter would make the site preview from its own server deploy instead. Add such a route to the preview build
393
+ only, which runs with `CONLOCA_PREVIEW_BUILD=1`: the dispatcher then serves it next to the static site, and the build
394
+ reports it for `run_worker_first`. Keep its file outside `src/pages`:
275
395
 
276
- A build that lacks a prerequisite — no `CONLOCA_BUILD_TOKEN`, no repository identity, no git sha/branch, or no public
277
- base URL — completes without registering and ends with one summary block, with a `missing:` line for each prerequisite
278
- it lacks:
396
+ ```js
397
+ export default defineConfig({
398
+ integrations: [
399
+ // ...conlocaCMS(...), conlocaCloud({ previewBuild: {} }),
400
+ ...(process.env.CONLOCA_PREVIEW_BUILD === '1'
401
+ ? [
402
+ {
403
+ name: 'preview-only-routes',
404
+ hooks: {
405
+ 'astro:config:setup': ({ injectRoute }) =>
406
+ injectRoute({ pattern: '/api/ping', entrypoint: './src/api/ping.ts', prerender: false }),
407
+ },
408
+ },
409
+ ]
410
+ : []),
411
+ ],
412
+ });
413
+ ```
279
414
 
280
- ```plain
281
- [@conloca/cloud-astro] editor at https://cms.example.com NOT updated by this build
282
- missing: build token (set buildToken or CONLOCA_BUILD_TOKEN)
283
- consequence: registration was skipped, so the editor keeps serving the previous build of this branch (or the default branch's, or nothing, if neither was ever registered)
284
- check: conloca doctor --live
415
+ If the preview build fails and `run_worker_first` lists only the two preview entries, the site still builds and deploys,
416
+ and `/_conloca/preview/` answers "Preview couldn't load the draft". If it also lists your on-demand routes, or
417
+ `not_found_handling` is `"none"`, the build fails instead: the preview server is what serves those routes, and shipping
418
+ without it would break them.
419
+
420
+ On the Cloudflare Workers Paid plan the dispatcher limits each visitor to 60 requests under `/_conloca/preview/` per 10
421
+ seconds (the `ratelimits` binding, counted per Cloudflare location and approximately) and answers "Too many preview
422
+ requests — try again in a few seconds" over it. On the Free plan there is no limit: a blocked request would still count
423
+ against the day's requests, so a limit adds nothing there. A flood can then use up the day's requests and pause preview
424
+ until 00:00 UTC, but never the published pages, which don't run the dispatcher. A site with on-demand routes (API
425
+ routes, `/mcp`) still previews next to itself on the Free plan, since those routes need the dispatcher too, and
426
+ `conloca connect` and doctor (CC23) warn that previews and those routes share one daily request quota: a flood of
427
+ preview requests can stop those routes until 00:00 UTC. Cloudflare Workers Paid removes the daily limit. A rate-limiting
428
+ rule on `/_conloca/preview/*` in the Cloudflare dashboard (Security → WAF) stops a flood before it reaches the
429
+ dispatcher; it is optional, and doctor doesn't check it.
430
+
431
+ Not suited to this mode: sites that navigate on the client (view transitions, `navigate()`), call same-origin APIs that
432
+ should see drafts, load third-party tags that must not see draft content, open same-origin pages from scripts
433
+ (`window.open` would let the opener read a draft), or register a service worker that handles navigations (it would see
434
+ draft pages, and could cache them or answer published ones). Use a separate preview deploy.
435
+
436
+ ### A separate preview deploy
437
+
438
+ Set `previewBuild: { separate: true }`. Your build then runs no preview build. Add a second deploy (for example a second
439
+ Cloudflare Workers Builds project) that builds with `CONLOCA_PREVIEW_BUILD=1 CLOUDFLARE_ENV=preview` before your build
440
+ command (`CLOUDFLARE_ENV` picks the Wrangler environment at build time, not at deploy) and deploys with a plain
441
+ `wrangler deploy`. Put its address in `sites.json`:
442
+
443
+ ```json
444
+ { "sites": { "default": { "previewUrl": { "en": "https://preview.example.com" } } } }
285
445
  ```
286
446
 
287
- Set `requireRegistration: true` in CI to turn that into a build failure. An attempted registration that the endpoint
288
- rejects always fails the build; there is no switch for that.
447
+ A workspace admin confirms the address in the editor once; from then on every preview link opens there.
289
448
 
290
449
  ## Doctor
291
450
 
292
451
  This package is a `conloca doctor` extension (`conloca.doctor` in package.json): `conloca doctor` in a project that
293
452
  depends on it runs this package's checks after the CMS ones, offline by default.
294
453
 
295
- | Check | What it verifies |
296
- | ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
297
- | CC1 | `conlocaCloud(...)` is wired next to `conlocaCMS(...)` (an absent `conlocaCMS` is an error) |
298
- | CC2 | A build token is available (`CONLOCA_BUILD_TOKEN`; missing = error under CI, info locally) and parses as `cbt_…`, with its own message for a pasted `CONLOCA_BUILD_TOKEN=` prefix (skipped when `conlocaCloud` is not called) |
299
- | CC3 | `endpoint` is a valid https URL (no trailing slash); `publicBaseUrl`/`previewDomain` when set, or `CF_PAGES_URL` under CI; skipped likewise |
300
- | CC4 | `conlocaCMS` options the endpoint's editor ignores (`editorStyles`, `editorCSS`) |
301
- | CC5 | `--live`: the endpoint accepts the token (a 401 means a replaced token — put the new one in the CI secret — or an endpoint without the status route) |
302
- | CC6 | `--live`: a registration serves this branch and site — own row, inherited from the default branch, or none |
303
- | CC7 | `--live`: the editor bundle the registration names is still deployed (catches a later deploy deleting it) and how stale it is; it does not check the cross-origin header |
304
- | CC8 | `previewBuild` is `false`, or the preview build has an SSR adapter (the project's own or `previewBuild.adapter`); a static project with neither is an error, because every build that registers would fail |
305
-
306
- `conloca doctor --live` sends the build token ONLY to the configured endpoint. When the config computes `endpoint` (for
307
- example from an environment variable), set `CONLOCA_ENDPOINT` so doctor can read it.
454
+ | Check | What it verifies |
455
+ | ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
456
+ | CC1 | `conlocaCloud(...)` is wired next to `conlocaCMS(...)` (an absent `conlocaCMS` is an error); notes that the deployed `conloca.json` publishes the repository's name |
457
+ | CC8 | How the preview build serves drafts: next to a static site on Cloudflare Workers (D3), from the site's own server deploy (D2), or a separate deploy (D4) |
458
+ | CC9 | `sites.json` gives the site named `default` (or the only site) a bare host in `domains[defaultLocale]` and a valid `base`; Astro's `site` and `base`, when the config shows them, agree (warnings) |
459
+ | CC10 | No committed `public/_headers`, `netlify.toml` or `vercel.json` sets `X-Frame-Options` or `frame-ancestors` for the whole site without a `/_conloca/editor/` rule; the error carries the rule to add |
460
+ | CC11 | `--live`: `<host><base>_conloca/editor/conloca.json` is deployed, public, and names this repository and site; warns when it serves another commit than your checkout |
461
+ | CC12 | `--live`: the deployed `/_conloca/editor/` may be framed by `https://*.conloca.com` and its `script-src` allows the editor's origin |
462
+ | CC13 | `--live`: the page's protocol is in the range the editor publishes at `/host/protocols.json` |
463
+ | CC14 | No tracked workflow and not the astro config still names `CONLOCA_BUILD_TOKEN`, `buildToken`, `publicBaseUrl`, `previewDomain` or `requireRegistration` (warnings) |
464
+ | CC15 | D3/D4: a `wrangler.jsonc` deploys to Cloudflare Workers, not Pages; a `wrangler.toml` is asked to become `wrangler.jsonc` |
465
+ | CC16 | D3: the project's wrangler is 4.36 or newer (`run_worker_first` patterns and the `ratelimits` binding); a warning when it is not installed |
466
+ | CC17 | D3: `main` is the dispatcher, `nodejs_compat` is on, assets bind as `ASSETS`, `run_worker_first` covers the preview route (no `!` exclusion, at most 100 entries), no env block replaces `main` or `assets`, and 404 handling is not single-page-application. D4: `main` no longer names the D3 dispatcher, and without a `main` there is no assets `binding` and no `run_worker_first`, which Wrangler refuses on an assets-only deploy |
467
+ | CC18 | D3: `run_worker_first` lists every route the last build renders on demand |
468
+ | CC19 | D3: no `.wrangler/deploy/config.json` points a plain `wrangler deploy` at the preview server |
469
+ | CC20 | D3 (warning): the site has a 404 page (read from the build when there is one), unless `not_found_handling` is `"none"`; a middleware that negotiates responses gets the `"none"`-or-static choice |
470
+ | CC21 | D3: no tracked file loads a tag manager, which would run on draft pages (warning; recommends `separate: true`) |
471
+ | CC22 | D3, Paid plan (or none recorded): `wrangler.jsonc` (and every `env` block in it) has the `conlocaPreviewLimit` rate-limit binding at 60 requests per 10 s. Free plan: none expected, and one that is there is only noted. A rule in the Cloudflare dashboard is optional and not checked |
472
+ | CC23 | D3: `package.json` records the Cloudflare plan (`conloca.cfPlan`); on Free, a warning: with on-demand routes, that previews and those routes share one daily request quota |
473
+ | CC24 | `--live`, D4: `previewUrl`'s `conloca.json` answers as D4 and names the site's release |
474
+
475
+ `conloca doctor` reads the rate-limit binding and the recorded plan from your project's files; it never contacts
476
+ Cloudflare and needs no token. `conloca doctor --live` sends no credential: it contacts your site's host, its
477
+ `previewUrl` and the editor's public `/host/protocols.json`. When the config computes `endpoint` (for example from an
478
+ environment variable), set `CONLOCA_ENDPOINT` so doctor can read it.
308
479
 
309
480
  The integration also scaffolds a one-page agent skill at `.claude/skills/conloca-cloud/SKILL.md` — in the nearest
310
481
  `.claude/` directory between the Astro project and the git root — on any Astro command that loads the config (build,
311
482
  dev, sync, check), once, never overwriting an existing file. Repos without a `.claude/` directory get nothing. Projects
312
- outside a git repository get nothing either. The page is not auto-updated: copy the current one from this package's
313
- `src/skill/SKILL.md` when it changes.
483
+ outside a git repository get nothing either. `conloca upgrade` refreshes it; an edited page is kept and the new one
484
+ written beside it as `SKILL.new.md`.
314
485
 
315
486
  ## Tests
316
487