@uniformdev/canvas-contentful 16.2.4 → 17.1.1-alpha.151
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 +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +4 -4
package/dist/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createBatchEnhancer as I,UniqueBatchEntries as Q}from"@uniformdev/canvas";var x=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}};import{createLimitPolicy as N}from"@uniformdev/canvas";var v=N({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 L(e,t){if(!!e)return`${t==="desc"?"-":""}${e}`}function A({clients:e,parameterValue:t,parameterName:n,component:o,context:
|
|
1
|
+
import{createBatchEnhancer as I,UniqueBatchEntries as Q}from"@uniformdev/canvas";var x=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}};import{createLimitPolicy as N}from"@uniformdev/canvas";var v=N({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 L(e,t){if(!!e)return`${t==="desc"?"-":""}${e}`}function A({clients:e,parameterValue:t,parameterName:n,component:o,context:E}){let{source:i="default"}=t,l=e.getClient({source:i,isPreviewClient:E.preview});if(!l)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 l}var T={select:"fields",include:1},k=Object.freeze(["contentfulEntry"]);function S(e){return e instanceof x}function ae({client:e,previewClient:t,createQuery:n,useBatching:o,limitPolicy:E}){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 l=(()=>{if(S(e))return e;let s=new x;return s.addClient({client:e,previewClient:t}),s})(),y=E||v;return o?I({handleBatch:async s=>{var f;let u=s.reduce((a,r)=>{let{parameter:C,parameterName:c,component:d,context:m}=r.args,h=C.value;if(!V(h))return a;let g=O({parameterValue:h,parameterName:c,clients:l,component:d,context:m}),p="";if(w(h))p="legacy-group";else{let{source:M="default"}=h;p=M}return a[p]&&Array.isArray(a[p].tasks)?a[p].tasks.push(r):a[p]={client:g,tasks:[r]},a},{});try{console.time("fetch all entries");for await(let[a,r]of Object.entries(u)){let{context:C,component:c}=r.tasks[0].args,d=(f=n==null?void 0:n({component:c,defaultQuery:{...T},context:C}))!=null?f:T,m=new Q(r.tasks,g=>w(g.parameter.value)?g.parameter.value:g.parameter.value.entryId),h=Object.keys(m.groups);console.time(`fetch entries ${a}`);try{(await r.client.getEntries({"sys.id[in]":h.join(","),limit:h.length,...d})).items.forEach(p=>{m.resolveKey(p.sys.id,p)}),m.resolveRemaining(null)}finally{console.timeEnd(`fetch entries ${a}`)}}console.timeEnd("fetch all entries")}catch(a){let r=P(a),C=new Error(`Failed loading Contentful entries batch (${s.length}) ${r}`);s.forEach(c=>c.reject(C))}},shouldQueue:({parameter:s})=>$(s),limitPolicy:y}):{enhanceOne:async function({parameter:u,parameterName:f,component:a,context:r}){var C,c;if($(u)){if(!V(u.value))return null;let d=O({clients:l,parameterName:f,parameterValue:u.value,component:a,context:r}),m=w(u.value)?u.value:u.value.entryId,h=(C=n==null?void 0:n({parameter:u,parameterName:f,component:a,defaultQuery:{...T},context:r}))!=null?C:T;try{return console.time(`fetch entry ${m}`),await d.getEntry(m,h)}catch(g){let p=P(g);throw w(u.value)?new Error(`Failed loading Contentful entry '${u.value}' referenced in parameter '${f}': ${p}`):new Error(`Failed loading Contentful entry '${m}' from source '${(c=u.value.source)!=null?c:"default"}' referenced in parameter '${f}': ${p}`)}finally{console.timeEnd(`fetch entry ${m}`)}}},limitPolicy:y}}function $(e){var t;return e.type===k[0]&&(((t=e.value)==null?void 0:t.entryId)||typeof e.value=="string")}function w(e){return typeof e=="string"}function V(e){return!(!e||!w(e)&&!e.entryId)}function O({clients:e,parameterValue:t,parameterName:n,component:o,context:E}){if(w(t)){let y=e.getClient({isPreviewClient:E.preview});if(!y)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 y}let{source:i="default"}=t,l=e.getClient({source:i,isPreviewClient:E.preview});if(!l)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 l}var R={select:"fields",include:1},_=Object.freeze(["contentfulMultiEntry"]);function fe({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:l,component:y,context:s}){var u,f;if(j(i)){if(!Y(i.value))return null;let a=A({clients:e,parameterName:l,parameterValue:i.value,component:y,context:s}),r=i.value.entries,C=(u=t==null?void 0:t({parameter:i,parameterName:l,component:y,defaultQuery:{...R},context:s}))!=null?u:R;try{console.time(`fetch entries ${r.join()}`);let c=await a.getEntries({"sys.id[in]":r.join(),limit:r.length,...C});return B(c.items,r)}catch(c){let d=P(c);throw new Error(`Failed loading Contentful entries '${r.join()}' from source '${(f=i.value.source)!=null?f:"default"}' referenced in parameter '${l}': ${d}`)}finally{console.timeEnd(`fetch entries ${r.join()}`)}}},limitPolicy:n||v}}function j(e){return e.type===_[0]}function Y(e){var t;return!(!e||!((t=e.entries)!=null&&t.length))}function B(e,t){var o;if(!e.length||!((o=e[0].sys)!=null&&o.id))return e;let n=[];for(let E of t){let i=e.find(l=>l.sys.id===E);i&&n.push(i)}return n}var U=Object.freeze(["contentfulQuery"]),b={select:"fields",include:1};function pe({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:l,component:y,context:s}){var u,f;if(q(i)){if(!D(i.value))return null;let a=A({clients:e,parameterName:l,parameterValue:i.value,component:y,context:s}),r=i.value,C=z(r.count),c=(u=t==null?void 0:t({parameter:i,parameterName:l,component:y,defaultQuery:{...b},context:s}))!=null?u:b,d=`fetch query: ${C} entries with '${r.contentType}' content type`;try{return console.time(d),(await a.getEntries({content_type:r.contentType,order:L(r.sortBy,r.sortOrder),limit:C,...c})).items}catch(m){let h=P(m);throw new Error(`Failed loading Contentful entries with '${r.contentType}' content type from source '${(f=r.source)!=null?f:"default"}' referenced in parameter '${l}': ${h}`)}finally{console.timeEnd(d)}}},limitPolicy:n||v}}function q(e){return e.type===U[0]}function D(e){return!(!e||!e.source||!e.contentType||typeof e.count=="undefined")}function z(e){return!e||e<1?1:e>1e3?1e3:e}import{documentToHtmlString as K}from"@contentful/rich-text-html-renderer";var he=({parameter:e})=>{let t=e.value;if(!t)return t;if(!G(t))return F(t),t;for(let n of t)F(n);return t};function F(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]=K(o))})}function G(e){return Array.isArray(e)}export{_ as CANVAS_CONTENTFUL_MULTI_PARAMETER_TYPES,k as CANVAS_CONTENTFUL_PARAMETER_TYPES,U as CANVAS_CONTENTFUL_QUERY_PARAMETER_TYPES,x as ContentfulClientList,he as contentfulRichTextToHtmlEnhancer,ae as createContentfulEnhancer,fe as createContentfulMultiEnhancer,pe as createContentfulQueryEnhancer};
|
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
|
|
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 s of B(t))!U.call(e,s)&&s!==n&&$(e,s,{get:()=>t[s],enumerable:!(o=Y(t,s))||o.enumerable});return e};var z=e=>D($({},"__esModule",{value:!0}),e);var ie={};q(ie,{CANVAS_CONTENTFUL_MULTI_PARAMETER_TYPES:()=>I,CANVAS_CONTENTFUL_PARAMETER_TYPES:()=>M,CANVAS_CONTENTFUL_QUERY_PARAMETER_TYPES:()=>k,ContentfulClientList:()=>v,contentfulRichTextToHtmlEnhancer:()=>re,createContentfulEnhancer:()=>G,createContentfulMultiEnhancer:()=>H,createContentfulQueryEnhancer:()=>Z});module.exports=z(ie);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:s}){let{source:i="default"}=t,l=e.getClient({source:i,isPreviewClient:s.preview});if(!l)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 l}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:s}){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 l=(()=>{if(K(e))return e;let c=new v;return c.addClient({client:e,previewClient:t}),c})(),d=s||w;return o?(0,L.createBatchEnhancer)({handleBatch:async c=>{var C;let u=c.reduce((a,r)=>{let{parameter:m,parameterName:f,component:h,context:p}=r.args,E=m.value;if(!b(E))return a;let g=F({parameterValue:E,parameterName:f,clients:l,component:h,context:p}),y="";if(x(E))y="legacy-group";else{let{source:j="default"}=E;y=j}return a[y]&&Array.isArray(a[y].tasks)?a[y].tasks.push(r):a[y]={client:g,tasks:[r]},a},{});try{console.time("fetch all entries");for await(let[a,r]of Object.entries(u)){let{context:m,component:f}=r.tasks[0].args,h=(C=n==null?void 0:n({component:f,defaultQuery:{...T},context:m}))!=null?C:T,p=new L.UniqueBatchEntries(r.tasks,g=>x(g.parameter.value)?g.parameter.value:g.parameter.value.entryId),E=Object.keys(p.groups);console.time(`fetch entries ${a}`);try{(await r.client.getEntries({"sys.id[in]":E.join(","),limit:E.length,...h})).items.forEach(y=>{p.resolveKey(y.sys.id,y)}),p.resolveRemaining(null)}finally{console.timeEnd(`fetch entries ${a}`)}}console.timeEnd("fetch all entries")}catch(a){let r=P(a),m=new Error(`Failed loading Contentful entries batch (${c.length}) ${r}`);c.forEach(f=>f.reject(m))}},shouldQueue:({parameter:c})=>R(c),limitPolicy:d}):{enhanceOne:async function({parameter:u,parameterName:C,component:a,context:r}){var m,f;if(R(u)){if(!b(u.value))return null;let h=F({clients:l,parameterName:C,parameterValue:u.value,component:a,context:r}),p=x(u.value)?u.value:u.value.entryId,E=(m=n==null?void 0:n({parameter:u,parameterName:C,component:a,defaultQuery:{...T},context:r}))!=null?m:T;try{return console.time(`fetch entry ${p}`),await h.getEntry(p,E)}catch(g){let y=P(g);throw x(u.value)?new Error(`Failed loading Contentful entry '${u.value}' referenced in parameter '${C}': ${y}`):new Error(`Failed loading Contentful entry '${p}' from source '${(f=u.value.source)!=null?f:"default"}' referenced in parameter '${C}': ${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:s}){if(x(t)){let d=e.getClient({isPreviewClient:s.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,l=e.getClient({source:i,isPreviewClient:s.preview});if(!l)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 l}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:l,component:d,context:c}){var u,C;if(J(i)){if(!W(i.value))return null;let a=A({clients:e,parameterName:l,parameterValue:i.value,component:d,context:c}),r=i.value.entries,m=(u=t==null?void 0:t({parameter:i,parameterName:l,component:d,defaultQuery:{...N},context:c}))!=null?u:N;try{console.time(`fetch entries ${r.join()}`);let f=await a.getEntries({"sys.id[in]":r.join(),limit:r.length,...m});return X(f.items,r)}catch(f){let h=P(f);throw new Error(`Failed loading Contentful entries '${r.join()}' from source '${(C=i.value.source)!=null?C:"default"}' referenced in parameter '${l}': ${h}`)}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))}function X(e,t){var o;if(!e.length||!((o=e[0].sys)!=null&&o.id))return e;let n=[];for(let s of t){let i=e.find(l=>l.sys.id===s);i&&n.push(i)}return n}var k=Object.freeze(["contentfulQuery"]),Q={select:"fields",include:1};function Z({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:l,component:d,context:c}){var u,C;if(ee(i)){if(!te(i.value))return null;let a=A({clients:e,parameterName:l,parameterValue:i.value,component:d,context:c}),r=i.value,m=ne(r.count),f=(u=t==null?void 0:t({parameter:i,parameterName:l,component:d,defaultQuery:{...Q},context:c}))!=null?u:Q,h=`fetch query: ${m} entries with '${r.contentType}' content type`;try{return console.time(h),(await a.getEntries({content_type:r.contentType,order:O(r.sortBy,r.sortOrder),limit:m,...f})).items}catch(p){let E=P(p);throw new Error(`Failed loading Contentful entries with '${r.contentType}' content type from source '${(C=r.source)!=null?C:"default"}' referenced in parameter '${l}': ${E}`)}finally{console.timeEnd(h)}}},limitPolicy:n||w}}function ee(e){return e.type===k[0]}function te(e){return!(!e||!e.source||!e.contentType||typeof e.count=="undefined")}function ne(e){return!e||e<1?1:e>1e3?1e3:e}var _=require("@contentful/rich-text-html-renderer"),re=({parameter:e})=>{let t=e.value;if(!t)return t;if(!oe(t))return S(t),t;for(let n of t)S(n);return t};function S(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,_.documentToHtmlString)(o))})}function oe(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/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createBatchEnhancer as I,UniqueBatchEntries as Q}from"@uniformdev/canvas";var x=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}};import{createLimitPolicy as N}from"@uniformdev/canvas";var v=N({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 L(e,t){if(!!e)return`${t==="desc"?"-":""}${e}`}function A({clients:e,parameterValue:t,parameterName:n,component:o,context:
|
|
1
|
+
import{createBatchEnhancer as I,UniqueBatchEntries as Q}from"@uniformdev/canvas";var x=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}};import{createLimitPolicy as N}from"@uniformdev/canvas";var v=N({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 L(e,t){if(!!e)return`${t==="desc"?"-":""}${e}`}function A({clients:e,parameterValue:t,parameterName:n,component:o,context:E}){let{source:i="default"}=t,l=e.getClient({source:i,isPreviewClient:E.preview});if(!l)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 l}var T={select:"fields",include:1},k=Object.freeze(["contentfulEntry"]);function S(e){return e instanceof x}function ae({client:e,previewClient:t,createQuery:n,useBatching:o,limitPolicy:E}){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 l=(()=>{if(S(e))return e;let s=new x;return s.addClient({client:e,previewClient:t}),s})(),y=E||v;return o?I({handleBatch:async s=>{var f;let u=s.reduce((a,r)=>{let{parameter:C,parameterName:c,component:d,context:m}=r.args,h=C.value;if(!V(h))return a;let g=O({parameterValue:h,parameterName:c,clients:l,component:d,context:m}),p="";if(w(h))p="legacy-group";else{let{source:M="default"}=h;p=M}return a[p]&&Array.isArray(a[p].tasks)?a[p].tasks.push(r):a[p]={client:g,tasks:[r]},a},{});try{console.time("fetch all entries");for await(let[a,r]of Object.entries(u)){let{context:C,component:c}=r.tasks[0].args,d=(f=n==null?void 0:n({component:c,defaultQuery:{...T},context:C}))!=null?f:T,m=new Q(r.tasks,g=>w(g.parameter.value)?g.parameter.value:g.parameter.value.entryId),h=Object.keys(m.groups);console.time(`fetch entries ${a}`);try{(await r.client.getEntries({"sys.id[in]":h.join(","),limit:h.length,...d})).items.forEach(p=>{m.resolveKey(p.sys.id,p)}),m.resolveRemaining(null)}finally{console.timeEnd(`fetch entries ${a}`)}}console.timeEnd("fetch all entries")}catch(a){let r=P(a),C=new Error(`Failed loading Contentful entries batch (${s.length}) ${r}`);s.forEach(c=>c.reject(C))}},shouldQueue:({parameter:s})=>$(s),limitPolicy:y}):{enhanceOne:async function({parameter:u,parameterName:f,component:a,context:r}){var C,c;if($(u)){if(!V(u.value))return null;let d=O({clients:l,parameterName:f,parameterValue:u.value,component:a,context:r}),m=w(u.value)?u.value:u.value.entryId,h=(C=n==null?void 0:n({parameter:u,parameterName:f,component:a,defaultQuery:{...T},context:r}))!=null?C:T;try{return console.time(`fetch entry ${m}`),await d.getEntry(m,h)}catch(g){let p=P(g);throw w(u.value)?new Error(`Failed loading Contentful entry '${u.value}' referenced in parameter '${f}': ${p}`):new Error(`Failed loading Contentful entry '${m}' from source '${(c=u.value.source)!=null?c:"default"}' referenced in parameter '${f}': ${p}`)}finally{console.timeEnd(`fetch entry ${m}`)}}},limitPolicy:y}}function $(e){var t;return e.type===k[0]&&(((t=e.value)==null?void 0:t.entryId)||typeof e.value=="string")}function w(e){return typeof e=="string"}function V(e){return!(!e||!w(e)&&!e.entryId)}function O({clients:e,parameterValue:t,parameterName:n,component:o,context:E}){if(w(t)){let y=e.getClient({isPreviewClient:E.preview});if(!y)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 y}let{source:i="default"}=t,l=e.getClient({source:i,isPreviewClient:E.preview});if(!l)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 l}var R={select:"fields",include:1},_=Object.freeze(["contentfulMultiEntry"]);function fe({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:l,component:y,context:s}){var u,f;if(j(i)){if(!Y(i.value))return null;let a=A({clients:e,parameterName:l,parameterValue:i.value,component:y,context:s}),r=i.value.entries,C=(u=t==null?void 0:t({parameter:i,parameterName:l,component:y,defaultQuery:{...R},context:s}))!=null?u:R;try{console.time(`fetch entries ${r.join()}`);let c=await a.getEntries({"sys.id[in]":r.join(),limit:r.length,...C});return B(c.items,r)}catch(c){let d=P(c);throw new Error(`Failed loading Contentful entries '${r.join()}' from source '${(f=i.value.source)!=null?f:"default"}' referenced in parameter '${l}': ${d}`)}finally{console.timeEnd(`fetch entries ${r.join()}`)}}},limitPolicy:n||v}}function j(e){return e.type===_[0]}function Y(e){var t;return!(!e||!((t=e.entries)!=null&&t.length))}function B(e,t){var o;if(!e.length||!((o=e[0].sys)!=null&&o.id))return e;let n=[];for(let E of t){let i=e.find(l=>l.sys.id===E);i&&n.push(i)}return n}var U=Object.freeze(["contentfulQuery"]),b={select:"fields",include:1};function pe({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:l,component:y,context:s}){var u,f;if(q(i)){if(!D(i.value))return null;let a=A({clients:e,parameterName:l,parameterValue:i.value,component:y,context:s}),r=i.value,C=z(r.count),c=(u=t==null?void 0:t({parameter:i,parameterName:l,component:y,defaultQuery:{...b},context:s}))!=null?u:b,d=`fetch query: ${C} entries with '${r.contentType}' content type`;try{return console.time(d),(await a.getEntries({content_type:r.contentType,order:L(r.sortBy,r.sortOrder),limit:C,...c})).items}catch(m){let h=P(m);throw new Error(`Failed loading Contentful entries with '${r.contentType}' content type from source '${(f=r.source)!=null?f:"default"}' referenced in parameter '${l}': ${h}`)}finally{console.timeEnd(d)}}},limitPolicy:n||v}}function q(e){return e.type===U[0]}function D(e){return!(!e||!e.source||!e.contentType||typeof e.count=="undefined")}function z(e){return!e||e<1?1:e>1e3?1e3:e}import{documentToHtmlString as K}from"@contentful/rich-text-html-renderer";var he=({parameter:e})=>{let t=e.value;if(!t)return t;if(!G(t))return F(t),t;for(let n of t)F(n);return t};function F(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]=K(o))})}function G(e){return Array.isArray(e)}export{_ as CANVAS_CONTENTFUL_MULTI_PARAMETER_TYPES,k as CANVAS_CONTENTFUL_PARAMETER_TYPES,U as CANVAS_CONTENTFUL_QUERY_PARAMETER_TYPES,x as ContentfulClientList,he as contentfulRichTextToHtmlEnhancer,ae as createContentfulEnhancer,fe as createContentfulMultiEnhancer,pe as createContentfulQueryEnhancer};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-contentful",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "17.1.1-alpha.151+3c57dd245",
|
|
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": "^
|
|
26
|
+
"@uniformdev/canvas": "^17.1.1-alpha.151+3c57dd245"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@contentful/rich-text-html-renderer": ">= 14",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@contentful/rich-text-html-renderer": "15.13.1",
|
|
34
|
-
"contentful": "9.1.
|
|
34
|
+
"contentful": "9.1.34"
|
|
35
35
|
},
|
|
36
36
|
"files": [
|
|
37
37
|
"/dist"
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "3c57dd245b59aa55368da8991d1e39bc633bbed8"
|
|
43
43
|
}
|