@decocms/nextjs 8.5.2 → 8.7.0
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 +82 -15
- package/dist/DraftPreviewIndicator.d.ts.map +1 -1
- package/dist/DraftPreviewIndicator.js +4 -3
- package/dist/DraftPreviewIndicator.js.map +1 -1
- package/dist/assignments.d.ts +95 -0
- package/dist/assignments.d.ts.map +1 -0
- package/dist/assignments.js +229 -0
- package/dist/assignments.js.map +1 -0
- package/dist/draft.d.ts +36 -10
- package/dist/draft.d.ts.map +1 -1
- package/dist/draft.js +38 -12
- package/dist/draft.js.map +1 -1
- package/dist/drafts.d.ts +39 -60
- package/dist/drafts.d.ts.map +1 -1
- package/dist/drafts.js +58 -117
- package/dist/drafts.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/instrumentation/index.d.ts +1 -1
- package/dist/instrumentation/index.js +3 -3
- package/dist/instrumentation/index.js.map +1 -1
- package/dist/proxy/index.d.ts +175 -35
- package/dist/proxy/index.d.ts.map +1 -1
- package/dist/proxy/index.js +242 -41
- package/dist/proxy/index.js.map +1 -1
- package/dist/server/index.d.ts +59 -20
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +143 -25
- package/dist/server/index.js.map +1 -1
- package/dist/server/slot.d.ts +25 -4
- package/dist/server/slot.d.ts.map +1 -1
- package/dist/server/slot.js +13 -9
- package/dist/server/slot.js.map +1 -1
- package/dist/visitor.d.ts +16 -0
- package/dist/visitor.d.ts.map +1 -0
- package/dist/visitor.js +16 -0
- package/dist/visitor.js.map +1 -0
- package/package.json +3 -3
- package/src/DraftPreviewIndicator.tsx +4 -3
- package/src/assignments.ts +278 -0
- package/src/config/index.cjs +1 -1
- package/src/draft.ts +43 -12
- package/src/drafts.ts +71 -126
- package/src/index.ts +5 -2
- package/src/instrumentation/index.ts +3 -3
- package/src/proxy/index.ts +371 -59
- package/src/server/index.ts +173 -33
- package/src/server/slot.ts +33 -5
- package/src/visitor.ts +16 -0
package/dist/draft.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The draft names and headers of a Deco Next.js site: the `?__draft=` link,
|
|
3
3
|
* the cookie that keeps a preview going, the request header the proxy hands
|
|
4
|
-
* the pages, and the response headers of a page rendered from a draft. The
|
|
4
|
+
* the pages the version on, and the response headers of a page rendered from a draft. The
|
|
5
5
|
* proxy reads and writes them (`./drafts.ts`, `./proxy`); the pages read the
|
|
6
6
|
* header (`./server`); `./config/index.cjs` repeats them (`config.test.ts`
|
|
7
7
|
* holds them equal). This package's own copy: it never imports
|
|
@@ -20,24 +20,50 @@ export const DRAFT_PARAM = "__draft";
|
|
|
20
20
|
export const DRAFT_COOKIE = "__deco_draft";
|
|
21
21
|
/**
|
|
22
22
|
* The request header the proxy sets on the request it hands the pages once it
|
|
23
|
-
* accepted
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* accepted a Studio link: the version (a draft pointer or a release's commit
|
|
24
|
+
* SHA), already checked, without the preview's moment and switched tests
|
|
25
|
+
* (those are decided in the proxy: `ASSIGNMENTS_HEADER`). The proxy removes
|
|
26
|
+
* any copy that arrives from outside, and `bindDraft` repeats the host check,
|
|
27
|
+
* so a client can't send one itself.
|
|
26
28
|
*/
|
|
27
|
-
export const
|
|
29
|
+
export const VERSION_HEADER = "x-deco-version";
|
|
30
|
+
/**
|
|
31
|
+
* The request header the proxy sets on a draft request it hands the pages:
|
|
32
|
+
* the id of the release check it made for it (`cms.checkRelease()`), so
|
|
33
|
+
* `bindDraft`'s host check and the page's draft reads wait for that check
|
|
34
|
+
* instead of making their own (one `latest.json` read per preview request).
|
|
35
|
+
* The proxy removes any copy that arrives from outside; an id the CMS didn't
|
|
36
|
+
* make (a proxy in another process) is a check of its own anyway.
|
|
37
|
+
*/
|
|
38
|
+
export const RELEASE_CHECK_HEADER = "x-deco-release-check";
|
|
28
39
|
/** The URL prefix a drafted request is rewritten onto (`app/%5Fdraft/[[...path]]`). */
|
|
29
40
|
export const DRAFT_ROUTE_PREFIX = "/_draft";
|
|
30
41
|
/**
|
|
31
|
-
* The
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
42
|
+
* The request header the proxy sets when the link named a draft that can't be
|
|
43
|
+
* read anymore (deleted, say): the pages render the release and
|
|
44
|
+
* `DraftPreviewIndicator` says so calmly. The proxy removes any copy that
|
|
45
|
+
* arrives from outside.
|
|
46
|
+
*/
|
|
47
|
+
export const DRAFT_UNAVAILABLE_HEADER = "x-deco-draft-unavailable";
|
|
48
|
+
/**
|
|
49
|
+
* The `Cache-Control` of every response to a preview request (a request with
|
|
50
|
+
* `?__draft=`, whatever its value, or the draft cookie): always revalidated,
|
|
51
|
+
* never answered from a cache (PO 2026-10-23).
|
|
52
|
+
*/
|
|
53
|
+
export const DRAFT_CACHE_CONTROL = "max-age=0, no-cache, must-revalidate";
|
|
54
|
+
/**
|
|
55
|
+
* The response headers of a preview: never answered from a browser's or a
|
|
56
|
+
* CDN's cache (`Cache-Control: max-age=0, no-cache, must-revalidate`, `Vary:
|
|
57
|
+
* Cookie`) and never indexed (`X-Robots-Tag: noindex, nofollow`). `{}` when
|
|
58
|
+
* `preview` is `null`, `false` or empty, so the result of the draft decision
|
|
59
|
+
* applies as is: pass the version, or whether the request carries a draft
|
|
60
|
+
* signal at all (`?__draft=off` and a refused or unavailable draft too).
|
|
35
61
|
*/
|
|
36
|
-
export function draftResponseHeaders(
|
|
37
|
-
if (!
|
|
62
|
+
export function draftResponseHeaders(preview) {
|
|
63
|
+
if (!preview)
|
|
38
64
|
return {};
|
|
39
65
|
return {
|
|
40
|
-
"Cache-Control":
|
|
66
|
+
"Cache-Control": DRAFT_CACHE_CONTROL,
|
|
41
67
|
Vary: "Cookie",
|
|
42
68
|
"X-Robots-Tag": "noindex, nofollow",
|
|
43
69
|
};
|
package/dist/draft.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draft.js","sourceRoot":"","sources":["../src/draft.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAC;AAErC;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,cAAc,CAAC;AAE3C
|
|
1
|
+
{"version":3,"file":"draft.js","sourceRoot":"","sources":["../src/draft.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAC;AAErC;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,cAAc,CAAC;AAE3C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAgB,CAAC;AAE/C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;AAE3D,uFAAuF;AACvF,MAAM,CAAC,MAAM,kBAAkB,GAAG,SAAS,CAAC;AAE5C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,0BAA0B,CAAC;AAEnE;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,sCAAsC,CAAC;AAE1E;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAA4C;IAE5C,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IACxB,OAAO;QACL,eAAe,EAAE,mBAAmB;QACpC,IAAI,EAAE,QAAQ;QACd,cAAc,EAAE,mBAAmB;KACpC,CAAC;AACJ,CAAC"}
|
package/dist/drafts.d.ts
CHANGED
|
@@ -1,67 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Which hosts may render drafts:
|
|
3
|
-
*
|
|
4
|
-
* `
|
|
5
|
-
* `
|
|
6
|
-
*
|
|
7
|
-
*
|
|
2
|
+
* Which hosts may render drafts: the ones the CMS allows (`cms.readVersion`):
|
|
3
|
+
* the addresses Studio writes into the current release's metadata, plus
|
|
4
|
+
* `createCMS`'s `preview.hosts`; every host while the site has published no
|
|
5
|
+
* list, or with no `site` and no `preview.hosts`. The site declares nothing
|
|
6
|
+
* here (PO 2026-10-22). The proxy
|
|
7
|
+
* (`decideDraft`) and the pages (`bindDraft`) ask the same CMS.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* matches them). A site that declares none has none, as in v7: blocks'
|
|
12
|
-
* own default (every host) doesn't count as a declaration.
|
|
13
|
-
* - The hosts Deco runs the site on, named after the site and always added:
|
|
14
|
-
* `<site>.deco.site` and `<site>.deco-cx.workers.dev`, exact.
|
|
15
|
-
* - `previewHosts: [...]` replaces the site's own list (the inferred hosts are
|
|
16
|
-
* still added); `previewHosts: "none"` turns previews off on every host.
|
|
17
|
-
*
|
|
18
|
-
* Hosts compare exactly, lowercased, port included (`localhost:3000`). The
|
|
19
|
-
* host is the one the visitor asked for: `x-forwarded-host` behind a proxy,
|
|
20
|
-
* else `host`.
|
|
9
|
+
* The host is the one the visitor asked for: `x-forwarded-host` behind a
|
|
10
|
+
* proxy, else `host`.
|
|
21
11
|
*
|
|
22
12
|
* The draft itself is the capability: a host check only bounds where a draft
|
|
23
13
|
* link works. A request the check refuses gets the release, never an error.
|
|
24
14
|
*
|
|
15
|
+
* What a link carries is a version, as `cms.readVersion` reads it: a draft
|
|
16
|
+
* pointer, or a published release's commit SHA (Studio's "Preview this
|
|
17
|
+
* version"), with the preview's moment and switched tests and campaigns
|
|
18
|
+
* (`__at`, `__test`, `__campaign`; `parseVersion` from `@decocms/blocks`).
|
|
19
|
+
* Both pass the same host check: a visitor on the live site never picks a
|
|
20
|
+
* version.
|
|
21
|
+
*
|
|
25
22
|
* No React, no Next.js and no module state: the proxy and the pages share it.
|
|
26
23
|
*/
|
|
27
|
-
import { type CMS, type RequestLike } from "@decocms/blocks";
|
|
28
|
-
export interface PreviewPolicy {
|
|
29
|
-
/** The site's name: `<site>.deco.site` and `<site>.deco-cx.workers.dev` may preview. */
|
|
30
|
-
site?: string;
|
|
31
|
-
/** Replaces the `CMS` block's preview hosts; `"none"` turns previews off everywhere. */
|
|
32
|
-
previewHosts?: readonly string[] | "none";
|
|
33
|
-
}
|
|
34
|
-
/** The hosts Deco runs `site` on, which may always preview (unless previews are off). */
|
|
35
|
-
export declare function inferredPreviewHosts(site: string | undefined): string[];
|
|
36
|
-
/**
|
|
37
|
-
* Whether `host` may preview without asking the CMS: `true` (an override or
|
|
38
|
-
* inferred host), `false` (previews off, or the override leaves it out), or
|
|
39
|
-
* `"cms"` when only the site's declared preview hosts can say (none declared:
|
|
40
|
-
* `false`, see {@link declaresPreviewHosts}).
|
|
41
|
-
*/
|
|
42
|
-
export declare function previewHostDecision(host: string, policy: PreviewPolicy): boolean | "cms";
|
|
43
|
-
/**
|
|
44
|
-
* Whether any host may preview (v7's `isDraftPreviewEnabled`): a page checks
|
|
45
|
-
* it before it reads the request's headers, so a site with previews off never
|
|
46
|
-
* turns a static page dynamic. `false` for `previewHosts: "none"`; `true` with
|
|
47
|
-
* a site name or an override list; otherwise whether the site declares
|
|
48
|
-
* preview hosts and they allow any.
|
|
49
|
-
*/
|
|
50
|
-
export declare function isDraftPreviewEnabled(cms: Pick<CMS, "settings" | "forRelease">, policy: PreviewPolicy): Promise<boolean>;
|
|
24
|
+
import { type CMS, type RequestLike, type RequestVersion } from "@decocms/blocks";
|
|
51
25
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* a site without a list previewed only on its Deco hosts. The saved `CMS`
|
|
56
|
-
* block tells an explicit `["*"]` from that default.
|
|
26
|
+
* What a request's Studio link asks for, as `@decocms/blocks` reads it:
|
|
27
|
+
* `?__draft=` first, then the draft cookie; `null` for `?__draft=off` and
|
|
28
|
+
* for a value that doesn't parse.
|
|
57
29
|
*/
|
|
58
|
-
export declare function
|
|
59
|
-
/**
|
|
60
|
-
* The pointer a request carries, as `@decocms/blocks` reads it: `?__draft=`
|
|
61
|
-
* first, then the draft cookie; `null` for `?__draft=off` and for a value
|
|
62
|
-
* that doesn't parse.
|
|
63
|
-
*/
|
|
64
|
-
export declare function readDraftPointer(request: RequestLike): string | null;
|
|
30
|
+
export declare function readDraftVersion(request: RequestLike): RequestVersion | null;
|
|
65
31
|
/** Whether the request carries a draft signal at all: without one the CMS is never asked. */
|
|
66
32
|
export declare function hasDraftSignal(request: RequestLike): boolean;
|
|
67
33
|
/** The host the visitor asked for: the first `x-forwarded-host`, else `host`. */
|
|
@@ -76,11 +42,21 @@ export declare function requestHost(headers: {
|
|
|
76
42
|
*/
|
|
77
43
|
export declare function requestLike(headers: Headers, pathAndQuery: string, fallbackHost?: string): RequestLike | null;
|
|
78
44
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
45
|
+
* What `request` renders (a draft pointer or a release's commit SHA, with
|
|
46
|
+
* the preview's moment and switched tests and campaigns), or `null` for the
|
|
47
|
+
* current release: what its Studio link carries, on a host the CMS allows.
|
|
48
|
+
*/
|
|
49
|
+
export declare function allowedDraft(cms: Pick<CMS, "readVersion">, request: RequestLike, releaseCheck?: string | null): Promise<RequestVersion | null>;
|
|
50
|
+
/** Whether a version names a saved draft (a pointer, not a release's SHA and not `local`). */
|
|
51
|
+
export declare function namesDraft(version: string): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* The release check of a request whose link names a draft
|
|
54
|
+
* (`cms.checkRelease()`), so its host check, its draft reads and its render
|
|
55
|
+
* share one read of `latest.json`: the one `forwarded` names when the CMS
|
|
56
|
+
* made it (the proxy's, for the same request), else a new one. `undefined`
|
|
57
|
+
* for any other request: the release, a release's SHA, no link.
|
|
82
58
|
*/
|
|
83
|
-
export declare function
|
|
59
|
+
export declare function draftReleaseCheck(cms: Pick<CMS, "checkRelease">, request: RequestLike, forwarded?: string | null): Promise<string | undefined>;
|
|
84
60
|
/**
|
|
85
61
|
* The draft cookie: the same `Set-Cookie` `cms.draftCookie` writes (a test
|
|
86
62
|
* holds the two together). Studio frames the site cross-site, hence
|
|
@@ -89,6 +65,9 @@ export declare function allowedDraft(cms: Pick<CMS, "draftPointer" | "settings"
|
|
|
89
65
|
export declare function draftCookie(value: string, extra?: string[]): string;
|
|
90
66
|
/** Whether the request ends a preview (`?__draft=off`): the cookie goes on any host. */
|
|
91
67
|
export declare function endsPreview(request: RequestLike): boolean;
|
|
92
|
-
/**
|
|
93
|
-
|
|
68
|
+
/**
|
|
69
|
+
* The request's own `?__draft=` value when it is a version (a draft link,
|
|
70
|
+
* not the cookie): the value its cookie stores; `null` otherwise.
|
|
71
|
+
*/
|
|
72
|
+
export declare function draftLinkValue(request: RequestLike): string | null;
|
|
94
73
|
//# sourceMappingURL=drafts.d.ts.map
|
package/dist/drafts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drafts.d.ts","sourceRoot":"","sources":["../src/drafts.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"drafts.d.ts","sourceRoot":"","sources":["../src/drafts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EACL,KAAK,GAAG,EAGR,KAAK,WAAW,EAChB,KAAK,cAAc,EACpB,MAAM,iBAAiB,CAAC;AA2BzB;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,GAAG,IAAI,CAM5E;AAED,6FAA6F;AAC7F,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAI5D;AAED,iFAAiF;AACjF,wBAAgB,WAAW,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,MAAM,GAAG,IAAI,CAIxF;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,MAAM,EACpB,YAAY,CAAC,EAAE,MAAM,GACpB,WAAW,GAAG,IAAI,CAQpB;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAChC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,aAAa,CAAC,EAC7B,OAAO,EAAE,WAAW,EACpB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAC3B,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAIhC;AAKD,8FAA8F;AAC9F,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAGnD;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,EAC9B,OAAO,EAAE,WAAW,EACpB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GACxB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAI7B;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,GAAE,MAAM,EAAO,GAAG,MAAM,CAUvE;AAED,wFAAwF;AACxF,wBAAgB,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAEzD;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI,CAGlE"}
|
package/dist/drafts.js
CHANGED
|
@@ -1,100 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Which hosts may render drafts:
|
|
3
|
-
*
|
|
4
|
-
* `
|
|
5
|
-
* `
|
|
6
|
-
*
|
|
7
|
-
*
|
|
2
|
+
* Which hosts may render drafts: the ones the CMS allows (`cms.readVersion`):
|
|
3
|
+
* the addresses Studio writes into the current release's metadata, plus
|
|
4
|
+
* `createCMS`'s `preview.hosts`; every host while the site has published no
|
|
5
|
+
* list, or with no `site` and no `preview.hosts`. The site declares nothing
|
|
6
|
+
* here (PO 2026-10-22). The proxy
|
|
7
|
+
* (`decideDraft`) and the pages (`bindDraft`) ask the same CMS.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* matches them). A site that declares none has none, as in v7: blocks'
|
|
12
|
-
* own default (every host) doesn't count as a declaration.
|
|
13
|
-
* - The hosts Deco runs the site on, named after the site and always added:
|
|
14
|
-
* `<site>.deco.site` and `<site>.deco-cx.workers.dev`, exact.
|
|
15
|
-
* - `previewHosts: [...]` replaces the site's own list (the inferred hosts are
|
|
16
|
-
* still added); `previewHosts: "none"` turns previews off on every host.
|
|
17
|
-
*
|
|
18
|
-
* Hosts compare exactly, lowercased, port included (`localhost:3000`). The
|
|
19
|
-
* host is the one the visitor asked for: `x-forwarded-host` behind a proxy,
|
|
20
|
-
* else `host`.
|
|
9
|
+
* The host is the one the visitor asked for: `x-forwarded-host` behind a
|
|
10
|
+
* proxy, else `host`.
|
|
21
11
|
*
|
|
22
12
|
* The draft itself is the capability: a host check only bounds where a draft
|
|
23
13
|
* link works. A request the check refuses gets the release, never an error.
|
|
24
14
|
*
|
|
15
|
+
* What a link carries is a version, as `cms.readVersion` reads it: a draft
|
|
16
|
+
* pointer, or a published release's commit SHA (Studio's "Preview this
|
|
17
|
+
* version"), with the preview's moment and switched tests and campaigns
|
|
18
|
+
* (`__at`, `__test`, `__campaign`; `parseVersion` from `@decocms/blocks`).
|
|
19
|
+
* Both pass the same host check: a visitor on the live site never picks a
|
|
20
|
+
* version.
|
|
21
|
+
*
|
|
25
22
|
* No React, no Next.js and no module state: the proxy and the pages share it.
|
|
26
23
|
*/
|
|
27
|
-
import { parseDraftPointer } from "@decocms/blocks";
|
|
24
|
+
import { parseDraftPointer, parseVersion, } from "@decocms/blocks";
|
|
28
25
|
import { DRAFT_COOKIE, DRAFT_PARAM } from "./draft.js";
|
|
29
|
-
/** The hosts Deco runs `site` on, which may always preview (unless previews are off). */
|
|
30
|
-
export function inferredPreviewHosts(site) {
|
|
31
|
-
const s = (site ?? "").trim().toLowerCase();
|
|
32
|
-
return s ? [`${s}.deco.site`, `${s}.deco-cx.workers.dev`] : [];
|
|
33
|
-
}
|
|
34
|
-
function overrideHosts(policy) {
|
|
35
|
-
if (policy.previewHosts === "none")
|
|
36
|
-
return ["none"];
|
|
37
|
-
return (policy.previewHosts ?? []).map((h) => h.trim().toLowerCase()).filter(Boolean);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Whether `host` may preview without asking the CMS: `true` (an override or
|
|
41
|
-
* inferred host), `false` (previews off, or the override leaves it out), or
|
|
42
|
-
* `"cms"` when only the site's declared preview hosts can say (none declared:
|
|
43
|
-
* `false`, see {@link declaresPreviewHosts}).
|
|
44
|
-
*/
|
|
45
|
-
export function previewHostDecision(host, policy) {
|
|
46
|
-
const override = overrideHosts(policy);
|
|
47
|
-
if (override.includes("none"))
|
|
48
|
-
return false;
|
|
49
|
-
const h = host.trim().toLowerCase();
|
|
50
|
-
if (h === "")
|
|
51
|
-
return false;
|
|
52
|
-
if (inferredPreviewHosts(policy.site).includes(h))
|
|
53
|
-
return true;
|
|
54
|
-
if (policy.previewHosts !== undefined)
|
|
55
|
-
return override.includes(h);
|
|
56
|
-
return "cms";
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Whether any host may preview (v7's `isDraftPreviewEnabled`): a page checks
|
|
60
|
-
* it before it reads the request's headers, so a site with previews off never
|
|
61
|
-
* turns a static page dynamic. `false` for `previewHosts: "none"`; `true` with
|
|
62
|
-
* a site name or an override list; otherwise whether the site declares
|
|
63
|
-
* preview hosts and they allow any.
|
|
64
|
-
*/
|
|
65
|
-
export async function isDraftPreviewEnabled(cms, policy) {
|
|
66
|
-
const override = overrideHosts(policy);
|
|
67
|
-
if (override.includes("none"))
|
|
68
|
-
return false;
|
|
69
|
-
if (inferredPreviewHosts(policy.site).length > 0)
|
|
70
|
-
return true;
|
|
71
|
-
if (policy.previewHosts !== undefined)
|
|
72
|
-
return override.length > 0;
|
|
73
|
-
return (await declaresPreviewHosts(cms)) && (await cms.settings()).preview.hosts.length > 0;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Whether the site declares its own preview hosts: in the `CMS` block, or as
|
|
77
|
-
* `createCMS`'s `preview.hosts`. When it declares none, `cms.settings()`
|
|
78
|
-
* reports blocks' default, every host (`["*"]`), which v7 never had: there,
|
|
79
|
-
* a site without a list previewed only on its Deco hosts. The saved `CMS`
|
|
80
|
-
* block tells an explicit `["*"]` from that default.
|
|
81
|
-
*/
|
|
82
|
-
export async function declaresPreviewHosts(cms) {
|
|
83
|
-
const { hosts } = (await cms.settings()).preview;
|
|
84
|
-
if (hosts.length !== 1 || hosts[0] !== "*")
|
|
85
|
-
return true;
|
|
86
|
-
try {
|
|
87
|
-
const [block] = await cms.forRelease().resolve("CMS", { run: false });
|
|
88
|
-
const preview = isRecord(block) ? block.preview : undefined;
|
|
89
|
-
return isRecord(preview) && ("hosts" in preview || "__resolveType" in preview);
|
|
90
|
-
}
|
|
91
|
-
catch {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
function isRecord(value) {
|
|
96
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
97
|
-
}
|
|
98
26
|
const DRAFT_OFF = "off";
|
|
99
27
|
function draftParam(request) {
|
|
100
28
|
try {
|
|
@@ -121,18 +49,18 @@ function readCookie(header, name) {
|
|
|
121
49
|
return null;
|
|
122
50
|
}
|
|
123
51
|
/**
|
|
124
|
-
*
|
|
125
|
-
* first, then the draft cookie; `null` for `?__draft=off` and
|
|
126
|
-
* that doesn't parse.
|
|
52
|
+
* What a request's Studio link asks for, as `@decocms/blocks` reads it:
|
|
53
|
+
* `?__draft=` first, then the draft cookie; `null` for `?__draft=off` and
|
|
54
|
+
* for a value that doesn't parse.
|
|
127
55
|
*/
|
|
128
|
-
export function
|
|
56
|
+
export function readDraftVersion(request) {
|
|
129
57
|
const param = draftParam(request);
|
|
130
58
|
if (param === DRAFT_OFF)
|
|
131
59
|
return null;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return
|
|
60
|
+
const fromLink = param ? parseVersion(param) : null;
|
|
61
|
+
if (fromLink !== null)
|
|
62
|
+
return fromLink;
|
|
63
|
+
return parseVersion(readCookie(request.headers.get("cookie"), DRAFT_COOKIE));
|
|
136
64
|
}
|
|
137
65
|
/** Whether the request carries a draft signal at all: without one the CMS is never asked. */
|
|
138
66
|
export function hasDraftSignal(request) {
|
|
@@ -162,26 +90,35 @@ export function requestLike(headers, pathAndQuery, fallbackHost) {
|
|
|
162
90
|
}
|
|
163
91
|
}
|
|
164
92
|
/**
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
93
|
+
* What `request` renders (a draft pointer or a release's commit SHA, with
|
|
94
|
+
* the preview's moment and switched tests and campaigns), or `null` for the
|
|
95
|
+
* current release: what its Studio link carries, on a host the CMS allows.
|
|
168
96
|
*/
|
|
169
|
-
export async function allowedDraft(cms, request,
|
|
170
|
-
const
|
|
171
|
-
if (
|
|
172
|
-
return null;
|
|
173
|
-
let host;
|
|
174
|
-
try {
|
|
175
|
-
host = new URL(request.url).host;
|
|
176
|
-
}
|
|
177
|
-
catch {
|
|
97
|
+
export async function allowedDraft(cms, request, releaseCheck) {
|
|
98
|
+
const read = readDraftVersion(request);
|
|
99
|
+
if (read === null)
|
|
178
100
|
return null;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
101
|
+
return (await cms.readVersion(request, { releaseCheck })) === null ? null : read;
|
|
102
|
+
}
|
|
103
|
+
/** A draft pointer's version that names no draft: the release, nothing fetched. */
|
|
104
|
+
const LOCAL_VERSION = "local";
|
|
105
|
+
/** Whether a version names a saved draft (a pointer, not a release's SHA and not `local`). */
|
|
106
|
+
export function namesDraft(version) {
|
|
107
|
+
const parsed = parseDraftPointer(version);
|
|
108
|
+
return parsed !== null && parsed.version !== LOCAL_VERSION;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The release check of a request whose link names a draft
|
|
112
|
+
* (`cms.checkRelease()`), so its host check, its draft reads and its render
|
|
113
|
+
* share one read of `latest.json`: the one `forwarded` names when the CMS
|
|
114
|
+
* made it (the proxy's, for the same request), else a new one. `undefined`
|
|
115
|
+
* for any other request: the release, a release's SHA, no link.
|
|
116
|
+
*/
|
|
117
|
+
export async function draftReleaseCheck(cms, request, forwarded) {
|
|
118
|
+
const read = readDraftVersion(request);
|
|
119
|
+
if (read === null || !namesDraft(read.version))
|
|
120
|
+
return undefined;
|
|
121
|
+
return cms.checkRelease(forwarded);
|
|
185
122
|
}
|
|
186
123
|
/**
|
|
187
124
|
* The draft cookie: the same `Set-Cookie` `cms.draftCookie` writes (a test
|
|
@@ -203,8 +140,12 @@ export function draftCookie(value, extra = []) {
|
|
|
203
140
|
export function endsPreview(request) {
|
|
204
141
|
return draftParam(request) === DRAFT_OFF;
|
|
205
142
|
}
|
|
206
|
-
/**
|
|
207
|
-
|
|
208
|
-
|
|
143
|
+
/**
|
|
144
|
+
* The request's own `?__draft=` value when it is a version (a draft link,
|
|
145
|
+
* not the cookie): the value its cookie stores; `null` otherwise.
|
|
146
|
+
*/
|
|
147
|
+
export function draftLinkValue(request) {
|
|
148
|
+
const param = draftParam(request);
|
|
149
|
+
return param && param !== DRAFT_OFF && parseVersion(param) !== null ? param : null;
|
|
209
150
|
}
|
|
210
151
|
//# sourceMappingURL=drafts.js.map
|
package/dist/drafts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drafts.js","sourceRoot":"","sources":["../src/drafts.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"drafts.js","sourceRoot":"","sources":["../src/drafts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAEL,iBAAiB,EACjB,YAAY,GAGb,MAAM,iBAAiB,C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AACH,MAAM,UAAU,cAAc,CAAC,OAAoB;IACjD,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAClC,OAAO,KAAK,IAAI,KAAK,KAAK,SAAS,IAAI,YAAY,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACrF,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
* Outside Studio's frame, "." opens the page in Studio's editor.
|
|
12
12
|
* - `StudioPage`: rendered inside each CMS page, `<StudioPage pathTemplate={page.path} />`,
|
|
13
13
|
* tells the bridge which page "." opens (the root layout doesn't re-render per page).
|
|
14
|
-
* - `DRAFT_PARAM`, `DRAFT_COOKIE`, `
|
|
14
|
+
* - `DRAFT_PARAM`, `DRAFT_COOKIE`, `VERSION_HEADER`, `draftResponseHeaders`,
|
|
15
|
+
* `VISITOR_HEADER`, `ASSIGNMENTS_HEADER`,
|
|
15
16
|
* `STUDIO_ORIGINS`, `STUDIO_FRAME_ANCESTORS`, `isStudioOrigin`: for a site
|
|
16
17
|
* that needs them in its own code (a route that sets its own headers, a CSP
|
|
17
18
|
* it writes itself). The package's own copy: it never imports
|
|
@@ -22,8 +23,10 @@
|
|
|
22
23
|
* loads React.
|
|
23
24
|
*/
|
|
24
25
|
export { DraftBadge, StudioPage, type StudioPageInfo } from "@decocms/blocks/preview";
|
|
26
|
+
export { ASSIGNMENTS_HEADER } from "./assignments.ts";
|
|
25
27
|
export { DraftPreviewIndicator, type DraftPreviewIndicatorProps, } from "./DraftPreviewIndicator.tsx";
|
|
26
|
-
export { DRAFT_COOKIE,
|
|
28
|
+
export { DRAFT_COOKIE, DRAFT_PARAM, draftResponseHeaders, VERSION_HEADER } from "./draft.ts";
|
|
27
29
|
export { StudioBridge, type StudioBridgeProps } from "./StudioBridge.ts";
|
|
28
30
|
export { isStudioOrigin, STUDIO_FRAME_ANCESTORS, STUDIO_ORIGINS } from "./studio.ts";
|
|
31
|
+
export { VISITOR_HEADER } from "./visitor.ts";
|
|
29
32
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EACL,qBAAqB,EACrB,KAAK,0BAA0B,GAChC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC7F,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
* Outside Studio's frame, "." opens the page in Studio's editor.
|
|
12
12
|
* - `StudioPage`: rendered inside each CMS page, `<StudioPage pathTemplate={page.path} />`,
|
|
13
13
|
* tells the bridge which page "." opens (the root layout doesn't re-render per page).
|
|
14
|
-
* - `DRAFT_PARAM`, `DRAFT_COOKIE`, `
|
|
14
|
+
* - `DRAFT_PARAM`, `DRAFT_COOKIE`, `VERSION_HEADER`, `draftResponseHeaders`,
|
|
15
|
+
* `VISITOR_HEADER`, `ASSIGNMENTS_HEADER`,
|
|
15
16
|
* `STUDIO_ORIGINS`, `STUDIO_FRAME_ANCESTORS`, `isStudioOrigin`: for a site
|
|
16
17
|
* that needs them in its own code (a route that sets its own headers, a CSP
|
|
17
18
|
* it writes itself). The package's own copy: it never imports
|
|
@@ -22,8 +23,10 @@
|
|
|
22
23
|
* loads React.
|
|
23
24
|
*/
|
|
24
25
|
export { DraftBadge, StudioPage } from "@decocms/blocks/preview";
|
|
26
|
+
export { ASSIGNMENTS_HEADER } from "./assignments.js";
|
|
25
27
|
export { DraftPreviewIndicator, } from "./DraftPreviewIndicator.js";
|
|
26
|
-
export { DRAFT_COOKIE,
|
|
28
|
+
export { DRAFT_COOKIE, DRAFT_PARAM, draftResponseHeaders, VERSION_HEADER } from "./draft.js";
|
|
27
29
|
export { StudioBridge } from "./StudioBridge.js";
|
|
28
30
|
export { isStudioOrigin, STUDIO_FRAME_ANCESTORS, STUDIO_ORIGINS } from "./studio.js";
|
|
31
|
+
export { VISITOR_HEADER } from "./visitor.js";
|
|
29
32
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAuB,MAAM,yBAAyB,CAAC;AACtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EACL,qBAAqB,GAEtB,MAAM,4BAA6B,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC7F,OAAO,EAAE,YAAY,EAA0B,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* Labels: `http.route` is Next's route template (`unmatched` when Next names
|
|
25
25
|
* none); RSC requests count under their page's route, as the requests they
|
|
26
26
|
* are. `cache` is `DRAFT` for a draft render (the proxy forwarded
|
|
27
|
-
* `x-deco-
|
|
27
|
+
* `x-deco-version`, or the request was rewritten onto `/_draft`) and otherwise
|
|
28
28
|
* `BYPASS`: Next decides its cache (`x-nextjs-cache`) on the response, which
|
|
29
29
|
* the span never sees.
|
|
30
30
|
*/
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
* Labels: `http.route` is Next's route template (`unmatched` when Next names
|
|
25
25
|
* none); RSC requests count under their page's route, as the requests they
|
|
26
26
|
* are. `cache` is `DRAFT` for a draft render (the proxy forwarded
|
|
27
|
-
* `x-deco-
|
|
27
|
+
* `x-deco-version`, or the request was rewritten onto `/_draft`) and otherwise
|
|
28
28
|
* `BYPASS`: Next decides its cache (`x-nextjs-cache`) on the response, which
|
|
29
29
|
* the span never sees.
|
|
30
30
|
*/
|
|
31
31
|
import { recordServerRequest } from "@decocms/blocks/metrics";
|
|
32
|
-
import {
|
|
32
|
+
import { DRAFT_ROUTE_PREFIX, VERSION_HEADER } from "../draft.js";
|
|
33
33
|
/** The span type Next.js gives its one root span per request. */
|
|
34
34
|
const ROOT_SPAN_TYPE = "BaseServer.handleRequest";
|
|
35
35
|
const REGISTERED = Symbol.for("decocms.nextjs.instrumentation");
|
|
@@ -185,7 +185,7 @@ function draftPropagator(DRAFT) {
|
|
|
185
185
|
inject() { },
|
|
186
186
|
extract(context, carrier, getter) {
|
|
187
187
|
try {
|
|
188
|
-
const value = getter.get(carrier,
|
|
188
|
+
const value = getter.get(carrier, VERSION_HEADER);
|
|
189
189
|
return value !== undefined && value !== "" ? context.setValue(DRAFT, true) : context;
|
|
190
190
|
}
|
|
191
191
|
catch {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/instrumentation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAW9D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/instrumentation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAW9D,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAIjE,iEAAiE;AACjE,MAAM,cAAc,GAAG,0BAA0B,CAAC;AAClD,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;AAChE;;;;;GAKG;AACH,MAAM,MAAM,GAAG,aAAa,CAAC;AA0B7B,8CAA8C;AAC9C,MAAM,YAAY,GAAG,CAAC,CAAC;AAEvB,uEAAuE;AACvE,SAAS,iBAAiB,CACxB,UAAsB,EACtB,OAAe,EACf,OAAgB,EAChB,KAAc;IAEd,MAAM,KAAK,GAAG,OAAO,UAAU,CAAC,YAAY,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAClG,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC,CAAC;IACpD,6FAA6F;IAC7F,MAAM,MAAM,GAAG,OAAO,IAAI,CAAC,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,IAAI,GAAG,CAAC;IAC7D,+EAA+E;IAC/E,KAAK,mBAAmB,CAAC;QACvB,KAAK;QACL,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,aAAa,CAAC,IAAI,EAAE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