@uniformdev/canvas 12.0.1-alpha.94 → 12.2.1-alpha.121
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +1 -1
- package/README.md +5 -5
- package/dist/chunk-A4MBTKCQ.mjs +2 -0
- package/dist/cli/cli.d.ts +14 -0
- package/dist/cli/cli.js +4 -0
- package/dist/cli/cli.mjs +3 -0
- package/dist/createEventBus-ca90547e.d.ts +255 -0
- package/dist/index.d.ts +365 -0
- package/dist/index.esm.js +4 -0
- package/dist/index.js +5 -0
- package/dist/index.mjs +4 -0
- package/package.json +34 -34
- package/dist/cjs/CanvasClient.d.ts +0 -50
- package/dist/cjs/CanvasClient.js +0 -1
- package/dist/cjs/cli/arraySyncEngineDataSource.d.ts +0 -10
- package/dist/cjs/cli/arraySyncEngineDataSource.js +0 -1
- package/dist/cjs/cli/cli.d.ts +0 -3
- package/dist/cjs/cli/cli.js +0 -1
- package/dist/cjs/cli/commands/component/_util.d.ts +0 -3
- package/dist/cjs/cli/commands/component/_util.js +0 -1
- package/dist/cjs/cli/commands/component/get.d.ts +0 -7
- package/dist/cjs/cli/commands/component/get.js +0 -1
- package/dist/cjs/cli/commands/component/list.d.ts +0 -6
- package/dist/cjs/cli/commands/component/list.js +0 -1
- package/dist/cjs/cli/commands/component/pull.d.ts +0 -10
- package/dist/cjs/cli/commands/component/pull.js +0 -1
- package/dist/cjs/cli/commands/component/push.d.ts +0 -9
- package/dist/cjs/cli/commands/component/push.js +0 -1
- package/dist/cjs/cli/commands/component/remove.d.ts +0 -7
- package/dist/cjs/cli/commands/component/remove.js +0 -1
- package/dist/cjs/cli/commands/component/update.d.ts +0 -7
- package/dist/cjs/cli/commands/component/update.js +0 -1
- package/dist/cjs/cli/commands/component.d.ts +0 -2
- package/dist/cjs/cli/commands/component.js +0 -1
- package/dist/cjs/cli/commands/composition/_util.d.ts +0 -3
- package/dist/cjs/cli/commands/composition/_util.js +0 -1
- package/dist/cjs/cli/commands/composition/get.d.ts +0 -8
- package/dist/cjs/cli/commands/composition/get.js +0 -1
- package/dist/cjs/cli/commands/composition/list.d.ts +0 -8
- package/dist/cjs/cli/commands/composition/list.js +0 -1
- package/dist/cjs/cli/commands/composition/pull.d.ts +0 -10
- package/dist/cjs/cli/commands/composition/pull.js +0 -1
- package/dist/cjs/cli/commands/composition/push.d.ts +0 -9
- package/dist/cjs/cli/commands/composition/push.js +0 -1
- package/dist/cjs/cli/commands/composition/remove.d.ts +0 -7
- package/dist/cjs/cli/commands/composition/remove.js +0 -1
- package/dist/cjs/cli/commands/composition/update.d.ts +0 -7
- package/dist/cjs/cli/commands/composition/update.js +0 -1
- package/dist/cjs/cli/commands/composition.d.ts +0 -2
- package/dist/cjs/cli/commands/composition.js +0 -1
- package/dist/cjs/cli/componentDefinitionEngineDataSource.d.ts +0 -7
- package/dist/cjs/cli/componentDefinitionEngineDataSource.js +0 -1
- package/dist/cjs/cli/componentInstanceEngineDataSource.d.ts +0 -9
- package/dist/cjs/cli/componentInstanceEngineDataSource.js +0 -1
- package/dist/cjs/cli/fileSyncEngineDataSource.d.ts +0 -9
- package/dist/cjs/cli/fileSyncEngineDataSource.js +0 -1
- package/dist/cjs/cli/package.d.ts +0 -7
- package/dist/cjs/cli/package.js +0 -1
- package/dist/cjs/cli/syncEngine.d.ts +0 -49
- package/dist/cjs/cli/syncEngine.js +0 -1
- package/dist/cjs/cli/syncEngineConsoleLogger.d.ts +0 -5
- package/dist/cjs/cli/syncEngineConsoleLogger.js +0 -1
- package/dist/cjs/cli/util.d.ts +0 -43
- package/dist/cjs/cli/util.js +0 -1
- package/dist/cjs/enhancement/EnhancerBuilder.d.ts +0 -66
- package/dist/cjs/enhancement/EnhancerBuilder.js +0 -1
- package/dist/cjs/enhancement/UniqueBatchEntries.d.ts +0 -17
- package/dist/cjs/enhancement/UniqueBatchEntries.js +0 -1
- package/dist/cjs/enhancement/batchEnhancer.d.ts +0 -39
- package/dist/cjs/enhancement/batchEnhancer.js +0 -1
- package/dist/cjs/enhancement/compose.d.ts +0 -6
- package/dist/cjs/enhancement/compose.js +0 -1
- package/dist/cjs/enhancement/createLimitPolicy.d.ts +0 -8
- package/dist/cjs/enhancement/createLimitPolicy.js +0 -1
- package/dist/cjs/enhancement/enhance.d.ts +0 -18
- package/dist/cjs/enhancement/enhance.js +0 -1
- package/dist/cjs/enhancement/localize.d.ts +0 -11
- package/dist/cjs/enhancement/localize.js +0 -1
- package/dist/cjs/enhancement/walkComponentTree.d.ts +0 -14
- package/dist/cjs/enhancement/walkComponentTree.js +0 -1
- package/dist/cjs/index.d.ts +0 -17
- package/dist/cjs/index.js +0 -1
- package/dist/cjs/preview/EventNames.d.ts +0 -1
- package/dist/cjs/preview/EventNames.js +0 -1
- package/dist/cjs/preview/createEventBus.d.ts +0 -6
- package/dist/cjs/preview/createEventBus.js +0 -1
- package/dist/cjs/preview/getChannelName.d.ts +0 -1
- package/dist/cjs/preview/getChannelName.js +0 -1
- package/dist/cjs/preview/subscribeToComposition.d.ts +0 -13
- package/dist/cjs/preview/subscribeToComposition.js +0 -1
- package/dist/cjs/types/componentDefinitions.d.ts +0 -90
- package/dist/cjs/types/componentDefinitions.js +0 -1
- package/dist/cjs/types/componentInstances.d.ts +0 -104
- package/dist/cjs/types/componentInstances.js +0 -1
- package/dist/cjs/types/enhancement.d.ts +0 -79
- package/dist/cjs/types/enhancement.js +0 -1
- package/dist/cjs/types/index.d.ts +0 -3
- package/dist/cjs/types/index.js +0 -1
- package/dist/cjs/utils/constants.d.ts +0 -20
- package/dist/cjs/utils/constants.js +0 -1
- package/dist/cjs/utils/isSystemComponentDefinition.d.ts +0 -2
- package/dist/cjs/utils/isSystemComponentDefinition.js +0 -1
- package/dist/cjs/utils/mapSlotToPersonalizedVariations.d.ts +0 -7
- package/dist/cjs/utils/mapSlotToPersonalizedVariations.js +0 -1
- package/dist/esm/CanvasClient.d.ts +0 -50
- package/dist/esm/CanvasClient.js +0 -1
- package/dist/esm/cli/arraySyncEngineDataSource.d.ts +0 -10
- package/dist/esm/cli/arraySyncEngineDataSource.js +0 -1
- package/dist/esm/cli/cli.d.ts +0 -3
- package/dist/esm/cli/cli.js +0 -1
- package/dist/esm/cli/commands/component/_util.d.ts +0 -3
- package/dist/esm/cli/commands/component/_util.js +0 -1
- package/dist/esm/cli/commands/component/get.d.ts +0 -7
- package/dist/esm/cli/commands/component/get.js +0 -1
- package/dist/esm/cli/commands/component/list.d.ts +0 -6
- package/dist/esm/cli/commands/component/list.js +0 -1
- package/dist/esm/cli/commands/component/pull.d.ts +0 -10
- package/dist/esm/cli/commands/component/pull.js +0 -1
- package/dist/esm/cli/commands/component/push.d.ts +0 -9
- package/dist/esm/cli/commands/component/push.js +0 -1
- package/dist/esm/cli/commands/component/remove.d.ts +0 -7
- package/dist/esm/cli/commands/component/remove.js +0 -1
- package/dist/esm/cli/commands/component/update.d.ts +0 -7
- package/dist/esm/cli/commands/component/update.js +0 -1
- package/dist/esm/cli/commands/component.d.ts +0 -2
- package/dist/esm/cli/commands/component.js +0 -1
- package/dist/esm/cli/commands/composition/_util.d.ts +0 -3
- package/dist/esm/cli/commands/composition/_util.js +0 -1
- package/dist/esm/cli/commands/composition/get.d.ts +0 -8
- package/dist/esm/cli/commands/composition/get.js +0 -1
- package/dist/esm/cli/commands/composition/list.d.ts +0 -8
- package/dist/esm/cli/commands/composition/list.js +0 -1
- package/dist/esm/cli/commands/composition/pull.d.ts +0 -10
- package/dist/esm/cli/commands/composition/pull.js +0 -1
- package/dist/esm/cli/commands/composition/push.d.ts +0 -9
- package/dist/esm/cli/commands/composition/push.js +0 -1
- package/dist/esm/cli/commands/composition/remove.d.ts +0 -7
- package/dist/esm/cli/commands/composition/remove.js +0 -1
- package/dist/esm/cli/commands/composition/update.d.ts +0 -7
- package/dist/esm/cli/commands/composition/update.js +0 -1
- package/dist/esm/cli/commands/composition.d.ts +0 -2
- package/dist/esm/cli/commands/composition.js +0 -1
- package/dist/esm/cli/componentDefinitionEngineDataSource.d.ts +0 -7
- package/dist/esm/cli/componentDefinitionEngineDataSource.js +0 -1
- package/dist/esm/cli/componentInstanceEngineDataSource.d.ts +0 -9
- package/dist/esm/cli/componentInstanceEngineDataSource.js +0 -1
- package/dist/esm/cli/fileSyncEngineDataSource.d.ts +0 -9
- package/dist/esm/cli/fileSyncEngineDataSource.js +0 -1
- package/dist/esm/cli/package.d.ts +0 -7
- package/dist/esm/cli/package.js +0 -1
- package/dist/esm/cli/syncEngine.d.ts +0 -49
- package/dist/esm/cli/syncEngine.js +0 -1
- package/dist/esm/cli/syncEngineConsoleLogger.d.ts +0 -5
- package/dist/esm/cli/syncEngineConsoleLogger.js +0 -1
- package/dist/esm/cli/util.d.ts +0 -43
- package/dist/esm/cli/util.js +0 -1
- package/dist/esm/enhancement/EnhancerBuilder.d.ts +0 -66
- package/dist/esm/enhancement/EnhancerBuilder.js +0 -1
- package/dist/esm/enhancement/UniqueBatchEntries.d.ts +0 -17
- package/dist/esm/enhancement/UniqueBatchEntries.js +0 -1
- package/dist/esm/enhancement/batchEnhancer.d.ts +0 -39
- package/dist/esm/enhancement/batchEnhancer.js +0 -1
- package/dist/esm/enhancement/compose.d.ts +0 -6
- package/dist/esm/enhancement/compose.js +0 -1
- package/dist/esm/enhancement/createLimitPolicy.d.ts +0 -8
- package/dist/esm/enhancement/createLimitPolicy.js +0 -1
- package/dist/esm/enhancement/enhance.d.ts +0 -18
- package/dist/esm/enhancement/enhance.js +0 -1
- package/dist/esm/enhancement/localize.d.ts +0 -11
- package/dist/esm/enhancement/localize.js +0 -1
- package/dist/esm/enhancement/walkComponentTree.d.ts +0 -14
- package/dist/esm/enhancement/walkComponentTree.js +0 -1
- package/dist/esm/index.d.ts +0 -17
- package/dist/esm/index.js +0 -1
- package/dist/esm/preview/EventNames.d.ts +0 -1
- package/dist/esm/preview/EventNames.js +0 -0
- package/dist/esm/preview/createEventBus.d.ts +0 -6
- package/dist/esm/preview/createEventBus.js +0 -1
- package/dist/esm/preview/getChannelName.d.ts +0 -1
- package/dist/esm/preview/getChannelName.js +0 -1
- package/dist/esm/preview/subscribeToComposition.d.ts +0 -13
- package/dist/esm/preview/subscribeToComposition.js +0 -1
- package/dist/esm/types/componentDefinitions.d.ts +0 -90
- package/dist/esm/types/componentDefinitions.js +0 -0
- package/dist/esm/types/componentInstances.d.ts +0 -104
- package/dist/esm/types/componentInstances.js +0 -0
- package/dist/esm/types/enhancement.d.ts +0 -79
- package/dist/esm/types/enhancement.js +0 -0
- package/dist/esm/types/index.d.ts +0 -3
- package/dist/esm/types/index.js +0 -1
- package/dist/esm/utils/constants.d.ts +0 -20
- package/dist/esm/utils/constants.js +0 -1
- package/dist/esm/utils/isSystemComponentDefinition.d.ts +0 -2
- package/dist/esm/utils/isSystemComponentDefinition.js +0 -1
- package/dist/esm/utils/mapSlotToPersonalizedVariations.d.ts +0 -7
- package/dist/esm/utils/mapSlotToPersonalizedVariations.js +0 -1
package/dist/index.d.ts
ADDED
@@ -0,0 +1,365 @@
|
|
1
|
+
import { C as ComponentInstance, a as ComponentParameter, b as CompositionAPIOptions, c as CompositionListAPIResponse, d as CompositionAPIResponse, e as CompositionAPIPutRequest, f as CompositionAPIDeleteRequest, g as ComponentDefinitionListAPIOptions, h as ComponentDefinitionAPIResponse, i as ComponentDefinitionAPIPutRequest, j as ComponentDefinitionAPIDeleteRequest, P as PreviewEventBus } from './createEventBus-ca90547e';
|
2
|
+
export { r as ChannelSubscription, o as ComponentDefinition, j as ComponentDefinitionAPIDeleteRequest, i as ComponentDefinitionAPIPutRequest, h as ComponentDefinitionAPIResponse, g as ComponentDefinitionListAPIOptions, k as ComponentDefinitionParameter, n as ComponentDefinitionSlot, m as ComponentDefinitionSlugSettings, l as ComponentDefinitionVariant, C as ComponentInstance, a as ComponentParameter, f as CompositionAPIDeleteRequest, b as CompositionAPIOptions, e as CompositionAPIPutRequest, d as CompositionAPIResponse, q as CompositionFetchState, c as CompositionListAPIResponse, p as CreatingComponentDefinition, P as PreviewEventBus, R as RootComponentInstance, s as createEventBus } from './createEventBus-ca90547e';
|
3
|
+
import { Options } from 'p-throttle';
|
4
|
+
import { Options as Options$1 } from 'p-retry';
|
5
|
+
import { PersonalizedVariant, TestVariant } from '@uniformdev/context';
|
6
|
+
import 'pusher-js';
|
7
|
+
|
8
|
+
declare type EnhancerContext = {
|
9
|
+
preview?: boolean;
|
10
|
+
};
|
11
|
+
/** Options passed to a ComponentEnhancer function */
|
12
|
+
declare type ComponentEnhancerOptions<TContext extends EnhancerContext = EnhancerContext> = {
|
13
|
+
component: Readonly<ComponentInstance>;
|
14
|
+
context: TContext;
|
15
|
+
};
|
16
|
+
/**
|
17
|
+
* A function which is called for each matching component in a composition, which can manipulate the value of a specific key in the component's `data` property.
|
18
|
+
* Used to enhance layout data with information from other platforms, such as private APIs, where the value is not tied to a parameter
|
19
|
+
* and is intrinsic to the component itself.
|
20
|
+
*
|
21
|
+
* Note: the configuration of enhancers namespaces component enhancers into a named property on the data object to avoid collisions,
|
22
|
+
* thus an enhancer need not worry about merging values with other enhancers, nor which key it has been registered under.
|
23
|
+
*
|
24
|
+
* Return values:
|
25
|
+
* TValue - sets the configured key in the component's data value to this value
|
26
|
+
* undefined - do not set the component's data key
|
27
|
+
*/
|
28
|
+
declare type ComponentEnhancerFunction<TValue = unknown, TContext extends EnhancerContext = EnhancerContext> = (options: ComponentEnhancerOptions<TContext>) => Promise<TValue | undefined> | TValue | undefined;
|
29
|
+
/**
|
30
|
+
* Defines logic to add arbitrary async data to a component's `data` property.
|
31
|
+
* Used to enhance layout data with information from other platforms, such as private APIs,
|
32
|
+
* where the value is not tied to a parameter and is intrinsic to the component itself.
|
33
|
+
*/
|
34
|
+
declare type ComponentEnhancer<TValue = unknown, TContext extends EnhancerContext = EnhancerContext> = {
|
35
|
+
/** Function called to enhance a single component in a composition. */
|
36
|
+
enhanceOne: ComponentEnhancerFunction<TValue, TContext>;
|
37
|
+
/**
|
38
|
+
* The limit policy that defines how much concurrency and retry is allowed for this enhancer.
|
39
|
+
* If the enhancer does not define completeAll(), this limit policy is applied to enhanceOne() calls.
|
40
|
+
* If the enhancer does define completeAll(), this limit policy is applied to the completeAll() calls.
|
41
|
+
* If the limit policy is undefined, unbounded concurrency is allowed and no error retrying will occur.
|
42
|
+
*/
|
43
|
+
limitPolicy?: LimitPolicy;
|
44
|
+
completeAll?: () => Promise<void>;
|
45
|
+
};
|
46
|
+
/** Options passed to a ComponentParameterEnhancer function */
|
47
|
+
declare type ComponentParameterEnhancerOptions<TRawValue = unknown, TContext extends EnhancerContext = EnhancerContext> = {
|
48
|
+
parameter: Readonly<ComponentParameter<TRawValue>>;
|
49
|
+
parameterName: string;
|
50
|
+
component: Readonly<ComponentInstance>;
|
51
|
+
context: TContext;
|
52
|
+
};
|
53
|
+
/**
|
54
|
+
* A function which is called for each component parameter in a component tree, which can manipulate the value of the parameter.
|
55
|
+
* Used to enhance layout data with information from other platforms, such as CMS, commerce, indexing, etc.
|
56
|
+
*
|
57
|
+
* Return values:
|
58
|
+
* TValue - replaces the original parameter value with this value
|
59
|
+
* undefined - do not change the original parameter value
|
60
|
+
* null - sets the parameter value to null, replacing any existing value (i.e. if its value could not be resolved in an external system)
|
61
|
+
*/
|
62
|
+
declare type ComponentParameterEnhancerFunction<TRawValue = unknown, TOutputValue = unknown, TContext extends EnhancerContext = EnhancerContext> = (options: ComponentParameterEnhancerOptions<TRawValue, TContext>) => Promise<TOutputValue | undefined | null> | TOutputValue | undefined | null;
|
63
|
+
/**
|
64
|
+
* Defines logic to replace the value of a component parameter with arbitrary async data.
|
65
|
+
* Used to enhance layout data with information from other platforms, such as CMS, commerce, indexing, etc,
|
66
|
+
* where that data is directly expandable from a parameter value.
|
67
|
+
*/
|
68
|
+
declare type ComponentParameterEnhancer<TRawValue = unknown, TOutputValue = unknown, TContext extends EnhancerContext = EnhancerContext> = {
|
69
|
+
/** Function called to enhance a single parameter to be enhanced. */
|
70
|
+
enhanceOne: ComponentParameterEnhancerFunction<TRawValue, TOutputValue, TContext>;
|
71
|
+
/**
|
72
|
+
* The limit policy that defines how much concurrency and retry is allowed for this enhancer.
|
73
|
+
* If the enhancer does not define completeAll(), this limit policy is applied to enhanceOne() calls.
|
74
|
+
* If the enhancer does define completeAll(), this limit policy is applied to the completeAll() calls.
|
75
|
+
* If the limit policy is undefined, unbounded concurrency is allowed and no error retrying will occur.
|
76
|
+
*/
|
77
|
+
limitPolicy?: LimitPolicy;
|
78
|
+
/**
|
79
|
+
* Function called, if defined, after all enhanceOne() calls have completed for the composition being enhanced.
|
80
|
+
* Used to enable batching.
|
81
|
+
* Return the number of batched items processed (or zero if that does not apply).
|
82
|
+
*/
|
83
|
+
completeAll?: () => Promise<number>;
|
84
|
+
};
|
85
|
+
|
86
|
+
declare type ComponentLocationReference = {
|
87
|
+
component: ComponentInstance;
|
88
|
+
parentSlot?: string;
|
89
|
+
parentSlotIndex?: number;
|
90
|
+
};
|
91
|
+
declare type WalkComponentTreeActions = {
|
92
|
+
replaceComponent: (replacementComponent: ComponentInstance) => void;
|
93
|
+
removeComponent: () => void;
|
94
|
+
insertAfter: (components: ComponentInstance | ComponentInstance[]) => void;
|
95
|
+
};
|
96
|
+
/** Walks a composition's component tree, visiting each component instance depth-first, in order. */
|
97
|
+
declare function walkComponentTree(component: ComponentInstance, visitor: (component: ComponentInstance, ancestorsAndSelf: Array<ComponentLocationReference>, actions: WalkComponentTreeActions) => void): void;
|
98
|
+
declare function getComponentPath(ancestorsAndSelf: Array<ComponentLocationReference>): string;
|
99
|
+
|
100
|
+
/** A single entry in a batch of queued enhancements. */
|
101
|
+
declare class BatchEntry<TArgs, TResult> {
|
102
|
+
private _resolve;
|
103
|
+
private _reject;
|
104
|
+
args: TArgs;
|
105
|
+
private _isCompleted;
|
106
|
+
constructor(_resolve: (result: TResult) => void, _reject: (reason: any) => void, args: TArgs);
|
107
|
+
/** Mark the batch entry as successfully completed. */
|
108
|
+
resolve(result: TResult): void;
|
109
|
+
/** Mark the batch entry as failed. */
|
110
|
+
reject(reason: any): void;
|
111
|
+
/** @return Whether the batch entry has been completed (resolved or rejected). */
|
112
|
+
get isCompleted(): boolean;
|
113
|
+
}
|
114
|
+
/**
|
115
|
+
* An enhancer that queues up promises for each component that needs enhancing,
|
116
|
+
* and once all enhancements have been queued handles them all in a batch.
|
117
|
+
* Note: this type is adaptable to both ComponentParameterEnhancer and ComponentEnhancer types.
|
118
|
+
*/
|
119
|
+
declare type BatchEnhancer<TArgs, TResult> = {
|
120
|
+
/** Adds a promise to the enhancement queue. */
|
121
|
+
enhanceOne: (args: TArgs) => Promise<TResult | undefined>;
|
122
|
+
/** Calls the batch enhancer function for all queued promises and resolves them. Returns number of processed items. */
|
123
|
+
completeAll: () => Promise<number>;
|
124
|
+
limitPolicy?: LimitPolicy;
|
125
|
+
};
|
126
|
+
/**
|
127
|
+
* Creates an enhancer that batches up all enhancements for a composition into a set of promises,
|
128
|
+
* and then handles them all in a single batch. Used to reduce the number of HTTP requests
|
129
|
+
* needed to fulfill layout enhancements when a layout uses many resources from other systems.
|
130
|
+
*/
|
131
|
+
declare function createBatchEnhancer<TArgs, TResult>({ handleBatch, shouldQueue, limitPolicy, }: {
|
132
|
+
/** Function called to handle one or more batched up enhancements. (note: queue will never be an empty array) */
|
133
|
+
handleBatch: (queue: ReadonlyArray<Readonly<BatchEntry<TArgs, TResult>>>) => Promise<void>;
|
134
|
+
/** Function called to determine if a given enhancement should be queued, i.e. don't queue invalid or null/undefined values. */
|
135
|
+
shouldQueue?: (args: TArgs) => boolean;
|
136
|
+
limitPolicy?: LimitPolicy;
|
137
|
+
}): BatchEnhancer<TArgs, TResult>;
|
138
|
+
|
139
|
+
/**
|
140
|
+
* Given a batch of enhancements containing potentially duplicate entries (i.e. several components referencing the same thing),
|
141
|
+
* group them together by some unique identifier and enable simpler batch processing.
|
142
|
+
*/
|
143
|
+
declare class UniqueBatchEntries<TArgs, TResult> {
|
144
|
+
groups: Readonly<Record<string, ReadonlyArray<Readonly<BatchEntry<TArgs, TResult>>>>>;
|
145
|
+
constructor(
|
146
|
+
/** The batch queue being processed. */
|
147
|
+
entries: ReadonlyArray<Readonly<BatchEntry<TArgs, TResult>>>,
|
148
|
+
/** A function to select the unique identifier for a given batch entry. */
|
149
|
+
uniqueKeySelector: (entry: Readonly<TArgs>) => string);
|
150
|
+
/** Resolves all entries in a group key with the same result value. */
|
151
|
+
resolveKey(key: string, result: TResult): void;
|
152
|
+
/** Resolves all remaining entries that have not been otherwise resolved with a specific value */
|
153
|
+
resolveRemaining(value: TResult): void;
|
154
|
+
}
|
155
|
+
|
156
|
+
/**
|
157
|
+
* Builds a definition of the enhancers to run on Canvas components to add data from other systems.
|
158
|
+
* Note that only the first matching enhancer will be run.
|
159
|
+
*/
|
160
|
+
declare class ChildEnhancerBuilder {
|
161
|
+
private _paramMatches;
|
162
|
+
private _dataMatches;
|
163
|
+
/** Targets an enhancer to modify the value of any parameter */
|
164
|
+
parameter(enhancer: ComponentParameterEnhancer<any, any> | ComponentParameterEnhancerFunction<any>): this;
|
165
|
+
/** Targets an enhancer to modify the value of any parameter with a specific name */
|
166
|
+
parameterName(name: string | readonly string[], enhancer: ComponentParameterEnhancer<any, any> | ComponentParameterEnhancerFunction<any>): this;
|
167
|
+
/** Targets an enhancer to modify the value of any parameter with a specific type */
|
168
|
+
parameterType(type: string | readonly string[], enhancer: ComponentParameterEnhancer<any, any> | ComponentParameterEnhancerFunction<any>): this;
|
169
|
+
/**
|
170
|
+
* Targets an enhancer to set a specific object key on the component's `data` property.
|
171
|
+
* Note: an exception will be thrown if the same key is registered more than once.
|
172
|
+
*/
|
173
|
+
data(name: string, enhancer: ComponentEnhancer<any> | ComponentEnhancerFunction<any>): this;
|
174
|
+
/**
|
175
|
+
* Resolves the parameter enhancer for a given parameter, if one exists.
|
176
|
+
* The first matching enhancer by registration order is returned, if more than one could match.
|
177
|
+
*/
|
178
|
+
resolveParameterEnhancer(parameterName: string, parameter: ComponentParameter): ComponentParameterEnhancer<unknown, unknown, EnhancerContext> | undefined;
|
179
|
+
/**
|
180
|
+
* Resolves component enhancer(s) for a given component.
|
181
|
+
* Returns a Map where the key is the name of the data property and the value is the enhancer.
|
182
|
+
*/
|
183
|
+
resolveComponentEnhancers(): Map<string, ComponentEnhancer<unknown, EnhancerContext>>;
|
184
|
+
private _resolveParameterEnhancer;
|
185
|
+
}
|
186
|
+
/**
|
187
|
+
* Builds a definition of the enhancers to run on Canvas components to add data from other systems.
|
188
|
+
* Note that only the first matching enhancer will be run.
|
189
|
+
*/
|
190
|
+
declare class EnhancerBuilder {
|
191
|
+
private _componentIndex;
|
192
|
+
private _rootBuilder;
|
193
|
+
/** Targets an enhancer to modify the value of any parameter */
|
194
|
+
parameter(enhancer: ComponentParameterEnhancer<any, any> | ComponentParameterEnhancerFunction): this;
|
195
|
+
/** Targets an enhancer to modify the value of any parameter with a specific name */
|
196
|
+
parameterName(name: string | readonly string[], enhancer: ComponentParameterEnhancer<any, any> | ComponentParameterEnhancerFunction): this;
|
197
|
+
/** Targets an enhancer to modify the value of any parameter with a specific type */
|
198
|
+
parameterType(type: string | readonly string[], enhancer: ComponentParameterEnhancer<any, any> | ComponentParameterEnhancerFunction<any>): this;
|
199
|
+
/**
|
200
|
+
* Targets an enhancer to set a specific object key on the component's `data` property.
|
201
|
+
* Note: an exception will be thrown if the same key is registered more than once.
|
202
|
+
*/
|
203
|
+
data(name: string, enhancer: ComponentEnhancer<any> | ComponentEnhancerFunction<any>): this;
|
204
|
+
/**
|
205
|
+
* Targets a subset of enhancers at a specific component type.
|
206
|
+
* Global enhancers will still be run if no matching enhancer is registered for this component's properties.
|
207
|
+
*/
|
208
|
+
component(name: string | readonly string[], builder: (builder: ChildEnhancerBuilder) => void): EnhancerBuilder;
|
209
|
+
/**
|
210
|
+
* Resolves the parameter enhancer for a given parameter, if one exists.
|
211
|
+
* The first matching enhancer by registration order is returned, if more than one could match.
|
212
|
+
*/
|
213
|
+
resolveParameterEnhancer(component: ComponentInstance, parameterName: string, parameter: ComponentParameter): ComponentParameterEnhancer<unknown, unknown, EnhancerContext> | undefined;
|
214
|
+
/**
|
215
|
+
* Resolves component enhancer(s) for a given component.
|
216
|
+
* Returns a Map where the key is the name of the data property and the value is the enhancer.
|
217
|
+
*/
|
218
|
+
resolveComponentEnhancers(component: ComponentInstance): Map<string, ComponentEnhancer<unknown, EnhancerContext>>;
|
219
|
+
}
|
220
|
+
|
221
|
+
declare type EnhancerError = {
|
222
|
+
message: string;
|
223
|
+
error: Error | string;
|
224
|
+
};
|
225
|
+
/**
|
226
|
+
* Applies enhancer functions to a component tree.
|
227
|
+
* IMPORTANT: the input composition object is mutated. Plan accordingly.
|
228
|
+
* Want immutability? Grab immer :)
|
229
|
+
*/
|
230
|
+
declare function enhance<TContext extends EnhancerContext = EnhancerContext>({ composition, enhancers, context, onErrors, }: {
|
231
|
+
composition: ComponentInstance;
|
232
|
+
enhancers: EnhancerBuilder;
|
233
|
+
context: TContext;
|
234
|
+
onErrors?: (errors: EnhancerError[]) => void;
|
235
|
+
}): Promise<void>;
|
236
|
+
|
237
|
+
/**
|
238
|
+
* Composes several enhancers into a synchronous chain. Can be used to modify the output of an enhancer.
|
239
|
+
* NOTE: only the first enhancer in the chain may use batching (completeAll()).
|
240
|
+
*/
|
241
|
+
declare const compose: (input: ComponentParameterEnhancer<any, any>, ...composers: ReadonlyArray<ComponentParameterEnhancer<any, any> | ComponentParameterEnhancerFunction<any>>) => ComponentParameterEnhancer<any, any>;
|
242
|
+
|
243
|
+
declare type LimitPolicy = <ReturnValue>(func: () => Promise<ReturnValue>) => Promise<ReturnValue>;
|
244
|
+
declare function createLimitPolicy({ throttle, retry, }: {
|
245
|
+
throttle?: Options | false;
|
246
|
+
retry?: Options$1 | false;
|
247
|
+
}): LimitPolicy;
|
248
|
+
declare const nullLimitPolicy: LimitPolicy;
|
249
|
+
|
250
|
+
declare type CanvasClientOptions = {
|
251
|
+
/** The Uniform API host to use. Internal use. */
|
252
|
+
apiHost?: string;
|
253
|
+
/** The Uniform API key to use when sending API requests. This or bearer token must be specified. */
|
254
|
+
apiKey?: string | null;
|
255
|
+
/** The Uniform bearer token to use. Internal use. */
|
256
|
+
bearerToken?: string | null;
|
257
|
+
/** The Uniform project ID to connect to */
|
258
|
+
projectId?: string | null;
|
259
|
+
/** Specify a fetch implementation to use when fetching data. Useful if you want to only polyfill selectively. */
|
260
|
+
fetch?: typeof fetch;
|
261
|
+
/**
|
262
|
+
* Specify how to retry and throttle requests.
|
263
|
+
* Default: retry 3x on failures with exponential backoff, up to 10 requests per second.
|
264
|
+
* Use createLimitPolicy() to help creating a policy. */
|
265
|
+
limitPolicy?: LimitPolicy;
|
266
|
+
};
|
267
|
+
declare class CanvasClientError extends Error {
|
268
|
+
errorMessage: string;
|
269
|
+
fetchMethod: string;
|
270
|
+
fetchUri: string;
|
271
|
+
statusCode?: number | undefined;
|
272
|
+
statusText?: string | undefined;
|
273
|
+
constructor(errorMessage: string, fetchMethod: string, fetchUri: string, statusCode?: number | undefined, statusText?: string | undefined);
|
274
|
+
}
|
275
|
+
declare class CanvasClient {
|
276
|
+
private options;
|
277
|
+
constructor(options: CanvasClientOptions);
|
278
|
+
/** Fetches lists of Canvas compositions, optionally by type */
|
279
|
+
getCompositionList(options?: Omit<CompositionAPIOptions, 'projectId'>): Promise<CompositionListAPIResponse>;
|
280
|
+
/** Fetches a Canvas composition by string name (slug) */
|
281
|
+
getCompositionBySlug(options: Pick<CompositionAPIOptions, 'slug' | 'state' | 'skipEnhance' | 'skipPatternResolution'>): Promise<CompositionAPIResponse>;
|
282
|
+
/** Fetches a Canvas composition by its public UUID */
|
283
|
+
getCompositionById(options: Pick<CompositionAPIOptions, 'compositionId' | 'state' | 'skipEnhance' | 'skipPatternResolution'>): Promise<CompositionAPIResponse>;
|
284
|
+
/** Updates or creates a Canvas component definition */
|
285
|
+
updateComposition(body: Omit<CompositionAPIPutRequest, 'projectId'>): Promise<void>;
|
286
|
+
/** Deletes a Canvas component definition */
|
287
|
+
removeComposition(body: Omit<CompositionAPIDeleteRequest, 'projectId'>): Promise<void>;
|
288
|
+
/** Fetches all Canvas component definitions */
|
289
|
+
getComponentDefinitions(options?: Omit<ComponentDefinitionListAPIOptions, 'projectId'>): Promise<ComponentDefinitionAPIResponse>;
|
290
|
+
/** Updates or creates a Canvas component definition */
|
291
|
+
updateComponentDefinition(body: Omit<ComponentDefinitionAPIPutRequest, 'projectId'>): Promise<void>;
|
292
|
+
/** Deletes a Canvas component definition */
|
293
|
+
removeComponentDefinition(body: Omit<ComponentDefinitionAPIDeleteRequest, 'projectId'>): Promise<void>;
|
294
|
+
private apiClient;
|
295
|
+
private createUrl;
|
296
|
+
}
|
297
|
+
|
298
|
+
/** Public ID of Canvas personalization component type */
|
299
|
+
declare const CANVAS_PERSONALIZE_TYPE = "$personalization";
|
300
|
+
/** Public ID of Canvas A/B test component type */
|
301
|
+
declare const CANVAS_TEST_TYPE = "$test";
|
302
|
+
/** Public ID of Canvas localization component type */
|
303
|
+
declare const CANVAS_LOCALIZATION_TYPE = "$localization";
|
304
|
+
/** Public ID of the intent tag parameter on the Canvas personalization component type */
|
305
|
+
declare const CANVAS_INTENT_TAG_PARAM = "intentTag";
|
306
|
+
/** Public ID of the locale parameter on Canvas components */
|
307
|
+
declare const CANVAS_LOCALE_TAG_PARAM = "locale";
|
308
|
+
/** Name of the slot on CANVAS_PERSONALIZE_TYPE */
|
309
|
+
declare const CANVAS_PERSONALIZE_SLOT = "pz";
|
310
|
+
/** Name of the slot on CANVAS_TEST_TYPE */
|
311
|
+
declare const CANVAS_TEST_SLOT = "test";
|
312
|
+
/** Name of the slot on CANVAS_TEST_TYPE */
|
313
|
+
declare const CANVAS_LOCALIZATION_SLOT = "localized";
|
314
|
+
/** Constant for a draft composition state. Subject to change. */
|
315
|
+
declare const CANVAS_DRAFT_STATE = 0;
|
316
|
+
/** Constant for a published composition state. Subject to change. */
|
317
|
+
declare const CANVAS_PUBLISHED_STATE = 64;
|
318
|
+
/** Public ID of the Uniform Context personalization parameter on Canvas components */
|
319
|
+
declare const CANVAS_PERSONALIZATION_PARAM = "$pzCrit";
|
320
|
+
/** Public ID of the Uniform Context enrichment tag parameter on Canvas components */
|
321
|
+
declare const CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
|
322
|
+
|
323
|
+
/** Determines if a given Canvas component type is a system-defined type */
|
324
|
+
declare const isSystemComponentDefinition: (componentType: string) => boolean;
|
325
|
+
|
326
|
+
/**
|
327
|
+
* Converts components in a slot into personalized variations (based on each component's intent tag in Canvas) suitable to pass to a personalize component
|
328
|
+
* Useful when implementing custom personalization settings for Canvas components.
|
329
|
+
*/
|
330
|
+
declare function mapSlotToPersonalizedVariations(slot: ComponentInstance[] | undefined): Array<ComponentInstance & PersonalizedVariant>;
|
331
|
+
|
332
|
+
/**
|
333
|
+
* Converts components in a slot into test variations (based on each component's Context tag in Canvas) suitable to pass to a personalize component
|
334
|
+
* Useful when implementing custom test settings for Canvas components.
|
335
|
+
*/
|
336
|
+
declare function mapSlotToTestVariations(slot: ComponentInstance[] | undefined): Array<ComponentInstance & TestVariant>;
|
337
|
+
|
338
|
+
declare function getChannelName(projectId: string, compositionId: string, state: number): string;
|
339
|
+
|
340
|
+
declare type EventNames = 'updated';
|
341
|
+
|
342
|
+
declare type SubscribeToCompositionOptions = {
|
343
|
+
projectId: string;
|
344
|
+
compositionId: string;
|
345
|
+
compositionState: number;
|
346
|
+
callback: (data: unknown) => void;
|
347
|
+
eventBus: PreviewEventBus;
|
348
|
+
event: EventNames;
|
349
|
+
};
|
350
|
+
declare type UnsubscribeCallback = () => void;
|
351
|
+
/** Subscribes to a composition event */
|
352
|
+
declare function subscribeToComposition({ projectId, compositionId, compositionState, eventBus: { subscribe }, callback, event, }: SubscribeToCompositionOptions): UnsubscribeCallback;
|
353
|
+
|
354
|
+
declare function extractLocales({ component }: {
|
355
|
+
component: ComponentInstance;
|
356
|
+
}): Record<string, ComponentInstance[]>;
|
357
|
+
declare function localize({ composition, locale, }: {
|
358
|
+
composition: ComponentInstance;
|
359
|
+
locale: string | ((options: {
|
360
|
+
component: Readonly<ComponentInstance>;
|
361
|
+
locales: Readonly<Record<string, ComponentInstance[]>>;
|
362
|
+
}) => string | undefined);
|
363
|
+
}): void;
|
364
|
+
|
365
|
+
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, 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 };
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import{a as L,b as d,c as j,d as k,e as F,f as N,g as v,h as f,i as T,j as V,k as U,l as w,m as z,n as W,o as D,p as H}from"./chunk-A4MBTKCQ.mjs";function y(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 E(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 I=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 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(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}},R=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(r=>{this._componentIndex[r]=this._componentIndex[r]||new P,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 _=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 q({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,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 ee({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;y(o,(s,p)=>{var h;Object.entries((h=s.parameters)!=null?h:{}).forEach(([g,A])=>{let C=e.resolveParameterEnhancer(s,g,A);C&&(i.add(C),r.push(B(s,p,g,A,C,t)))});let m=e.resolveComponentEnhancers(s);r.push(S(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:d)(()=>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:d)(()=>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 S(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?d:(i=a.limitPolicy)!=null?i:d)(async()=>a.enhanceOne({component:o,context:n}));s!=null&&(o.data[r]=s)}catch(c){let s=`Component ${E(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 B(o,e,t,n,r,a){var i;try{let s=await(r.completeAll?d:(i=r.limitPolicy)!=null?i:d)(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 ${E(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 te=(o,...e)=>({enhanceOne:n=>{let r=o.enhanceOne(n);for(let a of e){let i=O(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:()=>{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=(n=o.completeAll)==null?void 0:n.call(o))!=null?r:Promise.resolve(0)}});function O(o){return!!o&&(typeof o=="object"||typeof o=="function")&&typeof o.then=="function"}var oe=o=>o.startsWith("$");function ie(o){return o?o.map((e,t)=>{var a,i,c;let n=(i=(a=e.parameters)==null?void 0:a[f])==null?void 0:i.value,r=(c=n==null?void 0:n.id)!=null?c:"testId"in e?e.testId:`pz-${t}-${e.type}`;return{...e,id:r,pz:n==null?void 0:n.pz}}):[]}function me(o){return o?o.map((e,t)=>{var a,i,c;let n=(i=(a=e.parameters)==null?void 0:a[f])==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,testDistribution:n==null?void 0:n.testDistribution}}):[]}var x="https://js.pusher.com/7.0.3/pusher.min.js";async function M(){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="${x}"><\/script> manually.`)},5e3),n=document.createElement("script");n.src=x,n.addEventListener("load",()=>{clearTimeout(t),o(window.Pusher)}),document.head.appendChild(n)})}async function ue(){let o=await M();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 b(o,e,t){return`${o}.${e}@${t}`}function ye({projectId:o,compositionId:e,compositionState:t=0,eventBus:{subscribe:n},callback:r,event:a="updated"}){let i=b(o,e,t),c=n(i),s=c.addEventHandler(a,r);return()=>{s(),c.unsubscribe()}}function $({component:o}){var n;let e={},t=(n=o.slots)==null?void 0:n[w];return t==null||t.forEach(r=>{var i;let a=(i=r.parameters)==null?void 0:i[T];(a==null?void 0:a.value)&&typeof a.value=="string"&&(e[a.value]=e[a.value]||[],e[a.value].push(r))}),e}function ge({composition:o,locale:e}){y(o,(t,n,r)=>{if(t.type===v){let a=$({component:t}),i=typeof e=="string"?e:e({component:t,locales:a}),c;if(i&&(c=a[i]),c==null?void 0:c.length){let[s,...p]=c;r.replaceComponent(s),p.length&&r.insertAfter(p)}else r.removeComponent()}})}export{_ as BatchEntry,z as CANVAS_DRAFT_STATE,H as CANVAS_ENRICHMENT_TAG_PARAM,f as CANVAS_INTENT_TAG_PARAM,T as CANVAS_LOCALE_TAG_PARAM,w as CANVAS_LOCALIZATION_SLOT,v as CANVAS_LOCALIZATION_TYPE,D as CANVAS_PERSONALIZATION_PARAM,V as CANVAS_PERSONALIZE_SLOT,F as CANVAS_PERSONALIZE_TYPE,W as CANVAS_PUBLISHED_STATE,U as CANVAS_TEST_SLOT,N as CANVAS_TEST_TYPE,k as CanvasClient,j as CanvasClientError,P as ChildEnhancerBuilder,R as EnhancerBuilder,I as UniqueBatchEntries,te as compose,q as createBatchEnhancer,ue as createEventBus,L as createLimitPolicy,ee as enhance,$ as extractLocales,b as getChannelName,E as getComponentPath,oe as isSystemComponentDefinition,ge as localize,ie as mapSlotToPersonalizedVariations,me as mapSlotToTestVariations,d as nullLimitPolicy,ye as subscribeToComposition,y as walkComponentTree};
|
package/dist/index.js
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
var V=Object.create;var C=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var b=r=>C(r,"__esModule",{value:!0});var H=(r,e)=>{for(var n in e)C(r,n,{get:e[n],enumerable:!0})},S=(r,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of F(e))!z.call(r,o)&&(n||o!=="default")&&C(r,o,{get:()=>e[o],enumerable:!(t=M(e,o))||t.enumerable});return r},O=(r,e)=>S(b(C(r!=null?V(D(r)):{},"default",!e&&r&&r.__esModule?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r),K=(r=>(e,n)=>r&&r.get(e)||(n=S(b({}),e,1),r&&r.set(e,n),n))(typeof WeakMap!="undefined"?new WeakMap:0);var he={};H(he,{BatchEntry:()=>g,CANVAS_DRAFT_STATE:()=>te,CANVAS_ENRICHMENT_TAG_PARAM:()=>ie,CANVAS_INTENT_TAG_PARAM:()=>y,CANVAS_LOCALE_TAG_PARAM:()=>v,CANVAS_LOCALIZATION_SLOT:()=>w,CANVAS_LOCALIZATION_TYPE:()=>T,CANVAS_PERSONALIZATION_PARAM:()=>re,CANVAS_PERSONALIZE_SLOT:()=>ee,CANVAS_PERSONALIZE_TYPE:()=>Q,CANVAS_PUBLISHED_STATE:()=>oe,CANVAS_TEST_SLOT:()=>ne,CANVAS_TEST_TYPE:()=>X,CanvasClient:()=>U,CanvasClientError:()=>f,ChildEnhancerBuilder:()=>P,EnhancerBuilder:()=>N,UniqueBatchEntries:()=>L,compose:()=>J,createBatchEnhancer:()=>q,createEventBus:()=>me,createLimitPolicy:()=>I,enhance:()=>G,extractLocales:()=>k,getChannelName:()=>_,getComponentPath:()=>A,isSystemComponentDefinition:()=>se,localize:()=>ue,mapSlotToPersonalizedVariations:()=>ae,mapSlotToTestVariations:()=>ce,nullLimitPolicy:()=>u,subscribeToComposition:()=>le,walkComponentTree:()=>d});function d(r,e){let n=[{ancestorsAndSelf:[{component:r,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let t=n.pop();if(!t)continue;let o=t.ancestorsAndSelf[0];e(o.component,t.ancestorsAndSelf,{replaceComponent:s=>{Object.assign(o.component,s),["parameters","variant","slots","data","_pattern","_patternError"].forEach(a=>{s[a]||delete o.component[a]})},removeComponent:()=>{let{parentSlot:s,parentSlotIndex:c}=t.ancestorsAndSelf[0],a=t.ancestorsAndSelf[1];if(s&&typeof c!="undefined")a.component.slots[s].splice(c,1);else throw new Error("Unable to delete composition.")},insertAfter:s=>{let c=Array.isArray(s)?s:[s],{parentSlot:a,parentSlotIndex:p}=t.ancestorsAndSelf[0],l=t.ancestorsAndSelf[1];if(a&&typeof p!="undefined")l.component.slots[a].splice(p+1,0,...c);else throw new Error("Unable to insert after a component not in a slot.")}});let i=o.component.slots;if(i){let s=Object.keys(i);for(let c=s.length-1;c>=0;c--){let a=s[c],p=i[a];for(let l=p.length-1;l>=0;l--)n.push({ancestorsAndSelf:[{component:p[l],parentSlot:a,parentSlotIndex:l},...t.ancestorsAndSelf]})}}}while(n.length>0)}function A(r){let e=[];for(let n=r.length-1;n>=0;n--){let{parentSlot:t,parentSlotIndex:o}=r[n];t&&o!==void 0&&e.push(`${t}[${o}]`)}return`.${e.join(".")}`}var L=class{constructor(e,n){this.groups=e.reduce((t,o)=>{var s;let i=n(o.args);return t[i]=(s=t[i])!=null?s:[],t[i].push(o),t},{})}resolveKey(e,n){this.groups[e].forEach(t=>t.resolve(n))}resolveRemaining(e){Object.keys(this.groups).forEach(n=>{this.groups[n].forEach(t=>{t.isCompleted||t.resolve(e)})})}};var P=class{constructor(){this._paramMatches=Array();this._dataMatches=new Map}parameter(e){return this._paramMatches.push({enhancer:this._resolveParameterEnhancer(e)}),this}parameterName(e,n){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({name:o,enhancer:this._resolveParameterEnhancer(n)})),this}parameterType(e,n){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({type:o,enhancer:this._resolveParameterEnhancer(n)})),this}data(e,n){if(this._dataMatches.has(e))throw new Error(`${e} enhancer data key has been used more than once. This will cause data loss.`);return this._dataMatches.set(e,typeof n=="function"?{enhanceOne:n}:n),this}resolveParameterEnhancer(e,n){var t;return(t=this._paramMatches.find(o=>o.name&&o.name===e||o.type&&o.type===n.type||!o.type&&!o.name))==null?void 0:t.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},N=class{constructor(){this._componentIndex={};this._rootBuilder=new P}parameter(e){return this._rootBuilder.parameter(e),this}parameterName(e,n){return this._rootBuilder.parameterName(e,n),this}parameterType(e,n){return this._rootBuilder.parameterType(e,n),this}data(e,n){return this._rootBuilder.data(e,n),this}component(e,n){return(Array.isArray(e)?e:[e]).forEach(o=>{this._componentIndex[o]=this._componentIndex[o]||new P,n(this._componentIndex[o])}),this}resolveParameterEnhancer(e,n,t){let o=this._componentIndex[e.type];if(o){let i=o.resolveParameterEnhancer(n,t);if(i)return i}return this._rootBuilder.resolveParameterEnhancer(n,t)}resolveComponentEnhancers(e){let n=this._rootBuilder.resolveComponentEnhancers(),t=this._componentIndex[e.type];if(t){n=new Map(n);for(let[o,i]of t.resolveComponentEnhancers())n.set(o,i)}return n}};var g=class{constructor(e,n,t){this._resolve=e;this._reject=n;this.args=t;this._isCompleted=!1}resolve(e){this._resolve(e),this._isCompleted=!0}reject(e){this._reject(e),this._isCompleted=!0}get isCompleted(){return this._isCompleted}};function q({handleBatch:r,shouldQueue:e,limitPolicy:n}){let t=[];return{enhanceOne:async s=>{if(!e||e(s))return new Promise((c,a)=>{t.push(new g(c,a,s))})},completeAll:async()=>{if(t.length>0){try{await r(t)}catch(c){t.forEach(a=>a.reject(c))}if(t.some(c=>!c.isCompleted))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!")}let s=t.length;return t=[],s},limitPolicy:n}}var j=O(require("p-throttle")),B=O(require("p-retry"));function I({throttle:r={interval:1e3,limit:10},retry:e={retries:1,factor:1.66}}){let n=r?(0,j.default)(r):null;return function(o){let i=async()=>await o();if(n&&(i=n(i)),e){let s=i;i=()=>(0,B.default)(s,e)}return i()}}var u=async r=>await r();async function G({composition:r,enhancers:e,context:n,onErrors:t=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;d(r,(a,p)=>{var h;Object.entries((h=a.parameters)!=null?h:{}).forEach(([x,R])=>{let E=e.resolveParameterEnhancer(a,x,R);E&&(s.add(E),o.push(Y(a,p,x,R,E,n)))});let l=e.resolveComponentEnhancers(a);o.push(Z(a,p,l,n)),i.add(l)}),o.push(...Array.from(i).flatMap(a=>Array.from(a).map(async([,p])=>{var l;try{p.completeAll&&await((l=p.limitPolicy)!=null?l:u)(()=>p.completeAll())}catch(h){return{error:h,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),o.push(...Array.from(s).map(async a=>{var p;try{a.completeAll&&await((p=a.limitPolicy)!=null?p:u)(()=>a.completeAll())}catch(l){return{error:l,message:"Batch parameter enhancer failed. Individual failed parameters should receive their own rejections."}}}));let c=(await Promise.all(o)).flatMap(a=>Array.isArray(a)?a:[a]).filter(a=>a);c.length&&t(c)}async function Z(r,e,n,t){return n.size&&(r.data={}),await Promise.all(Array.from(n).map(async([o,i])=>{var s;try{let a=await(i.completeAll?u:(s=i.limitPolicy)!=null?s:u)(async()=>i.enhanceOne({component:r,context:t}));a!=null&&(r.data[o]=a)}catch(c){let a=`Component ${A(e)} (type: ${r.type}): data.${o} enhancer threw exception. Data key will not be present.`;return delete r.data[o],{message:a,error:c}}}))}async function Y(r,e,n,t,o,i){var s;try{let a=await(o.completeAll?u:(s=o.limitPolicy)!=null?s:u)(async()=>o.enhanceOne({parameter:t,parameterName:n,component:r,context:i}));a===null?delete r.parameters[n]:typeof a=="undefined"?r.parameters[n]={...t,value:t.value}:r.parameters[n]={...t,value:a}}catch(c){let a=`Component ${A(e)} (type: ${r.type}): enhancing parameter ${n} (type: ${t.type}) threw exception. Parameter will be removed.`;return delete r.parameters[n],{message:a,error:c}}}var J=(r,...e)=>({enhanceOne:t=>{let o=r.enhanceOne(t);for(let i of e){let s=W(o)?o:Promise.resolve(o),c="enhanceOne"in i?i.enhanceOne:i;o=s.then(a=>c({...t,parameter:{type:t.parameter.type,value:a}}))}return o},completeAll:()=>{var t,o;for(let i of e)if("completeAll"in i)throw new Error("Only the first enhancer in a compose chain can use the completeAll function (batching)");return(o=(t=r.completeAll)==null?void 0:t.call(r))!=null?o:Promise.resolve(0)}});function W(r){return!!r&&(typeof r=="object"||typeof r=="function")&&typeof r.then=="function"}var f=class extends Error{constructor(e,n,t,o,i){super(`${e}
|
5
|
+
${o}${i?" "+i:""} (${n} ${t})`);this.errorMessage=e;this.fetchMethod=n;this.fetchUri=t;this.statusCode=o;this.statusText=i;Object.setPrototypeOf(this,f.prototype)}},U=class{constructor(e){var t,o,i,s,c;if(!e.apiKey&&!e.bearerToken)throw new Error("You must provide an API key or a bearer token");let n=e.fetch;if(!n)if(typeof window!="undefined")n=window.fetch.bind(window);else if(typeof fetch!="undefined")n=fetch;else throw new Error("You must provide or polyfill a fetch implementation when not in a browser");this.options={...e,fetch:n,apiHost:(t=e.apiHost)!=null?t:"https://uniform.app",apiKey:(o=e.apiKey)!=null?o:null,projectId:(i=e.projectId)!=null?i:null,bearerToken:(s=e.bearerToken)!=null?s:null,limitPolicy:(c=e.limitPolicy)!=null?c:I({})}}async getCompositionList(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async getCompositionBySlug(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async getCompositionById(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async updateComposition(e){let n=this.createUrl("/api/v1/canvas");await this.apiClient(n,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(e){let n=this.createUrl("/api/v1/canvas");await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async getComponentDefinitions(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas-definitions",{...e,projectId:n});return await this.apiClient(t)}async updateComponentDefinition(e){let n=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(n,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(e){let n=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(e,n){return this.options.limitPolicy(async()=>{var i;let t=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`},o=await this.options.fetch(e.toString(),{...n,headers:{...n==null?void 0:n.headers,...t}});if(!o.ok){let s="";try{let c=await o.text();try{let a=JSON.parse(c);a.errorMessage?s=Array.isArray(a.errorMessage)?a.errorMessage.join(", "):a.errorMessage:s=c}catch(a){s=c}}catch(c){s="General error"}throw new f(s,(i=n==null?void 0:n.method)!=null?i:"GET",e.toString(),o.status)}return(n==null?void 0:n.expectNoContent)?null:await o.json()})}createUrl(e,n){let t=new URL(`${this.options.apiHost}${e}`);return Object.entries(n!=null?n:{}).forEach(([o,i])=>{var s;typeof i!==void 0&&i!==null&&t.searchParams.append(o,(s=i==null?void 0:i.toString())!=null?s:"")}),t}};var Q="$personalization",X="$test",T="$localization",y="intentTag",v="locale",ee="pz",ne="test",w="localized",te=0,oe=64,re="$pzCrit",ie="$enr";var se=r=>r.startsWith("$");function ae(r){return r?r.map((e,n)=>{var i,s,c;let t=(s=(i=e.parameters)==null?void 0:i[y])==null?void 0:s.value,o=(c=t==null?void 0:t.id)!=null?c:"testId"in e?e.testId:`pz-${n}-${e.type}`;return{...e,id:o,pz:t==null?void 0:t.pz}}):[]}function ce(r){return r?r.map((e,n)=>{var i,s,c;let t=(s=(i=e.parameters)==null?void 0:i[y])==null?void 0:s.value,o=(c=t==null?void 0:t.id)!=null?c:"testId"in e?e.testId:`ab-${n}-${e.type}`;return{...e,id:o,testDistribution:t==null?void 0:t.testDistribution}}):[]}var $="https://js.pusher.com/7.0.3/pusher.min.js";async function pe(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((r,e)=>{let n=setTimeout(()=>{window.Pusher&&r(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${$}"><\/script> manually.`)},5e3),t=document.createElement("script");t.src=$,t.addEventListener("load",()=>{clearTimeout(n),r(window.Pusher)}),document.head.appendChild(t)})}async function me(){let r=await pe();if(!r)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let n=new r("7b5f5abd160fea549ffe",{cluster:"mt1"});n.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:t=>{let o=n.subscribe(t);return{unsubscribe:()=>n.unsubscribe(t),addEventHandler:(i,s)=>(o.bind(i,s),()=>o.unbind(i,s))}}}}return e}function _(r,e,n){return`${r}.${e}@${n}`}function le({projectId:r,compositionId:e,compositionState:n=0,eventBus:{subscribe:t},callback:o,event:i="updated"}){let s=_(r,e,n),c=t(s),a=c.addEventHandler(i,o);return()=>{a(),c.unsubscribe()}}function k({component:r}){var t;let e={},n=(t=r.slots)==null?void 0:t[w];return n==null||n.forEach(o=>{var s;let i=(s=o.parameters)==null?void 0:s[v];(i==null?void 0:i.value)&&typeof i.value=="string"&&(e[i.value]=e[i.value]||[],e[i.value].push(o))}),e}function ue({composition:r,locale:e}){d(r,(n,t,o)=>{if(n.type===T){let i=k({component:n}),s=typeof e=="string"?e:e({component:n,locales:i}),c;if(s&&(c=i[s]),c==null?void 0:c.length){let[a,...p]=c;o.replaceComponent(a),p.length&&o.insertAfter(p)}else o.removeComponent()}})}module.exports=K(he);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,CanvasClient,CanvasClientError,ChildEnhancerBuilder,EnhancerBuilder,UniqueBatchEntries,compose,createBatchEnhancer,createEventBus,createLimitPolicy,enhance,extractLocales,getChannelName,getComponentPath,isSystemComponentDefinition,localize,mapSlotToPersonalizedVariations,mapSlotToTestVariations,nullLimitPolicy,subscribeToComposition,walkComponentTree});
|
package/dist/index.mjs
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
import{a as L,b as d,c as j,d as k,e as F,f as N,g as v,h as f,i as T,j as V,k as U,l as w,m as z,n as W,o as D,p as H}from"./chunk-A4MBTKCQ.mjs";function y(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 E(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 I=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 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(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}},R=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(r=>{this._componentIndex[r]=this._componentIndex[r]||new P,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 _=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 q({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,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 ee({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;y(o,(s,p)=>{var h;Object.entries((h=s.parameters)!=null?h:{}).forEach(([g,A])=>{let C=e.resolveParameterEnhancer(s,g,A);C&&(i.add(C),r.push(B(s,p,g,A,C,t)))});let m=e.resolveComponentEnhancers(s);r.push(S(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:d)(()=>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:d)(()=>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 S(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?d:(i=a.limitPolicy)!=null?i:d)(async()=>a.enhanceOne({component:o,context:n}));s!=null&&(o.data[r]=s)}catch(c){let s=`Component ${E(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 B(o,e,t,n,r,a){var i;try{let s=await(r.completeAll?d:(i=r.limitPolicy)!=null?i:d)(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 ${E(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 te=(o,...e)=>({enhanceOne:n=>{let r=o.enhanceOne(n);for(let a of e){let i=O(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:()=>{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=(n=o.completeAll)==null?void 0:n.call(o))!=null?r:Promise.resolve(0)}});function O(o){return!!o&&(typeof o=="object"||typeof o=="function")&&typeof o.then=="function"}var oe=o=>o.startsWith("$");function ie(o){return o?o.map((e,t)=>{var a,i,c;let n=(i=(a=e.parameters)==null?void 0:a[f])==null?void 0:i.value,r=(c=n==null?void 0:n.id)!=null?c:"testId"in e?e.testId:`pz-${t}-${e.type}`;return{...e,id:r,pz:n==null?void 0:n.pz}}):[]}function me(o){return o?o.map((e,t)=>{var a,i,c;let n=(i=(a=e.parameters)==null?void 0:a[f])==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,testDistribution:n==null?void 0:n.testDistribution}}):[]}var x="https://js.pusher.com/7.0.3/pusher.min.js";async function M(){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="${x}"><\/script> manually.`)},5e3),n=document.createElement("script");n.src=x,n.addEventListener("load",()=>{clearTimeout(t),o(window.Pusher)}),document.head.appendChild(n)})}async function ue(){let o=await M();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 b(o,e,t){return`${o}.${e}@${t}`}function ye({projectId:o,compositionId:e,compositionState:t=0,eventBus:{subscribe:n},callback:r,event:a="updated"}){let i=b(o,e,t),c=n(i),s=c.addEventHandler(a,r);return()=>{s(),c.unsubscribe()}}function $({component:o}){var n;let e={},t=(n=o.slots)==null?void 0:n[w];return t==null||t.forEach(r=>{var i;let a=(i=r.parameters)==null?void 0:i[T];(a==null?void 0:a.value)&&typeof a.value=="string"&&(e[a.value]=e[a.value]||[],e[a.value].push(r))}),e}function ge({composition:o,locale:e}){y(o,(t,n,r)=>{if(t.type===v){let a=$({component:t}),i=typeof e=="string"?e:e({component:t,locales:a}),c;if(i&&(c=a[i]),c==null?void 0:c.length){let[s,...p]=c;r.replaceComponent(s),p.length&&r.insertAfter(p)}else r.removeComponent()}})}export{_ as BatchEntry,z as CANVAS_DRAFT_STATE,H as CANVAS_ENRICHMENT_TAG_PARAM,f as CANVAS_INTENT_TAG_PARAM,T as CANVAS_LOCALE_TAG_PARAM,w as CANVAS_LOCALIZATION_SLOT,v as CANVAS_LOCALIZATION_TYPE,D as CANVAS_PERSONALIZATION_PARAM,V as CANVAS_PERSONALIZE_SLOT,F as CANVAS_PERSONALIZE_TYPE,W as CANVAS_PUBLISHED_STATE,U as CANVAS_TEST_SLOT,N as CANVAS_TEST_TYPE,k as CanvasClient,j as CanvasClientError,P as ChildEnhancerBuilder,R as EnhancerBuilder,I as UniqueBatchEntries,te as compose,q as createBatchEnhancer,ue as createEventBus,L as createLimitPolicy,ee as enhance,$ as extractLocales,b as getChannelName,E as getComponentPath,oe as isSystemComponentDefinition,ge as localize,ie as mapSlotToPersonalizedVariations,me as mapSlotToTestVariations,d as nullLimitPolicy,ye as subscribeToComposition,y as walkComponentTree};
|
package/package.json
CHANGED
@@ -1,68 +1,69 @@
|
|
1
1
|
{
|
2
2
|
"name": "@uniformdev/canvas",
|
3
|
-
"version": "12.
|
3
|
+
"version": "12.2.1-alpha.121+3d33c2be",
|
4
4
|
"description": "Common functionality and types for Uniform Canvas",
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
6
|
-
"main": "./dist/
|
7
|
-
"module": "./dist/
|
6
|
+
"main": "./dist/index.js",
|
7
|
+
"module": "./dist/index.esm.js",
|
8
8
|
"exports": {
|
9
9
|
".": {
|
10
|
-
"import":
|
11
|
-
|
10
|
+
"import": {
|
11
|
+
"node": "./dist/index.mjs",
|
12
|
+
"default": "./dist/index.esm.js"
|
13
|
+
},
|
14
|
+
"require": "./dist/index.js"
|
12
15
|
},
|
13
16
|
"./cli": {
|
14
|
-
"import": "./dist/
|
15
|
-
"require": "./dist/
|
17
|
+
"import": "./dist/cli/cli.mjs",
|
18
|
+
"require": "./dist/cli/cli.js"
|
16
19
|
}
|
17
20
|
},
|
21
|
+
"types": "./dist/index.d.ts",
|
18
22
|
"typesVersions": {
|
19
23
|
"*": {
|
20
|
-
"
|
21
|
-
"./dist/
|
24
|
+
"*": [
|
25
|
+
"./dist/index.d.ts"
|
22
26
|
],
|
23
27
|
"cli": [
|
24
|
-
"./dist/
|
28
|
+
"./dist/cli/cli.d.ts"
|
25
29
|
]
|
26
30
|
}
|
27
31
|
},
|
28
32
|
"sideEffects": false,
|
29
33
|
"scripts": {
|
30
|
-
"build": "
|
31
|
-
"
|
32
|
-
"build:cjs": "tsc -p ./tsconfig.cjs.json",
|
33
|
-
"dev": "run-p dev:esm dev:cjs",
|
34
|
-
"dev:esm": "tsc -w",
|
35
|
-
"dev:cjs": "tsc -w -p ./tsconfig.cjs.json",
|
34
|
+
"build": "tsup",
|
35
|
+
"dev": "tsup --watch",
|
36
36
|
"clean": "rimraf dist",
|
37
37
|
"test": "jest --maxWorkers=1",
|
38
38
|
"lint": "eslint \"src/**/*.{js,ts,tsx}\"",
|
39
39
|
"format": "prettier --write \"src/**/*.{js,ts,tsx}\"",
|
40
40
|
"ci:verify": "run-p lint test",
|
41
|
-
"ci:build": "
|
41
|
+
"ci:build": "tsup --minify --clean"
|
42
42
|
},
|
43
43
|
"devDependencies": {
|
44
|
-
"@types/diff": "5.0.
|
45
|
-
"@types/jest": "27.0
|
46
|
-
"@types/js-yaml": "4.0.
|
44
|
+
"@types/diff": "5.0.2",
|
45
|
+
"@types/jest": "27.4.0",
|
46
|
+
"@types/js-yaml": "4.0.5",
|
47
47
|
"@types/lodash.isequalwith": "4.4.6",
|
48
|
-
"@types/node": "16.
|
49
|
-
"@types/yargs": "17.0.
|
50
|
-
"@uniformdev/cli": "^12.
|
51
|
-
"eslint": "
|
52
|
-
"eslint-plugin-react": "7.
|
53
|
-
"eslint-plugin-react-hooks": "4.
|
54
|
-
"jest": "27.
|
48
|
+
"@types/node": "16.11.19",
|
49
|
+
"@types/yargs": "17.0.8",
|
50
|
+
"@uniformdev/cli": "^12.2.1-alpha.121+3d33c2be",
|
51
|
+
"eslint": "8.6.0",
|
52
|
+
"eslint-plugin-react": "7.28.0",
|
53
|
+
"eslint-plugin-react-hooks": "4.3.0",
|
54
|
+
"jest": "27.4.7",
|
55
55
|
"npm-run-all": "4.1.5",
|
56
|
+
"pusher-js": "7.0.3",
|
56
57
|
"rimraf": "3.0.2",
|
57
|
-
"ts-jest": "27.
|
58
|
-
"
|
58
|
+
"ts-jest": "27.1.2",
|
59
|
+
"tsup": "5.11.11",
|
60
|
+
"yargs": "17.3.1"
|
59
61
|
},
|
60
62
|
"peerDependencies": {
|
61
63
|
"yargs": "^17.0.1"
|
62
64
|
},
|
63
65
|
"dependencies": {
|
64
|
-
"@uniformdev/
|
65
|
-
"@uniformdev/optimize-tracker-common": "^12.0.1-alpha.94+0290763c",
|
66
|
+
"@uniformdev/context": "^12.2.1-alpha.121+3d33c2be",
|
66
67
|
"chalk": "^4.1.2",
|
67
68
|
"diff": "^5.0.0",
|
68
69
|
"isomorphic-unfetch": "^3.1.0",
|
@@ -70,8 +71,7 @@
|
|
70
71
|
"lodash.isequalwith": "^4.4.0",
|
71
72
|
"p-limit": "^3.1.0",
|
72
73
|
"p-retry": "^4.6.1",
|
73
|
-
"p-throttle": "^4.1.1"
|
74
|
-
"pusher-js": ">=7.0.3"
|
74
|
+
"p-throttle": "^4.1.1"
|
75
75
|
},
|
76
76
|
"files": [
|
77
77
|
"/dist"
|
@@ -79,5 +79,5 @@
|
|
79
79
|
"publishConfig": {
|
80
80
|
"access": "public"
|
81
81
|
},
|
82
|
-
"gitHead": "
|
82
|
+
"gitHead": "3d33c2be484210ce3f056e80176fc6f56b69dabc"
|
83
83
|
}
|
@@ -1,50 +0,0 @@
|
|
1
|
-
import { LimitPolicy } from './enhancement/createLimitPolicy';
|
2
|
-
import { ComponentDefinitionAPIDeleteRequest, ComponentDefinitionAPIPutRequest, ComponentDefinitionAPIResponse, ComponentDefinitionListAPIOptions } from './types/componentDefinitions';
|
3
|
-
import { CompositionAPIDeleteRequest, CompositionAPIOptions, CompositionAPIPutRequest, CompositionAPIResponse, CompositionListAPIResponse } from './types/componentInstances';
|
4
|
-
export declare type CanvasClientOptions = {
|
5
|
-
/** The Uniform API host to use. Internal use. */
|
6
|
-
apiHost?: string;
|
7
|
-
/** The Uniform API key to use when sending API requests. This or bearer token must be specified. */
|
8
|
-
apiKey?: string | null;
|
9
|
-
/** The Uniform bearer token to use. Internal use. */
|
10
|
-
bearerToken?: string | null;
|
11
|
-
/** The Uniform project ID to connect to */
|
12
|
-
projectId?: string | null;
|
13
|
-
/** Specify a fetch implementation to use when fetching data. Useful if you want to only polyfill selectively. */
|
14
|
-
fetch?: typeof fetch;
|
15
|
-
/**
|
16
|
-
* Specify how to retry and throttle requests.
|
17
|
-
* Default: retry 3x on failures with exponential backoff, up to 10 requests per second.
|
18
|
-
* Use createLimitPolicy() to help creating a policy. */
|
19
|
-
limitPolicy?: LimitPolicy;
|
20
|
-
};
|
21
|
-
export declare class CanvasClientError extends Error {
|
22
|
-
errorMessage: string;
|
23
|
-
fetchMethod: string;
|
24
|
-
fetchUri: string;
|
25
|
-
statusCode?: number | undefined;
|
26
|
-
statusText?: string | undefined;
|
27
|
-
constructor(errorMessage: string, fetchMethod: string, fetchUri: string, statusCode?: number | undefined, statusText?: string | undefined);
|
28
|
-
}
|
29
|
-
export declare class CanvasClient {
|
30
|
-
private options;
|
31
|
-
constructor(options: CanvasClientOptions);
|
32
|
-
/** Fetches lists of Canvas compositions, optionally by type */
|
33
|
-
getCompositionList(options?: Omit<CompositionAPIOptions, 'projectId'>): Promise<CompositionListAPIResponse>;
|
34
|
-
/** Fetches a Canvas composition by string name (slug) */
|
35
|
-
getCompositionBySlug(options: Pick<CompositionAPIOptions, 'slug' | 'state' | 'skipEnhance' | 'skipPatternResolution'>): Promise<CompositionAPIResponse>;
|
36
|
-
/** Fetches a Canvas composition by its public UUID */
|
37
|
-
getCompositionById(options: Pick<CompositionAPIOptions, 'compositionId' | 'state' | 'skipEnhance' | 'skipPatternResolution'>): Promise<CompositionAPIResponse>;
|
38
|
-
/** Updates or creates a Canvas component definition */
|
39
|
-
updateComposition(body: Omit<CompositionAPIPutRequest, 'projectId'>): Promise<void>;
|
40
|
-
/** Deletes a Canvas component definition */
|
41
|
-
removeComposition(body: Omit<CompositionAPIDeleteRequest, 'projectId'>): Promise<void>;
|
42
|
-
/** Fetches all Canvas component definitions */
|
43
|
-
getComponentDefinitions(options?: Omit<ComponentDefinitionListAPIOptions, 'projectId'>): Promise<ComponentDefinitionAPIResponse>;
|
44
|
-
/** Updates or creates a Canvas component definition */
|
45
|
-
updateComponentDefinition(body: Omit<ComponentDefinitionAPIPutRequest, 'projectId'>): Promise<void>;
|
46
|
-
/** Deletes a Canvas component definition */
|
47
|
-
removeComponentDefinition(body: Omit<ComponentDefinitionAPIDeleteRequest, 'projectId'>): Promise<void>;
|
48
|
-
private apiClient;
|
49
|
-
private createUrl;
|
50
|
-
}
|