@conloca/cloud-astro 0.0.0-bootstrap.0 → 0.2.1
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 +327 -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 +173 -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 +532 -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 +52 -0
- package/dist/src/preview/_dispatch.d.ts.map +1 -0
- package/dist/src/preview/_dispatch.js +70 -0
- package/dist/src/preview/_dispatch.js.map +1 -0
- package/dist/src/preview/_resolve-opts.d.ts +28 -0
- package/dist/src/preview/_resolve-opts.d.ts.map +1 -0
- package/dist/src/preview/_resolve-opts.js +70 -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 +112 -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 +159 -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 +125 -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 +170 -5
- package/src/build-commit.ts +22 -0
- package/src/bundle.ts +563 -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 +595 -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 +101 -0
- package/src/preview/_resolve-opts.ts +84 -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 +303 -0
- package/src/preview/preview-path.ts +28 -0
- package/src/preview/satteri-workerd.ts +24 -0
- package/src/preview/site-middleware.ts +209 -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 +127 -0
- package/src/virtual-modules.d.ts +51 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { LocalizedEntry } from '@conloca/content-api';
|
|
2
|
+
import type { PreviewContext } from './middleware.js';
|
|
3
|
+
/**
|
|
4
|
+
* Four-verdict response of the endpoint's page-status route.
|
|
5
|
+
*
|
|
6
|
+
* - `unchanged` — page render graph is byte-equivalent to the production
|
|
7
|
+
* build; serve the ordinary page.
|
|
8
|
+
* - `changed` — page or one of its dependencies has been edited in the
|
|
9
|
+
* branch; carry the (possibly empty) embedded payload map into the
|
|
10
|
+
* preview reader so dependency reads short-circuit when the endpoint
|
|
11
|
+
* bundled them inline.
|
|
12
|
+
* - `deleted` — branch removed the page; the site's own not-found flow
|
|
13
|
+
* answers.
|
|
14
|
+
* - `redirect` — branch installed a redirect at the page's path; callers
|
|
15
|
+
* issue a 302 (we deliberately downgrade 301 to 302 — see fetchPageStatus).
|
|
16
|
+
*
|
|
17
|
+
* The verdict-to-response mapping lives in the site middleware
|
|
18
|
+
* (`./site-middleware.ts`), which renders through the site's own route.
|
|
19
|
+
*/
|
|
20
|
+
export type PageStatus = {
|
|
21
|
+
kind: 'unchanged';
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'changed';
|
|
24
|
+
embedded: ReadonlyMap<string, LocalizedEntry>;
|
|
25
|
+
} | {
|
|
26
|
+
kind: 'deleted';
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'redirect';
|
|
29
|
+
target: string;
|
|
30
|
+
};
|
|
31
|
+
interface FetchPageStatusInput {
|
|
32
|
+
saasEndpoint: string;
|
|
33
|
+
ctx: PreviewContext;
|
|
34
|
+
path: string;
|
|
35
|
+
/** Site/locale the render resolves against. Unset ⇒ the endpoint's defaults
|
|
36
|
+
* (`default`/`en`) — fine for single-site, wrong for anything else, and the
|
|
37
|
+
* embedded map is locale-keyed so a mismatch silently never hits. */
|
|
38
|
+
site?: string;
|
|
39
|
+
locale?: string;
|
|
40
|
+
fetchFn?: typeof fetch;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Calls `GET {endpoint}/preview/page-status/{path}` with the preview JWT and
|
|
44
|
+
* decodes the four-verdict response into a {@link PageStatus} value.
|
|
45
|
+
*
|
|
46
|
+
* 301 responses are deliberately surfaced as `{ kind: 'redirect' }` with
|
|
47
|
+
* the same target as 302 — the downstream caller always emits 302 so
|
|
48
|
+
* a stale preview redirect cannot be cached by intermediaries.
|
|
49
|
+
*/
|
|
50
|
+
export declare function fetchPageStatus(input: FetchPageStatusInput): Promise<PageStatus>;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=_dispatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dispatch.d.ts","sourceRoot":"","sources":["../../../src/preview/_dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,GACrB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;CAAE,GAClE;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzC,UAAU,oBAAoB;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,cAAc,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb;;0EAEsE;IACtE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,wBAAsB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,UAAU,CAAC,CAwBtF"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calls `GET {endpoint}/preview/page-status/{path}` with the preview JWT and
|
|
3
|
+
* decodes the four-verdict response into a {@link PageStatus} value.
|
|
4
|
+
*
|
|
5
|
+
* 301 responses are deliberately surfaced as `{ kind: 'redirect' }` with
|
|
6
|
+
* the same target as 302 — the downstream caller always emits 302 so
|
|
7
|
+
* a stale preview redirect cannot be cached by intermediaries.
|
|
8
|
+
*/
|
|
9
|
+
export async function fetchPageStatus(input) {
|
|
10
|
+
const fetchImpl = input.fetchFn ?? fetch;
|
|
11
|
+
const normalisedPath = input.path.replace(/^\/+/u, '');
|
|
12
|
+
const query = new URLSearchParams();
|
|
13
|
+
if (input.locale !== undefined)
|
|
14
|
+
query.set('locale', input.locale);
|
|
15
|
+
if (input.site !== undefined)
|
|
16
|
+
query.set('site', input.site);
|
|
17
|
+
const suffix = query.size > 0 ? `?${query.toString()}` : '';
|
|
18
|
+
const url = `${input.saasEndpoint}/preview/page-status/${normalisedPath}${suffix}`;
|
|
19
|
+
const response = await fetchImpl(url, {
|
|
20
|
+
headers: { authorization: `Bearer ${input.ctx.jwt}` },
|
|
21
|
+
redirect: 'manual',
|
|
22
|
+
});
|
|
23
|
+
if (response.status === 304)
|
|
24
|
+
return { kind: 'unchanged' };
|
|
25
|
+
if (response.status === 404)
|
|
26
|
+
return { kind: 'deleted' };
|
|
27
|
+
if (response.status === 301 || response.status === 302) {
|
|
28
|
+
const target = response.headers.get('location') ?? '/';
|
|
29
|
+
return { kind: 'redirect', target };
|
|
30
|
+
}
|
|
31
|
+
if (response.status === 200) {
|
|
32
|
+
const data = await response.json();
|
|
33
|
+
return { kind: 'changed', embedded: decodeEmbedded(data) };
|
|
34
|
+
}
|
|
35
|
+
throw new Error(`preview page-status ${input.path}: ${response.status}`);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Decodes the optional `{ embedded: { "${id} ${locale}": LocalizedEntry } }`
|
|
39
|
+
* payload from a 200 page-status response into the strongly-typed map
|
|
40
|
+
* the {@link import('./content-api.js').PreviewContentAPI} consumes. Unknown
|
|
41
|
+
* fields are ignored; malformed entries are dropped silently rather than
|
|
42
|
+
* throwing — a bad embedded payload should degrade to a network fetch, not
|
|
43
|
+
* 500 the page.
|
|
44
|
+
*/
|
|
45
|
+
function decodeEmbedded(data) {
|
|
46
|
+
if (typeof data !== 'object' || data === null)
|
|
47
|
+
return new Map();
|
|
48
|
+
const embedded = data.embedded;
|
|
49
|
+
if (typeof embedded !== 'object' || embedded === null)
|
|
50
|
+
return new Map();
|
|
51
|
+
const map = new Map();
|
|
52
|
+
for (const [key, value] of Object.entries(embedded)) {
|
|
53
|
+
if (isLocalizedEntry(value)) {
|
|
54
|
+
map.set(key, value);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return map;
|
|
58
|
+
}
|
|
59
|
+
function isLocalizedEntry(value) {
|
|
60
|
+
if (typeof value !== 'object' || value === null)
|
|
61
|
+
return false;
|
|
62
|
+
const v = value;
|
|
63
|
+
if (typeof v.id !== 'string')
|
|
64
|
+
return false;
|
|
65
|
+
if (typeof v.localized !== 'object' || v.localized === null)
|
|
66
|
+
return false;
|
|
67
|
+
const l = v.localized;
|
|
68
|
+
return typeof l.etag === 'string' && typeof l.locale === 'string' && typeof l.content === 'object';
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=_dispatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dispatch.js","sourceRoot":"","sources":["../../../src/preview/_dispatch.ts"],"names":[],"mappings":"AAsCA;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,KAA2B;IAC/D,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC;IACzC,MAAM,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACvD,MAAM,KAAK,GAAG,IAAI,eAAe,EAAE,CAAC;IACpC,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS;QAAE,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAClE,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;QAAE,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5D,MAAM,GAAG,GAAG,GAAG,KAAK,CAAC,YAAY,wBAAwB,cAAc,GAAG,MAAM,EAAE,CAAC;IACnF,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,GAAG,EAAE;QACpC,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE;QACrD,QAAQ,EAAE,QAAQ;KACnB,CAAC,CAAC;IAEH,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;QAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;IAC1D,IAAI,QAAQ,CAAC,MAAM,KA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AC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc;IACtC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC9D,MAAM,CAAC,GAAG,KAA8C,CAAC;IACzD,IAAI,OAAO,CAAC,CAAC,EAAE,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC3C,IAAI,OAAO,CAAC,CAAC,SAAS,KAAK,QAAQ,IAAI,CAAC,CAAC,SAAS,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC1E,MAAM,CAAC,GAAG,CAAC,CAAC,SAAoE,CAAC;IACjF,OAAO,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,MAAM,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ,CAAC;AACrG,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { PreviewMiddlewareOptions } from './middleware.js';
|
|
2
|
+
/** Values the preview build can bake into the artifact at build time. */
|
|
3
|
+
export interface BakedPreviewOpts {
|
|
4
|
+
secret?: string;
|
|
5
|
+
saasEndpoint?: string;
|
|
6
|
+
saasIssuer?: string;
|
|
7
|
+
saasAudience?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Resolve the middleware options, preferring values baked in at build time and
|
|
11
|
+
* falling back to the runtime environment.
|
|
12
|
+
*
|
|
13
|
+
* Baking is what removes the deployer's setup burden: every value is already
|
|
14
|
+
* known while the preview build runs — the secret arrived with registration,
|
|
15
|
+
* the endpoint and audience are integration options — so a correctly built
|
|
16
|
+
* preview artifact needs NO env vars on the deployment. It also removes a
|
|
17
|
+
* chicken-and-egg loop: the secret is generated during the build but the
|
|
18
|
+
* deployment that would carry it happens afterwards.
|
|
19
|
+
*
|
|
20
|
+
* The environment still wins when set, so one artifact can be promoted across
|
|
21
|
+
* environments without a rebuild.
|
|
22
|
+
*
|
|
23
|
+
* Throws naming the missing variable — a misconfigured preview runtime must
|
|
24
|
+
* not silently accept requests.
|
|
25
|
+
*/
|
|
26
|
+
export declare function resolveFromBaked(baked: BakedPreviewOpts, readEnvVar: (name: string) => string | undefined): PreviewMiddlewareOptions;
|
|
27
|
+
export declare function resolveEndpointFetch(): Promise<typeof fetch | undefined>;
|
|
28
|
+
//# sourceMappingURL=_resolve-opts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_resolve-opts.d.ts","sourceRoot":"","sources":["../../../src/preview/_resolve-opts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAEhE,yEAAyE;AACzE,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,gBAAgB,EACvB,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,GAC/C,wBAAwB,CAiB1B;AAeD,wBAAgB,oBAAoB,IAAI,OAAO,CAAC,OAAO,KAAK,GAAG,SAAS,CAAC,CAqBxE"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve the middleware options, preferring values baked in at build time and
|
|
3
|
+
* falling back to the runtime environment.
|
|
4
|
+
*
|
|
5
|
+
* Baking is what removes the deployer's setup burden: every value is already
|
|
6
|
+
* known while the preview build runs — the secret arrived with registration,
|
|
7
|
+
* the endpoint and audience are integration options — so a correctly built
|
|
8
|
+
* preview artifact needs NO env vars on the deployment. It also removes a
|
|
9
|
+
* chicken-and-egg loop: the secret is generated during the build but the
|
|
10
|
+
* deployment that would carry it happens afterwards.
|
|
11
|
+
*
|
|
12
|
+
* The environment still wins when set, so one artifact can be promoted across
|
|
13
|
+
* environments without a rebuild.
|
|
14
|
+
*
|
|
15
|
+
* Throws naming the missing variable — a misconfigured preview runtime must
|
|
16
|
+
* not silently accept requests.
|
|
17
|
+
*/
|
|
18
|
+
export function resolveFromBaked(baked, readEnvVar) {
|
|
19
|
+
const pick = (envName, bakedValue) => {
|
|
20
|
+
const fromEnv = readEnvVar(envName);
|
|
21
|
+
if (fromEnv)
|
|
22
|
+
return fromEnv;
|
|
23
|
+
if (bakedValue)
|
|
24
|
+
return bakedValue;
|
|
25
|
+
throw new Error(`${'@conloca/cloud-astro'}: preview SSR handler is missing required configuration ${envName}. ` +
|
|
26
|
+
'The preview build normally bakes this in from the conlocaCloud() options; ' +
|
|
27
|
+
`set ${envName} on the deployment to override.`);
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
secret: pick('CONLOCA_PREVIEW_SECRET', baked.secret),
|
|
31
|
+
saasEndpoint: pick('CONLOCA_SAAS_ENDPOINT', baked.saasEndpoint),
|
|
32
|
+
saasIssuer: pick('CONLOCA_SAAS_ISSUER', baked.saasIssuer),
|
|
33
|
+
saasAudience: pick('CONLOCA_SAAS_AUDIENCE', baked.saasAudience),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Endpoint transport: prefer a `CONLOCA_SAAS` binding when the Cloudflare
|
|
38
|
+
* Workers runtime exposes one, else `undefined` so callers fall back to
|
|
39
|
+
* the global fetch. Bind it when a plain fetch from the preview deployment
|
|
40
|
+
* cannot reach the endpoint by its hostname; JWKS discovery and every preview
|
|
41
|
+
* read then go through the binding.
|
|
42
|
+
*
|
|
43
|
+
* Bindings come from Cloudflare's runtime module (Astro v6 removed
|
|
44
|
+
* `locals.runtime.env`); the import is dynamic and swallowed on Node, where
|
|
45
|
+
* the module does not exist and the global fetch is correct. Memoized so
|
|
46
|
+
* jose's JWKS cache keys off a stable function identity.
|
|
47
|
+
*/
|
|
48
|
+
let endpointFetchPromise;
|
|
49
|
+
export function resolveEndpointFetch() {
|
|
50
|
+
endpointFetchPromise ??= (async () => {
|
|
51
|
+
try {
|
|
52
|
+
const mod = (await import(/* @vite-ignore */ 'cloudflare:workers'));
|
|
53
|
+
const binding = mod.env?.CONLOCA_SAAS;
|
|
54
|
+
if (typeof binding === 'object' &&
|
|
55
|
+
binding !== null &&
|
|
56
|
+
typeof binding.fetch === 'function') {
|
|
57
|
+
const fetcher = binding;
|
|
58
|
+
// Cast: an arrow satisfies fetch's call signature but not the static
|
|
59
|
+
// properties Bun's typings hang off `typeof fetch` (preconnect).
|
|
60
|
+
return ((input, init) => fetcher.fetch(input, init));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// Not running on Cloudflare Workers — the global fetch is the transport.
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
})();
|
|
68
|
+
return endpointFetchPromise;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=_resolve-opts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_resolve-opts.js","sourceRoot":"","sources":["../../../src/preview/_resolve-opts.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAuB,EACvB,UAAgD;IAEhD,MAAM,IAAI,GAAG,CAAC,OAAe,EAAE,UAA8B,EAAU,EAAE;QACvE,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;QACpC,IAAI,OAAO;YAAE,OAAO,OAAO,CAAC;QAC5B,IAAI,UAAU;YAAE,OAAO,UAAU,CAAC;QAClC,MAAM,IAAI,KAAK,CACb,GAAG,sBAAsB,2DAA2D,OAAO,IAAI;YAC7F,4EAA4E;YAC5E,OAAO,OAAO,iCAAiC,CAClD,CAAC;IACJ,CAAC,CAAC;IACF,OAAO;QACL,MAAM,EAAE,IAAI,CAAC,wBAAwB,EAAE,KAAK,CAAC,MAAM,CAAC;QACpD,YAAY,EAAE,IAAI,CAAC,uBAAuB,EAAE,KAAK,CAAC,YAAY,CAAC;QAC/D,UAAU,EAAE,IAAI,CAAC,qBAAqB,EAAE,KAAK,CAAC,UAAU,CAAC;QACzD,YAAY,EAAE,IAAI,CAAC,uBAAuB,EAAE,KAAK,CAAC,YAAY,CAAC;KAChE,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,IAAI,oBAAmE,CAAC;AACxE,MAAM,UAAU,oBAAoB;IAClC,oBAAoB,KAAK,CAAC,KAAK,IAAI,EAAE;QACnC,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,CAAC,MAAM,MAAM,CAAC,kBAAkB,CAAC,oBAAoB,CAAC,CAAsC,CAAC;YACzG,MAAM,OAAO,GAAG,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC;YACtC,IACE,OAAO,OAAO,KAAK,QAAQ;gBAC3B,OAAO,KAAK,IAAI;gBAChB,OAAQ,OAA+B,CAAC,KAAK,KAAK,UAAU,EAC5D,CAAC;gBACD,MAAM,OAAO,GAAG,OAAkC,CAAC;gBACnD,qEAAqE;gBACrE,iEAAiE;gBACjE,OAAO,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAiB,CAAC;YACvE,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,yEAAyE;QAC3E,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,EAAE,CAAC;IACL,OAAO,oBAAoB,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { PreviewContext } from './middleware.js';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the body of the script tag that renders the floating preview
|
|
4
|
+
* banner inside the rendered page. Exported separately so the script
|
|
5
|
+
* source can be unit-tested without parsing surrounding HTML.
|
|
6
|
+
*
|
|
7
|
+
* The script is intentionally framework-free vanilla JS: it has to run
|
|
8
|
+
* inside whatever HTML the site's Astro renderer produced, with no
|
|
9
|
+
* assumption about React/preact/svelte runtime presence. The collapse-state
|
|
10
|
+
* persistence uses localStorage with a fixed key so opening multiple
|
|
11
|
+
* previews on the same origin gives a consistent UX.
|
|
12
|
+
*
|
|
13
|
+
* The preview context is embedded as a JSON literal — `JSON.stringify`
|
|
14
|
+
* encodes both `"` and `</script>` sequences safely, which is the
|
|
15
|
+
* canonical way to embed server data in a same-origin inline script.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getBannerScriptText(ctx: PreviewContext, endpoint?: string, exitPath?: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Returns `html` with the preview banner script and `<meta robots noindex>`
|
|
20
|
+
* tag injected before the closing `</body>` tag.
|
|
21
|
+
*
|
|
22
|
+
* The injection uses `String.prototype.replace` with a string argument
|
|
23
|
+
* (not a regex), so only the FIRST `</body>` match is rewritten. That
|
|
24
|
+
* matters because a misconfigured renderer can emit malformed HTML with
|
|
25
|
+
* multiple `</body>` tags; we never want to inject the banner more than
|
|
26
|
+
* once per response.
|
|
27
|
+
*/
|
|
28
|
+
export declare function injectPreviewBanner(html: string, ctx: PreviewContext, endpoint?: string, exitPath?: string): string;
|
|
29
|
+
//# sourceMappingURL=banner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"banner.d.ts","sourceRoot":"","sources":["../../../src/preview/banner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,cAAc,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CA8DrG;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,cAAc,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAInH"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the body of the script tag that renders the floating preview
|
|
3
|
+
* banner inside the rendered page. Exported separately so the script
|
|
4
|
+
* source can be unit-tested without parsing surrounding HTML.
|
|
5
|
+
*
|
|
6
|
+
* The script is intentionally framework-free vanilla JS: it has to run
|
|
7
|
+
* inside whatever HTML the site's Astro renderer produced, with no
|
|
8
|
+
* assumption about React/preact/svelte runtime presence. The collapse-state
|
|
9
|
+
* persistence uses localStorage with a fixed key so opening multiple
|
|
10
|
+
* previews on the same origin gives a consistent UX.
|
|
11
|
+
*
|
|
12
|
+
* The preview context is embedded as a JSON literal — `JSON.stringify`
|
|
13
|
+
* encodes both `"` and `</script>` sequences safely, which is the
|
|
14
|
+
* canonical way to embed server data in a same-origin inline script.
|
|
15
|
+
*/
|
|
16
|
+
export function getBannerScriptText(ctx, endpoint, exitPath) {
|
|
17
|
+
// Serialize then patch the `<` character that JSON.stringify does NOT
|
|
18
|
+
// escape. Browsers terminate inline scripts on `</script>` regardless of
|
|
19
|
+
// string-literal context, so a branch name containing `</script>` would
|
|
20
|
+
// break out of the script tag. Replacing `</` with `<\/` is the standard
|
|
21
|
+
// mitigation (also done by ASP.NET's Json.Encode, Rails' j helper, etc.).
|
|
22
|
+
//
|
|
23
|
+
// The endpoint rides the envelope alongside the preview ctx so the
|
|
24
|
+
// "Share Preview" button can call `GET {endpoint}/preview/share` from the
|
|
25
|
+
// browser with the preview JWT (the same credential the cookie carries; the
|
|
26
|
+
// cookie is HttpOnly, so the button reads the JWT from here). Absent an
|
|
27
|
+
// endpoint the button is inert. `endpoint: undefined` drops out of the JSON.
|
|
28
|
+
//
|
|
29
|
+
// `exitPath` is the server-side exit route (secret-prefixed). Embedding it
|
|
30
|
+
// here does not widen the secret's exposure: this script is served only to
|
|
31
|
+
// credentialed preview visitors, who already hold the secret — it is in the
|
|
32
|
+
// entry/share URL they arrived through — and the response is no-store.
|
|
33
|
+
const ctxJson = JSON.stringify({ ...ctx, endpoint, exitPath }).replace(/</g, '\\u003c');
|
|
34
|
+
return [
|
|
35
|
+
`var __conlocaPreview = ${ctxJson};`,
|
|
36
|
+
"var __conlocaCollapseKey = 'conloca.preview.collapsed';",
|
|
37
|
+
"var __conlocaIsCollapsed = function () { try { return localStorage.getItem(__conlocaCollapseKey) === '1'; } catch (e) { return false; } };",
|
|
38
|
+
"var __conlocaSetCollapsed = function (v) { try { localStorage.setItem(__conlocaCollapseKey, v ? '1' : '0'); } catch (e) {} };",
|
|
39
|
+
'var __conlocaRender = function () {',
|
|
40
|
+
" var host = document.createElement('div');",
|
|
41
|
+
" host.id = 'conloca-preview-banner';",
|
|
42
|
+
" host.style.cssText = 'position:fixed;bottom:16px;right:16px;z-index:2147483647;font-family:system-ui,sans-serif;background:#111;color:#fff;border-radius:8px;box-shadow:0 4px 12px rgba(0,0,0,0.35);padding:8px 12px;font-size:13px;display:flex;gap:12px;align-items:center;';",
|
|
43
|
+
" var label = document.createElement('span'); label.textContent = 'Preview: ' + __conlocaPreview.branch; host.appendChild(label);",
|
|
44
|
+
// "Edit" reuses the landing page's `/login?return=` contract:
|
|
45
|
+
// the endpoint's login route already knows how to send an authenticated
|
|
46
|
+
// session into the editor for the requested page.
|
|
47
|
+
" var edit = document.createElement('a'); edit.textContent = 'Edit'; edit.style.color = '#9cf';",
|
|
48
|
+
" if (__conlocaPreview.endpoint) { edit.href = __conlocaPreview.endpoint + '/login?return=' + encodeURIComponent(location.pathname); host.appendChild(edit); }",
|
|
49
|
+
// "Exit Preview" must round-trip the server: the cookie is HttpOnly, so
|
|
50
|
+
// only a Set-Cookie response can expire it. `to` returns the visitor to
|
|
51
|
+
// this page, now published.
|
|
52
|
+
" var exitLink = document.createElement('a'); exitLink.textContent = 'Exit Preview'; exitLink.style.color = '#9cf';",
|
|
53
|
+
" if (__conlocaPreview.exitPath) { exitLink.href = __conlocaPreview.exitPath + '?to=' + encodeURIComponent(location.pathname); host.appendChild(exitLink); }",
|
|
54
|
+
" var share = document.createElement('button'); share.type = 'button'; share.textContent = 'Share Preview'; share.style.cssText = 'background:#333;color:#fff;border:1px solid #555;border-radius:4px;padding:2px 8px;cursor:pointer;'; host.appendChild(share);",
|
|
55
|
+
// "Share Preview": mint a fresh shareable link via GET {endpoint}/preview/share
|
|
56
|
+
// and copy it to the clipboard. Bearer-authenticated with the preview JWT
|
|
57
|
+
// (the route reads Authorization/?token=, never the HttpOnly cookie). The
|
|
58
|
+
// button briefly reflects the outcome, then restores.
|
|
59
|
+
" share.addEventListener('click', function () {",
|
|
60
|
+
' if (!__conlocaPreview.endpoint) return;',
|
|
61
|
+
" var shareUrl = __conlocaPreview.endpoint + '/preview/share?branch=' + encodeURIComponent(__conlocaPreview.branch);",
|
|
62
|
+
' var previousLabel = share.textContent;',
|
|
63
|
+
' share.disabled = true;',
|
|
64
|
+
" fetch(shareUrl, { headers: { authorization: 'Bearer ' + __conlocaPreview.jwt } })",
|
|
65
|
+
" .then(function (res) { if (!res.ok) throw new Error('share ' + res.status); return res.json(); })",
|
|
66
|
+
" .then(function (data) { if (!data || typeof data.url !== 'string') throw new Error('missing url'); return navigator.clipboard.writeText(data.url); })",
|
|
67
|
+
" .then(function () { share.textContent = 'Link copied'; })",
|
|
68
|
+
" .catch(function () { share.textContent = 'Copy failed'; })",
|
|
69
|
+
' .then(function () { setTimeout(function () { share.textContent = previousLabel; share.disabled = false; }, 2000); });',
|
|
70
|
+
' });',
|
|
71
|
+
" var collapse = document.createElement('button'); collapse.type = 'button'; collapse.textContent = __conlocaIsCollapsed() ? '+' : '-'; collapse.style.cssText = 'background:transparent;color:#fff;border:none;cursor:pointer;font-size:16px;line-height:1;'; host.appendChild(collapse);",
|
|
72
|
+
" collapse.addEventListener('click', function () { var c = !__conlocaIsCollapsed(); __conlocaSetCollapsed(c); host.style.display = c ? 'none' : ''; });",
|
|
73
|
+
" if (__conlocaIsCollapsed()) host.style.display = 'none';",
|
|
74
|
+
' document.body.appendChild(host);',
|
|
75
|
+
'};',
|
|
76
|
+
"if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', __conlocaRender); } else { __conlocaRender(); }",
|
|
77
|
+
].join(' ');
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Returns `html` with the preview banner script and `<meta robots noindex>`
|
|
81
|
+
* tag injected before the closing `</body>` tag.
|
|
82
|
+
*
|
|
83
|
+
* The injection uses `String.prototype.replace` with a string argument
|
|
84
|
+
* (not a regex), so only the FIRST `</body>` match is rewritten. That
|
|
85
|
+
* matters because a misconfigured renderer can emit malformed HTML with
|
|
86
|
+
* multiple `</body>` tags; we never want to inject the banner more than
|
|
87
|
+
* once per response.
|
|
88
|
+
*/
|
|
89
|
+
export function injectPreviewBanner(html, ctx, endpoint, exitPath) {
|
|
90
|
+
const robotsMeta = '<meta name="robots" content="noindex, nofollow">';
|
|
91
|
+
const script = `<script>${getBannerScriptText(ctx, endpoint, exitPath)}</script>`;
|
|
92
|
+
return html.replace('</body>', `${robotsMeta + script}</body>`);
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=banner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"banner.js","sourceRoot":"","sources":["../../../src/preview/banner.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAmB,EAAE,QAAiB,EAAE,QAAiB;IAC3F,sEAAsE;IACtE,yEAAyE;IACzE,wEAAwE;IACxE,yEAAyE;IACzE,0EAA0E;IAC1E,EAAE;IACF,mEAAmE;IACnE,0EAA0E;IAC1E,4EAA4E;IAC5E,wEAAwE;IACxE,6EAA6E;IAC7E,EAAE;IACF,2EAA2E;IAC3E,2EAA2E;IAC3E,4EAA4E;IAC5E,uEAAuE;IACvE,MAAM,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ContentEntry, ContentManifest, CreateContentInput, CreateResult, DeleteLocaleInput, DeleteResult, FindOptions, Fragments, GlobalFilters, LocalizedEntry, Site, SitesConfig, UpdateLocaleInput, UpdateResult } from '@conloca/content-api';
|
|
2
|
+
import type { PreviewContext } from './middleware.js';
|
|
3
|
+
/**
|
|
4
|
+
* `Data` is not re-exported from `@conloca/content-api`'s package index; we
|
|
5
|
+
* pull it off the `ContentAPI` interface via an indexed type so the preview
|
|
6
|
+
* reader's `data` field has the same nominal shape without depending on
|
|
7
|
+
* deep imports.
|
|
8
|
+
*/
|
|
9
|
+
type ContentAPIData = ContentAPI['data'];
|
|
10
|
+
/**
|
|
11
|
+
* Options consumed by {@link PreviewContentAPI}.
|
|
12
|
+
*
|
|
13
|
+
* The reader is constructed once per request inside the preview SSR
|
|
14
|
+
* dispatcher; passing the baseline reader through the options keeps the
|
|
15
|
+
* "no long-lived cache" rule honest (no per-package singleton can
|
|
16
|
+
* accidentally outlive a request).
|
|
17
|
+
*
|
|
18
|
+
* `embeddedPayloads` is the optimisation the endpoint's page-status route
|
|
19
|
+
* uses to avoid N+1 fetches when it has already loaded a changed dependency
|
|
20
|
+
* to compute the page render graph. Keys are `"${id} ${locale}"`; the value
|
|
21
|
+
* is the full {@link LocalizedEntry} envelope the renderer would have read
|
|
22
|
+
* from disk. When supplied, {@link PreviewContentAPI.getLocalized} short-
|
|
23
|
+
* circuits the network fetch for that pair.
|
|
24
|
+
*
|
|
25
|
+
* `fetchFn` is the optional fetch injection seam. Tests pass a recording
|
|
26
|
+
* stub so the network is never touched.
|
|
27
|
+
*/
|
|
28
|
+
export interface PreviewContentAPIOptions {
|
|
29
|
+
saasEndpoint: string;
|
|
30
|
+
ctx: PreviewContext;
|
|
31
|
+
/**
|
|
32
|
+
* The build's static collection-backed reader. Used for `304` fall-back
|
|
33
|
+
* inside `getLocalized` when the endpoint reports a dependency unchanged in the
|
|
34
|
+
* branch, and as the manifest source only when the branch listing could not
|
|
35
|
+
* be loaded. A loaded branch listing is authoritative for additions,
|
|
36
|
+
* deletions, and each manifest's locale set.
|
|
37
|
+
*/
|
|
38
|
+
baselineApi: ContentAPI;
|
|
39
|
+
embeddedPayloads?: ReadonlyMap<string, LocalizedEntry>;
|
|
40
|
+
fetchFn?: typeof fetch;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Per-request preview-aware `ContentAPI` reader.
|
|
44
|
+
*
|
|
45
|
+
* The page handler boundary reads through `Astro.locals.contentApi` when
|
|
46
|
+
* present; the preview dispatcher installs an instance of this class on that
|
|
47
|
+
* property. For unchanged dependencies the reader transparently
|
|
48
|
+
* falls back to the baseline so the production assets are reused; for changed
|
|
49
|
+
* dependencies the reader fetches `/preview/content` from the endpoint,
|
|
50
|
+
* carrying the preview JWT in the `Authorization` header.
|
|
51
|
+
*
|
|
52
|
+
* Write methods always return a failure result — preview SSR is strictly
|
|
53
|
+
* read-only: no write reaches the endpoint from the preview reader.
|
|
54
|
+
*/
|
|
55
|
+
export declare class PreviewContentAPI implements ContentAPI {
|
|
56
|
+
/**
|
|
57
|
+
* Fragments/Data facades delegate to the baseline reader. The preview
|
|
58
|
+
* renderer reads fragment / data dependencies through `getLocalized` once
|
|
59
|
+
* the page handler has resolved the dependency id, so the facades only
|
|
60
|
+
* need to surface the baseline's listing semantics for legacy callers.
|
|
61
|
+
*/
|
|
62
|
+
readonly fragments: Fragments;
|
|
63
|
+
readonly data: ContentAPIData;
|
|
64
|
+
private readonly opts;
|
|
65
|
+
private readonly fetchImpl;
|
|
66
|
+
/** The branch's page set, once {@link loadBranchManifests} has run. */
|
|
67
|
+
private branchManifests?;
|
|
68
|
+
private readonly localizedReads;
|
|
69
|
+
constructor(opts: PreviewContentAPIOptions);
|
|
70
|
+
get sitesConfig(): SitesConfig;
|
|
71
|
+
getContent(id: string): Promise<ContentEntry | null>;
|
|
72
|
+
getLocalized(id: string, locale: string): Promise<LocalizedEntry | null>;
|
|
73
|
+
private fetchLocalized;
|
|
74
|
+
getContentAsBuffer(id: string, locale: string): Promise<{
|
|
75
|
+
buffer: Uint8Array;
|
|
76
|
+
etag: string;
|
|
77
|
+
contentType: 'application/json' | 'text/mdx';
|
|
78
|
+
} | null>;
|
|
79
|
+
getSite(siteName: string): Site | null;
|
|
80
|
+
/**
|
|
81
|
+
* Prefetch the branch's own manifest listing.
|
|
82
|
+
*
|
|
83
|
+
* The baseline is a snapshot of the last PRODUCTION build, so it cannot know
|
|
84
|
+
* about a page created on the branch and still contains pages the branch
|
|
85
|
+
* deleted — listing from it makes new pages unpreviewable and deleted ones
|
|
86
|
+
* linger. The branch is the authority for the page set; the baseline stays
|
|
87
|
+
* the fallback for unchanged dependency CONTENT.
|
|
88
|
+
*
|
|
89
|
+
* Prefetched rather than fetched lazily because `ContentAPI.listAllContent`
|
|
90
|
+
* is a synchronous generator. On any failure the listing is left unset and
|
|
91
|
+
* `listAllContent` degrades to the baseline — a stale page set renders
|
|
92
|
+
* something, an exception renders nothing.
|
|
93
|
+
*/
|
|
94
|
+
loadBranchManifests(): Promise<void>;
|
|
95
|
+
listAllContent(filters?: GlobalFilters): Generator<ContentManifest>;
|
|
96
|
+
findUntranslatedContent(targetLocale: string, options?: FindOptions): Generator<ContentManifest>;
|
|
97
|
+
createContent(_input: CreateContentInput): Promise<CreateResult>;
|
|
98
|
+
updateLocalized(_input: UpdateLocaleInput): Promise<UpdateResult>;
|
|
99
|
+
deleteContent(_id: string, _etag: string): Promise<DeleteResult>;
|
|
100
|
+
deleteLocalized(_input: DeleteLocaleInput): Promise<DeleteResult>;
|
|
101
|
+
batchUpdate(operations: UpdateLocaleInput[]): Promise<BatchResult>;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Composes the embedded-payload map key. Public so the dispatcher (and the
|
|
105
|
+
* page-status response decoder) can build keys that the reader will match
|
|
106
|
+
* without leaking the encoding choice across modules.
|
|
107
|
+
*/
|
|
108
|
+
export declare function embeddedKey(id: string, locale: string): string;
|
|
109
|
+
export {};
|
|
110
|
+
//# sourceMappingURL=content-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-api.d.ts","sourceRoot":"","sources":["../../../src/preview/content-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,SAAS,EACT,aAAa,EAEb,cAAc,EACd,IAAI,EACJ,WAAW,EACX,iBAAiB,EACjB,YAAY,EACb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;;;;GAKG;AACH,KAAK,cAAc,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;AAEzC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,wBAAwB;IACvC,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,cAAc,CAAC;IACpB;;;;;;OAMG;IACH,WAAW,EAAE,UAAU,CAAC;IACxB,gBAAgB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACvD,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;CACxB;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,iBAAkB,YAAW,UAAU;IAClD;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAE9B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA2B;IAChD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAe;IACzC,uEAAuE;IACvE,OAAO,CAAC,eAAe,CAAC,CAAoB;IAC5C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAqD;IAEpF,YAAY,IAAI,EAAE,wBAAwB,EAQzC;IAED,IAAI,WAAW,IAAI,WAAW,CAE7B;IAMK,UAAU,CAAC,EAAE,EA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