@alpaca-headless/alpaca-headless-nextjs 1.0.3390 → 1.0.3399
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.
- package/.eslintrc.json +3 -0
- package/README.md +36 -0
- package/dist/EditorIntegration.d.ts +6 -0
- package/dist/EditorIntegration.js +5 -0
- package/dist/EditorIntegrationClient.d.ts +9 -0
- package/dist/EditorIntegrationClient.js +54 -0
- package/dist/client-components/MultiComponentEditor.d.ts +12 -0
- package/dist/client-components/MultiComponentEditor.js +47 -0
- package/dist/client-components/index.d.ts +1 -0
- package/dist/client-components/index.js +2 -0
- package/dist/handleBasicAuthRoute.d.ts +8 -0
- package/dist/handleBasicAuthRoute.js +42 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +11 -0
- package/dist/middleware/handleRequest.d.ts +8 -0
- package/dist/middleware/handleRequest.js +42 -0
- package/dist/middleware/index.d.ts +1 -0
- package/dist/middleware/index.js +1 -0
- package/dist/proxy/index.d.ts +8 -0
- package/dist/proxy/index.js +77 -0
- package/dist/useExposeRefreshFunction.d.ts +7 -0
- package/dist/useExposeRefreshFunction.js +32 -0
- package/next.config.mjs +4 -0
- package/package.json +51 -29
- package/postcss.config.js +6 -0
- package/src/EditorIntegration.tsx +11 -0
- package/src/EditorIntegrationClient.tsx +74 -0
- package/src/client-components/MultiComponentEditor.tsx +133 -0
- package/src/client-components/index.ts +3 -0
- package/src/handleBasicAuthRoute.ts +62 -0
- package/src/index.ts +15 -0
- package/src/middleware/handleRequest.ts +62 -0
- package/src/middleware/index.ts +1 -0
- package/src/proxy/index.ts +108 -0
- package/src/useExposeRefreshFunction.ts +45 -0
- package/tailwind.config.js +17 -0
- package/tailwind.config.ts +20 -0
- package/tsconfig.json +26 -0
- package/dist/cjs/alpacaContext.js +0 -12
- package/dist/cjs/components/Image.js +0 -36
- package/dist/cjs/components/Link.js +0 -22
- package/dist/cjs/components/Picture.js +0 -116
- package/dist/cjs/components/Placeholder.js +0 -55
- package/dist/cjs/components/RichText.js +0 -42
- package/dist/cjs/components/Text.js +0 -39
- package/dist/cjs/components/index.js +0 -22
- package/dist/cjs/fieldTypes.js +0 -2
- package/dist/cjs/graphQLTypes.js +0 -2
- package/dist/cjs/index.js +0 -36
- package/dist/cjs/layoutData.js +0 -2
- package/dist/cjs/loadRouteData.js +0 -114
- package/dist/cjs/mediaProtection.js +0 -56
- package/dist/esm/alpacaContext.js +0 -8
- package/dist/esm/components/Image.js +0 -32
- package/dist/esm/components/Link.js +0 -18
- package/dist/esm/components/Picture.js +0 -112
- package/dist/esm/components/Placeholder.js +0 -51
- package/dist/esm/components/RichText.js +0 -35
- package/dist/esm/components/Text.js +0 -32
- package/dist/esm/components/index.js +0 -6
- package/dist/esm/fieldTypes.js +0 -1
- package/dist/esm/graphQLTypes.js +0 -1
- package/dist/esm/index.js +0 -7
- package/dist/esm/layoutData.js +0 -1
- package/dist/esm/loadRouteData.js +0 -110
- package/dist/esm/mediaProtection.js +0 -49
- package/next.config.js +0 -6
- package/types/alpacaContext.d.ts +0 -19
- package/types/components/Image.d.ts +0 -10
- package/types/components/Link.d.ts +0 -6
- package/types/components/Picture.d.ts +0 -20
- package/types/components/Placeholder.d.ts +0 -5
- package/types/components/RichText.d.ts +0 -282
- package/types/components/Text.d.ts +0 -278
- package/types/components/index.d.ts +0 -6
- package/types/fieldTypes.d.ts +0 -62
- package/types/graphQLTypes.d.ts +0 -26
- package/types/index.d.ts +0 -7
- package/types/layoutData.d.ts +0 -11
- package/types/loadRouteData.d.ts +0 -36
- package/types/mediaProtection.d.ts +0 -2
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
|
-
import { hashImageUrl } from "../mediaProtection";
|
|
14
|
-
// const addClassName = (otherAttrs: { [key: string]: unknown }): void => {
|
|
15
|
-
// if (otherAttrs.class) {
|
|
16
|
-
// // if any classes are defined properly already
|
|
17
|
-
// if (otherAttrs.className) {
|
|
18
|
-
// let className: string = otherAttrs.className as string;
|
|
19
|
-
// className += ` ${otherAttrs.class}`;
|
|
20
|
-
// otherAttrs.className = className;
|
|
21
|
-
// } else {
|
|
22
|
-
// otherAttrs.className = otherAttrs.class;
|
|
23
|
-
// }
|
|
24
|
-
// delete otherAttrs.class;
|
|
25
|
-
// }
|
|
26
|
-
// };
|
|
27
|
-
export const Picture = (_a) => {
|
|
28
|
-
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
29
|
-
var { field, imageParams, sources, defaultVariant, renderJsonLinkedData } = _a, otherProps = __rest(_a, ["field", "imageParams", "sources", "defaultVariant", "renderJsonLinkedData"]);
|
|
30
|
-
if (!field)
|
|
31
|
-
return null;
|
|
32
|
-
const variants = (_b = field.value) === null || _b === void 0 ? void 0 : _b.variants;
|
|
33
|
-
const img = (_d = (_c = field.value) === null || _c === void 0 ? void 0 : _c.variants.find((x) => x.name.toUpperCase() == (defaultVariant === null || defaultVariant === void 0 ? void 0 : defaultVariant.toUpperCase()))) !== null && _d !== void 0 ? _d : (_e = field.value) === null || _e === void 0 ? void 0 : _e.variants[0];
|
|
34
|
-
const attrs = Object.assign({ src: img === null || img === void 0 ? void 0 : img.src }, otherProps);
|
|
35
|
-
const videoVariants = variants === null || variants === void 0 ? void 0 : variants.filter(f => f.videoUrl !== null);
|
|
36
|
-
let videoVariantSources = {};
|
|
37
|
-
videoVariants === null || videoVariants === void 0 ? void 0 : videoVariants.forEach(variant => {
|
|
38
|
-
let key = `data-src-${variant.name.toLowerCase().replace(" ", "")}`;
|
|
39
|
-
videoVariantSources[key] = variant.videoUrl;
|
|
40
|
-
});
|
|
41
|
-
const video = img === null || img === void 0 ? void 0 : img.videoUrl;
|
|
42
|
-
const videoAttr = Object.assign(Object.assign({ src: video }, videoVariantSources), otherProps);
|
|
43
|
-
if (!(sources === null || sources === void 0 ? void 0 : sources.length)) {
|
|
44
|
-
return _jsx("img", Object.assign({}, attrs, { alt: (_f = field.value) === null || _f === void 0 ? void 0 : _f.alt }));
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
return (_jsxs(_Fragment, { children: [_jsxs("picture", { children: [sources === null || sources === void 0 ? void 0 : sources.map((source) => {
|
|
48
|
-
const variant = variants === null || variants === void 0 ? void 0 : variants.find((v) => v.name.toLowerCase() == source.variant.toLowerCase() && v.src);
|
|
49
|
-
if (!variant)
|
|
50
|
-
return;
|
|
51
|
-
let srcSet = hashImageUrl(variant.src);
|
|
52
|
-
const getScaledImage = (variant, width) => {
|
|
53
|
-
if (width > variant.width)
|
|
54
|
-
return { src: variant.src, width: 0 };
|
|
55
|
-
else
|
|
56
|
-
return { src: variant.src + `${variant.src.includes('?') ? '&' : '?'}mw=` + width, width: width };
|
|
57
|
-
};
|
|
58
|
-
if (source.widths && source.widths.length) {
|
|
59
|
-
let scaledImages = source.widths.map((x) => getScaledImage(variant, x));
|
|
60
|
-
srcSet = "";
|
|
61
|
-
for (let w = 0; w < scaledImages.length; w++) {
|
|
62
|
-
if (srcSet.length)
|
|
63
|
-
srcSet = srcSet + ", ";
|
|
64
|
-
srcSet +=
|
|
65
|
-
hashImageUrl(scaledImages[w].src) +
|
|
66
|
-
" " +
|
|
67
|
-
source.widths[w] +
|
|
68
|
-
"w";
|
|
69
|
-
if (scaledImages[w].width === 0)
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
if (source.width) {
|
|
75
|
-
srcSet = hashImageUrl(getScaledImage(variant, source.width).src);
|
|
76
|
-
if (source.scales) {
|
|
77
|
-
let scaledImages = source.scales.map((x) => { var _a; return getScaledImage(variant, ((_a = source.width) !== null && _a !== void 0 ? _a : 0) * x); });
|
|
78
|
-
srcSet = "";
|
|
79
|
-
for (let w = 0; w < scaledImages.length; w++) {
|
|
80
|
-
if (srcSet.length)
|
|
81
|
-
srcSet = srcSet + ", ";
|
|
82
|
-
srcSet +=
|
|
83
|
-
hashImageUrl(scaledImages[w].src) +
|
|
84
|
-
" " +
|
|
85
|
-
source.scales[w] +
|
|
86
|
-
"x";
|
|
87
|
-
if (scaledImages[w].width === 0)
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return (_jsx("source", { srcSet: srcSet, media: source.media }, source.variant + source.media));
|
|
94
|
-
}), _jsx("img", Object.assign({}, attrs, { alt: (_g = field.value) === null || _g === void 0 ? void 0 : _g.alt }))] }), renderJsonLinkedData && !video ? _jsx("script", { type: "application/ld+json", dangerouslySetInnerHTML: {
|
|
95
|
-
__html: JSON.stringify({
|
|
96
|
-
"@context": "http://schema.org",
|
|
97
|
-
"@type": "ImageObject",
|
|
98
|
-
"image": img === null || img === void 0 ? void 0 : img.src,
|
|
99
|
-
"description": (_h = field.value) === null || _h === void 0 ? void 0 : _h.alt,
|
|
100
|
-
"name": (_j = field.value) === null || _j === void 0 ? void 0 : _j.name
|
|
101
|
-
})
|
|
102
|
-
} }) : null, video && _jsx("video", Object.assign({}, videoAttr)), renderJsonLinkedData && video ? _jsx("script", { type: "application/ld+json", dangerouslySetInnerHTML: {
|
|
103
|
-
__html: JSON.stringify({
|
|
104
|
-
"@context": "http://schema.org",
|
|
105
|
-
"@type": "VideoObject",
|
|
106
|
-
"contentUrl": img === null || img === void 0 ? void 0 : img.src,
|
|
107
|
-
"description": (_k = field.value) === null || _k === void 0 ? void 0 : _k.alt,
|
|
108
|
-
"name": (_l = field.value) === null || _l === void 0 ? void 0 : _l.name
|
|
109
|
-
})
|
|
110
|
-
} }) : null] }));
|
|
111
|
-
}
|
|
112
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
-
import { useAlpacaContext, } from "..";
|
|
12
|
-
export function Placeholder({ name, content, }) {
|
|
13
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
-
const data = yield content;
|
|
15
|
-
if (!("placeholders" in data))
|
|
16
|
-
return;
|
|
17
|
-
const placeholderData = data.placeholders.find((x) => x.name == name);
|
|
18
|
-
if (!placeholderData)
|
|
19
|
-
return;
|
|
20
|
-
const context = useAlpacaContext();
|
|
21
|
-
const loader = context.componentModuleLoader;
|
|
22
|
-
const promises = placeholderData === null || placeholderData === void 0 ? void 0 : placeholderData.components.map((component) => __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
let module = null;
|
|
24
|
-
try {
|
|
25
|
-
module = yield loader(component.componentType);
|
|
26
|
-
}
|
|
27
|
-
catch (e) {
|
|
28
|
-
console.log(e);
|
|
29
|
-
}
|
|
30
|
-
if (!module) {
|
|
31
|
-
console.log("Could not find module " + component.componentType);
|
|
32
|
-
return {
|
|
33
|
-
data: { name: component.componentType },
|
|
34
|
-
Component: ComponentNotFound,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
return { data: component, Component: module.default };
|
|
38
|
-
}));
|
|
39
|
-
const components = yield Promise.all(promises);
|
|
40
|
-
return (_jsx(_Fragment, { children: components.map(({ Component, data }) => (_jsx(Component, { component: data }))) }));
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
function ComponentNotFound({ component }) {
|
|
44
|
-
return (_jsxs("div", { style: {
|
|
45
|
-
backgroundColor: "orange",
|
|
46
|
-
color: "red",
|
|
47
|
-
fontSize: 18,
|
|
48
|
-
padding: 10,
|
|
49
|
-
border: "3px solid red",
|
|
50
|
-
}, children: ["Component not found: ", component.name, " "] }));
|
|
51
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
-
var t = {};
|
|
12
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
-
t[p] = s[p];
|
|
14
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
-
t[p[i]] = s[p[i]];
|
|
18
|
-
}
|
|
19
|
-
return t;
|
|
20
|
-
};
|
|
21
|
-
import React from "react";
|
|
22
|
-
export function RichText(_a) {
|
|
23
|
-
var { field, tag, editable } = _a, props = __rest(_a, ["field", "tag", "editable"]);
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
if (!field)
|
|
26
|
-
return;
|
|
27
|
-
const internalProps = {
|
|
28
|
-
dangerouslySetInnerHTML: {
|
|
29
|
-
__html: field.value,
|
|
30
|
-
},
|
|
31
|
-
editable: editable,
|
|
32
|
-
};
|
|
33
|
-
return React.createElement(tag || "div", Object.assign(props, internalProps));
|
|
34
|
-
});
|
|
35
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
-
var t = {};
|
|
12
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
-
t[p] = s[p];
|
|
14
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
-
t[p[i]] = s[p[i]];
|
|
18
|
-
}
|
|
19
|
-
return t;
|
|
20
|
-
};
|
|
21
|
-
import React from "react";
|
|
22
|
-
export function Text(_a) {
|
|
23
|
-
var { field, tag, editable } = _a, props = __rest(_a, ["field", "tag", "editable"]);
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
if (!field)
|
|
26
|
-
return;
|
|
27
|
-
if (editable)
|
|
28
|
-
return React.createElement(tag || "div", props, field.value);
|
|
29
|
-
else
|
|
30
|
-
return React.createElement(tag || "div", props, field.value);
|
|
31
|
-
});
|
|
32
|
-
}
|
package/dist/esm/fieldTypes.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/esm/graphQLTypes.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/esm/index.js
DELETED
package/dist/esm/layoutData.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { useAlpacaContext } from "./alpacaContext";
|
|
11
|
-
import { cookies } from "next/headers";
|
|
12
|
-
import { cache } from "react";
|
|
13
|
-
const fetchRouteData = cache((path, host, mode, itemId, language) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
-
const request = {
|
|
15
|
-
Path: path,
|
|
16
|
-
Host: host,
|
|
17
|
-
Mode: mode,
|
|
18
|
-
ItemId: itemId,
|
|
19
|
-
Language: language,
|
|
20
|
-
};
|
|
21
|
-
const url = process.env.LAYOUT_SERVICE_URL + "/alpaca/headless/layout";
|
|
22
|
-
console.log(`Fetching page layout from ${url}. Host:${request.Host} Path: ${request.Path}`);
|
|
23
|
-
const response = yield fetch(url, {
|
|
24
|
-
method: "POST",
|
|
25
|
-
body: JSON.stringify(request),
|
|
26
|
-
credentials: "include",
|
|
27
|
-
headers: {
|
|
28
|
-
"Content-Type": "application/json",
|
|
29
|
-
Cookie: cookies().toString(),
|
|
30
|
-
"x-api-key": process.env.API_KEY,
|
|
31
|
-
},
|
|
32
|
-
next: {
|
|
33
|
-
tags: ["pages"],
|
|
34
|
-
revalidate: mode === "preview" || mode == "edit" ? 0 : 30,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
if (response.status === 404) {
|
|
38
|
-
return {
|
|
39
|
-
type: "notfound",
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
if (response.status === 301) {
|
|
43
|
-
return {
|
|
44
|
-
type: "redirect",
|
|
45
|
-
location: response.url,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
if (!response.ok) {
|
|
49
|
-
const message = yield response.text();
|
|
50
|
-
return {
|
|
51
|
-
type: "error",
|
|
52
|
-
errorCode: response.status,
|
|
53
|
-
message: message,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
const data = yield response.json();
|
|
57
|
-
console.log(data);
|
|
58
|
-
const context = useAlpacaContext();
|
|
59
|
-
context.pageContext = {
|
|
60
|
-
itemId: data.page.id,
|
|
61
|
-
templateId: data.page.templateId,
|
|
62
|
-
language: data.page.language,
|
|
63
|
-
site: data.site,
|
|
64
|
-
pageEditing: true,
|
|
65
|
-
pageState: "",
|
|
66
|
-
database: data.page.database,
|
|
67
|
-
};
|
|
68
|
-
context.fields = data.page.fields;
|
|
69
|
-
context.dictionary = yield loadDictionary(context.pageContext.site.name, context.pageContext.language, mode);
|
|
70
|
-
context.translate = (text) => {
|
|
71
|
-
return context.dictionary[text] || text;
|
|
72
|
-
};
|
|
73
|
-
return Object.assign(Object.assign({}, data.page), { type: "page" });
|
|
74
|
-
}));
|
|
75
|
-
export function loadRouteData(params, searchParams, host) {
|
|
76
|
-
var _a, _b;
|
|
77
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
const result = yield fetchRouteData((_b = (_a = params.path) === null || _a === void 0 ? void 0 : _a.join("/")) !== null && _b !== void 0 ? _b : "/", host, searchParams["mode"] || "normal", searchParams["itemid"], searchParams["language"]);
|
|
79
|
-
return result;
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
function loadDictionary(siteName, language, mode) {
|
|
83
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
const url = process.env.LAYOUT_SERVICE_URL +
|
|
85
|
-
"/alpaca/headless/dictionary?siteName=" +
|
|
86
|
-
siteName +
|
|
87
|
-
"&language=" +
|
|
88
|
-
language;
|
|
89
|
-
console.log(`Fetching dictionary from ${url}.`);
|
|
90
|
-
const response = yield fetch(url, {
|
|
91
|
-
method: "GET",
|
|
92
|
-
credentials: "include",
|
|
93
|
-
headers: {
|
|
94
|
-
"Content-Type": "application/json",
|
|
95
|
-
Cookie: cookies().toString(),
|
|
96
|
-
},
|
|
97
|
-
next: {
|
|
98
|
-
tags: ["dictionary"],
|
|
99
|
-
revalidate: mode === "preview" || mode == "edit" ? 15 : 600,
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
if (!response.ok) {
|
|
103
|
-
console.log("Could not load dictionary: Response code: " + response.status);
|
|
104
|
-
return {};
|
|
105
|
-
}
|
|
106
|
-
const data = yield response.json();
|
|
107
|
-
console.log(data);
|
|
108
|
-
return data;
|
|
109
|
-
});
|
|
110
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import crypto from "crypto";
|
|
2
|
-
import "url";
|
|
3
|
-
const protectedParams = [
|
|
4
|
-
"w",
|
|
5
|
-
"h",
|
|
6
|
-
"mw",
|
|
7
|
-
"mh",
|
|
8
|
-
"sc",
|
|
9
|
-
"as",
|
|
10
|
-
"bc",
|
|
11
|
-
"db",
|
|
12
|
-
"iar",
|
|
13
|
-
"la",
|
|
14
|
-
"thn",
|
|
15
|
-
"vs",
|
|
16
|
-
"sc_content",
|
|
17
|
-
"sc_lang",
|
|
18
|
-
"sc_site",
|
|
19
|
-
"gray",
|
|
20
|
-
"rev",
|
|
21
|
-
"devicepixelratio",
|
|
22
|
-
"encodequality",
|
|
23
|
-
"rx",
|
|
24
|
-
"ry",
|
|
25
|
-
"rw",
|
|
26
|
-
"rh",
|
|
27
|
-
"crop",
|
|
28
|
-
];
|
|
29
|
-
export function hashImageUrl(url) {
|
|
30
|
-
if (!process.env.MEDIA_REQUESTPROTECTION_SHAREDSECRET)
|
|
31
|
-
return url;
|
|
32
|
-
if (!url)
|
|
33
|
-
return url;
|
|
34
|
-
const baseURL = 'http://temp-base-url.com'; // This will serve as a placeholder.
|
|
35
|
-
const uri = new URL(url.toLowerCase(), baseURL);
|
|
36
|
-
uri.searchParams.delete("hash");
|
|
37
|
-
const searchParams = protectedParams
|
|
38
|
-
.map((x) => ({ name: x, val: uri.searchParams.get(x) }))
|
|
39
|
-
.filter((x) => x.val)
|
|
40
|
-
.map((x) => x.name + "=" + x.val)
|
|
41
|
-
.join("&");
|
|
42
|
-
const stringToProtect = uri.pathname.substring(1) + "?" + searchParams;
|
|
43
|
-
const hash = crypto
|
|
44
|
-
.createHash("md5")
|
|
45
|
-
.update(stringToProtect + process.env.MEDIA_REQUESTPROTECTION_SHAREDSECRET, "utf16le")
|
|
46
|
-
.digest("hex");
|
|
47
|
-
uri.searchParams.set("hash", hash);
|
|
48
|
-
return url.startsWith('http') ? uri.toString() : uri.pathname + uri.search;
|
|
49
|
-
}
|
package/next.config.js
DELETED
package/types/alpacaContext.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
type AlpacaContext = {
|
|
2
|
-
translate: (text: string) => string;
|
|
3
|
-
componentModuleLoader: (name: string) => Promise<any>;
|
|
4
|
-
pageContext: {
|
|
5
|
-
itemId: string;
|
|
6
|
-
templateId: string;
|
|
7
|
-
language: string;
|
|
8
|
-
database: string;
|
|
9
|
-
pageEditing: boolean;
|
|
10
|
-
pageState: string;
|
|
11
|
-
site: {
|
|
12
|
-
name: string;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
fields: unknown;
|
|
16
|
-
dictionary: any;
|
|
17
|
-
};
|
|
18
|
-
export declare function useAlpacaContext(): AlpacaContext;
|
|
19
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { ImageField } from "../fieldTypes";
|
|
3
|
-
export interface ImageProps {
|
|
4
|
-
[attributeName: string]: unknown;
|
|
5
|
-
field?: ImageField;
|
|
6
|
-
imageParams?: {
|
|
7
|
-
[paramName: string]: string | number;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
export declare const Image: React.FC<ImageProps>;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { LinkField } from "../fieldTypes";
|
|
3
|
-
export declare function Link({ field, children, ...props }: {
|
|
4
|
-
field: LinkField;
|
|
5
|
-
children: React.ReactNode;
|
|
6
|
-
} & React.AnchorHTMLAttributes<HTMLAnchorElement>): import("react/jsx-runtime").JSX.Element | undefined;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { PictureField } from "../fieldTypes";
|
|
3
|
-
export interface PictureSource {
|
|
4
|
-
media: string;
|
|
5
|
-
variant: string;
|
|
6
|
-
widths?: number[];
|
|
7
|
-
width?: number;
|
|
8
|
-
scales?: number[];
|
|
9
|
-
}
|
|
10
|
-
export interface PictureProps {
|
|
11
|
-
[attributeName: string]: unknown;
|
|
12
|
-
field?: PictureField;
|
|
13
|
-
imageParams?: {
|
|
14
|
-
[paramName: string]: string | number;
|
|
15
|
-
};
|
|
16
|
-
defaultVariant?: string;
|
|
17
|
-
sources?: PictureSource[];
|
|
18
|
-
renderJsonLinkedData?: boolean;
|
|
19
|
-
}
|
|
20
|
-
export declare const Picture: React.FC<PictureProps>;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { ComponentData, Page, Redirect, NotFound, Error } from "..";
|
|
2
|
-
export declare function Placeholder({ name, content, }: {
|
|
3
|
-
name: string;
|
|
4
|
-
content: Promise<Error | Page | Redirect | NotFound | ComponentData> | ComponentData;
|
|
5
|
-
}): Promise<import("react/jsx-runtime").JSX.Element | undefined>;
|