@decocms/tanstack 8.9.1 → 8.11.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 +4 -4
- package/dist/csp.d.ts +32 -0
- package/dist/csp.d.ts.map +1 -0
- package/dist/csp.js +76 -0
- package/dist/csp.js.map +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/react/DecoDocument.d.ts +16 -2
- package/dist/react/DecoDocument.d.ts.map +1 -1
- package/dist/react/DecoDocument.js +15 -10
- package/dist/react/DecoDocument.js.map +1 -1
- package/dist/studio.d.ts +20 -0
- package/dist/studio.d.ts.map +1 -1
- package/dist/studio.js +47 -0
- package/dist/studio.js.map +1 -1
- package/dist/worker/assignments.d.ts.map +1 -1
- package/dist/worker/assignments.js +3 -9
- package/dist/worker/assignments.js.map +1 -1
- package/dist/worker/cache.d.ts +10 -2
- package/dist/worker/cache.d.ts.map +1 -1
- package/dist/worker/cache.js +26 -2
- package/dist/worker/cache.js.map +1 -1
- package/dist/worker/drafts.d.ts +2 -1
- package/dist/worker/drafts.d.ts.map +1 -1
- package/dist/worker/drafts.js +3 -2
- package/dist/worker/drafts.js.map +1 -1
- package/dist/worker/index.d.ts +14 -2
- package/dist/worker/index.d.ts.map +1 -1
- package/dist/worker/index.js +26 -39
- package/dist/worker/index.js.map +1 -1
- package/dist/worker/security.d.ts +7 -6
- package/dist/worker/security.d.ts.map +1 -1
- package/dist/worker/security.js +14 -30
- package/dist/worker/security.js.map +1 -1
- package/package.json +2 -2
- package/src/csp.ts +99 -0
- package/src/index.ts +12 -3
- package/src/react/DecoDocument.tsx +30 -6
- package/src/studio.ts +47 -0
- package/src/worker/assignments.ts +4 -13
- package/src/worker/cache.ts +19 -2
- package/src/worker/drafts.ts +3 -2
- package/src/worker/index.ts +42 -44
- package/src/worker/security.ts +19 -33
package/README.md
CHANGED
|
@@ -44,13 +44,13 @@ The visitor's first-visit cookie is never in what `render()` returns: the worker
|
|
|
44
44
|
What the key needs, from `@decocms/tanstack/worker`, the same names as `@decocms/nextjs/proxy`'s where both have them:
|
|
45
45
|
|
|
46
46
|
- `assignmentsKey(page.assignments)`: the tests on and the campaigns running, as one string (`x=<tests>|c=<campaigns>`, `""` for none), never the visitor's id. Visitors on the same side of every test share one entry, the other side gets its own, and a campaign starting or ending moves every page to new entries. `liveAssignmentKeys(cms)` lists every key a live request can carry now (each subset of the saved tests, with the running campaigns and with none), for a purge.
|
|
47
|
-
- `cacheVersion(cms, buildHash)`: `<build>.<content revision>`, so a deploy or a published release gets new entries at once.
|
|
47
|
+
- `cacheVersion(cms, buildHash, page.url)`: `<build>.<content revision>`, so a deploy or a published release gets new entries at once. With the URL, the revision is the one that page renders (right after a publish, the previous one while the page's new blocks load), so a page is never stored under a revision it didn't render.
|
|
48
48
|
- `detectDevice(userAgent)` (v7's classes: `mobile`, `tablet`, `desktop`), `segmentKey(segment)` (a segment's parts as one stable string) and `segmentToken(segment, version)`: the `__cseg` token. Pass it as `render({ csegToken })` and `DecoDocument` publishes it; `decoServerFnFetch` sends it back on the page's navigation data (`CSEG_PARAM`), and your cache may let the CDN keep that response when the token matches the request's own.
|
|
49
49
|
- `isCacheable(request, { version, dev })`, `requestVersion(request)`, `isServerFnPath(pathname)`, `serverFnPagePath(url)` (the page a server-function page load asks for, from its payload) and `DEGRADED_HEADER` (a page whose loader failed: never store it).
|
|
50
50
|
|
|
51
51
|
A complete worker entry with a page cache is [`examples/tanstack-worker-smoke/src/worker-entry.ts`](https://github.com/decocms/blocks/blob/main/examples/tanstack-worker-smoke/src/worker-entry.ts): copy it to your `src/worker-entry.ts` and change what your site needs. It is v7's edge cache on the Cloudflare Cache API, and every part of it is yours:
|
|
52
52
|
|
|
53
|
-
- **The key**: the path (tracking parameters and `__cseg` dropped), the device and your segment's own parts (`buildSegment`, v7's: a region, a sales channel), `assignmentsKey(page.assignments)` and `cacheVersion(cms, __BUILD_HASH__)`. A signed-in shopper (`loggedIn: true` from `buildSegment`), a private response and a degraded one are never stored.
|
|
53
|
+
- **The key**: the path (tracking parameters and `__cseg` dropped), the device and your segment's own parts (`buildSegment`, v7's: a region, a sales channel), `assignmentsKey(page.assignments)` and `cacheVersion(cms, __BUILD_HASH__, page.url)`. A signed-in shopper (`loggedIn: true` from `buildSegment`), a private response and a degraded one are never stored.
|
|
54
54
|
- **The profiles**: v7's cache profiles per URL (`PROFILES`), each with how long a page stays fresh, how long it is served stale while it revalidates, and how long when the app fails.
|
|
55
55
|
- **The purge**: v7's `POST /_cache/purge` with `Authorization: Bearer <PURGE_TOKEN>` and a body of `{ "paths": ["/", "/shoes"] }`, optionally with `"segments": [{ "device": "desktop", "salesChannel": "2" }]` (your own parts). It drops each exact path (`/shoes` never drops `/shoes?page=2`) under the current version, for each segment (the devices when the body names none), each assignments key, as a navigation and as a server-function fetch, and answers `{ "purged": [...], "total": n }`. The Cache API is per data center, so a purge reaches the copies of the data center that serves it.
|
|
56
56
|
|
|
@@ -58,7 +58,7 @@ A complete worker entry with a page cache is [`examples/tanstack-worker-smoke/sr
|
|
|
58
58
|
|
|
59
59
|
### Names and Studio's origins
|
|
60
60
|
|
|
61
|
-
The root export holds what the worker, `/server` and `DecoDocument` share, for a site's own code: the draft names (`DRAFT_PARAM` `__draft`, `DRAFT_COOKIE` `__deco_draft`), the headers the worker hands the app (`VERSION_HEADER` `x-deco-version`, `VISITOR_HEADER` `x-deco-visitor`, `ASSIGNMENTS_HEADER` `x-deco-assignments`), `draftResponseHeaders(preview)` (`max-age=0, no-cache, must-revalidate`, `Vary: Cookie`, `noindex`; pass the version, or `true` for any request with a draft signal), and Studio's origins: `STUDIO_ORIGINS`, `STUDIO_FRAME_ANCESTORS` (what the worker's `frame-ancestors` starts from) and `isStudioOrigin
|
|
61
|
+
The root export holds what the worker, `/server` and `DecoDocument` share, for a site's own code: the draft names (`DRAFT_PARAM` `__draft`, `DRAFT_COOKIE` `__deco_draft`), the headers the worker hands the app (`VERSION_HEADER` `x-deco-version`, `VISITOR_HEADER` `x-deco-visitor`, `ASSIGNMENTS_HEADER` `x-deco-assignments`), `draftResponseHeaders(preview)` (`max-age=0, no-cache, must-revalidate`, `Vary: Cookie`, `noindex`; pass the version, or `true` for any request with a draft signal), and Studio's origins: `STUDIO_ORIGINS`, `STUDIO_FRAME_ANCESTORS` (what the worker's `frame-ancestors` starts from) and `isStudioOrigin`; the Studio channel's exact list, `DEFAULT_STUDIO_ORIGINS` and `studioOrigins(option?)`; and `withStudioCsp(directives)`, what the worker does to the site's `csp` (Studio's origins in `script-src` and `frame-ancestors`), for a policy the site sends some other way. `DecoDocument` passes `STUDIO_ORIGINS` to the Studio bridge.
|
|
62
62
|
|
|
63
63
|
```ts
|
|
64
64
|
import { STUDIO_ORIGINS, VERSION_HEADER } from "@decocms/tanstack";
|
|
@@ -81,7 +81,7 @@ export const startInstance = createStart(() => ({ serverFns: { fetch: decoServer
|
|
|
81
81
|
export const Route = createRootRoute({ component: () => <DecoDocument site="my-store" /> });
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
`DecoDocument` mounts Studio's bridge and the draft badge. A page route returns `pathTemplate` (the page block's `path`, as `matchRoute` matched it) in its loader data, so "." on the store page opens that page in Studio's editor. A site that keeps its own document (a skip link before `<main>`, say) renders `<DecoPreview site="my-store" />` in its `<body>` instead: the bridge, the badge and the draft they read.
|
|
84
|
+
`DecoDocument` mounts Studio's bridge, the Studio channel and the draft badge. The Studio channel is on every page, production included: a small inline script (about 0.7 kB gzipped) through which Studio loads its own editor code (the section wireframe, the page swap after a save) into the page when it frames it. It is the only way Studio runs code in the page: the bridge evaluates no script Studio sends. The page trusts a list of exact Studio origins: the `studioOrigins` prop when given, else the `DECO_STUDIO_ORIGIN` environment variable, comma-separated (read on the server; a local Studio, such as `http://localhost:3000`), else Studio's production and staging origins (`DEFAULT_STUDIO_ORIGINS`). Framed, the page posts `{ type: "deco:ready" }` with each of them as the target origin (only a parent at one of them receives it) and imports a module only when Studio's answer, `{ type: "deco:load", url }`, comes from exactly one of them and names a URL on the origin of that message; not framed, or framed by any other origin, it does nothing. The worker adds the same list to every HTML response's CSP: to `frame-ancestors`, and to `script-src` (or `script-src-elem`; a policy that restricts scripts only through `default-src` gets a `script-src` with its sources plus Studio's). A site that sets `studioOrigins` on `DecoDocument` sets the worker's `studioOrigins` option too; `DECO_STUDIO_ORIGIN` sets both. The inline scripts take the site's `nonce`. The message and module types are in `@decocms/blocks/protocol`. A page route returns `pathTemplate` (the page block's `path`, as `matchRoute` matched it) in its loader data, so "." on the store page opens that page in Studio's editor. A site that keeps its own document (a skip link before `<main>`, say) renders `<DecoPreview site="my-store" />` in its `<body>` instead: the bridge, the badge and the draft they read.
|
|
85
85
|
|
|
86
86
|
## Images
|
|
87
87
|
|
package/dist/csp.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** A Studio on this machine, in local development. */
|
|
2
|
+
export declare const LOOPBACK_ANCESTORS: readonly string[];
|
|
3
|
+
export interface StudioCspOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Studio's origins; default {@link studioOrigins}() (`DECO_STUDIO_ORIGIN`,
|
|
6
|
+
* else production and staging). Read through {@link studioOrigins} like any
|
|
7
|
+
* other value: an entry that isn't an exact http(s) origin is dropped.
|
|
8
|
+
*/
|
|
9
|
+
studioOrigins?: readonly string[];
|
|
10
|
+
/** More origins that may frame the site, besides Studio's (a marketing tool's editor). */
|
|
11
|
+
frameAncestors?: readonly string[];
|
|
12
|
+
/** Local development: loopback may frame the site. */
|
|
13
|
+
dev?: boolean;
|
|
14
|
+
/** Add `frame-ancestors` when the directives have none. Default `true`. */
|
|
15
|
+
addFrameAncestors?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** The directives of a policy (`"a; b"` or `["a", "b"]`), trimmed, empty ones dropped. */
|
|
18
|
+
export declare function cspDirectives(value: string | readonly string[] | undefined): string[];
|
|
19
|
+
/** The `frame-ancestors` sources: Studio's, the site's own, and loopback in development. */
|
|
20
|
+
export declare function studioFrameAncestors(options?: StudioCspOptions): string[];
|
|
21
|
+
/**
|
|
22
|
+
* A policy's directives with what Studio needs added: Studio's origins in
|
|
23
|
+
* `script-src` (and `script-src-elem`), so the Studio channel can import
|
|
24
|
+
* Studio's modules, and a `frame-ancestors` with Studio's (when the policy has
|
|
25
|
+
* none). A policy that restricts scripts only through `default-src` gets a
|
|
26
|
+
* `script-src` with `default-src`'s sources plus Studio's, which allows the
|
|
27
|
+
* same scripts as before and Studio's modules. A policy that doesn't restrict
|
|
28
|
+
* scripts, or forbids them all (`'none'`), keeps its scripts as they are.
|
|
29
|
+
* A site's own `frame-ancestors` is kept as is.
|
|
30
|
+
*/
|
|
31
|
+
export declare function withStudioCsp(directives: string | readonly string[] | undefined, options?: StudioCspOptions): string[];
|
|
32
|
+
//# sourceMappingURL=csp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csp.d.ts","sourceRoot":"","sources":["../src/csp.ts"],"names":[],"mappings":"AAWA,sDAAsD;AACtD,eAAO,MAAM,kBAAkB,EAAE,SAAS,MAAM,EAG9C,CAAC;AAEH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,0FAA0F;IAC1F,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,sDAAsD;IACtD,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,2EAA2E;IAC3E,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,0FAA0F;AAC1F,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,EAAE,CAIrF;AAeD,4FAA4F;AAC5F,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,gBAAqB,GAAG,MAAM,EAAE,CAS7E;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,EAClD,OAAO,GAAE,gBAAqB,GAC7B,MAAM,EAAE,CAqBV"}
|
package/dist/csp.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What Studio needs in a page's Content Security Policy: its origins in
|
|
3
|
+
* `script-src` (the Studio channel imports Studio's modules from them) and in
|
|
4
|
+
* `frame-ancestors` (its site editor frames the page). The worker adds both to
|
|
5
|
+
* every HTML response's policy (`csp` of `createDecoWorker`); a site that
|
|
6
|
+
* writes its own policy elsewhere passes it through {@link withStudioCsp}.
|
|
7
|
+
* The origins are {@link studioOrigins}: the same list the Studio channel
|
|
8
|
+
* trusts. No framework code: safe in every bundle.
|
|
9
|
+
*/
|
|
10
|
+
import { STUDIO_FRAME_ANCESTORS, studioOrigins } from "./studio.js";
|
|
11
|
+
/** A Studio on this machine, in local development. */
|
|
12
|
+
export const LOOPBACK_ANCESTORS = Object.freeze([
|
|
13
|
+
"http://localhost:*",
|
|
14
|
+
"http://127.0.0.1:*",
|
|
15
|
+
]);
|
|
16
|
+
/** The directives of a policy (`"a; b"` or `["a", "b"]`), trimmed, empty ones dropped. */
|
|
17
|
+
export function cspDirectives(value) {
|
|
18
|
+
if (value === undefined)
|
|
19
|
+
return [];
|
|
20
|
+
const list = typeof value === "string" ? value.split(";") : [...value];
|
|
21
|
+
return list.map((d) => d.trim()).filter(Boolean);
|
|
22
|
+
}
|
|
23
|
+
const nameOf = (directive) => (directive.split(/\s+/, 1)[0] ?? "").toLowerCase();
|
|
24
|
+
const isNone = (values) => values.length === 1 && values[0]?.toLowerCase() === "'none'";
|
|
25
|
+
/** `directive` with each of `sources` it lacks appended; one that is `'none'` stays as is. */
|
|
26
|
+
function withSources(directive, sources) {
|
|
27
|
+
const [name = "", ...values] = directive.split(/\s+/);
|
|
28
|
+
if (isNone(values))
|
|
29
|
+
return directive;
|
|
30
|
+
const have = new Set(values.map((v) => v.toLowerCase()));
|
|
31
|
+
const extra = sources.filter((s) => !have.has(s.toLowerCase()));
|
|
32
|
+
return extra.length ? [name, ...values, ...extra].join(" ") : directive;
|
|
33
|
+
}
|
|
34
|
+
/** The `frame-ancestors` sources: Studio's, the site's own, and loopback in development. */
|
|
35
|
+
export function studioFrameAncestors(options = {}) {
|
|
36
|
+
return [
|
|
37
|
+
...new Set([
|
|
38
|
+
...STUDIO_FRAME_ANCESTORS,
|
|
39
|
+
...studioOrigins(options.studioOrigins),
|
|
40
|
+
...(options.frameAncestors ?? []),
|
|
41
|
+
...(options.dev ? LOOPBACK_ANCESTORS : []),
|
|
42
|
+
]),
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A policy's directives with what Studio needs added: Studio's origins in
|
|
47
|
+
* `script-src` (and `script-src-elem`), so the Studio channel can import
|
|
48
|
+
* Studio's modules, and a `frame-ancestors` with Studio's (when the policy has
|
|
49
|
+
* none). A policy that restricts scripts only through `default-src` gets a
|
|
50
|
+
* `script-src` with `default-src`'s sources plus Studio's, which allows the
|
|
51
|
+
* same scripts as before and Studio's modules. A policy that doesn't restrict
|
|
52
|
+
* scripts, or forbids them all (`'none'`), keeps its scripts as they are.
|
|
53
|
+
* A site's own `frame-ancestors` is kept as is.
|
|
54
|
+
*/
|
|
55
|
+
export function withStudioCsp(directives, options = {}) {
|
|
56
|
+
const origins = studioOrigins(options.studioOrigins);
|
|
57
|
+
let list = cspDirectives(directives);
|
|
58
|
+
if (origins.length) {
|
|
59
|
+
const isScript = (d) => ["script-src", "script-src-elem"].includes(nameOf(d));
|
|
60
|
+
if (list.some(isScript)) {
|
|
61
|
+
list = list.map((d) => (isScript(d) ? withSources(d, origins) : d));
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const fallback = list.find((d) => nameOf(d) === "default-src");
|
|
65
|
+
const values = fallback?.split(/\s+/).slice(1) ?? [];
|
|
66
|
+
if (fallback && !isNone(values)) {
|
|
67
|
+
list.push(withSources(["script-src", ...values].join(" "), origins));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (options.addFrameAncestors !== false && !list.some((d) => nameOf(d) === "frame-ancestors")) {
|
|
72
|
+
list.push(`frame-ancestors ${studioFrameAncestors({ ...options, studioOrigins: origins }).join(" ")}`);
|
|
73
|
+
}
|
|
74
|
+
return list;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=csp.js.map
|
package/dist/csp.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csp.js","sourceRoot":"","sources":["../src/csp.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEpE,sDAAsD;AACtD,MAAM,CAAC,MAAM,kBAAkB,GAAsB,MAAM,CAAC,MAAM,CAAC;IACjE,oBAAoB;IACpB,oBAAoB;CACrB,CAAC,CAAC;AAiBH,0FAA0F;AAC1F,MAAM,UAAU,aAAa,CAAC,KAA6C;IACzE,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IACnC,MAAM,IAAI,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;IACvE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,MAAM,GAAG,CAAC,SAAiB,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;AACzF,MAAM,MAAM,GAAG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AC,KAAK,iBAAiB,CAAC,EAAE,CAAC;QAC9F,IAAI,CAAC,IAAI,CACP,mBAAmB,oBAAoB,CAAC,EAAE,GAAG,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAC5F,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `@decocms/tanstack`: the names and lists the worker, the server helpers and
|
|
3
3
|
* the document share, for a site that needs them in its own code (a route
|
|
4
|
-
* that sets its own headers, a CSP it writes itself
|
|
5
|
-
*
|
|
4
|
+
* that sets its own headers, a CSP it writes itself: `withStudioCsp` adds
|
|
5
|
+
* Studio's origins to it, as the worker does). No framework imports, no
|
|
6
|
+
* state: safe in every bundle.
|
|
6
7
|
*/
|
|
7
8
|
export { ASSIGNMENTS_HEADER } from "./assignments.ts";
|
|
9
|
+
export { type StudioCspOptions, withStudioCsp } from "./csp.ts";
|
|
8
10
|
export { DRAFT_COOKIE, DRAFT_PARAM, draftResponseHeaders, VERSION_HEADER } from "./draft.ts";
|
|
9
|
-
export { isStudioOrigin, STUDIO_FRAME_ANCESTORS, STUDIO_ORIGINS } from "./studio.ts";
|
|
11
|
+
export { DEFAULT_STUDIO_ORIGINS, isStudioOrigin, STUDIO_FRAME_ANCESTORS, STUDIO_ORIGIN, STUDIO_ORIGINS, studioOrigins, } from "./studio.ts";
|
|
10
12
|
export { VISITOR_HEADER } from "./visitor.ts";
|
|
11
13
|
//# 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;;;;;;GAMG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,KAAK,gBAAgB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC7F,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,sBAAsB,EACtB,aAAa,EACb,cAAc,EACd,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `@decocms/tanstack`: the names and lists the worker, the server helpers and
|
|
3
3
|
* the document share, for a site that needs them in its own code (a route
|
|
4
|
-
* that sets its own headers, a CSP it writes itself
|
|
5
|
-
*
|
|
4
|
+
* that sets its own headers, a CSP it writes itself: `withStudioCsp` adds
|
|
5
|
+
* Studio's origins to it, as the worker does). No framework imports, no
|
|
6
|
+
* state: safe in every bundle.
|
|
6
7
|
*/
|
|
7
8
|
export { ASSIGNMENTS_HEADER } from "./assignments.js";
|
|
9
|
+
export { withStudioCsp } from "./csp.js";
|
|
8
10
|
export { DRAFT_COOKIE, DRAFT_PARAM, draftResponseHeaders, VERSION_HEADER } from "./draft.js";
|
|
9
|
-
export { isStudioOrigin, STUDIO_FRAME_ANCESTORS, STUDIO_ORIGINS } from "./studio.js";
|
|
11
|
+
export { DEFAULT_STUDIO_ORIGINS, isStudioOrigin, STUDIO_FRAME_ANCESTORS, STUDIO_ORIGIN, STUDIO_ORIGINS, studioOrigins, } from "./studio.js";
|
|
10
12
|
export { VISITOR_HEADER } from "./visitor.js";
|
|
11
13
|
//# 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;;;;;;GAMG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAyB,aAAa,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC7F,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,sBAAsB,EACtB,aAAa,EACb,cAAc,EACd,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -24,6 +24,13 @@ export interface DecoPreviewProps {
|
|
|
24
24
|
editShortcut?: boolean;
|
|
25
25
|
/** The CSP nonce for the inline scripts, when the site enforces one. */
|
|
26
26
|
nonce?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The Studio origins the Studio channel trusts, each an exact origin.
|
|
29
|
+
* Default: `DECO_STUDIO_ORIGIN` (comma-separated), else Studio's production
|
|
30
|
+
* and staging origins (`DEFAULT_STUDIO_ORIGINS`). A site that sets it sets
|
|
31
|
+
* the worker's `studioOrigins` too, so its CSP allows the same origins.
|
|
32
|
+
*/
|
|
33
|
+
studioOrigins?: readonly string[];
|
|
27
34
|
}
|
|
28
35
|
/**
|
|
29
36
|
* What `DecoDocument` mounts for Studio and draft previews, for a site that
|
|
@@ -31,7 +38,7 @@ export interface DecoPreviewProps {
|
|
|
31
38
|
* draft and CDN segment token published to the browser, `StudioBridge` and
|
|
32
39
|
* `DraftBadge`. Render it once, in the `<body>`.
|
|
33
40
|
*/
|
|
34
|
-
export declare function DecoPreview({ site, editShortcut, nonce }: DecoPreviewProps): import("react").JSX.Element;
|
|
41
|
+
export declare function DecoPreview({ site, editShortcut, nonce, studioOrigins }: DecoPreviewProps): import("react").JSX.Element;
|
|
35
42
|
export interface DecoDocumentProps {
|
|
36
43
|
/** The site's name in Deco (the Studio bridge's shortcut opens the page under it). */
|
|
37
44
|
site: string;
|
|
@@ -54,8 +61,15 @@ export interface DecoDocumentProps {
|
|
|
54
61
|
editShortcut?: boolean;
|
|
55
62
|
/** The CSP nonce for the inline scripts, when the site enforces one. */
|
|
56
63
|
nonce?: string;
|
|
64
|
+
/**
|
|
65
|
+
* The Studio origins the Studio channel trusts, each an exact origin.
|
|
66
|
+
* Default: `DECO_STUDIO_ORIGIN` (comma-separated), else Studio's production
|
|
67
|
+
* and staging origins (`DEFAULT_STUDIO_ORIGINS`). A site that sets it sets
|
|
68
|
+
* the worker's `studioOrigins` too, so its CSP allows the same origins.
|
|
69
|
+
*/
|
|
70
|
+
studioOrigins?: readonly string[];
|
|
57
71
|
/** Rendered after the page (toasts, drawers, analytics). */
|
|
58
72
|
children?: ReactNode;
|
|
59
73
|
}
|
|
60
|
-
export declare function DecoDocument({ site, lang, bodyClassName, account, readyDelay, outlet, editShortcut, nonce, children, }: DecoDocumentProps): import("react").JSX.Element;
|
|
74
|
+
export declare function DecoDocument({ site, lang, bodyClassName, account, readyDelay, outlet, editShortcut, nonce, studioOrigins, children, }: DecoDocumentProps): import("react").JSX.Element;
|
|
61
75
|
//# sourceMappingURL=DecoDocument.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DecoDocument.d.ts","sourceRoot":"","sources":["../../src/react/DecoDocument.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DecoDocument.d.ts","sourceRoot":"","sources":["../../src/react/DecoDocument.tsx"],"names":[],"mappings":"AAyBA,OAAO,EAAE,KAAK,SAAS,EAA+B,MAAM,OAAO,CAAC;AAKpE,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,YAAY,CAAC,EAAE,OAAO,CAAC;KACxB;CACF;AAED,MAAM,WAAW,uBAAuB;IACtC,2FAA2F;IAC3F,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,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 -12,15 +12,20 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
|
|
|
12
12
|
* - `StudioBridge` (in Studio's frame it answers Studio's origins,
|
|
13
13
|
* `STUDIO_ORIGINS`; outside it, "." opens the page in Studio's editor, with
|
|
14
14
|
* the page's `pathTemplate` from the route's loader data) and `DraftBadge`
|
|
15
|
-
* (only on a draft page outside Studio's frame), from `@decocms/blocks/preview
|
|
15
|
+
* (only on a draft page outside Studio's frame), from `@decocms/blocks/preview`;
|
|
16
|
+
* - `StudioChannel` (every page, production included: framed by one of
|
|
17
|
+
* Studio's origins, `studioOrigins` / `DECO_STUDIO_ORIGIN` / Studio's
|
|
18
|
+
* production and staging origins, each exact, it loads the editor's own
|
|
19
|
+
* modules from that origin; otherwise it does nothing). The worker adds the
|
|
20
|
+
* same origins to the page's CSP `script-src` and `frame-ancestors`.
|
|
16
21
|
*
|
|
17
22
|
* A site that keeps its own document renders `DecoPreview` in its `<body>`
|
|
18
23
|
* for the bridge, the badge and the draft they read.
|
|
19
24
|
*/
|
|
20
|
-
import { DraftBadge, StudioBridge } from "@decocms/blocks/preview";
|
|
25
|
+
import { DraftBadge, StudioBridge, StudioChannel } from "@decocms/blocks/preview";
|
|
21
26
|
import { HeadContent, Outlet, ScriptOnce, Scripts, useRouterState } from "@tanstack/react-router";
|
|
22
27
|
import { useEffect, useRef, useState } from "react";
|
|
23
|
-
import { STUDIO_ORIGINS } from "../studio.js";
|
|
28
|
+
import { STUDIO_ORIGINS, studioOrigins } from "../studio.js";
|
|
24
29
|
import { pageValues, publishScript } from "./pageValues.js";
|
|
25
30
|
import { DATA_EVENT_OBSERVER, eventsBootstrap, PROGRESS_CSS } from "./scripts.js";
|
|
26
31
|
/** A loading bar at the top of the page during client-side navigation. */
|
|
@@ -61,12 +66,12 @@ function studioPageOf(matches) {
|
|
|
61
66
|
}
|
|
62
67
|
return undefined;
|
|
63
68
|
}
|
|
64
|
-
/** The Studio bridge, with the page on screen, and the badge for the request's draft. */
|
|
65
|
-
function StudioPieces({ site, editShortcut, nonce, draft, draftUnavailable, }) {
|
|
69
|
+
/** The Studio bridge, with the page on screen, the Studio channel, and the badge for the request's draft. */
|
|
70
|
+
function StudioPieces({ site, editShortcut, nonce, studioOrigins: origins, draft, draftUnavailable, }) {
|
|
66
71
|
// Two primitives, so a navigation that keeps the page doesn't re-render the document.
|
|
67
72
|
const pathTemplate = useRouterState({ select: (s) => studioPageOf(s.matches)?.pathTemplate });
|
|
68
73
|
const pageId = useRouterState({ select: (s) => studioPageOf(s.matches)?.id });
|
|
69
|
-
return (_jsxs(_Fragment, { children: [_jsx(StudioBridge, { site: site, trustedOrigins: STUDIO_ORIGINS, editShortcut: editShortcut, page: { pathTemplate, id: pageId }, nonce: nonce }), _jsx(DraftBadge, { pointer: draft ?? null, unavailable: draftUnavailable })] }));
|
|
74
|
+
return (_jsxs(_Fragment, { children: [_jsx(StudioBridge, { site: site, trustedOrigins: STUDIO_ORIGINS, editShortcut: editShortcut, page: { pathTemplate, id: pageId }, nonce: nonce }), _jsx(StudioChannel, { studioOrigins: studioOrigins(origins), nonce: nonce }), _jsx(DraftBadge, { pointer: draft ?? null, unavailable: draftUnavailable })] }));
|
|
70
75
|
}
|
|
71
76
|
/**
|
|
72
77
|
* What `DecoDocument` mounts for Studio and draft previews, for a site that
|
|
@@ -74,12 +79,12 @@ function StudioPieces({ site, editShortcut, nonce, draft, draftUnavailable, }) {
|
|
|
74
79
|
* draft and CDN segment token published to the browser, `StudioBridge` and
|
|
75
80
|
* `DraftBadge`. Render it once, in the `<body>`.
|
|
76
81
|
*/
|
|
77
|
-
export function DecoPreview({ site, editShortcut, nonce }) {
|
|
82
|
+
export function DecoPreview({ site, editShortcut, nonce, studioOrigins }) {
|
|
78
83
|
const values = pageValues();
|
|
79
84
|
const publish = publishScript(values);
|
|
80
|
-
return (_jsxs(_Fragment, { children: [publish && (_jsx("script", { nonce: nonce, suppressHydrationWarning: true, dangerouslySetInnerHTML: { __html: publish } })), _jsx(StudioPieces, { site: site, editShortcut: editShortcut, nonce: nonce, draft: values.draft, draftUnavailable: values.draftUnavailable })] }));
|
|
85
|
+
return (_jsxs(_Fragment, { children: [publish && (_jsx("script", { nonce: nonce, suppressHydrationWarning: true, dangerouslySetInnerHTML: { __html: publish } })), _jsx(StudioPieces, { site: site, editShortcut: editShortcut, nonce: nonce, studioOrigins: studioOrigins, draft: values.draft, draftUnavailable: values.draftUnavailable })] }));
|
|
81
86
|
}
|
|
82
|
-
export function DecoDocument({ site, lang = "en", bodyClassName = "bg-base-200 text-base-content", account = "", readyDelay = 500, outlet = "main", editShortcut, nonce, children, }) {
|
|
87
|
+
export function DecoDocument({ site, lang = "en", bodyClassName = "bg-base-200 text-base-content", account = "", readyDelay = 500, outlet = "main", editShortcut, nonce, studioOrigins, children, }) {
|
|
83
88
|
// Pages wait for this signal before running work that must follow hydration.
|
|
84
89
|
useEffect(() => {
|
|
85
90
|
const id = setTimeout(() => {
|
|
@@ -91,6 +96,6 @@ export function DecoDocument({ site, lang = "en", bodyClassName = "bg-base-200 t
|
|
|
91
96
|
const values = pageValues();
|
|
92
97
|
const publish = publishScript(values);
|
|
93
98
|
const Outer = outlet;
|
|
94
|
-
return (_jsxs("html", { lang: lang, "data-theme": "light", suppressHydrationWarning: true, children: [_jsxs("head", { children: [_jsx(HeadContent, {}), publish && (_jsx("script", { nonce: nonce, suppressHydrationWarning: true, dangerouslySetInnerHTML: { __html: publish } }))] }), _jsxs("body", { className: bodyClassName, suppressHydrationWarning: true, children: [_jsx(ScriptOnce, { children: eventsBootstrap(account) }), _jsx(NavigationProgress, {}), _jsx(Outer, { children: _jsx(StableOutlet, {}) }), children, _jsx(StudioPieces, { site: site, editShortcut: editShortcut, nonce: nonce, draft: values.draft, draftUnavailable: values.draftUnavailable }), _jsx(ScriptOnce, { children: DATA_EVENT_OBSERVER }), _jsx(Scripts, {})] })] }));
|
|
99
|
+
return (_jsxs("html", { lang: lang, "data-theme": "light", suppressHydrationWarning: true, children: [_jsxs("head", { children: [_jsx(HeadContent, {}), publish && (_jsx("script", { nonce: nonce, suppressHydrationWarning: true, dangerouslySetInnerHTML: { __html: publish } }))] }), _jsxs("body", { className: bodyClassName, suppressHydrationWarning: true, children: [_jsx(ScriptOnce, { children: eventsBootstrap(account) }), _jsx(NavigationProgress, {}), _jsx(Outer, { children: _jsx(StableOutlet, {}) }), children, _jsx(StudioPieces, { site: site, editShortcut: editShortcut, nonce: nonce, studioOrigins: studioOrigins, draft: values.draft, draftUnavailable: values.draftUnavailable }), _jsx(ScriptOnce, { children: DATA_EVENT_OBSERVER }), _jsx(Scripts, {})] })] }));
|
|
95
100
|
}
|
|
96
101
|
//# sourceMappingURL=DecoDocument.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DecoDocument.js","sourceRoot":"","sources":["../../src/react/DecoDocument.tsx"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"DecoDocument.js","sourceRoot":"","sources":["../../src/react/DecoDocument.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAClG,OAAO,EAAkB,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAalF,0EAA0E;AAC1E,MAAM,UAAU,kBAAkB,CAAC,EACjC,KAAK,GAAG,8CAA8C,GAC9B;IACxB,MAAM,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AAC,CAAC;QAClD,CAAC,EAAE,UAAU,CAAC,CAAC;QACf,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;IAChC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IAEjB,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;IAC5B,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,KAAK,GAAG,MAAM,CAAC;IAErB,OAAO,CACL,gBAAM,IAAI,EAAE,IAAI,gBAAa,OAAO,EAAC,wBAAwB,mBAC3D,2BACE,KAAC,WAAW,KAAG,EACd,OAAO,IAAI,CACV,iBACE,KAAK,EAAE,KAAK,EACZ,wBAAwB,QACxB,uBAAuB,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,GAC5C,CACH,IACI,EACP,gBAAM,SAAS,EAAE,aAAa,EAAE,wBAAwB,mBACtD,KAAC,UAAU,cAAE,eAAe,CAAC,OAAO,CAAC,GAAc,EACnD,KAAC,kBAAkB,KAAG,EACtB,KAAC,KAAK,cACJ,KAAC,YAAY,KAAG,GACV,EACP,QAAQ,EACT,KAAC,YAAY,IACX,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,KAAK,EACZ,aAAa,EAAE,aAAa,EAC5B,KAAK,EAAE,MAAM,CAAC,KAAK,EACnB,gBAAgB,EAAE,MAAM,CAAC,gBAAgB,GACzC,EACF,KAAC,UAAU,cAAE,mBAAmB,GAAc,EAC9C,KAAC,OAAO,KAAG,IACN,IACF,CACR,CAAC;AACJ,CAAC"}
|
package/dist/studio.d.ts
CHANGED
|
@@ -19,6 +19,26 @@ export declare const STUDIO_ORIGINS: readonly string[];
|
|
|
19
19
|
* development (`http://localhost:*`), where a Studio runs on the same machine.
|
|
20
20
|
*/
|
|
21
21
|
export declare const STUDIO_FRAME_ANCESTORS: readonly string[];
|
|
22
|
+
/** Studio's production origin. */
|
|
23
|
+
export declare const STUDIO_ORIGIN = "https://studio.decocms.com";
|
|
24
|
+
/**
|
|
25
|
+
* The exact origins a page trusts for the Studio channel by default, and adds
|
|
26
|
+
* to its CSP (`script-src`, `frame-ancestors`): Studio's production and
|
|
27
|
+
* staging origins. No wildcard: each one is compared exactly.
|
|
28
|
+
*/
|
|
29
|
+
export declare const DEFAULT_STUDIO_ORIGINS: readonly string[];
|
|
30
|
+
/**
|
|
31
|
+
* The Studio origins the page trusts: the Studio channel accepts messages and
|
|
32
|
+
* modules from them, and the binding adds them to the page's CSP `script-src`
|
|
33
|
+
* and `frame-ancestors`. The binding option when given (an empty list turns
|
|
34
|
+
* the channel off), else the `DECO_STUDIO_ORIGIN` environment variable, a
|
|
35
|
+
* comma-separated list (a local or staging Studio, such as
|
|
36
|
+
* `http://localhost:3000`; read where `process.env` exists, so on the
|
|
37
|
+
* server), else {@link DEFAULT_STUDIO_ORIGINS}. Each entry must be an exact
|
|
38
|
+
* http(s) origin; any other value (a path, a wildcard, a CSP keyword) is
|
|
39
|
+
* dropped, so the list never widens the CSP beyond origins.
|
|
40
|
+
*/
|
|
41
|
+
export declare function studioOrigins(option?: readonly string[]): readonly string[];
|
|
22
42
|
/**
|
|
23
43
|
* Whether `origin` (a `MessageEvent.origin`, an `Origin` header) is one of
|
|
24
44
|
* {@link STUDIO_ORIGINS}: `https`, the default port, and `decocms.com` or a
|
package/dist/studio.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"studio.d.ts","sourceRoot":"","sources":["../src/studio.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAK1C,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAIlD,CAAC;AAEH;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAazE"}
|
|
1
|
+
{"version":3,"file":"studio.d.ts","sourceRoot":"","sources":["../src/studio.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAK1C,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAIlD,CAAC;AAEH,kCAAkC;AAClC,eAAO,MAAM,aAAa,+BAA+B,CAAC;AAE1D;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAGlD,CAAC;AAkBH;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,MAAM,EAAE,CAK3E;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAazE"}
|
package/dist/studio.js
CHANGED
|
@@ -28,6 +28,53 @@ export const STUDIO_FRAME_ANCESTORS = Object.freeze([
|
|
|
28
28
|
...STUDIO_ORIGINS,
|
|
29
29
|
"https://*.deco.studio",
|
|
30
30
|
]);
|
|
31
|
+
/** Studio's production origin. */
|
|
32
|
+
export const STUDIO_ORIGIN = "https://studio.decocms.com";
|
|
33
|
+
/**
|
|
34
|
+
* The exact origins a page trusts for the Studio channel by default, and adds
|
|
35
|
+
* to its CSP (`script-src`, `frame-ancestors`): Studio's production and
|
|
36
|
+
* staging origins. No wildcard: each one is compared exactly.
|
|
37
|
+
*/
|
|
38
|
+
export const DEFAULT_STUDIO_ORIGINS = Object.freeze([
|
|
39
|
+
STUDIO_ORIGIN,
|
|
40
|
+
"https://studio-stg.decocms.com",
|
|
41
|
+
]);
|
|
42
|
+
/** `value` as an exact http(s) origin (`https://host[:port]`, a trailing `/` dropped; no wildcard), or `""`. */
|
|
43
|
+
function asOrigin(value) {
|
|
44
|
+
if (typeof value !== "string")
|
|
45
|
+
return "";
|
|
46
|
+
const trimmed = value.trim();
|
|
47
|
+
try {
|
|
48
|
+
const url = new URL(trimmed);
|
|
49
|
+
if (url.protocol !== "https:" && url.protocol !== "http:")
|
|
50
|
+
return "";
|
|
51
|
+
// A host name or an IP address: a URL parser accepts `*` in a host, which a
|
|
52
|
+
// CSP source would read as a wildcard.
|
|
53
|
+
if (!/^(\[[0-9a-f:.]+\]|[a-z0-9_.-]+)$/.test(url.hostname))
|
|
54
|
+
return "";
|
|
55
|
+
return trimmed === url.origin || trimmed === `${url.origin}/` ? url.origin : "";
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return "";
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The Studio origins the page trusts: the Studio channel accepts messages and
|
|
63
|
+
* modules from them, and the binding adds them to the page's CSP `script-src`
|
|
64
|
+
* and `frame-ancestors`. The binding option when given (an empty list turns
|
|
65
|
+
* the channel off), else the `DECO_STUDIO_ORIGIN` environment variable, a
|
|
66
|
+
* comma-separated list (a local or staging Studio, such as
|
|
67
|
+
* `http://localhost:3000`; read where `process.env` exists, so on the
|
|
68
|
+
* server), else {@link DEFAULT_STUDIO_ORIGINS}. Each entry must be an exact
|
|
69
|
+
* http(s) origin; any other value (a path, a wildcard, a CSP keyword) is
|
|
70
|
+
* dropped, so the list never widens the CSP beyond origins.
|
|
71
|
+
*/
|
|
72
|
+
export function studioOrigins(option) {
|
|
73
|
+
const env = globalThis.process
|
|
74
|
+
?.env?.DECO_STUDIO_ORIGIN;
|
|
75
|
+
const list = option ?? (env?.trim() ? env.split(",") : DEFAULT_STUDIO_ORIGINS);
|
|
76
|
+
return [...new Set(list.map(asOrigin).filter(Boolean))];
|
|
77
|
+
}
|
|
31
78
|
/**
|
|
32
79
|
* Whether `origin` (a `MessageEvent.origin`, an `Origin` header) is one of
|
|
33
80
|
* {@link STUDIO_ORIGINS}: `https`, the default port, and `decocms.com` or a
|
package/dist/studio.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"studio.js","sourceRoot":"","sources":["../src/studio.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAsB,MAAM,CAAC,MAAM,CAAC;IAC7D,4BAA4B;IAC5B,gCAAgC;IAChC,qBAAqB;IACrB,uBAAuB;CACxB,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAsB,MAAM,CAAC,MAAM,CAAC;IACrE,QAAQ;IACR,GAAG,cAAc;IACjB,uBAAuB;CACxB,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,MAAiC;IAC9D,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,EAAE;QAAE,OAAO,KAAK,CAAC;IAC9D,IAAI,GAAQ,CAAC;IACb,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;IACD,8EAA8E;IAC9E,yBAAyB;IACzB,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,KAAK,EAAE;QAAE,OAAO,KAAK,CAAC;IACxF,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC;IAC1B,OAAO,IAAI,KAAK,aAAa,IAAI,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;AACjE,CAAC"}
|
|
1
|
+
{"version":3,"file":"studio.js","sourceRoot":"","sources":["../src/studio.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAsB,MAAM,CAAC,MAAM,CAAC;IAC7D,4BAA4B;IAC5B,gCAAgC;IAChC,qBAAqB;IACrB,uBA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,CAAC;CACxB;
|
|
1
|
+
{"version":3,"file":"assignments.d.ts","sourceRoot":"","sources":["../../src/worker/assignments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,MAAM,WAAW,kBAAmB,SAAQ,kBAAkB;IAC5D,wDAAwD;IACxD,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAiCD;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,EACxB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,kBAAkB,CAAC,CAa7B;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA0BpF;AASD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,WAAW,EAAE,kBAAkB,GAAG,MAAM,CAStE"}
|
|
@@ -7,19 +7,13 @@ function isRecord(value) {
|
|
|
7
7
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
* missing
|
|
10
|
+
* The saved `block` resolved, each name `true` or `false`; none when it is
|
|
11
|
+
* missing. Whether it exists comes from the index (`NOT_FOUND`, which is no
|
|
12
|
+
* error to report), with no body listed.
|
|
12
13
|
*/
|
|
13
|
-
async function saves(client, type) {
|
|
14
|
-
const [list] = await client.list(type);
|
|
15
|
-
return (list?.length ?? 0) > 0;
|
|
16
|
-
}
|
|
17
|
-
/** The saved `block` resolved, each name `true` or `false`; none when it is missing. */
|
|
18
14
|
async function decided(client, spec) {
|
|
19
15
|
const out = record();
|
|
20
16
|
try {
|
|
21
|
-
if (!(await saves(client, spec.type)))
|
|
22
|
-
return out;
|
|
23
17
|
const [value] = await client.resolve(spec.block);
|
|
24
18
|
if (!isRecord(value))
|
|
25
19
|
return out;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assignments.js","sourceRoot":"","sources":["../../src/worker/assignments.ts"],"names":[],"mappings":"AAyBA,MAAM,WAAW,GAAG,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,eAAe,EAAW,CAAC;AAC7E,MAAM,SAAS,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAW,CAAC;AAIpE,kEAAkE;AAClE,MAAM,UAAU,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAElF,MAAM,MAAM,GAAG,GAAgB,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAgB,CAAC;AAErE,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED
|
|
1
|
+
{"version":3,"file":"assignments.js","sourceRoot":"","sources":["../../src/worker/assignments.ts"],"names":[],"mappings":"AAyBA,MAAM,WAAW,GAAG,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,eAAe,EAAW,CAAC;AAC7E,MAAM,SAAS,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAW,CAAC;AAIpE,kEAAkE;AAClE,MAAM,UAAU,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC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C/C,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IACjD,IAAI,KAAK,CAAC,MAAM;QAAE,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACjD,IAAI,SAAS,CAAC,MAAM;QAAE,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACzD,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC"}
|
package/dist/worker/cache.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* version every key carries, and the version (draft or old release) a request
|
|
5
5
|
* renders. The worker caches nothing itself.
|
|
6
6
|
*/
|
|
7
|
-
import type
|
|
7
|
+
import { type CMS } from "@decocms/blocks";
|
|
8
8
|
/**
|
|
9
9
|
* Whether a request may be served from or stored in a shared cache at all:
|
|
10
10
|
* a GET of the current release (`version` `null`: never a preview, a draft
|
|
@@ -22,8 +22,16 @@ export declare function isCacheable(request: Pick<Request, "method" | "url" | "h
|
|
|
22
22
|
* `<build>.<content revision>`, for every cache key: a new build or a
|
|
23
23
|
* published release gets new entries at once. The build alone when the
|
|
24
24
|
* revision can't be read.
|
|
25
|
+
*
|
|
26
|
+
* With `url` (the request's, `page.url`), the revision is the one the page
|
|
27
|
+
* renders. Right after a publish, a page whose new blocks aren't cached yet is
|
|
28
|
+
* served on the previous index while they load (the previous-index rule):
|
|
29
|
+
* this pins the same way, on the page the URL routes to (for a server
|
|
30
|
+
* function, the page its payload loads), so a page rendered on the previous
|
|
31
|
+
* index is never stored under the new revision. Without `url`, the revision a
|
|
32
|
+
* request that reads no page pins.
|
|
25
33
|
*/
|
|
26
|
-
export declare function cacheVersion(cms: Pick<CMS, "forRelease">, buildHash: string): Promise<string>;
|
|
34
|
+
export declare function cacheVersion(cms: Pick<CMS, "forRelease">, buildHash: string, url?: URL): Promise<string>;
|
|
27
35
|
/**
|
|
28
36
|
* The version a request renders as the worker decided it (a Studio link's
|
|
29
37
|
* draft pointer or release SHA, after the host allowlist), from the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/worker/cache.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/worker/cache.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,KAAK,GAAG,EAAc,MAAM,iBAAiB,CAAC;AAKvD;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,QAAQ,GAAG,KAAK,GAAG,SAAS,CAAC,EACpD,MAAM,EAAE;IAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,GAChD,OAAO,CAST;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,YAAY,CAChC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,YAAY,CAAC,EAC5B,SAAS,EAAE,MAAM,EACjB,GAAG,CAAC,EAAE,GAAG,GACR,OAAO,CAAC,MAAM,CAAC,CAejB;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,GAAG,MAAM,GAAG,IAAI,CAE/E"}
|
package/dist/worker/cache.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a site needs to build its own page cache in front of the worker (the
|
|
3
|
+
* README's worker-entry recipe): whether a request may be cached at all, the
|
|
4
|
+
* version every key carries, and the version (draft or old release) a request
|
|
5
|
+
* renders. The worker caches nothing itself.
|
|
6
|
+
*/
|
|
7
|
+
import { matchRoute } from "@decocms/blocks";
|
|
1
8
|
import { VERSION_HEADER } from "../draft.js";
|
|
2
9
|
import { hasDraftSignal } from "./drafts.js";
|
|
10
|
+
import { serverFnPagePath } from "./serverFn.js";
|
|
3
11
|
/**
|
|
4
12
|
* Whether a request may be served from or stored in a shared cache at all:
|
|
5
13
|
* a GET of the current release (`version` `null`: never a preview, a draft
|
|
@@ -21,11 +29,27 @@ export function isCacheable(request, inputs) {
|
|
|
21
29
|
* `<build>.<content revision>`, for every cache key: a new build or a
|
|
22
30
|
* published release gets new entries at once. The build alone when the
|
|
23
31
|
* revision can't be read.
|
|
32
|
+
*
|
|
33
|
+
* With `url` (the request's, `page.url`), the revision is the one the page
|
|
34
|
+
* renders. Right after a publish, a page whose new blocks aren't cached yet is
|
|
35
|
+
* served on the previous index while they load (the previous-index rule):
|
|
36
|
+
* this pins the same way, on the page the URL routes to (for a server
|
|
37
|
+
* function, the page its payload loads), so a page rendered on the previous
|
|
38
|
+
* index is never stored under the new revision. Without `url`, the revision a
|
|
39
|
+
* request that reads no page pins.
|
|
24
40
|
*/
|
|
25
|
-
export async function cacheVersion(cms, buildHash) {
|
|
41
|
+
export async function cacheVersion(cms, buildHash, url) {
|
|
26
42
|
let revision = "";
|
|
27
43
|
try {
|
|
28
|
-
|
|
44
|
+
const client = cms.forRelease();
|
|
45
|
+
if (url !== undefined) {
|
|
46
|
+
const [routes] = await client.routes();
|
|
47
|
+
const match = matchRoute(serverFnPagePath(url) ?? url, { routes: routes ?? [] });
|
|
48
|
+
// Pins on the page, as the page's own client does.
|
|
49
|
+
if (match.kind === "match")
|
|
50
|
+
client.prefetch(match.entry.name);
|
|
51
|
+
}
|
|
52
|
+
revision = await client.revision();
|
|
29
53
|
}
|
|
30
54
|
catch {
|
|
31
55
|
// The content didn't load: key on the build only.
|
package/dist/worker/cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/worker/cache.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../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CAAC;QAChE,CAAC;QACD,QAAQ,GAAG,MAAM,MAAM,CAAC,QAAQ,EAAE,CAAC;IACrC,CAAC;IAAC,MAAM,CAAC;QACP,kDAAkD;IACpD,CAAC;IACD,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,OAAiC;IAC9D,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,IAAI,CAAC;AACrD,CAAC"}
|
package/dist/worker/drafts.d.ts
CHANGED
|
@@ -60,7 +60,8 @@ export interface DraftDecision {
|
|
|
60
60
|
* request first checks for the latest release, once (`cms.checkRelease()`),
|
|
61
61
|
* and the host check and every draft read share that check. A draft
|
|
62
62
|
* pointer is read once before the page renders (`forDraft(...).revision()`,
|
|
63
|
-
* the same read the page makes
|
|
63
|
+
* the same read the page makes: every draft read under the request's release
|
|
64
|
+
* check shares one read of the draft's files): a draft that can't
|
|
64
65
|
* be read gives the release and `unavailable`, never an error page.
|
|
65
66
|
*/
|
|
66
67
|
export declare function decideDraft(cms: Pick<CMS, "readVersion" | "forDraft" | "checkRelease">, request: Request): Promise<DraftDecision>;
|