@conloca/cloud-astro 0.2.2 → 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 -208
- 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 -408
- 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/_resolve-opts.d.ts +16 -10
- package/dist/src/preview/_resolve-opts.d.ts.map +1 -1
- package/dist/src/preview/_resolve-opts.js +21 -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 +25 -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 +16 -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 -69
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +37 -13
- 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 -461
- package/src/node.ts +18 -2
- package/src/preview/_resolve-opts.ts +29 -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 +77 -66
- package/src/preview/preview-path.ts +26 -8
- package/src/preview/site-middleware.ts +16 -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 -70
- package/src/virtual-modules.d.ts +4 -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 -181
- 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 -570
- package/src/discovery.ts +0 -183
- package/src/register.ts +0 -180
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
classifyEditorHostResponse,
|
|
3
|
+
classifyFrameHeaders,
|
|
4
|
+
EDITOR_HOST_PROTOCOL,
|
|
5
|
+
EDITOR_PAGE_PATH,
|
|
6
|
+
type EditorPageInfo,
|
|
7
|
+
editorUiOrigin,
|
|
8
|
+
isFromVercel,
|
|
9
|
+
parentRoot,
|
|
10
|
+
} from '@conloca/content-api/editor-host';
|
|
3
11
|
import { messageOf } from '../message-of.js';
|
|
4
12
|
import { resolveBuildSiteId } from '../site-id.js';
|
|
5
|
-
import {
|
|
13
|
+
import { INTEGRATION_NOT_CALLED, suppliedEndpoint } from './checks-offline.js';
|
|
6
14
|
import { type ConfigScan, optionLiteral } from './config-scan.js';
|
|
7
15
|
import {
|
|
8
16
|
type CheckId,
|
|
@@ -13,312 +21,292 @@ import {
|
|
|
13
21
|
skipped,
|
|
14
22
|
} from './types.js';
|
|
15
23
|
|
|
16
|
-
const LIVE_CHECK_IDS: readonly CheckId[] = ['
|
|
24
|
+
const LIVE_CHECK_IDS: readonly CheckId[] = ['CC11', 'CC12', 'CC13'];
|
|
17
25
|
|
|
18
26
|
/** Every doctor request is bounded: a hanging host must never hang `conloca doctor` (the CLI seam has no timer of its own). */
|
|
19
27
|
const REQUEST_TIMEOUT_MS = 10_000;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function builtWithNote(value: string | null | undefined): string {
|
|
25
|
-
return typeof value === 'string' && VERSION_SHAPE.test(value) ? ` (built with ${PACKAGE_NAME} ${value})` : '';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** One row of the endpoint's status route (`GET /api/v1/registrations/status`). */
|
|
29
|
-
interface StatusRegistration {
|
|
30
|
-
/**
|
|
31
|
-
* Absent on the wire for active rows; true for an older row with no site id yet, which becomes active the next
|
|
32
|
-
* time the editor opens.
|
|
33
|
-
*/
|
|
34
|
-
parked?: boolean;
|
|
35
|
-
branch: string;
|
|
36
|
-
siteId: string | null;
|
|
37
|
-
gitSha: string;
|
|
38
|
-
registeredAt: number;
|
|
39
|
-
editorBundleUrl: string;
|
|
40
|
-
/** Absent when the endpoint predates the field; null when the build that registered sent none. */
|
|
41
|
-
clientVersion?: string | null;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
interface StatusResponse {
|
|
45
|
-
defaultBranch: string | null;
|
|
46
|
-
registrations: StatusRegistration[];
|
|
47
|
-
}
|
|
28
|
+
/** The server probe's conloca.json cap; a longer answer reads as `invalid` here as there. */
|
|
29
|
+
const CONLOCA_JSON_CAP_BYTES = 16 * 1024;
|
|
30
|
+
/** CC11 judges everything but the protocol; CC13 holds that against the range the editor publishes. */
|
|
31
|
+
const ANY_PROTOCOL = { min: Number.NEGATIVE_INFINITY, max: Number.POSITIVE_INFINITY };
|
|
48
32
|
|
|
49
33
|
interface LiveInput {
|
|
50
34
|
context: CloudDoctorContext;
|
|
51
35
|
deps: DoctorDeps;
|
|
52
36
|
scan: ConfigScan;
|
|
53
|
-
/**
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
|
|
37
|
+
/** CC9's verdict: `https://<host><base>`, undefined when CC9 failed. */
|
|
38
|
+
address: string | undefined;
|
|
39
|
+
/** What the build writes as `repo`, undefined when it cannot tell. */
|
|
40
|
+
repoUri: string | undefined;
|
|
57
41
|
}
|
|
58
42
|
|
|
59
43
|
const skipAll = (reason: string): CheckOutcome[] => LIVE_CHECK_IDS.map((id) => skipped(id, reason));
|
|
60
44
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const row = value as Record<string, unknown>;
|
|
64
|
-
return (
|
|
65
|
-
typeof row.branch === 'string' &&
|
|
66
|
-
typeof row.gitSha === 'string' &&
|
|
67
|
-
typeof row.editorBundleUrl === 'string' &&
|
|
68
|
-
typeof row.registeredAt === 'number' &&
|
|
69
|
-
(row.siteId === null || typeof row.siteId === 'string') &&
|
|
70
|
-
(row.parked === undefined || typeof row.parked === 'boolean') &&
|
|
71
|
-
(row.clientVersion === undefined || row.clientVersion === null || typeof row.clientVersion === 'string')
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** Every field the checks read, so an endpoint drift fails CC5 loudly instead of surfacing as a broken CC6/CC7. */
|
|
76
|
-
function isStatusResponse(value: unknown): value is StatusResponse {
|
|
77
|
-
if (typeof value !== 'object' || value === null) return false;
|
|
78
|
-
const body = value as Record<string, unknown>;
|
|
79
|
-
return (
|
|
80
|
-
(body.defaultBranch === null || typeof body.defaultBranch === 'string') &&
|
|
81
|
-
Array.isArray(body.registrations) &&
|
|
82
|
-
body.registrations.every(isStatusRegistration)
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
type StatusProbe = { outcome: CheckOutcome } & ({ body: StatusResponse } | { skipReason: string });
|
|
87
|
-
|
|
88
|
-
interface StatusTarget {
|
|
89
|
-
token: string;
|
|
90
|
-
endpoint: string;
|
|
91
|
-
repoUri: string;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function statusFailed(outcome: CheckOutcome, message: string, skipReason: string): StatusProbe {
|
|
95
|
-
outcome.problems.push({ check: 'CC5', level: 'error', message });
|
|
96
|
-
return { outcome, skipReason };
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* CC5 — GET the status route with the token, joining the path exactly as the
|
|
101
|
-
* build does (register.ts) so --live reproduces the build's own request. 200
|
|
102
|
-
* and 401 both prove reachability; only 200 yields rows.
|
|
103
|
-
*/
|
|
104
|
-
async function probeStatus(fetchFn: DoctorDeps['fetch'], target: StatusTarget): Promise<StatusProbe> {
|
|
105
|
-
const outcome = outcomeOf('CC5');
|
|
106
|
-
const url = `${target.endpoint}/api/v1/registrations/status?repoUri=${encodeURIComponent(target.repoUri)}`;
|
|
107
|
-
let response: Response;
|
|
45
|
+
/** GET with no credential and no followed redirect: the answer the server's probe would see. */
|
|
46
|
+
async function request(fetchFn: DoctorDeps['fetch'], url: string): Promise<Response | Error> {
|
|
108
47
|
try {
|
|
109
|
-
|
|
110
|
-
|
|
48
|
+
return await fetchFn(url, {
|
|
49
|
+
method: 'GET',
|
|
50
|
+
redirect: 'manual',
|
|
51
|
+
credentials: 'omit',
|
|
111
52
|
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
112
53
|
});
|
|
113
54
|
} catch (error) {
|
|
114
|
-
return
|
|
115
|
-
outcome,
|
|
116
|
-
`endpoint ${target.endpoint} is unreachable (${messageOf(error)}) — check the endpoint option and network access from this machine`,
|
|
117
|
-
'the endpoint is unreachable',
|
|
118
|
-
);
|
|
55
|
+
return new Error(messageOf(error));
|
|
119
56
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
if (response.status === 403) {
|
|
128
|
-
return statusFailed(
|
|
129
|
-
outcome,
|
|
130
|
-
`the token does not cover ${target.repoUri} — give the endpoint access to that repository or fix repoUri`,
|
|
131
|
-
'the repository is not covered by the token',
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
if (!response.ok) {
|
|
135
|
-
return statusFailed(
|
|
136
|
-
outcome,
|
|
137
|
-
`endpoint answered HTTP ${response.status} for the registration status — the endpoint may predate this check; update it or retry`,
|
|
138
|
-
`the status route answered HTTP ${response.status}`,
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
let body: unknown;
|
|
142
|
-
try {
|
|
143
|
-
body = await response.json();
|
|
144
|
-
} catch {
|
|
145
|
-
return statusFailed(
|
|
146
|
-
outcome,
|
|
147
|
-
'the endpoint answered 200 but not with JSON — does endpoint point at the site itself instead of the editor endpoint?',
|
|
148
|
-
'the endpoint did not answer with JSON',
|
|
149
|
-
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** A 200 body as text when it fits in `CONLOCA_JSON_CAP_BYTES`, else null; reading stops at the cap, as the probe's does. */
|
|
60
|
+
async function cappedText(answer: Response): Promise<string | null> {
|
|
61
|
+
if (answer.status !== 200) {
|
|
62
|
+
await answer.body?.cancel().catch(() => {});
|
|
63
|
+
return null;
|
|
150
64
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
);
|
|
65
|
+
const chunks: Uint8Array[] = [];
|
|
66
|
+
let size = 0;
|
|
67
|
+
// Leaving the loop early cancels the stream.
|
|
68
|
+
for await (const chunk of answer.body ?? []) {
|
|
69
|
+
size += chunk.byteLength;
|
|
70
|
+
if (size > CONLOCA_JSON_CAP_BYTES) return null;
|
|
71
|
+
chunks.push(chunk);
|
|
157
72
|
}
|
|
158
|
-
|
|
159
|
-
return { outcome, body };
|
|
73
|
+
return new TextDecoder().decode(Buffer.concat(chunks));
|
|
160
74
|
}
|
|
161
75
|
|
|
162
|
-
/**
|
|
163
|
-
function
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
});
|
|
176
|
-
return { outcome, row: undefined };
|
|
76
|
+
/** CC11 — conloca.json at the address, through the server's classifier; the commit is held against local HEAD. */
|
|
77
|
+
async function checkEditorPage(
|
|
78
|
+
input: LiveInput,
|
|
79
|
+
address: string,
|
|
80
|
+
): Promise<{ outcome: CheckOutcome; info?: EditorPageInfo }> {
|
|
81
|
+
const { context, deps, scan, repoUri } = input;
|
|
82
|
+
if (repoUri === undefined) {
|
|
83
|
+
return {
|
|
84
|
+
outcome: skipped(
|
|
85
|
+
'CC11',
|
|
86
|
+
'repository identity could not be determined — build in a CI environment or Git checkout, or set repoUri',
|
|
87
|
+
),
|
|
88
|
+
};
|
|
177
89
|
}
|
|
178
|
-
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
own === undefined && inheritable
|
|
190
|
-
? live.find((row) => row.branch === defaultBranch && row.siteId === siteId)
|
|
191
|
-
: undefined;
|
|
192
|
-
const details: string[] = [];
|
|
193
|
-
if (own) {
|
|
194
|
-
details.push(`site "${siteId}": own registration ${own.gitSha}${builtWithNote(own.clientVersion)}`);
|
|
195
|
-
} else if (inherited) {
|
|
196
|
-
outcome.problems.push({
|
|
197
|
-
check: 'CC6',
|
|
198
|
-
level: 'warn',
|
|
199
|
-
message: `site "${siteId}": no registration for branch ${branch} — the editor inherits the default branch's (${defaultBranch}) registration; it works, preview is degraded. Build ${branch} with the token to register it`,
|
|
90
|
+
const outcome = outcomeOf('CC11');
|
|
91
|
+
const error = (message: string) => {
|
|
92
|
+
outcome.problems.push({ check: 'CC11', level: 'error', message });
|
|
93
|
+
return { outcome };
|
|
94
|
+
};
|
|
95
|
+
let siteId: string;
|
|
96
|
+
try {
|
|
97
|
+
siteId = resolveBuildSiteId({
|
|
98
|
+
contentRoot: context.contentRoot,
|
|
99
|
+
override: optionLiteral(scan, 'siteId'),
|
|
100
|
+
readFile: (path) => deps.readFile(path),
|
|
200
101
|
});
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
102
|
+
} catch (cause) {
|
|
103
|
+
return error(messageOf(cause));
|
|
104
|
+
}
|
|
105
|
+
const url = `${address}${EDITOR_PAGE_PATH.slice(1)}conloca.json`;
|
|
106
|
+
const answer = await request(deps.fetch, url);
|
|
107
|
+
if (answer instanceof Error) return error(`${url} could not be reached (${answer.message})`);
|
|
108
|
+
const body = await cappedText(answer);
|
|
109
|
+
const vercel = isFromVercel(answer.headers);
|
|
110
|
+
const verdict = classifyEditorHostResponse(
|
|
111
|
+
{
|
|
112
|
+
status: answer.status,
|
|
113
|
+
contentType: answer.headers.get('content-type'),
|
|
114
|
+
location: answer.headers.get('location'),
|
|
115
|
+
vercel,
|
|
116
|
+
body,
|
|
117
|
+
},
|
|
118
|
+
{ repoUri, siteId, protocols: ANY_PROTOCOL },
|
|
119
|
+
);
|
|
120
|
+
const { info } = verdict;
|
|
121
|
+
switch (verdict.status) {
|
|
122
|
+
case 'ready':
|
|
123
|
+
break;
|
|
124
|
+
case 'unreachable':
|
|
125
|
+
return error(`${url} answers HTTP ${answer.status} — the site is down or limiting requests; try again later`);
|
|
126
|
+
case 'protected':
|
|
127
|
+
return error(
|
|
128
|
+
`${url} asks visitors to sign in${vercel ? ' (Vercel Deployment Protection)' : ''} — put the public production address in sites.json, or let visitors through`,
|
|
129
|
+
);
|
|
130
|
+
case 'not-found':
|
|
131
|
+
return error(`${url} is not deployed — deploy the commit that adds conlocaCloud() to astro.config`);
|
|
132
|
+
case 'wrong-repo':
|
|
133
|
+
// A page built without a git remote names no repository, so no workspace can claim it.
|
|
134
|
+
if (verdict.reason === 'repo-missing') {
|
|
135
|
+
return {
|
|
136
|
+
...error(
|
|
137
|
+
`${url} names no repository because the build could not read the git remote — set repoUri in conlocaCloud(...)`,
|
|
138
|
+
),
|
|
139
|
+
info,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
...error(`${address} serves the editor page of ${info?.repo}, not ${repoUri} — check domains in sites.json`),
|
|
144
|
+
info,
|
|
145
|
+
};
|
|
146
|
+
case 'wrong-site':
|
|
147
|
+
return {
|
|
148
|
+
...error(`${address} serves site "${info?.siteId}", not "${siteId}" — check siteId in sites.json`),
|
|
149
|
+
info,
|
|
150
|
+
};
|
|
151
|
+
default:
|
|
152
|
+
return error(
|
|
153
|
+
`${url} is not a conloca.json the editor can read — check that the host serves the built file unchanged`,
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
if (info === undefined) return { outcome };
|
|
157
|
+
const local = deps.git(['rev-parse', 'HEAD'], context.projectDir);
|
|
158
|
+
const served = info.commit?.slice(0, 7) ?? 'an unknown commit';
|
|
159
|
+
if (local !== undefined && info.commit !== local) {
|
|
204
160
|
outcome.problems.push({
|
|
205
|
-
check: '
|
|
161
|
+
check: 'CC11',
|
|
206
162
|
level: 'warn',
|
|
207
|
-
message:
|
|
208
|
-
});
|
|
209
|
-
} else {
|
|
210
|
-
const fallback = inheritable ? ` (nor the default branch ${defaultBranch})` : '';
|
|
211
|
-
outcome.problems.push({
|
|
212
|
-
check: 'CC6',
|
|
213
|
-
level: 'error',
|
|
214
|
-
message: `site "${siteId}": no registration serves branch ${branch}${fallback} — the editor will not load; build ${branch} with CONLOCA_BUILD_TOKEN set`,
|
|
163
|
+
message: `${address} is serving ${served}, your checkout is at ${local.slice(0, 7)} — deploy to see your latest components in the editor`,
|
|
215
164
|
});
|
|
216
165
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
details.push(
|
|
220
|
-
`${parkedHere.length} older registration(s) not active yet — they become active the next time the editor opens`,
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
if (details.length > 0) outcome.detail = details.join('; ');
|
|
224
|
-
return { outcome, row: own ?? inherited };
|
|
166
|
+
outcome.detail = `${address}${EDITOR_PAGE_PATH.slice(1)} serves site "${siteId}" of ${info.repo} at ${served}`;
|
|
167
|
+
return { outcome, info };
|
|
225
168
|
}
|
|
226
169
|
|
|
227
|
-
/**
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
response = await fetchFn(url, {
|
|
237
|
-
method: 'GET',
|
|
238
|
-
headers: { range: 'bytes=0-0' },
|
|
239
|
-
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
return response.ok ? { ok: true } : { ok: false, answer: `HTTP ${response.status}` };
|
|
243
|
-
} catch (error) {
|
|
244
|
-
return { ok: false, answer: `unreachable (${messageOf(error)})` };
|
|
245
|
-
}
|
|
170
|
+
/** The sources that govern module scripts, per policy: script-src-elem, else script-src, else default-src. */
|
|
171
|
+
function scriptSources(csp: string): string[][] {
|
|
172
|
+
return csp.split(',').flatMap((policy) => {
|
|
173
|
+
const directives = policy.split(';').map((directive) => directive.trim().toLowerCase().split(/\s+/));
|
|
174
|
+
const found = ['script-src-elem', 'script-src', 'default-src']
|
|
175
|
+
.map((wanted) => directives.find(([name]) => name === wanted))
|
|
176
|
+
.find((directive) => directive !== undefined);
|
|
177
|
+
return found === undefined ? [] : [found.slice(1)];
|
|
178
|
+
});
|
|
246
179
|
}
|
|
247
180
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
181
|
+
const HOST_SOURCE = /^(?:([a-z][a-z0-9+.-]*):\/\/)?(\*|(?:\*\.)?[a-z0-9.-]+)(?::(\d+|\*))?(\/\S*)?$/;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Whether one CSP source expression admits an https `target` (CSP3 "does url match expression"). Keywords, nonces and
|
|
185
|
+
* hashes never admit a cross-origin file here; `'strict-dynamic'` is not modelled.
|
|
186
|
+
*/
|
|
187
|
+
function sourceAllows(source: string, target: URL): boolean {
|
|
188
|
+
if (source === '*' || source === 'https:' || source === 'http:') return true;
|
|
189
|
+
const match = HOST_SOURCE.exec(source);
|
|
190
|
+
if (match === null) return false;
|
|
191
|
+
const [, scheme, host = '', port, path] = match;
|
|
192
|
+
if (scheme !== undefined && scheme !== 'https' && scheme !== 'http') return false;
|
|
193
|
+
const hostMatches =
|
|
194
|
+
host === '*' || (host.startsWith('*.') ? target.hostname.endsWith(host.slice(1)) : host === target.hostname);
|
|
195
|
+
const portMatches = port === undefined || port === '*' || Number(port) === Number(target.port || 443);
|
|
196
|
+
const pathMatches =
|
|
197
|
+
path === undefined || (path.endsWith('/') ? target.pathname.startsWith(path) : target.pathname === path);
|
|
198
|
+
return hostMatches && portMatches && pathMatches;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** CC12 — the editor page's own headers, through the server's frame classifier, and whether it may load the editor UI. */
|
|
202
|
+
async function checkFrameHeaders(
|
|
203
|
+
address: string,
|
|
204
|
+
origin: string | null,
|
|
253
205
|
fetchFn: DoctorDeps['fetch'],
|
|
254
206
|
): Promise<CheckOutcome> {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
outcome.problems.push({
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
207
|
+
const editorRoot = origin === null ? null : parentRoot(origin);
|
|
208
|
+
if (origin === null || editorRoot === null) return skipped('CC12', 'no editor UI origin');
|
|
209
|
+
const outcome = outcomeOf('CC12');
|
|
210
|
+
const error = (message: string) => {
|
|
211
|
+
outcome.problems.push({ check: 'CC12', level: 'error', message });
|
|
212
|
+
return outcome;
|
|
213
|
+
};
|
|
214
|
+
const url = `${address}${EDITOR_PAGE_PATH.slice(1)}`;
|
|
215
|
+
const answer = await request(fetchFn, url);
|
|
216
|
+
if (answer instanceof Error) return error(`${url} could not be reached (${answer.message})`);
|
|
217
|
+
await answer.body?.cancel().catch(() => {});
|
|
218
|
+
if (answer.status >= 500 || answer.status === 429) {
|
|
219
|
+
return error(`${url} answers HTTP ${answer.status} — the site is down or limiting requests; try again later`);
|
|
268
220
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
export async function runLiveChecks(input: LiveInput): Promise<CheckOutcome[]> {
|
|
274
|
-
const { context, deps, scan, token, endpoint } = input;
|
|
275
|
-
if (!context.live) return skipAll('live checks run only with --live');
|
|
276
|
-
// The live trio diagnoses this integration: an unwired one is the reason, exactly as CC2/CC3 say.
|
|
277
|
-
if (scan.kind === 'read' && scan.config.conlocaCloud === 'absent') return skipAll(INTEGRATION_NOT_CALLED);
|
|
278
|
-
if (token === undefined) {
|
|
279
|
-
// CC2 already said why a supplied token is unusable; only a missing one gets the how-to here.
|
|
280
|
-
return skipAll(
|
|
281
|
-
suppliedBuildToken(scan, deps.env) === undefined
|
|
282
|
-
? 'no build token — set CONLOCA_BUILD_TOKEN'
|
|
283
|
-
: 'no usable build token (see CC2)',
|
|
221
|
+
// A 404 or a redirect carries the host's headers, not the page's, so it proves nothing about framing.
|
|
222
|
+
if (!answer.ok) {
|
|
223
|
+
return error(
|
|
224
|
+
`${url} answers HTTP ${answer.status}, not the editor page, so its headers say nothing yet — deploy it first (see CC11)`,
|
|
284
225
|
);
|
|
285
226
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
227
|
+
const headers = {
|
|
228
|
+
xFrameOptions: answer.headers.get('x-frame-options'),
|
|
229
|
+
csp: answer.headers.get('content-security-policy'),
|
|
230
|
+
};
|
|
231
|
+
const ancestor = `https://*.${editorRoot}`;
|
|
232
|
+
const hint = 'run conloca connect again, or exempt /_conloca/editor/ in your host settings';
|
|
233
|
+
if (classifyFrameHeaders(headers, [ancestor]) === 'frame-blocked') {
|
|
234
|
+
const seen = /frame-ancestors/i.test(headers.csp ?? '')
|
|
235
|
+
? `a Content-Security-Policy whose frame-ancestors excludes ${ancestor}`
|
|
236
|
+
: `X-Frame-Options: ${headers.xFrameOptions}`;
|
|
237
|
+
error(`${url} sends ${seen}, so the workspace editor cannot frame it — ${hint}`);
|
|
293
238
|
}
|
|
294
|
-
// The
|
|
295
|
-
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
239
|
+
// The editor UI modules live under /host/v<protocol>/ on the editor UI origin.
|
|
240
|
+
const editorUi = new URL(`/host/v${EDITOR_HOST_PROTOCOL}/`, origin);
|
|
241
|
+
const blocksEditor = scriptSources(headers.csp ?? '').some(
|
|
242
|
+
(sources) => !sources.some((source) => sourceAllows(source, editorUi)),
|
|
243
|
+
);
|
|
244
|
+
if (blocksEditor) {
|
|
245
|
+
error(
|
|
246
|
+
`${url} sends a Content-Security-Policy whose script-src does not allow ${origin}, so the editor page cannot load the editor — add ${origin} to script-src for /_conloca/editor/`,
|
|
301
247
|
);
|
|
302
248
|
}
|
|
249
|
+
if (outcome.problems.length === 0) outcome.detail = `${url} may be framed by ${ancestor}`;
|
|
250
|
+
return outcome;
|
|
251
|
+
}
|
|
303
252
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
253
|
+
function isProtocolRange(value: unknown): value is { min: number; max: number } {
|
|
254
|
+
return (
|
|
255
|
+
typeof value === 'object' &&
|
|
256
|
+
value !== null &&
|
|
257
|
+
'min' in value &&
|
|
258
|
+
'max' in value &&
|
|
259
|
+
Number.isSafeInteger(value.min) &&
|
|
260
|
+
Number.isSafeInteger(value.max)
|
|
261
|
+
);
|
|
262
|
+
}
|
|
308
263
|
|
|
309
|
-
|
|
264
|
+
/** CC13 — the page's protocol against the range the editor UI publishes at `<origin>/host/protocols.json`. */
|
|
265
|
+
async function checkProtocol(
|
|
266
|
+
info: EditorPageInfo | undefined,
|
|
267
|
+
origin: string | null,
|
|
268
|
+
fetchFn: DoctorDeps['fetch'],
|
|
269
|
+
): Promise<CheckOutcome> {
|
|
270
|
+
if (origin === null) return skipped('CC13', 'no editor UI origin');
|
|
271
|
+
if (info === undefined) return skipped('CC13', 'no conloca.json to read (see CC11)');
|
|
272
|
+
const outcome = outcomeOf('CC13');
|
|
273
|
+
const error = (message: string) => {
|
|
274
|
+
outcome.problems.push({ check: 'CC13', level: 'error', message });
|
|
275
|
+
return outcome;
|
|
276
|
+
};
|
|
277
|
+
const url = `${origin}/host/protocols.json`;
|
|
278
|
+
const answer = await request(fetchFn, url);
|
|
279
|
+
if (answer instanceof Error) return error(`${url} could not be reached (${answer.message})`);
|
|
280
|
+
let range: unknown;
|
|
310
281
|
try {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
readFile: deps.readFile,
|
|
315
|
-
});
|
|
316
|
-
} catch (error) {
|
|
317
|
-
const outcome = outcomeOf('CC6');
|
|
318
|
-
outcome.problems.push({ check: 'CC6', level: 'error', message: messageOf(error) });
|
|
319
|
-
return [status.outcome, outcome, skipped('CC7', 'the site id could not be resolved')];
|
|
282
|
+
range = answer.ok ? await answer.json() : undefined;
|
|
283
|
+
} catch {
|
|
284
|
+
range = undefined;
|
|
320
285
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
286
|
+
if (!isProtocolRange(range)) {
|
|
287
|
+
return error(`${url} did not answer the editor's protocol range as JSON (HTTP ${answer.status})`);
|
|
288
|
+
}
|
|
289
|
+
const { protocol } = info;
|
|
290
|
+
const speaks = `the editor page speaks protocol ${protocol} and the editor speaks ${range.min}–${range.max}`;
|
|
291
|
+
if (protocol < range.min) return error(`${speaks} — rebuild with a newer @conloca/cloud-astro and deploy`);
|
|
292
|
+
if (protocol > range.max) return error(`${speaks} — the editor does not speak this version yet`);
|
|
293
|
+
outcome.detail = `protocol ${protocol}, the editor speaks ${range.min}–${range.max}`;
|
|
294
|
+
return outcome;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* CC11–CC13. Networks only under --live, sends no credential, and contacts only the site's own domain and the editor UI's
|
|
299
|
+
* public protocols.json — so it runs anywhere, forks and Dependabot included.
|
|
300
|
+
*/
|
|
301
|
+
export async function runLiveChecks(input: LiveInput): Promise<CheckOutcome[]> {
|
|
302
|
+
const { context, deps, scan, address } = input;
|
|
303
|
+
if (!context.live) return skipAll('live checks run only with --live');
|
|
304
|
+
if (scan.kind === 'read' && scan.config.conlocaCloud === 'absent') return skipAll(INTEGRATION_NOT_CALLED);
|
|
305
|
+
if (address === undefined) return skipAll('no site domain (see CC9)');
|
|
306
|
+
const origin = editorUiOrigin(suppliedEndpoint(scan, deps.env));
|
|
307
|
+
const [page, frame] = await Promise.all([
|
|
308
|
+
checkEditorPage(input, address),
|
|
309
|
+
checkFrameHeaders(address, origin, deps.fetch),
|
|
310
|
+
]);
|
|
311
|
+
return [page.outcome, frame, await checkProtocol(page.info, origin, deps.fetch)];
|
|
324
312
|
}
|