@nascentdigital/funnel-editor-contentful 4.6.7 → 5.0.2

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 (129) hide show
  1. package/dist/Editor.d.ts +6 -1
  2. package/dist/Editor.js +17 -1
  3. package/dist/EditorApp.js +11 -9
  4. package/dist/EditorPageRouter.d.ts +1 -0
  5. package/dist/EditorPageRouter.js +40 -0
  6. package/dist/EntryEditor.js +43 -1
  7. package/dist/EntrySidebar.js +18 -1
  8. package/dist/asset/index.d.ts +1 -0
  9. package/dist/{page/hooks → asset}/index.js +1 -1
  10. package/dist/asset/repository/AssetRepository.d.ts +10 -0
  11. package/dist/asset/repository/AssetRepository.js +33 -0
  12. package/dist/asset/repository/index.d.ts +1 -0
  13. package/dist/{core/api → asset/repository}/index.js +1 -3
  14. package/dist/collection/controller/ContentfulCollectionController.d.ts +41 -0
  15. package/dist/collection/controller/ContentfulCollectionController.js +278 -0
  16. package/dist/collection/controller/ContentfulCollectionControllerContainer.d.ts +5 -0
  17. package/dist/collection/controller/ContentfulCollectionControllerContainer.js +28 -0
  18. package/dist/collection/controller/index.d.ts +3 -0
  19. package/dist/collection/controller/index.js +19 -0
  20. package/dist/collection/controller/useContentfulCollectionController.d.ts +2 -0
  21. package/dist/collection/controller/useContentfulCollectionController.js +8 -0
  22. package/dist/collection/domain/Collection.d.ts +108 -0
  23. package/dist/collection/domain/Collection.js +386 -0
  24. package/dist/collection/domain/index.d.ts +1 -0
  25. package/dist/collection/domain/index.js +17 -0
  26. package/dist/collection/index.d.ts +3 -0
  27. package/dist/collection/index.js +19 -0
  28. package/dist/collection/repository/CollectionRepository.d.ts +49 -0
  29. package/dist/collection/repository/CollectionRepository.js +210 -0
  30. package/dist/collection/repository/index.d.ts +1 -0
  31. package/dist/collection/repository/index.js +17 -0
  32. package/dist/collection/screens/CollectionEditor.d.ts +1 -0
  33. package/dist/collection/screens/CollectionEditor.js +59 -0
  34. package/dist/collection/screens/index.d.ts +1 -0
  35. package/dist/collection/screens/index.js +17 -0
  36. package/dist/core/bridge/AppBridgeContainer.d.ts +9 -0
  37. package/dist/core/bridge/AppBridgeContainer.js +55 -0
  38. package/dist/core/bridge/AppBridgeContext.d.ts +8 -0
  39. package/dist/core/bridge/AppBridgeContext.js +11 -0
  40. package/dist/core/bridge/AppMessage.d.ts +19 -0
  41. package/dist/core/bridge/AppMessage.js +19 -0
  42. package/dist/core/bridge/index.d.ts +4 -0
  43. package/dist/core/bridge/index.js +20 -0
  44. package/dist/core/bridge/useAppBridge.d.ts +8 -0
  45. package/dist/core/bridge/useAppBridge.js +24 -0
  46. package/dist/core/client/ContentfulClientContainer.d.ts +8 -0
  47. package/dist/core/client/ContentfulClientContainer.js +43 -0
  48. package/dist/core/client/ContentfulClientContext.d.ts +8 -0
  49. package/dist/core/client/ContentfulClientContext.js +8 -0
  50. package/dist/core/client/index.d.ts +3 -0
  51. package/dist/core/client/index.js +19 -0
  52. package/dist/core/client/useContentfulClient.d.ts +4 -0
  53. package/dist/core/client/useContentfulClient.js +24 -0
  54. package/dist/core/contentful/Contentful.d.ts +33 -0
  55. package/dist/core/contentful/Contentful.js +67 -0
  56. package/dist/core/contentful/ContentfulAsset.d.ts +23 -0
  57. package/dist/core/contentful/ContentfulAsset.js +89 -0
  58. package/dist/core/contentful/ContentfulCollection.d.ts +29 -0
  59. package/dist/core/contentful/ContentfulCollection.js +97 -0
  60. package/dist/core/contentful/ContentfulPage.d.ts +31 -0
  61. package/dist/core/contentful/ContentfulPage.js +84 -0
  62. package/dist/core/contentful/ContentfulRefs.d.ts +16 -0
  63. package/dist/core/contentful/ContentfulRefs.js +152 -0
  64. package/dist/core/contentful/index.d.ts +5 -0
  65. package/dist/core/contentful/index.js +21 -0
  66. package/dist/core/index.d.ts +3 -2
  67. package/dist/core/index.js +3 -2
  68. package/dist/core/repository/CollectionSerializer.d.ts +9 -0
  69. package/dist/core/repository/CollectionSerializer.js +41 -0
  70. package/dist/core/repository/LocalCollectionRepository.d.ts +27 -0
  71. package/dist/core/repository/LocalCollectionRepository.js +143 -0
  72. package/dist/core/repository/LocalPageRepository.d.ts +16 -0
  73. package/dist/core/repository/LocalPageRepository.js +153 -0
  74. package/dist/core/repository/PageSerializer.d.ts +3 -3
  75. package/dist/core/repository/PageSerializer.js +18 -14
  76. package/dist/core/repository/RemoteCollectionRepository.d.ts +19 -0
  77. package/dist/core/repository/RemoteCollectionRepository.js +236 -0
  78. package/dist/core/repository/RemotePageRepository.d.ts +14 -0
  79. package/dist/core/repository/RemotePageRepository.js +113 -0
  80. package/dist/core/repository/index.d.ts +4 -1
  81. package/dist/core/repository/index.js +4 -1
  82. package/dist/explore/components/Header.d.ts +26 -0
  83. package/dist/explore/components/Header.js +31 -0
  84. package/dist/explore/components/index.d.ts +1 -0
  85. package/dist/explore/components/index.js +17 -0
  86. package/dist/explore/index.d.ts +1 -0
  87. package/dist/explore/index.js +17 -0
  88. package/dist/explore/screens/Dashboard.d.ts +1 -0
  89. package/dist/explore/screens/Dashboard.js +22 -0
  90. package/dist/explore/screens/PageExplorer.d.ts +1 -0
  91. package/dist/explore/screens/PageExplorer.js +9 -0
  92. package/dist/explore/screens/SiteExplorer.d.ts +1 -0
  93. package/dist/explore/screens/SiteExplorer.js +24 -0
  94. package/dist/explore/screens/index.d.ts +3 -0
  95. package/dist/explore/screens/index.js +19 -0
  96. package/dist/page/{hooks/PageController.d.ts → controller/ContentfulPageController.d.ts} +17 -6
  97. package/dist/page/controller/ContentfulPageController.js +277 -0
  98. package/dist/page/controller/ContentfulPageControllerContainer.d.ts +5 -0
  99. package/dist/page/controller/ContentfulPageControllerContainer.js +28 -0
  100. package/dist/page/controller/index.d.ts +3 -0
  101. package/dist/page/controller/index.js +19 -0
  102. package/dist/page/controller/useContentfulPageController.d.ts +2 -0
  103. package/dist/page/controller/useContentfulPageController.js +8 -0
  104. package/dist/{core → page}/domain/Page.d.ts +71 -10
  105. package/dist/page/domain/Page.js +631 -0
  106. package/dist/page/index.d.ts +3 -0
  107. package/dist/page/index.js +3 -0
  108. package/dist/page/repository/PageRepository.d.ts +45 -0
  109. package/dist/page/repository/PageRepository.js +224 -0
  110. package/dist/page/repository/index.d.ts +1 -0
  111. package/dist/page/repository/index.js +17 -0
  112. package/dist/page/screens/PageEditor.js +29 -15
  113. package/package.json +10 -4
  114. package/dist/core/api/EditorApiClient.d.ts +0 -7
  115. package/dist/core/api/EditorApiClient.js +0 -29
  116. package/dist/core/api/EditorApiContainer.d.ts +0 -5
  117. package/dist/core/api/EditorApiContainer.js +0 -16
  118. package/dist/core/api/EditorApiContext.d.ts +0 -7
  119. package/dist/core/api/EditorApiContext.js +0 -6
  120. package/dist/core/api/index.d.ts +0 -3
  121. package/dist/core/api/useEditorApi.d.ts +0 -2
  122. package/dist/core/api/useEditorApi.js +0 -12
  123. package/dist/core/domain/Page.js +0 -180
  124. package/dist/core/repository/PageRepository.d.ts +0 -12
  125. package/dist/core/repository/PageRepository.js +0 -23
  126. package/dist/page/hooks/PageController.js +0 -107
  127. package/dist/page/hooks/index.d.ts +0 -1
  128. /package/dist/{core → page}/domain/index.d.ts +0 -0
  129. /package/dist/{core → page}/domain/index.js +0 -0
@@ -0,0 +1,33 @@
1
+ import type { BaseAppSDK } from '@contentful/app-sdk';
2
+ import { EntryAPI } from '@contentful/app-sdk/dist/types/entry.types';
3
+ import { QueryOptions } from 'contentful-management/dist/typings/common-types';
4
+ import { EntryProps } from 'contentful-management/dist/typings/entities/entry';
5
+ export declare namespace Contentful {
6
+ type Base = {
7
+ id: string;
8
+ createdOn: number;
9
+ updatedOn: number;
10
+ };
11
+ type LinkType = 'Asset' | 'Entry' | 'Upload';
12
+ type Link<TType extends LinkType = LinkType> = {
13
+ sys: {
14
+ type: 'Link';
15
+ linkType: TType;
16
+ id: string;
17
+ };
18
+ };
19
+ namespace Link {
20
+ type Asset = Link<'Asset'>;
21
+ type Entry = Link<'Entry'>;
22
+ }
23
+ function toLink(id: string, linkType: LinkType): Link;
24
+ type Fields<TData extends Record<string, any>> = {
25
+ [TKey in Exclude<keyof TData, keyof Base>]: {
26
+ [locale: string]: TData[TKey];
27
+ };
28
+ };
29
+ function allEntries<T = EntryProps>(sdk: BaseAppSDK, baseQuery?: QueryOptions): Promise<T[]>;
30
+ function allEntriesNormalized<T extends Base>(sdk: BaseAppSDK, baseQuery?: QueryOptions): Promise<T[]>;
31
+ function normalize<T extends Base>(entry: EntryAPI): T;
32
+ function normalizeRemote<T extends Base>({ sys, fields }: EntryProps, locale: string): T;
33
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Contentful = void 0;
4
+ var Contentful;
5
+ (function (Contentful) {
6
+ function toLink(id, linkType) {
7
+ return {
8
+ sys: {
9
+ type: 'Link',
10
+ linkType,
11
+ id
12
+ }
13
+ };
14
+ }
15
+ Contentful.toLink = toLink;
16
+ async function allEntries(sdk, baseQuery = {}) {
17
+ // setup
18
+ let skip = 0;
19
+ const limit = baseQuery.limit || 1000;
20
+ let total = 1;
21
+ const allItems = [];
22
+ // loop until no more pages
23
+ while (skip < total) {
24
+ const response = await sdk.cma.entry.getMany({
25
+ query: Object.assign(Object.assign({}, baseQuery), { limit,
26
+ skip })
27
+ });
28
+ total = response.total;
29
+ allItems.push(...response.items);
30
+ skip += limit;
31
+ }
32
+ // return
33
+ return allItems;
34
+ }
35
+ Contentful.allEntries = allEntries;
36
+ async function allEntriesNormalized(sdk, baseQuery = {}) {
37
+ // locale
38
+ const locale = sdk.locales.default;
39
+ // fetch items
40
+ const items = await allEntries(sdk, baseQuery);
41
+ // normalize
42
+ return items.map(item => normalizeRemote(item, locale));
43
+ }
44
+ Contentful.allEntriesNormalized = allEntriesNormalized;
45
+ function normalize(entry) {
46
+ // get sys
47
+ const sys = entry.getSys();
48
+ // simplify fields (remove locale)
49
+ const normalizedFields = {};
50
+ for (const key in entry.fields) {
51
+ normalizedFields[key] = entry.fields[key].getValue();
52
+ }
53
+ // return normalized form
54
+ return Object.assign({ id: sys.id, createdOn: new Date(sys.createdAt).getTime(), updatedOn: new Date(sys.updatedAt).getTime() }, normalizedFields);
55
+ }
56
+ Contentful.normalize = normalize;
57
+ function normalizeRemote({ sys, fields }, locale) {
58
+ // simplify fields (remove locale)
59
+ const normalizedFields = {};
60
+ for (const key in fields) {
61
+ normalizedFields[key] = fields[key][locale];
62
+ }
63
+ // return normalized form
64
+ return Object.assign({ id: sys.id, createdOn: new Date(sys.createdAt).getTime(), updatedOn: new Date(sys.updatedAt).getTime() }, normalizedFields);
65
+ }
66
+ Contentful.normalizeRemote = normalizeRemote;
67
+ })(Contentful || (exports.Contentful = Contentful = {}));
@@ -0,0 +1,23 @@
1
+ import { EditorAppSDK } from '@contentful/app-sdk';
2
+ import { Schema } from '@nascentdigital/funnel-core';
3
+ import { IAssetRepository } from '@nascentdigital/funnel-editor/components';
4
+ import type { EntryProps } from 'contentful-management/dist/typings/entities/entry';
5
+ import { Contentful } from './Contentful';
6
+ export type ContentfulAsset = Contentful.Base & {
7
+ name: string;
8
+ description?: string | null;
9
+ brand?: string | null;
10
+ type: string;
11
+ scope: string;
12
+ tags?: string[];
13
+ url: string;
14
+ size: number;
15
+ metadata: object;
16
+ media: Contentful.Link.Asset;
17
+ };
18
+ export declare namespace ContentfulAsset {
19
+ const contentTypeId: "asset";
20
+ type Remote = EntryProps<Contentful.Fields<ContentfulAsset>>;
21
+ function upload(args: IAssetRepository.UploadFile.Args, sdk: EditorAppSDK): Promise<Remote>;
22
+ function serialize(entry: Remote, locale: string): Schema.Asset.Linked;
23
+ }
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContentfulAsset = void 0;
4
+ // extension
5
+ var ContentfulAsset;
6
+ (function (ContentfulAsset) {
7
+ // consts
8
+ ContentfulAsset.contentTypeId = 'asset';
9
+ // helpers
10
+ async function upload(args, sdk) {
11
+ // setup
12
+ var _a, _b, _c;
13
+ // upload file
14
+ const uploadResult = await sdk.cma.upload.create({}, {
15
+ file: await args.file.arrayBuffer()
16
+ });
17
+ // create contentful asset
18
+ const locale = sdk.locales.default;
19
+ const contentfulAsset = await sdk.cma.asset.create({}, {
20
+ fields: {
21
+ title: { [locale]: args.name },
22
+ description: { [locale]: (_a = args.description) !== null && _a !== void 0 ? _a : '' },
23
+ file: {
24
+ [locale]: {
25
+ contentType: args.file.type,
26
+ fileName: args.name,
27
+ uploadFrom: {
28
+ sys: {
29
+ type: 'Link',
30
+ linkType: 'Upload',
31
+ id: uploadResult.sys.id
32
+ }
33
+ }
34
+ }
35
+ }
36
+ }
37
+ });
38
+ // process contentful asset (creates url etc.) and return
39
+ const processedAsset = await sdk.cma.asset.processForAllLocales({}, contentfulAsset);
40
+ // create funnel asset then return
41
+ return await sdk.cma.entry.create({ contentTypeId: ContentfulAsset.contentTypeId }, {
42
+ fields: {
43
+ name: { [locale]: args.name },
44
+ description: { [locale]: (_b = args.description) !== null && _b !== void 0 ? _b : null },
45
+ brand: { [locale]: (_c = args.brand) !== null && _c !== void 0 ? _c : null },
46
+ type: { [locale]: args.type },
47
+ scope: { [locale]: args.scope },
48
+ tags: { [locale]: args.tags },
49
+ url: { [locale]: 'https:' + processedAsset.fields.file[locale].url },
50
+ size: { [locale]: args.size },
51
+ metadata: { [locale]: args.metadata },
52
+ media: {
53
+ [locale]: {
54
+ sys: {
55
+ type: 'Link',
56
+ linkType: 'Asset',
57
+ id: processedAsset.sys.id
58
+ }
59
+ }
60
+ }
61
+ }
62
+ });
63
+ }
64
+ ContentfulAsset.upload = upload;
65
+ function serialize(entry, locale) {
66
+ var _a, _b;
67
+ console.debug('[ContentfulAsset] serializing asset', entry);
68
+ // extract fields
69
+ const { name, description, type, brand, metadata, scope, tags, url, size } = entry.fields;
70
+ // create asset
71
+ return {
72
+ __root: 'asset',
73
+ type: 'asset',
74
+ value: {
75
+ id: entry.sys.id,
76
+ name: name[locale],
77
+ description: description === null || description === void 0 ? void 0 : description[locale],
78
+ type: type[locale],
79
+ brand: (_a = brand === null || brand === void 0 ? void 0 : brand[locale]) !== null && _a !== void 0 ? _a : undefined,
80
+ metadata: metadata[locale],
81
+ scope: scope[locale],
82
+ tags: (_b = tags === null || tags === void 0 ? void 0 : tags[locale]) !== null && _b !== void 0 ? _b : [],
83
+ url: url[locale],
84
+ size: size[locale]
85
+ }
86
+ };
87
+ }
88
+ ContentfulAsset.serialize = serialize;
89
+ })(ContentfulAsset || (exports.ContentfulAsset = ContentfulAsset = {}));
@@ -0,0 +1,29 @@
1
+ import { EntryAPI } from '@contentful/app-sdk/dist/types/entry.types';
2
+ import { Schema } from '@nascentdigital/funnel-core';
3
+ import { EntryProps } from 'contentful-management/dist/typings/entities/entry';
4
+ import { Contentful } from './Contentful';
5
+ export type ContentfulCollection = Contentful.Base & {
6
+ groupId: string;
7
+ name: string;
8
+ type: string;
9
+ brand?: string;
10
+ language: string;
11
+ version: number;
12
+ tags?: string;
13
+ fields: object;
14
+ pageRefIds?: string;
15
+ state: string;
16
+ errors: boolean;
17
+ publishedOn?: number;
18
+ references?: Contentful.Link[];
19
+ };
20
+ export declare namespace ContentfulCollection {
21
+ const contentTypeId: "collection";
22
+ type Remote = EntryProps<Contentful.Fields<ContentfulCollection>>;
23
+ function serialize(entry: EntryAPI): Schema.Collection.Data;
24
+ function serializeRemoteRef(entry: Remote, locale: string): Schema.Collection.Data.AsRef;
25
+ function serializeRemote(entry: Remote, locale: string): Schema.Collection.Data;
26
+ function serializeRemoteWithRefs(entry: Remote, locale: string): Schema.Collection.FlattenedData;
27
+ function deserialize(data: Schema.Collection.Data): ContentfulCollection;
28
+ function deserializeLinks(collection: ContentfulCollection): Contentful.Link[];
29
+ }
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContentfulCollection = void 0;
4
+ const Contentful_1 = require("./Contentful");
5
+ const ContentfulRefs_1 = require("./ContentfulRefs");
6
+ // extension
7
+ var ContentfulCollection;
8
+ (function (ContentfulCollection) {
9
+ // consts
10
+ ContentfulCollection.contentTypeId = 'collection';
11
+ // helpers
12
+ function serialize(entry) {
13
+ // normalize
14
+ const normalized = Contentful_1.Contentful.normalize(entry);
15
+ // create collection data
16
+ return normalizedToData(normalized);
17
+ }
18
+ ContentfulCollection.serialize = serialize;
19
+ function serializeRemoteRef(entry, locale) {
20
+ // normalize
21
+ const normalized = Contentful_1.Contentful.normalizeRemote(entry, locale);
22
+ // return collection ref data
23
+ return normalizedToRef(normalized);
24
+ }
25
+ ContentfulCollection.serializeRemoteRef = serializeRemoteRef;
26
+ function serializeRemote(entry, locale) {
27
+ // normalize
28
+ const normalized = Contentful_1.Contentful.normalizeRemote(entry, locale);
29
+ // create collection data
30
+ return normalizedToData(normalized);
31
+ }
32
+ ContentfulCollection.serializeRemote = serializeRemote;
33
+ function serializeRemoteWithRefs(entry, locale) {
34
+ // normalize
35
+ const normalized = Contentful_1.Contentful.normalizeRemote(entry, locale);
36
+ // create collection flattened data
37
+ return normalizeToFlattened(normalized);
38
+ }
39
+ ContentfulCollection.serializeRemoteWithRefs = serializeRemoteWithRefs;
40
+ function deserialize(data) {
41
+ var _a;
42
+ return {
43
+ id: data.id,
44
+ groupId: data.groupId,
45
+ type: data.type,
46
+ version: data.version,
47
+ language: data.language,
48
+ state: data.state,
49
+ name: data.name,
50
+ fields: data.fields,
51
+ tags: JSON.stringify((_a = data.tags) !== null && _a !== void 0 ? _a : []),
52
+ errors: data.errors,
53
+ createdOn: data.createdOn,
54
+ updatedOn: data.updatedOn
55
+ };
56
+ }
57
+ ContentfulCollection.deserialize = deserialize;
58
+ function deserializeLinks(collection) {
59
+ const refs = ContentfulRefs_1.ContentfulRefs.find({ fields: collection.fields });
60
+ const entryIds = [
61
+ ...refs.assets.values(),
62
+ ...refs.pages.values(),
63
+ ...refs.collections.values()
64
+ ];
65
+ return entryIds.map(id => Contentful_1.Contentful.toLink(id, 'Entry'));
66
+ }
67
+ ContentfulCollection.deserializeLinks = deserializeLinks;
68
+ // private helpers
69
+ function normalizedToRef(data) {
70
+ var _a;
71
+ return {
72
+ id: data.id,
73
+ groupId: data.groupId,
74
+ version: data.version,
75
+ type: data.type,
76
+ brand: data.brand,
77
+ language: data.language,
78
+ state: data.state,
79
+ name: data.name,
80
+ tags: JSON.parse((_a = data.tags) !== null && _a !== void 0 ? _a : '[]'),
81
+ errors: data.errors,
82
+ createdOn: data.createdOn,
83
+ updatedOn: data.updatedOn,
84
+ publishedOn: data.publishedOn
85
+ };
86
+ }
87
+ function normalizedToData(data) {
88
+ return Object.assign(Object.assign({ __root: 'collection' }, normalizedToRef(data)), { fields: data.fields });
89
+ }
90
+ function normalizeToFlattened(data) {
91
+ return {
92
+ data: normalizedToData(data),
93
+ files: {},
94
+ collections: {}
95
+ };
96
+ }
97
+ })(ContentfulCollection || (exports.ContentfulCollection = ContentfulCollection = {}));
@@ -0,0 +1,31 @@
1
+ import { EntryAPI } from '@contentful/app-sdk/dist/types/entry.types';
2
+ import { Schema } from '@nascentdigital/funnel-core';
3
+ import { EntryProps } from 'contentful-management/dist/typings/entities/entry';
4
+ import { Contentful } from './Contentful';
5
+ export type ContentfulPage = Contentful.Base & {
6
+ groupId: string;
7
+ type: string;
8
+ name: string;
9
+ brand: string;
10
+ region: string;
11
+ language: string;
12
+ slug?: string;
13
+ tags: string;
14
+ url: string;
15
+ discover: object;
16
+ preview?: object;
17
+ content: object;
18
+ state: string;
19
+ errors: boolean;
20
+ publishedOn?: number;
21
+ publication?: number;
22
+ };
23
+ export declare namespace ContentfulPage {
24
+ const contentTypeId: "page";
25
+ type Remote = EntryProps<Contentful.Fields<ContentfulPage>>;
26
+ function serialize(entry: EntryAPI): Schema.Page.Data;
27
+ function serializeRemoteLink(entry: Remote, locale: string): Schema.Page.Data.AsLink;
28
+ function deserialize(data: Schema.Page.Data): ContentfulPage;
29
+ function deserializeLinks(page: ContentfulPage): Contentful.Link[];
30
+ function normalizedToLink(data: ContentfulPage): Schema.Page.Data.AsLink;
31
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContentfulPage = void 0;
4
+ const Contentful_1 = require("./Contentful");
5
+ const ContentfulRefs_1 = require("./ContentfulRefs");
6
+ // extension
7
+ var ContentfulPage;
8
+ (function (ContentfulPage) {
9
+ // consts
10
+ ContentfulPage.contentTypeId = 'page';
11
+ // helpers
12
+ function serialize(entry) {
13
+ // normalize entry
14
+ const normalized = Contentful_1.Contentful.normalize(entry);
15
+ // return data
16
+ return Object.assign(Object.assign({ __root: 'page' }, normalizedToLink(normalized)), { discover: normalized.discover, preview: normalized.preview, content: normalized.content });
17
+ }
18
+ ContentfulPage.serialize = serialize;
19
+ function serializeRemoteLink(entry, locale) {
20
+ // normalize entry
21
+ const normalized = Contentful_1.Contentful.normalizeRemote(entry, locale);
22
+ // return link data
23
+ return normalizedToLink(normalized);
24
+ }
25
+ ContentfulPage.serializeRemoteLink = serializeRemoteLink;
26
+ function deserialize(data) {
27
+ var _a;
28
+ return {
29
+ id: data.id,
30
+ createdOn: data.createdOn,
31
+ updatedOn: data.updatedOn,
32
+ name: data.name,
33
+ groupId: data.groupId,
34
+ type: data.type,
35
+ brand: data.brand,
36
+ region: data.region,
37
+ language: data.language,
38
+ slug: data.slug,
39
+ url: data.url,
40
+ tags: JSON.stringify((_a = data.tags) !== null && _a !== void 0 ? _a : []),
41
+ discover: data.discover,
42
+ preview: data.preview,
43
+ content: data.content,
44
+ errors: data.errors,
45
+ state: data.state,
46
+ publishedOn: data.publishedOn,
47
+ publication: data.publication
48
+ };
49
+ }
50
+ ContentfulPage.deserialize = deserialize;
51
+ function deserializeLinks(page) {
52
+ const refs = ContentfulRefs_1.ContentfulRefs.find({ content: page.content });
53
+ const entryIds = [
54
+ ...refs.assets.values(),
55
+ ...refs.pages.values(),
56
+ ...refs.collections.values()
57
+ ];
58
+ return entryIds.map(id => Contentful_1.Contentful.toLink(id, 'Entry'));
59
+ }
60
+ ContentfulPage.deserializeLinks = deserializeLinks;
61
+ // private helpers
62
+ function normalizedToLink(data) {
63
+ var _a;
64
+ return {
65
+ id: data.id,
66
+ groupId: data.groupId,
67
+ type: data.type,
68
+ brand: data.brand,
69
+ region: data.region,
70
+ language: data.language,
71
+ state: data.state,
72
+ name: data.name,
73
+ url: data.url,
74
+ slug: data.slug,
75
+ errors: data.errors,
76
+ publishedOn: data.publishedOn,
77
+ publication: data.publication,
78
+ tags: JSON.parse((_a = data.tags) !== null && _a !== void 0 ? _a : '[]'),
79
+ createdOn: data.createdOn,
80
+ updatedOn: data.updatedOn
81
+ };
82
+ }
83
+ ContentfulPage.normalizedToLink = normalizedToLink;
84
+ })(ContentfulPage || (exports.ContentfulPage = ContentfulPage = {}));
@@ -0,0 +1,16 @@
1
+ import { Schema } from '@nascentdigital/funnel-core';
2
+ import { Asset, IPage } from '@nascentdigital/funnel-editor/components';
3
+ import type { EntryReferenceProps } from 'contentful-management/dist/typings/entities/entry';
4
+ export declare namespace ContentfulRefs {
5
+ type Computed = {
6
+ assets: Set<Schema.Asset.Id>;
7
+ pages: Set<Schema.Page.Id>;
8
+ collections: Set<Schema.Collection.Id>;
9
+ };
10
+ function find(data: any): Computed;
11
+ function serialize(refs: EntryReferenceProps, locale: string): {
12
+ assets: Asset[];
13
+ pages: IPage.Ref[];
14
+ collections: Schema.Collection.Data.AsLink[];
15
+ };
16
+ }
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.ContentfulRefs = void 0;
15
+ const funnel_core_1 = require("@nascentdigital/funnel-core");
16
+ const components_1 = require("@nascentdigital/funnel-editor/components");
17
+ const ContentfulAsset_1 = require("./ContentfulAsset");
18
+ const ContentfulCollection_1 = require("./ContentfulCollection");
19
+ const ContentfulPage_1 = require("./ContentfulPage");
20
+ // namespace
21
+ var ContentfulRefs;
22
+ (function (ContentfulRefs) {
23
+ function find(data) {
24
+ // prepare sets
25
+ const assets = new Set();
26
+ const pages = new Set();
27
+ const collections = new Set();
28
+ // extract actual refs
29
+ funnel_core_1.ObjectUtils.walk(data, ({ value }) => {
30
+ // track assets
31
+ if (funnel_core_1.Schema.Asset.filter(value)) {
32
+ // track file (if it's real)
33
+ const assetId = funnel_core_1.Schema.Asset.getId(value);
34
+ if (assetId) {
35
+ assets.add(assetId);
36
+ }
37
+ // don't recurse
38
+ return false;
39
+ }
40
+ // track page links
41
+ else if (funnel_core_1.Schema.Field.Data.InternalLink.filter(value)) {
42
+ // track page (only if the id's real)
43
+ const pageId = funnel_core_1.Schema.Field.Data.InternalLink.getId(value);
44
+ if (pageId && pageId !== funnel_core_1.Schema.Page.Id.draft) {
45
+ pages.add(pageId);
46
+ }
47
+ // don't recurse
48
+ return false;
49
+ }
50
+ // transform collection refs
51
+ else if (funnel_core_1.Schema.Field.Data.Collection.Ref.filter(value)) {
52
+ // track collection (only if the id's real)
53
+ const collectionId = funnel_core_1.Schema.Field.Data.Collection.Ref.getId(value);
54
+ if (collectionId && collectionId !== funnel_core_1.Schema.Collection.Id.draft) {
55
+ collections.add(collectionId);
56
+ }
57
+ // don't recurse
58
+ return false;
59
+ }
60
+ // transform page refs
61
+ else if (funnel_core_1.Schema.Field.Data.Page.filter(value)) {
62
+ // track page (only if the id's real)
63
+ const pageId = funnel_core_1.Schema.Field.Data.Page.getId(value);
64
+ if (pageId && pageId !== funnel_core_1.Schema.Page.Id.draft) {
65
+ pages.add(pageId);
66
+ }
67
+ // don't recurse
68
+ return false;
69
+ }
70
+ // otherwise recurse deeper
71
+ else {
72
+ return true;
73
+ }
74
+ });
75
+ // return refs
76
+ return {
77
+ assets,
78
+ pages,
79
+ collections
80
+ };
81
+ }
82
+ ContentfulRefs.find = find;
83
+ function serialize(refs, locale) {
84
+ var _a, _b, _c, _d;
85
+ // create empty refs
86
+ const assets = [];
87
+ const pages = [];
88
+ const collections = [];
89
+ // loop over references and serialize
90
+ const { Entry: entries = [], Asset: files = [] } = (_a = refs.includes) !== null && _a !== void 0 ? _a : {};
91
+ for (const entry of entries) {
92
+ switch (entry.sys.contentType.sys.id) {
93
+ // asset
94
+ case ContentfulAsset_1.ContentfulAsset.contentTypeId: {
95
+ // try to find file
96
+ const fileId = entry.fields.media[locale].sys.id;
97
+ const file = files.find(file => file.sys.id === fileId);
98
+ if (!file) {
99
+ throw new funnel_core_1.NotFoundError(`cannot find Contentful media "${fileId}" for asset "${entry.sys.id}"`);
100
+ }
101
+ console.debug('[ContentfulRefs/serialize] parsing asset', { entry, file });
102
+ assets.push({
103
+ __root: 'asset',
104
+ type: 'asset',
105
+ value: {
106
+ id: entry.sys.id,
107
+ name: entry.fields.name[locale],
108
+ description: (_d = (_b = entry.fields.description[locale]) !== null && _b !== void 0 ? _b : (_c = file.fields.description) === null || _c === void 0 ? void 0 : _c[locale]) !== null && _d !== void 0 ? _d : undefined,
109
+ type: entry.fields.type[locale],
110
+ brand: entry.fields.brand[locale],
111
+ scope: entry.fields.scope[locale],
112
+ tags: [],
113
+ url: 'https:' + file.fields.file[locale].url,
114
+ size: entry.fields.size[locale],
115
+ metadata: entry.fields.metadata[locale]
116
+ }
117
+ });
118
+ break;
119
+ }
120
+ // page
121
+ case ContentfulPage_1.ContentfulPage.contentTypeId: {
122
+ // convert to link and get template
123
+ const pageEntry = entry;
124
+ const _e = ContentfulPage_1.ContentfulPage.serializeRemoteLink(pageEntry, locale), { type, tags } = _e, data = __rest(_e, ["type", "tags"]);
125
+ const template = funnel_core_1.Schema.Site.getPage(type, data.region);
126
+ // push link
127
+ pages.push(Object.assign({ template, tags: components_1.TagSerializer.deserializeTags({
128
+ groups: template.tags,
129
+ tagsData: tags
130
+ }) }, data));
131
+ break;
132
+ }
133
+ // collection
134
+ case ContentfulCollection_1.ContentfulCollection.contentTypeId: {
135
+ // convert to link and get template
136
+ const collectionEntry = entry;
137
+ const data = ContentfulCollection_1.ContentfulCollection.serializeRemote(collectionEntry, locale);
138
+ // push data
139
+ collections.push(data);
140
+ break;
141
+ }
142
+ }
143
+ }
144
+ // return
145
+ return {
146
+ assets,
147
+ pages,
148
+ collections
149
+ };
150
+ }
151
+ ContentfulRefs.serialize = serialize;
152
+ })(ContentfulRefs || (exports.ContentfulRefs = ContentfulRefs = {}));
@@ -0,0 +1,5 @@
1
+ export * from './Contentful';
2
+ export * from './ContentfulAsset';
3
+ export * from './ContentfulCollection';
4
+ export * from './ContentfulPage';
5
+ export * from './ContentfulRefs';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Contentful"), exports);
18
+ __exportStar(require("./ContentfulAsset"), exports);
19
+ __exportStar(require("./ContentfulCollection"), exports);
20
+ __exportStar(require("./ContentfulPage"), exports);
21
+ __exportStar(require("./ContentfulRefs"), exports);
@@ -1,3 +1,4 @@
1
- export * from './api';
2
- export * from './domain';
1
+ export * from './bridge';
2
+ export * from './client';
3
+ export * from './contentful';
3
4
  export * from './repository';
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./api"), exports);
18
- __exportStar(require("./domain"), exports);
17
+ __exportStar(require("./bridge"), exports);
18
+ __exportStar(require("./client"), exports);
19
+ __exportStar(require("./contentful"), exports);
19
20
  __exportStar(require("./repository"), exports);