@enonic/nextjs-adapter 2.0.0-B1 → 2.0.0-B3

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.
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { getMetaQuery, pageFragmentQuery } from './getMetaData';
11
- import adapterConstants, { addJsessionHeaders, addLocaleHeaders, APP_NAME, APP_NAME_DASHED, FRAGMENT_CONTENTTYPE_NAME, FRAGMENT_DEFAULT_REGION_NAME, GET_STATIC_PATHS_QUERY, getContentApiUrl, getLocaleProjectConfig, getLocaleProjectConfigs, getRenderMode, getXpBaseUrl, IS_DEV_MODE, normalizeLocale, PAGE_TEMPLATE_CONTENTTYPE_NAME, PAGE_TEMPLATE_FOLDER, RENDER_MODE, sanitizeGraphqlName, XP_COMPONENT_TYPE, XP_REQUEST_TYPE, } from '../utils';
11
+ import adapterConstants, { addJsessionHeaders, addLocaleHeaders, APP_NAME, APP_NAME_DASHED, FRAGMENT_CONTENTTYPE_NAME, FRAGMENT_DEFAULT_REGION_NAME, GET_STATIC_PATHS_QUERY, getContentApiUrl, getLocaleProjectConfig, getLocaleProjectConfigs, getRenderMode, getXpBaseUrl, IS_DEV_MODE, normalizeLocale, PAGE_TEMPLATE_CONTENTTYPE_NAME, PAGE_TEMPLATE_FOLDER, PURGE_CACHE_URL, RENDER_MODE, sanitizeGraphqlName, XP_COMPONENT_TYPE, XP_REQUEST_TYPE, } from '../utils';
12
12
  import { ComponentRegistry } from '../ComponentRegistry';
13
13
  import { getUrl, UrlProcessor } from '../UrlProcessor';
14
14
  const NO_PROPS_PROCESSOR = (props) => __awaiter(void 0, void 0, void 0, function* () { var _a; return (_a = yield props) !== null && _a !== void 0 ? _a : {}; });
@@ -598,6 +598,10 @@ const buildContentFetcher = (config) => {
598
598
  UrlProcessor.setSiteKey(projectConfig.site);
599
599
  try {
600
600
  const requestContentPath = getCleanContentPathArrayOrThrow400(contentPathOrArray);
601
+ if ('/' + requestContentPath === PURGE_CACHE_URL) {
602
+ // return 404 for /_/cache/enonic/purge because it should've been handled by standalone endpoint
603
+ return errorResponse('404', 'Not found', requestType, renderMode, contentApiUrl, xpBaseUrl, context.locale, context.defaultLocale, requestContentPath);
604
+ }
601
605
  const [siteRelativeContentPath, componentPath] = getContentAndComponentPaths(requestContentPath, context);
602
606
  if (componentPath) {
603
607
  // set component request type because url contains component path
@@ -786,7 +790,7 @@ function populateEnonicHeaders(context) {
786
790
  context.params = Object.assign(context.params || {}, pd.params);
787
791
  context.req = req;
788
792
  }
789
- export function fetchContentPathsForAllLocales(path, query = GET_STATIC_PATHS_QUERY, countPerLocale) {
793
+ export function fetchContentPathsForAllLocales(path, query = GET_STATIC_PATHS_QUERY, countPerLocale = 999) {
790
794
  return __awaiter(this, void 0, void 0, function* () {
791
795
  const promises = Object.values(getLocaleProjectConfigs()).map(config => fetchContentPathsForLocale(path, config, query, countPerLocale));
792
796
  return Promise.all(promises).then(results => {
@@ -794,7 +798,7 @@ export function fetchContentPathsForAllLocales(path, query = GET_STATIC_PATHS_QU
794
798
  });
795
799
  });
796
800
  }
797
- export function fetchContentPathsForLocale(path, config, query = GET_STATIC_PATHS_QUERY, count) {
801
+ export function fetchContentPathsForLocale(path, config, query = GET_STATIC_PATHS_QUERY, count = 999) {
798
802
  return __awaiter(this, void 0, void 0, function* () {
799
803
  const contentApiUrl = getContentApiUrl({ locale: config.locale });
800
804
  const body = {
@@ -805,7 +809,7 @@ export function fetchContentPathsForLocale(path, config, query = GET_STATIC_PATH
805
809
  },
806
810
  };
807
811
  return fetchGuillotine(contentApiUrl, body, config).then((results) => {
808
- return results.guillotine.query.reduce((prev, child) => {
812
+ return results.guillotine.queryDsl.reduce((prev, child) => {
809
813
  var _a;
810
814
  const regexp = new RegExp(`/${(_a = child.site) === null || _a === void 0 ? void 0 : _a._name}/?`);
811
815
  const contentPath = child._path.replace(regexp, '');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enonic/nextjs-adapter",
3
- "version": "2.0.0-B1",
3
+ "version": "2.0.0-B3",
4
4
  "license": "Apache-2.0",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -13,22 +13,22 @@
13
13
  "lint:fix": "eslint --fix server && eslint --fix src"
14
14
  },
15
15
  "dependencies": {
16
- "html-react-parser": "^4.2.0",
17
- "lru-cache": "^10.0.0",
18
- "next": "13.4.12",
16
+ "html-react-parser": "^4.2.1",
17
+ "lru-cache": "^10.0.1",
18
+ "next": "13.4.19",
19
19
  "react": "18.2.0",
20
20
  "react-dom": "18.2.0",
21
21
  "unescape": "^1.0.1"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@enonic/eslint-config": "^1.1.0",
25
- "@types/node": "^20.4.4",
26
- "@types/react": "18.2.15",
25
+ "@types/node": "^20.5.1",
26
+ "@types/react": "18.2.20",
27
27
  "@types/react-dom": "18.2.7",
28
28
  "@typescript-eslint/eslint-plugin": "^5.61.0",
29
29
  "@typescript-eslint/parser": "^5.62.0",
30
- "eslint": "^8.45.0",
31
- "eslint-plugin-react": "^7.33.0",
30
+ "eslint": "^8.47.0",
31
+ "eslint-plugin-react": "^7.33.2",
32
32
  "typescript": "^5.1.6"
33
33
  }
34
34
  }
@@ -4,12 +4,13 @@ type FileSystemCacheContext = Omit<CacheHandlerContext, 'fs' | 'serverDistDir'>
4
4
  fs: CacheFs;
5
5
  serverDistDir: string;
6
6
  };
7
- export default class ClearableFileCache implements CacheHandler {
7
+ export default class FileSystemCache implements CacheHandler {
8
8
  private fs;
9
9
  private flushToDisk?;
10
10
  private serverDistDir;
11
11
  private appDir;
12
12
  private tagsManifestPath?;
13
+ private revalidatedTags;
13
14
  constructor(ctx: FileSystemCacheContext);
14
15
  clear(): void;
15
16
  delete(path: string): boolean | undefined;
@@ -41,15 +41,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  var path_1 = __importDefault(require("path"));
43
43
  var lru_cache_1 = require("lru-cache");
44
- var constants_1 = require("next/dist/lib/constants");
44
+ var utils_1 = require("next/dist/server/lib/incremental-cache/utils");
45
45
  var memoryCache;
46
46
  var tagsManifest;
47
- var ClearableFileCache = /** @class */ (function () {
48
- function ClearableFileCache(ctx) {
47
+ var FileSystemCache = /** @class */ (function () {
48
+ function FileSystemCache(ctx) {
49
49
  this.fs = ctx.fs;
50
50
  this.flushToDisk = ctx.flushToDisk;
51
51
  this.serverDistDir = ctx.serverDistDir;
52
52
  this.appDir = !!ctx._appDir;
53
+ this.revalidatedTags = ctx.revalidatedTags;
53
54
  if (ctx.maxMemoryCacheSize && !memoryCache) {
54
55
  memoryCache = new lru_cache_1.LRUCache({
55
56
  max: ctx.maxMemoryCacheSize,
@@ -82,14 +83,14 @@ var ClearableFileCache = /** @class */ (function () {
82
83
  this.loadTagsManifest();
83
84
  }
84
85
  }
85
- ClearableFileCache.prototype.clear = function () {
86
+ FileSystemCache.prototype.clear = function () {
86
87
  memoryCache === null || memoryCache === void 0 ? void 0 : memoryCache.clear();
87
88
  };
88
- ClearableFileCache.prototype.delete = function (path) {
89
+ FileSystemCache.prototype.delete = function (path) {
89
90
  return memoryCache === null || memoryCache === void 0 ? void 0 : memoryCache.delete(path);
90
91
  };
91
- ClearableFileCache.prototype.loadTagsManifest = function () {
92
- if (!this.tagsManifestPath || !this.fs)
92
+ FileSystemCache.prototype.loadTagsManifest = function () {
93
+ if (!this.tagsManifestPath || !this.fs || tagsManifest)
93
94
  return;
94
95
  try {
95
96
  tagsManifest = JSON.parse(this.fs.readFileSync(this.tagsManifestPath).toString('utf8'));
@@ -98,7 +99,7 @@ var ClearableFileCache = /** @class */ (function () {
98
99
  tagsManifest = { version: 1, items: {} };
99
100
  }
100
101
  };
101
- ClearableFileCache.prototype.setTags = function (key, tags) {
102
+ FileSystemCache.prototype.setTags = function (key, tags) {
102
103
  return __awaiter(this, void 0, void 0, function () {
103
104
  var _i, tags_1, tag, data, err_1;
104
105
  return __generator(this, function (_a) {
@@ -135,7 +136,7 @@ var ClearableFileCache = /** @class */ (function () {
135
136
  });
136
137
  });
137
138
  };
138
- ClearableFileCache.prototype.revalidateTag = function (tag) {
139
+ FileSystemCache.prototype.revalidateTag = function (tag) {
139
140
  return __awaiter(this, void 0, void 0, function () {
140
141
  var data, err_2;
141
142
  return __generator(this, function (_a) {
@@ -170,34 +171,35 @@ var ClearableFileCache = /** @class */ (function () {
170
171
  });
171
172
  });
172
173
  };
173
- ClearableFileCache.prototype.get = function (key, fetchCache) {
174
- var _a, _b;
174
+ FileSystemCache.prototype.get = function (key, fetchCache) {
175
+ var _a, _b, _c, _d;
175
176
  return __awaiter(this, void 0, void 0, function () {
176
- var data, filePath, fileData, mtime, meta, _c, _d, cacheEntry, _1, _e, filePath, isAppPath, fileData, mtime, lastModified, parsedData, pageData, _f, _g, _h, _j, _k, _l, _m, _2, innerData, isStale;
177
- return __generator(this, function (_o) {
178
- switch (_o.label) {
177
+ var data, filePath, fileData, mtime, meta, _e, _f, cacheEntry, _1, _g, filePath, isAppPath, fileData, mtime, lastModified, parsedData, pageData, _h, _j, _k, _l, _m, _o, _p, meta, _q, _r, _2, _3, cacheTags, tagsHeader, derivedTags, isStale, innerData, derivedTags, wasRevalidated;
178
+ var _this = this;
179
+ return __generator(this, function (_s) {
180
+ switch (_s.label) {
179
181
  case 0:
180
182
  data = memoryCache === null || memoryCache === void 0 ? void 0 : memoryCache.get(key);
181
- if (!(!data && process.env.NEXT_RUNTIME !== 'edge')) return [3 /*break*/, 20];
182
- _o.label = 1;
183
+ if (!(!data && process.env.NEXT_RUNTIME !== 'edge')) return [3 /*break*/, 24];
184
+ _s.label = 1;
183
185
  case 1:
184
- _o.trys.push([1, 6, , 7]);
186
+ _s.trys.push([1, 6, , 7]);
185
187
  return [4 /*yield*/, this.getFsPath({
186
188
  pathname: "".concat(key, ".body"),
187
189
  appDir: true,
188
190
  })];
189
191
  case 2:
190
- filePath = (_o.sent()).filePath;
192
+ filePath = (_s.sent()).filePath;
191
193
  return [4 /*yield*/, this.fs.readFile(filePath)];
192
194
  case 3:
193
- fileData = _o.sent();
195
+ fileData = _s.sent();
194
196
  return [4 /*yield*/, this.fs.stat(filePath)];
195
197
  case 4:
196
- mtime = (_o.sent()).mtime;
197
- _d = (_c = JSON).parse;
198
+ mtime = (_s.sent()).mtime;
199
+ _f = (_e = JSON).parse;
198
200
  return [4 /*yield*/, this.fs.readFile(filePath.replace(/\.body$/, '.meta'))];
199
201
  case 5:
200
- meta = _d.apply(_c, [(_o.sent()).toString('utf8')]);
202
+ meta = _f.apply(_e, [(_s.sent()).toString('utf8')]);
201
203
  cacheEntry = {
202
204
  lastModified: mtime.getTime(),
203
205
  value: {
@@ -209,22 +211,22 @@ var ClearableFileCache = /** @class */ (function () {
209
211
  };
210
212
  return [2 /*return*/, cacheEntry];
211
213
  case 6:
212
- _1 = _o.sent();
214
+ _1 = _s.sent();
213
215
  return [3 /*break*/, 7];
214
216
  case 7:
215
- _o.trys.push([7, 19, , 20]);
217
+ _s.trys.push([7, 23, , 24]);
216
218
  return [4 /*yield*/, this.getFsPath({
217
219
  pathname: fetchCache ? key : "".concat(key, ".html"),
218
220
  fetchCache: fetchCache,
219
221
  })];
220
222
  case 8:
221
- _e = _o.sent(), filePath = _e.filePath, isAppPath = _e.isAppPath;
223
+ _g = _s.sent(), filePath = _g.filePath, isAppPath = _g.isAppPath;
222
224
  return [4 /*yield*/, this.fs.readFile(filePath)];
223
225
  case 9:
224
- fileData = (_o.sent()).toString('utf-8');
226
+ fileData = (_s.sent()).toString('utf-8');
225
227
  return [4 /*yield*/, this.fs.stat(filePath)];
226
228
  case 10:
227
- mtime = (_o.sent()).mtime;
229
+ mtime = (_s.sent()).mtime;
228
230
  if (!fetchCache) return [3 /*break*/, 11];
229
231
  lastModified = mtime.getTime();
230
232
  parsedData = JSON.parse(fileData);
@@ -232,60 +234,104 @@ var ClearableFileCache = /** @class */ (function () {
232
234
  lastModified: lastModified,
233
235
  value: parsedData,
234
236
  };
235
- return [3 /*break*/, 18];
237
+ return [3 /*break*/, 22];
236
238
  case 11:
237
239
  if (!isAppPath) return [3 /*break*/, 14];
238
- _h = (_g = this.fs).readFile;
240
+ _k = (_j = this.fs).readFile;
239
241
  return [4 /*yield*/, this.getFsPath({
240
242
  pathname: "".concat(key, ".rsc"),
241
243
  appDir: true,
242
244
  })];
243
- case 12: return [4 /*yield*/, _h.apply(_g, [(_o.sent()).filePath])];
245
+ case 12: return [4 /*yield*/, _k.apply(_j, [(_s.sent()).filePath])];
244
246
  case 13:
245
- _f = (_o.sent()).toString('utf8');
247
+ _h = (_s.sent()).toString('utf8');
246
248
  return [3 /*break*/, 17];
247
249
  case 14:
248
- _k = (_j = JSON).parse;
249
- _m = (_l = this.fs).readFile;
250
+ _m = (_l = JSON).parse;
251
+ _p = (_o = this.fs).readFile;
250
252
  return [4 /*yield*/, this.getFsPath({
251
253
  pathname: "".concat(key, ".json"),
252
254
  appDir: false,
253
255
  })];
254
- case 15: return [4 /*yield*/, _m.apply(_l, [(_o.sent()).filePath])];
256
+ case 15: return [4 /*yield*/, _p.apply(_o, [(_s.sent()).filePath])];
255
257
  case 16:
256
- _f = _k.apply(_j, [(_o.sent()).toString('utf8')]);
257
- _o.label = 17;
258
+ _h = _m.apply(_l, [(_s.sent()).toString('utf8')]);
259
+ _s.label = 17;
258
260
  case 17:
259
- pageData = _f;
261
+ pageData = _h;
262
+ meta = {};
263
+ if (!isAppPath) return [3 /*break*/, 21];
264
+ _s.label = 18;
265
+ case 18:
266
+ _s.trys.push([18, 20, , 21]);
267
+ _r = (_q = JSON).parse;
268
+ return [4 /*yield*/, this.fs.readFile(filePath.replace(/\.html$/, '.meta'))];
269
+ case 19:
270
+ meta = _r.apply(_q, [(_s.sent()).toString('utf-8')]);
271
+ return [3 /*break*/, 21];
272
+ case 20:
273
+ _2 = _s.sent();
274
+ return [3 /*break*/, 21];
275
+ case 21:
260
276
  data = {
261
277
  lastModified: mtime.getTime(),
262
278
  value: {
263
279
  kind: 'PAGE',
264
280
  html: fileData,
265
281
  pageData: pageData,
282
+ headers: meta.headers,
283
+ status: meta.status,
266
284
  },
267
285
  };
268
- _o.label = 18;
269
- case 18:
286
+ _s.label = 22;
287
+ case 22:
270
288
  if (data) {
271
289
  memoryCache === null || memoryCache === void 0 ? void 0 : memoryCache.set(key, data);
272
290
  }
273
- return [3 /*break*/, 20];
274
- case 19:
275
- _2 = _o.sent();
276
- return [3 /*break*/, 20];
277
- case 20:
278
- if (data && ((_a = data === null || data === void 0 ? void 0 : data.value) === null || _a === void 0 ? void 0 : _a.kind) === 'FETCH') {
291
+ return [3 /*break*/, 24];
292
+ case 23:
293
+ _3 = _s.sent();
294
+ return [3 /*break*/, 24];
295
+ case 24:
296
+ if (((_a = data === null || data === void 0 ? void 0 : data.value) === null || _a === void 0 ? void 0 : _a.kind) === 'PAGE') {
297
+ tagsHeader = (_b = data.value.headers) === null || _b === void 0 ? void 0 : _b['x-next-cache-tags'];
298
+ if (typeof tagsHeader === 'string') {
299
+ cacheTags = tagsHeader.split(',');
300
+ }
301
+ }
302
+ if (((_c = data === null || data === void 0 ? void 0 : data.value) === null || _c === void 0 ? void 0 : _c.kind) === 'PAGE' && (cacheTags === null || cacheTags === void 0 ? void 0 : cacheTags.length)) {
279
303
  this.loadTagsManifest();
280
- innerData = data.value.data;
281
- isStale = (_b = innerData.tags) === null || _b === void 0 ? void 0 : _b.some(function (tag) {
304
+ derivedTags = (0, utils_1.getDerivedTags)(cacheTags || []);
305
+ isStale = derivedTags.some(function (tag) {
282
306
  var _a;
283
307
  return (((_a = tagsManifest === null || tagsManifest === void 0 ? void 0 : tagsManifest.items[tag]) === null || _a === void 0 ? void 0 : _a.revalidatedAt) &&
284
308
  (tagsManifest === null || tagsManifest === void 0 ? void 0 : tagsManifest.items[tag].revalidatedAt) >=
285
309
  ((data === null || data === void 0 ? void 0 : data.lastModified) || Date.now()));
286
310
  });
311
+ // we trigger a blocking validation if an ISR page
312
+ // had a tag revalidated, if we want to be a background
313
+ // revalidation instead we return data.lastModified = -1
287
314
  if (isStale) {
288
- data.lastModified = Date.now() - constants_1.CACHE_ONE_YEAR;
315
+ data = undefined;
316
+ }
317
+ }
318
+ if (data && ((_d = data === null || data === void 0 ? void 0 : data.value) === null || _d === void 0 ? void 0 : _d.kind) === 'FETCH') {
319
+ this.loadTagsManifest();
320
+ innerData = data.value.data;
321
+ derivedTags = (0, utils_1.getDerivedTags)(innerData.tags || []);
322
+ wasRevalidated = derivedTags.some(function (tag) {
323
+ var _a;
324
+ if (_this.revalidatedTags.includes(tag)) {
325
+ return true;
326
+ }
327
+ return (((_a = tagsManifest === null || tagsManifest === void 0 ? void 0 : tagsManifest.items[tag]) === null || _a === void 0 ? void 0 : _a.revalidatedAt) &&
328
+ (tagsManifest === null || tagsManifest === void 0 ? void 0 : tagsManifest.items[tag].revalidatedAt) >=
329
+ ((data === null || data === void 0 ? void 0 : data.lastModified) || Date.now()));
330
+ });
331
+ // When revalidate tag is called we don't return
332
+ // stale data so it's updated right away
333
+ if (wasRevalidated) {
334
+ data = undefined;
289
335
  }
290
336
  }
291
337
  return [2 /*return*/, data || null];
@@ -293,7 +339,7 @@ var ClearableFileCache = /** @class */ (function () {
293
339
  });
294
340
  });
295
341
  };
296
- ClearableFileCache.prototype.set = function (key, data) {
342
+ FileSystemCache.prototype.set = function (key, data) {
297
343
  return __awaiter(this, void 0, void 0, function () {
298
344
  var filePath, isAppPath, htmlPath, _a, _b, filePath;
299
345
  return __generator(this, function (_c) {
@@ -323,7 +369,7 @@ var ClearableFileCache = /** @class */ (function () {
323
369
  _c.sent();
324
370
  return [2 /*return*/];
325
371
  case 5:
326
- if (!((data === null || data === void 0 ? void 0 : data.kind) === 'PAGE')) return [3 /*break*/, 11];
372
+ if (!((data === null || data === void 0 ? void 0 : data.kind) === 'PAGE')) return [3 /*break*/, 13];
327
373
  isAppPath = typeof data.pageData === 'string';
328
374
  return [4 /*yield*/, this.getFsPath({
329
375
  pathname: "".concat(key, ".html"),
@@ -346,31 +392,39 @@ var ClearableFileCache = /** @class */ (function () {
346
392
  isAppPath ? data.pageData : JSON.stringify(data.pageData)])];
347
393
  case 10:
348
394
  _c.sent();
349
- return [3 /*break*/, 16];
395
+ if (!(data.headers || data.status)) return [3 /*break*/, 12];
396
+ return [4 /*yield*/, this.fs.writeFile(htmlPath.replace(/\.html$/, '.meta'), JSON.stringify({
397
+ headers: data.headers,
398
+ status: data.status,
399
+ }))];
350
400
  case 11:
351
- if (!((data === null || data === void 0 ? void 0 : data.kind) === 'FETCH')) return [3 /*break*/, 16];
401
+ _c.sent();
402
+ _c.label = 12;
403
+ case 12: return [3 /*break*/, 18];
404
+ case 13:
405
+ if (!((data === null || data === void 0 ? void 0 : data.kind) === 'FETCH')) return [3 /*break*/, 18];
352
406
  return [4 /*yield*/, this.getFsPath({
353
407
  pathname: key,
354
408
  fetchCache: true,
355
409
  })];
356
- case 12:
410
+ case 14:
357
411
  filePath = (_c.sent()).filePath;
358
412
  return [4 /*yield*/, this.fs.mkdir(path_1.default.dirname(filePath))];
359
- case 13:
413
+ case 15:
360
414
  _c.sent();
361
415
  return [4 /*yield*/, this.fs.writeFile(filePath, JSON.stringify(data))];
362
- case 14:
416
+ case 16:
363
417
  _c.sent();
364
418
  return [4 /*yield*/, this.setTags(key, data.data.tags || [])];
365
- case 15:
419
+ case 17:
366
420
  _c.sent();
367
- _c.label = 16;
368
- case 16: return [2 /*return*/];
421
+ _c.label = 18;
422
+ case 18: return [2 /*return*/];
369
423
  }
370
424
  });
371
425
  });
372
426
  };
373
- ClearableFileCache.prototype.getFsPath = function (_a) {
427
+ FileSystemCache.prototype.getFsPath = function (_a) {
374
428
  var pathname = _a.pathname, appDir = _a.appDir, fetchCache = _a.fetchCache;
375
429
  return __awaiter(this, void 0, void 0, function () {
376
430
  var isAppPath, filePath, err_3;
@@ -413,6 +467,6 @@ var ClearableFileCache = /** @class */ (function () {
413
467
  });
414
468
  });
415
469
  };
416
- return ClearableFileCache;
470
+ return FileSystemCache;
417
471
  }());
418
- exports.default = ClearableFileCache;
472
+ exports.default = FileSystemCache;
package/server/index.js CHANGED
@@ -97,7 +97,7 @@ exports.default = (function (next) { return __awaiter(void 0, void 0, void 0, fu
97
97
  return [3 /*break*/, 5];
98
98
  case 3:
99
99
  tokenParam = parsedUrl.searchParams.get('token');
100
- if (tokenParam !== process.env.API_TOKEN) {
100
+ if (tokenParam !== process.env.ENONIC_API_TOKEN) {
101
101
  // XP hijacks 401 to show login page, so send 407 instead
102
102
  res.statusCode = 407;
103
103
  res.end(JSON.stringify({ message: 'Invalid token' }));
package/utils.d.ts CHANGED
@@ -5,6 +5,7 @@ import { GetServerSidePropsContext } from 'next';
5
5
  import { ParsedUrlQuery } from 'node:querystring';
6
6
  import { IncomingHttpHeaders } from 'http';
7
7
  export declare const IS_DEV_MODE: boolean;
8
+ export declare const PURGE_CACHE_URL = "/_/enonic/cache/purge";
8
9
  export declare enum ENV_VARS {
9
10
  PROJECTS = "ENONIC_PROJECTS",
10
11
  API = "ENONIC_API",
@@ -36,7 +37,7 @@ export declare const DEFAULT_LOCALE_HEADER = "default-locale";
36
37
  * - media
37
38
  * - paths with '/_' in them
38
39
  */
39
- export declare const GET_STATIC_PATHS_QUERY = "query ($count: Int = 100){\n guillotine {\n query(query: \"type != 'base:folder' AND type != 'base:shortcut' AND type NOT LIKE 'media:*' AND _path NOT LIKE '*/_*'\", first: $count) {\n _name\n _path\n site {\n _name\n }\n }\n }\n}";
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: {string: \"media:*\"}}}\n {like: {field: \"_path\", value: {string: \"*/_*\"}}}\n ]}}\n ) {\n _name\n _path\n site {_name}\n }\n }\n}";
40
41
  export declare enum XP_REQUEST_TYPE {
41
42
  COMPONENT = "component",
42
43
  TYPE = "type",
package/utils.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const mode = process.env.MODE || process.env.NEXT_PUBLIC_MODE;
2
2
  export const IS_DEV_MODE = (mode === 'development');
3
+ export const PURGE_CACHE_URL = '/_/enonic/cache/purge';
3
4
  export var ENV_VARS;
4
5
  (function (ENV_VARS) {
5
6
  ENV_VARS["PROJECTS"] = "ENONIC_PROJECTS";
@@ -39,14 +40,23 @@ export const DEFAULT_LOCALE_HEADER = 'default-locale';
39
40
  * - media
40
41
  * - paths with '/_' in them
41
42
  */
42
- export const GET_STATIC_PATHS_QUERY = `query ($count: Int = 100){
43
+ export const GET_STATIC_PATHS_QUERY = `query ($count: Int) {
43
44
  guillotine {
44
- query(query: "type != 'base:folder' AND type != 'base:shortcut' AND type NOT LIKE 'media:*' AND _path NOT LIKE '*/_*'", first: $count) {
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: {string: "media:*"}}}
54
+ {like: {field: "_path", value: {string: "*/_*"}}}
55
+ ]}}
56
+ ) {
45
57
  _name
46
58
  _path
47
- site {
48
- _name
49
- }
59
+ site {_name}
50
60
  }
51
61
  }
52
62
  }`;