@ninetailed/experience.js-utils-contentful 7.5.2 → 7.5.3-beta.2
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.d.ts +1 -0
- package/{index.js → index.esm.js} +44 -44
- package/package.json +15 -14
- /package/{index.cjs → index.cjs.js} +0 -0
package/index.cjs.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
|
@@ -2,12 +2,12 @@ import { z } from 'zod';
|
|
|
2
2
|
import { logger } from '@ninetailed/experience.js-shared';
|
|
3
3
|
import { Config, ExperienceMapper as ExperienceMapper$1 } from '@ninetailed/experience.js-utils';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* This does not work anymore from zod > 3.21.0:
|
|
7
|
-
*
|
|
8
|
-
* We have to cast the result of passthrough() to z.ZodObject<{}> to make it work,
|
|
9
|
-
* as the inferred type changed to {} & { [k: string]: unknown; }
|
|
10
|
-
* It was {} before, so we do the type cast to get it back to {}.
|
|
5
|
+
/**
|
|
6
|
+
* This does not work anymore from zod > 3.21.0:
|
|
7
|
+
*
|
|
8
|
+
* We have to cast the result of passthrough() to z.ZodObject<{}> to make it work,
|
|
9
|
+
* as the inferred type changed to {} & { [k: string]: unknown; }
|
|
10
|
+
* It was {} before, so we do the type cast to get it back to {}.
|
|
11
11
|
*/
|
|
12
12
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
13
13
|
const EntryFields = z.object({}).passthrough();
|
|
@@ -43,7 +43,7 @@ const EntrySchema = z.object({
|
|
|
43
43
|
});
|
|
44
44
|
const parse$2 = input => {
|
|
45
45
|
const output = EntrySchema.parse(input);
|
|
46
|
-
return Object.assign(
|
|
46
|
+
return Object.assign({}, output, {
|
|
47
47
|
fields: input.fields
|
|
48
48
|
});
|
|
49
49
|
};
|
|
@@ -52,28 +52,28 @@ const safeParse$2 = input => {
|
|
|
52
52
|
if (!output.success) {
|
|
53
53
|
return output;
|
|
54
54
|
}
|
|
55
|
-
return Object.assign(
|
|
56
|
-
data: Object.assign(
|
|
55
|
+
return Object.assign({}, output, {
|
|
56
|
+
data: Object.assign({}, output.data, {
|
|
57
57
|
fields: input.fields
|
|
58
58
|
})
|
|
59
59
|
});
|
|
60
60
|
};
|
|
61
|
-
const Entry = Object.assign(
|
|
61
|
+
const Entry = Object.assign({}, EntrySchema, {
|
|
62
62
|
parse: parse$2,
|
|
63
63
|
safeParse: safeParse$2
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
const AudienceEntryFields = EntryFields.extend({
|
|
67
|
-
/**
|
|
68
|
-
* The name of the audience (Short Text)
|
|
67
|
+
/**
|
|
68
|
+
* The name of the audience (Short Text)
|
|
69
69
|
*/
|
|
70
70
|
nt_name: z.string(),
|
|
71
|
-
/**
|
|
72
|
-
* The description of the audience (Short Text)
|
|
71
|
+
/**
|
|
72
|
+
* The description of the audience (Short Text)
|
|
73
73
|
*/
|
|
74
74
|
nt_description: z.string().optional(),
|
|
75
|
-
/**
|
|
76
|
-
* The internal id of the audience (Short Text)
|
|
75
|
+
/**
|
|
76
|
+
* The internal id of the audience (Short Text)
|
|
77
77
|
*/
|
|
78
78
|
nt_audience_id: z.string()
|
|
79
79
|
});
|
|
@@ -95,34 +95,34 @@ AudienceMapper.isAudienceEntry = entry => {
|
|
|
95
95
|
};
|
|
96
96
|
|
|
97
97
|
const ExperienceEntryFields = z.object({
|
|
98
|
-
/**
|
|
99
|
-
* The name of the experience (Short Text)
|
|
98
|
+
/**
|
|
99
|
+
* The name of the experience (Short Text)
|
|
100
100
|
*/
|
|
101
101
|
nt_name: z.string(),
|
|
102
|
-
/**
|
|
103
|
-
* The description of the experience (Short Text)
|
|
102
|
+
/**
|
|
103
|
+
* The description of the experience (Short Text)
|
|
104
104
|
*/
|
|
105
105
|
nt_description: z.string().optional().nullable(),
|
|
106
|
-
/**
|
|
107
|
-
* The type if the experience (nt_experiment | nt_personalization)
|
|
106
|
+
/**
|
|
107
|
+
* The type if the experience (nt_experiment | nt_personalization)
|
|
108
108
|
*/
|
|
109
109
|
nt_type: z.union([z.string(), z.string()]),
|
|
110
|
-
/**
|
|
111
|
-
* The config of the experience (JSON)
|
|
110
|
+
/**
|
|
111
|
+
* The config of the experience (JSON)
|
|
112
112
|
*/
|
|
113
113
|
nt_config: Config.optional().nullable().default(null).transform(val => {
|
|
114
|
-
return val
|
|
114
|
+
return val != null ? val : {
|
|
115
115
|
traffic: 0,
|
|
116
116
|
distribution: [0.5, 0.5],
|
|
117
117
|
components: []
|
|
118
118
|
};
|
|
119
119
|
}),
|
|
120
|
-
/**
|
|
121
|
-
* The audience of the experience (Audience)
|
|
120
|
+
/**
|
|
121
|
+
* The audience of the experience (Audience)
|
|
122
122
|
*/
|
|
123
123
|
nt_audience: AudienceEntry.optional().nullable(),
|
|
124
|
-
/**
|
|
125
|
-
* All used variants of the experience (Contentful references to other Content Types)
|
|
124
|
+
/**
|
|
125
|
+
* All used variants of the experience (Contentful references to other Content Types)
|
|
126
126
|
*/
|
|
127
127
|
nt_variants: z.array(EntrySchema).optional()
|
|
128
128
|
});
|
|
@@ -131,8 +131,8 @@ const ExperienceEntrySchema = EntrySchema.extend({
|
|
|
131
131
|
});
|
|
132
132
|
const parse$1 = input => {
|
|
133
133
|
const output = ExperienceEntrySchema.parse(input);
|
|
134
|
-
return Object.assign(
|
|
135
|
-
fields: Object.assign(
|
|
134
|
+
return Object.assign({}, output, {
|
|
135
|
+
fields: Object.assign({}, output.fields, {
|
|
136
136
|
nt_variants: input.fields.nt_variants || []
|
|
137
137
|
})
|
|
138
138
|
});
|
|
@@ -142,15 +142,15 @@ const safeParse$1 = input => {
|
|
|
142
142
|
if (!output.success) {
|
|
143
143
|
return output;
|
|
144
144
|
}
|
|
145
|
-
return Object.assign(
|
|
146
|
-
data: Object.assign(
|
|
147
|
-
fields: Object.assign(
|
|
145
|
+
return Object.assign({}, output, {
|
|
146
|
+
data: Object.assign({}, output.data, {
|
|
147
|
+
fields: Object.assign({}, output.data.fields, {
|
|
148
148
|
nt_variants: input.fields.nt_variants || []
|
|
149
149
|
})
|
|
150
150
|
})
|
|
151
151
|
});
|
|
152
152
|
};
|
|
153
|
-
const ExperienceEntry = Object.assign(
|
|
153
|
+
const ExperienceEntry = Object.assign({}, ExperienceEntrySchema, {
|
|
154
154
|
parse: parse$1,
|
|
155
155
|
safeParse: safeParse$1
|
|
156
156
|
});
|
|
@@ -162,8 +162,8 @@ const ExperimentEntrySchema = ExperienceEntrySchema.extend({
|
|
|
162
162
|
});
|
|
163
163
|
const parse = input => {
|
|
164
164
|
const output = ExperimentEntrySchema.parse(input);
|
|
165
|
-
return Object.assign(
|
|
166
|
-
fields: Object.assign(
|
|
165
|
+
return Object.assign({}, output, {
|
|
166
|
+
fields: Object.assign({}, output.fields, {
|
|
167
167
|
nt_variants: input.fields.nt_variants || []
|
|
168
168
|
})
|
|
169
169
|
});
|
|
@@ -173,15 +173,15 @@ const safeParse = input => {
|
|
|
173
173
|
if (!output.success) {
|
|
174
174
|
return output;
|
|
175
175
|
}
|
|
176
|
-
return Object.assign(
|
|
177
|
-
data: Object.assign(
|
|
178
|
-
fields: Object.assign(
|
|
176
|
+
return Object.assign({}, output, {
|
|
177
|
+
data: Object.assign({}, output.data, {
|
|
178
|
+
fields: Object.assign({}, output.data.fields, {
|
|
179
179
|
nt_variants: input.fields.nt_variants || []
|
|
180
180
|
})
|
|
181
181
|
})
|
|
182
182
|
});
|
|
183
183
|
};
|
|
184
|
-
const ExperimentEntry = Object.assign(
|
|
184
|
+
const ExperimentEntry = Object.assign({}, ExperimentEntrySchema, {
|
|
185
185
|
parse,
|
|
186
186
|
safeParse
|
|
187
187
|
});
|
|
@@ -201,14 +201,14 @@ function createExperience(id, fields, variants) {
|
|
|
201
201
|
nt_audience,
|
|
202
202
|
nt_config
|
|
203
203
|
} = fields;
|
|
204
|
-
return Object.assign(
|
|
204
|
+
return Object.assign({
|
|
205
205
|
id,
|
|
206
206
|
name: nt_name,
|
|
207
207
|
description: nt_description || '',
|
|
208
208
|
type: nt_type
|
|
209
209
|
}, nt_audience ? {
|
|
210
210
|
audience: mapAudience(nt_audience)
|
|
211
|
-
} : {}
|
|
211
|
+
} : {}, {
|
|
212
212
|
config: nt_config,
|
|
213
213
|
variants
|
|
214
214
|
});
|
|
@@ -230,7 +230,7 @@ class ExperienceMapper {
|
|
|
230
230
|
sys,
|
|
231
231
|
fields
|
|
232
232
|
} = validateExperienceEntry(ctfEntry);
|
|
233
|
-
const variants = fields.nt_variants.map(variant => Object.assign(
|
|
233
|
+
const variants = fields.nt_variants.map(variant => Object.assign({}, variant, {
|
|
234
234
|
id: variant.sys.id
|
|
235
235
|
}));
|
|
236
236
|
const experience = createExperience(sys.id, fields, variants);
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ninetailed/experience.js-utils-contentful",
|
|
3
|
-
"version": "7.5.2",
|
|
3
|
+
"version": "7.5.3-beta.2",
|
|
4
4
|
"description": "Contentful utilities for Experience.js",
|
|
5
|
-
"
|
|
5
|
+
"dependencies": {
|
|
6
6
|
"contentful": "^9.1.32",
|
|
7
|
-
"@contentful/rich-text-types": "16.2.0"
|
|
7
|
+
"@contentful/rich-text-types": "16.2.0",
|
|
8
|
+
"@ninetailed/experience.js-utils": "*",
|
|
9
|
+
"@ninetailed/experience.js": "*",
|
|
10
|
+
"@ninetailed/experience.js-shared": "*",
|
|
11
|
+
"zod": "3.21.4"
|
|
8
12
|
},
|
|
9
13
|
"license": "MIT",
|
|
10
14
|
"repository": {
|
|
@@ -12,15 +16,12 @@
|
|
|
12
16
|
"url": "https://github.com/ninetailed-inc/experience.js.git",
|
|
13
17
|
"directory": "packages/utils/contentful"
|
|
14
18
|
},
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"zod": "3.21.4"
|
|
24
|
-
},
|
|
25
|
-
"peerDependencies": {}
|
|
19
|
+
"keywords": [
|
|
20
|
+
"contentful",
|
|
21
|
+
"ninetailed",
|
|
22
|
+
"personalization",
|
|
23
|
+
"a/b testing"
|
|
24
|
+
],
|
|
25
|
+
"module": "./index.esm.js",
|
|
26
|
+
"main": "./index.cjs.js"
|
|
26
27
|
}
|
|
File without changes
|