@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.
- package/README.md +328 -2
- package/dist/src/build-commit.d.ts +19 -0
- package/dist/src/build-commit.d.ts.map +1 -0
- package/dist/src/build-commit.js +6 -0
- package/dist/src/build-commit.js.map +1 -0
- package/dist/src/bundle.d.ts +181 -0
- package/dist/src/bundle.d.ts.map +1 -0
- package/dist/src/bundle.js +413 -0
- package/dist/src/bundle.js.map +1 -0
- package/dist/src/component-manifest.d.ts +29 -0
- package/dist/src/component-manifest.d.ts.map +1 -0
- package/dist/src/component-manifest.js +53 -0
- package/dist/src/component-manifest.js.map +1 -0
- package/dist/src/constants.d.ts +26 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +26 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/descriptors.d.ts +25 -0
- package/dist/src/descriptors.d.ts.map +1 -0
- package/dist/src/descriptors.js +65 -0
- package/dist/src/descriptors.js.map +1 -0
- package/dist/src/discovery.d.ts +58 -0
- package/dist/src/discovery.d.ts.map +1 -0
- package/dist/src/discovery.js +133 -0
- package/dist/src/discovery.js.map +1 -0
- package/dist/src/doctor/checks-live.d.ts +15 -0
- package/dist/src/doctor/checks-live.d.ts.map +1 -0
- package/dist/src/doctor/checks-live.js +229 -0
- package/dist/src/doctor/checks-live.js.map +1 -0
- package/dist/src/doctor/checks-offline.d.ts +36 -0
- package/dist/src/doctor/checks-offline.d.ts.map +1 -0
- package/dist/src/doctor/checks-offline.js +301 -0
- package/dist/src/doctor/checks-offline.js.map +1 -0
- package/dist/src/doctor/config-scan.d.ts +55 -0
- package/dist/src/doctor/config-scan.d.ts.map +1 -0
- package/dist/src/doctor/config-scan.js +178 -0
- package/dist/src/doctor/config-scan.js.map +1 -0
- package/dist/src/doctor/run.d.ts +4 -0
- package/dist/src/doctor/run.d.ts.map +1 -0
- package/dist/src/doctor/run.js +29 -0
- package/dist/src/doctor/run.js.map +1 -0
- package/dist/src/doctor/types.d.ts +60 -0
- package/dist/src/doctor/types.d.ts.map +1 -0
- package/dist/src/doctor/types.js +18 -0
- package/dist/src/doctor/types.js.map +1 -0
- package/dist/src/doctor.d.ts +9 -0
- package/dist/src/doctor.d.ts.map +1 -0
- package/dist/src/doctor.js +12 -0
- package/dist/src/doctor.js.map +1 -0
- package/dist/src/git.d.ts +38 -0
- package/dist/src/git.d.ts.map +1 -0
- package/dist/src/git.js +43 -0
- package/dist/src/git.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +7 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/integration.d.ts +6 -0
- package/dist/src/integration.d.ts.map +1 -0
- package/dist/src/integration.js +544 -0
- package/dist/src/integration.js.map +1 -0
- package/dist/src/message-of.d.ts +3 -0
- package/dist/src/message-of.d.ts.map +1 -0
- package/dist/src/message-of.js +5 -0
- package/dist/src/message-of.js.map +1 -0
- package/dist/src/node.d.ts +3 -0
- package/dist/src/node.d.ts.map +1 -0
- package/dist/src/node.js +4 -0
- package/dist/src/node.js.map +1 -0
- package/dist/src/package-version.d.ts +7 -0
- package/dist/src/package-version.d.ts.map +1 -0
- package/dist/src/package-version.js +17 -0
- package/dist/src/package-version.js.map +1 -0
- package/dist/src/preview/_dispatch.d.ts +55 -0
- package/dist/src/preview/_dispatch.d.ts.map +1 -0
- package/dist/src/preview/_dispatch.js +72 -0
- package/dist/src/preview/_dispatch.js.map +1 -0
- package/dist/src/preview/_resolve-opts.d.ts +30 -0
- package/dist/src/preview/_resolve-opts.d.ts.map +1 -0
- package/dist/src/preview/_resolve-opts.js +73 -0
- package/dist/src/preview/_resolve-opts.js.map +1 -0
- package/dist/src/preview/banner.d.ts +29 -0
- package/dist/src/preview/banner.d.ts.map +1 -0
- package/dist/src/preview/banner.js +94 -0
- package/dist/src/preview/banner.js.map +1 -0
- package/dist/src/preview/content-api.d.ts +110 -0
- package/dist/src/preview/content-api.d.ts.map +1 -0
- package/dist/src/preview/content-api.js +216 -0
- package/dist/src/preview/content-api.js.map +1 -0
- package/dist/src/preview/cookie.d.ts +36 -0
- package/dist/src/preview/cookie.d.ts.map +1 -0
- package/dist/src/preview/cookie.js +59 -0
- package/dist/src/preview/cookie.js.map +1 -0
- package/dist/src/preview/headers.d.ts +25 -0
- package/dist/src/preview/headers.d.ts.map +1 -0
- package/dist/src/preview/headers.js +31 -0
- package/dist/src/preview/headers.js.map +1 -0
- package/dist/src/preview/landing.d.ts +22 -0
- package/dist/src/preview/landing.d.ts.map +1 -0
- package/dist/src/preview/landing.js +70 -0
- package/dist/src/preview/landing.js.map +1 -0
- package/dist/src/preview/middleware.d.ts +118 -0
- package/dist/src/preview/middleware.d.ts.map +1 -0
- package/dist/src/preview/middleware.js +197 -0
- package/dist/src/preview/middleware.js.map +1 -0
- package/dist/src/preview/preview-path.d.ts +21 -0
- package/dist/src/preview/preview-path.d.ts.map +1 -0
- package/dist/src/preview/preview-path.js +29 -0
- package/dist/src/preview/preview-path.js.map +1 -0
- package/dist/src/preview/satteri-workerd.d.ts +17 -0
- package/dist/src/preview/satteri-workerd.d.ts.map +1 -0
- package/dist/src/preview/satteri-workerd.js +18 -0
- package/dist/src/preview/satteri-workerd.js.map +1 -0
- package/dist/src/preview/site-middleware.d.ts +69 -0
- package/dist/src/preview/site-middleware.d.ts.map +1 -0
- package/dist/src/preview/site-middleware.js +160 -0
- package/dist/src/preview/site-middleware.js.map +1 -0
- package/dist/src/preview/workerd-shim.d.ts +19 -0
- package/dist/src/preview/workerd-shim.d.ts.map +1 -0
- package/dist/src/preview/workerd-shim.js +33 -0
- package/dist/src/preview/workerd-shim.js.map +1 -0
- package/dist/src/preview-build.d.ts +71 -0
- package/dist/src/preview-build.d.ts.map +1 -0
- package/dist/src/preview-build.js +115 -0
- package/dist/src/preview-build.js.map +1 -0
- package/dist/src/preview.d.ts +6 -0
- package/dist/src/preview.d.ts.map +1 -0
- package/dist/src/preview.js +12 -0
- package/dist/src/preview.js.map +1 -0
- package/dist/src/register.d.ts +98 -0
- package/dist/src/register.d.ts.map +1 -0
- package/dist/src/register.js +103 -0
- package/dist/src/register.js.map +1 -0
- package/dist/src/repository.d.ts +18 -0
- package/dist/src/repository.d.ts.map +1 -0
- package/dist/src/repository.js +46 -0
- package/dist/src/repository.js.map +1 -0
- package/dist/src/site-id.d.ts +18 -0
- package/dist/src/site-id.d.ts.map +1 -0
- package/dist/src/site-id.js +70 -0
- package/dist/src/site-id.js.map +1 -0
- package/dist/src/site-middleware.d.ts +18 -0
- package/dist/src/site-middleware.d.ts.map +1 -0
- package/dist/src/site-middleware.js +47 -0
- package/dist/src/site-middleware.js.map +1 -0
- package/dist/src/skill.d.ts +26 -0
- package/dist/src/skill.d.ts.map +1 -0
- package/dist/src/skill.js +67 -0
- package/dist/src/skill.js.map +1 -0
- package/dist/src/types.d.ts +135 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +182 -4
- package/src/build-commit.ts +22 -0
- package/src/bundle.ts +570 -0
- package/src/component-manifest.ts +75 -0
- package/src/constants.ts +28 -0
- package/src/descriptors.ts +92 -0
- package/src/discovery.ts +183 -0
- package/src/doctor/checks-live.ts +324 -0
- package/src/doctor/checks-offline.ts +325 -0
- package/src/doctor/config-scan.ts +205 -0
- package/src/doctor/run.ts +39 -0
- package/src/doctor/types.ts +71 -0
- package/src/doctor.ts +14 -0
- package/src/git.ts +66 -0
- package/src/index.ts +8 -0
- package/src/integration.ts +607 -0
- package/src/message-of.ts +4 -0
- package/src/node.ts +5 -0
- package/src/package-version.ts +16 -0
- package/src/preview/_dispatch.ts +105 -0
- package/src/preview/_resolve-opts.ts +89 -0
- package/src/preview/banner.ts +96 -0
- package/src/preview/content-api.ts +293 -0
- package/src/preview/cookie.ts +54 -0
- package/src/preview/headers.ts +30 -0
- package/src/preview/landing.ts +73 -0
- package/src/preview/middleware.ts +309 -0
- package/src/preview/preview-path.ts +28 -0
- package/src/preview/satteri-workerd.ts +24 -0
- package/src/preview/site-middleware.ts +210 -0
- package/src/preview/workerd-shim.ts +31 -0
- package/src/preview-build.ts +147 -0
- package/src/preview-handler.astro +55 -0
- package/src/preview-handler.d.ts +6 -0
- package/src/preview.ts +22 -0
- package/src/register.ts +180 -0
- package/src/repository.ts +54 -0
- package/src/site-id.ts +86 -0
- package/src/site-middleware.ts +55 -0
- package/src/skill/SKILL.md +69 -0
- package/src/skill.ts +66 -0
- package/src/types.ts +137 -0
- package/src/virtual-modules.d.ts +52 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { PREVIEW_SECRET_ENV_FLAG } from './constants.js';
|
|
2
|
+
import type { PreviewBuildOptions } from './types.js';
|
|
3
|
+
export { PREVIEW_SECRET_ENV_FLAG };
|
|
4
|
+
/**
|
|
5
|
+
* The minimal child-process surface this module relies on. Letting
|
|
6
|
+
* {@link _spawnPreviewBuildWith} accept any function that produces a process
|
|
7
|
+
* with an `on('exit', ...)` listener keeps the test seam narrow — tests can
|
|
8
|
+
* pass a tiny fake without reconstructing the full `ChildProcess` shape, and
|
|
9
|
+
* the implementation stays decoupled from internals it doesn't use.
|
|
10
|
+
*/
|
|
11
|
+
export interface PreviewBuildChildProcess {
|
|
12
|
+
on(event: 'exit', listener: (code: number | null) => void): unknown;
|
|
13
|
+
}
|
|
14
|
+
export type PreviewBuildSpawn = (command: string, args: readonly string[], options: {
|
|
15
|
+
env: NodeJS.ProcessEnv;
|
|
16
|
+
stdio: 'inherit';
|
|
17
|
+
}) => PreviewBuildChildProcess;
|
|
18
|
+
/**
|
|
19
|
+
* Pure constructor for the child-process environment passed to the recursive
|
|
20
|
+
* preview build. Extracted so tests can verify the contract (env flag + secret
|
|
21
|
+
* + parent-env inheritance) without spinning up a child process — and so the
|
|
22
|
+
* real-process smoke test can call it the same way the integration does.
|
|
23
|
+
*
|
|
24
|
+
* Inherits the parent environment so PATH, credentials, and any host-specific
|
|
25
|
+
* build vars (CF_PAGES_*, GITHUB_*) reach the child.
|
|
26
|
+
*/
|
|
27
|
+
export declare function buildPreviewChildEnv(parentEnv: NodeJS.ProcessEnv, previewSecret: string): NodeJS.ProcessEnv;
|
|
28
|
+
/**
|
|
29
|
+
* Locate the `astro` CLI binary in the site's `node_modules/.bin/`. We
|
|
30
|
+
* resolve relative to the current working directory (where `astro build` is
|
|
31
|
+
* being invoked) rather than to this package's install location, because
|
|
32
|
+
* `@conloca/cloud-astro` lists `astro` only as a peerDependency and would
|
|
33
|
+
* therefore not have it in its own node_modules.
|
|
34
|
+
*
|
|
35
|
+
* Bare `bun x astro build` would be the obvious one-liner, but `bunx`/`bun x`
|
|
36
|
+
* auto-fetch a package when it is missing, which a build must never do — so
|
|
37
|
+
* resolve the installed binary and spawn it directly.
|
|
38
|
+
*/
|
|
39
|
+
export declare function resolveAstroBin(cwd?: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Spawns the recursive preview `astro build` from the primary build's
|
|
42
|
+
* `astro:build:done` hook.
|
|
43
|
+
*
|
|
44
|
+
* The child process inherits the parent environment and additionally receives:
|
|
45
|
+
* - {@link PREVIEW_BUILD_ENV_FLAG} set to `'1'` so the integration's own
|
|
46
|
+
* `astro:build:done` short-circuits inside the child (recursion guard
|
|
47
|
+
* contract).
|
|
48
|
+
* - {@link PREVIEW_SECRET_ENV_FLAG} set to the per-branch secret so the
|
|
49
|
+
* child's `astro:config:setup` can inject the literal secret-scoped
|
|
50
|
+
* preview route (`/conloca_preview_${SECRET}/[...path]`).
|
|
51
|
+
*
|
|
52
|
+
* If this function is itself called from within a recursive build (i.e. the
|
|
53
|
+
* env flag is already set to `'1'`), it returns immediately without spawning,
|
|
54
|
+
* which is the outermost layer of the recursion guard.
|
|
55
|
+
*
|
|
56
|
+
* On a non-zero child exit, behaviour depends on {@link PreviewBuildOptions.required}:
|
|
57
|
+
* - `true` (default) → rejects with an error naming the exit code.
|
|
58
|
+
* - `false` → resolves and logs a warning so onboarding setups can continue
|
|
59
|
+
* when the preview build is not yet wired correctly.
|
|
60
|
+
*/
|
|
61
|
+
export declare function spawnPreviewBuild(previewSecret: string, opts: PreviewBuildOptions): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Internal seam that takes the spawn function as a parameter so tests can
|
|
64
|
+
* substitute a fake. Public callers should use {@link spawnPreviewBuild}.
|
|
65
|
+
*
|
|
66
|
+
* Exported with a leading underscore to signal that this is an internal API
|
|
67
|
+
* and not part of the package's public surface; it is not re-exported from
|
|
68
|
+
* `src/index.ts` or `src/node.ts`.
|
|
69
|
+
*/
|
|
70
|
+
export declare function _spawnPreviewBuildWith(spawnFn: PreviewBuildSpawn, previewSecret: string, opts: PreviewBuildOptions): Promise<void>;
|
|
71
|
+
//# sourceMappingURL=preview-build.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview-build.d.ts","sourceRoot":"","sources":["../../src/preview-build.ts"],"names":[],"mappings":"AAGA,OAAO,EAAwC,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAC/F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,OAAO,EAAE,uBAAuB,EAAE,CAAC;AAEnC;;;;;;GAMG;AACH,MAAM,WAAW,wBAAwB;IACvC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,GAAG,OAAO,CAAC;CACrE;AAED,MAAM,MAAM,iBAAiB,GAAG,CAC9B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,OAAO,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,KAClD,wBAAwB,CAAC;AAE9B;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,CAAC,UAAU,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC,UAAU,CAM3G;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,GAAG,GAAE,MAAsB,GAAG,MAAM,CAcnE;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,iBAAiB,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAEvG;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,iBAAiB,EAC1B,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,mBAAmB,GACxB,OAAO,CAAC,IAAI,CAAC,CAwCf"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { PACKAGE_NAME, PREVIEW_BUILD_ENV_FLAG, PREVIEW_SECRET_ENV_FLAG } from './constants.js';
|
|
5
|
+
export { PREVIEW_SECRET_ENV_FLAG };
|
|
6
|
+
/**
|
|
7
|
+
* Pure constructor for the child-process environment passed to the recursive
|
|
8
|
+
* preview build. Extracted so tests can verify the contract (env flag + secret
|
|
9
|
+
* + parent-env inheritance) without spinning up a child process — and so the
|
|
10
|
+
* real-process smoke test can call it the same way the integration does.
|
|
11
|
+
*
|
|
12
|
+
* Inherits the parent environment so PATH, credentials, and any host-specific
|
|
13
|
+
* build vars (CF_PAGES_*, GITHUB_*) reach the child.
|
|
14
|
+
*/
|
|
15
|
+
export function buildPreviewChildEnv(parentEnv, previewSecret) {
|
|
16
|
+
return {
|
|
17
|
+
...parentEnv,
|
|
18
|
+
[PREVIEW_BUILD_ENV_FLAG]: '1',
|
|
19
|
+
[PREVIEW_SECRET_ENV_FLAG]: previewSecret,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Locate the `astro` CLI binary in the site's `node_modules/.bin/`. We
|
|
24
|
+
* resolve relative to the current working directory (where `astro build` is
|
|
25
|
+
* being invoked) rather than to this package's install location, because
|
|
26
|
+
* `@conloca/cloud-astro` lists `astro` only as a peerDependency and would
|
|
27
|
+
* therefore not have it in its own node_modules.
|
|
28
|
+
*
|
|
29
|
+
* Bare `bun x astro build` would be the obvious one-liner, but `bunx`/`bun x`
|
|
30
|
+
* auto-fetch a package when it is missing, which a build must never do — so
|
|
31
|
+
* resolve the installed binary and spawn it directly.
|
|
32
|
+
*/
|
|
33
|
+
export function resolveAstroBin(cwd = process.cwd()) {
|
|
34
|
+
const candidates = [
|
|
35
|
+
join(cwd, 'node_modules', '.bin', 'astro'),
|
|
36
|
+
join(cwd, '..', 'node_modules', '.bin', 'astro'),
|
|
37
|
+
join(cwd, '..', '..', 'node_modules', '.bin', 'astro'),
|
|
38
|
+
];
|
|
39
|
+
const found = candidates.find((p) => existsSync(p));
|
|
40
|
+
if (!found) {
|
|
41
|
+
throw new Error(`${PACKAGE_NAME}: cannot locate the astro binary. Looked in: ${candidates.join(', ')}. ` +
|
|
42
|
+
'Is astro installed as a dependency?');
|
|
43
|
+
}
|
|
44
|
+
return found;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Spawns the recursive preview `astro build` from the primary build's
|
|
48
|
+
* `astro:build:done` hook.
|
|
49
|
+
*
|
|
50
|
+
* The child process inherits the parent environment and additionally receives:
|
|
51
|
+
* - {@link PREVIEW_BUILD_ENV_FLAG} set to `'1'` so the integration's own
|
|
52
|
+
* `astro:build:done` short-circuits inside the child (recursion guard
|
|
53
|
+
* contract).
|
|
54
|
+
* - {@link PREVIEW_SECRET_ENV_FLAG} set to the per-branch secret so the
|
|
55
|
+
* child's `astro:config:setup` can inject the literal secret-scoped
|
|
56
|
+
* preview route (`/conloca_preview_${SECRET}/[...path]`).
|
|
57
|
+
*
|
|
58
|
+
* If this function is itself called from within a recursive build (i.e. the
|
|
59
|
+
* env flag is already set to `'1'`), it returns immediately without spawning,
|
|
60
|
+
* which is the outermost layer of the recursion guard.
|
|
61
|
+
*
|
|
62
|
+
* On a non-zero child exit, behaviour depends on {@link PreviewBuildOptions.required}:
|
|
63
|
+
* - `true` (default) → rejects with an error naming the exit code.
|
|
64
|
+
* - `false` → resolves and logs a warning so onboarding setups can continue
|
|
65
|
+
* when the preview build is not yet wired correctly.
|
|
66
|
+
*/
|
|
67
|
+
export async function spawnPreviewBuild(previewSecret, opts) {
|
|
68
|
+
await _spawnPreviewBuildWith(spawn, previewSecret, opts);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Internal seam that takes the spawn function as a parameter so tests can
|
|
72
|
+
* substitute a fake. Public callers should use {@link spawnPreviewBuild}.
|
|
73
|
+
*
|
|
74
|
+
* Exported with a leading underscore to signal that this is an internal API
|
|
75
|
+
* and not part of the package's public surface; it is not re-exported from
|
|
76
|
+
* `src/index.ts` or `src/node.ts`.
|
|
77
|
+
*/
|
|
78
|
+
export async function _spawnPreviewBuildWith(spawnFn, previewSecret, opts) {
|
|
79
|
+
// Recursion guard: bail out before doing any work if we're already inside
|
|
80
|
+
// a recursive preview build. This matches the short-circuit in the
|
|
81
|
+
// integration's `astro:build:done` hook.
|
|
82
|
+
if (process.env[PREVIEW_BUILD_ENV_FLAG] === '1') {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (!previewSecret) {
|
|
86
|
+
throw new Error(`${PACKAGE_NAME}: preview secret is required to spawn the preview build`);
|
|
87
|
+
}
|
|
88
|
+
const required = opts.required ?? true;
|
|
89
|
+
const astroBin = resolveAstroBin();
|
|
90
|
+
const child = spawnFn(astroBin, ['build'], {
|
|
91
|
+
env: buildPreviewChildEnv(process.env, previewSecret),
|
|
92
|
+
stdio: 'inherit',
|
|
93
|
+
});
|
|
94
|
+
await new Promise((resolve, reject) => {
|
|
95
|
+
child.on('exit', (code) => {
|
|
96
|
+
if (code === 0) {
|
|
97
|
+
resolve();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const reason = code === null ? 'signal' : `exit ${code}`;
|
|
101
|
+
if (required) {
|
|
102
|
+
reject(new Error(`${PACKAGE_NAME}: preview build failed (${reason})`));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
// Soft-fail path — opt-in via `previewBuild.required = false`. Use
|
|
106
|
+
// console.warn rather than the Astro logger because the spawn helper is
|
|
107
|
+
// pure: the integration's `astro:build:done` may evolve to pass a
|
|
108
|
+
// logger down, but until it does, warn keeps the signal
|
|
109
|
+
// visible without leaking a logger dependency into the spawn module.
|
|
110
|
+
console.warn(`${PACKAGE_NAME}: preview build failed (${reason}); previewBuild.required=false, continuing`);
|
|
111
|
+
resolve();
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=preview-build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview-build.js","sourceRoot":"","sources":["../../src/preview-build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAG/F,OAAO,EAAE,uBAAuB,EAAE,CAAC;AAmBnC;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,SAA4B,EAAE,aAAqB;IACtF,OAAO;QACL,GAAG,SAAS;QACZ,CAAC,sBAAsB,CAAC,EAAE,GAAG;QAC7B,CAAC,uBAAuB,CAAC,EAAE,aAAa;KACzC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe,CAAC,GAAG,GAAW,OAAO,CAAC,GAAG,EAAE;IACzD,MAAM,UAAU,GAAG;QACjB,I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,EAAE,CAAC,OAAO,CAAC,EAAE;QACzC,GAAG,EAAE,oBAAoB,CAAC,OAAO,CAAC,GAAG,EAAE,aAAa,CAAC;QACrD,KAAK,EAAE,SAAS;KACjB,CAAC,CAAC;IAEH,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC1C,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAmB,EAAE,EAAE;YACvC,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;gBACf,OAAO,EAAE,CAAC;gBACV,OAAO;YACT,CAAC;YACD,MAAM,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC;YACzD,IAAI,QAAQ,EAAE,CAAC;gBACb,MAAM,CAAC,IAAI,KAAK,CAAC,GAAG,YAAY,2BAA2B,MAAM,GAAG,CAAC,CAAC,CAAC;gBACvE,OAAO;YACT,CAAC;YACD,mEAAmE;YACnE,wEAAwE;YACxE,kEAAkE;YAClE,wDAAwD;YACxD,qEAAqE;YACrE,OAAO,CAAC,IAAI,CAAC,GAAG,YAAY,2BAA2B,MAAM,4CAA4C,CAAC,CAAC;YAC3G,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { getBannerScriptText, injectPreviewBanner } from './preview/banner.js';
|
|
2
|
+
export { embeddedKey, PreviewContentAPI, type PreviewContentAPIOptions, } from './preview/content-api.js';
|
|
3
|
+
export { applyPreviewHeaders } from './preview/headers.js';
|
|
4
|
+
export { renderNoPreviewLanding } from './preview/landing.js';
|
|
5
|
+
export { handlePreviewRequest, type PreviewContext, type PreviewMiddlewareOptions, type PreviewVerdict, previewParamName, } from './preview/middleware.js';
|
|
6
|
+
//# sourceMappingURL=preview.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../src/preview.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,KAAK,wBAAwB,GAC9B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EACL,oBAAoB,EACpB,KAAK,cAAc,EACnB,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EACnB,gBAAgB,GACjB,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Public `./preview` subpath for `@conloca/cloud-astro`.
|
|
2
|
+
//
|
|
3
|
+
// Re-exports the preview-middleware + preview-reader surface that the SSR
|
|
4
|
+
// catch-all handler (and any site-supplied request-runtime wrapper)
|
|
5
|
+
// consumes. Keeping the implementation behind a `./preview/*` directory lets
|
|
6
|
+
// the public subpath stay stable while the internals evolve.
|
|
7
|
+
export { getBannerScriptText, injectPreviewBanner } from './preview/banner.js';
|
|
8
|
+
export { embeddedKey, PreviewContentAPI, } from './preview/content-api.js';
|
|
9
|
+
export { applyPreviewHeaders } from './preview/headers.js';
|
|
10
|
+
export { renderNoPreviewLanding } from './preview/landing.js';
|
|
11
|
+
export { handlePreviewRequest, previewParamName, } from './preview/middleware.js';
|
|
12
|
+
//# sourceMappingURL=preview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview.js","sourceRoot":"","sources":["../../src/preview.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,EAAE;AACF,0EAA0E;AAC1E,oEAAoE;AACpE,6EAA6E;AAC7E,6DAA6D;AAE7D,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EACL,WAAW,EACX,iBAAiB,GAElB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EACL,oBAAoB,EAIpB,gBAAgB,GACjB,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registration request (`POST {endpoint}/api/v1/registrations`). Auth is the
|
|
3
|
+
* build token (`cbt_<id>.<secret>`) the endpoint issued; the body carries build
|
|
4
|
+
* metadata only.
|
|
5
|
+
*/
|
|
6
|
+
export interface RegistrationInput {
|
|
7
|
+
/** Editor endpoint, e.g. 'https://cms.example.com'. */
|
|
8
|
+
endpoint: string;
|
|
9
|
+
/** Build token sent as `Authorization: Bearer <token>`. */
|
|
10
|
+
buildToken: string;
|
|
11
|
+
/** Auto-detected `owner/repo` identity of the build checkout. */
|
|
12
|
+
repoUri: string;
|
|
13
|
+
gitSha: string;
|
|
14
|
+
branch: string;
|
|
15
|
+
/** Deployable-site id (top-level siteId in the content root's
|
|
16
|
+
* sites.json, or the implicit 'default' for a zero-config repo). Resolved at
|
|
17
|
+
* build via resolveBuildSiteId — registration attaches, never defines. */
|
|
18
|
+
siteId: string;
|
|
19
|
+
/** Absolute URL the editor fetches the bundle from. */
|
|
20
|
+
editorBundleUrl: string;
|
|
21
|
+
/** Full sha-256 hex of the bundle bytes; the editor refuses non-matching bytes. */
|
|
22
|
+
bundleHash: string;
|
|
23
|
+
/** Absolute URL of the companion canvas stylesheet; absent when the config graph has no styles. */
|
|
24
|
+
stylesheetUrl?: string;
|
|
25
|
+
/** Full sha-256 hex of the stylesheet bytes; the editor skips non-matching bytes (fail-soft). */
|
|
26
|
+
stylesheetHash?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Discovered content-wrapper shape of the fragmentPreviewRoute — inline
|
|
29
|
+
* because it is well under 1 KB; a URL+hash would add a
|
|
30
|
+
* fetch and a verification for nothing.
|
|
31
|
+
*/
|
|
32
|
+
hostWrappers?: {
|
|
33
|
+
content: {
|
|
34
|
+
tagName: string;
|
|
35
|
+
className: string;
|
|
36
|
+
} | null;
|
|
37
|
+
codeBlock: unknown;
|
|
38
|
+
};
|
|
39
|
+
/** Absolute URL of the discovery route's collected CSS; same artifact pattern as stylesheetUrl. */
|
|
40
|
+
routeCssUrl?: string;
|
|
41
|
+
/** Full sha-256 hex of the route-CSS bytes; the editor skips non-matching bytes (fail-soft). */
|
|
42
|
+
routeCssHash?: string;
|
|
43
|
+
/** Absolute URL of the build's component manifest; same artifact pattern as stylesheetUrl. */
|
|
44
|
+
componentManifestUrl?: string;
|
|
45
|
+
/** Full sha-256 hex of the manifest bytes; a reader refuses non-matching bytes. */
|
|
46
|
+
componentManifestHash?: string;
|
|
47
|
+
deploymentUrl?: string;
|
|
48
|
+
deploymentProvider?: string;
|
|
49
|
+
/**
|
|
50
|
+
* The commit the artifact was actually built from; differs from gitSha only when CI hands over the branch's
|
|
51
|
+
* latest commit.
|
|
52
|
+
*/
|
|
53
|
+
buildId?: string;
|
|
54
|
+
/**
|
|
55
|
+
* The `@conloca/cloud-astro` version that produced this build, so the endpoint and the doctor can say which
|
|
56
|
+
* package version built the editor bundle.
|
|
57
|
+
*/
|
|
58
|
+
clientVersion?: string;
|
|
59
|
+
}
|
|
60
|
+
export interface RegistrationResult {
|
|
61
|
+
/** Per-branch preview secret consumed by the recursive preview build. */
|
|
62
|
+
previewSecret: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The minimal fetch surface this module relies on. A narrow seam (matching
|
|
66
|
+
* `PreviewBuildSpawn` in preview-build.ts) lets tests pass a tiny fake
|
|
67
|
+
* without reconstructing the full `fetch` typing.
|
|
68
|
+
*/
|
|
69
|
+
export type RegistrationFetch = (url: string, init: {
|
|
70
|
+
method: 'POST';
|
|
71
|
+
headers: Record<string, string>;
|
|
72
|
+
body: string;
|
|
73
|
+
}) => Promise<Response>;
|
|
74
|
+
/**
|
|
75
|
+
* Backoff before each retry; length + 1 = total attempts. Starts at 1 s,
|
|
76
|
+
* doubles to a 30 s ceiling and stops before the waits alone exceed the
|
|
77
|
+
* budget: an endpoint that has just been set up can answer 503 for a while,
|
|
78
|
+
* and a budget of about a second gives up long before it settles.
|
|
79
|
+
*/
|
|
80
|
+
export declare function _registrationRetryDelays(): number[];
|
|
81
|
+
/**
|
|
82
|
+
* POSTs the registration to the endpoint and returns the per-branch preview
|
|
83
|
+
* secret. Network errors and 5xx responses are retried with exponential
|
|
84
|
+
* backoff (1 s doubling to 30 s, ten attempts within a three-minute wait
|
|
85
|
+
* budget); 4xx responses throw immediately with the response body so
|
|
86
|
+
* the caller can surface the exact rejection reason (e.g. an invalid token).
|
|
87
|
+
*/
|
|
88
|
+
export declare function postRegistration(input: RegistrationInput): Promise<RegistrationResult>;
|
|
89
|
+
/**
|
|
90
|
+
* Internal seam that takes the fetch function (and retry backoff) as
|
|
91
|
+
* parameters so tests can substitute fakes. Public callers should use
|
|
92
|
+
* {@link postRegistration}.
|
|
93
|
+
*
|
|
94
|
+
* Exported with a leading underscore to signal that this is an internal API
|
|
95
|
+
* and not part of the package's public surface.
|
|
96
|
+
*/
|
|
97
|
+
export declare function _postRegistrationWith(fetchFn: RegistrationFetch, input: RegistrationInput, retryDelaysMs?: readonly number[]): Promise<RegistrationResult>;
|
|
98
|
+
//# sourceMappingURL=register.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/register.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,uDAAuD;IACvD,QAAQ,EAAE,MAAM,CAAC;IACjB,2DAA2D;IAC3D,UAAU,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;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AID;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAE5F;AAED;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,iBAAiB,EAC1B,KAAK,EAAE,iBAAiB,EACxB,aAAa,GAAE,SAAS,MAAM,EAA4B,GACzD,OAAO,CAAC,kBAAkB,CAAC,CA6D7B"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { PACKAGE_NAME } from './constants.js';
|
|
2
|
+
const INITIAL_RETRY_MS = 1_000;
|
|
3
|
+
const MAX_RETRY_MS = 30_000;
|
|
4
|
+
const RETRY_BUDGET_MS = 180_000;
|
|
5
|
+
/**
|
|
6
|
+
* Backoff before each retry; length + 1 = total attempts. Starts at 1 s,
|
|
7
|
+
* doubles to a 30 s ceiling and stops before the waits alone exceed the
|
|
8
|
+
* budget: an endpoint that has just been set up can answer 503 for a while,
|
|
9
|
+
* and a budget of about a second gives up long before it settles.
|
|
10
|
+
*/
|
|
11
|
+
export function _registrationRetryDelays() {
|
|
12
|
+
const delays = [];
|
|
13
|
+
let next = INITIAL_RETRY_MS;
|
|
14
|
+
let total = 0;
|
|
15
|
+
while (total + next <= RETRY_BUDGET_MS) {
|
|
16
|
+
delays.push(next);
|
|
17
|
+
total += next;
|
|
18
|
+
next = Math.min(next * 2, MAX_RETRY_MS);
|
|
19
|
+
}
|
|
20
|
+
return delays;
|
|
21
|
+
}
|
|
22
|
+
const DEFAULT_RETRY_DELAYS_MS = _registrationRetryDelays();
|
|
23
|
+
/**
|
|
24
|
+
* POSTs the registration to the endpoint and returns the per-branch preview
|
|
25
|
+
* secret. Network errors and 5xx responses are retried with exponential
|
|
26
|
+
* backoff (1 s doubling to 30 s, ten attempts within a three-minute wait
|
|
27
|
+
* budget); 4xx responses throw immediately with the response body so
|
|
28
|
+
* the caller can surface the exact rejection reason (e.g. an invalid token).
|
|
29
|
+
*/
|
|
30
|
+
export async function postRegistration(input) {
|
|
31
|
+
return _postRegistrationWith((url, init) => fetch(url, init), input);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Internal seam that takes the fetch function (and retry backoff) as
|
|
35
|
+
* parameters so tests can substitute fakes. Public callers should use
|
|
36
|
+
* {@link postRegistration}.
|
|
37
|
+
*
|
|
38
|
+
* Exported with a leading underscore to signal that this is an internal API
|
|
39
|
+
* and not part of the package's public surface.
|
|
40
|
+
*/
|
|
41
|
+
export async function _postRegistrationWith(fetchFn, input, retryDelaysMs = DEFAULT_RETRY_DELAYS_MS) {
|
|
42
|
+
const url = `${input.endpoint}/api/v1/registrations`;
|
|
43
|
+
const init = {
|
|
44
|
+
method: 'POST',
|
|
45
|
+
headers: {
|
|
46
|
+
'content-type': 'application/json',
|
|
47
|
+
authorization: `Bearer ${input.buildToken}`,
|
|
48
|
+
},
|
|
49
|
+
// JSON.stringify drops undefined optional fields, matching the endpoint's
|
|
50
|
+
// "optional means absent" reading of the body.
|
|
51
|
+
body: JSON.stringify({
|
|
52
|
+
repoUri: input.repoUri,
|
|
53
|
+
gitSha: input.gitSha,
|
|
54
|
+
branch: input.branch,
|
|
55
|
+
siteId: input.siteId,
|
|
56
|
+
editorBundleUrl: input.editorBundleUrl,
|
|
57
|
+
bundleHash: input.bundleHash,
|
|
58
|
+
stylesheetUrl: input.stylesheetUrl,
|
|
59
|
+
stylesheetHash: input.stylesheetHash,
|
|
60
|
+
hostWrappers: input.hostWrappers,
|
|
61
|
+
routeCssUrl: input.routeCssUrl,
|
|
62
|
+
routeCssHash: input.routeCssHash,
|
|
63
|
+
componentManifestUrl: input.componentManifestUrl,
|
|
64
|
+
componentManifestHash: input.componentManifestHash,
|
|
65
|
+
deploymentUrl: input.deploymentUrl,
|
|
66
|
+
deploymentProvider: input.deploymentProvider,
|
|
67
|
+
buildId: input.buildId,
|
|
68
|
+
clientVersion: input.clientVersion,
|
|
69
|
+
}),
|
|
70
|
+
};
|
|
71
|
+
const attempts = retryDelaysMs.length + 1;
|
|
72
|
+
let lastFailure = '';
|
|
73
|
+
for (let attempt = 0; attempt < attempts; attempt++) {
|
|
74
|
+
if (attempt > 0 && retryDelaysMs[attempt - 1] > 0) {
|
|
75
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelaysMs[attempt - 1]));
|
|
76
|
+
}
|
|
77
|
+
let response;
|
|
78
|
+
try {
|
|
79
|
+
response = await fetchFn(url, init);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
// Network-level failure (endpoint unreachable, DNS, reset) — retry.
|
|
83
|
+
lastFailure = error instanceof Error ? error.message : String(error);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (response.ok) {
|
|
87
|
+
const payload = (await response.json().catch(() => null));
|
|
88
|
+
if (typeof payload?.previewSecret !== 'string' || payload.previewSecret === '') {
|
|
89
|
+
throw new Error(`${PACKAGE_NAME}: registration response is missing previewSecret`);
|
|
90
|
+
}
|
|
91
|
+
return { previewSecret: payload.previewSecret };
|
|
92
|
+
}
|
|
93
|
+
const text = await response.text().catch(() => '');
|
|
94
|
+
if (response.status < 500) {
|
|
95
|
+
// 4xx is deterministic (bad token, repo not covered, malformed body) —
|
|
96
|
+
// retrying cannot help, and the body carries the exact reason.
|
|
97
|
+
throw new Error(`${PACKAGE_NAME}: registration rejected: HTTP ${response.status} ${text}`);
|
|
98
|
+
}
|
|
99
|
+
lastFailure = `HTTP ${response.status} ${text}`;
|
|
100
|
+
}
|
|
101
|
+
throw new Error(`${PACKAGE_NAME}: registration failed after ${attempts} attempts: ${lastFailure}`);
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../src/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAuE9C,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAC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AAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACrE,SAAS;QACX,CAAC;QACD,IAAI,QAAQ,CAAC,EAAE,EAAE,CAAC;YAChB,MAAM,OAAO,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAuC,CAAC;YAChG,IAAI,OAAO,OAAO,EAAE,aAAa,KAAK,QAAQ,IAAI,OAAO,CAAC,aAAa,KAAK,EAAE,EAAE,CAAC;gBAC/E,MAAM,IAAI,KAAK,CAAC,GAAG,YAAY,kDAAkD,CAAC,CAAC;YACrF,CAAC;YACD,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC;QAClD,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;QACnD,IAAI,QAAQ,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;YAC1B,uEAAuE;YACvE,+DAA+D;YAC/D,MAAM,IAAI,KAAK,CAAC,GAAG,YAAY,iCAAiC,QAAQ,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC,CAAC;QAC7F,CAAC;QACD,WAAW,GAAG,QAAQ,QAAQ,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;IAClD,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,GAAG,YAAY,+BAA+B,QAAQ,cAAc,WAAW,EAAE,CAAC,CAAC;AACrG,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Minimal environment surface used for zero-config repository detection. */
|
|
2
|
+
export type RepositoryEnvironment = Record<string, string | undefined>;
|
|
3
|
+
export interface DetectRepositoryUriInput {
|
|
4
|
+
/** Advanced escape hatch for non-standard checkouts. Normal builds omit it. */
|
|
5
|
+
explicit?: string;
|
|
6
|
+
env?: RepositoryEnvironment;
|
|
7
|
+
/** `remote.origin.url`, supplied by the integration after a best-effort git read. */
|
|
8
|
+
remote?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Normalize a provider full_name or common Git remote into `owner/repo`.
|
|
12
|
+
* Deliberately rejects local paths and nested groups: a registration names
|
|
13
|
+
* its repository GitHub-style, as two segments.
|
|
14
|
+
*/
|
|
15
|
+
export declare function normalizeRepositoryUri(input: string | undefined): string | undefined;
|
|
16
|
+
/** Resolve repo identity from configuration-free CI metadata, then Git. */
|
|
17
|
+
export declare function detectRepositoryUri(input?: DetectRepositoryUriInput): string | undefined;
|
|
18
|
+
//# sourceMappingURL=repository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../src/repository.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAEvE,MAAM,WAAW,wBAAwB;IACvC,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,qBAAqB,CAAC;IAC5B,qFAAqF;IACrF,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAID;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAqBpF;AAED,2EAA2E;AAC3E,wBAAgB,mBAAmB,CAAC,KAAK,GAAE,wBAA6B,GAAG,MAAM,GAAG,SAAS,CAW5F"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const REPO_SEGMENT = /^[A-Za-z0-9_.-]+$/;
|
|
2
|
+
/**
|
|
3
|
+
* Normalize a provider full_name or common Git remote into `owner/repo`.
|
|
4
|
+
* Deliberately rejects local paths and nested groups: a registration names
|
|
5
|
+
* its repository GitHub-style, as two segments.
|
|
6
|
+
*/
|
|
7
|
+
export function normalizeRepositoryUri(input) {
|
|
8
|
+
if (input === undefined)
|
|
9
|
+
return undefined;
|
|
10
|
+
let value = input.trim();
|
|
11
|
+
if (value === '' || value.startsWith('/'))
|
|
12
|
+
return undefined;
|
|
13
|
+
const scp = /^[^@/]+@[^:/]+:(.+)$/.exec(value);
|
|
14
|
+
if (scp) {
|
|
15
|
+
value = scp[1];
|
|
16
|
+
}
|
|
17
|
+
else if (value.includes('://')) {
|
|
18
|
+
try {
|
|
19
|
+
value = new URL(value).pathname;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
value = value.replace(/^\/+|\/+$/g, '').replace(/\.git$/, '');
|
|
26
|
+
let parts = value.split('/');
|
|
27
|
+
if (parts.length === 3 && parts[0].includes('.'))
|
|
28
|
+
parts = parts.slice(1);
|
|
29
|
+
if (parts.length !== 2 || !parts.every((part) => REPO_SEGMENT.test(part)))
|
|
30
|
+
return undefined;
|
|
31
|
+
return `${parts[0]}/${parts[1]}`;
|
|
32
|
+
}
|
|
33
|
+
/** Resolve repo identity from configuration-free CI metadata, then Git. */
|
|
34
|
+
export function detectRepositoryUri(input = {}) {
|
|
35
|
+
const env = input.env ?? process.env;
|
|
36
|
+
const vercel = env.VERCEL_GIT_REPO_OWNER && env.VERCEL_GIT_REPO_SLUG
|
|
37
|
+
? `${env.VERCEL_GIT_REPO_OWNER}/${env.VERCEL_GIT_REPO_SLUG}`
|
|
38
|
+
: undefined;
|
|
39
|
+
for (const candidate of [input.explicit, env.GITHUB_REPOSITORY, vercel, env.CI_PROJECT_PATH, input.remote]) {
|
|
40
|
+
const normalized = normalizeRepositoryUri(candidate);
|
|
41
|
+
if (normalized !== undefined)
|
|
42
|
+
return normalized;
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.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AO,SAAS,CAAC;IAC5F,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AACnC,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,mBAAmB,CAAC,KAAK,GAA6B,EAAE;IACtE,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IACrC,MAAM,MAAM,GACV,GAAG,CAAC,qBAAqB,IAAI,GAAG,CAAC,oBAAoB;QACnD,CAAC,CAAC,GAAG,GAAG,CAAC,qBAAqB,IAAI,GAAG,CAAC,oBAAoB,EAAE;QAC5D,CAAC,CAAC,SAAS,CAAC;IAChB,KAAK,MAAM,SAAS,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,iBAAiB,EAAE,MAAM,EAAE,GAAG,CAAC,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3G,MAAM,UAAU,GAAG,sBAAsB,CAAC,SAAS,CAAC,CAAC;QACrD,IAAI,UAAU,KAAK,SAAS;YAAE,OAAO,UAAU,CAAC;IAClD,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** The site-id grammar: lowercase alphanumerics and dashes, 1-64 chars, alphanumeric first. */
|
|
2
|
+
export declare const SITE_ID_RE: RegExp;
|
|
3
|
+
/**
|
|
4
|
+
* Resolve the build's deployable-site id. STRICT: malformed input fails the
|
|
5
|
+
* build — a silent mis-attach is the same "deployed, but the editor points at
|
|
6
|
+
* the wrong content" miss, only at a different address. A cleanly-parsed
|
|
7
|
+
* sites.json without a top-level siteId is the zero-config repo: implicit
|
|
8
|
+
* 'default'.
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolveBuildSiteId(opts: {
|
|
11
|
+
/** process.env.CONLOCA_CONTENT_ROOT — the channel conlocaCMS already publishes. */
|
|
12
|
+
contentRoot: string | undefined;
|
|
13
|
+
/** options.siteId — advanced override for CMS-less builds. */
|
|
14
|
+
override: string | undefined;
|
|
15
|
+
/** Seam for tests; defaults to a utf8 readFileSync. */
|
|
16
|
+
readFile?: (path: string) => string;
|
|
17
|
+
}): string;
|
|
18
|
+
//# sourceMappingURL=site-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site-id.d.ts","sourceRoot":"","sources":["../../src/site-id.ts"],"names":[],"mappings":"AAIA,+FAA+F;AAC/F,eAAO,MAAM,UAAU,QAA8B,CAAC;AAEtD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IACvC,mFAAmF;IACnF,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,8DAA8D;IAC9D,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,uDAAuD;IACvD,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACrC,GAAG,MAAM,CA0DT"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { PACKAGE_NAME } from './constants.js';
|
|
4
|
+
/** The site-id grammar: lowercase alphanumerics and dashes, 1-64 chars, alphanumeric first. */
|
|
5
|
+
export const SITE_ID_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
6
|
+
/**
|
|
7
|
+
* Resolve the build's deployable-site id. STRICT: malformed input fails the
|
|
8
|
+
* build — a silent mis-attach is the same "deployed, but the editor points at
|
|
9
|
+
* the wrong content" miss, only at a different address. A cleanly-parsed
|
|
10
|
+
* sites.json without a top-level siteId is the zero-config repo: implicit
|
|
11
|
+
* 'default'.
|
|
12
|
+
*/
|
|
13
|
+
export function resolveBuildSiteId(opts) {
|
|
14
|
+
const read = opts.readFile ?? ((p) => readFileSync(p, 'utf8'));
|
|
15
|
+
if (opts.contentRoot === undefined || opts.contentRoot === '') {
|
|
16
|
+
// CMS channel absent — the override stands alone (a CMS-less build).
|
|
17
|
+
if (opts.override === undefined) {
|
|
18
|
+
throw new Error(`${PACKAGE_NAME}: cannot determine siteId — CONLOCA_CONTENT_ROOT is not set ` +
|
|
19
|
+
'(is conlocaCMS installed?) and no siteId override is configured');
|
|
20
|
+
}
|
|
21
|
+
assertSlug(opts.override, 'siteId override');
|
|
22
|
+
return opts.override;
|
|
23
|
+
}
|
|
24
|
+
const path = join(opts.contentRoot, 'sites.json');
|
|
25
|
+
let raw;
|
|
26
|
+
try {
|
|
27
|
+
raw = read(path);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
throw new Error(`${PACKAGE_NAME}: missing ${path} — the CMS content root must carry its sites.json`);
|
|
31
|
+
}
|
|
32
|
+
let parsed;
|
|
33
|
+
try {
|
|
34
|
+
parsed = JSON.parse(raw);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
throw new Error(`${PACKAGE_NAME}: could not parse ${path} as JSON`);
|
|
38
|
+
}
|
|
39
|
+
const record = parsed;
|
|
40
|
+
if (record === null ||
|
|
41
|
+
typeof record !== 'object' ||
|
|
42
|
+
record.sites === null ||
|
|
43
|
+
typeof record.sites !== 'object' ||
|
|
44
|
+
Array.isArray(record.sites)) {
|
|
45
|
+
throw new Error(`${PACKAGE_NAME}: ${path} has no "sites" object — refusing to register a broken content model`);
|
|
46
|
+
}
|
|
47
|
+
let resolved;
|
|
48
|
+
if ('siteId' in record) {
|
|
49
|
+
if (typeof record.siteId !== 'string' || !SITE_ID_RE.test(record.siteId)) {
|
|
50
|
+
throw new Error(`${PACKAGE_NAME}: invalid top-level siteId in ${path} (want ${SITE_ID_RE})`);
|
|
51
|
+
}
|
|
52
|
+
resolved = record.siteId;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
resolved = 'default'; // zero-config repo — soft path, never a build failure
|
|
56
|
+
}
|
|
57
|
+
// The env channel is authoritative: an override that DIFFERS from either the
|
|
58
|
+
// explicit id or the implicit default fails the build, never picks silently.
|
|
59
|
+
if (opts.override !== undefined && opts.override !== resolved) {
|
|
60
|
+
throw new Error(`${PACKAGE_NAME}: siteId override "${opts.override}" contradicts ${path} (resolved "${resolved}") — ` +
|
|
61
|
+
'remove the override or fix sites.json');
|
|
62
|
+
}
|
|
63
|
+
return resolved;
|
|
64
|
+
}
|
|
65
|
+
function assertSlug(value, label) {
|
|
66
|
+
if (!SITE_ID_RE.test(value)) {
|
|
67
|
+
throw new Error(`${PACKAGE_NAME}: ${label} "${value}" is not a valid site slug (${SITE_ID_RE})`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=site-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site-id.js","sourceRoot":"","sources":["../../src/site-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,+FAA+F;AAC/F,MAAM,CAAC,MAAM,UAAU,GAAG,2BAA2B,CAAC;AAEtD;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAOlC;IACC,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IAEvE,IAAI,IAAI,CAAC,WAAW,KAAK,SAAS,IAAI,IAAI,CAAC,WAAW,KAAK,EAAE,EAAE,CAAC;QAC9D,qEAAqE;QACrE,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CACb,GAAG,YAAY,8DAA8D;gBAC3E,iEAAiE,CACpE,CAAC;QACJ,CAAC;QACD,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,i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B,CAAC;SAAM,CAAC;QACN,QAAQ,GAAG,SAAS,CAAC,CAAC,sDAAsD;IAC9E,CAAC;IAED,6EAA6E;IAC7E,6EAA6E;IAC7E,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,IAAI,IAAI,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC9D,MAAM,IAAI,KAAK,CACb,GAAG,YAAY,sBAAsB,IAAI,CAAC,QAAQ,iBAAiB,IAAI,eAAe,QAAQ,OAAO;YACnG,uCAAuC,CAC1C,CAAC;IACJ,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,UAAU,CAAC,KAAa,EAAE,KAAa;IAC9C,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,GAAG,YAAY,KAAK,KAAK,KAAK,KAAK,+BAA+B,UAAU,GAAG,CAAC,CAAC;IACnG,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Astro middleware entrypoint for the recursive preview build.
|
|
3
|
+
*
|
|
4
|
+
* `addMiddleware({ entrypoint: '@conloca/cloud-astro/site-middleware' })` in
|
|
5
|
+
* the integration resolves to this module, so it must export `onRequest` —
|
|
6
|
+
* Astro's middleware contract. The verdict/render logic lives in
|
|
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.
|
|
12
|
+
*
|
|
13
|
+
* Mounted ONLY inside the preview build (see `integration.ts`), never in the
|
|
14
|
+
* site's production build.
|
|
15
|
+
*/
|
|
16
|
+
import { type PreviewMiddlewareContext, type PreviewMiddlewareNext } from './preview/site-middleware.js';
|
|
17
|
+
export declare function onRequest(context: PreviewMiddlewareContext, next: PreviewMiddlewareNext): Promise<Response>;
|
|
18
|
+
//# sourceMappingURL=site-middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site-middleware.d.ts","sourceRoot":"","sources":["../../src/site-middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAQH,OAAO,EAEL,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,EAC3B,MAAM,8BAA8B,CAAC;AAoBtC,wBAAsB,SAAS,CAAC,OAAO,EAAE,wBAAwB,EAAE,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAQjH"}
|