@decocms/blocks 7.72.0 → 8.1.0-next.0

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 (148) hide show
  1. package/bin/deco.js +13 -0
  2. package/package.json +32 -3
  3. package/src/cms/schema.ts +1 -1
  4. package/src/hooks/LiveControls.tsx +2 -0
  5. package/src/hooks/useLoadMore.ts +2 -0
  6. package/src/index.ts +37 -0
  7. package/src/protocol/assets.ts +124 -0
  8. package/src/protocol/canonical.ts +7 -0
  9. package/src/protocol/ciphertext.ts +6 -0
  10. package/src/protocol/client.ts +170 -0
  11. package/src/protocol/conformance/cases/assets.ts +81 -0
  12. package/src/protocol/conformance/cases/guards.ts +314 -0
  13. package/src/protocol/conformance/cases/reads.ts +168 -0
  14. package/src/protocol/conformance/cases/types.ts +9 -0
  15. package/src/protocol/conformance/cases/wire.ts +138 -0
  16. package/src/protocol/conformance/cases/writes.ts +345 -0
  17. package/src/protocol/conformance/contentHashFixtures.ts +79 -0
  18. package/src/protocol/conformance/context.ts +222 -0
  19. package/src/protocol/conformance/index.ts +140 -0
  20. package/src/protocol/errors.ts +142 -0
  21. package/src/protocol/index.ts +39 -0
  22. package/src/protocol/keys.ts +279 -0
  23. package/src/protocol/params.ts +67 -0
  24. package/src/protocol/secrets.ts +231 -0
  25. package/src/protocol/server/assets.ts +119 -0
  26. package/src/protocol/server/auth.ts +49 -0
  27. package/src/protocol/server/bodyCache.ts +84 -0
  28. package/src/protocol/server/content.ts +175 -0
  29. package/src/protocol/server/core.ts +112 -0
  30. package/src/protocol/server/handler.ts +102 -0
  31. package/src/protocol/server/http.ts +139 -0
  32. package/src/protocol/server/index.ts +11 -0
  33. package/src/protocol/server/methods/apply.ts +341 -0
  34. package/src/protocol/server/methods/read.ts +156 -0
  35. package/src/protocol/server/rpc.ts +136 -0
  36. package/src/protocol/storage/fs/hash.ts +21 -0
  37. package/src/protocol/storage/fs/index.ts +338 -0
  38. package/src/protocol/storage/fs/lock.ts +68 -0
  39. package/src/protocol/storage/fs/transaction.ts +183 -0
  40. package/src/protocol/storage/fs/unsupported.ts +15 -0
  41. package/src/protocol/storage/memory.ts +238 -0
  42. package/src/protocol/storage.ts +182 -0
  43. package/src/protocol/types.ts +172 -0
  44. package/src/v8/analytics.ts +50 -0
  45. package/src/v8/background.ts +107 -0
  46. package/src/v8/builtins/data.ts +23 -0
  47. package/src/v8/builtins/index.ts +26 -0
  48. package/src/v8/builtins/lazy.ts +23 -0
  49. package/src/v8/builtins/legacy.ts +65 -0
  50. package/src/v8/builtins/matchers.ts +31 -0
  51. package/src/v8/builtins/multivariate.ts +25 -0
  52. package/src/v8/builtins/secret.ts +82 -0
  53. package/src/v8/canonical.ts +117 -0
  54. package/src/v8/ciphertext.ts +158 -0
  55. package/src/v8/cli/builtins.ts +20 -0
  56. package/src/v8/cli/check/index.ts +774 -0
  57. package/src/v8/cli/check/messages.ts +168 -0
  58. package/src/v8/cli/content.ts +287 -0
  59. package/src/v8/cli/index.ts +17 -0
  60. package/src/v8/cli/log.ts +18 -0
  61. package/src/v8/cli/main.ts +12 -0
  62. package/src/v8/cli/root.ts +66 -0
  63. package/src/v8/cli/run.ts +236 -0
  64. package/src/v8/cli/schema/builtinSchemas.ts +236 -0
  65. package/src/v8/cli/schema/generate.ts +507 -0
  66. package/src/v8/cli/schema/index.ts +63 -0
  67. package/src/v8/cli/schema/tsProgram.ts +497 -0
  68. package/src/v8/cli/schema/typeToSchema.ts +689 -0
  69. package/src/v8/cli/serve/server.ts +303 -0
  70. package/src/v8/cli/watch.ts +86 -0
  71. package/src/v8/client.ts +147 -0
  72. package/src/v8/cms.ts +237 -0
  73. package/src/v8/content.ts +195 -0
  74. package/src/v8/draft.ts +136 -0
  75. package/src/v8/errors.ts +59 -0
  76. package/src/v8/fetch.ts +152 -0
  77. package/src/v8/identity.ts +65 -0
  78. package/src/v8/index.ts +39 -0
  79. package/src/v8/json.ts +74 -0
  80. package/src/v8/matchRoute.ts +204 -0
  81. package/src/v8/remoteLoader.ts +282 -0
  82. package/src/v8/resolver.ts +278 -0
  83. package/src/v8/secrets.ts +17 -0
  84. package/src/v8/telemetry.ts +533 -0
  85. package/src/v8/types.ts +240 -0
  86. package/src/cms/blockSource.test.ts +0 -76
  87. package/src/cms/client.browserBundle.test.ts +0 -44
  88. package/src/cms/deferredTrigger.test.ts +0 -32
  89. package/src/cms/draftSource.test.ts +0 -519
  90. package/src/cms/layoutCacheRace.test.ts +0 -181
  91. package/src/cms/loadDecofileDirectory.test.ts +0 -109
  92. package/src/cms/loader.test.ts +0 -557
  93. package/src/cms/registry.test.ts +0 -110
  94. package/src/cms/renderJson.test.ts +0 -167
  95. package/src/cms/resolve.test.ts +0 -1492
  96. package/src/cms/schema.test.ts +0 -356
  97. package/src/cms/sectionLoaderContext.test.ts +0 -111
  98. package/src/cms/sectionLoaders.test.ts +0 -625
  99. package/src/cms/sectionMixins.test.ts +0 -167
  100. package/src/cms/stickyFlags.test.ts +0 -117
  101. package/src/flags/flags.test.ts +0 -148
  102. package/src/hooks/Image.test.ts +0 -239
  103. package/src/hooks/RenderSection.test.tsx +0 -81
  104. package/src/hooks/Stats.test.ts +0 -112
  105. package/src/hooks/useLoadMore.test.ts +0 -205
  106. package/src/matchers/builtins.test.ts +0 -318
  107. package/src/matchers/override.test.ts +0 -205
  108. package/src/middleware/hydrationContext.test.ts +0 -61
  109. package/src/middleware/observability.test.ts +0 -335
  110. package/src/middleware/validateSection.test.ts +0 -147
  111. package/src/preview/DraftPreviewBadge.render.test.tsx +0 -67
  112. package/src/preview/DraftPreviewBadge.test.ts +0 -55
  113. package/src/sdk/abTesting.test.ts +0 -381
  114. package/src/sdk/cacheHeaders.test.ts +0 -258
  115. package/src/sdk/cacheStorage.test.ts +0 -242
  116. package/src/sdk/cachedLoader.test.ts +0 -122
  117. package/src/sdk/cachedLoaderMaxBytes.test.ts +0 -23
  118. package/src/sdk/cachedLoaderModule.test.ts +0 -209
  119. package/src/sdk/cachedLoaderSizeMetric.test.ts +0 -93
  120. package/src/sdk/cn.test.ts +0 -34
  121. package/src/sdk/composite.test.ts +0 -121
  122. package/src/sdk/cookie.test.ts +0 -108
  123. package/src/sdk/crypto.test.ts +0 -65
  124. package/src/sdk/deepOmit.test.ts +0 -45
  125. package/src/sdk/encoding.test.ts +0 -71
  126. package/src/sdk/env.test.ts +0 -33
  127. package/src/sdk/experiments.test.ts +0 -328
  128. package/src/sdk/fetchCache.test.ts +0 -164
  129. package/src/sdk/flags.test.ts +0 -91
  130. package/src/sdk/http.test.ts +0 -71
  131. package/src/sdk/inflightTimeout.test.ts +0 -35
  132. package/src/sdk/instrumentedFetch.test.ts +0 -559
  133. package/src/sdk/invoke.test.ts +0 -115
  134. package/src/sdk/logger.test.ts +0 -432
  135. package/src/sdk/otel.test.ts +0 -691
  136. package/src/sdk/otelAdapters.test.ts +0 -89
  137. package/src/sdk/otelHttpLog.test.ts +0 -457
  138. package/src/sdk/otelHttpMeter.test.ts +0 -395
  139. package/src/sdk/otelHttpTracer.test.ts +0 -474
  140. package/src/sdk/replaceStream.test.ts +0 -117
  141. package/src/sdk/requestContextStorage.browser.test.ts +0 -29
  142. package/src/sdk/splitExactRedirects.test.ts +0 -154
  143. package/src/sdk/urlRedaction.test.ts +0 -73
  144. package/src/sdk/urlUtils.test.ts +0 -34
  145. package/src/sdk/useDevice.test.ts +0 -130
  146. package/src/sdk/useScript.test.ts +0 -128
  147. package/src/sdk/useSuggestions.test.ts +0 -230
  148. package/tsconfig.json +0 -7
@@ -1,110 +0,0 @@
1
- import { beforeEach, describe, expect, it } from "vitest";
2
- import {
3
- getResolvedComponent,
4
- getSection,
5
- getSectionOptions,
6
- getSyncComponent,
7
- registerSection,
8
- registerSectionsSync,
9
- } from "./registry";
10
-
11
- // Reset globalThis.__deco between tests to avoid cross-test pollution
12
- beforeEach(() => {
13
- const G = globalThis as any;
14
- G.__deco.sectionRegistry = {};
15
- G.__deco.sectionOptions = {};
16
- G.__deco.resolvedComponents = {};
17
- G.__deco.syncComponents = {};
18
- });
19
-
20
- describe("registerSection + getSection", () => {
21
- it("registers and retrieves a section loader", () => {
22
- const loader = async () => ({ default: () => null });
23
- registerSection("site/sections/Hero.tsx", loader);
24
-
25
- const retrieved = getSection("site/sections/Hero.tsx");
26
- expect(retrieved).toBe(loader);
27
- });
28
-
29
- it("returns undefined for unregistered section", () => {
30
- expect(getSection("nonexistent")).toBeUndefined();
31
- });
32
- });
33
-
34
- describe("registerSection with options", () => {
35
- it("stores loadingFallback in section options", () => {
36
- const fallback = () => null;
37
- registerSection("site/sections/Shelf.tsx", async () => ({ default: () => null }), {
38
- loadingFallback: fallback,
39
- });
40
-
41
- const opts = getSectionOptions("site/sections/Shelf.tsx");
42
- expect(opts?.loadingFallback).toBe(fallback);
43
- });
44
-
45
- it("stores clientOnly flag in section options", () => {
46
- registerSection("site/sections/Analytics.tsx", async () => ({ default: () => null }), {
47
- clientOnly: true,
48
- });
49
-
50
- const opts = getSectionOptions("site/sections/Analytics.tsx");
51
- expect(opts?.clientOnly).toBe(true);
52
- });
53
-
54
- it("clientOnly defaults to undefined when not set", () => {
55
- registerSection("site/sections/Normal.tsx", async () => ({ default: () => null }), {
56
- loadingFallback: () => null,
57
- });
58
-
59
- const opts = getSectionOptions("site/sections/Normal.tsx");
60
- expect(opts?.clientOnly).toBeUndefined();
61
- });
62
-
63
- it("clientOnly false is preserved", () => {
64
- registerSection("site/sections/Explicit.tsx", async () => ({ default: () => null }), {
65
- clientOnly: false,
66
- });
67
-
68
- const opts = getSectionOptions("site/sections/Explicit.tsx");
69
- expect(opts?.clientOnly).toBe(false);
70
- });
71
-
72
- it("returns undefined options for section without options", () => {
73
- registerSection("site/sections/Plain.tsx", async () => ({ default: () => null }));
74
- expect(getSectionOptions("site/sections/Plain.tsx")).toBeUndefined();
75
- });
76
- });
77
-
78
- describe("registerSectionsSync", () => {
79
- it("registers component as sync and resolved", () => {
80
- const MyComponent = () => null;
81
- registerSectionsSync({ "site/sections/Header.tsx": MyComponent });
82
-
83
- expect(getSyncComponent("site/sections/Header.tsx")).toBe(MyComponent);
84
- expect(getResolvedComponent("site/sections/Header.tsx")).toBe(MyComponent);
85
- });
86
-
87
- it("accepts module objects with LoadingFallback", () => {
88
- const MyComponent = () => null;
89
- const MyFallback = () => null;
90
-
91
- registerSectionsSync({
92
- "site/sections/Footer.tsx": {
93
- default: MyComponent,
94
- LoadingFallback: MyFallback,
95
- },
96
- });
97
-
98
- expect(getSyncComponent("site/sections/Footer.tsx")).toBe(MyComponent);
99
- const opts = getSectionOptions("site/sections/Footer.tsx");
100
- expect(opts?.loadingFallback).toBe(MyFallback);
101
- });
102
-
103
- it("skips entries without callable default export", () => {
104
- registerSectionsSync({
105
- "site/sections/Bad.tsx": { default: "not a function" } as any,
106
- });
107
-
108
- expect(getSyncComponent("site/sections/Bad.tsx")).toBeUndefined();
109
- });
110
- });
@@ -1,167 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import {
3
- isSecretValue,
4
- type RenderJsonModule,
5
- serializeRenderJson,
6
- stringifyWithoutSecrets,
7
- } from "./renderJson";
8
-
9
- const modules: Record<string, RenderJsonModule> = {
10
- "site/sections/Product/ProductDetails.tsx": {
11
- renderJson: ({ storeConfig: _s, ...rest }) => rest,
12
- },
13
- "site/sections/Theme/Theme.tsx": { renderJson: false },
14
- "site/sections/Footer/Footer.tsx": {}, // no renderJson → full props
15
- };
16
- const getSectionModule = (c: string) => modules[c];
17
-
18
- describe("serializeRenderJson", () => {
19
- it("applies a projection function to the props", () => {
20
- const out = serializeRenderJson(
21
- [{ component: "site/sections/Product/ProductDetails.tsx", props: { storeConfig: {}, page: 1 } }],
22
- { getSectionModule },
23
- );
24
- expect(out).toEqual([
25
- { component: "site/sections/Product/ProductDetails.tsx", props: { page: 1 } },
26
- ]);
27
- });
28
-
29
- it("drops sections whose module exports renderJson === false", () => {
30
- const out = serializeRenderJson(
31
- [
32
- { component: "site/sections/Theme/Theme.tsx", props: { x: 1 } },
33
- { component: "site/sections/Footer/Footer.tsx", props: { y: 2 } },
34
- ],
35
- { getSectionModule },
36
- );
37
- expect(out).toEqual([{ component: "site/sections/Footer/Footer.tsx", props: { y: 2 } }]);
38
- });
39
-
40
- it("passes full props through when there is no renderJson export", () => {
41
- const out = serializeRenderJson([{ component: "site/sections/Footer/Footer.tsx", props: { y: 2 } }], {
42
- getSectionModule,
43
- });
44
- expect(out).toEqual([{ component: "site/sections/Footer/Footer.tsx", props: { y: 2 } }]);
45
- });
46
-
47
- it("drops sections by sectionsToIgnore suffix match on resolveType", () => {
48
- const out = serializeRenderJson(
49
- [
50
- { component: "website/sections/Seo/SeoV2.tsx", props: { title: "x" } },
51
- { component: "site/sections/Footer/Footer.tsx", props: { y: 2 } },
52
- ],
53
- { getSectionModule, sectionsToIgnore: ["SeoV2.tsx"] },
54
- );
55
- expect(out).toEqual([{ component: "site/sections/Footer/Footer.tsx", props: { y: 2 } }]);
56
- });
57
-
58
- it("ignores blank sectionsToIgnore entries (a '' suffix must not drop everything)", () => {
59
- const out = serializeRenderJson(
60
- [{ component: "site/sections/Footer/Footer.tsx", props: { y: 2 } }],
61
- { getSectionModule, sectionsToIgnore: ["", " "] },
62
- );
63
- expect(out).toHaveLength(1);
64
- });
65
-
66
- it("keeps full props when no getSectionModule is provided", () => {
67
- const out = serializeRenderJson([{ component: "a", props: { z: 1 } }]);
68
- expect(out).toEqual([{ component: "a", props: { z: 1 } }]);
69
- });
70
-
71
- it("defaults missing props to an empty object", () => {
72
- const out = serializeRenderJson([{ component: "a" }]);
73
- expect(out).toEqual([{ component: "a", props: {} }]);
74
- });
75
-
76
- it("strips framework-injected keys (__page*, device, isMobile) from props", () => {
77
- const out = serializeRenderJson(
78
- [
79
- {
80
- component: "a",
81
- props: {
82
- title: "keep",
83
- __pageUrl: "https://x/y",
84
- __pagePath: "/y",
85
- device: "mobile",
86
- isMobile: true,
87
- currentSearchParam: "q",
88
- },
89
- },
90
- ],
91
- // no projection → pass-through, but injected keys must still be stripped
92
- );
93
- expect(out).toEqual([{ component: "a", props: { title: "keep" } }]);
94
- });
95
-
96
- it("strips injected keys even when a projection rest-spreads them through", () => {
97
- const out = serializeRenderJson([{ component: "a", props: { keep: 1, __pageUrl: "u", device: "d" } }], {
98
- getSectionModule: () => ({ renderJson: (p: Record<string, unknown>) => p }), // identity passes __ through
99
- });
100
- expect(out).toEqual([{ component: "a", props: { keep: 1 } }]);
101
- });
102
-
103
- it("interleaves deferred sections as { component, lazyUrl } by index", () => {
104
- const out = serializeRenderJson(
105
- [
106
- { component: "site/sections/Footer/Footer.tsx", props: { y: 2 }, index: 2 },
107
- { component: "site/sections/Header.tsx", props: { h: 1 }, index: 0 },
108
- ],
109
- {
110
- getSectionModule,
111
- deferred: [{ component: "site/sections/Shelf.tsx", index: 1 }],
112
- lazyUrlFor: (ref) => `/p?renderJson&__lazy=${ref.index}`,
113
- },
114
- );
115
- expect(out).toEqual([
116
- { component: "site/sections/Header.tsx", props: { h: 1 } },
117
- { component: "site/sections/Shelf.tsx", lazyUrl: "/p?renderJson&__lazy=1" },
118
- { component: "site/sections/Footer/Footer.tsx", props: { y: 2 } },
119
- ]);
120
- });
121
-
122
- it("does not emit a lazyUrl for a dropped deferred section", () => {
123
- const out = serializeRenderJson([{ component: "site/sections/Header.tsx", props: {}, index: 0 }], {
124
- getSectionModule,
125
- sectionsToIgnore: ["SeoV2.tsx"],
126
- deferred: [
127
- { component: "website/sections/Seo/SeoV2.tsx", index: 1 }, // suffix-dropped
128
- { component: "site/sections/Theme/Theme.tsx", index: 2 }, // renderJson === false
129
- ],
130
- lazyUrlFor: (ref) => `/p?renderJson&__lazy=${ref.index}`,
131
- });
132
- expect(out).toEqual([{ component: "site/sections/Header.tsx", props: {} }]);
133
- });
134
- });
135
-
136
- describe("isSecretValue / stringifyWithoutSecrets", () => {
137
- it("detects a resolved Secret ({ get: fn }) and an unresolved secret block", () => {
138
- expect(isSecretValue({ get: () => "plaintext" })).toBe(true);
139
- expect(isSecretValue({ __resolveType: "website/loaders/secret.ts", encrypted: "x" })).toBe(true);
140
- });
141
-
142
- it("does not flag content that merely has a `get` method or other shapes", () => {
143
- expect(isSecretValue({ get: () => 1, other: true })).toBe(false); // extra key
144
- expect(isSecretValue({ token: "abc" })).toBe(false); // plaintext (undetectable by shape)
145
- expect(isSecretValue("just a string")).toBe(false);
146
- expect(isSecretValue(null)).toBe(false);
147
- });
148
-
149
- it("strips Secret-shaped values anywhere in the tree", () => {
150
- const payload = {
151
- title: "keep",
152
- apiKey: { get: () => "SECRET" }, // resolved Secret → dropped
153
- nested: { token: { get: () => "SECRET2" }, keep: 1 },
154
- list: [{ get: () => "S" }, { real: "item" }],
155
- block: { __resolveType: "website/loaders/secret.ts", encrypted: "enc" }, // dropped
156
- };
157
- const out = JSON.parse(stringifyWithoutSecrets(payload));
158
- expect(out).toEqual({
159
- title: "keep",
160
- nested: { keep: 1 },
161
- list: [null, { real: "item" }], // Secret element → null (array slot preserved)
162
- // apiKey and block are gone entirely
163
- });
164
- expect("apiKey" in out).toBe(false);
165
- expect("block" in out).toBe(false);
166
- });
167
- });