@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,264 +0,0 @@
1
- import type { ComponentType } from "react";
2
- import type { RenderJson } from "./renderJson";
3
-
4
- export type OnBeforeResolveProps = (props: Record<string, unknown>) => Record<string, unknown>;
5
-
6
- export type SectionModule = {
7
- default: ComponentType<any>;
8
- loader?: (props: any) => Promise<any> | any;
9
- onBeforeResolveProps?: OnBeforeResolveProps;
10
- LoadingFallback?: ComponentType<any>;
11
- ErrorFallback?: ComponentType<{ error: Error }>;
12
- /** How this section renders to JSON for the mobile app (?renderJson). */
13
- renderJson?: RenderJson;
14
- };
15
-
16
- type RegistryEntry = () => Promise<SectionModule>;
17
-
18
- export interface SectionOptions {
19
- /** Custom loading fallback component for this section. */
20
- loadingFallback?: ComponentType<any>;
21
- /** Custom error fallback component for this section. */
22
- errorFallback?: ComponentType<{ error: Error }>;
23
- /**
24
- * The section's `renderJson` export (?renderJson mobile path): `false` drops
25
- * the section from the JSON, a function projects its props. Populated by the
26
- * generated section conventions and, as a fallback, on module preload.
27
- */
28
- renderJson?: RenderJson;
29
- /**
30
- * When true, the section is wrapped in `<ClientOnly>` from TanStack Router.
31
- * It renders only on the client — no SSR, no hydration mismatch.
32
- * Use for analytics scripts, GTM, third-party widgets, and other
33
- * browser-dependent components.
34
- */
35
- clientOnly?: boolean;
36
- }
37
-
38
- // globalThis-backed: server function split modules need access to the registry
39
- const G = globalThis as any;
40
- if (!G.__deco) G.__deco = {};
41
- if (!G.__deco.sectionRegistry) G.__deco.sectionRegistry = {};
42
- if (!G.__deco.sectionOptions) G.__deco.sectionOptions = {};
43
- if (!G.__deco.resolvedComponents) G.__deco.resolvedComponents = {};
44
- if (!G.__deco.syncComponents) G.__deco.syncComponents = {};
45
- if (!G.__deco.onBeforeResolvePropsRegistry) G.__deco.onBeforeResolvePropsRegistry = {};
46
-
47
- const registry: Record<string, RegistryEntry> = G.__deco.sectionRegistry;
48
- const sectionOptions: Record<string, SectionOptions> = G.__deco.sectionOptions;
49
-
50
- // Cache of already-resolved component references.
51
- // When a module is loaded (server-side or after first client import),
52
- // the default export is stored here so subsequent renders can use
53
- // the component directly WITHOUT React.lazy/Suspense — preventing
54
- // hydration flash on SSR'd content.
55
- const resolvedComponents: Record<string, ComponentType<any>> = G.__deco.resolvedComponents;
56
-
57
- // Static sync registry — components that were statically imported and
58
- // are guaranteed available on BOTH server and client without any async import.
59
- // These never need React.lazy/Suspense and render identically on SSR and hydration.
60
- const syncComponents: Record<string, ComponentType<any>> = G.__deco.syncComponents;
61
-
62
- // onBeforeResolveProps registry — functions that transform raw CMS props
63
- // BEFORE resolvables are resolved. Allows sections to extract data from
64
- // raw resolvable structures (e.g., collection IDs from loader refs) that
65
- // would be lost after resolution.
66
- const onBeforeResolvePropsRegistry: Record<string, OnBeforeResolveProps> =
67
- G.__deco.onBeforeResolvePropsRegistry;
68
-
69
- export function registerSection(key: string, loader: RegistryEntry, options?: SectionOptions) {
70
- registry[key] = loader;
71
- if (options) sectionOptions[key] = options;
72
- }
73
-
74
- export function registerSections(
75
- sections: Record<string, RegistryEntry>,
76
- defaultOptions?: SectionOptions,
77
- ) {
78
- for (const [key, loader] of Object.entries(sections)) {
79
- registry[key] = loader;
80
- if (defaultOptions) sectionOptions[key] = { ...defaultOptions };
81
- }
82
- }
83
-
84
- /**
85
- * Set a section's `renderJson` option (?renderJson mobile path) without touching
86
- * its loader/component registration. Called from the generated section
87
- * conventions for `export const renderJson = false | (props) => ...`.
88
- */
89
- export function setSectionRenderJson(key: string, renderJson: RenderJson): void {
90
- sectionOptions[key] = { ...sectionOptions[key], renderJson };
91
- }
92
-
93
- export function getSection(resolveType: string): RegistryEntry | undefined {
94
- return registry[resolveType];
95
- }
96
-
97
- export function getSectionOptions(resolveType: string): SectionOptions | undefined {
98
- return sectionOptions[resolveType];
99
- }
100
-
101
- /**
102
- * Load a section module eagerly to extract LoadingFallback/ErrorFallback.
103
- * Used by DeferredSectionWrapper to show custom skeletons before the section
104
- * scrolls into view and its full props are fetched.
105
- */
106
- export async function preloadSectionModule(
107
- resolveType: string,
108
- ): Promise<SectionOptions | undefined> {
109
- const existing = sectionOptions[resolveType];
110
- if (existing?.loadingFallback) return existing;
111
-
112
- const loader = registry[resolveType];
113
- if (!loader) return undefined;
114
-
115
- try {
116
- const mod = await loader();
117
- const opts: SectionOptions = { ...existing };
118
- if (mod.LoadingFallback) opts.loadingFallback = mod.LoadingFallback;
119
- if (mod.ErrorFallback) opts.errorFallback = mod.ErrorFallback;
120
- if (mod.renderJson !== undefined) opts.renderJson = mod.renderJson;
121
- sectionOptions[resolveType] = opts;
122
- return opts;
123
- } catch (e) {
124
- console.warn(`[Registry] Failed to preload section module "${resolveType}":`, e);
125
- return existing;
126
- }
127
- }
128
-
129
- /**
130
- * Get a previously resolved component. Returns undefined if the module
131
- * hasn't been imported yet. Use this to render WITHOUT React.lazy/Suspense
132
- * for sections whose JS is already loaded — avoids hydration flash.
133
- */
134
- export function getResolvedComponent(key: string): ComponentType<any> | undefined {
135
- return resolvedComponents[key];
136
- }
137
-
138
- /**
139
- * Store a resolved component reference. Called after a successful import()
140
- * so future renders can skip React.lazy entirely.
141
- */
142
- export function setResolvedComponent(key: string, component: ComponentType<any>): void {
143
- resolvedComponents[key] = component;
144
- }
145
-
146
- /**
147
- * Pre-import section modules and cache their default exports.
148
- * Called server-side after resolving eager sections so that
149
- * the SSR render tree uses direct component refs instead of React.lazy.
150
- */
151
- export async function preloadSectionComponents(keys: string[]): Promise<void> {
152
- await Promise.all(
153
- keys.map(async (key) => {
154
- if (resolvedComponents[key]) return;
155
- const loader = registry[key];
156
- if (!loader) return;
157
- try {
158
- const mod = await loader();
159
- if (mod?.default) {
160
- resolvedComponents[key] = mod.default;
161
- }
162
- if (mod?.onBeforeResolveProps && !onBeforeResolvePropsRegistry[key]) {
163
- onBeforeResolvePropsRegistry[key] = mod.onBeforeResolveProps;
164
- }
165
- const opts: SectionOptions = { ...sectionOptions[key] };
166
- if (mod.LoadingFallback) opts.loadingFallback = mod.LoadingFallback;
167
- if (mod.ErrorFallback) opts.errorFallback = mod.ErrorFallback;
168
- if (mod.renderJson !== undefined) opts.renderJson = mod.renderJson;
169
- sectionOptions[key] = opts;
170
- } catch (e) {
171
- console.warn(`[Registry] Failed to preload component "${key}":`, e);
172
- }
173
- }),
174
- );
175
- }
176
-
177
- /**
178
- * A sync section entry: either a plain component reference or a full module
179
- * object with optional LoadingFallback and ErrorFallback.
180
- * Providing the full module allows DeferredSectionWrapper to show the correct
181
- * skeleton immediately (optionsReady=true on first render) without waiting for
182
- * the async preloadSectionModule() call.
183
- */
184
- export type SyncSectionEntry =
185
- | ComponentType<any>
186
- | {
187
- default: ComponentType<any>;
188
- LoadingFallback?: ComponentType<any>;
189
- ErrorFallback?: ComponentType<{ error: Error }>;
190
- renderJson?: RenderJson;
191
- };
192
-
193
- /**
194
- * Register sections with their already-imported component references.
195
- * These are available synchronously on both server and client — no dynamic
196
- * import, no React.lazy, no Suspense. Use for critical above-the-fold
197
- * sections that must never flash during hydration.
198
- *
199
- * Accepts either a plain component or a full module object (with optional
200
- * LoadingFallback / ErrorFallback). Providing the module object populates
201
- * sectionOptions immediately, so DeferredSectionWrapper can show the correct
202
- * skeleton without an extra async preloadSectionModule() round-trip.
203
- */
204
- export function registerSectionsSync(sections: Record<string, SyncSectionEntry>): void {
205
- for (const [key, entry] of Object.entries(sections)) {
206
- const raw = typeof entry === "function" ? entry : (entry as any).default;
207
- // Accept functions and React wrapper objects (React.memo, forwardRef, lazy)
208
- const REACT_WRAPPERS = [
209
- Symbol.for("react.memo"),
210
- Symbol.for("react.forward_ref"),
211
- Symbol.for("react.lazy"),
212
- ];
213
- const component =
214
- typeof raw === "function" ||
215
- (raw != null && typeof raw === "object" && REACT_WRAPPERS.includes((raw as any).$$typeof))
216
- ? raw
217
- : undefined;
218
- if (!component) {
219
- console.warn(`[registerSectionsSync] "${key}" has no callable default export — skipping`);
220
- continue;
221
- }
222
- syncComponents[key] = component;
223
- resolvedComponents[key] = component;
224
-
225
- if (typeof entry !== "function") {
226
- const opts: SectionOptions = { ...sectionOptions[key] };
227
- if (entry.LoadingFallback) opts.loadingFallback = entry.LoadingFallback;
228
- if (entry.ErrorFallback) opts.errorFallback = entry.ErrorFallback;
229
- if (entry.renderJson !== undefined) opts.renderJson = entry.renderJson;
230
- sectionOptions[key] = opts;
231
- }
232
- }
233
- }
234
-
235
- /**
236
- * Get a synchronously-registered component. Returns undefined if the
237
- * section was only registered with a lazy loader (registerSections).
238
- */
239
- export function getSyncComponent(key: string): ComponentType<any> | undefined {
240
- return syncComponents[key];
241
- }
242
-
243
- /**
244
- * Register an onBeforeResolveProps function for a section.
245
- * Called with raw CMS props (containing unresolved `__resolveType` references)
246
- * BEFORE the resolution engine resolves them. Use to extract metadata from
247
- * resolvable structures that would be lost after resolution.
248
- */
249
- export function registerOnBeforeResolveProps(sectionKey: string, fn: OnBeforeResolveProps): void {
250
- onBeforeResolvePropsRegistry[sectionKey] = fn;
251
- }
252
-
253
- /** Get the registered onBeforeResolveProps for a section, if any. */
254
- export function getOnBeforeResolveProps(sectionKey: string): OnBeforeResolveProps | undefined {
255
- return onBeforeResolvePropsRegistry[sectionKey];
256
- }
257
-
258
- export function listRegisteredSections(): string[] {
259
- return Object.keys(registry);
260
- }
261
-
262
- export function getSectionRegistry(): Record<string, RegistryEntry> {
263
- return registry;
264
- }
@@ -1,179 +0,0 @@
1
- /**
2
- * renderJson — structured JSON projection of a resolved page for the mobile app.
3
- *
4
- * A section controls how it renders to JSON through a recognized named export
5
- * `renderJson` (same convention family as `loader`/`action`/`LoadingFallback`):
6
- *
7
- * - `export const renderJson = false` — drop the section from the JSON entirely
8
- * (web-only: theme/analytics/SEO/scripts). It also short-circuits the loader
9
- * in {@link runSectionLoaders} (no data fetch for a dropped section).
10
- * - `export const renderJson = (props) => projected` — a pure projection applied
11
- * to the resolved props before serialization (typically {@link deepOmit} of
12
- * internal/SEO/store-config fields).
13
- * - no export — the section serializes with its full resolved props.
14
- *
15
- * The whole-page envelope (`?renderJson`) is `{ name, path, sections }`, where
16
- * each section is `{ component, props }`. This is the lean shape — no admin
17
- * `resolveChain`/metadata (unlike the legacy `?asJson`).
18
- *
19
- * Ported from the deco-runtime fork's `serialize-section.ts`, adapted for the
20
- * TanStack pipeline: sections are resolved EAGERLY before serialization, so this
21
- * serializer has no lazy-placeholder (`{ component, lazyUrl }`) branch — the
22
- * mobile app receives the whole page in one request.
23
- *
24
- * ponytail: no nested section-in-section recursion (composite/layout sections).
25
- * deepOmit handles trimming within a single section's data; add a recursive walk
26
- * here if a composite section must project its child sections.
27
- */
28
-
29
- // deno-lint-ignore-style any: a projection accepts the section's own resolved props.
30
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
- export type RenderJson = ((props: any) => Record<string, unknown>) | false;
32
-
33
- export interface RenderJsonModule {
34
- renderJson?: RenderJson;
35
- }
36
-
37
- /** A resolved section after its loader ran: component id + enriched props. */
38
- export interface SerializableSection {
39
- component: string;
40
- props?: Record<string, unknown>;
41
- /** Position in the page's flat section list (used to interleave with lazy ones). */
42
- index?: number;
43
- }
44
-
45
- /** A deferred section that isn't resolved eagerly — emitted as a lazy placeholder. */
46
- export interface DeferredRef {
47
- component: string;
48
- index: number;
49
- }
50
-
51
- /** An eager section carries `props`; a lazy one carries a `lazyUrl` to fetch it. */
52
- export type SerializedSection =
53
- | { component: string; props: Record<string, unknown> }
54
- | { component: string; lazyUrl: string };
55
-
56
- export interface SerializeOptions {
57
- /**
58
- * Resolves a section module by resolveType so the serializer can honor its
59
- * `renderJson` export. When omitted, every section keeps its full props.
60
- */
61
- getSectionModule?: (component: string) => RenderJsonModule | undefined;
62
- /**
63
- * App-owned sections excluded from the response, matched by resolveType
64
- * suffix (e.g. "SeoV2.tsx"). Blank entries are ignored — a "" suffix would
65
- * endsWith-match every section.
66
- */
67
- sectionsToIgnore?: string[];
68
- /**
69
- * Deferred sections to emit as `{ component, lazyUrl }` placeholders,
70
- * interleaved with the eager ones by `index`. Dropped sections
71
- * (`renderJson === false` / `sectionsToIgnore`) are omitted here too. When
72
- * set, the output is ordered by `index`.
73
- */
74
- deferred?: DeferredRef[];
75
- /** Builds the lazy-fetch URL for a deferred section. Required when `deferred` is set. */
76
- lazyUrlFor?: (ref: DeferredRef) => string;
77
- }
78
-
79
- /**
80
- * Projects a page's sections into the lean renderJson shape. Eager sections
81
- * become `{ component, props }` (a `renderJson` function projects the props;
82
- * otherwise props pass through). Deferred sections become
83
- * `{ component, lazyUrl }`, interleaved by `index`. A section is dropped when
84
- * its resolveType matches a `sectionsToIgnore` suffix OR its module exports
85
- * `renderJson === false` (for a deferred section, dropping avoids emitting a
86
- * lazyUrl the app would fetch for nothing).
87
- */
88
- /**
89
- * Keys the section loader / mixins inject into props at request time — page
90
- * context (`__pageUrl`/`__pagePath`, `runSectionLoaders`) and device
91
- * (`device`/`isMobile`/`currentSearchParam`, the withDevice/withMobile/
92
- * withSearchParam mixins). They are request-derived framework internals, NOT
93
- * content, so they are stripped from the JSON: they would bust the ETag per
94
- * request/device and leak internals the mobile app shouldn't cache. Any
95
- * `__`-prefixed key is treated as internal by convention (mirrors `__section`).
96
- */
97
- const FRAMEWORK_INJECTED_KEYS = new Set(["device", "isMobile", "currentSearchParam"]);
98
-
99
- function stripFrameworkKeys(props: Record<string, unknown>): Record<string, unknown> {
100
- let out: Record<string, unknown> | null = null;
101
- for (const k of Object.keys(props)) {
102
- if (k.startsWith("__") || FRAMEWORK_INJECTED_KEYS.has(k)) {
103
- out ??= { ...props };
104
- delete out[k];
105
- }
106
- }
107
- return out ?? props;
108
- }
109
-
110
- export function serializeRenderJson(
111
- sections: SerializableSection[],
112
- opts: SerializeOptions = {},
113
- ): SerializedSection[] {
114
- const ignore = (opts.sectionsToIgnore ?? [])
115
- .map((s) => s.trim())
116
- .filter((s) => s.length > 0);
117
-
118
- const renderJsonOf = (component: string): RenderJson | undefined =>
119
- opts.getSectionModule?.(component)?.renderJson;
120
-
121
- const isDropped = (component: string): boolean =>
122
- ignore.some((suffix) => component.endsWith(suffix)) ||
123
- renderJsonOf(component) === false;
124
-
125
- const eager = sections
126
- .filter((s) => !isDropped(s.component))
127
- .map((section) => {
128
- const rj = renderJsonOf(section.component);
129
- const projected = typeof rj === "function" ? rj(section.props ?? {}) : section.props ?? {};
130
- const props = stripFrameworkKeys(projected);
131
- return { index: section.index, out: { component: section.component, props } as SerializedSection };
132
- });
133
-
134
- // No deferred sections → preserve input order (backward compatible).
135
- if (!opts.deferred || opts.deferred.length === 0) {
136
- return eager.map((e) => e.out);
137
- }
138
-
139
- const lazyUrlFor = opts.lazyUrlFor;
140
- const lazy = opts.deferred
141
- .filter((ref) => !isDropped(ref.component) && !!lazyUrlFor)
142
- .map((ref) => ({
143
- index: ref.index,
144
- out: { component: ref.component, lazyUrl: lazyUrlFor!(ref) } as SerializedSection,
145
- }));
146
-
147
- // Interleave eager + lazy by their position in the page's flat section list.
148
- return [...eager, ...lazy].sort((a, b) => (a.index ?? 0) - (b.index ?? 0)).map((e) => e.out);
149
- }
150
-
151
- /**
152
- * A resolved Deco `Secret` is `{ get: () => string | null }` (apps-website
153
- * `loaders/secret.ts`) — the plaintext lives behind a function, so JSON.stringify
154
- * already drops it to `{}`. An unresolved secret block is `{ __resolveType:
155
- * ".../secret.ts", encrypted, ... }`. Neither has any place in a page-as-JSON
156
- * payload, so we remove the whole field. Matches by shape, so no content field
157
- * is caught by accident.
158
- *
159
- * Limitation: a *plaintext* secret a loader extracted into a string prop (the
160
- * deprecated `SecretString` or a manual `secret.get()`) is indistinguishable from
161
- * content — keep secrets as `Secret`, never resolve them into a serialized prop.
162
- */
163
- export function isSecretValue(value: unknown): boolean {
164
- if (!value || typeof value !== "object") return false;
165
- const o = value as Record<string, unknown>;
166
- // Resolved Secret: an object whose only own key is a `get` function.
167
- if (typeof o.get === "function" && Object.keys(o).length === 1) return true;
168
- // Unresolved secret block (defensive — resolved props usually drop __resolveType).
169
- const rt = o.__resolveType;
170
- return typeof rt === "string" && /secret/i.test(rt);
171
- }
172
-
173
- /**
174
- * `JSON.stringify` that drops any Secret-shaped value ({@link isSecretValue})
175
- * anywhere in the tree. Used for both `?renderJson` and `?asJson` bodies.
176
- */
177
- export function stringifyWithoutSecrets(value: unknown): string {
178
- return JSON.stringify(value, (_key, v) => (isSecretValue(v) ? undefined : v));
179
- }