@alpaca-headless/alpaca-headless 1.0.4180 → 1.0.4184
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,7 +3,7 @@ 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, editRev, siteName, urlSearchParams
|
|
6
|
+
const fetchRouteData = async ({ path, host, mode, itemId, language, version, options, apiConfig, editRev, siteName, urlSearchParams }) => {
|
|
7
7
|
var _a;
|
|
8
8
|
if ((mode === "edit" || mode === "preview") && !editRev) {
|
|
9
9
|
return await doFetchRouteData(path, host, mode, itemId, language, version, options, apiConfig, siteName, urlSearchParams);
|
|
@@ -34,7 +34,7 @@ const doFetchRouteData = async (path, host, mode, itemId, language, version, opt
|
|
|
34
34
|
version,
|
|
35
35
|
siteName,
|
|
36
36
|
options,
|
|
37
|
-
urlSearchParams
|
|
37
|
+
urlSearchParams
|
|
38
38
|
};
|
|
39
39
|
console.log(`@Fetching page layout. Host:${request.host} Path: ${request.path}`, request);
|
|
40
40
|
const startTime = performance.now();
|
|
@@ -86,7 +86,7 @@ export async function getPage({ itemId, language, version, siteName, renderOptio
|
|
|
86
86
|
version,
|
|
87
87
|
options: renderOptions,
|
|
88
88
|
apiConfig,
|
|
89
|
-
siteName
|
|
89
|
+
siteName
|
|
90
90
|
});
|
|
91
91
|
return await createRouteData(result, renderings, renderOptions, mode, apiConfig, compileRendering);
|
|
92
92
|
}
|
|
@@ -114,22 +114,18 @@ async function createRouteData(result, renderings, renderOptions, mode, apiConfi
|
|
|
114
114
|
}
|
|
115
115
|
export async function resolveRoute({ path, searchParams, host, renderOptions, renderings, compileRendering, apiConfig, }) {
|
|
116
116
|
var _a;
|
|
117
|
-
const mode = searchParams["
|
|
117
|
+
const mode = searchParams["mode"] || "normal";
|
|
118
118
|
const result = await fetchRouteData({
|
|
119
|
-
path: Array.isArray(path)
|
|
120
|
-
? (_a = path === null || path === void 0 ? void 0 : path.join("/")) !== null && _a !== void 0 ? _a : "/"
|
|
121
|
-
: (path || "/"),
|
|
119
|
+
path: Array.isArray(path) ? (_a = path === null || path === void 0 ? void 0 : path.join("/")) !== null && _a !== void 0 ? _a : "/" : (path || "/"),
|
|
122
120
|
host,
|
|
123
121
|
mode,
|
|
124
|
-
itemId: searchParams["
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
language: searchParams["sc_lang"] || searchParams["lang"],
|
|
128
|
-
version: parseInt(searchParams["sc_version"] || searchParams["version"]),
|
|
122
|
+
itemId: searchParams["itemid"] || searchParams["itemId"],
|
|
123
|
+
language: searchParams["lang"],
|
|
124
|
+
version: parseInt(searchParams["version"]),
|
|
129
125
|
options: renderOptions,
|
|
130
126
|
apiConfig,
|
|
131
127
|
editRev: searchParams["edit_rev"],
|
|
132
|
-
urlSearchParams: new URLSearchParams(searchParams).toString()
|
|
128
|
+
urlSearchParams: new URLSearchParams(searchParams).toString()
|
|
133
129
|
});
|
|
134
130
|
return await createRouteData(result, renderings, renderOptions, mode, apiConfig, compileRendering);
|
|
135
131
|
}
|
package/package.json
CHANGED
|
@@ -29,7 +29,8 @@ if (!globalThis.alpacaRouteDataCache) {
|
|
|
29
29
|
globalThis.alpacaRouteDataCache = {};
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
const fetchRouteData = async (
|
|
32
|
+
const fetchRouteData = async (
|
|
33
|
+
{
|
|
33
34
|
path,
|
|
34
35
|
host,
|
|
35
36
|
mode,
|
|
@@ -37,24 +38,26 @@ const fetchRouteData = async ({
|
|
|
37
38
|
language,
|
|
38
39
|
version,
|
|
39
40
|
options,
|
|
40
|
-
apiConfig,
|
|
41
|
+
apiConfig,
|
|
41
42
|
editRev,
|
|
42
43
|
siteName,
|
|
43
|
-
urlSearchParams
|
|
44
|
-
}: {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
44
|
+
urlSearchParams
|
|
45
|
+
} : {
|
|
46
|
+
path: string,
|
|
47
|
+
host: string,
|
|
48
|
+
mode: string,
|
|
49
|
+
itemId: string,
|
|
50
|
+
language: string,
|
|
51
|
+
version: number,
|
|
52
|
+
options: RenderOptions,
|
|
53
|
+
apiConfig?: ApiConfig,
|
|
54
|
+
siteName?: string,
|
|
55
|
+
editRev?: string,
|
|
56
|
+
urlSearchParams?: string
|
|
57
|
+
}
|
|
58
|
+
): Promise<Result> => {
|
|
59
|
+
|
|
60
|
+
if((mode === "edit" || mode === "preview") && !editRev) {
|
|
58
61
|
return await doFetchRouteData(
|
|
59
62
|
path,
|
|
60
63
|
host,
|
|
@@ -69,11 +72,11 @@ const fetchRouteData = async ({
|
|
|
69
72
|
);
|
|
70
73
|
}
|
|
71
74
|
|
|
75
|
+
|
|
72
76
|
const cache = globalThis.alpacaRouteDataCache;
|
|
73
|
-
|
|
74
|
-
const cacheKey =
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
|
|
78
|
+
const cacheKey = itemId + language + version + siteName + path + host + editRev + mode;
|
|
79
|
+
|
|
77
80
|
if (cacheKey && cache[cacheKey]?.expiresOn > new Date()) {
|
|
78
81
|
Object.keys(cache).forEach((key) => {
|
|
79
82
|
if (cache[key].expiresOn < new Date()) {
|
|
@@ -124,7 +127,7 @@ const doFetchRouteData = async (
|
|
|
124
127
|
version,
|
|
125
128
|
siteName,
|
|
126
129
|
options,
|
|
127
|
-
urlSearchParams
|
|
130
|
+
urlSearchParams
|
|
128
131
|
};
|
|
129
132
|
|
|
130
133
|
console.log(
|
|
@@ -222,8 +225,8 @@ export async function getPage({
|
|
|
222
225
|
language,
|
|
223
226
|
version,
|
|
224
227
|
options: renderOptions,
|
|
225
|
-
apiConfig,
|
|
226
|
-
siteName
|
|
228
|
+
apiConfig,
|
|
229
|
+
siteName
|
|
227
230
|
});
|
|
228
231
|
|
|
229
232
|
return await createRouteData(
|
|
@@ -307,23 +310,18 @@ export async function resolveRoute({
|
|
|
307
310
|
compileRendering,
|
|
308
311
|
apiConfig,
|
|
309
312
|
}: ResolveRouteParams): Promise<RouteData> {
|
|
310
|
-
const mode = searchParams["
|
|
313
|
+
const mode = searchParams["mode"] || "normal";
|
|
311
314
|
const result = await fetchRouteData({
|
|
312
|
-
path: Array.isArray(path)
|
|
313
|
-
? path?.join("/") ?? "/"
|
|
314
|
-
: ((path || "/") as string),
|
|
315
|
+
path: Array.isArray(path) ? path?.join("/") ?? "/" : ((path || "/") as string),
|
|
315
316
|
host,
|
|
316
317
|
mode,
|
|
317
|
-
itemId:
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
searchParams["itemId"],
|
|
321
|
-
language: searchParams["sc_lang"] || searchParams["lang"],
|
|
322
|
-
version: parseInt(searchParams["sc_version"] || searchParams["version"]),
|
|
318
|
+
itemId: searchParams["itemid"] || searchParams["itemId"],
|
|
319
|
+
language: searchParams["lang"],
|
|
320
|
+
version: parseInt(searchParams["version"]),
|
|
323
321
|
options: renderOptions,
|
|
324
322
|
apiConfig,
|
|
325
323
|
editRev: searchParams["edit_rev"],
|
|
326
|
-
urlSearchParams: new URLSearchParams(searchParams).toString()
|
|
324
|
+
urlSearchParams: new URLSearchParams(searchParams).toString()
|
|
327
325
|
});
|
|
328
326
|
|
|
329
327
|
return await createRouteData(
|