@enonic/nextjs-adapter 2.0.0-B3 → 3.0.0-B1
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/UrlProcessor.d.ts +3 -2
- package/UrlProcessor.js +25 -10
- package/guillotine/fetchContent.d.ts +6 -7
- package/guillotine/fetchContent.js +99 -90
- package/i18n/LocaleContext.d.ts +13 -0
- package/i18n/LocaleContext.jsx +42 -0
- package/i18n/i18n.d.ts +13 -0
- package/i18n/i18n.js +56 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +16 -13
- package/utils.d.ts +28 -31
- package/utils.js +77 -63
- package/views/BaseComponent.d.ts +1 -1
- package/views/BaseComponent.jsx +19 -5
- package/views/RichTextView.jsx +4 -1
- 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/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
|
-
}); });
|