@bright.global/arboretum-sdk 0.1.0-rc.1 → 0.1.0-rc.10

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 (48) hide show
  1. package/dist/clients/contentful-client/impl/constants.js +5 -2
  2. package/dist/clients/contentful-client/impl/contentful-client-impl.js +11 -6
  3. package/dist/clients/contentful-client/impl/methods/contentful-fetch.js +2 -3
  4. package/dist/es6/clients/contentful-client/impl/constants.js +4 -1
  5. package/dist/es6/clients/contentful-client/impl/contentful-client-impl.js +11 -6
  6. package/dist/es6/clients/contentful-client/impl/methods/contentful-fetch.js +3 -4
  7. package/dist/es6/impl/arboretum-client.impl.js +6 -2
  8. package/dist/es6/impl/constants.js +5 -0
  9. package/dist/es6/impl/data/page-entries.js +16 -10
  10. package/dist/es6/impl/data/page-entries.test.js +21 -17
  11. package/dist/es6/impl/data/sitemap-data.js +11 -13
  12. package/dist/es6/impl/sitemap/adapters/redirect-entry-adapter.js +1 -1
  13. package/dist/es6/impl/sitemap/adapters/redirect-to-arboretum-page-adapter.js +1 -0
  14. package/dist/es6/impl/sitemap/adapters/to-arboretum-page-with-missing-data-adapter.js +1 -0
  15. package/dist/es6/impl/sitemap/helpers/build-localized-sitemap.js +23 -20
  16. package/dist/es6/impl/sitemap/methods/orphaned-pages.js +97 -0
  17. package/dist/es6/impl/sitemap/methods/search-orphaned-pages.js +41 -0
  18. package/dist/es6/impl/sitemap/methods/search.js +43 -87
  19. package/dist/es6/utils/phrase-similarity.js +6 -0
  20. package/dist/es6/utils/string-similarity.js +1 -1
  21. package/dist/impl/arboretum-client.impl.js +6 -2
  22. package/dist/impl/constants.js +8 -0
  23. package/dist/impl/data/page-entries.js +16 -10
  24. package/dist/impl/data/page-entries.test.js +19 -15
  25. package/dist/impl/data/sitemap-data.js +5 -7
  26. package/dist/impl/sitemap/adapters/redirect-entry-adapter.js +1 -1
  27. package/dist/impl/sitemap/adapters/redirect-to-arboretum-page-adapter.js +1 -0
  28. package/dist/impl/sitemap/adapters/to-arboretum-page-with-missing-data-adapter.js +1 -0
  29. package/dist/impl/sitemap/helpers/build-localized-sitemap.js +25 -21
  30. package/dist/impl/sitemap/methods/orphaned-pages.js +101 -0
  31. package/dist/impl/sitemap/methods/search-orphaned-pages.js +45 -0
  32. package/dist/impl/sitemap/methods/search.js +43 -87
  33. package/dist/types/arboretum-client.d.ts +23 -8
  34. package/dist/types/clients/contentful-client/impl/constants.d.ts +4 -1
  35. package/dist/types/impl/constants.d.ts +5 -0
  36. package/dist/types/impl/data/page-entries.d.ts +5 -1
  37. package/dist/types/impl/data/sitemap-data.d.ts +8 -8
  38. package/dist/types/impl/sitemap/helpers/build-localized-sitemap.d.ts +10 -2
  39. package/dist/types/impl/sitemap/methods/orphaned-pages.d.ts +3 -0
  40. package/dist/types/impl/sitemap/methods/search-orphaned-pages.d.ts +3 -0
  41. package/dist/types/impl/sitemap/methods/search.d.ts +3 -3
  42. package/dist/types/utils/phrase-similarity.d.ts +1 -0
  43. package/dist/utils/phrase-similarity.js +10 -0
  44. package/dist/utils/string-similarity.js +1 -1
  45. package/package.json +1 -1
  46. package/dist/es6/impl/data/home-page.js +0 -75
  47. package/dist/impl/data/home-page.js +0 -79
  48. package/dist/types/impl/data/home-page.d.ts +0 -3
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_RETRY_LIMIT = exports.DEFAULT_RETRY_ON_ERROR = exports.DEFAULT_TIMEOUT = exports.DEFAULT_HOST = exports.DEFAULT_ENVIRONMENT = void 0;
3
+ exports.EU_PREVIEW_HOST = exports.PREVIEW_HOST = exports.EU_PUBLISHED_HOST = exports.PUBLISHED_HOST = exports.DEFAULT_RETRY_LIMIT = exports.DEFAULT_RETRY_ON_ERROR = exports.DEFAULT_TIMEOUT = exports.DEFAULT_ENVIRONMENT = void 0;
4
4
  exports.DEFAULT_ENVIRONMENT = "master";
5
- exports.DEFAULT_HOST = "cdn.contentful.com";
6
5
  exports.DEFAULT_TIMEOUT = 30000;
7
6
  exports.DEFAULT_RETRY_ON_ERROR = true;
8
7
  exports.DEFAULT_RETRY_LIMIT = 5;
8
+ exports.PUBLISHED_HOST = "cdn.contentful.com";
9
+ exports.EU_PUBLISHED_HOST = "cdn.eu.contentful.com";
10
+ exports.PREVIEW_HOST = "preview.contentful.com";
11
+ exports.EU_PREVIEW_HOST = "preview.eu.contentful.com";
@@ -12,10 +12,11 @@ var __assign = (this && this.__assign) || function () {
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.createCdaRestApiContentfulClient = exports.createContentfulClient = void 0;
15
- var get_locales_1 = require("./methods/get-locales");
15
+ var constants_1 = require("./constants");
16
16
  var get_content_types_1 = require("./methods/get-content-types");
17
- var get_tags_1 = require("./methods/get-tags");
18
17
  var get_entries_1 = require("./methods/get-entries");
18
+ var get_locales_1 = require("./methods/get-locales");
19
+ var get_tags_1 = require("./methods/get-tags");
19
20
  var createContentfulClient = function (config) {
20
21
  var configType = config.type;
21
22
  switch (config.type) {
@@ -30,10 +31,14 @@ var createContentfulClient = function (config) {
30
31
  };
31
32
  }
32
33
  case "cda-client-params": {
33
- var previewHostOrUndefined = config.preview
34
- ? "preview.contentful.com"
35
- : undefined;
36
- return (0, exports.createCdaRestApiContentfulClient)(__assign(__assign({}, config.contentful), { host: previewHostOrUndefined }));
34
+ var host = config.preview
35
+ ? config.contentful.euDataResidency
36
+ ? constants_1.EU_PREVIEW_HOST
37
+ : constants_1.PREVIEW_HOST
38
+ : config.contentful.euDataResidency
39
+ ? constants_1.EU_PUBLISHED_HOST
40
+ : constants_1.PUBLISHED_HOST;
41
+ return (0, exports.createCdaRestApiContentfulClient)(__assign(__assign({}, config.contentful), { host: host }));
37
42
  }
38
43
  case "cma-client": {
39
44
  var client_1 = config.contentful.client;
@@ -72,7 +72,7 @@ var contentfulFetchWithRetires = function (p, retryLimit, retry) {
72
72
  if (!(retry < retryLimit &&
73
73
  (res.status === 429 || res.status === 500))) return [3 /*break*/, 3];
74
74
  delay = getRetryDelay(retry);
75
- msg = "Waiting for ".concat(delay, "ms before retrying... (retry: ").concat(delay, "/").concat(retryLimit, ")");
75
+ msg = "Waiting for ".concat(delay, "ms before retrying... (retry: ").concat(retry + 1, "/").concat(retryLimit, ")");
76
76
  if (res.status === 500) {
77
77
  console.log("[warning] Internal server error occurred. ".concat(msg));
78
78
  }
@@ -97,8 +97,7 @@ var contentfulFetchWithRetires = function (p, retryLimit, retry) {
97
97
  };
98
98
  var contentfulFetch = function (config) {
99
99
  return function (endpoint, query) {
100
- var space = config.space, accessToken = config.accessToken;
101
- var host = config.host || constants_1.DEFAULT_HOST;
100
+ var space = config.space, accessToken = config.accessToken, host = config.host;
102
101
  var environment = config.environment || constants_1.DEFAULT_ENVIRONMENT;
103
102
  var params = new URLSearchParams();
104
103
  params.append("access_token", accessToken);
@@ -1,5 +1,8 @@
1
1
  export var DEFAULT_ENVIRONMENT = "master";
2
- export var DEFAULT_HOST = "cdn.contentful.com";
3
2
  export var DEFAULT_TIMEOUT = 30000;
4
3
  export var DEFAULT_RETRY_ON_ERROR = true;
5
4
  export var DEFAULT_RETRY_LIMIT = 5;
5
+ export var PUBLISHED_HOST = "cdn.contentful.com";
6
+ export var EU_PUBLISHED_HOST = "cdn.eu.contentful.com";
7
+ export var PREVIEW_HOST = "preview.contentful.com";
8
+ export var EU_PREVIEW_HOST = "preview.eu.contentful.com";
@@ -9,10 +9,11 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import { getLocales } from "./methods/get-locales";
12
+ import { EU_PREVIEW_HOST, EU_PUBLISHED_HOST, PREVIEW_HOST, PUBLISHED_HOST, } from "./constants";
13
13
  import { getContentTypes } from "./methods/get-content-types";
14
- import { getTags } from "./methods/get-tags";
15
14
  import { getEntries } from "./methods/get-entries";
15
+ import { getLocales } from "./methods/get-locales";
16
+ import { getTags } from "./methods/get-tags";
16
17
  export var createContentfulClient = function (config) {
17
18
  var configType = config.type;
18
19
  switch (config.type) {
@@ -27,10 +28,14 @@ export var createContentfulClient = function (config) {
27
28
  };
28
29
  }
29
30
  case "cda-client-params": {
30
- var previewHostOrUndefined = config.preview
31
- ? "preview.contentful.com"
32
- : undefined;
33
- return createCdaRestApiContentfulClient(__assign(__assign({}, config.contentful), { host: previewHostOrUndefined }));
31
+ var host = config.preview
32
+ ? config.contentful.euDataResidency
33
+ ? EU_PREVIEW_HOST
34
+ : PREVIEW_HOST
35
+ : config.contentful.euDataResidency
36
+ ? EU_PUBLISHED_HOST
37
+ : PUBLISHED_HOST;
38
+ return createCdaRestApiContentfulClient(__assign(__assign({}, config.contentful), { host: host }));
34
39
  }
35
40
  case "cma-client": {
36
41
  var client_1 = config.contentful.client;
@@ -51,7 +51,7 @@ var __read = (this && this.__read) || function (o, n) {
51
51
  return ar;
52
52
  };
53
53
  import { getRandomNumber } from "../../../../utils/get-rendom-number";
54
- import { DEFAULT_ENVIRONMENT, DEFAULT_HOST, DEFAULT_RETRY_LIMIT, DEFAULT_RETRY_ON_ERROR, } from "../constants";
54
+ import { DEFAULT_ENVIRONMENT, DEFAULT_RETRY_LIMIT, DEFAULT_RETRY_ON_ERROR, } from "../constants";
55
55
  var sleep = function (ms) { return new Promise(function (r) { return setTimeout(r, ms); }); };
56
56
  var getRetryDelay = function (retry) {
57
57
  return Math.ceil(Math.pow(getRandomNumber(1.2, 1.4), retry) * 1000);
@@ -69,7 +69,7 @@ var contentfulFetchWithRetires = function (p, retryLimit, retry) {
69
69
  if (!(retry < retryLimit &&
70
70
  (res.status === 429 || res.status === 500))) return [3 /*break*/, 3];
71
71
  delay = getRetryDelay(retry);
72
- msg = "Waiting for ".concat(delay, "ms before retrying... (retry: ").concat(delay, "/").concat(retryLimit, ")");
72
+ msg = "Waiting for ".concat(delay, "ms before retrying... (retry: ").concat(retry + 1, "/").concat(retryLimit, ")");
73
73
  if (res.status === 500) {
74
74
  console.log("[warning] Internal server error occurred. ".concat(msg));
75
75
  }
@@ -94,8 +94,7 @@ var contentfulFetchWithRetires = function (p, retryLimit, retry) {
94
94
  };
95
95
  export var contentfulFetch = function (config) {
96
96
  return function (endpoint, query) {
97
- var space = config.space, accessToken = config.accessToken;
98
- var host = config.host || DEFAULT_HOST;
97
+ var space = config.space, accessToken = config.accessToken, host = config.host;
99
98
  var environment = config.environment || DEFAULT_ENVIRONMENT;
100
99
  var params = new URLSearchParams();
101
100
  params.append("access_token", accessToken);
@@ -78,7 +78,6 @@ import { pagesByTagId } from "./sitemap/methods/pages-by-tag-id";
78
78
  import { pagesByIds } from "./sitemap/methods/pages-by-ids";
79
79
  import { pagesByPaths } from "./sitemap/methods/pages-by-paths";
80
80
  import { regenerate } from "./sitemap/methods/regenerate";
81
- import { search } from "./sitemap/methods/search";
82
81
  import { status } from "./sitemap/methods/status";
83
82
  import { right } from "../utils/fp-utils";
84
83
  import { pages } from "./sitemap/methods/pages";
@@ -86,6 +85,9 @@ import { buildSitemapEagerly } from "./sitemap/helpers/build-sitemap-eagerly";
86
85
  import { cachedData } from "./sitemap/methods/cached-data";
87
86
  import { buildPagesByTagEagerly } from "./sitemap/helpers/build-pages-by-tag-eagerly";
88
87
  import { homePage } from "./sitemap/methods/home-page";
88
+ import { orphanedPages } from "./sitemap/methods/orphaned-pages";
89
+ import { searchOrphanedPages } from "./sitemap/methods/search-orphaned-pages";
90
+ import { search } from "./sitemap/methods/search";
89
91
  var pageTagIdPrefix = "page";
90
92
  var pageHomeTagId = "".concat(pageTagIdPrefix, "Home");
91
93
  var localeTagIdPrefix = "locale";
@@ -123,7 +125,7 @@ export var createArboretumClient = function (config) { return __awaiter(void 0,
123
125
  sitemapDataCtx = {
124
126
  preview: config.preview,
125
127
  clientApi: clientApi,
126
- options: __assign(__assign({}, options), { includeEntryStatus: includeEntryStatus, sitemapRepresentation: (_c = config.options) === null || _c === void 0 ? void 0 : _c.sitemapRepresentation }),
128
+ options: __assign(__assign({}, options), { includeEntryStatus: includeEntryStatus, pageRelations: (_c = config.options) === null || _c === void 0 ? void 0 : _c.pageRelations }),
127
129
  localeTagIdPrefix: localeTagIdPrefix,
128
130
  pageHomeTagId: options.homePageTagId || pageHomeTagId,
129
131
  contentfulClientType: config.type === "cda-client" && config.contentful.client.withAllLocales
@@ -168,6 +170,8 @@ export var createArboretumClient = function (config) { return __awaiter(void 0,
168
170
  search: search(ctx_1),
169
171
  status: status(ctx_1),
170
172
  cachedData: cachedData(ctx_1),
173
+ orphanedPages: orphanedPages(ctx_1),
174
+ searchOrphanedPages: searchOrphanedPages(ctx_1),
171
175
  },
172
176
  warnings: dataE.right.warnings,
173
177
  }];
@@ -0,0 +1,5 @@
1
+ export var CONSTANTS = {
2
+ search: {
3
+ minSearchScore: 0.4,
4
+ },
5
+ };
@@ -105,7 +105,7 @@ var cmaOnlyEntriesStatusMap = function (_a, contentfulClientType, options) {
105
105
  });
106
106
  };
107
107
  export var pageEntries = function (ctx, apiClient, cmaPreviewClientApi) { return __awaiter(void 0, void 0, void 0, function () {
108
- var options, pageContentTypes, pageEntriesPromise, statusRecordPromise, _a, pageEntries, cmaOnlyStatusRecord;
108
+ var options, pageContentTypes, pageEntriesPromise, statusRecordPromise, _a, pageEntries, cmaOnlyStatusRecord, homePages, allPages;
109
109
  return __generator(this, function (_b) {
110
110
  switch (_b.label) {
111
111
  case 0:
@@ -134,15 +134,21 @@ export var pageEntries = function (ctx, apiClient, cmaPreviewClientApi) { return
134
134
  ])];
135
135
  case 1:
136
136
  _a = __read.apply(void 0, [_b.sent(), 2]), pageEntries = _a[0], cmaOnlyStatusRecord = _a[1];
137
- return [2 /*return*/, arrayToMap(function (e) { return e.sys.id; })(function (entry) {
138
- var cmaOnlyStatus = ctx.contentfulClientType === "cma-client"
139
- ? entryStatus(entry.sys) || cmaOnlyStatusRecord.get(entry.sys.id)
140
- : undefined;
141
- if (cmaOnlyStatus) {
142
- entry.sys = __assign(__assign({}, entry.sys), { cmaOnlyStatus: cmaOnlyStatus });
143
- }
144
- return entry;
145
- })(pageEntries.flat())];
137
+ homePages = [];
138
+ allPages = new Map(pageEntries.flat().map(function (entry) {
139
+ var _a;
140
+ if ((_a = entry.metadata) === null || _a === void 0 ? void 0 : _a.tags.find(function (t) { return t.sys.id.startsWith(ctx.pageHomeTagId); })) {
141
+ homePages.push(entry);
142
+ }
143
+ var cmaOnlyStatus = ctx.contentfulClientType === "cma-client"
144
+ ? entryStatus(entry.sys) || cmaOnlyStatusRecord.get(entry.sys.id)
145
+ : undefined;
146
+ if (cmaOnlyStatus) {
147
+ entry.sys = __assign(__assign({}, entry.sys), { cmaOnlyStatus: cmaOnlyStatus });
148
+ }
149
+ return [entry.sys.id, entry];
150
+ }));
151
+ return [2 /*return*/, { allPages: allPages, homePages: homePages }];
146
152
  }
147
153
  });
148
154
  }); };
@@ -59,71 +59,73 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
59
59
  }
60
60
  return to.concat(ar || Array.prototype.slice.call(from));
61
61
  };
62
- import { mockedEntrySysId, multipleContentTypesMockedContentfulEntriesClientApi, } from './helpers/__mocks__/mocked-contentful-entries-client-api';
63
- import { pageEntries } from './page-entries';
62
+ import { mockedEntrySysId, multipleContentTypesMockedContentfulEntriesClientApi, } from "./helpers/__mocks__/mocked-contentful-entries-client-api";
63
+ import { pageEntries } from "./page-entries";
64
64
  var productTypesOptions = function (productTypesIds) {
65
65
  var seed = {};
66
66
  return productTypesIds.reduce(function (acc, ct) {
67
67
  acc[ct] = {
68
- slugFieldId: 'slug',
68
+ slugFieldId: "slug",
69
69
  };
70
70
  return acc;
71
71
  }, seed);
72
72
  };
73
73
  describe(pageEntries, function () {
74
- test('Handle case where there are no page entries', function () { return __awaiter(void 0, void 0, void 0, function () {
74
+ test("Handle case where there are no page entries", function () { return __awaiter(void 0, void 0, void 0, function () {
75
75
  var singleTestPageContentType, testPageContentTypes, entries1, entries2;
76
76
  return __generator(this, function (_a) {
77
77
  switch (_a.label) {
78
78
  case 0:
79
- singleTestPageContentType = ['page1ContentType'];
79
+ singleTestPageContentType = ["page1ContentType"];
80
80
  testPageContentTypes = __spreadArray(__spreadArray([], __read(singleTestPageContentType), false), [
81
- 'page2ContentType',
81
+ "page2ContentType",
82
82
  ], false);
83
83
  return [4 /*yield*/, pageEntries({
84
- contentfulClientType: 'cda-client',
84
+ contentfulClientType: "cda-client",
85
85
  options: {
86
86
  pageContentTypes: productTypesOptions(singleTestPageContentType),
87
87
  },
88
88
  preview: false,
89
+ pageHomeTagId: "homePage",
89
90
  }, multipleContentTypesMockedContentfulEntriesClientApi(singleTestPageContentType.map(function (contentType) { return ({
90
91
  contentType: contentType,
91
92
  total: 0,
92
93
  }); })))];
93
94
  case 1:
94
95
  entries1 = _a.sent();
95
- expect(entries1.size).toBe(0);
96
+ expect(entries1.allPages.size).toBe(0);
96
97
  return [4 /*yield*/, pageEntries({
97
- contentfulClientType: 'cda-client',
98
+ contentfulClientType: "cda-client",
98
99
  options: {
99
100
  pageContentTypes: productTypesOptions(testPageContentTypes),
100
101
  },
101
102
  preview: false,
103
+ pageHomeTagId: "homePage",
102
104
  }, multipleContentTypesMockedContentfulEntriesClientApi(testPageContentTypes.map(function (contentType) { return ({
103
105
  contentType: contentType,
104
106
  total: 0,
105
107
  }); })))];
106
108
  case 2:
107
109
  entries2 = _a.sent();
108
- expect(entries2.size).toBe(0);
110
+ expect(entries2.allPages.size).toBe(0);
109
111
  return [2 /*return*/];
110
112
  }
111
113
  });
112
114
  }); });
113
115
  describe(pageEntries, function () {
114
- test('Handle case where there are page entries', function () { return __awaiter(void 0, void 0, void 0, function () {
116
+ test("Handle case where there are page entries", function () { return __awaiter(void 0, void 0, void 0, function () {
115
117
  var singleTestPageContentType, testPageContentTypes, entries1, entries1Ids, expectedEntries1Ids, entries2, entries2Ids, expectedEntries2Ids;
116
118
  return __generator(this, function (_a) {
117
119
  switch (_a.label) {
118
120
  case 0:
119
121
  singleTestPageContentType = [
120
- { contentType: 'page1ContentType', total: 101 },
122
+ { contentType: "page1ContentType", total: 101 },
121
123
  ];
122
124
  testPageContentTypes = __spreadArray(__spreadArray([], __read(singleTestPageContentType), false), [
123
- { contentType: 'page2ContentType', total: 1001 },
125
+ { contentType: "page2ContentType", total: 1001 },
124
126
  ], false);
125
127
  return [4 /*yield*/, pageEntries({
126
- contentfulClientType: 'cda-client',
128
+ contentfulClientType: "cda-client",
127
129
  options: {
128
130
  pageContentTypes: productTypesOptions(singleTestPageContentType.map(function (_a) {
129
131
  var contentType = _a.contentType;
@@ -131,10 +133,11 @@ describe(pageEntries, function () {
131
133
  })),
132
134
  },
133
135
  preview: false,
136
+ pageHomeTagId: "homePage",
134
137
  }, multipleContentTypesMockedContentfulEntriesClientApi(singleTestPageContentType))];
135
138
  case 1:
136
139
  entries1 = _a.sent();
137
- entries1Ids = __spreadArray([], __read(entries1.values()), false).map(function (e) { return e.sys.id; });
140
+ entries1Ids = __spreadArray([], __read(entries1.allPages.values()), false).map(function (e) { return e.sys.id; });
138
141
  expectedEntries1Ids = singleTestPageContentType.flatMap(function (_a) {
139
142
  var total = _a.total, contentType = _a.contentType;
140
143
  return __spreadArray([], __read(Array(total).keys()), false).map(function (_, idx) {
@@ -143,7 +146,7 @@ describe(pageEntries, function () {
143
146
  });
144
147
  expect(entries1Ids).toEqual(expectedEntries1Ids);
145
148
  return [4 /*yield*/, pageEntries({
146
- contentfulClientType: 'cda-client',
149
+ contentfulClientType: "cda-client",
147
150
  options: {
148
151
  pageContentTypes: productTypesOptions(testPageContentTypes.map(function (_a) {
149
152
  var contentType = _a.contentType;
@@ -151,10 +154,11 @@ describe(pageEntries, function () {
151
154
  })),
152
155
  },
153
156
  preview: false,
157
+ pageHomeTagId: "homePage",
154
158
  }, multipleContentTypesMockedContentfulEntriesClientApi(testPageContentTypes))];
155
159
  case 2:
156
160
  entries2 = _a.sent();
157
- entries2Ids = __spreadArray([], __read(entries2.values()), false).map(function (e) { return e.sys.id; });
161
+ entries2Ids = __spreadArray([], __read(entries2.allPages.values()), false).map(function (e) { return e.sys.id; });
158
162
  expectedEntries2Ids = testPageContentTypes.flatMap(function (_a) {
159
163
  var total = _a.total, contentType = _a.contentType;
160
164
  return __spreadArray([], __read(Array(total).keys()), false).map(function (_, idx) {
@@ -70,15 +70,14 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
70
70
  }
71
71
  return to.concat(ar || Array.prototype.slice.call(from));
72
72
  };
73
- import { pageEntries } from './page-entries';
74
- import { left, right } from '../../utils/fp-utils';
75
- import { contentTypes } from './content-types';
76
- import { locales } from './locales';
77
- import { homePages } from './home-page';
78
- import { redirectEntries } from './redirect-entries';
79
- import { homePagesByTagId } from './helpers/home-pages-by-tag-id';
73
+ import { pageEntries } from "./page-entries";
74
+ import { left, right } from "../../utils/fp-utils";
75
+ import { contentTypes } from "./content-types";
76
+ import { locales } from "./locales";
77
+ import { redirectEntries } from "./redirect-entries";
78
+ import { homePagesByTagId, } from "./helpers/home-pages-by-tag-id";
80
79
  export var sitemapData = function (ctx) { return __awaiter(void 0, void 0, void 0, function () {
81
- var _a, pages, redirects, ct, l, hp, warnings, pagesByTagId;
80
+ var _a, pages, redirects, ct, l, warnings, pagesByTagId;
82
81
  return __generator(this, function (_b) {
83
82
  switch (_b.label) {
84
83
  case 0: return [4 /*yield*/, Promise.all([
@@ -86,20 +85,19 @@ export var sitemapData = function (ctx) { return __awaiter(void 0, void 0, void
86
85
  redirectEntries(ctx),
87
86
  contentTypes(ctx),
88
87
  locales(ctx),
89
- homePages(ctx, ctx.pageHomeTagId),
90
88
  ])];
91
89
  case 1:
92
- _a = __read.apply(void 0, [_b.sent(), 5]), pages = _a[0], redirects = _a[1], ct = _a[2], l = _a[3], hp = _a[4];
90
+ _a = __read.apply(void 0, [_b.sent(), 4]), pages = _a[0], redirects = _a[1], ct = _a[2], l = _a[3];
93
91
  warnings = [];
94
92
  ct.warnings && warnings.push.apply(warnings, __spreadArray([], __read(ct.warnings), false));
95
- if (l._tag === 'Left') {
93
+ if (l._tag === "Left") {
96
94
  return [2 /*return*/, left([l.left])];
97
95
  }
98
96
  else {
99
- pagesByTagId = homePagesByTagId(ctx, l.right, hp);
97
+ pagesByTagId = homePagesByTagId(ctx, l.right, pages.homePages);
100
98
  pagesByTagId.warnings && warnings.push.apply(warnings, __spreadArray([], __read(pagesByTagId.warnings), false));
101
99
  return [2 /*return*/, right({
102
- data: __assign(__assign({}, l.right), { homePagesByTagId: pagesByTagId.homePagesByTagId, contentTypes: ct.contentTypes, pages: pages, redirects: redirects }),
100
+ data: __assign(__assign({}, l.right), { homePagesByTagId: pagesByTagId.homePagesByTagId, contentTypes: ct.contentTypes, pages: pages.allPages, redirects: redirects }),
103
101
  warnings: warnings.length > 0 ? warnings : undefined,
104
102
  })];
105
103
  }
@@ -12,7 +12,7 @@ export var redirectEntryAdapter = function (data, pageField, pathField, typeFiel
12
12
  return pageSysId && path && (type === "redirect" || type === "alias")
13
13
  ? {
14
14
  page: { sys: { id: pageSysId } },
15
- path: parent.path + path,
15
+ path: parent.path + (path.startsWith("/") ? path : "/".concat(path)),
16
16
  title: title || undefined,
17
17
  metadata: entry.metadata,
18
18
  type: type,
@@ -7,5 +7,6 @@ export var redirectToArboretumPage = function (localeCode) {
7
7
  path: redirect.path,
8
8
  cmaOnlyStatus: redirect.sys.cmaOnlyStatus,
9
9
  title: redirect.title,
10
+ metadata: redirect.metadata
10
11
  }); };
11
12
  };
@@ -14,5 +14,6 @@ export var toArboretumPageWithMissingData = function (localeCode) {
14
14
  children: children,
15
15
  ancestors: ancestors,
16
16
  additionalFields: page.additionalFields,
17
+ metadata: page.metadata
17
18
  }); };
18
19
  };
@@ -69,6 +69,27 @@ var findPageFieldF = function (data, options, pageContentTypeId) {
69
69
  : undefined;
70
70
  };
71
71
  };
72
+ export var buildPage = function (data, options, childrenRefsByPageId, locale, parent, pageEntry) {
73
+ var _a;
74
+ var pageContentTypeConfig = options.pageContentTypes[pageEntry.sys.contentType.sys.id];
75
+ var findPageField = findPageFieldF(data, options, pageEntry.sys.contentType.sys.id);
76
+ var slugField = findPageField(pageContentTypeConfig.slugFieldId);
77
+ var titleField = pageContentTypeConfig.titleFieldId
78
+ ? findPageField(pageContentTypeConfig.titleFieldId)
79
+ : undefined;
80
+ var childPagesField = pageContentTypeConfig.childPagesFieldId
81
+ ? findPageField(pageContentTypeConfig.childPagesFieldId)
82
+ : undefined;
83
+ var fieldValue = localizeField(data, locale);
84
+ var childrenRefs = childrenRefsByPageId
85
+ ? childrenRefsByPageId.get(pageEntry.sys.id) || []
86
+ : childPagesField
87
+ ? ((_a = fieldValue(childPagesField.localized, pageEntry.fields[childPagesField.id])) === null || _a === void 0 ? void 0 : _a.flatMap(function (childPage) { var _a; return ((_a = childPage === null || childPage === void 0 ? void 0 : childPage.sys) === null || _a === void 0 ? void 0 : _a.id) ? [{ sys: { id: childPage === null || childPage === void 0 ? void 0 : childPage.sys.id } }] : []; })) || []
88
+ : [];
89
+ return slugField
90
+ ? pageEntryAdapter(data, options, slugField, titleField, childrenRefs, locale, parent, pageEntry)
91
+ : undefined;
92
+ };
72
93
  var getChildrenRefsByParentId = function (data, locale, options) {
73
94
  var pages = data.pages;
74
95
  var acc = new Map();
@@ -98,26 +119,8 @@ var getChildrenRefsByParentId = function (data, locale, options) {
98
119
  return acc;
99
120
  };
100
121
  var buildLocalizedSitemapArrRecursively = function (data, options, locale, parent, childrenRefsByPageId, pageEntry, acc) {
101
- var _a;
102
122
  var pages = data.pages;
103
- var pageContentTypeConfig = options.pageContentTypes[pageEntry.sys.contentType.sys.id];
104
- var findPageField = findPageFieldF(data, options, pageEntry.sys.contentType.sys.id);
105
- var slugField = findPageField(pageContentTypeConfig.slugFieldId);
106
- var titleField = pageContentTypeConfig.titleFieldId
107
- ? findPageField(pageContentTypeConfig.titleFieldId)
108
- : undefined;
109
- var childPagesField = pageContentTypeConfig.childPagesFieldId
110
- ? findPageField(pageContentTypeConfig.childPagesFieldId)
111
- : undefined;
112
- var fieldValue = localizeField(data, locale);
113
- var childrenRefs = childrenRefsByPageId
114
- ? childrenRefsByPageId.get(pageEntry.sys.id) || []
115
- : childPagesField
116
- ? ((_a = fieldValue(childPagesField.localized, pageEntry.fields[childPagesField.id])) === null || _a === void 0 ? void 0 : _a.flatMap(function (childPage) { var _a; return ((_a = childPage === null || childPage === void 0 ? void 0 : childPage.sys) === null || _a === void 0 ? void 0 : _a.id) ? [{ sys: { id: childPage === null || childPage === void 0 ? void 0 : childPage.sys.id } }] : []; })) || []
117
- : [];
118
- var page = slugField
119
- ? pageEntryAdapter(data, options, slugField, titleField, childrenRefs, locale, parent, pageEntry)
120
- : undefined;
123
+ var page = buildPage(data, options, childrenRefsByPageId, locale, parent, pageEntry);
121
124
  if (page) {
122
125
  var validChildPages_1 = page.childPages.filter(function (c) { return pages.get(c.sys.id) && !acc.get(c.sys.id); });
123
126
  var redirectChildPages = isRoot(page) && options.redirectContentType
@@ -148,7 +151,7 @@ export var buildLocalizedSitemap = function (data, options, pageHomeTagId, local
148
151
  var homePageRef = (_d = (_c = (_b = (_a = homePagesByTagId === null || homePagesByTagId === void 0 ? void 0 : homePagesByTagId.get(locale.code)) === null || _a === void 0 ? void 0 : _a.get(pageHomeTagId)) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.sys) === null || _d === void 0 ? void 0 : _d.id;
149
152
  var homePageEntry = homePageRef ? pages.get(homePageRef) : undefined;
150
153
  if (homePageEntry) {
151
- var childrenRefsByPageId = options.sitemapRepresentation === "child-to-parent"
154
+ var childrenRefsByPageId = options.pageRelations === "child-to-parent"
152
155
  ? getChildrenRefsByParentId(data, locale, options)
153
156
  : undefined;
154
157
  var sitemap = buildLocalizedSitemapArrRecursively(data, options, locale, undefined, childrenRefsByPageId, homePageEntry, new Map());
@@ -0,0 +1,97 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __read = (this && this.__read) || function (o, n) {
13
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
14
+ if (!m) return o;
15
+ var i = m.call(o), r, ar = [], e;
16
+ try {
17
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
18
+ }
19
+ catch (error) { e = { error: error }; }
20
+ finally {
21
+ try {
22
+ if (r && !r.done && (m = i["return"])) m.call(i);
23
+ }
24
+ finally { if (e) throw e.error; }
25
+ }
26
+ return ar;
27
+ };
28
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
29
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
30
+ if (ar || !(i in from)) {
31
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
32
+ ar[i] = from[i];
33
+ }
34
+ }
35
+ return to.concat(ar || Array.prototype.slice.call(from));
36
+ };
37
+ import { left, right } from "../../../utils/fp-utils";
38
+ import { buildPage, localizedSitemapFromCacheOrBuildEff, } from "../helpers/build-localized-sitemap";
39
+ import { toArboretumPage } from "../adapters/to-arboretum-page-adapter";
40
+ var singleOrAllLocalesE = function (locales) {
41
+ return function (localeCode) {
42
+ if (localeCode) {
43
+ var locale = locales.get(localeCode);
44
+ return locale
45
+ ? right([locale])
46
+ : left("Failed to find locale by code: ".concat(localeCode));
47
+ }
48
+ else {
49
+ return right(__spreadArray([], __read(locales.values()), false));
50
+ }
51
+ };
52
+ };
53
+ export var orphanedPages = function (ctx) {
54
+ return function (options) {
55
+ var localeCode = options === null || options === void 0 ? void 0 : options.localeCode;
56
+ var localesE = singleOrAllLocalesE(ctx.data.locales)(localeCode);
57
+ var skip = typeof (options === null || options === void 0 ? void 0 : options.skip) !== "undefined" ? options.skip : 0;
58
+ if (localesE._tag === "Right") {
59
+ var pages = localesE.right
60
+ .flatMap(function (locale) {
61
+ var localizedSitemapE = localizedSitemapFromCacheOrBuildEff(ctx, locale);
62
+ var pages = localizedSitemapE._tag === "Right"
63
+ ? __spreadArray([], __read(ctx.data.pages.values()), false).flatMap(function (p) {
64
+ var sitemapPage = localizedSitemapE.right.sitemap.get(p.sys.id);
65
+ if (sitemapPage) {
66
+ return [];
67
+ }
68
+ else {
69
+ var page = buildPage(ctx.data, ctx.options, undefined, locale, undefined, p);
70
+ var arboretumPage = page
71
+ ? toArboretumPage(localizedSitemapE.right, locale.code, {})(page)
72
+ : undefined;
73
+ return arboretumPage
74
+ ? [
75
+ __assign(__assign({}, arboretumPage), { path: undefined, totalDirectChildrenCount: undefined, ancestors: undefined, children: undefined }),
76
+ ]
77
+ : [];
78
+ }
79
+ })
80
+ : [];
81
+ return pages;
82
+ })
83
+ .sort(function (p1, p2) {
84
+ if (p1.id < p2.id)
85
+ return -1;
86
+ if (p1.id > p2.id)
87
+ return 1;
88
+ return 0;
89
+ })
90
+ .slice(skip, options === null || options === void 0 ? void 0 : options.limit);
91
+ return right(pages);
92
+ }
93
+ else {
94
+ return localesE;
95
+ }
96
+ };
97
+ };
@@ -0,0 +1,41 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { phraseSimilarity } from "../../../utils/phrase-similarity";
13
+ import { CONSTANTS } from "../../constants";
14
+ import { orphanedPages } from "./orphaned-pages";
15
+ var orphanedPagePhraseSimilarity = function (page, phrase) {
16
+ var slugSimilarity = phraseSimilarity(phrase, page.slug);
17
+ var idSimilarity = phraseSimilarity(phrase, page.id);
18
+ var titleSimilarity = page.title ? phraseSimilarity(phrase, page.title) : 0;
19
+ return Math.max(slugSimilarity, idSimilarity, titleSimilarity);
20
+ };
21
+ export var searchOrphanedPages = function (ctx) {
22
+ return function (phrase, localeCode, limit) {
23
+ var pages = orphanedPages(ctx)({ localeCode: localeCode });
24
+ if (pages._tag === "Right") {
25
+ return pages.right
26
+ .map(function (page) {
27
+ var searchScore = orphanedPagePhraseSimilarity(page, phrase);
28
+ return __assign(__assign({}, page), { searchScore: searchScore });
29
+ })
30
+ .filter(function (_a) {
31
+ var searchScore = _a.searchScore;
32
+ return searchScore >= CONSTANTS.search.minSearchScore;
33
+ })
34
+ .sort(function (a, b) { return b.searchScore - a.searchScore; })
35
+ .slice(0, limit);
36
+ }
37
+ else {
38
+ return [];
39
+ }
40
+ };
41
+ };