@decocms/blocks 8.1.0-next.0 → 8.1.0-next.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.
Files changed (114) hide show
  1. package/package.json +6 -92
  2. package/src/index.ts +2 -12
  3. package/src/protocol/storage/memory.ts +1 -1
  4. package/src/v8/background.ts +3 -3
  5. package/src/v8/builtins/legacy.ts +1 -1
  6. package/src/v8/cli/index.ts +1 -1
  7. package/src/v8/fetch.ts +8 -27
  8. package/src/v8/remoteLoader.ts +1 -1
  9. package/src/v8/telemetry.ts +1 -1
  10. package/src/cms/applySectionConventions.ts +0 -148
  11. package/src/cms/blockSource.ts +0 -228
  12. package/src/cms/client.ts +0 -85
  13. package/src/cms/deferredTrigger.ts +0 -58
  14. package/src/cms/draftSource.ts +0 -476
  15. package/src/cms/index.ts +0 -180
  16. package/src/cms/loadDecofileDirectory.ts +0 -89
  17. package/src/cms/loader.ts +0 -563
  18. package/src/cms/registry.ts +0 -264
  19. package/src/cms/renderJson.ts +0 -179
  20. package/src/cms/resolve.ts +0 -2583
  21. package/src/cms/schema.ts +0 -1219
  22. package/src/cms/sectionLoaderContext.ts +0 -113
  23. package/src/cms/sectionLoaders.ts +0 -686
  24. package/src/cms/sectionMixins.ts +0 -153
  25. package/src/flags/audience.ts +0 -56
  26. package/src/flags/everyone.ts +0 -29
  27. package/src/flags/flag.ts +0 -15
  28. package/src/flags/multivariate/image.ts +0 -11
  29. package/src/flags/multivariate/message.ts +0 -11
  30. package/src/flags/multivariate/page.ts +0 -16
  31. package/src/flags/multivariate/section.ts +0 -16
  32. package/src/flags/multivariate.ts +0 -1
  33. package/src/flags/types.ts +0 -59
  34. package/src/flags/utils/multivariate.ts +0 -20
  35. package/src/hooks/Image.tsx +0 -314
  36. package/src/hooks/JsonLd.tsx +0 -353
  37. package/src/hooks/LazySection.tsx +0 -121
  38. package/src/hooks/LiveControls.tsx +0 -144
  39. package/src/hooks/Picture.tsx +0 -127
  40. package/src/hooks/RenderSection.tsx +0 -91
  41. package/src/hooks/SectionErrorFallback.tsx +0 -97
  42. package/src/hooks/Stats.tsx +0 -134
  43. package/src/hooks/index.ts +0 -35
  44. package/src/hooks/useLoadMore.ts +0 -100
  45. package/src/matchers/builtins.ts +0 -459
  46. package/src/matchers/countryNames.ts +0 -104
  47. package/src/matchers/override.ts +0 -136
  48. package/src/matchers/posthog.ts +0 -154
  49. package/src/middleware/decoState.ts +0 -55
  50. package/src/middleware/healthMetrics.ts +0 -133
  51. package/src/middleware/hydrationContext.ts +0 -79
  52. package/src/middleware/index.ts +0 -88
  53. package/src/middleware/liveness.ts +0 -21
  54. package/src/middleware/observability.ts +0 -800
  55. package/src/middleware/validateSection.ts +0 -100
  56. package/src/preview/DraftPreviewBadge.tsx +0 -306
  57. package/src/preview/decoMark.ts +0 -11
  58. package/src/preview/index.ts +0 -8
  59. package/src/sdk/abTesting.ts +0 -556
  60. package/src/sdk/analytics.ts +0 -147
  61. package/src/sdk/cacheHeaders.ts +0 -633
  62. package/src/sdk/cacheStorage.ts +0 -287
  63. package/src/sdk/cachedLoader.ts +0 -556
  64. package/src/sdk/clx.ts +0 -5
  65. package/src/sdk/cn.ts +0 -28
  66. package/src/sdk/composite.ts +0 -114
  67. package/src/sdk/cookie.ts +0 -129
  68. package/src/sdk/crypto.ts +0 -199
  69. package/src/sdk/csp.ts +0 -59
  70. package/src/sdk/deepOmit.ts +0 -52
  71. package/src/sdk/detectDevice.ts +0 -45
  72. package/src/sdk/djb2.ts +0 -20
  73. package/src/sdk/encoding.ts +0 -44
  74. package/src/sdk/env.ts +0 -54
  75. package/src/sdk/experiments.ts +0 -314
  76. package/src/sdk/fetchCache.ts +0 -269
  77. package/src/sdk/fetchTimeout.ts +0 -58
  78. package/src/sdk/flags.ts +0 -138
  79. package/src/sdk/http.ts +0 -124
  80. package/src/sdk/index.ts +0 -97
  81. package/src/sdk/inflightTimeout.ts +0 -53
  82. package/src/sdk/instrumentedFetch.ts +0 -362
  83. package/src/sdk/invoke.ts +0 -298
  84. package/src/sdk/logger.ts +0 -304
  85. package/src/sdk/mergeCacheControl.ts +0 -150
  86. package/src/sdk/nonce.ts +0 -46
  87. package/src/sdk/normalizeUrls.ts +0 -91
  88. package/src/sdk/observability.ts +0 -116
  89. package/src/sdk/otel.ts +0 -1118
  90. package/src/sdk/otelAdapters/clickhouseCollector.ts +0 -65
  91. package/src/sdk/otelAdapters.ts +0 -144
  92. package/src/sdk/otelHttpLog.ts +0 -419
  93. package/src/sdk/otelHttpMeter.ts +0 -532
  94. package/src/sdk/otelHttpTracer.ts +0 -543
  95. package/src/sdk/redirects.ts +0 -336
  96. package/src/sdk/requestContext.ts +0 -281
  97. package/src/sdk/requestContextStorage.browser.ts +0 -43
  98. package/src/sdk/requestContextStorage.ts +0 -35
  99. package/src/sdk/responseCache.ts +0 -82
  100. package/src/sdk/retry.ts +0 -45
  101. package/src/sdk/serverTimings.ts +0 -68
  102. package/src/sdk/signal.ts +0 -42
  103. package/src/sdk/sitemap.ts +0 -160
  104. package/src/sdk/urlRedaction.ts +0 -82
  105. package/src/sdk/urlUtils.ts +0 -183
  106. package/src/sdk/useDevice.ts +0 -89
  107. package/src/sdk/useDeviceContext.tsx +0 -108
  108. package/src/sdk/useId.ts +0 -7
  109. package/src/sdk/useScript.ts +0 -210
  110. package/src/sdk/useSuggestions.ts +0 -188
  111. package/src/sdk/wrapCaughtErrors.ts +0 -107
  112. package/src/setup.ts +0 -120
  113. package/src/types/index.ts +0 -53
  114. package/src/types/widgets.ts +0 -14
@@ -1,228 +0,0 @@
1
- /**
2
- * BlockSource — the runtime source of truth for the CMS decofile.
3
- *
4
- * A `BlockSource` asynchronously yields the *whole* decofile snapshot (the
5
- * `Record<string, unknown>` blocks map) plus its revision hash. This is the
6
- * "fast deploy" seam: the framework can hydrate the in-memory block map from a
7
- * remote source (Cloudflare KV) on cold start and swap it on revision change,
8
- * WITHOUT making the synchronous resolution hot path (`loadBlocks()` in
9
- * `loader.ts`) async.
10
- *
11
- * Design note (whole-snapshot vs per-block): the resolver calls `loadBlocks()`
12
- * synchronously in dozens of places (matchers, deferral checks, page lookup,
13
- * SEO). Rather than threading `async` through all of that, a `BlockSource`
14
- * loads the entire decofile once and the framework calls `setBlocks()` to swap
15
- * the in-memory map. Per-request reads stay in-memory (zero added latency); KV
16
- * is touched only on cold start and during the opportunistic revision poll.
17
- *
18
- * Mirrors the `DecofileProvider` pattern from the original deco-cx/deco Fresh
19
- * runtime (`engine/decofile/provider.ts`), trimmed to what the snapshot-swap
20
- * model needs.
21
- */
22
-
23
- import { djb2Hex } from "../sdk/djb2";
24
-
25
- /** A fully-loaded decofile snapshot: the blocks map and its revision hash. */
26
- export interface BlockSnapshot {
27
- /** The decofile — a flat map of block name → block JSON. */
28
- blocks: Record<string, unknown>;
29
- /** DJB2 hex revision computed over the blocks (see `computeRevision`). */
30
- revision: string;
31
- }
32
-
33
- /**
34
- * Source of the runtime decofile snapshot.
35
- *
36
- * Implementations:
37
- * - `BundledBlockSource` — the build-time `blocks.gen` snapshot (fallback /
38
- * local dev). A no-op here because `setup.ts` already loads it via
39
- * `setBlocks()` at module init.
40
- * - `KVBlockSource` — reads `decofile:<id>` + `index:revision:<id>` (keyed by
41
- * deployment id) from a Cloudflare KV namespace.
42
- */
43
- export interface BlockSource {
44
- /**
45
- * Load the full decofile snapshot. Returns `null` when this source has no
46
- * snapshot to offer (e.g. KV key missing, or the bundled source which is
47
- * already applied at startup) — the caller then keeps whatever blocks are
48
- * currently in memory.
49
- */
50
- loadSnapshot(): Promise<BlockSnapshot | null>;
51
-
52
- /**
53
- * Cheap revision probe used for change detection during polling. Returns the
54
- * current revision without transferring the full snapshot, or `null` when
55
- * unavailable.
56
- */
57
- getRevision(): Promise<string | null>;
58
- }
59
-
60
- /**
61
- * Compute the revision hash for a blocks map.
62
- *
63
- * MUST match `computeRevision` in `loader.ts` (DJB2 over the JSON string) so
64
- * that a snapshot written to KV and the revision stored alongside it agree
65
- * with the revision an isolate computes after `setBlocks()` — otherwise the
66
- * poller would see a permanent mismatch and reload on every tick.
67
- */
68
- export function computeRevision(blocks: Record<string, unknown>): string {
69
- return djb2Hex(JSON.stringify(blocks));
70
- }
71
-
72
- /**
73
- * Bundled (build-time) snapshot source.
74
- *
75
- * Intentionally a no-op `loadSnapshot()`: the bundled `blocks.gen` is applied
76
- * by `createSiteSetup()` → `setBlocks()` at module load, before any request.
77
- * This exists so callers can treat "bundled" uniformly through the
78
- * `BlockSource` interface and so the composition layer (KV primary + bundled
79
- * fallback) has a concrete fallback object.
80
- */
81
- export class BundledBlockSource implements BlockSource {
82
- loadSnapshot(): Promise<BlockSnapshot | null> {
83
- return Promise.resolve(null);
84
- }
85
-
86
- getRevision(): Promise<string | null> {
87
- return Promise.resolve(null);
88
- }
89
- }
90
-
91
- // ---------------------------------------------------------------------------
92
- // Minimal Cloudflare KV type
93
- // ---------------------------------------------------------------------------
94
-
95
- /**
96
- * Minimal structural type for a Cloudflare KV namespace binding.
97
- *
98
- * Declared locally (matching the pattern in `workerEntry.ts`, which defines
99
- * its own `WorkerExecutionContext`) so `@decocms/start` does not depend on
100
- * `@cloudflare/workers-types`. Only the methods the framework actually uses
101
- * are modeled.
102
- */
103
- export interface KVNamespace {
104
- get(key: string, options?: { type?: "text" }): Promise<string | null>;
105
- put(
106
- key: string,
107
- value: string,
108
- options?: { expirationTtl?: number; metadata?: Record<string, unknown> },
109
- ): Promise<void>;
110
- delete(key: string): Promise<void>;
111
- }
112
-
113
- // ---------------------------------------------------------------------------
114
- // KV key layout — keyed by DEPLOYMENT ID so every code deployment reads its own
115
- // content snapshot (deploy isolation, cheap rollback, build-time content sync).
116
- //
117
- // The deployment id is the git commit sha (see `getDeploymentId` below).
118
- // Shared by the runtime reader (`kvBlockSource.ts`), the write-through path
119
- // (`admin/decofile.ts`), and the CI sync/migrate scripts, so the contract can't
120
- // drift between read and write sides.
121
- //
122
- // decofile:<id> full decofile JSON for deployment <id>
123
- // index:revision:<id> DJB2 hex revision of that snapshot (polled)
124
- // index:live pointer to the currently-live <id> (set post-deploy)
125
- // index:deployments JSON [{id, ts}] (newest last) — GC bookkeeping
126
- // redirect:<id>:<path> ONE key per exact redirect (see below)
127
- // ---------------------------------------------------------------------------
128
-
129
- /** KV key holding the full decofile JSON for deployment `id`. */
130
- export function snapshotKey(id: string): string {
131
- return `decofile:${id}`;
132
- }
133
-
134
- /** KV key holding the DJB2 hex revision of deployment `id`'s snapshot. */
135
- export function revisionKey(id: string): string {
136
- return `index:revision:${id}`;
137
- }
138
-
139
- /** Pointer key naming the currently-live deployment id. Written by a code
140
- * deploy AFTER the new version has activated (so a rolling deploy never points
141
- * live at a version that isn't serving yet). */
142
- export const LIVE_KEY = "index:live";
143
-
144
- /** Bookkeeping key: JSON array of `{ id, ts }` (newest last) tracking known
145
- * deployment snapshots so the sync script can GC all but the last N. */
146
- export const DEPLOYMENTS_KEY = "index:deployments";
147
-
148
- // ---------------------------------------------------------------------------
149
- // Exact redirects — one KV key each, deliberately NOT inside the decofile.
150
- //
151
- // A bulk-migration site can carry tens of thousands of rules. Inside the
152
- // decofile they are resident in every isolate twice over: once in the parsed
153
- // snapshot graph, once in the `RedirectMap` built from it — megabytes of a
154
- // 128MB budget, for data that is read at most once per request and usually
155
- // never. As their own keys they are looked up on demand and the list is never
156
- // loaded at all.
157
- //
158
- // Only EXACT rules move. Glob rules (`/old/*`) cannot be addressed by key and
159
- // must be scanned in order, so they stay in the decofile — there are tens of
160
- // them, not thousands.
161
- // ---------------------------------------------------------------------------
162
-
163
- /** Key prefix holding deployment `id`'s exact redirects (one key per path). */
164
- export function redirectPrefix(id: string): string {
165
- return `redirect:${id}:`;
166
- }
167
-
168
- /**
169
- * KV key for one exact redirect. `path` MUST already be normalized by
170
- * `normalizePath` (`@decocms/blocks/sdk/redirects`) on both sides — the writer
171
- * and the request-time lookup — or a rule is written under a key nothing ever
172
- * asks for.
173
- */
174
- export function redirectKey(id: string, path: string): string {
175
- return `${redirectPrefix(id)}${path}`;
176
- }
177
-
178
- /** Value stored at a `redirect:<id>:<path>` key. */
179
- export interface StoredRedirect {
180
- to: string;
181
- status: 301 | 302;
182
- }
183
-
184
- // ---------------------------------------------------------------------------
185
- // Deployment id resolution
186
- //
187
- // Which snapshot key does THIS running worker read/write? The deployment id.
188
- // Kept here (framework-agnostic) alongside the key builders it feeds, so the
189
- // runtime read path (`@decocms/tanstack` kvHydration) and the write-through
190
- // path (`@decocms/blocks-admin` decofile) resolve it identically — no drift.
191
- // ---------------------------------------------------------------------------
192
-
193
- /** Deploy-time var naming this version's content snapshot key. Set by the
194
- * deploy command (`wrangler deploy --var DECO_DEPLOYMENT_ID:<sha>`). */
195
- export const DEPLOYMENT_ID_ENV = "DECO_DEPLOYMENT_ID";
196
-
197
- /** Fallback var (cache-key version) — the same commit sha, already threaded by
198
- * some sites via `--var BUILD_HASH:<sha>`. */
199
- export const BUILD_HASH_ENV = "BUILD_HASH";
200
-
201
- // Build-time constant injected by the tanstack `decoVitePlugin()` (git
202
- // rev-parse / WORKERS_CI_COMMIT_SHA) as the last-resort deployment id. Declared
203
- // here with a `typeof` guard so it's inert where the define isn't applied
204
- // (e.g. the Next.js build, or this package's own tsc output).
205
- declare const __DECO_BUILD_HASH__: string | undefined;
206
-
207
- /**
208
- * Resolve this worker's deployment id — the key its content is stored under
209
- * (`decofile:<id>`). Priority:
210
- * 1. `env.DECO_DEPLOYMENT_ID` — set by the deploy command (authoritative).
211
- * 2. `env.BUILD_HASH` — the cache-key version var; the same commit sha.
212
- * 3. `__DECO_BUILD_HASH__` — build-time constant (the commit the bundle, and
213
- * thus the build-time content sync, was produced from).
214
- * Returns `null` when none resolves — the caller then serves the bundled
215
- * snapshot (never another deployment's content).
216
- */
217
- export function getDeploymentId(env: Record<string, unknown>): string | null {
218
- const fromDeploymentVar = env[DEPLOYMENT_ID_ENV];
219
- if (typeof fromDeploymentVar === "string" && fromDeploymentVar) {
220
- return fromDeploymentVar;
221
- }
222
- const fromBuildHash = env[BUILD_HASH_ENV];
223
- if (typeof fromBuildHash === "string" && fromBuildHash) return fromBuildHash;
224
- if (typeof __DECO_BUILD_HASH__ !== "undefined" && __DECO_BUILD_HASH__) {
225
- return __DECO_BUILD_HASH__;
226
- }
227
- return null;
228
- }
package/src/cms/client.ts DELETED
@@ -1,85 +0,0 @@
1
- /**
2
- * Client-safe subset of `@decocms/blocks/cms`.
3
- *
4
- * `@decocms/blocks/cms` (the full barrel in `./index.ts`) re-exports
5
- * `loader.ts` and `resolve.ts`, which transitively import `node:async_hooks`
6
- * and `node:fs/promises`. Bundling ANY export from that barrel for a browser
7
- * target — even one that itself has zero Node dependencies, like
8
- * `getResolvedComponent` — drags the whole module graph in, since ES module
9
- * imports are evaluated at the file level, not per-export. Turbopack rejects
10
- * this outright in production builds ("the chunking context does not
11
- * support external modules"); webpack has historically let it through
12
- * uncaught, which just defers the failure to whoever notices the bloated
13
- * client bundle or a runtime error.
14
- *
15
- * This entry point exists so Client Components can import section-registry
16
- * lookups (e.g. to resolve and render a section by name, given data already
17
- * fetched server-side) without pulling in the resolver/loader machinery.
18
- *
19
- * Verified client-safe by import-graph inspection, transitively:
20
- * - `registry.ts` imports only React types.
21
- * - `sectionMixins.ts` imports `useDevice.ts`, which goes through
22
- * `requestContext.ts` — that module's only `node:async_hooks` dependency
23
- * (`requestContextStorage.ts`) is itself swapped for a no-op browser stub
24
- * via this package's `"browser"` export condition (see
25
- * `sdk/requestContextStorage.browser.ts`), so it's already safe for a
26
- * browser bundle.
27
- * - `schema.ts` has no imports at all.
28
- * - `deferredTrigger.ts` has no imports at all — it only reads the
29
- * `globalThis.__deco.asyncConfig` bag `resolve.ts` writes, which is exactly
30
- * why it is a standalone module instead of living in `resolve.ts`.
31
- *
32
- * Deliberately NOT re-exported here: `loader.ts`, `resolve.ts`,
33
- * `sectionLoaders.ts`, `loadDecofileDirectory.ts`, `blockSource.ts`, and
34
- * `applySectionConventions.ts` (which itself pulls in `resolve.ts` and
35
- * `sectionLoaders.ts` for section-registration setup). Those are resolver/
36
- * storage concerns that only make sense server-side — import them from
37
- * `@decocms/blocks/cms` instead.
38
- */
39
- export type { DeferredTrigger } from "./deferredTrigger";
40
- export { DEFAULT_DEFERRED_TRIGGER, getDeferredTrigger } from "./deferredTrigger";
41
- export type { OnBeforeResolveProps, SectionModule, SectionOptions } from "./registry";
42
- export {
43
- getResolvedComponent,
44
- getSection,
45
- getSectionOptions,
46
- getSectionRegistry,
47
- getSyncComponent,
48
- listRegisteredSections,
49
- preloadSectionComponents,
50
- preloadSectionModule,
51
- registerOnBeforeResolveProps,
52
- registerSection,
53
- registerSections,
54
- registerSectionsSync,
55
- setResolvedComponent,
56
- } from "./registry";
57
- export type {
58
- ActionConfig,
59
- AppSchemas,
60
- BlockPropsSchema,
61
- LoaderConfig,
62
- MatcherConfig,
63
- MetaResponse,
64
- } from "./schema";
65
- export {
66
- composeMeta,
67
- getRegisteredLoaders,
68
- getRegisteredMatchers,
69
- inferLoaderTags,
70
- registerActionSchema,
71
- registerActionSchemas,
72
- registerAppSchemas,
73
- registerLoaderSchema,
74
- registerLoaderSchemas,
75
- registerMatcherSchema,
76
- registerMatcherSchemas,
77
- } from "./schema";
78
- export type { SectionLoaderFn } from "./sectionLoaders";
79
- export {
80
- compose,
81
- withDevice,
82
- withMobile,
83
- withSearchParam,
84
- withSectionLoader,
85
- } from "./sectionMixins";
@@ -1,58 +0,0 @@
1
- /**
2
- * Client-safe reader for the deferred-section trigger mode.
3
- *
4
- * Lives in its own module — with zero imports — so a browser bundle can reach
5
- * it without dragging in `resolve.ts` (and its `node:async_hooks` /
6
- * `node:fs/promises` chain). Same reasoning as `cms/client.ts`; see the header
7
- * comment there.
8
- *
9
- * The value itself is written by `setAsyncRenderingConfig()` in `resolve.ts`,
10
- * into the same `globalThis.__deco.asyncConfig` bag the server reads.
11
- *
12
- * WHERE THE SETTING HAS TO RUN: this is read in the browser, so
13
- * `setAsyncRenderingConfig()` only takes effect if it runs in a module the
14
- * client bundle also loads — normally `setup.ts`, imported from `router.tsx`.
15
- * Set it from server-only code (the worker entry, `server.ts`) and the server
16
- * defers the section as expected while the client silently falls back to
17
- * `"intersection"`, which looks exactly like the option being ignored.
18
- *
19
- * WHO READS IT: only `@decocms/tanstack` (`DeferredSectionWrapper` in
20
- * `hooks/DecoPageRenderer.tsx`). It lives here because that is where
21
- * `AsyncRenderingConfig` lives; in `@decocms/nextjs` it is a no-op.
22
- */
23
-
24
- /**
25
- * How a deferred (⚡) section decides it's time to fetch its real markup.
26
- *
27
- * - `"intersection"` — wait until the skeleton is within 300px of the viewport.
28
- * Cheapest, and the default.
29
- * - `"load"` — fetch as soon as the wrapper mounts, without waiting for scroll.
30
- * This is what Deco on Fresh does through `DispatchAsyncRender`'s
31
- * `partialTriggerMode: "load"`: the page ships a light skeleton HTML and then
32
- * materializes every deferred section right after hydration. Sites migrating
33
- * from Fresh need this to keep parity — under `"intersection"` alone, content
34
- * below the fold does not exist until the user scrolls, which loses
35
- * below-the-fold analytics impressions and leaves the document short.
36
- *
37
- * The tradeoff of `"load"` is a request burst: every deferred section fires its
38
- * serverFn POST in the same commit, on first load and again on every SPA
39
- * navigation. That is precisely what the rAF + observer path exists to avoid,
40
- * and it is also exactly what Fresh does — so it is the right default for a
41
- * migrated site and the wrong one for a page with many heavy deferred sections.
42
- * The switch is site-wide; a per-section override (honouring the `loading` prop
43
- * the CMS `Lazy.tsx` wrapper already carries, which the resolver currently
44
- * discards) would be the finer-grained successor.
45
- */
46
- export type DeferredTrigger = "intersection" | "load";
47
-
48
- export const DEFAULT_DEFERRED_TRIGGER: DeferredTrigger = "intersection";
49
-
50
- /**
51
- * Read the configured trigger. Falls back to `"intersection"` when
52
- * `setAsyncRenderingConfig()` was never called or omitted the option, so
53
- * existing sites are not regressed by a framework bump.
54
- */
55
- export function getDeferredTrigger(): DeferredTrigger {
56
- const config = (globalThis as any).__deco?.asyncConfig;
57
- return config?.deferredTrigger ?? DEFAULT_DEFERRED_TRIGGER;
58
- }