@uniformdev/canvas-contentful 12.2.1-alpha.51 → 13.0.1-alpha.70

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.d.ts CHANGED
@@ -27,6 +27,19 @@ declare class ContentfulClientList {
27
27
  }): ContentfulClientApi | undefined;
28
28
  }
29
29
 
30
+ /** The default shape of the Contentful entry. Note that this can change if the query is altered. */
31
+ declare type ContentfulEntryResult<TFields> = {
32
+ /**
33
+ * The shape of the `fields` that the Contentful REST API is expected to return for this entry
34
+ * https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/entries/entry
35
+ *
36
+ * These should line up with the fields in your content model(s) that are allowed for this component.
37
+ */
38
+ fields: TFields;
39
+ /** System fields returned by the Contentful API. If you modify the query parameters to fetch more than fields, you may get more sys data than this. */
40
+ sys: Partial<Pick<Sys, 'id' | 'type'>>;
41
+ };
42
+
30
43
  declare type EntrySelectorParameterValue = {
31
44
  entryId: string;
32
45
  source?: string;
@@ -44,17 +57,7 @@ declare type CreateContentfulQueryOptions<TContext extends EnhancerContext = Enh
44
57
  context: TContext;
45
58
  };
46
59
  /** The default shape of the result value of the Contentful enhancer. Note that this can change if the query is altered. */
47
- declare type ContentfulEnhancerResult<TFields> = {
48
- /**
49
- * The shape of the `fields` that the Contentful REST API is expected to return for this entry
50
- * https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/entries/entry
51
- *
52
- * These should line up with the fields in your content model(s) that are allowed for this component.
53
- */
54
- fields: TFields;
55
- /** System fields returned by the Contentful API. If you modify the query parameters to fetch more than fields, you may get more sys data than this. */
56
- sys: Partial<Pick<Sys, 'id' | 'type'>>;
57
- } | null;
60
+ declare type ContentfulEnhancerResult<TFields> = ContentfulEntryResult<TFields> | null;
58
61
  declare type CreateContentfulEnhancerOptions = {
59
62
  /** Either a list of Contentful clients for use with multi-space/environment-enabled Canvas projects.
60
63
  * Or a single Contentful client for use with legacy Canvas data.*/
@@ -72,6 +75,66 @@ declare type CreateContentfulEnhancerOptions = {
72
75
  declare const CANVAS_CONTENTFUL_PARAMETER_TYPES: readonly string[];
73
76
  declare function createContentfulEnhancer({ client, previewClient, createQuery, useBatching, limitPolicy, }: CreateContentfulEnhancerOptions): ComponentParameterEnhancer<EntrySelectorParameterValue, ContentfulEnhancerResult<unknown>>;
74
77
 
75
- declare const contentfulRichTextToHtmlEnhancer: ComponentParameterEnhancerFunction<ContentfulEnhancerResult<unknown>>;
78
+ declare type ContentfulMultiEntryParameterValue = {
79
+ entries: string[];
80
+ source: string;
81
+ } | null | undefined;
82
+ declare type CreateContentfulMultiEntryQueryOptions<TContext extends EnhancerContext = EnhancerContext> = {
83
+ /** Canvas parameter name being queried for */
84
+ parameterName: string;
85
+ /** Canvas parameter value being fetched */
86
+ parameter: ComponentParameter<ContentfulMultiEntryParameterValue>;
87
+ /** Component containing the parameter being fetched */
88
+ component: ComponentInstance;
89
+ /** The default Contentful query expression (select fields + include 1 layer of references) */
90
+ defaultQuery: any;
91
+ /** The enhancer context provided to the enhance() function */
92
+ context: TContext;
93
+ };
94
+ /** The default shape of the result value of the Contentful Multi Entry enhancer. Note that this can change if the query is altered. */
95
+ declare type ContentfulMultiEntryEnhancerResult<TFields> = ContentfulEntryResult<TFields>[] | null;
96
+ declare type CreateContentfulMultiEntryEnhancerOptions = {
97
+ /** Either a list of Contentful clients for use with multi-space/environment-enabled Canvas projects. */
98
+ clients: ContentfulClientList;
99
+ /** Creates the Contentful client's query params for specific parameters. See https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters */
100
+ createQuery?: (options: CreateContentfulMultiEntryQueryOptions) => any | undefined;
101
+ limitPolicy?: LimitPolicy;
102
+ };
103
+ declare const CANVAS_CONTENTFUL_MULTI_PARAMETER_TYPES: readonly string[];
104
+ declare function createContentfulMultiEnhancer({ clients, createQuery, limitPolicy, }: CreateContentfulMultiEntryEnhancerOptions): ComponentParameterEnhancer<ContentfulMultiEntryParameterValue, ContentfulMultiEntryEnhancerResult<unknown>>;
105
+
106
+ declare const CANVAS_CONTENTFUL_QUERY_PARAMETER_TYPES: readonly string[];
107
+ declare type ContentfulQueryParameterValue = {
108
+ source: string;
109
+ contentType: string;
110
+ count: number;
111
+ sortBy?: string;
112
+ sortOrder?: 'asc' | 'desc';
113
+ } | null | undefined;
114
+ /** The default shape of the result value of the Contentful Query enhancer. Note that this can change if the query is altered. */
115
+ declare type ContentfulQueryEnhancerResult<TFields> = ContentfulEntryResult<TFields>[] | null;
116
+ declare type CreateContentfulQueryApiQueryOptions<TContext extends EnhancerContext = EnhancerContext> = {
117
+ /** Canvas parameter name being queried for */
118
+ parameterName: string;
119
+ /** Canvas parameter value being fetched */
120
+ parameter: ComponentParameter<ContentfulQueryParameterValue>;
121
+ /** Component containing the parameter being fetched */
122
+ component: ComponentInstance;
123
+ /** The default Contentful query expression (select fields + include 1 layer of references) */
124
+ defaultQuery: any;
125
+ /** The enhancer context provided to the enhance() function */
126
+ context: TContext;
127
+ };
128
+ declare type CreateContentfulQueryEnhancerOptions = {
129
+ /** Either a list of Contentful clients for use with multi-space/environment-enabled Canvas projects. */
130
+ clients: ContentfulClientList;
131
+ /** Creates the Contentful client's query params for specific parameters. See https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters */
132
+ createQuery?: (options: CreateContentfulQueryApiQueryOptions) => any | undefined;
133
+ limitPolicy?: LimitPolicy;
134
+ };
135
+ declare function createContentfulQueryEnhancer({ clients, createQuery, limitPolicy, }: CreateContentfulQueryEnhancerOptions): ComponentParameterEnhancer<ContentfulQueryParameterValue, ContentfulQueryEnhancerResult<unknown>>;
136
+
137
+ declare type EnhancerValue = ContentfulEntryResult<unknown> | ContentfulEntryResult<unknown>[] | null;
138
+ declare const contentfulRichTextToHtmlEnhancer: ComponentParameterEnhancerFunction<EnhancerValue>;
76
139
 
77
- export { AddClientArgs, CANVAS_CONTENTFUL_PARAMETER_TYPES, ContentfulClientList, ContentfulEnhancerResult, CreateContentfulEnhancerOptions, CreateContentfulQueryOptions, EntrySelectorParameterValue, contentfulRichTextToHtmlEnhancer, createContentfulEnhancer };
140
+ export { AddClientArgs, CANVAS_CONTENTFUL_MULTI_PARAMETER_TYPES, CANVAS_CONTENTFUL_PARAMETER_TYPES, CANVAS_CONTENTFUL_QUERY_PARAMETER_TYPES, ContentfulClientList, ContentfulEnhancerResult, ContentfulMultiEntryEnhancerResult, ContentfulMultiEntryParameterValue, ContentfulQueryEnhancerResult, ContentfulQueryParameterValue, CreateContentfulEnhancerOptions, CreateContentfulMultiEntryEnhancerOptions, CreateContentfulMultiEntryQueryOptions, CreateContentfulQueryApiQueryOptions, CreateContentfulQueryEnhancerOptions, CreateContentfulQueryOptions, EntrySelectorParameterValue, contentfulRichTextToHtmlEnhancer, createContentfulEnhancer, createContentfulMultiEnhancer, createContentfulQueryEnhancer };
package/dist/index.esm.js CHANGED
@@ -1 +1 @@
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};
1
+ import{createBatchEnhancer as S,UniqueBatchEntries as _}from"@uniformdev/canvas";var L=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 Q}from"@uniformdev/canvas";var x=Q({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 V(e,t){if(!!e)return`${t==="desc"?"-":""}${e}`}function A({clients:e,parameterValue:t,parameterName:n,component:o,context:g}){let{source:i="default"}=t,a=e.getClient({source:i,isPreviewClient:g.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 $={select:"fields",include:1},k=Object.freeze(["contentfulEntry"]);function j(e){return e instanceof L}function se({client:e,previewClient:t,createQuery:n,useBatching:o,limitPolicy:g}){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(j(e))return e;let s=new L;return s.addClient({client:e,previewClient:t}),s})(),y=g||x;return o?S({handleBatch:async s=>{var c;let l=s.reduce((u,r)=>{let{parameter:f,parameterName:C,component:h,context:m}=r.args,d=f.value;if(!O(d))return u;let E=b({parameterValue:d,parameterName:C,clients:a,component:h,context:m}),p="";if(T(d))p="legacy-group";else{let{source:I="default"}=d;p=I}return u[p]&&Array.isArray(u[p].tasks)?u[p].tasks.push(r):u[p]={client:E,tasks:[r]},u},{});try{console.time("fetch all entries");for await(let[u,r]of Object.entries(l)){let{context:f,component:C}=r.tasks[0].args,h=(c=n==null?void 0:n({component:C,defaultQuery:{...$},context:f}))!=null?c:$,m=new _(r.tasks,E=>T(E.parameter.value)?E.parameter.value:E.parameter.value.entryId),d=Object.keys(m.groups);console.time(`fetch entries ${u}`);try{(await r.client.getEntries({"sys.id[in]":d.join(","),limit:d.length,...h})).items.forEach(p=>{m.resolveKey(p.sys.id,p)}),m.resolveRemaining(null)}finally{console.timeEnd(`fetch entries ${u}`)}}console.timeEnd("fetch all entries")}catch(u){let r=P(u),f=new Error(`Failed loading Contentful entries batch (${s.length}) ${r}`);s.forEach(C=>C.reject(f))}},shouldQueue:({parameter:s})=>R(s),limitPolicy:y}):{enhanceOne:async function({parameter:l,parameterName:c,component:u,context:r}){var f,C;if(R(l)){if(!O(l.value))return null;let h=b({clients:a,parameterName:c,parameterValue:l.value,component:u,context:r}),m=T(l.value)?l.value:l.value.entryId,d=(f=n==null?void 0:n({parameter:l,parameterName:c,component:u,defaultQuery:{...$},context:r}))!=null?f:$;try{return console.time(`fetch entry ${m}`),await h.getEntry(m,d)}catch(E){let p=P(E);throw T(l.value)?new Error(`Failed loading Contentful entry '${l.value}' referenced in parameter '${c}': ${p}`):new Error(`Failed loading Contentful entry '${m}' from source '${(C=l.value.source)!=null?C:"default"}' referenced in parameter '${c}': ${p}`)}finally{console.timeEnd(`fetch entry ${m}`)}}},limitPolicy:y}}function R(e){var t;return e.type===k[0]&&(((t=e.value)==null?void 0:t.entryId)||typeof e.value=="string")}function T(e){return typeof e=="string"}function O(e){return!(!e||!T(e)&&!e.entryId)}function b({clients:e,parameterValue:t,parameterName:n,component:o,context:g}){if(T(t)){let y=e.getClient({isPreviewClient:g.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,a=e.getClient({source:i,isPreviewClient:g.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 F={select:"fields",include:1},Y=Object.freeze(["contentfulMultiEntry"]);function Ce({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:y,context:s}){var l,c;if(B(i)){if(!U(i.value))return null;let u=A({clients:e,parameterName:a,parameterValue:i.value,component:y,context:s}),r=i.value.entries,f=(l=t==null?void 0:t({parameter:i,parameterName:a,component:y,defaultQuery:{...F},context:s}))!=null?l:F;try{return console.time(`fetch entries ${r.join()}`),(await u.getEntries({"sys.id[in]":r.join(),limit:r.length,...f})).items}catch(C){let h=P(C);throw new Error(`Failed loading Contentful entries '${r.join()}' from source '${(c=i.value.source)!=null?c:"default"}' referenced in parameter '${a}': ${h}`)}finally{console.timeEnd(`fetch entries ${r.join()}`)}}},limitPolicy:n||x}}function B(e){return e.type===Y[0]}function U(e){var t;return!(!e||!((t=e.entries)==null?void 0:t.length))}var q=Object.freeze(["contentfulQuery"]),M={select:"fields",include:1};function ye({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:y,context:s}){var l,c;if(D(i)){if(!z(i.value))return null;let u=A({clients:e,parameterName:a,parameterValue:i.value,component:y,context:s}),r=i.value,f=H(r.count),C=(l=t==null?void 0:t({parameter:i,parameterName:a,component:y,defaultQuery:{...M},context:s}))!=null?l:M,h=`fetch query: ${f} entries with '${r.contentType}' content type`;try{return console.time(h),(await u.getEntries({content_type:r.contentType,order:V(r.sortBy,r.sortOrder),limit:f,...C})).items}catch(m){let d=P(m);throw new Error(`Failed loading Contentful entries with '${r.contentType}' content type from source '${(c=r.source)!=null?c:"default"}' referenced in parameter '${a}': ${d}`)}finally{console.timeEnd(h)}}},limitPolicy:n||x}}function D(e){return e.type===q[0]}function z(e){return!(!e||!e.source||!e.contentType||typeof e.count=="undefined")}function H(e){return!e||e<1?1:e>1e3?1e3:e}import{documentToHtmlString as K}from"@contentful/rich-text-html-renderer";var Ee=({parameter:e})=>{let t=e.value;if(!t)return t;if(!G(t))return N(t),t;for(let n of t)N(n);return t};function N(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{Y as CANVAS_CONTENTFUL_MULTI_PARAMETER_TYPES,k as CANVAS_CONTENTFUL_PARAMETER_TYPES,q as CANVAS_CONTENTFUL_QUERY_PARAMETER_TYPES,L as ContentfulClientList,Ee as contentfulRichTextToHtmlEnhancer,se as createContentfulEnhancer,Ce as createContentfulMultiEnhancer,ye as createContentfulQueryEnhancer};
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 _=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});
1
+ var q=Object.create;var L=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var O=e=>L(e,"__esModule",{value:!0});var G=(e,t)=>{O(e);for(var n in t)L(e,n,{get:t[n],enumerable:!0})},J=(e,t,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of z(t))!K.call(e,o)&&o!=="default"&&L(e,o,{get:()=>t[o],enumerable:!(n=D(t,o))||n.enumerable});return e},R=e=>J(O(L(e!=null?q(H(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);G(exports,{CANVAS_CONTENTFUL_MULTI_PARAMETER_TYPES:()=>_,CANVAS_CONTENTFUL_PARAMETER_TYPES:()=>M,CANVAS_CONTENTFUL_QUERY_PARAMETER_TYPES:()=>k,ContentfulClientList:()=>T,contentfulRichTextToHtmlEnhancer:()=>le,createContentfulEnhancer:()=>X,createContentfulMultiEnhancer:()=>Z,createContentfulQueryEnhancer:()=>ne});var $=R(require("@uniformdev/canvas"));var T=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 b=R(require("@uniformdev/canvas")),w=(0,b.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 F(e,t){if(!!e)return`${t==="desc"?"-":""}${e}`}function A({clients:e,parameterValue:t,parameterName:n,component:o,context:g}){let{source:i="default"}=t,a=e.getClient({source:i,isPreviewClient:g.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 V={select:"fields",include:1},M=Object.freeze(["contentfulEntry"]);function W(e){return e instanceof T}function X({client:e,previewClient:t,createQuery:n,useBatching:o,limitPolicy:g}){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(W(e))return e;let s=new T;return s.addClient({client:e,previewClient:t}),s})(),y=g||w;return o?(0,$.createBatchEnhancer)({handleBatch:async s=>{var c;let l=s.reduce((u,r)=>{let{parameter:f,parameterName:C,component:h,context:m}=r.args,d=f.value;if(!I(d))return u;let E=Q({parameterValue:d,parameterName:C,clients:a,component:h,context:m}),p="";if(x(d))p="legacy-group";else{let{source:U="default"}=d;p=U}return u[p]&&Array.isArray(u[p].tasks)?u[p].tasks.push(r):u[p]={client:E,tasks:[r]},u},{});try{console.time("fetch all entries");for await(let[u,r]of Object.entries(l)){let{context:f,component:C}=r.tasks[0].args,h=(c=n==null?void 0:n({component:C,defaultQuery:{...V},context:f}))!=null?c:V,m=new $.UniqueBatchEntries(r.tasks,E=>x(E.parameter.value)?E.parameter.value:E.parameter.value.entryId),d=Object.keys(m.groups);console.time(`fetch entries ${u}`);try{(await r.client.getEntries({"sys.id[in]":d.join(","),limit:d.length,...h})).items.forEach(p=>{m.resolveKey(p.sys.id,p)}),m.resolveRemaining(null)}finally{console.timeEnd(`fetch entries ${u}`)}}console.timeEnd("fetch all entries")}catch(u){let r=P(u),f=new Error(`Failed loading Contentful entries batch (${s.length}) ${r}`);s.forEach(C=>C.reject(f))}},shouldQueue:({parameter:s})=>N(s),limitPolicy:y}):{enhanceOne:async function({parameter:l,parameterName:c,component:u,context:r}){var f,C;if(N(l)){if(!I(l.value))return null;let h=Q({clients:a,parameterName:c,parameterValue:l.value,component:u,context:r}),m=x(l.value)?l.value:l.value.entryId,d=(f=n==null?void 0:n({parameter:l,parameterName:c,component:u,defaultQuery:{...V},context:r}))!=null?f:V;try{return console.time(`fetch entry ${m}`),await h.getEntry(m,d)}catch(E){let p=P(E);throw x(l.value)?new Error(`Failed loading Contentful entry '${l.value}' referenced in parameter '${c}': ${p}`):new Error(`Failed loading Contentful entry '${m}' from source '${(C=l.value.source)!=null?C:"default"}' referenced in parameter '${c}': ${p}`)}finally{console.timeEnd(`fetch entry ${m}`)}}},limitPolicy:y}}function N(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 I(e){return!(!e||!x(e)&&!e.entryId)}function Q({clients:e,parameterValue:t,parameterName:n,component:o,context:g}){if(x(t)){let y=e.getClient({isPreviewClient:g.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,a=e.getClient({source:i,isPreviewClient:g.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 S={select:"fields",include:1},_=Object.freeze(["contentfulMultiEntry"]);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:a,component:y,context:s}){var l,c;if(ee(i)){if(!te(i.value))return null;let u=A({clients:e,parameterName:a,parameterValue:i.value,component:y,context:s}),r=i.value.entries,f=(l=t==null?void 0:t({parameter:i,parameterName:a,component:y,defaultQuery:{...S},context:s}))!=null?l:S;try{return console.time(`fetch entries ${r.join()}`),(await u.getEntries({"sys.id[in]":r.join(),limit:r.length,...f})).items}catch(C){let h=P(C);throw new Error(`Failed loading Contentful entries '${r.join()}' from source '${(c=i.value.source)!=null?c:"default"}' referenced in parameter '${a}': ${h}`)}finally{console.timeEnd(`fetch entries ${r.join()}`)}}},limitPolicy:n||w}}function ee(e){return e.type===_[0]}function te(e){var t;return!(!e||!((t=e.entries)==null?void 0:t.length))}var k=Object.freeze(["contentfulQuery"]),j={select:"fields",include:1};function ne({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:y,context:s}){var l,c;if(re(i)){if(!oe(i.value))return null;let u=A({clients:e,parameterName:a,parameterValue:i.value,component:y,context:s}),r=i.value,f=ie(r.count),C=(l=t==null?void 0:t({parameter:i,parameterName:a,component:y,defaultQuery:{...j},context:s}))!=null?l:j,h=`fetch query: ${f} entries with '${r.contentType}' content type`;try{return console.time(h),(await u.getEntries({content_type:r.contentType,order:F(r.sortBy,r.sortOrder),limit:f,...C})).items}catch(m){let d=P(m);throw new Error(`Failed loading Contentful entries with '${r.contentType}' content type from source '${(c=r.source)!=null?c:"default"}' referenced in parameter '${a}': ${d}`)}finally{console.timeEnd(h)}}},limitPolicy:n||w}}function re(e){return e.type===k[0]}function oe(e){return!(!e||!e.source||!e.contentType||typeof e.count=="undefined")}function ie(e){return!e||e<1?1:e>1e3?1e3:e}var Y=R(require("@contentful/rich-text-html-renderer")),le=({parameter:e})=>{let t=e.value;if(!t)return t;if(!ue(t))return B(t),t;for(let n of t)B(n);return t};function B(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,Y.documentToHtmlString)(o))})}function ue(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 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};
1
+ import{createBatchEnhancer as S,UniqueBatchEntries as _}from"@uniformdev/canvas";var L=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 Q}from"@uniformdev/canvas";var x=Q({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 V(e,t){if(!!e)return`${t==="desc"?"-":""}${e}`}function A({clients:e,parameterValue:t,parameterName:n,component:o,context:g}){let{source:i="default"}=t,a=e.getClient({source:i,isPreviewClient:g.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 $={select:"fields",include:1},k=Object.freeze(["contentfulEntry"]);function j(e){return e instanceof L}function se({client:e,previewClient:t,createQuery:n,useBatching:o,limitPolicy:g}){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(j(e))return e;let s=new L;return s.addClient({client:e,previewClient:t}),s})(),y=g||x;return o?S({handleBatch:async s=>{var c;let l=s.reduce((u,r)=>{let{parameter:f,parameterName:C,component:h,context:m}=r.args,d=f.value;if(!O(d))return u;let E=b({parameterValue:d,parameterName:C,clients:a,component:h,context:m}),p="";if(T(d))p="legacy-group";else{let{source:I="default"}=d;p=I}return u[p]&&Array.isArray(u[p].tasks)?u[p].tasks.push(r):u[p]={client:E,tasks:[r]},u},{});try{console.time("fetch all entries");for await(let[u,r]of Object.entries(l)){let{context:f,component:C}=r.tasks[0].args,h=(c=n==null?void 0:n({component:C,defaultQuery:{...$},context:f}))!=null?c:$,m=new _(r.tasks,E=>T(E.parameter.value)?E.parameter.value:E.parameter.value.entryId),d=Object.keys(m.groups);console.time(`fetch entries ${u}`);try{(await r.client.getEntries({"sys.id[in]":d.join(","),limit:d.length,...h})).items.forEach(p=>{m.resolveKey(p.sys.id,p)}),m.resolveRemaining(null)}finally{console.timeEnd(`fetch entries ${u}`)}}console.timeEnd("fetch all entries")}catch(u){let r=P(u),f=new Error(`Failed loading Contentful entries batch (${s.length}) ${r}`);s.forEach(C=>C.reject(f))}},shouldQueue:({parameter:s})=>R(s),limitPolicy:y}):{enhanceOne:async function({parameter:l,parameterName:c,component:u,context:r}){var f,C;if(R(l)){if(!O(l.value))return null;let h=b({clients:a,parameterName:c,parameterValue:l.value,component:u,context:r}),m=T(l.value)?l.value:l.value.entryId,d=(f=n==null?void 0:n({parameter:l,parameterName:c,component:u,defaultQuery:{...$},context:r}))!=null?f:$;try{return console.time(`fetch entry ${m}`),await h.getEntry(m,d)}catch(E){let p=P(E);throw T(l.value)?new Error(`Failed loading Contentful entry '${l.value}' referenced in parameter '${c}': ${p}`):new Error(`Failed loading Contentful entry '${m}' from source '${(C=l.value.source)!=null?C:"default"}' referenced in parameter '${c}': ${p}`)}finally{console.timeEnd(`fetch entry ${m}`)}}},limitPolicy:y}}function R(e){var t;return e.type===k[0]&&(((t=e.value)==null?void 0:t.entryId)||typeof e.value=="string")}function T(e){return typeof e=="string"}function O(e){return!(!e||!T(e)&&!e.entryId)}function b({clients:e,parameterValue:t,parameterName:n,component:o,context:g}){if(T(t)){let y=e.getClient({isPreviewClient:g.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,a=e.getClient({source:i,isPreviewClient:g.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 F={select:"fields",include:1},Y=Object.freeze(["contentfulMultiEntry"]);function Ce({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:y,context:s}){var l,c;if(B(i)){if(!U(i.value))return null;let u=A({clients:e,parameterName:a,parameterValue:i.value,component:y,context:s}),r=i.value.entries,f=(l=t==null?void 0:t({parameter:i,parameterName:a,component:y,defaultQuery:{...F},context:s}))!=null?l:F;try{return console.time(`fetch entries ${r.join()}`),(await u.getEntries({"sys.id[in]":r.join(),limit:r.length,...f})).items}catch(C){let h=P(C);throw new Error(`Failed loading Contentful entries '${r.join()}' from source '${(c=i.value.source)!=null?c:"default"}' referenced in parameter '${a}': ${h}`)}finally{console.timeEnd(`fetch entries ${r.join()}`)}}},limitPolicy:n||x}}function B(e){return e.type===Y[0]}function U(e){var t;return!(!e||!((t=e.entries)==null?void 0:t.length))}var q=Object.freeze(["contentfulQuery"]),M={select:"fields",include:1};function ye({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:y,context:s}){var l,c;if(D(i)){if(!z(i.value))return null;let u=A({clients:e,parameterName:a,parameterValue:i.value,component:y,context:s}),r=i.value,f=H(r.count),C=(l=t==null?void 0:t({parameter:i,parameterName:a,component:y,defaultQuery:{...M},context:s}))!=null?l:M,h=`fetch query: ${f} entries with '${r.contentType}' content type`;try{return console.time(h),(await u.getEntries({content_type:r.contentType,order:V(r.sortBy,r.sortOrder),limit:f,...C})).items}catch(m){let d=P(m);throw new Error(`Failed loading Contentful entries with '${r.contentType}' content type from source '${(c=r.source)!=null?c:"default"}' referenced in parameter '${a}': ${d}`)}finally{console.timeEnd(h)}}},limitPolicy:n||x}}function D(e){return e.type===q[0]}function z(e){return!(!e||!e.source||!e.contentType||typeof e.count=="undefined")}function H(e){return!e||e<1?1:e>1e3?1e3:e}import{documentToHtmlString as K}from"@contentful/rich-text-html-renderer";var Ee=({parameter:e})=>{let t=e.value;if(!t)return t;if(!G(t))return N(t),t;for(let n of t)N(n);return t};function N(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{Y as CANVAS_CONTENTFUL_MULTI_PARAMETER_TYPES,k as CANVAS_CONTENTFUL_PARAMETER_TYPES,q as CANVAS_CONTENTFUL_QUERY_PARAMETER_TYPES,L as ContentfulClientList,Ee as contentfulRichTextToHtmlEnhancer,se as createContentfulEnhancer,Ce as createContentfulMultiEnhancer,ye as createContentfulQueryEnhancer};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-contentful",
3
- "version": "12.2.1-alpha.51+9f55cc00",
3
+ "version": "13.0.1-alpha.70+21cf4ced",
4
4
  "description": "Contentful data enhancers for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -25,25 +25,25 @@
25
25
  "ci:build": "tsup --minify --clean"
26
26
  },
27
27
  "dependencies": {
28
- "@uniformdev/canvas": "^12.2.1-alpha.51+9f55cc00"
28
+ "@uniformdev/canvas": "^13.0.1-alpha.70+21cf4ced"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "@contentful/rich-text-html-renderer": ">= 14",
32
32
  "contentful": ">= 8"
33
33
  },
34
34
  "devDependencies": {
35
- "@contentful/rich-text-html-renderer": "15.4.0",
36
- "@types/jest": "27.0.2",
37
- "@types/node": "16.7.1",
38
- "contentful": "9.1.4",
39
- "eslint": "7.32.0",
40
- "eslint-plugin-react": "7.26.1",
41
- "eslint-plugin-react-hooks": "4.2.0",
42
- "jest": "27.3.1",
35
+ "@contentful/rich-text-html-renderer": "15.9.1",
36
+ "@types/jest": "27.0.3",
37
+ "@types/node": "16.11.12",
38
+ "contentful": "9.1.5",
39
+ "eslint": "8.4.1",
40
+ "eslint-plugin-react": "7.27.1",
41
+ "eslint-plugin-react-hooks": "4.3.0",
42
+ "jest": "27.4.4",
43
43
  "npm-run-all": "4.1.5",
44
44
  "rimraf": "3.0.2",
45
- "ts-jest": "27.0.7",
46
- "tsup": "5.6.0"
45
+ "ts-jest": "27.1.1",
46
+ "tsup": "5.11.1"
47
47
  },
48
48
  "files": [
49
49
  "/dist"
@@ -51,5 +51,5 @@
51
51
  "publishConfig": {
52
52
  "access": "public"
53
53
  },
54
- "gitHead": "9f55cc00e4a351a0d95d767e66a3e81fb9fb29aa"
54
+ "gitHead": "21cf4cedab72c4bd29048c47d3a6a772d997985b"
55
55
  }