@uniformdev/next-app-router-shared 20.7.1-alpha.118

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 ADDED
@@ -0,0 +1,2 @@
1
+ © 2024 Uniform Systems, Inc. All Rights Reserved.
2
+ See details of Uniform Systems, Inc. Master Subscription Agreement here: https://uniform.dev/eula
@@ -0,0 +1,271 @@
1
+ import { ComponentParameter as ComponentParameter$1, VisibilityParameterValue, CANVAS_PERSONALIZATION_PARAM, ComponentInstance } from '@uniformdev/canvas';
2
+ import { PersonalizedVariant, VariationMatchMetadata, PersonalizeOptions, Context, PersonalizationEvent, TestVariant, TestOptions, TestEvent, VariantMatchCriteria } from '@uniformdev/context';
3
+ import { ReactNode } from 'react';
4
+
5
+ type ComponentContext = {
6
+ _id: string;
7
+ _parentId: string | null;
8
+ slotName: string | undefined;
9
+ slotIndex: number | undefined;
10
+ };
11
+
12
+ type ComponentParameter<TValue = unknown> = ComponentParameter$1<TValue> & {
13
+ parameterId: string;
14
+ _contextualEditing?: {
15
+ isEditable: boolean;
16
+ };
17
+ };
18
+
19
+ type PageStateComponentFields = {
20
+ indexes?: number[];
21
+ };
22
+ type PageStateComponent = {
23
+ _id: string;
24
+ } & PageStateComponentFields;
25
+ type PageState = {
26
+ /**
27
+ * The state of the composition
28
+ */
29
+ compositionState: number;
30
+ /**
31
+ * The route path that was matched
32
+ */
33
+ routePath: string;
34
+ /**
35
+ * The components in the page state.
36
+ * NOTE: Key might contain partial component ids so use {@link resolveComponentFromPageState} to resolve data.
37
+ * @deprecated Use {@link resolveComponentFromPageState} instead.
38
+ */
39
+ components: Record<string, PageStateComponentFields>;
40
+ /**
41
+ * Whether a rule is true or false.
42
+ * NOTE: Key is a compressed hash of the rule and cannot be looked up directly from this object.
43
+ */
44
+ rules: Record<string, boolean> | undefined;
45
+ /**
46
+ * Keys to federate cache IDs on.
47
+ */
48
+ keys: Record<string, string> | undefined;
49
+ /**
50
+ * Release ID to resolve the route from.
51
+ */
52
+ releaseId: string | undefined;
53
+ /**
54
+ * Default consent for the current request. Only specified if middleware was passed a value for {@link HandleOptions.defaultConsent}.
55
+ */
56
+ defaultConsent: boolean | undefined;
57
+ /**
58
+ * While in Canvas Editing mode, this will be set to 'editor'.
59
+ * While in Canvas Preview mode, this will be set to 'preview'.
60
+ * While in Published mode, this will be undefined.
61
+ */
62
+ previewMode: 'editor' | 'preview' | undefined;
63
+ };
64
+ declare const resolveComponentFromPageState: ({ pageState, componentId: providedComponentId, }: {
65
+ pageState: PageState;
66
+ componentId: string;
67
+ }) => PageStateComponentFields;
68
+ declare const getRuleId: (rule: VisibilityParameterValue) => string;
69
+ declare const resolveRuleFromPageState: ({ pageState, rule, }: {
70
+ pageState: PageState;
71
+ rule: VisibilityParameterValue;
72
+ }) => boolean | undefined;
73
+ declare const serializeEvaluationResult: ({ payload, encode, }: {
74
+ payload: PageState;
75
+ encode?: boolean;
76
+ }) => string;
77
+ declare const deserializeEvaluationResult: ({ input: providedInput, decode, }: {
78
+ input: string;
79
+ decode?: boolean;
80
+ }) => PageState;
81
+
82
+ type CompositionContext = {
83
+ _id: string;
84
+ type: string;
85
+ state: number;
86
+ isContextualEditing: boolean;
87
+ /** Matched route from Project Map node. */
88
+ matchedRoute: string;
89
+ /** Dynamic inputs for the composition from the route path: path segment and query string parameters. */
90
+ dynamicInputs: Record<string, string>;
91
+ pageState: PageState;
92
+ };
93
+
94
+ type IndexedPersonalizationVariant = PersonalizedVariant<VariationMatchMetadata> & {
95
+ componentId: string;
96
+ index: number;
97
+ };
98
+ declare const evaluatePersonalization: ({ personalization, context, compositionContext, }: {
99
+ personalization: PersonalizeOptions<IndexedPersonalizationVariant>;
100
+ context: Context;
101
+ compositionContext: CompositionContext;
102
+ }) => {
103
+ indexes: number[];
104
+ componentIds: string[];
105
+ event: PersonalizationEvent;
106
+ };
107
+
108
+ type IndexedTestVariant = TestVariant & {
109
+ componentId: string;
110
+ index: number;
111
+ };
112
+ declare const evaluateTest: ({ test, context, compositionContext, }: {
113
+ test: TestOptions<IndexedTestVariant>;
114
+ context: Context;
115
+ compositionContext: CompositionContext;
116
+ }) => {
117
+ index: number | null;
118
+ componentId: string | null;
119
+ event: TestEvent | null;
120
+ };
121
+
122
+ type ExtractPersonalizationVariant = IndexedPersonalizationVariant;
123
+ type ExtractPersonalizationResult = PersonalizeOptions<ExtractPersonalizationVariant>;
124
+ type ExtractTestVariant = IndexedTestVariant;
125
+ type ExtractTestResult = TestOptions<ExtractTestVariant>;
126
+
127
+ type SlotDefinition = {
128
+ name: string;
129
+ items: ({
130
+ _id: string;
131
+ [CANVAS_PERSONALIZATION_PARAM]: VariantMatchCriteria | undefined;
132
+ /**
133
+ * Only populated for variants of tests or personalizations
134
+ */
135
+ variantId: string | undefined;
136
+ component: ReactNode;
137
+ } | null)[];
138
+ };
139
+
140
+ type ComponentProps<TParameters extends Record<string, ComponentParameter> | unknown = Record<string, ComponentParameter>, TSlotNames extends string = string> = {
141
+ type: string;
142
+ variant: string | undefined;
143
+ slots: Record<TSlotNames, SlotDefinition>;
144
+ parameters: TParameters;
145
+ component: ComponentContext;
146
+ context: CompositionContext;
147
+ };
148
+ type PersonalizeProps = ComponentProps<{
149
+ algorithm?: ComponentParameter<string>;
150
+ trackingEventName?: ComponentParameter<string>;
151
+ }> & {
152
+ indexes: number[];
153
+ };
154
+ type TestProps = ComponentProps & {
155
+ index: number;
156
+ test: ExtractTestResult;
157
+ };
158
+
159
+ type CacheMode = {
160
+ type: RequestInit['cache'];
161
+ bypassCache?: boolean;
162
+ } | {
163
+ type: 'revalidate';
164
+ interval: number;
165
+ bypassCache?: boolean;
166
+ };
167
+ type ManifestCacheMode = CacheMode;
168
+ type ProjectMapCacheMode = CacheMode;
169
+ type CanvasCacheMode = CacheMode & {
170
+ disableSWR?: boolean;
171
+ };
172
+ type UniformServerConfig = {
173
+ /**
174
+ * Sets the default value of storage consent for new unknown visitors.
175
+ *
176
+ * @default false
177
+ */
178
+ defaultConsent?: boolean;
179
+ /**
180
+ * The path to the playground page.
181
+ */
182
+ playgroundPath?: string;
183
+ /**
184
+ * Cache mode for manifest data.
185
+ *
186
+ */
187
+ manifestCache?: ManifestCacheMode;
188
+ /**
189
+ * Cache mode for canvas data.
190
+ *
191
+ */
192
+ canvasCache?: CanvasCacheMode;
193
+ /**
194
+ * Cache mode for project map data.
195
+ *
196
+ */
197
+ projectMapCache?: ProjectMapCacheMode;
198
+ eTags?: {
199
+ /**
200
+ * Generate ETags for published compositions.
201
+ *
202
+ * @default false
203
+ */
204
+ generateETags?: boolean;
205
+ /**
206
+ * Cache control header for pages that have ETags.
207
+ *
208
+ * @default 'no-cache, must-revalidate'
209
+ */
210
+ cacheControl?: string | null;
211
+ };
212
+ /**
213
+ * Options for Uniform Context
214
+ */
215
+ context?: {
216
+ /**
217
+ * Disables the Uniform Context dev tools.
218
+ *
219
+ * @default false
220
+ */
221
+ disableDevTools?: boolean;
222
+ };
223
+ /**
224
+ * 😅
225
+ */
226
+ experimental?: {
227
+ /**
228
+ * Enables quirk serialization for Uniform Context.
229
+ *
230
+ * @default false
231
+ */
232
+ quirkSerialization?: boolean;
233
+ /**
234
+ * Enables visual editing mode.
235
+ *
236
+ * @default false
237
+ */
238
+ vercelVisualEditing?: boolean;
239
+ /**
240
+ * Enables runtime cache in middleware.
241
+ *
242
+ * @default false
243
+ */
244
+ middlewareRuntimeCache?: boolean;
245
+ /**
246
+ * Requires middlewareRuntimeCache to be enabled. If enabled, the middleware will retain a copy
247
+ * of the old route data in cache and use it while the new route data is being fetched.
248
+ *
249
+ * @default false
250
+ */
251
+ disableSwrMiddlewareCache?: boolean;
252
+ };
253
+ };
254
+
255
+ declare const extractPersonalizationName: ({ component, }: {
256
+ component: Pick<ComponentInstance, "parameters">;
257
+ }) => string;
258
+
259
+ declare const extractTestName: ({ component }: {
260
+ component: Pick<ComponentInstance, "parameters">;
261
+ }) => string;
262
+
263
+ type RewriteRequestPathResult = {
264
+ path: string;
265
+ keys?: Record<string, string>;
266
+ };
267
+
268
+ declare const UNIFORM_MIDDLEWARE_SCORE_COOKIE_NAME = "ufsc";
269
+ declare const UNIFORM_MIDDLEWARE_QUIRK_COOKIE_NAME = "ufqc";
270
+
271
+ export { type CacheMode, type CanvasCacheMode, type ComponentContext, type ComponentParameter, type ComponentProps, type CompositionContext, type ExtractPersonalizationResult, type ExtractPersonalizationVariant, type ExtractTestResult, type ExtractTestVariant, type IndexedPersonalizationVariant, type IndexedTestVariant, type ManifestCacheMode, type PageState, type PageStateComponent, type PageStateComponentFields, type PersonalizeProps, type ProjectMapCacheMode, type RewriteRequestPathResult, type SlotDefinition, type TestProps, UNIFORM_MIDDLEWARE_QUIRK_COOKIE_NAME, UNIFORM_MIDDLEWARE_SCORE_COOKIE_NAME, type UniformServerConfig, deserializeEvaluationResult, evaluatePersonalization, evaluateTest, extractPersonalizationName, extractTestName, getRuleId, resolveComponentFromPageState, resolveRuleFromPageState, serializeEvaluationResult };
@@ -0,0 +1,271 @@
1
+ import { ComponentParameter as ComponentParameter$1, VisibilityParameterValue, CANVAS_PERSONALIZATION_PARAM, ComponentInstance } from '@uniformdev/canvas';
2
+ import { PersonalizedVariant, VariationMatchMetadata, PersonalizeOptions, Context, PersonalizationEvent, TestVariant, TestOptions, TestEvent, VariantMatchCriteria } from '@uniformdev/context';
3
+ import { ReactNode } from 'react';
4
+
5
+ type ComponentContext = {
6
+ _id: string;
7
+ _parentId: string | null;
8
+ slotName: string | undefined;
9
+ slotIndex: number | undefined;
10
+ };
11
+
12
+ type ComponentParameter<TValue = unknown> = ComponentParameter$1<TValue> & {
13
+ parameterId: string;
14
+ _contextualEditing?: {
15
+ isEditable: boolean;
16
+ };
17
+ };
18
+
19
+ type PageStateComponentFields = {
20
+ indexes?: number[];
21
+ };
22
+ type PageStateComponent = {
23
+ _id: string;
24
+ } & PageStateComponentFields;
25
+ type PageState = {
26
+ /**
27
+ * The state of the composition
28
+ */
29
+ compositionState: number;
30
+ /**
31
+ * The route path that was matched
32
+ */
33
+ routePath: string;
34
+ /**
35
+ * The components in the page state.
36
+ * NOTE: Key might contain partial component ids so use {@link resolveComponentFromPageState} to resolve data.
37
+ * @deprecated Use {@link resolveComponentFromPageState} instead.
38
+ */
39
+ components: Record<string, PageStateComponentFields>;
40
+ /**
41
+ * Whether a rule is true or false.
42
+ * NOTE: Key is a compressed hash of the rule and cannot be looked up directly from this object.
43
+ */
44
+ rules: Record<string, boolean> | undefined;
45
+ /**
46
+ * Keys to federate cache IDs on.
47
+ */
48
+ keys: Record<string, string> | undefined;
49
+ /**
50
+ * Release ID to resolve the route from.
51
+ */
52
+ releaseId: string | undefined;
53
+ /**
54
+ * Default consent for the current request. Only specified if middleware was passed a value for {@link HandleOptions.defaultConsent}.
55
+ */
56
+ defaultConsent: boolean | undefined;
57
+ /**
58
+ * While in Canvas Editing mode, this will be set to 'editor'.
59
+ * While in Canvas Preview mode, this will be set to 'preview'.
60
+ * While in Published mode, this will be undefined.
61
+ */
62
+ previewMode: 'editor' | 'preview' | undefined;
63
+ };
64
+ declare const resolveComponentFromPageState: ({ pageState, componentId: providedComponentId, }: {
65
+ pageState: PageState;
66
+ componentId: string;
67
+ }) => PageStateComponentFields;
68
+ declare const getRuleId: (rule: VisibilityParameterValue) => string;
69
+ declare const resolveRuleFromPageState: ({ pageState, rule, }: {
70
+ pageState: PageState;
71
+ rule: VisibilityParameterValue;
72
+ }) => boolean | undefined;
73
+ declare const serializeEvaluationResult: ({ payload, encode, }: {
74
+ payload: PageState;
75
+ encode?: boolean;
76
+ }) => string;
77
+ declare const deserializeEvaluationResult: ({ input: providedInput, decode, }: {
78
+ input: string;
79
+ decode?: boolean;
80
+ }) => PageState;
81
+
82
+ type CompositionContext = {
83
+ _id: string;
84
+ type: string;
85
+ state: number;
86
+ isContextualEditing: boolean;
87
+ /** Matched route from Project Map node. */
88
+ matchedRoute: string;
89
+ /** Dynamic inputs for the composition from the route path: path segment and query string parameters. */
90
+ dynamicInputs: Record<string, string>;
91
+ pageState: PageState;
92
+ };
93
+
94
+ type IndexedPersonalizationVariant = PersonalizedVariant<VariationMatchMetadata> & {
95
+ componentId: string;
96
+ index: number;
97
+ };
98
+ declare const evaluatePersonalization: ({ personalization, context, compositionContext, }: {
99
+ personalization: PersonalizeOptions<IndexedPersonalizationVariant>;
100
+ context: Context;
101
+ compositionContext: CompositionContext;
102
+ }) => {
103
+ indexes: number[];
104
+ componentIds: string[];
105
+ event: PersonalizationEvent;
106
+ };
107
+
108
+ type IndexedTestVariant = TestVariant & {
109
+ componentId: string;
110
+ index: number;
111
+ };
112
+ declare const evaluateTest: ({ test, context, compositionContext, }: {
113
+ test: TestOptions<IndexedTestVariant>;
114
+ context: Context;
115
+ compositionContext: CompositionContext;
116
+ }) => {
117
+ index: number | null;
118
+ componentId: string | null;
119
+ event: TestEvent | null;
120
+ };
121
+
122
+ type ExtractPersonalizationVariant = IndexedPersonalizationVariant;
123
+ type ExtractPersonalizationResult = PersonalizeOptions<ExtractPersonalizationVariant>;
124
+ type ExtractTestVariant = IndexedTestVariant;
125
+ type ExtractTestResult = TestOptions<ExtractTestVariant>;
126
+
127
+ type SlotDefinition = {
128
+ name: string;
129
+ items: ({
130
+ _id: string;
131
+ [CANVAS_PERSONALIZATION_PARAM]: VariantMatchCriteria | undefined;
132
+ /**
133
+ * Only populated for variants of tests or personalizations
134
+ */
135
+ variantId: string | undefined;
136
+ component: ReactNode;
137
+ } | null)[];
138
+ };
139
+
140
+ type ComponentProps<TParameters extends Record<string, ComponentParameter> | unknown = Record<string, ComponentParameter>, TSlotNames extends string = string> = {
141
+ type: string;
142
+ variant: string | undefined;
143
+ slots: Record<TSlotNames, SlotDefinition>;
144
+ parameters: TParameters;
145
+ component: ComponentContext;
146
+ context: CompositionContext;
147
+ };
148
+ type PersonalizeProps = ComponentProps<{
149
+ algorithm?: ComponentParameter<string>;
150
+ trackingEventName?: ComponentParameter<string>;
151
+ }> & {
152
+ indexes: number[];
153
+ };
154
+ type TestProps = ComponentProps & {
155
+ index: number;
156
+ test: ExtractTestResult;
157
+ };
158
+
159
+ type CacheMode = {
160
+ type: RequestInit['cache'];
161
+ bypassCache?: boolean;
162
+ } | {
163
+ type: 'revalidate';
164
+ interval: number;
165
+ bypassCache?: boolean;
166
+ };
167
+ type ManifestCacheMode = CacheMode;
168
+ type ProjectMapCacheMode = CacheMode;
169
+ type CanvasCacheMode = CacheMode & {
170
+ disableSWR?: boolean;
171
+ };
172
+ type UniformServerConfig = {
173
+ /**
174
+ * Sets the default value of storage consent for new unknown visitors.
175
+ *
176
+ * @default false
177
+ */
178
+ defaultConsent?: boolean;
179
+ /**
180
+ * The path to the playground page.
181
+ */
182
+ playgroundPath?: string;
183
+ /**
184
+ * Cache mode for manifest data.
185
+ *
186
+ */
187
+ manifestCache?: ManifestCacheMode;
188
+ /**
189
+ * Cache mode for canvas data.
190
+ *
191
+ */
192
+ canvasCache?: CanvasCacheMode;
193
+ /**
194
+ * Cache mode for project map data.
195
+ *
196
+ */
197
+ projectMapCache?: ProjectMapCacheMode;
198
+ eTags?: {
199
+ /**
200
+ * Generate ETags for published compositions.
201
+ *
202
+ * @default false
203
+ */
204
+ generateETags?: boolean;
205
+ /**
206
+ * Cache control header for pages that have ETags.
207
+ *
208
+ * @default 'no-cache, must-revalidate'
209
+ */
210
+ cacheControl?: string | null;
211
+ };
212
+ /**
213
+ * Options for Uniform Context
214
+ */
215
+ context?: {
216
+ /**
217
+ * Disables the Uniform Context dev tools.
218
+ *
219
+ * @default false
220
+ */
221
+ disableDevTools?: boolean;
222
+ };
223
+ /**
224
+ * 😅
225
+ */
226
+ experimental?: {
227
+ /**
228
+ * Enables quirk serialization for Uniform Context.
229
+ *
230
+ * @default false
231
+ */
232
+ quirkSerialization?: boolean;
233
+ /**
234
+ * Enables visual editing mode.
235
+ *
236
+ * @default false
237
+ */
238
+ vercelVisualEditing?: boolean;
239
+ /**
240
+ * Enables runtime cache in middleware.
241
+ *
242
+ * @default false
243
+ */
244
+ middlewareRuntimeCache?: boolean;
245
+ /**
246
+ * Requires middlewareRuntimeCache to be enabled. If enabled, the middleware will retain a copy
247
+ * of the old route data in cache and use it while the new route data is being fetched.
248
+ *
249
+ * @default false
250
+ */
251
+ disableSwrMiddlewareCache?: boolean;
252
+ };
253
+ };
254
+
255
+ declare const extractPersonalizationName: ({ component, }: {
256
+ component: Pick<ComponentInstance, "parameters">;
257
+ }) => string;
258
+
259
+ declare const extractTestName: ({ component }: {
260
+ component: Pick<ComponentInstance, "parameters">;
261
+ }) => string;
262
+
263
+ type RewriteRequestPathResult = {
264
+ path: string;
265
+ keys?: Record<string, string>;
266
+ };
267
+
268
+ declare const UNIFORM_MIDDLEWARE_SCORE_COOKIE_NAME = "ufsc";
269
+ declare const UNIFORM_MIDDLEWARE_QUIRK_COOKIE_NAME = "ufqc";
270
+
271
+ export { type CacheMode, type CanvasCacheMode, type ComponentContext, type ComponentParameter, type ComponentProps, type CompositionContext, type ExtractPersonalizationResult, type ExtractPersonalizationVariant, type ExtractTestResult, type ExtractTestVariant, type IndexedPersonalizationVariant, type IndexedTestVariant, type ManifestCacheMode, type PageState, type PageStateComponent, type PageStateComponentFields, type PersonalizeProps, type ProjectMapCacheMode, type RewriteRequestPathResult, type SlotDefinition, type TestProps, UNIFORM_MIDDLEWARE_QUIRK_COOKIE_NAME, UNIFORM_MIDDLEWARE_SCORE_COOKIE_NAME, type UniformServerConfig, deserializeEvaluationResult, evaluatePersonalization, evaluateTest, extractPersonalizationName, extractTestName, getRuleId, resolveComponentFromPageState, resolveRuleFromPageState, serializeEvaluationResult };