@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,107 +0,0 @@
1
- /**
2
- * Error wrapping utility for loader/action results.
3
- *
4
- * Wraps a loader function so that thrown errors are caught and
5
- * returned as a deferred error proxy object instead of crashing
6
- * the entire page render.
7
- *
8
- * The proxy looks like the expected return type but throws the
9
- * original error if any property is accessed -- this lets the
10
- * section that uses the data decide whether to render a fallback
11
- * or propagate the error to an ErrorBoundary.
12
- *
13
- * @example
14
- * ```ts
15
- * import { wrapCaughtErrors } from "@decocms/start/sdk/wrapCaughtErrors";
16
- *
17
- * const safeProductList = wrapCaughtErrors(vtexProductList);
18
- * const products = await safeProductList({ query: "shoes" });
19
- * // If vtexProductList threw, `products` is a proxy that throws on access
20
- * ```
21
- */
22
-
23
- const ERROR_MARKER = Symbol("__decoWrappedError");
24
-
25
- export interface WrappedError {
26
- [ERROR_MARKER]: true;
27
- error: unknown;
28
- message: string;
29
- }
30
-
31
- /**
32
- * Check if a value is a wrapped error proxy.
33
- */
34
- export function isWrappedError(value: unknown): value is WrappedError {
35
- try {
36
- return value != null && typeof value === "object" && (value as any)[ERROR_MARKER] === true;
37
- } catch {
38
- return true;
39
- }
40
- }
41
-
42
- /**
43
- * Extract the original error from a wrapped error.
44
- */
45
- export function unwrapError(value: unknown): unknown {
46
- if (isWrappedError(value)) {
47
- return value.error;
48
- }
49
- return value;
50
- }
51
-
52
- function createErrorProxy(error: unknown): any {
53
- const message = error instanceof Error ? error.message : String(error);
54
-
55
- const target = {
56
- [ERROR_MARKER]: true,
57
- error,
58
- message,
59
- };
60
-
61
- return new Proxy(target, {
62
- get(_target, prop) {
63
- if (prop === ERROR_MARKER) return true;
64
- if (prop === "error") return error;
65
- if (prop === "message") return message;
66
- if (prop === Symbol.toPrimitive) return () => `[WrappedError: ${message}]`;
67
- if (prop === "toString") return () => `[WrappedError: ${message}]`;
68
- if (prop === "toJSON") return () => ({ __error: true, message });
69
-
70
- throw error;
71
- },
72
- has(_target, prop) {
73
- return prop === ERROR_MARKER || prop === "error" || prop === "message";
74
- },
75
- });
76
- }
77
-
78
- /**
79
- * Wrap a loader/action function to catch errors and return a proxy.
80
- *
81
- * @param fn - The loader or action function to wrap
82
- * @param onError - Optional error handler (for logging, metrics, etc.)
83
- */
84
- export function wrapCaughtErrors<TArgs extends unknown[], TReturn>(
85
- fn: (...args: TArgs) => Promise<TReturn>,
86
- onError?: (error: unknown, args: TArgs) => void,
87
- ): (...args: TArgs) => Promise<TReturn> {
88
- return async (...args: TArgs): Promise<TReturn> => {
89
- try {
90
- return await fn(...args);
91
- } catch (error) {
92
- onError?.(error, args);
93
-
94
- const isDev =
95
- typeof globalThis.process !== "undefined" &&
96
- globalThis.process.env?.NODE_ENV === "development";
97
- if (isDev) {
98
- console.error(
99
- `[wrapCaughtErrors] Loader failed:`,
100
- error instanceof Error ? error.message : error,
101
- );
102
- }
103
-
104
- return createErrorProxy(error) as TReturn;
105
- }
106
- };
107
- }
package/src/setup.ts DELETED
@@ -1,120 +0,0 @@
1
- /**
2
- * One-call site bootstrap for the framework-agnostic parts of a site:
3
- * section registration, matchers, blocks, and CMS-resolution error
4
- * handling. Sites that also need the admin protocol (meta schema, render
5
- * shell, preview wrapper, commerce-loader-to-invoke wiring) call
6
- * createAdminSetup() from @decocms/blocks-admin alongside this — the two
7
- * were one function before the package split; they're split here because
8
- * createAdminSetup's concerns require importing from admin, and
9
- * runtime cannot depend on admin without creating a circular
10
- * dependency (admin already depends on runtime).
11
- *
12
- * Everything site-specific (section loaders, cacheable sections, async
13
- * rendering, layout sections, commerce loaders, sync sections) remains in
14
- * the site's own setup file — createSiteSetup only handles the
15
- * framework-generic wiring.
16
- */
17
-
18
- import {
19
- loadBlocks,
20
- onBeforeResolve,
21
- registerSections,
22
- setBlocks,
23
- setDanglingReferenceHandler,
24
- setResolveErrorHandler,
25
- } from "./cms/index";
26
- import { registerBuiltinMatchers } from "./matchers/builtins";
27
- import { registerProductionOrigins } from "./sdk/normalizeUrls";
28
-
29
- export interface SiteSetupOptions {
30
- /**
31
- * Section glob from Vite — pass `import.meta.glob("./sections/**\/*.tsx")`.
32
- * Keys are transformed from `./sections/X.tsx` → `site/sections/X.tsx`.
33
- */
34
- sections: Record<string, () => Promise<any>>;
35
-
36
- /**
37
- * Generated blocks object — import and pass directly:
38
- * `import { blocks } from "../.deco/blocks.gen";` (`.deco/blocks.gen.ts`
39
- * is `generate-blocks.ts`'s default output location).
40
- */
41
- blocks: Record<string, unknown>;
42
-
43
- /** Production origins for URL normalization. */
44
- productionOrigins?: string[];
45
-
46
- /**
47
- * Custom matcher registrations to run alongside builtins.
48
- * Each function is called once during setup.
49
- */
50
- customMatchers?: Array<() => void>;
51
-
52
- /** Error handler for CMS resolution errors. */
53
- onResolveError?: (
54
- error: unknown,
55
- resolveType: string,
56
- context: string,
57
- ) => void;
58
-
59
- /** Handler for dangling CMS references (missing __resolveType targets). */
60
- onDanglingReference?: (resolveType: string) => any;
61
-
62
- /**
63
- * Called after blocks are loaded — use for platform initialization.
64
- * Also called on every onBeforeResolve (decofile hot-reload).
65
- */
66
- initPlatform?: (blocks: any) => void;
67
- }
68
-
69
- /**
70
- * Bootstrap a Deco site's framework-agnostic core — registers sections,
71
- * matchers, blocks, and error handlers. Call once at the top of your
72
- * setup.ts, before site-specific registrations, and alongside
73
- * createAdminSetup() (@decocms/blocks-admin) if the site also needs the
74
- * admin protocol.
75
- */
76
- export function createSiteSetup(options: SiteSetupOptions): void {
77
- // 1. Error handlers (set first so they catch issues during registration)
78
- if (options.onResolveError) {
79
- setResolveErrorHandler(options.onResolveError);
80
- }
81
- if (options.onDanglingReference) {
82
- setDanglingReferenceHandler(options.onDanglingReference);
83
- }
84
-
85
- // 2. Section glob registration — transform Vite paths to CMS keys
86
- const sections: Record<string, () => Promise<any>> = {};
87
- for (const [path, loader] of Object.entries(options.sections)) {
88
- sections[`site/${path.slice(2)}`] = loader;
89
- }
90
- registerSections(sections);
91
-
92
- // 3. Matchers
93
- registerBuiltinMatchers();
94
- if (options.customMatchers) {
95
- for (const register of options.customMatchers) {
96
- register();
97
- }
98
- }
99
-
100
- // 4. Production origins
101
- if (options.productionOrigins?.length) {
102
- registerProductionOrigins(options.productionOrigins);
103
- }
104
-
105
- // 5. Blocks + platform init (server-only)
106
- if (typeof document === "undefined") {
107
- setBlocks(options.blocks);
108
- if (options.initPlatform) {
109
- options.initPlatform(loadBlocks());
110
- }
111
- }
112
-
113
- // 6. onBeforeResolve — re-init platform on decofile hot-reload
114
- if (options.initPlatform) {
115
- const init = options.initPlatform;
116
- onBeforeResolve(() => {
117
- init(loadBlocks());
118
- });
119
- }
120
- }
@@ -1,53 +0,0 @@
1
- /**
2
- * Types that match @deco/deco's type exports.
3
- * These allow storefront sites to use the same type interfaces
4
- * without depending on the Deno-specific @deco/deco package.
5
- */
6
-
7
- /**
8
- * Compat context handed to ported deco.cx (Fresh) section loaders as the 3rd
9
- * argument (issue #305). `state` is the app state; `device`/`invoke`/`response`
10
- * mirror what Fresh's `ctx` exposed, and the index signature lets migrated
11
- * loaders read per-app state directly off `ctx` (`ctx.vtex`, `ctx.salesforce`).
12
- * Deep reads should still be optional-chained — an unconfigured app is
13
- * `undefined`. See `@decocms/blocks/cms`'s `SectionLoaderContext` for the
14
- * runtime shape.
15
- */
16
- export interface FnContext<TState = any> {
17
- state: TState;
18
- device?: "mobile" | "tablet" | "desktop";
19
- invoke?: any;
20
- response?: { headers: Headers };
21
- getAppState?: <T>(appName: string) => T | undefined;
22
- [key: string]: any;
23
- }
24
-
25
- export type App<TManifest = any, TState = any, TDeps extends any[] = any[]> = {
26
- state: TState;
27
- manifest: TManifest;
28
- dependencies?: TDeps;
29
- };
30
-
31
- export type AppContext<TApp extends App = App> = FnContext<TApp["state"]>;
32
-
33
- export type Section<TProps = any> = {
34
- Component: import("react").ComponentType<TProps>;
35
- props: TProps;
36
- };
37
-
38
- export type SectionProps<TLoader = any, TAction = TLoader> = TLoader extends (
39
- ...args: any[]
40
- ) => Promise<infer R>
41
- ? R
42
- : TLoader;
43
-
44
- export type Resolved<T> = T;
45
-
46
- export interface LoadingFallbackProps<TProps = any> {
47
- [key: string]: any;
48
- }
49
-
50
- export type Flag = {
51
- name: string;
52
- value: boolean;
53
- };
@@ -1,14 +0,0 @@
1
- /**
2
- * CMS admin widget type aliases.
3
- * These are string types that signal to the Deco CMS admin UI
4
- * which editor widget to render for a given prop.
5
- */
6
- export type ImageWidget = string;
7
- export type HTMLWidget = string;
8
- export type VideoWidget = string;
9
- export type TextWidget = string;
10
- export type RichText = string;
11
- export type Secret = string;
12
- export type Color = string;
13
- export type ButtonWidget = string;
14
- export type TextArea = string;