@ninetailed/experience.js-utils-contentful 2.0.0-beta.9 → 2.0.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.
@@ -0,0 +1,3 @@
1
+ export { Entry } from './Entry';
2
+ export { AudienceEntry } from './AudienceEntry';
3
+ export { ExperienceEntry } from './ExperienceEntry';
package/src/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './types';
2
- export { AudienceMapper, ExperienceMapper } from './lib';
package/src/index.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExperienceMapper = exports.AudienceMapper = void 0;
4
- const tslib_1 = require("tslib");
5
- (0, tslib_1.__exportStar)(require("./types"), exports);
6
- var lib_1 = require("./lib");
7
- Object.defineProperty(exports, "AudienceMapper", { enumerable: true, get: function () { return lib_1.AudienceMapper; } });
8
- Object.defineProperty(exports, "ExperienceMapper", { enumerable: true, get: function () { return lib_1.ExperienceMapper; } });
9
- //# sourceMappingURL=index.js.map
package/src/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/utils/contentful/src/index.ts"],"names":[],"mappings":";;;;AAAA,uDAAwB;AACxB,6BAAyD;AAAhD,qGAAA,cAAc,OAAA;AAAE,uGAAA,gBAAgB,OAAA"}
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AudienceMapper = void 0;
4
- class AudienceMapper {
5
- static mapAudience(audience) {
6
- return {
7
- id: audience.sys.id,
8
- };
9
- }
10
- }
11
- exports.AudienceMapper = AudienceMapper;
12
- //# sourceMappingURL=AudienceMapper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AudienceMapper.js","sourceRoot":"","sources":["../../../../../../packages/utils/contentful/src/lib/AudienceMapper.ts"],"names":[],"mappings":";;;AAEA,MAAa,cAAc;IACzB,MAAM,CAAC,WAAW,CAAC,QAAuB;QACxC,OAAO;YACL,EAAE,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE;SACpB,CAAC;IACJ,CAAC;CACF;AAND,wCAMC"}
@@ -1,19 +0,0 @@
1
- import { Baseline, Variant, ExperienceConfiguration } from '@ninetailed/experience.js';
2
- import { Entry } from 'contentful';
3
- import { ExperienceEntry } from '../types';
4
- import { BaselineWithExperiencesEntry } from '../types/BaselineWithExperiencesEntry';
5
- declare type MapVariantOptions = {
6
- hidden: boolean;
7
- };
8
- declare type MapBaseline<BaselineType = Entry<unknown>> = (baseline: BaselineType) => Baseline;
9
- declare type MapVariant<VariantType = Entry<unknown>> = (variant: VariantType, options: MapVariantOptions) => Variant;
10
- declare type MapExperienceOptions<BaselineType = Entry<unknown>, VariantType = Entry<unknown>> = {
11
- mapBaseline?: MapBaseline<BaselineType>;
12
- mapVariant?: MapVariant<VariantType>;
13
- };
14
- export declare class ExperienceMapper {
15
- static mapExperience<BaselineType = Entry<unknown>>(entry: ExperienceEntry, baseline: BaselineType, options?: MapExperienceOptions<BaselineType>): ExperienceConfiguration;
16
- static mapExperiment(entry: ExperienceEntry): ExperienceConfiguration;
17
- static mapBaselineWithExperiences(entry: BaselineWithExperiencesEntry): ExperienceConfiguration[];
18
- }
19
- export {};
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExperienceMapper = void 0;
4
- const AudienceMapper_1 = require("./AudienceMapper");
5
- const defaultMapBaseline = (baseline) => (Object.assign(Object.assign({}, baseline), { id: baseline.sys.id }));
6
- const defaultMapVariant = (variant, { hidden }) => (Object.assign(Object.assign({}, variant), { id: variant.sys.id, hidden: hidden }));
7
- class ExperienceMapper {
8
- static mapExperience(entry, baseline, options) {
9
- const _mapBaseline = ((options === null || options === void 0 ? void 0 : options.mapBaseline) ||
10
- defaultMapBaseline);
11
- const _mapVariant = (options === null || options === void 0 ? void 0 : options.mapVariant) || defaultMapVariant;
12
- const config = Object.assign({ traffic: 0, distribution: [0.5, 0.5], components: [
13
- {
14
- baseline: { id: '' },
15
- variants: [{ id: '', hidden: false }],
16
- },
17
- ] }, entry.fields.nt_config);
18
- const variantReferences = (entry.fields.nt_variants || []).filter((variantReference) => !!variantReference);
19
- return Object.assign(Object.assign({ id: entry.sys.id, type: entry.fields.nt_type }, (entry.fields.nt_audience
20
- ? {
21
- audience: AudienceMapper_1.AudienceMapper.mapAudience(entry.fields.nt_audience),
22
- }
23
- : {})), { trafficAllocation: config.traffic, distribution: config.distribution.map((percentage, index) => ({
24
- index,
25
- start: config.distribution.slice(0, index).reduce((a, b) => a + b, 0),
26
- end: config.distribution.slice(0, index + 1).reduce((a, b) => a + b, 0),
27
- })), components: config.components.map((component) => {
28
- return {
29
- baseline: _mapBaseline(baseline),
30
- variants: component.variants
31
- .map((variant) => {
32
- const matchingVariant = variantReferences.find((variantReference) => variantReference.sys.id === variant.id);
33
- if (!matchingVariant) {
34
- return null;
35
- }
36
- return _mapVariant(matchingVariant, { hidden: variant.hidden });
37
- })
38
- .filter((variant) => variant !== null),
39
- };
40
- }) });
41
- }
42
- static mapExperiment(entry) {
43
- return this.mapExperience(entry, null, {
44
- mapBaseline: () => ({ id: '' }),
45
- mapVariant: () => ({ id: '', hidden: false }),
46
- });
47
- }
48
- static mapBaselineWithExperiences(entry) {
49
- return entry.fields.nt_experiences.map((experience) => this.mapExperience(experience, entry));
50
- }
51
- }
52
- exports.ExperienceMapper = ExperienceMapper;
53
- //# sourceMappingURL=ExperienceMapper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExperienceMapper.js","sourceRoot":"","sources":["../../../../../../packages/utils/contentful/src/lib/ExperienceMapper.ts"],"names":[],"mappings":";;;AASA,qDAAkD;AAuBlD,MAAM,kBAAkB,GAAgC,CAAC,QAAQ,EAAE,EAAE,CAAC,iCACjE,QAAQ,KACX,EAAE,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,IACnB,CAAC;AAEH,MAAM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AAC,aAAa,CAAO,KAAK,EAAE,IAAI,EAAE;YAC3C,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;YAC/B,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;SAC9C,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,0BAA0B,CAC/B,KAAmC;QAEnC,OAAO,KAAK,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CACpD,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,KAAK,CAAC,CACtC,CAAC;IACJ,CAAC;CACF;AA3ED,4CA2EC"}
@@ -1,2 +0,0 @@
1
- export { AudienceMapper } from './AudienceMapper';
2
- export { ExperienceMapper } from './ExperienceMapper';
package/src/lib/index.js DELETED
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExperienceMapper = exports.AudienceMapper = void 0;
4
- var AudienceMapper_1 = require("./AudienceMapper");
5
- Object.defineProperty(exports, "AudienceMapper", { enumerable: true, get: function () { return AudienceMapper_1.AudienceMapper; } });
6
- var ExperienceMapper_1 = require("./ExperienceMapper");
7
- Object.defineProperty(exports, "ExperienceMapper", { enumerable: true, get: function () { return ExperienceMapper_1.ExperienceMapper; } });
8
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/utils/contentful/src/lib/index.ts"],"names":[],"mappings":";;;AAAA,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA"}
@@ -1,12 +0,0 @@
1
- import { Entry, EntryFields } from 'contentful';
2
- export declare type AudienceFields = {
3
- /**
4
- * The name of the audience (Short Text)
5
- */
6
- nt_name: EntryFields.Symbol;
7
- /**
8
- * The internal id of the audience (Short Text)
9
- */
10
- nt_audience_id: EntryFields.Symbol;
11
- };
12
- export declare type AudienceEntry = Entry<AudienceFields>;
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=AudienceEntry.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AudienceEntry.js","sourceRoot":"","sources":["../../../../../../packages/utils/contentful/src/types/AudienceEntry.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=BaselineWithExperiencesEntry.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BaselineWithExperiencesEntry.js","sourceRoot":"","sources":["../../../../../../packages/utils/contentful/src/types/BaselineWithExperiencesEntry.ts"],"names":[],"mappings":""}
@@ -1,32 +0,0 @@
1
- import { Distribution, BaselineWithVariants } from '@ninetailed/experience.js';
2
- import { Entry, EntryFields } from 'contentful';
3
- import { AudienceEntry } from './AudienceEntry';
4
- declare type Config = {
5
- scatteredDistribution: Distribution[];
6
- traffic: number;
7
- components: BaselineWithVariants[];
8
- };
9
- declare type ExperienceFields<VariantEntry extends Entry<unknown> = Entry<unknown>> = {
10
- /**
11
- * The name of the experience (Short Text)
12
- */
13
- nt_name: EntryFields.Symbol;
14
- /**
15
- * The type if the experience (nt_experiment | nt_personalization)
16
- */
17
- nt_type: EntryFields.Symbol;
18
- /**
19
- * The config of the experience (JSON)
20
- */
21
- nt_config?: EntryFields.Object<Config>;
22
- /**
23
- * The audience of the experience (Audience)
24
- */
25
- nt_audience?: AudienceEntry;
26
- /**
27
- * All used variants of the experience (Contentful references to other Content Types)
28
- */
29
- nt_variants?: VariantEntry[];
30
- };
31
- export declare type ExperienceEntry = Entry<ExperienceFields>;
32
- export {};
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=ExperienceEntry.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExperienceEntry.js","sourceRoot":"","sources":["../../../../../../packages/utils/contentful/src/types/ExperienceEntry.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export type { AudienceEntry } from './AudienceEntry';
2
- export type { ExperienceEntry } from './ExperienceEntry';
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/utils/contentful/src/types/index.ts"],"names":[],"mappings":""}