@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,134 +0,0 @@
1
- /**
2
- * Stats — deco's first-party analytics collector.
3
- *
4
- * MOUNTED BY THE FRAMEWORK. `DecoRootLayout` renders it, so a site turns analytics on with an
5
- * environment variable and no code change — the same ergonomics the Fresh side already has,
6
- * where `website/pages/Page.tsx` renders it for every page.
7
- *
8
- * It lives in `@decocms/blocks` rather than in `@decocms/apps-website` because of what it is:
9
- * twenty lines of a `<link>` and a `<script>` driven by environment variables, pointing at our
10
- * own collector. `OneDollarStats` belongs among the apps because it is a VENDOR integration —
11
- * it wraps `history`, decodes a cookie and feeds a third party\'s SDK. This is framework
12
- * infrastructure, and putting it here is also what lets `@decocms/tanstack` mount it without
13
- * importing from an apps package, which would be a new edge in a dependency graph the repo
14
- * keeps one-way on purpose.
15
- *
16
- * `@decocms/apps-website/components/Stats` re-exports it, so anything importing the old path
17
- * keeps working.
18
- *
19
- * ## Why this is twenty lines and OneDollarStats is three hundred
20
- *
21
- * Not because it does less — because the work is on the other side. The lilstts SDK
22
- * has no notion of SPA navigation the way this app routes, no notion of the
23
- * `deco_segment` cookie, and no notion of `window.DECO.events`, so the component has
24
- * to wrap `history.pushState`, poll for globals, read and decode the cookie, and
25
- * forward every commerce event by hand.
26
- *
27
- * The deco collector's own bundle already does all of it, and is tested doing it:
28
- * the core module takes the first pageview through the prerender guard, wraps
29
- * `pushState`, `replaceState` and `popstate`, and flushes on `pagehide` and
30
- * `visibilitychange`; the deco module reads `deco_segment` into experiment
31
- * assignments and subscribes to `window.DECO.events`, mapping the commerce
32
- * vocabulary. None of that belongs in a component that would then be a second
33
- * implementation of it, drifting from the first.
34
- *
35
- * So there is no `useEffect` here, and that is the point. Nothing to hydrate, no
36
- * readiness polling, no module-level guard against StrictMode double-mounting —
37
- * because there is no client state to guard.
38
- *
39
- * ## data- attributes, not a global
40
- *
41
- * `dev` and `debug` are read off the tag rather than from `window.__dq`, and this is
42
- * load-bearing on exactly this framework. TanStack hoists `<script async>` into
43
- * `<head>` ABOVE any inline configuration block — measured at byte 190 against byte
44
- * 1108 on a real site. A component that set a global and expected the collector to
45
- * find it would boot into silence here, with no error: the collector would see a
46
- * development host, skip, and say nothing. Attributes cannot lose that race because
47
- * they are on the element that is executing.
48
- *
49
- * ## Off by default
50
- *
51
- * `DECO_ANALYTICS_ENABLED` must be set to `true`. This is the inverse of
52
- * `ONEDOLLAR_ENABLED`, which defaults to on, and the asymmetry is deliberate: one is
53
- * the incumbent and the other is being introduced. The two gates are also
54
- * independent, so a site can run both during a shadow comparison and neither gate
55
- * can turn the other off.
56
- */
57
-
58
- export interface Props {
59
- /**
60
- * Where the collector is published. Empty means same-origin, which is the
61
- * intended deployment: the script and the beacon are served from the site's own
62
- * hostname so no third-party request is involved and nothing is blocked.
63
- */
64
- origin?: string;
65
- /**
66
- * The site's public key, for sites NOT served through our CDN.
67
- *
68
- * Sites behind our edge are identified by the `Host` header, which a visitor
69
- * cannot forge; those must leave this unset. A key travels in the page source
70
- * where anyone can read and reuse it, so a key-identified site is recorded with
71
- * `site_id_source = tag` and is never billed from.
72
- */
73
- siteKey?: string;
74
- /** `defer` instead of `async`. Only for a page that needs strict ordering. */
75
- defer?: boolean;
76
- /**
77
- * Collect from localhost. The collector refuses local and private hostnames by
78
- * default, which is why a developer sees nothing until this is on.
79
- */
80
- dev?: boolean;
81
- /** Log every queued and flushed batch to the console. */
82
- debug?: boolean;
83
- }
84
-
85
- /** Same-origin. See {@link Props.origin}. */
86
- export const DEFAULT_ORIGIN = "";
87
-
88
- /**
89
- * Opt-in, and independent of `ONEDOLLAR_ENABLED` so both can run at once.
90
- */
91
- const DECO_ANALYTICS_ENABLED = process.env.DECO_ANALYTICS_ENABLED === "true";
92
- const DECO_ANALYTICS_ORIGIN = process.env.DECO_ANALYTICS_ORIGIN;
93
- const DECO_ANALYTICS_SITE_KEY = process.env.DECO_ANALYTICS_SITE_KEY;
94
-
95
- function Stats({ origin, siteKey, defer, dev, debug }: Props) {
96
- if (!DECO_ANALYTICS_ENABLED) return null;
97
-
98
- const base = origin ?? DECO_ANALYTICS_ORIGIN ?? DEFAULT_ORIGIN;
99
- const key = siteKey ?? DECO_ANALYTICS_SITE_KEY;
100
-
101
- return (
102
- <>
103
- {/*
104
- * Only when the collector is on another origin. A `preconnect` to the page's
105
- * own origin is a wasted hint at best, and on some browsers it is a second
106
- * connection opened for nothing.
107
- */}
108
- {base ? <link rel="preconnect" href={base} crossOrigin="anonymous" /> : null}
109
- <script
110
- id="deco-analytics"
111
- async={!defer}
112
- defer={defer}
113
- // THE KEY GOES IN THE URL, not in a `data-` attribute. The collector resolves the
114
- // site server-side while RENDERING the bundle -- it reads `?k=` and writes the
115
- // resolved config into the script it returns -- so a key on the element arrives
116
- // far too late to matter. It is also never read: the bundle only looks at
117
- // `data-dev` and `data-debug`.
118
- //
119
- // This was `data-site` and it would have failed the way this project's failures
120
- // always do: the collector resolves nothing, serves the `s:"unknown"` fallback,
121
- // and the site collects exactly zero with no error anywhere. Same shape as the
122
- // bug that once made the entire self-serve tier silent.
123
- src={`${base}/_dq/a.js${key ? `?k=${encodeURIComponent(key)}` : ""}`}
124
- // Rendered only when true. `data-dev="false"` and an absent attribute mean
125
- // the same thing to the collector, and the absent one cannot be mistaken
126
- // for a deliberate setting by someone reading the page source.
127
- data-dev={dev ? "true" : undefined}
128
- data-debug={debug ? "true" : undefined}
129
- />
130
- </>
131
- );
132
- }
133
-
134
- export default Stats;
@@ -1,35 +0,0 @@
1
- export { isBelowFold, LazySection, type LazySectionProps } from "./LazySection";
2
- export { LiveControls } from "./LiveControls";
3
- export { default as Stats, DEFAULT_ORIGIN as STATS_DEFAULT_ORIGIN, type Props as StatsProps } from "./Stats";
4
- export { SectionErrorBoundary } from "./SectionErrorFallback";
5
- export { default as RenderSection } from "./RenderSection";
6
-
7
- // Commerce UI primitives (moved from apps-start's commerce/components/).
8
- export {
9
- default as Image,
10
- registerImageCdnDomain,
11
- getImageCdnDomain,
12
- registerImageQuality,
13
- getImageQuality,
14
- getOptimizedMediaUrl,
15
- getSrcSet,
16
- FACTORS,
17
- type ImageProps,
18
- type ImageQuality,
19
- type FitOptions,
20
- } from "./Image";
21
- export { Picture, Source, type PictureProps, type SourceProps } from "./Picture";
22
- export { useLoadMore } from "./useLoadMore";
23
- export {
24
- ProductJsonLd,
25
- PLPJsonLd,
26
- BreadcrumbJsonLd,
27
- seoMetaTags,
28
- type ProductJsonLdProps,
29
- type PLPJsonLdProps,
30
- type BreadcrumbJsonLdProps,
31
- type SeoMetaProps,
32
- type JsonLdProduct,
33
- type JsonLdProductListingPage,
34
- type JsonLdBreadcrumbList,
35
- } from "./JsonLd";
@@ -1,100 +0,0 @@
1
- "use client";
2
-
3
- import { useState, useEffect, useCallback, useRef } from "react";
4
-
5
- /**
6
- * Extract the next-page URL from a loader result.
7
- * Handles both conventions used by commerce loaders:
8
- * - pageInfo.nextPage (VTEX, Blog, most standard loaders)
9
- * - nextPage (flat, some legacy loaders)
10
- */
11
- export function getNextPageUrl(data: unknown): string | undefined {
12
- if (!data || typeof data !== "object") return undefined;
13
- const d = data as Record<string, unknown>;
14
- if (d.pageInfo && typeof d.pageInfo === "object") {
15
- const pi = d.pageInfo as Record<string, unknown>;
16
- if (typeof pi.nextPage === "string" && pi.nextPage) return pi.nextPage;
17
- }
18
- if (typeof d.nextPage === "string" && d.nextPage) return d.nextPage;
19
- return undefined;
20
- }
21
-
22
- /**
23
- * Accumulates pages of loader data for "Ver mais" / load-more pagination.
24
- *
25
- * Fresh's `usePartialSection({ mode: "append" })` appended HTML without a
26
- * page reload. This hook is the TanStack equivalent: it calls the loader
27
- * via POST /deco/invoke — passing the nextPage URL as `__pageUrl` so the
28
- * loader reconstructs query, sort, and filter state from it — then pushes
29
- * the result into local state.
30
- *
31
- * Usage in a migrated section:
32
- * ```tsx
33
- * "use client"
34
- * const { pages, loadMore, loading, hasMore, error } = useLoadMore(
35
- * props.page ?? { products: [], pageInfo: {} },
36
- * "apps/vtex.ts/loaders/intelligentSearch/productListingPage.ts",
37
- * pageUrl // resetKey: pass the current page URL so accumulated pages reset on filter/sort change
38
- * )
39
- * const allProducts = pages.flatMap(p => p.products ?? [])
40
- * ```
41
- *
42
- * The component must be `"use client"` because this hook uses useState.
43
- *
44
- * @param resetKey - When this value changes, accumulated pages reset to [initial].
45
- * Pass the current page URL (or any value that changes on filter/sort navigation)
46
- * to clear the accumulated product list when the user changes filters.
47
- * Without resetKey, add `key={pageUrl}` to the section element instead.
48
- */
49
- export function useLoadMore<T>(initial: T, loaderKey: string, resetKey?: unknown) {
50
- const [pages, setPages] = useState<T[]>([initial]);
51
- const [loading, setLoading] = useState(false);
52
- const [error, setError] = useState<Error | null>(null);
53
- // useRef guard prevents two rapid clicks both passing the !loading check
54
- // before the async state update propagates (React state is not synchronous).
55
- const inflight = useRef(false);
56
- // Skip the reset effect on first mount — pages are already seeded from useState.
57
- const isFirstRender = useRef(true);
58
-
59
- useEffect(() => {
60
- if (isFirstRender.current) {
61
- isFirstRender.current = false;
62
- return;
63
- }
64
- setPages([initial]);
65
- setError(null);
66
- // eslint-disable-next-line react-hooks/exhaustive-deps
67
- }, [resetKey]);
68
-
69
- const lastPage = pages[pages.length - 1];
70
- const nextPageRel = getNextPageUrl(lastPage);
71
- const hasMore = Boolean(nextPageRel);
72
-
73
- const loadMore = useCallback(async () => {
74
- if (!nextPageRel || inflight.current) return;
75
- inflight.current = true;
76
- setLoading(true);
77
- setError(null);
78
- try {
79
- const abs = new URL(nextPageRel, location.href);
80
- const res = await fetch("/deco/invoke", {
81
- method: "POST",
82
- headers: { "content-type": "application/json" },
83
- body: JSON.stringify({
84
- key: loaderKey,
85
- props: { __pageUrl: abs.href, __pagePath: abs.pathname },
86
- }),
87
- });
88
- if (!res.ok) throw new Error(`invoke ${res.status} for ${loaderKey}`);
89
- const next = (await res.json()) as T;
90
- setPages((prev) => [...prev, next]);
91
- } catch (e) {
92
- setError(e instanceof Error ? e : new Error(String(e)));
93
- } finally {
94
- inflight.current = false;
95
- setLoading(false);
96
- }
97
- }, [nextPageRel, loaderKey]);
98
-
99
- return { pages, loadMore, loading, hasMore, error };
100
- }