@conloca/cloud-astro 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/README.md +261 -207
  2. package/dist/.build-inputs.json +60 -0
  3. package/dist/src/component-manifest.d.ts +5 -3
  4. package/dist/src/component-manifest.d.ts.map +1 -1
  5. package/dist/src/component-manifest.js +7 -7
  6. package/dist/src/component-manifest.js.map +1 -1
  7. package/dist/src/constants.d.ts +5 -13
  8. package/dist/src/constants.d.ts.map +1 -1
  9. package/dist/src/constants.js +5 -13
  10. package/dist/src/constants.js.map +1 -1
  11. package/dist/src/descriptors.d.ts +2 -2
  12. package/dist/src/descriptors.d.ts.map +1 -1
  13. package/dist/src/doctor/checks-address.d.ts +18 -0
  14. package/dist/src/doctor/checks-address.d.ts.map +1 -0
  15. package/dist/src/doctor/checks-address.js +163 -0
  16. package/dist/src/doctor/checks-address.js.map +1 -0
  17. package/dist/src/doctor/checks-live.d.ts +8 -5
  18. package/dist/src/doctor/checks-live.d.ts.map +1 -1
  19. package/dist/src/doctor/checks-live.js +220 -188
  20. package/dist/src/doctor/checks-live.js.map +1 -1
  21. package/dist/src/doctor/checks-offline.d.ts +8 -23
  22. package/dist/src/doctor/checks-offline.d.ts.map +1 -1
  23. package/dist/src/doctor/checks-offline.js +22 -239
  24. package/dist/src/doctor/checks-offline.js.map +1 -1
  25. package/dist/src/doctor/config-scan.d.ts +6 -3
  26. package/dist/src/doctor/config-scan.d.ts.map +1 -1
  27. package/dist/src/doctor/config-scan.js +21 -11
  28. package/dist/src/doctor/config-scan.js.map +1 -1
  29. package/dist/src/doctor/run.d.ts.map +1 -1
  30. package/dist/src/doctor/run.js +12 -10
  31. package/dist/src/doctor/run.js.map +1 -1
  32. package/dist/src/doctor/types.d.ts +7 -7
  33. package/dist/src/doctor/types.d.ts.map +1 -1
  34. package/dist/src/doctor/types.js +7 -7
  35. package/dist/src/doctor/types.js.map +1 -1
  36. package/dist/src/editor-page/bundle.d.ts +88 -0
  37. package/dist/src/editor-page/bundle.d.ts.map +1 -0
  38. package/dist/src/editor-page/bundle.js +370 -0
  39. package/dist/src/editor-page/bundle.js.map +1 -0
  40. package/dist/src/editor-page/emit.d.ts +33 -0
  41. package/dist/src/editor-page/emit.d.ts.map +1 -0
  42. package/dist/src/editor-page/emit.js +183 -0
  43. package/dist/src/editor-page/emit.js.map +1 -0
  44. package/dist/src/editor-page/framing.d.ts +23 -0
  45. package/dist/src/editor-page/framing.d.ts.map +1 -0
  46. package/dist/src/editor-page/framing.js +39 -0
  47. package/dist/src/editor-page/framing.js.map +1 -0
  48. package/dist/src/editor-page/page.d.ts +9 -0
  49. package/dist/src/editor-page/page.d.ts.map +1 -0
  50. package/dist/src/editor-page/page.js +31 -0
  51. package/dist/src/editor-page/page.js.map +1 -0
  52. package/dist/src/editor-page/site-base.d.ts +4 -0
  53. package/dist/src/editor-page/site-base.d.ts.map +1 -0
  54. package/dist/src/editor-page/site-base.js +13 -0
  55. package/dist/src/editor-page/site-base.js.map +1 -0
  56. package/dist/src/git.d.ts +11 -8
  57. package/dist/src/git.d.ts.map +1 -1
  58. package/dist/src/git.js +25 -8
  59. package/dist/src/git.js.map +1 -1
  60. package/dist/src/index.d.ts +3 -1
  61. package/dist/src/index.d.ts.map +1 -1
  62. package/dist/src/index.js +9 -6
  63. package/dist/src/index.js.map +1 -1
  64. package/dist/src/integration.d.ts +1 -1
  65. package/dist/src/integration.d.ts.map +1 -1
  66. package/dist/src/integration.js +245 -396
  67. package/dist/src/integration.js.map +1 -1
  68. package/dist/src/node.d.ts +3 -1
  69. package/dist/src/node.d.ts.map +1 -1
  70. package/dist/src/node.js +7 -2
  71. package/dist/src/node.js.map +1 -1
  72. package/dist/src/preview/_dispatch.d.ts +5 -2
  73. package/dist/src/preview/_dispatch.d.ts.map +1 -1
  74. package/dist/src/preview/_dispatch.js +2 -0
  75. package/dist/src/preview/_dispatch.js.map +1 -1
  76. package/dist/src/preview/_resolve-opts.d.ts +18 -10
  77. package/dist/src/preview/_resolve-opts.d.ts.map +1 -1
  78. package/dist/src/preview/_resolve-opts.js +24 -10
  79. package/dist/src/preview/_resolve-opts.js.map +1 -1
  80. package/dist/src/preview/banner.d.ts.map +1 -1
  81. package/dist/src/preview/banner.js +2 -4
  82. package/dist/src/preview/banner.js.map +1 -1
  83. package/dist/src/preview/cookie.d.ts +5 -2
  84. package/dist/src/preview/cookie.d.ts.map +1 -1
  85. package/dist/src/preview/cookie.js +5 -2
  86. package/dist/src/preview/cookie.js.map +1 -1
  87. package/dist/src/preview/label.d.ts +8 -0
  88. package/dist/src/preview/label.d.ts.map +1 -0
  89. package/dist/src/preview/label.js +14 -0
  90. package/dist/src/preview/label.js.map +1 -0
  91. package/dist/src/preview/landing.d.ts +2 -2
  92. package/dist/src/preview/landing.js +2 -2
  93. package/dist/src/preview/middleware.d.ts +31 -20
  94. package/dist/src/preview/middleware.d.ts.map +1 -1
  95. package/dist/src/preview/middleware.js +56 -51
  96. package/dist/src/preview/middleware.js.map +1 -1
  97. package/dist/src/preview/preview-path.d.ts +18 -5
  98. package/dist/src/preview/preview-path.d.ts.map +1 -1
  99. package/dist/src/preview/preview-path.js +24 -8
  100. package/dist/src/preview/preview-path.js.map +1 -1
  101. package/dist/src/preview/site-middleware.d.ts +5 -5
  102. package/dist/src/preview/site-middleware.d.ts.map +1 -1
  103. package/dist/src/preview/site-middleware.js +17 -16
  104. package/dist/src/preview/site-middleware.js.map +1 -1
  105. package/dist/src/preview-build.d.ts +18 -15
  106. package/dist/src/preview-build.d.ts.map +1 -1
  107. package/dist/src/preview-build.js +36 -21
  108. package/dist/src/preview-build.js.map +1 -1
  109. package/dist/src/preview.d.ts +1 -1
  110. package/dist/src/preview.d.ts.map +1 -1
  111. package/dist/src/preview.js +1 -1
  112. package/dist/src/preview.js.map +1 -1
  113. package/dist/src/repository.d.ts +1 -1
  114. package/dist/src/repository.js +1 -1
  115. package/dist/src/resolve-options.d.ts +17 -0
  116. package/dist/src/resolve-options.d.ts.map +1 -0
  117. package/dist/src/resolve-options.js +21 -0
  118. package/dist/src/resolve-options.js.map +1 -0
  119. package/dist/src/site-id.d.ts +0 -2
  120. package/dist/src/site-id.d.ts.map +1 -1
  121. package/dist/src/site-id.js +2 -3
  122. package/dist/src/site-id.js.map +1 -1
  123. package/dist/src/types.d.ts +21 -59
  124. package/dist/src/types.d.ts.map +1 -1
  125. package/package.json +44 -15
  126. package/src/component-manifest.ts +11 -8
  127. package/src/constants.ts +5 -14
  128. package/src/descriptors.ts +2 -2
  129. package/src/doctor/checks-address.ts +190 -0
  130. package/src/doctor/checks-live.ts +256 -268
  131. package/src/doctor/checks-offline.ts +24 -262
  132. package/src/doctor/config-scan.ts +21 -9
  133. package/src/doctor/run.ts +14 -16
  134. package/src/doctor/types.ts +7 -7
  135. package/src/editor-page/bundle.ts +482 -0
  136. package/src/editor-page/emit.ts +246 -0
  137. package/src/editor-page/framing.ts +62 -0
  138. package/src/editor-page/page.ts +37 -0
  139. package/src/editor-page/site-base.ts +11 -0
  140. package/src/git.ts +29 -10
  141. package/src/index.ts +20 -6
  142. package/src/integration.ts +255 -449
  143. package/src/node.ts +18 -2
  144. package/src/preview/_dispatch.ts +6 -2
  145. package/src/preview/_resolve-opts.ts +34 -11
  146. package/src/preview/banner.ts +2 -4
  147. package/src/preview/cookie.ts +5 -2
  148. package/src/preview/label.ts +12 -0
  149. package/src/preview/landing.ts +2 -2
  150. package/src/preview/middleware.ts +83 -66
  151. package/src/preview/preview-path.ts +26 -8
  152. package/src/preview/site-middleware.ts +17 -21
  153. package/src/preview-build.ts +42 -26
  154. package/src/preview-handler.astro +10 -8
  155. package/src/preview.ts +0 -1
  156. package/src/repository.ts +1 -1
  157. package/src/resolve-options.ts +37 -0
  158. package/src/site-id.ts +2 -4
  159. package/src/skill/SKILL.md +51 -55
  160. package/src/types.ts +21 -60
  161. package/src/virtual-modules.d.ts +5 -1
  162. package/dist/src/build-commit.d.ts +0 -19
  163. package/dist/src/build-commit.d.ts.map +0 -1
  164. package/dist/src/build-commit.js +0 -6
  165. package/dist/src/build-commit.js.map +0 -1
  166. package/dist/src/bundle.d.ts +0 -173
  167. package/dist/src/bundle.d.ts.map +0 -1
  168. package/dist/src/bundle.js +0 -413
  169. package/dist/src/bundle.js.map +0 -1
  170. package/dist/src/discovery.d.ts +0 -58
  171. package/dist/src/discovery.d.ts.map +0 -1
  172. package/dist/src/discovery.js +0 -133
  173. package/dist/src/discovery.js.map +0 -1
  174. package/dist/src/register.d.ts +0 -98
  175. package/dist/src/register.d.ts.map +0 -1
  176. package/dist/src/register.js +0 -103
  177. package/dist/src/register.js.map +0 -1
  178. package/src/build-commit.ts +0 -22
  179. package/src/bundle.ts +0 -563
  180. package/src/discovery.ts +0 -183
  181. package/src/register.ts +0 -180
@@ -1,17 +1,13 @@
1
- import { existsSync } from 'node:fs';
2
1
  import { createRequire } from 'node:module';
3
2
  import { fileURLToPath } from 'node:url';
4
3
  import { readEditorDescriptors } from '@conloca/astro-cms/node';
5
- import { registrationCommits } from './build-commit.js';
6
- import { bundleEditorAssets, emitRouteCssArtifact, mirrorEditorAssets } from './bundle.js';
7
- import { emitComponentManifest } from './component-manifest.js';
8
- import { BUILD_TOKEN_ENV_VAR, PACKAGE_NAME, PREVIEW_BUILD_ENV_FLAG, PREVIEW_SECRET_ENV_FLAG } from './constants.js';
9
- import { resolveEditorDescriptors } from './descriptors.js';
10
- import { discoverStyleContext } from './discovery.js';
4
+ import { DEFAULT_EDITOR_ENDPOINT, editorUiOrigin } from '@conloca/content-api/editor-host';
5
+ import { PACKAGE_NAME, PREVIEW_BUILD_ENV_FLAG } from './constants.js';
6
+ import { emitEditorPage, mirrorEditorPage } from './editor-page/emit.js';
11
7
  import { gitOutput, resolveBuildRef, resolveRepositoryUri } from './git.js';
12
- import { packageVersion } from './package-version.js';
13
- import { spawnPreviewBuild } from './preview-build.js';
14
- import { postRegistration } from './register.js';
8
+ import { PREVIEW_ROUTE_SEGMENT } from './preview/preview-path.js';
9
+ import { previewBuildMode, spawnPreviewBuild } from './preview-build.js';
10
+ import { resolveInheritedOptions } from './resolve-options.js';
15
11
  import { resolveBuildSiteId } from './site-id.js';
16
12
  import { scaffoldSkill } from './skill.js';
17
13
  // Re-export the constants that moved out of this module when the preview
@@ -20,203 +16,224 @@ import { scaffoldSkill } from './skill.js';
20
16
  export { PACKAGE_NAME, PREVIEW_BUILD_ENV_FLAG };
21
17
  /**
22
18
  * Returns the site's Astro integration that hooks into `astro:build:done`
23
- * to bundle editor assets, register the build at `endpoint`, and
24
- * (optionally) trigger a recursive preview build.
19
+ * to write the editor page and, when the site opts in, trigger a recursive
20
+ * preview build.
25
21
  *
26
22
  * The build:done pipeline:
27
23
  *
28
- * 1. esbuild the site's puck config into one browser ESM bundle under
29
- * `dist/_conloca/` with react/react-dom/jsx-runtime/puck externalized
30
- * (the editor supplies them at runtime), plus a `_headers` CORS
31
- * rule so the editor's origin can load it cross-origin. For a conlocaCMS
32
- * build it also writes the component manifest there (what each
33
- * component accepts, read from source) and registers its URL + hash
34
- * with the bundle.
35
- * 2. POST the registration (repo, git sha, branch, bundle URL + hash) to the
36
- * endpoint, authenticated by the build token. An ATTEMPTED
37
- * registration that is rejected FAILS THE BUILD — the error carries the
38
- * endpoint's exact status and body. Only a never-attempted registration (no
39
- * build token, repo identity, git sha/branch, or public base URL) skips,
40
- * ending the build with one summary block — or failing it when
41
- * `requireRegistration` is set.
42
- * 3. Spawn the recursive preview build with the preview secret
43
- * returned by registration (or the env override).
24
+ * 0. Write the editor page to `dist/_conloca/editor/`: `index.html`, the
25
+ * site's compiled puck config and styles, the MDX sandbox frame and
26
+ * `conloca.json`. Every build does this; the page carries no credential.
27
+ * 1. Only when `previewBuild` is given as an object and an SSR adapter
28
+ * exists (refused under @astrojs/vercel and @astrojs/netlify, checked
29
+ * already at `astro:config:done`), spawn the recursive preview build
30
+ * and copy the editor page into its
31
+ * client folder. It mounts `/_conloca/preview/` and
32
+ * bakes in the repository, site and branch it serves (every pass must
33
+ * match them), Astro's base and the commit it was built from.
44
34
  */
45
35
  const VIRTUAL_PREVIEW_OPTS = 'virtual:conloca-preview-opts';
46
36
  const RESOLVED_PREVIEW_OPTS = `\0${VIRTUAL_PREVIEW_OPTS}`;
47
- export function conlocaCloud(options) {
37
+ export function conlocaCloud(options = {}) {
48
38
  validateOptions(options);
49
39
  const repoUri = resolveRepositoryUri(options.repoUri, process.env);
50
40
  // Populated during the preview build's config:setup and read by the virtual
51
41
  // module below. Server-only — never reaches a browser bundle.
52
42
  let previewOptsModule;
43
+ // The Astro command, recorded in config:setup: only `astro build` starts
44
+ // the preview build, so only it checks the preview adapter at config:done.
45
+ let astroCommand;
53
46
  // The project root, captured in config:setup: astro:build:done only hands
54
47
  // over the build's own outDir, but the siteStyles resolve against the root,
55
- // and locating the CHILD build's client dir (for the editor-asset mirror)
48
+ // and locating the CHILD build's client dir (for the editor page mirror)
56
49
  // needs the root the child resolves against.
57
50
  let projectRoot;
58
- // Adapter name, finalized only at config:done. Discovery boots the built
59
- // server entry for `output: 'server'` sites, and only the node adapter's
60
- // entry is a plain bootable process (see discovery.ts).
51
+ // Adapter name, finalized only at config:done: the preview build reads it
52
+ // when previewBuild names no adapter of its own.
61
53
  let adapterName;
62
- // The site's Vite config, finalized at config:done: the siteStyles compile
63
- // through it, as they do in conlocaCMS's dev editor.
54
+ // The site's Vite config, finalized at config:done: the editor page and the
55
+ // siteStyles compile through it, as they do in conlocaCMS's dev editor. It
56
+ // holds the site's and integrations' plugins only; Astro adds its own core
57
+ // plugins to a separate config when it builds, so none reach the editor page.
64
58
  let viteConfig;
59
+ // Astro's base, as written: the editor page's URLs sit below it.
60
+ let astroBase = '/';
61
+ // The editor options, settled at config:done: conlocaCMS publishes its
62
+ // channel from its own config:setup, which may run after ours.
63
+ let inherited;
64
+ // Whether the parent build starts the preview build, read with the adapter
65
+ // the child will use: previewBuild.adapter, else the project's own.
66
+ const previewMode = () => previewBuildMode(options.previewBuild, (options.previewBuild || undefined)?.adapter?.name ?? adapterName);
65
67
  return {
66
68
  name: PACKAGE_NAME,
67
69
  hooks: {
68
- 'astro:config:setup': ({ logger, injectRoute, updateConfig, config, addMiddleware }) => {
70
+ 'astro:config:setup': ({ logger, injectRoute, updateConfig, config, addMiddleware, command }) => {
69
71
  // Optional-chained: unit tests drive this hook with a bare { logger }.
70
72
  projectRoot = config?.root;
73
+ astroCommand = command;
71
74
  // The agent skill: write-if-not-exists, fail-soft, and
72
75
  // never from the recursive preview child (it would race the parent).
73
76
  if (process.env[PREVIEW_BUILD_ENV_FLAG] !== '1' && config?.root) {
74
77
  scaffoldSkill(fileURLToPath(config.root), logger);
75
78
  }
76
- logger.info(`integration registered (endpoint=${options.endpoint}, previewMode=${options.previewDomain ? 'preview-domain' : 'same-domain-runtime'})`);
79
+ logger.info(`integration registered (endpoint=${options.endpoint ?? DEFAULT_EDITOR_ENDPOINT})`);
77
80
  // Only the recursive preview build (which sets PREVIEW_BUILD_ENV_FLAG)
78
- // mounts the secret-scoped SSR catch-all that renders previews. A
79
- // site's normal build must never expose it; the per-branch secret in
80
- // the path is the load guard (JWT validation in the handler is the real
81
- // auth boundary). Without a secret there is nothing to scope, so skip.
81
+ // mounts the SSR catch-all that renders previews; a site's normal
82
+ // build never exposes it. The route is fixed and public: the signed
83
+ // pass, checked against what this build bakes in, is the lock.
82
84
  if (process.env[PREVIEW_BUILD_ENV_FLAG] === '1') {
83
- const secret = process.env[PREVIEW_SECRET_ENV_FLAG];
84
- if (secret) {
85
- if (!repoUri) {
86
- throw new Error(`${PACKAGE_NAME}: could not determine repository identity for the preview build ` +
87
- '(build in a Git checkout or set repoUri as an advanced override)');
88
- }
89
- injectRoute({
90
- pattern: `/conloca_preview_${secret}/[...path]`,
91
- entrypoint: '@conloca/cloud-astro/preview-handler',
92
- prerender: false,
93
- });
94
- // The prefixed route above is the ENTRY DOOR — the only URL the
95
- // endpoint can link to before a cookie exists. This interceptor is the
96
- // serving surface: once the init hop sets the `Path=/` cookie, the
97
- // browser sends the credential on every same-origin request, so
98
- // internal links keep rendering drafts instead of silently falling
99
- // back to published content after one page view. Fail-open — an
100
- // uncredentialed visitor gets the ordinary page.
101
- addMiddleware({ entrypoint: '@conloca/cloud-astro/site-middleware', order: 'pre' });
102
- // Bake the middleware's configuration into the artifact. Every
103
- // value is already known here — the secret arrived with
104
- // registration, endpoint/audience are integration options — so a
105
- // correctly built preview deployment needs NO env vars set on it.
106
- // That also closes a chicken-and-egg loop: the secret is generated
107
- // DURING this build, but the deployment that would carry it as an
108
- // env var only happens afterwards. `saasIssuer` stays unbaked
109
- // unless configured: it is a property of the endpoint, not of the site.
110
- previewOptsModule = {
111
- secret,
112
- saasEndpoint: options.endpoint,
113
- // The token's `aud` is the repo URI as registered — the same
114
- // string this integration posts at registration time.
115
- saasAudience: repoUri,
116
- ...(options.saasIssuer ? { saasIssuer: options.saasIssuer } : {}),
117
- };
118
- // Preview-build path: the child build must emit an SSR
119
- // artifact even when the primary build is fully static. Switch to
120
- // server output, apply the preview adapter (the project's own
121
- // adapter stays in force when it already has one), and write to a
122
- // SEPARATE outDir so the child never clobbers the primary dist/.
123
- const previewBuild = options.previewBuild === false ? {} : (options.previewBuild ?? {});
124
- const adapter = previewBuild.adapter ?? config.adapter;
125
- if (!adapter) {
126
- throw new Error(`${PACKAGE_NAME}: the preview build needs an SSR adapter — the project is static and ` +
127
- 'previewBuild.adapter is not set. Pass one (e.g. previewBuild: { adapter: cloudflare() }) ' +
128
- 'or set previewBuild: false to opt out of draft preview.');
129
- }
130
- // Astro allows exactly one deployment integration. Adding
131
- // previewBuild.adapter next to the project's own would make the
132
- // child build die on Astro's adapter-conflict error, which names
133
- // neither this integration nor the option — fail here with the
134
- // actual cause. The child inherits the project adapter, so the
135
- // option is unnecessary on SSR projects.
136
- if (previewBuild.adapter && config.adapter) {
137
- const projectAdapterName = config.adapter.name ?? 'the project adapter';
138
- throw new Error(`${PACKAGE_NAME}: previewBuild.adapter conflicts with the project's own adapter ` +
139
- `(${projectAdapterName}) — Astro allows only one deployment integration per build. ` +
140
- 'Remove previewBuild.adapter; the preview build inherits the project adapter.');
141
- }
142
- // Trailing slash so URL-joining treats it as a directory. Astro
143
- // derives build.client/build.server from outDir BEFORE hooks run,
144
- // so overriding outDir alone still writes into the primary dist/ —
145
- // all three must move together.
146
- // OUTSIDE dist/ on purpose, against the original design: the
147
- // artifact bakes the preview secret, so a wholesale static upload
148
- // of dist/ must never be able to publish it — and Astro clears
149
- // dist/ at the start of a build, which would wipe a sibling
150
- // artifact parked inside it.
151
- const previewOut = new URL(`${previewBuild.outDir ?? '.conloca/preview-server'}/`, config.root);
152
- // The site's extra config goes through its OWN updateConfig
153
- // call: Astro deep-merges successive calls (concatenating
154
- // vite.plugins and integrations), whereas spreading it into the
155
- // object below would shallow-replace whole keys — a user `vite`
156
- // entry silently dropped the required virtual-module plugin.
157
- // Ours comes second so the required scalars (output, outDir,
158
- // build dirs) always win; previewBuild.outDir is the supported
159
- // override for the artifact location.
160
- if (previewBuild.config) {
161
- updateConfig(previewBuild.config);
162
- }
163
- updateConfig({
164
- output: 'server',
165
- outDir: previewOut,
166
- build: { client: new URL('client/', previewOut), server: new URL('server/', previewOut) },
167
- vite: {
168
- // The middleware dynamically imports Cloudflare's runtime
169
- // module (binding transport). The Cloudflare adapter resolves
170
- // the scheme itself; every other adapter's Rollup pass fails
171
- // the child build on it unless externalized. Off Cloudflare
172
- // Workers the runtime import rejects and the middleware falls
173
- // back to the global fetch.
174
- build: { rollupOptions: { external: [/^cloudflare:/] } },
175
- // Starlight renders Steps, Tabs and FileTree with satteri's
176
- // htmlToHast. On Cloudflare Workers satteri resolves to a
177
- // binding that can be neither installed nor run on workerd, so the child
178
- // build fails to resolve it — swap in a stand-in there. The
179
- // target is an absolute path: a bare name would be looked up
180
- // from the Starlight file, which cannot see this package in an
181
- // isolated (non-hoisted) node_modules layout.
182
- ...(adapter.name === '@astrojs/cloudflare'
183
- ? {
184
- resolve: {
185
- alias: [
186
- {
187
- find: /^satteri$/,
188
- replacement: resolveSatteriStandIn(),
189
- },
190
- ],
191
- },
192
- }
193
- : {}),
194
- plugins: [
195
- {
196
- name: 'conloca-preview-opts',
197
- resolveId(id) {
198
- return id === VIRTUAL_PREVIEW_OPTS ? RESOLVED_PREVIEW_OPTS : undefined;
199
- },
200
- load(id) {
201
- if (id !== RESOLVED_PREVIEW_OPTS)
202
- return undefined;
203
- // Read lazily so the values assigned above are captured.
204
- return `export default ${JSON.stringify(previewOptsModule ?? {})};`;
205
- },
206
- },
207
- ],
208
- },
209
- // The adapter must ride in BOTH ways: as `adapter` because the
210
- // build gate checks `config.adapter` before creating the SSR
211
- // bundle, and as an integration because only the adapter's own
212
- // astro:config:done hook calls setAdapter — which is what the
213
- // build pipeline actually renders through. (Astro unshifts
214
- // config.adapter into the integration list BEFORE any hook runs,
215
- // so setting `adapter` alone here is too late for the hooks.)
216
- // A project that is already SSR keeps its own adapter untouched.
217
- ...(previewBuild.adapter ? { adapter: previewBuild.adapter, integrations: [previewBuild.adapter] } : {}),
218
- });
85
+ if (!repoUri) {
86
+ throw new Error(`${PACKAGE_NAME}: could not determine repository identity for the preview build ` +
87
+ '(build in a Git checkout or set repoUri as an advanced override)');
88
+ }
89
+ // The project's own checkout answers git, not the directory the
90
+ // build was started from.
91
+ const projectGit = (args) => gitOutput(args, fileURLToPath(config.root));
92
+ const buildRef = resolveBuildRef(process.env, projectGit);
93
+ if (!buildRef.branch) {
94
+ throw new Error(`${PACKAGE_NAME}: could not determine the branch the preview build serves (set CF_PAGES_BRANCH, ` +
95
+ 'WORKERS_CI_BRANCH, VERCEL_GIT_COMMIT_REF or GITHUB_REF_NAME, or build in a git checkout on a branch)');
96
+ }
97
+ const siteId = resolveBuildSiteId({
98
+ contentRoot: process.env.CONLOCA_CONTENT_ROOT,
99
+ override: options.siteId,
100
+ });
101
+ injectRoute({
102
+ pattern: `${PREVIEW_ROUTE_SEGMENT}/[...path]`,
103
+ entrypoint: '@conloca/cloud-astro/preview-handler',
104
+ prerender: false,
105
+ });
106
+ // The route above is the ENTRY DOOR — the only URL the endpoint can
107
+ // link to before a cookie exists. This interceptor is the serving
108
+ // surface: once the init hop sets the `Path=/` cookie, the browser
109
+ // sends the credential on every same-origin request, so internal
110
+ // links keep rendering drafts instead of silently falling back to
111
+ // published content after one page view. Fail-open — an
112
+ // uncredentialed visitor gets the ordinary page.
113
+ addMiddleware({ entrypoint: '@conloca/cloud-astro/site-middleware', order: 'pre' });
114
+ // The commit this preview build's checkout holds: a PR build may
115
+ // check out a merge commit rather than the commit CI hands over.
116
+ // Page-status compares the branch's latest commit with it, so the
117
+ // endpoint diffs against the content actually serving, not a newer
118
+ // commit whose deploy never landed. A checkout commit the
119
+ // endpoint does not have makes it render from the branch instead.
120
+ const buildCommit = projectGit(['rev-parse', 'HEAD']) ?? buildRef.gitSha;
121
+ // Bake the middleware's configuration into the artifact. Every value
122
+ // is already known here — endpoint and audience are integration
123
+ // options; repository, site, branch, base and commit are what this
124
+ // build was made from, and every pass must match the first three —
125
+ // so a correctly built preview deployment needs NO env vars set on
126
+ // it. `saasIssuer` stays unbaked unless configured: it is a property
127
+ // of the endpoint, not of the site.
128
+ previewOptsModule = {
129
+ saasEndpoint: options.endpoint ?? DEFAULT_EDITOR_ENDPOINT,
130
+ // The token's `aud` is the repo URI this build resolved.
131
+ saasAudience: repoUri,
132
+ ...(options.saasIssuer ? { saasIssuer: options.saasIssuer } : {}),
133
+ ...(buildCommit ? { buildCommit } : {}),
134
+ repo: repoUri,
135
+ siteId,
136
+ branch: buildRef.branch,
137
+ base: config.base ?? '/',
138
+ };
139
+ // Preview-build path: the child build must emit an SSR
140
+ // artifact even when the primary build is fully static. Switch to
141
+ // server output, apply the preview adapter (the project's own
142
+ // adapter stays in force when it already has one), and write to a
143
+ // SEPARATE outDir so the child never clobbers the primary dist/.
144
+ const previewBuild = options.previewBuild || {};
145
+ const adapter = previewBuild.adapter ?? config.adapter;
146
+ // Throws for a missing adapter, or one the preview build is refused
147
+ // under — the parent already checked, this keeps the child honest.
148
+ previewBuildMode(previewBuild, adapter?.name);
149
+ // Astro allows exactly one deployment integration. Adding
150
+ // previewBuild.adapter next to the project's own would make the
151
+ // child build die on Astro's adapter-conflict error, which names
152
+ // neither this integration nor the option — fail here with the
153
+ // actual cause. The child inherits the project adapter, so the
154
+ // option is unnecessary on SSR projects.
155
+ if (previewBuild.adapter && config.adapter) {
156
+ const projectAdapterName = config.adapter.name;
157
+ throw new Error(`${PACKAGE_NAME}: previewBuild.adapter conflicts with the project's own adapter ` +
158
+ `(${projectAdapterName}) — Astro allows only one deployment integration per build. ` +
159
+ 'Remove previewBuild.adapter; the preview build inherits the project adapter.');
219
160
  }
161
+ // Trailing slash so URL-joining treats it as a directory. Astro
162
+ // derives build.client/build.server from outDir BEFORE hooks run,
163
+ // so overriding outDir alone still writes into the primary dist/ —
164
+ // all three must move together.
165
+ // OUTSIDE dist/ on purpose, against the original design: a
166
+ // wholesale static upload of dist/ must never publish the preview
167
+ // server — and Astro clears dist/ at the start of a build, which
168
+ // would wipe a sibling artifact parked inside it.
169
+ const previewOut = new URL(`${previewBuild.outDir ?? '.conloca/preview-server'}/`, config.root);
170
+ // The site's extra config goes through its OWN updateConfig
171
+ // call: Astro deep-merges successive calls (concatenating
172
+ // vite.plugins and integrations), whereas spreading it into the
173
+ // object below would shallow-replace whole keys — a user `vite`
174
+ // entry silently dropped the required virtual-module plugin.
175
+ // Ours comes second so the required scalars (output, outDir,
176
+ // build dirs) always win; previewBuild.outDir is the supported
177
+ // override for the artifact location.
178
+ if (previewBuild.config) {
179
+ updateConfig(previewBuild.config);
180
+ }
181
+ updateConfig({
182
+ output: 'server',
183
+ outDir: previewOut,
184
+ build: { client: new URL('client/', previewOut), server: new URL('server/', previewOut) },
185
+ vite: {
186
+ // The middleware dynamically imports Cloudflare's runtime
187
+ // module (binding transport). The Cloudflare adapter resolves
188
+ // the scheme itself; every other adapter's Rollup pass fails
189
+ // the child build on it unless externalized. Off Cloudflare
190
+ // Workers the runtime import rejects and the middleware falls
191
+ // back to the global fetch.
192
+ build: { rollupOptions: { external: [/^cloudflare:/] } },
193
+ // Starlight renders Steps, Tabs and FileTree with satteri's
194
+ // htmlToHast. On Cloudflare Workers satteri resolves to a
195
+ // binding that can be neither installed nor run on workerd, so the child
196
+ // build fails to resolve it — swap in a stand-in there. The
197
+ // target is an absolute path: a bare name would be looked up
198
+ // from the Starlight file, which cannot see this package in an
199
+ // isolated (non-hoisted) node_modules layout.
200
+ ...(adapter?.name === '@astrojs/cloudflare'
201
+ ? {
202
+ resolve: {
203
+ alias: [
204
+ {
205
+ find: /^satteri$/,
206
+ replacement: resolveSatteriStandIn(),
207
+ },
208
+ ],
209
+ },
210
+ }
211
+ : {}),
212
+ plugins: [
213
+ {
214
+ name: 'conloca-preview-opts',
215
+ resolveId(id) {
216
+ return id === VIRTUAL_PREVIEW_OPTS ? RESOLVED_PREVIEW_OPTS : undefined;
217
+ },
218
+ load(id) {
219
+ if (id !== RESOLVED_PREVIEW_OPTS)
220
+ return undefined;
221
+ // Read lazily so the values assigned above are captured.
222
+ return `export default ${JSON.stringify(previewOptsModule ?? {})};`;
223
+ },
224
+ },
225
+ ],
226
+ },
227
+ // The adapter must ride in BOTH ways: as `adapter` because the
228
+ // build gate checks `config.adapter` before creating the SSR
229
+ // bundle, and as an integration because only the adapter's own
230
+ // astro:config:done hook calls setAdapter — which is what the
231
+ // build pipeline actually renders through. (Astro unshifts
232
+ // config.adapter into the integration list BEFORE any hook runs,
233
+ // so setting `adapter` alone here is too late for the hooks.)
234
+ // A project that is already SSR keeps its own adapter untouched.
235
+ ...(previewBuild.adapter ? { adapter: previewBuild.adapter, integrations: [previewBuild.adapter] } : {}),
236
+ });
220
237
  }
221
238
  },
222
239
  /**
@@ -238,15 +255,12 @@ export function conlocaCloud(options) {
238
255
  * record, runs AFTER the `export const prerender` source parse, and
239
256
  * Astro reads `prerender` back after every integration has run.
240
257
  *
241
- * Gated on the secret as well as the flag, mirroring the config hook: no
242
- * secret means no interceptor was mounted, so stripping the site's
243
- * static output would buy nothing.
258
+ * Gated on the flag, as the config hook is: only the preview build
259
+ * mounts the interceptor these routes must reach.
244
260
  */
245
261
  'astro:route:setup': ({ route, logger }) => {
246
262
  if (process.env[PREVIEW_BUILD_ENV_FLAG] !== '1')
247
263
  return;
248
- if (!process.env[PREVIEW_SECRET_ENV_FLAG])
249
- return;
250
264
  // `type` exists at runtime but is absent from the public RouteOptions
251
265
  // type. Endpoints keep their prerendered data files: they emit no HTML
252
266
  // to intercept, and one built from getStaticPaths would break on demand.
@@ -271,106 +285,56 @@ export function conlocaCloud(options) {
271
285
  'astro:config:done': ({ config }) => {
272
286
  adapterName = config.adapter?.name;
273
287
  viteConfig = config.vite;
288
+ astroBase = config.base ?? '/';
289
+ inherited = resolveInheritedOptions(options, readEditorDescriptors());
290
+ // A refused or missing preview adapter fails `astro build` here,
291
+ // before the site builds, rather than after it. `astro dev`, `sync`
292
+ // and `preview` never start the preview build, so they are left
293
+ // alone. The child build checks its own.
294
+ if (astroCommand === 'build' && process.env[PREVIEW_BUILD_ENV_FLAG] !== '1')
295
+ previewMode();
274
296
  },
275
297
  'astro:build:done': async ({ dir, logger }) => {
276
298
  if (process.env[PREVIEW_BUILD_ENV_FLAG] === '1') {
277
299
  // The recursive preview build sets this flag on the child
278
- // Astro process. Re-entering registration there would create an
279
- // infinite build loop, so we short-circuit.
280
- logger.info('skipping registration: recursive preview build detected');
300
+ // Astro process. Writing the editor page there again would race
301
+ // the parent, which mirrors its own copy in, so we short-circuit.
302
+ logger.info('skipping the editor page: recursive preview build detected');
281
303
  return;
282
304
  }
283
305
  // Astro always runs the config hooks first. No fallback: compiling
284
306
  // against the working directory would build the canvas stylesheet for
285
307
  // the wrong project without a word.
286
- if (projectRoot === undefined || viteConfig === undefined) {
308
+ if (projectRoot === undefined || viteConfig === undefined || inherited === undefined) {
287
309
  throw new Error(`${PACKAGE_NAME}: astro:build:done ran before the config hooks recorded the project root and Vite config`);
288
310
  }
289
- // Editor descriptors (the bundle's third leg): the host's schemas
290
- // module and the auto-discovered MDX registry, both resolved by
291
- // conlocaCMS and read off its channel. The scan runs here because the
292
- // editor at the endpoint has no dev server to serve `/api/registry` from.
293
- const descriptors = await resolveEditorDescriptors(logger);
294
- const bundle = await bundleEditorAssets({
311
+ // The editor page: every build writes it.
312
+ await emitEditorPage({
295
313
  dir: fileURLToPath(dir),
296
314
  root: fileURLToPath(projectRoot),
315
+ base: astroBase,
297
316
  vite: viteConfig,
298
- puckConfigPath: options.puckConfigPath,
299
- siteStyles: options.siteStyles,
300
- publicBaseUrl: resolveDeploymentUrl(options),
301
- ...(descriptors === undefined ? {} : { descriptors }),
317
+ endpoint: options.endpoint,
318
+ inherited,
319
+ repoUri,
320
+ siteIdOverride: options.siteId,
302
321
  logger,
303
322
  });
304
- // The component vocabulary for agents, read from the config the bundle
305
- // just compiled. Only a build conlocaCMS is part of carries one (its
306
- // descriptor channel is how this add-on knows): without the CMS there
307
- // are no pages for an agent to compose. Gated on the channel itself,
308
- // not on `descriptors` — that is also undefined for a CMS build with
309
- // no schemas module, MDX components or templates, which still has a
310
- // Puck vocabulary. An unreadable channel already warned above.
311
- const componentManifest = readEditorDescriptors(process.env) === undefined
312
- ? undefined
313
- : await emitComponentManifest({
314
- dir: fileURLToPath(dir),
315
- puckConfigPath: options.puckConfigPath,
316
- projectRoot: process.cwd(),
317
- logger,
318
- });
319
- // Build-time style discovery: read the discovery
320
- // route's rendered page, collect its CSS, run the shared wrapper
321
- // heuristic; results ride registration below. Opt-in via the option —
322
- // and fail-soft throughout: a build must never die over preview
323
- // styling.
324
- let discovery;
325
- let routeCssArtifact;
326
- if (options.fragmentPreviewRoute) {
327
- const clientDir = fileURLToPath(dir);
328
- const nodeEntry = fileURLToPath(new URL('../server/entry.mjs', dir));
329
- discovery = await discoverStyleContext({
330
- clientDir,
331
- serverEntry: adapterName === '@astrojs/node' && existsSync(nodeEntry) ? nodeEntry : undefined,
332
- route: options.fragmentPreviewRoute,
333
- logger,
334
- });
335
- if (discovery?.routeCss) {
336
- routeCssArtifact = await emitRouteCssArtifact(clientDir, discovery.routeCss, resolveDeploymentUrl(options), logger);
337
- }
338
- }
339
- const registration = await registerBuild(options, repoUri, bundle, logger, {
340
- hostWrappers: discovery?.hostWrappers,
341
- routeCssArtifact: routeCssArtifact?.stylesheet,
342
- componentManifest,
343
- });
344
- let registeredSecret;
345
- if ('missing' in registration)
346
- reportSkippedRegistration(registration.missing, options, logger);
347
- else
348
- registeredSecret = registration.previewSecret;
349
- if (options.previewBuild === false) {
350
- // The site explicitly opted out of the recursive preview build.
351
- return;
352
- }
353
- // Prefer the secret returned by registration; the env override lets
354
- // CI smoke-test the recursive build path without a reachable endpoint.
355
- const previewSecret = registeredSecret ?? process.env[PREVIEW_SECRET_ENV_FLAG];
356
- if (!previewSecret) {
323
+ // Strict opt-in: only a previewBuild given as an object starts the
324
+ // second build.
325
+ const previewBuild = options.previewBuild || undefined;
326
+ if (previewBuild === undefined || previewMode() === 'off')
357
327
  return;
358
- }
359
- await spawnPreviewBuild(previewSecret, options.previewBuild ?? {});
360
- // The child build cannot compile the editor bundle itself (it
328
+ await spawnPreviewBuild(previewBuild);
329
+ // The child build cannot write the editor files itself (it
361
330
  // short-circuits this hook — see the recursion guard above), but in
362
331
  // a deployment that serves the site and the preview from one
363
332
  // Cloudflare Worker its client dir is THE asset set serving the site,
364
- // so the editor at the endpoint loads `/_conloca/*` from it. Mirror
365
- // the bundle + its CORS rule from this build's dist into it.
366
- // previewBuild === false already returned above, so only the options
367
- // object (or undefined) reaches this point.
368
- const previewOut = new URL(`${options.previewBuild?.outDir ?? '.conloca/preview-server'}/`, projectRoot);
369
- await mirrorEditorAssets(fileURLToPath(dir), fileURLToPath(new URL('client/', previewOut)), [
370
- ...bundle.assetCorsPaths,
371
- ...(routeCssArtifact?.assetCorsPaths ?? []),
372
- ]);
373
- logger.info('editor assets mirrored into the preview client dir');
333
+ // so the editor files must be there too. Mirror them from this build's dist.
334
+ const previewOut = new URL(`${previewBuild.outDir ?? '.conloca/preview-server'}/`, projectRoot);
335
+ const previewClient = fileURLToPath(new URL('client/', previewOut));
336
+ await mirrorEditorPage(fileURLToPath(dir), previewClient);
337
+ logger.info('editor page mirrored into the preview client dir');
374
338
  },
375
339
  },
376
340
  };
@@ -385,142 +349,24 @@ function resolveSatteriStandIn() {
385
349
  'Cloudflare preview build uses in place of satteri — is the package installed and built?', { cause });
386
350
  }
387
351
  }
388
- /**
389
- * The origin the deployed site answers on. Used for two things that must agree:
390
- * absolutizing the bundle/stylesheet URLs a registration carries, and re-pointing the
391
- * stylesheet's own asset URLs at the site (they would otherwise resolve
392
- * against the editor's origin — see `rewriteStylesheetAssetUrls`).
393
- */
394
- function resolveDeploymentUrl(options) {
395
- if (!options.previewDomain) {
396
- return options.publicBaseUrl ?? process.env.CF_PAGES_URL;
397
- }
398
- const previewUrl = new URL(options.previewDomain.includes('://') ? options.previewDomain : `https://${options.previewDomain}`);
399
- return previewUrl.origin;
400
- }
401
- /**
402
- * ONE end-of-build block for a skipped registration — every prerequisite that
403
- * was missing and what it costs — the last thing the integration prints.
404
- * With `requireRegistration` it fails the build instead.
405
- */
406
- function reportSkippedRegistration(missing, options, logger) {
407
- const summary = [
408
- `editor at ${options.endpoint} NOT updated by this build`,
409
- ...missing.map((prerequisite) => ` missing: ${prerequisite}`),
410
- " 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)",
411
- ' check: conloca doctor --live',
412
- ].join('\n');
413
- if (options.requireRegistration) {
414
- throw new Error(`${PACKAGE_NAME}: ${summary}\n requireRegistration is on, so this build fails.`);
415
- }
416
- logger.warn(summary);
417
- }
418
- /**
419
- * Registers the freshly built editor bundle at the endpoint. Soft-skip ONLY
420
- * when registration was never attempted: the pre-request guards (no build
421
- * token, no repo identity, no sha/branch, no base URL) each warn, and every
422
- * missing prerequisite is returned at once, so one build names all that setup
423
- * still lacks and an unregistered deploy still completes — the hook turns
424
- * that into one end-of-build summary (or a failure under
425
- * `requireRegistration`). Once a registration IS attempted, its failure
426
- * FAILS THE BUILD: postRegistration throws on any
427
- * deterministic 4xx and after exhausting the ≥500 retry backoff, and that
428
- * error — carrying the HTTP status and response body — propagates. A green
429
- * deploy whose registration silently went missing is the "deployed but
430
- * editor unregistered" class this project exists to kill.
431
- */
432
- async function registerBuild(options, repoUri, bundle, logger, discovery = {}) {
433
- const missing = [];
434
- const buildToken = options.buildToken ?? process.env[BUILD_TOKEN_ENV_VAR];
435
- if (!buildToken) {
436
- logger.warn(`skipping registration: no build token (set buildToken or ${BUILD_TOKEN_ENV_VAR})`);
437
- missing.push(`build token (set buildToken or ${BUILD_TOKEN_ENV_VAR})`);
438
- }
439
- if (!repoUri) {
440
- logger.warn('skipping registration: could not determine repository identity ' +
441
- '(build in a supported CI environment or Git checkout, or set repoUri)');
442
- missing.push('repository identity (build in a supported CI environment or Git checkout, or set repoUri)');
443
- }
444
- const { branch } = resolveBuildRef();
445
- // CI may hand over the branch's latest commit to register; the checkout is what was built.
446
- const commits = registrationCommits({
447
- eventCommitSha: process.env.CF_PAGES_COMMIT_SHA,
448
- checkoutCommitSha: gitOutput(['rev-parse', 'HEAD']),
449
- });
450
- const gitSha = commits.gitSha;
451
- if (!gitSha || !branch) {
452
- logger.warn('skipping registration: could not resolve the git sha/branch ' +
453
- '(set CF_PAGES_COMMIT_SHA and CF_PAGES_BRANCH, or build inside a git checkout)');
454
- missing.push('git sha/branch (set CF_PAGES_COMMIT_SHA and CF_PAGES_BRANCH, or build inside a git checkout)');
455
- }
456
- const deploymentUrl = resolveDeploymentUrl(options);
457
- const baseUrl = deploymentUrl;
458
- if (!baseUrl) {
459
- logger.warn('skipping registration: no public base URL for the editor bundle (set previewDomain, publicBaseUrl, or CF_PAGES_URL)');
460
- missing.push('public base URL for the editor bundle (set previewDomain, publicBaseUrl, or CF_PAGES_URL)');
461
- }
462
- // Restates the guards above, so the values below are typed as set.
463
- if (!buildToken || !repoUri || !gitSha || !branch || !baseUrl)
464
- return { missing };
465
- // Resolve the deployable-site id (STRICT): a throw here FAILS THE BUILD —
466
- // after the soft skip guards above, so only a build that is actually
467
- // registering can die on it. A silently mis-attached registration points
468
- // the editor at the wrong site, which is the same miss as never having
469
- // registered at all. The channel is CONLOCA_CONTENT_ROOT (published by
470
- // conlocaCMS); options.siteId is the CMS-less-build override.
471
- const siteId = resolveBuildSiteId({
472
- contentRoot: process.env.CONLOCA_CONTENT_ROOT,
473
- override: options.siteId,
474
- });
475
- // NO catch: from here on the registration is ATTEMPTED, and an attempted
476
- // registration's failure fails the build. postRegistration already retried
477
- // transient (≥500 / network) failures with backoff; what escapes is either
478
- // a deterministic 4xx (unknown siteId, bad token — fix and rebuild) or an
479
- // exhausted retry budget, and the error message carries the HTTP status +
480
- // response body verbatim.
481
- logger.info('registering at the endpoint (transient failures retry, with up to ~2.5 minutes of waiting between attempts)');
482
- const { previewSecret } = await postRegistration({
483
- endpoint: options.endpoint,
484
- buildToken,
485
- repoUri,
486
- gitSha,
487
- siteId,
488
- branch,
489
- editorBundleUrl: new URL(bundle.url, baseUrl).toString(),
490
- bundleHash: bundle.hash,
491
- ...(bundle.stylesheet === undefined
492
- ? {}
493
- : {
494
- stylesheetUrl: new URL(bundle.stylesheet.url, baseUrl).toString(),
495
- stylesheetHash: bundle.stylesheet.hash,
496
- }),
497
- ...(discovery.hostWrappers === undefined ? {} : { hostWrappers: discovery.hostWrappers }),
498
- ...(discovery.routeCssArtifact === undefined
499
- ? {}
500
- : {
501
- routeCssUrl: new URL(discovery.routeCssArtifact.url, baseUrl).toString(),
502
- routeCssHash: discovery.routeCssArtifact.hash,
503
- }),
504
- ...(discovery.componentManifest === undefined
505
- ? {}
506
- : {
507
- componentManifestUrl: new URL(discovery.componentManifest.url, baseUrl).toString(),
508
- componentManifestHash: discovery.componentManifest.hash,
509
- }),
510
- deploymentUrl,
511
- buildId: commits.buildId,
512
- clientVersion: packageVersion(),
513
- });
514
- logger.info(`registration complete (gitSha=${gitSha}, branch=${branch}, buildId=${commits.buildId})`);
515
- return { previewSecret };
516
- }
352
+ /** The options the editor page made obsolete; naming one fails the build so the config gets updated. */
353
+ const REMOVED_OPTIONS = [
354
+ 'buildToken',
355
+ 'requireRegistration',
356
+ 'publicBaseUrl',
357
+ 'previewDomain',
358
+ 'editorBundlePlugins',
359
+ 'fragmentPreviewRoute',
360
+ ];
361
+ /** Refuses a removed option, a malformed endpoint, or one that is not an `app.` address, at config load. */
517
362
  function validateOptions(options) {
518
- if (!options.endpoint) {
519
- throw new Error(`${PACKAGE_NAME}: endpoint is required`);
520
- }
521
- if (!options.puckConfigPath) {
522
- throw new Error(`${PACKAGE_NAME}: puckConfigPath is required`);
363
+ for (const name of REMOVED_OPTIONS) {
364
+ if (name in options) {
365
+ throw new Error(`${PACKAGE_NAME}: option "${name}" was removed — run \`npx @conloca/cli connect\` to update this config`);
366
+ }
523
367
  }
368
+ if (options.endpoint === undefined)
369
+ return;
524
370
  try {
525
371
  // Throws on malformed URLs; we don't keep the parsed value.
526
372
  new URL(options.endpoint);
@@ -528,5 +374,8 @@ function validateOptions(options) {
528
374
  catch {
529
375
  throw new Error(`${PACKAGE_NAME}: endpoint must be a valid URL, got ${options.endpoint}`);
530
376
  }
377
+ if (editorUiOrigin(options.endpoint) === null) {
378
+ throw new Error(`${PACKAGE_NAME}: endpoint must be the workspace editor's app. address (for example https://app.conloca.com), got ${options.endpoint}`);
379
+ }
531
380
  }
532
381
  //# sourceMappingURL=integration.js.map