@uniformdev/canvas 16.1.1-alpha.321 → 16.2.1-alpha.106
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-ADDR7SB6.mjs → chunk-LLGWMZOC.mjs} +2 -2
- package/dist/cli/cli.d.ts +1 -1
- package/dist/cli/cli.js +38 -38
- package/dist/cli/cli.mjs +36 -36
- package/dist/createEventBus-3af5b249.d.ts +957 -0
- package/dist/index.d.ts +176 -10
- package/dist/index.esm.js +1 -1
- package/dist/index.js +4 -4
- package/dist/index.mjs +1 -1
- package/package.json +10 -7
- package/dist/createEventBus-a6696d11.d.ts +0 -266
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { C as ComponentInstance, a as ComponentParameter, b as
|
2
|
-
export {
|
1
|
+
import { C as ComponentInstance, a as ComponentParameter, b as CompositionGetParameters, c as CompositionPutParameters, d as CompositionDeleteParameters, e as ComponentDefinitionGetParameters, f as ComponentDefinitionPutParameters, g as ComponentDefinitionDeleteParameters, P as PreviewEventBus } from './createEventBus-3af5b249.js';
|
2
|
+
export { z as ChannelSubscription, r as ComponentDefinition, k as ComponentDefinitionAPIDeleteRequest, j as ComponentDefinitionAPIPutRequest, i as ComponentDefinitionAPIResponse, g as ComponentDefinitionDeleteParameters, e as ComponentDefinitionGetParameters, h as ComponentDefinitionGetResponse, l as ComponentDefinitionListAPIOptions, m as ComponentDefinitionParameter, q as ComponentDefinitionPermission, f as ComponentDefinitionPutParameters, p as ComponentDefinitionSlot, o as ComponentDefinitionSlugSettings, n as ComponentDefinitionVariant, C as ComponentInstance, a as ComponentParameter, w as CompositionAPIDeleteRequest, y as CompositionAPIOptions, v as CompositionAPIResponse, d as CompositionDeleteParameters, u as CompositionGetListResponse, b as CompositionGetParameters, t as CompositionGetResponse, x as CompositionListAPIResponse, c as CompositionPutParameters, s as CreatingComponentDefinition, P as PreviewEventBus, R as RootComponentInstance, A as createEventBus } from './createEventBus-3af5b249.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';
|
@@ -277,21 +277,187 @@ declare class CanvasClient {
|
|
277
277
|
private options;
|
278
278
|
constructor(options: CanvasClientOptions);
|
279
279
|
/** Fetches lists of Canvas compositions, optionally by type */
|
280
|
-
getCompositionList(options?: Omit<
|
280
|
+
getCompositionList(options?: Omit<CompositionGetParameters, 'projectId'>): Promise<{
|
281
|
+
compositions: {
|
282
|
+
state: number;
|
283
|
+
projectId: string;
|
284
|
+
created: string;
|
285
|
+
modified: string;
|
286
|
+
pattern: boolean;
|
287
|
+
composition: {
|
288
|
+
type: string;
|
289
|
+
parameters?: {
|
290
|
+
[key: string]: {
|
291
|
+
value: unknown;
|
292
|
+
type: string;
|
293
|
+
};
|
294
|
+
} | undefined;
|
295
|
+
variant?: string | undefined;
|
296
|
+
slots?: {
|
297
|
+
[key: string]: {
|
298
|
+
type: string;
|
299
|
+
parameters?: {
|
300
|
+
[key: string]: {
|
301
|
+
value: unknown;
|
302
|
+
type: string;
|
303
|
+
};
|
304
|
+
} | undefined;
|
305
|
+
variant?: string | undefined;
|
306
|
+
slots?: {
|
307
|
+
[key: string]: any[];
|
308
|
+
} | undefined;
|
309
|
+
_pattern?: string | undefined;
|
310
|
+
_patternError?: "NOTFOUND" | "CYCLIC" | undefined;
|
311
|
+
}[];
|
312
|
+
} | undefined;
|
313
|
+
_id: string;
|
314
|
+
_slug?: string | null | undefined;
|
315
|
+
_name: string;
|
316
|
+
};
|
317
|
+
}[];
|
318
|
+
}>;
|
281
319
|
/** Fetches a Canvas composition by string name (slug) */
|
282
|
-
getCompositionBySlug(options: Pick<
|
320
|
+
getCompositionBySlug(options: Pick<CompositionGetParameters, 'slug' | 'state' | 'skipEnhance' | 'skipPatternResolution'>): Promise<{
|
321
|
+
state: number;
|
322
|
+
projectId: string;
|
323
|
+
created: string;
|
324
|
+
modified: string;
|
325
|
+
pattern: boolean;
|
326
|
+
composition: {
|
327
|
+
type: string;
|
328
|
+
parameters?: {
|
329
|
+
[key: string]: {
|
330
|
+
value: unknown;
|
331
|
+
type: string;
|
332
|
+
};
|
333
|
+
} | undefined;
|
334
|
+
variant?: string | undefined;
|
335
|
+
slots?: {
|
336
|
+
[key: string]: {
|
337
|
+
type: string;
|
338
|
+
parameters?: {
|
339
|
+
[key: string]: {
|
340
|
+
value: unknown;
|
341
|
+
type: string;
|
342
|
+
};
|
343
|
+
} | undefined;
|
344
|
+
variant?: string | undefined;
|
345
|
+
slots?: {
|
346
|
+
[key: string]: any[];
|
347
|
+
} | undefined;
|
348
|
+
_pattern?: string | undefined;
|
349
|
+
_patternError?: "NOTFOUND" | "CYCLIC" | undefined;
|
350
|
+
}[];
|
351
|
+
} | undefined;
|
352
|
+
_id: string;
|
353
|
+
_slug?: string | null | undefined;
|
354
|
+
_name: string;
|
355
|
+
};
|
356
|
+
}>;
|
283
357
|
/** Fetches a Canvas composition by its public UUID */
|
284
|
-
getCompositionById(options: Pick<
|
358
|
+
getCompositionById(options: Pick<CompositionGetParameters, 'compositionId' | 'state' | 'skipEnhance' | 'skipPatternResolution'>): Promise<{
|
359
|
+
state: number;
|
360
|
+
projectId: string;
|
361
|
+
created: string;
|
362
|
+
modified: string;
|
363
|
+
pattern: boolean;
|
364
|
+
composition: {
|
365
|
+
type: string;
|
366
|
+
parameters?: {
|
367
|
+
[key: string]: {
|
368
|
+
value: unknown;
|
369
|
+
type: string;
|
370
|
+
};
|
371
|
+
} | undefined;
|
372
|
+
variant?: string | undefined;
|
373
|
+
slots?: {
|
374
|
+
[key: string]: {
|
375
|
+
type: string;
|
376
|
+
parameters?: {
|
377
|
+
[key: string]: {
|
378
|
+
value: unknown;
|
379
|
+
type: string;
|
380
|
+
};
|
381
|
+
} | undefined;
|
382
|
+
variant?: string | undefined;
|
383
|
+
slots?: {
|
384
|
+
[key: string]: any[];
|
385
|
+
} | undefined;
|
386
|
+
_pattern?: string | undefined;
|
387
|
+
_patternError?: "NOTFOUND" | "CYCLIC" | undefined;
|
388
|
+
}[];
|
389
|
+
} | undefined;
|
390
|
+
_id: string;
|
391
|
+
_slug?: string | null | undefined;
|
392
|
+
_name: string;
|
393
|
+
};
|
394
|
+
}>;
|
285
395
|
/** Updates or creates a Canvas component definition */
|
286
|
-
updateComposition(body: Omit<
|
396
|
+
updateComposition(body: Omit<CompositionPutParameters, 'projectId'>): Promise<void>;
|
287
397
|
/** Deletes a Canvas component definition */
|
288
|
-
removeComposition(body: Omit<
|
398
|
+
removeComposition(body: Omit<CompositionDeleteParameters, 'projectId'>): Promise<void>;
|
289
399
|
/** Fetches all Canvas component definitions */
|
290
|
-
getComponentDefinitions(options?: Omit<
|
400
|
+
getComponentDefinitions(options?: Omit<ComponentDefinitionGetParameters, 'projectId'>): Promise<{
|
401
|
+
componentDefinitions: {
|
402
|
+
id: string;
|
403
|
+
name: string;
|
404
|
+
icon?: string | undefined;
|
405
|
+
titleParameter?: string | null | undefined;
|
406
|
+
canBeComposition?: boolean | undefined;
|
407
|
+
parameters?: {
|
408
|
+
id: string;
|
409
|
+
name: string;
|
410
|
+
helpText?: string | undefined;
|
411
|
+
type: string;
|
412
|
+
typeConfig?: unknown;
|
413
|
+
}[] | undefined;
|
414
|
+
useTeamPermissions?: boolean | undefined;
|
415
|
+
permissions?: {
|
416
|
+
roleId: string;
|
417
|
+
permission: "read" | "write" | "delete";
|
418
|
+
state: number;
|
419
|
+
}[] | undefined;
|
420
|
+
slots?: {
|
421
|
+
id: string;
|
422
|
+
name: string;
|
423
|
+
allowedComponents: string[];
|
424
|
+
inheritAllowedComponents: boolean;
|
425
|
+
minComponents?: number | undefined;
|
426
|
+
maxComponents?: number | undefined;
|
427
|
+
}[] | undefined;
|
428
|
+
slugSettings?: {
|
429
|
+
required?: "no" | "yes" | "disabled" | undefined;
|
430
|
+
unique?: "no" | "local" | "global" | undefined;
|
431
|
+
regularExpression?: string | undefined;
|
432
|
+
regularExpressionMessage?: string | undefined;
|
433
|
+
} | undefined;
|
434
|
+
defaults?: {
|
435
|
+
type: string;
|
436
|
+
parameters?: {
|
437
|
+
[key: string]: {
|
438
|
+
value: unknown;
|
439
|
+
type: string;
|
440
|
+
};
|
441
|
+
} | undefined;
|
442
|
+
variant?: string | undefined;
|
443
|
+
slots?: {
|
444
|
+
[key: string]: any[];
|
445
|
+
} | undefined;
|
446
|
+
_pattern?: string | undefined;
|
447
|
+
_patternError?: "NOTFOUND" | "CYCLIC" | undefined;
|
448
|
+
} | null | undefined;
|
449
|
+
variants?: {
|
450
|
+
id: string;
|
451
|
+
name: string;
|
452
|
+
}[] | undefined;
|
453
|
+
created?: string | undefined;
|
454
|
+
updated?: string | undefined;
|
455
|
+
}[];
|
456
|
+
}>;
|
291
457
|
/** Updates or creates a Canvas component definition */
|
292
|
-
updateComponentDefinition(body: Omit<
|
458
|
+
updateComponentDefinition(body: Omit<ComponentDefinitionPutParameters, 'projectId'>): Promise<void>;
|
293
459
|
/** Deletes a Canvas component definition */
|
294
|
-
removeComponentDefinition(body: Omit<
|
460
|
+
removeComponentDefinition(body: Omit<ComponentDefinitionDeleteParameters, 'projectId'>): Promise<void>;
|
295
461
|
private apiClient;
|
296
462
|
private createUrl;
|
297
463
|
private static getRequestId;
|
package/dist/index.esm.js
CHANGED
@@ -1,4 +1,4 @@
|
|
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-
|
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-LLGWMZOC.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
|
-
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
|
2
|
-
${typeof
|
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 G=(r,e)=>{for(var t in e)C(r,t,{get:e[t],enumerable:!0})},L=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of U(e))!D.call(r,o)&&o!==t&&C(r,o,{get:()=>e[o],enumerable:!(n=M(e,o))||n.enumerable});return r};var N=(r,e,t)=>(t=r!=null?B(F(r)):{},L(e||!r||!r.__esModule?C(t,"default",{value:r,enumerable:!0}):t,r)),z=r=>L(C({},"__esModule",{value:!0}),r);var me={};G(me,{BatchEntry:()=>E,CANVAS_DRAFT_STATE:()=>_e,CANVAS_ENRICHMENT_TAG_PARAM:()=>ne,CANVAS_INTENT_TAG_PARAM:()=>X,CANVAS_LOCALE_TAG_PARAM:()=>I,CANVAS_LOCALIZATION_SLOT:()=>w,CANVAS_LOCALIZATION_TYPE:()=>x,CANVAS_PERSONALIZATION_PARAM:()=>_,CANVAS_PERSONALIZE_SLOT:()=>ee,CANVAS_PERSONALIZE_TYPE:()=>Q,CANVAS_PUBLISHED_STATE:()=>Re,CANVAS_TEST_SLOT:()=>te,CANVAS_TEST_TYPE:()=>q,CANVAS_TEST_VARIANT_PARAM:()=>R,CanvasClient:()=>y,CanvasClientError:()=>u,ChildEnhancerBuilder:()=>f,EnhancerBuilder:()=>T,UniqueBatchEntries:()=>g,compose:()=>J,createBatchEnhancer:()=>H,createEventBus:()=>se,createLimitPolicy:()=>v,enhance:()=>K,extractLocales:()=>k,getChannelName:()=>b,getComponentPath:()=>P,isSystemComponentDefinition:()=>oe,localize:()=>pe,mapSlotToPersonalizedVariations:()=>re,mapSlotToTestVariations:()=>ae,nullLimitPolicy:()=>l,subscribeToComposition:()=>ce,walkComponentTree:()=>d});module.exports=z(me);function d(r,e){let t=[{ancestorsAndSelf:[{component:r,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let n=t.pop();if(!n)continue;let o=n.ancestorsAndSelf[0];e(o.component,n.ancestorsAndSelf,{replaceComponent:i=>{Object.assign(o.component,i),["parameters","variant","slots","data","_pattern","_patternError"].forEach(s=>{i[s]||delete o.component[s]})},removeComponent:()=>{let{parentSlot:i,parentSlotIndex:c}=n.ancestorsAndSelf[0],s=n.ancestorsAndSelf[1];if(i&&typeof c!="undefined")s.component.slots[i].splice(c,1);else throw new Error("Unable to delete composition.")},insertAfter:i=>{let c=Array.isArray(i)?i:[i],{parentSlot:s,parentSlotIndex:p}=n.ancestorsAndSelf[0],m=n.ancestorsAndSelf[1];if(s&&typeof p!="undefined")m.component.slots[s].splice(p+1,0,...c);else throw new Error("Unable to insert after a component not in a slot.")}});let a=o.component.slots;if(a){let i=Object.keys(a);for(let c=i.length-1;c>=0;c--){let s=i[c],p=a[s];for(let m=p.length-1;m>=0;m--)t.push({ancestorsAndSelf:[{component:p[m],parentSlot:s,parentSlotIndex:m},...n.ancestorsAndSelf]})}}}while(t.length>0)}function P(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 g=class{constructor(e,t){this.groups=e.reduce((n,o)=>{var i;let a=t(o.args);return n[a]=(i=n[a])!=null?i:[],n[a].push(o),n},{})}resolveKey(e,t){this.groups[e].forEach(n=>n.resolve(t))}resolveRemaining(e){Object.keys(this.groups).forEach(t=>{this.groups[t].forEach(n=>{n.isCompleted||n.resolve(e)})})}};var f=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}},T=class{constructor(){this._componentIndex={};this._rootBuilder=new f}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 f,t(this._componentIndex[o])}),this}resolveParameterEnhancer(e,t,n){let o=this._componentIndex[e.type];if(o){let a=o.resolveParameterEnhancer(t,n);if(a)return a}return this._rootBuilder.resolveParameterEnhancer(t,n)}resolveComponentEnhancers(e){let t=this._rootBuilder.resolveComponentEnhancers(),n=this._componentIndex[e.type];if(n){t=new Map(t);for(let[o,a]of n.resolveComponentEnhancers())t.set(o,a)}return t}};var E=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 H({handleBatch:r,shouldQueue:e,limitPolicy:t}){let n=[];return{enhanceOne:async i=>{if(!e||e(i))return new Promise((c,s)=>{n.push(new E(c,s,i))})},completeAll:async()=>{if(n.length>0){try{await r(n)}catch(c){n.forEach(s=>s.reject(c))}if(n.some(c=>!c.isCompleted))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!")}let i=n.length;return n=[],i},limitPolicy:t}}var j=N(require("p-throttle")),V=N(require("p-retry"));function v({throttle:r={interval:1e3,limit:10},retry:e={retries:1,factor:1.66}}){let t=r?(0,j.default)(r):null;return function(o){let a=async()=>await o();if(t&&(a=t(a)),e){let i=a;a=()=>(0,V.default)(i,e)}return a()}}var l=async r=>await r();async function K({composition:r,enhancers:e,context:t,onErrors:n=o=>{throw new Error(o.map(a=>`${a.message}
|
2
|
+
${typeof a.error=="object"&&"stack"in a.error?a.error.stack:a.error}`).join(`
|
3
3
|
|
4
|
-
`))}}){let o=[],
|
5
|
-
${
|
4
|
+
`))}}){let o=[],a=new Set,i=new Set;d(r,(s,p)=>{var h;Object.entries((h=s.parameters)!=null?h:{}).forEach(([S,O])=>{let A=e.resolveParameterEnhancer(s,S,O);A&&(i.add(A),o.push(Y(s,p,S,O,A,t)))});let m=e.resolveComponentEnhancers(s);o.push(Z(s,p,m,t)),a.add(m)}),o.push(...Array.from(a).flatMap(s=>Array.from(s).map(async([,p])=>{var m;try{p.completeAll&&await((m=p.limitPolicy)!=null?m:l)(()=>p.completeAll())}catch(h){return{error:h,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),o.push(...Array.from(i).map(async s=>{var p;try{s.completeAll&&await((p=s.limitPolicy)!=null?p:l)(()=>s.completeAll())}catch(m){return{error:m,message:"Batch parameter enhancer failed. Individual failed parameters should receive their own rejections."}}}));let c=(await Promise.all(o)).flatMap(s=>Array.isArray(s)?s:[s]).filter(s=>s);c.length&&n(c)}async function Z(r,e,t,n){return t.size&&(r.data={}),await Promise.all(Array.from(t).map(async([o,a])=>{var i;try{let s=await(a.completeAll?l:(i=a.limitPolicy)!=null?i:l)(async()=>a.enhanceOne({component:r,context:n}));s!=null&&(r.data[o]=s)}catch(c){let s=`Component ${P(e)} (type: ${r.type}): data.${o} enhancer threw exception. Data key will not be present.`;return delete r.data[o],{message:s,error:c}}}))}async function Y(r,e,t,n,o,a){var i;try{let s=await(o.completeAll?l:(i=o.limitPolicy)!=null?i:l)(async()=>o.enhanceOne({parameter:n,parameterName:t,component:r,context:a}));s===null?delete r.parameters[t]:typeof s=="undefined"?r.parameters[t]={...n,value:n.value}:r.parameters[t]={...n,value:s}}catch(c){let s=`Component ${P(e)} (type: ${r.type}): enhancing parameter ${t} (type: ${n.type}) threw exception. Parameter will be removed.`;return delete r.parameters[t],{message:s,error:c}}}var J=(r,...e)=>({enhanceOne:n=>{let o="enhanceOne"in r?r.enhanceOne(n):r(n);for(let a of e){let i=W(o)?o:Promise.resolve(o),c="enhanceOne"in a?a.enhanceOne:a;o=i.then(s=>c({...n,parameter:{type:n.parameter.type,value:s}}))}return o},completeAll:async()=>{var n,o;for(let a of e)if("completeAll"in a)throw new Error("Only the first enhancer in a compose chain can use the completeAll function (batching)");return(o="completeAll"in r?(n=r.completeAll)==null?void 0:n.call(r):0)!=null?o:0}});function W(r){return!!r&&(typeof r=="object"||typeof r=="function")&&typeof r.then=="function"}var u=class extends Error{constructor(t,n,o,a,i,c){super(`${t}
|
5
|
+
${a}${i?" "+i:""} (${n} ${o}${c?` Request ID: ${c}`:""})`);this.errorMessage=t;this.fetchMethod=n;this.fetchUri=o;this.statusCode=a;this.statusText=i;this.requestId=c;Object.setPrototypeOf(this,u.prototype)}},y=class{constructor(e){var n,o,a,i,c;if(!e.apiKey&&!e.bearerToken)throw new Error("You must provide an API key or a bearer token");let t=e.fetch;if(!t)if(typeof window!="undefined")t=window.fetch.bind(window);else if(typeof fetch!="undefined")t=fetch;else throw new Error("You must provide or polyfill a fetch implementation when not in a browser");this.options={...e,fetch:t,apiHost:(n=e.apiHost)!=null?n:"https://uniform.app",apiKey:(o=e.apiKey)!=null?o:null,projectId:(a=e.projectId)!=null?a:null,bearerToken:(i=e.bearerToken)!=null?i:null,limitPolicy:(c=e.limitPolicy)!=null?c:v({})}}async getCompositionList(e){let{projectId:t}=this.options,n=this.createUrl("/api/v1/canvas",{...e,projectId:t});return await this.apiClient(n)}async getCompositionBySlug(e){let{projectId:t}=this.options,n=this.createUrl("/api/v1/canvas",{...e,projectId:t});return await this.apiClient(n)}async getCompositionById(e){let{projectId:t}=this.options,n=this.createUrl("/api/v1/canvas",{...e,projectId:t});return await this.apiClient(n)}async updateComposition(e){let t=this.createUrl("/api/v1/canvas");await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(e){let t=this.createUrl("/api/v1/canvas");await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async getComponentDefinitions(e){let{projectId:t}=this.options,n=this.createUrl("/api/v1/canvas-definitions",{...e,projectId:t});return await this.apiClient(n)}async updateComponentDefinition(e){let t=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(e){let t=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(e,t){return this.options.limitPolicy(async()=>{var a;let n=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`},o=await this.options.fetch(e.toString(),{...t,headers:{...t==null?void 0:t.headers,...n}});if(!o.ok){let i="";try{let c=await o.text();try{let s=JSON.parse(c);s.errorMessage?i=Array.isArray(s.errorMessage)?s.errorMessage.join(", "):s.errorMessage:i=c}catch(s){i=c}}catch(c){i="General error"}throw new u(i,(a=t==null?void 0:t.method)!=null?a:"GET",e.toString(),o.status,o.statusText,y.getRequestId(o))}return t!=null&&t.expectNoContent?null:await o.json()})}createUrl(e,t){let n=new URL(`${this.options.apiHost}${e}`);return Object.entries(t!=null?t:{}).forEach(([o,a])=>{var i;typeof a!==void 0&&a!==null&&n.searchParams.append(o,(i=a==null?void 0:a.toString())!=null?i:"")}),n}static getRequestId(e){let t=e.headers.get("x-nf-request-id");if(t)return t}};var Q="$personalization",q="$test",x="$localization",X="intentTag",I="locale",ee="pz",te="test",w="localized",_e=0,Re=64,_="$pzCrit",R="$tstVrnt",ne="$enr";var oe=r=>r.startsWith("$");function re(r){return r?r.map((e,t)=>{var a,i;let n=(i=(a=e.parameters)==null?void 0:a[_])==null?void 0:i.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 a,i,c;let n=(i=(a=e.parameters)==null?void 0:a[R])==null?void 0:i.value,o=(c=n==null?void 0:n.id)!=null?c:"testId"in e?e.testId:`ab-${t}-${e.type}`;return{...e,id:o}}):[]}var $="https://js.pusher.com/7.0.3/pusher.min.js";async function ie(){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="${$}"><\/script> manually.`)},5e3),n=document.createElement("script");n.src=$,n.addEventListener("load",()=>{clearTimeout(t),r(window.Pusher)}),document.head.appendChild(n)})}async function se(){let r=await ie();if(!r)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let t=new r("7b5f5abd160fea549ffe",{cluster:"mt1"});t.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:n=>{let o=t.subscribe(n);return{unsubscribe:()=>t.unsubscribe(n),addEventHandler:(a,i)=>(o.bind(a,i),()=>o.unbind(a,i))}}}}return e}function b(r,e,t){return`${r}.${e}@${t}`}function ce({projectId:r,compositionId:e,compositionState:t=0,eventBus:{subscribe:n},callback:o,event:a="updated"}){let i=b(r,e,t),c=n(i),s=c.addEventHandler(a,o);return()=>{s(),c.unsubscribe()}}function k({component:r}){var n;let e={},t=(n=r.slots)==null?void 0:n[w];return t==null||t.forEach(o=>{var i;let a=(i=o.parameters)==null?void 0:i[I];(a==null?void 0:a.value)&&typeof a.value=="string"&&(e[a.value]=e[a.value]||[],e[a.value].push(o))}),e}function pe({composition:r,locale:e}){d(r,(t,n,o)=>{if(t.type===x){let a=k({component:t}),i=typeof e=="string"?e:e({component:t,locales:a}),c;if(i&&(c=a[i]),c!=null&&c.length){let[s,...p]=c;o.replaceComponent(s),p.length&&o.insertAfter(p)}else o.removeComponent()}})}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
|
-
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
|
+
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-LLGWMZOC.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.
|
3
|
+
"version": "16.2.1-alpha.106+a3eb5a014",
|
4
4
|
"description": "Common functionality and types for Uniform Canvas",
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
6
6
|
"main": "./dist/index.js",
|
@@ -36,22 +36,25 @@
|
|
36
36
|
},
|
37
37
|
"sideEffects": false,
|
38
38
|
"scripts": {
|
39
|
-
"build": "
|
40
|
-
"
|
39
|
+
"build": "run-s update-openapi build:ts",
|
40
|
+
"build:ts": "tsup --minify",
|
41
|
+
"dev": "run-s update-openapi dev:ts",
|
42
|
+
"dev:ts": "tsup --watch",
|
41
43
|
"clean": "rimraf dist",
|
42
44
|
"test": "jest --maxWorkers=1",
|
43
45
|
"lint": "eslint \"src/**/*.{js,ts,tsx}\"",
|
44
|
-
"format": "prettier --write \"src/**/*.{js,ts,tsx}\""
|
46
|
+
"format": "prettier --write \"src/**/*.{js,ts,tsx}\"",
|
47
|
+
"update-openapi": "tsx ./scripts/update-openapi.cts"
|
45
48
|
},
|
46
49
|
"devDependencies": {
|
47
50
|
"@types/retry": "0.12.1",
|
48
51
|
"@types/yargs": "17.0.10",
|
49
|
-
"@uniformdev/cli": "^16.
|
52
|
+
"@uniformdev/cli": "^16.2.1-alpha.106+a3eb5a014",
|
50
53
|
"pusher-js": "7.0.6",
|
51
54
|
"yargs": "17.5.1"
|
52
55
|
},
|
53
56
|
"dependencies": {
|
54
|
-
"@uniformdev/context": "^16.
|
57
|
+
"@uniformdev/context": "^16.2.1-alpha.106+a3eb5a014",
|
55
58
|
"isomorphic-unfetch": "^3.1.0",
|
56
59
|
"p-limit": "^3.1.0",
|
57
60
|
"p-retry": "^4.6.2",
|
@@ -63,5 +66,5 @@
|
|
63
66
|
"publishConfig": {
|
64
67
|
"access": "public"
|
65
68
|
},
|
66
|
-
"gitHead": "
|
69
|
+
"gitHead": "a3eb5a01423196eee3cb0fbb2a4e9372b420f160"
|
67
70
|
}
|