@decocms/blocks 7.72.0 → 8.0.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,230 +0,0 @@
1
- /**
2
- * Tests for the `createUseSuggestions` factory.
3
- *
4
- * The hook itself depends on React (useCallback). This file exercises
5
- * the parts of the factory that don't need a React renderer:
6
- * - factory shape + isolation between calls
7
- * - the non-React `_internal.setQuery` flow which carries every bit
8
- * of behaviour the React hook delegates to (queue, cancel guard,
9
- * loading-flag invariants, error path)
10
- *
11
- * Hook-level integration is exercised by the site-level smoke (the
12
- * factory has shipped to two production sites with the same shape).
13
- */
14
-
15
- import { describe, expect, it, vi } from "vitest";
16
- import { createUseSuggestions } from "./useSuggestions";
17
-
18
- interface FakeSuggestion {
19
- products: string[];
20
- }
21
-
22
- const FAKE_LOADER = {
23
- __resolveType: "site/loaders/search/suggestions.ts",
24
- limit: 5,
25
- } as unknown as FakeSuggestion;
26
-
27
- function makeOkFetch(payload: unknown, delayMs = 0): typeof fetch {
28
- return ((_input: RequestInfo | URL, _init?: RequestInit) =>
29
- new Promise((resolve) => {
30
- setTimeout(
31
- () =>
32
- resolve(
33
- new Response(JSON.stringify(payload), {
34
- status: 200,
35
- headers: { "Content-Type": "application/json" },
36
- }),
37
- ),
38
- delayMs,
39
- );
40
- })) as typeof fetch;
41
- }
42
-
43
- describe("createUseSuggestions — factory shape", () => {
44
- it("returns useSuggestions + _internal", () => {
45
- const f = createUseSuggestions<FakeSuggestion>();
46
- expect(typeof f.useSuggestions).toBe("function");
47
- expect(typeof f._internal.setQuery).toBe("function");
48
- expect(typeof f._internal.drain).toBe("function");
49
- expect(f._internal.payload.value).toBeNull();
50
- expect(f._internal.loading.value).toBe(false);
51
- });
52
-
53
- it("two factory calls produce independent state + functions", () => {
54
- const a = createUseSuggestions<FakeSuggestion>();
55
- const b = createUseSuggestions<FakeSuggestion>();
56
- expect(a.useSuggestions).not.toBe(b.useSuggestions);
57
- expect(a._internal.payload).not.toBe(b._internal.payload);
58
- expect(a._internal.loading).not.toBe(b._internal.loading);
59
- });
60
- });
61
-
62
- describe("createUseSuggestions — fetch happy path", () => {
63
- it("posts to /deco/invoke/<__resolveType> with the query + extra props", async () => {
64
- const spy = vi.fn(makeOkFetch({ products: ["a", "b"] }));
65
- const f = createUseSuggestions<FakeSuggestion>({ fetchImpl: spy });
66
- f._internal.setQuery("samsung", FAKE_LOADER);
67
- await f._internal.drain();
68
-
69
- expect(spy).toHaveBeenCalledTimes(1);
70
- const [url, init] = spy.mock.calls[0];
71
- expect(url).toBe("/deco/invoke/site/loaders/search/suggestions.ts");
72
- expect(init?.method).toBe("POST");
73
- expect(JSON.parse(init?.body as string)).toEqual({
74
- query: "samsung",
75
- limit: 5,
76
- });
77
- });
78
-
79
- it("populates payload with the parsed response", async () => {
80
- const f = createUseSuggestions<FakeSuggestion>({
81
- fetchImpl: makeOkFetch({ products: ["a", "b"] }),
82
- });
83
- f._internal.setQuery("samsung", FAKE_LOADER);
84
- await f._internal.drain();
85
- expect(f._internal.payload.value).toEqual({ products: ["a", "b"] });
86
- });
87
-
88
- it("flips loading to true synchronously, back to false after fetch settles", async () => {
89
- const f = createUseSuggestions<FakeSuggestion>({
90
- fetchImpl: makeOkFetch({ products: [] }),
91
- });
92
- expect(f._internal.loading.value).toBe(false);
93
- f._internal.setQuery("hi", FAKE_LOADER);
94
- expect(f._internal.loading.value).toBe(true);
95
- await f._internal.drain();
96
- expect(f._internal.loading.value).toBe(false);
97
- });
98
- });
99
-
100
- describe("createUseSuggestions — cancel + queue semantics", () => {
101
- it("cancels older queries BEFORE they fetch — only the latest hits the network", async () => {
102
- // Mock echoes the body's `query` field so we can tell which
103
- // invocation actually reached the network.
104
- const calls: string[] = [];
105
- const fetchImpl: typeof fetch = ((_url, init) => {
106
- const body = JSON.parse(init?.body as string) as { query: string };
107
- calls.push(body.query);
108
- return Promise.resolve(
109
- new Response(JSON.stringify({ products: [body.query] }), {
110
- status: 200,
111
- }),
112
- );
113
- }) as typeof fetch;
114
-
115
- const f = createUseSuggestions<FakeSuggestion>({ fetchImpl });
116
- // Three queries kicked off back-to-back synchronously.
117
- f._internal.setQuery("a", FAKE_LOADER);
118
- f._internal.setQuery("b", FAKE_LOADER);
119
- f._internal.setQuery("c", FAKE_LOADER);
120
- await f._internal.drain();
121
-
122
- // Only the latest query reaches the network — the cancel
123
- // guard short-circuits the first two before they fetch.
124
- expect(calls).toEqual(["c"]);
125
- expect(f._internal.payload.value).toEqual({ products: ["c"] });
126
- });
127
-
128
- it("the latest-query guard prevents stale fetches from clearing loading prematurely", async () => {
129
- // If the cancel guard ever regresses, this is the test that
130
- // catches it: we kick off fetch #1, immediately call setQuery
131
- // again, await drain, and expect the FINAL state to reflect
132
- // the latest query — not an inconsistent "loading false but
133
- // payload stale" mid-state.
134
- const fetchImpl = makeOkFetch({ products: ["latest"] }, 5);
135
- const f = createUseSuggestions<FakeSuggestion>({ fetchImpl });
136
- f._internal.setQuery("a", FAKE_LOADER);
137
- f._internal.setQuery("b", FAKE_LOADER);
138
- f._internal.setQuery("c", FAKE_LOADER);
139
- await f._internal.drain();
140
- expect(f._internal.loading.value).toBe(false);
141
- expect(f._internal.payload.value).toEqual({ products: ["latest"] });
142
- });
143
-
144
- it("queues serially — fetches don't run concurrently", async () => {
145
- // Race detector: track whether the count of in-flight fetches
146
- // ever exceeds 1.
147
- let inflight = 0;
148
- let maxInflight = 0;
149
- const fetchImpl: typeof fetch = (() =>
150
- new Promise<Response>((resolve) => {
151
- inflight += 1;
152
- maxInflight = Math.max(maxInflight, inflight);
153
- setTimeout(() => {
154
- inflight -= 1;
155
- resolve(
156
- new Response(JSON.stringify({ products: [] }), { status: 200 }),
157
- );
158
- }, 5);
159
- })) as typeof fetch;
160
-
161
- const f = createUseSuggestions<FakeSuggestion>({ fetchImpl });
162
- f._internal.setQuery("a", FAKE_LOADER);
163
- f._internal.setQuery("b", FAKE_LOADER);
164
- f._internal.setQuery("c", FAKE_LOADER);
165
- await f._internal.drain();
166
- expect(maxInflight).toBe(1);
167
- });
168
- });
169
-
170
- describe("createUseSuggestions — error path", () => {
171
- it("forwards thrown errors to onError + console.error, does NOT update payload", async () => {
172
- const onError = vi.fn();
173
- const consoleError = vi
174
- .spyOn(console, "error")
175
- .mockImplementation(() => {});
176
-
177
- const fetchImpl = (() =>
178
- Promise.reject(new Error("network down"))) as typeof fetch;
179
- const f = createUseSuggestions<FakeSuggestion>({ fetchImpl, onError });
180
-
181
- f._internal.setQuery("samsung", FAKE_LOADER);
182
- await f._internal.drain();
183
-
184
- expect(onError).toHaveBeenCalledTimes(1);
185
- const [err, query] = onError.mock.calls[0];
186
- expect((err as Error).message).toBe("network down");
187
- expect(query).toBe("samsung");
188
- expect(consoleError).toHaveBeenCalled();
189
- expect(f._internal.payload.value).toBeNull();
190
- expect(f._internal.loading.value).toBe(false);
191
-
192
- consoleError.mockRestore();
193
- });
194
-
195
- it("non-2xx responses surface as errors", async () => {
196
- const onError = vi.fn();
197
- const consoleError = vi
198
- .spyOn(console, "error")
199
- .mockImplementation(() => {});
200
- const fetchImpl = (() =>
201
- Promise.resolve(
202
- new Response("internal error", { status: 500 }),
203
- )) as typeof fetch;
204
- const f = createUseSuggestions<FakeSuggestion>({ fetchImpl, onError });
205
-
206
- f._internal.setQuery("x", FAKE_LOADER);
207
- await f._internal.drain();
208
-
209
- expect(onError).toHaveBeenCalledTimes(1);
210
- expect((onError.mock.calls[0][0] as Error).message).toContain("500");
211
- expect(f._internal.payload.value).toBeNull();
212
- expect(f._internal.loading.value).toBe(false);
213
-
214
- consoleError.mockRestore();
215
- });
216
-
217
- it("does NOT throw if onError is omitted (still console.errors)", async () => {
218
- const consoleError = vi
219
- .spyOn(console, "error")
220
- .mockImplementation(() => {});
221
- const fetchImpl = (() =>
222
- Promise.reject(new Error("boom"))) as typeof fetch;
223
- const f = createUseSuggestions<FakeSuggestion>({ fetchImpl });
224
-
225
- f._internal.setQuery("x", FAKE_LOADER);
226
- await expect(f._internal.drain()).resolves.toBeUndefined();
227
- expect(consoleError).toHaveBeenCalled();
228
- consoleError.mockRestore();
229
- });
230
- });
package/tsconfig.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "outDir": "dist"
5
- },
6
- "include": ["src/**/*", "package.json"]
7
- }