@enonic/nextjs-adapter 2.0.1 → 2.0.2

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/ComponentRegistry.d.ts +64 -0
  2. package/ComponentRegistry.js +121 -0
  3. package/UrlProcessor.d.ts +25 -0
  4. package/{src/UrlProcessor.ts → UrlProcessor.js} +35 -53
  5. package/baseMappings.d.ts +1 -0
  6. package/{src/baseMappings.ts → baseMappings.js} +3 -13
  7. package/guillotine/fetchContent.d.ts +49 -0
  8. package/{src/guillotine/fetchContent.ts → guillotine/fetchContent.js} +243 -493
  9. package/guillotine/getMetaData.d.ts +94 -0
  10. package/guillotine/getMetaData.js +128 -0
  11. package/{src/index.ts → index.d.ts} +1 -1
  12. package/index.js +5 -0
  13. package/package.json +2 -2
  14. package/query/Shortcut.d.ts +1 -0
  15. package/server/ClearableFileCache.d.ts +31 -0
  16. package/server/ClearableFileCache.js +472 -0
  17. package/server/cache.d.ts +2 -0
  18. package/server/cache.js +129 -0
  19. package/server/index.d.ts +5 -0
  20. package/server/index.js +132 -0
  21. package/utils.d.ts +114 -0
  22. package/{src/utils.ts → utils.js} +69 -148
  23. package/views/BaseComponent.d.ts +25 -0
  24. package/{src/views/BaseComponent.tsx → views/BaseComponent.jsx} +39 -73
  25. package/views/BaseContent.d.ts +4 -0
  26. package/{src/views/BaseContent.tsx → views/BaseContent.jsx} +17 -24
  27. package/views/BaseLayout.d.ts +17 -0
  28. package/views/BaseLayout.jsx +24 -0
  29. package/views/BaseMacro.d.ts +16 -0
  30. package/{src/views/BaseMacro.tsx → views/BaseMacro.jsx} +29 -45
  31. package/views/BasePage.d.ts +19 -0
  32. package/views/BasePage.jsx +34 -0
  33. package/views/BasePart.d.ts +19 -0
  34. package/views/BasePart.jsx +24 -0
  35. package/views/Empty.d.ts +3 -0
  36. package/{src/views/Empty.tsx → views/Empty.jsx} +0 -2
  37. package/views/Fragment.d.ts +10 -0
  38. package/views/Fragment.jsx +30 -0
  39. package/views/MainView.d.ts +4 -0
  40. package/views/MainView.jsx +14 -0
  41. package/views/Region.d.ts +20 -0
  42. package/views/Region.jsx +52 -0
  43. package/views/RichTextView.d.ts +16 -0
  44. package/{src/views/RichTextView.tsx → views/RichTextView.jsx} +10 -31
  45. package/views/SingleComponent.d.ts +5 -0
  46. package/{src/views/SingleComponent.tsx → views/SingleComponent.jsx} +2 -8
  47. package/views/StaticContent.d.ts +15 -0
  48. package/views/StaticContent.jsx +36 -0
  49. package/views/Text.d.ts +9 -0
  50. package/views/Text.jsx +4 -0
  51. package/views/macros/DefaultMacro.d.ts +4 -0
  52. package/views/macros/DefaultMacro.jsx +3 -0
  53. package/views/macros/DisableMacro.d.ts +3 -0
  54. package/views/macros/DisableMacro.jsx +2 -0
  55. package/.eslint-childrc.js +0 -17
  56. package/.eslintrc.js +0 -15
  57. package/.github/dependabot.yml +0 -20
  58. package/.github/pull-merger.yml +0 -1
  59. package/.github/workflows/release.yml +0 -39
  60. package/LICENSE +0 -201
  61. package/RELEASE.md +0 -75
  62. package/server/.eslintrc.js +0 -11
  63. package/server/ClearableFileCache.ts +0 -410
  64. package/server/cache.ts +0 -50
  65. package/server/index.ts +0 -74
  66. package/server/tsconfig.json +0 -23
  67. package/src/.eslintrc.js +0 -11
  68. package/src/ComponentRegistry.ts +0 -189
  69. package/src/guillotine/getMetaData.ts +0 -246
  70. package/src/tsconfig.json +0 -20
  71. package/src/views/BaseLayout.tsx +0 -45
  72. package/src/views/BasePage.tsx +0 -56
  73. package/src/views/BasePart.tsx +0 -50
  74. package/src/views/Fragment.tsx +0 -45
  75. package/src/views/MainView.tsx +0 -21
  76. package/src/views/Region.tsx +0 -89
  77. package/src/views/StaticContent.tsx +0 -40
  78. package/src/views/Text.tsx +0 -15
  79. package/src/views/macros/DefaultMacro.tsx +0 -9
  80. package/src/views/macros/DisableMacro.tsx +0 -8
  81. /package/{src/query/Shortcut.ts → query/Shortcut.js} +0 -0
@@ -0,0 +1,132 @@
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 __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.withEnonicCache = exports.PURGE_CACHE_URL = void 0;
43
+ var http_1 = require("http");
44
+ var cache_1 = require("./cache");
45
+ var path_1 = __importDefault(require("path"));
46
+ var hostname = process.env.HOST || '127.0.0.1';
47
+ var dev = process.env.NODE_ENV !== 'production';
48
+ var port = process.env.PORT && parseInt(process.env.PORT, 10) || (dev ? 3000 : 4242);
49
+ exports.PURGE_CACHE_URL = '/_/enonic/cache/purge';
50
+ var withEnonicCache = function (config) {
51
+ var exp = config.experimental || {};
52
+ exp.isrMemoryCacheSize = exp.isrMemoryCacheSize || 1000000;
53
+ exp.incrementalCacheHandlerPath = path_1.default.resolve(__dirname, 'ClearableFileCache.js');
54
+ config.experimental = exp;
55
+ return config;
56
+ };
57
+ exports.withEnonicCache = withEnonicCache;
58
+ // Not typed to prevent collision of local types with end-user ones
59
+ exports.default = (function (next) { return __awaiter(void 0, void 0, void 0, function () {
60
+ var nextServer, nextHandler;
61
+ return __generator(this, function (_a) {
62
+ switch (_a.label) {
63
+ case 0:
64
+ nextServer = next({ dev: dev, hostname: hostname, port: port });
65
+ nextHandler = nextServer.getRequestHandler();
66
+ return [4 /*yield*/, nextServer.prepare().then(function () { return __awaiter(void 0, void 0, void 0, function () {
67
+ var nextNodeServer, opts, purgeUrl, server;
68
+ var _a;
69
+ return __generator(this, function (_b) {
70
+ switch (_b.label) {
71
+ case 0: return [4 /*yield*/, ((_a = nextServer['getServer']) === null || _a === void 0 ? void 0 : _a.call(nextServer))];
72
+ case 1:
73
+ nextNodeServer = _b.sent();
74
+ if (!nextNodeServer) {
75
+ console.error('Unable to access incremental cache, cache purge endpoint will be disabled');
76
+ return [2 /*return*/, nextServer];
77
+ }
78
+ opts = nextNodeServer['serverOptions'].conf;
79
+ purgeUrl = ((opts === null || opts === void 0 ? void 0 : opts.basePath) || '') + exports.PURGE_CACHE_URL;
80
+ console.info("Staring cache purge endpoint at ".concat(purgeUrl, "..."));
81
+ server = (0, http_1.createServer)(function (req, res) { return __awaiter(void 0, void 0, void 0, function () {
82
+ var parsedUrl, tokenParam, cache, pathParam;
83
+ return __generator(this, function (_a) {
84
+ switch (_a.label) {
85
+ case 0:
86
+ parsedUrl = new URL("http://".concat(hostname, ":").concat(port).concat(req.url || ''));
87
+ if (!(parsedUrl.pathname !== purgeUrl)) return [3 /*break*/, 2];
88
+ return [4 /*yield*/, nextHandler(req, res)];
89
+ case 1:
90
+ _a.sent();
91
+ return [3 /*break*/, 5];
92
+ case 2:
93
+ if (!dev) return [3 /*break*/, 3];
94
+ console.warn('\nCache clearing is not available in DEV mode.\n');
95
+ res.setHeader('Content-Type', 'application/json');
96
+ res.end(JSON.stringify({ purged: false }));
97
+ return [3 /*break*/, 5];
98
+ case 3:
99
+ tokenParam = parsedUrl.searchParams.get('token');
100
+ if (tokenParam !== process.env.ENONIC_API_TOKEN) {
101
+ // XP hijacks 401 to show login page, so send 407 instead
102
+ res.statusCode = 407;
103
+ res.end(JSON.stringify({ message: 'Invalid token' }));
104
+ return [2 /*return*/];
105
+ }
106
+ cache = nextNodeServer.getIncrementalCache({
107
+ requestHeaders: Object.assign({}, req.headers),
108
+ });
109
+ pathParam = parsedUrl.searchParams.get('path') || undefined;
110
+ return [4 /*yield*/, (0, cache_1.purgeCache)(cache, pathParam)];
111
+ case 4:
112
+ _a.sent();
113
+ res.setHeader('Content-Type', 'application/json');
114
+ res.end(JSON.stringify({ purged: true }));
115
+ _a.label = 5;
116
+ case 5: return [2 /*return*/];
117
+ }
118
+ });
119
+ }); }).listen(port, hostname, function () {
120
+ console.info("Server ready on ".concat(hostname, ":").concat(port));
121
+ }).on('error', function (e) {
122
+ console.error('Server error:', e);
123
+ server.close();
124
+ });
125
+ return [2 /*return*/, nextServer];
126
+ }
127
+ });
128
+ }); })];
129
+ case 1: return [2 /*return*/, _a.sent()];
130
+ }
131
+ });
132
+ }); });
package/utils.d.ts ADDED
@@ -0,0 +1,114 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /** Import config values from .env, .env.development and .env.production */
4
+ import { GetServerSidePropsContext } from 'next';
5
+ import { ParsedUrlQuery } from 'node:querystring';
6
+ import { IncomingHttpHeaders } from 'http';
7
+ export declare const IS_DEV_MODE: boolean;
8
+ export declare const PURGE_CACHE_URL = "/_/enonic/cache/purge";
9
+ export declare enum ENV_VARS {
10
+ PROJECTS = "ENONIC_PROJECTS",
11
+ API = "ENONIC_API",
12
+ API_TOKEN = "ENONIC_API_TOKEN"
13
+ }
14
+ /** Optional utility value - defining in one place the name of the target app (the app that defines the content types, the app name is therefore part of the content type strings used both in typeselector and in query introspections) */
15
+ export declare const APP_NAME: string;
16
+ /** Optional utility value - derived from APP_NAME, only with underscores instead of dots */
17
+ export declare const APP_NAME_UNDERSCORED: string;
18
+ /** Optional utility value - derived from APP_NAME, only with dashes instead of dots */
19
+ export declare const APP_NAME_DASHED: string;
20
+ export declare const XP_BASE_URL_HEADER = "xpbaseurl";
21
+ export declare const RENDER_MODE_HEADER = "content-studio-mode";
22
+ export declare const PROJECT_ID_HEADER = "content-studio-project";
23
+ export declare const JSESSIONID_HEADER = "jsessionid";
24
+ export declare const PORTAL_COMPONENT_ATTRIBUTE = "data-portal-component-type";
25
+ export declare const PORTAL_REGION_ATTRIBUTE = "data-portal-region";
26
+ export declare const FRAGMENT_CONTENTTYPE_NAME = "portal:fragment";
27
+ export declare const FRAGMENT_DEFAULT_REGION_NAME = "fragment";
28
+ export declare const PAGE_TEMPLATE_CONTENTTYPE_NAME = "portal:page-template";
29
+ export declare const PAGE_TEMPLATE_FOLDER = "portal:template-folder";
30
+ export declare const SITE_CONTENTTYPE_NAME = "portal:site";
31
+ export declare const LOCALE_HEADER = "locale";
32
+ export declare const LOCALES_HEADER = "locales";
33
+ export declare const DEFAULT_LOCALE_HEADER = "default-locale";
34
+ /** excluded contents:
35
+ * - folder
36
+ * - shortcuts (redirect can't be used in prerender)
37
+ * - media
38
+ * - paths with '/_' in them
39
+ */
40
+ export declare const GET_STATIC_PATHS_QUERY = "query ($count: Int) {\n guillotine {\n queryDsl(\n first: $count,\n sort: {\n field: \"modifiedTime\",\n direction: DESC \n }\n query: {boolean: {mustNot: [\n {in: {field: \"type\", stringValues: [\"base:folder\", \"base:shortcut\"]}}\n {like: {field: \"type\", value: \"media:*\"}}\n {like: {field: \"_path\", value: \"*/_*\"}}\n ]}}\n ) {\n _name\n _path\n site {_name}\n }\n }\n}";
41
+ export declare enum XP_REQUEST_TYPE {
42
+ COMPONENT = "component",
43
+ TYPE = "type",
44
+ PAGE = "page"
45
+ }
46
+ export declare enum RENDER_MODE {
47
+ INLINE = "inline",
48
+ EDIT = "edit",
49
+ PREVIEW = "preview",
50
+ LIVE = "live",
51
+ ADMIN = "admin",
52
+ NEXT = "next"
53
+ }
54
+ export declare enum XP_COMPONENT_TYPE {
55
+ PART = "part",
56
+ LAYOUT = "layout",
57
+ TEXT = "text",
58
+ FRAGMENT = "fragment",
59
+ PAGE = "page"
60
+ }
61
+ export interface ServerSideParams extends ParsedUrlQuery {
62
+ contentPath?: string[];
63
+ mode?: string;
64
+ }
65
+ export interface PreviewParams {
66
+ contentPath: string[];
67
+ headers: Record<string, string>;
68
+ params: Record<string, string>;
69
+ }
70
+ export type Context = GetServerSidePropsContext<ServerSideParams, PreviewParams>;
71
+ export type LocaleProjectConfig = {
72
+ project: string;
73
+ site: string;
74
+ locale: string;
75
+ };
76
+ export type LocaleProjectConfigs = {
77
+ default: LocaleProjectConfig;
78
+ [locale: string]: LocaleProjectConfig;
79
+ };
80
+ export interface MinimalContext {
81
+ req?: {
82
+ headers: IncomingHttpHeaders;
83
+ };
84
+ locale?: string;
85
+ defaultLocale?: string;
86
+ locales?: string[];
87
+ }
88
+ export interface ContentPathItem {
89
+ params: {
90
+ contentPath: string[];
91
+ };
92
+ locale?: string;
93
+ }
94
+ export declare const getRenderMode: (context?: MinimalContext) => RENDER_MODE;
95
+ export declare function normalizeLocale(locale: string): string | undefined;
96
+ export declare function getLocaleProjectConfig(context?: MinimalContext): LocaleProjectConfig;
97
+ export declare function getLocaleProjectConfigById(projectId?: string, useDefault?: boolean): LocaleProjectConfig;
98
+ export declare function getLocaleProjectConfigs(): LocaleProjectConfigs;
99
+ export declare function fixDoubleSlashes(str: string): string;
100
+ export declare function getContentApiUrl(context?: MinimalContext): string;
101
+ export declare function addJsessionHeaders(headers?: Object, context?: MinimalContext): void;
102
+ export declare function addLocaleHeaders(headers?: Object, context?: Context): void;
103
+ export declare const getXpBaseUrl: (context?: MinimalContext) => string;
104
+ export declare const commonChars: (s1?: string, s2?: string, wordSeparators?: string) => string;
105
+ export declare const sanitizeGraphqlName: (text: string) => string;
106
+ declare const adapterConstants: {
107
+ IS_DEV_MODE: boolean;
108
+ APP_NAME: string;
109
+ APP_NAME_UNDERSCORED: string;
110
+ APP_NAME_DASHED: string;
111
+ PORTAL_COMPONENT_ATTRIBUTE: string;
112
+ PORTAL_REGION_ATTRIBUTE: string;
113
+ };
114
+ export default adapterConstants;
@@ -1,60 +1,39 @@
1
- /** Import config values from .env, .env.development and .env.production */
2
- import {GetServerSidePropsContext} from 'next';
3
- import {ParsedUrlQuery} from 'node:querystring';
4
- import {IncomingHttpHeaders} from 'http';
5
-
6
1
  const mode = process.env.MODE || process.env.NEXT_PUBLIC_MODE;
7
2
  export const IS_DEV_MODE = (mode === 'development');
8
-
9
3
  export const PURGE_CACHE_URL = '/_/enonic/cache/purge';
10
-
11
- export enum ENV_VARS {
12
- PROJECTS = 'ENONIC_PROJECTS',
13
- API = 'ENONIC_API',
14
- API_TOKEN = 'ENONIC_API_TOKEN',
15
- }
16
-
4
+ export var ENV_VARS;
5
+ (function (ENV_VARS) {
6
+ ENV_VARS["PROJECTS"] = "ENONIC_PROJECTS";
7
+ ENV_VARS["API"] = "ENONIC_API";
8
+ ENV_VARS["API_TOKEN"] = "ENONIC_API_TOKEN";
9
+ })(ENV_VARS || (ENV_VARS = {}));
17
10
  /** URL to the guillotine API */
18
11
  const API_URL = (process.env.ENONIC_API || process.env.NEXT_PUBLIC_ENONIC_API);
19
-
20
12
  /** Locales and Enonic XP projects correspondence list */
21
13
  const PROJECTS = (process.env.ENONIC_PROJECTS || process.env.NEXT_PUBLIC_ENONIC_PROJECTS);
22
-
23
14
  /** Optional utility value - defining in one place the name of the target app (the app that defines the content types, the app name is therefore part of the content type strings used both in typeselector and in query introspections) */
24
15
  export const APP_NAME = (process.env.ENONIC_APP_NAME || process.env.NEXT_PUBLIC_ENONIC_APP_NAME);
25
-
26
16
  /** Optional utility value - derived from APP_NAME, only with underscores instead of dots */
27
17
  export const APP_NAME_UNDERSCORED = (APP_NAME || '').replace(/\./g, '_');
28
-
29
18
  /** Optional utility value - derived from APP_NAME, only with dashes instead of dots */
30
19
  export const APP_NAME_DASHED = (APP_NAME || '').replace(/\./g, '-');
31
-
32
20
  const PROJECT_CONFIG_REGEXP = new RegExp('^(?:([\\w-]+):)?([^\\/\\s]+)(\\/[\\w-.]+)?$', 'i');
33
-
34
-
35
21
  // //////////////////////////////////////////////////////////////////////// Hardcode-able constants
36
-
37
22
  // URI parameter marking that a request is for a preview for CS. MUST MATCH THE VALUE OF 'FROM_XP_PARAM' on XP side.
38
23
  export const XP_BASE_URL_HEADER = 'xpbaseurl';
39
24
  export const RENDER_MODE_HEADER = 'content-studio-mode';
40
25
  export const PROJECT_ID_HEADER = 'content-studio-project';
41
26
  export const JSESSIONID_HEADER = 'jsessionid';
42
-
43
27
  export const PORTAL_COMPONENT_ATTRIBUTE = 'data-portal-component-type';
44
28
  export const PORTAL_REGION_ATTRIBUTE = 'data-portal-region';
45
-
46
29
  export const FRAGMENT_CONTENTTYPE_NAME = 'portal:fragment';
47
30
  export const FRAGMENT_DEFAULT_REGION_NAME = 'fragment';
48
-
49
31
  export const PAGE_TEMPLATE_CONTENTTYPE_NAME = 'portal:page-template';
50
32
  export const PAGE_TEMPLATE_FOLDER = 'portal:template-folder';
51
-
52
33
  export const SITE_CONTENTTYPE_NAME = 'portal:site';
53
-
54
34
  export const LOCALE_HEADER = 'locale';
55
35
  export const LOCALES_HEADER = 'locales';
56
36
  export const DEFAULT_LOCALE_HEADER = 'default-locale';
57
-
58
37
  /** excluded contents:
59
38
  * - folder
60
39
  * - shortcuts (redirect can't be used in prerender)
@@ -81,93 +60,49 @@ export const GET_STATIC_PATHS_QUERY = `query ($count: Int) {
81
60
  }
82
61
  }
83
62
  }`;
84
-
85
-
86
63
  // ------------------------------- Exports and auxillary functions derived from values above ------------------------------------
87
-
88
- export enum XP_REQUEST_TYPE {
89
- COMPONENT = 'component',
90
- TYPE = 'type',
91
- PAGE = 'page',
92
- }
93
-
94
- export enum RENDER_MODE {
95
- INLINE = 'inline',
96
- EDIT = 'edit',
97
- PREVIEW = 'preview',
98
- LIVE = 'live',
99
- ADMIN = 'admin',
100
- NEXT = 'next' // Fallback: not using XP proxy but rendering directly with next.js
101
- }
102
-
64
+ export var XP_REQUEST_TYPE;
65
+ (function (XP_REQUEST_TYPE) {
66
+ XP_REQUEST_TYPE["COMPONENT"] = "component";
67
+ XP_REQUEST_TYPE["TYPE"] = "type";
68
+ XP_REQUEST_TYPE["PAGE"] = "page";
69
+ })(XP_REQUEST_TYPE || (XP_REQUEST_TYPE = {}));
70
+ export var RENDER_MODE;
71
+ (function (RENDER_MODE) {
72
+ RENDER_MODE["INLINE"] = "inline";
73
+ RENDER_MODE["EDIT"] = "edit";
74
+ RENDER_MODE["PREVIEW"] = "preview";
75
+ RENDER_MODE["LIVE"] = "live";
76
+ RENDER_MODE["ADMIN"] = "admin";
77
+ RENDER_MODE["NEXT"] = "next"; // Fallback: not using XP proxy but rendering directly with next.js
78
+ })(RENDER_MODE || (RENDER_MODE = {}));
103
79
  // TODO: Use these instead of hardcoded strings everywhere
104
- export enum XP_COMPONENT_TYPE {
105
- PART = 'part',
106
- LAYOUT = 'layout',
107
- TEXT = 'text',
108
- FRAGMENT = 'fragment',
109
- PAGE = 'page',
110
- }
111
-
112
- export interface ServerSideParams
113
- extends ParsedUrlQuery {
114
- // String array catching a sub-path assumed to match the site-relative path of an XP content.
115
- contentPath?: string[];
116
- mode?: string;
117
- }
118
-
119
- export interface PreviewParams {
120
- contentPath: string[];
121
- headers: Record<string, string>;
122
- params: Record<string, string>;
123
- }
124
-
125
- export type Context = GetServerSidePropsContext<ServerSideParams, PreviewParams>;
126
-
127
- export type LocaleProjectConfig = {
128
- project: string;
129
- site: string;
130
- locale: string;
131
- };
132
-
133
- export type LocaleProjectConfigs = {
134
- default: LocaleProjectConfig;
135
- [locale: string]: LocaleProjectConfig;
136
- };
137
-
138
- export interface MinimalContext {
139
- req?: {
140
- headers: IncomingHttpHeaders;
141
- }
142
- locale?: string;
143
- defaultLocale?: string;
144
- locales?: string[];
145
- }
146
-
147
- export interface ContentPathItem {
148
- params: { contentPath: string[] },
149
- locale?: string,
150
- }
151
-
152
- export const getRenderMode = (context?: MinimalContext): RENDER_MODE => {
153
- const value = (context?.req?.headers || {})[RENDER_MODE_HEADER] as string | undefined;
154
- const enumValue = RENDER_MODE[<keyof typeof RENDER_MODE>value?.toUpperCase()];
80
+ export var XP_COMPONENT_TYPE;
81
+ (function (XP_COMPONENT_TYPE) {
82
+ XP_COMPONENT_TYPE["PART"] = "part";
83
+ XP_COMPONENT_TYPE["LAYOUT"] = "layout";
84
+ XP_COMPONENT_TYPE["TEXT"] = "text";
85
+ XP_COMPONENT_TYPE["FRAGMENT"] = "fragment";
86
+ XP_COMPONENT_TYPE["PAGE"] = "page";
87
+ })(XP_COMPONENT_TYPE || (XP_COMPONENT_TYPE = {}));
88
+ export const getRenderMode = (context) => {
89
+ var _a;
90
+ const value = (((_a = context === null || context === void 0 ? void 0 : context.req) === null || _a === void 0 ? void 0 : _a.headers) || {})[RENDER_MODE_HEADER];
91
+ const enumValue = RENDER_MODE[value === null || value === void 0 ? void 0 : value.toUpperCase()];
155
92
  return enumValue || RENDER_MODE[process.env.RENDER_MODE] || RENDER_MODE.NEXT;
156
93
  };
157
-
158
- export function normalizeLocale(locale: string): string | undefined {
94
+ export function normalizeLocale(locale) {
159
95
  return locale !== 'default' ? locale : undefined;
160
96
  }
161
-
162
- export function getLocaleProjectConfig(context?: MinimalContext): LocaleProjectConfig {
163
- const projectId = (context?.req?.headers || {})[PROJECT_ID_HEADER] as string | undefined;
97
+ export function getLocaleProjectConfig(context) {
98
+ var _a;
99
+ const projectId = (((_a = context === null || context === void 0 ? void 0 : context.req) === null || _a === void 0 ? void 0 : _a.headers) || {})[PROJECT_ID_HEADER];
164
100
  if (projectId) {
165
101
  return getLocaleProjectConfigById(projectId);
166
102
  }
167
-
168
103
  const projectsConfig = getLocaleProjectConfigs();
169
- const locale = context?.locale || context?.defaultLocale;
170
- let config: LocaleProjectConfig = projectsConfig[locale];
104
+ const locale = (context === null || context === void 0 ? void 0 : context.locale) || (context === null || context === void 0 ? void 0 : context.defaultLocale);
105
+ let config = projectsConfig[locale];
171
106
  if (!config) {
172
107
  config = projectsConfig.default;
173
108
  }
@@ -175,32 +110,28 @@ export function getLocaleProjectConfig(context?: MinimalContext): LocaleProjectC
175
110
  throw new Error(`No config for locale "${locale}" found in "${ENV_VARS.PROJECTS}" environmental variable.
176
111
  Format: <default-repository-name>/<site-path>,<language>:<repository-name>/<site-path>,...`);
177
112
  }
178
-
179
113
  return config;
180
114
  }
181
-
182
- export function getLocaleProjectConfigById(projectId?: string, useDefault = true): LocaleProjectConfig {
183
- const projects: LocaleProjectConfigs = getLocaleProjectConfigs();
115
+ export function getLocaleProjectConfigById(projectId, useDefault = true) {
116
+ const projects = getLocaleProjectConfigs();
184
117
  if (!projectId) {
185
118
  return useDefault ? projects.default : undefined;
186
119
  }
187
-
188
120
  const match = Object.values(projects).find(p => {
189
- return p?.project?.toLowerCase() === projectId.toLowerCase();
121
+ var _a;
122
+ return ((_a = p === null || p === void 0 ? void 0 : p.project) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === projectId.toLowerCase();
190
123
  });
191
-
192
124
  return match || (useDefault ? projects.default : undefined);
193
125
  }
194
-
195
- export function getLocaleProjectConfigs(): LocaleProjectConfigs {
126
+ export function getLocaleProjectConfigs() {
196
127
  const str = PROJECTS;
197
128
  const envVarName = ENV_VARS.PROJECTS;
198
- if (!str?.length) {
129
+ if (!(str === null || str === void 0 ? void 0 : str.length)) {
199
130
  throw Error(`"${envVarName}" environmental variable is required.`);
200
131
  }
201
- const result: LocaleProjectConfigs = str.split(',').reduce((config, prjStr) => {
202
- const matches: RegExpExecArray = PROJECT_CONFIG_REGEXP.exec(prjStr?.trim());
203
- if (!matches?.length) {
132
+ const result = str.split(',').reduce((config, prjStr) => {
133
+ const matches = PROJECT_CONFIG_REGEXP.exec(prjStr === null || prjStr === void 0 ? void 0 : prjStr.trim());
134
+ if (!(matches === null || matches === void 0 ? void 0 : matches.length)) {
204
135
  return config;
205
136
  }
206
137
  const [full, lang = 'default', project, site] = matches;
@@ -210,7 +141,8 @@ export function getLocaleProjectConfigs(): LocaleProjectConfigs {
210
141
  site,
211
142
  locale: lang,
212
143
  };
213
- } else {
144
+ }
145
+ else {
214
146
  throw Error(`Wrong configuration in "${envVarName}": ${prjStr}.
215
147
  Format: <default-repository-name>/<site-path>,<language>:<repository-name>/<site-path>,...`);
216
148
  }
@@ -228,49 +160,42 @@ export function getLocaleProjectConfigs(): LocaleProjectConfigs {
228
160
  }
229
161
  return result;
230
162
  }
231
-
232
- export function fixDoubleSlashes(str: string) {
163
+ export function fixDoubleSlashes(str) {
233
164
  return str.replace(/(^|[^:/])\/{2,}/g, '$1/');
234
165
  }
235
-
236
- export function getContentApiUrl(context?: MinimalContext): string {
166
+ export function getContentApiUrl(context) {
237
167
  const project = getLocaleProjectConfig(context).project;
238
168
  const branch = getRenderMode(context) === RENDER_MODE.NEXT ? 'master' : 'draft';
239
-
240
169
  return fixDoubleSlashes(`${API_URL}/${project}/${branch}`);
241
170
  }
242
-
243
- export function addJsessionHeaders(headers: Object = {}, context?: MinimalContext): void {
244
- const jsessionid = context?.req?.headers[JSESSIONID_HEADER];
171
+ export function addJsessionHeaders(headers = {}, context) {
172
+ var _a;
173
+ const jsessionid = (_a = context === null || context === void 0 ? void 0 : context.req) === null || _a === void 0 ? void 0 : _a.headers[JSESSIONID_HEADER];
245
174
  if (jsessionid) {
246
175
  headers['Cookie'] = `${JSESSIONID_HEADER}=${jsessionid}`;
247
176
  }
248
177
  }
249
-
250
- export function addLocaleHeaders(headers: Object = {}, context?: Context): void {
251
- const locale = context?.locale;
178
+ export function addLocaleHeaders(headers = {}, context) {
179
+ const locale = context === null || context === void 0 ? void 0 : context.locale;
252
180
  if (locale) {
253
181
  headers[LOCALE_HEADER] = locale;
254
182
  }
255
- const locales = context?.locales;
183
+ const locales = context === null || context === void 0 ? void 0 : context.locales;
256
184
  if (locales) {
257
185
  headers[LOCALES_HEADER] = JSON.stringify(locales);
258
186
  }
259
- const defaultLocale = context?.defaultLocale;
187
+ const defaultLocale = context === null || context === void 0 ? void 0 : context.defaultLocale;
260
188
  if (defaultLocale) {
261
189
  headers[DEFAULT_LOCALE_HEADER] = defaultLocale;
262
190
  }
263
191
  }
264
-
265
- export const getXpBaseUrl = (context?: MinimalContext): string => {
266
- const header = ((context?.req?.headers || {})[XP_BASE_URL_HEADER] || '') as string;
267
-
192
+ export const getXpBaseUrl = (context) => {
193
+ var _a;
194
+ const header = ((((_a = context === null || context === void 0 ? void 0 : context.req) === null || _a === void 0 ? void 0 : _a.headers) || {})[XP_BASE_URL_HEADER] || '');
268
195
  // TODO: workaround for XP pattern controller mapping not picked up in edit mode
269
196
  return (header || '/').replace(/\/edit\//, '/inline/');
270
197
  };
271
-
272
-
273
- export const commonChars = (s1?: string, s2?: string, wordSeparators?: string) => {
198
+ export const commonChars = (s1, s2, wordSeparators) => {
274
199
  let result = '';
275
200
  if (!s1 || s1.length === 0 || !s2 || s2.length === 0) {
276
201
  return result;
@@ -279,26 +204,26 @@ export const commonChars = (s1?: string, s2?: string, wordSeparators?: string) =
279
204
  let lastCommonIndex = -1;
280
205
  for (let i = 0; i < s1.length; i++) {
281
206
  const s1El = s1[i];
282
- if (wordSeparators?.indexOf(s1El) >= 0) {
207
+ if ((wordSeparators === null || wordSeparators === void 0 ? void 0 : wordSeparators.indexOf(s1El)) >= 0) {
283
208
  lastSeparatorIndex = i;
284
209
  }
285
210
  if (s2[i] === s1El) {
286
211
  lastCommonIndex = i;
287
- } else {
212
+ }
213
+ else {
288
214
  break;
289
215
  }
290
216
  }
291
-
292
217
  if (lastSeparatorIndex > 0 || lastCommonIndex === lastSeparatorIndex) {
293
218
  result = s1.substring(0, lastSeparatorIndex);
294
- } else if (lastCommonIndex > -1) {
219
+ }
220
+ else if (lastCommonIndex > -1) {
295
221
  result = s1.substring(0, lastCommonIndex + 1);
296
222
  }
297
-
298
223
  return result;
299
224
  };
300
225
  // sanitizes text according to graphql naming spec http://spec.graphql.org/October2021/#sec-Names
301
- export const sanitizeGraphqlName = (text: string) => {
226
+ export const sanitizeGraphqlName = (text) => {
302
227
  if (!text || text.trim().length === 0) {
303
228
  return '';
304
229
  }
@@ -308,9 +233,7 @@ export const sanitizeGraphqlName = (text: string) => {
308
233
  }
309
234
  return result;
310
235
  };
311
-
312
236
  // ---------------------------------------------------------------------------------------------------------------- Export
313
-
314
237
  const adapterConstants = {
315
238
  IS_DEV_MODE,
316
239
  APP_NAME,
@@ -319,7 +242,6 @@ const adapterConstants = {
319
242
  PORTAL_COMPONENT_ATTRIBUTE,
320
243
  PORTAL_REGION_ATTRIBUTE,
321
244
  };
322
-
323
245
  // Verify required values
324
246
  const NOT_REQUIRED = ['IS_DEV_MODE'];
325
247
  Object.keys(adapterConstants).forEach(key => {
@@ -327,5 +249,4 @@ Object.keys(adapterConstants).forEach(key => {
327
249
  throw Error(`constants.ts: Config value '${key}' is missing (from .env?)`);
328
250
  }
329
251
  });
330
-
331
252
  export default adapterConstants;
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import { MetaData, PageComponent } from '../guillotine/getMetaData';
3
+ export type BaseComponentProps = {
4
+ component: PageComponent;
5
+ meta: MetaData;
6
+ common?: any;
7
+ };
8
+ declare const BaseComponent: ({ component, meta, common }: BaseComponentProps) => JSX.Element;
9
+ export default BaseComponent;
10
+ export declare const MissingComponent: ({ descriptor, type }: {
11
+ descriptor?: string;
12
+ type: string;
13
+ }) => React.JSX.Element;
14
+ export declare function shouldShowMissingView(meta: MetaData): boolean;
15
+ export declare const ErrorComponent: ({ type, descriptor, reason }: {
16
+ type?: string;
17
+ descriptor?: string;
18
+ reason: string;
19
+ }) => React.JSX.Element;
20
+ export declare function shouldShowErrorView(meta: MetaData): boolean;
21
+ export declare const PlaceholderComponent: ({ type, descriptor }: {
22
+ type?: string;
23
+ descriptor?: string;
24
+ }) => React.JSX.Element;
25
+ export declare function shouldShowPlaceholderView(meta: MetaData): boolean;