@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.
- package/README.md +261 -207
- package/dist/.build-inputs.json +60 -0
- package/dist/src/component-manifest.d.ts +5 -3
- package/dist/src/component-manifest.d.ts.map +1 -1
- package/dist/src/component-manifest.js +7 -7
- package/dist/src/component-manifest.js.map +1 -1
- package/dist/src/constants.d.ts +5 -13
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +5 -13
- package/dist/src/constants.js.map +1 -1
- package/dist/src/descriptors.d.ts +2 -2
- package/dist/src/descriptors.d.ts.map +1 -1
- package/dist/src/doctor/checks-address.d.ts +18 -0
- package/dist/src/doctor/checks-address.d.ts.map +1 -0
- package/dist/src/doctor/checks-address.js +163 -0
- package/dist/src/doctor/checks-address.js.map +1 -0
- package/dist/src/doctor/checks-live.d.ts +8 -5
- package/dist/src/doctor/checks-live.d.ts.map +1 -1
- package/dist/src/doctor/checks-live.js +220 -188
- package/dist/src/doctor/checks-live.js.map +1 -1
- package/dist/src/doctor/checks-offline.d.ts +8 -23
- package/dist/src/doctor/checks-offline.d.ts.map +1 -1
- package/dist/src/doctor/checks-offline.js +22 -239
- package/dist/src/doctor/checks-offline.js.map +1 -1
- package/dist/src/doctor/config-scan.d.ts +6 -3
- package/dist/src/doctor/config-scan.d.ts.map +1 -1
- package/dist/src/doctor/config-scan.js +21 -11
- package/dist/src/doctor/config-scan.js.map +1 -1
- package/dist/src/doctor/run.d.ts.map +1 -1
- package/dist/src/doctor/run.js +12 -10
- package/dist/src/doctor/run.js.map +1 -1
- package/dist/src/doctor/types.d.ts +7 -7
- package/dist/src/doctor/types.d.ts.map +1 -1
- package/dist/src/doctor/types.js +7 -7
- package/dist/src/doctor/types.js.map +1 -1
- package/dist/src/editor-page/bundle.d.ts +88 -0
- package/dist/src/editor-page/bundle.d.ts.map +1 -0
- package/dist/src/editor-page/bundle.js +370 -0
- package/dist/src/editor-page/bundle.js.map +1 -0
- package/dist/src/editor-page/emit.d.ts +33 -0
- package/dist/src/editor-page/emit.d.ts.map +1 -0
- package/dist/src/editor-page/emit.js +183 -0
- package/dist/src/editor-page/emit.js.map +1 -0
- package/dist/src/editor-page/framing.d.ts +23 -0
- package/dist/src/editor-page/framing.d.ts.map +1 -0
- package/dist/src/editor-page/framing.js +39 -0
- package/dist/src/editor-page/framing.js.map +1 -0
- package/dist/src/editor-page/page.d.ts +9 -0
- package/dist/src/editor-page/page.d.ts.map +1 -0
- package/dist/src/editor-page/page.js +31 -0
- package/dist/src/editor-page/page.js.map +1 -0
- package/dist/src/editor-page/site-base.d.ts +4 -0
- package/dist/src/editor-page/site-base.d.ts.map +1 -0
- package/dist/src/editor-page/site-base.js +13 -0
- package/dist/src/editor-page/site-base.js.map +1 -0
- package/dist/src/git.d.ts +11 -8
- package/dist/src/git.d.ts.map +1 -1
- package/dist/src/git.js +25 -8
- package/dist/src/git.js.map +1 -1
- package/dist/src/index.d.ts +3 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +9 -6
- package/dist/src/index.js.map +1 -1
- package/dist/src/integration.d.ts +1 -1
- package/dist/src/integration.d.ts.map +1 -1
- package/dist/src/integration.js +245 -396
- package/dist/src/integration.js.map +1 -1
- package/dist/src/node.d.ts +3 -1
- package/dist/src/node.d.ts.map +1 -1
- package/dist/src/node.js +7 -2
- package/dist/src/node.js.map +1 -1
- package/dist/src/preview/_dispatch.d.ts +5 -2
- package/dist/src/preview/_dispatch.d.ts.map +1 -1
- package/dist/src/preview/_dispatch.js +2 -0
- package/dist/src/preview/_dispatch.js.map +1 -1
- package/dist/src/preview/_resolve-opts.d.ts +18 -10
- package/dist/src/preview/_resolve-opts.d.ts.map +1 -1
- package/dist/src/preview/_resolve-opts.js +24 -10
- package/dist/src/preview/_resolve-opts.js.map +1 -1
- package/dist/src/preview/banner.d.ts.map +1 -1
- package/dist/src/preview/banner.js +2 -4
- package/dist/src/preview/banner.js.map +1 -1
- package/dist/src/preview/cookie.d.ts +5 -2
- package/dist/src/preview/cookie.d.ts.map +1 -1
- package/dist/src/preview/cookie.js +5 -2
- package/dist/src/preview/cookie.js.map +1 -1
- package/dist/src/preview/label.d.ts +8 -0
- package/dist/src/preview/label.d.ts.map +1 -0
- package/dist/src/preview/label.js +14 -0
- package/dist/src/preview/label.js.map +1 -0
- package/dist/src/preview/landing.d.ts +2 -2
- package/dist/src/preview/landing.js +2 -2
- package/dist/src/preview/middleware.d.ts +31 -20
- package/dist/src/preview/middleware.d.ts.map +1 -1
- package/dist/src/preview/middleware.js +56 -51
- package/dist/src/preview/middleware.js.map +1 -1
- package/dist/src/preview/preview-path.d.ts +18 -5
- package/dist/src/preview/preview-path.d.ts.map +1 -1
- package/dist/src/preview/preview-path.js +24 -8
- package/dist/src/preview/preview-path.js.map +1 -1
- package/dist/src/preview/site-middleware.d.ts +5 -5
- package/dist/src/preview/site-middleware.d.ts.map +1 -1
- package/dist/src/preview/site-middleware.js +17 -16
- package/dist/src/preview/site-middleware.js.map +1 -1
- package/dist/src/preview-build.d.ts +18 -15
- package/dist/src/preview-build.d.ts.map +1 -1
- package/dist/src/preview-build.js +36 -21
- package/dist/src/preview-build.js.map +1 -1
- package/dist/src/preview.d.ts +1 -1
- package/dist/src/preview.d.ts.map +1 -1
- package/dist/src/preview.js +1 -1
- package/dist/src/preview.js.map +1 -1
- package/dist/src/repository.d.ts +1 -1
- package/dist/src/repository.js +1 -1
- package/dist/src/resolve-options.d.ts +17 -0
- package/dist/src/resolve-options.d.ts.map +1 -0
- package/dist/src/resolve-options.js +21 -0
- package/dist/src/resolve-options.js.map +1 -0
- package/dist/src/site-id.d.ts +0 -2
- package/dist/src/site-id.d.ts.map +1 -1
- package/dist/src/site-id.js +2 -3
- package/dist/src/site-id.js.map +1 -1
- package/dist/src/types.d.ts +21 -59
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +44 -15
- package/src/component-manifest.ts +11 -8
- package/src/constants.ts +5 -14
- package/src/descriptors.ts +2 -2
- package/src/doctor/checks-address.ts +190 -0
- package/src/doctor/checks-live.ts +256 -268
- package/src/doctor/checks-offline.ts +24 -262
- package/src/doctor/config-scan.ts +21 -9
- package/src/doctor/run.ts +14 -16
- package/src/doctor/types.ts +7 -7
- package/src/editor-page/bundle.ts +482 -0
- package/src/editor-page/emit.ts +246 -0
- package/src/editor-page/framing.ts +62 -0
- package/src/editor-page/page.ts +37 -0
- package/src/editor-page/site-base.ts +11 -0
- package/src/git.ts +29 -10
- package/src/index.ts +20 -6
- package/src/integration.ts +255 -449
- package/src/node.ts +18 -2
- package/src/preview/_dispatch.ts +6 -2
- package/src/preview/_resolve-opts.ts +34 -11
- package/src/preview/banner.ts +2 -4
- package/src/preview/cookie.ts +5 -2
- package/src/preview/label.ts +12 -0
- package/src/preview/landing.ts +2 -2
- package/src/preview/middleware.ts +83 -66
- package/src/preview/preview-path.ts +26 -8
- package/src/preview/site-middleware.ts +17 -21
- package/src/preview-build.ts +42 -26
- package/src/preview-handler.astro +10 -8
- package/src/preview.ts +0 -1
- package/src/repository.ts +1 -1
- package/src/resolve-options.ts +37 -0
- package/src/site-id.ts +2 -4
- package/src/skill/SKILL.md +51 -55
- package/src/types.ts +21 -60
- package/src/virtual-modules.d.ts +5 -1
- package/dist/src/build-commit.d.ts +0 -19
- package/dist/src/build-commit.d.ts.map +0 -1
- package/dist/src/build-commit.js +0 -6
- package/dist/src/build-commit.js.map +0 -1
- package/dist/src/bundle.d.ts +0 -173
- package/dist/src/bundle.d.ts.map +0 -1
- package/dist/src/bundle.js +0 -413
- package/dist/src/bundle.js.map +0 -1
- package/dist/src/discovery.d.ts +0 -58
- package/dist/src/discovery.d.ts.map +0 -1
- package/dist/src/discovery.js +0 -133
- package/dist/src/discovery.js.map +0 -1
- package/dist/src/register.d.ts +0 -98
- package/dist/src/register.d.ts.map +0 -1
- package/dist/src/register.js +0 -103
- package/dist/src/register.js.map +0 -1
- package/src/build-commit.ts +0 -22
- package/src/bundle.ts +0 -563
- package/src/discovery.ts +0 -183
- package/src/register.ts +0 -180
package/src/preview-build.ts
CHANGED
|
@@ -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,
|
|
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
|
-
|
|
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 +
|
|
29
|
-
*
|
|
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
|
|
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
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
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(
|
|
92
|
-
await _spawnPreviewBuildWith(spawn,
|
|
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
|
-
|
|
104
|
-
|
|
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
|
|
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
|
-
*
|
|
7
|
-
* `/
|
|
8
|
-
*
|
|
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
|
|
16
|
-
* with a 302 to the clean path. Rendering under the
|
|
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
|
|
29
|
-
// missing
|
|
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
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:
|
|
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
|
|
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;
|
package/src/skill/SKILL.md
CHANGED
|
@@ -1,69 +1,65 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: conloca-cloud
|
|
3
|
-
description: Load when a Conloca site uses @conloca/cloud-astro —
|
|
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
|
|
6
|
+
# Connecting a site to the workspace editor
|
|
7
7
|
|
|
8
|
-
`conlocaCloud(
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
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
|
-
|
|
23
|
-
`
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
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
|
-
|
|
63
|
-
|
|
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
|
-
|
|
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
|
-
|
|
69
|
-
|
|
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
|
-
*
|
|
9
|
-
*
|
|
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
|
|
24
|
-
*
|
|
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
|
-
*
|
|
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
|
-
/**
|
|
43
|
-
|
|
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`.
|
|
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
|
|
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
|
|
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
|
-
*
|
|
84
|
-
*
|
|
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
|
}
|
package/src/virtual-modules.d.ts
CHANGED
|
@@ -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"}
|
package/dist/src/build-commit.js
DELETED
|
@@ -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"}
|