@conloca/cloud-astro 0.2.5 → 0.2.6

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 (171) hide show
  1. package/README.md +69 -22
  2. package/dist/.build-inputs.json +36 -23
  3. package/dist/src/constants.d.ts +4 -4
  4. package/dist/src/constants.js +4 -4
  5. package/dist/src/d3-build.d.ts +6 -2
  6. package/dist/src/d3-build.d.ts.map +1 -1
  7. package/dist/src/d3-build.js +15 -11
  8. package/dist/src/d3-build.js.map +1 -1
  9. package/dist/src/d8-adapters.d.ts +10 -0
  10. package/dist/src/d8-adapters.d.ts.map +1 -0
  11. package/dist/src/d8-adapters.js +19 -0
  12. package/dist/src/d8-adapters.js.map +1 -0
  13. package/dist/src/d8-build.d.ts +99 -0
  14. package/dist/src/d8-build.d.ts.map +1 -0
  15. package/dist/src/d8-build.js +265 -0
  16. package/dist/src/d8-build.js.map +1 -0
  17. package/dist/src/d8-guards.d.ts +29 -0
  18. package/dist/src/d8-guards.d.ts.map +1 -0
  19. package/dist/src/d8-guards.js +145 -0
  20. package/dist/src/d8-guards.js.map +1 -0
  21. package/dist/src/d8-middleware.d.ts +7 -0
  22. package/dist/src/d8-middleware.d.ts.map +1 -0
  23. package/dist/src/d8-middleware.js +15 -0
  24. package/dist/src/d8-middleware.js.map +1 -0
  25. package/dist/src/d8-render.d.ts +9 -0
  26. package/dist/src/d8-render.d.ts.map +1 -0
  27. package/dist/src/d8-render.js +52 -0
  28. package/dist/src/d8-render.js.map +1 -0
  29. package/dist/src/doctor/checks-d8.d.ts +7 -0
  30. package/dist/src/doctor/checks-d8.d.ts.map +1 -0
  31. package/dist/src/doctor/checks-d8.js +240 -0
  32. package/dist/src/doctor/checks-d8.js.map +1 -0
  33. package/dist/src/doctor/checks-live.d.ts.map +1 -1
  34. package/dist/src/doctor/checks-live.js +3 -5
  35. package/dist/src/doctor/checks-live.js.map +1 -1
  36. package/dist/src/doctor/checks-offline.d.ts +2 -0
  37. package/dist/src/doctor/checks-offline.d.ts.map +1 -1
  38. package/dist/src/doctor/checks-offline.js +17 -8
  39. package/dist/src/doctor/checks-offline.js.map +1 -1
  40. package/dist/src/doctor/checks-preview-live.d.ts +7 -2
  41. package/dist/src/doctor/checks-preview-live.d.ts.map +1 -1
  42. package/dist/src/doctor/checks-preview-live.js +107 -7
  43. package/dist/src/doctor/checks-preview-live.js.map +1 -1
  44. package/dist/src/doctor/checks-preview.d.ts.map +1 -1
  45. package/dist/src/doctor/checks-preview.js +9 -4
  46. package/dist/src/doctor/checks-preview.js.map +1 -1
  47. package/dist/src/doctor/config-scan.d.ts +24 -6
  48. package/dist/src/doctor/config-scan.d.ts.map +1 -1
  49. package/dist/src/doctor/config-scan.js +89 -18
  50. package/dist/src/doctor/config-scan.js.map +1 -1
  51. package/dist/src/doctor/run.d.ts.map +1 -1
  52. package/dist/src/doctor/run.js +2 -0
  53. package/dist/src/doctor/run.js.map +1 -1
  54. package/dist/src/doctor/types.d.ts +7 -0
  55. package/dist/src/doctor/types.d.ts.map +1 -1
  56. package/dist/src/doctor/types.js +7 -0
  57. package/dist/src/doctor/types.js.map +1 -1
  58. package/dist/src/editor-page/emit.d.ts +4 -3
  59. package/dist/src/editor-page/emit.d.ts.map +1 -1
  60. package/dist/src/editor-page/emit.js +9 -9
  61. package/dist/src/editor-page/emit.js.map +1 -1
  62. package/dist/src/integration.d.ts.map +1 -1
  63. package/dist/src/integration.js +228 -124
  64. package/dist/src/integration.js.map +1 -1
  65. package/dist/src/node.d.ts +2 -0
  66. package/dist/src/node.d.ts.map +1 -1
  67. package/dist/src/node.js +4 -0
  68. package/dist/src/node.js.map +1 -1
  69. package/dist/src/preview/_resolve-opts.d.ts +26 -1
  70. package/dist/src/preview/_resolve-opts.d.ts.map +1 -1
  71. package/dist/src/preview/_resolve-opts.js.map +1 -1
  72. package/dist/src/preview/content-api.d.ts +15 -0
  73. package/dist/src/preview/content-api.d.ts.map +1 -1
  74. package/dist/src/preview/content-api.js +57 -6
  75. package/dist/src/preview/content-api.js.map +1 -1
  76. package/dist/src/preview/d8-middleware.d.ts +25 -0
  77. package/dist/src/preview/d8-middleware.d.ts.map +1 -0
  78. package/dist/src/preview/d8-middleware.js +94 -0
  79. package/dist/src/preview/d8-middleware.js.map +1 -0
  80. package/dist/src/preview/dispatcher.d.ts +3 -16
  81. package/dist/src/preview/dispatcher.d.ts.map +1 -1
  82. package/dist/src/preview/dispatcher.js +46 -134
  83. package/dist/src/preview/dispatcher.js.map +1 -1
  84. package/dist/src/preview/headers.d.ts +3 -0
  85. package/dist/src/preview/headers.d.ts.map +1 -1
  86. package/dist/src/preview/headers.js +10 -1
  87. package/dist/src/preview/headers.js.map +1 -1
  88. package/dist/src/preview/links.d.ts +23 -0
  89. package/dist/src/preview/links.d.ts.map +1 -0
  90. package/dist/src/preview/links.js +168 -0
  91. package/dist/src/preview/links.js.map +1 -0
  92. package/dist/src/preview/middleware.d.ts +9 -3
  93. package/dist/src/preview/middleware.d.ts.map +1 -1
  94. package/dist/src/preview/middleware.js +36 -16
  95. package/dist/src/preview/middleware.js.map +1 -1
  96. package/dist/src/preview/prefix-router.d.ts +67 -0
  97. package/dist/src/preview/prefix-router.d.ts.map +1 -0
  98. package/dist/src/preview/prefix-router.js +153 -0
  99. package/dist/src/preview/prefix-router.js.map +1 -0
  100. package/dist/src/preview/preview-path.d.ts +8 -3
  101. package/dist/src/preview/preview-path.d.ts.map +1 -1
  102. package/dist/src/preview/preview-path.js +16 -4
  103. package/dist/src/preview/preview-path.js.map +1 -1
  104. package/dist/src/preview/site-middleware.d.ts +8 -2
  105. package/dist/src/preview/site-middleware.d.ts.map +1 -1
  106. package/dist/src/preview/site-middleware.js +90 -31
  107. package/dist/src/preview/site-middleware.js.map +1 -1
  108. package/dist/src/preview/site-page-sources.d.ts +21 -0
  109. package/dist/src/preview/site-page-sources.d.ts.map +1 -0
  110. package/dist/src/preview/site-page-sources.js +129 -0
  111. package/dist/src/preview/site-page-sources.js.map +1 -0
  112. package/dist/src/preview/site-pages.d.ts +18 -0
  113. package/dist/src/preview/site-pages.d.ts.map +1 -0
  114. package/dist/src/preview/site-pages.js +7 -0
  115. package/dist/src/preview/site-pages.js.map +1 -0
  116. package/dist/src/preview-build.d.ts +17 -16
  117. package/dist/src/preview-build.d.ts.map +1 -1
  118. package/dist/src/preview-build.js +37 -40
  119. package/dist/src/preview-build.js.map +1 -1
  120. package/dist/src/preview-image-endpoint.d.ts +8 -0
  121. package/dist/src/preview-image-endpoint.d.ts.map +1 -0
  122. package/dist/src/preview-image-endpoint.js +34 -0
  123. package/dist/src/preview-image-endpoint.js.map +1 -0
  124. package/dist/src/preview-render-seams.d.ts +7 -0
  125. package/dist/src/preview-render-seams.d.ts.map +1 -0
  126. package/dist/src/preview-render-seams.js +27 -0
  127. package/dist/src/preview-render-seams.js.map +1 -0
  128. package/dist/src/site-middleware.d.ts +2 -4
  129. package/dist/src/site-middleware.d.ts.map +1 -1
  130. package/dist/src/site-middleware.js +6 -22
  131. package/dist/src/site-middleware.js.map +1 -1
  132. package/dist/src/types.d.ts +15 -16
  133. package/dist/src/types.d.ts.map +1 -1
  134. package/package.json +138 -6
  135. package/src/constants.ts +4 -4
  136. package/src/d3-build.ts +20 -14
  137. package/src/d8-adapters.ts +19 -0
  138. package/src/d8-build.ts +356 -0
  139. package/src/d8-guards.ts +177 -0
  140. package/src/d8-middleware.ts +17 -0
  141. package/src/d8-render.ts +61 -0
  142. package/src/doctor/checks-d8.ts +256 -0
  143. package/src/doctor/checks-live.ts +3 -4
  144. package/src/doctor/checks-offline.ts +21 -8
  145. package/src/doctor/checks-preview-live.ts +114 -8
  146. package/src/doctor/checks-preview.ts +9 -4
  147. package/src/doctor/config-scan.ts +86 -15
  148. package/src/doctor/run.ts +2 -0
  149. package/src/doctor/types.ts +8 -0
  150. package/src/editor-page/emit.ts +23 -14
  151. package/src/integration.ts +274 -135
  152. package/src/node.ts +4 -0
  153. package/src/preview/_resolve-opts.ts +17 -1
  154. package/src/preview/content-api.ts +60 -5
  155. package/src/preview/d8-middleware.ts +124 -0
  156. package/src/preview/dispatcher.ts +55 -150
  157. package/src/preview/headers.ts +10 -1
  158. package/src/preview/links.ts +175 -0
  159. package/src/preview/middleware.ts +41 -19
  160. package/src/preview/prefix-router.ts +197 -0
  161. package/src/preview/preview-path.ts +24 -6
  162. package/src/preview/site-middleware.ts +109 -38
  163. package/src/preview/site-page-sources.ts +146 -0
  164. package/src/preview/site-pages.ts +22 -0
  165. package/src/preview-build.ts +43 -42
  166. package/src/preview-image-endpoint.ts +35 -0
  167. package/src/preview-render-seams.ts +31 -0
  168. package/src/site-middleware.ts +6 -24
  169. package/src/skill/SKILL.md +19 -1
  170. package/src/types.ts +15 -16
  171. package/src/virtual-modules.d.ts +17 -2
@@ -5,27 +5,22 @@
5
5
  * the integration resolves to this module, so it must export `onRequest` —
6
6
  * Astro's middleware contract. The verdict/render logic lives in
7
7
  * `./preview/site-middleware.ts`, which is env-free and unit-testable; this
8
- * file binds it to the runtime env resolution and to the site's own build
9
- * graph: `astro:content` and the routing-config virtual module only resolve
10
- * here, so the collection-backed baseline is constructed here and injected as
11
- * a seam.
8
+ * file binds it to the runtime env resolution and to the render seams built
9
+ * from the site's own build graph (`./preview-render-seams.ts`).
12
10
  *
13
11
  * Mounted ONLY inside the preview build (see `integration.ts`), never in the
14
12
  * site's production build.
15
13
  */
16
14
 
17
- import { getCollection } from 'astro:content';
18
15
  import baked from 'virtual:conloca-preview-opts';
19
- import routingConfig from 'virtual:conloca-routing-config';
20
- import { createCollectionBackedContentAPI } from '@conloca/astro-cms';
21
- import type { ContentAPI } from '@conloca/content-api';
22
- import { resolveEndpointFetch, resolveFromBaked } from './preview/_resolve-opts.js';
16
+ import { resolveFromBaked } from './preview/_resolve-opts.js';
23
17
  import {
24
18
  createPreviewSiteMiddleware,
25
19
  type PreviewMiddlewareContext,
26
20
  type PreviewMiddlewareNext,
27
21
  } from './preview/site-middleware.js';
28
22
  import { untagWorkerdProcess } from './preview/workerd-shim.js';
23
+ import { previewRenderSeams } from './preview-render-seams.js';
29
24
 
30
25
  // At Cloudflare Worker start-up, before any render: workerd's nodejs_compat
31
26
  // process can masquerade as Node's, sending Astro down a streaming branch whose
@@ -33,23 +28,10 @@ import { untagWorkerdProcess } from './preview/workerd-shim.js';
33
28
  // literal string "[object Object]". See the shim's doc for the full chain.
34
29
  untagWorkerdProcess();
35
30
 
36
- // One baseline per process: the built collections are immutable at runtime,
37
- // and constructing the collection-backed reader walks every collection.
38
- let baselinePromise: Promise<ContentAPI> | undefined;
39
- function baselineApi(): Promise<ContentAPI> {
40
- baselinePromise ??= createCollectionBackedContentAPI({
41
- getCollection: (name) => getCollection(name),
42
- routing: routingConfig,
43
- });
44
- return baselinePromise;
45
- }
46
-
47
31
  export async function onRequest(context: PreviewMiddlewareContext, next: PreviewMiddlewareNext): Promise<Response> {
48
32
  const handler = createPreviewSiteMiddleware(() => resolveFromBaked(baked, (name) => process.env[name]), {
49
- baselineApi,
50
- site: routingConfig.siteName,
51
- locale: routingConfig.locale,
52
- fetchFn: await resolveEndpointFetch(),
33
+ ...(await previewRenderSeams()),
34
+ baked,
53
35
  });
54
36
  return handler(context, next);
55
37
  }
@@ -36,7 +36,7 @@ conloca doctor --live # sends no credential: only your site's host and the e
36
36
  conloca doctor # offline: wiring, sites.json host, committed framing headers, key leftovers
37
37
  ```
38
38
 
39
- This package's checks are `CC1` and `CC8`–`CC24`:
39
+ This package's checks are `CC1` and `CC8`–`CC29`:
40
40
 
41
41
  - **CC9** — `sites.json`: the site named `default` (or the only one) has a bare host in `domains[defaultLocale]` and a
42
42
  valid `base`. The editor opens `https://<host><base>_conloca/editor/`; it refuses IPs, `localhost`, `*.conloca.com`.
@@ -59,6 +59,24 @@ This package's checks are `CC1` and `CC8`–`CC24`:
59
59
  `connect --yes --cf-plan paid` (or `free`). On Free with API routes, CC23 warns that previews and those routes share
60
60
  one daily request quota; Cloudflare Workers Paid removes the limit.
61
61
  - **CC24** (live) — a separate preview deploy's `conloca.json` answers as D4.
62
+ - **CC25–CC28** — draft previews in the site's own build (d8): one of the four official adapters, in the tested release
63
+ range, on an astro at or above its floor; nothing that turns preview off (`isr` without the preview route excluded,
64
+ edge middleware, `previewBuild.adapter`, `separate: true` under Vercel or Netlify); the host's routing (Vercel
65
+ `build.format: 'file'`, `site` on Vercel and Netlify, a static Cloudflare site's `run_worker_first` and `"404-page"`);
66
+ `security.allowedDomains` on `@astrojs/node`. Fix: `npx @conloca/cli connect` (adds the adapter and its options).
67
+ - **CC29** (live) — `<host><base>_conloca/preview/__exit` answers 302, uncached, as the configured mode. A failure names
68
+ where the host keeps logs; a 401/403/429 means something in front of the site blocks `/_conloca/preview/*`.
69
+
70
+ ## Draft previews in the site's own build (d8)
71
+
72
+ - Updating `@conloca/cloud-astro` switches a D2 site (preview from its own server) and an `@astrojs/cloudflare`
73
+ server-rendered site to d8 on the next build. Run `npx @conloca/cli upgrade` for the edits: the start command moves to
74
+ `node dist/server/entry.mjs`, and the `previewBuild` options d8 ignores go.
75
+ - Read `Astro.locals.contentApi` inside each request. Never cache it, or anything read from it, at module level: on a
76
+ server-rendered site drafts and published pages share one warm function.
77
+ - A static Vercel site adds a `src/pages/404` page, or every miss runs the preview function.
78
+ - Vercel and Netlify sites set `site` in `astro.config` so their own pages stay inside the preview. `site` also changes
79
+ canonical, sitemap, RSS and Open Graph URLs on the live pages: ask the site owner first.
62
80
 
63
81
  ## Framing: only when the site forbids it
64
82
 
package/src/types.ts CHANGED
@@ -1,32 +1,31 @@
1
1
  import type { AstroIntegration } from 'astro';
2
2
 
3
3
  /**
4
- * The second build that serves draft previews. Off unless given as an object. A static site's preview server runs on
5
- * Cloudflare Workers under `/_conloca/preview/` next to the site (it needs `@astrojs/cloudflare` installed); a site
6
- * with an adapter serves drafts from its own server deploy; `separate: true` builds a separate preview deploy.
7
- * Refused under `@astrojs/vercel` and `@astrojs/netlify`.
4
+ * Draft previews. Off unless given as an object. A static site's preview server is a second build that runs on
5
+ * Cloudflare Workers under `/_conloca/preview/` next to the site (D3; it needs `@astrojs/cloudflare` installed); a site
6
+ * with an adapter renders drafts in its own build (D8); `separate: true` builds a separate preview deploy (D4).
7
+ * `config` and `outDir` belong to D3 and D4 only (a D8 build warns they have no effect); `required` is ignored in every
8
+ * mode, with a warning. `separate` is
9
+ * refused under `@astrojs/vercel` and `@astrojs/netlify`.
8
10
  */
9
11
  export interface PreviewBuildOptions {
10
- /**
11
- * Optional alternative Astro adapter to use for the preview build.
12
- * Falls back to the project's default adapter when omitted.
13
- */
12
+ /** Refused: drafts render through the adapter in astro.config. Kept in the type so the refusal can name it. */
14
13
  adapter?: AstroIntegration;
15
14
  /**
16
- * Adapter-specific config overrides forwarded to the recursive build.
15
+ * Adapter-specific config overrides forwarded to the D3 or D4 preview build.
17
16
  */
18
17
  config?: Record<string, unknown>;
19
18
  /**
20
- * Output directory for the preview build. Defaults to `.conloca/preview-server`
19
+ * Output directory for the D3 or D4 preview build. Defaults to `.conloca/preview-server`
21
20
  * — outside `dist/`, so the preview server can never ride a wholesale static
22
21
  * upload of the site and Astro's dist-clearing cannot wipe it.
23
22
  */
24
23
  outDir?: string;
25
24
  /**
26
- * If true, fail the site's build when a D2 preview build fails. Defaults to true; set false while setting up.
27
- * A failed D3 preview build fails the site's build only when its server also serves the live site (`run_worker_first`
28
- * lists routes beyond the preview route, or `not_found_handling` is `"none"`); otherwise the site ships and its
29
- * preview route answers "preview unavailable". This option changes neither.
25
+ * Ignored in every mode (the build warns). A failed D3 preview build fails the site's build only when its server also
26
+ * serves the live site (`run_worker_first` lists routes beyond the preview route, or `not_found_handling` is
27
+ * `"none"`); otherwise the site ships and its preview route answers "preview unavailable". A D4 build is its deploy's
28
+ * own.
30
29
  */
31
30
  required?: boolean;
32
31
  /**
@@ -79,8 +78,8 @@ export interface ConlocaCloudOptions {
79
78
  */
80
79
  siteStyles?: string | string[];
81
80
  /**
82
- * Off unless given as an object; the second build that serves draft
83
- * previews. Refused under @astrojs/vercel and @astrojs/netlify.
81
+ * Off unless given as an object: draft previews in the site's own build (d8, with an adapter), next to a static
82
+ * site (D3) or from a separate deploy (D4). `separate` is refused under @astrojs/vercel and @astrojs/netlify.
84
83
  */
85
84
  previewBuild?: PreviewBuildOptions | false;
86
85
  /**
@@ -6,8 +6,9 @@
6
6
  * augmenting an existing module rather than declaring a new ambient one.
7
7
  *
8
8
  * `virtual:conloca-preview-opts` carries the preview middleware's configuration
9
- * baked in during the recursive preview build, so a preview deployment needs no
10
- * runtime env vars. It resolves to `{}` outside that build.
9
+ * baked in during the preview build (or a d8 site's own build), so a preview
10
+ * deployment needs no runtime env vars. It resolves to `{}` outside those builds.
11
+ * Mirrors `BakedPreviewOpts`.
11
12
  */
12
13
  declare module 'virtual:conloca-preview-opts' {
13
14
  const baked: {
@@ -19,6 +20,15 @@ declare module 'virtual:conloca-preview-opts' {
19
20
  siteId?: string;
20
21
  branch?: string;
21
22
  base?: string;
23
+ mode?: 'd2' | 'd3' | 'd4' | 'd8';
24
+ domains?: string[];
25
+ trailingSlash?: 'always' | 'never' | 'ignore';
26
+ sitePages?:
27
+ | { kind: 'disk'; serverEntry: string }
28
+ | { kind: 'assets' }
29
+ | { kind: 'function'; serverEntry: string; origin: string | null }
30
+ | { kind: 'none' };
31
+ buildFormat?: 'directory' | 'file' | 'preserve';
22
32
  };
23
33
  export default baked;
24
34
  }
@@ -44,6 +54,11 @@ declare module 'astro:content' {
44
54
  export function getCollection(collection: string): Promise<{ data: Record<string, unknown> }[]>;
45
55
  }
46
56
 
57
+ /** Astro's assets module, resolvable only inside a site build: the image config the preview image endpoint checks. */
58
+ declare module 'astro:assets' {
59
+ export const imageConfig: import('astro').AstroConfig['image'];
60
+ }
61
+
47
62
  /**
48
63
  * The Cloudflare Workers runtime module (bindings live here since Astro v6
49
64
  * removed `locals.runtime.env`). Only resolvable inside workerd; the preview