diff --git a/package-lock.json b/package-lock.json index 7e5456a..1f55eb4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "@kontent-ai/smart-link", "version": "3.2.0-next.0", "license": "MIT", + "dependencies": { + "@kontent-ai/delivery-sdk": "^14.6.0" + }, "devDependencies": { "@babel/core": "7.18.10", "@storybook/addon-actions": "6.5.10", @@ -2747,6 +2750,65 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@kontent-ai/core-sdk": { + "version": "10.3.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/core-sdk/-/core-sdk-10.3.0.tgz", + "integrity": "sha512-fuoi2NqEvEopYyayRVucsth7ndhQB9q4OdWwj7GfLNYHusOXXuXKAB1vNgT0T4O09TMykEkXnWZnP6Gz/Ovadg==", + "dependencies": { + "axios": "1.6.2" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@kontent-ai/core-sdk/node_modules/axios": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", + "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", + "dependencies": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/@kontent-ai/core-sdk/node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/@kontent-ai/delivery-sdk": { + "version": "14.6.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/delivery-sdk/-/delivery-sdk-14.6.0.tgz", + "integrity": "sha512-2/h5i2BpKYQREU6khiswnndi/VKlMCzBKNg1ZNBxc7zxYZcF2+53bbQ6H6agWYyZfgskTd0NpKBy7+5Ff7HgwA==", + "dependencies": { + "@kontent-ai/core-sdk": "10.3.0", + "url-parse": "1.5.10", + "uuid": "9.0.1" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/@kontent-ai/delivery-sdk/node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/@loki/browser": { "version": "0.31.2", "resolved": "https://registry.npmjs.org/@loki/browser/-/browser-0.31.2.tgz", @@ -21370,8 +21432,7 @@ "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "dev": true + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "node_modules/at-least-node": { "version": "1.0.0", @@ -23186,7 +23247,6 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, "dependencies": { "delayed-stream": "~1.0.0" }, @@ -24158,7 +24218,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "dev": true, "engines": { "node": ">=0.4.0" } @@ -26039,7 +26098,6 @@ "version": "1.15.4", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.4.tgz", "integrity": "sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==", - "dev": true, "funding": [ { "type": "individual", @@ -30539,7 +30597,6 @@ }, "node_modules/mime-db": { "version": "1.52.0", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.6" @@ -30547,7 +30604,6 @@ }, "node_modules/mime-types": { "version": "2.1.35", - "dev": true, "license": "MIT", "dependencies": { "mime-db": "1.52.0" @@ -32129,6 +32185,11 @@ "node": ">= 0.10" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/prr": { "version": "1.0.1", "dev": true, @@ -32232,6 +32293,11 @@ "node": ">=0.4.x" } }, + "node_modules/querystringify": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz", + "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==" + }, "node_modules/queue-microtask": { "version": "1.2.3", "dev": true, @@ -33048,7 +33114,6 @@ }, "node_modules/requires-port": { "version": "1.0.0", - "dev": true, "license": "MIT" }, "node_modules/resolve": { @@ -35690,6 +35755,15 @@ "node": ">=8.9.0" } }, + "node_modules/url-parse": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz", + "integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==", + "dependencies": { + "querystringify": "^2.1.1", + "requires-port": "^1.0.0" + } + }, "node_modules/url/node_modules/punycode": { "version": "1.3.2", "dev": true, @@ -38664,6 +38738,53 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "@kontent-ai/core-sdk": { + "version": "10.3.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/core-sdk/-/core-sdk-10.3.0.tgz", + "integrity": "sha512-fuoi2NqEvEopYyayRVucsth7ndhQB9q4OdWwj7GfLNYHusOXXuXKAB1vNgT0T4O09TMykEkXnWZnP6Gz/Ovadg==", + "requires": { + "axios": "1.6.2" + }, + "dependencies": { + "axios": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", + "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", + "requires": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + } + } + }, + "@kontent-ai/delivery-sdk": { + "version": "14.6.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/delivery-sdk/-/delivery-sdk-14.6.0.tgz", + "integrity": "sha512-2/h5i2BpKYQREU6khiswnndi/VKlMCzBKNg1ZNBxc7zxYZcF2+53bbQ6H6agWYyZfgskTd0NpKBy7+5Ff7HgwA==", + "requires": { + "@kontent-ai/core-sdk": "10.3.0", + "url-parse": "1.5.10", + "uuid": "9.0.1" + }, + "dependencies": { + "uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==" + } + } + }, "@loki/browser": { "version": "0.31.2", "resolved": "https://registry.npmjs.org/@loki/browser/-/browser-0.31.2.tgz", @@ -52441,8 +52562,7 @@ "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "dev": true + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "at-least-node": { "version": "1.0.0", @@ -53777,7 +53897,6 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, "requires": { "delayed-stream": "~1.0.0" } @@ -54485,8 +54604,7 @@ "delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "dev": true + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==" }, "delegates": { "version": "1.0.0", @@ -55822,8 +55940,7 @@ "follow-redirects": { "version": "1.15.4", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.4.tgz", - "integrity": "sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==", - "dev": true + "integrity": "sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==" }, "for-in": { "version": "1.0.2", @@ -58953,12 +59070,10 @@ "dev": true }, "mime-db": { - "version": "1.52.0", - "dev": true + "version": "1.52.0" }, "mime-types": { "version": "2.1.35", - "dev": true, "requires": { "mime-db": "1.52.0" } @@ -60092,6 +60207,11 @@ "ipaddr.js": "1.9.1" } }, + "proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "prr": { "version": "1.0.1", "dev": true @@ -60174,6 +60294,11 @@ "version": "0.2.1", "dev": true }, + "querystringify": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz", + "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==" + }, "queue-microtask": { "version": "1.2.3", "dev": true @@ -60753,8 +60878,7 @@ "dev": true }, "requires-port": { - "version": "1.0.0", - "dev": true + "version": "1.0.0" }, "resolve": { "version": "1.22.1", @@ -62592,6 +62716,15 @@ } } }, + "url-parse": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz", + "integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==", + "requires": { + "querystringify": "^2.1.1", + "requires-port": "^1.0.0" + } + }, "use": { "version": "3.1.1", "dev": true diff --git a/package.json b/package.json index 2b9678c..59bc666 100644 --- a/package.json +++ b/package.json @@ -117,5 +117,8 @@ "webpack-bundle-analyzer": "4.5.0", "webpack-cli": "4.10.0", "webpack-merge": "5.8.0" + }, + "dependencies": { + "@kontent-ai/delivery-sdk": "^14.6.0" } } diff --git a/src/lib/DeliverElementData.ts b/src/lib/DeliverElementData.ts new file mode 100644 index 0000000..c881cd7 --- /dev/null +++ b/src/lib/DeliverElementData.ts @@ -0,0 +1,48 @@ +import { Elements } from '@kontent-ai/delivery-sdk'; +import { ElementType as DeliverElementType } from '@kontent-ai/delivery-sdk/dist/cjs/elements/element-type'; + +type DeliverElementDataTemplate = { + readonly type: TType; + readonly data: Omit; +}; + +export type DeliverAssetElementData = DeliverElementDataTemplate; +export type DeliverCustomElementData = DeliverElementDataTemplate< + Elements.CustomElement, + DeliverElementType.Custom +>; +export type DeliverDatetimeElementData = DeliverElementDataTemplate< + Elements.DateTimeElement, + DeliverElementType.DateTime +>; +export type DeliverLinkedItemsElementData = DeliverElementDataTemplate< + Elements.LinkedItemsElement, + DeliverElementType.ModularContent +>; +export type DeliverMultipleChoiceElementData = DeliverElementDataTemplate< + Elements.MultipleChoiceElement, + DeliverElementType.MultipleChoice +>; +export type DeliverNumberElementData = DeliverElementDataTemplate; +export type DeliverRichTextElementData = DeliverElementDataTemplate< + Elements.RichTextElement, + DeliverElementType.RichText +>; +export type DeliverTaxonomyElementData = DeliverElementDataTemplate< + Elements.TaxonomyElement, + DeliverElementType.Taxonomy +>; +export type DeliverTextElementData = DeliverElementDataTemplate; +export type DeliverUrlSlugElementData = DeliverElementDataTemplate; + +export type DeliverElementData = + | DeliverAssetElementData + | DeliverCustomElementData + | DeliverDatetimeElementData + | DeliverLinkedItemsElementData + | DeliverMultipleChoiceElementData + | DeliverNumberElementData + | DeliverRichTextElementData + | DeliverTaxonomyElementData + | DeliverTextElementData + | DeliverUrlSlugElementData; diff --git a/src/lib/IFrameCommunicatorTypes.ts b/src/lib/IFrameCommunicatorTypes.ts index 039081f..ac5d052 100644 --- a/src/lib/IFrameCommunicatorTypes.ts +++ b/src/lib/IFrameCommunicatorTypes.ts @@ -1,3 +1,5 @@ +import { DeliverElementData } from './DeliverElementData'; + interface ISDKSupportedFeatures { readonly previewIFrameCurrentUrlHandler: boolean; readonly refreshHandler: boolean; @@ -51,12 +53,9 @@ export interface IUpdateReference { readonly codename: T; } -export interface IUpdateMessageElement { +export type IUpdateMessageElement = DeliverElementData & { readonly element: IUpdateReference; - readonly type: string; - // The data props must match the props from the Delivery API for the given element type - readonly data: Readonly>; -} +}; export interface IUpdateMessageData { readonly projectId: string;