@ninetailed/experience.js-utils 7.18.11 → 7.18.13
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 +0 -2
- package/index.esm.d.ts +1 -0
- package/index.esm.js +44 -44
- package/package.json +3 -3
package/index.cjs.js
CHANGED
package/index.esm.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
package/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { variableVariantSchema, InlineVariableComponentValueTypeEnum, logger } from '@ninetailed/experience.js-shared';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
|
|
4
4
|
const Audience = z.object({
|
|
@@ -7,11 +7,11 @@ const Audience = z.object({
|
|
|
7
7
|
description: z.string().optional()
|
|
8
8
|
});
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
var ComponentTypeEnum;
|
|
11
|
+
(function (ComponentTypeEnum) {
|
|
11
12
|
ComponentTypeEnum["EntryReplacement"] = "EntryReplacement";
|
|
12
13
|
ComponentTypeEnum["InlineVariable"] = "InlineVariable";
|
|
13
|
-
|
|
14
|
-
}({});
|
|
14
|
+
})(ComponentTypeEnum || (ComponentTypeEnum = {}));
|
|
15
15
|
const entryReplacementVariantSchema = z.object({
|
|
16
16
|
id: z.string(),
|
|
17
17
|
hidden: z.boolean().default(false)
|
|
@@ -37,9 +37,9 @@ function isInlineVariableComponent(component) {
|
|
|
37
37
|
const ExperienceConfigComponentSchema = z.preprocess(input => {
|
|
38
38
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
39
|
const component = input;
|
|
40
|
-
if (!(component
|
|
40
|
+
if (!(component === null || component === void 0 ? void 0 : component.type)) {
|
|
41
41
|
if ('baseline' in component && 'variants' in component) {
|
|
42
|
-
return Object.assign({}, component, {
|
|
42
|
+
return Object.assign(Object.assign({}, component), {
|
|
43
43
|
type: ComponentTypeEnum.EntryReplacement
|
|
44
44
|
});
|
|
45
45
|
}
|
|
@@ -65,17 +65,17 @@ const Variant = z.object({
|
|
|
65
65
|
id: z.string()
|
|
66
66
|
}).catchall(z.unknown());
|
|
67
67
|
|
|
68
|
-
/**
|
|
69
|
-
* Zod helper for parsing arrays and ignore items not specified in the schema
|
|
70
|
-
*
|
|
71
|
-
* @param zodUnion - union of known types
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* const binaryArraySchema = arrayIgnoreUnknown(z.union([z.literal('0'), z.literal('1')]))
|
|
75
|
-
* type BinaryArray = z.TypeOf<typeof binaryArraySchema>
|
|
76
|
-
*
|
|
77
|
-
* const binaryArray: BinaryArray = binaryArraySchema.parse(['0', '1', '2', '0'])
|
|
78
|
-
* console.log(binaryArray) // ['0', '1', '0']
|
|
68
|
+
/**
|
|
69
|
+
* Zod helper for parsing arrays and ignore items not specified in the schema
|
|
70
|
+
*
|
|
71
|
+
* @param zodUnion - union of known types
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* const binaryArraySchema = arrayIgnoreUnknown(z.union([z.literal('0'), z.literal('1')]))
|
|
75
|
+
* type BinaryArray = z.TypeOf<typeof binaryArraySchema>
|
|
76
|
+
*
|
|
77
|
+
* const binaryArray: BinaryArray = binaryArraySchema.parse(['0', '1', '2', '0'])
|
|
78
|
+
* console.log(binaryArray) // ['0', '1', '0']
|
|
79
79
|
*/
|
|
80
80
|
function zodArrayIgnoreUnknown(zodType) {
|
|
81
81
|
const isKnownItem = item => zodType.safeParse(item).success;
|
|
@@ -92,39 +92,39 @@ function isArray(item) {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
const ExperienceSchema = z.object({
|
|
95
|
-
/**
|
|
96
|
-
* The experience's ID from the Experience API's standpoint.
|
|
97
|
-
* It maps to the `nt_experience_id` field on the Ninetailed Experience entry in Contentful.
|
|
95
|
+
/**
|
|
96
|
+
* The experience's ID from the Experience API's standpoint.
|
|
97
|
+
* It maps to the `nt_experience_id` field on the Ninetailed Experience entry in Contentful.
|
|
98
98
|
*/
|
|
99
99
|
id: z.string(),
|
|
100
|
-
/**
|
|
101
|
-
* The name of the experience (Short Text)
|
|
100
|
+
/**
|
|
101
|
+
* The name of the experience (Short Text)
|
|
102
102
|
*/
|
|
103
103
|
name: z.string(),
|
|
104
|
-
/**
|
|
105
|
-
* The description of the experience (Short Text)
|
|
104
|
+
/**
|
|
105
|
+
* The description of the experience (Short Text)
|
|
106
106
|
*/
|
|
107
107
|
description: z.string().optional(),
|
|
108
|
-
/**
|
|
109
|
-
* The type if the experience (nt_experiment | nt_personalization)
|
|
108
|
+
/**
|
|
109
|
+
* The type if the experience (nt_experiment | nt_personalization)
|
|
110
110
|
*/
|
|
111
111
|
type: z.union([z.string().regex(/^nt_experiment$/g), z.string().regex(/^nt_personalization$/g)]),
|
|
112
|
-
/**
|
|
113
|
-
* The config of the experience (JSON)
|
|
112
|
+
/**
|
|
113
|
+
* The config of the experience (JSON)
|
|
114
114
|
*/
|
|
115
115
|
config: Config.default({}),
|
|
116
|
-
/**
|
|
117
|
-
* The audience of the experience (Audience)
|
|
116
|
+
/**
|
|
117
|
+
* The audience of the experience (Audience)
|
|
118
118
|
*/
|
|
119
119
|
audience: Audience.optional().nullable(),
|
|
120
|
-
/**
|
|
121
|
-
* All used variants of the experience (References to other Content Types)
|
|
120
|
+
/**
|
|
121
|
+
* All used variants of the experience (References to other Content Types)
|
|
122
122
|
*/
|
|
123
123
|
variants: zodArrayIgnoreUnknown(Variant).default([])
|
|
124
124
|
});
|
|
125
125
|
const parse$1 = input => {
|
|
126
126
|
const output = ExperienceSchema.parse(input);
|
|
127
|
-
return Object.assign({}, output, {
|
|
127
|
+
return Object.assign(Object.assign({}, output), {
|
|
128
128
|
variants: output.variants
|
|
129
129
|
});
|
|
130
130
|
};
|
|
@@ -133,13 +133,13 @@ const safeParse$1 = input => {
|
|
|
133
133
|
if (!output.success) {
|
|
134
134
|
return output;
|
|
135
135
|
}
|
|
136
|
-
return Object.assign({}, output, {
|
|
137
|
-
data: Object.assign({}, output.data, {
|
|
136
|
+
return Object.assign(Object.assign({}, output), {
|
|
137
|
+
data: Object.assign(Object.assign({}, output.data), {
|
|
138
138
|
variants: output.data.variants
|
|
139
139
|
})
|
|
140
140
|
});
|
|
141
141
|
};
|
|
142
|
-
const Experience = Object.assign({}, ExperienceSchema, {
|
|
142
|
+
const Experience = Object.assign(Object.assign({}, ExperienceSchema), {
|
|
143
143
|
parse: parse$1,
|
|
144
144
|
safeParse: safeParse$1
|
|
145
145
|
});
|
|
@@ -149,7 +149,7 @@ const ExperimentSchema = ExperienceSchema.extend({
|
|
|
149
149
|
});
|
|
150
150
|
const parse = input => {
|
|
151
151
|
const output = ExperimentSchema.parse(input);
|
|
152
|
-
return Object.assign({}, output, {
|
|
152
|
+
return Object.assign(Object.assign({}, output), {
|
|
153
153
|
variants: output.variants
|
|
154
154
|
});
|
|
155
155
|
};
|
|
@@ -158,13 +158,13 @@ const safeParse = input => {
|
|
|
158
158
|
if (!output.success) {
|
|
159
159
|
return output;
|
|
160
160
|
}
|
|
161
|
-
return Object.assign({}, output, {
|
|
162
|
-
data: Object.assign({}, output.data, {
|
|
161
|
+
return Object.assign(Object.assign({}, output), {
|
|
162
|
+
data: Object.assign(Object.assign({}, output.data), {
|
|
163
163
|
variants: output.data.variants
|
|
164
164
|
})
|
|
165
165
|
});
|
|
166
166
|
};
|
|
167
|
-
const Experiment = Object.assign({}, ExperimentSchema, {
|
|
167
|
+
const Experiment = Object.assign(Object.assign({}, ExperimentSchema), {
|
|
168
168
|
parse,
|
|
169
169
|
safeParse
|
|
170
170
|
});
|
|
@@ -193,15 +193,15 @@ class ExperienceMapper {
|
|
|
193
193
|
traffic,
|
|
194
194
|
sticky
|
|
195
195
|
} = config;
|
|
196
|
-
return Object.assign({
|
|
196
|
+
return Object.assign(Object.assign(Object.assign({
|
|
197
197
|
id,
|
|
198
198
|
type: type,
|
|
199
199
|
name
|
|
200
200
|
}, description ? {
|
|
201
201
|
description
|
|
202
|
-
} : {}, audience ? {
|
|
202
|
+
} : {}), audience ? {
|
|
203
203
|
audience
|
|
204
|
-
} : {}, {
|
|
204
|
+
} : {}), {
|
|
205
205
|
trafficAllocation: traffic,
|
|
206
206
|
distribution: config.distribution.map((percentage, index) => ({
|
|
207
207
|
index,
|
|
@@ -217,7 +217,7 @@ class ExperienceMapper {
|
|
|
217
217
|
return variantRef;
|
|
218
218
|
}
|
|
219
219
|
const matchingVariant = variants.find(variant => variant.id === variantRef.id);
|
|
220
|
-
return matchingVariant
|
|
220
|
+
return matchingVariant !== null && matchingVariant !== void 0 ? matchingVariant : null;
|
|
221
221
|
}).filter(variant => variant !== null);
|
|
222
222
|
return {
|
|
223
223
|
type: ComponentTypeEnum.EntryReplacement,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ninetailed/experience.js-utils",
|
|
3
|
-
"version": "7.18.
|
|
3
|
+
"version": "7.18.13",
|
|
4
4
|
"description": "Ninetailed Experience.js Utils",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"sideEffects": false,
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@ninetailed/experience.js": "7.18.
|
|
26
|
-
"@ninetailed/experience.js-shared": "7.18.
|
|
25
|
+
"@ninetailed/experience.js": "7.18.13",
|
|
26
|
+
"@ninetailed/experience.js-shared": "7.18.13",
|
|
27
27
|
"zod": "3.23.0"
|
|
28
28
|
}
|
|
29
29
|
}
|