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