@bright.global/arboretum-sdk 0.0.8 → 0.1.0-rc.0
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/es6/impl/arboretum-client.impl.js +13 -13
- package/dist/es6/impl/data/page-entries.js +1 -0
- package/dist/es6/impl/sitemap/adapters/page-entry-adapter.js +6 -8
- package/dist/es6/impl/sitemap/adapters/to-arboretum-page-adapter.test.js +6 -0
- package/dist/es6/impl/sitemap/adapters/to-arboretum-page-with-missing-data-adapter.js +2 -1
- package/dist/es6/impl/sitemap/helpers/__mocks__/mocked-localized-sitemap.js +59 -58
- package/dist/es6/impl/sitemap/helpers/build-localized-sitemap.js +56 -12
- package/dist/es6/impl/sitemap/helpers/build-localized-sitemap.test.js +34 -34
- package/dist/impl/arboretum-client.impl.js +13 -13
- package/dist/impl/data/page-entries.js +1 -0
- package/dist/impl/sitemap/adapters/page-entry-adapter.js +5 -7
- package/dist/impl/sitemap/adapters/to-arboretum-page-adapter.test.js +6 -0
- package/dist/impl/sitemap/adapters/to-arboretum-page-with-missing-data-adapter.js +2 -1
- package/dist/impl/sitemap/helpers/__mocks__/mocked-localized-sitemap.js +59 -58
- package/dist/impl/sitemap/helpers/build-localized-sitemap.js +52 -8
- package/dist/impl/sitemap/helpers/build-localized-sitemap.test.js +30 -30
- package/dist/types/arboretum-client.d.ts +6 -3
- package/dist/types/impl/arboretum-client.impl.d.ts +1 -0
- package/dist/types/impl/sitemap/adapters/page-entry-adapter.d.ts +4 -4
- package/dist/types/impl/sitemap/adapters/to-arboretum-page-with-missing-data-adapter.d.ts +3 -3
- package/dist/types/impl/sitemap/helpers/__mocks__/mocked-localized-sitemap.d.ts +1 -1
- package/dist/types/impl/sitemap/helpers/build-localized-sitemap.d.ts +5 -5
- package/package.json +1 -1
|
@@ -111,9 +111,9 @@ var arboretumConfigOptions = function (config) {
|
|
|
111
111
|
};
|
|
112
112
|
var createArboretumClient = function (config) { return __awaiter(void 0, void 0, void 0, function () {
|
|
113
113
|
var clientApi, cmaPreviewClientApi, includeEntryStatus, options, sitemapDataCtx, dataE, _a, c, sitemap, pagesByTagIdRecord, ctx_1;
|
|
114
|
-
var _b, _c, _d, _e, _f, _g, _h;
|
|
115
|
-
return __generator(this, function (
|
|
116
|
-
switch (
|
|
114
|
+
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
115
|
+
return __generator(this, function (_k) {
|
|
116
|
+
switch (_k.label) {
|
|
117
117
|
case 0:
|
|
118
118
|
clientApi = (0, contentful_client_impl_1.createContentfulClient)(config);
|
|
119
119
|
cmaPreviewClientApi = config.type === "cma-client"
|
|
@@ -122,11 +122,11 @@ var createArboretumClient = function (config) { return __awaiter(void 0, void 0,
|
|
|
122
122
|
includeEntryStatus = config.type === "cma-client" ? !!((_b = config.options) === null || _b === void 0 ? void 0 : _b.includeEntryStatus) : false;
|
|
123
123
|
return [4 /*yield*/, arboretumConfigOptions(config)];
|
|
124
124
|
case 1:
|
|
125
|
-
options =
|
|
125
|
+
options = _k.sent();
|
|
126
126
|
sitemapDataCtx = {
|
|
127
127
|
preview: config.preview,
|
|
128
128
|
clientApi: clientApi,
|
|
129
|
-
options: __assign(__assign({}, options), { includeEntryStatus: includeEntryStatus }),
|
|
129
|
+
options: __assign(__assign({}, options), { includeEntryStatus: includeEntryStatus, sitemapRepresentation: (_c = config.options) === null || _c === void 0 ? void 0 : _c.sitemapRepresentation }),
|
|
130
130
|
localeTagIdPrefix: localeTagIdPrefix,
|
|
131
131
|
pageHomeTagId: options.homePageTagId || pageHomeTagId,
|
|
132
132
|
contentfulClientType: config.type === "cda-client" && config.contentful.client.withAllLocales
|
|
@@ -135,25 +135,25 @@ var createArboretumClient = function (config) { return __awaiter(void 0, void 0,
|
|
|
135
135
|
pageTagIdPrefix: pageTagIdPrefix,
|
|
136
136
|
cmaPreviewClientApi: cmaPreviewClientApi,
|
|
137
137
|
};
|
|
138
|
-
if (!((
|
|
139
|
-
_a = (0, fp_utils_1.right)({ data: (
|
|
138
|
+
if (!((_d = config.options) === null || _d === void 0 ? void 0 : _d.data)) return [3 /*break*/, 2];
|
|
139
|
+
_a = (0, fp_utils_1.right)({ data: (_e = config.options) === null || _e === void 0 ? void 0 : _e.data.data, warnings: undefined });
|
|
140
140
|
return [3 /*break*/, 4];
|
|
141
141
|
case 2: return [4 /*yield*/, (0, sitemap_data_1.sitemapData)(sitemapDataCtx)];
|
|
142
142
|
case 3:
|
|
143
|
-
_a =
|
|
144
|
-
|
|
143
|
+
_a = _k.sent();
|
|
144
|
+
_k.label = 4;
|
|
145
145
|
case 4:
|
|
146
146
|
dataE = _a;
|
|
147
147
|
if (dataE._tag === "Right") {
|
|
148
148
|
c = __assign(__assign({}, sitemapDataCtx), { data: dataE.right.data });
|
|
149
|
-
sitemap = ((
|
|
149
|
+
sitemap = ((_f = config.options) === null || _f === void 0 ? void 0 : _f.data)
|
|
150
150
|
? config.options.data.sitemap
|
|
151
|
-
: ((
|
|
151
|
+
: ((_g = config.options) === null || _g === void 0 ? void 0 : _g.eagerly)
|
|
152
152
|
? (0, build_sitemap_eagerly_1.buildSitemapEagerly)(c, dataE.right.data.locales)
|
|
153
153
|
: new Map();
|
|
154
|
-
pagesByTagIdRecord = ((
|
|
154
|
+
pagesByTagIdRecord = ((_h = config.options) === null || _h === void 0 ? void 0 : _h.data)
|
|
155
155
|
? config.options.data.pagesByTagId
|
|
156
|
-
: ((
|
|
156
|
+
: ((_j = config.options) === null || _j === void 0 ? void 0 : _j.eagerly)
|
|
157
157
|
? (0, build_pages_by_tag_eagerly_1.buildPagesByTagEagerly)(__assign(__assign({}, c), { sitemap: sitemap }), dataE.right.data.locales)
|
|
158
158
|
: new Map();
|
|
159
159
|
ctx_1 = __assign(__assign({}, c), { data: dataE.right.data, sitemap: sitemap, pagesByTagId: pagesByTagIdRecord, lastUpdatedAt: new Date().toISOString(), regenerationInProgress: false });
|
|
@@ -85,6 +85,7 @@ var getAllPageEntriesRecursively = function (_a, contentfulClientType, pageConte
|
|
|
85
85
|
pageContentTypeOpt.slugFieldId,
|
|
86
86
|
pageContentTypeOpt.childPagesFieldId,
|
|
87
87
|
pageContentTypeOpt.titleFieldId,
|
|
88
|
+
pageContentTypeOpt.parentPageFieldId,
|
|
88
89
|
].flatMap(function (id) { return (id ? ["fields.".concat(id)] : []); });
|
|
89
90
|
return [2 /*return*/, (0, get_all_entries_recursively_1.getAllEntriesRecursively)({ getEntries: getEntries }, contentfulClientType, pageContentTypeOpt.id, skip, acc,
|
|
90
91
|
/* For some reason select param causes errors in CMA. I'm getting the following response:
|
|
@@ -2,29 +2,27 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.pageEntryAdapter = void 0;
|
|
4
4
|
var localize_contentful_field_1 = require("../helpers/localize-contentful-field");
|
|
5
|
-
var pageEntryAdapter = function (data, slugField, titleField,
|
|
5
|
+
var pageEntryAdapter = function (data, slugField, titleField, childrenRefs, locale, parent, entry) {
|
|
6
6
|
var _a;
|
|
7
7
|
var fieldValue = (0, localize_contentful_field_1.localizeField)(data, locale);
|
|
8
8
|
var slug = (_a = fieldValue(slugField.localized, entry.fields[slugField.id])) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
9
9
|
var title = titleField
|
|
10
10
|
? fieldValue(titleField.localized, entry.fields[titleField.id])
|
|
11
11
|
: undefined;
|
|
12
|
-
var childPages = childPagesField
|
|
13
|
-
? fieldValue(childPagesField.localized, entry.fields[childPagesField.id])
|
|
14
|
-
: undefined;
|
|
15
12
|
return slug
|
|
16
13
|
? {
|
|
17
|
-
type:
|
|
14
|
+
type: "page",
|
|
18
15
|
parent: parent ? { sys: parent.sys } : undefined,
|
|
19
|
-
path: parent ? parent.path +
|
|
16
|
+
path: parent ? parent.path + "/" + slug : "/" + locale.code,
|
|
20
17
|
slug: slug,
|
|
21
18
|
title: title || undefined,
|
|
22
19
|
sys: {
|
|
23
20
|
id: entry.sys.id,
|
|
24
21
|
cmaOnlyStatus: entry.sys.cmaOnlyStatus,
|
|
22
|
+
contentTypeId: entry.sys.contentType.sys.id,
|
|
25
23
|
},
|
|
26
24
|
metadata: entry.metadata,
|
|
27
|
-
childPages: (
|
|
25
|
+
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 } }] : []; })) || [],
|
|
28
26
|
}
|
|
29
27
|
: undefined;
|
|
30
28
|
};
|
|
@@ -39,11 +39,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
var mocked_localized_sitemap_1 = require("../helpers/__mocks__/mocked-localized-sitemap");
|
|
40
40
|
var to_arboretum_page_adapter_1 = require("./to-arboretum-page-adapter");
|
|
41
41
|
var localeCode = 'en';
|
|
42
|
+
var contentTypeId = "page";
|
|
42
43
|
var toArboretumPageF = function (options) {
|
|
43
44
|
return (0, to_arboretum_page_adapter_1.toArboretumPage)(mocked_localized_sitemap_1.mockedLocalizedSitemap, localeCode, options);
|
|
44
45
|
};
|
|
45
46
|
var arboretumPageRoot = {
|
|
46
47
|
type: 'page',
|
|
48
|
+
contentTypeId: contentTypeId,
|
|
47
49
|
id: mocked_localized_sitemap_1.mockedRoot.sys.id,
|
|
48
50
|
localeCode: localeCode,
|
|
49
51
|
path: mocked_localized_sitemap_1.mockedRoot.path,
|
|
@@ -52,6 +54,7 @@ var arboretumPageRoot = {
|
|
|
52
54
|
};
|
|
53
55
|
var arboretumPagePage1 = {
|
|
54
56
|
id: mocked_localized_sitemap_1.mockedPage1.sys.id,
|
|
57
|
+
contentTypeId: contentTypeId,
|
|
55
58
|
localeCode: localeCode,
|
|
56
59
|
path: mocked_localized_sitemap_1.mockedPage1.path,
|
|
57
60
|
slug: mocked_localized_sitemap_1.mockedPage1.slug,
|
|
@@ -60,6 +63,7 @@ var arboretumPagePage1 = {
|
|
|
60
63
|
};
|
|
61
64
|
var arboretumPagePage1_1 = {
|
|
62
65
|
id: mocked_localized_sitemap_1.mockedPage1_1.sys.id,
|
|
66
|
+
contentTypeId: contentTypeId,
|
|
63
67
|
localeCode: localeCode,
|
|
64
68
|
path: mocked_localized_sitemap_1.mockedPage1_1.path,
|
|
65
69
|
slug: mocked_localized_sitemap_1.mockedPage1_1.slug,
|
|
@@ -68,6 +72,7 @@ var arboretumPagePage1_1 = {
|
|
|
68
72
|
};
|
|
69
73
|
var arboretumPage1_1_1 = {
|
|
70
74
|
id: mocked_localized_sitemap_1.mockedPage1_1_1.sys.id,
|
|
75
|
+
contentTypeId: contentTypeId,
|
|
71
76
|
localeCode: localeCode,
|
|
72
77
|
path: mocked_localized_sitemap_1.mockedPage1_1_1.path,
|
|
73
78
|
slug: mocked_localized_sitemap_1.mockedPage1_1_1.slug,
|
|
@@ -76,6 +81,7 @@ var arboretumPage1_1_1 = {
|
|
|
76
81
|
};
|
|
77
82
|
var arboretumPage1_1_2 = {
|
|
78
83
|
id: mocked_localized_sitemap_1.mockedPage1_1_2.sys.id,
|
|
84
|
+
contentTypeId: contentTypeId,
|
|
79
85
|
localeCode: localeCode,
|
|
80
86
|
path: mocked_localized_sitemap_1.mockedPage1_1_2.path,
|
|
81
87
|
slug: mocked_localized_sitemap_1.mockedPage1_1_2.slug,
|
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.toArboretumPageWithMissingData = void 0;
|
|
4
4
|
var toArboretumPageWithMissingData = function (localeCode) {
|
|
5
5
|
return function (page, ancestors, children) { return ({
|
|
6
|
-
type:
|
|
6
|
+
type: "page",
|
|
7
|
+
contentTypeId: page.sys.contentTypeId,
|
|
7
8
|
id: page.sys.id,
|
|
8
9
|
title: page.title,
|
|
9
10
|
cmaOnlyStatus: page.sys.cmaOnlyStatus,
|
|
@@ -26,24 +26,25 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
26
26
|
};
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
28
|
exports.mockedLocalizedSitemapWithCircularReference = exports.mockedCircularReferencesPages = exports.mockedPage1WithCircularReference = exports.mockedLocalizedSitemap = exports.mockedPages = exports.mockedRedirects = exports.mockedPage3 = exports.mockedPage2_1 = exports.mockedPage2 = exports.mockedPage1_1_2 = exports.mockedPage1_1_1 = exports.mockedPage1_2 = exports.mockedPage1_1 = exports.mockedPage1 = exports.mockedRoot = void 0;
|
|
29
|
-
var mockedRootSysId =
|
|
30
|
-
var mockedPage1SysId =
|
|
31
|
-
var mockedPage1_1SysId =
|
|
32
|
-
var mockedPage1_1_1SysId =
|
|
33
|
-
var mockedPage1_1_2SysId =
|
|
34
|
-
var mockedPage1_2SysId =
|
|
35
|
-
var mockedPage2SysId =
|
|
36
|
-
var mockedPage2_1SysId =
|
|
37
|
-
var mockedPage3SysId =
|
|
38
|
-
var mockedRedirect1SysId =
|
|
39
|
-
var mockedRedirect2SysId =
|
|
40
|
-
var mockedRedirect3SysId =
|
|
29
|
+
var mockedRootSysId = "root";
|
|
30
|
+
var mockedPage1SysId = "page1";
|
|
31
|
+
var mockedPage1_1SysId = "page1-1";
|
|
32
|
+
var mockedPage1_1_1SysId = "page1-1-1";
|
|
33
|
+
var mockedPage1_1_2SysId = "page1-1-2";
|
|
34
|
+
var mockedPage1_2SysId = "page1-2";
|
|
35
|
+
var mockedPage2SysId = "page2";
|
|
36
|
+
var mockedPage2_1SysId = "page2_1";
|
|
37
|
+
var mockedPage3SysId = "page3";
|
|
38
|
+
var mockedRedirect1SysId = "redirect1";
|
|
39
|
+
var mockedRedirect2SysId = "redirect2";
|
|
40
|
+
var mockedRedirect3SysId = "redirect3";
|
|
41
|
+
var contentTypeId = "page";
|
|
41
42
|
exports.mockedRoot = {
|
|
42
|
-
type:
|
|
43
|
-
sys: { id: mockedRootSysId },
|
|
43
|
+
type: "page",
|
|
44
|
+
sys: { id: mockedRootSysId, contentTypeId: contentTypeId },
|
|
44
45
|
parent: undefined,
|
|
45
46
|
slug: mockedRootSysId,
|
|
46
|
-
path:
|
|
47
|
+
path: "/en",
|
|
47
48
|
childPages: [
|
|
48
49
|
{ sys: { id: mockedPage1SysId } },
|
|
49
50
|
{ sys: { id: mockedPage2SysId } },
|
|
@@ -54,21 +55,21 @@ exports.mockedRoot = {
|
|
|
54
55
|
],
|
|
55
56
|
};
|
|
56
57
|
exports.mockedPage1 = {
|
|
57
|
-
type:
|
|
58
|
-
sys: { id: mockedPage1SysId },
|
|
59
|
-
parent: { sys: exports.mockedRoot.sys },
|
|
58
|
+
type: "page",
|
|
59
|
+
sys: { id: mockedPage1SysId, contentTypeId: contentTypeId },
|
|
60
|
+
parent: { sys: { id: exports.mockedRoot.sys.id } },
|
|
60
61
|
slug: mockedPage1SysId,
|
|
61
|
-
path: exports.mockedRoot.path +
|
|
62
|
+
path: exports.mockedRoot.path + "/" + mockedPage1SysId,
|
|
62
63
|
childPages: [
|
|
63
64
|
{ sys: { id: mockedPage1_1SysId } },
|
|
64
65
|
{ sys: { id: mockedPage1_2SysId } },
|
|
65
66
|
],
|
|
66
67
|
};
|
|
67
68
|
exports.mockedPage1_1 = {
|
|
68
|
-
type:
|
|
69
|
-
sys: { id: mockedPage1_1SysId },
|
|
70
|
-
parent: { sys: exports.mockedPage1.sys },
|
|
71
|
-
path: exports.mockedPage1.path +
|
|
69
|
+
type: "page",
|
|
70
|
+
sys: { id: mockedPage1_1SysId, contentTypeId: contentTypeId },
|
|
71
|
+
parent: { sys: { id: exports.mockedPage1.sys.id } },
|
|
72
|
+
path: exports.mockedPage1.path + "/" + mockedPage1_1SysId,
|
|
72
73
|
slug: mockedPage1_1SysId,
|
|
73
74
|
childPages: [
|
|
74
75
|
{ sys: { id: mockedPage1_1_1SysId } },
|
|
@@ -76,72 +77,72 @@ exports.mockedPage1_1 = {
|
|
|
76
77
|
],
|
|
77
78
|
};
|
|
78
79
|
exports.mockedPage1_2 = {
|
|
79
|
-
type:
|
|
80
|
-
sys: { id: mockedPage1_2SysId },
|
|
81
|
-
parent: { sys: exports.mockedPage1.sys },
|
|
82
|
-
path: exports.mockedPage1.path +
|
|
80
|
+
type: "page",
|
|
81
|
+
sys: { id: mockedPage1_2SysId, contentTypeId: contentTypeId },
|
|
82
|
+
parent: { sys: { id: exports.mockedPage1.sys.id } },
|
|
83
|
+
path: exports.mockedPage1.path + "/" + mockedPage1_2SysId,
|
|
83
84
|
slug: mockedPage1_2SysId,
|
|
84
85
|
childPages: [],
|
|
85
86
|
};
|
|
86
87
|
exports.mockedPage1_1_1 = {
|
|
87
|
-
type:
|
|
88
|
-
sys: { id: mockedPage1_1_1SysId },
|
|
89
|
-
parent: { sys: exports.mockedPage1_1.sys },
|
|
90
|
-
path: exports.mockedPage1_1.path +
|
|
88
|
+
type: "page",
|
|
89
|
+
sys: { id: mockedPage1_1_1SysId, contentTypeId: contentTypeId },
|
|
90
|
+
parent: { sys: { id: exports.mockedPage1_1.sys.id } },
|
|
91
|
+
path: exports.mockedPage1_1.path + "/" + mockedPage1_1_1SysId,
|
|
91
92
|
slug: mockedPage1_1_1SysId,
|
|
92
93
|
childPages: [],
|
|
93
94
|
};
|
|
94
95
|
exports.mockedPage1_1_2 = {
|
|
95
|
-
type:
|
|
96
|
-
sys: { id: mockedPage1_1_2SysId },
|
|
97
|
-
parent: { sys: exports.mockedPage1_1.sys },
|
|
98
|
-
path: exports.mockedPage1_1.path +
|
|
96
|
+
type: "page",
|
|
97
|
+
sys: { id: mockedPage1_1_2SysId, contentTypeId: contentTypeId },
|
|
98
|
+
parent: { sys: { id: exports.mockedPage1_1.sys.id } },
|
|
99
|
+
path: exports.mockedPage1_1.path + "/" + mockedPage1_1_2SysId,
|
|
99
100
|
slug: mockedPage1_1_2SysId,
|
|
100
101
|
childPages: [],
|
|
101
102
|
};
|
|
102
103
|
exports.mockedPage2 = {
|
|
103
|
-
type:
|
|
104
|
-
sys: { id: mockedPage2SysId },
|
|
105
|
-
parent: { sys: exports.mockedRoot.sys },
|
|
106
|
-
path: exports.mockedRoot.path +
|
|
104
|
+
type: "page",
|
|
105
|
+
sys: { id: mockedPage2SysId, contentTypeId: contentTypeId },
|
|
106
|
+
parent: { sys: { id: exports.mockedRoot.sys.id } },
|
|
107
|
+
path: exports.mockedRoot.path + "/" + mockedPage2SysId,
|
|
107
108
|
slug: mockedPage2SysId,
|
|
108
109
|
childPages: [{ sys: { id: mockedPage2_1SysId } }],
|
|
109
110
|
};
|
|
110
111
|
exports.mockedPage2_1 = {
|
|
111
|
-
type:
|
|
112
|
-
sys: { id: mockedPage2_1SysId },
|
|
113
|
-
parent: { sys: exports.mockedPage2.sys },
|
|
114
|
-
path: exports.mockedPage2.path +
|
|
112
|
+
type: "page",
|
|
113
|
+
sys: { id: mockedPage2_1SysId, contentTypeId: contentTypeId },
|
|
114
|
+
parent: { sys: { id: exports.mockedPage2.sys.id } },
|
|
115
|
+
path: exports.mockedPage2.path + "/" + mockedPage2_1SysId,
|
|
115
116
|
slug: mockedPage2_1SysId,
|
|
116
117
|
childPages: [],
|
|
117
118
|
};
|
|
118
119
|
exports.mockedPage3 = {
|
|
119
|
-
type:
|
|
120
|
-
sys: { id: mockedPage3SysId },
|
|
121
|
-
parent: { sys: exports.mockedRoot.sys },
|
|
122
|
-
path: exports.mockedRoot.path +
|
|
120
|
+
type: "page",
|
|
121
|
+
sys: { id: mockedPage3SysId, contentTypeId: contentTypeId },
|
|
122
|
+
parent: { sys: { id: exports.mockedRoot.sys.id } },
|
|
123
|
+
path: exports.mockedRoot.path + "/" + mockedPage3SysId,
|
|
123
124
|
slug: mockedPage3SysId,
|
|
124
125
|
childPages: [],
|
|
125
126
|
};
|
|
126
127
|
var mockedRedirect1 = {
|
|
127
|
-
type:
|
|
128
|
+
type: "alias",
|
|
128
129
|
sys: { id: mockedRedirect1SysId },
|
|
129
130
|
page: { sys: { id: mockedRedirect1SysId } },
|
|
130
|
-
path: exports.mockedRoot.path +
|
|
131
|
+
path: exports.mockedRoot.path + "/" + mockedRedirect1SysId,
|
|
131
132
|
parent: { sys: { id: exports.mockedRoot.sys.id } },
|
|
132
133
|
};
|
|
133
134
|
var mockedRedirect2 = {
|
|
134
|
-
type:
|
|
135
|
+
type: "redirect",
|
|
135
136
|
sys: { id: mockedRedirect2SysId },
|
|
136
137
|
page: { sys: { id: mockedRedirect2SysId } },
|
|
137
|
-
path: exports.mockedRoot.path +
|
|
138
|
+
path: exports.mockedRoot.path + "/" + mockedRedirect2SysId,
|
|
138
139
|
parent: { sys: { id: exports.mockedRoot.sys.id } },
|
|
139
140
|
};
|
|
140
141
|
var mockedRedirect3 = {
|
|
141
|
-
type:
|
|
142
|
+
type: "alias",
|
|
142
143
|
sys: { id: mockedRedirect3SysId },
|
|
143
144
|
page: { sys: { id: mockedRedirect3SysId } },
|
|
144
|
-
path: exports.mockedRoot.path +
|
|
145
|
+
path: exports.mockedRoot.path + "/" + mockedRedirect3SysId,
|
|
145
146
|
parent: { sys: { id: exports.mockedRoot.sys.id } },
|
|
146
147
|
};
|
|
147
148
|
exports.mockedRedirects = [
|
|
@@ -161,9 +162,9 @@ exports.mockedPages = __spreadArray([
|
|
|
161
162
|
exports.mockedPage3
|
|
162
163
|
], __read(exports.mockedRedirects), false);
|
|
163
164
|
exports.mockedLocalizedSitemap = {
|
|
164
|
-
root: { sys: exports.mockedRoot.sys },
|
|
165
|
+
root: { sys: { id: exports.mockedRoot.sys.id } },
|
|
165
166
|
sitemap: new Map(exports.mockedPages.map(function (page) {
|
|
166
|
-
if (!page.parent && page.type ===
|
|
167
|
+
if (!page.parent && page.type === "page") {
|
|
167
168
|
return [page.sys.id, page];
|
|
168
169
|
}
|
|
169
170
|
return [page.sys.id, page];
|
|
@@ -171,10 +172,10 @@ exports.mockedLocalizedSitemap = {
|
|
|
171
172
|
pageIdByPath: new Map(exports.mockedPages.map(function (page) { return [page.path, page.sys.id]; })),
|
|
172
173
|
};
|
|
173
174
|
exports.mockedPage1WithCircularReference = {
|
|
174
|
-
type:
|
|
175
|
-
sys: { id: mockedPage1SysId },
|
|
175
|
+
type: "page",
|
|
176
|
+
sys: { id: mockedPage1SysId, contentTypeId: contentTypeId },
|
|
176
177
|
parent: { sys: { id: exports.mockedRoot.sys.id } },
|
|
177
|
-
path: exports.mockedRoot.path +
|
|
178
|
+
path: exports.mockedRoot.path + "/" + mockedPage1SysId,
|
|
178
179
|
slug: mockedPage1SysId,
|
|
179
180
|
childPages: [{ sys: { id: mockedRootSysId } }],
|
|
180
181
|
};
|
|
@@ -41,6 +41,7 @@ var fp_utils_1 = require("../../../utils/fp-utils");
|
|
|
41
41
|
var page_entry_adapter_1 = require("../adapters/page-entry-adapter");
|
|
42
42
|
var redirect_entry_adapter_1 = require("../adapters/redirect-entry-adapter");
|
|
43
43
|
var is_root_1 = require("./is-root");
|
|
44
|
+
var localize_contentful_field_1 = require("./localize-contentful-field");
|
|
44
45
|
var getAllRedirects = function (data, options, locale, parent) {
|
|
45
46
|
var redirectContentType = options.id
|
|
46
47
|
? data.contentTypes.get(options.id)
|
|
@@ -61,15 +62,49 @@ var getAllRedirects = function (data, options, locale, parent) {
|
|
|
61
62
|
return redirect ? [redirect] : [];
|
|
62
63
|
});
|
|
63
64
|
};
|
|
64
|
-
var
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
var findPageFieldF = function (data, options, pageContentTypeId) {
|
|
66
|
+
return function (fieldId) {
|
|
67
|
+
var contentTypes = data.contentTypes;
|
|
68
|
+
var pageContentType = contentTypes.get(pageContentTypeId);
|
|
69
|
+
var pageContentTypeConfig = options.pageContentTypes[pageContentTypeId];
|
|
69
70
|
return pageContentType && pageContentTypeConfig
|
|
70
71
|
? pageContentType.fields.get(fieldId)
|
|
71
72
|
: undefined;
|
|
72
73
|
};
|
|
74
|
+
};
|
|
75
|
+
var getChildrenRefsByParentId = function (data, locale, options) {
|
|
76
|
+
var pages = data.pages;
|
|
77
|
+
var acc = new Map();
|
|
78
|
+
pages.forEach(function (page) {
|
|
79
|
+
var _a;
|
|
80
|
+
var pageContentTypeConfig = options.pageContentTypes[page.sys.contentType.sys.id];
|
|
81
|
+
var findPageField = findPageFieldF(data, options, page.sys.contentType.sys.id);
|
|
82
|
+
var parentPageField = pageContentTypeConfig.parentPageFieldId
|
|
83
|
+
? findPageField(pageContentTypeConfig.parentPageFieldId)
|
|
84
|
+
: undefined;
|
|
85
|
+
var fieldValue = (0, localize_contentful_field_1.localizeField)(data, locale);
|
|
86
|
+
var parentPage = parentPageField
|
|
87
|
+
? fieldValue(parentPageField.localized, page.fields[parentPageField.id])
|
|
88
|
+
: undefined;
|
|
89
|
+
var parentPageId = (_a = parentPage === null || parentPage === void 0 ? void 0 : parentPage.sys) === null || _a === void 0 ? void 0 : _a.id;
|
|
90
|
+
if (parentPageId) {
|
|
91
|
+
var pageRef = { sys: { id: page.sys.id } };
|
|
92
|
+
var maybePages = acc.get(parentPageId);
|
|
93
|
+
if (maybePages) {
|
|
94
|
+
maybePages.push(pageRef);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
acc.set(parentPageId, [pageRef]);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
return acc;
|
|
102
|
+
};
|
|
103
|
+
var buildLocalizedSitemapArrRecursively = function (data, options, locale, parent, childrenRefsByPageId, pageEntry, acc) {
|
|
104
|
+
var _a;
|
|
105
|
+
var pages = data.pages;
|
|
106
|
+
var pageContentTypeConfig = options.pageContentTypes[pageEntry.sys.contentType.sys.id];
|
|
107
|
+
var findPageField = findPageFieldF(data, options, pageEntry.sys.contentType.sys.id);
|
|
73
108
|
var slugField = findPageField(pageContentTypeConfig.slugFieldId);
|
|
74
109
|
var titleField = pageContentTypeConfig.titleFieldId
|
|
75
110
|
? findPageField(pageContentTypeConfig.titleFieldId)
|
|
@@ -77,8 +112,14 @@ var buildLocalizedSitemapArrRecursively = function (data, options, locale, paren
|
|
|
77
112
|
var childPagesField = pageContentTypeConfig.childPagesFieldId
|
|
78
113
|
? findPageField(pageContentTypeConfig.childPagesFieldId)
|
|
79
114
|
: undefined;
|
|
115
|
+
var fieldValue = (0, localize_contentful_field_1.localizeField)(data, locale);
|
|
116
|
+
var childrenRefs = childrenRefsByPageId
|
|
117
|
+
? childrenRefsByPageId.get(pageEntry.sys.id) || []
|
|
118
|
+
: childPagesField
|
|
119
|
+
? ((_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 } }] : []; })) || []
|
|
120
|
+
: [];
|
|
80
121
|
var page = slugField
|
|
81
|
-
? (0, page_entry_adapter_1.pageEntryAdapter)(data, slugField, titleField,
|
|
122
|
+
? (0, page_entry_adapter_1.pageEntryAdapter)(data, slugField, titleField, childrenRefs, locale, parent, pageEntry)
|
|
82
123
|
: undefined;
|
|
83
124
|
if (page) {
|
|
84
125
|
var validChildPages_1 = page.childPages.filter(function (c) { return pages.get(c.sys.id) && !acc.get(c.sys.id); });
|
|
@@ -96,7 +137,7 @@ var buildLocalizedSitemapArrRecursively = function (data, options, locale, paren
|
|
|
96
137
|
var id = _a.sys.id;
|
|
97
138
|
var childPageEntry = pages.get(id);
|
|
98
139
|
childPageEntry &&
|
|
99
|
-
buildLocalizedSitemapArrRecursively(data, options, locale, { sys: pageEntry.sys, path: page.path }, childPageEntry, acc);
|
|
140
|
+
buildLocalizedSitemapArrRecursively(data, options, locale, { sys: pageEntry.sys, path: page.path }, childrenRefsByPageId, childPageEntry, acc);
|
|
100
141
|
});
|
|
101
142
|
return acc;
|
|
102
143
|
}
|
|
@@ -110,7 +151,10 @@ var buildLocalizedSitemap = function (data, options, pageHomeTagId, locale) {
|
|
|
110
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;
|
|
111
152
|
var homePageEntry = homePageRef ? pages.get(homePageRef) : undefined;
|
|
112
153
|
if (homePageEntry) {
|
|
113
|
-
var
|
|
154
|
+
var childrenRefsByPageId = options.sitemapRepresentation === "child-to-parent"
|
|
155
|
+
? getChildrenRefsByParentId(data, locale, options)
|
|
156
|
+
: undefined;
|
|
157
|
+
var sitemap = buildLocalizedSitemapArrRecursively(data, options, locale, undefined, childrenRefsByPageId, homePageEntry, new Map());
|
|
114
158
|
return (0, fp_utils_1.right)({
|
|
115
159
|
root: { sys: homePageEntry.sys },
|
|
116
160
|
sitemap: sitemap,
|
|
@@ -17,18 +17,18 @@ var json_stringify_map_replacer_1 = require("../../../utils/json-stringify-map-r
|
|
|
17
17
|
var build_localized_sitemap_1 = require("./build-localized-sitemap");
|
|
18
18
|
var mocked_localized_sitemap_1 = require("./__mocks__/mocked-localized-sitemap");
|
|
19
19
|
var defaultLocale = {
|
|
20
|
-
code:
|
|
20
|
+
code: "en",
|
|
21
21
|
default: true,
|
|
22
22
|
fallbackCode: null,
|
|
23
|
-
name:
|
|
23
|
+
name: "English",
|
|
24
24
|
};
|
|
25
|
-
var pageContentTypeId =
|
|
26
|
-
var pageContentTypeSlugFieldId =
|
|
27
|
-
var pageContentTypeChildPagesFieldId =
|
|
28
|
-
var redirectContentTypeId =
|
|
29
|
-
var redirectContentTypePage =
|
|
30
|
-
var redirectContentTypePath =
|
|
31
|
-
var redirectContentTypeType =
|
|
25
|
+
var pageContentTypeId = "page";
|
|
26
|
+
var pageContentTypeSlugFieldId = "slug";
|
|
27
|
+
var pageContentTypeChildPagesFieldId = "childPages";
|
|
28
|
+
var redirectContentTypeId = "redirect";
|
|
29
|
+
var redirectContentTypePage = "page";
|
|
30
|
+
var redirectContentTypePath = "path";
|
|
31
|
+
var redirectContentTypeType = "type";
|
|
32
32
|
var contentTypes = new Map([
|
|
33
33
|
[
|
|
34
34
|
pageContentTypeId,
|
|
@@ -40,8 +40,8 @@ var contentTypes = new Map([
|
|
|
40
40
|
{
|
|
41
41
|
id: pageContentTypeSlugFieldId,
|
|
42
42
|
localized: true,
|
|
43
|
-
name:
|
|
44
|
-
type: "Symbol"
|
|
43
|
+
name: "Slug",
|
|
44
|
+
type: "Symbol",
|
|
45
45
|
},
|
|
46
46
|
],
|
|
47
47
|
[
|
|
@@ -49,8 +49,8 @@ var contentTypes = new Map([
|
|
|
49
49
|
{
|
|
50
50
|
id: pageContentTypeChildPagesFieldId,
|
|
51
51
|
localized: true,
|
|
52
|
-
name:
|
|
53
|
-
type: "Array"
|
|
52
|
+
name: "Child Pages",
|
|
53
|
+
type: "Array",
|
|
54
54
|
},
|
|
55
55
|
],
|
|
56
56
|
]),
|
|
@@ -66,8 +66,8 @@ var contentTypes = new Map([
|
|
|
66
66
|
{
|
|
67
67
|
id: redirectContentTypePage,
|
|
68
68
|
localized: true,
|
|
69
|
-
name:
|
|
70
|
-
type: "Link"
|
|
69
|
+
name: "Page",
|
|
70
|
+
type: "Link",
|
|
71
71
|
},
|
|
72
72
|
],
|
|
73
73
|
[
|
|
@@ -75,8 +75,8 @@ var contentTypes = new Map([
|
|
|
75
75
|
{
|
|
76
76
|
id: redirectContentTypePath,
|
|
77
77
|
localized: true,
|
|
78
|
-
name:
|
|
79
|
-
type: "Symbol"
|
|
78
|
+
name: "Path",
|
|
79
|
+
type: "Symbol",
|
|
80
80
|
},
|
|
81
81
|
],
|
|
82
82
|
[
|
|
@@ -84,8 +84,8 @@ var contentTypes = new Map([
|
|
|
84
84
|
{
|
|
85
85
|
id: redirectContentTypeType,
|
|
86
86
|
localized: true,
|
|
87
|
-
name:
|
|
88
|
-
type: "Symbol"
|
|
87
|
+
name: "Type",
|
|
88
|
+
type: "Symbol",
|
|
89
89
|
},
|
|
90
90
|
],
|
|
91
91
|
]),
|
|
@@ -142,7 +142,7 @@ var redirectToEntry = function (page, tagsIds) {
|
|
|
142
142
|
});
|
|
143
143
|
};
|
|
144
144
|
describe(build_localized_sitemap_1.buildLocalizedSitemap, function () {
|
|
145
|
-
test(
|
|
145
|
+
test("Not enough data to build sitemap", function () {
|
|
146
146
|
var emptyData = {
|
|
147
147
|
contentTypes: contentTypes,
|
|
148
148
|
defaultLocaleCode: defaultLocale.code,
|
|
@@ -151,17 +151,17 @@ describe(build_localized_sitemap_1.buildLocalizedSitemap, function () {
|
|
|
151
151
|
pages: new Map(),
|
|
152
152
|
redirects: [],
|
|
153
153
|
};
|
|
154
|
-
expect((0, build_localized_sitemap_1.buildLocalizedSitemap)(emptyData, { pageContentTypes: {} },
|
|
154
|
+
expect((0, build_localized_sitemap_1.buildLocalizedSitemap)(emptyData, { pageContentTypes: {} }, "pageHome", defaultLocale)._tag).toBe("Left");
|
|
155
155
|
});
|
|
156
|
-
test(
|
|
157
|
-
var pageHomeTagId =
|
|
156
|
+
test("Build localized sitemap", function () {
|
|
157
|
+
var pageHomeTagId = "pagHome";
|
|
158
158
|
var pagesEntries = mocked_localized_sitemap_1.mockedPages.flatMap(function (page) {
|
|
159
|
-
return page.type ===
|
|
160
|
-
? [pageToEntry(page, page.sys.id ===
|
|
159
|
+
return page.type === "page"
|
|
160
|
+
? [pageToEntry(page, page.sys.id === "root" ? [pageHomeTagId] : [])]
|
|
161
161
|
: [];
|
|
162
162
|
});
|
|
163
163
|
var redirectsEntries = mocked_localized_sitemap_1.mockedPages.flatMap(function (page) {
|
|
164
|
-
return page.type !==
|
|
164
|
+
return page.type !== "page" ? [redirectToEntry(page)] : [];
|
|
165
165
|
});
|
|
166
166
|
var data = {
|
|
167
167
|
contentTypes: contentTypes,
|
|
@@ -178,10 +178,10 @@ describe(build_localized_sitemap_1.buildLocalizedSitemap, function () {
|
|
|
178
178
|
};
|
|
179
179
|
expect(JSON.parse(JSON.stringify((0, build_localized_sitemap_1.buildLocalizedSitemap)(data, options, pageHomeTagId, defaultLocale), json_stringify_map_replacer_1.jsonStrigifyMapReplacer))).toMatchObject(JSON.parse(JSON.stringify((0, fp_utils_1.right)(mocked_localized_sitemap_1.mockedLocalizedSitemap), json_stringify_map_replacer_1.jsonStrigifyMapReplacer)));
|
|
180
180
|
});
|
|
181
|
-
test(
|
|
182
|
-
var pageHomeTagId =
|
|
181
|
+
test("Handle reference cycles", function () {
|
|
182
|
+
var pageHomeTagId = "pagHome";
|
|
183
183
|
var entries = mocked_localized_sitemap_1.mockedCircularReferencesPages.map(function (page) {
|
|
184
|
-
return pageToEntry(page, page.sys.id ===
|
|
184
|
+
return pageToEntry(page, page.sys.id === "root" ? [pageHomeTagId] : []);
|
|
185
185
|
});
|
|
186
186
|
var data = {
|
|
187
187
|
contentTypes: contentTypes,
|
|
@@ -197,7 +197,7 @@ describe(build_localized_sitemap_1.buildLocalizedSitemap, function () {
|
|
|
197
197
|
redirects: [],
|
|
198
198
|
};
|
|
199
199
|
var expectedLocalizedSitemap = (0, fp_utils_1.right)({
|
|
200
|
-
root: { sys: mocked_localized_sitemap_1.mockedRoot.sys },
|
|
200
|
+
root: { sys: { id: mocked_localized_sitemap_1.mockedRoot.sys.id } },
|
|
201
201
|
sitemap: new Map([
|
|
202
202
|
__assign(__assign({}, mocked_localized_sitemap_1.mockedRoot), { childPages: [
|
|
203
203
|
{ sys: { id: mocked_localized_sitemap_1.mockedPage1WithCircularReference.sys.id } },
|