@uniformdev/canvas 16.2.1-alpha.106 → 16.2.1-nuxt.249

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.
@@ -256,6 +256,32 @@ interface external$1 {
256
256
  value: unknown;
257
257
  /** @description The type of the parameter. Determines how it is displayed when editing, and tells the consumer how to process it. */
258
258
  type: string;
259
+ binding?: external$1["uniform-canvas-types.swagger.yml"]["components"]["schemas"]["ComponentParameterBinding"];
260
+ };
261
+ /**
262
+ * @deprecated
263
+ * @description Defines a binding from a resource data value to a component parameter value. Do not use.
264
+ */
265
+ ComponentParameterBinding: {
266
+ /**
267
+ * @description A JSON Pointer expression that defines the binding directly to the parameter value, or
268
+ * a map of JSON Pointers in the target parameter to JSON Pointers in the source resource data.
269
+ * Used to bind to object-type values.
270
+ * e.g. { "/prop1/thing": "/res1/things/value" } would set the target parameter's `value` to
271
+ * {
272
+ * prop1: {
273
+ * thing: "value of /res1/things/value resource"
274
+ * }
275
+ * }
276
+ */
277
+ pointer: string | {
278
+ [key: string]: string;
279
+ };
280
+ /**
281
+ * @description The syntax of the binding (currently always 'jptr')
282
+ * @enum {string}
283
+ */
284
+ syntax: "jptr";
259
285
  };
260
286
  /** @description Defines the shape of a component instance served by the composition API. */
261
287
  ComponentInstance: {
@@ -437,6 +463,32 @@ interface components$1 {
437
463
  value: unknown;
438
464
  /** @description The type of the parameter. Determines how it is displayed when editing, and tells the consumer how to process it. */
439
465
  type: string;
466
+ binding?: components$1["schemas"]["ComponentParameterBinding"];
467
+ };
468
+ /**
469
+ * @deprecated
470
+ * @description Defines a binding from a resource data value to a component parameter value. Do not use.
471
+ */
472
+ ComponentParameterBinding: {
473
+ /**
474
+ * @description A JSON Pointer expression that defines the binding directly to the parameter value, or
475
+ * a map of JSON Pointers in the target parameter to JSON Pointers in the source resource data.
476
+ * Used to bind to object-type values.
477
+ * e.g. { "/prop1/thing": "/res1/things/value" } would set the target parameter's `value` to
478
+ * {
479
+ * prop1: {
480
+ * thing: "value of /res1/things/value resource"
481
+ * }
482
+ * }
483
+ */
484
+ pointer: string | {
485
+ [key: string]: string;
486
+ };
487
+ /**
488
+ * @description The syntax of the binding (currently always 'jptr')
489
+ * @enum {string}
490
+ */
491
+ syntax: "jptr";
440
492
  };
441
493
  /** @description Defines the shape of a component instance served by the composition API. */
442
494
  ComponentInstance: {
@@ -842,6 +894,32 @@ interface external {
842
894
  value: unknown;
843
895
  /** @description The type of the parameter. Determines how it is displayed when editing, and tells the consumer how to process it. */
844
896
  type: string;
897
+ binding?: external["uniform-canvas-types.swagger.yml"]["components"]["schemas"]["ComponentParameterBinding"];
898
+ };
899
+ /**
900
+ * @deprecated
901
+ * @description Defines a binding from a resource data value to a component parameter value. Do not use.
902
+ */
903
+ ComponentParameterBinding: {
904
+ /**
905
+ * @description A JSON Pointer expression that defines the binding directly to the parameter value, or
906
+ * a map of JSON Pointers in the target parameter to JSON Pointers in the source resource data.
907
+ * Used to bind to object-type values.
908
+ * e.g. { "/prop1/thing": "/res1/things/value" } would set the target parameter's `value` to
909
+ * {
910
+ * prop1: {
911
+ * thing: "value of /res1/things/value resource"
912
+ * }
913
+ * }
914
+ */
915
+ pointer: string | {
916
+ [key: string]: string;
917
+ };
918
+ /**
919
+ * @description The syntax of the binding (currently always 'jptr')
920
+ * @enum {string}
921
+ */
922
+ syntax: "jptr";
845
923
  };
846
924
  /** @description Defines the shape of a component instance served by the composition API. */
847
925
  ComponentInstance: {
@@ -921,6 +999,8 @@ declare type ComponentParameter<TValue = unknown> = Omit<SharedComponents['Compo
921
999
  /** The type of the parameter. Determines how it is displayed when editing, and tells the consumer how to process it. */
922
1000
  value: TValue;
923
1001
  };
1002
+ /** Defines a binding from a resource data value to a component parameter value. */
1003
+ declare type ComponentParameterBinding = SharedComponents['ComponentParameterBinding'];
924
1004
  /** Defines the shape of a component instance served by the composition API. */
925
1005
  declare type ComponentInstance = SharedComponents['ComponentInstance'] & {
926
1006
  /** Data for the component instance, provided by a component enhancer. Never set in unenhanced data. */
@@ -954,4 +1034,4 @@ declare global {
954
1034
  */
955
1035
  declare function createEventBus(): Promise<PreviewEventBus | undefined>;
956
1036
 
957
- export { createEventBus as A, ComponentInstance as C, PreviewEventBus as P, RootComponentInstance as R, ComponentParameter as a, CompositionGetParameters as b, CompositionPutParameters as c, CompositionDeleteParameters as d, ComponentDefinitionGetParameters as e, ComponentDefinitionPutParameters as f, ComponentDefinitionDeleteParameters as g, ComponentDefinitionGetResponse as h, ComponentDefinitionAPIResponse as i, ComponentDefinitionAPIPutRequest as j, ComponentDefinitionAPIDeleteRequest as k, ComponentDefinitionListAPIOptions as l, ComponentDefinitionParameter as m, ComponentDefinitionVariant as n, ComponentDefinitionSlugSettings as o, ComponentDefinitionSlot as p, ComponentDefinitionPermission as q, ComponentDefinition as r, CreatingComponentDefinition as s, CompositionGetResponse as t, CompositionGetListResponse as u, CompositionAPIResponse as v, CompositionAPIDeleteRequest as w, CompositionListAPIResponse as x, CompositionAPIOptions as y, ChannelSubscription as z };
1037
+ export { ChannelSubscription as A, createEventBus as B, ComponentInstance as C, PreviewEventBus as P, RootComponentInstance as R, ComponentParameter as a, CompositionGetParameters as b, CompositionPutParameters as c, CompositionDeleteParameters as d, ComponentDefinitionGetParameters as e, ComponentDefinitionPutParameters as f, ComponentDefinitionDeleteParameters as g, ComponentDefinitionGetResponse as h, ComponentDefinitionAPIResponse as i, ComponentDefinitionAPIPutRequest as j, ComponentDefinitionAPIDeleteRequest as k, ComponentDefinitionListAPIOptions as l, ComponentDefinitionParameter as m, ComponentDefinitionVariant as n, ComponentDefinitionSlugSettings as o, ComponentDefinitionSlot as p, ComponentDefinitionPermission as q, ComponentDefinition as r, CreatingComponentDefinition as s, CompositionGetResponse as t, CompositionGetListResponse as u, CompositionAPIResponse as v, CompositionAPIDeleteRequest as w, CompositionListAPIResponse as x, CompositionAPIOptions as y, ComponentParameterBinding as z };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
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';
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-c826147a.js';
2
+ export { A 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, s as CreatingComponentDefinition, P as PreviewEventBus, R as RootComponentInstance, B as createEventBus } from './createEventBus-c826147a.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,8 @@ 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 caching is disabled. */
272
+ bypassCache?: boolean;
266
273
  };
267
274
  declare class CanvasClientError extends Error {
268
275
  errorMessage: string;
@@ -290,6 +297,12 @@ declare class CanvasClient {
290
297
  [key: string]: {
291
298
  value: unknown;
292
299
  type: string;
300
+ binding?: {
301
+ pointer: string | {
302
+ [key: string]: string;
303
+ };
304
+ syntax: "jptr";
305
+ } | undefined;
293
306
  };
294
307
  } | undefined;
295
308
  variant?: string | undefined;
@@ -300,6 +313,12 @@ declare class CanvasClient {
300
313
  [key: string]: {
301
314
  value: unknown;
302
315
  type: string;
316
+ binding?: {
317
+ pointer: string | {
318
+ [key: string]: string;
319
+ };
320
+ syntax: "jptr";
321
+ } | undefined;
303
322
  };
304
323
  } | undefined;
305
324
  variant?: string | undefined;
@@ -329,6 +348,12 @@ declare class CanvasClient {
329
348
  [key: string]: {
330
349
  value: unknown;
331
350
  type: string;
351
+ binding?: {
352
+ pointer: string | {
353
+ [key: string]: string;
354
+ };
355
+ syntax: "jptr";
356
+ } | undefined;
332
357
  };
333
358
  } | undefined;
334
359
  variant?: string | undefined;
@@ -339,6 +364,12 @@ declare class CanvasClient {
339
364
  [key: string]: {
340
365
  value: unknown;
341
366
  type: string;
367
+ binding?: {
368
+ pointer: string | {
369
+ [key: string]: string;
370
+ };
371
+ syntax: "jptr";
372
+ } | undefined;
342
373
  };
343
374
  } | undefined;
344
375
  variant?: string | undefined;
@@ -367,6 +398,12 @@ declare class CanvasClient {
367
398
  [key: string]: {
368
399
  value: unknown;
369
400
  type: string;
401
+ binding?: {
402
+ pointer: string | {
403
+ [key: string]: string;
404
+ };
405
+ syntax: "jptr";
406
+ } | undefined;
370
407
  };
371
408
  } | undefined;
372
409
  variant?: string | undefined;
@@ -377,6 +414,12 @@ declare class CanvasClient {
377
414
  [key: string]: {
378
415
  value: unknown;
379
416
  type: string;
417
+ binding?: {
418
+ pointer: string | {
419
+ [key: string]: string;
420
+ };
421
+ syntax: "jptr";
422
+ } | undefined;
380
423
  };
381
424
  } | undefined;
382
425
  variant?: string | undefined;
@@ -437,6 +480,12 @@ declare class CanvasClient {
437
480
  [key: string]: {
438
481
  value: unknown;
439
482
  type: string;
483
+ binding?: {
484
+ pointer: string | {
485
+ [key: string]: string;
486
+ };
487
+ syntax: "jptr";
488
+ } | undefined;
440
489
  };
441
490
  } | undefined;
442
491
  variant?: string | undefined;
@@ -462,6 +511,9 @@ declare class CanvasClient {
462
511
  private createUrl;
463
512
  private static getRequestId;
464
513
  }
514
+ declare class UncachedCanvasClient extends CanvasClient {
515
+ constructor(options: Omit<CanvasClientOptions, 'bypassCache'>);
516
+ }
465
517
 
466
518
  /** Public ID of Canvas personalization component type */
467
519
  declare const CANVAS_PERSONALIZE_TYPE = "$personalization";
@@ -489,6 +541,14 @@ declare const CANVAS_PERSONALIZATION_PARAM = "$pzCrit";
489
541
  declare const CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
490
542
  /** Public ID of the Uniform Context enrichment tag parameter on Canvas components */
491
543
  declare const CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
544
+ /** Component type of 'loop' system component */
545
+ declare const CANVAS_LOOP_TYPE = "$loop";
546
+ /** Name of parameter on loop component that defines the name of the resource to expose for the iterator */
547
+ declare const CANVAS_LOOP_RESOURCE_PARAMETER = "$loopResource";
548
+ /** Name of the parameter that stores the binding for the loop */
549
+ declare const CANVAS_LOOP_PARAMETER = "$loopBinding";
550
+ /** Name of the slot that the loop component exposes for the iterator body */
551
+ declare const CANVAS_LOOP_SLOT = "body";
492
552
 
493
553
  /** Determines if a given Canvas component type is a system-defined type */
494
554
  declare const isSystemComponentDefinition: (componentType: string) => boolean;
@@ -532,4 +592,47 @@ declare function localize({ composition, locale, }: {
532
592
  }) => string | undefined);
533
593
  }): void;
534
594
 
535
- 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 };
595
+ /**
596
+ * Resource objects that can be bound to on a composition
597
+ * @deprecated Do not use
598
+ */
599
+ declare type CompositionResources = Record<string, unknown>;
600
+
601
+ /** @deprecated Do not use */
602
+ declare type BindParameterResult = {
603
+ bound: boolean;
604
+ value?: unknown;
605
+ };
606
+ /** @deprecated Do not use */
607
+ declare function bindParameter(parameter: ComponentParameter, resources: CompositionResources): BindParameterResult;
608
+
609
+ /** @deprecated Do not use */
610
+ declare type BindParametersResult = {
611
+ hasBindings: boolean;
612
+ errors: Error[];
613
+ result: ComponentInstance;
614
+ };
615
+ /** @deprecated Do not use */
616
+ declare type BindParametersOptions = {
617
+ /**
618
+ * If true, any binding errors are thrown. Otherwise, they are returned in the result.
619
+ * @default true
620
+ */
621
+ throwErrors?: boolean;
622
+ /**
623
+ * If true, loop components are bound and replaced by their enumerated values.
624
+ * If false, loop components are untouched and remain in the composition data with bindings still in the loop body.
625
+ * @default true
626
+ */
627
+ expandLoops?: boolean;
628
+ /**
629
+ * If true, leaves binding expressions behind in the resulting composition.
630
+ * If false, binding expressions are removed from the resulting composition.
631
+ * @default false
632
+ */
633
+ preserveBindings?: boolean;
634
+ };
635
+ /** @deprecated Do not use */
636
+ declare function bindParameters(composition: ComponentInstance, resources: CompositionResources, options?: BindParametersOptions): BindParametersResult;
637
+
638
+ export { BatchEnhancer, BatchEntry, BindParameterResult, BindParametersOptions, BindParametersResult, CANVAS_DRAFT_STATE, CANVAS_ENRICHMENT_TAG_PARAM, CANVAS_INTENT_TAG_PARAM, CANVAS_LOCALE_TAG_PARAM, CANVAS_LOCALIZATION_SLOT, CANVAS_LOCALIZATION_TYPE, CANVAS_LOOP_PARAMETER, CANVAS_LOOP_RESOURCE_PARAMETER, CANVAS_LOOP_SLOT, CANVAS_LOOP_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, CompositionResources, EnhancerBuilder, EnhancerContext, EnhancerError, EventNames, LimitPolicy, SubscribeToCompositionOptions, UncachedCanvasClient, UniqueBatchEntries, UnsubscribeCallback, WalkComponentTreeActions, bindParameter, bindParameters, compose, createBatchEnhancer, createLimitPolicy, enhance, extractLocales, getChannelName, getComponentPath, isSystemComponentDefinition, localize, mapSlotToPersonalizedVariations, mapSlotToTestVariations, nullLimitPolicy, subscribeToComposition, walkComponentTree };
package/dist/index.esm.js CHANGED
@@ -1,4 +1 @@
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
- ${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,U as J,V as K,W as L,X as M,Y as N,Z as O,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-BJ45Y4JT.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,D as CANVAS_LOOP_PARAMETER,C as CANVAS_LOOP_RESOURCE_PARAMETER,E as CANVAS_LOOP_SLOT,B as CANVAS_LOOP_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,N as bindParameter,O as bindParameters,k as compose,g as createBatchEnhancer,I as createEventBus,h as createLimitPolicy,j as enhance,L as extractLocales,J as getChannelName,b as getComponentPath,F as isSystemComponentDefinition,M as localize,G as mapSlotToPersonalizedVariations,H as mapSlotToTestVariations,i as nullLimitPolicy,K as subscribeToComposition,a as walkComponentTree};
package/dist/index.js CHANGED
@@ -1,5 +1,11 @@
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(`
1
+ "use strict";var he=Object.create;var b=Object.defineProperty;var fe=Object.getOwnPropertyDescriptor;var de=Object.getOwnPropertyNames;var ye=Object.getPrototypeOf,Ce=Object.prototype.hasOwnProperty;var I=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),Ee=(n,e)=>{for(var t in e)b(n,t,{get:e[t],enumerable:!0})},Z=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of de(e))!Ce.call(n,o)&&o!==t&&b(n,o,{get:()=>e[o],enumerable:!(r=fe(e,o))||r.enumerable});return n};var q=(n,e,t)=>(t=n!=null?he(ye(n)):{},Z(e||!n||!n.__esModule?b(t,"default",{value:n,enumerable:!0}):t,n)),Pe=n=>Z(b({},"__esModule",{value:!0}),n);var Q=I((We,W)=>{function h(n,e){typeof e=="boolean"&&(e={forever:e}),this._originalTimeouts=JSON.parse(JSON.stringify(n)),this._timeouts=n,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))}W.exports=h;h.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)};h.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null};h.prototype.retry=function(n){if(this._timeout&&clearTimeout(this._timeout),!n)return!1;var e=new Date().getTime();if(n&&e-this._operationStart>=this._maxRetryTime)return this._errors.push(n),this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(n);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 r=this;return this._timer=setTimeout(function(){r._attempts++,r._operationTimeoutCb&&(r._timeout=setTimeout(function(){r._operationTimeoutCb(r._attempts)},r._operationTimeout),r._options.unref&&r._timeout.unref()),r._fn(r._attempts)},t),this._options.unref&&this._timer.unref(),!0};h.prototype.attempt=function(n,e){this._fn=n,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)};h.prototype.try=function(n){console.log("Using RetryOperation.try() is deprecated"),this.attempt(n)};h.prototype.start=function(n){console.log("Using RetryOperation.start() is deprecated"),this.attempt(n)};h.prototype.start=h.prototype.try;h.prototype.errors=function(){return this._errors};h.prototype.attempts=function(){return this._attempts};h.prototype.mainError=function(){if(this._errors.length===0)return null;for(var n={},e=null,t=0,r=0;r<this._errors.length;r++){var o=this._errors[r],i=o.message,s=(n[i]||0)+1;n[i]=s,s>=t&&(e=o,t=s)}return e}});var X=I(A=>{var Ae=Q();A.operation=function(n){var e=A.timeouts(n);return new Ae(e,{forever:n&&(n.forever||n.retries===1/0),unref:n&&n.unref,maxRetryTime:n&&n.maxRetryTime})};A.timeouts=function(n){if(n instanceof Array)return[].concat(n);var e={retries:10,factor:2,minTimeout:1*1e3,maxTimeout:1/0,randomize:!1};for(var t in n)e[t]=n[t];if(e.minTimeout>e.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var r=[],o=0;o<e.retries;o++)r.push(this.createTimeout(o,e));return n&&n.forever&&!r.length&&r.push(this.createTimeout(o,e)),r.sort(function(i,s){return i-s}),r};A.createTimeout=function(n,e){var t=e.randomize?Math.random()+1:1,r=Math.round(t*Math.max(e.minTimeout,1)*Math.pow(e.factor,n));return r=Math.min(r,e.maxTimeout),r};A.wrap=function(n,e,t){if(e instanceof Array&&(t=e,e=null),!t){t=[];for(var r in n)typeof n[r]=="function"&&t.push(r)}for(var o=0;o<t.length;o++){var i=t[o],s=n[i];n[i]=function(a){var p=A.operation(e),m=Array.prototype.slice.call(arguments,1),l=m.pop();m.push(function(u){p.retry(u)||(u&&(arguments[0]=p.mainError()),l.apply(this,arguments))}),p.attempt(function(){a.apply(n,m)})}.bind(n,s),n[i].options=e}}});var te=I((Xe,ee)=>{ee.exports=X()});var ze={};Ee(ze,{BatchEntry:()=>w,CANVAS_DRAFT_STATE:()=>ft,CANVAS_ENRICHMENT_TAG_PARAM:()=>Be,CANVAS_INTENT_TAG_PARAM:()=>Le,CANVAS_LOCALE_TAG_PARAM:()=>j,CANVAS_LOCALIZATION_SLOT:()=>U,CANVAS_LOCALIZATION_TYPE:()=>k,CANVAS_LOOP_PARAMETER:()=>H,CANVAS_LOOP_RESOURCE_PARAMETER:()=>z,CANVAS_LOOP_SLOT:()=>J,CANVAS_LOOP_TYPE:()=>G,CANVAS_PERSONALIZATION_PARAM:()=>D,CANVAS_PERSONALIZE_SLOT:()=>Ne,CANVAS_PERSONALIZE_TYPE:()=>Oe,CANVAS_PUBLISHED_STATE:()=>dt,CANVAS_TEST_SLOT:()=>$e,CANVAS_TEST_TYPE:()=>Se,CANVAS_TEST_VARIANT_PARAM:()=>F,CanvasClient:()=>_,CanvasClientError:()=>T,ChildEnhancerBuilder:()=>v,EnhancerBuilder:()=>S,UncachedCanvasClient:()=>V,UniqueBatchEntries:()=>O,bindParameter:()=>Y,bindParameters:()=>pe,compose:()=>Re,createBatchEnhancer:()=>ge,createEventBus:()=>Ue,createLimitPolicy:()=>M,enhance:()=>be,extractLocales:()=>ie,getChannelName:()=>K,getComponentPath:()=>g,isSystemComponentDefinition:()=>Me,localize:()=>Fe,mapSlotToPersonalizedVariations:()=>Ve,mapSlotToTestVariations:()=>ke,nullLimitPolicy:()=>C,subscribeToComposition:()=>De,walkComponentTree:()=>P});module.exports=Pe(ze);function P(n,e){let t=[{ancestorsAndSelf:[{component:n,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let r=t.pop();if(!r)continue;let o=r.ancestorsAndSelf[0],i=!0;e(o.component,r.ancestorsAndSelf,{replaceComponent:c=>{Object.assign(o.component,c),["parameters","variant","slots","data","_pattern","_patternError"].forEach(p=>{c[p]||delete o.component[p]})},removeComponent:()=>{let{parentSlot:c,parentSlotIndex:a}=r.ancestorsAndSelf[0],p=r.ancestorsAndSelf[1];if(c&&typeof a!="undefined")p.component.slots[c].splice(a,1);else throw new Error("Unable to delete composition.")},insertAfter:c=>{let a=Array.isArray(c)?c:[c],{parentSlot:p,parentSlotIndex:m}=r.ancestorsAndSelf[0],l=r.ancestorsAndSelf[1];if(p&&typeof m!="undefined")l.component.slots[p].splice(m+1,0,...a);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 c=Object.keys(s);for(let a=c.length-1;a>=0;a--){let p=c[a],m=s[p];for(let l=m.length-1;l>=0;l--)t.push({ancestorsAndSelf:[{component:m[l],parentSlot:p,parentSlotIndex:l},...r.ancestorsAndSelf]})}}}while(t.length>0)}function g(n){let e=[];for(let t=n.length-1;t>=0;t--){let{parentSlot:r,parentSlotIndex:o}=n[t];r&&o!==void 0&&e.push(`${r}[${o}]`)}return`.${e.join(".")}`}var O=class{constructor(e,t){this.groups=e.reduce((r,o)=>{var s;let i=t(o.args);return r[i]=(s=r[i])!=null?s:[],r[i].push(o),r},{})}resolveKey(e,t){this.groups[e].forEach(r=>r.resolve(t))}resolveRemaining(e){Object.keys(this.groups).forEach(t=>{this.groups[t].forEach(r=>{r.isCompleted||r.resolve(e)})})}};var v=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 r;return(r=this._paramMatches.find(o=>o.name&&o.name===e||o.type&&o.type===t.type||!o.type&&!o.name))==null?void 0:r.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},S=class{constructor(){this._componentIndex={};this._rootBuilder=new v}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 v,t(this._componentIndex[o])}),this}resolveParameterEnhancer(e,t,r){let o=this._componentIndex[e.type];if(o){let i=o.resolveParameterEnhancer(t,r);if(i)return i}return this._rootBuilder.resolveParameterEnhancer(t,r)}resolveComponentEnhancers(e){let t=this._rootBuilder.resolveComponentEnhancers(),r=this._componentIndex[e.type];if(r){t=new Map(t);for(let[o,i]of r.resolveComponentEnhancers())t.set(o,i)}return t}};var w=class{constructor(e,t,r){this._resolve=e;this._reject=t;this.args=r;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 ge({handleBatch:n,shouldQueue:e,limitPolicy:t}){let r=[];return{enhanceOne:async s=>{if(!e||e(s))return new Promise((c,a)=>{r.push(new w(c,a,s))})},completeAll:async()=>{if(r.length>0){try{await n(r)}catch(c){r.forEach(a=>a.reject(c))}if(r.some(c=>!c.isCompleted))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!")}let s=r.length;return r=[],s},limitPolicy:t}}var L=class extends Error{constructor(){super("Throttled function aborted"),this.name="AbortError"}};function N({limit:n,interval:e,strict:t}){if(!Number.isFinite(n))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 r=new Map,o=0,i=0;function s(){let m=Date.now();return m-o>e?(i=1,o=m,0):(i<n?i++:(o+=e,i=1),o-m)}let c=[];function a(){let m=Date.now();if(c.length<n)return c.push(m),0;let l=c.shift()+e;return m>=l?(c.push(m),0):(c.push(l),l-m)}let p=t?a:s;return m=>{let l=function(...u){if(!l.isEnabled)return(async()=>m.apply(this,u))();let d;return new Promise((f,y)=>{d=setTimeout(()=>{f(m.apply(this,u)),r.delete(d)},p()),r.set(d,y)})};return l.abort=()=>{for(let u of r.keys())clearTimeout(u),r.get(u)(new L);r.clear(),c.splice(0,c.length)},l.isEnabled=!0,l}}var re=q(te(),1),Te=new Set(["Failed to fetch","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Network request failed"]),$=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}},_e=(n,e,t)=>{let r=t.retries-(e-1);return n.attemptNumber=e,n.retriesLeft=r,n},ve=n=>Te.has(n),ne=n=>globalThis.DOMException===void 0?new Error(n):new DOMException(n);async function B(n,e){return new Promise((t,r)=>{e={onFailedAttempt(){},retries:10,...e};let o=re.default.operation(e);o.attempt(async i=>{try{t(await n(i))}catch(s){if(!(s instanceof Error)){r(new TypeError(`Non-error was thrown: "${s}". You should only throw errors.`));return}if(s instanceof $)o.stop(),r(s.originalError);else if(s instanceof TypeError&&!ve(s.message))o.stop(),r(s);else{_e(s,i,e);try{await e.onFailedAttempt(s)}catch(c){r(c);return}o.retry(s)||r(o.mainError())}}}),e.signal&&!e.signal.aborted&&e.signal.addEventListener("abort",()=>{o.stop();let i=e.signal.reason===void 0?ne("The operation was aborted."):e.signal.reason;r(i instanceof Error?i:ne(i))},{once:!0})})}function M({throttle:n={interval:1e3,limit:10},retry:e={retries:1,factor:1.66}}){let t=n?N(n):null;return function(o){let i=async()=>await o();if(t&&(i=t(i)),e){let s=i;i=()=>B(s,e)}return i()}}var C=async n=>await n();async function be({composition:n,enhancers:e,context:t,onErrors:r=o=>{throw new Error(o.map(i=>`${i.message}
2
+ ${typeof i.error=="object"&&"stack"in i.error?i.error.stack:i.error}`).join(`
3
3
 
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});
4
+ `))}}){let o=[],i=new Set,s=new Set;P(n,(a,p)=>{var l;Object.entries((l=a.parameters)!=null?l:{}).forEach(([u,d])=>{let f=e.resolveParameterEnhancer(a,u,d);f&&(s.add(f),o.push(xe(a,p,u,d,f,t)))});let m=e.resolveComponentEnhancers(a);o.push(we(a,p,m,t)),i.add(m)}),o.push(...Array.from(i).flatMap(a=>Array.from(a).map(async([,p])=>{var m;try{p.completeAll&&await((m=p.limitPolicy)!=null?m:C)(()=>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 a=>{var p;try{a.completeAll&&await((p=a.limitPolicy)!=null?p:C)(()=>a.completeAll())}catch(m){return{error:m,message:"Batch parameter enhancer failed. Individual failed parameters should receive their own rejections."}}}));let c=(await Promise.all(o)).flatMap(a=>Array.isArray(a)?a:[a]).filter(a=>a);c.length&&r(c)}async function we(n,e,t,r){return t.size&&(n.data={}),await Promise.all(Array.from(t).map(async([o,i])=>{var s;try{let a=await(i.completeAll?C:(s=i.limitPolicy)!=null?s:C)(async()=>i.enhanceOne({component:n,context:r}));a!=null&&(n.data[o]=a)}catch(c){let a=`Component ${g(e)} (type: ${n.type}): data.${o} enhancer threw exception. Data key will not be present.`;return delete n.data[o],{message:a,error:c}}}))}async function xe(n,e,t,r,o,i){var s;try{let a=await(o.completeAll?C:(s=o.limitPolicy)!=null?s:C)(async()=>o.enhanceOne({parameter:r,parameterName:t,component:n,context:i}));a===null?delete n.parameters[t]:typeof a=="undefined"?n.parameters[t]={...r,value:r.value}:n.parameters[t]={...r,value:a}}catch(c){let a=`Component ${g(e)} (type: ${n.type}): enhancing parameter ${t} (type: ${r.type}) threw exception. Parameter will be removed.`;return delete n.parameters[t],{message:a,error:c}}}var Re=(n,...e)=>({enhanceOne:r=>{let o="enhanceOne"in n?n.enhanceOne(r):n(r);for(let i of e){let s=Ie(o)?o:Promise.resolve(o),c="enhanceOne"in i?i.enhanceOne:i;o=s.then(a=>c({...r,parameter:{type:r.parameter.type,value:a}}))}return o},completeAll:async()=>{var r,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 n?(r=n.completeAll)==null?void 0:r.call(n):0)!=null?o:0}});function Ie(n){return!!n&&(typeof n=="object"||typeof n=="function")&&typeof n.then=="function"}var T=class extends Error{constructor(t,r,o,i,s,c){super(`${t}
5
+ ${i}${s?" "+s:""} (${r} ${o}${c?` Request ID: ${c}`:""})`);this.errorMessage=t;this.fetchMethod=r;this.fetchUri=o;this.statusCode=i;this.statusText=s;this.requestId=c;Object.setPrototypeOf(this,T.prototype)}},_=class{constructor(e){var r,o,i,s,c,a;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:(r=e.apiHost)!=null?r:"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:M({}),bypassCache:(a=e.bypassCache)!=null?a:!1}}async getCompositionList(e){let{projectId:t}=this.options,r=this.createUrl("/api/v1/canvas",{...e,projectId:t});return await this.apiClient(r)}async getCompositionBySlug(e){let{projectId:t}=this.options,r=this.createUrl("/api/v1/canvas",{...e,projectId:t});return await this.apiClient(r)}async getCompositionById(e){let{projectId:t}=this.options,r=this.createUrl("/api/v1/canvas",{...e,projectId:t});return await this.apiClient(r)}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:r}=this.options;await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:r}),expectNoContent:!0})}async getComponentDefinitions(e){let{projectId:t}=this.options,r=this.createUrl("/api/v1/canvas-definitions",{...e,projectId:t});return await this.apiClient(r)}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 r=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`},o=await this.options.fetch(e.toString(),{...t,headers:{"x-bypass-cache":this.options.bypassCache.toString(),...t==null?void 0:t.headers,...r}});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 T(s,(i=t==null?void 0:t.method)!=null?i:"GET",e.toString(),o.status,o.statusText,_.getRequestId(o))}return t!=null&&t.expectNoContent?null:await o.json()})}createUrl(e,t){let r=new URL(`${this.options.apiHost}${e}`);return Object.entries(t!=null?t:{}).forEach(([o,i])=>{var s;typeof i!==void 0&&i!==null&&r.searchParams.append(o,(s=i==null?void 0:i.toString())!=null?s:"")}),r}static getRequestId(e){let t=e.headers.get("apigw-requestid");if(t)return t}},V=class extends _{constructor(e){super({...e,bypassCache:!0})}};var Oe="$personalization",Se="$test",k="$localization",Le="intentTag",j="locale",Ne="pz",$e="test",U="localized",ft=0,dt=64,D="$pzCrit",F="$tstVrnt",Be="$enr",G="$loop",z="$loopResource",H="$loopBinding",J="body";var Me=n=>n.startsWith("$");function Ve(n){return n?n.map((e,t)=>{var i,s;let r=(s=(i=e.parameters)==null?void 0:i[D])==null?void 0:s.value,o=(r==null?void 0:r.name)||`pz-${t}-${e.type}`;return{...e,id:o,pz:r}}):[]}function ke(n){return n?n.map((e,t)=>{var i,s,c;let r=(s=(i=e.parameters)==null?void 0:i[F])==null?void 0:s.value,o=(c=r==null?void 0:r.id)!=null?c:"testId"in e?e.testId:`ab-${t}-${e.type}`;return{...e,id:o}}):[]}var oe="https://js.pusher.com/7.0.3/pusher.min.js";async function je(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((n,e)=>{let t=setTimeout(()=>{window.Pusher&&n(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${oe}"><\/script> manually.`)},5e3),r=document.createElement("script");r.src=oe,r.addEventListener("load",()=>{clearTimeout(t),n(window.Pusher)}),document.head.appendChild(r)})}async function Ue(){let n=await je();if(!n)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let t=new n("7b5f5abd160fea549ffe",{cluster:"mt1"});t.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:r=>{let o=t.subscribe(r);return{unsubscribe:()=>t.unsubscribe(r),addEventHandler:(i,s)=>(o.bind(i,s),()=>o.unbind(i,s))}}}}return e}function K(n,e,t){return`${n}.${e}@${t}`}function De({projectId:n,compositionId:e,compositionState:t=0,eventBus:{subscribe:r},callback:o,event:i="updated"}){let s=K(n,e,t),c=r(s),a=c.addEventHandler(i,o);return()=>{a(),c.unsubscribe()}}function ie({component:n}){var r;let e={},t=(r=n.slots)==null?void 0:r[U];return t==null||t.forEach(o=>{var s;let i=(s=o.parameters)==null?void 0:s[j];(i==null?void 0:i.value)&&typeof i.value=="string"&&(e[i.value]=e[i.value]||[],e[i.value].push(o))}),e}function Fe({composition:n,locale:e}){P(n,(t,r,o)=>{if(t.type===k){let i=ie({component:t}),s=typeof e=="string"?e:e({component:t,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()}})}var x=require("json-pointer");function ae(n,e){if(typeof n.pointer=="string")return se(e,n.pointer);let t={};return Object.entries(n.pointer).forEach(([r,o])=>{(0,x.set)(t,r,se(e,o))}),t}function se(n,e){try{return(0,x.get)(n,e)}catch(t){throw new Error(`Unable to resolve resource pointer '${e}': ${t.message}
6
+
7
+ Resources:
8
+ ${JSON.stringify(n,null,2)}`)}}function Y(n,e){if(!(n!=null&&n.binding))return{bound:!1};switch(n.binding.syntax){case"jptr":return{bound:!0,value:ae(n.binding,e)};default:throw new Error(`Unsupported binding syntax '${n.binding.syntax}'`)}}var ce=q(require("rfdc"));var Ge=(0,ce.default)();function pe(n,e,t){let{throwErrors:r=!0,expandLoops:o=!0,preserveBindings:i=!1}=t||{},s=Ge(n),c=!1,a=[];if(P(s,(p,m,l)=>{var u,d;if(!!p.parameters&&(Object.entries(p.parameters).forEach(([f,y])=>{try{let E=Y(y,e);E.bound&&(c=!0,y.value=E.value,i||delete y.binding)}catch(E){a.push(new Error(`Failed to bind parameter ${f} in component ${g(m)}: ${E.message}`)),delete p.parameters[f]}}),p.type===G&&(l.stopProcessingDescendants(),o))){let f=(d=(u=p.slots)==null?void 0:u[J])!=null?d:[],y=p.parameters[H].value;if(!Array.isArray(y)){a.push(new Error(`Failed to bind loop component ${g(m)}: loop is not bound to an array of data`));return}let E={...t,throwErrors:!1};y.reverse().forEach(me=>{let le={...e,[p.parameters[z].value]:me};f.forEach(ue=>{let R=pe(ue,le,E);R.errors.length>0?a.push(...R.errors):l.insertAfter(R.result)})}),l.removeComponent()}}),r&&a.length>0)throw new Error(`${a.length} error${a.length!==1?"s":""} occurred while binding parameters to resources.
9
+
10
+ ${a.map(p=>p.message).join(`
11
+ `)}`);return{hasBindings:c,errors:a,result:s}}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_LOOP_PARAMETER,CANVAS_LOOP_RESOURCE_PARAMETER,CANVAS_LOOP_SLOT,CANVAS_LOOP_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,bindParameter,bindParameters,compose,createBatchEnhancer,createEventBus,createLimitPolicy,enhance,extractLocales,getChannelName,getComponentPath,isSystemComponentDefinition,localize,mapSlotToPersonalizedVariations,mapSlotToTestVariations,nullLimitPolicy,subscribeToComposition,walkComponentTree});
package/dist/index.mjs CHANGED
@@ -1,4 +1 @@
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
- ${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,U as J,V as K,W as L,X as M,Y as N,Z as O,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-BJ45Y4JT.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,D as CANVAS_LOOP_PARAMETER,C as CANVAS_LOOP_RESOURCE_PARAMETER,E as CANVAS_LOOP_SLOT,B as CANVAS_LOOP_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,N as bindParameter,O as bindParameters,k as compose,g as createBatchEnhancer,I as createEventBus,h as createLimitPolicy,j as enhance,L as extractLocales,J as getChannelName,b as getComponentPath,F as isSystemComponentDefinition,M as localize,G as mapSlotToPersonalizedVariations,H as mapSlotToTestVariations,i as nullLimitPolicy,K as subscribeToComposition,a as walkComponentTree};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas",
3
- "version": "16.2.1-alpha.106+a3eb5a014",
3
+ "version": "16.2.1-nuxt.249+6d2287689",
4
4
  "description": "Common functionality and types for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -47,18 +47,20 @@
47
47
  "update-openapi": "tsx ./scripts/update-openapi.cts"
48
48
  },
49
49
  "devDependencies": {
50
+ "@types/json-pointer": "^1.0.31",
50
51
  "@types/retry": "0.12.1",
51
52
  "@types/yargs": "17.0.10",
52
- "@uniformdev/cli": "^16.2.1-alpha.106+a3eb5a014",
53
- "pusher-js": "7.0.6",
53
+ "@uniformdev/cli": "^16.2.1-nuxt.249+6d2287689",
54
+ "p-limit": "4.0.0",
55
+ "p-retry": "5.1.1",
56
+ "p-throttle": "5.0.0",
57
+ "pusher-js": "7.2.0",
54
58
  "yargs": "17.5.1"
55
59
  },
56
60
  "dependencies": {
57
- "@uniformdev/context": "^16.2.1-alpha.106+a3eb5a014",
58
- "isomorphic-unfetch": "^3.1.0",
59
- "p-limit": "^3.1.0",
60
- "p-retry": "^4.6.2",
61
- "p-throttle": "^4.1.1"
61
+ "@uniformdev/context": "^16.2.1-nuxt.249+6d2287689",
62
+ "json-pointer": "^0.6.2",
63
+ "rfdc": "^1.3.0"
62
64
  },
63
65
  "files": [
64
66
  "/dist"
@@ -66,5 +68,5 @@
66
68
  "publishConfig": {
67
69
  "access": "public"
68
70
  },
69
- "gitHead": "a3eb5a01423196eee3cb0fbb2a4e9372b420f160"
71
+ "gitHead": "6d2287689097cb256d17483ea3726d4bb87b2fa6"
70
72
  }
@@ -1,2 +0,0 @@
1
- var h=Object.create;var m=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var R=(i=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(i,{get:(t,e)=>(typeof require!="undefined"?require:t)[e]}):i)(function(i){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+i+'" is not supported')});var I=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports);var A=(i,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of d(t))!y.call(i,n)&&n!==e&&m(i,n,{get:()=>t[n],enumerable:!(o=f(t,n))||o.enumerable});return i};var g=(i,t,e)=>(e=i!=null?h(C(i)):{},A(t||!i||!i.__esModule?m(e,"default",{value:i,enumerable:!0}):e,i));import P from"p-throttle";import T from"p-retry";function u({throttle:i={interval:1e3,limit:10},retry:t={retries:1,factor:1.66}}){let e=i?P(i):null;return function(n){let r=async()=>await n();if(e&&(r=e(r)),t){let s=r;r=()=>T(s,t)}return r()}}var L=async i=>await i();var c=class extends Error{constructor(e,o,n,r,s,a){super(`${e}
2
- ${r}${s?" "+s:""} (${o} ${n}${a?` Request ID: ${a}`:""})`);this.errorMessage=e;this.fetchMethod=o;this.fetchUri=n;this.statusCode=r;this.statusText=s;this.requestId=a;Object.setPrototypeOf(this,c.prototype)}},l=class{constructor(t){var o,n,r,s,a;if(!t.apiKey&&!t.bearerToken)throw new Error("You must provide an API key or a bearer token");let e=t.fetch;if(!e)if(typeof window!="undefined")e=window.fetch.bind(window);else if(typeof fetch!="undefined")e=fetch;else throw new Error("You must provide or polyfill a fetch implementation when not in a browser");this.options={...t,fetch:e,apiHost:(o=t.apiHost)!=null?o:"https://uniform.app",apiKey:(n=t.apiKey)!=null?n:null,projectId:(r=t.projectId)!=null?r:null,bearerToken:(s=t.bearerToken)!=null?s:null,limitPolicy:(a=t.limitPolicy)!=null?a:u({})}}async getCompositionList(t){let{projectId:e}=this.options,o=this.createUrl("/api/v1/canvas",{...t,projectId:e});return await this.apiClient(o)}async getCompositionBySlug(t){let{projectId:e}=this.options,o=this.createUrl("/api/v1/canvas",{...t,projectId:e});return await this.apiClient(o)}async getCompositionById(t){let{projectId:e}=this.options,o=this.createUrl("/api/v1/canvas",{...t,projectId:e});return await this.apiClient(o)}async updateComposition(t){let e=this.createUrl("/api/v1/canvas");await this.apiClient(e,{method:"PUT",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(t){let e=this.createUrl("/api/v1/canvas");await this.apiClient(e,{method:"DELETE",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async getComponentDefinitions(t){let{projectId:e}=this.options,o=this.createUrl("/api/v1/canvas-definitions",{...t,projectId:e});return await this.apiClient(o)}async updateComponentDefinition(t){let e=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(e,{method:"PUT",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(t){let e=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(e,{method:"DELETE",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(t,e){return this.options.limitPolicy(async()=>{var r;let o=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`},n=await this.options.fetch(t.toString(),{...e,headers:{...e==null?void 0:e.headers,...o}});if(!n.ok){let s="";try{let a=await n.text();try{let p=JSON.parse(a);p.errorMessage?s=Array.isArray(p.errorMessage)?p.errorMessage.join(", "):p.errorMessage:s=a}catch(p){s=a}}catch(a){s="General error"}throw new c(s,(r=e==null?void 0:e.method)!=null?r:"GET",t.toString(),n.status,n.statusText,l.getRequestId(n))}return e!=null&&e.expectNoContent?null:await n.json()})}createUrl(t,e){let o=new URL(`${this.options.apiHost}${t}`);return Object.entries(e!=null?e:{}).forEach(([n,r])=>{var s;typeof r!==void 0&&r!==null&&o.searchParams.append(n,(s=r==null?void 0:r.toString())!=null?s:"")}),o}static getRequestId(t){let e=t.headers.get("x-nf-request-id");if(e)return e}};var U="$personalization",V="$test",D="$localization",G="intentTag",v="locale",k="pz",$="test",M="localized",H=0,z=64,F="$pzCrit",K="$tstVrnt",J="$enr";export{R as a,I as b,g as c,u as d,L as e,c as f,l as g,U as h,V as i,D as j,G as k,v as l,k as m,$ as n,M as o,H as p,z as q,F as r,K as s,J as t};