@uniformdev/canvas 16.2.1 → 16.2.4

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.
@@ -44,7 +44,7 @@ declare type CompositionAPIOptions = {
44
44
  offset?: number;
45
45
  /** Max number of records to return (defaults to 100) */
46
46
  limit?: number;
47
- /** The state of the composition to fetch (defaults to the published state. See CANVAS_DRAFT_STATE and CANVAS_PUBLISHED_STATE) */
47
+ /** State of compositions to fetch. Default = 'published' */
48
48
  state?: number;
49
49
  /**
50
50
  * Signals a Canvas enhancer proxy to skip processing enhancements to the data and return raw data only.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as ComponentInstance, a as ComponentParameter, b as CompositionAPIOptions, c as CompositionListAPIResponse, d as CompositionAPIResponse, e as CompositionAPIDeleteRequest, f as ComponentDefinitionListAPIOptions, g as ComponentDefinitionAPIResponse, h as ComponentDefinitionAPIPutRequest, i as ComponentDefinitionAPIDeleteRequest, P as PreviewEventBus } from './createEventBus-f5cdcc4e.js';
2
- export { r as ChannelSubscription, o as ComponentDefinition, i as ComponentDefinitionAPIDeleteRequest, h as ComponentDefinitionAPIPutRequest, g as ComponentDefinitionAPIResponse, f as ComponentDefinitionListAPIOptions, j as ComponentDefinitionParameter, n as ComponentDefinitionPermission, m as ComponentDefinitionSlot, l as ComponentDefinitionSlugSettings, k as ComponentDefinitionVariant, C as ComponentInstance, a as ComponentParameter, e as CompositionAPIDeleteRequest, b as CompositionAPIOptions, d as CompositionAPIResponse, q as CompositionFetchState, c as CompositionListAPIResponse, p as CreatingComponentDefinition, P as PreviewEventBus, R as RootComponentInstance, s as createEventBus } from './createEventBus-f5cdcc4e.js';
1
+ import { C as ComponentInstance, a as ComponentParameter, b as CompositionAPIOptions, c as CompositionListAPIResponse, d as CompositionAPIResponse, e as CompositionAPIDeleteRequest, f as ComponentDefinitionListAPIOptions, g as ComponentDefinitionAPIResponse, h as ComponentDefinitionAPIPutRequest, i as ComponentDefinitionAPIDeleteRequest, P as PreviewEventBus } from './createEventBus-a6696d11.js';
2
+ export { r as ChannelSubscription, o as ComponentDefinition, i as ComponentDefinitionAPIDeleteRequest, h as ComponentDefinitionAPIPutRequest, g as ComponentDefinitionAPIResponse, f as ComponentDefinitionListAPIOptions, j as ComponentDefinitionParameter, n as ComponentDefinitionPermission, m as ComponentDefinitionSlot, l as ComponentDefinitionSlugSettings, k as ComponentDefinitionVariant, C as ComponentInstance, a as ComponentParameter, e as CompositionAPIDeleteRequest, b as CompositionAPIOptions, d as CompositionAPIResponse, q as CompositionFetchState, c as CompositionListAPIResponse, p as CreatingComponentDefinition, P as PreviewEventBus, R as RootComponentInstance, s as createEventBus } from './createEventBus-a6696d11.js';
3
3
  import { Options } from 'p-throttle';
4
4
  import { Options as Options$1 } from 'p-retry';
5
5
  import { PersonalizedVariant, TestVariant } from '@uniformdev/context';
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";import{d as L,e as l,f as $,g as j,h as k,i as F,j as A,k as V,l as g,m as N,n as U,o as v,p as z,q as W,r as x,s as w,t as H}from"./chunk-HJHWEOMG.mjs";function u(o,e){let t=[{ancestorsAndSelf:[{component:o,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let n=t.pop();if(!n)continue;let r=n.ancestorsAndSelf[0];e(r.component,n.ancestorsAndSelf,{replaceComponent:i=>{Object.assign(r.component,i),["parameters","variant","slots","data","_pattern","_patternError"].forEach(s=>{i[s]||delete r.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=r.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 y(o){let e=[];for(let t=o.length-1;t>=0;t--){let{parentSlot:n,parentSlotIndex:r}=o[t];n&&r!==void 0&&e.push(`${n}[${r}]`)}return`.${e.join(".")}`}var T=class{constructor(e,t){this.groups=e.reduce((n,r)=>{var i;let a=t(r.args);return n[a]=(i=n[a])!=null?i:[],n[a].push(r),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 d=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(r=>this._paramMatches.push({name:r,enhancer:this._resolveParameterEnhancer(t)})),this}parameterType(e,t){return(Array.isArray(e)?e:[e]).forEach(r=>this._paramMatches.push({type:r,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(r=>r.name&&r.name===e||r.type&&r.type===t.type||!r.type&&!r.name))==null?void 0:n.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},_=class{constructor(){this._componentIndex={};this._rootBuilder=new d}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(r=>{this._componentIndex[r]=this._componentIndex[r]||new d,t(this._componentIndex[r])}),this}resolveParameterEnhancer(e,t,n){let r=this._componentIndex[e.type];if(r){let a=r.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[r,a]of n.resolveComponentEnhancers())t.set(r,a)}return t}};var C=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 D({handleBatch:o,shouldQueue:e,limitPolicy:t}){let n=[];return{enhanceOne:async i=>{if(!e||e(i))return new Promise((c,s)=>{n.push(new C(c,s,i))})},completeAll:async()=>{if(n.length>0){try{await o(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}}async function X({composition:o,enhancers:e,context:t,onErrors:n=r=>{throw new Error(r.map(a=>`${a.message}
1
+ import{d as L,e as l,f as $,g as j,h as k,i as F,j as A,k as V,l as g,m as N,n as U,o as v,p as z,q as W,r as x,s as w,t as H}from"./chunk-ADDR7SB6.mjs";function u(o,e){let t=[{ancestorsAndSelf:[{component:o,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let n=t.pop();if(!n)continue;let r=n.ancestorsAndSelf[0];e(r.component,n.ancestorsAndSelf,{replaceComponent:i=>{Object.assign(r.component,i),["parameters","variant","slots","data","_pattern","_patternError"].forEach(s=>{i[s]||delete r.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=r.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 y(o){let e=[];for(let t=o.length-1;t>=0;t--){let{parentSlot:n,parentSlotIndex:r}=o[t];n&&r!==void 0&&e.push(`${n}[${r}]`)}return`.${e.join(".")}`}var T=class{constructor(e,t){this.groups=e.reduce((n,r)=>{var i;let a=t(r.args);return n[a]=(i=n[a])!=null?i:[],n[a].push(r),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 d=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(r=>this._paramMatches.push({name:r,enhancer:this._resolveParameterEnhancer(t)})),this}parameterType(e,t){return(Array.isArray(e)?e:[e]).forEach(r=>this._paramMatches.push({type:r,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(r=>r.name&&r.name===e||r.type&&r.type===t.type||!r.type&&!r.name))==null?void 0:n.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},_=class{constructor(){this._componentIndex={};this._rootBuilder=new d}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(r=>{this._componentIndex[r]=this._componentIndex[r]||new d,t(this._componentIndex[r])}),this}resolveParameterEnhancer(e,t,n){let r=this._componentIndex[e.type];if(r){let a=r.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[r,a]of n.resolveComponentEnhancers())t.set(r,a)}return t}};var C=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 D({handleBatch:o,shouldQueue:e,limitPolicy:t}){let n=[];return{enhanceOne:async i=>{if(!e||e(i))return new Promise((c,s)=>{n.push(new C(c,s,i))})},completeAll:async()=>{if(n.length>0){try{await o(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}}async function X({composition:o,enhancers:e,context:t,onErrors:n=r=>{throw new Error(r.map(a=>`${a.message}
2
2
  ${typeof a.error=="object"&&"stack"in a.error?a.error.stack:a.error}`).join(`
3
3
 
4
4
  `))}}){let r=[],a=new Set,i=new Set;u(o,(s,p)=>{var h;Object.entries((h=s.parameters)!=null?h:{}).forEach(([E,P])=>{let f=e.resolveParameterEnhancer(s,E,P);f&&(i.add(f),r.push(S(s,p,E,P,f,t)))});let m=e.resolveComponentEnhancers(s);r.push(R(s,p,m,t)),a.add(m)}),r.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(h){return{error:h,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),r.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(r)).flatMap(s=>Array.isArray(s)?s:[s]).filter(s=>s);c.length&&n(c)}async function R(o,e,t,n){return t.size&&(o.data={}),await Promise.all(Array.from(t).map(async([r,a])=>{var i;try{let s=await(a.completeAll?l:(i=a.limitPolicy)!=null?i:l)(async()=>a.enhanceOne({component:o,context:n}));s!=null&&(o.data[r]=s)}catch(c){let s=`Component ${y(e)} (type: ${o.type}): data.${r} enhancer threw exception. Data key will not be present.`;return delete o.data[r],{message:s,error:c}}}))}async function S(o,e,t,n,r,a){var i;try{let s=await(r.completeAll?l:(i=r.limitPolicy)!=null?i:l)(async()=>r.enhanceOne({parameter:n,parameterName:t,component:o,context:a}));s===null?delete o.parameters[t]:typeof s=="undefined"?o.parameters[t]={...n,value:n.value}:o.parameters[t]={...n,value:s}}catch(c){let s=`Component ${y(e)} (type: ${o.type}): enhancing parameter ${t} (type: ${n.type}) threw exception. Parameter will be removed.`;return delete o.parameters[t],{message:s,error:c}}}var ne=(o,...e)=>({enhanceOne:n=>{let r="enhanceOne"in o?o.enhanceOne(n):o(n);for(let a of e){let i=B(r)?r:Promise.resolve(r),c="enhanceOne"in a?a.enhanceOne:a;r=i.then(s=>c({...n,parameter:{type:n.parameter.type,value:s}}))}return r},completeAll:async()=>{var n,r;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(r="completeAll"in o?(n=o.completeAll)==null?void 0:n.call(o):0)!=null?r:0}});function B(o){return!!o&&(typeof o=="object"||typeof o=="function")&&typeof o.then=="function"}var re=o=>o.startsWith("$");function se(o){return o?o.map((e,t)=>{var a,i;let n=(i=(a=e.parameters)==null?void 0:a[x])==null?void 0:i.value,r=(n==null?void 0:n.name)||`pz-${t}-${e.type}`;return{...e,id:r,pz:n}}):[]}function pe(o){return o?o.map((e,t)=>{var a,i,c;let n=(i=(a=e.parameters)==null?void 0:a[w])==null?void 0:i.value,r=(c=n==null?void 0:n.id)!=null?c:"testId"in e?e.testId:`ab-${t}-${e.type}`;return{...e,id:r}}):[]}var b="https://js.pusher.com/7.0.3/pusher.min.js";async function O(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((o,e)=>{let t=setTimeout(()=>{window.Pusher&&o(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${b}"><\/script> manually.`)},5e3),n=document.createElement("script");n.src=b,n.addEventListener("load",()=>{clearTimeout(t),o(window.Pusher)}),document.head.appendChild(n)})}async function le(){let o=await O();if(!o)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let t=new o("7b5f5abd160fea549ffe",{cluster:"mt1"});t.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:n=>{let r=t.subscribe(n);return{unsubscribe:()=>t.unsubscribe(n),addEventHandler:(a,i)=>(r.bind(a,i),()=>r.unbind(a,i))}}}}return e}function I(o,e,t){return`${o}.${e}@${t}`}function fe({projectId:o,compositionId:e,compositionState:t=0,eventBus:{subscribe:n},callback:r,event:a="updated"}){let i=I(o,e,t),c=n(i),s=c.addEventHandler(a,r);return()=>{s(),c.unsubscribe()}}function M({component:o}){var n;let e={},t=(n=o.slots)==null?void 0:n[v];return t==null||t.forEach(r=>{var i;let a=(i=r.parameters)==null?void 0:i[g];(a==null?void 0:a.value)&&typeof a.value=="string"&&(e[a.value]=e[a.value]||[],e[a.value].push(r))}),e}function Pe({composition:o,locale:e}){u(o,(t,n,r)=>{if(t.type===A){let a=M({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;r.replaceComponent(s),p.length&&r.insertAfter(p)}else r.removeComponent()}})}export{C as BatchEntry,z as CANVAS_DRAFT_STATE,H as CANVAS_ENRICHMENT_TAG_PARAM,V as CANVAS_INTENT_TAG_PARAM,g as CANVAS_LOCALE_TAG_PARAM,v as CANVAS_LOCALIZATION_SLOT,A as CANVAS_LOCALIZATION_TYPE,x as CANVAS_PERSONALIZATION_PARAM,N as CANVAS_PERSONALIZE_SLOT,k as CANVAS_PERSONALIZE_TYPE,W as CANVAS_PUBLISHED_STATE,U as CANVAS_TEST_SLOT,F as CANVAS_TEST_TYPE,w as CANVAS_TEST_VARIANT_PARAM,j as CanvasClient,$ as CanvasClientError,d as ChildEnhancerBuilder,_ as EnhancerBuilder,T as UniqueBatchEntries,ne as compose,D as createBatchEnhancer,le as createEventBus,L as createLimitPolicy,X as enhance,M as extractLocales,I as getChannelName,y as getComponentPath,re as isSystemComponentDefinition,Pe as localize,se as mapSlotToPersonalizedVariations,pe as mapSlotToTestVariations,l as nullLimitPolicy,fe as subscribeToComposition,u as walkComponentTree};
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";var B=Object.create;var C=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var z=(r,e)=>{for(var n in e)C(r,n,{get:e[n],enumerable:!0})},L=(r,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of U(e))!D.call(r,o)&&o!==n&&C(r,o,{get:()=>e[o],enumerable:!(t=M(e,o))||t.enumerable});return r};var N=(r,e,n)=>(n=r!=null?B(F(r)):{},L(e||!r||!r.__esModule?C(n,"default",{value:r,enumerable:!0}):n,r)),H=r=>L(C({},"__esModule",{value:!0}),r);var le={};z(le,{BatchEntry:()=>P,CANVAS_DRAFT_STATE:()=>_e,CANVAS_ENRICHMENT_TAG_PARAM:()=>te,CANVAS_INTENT_TAG_PARAM:()=>X,CANVAS_LOCALE_TAG_PARAM:()=>R,CANVAS_LOCALIZATION_SLOT:()=>x,CANVAS_LOCALIZATION_TYPE:()=>v,CANVAS_PERSONALIZATION_PARAM:()=>_,CANVAS_PERSONALIZE_SLOT:()=>ee,CANVAS_PERSONALIZE_TYPE:()=>W,CANVAS_PUBLISHED_STATE:()=>we,CANVAS_TEST_SLOT:()=>ne,CANVAS_TEST_TYPE:()=>Q,CANVAS_TEST_VARIANT_PARAM:()=>w,CanvasClient:()=>y,CanvasClientError:()=>u,ChildEnhancerBuilder:()=>f,EnhancerBuilder:()=>I,UniqueBatchEntries:()=>g,compose:()=>Y,createBatchEnhancer:()=>q,createEventBus:()=>ae,createLimitPolicy:()=>T,enhance:()=>K,extractLocales:()=>k,getChannelName:()=>b,getComponentPath:()=>A,isSystemComponentDefinition:()=>oe,localize:()=>pe,mapSlotToPersonalizedVariations:()=>re,mapSlotToTestVariations:()=>ie,nullLimitPolicy:()=>m,subscribeToComposition:()=>ce,walkComponentTree:()=>d});module.exports=H(le);function d(r,e){let n=[{ancestorsAndSelf:[{component:r,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let t=n.pop();if(!t)continue;let o=t.ancestorsAndSelf[0];e(o.component,t.ancestorsAndSelf,{replaceComponent:s=>{Object.assign(o.component,s),["parameters","variant","slots","data","_pattern","_patternError"].forEach(a=>{s[a]||delete o.component[a]})},removeComponent:()=>{let{parentSlot:s,parentSlotIndex:c}=t.ancestorsAndSelf[0],a=t.ancestorsAndSelf[1];if(s&&typeof c!="undefined")a.component.slots[s].splice(c,1);else throw new Error("Unable to delete composition.")},insertAfter:s=>{let c=Array.isArray(s)?s:[s],{parentSlot:a,parentSlotIndex:p}=t.ancestorsAndSelf[0],l=t.ancestorsAndSelf[1];if(a&&typeof p!="undefined")l.component.slots[a].splice(p+1,0,...c);else throw new Error("Unable to insert after a component not in a slot.")}});let i=o.component.slots;if(i){let s=Object.keys(i);for(let c=s.length-1;c>=0;c--){let a=s[c],p=i[a];for(let l=p.length-1;l>=0;l--)n.push({ancestorsAndSelf:[{component:p[l],parentSlot:a,parentSlotIndex:l},...t.ancestorsAndSelf]})}}}while(n.length>0)}function A(r){let e=[];for(let n=r.length-1;n>=0;n--){let{parentSlot:t,parentSlotIndex:o}=r[n];t&&o!==void 0&&e.push(`${t}[${o}]`)}return`.${e.join(".")}`}var g=class{constructor(e,n){this.groups=e.reduce((t,o)=>{var s;let i=n(o.args);return t[i]=(s=t[i])!=null?s:[],t[i].push(o),t},{})}resolveKey(e,n){this.groups[e].forEach(t=>t.resolve(n))}resolveRemaining(e){Object.keys(this.groups).forEach(n=>{this.groups[n].forEach(t=>{t.isCompleted||t.resolve(e)})})}};var f=class{constructor(){this._paramMatches=Array();this._dataMatches=new Map}parameter(e){return this._paramMatches.push({enhancer:this._resolveParameterEnhancer(e)}),this}parameterName(e,n){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({name:o,enhancer:this._resolveParameterEnhancer(n)})),this}parameterType(e,n){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({type:o,enhancer:this._resolveParameterEnhancer(n)})),this}data(e,n){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 n=="function"?{enhanceOne:n}:n),this}resolveParameterEnhancer(e,n){var t;return(t=this._paramMatches.find(o=>o.name&&o.name===e||o.type&&o.type===n.type||!o.type&&!o.name))==null?void 0:t.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},I=class{constructor(){this._componentIndex={};this._rootBuilder=new f}parameter(e){return this._rootBuilder.parameter(e),this}parameterName(e,n){return this._rootBuilder.parameterName(e,n),this}parameterType(e,n){return this._rootBuilder.parameterType(e,n),this}data(e,n){return this._rootBuilder.data(e,n),this}component(e,n){return(Array.isArray(e)?e:[e]).forEach(o=>{this._componentIndex[o]=this._componentIndex[o]||new f,n(this._componentIndex[o])}),this}resolveParameterEnhancer(e,n,t){let o=this._componentIndex[e.type];if(o){let i=o.resolveParameterEnhancer(n,t);if(i)return i}return this._rootBuilder.resolveParameterEnhancer(n,t)}resolveComponentEnhancers(e){let n=this._rootBuilder.resolveComponentEnhancers(),t=this._componentIndex[e.type];if(t){n=new Map(n);for(let[o,i]of t.resolveComponentEnhancers())n.set(o,i)}return n}};var P=class{constructor(e,n,t){this._resolve=e;this._reject=n;this.args=t;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 q({handleBatch:r,shouldQueue:e,limitPolicy:n}){let t=[];return{enhanceOne:async s=>{if(!e||e(s))return new Promise((c,a)=>{t.push(new P(c,a,s))})},completeAll:async()=>{if(t.length>0){try{await r(t)}catch(c){t.forEach(a=>a.reject(c))}if(t.some(c=>!c.isCompleted))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!")}let s=t.length;return t=[],s},limitPolicy:n}}var j=N(require("p-throttle")),V=N(require("p-retry"));function T({throttle:r={interval:1e3,limit:10},retry:e={retries:1,factor:1.66}}){let n=r?(0,j.default)(r):null;return function(o){let i=async()=>await o();if(n&&(i=n(i)),e){let s=i;i=()=>(0,V.default)(s,e)}return i()}}var m=async r=>await r();async function K({composition:r,enhancers:e,context:n,onErrors:t=o=>{throw new Error(o.map(i=>`${i.message}
1
+ var B=Object.create;var C=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var z=(r,e)=>{for(var n in e)C(r,n,{get:e[n],enumerable:!0})},L=(r,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of U(e))!D.call(r,o)&&o!==n&&C(r,o,{get:()=>e[o],enumerable:!(t=M(e,o))||t.enumerable});return r};var N=(r,e,n)=>(n=r!=null?B(F(r)):{},L(e||!r||!r.__esModule?C(n,"default",{value:r,enumerable:!0}):n,r)),H=r=>L(C({},"__esModule",{value:!0}),r);var me={};z(me,{BatchEntry:()=>P,CANVAS_DRAFT_STATE:()=>we,CANVAS_ENRICHMENT_TAG_PARAM:()=>te,CANVAS_INTENT_TAG_PARAM:()=>X,CANVAS_LOCALE_TAG_PARAM:()=>R,CANVAS_LOCALIZATION_SLOT:()=>x,CANVAS_LOCALIZATION_TYPE:()=>v,CANVAS_PERSONALIZATION_PARAM:()=>w,CANVAS_PERSONALIZE_SLOT:()=>ee,CANVAS_PERSONALIZE_TYPE:()=>W,CANVAS_PUBLISHED_STATE:()=>_e,CANVAS_TEST_SLOT:()=>ne,CANVAS_TEST_TYPE:()=>Q,CANVAS_TEST_VARIANT_PARAM:()=>_,CanvasClient:()=>y,CanvasClientError:()=>u,ChildEnhancerBuilder:()=>f,EnhancerBuilder:()=>I,UniqueBatchEntries:()=>g,compose:()=>Y,createBatchEnhancer:()=>q,createEventBus:()=>ae,createLimitPolicy:()=>T,enhance:()=>K,extractLocales:()=>k,getChannelName:()=>b,getComponentPath:()=>A,isSystemComponentDefinition:()=>oe,localize:()=>pe,mapSlotToPersonalizedVariations:()=>re,mapSlotToTestVariations:()=>ie,nullLimitPolicy:()=>l,subscribeToComposition:()=>ce,walkComponentTree:()=>d});module.exports=H(me);function d(r,e){let n=[{ancestorsAndSelf:[{component:r,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let t=n.pop();if(!t)continue;let o=t.ancestorsAndSelf[0];e(o.component,t.ancestorsAndSelf,{replaceComponent:s=>{Object.assign(o.component,s),["parameters","variant","slots","data","_pattern","_patternError"].forEach(a=>{s[a]||delete o.component[a]})},removeComponent:()=>{let{parentSlot:s,parentSlotIndex:c}=t.ancestorsAndSelf[0],a=t.ancestorsAndSelf[1];if(s&&typeof c!="undefined")a.component.slots[s].splice(c,1);else throw new Error("Unable to delete composition.")},insertAfter:s=>{let c=Array.isArray(s)?s:[s],{parentSlot:a,parentSlotIndex:p}=t.ancestorsAndSelf[0],m=t.ancestorsAndSelf[1];if(a&&typeof p!="undefined")m.component.slots[a].splice(p+1,0,...c);else throw new Error("Unable to insert after a component not in a slot.")}});let i=o.component.slots;if(i){let s=Object.keys(i);for(let c=s.length-1;c>=0;c--){let a=s[c],p=i[a];for(let m=p.length-1;m>=0;m--)n.push({ancestorsAndSelf:[{component:p[m],parentSlot:a,parentSlotIndex:m},...t.ancestorsAndSelf]})}}}while(n.length>0)}function A(r){let e=[];for(let n=r.length-1;n>=0;n--){let{parentSlot:t,parentSlotIndex:o}=r[n];t&&o!==void 0&&e.push(`${t}[${o}]`)}return`.${e.join(".")}`}var g=class{constructor(e,n){this.groups=e.reduce((t,o)=>{var s;let i=n(o.args);return t[i]=(s=t[i])!=null?s:[],t[i].push(o),t},{})}resolveKey(e,n){this.groups[e].forEach(t=>t.resolve(n))}resolveRemaining(e){Object.keys(this.groups).forEach(n=>{this.groups[n].forEach(t=>{t.isCompleted||t.resolve(e)})})}};var f=class{constructor(){this._paramMatches=Array();this._dataMatches=new Map}parameter(e){return this._paramMatches.push({enhancer:this._resolveParameterEnhancer(e)}),this}parameterName(e,n){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({name:o,enhancer:this._resolveParameterEnhancer(n)})),this}parameterType(e,n){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({type:o,enhancer:this._resolveParameterEnhancer(n)})),this}data(e,n){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 n=="function"?{enhanceOne:n}:n),this}resolveParameterEnhancer(e,n){var t;return(t=this._paramMatches.find(o=>o.name&&o.name===e||o.type&&o.type===n.type||!o.type&&!o.name))==null?void 0:t.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},I=class{constructor(){this._componentIndex={};this._rootBuilder=new f}parameter(e){return this._rootBuilder.parameter(e),this}parameterName(e,n){return this._rootBuilder.parameterName(e,n),this}parameterType(e,n){return this._rootBuilder.parameterType(e,n),this}data(e,n){return this._rootBuilder.data(e,n),this}component(e,n){return(Array.isArray(e)?e:[e]).forEach(o=>{this._componentIndex[o]=this._componentIndex[o]||new f,n(this._componentIndex[o])}),this}resolveParameterEnhancer(e,n,t){let o=this._componentIndex[e.type];if(o){let i=o.resolveParameterEnhancer(n,t);if(i)return i}return this._rootBuilder.resolveParameterEnhancer(n,t)}resolveComponentEnhancers(e){let n=this._rootBuilder.resolveComponentEnhancers(),t=this._componentIndex[e.type];if(t){n=new Map(n);for(let[o,i]of t.resolveComponentEnhancers())n.set(o,i)}return n}};var P=class{constructor(e,n,t){this._resolve=e;this._reject=n;this.args=t;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 q({handleBatch:r,shouldQueue:e,limitPolicy:n}){let t=[];return{enhanceOne:async s=>{if(!e||e(s))return new Promise((c,a)=>{t.push(new P(c,a,s))})},completeAll:async()=>{if(t.length>0){try{await r(t)}catch(c){t.forEach(a=>a.reject(c))}if(t.some(c=>!c.isCompleted))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!")}let s=t.length;return t=[],s},limitPolicy:n}}var j=N(require("p-throttle")),V=N(require("p-retry"));function T({throttle:r={interval:1e3,limit:10},retry:e={retries:1,factor:1.66}}){let n=r?(0,j.default)(r):null;return function(o){let i=async()=>await o();if(n&&(i=n(i)),e){let s=i;i=()=>(0,V.default)(s,e)}return i()}}var l=async r=>await r();async function K({composition:r,enhancers:e,context:n,onErrors:t=o=>{throw new Error(o.map(i=>`${i.message}
2
2
  ${typeof i.error=="object"&&"stack"in i.error?i.error.stack:i.error}`).join(`
3
3
 
4
- `))}}){let o=[],i=new Set,s=new Set;d(r,(a,p)=>{var h;Object.entries((h=a.parameters)!=null?h:{}).forEach(([S,O])=>{let E=e.resolveParameterEnhancer(a,S,O);E&&(s.add(E),o.push(G(a,p,S,O,E,n)))});let l=e.resolveComponentEnhancers(a);o.push(Z(a,p,l,n)),i.add(l)}),o.push(...Array.from(i).flatMap(a=>Array.from(a).map(async([,p])=>{var l;try{p.completeAll&&await((l=p.limitPolicy)!=null?l:m)(()=>p.completeAll())}catch(h){return{error:h,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),o.push(...Array.from(s).map(async a=>{var p;try{a.completeAll&&await((p=a.limitPolicy)!=null?p:m)(()=>a.completeAll())}catch(l){return{error:l,message:"Batch parameter enhancer failed. Individual failed parameters should receive their own rejections."}}}));let c=(await Promise.all(o)).flatMap(a=>Array.isArray(a)?a:[a]).filter(a=>a);c.length&&t(c)}async function Z(r,e,n,t){return n.size&&(r.data={}),await Promise.all(Array.from(n).map(async([o,i])=>{var s;try{let a=await(i.completeAll?m:(s=i.limitPolicy)!=null?s:m)(async()=>i.enhanceOne({component:r,context:t}));a!=null&&(r.data[o]=a)}catch(c){let a=`Component ${A(e)} (type: ${r.type}): data.${o} enhancer threw exception. Data key will not be present.`;return delete r.data[o],{message:a,error:c}}}))}async function G(r,e,n,t,o,i){var s;try{let a=await(o.completeAll?m:(s=o.limitPolicy)!=null?s:m)(async()=>o.enhanceOne({parameter:t,parameterName:n,component:r,context:i}));a===null?delete r.parameters[n]:typeof a=="undefined"?r.parameters[n]={...t,value:t.value}:r.parameters[n]={...t,value:a}}catch(c){let a=`Component ${A(e)} (type: ${r.type}): enhancing parameter ${n} (type: ${t.type}) threw exception. Parameter will be removed.`;return delete r.parameters[n],{message:a,error:c}}}var Y=(r,...e)=>({enhanceOne:t=>{let o="enhanceOne"in r?r.enhanceOne(t):r(t);for(let i of e){let s=J(o)?o:Promise.resolve(o),c="enhanceOne"in i?i.enhanceOne:i;o=s.then(a=>c({...t,parameter:{type:t.parameter.type,value:a}}))}return o},completeAll:async()=>{var t,o;for(let i of e)if("completeAll"in i)throw new Error("Only the first enhancer in a compose chain can use the completeAll function (batching)");return(o="completeAll"in r?(t=r.completeAll)==null?void 0:t.call(r):0)!=null?o:0}});function J(r){return!!r&&(typeof r=="object"||typeof r=="function")&&typeof r.then=="function"}var u=class extends Error{constructor(n,t,o,i,s,c){super(`${n}
5
- ${i}${s?" "+s:""} (${t} ${o}${c?` Request ID: ${c}`:""})`);this.errorMessage=n;this.fetchMethod=t;this.fetchUri=o;this.statusCode=i;this.statusText=s;this.requestId=c;Object.setPrototypeOf(this,u.prototype)}},y=class{constructor(e){var t,o,i,s,c;if(!e.apiKey&&!e.bearerToken)throw new Error("You must provide an API key or a bearer token");let n=e.fetch;if(!n)if(typeof globalThis!="undefined"&&typeof globalThis.fetch!="undefined")n=globalThis.fetch.bind(globalThis);else if(typeof fetch!="undefined")n=fetch;else throw new Error("You must provide or polyfill a fetch implementation when not in a browser");this.options={...e,fetch:n,apiHost:(t=e.apiHost)!=null?t:"https://uniform.app",apiKey:(o=e.apiKey)!=null?o:null,projectId:(i=e.projectId)!=null?i:null,bearerToken:(s=e.bearerToken)!=null?s:null,limitPolicy:(c=e.limitPolicy)!=null?c:T({})}}async getCompositionList(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async getCompositionBySlug(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async getCompositionById(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async updateComposition(e){let n=this.createUrl("/api/v1/canvas");await this.apiClient(n,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(e){let n=this.createUrl("/api/v1/canvas"),{projectId:t}=this.options;await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:t}),expectNoContent:!0})}async getComponentDefinitions(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas-definitions",{...e,projectId:n});return await this.apiClient(t)}async updateComponentDefinition(e){let n=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(n,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(e){let n=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(e,n){return this.options.limitPolicy(async()=>{var i;let t=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`},o=await this.options.fetch(e.toString(),{...n,headers:{...n==null?void 0:n.headers,...t}});if(!o.ok){let s="";try{let c=await o.text();try{let a=JSON.parse(c);a.errorMessage?s=Array.isArray(a.errorMessage)?a.errorMessage.join(", "):a.errorMessage:s=c}catch(a){s=c}}catch(c){s="General error"}throw new u(s,(i=n==null?void 0:n.method)!=null?i:"GET",e.toString(),o.status,o.statusText,y.getRequestId(o))}return n!=null&&n.expectNoContent?null:await o.json()})}createUrl(e,n){let t=new URL(`${this.options.apiHost}${e}`);return Object.entries(n!=null?n:{}).forEach(([o,i])=>{var s;typeof i!==void 0&&i!==null&&t.searchParams.append(o,(s=i==null?void 0:i.toString())!=null?s:"")}),t}static getRequestId(e){let n=e.headers.get("x-nf-request-id");if(n)return n}};var W="$personalization",Q="$test",v="$localization",X="intentTag",R="locale",ee="pz",ne="test",x="localized",_e=0,we=64,_="$pzCrit",w="$tstVrnt",te="$enr";var oe=r=>r.startsWith("$");function re(r){return r?r.map((e,n)=>{var i,s;let t=(s=(i=e.parameters)==null?void 0:i[_])==null?void 0:s.value,o=(t==null?void 0:t.name)||`pz-${n}-${e.type}`;return{...e,id:o,pz:t}}):[]}function ie(r){return r?r.map((e,n)=>{var i,s,c;let t=(s=(i=e.parameters)==null?void 0:i[w])==null?void 0:s.value,o=(c=t==null?void 0:t.id)!=null?c:"testId"in e?e.testId:`ab-${n}-${e.type}`;return{...e,id:o}}):[]}var $="https://js.pusher.com/7.0.3/pusher.min.js";async function se(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((r,e)=>{let n=setTimeout(()=>{window.Pusher&&r(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${$}"><\/script> manually.`)},5e3),t=document.createElement("script");t.src=$,t.addEventListener("load",()=>{clearTimeout(n),r(window.Pusher)}),document.head.appendChild(t)})}async function ae(){let r=await se();if(!r)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let n=new r("7b5f5abd160fea549ffe",{cluster:"mt1"});n.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:t=>{let o=n.subscribe(t);return{unsubscribe:()=>n.unsubscribe(t),addEventHandler:(i,s)=>(o.bind(i,s),()=>o.unbind(i,s))}}}}return e}function b(r,e,n){return`${r}.${e}@${n}`}function ce({projectId:r,compositionId:e,compositionState:n=0,eventBus:{subscribe:t},callback:o,event:i="updated"}){let s=b(r,e,n),c=t(s),a=c.addEventHandler(i,o);return()=>{a(),c.unsubscribe()}}function k({component:r}){var t;let e={},n=(t=r.slots)==null?void 0:t[x];return n==null||n.forEach(o=>{var s;let i=(s=o.parameters)==null?void 0:s[R];(i==null?void 0:i.value)&&typeof i.value=="string"&&(e[i.value]=e[i.value]||[],e[i.value].push(o))}),e}function pe({composition:r,locale:e}){d(r,(n,t,o)=>{if(n.type===v){let i=k({component:n}),s=typeof e=="string"?e:e({component:n,locales:i}),c;if(s&&(c=i[s]),c!=null&&c.length){let[a,...p]=c;o.replaceComponent(a),p.length&&o.insertAfter(p)}else o.removeComponent()}})}0&&(module.exports={BatchEntry,CANVAS_DRAFT_STATE,CANVAS_ENRICHMENT_TAG_PARAM,CANVAS_INTENT_TAG_PARAM,CANVAS_LOCALE_TAG_PARAM,CANVAS_LOCALIZATION_SLOT,CANVAS_LOCALIZATION_TYPE,CANVAS_PERSONALIZATION_PARAM,CANVAS_PERSONALIZE_SLOT,CANVAS_PERSONALIZE_TYPE,CANVAS_PUBLISHED_STATE,CANVAS_TEST_SLOT,CANVAS_TEST_TYPE,CANVAS_TEST_VARIANT_PARAM,CanvasClient,CanvasClientError,ChildEnhancerBuilder,EnhancerBuilder,UniqueBatchEntries,compose,createBatchEnhancer,createEventBus,createLimitPolicy,enhance,extractLocales,getChannelName,getComponentPath,isSystemComponentDefinition,localize,mapSlotToPersonalizedVariations,mapSlotToTestVariations,nullLimitPolicy,subscribeToComposition,walkComponentTree});
4
+ `))}}){let o=[],i=new Set,s=new Set;d(r,(a,p)=>{var h;Object.entries((h=a.parameters)!=null?h:{}).forEach(([S,O])=>{let E=e.resolveParameterEnhancer(a,S,O);E&&(s.add(E),o.push(G(a,p,S,O,E,n)))});let m=e.resolveComponentEnhancers(a);o.push(Z(a,p,m,n)),i.add(m)}),o.push(...Array.from(i).flatMap(a=>Array.from(a).map(async([,p])=>{var m;try{p.completeAll&&await((m=p.limitPolicy)!=null?m:l)(()=>p.completeAll())}catch(h){return{error:h,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),o.push(...Array.from(s).map(async a=>{var p;try{a.completeAll&&await((p=a.limitPolicy)!=null?p:l)(()=>a.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(a=>Array.isArray(a)?a:[a]).filter(a=>a);c.length&&t(c)}async function Z(r,e,n,t){return n.size&&(r.data={}),await Promise.all(Array.from(n).map(async([o,i])=>{var s;try{let a=await(i.completeAll?l:(s=i.limitPolicy)!=null?s:l)(async()=>i.enhanceOne({component:r,context:t}));a!=null&&(r.data[o]=a)}catch(c){let a=`Component ${A(e)} (type: ${r.type}): data.${o} enhancer threw exception. Data key will not be present.`;return delete r.data[o],{message:a,error:c}}}))}async function G(r,e,n,t,o,i){var s;try{let a=await(o.completeAll?l:(s=o.limitPolicy)!=null?s:l)(async()=>o.enhanceOne({parameter:t,parameterName:n,component:r,context:i}));a===null?delete r.parameters[n]:typeof a=="undefined"?r.parameters[n]={...t,value:t.value}:r.parameters[n]={...t,value:a}}catch(c){let a=`Component ${A(e)} (type: ${r.type}): enhancing parameter ${n} (type: ${t.type}) threw exception. Parameter will be removed.`;return delete r.parameters[n],{message:a,error:c}}}var Y=(r,...e)=>({enhanceOne:t=>{let o="enhanceOne"in r?r.enhanceOne(t):r(t);for(let i of e){let s=J(o)?o:Promise.resolve(o),c="enhanceOne"in i?i.enhanceOne:i;o=s.then(a=>c({...t,parameter:{type:t.parameter.type,value:a}}))}return o},completeAll:async()=>{var t,o;for(let i of e)if("completeAll"in i)throw new Error("Only the first enhancer in a compose chain can use the completeAll function (batching)");return(o="completeAll"in r?(t=r.completeAll)==null?void 0:t.call(r):0)!=null?o:0}});function J(r){return!!r&&(typeof r=="object"||typeof r=="function")&&typeof r.then=="function"}var u=class extends Error{constructor(n,t,o,i,s,c){super(`${n}
5
+ ${i}${s?" "+s:""} (${t} ${o}${c?` Request ID: ${c}`:""})`);this.errorMessage=n;this.fetchMethod=t;this.fetchUri=o;this.statusCode=i;this.statusText=s;this.requestId=c;Object.setPrototypeOf(this,u.prototype)}},y=class{constructor(e){var t,o,i,s,c;if(!e.apiKey&&!e.bearerToken)throw new Error("You must provide an API key or a bearer token");let n=e.fetch;if(!n)if(typeof window!="undefined")n=window.fetch.bind(window);else if(typeof fetch!="undefined")n=fetch;else throw new Error("You must provide or polyfill a fetch implementation when not in a browser");this.options={...e,fetch:n,apiHost:(t=e.apiHost)!=null?t:"https://uniform.app",apiKey:(o=e.apiKey)!=null?o:null,projectId:(i=e.projectId)!=null?i:null,bearerToken:(s=e.bearerToken)!=null?s:null,limitPolicy:(c=e.limitPolicy)!=null?c:T({})}}async getCompositionList(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async getCompositionBySlug(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async getCompositionById(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async updateComposition(e){let n=this.createUrl("/api/v1/canvas");await this.apiClient(n,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(e){let n=this.createUrl("/api/v1/canvas");await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async getComponentDefinitions(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas-definitions",{...e,projectId:n});return await this.apiClient(t)}async updateComponentDefinition(e){let n=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(n,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(e){let n=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(e,n){return this.options.limitPolicy(async()=>{var i;let t=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`},o=await this.options.fetch(e.toString(),{...n,headers:{...n==null?void 0:n.headers,...t}});if(!o.ok){let s="";try{let c=await o.text();try{let a=JSON.parse(c);a.errorMessage?s=Array.isArray(a.errorMessage)?a.errorMessage.join(", "):a.errorMessage:s=c}catch(a){s=c}}catch(c){s="General error"}throw new u(s,(i=n==null?void 0:n.method)!=null?i:"GET",e.toString(),o.status,o.statusText,y.getRequestId(o))}return n!=null&&n.expectNoContent?null:await o.json()})}createUrl(e,n){let t=new URL(`${this.options.apiHost}${e}`);return Object.entries(n!=null?n:{}).forEach(([o,i])=>{var s;typeof i!==void 0&&i!==null&&t.searchParams.append(o,(s=i==null?void 0:i.toString())!=null?s:"")}),t}static getRequestId(e){let n=e.headers.get("x-nf-request-id");if(n)return n}};var W="$personalization",Q="$test",v="$localization",X="intentTag",R="locale",ee="pz",ne="test",x="localized",we=0,_e=64,w="$pzCrit",_="$tstVrnt",te="$enr";var oe=r=>r.startsWith("$");function re(r){return r?r.map((e,n)=>{var i,s;let t=(s=(i=e.parameters)==null?void 0:i[w])==null?void 0:s.value,o=(t==null?void 0:t.name)||`pz-${n}-${e.type}`;return{...e,id:o,pz:t}}):[]}function ie(r){return r?r.map((e,n)=>{var i,s,c;let t=(s=(i=e.parameters)==null?void 0:i[_])==null?void 0:s.value,o=(c=t==null?void 0:t.id)!=null?c:"testId"in e?e.testId:`ab-${n}-${e.type}`;return{...e,id:o}}):[]}var $="https://js.pusher.com/7.0.3/pusher.min.js";async function se(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((r,e)=>{let n=setTimeout(()=>{window.Pusher&&r(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${$}"><\/script> manually.`)},5e3),t=document.createElement("script");t.src=$,t.addEventListener("load",()=>{clearTimeout(n),r(window.Pusher)}),document.head.appendChild(t)})}async function ae(){let r=await se();if(!r)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let n=new r("7b5f5abd160fea549ffe",{cluster:"mt1"});n.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:t=>{let o=n.subscribe(t);return{unsubscribe:()=>n.unsubscribe(t),addEventHandler:(i,s)=>(o.bind(i,s),()=>o.unbind(i,s))}}}}return e}function b(r,e,n){return`${r}.${e}@${n}`}function ce({projectId:r,compositionId:e,compositionState:n=0,eventBus:{subscribe:t},callback:o,event:i="updated"}){let s=b(r,e,n),c=t(s),a=c.addEventHandler(i,o);return()=>{a(),c.unsubscribe()}}function k({component:r}){var t;let e={},n=(t=r.slots)==null?void 0:t[x];return n==null||n.forEach(o=>{var s;let i=(s=o.parameters)==null?void 0:s[R];(i==null?void 0:i.value)&&typeof i.value=="string"&&(e[i.value]=e[i.value]||[],e[i.value].push(o))}),e}function pe({composition:r,locale:e}){d(r,(n,t,o)=>{if(n.type===v){let i=k({component:n}),s=typeof e=="string"?e:e({component:n,locales:i}),c;if(s&&(c=i[s]),c!=null&&c.length){let[a,...p]=c;o.replaceComponent(a),p.length&&o.insertAfter(p)}else o.removeComponent()}})}0&&(module.exports={BatchEntry,CANVAS_DRAFT_STATE,CANVAS_ENRICHMENT_TAG_PARAM,CANVAS_INTENT_TAG_PARAM,CANVAS_LOCALE_TAG_PARAM,CANVAS_LOCALIZATION_SLOT,CANVAS_LOCALIZATION_TYPE,CANVAS_PERSONALIZATION_PARAM,CANVAS_PERSONALIZE_SLOT,CANVAS_PERSONALIZE_TYPE,CANVAS_PUBLISHED_STATE,CANVAS_TEST_SLOT,CANVAS_TEST_TYPE,CANVAS_TEST_VARIANT_PARAM,CanvasClient,CanvasClientError,ChildEnhancerBuilder,EnhancerBuilder,UniqueBatchEntries,compose,createBatchEnhancer,createEventBus,createLimitPolicy,enhance,extractLocales,getChannelName,getComponentPath,isSystemComponentDefinition,localize,mapSlotToPersonalizedVariations,mapSlotToTestVariations,nullLimitPolicy,subscribeToComposition,walkComponentTree});
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";import{d as L,e as l,f as $,g as j,h as k,i as F,j as A,k as V,l as g,m as N,n as U,o as v,p as z,q as W,r as x,s as w,t as H}from"./chunk-HJHWEOMG.mjs";function u(o,e){let t=[{ancestorsAndSelf:[{component:o,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let n=t.pop();if(!n)continue;let r=n.ancestorsAndSelf[0];e(r.component,n.ancestorsAndSelf,{replaceComponent:i=>{Object.assign(r.component,i),["parameters","variant","slots","data","_pattern","_patternError"].forEach(s=>{i[s]||delete r.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=r.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 y(o){let e=[];for(let t=o.length-1;t>=0;t--){let{parentSlot:n,parentSlotIndex:r}=o[t];n&&r!==void 0&&e.push(`${n}[${r}]`)}return`.${e.join(".")}`}var T=class{constructor(e,t){this.groups=e.reduce((n,r)=>{var i;let a=t(r.args);return n[a]=(i=n[a])!=null?i:[],n[a].push(r),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 d=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(r=>this._paramMatches.push({name:r,enhancer:this._resolveParameterEnhancer(t)})),this}parameterType(e,t){return(Array.isArray(e)?e:[e]).forEach(r=>this._paramMatches.push({type:r,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(r=>r.name&&r.name===e||r.type&&r.type===t.type||!r.type&&!r.name))==null?void 0:n.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},_=class{constructor(){this._componentIndex={};this._rootBuilder=new d}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(r=>{this._componentIndex[r]=this._componentIndex[r]||new d,t(this._componentIndex[r])}),this}resolveParameterEnhancer(e,t,n){let r=this._componentIndex[e.type];if(r){let a=r.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[r,a]of n.resolveComponentEnhancers())t.set(r,a)}return t}};var C=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 D({handleBatch:o,shouldQueue:e,limitPolicy:t}){let n=[];return{enhanceOne:async i=>{if(!e||e(i))return new Promise((c,s)=>{n.push(new C(c,s,i))})},completeAll:async()=>{if(n.length>0){try{await o(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}}async function X({composition:o,enhancers:e,context:t,onErrors:n=r=>{throw new Error(r.map(a=>`${a.message}
1
+ import{d as L,e as l,f as $,g as j,h as k,i as F,j as A,k as V,l as g,m as N,n as U,o as v,p as z,q as W,r as x,s as w,t as H}from"./chunk-ADDR7SB6.mjs";function u(o,e){let t=[{ancestorsAndSelf:[{component:o,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let n=t.pop();if(!n)continue;let r=n.ancestorsAndSelf[0];e(r.component,n.ancestorsAndSelf,{replaceComponent:i=>{Object.assign(r.component,i),["parameters","variant","slots","data","_pattern","_patternError"].forEach(s=>{i[s]||delete r.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=r.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 y(o){let e=[];for(let t=o.length-1;t>=0;t--){let{parentSlot:n,parentSlotIndex:r}=o[t];n&&r!==void 0&&e.push(`${n}[${r}]`)}return`.${e.join(".")}`}var T=class{constructor(e,t){this.groups=e.reduce((n,r)=>{var i;let a=t(r.args);return n[a]=(i=n[a])!=null?i:[],n[a].push(r),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 d=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(r=>this._paramMatches.push({name:r,enhancer:this._resolveParameterEnhancer(t)})),this}parameterType(e,t){return(Array.isArray(e)?e:[e]).forEach(r=>this._paramMatches.push({type:r,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(r=>r.name&&r.name===e||r.type&&r.type===t.type||!r.type&&!r.name))==null?void 0:n.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},_=class{constructor(){this._componentIndex={};this._rootBuilder=new d}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(r=>{this._componentIndex[r]=this._componentIndex[r]||new d,t(this._componentIndex[r])}),this}resolveParameterEnhancer(e,t,n){let r=this._componentIndex[e.type];if(r){let a=r.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[r,a]of n.resolveComponentEnhancers())t.set(r,a)}return t}};var C=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 D({handleBatch:o,shouldQueue:e,limitPolicy:t}){let n=[];return{enhanceOne:async i=>{if(!e||e(i))return new Promise((c,s)=>{n.push(new C(c,s,i))})},completeAll:async()=>{if(n.length>0){try{await o(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}}async function X({composition:o,enhancers:e,context:t,onErrors:n=r=>{throw new Error(r.map(a=>`${a.message}
2
2
  ${typeof a.error=="object"&&"stack"in a.error?a.error.stack:a.error}`).join(`
3
3
 
4
4
  `))}}){let r=[],a=new Set,i=new Set;u(o,(s,p)=>{var h;Object.entries((h=s.parameters)!=null?h:{}).forEach(([E,P])=>{let f=e.resolveParameterEnhancer(s,E,P);f&&(i.add(f),r.push(S(s,p,E,P,f,t)))});let m=e.resolveComponentEnhancers(s);r.push(R(s,p,m,t)),a.add(m)}),r.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(h){return{error:h,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),r.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(r)).flatMap(s=>Array.isArray(s)?s:[s]).filter(s=>s);c.length&&n(c)}async function R(o,e,t,n){return t.size&&(o.data={}),await Promise.all(Array.from(t).map(async([r,a])=>{var i;try{let s=await(a.completeAll?l:(i=a.limitPolicy)!=null?i:l)(async()=>a.enhanceOne({component:o,context:n}));s!=null&&(o.data[r]=s)}catch(c){let s=`Component ${y(e)} (type: ${o.type}): data.${r} enhancer threw exception. Data key will not be present.`;return delete o.data[r],{message:s,error:c}}}))}async function S(o,e,t,n,r,a){var i;try{let s=await(r.completeAll?l:(i=r.limitPolicy)!=null?i:l)(async()=>r.enhanceOne({parameter:n,parameterName:t,component:o,context:a}));s===null?delete o.parameters[t]:typeof s=="undefined"?o.parameters[t]={...n,value:n.value}:o.parameters[t]={...n,value:s}}catch(c){let s=`Component ${y(e)} (type: ${o.type}): enhancing parameter ${t} (type: ${n.type}) threw exception. Parameter will be removed.`;return delete o.parameters[t],{message:s,error:c}}}var ne=(o,...e)=>({enhanceOne:n=>{let r="enhanceOne"in o?o.enhanceOne(n):o(n);for(let a of e){let i=B(r)?r:Promise.resolve(r),c="enhanceOne"in a?a.enhanceOne:a;r=i.then(s=>c({...n,parameter:{type:n.parameter.type,value:s}}))}return r},completeAll:async()=>{var n,r;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(r="completeAll"in o?(n=o.completeAll)==null?void 0:n.call(o):0)!=null?r:0}});function B(o){return!!o&&(typeof o=="object"||typeof o=="function")&&typeof o.then=="function"}var re=o=>o.startsWith("$");function se(o){return o?o.map((e,t)=>{var a,i;let n=(i=(a=e.parameters)==null?void 0:a[x])==null?void 0:i.value,r=(n==null?void 0:n.name)||`pz-${t}-${e.type}`;return{...e,id:r,pz:n}}):[]}function pe(o){return o?o.map((e,t)=>{var a,i,c;let n=(i=(a=e.parameters)==null?void 0:a[w])==null?void 0:i.value,r=(c=n==null?void 0:n.id)!=null?c:"testId"in e?e.testId:`ab-${t}-${e.type}`;return{...e,id:r}}):[]}var b="https://js.pusher.com/7.0.3/pusher.min.js";async function O(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((o,e)=>{let t=setTimeout(()=>{window.Pusher&&o(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${b}"><\/script> manually.`)},5e3),n=document.createElement("script");n.src=b,n.addEventListener("load",()=>{clearTimeout(t),o(window.Pusher)}),document.head.appendChild(n)})}async function le(){let o=await O();if(!o)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let t=new o("7b5f5abd160fea549ffe",{cluster:"mt1"});t.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:n=>{let r=t.subscribe(n);return{unsubscribe:()=>t.unsubscribe(n),addEventHandler:(a,i)=>(r.bind(a,i),()=>r.unbind(a,i))}}}}return e}function I(o,e,t){return`${o}.${e}@${t}`}function fe({projectId:o,compositionId:e,compositionState:t=0,eventBus:{subscribe:n},callback:r,event:a="updated"}){let i=I(o,e,t),c=n(i),s=c.addEventHandler(a,r);return()=>{s(),c.unsubscribe()}}function M({component:o}){var n;let e={},t=(n=o.slots)==null?void 0:n[v];return t==null||t.forEach(r=>{var i;let a=(i=r.parameters)==null?void 0:i[g];(a==null?void 0:a.value)&&typeof a.value=="string"&&(e[a.value]=e[a.value]||[],e[a.value].push(r))}),e}function Pe({composition:o,locale:e}){u(o,(t,n,r)=>{if(t.type===A){let a=M({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;r.replaceComponent(s),p.length&&r.insertAfter(p)}else r.removeComponent()}})}export{C as BatchEntry,z as CANVAS_DRAFT_STATE,H as CANVAS_ENRICHMENT_TAG_PARAM,V as CANVAS_INTENT_TAG_PARAM,g as CANVAS_LOCALE_TAG_PARAM,v as CANVAS_LOCALIZATION_SLOT,A as CANVAS_LOCALIZATION_TYPE,x as CANVAS_PERSONALIZATION_PARAM,N as CANVAS_PERSONALIZE_SLOT,k as CANVAS_PERSONALIZE_TYPE,W as CANVAS_PUBLISHED_STATE,U as CANVAS_TEST_SLOT,F as CANVAS_TEST_TYPE,w as CANVAS_TEST_VARIANT_PARAM,j as CanvasClient,$ as CanvasClientError,d as ChildEnhancerBuilder,_ as EnhancerBuilder,T as UniqueBatchEntries,ne as compose,D as createBatchEnhancer,le as createEventBus,L as createLimitPolicy,X as enhance,M as extractLocales,I as getChannelName,y as getComponentPath,re as isSystemComponentDefinition,Pe as localize,se as mapSlotToPersonalizedVariations,pe as mapSlotToTestVariations,l as nullLimitPolicy,fe as subscribeToComposition,u as walkComponentTree};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas",
3
- "version": "16.2.1",
3
+ "version": "16.2.4",
4
4
  "description": "Common functionality and types for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -46,21 +46,22 @@
46
46
  "devDependencies": {
47
47
  "@types/retry": "0.12.1",
48
48
  "@types/yargs": "17.0.10",
49
- "@uniformdev/cli": "^16.2.0",
49
+ "@uniformdev/cli": "^16.2.4",
50
50
  "pusher-js": "7.0.6",
51
51
  "yargs": "17.5.1"
52
52
  },
53
53
  "dependencies": {
54
- "@uniformdev/context": "^16.2.0",
54
+ "@uniformdev/context": "^16.2.4",
55
55
  "isomorphic-unfetch": "^3.1.0",
56
- "p-limit": "4.0.0",
57
- "p-retry": "5.1.1",
58
- "p-throttle": "5.0.0"
56
+ "p-limit": "^3.1.0",
57
+ "p-retry": "^4.6.2",
58
+ "p-throttle": "^4.1.1"
59
59
  },
60
60
  "files": [
61
61
  "/dist"
62
62
  ],
63
63
  "publishConfig": {
64
64
  "access": "public"
65
- }
65
+ },
66
+ "gitHead": "b2ed666efec0c0e255c2a1b8561ff7899834a2d5"
66
67
  }
package/CHANGELOG.md DELETED
@@ -1,151 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- ## [16.2.0](https://github.com/uniformdev/platform/compare/v16.1.0...v16.2.0) (2022-06-30)
7
-
8
- ### Features
9
-
10
- - **canvas:** add optional field to specify name for each variant wit… ([#5725](https://github.com/uniformdev/platform/issues/5725)) ([095b959](https://github.com/uniformdev/platform/commit/095b9590c3cba060b94823345eec5832b5f58fb2))
11
-
12
- ### Bug Fixes
13
-
14
- - **cli:** Fix push command description (not Optimize) ([67e08e3](https://github.com/uniformdev/platform/commit/67e08e347570137c24d21c86b974ccc28d366d4b))
15
- - **cli:** Fix push command description (not Optimize) ([ec63625](https://github.com/uniformdev/platform/commit/ec6362589484362e4fbd9c94db66f9718e734c6a))
16
-
17
- ## [16.1.0](https://github.com/uniformdev/platform/compare/v16.0.0...v16.1.0) (2022-06-02)
18
-
19
- ### Features
20
-
21
- - **canvas:** add help text to canvas parameter (4057) ([e79fb0f](https://github.com/uniformdev/platform/commit/e79fb0fd26e1164414d38f6bd6fba763fa676ef9))
22
- - **security:** add roles support ([71da60b](https://github.com/uniformdev/platform/commit/71da60ba47ccabe993322a3a23f1bc66286991b2)), closes [#4275](https://github.com/uniformdev/platform/issues/4275)
23
-
24
- ## [16.0.0](https://github.com/uniformdev/platform/compare/v15.0.0...v16.0.0) (2022-04-26)
25
-
26
- ### Bug Fixes
27
-
28
- - **deps:** pin dependencies ([bdefb56](https://github.com/uniformdev/platform/commit/bdefb56d3278090905ae48b5f2b0d297c990f4f1))
29
- - **deps:** update dependency yargs to v17.4.1 ([032fbc0](https://github.com/uniformdev/platform/commit/032fbc0192684e5954152b95472f4d5b30164dd7))
30
-
31
- ## [15.0.0](https://github.com/uniformdev/optimize/compare/v14.2.0...v15.0.0) (2022-03-28)
32
-
33
- ### Features
34
-
35
- - **onboarding:** new Context based onboarding projects ([b33b88e](https://github.com/uniformdev/optimize/commit/b33b88e54d0be144d556c6112bff94bdb19cffb8)), closes [#4316](https://github.com/uniformdev/optimize/issues/4316)
36
-
37
- ### Bug Fixes
38
-
39
- - **deps:** update dependency yargs to v17.4.0 ([b25061e](https://github.com/uniformdev/optimize/commit/b25061e0761ecacac15bcc618a059e56809fd6fb))
40
-
41
- ### [14.1.1](https://github.com/uniformdev/optimize-sdk-internal/compare/v14.1.0...v14.1.1) (2022-02-02)
42
-
43
- **Note:** Version bump only for package @uniformdev/canvas
44
-
45
- ## [14.1.0](https://github.com/uniformdev/optimize-sdk-internal/compare/v14.0.0...v14.1.0) (2022-02-02)
46
-
47
- ### Features
48
-
49
- - **composition-defaults:** add `defaults` prop to `ComponentDefinition` ([5679a4e](https://github.com/uniformdev/optimize-sdk-internal/commit/5679a4e266ad416832154e6a18054f7ce39f1f3d)), closes [#3182](https://github.com/uniformdev/optimize-sdk-internal/issues/3182)
50
-
51
- ## [14.0.0](https://github.com/uniformdev/optimize-sdk-internal/compare/v13.0.0...v14.0.0) (2021-12-21)
52
-
53
- ### Features
54
-
55
- - **dashbord:** add slags setting to ComponentDefinition ([#3347](https://github.com/uniformdev/optimize-sdk-internal/issues/3347)) ([#776](https://github.com/uniformdev/optimize-sdk-internal/issues/776)) ([07804d8](https://github.com/uniformdev/optimize-sdk-internal/commit/07804d820f2dbec8182b9c401761e71ab5642a17))
56
- - **dashbord:** update slags setting to ComponentDefinition ([#3347](https://github.com/uniformdev/optimize-sdk-internal/issues/3347)) ([#778](https://github.com/uniformdev/optimize-sdk-internal/issues/778)) ([29cec98](https://github.com/uniformdev/optimize-sdk-internal/commit/29cec98248b1c07c6983b0cf6192ec54396b1f5a))
57
- - **typescript:** expose updated type con ComponentDefinition ([#705](https://github.com/uniformdev/optimize-sdk-internal/issues/705)) ([4275a7c](https://github.com/uniformdev/optimize-sdk-internal/commit/4275a7cfd3fbd8b84549638d503c0f77d390208d))
58
-
59
- ### Bug Fixes
60
-
61
- - **canvas:** Use fetch based on options ([8c73f59](https://github.com/uniformdev/optimize-sdk-internal/commit/8c73f592371d01e106773f8a5b51dd60154fa3b4))
62
- - **deps:** upgrade dependency versions ([2ed0022](https://github.com/uniformdev/optimize-sdk-internal/commit/2ed002274b06f06e13e0be1f3024a9b93a2f6d14))
63
-
64
- ## [13.0.0](https://github.com/uniformdev/optimize-sdk-internal/compare/v12.2.0...v13.0.0) (2021-11-24)
65
-
66
- ### ⚠ BREAKING CHANGES
67
-
68
- - **npm:** Bundled ESM exports from npm packages have changed internal package structure
69
- - **npm:** npm package files are now transpiled to target ES2018 instead of ES5, significantly reducing their size
70
-
71
- ### Features
72
-
73
- - **localization:** added insertAfter walk component action, support for matching multiple components of the same locale, associated tests. BREAKING CHANGE: localize locale function now provides an array of matched components ([#680](https://github.com/uniformdev/optimize-sdk-internal/issues/680)) ([0071e16](https://github.com/uniformdev/optimize-sdk-internal/commit/0071e168f8a5e5f5cecd3ce908383dc690d3fd3c))
74
- - **npm:** update package build system for better ESM compatibility ([d66f998](https://github.com/uniformdev/optimize-sdk-internal/commit/d66f998e30e186dbe7886a9d4197c49a8b25b89c))
75
-
76
- ### Bug Fixes
77
-
78
- - **canvas:** load pusher from CDN only when needed ([25f2b18](https://github.com/uniformdev/optimize-sdk-internal/commit/25f2b1873668b171a2f210000d785108c238fafe))
79
-
80
- ## [12.2.0](https://github.com/uniformdev/optimize-sdk-internal/compare/v12.0.0...v12.2.0) (2021-10-28)
81
-
82
- ### Features
83
-
84
- - **canvas-cli:** support serializing and fetching pattern references ([cb701bc](https://github.com/uniformdev/optimize-sdk-internal/commit/cb701bc5ef6fd46460190986480b183dfec6a280))
85
- - **canvas-sdk:** support for patterns ([33d421c](https://github.com/uniformdev/optimize-sdk-internal/commit/33d421cbf1cd7afaee7dd9f71b48f8f9c40ce589))
86
- - **localization:** added localize function, updated walk component function to allow component level modifications ([b1766e0](https://github.com/uniformdev/optimize-sdk-internal/commit/b1766e0ab1fa4e072a19216a715f756121a19626))
87
-
88
- ### Bug Fixes
89
-
90
- - **canvas-sdk:** improved enhancer error messaging ([6ff0026](https://github.com/uniformdev/optimize-sdk-internal/commit/6ff0026fd5702e3ef7474a82057c8dde86765c16))
91
- - export localize from canvas package ([#627](https://github.com/uniformdev/optimize-sdk-internal/issues/627)) ([69b87bc](https://github.com/uniformdev/optimize-sdk-internal/commit/69b87bc05d2f0e3ed3bac8b20fc395686db82a51))
92
- - **localization:** added a list of undefined fields that need to be checked after replacing a component to ensure they match ([#628](https://github.com/uniformdev/optimize-sdk-internal/issues/628)) ([278f9f3](https://github.com/uniformdev/optimize-sdk-internal/commit/278f9f380bdb3e0826a9edbce773d5a03050feaf))
93
- - **localization:** added walk component test coverage, fixed typo ([15687c0](https://github.com/uniformdev/optimize-sdk-internal/commit/15687c0ecf3df23fb4080064d7c358cbb6bbe346))
94
- - **localization:** comment for locale tag param ([07b4ac4](https://github.com/uniformdev/optimize-sdk-internal/commit/07b4ac4287e6644a3ab7307cdd5f013c5c03c251))
95
-
96
- ## [12.0.0](https://github.com/uniformdev/optimize-sdk-internal/compare/v11.0.0...v12.0.0) (2021-10-05)
97
-
98
- ### ⚠ BREAKING CHANGES
99
-
100
- - **canvas:** everything that was named 'UPM' at all is now equivalently titled 'Canvas' or 'CANVAS' depending on the context. Literally everything.
101
-
102
- ### Features
103
-
104
- - **canvas-cli:** add update diffing support (--diff flag) ([62a34a1](https://github.com/uniformdev/optimize-sdk-internal/commit/62a34a1728b0e087a769ea0819b7f00cd65b526a))
105
- - **canvas:** farewell UPM, we hardly knew ye ([00997ae](https://github.com/uniformdev/optimize-sdk-internal/commit/00997aecd388403a0b98d0a919750b994d3794c1))
106
-
107
- ### Bug Fixes
108
-
109
- - **canvas-cli:** improved canvas CLI scalability and messaging ([4ad2ea4](https://github.com/uniformdev/optimize-sdk-internal/commit/4ad2ea47749ec11684db24605da50b6dfb067236))
110
-
111
- ## [11.0.0](https://github.com/uniformdev/optimize-sdk-internal/compare/v10.0.0...v11.0.0) (2021-09-07)
112
-
113
- ### ⚠ BREAKING CHANGES
114
-
115
- - **upm:** this CLI will only work with 'new' API keys for UPM APIs
116
- - **cli+cms:** the UNIFORM_CLI_BASE_URL environment variable should now be set to the Uniform dashboard URL, not an AWS S3 bucket
117
-
118
- ### Features
119
-
120
- - **cli+cms:** support new proxied intent manifest endpoint ([a43f4db](https://github.com/uniformdev/optimize-sdk-internal/commit/a43f4db4743deb2752b20db0cc047eaf08c705a0))
121
- - **upm:** support project ID requirement for UPM APIs ([f139b29](https://github.com/uniformdev/optimize-sdk-internal/commit/f139b29357c4f1525ba4420073e19137be7e7869))
122
- - **upm:** throw if source for UPM cli sync is empty (to prevent unintentional delete-all) ([0f97e44](https://github.com/uniformdev/optimize-sdk-internal/commit/0f97e444c88dc5d3dbb304014810566a9b16f026))
123
-
124
- ### Bug Fixes
125
-
126
- - **upm-cli:** don't store state on disk - use CLI param instead ([a638928](https://github.com/uniformdev/optimize-sdk-internal/commit/a638928a17b8cc56b125e62628881819f26934e6)), closes [#2550](https://github.com/uniformdev/optimize-sdk-internal/issues/2550)
127
- - **upm:** await actions before running deletes ([f58aa95](https://github.com/uniformdev/optimize-sdk-internal/commit/f58aa952fc1d9af76e8fcd0d4cf7139f24966175))
128
- - **upm:** fixed deleting UPM items when pushing with the CLI ([6f301c9](https://github.com/uniformdev/optimize-sdk-internal/commit/6f301c94ea1c78b94e00c753b86d2af92b938819))
129
- - **upm:** fixed error instanceof UpmClientError ([1027695](https://github.com/uniformdev/optimize-sdk-internal/commit/10276954d469da227c8bfec0f374a4f7fafd0b7b))
130
- - **upm:** fixed naughty type refs that weren't externally resolvable, resulting in faux `any` types ([ee5d7e2](https://github.com/uniformdev/optimize-sdk-internal/commit/ee5d7e2e8c93f08afc562a36e3baa8499830e249))
131
- - **upm:** make enhancerbuilder fallback as expected when overriding params ([4d8edb4](https://github.com/uniformdev/optimize-sdk-internal/commit/4d8edb4932944293b927a579b68f5d14a93b9008))
132
- - **upm:** upm comp list not supporting states ([0920553](https://github.com/uniformdev/optimize-sdk-internal/commit/092055369ff38b25a4e32209c95afb56f3c15255))
133
-
134
- ## [10.0.0](https://github.com/uniformdev/optimize-sdk-internal/compare/v9.0.1...v10.0.0) (2021-08-11)
135
-
136
- ### Features
137
-
138
- - **cli:** add upm CLI plugin ([9b027f4](https://github.com/uniformdev/optimize-sdk-internal/commit/9b027f4f0bcd144a322b7fa2e051692c2a813372))
139
- - **upm:** add enhancer proxy, generic enhancers, enhancer batching ([8de1402](https://github.com/uniformdev/optimize-sdk-internal/commit/8de1402da957388f11662af4f39d183e1ad5437a))
140
- - **upm:** add packaging to the CLI for multiple artifacts in one file ([7d9c5b3](https://github.com/uniformdev/optimize-sdk-internal/commit/7d9c5b35016b82f5bc85e9a462bc9206cef486c2))
141
- - **upm:** add types for UPM component definition API, unified types for composition API ([eb4296a](https://github.com/uniformdev/optimize-sdk-internal/commit/eb4296a0908dfe48b7fe8973dfe319f7c9e1ae1c))
142
-
143
- ### [9.0.1](https://github.com/uniformdev/optimize-sdk-internal/compare/v9.0.0...v9.0.1) (2021-07-12)
144
-
145
- **Note:** Version bump only for package @uniformdev/upm
146
-
147
- ## [9.0.0](https://github.com/uniformdev/optimize-sdk-internal/compare/v8.0.1...v9.0.0) (2021-06-30)
148
-
149
- ### Features
150
-
151
- - **upm:** add initial UPM SDK ([e2419b7](https://github.com/uniformdev/optimize-sdk-internal/commit/e2419b77a987c686ec1594d37e1c1452912f10fa))
@@ -1,2 +0,0 @@
1
- var m=Object.create;var h=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty;var R=(o=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(o,{get:(t,e)=>(typeof require!="undefined"?require:t)[e]}):o)(function(o){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+o+'" is not supported')});var T=(o,t)=>()=>(t||o((t={exports:{}}).exports,t),t.exports);var y=(o,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of d(t))!C.call(o,n)&&n!==e&&h(o,n,{get:()=>t[n],enumerable:!(i=f(t,n))||i.enumerable});return o};var O=(o,t,e)=>(e=o!=null?m(I(o)):{},y(t||!o||!o.__esModule?h(e,"default",{value:o,enumerable:!0}):e,o));import P from"p-retry";var u=import("p-throttle");console.log("pThrottle",u);var N=u.Options;function A({throttle:o={interval:1e3,limit:10},retry:t={retries:1,factor:1.66}}){let e=o?u(o):null;return function(n){let s=async()=>await n();if(e&&(s=e(s)),t){let r=s;s=()=>P(r,t)}return s()}}var x=async o=>await o();var a=class extends Error{constructor(e,i,n,s,r,p){super(`${e}
2
- ${s}${r?" "+r:""} (${i} ${n}${p?` Request ID: ${p}`:""})`);this.errorMessage=e;this.fetchMethod=i;this.fetchUri=n;this.statusCode=s;this.statusText=r;this.requestId=p;Object.setPrototypeOf(this,a.prototype)}},l=class{constructor(t){var i,n,s,r,p;if(!t.apiKey&&!t.bearerToken)throw new Error("You must provide an API key or a bearer token");let e=t.fetch;if(!e)if(typeof globalThis!="undefined"&&typeof globalThis.fetch!="undefined")e=globalThis.fetch.bind(globalThis);else if(typeof fetch!="undefined")e=fetch;else throw new Error("You must provide or polyfill a fetch implementation when not in a browser");this.options={...t,fetch:e,apiHost:(i=t.apiHost)!=null?i:"https://uniform.app",apiKey:(n=t.apiKey)!=null?n:null,projectId:(s=t.projectId)!=null?s:null,bearerToken:(r=t.bearerToken)!=null?r:null,limitPolicy:(p=t.limitPolicy)!=null?p:A({})}}async getCompositionList(t){let{projectId:e}=this.options,i=this.createUrl("/api/v1/canvas",{...t,projectId:e});return await this.apiClient(i)}async getCompositionBySlug(t){let{projectId:e}=this.options,i=this.createUrl("/api/v1/canvas",{...t,projectId:e});return await this.apiClient(i)}async getCompositionById(t){let{projectId:e}=this.options,i=this.createUrl("/api/v1/canvas",{...t,projectId:e});return await this.apiClient(i)}async updateComposition(t){let e=this.createUrl("/api/v1/canvas");await this.apiClient(e,{method:"PUT",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(t){let e=this.createUrl("/api/v1/canvas"),{projectId:i}=this.options;await this.apiClient(e,{method:"DELETE",body:JSON.stringify({...t,projectId:i}),expectNoContent:!0})}async getComponentDefinitions(t){let{projectId:e}=this.options,i=this.createUrl("/api/v1/canvas-definitions",{...t,projectId:e});return await this.apiClient(i)}async updateComponentDefinition(t){let e=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(e,{method:"PUT",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(t){let e=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(e,{method:"DELETE",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(t,e){return this.options.limitPolicy(async()=>{var s;let i=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`},n=await this.options.fetch(t.toString(),{...e,headers:{...e==null?void 0:e.headers,...i}});if(!n.ok){let r="";try{let p=await n.text();try{let c=JSON.parse(p);c.errorMessage?r=Array.isArray(c.errorMessage)?c.errorMessage.join(", "):c.errorMessage:r=p}catch(c){r=p}}catch(p){r="General error"}throw new a(r,(s=e==null?void 0:e.method)!=null?s:"GET",t.toString(),n.status,n.statusText,l.getRequestId(n))}return e!=null&&e.expectNoContent?null:await n.json()})}createUrl(t,e){let i=new URL(`${this.options.apiHost}${t}`);return Object.entries(e!=null?e:{}).forEach(([n,s])=>{var r;typeof s!==void 0&&s!==null&&i.searchParams.append(n,(r=s==null?void 0:s.toString())!=null?r:"")}),i}static getRequestId(t){let e=t.headers.get("x-nf-request-id");if(e)return e}};var w="$personalization",U="$test",V="$localization",D="intentTag",v="locale",k="pz",$="test",M="localized",q=0,H=64,z="$pzCrit",F="$tstVrnt",K="$enr";export{R as a,T as b,O as c,A as d,x as e,a as f,l as g,w as h,U as i,V as j,D as k,v as l,k as m,$ as n,M as o,q as p,H as q,z as r,F as s,K as t};
@@ -1,2 +0,0 @@
1
- var A=Object.create;var u=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var d=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var P=(o=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(o,{get:(t,e)=>(typeof require!="undefined"?require:t)[e]}):o)(function(o){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+o+'" is not supported')});var R=(o,t)=>()=>(t||o((t={exports:{}}).exports,t),t.exports);var I=(o,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of f(t))!y.call(o,n)&&n!==e&&u(o,n,{get:()=>t[n],enumerable:!(i=m(t,n))||i.enumerable});return o};var T=(o,t,e)=>(e=o!=null?A(d(o)):{},I(t||!o||!o.__esModule?u(e,"default",{value:o,enumerable:!0}):e,o));import C from"p-retry";async function h({throttle:o={interval:1e3,limit:10},retry:t={retries:1,factor:1.66}}){let e=o?(await import("p-throttle"))(o):null;return function(n){let s=async()=>await n();if(e&&(s=e(s)),t){let r=s;s=()=>C(r,t)}return s()}}var S=async o=>await o();var a=class extends Error{constructor(e,i,n,s,r,p){super(`${e}
2
- ${s}${r?" "+r:""} (${i} ${n}${p?` Request ID: ${p}`:""})`);this.errorMessage=e;this.fetchMethod=i;this.fetchUri=n;this.statusCode=s;this.statusText=r;this.requestId=p;Object.setPrototypeOf(this,a.prototype)}},l=class{constructor(t){var i,n,s,r,p;if(!t.apiKey&&!t.bearerToken)throw new Error("You must provide an API key or a bearer token");let e=t.fetch;if(!e)if(typeof globalThis!="undefined"&&typeof globalThis.fetch!="undefined")e=globalThis.fetch.bind(globalThis);else if(typeof fetch!="undefined")e=fetch;else throw new Error("You must provide or polyfill a fetch implementation when not in a browser");this.options={...t,fetch:e,apiHost:(i=t.apiHost)!=null?i:"https://uniform.app",apiKey:(n=t.apiKey)!=null?n:null,projectId:(s=t.projectId)!=null?s:null,bearerToken:(r=t.bearerToken)!=null?r:null,limitPolicy:(p=t.limitPolicy)!=null?p:h({})}}async getCompositionList(t){let{projectId:e}=this.options,i=this.createUrl("/api/v1/canvas",{...t,projectId:e});return await this.apiClient(i)}async getCompositionBySlug(t){let{projectId:e}=this.options,i=this.createUrl("/api/v1/canvas",{...t,projectId:e});return await this.apiClient(i)}async getCompositionById(t){let{projectId:e}=this.options,i=this.createUrl("/api/v1/canvas",{...t,projectId:e});return await this.apiClient(i)}async updateComposition(t){let e=this.createUrl("/api/v1/canvas");await this.apiClient(e,{method:"PUT",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(t){let e=this.createUrl("/api/v1/canvas"),{projectId:i}=this.options;await this.apiClient(e,{method:"DELETE",body:JSON.stringify({...t,projectId:i}),expectNoContent:!0})}async getComponentDefinitions(t){let{projectId:e}=this.options,i=this.createUrl("/api/v1/canvas-definitions",{...t,projectId:e});return await this.apiClient(i)}async updateComponentDefinition(t){let e=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(e,{method:"PUT",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(t){let e=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(e,{method:"DELETE",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(t,e){return this.options.limitPolicy(async()=>{var s;let i=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`},n=await this.options.fetch(t.toString(),{...e,headers:{...e==null?void 0:e.headers,...i}});if(!n.ok){let r="";try{let p=await n.text();try{let c=JSON.parse(p);c.errorMessage?r=Array.isArray(c.errorMessage)?c.errorMessage.join(", "):c.errorMessage:r=p}catch(c){r=p}}catch(p){r="General error"}throw new a(r,(s=e==null?void 0:e.method)!=null?s:"GET",t.toString(),n.status,n.statusText,l.getRequestId(n))}return e!=null&&e.expectNoContent?null:await n.json()})}createUrl(t,e){let i=new URL(`${this.options.apiHost}${t}`);return Object.entries(e!=null?e:{}).forEach(([n,s])=>{var r;typeof s!==void 0&&s!==null&&i.searchParams.append(n,(r=s==null?void 0:s.toString())!=null?r:"")}),i}static getRequestId(t){let e=t.headers.get("x-nf-request-id");if(e)return e}};var _="$personalization",j="$test",w="$localization",U="intentTag",V="locale",D="pz",v="test",k="localized",$=0,M=64,q="$pzCrit",H="$tstVrnt",z="$enr";export{P as a,R as b,T as c,h as d,S as e,a as f,l as g,_ as h,j as i,w as j,U as k,V as l,D as m,v as n,k as o,$ as p,M as q,q as r,H as s,z as t};
@@ -1,2 +0,0 @@
1
- var A=Object.create;var u=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var d=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var R=(o=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(o,{get:(t,e)=>(typeof require!="undefined"?require:t)[e]}):o)(function(o){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+o+'" is not supported')});var T=(o,t)=>()=>(t||o((t={exports:{}}).exports,t),t.exports);var C=(o,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of f(t))!I.call(o,n)&&n!==e&&u(o,n,{get:()=>t[n],enumerable:!(i=m(t,n))||i.enumerable});return o};var O=(o,t,e)=>(e=o!=null?A(d(o)):{},C(t||!o||!o.__esModule?u(e,"default",{value:o,enumerable:!0}):e,o));import y from"p-throttle";import P from"p-retry";function h({throttle:o={interval:1e3,limit:10},retry:t={retries:1,factor:1.66}}){let e=o?y(o):null;return function(n){let s=async()=>await n();if(e&&(s=e(s)),t){let r=s;s=()=>P(r,t)}return s()}}var E=async o=>await o();var a=class extends Error{constructor(e,i,n,s,r,p){super(`${e}
2
- ${s}${r?" "+r:""} (${i} ${n}${p?` Request ID: ${p}`:""})`);this.errorMessage=e;this.fetchMethod=i;this.fetchUri=n;this.statusCode=s;this.statusText=r;this.requestId=p;Object.setPrototypeOf(this,a.prototype)}},l=class{constructor(t){var i,n,s,r,p;if(!t.apiKey&&!t.bearerToken)throw new Error("You must provide an API key or a bearer token");let e=t.fetch;if(!e)if(typeof globalThis!="undefined"&&typeof globalThis.fetch!="undefined")e=globalThis.fetch.bind(globalThis);else if(typeof fetch!="undefined")e=fetch;else throw new Error("You must provide or polyfill a fetch implementation when not in a browser");this.options={...t,fetch:e,apiHost:(i=t.apiHost)!=null?i:"https://uniform.app",apiKey:(n=t.apiKey)!=null?n:null,projectId:(s=t.projectId)!=null?s:null,bearerToken:(r=t.bearerToken)!=null?r:null,limitPolicy:(p=t.limitPolicy)!=null?p:h({})}}async getCompositionList(t){let{projectId:e}=this.options,i=this.createUrl("/api/v1/canvas",{...t,projectId:e});return await this.apiClient(i)}async getCompositionBySlug(t){let{projectId:e}=this.options,i=this.createUrl("/api/v1/canvas",{...t,projectId:e});return await this.apiClient(i)}async getCompositionById(t){let{projectId:e}=this.options,i=this.createUrl("/api/v1/canvas",{...t,projectId:e});return await this.apiClient(i)}async updateComposition(t){let e=this.createUrl("/api/v1/canvas");await this.apiClient(e,{method:"PUT",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(t){let e=this.createUrl("/api/v1/canvas"),{projectId:i}=this.options;await this.apiClient(e,{method:"DELETE",body:JSON.stringify({...t,projectId:i}),expectNoContent:!0})}async getComponentDefinitions(t){let{projectId:e}=this.options,i=this.createUrl("/api/v1/canvas-definitions",{...t,projectId:e});return await this.apiClient(i)}async updateComponentDefinition(t){let e=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(e,{method:"PUT",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(t){let e=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(e,{method:"DELETE",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(t,e){return this.options.limitPolicy(async()=>{var s;let i=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`},n=await this.options.fetch(t.toString(),{...e,headers:{...e==null?void 0:e.headers,...i}});if(!n.ok){let r="";try{let p=await n.text();try{let c=JSON.parse(p);c.errorMessage?r=Array.isArray(c.errorMessage)?c.errorMessage.join(", "):c.errorMessage:r=p}catch(c){r=p}}catch(p){r="General error"}throw new a(r,(s=e==null?void 0:e.method)!=null?s:"GET",t.toString(),n.status,n.statusText,l.getRequestId(n))}return e!=null&&e.expectNoContent?null:await n.json()})}createUrl(t,e){let i=new URL(`${this.options.apiHost}${t}`);return Object.entries(e!=null?e:{}).forEach(([n,s])=>{var r;typeof s!==void 0&&s!==null&&i.searchParams.append(n,(r=s==null?void 0:s.toString())!=null?r:"")}),i}static getRequestId(t){let e=t.headers.get("x-nf-request-id");if(e)return e}};var U="$personalization",V="$test",D="$localization",v="intentTag",k="locale",$="pz",M="test",q="localized",H=0,z=64,F="$pzCrit",K="$tstVrnt",G="$enr";export{R as a,T as b,O as c,h as d,E as e,a as f,l as g,U as h,V as i,D as j,v as k,k as l,$ as m,M as n,q as o,H as p,z as q,F as r,K as s,G as t};
@@ -1,2 +0,0 @@
1
- var R=Object.create;var A=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var S=(o=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(o,{get:(t,e)=>(typeof require!="undefined"?require:t)[e]}):o)(function(o){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+o+'" is not supported')});var L=(o,t)=>()=>(t||o((t={exports:{}}).exports,t),t.exports);var N=(o,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of g(t))!x.call(o,n)&&n!==e&&A(o,n,{get:()=>t[n],enumerable:!(i=O(t,n))||i.enumerable});return o};var _=(o,t,e)=>(e=o!=null?R(b(o)):{},N(t||!o||!o.__esModule?A(e,"default",{value:o,enumerable:!0}):e,o));var d=class extends Error{constructor(){super("Throttled function aborted"),this.name="AbortError"}},y=({limit:o,interval:t,strict:e})=>{if(!Number.isFinite(o))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(t))throw new TypeError("Expected `interval` to be a finite number");let i=new Map,n=0,s=0;function r(){let p=Date.now();return p-n>t?(s=1,n=p,0):(s<o?s++:(n+=t,s=1),n-p)}let c=[];function l(){let p=Date.now();if(c.length<o)return c.push(p),0;let a=c.shift()+t;return p>=a?(c.push(p),0):(c.push(a),a-p)}let I=e?l:r;return p=>{let a=function(...u){if(!a.isEnabled)return(async()=>p.apply(this,u))();let m;return new Promise((P,T)=>{m=setTimeout(()=>{P(p.apply(this,u)),i.delete(m)},I()),i.set(m,T)})};return a.abort=()=>{for(let u of i.keys())clearTimeout(u),i.get(u)(new d);i.clear(),c.splice(0,c.length)},a.isEnabled=!0,a}};import E from"p-retry";function C({throttle:o={interval:1e3,limit:10},retry:t={retries:1,factor:1.66}}){let e=o?y(o):null;return function(n){let s=async()=>await n();if(e&&(s=e(s)),t){let r=s;s=()=>E(r,t)}return s()}}var v=async o=>await o();var h=class extends Error{constructor(e,i,n,s,r,c){super(`${e}
2
- ${s}${r?" "+r:""} (${i} ${n}${c?` Request ID: ${c}`:""})`);this.errorMessage=e;this.fetchMethod=i;this.fetchUri=n;this.statusCode=s;this.statusText=r;this.requestId=c;Object.setPrototypeOf(this,h.prototype)}},f=class{constructor(t){var i,n,s,r,c;if(!t.apiKey&&!t.bearerToken)throw new Error("You must provide an API key or a bearer token");let e=t.fetch;if(!e)if(typeof globalThis!="undefined"&&typeof globalThis.fetch!="undefined")e=globalThis.fetch.bind(globalThis);else if(typeof fetch!="undefined")e=fetch;else throw new Error("You must provide or polyfill a fetch implementation when not in a browser");this.options={...t,fetch:e,apiHost:(i=t.apiHost)!=null?i:"https://uniform.app",apiKey:(n=t.apiKey)!=null?n:null,projectId:(s=t.projectId)!=null?s:null,bearerToken:(r=t.bearerToken)!=null?r:null,limitPolicy:(c=t.limitPolicy)!=null?c:C({})}}async getCompositionList(t){let{projectId:e}=this.options,i=this.createUrl("/api/v1/canvas",{...t,projectId:e});return await this.apiClient(i)}async getCompositionBySlug(t){let{projectId:e}=this.options,i=this.createUrl("/api/v1/canvas",{...t,projectId:e});return await this.apiClient(i)}async getCompositionById(t){let{projectId:e}=this.options,i=this.createUrl("/api/v1/canvas",{...t,projectId:e});return await this.apiClient(i)}async updateComposition(t){let e=this.createUrl("/api/v1/canvas");await this.apiClient(e,{method:"PUT",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(t){let e=this.createUrl("/api/v1/canvas"),{projectId:i}=this.options;await this.apiClient(e,{method:"DELETE",body:JSON.stringify({...t,projectId:i}),expectNoContent:!0})}async getComponentDefinitions(t){let{projectId:e}=this.options,i=this.createUrl("/api/v1/canvas-definitions",{...t,projectId:e});return await this.apiClient(i)}async updateComponentDefinition(t){let e=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(e,{method:"PUT",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(t){let e=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(e,{method:"DELETE",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(t,e){return this.options.limitPolicy(async()=>{var s;let i=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`},n=await this.options.fetch(t.toString(),{...e,headers:{...e==null?void 0:e.headers,...i}});if(!n.ok){let r="";try{let c=await n.text();try{let l=JSON.parse(c);l.errorMessage?r=Array.isArray(l.errorMessage)?l.errorMessage.join(", "):l.errorMessage:r=c}catch(l){r=c}}catch(c){r="General error"}throw new h(r,(s=e==null?void 0:e.method)!=null?s:"GET",t.toString(),n.status,n.statusText,f.getRequestId(n))}return e!=null&&e.expectNoContent?null:await n.json()})}createUrl(t,e){let i=new URL(`${this.options.apiHost}${t}`);return Object.entries(e!=null?e:{}).forEach(([n,s])=>{var r;typeof s!==void 0&&s!==null&&i.searchParams.append(n,(r=s==null?void 0:s.toString())!=null?r:"")}),i}static getRequestId(t){let e=t.headers.get("x-nf-request-id");if(e)return e}};var H="$personalization",z="$test",K="$localization",G="intentTag",J="locale",Y="pz",Z="test",B="localized",Q=0,W=64,X="$pzCrit",tt="$tstVrnt",et="$enr";export{S as a,L as b,_ as c,C as d,v as e,h as f,f as g,H as h,z as i,K as j,G as k,J as l,Y as m,Z as n,B as o,Q as p,W as q,X as r,tt as s,et as t};
@@ -1,2 +0,0 @@
1
- var m=Object.create;var u=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var R=(o=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(o,{get:(t,e)=>(typeof require!="undefined"?require:t)[e]}):o)(function(o){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+o+'" is not supported')});var T=(o,t)=>()=>(t||o((t={exports:{}}).exports,t),t.exports);var C=(o,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of d(t))!y.call(o,n)&&n!==e&&u(o,n,{get:()=>t[n],enumerable:!(i=f(t,n))||i.enumerable});return o};var O=(o,t,e)=>(e=o!=null?m(I(o)):{},C(t||!o||!o.__esModule?u(e,"default",{value:o,enumerable:!0}):e,o));import P from"p-retry";var h=import("p-throttle");console.log("pThrottle",h);function A({throttle:o={interval:1e3,limit:10},retry:t={retries:1,factor:1.66}}){let e=o?h(o):null;return function(n){let s=async()=>await n();if(e&&(s=e(s)),t){let r=s;s=()=>P(r,t)}return s()}}var L=async o=>await o();var a=class extends Error{constructor(e,i,n,s,r,p){super(`${e}
2
- ${s}${r?" "+r:""} (${i} ${n}${p?` Request ID: ${p}`:""})`);this.errorMessage=e;this.fetchMethod=i;this.fetchUri=n;this.statusCode=s;this.statusText=r;this.requestId=p;Object.setPrototypeOf(this,a.prototype)}},l=class{constructor(t){var i,n,s,r,p;if(!t.apiKey&&!t.bearerToken)throw new Error("You must provide an API key or a bearer token");let e=t.fetch;if(!e)if(typeof globalThis!="undefined"&&typeof globalThis.fetch!="undefined")e=globalThis.fetch.bind(globalThis);else if(typeof fetch!="undefined")e=fetch;else throw new Error("You must provide or polyfill a fetch implementation when not in a browser");this.options={...t,fetch:e,apiHost:(i=t.apiHost)!=null?i:"https://uniform.app",apiKey:(n=t.apiKey)!=null?n:null,projectId:(s=t.projectId)!=null?s:null,bearerToken:(r=t.bearerToken)!=null?r:null,limitPolicy:(p=t.limitPolicy)!=null?p:A({})}}async getCompositionList(t){let{projectId:e}=this.options,i=this.createUrl("/api/v1/canvas",{...t,projectId:e});return await this.apiClient(i)}async getCompositionBySlug(t){let{projectId:e}=this.options,i=this.createUrl("/api/v1/canvas",{...t,projectId:e});return await this.apiClient(i)}async getCompositionById(t){let{projectId:e}=this.options,i=this.createUrl("/api/v1/canvas",{...t,projectId:e});return await this.apiClient(i)}async updateComposition(t){let e=this.createUrl("/api/v1/canvas");await this.apiClient(e,{method:"PUT",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(t){let e=this.createUrl("/api/v1/canvas"),{projectId:i}=this.options;await this.apiClient(e,{method:"DELETE",body:JSON.stringify({...t,projectId:i}),expectNoContent:!0})}async getComponentDefinitions(t){let{projectId:e}=this.options,i=this.createUrl("/api/v1/canvas-definitions",{...t,projectId:e});return await this.apiClient(i)}async updateComponentDefinition(t){let e=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(e,{method:"PUT",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(t){let e=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(e,{method:"DELETE",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(t,e){return this.options.limitPolicy(async()=>{var s;let i=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`},n=await this.options.fetch(t.toString(),{...e,headers:{...e==null?void 0:e.headers,...i}});if(!n.ok){let r="";try{let p=await n.text();try{let c=JSON.parse(p);c.errorMessage?r=Array.isArray(c.errorMessage)?c.errorMessage.join(", "):c.errorMessage:r=p}catch(c){r=p}}catch(p){r="General error"}throw new a(r,(s=e==null?void 0:e.method)!=null?s:"GET",t.toString(),n.status,n.statusText,l.getRequestId(n))}return e!=null&&e.expectNoContent?null:await n.json()})}createUrl(t,e){let i=new URL(`${this.options.apiHost}${t}`);return Object.entries(e!=null?e:{}).forEach(([n,s])=>{var r;typeof s!==void 0&&s!==null&&i.searchParams.append(n,(r=s==null?void 0:s.toString())!=null?r:"")}),i}static getRequestId(t){let e=t.headers.get("x-nf-request-id");if(e)return e}};var j="$personalization",w="$test",U="$localization",V="intentTag",D="locale",v="pz",k="test",$="localized",M=0,q=64,H="$pzCrit",z="$tstVrnt",F="$enr";export{R as a,T as b,O as c,A as d,L as e,a as f,l as g,j as h,w as i,U as j,V as k,D as l,v as m,k as n,$ as o,M as p,q,H as r,z as s,F as t};