@uniformdev/canvas 16.2.3 → 17.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as ComponentInstance, a as ComponentParameter, b as CompositionAPIOptions, c as CompositionListAPIResponse, d as CompositionAPIResponse, e as CompositionAPIDeleteRequest, f as ComponentDefinitionListAPIOptions, g as ComponentDefinitionAPIResponse, h as ComponentDefinitionAPIPutRequest, i as ComponentDefinitionAPIDeleteRequest, P as PreviewEventBus } from './createEventBus-f5cdcc4e.js';
2
- export { r as ChannelSubscription, o as ComponentDefinition, i as ComponentDefinitionAPIDeleteRequest, h as ComponentDefinitionAPIPutRequest, g as ComponentDefinitionAPIResponse, f as ComponentDefinitionListAPIOptions, j as ComponentDefinitionParameter, n as ComponentDefinitionPermission, m as ComponentDefinitionSlot, l as ComponentDefinitionSlugSettings, k as ComponentDefinitionVariant, C as ComponentInstance, a as ComponentParameter, e as CompositionAPIDeleteRequest, b as CompositionAPIOptions, d as CompositionAPIResponse, q as CompositionFetchState, c as CompositionListAPIResponse, p as CreatingComponentDefinition, P as PreviewEventBus, R as RootComponentInstance, s as createEventBus } from './createEventBus-f5cdcc4e.js';
1
+ import { C as ComponentInstance, a as ComponentParameter, b as CompositionGetParameters, c as CompositionPutParameters, d as CompositionDeleteParameters, e as ComponentDefinitionGetParameters, f as ComponentDefinitionPutParameters, g as ComponentDefinitionDeleteParameters, P as PreviewEventBus } from './createEventBus-c46c67da.js';
2
+ export { F as CanvasDefinitions, G 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, z as ComponentParameterBinding, 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, E as CompositionResourceDefinition, D as CompositionResourceDefinitions, B as CompositionVariable, A as CompositionVariableDefinitions, s as CreatingComponentDefinition, P as PreviewEventBus, R as RootComponentInstance, H as createEventBus } from './createEventBus-c46c67da.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';
@@ -89,9 +89,14 @@ declare type ComponentLocationReference = {
89
89
  parentSlotIndex?: number;
90
90
  };
91
91
  declare type WalkComponentTreeActions = {
92
+ /** Replaces the component being visited with a new object */
92
93
  replaceComponent: (replacementComponent: ComponentInstance) => void;
94
+ /** Removes the component being visited from the composition */
93
95
  removeComponent: () => void;
96
+ /** Inserts a new component immediately after the current component in its parent slot */
94
97
  insertAfter: (components: ComponentInstance | ComponentInstance[]) => void;
98
+ /** Aborts visitation of components that are in child slots of the current component */
99
+ stopProcessingDescendants: () => void;
95
100
  };
96
101
  /** Walks a composition's component tree, visiting each component instance depth-first, in order. */
97
102
  declare function walkComponentTree(component: ComponentInstance, visitor: (component: ComponentInstance, ancestorsAndSelf: Array<ComponentLocationReference>, actions: WalkComponentTreeActions) => void): void;
@@ -263,6 +268,10 @@ declare type CanvasClientOptions = {
263
268
  * Default: retry 3x on failures with exponential backoff, up to 10 requests per second.
264
269
  * Use createLimitPolicy() to help creating a policy. */
265
270
  limitPolicy?: LimitPolicy;
271
+ /** Specify whether CDN caching is disabled. */
272
+ bypassCache?: boolean;
273
+ /** @deprecated do not use */
274
+ experiment14?: boolean;
266
275
  };
267
276
  declare class CanvasClientError extends Error {
268
277
  errorMessage: string;
@@ -276,26 +285,291 @@ declare class CanvasClientError extends Error {
276
285
  declare class CanvasClient {
277
286
  private options;
278
287
  constructor(options: CanvasClientOptions);
288
+ private get canvasUrl();
279
289
  /** Fetches lists of Canvas compositions, optionally by type */
280
- getCompositionList(options?: Omit<CompositionAPIOptions, 'projectId'>): Promise<CompositionListAPIResponse>;
290
+ getCompositionList(options?: Omit<CompositionGetParameters, 'projectId'>): Promise<{
291
+ compositions: {
292
+ state: number;
293
+ projectId: string;
294
+ created: string;
295
+ modified: string;
296
+ pattern: boolean;
297
+ resources?: {
298
+ [key: string]: {
299
+ type: string;
300
+ data: {
301
+ [key: string]: unknown;
302
+ };
303
+ };
304
+ } | undefined;
305
+ composition: {
306
+ type: string;
307
+ parameters?: {
308
+ [key: string]: {
309
+ value: unknown;
310
+ type: string;
311
+ binding?: {
312
+ pointer: string | {
313
+ [key: string]: string;
314
+ };
315
+ syntax: "jptr";
316
+ required?: boolean | undefined;
317
+ } | undefined;
318
+ };
319
+ } | undefined;
320
+ variant?: string | undefined;
321
+ slots?: {
322
+ [key: string]: {
323
+ type: string;
324
+ parameters?: {
325
+ [key: string]: {
326
+ value: unknown;
327
+ type: string;
328
+ binding?: {
329
+ pointer: string | {
330
+ [key: string]: string;
331
+ };
332
+ syntax: "jptr";
333
+ required?: boolean | undefined;
334
+ } | undefined;
335
+ };
336
+ } | undefined;
337
+ variant?: string | undefined;
338
+ slots?: {
339
+ [key: string]: any[];
340
+ } | undefined;
341
+ _id?: string | undefined;
342
+ _pattern?: string | undefined;
343
+ _patternError?: "NOTFOUND" | "CYCLIC" | undefined;
344
+ }[];
345
+ } | undefined;
346
+ _id: string;
347
+ _slug?: string | null | undefined;
348
+ _name: string;
349
+ };
350
+ variables?: {
351
+ [key: string]: {
352
+ required: boolean;
353
+ default: string;
354
+ };
355
+ } | undefined;
356
+ }[];
357
+ }>;
281
358
  /** Fetches a Canvas composition by string name (slug) */
282
- getCompositionBySlug(options: Pick<CompositionAPIOptions, 'slug' | 'state' | 'skipEnhance' | 'skipPatternResolution'>): Promise<CompositionAPIResponse>;
359
+ getCompositionBySlug(options: Pick<CompositionGetParameters, 'slug' | 'state' | 'skipEnhance' | 'skipPatternResolution' | 'withComponentIDs'>): Promise<{
360
+ state: number;
361
+ projectId: string;
362
+ created: string;
363
+ modified: string;
364
+ pattern: boolean;
365
+ resources?: {
366
+ [key: string]: {
367
+ type: string;
368
+ data: {
369
+ [key: string]: unknown;
370
+ };
371
+ };
372
+ } | undefined;
373
+ composition: {
374
+ type: string;
375
+ parameters?: {
376
+ [key: string]: {
377
+ value: unknown;
378
+ type: string;
379
+ binding?: {
380
+ pointer: string | {
381
+ [key: string]: string;
382
+ };
383
+ syntax: "jptr";
384
+ required?: boolean | undefined;
385
+ } | undefined;
386
+ };
387
+ } | undefined;
388
+ variant?: string | undefined;
389
+ slots?: {
390
+ [key: string]: {
391
+ type: string;
392
+ parameters?: {
393
+ [key: string]: {
394
+ value: unknown;
395
+ type: string;
396
+ binding?: {
397
+ pointer: string | {
398
+ [key: string]: string;
399
+ };
400
+ syntax: "jptr";
401
+ required?: boolean | undefined;
402
+ } | undefined;
403
+ };
404
+ } | undefined;
405
+ variant?: string | undefined;
406
+ slots?: {
407
+ [key: string]: any[];
408
+ } | undefined;
409
+ _id?: string | undefined;
410
+ _pattern?: string | undefined;
411
+ _patternError?: "NOTFOUND" | "CYCLIC" | undefined;
412
+ }[];
413
+ } | undefined;
414
+ _id: string;
415
+ _slug?: string | null | undefined;
416
+ _name: string;
417
+ };
418
+ variables?: {
419
+ [key: string]: {
420
+ required: boolean;
421
+ default: string;
422
+ };
423
+ } | undefined;
424
+ }>;
283
425
  /** Fetches a Canvas composition by its public UUID */
284
- getCompositionById(options: Pick<CompositionAPIOptions, 'compositionId' | 'state' | 'skipEnhance' | 'skipPatternResolution'>): Promise<CompositionAPIResponse>;
426
+ getCompositionById(options: Pick<CompositionGetParameters, 'compositionId' | 'state' | 'skipEnhance' | 'skipPatternResolution' | 'withComponentIDs'>): Promise<{
427
+ state: number;
428
+ projectId: string;
429
+ created: string;
430
+ modified: string;
431
+ pattern: boolean;
432
+ resources?: {
433
+ [key: string]: {
434
+ type: string;
435
+ data: {
436
+ [key: string]: unknown;
437
+ };
438
+ };
439
+ } | undefined;
440
+ composition: {
441
+ type: string;
442
+ parameters?: {
443
+ [key: string]: {
444
+ value: unknown;
445
+ type: string;
446
+ binding?: {
447
+ pointer: string | {
448
+ [key: string]: string;
449
+ };
450
+ syntax: "jptr";
451
+ required?: boolean | undefined;
452
+ } | undefined;
453
+ };
454
+ } | undefined;
455
+ variant?: string | undefined;
456
+ slots?: {
457
+ [key: string]: {
458
+ type: string;
459
+ parameters?: {
460
+ [key: string]: {
461
+ value: unknown;
462
+ type: string;
463
+ binding?: {
464
+ pointer: string | {
465
+ [key: string]: string;
466
+ };
467
+ syntax: "jptr";
468
+ required?: boolean | undefined;
469
+ } | undefined;
470
+ };
471
+ } | undefined;
472
+ variant?: string | undefined;
473
+ slots?: {
474
+ [key: string]: any[];
475
+ } | undefined;
476
+ _id?: string | undefined;
477
+ _pattern?: string | undefined;
478
+ _patternError?: "NOTFOUND" | "CYCLIC" | undefined;
479
+ }[];
480
+ } | undefined;
481
+ _id: string;
482
+ _slug?: string | null | undefined;
483
+ _name: string;
484
+ };
485
+ variables?: {
486
+ [key: string]: {
487
+ required: boolean;
488
+ default: string;
489
+ };
490
+ } | undefined;
491
+ }>;
285
492
  /** Updates or creates a Canvas component definition */
286
- updateComposition(body: Omit<CompositionAPIResponse, 'projectId'>): Promise<void>;
493
+ updateComposition(body: Omit<CompositionPutParameters, 'projectId'>): Promise<void>;
287
494
  /** Deletes a Canvas component definition */
288
- removeComposition(body: Omit<CompositionAPIDeleteRequest, 'projectId'>): Promise<void>;
495
+ removeComposition(body: Omit<CompositionDeleteParameters, 'projectId'>): Promise<void>;
289
496
  /** Fetches all Canvas component definitions */
290
- getComponentDefinitions(options?: Omit<ComponentDefinitionListAPIOptions, 'projectId'>): Promise<ComponentDefinitionAPIResponse>;
497
+ getComponentDefinitions(options?: Omit<ComponentDefinitionGetParameters, 'projectId'>): Promise<{
498
+ componentDefinitions: {
499
+ id: string;
500
+ name: string;
501
+ icon?: string | undefined;
502
+ titleParameter?: string | null | undefined;
503
+ canBeComposition?: boolean | undefined;
504
+ parameters?: {
505
+ id: string;
506
+ name: string;
507
+ helpText?: string | undefined;
508
+ type: string;
509
+ typeConfig?: unknown;
510
+ }[] | undefined;
511
+ useTeamPermissions?: boolean | undefined;
512
+ permissions?: {
513
+ roleId: string;
514
+ permission: "read" | "write" | "delete";
515
+ state: number;
516
+ }[] | undefined;
517
+ slots?: {
518
+ id: string;
519
+ name: string;
520
+ allowedComponents: string[];
521
+ inheritAllowedComponents: boolean;
522
+ minComponents?: number | undefined;
523
+ maxComponents?: number | undefined;
524
+ }[] | undefined;
525
+ slugSettings?: {
526
+ required?: "no" | "yes" | "disabled" | undefined;
527
+ unique?: "no" | "local" | "global" | undefined;
528
+ regularExpression?: string | undefined;
529
+ regularExpressionMessage?: string | undefined;
530
+ } | undefined;
531
+ defaults?: {
532
+ type: string;
533
+ parameters?: {
534
+ [key: string]: {
535
+ value: unknown;
536
+ type: string;
537
+ binding?: {
538
+ pointer: string | {
539
+ [key: string]: string;
540
+ };
541
+ syntax: "jptr";
542
+ required?: boolean | undefined;
543
+ } | undefined;
544
+ };
545
+ } | undefined;
546
+ variant?: string | undefined;
547
+ slots?: {
548
+ [key: string]: any[];
549
+ } | undefined;
550
+ _id?: string | undefined;
551
+ _pattern?: string | undefined;
552
+ _patternError?: "NOTFOUND" | "CYCLIC" | undefined;
553
+ } | null | undefined;
554
+ variants?: {
555
+ id: string;
556
+ name: string;
557
+ }[] | undefined;
558
+ created?: string | undefined;
559
+ updated?: string | undefined;
560
+ }[];
561
+ }>;
291
562
  /** Updates or creates a Canvas component definition */
292
- updateComponentDefinition(body: Omit<ComponentDefinitionAPIPutRequest, 'projectId'>): Promise<void>;
563
+ updateComponentDefinition(body: Omit<ComponentDefinitionPutParameters, 'projectId'>): Promise<void>;
293
564
  /** Deletes a Canvas component definition */
294
- removeComponentDefinition(body: Omit<ComponentDefinitionAPIDeleteRequest, 'projectId'>): Promise<void>;
565
+ removeComponentDefinition(body: Omit<ComponentDefinitionDeleteParameters, 'projectId'>): Promise<void>;
295
566
  private apiClient;
296
567
  private createUrl;
297
568
  private static getRequestId;
298
569
  }
570
+ declare class UncachedCanvasClient extends CanvasClient {
571
+ constructor(options: Omit<CanvasClientOptions, 'bypassCache'>);
572
+ }
299
573
 
300
574
  /** Public ID of Canvas personalization component type */
301
575
  declare const CANVAS_PERSONALIZE_TYPE = "$personalization";
@@ -366,4 +640,4 @@ declare function localize({ composition, locale, }: {
366
640
  }) => string | undefined);
367
641
  }): void;
368
642
 
369
- export { BatchEnhancer, 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, CanvasClientOptions, ChildEnhancerBuilder, ComponentEnhancer, ComponentEnhancerFunction, ComponentEnhancerOptions, ComponentLocationReference, ComponentParameterEnhancer, ComponentParameterEnhancerFunction, ComponentParameterEnhancerOptions, EnhancerBuilder, EnhancerContext, EnhancerError, EventNames, LimitPolicy, SubscribeToCompositionOptions, UniqueBatchEntries, UnsubscribeCallback, compose, createBatchEnhancer, createLimitPolicy, enhance, extractLocales, getChannelName, getComponentPath, isSystemComponentDefinition, localize, mapSlotToPersonalizedVariations, mapSlotToTestVariations, nullLimitPolicy, subscribeToComposition, walkComponentTree };
643
+ export { BatchEnhancer, 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, CanvasClientOptions, ChildEnhancerBuilder, ComponentEnhancer, ComponentEnhancerFunction, ComponentEnhancerOptions, ComponentLocationReference, ComponentParameterEnhancer, ComponentParameterEnhancerFunction, ComponentParameterEnhancerOptions, EnhancerBuilder, EnhancerContext, EnhancerError, EventNames, LimitPolicy, SubscribeToCompositionOptions, UncachedCanvasClient, UniqueBatchEntries, UnsubscribeCallback, WalkComponentTreeActions, compose, createBatchEnhancer, createLimitPolicy, enhance, extractLocales, getChannelName, getComponentPath, isSystemComponentDefinition, localize, mapSlotToPersonalizedVariations, mapSlotToTestVariations, nullLimitPolicy, subscribeToComposition, walkComponentTree };
package/dist/index.esm.js CHANGED
@@ -1,4 +1 @@
1
- "use strict";import{d as L,e as l,f as $,g as j,h as k,i as F,j as A,k as V,l as g,m as N,n as U,o as v,p as z,q as W,r as x,s as w,t as H}from"./chunk-HJHWEOMG.mjs";function u(o,e){let t=[{ancestorsAndSelf:[{component:o,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let n=t.pop();if(!n)continue;let r=n.ancestorsAndSelf[0];e(r.component,n.ancestorsAndSelf,{replaceComponent:i=>{Object.assign(r.component,i),["parameters","variant","slots","data","_pattern","_patternError"].forEach(s=>{i[s]||delete r.component[s]})},removeComponent:()=>{let{parentSlot:i,parentSlotIndex:c}=n.ancestorsAndSelf[0],s=n.ancestorsAndSelf[1];if(i&&typeof c!="undefined")s.component.slots[i].splice(c,1);else throw new Error("Unable to delete composition.")},insertAfter:i=>{let c=Array.isArray(i)?i:[i],{parentSlot:s,parentSlotIndex:p}=n.ancestorsAndSelf[0],m=n.ancestorsAndSelf[1];if(s&&typeof p!="undefined")m.component.slots[s].splice(p+1,0,...c);else throw new Error("Unable to insert after a component not in a slot.")}});let a=r.component.slots;if(a){let i=Object.keys(a);for(let c=i.length-1;c>=0;c--){let s=i[c],p=a[s];for(let m=p.length-1;m>=0;m--)t.push({ancestorsAndSelf:[{component:p[m],parentSlot:s,parentSlotIndex:m},...n.ancestorsAndSelf]})}}}while(t.length>0)}function y(o){let e=[];for(let t=o.length-1;t>=0;t--){let{parentSlot:n,parentSlotIndex:r}=o[t];n&&r!==void 0&&e.push(`${n}[${r}]`)}return`.${e.join(".")}`}var T=class{constructor(e,t){this.groups=e.reduce((n,r)=>{var i;let a=t(r.args);return n[a]=(i=n[a])!=null?i:[],n[a].push(r),n},{})}resolveKey(e,t){this.groups[e].forEach(n=>n.resolve(t))}resolveRemaining(e){Object.keys(this.groups).forEach(t=>{this.groups[t].forEach(n=>{n.isCompleted||n.resolve(e)})})}};var d=class{constructor(){this._paramMatches=Array();this._dataMatches=new Map}parameter(e){return this._paramMatches.push({enhancer:this._resolveParameterEnhancer(e)}),this}parameterName(e,t){return(Array.isArray(e)?e:[e]).forEach(r=>this._paramMatches.push({name:r,enhancer:this._resolveParameterEnhancer(t)})),this}parameterType(e,t){return(Array.isArray(e)?e:[e]).forEach(r=>this._paramMatches.push({type:r,enhancer:this._resolveParameterEnhancer(t)})),this}data(e,t){if(this._dataMatches.has(e))throw new Error(`${e} enhancer data key has been used more than once. This will cause data loss.`);return this._dataMatches.set(e,typeof t=="function"?{enhanceOne:t}:t),this}resolveParameterEnhancer(e,t){var n;return(n=this._paramMatches.find(r=>r.name&&r.name===e||r.type&&r.type===t.type||!r.type&&!r.name))==null?void 0:n.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},_=class{constructor(){this._componentIndex={};this._rootBuilder=new d}parameter(e){return this._rootBuilder.parameter(e),this}parameterName(e,t){return this._rootBuilder.parameterName(e,t),this}parameterType(e,t){return this._rootBuilder.parameterType(e,t),this}data(e,t){return this._rootBuilder.data(e,t),this}component(e,t){return(Array.isArray(e)?e:[e]).forEach(r=>{this._componentIndex[r]=this._componentIndex[r]||new d,t(this._componentIndex[r])}),this}resolveParameterEnhancer(e,t,n){let r=this._componentIndex[e.type];if(r){let a=r.resolveParameterEnhancer(t,n);if(a)return a}return this._rootBuilder.resolveParameterEnhancer(t,n)}resolveComponentEnhancers(e){let t=this._rootBuilder.resolveComponentEnhancers(),n=this._componentIndex[e.type];if(n){t=new Map(t);for(let[r,a]of n.resolveComponentEnhancers())t.set(r,a)}return t}};var C=class{constructor(e,t,n){this._resolve=e;this._reject=t;this.args=n;this._isCompleted=!1}resolve(e){this._resolve(e),this._isCompleted=!0}reject(e){this._reject(e),this._isCompleted=!0}get isCompleted(){return this._isCompleted}};function D({handleBatch:o,shouldQueue:e,limitPolicy:t}){let n=[];return{enhanceOne:async i=>{if(!e||e(i))return new Promise((c,s)=>{n.push(new C(c,s,i))})},completeAll:async()=>{if(n.length>0){try{await o(n)}catch(c){n.forEach(s=>s.reject(c))}if(n.some(c=>!c.isCompleted))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!")}let i=n.length;return n=[],i},limitPolicy:t}}async function X({composition:o,enhancers:e,context:t,onErrors:n=r=>{throw new Error(r.map(a=>`${a.message}
2
- ${typeof a.error=="object"&&"stack"in a.error?a.error.stack:a.error}`).join(`
3
-
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};
1
+ import{A as p,B as q,C as r,D as s,E as t,F as u,G as v,H as w,I as x,J as y,K as z,L as A,M as B,N as C,O as D,P as E,Q as F,R as G,S as H,T as I,l as a,m as b,n as c,o as d,p as e,q as f,r as g,s as h,t as i,u as j,v as k,w as l,x as m,y as n,z as o}from"./chunk-UPCNKIFB.mjs";export{f as BatchEntry,w as CANVAS_DRAFT_STATE,A as CANVAS_ENRICHMENT_TAG_PARAM,r as CANVAS_INTENT_TAG_PARAM,s as CANVAS_LOCALE_TAG_PARAM,v as CANVAS_LOCALIZATION_SLOT,q as CANVAS_LOCALIZATION_TYPE,y as CANVAS_PERSONALIZATION_PARAM,t as CANVAS_PERSONALIZE_SLOT,o as CANVAS_PERSONALIZE_TYPE,x as CANVAS_PUBLISHED_STATE,u as CANVAS_TEST_SLOT,p as CANVAS_TEST_TYPE,z as CANVAS_TEST_VARIANT_PARAM,m as CanvasClient,l as CanvasClientError,d as ChildEnhancerBuilder,e as EnhancerBuilder,n as UncachedCanvasClient,c as UniqueBatchEntries,k as compose,g as createBatchEnhancer,E as createEventBus,h as createLimitPolicy,j as enhance,H as extractLocales,F as getChannelName,b as getComponentPath,B as isSystemComponentDefinition,I as localize,C as mapSlotToPersonalizedVariations,D as mapSlotToTestVariations,i as nullLimitPolicy,G as subscribeToComposition,a as walkComponentTree};
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";var B=Object.create;var C=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var z=(r,e)=>{for(var n in e)C(r,n,{get:e[n],enumerable:!0})},L=(r,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of U(e))!D.call(r,o)&&o!==n&&C(r,o,{get:()=>e[o],enumerable:!(t=M(e,o))||t.enumerable});return r};var N=(r,e,n)=>(n=r!=null?B(F(r)):{},L(e||!r||!r.__esModule?C(n,"default",{value:r,enumerable:!0}):n,r)),H=r=>L(C({},"__esModule",{value:!0}),r);var le={};z(le,{BatchEntry:()=>P,CANVAS_DRAFT_STATE:()=>_e,CANVAS_ENRICHMENT_TAG_PARAM:()=>te,CANVAS_INTENT_TAG_PARAM:()=>X,CANVAS_LOCALE_TAG_PARAM:()=>R,CANVAS_LOCALIZATION_SLOT:()=>x,CANVAS_LOCALIZATION_TYPE:()=>v,CANVAS_PERSONALIZATION_PARAM:()=>_,CANVAS_PERSONALIZE_SLOT:()=>ee,CANVAS_PERSONALIZE_TYPE:()=>W,CANVAS_PUBLISHED_STATE:()=>we,CANVAS_TEST_SLOT:()=>ne,CANVAS_TEST_TYPE:()=>Q,CANVAS_TEST_VARIANT_PARAM:()=>w,CanvasClient:()=>y,CanvasClientError:()=>u,ChildEnhancerBuilder:()=>f,EnhancerBuilder:()=>I,UniqueBatchEntries:()=>g,compose:()=>Y,createBatchEnhancer:()=>q,createEventBus:()=>ae,createLimitPolicy:()=>T,enhance:()=>K,extractLocales:()=>k,getChannelName:()=>b,getComponentPath:()=>A,isSystemComponentDefinition:()=>oe,localize:()=>pe,mapSlotToPersonalizedVariations:()=>re,mapSlotToTestVariations:()=>ie,nullLimitPolicy:()=>m,subscribeToComposition:()=>ce,walkComponentTree:()=>d});module.exports=H(le);function d(r,e){let n=[{ancestorsAndSelf:[{component:r,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let t=n.pop();if(!t)continue;let o=t.ancestorsAndSelf[0];e(o.component,t.ancestorsAndSelf,{replaceComponent:s=>{Object.assign(o.component,s),["parameters","variant","slots","data","_pattern","_patternError"].forEach(a=>{s[a]||delete o.component[a]})},removeComponent:()=>{let{parentSlot:s,parentSlotIndex:c}=t.ancestorsAndSelf[0],a=t.ancestorsAndSelf[1];if(s&&typeof c!="undefined")a.component.slots[s].splice(c,1);else throw new Error("Unable to delete composition.")},insertAfter:s=>{let c=Array.isArray(s)?s:[s],{parentSlot:a,parentSlotIndex:p}=t.ancestorsAndSelf[0],l=t.ancestorsAndSelf[1];if(a&&typeof p!="undefined")l.component.slots[a].splice(p+1,0,...c);else throw new Error("Unable to insert after a component not in a slot.")}});let i=o.component.slots;if(i){let s=Object.keys(i);for(let c=s.length-1;c>=0;c--){let a=s[c],p=i[a];for(let l=p.length-1;l>=0;l--)n.push({ancestorsAndSelf:[{component:p[l],parentSlot:a,parentSlotIndex:l},...t.ancestorsAndSelf]})}}}while(n.length>0)}function A(r){let e=[];for(let n=r.length-1;n>=0;n--){let{parentSlot:t,parentSlotIndex:o}=r[n];t&&o!==void 0&&e.push(`${t}[${o}]`)}return`.${e.join(".")}`}var g=class{constructor(e,n){this.groups=e.reduce((t,o)=>{var s;let i=n(o.args);return t[i]=(s=t[i])!=null?s:[],t[i].push(o),t},{})}resolveKey(e,n){this.groups[e].forEach(t=>t.resolve(n))}resolveRemaining(e){Object.keys(this.groups).forEach(n=>{this.groups[n].forEach(t=>{t.isCompleted||t.resolve(e)})})}};var f=class{constructor(){this._paramMatches=Array();this._dataMatches=new Map}parameter(e){return this._paramMatches.push({enhancer:this._resolveParameterEnhancer(e)}),this}parameterName(e,n){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({name:o,enhancer:this._resolveParameterEnhancer(n)})),this}parameterType(e,n){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({type:o,enhancer:this._resolveParameterEnhancer(n)})),this}data(e,n){if(this._dataMatches.has(e))throw new Error(`${e} enhancer data key has been used more than once. This will cause data loss.`);return this._dataMatches.set(e,typeof n=="function"?{enhanceOne:n}:n),this}resolveParameterEnhancer(e,n){var t;return(t=this._paramMatches.find(o=>o.name&&o.name===e||o.type&&o.type===n.type||!o.type&&!o.name))==null?void 0:t.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},I=class{constructor(){this._componentIndex={};this._rootBuilder=new f}parameter(e){return this._rootBuilder.parameter(e),this}parameterName(e,n){return this._rootBuilder.parameterName(e,n),this}parameterType(e,n){return this._rootBuilder.parameterType(e,n),this}data(e,n){return this._rootBuilder.data(e,n),this}component(e,n){return(Array.isArray(e)?e:[e]).forEach(o=>{this._componentIndex[o]=this._componentIndex[o]||new f,n(this._componentIndex[o])}),this}resolveParameterEnhancer(e,n,t){let o=this._componentIndex[e.type];if(o){let i=o.resolveParameterEnhancer(n,t);if(i)return i}return this._rootBuilder.resolveParameterEnhancer(n,t)}resolveComponentEnhancers(e){let n=this._rootBuilder.resolveComponentEnhancers(),t=this._componentIndex[e.type];if(t){n=new Map(n);for(let[o,i]of t.resolveComponentEnhancers())n.set(o,i)}return n}};var P=class{constructor(e,n,t){this._resolve=e;this._reject=n;this.args=t;this._isCompleted=!1}resolve(e){this._resolve(e),this._isCompleted=!0}reject(e){this._reject(e),this._isCompleted=!0}get isCompleted(){return this._isCompleted}};function q({handleBatch:r,shouldQueue:e,limitPolicy:n}){let t=[];return{enhanceOne:async s=>{if(!e||e(s))return new Promise((c,a)=>{t.push(new P(c,a,s))})},completeAll:async()=>{if(t.length>0){try{await r(t)}catch(c){t.forEach(a=>a.reject(c))}if(t.some(c=>!c.isCompleted))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!")}let s=t.length;return t=[],s},limitPolicy:n}}var j=N(require("p-throttle")),V=N(require("p-retry"));function T({throttle:r={interval:1e3,limit:10},retry:e={retries:1,factor:1.66}}){let n=r?(0,j.default)(r):null;return function(o){let i=async()=>await o();if(n&&(i=n(i)),e){let s=i;i=()=>(0,V.default)(s,e)}return i()}}var m=async r=>await r();async function K({composition:r,enhancers:e,context:n,onErrors:t=o=>{throw new Error(o.map(i=>`${i.message}
1
+ "use strict";var Q=Object.create;var A=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.getPrototypeOf,ne=Object.prototype.hasOwnProperty;var x=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),re=(r,e)=>{for(var t in e)A(r,t,{get:e[t],enumerable:!0})},B=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ee(e))!ne.call(r,o)&&o!==t&&A(r,o,{get:()=>e[o],enumerable:!(n=X(e,o))||n.enumerable});return r};var oe=(r,e,t)=>(t=r!=null?Q(te(r)):{},B(e||!r||!r.__esModule?A(t,"default",{value:r,enumerable:!0}):t,r)),ie=r=>B(A({},"__esModule",{value:!0}),r);var G=x((Ve,F)=>{function u(r,e){typeof e=="boolean"&&(e={forever:e}),this._originalTimeouts=JSON.parse(JSON.stringify(r)),this._timeouts=r,this._options=e||{},this._maxRetryTime=e&&e.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._timer=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}F.exports=u;u.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)};u.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null};u.prototype.retry=function(r){if(this._timeout&&clearTimeout(this._timeout),!r)return!1;var e=new Date().getTime();if(r&&e-this._operationStart>=this._maxRetryTime)return this._errors.push(r),this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(r);var t=this._timeouts.shift();if(t===void 0)if(this._cachedTimeouts)this._errors.splice(0,this._errors.length-1),t=this._cachedTimeouts.slice(-1);else return!1;var n=this;return this._timer=setTimeout(function(){n._attempts++,n._operationTimeoutCb&&(n._timeout=setTimeout(function(){n._operationTimeoutCb(n._attempts)},n._operationTimeout),n._options.unref&&n._timeout.unref()),n._fn(n._attempts)},t),this._options.unref&&this._timer.unref(),!0};u.prototype.attempt=function(r,e){this._fn=r,e&&(e.timeout&&(this._operationTimeout=e.timeout),e.cb&&(this._operationTimeoutCb=e.cb));var t=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){t._operationTimeoutCb()},t._operationTimeout)),this._operationStart=new Date().getTime(),this._fn(this._attempts)};u.prototype.try=function(r){console.log("Using RetryOperation.try() is deprecated"),this.attempt(r)};u.prototype.start=function(r){console.log("Using RetryOperation.start() is deprecated"),this.attempt(r)};u.prototype.start=u.prototype.try;u.prototype.errors=function(){return this._errors};u.prototype.attempts=function(){return this._attempts};u.prototype.mainError=function(){if(this._errors.length===0)return null;for(var r={},e=null,t=0,n=0;n<this._errors.length;n++){var o=this._errors[n],i=o.message,s=(r[i]||0)+1;r[i]=s,s>=t&&(e=o,t=s)}return e}});var z=x(d=>{var ae=G();d.operation=function(r){var e=d.timeouts(r);return new ae(e,{forever:r&&(r.forever||r.retries===1/0),unref:r&&r.unref,maxRetryTime:r&&r.maxRetryTime})};d.timeouts=function(r){if(r instanceof Array)return[].concat(r);var e={retries:10,factor:2,minTimeout:1*1e3,maxTimeout:1/0,randomize:!1};for(var t in r)e[t]=r[t];if(e.minTimeout>e.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var n=[],o=0;o<e.retries;o++)n.push(this.createTimeout(o,e));return r&&r.forever&&!n.length&&n.push(this.createTimeout(o,e)),n.sort(function(i,s){return i-s}),n};d.createTimeout=function(r,e){var t=e.randomize?Math.random()+1:1,n=Math.round(t*Math.max(e.minTimeout,1)*Math.pow(e.factor,r));return n=Math.min(n,e.maxTimeout),n};d.wrap=function(r,e,t){if(e instanceof Array&&(t=e,e=null),!t){t=[];for(var n in r)typeof r[n]=="function"&&t.push(n)}for(var o=0;o<t.length;o++){var i=t[o],s=r[i];r[i]=function(c){var p=d.operation(e),m=Array.prototype.slice.call(arguments,1),l=m.pop();m.push(function(h){p.retry(h)||(h&&(arguments[0]=p.mainError()),l.apply(this,arguments))}),p.attempt(function(){c.apply(r,m)})}.bind(r,s),r[i].options=e}}});var K=x((De,H)=>{H.exports=z()});var Re={};re(Re,{BatchEntry:()=>v,CANVAS_DRAFT_STATE:()=>et,CANVAS_ENRICHMENT_TAG_PARAM:()=>Pe,CANVAS_INTENT_TAG_PARAM:()=>Ee,CANVAS_LOCALE_TAG_PARAM:()=>M,CANVAS_LOCALIZATION_SLOT:()=>U,CANVAS_LOCALIZATION_TYPE:()=>k,CANVAS_PERSONALIZATION_PARAM:()=>V,CANVAS_PERSONALIZE_SLOT:()=>Te,CANVAS_PERSONALIZE_TYPE:()=>ye,CANVAS_PUBLISHED_STATE:()=>tt,CANVAS_TEST_SLOT:()=>ge,CANVAS_TEST_TYPE:()=>Ce,CANVAS_TEST_VARIANT_PARAM:()=>$,CanvasClient:()=>E,CanvasClientError:()=>C,ChildEnhancerBuilder:()=>P,EnhancerBuilder:()=>b,UncachedCanvasClient:()=>L,UniqueBatchEntries:()=>w,compose:()=>fe,createBatchEnhancer:()=>se,createEventBus:()=>we,createLimitPolicy:()=>N,enhance:()=>le,extractLocales:()=>W,getChannelName:()=>D,getComponentPath:()=>_,isSystemComponentDefinition:()=>Ae,localize:()=>Ie,mapSlotToPersonalizedVariations:()=>_e,mapSlotToTestVariations:()=>ve,nullLimitPolicy:()=>f,subscribeToComposition:()=>be,walkComponentTree:()=>g});module.exports=ie(Re);function g(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],i=!0;e(o.component,n.ancestorsAndSelf,{replaceComponent:a=>{Object.assign(o.component,a),["parameters","variant","slots","data","_pattern","_patternError"].forEach(p=>{a[p]||delete o.component[p]})},removeComponent:()=>{let{parentSlot:a,parentComponent:c,correctedParentSlotIndex:p}=j(n,o.component);if(a&&typeof p!="undefined")c.component.slots[a].splice(p,1);else throw new Error("Unable to delete composition.")},insertAfter:a=>{let c=Array.isArray(a)?a:[a],{parentSlot:p,parentComponent:m,correctedParentSlotIndex:l}=j(n,o.component);if(p&&typeof l!="undefined")m.component.slots[p].splice(l+1,0,...c);else throw new Error("Unable to insert after a component not in a slot.")},stopProcessingDescendants(){i=!1}});let s=o.component.slots;if(i&&s){let a=Object.keys(s);for(let c=a.length-1;c>=0;c--){let p=a[c],m=s[p];for(let l=m.length-1;l>=0;l--)t.push({ancestorsAndSelf:[{component:m[l],parentSlot:p,parentSlotIndex:l},...n.ancestorsAndSelf]})}}}while(t.length>0)}function _(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(".")}`}function j(r,e){let{parentSlot:t,parentSlotIndex:n}=r.ancestorsAndSelf[0],o=r.ancestorsAndSelf[1],i=n;return t&&n!==void 0&&o.component.slots&&o.component.slots[t][n]!==e&&(i=o.component.slots[t].findIndex(s=>s===e)),{parentSlot:t,parentComponent:o,correctedParentSlotIndex:i}}var w=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 P=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}},b=class{constructor(){this._componentIndex={};this._rootBuilder=new P}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 P,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 v=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 se({handleBatch:r,shouldQueue:e,limitPolicy:t}){let n=[];return{enhanceOne:async s=>{if(!e||e(s))return new Promise((a,c)=>{n.push(new v(a,c,s))})},completeAll:async()=>{if(n.length>0){try{await r(n)}catch(a){n.forEach(c=>c.reject(a))}if(n.some(a=>!a.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 I=class extends Error{constructor(){super("Throttled function aborted"),this.name="AbortError"}};function R({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 m=Date.now();return m-o>e?(i=1,o=m,0):(i<r?i++:(o+=e,i=1),o-m)}let a=[];function c(){let m=Date.now();if(a.length<r)return a.push(m),0;let l=a.shift()+e;return m>=l?(a.push(m),0):(a.push(l),l-m)}let p=t?c:s;return m=>{let l=function(...h){if(!l.isEnabled)return(async()=>m.apply(this,h))();let y;return new Promise((T,Y)=>{y=setTimeout(()=>{T(m.apply(this,h)),n.delete(y)},p()),n.set(y,Y)})};return l.abort=()=>{for(let h of n.keys())clearTimeout(h),n.get(h)(new I);n.clear(),a.splice(0,a.length)},l.isEnabled=!0,l}}var q=oe(K(),1),ce=new Set(["Failed to fetch","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Network request failed"]),S=class extends Error{constructor(e){super(),e instanceof Error?(this.originalError=e,{message:e}=e):(this.originalError=new Error(e),this.originalError.stack=this.stack),this.name="AbortError",this.message=e}},pe=(r,e,t)=>{let n=t.retries-(e-1);return r.attemptNumber=e,r.retriesLeft=n,r},me=r=>ce.has(r),Z=r=>globalThis.DOMException===void 0?new Error(r):new DOMException(r);async function O(r,e){return new Promise((t,n)=>{e={onFailedAttempt(){},retries:10,...e};let o=q.default.operation(e);o.attempt(async i=>{try{t(await r(i))}catch(s){if(!(s instanceof Error)){n(new TypeError(`Non-error was thrown: "${s}". You should only throw errors.`));return}if(s instanceof S)o.stop(),n(s.originalError);else if(s instanceof TypeError&&!me(s.message))o.stop(),n(s);else{pe(s,i,e);try{await e.onFailedAttempt(s)}catch(a){n(a);return}o.retry(s)||n(o.mainError())}}}),e.signal&&!e.signal.aborted&&e.signal.addEventListener("abort",()=>{o.stop();let i=e.signal.reason===void 0?Z("The operation was aborted."):e.signal.reason;n(i instanceof Error?i:Z(i))},{once:!0})})}function N({throttle:r={interval:1e3,limit:10},retry:e={retries:1,factor:1.66}}){let t=r?R(r):null;return function(o){let i=async()=>await o();if(t&&(i=t(i)),e){let s=i;i=()=>O(s,e)}return i()}}var f=async r=>await r();async function le({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;d(r,(a,p)=>{var h;Object.entries((h=a.parameters)!=null?h:{}).forEach(([S,O])=>{let E=e.resolveParameterEnhancer(a,S,O);E&&(s.add(E),o.push(G(a,p,S,O,E,n)))});let l=e.resolveComponentEnhancers(a);o.push(Z(a,p,l,n)),i.add(l)}),o.push(...Array.from(i).flatMap(a=>Array.from(a).map(async([,p])=>{var l;try{p.completeAll&&await((l=p.limitPolicy)!=null?l:m)(()=>p.completeAll())}catch(h){return{error:h,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),o.push(...Array.from(s).map(async a=>{var p;try{a.completeAll&&await((p=a.limitPolicy)!=null?p:m)(()=>a.completeAll())}catch(l){return{error:l,message:"Batch parameter enhancer failed. Individual failed parameters should receive their own rejections."}}}));let c=(await Promise.all(o)).flatMap(a=>Array.isArray(a)?a:[a]).filter(a=>a);c.length&&t(c)}async function Z(r,e,n,t){return n.size&&(r.data={}),await Promise.all(Array.from(n).map(async([o,i])=>{var s;try{let a=await(i.completeAll?m:(s=i.limitPolicy)!=null?s:m)(async()=>i.enhanceOne({component:r,context:t}));a!=null&&(r.data[o]=a)}catch(c){let a=`Component ${A(e)} (type: ${r.type}): data.${o} enhancer threw exception. Data key will not be present.`;return delete r.data[o],{message:a,error:c}}}))}async function G(r,e,n,t,o,i){var s;try{let a=await(o.completeAll?m:(s=o.limitPolicy)!=null?s:m)(async()=>o.enhanceOne({parameter:t,parameterName:n,component:r,context:i}));a===null?delete r.parameters[n]:typeof a=="undefined"?r.parameters[n]={...t,value:t.value}:r.parameters[n]={...t,value:a}}catch(c){let a=`Component ${A(e)} (type: ${r.type}): enhancing parameter ${n} (type: ${t.type}) threw exception. Parameter will be removed.`;return delete r.parameters[n],{message:a,error:c}}}var Y=(r,...e)=>({enhanceOne:t=>{let o="enhanceOne"in r?r.enhanceOne(t):r(t);for(let i of e){let s=J(o)?o:Promise.resolve(o),c="enhanceOne"in i?i.enhanceOne:i;o=s.then(a=>c({...t,parameter:{type:t.parameter.type,value:a}}))}return o},completeAll:async()=>{var t,o;for(let i of e)if("completeAll"in i)throw new Error("Only the first enhancer in a compose chain can use the completeAll function (batching)");return(o="completeAll"in r?(t=r.completeAll)==null?void 0:t.call(r):0)!=null?o:0}});function J(r){return!!r&&(typeof r=="object"||typeof r=="function")&&typeof r.then=="function"}var u=class extends Error{constructor(n,t,o,i,s,c){super(`${n}
5
- ${i}${s?" "+s:""} (${t} ${o}${c?` Request ID: ${c}`:""})`);this.errorMessage=n;this.fetchMethod=t;this.fetchUri=o;this.statusCode=i;this.statusText=s;this.requestId=c;Object.setPrototypeOf(this,u.prototype)}},y=class{constructor(e){var t,o,i,s,c;if(!e.apiKey&&!e.bearerToken)throw new Error("You must provide an API key or a bearer token");let n=e.fetch;if(!n)if(typeof globalThis!="undefined"&&typeof globalThis.fetch!="undefined")n=globalThis.fetch.bind(globalThis);else if(typeof fetch!="undefined")n=fetch;else throw new Error("You must provide or polyfill a fetch implementation when not in a browser");this.options={...e,fetch:n,apiHost:(t=e.apiHost)!=null?t:"https://uniform.app",apiKey:(o=e.apiKey)!=null?o:null,projectId:(i=e.projectId)!=null?i:null,bearerToken:(s=e.bearerToken)!=null?s:null,limitPolicy:(c=e.limitPolicy)!=null?c:T({})}}async getCompositionList(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async getCompositionBySlug(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async getCompositionById(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async updateComposition(e){let n=this.createUrl("/api/v1/canvas");await this.apiClient(n,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(e){let n=this.createUrl("/api/v1/canvas"),{projectId:t}=this.options;await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:t}),expectNoContent:!0})}async getComponentDefinitions(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas-definitions",{...e,projectId:n});return await this.apiClient(t)}async updateComponentDefinition(e){let n=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(n,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(e){let n=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(e,n){return this.options.limitPolicy(async()=>{var i;let t=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`},o=await this.options.fetch(e.toString(),{...n,headers:{...n==null?void 0:n.headers,...t}});if(!o.ok){let s="";try{let c=await o.text();try{let a=JSON.parse(c);a.errorMessage?s=Array.isArray(a.errorMessage)?a.errorMessage.join(", "):a.errorMessage:s=c}catch(a){s=c}}catch(c){s="General error"}throw new u(s,(i=n==null?void 0:n.method)!=null?i:"GET",e.toString(),o.status,o.statusText,y.getRequestId(o))}return n!=null&&n.expectNoContent?null:await o.json()})}createUrl(e,n){let t=new URL(`${this.options.apiHost}${e}`);return Object.entries(n!=null?n:{}).forEach(([o,i])=>{var s;typeof i!==void 0&&i!==null&&t.searchParams.append(o,(s=i==null?void 0:i.toString())!=null?s:"")}),t}static getRequestId(e){let n=e.headers.get("x-nf-request-id");if(n)return n}};var W="$personalization",Q="$test",v="$localization",X="intentTag",R="locale",ee="pz",ne="test",x="localized",_e=0,we=64,_="$pzCrit",w="$tstVrnt",te="$enr";var oe=r=>r.startsWith("$");function re(r){return r?r.map((e,n)=>{var i,s;let t=(s=(i=e.parameters)==null?void 0:i[_])==null?void 0:s.value,o=(t==null?void 0:t.name)||`pz-${n}-${e.type}`;return{...e,id:o,pz:t}}):[]}function ie(r){return r?r.map((e,n)=>{var i,s,c;let t=(s=(i=e.parameters)==null?void 0:i[w])==null?void 0:s.value,o=(c=t==null?void 0:t.id)!=null?c:"testId"in e?e.testId:`ab-${n}-${e.type}`;return{...e,id:o}}):[]}var $="https://js.pusher.com/7.0.3/pusher.min.js";async function se(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((r,e)=>{let n=setTimeout(()=>{window.Pusher&&r(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${$}"><\/script> manually.`)},5e3),t=document.createElement("script");t.src=$,t.addEventListener("load",()=>{clearTimeout(n),r(window.Pusher)}),document.head.appendChild(t)})}async function ae(){let r=await se();if(!r)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let n=new r("7b5f5abd160fea549ffe",{cluster:"mt1"});n.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:t=>{let o=n.subscribe(t);return{unsubscribe:()=>n.unsubscribe(t),addEventHandler:(i,s)=>(o.bind(i,s),()=>o.unbind(i,s))}}}}return e}function b(r,e,n){return`${r}.${e}@${n}`}function ce({projectId:r,compositionId:e,compositionState:n=0,eventBus:{subscribe:t},callback:o,event:i="updated"}){let s=b(r,e,n),c=t(s),a=c.addEventHandler(i,o);return()=>{a(),c.unsubscribe()}}function k({component:r}){var t;let e={},n=(t=r.slots)==null?void 0:t[x];return n==null||n.forEach(o=>{var s;let i=(s=o.parameters)==null?void 0:s[R];(i==null?void 0:i.value)&&typeof i.value=="string"&&(e[i.value]=e[i.value]||[],e[i.value].push(o))}),e}function pe({composition:r,locale:e}){d(r,(n,t,o)=>{if(n.type===v){let i=k({component:n}),s=typeof e=="string"?e:e({component:n,locales:i}),c;if(s&&(c=i[s]),c!=null&&c.length){let[a,...p]=c;o.replaceComponent(a),p.length&&o.insertAfter(p)}else o.removeComponent()}})}0&&(module.exports={BatchEntry,CANVAS_DRAFT_STATE,CANVAS_ENRICHMENT_TAG_PARAM,CANVAS_INTENT_TAG_PARAM,CANVAS_LOCALE_TAG_PARAM,CANVAS_LOCALIZATION_SLOT,CANVAS_LOCALIZATION_TYPE,CANVAS_PERSONALIZATION_PARAM,CANVAS_PERSONALIZE_SLOT,CANVAS_PERSONALIZE_TYPE,CANVAS_PUBLISHED_STATE,CANVAS_TEST_SLOT,CANVAS_TEST_TYPE,CANVAS_TEST_VARIANT_PARAM,CanvasClient,CanvasClientError,ChildEnhancerBuilder,EnhancerBuilder,UniqueBatchEntries,compose,createBatchEnhancer,createEventBus,createLimitPolicy,enhance,extractLocales,getChannelName,getComponentPath,isSystemComponentDefinition,localize,mapSlotToPersonalizedVariations,mapSlotToTestVariations,nullLimitPolicy,subscribeToComposition,walkComponentTree});
4
+ `))}}){let o=[],i=new Set,s=new Set;g(r,(c,p)=>{var l;Object.entries((l=c.parameters)!=null?l:{}).forEach(([h,y])=>{let T=e.resolveParameterEnhancer(c,h,y);T&&(s.add(T),o.push(he(c,p,h,y,T,t)))});let m=e.resolveComponentEnhancers(c);o.push(ue(c,p,m,t)),i.add(m)}),o.push(...Array.from(i).flatMap(c=>Array.from(c).map(async([,p])=>{var m;try{p.completeAll&&await((m=p.limitPolicy)!=null?m:f)(()=>p.completeAll())}catch(l){return{error:l,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),o.push(...Array.from(s).map(async c=>{var p;try{c.completeAll&&await((p=c.limitPolicy)!=null?p:f)(()=>c.completeAll())}catch(m){return{error:m,message:"Batch parameter enhancer failed. Individual failed parameters should receive their own rejections."}}}));let a=(await Promise.all(o)).flatMap(c=>Array.isArray(c)?c:[c]).filter(c=>c);a.length&&n(a)}async function ue(r,e,t,n){return t.size&&(r.data={}),await Promise.all(Array.from(t).map(async([o,i])=>{var s;try{let c=await(i.completeAll?f:(s=i.limitPolicy)!=null?s:f)(async()=>i.enhanceOne({component:r,context:n}));c!=null&&(r.data[o]=c)}catch(a){let c=`Component ${_(e)} (type: ${r.type}): data.${o} enhancer threw exception. Data key will not be present.`;return delete r.data[o],{message:c,error:a}}}))}async function he(r,e,t,n,o,i){var s;try{let c=await(o.completeAll?f:(s=o.limitPolicy)!=null?s:f)(async()=>o.enhanceOne({parameter:n,parameterName:t,component:r,context:i}));c===null?delete r.parameters[t]:typeof c=="undefined"?r.parameters[t]={...n,value:n.value}:r.parameters[t]={...n,value:c}}catch(a){let c=`Component ${_(e)} (type: ${r.type}): enhancing parameter ${t} (type: ${n.type}) threw exception. Parameter will be removed.`;return delete r.parameters[t],{message:c,error:a}}}var fe=(r,...e)=>({enhanceOne:n=>{let o="enhanceOne"in r?r.enhanceOne(n):r(n);for(let i of e){let s=de(o)?o:Promise.resolve(o),a="enhanceOne"in i?i.enhanceOne:i;o=s.then(c=>a({...n,parameter:{type:n.parameter.type,value:c}}))}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 de(r){return!!r&&(typeof r=="object"||typeof r=="function")&&typeof r.then=="function"}var C=class extends Error{constructor(t,n,o,i,s,a){super(`${t}
5
+ ${i}${s?" "+s:""} (${n} ${o}${a?` Request ID: ${a}`:""})`);this.errorMessage=t;this.fetchMethod=n;this.fetchUri=o;this.statusCode=i;this.statusText=s;this.requestId=a;Object.setPrototypeOf(this,C.prototype)}},E=class{constructor(e){var n,o,i,s,a,c,p;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:(a=e.limitPolicy)!=null?a:N({}),bypassCache:(c=e.bypassCache)!=null?c:!1,experiment14:(p=e.experiment14)!=null?p:!1}}get canvasUrl(){return this.options.experiment14?"/api/edge/v1/composition":"/api/v1/canvas"}async getCompositionList(e){let{projectId:t}=this.options,n=this.createUrl(this.canvasUrl,{...e,projectId:t});return await this.apiClient(n)}async getCompositionBySlug(e){let{projectId:t}=this.options,n=this.createUrl(this.canvasUrl,{...e,projectId:t});return await this.apiClient(n)}async getCompositionById(e){let{projectId:t}=this.options,n=this.createUrl(this.canvasUrl,{...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}`};this.options.bypassCache&&(n["x-bypass-cache"]="true");let o=await this.options.fetch(e.toString(),{...t,headers:{...t==null?void 0:t.headers,...n}});if(!o.ok){let s="";try{let a=await o.text();try{let c=JSON.parse(a);c.errorMessage?s=Array.isArray(c.errorMessage)?c.errorMessage.join(", "):c.errorMessage:s=a}catch(c){s=a}}catch(a){s="General error"}throw new C(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("apigw-requestid");if(t)return t}},L=class extends E{constructor(e){super({...e,bypassCache:!0})}};var ye="$personalization",Ce="$test",k="$localization",Ee="intentTag",M="locale",Te="pz",ge="test",U="localized",et=0,tt=64,V="$pzCrit",$="$tstVrnt",Pe="$enr";var Ae=r=>r.startsWith("$");function _e(r){return r?r.map((e,t)=>{var i,s;let n=(s=(i=e.parameters)==null?void 0:i[V])==null?void 0:s.value,o=(n==null?void 0:n.name)||`pz-${t}-${e.type}`;return{...e,id:o,pz:n}}):[]}function ve(r){return r?r.map((e,t)=>{var i,s,a;let n=(s=(i=e.parameters)==null?void 0:i[$])==null?void 0:s.value,o=(a=n==null?void 0:n.id)!=null?a:"testId"in e?e.testId:`ab-${t}-${e.type}`;return{...e,id:o}}):[]}var J="https://js.pusher.com/7.0.3/pusher.min.js";async function xe(){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="${J}"><\/script> manually.`)},5e3),n=document.createElement("script");n.src=J,n.addEventListener("load",()=>{clearTimeout(t),r(window.Pusher)}),document.head.appendChild(n)})}async function we(){let r=await xe();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 D(r,e,t){return`${r}.${e}@${t}`}function be({projectId:r,compositionId:e,compositionState:t=0,eventBus:{subscribe:n},callback:o,event:i="updated"}){let s=D(r,e,t),a=n(s),c=a.addEventHandler(i,o);return()=>{c(),a.unsubscribe()}}function W({component:r}){var n;let e={},t=(n=r.slots)==null?void 0:n[U];return t==null||t.forEach(o=>{var s;let i=(s=o.parameters)==null?void 0:s[M];(i==null?void 0:i.value)&&typeof i.value=="string"&&(e[i.value]=e[i.value]||[],e[i.value].push(o))}),e}function Ie({composition:r,locale:e}){g(r,(t,n,o)=>{if(t.type===k){let i=W({component:t}),s=typeof e=="string"?e:e({component:t,locales:i}),a;if(s&&(a=i[s]),a!=null&&a.length){let[c,...p]=a;o.replaceComponent(c),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,UncachedCanvasClient,UniqueBatchEntries,compose,createBatchEnhancer,createEventBus,createLimitPolicy,enhance,extractLocales,getChannelName,getComponentPath,isSystemComponentDefinition,localize,mapSlotToPersonalizedVariations,mapSlotToTestVariations,nullLimitPolicy,subscribeToComposition,walkComponentTree});
package/dist/index.mjs CHANGED
@@ -1,4 +1 @@
1
- "use strict";import{d as L,e as l,f as $,g as j,h as k,i as F,j as A,k as V,l as g,m as N,n as U,o as v,p as z,q as W,r as x,s as w,t as H}from"./chunk-HJHWEOMG.mjs";function u(o,e){let t=[{ancestorsAndSelf:[{component:o,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let n=t.pop();if(!n)continue;let r=n.ancestorsAndSelf[0];e(r.component,n.ancestorsAndSelf,{replaceComponent:i=>{Object.assign(r.component,i),["parameters","variant","slots","data","_pattern","_patternError"].forEach(s=>{i[s]||delete r.component[s]})},removeComponent:()=>{let{parentSlot:i,parentSlotIndex:c}=n.ancestorsAndSelf[0],s=n.ancestorsAndSelf[1];if(i&&typeof c!="undefined")s.component.slots[i].splice(c,1);else throw new Error("Unable to delete composition.")},insertAfter:i=>{let c=Array.isArray(i)?i:[i],{parentSlot:s,parentSlotIndex:p}=n.ancestorsAndSelf[0],m=n.ancestorsAndSelf[1];if(s&&typeof p!="undefined")m.component.slots[s].splice(p+1,0,...c);else throw new Error("Unable to insert after a component not in a slot.")}});let a=r.component.slots;if(a){let i=Object.keys(a);for(let c=i.length-1;c>=0;c--){let s=i[c],p=a[s];for(let m=p.length-1;m>=0;m--)t.push({ancestorsAndSelf:[{component:p[m],parentSlot:s,parentSlotIndex:m},...n.ancestorsAndSelf]})}}}while(t.length>0)}function y(o){let e=[];for(let t=o.length-1;t>=0;t--){let{parentSlot:n,parentSlotIndex:r}=o[t];n&&r!==void 0&&e.push(`${n}[${r}]`)}return`.${e.join(".")}`}var T=class{constructor(e,t){this.groups=e.reduce((n,r)=>{var i;let a=t(r.args);return n[a]=(i=n[a])!=null?i:[],n[a].push(r),n},{})}resolveKey(e,t){this.groups[e].forEach(n=>n.resolve(t))}resolveRemaining(e){Object.keys(this.groups).forEach(t=>{this.groups[t].forEach(n=>{n.isCompleted||n.resolve(e)})})}};var d=class{constructor(){this._paramMatches=Array();this._dataMatches=new Map}parameter(e){return this._paramMatches.push({enhancer:this._resolveParameterEnhancer(e)}),this}parameterName(e,t){return(Array.isArray(e)?e:[e]).forEach(r=>this._paramMatches.push({name:r,enhancer:this._resolveParameterEnhancer(t)})),this}parameterType(e,t){return(Array.isArray(e)?e:[e]).forEach(r=>this._paramMatches.push({type:r,enhancer:this._resolveParameterEnhancer(t)})),this}data(e,t){if(this._dataMatches.has(e))throw new Error(`${e} enhancer data key has been used more than once. This will cause data loss.`);return this._dataMatches.set(e,typeof t=="function"?{enhanceOne:t}:t),this}resolveParameterEnhancer(e,t){var n;return(n=this._paramMatches.find(r=>r.name&&r.name===e||r.type&&r.type===t.type||!r.type&&!r.name))==null?void 0:n.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},_=class{constructor(){this._componentIndex={};this._rootBuilder=new d}parameter(e){return this._rootBuilder.parameter(e),this}parameterName(e,t){return this._rootBuilder.parameterName(e,t),this}parameterType(e,t){return this._rootBuilder.parameterType(e,t),this}data(e,t){return this._rootBuilder.data(e,t),this}component(e,t){return(Array.isArray(e)?e:[e]).forEach(r=>{this._componentIndex[r]=this._componentIndex[r]||new d,t(this._componentIndex[r])}),this}resolveParameterEnhancer(e,t,n){let r=this._componentIndex[e.type];if(r){let a=r.resolveParameterEnhancer(t,n);if(a)return a}return this._rootBuilder.resolveParameterEnhancer(t,n)}resolveComponentEnhancers(e){let t=this._rootBuilder.resolveComponentEnhancers(),n=this._componentIndex[e.type];if(n){t=new Map(t);for(let[r,a]of n.resolveComponentEnhancers())t.set(r,a)}return t}};var C=class{constructor(e,t,n){this._resolve=e;this._reject=t;this.args=n;this._isCompleted=!1}resolve(e){this._resolve(e),this._isCompleted=!0}reject(e){this._reject(e),this._isCompleted=!0}get isCompleted(){return this._isCompleted}};function D({handleBatch:o,shouldQueue:e,limitPolicy:t}){let n=[];return{enhanceOne:async i=>{if(!e||e(i))return new Promise((c,s)=>{n.push(new C(c,s,i))})},completeAll:async()=>{if(n.length>0){try{await o(n)}catch(c){n.forEach(s=>s.reject(c))}if(n.some(c=>!c.isCompleted))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!")}let i=n.length;return n=[],i},limitPolicy:t}}async function X({composition:o,enhancers:e,context:t,onErrors:n=r=>{throw new Error(r.map(a=>`${a.message}
2
- ${typeof a.error=="object"&&"stack"in a.error?a.error.stack:a.error}`).join(`
3
-
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};
1
+ import{A as p,B as q,C as r,D as s,E as t,F as u,G as v,H as w,I as x,J as y,K as z,L as A,M as B,N as C,O as D,P as E,Q as F,R as G,S as H,T as I,l as a,m as b,n as c,o as d,p as e,q as f,r as g,s as h,t as i,u as j,v as k,w as l,x as m,y as n,z as o}from"./chunk-UPCNKIFB.mjs";export{f as BatchEntry,w as CANVAS_DRAFT_STATE,A as CANVAS_ENRICHMENT_TAG_PARAM,r as CANVAS_INTENT_TAG_PARAM,s as CANVAS_LOCALE_TAG_PARAM,v as CANVAS_LOCALIZATION_SLOT,q as CANVAS_LOCALIZATION_TYPE,y as CANVAS_PERSONALIZATION_PARAM,t as CANVAS_PERSONALIZE_SLOT,o as CANVAS_PERSONALIZE_TYPE,x as CANVAS_PUBLISHED_STATE,u as CANVAS_TEST_SLOT,p as CANVAS_TEST_TYPE,z as CANVAS_TEST_VARIANT_PARAM,m as CanvasClient,l as CanvasClientError,d as ChildEnhancerBuilder,e as EnhancerBuilder,n as UncachedCanvasClient,c as UniqueBatchEntries,k as compose,g as createBatchEnhancer,E as createEventBus,h as createLimitPolicy,j as enhance,H as extractLocales,F as getChannelName,b as getComponentPath,B as isSystemComponentDefinition,I as localize,C as mapSlotToPersonalizedVariations,D as mapSlotToTestVariations,i as nullLimitPolicy,G as subscribeToComposition,a as walkComponentTree};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas",
3
- "version": "16.2.3",
3
+ "version": "17.1.0",
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,31 +36,34 @@
36
36
  },
37
37
  "sideEffects": false,
38
38
  "scripts": {
39
- "build": "tsup --minify",
40
- "dev": "tsup --watch",
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
- "@types/yargs": "17.0.10",
49
- "@uniformdev/cli": "^16.2.0",
50
- "pusher-js": "7.0.6",
51
+ "@types/yargs": "17.0.11",
52
+ "@uniformdev/cli": "^17.1.0",
53
+ "p-limit": "4.0.0",
54
+ "p-retry": "5.1.1",
55
+ "p-throttle": "5.0.0",
56
+ "pusher-js": "7.3.0",
51
57
  "yargs": "17.5.1"
52
58
  },
53
59
  "dependencies": {
54
- "@uniformdev/context": "^16.2.0",
55
- "isomorphic-unfetch": "^3.1.0",
56
- "p-limit": "3.1.0",
57
- "p-retry": "4.6.2",
58
- "p-throttle": "4.1.1"
60
+ "@uniformdev/context": "^17.1.0"
59
61
  },
60
62
  "files": [
61
63
  "/dist"
62
64
  ],
63
65
  "publishConfig": {
64
66
  "access": "public"
65
- }
67
+ },
68
+ "gitHead": "47c6abcea06f19dcd2e723bbee79da32e7c395e5"
66
69
  }