@decocms/tanstack 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 +35 -8
- package/dist/assignments.d.ts +31 -0
- package/dist/assignments.d.ts.map +1 -0
- package/dist/assignments.js +61 -0
- package/dist/assignments.js.map +1 -0
- package/dist/draft.d.ts +28 -9
- package/dist/draft.d.ts.map +1 -1
- package/dist/draft.js +30 -11
- package/dist/draft.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/react/DecoDocument.d.ts.map +1 -1
- package/dist/react/DecoDocument.js +4 -4
- package/dist/react/DecoDocument.js.map +1 -1
- package/dist/react/pageValues.d.ts +3 -0
- package/dist/react/pageValues.d.ts.map +1 -1
- package/dist/react/pageValues.js +13 -4
- package/dist/react/pageValues.js.map +1 -1
- package/dist/scope/server.d.ts +6 -1
- package/dist/scope/server.d.ts.map +1 -1
- package/dist/scope/server.js.map +1 -1
- package/dist/server/index.d.ts +37 -8
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +45 -9
- package/dist/server/index.js.map +1 -1
- package/dist/shared.d.ts +5 -5
- package/dist/shared.js +5 -5
- package/dist/start/index.d.ts +3 -3
- package/dist/start/index.js +3 -3
- package/dist/visitor.d.ts +14 -0
- package/dist/visitor.d.ts.map +1 -0
- package/dist/visitor.js +14 -0
- package/dist/visitor.js.map +1 -0
- package/dist/worker/assignments.d.ts +44 -0
- package/dist/worker/assignments.d.ts.map +1 -0
- package/dist/worker/assignments.js +114 -0
- package/dist/worker/assignments.js.map +1 -0
- package/dist/worker/cache.d.ts +35 -0
- package/dist/worker/cache.d.ts.map +1 -0
- package/dist/worker/cache.js +45 -0
- package/dist/worker/cache.js.map +1 -0
- package/dist/worker/cookies.d.ts +1 -5
- package/dist/worker/cookies.d.ts.map +1 -1
- package/dist/worker/cookies.js +1 -26
- package/dist/worker/cookies.js.map +1 -1
- package/dist/worker/drafts.d.ts +54 -46
- package/dist/worker/drafts.d.ts.map +1 -1
- package/dist/worker/drafts.js +88 -88
- package/dist/worker/drafts.js.map +1 -1
- package/dist/worker/index.d.ts +82 -51
- package/dist/worker/index.d.ts.map +1 -1
- package/dist/worker/index.js +197 -372
- package/dist/worker/index.js.map +1 -1
- package/dist/worker/segment.d.ts +7 -6
- package/dist/worker/segment.d.ts.map +1 -1
- package/dist/worker/segment.js +6 -5
- package/dist/worker/segment.js.map +1 -1
- package/dist/worker/serverFn.d.ts +12 -0
- package/dist/worker/serverFn.d.ts.map +1 -0
- package/dist/worker/serverFn.js +44 -0
- package/dist/worker/serverFn.js.map +1 -0
- package/package.json +3 -3
- package/src/assignments.ts +77 -0
- package/src/draft.ts +34 -11
- package/src/index.ts +3 -1
- package/src/react/DecoDocument.tsx +20 -4
- package/src/react/pageValues.ts +12 -4
- package/src/scope/server.ts +6 -1
- package/src/server/index.ts +57 -12
- package/src/shared.ts +5 -5
- package/src/start/index.ts +3 -3
- package/src/visitor.ts +14 -0
- package/src/worker/assignments.ts +146 -0
- package/src/worker/cache.ts +61 -0
- package/src/worker/cookies.ts +1 -27
- package/src/worker/drafts.ts +113 -98
- package/src/worker/index.ts +276 -436
- package/src/worker/segment.ts +7 -7
- package/src/worker/serverFn.ts +36 -0
- package/dist/worker/cacheProfiles.d.ts +0 -43
- package/dist/worker/cacheProfiles.d.ts.map +0 -1
- package/dist/worker/cacheProfiles.js +0 -162
- package/dist/worker/cacheProfiles.js.map +0 -1
- package/src/worker/cacheProfiles.ts +0 -180
package/dist/server/index.js
CHANGED
|
@@ -1,16 +1,51 @@
|
|
|
1
|
+
import { parseVisitor } from "@decocms/blocks/experiments";
|
|
1
2
|
import { getRequest, setResponseHeader } from "@tanstack/react-start/server";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import { ASSIGNMENTS_HEADER, parseAssignments } from "../assignments.js";
|
|
4
|
+
import { RELEASE_CHECK_HEADER, VERSION_HEADER } from "../draft.js";
|
|
5
|
+
import { VISITOR_HEADER } from "../visitor.js";
|
|
6
|
+
/**
|
|
7
|
+
* The version `request` renders (a Studio link's draft pointer or release
|
|
8
|
+
* SHA, checked by the worker), or `null` for the current release.
|
|
9
|
+
*/
|
|
10
|
+
export function requestVersion(request = getRequest()) {
|
|
11
|
+
return request.headers.get(VERSION_HEADER) || null;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The visitor the worker read for `request`, or `null` when there is none (a
|
|
15
|
+
* request that didn't come through `createDecoWorker`).
|
|
16
|
+
*/
|
|
17
|
+
export function requestVisitor(request = getRequest()) {
|
|
18
|
+
return parseVisitor(request.headers.get(VISITOR_HEADER));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Each test and campaign on or off as the worker decided them for `request`,
|
|
22
|
+
* or `null` when it decided none (a request that didn't come through
|
|
23
|
+
* `createDecoWorker`).
|
|
24
|
+
*/
|
|
25
|
+
export function requestAssignments(request = getRequest()) {
|
|
26
|
+
return parseAssignments(request.headers.get(ASSIGNMENTS_HEADER));
|
|
6
27
|
}
|
|
7
28
|
/**
|
|
8
|
-
* The content client for a request:
|
|
9
|
-
* `
|
|
29
|
+
* The content client for a request: `cms.client({ version, experiments,
|
|
30
|
+
* campaigns })` with what the worker decided, so the page renders the tests
|
|
31
|
+
* and campaigns the worker keyed its cache on and a preview reads its draft
|
|
32
|
+
* or old release. The visitor rides along (`client.visitor`) but decides
|
|
33
|
+
* nothing the worker already did; without the worker's decisions (a request
|
|
34
|
+
* that didn't come through it) the visitor decides. Create one per request.
|
|
35
|
+
* Without `request`, the request being served (`getRequest()`).
|
|
10
36
|
*/
|
|
11
37
|
export function contentClient(cms, request = getRequest()) {
|
|
12
|
-
const
|
|
13
|
-
|
|
38
|
+
const decided = requestAssignments(request);
|
|
39
|
+
const version = requestVersion(request);
|
|
40
|
+
// The worker's release check for this draft request: the draft waits for it, never one of its own.
|
|
41
|
+
const releaseCheck = version === null ? null : request.headers.get(RELEASE_CHECK_HEADER);
|
|
42
|
+
return cms.client({
|
|
43
|
+
version,
|
|
44
|
+
...(releaseCheck ? { releaseCheck } : {}),
|
|
45
|
+
visitor: requestVisitor(request),
|
|
46
|
+
experiments: decided?.experiments,
|
|
47
|
+
campaigns: decided?.campaigns,
|
|
48
|
+
});
|
|
14
49
|
}
|
|
15
50
|
/** True when the browser called a server function over HTTP; false while a document renders. */
|
|
16
51
|
export function isServerFnCall(request = getRequest()) {
|
|
@@ -18,7 +53,8 @@ export function isServerFnCall(request = getRequest()) {
|
|
|
18
53
|
}
|
|
19
54
|
/**
|
|
20
55
|
* Marks a server function's response as per-visitor (`Cache-Control: private,
|
|
21
|
-
* no-store`):
|
|
56
|
+
* no-store`): a site's page cache never stores it (the example worker entry the README links) and
|
|
57
|
+
* the CDN never keeps it. Only when
|
|
22
58
|
* the browser called the function over HTTP; while a document renders the
|
|
23
59
|
* function is a plain call and the header would land on the page.
|
|
24
60
|
*/
|
package/dist/server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,YAAY,EAAgB,MAAM,6BAA6B,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAA2B,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAClG,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,OAAO,GAAY,UAAU,EAAE;IAC5D,OAAO,OAAO,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;;;;GAMG;AACH,MAAM,UAAU,WAAW;IACzB,IAAI,CAAC,cAAc,EAAE;QAAE,OAAO;IAC9B,iBAAiB,CAAC,eAAe,EAAE,mBAAmB,CAAC,CAAC;AAC1D,CAAC;AAED,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/shared.d.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* The query parameter `decoServerFnFetch` adds to a server-function URL: the
|
|
7
|
-
* page's CDN segment token, which
|
|
8
|
-
* cache the response. `__d` is avoided: v7 used it as a debug flag.
|
|
7
|
+
* page's CDN segment token, which a site's page cache checks before it lets
|
|
8
|
+
* the CDN cache the response. `__d` is avoided: v7 used it as a debug flag.
|
|
9
9
|
*/
|
|
10
10
|
export declare const CSEG_PARAM = "__cseg";
|
|
11
11
|
/** The `window` property the page publishes the token on. */
|
|
@@ -18,9 +18,9 @@ export declare const CSEG_GLOBAL = "__DECO_CSEG";
|
|
|
18
18
|
*/
|
|
19
19
|
export declare const PAGE_STATUS_HEADER = "x-page-status";
|
|
20
20
|
/**
|
|
21
|
-
* The response header a page sets when a loader it depends on failed:
|
|
22
|
-
*
|
|
23
|
-
* has one.
|
|
21
|
+
* The response header a page sets when a loader it depends on failed: a
|
|
22
|
+
* site's page cache never stores that response, and serves a stale copy
|
|
23
|
+
* instead when it has one (the example worker entry the README links).
|
|
24
24
|
*/
|
|
25
25
|
export declare const DEGRADED_HEADER = "x-deco-degraded";
|
|
26
26
|
//# sourceMappingURL=shared.d.ts.map
|
package/dist/shared.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* The query parameter `decoServerFnFetch` adds to a server-function URL: the
|
|
7
|
-
* page's CDN segment token, which
|
|
8
|
-
* cache the response. `__d` is avoided: v7 used it as a debug flag.
|
|
7
|
+
* page's CDN segment token, which a site's page cache checks before it lets
|
|
8
|
+
* the CDN cache the response. `__d` is avoided: v7 used it as a debug flag.
|
|
9
9
|
*/
|
|
10
10
|
export const CSEG_PARAM = "__cseg";
|
|
11
11
|
/** The `window` property the page publishes the token on. */
|
|
@@ -18,9 +18,9 @@ export const CSEG_GLOBAL = "__DECO_CSEG";
|
|
|
18
18
|
*/
|
|
19
19
|
export const PAGE_STATUS_HEADER = "x-page-status";
|
|
20
20
|
/**
|
|
21
|
-
* The response header a page sets when a loader it depends on failed:
|
|
22
|
-
*
|
|
23
|
-
* has one.
|
|
21
|
+
* The response header a page sets when a loader it depends on failed: a
|
|
22
|
+
* site's page cache never stores that response, and serves a stale copy
|
|
23
|
+
* instead when it has one (the example worker entry the README links).
|
|
24
24
|
*/
|
|
25
25
|
export const DEGRADED_HEADER = "x-deco-degraded";
|
|
26
26
|
//# sourceMappingURL=shared.js.map
|
package/dist/start/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `fetch` for server-function calls: adds the CDN segment token the page
|
|
3
3
|
* published (`__cseg`), so the CDN can cache client-side navigation data. The
|
|
4
|
-
* token is a hint: the
|
|
5
|
-
*
|
|
6
|
-
* a plain `fetch`.
|
|
4
|
+
* token is a hint: the site's page cache (the example worker entry the README links)
|
|
5
|
+
* recomputes it from the request and lets the CDN keep the response only when
|
|
6
|
+
* they match. With no token on the page, a plain `fetch`.
|
|
7
7
|
*/
|
|
8
8
|
export declare const decoServerFnFetch: typeof fetch;
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/start/index.js
CHANGED
|
@@ -16,9 +16,9 @@ function publishedToken() {
|
|
|
16
16
|
/**
|
|
17
17
|
* `fetch` for server-function calls: adds the CDN segment token the page
|
|
18
18
|
* published (`__cseg`), so the CDN can cache client-side navigation data. The
|
|
19
|
-
* token is a hint: the
|
|
20
|
-
*
|
|
21
|
-
* a plain `fetch`.
|
|
19
|
+
* token is a hint: the site's page cache (the example worker entry the README links)
|
|
20
|
+
* recomputes it from the request and lets the CDN keep the response only when
|
|
21
|
+
* they match. With no token on the page, a plain `fetch`.
|
|
22
22
|
*/
|
|
23
23
|
export const decoServerFnFetch = (input, init) => {
|
|
24
24
|
// TanStack's server-function fetcher passes the URL as a string; anything else goes through as is.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the worker hands the app the visitor: the request header it sets on a
|
|
3
|
+
* page or server-function request once it read the visitor (`readVisitor`
|
|
4
|
+
* from `@decocms/blocks/experiments`, a new one on a first visit). The worker
|
|
5
|
+
* writes it (`./worker/index.ts`); the app reads it (`contentClient` from
|
|
6
|
+
* `@decocms/tanstack/server`). No imports, no state: safe in every bundle.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The request header carrying the visitor, in its stored form (the
|
|
10
|
+
* `deco_segment` cookie's value, `serializeVisitor`). The worker removes any
|
|
11
|
+
* copy that arrives from outside, so a client can't send one itself.
|
|
12
|
+
*/
|
|
13
|
+
export declare const VISITOR_HEADER = "x-deco-visitor";
|
|
14
|
+
//# sourceMappingURL=visitor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visitor.d.ts","sourceRoot":"","sources":["../src/visitor.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;GAIG;AACH,eAAO,MAAM,cAAc,mBAAmB,CAAC"}
|
package/dist/visitor.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the worker hands the app the visitor: the request header it sets on a
|
|
3
|
+
* page or server-function request once it read the visitor (`readVisitor`
|
|
4
|
+
* from `@decocms/blocks/experiments`, a new one on a first visit). The worker
|
|
5
|
+
* writes it (`./worker/index.ts`); the app reads it (`contentClient` from
|
|
6
|
+
* `@decocms/tanstack/server`). No imports, no state: safe in every bundle.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The request header carrying the visitor, in its stored form (the
|
|
10
|
+
* `deco_segment` cookie's value, `serializeVisitor`). The worker removes any
|
|
11
|
+
* copy that arrives from outside, so a client can't send one itself.
|
|
12
|
+
*/
|
|
13
|
+
export const VISITOR_HEADER = "x-deco-visitor";
|
|
14
|
+
//# sourceMappingURL=visitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visitor.js","sourceRoot":"","sources":["../src/visitor.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A request's assignments (what its content gives it), decided once by the
|
|
3
|
+
* worker: the version it reads (a Studio link's draft or release SHA), each
|
|
4
|
+
* test of the saved `experiments` block on or off for its visitor and each
|
|
5
|
+
* campaign of the saved `campaigns` block running or not at its date, with a
|
|
6
|
+
* preview's switched tests and campaigns on top. The worker hands them to the
|
|
7
|
+
* page (`x-deco-assignments`) and to the site's `pageCache`
|
|
8
|
+
* (`page.assignments`), whose key carries them (`assignmentsKey`). Two
|
|
9
|
+
* requests with the same assignments render the same content, so they share
|
|
10
|
+
* a cache entry; the visitor id itself is never in the key, or every visitor
|
|
11
|
+
* would miss.
|
|
12
|
+
*
|
|
13
|
+
* Blocks decides (`cms.client({ visitor, version, … })`); this only reads
|
|
14
|
+
* the answers. A site without either block has no assignments and keys as
|
|
15
|
+
* before.
|
|
16
|
+
*/
|
|
17
|
+
import type { ClientOptions, CMS } from "@decocms/blocks";
|
|
18
|
+
import type { DecidedAssignments } from "../assignments.ts";
|
|
19
|
+
export interface RequestAssignments extends DecidedAssignments {
|
|
20
|
+
/** The version read, `null` for the current release. */
|
|
21
|
+
version: string | null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The assignments of one request: `cms.client(options)` (the version, the
|
|
25
|
+
* visitor, the date and a preview's switched tests and campaigns, as
|
|
26
|
+
* `cms.readVersion` reads them) resolving `experiments` and `campaigns`.
|
|
27
|
+
* Missing blocks (or content that doesn't load) give none, never an error.
|
|
28
|
+
*/
|
|
29
|
+
export declare function readAssignments(cms: Pick<CMS, "client">, options: ClientOptions): Promise<RequestAssignments>;
|
|
30
|
+
/**
|
|
31
|
+
* Every assignments key a live request can carry now, for a site's purge: each
|
|
32
|
+
* subset of the tests in the saved `experiments` block on (the empty one
|
|
33
|
+
* included), with the campaigns running now and with none. Previews are
|
|
34
|
+
* never cached, so no version. A site without either block has one: `""`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function liveAssignmentKeys(cms: Pick<CMS, "client">): Promise<string[]>;
|
|
37
|
+
/**
|
|
38
|
+
* The assignments as one stable string for a cache key:
|
|
39
|
+
* `v=<version>|x=<tests on>|c=<campaigns running>`, names sorted and
|
|
40
|
+
* URL-encoded, empty parts left out; `""` for none. The names that are off
|
|
41
|
+
* aren't in it: within one content revision they are the rest.
|
|
42
|
+
*/
|
|
43
|
+
export declare function assignmentsKey(assignments: RequestAssignments): string;
|
|
44
|
+
//# sourceMappingURL=assignments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AA0CD;;;;;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"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
const EXPERIMENTS = { block: "experiments", type: "split-traffic" };
|
|
2
|
+
const CAMPAIGNS = { block: "campaigns", type: "calendar" };
|
|
3
|
+
/** Plain code-unit order, the same on every server and locale. */
|
|
4
|
+
const byCodeUnit = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
5
|
+
const record = () => Object.create(null);
|
|
6
|
+
function isRecord(value) {
|
|
7
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Whether the content saves a block of `type`: listing never fails on a
|
|
11
|
+
* missing block, so a site without tests or campaigns reports no error.
|
|
12
|
+
*/
|
|
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
|
+
async function decided(client, spec) {
|
|
19
|
+
const out = record();
|
|
20
|
+
try {
|
|
21
|
+
if (!(await saves(client, spec.type)))
|
|
22
|
+
return out;
|
|
23
|
+
const [value] = await client.resolve(spec.block);
|
|
24
|
+
if (!isRecord(value))
|
|
25
|
+
return out;
|
|
26
|
+
for (const name of Object.keys(value).sort(byCodeUnit))
|
|
27
|
+
out[name] = value[name] === true;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// Content that doesn't load gives no assignments.
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The assignments of one request: `cms.client(options)` (the version, the
|
|
36
|
+
* visitor, the date and a preview's switched tests and campaigns, as
|
|
37
|
+
* `cms.readVersion` reads them) resolving `experiments` and `campaigns`.
|
|
38
|
+
* Missing blocks (or content that doesn't load) give none, never an error.
|
|
39
|
+
*/
|
|
40
|
+
export async function readAssignments(cms, options) {
|
|
41
|
+
const version = typeof options.version === "string" ? options.version : null;
|
|
42
|
+
let client;
|
|
43
|
+
try {
|
|
44
|
+
client = cms.client(options);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return { version, experiments: record(), campaigns: record() };
|
|
48
|
+
}
|
|
49
|
+
const [experiments, campaigns] = await Promise.all([
|
|
50
|
+
decided(client, EXPERIMENTS),
|
|
51
|
+
decided(client, CAMPAIGNS),
|
|
52
|
+
]);
|
|
53
|
+
return { version, experiments, campaigns };
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Every assignments key a live request can carry now, for a site's purge: each
|
|
57
|
+
* subset of the tests in the saved `experiments` block on (the empty one
|
|
58
|
+
* included), with the campaigns running now and with none. Previews are
|
|
59
|
+
* never cached, so no version. A site without either block has one: `""`.
|
|
60
|
+
*/
|
|
61
|
+
export async function liveAssignmentKeys(cms) {
|
|
62
|
+
let client;
|
|
63
|
+
try {
|
|
64
|
+
client = cms.client();
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return [""];
|
|
68
|
+
}
|
|
69
|
+
const [saved, campaigns] = await Promise.all([
|
|
70
|
+
decided(client, EXPERIMENTS),
|
|
71
|
+
decided(client, CAMPAIGNS),
|
|
72
|
+
]);
|
|
73
|
+
const tests = Object.keys(saved);
|
|
74
|
+
const running = Object.keys(campaigns).some((name) => campaigns[name] === true);
|
|
75
|
+
const campaignSets = running ? [campaigns, record()] : [record()];
|
|
76
|
+
const keys = [];
|
|
77
|
+
// Subsets by bitmask, tests in sorted order: 2^tests of them.
|
|
78
|
+
for (let mask = 0; mask < 2 ** tests.length; mask++) {
|
|
79
|
+
const experiments = record();
|
|
80
|
+
tests.forEach((name, i) => {
|
|
81
|
+
experiments[name] = Math.floor(mask / 2 ** i) % 2 === 1;
|
|
82
|
+
});
|
|
83
|
+
for (const set of campaignSets) {
|
|
84
|
+
keys.push(assignmentsKey({ version: null, experiments, campaigns: set }));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return keys;
|
|
88
|
+
}
|
|
89
|
+
/** The names that are on, sorted. */
|
|
90
|
+
function onNames(assignments) {
|
|
91
|
+
return Object.keys(assignments)
|
|
92
|
+
.filter((name) => assignments[name] === true)
|
|
93
|
+
.sort(byCodeUnit);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The assignments as one stable string for a cache key:
|
|
97
|
+
* `v=<version>|x=<tests on>|c=<campaigns running>`, names sorted and
|
|
98
|
+
* URL-encoded, empty parts left out; `""` for none. The names that are off
|
|
99
|
+
* aren't in it: within one content revision they are the rest.
|
|
100
|
+
*/
|
|
101
|
+
export function assignmentsKey(assignments) {
|
|
102
|
+
const list = (names) => names.map(encodeURIComponent).join(",");
|
|
103
|
+
const parts = [];
|
|
104
|
+
if (assignments.version)
|
|
105
|
+
parts.push(`v=${encodeURIComponent(assignments.version)}`);
|
|
106
|
+
const tests = onNames(assignments.experiments);
|
|
107
|
+
const campaigns = onNames(assignments.campaigns);
|
|
108
|
+
if (tests.length)
|
|
109
|
+
parts.push(`x=${list(tests)}`);
|
|
110
|
+
if (campaigns.length)
|
|
111
|
+
parts.push(`c=${list(campaigns)}`);
|
|
112
|
+
return parts.join("|");
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=assignments.js.map
|
|
@@ -0,0 +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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AAU,CAAC,CAAC;AACtB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,WAA+B;IAC5D,MAAM,IAAI,GAAG,CAAC,KAAe,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1E,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,WAAW,CAAC,OAAO;QAAE,KAAK,CAAC,IAAI,CAAC,KAAK,kBAAkB,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACpF,MAAM,KAAK,GAAG,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;IAC/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"}
|
|
@@ -0,0 +1,35 @@
|
|
|
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 type { CMS } from "@decocms/blocks";
|
|
8
|
+
/**
|
|
9
|
+
* Whether a request may be served from or stored in a shared cache at all:
|
|
10
|
+
* a GET of the current release (`version` `null`: never a preview, a draft
|
|
11
|
+
* or an old release), carrying no draft signal at all (no `?__draft=`, `off`
|
|
12
|
+
* included, and no draft cookie: a preview always renders), outside local
|
|
13
|
+
* development, without `Authorization`, and not one of TanStack Start's own
|
|
14
|
+
* `/_build` files. The worker calls a
|
|
15
|
+
* site's `pageCache` only for these.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isCacheable(request: Pick<Request, "method" | "url" | "headers">, inputs: {
|
|
18
|
+
version: string | null;
|
|
19
|
+
dev?: boolean;
|
|
20
|
+
}): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* `<build>.<content revision>`, for every cache key: a new build or a
|
|
23
|
+
* published release gets new entries at once. The build alone when the
|
|
24
|
+
* revision can't be read.
|
|
25
|
+
*/
|
|
26
|
+
export declare function cacheVersion(cms: Pick<CMS, "forRelease">, buildHash: string): Promise<string>;
|
|
27
|
+
/**
|
|
28
|
+
* The version a request renders as the worker decided it (a Studio link's
|
|
29
|
+
* draft pointer or release SHA, after the host allowlist), from the
|
|
30
|
+
* `x-deco-version` header it sets; `null` for the current release. For the
|
|
31
|
+
* request a `routes` handler or `pageCache` gets: the worker removes any copy
|
|
32
|
+
* that arrives from outside.
|
|
33
|
+
*/
|
|
34
|
+
export declare function requestVersion(request: Pick<Request, "headers">): string | null;
|
|
35
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/worker/cache.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAI3C;;;;;;;;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;;;;GAIG;AACH,wBAAsB,YAAY,CAChC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,YAAY,CAAC,EAC5B,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC,CAQjB;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,GAAG,MAAM,GAAG,IAAI,CAE/E"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { VERSION_HEADER } from "../draft.js";
|
|
2
|
+
import { hasDraftSignal } from "./drafts.js";
|
|
3
|
+
/**
|
|
4
|
+
* Whether a request may be served from or stored in a shared cache at all:
|
|
5
|
+
* a GET of the current release (`version` `null`: never a preview, a draft
|
|
6
|
+
* or an old release), carrying no draft signal at all (no `?__draft=`, `off`
|
|
7
|
+
* included, and no draft cookie: a preview always renders), outside local
|
|
8
|
+
* development, without `Authorization`, and not one of TanStack Start's own
|
|
9
|
+
* `/_build` files. The worker calls a
|
|
10
|
+
* site's `pageCache` only for these.
|
|
11
|
+
*/
|
|
12
|
+
export function isCacheable(request, inputs) {
|
|
13
|
+
return (request.method === "GET" &&
|
|
14
|
+
inputs.version === null &&
|
|
15
|
+
inputs.dev !== true &&
|
|
16
|
+
!request.headers.has("authorization") &&
|
|
17
|
+
!hasDraftSignal(request) &&
|
|
18
|
+
!new URL(request.url).pathname.startsWith("/_build"));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* `<build>.<content revision>`, for every cache key: a new build or a
|
|
22
|
+
* published release gets new entries at once. The build alone when the
|
|
23
|
+
* revision can't be read.
|
|
24
|
+
*/
|
|
25
|
+
export async function cacheVersion(cms, buildHash) {
|
|
26
|
+
let revision = "";
|
|
27
|
+
try {
|
|
28
|
+
revision = await cms.forRelease().revision();
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// The content didn't load: key on the build only.
|
|
32
|
+
}
|
|
33
|
+
return [buildHash, revision].filter(Boolean).join(".");
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The version a request renders as the worker decided it (a Studio link's
|
|
37
|
+
* draft pointer or release SHA, after the host allowlist), from the
|
|
38
|
+
* `x-deco-version` header it sets; `null` for the current release. For the
|
|
39
|
+
* request a `routes` handler or `pageCache` gets: the worker removes any copy
|
|
40
|
+
* that arrives from outside.
|
|
41
|
+
*/
|
|
42
|
+
export function requestVersion(request) {
|
|
43
|
+
return request.headers.get(VERSION_HEADER) || null;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/worker/cache.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CACzB,OAAoD,EACpD,MAAiD;IAEjD,OAAO,CACL,OAAO,CAAC,MAAM,KAAK,KAAK;QACxB,MAAM,CAAC,OAAO,KAAK,IAAI;QACvB,MAAM,CAAC,GAAG,KAAK,IAAI;QACnB,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;QACrC,CAAC,cAAc,CAAC,OAAO,CAAC;QACxB,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CACrD,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,GAA4B,EAC5B,SAAiB;IAEjB,IAAI,QAAQ,GAAG,EAAE,CAAC;IAClB,IAAI,CAAC;QACH,QAAQ,GAAG,MAAM,GAAG,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE,CAAC;IAC/C,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/cookies.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
/** Set-Cookie handling:
|
|
2
|
-
/** Whether every cookie the response sets is one a shared (cached) response may set. */
|
|
3
|
-
export declare function hasOnlySafeCookies(response: Response, safe: ReadonlySet<string>): boolean;
|
|
4
|
-
/** A copy for the cache without the safe cookies; the visitor still gets them. */
|
|
5
|
-
export declare function withoutSafeCookies(response: Response, safe: ReadonlySet<string>): Response;
|
|
1
|
+
/** Set-Cookie handling: one header per cookie. */
|
|
6
2
|
/**
|
|
7
3
|
* A Set-Cookie's identity: name + Domain + Path, the way the browser keys its
|
|
8
4
|
* cookie jar (RFC 6265 §5.3), so two headers that differ in scope address two
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../../src/worker/cookies.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../../src/worker/cookies.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAElD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAc3D;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAQzD"}
|
package/dist/worker/cookies.js
CHANGED
|
@@ -1,29 +1,4 @@
|
|
|
1
|
-
/** Set-Cookie handling:
|
|
2
|
-
function cookieName(setCookie) {
|
|
3
|
-
const eq = setCookie.indexOf("=");
|
|
4
|
-
return eq > 0 ? setCookie.slice(0, eq).trim() : "";
|
|
5
|
-
}
|
|
6
|
-
/** Whether every cookie the response sets is one a shared (cached) response may set. */
|
|
7
|
-
export function hasOnlySafeCookies(response, safe) {
|
|
8
|
-
return response.headers.getSetCookie().every((c) => {
|
|
9
|
-
const name = cookieName(c);
|
|
10
|
-
return name === "" || safe.has(name);
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
/** A copy for the cache without the safe cookies; the visitor still gets them. */
|
|
14
|
-
export function withoutSafeCookies(response, safe) {
|
|
15
|
-
const copy = response.clone();
|
|
16
|
-
const cookies = response.headers.getSetCookie();
|
|
17
|
-
if (cookies.length === 0)
|
|
18
|
-
return copy;
|
|
19
|
-
copy.headers.delete("set-cookie");
|
|
20
|
-
for (const c of cookies) {
|
|
21
|
-
const name = cookieName(c);
|
|
22
|
-
if (name && !safe.has(name))
|
|
23
|
-
copy.headers.append("set-cookie", c);
|
|
24
|
-
}
|
|
25
|
-
return copy;
|
|
26
|
-
}
|
|
1
|
+
/** Set-Cookie handling: one header per cookie. */
|
|
27
2
|
/**
|
|
28
3
|
* A Set-Cookie's identity: name + Domain + Path, the way the browser keys its
|
|
29
4
|
* cookie jar (RFC 6265 §5.3), so two headers that differ in scope address two
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookies.js","sourceRoot":"","sources":["../../src/worker/cookies.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"cookies.js","sourceRoot":"","sources":["../../src/worker/cookies.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAElD;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,SAAiB;IACjD,MAAM,CAAC,SAAS,GAAG,EAAE,EAAE,GAAG,KAAK,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACxD,MAAM,EAAE,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAClC,MAAM,IAAI,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IA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