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