@alpaca-headless/alpaca-headless 1.0.541 → 1.0.542

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.
@@ -109,7 +109,7 @@ export function renderPlaceholder(wrap, componentsWithProps, placeholderData, co
109
109
  return wrap(_jsxs(_Fragment, { children: [context.isEditing && (_jsx("script", { "data-placeholder-start": placeholderData.key, "data-description": description })), componentsWithProps.map(({ Component, data, props }) => {
110
110
  var _a, _b, _c, _d, _e;
111
111
  return (_jsx(_Fragment, { children: _jsxs(ErrorBoundary, { FallbackComponent: ErrorFallback, children: [context.isEditing && (_jsx("script", { "data-component-start": data.id, "data-itemid": ((_b = (_a = data._editor) === null || _a === void 0 ? void 0 : _a.linkedComponentItem) === null || _b === void 0 ? void 0 : _b.id) ||
112
- data.id, "data-layoutid": (_d = (_c = data._editor) === null || _c === void 0 ? void 0 : _c.hostingPageItem) === null || _d === void 0 ? void 0 : _d.id })), _createElement(Component, Object.assign({}, props, { key: data.id })), context.isEditing && (_jsx("script", { "data-component-end": data.id }))] }, "EB" + data.id + ((_e = data.rendering) === null || _e === void 0 ? void 0 : _e.revision)) }));
112
+ data.id, "data-typeid": data.templateId, "data-layoutid": (_d = (_c = data._editor) === null || _c === void 0 ? void 0 : _c.hostingPageItem) === null || _d === void 0 ? void 0 : _d.id })), _createElement(Component, Object.assign({}, props, { key: data.id })), context.isEditing && (_jsx("script", { "data-component-end": data.id }))] }, "EB" + data.id + ((_e = data.rendering) === null || _e === void 0 ? void 0 : _e.revision)) }));
113
113
  }), placeholderData.hasMore && (_jsx(Suspense, { children: _jsx(LazyPlaceholder, { placeholder: placeholderData, context: context }) })), context.isEditing && (_jsx("script", { "data-placeholder-end": placeholderData.key }))] }));
114
114
  }
115
115
  function ComponentNotFound({ component }) {
@@ -27,7 +27,7 @@ export type GetPageParams = {
27
27
  searchParams: any;
28
28
  apiConfig?: ApiConfig;
29
29
  };
30
- export declare function getPage({ itemId, language, version, siteName, renderOptions, renderings, compileRendering, mode, searchParams, apiConfig, }: GetPageParams): Promise<RouteData>;
30
+ export declare function getPage({ itemId, language, version, siteName, renderOptions, renderings, compileRendering, mode, apiConfig, }: GetPageParams): Promise<RouteData>;
31
31
  export type ResolveRouteParams = {
32
32
  path: string[] | string;
33
33
  searchParams: any;
@@ -3,10 +3,13 @@ import { apiPostObject } from "../services/api";
3
3
  if (!globalThis.alpacaRouteDataCache) {
4
4
  globalThis.alpacaRouteDataCache = {};
5
5
  }
6
- const fetchRouteData = async (path, host, mode, itemId, language, version, options, apiConfig, editRevision, siteName) => {
6
+ const fetchRouteData = async (path, host, mode, itemId, language, version, options, apiConfig, siteName) => {
7
7
  var _a;
8
+ if (mode === "edit" || mode === "preview") {
9
+ return await doFetchRouteData(path, host, mode, itemId, language, version, options, apiConfig, siteName);
10
+ }
8
11
  const cache = globalThis.alpacaRouteDataCache;
9
- const cacheKey = editRevision + itemId + language + version + siteName + path + host + mode;
12
+ const cacheKey = itemId + language + version + siteName + path + host;
10
13
  if (cacheKey && ((_a = cache[cacheKey]) === null || _a === void 0 ? void 0 : _a.expiresOn) > new Date()) {
11
14
  Object.keys(cache).forEach((key) => {
12
15
  if (cache[key].expiresOn < new Date()) {
@@ -72,8 +75,8 @@ const doFetchRouteData = async (path, host, mode, itemId, language, version, opt
72
75
  duration,
73
76
  };
74
77
  };
75
- export async function getPage({ itemId, language, version, siteName, renderOptions, renderings, compileRendering, mode, searchParams, apiConfig, }) {
76
- const result = await fetchRouteData("", "", mode || "normal", itemId, language, version, renderOptions, apiConfig, searchParams["edit_rev"], siteName);
78
+ export async function getPage({ itemId, language, version, siteName, renderOptions, renderings, compileRendering, mode, apiConfig, }) {
79
+ const result = await fetchRouteData("", "", mode || "normal", itemId, language, version, renderOptions, apiConfig, siteName);
77
80
  return await createRouteData(result, renderings, renderOptions, mode, apiConfig, compileRendering);
78
81
  }
79
82
  async function createRouteData(result, renderings, renderOptions, mode, apiConfig, compileRendering) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alpaca-headless/alpaca-headless",
3
- "version": "1.0.541",
3
+ "version": "1.0.542",
4
4
  "type": "module",
5
5
  "description": "Alpaca Headless",
6
6
  "main": "dist/index.js",
@@ -221,6 +221,7 @@ export function renderPlaceholder(
221
221
  (data as ComponentData)._editor?.linkedComponentItem?.id ||
222
222
  data.id
223
223
  }
224
+ data-typeid={ (data as ComponentData).templateId}
224
225
  data-layoutid={
225
226
  (data as ComponentData)._editor?.hostingPageItem?.id
226
227
  }
@@ -37,14 +37,28 @@ const fetchRouteData = async (
37
37
  language: string,
38
38
  version: number,
39
39
  options: RenderOptions,
40
- apiConfig?: ApiConfig,
41
- editRevision?: string,
40
+ apiConfig?: ApiConfig,
42
41
  siteName?: string
43
42
  ): Promise<Result> => {
44
- const cache = globalThis.alpacaRouteDataCache;
45
- const cacheKey =
46
- editRevision + itemId + language + version + siteName + path + host + mode;
47
43
 
44
+ if(mode === "edit" || mode === "preview") {
45
+ return await doFetchRouteData(
46
+ path,
47
+ host,
48
+ mode,
49
+ itemId,
50
+ language,
51
+ version,
52
+ options,
53
+ apiConfig,
54
+ siteName
55
+ );
56
+ }
57
+
58
+ const cache = globalThis.alpacaRouteDataCache;
59
+
60
+ const cacheKey = itemId + language + version + siteName + path + host;
61
+
48
62
  if (cacheKey && cache[cacheKey]?.expiresOn > new Date()) {
49
63
  Object.keys(cache).forEach((key) => {
50
64
  if (cache[key].expiresOn < new Date()) {
@@ -180,7 +194,6 @@ export async function getPage({
180
194
  renderings,
181
195
  compileRendering,
182
196
  mode,
183
- searchParams,
184
197
  apiConfig,
185
198
  }: GetPageParams): Promise<RouteData> {
186
199
  const result = await fetchRouteData(
@@ -191,8 +204,7 @@ export async function getPage({
191
204
  language,
192
205
  version,
193
206
  renderOptions,
194
- apiConfig,
195
- searchParams["edit_rev"],
207
+ apiConfig,
196
208
  siteName
197
209
  );
198
210