@conloca/cloud-astro 0.2.3 → 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.
Files changed (159) hide show
  1. package/README.md +155 -37
  2. package/dist/.build-inputs.json +32 -23
  3. package/dist/src/constants.d.ts +12 -3
  4. package/dist/src/constants.d.ts.map +1 -1
  5. package/dist/src/constants.js +12 -3
  6. package/dist/src/constants.js.map +1 -1
  7. package/dist/src/d3-build.d.ts +70 -0
  8. package/dist/src/d3-build.d.ts.map +1 -0
  9. package/dist/src/d3-build.js +272 -0
  10. package/dist/src/d3-build.js.map +1 -0
  11. package/dist/src/descriptors.d.ts.map +1 -1
  12. package/dist/src/descriptors.js +4 -2
  13. package/dist/src/descriptors.js.map +1 -1
  14. package/dist/src/doctor/checks-live.d.ts +2 -2
  15. package/dist/src/doctor/checks-live.d.ts.map +1 -1
  16. package/dist/src/doctor/checks-live.js +10 -4
  17. package/dist/src/doctor/checks-live.js.map +1 -1
  18. package/dist/src/doctor/checks-offline.d.ts +1 -5
  19. package/dist/src/doctor/checks-offline.d.ts.map +1 -1
  20. package/dist/src/doctor/checks-offline.js +15 -27
  21. package/dist/src/doctor/checks-offline.js.map +1 -1
  22. package/dist/src/doctor/checks-preview-limits.d.ts +11 -0
  23. package/dist/src/doctor/checks-preview-limits.d.ts.map +1 -0
  24. package/dist/src/doctor/checks-preview-limits.js +133 -0
  25. package/dist/src/doctor/checks-preview-limits.js.map +1 -0
  26. package/dist/src/doctor/checks-preview-live.d.ts +14 -0
  27. package/dist/src/doctor/checks-preview-live.d.ts.map +1 -0
  28. package/dist/src/doctor/checks-preview-live.js +72 -0
  29. package/dist/src/doctor/checks-preview-live.js.map +1 -0
  30. package/dist/src/doctor/checks-preview.d.ts +7 -0
  31. package/dist/src/doctor/checks-preview.d.ts.map +1 -0
  32. package/dist/src/doctor/checks-preview.js +287 -0
  33. package/dist/src/doctor/checks-preview.js.map +1 -0
  34. package/dist/src/doctor/config-scan.d.ts +6 -0
  35. package/dist/src/doctor/config-scan.d.ts.map +1 -1
  36. package/dist/src/doctor/config-scan.js +17 -0
  37. package/dist/src/doctor/config-scan.js.map +1 -1
  38. package/dist/src/doctor/run.d.ts.map +1 -1
  39. package/dist/src/doctor/run.js +4 -0
  40. package/dist/src/doctor/run.js.map +1 -1
  41. package/dist/src/doctor/types.d.ts +11 -1
  42. package/dist/src/doctor/types.d.ts.map +1 -1
  43. package/dist/src/doctor/types.js +11 -1
  44. package/dist/src/doctor/types.js.map +1 -1
  45. package/dist/src/editor-page/bundle.d.ts +2 -0
  46. package/dist/src/editor-page/bundle.d.ts.map +1 -1
  47. package/dist/src/editor-page/bundle.js +3 -0
  48. package/dist/src/editor-page/bundle.js.map +1 -1
  49. package/dist/src/editor-page/data-schemas.d.ts +16 -0
  50. package/dist/src/editor-page/data-schemas.d.ts.map +1 -0
  51. package/dist/src/editor-page/data-schemas.js +39 -0
  52. package/dist/src/editor-page/data-schemas.js.map +1 -0
  53. package/dist/src/editor-page/emit.d.ts +37 -1
  54. package/dist/src/editor-page/emit.d.ts.map +1 -1
  55. package/dist/src/editor-page/emit.js +75 -4
  56. package/dist/src/editor-page/emit.js.map +1 -1
  57. package/dist/src/index.d.ts +1 -0
  58. package/dist/src/index.d.ts.map +1 -1
  59. package/dist/src/index.js +2 -0
  60. package/dist/src/index.js.map +1 -1
  61. package/dist/src/integration.d.ts.map +1 -1
  62. package/dist/src/integration.js +165 -41
  63. package/dist/src/integration.js.map +1 -1
  64. package/dist/src/preview/_dispatch.d.ts +12 -0
  65. package/dist/src/preview/_dispatch.d.ts.map +1 -1
  66. package/dist/src/preview/_dispatch.js +31 -0
  67. package/dist/src/preview/_dispatch.js.map +1 -1
  68. package/dist/src/preview/_resolve-opts.d.ts +3 -0
  69. package/dist/src/preview/_resolve-opts.d.ts.map +1 -1
  70. package/dist/src/preview/_resolve-opts.js +3 -1
  71. package/dist/src/preview/_resolve-opts.js.map +1 -1
  72. package/dist/src/preview/banner.d.ts +12 -9
  73. package/dist/src/preview/banner.d.ts.map +1 -1
  74. package/dist/src/preview/banner.js +46 -41
  75. package/dist/src/preview/banner.js.map +1 -1
  76. package/dist/src/preview/cloudflare-adapter.d.ts +35 -0
  77. package/dist/src/preview/cloudflare-adapter.d.ts.map +1 -0
  78. package/dist/src/preview/cloudflare-adapter.js +92 -0
  79. package/dist/src/preview/cloudflare-adapter.js.map +1 -0
  80. package/dist/src/preview/cookie.d.ts +9 -13
  81. package/dist/src/preview/cookie.d.ts.map +1 -1
  82. package/dist/src/preview/cookie.js +15 -25
  83. package/dist/src/preview/cookie.js.map +1 -1
  84. package/dist/src/preview/dispatcher.d.ts +73 -0
  85. package/dist/src/preview/dispatcher.d.ts.map +1 -0
  86. package/dist/src/preview/dispatcher.js +329 -0
  87. package/dist/src/preview/dispatcher.js.map +1 -0
  88. package/dist/src/preview/entry-code.d.ts +33 -0
  89. package/dist/src/preview/entry-code.d.ts.map +1 -0
  90. package/dist/src/preview/entry-code.js +33 -0
  91. package/dist/src/preview/entry-code.js.map +1 -0
  92. package/dist/src/preview/headers.d.ts +24 -4
  93. package/dist/src/preview/headers.d.ts.map +1 -1
  94. package/dist/src/preview/headers.js +35 -7
  95. package/dist/src/preview/headers.js.map +1 -1
  96. package/dist/src/preview/landing.d.ts +21 -0
  97. package/dist/src/preview/landing.d.ts.map +1 -1
  98. package/dist/src/preview/landing.js +103 -35
  99. package/dist/src/preview/landing.js.map +1 -1
  100. package/dist/src/preview/middleware.d.ts +29 -7
  101. package/dist/src/preview/middleware.d.ts.map +1 -1
  102. package/dist/src/preview/middleware.js +238 -84
  103. package/dist/src/preview/middleware.js.map +1 -1
  104. package/dist/src/preview/preview-path.d.ts +29 -0
  105. package/dist/src/preview/preview-path.d.ts.map +1 -1
  106. package/dist/src/preview/preview-path.js +41 -0
  107. package/dist/src/preview/preview-path.js.map +1 -1
  108. package/dist/src/preview/redeem-url.d.ts +7 -0
  109. package/dist/src/preview/redeem-url.d.ts.map +1 -0
  110. package/dist/src/preview/redeem-url.js +14 -0
  111. package/dist/src/preview/redeem-url.js.map +1 -0
  112. package/dist/src/preview/site-middleware.d.ts.map +1 -1
  113. package/dist/src/preview/site-middleware.js +39 -12
  114. package/dist/src/preview/site-middleware.js.map +1 -1
  115. package/dist/src/preview-build.d.ts +19 -8
  116. package/dist/src/preview-build.d.ts.map +1 -1
  117. package/dist/src/preview-build.js +47 -21
  118. package/dist/src/preview-build.js.map +1 -1
  119. package/dist/src/skill.d.ts +11 -0
  120. package/dist/src/skill.d.ts.map +1 -1
  121. package/dist/src/skill.js +32 -9
  122. package/dist/src/skill.js.map +1 -1
  123. package/dist/src/types.d.ts +15 -12
  124. package/dist/src/types.d.ts.map +1 -1
  125. package/package.json +33 -7
  126. package/src/constants.ts +14 -3
  127. package/src/d3-build.ts +315 -0
  128. package/src/descriptors.ts +4 -2
  129. package/src/doctor/checks-live.ts +10 -4
  130. package/src/doctor/checks-offline.ts +16 -25
  131. package/src/doctor/checks-preview-limits.ts +137 -0
  132. package/src/doctor/checks-preview-live.ts +77 -0
  133. package/src/doctor/checks-preview.ts +302 -0
  134. package/src/doctor/config-scan.ts +14 -0
  135. package/src/doctor/run.ts +4 -0
  136. package/src/doctor/types.ts +11 -1
  137. package/src/editor-page/bundle.ts +5 -0
  138. package/src/editor-page/data-schemas.ts +47 -0
  139. package/src/editor-page/emit.ts +124 -8
  140. package/src/index.ts +2 -0
  141. package/src/integration.ts +176 -40
  142. package/src/preview/_dispatch.ts +36 -1
  143. package/src/preview/_resolve-opts.ts +6 -1
  144. package/src/preview/banner.ts +61 -41
  145. package/src/preview/cloudflare-adapter.ts +103 -0
  146. package/src/preview/cookie.ts +14 -23
  147. package/src/preview/dispatcher.ts +407 -0
  148. package/src/preview/entry-code.ts +51 -0
  149. package/src/preview/headers.ts +35 -7
  150. package/src/preview/landing.ts +115 -37
  151. package/src/preview/middleware.ts +264 -88
  152. package/src/preview/preview-path.ts +57 -0
  153. package/src/preview/redeem-url.ts +14 -0
  154. package/src/preview/site-middleware.ts +47 -12
  155. package/src/preview-build.ts +67 -24
  156. package/src/preview-handler.astro +2 -1
  157. package/src/skill/SKILL.md +14 -2
  158. package/src/skill.ts +36 -8
  159. package/src/types.ts +15 -12
@@ -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
- * - `cache-control: private, no-store` — overrides whatever the renderer
11
- * emitted. Preview content is per-branch, per-JWT, and must never enter
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
- headers.set('cache-control', 'private, no-store');
28
- headers.append('content-security-policy', "frame-ancestors 'none'");
29
- return new Response(response.body, { status: response.status, headers });
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
  }
@@ -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 escapedPath = escapeHtml(opts.pathname);
24
- const escapedLogin = escapeHtml(loginUrl.toString());
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
- const body = [
27
- '<!doctype html>',
28
- '<html lang="en">',
29
- '<head>',
30
- '<meta charset="utf-8">',
31
- '<meta name="viewport" content="width=device-width, initial-scale=1">',
32
- '<meta name="robots" content="noindex, nofollow">',
33
- '<title>Conloca preview</title>',
34
- '<style>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}</style>',
35
- '</head>',
36
- '<body>',
37
- '<h1>This is a Conloca preview environment</h1>',
38
- '<p>To preview unreleased content you need to log in. Otherwise visit the production site.</p>',
39
- '<p>',
40
- `<a class="btn primary" href="${escapedLogin}">Log in to edit</a>`,
41
- `<a class="btn secondary" href="${escapedPath}">Go to production</a>`,
42
- '</p>',
43
- '</body>',
44
- '</html>',
45
- ].join('');
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
- return new Response(body, {
48
- status: 200,
49
- headers: {
50
- 'content-type': 'text/html; charset=utf-8',
51
- 'x-robots-tag': 'noindex',
52
- 'cache-control': 'private, no-store',
53
- // This is a Conloca-authored page (only an inline <style>, no scripts),
54
- // so it carries a tight own CSP — no script execution, no framing.
55
- 'content-security-policy':
56
- "default-src 'none'; style-src 'unsafe-inline'; img-src 'self' data:; base-uri 'none'; form-action 'none'; frame-ancestors 'none'",
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 the rendered
63
- * pathname from breaking out of an attribute or injecting markup. We do
64
- * not pull in a dependency for one helper used in one place.
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