@ninetailed/experience.js-utils 7.5.3-beta.2 → 7.5.3-beta.4

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.
@@ -33,17 +33,17 @@ const Variant = z.object({
33
33
  id: z.string()
34
34
  }).catchall(z.unknown());
35
35
 
36
- /**
37
- * Zod helper for parsing arrays and ignore items not specified in the schema
38
- *
39
- * @param zodUnion - union of known types
40
- *
41
- * @example
42
- * const binaryArraySchema = arrayIgnoreUnknown(z.union([z.literal('0'), z.literal('1')]))
43
- * type BinaryArray = z.TypeOf<typeof binaryArraySchema>
44
- *
45
- * const binaryArray: BinaryArray = binaryArraySchema.parse(['0', '1', '2', '0'])
46
- * console.log(binaryArray) // ['0', '1', '0']
36
+ /**
37
+ * Zod helper for parsing arrays and ignore items not specified in the schema
38
+ *
39
+ * @param zodUnion - union of known types
40
+ *
41
+ * @example
42
+ * const binaryArraySchema = arrayIgnoreUnknown(z.union([z.literal('0'), z.literal('1')]))
43
+ * type BinaryArray = z.TypeOf<typeof binaryArraySchema>
44
+ *
45
+ * const binaryArray: BinaryArray = binaryArraySchema.parse(['0', '1', '2', '0'])
46
+ * console.log(binaryArray) // ['0', '1', '0']
47
47
  */
48
48
  function zodArrayIgnoreUnknown(zodType) {
49
49
  const isKnownItem = item => zodType.safeParse(item).success;
@@ -61,34 +61,34 @@ function isArray(item) {
61
61
 
62
62
  const ExperienceSchema = z.object({
63
63
  id: z.string(),
64
- /**
65
- * The name of the experience (Short Text)
64
+ /**
65
+ * The name of the experience (Short Text)
66
66
  */
67
67
  name: z.string(),
68
- /**
69
- * The description of the experience (Short Text)
68
+ /**
69
+ * The description of the experience (Short Text)
70
70
  */
71
71
  description: z.string().optional(),
72
- /**
73
- * The type if the experience (nt_experiment | nt_personalization)
72
+ /**
73
+ * The type if the experience (nt_experiment | nt_personalization)
74
74
  */
75
75
  type: z.union([z.string().regex(/^nt_experiment$/g), z.string().regex(/^nt_personalization$/g)]),
76
- /**
77
- * The config of the experience (JSON)
76
+ /**
77
+ * The config of the experience (JSON)
78
78
  */
79
79
  config: Config.default({}),
80
- /**
81
- * The audience of the experience (Audience)
80
+ /**
81
+ * The audience of the experience (Audience)
82
82
  */
83
83
  audience: Audience.optional().nullable(),
84
- /**
85
- * All used variants of the experience (References to other Content Types)
84
+ /**
85
+ * All used variants of the experience (References to other Content Types)
86
86
  */
87
87
  variants: zodArrayIgnoreUnknown(Variant).default([])
88
88
  });
89
89
  const parse$1 = input => {
90
90
  const output = ExperienceSchema.parse(input);
91
- return Object.assign({}, output, {
91
+ return Object.assign(Object.assign({}, output), {
92
92
  variants: input.variants
93
93
  });
94
94
  };
@@ -97,13 +97,13 @@ const safeParse$1 = input => {
97
97
  if (!output.success) {
98
98
  return output;
99
99
  }
100
- return Object.assign({}, output, {
101
- data: Object.assign({}, output.data, {
100
+ return Object.assign(Object.assign({}, output), {
101
+ data: Object.assign(Object.assign({}, output.data), {
102
102
  variants: input.variants
103
103
  })
104
104
  });
105
105
  };
106
- const Experience = Object.assign({}, ExperienceSchema, {
106
+ const Experience = Object.assign(Object.assign({}, ExperienceSchema), {
107
107
  parse: parse$1,
108
108
  safeParse: safeParse$1
109
109
  });
@@ -113,7 +113,7 @@ const ExperimentSchema = ExperienceSchema.extend({
113
113
  });
114
114
  const parse = input => {
115
115
  const output = ExperimentSchema.parse(input);
116
- return Object.assign({}, output, {
116
+ return Object.assign(Object.assign({}, output), {
117
117
  variants: input.variants
118
118
  });
119
119
  };
@@ -122,13 +122,13 @@ const safeParse = input => {
122
122
  if (!output.success) {
123
123
  return output;
124
124
  }
125
- return Object.assign({}, output, {
126
- data: Object.assign({}, output.data, {
125
+ return Object.assign(Object.assign({}, output), {
126
+ data: Object.assign(Object.assign({}, output.data), {
127
127
  variants: input.variants
128
128
  })
129
129
  });
130
130
  };
131
- const Experiment = Object.assign({}, ExperimentSchema, {
131
+ const Experiment = Object.assign(Object.assign({}, ExperimentSchema), {
132
132
  parse,
133
133
  safeParse
134
134
  });
@@ -156,15 +156,15 @@ class ExperienceMapper {
156
156
  components,
157
157
  traffic
158
158
  } = config;
159
- return Object.assign({
159
+ return Object.assign(Object.assign(Object.assign({
160
160
  id,
161
161
  type: type,
162
162
  name
163
163
  }, description ? {
164
164
  description
165
- } : {}, audience ? {
165
+ } : {}), audience ? {
166
166
  audience
167
- } : {}, {
167
+ } : {}), {
168
168
  trafficAllocation: traffic,
169
169
  distribution: config.distribution.map((percentage, index) => ({
170
170
  index,
@@ -178,7 +178,7 @@ class ExperienceMapper {
178
178
  return variantRef;
179
179
  }
180
180
  const matchingVariant = variants.find(variant => variant.id === variantRef.id);
181
- return matchingVariant != null ? matchingVariant : null;
181
+ return matchingVariant !== null && matchingVariant !== void 0 ? matchingVariant : null;
182
182
  }).filter(variant => variant !== null)
183
183
  }))
184
184
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js-utils",
3
- "version": "7.5.3-beta.2",
3
+ "version": "7.5.3-beta.4",
4
4
  "description": "Ninetailed Experience.js Utils",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -8,11 +8,14 @@
8
8
  "url": "https://github.com/ninetailed-inc/experience.js.git",
9
9
  "directory": "packages/utils/javascript"
10
10
  },
11
+ "module": "./index.js",
12
+ "main": "./index.cjs",
13
+ "type": "module",
14
+ "types": "./src/index.d.ts",
11
15
  "dependencies": {
12
- "@ninetailed/experience.js": "*",
13
- "@ninetailed/experience.js-shared": "*",
16
+ "@ninetailed/experience.js": "7.5.3-beta.4",
17
+ "@ninetailed/experience.js-shared": "7.5.3-beta.4",
14
18
  "zod": "3.21.4"
15
19
  },
16
- "module": "./index.esm.js",
17
- "main": "./index.cjs.js"
20
+ "peerDependencies": {}
18
21
  }
package/index.cjs.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src/index";
File without changes