@nascentdigital/funnel-editor-contentful 4.6.7 → 5.0.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.
Files changed (85) hide show
  1. package/dist/Editor.d.ts +6 -1
  2. package/dist/Editor.js +17 -1
  3. package/dist/EditorApp.js +1 -1
  4. package/dist/EntryEditor.js +42 -1
  5. package/dist/EntrySidebar.js +18 -1
  6. package/dist/collection/controller/LocalCollectionController.d.ts +35 -0
  7. package/dist/collection/controller/LocalCollectionController.js +200 -0
  8. package/dist/collection/controller/LocalCollectionControllerContainer.d.ts +8 -0
  9. package/dist/collection/controller/LocalCollectionControllerContainer.js +36 -0
  10. package/dist/collection/controller/LocalCollectionControllerContext.d.ts +7 -0
  11. package/dist/collection/controller/LocalCollectionControllerContext.js +6 -0
  12. package/dist/collection/controller/index.d.ts +4 -0
  13. package/dist/collection/controller/index.js +20 -0
  14. package/dist/collection/controller/useLocalCollectionController.d.ts +2 -0
  15. package/dist/collection/controller/useLocalCollectionController.js +10 -0
  16. package/dist/collection/index.d.ts +2 -0
  17. package/dist/collection/index.js +18 -0
  18. package/dist/collection/screens/CollectionEditor.d.ts +1 -0
  19. package/dist/collection/screens/CollectionEditor.js +42 -0
  20. package/dist/collection/screens/index.d.ts +1 -0
  21. package/dist/{page/hooks → collection/screens}/index.js +1 -1
  22. package/dist/core/bridge/AppBridgeContainer.d.ts +9 -0
  23. package/dist/core/bridge/AppBridgeContainer.js +55 -0
  24. package/dist/core/bridge/AppBridgeContext.d.ts +8 -0
  25. package/dist/core/bridge/AppBridgeContext.js +11 -0
  26. package/dist/core/bridge/AppMessage.d.ts +19 -0
  27. package/dist/core/bridge/AppMessage.js +19 -0
  28. package/dist/core/bridge/index.d.ts +4 -0
  29. package/dist/core/bridge/index.js +20 -0
  30. package/dist/core/bridge/useAppBridge.d.ts +8 -0
  31. package/dist/core/bridge/useAppBridge.js +24 -0
  32. package/dist/core/contentful/Contentful.d.ts +33 -0
  33. package/dist/core/contentful/Contentful.js +67 -0
  34. package/dist/core/contentful/ContentfulAsset.d.ts +23 -0
  35. package/dist/core/contentful/ContentfulAsset.js +88 -0
  36. package/dist/core/contentful/ContentfulCollection.d.ts +29 -0
  37. package/dist/core/contentful/ContentfulCollection.js +97 -0
  38. package/dist/core/contentful/ContentfulPage.d.ts +31 -0
  39. package/dist/core/contentful/ContentfulPage.js +84 -0
  40. package/dist/core/contentful/ContentfulRefs.d.ts +16 -0
  41. package/dist/core/contentful/ContentfulRefs.js +152 -0
  42. package/dist/core/contentful/index.d.ts +5 -0
  43. package/dist/core/contentful/index.js +21 -0
  44. package/dist/core/domain/Collection.d.ts +99 -0
  45. package/dist/core/domain/Collection.js +311 -0
  46. package/dist/core/domain/Page.d.ts +58 -8
  47. package/dist/core/domain/Page.js +329 -16
  48. package/dist/core/domain/index.d.ts +1 -0
  49. package/dist/core/domain/index.js +1 -0
  50. package/dist/core/index.d.ts +2 -0
  51. package/dist/core/index.js +2 -0
  52. package/dist/core/repository/AssetRepository.d.ts +10 -0
  53. package/dist/core/repository/AssetRepository.js +33 -0
  54. package/dist/core/repository/CollectionSerializer.d.ts +9 -0
  55. package/dist/core/repository/CollectionSerializer.js +41 -0
  56. package/dist/core/repository/LocalCollectionRepository.d.ts +27 -0
  57. package/dist/core/repository/LocalCollectionRepository.js +143 -0
  58. package/dist/core/repository/LocalPageRepository.d.ts +16 -0
  59. package/dist/core/repository/LocalPageRepository.js +153 -0
  60. package/dist/core/repository/PageSerializer.d.ts +2 -2
  61. package/dist/core/repository/PageSerializer.js +16 -13
  62. package/dist/core/repository/RemoteCollectionRepository.d.ts +19 -0
  63. package/dist/core/repository/RemoteCollectionRepository.js +236 -0
  64. package/dist/core/repository/RemotePageRepository.d.ts +14 -0
  65. package/dist/core/repository/RemotePageRepository.js +113 -0
  66. package/dist/core/repository/index.d.ts +5 -1
  67. package/dist/core/repository/index.js +5 -1
  68. package/dist/page/{hooks/PageController.d.ts → controller/LocalPageController.d.ts} +11 -6
  69. package/dist/page/controller/LocalPageController.js +190 -0
  70. package/dist/page/controller/LocalPageControllerContainer.d.ts +8 -0
  71. package/dist/page/controller/LocalPageControllerContainer.js +36 -0
  72. package/dist/page/controller/LocalPageControllerContext.d.ts +7 -0
  73. package/dist/page/controller/LocalPageControllerContext.js +6 -0
  74. package/dist/page/controller/index.d.ts +3 -0
  75. package/dist/page/controller/index.js +19 -0
  76. package/dist/page/controller/useLocalPageController.d.ts +2 -0
  77. package/dist/page/controller/useLocalPageController.js +10 -0
  78. package/dist/page/index.d.ts +1 -0
  79. package/dist/page/index.js +1 -0
  80. package/dist/page/screens/PageEditor.js +9 -11
  81. package/package.json +5 -3
  82. package/dist/core/repository/PageRepository.d.ts +0 -12
  83. package/dist/core/repository/PageRepository.js +0 -23
  84. package/dist/page/hooks/PageController.js +0 -107
  85. package/dist/page/hooks/index.d.ts +0 -1
@@ -0,0 +1,19 @@
1
+ import { Tagged } from 'type-fest';
2
+ export type AppDomain = 'app';
3
+ export interface AppMessage {
4
+ domain: AppDomain;
5
+ type: string;
6
+ timestamp: number;
7
+ }
8
+ export type AppContextId = Tagged<string, 'funnel.AppContextId'>;
9
+ export interface TrackedAppMessage extends AppMessage {
10
+ source: AppContextId;
11
+ }
12
+ export interface AppBlockNavMessage extends AppMessage {
13
+ type: 'blockNav';
14
+ itemId: string;
15
+ }
16
+ export declare namespace AppBlockNavMessage {
17
+ function create(itemId: string): AppBlockNavMessage;
18
+ function guard(message: AppMessage): message is AppBlockNavMessage;
19
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppBlockNavMessage = void 0;
4
+ var AppBlockNavMessage;
5
+ (function (AppBlockNavMessage) {
6
+ function create(itemId) {
7
+ return {
8
+ domain: 'app',
9
+ type: 'blockNav',
10
+ timestamp: Date.now(),
11
+ itemId
12
+ };
13
+ }
14
+ AppBlockNavMessage.create = create;
15
+ function guard(message) {
16
+ return message.domain === 'app' && message.type === 'blockNav';
17
+ }
18
+ AppBlockNavMessage.guard = guard;
19
+ })(AppBlockNavMessage || (exports.AppBlockNavMessage = AppBlockNavMessage = {}));
@@ -0,0 +1,4 @@
1
+ export * from './AppBridgeContainer';
2
+ export * from './AppBridgeContext';
3
+ export * from './AppMessage';
4
+ export * from './useAppBridge';
@@ -0,0 +1,20 @@
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("./AppBridgeContainer"), exports);
18
+ __exportStar(require("./AppBridgeContext"), exports);
19
+ __exportStar(require("./AppMessage"), exports);
20
+ __exportStar(require("./useAppBridge"), exports);
@@ -0,0 +1,8 @@
1
+ import { Observable } from 'rxjs';
2
+ import { AppMessage } from './AppMessage';
3
+ export type AppMessageSubmission = Omit<AppMessage, 'source'>;
4
+ export type UseAppBridgetHook = {
5
+ sendMessage(message: AppMessageSubmission): void;
6
+ messages$: Observable<AppMessage>;
7
+ };
8
+ export declare function useAppBridge(): UseAppBridgetHook;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAppBridge = useAppBridge;
4
+ const react_1 = require("react");
5
+ const AppBridgeContext_1 = require("./AppBridgeContext");
6
+ // hook
7
+ function useAppBridge() {
8
+ // bind context
9
+ const { id, eventBus, channel } = (0, react_1.useContext)(AppBridgeContext_1.AppBridgeContext);
10
+ // helpers
11
+ const sendMessage = (message) => {
12
+ // track the message
13
+ const trackedMessage = Object.assign({ source: id }, message);
14
+ // send to local bus
15
+ eventBus.next(trackedMessage);
16
+ // echo to remote bus (if any)
17
+ channel.postMessage(trackedMessage);
18
+ };
19
+ // return hook interface
20
+ return {
21
+ sendMessage,
22
+ messages$: eventBus.asObservable()
23
+ };
24
+ }
@@ -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
+ media: Contentful.Link.Asset;
12
+ metadata: object;
13
+ scope: string;
14
+ tags?: string | null;
15
+ url: string;
16
+ size: number;
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,88 @@
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
+ var _a, _b, _c;
12
+ // setup
13
+ const locale = sdk.locales.default;
14
+ // upload file
15
+ const uploadResult = await sdk.cma.upload.create({}, {
16
+ file: await args.file.arrayBuffer()
17
+ });
18
+ // create contentful asset
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]: JSON.stringify(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
+ // extract fields
68
+ const { name, description, type, brand, metadata, scope, tags, url, size } = entry.fields;
69
+ // create asset
70
+ return {
71
+ __root: 'asset',
72
+ type: 'asset',
73
+ value: {
74
+ id: entry.sys.id,
75
+ name: name[locale],
76
+ description: description === null || description === void 0 ? void 0 : description[locale],
77
+ type: type[locale],
78
+ brand: (_a = brand === null || brand === void 0 ? void 0 : brand[locale]) !== null && _a !== void 0 ? _a : undefined,
79
+ metadata: metadata[locale],
80
+ scope: scope[locale],
81
+ tags: JSON.parse((_b = tags === null || tags === void 0 ? void 0 : tags[locale]) !== null && _b !== void 0 ? _b : '[]'),
82
+ url: url[locale],
83
+ size: size[locale]
84
+ }
85
+ };
86
+ }
87
+ ContentfulAsset.serialize = serialize;
88
+ })(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
+ references?: Contentful.Link[];
15
+ pageRefIds?: string;
16
+ state: string;
17
+ errors: boolean;
18
+ publishedOn?: number;
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
+ }