@alpaca-headless/alpaca-headless 1.0.3584 → 1.0.3586
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.
|
@@ -3,13 +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, siteName) => {
|
|
6
|
+
const fetchRouteData = async ({ path, host, mode, itemId, language, version, options, apiConfig, editRev, siteName }) => {
|
|
7
7
|
var _a;
|
|
8
|
-
if (mode === "edit" || mode === "preview") {
|
|
8
|
+
if ((mode === "edit" || mode === "preview") && !editRev) {
|
|
9
9
|
return await doFetchRouteData(path, host, mode, itemId, language, version, options, apiConfig, siteName);
|
|
10
10
|
}
|
|
11
11
|
const cache = globalThis.alpacaRouteDataCache;
|
|
12
|
-
const cacheKey = itemId + language + version + siteName + path + host;
|
|
12
|
+
const cacheKey = itemId + language + version + siteName + path + host + editRev;
|
|
13
13
|
if (cacheKey && ((_a = cache[cacheKey]) === null || _a === void 0 ? void 0 : _a.expiresOn) > new Date()) {
|
|
14
14
|
Object.keys(cache).forEach((key) => {
|
|
15
15
|
if (cache[key].expiresOn < new Date()) {
|
|
@@ -76,7 +76,17 @@ const doFetchRouteData = async (path, host, mode, itemId, language, version, opt
|
|
|
76
76
|
};
|
|
77
77
|
};
|
|
78
78
|
export async function getPage({ itemId, language, version, siteName, renderOptions, renderings, compileRendering, mode, apiConfig, }) {
|
|
79
|
-
const result = await fetchRouteData(
|
|
79
|
+
const result = await fetchRouteData({
|
|
80
|
+
path: "",
|
|
81
|
+
host: "",
|
|
82
|
+
mode: mode || "normal",
|
|
83
|
+
itemId,
|
|
84
|
+
language,
|
|
85
|
+
version,
|
|
86
|
+
options: renderOptions,
|
|
87
|
+
apiConfig,
|
|
88
|
+
siteName
|
|
89
|
+
});
|
|
80
90
|
return await createRouteData(result, renderings, renderOptions, mode, apiConfig, compileRendering);
|
|
81
91
|
}
|
|
82
92
|
async function createRouteData(result, renderings, renderOptions, mode, apiConfig, compileRendering) {
|
|
@@ -104,7 +114,17 @@ async function createRouteData(result, renderings, renderOptions, mode, apiConfi
|
|
|
104
114
|
export async function resolveRoute({ path, searchParams, host, renderOptions, renderings, compileRendering, apiConfig, }) {
|
|
105
115
|
var _a;
|
|
106
116
|
const mode = searchParams["mode"] || "normal";
|
|
107
|
-
const result = await fetchRouteData(
|
|
117
|
+
const result = await fetchRouteData({
|
|
118
|
+
path: Array.isArray(path) ? (_a = path === null || path === void 0 ? void 0 : path.join("/")) !== null && _a !== void 0 ? _a : "/" : (path || "/"),
|
|
119
|
+
host,
|
|
120
|
+
mode,
|
|
121
|
+
itemId: searchParams["itemid"] || searchParams["itemId"],
|
|
122
|
+
language: searchParams["lang"],
|
|
123
|
+
version: parseInt(searchParams["version"]),
|
|
124
|
+
options: renderOptions,
|
|
125
|
+
apiConfig,
|
|
126
|
+
editRev: searchParams["edit_rev"],
|
|
127
|
+
});
|
|
108
128
|
return await createRouteData(result, renderings, renderOptions, mode, apiConfig, compileRendering);
|
|
109
129
|
}
|
|
110
130
|
export const loadPartialLayout = async (itemId, language, version, component, placeholderKey, options, siteName, mode) => {
|
package/package.json
CHANGED
|
@@ -30,18 +30,32 @@ if (!globalThis.alpacaRouteDataCache) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
const fetchRouteData = async (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
{
|
|
34
|
+
path,
|
|
35
|
+
host,
|
|
36
|
+
mode,
|
|
37
|
+
itemId,
|
|
38
|
+
language,
|
|
39
|
+
version,
|
|
40
|
+
options,
|
|
41
|
+
apiConfig,
|
|
42
|
+
editRev,
|
|
43
|
+
siteName
|
|
44
|
+
} : {
|
|
45
|
+
path: string,
|
|
46
|
+
host: string,
|
|
47
|
+
mode: string,
|
|
48
|
+
itemId: string,
|
|
49
|
+
language: string,
|
|
50
|
+
version: number,
|
|
51
|
+
options: RenderOptions,
|
|
52
|
+
apiConfig?: ApiConfig,
|
|
53
|
+
siteName?: string,
|
|
54
|
+
editRev?: string
|
|
55
|
+
}
|
|
42
56
|
): Promise<Result> => {
|
|
43
57
|
|
|
44
|
-
if(mode === "edit" || mode === "preview") {
|
|
58
|
+
if((mode === "edit" || mode === "preview") && !editRev) {
|
|
45
59
|
return await doFetchRouteData(
|
|
46
60
|
path,
|
|
47
61
|
host,
|
|
@@ -55,9 +69,10 @@ const fetchRouteData = async (
|
|
|
55
69
|
);
|
|
56
70
|
}
|
|
57
71
|
|
|
72
|
+
|
|
58
73
|
const cache = globalThis.alpacaRouteDataCache;
|
|
59
74
|
|
|
60
|
-
const cacheKey = itemId + language + version + siteName + path + host;
|
|
75
|
+
const cacheKey = itemId + language + version + siteName + path + host + editRev;
|
|
61
76
|
|
|
62
77
|
if (cacheKey && cache[cacheKey]?.expiresOn > new Date()) {
|
|
63
78
|
Object.keys(cache).forEach((key) => {
|
|
@@ -196,17 +211,17 @@ export async function getPage({
|
|
|
196
211
|
mode,
|
|
197
212
|
apiConfig,
|
|
198
213
|
}: GetPageParams): Promise<RouteData> {
|
|
199
|
-
const result = await fetchRouteData(
|
|
200
|
-
"",
|
|
201
|
-
"",
|
|
202
|
-
mode || "normal",
|
|
214
|
+
const result = await fetchRouteData({
|
|
215
|
+
path: "",
|
|
216
|
+
host: "",
|
|
217
|
+
mode: mode || "normal",
|
|
203
218
|
itemId,
|
|
204
219
|
language,
|
|
205
220
|
version,
|
|
206
|
-
renderOptions,
|
|
221
|
+
options: renderOptions,
|
|
207
222
|
apiConfig,
|
|
208
223
|
siteName
|
|
209
|
-
);
|
|
224
|
+
});
|
|
210
225
|
|
|
211
226
|
return await createRouteData(
|
|
212
227
|
result,
|
|
@@ -290,17 +305,17 @@ export async function resolveRoute({
|
|
|
290
305
|
apiConfig,
|
|
291
306
|
}: ResolveRouteParams): Promise<RouteData> {
|
|
292
307
|
const mode = searchParams["mode"] || "normal";
|
|
293
|
-
const result = await fetchRouteData(
|
|
294
|
-
Array.isArray(path) ? path?.join("/") ?? "/" : ((path || "/") as string),
|
|
308
|
+
const result = await fetchRouteData({
|
|
309
|
+
path: Array.isArray(path) ? path?.join("/") ?? "/" : ((path || "/") as string),
|
|
295
310
|
host,
|
|
296
311
|
mode,
|
|
297
|
-
searchParams["itemid"] || searchParams["itemId"],
|
|
298
|
-
searchParams["lang"],
|
|
299
|
-
parseInt(searchParams["version"]),
|
|
300
|
-
renderOptions,
|
|
312
|
+
itemId: searchParams["itemid"] || searchParams["itemId"],
|
|
313
|
+
language: searchParams["lang"],
|
|
314
|
+
version: parseInt(searchParams["version"]),
|
|
315
|
+
options: renderOptions,
|
|
301
316
|
apiConfig,
|
|
302
|
-
searchParams["edit_rev"]
|
|
303
|
-
);
|
|
317
|
+
editRev: searchParams["edit_rev"],
|
|
318
|
+
});
|
|
304
319
|
|
|
305
320
|
return await createRouteData(
|
|
306
321
|
result,
|