@sitecore-content-sdk/react 1.5.0-canary.9 → 2.0.0-canary.2

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.
@@ -39,13 +39,16 @@ const react_1 = __importStar(require("react"));
39
39
  const dlHelpers = __importStar(require("@sitecore-content-sdk/content/editing"));
40
40
  const codegen = __importStar(require("@sitecore-content-sdk/content/codegen"));
41
41
  const update_server_component_action_1 = require("../../server-actions/update-server-component-action");
42
+ const withSitecore_1 = require("../../enhancers/withSitecore");
42
43
  let { getDesignLibraryComponentPropsEvent, addServerComponentPreviewHandler, getDesignLibraryImportMapEvent, addStyleElement, sendErrorEvent, } = codegen;
43
44
  let { getDesignLibraryStatusEvent, addComponentUpdateHandler, postToDesignLibrary } = dlHelpers;
44
- let _updateServerComponentAction = update_server_component_action_1.updateServerComponentAction;
45
+ let _updateComponentAction = update_server_component_action_1.updateComponentAction;
46
+ let _previewComponentAction = update_server_component_action_1.previewComponentAction;
45
47
  const __mockDependencies = (mocks) => {
46
48
  postToDesignLibrary = mocks.postToDesignLibrary;
47
49
  addComponentUpdateHandler = mocks.addComponentUpdateHandler;
48
- _updateServerComponentAction = mocks.updateServerComponentAction;
50
+ _updateComponentAction = mocks.updateComponentAction;
51
+ _previewComponentAction = mocks.previewComponentAction;
49
52
  addServerComponentPreviewHandler = mocks.addServerComponentPreviewHandler;
50
53
  getDesignLibraryImportMapEvent = mocks.getDesignLibraryImportMapEvent;
51
54
  getDesignLibraryComponentPropsEvent = mocks.getDesignLibraryComponentPropsEvent;
@@ -64,17 +67,12 @@ const DesignLibraryPreviewEvents = ({ designLibraryStatus, component, }) => {
64
67
  (0, react_1.useEffect)(() => {
65
68
  if (!(component === null || component === void 0 ? void 0 : component.uid))
66
69
  return;
67
- postToDesignLibrary(getDesignLibraryStatusEvent(designLibraryStatus, component.uid));
68
- const unsubUpdate = addComponentUpdateHandler(component, (updated) => {
69
- _updateServerComponentAction({ uid: updated.uid, updatedComponent: updated });
70
- });
71
- // eslint-disable-next-line no-unused-vars
72
- const unsubPreview = addServerComponentPreviewHandler((_eventArgs) => {
73
- console.error('Component Library variant generation for server components is temporarily disabled.');
70
+ postToDesignLibrary(getDesignLibraryStatusEvent(designLibraryStatus, component.uid, true));
71
+ const unsubUpdate = addComponentUpdateHandler(component, (rendering) => {
72
+ _updateComponentAction({ uid: rendering.uid, rendering });
74
73
  });
75
74
  return () => {
76
75
  unsubUpdate && unsubUpdate();
77
- unsubPreview && unsubPreview();
78
76
  };
79
77
  }, [component, designLibraryStatus]);
80
78
  return react_1.default.createElement(react_1.default.Fragment, null);
@@ -88,41 +86,46 @@ exports.DesignLibraryPreviewEvents = DesignLibraryPreviewEvents;
88
86
  * @param {DesignLibraryVariantGenerationEventsProps} props The props. {@link DesignLibraryVariantGenerationEventsProps}
89
87
  * @returns {JSX.Element} empty JSX element.
90
88
  */
91
- const DesignLibraryVariantGenerationEvents = ({ designLibraryStatus, component, importMap, importMapError, previewComponentData, }) => {
89
+ const DesignLibraryVariantGenerationEvents = ({ designLibraryStatus, component, importMap, componentInitError, generatedComponentData, }) => {
90
+ const { api } = (0, withSitecore_1.useSitecore)();
92
91
  (0, react_1.useEffect)(() => {
93
- var _a, _b;
92
+ var _a;
94
93
  if (!(component === null || component === void 0 ? void 0 : component.uid))
95
94
  return;
96
- postToDesignLibrary(getDesignLibraryStatusEvent(designLibraryStatus, component.uid));
97
- const unsubUpdate = addComponentUpdateHandler(component, (updated) => {
98
- _updateServerComponentAction({
99
- uid: updated.uid,
100
- updatedComponent: updated,
101
- previewComponent: previewComponentData,
95
+ postToDesignLibrary(getDesignLibraryStatusEvent(designLibraryStatus, component.uid, true));
96
+ const unsubUpdate = addComponentUpdateHandler(component, (rendering) => {
97
+ _updateComponentAction({
98
+ uid: rendering.uid,
99
+ rendering,
100
+ generatedComponentData,
102
101
  });
103
102
  });
104
103
  const unsubPreview = addServerComponentPreviewHandler((eventArgs) => {
105
- _updateServerComponentAction({ uid: component.uid, previewComponent: eventArgs });
104
+ var _a;
105
+ _previewComponentAction({
106
+ uid: component.uid,
107
+ args: eventArgs,
108
+ }, (_a = api === null || api === void 0 ? void 0 : api.edge) === null || _a === void 0 ? void 0 : _a.edgeUrl);
106
109
  });
107
- if (importMapError) {
108
- // an import map error occurred on the server side in DesignLibraryServer, post error event to Design Studio
109
- sendErrorEvent(component.uid, importMapError, codegen.DesignLibraryPreviewError.RenderInit);
110
+ if (componentInitError) {
111
+ // an error occurred during initialization of the component on the server side
112
+ sendErrorEvent(component.uid, componentInitError, codegen.DesignLibraryPreviewError.RenderInit);
110
113
  }
111
114
  else {
112
115
  const importMapEvent = getDesignLibraryImportMapEvent(component.uid, importMap);
113
116
  postToDesignLibrary(importMapEvent);
114
117
  const propsEvent = getDesignLibraryComponentPropsEvent(component.uid, component.fields, component.params);
115
118
  postToDesignLibrary(propsEvent);
116
- if ((_b = (_a = previewComponentData === null || previewComponentData === void 0 ? void 0 : previewComponentData.message) === null || _a === void 0 ? void 0 : _a.styles) === null || _b === void 0 ? void 0 : _b.content) {
119
+ if ((_a = generatedComponentData === null || generatedComponentData === void 0 ? void 0 : generatedComponentData.styles) === null || _a === void 0 ? void 0 : _a.content) {
117
120
  // the generated component has custom styles, so add the css in style element and add it to document head
118
- addStyleElement(previewComponentData.message.styles.content);
121
+ addStyleElement(generatedComponentData.styles.content);
119
122
  }
120
123
  }
121
124
  return () => {
122
125
  unsubUpdate && unsubUpdate();
123
126
  unsubPreview && unsubPreview();
124
127
  };
125
- }, [component, designLibraryStatus, importMap, importMapError, previewComponentData]);
128
+ }, [component, designLibraryStatus, importMap, componentInitError, generatedComponentData]);
126
129
  return react_1.default.createElement(react_1.default.Fragment, null);
127
130
  };
128
131
  exports.DesignLibraryVariantGenerationEvents = DesignLibraryVariantGenerationEvents;
@@ -79,9 +79,7 @@ const DesignLibraryServer = async ({ page, componentMap, rendering, loadServerIm
79
79
  return null;
80
80
  }
81
81
  const isVariantGeneration = (_a = page.mode.designLibrary) === null || _a === void 0 ? void 0 : _a.isVariantGeneration;
82
- // Temporarily disable server side variant generation due to potential security vulerability
83
- // eslint-disable-next-line no-constant-condition
84
- if (isVariantGeneration && false) {
82
+ if (isVariantGeneration) {
85
83
  return (react_1.default.createElement(exports.DesignLibraryServerVariantGeneration, { page: page, rendering: rendering, loadServerImportMap: loadServerImportMap, componentMap: componentMap }));
86
84
  }
87
85
  return (react_1.default.createElement(exports.DesignLibraryServerPreview, { page: page, rendering: rendering, componentMap: componentMap }));
@@ -103,12 +101,12 @@ const DesignLibraryServerVariantGeneration = async ({ page, rendering, loadServe
103
101
  let importMap;
104
102
  let importMapInfo;
105
103
  let Component;
106
- let importMapError;
107
- let previewComponentData;
104
+ let componentInitError;
105
+ let generatedComponentData;
108
106
  // load importmap and importmap payload to pass to FE
109
107
  // if not provided, or errors during load set error to pass to FE
110
108
  if (!loadServerImportMap) {
111
- importMapError = 'No loadImportMap provided';
109
+ componentInitError = 'No loadImportMap provided';
112
110
  }
113
111
  else {
114
112
  try {
@@ -117,7 +115,7 @@ const DesignLibraryServerVariantGeneration = async ({ page, rendering, loadServe
117
115
  importMapInfo = getImportMapInfo(importMap);
118
116
  }
119
117
  catch (e) {
120
- importMapError = `Error loading import map: ${e}`;
118
+ componentInitError = `Error loading import map: ${e}`;
121
119
  }
122
120
  }
123
121
  let componentToUpdate = (_b = (_a = rendering === null || rendering === void 0 ? void 0 : rendering.placeholders) === null || _a === void 0 ? void 0 : _a[layout_1.EDITING_COMPONENT_PLACEHOLDER]) === null || _b === void 0 ? void 0 : _b[0];
@@ -127,24 +125,43 @@ const DesignLibraryServerVariantGeneration = async ({ page, rendering, loadServe
127
125
  return react_1.default.createElement(ErrorBoundary_1.ErrorComponent, { message: "Rendering UID is missing in the rendering data" });
128
126
  const uid = componentToUpdate.uid;
129
127
  const componentUpdateKey = `${editing_1.COMPONENT_UPDATE_CACHE_KEY_PREFIX}${uid}`;
128
+ const componentPreviewKey = `${editing_1.COMPONENT_PREVIEW_CACHE_KEY_PREFIX}${uid}`;
130
129
  // check if we have an update for this component in the global cache
131
130
  if (hasCache(componentUpdateKey)) {
132
- // we have an update, get it and clean the cache
131
+ // we have fields/params update, get it and clean the cache
133
132
  designLibraryStatus = editing_1.DesignLibraryStatus.RENDERED;
134
133
  const updateData = getCacheAndClean(componentUpdateKey);
135
134
  // apply the updates to the component rendering
136
- if (updateData === null || updateData === void 0 ? void 0 : updateData.updatedComponent) {
137
- updateComponent(componentToUpdate, updateData.updatedComponent.fields, updateData.updatedComponent.params);
135
+ if (updateData === null || updateData === void 0 ? void 0 : updateData.rendering) {
136
+ updateComponent(componentToUpdate, updateData.rendering.fields, updateData.rendering.params);
137
+ }
138
+ // generate the component instance if we are dealing with an AI-generated component
139
+ if ((updateData === null || updateData === void 0 ? void 0 : updateData.generatedComponentData) && !componentInitError && importMap) {
140
+ generatedComponentData = updateData.generatedComponentData;
141
+ try {
142
+ // use provided code and import map to create the component instance
143
+ Component = createComponentInstance(importMap, updateData.generatedComponentData);
144
+ }
145
+ catch (error) {
146
+ // error during component initialization - send error to client
147
+ componentInitError = error.toString();
148
+ }
138
149
  }
139
- if ((updateData === null || updateData === void 0 ? void 0 : updateData.previewComponent) && !importMapError && importMap) {
140
- previewComponentData = updateData.previewComponent;
150
+ }
151
+ else if (hasCache(componentPreviewKey) && !componentInitError && importMap) {
152
+ // we have a preview update, get it and clean the cache
153
+ designLibraryStatus = editing_1.DesignLibraryStatus.RENDERED;
154
+ const previewData = getCacheAndClean(componentPreviewKey);
155
+ componentInitError = previewData === null || previewData === void 0 ? void 0 : previewData.error;
156
+ if (previewData === null || previewData === void 0 ? void 0 : previewData.generatedComponentData) {
157
+ generatedComponentData = previewData.generatedComponentData;
141
158
  try {
142
159
  // use provided code and import map to create the component instance
143
- Component = createComponentInstance(importMap, updateData.previewComponent);
160
+ Component = createComponentInstance(importMap, previewData.generatedComponentData);
144
161
  }
145
162
  catch (error) {
146
163
  // error during component initialization - send error to client
147
- importMapError = error.toString();
164
+ componentInitError = error.toString();
148
165
  }
149
166
  }
150
167
  }
@@ -154,7 +171,7 @@ const DesignLibraryServerVariantGeneration = async ({ page, rendering, loadServe
154
171
  react_1.default.createElement(Component, { fields: componentToUpdate.fields, params: componentToUpdate.params, key: Date.now() })))) : (react_1.default.createElement(Placeholder_1.AppPlaceholder, { name: layout_1.EDITING_COMPONENT_PLACEHOLDER, page: page, rendering: rendering, componentMap: componentMap, key: Date.now() })),
155
172
  react_1.default.createElement(DesignLibraryClientEvents_1.DesignLibraryVariantGenerationEvents, { designLibraryStatus: designLibraryStatus, importMap: importMapInfo,
156
173
  // pass a new object since we have mutated the original which leads to old reference passed to the client
157
- component: Object.assign({}, componentToUpdate), importMapError: importMapError, previewComponentData: previewComponentData })));
174
+ component: Object.assign({}, componentToUpdate), componentInitError: componentInitError, generatedComponentData: generatedComponentData })));
158
175
  };
159
176
  exports.DesignLibraryServerVariantGeneration = DesignLibraryServerVariantGeneration;
160
177
  /**
@@ -182,12 +199,12 @@ const DesignLibraryServerPreview = async ({ page, rendering, componentMap, }) =>
182
199
  designLibraryStatus = editing_1.DesignLibraryStatus.RENDERED;
183
200
  const updateData = getCacheAndClean(componentUpdateKey);
184
201
  // apply the updates to the component rendering
185
- if (updateData === null || updateData === void 0 ? void 0 : updateData.updatedComponent) {
186
- updateComponent(componentToUpdate, updateData.updatedComponent.fields, updateData.updatedComponent.params);
202
+ if (updateData === null || updateData === void 0 ? void 0 : updateData.rendering) {
203
+ updateComponent(componentToUpdate, updateData.rendering.fields, updateData.rendering.params);
187
204
  }
188
205
  }
189
206
  return (react_1.default.createElement(react_1.default.Fragment, null,
190
- react_1.default.createElement(Placeholder_1.AppPlaceholder, { name: layout_1.EDITING_COMPONENT_PLACEHOLDER, page: page, rendering: rendering, componentMap: componentMap }),
207
+ react_1.default.createElement(Placeholder_1.AppPlaceholder, { name: layout_1.EDITING_COMPONENT_PLACEHOLDER, page: page, rendering: rendering, componentMap: componentMap, key: Date.now() }),
191
208
  react_1.default.createElement(DesignLibraryClientEvents_1.DesignLibraryPreviewEvents, { designLibraryStatus: designLibraryStatus,
192
209
  // pass a new object since we have mutated the original which leads to old reference passed to the client
193
210
  component: Object.assign({}, componentToUpdate) })));
@@ -1,18 +1,51 @@
1
1
  "use strict";
2
2
  'use server';
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.updateServerComponentAction = updateServerComponentAction;
4
+ exports.updateComponentAction = updateComponentAction;
5
+ exports.previewComponentAction = previewComponentAction;
5
6
  const content_1 = require("@sitecore-content-sdk/content");
7
+ const codegen_1 = require("@sitecore-content-sdk/content/codegen");
6
8
  const tools_1 = require("@sitecore-content-sdk/core/tools");
7
9
  const editing_1 = require("@sitecore-content-sdk/content/editing");
8
10
  /**
9
11
  * Server action to update global cache with the provided component updates received from Design Library.
10
12
  * Stores the given {@link ComponentUpdateModel} in the global cache using a key based on the component UID.
11
- * This enables dynamic rendering of server components inside Design Library
12
- * @param {ComponentUpdateModel} componentUpdate - The component update model containing the UID and optional updated or preview component data.
13
+ * This enables rendering dynamic updates of server components inside Design Library
14
+ * @param {ComponentUpdateModel} updatedComponent - The component update model containing the UID and optional updated or preview component data.
13
15
  * @returns A Promise that resolves when the cache has been updated.
14
16
  */
15
- async function updateServerComponentAction(componentUpdate) {
16
- content_1.debug.editing(`Updating server component cache for Component: ${componentUpdate.uid}`);
17
- (0, tools_1.setCache)(`${editing_1.COMPONENT_UPDATE_CACHE_KEY_PREFIX}${componentUpdate.uid}`, componentUpdate);
17
+ async function updateComponentAction(updatedComponent) {
18
+ content_1.debug.editing(`Updating server component cache for Update Component: ${updatedComponent.uid}`);
19
+ (0, tools_1.setCache)(`${editing_1.COMPONENT_UPDATE_CACHE_KEY_PREFIX}${updatedComponent.uid}`, updatedComponent);
20
+ }
21
+ /**
22
+ * Server action to update global cache with the generated component data in variant generation mode
23
+ * The generated component data is retrieved from a secured cache endpoint via the provided event arguments.
24
+ * This enables rendering dynamic updates of server components inside Design Library
25
+ * @param {PreviewEventModel} previewEvent - The preview event model containing the UID and the preview event arguments with cache information to fetch the generated component data.
26
+ * @param {string} [edgeUrl] - Optional Edge URL to fetch the generated component data.
27
+ * @returns A Promise that resolves when the cache has been updated.
28
+ */
29
+ async function previewComponentAction(previewEvent, edgeUrl) {
30
+ content_1.debug.editing(`Updating server component cache for Preview Component: ${previewEvent.uid}`);
31
+ const updatedComponent = {
32
+ uid: previewEvent.uid,
33
+ generatedComponentData: undefined,
34
+ error: undefined,
35
+ };
36
+ if (previewEvent.args) {
37
+ // we've received a component preview event from the Design Library, so we need to fetch the generated component data from secured endpoint
38
+ try {
39
+ updatedComponent.generatedComponentData = await (0, codegen_1.fetchGeneratedComponentFromCache)(previewEvent.args.message.cache.id, previewEvent.args.message.cache.token, edgeUrl);
40
+ }
41
+ catch (error) {
42
+ content_1.debug.editing(`Error fetching generated component data from cache for Component: ${previewEvent.uid}`, error);
43
+ updatedComponent.error = error instanceof Error ? error.message : String(error);
44
+ }
45
+ }
46
+ else {
47
+ content_1.debug.editing(`No preview event arguments provided for Component: ${previewEvent.uid}`);
48
+ updatedComponent.error = 'No preview event arguments provided';
49
+ }
50
+ (0, tools_1.setCache)(`${editing_1.COMPONENT_PREVIEW_CACHE_KEY_PREFIX}${updatedComponent.uid}`, updatedComponent);
18
51
  }
@@ -2,14 +2,17 @@
2
2
  import React, { useEffect } from 'react';
3
3
  import * as dlHelpers from '@sitecore-content-sdk/content/editing';
4
4
  import * as codegen from '@sitecore-content-sdk/content/codegen';
5
- import { updateServerComponentAction } from '../../server-actions/update-server-component-action';
5
+ import { updateComponentAction, previewComponentAction, } from '../../server-actions/update-server-component-action';
6
+ import { useSitecore } from '../../enhancers/withSitecore';
6
7
  let { getDesignLibraryComponentPropsEvent, addServerComponentPreviewHandler, getDesignLibraryImportMapEvent, addStyleElement, sendErrorEvent, } = codegen;
7
8
  let { getDesignLibraryStatusEvent, addComponentUpdateHandler, postToDesignLibrary } = dlHelpers;
8
- let _updateServerComponentAction = updateServerComponentAction;
9
+ let _updateComponentAction = updateComponentAction;
10
+ let _previewComponentAction = previewComponentAction;
9
11
  export const __mockDependencies = (mocks) => {
10
12
  postToDesignLibrary = mocks.postToDesignLibrary;
11
13
  addComponentUpdateHandler = mocks.addComponentUpdateHandler;
12
- _updateServerComponentAction = mocks.updateServerComponentAction;
14
+ _updateComponentAction = mocks.updateComponentAction;
15
+ _previewComponentAction = mocks.previewComponentAction;
13
16
  addServerComponentPreviewHandler = mocks.addServerComponentPreviewHandler;
14
17
  getDesignLibraryImportMapEvent = mocks.getDesignLibraryImportMapEvent;
15
18
  getDesignLibraryComponentPropsEvent = mocks.getDesignLibraryComponentPropsEvent;
@@ -27,17 +30,12 @@ export const DesignLibraryPreviewEvents = ({ designLibraryStatus, component, })
27
30
  useEffect(() => {
28
31
  if (!(component === null || component === void 0 ? void 0 : component.uid))
29
32
  return;
30
- postToDesignLibrary(getDesignLibraryStatusEvent(designLibraryStatus, component.uid));
31
- const unsubUpdate = addComponentUpdateHandler(component, (updated) => {
32
- _updateServerComponentAction({ uid: updated.uid, updatedComponent: updated });
33
- });
34
- // eslint-disable-next-line no-unused-vars
35
- const unsubPreview = addServerComponentPreviewHandler((_eventArgs) => {
36
- console.error('Component Library variant generation for server components is temporarily disabled.');
33
+ postToDesignLibrary(getDesignLibraryStatusEvent(designLibraryStatus, component.uid, true));
34
+ const unsubUpdate = addComponentUpdateHandler(component, (rendering) => {
35
+ _updateComponentAction({ uid: rendering.uid, rendering });
37
36
  });
38
37
  return () => {
39
38
  unsubUpdate && unsubUpdate();
40
- unsubPreview && unsubPreview();
41
39
  };
42
40
  }, [component, designLibraryStatus]);
43
41
  return React.createElement(React.Fragment, null);
@@ -50,40 +48,45 @@ export const DesignLibraryPreviewEvents = ({ designLibraryStatus, component, })
50
48
  * @param {DesignLibraryVariantGenerationEventsProps} props The props. {@link DesignLibraryVariantGenerationEventsProps}
51
49
  * @returns {JSX.Element} empty JSX element.
52
50
  */
53
- export const DesignLibraryVariantGenerationEvents = ({ designLibraryStatus, component, importMap, importMapError, previewComponentData, }) => {
51
+ export const DesignLibraryVariantGenerationEvents = ({ designLibraryStatus, component, importMap, componentInitError, generatedComponentData, }) => {
52
+ const { api } = useSitecore();
54
53
  useEffect(() => {
55
- var _a, _b;
54
+ var _a;
56
55
  if (!(component === null || component === void 0 ? void 0 : component.uid))
57
56
  return;
58
- postToDesignLibrary(getDesignLibraryStatusEvent(designLibraryStatus, component.uid));
59
- const unsubUpdate = addComponentUpdateHandler(component, (updated) => {
60
- _updateServerComponentAction({
61
- uid: updated.uid,
62
- updatedComponent: updated,
63
- previewComponent: previewComponentData,
57
+ postToDesignLibrary(getDesignLibraryStatusEvent(designLibraryStatus, component.uid, true));
58
+ const unsubUpdate = addComponentUpdateHandler(component, (rendering) => {
59
+ _updateComponentAction({
60
+ uid: rendering.uid,
61
+ rendering,
62
+ generatedComponentData,
64
63
  });
65
64
  });
66
65
  const unsubPreview = addServerComponentPreviewHandler((eventArgs) => {
67
- _updateServerComponentAction({ uid: component.uid, previewComponent: eventArgs });
66
+ var _a;
67
+ _previewComponentAction({
68
+ uid: component.uid,
69
+ args: eventArgs,
70
+ }, (_a = api === null || api === void 0 ? void 0 : api.edge) === null || _a === void 0 ? void 0 : _a.edgeUrl);
68
71
  });
69
- if (importMapError) {
70
- // an import map error occurred on the server side in DesignLibraryServer, post error event to Design Studio
71
- sendErrorEvent(component.uid, importMapError, codegen.DesignLibraryPreviewError.RenderInit);
72
+ if (componentInitError) {
73
+ // an error occurred during initialization of the component on the server side
74
+ sendErrorEvent(component.uid, componentInitError, codegen.DesignLibraryPreviewError.RenderInit);
72
75
  }
73
76
  else {
74
77
  const importMapEvent = getDesignLibraryImportMapEvent(component.uid, importMap);
75
78
  postToDesignLibrary(importMapEvent);
76
79
  const propsEvent = getDesignLibraryComponentPropsEvent(component.uid, component.fields, component.params);
77
80
  postToDesignLibrary(propsEvent);
78
- if ((_b = (_a = previewComponentData === null || previewComponentData === void 0 ? void 0 : previewComponentData.message) === null || _a === void 0 ? void 0 : _a.styles) === null || _b === void 0 ? void 0 : _b.content) {
81
+ if ((_a = generatedComponentData === null || generatedComponentData === void 0 ? void 0 : generatedComponentData.styles) === null || _a === void 0 ? void 0 : _a.content) {
79
82
  // the generated component has custom styles, so add the css in style element and add it to document head
80
- addStyleElement(previewComponentData.message.styles.content);
83
+ addStyleElement(generatedComponentData.styles.content);
81
84
  }
82
85
  }
83
86
  return () => {
84
87
  unsubUpdate && unsubUpdate();
85
88
  unsubPreview && unsubPreview();
86
89
  };
87
- }, [component, designLibraryStatus, importMap, importMapError, previewComponentData]);
90
+ }, [component, designLibraryStatus, importMap, componentInitError, generatedComponentData]);
88
91
  return React.createElement(React.Fragment, null);
89
92
  };
@@ -3,7 +3,7 @@ import React from 'react';
3
3
  import { EDITING_COMPONENT_PLACEHOLDER } from '@sitecore-content-sdk/content/layout';
4
4
  import { DesignLibraryPreviewEvents, DesignLibraryVariantGenerationEvents, } from './DesignLibraryClientEvents';
5
5
  import * as globalCache from '@sitecore-content-sdk/core/tools';
6
- import { DesignLibraryStatus, COMPONENT_UPDATE_CACHE_KEY_PREFIX, updateComponent as updateComponentOriginal, } from '@sitecore-content-sdk/content/editing';
6
+ import { DesignLibraryStatus, COMPONENT_UPDATE_CACHE_KEY_PREFIX, COMPONENT_PREVIEW_CACHE_KEY_PREFIX, updateComponent as updateComponentOriginal, } from '@sitecore-content-sdk/content/editing';
7
7
  import * as codegen from '@sitecore-content-sdk/content/codegen';
8
8
  import { AppPlaceholder, PlaceholderMetadata } from '../Placeholder';
9
9
  import { DesignLibraryErrorBoundary } from './DesignLibraryErrorBoundary';
@@ -39,9 +39,7 @@ export const DesignLibraryServer = async ({ page, componentMap, rendering, loadS
39
39
  return null;
40
40
  }
41
41
  const isVariantGeneration = (_a = page.mode.designLibrary) === null || _a === void 0 ? void 0 : _a.isVariantGeneration;
42
- // Temporarily disable server side variant generation due to potential security vulerability
43
- // eslint-disable-next-line no-constant-condition
44
- if (isVariantGeneration && false) {
42
+ if (isVariantGeneration) {
45
43
  return (React.createElement(DesignLibraryServerVariantGeneration, { page: page, rendering: rendering, loadServerImportMap: loadServerImportMap, componentMap: componentMap }));
46
44
  }
47
45
  return (React.createElement(DesignLibraryServerPreview, { page: page, rendering: rendering, componentMap: componentMap }));
@@ -62,12 +60,12 @@ export const DesignLibraryServerVariantGeneration = async ({ page, rendering, lo
62
60
  let importMap;
63
61
  let importMapInfo;
64
62
  let Component;
65
- let importMapError;
66
- let previewComponentData;
63
+ let componentInitError;
64
+ let generatedComponentData;
67
65
  // load importmap and importmap payload to pass to FE
68
66
  // if not provided, or errors during load set error to pass to FE
69
67
  if (!loadServerImportMap) {
70
- importMapError = 'No loadImportMap provided';
68
+ componentInitError = 'No loadImportMap provided';
71
69
  }
72
70
  else {
73
71
  try {
@@ -76,7 +74,7 @@ export const DesignLibraryServerVariantGeneration = async ({ page, rendering, lo
76
74
  importMapInfo = getImportMapInfo(importMap);
77
75
  }
78
76
  catch (e) {
79
- importMapError = `Error loading import map: ${e}`;
77
+ componentInitError = `Error loading import map: ${e}`;
80
78
  }
81
79
  }
82
80
  let componentToUpdate = (_b = (_a = rendering === null || rendering === void 0 ? void 0 : rendering.placeholders) === null || _a === void 0 ? void 0 : _a[EDITING_COMPONENT_PLACEHOLDER]) === null || _b === void 0 ? void 0 : _b[0];
@@ -86,24 +84,43 @@ export const DesignLibraryServerVariantGeneration = async ({ page, rendering, lo
86
84
  return React.createElement(ErrorComponent, { message: "Rendering UID is missing in the rendering data" });
87
85
  const uid = componentToUpdate.uid;
88
86
  const componentUpdateKey = `${COMPONENT_UPDATE_CACHE_KEY_PREFIX}${uid}`;
87
+ const componentPreviewKey = `${COMPONENT_PREVIEW_CACHE_KEY_PREFIX}${uid}`;
89
88
  // check if we have an update for this component in the global cache
90
89
  if (hasCache(componentUpdateKey)) {
91
- // we have an update, get it and clean the cache
90
+ // we have fields/params update, get it and clean the cache
92
91
  designLibraryStatus = DesignLibraryStatus.RENDERED;
93
92
  const updateData = getCacheAndClean(componentUpdateKey);
94
93
  // apply the updates to the component rendering
95
- if (updateData === null || updateData === void 0 ? void 0 : updateData.updatedComponent) {
96
- updateComponent(componentToUpdate, updateData.updatedComponent.fields, updateData.updatedComponent.params);
94
+ if (updateData === null || updateData === void 0 ? void 0 : updateData.rendering) {
95
+ updateComponent(componentToUpdate, updateData.rendering.fields, updateData.rendering.params);
96
+ }
97
+ // generate the component instance if we are dealing with an AI-generated component
98
+ if ((updateData === null || updateData === void 0 ? void 0 : updateData.generatedComponentData) && !componentInitError && importMap) {
99
+ generatedComponentData = updateData.generatedComponentData;
100
+ try {
101
+ // use provided code and import map to create the component instance
102
+ Component = createComponentInstance(importMap, updateData.generatedComponentData);
103
+ }
104
+ catch (error) {
105
+ // error during component initialization - send error to client
106
+ componentInitError = error.toString();
107
+ }
97
108
  }
98
- if ((updateData === null || updateData === void 0 ? void 0 : updateData.previewComponent) && !importMapError && importMap) {
99
- previewComponentData = updateData.previewComponent;
109
+ }
110
+ else if (hasCache(componentPreviewKey) && !componentInitError && importMap) {
111
+ // we have a preview update, get it and clean the cache
112
+ designLibraryStatus = DesignLibraryStatus.RENDERED;
113
+ const previewData = getCacheAndClean(componentPreviewKey);
114
+ componentInitError = previewData === null || previewData === void 0 ? void 0 : previewData.error;
115
+ if (previewData === null || previewData === void 0 ? void 0 : previewData.generatedComponentData) {
116
+ generatedComponentData = previewData.generatedComponentData;
100
117
  try {
101
118
  // use provided code and import map to create the component instance
102
- Component = createComponentInstance(importMap, updateData.previewComponent);
119
+ Component = createComponentInstance(importMap, previewData.generatedComponentData);
103
120
  }
104
121
  catch (error) {
105
122
  // error during component initialization - send error to client
106
- importMapError = error.toString();
123
+ componentInitError = error.toString();
107
124
  }
108
125
  }
109
126
  }
@@ -113,7 +130,7 @@ export const DesignLibraryServerVariantGeneration = async ({ page, rendering, lo
113
130
  React.createElement(Component, { fields: componentToUpdate.fields, params: componentToUpdate.params, key: Date.now() })))) : (React.createElement(AppPlaceholder, { name: EDITING_COMPONENT_PLACEHOLDER, page: page, rendering: rendering, componentMap: componentMap, key: Date.now() })),
114
131
  React.createElement(DesignLibraryVariantGenerationEvents, { designLibraryStatus: designLibraryStatus, importMap: importMapInfo,
115
132
  // pass a new object since we have mutated the original which leads to old reference passed to the client
116
- component: Object.assign({}, componentToUpdate), importMapError: importMapError, previewComponentData: previewComponentData })));
133
+ component: Object.assign({}, componentToUpdate), componentInitError: componentInitError, generatedComponentData: generatedComponentData })));
117
134
  };
118
135
  /**
119
136
  * Design Library component for rendering server components in app router application when variant generation is not enabled.
@@ -140,12 +157,12 @@ export const DesignLibraryServerPreview = async ({ page, rendering, componentMap
140
157
  designLibraryStatus = DesignLibraryStatus.RENDERED;
141
158
  const updateData = getCacheAndClean(componentUpdateKey);
142
159
  // apply the updates to the component rendering
143
- if (updateData === null || updateData === void 0 ? void 0 : updateData.updatedComponent) {
144
- updateComponent(componentToUpdate, updateData.updatedComponent.fields, updateData.updatedComponent.params);
160
+ if (updateData === null || updateData === void 0 ? void 0 : updateData.rendering) {
161
+ updateComponent(componentToUpdate, updateData.rendering.fields, updateData.rendering.params);
145
162
  }
146
163
  }
147
164
  return (React.createElement(React.Fragment, null,
148
- React.createElement(AppPlaceholder, { name: EDITING_COMPONENT_PLACEHOLDER, page: page, rendering: rendering, componentMap: componentMap }),
165
+ React.createElement(AppPlaceholder, { name: EDITING_COMPONENT_PLACEHOLDER, page: page, rendering: rendering, componentMap: componentMap, key: Date.now() }),
149
166
  React.createElement(DesignLibraryPreviewEvents, { designLibraryStatus: designLibraryStatus,
150
167
  // pass a new object since we have mutated the original which leads to old reference passed to the client
151
168
  component: Object.assign({}, componentToUpdate) })));
@@ -1,15 +1,47 @@
1
1
  'use server';
2
2
  import { debug } from '@sitecore-content-sdk/content';
3
+ import { fetchGeneratedComponentFromCache, } from '@sitecore-content-sdk/content/codegen';
3
4
  import { setCache } from '@sitecore-content-sdk/core/tools';
4
- import { COMPONENT_UPDATE_CACHE_KEY_PREFIX } from '@sitecore-content-sdk/content/editing';
5
+ import { COMPONENT_UPDATE_CACHE_KEY_PREFIX, COMPONENT_PREVIEW_CACHE_KEY_PREFIX, } from '@sitecore-content-sdk/content/editing';
5
6
  /**
6
7
  * Server action to update global cache with the provided component updates received from Design Library.
7
8
  * Stores the given {@link ComponentUpdateModel} in the global cache using a key based on the component UID.
8
- * This enables dynamic rendering of server components inside Design Library
9
- * @param {ComponentUpdateModel} componentUpdate - The component update model containing the UID and optional updated or preview component data.
9
+ * This enables rendering dynamic updates of server components inside Design Library
10
+ * @param {ComponentUpdateModel} updatedComponent - The component update model containing the UID and optional updated or preview component data.
10
11
  * @returns A Promise that resolves when the cache has been updated.
11
12
  */
12
- export async function updateServerComponentAction(componentUpdate) {
13
- debug.editing(`Updating server component cache for Component: ${componentUpdate.uid}`);
14
- setCache(`${COMPONENT_UPDATE_CACHE_KEY_PREFIX}${componentUpdate.uid}`, componentUpdate);
13
+ export async function updateComponentAction(updatedComponent) {
14
+ debug.editing(`Updating server component cache for Update Component: ${updatedComponent.uid}`);
15
+ setCache(`${COMPONENT_UPDATE_CACHE_KEY_PREFIX}${updatedComponent.uid}`, updatedComponent);
16
+ }
17
+ /**
18
+ * Server action to update global cache with the generated component data in variant generation mode
19
+ * The generated component data is retrieved from a secured cache endpoint via the provided event arguments.
20
+ * This enables rendering dynamic updates of server components inside Design Library
21
+ * @param {PreviewEventModel} previewEvent - The preview event model containing the UID and the preview event arguments with cache information to fetch the generated component data.
22
+ * @param {string} [edgeUrl] - Optional Edge URL to fetch the generated component data.
23
+ * @returns A Promise that resolves when the cache has been updated.
24
+ */
25
+ export async function previewComponentAction(previewEvent, edgeUrl) {
26
+ debug.editing(`Updating server component cache for Preview Component: ${previewEvent.uid}`);
27
+ const updatedComponent = {
28
+ uid: previewEvent.uid,
29
+ generatedComponentData: undefined,
30
+ error: undefined,
31
+ };
32
+ if (previewEvent.args) {
33
+ // we've received a component preview event from the Design Library, so we need to fetch the generated component data from secured endpoint
34
+ try {
35
+ updatedComponent.generatedComponentData = await fetchGeneratedComponentFromCache(previewEvent.args.message.cache.id, previewEvent.args.message.cache.token, edgeUrl);
36
+ }
37
+ catch (error) {
38
+ debug.editing(`Error fetching generated component data from cache for Component: ${previewEvent.uid}`, error);
39
+ updatedComponent.error = error instanceof Error ? error.message : String(error);
40
+ }
41
+ }
42
+ else {
43
+ debug.editing(`No preview event arguments provided for Component: ${previewEvent.uid}`);
44
+ updatedComponent.error = 'No preview event arguments provided';
45
+ }
46
+ setCache(`${COMPONENT_PREVIEW_CACHE_KEY_PREFIX}${updatedComponent.uid}`, updatedComponent);
15
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-content-sdk/react",
3
- "version": "1.5.0-canary.9",
3
+ "version": "2.0.0-canary.2",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -76,14 +76,14 @@
76
76
  "react-dom": "^19.2.1"
77
77
  },
78
78
  "dependencies": {
79
- "@sitecore-content-sdk/content": "1.5.0-canary.9",
80
- "@sitecore-content-sdk/core": "1.5.0-canary.9",
81
- "@sitecore-content-sdk/search": "0.2.0-canary.9",
79
+ "@sitecore-content-sdk/content": "2.0.0-canary.2",
80
+ "@sitecore-content-sdk/core": "2.0.0-canary.2",
81
+ "@sitecore-content-sdk/search": "0.2.0-canary.12",
82
82
  "fast-deep-equal": "^3.1.3"
83
83
  },
84
84
  "description": "",
85
85
  "types": "types/index.d.ts",
86
- "gitHead": "1ee268ebf45cb5138f525201290568370e004241",
86
+ "gitHead": "fb5a8d3373cf15bbb9dcc2312b80825fe7d82ac8",
87
87
  "files": [
88
88
  "dist",
89
89
  "types",
@@ -17,5 +17,5 @@ export declare const DesignLibraryPreviewEvents: ({ designLibraryStatus, compone
17
17
  * @param {DesignLibraryVariantGenerationEventsProps} props The props. {@link DesignLibraryVariantGenerationEventsProps}
18
18
  * @returns {JSX.Element} empty JSX element.
19
19
  */
20
- export declare const DesignLibraryVariantGenerationEvents: ({ designLibraryStatus, component, importMap, importMapError, previewComponentData, }: DesignLibraryVariantGenerationEventsProps) => React.JSX.Element;
20
+ export declare const DesignLibraryVariantGenerationEvents: ({ designLibraryStatus, component, importMap, componentInitError, generatedComponentData, }: DesignLibraryVariantGenerationEventsProps) => React.JSX.Element;
21
21
  //# sourceMappingURL=DesignLibraryClientEvents.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DesignLibraryClientEvents.d.ts","sourceRoot":"","sources":["../../../src/components/DesignLibrary/DesignLibraryClientEvents.tsx"],"names":[],"mappings":"AACA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAIzC,OAAO,EACL,+BAA+B,EAC/B,yCAAyC,EAC1C,MAAM,UAAU,CAAC;AAYlB,eAAO,MAAM,kBAAkB,GAAI,OAAO,GAAG,SAS5C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,GAAI,qCAGxC,+BAA+B,sBAwBjC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,oCAAoC,GAAI,sFAMlD,yCAAyC,sBA6C3C,CAAC"}
1
+ {"version":3,"file":"DesignLibraryClientEvents.d.ts","sourceRoot":"","sources":["../../../src/components/DesignLibrary/DesignLibraryClientEvents.tsx"],"names":[],"mappings":"AACA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAOzC,OAAO,EACL,+BAA+B,EAC/B,yCAAyC,EAC1C,MAAM,UAAU,CAAC;AAclB,eAAO,MAAM,kBAAkB,GAAI,OAAO,GAAG,SAU5C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,GAAI,qCAGxC,+BAA+B,sBAgBjC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,oCAAoC,GAAI,4FAMlD,yCAAyC,sBAyD3C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"DesignLibraryServer.d.ts","sourceRoot":"","sources":["../../../src/components/DesignLibrary/DesignLibraryServer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAiB1B,OAAO,EAEL,wBAAwB,EACxB,+BAA+B,EAC/B,yCAAyC,EAC1C,MAAM,UAAU,CAAC;AAOlB,eAAO,MAAM,kBAAkB,GAAU,OAAO,GAAG,kBAUlD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,GAAU,yDAKvC,wBAAwB,sCAuB1B,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,oCAAoC,GAAU,yDAKxD,yCAAyC,+BA4F3C,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,0BAA0B,GAAU,oCAI9C,+BAA+B,+BAyCjC,CAAC"}
1
+ {"version":3,"file":"DesignLibraryServer.d.ts","sourceRoot":"","sources":["../../../src/components/DesignLibrary/DesignLibraryServer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAoB1B,OAAO,EAEL,wBAAwB,EACxB,+BAA+B,EAC/B,yCAAyC,EAC1C,MAAM,UAAU,CAAC;AAOlB,eAAO,MAAM,kBAAkB,GAAU,OAAO,GAAG,kBAUlD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,GAAU,yDAKvC,wBAAwB,sCAoB1B,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,oCAAoC,GAAU,yDAKxD,yCAAyC,+BA6G3C,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,0BAA0B,GAAU,oCAI9C,+BAA+B,+BAsCjC,CAAC"}
@@ -1,8 +1,7 @@
1
- import { ImportEntry, ImportEntryInfo } from '@sitecore-content-sdk/content/codegen';
1
+ import { GeneratedComponentData, ImportEntry, ImportEntryInfo } from '@sitecore-content-sdk/content/codegen';
2
2
  import { ComponentFields, ComponentParams, ComponentRendering, RouteData } from '@sitecore-content-sdk/content/layout';
3
3
  import { DesignLibraryStatus } from '@sitecore-content-sdk/content/editing';
4
4
  import { Page } from '@sitecore-content-sdk/content/client';
5
- import { ComponentPreviewEventArgs } from '@sitecore-content-sdk/content/codegen';
6
5
  import { ComponentMap } from '../sharedTypes';
7
6
  export type ImportMapImport = {
8
7
  default: ImportEntry[];
@@ -49,12 +48,15 @@ export type DesignLibraryVariantGenerationEventsProps = DesignLibraryPreviewEven
49
48
  */
50
49
  importMap?: ImportEntryInfo[];
51
50
  /**
52
- * Any error that occurred while loading the import map to be posted as a message to the Design Studio.
51
+ * Any error that occurred during initialization of the component:
52
+ * - importMap error
53
+ * - error fetching the generated component data from secured endpoint
54
+ * - error during generation of the component on the server side
53
55
  */
54
- importMapError?: string;
56
+ componentInitError?: string;
55
57
  /**
56
- * The preview component data received from design library.
58
+ * The generated component data received from design library.
57
59
  */
58
- previewComponentData?: ComponentPreviewEventArgs;
60
+ generatedComponentData?: GeneratedComponentData;
59
61
  };
60
62
  //# sourceMappingURL=models.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../src/components/DesignLibrary/models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACrF,OAAO,EACL,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,SAAS,EACV,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,IAAI,EAAE,MAAM,sCAAsC,CAAC;AAC5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,WAAW,EAAE,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,aAAa,CAAC;IACjD,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B,CAAC,CAAC;AAEH,MAAM,MAAM,wBAAwB,GAAG;IACrC;;OAEG;IACH,YAAY,EAAE,YAAY,CAAC;IAC3B;;OAEG;IACH,SAAS,EAAE,kBAAkB,GAAG,SAAS,CAAC;IAC1C;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC;IACX;;OAEG;IACH,mBAAmB,EAAE,MAAM,OAAO,CAAC,eAAe,CAAC,CAAC;CACrD,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,wBAAwB,CAAC;AAE7D,MAAM,MAAM,+BAA+B,GAAG,IAAI,CAAC,wBAAwB,EAAE,qBAAqB,CAAC,CAAC;AAEpG,MAAM,MAAM,yCAAyC,GAAG,wBAAwB,CAAC;AAEjF,MAAM,MAAM,+BAA+B,GAAG;IAC5C;;OAEG;IACH,mBAAmB,EAAE,mBAAmB,CAAC;IACzC;;OAEG;IACH,SAAS,EAAE,kBAAkB,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,yCAAyC,GAAG,+BAA+B,GAAG;IACxF;;OAEG;IACH,SAAS,CAAC,EAAE,eAAe,EAAE,CAAC;IAC9B;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;OAEG;IACH,oBAAoB,CAAC,EAAE,yBAAyB,CAAC;CAClD,CAAC"}
1
+ {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../src/components/DesignLibrary/models.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,WAAW,EACX,eAAe,EAChB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,SAAS,EACV,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,IAAI,EAAE,MAAM,sCAAsC,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,WAAW,EAAE,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,aAAa,CAAC;IACjD,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B,CAAC,CAAC;AAEH,MAAM,MAAM,wBAAwB,GAAG;IACrC;;OAEG;IACH,YAAY,EAAE,YAAY,CAAC;IAC3B;;OAEG;IACH,SAAS,EAAE,kBAAkB,GAAG,SAAS,CAAC;IAC1C;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC;IACX;;OAEG;IACH,mBAAmB,EAAE,MAAM,OAAO,CAAC,eAAe,CAAC,CAAC;CACrD,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,wBAAwB,CAAC;AAE7D,MAAM,MAAM,+BAA+B,GAAG,IAAI,CAAC,wBAAwB,EAAE,qBAAqB,CAAC,CAAC;AAEpG,MAAM,MAAM,yCAAyC,GAAG,wBAAwB,CAAC;AAEjF,MAAM,MAAM,+BAA+B,GAAG;IAC5C;;OAEG;IACH,mBAAmB,EAAE,mBAAmB,CAAC;IACzC;;OAEG;IACH,SAAS,EAAE,kBAAkB,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,yCAAyC,GAAG,+BAA+B,GAAG;IACxF;;OAEG;IACH,SAAS,CAAC,EAAE,eAAe,EAAE,CAAC;IAC9B;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;OAEG;IACH,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;CACjD,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { ComponentRendering } from '@sitecore-content-sdk/content/layout';
2
- import { ComponentPreviewEventArgs } from '@sitecore-content-sdk/content/codegen';
2
+ import { ServerComponentPreviewEventArgs, GeneratedComponentData } from '@sitecore-content-sdk/content/codegen';
3
3
  export type ComponentUpdateModel = {
4
4
  /**
5
5
  * Unique identifier of the component being updated.
@@ -8,18 +8,51 @@ export type ComponentUpdateModel = {
8
8
  /**
9
9
  * The updated component rendering data.
10
10
  */
11
- updatedComponent?: ComponentRendering;
11
+ rendering?: ComponentRendering;
12
+ /**
13
+ * The data needed for generated component to be rendered on the server. Required if update event is coming for a generated component in variant generation mode.
14
+ */
15
+ generatedComponentData?: GeneratedComponentData;
16
+ };
17
+ export type ComponentPreviewModel = {
18
+ /**
19
+ * Unique identifier of the component being updated.
20
+ */
21
+ uid: string;
22
+ /**
23
+ * The data needed for generated component to be rendered on the server
24
+ */
25
+ generatedComponentData?: GeneratedComponentData;
26
+ /**
27
+ * Error message in case fetching generated component data from secured cache endpoint fails.
28
+ */
29
+ error?: string;
30
+ };
31
+ export type PreviewEventModel = {
32
+ /**
33
+ * Unique identifier of the component being updated.
34
+ */
35
+ uid: string;
12
36
  /**
13
37
  * The preview component event arguments in variant generation mode.
14
38
  */
15
- previewComponent?: ComponentPreviewEventArgs;
39
+ args: ServerComponentPreviewEventArgs;
16
40
  };
17
41
  /**
18
42
  * Server action to update global cache with the provided component updates received from Design Library.
19
43
  * Stores the given {@link ComponentUpdateModel} in the global cache using a key based on the component UID.
20
- * This enables dynamic rendering of server components inside Design Library
21
- * @param {ComponentUpdateModel} componentUpdate - The component update model containing the UID and optional updated or preview component data.
44
+ * This enables rendering dynamic updates of server components inside Design Library
45
+ * @param {ComponentUpdateModel} updatedComponent - The component update model containing the UID and optional updated or preview component data.
46
+ * @returns A Promise that resolves when the cache has been updated.
47
+ */
48
+ export declare function updateComponentAction(updatedComponent: ComponentUpdateModel): Promise<void>;
49
+ /**
50
+ * Server action to update global cache with the generated component data in variant generation mode
51
+ * The generated component data is retrieved from a secured cache endpoint via the provided event arguments.
52
+ * This enables rendering dynamic updates of server components inside Design Library
53
+ * @param {PreviewEventModel} previewEvent - The preview event model containing the UID and the preview event arguments with cache information to fetch the generated component data.
54
+ * @param {string} [edgeUrl] - Optional Edge URL to fetch the generated component data.
22
55
  * @returns A Promise that resolves when the cache has been updated.
23
56
  */
24
- export declare function updateServerComponentAction(componentUpdate: ComponentUpdateModel): Promise<void>;
57
+ export declare function previewComponentAction(previewEvent: PreviewEventModel, edgeUrl?: string): Promise<void>;
25
58
  //# sourceMappingURL=update-server-component-action.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"update-server-component-action.d.ts","sourceRoot":"","sources":["../../src/server-actions/update-server-component-action.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAIlF,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,gBAAgB,CAAC,EAAE,kBAAkB,CAAC;IACtC;;OAEG;IACH,gBAAgB,CAAC,EAAE,yBAAyB,CAAC;CAC9C,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,eAAe,EAAE,oBAAoB,GACpC,OAAO,CAAC,IAAI,CAAC,CAGf"}
1
+ {"version":3,"file":"update-server-component-action.d.ts","sourceRoot":"","sources":["../../src/server-actions/update-server-component-action.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EACL,+BAA+B,EAC/B,sBAAsB,EAEvB,MAAM,uCAAuC,CAAC;AAO/C,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,SAAS,CAAC,EAAE,kBAAkB,CAAC;IAC/B;;OAEG;IACH,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;CACjD,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;IAChD;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,IAAI,EAAE,+BAA+B,CAAC;CACvC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CAAC,gBAAgB,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAGjG;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,YAAY,EAAE,iBAAiB,EAC/B,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CA8Bf"}