@decocms/tanstack 8.5.2 → 8.6.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 +9 -6
- package/dist/draft.d.ts.map +1 -1
- package/dist/draft.js +10 -7
- 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/scope/server.d.ts +1 -1
- package/dist/scope/server.d.ts.map +1 -1
- package/dist/server/index.d.ts +35 -8
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +41 -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 +33 -0
- package/dist/worker/cache.d.ts.map +1 -0
- package/dist/worker/cache.js +41 -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 +27 -48
- package/dist/worker/drafts.d.ts.map +1 -1
- package/dist/worker/drafts.js +33 -88
- package/dist/worker/drafts.js.map +1 -1
- package/dist/worker/index.d.ts +77 -51
- package/dist/worker/index.d.ts.map +1 -1
- package/dist/worker/index.js +141 -360
- 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 +10 -7
- package/src/index.ts +3 -1
- package/src/scope/server.ts +1 -1
- package/src/server/index.ts +51 -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 +57 -0
- package/src/worker/cookies.ts +1 -27
- package/src/worker/drafts.ts +38 -98
- package/src/worker/index.ts +213 -425
- 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/worker/index.d.ts
CHANGED
|
@@ -5,29 +5,51 @@
|
|
|
5
5
|
*
|
|
6
6
|
* - `/deco/_liveness` answers `OK`; v7's admin paths (`/deco/*`, `/live/*`,
|
|
7
7
|
* `/.decofile`) answer 404.
|
|
8
|
-
* -
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* - Versions: the host allowlist (`./drafts.ts`) for a Studio link's version
|
|
9
|
+
* (a draft, or a published release by its commit SHA, with the preview's
|
|
10
|
+
* moment and switched tests and campaigns), the draft cookie, the
|
|
11
|
+
* `x-deco-version` request header the page reads, and on the response
|
|
12
|
+
* `no-store`, `Vary: Cookie` and `noindex`.
|
|
11
13
|
* - The CMS redirects, before any route.
|
|
12
|
-
* -
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* - No page cache: caching is the site's (`pageCache`, the README's
|
|
15
|
+
* worker-entry recipe), with the helpers it needs exported here
|
|
16
|
+
* (`assignmentsKey`, `cacheVersion`, `isCacheable`, …).
|
|
17
|
+
* The worker calls `pageCache` only for a request `isCacheable` accepts,
|
|
18
|
+
* never for a preview, and adds the visitor's cookie after it, so a stored
|
|
19
|
+
* copy never carries one. A page request with `Authorization` is never
|
|
20
|
+
* handed to it and answers `private, no-cache, no-store`. A response with no
|
|
21
|
+
* `CDN-Cache-Control` tells the CDN `no-store`, at one exit.
|
|
17
22
|
* - Security headers and `frame-ancestors` for Studio; immutable fingerprinted
|
|
18
23
|
* assets; one `Set-Cookie` per cookie; `x-page-status`.
|
|
24
|
+
* - The visitor: on a page or server-function request, `readVisitor` from
|
|
25
|
+
* `@decocms/blocks/experiments` (the `deco_segment` cookie, or a new
|
|
26
|
+
* visitor), handed to the app on `x-deco-visitor`; the cookie is sent on a
|
|
27
|
+
* first visit only, never from a preview.
|
|
28
|
+
* - What the request's content gives it, decided once per request: each test
|
|
29
|
+
* and campaign on or off (`readAssignments`: `cms.client({ visitor,
|
|
30
|
+
* version, date, experiments, campaigns })` with the visitor and the Studio
|
|
31
|
+
* link's version, moment and switched tests and campaigns), handed to the
|
|
32
|
+
* site's `pageCache` (`page.assignments`, for its key) and to the app on
|
|
33
|
+
* `x-deco-assignments` (`contentClient` builds
|
|
34
|
+
* `cms.client({ version, experiments, campaigns })` from it, deciding
|
|
35
|
+
* nothing again).
|
|
19
36
|
* - `http.server.request.duration` for every request, to the CMS's telemetry
|
|
20
37
|
* (`recordServerRequest` from `@decocms/blocks/metrics`), labelled with the route's template, the
|
|
21
|
-
* method, the status class, the cache decision
|
|
22
|
-
* when the CMS has no
|
|
38
|
+
* method, the status class, the cache decision (the `X-Cache` the site's
|
|
39
|
+
* `pageCache` answered with) and the device; nothing when the CMS has no
|
|
40
|
+
* telemetry.
|
|
23
41
|
*/
|
|
24
42
|
import { type CMS } from "@decocms/blocks";
|
|
25
|
-
import { type
|
|
43
|
+
import { type Visitor } from "@decocms/blocks/experiments";
|
|
44
|
+
import { type RequestAssignments } from "./assignments.ts";
|
|
26
45
|
import { type CspOptions } from "./security.ts";
|
|
27
|
-
|
|
28
|
-
export {
|
|
46
|
+
import { type Device } from "./segment.ts";
|
|
47
|
+
export { CSEG_PARAM, DEGRADED_HEADER } from "../shared.ts";
|
|
48
|
+
export { assignmentsKey, liveAssignmentKeys, type RequestAssignments, readAssignments, } from "./assignments.ts";
|
|
49
|
+
export { cacheVersion, isCacheable, requestVersion } from "./cache.ts";
|
|
29
50
|
export type { CspOptions } from "./security.ts";
|
|
30
|
-
export type
|
|
51
|
+
export { type Device, detectDevice, type Segment, segmentKey, segmentToken } from "./segment.ts";
|
|
52
|
+
export { isServerFnPath, serverFnPagePath } from "./serverFn.ts";
|
|
31
53
|
/** The part of Cloudflare's `ExecutionContext` the worker uses. */
|
|
32
54
|
export interface ExecutionContextLike {
|
|
33
55
|
waitUntil(promise: Promise<unknown>): void;
|
|
@@ -40,42 +62,56 @@ export interface ExecutionContextLike {
|
|
|
40
62
|
export interface ServerEntry {
|
|
41
63
|
fetch(request: Request, env?: any, ctx?: any): Response | Promise<Response>;
|
|
42
64
|
}
|
|
43
|
-
/**
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
65
|
+
/**
|
|
66
|
+
* A page or server-function request the site's `pageCache` may answer from
|
|
67
|
+
* its own cache: always one `isCacheable` accepts (a GET of the current
|
|
68
|
+
* release, never a preview).
|
|
69
|
+
*/
|
|
70
|
+
export interface PageRequest<Env = unknown> {
|
|
71
|
+
/** The request as the app gets it: the visitor and the assignments on their headers. */
|
|
72
|
+
request: Request;
|
|
73
|
+
url: URL;
|
|
74
|
+
/** The visitor the worker read (`readVisitor`). */
|
|
75
|
+
visitor: Visitor;
|
|
76
|
+
/**
|
|
77
|
+
* Each test and campaign on or off for this request, as the worker decided
|
|
78
|
+
* them and the page renders them: key the cache on `assignmentsKey(page.assignments)`.
|
|
79
|
+
*/
|
|
80
|
+
assignments: RequestAssignments;
|
|
81
|
+
/** The request's device class, from its user agent. */
|
|
82
|
+
device: Device;
|
|
83
|
+
env: Env;
|
|
84
|
+
ctx: ExecutionContextLike;
|
|
85
|
+
/**
|
|
86
|
+
* Renders the page: the app's response, with `x-page-status` applied and
|
|
87
|
+
* without the visitor's cookie (the worker adds it to whatever `pageCache`
|
|
88
|
+
* answers). `csegToken` is the `__cseg` token `DecoDocument` publishes and
|
|
89
|
+
* `decoServerFnFetch` sends back on the page's navigation data.
|
|
90
|
+
*/
|
|
91
|
+
render(scope?: {
|
|
92
|
+
csegToken?: string;
|
|
93
|
+
}): Promise<Response>;
|
|
53
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* The site's page cache: answers a page from its own cache, or calls
|
|
97
|
+
* `page.render()`. Set `X-Cache` (`HIT`, `STALE-HIT`, `STALE-ERROR`, `MISS`)
|
|
98
|
+
* on the answer and the request's metric counts it.
|
|
99
|
+
*/
|
|
100
|
+
export type PageCache<Env = unknown> = (page: PageRequest<Env>) => Promise<Response>;
|
|
54
101
|
export interface DecoWorkerOptions<Env = unknown> {
|
|
55
102
|
serverEntry: ServerEntry;
|
|
56
|
-
/** The site's CMS: drafts, the
|
|
103
|
+
/** The site's CMS: drafts, the CMS redirects, the page templates of the request metric. */
|
|
57
104
|
cms: CMS;
|
|
58
|
-
/**
|
|
59
|
-
site: string;
|
|
60
|
-
/** The build's id, in every cache key: the commit sha (`decoTanstack()` defines `__BUILD_HASH__`). */
|
|
61
|
-
buildHash: string;
|
|
62
|
-
/** Local development (`import.meta.env.DEV`): no edge cache, `no-cache` pages, loopback may frame the site. */
|
|
105
|
+
/** Local development (`import.meta.env.DEV`): `pageCache` is never called, loopback may frame the site. */
|
|
63
106
|
dev?: boolean;
|
|
64
107
|
/** The site's Content-Security-Policy. Studio's `frame-ancestors` is always added. */
|
|
65
108
|
csp?: CspOptions;
|
|
66
109
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* must never share a cached response (a signed-in shopper).
|
|
110
|
+
* The site's own page cache (the example worker entry the README links), called for
|
|
111
|
+
* every page and server-function request `isCacheable` accepts. Without
|
|
112
|
+
* it nothing is cached: every request renders.
|
|
71
113
|
*/
|
|
72
|
-
|
|
73
|
-
/** Changes to the default cache profiles (`DEFAULT_CACHE_PROFILES`). */
|
|
74
|
-
cacheProfiles?: CacheProfileOverrides;
|
|
75
|
-
/** Cookies a cached response may set (stripped from the stored copy). Default: `_deco_bucket`. */
|
|
76
|
-
safeCookies?: readonly string[];
|
|
77
|
-
/** Turns on `POST /_cache/purge` with `Authorization: Bearer <token>`. */
|
|
78
|
-
purgeToken?: (env: Env) => string | undefined;
|
|
114
|
+
pageCache?: PageCache<Env>;
|
|
79
115
|
/**
|
|
80
116
|
* `Link: rel=preload` hints on every HTML response the app renders. A
|
|
81
117
|
* `routes` response carries none: it is another origin's page (a proxied
|
|
@@ -85,14 +121,6 @@ export interface DecoWorkerOptions<Env = unknown> {
|
|
|
85
121
|
styles?: readonly string[];
|
|
86
122
|
fonts?: readonly string[];
|
|
87
123
|
};
|
|
88
|
-
/**
|
|
89
|
-
* v7's `DECO_ALLOWED_PREVIEW_HOSTS`: replaces the site's declared preview
|
|
90
|
-
* hosts (the `CMS` block's), exact hosts with their port
|
|
91
|
-
* (`["localhost:5173"]` for local development); the site's Deco hosts stay
|
|
92
|
-
* allowed. `"none"` turns draft previews off on every host. Without it and
|
|
93
|
-
* without hosts in the `CMS` block, drafts preview only on the Deco hosts.
|
|
94
|
-
*/
|
|
95
|
-
previewHosts?: readonly string[] | "none";
|
|
96
124
|
/**
|
|
97
125
|
* The escape hatch, after the CMS redirects and before anything else: answer
|
|
98
126
|
* a request yourself (a commerce proxy, a sitemap, an A/B route) or return
|
|
@@ -101,8 +129,6 @@ export interface DecoWorkerOptions<Env = unknown> {
|
|
|
101
129
|
* but without the `preload` hints.
|
|
102
130
|
*/
|
|
103
131
|
routes?: (request: Request, env: Env, ctx: ExecutionContextLike) => Response | null | undefined | Promise<Response | null | undefined>;
|
|
104
|
-
/** Called once per page or server-function request (D3: no exporter is built in). */
|
|
105
|
-
onCache?: (event: CacheEvent) => void;
|
|
106
132
|
}
|
|
107
133
|
export interface DecoWorker<Env> {
|
|
108
134
|
fetch(request: Request, env: Env, ctx: ExecutionContextLike): Promise<Response>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/worker/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/worker/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,OAAO,EAAE,KAAK,GAAG,EAAyC,MAAM,iBAAiB,CAAC;AAClF,OAAO,EAAiC,KAAK,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAO1F,OAAO,EAAE,KAAK,kBAAkB,EAAmB,MAAM,kBAAkB,CAAC;AAI5E,OAAO,EAAE,KAAK,UAAU,EAAuB,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,cAAc,CAAC;AAGzD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,KAAK,kBAAkB,EACvB,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACvE,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,KAAK,MAAM,EAAE,YAAY,EAAE,KAAK,OAAO,EAAE,UAAU,EAAE,YAAY,EA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