@uniformdev/canvas-next-rsc 19.69.0 → 19.73.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 (156) hide show
  1. package/dist/UniformComposition-38e22896.d.ts +61 -0
  2. package/dist/component.d.mts +76 -0
  3. package/dist/component.d.ts +76 -0
  4. package/dist/component.js +218 -0
  5. package/dist/component.mjs +182 -0
  6. package/dist/config.d.mts +6 -0
  7. package/dist/config.d.ts +6 -1
  8. package/dist/config.js +56 -29
  9. package/dist/config.mjs +41 -0
  10. package/dist/handler.d.mts +12 -0
  11. package/dist/handler.d.ts +12 -2
  12. package/dist/handler.js +703 -2
  13. package/dist/handler.mjs +682 -0
  14. package/dist/{client/manifestClient.d.ts → index.d.mts} +100 -18
  15. package/dist/index.d.ts +243 -23
  16. package/dist/index.esm.js +977 -0
  17. package/dist/index.js +1013 -29
  18. package/dist/index.mjs +977 -0
  19. package/package.json +23 -15
  20. package/dist/actions/updateContext.d.ts +0 -2
  21. package/dist/actions/updateContext.js +0 -17
  22. package/dist/client/canvasClient.d.ts +0 -5
  23. package/dist/client/canvasClient.js +0 -53
  24. package/dist/client/manifestClient.js +0 -33
  25. package/dist/client/projectMapClient.d.ts +0 -5
  26. package/dist/client/projectMapClient.js +0 -17
  27. package/dist/client/routeClient.d.ts +0 -5
  28. package/dist/client/routeClient.js +0 -68
  29. package/dist/components/DefaultNotImplementedComponent.d.ts +0 -2
  30. package/dist/components/DefaultNotImplementedComponent.js +0 -45
  31. package/dist/components/GoogleTagManagerAnalytics.d.ts +0 -3
  32. package/dist/components/GoogleTagManagerAnalytics.js +0 -44
  33. package/dist/components/UniformComponent.d.ts +0 -25
  34. package/dist/components/UniformComponent.js +0 -14
  35. package/dist/components/UniformComposition.d.ts +0 -40
  36. package/dist/components/UniformComposition.js +0 -35
  37. package/dist/components/UniformContext.d.ts +0 -8
  38. package/dist/components/UniformContext.js +0 -19
  39. package/dist/components/UniformRichText.d.ts +0 -38
  40. package/dist/components/UniformRichText.js +0 -15
  41. package/dist/components/UniformRichTextNode.d.ts +0 -10
  42. package/dist/components/UniformRichTextNode.js +0 -49
  43. package/dist/components/UniformScript.d.ts +0 -3
  44. package/dist/components/UniformScript.js +0 -49
  45. package/dist/components/UniformSlot.d.ts +0 -40
  46. package/dist/components/UniformSlot.js +0 -38
  47. package/dist/components/UniformText.d.ts +0 -6
  48. package/dist/components/UniformText.js +0 -5
  49. package/dist/components/__tests__/evaluateComposition.spec.d.ts +0 -1
  50. package/dist/components/__tests__/evaluateComposition.spec.js +0 -80
  51. package/dist/components/convertComponentToProps.d.ts +0 -14
  52. package/dist/components/convertComponentToProps.js +0 -22
  53. package/dist/components/evaluateComposition.d.ts +0 -22
  54. package/dist/components/evaluateComposition.js +0 -183
  55. package/dist/components/getEnrichmentTags.d.ts +0 -3
  56. package/dist/components/getEnrichmentTags.js +0 -13
  57. package/dist/components/getUniformContext.d.ts +0 -6
  58. package/dist/components/getUniformContext.js +0 -17
  59. package/dist/components/nodes/HeadingRichTextNode.d.ts +0 -2
  60. package/dist/components/nodes/HeadingRichTextNode.js +0 -6
  61. package/dist/components/nodes/LinebreakRichTextNode.d.ts +0 -2
  62. package/dist/components/nodes/LinebreakRichTextNode.js +0 -4
  63. package/dist/components/nodes/LinkRichTextNode.d.ts +0 -2
  64. package/dist/components/nodes/LinkRichTextNode.js +0 -6
  65. package/dist/components/nodes/ListItemRichTextNode.d.ts +0 -2
  66. package/dist/components/nodes/ListItemRichTextNode.js +0 -5
  67. package/dist/components/nodes/ListRichTextNode.d.ts +0 -2
  68. package/dist/components/nodes/ListRichTextNode.js +0 -6
  69. package/dist/components/nodes/ParagraphRichTextNode.d.ts +0 -2
  70. package/dist/components/nodes/ParagraphRichTextNode.js +0 -6
  71. package/dist/components/nodes/TabRichTextNode.d.ts +0 -2
  72. package/dist/components/nodes/TabRichTextNode.js +0 -4
  73. package/dist/components/nodes/TextRichTextNode.d.ts +0 -2
  74. package/dist/components/nodes/TextRichTextNode.js +0 -9
  75. package/dist/components/renderComponent.d.ts +0 -15
  76. package/dist/components/renderComponent.js +0 -52
  77. package/dist/components/resolvePath.d.ts +0 -5
  78. package/dist/components/resolvePath.js +0 -34
  79. package/dist/components/retrieveRoute.d.ts +0 -141
  80. package/dist/components/retrieveRoute.js +0 -146
  81. package/dist/components/types.d.ts +0 -11
  82. package/dist/components/types.js +0 -1
  83. package/dist/config/helpers.d.ts +0 -17
  84. package/dist/config/helpers.js +0 -34
  85. package/dist/config/models.d.ts +0 -51
  86. package/dist/config/models.js +0 -1
  87. package/dist/cookie/index.d.ts +0 -12
  88. package/dist/cookie/index.js +0 -21
  89. package/dist/handler/createPreviewGETRouteHandler.d.ts +0 -1
  90. package/dist/handler/createPreviewGETRouteHandler.js +0 -43
  91. package/dist/handler/createPreviewPOSTRouteHandler.d.ts +0 -1
  92. package/dist/handler/createPreviewPOSTRouteHandler.js +0 -88
  93. package/dist/handler/createUniformRouteHandler.d.ts +0 -4
  94. package/dist/handler/createUniformRouteHandler.js +0 -10
  95. package/dist/handler/helpers.d.ts +0 -19
  96. package/dist/handler/helpers.js +0 -148
  97. package/dist/handler/messages/handleCompositionChanged.d.ts +0 -2
  98. package/dist/handler/messages/handleCompositionChanged.js +0 -9
  99. package/dist/handler/messages/handleCompositionDeleted.d.ts +0 -2
  100. package/dist/handler/messages/handleCompositionDeleted.js +0 -9
  101. package/dist/handler/messages/handleCompositionPublished.d.ts +0 -2
  102. package/dist/handler/messages/handleCompositionPublished.js +0 -9
  103. package/dist/handler/messages/handleManifestPublished.d.ts +0 -2
  104. package/dist/handler/messages/handleManifestPublished.js +0 -10
  105. package/dist/handler/messages/handleProjectMapNodeDelete.d.ts +0 -2
  106. package/dist/handler/messages/handleProjectMapNodeDelete.js +0 -21
  107. package/dist/handler/messages/handleProjectMapNodeInsert.d.ts +0 -2
  108. package/dist/handler/messages/handleProjectMapNodeInsert.js +0 -21
  109. package/dist/handler/messages/handleProjectMapNodeUpdate.d.ts +0 -2
  110. package/dist/handler/messages/handleProjectMapNodeUpdate.js +0 -22
  111. package/dist/handler/messages/handleRedirectDelete.d.ts +0 -2
  112. package/dist/handler/messages/handleRedirectDelete.js +0 -15
  113. package/dist/handler/messages/handleRedirectInsert.d.ts +0 -2
  114. package/dist/handler/messages/handleRedirectInsert.js +0 -15
  115. package/dist/handler/messages/handleRedirectUpdate.d.ts +0 -2
  116. package/dist/handler/messages/handleRedirectUpdate.js +0 -15
  117. package/dist/hooks/useForgetMe.d.ts +0 -4
  118. package/dist/hooks/useForgetMe.js +0 -10
  119. package/dist/hooks/useToggleConsent.d.ts +0 -7
  120. package/dist/hooks/useToggleConsent.js +0 -22
  121. package/dist/hooks/useUniformContext.d.ts +0 -1
  122. package/dist/hooks/useUniformContext.js +0 -3
  123. package/dist/models/index.d.ts +0 -30
  124. package/dist/models/index.js +0 -1
  125. package/dist/register/componentStore.d.ts +0 -1
  126. package/dist/register/componentStore.js +0 -2
  127. package/dist/register/componentStoreResolver.d.ts +0 -2
  128. package/dist/register/componentStoreResolver.js +0 -5
  129. package/dist/register/createComponentStore.d.ts +0 -12
  130. package/dist/register/createComponentStore.js +0 -13
  131. package/dist/register/createComponentStoreResolver.d.ts +0 -9
  132. package/dist/register/createComponentStoreResolver.js +0 -9
  133. package/dist/register/getTypeWithVariant.d.ts +0 -1
  134. package/dist/register/getTypeWithVariant.js +0 -1
  135. package/dist/register/registerUniformComponent.d.ts +0 -6
  136. package/dist/register/registerUniformComponent.js +0 -8
  137. package/dist/resolve/resolveChildren.d.ts +0 -10
  138. package/dist/resolve/resolveChildren.js +0 -20
  139. package/dist/score/index.d.ts +0 -3
  140. package/dist/score/index.js +0 -114
  141. package/dist/utils/__tests__/apply.spec.d.ts +0 -1
  142. package/dist/utils/__tests__/apply.spec.js +0 -358
  143. package/dist/utils/__tests__/diff.spec.d.ts +0 -1
  144. package/dist/utils/__tests__/diff.spec.js +0 -394
  145. package/dist/utils/apply.d.ts +0 -6
  146. package/dist/utils/apply.js +0 -124
  147. package/dist/utils/comp.d.ts +0 -16
  148. package/dist/utils/comp.js +0 -65
  149. package/dist/utils/diff.d.ts +0 -44
  150. package/dist/utils/diff.js +0 -144
  151. package/dist/utils/draft.d.ts +0 -12
  152. package/dist/utils/draft.js +0 -22
  153. package/dist/utils/tag.d.ts +0 -2
  154. package/dist/utils/tag.js +0 -7
  155. package/dist/utils/url.d.ts +0 -1
  156. package/dist/utils/url.js +0 -10
package/dist/index.mjs ADDED
@@ -0,0 +1,977 @@
1
+ // src/index.ts
2
+ import "server-only";
3
+
4
+ // src/clients/canvasClient.ts
5
+ import { CanvasClient } from "@uniformdev/canvas";
6
+
7
+ // src/config/helpers.ts
8
+ import { getServerConfig } from "@uniformdev/canvas-next-rsc-shared";
9
+
10
+ // src/utils/draft.ts
11
+ import { IN_CONTEXT_EDITOR_QUERY_STRING_PARAM } from "@uniformdev/canvas";
12
+ import { draftMode } from "next/headers";
13
+ var isDraftModeEnabled = ({
14
+ searchParams
15
+ }) => {
16
+ if (isDevelopmentEnvironment()) {
17
+ return isIncontextEditingEnabled({ searchParams });
18
+ }
19
+ let draftModeEnabled = false;
20
+ try {
21
+ draftModeEnabled = draftMode().isEnabled;
22
+ } catch (e) {
23
+ }
24
+ return draftModeEnabled || isIncontextEditingEnabled({ searchParams });
25
+ };
26
+ var isIncontextEditingEnabled = ({
27
+ searchParams
28
+ }) => {
29
+ const containsKey = typeof (searchParams == null ? void 0 : searchParams[IN_CONTEXT_EDITOR_QUERY_STRING_PARAM]) !== "undefined";
30
+ return containsKey;
31
+ };
32
+ var isOnVercelPreviewEnvironment = () => {
33
+ return process.env.VERCEL_ENV === "preview";
34
+ };
35
+ var isDevelopmentEnvironment = () => {
36
+ return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
37
+ };
38
+
39
+ // src/config/helpers.ts
40
+ var shouldCacheBeDisabled = (options) => {
41
+ if (isDraftModeEnabled(options)) {
42
+ return { disabled: true, reason: "DRAFT" };
43
+ }
44
+ if (isIncontextEditingEnabled(options)) {
45
+ return { disabled: true, reason: "INCONTEXT" };
46
+ }
47
+ if (isDevelopmentEnvironment()) {
48
+ return { disabled: true, reason: "DEV" };
49
+ }
50
+ return {
51
+ disabled: false,
52
+ reason: void 0
53
+ };
54
+ };
55
+ var getCanvasCacheStrategy = (options) => {
56
+ const { disabled, reason } = shouldCacheBeDisabled(options);
57
+ const config = getServerConfig();
58
+ if (disabled) {
59
+ if (reason === "DEV" && config.canvasCache) {
60
+ console.warn("Canvas cache (disabled) has been overridden by canvasCache config.");
61
+ return config.canvasCache;
62
+ }
63
+ return {
64
+ type: "no-cache"
65
+ };
66
+ }
67
+ if (config.canvasCache) {
68
+ return config.canvasCache;
69
+ }
70
+ return {
71
+ type: "force-cache"
72
+ };
73
+ };
74
+ var getManifestCacheStrategy = (options) => {
75
+ const { disabled, reason } = shouldCacheBeDisabled(options);
76
+ const config = getServerConfig();
77
+ if (disabled) {
78
+ if (reason === "DEV" && config.manifestCache) {
79
+ console.warn("Manifest cache (disabled) has been overridden by manifestCache config.");
80
+ return config.manifestCache;
81
+ }
82
+ return {
83
+ type: "no-cache"
84
+ };
85
+ }
86
+ if (config.manifestCache) {
87
+ return config.manifestCache;
88
+ }
89
+ return {
90
+ type: "force-cache"
91
+ };
92
+ };
93
+ var getProjectMapCacheStrategy = (options) => {
94
+ const { disabled, reason } = shouldCacheBeDisabled(options);
95
+ const config = getServerConfig();
96
+ if (disabled) {
97
+ if (reason === "DEV" && config.projectMapCache) {
98
+ console.warn("Project map cache (disabled) has been overridden by projectMapCache config.");
99
+ return config.projectMapCache;
100
+ }
101
+ return {
102
+ type: "no-cache"
103
+ };
104
+ }
105
+ if (config.projectMapCache) {
106
+ return config.projectMapCache;
107
+ }
108
+ return {
109
+ type: "force-cache"
110
+ };
111
+ };
112
+
113
+ // src/env/index.ts
114
+ var env = {
115
+ getProjectId: () => {
116
+ return process.env.UNIFORM_PROJECT_ID;
117
+ },
118
+ getApiKey: () => {
119
+ return process.env.UNIFORM_API_KEY;
120
+ },
121
+ getApiHost: () => {
122
+ return process.env.UNIFORM_API_HOST || process.env.UNIFORM_CLI_BASE_URL;
123
+ },
124
+ getEdgeApiHost: () => {
125
+ return process.env.UNIFORM_EDGE_API_HOST || process.env.UNIFORM_CLI_BASE_EDGE_URL;
126
+ }
127
+ };
128
+
129
+ // src/utils/tag.ts
130
+ var buildPathTag = (path) => {
131
+ const actualPath = path.startsWith("/") ? path : `/${path}`;
132
+ return `path:${actualPath}`.toLowerCase();
133
+ };
134
+ var buildCompositionTag = (compositionId) => {
135
+ return `composition:${compositionId}`.toLowerCase();
136
+ };
137
+
138
+ // src/clients/shared.ts
139
+ var determineFetchCacheOptions = (mode) => {
140
+ let cache = void 0;
141
+ let revalidate = void 0;
142
+ if (mode.type === "revalidate") {
143
+ cache = void 0;
144
+ revalidate = mode.interval;
145
+ } else {
146
+ cache = mode.type;
147
+ }
148
+ return {
149
+ cache,
150
+ revalidate
151
+ };
152
+ };
153
+
154
+ // src/clients/canvasClient.ts
155
+ var getCanvasClient = (options) => {
156
+ return new CanvasClient({
157
+ projectId: env.getProjectId(),
158
+ apiHost: env.getApiHost(),
159
+ apiKey: env.getApiKey(),
160
+ edgeApiHost: env.getEdgeApiHost(),
161
+ fetch: (req, init) => {
162
+ let requestedUrl;
163
+ if (typeof req === "string") {
164
+ requestedUrl = new URL(req);
165
+ } else if (req instanceof URL) {
166
+ requestedUrl = req;
167
+ } else {
168
+ requestedUrl = new URL(req.url);
169
+ }
170
+ const tags = [];
171
+ if (requestedUrl) {
172
+ const compositionIdKey = "compositionId";
173
+ const compositionIdsKey = "compositionIDs";
174
+ const compositionId = requestedUrl.searchParams.get(compositionIdKey);
175
+ const compositionIds = requestedUrl.searchParams.get(compositionIdsKey);
176
+ if (compositionId) {
177
+ tags.push(buildCompositionTag(compositionId));
178
+ }
179
+ if (compositionIds) {
180
+ const ids = compositionIds.split(",");
181
+ for (let i = 0; i < ids.length; i++) {
182
+ tags.push(buildCompositionTag(ids[i]));
183
+ }
184
+ }
185
+ }
186
+ const { cache, revalidate } = determineFetchCacheOptions(options.cache);
187
+ return fetch(req, {
188
+ ...init,
189
+ cache,
190
+ headers: {
191
+ ...init == null ? void 0 : init.headers,
192
+ "x-bypass-cache": "true"
193
+ },
194
+ next: {
195
+ revalidate
196
+ }
197
+ });
198
+ }
199
+ });
200
+ };
201
+ var getDefaultCanvasClient = ({
202
+ searchParams
203
+ }) => {
204
+ return getCanvasClient({
205
+ cache: getCanvasCacheStrategy({
206
+ searchParams
207
+ })
208
+ });
209
+ };
210
+
211
+ // src/clients/manifestClient.ts
212
+ import { ManifestClient } from "@uniformdev/context/api";
213
+ var getManifestClient = (options) => {
214
+ const manifestClient = new ManifestClient({
215
+ apiHost: env.getApiHost(),
216
+ apiKey: env.getApiKey(),
217
+ projectId: env.getProjectId(),
218
+ fetch: (req, init) => {
219
+ const { cache, revalidate } = determineFetchCacheOptions(options.cache);
220
+ return fetch(req, {
221
+ ...init,
222
+ headers: {
223
+ ...init == null ? void 0 : init.headers,
224
+ "x-bypass-cache": "true"
225
+ },
226
+ cache,
227
+ next: {
228
+ revalidate,
229
+ tags: ["manifest"]
230
+ }
231
+ });
232
+ }
233
+ });
234
+ return manifestClient;
235
+ };
236
+ var getDefaultManifestClient = ({
237
+ searchParams
238
+ }) => {
239
+ return getManifestClient({
240
+ cache: getManifestCacheStrategy({
241
+ searchParams
242
+ })
243
+ });
244
+ };
245
+ var getManifest = ({ searchParams }) => {
246
+ const manifestClient = getDefaultManifestClient({
247
+ searchParams
248
+ });
249
+ return manifestClient.get();
250
+ };
251
+
252
+ // src/clients/projectMapClient.ts
253
+ import { ProjectMapClient } from "@uniformdev/project-map";
254
+ var getProjectMapClient = (options) => {
255
+ const manifestClient = new ProjectMapClient({
256
+ apiHost: env.getApiHost(),
257
+ apiKey: env.getApiKey(),
258
+ projectId: env.getProjectId(),
259
+ fetch: (req, init) => {
260
+ const { cache, revalidate } = determineFetchCacheOptions(options.cache);
261
+ return fetch(req, {
262
+ ...init,
263
+ headers: {
264
+ ...init == null ? void 0 : init.headers,
265
+ "x-bypass-cache": "true"
266
+ },
267
+ cache,
268
+ next: {
269
+ revalidate
270
+ }
271
+ });
272
+ }
273
+ });
274
+ return manifestClient;
275
+ };
276
+ var getDefaultProjectMapClient = ({
277
+ searchParams
278
+ }) => {
279
+ return getProjectMapClient({
280
+ cache: getProjectMapCacheStrategy({
281
+ searchParams
282
+ })
283
+ });
284
+ };
285
+
286
+ // src/clients/routeClient.ts
287
+ import { RouteClient } from "@uniformdev/canvas";
288
+ var getRouteClient = (options) => {
289
+ const client = new RouteClient({
290
+ projectId: env.getProjectId(),
291
+ apiKey: env.getApiKey(),
292
+ edgeApiHost: env.getEdgeApiHost(),
293
+ fetch: (req, init) => {
294
+ let requestedUrl;
295
+ if (typeof req === "string") {
296
+ requestedUrl = new URL(req);
297
+ } else if (req instanceof URL) {
298
+ requestedUrl = req;
299
+ } else {
300
+ requestedUrl = new URL(req.url);
301
+ }
302
+ const tags = [];
303
+ if (requestedUrl) {
304
+ const pathKey = "path";
305
+ const path = requestedUrl.searchParams.get(pathKey);
306
+ if (path) {
307
+ const pieces = path.split("/");
308
+ for (let i = 0; i < pieces.length; i++) {
309
+ const segmentPieces = pieces.slice(0, i + 1);
310
+ const segment = segmentPieces.join("/");
311
+ tags.push(buildPathTag(segment));
312
+ }
313
+ }
314
+ }
315
+ const { cache, revalidate } = determineFetchCacheOptions(options.cache);
316
+ return fetch(req, {
317
+ ...init,
318
+ headers: {
319
+ ...init == null ? void 0 : init.headers,
320
+ "x-bypass-cache": "true"
321
+ },
322
+ cache,
323
+ next: {
324
+ revalidate,
325
+ tags: tags.length ? tags : void 0
326
+ }
327
+ });
328
+ }
329
+ });
330
+ return client;
331
+ };
332
+ var getDefaultRouteClient = ({ searchParams }) => {
333
+ return getRouteClient({
334
+ cache: getCanvasCacheStrategy({
335
+ searchParams
336
+ })
337
+ });
338
+ };
339
+
340
+ // src/components/ContextUpdateTransfer.tsx
341
+ import { ContextUpdateTransferClient } from "@uniformdev/canvas-next-rsc-client";
342
+ import React from "react";
343
+ var ContextUpdateTransfer = async ({
344
+ update,
345
+ serverContext
346
+ }) => {
347
+ const result = typeof update === "function" ? await update() : update;
348
+ if (!result) {
349
+ return null;
350
+ }
351
+ if (serverContext) {
352
+ await serverContext.__INTERNAL__.update(result);
353
+ }
354
+ return /* @__PURE__ */ React.createElement(ContextUpdateTransferClient, { ts: (/* @__PURE__ */ new Date()).valueOf(), update: result });
355
+ };
356
+
357
+ // src/components/generateStaticParams.ts
358
+ var createStaticParams = async (options) => {
359
+ var _a, _b;
360
+ const { expand } = options != null ? options : {};
361
+ const client = getProjectMapClient({
362
+ cache: {
363
+ type: "no-cache"
364
+ }
365
+ });
366
+ const { nodes } = await client.getNodes({});
367
+ const resolvedPaths = [];
368
+ if (nodes) {
369
+ for (let i = 0; i < nodes.length; i++) {
370
+ const node = nodes[i];
371
+ const isDynamic = node.path.includes(":");
372
+ if (!isDynamic) {
373
+ resolvedPaths.push(node.path);
374
+ } else if (expand) {
375
+ const expandedPaths = (_a = await expand(node)) != null ? _a : [];
376
+ resolvedPaths.push(...expandedPaths);
377
+ }
378
+ }
379
+ }
380
+ return (_b = resolvedPaths == null ? void 0 : resolvedPaths.map((path) => {
381
+ return {
382
+ path: path.split("/").filter(Boolean)
383
+ };
384
+ })) != null ? _b : [];
385
+ };
386
+ async function generateStaticParams() {
387
+ return createStaticParams();
388
+ }
389
+
390
+ // src/components/UniformComposition.ts
391
+ import {
392
+ CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE2,
393
+ CANVAS_EDITOR_STATE as CANVAS_EDITOR_STATE2,
394
+ CANVAS_ENRICHMENT_TAG_PARAM,
395
+ CANVAS_PERSONALIZE_TYPE,
396
+ CANVAS_TEST_TYPE,
397
+ walkNodeTree
398
+ } from "@uniformdev/canvas";
399
+ import { ClientContextualEditingComponentWrapper, TestClient } from "@uniformdev/canvas-next-rsc-client";
400
+ import {
401
+ getServerConfig as getServerConfig3,
402
+ resolvePath as resolvePath2
403
+ } from "@uniformdev/canvas-next-rsc-shared";
404
+ import { PureContextualEditingComponentWrapper } from "@uniformdev/canvas-react/core";
405
+ import { cookies as cookies2, headers } from "next/headers";
406
+ import { notFound, redirect } from "next/navigation";
407
+ import { createElement as createElement3, Fragment as Fragment3 } from "react";
408
+
409
+ // src/context/createServerUniformContext.ts
410
+ import {
411
+ createUniformContext
412
+ } from "@uniformdev/canvas-next-rsc-shared";
413
+ import { UNIFORM_DEFAULT_COOKIE_NAME } from "@uniformdev/context";
414
+ import { cookies } from "next/headers";
415
+ var createServerUniformContext = async (options) => {
416
+ const manifest = await getManifest(options);
417
+ const context = createServerUniformContextFromManifest({
418
+ ...options || {},
419
+ manifest
420
+ });
421
+ return context;
422
+ };
423
+ var createServerUniformContextFromManifest = async (options) => {
424
+ var _a;
425
+ const context = createUniformContext({
426
+ ...options || {},
427
+ serverCookieValue: (_a = cookies().get(UNIFORM_DEFAULT_COOKIE_NAME)) == null ? void 0 : _a.value
428
+ });
429
+ return {
430
+ ...context,
431
+ __INTERNAL__: {
432
+ update: (...props) => context.update(...props)
433
+ }
434
+ };
435
+ };
436
+
437
+ // src/utils/route.ts
438
+ import {
439
+ CANVAS_DRAFT_STATE,
440
+ CANVAS_EDITOR_STATE,
441
+ CANVAS_PUBLISHED_STATE
442
+ } from "@uniformdev/canvas";
443
+ import { getBaseUrl, getServerConfig as getServerConfig2, resolvePath } from "@uniformdev/canvas-next-rsc-shared";
444
+ import { getTargetVariableExpandedUrl } from "@uniformdev/redirect";
445
+ var retrieveRoute = async ({
446
+ params,
447
+ searchParams
448
+ }) => {
449
+ const { type, value } = resolvePath({
450
+ params
451
+ });
452
+ const states = determineState({
453
+ searchParams
454
+ });
455
+ let result;
456
+ for (let i = 0; i < states.length; i++) {
457
+ const state = states[i];
458
+ if (type === "path") {
459
+ try {
460
+ result = await retrieveRouteByPath({
461
+ path: value,
462
+ state,
463
+ searchParams
464
+ });
465
+ } catch (e) {
466
+ console.warn(`Failed to retrieve route by path: ${value} with state ${state}`, e);
467
+ }
468
+ } else if (type === "slug") {
469
+ const canvasClient = getDefaultCanvasClient({
470
+ searchParams
471
+ });
472
+ try {
473
+ const composition = await canvasClient.getCompositionBySlug({
474
+ slug: value,
475
+ state
476
+ });
477
+ result = {
478
+ type: "composition",
479
+ compositionApiResponse: composition,
480
+ matchedRoute: "slug"
481
+ };
482
+ } catch (e) {
483
+ console.warn(`Failed to retrieve composition by slug: ${value} with state ${state}`, e);
484
+ }
485
+ }
486
+ if ((result == null ? void 0 : result.type) !== "notFound") {
487
+ break;
488
+ }
489
+ }
490
+ if (!result) {
491
+ return void 0;
492
+ }
493
+ return {
494
+ ...result,
495
+ path: value
496
+ };
497
+ };
498
+ var retrieveRouteByPath = async ({
499
+ path,
500
+ state,
501
+ searchParams
502
+ }) => {
503
+ var _a;
504
+ const client = getDefaultRouteClient({
505
+ searchParams
506
+ });
507
+ return await client.getRoute({
508
+ path,
509
+ state,
510
+ withComponentIDs: true,
511
+ withContentSourceMap: isOnVercelPreviewEnvironment() && ((_a = getServerConfig2().experimental) == null ? void 0 : _a.vercelVisualEditing)
512
+ });
513
+ };
514
+ var resolveRedirectHref = (resolveResult, path) => {
515
+ let href;
516
+ if (resolveResult.redirect.targetProjectMapNodeId) {
517
+ const requestUrl = `${getBaseUrl()}${path}`;
518
+ const expandedUrl = getTargetVariableExpandedUrl(requestUrl, resolveResult.redirect);
519
+ const url = new URL(expandedUrl);
520
+ href = url.pathname;
521
+ } else {
522
+ href = resolveResult.redirect.targetUrl;
523
+ }
524
+ return href;
525
+ };
526
+ var determineState = ({ searchParams }) => {
527
+ const draftMode2 = isDraftModeEnabled({ searchParams });
528
+ const previewEnvironment = isOnVercelPreviewEnvironment();
529
+ const isDevelopment = isDevelopmentEnvironment();
530
+ const isCanvasEditing = isIncontextEditingEnabled({
531
+ searchParams
532
+ });
533
+ let states;
534
+ if (isCanvasEditing) {
535
+ states = [CANVAS_EDITOR_STATE, CANVAS_DRAFT_STATE];
536
+ } else {
537
+ states = draftMode2 || previewEnvironment || isDevelopment ? [CANVAS_DRAFT_STATE] : [CANVAS_PUBLISHED_STATE];
538
+ }
539
+ return states;
540
+ };
541
+
542
+ // src/components/ContextUpdateTrigger.tsx
543
+ import { ClientContextUpdate } from "@uniformdev/canvas-next-rsc-client";
544
+ import React2 from "react";
545
+ var ContextUpdateTrigger = () => {
546
+ return /* @__PURE__ */ React2.createElement(ClientContextUpdate, null);
547
+ };
548
+
549
+ // src/components/PersonalizeClientWrapper.tsx
550
+ import { PersonalizeClient } from "@uniformdev/canvas-next-rsc-client";
551
+ import { runPersonalization } from "@uniformdev/canvas-next-rsc-shared";
552
+ import React3 from "react";
553
+ var PersonalizeClientWrapper = (props) => {
554
+ const { indexes } = runPersonalization({
555
+ ...props,
556
+ contextInstance: void 0
557
+ });
558
+ return /* @__PURE__ */ React3.createElement(PersonalizeClient, { ...props, indexes });
559
+ };
560
+
561
+ // src/components/PersonalizeServer.ts
562
+ import { CANVAS_PERSONALIZE_SLOT } from "@uniformdev/canvas";
563
+ import { runPersonalization as runPersonalization2 } from "@uniformdev/canvas-next-rsc-shared";
564
+ import { createElement, Fragment } from "react";
565
+ var PersonalizeServer = (props) => {
566
+ var _a;
567
+ const { indexes } = runPersonalization2(props);
568
+ const slot = (_a = props.slots) == null ? void 0 : _a[CANVAS_PERSONALIZE_SLOT];
569
+ const components = indexes.map((index) => {
570
+ const component = slot.items[index];
571
+ return component;
572
+ });
573
+ return createElement(Fragment, void 0, components);
574
+ };
575
+
576
+ // src/components/TestServer.ts
577
+ import { CANVAS_TEST_SLOT, CANVAS_TEST_VARIANT_PARAM } from "@uniformdev/canvas";
578
+ import { createElement as createElement2, Fragment as Fragment2 } from "react";
579
+ var TestServer = ({ test, component, contextInstance, slots }) => {
580
+ var _a, _b, _c;
581
+ const slot = ((_a = component.slots) == null ? void 0 : _a[CANVAS_TEST_SLOT]) || [];
582
+ const { result } = contextInstance.test({
583
+ name: test,
584
+ variations: slot.map((v, i) => {
585
+ var _a2, _b2, _c2;
586
+ const contextTag = (_b2 = (_a2 = v.parameters) == null ? void 0 : _a2[CANVAS_TEST_VARIANT_PARAM]) == null ? void 0 : _b2.value;
587
+ const id = (_c2 = contextTag == null ? void 0 : contextTag.id) != null ? _c2 : "testId" in v ? v.testId : `ab-${i}-${v.type}`;
588
+ return {
589
+ id,
590
+ testDistribution: contextTag == null ? void 0 : contextTag.testDistribution,
591
+ index: i
592
+ };
593
+ })
594
+ });
595
+ const components = result ? (_c = (_b = slots == null ? void 0 : slots[CANVAS_TEST_SLOT]) == null ? void 0 : _b.items[result.index]) != null ? _c : null : null;
596
+ return createElement2(Fragment2, void 0, components);
597
+ };
598
+
599
+ // src/components/UniformComposition.ts
600
+ var UniformComposition = async ({
601
+ resolveComponent,
602
+ ...props
603
+ }) => {
604
+ let searchParams;
605
+ let serverContext = void 0;
606
+ if (props.mode === "static") {
607
+ searchParams = void 0;
608
+ } else if (props.mode === "server") {
609
+ serverContext = props.serverContext || await createServerUniformContext({
610
+ searchParams: props.searchParams
611
+ });
612
+ searchParams = props.searchParams;
613
+ }
614
+ let route = void 0;
615
+ if (props.composition) {
616
+ const { value } = resolvePath2(props);
617
+ route = {
618
+ type: "composition",
619
+ compositionApiResponse: props.composition,
620
+ matchedRoute: "composition",
621
+ path: value
622
+ };
623
+ } else {
624
+ route = await retrieveRoute({
625
+ params: props.params,
626
+ searchParams
627
+ });
628
+ }
629
+ if (!route || route.type === "notFound") {
630
+ notFound();
631
+ }
632
+ if (route.type === "redirect") {
633
+ const href = resolveRedirectHref(route, route.path);
634
+ redirect(href);
635
+ }
636
+ const state = route.compositionApiResponse.state;
637
+ if (state === CANVAS_DRAFT_STATE2 || state === CANVAS_EDITOR_STATE2) {
638
+ walkNodeTree(route.compositionApiResponse.composition, (node) => {
639
+ if (node.type === "component" && node.node.parameters) {
640
+ Object.keys(node.node.parameters).forEach((key) => {
641
+ const parameter = node.node.parameters[key];
642
+ if (parameter.type === "text") {
643
+ const contextualParameter = parameter;
644
+ contextualParameter._contextualEditing = {
645
+ isEditable: true
646
+ };
647
+ }
648
+ });
649
+ }
650
+ });
651
+ }
652
+ const compositionContext = {
653
+ composition: route.compositionApiResponse.composition,
654
+ matchedRoute: route.matchedRoute,
655
+ searchParams,
656
+ dynamicInputs: route.dynamicInputs,
657
+ type: "composition",
658
+ isContextualEditing: isIncontextEditingEnabled({ searchParams }),
659
+ isDraftMode: isDraftModeEnabled({ searchParams }),
660
+ state: route.compositionApiResponse.state,
661
+ path: route.path
662
+ };
663
+ const resolved = resolveComposition({
664
+ composition: route.compositionApiResponse.composition,
665
+ resolveComponent,
666
+ serverContext,
667
+ compositionContext,
668
+ mode: props.mode
669
+ });
670
+ let transfer = null;
671
+ if (props.mode === "server") {
672
+ const headersValue = headers();
673
+ const missingQuirkValue = "unknown";
674
+ transfer = createElement3(ContextUpdateTransfer, {
675
+ serverContext,
676
+ update: {
677
+ params: props.params,
678
+ searchParams,
679
+ cookies: cookies2().getAll().reduce((acc, cookie) => {
680
+ acc[cookie.name] = cookie.value;
681
+ return acc;
682
+ }, {}),
683
+ quirks: {
684
+ "vc-country": headersValue.get("x-vercel-ip-country") || missingQuirkValue,
685
+ "vc-region": headersValue.get("x-vercel-ip-country-region") || missingQuirkValue,
686
+ "vc-city": headersValue.get("x-vercel-ip-city") || missingQuirkValue
687
+ }
688
+ }
689
+ });
690
+ } else if (props.mode === "static") {
691
+ transfer = createElement3(ContextUpdateTrigger);
692
+ }
693
+ return createElement3(Fragment3, void 0, transfer, resolved);
694
+ };
695
+ var isServerComponent = ({
696
+ component,
697
+ serverContext
698
+ }) => {
699
+ var _a, _b;
700
+ if (component.type === CANVAS_PERSONALIZE_TYPE) {
701
+ return serverContext && ((_a = getServerConfig3().evaluation) == null ? void 0 : _a.personalization) !== "client";
702
+ }
703
+ if (component.type === CANVAS_TEST_TYPE) {
704
+ return serverContext && ((_b = getServerConfig3().evaluation) == null ? void 0 : _b.testing) !== "client";
705
+ }
706
+ };
707
+ var resolveSystemComponent = ({
708
+ component,
709
+ serverContext
710
+ }) => {
711
+ const server = isServerComponent({
712
+ component,
713
+ serverContext
714
+ });
715
+ if (component.type === CANVAS_PERSONALIZE_TYPE) {
716
+ return server ? PersonalizeServer : PersonalizeClientWrapper;
717
+ }
718
+ if (component.type === CANVAS_TEST_TYPE) {
719
+ return server ? TestServer : TestClient;
720
+ }
721
+ return null;
722
+ };
723
+ var resolveSlots = ({
724
+ component,
725
+ root,
726
+ resolveComponent,
727
+ serverContext,
728
+ compositionContext,
729
+ mode
730
+ }) => {
731
+ const slots = {};
732
+ if (component.slots) {
733
+ Object.keys(component.slots).forEach((slotName, slotIndex) => {
734
+ const resolved = resolveComponents({
735
+ target: {
736
+ type: "slot",
737
+ components: component.slots[slotName],
738
+ root,
739
+ parent: component
740
+ },
741
+ slotName,
742
+ slotIndex,
743
+ resolveComponent,
744
+ serverContext,
745
+ compositionContext,
746
+ mode
747
+ });
748
+ if (resolved) {
749
+ slots[slotName] = {
750
+ name: slotName,
751
+ items: resolved
752
+ };
753
+ }
754
+ });
755
+ }
756
+ return slots;
757
+ };
758
+ var resolveComposition = (props) => {
759
+ const [resolved] = resolveComponents({
760
+ ...props,
761
+ target: {
762
+ type: "root",
763
+ composition: props.composition
764
+ },
765
+ slotName: void 0,
766
+ slotIndex: void 0,
767
+ compositionContext: props.compositionContext
768
+ });
769
+ return resolved;
770
+ };
771
+ var resolveComponents = ({
772
+ serverContext,
773
+ target,
774
+ slotName,
775
+ slotIndex,
776
+ resolveComponent,
777
+ compositionContext,
778
+ mode
779
+ }) => {
780
+ const isRoot = !slotName && typeof slotIndex !== "number";
781
+ let root;
782
+ let parent = void 0;
783
+ let components;
784
+ if (target.type === "root") {
785
+ root = target.composition;
786
+ components = [target.composition];
787
+ } else {
788
+ root = target.root;
789
+ components = target.components;
790
+ parent = target.parent;
791
+ }
792
+ const resolved = components.map((component, componentIndex) => {
793
+ var _a, _b;
794
+ const isServer = isServerComponent({
795
+ component,
796
+ serverContext
797
+ });
798
+ const systemComponent = resolveSystemComponent({
799
+ component,
800
+ serverContext
801
+ });
802
+ const { component: regularComponent, includeContext } = resolveComponent({ component }) || {
803
+ component: null
804
+ };
805
+ if (!systemComponent && !regularComponent) {
806
+ return null;
807
+ }
808
+ const slots = resolveSlots({
809
+ component,
810
+ root,
811
+ resolveComponent,
812
+ serverContext,
813
+ compositionContext,
814
+ mode
815
+ });
816
+ const resolvedComponent = systemComponent || regularComponent;
817
+ const parameters = (_a = component.parameters) != null ? _a : {};
818
+ const enrichmentTags = (_b = parameters[CANVAS_ENRICHMENT_TAG_PARAM]) == null ? void 0 : _b.value;
819
+ const componentProps = {
820
+ key: `${slotName}-${componentIndex}-component`,
821
+ ...Object.keys(parameters).reduce((acc, cur) => {
822
+ acc[cur] = parameters[cur].value;
823
+ return acc;
824
+ }, {}),
825
+ component,
826
+ slots,
827
+ contextInstance: isServer || includeContext ? serverContext : void 0,
828
+ context: compositionContext
829
+ };
830
+ const element = createElement3(resolvedComponent, componentProps);
831
+ let tagElement = null;
832
+ if (enrichmentTags == null ? void 0 : enrichmentTags.length) {
833
+ tagElement = createElement3(ContextUpdateTransfer, {
834
+ key: `${slotName}-${componentIndex}-tags`,
835
+ update: {
836
+ enrichments: enrichmentTags
837
+ },
838
+ serverContext
839
+ });
840
+ }
841
+ let childNode;
842
+ if (compositionContext.isContextualEditing) {
843
+ const elements = [element];
844
+ if (tagElement) {
845
+ elements.push(tagElement);
846
+ }
847
+ childNode = createElement3(
848
+ PureContextualEditingComponentWrapper,
849
+ {
850
+ key: `${slotName}-${componentIndex}-wrapper`,
851
+ isPlaceholder: false,
852
+ parentComponent: parent,
853
+ component,
854
+ slotName,
855
+ indexInSlot: componentIndex,
856
+ slotChildrenCount: components.length,
857
+ isReadOnly: "false"
858
+ },
859
+ elements
860
+ );
861
+ } else if (mode === "static") {
862
+ const elements = [element];
863
+ if (tagElement) {
864
+ elements.push(tagElement);
865
+ }
866
+ childNode = createElement3(
867
+ ClientContextualEditingComponentWrapper,
868
+ {
869
+ key: `${slotName}-${componentIndex}-wrapper`,
870
+ isPlaceholder: false,
871
+ parentComponent: parent,
872
+ component,
873
+ slotName,
874
+ indexInSlot: componentIndex,
875
+ slotChildrenCount: components.length,
876
+ isReadOnly: "false"
877
+ },
878
+ elements
879
+ );
880
+ } else {
881
+ const elements = [element];
882
+ if (tagElement) {
883
+ elements.push(tagElement);
884
+ }
885
+ childNode = elements;
886
+ }
887
+ return createElement3(
888
+ Fragment3,
889
+ {
890
+ key: !isRoot ? `${slotName}-${componentIndex}` : void 0
891
+ },
892
+ childNode
893
+ );
894
+ });
895
+ return resolved;
896
+ };
897
+
898
+ // src/components/UniformContext.tsx
899
+ import {
900
+ DefaultUniformClientContext,
901
+ UniformScript
902
+ } from "@uniformdev/canvas-next-rsc-client";
903
+ import { Suspense } from "react";
904
+ import React4 from "react";
905
+ var UniformContext = async ({
906
+ clientContextComponent,
907
+ children
908
+ }) => {
909
+ const manifest = await getManifest({
910
+ searchParams: {}
911
+ });
912
+ const ContextComponent = clientContextComponent || DefaultUniformClientContext;
913
+ return /* @__PURE__ */ React4.createElement(React4.Fragment, null, children, /* @__PURE__ */ React4.createElement(ContextComponent, { manifest }), /* @__PURE__ */ React4.createElement(Suspense, { fallback: /* @__PURE__ */ React4.createElement(React4.Fragment, null) }, /* @__PURE__ */ React4.createElement(UniformScript, null)));
914
+ };
915
+
916
+ // src/components/UniformPlayground.tsx
917
+ import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE3, CANVAS_EDITOR_STATE as CANVAS_EDITOR_STATE3 } from "@uniformdev/canvas";
918
+ import { notFound as notFound2 } from "next/navigation";
919
+ import React5 from "react";
920
+ var UniformPlayground = async ({ searchParams, ...rest }) => {
921
+ if (!isDraftModeEnabled({ searchParams })) {
922
+ return /* @__PURE__ */ React5.createElement("div", null, /* @__PURE__ */ React5.createElement("h1", null, "Playground is only available in draft mode"));
923
+ }
924
+ const id = searchParams["id"];
925
+ if (!id) {
926
+ notFound2();
927
+ }
928
+ const canvasClient = getCanvasClient({
929
+ cache: {
930
+ type: "no-cache"
931
+ }
932
+ });
933
+ const possibleStates = [CANVAS_EDITOR_STATE3, CANVAS_DRAFT_STATE3];
934
+ let composition = void 0;
935
+ for (let i = 0; i < possibleStates.length; i++) {
936
+ const state = possibleStates[i];
937
+ try {
938
+ composition = await canvasClient.getCompositionById({
939
+ compositionId: id,
940
+ state,
941
+ withComponentIDs: true
942
+ });
943
+ } catch (e) {
944
+ console.warn(`Failed to get composition ${id} with state ${state}`, e);
945
+ }
946
+ if (composition) {
947
+ break;
948
+ }
949
+ }
950
+ if (!composition) {
951
+ notFound2();
952
+ }
953
+ return /* @__PURE__ */ React5.createElement(UniformComposition, { mode: "server", params: {}, composition, ...rest });
954
+ };
955
+ export {
956
+ ContextUpdateTransfer,
957
+ UniformComposition,
958
+ UniformContext,
959
+ UniformPlayground,
960
+ createServerUniformContext,
961
+ createStaticParams,
962
+ generateStaticParams,
963
+ getCanvasClient,
964
+ getDefaultCanvasClient,
965
+ getDefaultManifestClient,
966
+ getDefaultProjectMapClient,
967
+ getDefaultRouteClient,
968
+ getManifest,
969
+ getManifestClient,
970
+ getProjectMapClient,
971
+ getRouteClient,
972
+ isDevelopmentEnvironment,
973
+ isDraftModeEnabled,
974
+ isIncontextEditingEnabled,
975
+ isOnVercelPreviewEnvironment,
976
+ resolveComposition
977
+ };