@alpaca-headless/alpaca-headless 1.0.3495 → 1.0.3497

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-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)) }));
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)) }));
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, apiConfig, }: GetPageParams): Promise<RouteData>;
30
+ export declare function getPage({ itemId, language, version, siteName, renderOptions, renderings, compileRendering, mode, searchParams, apiConfig, }: GetPageParams): Promise<RouteData>;
31
31
  export type ResolveRouteParams = {
32
32
  path: string[] | string;
33
33
  searchParams: any;
@@ -3,13 +3,10 @@ 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, siteName) => {
6
+ const fetchRouteData = async (path, host, mode, itemId, language, version, options, apiConfig, editRevision, 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
- }
11
8
  const cache = globalThis.alpacaRouteDataCache;
12
- const cacheKey = itemId + language + version + siteName + path + host;
9
+ const cacheKey = editRevision + itemId + language + version + siteName + path + host + mode;
13
10
  if (cacheKey && ((_a = cache[cacheKey]) === null || _a === void 0 ? void 0 : _a.expiresOn) > new Date()) {
14
11
  Object.keys(cache).forEach((key) => {
15
12
  if (cache[key].expiresOn < new Date()) {
@@ -75,8 +72,8 @@ const doFetchRouteData = async (path, host, mode, itemId, language, version, opt
75
72
  duration,
76
73
  };
77
74
  };
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);
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);
80
77
  return await createRouteData(result, renderings, renderOptions, mode, apiConfig, compileRendering);
81
78
  }
82
79
  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.3495",
3
+ "version": "1.0.3497",
4
4
  "type": "module",
5
5
  "description": "Alpaca Headless",
6
6
  "main": "dist/index.js",
@@ -221,7 +221,6 @@ export function renderPlaceholder(
221
221
  (data as ComponentData)._editor?.linkedComponentItem?.id ||
222
222
  data.id
223
223
  }
224
- data-typeid={ (data as ComponentData).templateId}
225
224
  data-layoutid={
226
225
  (data as ComponentData)._editor?.hostingPageItem?.id
227
226
  }
@@ -37,28 +37,14 @@ const fetchRouteData = async (
37
37
  language: string,
38
38
  version: number,
39
39
  options: RenderOptions,
40
- apiConfig?: ApiConfig,
40
+ apiConfig?: ApiConfig,
41
+ editRevision?: string,
41
42
  siteName?: string
42
43
  ): Promise<Result> => {
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
44
  const cache = globalThis.alpacaRouteDataCache;
59
-
60
- const cacheKey = itemId + language + version + siteName + path + host;
61
-
45
+ const cacheKey =
46
+ editRevision + itemId + language + version + siteName + path + host + mode;
47
+
62
48
  if (cacheKey && cache[cacheKey]?.expiresOn > new Date()) {
63
49
  Object.keys(cache).forEach((key) => {
64
50
  if (cache[key].expiresOn < new Date()) {
@@ -194,6 +180,7 @@ export async function getPage({
194
180
  renderings,
195
181
  compileRendering,
196
182
  mode,
183
+ searchParams,
197
184
  apiConfig,
198
185
  }: GetPageParams): Promise<RouteData> {
199
186
  const result = await fetchRouteData(
@@ -204,7 +191,8 @@ export async function getPage({
204
191
  language,
205
192
  version,
206
193
  renderOptions,
207
- apiConfig,
194
+ apiConfig,
195
+ searchParams["edit_rev"],
208
196
  siteName
209
197
  );
210
198