@conloca/cloud-astro 0.2.3 → 0.2.5
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 +155 -37
- package/dist/.build-inputs.json +32 -23
- package/dist/src/constants.d.ts +12 -3
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +12 -3
- 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.map +1 -1
- package/dist/src/descriptors.js +4 -2
- package/dist/src/descriptors.js.map +1 -1
- package/dist/src/doctor/checks-live.d.ts +2 -2
- package/dist/src/doctor/checks-live.d.ts.map +1 -1
- package/dist/src/doctor/checks-live.js +10 -4
- package/dist/src/doctor/checks-live.js.map +1 -1
- package/dist/src/doctor/checks-offline.d.ts +1 -5
- package/dist/src/doctor/checks-offline.d.ts.map +1 -1
- package/dist/src/doctor/checks-offline.js +15 -27
- 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 +6 -0
- package/dist/src/doctor/config-scan.d.ts.map +1 -1
- package/dist/src/doctor/config-scan.js +17 -0
- 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 +4 -0
- package/dist/src/doctor/run.js.map +1 -1
- package/dist/src/doctor/types.d.ts +11 -1
- package/dist/src/doctor/types.d.ts.map +1 -1
- package/dist/src/doctor/types.js +11 -1
- package/dist/src/doctor/types.js.map +1 -1
- package/dist/src/editor-page/bundle.d.ts +2 -0
- package/dist/src/editor-page/bundle.d.ts.map +1 -1
- package/dist/src/editor-page/bundle.js +3 -0
- package/dist/src/editor-page/bundle.js.map +1 -1
- 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 +37 -1
- package/dist/src/editor-page/emit.d.ts.map +1 -1
- package/dist/src/editor-page/emit.js +75 -4
- package/dist/src/editor-page/emit.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/integration.d.ts.map +1 -1
- package/dist/src/integration.js +165 -41
- package/dist/src/integration.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 +3 -0
- package/dist/src/preview/_resolve-opts.d.ts.map +1 -1
- package/dist/src/preview/_resolve-opts.js +3 -1
- 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 -41
- 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 +9 -13
- package/dist/src/preview/cookie.d.ts.map +1 -1
- package/dist/src/preview/cookie.js +15 -25
- 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/landing.d.ts +21 -0
- package/dist/src/preview/landing.d.ts.map +1 -1
- package/dist/src/preview/landing.js +103 -35
- package/dist/src/preview/landing.js.map +1 -1
- package/dist/src/preview/middleware.d.ts +29 -7
- package/dist/src/preview/middleware.d.ts.map +1 -1
- package/dist/src/preview/middleware.js +238 -84
- package/dist/src/preview/middleware.js.map +1 -1
- package/dist/src/preview/preview-path.d.ts +29 -0
- package/dist/src/preview/preview-path.d.ts.map +1 -1
- package/dist/src/preview/preview-path.js +41 -0
- 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.map +1 -1
- package/dist/src/preview/site-middleware.js +39 -12
- package/dist/src/preview/site-middleware.js.map +1 -1
- package/dist/src/preview-build.d.ts +19 -8
- package/dist/src/preview-build.d.ts.map +1 -1
- package/dist/src/preview-build.js +47 -21
- package/dist/src/preview-build.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 +15 -12
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +33 -7
- package/src/constants.ts +14 -3
- package/src/d3-build.ts +315 -0
- package/src/descriptors.ts +4 -2
- package/src/doctor/checks-live.ts +10 -4
- package/src/doctor/checks-offline.ts +16 -25
- 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 +14 -0
- package/src/doctor/run.ts +4 -0
- package/src/doctor/types.ts +11 -1
- package/src/editor-page/bundle.ts +5 -0
- package/src/editor-page/data-schemas.ts +47 -0
- package/src/editor-page/emit.ts +124 -8
- package/src/index.ts +2 -0
- package/src/integration.ts +176 -40
- package/src/preview/_dispatch.ts +36 -1
- package/src/preview/_resolve-opts.ts +6 -1
- package/src/preview/banner.ts +61 -41
- package/src/preview/cloudflare-adapter.ts +103 -0
- package/src/preview/cookie.ts +14 -23
- 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/landing.ts +115 -37
- package/src/preview/middleware.ts +264 -88
- package/src/preview/preview-path.ts +57 -0
- package/src/preview/redeem-url.ts +14 -0
- package/src/preview/site-middleware.ts +47 -12
- package/src/preview-build.ts +67 -24
- package/src/preview-handler.astro +2 -1
- package/src/skill/SKILL.md +14 -2
- package/src/skill.ts +36 -8
- package/src/types.ts +15 -12
package/src/preview/headers.ts
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headers every preview response carries, its redirects and Conloca's own pages included:
|
|
3
|
+
*
|
|
4
|
+
* - `cache-control: private, no-store` — preview content is per-branch and
|
|
5
|
+
* per-pass, so no shared cache may keep it. `no-store` also prevents
|
|
6
|
+
* browser disk persistence, so a shared workstation doesn't expose draft
|
|
7
|
+
* pages.
|
|
8
|
+
* - `cdn-cache-control: no-store` and `vercel-cdn-cache-control: no-store` —
|
|
9
|
+
* CDNs read these before `cache-control` (RFC 9213), so a site-wide CDN
|
|
10
|
+
* rule that caches pages can't cache a draft.
|
|
11
|
+
* - `referrer-policy: same-origin` — a link out of a draft never tells
|
|
12
|
+
* another site the draft's address.
|
|
13
|
+
* - `vary: Cookie` — the same URL answers differently with and without the
|
|
14
|
+
* preview cookie.
|
|
15
|
+
*/
|
|
16
|
+
export const PREVIEW_CACHE_HEADERS = {
|
|
17
|
+
'cache-control': 'private, no-store',
|
|
18
|
+
'cdn-cache-control': 'no-store',
|
|
19
|
+
'vercel-cdn-cache-control': 'no-store',
|
|
20
|
+
'referrer-policy': 'same-origin',
|
|
21
|
+
vary: 'Cookie',
|
|
22
|
+
} as const;
|
|
23
|
+
|
|
1
24
|
/**
|
|
2
25
|
* Wraps a rendered preview response with the SEO/cache protection headers
|
|
3
26
|
* required for all preview responses:
|
|
@@ -7,10 +30,8 @@
|
|
|
7
30
|
* containment. Cloudflare Pages preview deployments already set this
|
|
8
31
|
* for their own preview URLs; we set it again so the protection
|
|
9
32
|
* survives custom domains, non-Pages hosts, and on-prem deployments.
|
|
10
|
-
* -
|
|
11
|
-
*
|
|
12
|
-
* a shared cache. `no-store` also prevents browser disk persistence so
|
|
13
|
-
* a shared workstation doesn't expose draft pages.
|
|
33
|
+
* - {@link PREVIEW_CACHE_HEADERS}, overriding whatever the renderer emitted.
|
|
34
|
+
* `vary` is appended once, so the site's own `Vary` survives.
|
|
14
35
|
* - `content-security-policy: frame-ancestors 'none'` — appended (not set)
|
|
15
36
|
* so it stacks with any CSP the site's own rendered page carries
|
|
16
37
|
* (browsers enforce the intersection of comma-joined policies). This
|
|
@@ -24,7 +45,14 @@
|
|
|
24
45
|
export function applyPreviewHeaders(response: Response): Response {
|
|
25
46
|
const headers = new Headers(response.headers);
|
|
26
47
|
headers.set('x-robots-tag', 'noindex');
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
48
|
+
for (const name of ['cache-control', 'cdn-cache-control', 'vercel-cdn-cache-control', 'referrer-policy'] as const) {
|
|
49
|
+
headers.set(name, PREVIEW_CACHE_HEADERS[name]);
|
|
50
|
+
}
|
|
51
|
+
// Appended, so the site's own Vary and CSP survive; once, because the dispatcher wraps what the server wrapped.
|
|
52
|
+
const varies = (headers.get('vary') ?? '').split(',').map((token) => token.trim().toLowerCase());
|
|
53
|
+
if (!varies.includes('cookie')) headers.append('vary', PREVIEW_CACHE_HEADERS.vary);
|
|
54
|
+
if (!(headers.get('content-security-policy') ?? '').includes("frame-ancestors 'none'")) {
|
|
55
|
+
headers.append('content-security-policy', "frame-ancestors 'none'");
|
|
56
|
+
}
|
|
57
|
+
return new Response(response.body, { status: response.status, statusText: response.statusText, headers });
|
|
30
58
|
}
|
package/src/preview/landing.ts
CHANGED
|
@@ -1,3 +1,48 @@
|
|
|
1
|
+
import type { ShareEndedKind } from './_dispatch.js';
|
|
2
|
+
import { PREVIEW_CACHE_HEADERS } from './headers.js';
|
|
3
|
+
|
|
4
|
+
const PAGE_STYLE =
|
|
5
|
+
'body{font-family:system-ui,sans-serif;max-width:32rem;margin:8rem auto;padding:0 1rem;line-height:1.5;color:#1a1a1a}h1{margin-bottom:1rem}a.btn{display:inline-block;padding:0.75rem 1.25rem;margin-right:0.5rem;border-radius:6px;text-decoration:none}a.btn.primary{background:#111;color:#fff}a.btn.secondary{border:1px solid #ccc;color:#1a1a1a}';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Headers of both pages below: noindex, never cached, and a tight own CSP.
|
|
9
|
+
* They are Conloca-authored (only an inline <style>, no scripts), so no
|
|
10
|
+
* script runs and nothing may frame them.
|
|
11
|
+
*/
|
|
12
|
+
const PAGE_HEADERS = {
|
|
13
|
+
'content-type': 'text/html; charset=utf-8',
|
|
14
|
+
'x-robots-tag': 'noindex',
|
|
15
|
+
...PREVIEW_CACHE_HEADERS,
|
|
16
|
+
'content-security-policy':
|
|
17
|
+
"default-src 'none'; style-src 'unsafe-inline'; img-src 'self' data:; base-uri 'none'; form-action 'none'; frame-ancestors 'none'",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** A heading, one paragraph and link buttons; the first link is the primary one. Hrefs are escaped here. */
|
|
21
|
+
function renderPage(content: { title: string; heading: string; text: string; links: [string, string][] }): string {
|
|
22
|
+
return [
|
|
23
|
+
'<!doctype html>',
|
|
24
|
+
'<html lang="en">',
|
|
25
|
+
'<head>',
|
|
26
|
+
'<meta charset="utf-8">',
|
|
27
|
+
'<meta name="viewport" content="width=device-width, initial-scale=1">',
|
|
28
|
+
'<meta name="robots" content="noindex, nofollow">',
|
|
29
|
+
`<title>${content.title}</title>`,
|
|
30
|
+
`<style>${PAGE_STYLE}</style>`,
|
|
31
|
+
'</head>',
|
|
32
|
+
'<body>',
|
|
33
|
+
`<h1>${content.heading}</h1>`,
|
|
34
|
+
`<p>${content.text}</p>`,
|
|
35
|
+
'<p>',
|
|
36
|
+
...content.links.map(
|
|
37
|
+
([label, href], index) =>
|
|
38
|
+
`<a class="btn ${index === 0 ? 'primary' : 'secondary'}" href="${escapeHtml(href)}">${label}</a>`,
|
|
39
|
+
),
|
|
40
|
+
'</p>',
|
|
41
|
+
'</body>',
|
|
42
|
+
'</html>',
|
|
43
|
+
].join('');
|
|
44
|
+
}
|
|
45
|
+
|
|
1
46
|
/**
|
|
2
47
|
* Renders the "no preview context" landing page returned when a request
|
|
3
48
|
* hits the preview route but carries neither a fresh query param nor a
|
|
@@ -15,53 +60,86 @@
|
|
|
15
60
|
* The page is wrapped with `x-robots-tag: noindex` so a leak of the URL
|
|
16
61
|
* cannot get indexed.
|
|
17
62
|
*/
|
|
18
|
-
export function renderNoPreviewLanding(opts: { pathname: string; saasEndpoint: string }): Response {
|
|
63
|
+
export function renderNoPreviewLanding(opts: { pathname: string; saasEndpoint: string; liveHref?: string }): Response {
|
|
19
64
|
// The deep-link to the endpoint's editor preserves both the path the user
|
|
20
65
|
// was trying to preview and the endpoint that issues the JWT.
|
|
21
66
|
const loginUrl = new URL('/login', opts.saasEndpoint);
|
|
22
67
|
loginUrl.searchParams.set('return', opts.pathname);
|
|
23
|
-
const
|
|
24
|
-
|
|
68
|
+
const body = renderPage({
|
|
69
|
+
title: 'Conloca preview',
|
|
70
|
+
heading: 'This is a Conloca preview environment',
|
|
71
|
+
text: 'To preview unreleased content you need to log in. Otherwise visit the production site.',
|
|
72
|
+
links: [
|
|
73
|
+
['Log in to edit', loginUrl.toString()],
|
|
74
|
+
['Go to production', opts.liveHref ?? opts.pathname],
|
|
75
|
+
],
|
|
76
|
+
});
|
|
77
|
+
return new Response(body, { status: 200, headers: PAGE_HEADERS });
|
|
78
|
+
}
|
|
25
79
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
'
|
|
36
|
-
'
|
|
37
|
-
'
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
80
|
+
/**
|
|
81
|
+
* The page a preview request gets when its draft could not be loaded (the
|
|
82
|
+
* page-status call failed). Never the published page: under preview,
|
|
83
|
+
* published bytes would pass for the draft. Retry reloads the page; Exit
|
|
84
|
+
* leaves preview, since the visitor can't remove the HttpOnly cookie
|
|
85
|
+
* themselves.
|
|
86
|
+
*/
|
|
87
|
+
export function renderPreviewUnavailable(opts: { retryHref: string; exitHref: string }): Response {
|
|
88
|
+
const body = renderPage({
|
|
89
|
+
title: 'Preview unavailable',
|
|
90
|
+
heading: "Preview couldn't load the draft",
|
|
91
|
+
text: 'The draft could not be fetched just now. Your published site is not affected.',
|
|
92
|
+
links: [
|
|
93
|
+
['Retry', opts.retryHref],
|
|
94
|
+
['Exit preview', opts.exitHref],
|
|
95
|
+
],
|
|
96
|
+
});
|
|
97
|
+
return new Response(body, { status: 503, headers: PAGE_HEADERS });
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Each ended link's words; the sharer's name arrives escaped. */
|
|
101
|
+
const SHARE_ENDED_COPY = {
|
|
102
|
+
'grant-expired': (sharer) => ({
|
|
103
|
+
heading: 'This preview link has expired',
|
|
104
|
+
text: `Ask ${sharer || 'the person who shared it'} for a new link.`,
|
|
105
|
+
link: 'View the live site',
|
|
106
|
+
}),
|
|
107
|
+
'grant-revoked': (sharer) => ({
|
|
108
|
+
heading: 'This preview link was turned off',
|
|
109
|
+
text: `${sharer || 'The person who shared it'} or a workspace admin turned it off.`,
|
|
110
|
+
link: 'View the live site',
|
|
111
|
+
}),
|
|
112
|
+
'draft-published': () => ({
|
|
113
|
+
heading: 'This draft was published',
|
|
114
|
+
text: 'Its changes are on the live site now.',
|
|
115
|
+
link: 'View live',
|
|
116
|
+
}),
|
|
117
|
+
'draft-discarded': () => ({
|
|
118
|
+
heading: 'This draft was discarded',
|
|
119
|
+
text: 'Its changes were thrown away, so there is nothing left to preview.',
|
|
120
|
+
link: 'View the live site',
|
|
121
|
+
}),
|
|
122
|
+
} satisfies Record<ShareEndedKind, (sharer: string) => { heading: string; text: string; link: string }>;
|
|
46
123
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
124
|
+
/**
|
|
125
|
+
* The page a share viewer gets once the link no longer opens. Never the published page: under preview it would
|
|
126
|
+
* pass for the draft. The one link leaves preview for the live page.
|
|
127
|
+
*/
|
|
128
|
+
export function renderShareEnded(kind: ShareEndedKind, opts: { sharedBy: string; liveHref: string }): Response {
|
|
129
|
+
const copy = SHARE_ENDED_COPY[kind](escapeHtml(opts.sharedBy));
|
|
130
|
+
const body = renderPage({
|
|
131
|
+
title: copy.heading,
|
|
132
|
+
heading: copy.heading,
|
|
133
|
+
text: copy.text,
|
|
134
|
+
links: [[copy.link, opts.liveHref]],
|
|
58
135
|
});
|
|
136
|
+
return new Response(body, { status: 410, headers: PAGE_HEADERS });
|
|
59
137
|
}
|
|
60
138
|
|
|
61
139
|
/**
|
|
62
|
-
* Minimal HTML attribute/text escaper — enough to prevent
|
|
63
|
-
*
|
|
64
|
-
* not pull in a dependency for one helper
|
|
140
|
+
* Minimal HTML attribute/text escaper — enough to prevent a rendered
|
|
141
|
+
* path from breaking out of an attribute or injecting markup. We do
|
|
142
|
+
* not pull in a dependency for one helper.
|
|
65
143
|
*/
|
|
66
144
|
function escapeHtml(value: string): string {
|
|
67
145
|
return value
|