@uniformdev/canvas-contentful 16.1.1-alpha.321 → 16.2.1-alpha.60

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 (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var $=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var q=(e,t)=>{for(var n in t)$(e,n,{get:t[n],enumerable:!0})},D=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let c of B(t))!U.call(e,c)&&c!==n&&$(e,c,{get:()=>t[c],enumerable:!(o=Y(t,c))||o.enumerable});return e};var z=e=>D($({},"__esModule",{value:!0}),e);var oe={};q(oe,{CANVAS_CONTENTFUL_MULTI_PARAMETER_TYPES:()=>I,CANVAS_CONTENTFUL_PARAMETER_TYPES:()=>M,CANVAS_CONTENTFUL_QUERY_PARAMETER_TYPES:()=>S,ContentfulClientList:()=>v,contentfulRichTextToHtmlEnhancer:()=>ne,createContentfulEnhancer:()=>G,createContentfulMultiEnhancer:()=>H,createContentfulQueryEnhancer:()=>X});module.exports=z(oe);var L=require("@uniformdev/canvas");var v=class{constructor(t){this._clients={},Array.isArray(t)?t.forEach(n=>this.addClient(n)):t&&this.addClient(t)}addClient({source:t="default",client:n,previewClient:o}){if(this._clients[t])throw new Error(`The source ${t} is always registered`);if(!n)throw new Error("You must provide a Contentful client for the ContentfulClientList");this._clients[t]={client:n,previewClient:o||n}}getClient({source:t="default",isPreviewClient:n}){let o=this._clients[t];if(!!o)return n?o.previewClient:o.client}};var V=require("@uniformdev/canvas"),w=(0,V.createLimitPolicy)({throttle:{limit:55,interval:1e3}});function P(e){return typeof e=="string"?e:typeof e=="object"&&e&&"error"in e?e.error:e instanceof Error?e.toString():JSON.stringify(e,null,2)}function O(e,t){if(!!e)return`${t==="desc"?"-":""}${e}`}function A({clients:e,parameterValue:t,parameterName:n,component:o,context:c}){let{source:i="default"}=t,a=e.getClient({source:i,isPreviewClient:c.preview});if(!a)throw new Error(`No Contentful client could be resolved for source key '${i}' referenced in parameter '${n} in component '${o.type}'. Ensure that the 'clients' property you are passing to the enhancer has a client instance registered for the source key.`);return a}var T={select:"fields",include:1},M=Object.freeze(["contentfulEntry"]);function K(e){return e instanceof v}function G({client:e,previewClient:t,createQuery:n,useBatching:o,limitPolicy:c}){if(!e)throw new Error("No Contentful clients were provided to the enhancer. You must provide at least one client via the `client` or `clients` property.");let a=(()=>{if(K(e))return e;let s=new v;return s.addClient({client:e,previewClient:t}),s})(),d=c||w;return o?(0,L.createBatchEnhancer)({handleBatch:async s=>{var f;let l=s.reduce((u,r)=>{let{parameter:C,parameterName:m,component:E,context:p}=r.args,h=C.value;if(!b(h))return u;let g=F({parameterValue:h,parameterName:m,clients:a,component:E,context:p}),y="";if(x(h))y="legacy-group";else{let{source:j="default"}=h;y=j}return u[y]&&Array.isArray(u[y].tasks)?u[y].tasks.push(r):u[y]={client:g,tasks:[r]},u},{});try{console.time("fetch all entries");for await(let[u,r]of Object.entries(l)){let{context:C,component:m}=r.tasks[0].args,E=(f=n==null?void 0:n({component:m,defaultQuery:{...T},context:C}))!=null?f:T,p=new L.UniqueBatchEntries(r.tasks,g=>x(g.parameter.value)?g.parameter.value:g.parameter.value.entryId),h=Object.keys(p.groups);console.time(`fetch entries ${u}`);try{(await r.client.getEntries({"sys.id[in]":h.join(","),limit:h.length,...E})).items.forEach(y=>{p.resolveKey(y.sys.id,y)}),p.resolveRemaining(null)}finally{console.timeEnd(`fetch entries ${u}`)}}console.timeEnd("fetch all entries")}catch(u){let r=P(u),C=new Error(`Failed loading Contentful entries batch (${s.length}) ${r}`);s.forEach(m=>m.reject(C))}},shouldQueue:({parameter:s})=>R(s),limitPolicy:d}):{enhanceOne:async function({parameter:l,parameterName:f,component:u,context:r}){var C,m;if(R(l)){if(!b(l.value))return null;let E=F({clients:a,parameterName:f,parameterValue:l.value,component:u,context:r}),p=x(l.value)?l.value:l.value.entryId,h=(C=n==null?void 0:n({parameter:l,parameterName:f,component:u,defaultQuery:{...T},context:r}))!=null?C:T;try{return console.time(`fetch entry ${p}`),await E.getEntry(p,h)}catch(g){let y=P(g);throw x(l.value)?new Error(`Failed loading Contentful entry '${l.value}' referenced in parameter '${f}': ${y}`):new Error(`Failed loading Contentful entry '${p}' from source '${(m=l.value.source)!=null?m:"default"}' referenced in parameter '${f}': ${y}`)}finally{console.timeEnd(`fetch entry ${p}`)}}},limitPolicy:d}}function R(e){var t;return e.type===M[0]&&(((t=e.value)==null?void 0:t.entryId)||typeof e.value=="string")}function x(e){return typeof e=="string"}function b(e){return!(!e||!x(e)&&!e.entryId)}function F({clients:e,parameterValue:t,parameterName:n,component:o,context:c}){if(x(t)){let d=e.getClient({isPreviewClient:c.preview});if(!d)throw new Error(`Parameter '${n}' in component '${o.type}' has a value '${t}' that is not compatible with multi-space/environment usage. If you wish to use multiple spaces/environments, you must convert your Canvas component parameters to the multi-space/environment compatible version. Otherwise, you can continue to use your parameters as-is, but must specify one of the clients provided to the Contentful enhancer as the 'default' client by registering it without specifying a source key.`);return d}let{source:i="default"}=t,a=e.getClient({source:i,isPreviewClient:c.preview});if(!a)throw new Error(`No Contentful client could be resolved for source key '${i}' referenced in parameter '${n} in component '${o.type}'. Ensure that the 'clients' property you are passing to the enhancer has a client instance registered for the source key.`);return a}var N={select:"fields",include:1},I=Object.freeze(["contentfulMultiEntry"]);function H({clients:e,createQuery:t,limitPolicy:n}){if(!e)throw new Error("No Contentful clients were provided to the enhancer. You must provide at least one client via the ContentfulClientList.");return{enhanceOne:async function({parameter:i,parameterName:a,component:d,context:s}){var l,f;if(J(i)){if(!W(i.value))return null;let u=A({clients:e,parameterName:a,parameterValue:i.value,component:d,context:s}),r=i.value.entries,C=(l=t==null?void 0:t({parameter:i,parameterName:a,component:d,defaultQuery:{...N},context:s}))!=null?l:N;try{return console.time(`fetch entries ${r.join()}`),(await u.getEntries({"sys.id[in]":r.join(),limit:r.length,...C})).items}catch(m){let E=P(m);throw new Error(`Failed loading Contentful entries '${r.join()}' from source '${(f=i.value.source)!=null?f:"default"}' referenced in parameter '${a}': ${E}`)}finally{console.timeEnd(`fetch entries ${r.join()}`)}}},limitPolicy:n||w}}function J(e){return e.type===I[0]}function W(e){var t;return!(!e||!((t=e.entries)!=null&&t.length))}var S=Object.freeze(["contentfulQuery"]),Q={select:"fields",include:1};function X({clients:e,createQuery:t,limitPolicy:n}){if(!e)throw new Error("No Contentful clients were provided to the enhancer. You must provide at least one client via the ContentfulClientList.");return{enhanceOne:async function({parameter:i,parameterName:a,component:d,context:s}){var l,f;if(Z(i)){if(!ee(i.value))return null;let u=A({clients:e,parameterName:a,parameterValue:i.value,component:d,context:s}),r=i.value,C=te(r.count),m=(l=t==null?void 0:t({parameter:i,parameterName:a,component:d,defaultQuery:{...Q},context:s}))!=null?l:Q,E=`fetch query: ${C} entries with '${r.contentType}' content type`;try{return console.time(E),(await u.getEntries({content_type:r.contentType,order:O(r.sortBy,r.sortOrder),limit:C,...m})).items}catch(p){let h=P(p);throw new Error(`Failed loading Contentful entries with '${r.contentType}' content type from source '${(f=r.source)!=null?f:"default"}' referenced in parameter '${a}': ${h}`)}finally{console.timeEnd(E)}}},limitPolicy:n||w}}function Z(e){return e.type===S[0]}function ee(e){return!(!e||!e.source||!e.contentType||typeof e.count=="undefined")}function te(e){return!e||e<1?1:e>1e3?1e3:e}var k=require("@contentful/rich-text-html-renderer"),ne=({parameter:e})=>{let t=e.value;if(!t)return t;if(!re(t))return _(t),t;for(let n of t)_(n);return t};function _(e){var t;typeof(e==null?void 0:e.fields)=="object"&&Object.entries((t=e.fields)!=null?t:{}).forEach(([n,o])=>{typeof o=="object"&&"nodeType"in o&&o.nodeType==="document"&&(e.fields[n]=(0,k.documentToHtmlString)(o))})}function re(e){return Array.isArray(e)}0&&(module.exports={CANVAS_CONTENTFUL_MULTI_PARAMETER_TYPES,CANVAS_CONTENTFUL_PARAMETER_TYPES,CANVAS_CONTENTFUL_QUERY_PARAMETER_TYPES,ContentfulClientList,contentfulRichTextToHtmlEnhancer,createContentfulEnhancer,createContentfulMultiEnhancer,createContentfulQueryEnhancer});
1
+ "use strict";var $=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var q=(e,t)=>{for(var n in t)$(e,n,{get:t[n],enumerable:!0})},D=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let c of B(t))!U.call(e,c)&&c!==n&&$(e,c,{get:()=>t[c],enumerable:!(o=Y(t,c))||o.enumerable});return e};var z=e=>D($({},"__esModule",{value:!0}),e);var oe={};q(oe,{CANVAS_CONTENTFUL_MULTI_PARAMETER_TYPES:()=>I,CANVAS_CONTENTFUL_PARAMETER_TYPES:()=>M,CANVAS_CONTENTFUL_QUERY_PARAMETER_TYPES:()=>S,ContentfulClientList:()=>v,contentfulRichTextToHtmlEnhancer:()=>ne,createContentfulEnhancer:()=>G,createContentfulMultiEnhancer:()=>H,createContentfulQueryEnhancer:()=>X});module.exports=z(oe);var L=require("@uniformdev/canvas");var v=class{constructor(t){this._clients={},Array.isArray(t)?t.forEach(n=>this.addClient(n)):t&&this.addClient(t)}addClient({source:t="default",client:n,previewClient:o}){if(this._clients[t])throw new Error(`The source ${t} is always registered`);if(!n)throw new Error("You must provide a Contentful client for the ContentfulClientList");this._clients[t]={client:n,previewClient:o||n}}getClient({source:t="default",isPreviewClient:n}){let o=this._clients[t];if(!!o)return n?o.previewClient:o.client}};var V=require("@uniformdev/canvas"),w=(0,V.createLimitPolicy)({throttle:{limit:55,interval:1e3}});function P(e){return typeof e=="string"?e:typeof e=="object"&&e&&"error"in e?e.error:e instanceof Error?e.toString():JSON.stringify(e,null,2)}function O(e,t){if(!!e)return`${t==="desc"?"-":""}${e}`}function A({clients:e,parameterValue:t,parameterName:n,component:o,context:c}){let{source:i="default"}=t,a=e.getClient({source:i,isPreviewClient:c.preview});if(!a)throw new Error(`No Contentful client could be resolved for source key '${i}' referenced in parameter '${n} in component '${o.type}'. Ensure that the 'clients' property you are passing to the enhancer has a client instance registered for the source key.`);return a}var T={select:"fields",include:1},M=Object.freeze(["contentfulEntry"]);function K(e){return e instanceof v}function G({client:e,previewClient:t,createQuery:n,useBatching:o,limitPolicy:c}){if(!e)throw new Error("No Contentful clients were provided to the enhancer. You must provide at least one client via the `client` or `clients` property.");let a=(()=>{if(K(e))return e;let s=new v;return s.addClient({client:e,previewClient:t}),s})(),d=c||w;return o?(0,L.createBatchEnhancer)({handleBatch:async s=>{var f;let l=s.reduce((u,r)=>{let{parameter:C,parameterName:m,component:E,context:p}=r.args,h=C.value;if(!b(h))return u;let g=F({parameterValue:h,parameterName:m,clients:a,component:E,context:p}),y="";if(x(h))y="legacy-group";else{let{source:j="default"}=h;y=j}return u[y]&&Array.isArray(u[y].tasks)?u[y].tasks.push(r):u[y]={client:g,tasks:[r]},u},{});try{console.time("fetch all entries");for await(let[u,r]of Object.entries(l)){let{context:C,component:m}=r.tasks[0].args,E=(f=n==null?void 0:n({component:m,defaultQuery:{...T},context:C}))!=null?f:T,p=new L.UniqueBatchEntries(r.tasks,g=>x(g.parameter.value)?g.parameter.value:g.parameter.value.entryId),h=Object.keys(p.groups);console.time(`fetch entries ${u}`);try{(await r.client.getEntries({"sys.id[in]":h.join(","),limit:h.length,...E})).items.forEach(y=>{p.resolveKey(y.sys.id,y)}),p.resolveRemaining(null)}finally{console.timeEnd(`fetch entries ${u}`)}}console.timeEnd("fetch all entries")}catch(u){let r=P(u),C=new Error(`Failed loading Contentful entries batch (${s.length}) ${r}`);s.forEach(m=>m.reject(C))}},shouldQueue:({parameter:s})=>R(s),limitPolicy:d}):{enhanceOne:async function({parameter:l,parameterName:f,component:u,context:r}){var C,m;if(R(l)){if(!b(l.value))return null;let E=F({clients:a,parameterName:f,parameterValue:l.value,component:u,context:r}),p=x(l.value)?l.value:l.value.entryId,h=(C=n==null?void 0:n({parameter:l,parameterName:f,component:u,defaultQuery:{...T},context:r}))!=null?C:T;try{return console.time(`fetch entry ${p}`),await E.getEntry(p,h)}catch(g){let y=P(g);throw x(l.value)?new Error(`Failed loading Contentful entry '${l.value}' referenced in parameter '${f}': ${y}`):new Error(`Failed loading Contentful entry '${p}' from source '${(m=l.value.source)!=null?m:"default"}' referenced in parameter '${f}': ${y}`)}finally{console.timeEnd(`fetch entry ${p}`)}}},limitPolicy:d}}function R(e){var t;return e.type===M[0]&&(((t=e.value)==null?void 0:t.entryId)||typeof e.value=="string")}function x(e){return typeof e=="string"}function b(e){return!(!e||!x(e)&&!e.entryId)}function F({clients:e,parameterValue:t,parameterName:n,component:o,context:c}){if(x(t)){let d=e.getClient({isPreviewClient:c.preview});if(!d)throw new Error(`Parameter '${n}' in component '${o.type}' has a value '${t}' that is not compatible with multi-space/environment usage. If you wish to use multiple spaces/environments, you must convert your Canvas component parameters to the multi-space/environment compatible version. Otherwise, you can continue to use your parameters as-is, but must specify one of the clients provided to the Contentful enhancer as the 'default' client by registering it without specifying a source key.`);return d}let{source:i="default"}=t,a=e.getClient({source:i,isPreviewClient:c.preview});if(!a)throw new Error(`No Contentful client could be resolved for source key '${i}' referenced in parameter '${n} in component '${o.type}'. Ensure that the 'clients' property you are passing to the enhancer has a client instance registered for the source key.`);return a}var N={select:"fields",include:1},I=Object.freeze(["contentfulMultiEntry"]);function H({clients:e,createQuery:t,limitPolicy:n}){if(!e)throw new Error("No Contentful clients were provided to the enhancer. You must provide at least one client via the ContentfulClientList.");return{enhanceOne:async function({parameter:i,parameterName:a,component:d,context:s}){var l,f;if(J(i)){if(!W(i.value))return null;let u=A({clients:e,parameterName:a,parameterValue:i.value,component:d,context:s}),r=i.value.entries,C=(l=t==null?void 0:t({parameter:i,parameterName:a,component:d,defaultQuery:{...N},context:s}))!=null?l:N;try{return console.time(`fetch entries ${r.join()}`),(await u.getEntries({"sys.id[in]":r.join(),limit:r.length,...C})).items}catch(m){let E=P(m);throw new Error(`Failed loading Contentful entries '${r.join()}' from source '${(f=i.value.source)!=null?f:"default"}' referenced in parameter '${a}': ${E}`)}finally{console.timeEnd(`fetch entries ${r.join()}`)}}},limitPolicy:n||w}}function J(e){return e.type===I[0]}function W(e){var t;return!(!e||!((t=e.entries)!=null&&t.length))}var S=Object.freeze(["contentfulQuery"]),Q={select:"fields",include:1};function X({clients:e,createQuery:t,limitPolicy:n}){if(!e)throw new Error("No Contentful clients were provided to the enhancer. You must provide at least one client via the ContentfulClientList.");return{enhanceOne:async function({parameter:i,parameterName:a,component:d,context:s}){var l,f;if(Z(i)){if(!ee(i.value))return null;let u=A({clients:e,parameterName:a,parameterValue:i.value,component:d,context:s}),r=i.value,C=te(r.count),m=(l=t==null?void 0:t({parameter:i,parameterName:a,component:d,defaultQuery:{...Q},context:s}))!=null?l:Q,E=`fetch query: ${C} entries with '${r.contentType}' content type`;try{return console.time(E),(await u.getEntries({content_type:r.contentType,order:O(r.sortBy,r.sortOrder),limit:C,...m})).items}catch(p){let h=P(p);throw new Error(`Failed loading Contentful entries with '${r.contentType}' content type from source '${(f=r.source)!=null?f:"default"}' referenced in parameter '${a}': ${h}`)}finally{console.timeEnd(E)}}},limitPolicy:n||w}}function Z(e){return e.type===S[0]}function ee(e){return!(!e||!e.source||!e.contentType||typeof e.count=="undefined")}function te(e){return!e||e<1?1:e>1e3?1e3:e}var k=require("@contentful/rich-text-html-renderer"),ne=({parameter:e})=>{let t=e.value;if(!t)return t;if(!re(t))return _(t),t;for(let n of t)_(n);return t};function _(e){var t;typeof(e==null?void 0:e.fields)=="object"&&Object.entries((t=e.fields)!=null?t:{}).forEach(([n,o])=>{typeof o=="object"&&"nodeType"in o&&o.nodeType==="document"&&(e.fields[n]=(0,k.documentToHtmlString)(o))})}function re(e){return Array.isArray(e)}0&&(module.exports={CANVAS_CONTENTFUL_MULTI_PARAMETER_TYPES,CANVAS_CONTENTFUL_PARAMETER_TYPES,CANVAS_CONTENTFUL_QUERY_PARAMETER_TYPES,ContentfulClientList,contentfulRichTextToHtmlEnhancer,createContentfulEnhancer,createContentfulMultiEnhancer,createContentfulQueryEnhancer});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-contentful",
3
- "version": "16.1.1-alpha.321+009555156",
3
+ "version": "16.2.1-alpha.60+4d040ee77",
4
4
  "description": "Contentful data enhancers for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "format": "prettier --write \"src/**/*.{js,ts,tsx}\""
24
24
  },
25
25
  "dependencies": {
26
- "@uniformdev/canvas": "^16.1.1-alpha.321+009555156"
26
+ "@uniformdev/canvas": "^16.2.1-alpha.60+4d040ee77"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "@contentful/rich-text-html-renderer": ">= 14",
@@ -39,5 +39,5 @@
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
- "gitHead": "0095551562382075ed1f09f5b22d6ce484ba3f7b"
42
+ "gitHead": "4d040ee77ebb1baf10bc23fff43b367100350e44"
43
43
  }