@enonic/nextjs-adapter 2.0.0 → 3.0.0-B2
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/baseMappings.js +3 -2
- package/baseMappings.js.map +1 -0
- package/client.d.ts +1 -0
- package/client.js +3 -0
- package/client.js.map +1 -0
- package/common/ComponentRegistry.d.ts +34 -0
- package/{ComponentRegistry.js → common/ComponentRegistry.js} +26 -26
- package/common/ComponentRegistry.js.map +1 -0
- package/{UrlProcessor.d.ts → common/UrlProcessor.d.ts} +5 -4
- package/{UrlProcessor.js → common/UrlProcessor.js} +40 -17
- package/common/UrlProcessor.js.map +1 -0
- package/common/constants.d.ts +50 -0
- package/common/constants.js +79 -0
- package/common/constants.js.map +1 -0
- package/common/env.d.ts +11 -0
- package/common/env.js +28 -0
- package/common/env.js.map +1 -0
- package/guillotine/applyProcessors.d.ts +2 -0
- package/guillotine/applyProcessors.js +33 -0
- package/guillotine/applyProcessors.js.map +1 -0
- package/guillotine/buildComponentTree.d.ts +2 -0
- package/guillotine/buildComponentTree.js +45 -0
- package/guillotine/buildComponentTree.js.map +1 -0
- package/guillotine/buildErrorResponse.d.ts +3 -0
- package/guillotine/buildErrorResponse.js +26 -0
- package/guillotine/buildErrorResponse.js.map +1 -0
- package/guillotine/buildPage.d.ts +2 -0
- package/guillotine/buildPage.js +10 -0
- package/guillotine/buildPage.js.map +1 -0
- package/guillotine/collectComponentDescriptors.d.ts +6 -0
- package/guillotine/collectComponentDescriptors.js +43 -0
- package/guillotine/collectComponentDescriptors.js.map +1 -0
- package/guillotine/combineMultipleQueries.d.ts +2 -0
- package/guillotine/combineMultipleQueries.js +58 -0
- package/guillotine/combineMultipleQueries.js.map +1 -0
- package/guillotine/createMetaData.d.ts +17 -0
- package/guillotine/createMetaData.js +44 -0
- package/guillotine/createMetaData.js.map +1 -0
- package/guillotine/fetchContent.d.ts +1 -41
- package/guillotine/fetchContent.js +193 -800
- package/guillotine/fetchContent.js.map +1 -0
- package/guillotine/fetchContentData.d.ts +2 -0
- package/guillotine/fetchContentData.js +27 -0
- package/guillotine/fetchContentData.js.map +1 -0
- package/guillotine/fetchContentPathsForAllLocales.d.ts +2 -0
- package/guillotine/fetchContentPathsForAllLocales.js +21 -0
- package/guillotine/fetchContentPathsForAllLocales.js.map +1 -0
- package/guillotine/fetchContentPathsForLocale.d.ts +2 -0
- package/guillotine/fetchContentPathsForLocale.js +40 -0
- package/guillotine/fetchContentPathsForLocale.js.map +1 -0
- package/guillotine/fetchFromApi.d.ts +3 -0
- package/guillotine/fetchFromApi.js +65 -0
- package/guillotine/fetchFromApi.js.map +1 -0
- package/guillotine/fetchGuillotine.d.ts +3 -0
- package/guillotine/fetchGuillotine.js +55 -0
- package/guillotine/fetchGuillotine.js.map +1 -0
- package/guillotine/fetchMetaData.d.ts +2 -0
- package/guillotine/fetchMetaData.js +30 -0
- package/guillotine/fetchMetaData.js.map +1 -0
- package/guillotine/getCleanContentPathArrayOrThrow400.d.ts +2 -0
- package/guillotine/getCleanContentPathArrayOrThrow400.js +20 -0
- package/guillotine/getCleanContentPathArrayOrThrow400.js.map +1 -0
- package/guillotine/getComponentConfig.d.ts +2 -0
- package/guillotine/getComponentConfig.js +5 -0
- package/guillotine/getComponentConfig.js.map +1 -0
- package/guillotine/getContentAndComponentPaths.d.ts +1 -0
- package/guillotine/getContentAndComponentPaths.js +12 -0
- package/guillotine/getContentAndComponentPaths.js.map +1 -0
- package/guillotine/getMetaData.d.ts +0 -92
- package/guillotine/getMetaData.js +47 -109
- package/guillotine/getMetaData.js.map +1 -0
- package/guillotine/getParentRegion.d.ts +2 -0
- package/guillotine/getParentRegion.js +40 -0
- package/guillotine/getParentRegion.js.map +1 -0
- package/guillotine/getQueryAndVariables.d.ts +2 -0
- package/guillotine/getQueryAndVariables.js +32 -0
- package/guillotine/getQueryAndVariables.js.map +1 -0
- package/guillotine/metadata/configQuery.d.ts +2 -0
- package/guillotine/metadata/configQuery.js +36 -0
- package/guillotine/metadata/configQuery.js.map +1 -0
- package/guillotine/metadata/richTextQuery.d.ts +1 -0
- package/guillotine/metadata/richTextQuery.js +32 -0
- package/guillotine/metadata/richTextQuery.js.map +1 -0
- package/guillotine/parseComponentPath.d.ts +2 -0
- package/guillotine/parseComponentPath.js +22 -0
- package/guillotine/parseComponentPath.js.map +1 -0
- package/guillotine/prefixLayoutPath.d.ts +1 -0
- package/guillotine/prefixLayoutPath.js +13 -0
- package/guillotine/prefixLayoutPath.js.map +1 -0
- package/guillotine/processComponentConfig.d.ts +2 -0
- package/guillotine/processComponentConfig.js +30 -0
- package/guillotine/processComponentConfig.js.map +1 -0
- package/guillotine/restrictComponentsToPath.d.ts +2 -0
- package/guillotine/restrictComponentsToPath.js +35 -0
- package/guillotine/restrictComponentsToPath.js.map +1 -0
- package/guillotine/validateData.d.ts +2 -0
- package/guillotine/validateData.js +7 -0
- package/guillotine/validateData.js.map +1 -0
- package/guillotine/validateNotFound.d.ts +2 -0
- package/guillotine/validateNotFound.js +16 -0
- package/guillotine/validateNotFound.js.map +1 -0
- package/guillotine/validateShortcut.d.ts +2 -0
- package/guillotine/validateShortcut.js +29 -0
- package/guillotine/validateShortcut.js.map +1 -0
- package/i18n/LocaleContext.d.ts +7 -0
- package/i18n/LocaleContext.jsx +46 -0
- package/i18n/LocaleContext.jsx.map +1 -0
- package/i18n/i18n.d.ts +11 -0
- package/i18n/i18n.js +57 -0
- package/i18n/i18n.js.map +1 -0
- package/index.d.ts +18 -5
- package/index.js +18 -5
- package/index.js.map +1 -0
- package/package.json +67 -16
- package/query/Shortcut.js +1 -0
- package/query/Shortcut.js.map +1 -0
- package/types/component.d.ts +114 -0
- package/types/component.js +2 -0
- package/types/component.js.map +1 -0
- package/types/componentProps.d.ts +104 -0
- package/types/componentProps.js +2 -0
- package/types/componentProps.js.map +1 -0
- package/types/guillotine.d.ts +342 -0
- package/types/guillotine.js +2 -0
- package/types/guillotine.js.map +1 -0
- package/types/i18n.d.ts +7 -0
- package/types/i18n.js +2 -0
- package/types/i18n.js.map +1 -0
- package/types/index.d.ts +45 -0
- package/types/index.js +3 -0
- package/types/index.js.map +1 -0
- package/types/next.d.ts +6 -0
- package/types/next.js +2 -0
- package/types/next.js.map +1 -0
- package/types/util.d.ts +3 -0
- package/types/util.js +3 -0
- package/types/util.js.map +1 -0
- package/utils/addLineNumbers.d.ts +1 -0
- package/utils/addLineNumbers.js +4 -0
- package/utils/addLineNumbers.js.map +1 -0
- package/utils/buildGuillotineRequestHeaders.d.ts +7 -0
- package/utils/buildGuillotineRequestHeaders.js +16 -0
- package/utils/buildGuillotineRequestHeaders.js.map +1 -0
- package/utils/commonChars.d.ts +1 -0
- package/utils/commonChars.js +17 -0
- package/utils/commonChars.js.map +1 -0
- package/utils/fixDoubleSlashes.d.ts +1 -0
- package/utils/fixDoubleSlashes.js +4 -0
- package/utils/fixDoubleSlashes.js.map +1 -0
- package/utils/getContentApiUrl.d.ts +2 -0
- package/utils/getContentApiUrl.js +15 -0
- package/utils/getContentApiUrl.js.map +1 -0
- package/utils/getProjectLocaleConfig.d.ts +2 -0
- package/utils/getProjectLocaleConfig.js +19 -0
- package/utils/getProjectLocaleConfig.js.map +1 -0
- package/utils/getProjectLocaleConfigById.d.ts +2 -0
- package/utils/getProjectLocaleConfigById.js +16 -0
- package/utils/getProjectLocaleConfigById.js.map +1 -0
- package/utils/getProjectLocaleConfigByLocale.d.ts +2 -0
- package/utils/getProjectLocaleConfigByLocale.js +13 -0
- package/utils/getProjectLocaleConfigByLocale.js.map +1 -0
- package/utils/getProjectLocaleConfigs.d.ts +2 -0
- package/utils/getProjectLocaleConfigs.js +30 -0
- package/utils/getProjectLocaleConfigs.js.map +1 -0
- package/utils/getProjectLocales.d.ts +1 -0
- package/utils/getProjectLocales.js +5 -0
- package/utils/getProjectLocales.js.map +1 -0
- package/utils/getRenderMode.d.ts +3 -0
- package/utils/getRenderMode.js +8 -0
- package/utils/getRenderMode.js.map +1 -0
- package/utils/getRequestLocaleInfo.d.ts +6 -0
- package/utils/getRequestLocaleInfo.js +26 -0
- package/utils/getRequestLocaleInfo.js.map +1 -0
- package/utils/getXpBaseUrl.d.ts +2 -0
- package/utils/getXpBaseUrl.js +8 -0
- package/utils/getXpBaseUrl.js.map +1 -0
- package/utils/indent.d.ts +1 -0
- package/utils/indent.js +5 -0
- package/utils/indent.js.map +1 -0
- package/utils/sanitizeGraphqlName.d.ts +1 -0
- package/utils/sanitizeGraphqlName.js +12 -0
- package/utils/sanitizeGraphqlName.js.map +1 -0
- package/views/BaseComponent.d.ts +5 -10
- package/views/BaseComponent.jsx +17 -6
- package/views/BaseComponent.jsx.map +1 -0
- package/views/BaseContent.d.ts +3 -3
- package/views/BaseContent.jsx +2 -5
- package/views/BaseContent.jsx.map +1 -0
- package/views/BaseLayout.d.ts +3 -16
- package/views/BaseLayout.jsx +3 -3
- package/views/BaseLayout.jsx.map +1 -0
- package/views/BaseMacro.d.ts +3 -13
- package/views/BaseMacro.jsx +4 -3
- package/views/BaseMacro.jsx.map +1 -0
- package/views/BasePage.d.ts +3 -18
- package/views/BasePage.jsx +3 -3
- package/views/BasePage.jsx.map +1 -0
- package/views/BasePart.d.ts +3 -18
- package/views/BasePart.jsx +3 -3
- package/views/BasePart.jsx.map +1 -0
- package/views/Empty.d.ts +2 -2
- package/views/Empty.jsx +2 -1
- package/views/Empty.jsx.map +1 -0
- package/views/Fragment.d.ts +3 -9
- package/views/Fragment.jsx +2 -2
- package/views/Fragment.jsx.map +1 -0
- package/views/MainView.d.ts +3 -3
- package/views/MainView.jsx +2 -2
- package/views/MainView.jsx.map +1 -0
- package/views/PropsView.d.ts +3 -0
- package/views/PropsView.jsx +21 -0
- package/views/PropsView.jsx.map +1 -0
- package/views/Region.d.ts +4 -17
- package/views/Region.jsx +2 -2
- package/views/Region.jsx.map +1 -0
- package/views/RichTextView.d.ts +3 -13
- package/views/RichTextView.jsx +6 -3
- package/views/RichTextView.jsx.map +1 -0
- package/views/SingleComponent.d.ts +3 -3
- package/views/SingleComponent.jsx +1 -2
- package/views/SingleComponent.jsx.map +1 -0
- package/views/StaticContent.d.ts +2 -6
- package/views/StaticContent.jsx +1 -0
- package/views/StaticContent.jsx.map +1 -0
- package/views/Text.d.ts +5 -5
- package/views/Text.jsx +1 -1
- package/views/Text.jsx.map +1 -0
- package/views/getClientHydratedHtml.d.ts +2 -0
- package/views/getClientHydratedHtml.jsx +9 -0
- package/views/getClientHydratedHtml.jsx.map +1 -0
- package/views/macros/DefaultMacro.d.ts +1 -1
- package/views/macros/DefaultMacro.jsx +1 -0
- package/views/macros/DefaultMacro.jsx.map +1 -0
- package/views/macros/DisableMacro.d.ts +1 -1
- package/views/macros/DisableMacro.jsx +1 -0
- package/views/macros/DisableMacro.jsx.map +1 -0
- package/ComponentRegistry.d.ts +0 -64
- package/server/ClearableFileCache.d.ts +0 -31
- package/server/ClearableFileCache.js +0 -472
- package/server/cache.d.ts +0 -2
- package/server/cache.js +0 -129
- package/server/index.d.ts +0 -5
- package/server/index.js +0 -132
- package/utils.d.ts +0 -114
- package/utils.js +0 -241
package/server/index.js
DELETED
|
@@ -1,132 +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 __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
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
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) => 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;
|
package/utils.js
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
const mode = process.env.MODE || process.env.NEXT_PUBLIC_MODE;
|
|
2
|
-
export const IS_DEV_MODE = (mode === 'development');
|
|
3
|
-
export const PURGE_CACHE_URL = '/_/enonic/cache/purge';
|
|
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 = {}));
|
|
10
|
-
/** URL to the guillotine API */
|
|
11
|
-
const API_URL = (process.env.ENONIC_API || process.env.NEXT_PUBLIC_ENONIC_API);
|
|
12
|
-
/** Locales and Enonic XP projects correspondence list */
|
|
13
|
-
const PROJECTS = (process.env.ENONIC_PROJECTS || process.env.NEXT_PUBLIC_ENONIC_PROJECTS);
|
|
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 const APP_NAME = (process.env.ENONIC_APP_NAME || process.env.NEXT_PUBLIC_ENONIC_APP_NAME);
|
|
16
|
-
/** Optional utility value - derived from APP_NAME, only with underscores instead of dots */
|
|
17
|
-
export const APP_NAME_UNDERSCORED = (APP_NAME || '').replace(/\./g, '_');
|
|
18
|
-
/** Optional utility value - derived from APP_NAME, only with dashes instead of dots */
|
|
19
|
-
export const APP_NAME_DASHED = (APP_NAME || '').replace(/\./g, '-');
|
|
20
|
-
const PROJECT_CONFIG_REGEXP = new RegExp('^(?:([\\w-]+):)?([^\\/\\s]+)(\\/[\\w-.]+)?$', 'i');
|
|
21
|
-
// //////////////////////////////////////////////////////////////////////// Hardcode-able constants
|
|
22
|
-
// URI parameter marking that a request is for a preview for CS. MUST MATCH THE VALUE OF 'FROM_XP_PARAM' on XP side.
|
|
23
|
-
export const XP_BASE_URL_HEADER = 'xpbaseurl';
|
|
24
|
-
export const RENDER_MODE_HEADER = 'content-studio-mode';
|
|
25
|
-
export const PROJECT_ID_HEADER = 'content-studio-project';
|
|
26
|
-
export const JSESSIONID_HEADER = 'jsessionid';
|
|
27
|
-
export const PORTAL_COMPONENT_ATTRIBUTE = 'data-portal-component-type';
|
|
28
|
-
export const PORTAL_REGION_ATTRIBUTE = 'data-portal-region';
|
|
29
|
-
export const FRAGMENT_CONTENTTYPE_NAME = 'portal:fragment';
|
|
30
|
-
export const FRAGMENT_DEFAULT_REGION_NAME = 'fragment';
|
|
31
|
-
export const PAGE_TEMPLATE_CONTENTTYPE_NAME = 'portal:page-template';
|
|
32
|
-
export const PAGE_TEMPLATE_FOLDER = 'portal:template-folder';
|
|
33
|
-
export const SITE_CONTENTTYPE_NAME = 'portal:site';
|
|
34
|
-
export const LOCALE_HEADER = 'locale';
|
|
35
|
-
export const LOCALES_HEADER = 'locales';
|
|
36
|
-
export const DEFAULT_LOCALE_HEADER = 'default-locale';
|
|
37
|
-
/** excluded contents:
|
|
38
|
-
* - folder
|
|
39
|
-
* - shortcuts (redirect can't be used in prerender)
|
|
40
|
-
* - media
|
|
41
|
-
* - paths with '/_' in them
|
|
42
|
-
*/
|
|
43
|
-
export const GET_STATIC_PATHS_QUERY = `query ($count: Int) {
|
|
44
|
-
guillotine {
|
|
45
|
-
queryDsl(
|
|
46
|
-
first: $count,
|
|
47
|
-
sort: {
|
|
48
|
-
field: "modifiedTime",
|
|
49
|
-
direction: DESC
|
|
50
|
-
}
|
|
51
|
-
query: {boolean: {mustNot: [
|
|
52
|
-
{in: {field: "type", stringValues: ["base:folder", "base:shortcut"]}}
|
|
53
|
-
{like: {field: "type", value: "media:*"}}
|
|
54
|
-
{like: {field: "_path", value: "*/_*"}}
|
|
55
|
-
]}}
|
|
56
|
-
) {
|
|
57
|
-
_name
|
|
58
|
-
_path
|
|
59
|
-
site {_name}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}`;
|
|
63
|
-
// ------------------------------- Exports and auxillary functions derived from values above ------------------------------------
|
|
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 = {}));
|
|
79
|
-
// TODO: Use these instead of hardcoded strings everywhere
|
|
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()];
|
|
92
|
-
return enumValue || RENDER_MODE[process.env.RENDER_MODE] || RENDER_MODE.NEXT;
|
|
93
|
-
};
|
|
94
|
-
export function normalizeLocale(locale) {
|
|
95
|
-
return locale !== 'default' ? locale : undefined;
|
|
96
|
-
}
|
|
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];
|
|
100
|
-
if (projectId) {
|
|
101
|
-
return getLocaleProjectConfigById(projectId);
|
|
102
|
-
}
|
|
103
|
-
const projectsConfig = getLocaleProjectConfigs();
|
|
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];
|
|
106
|
-
if (!config) {
|
|
107
|
-
config = projectsConfig.default;
|
|
108
|
-
}
|
|
109
|
-
if (!config) {
|
|
110
|
-
throw new Error(`No config for locale "${locale}" found in "${ENV_VARS.PROJECTS}" environmental variable.
|
|
111
|
-
Format: <default-repository-name>/<site-path>,<language>:<repository-name>/<site-path>,...`);
|
|
112
|
-
}
|
|
113
|
-
return config;
|
|
114
|
-
}
|
|
115
|
-
export function getLocaleProjectConfigById(projectId, useDefault = true) {
|
|
116
|
-
const projects = getLocaleProjectConfigs();
|
|
117
|
-
if (!projectId) {
|
|
118
|
-
return useDefault ? projects.default : undefined;
|
|
119
|
-
}
|
|
120
|
-
const match = Object.values(projects).find(p => {
|
|
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();
|
|
123
|
-
});
|
|
124
|
-
return match || (useDefault ? projects.default : undefined);
|
|
125
|
-
}
|
|
126
|
-
export function getLocaleProjectConfigs() {
|
|
127
|
-
const str = PROJECTS;
|
|
128
|
-
const envVarName = ENV_VARS.PROJECTS;
|
|
129
|
-
if (!(str === null || str === void 0 ? void 0 : str.length)) {
|
|
130
|
-
throw Error(`"${envVarName}" environmental variable is required.`);
|
|
131
|
-
}
|
|
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)) {
|
|
135
|
-
return config;
|
|
136
|
-
}
|
|
137
|
-
const [full, lang = 'default', project, site] = matches;
|
|
138
|
-
if (project && site) {
|
|
139
|
-
config[lang] = {
|
|
140
|
-
project,
|
|
141
|
-
site,
|
|
142
|
-
locale: lang,
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
throw Error(`Wrong configuration in "${envVarName}": ${prjStr}.
|
|
147
|
-
Format: <default-repository-name>/<site-path>,<language>:<repository-name>/<site-path>,...`);
|
|
148
|
-
}
|
|
149
|
-
return config;
|
|
150
|
-
}, {
|
|
151
|
-
default: {
|
|
152
|
-
project: '',
|
|
153
|
-
site: '',
|
|
154
|
-
locale: '',
|
|
155
|
-
},
|
|
156
|
-
});
|
|
157
|
-
if (!result.default.site || !result.default.project) {
|
|
158
|
-
throw Error(`"${envVarName}" environmental variable should contain default value.
|
|
159
|
-
Format: <default-repository-name>/<site-path>,<language>:<repository-name>/<site-path>,...`);
|
|
160
|
-
}
|
|
161
|
-
return result;
|
|
162
|
-
}
|
|
163
|
-
export function fixDoubleSlashes(str) {
|
|
164
|
-
return str.replace(/(^|[^:/])\/{2,}/g, '$1/');
|
|
165
|
-
}
|
|
166
|
-
export function getContentApiUrl(context) {
|
|
167
|
-
const project = getLocaleProjectConfig(context).project;
|
|
168
|
-
const branch = getRenderMode(context) === RENDER_MODE.NEXT ? 'master' : 'draft';
|
|
169
|
-
return fixDoubleSlashes(`${API_URL}/${project}/${branch}`);
|
|
170
|
-
}
|
|
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];
|
|
174
|
-
if (jsessionid) {
|
|
175
|
-
headers['Cookie'] = `${JSESSIONID_HEADER}=${jsessionid}`;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
export function addLocaleHeaders(headers = {}, context) {
|
|
179
|
-
const locale = context === null || context === void 0 ? void 0 : context.locale;
|
|
180
|
-
if (locale) {
|
|
181
|
-
headers[LOCALE_HEADER] = locale;
|
|
182
|
-
}
|
|
183
|
-
const locales = context === null || context === void 0 ? void 0 : context.locales;
|
|
184
|
-
if (locales) {
|
|
185
|
-
headers[LOCALES_HEADER] = JSON.stringify(locales);
|
|
186
|
-
}
|
|
187
|
-
const defaultLocale = context === null || context === void 0 ? void 0 : context.defaultLocale;
|
|
188
|
-
if (defaultLocale) {
|
|
189
|
-
headers[DEFAULT_LOCALE_HEADER] = defaultLocale;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
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] || '');
|
|
195
|
-
// TODO: workaround for XP pattern controller mapping not picked up in edit mode
|
|
196
|
-
return (header || '/').replace(/\/edit\//, '/inline/');
|
|
197
|
-
};
|
|
198
|
-
export const commonChars = (s1, s2) => {
|
|
199
|
-
let result = '';
|
|
200
|
-
if (!s1 || s1.length === 0 || !s2 || s2.length === 0) {
|
|
201
|
-
return result;
|
|
202
|
-
}
|
|
203
|
-
for (let i = 0; i < s1.length; i++) {
|
|
204
|
-
const s1Element = s1[i];
|
|
205
|
-
if (s2[i] === s1Element) {
|
|
206
|
-
result += s1Element;
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
break;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
return result;
|
|
213
|
-
};
|
|
214
|
-
// sanitizes text according to graphql naming spec http://spec.graphql.org/October2021/#sec-Names
|
|
215
|
-
export const sanitizeGraphqlName = (text) => {
|
|
216
|
-
if (!text || text.trim().length === 0) {
|
|
217
|
-
return '';
|
|
218
|
-
}
|
|
219
|
-
let result = text.replace(/([^0-9A-Za-z])+/g, '_');
|
|
220
|
-
if (result.length > 0 && /[0-9]/.test(result.charAt(0))) {
|
|
221
|
-
result = '_' + result;
|
|
222
|
-
}
|
|
223
|
-
return result;
|
|
224
|
-
};
|
|
225
|
-
// ---------------------------------------------------------------------------------------------------------------- Export
|
|
226
|
-
const adapterConstants = {
|
|
227
|
-
IS_DEV_MODE,
|
|
228
|
-
APP_NAME,
|
|
229
|
-
APP_NAME_UNDERSCORED,
|
|
230
|
-
APP_NAME_DASHED,
|
|
231
|
-
PORTAL_COMPONENT_ATTRIBUTE,
|
|
232
|
-
PORTAL_REGION_ATTRIBUTE,
|
|
233
|
-
};
|
|
234
|
-
// Verify required values
|
|
235
|
-
const NOT_REQUIRED = ['IS_DEV_MODE'];
|
|
236
|
-
Object.keys(adapterConstants).forEach(key => {
|
|
237
|
-
if (NOT_REQUIRED.indexOf(key) === -1 && !adapterConstants[key]) {
|
|
238
|
-
throw Error(`constants.ts: Config value '${key}' is missing (from .env?)`);
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
export default adapterConstants;
|