@ninetailed/experience.js-utils 7.13.0-beta.0 → 7.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs.js CHANGED
@@ -29,7 +29,7 @@ const variableVariantSchema = zod.z.object({
29
29
  value: zod.z.union([zod.z.string(), experience_jsShared.SerializableObject])
30
30
  });
31
31
  const EntryReplacementComponentSchema = zod.z.object({
32
- type: zod.z.literal(ComponentTypeEnum.EntryReplacement).optional(),
32
+ type: zod.z.literal(ComponentTypeEnum.EntryReplacement),
33
33
  baseline: entryReplacementVariantSchema,
34
34
  variants: zod.z.array(entryReplacementVariantSchema)
35
35
  });
@@ -46,7 +46,18 @@ const InlineVariableComponentSchema = zod.z.object({
46
46
  function isInlineVariableComponent(component) {
47
47
  return component.type === ComponentTypeEnum.InlineVariable;
48
48
  }
49
- const ExperienceConfigComponentSchema = zod.z.discriminatedUnion('type', [EntryReplacementComponentSchema, InlineVariableComponentSchema]);
49
+ const ExperienceConfigComponentSchema = zod.z.preprocess(input => {
50
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
+ const component = input;
52
+ if (!(component === null || component === void 0 ? void 0 : component.type)) {
53
+ if ('baseline' in component && 'variants' in component) {
54
+ return Object.assign(Object.assign({}, component), {
55
+ type: ComponentTypeEnum.EntryReplacement
56
+ });
57
+ }
58
+ }
59
+ return component;
60
+ }, zod.z.discriminatedUnion('type', [EntryReplacementComponentSchema, InlineVariableComponentSchema]));
50
61
  const Config = zod.z.object({
51
62
  distribution: zod.z.array(zod.z.number()).optional().default([0.5, 0.5]),
52
63
  traffic: zod.z.number().optional().default(0),
package/index.esm.js CHANGED
@@ -25,8 +25,7 @@ const variableVariantSchema = z.object({
25
25
  value: z.union([z.string(), SerializableObject])
26
26
  });
27
27
  const EntryReplacementComponentSchema = z.object({
28
- type: z.literal(ComponentTypeEnum.EntryReplacement).optional(),
29
- // [components-migration] TODO: to become mandatory once migration is finalized
28
+ type: z.literal(ComponentTypeEnum.EntryReplacement),
30
29
  baseline: entryReplacementVariantSchema,
31
30
  variants: z.array(entryReplacementVariantSchema)
32
31
  });
@@ -43,7 +42,18 @@ const InlineVariableComponentSchema = z.object({
43
42
  function isInlineVariableComponent(component) {
44
43
  return component.type === ComponentTypeEnum.InlineVariable;
45
44
  }
46
- const ExperienceConfigComponentSchema = z.discriminatedUnion('type', [EntryReplacementComponentSchema, InlineVariableComponentSchema]);
45
+ const ExperienceConfigComponentSchema = z.preprocess(input => {
46
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
+ const component = input;
48
+ if (!(component != null && component.type)) {
49
+ if ('baseline' in component && 'variants' in component) {
50
+ return Object.assign({}, component, {
51
+ type: ComponentTypeEnum.EntryReplacement
52
+ });
53
+ }
54
+ }
55
+ return component;
56
+ }, z.discriminatedUnion('type', [EntryReplacementComponentSchema, InlineVariableComponentSchema]));
47
57
  const Config = z.object({
48
58
  distribution: z.array(z.number()).optional().default([0.5, 0.5]),
49
59
  traffic: z.number().optional().default(0),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js-utils",
3
- "version": "7.13.0-beta.0",
3
+ "version": "7.13.0",
4
4
  "description": "Ninetailed Experience.js Utils",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -9,8 +9,8 @@
9
9
  "directory": "packages/utils/javascript"
10
10
  },
11
11
  "dependencies": {
12
- "@ninetailed/experience.js": "7.13.0-beta.0",
13
- "@ninetailed/experience.js-shared": "7.13.0-beta.0",
12
+ "@ninetailed/experience.js": "7.13.0",
13
+ "@ninetailed/experience.js-shared": "7.13.0",
14
14
  "zod": "3.23.0"
15
15
  },
16
16
  "module": "./index.esm.js",
@@ -27,7 +27,7 @@ export declare const variableVariantSchema: z.ZodObject<{
27
27
  value?: unknown;
28
28
  }>;
29
29
  export declare const EntryReplacementComponentSchema: z.ZodObject<{
30
- type: z.ZodOptional<z.ZodLiteral<ComponentTypeEnum.EntryReplacement>>;
30
+ type: z.ZodLiteral<ComponentTypeEnum.EntryReplacement>;
31
31
  baseline: z.ZodObject<{
32
32
  id: z.ZodString;
33
33
  hidden: z.ZodDefault<z.ZodBoolean>;
@@ -49,6 +49,7 @@ export declare const EntryReplacementComponentSchema: z.ZodObject<{
49
49
  hidden?: boolean | undefined;
50
50
  }>, "many">;
51
51
  }, "strip", z.ZodTypeAny, {
52
+ type: ComponentTypeEnum.EntryReplacement;
52
53
  baseline: {
53
54
  id: string;
54
55
  hidden: boolean;
@@ -57,8 +58,8 @@ export declare const EntryReplacementComponentSchema: z.ZodObject<{
57
58
  id: string;
58
59
  hidden: boolean;
59
60
  }[];
60
- type?: ComponentTypeEnum.EntryReplacement | undefined;
61
61
  }, {
62
+ type: ComponentTypeEnum.EntryReplacement;
62
63
  baseline: {
63
64
  id: string;
64
65
  hidden?: boolean | undefined;
@@ -67,7 +68,6 @@ export declare const EntryReplacementComponentSchema: z.ZodObject<{
67
68
  id: string;
68
69
  hidden?: boolean | undefined;
69
70
  }[];
70
- type?: ComponentTypeEnum.EntryReplacement | undefined;
71
71
  }>;
72
72
  export type EntryReplacementComponent = z.infer<typeof EntryReplacementComponentSchema>;
73
73
  export type TExperienceConfigComponentSchema = z.infer<typeof ExperienceConfigComponentSchema>;
@@ -113,8 +113,8 @@ export declare const InlineVariableComponentSchema: z.ZodObject<{
113
113
  }>;
114
114
  export type InlineVariableComponent = z.infer<typeof InlineVariableComponentSchema>;
115
115
  export declare function isInlineVariableComponent(component: TExperienceConfigComponentSchema): component is InlineVariableComponent;
116
- export declare const ExperienceConfigComponentSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
117
- type: z.ZodOptional<z.ZodLiteral<ComponentTypeEnum.EntryReplacement>>;
116
+ export declare const ExperienceConfigComponentSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
117
+ type: z.ZodLiteral<ComponentTypeEnum.EntryReplacement>;
118
118
  baseline: z.ZodObject<{
119
119
  id: z.ZodString;
120
120
  hidden: z.ZodDefault<z.ZodBoolean>;
@@ -136,6 +136,7 @@ export declare const ExperienceConfigComponentSchema: z.ZodDiscriminatedUnion<"t
136
136
  hidden?: boolean | undefined;
137
137
  }>, "many">;
138
138
  }, "strip", z.ZodTypeAny, {
139
+ type: ComponentTypeEnum.EntryReplacement;
139
140
  baseline: {
140
141
  id: string;
141
142
  hidden: boolean;
@@ -144,8 +145,8 @@ export declare const ExperienceConfigComponentSchema: z.ZodDiscriminatedUnion<"t
144
145
  id: string;
145
146
  hidden: boolean;
146
147
  }[];
147
- type?: ComponentTypeEnum.EntryReplacement | undefined;
148
148
  }, {
149
+ type: ComponentTypeEnum.EntryReplacement;
149
150
  baseline: {
150
151
  id: string;
151
152
  hidden?: boolean | undefined;
@@ -154,7 +155,6 @@ export declare const ExperienceConfigComponentSchema: z.ZodDiscriminatedUnion<"t
154
155
  id: string;
155
156
  hidden?: boolean | undefined;
156
157
  }[];
157
- type?: ComponentTypeEnum.EntryReplacement | undefined;
158
158
  }>, z.ZodObject<{
159
159
  type: z.ZodLiteral<ComponentTypeEnum.InlineVariable>;
160
160
  key: z.ZodString;
@@ -193,12 +193,32 @@ export declare const ExperienceConfigComponentSchema: z.ZodDiscriminatedUnion<"t
193
193
  }[];
194
194
  key: string;
195
195
  valueType: InlineVariableComponentValueTypeEnum;
196
- }>]>;
196
+ }>]>, {
197
+ type: ComponentTypeEnum.EntryReplacement;
198
+ baseline: {
199
+ id: string;
200
+ hidden: boolean;
201
+ };
202
+ variants: {
203
+ id: string;
204
+ hidden: boolean;
205
+ }[];
206
+ } | {
207
+ type: ComponentTypeEnum.InlineVariable;
208
+ baseline: {
209
+ value: string | SerializableObject;
210
+ };
211
+ variants: {
212
+ value: string | SerializableObject;
213
+ }[];
214
+ key: string;
215
+ valueType: InlineVariableComponentValueTypeEnum;
216
+ }, unknown>;
197
217
  export declare const Config: z.ZodObject<{
198
218
  distribution: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>>;
199
219
  traffic: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
200
- components: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
201
- type: z.ZodOptional<z.ZodLiteral<ComponentTypeEnum.EntryReplacement>>;
220
+ components: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
221
+ type: z.ZodLiteral<ComponentTypeEnum.EntryReplacement>;
202
222
  baseline: z.ZodObject<{
203
223
  id: z.ZodString;
204
224
  hidden: z.ZodDefault<z.ZodBoolean>;
@@ -220,6 +240,7 @@ export declare const Config: z.ZodObject<{
220
240
  hidden?: boolean | undefined;
221
241
  }>, "many">;
222
242
  }, "strip", z.ZodTypeAny, {
243
+ type: ComponentTypeEnum.EntryReplacement;
223
244
  baseline: {
224
245
  id: string;
225
246
  hidden: boolean;
@@ -228,8 +249,8 @@ export declare const Config: z.ZodObject<{
228
249
  id: string;
229
250
  hidden: boolean;
230
251
  }[];
231
- type?: ComponentTypeEnum.EntryReplacement | undefined;
232
252
  }, {
253
+ type: ComponentTypeEnum.EntryReplacement;
233
254
  baseline: {
234
255
  id: string;
235
256
  hidden?: boolean | undefined;
@@ -238,7 +259,6 @@ export declare const Config: z.ZodObject<{
238
259
  id: string;
239
260
  hidden?: boolean | undefined;
240
261
  }[];
241
- type?: ComponentTypeEnum.EntryReplacement | undefined;
242
262
  }>, z.ZodObject<{
243
263
  type: z.ZodLiteral<ComponentTypeEnum.InlineVariable>;
244
264
  key: z.ZodString;
@@ -277,12 +297,8 @@ export declare const Config: z.ZodObject<{
277
297
  }[];
278
298
  key: string;
279
299
  valueType: InlineVariableComponentValueTypeEnum;
280
- }>]>, "many">>>;
281
- sticky: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
282
- }, "strip", z.ZodTypeAny, {
283
- distribution: number[];
284
- traffic: number;
285
- components: ({
300
+ }>]>, {
301
+ type: ComponentTypeEnum.EntryReplacement;
286
302
  baseline: {
287
303
  id: string;
288
304
  hidden: boolean;
@@ -291,7 +307,6 @@ export declare const Config: z.ZodObject<{
291
307
  id: string;
292
308
  hidden: boolean;
293
309
  }[];
294
- type?: ComponentTypeEnum.EntryReplacement | undefined;
295
310
  } | {
296
311
  type: ComponentTypeEnum.InlineVariable;
297
312
  baseline: {
@@ -302,32 +317,37 @@ export declare const Config: z.ZodObject<{
302
317
  }[];
303
318
  key: string;
304
319
  valueType: InlineVariableComponentValueTypeEnum;
305
- })[];
306
- sticky: boolean;
307
- }, {
308
- distribution?: number[] | undefined;
309
- traffic?: number | undefined;
310
- components?: ({
320
+ }, unknown>, "many">>>;
321
+ sticky: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
322
+ }, "strip", z.ZodTypeAny, {
323
+ distribution: number[];
324
+ traffic: number;
325
+ components: ({
326
+ type: ComponentTypeEnum.EntryReplacement;
311
327
  baseline: {
312
328
  id: string;
313
- hidden?: boolean | undefined;
329
+ hidden: boolean;
314
330
  };
315
331
  variants: {
316
332
  id: string;
317
- hidden?: boolean | undefined;
333
+ hidden: boolean;
318
334
  }[];
319
- type?: ComponentTypeEnum.EntryReplacement | undefined;
320
335
  } | {
321
336
  type: ComponentTypeEnum.InlineVariable;
322
337
  baseline: {
323
- value?: unknown;
338
+ value: string | SerializableObject;
324
339
  };
325
340
  variants: {
326
- value?: unknown;
341
+ value: string | SerializableObject;
327
342
  }[];
328
343
  key: string;
329
344
  valueType: InlineVariableComponentValueTypeEnum;
330
- })[] | undefined;
345
+ })[];
346
+ sticky: boolean;
347
+ }, {
348
+ distribution?: number[] | undefined;
349
+ traffic?: number | undefined;
350
+ components?: unknown[] | undefined;
331
351
  sticky?: boolean | undefined;
332
352
  }>;
333
353
  export type ConfigLike = z.input<typeof Config>;