@uniformdev/canvas 17.0.0 → 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.
@@ -125,6 +125,12 @@ interface external$1 {
125
125
  "application/json": external$1["swagger.yml"]["components"]["schemas"]["Error"];
126
126
  };
127
127
  };
128
+ /** Resource not found */
129
+ NotFoundError: {
130
+ content: {
131
+ "application/json": external$1["swagger.yml"]["components"]["schemas"]["Error"];
132
+ };
133
+ };
128
134
  /** Too many requests in allowed time period */
129
135
  RateLimitError: unknown;
130
136
  /** Execution error occurred */
@@ -289,6 +295,14 @@ interface external$1 {
289
295
  * @enum {string}
290
296
  */
291
297
  syntax: "jptr";
298
+ /**
299
+ * @description Whether the binding should cause an error if it cannot be resolved.
300
+ * If true, and the binding cannot be resolved, an error will be returned by the binding process.
301
+ * If false, and the binding cannot be resolved, the parameter will be removed from the bound composition.
302
+ *
303
+ * @default false
304
+ */
305
+ required?: boolean;
292
306
  };
293
307
  /** @description Defines the shape of a component instance served by the composition API. */
294
308
  ComponentInstance: {
@@ -304,6 +318,8 @@ interface external$1 {
304
318
  slots?: {
305
319
  [key: string]: external$1["uniform-canvas-types.swagger.yml"]["components"]["schemas"]["ComponentInstance"][];
306
320
  };
321
+ /** @description Unique identifier of the component within the composition. This is not set unless specifically requested via `withComponentIDs` API parameter. */
322
+ _id?: string;
307
323
  /** @description Indicates this component instance should be sourced from a pattern library pattern. */
308
324
  _pattern?: string;
309
325
  /**
@@ -496,6 +512,14 @@ interface components$1 {
496
512
  * @enum {string}
497
513
  */
498
514
  syntax: "jptr";
515
+ /**
516
+ * @description Whether the binding should cause an error if it cannot be resolved.
517
+ * If true, and the binding cannot be resolved, an error will be returned by the binding process.
518
+ * If false, and the binding cannot be resolved, the parameter will be removed from the bound composition.
519
+ *
520
+ * @default false
521
+ */
522
+ required?: boolean;
499
523
  };
500
524
  /** @description Defines the shape of a component instance served by the composition API. */
501
525
  ComponentInstance: {
@@ -511,6 +535,8 @@ interface components$1 {
511
535
  slots?: {
512
536
  [key: string]: components$1["schemas"]["ComponentInstance"][];
513
537
  };
538
+ /** @description Unique identifier of the component within the composition. This is not set unless specifically requested via `withComponentIDs` API parameter. */
539
+ _id?: string;
514
540
  /** @description Indicates this component instance should be sourced from a pattern library pattern. */
515
541
  _pattern?: string;
516
542
  /**
@@ -605,7 +631,7 @@ interface paths {
605
631
  /** Max number of records to return */
606
632
  limit?: number;
607
633
  /**
608
- * Signals an enhancer proxy to skip processing enhancements to the data and return raw data only.
634
+ * @deprecated Signals an enhancer proxy to skip processing enhancements to the data and return raw data only.
609
635
  * This improves performance if you do not require enhanced component data.
610
636
  * If calling the Canvas API directly with no enhancer proxy, this has no effect.
611
637
  */
@@ -616,6 +642,11 @@ interface paths {
616
642
  * data embedded into it, and serialize the pattern data separately.
617
643
  */
618
644
  skipPatternResolution?: boolean;
645
+ /**
646
+ * If true the `_id` unique identifier of each non-root component will be part of the response data.
647
+ * If false, the `_id` will not be present in the API response.
648
+ */
649
+ withComponentIDs?: boolean;
619
650
  };
620
651
  };
621
652
  responses: {
@@ -665,6 +696,8 @@ interface paths {
665
696
  * @default false
666
697
  */
667
698
  pattern?: boolean;
699
+ resources?: components["schemas"]["CompositionResourceDefinitions"];
700
+ variables?: components["schemas"]["CompositionVariableDefinitions"];
668
701
  /** @description Ignored if present */
669
702
  created?: string;
670
703
  /** @description Ignored if present */
@@ -734,11 +767,53 @@ interface components {
734
767
  modified: string;
735
768
  /** @description Whether this composition is a pattern (can be referenced by other compositions, not treated as a composition) */
736
769
  pattern: boolean;
770
+ resources?: components["schemas"]["CompositionResourceDefinitions"];
737
771
  composition: external["uniform-canvas-types.swagger.yml"]["components"]["schemas"]["RootComponentInstance"];
772
+ variables?: components["schemas"]["CompositionVariableDefinitions"];
738
773
  };
739
774
  CompositionListResponse: {
740
775
  compositions: components["schemas"]["CompositionApiResponse"][];
741
776
  };
777
+ /**
778
+ * @deprecated
779
+ * @description Variables defined for this composition.
780
+ */
781
+ CompositionVariableDefinitions: {
782
+ [key: string]: components["schemas"]["CompositionVariable"];
783
+ };
784
+ /**
785
+ * @deprecated
786
+ * @description Defines a variable value that can be used in resources and bindings.
787
+ */
788
+ CompositionVariable: {
789
+ /**
790
+ * @description Whether the variable must have a value when bound to.
791
+ * If true, binding a composition without this variable set will return an error.
792
+ * If false, binding a composition without this variable set will use the default value instead.
793
+ */
794
+ required: boolean;
795
+ /** @description The default value of the variable, used when binding for editing or when an optional variable value is not provided. */
796
+ default: string;
797
+ };
798
+ /**
799
+ * @deprecated
800
+ * @description Resource definitions attached to this composition. The property name is the key of the resource in the resource document.
801
+ */
802
+ CompositionResourceDefinitions: {
803
+ [key: string]: components["schemas"]["CompositionResourceDefinition"];
804
+ };
805
+ /**
806
+ * @deprecated
807
+ * @description Resource definition attached to this composition
808
+ */
809
+ CompositionResourceDefinition: {
810
+ /** @description Integration that provides this resource */
811
+ type: string;
812
+ /** @description Type-specific data to configure resource */
813
+ data: {
814
+ [key: string]: unknown;
815
+ };
816
+ };
742
817
  };
743
818
  }
744
819
  interface external {
@@ -770,6 +845,12 @@ interface external {
770
845
  "application/json": external["swagger.yml"]["components"]["schemas"]["Error"];
771
846
  };
772
847
  };
848
+ /** Resource not found */
849
+ NotFoundError: {
850
+ content: {
851
+ "application/json": external["swagger.yml"]["components"]["schemas"]["Error"];
852
+ };
853
+ };
773
854
  /** Too many requests in allowed time period */
774
855
  RateLimitError: unknown;
775
856
  /** Execution error occurred */
@@ -934,6 +1015,14 @@ interface external {
934
1015
  * @enum {string}
935
1016
  */
936
1017
  syntax: "jptr";
1018
+ /**
1019
+ * @description Whether the binding should cause an error if it cannot be resolved.
1020
+ * If true, and the binding cannot be resolved, an error will be returned by the binding process.
1021
+ * If false, and the binding cannot be resolved, the parameter will be removed from the bound composition.
1022
+ *
1023
+ * @default false
1024
+ */
1025
+ required?: boolean;
937
1026
  };
938
1027
  /** @description Defines the shape of a component instance served by the composition API. */
939
1028
  ComponentInstance: {
@@ -949,6 +1038,8 @@ interface external {
949
1038
  slots?: {
950
1039
  [key: string]: external["uniform-canvas-types.swagger.yml"]["components"]["schemas"]["ComponentInstance"][];
951
1040
  };
1041
+ /** @description Unique identifier of the component within the composition. This is not set unless specifically requested via `withComponentIDs` API parameter. */
1042
+ _id?: string;
952
1043
  /** @description Indicates this component instance should be sourced from a pattern library pattern. */
953
1044
  _pattern?: string;
954
1045
  /**
@@ -1015,6 +1106,14 @@ declare type ComponentParameter<TValue = unknown> = Omit<SharedComponents['Compo
1015
1106
  };
1016
1107
  /** Defines a binding from a resource data value to a component parameter value. */
1017
1108
  declare type ComponentParameterBinding = SharedComponents['ComponentParameterBinding'];
1109
+ /** Variables defined for this composition. */
1110
+ declare type CompositionVariableDefinitions = Components['CompositionVariableDefinitions'];
1111
+ /** Defines a variable value that can be used in resources and bindings. */
1112
+ declare type CompositionVariable = Components['CompositionVariable'];
1113
+ /** Defines the shape of a resource bound to a composition */
1114
+ declare type CompositionResourceDefinitions = components['schemas']['CompositionResourceDefinitions'];
1115
+ /** Defines the shape of a resource bound to a composition */
1116
+ declare type CompositionResourceDefinition = components['schemas']['CompositionResourceDefinition'];
1018
1117
  /** Defines the shape of a component instance served by the composition API. */
1019
1118
  declare type ComponentInstance = SharedComponents['ComponentInstance'] & {
1020
1119
  /** Data for the component instance, provided by a component enhancer. Never set in unenhanced data. */
@@ -1053,4 +1152,4 @@ declare global {
1053
1152
  */
1054
1153
  declare function createEventBus(): Promise<PreviewEventBus | undefined>;
1055
1154
 
1056
- export { CanvasDefinitions as A, ChannelSubscription as B, ComponentInstance as C, createEventBus as D, 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 };
1155
+ export { CompositionVariableDefinitions as A, CompositionVariable as B, ComponentInstance as C, CompositionResourceDefinitions as D, CompositionResourceDefinition as E, CanvasDefinitions as F, ChannelSubscription as G, createEventBus as H, 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-aea3860f.js';
2
- export { A as CanvasDefinitions, B 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, D as createEventBus } from './createEventBus-aea3860f.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';
@@ -268,8 +268,10 @@ declare type CanvasClientOptions = {
268
268
  * Default: retry 3x on failures with exponential backoff, up to 10 requests per second.
269
269
  * Use createLimitPolicy() to help creating a policy. */
270
270
  limitPolicy?: LimitPolicy;
271
- /** Specify whether caching is disabled. */
271
+ /** Specify whether CDN caching is disabled. */
272
272
  bypassCache?: boolean;
273
+ /** @deprecated do not use */
274
+ experiment14?: boolean;
273
275
  };
274
276
  declare class CanvasClientError extends Error {
275
277
  errorMessage: string;
@@ -283,6 +285,7 @@ declare class CanvasClientError extends Error {
283
285
  declare class CanvasClient {
284
286
  private options;
285
287
  constructor(options: CanvasClientOptions);
288
+ private get canvasUrl();
286
289
  /** Fetches lists of Canvas compositions, optionally by type */
287
290
  getCompositionList(options?: Omit<CompositionGetParameters, 'projectId'>): Promise<{
288
291
  compositions: {
@@ -291,6 +294,14 @@ declare class CanvasClient {
291
294
  created: string;
292
295
  modified: string;
293
296
  pattern: boolean;
297
+ resources?: {
298
+ [key: string]: {
299
+ type: string;
300
+ data: {
301
+ [key: string]: unknown;
302
+ };
303
+ };
304
+ } | undefined;
294
305
  composition: {
295
306
  type: string;
296
307
  parameters?: {
@@ -302,6 +313,7 @@ declare class CanvasClient {
302
313
  [key: string]: string;
303
314
  };
304
315
  syntax: "jptr";
316
+ required?: boolean | undefined;
305
317
  } | undefined;
306
318
  };
307
319
  } | undefined;
@@ -318,6 +330,7 @@ declare class CanvasClient {
318
330
  [key: string]: string;
319
331
  };
320
332
  syntax: "jptr";
333
+ required?: boolean | undefined;
321
334
  } | undefined;
322
335
  };
323
336
  } | undefined;
@@ -325,6 +338,7 @@ declare class CanvasClient {
325
338
  slots?: {
326
339
  [key: string]: any[];
327
340
  } | undefined;
341
+ _id?: string | undefined;
328
342
  _pattern?: string | undefined;
329
343
  _patternError?: "NOTFOUND" | "CYCLIC" | undefined;
330
344
  }[];
@@ -333,15 +347,29 @@ declare class CanvasClient {
333
347
  _slug?: string | null | undefined;
334
348
  _name: string;
335
349
  };
350
+ variables?: {
351
+ [key: string]: {
352
+ required: boolean;
353
+ default: string;
354
+ };
355
+ } | undefined;
336
356
  }[];
337
357
  }>;
338
358
  /** Fetches a Canvas composition by string name (slug) */
339
- getCompositionBySlug(options: Pick<CompositionGetParameters, 'slug' | 'state' | 'skipEnhance' | 'skipPatternResolution'>): Promise<{
359
+ getCompositionBySlug(options: Pick<CompositionGetParameters, 'slug' | 'state' | 'skipEnhance' | 'skipPatternResolution' | 'withComponentIDs'>): Promise<{
340
360
  state: number;
341
361
  projectId: string;
342
362
  created: string;
343
363
  modified: string;
344
364
  pattern: boolean;
365
+ resources?: {
366
+ [key: string]: {
367
+ type: string;
368
+ data: {
369
+ [key: string]: unknown;
370
+ };
371
+ };
372
+ } | undefined;
345
373
  composition: {
346
374
  type: string;
347
375
  parameters?: {
@@ -353,6 +381,7 @@ declare class CanvasClient {
353
381
  [key: string]: string;
354
382
  };
355
383
  syntax: "jptr";
384
+ required?: boolean | undefined;
356
385
  } | undefined;
357
386
  };
358
387
  } | undefined;
@@ -369,6 +398,7 @@ declare class CanvasClient {
369
398
  [key: string]: string;
370
399
  };
371
400
  syntax: "jptr";
401
+ required?: boolean | undefined;
372
402
  } | undefined;
373
403
  };
374
404
  } | undefined;
@@ -376,6 +406,7 @@ declare class CanvasClient {
376
406
  slots?: {
377
407
  [key: string]: any[];
378
408
  } | undefined;
409
+ _id?: string | undefined;
379
410
  _pattern?: string | undefined;
380
411
  _patternError?: "NOTFOUND" | "CYCLIC" | undefined;
381
412
  }[];
@@ -384,14 +415,28 @@ declare class CanvasClient {
384
415
  _slug?: string | null | undefined;
385
416
  _name: string;
386
417
  };
418
+ variables?: {
419
+ [key: string]: {
420
+ required: boolean;
421
+ default: string;
422
+ };
423
+ } | undefined;
387
424
  }>;
388
425
  /** Fetches a Canvas composition by its public UUID */
389
- getCompositionById(options: Pick<CompositionGetParameters, 'compositionId' | 'state' | 'skipEnhance' | 'skipPatternResolution'>): Promise<{
426
+ getCompositionById(options: Pick<CompositionGetParameters, 'compositionId' | 'state' | 'skipEnhance' | 'skipPatternResolution' | 'withComponentIDs'>): Promise<{
390
427
  state: number;
391
428
  projectId: string;
392
429
  created: string;
393
430
  modified: string;
394
431
  pattern: boolean;
432
+ resources?: {
433
+ [key: string]: {
434
+ type: string;
435
+ data: {
436
+ [key: string]: unknown;
437
+ };
438
+ };
439
+ } | undefined;
395
440
  composition: {
396
441
  type: string;
397
442
  parameters?: {
@@ -403,6 +448,7 @@ declare class CanvasClient {
403
448
  [key: string]: string;
404
449
  };
405
450
  syntax: "jptr";
451
+ required?: boolean | undefined;
406
452
  } | undefined;
407
453
  };
408
454
  } | undefined;
@@ -419,6 +465,7 @@ declare class CanvasClient {
419
465
  [key: string]: string;
420
466
  };
421
467
  syntax: "jptr";
468
+ required?: boolean | undefined;
422
469
  } | undefined;
423
470
  };
424
471
  } | undefined;
@@ -426,6 +473,7 @@ declare class CanvasClient {
426
473
  slots?: {
427
474
  [key: string]: any[];
428
475
  } | undefined;
476
+ _id?: string | undefined;
429
477
  _pattern?: string | undefined;
430
478
  _patternError?: "NOTFOUND" | "CYCLIC" | undefined;
431
479
  }[];
@@ -434,6 +482,12 @@ declare class CanvasClient {
434
482
  _slug?: string | null | undefined;
435
483
  _name: string;
436
484
  };
485
+ variables?: {
486
+ [key: string]: {
487
+ required: boolean;
488
+ default: string;
489
+ };
490
+ } | undefined;
437
491
  }>;
438
492
  /** Updates or creates a Canvas component definition */
439
493
  updateComposition(body: Omit<CompositionPutParameters, 'projectId'>): Promise<void>;
@@ -470,7 +524,7 @@ declare class CanvasClient {
470
524
  }[] | undefined;
471
525
  slugSettings?: {
472
526
  required?: "no" | "yes" | "disabled" | undefined;
473
- unique?: "global" | "no" | "local" | undefined;
527
+ unique?: "no" | "local" | "global" | undefined;
474
528
  regularExpression?: string | undefined;
475
529
  regularExpressionMessage?: string | undefined;
476
530
  } | undefined;
@@ -485,6 +539,7 @@ declare class CanvasClient {
485
539
  [key: string]: string;
486
540
  };
487
541
  syntax: "jptr";
542
+ required?: boolean | undefined;
488
543
  } | undefined;
489
544
  };
490
545
  } | undefined;
@@ -492,6 +547,7 @@ declare class CanvasClient {
492
547
  slots?: {
493
548
  [key: string]: any[];
494
549
  } | undefined;
550
+ _id?: string | undefined;
495
551
  _pattern?: string | undefined;
496
552
  _patternError?: "NOTFOUND" | "CYCLIC" | undefined;
497
553
  } | null | undefined;
package/dist/index.esm.js CHANGED
@@ -1 +1 @@
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-VQFPUXRX.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};
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 Y=Object.create;var A=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var ee=Object.getPrototypeOf,te=Object.prototype.hasOwnProperty;var w=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),ne=(r,e)=>{for(var t in e)A(r,t,{get:e[t],enumerable:!0})},U=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of X(e))!te.call(r,o)&&o!==t&&A(r,o,{get:()=>e[o],enumerable:!(n=Q(e,o))||n.enumerable});return r};var re=(r,e,t)=>(t=r!=null?Y(ee(r)):{},U(e||!r||!r.__esModule?A(t,"default",{value:r,enumerable:!0}):t,r)),oe=r=>U(A({},"__esModule",{value:!0}),r);var F=w((Ve,j)=>{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))}j.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 G=w(d=>{var se=F();d.operation=function(r){var e=d.timeouts(r);return new se(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 m=d.operation(e),p=Array.prototype.slice.call(arguments,1),l=p.pop();p.push(function(h){m.retry(h)||(h&&(arguments[0]=m.mainError()),l.apply(this,arguments))}),m.attempt(function(){c.apply(r,p)})}.bind(r,s),r[i].options=e}}});var H=w((Be,z)=>{z.exports=G()});var Re={};ne(Re,{BatchEntry:()=>v,CANVAS_DRAFT_STATE:()=>Xe,CANVAS_ENRICHMENT_TAG_PARAM:()=>ge,CANVAS_INTENT_TAG_PARAM:()=>Ce,CANVAS_LOCALE_TAG_PARAM:()=>M,CANVAS_LOCALIZATION_SLOT:()=>V,CANVAS_LOCALIZATION_TYPE:()=>k,CANVAS_PERSONALIZATION_PARAM:()=>$,CANVAS_PERSONALIZE_SLOT:()=>Ee,CANVAS_PERSONALIZE_TYPE:()=>de,CANVAS_PUBLISHED_STATE:()=>et,CANVAS_TEST_SLOT:()=>Te,CANVAS_TEST_TYPE:()=>ye,CANVAS_TEST_VARIANT_PARAM:()=>B,CanvasClient:()=>E,CanvasClientError:()=>C,ChildEnhancerBuilder:()=>P,EnhancerBuilder:()=>b,UncachedCanvasClient:()=>L,UniqueBatchEntries:()=>x,compose:()=>he,createBatchEnhancer:()=>ie,createEventBus:()=>we,createLimitPolicy:()=>N,enhance:()=>me,extractLocales:()=>J,getChannelName:()=>D,getComponentPath:()=>_,isSystemComponentDefinition:()=>Pe,localize:()=>be,mapSlotToPersonalizedVariations:()=>Ae,mapSlotToTestVariations:()=>_e,nullLimitPolicy:()=>f,subscribeToComposition:()=>xe,walkComponentTree:()=>g});module.exports=oe(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(m=>{a[m]||delete o.component[m]})},removeComponent:()=>{let{parentSlot:a,parentSlotIndex:c}=n.ancestorsAndSelf[0],m=n.ancestorsAndSelf[1];if(a&&typeof c!="undefined")m.component.slots[a].splice(c,1);else throw new Error("Unable to delete composition.")},insertAfter:a=>{let c=Array.isArray(a)?a:[a],{parentSlot:m,parentSlotIndex:p}=n.ancestorsAndSelf[0],l=n.ancestorsAndSelf[1];if(m&&typeof p!="undefined")l.component.slots[m].splice(p+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 m=a[c],p=s[m];for(let l=p.length-1;l>=0;l--)t.push({ancestorsAndSelf:[{component:p[l],parentSlot:m,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(".")}`}var x=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 ie({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 R=class extends Error{constructor(){super("Throttled function aborted"),this.name="AbortError"}};function I({limit:r,interval:e,strict:t}){if(!Number.isFinite(r))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(e))throw new TypeError("Expected `interval` to be a finite number");let n=new Map,o=0,i=0;function s(){let p=Date.now();return p-o>e?(i=1,o=p,0):(i<r?i++:(o+=e,i=1),o-p)}let a=[];function c(){let p=Date.now();if(a.length<r)return a.push(p),0;let l=a.shift()+e;return p>=l?(a.push(p),0):(a.push(l),l-p)}let m=t?c:s;return p=>{let l=function(...h){if(!l.isEnabled)return(async()=>p.apply(this,h))();let y;return new Promise((T,W)=>{y=setTimeout(()=>{T(p.apply(this,h)),n.delete(y)},m()),n.set(y,W)})};return l.abort=()=>{for(let h of n.keys())clearTimeout(h),n.get(h)(new R);n.clear(),a.splice(0,a.length)},l.isEnabled=!0,l}}var Z=re(H(),1),ae=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}},ce=(r,e,t)=>{let n=t.retries-(e-1);return r.attemptNumber=e,r.retriesLeft=n,r},pe=r=>ae.has(r),K=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=Z.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&&!pe(s.message))o.stop(),n(s);else{ce(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?K("The operation was aborted."):e.signal.reason;n(i instanceof Error?i:K(i))},{once:!0})})}function N({throttle:r={interval:1e3,limit:10},retry:e={retries:1,factor:1.66}}){let t=r?I(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 me({composition:r,enhancers:e,context:t,onErrors:n=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;g(r,(c,m)=>{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(ue(c,m,h,y,T,t)))});let p=e.resolveComponentEnhancers(c);o.push(le(c,m,p,t)),i.add(p)}),o.push(...Array.from(i).flatMap(c=>Array.from(c).map(async([,m])=>{var p;try{m.completeAll&&await((p=m.limitPolicy)!=null?p:f)(()=>m.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 m;try{c.completeAll&&await((m=c.limitPolicy)!=null?m:f)(()=>c.completeAll())}catch(p){return{error:p,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 le(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 ue(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 he=(r,...e)=>({enhanceOne:n=>{let o="enhanceOne"in r?r.enhanceOne(n):r(n);for(let i of e){let s=fe(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 fe(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;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}}async getCompositionList(e){let{projectId:t}=this.options,n=this.createUrl("/api/v1/canvas",{...e,projectId:t});return await this.apiClient(n)}async getCompositionBySlug(e){let{projectId:t}=this.options,n=this.createUrl("/api/v1/canvas",{...e,projectId:t});return await this.apiClient(n)}async getCompositionById(e){let{projectId:t}=this.options,n=this.createUrl("/api/v1/canvas",{...e,projectId:t});return await this.apiClient(n)}async updateComposition(e){let t=this.createUrl("/api/v1/canvas");await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(e){let t=this.createUrl("/api/v1/canvas"),{projectId:n}=this.options;await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:n}),expectNoContent:!0})}async getComponentDefinitions(e){let{projectId:t}=this.options,n=this.createUrl("/api/v1/canvas-definitions",{...e,projectId:t});return await this.apiClient(n)}async updateComponentDefinition(e){let t=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(e){let t=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(e,t){return this.options.limitPolicy(async()=>{var i;let n=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`};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 de="$personalization",ye="$test",k="$localization",Ce="intentTag",M="locale",Ee="pz",Te="test",V="localized",Xe=0,et=64,$="$pzCrit",B="$tstVrnt",ge="$enr";var Pe=r=>r.startsWith("$");function Ae(r){return r?r.map((e,t)=>{var i,s;let n=(s=(i=e.parameters)==null?void 0:i[$])==null?void 0:s.value,o=(n==null?void 0:n.name)||`pz-${t}-${e.type}`;return{...e,id:o,pz:n}}):[]}function _e(r){return r?r.map((e,t)=>{var i,s,a;let n=(s=(i=e.parameters)==null?void 0:i[B])==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 q="https://js.pusher.com/7.0.3/pusher.min.js";async function ve(){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="${q}"><\/script> manually.`)},5e3),n=document.createElement("script");n.src=q,n.addEventListener("load",()=>{clearTimeout(t),r(window.Pusher)}),document.head.appendChild(n)})}async function we(){let r=await ve();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 xe({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 J({component:r}){var n;let e={},t=(n=r.slots)==null?void 0:n[V];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 be({composition:r,locale:e}){g(r,(t,n,o)=>{if(t.type===k){let i=J({component:t}),s=typeof e=="string"?e:e({component:t,locales:i}),a;if(s&&(a=i[s]),a!=null&&a.length){let[c,...m]=a;o.replaceComponent(c),m.length&&o.insertAfter(m)}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});
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 +1 @@
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-VQFPUXRX.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};
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": "17.0.0",
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",
@@ -48,16 +48,16 @@
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/retry": "0.12.1",
51
- "@types/yargs": "17.0.10",
52
- "@uniformdev/cli": "^17.0.0",
51
+ "@types/yargs": "17.0.11",
52
+ "@uniformdev/cli": "^17.1.0",
53
53
  "p-limit": "4.0.0",
54
54
  "p-retry": "5.1.1",
55
55
  "p-throttle": "5.0.0",
56
- "pusher-js": "7.2.0",
56
+ "pusher-js": "7.3.0",
57
57
  "yargs": "17.5.1"
58
58
  },
59
59
  "dependencies": {
60
- "@uniformdev/context": "^17.0.0"
60
+ "@uniformdev/context": "^17.1.0"
61
61
  },
62
62
  "files": [
63
63
  "/dist"
@@ -65,5 +65,5 @@
65
65
  "publishConfig": {
66
66
  "access": "public"
67
67
  },
68
- "gitHead": "d15f59e5cc80184d983b8c1ca67b1ee390158672"
68
+ "gitHead": "47c6abcea06f19dcd2e723bbee79da32e7c395e5"
69
69
  }
@@ -1,5 +0,0 @@
1
- var Y=Object.create;var E=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var ee=Object.getPrototypeOf,te=Object.prototype.hasOwnProperty;var ne=(n,e,t)=>e in n?E(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var ye=(n=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(n,{get:(e,t)=>(typeof require!="undefined"?require:e)[t]}):n)(function(n){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+n+'" is not supported')});var Ce=(n,e)=>()=>(n&&(e=n(n=0)),e);var _=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),Ee=(n,e)=>{for(var t in e)E(n,t,{get:e[t],enumerable:!0})},S=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of X(e))!te.call(n,o)&&o!==t&&E(n,o,{get:()=>e[o],enumerable:!(r=Q(e,o))||r.enumerable});return n};var re=(n,e,t)=>(t=n!=null?Y(ee(n)):{},S(e||!n||!n.__esModule?E(t,"default",{value:n,enumerable:!0}):t,n)),Te=n=>S(E({},"__esModule",{value:!0}),n);var ge=(n,e,t)=>(ne(n,typeof e!="symbol"?e+"":e,t),t),O=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var oe=(n,e,t)=>(O(n,e,"read from private field"),t?t.call(n):e.get(n)),Pe=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)},ie=(n,e,t,r)=>(O(n,e,"write to private field"),r?r.call(n,t):e.set(n,t),t),Ae=(n,e,t,r)=>({set _(o){ie(n,e,o,t)},get _(){return oe(n,e,r)}});var M=_((Se,k)=>{function u(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))}k.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(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};u.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)};u.prototype.try=function(n){console.log("Using RetryOperation.try() is deprecated"),this.attempt(n)};u.prototype.start=function(n){console.log("Using RetryOperation.start() is deprecated"),this.attempt(n)};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 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 V=_(f=>{var se=M();f.operation=function(n){var e=f.timeouts(n);return new se(e,{forever:n&&(n.forever||n.retries===1/0),unref:n&&n.unref,maxRetryTime:n&&n.maxRetryTime})};f.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};f.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};f.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(c){var m=f.operation(e),p=Array.prototype.slice.call(arguments,1),l=p.pop();p.push(function(h){m.retry(h)||(h&&(arguments[0]=m.mainError()),l.apply(this,arguments))}),m.attempt(function(){c.apply(n,p)})}.bind(n,s),n[i].options=e}}});var B=_((Ne,$)=>{$.exports=V()});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:a=>{Object.assign(o.component,a),["parameters","variant","slots","data","_pattern","_patternError"].forEach(m=>{a[m]||delete o.component[m]})},removeComponent:()=>{let{parentSlot:a,parentSlotIndex:c}=r.ancestorsAndSelf[0],m=r.ancestorsAndSelf[1];if(a&&typeof c!="undefined")m.component.slots[a].splice(c,1);else throw new Error("Unable to delete composition.")},insertAfter:a=>{let c=Array.isArray(a)?a:[a],{parentSlot:m,parentSlotIndex:p}=r.ancestorsAndSelf[0],l=r.ancestorsAndSelf[1];if(m&&typeof p!="undefined")l.component.slots[m].splice(p+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 m=a[c],p=s[m];for(let l=p.length-1;l>=0;l--)t.push({ancestorsAndSelf:[{component:p[l],parentSlot:m,parentSlotIndex:l},...r.ancestorsAndSelf]})}}}while(t.length>0)}function v(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 N=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 A=class{constructor(){this._paramMatches=Array();this._dataMatches=new Map}parameter(e){return this._paramMatches.push({enhancer:this._resolveParameterEnhancer(e)}),this}parameterName(e,t){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({name:o,enhancer:this._resolveParameterEnhancer(t)})),this}parameterType(e,t){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({type:o,enhancer:this._resolveParameterEnhancer(t)})),this}data(e,t){if(this._dataMatches.has(e))throw new Error(`${e} enhancer data key has been used more than once. This will cause data loss.`);return this._dataMatches.set(e,typeof t=="function"?{enhanceOne:t}:t),this}resolveParameterEnhancer(e,t){var 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}},L=class{constructor(){this._componentIndex={};this._rootBuilder=new A}parameter(e){return this._rootBuilder.parameter(e),this}parameterName(e,t){return this._rootBuilder.parameterName(e,t),this}parameterType(e,t){return this._rootBuilder.parameterType(e,t),this}data(e,t){return this._rootBuilder.data(e,t),this}component(e,t){return(Array.isArray(e)?e:[e]).forEach(o=>{this._componentIndex[o]=this._componentIndex[o]||new A,t(this._componentIndex[o])}),this}resolveParameterEnhancer(e,t,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 be({handleBatch:n,shouldQueue:e,limitPolicy:t}){let r=[];return{enhanceOne:async s=>{if(!e||e(s))return new Promise((a,c)=>{r.push(new w(a,c,s))})},completeAll:async()=>{if(r.length>0){try{await n(r)}catch(a){r.forEach(c=>c.reject(a))}if(r.some(a=>!a.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 x=class extends Error{constructor(){super("Throttled function aborted"),this.name="AbortError"}};function b({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 p=Date.now();return p-o>e?(i=1,o=p,0):(i<n?i++:(o+=e,i=1),o-p)}let a=[];function c(){let p=Date.now();if(a.length<n)return a.push(p),0;let l=a.shift()+e;return p>=l?(a.push(p),0):(a.push(l),l-p)}let m=t?c:s;return p=>{let l=function(...h){if(!l.isEnabled)return(async()=>p.apply(this,h))();let y;return new Promise((C,W)=>{y=setTimeout(()=>{C(p.apply(this,h)),r.delete(y)},m()),r.set(y,W)})};return l.abort=()=>{for(let h of r.keys())clearTimeout(h),r.get(h)(new x);r.clear(),a.splice(0,a.length)},l.isEnabled=!0,l}}var U=re(B(),1),ae=new Set(["Failed to fetch","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Network request failed"]),R=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}},ce=(n,e,t)=>{let r=t.retries-(e-1);return n.attemptNumber=e,n.retriesLeft=r,n},pe=n=>ae.has(n),D=n=>globalThis.DOMException===void 0?new Error(n):new DOMException(n);async function I(n,e){return new Promise((t,r)=>{e={onFailedAttempt(){},retries:10,...e};let o=U.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 R)o.stop(),r(s.originalError);else if(s instanceof TypeError&&!pe(s.message))o.stop(),r(s);else{ce(s,i,e);try{await e.onFailedAttempt(s)}catch(a){r(a);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?D("The operation was aborted."):e.signal.reason;r(i instanceof Error?i:D(i))},{once:!0})})}function j({throttle:n={interval:1e3,limit:10},retry:e={retries:1,factor:1.66}}){let t=n?b(n):null;return function(o){let i=async()=>await o();if(t&&(i=t(i)),e){let s=i;i=()=>I(s,e)}return i()}}var d=async n=>await n();async function Fe({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
-
4
- `))}}){let o=[],i=new Set,s=new Set;P(n,(c,m)=>{var l;Object.entries((l=c.parameters)!=null?l:{}).forEach(([h,y])=>{let C=e.resolveParameterEnhancer(c,h,y);C&&(s.add(C),o.push(le(c,m,h,y,C,t)))});let p=e.resolveComponentEnhancers(c);o.push(me(c,m,p,t)),i.add(p)}),o.push(...Array.from(i).flatMap(c=>Array.from(c).map(async([,m])=>{var p;try{m.completeAll&&await((p=m.limitPolicy)!=null?p:d)(()=>m.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 m;try{c.completeAll&&await((m=c.limitPolicy)!=null?m:d)(()=>c.completeAll())}catch(p){return{error:p,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&&r(a)}async function me(n,e,t,r){return t.size&&(n.data={}),await Promise.all(Array.from(t).map(async([o,i])=>{var s;try{let c=await(i.completeAll?d:(s=i.limitPolicy)!=null?s:d)(async()=>i.enhanceOne({component:n,context:r}));c!=null&&(n.data[o]=c)}catch(a){let c=`Component ${v(e)} (type: ${n.type}): data.${o} enhancer threw exception. Data key will not be present.`;return delete n.data[o],{message:c,error:a}}}))}async function le(n,e,t,r,o,i){var s;try{let c=await(o.completeAll?d:(s=o.limitPolicy)!=null?s:d)(async()=>o.enhanceOne({parameter:r,parameterName:t,component:n,context:i}));c===null?delete n.parameters[t]:typeof c=="undefined"?n.parameters[t]={...r,value:r.value}:n.parameters[t]={...r,value:c}}catch(a){let c=`Component ${v(e)} (type: ${n.type}): enhancing parameter ${t} (type: ${r.type}) threw exception. Parameter will be removed.`;return delete n.parameters[t],{message:c,error:a}}}var ze=(n,...e)=>({enhanceOne:r=>{let o="enhanceOne"in n?n.enhanceOne(r):n(r);for(let i of e){let s=ue(o)?o:Promise.resolve(o),a="enhanceOne"in i?i.enhanceOne:i;o=s.then(c=>a({...r,parameter:{type:r.parameter.type,value:c}}))}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 ue(n){return!!n&&(typeof n=="object"||typeof n=="function")&&typeof n.then=="function"}var T=class extends Error{constructor(t,r,o,i,s,a){super(`${t}
5
- ${i}${s?" "+s:""} (${r} ${o}${a?` Request ID: ${a}`:""})`);this.errorMessage=t;this.fetchMethod=r;this.fetchUri=o;this.statusCode=i;this.statusText=s;this.requestId=a;Object.setPrototypeOf(this,T.prototype)}},g=class{constructor(e){var r,o,i,s,a,c;if(!e.apiKey&&!e.bearerToken)throw new Error("You must provide an API key or a bearer token");let t=e.fetch;if(!t)if(typeof globalThis!="undefined"&&typeof globalThis.fetch!="undefined")t=globalThis.fetch.bind(globalThis);else if(typeof fetch!="undefined")t=fetch;else throw new Error("You must provide or polyfill a fetch implementation when not in a browser");this.options={...e,fetch:t,apiHost:(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:(a=e.limitPolicy)!=null?a:j({}),bypassCache:(c=e.bypassCache)!=null?c:!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}`};this.options.bypassCache&&(r["x-bypass-cache"]="true");let o=await this.options.fetch(e.toString(),{...t,headers:{...t==null?void 0:t.headers,...r}});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 T(s,(i=t==null?void 0:t.method)!=null?i:"GET",e.toString(),o.status,o.statusText,g.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}},F=class extends g{constructor(e){super({...e,bypassCache:!0})}};var Je="$personalization",We="$test",G="$localization",Ye="intentTag",z="locale",Qe="pz",Xe="test",H="localized",et=0,tt=64,K="$pzCrit",Z="$tstVrnt",nt="$enr";var ot=n=>n.startsWith("$");function at(n){return n?n.map((e,t)=>{var i,s;let r=(s=(i=e.parameters)==null?void 0:i[K])==null?void 0:s.value,o=(r==null?void 0:r.name)||`pz-${t}-${e.type}`;return{...e,id:o,pz:r}}):[]}function mt(n){return n?n.map((e,t)=>{var i,s,a;let r=(s=(i=e.parameters)==null?void 0:i[Z])==null?void 0:s.value,o=(a=r==null?void 0:r.id)!=null?a:"testId"in e?e.testId:`ab-${t}-${e.type}`;return{...e,id:o}}):[]}var q="https://js.pusher.com/7.0.3/pusher.min.js";async function he(){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="${q}"><\/script> manually.`)},5e3),r=document.createElement("script");r.src=q,r.addEventListener("load",()=>{clearTimeout(t),n(window.Pusher)}),document.head.appendChild(r)})}async function ut(){let n=await he();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 J(n,e,t){return`${n}.${e}@${t}`}function yt({projectId:n,compositionId:e,compositionState:t=0,eventBus:{subscribe:r},callback:o,event:i="updated"}){let s=J(n,e,t),a=r(s),c=a.addEventHandler(i,o);return()=>{c(),a.unsubscribe()}}function fe({component:n}){var r;let e={},t=(r=n.slots)==null?void 0:r[H];return t==null||t.forEach(o=>{var s;let i=(s=o.parameters)==null?void 0:s[z];(i==null?void 0:i.value)&&typeof i.value=="string"&&(e[i.value]=e[i.value]||[],e[i.value].push(o))}),e}function gt({composition:n,locale:e}){P(n,(t,r,o)=>{if(t.type===G){let i=fe({component:t}),s=typeof e=="string"?e:e({component:t,locales:i}),a;if(s&&(a=i[s]),a!=null&&a.length){let[c,...m]=a;o.replaceComponent(c),m.length&&o.insertAfter(m)}else o.removeComponent()}})}export{ye as a,Ce as b,_ as c,Ee as d,re as e,Te as f,ge as g,oe as h,Pe as i,ie as j,Ae as k,P as l,v as m,N as n,A as o,L as p,w as q,be as r,j as s,d as t,Fe as u,ze as v,T as w,g as x,F as y,Je as z,We as A,G as B,Ye as C,z as D,Qe as E,Xe as F,H as G,et as H,tt as I,K as J,Z as K,nt as L,ot as M,at as N,mt as O,ut as P,J as Q,yt as R,fe as S,gt as T};