@decocms/tanstack 8.1.0-next.0 → 8.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -0
- package/dist/draft.d.ts +33 -0
- package/dist/draft.d.ts.map +1 -0
- package/dist/draft.js +41 -0
- package/dist/draft.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/react/DecoDocument.d.ts +61 -0
- package/dist/react/DecoDocument.d.ts.map +1 -0
- package/dist/react/DecoDocument.js +96 -0
- package/dist/react/DecoDocument.js.map +1 -0
- package/dist/react/Image.d.ts +96 -0
- package/dist/react/Image.d.ts.map +1 -0
- package/dist/react/Image.js +79 -0
- package/dist/react/Image.js.map +1 -0
- package/dist/react/index.d.ts +7 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +7 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/pageValues.d.ts +10 -0
- package/dist/react/pageValues.d.ts.map +1 -0
- package/dist/react/pageValues.js +29 -0
- package/dist/react/pageValues.js.map +1 -0
- package/dist/react/scripts.d.ts +14 -0
- package/dist/react/scripts.d.ts.map +1 -0
- package/dist/react/scripts.js +96 -0
- package/dist/react/scripts.js.map +1 -0
- package/dist/router/index.d.ts +38 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +60 -0
- package/dist/router/index.js.map +1 -0
- package/dist/scope/browser.d.ts +11 -0
- package/dist/scope/browser.d.ts.map +1 -0
- package/dist/scope/browser.js +8 -0
- package/dist/scope/browser.js.map +1 -0
- package/dist/scope/server.d.ts +13 -0
- package/dist/scope/server.d.ts.map +1 -0
- package/dist/scope/server.js +26 -0
- package/dist/scope/server.js.map +1 -0
- package/dist/server/index.d.ts +27 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +31 -0
- package/dist/server/index.js.map +1 -0
- package/dist/shared.d.ts +26 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +26 -0
- package/dist/shared.js.map +1 -0
- package/dist/start/index.d.ts +9 -0
- package/dist/start/index.d.ts.map +1 -0
- package/dist/start/index.js +33 -0
- package/dist/start/index.js.map +1 -0
- package/dist/studio.d.ts +28 -0
- package/dist/studio.d.ts.map +1 -0
- package/dist/studio.js +53 -0
- package/dist/studio.js.map +1 -0
- package/dist/vite/index.d.ts +15 -0
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +95 -0
- package/dist/vite/index.js.map +1 -0
- package/dist/worker/cacheProfiles.d.ts +43 -0
- package/dist/worker/cacheProfiles.d.ts.map +1 -0
- package/dist/worker/cacheProfiles.js +162 -0
- package/dist/worker/cacheProfiles.js.map +1 -0
- package/dist/worker/cookies.d.ts +20 -0
- package/dist/worker/cookies.d.ts.map +1 -0
- package/dist/worker/cookies.js +69 -0
- package/dist/worker/cookies.js.map +1 -0
- package/dist/worker/drafts.d.ts +59 -0
- package/dist/worker/drafts.d.ts.map +1 -0
- package/dist/worker/drafts.js +140 -0
- package/dist/worker/drafts.js.map +1 -0
- package/dist/worker/index.d.ts +111 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +618 -0
- package/dist/worker/index.js.map +1 -0
- package/dist/worker/security.d.ts +14 -0
- package/dist/worker/security.d.ts.map +1 -0
- package/dist/worker/security.js +48 -0
- package/dist/worker/security.js.map +1 -0
- package/dist/worker/segment.d.ts +21 -0
- package/dist/worker/segment.d.ts.map +1 -0
- package/dist/worker/segment.js +43 -0
- package/dist/worker/segment.js.map +1 -0
- package/package.json +85 -37
- package/src/draft.ts +43 -0
- package/src/index.ts +8 -61
- package/src/react/DecoDocument.tsx +234 -0
- package/src/react/Image.tsx +213 -0
- package/src/react/index.ts +24 -0
- package/src/react/pageValues.ts +35 -0
- package/src/react/scripts.ts +98 -0
- package/src/router/index.ts +80 -0
- package/src/scope/browser.ts +18 -0
- package/src/scope/server.ts +37 -0
- package/src/server/index.ts +43 -0
- package/src/shared.ts +29 -0
- package/src/start/index.ts +31 -0
- package/src/studio.ts +52 -0
- package/src/vite/index.ts +105 -0
- package/src/worker/cacheProfiles.ts +180 -0
- package/src/worker/cookies.ts +65 -0
- package/src/worker/drafts.ts +157 -0
- package/src/worker/index.ts +784 -0
- package/src/worker/security.ts +63 -0
- package/src/worker/segment.ts +49 -0
- package/src/__conformance__/observability.test.ts +0 -221
- package/src/cms/kvBlockSource.test.ts +0 -82
- package/src/cms/kvBlockSource.ts +0 -68
- package/src/daemon/auth.ts +0 -204
- package/src/daemon/fs.ts +0 -238
- package/src/daemon/index.ts +0 -8
- package/src/daemon/middleware.ts +0 -156
- package/src/daemon/tunnel.ts +0 -129
- package/src/daemon/volumes.ts +0 -366
- package/src/daemon/watch.ts +0 -272
- package/src/hooks/CdnSegmentMarker.tsx +0 -38
- package/src/hooks/DecoPageRenderer.tsx +0 -750
- package/src/hooks/DecoRootLayout.tsx +0 -192
- package/src/hooks/DraftPreviewIndicator.test.tsx +0 -60
- package/src/hooks/DraftPreviewIndicator.tsx +0 -64
- package/src/hooks/NavigationProgress.test.tsx +0 -58
- package/src/hooks/NavigationProgress.tsx +0 -63
- package/src/hooks/PreviewProviders.test.tsx +0 -42
- package/src/hooks/PreviewProviders.tsx +0 -45
- package/src/hooks/StableOutlet.tsx +0 -30
- package/src/hooks/deferredObserverTiming.test.tsx +0 -91
- package/src/hooks/index.ts +0 -10
- package/src/routes/adminRoutes.test.ts +0 -99
- package/src/routes/adminRoutes.ts +0 -153
- package/src/routes/cmsRoute.test.ts +0 -267
- package/src/routes/cmsRoute.ts +0 -1053
- package/src/routes/components.tsx +0 -57
- package/src/routes/index.ts +0 -24
- package/src/routes/pageUrl.test.ts +0 -70
- package/src/routes/pageUrl.ts +0 -55
- package/src/routes/withSiteGlobals.test.ts +0 -243
- package/src/routes/withSiteGlobals.ts +0 -243
- package/src/sdk/backgroundTasks.test.ts +0 -68
- package/src/sdk/backgroundTasks.ts +0 -38
- package/src/sdk/cdnSegment.test.ts +0 -67
- package/src/sdk/cdnSegment.ts +0 -71
- package/src/sdk/cookiePassthrough.ts +0 -58
- package/src/sdk/createInvoke.ts +0 -77
- package/src/sdk/deferredSectionLoader.test.ts +0 -94
- package/src/sdk/deferredSectionLoader.ts +0 -46
- package/src/sdk/draft.test.ts +0 -341
- package/src/sdk/draft.ts +0 -277
- package/src/sdk/draftShared.ts +0 -16
- package/src/sdk/kvHydration.test.ts +0 -371
- package/src/sdk/kvHydration.ts +0 -263
- package/src/sdk/kvRedirects.test.ts +0 -132
- package/src/sdk/kvRedirects.ts +0 -125
- package/src/sdk/outboundHeaders.test.ts +0 -113
- package/src/sdk/outboundHeaders.ts +0 -81
- package/src/sdk/router.ts +0 -101
- package/src/sdk/serverFnFetch.ts +0 -59
- package/src/sdk/speculationRules.test.ts +0 -82
- package/src/sdk/speculationRules.ts +0 -136
- package/src/sdk/startEntry.ts +0 -31
- package/src/sdk/useHydrated.ts +0 -19
- package/src/sdk/workerEntry.cacheStorage.test.ts +0 -147
- package/src/sdk/workerEntry.test.ts +0 -1033
- package/src/sdk/workerEntry.trackingCache.test.ts +0 -328
- package/src/sdk/workerEntry.ts +0 -3154
- package/src/setupFastDeploy.ts +0 -13
- package/src/v8/__conformance__/delivery.test.ts +0 -100
- package/src/v8/binding.ts +0 -70
- package/src/v8/kvLoader.bundle.test.ts +0 -42
- package/src/v8/kvLoader.test.ts +0 -74
- package/src/v8/kvLoader.ts +0 -43
- package/src/vite/plugin-scaffold-gen.test.js +0 -106
- package/src/vite/plugin.js +0 -1022
- package/src/vite/plugin.test.js +0 -238
- package/src/vite/plugin.test.ts +0 -176
- package/tsconfig.json +0 -7
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createDecoWorker`: the Cloudflare Worker in front of TanStack Start, the way
|
|
3
|
+
* Deco runs every TanStack storefront. One entry, a few options, one escape
|
|
4
|
+
* hatch (`routes`). What every site gets, with no option:
|
|
5
|
+
*
|
|
6
|
+
* - `/deco/_liveness` answers `OK`; v7's admin paths (`/deco/*`, `/live/*`,
|
|
7
|
+
* `/.decofile`) answer 404.
|
|
8
|
+
* - Drafts: the host allowlist (`./drafts.ts`), the draft cookie, the
|
|
9
|
+
* `x-deco-draft` request header the page reads, and on the response
|
|
10
|
+
* `no-store`, `Vary: Cookie` and `noindex`. Only a real draft skips the cache.
|
|
11
|
+
* - The CMS redirects, before any route.
|
|
12
|
+
* - An edge cache (the Cloudflare Cache API) keyed by URL, device, the site's
|
|
13
|
+
* segment parts and `<build>.<content revision>`, with stale-while-revalidate
|
|
14
|
+
* and stale-if-error; logged-in, private and degraded responses never stored.
|
|
15
|
+
* - CDN caching of client-side navigation data whose `__cseg` token checks out;
|
|
16
|
+
* every other response tells the CDN `no-store`, at one exit.
|
|
17
|
+
* - Security headers and `frame-ancestors` for Studio; immutable fingerprinted
|
|
18
|
+
* assets; one `Set-Cookie` per cookie; `x-page-status`.
|
|
19
|
+
* - `http.server.request.duration` for every request, to the CMS's telemetry
|
|
20
|
+
* (`recordServerRequest` from `@decocms/blocks/metrics`), labelled with the route's template, the
|
|
21
|
+
* method, the status class, the cache decision and the device; nothing
|
|
22
|
+
* when the CMS has no telemetry.
|
|
23
|
+
*/
|
|
24
|
+
import { type CMS } from "@decocms/blocks";
|
|
25
|
+
import { type CacheProfileName, type CacheProfileOverrides } from "./cacheProfiles.ts";
|
|
26
|
+
import { type CspOptions } from "./security.ts";
|
|
27
|
+
export type { CacheProfile, CacheProfileName, CacheProfileOverrides, CacheWindow, } from "./cacheProfiles.ts";
|
|
28
|
+
export { DEFAULT_CACHE_PROFILES } from "./cacheProfiles.ts";
|
|
29
|
+
export type { CspOptions } from "./security.ts";
|
|
30
|
+
export type { Device, Segment } from "./segment.ts";
|
|
31
|
+
/** The part of Cloudflare's `ExecutionContext` the worker uses. */
|
|
32
|
+
export interface ExecutionContextLike {
|
|
33
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
34
|
+
passThroughOnException?(): void;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* TanStack Start's server entry (`createServerEntry({ fetch: handler.fetch })`). The worker
|
|
38
|
+
* passes it the request, the Worker's env and the execution context.
|
|
39
|
+
*/
|
|
40
|
+
export interface ServerEntry {
|
|
41
|
+
fetch(request: Request, env?: any, ctx?: any): Response | Promise<Response>;
|
|
42
|
+
}
|
|
43
|
+
/** What the edge cache did with a request (`X-Cache`). */
|
|
44
|
+
export type CacheDecision = "HIT" | "STALE-HIT" | "STALE-ERROR" | "MISS" | "BYPASS";
|
|
45
|
+
/** One page or server-function request, for `onCache`. */
|
|
46
|
+
export interface CacheEvent {
|
|
47
|
+
/** The page type (cache profile) the URL maps to. */
|
|
48
|
+
profile: CacheProfileName;
|
|
49
|
+
decision: CacheDecision;
|
|
50
|
+
/** Milliseconds from the request to the response's headers. */
|
|
51
|
+
ms: number;
|
|
52
|
+
status: number;
|
|
53
|
+
}
|
|
54
|
+
export interface DecoWorkerOptions<Env = unknown> {
|
|
55
|
+
serverEntry: ServerEntry;
|
|
56
|
+
/** The site's CMS: drafts, the content revision in the cache key, CMS redirects. */
|
|
57
|
+
cms: CMS;
|
|
58
|
+
/** The site's name: `<site>.deco.site` and `<site>.deco-cx.workers.dev` may preview drafts. */
|
|
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. */
|
|
63
|
+
dev?: boolean;
|
|
64
|
+
/** The site's Content-Security-Policy. Studio's `frame-ancestors` is always added. */
|
|
65
|
+
csp?: CspOptions;
|
|
66
|
+
/**
|
|
67
|
+
* More cache-key parts for a request (a region, a sales channel, an A/B
|
|
68
|
+
* cohort), merged over `{ device }` (`mobile`, `tablet` or `desktop`; return
|
|
69
|
+
* your own `device` to merge classes). Return `"private"` for a request that
|
|
70
|
+
* must never share a cached response (a signed-in shopper).
|
|
71
|
+
*/
|
|
72
|
+
segment?: (request: Request) => Record<string, string | undefined> | "private";
|
|
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;
|
|
79
|
+
/**
|
|
80
|
+
* `Link: rel=preload` hints on every HTML response the app renders. A
|
|
81
|
+
* `routes` response carries none: it is another origin's page (a proxied
|
|
82
|
+
* checkout, an A/B test's other site), and these are this app's assets.
|
|
83
|
+
*/
|
|
84
|
+
preload?: {
|
|
85
|
+
styles?: readonly string[];
|
|
86
|
+
fonts?: readonly string[];
|
|
87
|
+
};
|
|
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
|
+
/**
|
|
97
|
+
* The escape hatch, after the CMS redirects and before anything else: answer
|
|
98
|
+
* a request yourself (a commerce proxy, a sitemap, an A/B route) or return
|
|
99
|
+
* `null` to let the worker serve it. The request carries the checked draft.
|
|
100
|
+
* Its response leaves like any other (security headers, `CDN-Cache-Control`)
|
|
101
|
+
* but without the `preload` hints.
|
|
102
|
+
*/
|
|
103
|
+
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
|
+
}
|
|
107
|
+
export interface DecoWorker<Env> {
|
|
108
|
+
fetch(request: Request, env: Env, ctx: ExecutionContextLike): Promise<Response>;
|
|
109
|
+
}
|
|
110
|
+
export declare function createDecoWorker<Env = unknown>(options: DecoWorkerOptions<Env>): DecoWorker<Env>;
|
|
111
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/worker/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,KAAK,GAAG,EAAyC,MAAM,iBAAiB,CAAC;AAKlF,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAO3B,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,KAAK,UAAU,EAAuB,MAAM,eAAe,CAAC;AAGrE,YAAY,EACV,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,EACrB,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEpD,mEAAmE;AACnE,MAAM,WAAW,oBAAoB;IACnC,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IAC3C,sBAAsB,CAAC,IAAI,IAAI,CAAC;CACjC;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,GAAG,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CA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