@ninetailed/experience.js-utils-contentful 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 CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var zod = require('zod');
6
4
  var experience_jsShared = require('@ninetailed/experience.js-shared');
7
5
  var experience_jsUtils = require('@ninetailed/experience.js-utils');
@@ -112,6 +110,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
112
110
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
113
111
  PERFORMANCE OF THIS SOFTWARE.
114
112
  ***************************************************************************** */
113
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
114
+
115
115
 
116
116
  function __awaiter(thisArg, _arguments, P, generator) {
117
117
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -121,7 +121,12 @@ function __awaiter(thisArg, _arguments, P, generator) {
121
121
  function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
122
122
  step((generator = generator.apply(thisArg, _arguments || [])).next());
123
123
  });
124
- }
124
+ }
125
+
126
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
127
+ var e = new Error(message);
128
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
129
+ };
125
130
 
126
131
  const ExperienceEntryFields = zod.z.object({
127
132
  /**
package/index.esm.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/index";
package/index.esm.js CHANGED
@@ -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({}, output, {
46
+ return Object.assign(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({}, output, {
56
- data: Object.assign({}, output.data, {
55
+ return Object.assign(Object.assign({}, output), {
56
+ data: Object.assign(Object.assign({}, output.data), {
57
57
  fields: input.fields
58
58
  })
59
59
  });
60
60
  };
61
- const Entry = Object.assign({}, EntrySchema, {
61
+ const Entry = Object.assign(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
  });
@@ -94,36 +94,68 @@ AudienceMapper.isAudienceEntry = entry => {
94
94
  return AudienceEntry.safeParse(entry).success;
95
95
  };
96
96
 
97
+ /******************************************************************************
98
+ Copyright (c) Microsoft Corporation.
99
+
100
+ Permission to use, copy, modify, and/or distribute this software for any
101
+ purpose with or without fee is hereby granted.
102
+
103
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
104
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
105
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
106
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
107
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
108
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
109
+ PERFORMANCE OF THIS SOFTWARE.
110
+ ***************************************************************************** */
111
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
112
+
113
+
114
+ function __awaiter(thisArg, _arguments, P, generator) {
115
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
116
+ return new (P || (P = Promise))(function (resolve, reject) {
117
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
118
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
119
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
120
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
121
+ });
122
+ }
123
+
124
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
125
+ var e = new Error(message);
126
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
127
+ };
128
+
97
129
  const ExperienceEntryFields = z.object({
98
- /**
99
- * The name of the experience (Short Text)
130
+ /**
131
+ * The name of the experience (Short Text)
100
132
  */
101
133
  nt_name: z.string(),
102
- /**
103
- * The description of the experience (Short Text)
134
+ /**
135
+ * The description of the experience (Short Text)
104
136
  */
105
137
  nt_description: z.string().optional().nullable(),
106
- /**
107
- * The type if the experience (nt_experiment | nt_personalization)
138
+ /**
139
+ * The type if the experience (nt_experiment | nt_personalization)
108
140
  */
109
141
  nt_type: z.union([z.string(), z.string()]),
110
- /**
111
- * The config of the experience (JSON)
142
+ /**
143
+ * The config of the experience (JSON)
112
144
  */
113
145
  nt_config: Config.optional().nullable().default(null).transform(val => {
114
- return val != null ? val : {
146
+ return val !== null && val !== void 0 ? val : {
115
147
  traffic: 0,
116
148
  distribution: [0.5, 0.5],
117
149
  components: [],
118
150
  sticky: false
119
151
  };
120
152
  }),
121
- /**
122
- * The audience of the experience (Audience)
153
+ /**
154
+ * The audience of the experience (Audience)
123
155
  */
124
156
  nt_audience: AudienceEntry.optional().nullable(),
125
- /**
126
- * All used variants of the experience (Contentful references to other Content Types)
157
+ /**
158
+ * All used variants of the experience (Contentful references to other Content Types)
127
159
  */
128
160
  nt_variants: z.array(EntrySchema).optional(),
129
161
  nt_experience_id: z.string()
@@ -133,8 +165,8 @@ const ExperienceEntrySchema = EntrySchema.extend({
133
165
  });
134
166
  const parse$1 = input => {
135
167
  const output = ExperienceEntrySchema.parse(input);
136
- return Object.assign({}, output, {
137
- fields: Object.assign({}, output.fields, {
168
+ return Object.assign(Object.assign({}, output), {
169
+ fields: Object.assign(Object.assign({}, output.fields), {
138
170
  nt_variants: input.fields.nt_variants || []
139
171
  })
140
172
  });
@@ -144,15 +176,15 @@ const safeParse$1 = input => {
144
176
  if (!output.success) {
145
177
  return output;
146
178
  }
147
- return Object.assign({}, output, {
148
- data: Object.assign({}, output.data, {
149
- fields: Object.assign({}, output.data.fields, {
179
+ return Object.assign(Object.assign({}, output), {
180
+ data: Object.assign(Object.assign({}, output.data), {
181
+ fields: Object.assign(Object.assign({}, output.data.fields), {
150
182
  nt_variants: input.fields.nt_variants || []
151
183
  })
152
184
  })
153
185
  });
154
186
  };
155
- const ExperienceEntry = Object.assign({}, ExperienceEntrySchema, {
187
+ const ExperienceEntry = Object.assign(Object.assign({}, ExperienceEntrySchema), {
156
188
  parse: parse$1,
157
189
  safeParse: safeParse$1
158
190
  });
@@ -164,8 +196,8 @@ const ExperimentEntrySchema = ExperienceEntrySchema.extend({
164
196
  });
165
197
  const parse = input => {
166
198
  const output = ExperimentEntrySchema.parse(input);
167
- return Object.assign({}, output, {
168
- fields: Object.assign({}, output.fields, {
199
+ return Object.assign(Object.assign({}, output), {
200
+ fields: Object.assign(Object.assign({}, output.fields), {
169
201
  nt_variants: input.fields.nt_variants || []
170
202
  })
171
203
  });
@@ -175,15 +207,15 @@ const safeParse = input => {
175
207
  if (!output.success) {
176
208
  return output;
177
209
  }
178
- return Object.assign({}, output, {
179
- data: Object.assign({}, output.data, {
180
- fields: Object.assign({}, output.data.fields, {
210
+ return Object.assign(Object.assign({}, output), {
211
+ data: Object.assign(Object.assign({}, output.data), {
212
+ fields: Object.assign(Object.assign({}, output.data.fields), {
181
213
  nt_variants: input.fields.nt_variants || []
182
214
  })
183
215
  })
184
216
  });
185
217
  };
186
- const ExperimentEntry = Object.assign({}, ExperimentEntrySchema, {
218
+ const ExperimentEntry = Object.assign(Object.assign({}, ExperimentEntrySchema), {
187
219
  parse,
188
220
  safeParse
189
221
  });
@@ -204,7 +236,7 @@ function createExperience(fields, variants) {
204
236
  nt_config,
205
237
  nt_experience_id
206
238
  } = fields;
207
- return Object.assign({
239
+ return Object.assign(Object.assign({
208
240
  // By the time we reach here, nt_experience_id is guaranteed to be defined thanks to zod validations in validateExperienceEntry
209
241
  id: nt_experience_id,
210
242
  name: nt_name,
@@ -212,7 +244,7 @@ function createExperience(fields, variants) {
212
244
  type: nt_type
213
245
  }, nt_audience ? {
214
246
  audience: mapAudience(nt_audience)
215
- } : {}, {
247
+ } : {}), {
216
248
  config: nt_config,
217
249
  variants
218
250
  });
@@ -229,30 +261,28 @@ class ExperienceMapper {
229
261
  static isExperienceEntry(entry) {
230
262
  return ExperienceEntry.safeParse(entry).success;
231
263
  }
232
-
233
- /**
234
- * Maps a Contentful Ninetailed Experience Entry to a format compatible with the Experience.js SDK.
235
- *
236
- * @param ctfEntry A Contentful Ninetailed Experience Entry
264
+ /**
265
+ * Maps a Contentful Ninetailed Experience Entry to a format compatible with the Experience.js SDK.
266
+ *
267
+ * @param ctfEntry A Contentful Ninetailed Experience Entry
237
268
  */
238
269
  static mapExperience(ctfEntry) {
239
270
  const {
240
271
  fields
241
272
  } = validateExperienceEntry(ctfEntry);
242
- const variants = fields.nt_variants.map(variant => Object.assign({}, variant, {
273
+ const variants = fields.nt_variants.map(variant => Object.assign(Object.assign({}, variant), {
243
274
  id: variant.sys.id
244
275
  }));
245
276
  const experience = createExperience(fields, variants);
246
277
  return ExperienceMapper$1.mapExperience(experience);
247
278
  }
248
-
249
- /**
250
- *
251
- * Maps a Contentful Ninetailed Experience Entry to a format compatible with the Experience.js SDK
252
- * using a custom mapping function for the Experience's variants.
253
- *
254
- * @param ctfEntry A Contentful Ninetailed Experience Entry
255
- * @param mapFn A custom function to map the Experience's variants
279
+ /**
280
+ *
281
+ * Maps a Contentful Ninetailed Experience Entry to a format compatible with the Experience.js SDK
282
+ * using a custom mapping function for the Experience's variants.
283
+ *
284
+ * @param ctfEntry A Contentful Ninetailed Experience Entry
285
+ * @param mapFn A custom function to map the Experience's variants
256
286
  */
257
287
  static mapCustomExperience(ctfEntry, mapFn) {
258
288
  const {
@@ -262,18 +292,19 @@ class ExperienceMapper {
262
292
  const experience = createExperience(fields, variants);
263
293
  return ExperienceMapper$1.mapExperience(experience);
264
294
  }
265
-
266
- /**
267
- * Similar to `mapCustomExperience` but supports asynchronous mapping functions.
268
- * @see mapCustomExperience
295
+ /**
296
+ * Similar to `mapCustomExperience` but supports asynchronous mapping functions.
297
+ * @see mapCustomExperience
269
298
  */
270
- static async mapCustomExperienceAsync(ctfEntry, mapFn) {
271
- const {
272
- fields
273
- } = validateExperienceEntry(ctfEntry);
274
- const variants = await Promise.all(fields.nt_variants.map(mapFn));
275
- const experience = createExperience(fields, variants);
276
- return ExperienceMapper$1.mapExperience(experience);
299
+ static mapCustomExperienceAsync(ctfEntry, mapFn) {
300
+ return __awaiter(this, void 0, void 0, function* () {
301
+ const {
302
+ fields
303
+ } = validateExperienceEntry(ctfEntry);
304
+ const variants = yield Promise.all(fields.nt_variants.map(mapFn));
305
+ const experience = createExperience(fields, variants);
306
+ return ExperienceMapper$1.mapExperience(experience);
307
+ });
277
308
  }
278
309
  static isExperiment(entry) {
279
310
  return ExperimentEntry.safeParse(entry).success;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js-utils-contentful",
3
- "version": "7.18.11",
3
+ "version": "7.18.13",
4
4
  "description": "Contentful utilities for Experience.js",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -30,9 +30,9 @@
30
30
  "dependencies": {
31
31
  "contentful": "^11.10.2",
32
32
  "@contentful/rich-text-types": "17.2.5",
33
- "@ninetailed/experience.js-utils": "7.18.11",
34
- "@ninetailed/experience.js": "7.18.11",
35
- "@ninetailed/experience.js-shared": "7.18.11",
33
+ "@ninetailed/experience.js-utils": "7.18.13",
34
+ "@ninetailed/experience.js": "7.18.13",
35
+ "@ninetailed/experience.js-shared": "7.18.13",
36
36
  "zod": "3.23.0"
37
37
  },
38
38
  "resolutions": {