@uniformdev/canvas-contentful 12.2.1-alpha.39 → 12.2.1-alpha.59

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.
package/dist/index.esm.js CHANGED
@@ -1 +1 @@
1
- import{createBatchEnhancer as L,UniqueBatchEntries as S,createLimitPolicy as T}from"@uniformdev/canvas";var w=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:i}){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:i||n}}getClient({source:t="default",isPreviewClient:n}){let i=this._clients[t];if(!!i)return n?i.previewClient:i.client}};var P={select:"fields",include:1},R=Object.freeze(["contentfulEntry"]);function O(e){return e instanceof w}function Y({client:e,previewClient:t,createQuery:n,useBatching:i,limitPolicy:y}){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 E=(()=>{if(O(e))return e;let c=new w;return c.addClient({client:e,previewClient:t}),c})(),g=y||T({throttle:{limit:55,interval:1e3}});return i?L({handleBatch:async c=>{let l=c.reduce((r,s)=>{let{parameter:f,parameterName:C,component:p,context:m}=s.args,a=f.value;if(!b(a))return r;let d=$({parameterValue:a,parameterName:C,clients:E,component:p,context:m}),o="";if(h(a))o="legacy-group";else{let{source:v="default"}=a;o=v}return r[o]&&Array.isArray(r[o].tasks)?r[o].tasks.push(s):r[o]={client:d,tasks:[s]},r},{});try{console.time("Contentful: fetch entry batch"),await Promise.all(Object.values(l).map(async r=>{var d;let{context:s,component:f}=r.tasks[0].args,C=(d=n==null?void 0:n({component:f,defaultQuery:{...P},context:s}))!=null?d:P,p=new S(r.tasks,o=>h(o.parameter.value)?o.parameter.value:o.parameter.value.entryId),m=Object.keys(p.groups);(await r.client.getEntries({"sys.id[in]":m.join(","),limit:m.length,...C})).items.forEach(o=>{p.resolveKey(o.sys.id,o)}),p.resolveRemaining(null)})),console.timeEnd("Contentful: fetch entry batch")}catch(r){let s=x(r),f=new Error(`Failed loading Contentful entries batch (${c.length}) ${s}`);c.forEach(C=>C.reject(f))}},shouldQueue:({parameter:c})=>A(c),limitPolicy:g}):{enhanceOne:async function({parameter:l,parameterName:r,component:s,context:f}){var C,p;if(A(l)){if(!b(l.value))return null;let m=$({clients:E,parameterName:r,parameterValue:l.value,component:s,context:f}),a=h(l.value)?l.value:l.value.entryId,d=(C=n==null?void 0:n({parameter:l,parameterName:r,component:s,defaultQuery:{...P},context:f}))!=null?C:P;try{return console.time(`fetch entry ${a}`),await m.getEntry(a,d)}catch(o){let v=x(o);throw h(l.value)?new Error(`Failed loading Contentful entry '${l.value}' referenced in parameter '${r}': ${v}`):new Error(`Failed loading Contentful entry '${a}' from source '${(p=l.value.source)!=null?p:"default"}' referenced in parameter '${r}': ${v}`)}finally{console.timeEnd(`fetch entry ${a}`)}}},limitPolicy:g}}function A(e){var t;return e.type===R[0]&&(((t=e.value)==null?void 0:t.entryId)||typeof e.value=="string")}function x(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 h(e){return typeof e=="string"}function b(e){return!(!e||!h(e)&&!e.entryId)}function $({clients:e,parameterValue:t,parameterName:n,component:i,context:y}){if(h(t)){let g=e.getClient({isPreviewClient:y.preview});if(!g)throw new Error(`Parameter '${n}' in component '${i.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 g}let{source:u="default"}=t,E=e.getClient({source:u,isPreviewClient:y.preview});if(!E)throw new Error(`No Contentful client could be resolved for source key '${u}' referenced in parameter '${n} in component '${i.type}'. Ensure that the 'clients' property you are passing to the enhancer has a client instance registered for the source key.`);return E}import{documentToHtmlString as V}from"@contentful/rich-text-html-renderer";var M=({parameter:e})=>{var t,n,i;return typeof((t=e.value)==null?void 0:t.fields)!="object"||Object.entries((i=(n=e.value)==null?void 0:n.fields)!=null?i:{}).forEach(([y,u])=>{typeof u=="object"&&"nodeType"in u&&u.nodeType==="document"&&(e.value.fields[y]=V(u))}),e.value};export{R as CANVAS_CONTENTFUL_PARAMETER_TYPES,w as ContentfulClientList,M as contentfulRichTextToHtmlEnhancer,Y as createContentfulEnhancer};
1
+ import{createBatchEnhancer as S,UniqueBatchEntries as T,createLimitPolicy as R}from"@uniformdev/canvas";var w=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 P={select:"fields",include:1},O=Object.freeze(["contentfulEntry"]);function V(e){return e instanceof w}function Y({client:e,previewClient:t,createQuery:n,useBatching:o,limitPolicy:d}){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 E=(()=>{if(V(e))return e;let c=new w;return c.addClient({client:e,previewClient:t}),c})(),g=d||R({throttle:{limit:55,interval:1e3}});return o?S({handleBatch:async c=>{var y;let i=c.reduce((r,l)=>{let{parameter:p,parameterName:m,component:v,context:a}=l.args,u=p.value;if(!b(u))return r;let f=$({parameterValue:u,parameterName:m,clients:E,component:v,context:a}),s="";if(h(u))s="legacy-group";else{let{source:L="default"}=u;s=L}return r[s]&&Array.isArray(r[s].tasks)?r[s].tasks.push(l):r[s]={client:f,tasks:[l]},r},{});try{console.time("fetch all entries");for await(let[r,l]of Object.entries(i)){let{context:p,component:m}=l.tasks[0].args,v=(y=n==null?void 0:n({component:m,defaultQuery:{...P},context:p}))!=null?y:P,a=new T(l.tasks,f=>h(f.parameter.value)?f.parameter.value:f.parameter.value.entryId),u=Object.keys(a.groups);console.time(`fetch entries ${r}`);try{(await l.client.getEntries({"sys.id[in]":u.join(","),limit:u.length,...v})).items.forEach(s=>{a.resolveKey(s.sys.id,s)}),a.resolveRemaining(null)}finally{console.timeEnd(`fetch entries ${r}`)}}console.timeEnd("fetch all entries")}catch(r){let l=x(r),p=new Error(`Failed loading Contentful entries batch (${c.length}) ${l}`);c.forEach(m=>m.reject(p))}},shouldQueue:({parameter:c})=>A(c),limitPolicy:g}):{enhanceOne:async function({parameter:i,parameterName:y,component:r,context:l}){var p,m;if(A(i)){if(!b(i.value))return null;let v=$({clients:E,parameterName:y,parameterValue:i.value,component:r,context:l}),a=h(i.value)?i.value:i.value.entryId,u=(p=n==null?void 0:n({parameter:i,parameterName:y,component:r,defaultQuery:{...P},context:l}))!=null?p:P;try{return console.time(`fetch entry ${a}`),await v.getEntry(a,u)}catch(f){let s=x(f);throw h(i.value)?new Error(`Failed loading Contentful entry '${i.value}' referenced in parameter '${y}': ${s}`):new Error(`Failed loading Contentful entry '${a}' from source '${(m=i.value.source)!=null?m:"default"}' referenced in parameter '${y}': ${s}`)}finally{console.timeEnd(`fetch entry ${a}`)}}},limitPolicy:g}}function A(e){var t;return e.type===O[0]&&(((t=e.value)==null?void 0:t.entryId)||typeof e.value=="string")}function x(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 h(e){return typeof e=="string"}function b(e){return!(!e||!h(e)&&!e.entryId)}function $({clients:e,parameterValue:t,parameterName:n,component:o,context:d}){if(h(t)){let g=e.getClient({isPreviewClient:d.preview});if(!g)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 g}let{source:C="default"}=t,E=e.getClient({source:C,isPreviewClient:d.preview});if(!E)throw new Error(`No Contentful client could be resolved for source key '${C}' 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 E}import{documentToHtmlString as k}from"@contentful/rich-text-html-renderer";var M=({parameter:e})=>{var t,n,o;return typeof((t=e.value)==null?void 0:t.fields)!="object"||Object.entries((o=(n=e.value)==null?void 0:n.fields)!=null?o:{}).forEach(([d,C])=>{typeof C=="object"&&"nodeType"in C&&C.nodeType==="document"&&(e.value.fields[d]=k(C))}),e.value};export{O as CANVAS_CONTENTFUL_PARAMETER_TYPES,w as ContentfulClientList,M as contentfulRichTextToHtmlEnhancer,Y as createContentfulEnhancer};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var F=Object.create;var A=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var $=e=>A(e,"__esModule",{value:!0});var B=(e,t)=>{$(e);for(var n in t)A(e,n,{get:t[n],enumerable:!0})},H=(e,t,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of N(t))!_.call(e,r)&&r!=="default"&&A(e,r,{get:()=>t[r],enumerable:!(n=j(t,r))||n.enumerable});return e},L=e=>H($(A(e!=null?F(k(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);B(exports,{CANVAS_CONTENTFUL_PARAMETER_TYPES:()=>S,ContentfulClientList:()=>w,contentfulRichTextToHtmlEnhancer:()=>K,createContentfulEnhancer:()=>D});var h=L(require("@uniformdev/canvas"));var w=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:r}){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:r||n}}getClient({source:t="default",isPreviewClient:n}){let r=this._clients[t];if(!!r)return n?r.previewClient:r.client}};var x={select:"fields",include:1},S=Object.freeze(["contentfulEntry"]);function Y(e){return e instanceof w}function D({client:e,previewClient:t,createQuery:n,useBatching:r,limitPolicy:y}){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 g=(()=>{if(Y(e))return e;let c=new w;return c.addClient({client:e,previewClient:t}),c})(),v=y||(0,h.createLimitPolicy)({throttle:{limit:55,interval:1e3}});return r?(0,h.createBatchEnhancer)({handleBatch:async c=>{let l=c.reduce((o,s)=>{let{parameter:f,parameterName:C,component:p,context:m}=s.args,a=f.value;if(!O(a))return o;let d=V({parameterValue:a,parameterName:C,clients:g,component:p,context:m}),i="";if(E(a))i="legacy-group";else{let{source:P="default"}=a;i=P}return o[i]&&Array.isArray(o[i].tasks)?o[i].tasks.push(s):o[i]={client:d,tasks:[s]},o},{});try{console.time("Contentful: fetch entry batch"),await Promise.all(Object.values(l).map(async o=>{var d;let{context:s,component:f}=o.tasks[0].args,C=(d=n==null?void 0:n({component:f,defaultQuery:{...x},context:s}))!=null?d:x,p=new h.UniqueBatchEntries(o.tasks,i=>E(i.parameter.value)?i.parameter.value:i.parameter.value.entryId),m=Object.keys(p.groups);(await o.client.getEntries({"sys.id[in]":m.join(","),limit:m.length,...C})).items.forEach(i=>{p.resolveKey(i.sys.id,i)}),p.resolveRemaining(null)})),console.timeEnd("Contentful: fetch entry batch")}catch(o){let s=R(o),f=new Error(`Failed loading Contentful entries batch (${c.length}) ${s}`);c.forEach(C=>C.reject(f))}},shouldQueue:({parameter:c})=>T(c),limitPolicy:v}):{enhanceOne:async function({parameter:l,parameterName:o,component:s,context:f}){var C,p;if(T(l)){if(!O(l.value))return null;let m=V({clients:g,parameterName:o,parameterValue:l.value,component:s,context:f}),a=E(l.value)?l.value:l.value.entryId,d=(C=n==null?void 0:n({parameter:l,parameterName:o,component:s,defaultQuery:{...x},context:f}))!=null?C:x;try{return console.time(`fetch entry ${a}`),await m.getEntry(a,d)}catch(i){let P=R(i);throw E(l.value)?new Error(`Failed loading Contentful entry '${l.value}' referenced in parameter '${o}': ${P}`):new Error(`Failed loading Contentful entry '${a}' from source '${(p=l.value.source)!=null?p:"default"}' referenced in parameter '${o}': ${P}`)}finally{console.timeEnd(`fetch entry ${a}`)}}},limitPolicy:v}}function T(e){var t;return e.type===S[0]&&(((t=e.value)==null?void 0:t.entryId)||typeof e.value=="string")}function R(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 E(e){return typeof e=="string"}function O(e){return!(!e||!E(e)&&!e.entryId)}function V({clients:e,parameterValue:t,parameterName:n,component:r,context:y}){if(E(t)){let v=e.getClient({isPreviewClient:y.preview});if(!v)throw new Error(`Parameter '${n}' in component '${r.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 v}let{source:u="default"}=t,g=e.getClient({source:u,isPreviewClient:y.preview});if(!g)throw new Error(`No Contentful client could be resolved for source key '${u}' referenced in parameter '${n} in component '${r.type}'. Ensure that the 'clients' property you are passing to the enhancer has a client instance registered for the source key.`);return g}var I=L(require("@contentful/rich-text-html-renderer")),K=({parameter:e})=>{var t,n,r;return typeof((t=e.value)==null?void 0:t.fields)!="object"||Object.entries((r=(n=e.value)==null?void 0:n.fields)!=null?r:{}).forEach(([y,u])=>{typeof u=="object"&&"nodeType"in u&&u.nodeType==="document"&&(e.value.fields[y]=(0,I.documentToHtmlString)(u))}),e.value};0&&(module.exports={CANVAS_CONTENTFUL_PARAMETER_TYPES,ContentfulClientList,contentfulRichTextToHtmlEnhancer,createContentfulEnhancer});
1
+ var F=Object.create;var A=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var $=e=>A(e,"__esModule",{value:!0});var H=(e,t)=>{$(e);for(var n in t)A(e,n,{get:t[n],enumerable:!0})},K=(e,t,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of N(t))!B.call(e,r)&&r!=="default"&&A(e,r,{get:()=>t[r],enumerable:!(n=j(t,r))||n.enumerable});return e},L=e=>K($(A(e!=null?F(_(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);H(exports,{CANVAS_CONTENTFUL_PARAMETER_TYPES:()=>S,ContentfulClientList:()=>P,contentfulRichTextToHtmlEnhancer:()=>G,createContentfulEnhancer:()=>D});var h=L(require("@uniformdev/canvas"));var P=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:r}){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:r||n}}getClient({source:t="default",isPreviewClient:n}){let r=this._clients[t];if(!!r)return n?r.previewClient:r.client}};var x={select:"fields",include:1},S=Object.freeze(["contentfulEntry"]);function Y(e){return e instanceof P}function D({client:e,previewClient:t,createQuery:n,useBatching:r,limitPolicy:d}){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 g=(()=>{if(Y(e))return e;let c=new P;return c.addClient({client:e,previewClient:t}),c})(),v=d||(0,h.createLimitPolicy)({throttle:{limit:55,interval:1e3}});return r?(0,h.createBatchEnhancer)({handleBatch:async c=>{var y;let i=c.reduce((o,l)=>{let{parameter:p,parameterName:m,component:w,context:a}=l.args,u=p.value;if(!O(u))return o;let f=V({parameterValue:u,parameterName:m,clients:g,component:w,context:a}),s="";if(E(u))s="legacy-group";else{let{source:I="default"}=u;s=I}return o[s]&&Array.isArray(o[s].tasks)?o[s].tasks.push(l):o[s]={client:f,tasks:[l]},o},{});try{console.time("fetch all entries");for await(let[o,l]of Object.entries(i)){let{context:p,component:m}=l.tasks[0].args,w=(y=n==null?void 0:n({component:m,defaultQuery:{...x},context:p}))!=null?y:x,a=new h.UniqueBatchEntries(l.tasks,f=>E(f.parameter.value)?f.parameter.value:f.parameter.value.entryId),u=Object.keys(a.groups);console.time(`fetch entries ${o}`);try{(await l.client.getEntries({"sys.id[in]":u.join(","),limit:u.length,...w})).items.forEach(s=>{a.resolveKey(s.sys.id,s)}),a.resolveRemaining(null)}finally{console.timeEnd(`fetch entries ${o}`)}}console.timeEnd("fetch all entries")}catch(o){let l=R(o),p=new Error(`Failed loading Contentful entries batch (${c.length}) ${l}`);c.forEach(m=>m.reject(p))}},shouldQueue:({parameter:c})=>T(c),limitPolicy:v}):{enhanceOne:async function({parameter:i,parameterName:y,component:o,context:l}){var p,m;if(T(i)){if(!O(i.value))return null;let w=V({clients:g,parameterName:y,parameterValue:i.value,component:o,context:l}),a=E(i.value)?i.value:i.value.entryId,u=(p=n==null?void 0:n({parameter:i,parameterName:y,component:o,defaultQuery:{...x},context:l}))!=null?p:x;try{return console.time(`fetch entry ${a}`),await w.getEntry(a,u)}catch(f){let s=R(f);throw E(i.value)?new Error(`Failed loading Contentful entry '${i.value}' referenced in parameter '${y}': ${s}`):new Error(`Failed loading Contentful entry '${a}' from source '${(m=i.value.source)!=null?m:"default"}' referenced in parameter '${y}': ${s}`)}finally{console.timeEnd(`fetch entry ${a}`)}}},limitPolicy:v}}function T(e){var t;return e.type===S[0]&&(((t=e.value)==null?void 0:t.entryId)||typeof e.value=="string")}function R(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 E(e){return typeof e=="string"}function O(e){return!(!e||!E(e)&&!e.entryId)}function V({clients:e,parameterValue:t,parameterName:n,component:r,context:d}){if(E(t)){let v=e.getClient({isPreviewClient:d.preview});if(!v)throw new Error(`Parameter '${n}' in component '${r.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 v}let{source:C="default"}=t,g=e.getClient({source:C,isPreviewClient:d.preview});if(!g)throw new Error(`No Contentful client could be resolved for source key '${C}' referenced in parameter '${n} in component '${r.type}'. Ensure that the 'clients' property you are passing to the enhancer has a client instance registered for the source key.`);return g}var k=L(require("@contentful/rich-text-html-renderer")),G=({parameter:e})=>{var t,n,r;return typeof((t=e.value)==null?void 0:t.fields)!="object"||Object.entries((r=(n=e.value)==null?void 0:n.fields)!=null?r:{}).forEach(([d,C])=>{typeof C=="object"&&"nodeType"in C&&C.nodeType==="document"&&(e.value.fields[d]=(0,k.documentToHtmlString)(C))}),e.value};0&&(module.exports={CANVAS_CONTENTFUL_PARAMETER_TYPES,ContentfulClientList,contentfulRichTextToHtmlEnhancer,createContentfulEnhancer});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{createBatchEnhancer as L,UniqueBatchEntries as S,createLimitPolicy as T}from"@uniformdev/canvas";var w=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:i}){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:i||n}}getClient({source:t="default",isPreviewClient:n}){let i=this._clients[t];if(!!i)return n?i.previewClient:i.client}};var P={select:"fields",include:1},R=Object.freeze(["contentfulEntry"]);function O(e){return e instanceof w}function Y({client:e,previewClient:t,createQuery:n,useBatching:i,limitPolicy:y}){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 E=(()=>{if(O(e))return e;let c=new w;return c.addClient({client:e,previewClient:t}),c})(),g=y||T({throttle:{limit:55,interval:1e3}});return i?L({handleBatch:async c=>{let l=c.reduce((r,s)=>{let{parameter:f,parameterName:C,component:p,context:m}=s.args,a=f.value;if(!b(a))return r;let d=$({parameterValue:a,parameterName:C,clients:E,component:p,context:m}),o="";if(h(a))o="legacy-group";else{let{source:v="default"}=a;o=v}return r[o]&&Array.isArray(r[o].tasks)?r[o].tasks.push(s):r[o]={client:d,tasks:[s]},r},{});try{console.time("Contentful: fetch entry batch"),await Promise.all(Object.values(l).map(async r=>{var d;let{context:s,component:f}=r.tasks[0].args,C=(d=n==null?void 0:n({component:f,defaultQuery:{...P},context:s}))!=null?d:P,p=new S(r.tasks,o=>h(o.parameter.value)?o.parameter.value:o.parameter.value.entryId),m=Object.keys(p.groups);(await r.client.getEntries({"sys.id[in]":m.join(","),limit:m.length,...C})).items.forEach(o=>{p.resolveKey(o.sys.id,o)}),p.resolveRemaining(null)})),console.timeEnd("Contentful: fetch entry batch")}catch(r){let s=x(r),f=new Error(`Failed loading Contentful entries batch (${c.length}) ${s}`);c.forEach(C=>C.reject(f))}},shouldQueue:({parameter:c})=>A(c),limitPolicy:g}):{enhanceOne:async function({parameter:l,parameterName:r,component:s,context:f}){var C,p;if(A(l)){if(!b(l.value))return null;let m=$({clients:E,parameterName:r,parameterValue:l.value,component:s,context:f}),a=h(l.value)?l.value:l.value.entryId,d=(C=n==null?void 0:n({parameter:l,parameterName:r,component:s,defaultQuery:{...P},context:f}))!=null?C:P;try{return console.time(`fetch entry ${a}`),await m.getEntry(a,d)}catch(o){let v=x(o);throw h(l.value)?new Error(`Failed loading Contentful entry '${l.value}' referenced in parameter '${r}': ${v}`):new Error(`Failed loading Contentful entry '${a}' from source '${(p=l.value.source)!=null?p:"default"}' referenced in parameter '${r}': ${v}`)}finally{console.timeEnd(`fetch entry ${a}`)}}},limitPolicy:g}}function A(e){var t;return e.type===R[0]&&(((t=e.value)==null?void 0:t.entryId)||typeof e.value=="string")}function x(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 h(e){return typeof e=="string"}function b(e){return!(!e||!h(e)&&!e.entryId)}function $({clients:e,parameterValue:t,parameterName:n,component:i,context:y}){if(h(t)){let g=e.getClient({isPreviewClient:y.preview});if(!g)throw new Error(`Parameter '${n}' in component '${i.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 g}let{source:u="default"}=t,E=e.getClient({source:u,isPreviewClient:y.preview});if(!E)throw new Error(`No Contentful client could be resolved for source key '${u}' referenced in parameter '${n} in component '${i.type}'. Ensure that the 'clients' property you are passing to the enhancer has a client instance registered for the source key.`);return E}import{documentToHtmlString as V}from"@contentful/rich-text-html-renderer";var M=({parameter:e})=>{var t,n,i;return typeof((t=e.value)==null?void 0:t.fields)!="object"||Object.entries((i=(n=e.value)==null?void 0:n.fields)!=null?i:{}).forEach(([y,u])=>{typeof u=="object"&&"nodeType"in u&&u.nodeType==="document"&&(e.value.fields[y]=V(u))}),e.value};export{R as CANVAS_CONTENTFUL_PARAMETER_TYPES,w as ContentfulClientList,M as contentfulRichTextToHtmlEnhancer,Y as createContentfulEnhancer};
1
+ import{createBatchEnhancer as S,UniqueBatchEntries as T,createLimitPolicy as R}from"@uniformdev/canvas";var w=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 P={select:"fields",include:1},O=Object.freeze(["contentfulEntry"]);function V(e){return e instanceof w}function Y({client:e,previewClient:t,createQuery:n,useBatching:o,limitPolicy:d}){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 E=(()=>{if(V(e))return e;let c=new w;return c.addClient({client:e,previewClient:t}),c})(),g=d||R({throttle:{limit:55,interval:1e3}});return o?S({handleBatch:async c=>{var y;let i=c.reduce((r,l)=>{let{parameter:p,parameterName:m,component:v,context:a}=l.args,u=p.value;if(!b(u))return r;let f=$({parameterValue:u,parameterName:m,clients:E,component:v,context:a}),s="";if(h(u))s="legacy-group";else{let{source:L="default"}=u;s=L}return r[s]&&Array.isArray(r[s].tasks)?r[s].tasks.push(l):r[s]={client:f,tasks:[l]},r},{});try{console.time("fetch all entries");for await(let[r,l]of Object.entries(i)){let{context:p,component:m}=l.tasks[0].args,v=(y=n==null?void 0:n({component:m,defaultQuery:{...P},context:p}))!=null?y:P,a=new T(l.tasks,f=>h(f.parameter.value)?f.parameter.value:f.parameter.value.entryId),u=Object.keys(a.groups);console.time(`fetch entries ${r}`);try{(await l.client.getEntries({"sys.id[in]":u.join(","),limit:u.length,...v})).items.forEach(s=>{a.resolveKey(s.sys.id,s)}),a.resolveRemaining(null)}finally{console.timeEnd(`fetch entries ${r}`)}}console.timeEnd("fetch all entries")}catch(r){let l=x(r),p=new Error(`Failed loading Contentful entries batch (${c.length}) ${l}`);c.forEach(m=>m.reject(p))}},shouldQueue:({parameter:c})=>A(c),limitPolicy:g}):{enhanceOne:async function({parameter:i,parameterName:y,component:r,context:l}){var p,m;if(A(i)){if(!b(i.value))return null;let v=$({clients:E,parameterName:y,parameterValue:i.value,component:r,context:l}),a=h(i.value)?i.value:i.value.entryId,u=(p=n==null?void 0:n({parameter:i,parameterName:y,component:r,defaultQuery:{...P},context:l}))!=null?p:P;try{return console.time(`fetch entry ${a}`),await v.getEntry(a,u)}catch(f){let s=x(f);throw h(i.value)?new Error(`Failed loading Contentful entry '${i.value}' referenced in parameter '${y}': ${s}`):new Error(`Failed loading Contentful entry '${a}' from source '${(m=i.value.source)!=null?m:"default"}' referenced in parameter '${y}': ${s}`)}finally{console.timeEnd(`fetch entry ${a}`)}}},limitPolicy:g}}function A(e){var t;return e.type===O[0]&&(((t=e.value)==null?void 0:t.entryId)||typeof e.value=="string")}function x(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 h(e){return typeof e=="string"}function b(e){return!(!e||!h(e)&&!e.entryId)}function $({clients:e,parameterValue:t,parameterName:n,component:o,context:d}){if(h(t)){let g=e.getClient({isPreviewClient:d.preview});if(!g)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 g}let{source:C="default"}=t,E=e.getClient({source:C,isPreviewClient:d.preview});if(!E)throw new Error(`No Contentful client could be resolved for source key '${C}' 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 E}import{documentToHtmlString as k}from"@contentful/rich-text-html-renderer";var M=({parameter:e})=>{var t,n,o;return typeof((t=e.value)==null?void 0:t.fields)!="object"||Object.entries((o=(n=e.value)==null?void 0:n.fields)!=null?o:{}).forEach(([d,C])=>{typeof C=="object"&&"nodeType"in C&&C.nodeType==="document"&&(e.value.fields[d]=k(C))}),e.value};export{O as CANVAS_CONTENTFUL_PARAMETER_TYPES,w as ContentfulClientList,M as contentfulRichTextToHtmlEnhancer,Y as createContentfulEnhancer};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-contentful",
3
- "version": "12.2.1-alpha.39+d7525732",
3
+ "version": "12.2.1-alpha.59+ee5a4745",
4
4
  "description": "Contentful data enhancers for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -25,7 +25,7 @@
25
25
  "ci:build": "tsup --minify --clean"
26
26
  },
27
27
  "dependencies": {
28
- "@uniformdev/canvas": "^12.2.1-alpha.39+d7525732"
28
+ "@uniformdev/canvas": "^12.2.1-alpha.59+ee5a4745"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "@contentful/rich-text-html-renderer": ">= 14",
@@ -33,17 +33,17 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "@contentful/rich-text-html-renderer": "15.4.0",
36
- "@types/jest": "27.0.2",
36
+ "@types/jest": "27.0.3",
37
37
  "@types/node": "16.7.1",
38
38
  "contentful": "9.1.4",
39
39
  "eslint": "7.32.0",
40
- "eslint-plugin-react": "7.26.1",
41
- "eslint-plugin-react-hooks": "4.2.0",
40
+ "eslint-plugin-react": "7.27.1",
41
+ "eslint-plugin-react-hooks": "4.3.0",
42
42
  "jest": "27.3.1",
43
43
  "npm-run-all": "4.1.5",
44
44
  "rimraf": "3.0.2",
45
45
  "ts-jest": "27.0.7",
46
- "tsup": "5.6.0"
46
+ "tsup": "5.7.2"
47
47
  },
48
48
  "files": [
49
49
  "/dist"
@@ -51,5 +51,5 @@
51
51
  "publishConfig": {
52
52
  "access": "public"
53
53
  },
54
- "gitHead": "d752573207ec468ccf0479f90e06cc252a74c84e"
54
+ "gitHead": "ee5a4745535ac342d62ba2472e2a681c9867255b"
55
55
  }