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