@bright.global/arboretum-sdk 0.1.0-rc.0 → 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.
- package/dist/clients/contentful-client/impl/constants.js +5 -2
- package/dist/clients/contentful-client/impl/contentful-client-impl.js +11 -6
- package/dist/clients/contentful-client/impl/methods/contentful-fetch.js +2 -3
- package/dist/es6/clients/contentful-client/impl/constants.js +4 -1
- package/dist/es6/clients/contentful-client/impl/contentful-client-impl.js +11 -6
- package/dist/es6/clients/contentful-client/impl/methods/contentful-fetch.js +3 -4
- package/dist/es6/impl/arboretum-client.impl.js +6 -2
- package/dist/es6/impl/constants.js +5 -0
- package/dist/es6/impl/data/helpers/get-all-entries-recursively.js +21 -4
- package/dist/es6/impl/data/page-entries.js +25 -41
- package/dist/es6/impl/data/page-entries.test.js +21 -17
- package/dist/es6/impl/data/sitemap-data.js +11 -13
- package/dist/es6/impl/sitemap/adapters/page-entry-adapter.js +15 -2
- package/dist/es6/impl/sitemap/adapters/redirect-entry-adapter.js +1 -1
- package/dist/es6/impl/sitemap/adapters/redirect-to-arboretum-page-adapter.js +1 -0
- package/dist/es6/impl/sitemap/adapters/to-arboretum-page-with-missing-data-adapter.js +2 -0
- package/dist/es6/impl/sitemap/helpers/build-localized-sitemap.js +23 -20
- package/dist/es6/impl/sitemap/methods/orphaned-pages.js +97 -0
- package/dist/es6/impl/sitemap/methods/search-orphaned-pages.js +41 -0
- package/dist/es6/impl/sitemap/methods/search.js +43 -87
- package/dist/es6/utils/phrase-similarity.js +6 -0
- package/dist/es6/utils/string-similarity.js +1 -1
- package/dist/impl/arboretum-client.impl.js +6 -2
- package/dist/impl/constants.js +8 -0
- package/dist/impl/data/helpers/get-all-entries-recursively.js +21 -4
- package/dist/impl/data/page-entries.js +25 -41
- package/dist/impl/data/page-entries.test.js +19 -15
- package/dist/impl/data/sitemap-data.js +5 -7
- package/dist/impl/sitemap/adapters/page-entry-adapter.js +15 -2
- package/dist/impl/sitemap/adapters/redirect-entry-adapter.js +1 -1
- package/dist/impl/sitemap/adapters/redirect-to-arboretum-page-adapter.js +1 -0
- package/dist/impl/sitemap/adapters/to-arboretum-page-with-missing-data-adapter.js +2 -0
- package/dist/impl/sitemap/helpers/build-localized-sitemap.js +25 -21
- package/dist/impl/sitemap/methods/orphaned-pages.js +101 -0
- package/dist/impl/sitemap/methods/search-orphaned-pages.js +45 -0
- package/dist/impl/sitemap/methods/search.js +43 -87
- package/dist/types/arboretum-client.d.ts +27 -8
- package/dist/types/clients/contentful-client/impl/constants.d.ts +4 -1
- package/dist/types/impl/arboretum-client.impl.d.ts +3 -0
- package/dist/types/impl/constants.d.ts +5 -0
- package/dist/types/impl/data/page-entries.d.ts +5 -1
- package/dist/types/impl/data/sitemap-data.d.ts +8 -8
- package/dist/types/impl/sitemap/adapters/page-entry-adapter.d.ts +2 -2
- package/dist/types/impl/sitemap/helpers/build-localized-sitemap.d.ts +10 -2
- package/dist/types/impl/sitemap/methods/orphaned-pages.d.ts +3 -0
- package/dist/types/impl/sitemap/methods/search-orphaned-pages.d.ts +3 -0
- package/dist/types/impl/sitemap/methods/search.d.ts +3 -3
- package/dist/types/utils/phrase-similarity.d.ts +1 -0
- package/dist/utils/phrase-similarity.js +10 -0
- package/dist/utils/string-similarity.js +1 -1
- package/package.json +1 -1
- package/dist/es6/impl/data/home-page.js +0 -75
- package/dist/impl/data/home-page.js +0 -79
- 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.
|
|
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
|
|
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
|
|
34
|
-
?
|
|
35
|
-
|
|
36
|
-
|
|
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(
|
|
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 {
|
|
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
|
|
31
|
-
?
|
|
32
|
-
|
|
33
|
-
|
|
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,
|
|
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(
|
|
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,
|
|
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
|
}];
|
|
@@ -93,10 +93,27 @@ export var getAllEntriesRecursively = function (_a, contentfulClientType, conten
|
|
|
93
93
|
skip: skip,
|
|
94
94
|
content_type: contentType,
|
|
95
95
|
include: 0,
|
|
96
|
-
select:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
/* For some reason select param causes errors in CMA. I'm getting the following response:
|
|
97
|
+
{
|
|
98
|
+
"status": 400,
|
|
99
|
+
"statusText": "Bad Request",
|
|
100
|
+
"message": "The query you sent was invalid. Probably a filter or ordering specification is not applicable to the type of a field.",
|
|
101
|
+
"details": {
|
|
102
|
+
"errors": [
|
|
103
|
+
{
|
|
104
|
+
"name": "select",
|
|
105
|
+
"details": "Select is only applicable when querying a collection of entities."
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
},
|
|
109
|
+
"request": {
|
|
110
|
+
"url": "/spaces/8h4rcnu50txt/environments/dacjan-test/public/entries",
|
|
111
|
+
"method": "get",
|
|
112
|
+
...
|
|
113
|
+
},
|
|
114
|
+
}*/
|
|
115
|
+
select: contentfulClientType !== "cma-client" ? select : undefined,
|
|
116
|
+
locale: contentfulClientType === "cda-client-with-all-locales" ? undefined : "*",
|
|
100
117
|
})];
|
|
101
118
|
case 1:
|
|
102
119
|
items = (_b.sent()).items;
|
|
@@ -76,37 +76,8 @@ import { arrayToMap } from "../../utils/array-to-map";
|
|
|
76
76
|
var getAllPageEntriesRecursively = function (_a, contentfulClientType, pageContentTypeOpt, skip, acc, select) {
|
|
77
77
|
var getEntries = _a.getEntries;
|
|
78
78
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
79
|
-
var fieldsSelect;
|
|
80
79
|
return __generator(this, function (_b) {
|
|
81
|
-
|
|
82
|
-
pageContentTypeOpt.slugFieldId,
|
|
83
|
-
pageContentTypeOpt.childPagesFieldId,
|
|
84
|
-
pageContentTypeOpt.titleFieldId,
|
|
85
|
-
pageContentTypeOpt.parentPageFieldId,
|
|
86
|
-
].flatMap(function (id) { return (id ? ["fields.".concat(id)] : []); });
|
|
87
|
-
return [2 /*return*/, getAllEntriesRecursively({ getEntries: getEntries }, contentfulClientType, pageContentTypeOpt.id, skip, acc,
|
|
88
|
-
/* For some reason select param causes errors in CMA. I'm getting the following response:
|
|
89
|
-
{
|
|
90
|
-
"status": 400,
|
|
91
|
-
"statusText": "Bad Request",
|
|
92
|
-
"message": "The query you sent was invalid. Probably a filter or ordering specification is not applicable to the type of a field.",
|
|
93
|
-
"details": {
|
|
94
|
-
"errors": [
|
|
95
|
-
{
|
|
96
|
-
"name": "select",
|
|
97
|
-
"details": "Select is only applicable when querying a collection of entities."
|
|
98
|
-
}
|
|
99
|
-
]
|
|
100
|
-
},
|
|
101
|
-
"request": {
|
|
102
|
-
"url": "/spaces/8h4rcnu50txt/environments/dacjan-test/public/entries",
|
|
103
|
-
"method": "get",
|
|
104
|
-
...
|
|
105
|
-
},
|
|
106
|
-
}*/
|
|
107
|
-
select || contentfulClientType === "cma-client"
|
|
108
|
-
? undefined
|
|
109
|
-
: __spreadArray(["sys", "metadata"], __read(fieldsSelect), false).join(","), pageContentTypeOpt.childPagesFieldId
|
|
80
|
+
return [2 /*return*/, getAllEntriesRecursively({ getEntries: getEntries }, contentfulClientType, pageContentTypeOpt.id, skip, acc, select, pageContentTypeOpt.childPagesFieldId
|
|
110
81
|
? [pageContentTypeOpt.childPagesFieldId]
|
|
111
82
|
: [])];
|
|
112
83
|
});
|
|
@@ -134,7 +105,7 @@ var cmaOnlyEntriesStatusMap = function (_a, contentfulClientType, options) {
|
|
|
134
105
|
});
|
|
135
106
|
};
|
|
136
107
|
export var pageEntries = function (ctx, apiClient, cmaPreviewClientApi) { return __awaiter(void 0, void 0, void 0, function () {
|
|
137
|
-
var options, pageContentTypes, pageEntriesPromise, statusRecordPromise, _a, pageEntries, cmaOnlyStatusRecord;
|
|
108
|
+
var options, pageContentTypes, pageEntriesPromise, statusRecordPromise, _a, pageEntries, cmaOnlyStatusRecord, homePages, allPages;
|
|
138
109
|
return __generator(this, function (_b) {
|
|
139
110
|
switch (_b.label) {
|
|
140
111
|
case 0:
|
|
@@ -142,7 +113,14 @@ export var pageEntries = function (ctx, apiClient, cmaPreviewClientApi) { return
|
|
|
142
113
|
pageContentTypes = Object.entries(options.pageContentTypes);
|
|
143
114
|
pageEntriesPromise = Promise.all(pageContentTypes.map(function (_a) {
|
|
144
115
|
var _b = __read(_a, 2), id = _b[0], fieldIds = _b[1];
|
|
145
|
-
|
|
116
|
+
var fieldsSelect = __spreadArray([
|
|
117
|
+
fieldIds.slugFieldId,
|
|
118
|
+
fieldIds.childPagesFieldId,
|
|
119
|
+
fieldIds.titleFieldId,
|
|
120
|
+
fieldIds.parentPageFieldId
|
|
121
|
+
], __read((fieldIds.select || [])), false).flatMap(function (id) { return (id ? ["fields.".concat(id)] : []); });
|
|
122
|
+
var select = __spreadArray(["sys", "metadata"], __read(fieldsSelect), false).join(",");
|
|
123
|
+
return getAllPageEntriesRecursively(apiClient, ctx.contentfulClientType, __assign({ id: id }, fieldIds), 0, [], select);
|
|
146
124
|
}));
|
|
147
125
|
statusRecordPromise = ctx.options.includeEntryStatus &&
|
|
148
126
|
ctx.contentfulClientType === "cma-client" &&
|
|
@@ -156,15 +134,21 @@ export var pageEntries = function (ctx, apiClient, cmaPreviewClientApi) { return
|
|
|
156
134
|
])];
|
|
157
135
|
case 1:
|
|
158
136
|
_a = __read.apply(void 0, [_b.sent(), 2]), pageEntries = _a[0], cmaOnlyStatusRecord = _a[1];
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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 }];
|
|
168
152
|
}
|
|
169
153
|
});
|
|
170
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
|
|
63
|
-
import { pageEntries } from
|
|
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:
|
|
68
|
+
slugFieldId: "slug",
|
|
69
69
|
};
|
|
70
70
|
return acc;
|
|
71
71
|
}, seed);
|
|
72
72
|
};
|
|
73
73
|
describe(pageEntries, function () {
|
|
74
|
-
test(
|
|
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 = [
|
|
79
|
+
singleTestPageContentType = ["page1ContentType"];
|
|
80
80
|
testPageContentTypes = __spreadArray(__spreadArray([], __read(singleTestPageContentType), false), [
|
|
81
|
-
|
|
81
|
+
"page2ContentType",
|
|
82
82
|
], false);
|
|
83
83
|
return [4 /*yield*/, pageEntries({
|
|
84
|
-
contentfulClientType:
|
|
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:
|
|
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(
|
|
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:
|
|
122
|
+
{ contentType: "page1ContentType", total: 101 },
|
|
121
123
|
];
|
|
122
124
|
testPageContentTypes = __spreadArray(__spreadArray([], __read(singleTestPageContentType), false), [
|
|
123
|
-
{ contentType:
|
|
125
|
+
{ contentType: "page2ContentType", total: 1001 },
|
|
124
126
|
], false);
|
|
125
127
|
return [4 /*yield*/, pageEntries({
|
|
126
|
-
contentfulClientType:
|
|
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:
|
|
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
|
|
74
|
-
import { left, right } from
|
|
75
|
-
import { contentTypes } from
|
|
76
|
-
import { locales } from
|
|
77
|
-
import {
|
|
78
|
-
import {
|
|
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,
|
|
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(),
|
|
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 ===
|
|
93
|
+
if (l._tag === "Left") {
|
|
96
94
|
return [2 /*return*/, left([l.left])];
|
|
97
95
|
}
|
|
98
96
|
else {
|
|
99
|
-
pagesByTagId = homePagesByTagId(ctx, l.right,
|
|
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
|
}
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import { localizeField } from "../helpers/localize-contentful-field";
|
|
2
|
-
export var pageEntryAdapter = function (data, slugField, titleField, childrenRefs, locale, parent, entry) {
|
|
2
|
+
export var pageEntryAdapter = function (data, options, slugField, titleField, childrenRefs, locale, parent, entry) {
|
|
3
3
|
var _a;
|
|
4
4
|
var fieldValue = localizeField(data, locale);
|
|
5
5
|
var slug = (_a = fieldValue(slugField.localized, entry.fields[slugField.id])) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
6
6
|
var title = titleField
|
|
7
7
|
? fieldValue(titleField.localized, entry.fields[titleField.id])
|
|
8
8
|
: undefined;
|
|
9
|
+
var contentTypeId = entry.sys.contentType.sys.id;
|
|
10
|
+
var additionalFields = (options.pageContentTypes[contentTypeId].select || []).reduce(function (acc, fieldId) {
|
|
11
|
+
var contentType = data.contentTypes.get(contentTypeId);
|
|
12
|
+
if (contentType) {
|
|
13
|
+
var field = contentType.fields.get(fieldId);
|
|
14
|
+
var value = field
|
|
15
|
+
? fieldValue(field.localized, entry.fields[field.id])
|
|
16
|
+
: undefined;
|
|
17
|
+
acc[fieldId] = value;
|
|
18
|
+
}
|
|
19
|
+
return acc;
|
|
20
|
+
}, {});
|
|
9
21
|
return slug
|
|
10
22
|
? {
|
|
11
23
|
type: "page",
|
|
@@ -16,10 +28,11 @@ export var pageEntryAdapter = function (data, slugField, titleField, childrenRef
|
|
|
16
28
|
sys: {
|
|
17
29
|
id: entry.sys.id,
|
|
18
30
|
cmaOnlyStatus: entry.sys.cmaOnlyStatus,
|
|
19
|
-
contentTypeId:
|
|
31
|
+
contentTypeId: contentTypeId,
|
|
20
32
|
},
|
|
21
33
|
metadata: entry.metadata,
|
|
22
34
|
childPages: (childrenRefs === null || childrenRefs === void 0 ? void 0 : childrenRefs.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 } }] : []; })) || [],
|
|
35
|
+
additionalFields: additionalFields,
|
|
23
36
|
}
|
|
24
37
|
: undefined;
|
|
25
38
|
};
|
|
@@ -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,
|
|
@@ -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
|
|
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, 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.
|
|
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());
|