@uniformdev/canvas 16.2.1 → 16.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-REQRKU67.mjs → chunk-25VHCM7A.mjs} +2 -2
- package/dist/{chunk-ELYMSEKS.mjs → chunk-3FNUBWQC.mjs} +2 -2
- package/dist/{chunk-HJHWEOMG.mjs → chunk-6YIHVVY7.mjs} +2 -2
- package/dist/cli/cli.d.ts +0 -0
- package/dist/cli/cli.js +37 -37
- package/dist/cli/cli.mjs +1 -1
- package/dist/createEventBus-f5cdcc4e.d.ts +0 -0
- package/dist/index.d.ts +16 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.js +3 -3
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-4MW5D2TW.mjs +0 -2
- package/dist/chunk-TCXTKDSU.mjs +0 -2
package/dist/cli/cli.mjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"use strict";import{a as be,b as Ks,c as Vs,g as ne,p as Js,q as ir}from"../chunk-
|
1
|
+
"use strict";import{a as be,b as Ks,c as Vs,g as ne,p as Js,q as ir}from"../chunk-25VHCM7A.mjs";var Is=Ks((pn,Jt)=>{var Nf=200,Xi="__lodash_hash_undefined__",cs=1,zn=2,fs=9007199254740991,Hn="[object Arguments]",zi="[object Array]",us="[object Boolean]",ps="[object Date]",ds="[object Error]",hs="[object Function]",Tf="[object GeneratorFunction]",Bn="[object Map]",ms="[object Number]",Vt="[object Object]",Xo="[object Promise]",gs="[object RegExp]",Wn="[object Set]",bs="[object String]",Rf="[object Symbol]",Gi="[object WeakMap]",ys="[object ArrayBuffer]",Yn="[object DataView]",$f="[object Float32Array]",Uf="[object Float64Array]",Hf="[object Int8Array]",Bf="[object Int16Array]",Wf="[object Int32Array]",Yf="[object Uint8Array]",kf="[object Uint8ClampedArray]",zf="[object Uint16Array]",Gf="[object Uint32Array]",qf=/[\\^$.*+?()[\]{}|]/g,Kf=/^\[object .+?Constructor\]$/,Vf=/^(?:0|[1-9]\d*)$/,te={};te[$f]=te[Uf]=te[Hf]=te[Bf]=te[Wf]=te[Yf]=te[kf]=te[zf]=te[Gf]=!0;te[Hn]=te[zi]=te[ys]=te[us]=te[Yn]=te[ps]=te[ds]=te[hs]=te[Bn]=te[ms]=te[Vt]=te[gs]=te[Wn]=te[bs]=te[Gi]=!1;var ws=typeof global=="object"&&global&&global.Object===Object&&global,Jf=typeof self=="object"&&self&&self.Object===Object&&self,rt=ws||Jf||Function("return this")(),Cs=typeof pn=="object"&&pn&&!pn.nodeType&&pn,es=Cs&&typeof Jt=="object"&&Jt&&!Jt.nodeType&&Jt,Qf=es&&es.exports===Cs,ts=Qf&&ws.process,ns=function(){try{return ts&&ts.binding("util")}catch(e){}}(),is=ns&&ns.isTypedArray;function Zf(e,t){for(var n=-1,i=e?e.length:0;++n<i;)if(t(e[n],n,e))return!0;return!1}function Xf(e,t){for(var n=-1,i=Array(e);++n<e;)i[n]=t(n);return i}function eu(e){return function(t){return e(t)}}function tu(e,t){return e==null?void 0:e[t]}function qi(e){var t=!1;if(e!=null&&typeof e.toString!="function")try{t=!!(e+"")}catch(n){}return t}function nu(e){var t=-1,n=Array(e.size);return e.forEach(function(i,r){n[++t]=[r,i]}),n}function iu(e,t){return function(n){return e(t(n))}}function ru(e){var t=-1,n=Array(e.size);return e.forEach(function(i){n[++t]=i}),n}var ou=Array.prototype,su=Function.prototype,Gn=Object.prototype,Yi=rt["__core-js_shared__"],rs=function(){var e=/[^.]+$/.exec(Yi&&Yi.keys&&Yi.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),As=su.toString,ze=Gn.hasOwnProperty,mn=Gn.toString,au=RegExp("^"+As.call(ze).replace(qf,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),os=rt.Symbol,ss=rt.Uint8Array,lu=Gn.propertyIsEnumerable,cu=ou.splice,fu=iu(Object.keys,Object),Ki=Qt(rt,"DataView"),dn=Qt(rt,"Map"),Vi=Qt(rt,"Promise"),Ji=Qt(rt,"Set"),Qi=Qt(rt,"WeakMap"),hn=Qt(Object,"create"),uu=Tt(Ki),pu=Tt(dn),du=Tt(Vi),hu=Tt(Ji),mu=Tt(Qi),as=os?os.prototype:void 0,ki=as?as.valueOf:void 0;function Dt(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var i=e[t];this.set(i[0],i[1])}}function gu(){this.__data__=hn?hn(null):{}}function bu(e){return this.has(e)&&delete this.__data__[e]}function yu(e){var t=this.__data__;if(hn){var n=t[e];return n===Xi?void 0:n}return ze.call(t,e)?t[e]:void 0}function wu(e){var t=this.__data__;return hn?t[e]!==void 0:ze.call(t,e)}function Cu(e,t){var n=this.__data__;return n[e]=hn&&t===void 0?Xi:t,this}Dt.prototype.clear=gu;Dt.prototype.delete=bu;Dt.prototype.get=yu;Dt.prototype.has=wu;Dt.prototype.set=Cu;function Ge(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var i=e[t];this.set(i[0],i[1])}}function Au(){this.__data__=[]}function xu(e){var t=this.__data__,n=qn(t,e);if(n<0)return!1;var i=t.length-1;return n==i?t.pop():cu.call(t,n,1),!0}function vu(e){var t=this.__data__,n=qn(t,e);return n<0?void 0:t[n][1]}function Ou(e){return qn(this.__data__,e)>-1}function _u(e,t){var n=this.__data__,i=qn(n,e);return i<0?n.push([e,t]):n[i][1]=t,this}Ge.prototype.clear=Au;Ge.prototype.delete=xu;Ge.prototype.get=vu;Ge.prototype.has=Ou;Ge.prototype.set=_u;function Nt(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var i=e[t];this.set(i[0],i[1])}}function Eu(){this.__data__={hash:new Dt,map:new(dn||Ge),string:new Dt}}function Su(e){return Kn(this,e).delete(e)}function Iu(e){return Kn(this,e).get(e)}function ju(e){return Kn(this,e).has(e)}function Pu(e,t){return Kn(this,e).set(e,t),this}Nt.prototype.clear=Eu;Nt.prototype.delete=Su;Nt.prototype.get=Iu;Nt.prototype.has=ju;Nt.prototype.set=Pu;function kn(e){var t=-1,n=e?e.length:0;for(this.__data__=new Nt;++t<n;)this.add(e[t])}function Mu(e){return this.__data__.set(e,Xi),this}function Fu(e){return this.__data__.has(e)}kn.prototype.add=kn.prototype.push=Mu;kn.prototype.has=Fu;function it(e){this.__data__=new Ge(e)}function Lu(){this.__data__=new Ge}function Du(e){return this.__data__.delete(e)}function Nu(e){return this.__data__.get(e)}function Tu(e){return this.__data__.has(e)}function Ru(e,t){var n=this.__data__;if(n instanceof Ge){var i=n.__data__;if(!dn||i.length<Nf-1)return i.push([e,t]),this;n=this.__data__=new Nt(i)}return n.set(e,t),this}it.prototype.clear=Lu;it.prototype.delete=Du;it.prototype.get=Nu;it.prototype.has=Tu;it.prototype.set=Ru;function $u(e,t){var n=Zi(e)||Ju(e)?Xf(e.length,String):[],i=n.length,r=!!i;for(var s in e)(t||ze.call(e,s))&&!(r&&(s=="length"||Gu(s,i)))&&n.push(s);return n}function qn(e,t){for(var n=e.length;n--;)if(Os(e[n][0],t))return n;return-1}function Uu(e){return mn.call(e)}function xs(e,t,n,i,r){return e===t?!0:e==null||t==null||!er(e)&&!tr(t)?e!==e&&t!==t:Hu(e,t,xs,n,i,r)}function Hu(e,t,n,i,r,s){var o=Zi(e),a=Zi(t),l=zi,c=zi;o||(l=nt(e),l=l==Hn?Vt:l),a||(c=nt(t),c=c==Hn?Vt:c);var f=l==Vt&&!qi(e),u=c==Vt&&!qi(t),p=l==c;if(p&&!f)return s||(s=new it),o||Xu(e)?vs(e,t,n,i,r,s):ku(e,t,l,n,i,r,s);if(!(r&zn)){var h=f&&ze.call(e,"__wrapped__"),g=u&&ze.call(t,"__wrapped__");if(h||g){var b=h?e.value():e,m=g?t.value():t;return s||(s=new it),n(b,m,i,r,s)}}return p?(s||(s=new it),zu(e,t,n,i,r,s)):!1}function Bu(e){if(!er(e)||Ku(e))return!1;var t=Es(e)||qi(e)?au:Kf;return t.test(Tt(e))}function Wu(e){return tr(e)&&Ss(e.length)&&!!te[mn.call(e)]}function Yu(e){if(!Vu(e))return fu(e);var t=[];for(var n in Object(e))ze.call(e,n)&&n!="constructor"&&t.push(n);return t}function vs(e,t,n,i,r,s){var o=r&zn,a=e.length,l=t.length;if(a!=l&&!(o&&l>a))return!1;var c=s.get(e);if(c&&s.get(t))return c==t;var f=-1,u=!0,p=r&cs?new kn:void 0;for(s.set(e,t),s.set(t,e);++f<a;){var h=e[f],g=t[f];if(i)var b=o?i(g,h,f,t,e,s):i(h,g,f,e,t,s);if(b!==void 0){if(b)continue;u=!1;break}if(p){if(!Zf(t,function(m,x){if(!p.has(x)&&(h===m||n(h,m,i,r,s)))return p.add(x)})){u=!1;break}}else if(!(h===g||n(h,g,i,r,s))){u=!1;break}}return s.delete(e),s.delete(t),u}function ku(e,t,n,i,r,s,o){switch(n){case Yn:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case ys:return!(e.byteLength!=t.byteLength||!i(new ss(e),new ss(t)));case us:case ps:case ms:return Os(+e,+t);case ds:return e.name==t.name&&e.message==t.message;case gs:case bs:return e==t+"";case Bn:var a=nu;case Wn:var l=s&zn;if(a||(a=ru),e.size!=t.size&&!l)return!1;var c=o.get(e);if(c)return c==t;s|=cs,o.set(e,t);var f=vs(a(e),a(t),i,r,s,o);return o.delete(e),f;case Rf:if(ki)return ki.call(e)==ki.call(t)}return!1}function zu(e,t,n,i,r,s){var o=r&zn,a=ls(e),l=a.length,c=ls(t),f=c.length;if(l!=f&&!o)return!1;for(var u=l;u--;){var p=a[u];if(!(o?p in t:ze.call(t,p)))return!1}var h=s.get(e);if(h&&s.get(t))return h==t;var g=!0;s.set(e,t),s.set(t,e);for(var b=o;++u<l;){p=a[u];var m=e[p],x=t[p];if(i)var v=o?i(x,m,p,t,e,s):i(m,x,p,e,t,s);if(!(v===void 0?m===x||n(m,x,i,r,s):v)){g=!1;break}b||(b=p=="constructor")}if(g&&!b){var L=e.constructor,Y=t.constructor;L!=Y&&"constructor"in e&&"constructor"in t&&!(typeof L=="function"&&L instanceof L&&typeof Y=="function"&&Y instanceof Y)&&(g=!1)}return s.delete(e),s.delete(t),g}function Kn(e,t){var n=e.__data__;return qu(t)?n[typeof t=="string"?"string":"hash"]:n.map}function Qt(e,t){var n=tu(e,t);return Bu(n)?n:void 0}var nt=Uu;(Ki&&nt(new Ki(new ArrayBuffer(1)))!=Yn||dn&&nt(new dn)!=Bn||Vi&&nt(Vi.resolve())!=Xo||Ji&&nt(new Ji)!=Wn||Qi&&nt(new Qi)!=Gi)&&(nt=function(e){var t=mn.call(e),n=t==Vt?e.constructor:void 0,i=n?Tt(n):void 0;if(i)switch(i){case uu:return Yn;case pu:return Bn;case du:return Xo;case hu:return Wn;case mu:return Gi}return t});function Gu(e,t){return t=t==null?fs:t,!!t&&(typeof e=="number"||Vf.test(e))&&e>-1&&e%1==0&&e<t}function qu(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}function Ku(e){return!!rs&&rs in e}function Vu(e){var t=e&&e.constructor,n=typeof t=="function"&&t.prototype||Gn;return e===n}function Tt(e){if(e!=null){try{return As.call(e)}catch(t){}try{return e+""}catch(t){}}return""}function Os(e,t){return e===t||e!==e&&t!==t}function Ju(e){return Qu(e)&&ze.call(e,"callee")&&(!lu.call(e,"callee")||mn.call(e)==Hn)}var Zi=Array.isArray;function _s(e){return e!=null&&Ss(e.length)&&!Es(e)}function Qu(e){return tr(e)&&_s(e)}function Zu(e,t,n){n=typeof n=="function"?n:void 0;var i=n?n(e,t):void 0;return i===void 0?xs(e,t,n):!!i}function Es(e){var t=er(e)?mn.call(e):"";return t==hs||t==Tf}function Ss(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=fs}function er(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function tr(e){return!!e&&typeof e=="object"}var Xu=is?eu(is):Wu;function ls(e){return _s(e)?$u(e):Yu(e)}Jt.exports=Zu});import{notStrictEqual as xa,strictEqual as va}from"assert";var Qs={right:na,center:ia},Zs=0,gn=1,Xs=2,bn=3,ni=class{constructor(t){var n;this.width=t.width,this.wrap=(n=t.wrap)!==null&&n!==void 0?n:!0,this.rows=[]}span(...t){let n=this.div(...t);n.span=!0}resetOutput(){this.rows=[]}div(...t){if(t.length===0&&this.div(""),this.wrap&&this.shouldApplyLayoutDSL(...t)&&typeof t[0]=="string")return this.applyLayoutDSL(t[0]);let n=t.map(i=>typeof i=="string"?this.colFromString(i):i);return this.rows.push(n),n}shouldApplyLayoutDSL(...t){return t.length===1&&typeof t[0]=="string"&&/[\t\n]/.test(t[0])}applyLayoutDSL(t){let n=t.split(`
|
2
2
|
`).map(r=>r.split(" ")),i=0;return n.forEach(r=>{r.length>1&&_e.stringWidth(r[0])>i&&(i=Math.min(Math.floor(this.width*.5),_e.stringWidth(r[0])))}),n.forEach(r=>{this.div(...r.map((s,o)=>({text:s.trim(),padding:this.measurePadding(s),width:o===0&&r.length>1?i:void 0})))}),this.rows[this.rows.length-1]}colFromString(t){return{text:t,padding:this.measurePadding(t)}}measurePadding(t){let n=_e.stripAnsi(t);return[0,n.match(/\s*$/)[0].length,0,n.match(/^\s*/)[0].length]}toString(){let t=[];return this.rows.forEach(n=>{this.rowToString(n,t)}),t.filter(n=>!n.hidden).map(n=>n.text).join(`
|
3
3
|
`)}rowToString(t,n){return this.rasterize(t).forEach((i,r)=>{let s="";i.forEach((o,a)=>{let{width:l}=t[a],c=this.negatePadding(t[a]),f=o;if(c>_e.stringWidth(o)&&(f+=" ".repeat(c-_e.stringWidth(o))),t[a].align&&t[a].align!=="left"&&this.wrap){let p=Qs[t[a].align];f=p(f,c),_e.stringWidth(f)<c&&(f+=" ".repeat((l||0)-_e.stringWidth(f)-1))}let u=t[a].padding||[0,0,0,0];u[bn]&&(s+=" ".repeat(u[bn])),s+=rr(t[a],f,"| "),s+=f,s+=rr(t[a],f," |"),u[gn]&&(s+=" ".repeat(u[gn])),r===0&&n.length>0&&(s=this.renderInline(s,n[n.length-1]))}),n.push({text:s.replace(/ +$/,""),span:t.span})}),n}renderInline(t,n){let i=t.match(/^ */),r=i?i[0].length:0,s=n.text,o=_e.stringWidth(s.trimRight());return n.span?this.wrap?r<o?t:(n.hidden=!0,s.trimRight()+" ".repeat(r-o)+t.trimLeft()):(n.hidden=!0,s+t):t}rasterize(t){let n=[],i=this.columnWidths(t),r;return t.forEach((s,o)=>{s.width=i[o],this.wrap?r=_e.wrap(s.text,this.negatePadding(s),{hard:!0}).split(`
|
4
4
|
`):r=s.text.split(`
|
File without changes
|
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1
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
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';
|
3
|
-
import { Options } from 'p-throttle';
|
4
3
|
import { Options as Options$1 } from 'p-retry';
|
5
4
|
import { PersonalizedVariant, TestVariant } from '@uniformdev/context';
|
6
5
|
import 'pusher-js';
|
@@ -240,6 +239,22 @@ declare function enhance<TContext extends EnhancerContext = EnhancerContext>({ c
|
|
240
239
|
*/
|
241
240
|
declare const compose: (input: ComponentParameterEnhancer<any, any> | ComponentParameterEnhancerFunction<any>, ...composers: ReadonlyArray<ComponentParameterEnhancer<any, any> | ComponentParameterEnhancerFunction<any>>) => ComponentParameterEnhancer<any, any>;
|
242
241
|
|
242
|
+
interface Options {
|
243
|
+
/**
|
244
|
+
The maximum number of calls within an `interval`.
|
245
|
+
*/
|
246
|
+
readonly limit: number;
|
247
|
+
/**
|
248
|
+
The timespan for `limit` in milliseconds.
|
249
|
+
*/
|
250
|
+
readonly interval: number;
|
251
|
+
/**
|
252
|
+
Use a strict, more resource intensive, throttling algorithm. The default algorithm uses a windowed approach that will work correctly in most cases, limiting the total number of calls at the specified limit per interval window. The strict algorithm throttles each call individually, ensuring the limit is not exceeded for any interval.
|
253
|
+
@default false
|
254
|
+
*/
|
255
|
+
readonly strict?: boolean;
|
256
|
+
}
|
257
|
+
|
243
258
|
declare type LimitPolicy = <ReturnValue>(func: () => Promise<ReturnValue>) => Promise<ReturnValue>;
|
244
259
|
declare function createLimitPolicy({ throttle, retry, }: {
|
245
260
|
throttle?: Options | false;
|
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-
|
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-25VHCM7A.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
|
1
|
+
"use strict";var M=Object.create;var P=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var H=(r,e)=>{for(var t in e)P(r,t,{get:e[t],enumerable:!0})},j=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of D(e))!z.call(r,o)&&o!==t&&P(r,o,{get:()=>e[o],enumerable:!(n=U(e,o))||n.enumerable});return r};var q=(r,e,t)=>(t=r!=null?M(F(r)):{},j(e||!r||!r.__esModule?P(t,"default",{value:r,enumerable:!0}):t,r)),K=r=>j(P({},"__esModule",{value:!0}),r);var ue={};H(ue,{BatchEntry:()=>T,CANVAS_DRAFT_STATE:()=>Le,CANVAS_ENRICHMENT_TAG_PARAM:()=>re,CANVAS_INTENT_TAG_PARAM:()=>te,CANVAS_LOCALE_TAG_PARAM:()=>_,CANVAS_LOCALIZATION_SLOT:()=>S,CANVAS_LOCALIZATION_TYPE:()=>R,CANVAS_PERSONALIZATION_PARAM:()=>O,CANVAS_PERSONALIZE_SLOT:()=>ne,CANVAS_PERSONALIZE_TYPE:()=>X,CANVAS_PUBLISHED_STATE:()=>Ne,CANVAS_TEST_SLOT:()=>oe,CANVAS_TEST_TYPE:()=>ee,CANVAS_TEST_VARIANT_PARAM:()=>L,CanvasClient:()=>E,CanvasClientError:()=>f,ChildEnhancerBuilder:()=>A,EnhancerBuilder:()=>x,UniqueBatchEntries:()=>I,compose:()=>W,createBatchEnhancer:()=>Z,createEventBus:()=>pe,createLimitPolicy:()=>b,enhance:()=>G,extractLocales:()=>$,getChannelName:()=>N,getComponentPath:()=>g,isSystemComponentDefinition:()=>ie,localize:()=>me,mapSlotToPersonalizedVariations:()=>se,mapSlotToTestVariations:()=>ae,nullLimitPolicy:()=>h,subscribeToComposition:()=>le,walkComponentTree:()=>C});module.exports=K(ue);function C(r,e){let t=[{ancestorsAndSelf:[{component:r,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let n=t.pop();if(!n)continue;let o=n.ancestorsAndSelf[0];e(o.component,n.ancestorsAndSelf,{replaceComponent: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}=n.ancestorsAndSelf[0],a=n.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:l}=n.ancestorsAndSelf[0],p=n.ancestorsAndSelf[1];if(a&&typeof l!="undefined")p.component.slots[a].splice(l+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],l=i[a];for(let p=l.length-1;p>=0;p--)t.push({ancestorsAndSelf:[{component:l[p],parentSlot:a,parentSlotIndex:p},...n.ancestorsAndSelf]})}}}while(t.length>0)}function g(r){let e=[];for(let t=r.length-1;t>=0;t--){let{parentSlot:n,parentSlotIndex:o}=r[t];n&&o!==void 0&&e.push(`${n}[${o}]`)}return`.${e.join(".")}`}var I=class{constructor(e,t){this.groups=e.reduce((n,o)=>{var s;let i=t(o.args);return n[i]=(s=n[i])!=null?s:[],n[i].push(o),n},{})}resolveKey(e,t){this.groups[e].forEach(n=>n.resolve(t))}resolveRemaining(e){Object.keys(this.groups).forEach(t=>{this.groups[t].forEach(n=>{n.isCompleted||n.resolve(e)})})}};var A=class{constructor(){this._paramMatches=Array();this._dataMatches=new Map}parameter(e){return this._paramMatches.push({enhancer:this._resolveParameterEnhancer(e)}),this}parameterName(e,t){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({name:o,enhancer:this._resolveParameterEnhancer(t)})),this}parameterType(e,t){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({type:o,enhancer:this._resolveParameterEnhancer(t)})),this}data(e,t){if(this._dataMatches.has(e))throw new Error(`${e} enhancer data key has been used more than once. This will cause data loss.`);return this._dataMatches.set(e,typeof t=="function"?{enhanceOne:t}:t),this}resolveParameterEnhancer(e,t){var n;return(n=this._paramMatches.find(o=>o.name&&o.name===e||o.type&&o.type===t.type||!o.type&&!o.name))==null?void 0:n.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},x=class{constructor(){this._componentIndex={};this._rootBuilder=new A}parameter(e){return this._rootBuilder.parameter(e),this}parameterName(e,t){return this._rootBuilder.parameterName(e,t),this}parameterType(e,t){return this._rootBuilder.parameterType(e,t),this}data(e,t){return this._rootBuilder.data(e,t),this}component(e,t){return(Array.isArray(e)?e:[e]).forEach(o=>{this._componentIndex[o]=this._componentIndex[o]||new A,t(this._componentIndex[o])}),this}resolveParameterEnhancer(e,t,n){let o=this._componentIndex[e.type];if(o){let i=o.resolveParameterEnhancer(t,n);if(i)return i}return this._rootBuilder.resolveParameterEnhancer(t,n)}resolveComponentEnhancers(e){let t=this._rootBuilder.resolveComponentEnhancers(),n=this._componentIndex[e.type];if(n){t=new Map(t);for(let[o,i]of n.resolveComponentEnhancers())t.set(o,i)}return t}};var T=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 Z({handleBatch:r,shouldQueue:e,limitPolicy:t}){let n=[];return{enhanceOne:async s=>{if(!e||e(s))return new Promise((c,a)=>{n.push(new T(c,a,s))})},completeAll:async()=>{if(n.length>0){try{await r(n)}catch(c){n.forEach(a=>a.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 s=n.length;return n=[],s},limitPolicy:t}}var v=class extends Error{constructor(){super("Throttled function aborted"),this.name="AbortError"}};function w({limit:r,interval:e,strict:t}){if(!Number.isFinite(r))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(e))throw new TypeError("Expected `interval` to be a finite number");let n=new Map,o=0,i=0;function s(){let p=Date.now();return p-o>e?(i=1,o=p,0):(i<r?i++:(o+=e,i=1),o-p)}let c=[];function a(){let p=Date.now();if(c.length<r)return c.push(p),0;let m=c.shift()+e;return p>=m?(c.push(p),0):(c.push(m),m-p)}let l=t?a:s;return p=>{let m=function(...u){if(!m.isEnabled)return(async()=>p.apply(this,u))();let d;return new Promise((y,B)=>{d=setTimeout(()=>{y(p.apply(this,u)),n.delete(d)},l()),n.set(d,B)})};return m.abort=()=>{for(let u of n.keys())clearTimeout(u),n.get(u)(new v);n.clear(),c.splice(0,c.length)},m.isEnabled=!0,m}}var V=q(require("p-retry"));function b({throttle:r={interval:1e3,limit:10},retry:e={retries:1,factor:1.66}}){let t=r?w(r):null;return function(o){let i=async()=>await o();if(t&&(i=t(i)),e){let s=i;i=()=>(0,V.default)(s,e)}return i()}}var h=async r=>await r();async function G({composition:r,enhancers:e,context:t,onErrors:n=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;
|
5
|
-
${i}${s?" "+s:""} (${
|
4
|
+
`))}}){let o=[],i=new Set,s=new Set;C(r,(a,l)=>{var m;Object.entries((m=a.parameters)!=null?m:{}).forEach(([u,d])=>{let y=e.resolveParameterEnhancer(a,u,d);y&&(s.add(y),o.push(J(a,l,u,d,y,t)))});let p=e.resolveComponentEnhancers(a);o.push(Y(a,l,p,t)),i.add(p)}),o.push(...Array.from(i).flatMap(a=>Array.from(a).map(async([,l])=>{var p;try{l.completeAll&&await((p=l.limitPolicy)!=null?p:h)(()=>l.completeAll())}catch(m){return{error:m,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),o.push(...Array.from(s).map(async a=>{var l;try{a.completeAll&&await((l=a.limitPolicy)!=null?l:h)(()=>a.completeAll())}catch(p){return{error:p,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&&n(c)}async function Y(r,e,t,n){return t.size&&(r.data={}),await Promise.all(Array.from(t).map(async([o,i])=>{var s;try{let a=await(i.completeAll?h:(s=i.limitPolicy)!=null?s:h)(async()=>i.enhanceOne({component:r,context:n}));a!=null&&(r.data[o]=a)}catch(c){let a=`Component ${g(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 J(r,e,t,n,o,i){var s;try{let a=await(o.completeAll?h:(s=o.limitPolicy)!=null?s:h)(async()=>o.enhanceOne({parameter:n,parameterName:t,component:r,context:i}));a===null?delete r.parameters[t]:typeof a=="undefined"?r.parameters[t]={...n,value:n.value}:r.parameters[t]={...n,value:a}}catch(c){let a=`Component ${g(e)} (type: ${r.type}): enhancing parameter ${t} (type: ${n.type}) threw exception. Parameter will be removed.`;return delete r.parameters[t],{message:a,error:c}}}var W=(r,...e)=>({enhanceOne:n=>{let o="enhanceOne"in r?r.enhanceOne(n):r(n);for(let i of e){let s=Q(o)?o:Promise.resolve(o),c="enhanceOne"in i?i.enhanceOne:i;o=s.then(a=>c({...n,parameter:{type:n.parameter.type,value:a}}))}return o},completeAll:async()=>{var n,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?(n=r.completeAll)==null?void 0:n.call(r):0)!=null?o:0}});function Q(r){return!!r&&(typeof r=="object"||typeof r=="function")&&typeof r.then=="function"}var f=class extends Error{constructor(t,n,o,i,s,c){super(`${t}
|
5
|
+
${i}${s?" "+s:""} (${n} ${o}${c?` Request ID: ${c}`:""})`);this.errorMessage=t;this.fetchMethod=n;this.fetchUri=o;this.statusCode=i;this.statusText=s;this.requestId=c;Object.setPrototypeOf(this,f.prototype)}},E=class{constructor(e){var n,o,i,s,c;if(!e.apiKey&&!e.bearerToken)throw new Error("You must provide an API key or a bearer token");let t=e.fetch;if(!t)if(typeof globalThis!="undefined"&&typeof globalThis.fetch!="undefined")t=globalThis.fetch.bind(globalThis);else if(typeof fetch!="undefined")t=fetch;else throw new Error("You must provide or polyfill a fetch implementation when not in a browser");this.options={...e,fetch:t,apiHost:(n=e.apiHost)!=null?n:"https://uniform.app",apiKey:(o=e.apiKey)!=null?o:null,projectId:(i=e.projectId)!=null?i:null,bearerToken:(s=e.bearerToken)!=null?s:null,limitPolicy:(c=e.limitPolicy)!=null?c:b({})}}async getCompositionList(e){let{projectId:t}=this.options,n=this.createUrl("/api/v1/canvas",{...e,projectId:t});return await this.apiClient(n)}async getCompositionBySlug(e){let{projectId:t}=this.options,n=this.createUrl("/api/v1/canvas",{...e,projectId:t});return await this.apiClient(n)}async getCompositionById(e){let{projectId:t}=this.options,n=this.createUrl("/api/v1/canvas",{...e,projectId:t});return await this.apiClient(n)}async updateComposition(e){let t=this.createUrl("/api/v1/canvas");await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(e){let t=this.createUrl("/api/v1/canvas"),{projectId:n}=this.options;await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:n}),expectNoContent:!0})}async getComponentDefinitions(e){let{projectId:t}=this.options,n=this.createUrl("/api/v1/canvas-definitions",{...e,projectId:t});return await this.apiClient(n)}async updateComponentDefinition(e){let t=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(e){let t=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(e,t){return this.options.limitPolicy(async()=>{var i;let n=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`},o=await this.options.fetch(e.toString(),{...t,headers:{...t==null?void 0:t.headers,...n}});if(!o.ok){let 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 f(s,(i=t==null?void 0:t.method)!=null?i:"GET",e.toString(),o.status,o.statusText,E.getRequestId(o))}return t!=null&&t.expectNoContent?null:await o.json()})}createUrl(e,t){let n=new URL(`${this.options.apiHost}${e}`);return Object.entries(t!=null?t:{}).forEach(([o,i])=>{var s;typeof i!==void 0&&i!==null&&n.searchParams.append(o,(s=i==null?void 0:i.toString())!=null?s:"")}),n}static getRequestId(e){let t=e.headers.get("x-nf-request-id");if(t)return t}};var X="$personalization",ee="$test",R="$localization",te="intentTag",_="locale",ne="pz",oe="test",S="localized",Le=0,Ne=64,O="$pzCrit",L="$tstVrnt",re="$enr";var ie=r=>r.startsWith("$");function se(r){return r?r.map((e,t)=>{var i,s;let n=(s=(i=e.parameters)==null?void 0:i[O])==null?void 0:s.value,o=(n==null?void 0:n.name)||`pz-${t}-${e.type}`;return{...e,id:o,pz:n}}):[]}function ae(r){return r?r.map((e,t)=>{var i,s,c;let n=(s=(i=e.parameters)==null?void 0:i[L])==null?void 0:s.value,o=(c=n==null?void 0:n.id)!=null?c:"testId"in e?e.testId:`ab-${t}-${e.type}`;return{...e,id:o}}):[]}var k="https://js.pusher.com/7.0.3/pusher.min.js";async function ce(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((r,e)=>{let t=setTimeout(()=>{window.Pusher&&r(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${k}"><\/script> manually.`)},5e3),n=document.createElement("script");n.src=k,n.addEventListener("load",()=>{clearTimeout(t),r(window.Pusher)}),document.head.appendChild(n)})}async function pe(){let r=await ce();if(!r)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let t=new r("7b5f5abd160fea549ffe",{cluster:"mt1"});t.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:n=>{let o=t.subscribe(n);return{unsubscribe:()=>t.unsubscribe(n),addEventHandler:(i,s)=>(o.bind(i,s),()=>o.unbind(i,s))}}}}return e}function N(r,e,t){return`${r}.${e}@${t}`}function le({projectId:r,compositionId:e,compositionState:t=0,eventBus:{subscribe:n},callback:o,event:i="updated"}){let s=N(r,e,t),c=n(s),a=c.addEventHandler(i,o);return()=>{a(),c.unsubscribe()}}function $({component:r}){var n;let e={},t=(n=r.slots)==null?void 0:n[S];return t==null||t.forEach(o=>{var s;let i=(s=o.parameters)==null?void 0:s[_];(i==null?void 0:i.value)&&typeof i.value=="string"&&(e[i.value]=e[i.value]||[],e[i.value].push(o))}),e}function me({composition:r,locale:e}){C(r,(t,n,o)=>{if(t.type===R){let i=$({component:t}),s=typeof e=="string"?e:e({component:t,locales:i}),c;if(s&&(c=i[s]),c!=null&&c.length){let[a,...l]=c;o.replaceComponent(a),l.length&&o.insertAfter(l)}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-
|
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-25VHCM7A.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
package/dist/chunk-4MW5D2TW.mjs
DELETED
@@ -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};
|
package/dist/chunk-TCXTKDSU.mjs
DELETED
@@ -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};
|