@ninetailed/experience.js-utils-contentful 3.0.0-beta.15 → 3.0.0-beta.20

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.
@@ -46,7 +46,6 @@ const AudienceFields = z.object({
46
46
  * The name of the audience (Short Text)
47
47
  */
48
48
  nt_name: z.string(),
49
-
50
49
  /**
51
50
  * The internal id of the audience (Short Text)
52
51
  */
@@ -61,22 +60,18 @@ const ExperienceFields = z.object({
61
60
  * The name of the experience (Short Text)
62
61
  */
63
62
  nt_name: z.string(),
64
-
65
63
  /**
66
64
  * The type if the experience (nt_experiment | nt_personalization)
67
65
  */
68
66
  nt_type: z.union([z.literal('nt_experiment'), z.literal('nt_personalization')]),
69
-
70
67
  /**
71
68
  * The config of the experience (JSON)
72
69
  */
73
70
  nt_config: Config.optional().nullable(),
74
-
75
71
  /**
76
72
  * The audience of the experience (Audience)
77
73
  */
78
74
  nt_audience: AudienceEntry.optional().nullable(),
79
-
80
75
  /**
81
76
  * All used variants of the experience (Contentful references to other Content Types)
82
77
  */
@@ -98,7 +93,6 @@ class AudienceMapper {
98
93
  id: audience.fields.nt_audience_id
99
94
  };
100
95
  }
101
-
102
96
  }
103
97
 
104
98
  const isEntry = entry => {
@@ -108,22 +102,17 @@ const isEntry = entry => {
108
102
  const defaultMapVariant = variant => Object.assign(Object.assign({}, variant), {
109
103
  id: variant.sys.id
110
104
  });
111
-
112
105
  class ExperienceMapper {
113
106
  static isExperienceEntry(entry) {
114
107
  return ExperienceEntry.safeParse(entry).success;
115
108
  }
116
-
117
109
  static mapExperience(entry, options) {
118
110
  const _mapVariant = (options === null || options === void 0 ? void 0 : options.mapVariant) || defaultMapVariant;
119
-
120
111
  const parsedExperience = ExperienceEntry.safeParse(entry);
121
-
122
112
  if (!parsedExperience.success) {
123
113
  logger.warn('[Ninetailed Contentful ExperienceMapper]', 'Error parsing experience', parsedExperience.error.format());
124
114
  throw new Error(`[Ninetailed Contentful ExperienceMapper] The Experience Input is not valid. Please filter data first with "ExperienceMapper.isExperienceEntry".\n${JSON.stringify(parsedExperience.error.format(), null, 2)}`);
125
115
  }
126
-
127
116
  const {
128
117
  sys: {
129
118
  id
@@ -148,11 +137,9 @@ class ExperienceMapper {
148
137
  variants: nt_variants.map(variant => _mapVariant(variant))
149
138
  }));
150
139
  }
151
-
152
140
  static isExperiment(entry) {
153
141
  return ExperimentEntry.safeParse(entry).success;
154
142
  }
155
-
156
143
  static mapExperiment(entry) {
157
144
  return ExperienceMapper.mapExperience(entry, {
158
145
  mapVariant: () => ({
@@ -160,11 +147,9 @@ class ExperienceMapper {
160
147
  })
161
148
  });
162
149
  }
163
-
164
150
  static mapBaselineWithExperiences(entry) {
165
151
  return entry.fields.nt_experiences.filter(isEntry).map(experience => ExperienceMapper.mapExperience(experience));
166
152
  }
167
-
168
153
  }
169
154
 
170
155
  const isAudienceEntry = entry => {
@@ -1,44 +1,5 @@
1
- export declare const isAudienceEntry: (entry?: {
2
- metadata?: {
3
- tags: {
4
- sys: {
5
- type: "Link";
6
- id: string;
7
- linkType: "Tag";
8
- };
9
- }[];
10
- } | undefined;
11
- sys: {
12
- type?: string | undefined;
13
- createdAt?: string | undefined;
14
- updatedAt?: string | undefined;
15
- locale?: string | undefined;
16
- revision?: number | undefined;
17
- space?: {
18
- sys: {
19
- type: "Link";
20
- id: string;
21
- linkType: "Space";
22
- };
23
- } | undefined;
24
- environment?: {
25
- sys: {
26
- type: "Link";
27
- id: string;
28
- linkType: "Environment";
29
- };
30
- } | undefined;
31
- contentType?: {
32
- sys: {
33
- type: "Link";
34
- id: string;
35
- linkType: "ContentType";
36
- };
37
- } | undefined;
38
- id: string;
39
- };
40
- fields: {};
41
- } | undefined) => entry is {
1
+ import { Entry } from '../types';
2
+ export declare const isAudienceEntry: (entry?: Entry) => entry is {
42
3
  metadata?: {
43
4
  tags: {
44
5
  sys: {
package/lib/isEntry.d.ts CHANGED
@@ -1,44 +1,5 @@
1
- export declare const isEntry: (entry?: {
2
- metadata?: {
3
- tags: {
4
- sys: {
5
- type: "Link";
6
- id: string;
7
- linkType: "Tag";
8
- };
9
- }[];
10
- } | undefined;
11
- sys: {
12
- type?: string | undefined;
13
- createdAt?: string | undefined;
14
- updatedAt?: string | undefined;
15
- locale?: string | undefined;
16
- revision?: number | undefined;
17
- space?: {
18
- sys: {
19
- type: "Link";
20
- id: string;
21
- linkType: "Space";
22
- };
23
- } | undefined;
24
- environment?: {
25
- sys: {
26
- type: "Link";
27
- id: string;
28
- linkType: "Environment";
29
- };
30
- } | undefined;
31
- contentType?: {
32
- sys: {
33
- type: "Link";
34
- id: string;
35
- linkType: "ContentType";
36
- };
37
- } | undefined;
38
- id: string;
39
- };
40
- fields: {};
41
- } | undefined) => entry is {
1
+ import { Entry } from '../types';
2
+ export declare const isEntry: (entry?: Entry) => entry is {
42
3
  metadata?: {
43
4
  tags: {
44
5
  sys: {
@@ -1,44 +1,5 @@
1
- export declare const isExperienceEntry: (entry?: {
2
- metadata?: {
3
- tags: {
4
- sys: {
5
- type: "Link";
6
- id: string;
7
- linkType: "Tag";
8
- };
9
- }[];
10
- } | undefined;
11
- sys: {
12
- type?: string | undefined;
13
- createdAt?: string | undefined;
14
- updatedAt?: string | undefined;
15
- locale?: string | undefined;
16
- revision?: number | undefined;
17
- space?: {
18
- sys: {
19
- type: "Link";
20
- id: string;
21
- linkType: "Space";
22
- };
23
- } | undefined;
24
- environment?: {
25
- sys: {
26
- type: "Link";
27
- id: string;
28
- linkType: "Environment";
29
- };
30
- } | undefined;
31
- contentType?: {
32
- sys: {
33
- type: "Link";
34
- id: string;
35
- linkType: "ContentType";
36
- };
37
- } | undefined;
38
- id: string;
39
- };
40
- fields: {};
41
- } | undefined) => entry is {
1
+ import { Entry } from '../types';
2
+ export declare const isExperienceEntry: (entry?: Entry) => entry is {
42
3
  metadata?: {
43
4
  tags: {
44
5
  sys: {
package/package.json CHANGED
@@ -1,23 +1,17 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js-utils-contentful",
3
- "version": "3.0.0-beta.15",
3
+ "version": "3.0.0-beta.20",
4
4
  "peerDependencies": {
5
5
  "contentful": "^9.1.32"
6
6
  },
7
- "main": "./index.umd.js",
8
- "module": "./index.esm.js",
9
- "typings": "./index.d.ts",
7
+ "module": "./index.js",
8
+ "main": "./index.js",
9
+ "type": "module",
10
+ "types": "./index.d.ts",
10
11
  "dependencies": {
11
- "@ninetailed/experience.js-utils": "3.0.0-beta.15",
12
- "@ninetailed/experience.js": "3.0.0-beta.15",
13
- "@ninetailed/experience.js-shared": "3.0.0-beta.15",
14
- "ts-toolbelt": "^9.6.0",
15
- "diary": "^0.3.1",
16
- "zod": "^3.18.0",
17
- "locale-enum": "^1.1.1",
18
- "i18n-iso-countries": "^7.3.0",
19
- "analytics": "^0.8.0",
20
- "lodash": "^4.17.21",
21
- "murmurhash-js": "^1.0.0"
12
+ "@ninetailed/experience.js-utils": "3.0.0-beta.20",
13
+ "@ninetailed/experience.js": "3.0.0-beta.20",
14
+ "@ninetailed/experience.js-shared": "3.0.0-beta.20",
15
+ "zod": "3.19.1"
22
16
  }
23
17
  }
package/index.umd.js DELETED
@@ -1,232 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('zod'), require('@ninetailed/experience.js-utils'), require('@ninetailed/experience.js-shared')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'zod', '@ninetailed/experience.js-utils', '@ninetailed/experience.js-shared'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.UtilsContentful = {}, global.zod, global.experience_jsUtils, global.experience_jsShared));
5
- })(this, (function (exports, zod, experience_jsUtils, experience_jsShared) { 'use strict';
6
-
7
- var EntryLink = zod.z.object({
8
- type: zod.z.literal('Link'),
9
- linkType: zod.z.string(),
10
- id: zod.z.string()
11
- });
12
- var Entry = zod.z.object({
13
- sys: zod.z.object({
14
- type: zod.z.string().optional(),
15
- id: zod.z.string(),
16
- createdAt: zod.z.string().optional(),
17
- updatedAt: zod.z.string().optional(),
18
- locale: zod.z.string().optional(),
19
- revision: zod.z.number().optional(),
20
- space: zod.z.object({
21
- sys: EntryLink.extend({
22
- linkType: zod.z.literal('Space')
23
- })
24
- }).optional(),
25
- environment: zod.z.object({
26
- sys: EntryLink.extend({
27
- linkType: zod.z.literal('Environment')
28
- })
29
- }).optional(),
30
- contentType: zod.z.object({
31
- sys: EntryLink.extend({
32
- linkType: zod.z.literal('ContentType')
33
- })
34
- }).optional()
35
- }),
36
- fields: zod.z.object({}).passthrough(),
37
- metadata: zod.z.object({
38
- tags: zod.z.array(zod.z.object({
39
- sys: EntryLink.extend({
40
- linkType: zod.z.literal('Tag')
41
- })
42
- }))
43
- }).optional()
44
- });
45
-
46
- var AudienceFields = zod.z.object({
47
- /**
48
- * The name of the audience (Short Text)
49
- */
50
- nt_name: zod.z.string(),
51
-
52
- /**
53
- * The internal id of the audience (Short Text)
54
- */
55
- nt_audience_id: zod.z.string()
56
- });
57
- var AudienceEntry = Entry.extend({
58
- fields: AudienceFields
59
- });
60
-
61
- var ExperienceFields = zod.z.object({
62
- /**
63
- * The name of the experience (Short Text)
64
- */
65
- nt_name: zod.z.string(),
66
-
67
- /**
68
- * The type if the experience (nt_experiment | nt_personalization)
69
- */
70
- nt_type: zod.z.union([zod.z.literal('nt_experiment'), zod.z.literal('nt_personalization')]),
71
-
72
- /**
73
- * The config of the experience (JSON)
74
- */
75
- nt_config: experience_jsUtils.Config.optional().nullable(),
76
-
77
- /**
78
- * The audience of the experience (Audience)
79
- */
80
- nt_audience: AudienceEntry.optional().nullable(),
81
-
82
- /**
83
- * All used variants of the experience (Contentful references to other Content Types)
84
- */
85
- nt_variants: zod.z.array(Entry).default([])
86
- });
87
- var ExperienceEntry = Entry.extend({
88
- fields: ExperienceFields
89
- });
90
-
91
- var ExperimentEntry = ExperienceEntry.extend({
92
- fields: ExperienceFields.extend({
93
- nt_type: zod.z.literal('nt_experiment')
94
- })
95
- });
96
-
97
- var AudienceMapper =
98
- /** @class */
99
- function () {
100
- function AudienceMapper() {}
101
-
102
- AudienceMapper.mapAudience = function (audience) {
103
- return {
104
- id: audience.fields.nt_audience_id
105
- };
106
- };
107
-
108
- return AudienceMapper;
109
- }();
110
-
111
- /*! *****************************************************************************
112
- Copyright (c) Microsoft Corporation.
113
-
114
- Permission to use, copy, modify, and/or distribute this software for any
115
- purpose with or without fee is hereby granted.
116
-
117
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
118
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
119
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
120
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
121
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
122
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
123
- PERFORMANCE OF THIS SOFTWARE.
124
- ***************************************************************************** */
125
-
126
- var __assign = function() {
127
- __assign = Object.assign || function __assign(t) {
128
- for (var s, i = 1, n = arguments.length; i < n; i++) {
129
- s = arguments[i];
130
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
131
- }
132
- return t;
133
- };
134
- return __assign.apply(this, arguments);
135
- };
136
-
137
- var isEntry = function (entry) {
138
- return Entry.safeParse(entry).success;
139
- };
140
-
141
- var defaultMapVariant = function (variant) {
142
- return __assign(__assign({}, variant), {
143
- id: variant.sys.id
144
- });
145
- };
146
-
147
- var ExperienceMapper =
148
- /** @class */
149
- function () {
150
- function ExperienceMapper() {}
151
-
152
- ExperienceMapper.isExperienceEntry = function (entry) {
153
- return ExperienceEntry.safeParse(entry).success;
154
- };
155
-
156
- ExperienceMapper.mapExperience = function (entry, options) {
157
- var _mapVariant = (options === null || options === void 0 ? void 0 : options.mapVariant) || defaultMapVariant;
158
-
159
- var parsedExperience = ExperienceEntry.safeParse(entry);
160
-
161
- if (!parsedExperience.success) {
162
- experience_jsShared.logger.warn('[Ninetailed Contentful ExperienceMapper]', 'Error parsing experience', parsedExperience.error.format());
163
- throw new Error("[Ninetailed Contentful ExperienceMapper] The Experience Input is not valid. Please filter data first with \"ExperienceMapper.isExperienceEntry\".\n".concat(JSON.stringify(parsedExperience.error.format(), null, 2)));
164
- }
165
-
166
- var _a = parsedExperience.data,
167
- id = _a.sys.id,
168
- _b = _a.fields,
169
- nt_type = _b.nt_type,
170
- nt_name = _b.nt_name,
171
- nt_config = _b.nt_config,
172
- nt_audience = _b.nt_audience,
173
- nt_variants = _b.nt_variants;
174
- return experience_jsUtils.ExperienceMapper.mapExperience(__assign(__assign(__assign({
175
- id: id,
176
- type: nt_type,
177
- name: nt_name
178
- }, nt_audience ? {
179
- audience: AudienceMapper.mapAudience(nt_audience)
180
- } : {}), nt_config ? {
181
- config: nt_config
182
- } : {}), {
183
- variants: nt_variants.map(function (variant) {
184
- return _mapVariant(variant);
185
- })
186
- }));
187
- };
188
-
189
- ExperienceMapper.isExperiment = function (entry) {
190
- return ExperimentEntry.safeParse(entry).success;
191
- };
192
-
193
- ExperienceMapper.mapExperiment = function (entry) {
194
- return ExperienceMapper.mapExperience(entry, {
195
- mapVariant: function () {
196
- return {
197
- id: ''
198
- };
199
- }
200
- });
201
- };
202
-
203
- ExperienceMapper.mapBaselineWithExperiences = function (entry) {
204
- return entry.fields.nt_experiences.filter(isEntry).map(function (experience) {
205
- return ExperienceMapper.mapExperience(experience);
206
- });
207
- };
208
-
209
- return ExperienceMapper;
210
- }();
211
-
212
- var isAudienceEntry = function (entry) {
213
- return AudienceEntry.safeParse(entry).success;
214
- };
215
-
216
- var isExperienceEntry = function (entry) {
217
- return ExperienceEntry.safeParse(entry).success;
218
- };
219
-
220
- exports.AudienceEntry = AudienceEntry;
221
- exports.AudienceMapper = AudienceMapper;
222
- exports.Entry = Entry;
223
- exports.ExperienceEntry = ExperienceEntry;
224
- exports.ExperienceMapper = ExperienceMapper;
225
- exports.ExperimentEntry = ExperimentEntry;
226
- exports.isAudienceEntry = isAudienceEntry;
227
- exports.isEntry = isEntry;
228
- exports.isExperienceEntry = isExperienceEntry;
229
-
230
- Object.defineProperty(exports, '__esModule', { value: true });
231
-
232
- }));