@uniformdev/canvas 16.2.1-alpha.106 → 16.2.1-alpha.142
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/chunk-N2C6WISR.mjs +5 -0
- package/dist/cli/cli.js +72 -56
- package/dist/cli/cli.mjs +71 -55
- package/dist/createEventBus-97218204.d.ts +1003 -0
- package/dist/index.esm.js +1 -4
- package/dist/index.js +2 -2
- package/dist/index.mjs +1 -4
- package/package.json +4 -5
- package/dist/chunk-LLGWMZOC.mjs +0 -2
@@ -0,0 +1,5 @@
|
|
1
|
+
var j=Object.create;var d=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var K=(r=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(r,{get:(e,t)=>(typeof require!="undefined"?require:e)[t]}):r)(function(r){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+r+'" is not supported')});var Z=(r,e)=>()=>(r&&(e=r(r=0)),e);var Y=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),J=(r,e)=>{for(var t in e)d(r,t,{get:e[t],enumerable:!0})},v=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of $(e))!B.call(r,o)&&o!==t&&d(r,o,{get:()=>e[o],enumerable:!(n=V(e,o))||n.enumerable});return r};var W=(r,e,t)=>(t=r!=null?j(k(r)):{},v(e||!r||!r.__esModule?d(t,"default",{value:r,enumerable:!0}):t,r)),Q=r=>v(d({},"__esModule",{value:!0}),r);function f(r,e){let t=[{ancestorsAndSelf:[{component:r,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let n=t.pop();if(!n)continue;let o=n.ancestorsAndSelf[0];e(o.component,n.ancestorsAndSelf,{replaceComponent:i=>{Object.assign(o.component,i),["parameters","variant","slots","data","_pattern","_patternError"].forEach(s=>{i[s]||delete o.component[s]})},removeComponent:()=>{let{parentSlot:i,parentSlotIndex:c}=n.ancestorsAndSelf[0],s=n.ancestorsAndSelf[1];if(i&&typeof c!="undefined")s.component.slots[i].splice(c,1);else throw new Error("Unable to delete composition.")},insertAfter:i=>{let c=Array.isArray(i)?i:[i],{parentSlot:s,parentSlotIndex:p}=n.ancestorsAndSelf[0],m=n.ancestorsAndSelf[1];if(s&&typeof p!="undefined")m.component.slots[s].splice(p+1,0,...c);else throw new Error("Unable to insert after a component not in a slot.")}});let a=o.component.slots;if(a){let i=Object.keys(a);for(let c=i.length-1;c>=0;c--){let s=i[c],p=a[s];for(let m=p.length-1;m>=0;m--)t.push({ancestorsAndSelf:[{component:p[m],parentSlot:s,parentSlotIndex:m},...n.ancestorsAndSelf]})}}}while(t.length>0)}function E(r){let e=[];for(let t=r.length-1;t>=0;t--){let{parentSlot:n,parentSlotIndex:o}=r[t];n&&o!==void 0&&e.push(`${n}[${o}]`)}return`.${e.join(".")}`}var I=class{constructor(e,t){this.groups=e.reduce((n,o)=>{var i;let a=t(o.args);return n[a]=(i=n[a])!=null?i:[],n[a].push(o),n},{})}resolveKey(e,t){this.groups[e].forEach(n=>n.resolve(t))}resolveRemaining(e){Object.keys(this.groups).forEach(t=>{this.groups[t].forEach(n=>{n.isCompleted||n.resolve(e)})})}};var y=class{constructor(){this._paramMatches=Array();this._dataMatches=new Map}parameter(e){return this._paramMatches.push({enhancer:this._resolveParameterEnhancer(e)}),this}parameterName(e,t){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({name:o,enhancer:this._resolveParameterEnhancer(t)})),this}parameterType(e,t){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({type:o,enhancer:this._resolveParameterEnhancer(t)})),this}data(e,t){if(this._dataMatches.has(e))throw new Error(`${e} enhancer data key has been used more than once. This will cause data loss.`);return this._dataMatches.set(e,typeof t=="function"?{enhanceOne:t}:t),this}resolveParameterEnhancer(e,t){var n;return(n=this._paramMatches.find(o=>o.name&&o.name===e||o.type&&o.type===t.type||!o.type&&!o.name))==null?void 0:n.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},x=class{constructor(){this._componentIndex={};this._rootBuilder=new y}parameter(e){return this._rootBuilder.parameter(e),this}parameterName(e,t){return this._rootBuilder.parameterName(e,t),this}parameterType(e,t){return this._rootBuilder.parameterType(e,t),this}data(e,t){return this._rootBuilder.data(e,t),this}component(e,t){return(Array.isArray(e)?e:[e]).forEach(o=>{this._componentIndex[o]=this._componentIndex[o]||new y,t(this._componentIndex[o])}),this}resolveParameterEnhancer(e,t,n){let o=this._componentIndex[e.type];if(o){let a=o.resolveParameterEnhancer(t,n);if(a)return a}return this._rootBuilder.resolveParameterEnhancer(t,n)}resolveComponentEnhancers(e){let t=this._rootBuilder.resolveComponentEnhancers(),n=this._componentIndex[e.type];if(n){t=new Map(t);for(let[o,a]of n.resolveComponentEnhancers())t.set(o,a)}return t}};var A=class{constructor(e,t,n){this._resolve=e;this._reject=t;this.args=n;this._isCompleted=!1}resolve(e){this._resolve(e),this._isCompleted=!0}reject(e){this._reject(e),this._isCompleted=!0}get isCompleted(){return this._isCompleted}};function ne({handleBatch:r,shouldQueue:e,limitPolicy:t}){let n=[];return{enhanceOne:async i=>{if(!e||e(i))return new Promise((c,s)=>{n.push(new A(c,s,i))})},completeAll:async()=>{if(n.length>0){try{await r(n)}catch(c){n.forEach(s=>s.reject(c))}if(n.some(c=>!c.isCompleted))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!")}let i=n.length;return n=[],i},limitPolicy:t}}import M from"p-throttle";import U from"p-retry";function w({throttle:r={interval:1e3,limit:10},retry:e={retries:1,factor:1.66}}){let t=r?M(r):null;return function(o){let a=async()=>await o();if(t&&(a=t(a)),e){let i=a;a=()=>U(i,e)}return a()}}var l=async r=>await r();async function ue({composition:r,enhancers:e,context:t,onErrors:n=o=>{throw new Error(o.map(a=>`${a.message}
|
2
|
+
${typeof a.error=="object"&&"stack"in a.error?a.error.stack:a.error}`).join(`
|
3
|
+
|
4
|
+
`))}}){let o=[],a=new Set,i=new Set;f(r,(s,p)=>{var u;Object.entries((u=s.parameters)!=null?u:{}).forEach(([g,T])=>{let P=e.resolveParameterEnhancer(s,g,T);P&&(i.add(P),o.push(D(s,p,g,T,P,t)))});let m=e.resolveComponentEnhancers(s);o.push(F(s,p,m,t)),a.add(m)}),o.push(...Array.from(a).flatMap(s=>Array.from(s).map(async([,p])=>{var m;try{p.completeAll&&await((m=p.limitPolicy)!=null?m:l)(()=>p.completeAll())}catch(u){return{error:u,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),o.push(...Array.from(i).map(async s=>{var p;try{s.completeAll&&await((p=s.limitPolicy)!=null?p:l)(()=>s.completeAll())}catch(m){return{error:m,message:"Batch parameter enhancer failed. Individual failed parameters should receive their own rejections."}}}));let c=(await Promise.all(o)).flatMap(s=>Array.isArray(s)?s:[s]).filter(s=>s);c.length&&n(c)}async function F(r,e,t,n){return t.size&&(r.data={}),await Promise.all(Array.from(t).map(async([o,a])=>{var i;try{let s=await(a.completeAll?l:(i=a.limitPolicy)!=null?i:l)(async()=>a.enhanceOne({component:r,context:n}));s!=null&&(r.data[o]=s)}catch(c){let s=`Component ${E(e)} (type: ${r.type}): data.${o} enhancer threw exception. Data key will not be present.`;return delete r.data[o],{message:s,error:c}}}))}async function D(r,e,t,n,o,a){var i;try{let s=await(o.completeAll?l:(i=o.limitPolicy)!=null?i:l)(async()=>o.enhanceOne({parameter:n,parameterName:t,component:r,context:a}));s===null?delete r.parameters[t]:typeof s=="undefined"?r.parameters[t]={...n,value:n.value}:r.parameters[t]={...n,value:s}}catch(c){let s=`Component ${E(e)} (type: ${r.type}): enhancing parameter ${t} (type: ${n.type}) threw exception. Parameter will be removed.`;return delete r.parameters[t],{message:s,error:c}}}var de=(r,...e)=>({enhanceOne:n=>{let o="enhanceOne"in r?r.enhanceOne(n):r(n);for(let a of e){let i=G(o)?o:Promise.resolve(o),c="enhanceOne"in a?a.enhanceOne:a;o=i.then(s=>c({...n,parameter:{type:n.parameter.type,value:s}}))}return o},completeAll:async()=>{var n,o;for(let a of e)if("completeAll"in a)throw new Error("Only the first enhancer in a compose chain can use the completeAll function (batching)");return(o="completeAll"in r?(n=r.completeAll)==null?void 0:n.call(r):0)!=null?o:0}});function G(r){return!!r&&(typeof r=="object"||typeof r=="function")&&typeof r.then=="function"}var h=class extends Error{constructor(t,n,o,a,i,c){super(`${t}
|
5
|
+
${a}${i?" "+i:""} (${n} ${o}${c?` Request ID: ${c}`:""})`);this.errorMessage=t;this.fetchMethod=n;this.fetchUri=o;this.statusCode=a;this.statusText=i;this.requestId=c;Object.setPrototypeOf(this,h.prototype)}},C=class{constructor(e){var n,o,a,i,c;if(!e.apiKey&&!e.bearerToken)throw new Error("You must provide an API key or a bearer token");let t=e.fetch;if(!t)if(typeof window!="undefined")t=window.fetch.bind(window);else if(typeof fetch!="undefined")t=fetch;else throw new Error("You must provide or polyfill a fetch implementation when not in a browser");this.options={...e,fetch:t,apiHost:(n=e.apiHost)!=null?n:"https://uniform.app",apiKey:(o=e.apiKey)!=null?o:null,projectId:(a=e.projectId)!=null?a:null,bearerToken:(i=e.bearerToken)!=null?i:null,limitPolicy:(c=e.limitPolicy)!=null?c:w({})}}async getCompositionList(e){let{projectId:t}=this.options,n=this.createUrl("/api/v1/canvas",{...e,projectId:t});return await this.apiClient(n)}async getCompositionBySlug(e){let{projectId:t}=this.options,n=this.createUrl("/api/v1/canvas",{...e,projectId:t});return await this.apiClient(n)}async getCompositionById(e){let{projectId:t}=this.options,n=this.createUrl("/api/v1/canvas",{...e,projectId:t});return await this.apiClient(n)}async updateComposition(e){let t=this.createUrl("/api/v1/canvas");await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(e){let t=this.createUrl("/api/v1/canvas");await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async getComponentDefinitions(e){let{projectId:t}=this.options,n=this.createUrl("/api/v1/canvas-definitions",{...e,projectId:t});return await this.apiClient(n)}async updateComponentDefinition(e){let t=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(e){let t=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(e,t){return this.options.limitPolicy(async()=>{var a;let n=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`},o=await this.options.fetch(e.toString(),{...t,headers:{...t==null?void 0:t.headers,...n}});if(!o.ok){let i="";try{let c=await o.text();try{let s=JSON.parse(c);s.errorMessage?i=Array.isArray(s.errorMessage)?s.errorMessage.join(", "):s.errorMessage:i=c}catch(s){i=c}}catch(c){i="General error"}throw new h(i,(a=t==null?void 0:t.method)!=null?a:"GET",e.toString(),o.status,o.statusText,C.getRequestId(o))}return t!=null&&t.expectNoContent?null:await o.json()})}createUrl(e,t){let n=new URL(`${this.options.apiHost}${e}`);return Object.entries(t!=null?t:{}).forEach(([o,a])=>{var i;typeof a!==void 0&&a!==null&&n.searchParams.append(o,(i=a==null?void 0:a.toString())!=null?i:"")}),n}static getRequestId(e){let t=e.headers.get("apigw-requestid");if(t)return t}};var Ee="$personalization",Ae="$test",_="$localization",ge="intentTag",R="locale",Te="pz",ve="test",b="localized",Ie=0,xe=64,S="$pzCrit",O="$tstVrnt",we="$enr";var Re=r=>r.startsWith("$");function Oe(r){return r?r.map((e,t)=>{var a,i;let n=(i=(a=e.parameters)==null?void 0:a[S])==null?void 0:i.value,o=(n==null?void 0:n.name)||`pz-${t}-${e.type}`;return{...e,id:o,pz:n}}):[]}function je(r){return r?r.map((e,t)=>{var a,i,c;let n=(i=(a=e.parameters)==null?void 0:a[O])==null?void 0:i.value,o=(c=n==null?void 0:n.id)!=null?c:"testId"in e?e.testId:`ab-${t}-${e.type}`;return{...e,id:o}}):[]}var L="https://js.pusher.com/7.0.3/pusher.min.js";async function z(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((r,e)=>{let t=setTimeout(()=>{window.Pusher&&r(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${L}"><\/script> manually.`)},5e3),n=document.createElement("script");n.src=L,n.addEventListener("load",()=>{clearTimeout(t),r(window.Pusher)}),document.head.appendChild(n)})}async function $e(){let r=await z();if(!r)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let t=new r("7b5f5abd160fea549ffe",{cluster:"mt1"});t.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:n=>{let o=t.subscribe(n);return{unsubscribe:()=>t.unsubscribe(n),addEventHandler:(a,i)=>(o.bind(a,i),()=>o.unbind(a,i))}}}}return e}function N(r,e,t){return`${r}.${e}@${t}`}function Ue({projectId:r,compositionId:e,compositionState:t=0,eventBus:{subscribe:n},callback:o,event:a="updated"}){let i=N(r,e,t),c=n(i),s=c.addEventHandler(a,o);return()=>{s(),c.unsubscribe()}}function H({component:r}){var n;let e={},t=(n=r.slots)==null?void 0:n[b];return t==null||t.forEach(o=>{var i;let a=(i=o.parameters)==null?void 0:i[R];(a==null?void 0:a.value)&&typeof a.value=="string"&&(e[a.value]=e[a.value]||[],e[a.value].push(o))}),e}function ze({composition:r,locale:e}){f(r,(t,n,o)=>{if(t.type===_){let a=H({component:t}),i=typeof e=="string"?e:e({component:t,locales:a}),c;if(i&&(c=a[i]),c!=null&&c.length){let[s,...p]=c;o.replaceComponent(s),p.length&&o.insertAfter(p)}else o.removeComponent()}})}export{K as a,Z as b,Y as c,J as d,W as e,Q as f,f as g,E as h,I as i,y as j,x as k,A as l,ne as m,w as n,l as o,ue as p,de as q,h as r,C as s,Ee as t,Ae as u,_ as v,ge as w,R as x,Te as y,ve as z,b as A,Ie as B,xe as C,S as D,O as E,we as F,Re as G,Oe as H,je as I,$e as J,N as K,Ue as L,H as M,ze as N};
|