@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,10 +1,36 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { existsSync } from 'node:fs';
3
3
  import { join } from 'node:path';
4
- import { PACKAGE_NAME, PREVIEW_BUILD_ENV_FLAG, PREVIEW_SECRET_ENV_FLAG } from './constants.js';
4
+ import { PACKAGE_NAME, PREVIEW_BUILD_ENV_FLAG, REFUSED_PREVIEW_ADAPTERS } from './constants.js';
5
5
  import type { PreviewBuildOptions } from './types.js';
6
6
 
7
- export { PREVIEW_SECRET_ENV_FLAG };
7
+ /**
8
+ * Whether the recursive preview build runs: only when `previewBuild` is given
9
+ * as an object (strict opt-in, so a plain deploy never gets a second build),
10
+ * and then only with an SSR adapter that is not refused. Throws for a refused
11
+ * adapter or a missing one, so the build fails before it deploys anything.
12
+ */
13
+ export function previewBuildMode(
14
+ previewBuild: PreviewBuildOptions | false | undefined,
15
+ adapterName: string | undefined,
16
+ ): 'off' | 'on' {
17
+ if (!previewBuild) return 'off';
18
+ if (adapterName === undefined) {
19
+ throw new Error(
20
+ `${PACKAGE_NAME}: the preview build needs an SSR adapter — the project is static and ` +
21
+ 'previewBuild.adapter is not set. Pass one (e.g. previewBuild: { adapter: cloudflare() }) ' +
22
+ 'or remove previewBuild.',
23
+ );
24
+ }
25
+ if (REFUSED_PREVIEW_ADAPTERS.includes(adapterName)) {
26
+ throw new Error(
27
+ `${PACKAGE_NAME}: previewBuild is not supported with ${adapterName} yet: that adapter writes its deployable ` +
28
+ 'output at the project root, so the preview build could replace the live site. ' +
29
+ 'Remove previewBuild from conlocaCloud(...).',
30
+ );
31
+ }
32
+ return 'on';
33
+ }
8
34
 
9
35
  /**
10
36
  * The minimal child-process surface this module relies on. Letting
@@ -25,18 +51,18 @@ export type PreviewBuildSpawn = (
25
51
 
26
52
  /**
27
53
  * Pure constructor for the child-process environment passed to the recursive
28
- * preview build. Extracted so tests can verify the contract (env flag + secret
29
- * + parent-env inheritance) without spinning up a child process — and so the
54
+ * preview build. Extracted so tests can verify the contract (env flag +
55
+ * parent-env inheritance) without spinning up a child process — and so the
30
56
  * real-process smoke test can call it the same way the integration does.
31
57
  *
32
58
  * Inherits the parent environment so PATH, credentials, and any host-specific
33
- * build vars (CF_PAGES_*, GITHUB_*) reach the child.
59
+ * build vars (CF_PAGES_*, WORKERS_CI_*, GITHUB_*) reach the child, which reads
60
+ * the branch and commit it serves from them.
34
61
  */
35
- export function buildPreviewChildEnv(parentEnv: NodeJS.ProcessEnv, previewSecret: string): NodeJS.ProcessEnv {
62
+ export function buildPreviewChildEnv(parentEnv: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
36
63
  return {
37
64
  ...parentEnv,
38
65
  [PREVIEW_BUILD_ENV_FLAG]: '1',
39
- [PREVIEW_SECRET_ENV_FLAG]: previewSecret,
40
66
  };
41
67
  }
42
68
 
@@ -71,13 +97,10 @@ export function resolveAstroBin(cwd: string = process.cwd()): string {
71
97
  * Spawns the recursive preview `astro build` from the primary build's
72
98
  * `astro:build:done` hook.
73
99
  *
74
- * The child process inherits the parent environment and additionally receives:
75
- * - {@link PREVIEW_BUILD_ENV_FLAG} set to `'1'` so the integration's own
76
- * `astro:build:done` short-circuits inside the child (recursion guard
77
- * contract).
78
- * - {@link PREVIEW_SECRET_ENV_FLAG} set to the per-branch secret so the
79
- * child's `astro:config:setup` can inject the literal secret-scoped
80
- * preview route (`/conloca_preview_${SECRET}/[...path]`).
100
+ * The child process inherits the parent environment and additionally receives
101
+ * {@link PREVIEW_BUILD_ENV_FLAG} set to `'1'`: the child's `astro:config:setup`
102
+ * mounts the preview route on it, and its `astro:build:done` short-circuits
103
+ * on it (recursion guard contract).
81
104
  *
82
105
  * If this function is itself called from within a recursive build (i.e. the
83
106
  * env flag is already set to `'1'`), it returns immediately without spawning,
@@ -88,8 +111,8 @@ export function resolveAstroBin(cwd: string = process.cwd()): string {
88
111
  * - `false` → resolves and logs a warning so onboarding setups can continue
89
112
  * when the preview build is not yet wired correctly.
90
113
  */
91
- export async function spawnPreviewBuild(previewSecret: string, opts: PreviewBuildOptions): Promise<void> {
92
- await _spawnPreviewBuildWith(spawn, previewSecret, opts);
114
+ export async function spawnPreviewBuild(opts: PreviewBuildOptions): Promise<void> {
115
+ await _spawnPreviewBuildWith(spawn, opts);
93
116
  }
94
117
 
95
118
  /**
@@ -100,11 +123,8 @@ export async function spawnPreviewBuild(previewSecret: string, opts: PreviewBuil
100
123
  * and not part of the package's public surface; it is not re-exported from
101
124
  * `src/index.ts` or `src/node.ts`.
102
125
  */
103
- export async function _spawnPreviewBuildWith(
104
- spawnFn: PreviewBuildSpawn,
105
- previewSecret: string,
106
- opts: PreviewBuildOptions,
107
- ): Promise<void> {
126
+ // oxlint-disable-next-line no-underscore-dangle -- the internal test seam.
127
+ export async function _spawnPreviewBuildWith(spawnFn: PreviewBuildSpawn, opts: PreviewBuildOptions): Promise<void> {
108
128
  // Recursion guard: bail out before doing any work if we're already inside
109
129
  // a recursive preview build. This matches the short-circuit in the
110
130
  // integration's `astro:build:done` hook.
@@ -112,15 +132,11 @@ export async function _spawnPreviewBuildWith(
112
132
  return;
113
133
  }
114
134
 
115
- if (!previewSecret) {
116
- throw new Error(`${PACKAGE_NAME}: preview secret is required to spawn the preview build`);
117
- }
118
-
119
135
  const required = opts.required ?? true;
120
136
 
121
137
  const astroBin = resolveAstroBin();
122
138
  const child = spawnFn(astroBin, ['build'], {
123
- env: buildPreviewChildEnv(process.env, previewSecret),
139
+ env: buildPreviewChildEnv(process.env),
124
140
  stdio: 'inherit',
125
141
  });
126
142
 
@@ -3,17 +3,18 @@ import bakedPreviewOpts from 'virtual:conloca-preview-opts';
3
3
  import { resolveEndpointFetch, resolveFromBaked } from './preview/_resolve-opts.js';
4
4
  import { stripPreviewPrefix } from './preview/preview-path.js';
5
5
  /**
6
- * Secret-prefixed entry route injected by the recursive preview build at
7
- * `/conloca_preview_${SECRET}/[...path]`. The secret in the path is a
8
- * load guard — JWT validation is the actual auth boundary.
6
+ * Entry route injected by the recursive preview build at the fixed, public
7
+ * `/_conloca/preview/[...path]` (under Astro's `base`). The route guards
8
+ * nothing: the signed pass is the lock, checked against the repository, site
9
+ * and branch this build was made from.
9
10
  *
10
11
  * This route is the ENTRY DOOR only; the site-wide middleware
11
12
  * (`./site-middleware.ts`) is the serving surface. Three verdicts:
12
13
  *
13
14
  * 1. `response` — the query-token init hop (302 that sets the preview
14
15
  * cookie and points at the clean path) or the no-preview landing page.
15
- * 2. `preview` — a valid cookie on the literal prefixed URL: canonicalize
16
- * with a 302 to the clean path. Rendering under the prefix is never
16
+ * 2. `preview` — a valid cookie on the preview route itself: canonicalize
17
+ * with a 302 to the clean path. Rendering under the route is never
17
18
  * correct (links/assets assume clean paths), and after the redirect the
18
19
  * middleware serves the draft. Normally the middleware canonicalizes
19
20
  * before this route runs — this branch is the defense-in-depth for an
@@ -25,8 +26,9 @@ import { stripPreviewPrefix } from './preview/preview-path.js';
25
26
  import { handlePreviewRequest } from './preview.js';
26
27
 
27
28
  // Same baked-then-env resolution the middleware uses, so the entry route and
28
- // the serving surface can never disagree about the secret. Throws loudly on a
29
- // missing var: reaching this route means someone explicitly asked to preview.
29
+ // the serving surface can never disagree about what this build serves. Throws
30
+ // loudly on a missing value: reaching this route means someone explicitly
31
+ // asked to preview.
30
32
  const opts = resolveFromBaked(bakedPreviewOpts, (name) => process.env[name]);
31
33
  const verdict = await handlePreviewRequest(Astro.request, {
32
34
  ...opts,
@@ -46,7 +48,7 @@ if (verdict.kind === 'pass-through') {
46
48
  }
47
49
 
48
50
  // verdict.kind === 'preview' — canonicalize to the clean site path.
49
- const cleanPath = stripPreviewPrefix(Astro.originPathname ?? Astro.url.pathname);
51
+ const cleanPath = stripPreviewPrefix(Astro.originPathname ?? Astro.url.pathname, opts.base);
50
52
  const canonical: Response = new Response(null, {
51
53
  status: 302,
52
54
  headers: { location: cleanPath, 'cache-control': 'private, no-store' },
package/src/preview.ts CHANGED
@@ -18,5 +18,4 @@ export {
18
18
  type PreviewContext,
19
19
  type PreviewMiddlewareOptions,
20
20
  type PreviewVerdict,
21
- previewParamName,
22
21
  } from './preview/middleware.js';
package/src/repository.ts CHANGED
@@ -13,7 +13,7 @@ const REPO_SEGMENT = /^[A-Za-z0-9_.-]+$/;
13
13
 
14
14
  /**
15
15
  * Normalize a provider full_name or common Git remote into `owner/repo`.
16
- * Deliberately rejects local paths and nested groups: a registration names
16
+ * Deliberately rejects local paths and nested groups: the editor page names
17
17
  * its repository GitHub-style, as two segments.
18
18
  */
19
19
  export function normalizeRepositoryUri(input: string | undefined): string | undefined {
@@ -0,0 +1,37 @@
1
+ import type { EditorDescriptorChannel } from '@conloca/astro-cms/node';
2
+ import { PACKAGE_NAME } from './constants.js';
3
+ import type { ConlocaCloudOptions } from './types.js';
4
+
5
+ /** The editor options `conlocaCMS` already holds, settled for this build. */
6
+ export interface InheritedOptions {
7
+ puckConfigPath: string;
8
+ siteStyles?: string[];
9
+ editorStyles?: string[];
10
+ editorCss?: string;
11
+ }
12
+
13
+ /**
14
+ * Each option given to `conlocaCloud()` wins; the channel `conlocaCMS`
15
+ * published fills the rest. `editorStyles` and `editorCss` come from the
16
+ * channel only. Only `puckConfigPath` is mandatory: without it there is no
17
+ * editor to build.
18
+ */
19
+ export function resolveInheritedOptions(
20
+ options: Pick<ConlocaCloudOptions, 'puckConfigPath' | 'siteStyles'>,
21
+ channel: Pick<EditorDescriptorChannel, 'puckConfigPath' | 'siteStyles' | 'editorStyles' | 'editorCSS'> | undefined,
22
+ ): InheritedOptions {
23
+ const puckConfigPath = options.puckConfigPath ?? channel?.puckConfigPath;
24
+ if (!puckConfigPath) {
25
+ throw new Error(
26
+ `${PACKAGE_NAME}: puckConfigPath is required: add it to conlocaCloud(), or add conlocaCMS() to this site's integrations`,
27
+ );
28
+ }
29
+ const siteStyles =
30
+ typeof options.siteStyles === 'string' ? [options.siteStyles] : (options.siteStyles ?? channel?.siteStyles);
31
+ return {
32
+ puckConfigPath,
33
+ ...(siteStyles === undefined ? {} : { siteStyles }),
34
+ ...(channel?.editorStyles === undefined ? {} : { editorStyles: channel.editorStyles }),
35
+ ...(channel?.editorCSS === undefined ? {} : { editorCss: channel.editorCSS }),
36
+ };
37
+ }
package/src/site-id.ts CHANGED
@@ -1,10 +1,8 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
+ import { SITE_ID_RE } from '@conloca/content-api/editor-host';
3
4
  import { PACKAGE_NAME } from './constants.js';
4
5
 
5
- /** The site-id grammar: lowercase alphanumerics and dashes, 1-64 chars, alphanumeric first. */
6
- export const SITE_ID_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
7
-
8
6
  /**
9
7
  * Resolve the build's deployable-site id. STRICT: malformed input fails the
10
8
  * build — a silent mis-attach is the same "deployed, but the editor points at
@@ -55,7 +53,7 @@ export function resolveBuildSiteId(opts: {
55
53
  typeof record.sites !== 'object' ||
56
54
  Array.isArray(record.sites)
57
55
  ) {
58
- throw new Error(`${PACKAGE_NAME}: ${path} has no "sites" object — refusing to register a broken content model`);
56
+ throw new Error(`${PACKAGE_NAME}: ${path} has no "sites" object — refusing to build on a broken content model`);
59
57
  }
60
58
 
61
59
  let resolved: string;
@@ -1,69 +1,65 @@
1
1
  ---
2
2
  name: conloca-cloud
3
- description: Load when a Conloca site uses @conloca/cloud-astro — editor endpoint, build token, registrations, preview.
3
+ description: Load when a Conloca site uses @conloca/cloud-astro — conloca connect, the editor page, framing, doctor.
4
4
  ---
5
5
 
6
- # Connecting a site to an editor endpoint
6
+ # Connecting a site to the workspace editor
7
7
 
8
- `conlocaCloud(...)` from `@conloca/cloud-astro` is an add-on to `conlocaCMS(...)` — keep both in `integrations`. It
9
- hooks the site's `astro build` to compile the Puck config into an editor bundle, register that build at `endpoint`, and
10
- produce a draft-preview app. Nothing from it runs on the published site.
8
+ `conlocaCloud()` from `@conloca/cloud-astro` is an add-on to `conlocaCMS(...)` — keep both in `integrations`, after
9
+ `react()`. It needs no options: it takes `puckConfigPath` and `siteStyles` from `conlocaCMS` and builds for the
10
+ workspace editor at `https://app.conloca.com`. Each `astro build` adds the editor page under `_conloca/editor/` in the
11
+ output; the workspace editor at `<slug>.conloca.com` opens the deployed page in a frame. Nothing else of it runs on the
12
+ published site. There is no build key, secret or environment variable.
11
13
 
12
- ## First move: `conloca doctor --live`
13
-
14
- For any question about the editor at `endpoint` — editor not loading, a stale editor after a deploy, "is this branch
15
- registered?" — run this before reading source:
14
+ ## Set up: connect → commit → push → deploy → open
16
15
 
17
16
  ```bash
18
- CONLOCA_BUILD_TOKEN=cbt_... conloca doctor --live # add CONLOCA_ENDPOINT=https://... when the config computes endpoint
19
- conloca doctor # offline: config, token, endpoint, inert options
17
+ npx @conloca/cli connect # in the site's folder; add --yes when no terminal can answer
20
18
  ```
21
19
 
22
- This package's checks are `CC1`–`CC8`. Offline: the wiring, the build token, the endpoint and public base URL,
23
- `conlocaCMS` options the endpoint's editor ignores, and (CC8) whether a static project keeps the preview build off. With
24
- `--live` (the token goes only to the configured endpoint): the endpoint answers the token, a registration serves this
25
- branch and site, and the editor bundle that registration names is still deployed.
26
-
27
- ## The one secret: the build token
28
-
29
- `CONLOCA_BUILD_TOKEN=cbt_<id>.<secret>` is issued by the endpoint and set as a CI secret. It authenticates the build —
30
- no other setup, no OIDC. Repository identity comes from CI metadata (`GITHUB_REPOSITORY`, Vercel, GitLab) or the git
31
- remote; `repoUri` is only for non-standard checkouts. The `endpoint` is an https URL with no trailing slash.
32
-
33
- **Whole-line gotcha:** the endpoint shows and copies the token as the line `CONLOCA_BUILD_TOKEN=cbt_…`. Pasted whole
34
- into a secret's value, doctor CC2 reports it and the build's registration answers `401`; the token is fine — store only
35
- the part from `cbt_`.
36
-
37
- **Rotation gotcha:** creating a new token invalidates the old one. A `401` from the endpoint for a value that does start
38
- with `cbt_` (doctor CC5) means the CI secret still holds a rotated token — create a new one and update the secret.
39
-
40
- ## The pipeline: build → register → editor
20
+ `connect` installs the packages, wires `astro.config` (writing `repoUri` from a GitHub `origin`), writes the site's host
21
+ into `sites.json`, adds a framing rule only where a committed header file forbids framing, builds once to check the
22
+ editor page, and removes old build key lines from workflows. It shows diffs first, keeps values you set (`differs`), and
23
+ exits `2` with the lines to add when a step needs a person (`--site-url https://…` when `astro.config` has no `site`).
24
+ It never commits, pushes or deploys: commit, push to the default branch, deploy as usual, then open the workspace
25
+ editor. Editing needs the deployed site; before that, `astro dev` serves the local editor at `/__cms`.
41
26
 
42
- 1. `astro build` with the token compiles `dist/_conloca/editor-bundle.<hash>.js` and POSTs a registration naming the
43
- repo, git sha, branch, site id, and the bundle URL + hash.
44
- 2. The editor at `endpoint`, opened on a branch, loads the NEWEST registration for `(branch, site)`.
45
- 3. A build without a prerequisite (token, repo identity, sha/branch, public base URL) does not register; it warns and
46
- ends with a summary block. Set `requireRegistration: true` in CI to fail such builds. A registration the endpoint
47
- REJECTS always fails the build.
48
-
49
- ## Three states of a branch (doctor CC6)
50
-
51
- - **Own registration** — the branch was built with the token; the editor loads its bundle.
52
- - **Inherited** — no registration for this branch, but the default branch has one: the editor works from that bundle and
53
- draft preview is degraded. Build the branch with the token to register it.
54
- - **None** — neither: the editor will not load for this branch. Build it with the token.
55
-
56
- Doctor may also report older registrations that are not active yet. They become active the next time the editor opens,
57
- so a branch served only by them is a warning rather than "will not load" — it fails only if that branch has since grown
58
- a second site.
59
-
60
- ## A deleted bundle (CC7)
27
+ ## First move: `conloca doctor --live`
61
28
 
62
- A registration can outlive its bytes: a later deploy from another branch replaces `dist/`, and the registration still
63
- points at a bundle URL that now 404s. Nothing else notices — the editor just fails to load. `conloca doctor --live`
64
- probes the bundle URL the registration names and says so: rebuild and deploy from that branch.
29
+ For any question about the workspace editor — "Connect this site" stays, the frame stays blank, old components after a
30
+ deploy — run this before reading source:
65
31
 
66
- ## Options with no effect on the endpoint's editor
32
+ ```bash
33
+ conloca doctor --live # sends no credential: only your site's host and the editor's /host/protocols.json
34
+ conloca doctor # offline: wiring, sites.json host, committed framing headers, key leftovers
35
+ ```
67
36
 
68
- `conlocaCMS`'s `editorStyles` and `editorCSS` configure the local dev editor only. `templates`, `schemasPath`, and
69
- `mdxComponentFolders` reach the endpoint's editor automatically.
37
+ This package's checks are `CC1` and `CC8`–`CC14`:
38
+
39
+ - **CC9** — `sites.json`: the site named `default` (or the only one) has a bare host in `domains[defaultLocale]` and a
40
+ valid `base`. The editor opens `https://<host><base>_conloca/editor/`; it refuses IPs, `localhost`, `*.conloca.com`.
41
+ - **CC10** — a committed `public/_headers`, `netlify.toml` or `vercel.json` sets `X-Frame-Options` or `frame-ancestors`
42
+ site-wide with no `/_conloca/editor/` rule. Fix: `connect`, or the rule the error prints.
43
+ - **CC11** (live) — `conloca.json` is deployed, public, and names this repository and site. "names no repository" → set
44
+ `repoUri` in `conlocaCloud(...)`. Serving an older commit than HEAD is a warning: deploy.
45
+ - **CC12** (live) — the deployed page may be framed by `https://*.conloca.com`, and its `script-src` allows the editor's
46
+ origin. Headers from host settings or a proxy show up only here.
47
+ - **CC13** (live) — the page's protocol is in the editor's range; too old → rebuild with a newer `@conloca/cloud-astro`.
48
+ - **CC14** — a workflow or the config still names `CONLOCA_BUILD_TOKEN`, `buildToken`, `publicBaseUrl`, `previewDomain`
49
+ or `requireRegistration`. Remove them; nothing reads them for the editor page.
50
+
51
+ ## Framing: only when the site forbids it
52
+
53
+ A site sending no `X-Frame-Options` and no `frame-ancestors` needs nothing (GitHub Pages included). Otherwise
54
+ `/_conloca/editor/*` needs `Content-Security-Policy: frame-ancestors 'self' https://*.conloca.com`, plus
55
+ `/_conloca/editor/sandbox-frame.html` → `Content-Security-Policy: sandbox allow-scripts`. Cloudflare `_headers` also
56
+ detaches the site's headers on that path (`! X-Frame-Options`, `! Content-Security-Policy`); Netlify cannot detach;
57
+ Vercel uses `source: "/_conloca/editor/:path*"`. A site-wide CSP with `frame-ancestors` must be narrowed by hand — a
58
+ second policy cannot loosen it.
59
+
60
+ ## Components come from the branch's deploy
61
+
62
+ On other branches the editor offers the components of the deploy whose code is closest to the branch's latest commit:
63
+ the branch's own deploy, the default branch's, or a build of the branch it was created from (labelled in the editor), on
64
+ a tie in that order, with a warning when the components may differ from the branch's code. Doctor's CC11 warning still
65
+ says which commit is live.
package/src/types.ts CHANGED
@@ -5,8 +5,9 @@ import type { AstroIntegration } from 'astro';
5
5
  * site's production build completes. The preview build emits the SSR routes
6
6
  * that serve draft preview.
7
7
  *
8
- * Set to `false` to explicitly opt out of preview builds for sites that do not
9
- * need a draft/preview pipeline.
8
+ * Off unless given as an object: the second build that serves draft previews.
9
+ * It needs an SSR adapter (the project's own or `adapter` here) and is refused
10
+ * under `@astrojs/vercel` and `@astrojs/netlify`.
10
11
  */
11
12
  export interface PreviewBuildOptions {
12
13
  /**
@@ -20,8 +21,8 @@ export interface PreviewBuildOptions {
20
21
  config?: Record<string, unknown>;
21
22
  /**
22
23
  * Output directory for the preview build. Defaults to `.conloca/preview-server`
23
- * — outside `dist/`, so the secret-baked artifact can never ride a wholesale
24
- * static upload of the site and Astro's dist-clearing cannot wipe it.
24
+ * — outside `dist/`, so the preview server can never ride a wholesale static
25
+ * upload of the site and Astro's dist-clearing cannot wipe it.
25
26
  */
26
27
  outDir?: string;
27
28
  /**
@@ -32,20 +33,20 @@ export interface PreviewBuildOptions {
32
33
  }
33
34
 
34
35
  /**
35
- * Options accepted by {@link conlocaCloud}.
36
- *
37
- * Registration authenticates with one build token (`cbt_<id>.<secret>`)
38
- * issued by the endpoint. Repository identity is normally detected from CI metadata or the Git
39
- * checkout.
36
+ * Options accepted by {@link conlocaCloud}. Every one is optional: repository
37
+ * identity is normally detected from CI metadata or the Git checkout, and the
38
+ * editor options come from `conlocaCMS`.
40
39
  */
41
40
  export interface ConlocaCloudOptions {
42
- /** Editor endpoint, e.g. 'https://cms.example.com', no trailing slash. */
43
- endpoint: string;
41
+ /**
42
+ * The workspace editor's address, no trailing slash. Defaults to
43
+ * 'https://app.conloca.com'. Its host must start with `app.`.
44
+ */
45
+ endpoint?: string;
44
46
  /**
45
47
  * Advanced override for repository identity, normalized to `owner/repo`.
46
48
  * Normally omit this: Conloca detects GitHub, Vercel, or GitLab CI metadata,
47
- * then falls back to the checkout's `remote.origin.url`. Registration is
48
- * rejected when the token does not cover the detected repo.
49
+ * then falls back to the checkout's `remote.origin.url`.
49
50
  */
50
51
  repoUri?: string;
51
52
  /**
@@ -55,58 +56,27 @@ export interface ConlocaCloudOptions {
55
56
  * that contradicts it fails the build — never a silent pick.
56
57
  */
57
58
  siteId?: string;
58
- /**
59
- * Build token issued by the endpoint. Prefer injecting it via the
60
- * CONLOCA_BUILD_TOKEN environment variable instead of committing it here;
61
- * when neither is present the build skips registration (fail soft, unless
62
- * `requireRegistration` is set).
63
- */
64
- buildToken?: string;
65
59
  /**
66
60
  * Entry module of the puck config to compile into the editor bundle,
67
61
  * e.g. './src/puck.config.tsx'. Same option name as @conloca/astro-cms.
62
+ * Defaults to the `conlocaCMS` value.
68
63
  */
69
- puckConfigPath: string;
64
+ puckConfigPath?: string;
70
65
  /**
71
66
  * Site CSS for accurate preview rendering — same option name and shape
72
67
  * as `conlocaCMS({ siteStyles })`, and compiled the same way: by the site's
73
68
  * own Vite pipeline (its plugins, PostCSS config and preprocessors), into
74
- * the canvas stylesheet each build registers, ahead of the
69
+ * the editor page's canvas stylesheet, ahead of the
75
70
  * component modules, e.g. './src/styles/index.scss'. Paths resolve against
76
71
  * the project root. The assets these stylesheets reference are emitted under
77
- * `/_conloca/`, and an entry that fails to compile fails the build. Component
72
+ * `/_conloca/editor/`, and an entry that fails to compile fails the build. Component
78
73
  * `*.module.(s)css` imports compile in automatically — list here only what
79
- * lives outside the component graph.
74
+ * lives outside the component graph. Defaults to the `conlocaCMS` value.
80
75
  */
81
76
  siteStyles?: string | string[];
82
77
  /**
83
- * Representative content route for build-time style discovery — the SAME
84
- * name and meaning as `conlocaCMS`'s option: the page whose styles and
85
- * content-wrapper shape prose editing should adopt. When set, the build
86
- * reads that route's rendered page (a prerendered file, or the booted node
87
- * server entry), collects its CSS and wrapper shape, and registers them
88
- * alongside the bundle. Unset: discovery is skipped and the editor falls
89
- * back to the prose-safe derived tier.
90
- *
91
- * @example '/blog/welcome-post'
92
- */
93
- fragmentPreviewRoute?: string;
94
-
95
- /**
96
- * Public base URL of the deployed site, used to absolutize the editor
97
- * bundle URL when no dedicated preview domain is configured. Falls back to
98
- * the CF_PAGES_URL env var; without either, registration is skipped.
99
- */
100
- publicBaseUrl?: string;
101
- /**
102
- * Optional dedicated preview deployment as a hostname or absolute URL. A
103
- * hostname is normalized to HTTPS. When set, editor assets and preview links
104
- * use this deployment instead of the production site's public base URL.
105
- */
106
- previewDomain?: string;
107
- /**
108
- * Recursive preview build configuration. Set to `false` to opt out.
109
- * Defaults to enabled with project defaults.
78
+ * Off unless given as an object; the second build that serves draft
79
+ * previews. Refused under @astrojs/vercel and @astrojs/netlify.
110
80
  */
111
81
  previewBuild?: PreviewBuildOptions | false;
112
82
  /**
@@ -115,13 +85,4 @@ export interface ConlocaCloudOptions {
115
85
  * deployment must supply `CONLOCA_SAAS_ISSUER` at runtime.
116
86
  */
117
87
  saasIssuer?: string;
118
- /**
119
- * Fail the build when registration is SKIPPED for a missing prerequisite
120
- * (no build token, no repository identity, no git sha/branch, no public
121
- * base URL). Default false, so a plain `astro build` without the token
122
- * stays untouched. Turn it on in CI once setup is done: a deploy can
123
- * then never silently leave the editor at the endpoint stale. An ATTEMPTED
124
- * registration that fails always fails the build, regardless of this.
125
- */
126
- requireRegistration?: boolean;
127
88
  }
@@ -11,10 +11,14 @@
11
11
  */
12
12
  declare module 'virtual:conloca-preview-opts' {
13
13
  const baked: {
14
- secret?: string;
15
14
  saasEndpoint?: string;
16
15
  saasIssuer?: string;
17
16
  saasAudience?: string;
17
+ buildCommit?: string;
18
+ repo?: string;
19
+ siteId?: string;
20
+ branch?: string;
21
+ base?: string;
18
22
  };
19
23
  export default baked;
20
24
  }
@@ -1,19 +0,0 @@
1
- /**
2
- * The commit a registration names and the commit the artifact was built from.
3
- * They differ only when CI hands over the branch's latest commit
4
- * (`CF_PAGES_COMMIT_SHA`) while building another commit — a pull request's
5
- * merge commit — because the endpoint can only serve a commit the branch
6
- * actually carries.
7
- */
8
- export interface RegistrationCommits {
9
- gitSha: string | undefined;
10
- buildId: string | undefined;
11
- }
12
- /** Resolves which commit the registration names and which commit produced the bundle. */
13
- export declare function registrationCommits(input: {
14
- /** The branch's latest commit, as CI hands it over through CF_PAGES_COMMIT_SHA. */
15
- eventCommitSha: string | undefined;
16
- /** git rev-parse HEAD in the build checkout. */
17
- checkoutCommitSha: string | undefined;
18
- }): RegistrationCommits;
19
- //# sourceMappingURL=build-commit.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"build-commit.d.ts","sourceRoot":"","sources":["../../src/build-commit.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B;AAED,yFAAyF;AACzF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE;IACzC,mFAAmF;IACnF,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,gDAAgD;IAChD,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAC;CACvC,GAAG,mBAAmB,CAGtB"}
@@ -1,6 +0,0 @@
1
- /** Resolves which commit the registration names and which commit produced the bundle. */
2
- export function registrationCommits(input) {
3
- const gitSha = input.eventCommitSha ?? input.checkoutCommitSha;
4
- return { gitSha, buildId: input.checkoutCommitSha ?? gitSha };
5
- }
6
- //# sourceMappingURL=build-commit.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"build-commit.js","sourceRoot":"","sources":["../../src/build-commit.ts"],"names":[],"mappings":"AAYA,yFAAyF;AACzF,MAAM,UAAU,mBAAmB,CAAC,KAKnC;IACC,MAAM,MAAM,GAAG,KAAK,CAAC,cAAc,IAAI,KAAK,CAAC,iBAAiB,CAAC;IAC/D,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,iBAAiB,IAAI,MAAM,EAAE,CAAC;AAChE,CAAC"}