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

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.
@@ -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: select,
97
- locale: contentfulClientType === "cda-client-with-all-locales"
98
- ? undefined
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
- fieldsSelect = [
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
  });
@@ -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
- return getAllPageEntriesRecursively(apiClient, ctx.contentfulClientType, __assign({ id: id }, fieldIds), 0, []);
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" &&
@@ -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: entry.sys.contentType.sys.id,
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
  };
@@ -13,5 +13,6 @@ export var toArboretumPageWithMissingData = function (localeCode) {
13
13
  : page.childPages.length,
14
14
  children: children,
15
15
  ancestors: ancestors,
16
+ additionalFields: page.additionalFields,
16
17
  }); };
17
18
  };
@@ -116,7 +116,7 @@ var buildLocalizedSitemapArrRecursively = function (data, options, locale, paren
116
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
117
  : [];
118
118
  var page = slugField
119
- ? pageEntryAdapter(data, slugField, titleField, childrenRefs, locale, parent, pageEntry)
119
+ ? pageEntryAdapter(data, options, slugField, titleField, childrenRefs, locale, parent, pageEntry)
120
120
  : undefined;
121
121
  if (page) {
122
122
  var validChildPages_1 = page.childPages.filter(function (c) { return pages.get(c.sys.id) && !acc.get(c.sys.id); });
@@ -96,10 +96,27 @@ var getAllEntriesRecursively = function (_a, contentfulClientType, contentType,
96
96
  skip: skip,
97
97
  content_type: contentType,
98
98
  include: 0,
99
- select: select,
100
- locale: contentfulClientType === "cda-client-with-all-locales"
101
- ? undefined
102
- : "*",
99
+ /* For some reason select param causes errors in CMA. I'm getting the following response:
100
+ {
101
+ "status": 400,
102
+ "statusText": "Bad Request",
103
+ "message": "The query you sent was invalid. Probably a filter or ordering specification is not applicable to the type of a field.",
104
+ "details": {
105
+ "errors": [
106
+ {
107
+ "name": "select",
108
+ "details": "Select is only applicable when querying a collection of entities."
109
+ }
110
+ ]
111
+ },
112
+ "request": {
113
+ "url": "/spaces/8h4rcnu50txt/environments/dacjan-test/public/entries",
114
+ "method": "get",
115
+ ...
116
+ },
117
+ }*/
118
+ select: contentfulClientType !== "cma-client" ? select : undefined,
119
+ locale: contentfulClientType === "cda-client-with-all-locales" ? undefined : "*",
103
120
  })];
104
121
  case 1:
105
122
  items = (_b.sent()).items;
@@ -79,37 +79,8 @@ var array_to_map_1 = require("../../utils/array-to-map");
79
79
  var getAllPageEntriesRecursively = function (_a, contentfulClientType, pageContentTypeOpt, skip, acc, select) {
80
80
  var getEntries = _a.getEntries;
81
81
  return __awaiter(void 0, void 0, void 0, function () {
82
- var fieldsSelect;
83
82
  return __generator(this, function (_b) {
84
- fieldsSelect = [
85
- pageContentTypeOpt.slugFieldId,
86
- pageContentTypeOpt.childPagesFieldId,
87
- pageContentTypeOpt.titleFieldId,
88
- pageContentTypeOpt.parentPageFieldId,
89
- ].flatMap(function (id) { return (id ? ["fields.".concat(id)] : []); });
90
- return [2 /*return*/, (0, get_all_entries_recursively_1.getAllEntriesRecursively)({ getEntries: getEntries }, contentfulClientType, pageContentTypeOpt.id, skip, acc,
91
- /* For some reason select param causes errors in CMA. I'm getting the following response:
92
- {
93
- "status": 400,
94
- "statusText": "Bad Request",
95
- "message": "The query you sent was invalid. Probably a filter or ordering specification is not applicable to the type of a field.",
96
- "details": {
97
- "errors": [
98
- {
99
- "name": "select",
100
- "details": "Select is only applicable when querying a collection of entities."
101
- }
102
- ]
103
- },
104
- "request": {
105
- "url": "/spaces/8h4rcnu50txt/environments/dacjan-test/public/entries",
106
- "method": "get",
107
- ...
108
- },
109
- }*/
110
- select || contentfulClientType === "cma-client"
111
- ? undefined
112
- : __spreadArray(["sys", "metadata"], __read(fieldsSelect), false).join(","), pageContentTypeOpt.childPagesFieldId
83
+ return [2 /*return*/, (0, get_all_entries_recursively_1.getAllEntriesRecursively)({ getEntries: getEntries }, contentfulClientType, pageContentTypeOpt.id, skip, acc, select, pageContentTypeOpt.childPagesFieldId
113
84
  ? [pageContentTypeOpt.childPagesFieldId]
114
85
  : [])];
115
86
  });
@@ -145,7 +116,14 @@ var pageEntries = function (ctx, apiClient, cmaPreviewClientApi) { return __awai
145
116
  pageContentTypes = Object.entries(options.pageContentTypes);
146
117
  pageEntriesPromise = Promise.all(pageContentTypes.map(function (_a) {
147
118
  var _b = __read(_a, 2), id = _b[0], fieldIds = _b[1];
148
- return getAllPageEntriesRecursively(apiClient, ctx.contentfulClientType, __assign({ id: id }, fieldIds), 0, []);
119
+ var fieldsSelect = __spreadArray([
120
+ fieldIds.slugFieldId,
121
+ fieldIds.childPagesFieldId,
122
+ fieldIds.titleFieldId,
123
+ fieldIds.parentPageFieldId
124
+ ], __read((fieldIds.select || [])), false).flatMap(function (id) { return (id ? ["fields.".concat(id)] : []); });
125
+ var select = __spreadArray(["sys", "metadata"], __read(fieldsSelect), false).join(",");
126
+ return getAllPageEntriesRecursively(apiClient, ctx.contentfulClientType, __assign({ id: id }, fieldIds), 0, [], select);
149
127
  }));
150
128
  statusRecordPromise = ctx.options.includeEntryStatus &&
151
129
  ctx.contentfulClientType === "cma-client" &&
@@ -2,13 +2,25 @@
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, childrenRefs, locale, parent, entry) {
5
+ var pageEntryAdapter = function (data, options, 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 contentTypeId = entry.sys.contentType.sys.id;
13
+ var additionalFields = (options.pageContentTypes[contentTypeId].select || []).reduce(function (acc, fieldId) {
14
+ var contentType = data.contentTypes.get(contentTypeId);
15
+ if (contentType) {
16
+ var field = contentType.fields.get(fieldId);
17
+ var value = field
18
+ ? fieldValue(field.localized, entry.fields[field.id])
19
+ : undefined;
20
+ acc[fieldId] = value;
21
+ }
22
+ return acc;
23
+ }, {});
12
24
  return slug
13
25
  ? {
14
26
  type: "page",
@@ -19,10 +31,11 @@ var pageEntryAdapter = function (data, slugField, titleField, childrenRefs, loca
19
31
  sys: {
20
32
  id: entry.sys.id,
21
33
  cmaOnlyStatus: entry.sys.cmaOnlyStatus,
22
- contentTypeId: entry.sys.contentType.sys.id,
34
+ contentTypeId: contentTypeId,
23
35
  },
24
36
  metadata: entry.metadata,
25
37
  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 } }] : []; })) || [],
38
+ additionalFields: additionalFields,
26
39
  }
27
40
  : undefined;
28
41
  };
@@ -16,6 +16,7 @@ var toArboretumPageWithMissingData = function (localeCode) {
16
16
  : page.childPages.length,
17
17
  children: children,
18
18
  ancestors: ancestors,
19
+ additionalFields: page.additionalFields,
19
20
  }); };
20
21
  };
21
22
  exports.toArboretumPageWithMissingData = toArboretumPageWithMissingData;
@@ -119,7 +119,7 @@ var buildLocalizedSitemapArrRecursively = function (data, options, locale, paren
119
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
120
  : [];
121
121
  var page = slugField
122
- ? (0, page_entry_adapter_1.pageEntryAdapter)(data, slugField, titleField, childrenRefs, locale, parent, pageEntry)
122
+ ? (0, page_entry_adapter_1.pageEntryAdapter)(data, options, slugField, titleField, childrenRefs, locale, parent, pageEntry)
123
123
  : undefined;
124
124
  if (page) {
125
125
  var validChildPages_1 = page.childPages.filter(function (c) { return pages.get(c.sys.id) && !acc.get(c.sys.id); });
@@ -14,6 +14,7 @@ export type ArboretumClientContentfulConfigOptionsT = {
14
14
  titleFieldId?: string;
15
15
  childPagesFieldId?: string;
16
16
  parentPageFieldId?: string;
17
+ select?: Array<string>;
17
18
  };
18
19
  };
19
20
  redirectContentType?: {
@@ -103,6 +104,9 @@ export type ArboretumPageT = ArboretumPageBaseT & {
103
104
  totalDirectChildrenCount: number;
104
105
  children?: Array<ArboretumPageNodeT>;
105
106
  ancestors?: Array<Omit<ArboretumPageT, "children" | "ancestors">>;
107
+ additionalFields?: {
108
+ [key: string]: any;
109
+ };
106
110
  };
107
111
  export type ArboretumPageNodeT = ArboretumPageT | ArboretumRedirectT | ArboretumAliasT;
108
112
  export type OptionsT = {
@@ -32,6 +32,9 @@ export type PageT = {
32
32
  id: string;
33
33
  };
34
34
  }>;
35
+ additionalFields?: {
36
+ [key: string]: any;
37
+ };
35
38
  };
36
39
  export type RedirectT = {
37
40
  sys: {
@@ -1,6 +1,6 @@
1
- import { PageT } from "../../arboretum-client.impl";
1
+ import { ArboretumClientCtx, PageT } from "../../arboretum-client.impl";
2
2
  import { ContentTypeT, EntryT, LocaleT } from "../../../clients/contentful-client/contentful-client";
3
3
  import { SitemapDataT } from "../../data/sitemap-data";
4
- export declare const pageEntryAdapter: (data: Pick<SitemapDataT, "locales" | "defaultLocaleCode" | "pages">, slugField: ContentTypeT["fields"][number], titleField: ContentTypeT["fields"][number] | undefined, childrenRefs: PageT["childPages"], locale: LocaleT, parent: (NonNullable<PageT["parent"]> & {
4
+ export declare const pageEntryAdapter: (data: Pick<SitemapDataT, "locales" | "defaultLocaleCode" | "pages" | "contentTypes">, options: Pick<ArboretumClientCtx["options"], "pageContentTypes">, slugField: ContentTypeT["fields"][number], titleField: ContentTypeT["fields"][number] | undefined, childrenRefs: PageT["childPages"], locale: LocaleT, parent: (NonNullable<PageT["parent"]> & {
5
5
  path: string;
6
6
  }) | undefined, entry: EntryT) => PageT | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bright.global/arboretum-sdk",
3
- "version": "0.1.0-rc.0",
3
+ "version": "0.1.0-rc.1",
4
4
  "license": "MIT",
5
5
  "description": "The sitemap for contentful",
6
6
  "dependencies": {},