@conloca/cloud-astro 0.0.0-stage → 0.2.2

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 (196) hide show
  1. package/README.md +328 -2
  2. package/dist/src/build-commit.d.ts +19 -0
  3. package/dist/src/build-commit.d.ts.map +1 -0
  4. package/dist/src/build-commit.js +6 -0
  5. package/dist/src/build-commit.js.map +1 -0
  6. package/dist/src/bundle.d.ts +181 -0
  7. package/dist/src/bundle.d.ts.map +1 -0
  8. package/dist/src/bundle.js +413 -0
  9. package/dist/src/bundle.js.map +1 -0
  10. package/dist/src/component-manifest.d.ts +29 -0
  11. package/dist/src/component-manifest.d.ts.map +1 -0
  12. package/dist/src/component-manifest.js +53 -0
  13. package/dist/src/component-manifest.js.map +1 -0
  14. package/dist/src/constants.d.ts +26 -0
  15. package/dist/src/constants.d.ts.map +1 -0
  16. package/dist/src/constants.js +26 -0
  17. package/dist/src/constants.js.map +1 -0
  18. package/dist/src/descriptors.d.ts +25 -0
  19. package/dist/src/descriptors.d.ts.map +1 -0
  20. package/dist/src/descriptors.js +65 -0
  21. package/dist/src/descriptors.js.map +1 -0
  22. package/dist/src/discovery.d.ts +58 -0
  23. package/dist/src/discovery.d.ts.map +1 -0
  24. package/dist/src/discovery.js +133 -0
  25. package/dist/src/discovery.js.map +1 -0
  26. package/dist/src/doctor/checks-live.d.ts +15 -0
  27. package/dist/src/doctor/checks-live.d.ts.map +1 -0
  28. package/dist/src/doctor/checks-live.js +229 -0
  29. package/dist/src/doctor/checks-live.js.map +1 -0
  30. package/dist/src/doctor/checks-offline.d.ts +36 -0
  31. package/dist/src/doctor/checks-offline.d.ts.map +1 -0
  32. package/dist/src/doctor/checks-offline.js +301 -0
  33. package/dist/src/doctor/checks-offline.js.map +1 -0
  34. package/dist/src/doctor/config-scan.d.ts +55 -0
  35. package/dist/src/doctor/config-scan.d.ts.map +1 -0
  36. package/dist/src/doctor/config-scan.js +178 -0
  37. package/dist/src/doctor/config-scan.js.map +1 -0
  38. package/dist/src/doctor/run.d.ts +4 -0
  39. package/dist/src/doctor/run.d.ts.map +1 -0
  40. package/dist/src/doctor/run.js +29 -0
  41. package/dist/src/doctor/run.js.map +1 -0
  42. package/dist/src/doctor/types.d.ts +60 -0
  43. package/dist/src/doctor/types.d.ts.map +1 -0
  44. package/dist/src/doctor/types.js +18 -0
  45. package/dist/src/doctor/types.js.map +1 -0
  46. package/dist/src/doctor.d.ts +9 -0
  47. package/dist/src/doctor.d.ts.map +1 -0
  48. package/dist/src/doctor.js +12 -0
  49. package/dist/src/doctor.js.map +1 -0
  50. package/dist/src/git.d.ts +38 -0
  51. package/dist/src/git.d.ts.map +1 -0
  52. package/dist/src/git.js +43 -0
  53. package/dist/src/git.js.map +1 -0
  54. package/dist/src/index.d.ts +3 -0
  55. package/dist/src/index.d.ts.map +1 -0
  56. package/dist/src/index.js +7 -0
  57. package/dist/src/index.js.map +1 -0
  58. package/dist/src/integration.d.ts +6 -0
  59. package/dist/src/integration.d.ts.map +1 -0
  60. package/dist/src/integration.js +544 -0
  61. package/dist/src/integration.js.map +1 -0
  62. package/dist/src/message-of.d.ts +3 -0
  63. package/dist/src/message-of.d.ts.map +1 -0
  64. package/dist/src/message-of.js +5 -0
  65. package/dist/src/message-of.js.map +1 -0
  66. package/dist/src/node.d.ts +3 -0
  67. package/dist/src/node.d.ts.map +1 -0
  68. package/dist/src/node.js +4 -0
  69. package/dist/src/node.js.map +1 -0
  70. package/dist/src/package-version.d.ts +7 -0
  71. package/dist/src/package-version.d.ts.map +1 -0
  72. package/dist/src/package-version.js +17 -0
  73. package/dist/src/package-version.js.map +1 -0
  74. package/dist/src/preview/_dispatch.d.ts +55 -0
  75. package/dist/src/preview/_dispatch.d.ts.map +1 -0
  76. package/dist/src/preview/_dispatch.js +72 -0
  77. package/dist/src/preview/_dispatch.js.map +1 -0
  78. package/dist/src/preview/_resolve-opts.d.ts +30 -0
  79. package/dist/src/preview/_resolve-opts.d.ts.map +1 -0
  80. package/dist/src/preview/_resolve-opts.js +73 -0
  81. package/dist/src/preview/_resolve-opts.js.map +1 -0
  82. package/dist/src/preview/banner.d.ts +29 -0
  83. package/dist/src/preview/banner.d.ts.map +1 -0
  84. package/dist/src/preview/banner.js +94 -0
  85. package/dist/src/preview/banner.js.map +1 -0
  86. package/dist/src/preview/content-api.d.ts +110 -0
  87. package/dist/src/preview/content-api.d.ts.map +1 -0
  88. package/dist/src/preview/content-api.js +216 -0
  89. package/dist/src/preview/content-api.js.map +1 -0
  90. package/dist/src/preview/cookie.d.ts +36 -0
  91. package/dist/src/preview/cookie.d.ts.map +1 -0
  92. package/dist/src/preview/cookie.js +59 -0
  93. package/dist/src/preview/cookie.js.map +1 -0
  94. package/dist/src/preview/headers.d.ts +25 -0
  95. package/dist/src/preview/headers.d.ts.map +1 -0
  96. package/dist/src/preview/headers.js +31 -0
  97. package/dist/src/preview/headers.js.map +1 -0
  98. package/dist/src/preview/landing.d.ts +22 -0
  99. package/dist/src/preview/landing.d.ts.map +1 -0
  100. package/dist/src/preview/landing.js +70 -0
  101. package/dist/src/preview/landing.js.map +1 -0
  102. package/dist/src/preview/middleware.d.ts +118 -0
  103. package/dist/src/preview/middleware.d.ts.map +1 -0
  104. package/dist/src/preview/middleware.js +197 -0
  105. package/dist/src/preview/middleware.js.map +1 -0
  106. package/dist/src/preview/preview-path.d.ts +21 -0
  107. package/dist/src/preview/preview-path.d.ts.map +1 -0
  108. package/dist/src/preview/preview-path.js +29 -0
  109. package/dist/src/preview/preview-path.js.map +1 -0
  110. package/dist/src/preview/satteri-workerd.d.ts +17 -0
  111. package/dist/src/preview/satteri-workerd.d.ts.map +1 -0
  112. package/dist/src/preview/satteri-workerd.js +18 -0
  113. package/dist/src/preview/satteri-workerd.js.map +1 -0
  114. package/dist/src/preview/site-middleware.d.ts +69 -0
  115. package/dist/src/preview/site-middleware.d.ts.map +1 -0
  116. package/dist/src/preview/site-middleware.js +160 -0
  117. package/dist/src/preview/site-middleware.js.map +1 -0
  118. package/dist/src/preview/workerd-shim.d.ts +19 -0
  119. package/dist/src/preview/workerd-shim.d.ts.map +1 -0
  120. package/dist/src/preview/workerd-shim.js +33 -0
  121. package/dist/src/preview/workerd-shim.js.map +1 -0
  122. package/dist/src/preview-build.d.ts +71 -0
  123. package/dist/src/preview-build.d.ts.map +1 -0
  124. package/dist/src/preview-build.js +115 -0
  125. package/dist/src/preview-build.js.map +1 -0
  126. package/dist/src/preview.d.ts +6 -0
  127. package/dist/src/preview.d.ts.map +1 -0
  128. package/dist/src/preview.js +12 -0
  129. package/dist/src/preview.js.map +1 -0
  130. package/dist/src/register.d.ts +98 -0
  131. package/dist/src/register.d.ts.map +1 -0
  132. package/dist/src/register.js +103 -0
  133. package/dist/src/register.js.map +1 -0
  134. package/dist/src/repository.d.ts +18 -0
  135. package/dist/src/repository.d.ts.map +1 -0
  136. package/dist/src/repository.js +46 -0
  137. package/dist/src/repository.js.map +1 -0
  138. package/dist/src/site-id.d.ts +18 -0
  139. package/dist/src/site-id.d.ts.map +1 -0
  140. package/dist/src/site-id.js +70 -0
  141. package/dist/src/site-id.js.map +1 -0
  142. package/dist/src/site-middleware.d.ts +18 -0
  143. package/dist/src/site-middleware.d.ts.map +1 -0
  144. package/dist/src/site-middleware.js +47 -0
  145. package/dist/src/site-middleware.js.map +1 -0
  146. package/dist/src/skill.d.ts +26 -0
  147. package/dist/src/skill.d.ts.map +1 -0
  148. package/dist/src/skill.js +67 -0
  149. package/dist/src/skill.js.map +1 -0
  150. package/dist/src/types.d.ts +135 -0
  151. package/dist/src/types.d.ts.map +1 -0
  152. package/dist/src/types.js +2 -0
  153. package/dist/src/types.js.map +1 -0
  154. package/package.json +182 -4
  155. package/src/build-commit.ts +22 -0
  156. package/src/bundle.ts +570 -0
  157. package/src/component-manifest.ts +75 -0
  158. package/src/constants.ts +28 -0
  159. package/src/descriptors.ts +92 -0
  160. package/src/discovery.ts +183 -0
  161. package/src/doctor/checks-live.ts +324 -0
  162. package/src/doctor/checks-offline.ts +325 -0
  163. package/src/doctor/config-scan.ts +205 -0
  164. package/src/doctor/run.ts +39 -0
  165. package/src/doctor/types.ts +71 -0
  166. package/src/doctor.ts +14 -0
  167. package/src/git.ts +66 -0
  168. package/src/index.ts +8 -0
  169. package/src/integration.ts +607 -0
  170. package/src/message-of.ts +4 -0
  171. package/src/node.ts +5 -0
  172. package/src/package-version.ts +16 -0
  173. package/src/preview/_dispatch.ts +105 -0
  174. package/src/preview/_resolve-opts.ts +89 -0
  175. package/src/preview/banner.ts +96 -0
  176. package/src/preview/content-api.ts +293 -0
  177. package/src/preview/cookie.ts +54 -0
  178. package/src/preview/headers.ts +30 -0
  179. package/src/preview/landing.ts +73 -0
  180. package/src/preview/middleware.ts +309 -0
  181. package/src/preview/preview-path.ts +28 -0
  182. package/src/preview/satteri-workerd.ts +24 -0
  183. package/src/preview/site-middleware.ts +210 -0
  184. package/src/preview/workerd-shim.ts +31 -0
  185. package/src/preview-build.ts +147 -0
  186. package/src/preview-handler.astro +55 -0
  187. package/src/preview-handler.d.ts +6 -0
  188. package/src/preview.ts +22 -0
  189. package/src/register.ts +180 -0
  190. package/src/repository.ts +54 -0
  191. package/src/site-id.ts +86 -0
  192. package/src/site-middleware.ts +55 -0
  193. package/src/skill/SKILL.md +69 -0
  194. package/src/skill.ts +66 -0
  195. package/src/types.ts +137 -0
  196. package/src/virtual-modules.d.ts +52 -0
package/src/skill.ts ADDED
@@ -0,0 +1,66 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import { createRequire } from 'node:module';
3
+ import { dirname, join } from 'node:path';
4
+ import { pathToFileURL } from 'node:url';
5
+ import { messageOf } from './message-of.js';
6
+
7
+ export const SKILL_RELATIVE_PATH = join('.claude', 'skills', 'conloca-cloud', 'SKILL.md');
8
+
9
+ /**
10
+ * The canonical page, located from the package root (through the package's own `./package.json` export) so the
11
+ * built `dist/src/skill.js` and the source `src/skill.ts` reach the same shipped `src/skill/SKILL.md`. Resolved on
12
+ * demand, not at import: a copy running outside its package boundary must fail inside scaffoldSkill's
13
+ * fail-soft path, never while the site's Astro config is loading.
14
+ */
15
+ export function skillTemplateUrl(): URL {
16
+ const packageRoot = dirname(createRequire(import.meta.url).resolve('@conloca/cloud-astro/package.json'));
17
+ return pathToFileURL(join(packageRoot, 'src', 'skill', 'SKILL.md'));
18
+ }
19
+
20
+ type SkillLogger = { info(msg: string): void; debug(msg: string): void };
21
+
22
+ /**
23
+ * The nearest directory, from the Astro project root up to the git root, that
24
+ * carries a `.claude/`. Repo-root layouts are the real ones: a site's
25
+ * Astro project is usually a workspace member below the repo root. Needs a git
26
+ * root: a project outside any repository gets nothing.
27
+ */
28
+ export function findClaudeHome(projectRoot: string): string | undefined {
29
+ let dir = projectRoot;
30
+ let home: string | undefined;
31
+ for (;;) {
32
+ if (home === undefined && existsSync(join(dir, '.claude'))) home = dir;
33
+ // The git root bounds the walk; without one there is no repo to scaffold into
34
+ // (a stray ~/.claude must never receive a global copy).
35
+ if (existsSync(join(dir, '.git'))) return home;
36
+ const parent = dirname(dir);
37
+ if (parent === dir) return undefined;
38
+ dir = parent;
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Write the skill page once — never overwrite, never throw. A read-only CI
44
+ * checkout must not break a build over documentation.
45
+ */
46
+ export function scaffoldSkill(projectRoot: string, logger: SkillLogger): 'written' | 'exists' | 'skipped' | 'failed' {
47
+ const home = findClaudeHome(projectRoot);
48
+ if (home === undefined) {
49
+ logger.debug('no .claude/ directory between the project and the git root — agent skill not scaffolded');
50
+ return 'skipped';
51
+ }
52
+ const target = join(home, SKILL_RELATIVE_PATH);
53
+ if (existsSync(target)) return 'exists';
54
+ try {
55
+ mkdirSync(dirname(target), { recursive: true });
56
+ writeFileSync(target, readFileSync(skillTemplateUrl(), 'utf8'), { flag: 'wx' });
57
+ logger.info(`agent skill written to ${target}`);
58
+ return 'written';
59
+ } catch (error) {
60
+ // The exclusive write lost a race with a concurrent build (or a symlink sits
61
+ // at the path): the page is there, which is the truthful outcome.
62
+ if ((error as NodeJS.ErrnoException).code === 'EEXIST') return 'exists';
63
+ logger.info(`agent skill not written to ${target} (${messageOf(error)})`);
64
+ return 'failed';
65
+ }
66
+ }
package/src/types.ts ADDED
@@ -0,0 +1,137 @@
1
+ import type { AstroIntegration } from 'astro';
2
+ import type { Plugin as EsbuildPlugin } from 'esbuild';
3
+
4
+ /**
5
+ * Configuration for a recursive preview build that runs immediately after the
6
+ * site's production build completes. The preview build emits the SSR routes
7
+ * that serve draft preview.
8
+ *
9
+ * Set to `false` to explicitly opt out of preview builds for sites that do not
10
+ * need a draft/preview pipeline.
11
+ */
12
+ export interface PreviewBuildOptions {
13
+ /**
14
+ * Optional alternative Astro adapter to use for the preview build.
15
+ * Falls back to the project's default adapter when omitted.
16
+ */
17
+ adapter?: AstroIntegration;
18
+ /**
19
+ * Adapter-specific config overrides forwarded to the recursive build.
20
+ */
21
+ config?: Record<string, unknown>;
22
+ /**
23
+ * Output directory for the preview build. Defaults to `.conloca/preview-server`
24
+ * — outside `dist/`, so the secret-baked artifact can never ride a wholesale
25
+ * static upload of the site and Astro's dist-clearing cannot wipe it.
26
+ */
27
+ outDir?: string;
28
+ /**
29
+ * If true, fail the parent build when the preview build fails. Defaults to
30
+ * true; set false while setting up.
31
+ */
32
+ required?: boolean;
33
+ }
34
+
35
+ /**
36
+ * Options accepted by {@link conlocaCloud}.
37
+ *
38
+ * Registration authenticates with one build token (`cbt_<id>.<secret>`)
39
+ * issued by the endpoint. Repository identity is normally detected from CI metadata or the Git
40
+ * checkout.
41
+ */
42
+ export interface ConlocaCloudOptions {
43
+ /** Editor endpoint, e.g. 'https://cms.example.com', no trailing slash. */
44
+ endpoint: string;
45
+ /**
46
+ * Advanced override for repository identity, normalized to `owner/repo`.
47
+ * Normally omit this: Conloca detects GitHub, Vercel, or GitLab CI metadata,
48
+ * then falls back to the checkout's `remote.origin.url`. Registration is
49
+ * rejected when the token does not cover the detected repo.
50
+ */
51
+ repoUri?: string;
52
+ /**
53
+ * Advanced override for the deployable-site id, for CMS-less builds where
54
+ * `conlocaCMS` does not publish CONLOCA_CONTENT_ROOT. When the CMS channel IS
55
+ * present, the content root's sites.json is authoritative and an override
56
+ * that contradicts it fails the build — never a silent pick.
57
+ */
58
+ siteId?: string;
59
+ /**
60
+ * Build token issued by the endpoint. Prefer injecting it via the
61
+ * CONLOCA_BUILD_TOKEN environment variable instead of committing it here;
62
+ * when neither is present the build skips registration (fail soft, unless
63
+ * `requireRegistration` is set).
64
+ */
65
+ buildToken?: string;
66
+ /**
67
+ * Entry module of the puck config to compile into the editor bundle,
68
+ * e.g. './src/puck.config.tsx'. Same option name as @conloca/astro-cms.
69
+ */
70
+ puckConfigPath: string;
71
+ /**
72
+ * Site CSS for accurate preview rendering — same option name and shape
73
+ * as `conlocaCMS({ siteStyles })`, and compiled the same way: by the site's
74
+ * own Vite pipeline (its plugins, PostCSS config and preprocessors), into
75
+ * the canvas stylesheet each build registers, ahead of the
76
+ * component modules, e.g. './src/styles/index.scss'. Paths resolve against
77
+ * the project root. The assets these stylesheets reference are emitted under
78
+ * `/_conloca/`, and an entry that fails to compile fails the build. Component
79
+ * `*.module.(s)css` imports compile in automatically — list here only what
80
+ * lives outside the component graph.
81
+ */
82
+ siteStyles?: string | string[];
83
+ /**
84
+ * esbuild plugins for the editor bundle (puck config, its components and the
85
+ * conlocaCMS schemas module). That bundle is built with esbuild, outside the
86
+ * site's Vite pipeline, so a source transform the site's Vite plugins apply
87
+ * — e.g. Typia's `createValidate<T>()` generation in page schemas — must be
88
+ * passed here in its esbuild form too, or the bundle carries untransformed
89
+ * calls that throw when the editor loads it.
90
+ */
91
+ editorBundlePlugins?: EsbuildPlugin[];
92
+ /**
93
+ * Representative content route for build-time style discovery — the SAME
94
+ * name and meaning as `conlocaCMS`'s option: the page whose styles and
95
+ * content-wrapper shape prose editing should adopt. When set, the build
96
+ * reads that route's rendered page (a prerendered file, or the booted node
97
+ * server entry), collects its CSS and wrapper shape, and registers them
98
+ * alongside the bundle. Unset: discovery is skipped and the editor falls
99
+ * back to the prose-safe derived tier.
100
+ *
101
+ * @example '/blog/welcome-post'
102
+ */
103
+ fragmentPreviewRoute?: string;
104
+
105
+ /**
106
+ * Public base URL of the deployed site, used to absolutize the editor
107
+ * bundle URL when no dedicated preview domain is configured. Falls back to
108
+ * the CF_PAGES_URL env var; without either, registration is skipped.
109
+ */
110
+ publicBaseUrl?: string;
111
+ /**
112
+ * Optional dedicated preview deployment as a hostname or absolute URL. A
113
+ * hostname is normalized to HTTPS. When set, editor assets and preview links
114
+ * use this deployment instead of the production site's public base URL.
115
+ */
116
+ previewDomain?: string;
117
+ /**
118
+ * Recursive preview build configuration. Set to `false` to opt out.
119
+ * Defaults to enabled with project defaults.
120
+ */
121
+ previewBuild?: PreviewBuildOptions | false;
122
+ /**
123
+ * The token issuer (the JWT `iss` the preview middleware pins).
124
+ * Set it to bake the value into the preview artifact; otherwise the
125
+ * deployment must supply `CONLOCA_SAAS_ISSUER` at runtime.
126
+ */
127
+ saasIssuer?: string;
128
+ /**
129
+ * Fail the build when registration is SKIPPED for a missing prerequisite
130
+ * (no build token, no repository identity, no git sha/branch, no public
131
+ * base URL). Default false, so a plain `astro build` without the token
132
+ * stays untouched. Turn it on in CI once setup is done: a deploy can
133
+ * then never silently leave the editor at the endpoint stale. An ATTEMPTED
134
+ * registration that fails always fails the build, regardless of this.
135
+ */
136
+ requireRegistration?: boolean;
137
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Ambient declaration for the build-time virtual module the integration serves.
3
+ *
4
+ * Kept in its OWN file with no top-level import/export: in a module (a file
5
+ * that imports or exports anything), a `declare module` is treated as
6
+ * augmenting an existing module rather than declaring a new ambient one.
7
+ *
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.
11
+ */
12
+ declare module 'virtual:conloca-preview-opts' {
13
+ const baked: {
14
+ secret?: string;
15
+ saasEndpoint?: string;
16
+ saasIssuer?: string;
17
+ saasAudience?: string;
18
+ buildCommit?: string;
19
+ };
20
+ export default baked;
21
+ }
22
+
23
+ /**
24
+ * The routing config astro-cms's vite plugin serves to the site build. The
25
+ * middleware entry is compiled INTO the site's build graph (addMiddleware
26
+ * entrypoint), where the module resolves; this declaration only teaches tsc.
27
+ */
28
+ declare module 'virtual:conloca-routing-config' {
29
+ import type { ResolvedRoutingConfig } from '@conloca/astro-cms';
30
+
31
+ const config: ResolvedRoutingConfig;
32
+ export default config;
33
+ }
34
+
35
+ /**
36
+ * Astro's content-collections module, resolvable only inside a site build.
37
+ * Declared with the narrow surface the middleware entry consumes (the same
38
+ * projection `createCollectionBackedContentAPI` expects).
39
+ */
40
+ declare module 'astro:content' {
41
+ export function getCollection(collection: string): Promise<{ data: Record<string, unknown> }[]>;
42
+ }
43
+
44
+ /**
45
+ * The Cloudflare Workers runtime module (bindings live here since Astro v6
46
+ * removed `locals.runtime.env`). Only resolvable inside workerd; the preview
47
+ * middleware imports it dynamically and treats a failed import as "not on
48
+ * Cloudflare Workers". Declared with the narrow surface consumed (the env bag).
49
+ */
50
+ declare module 'cloudflare:workers' {
51
+ export const env: Record<string, unknown>;
52
+ }