@ninetailed/experience.js-utils-contentful 2.0.0-beta.4 → 2.0.0-beta.7
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/package.json
CHANGED
|
@@ -5,13 +5,14 @@ import { BaselineWithExperiencesEntry } from '../types/BaselineWithExperiencesEn
|
|
|
5
5
|
declare type MapVariantOptions = {
|
|
6
6
|
hidden: boolean;
|
|
7
7
|
};
|
|
8
|
-
declare type MapBaseline<
|
|
9
|
-
declare type
|
|
10
|
-
|
|
11
|
-
|
|
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>;
|
|
12
13
|
};
|
|
13
14
|
export declare class ExperienceMapper {
|
|
14
|
-
static mapExperience<
|
|
15
|
+
static mapExperience<BaselineType = Entry<unknown>>(entry: ExperienceEntry, baseline: BaselineType, options?: MapExperienceOptions<BaselineType>): ExperienceConfiguration;
|
|
15
16
|
static mapExperiment(entry: ExperienceEntry): ExperienceConfiguration;
|
|
16
17
|
static mapBaselineWithExperiences(entry: BaselineWithExperiencesEntry): ExperienceConfiguration[];
|
|
17
18
|
}
|
|
@@ -2,22 +2,34 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ExperienceMapper = void 0;
|
|
4
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 }));
|
|
5
7
|
class ExperienceMapper {
|
|
6
8
|
static mapExperience(entry, baseline, options) {
|
|
7
9
|
const _mapBaseline = ((options === null || options === void 0 ? void 0 : options.mapBaseline) ||
|
|
8
|
-
|
|
9
|
-
const _mapVariant = (options === null || options === void 0 ? void 0 : options.mapVariant) ||
|
|
10
|
-
|
|
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);
|
|
11
19
|
return Object.assign(Object.assign({ id: entry.sys.id, type: entry.fields.nt_type }, (entry.fields.nt_audience
|
|
12
20
|
? {
|
|
13
21
|
audience: AudienceMapper_1.AudienceMapper.mapAudience(entry.fields.nt_audience),
|
|
14
22
|
}
|
|
15
|
-
: {})), { trafficAllocation:
|
|
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) => {
|
|
16
28
|
return {
|
|
17
29
|
baseline: _mapBaseline(baseline),
|
|
18
30
|
variants: component.variants
|
|
19
31
|
.map((variant) => {
|
|
20
|
-
const matchingVariant =
|
|
32
|
+
const matchingVariant = variantReferences.find((variantReference) => variantReference.sys.id === variant.id);
|
|
21
33
|
if (!matchingVariant) {
|
|
22
34
|
return null;
|
|
23
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExperienceMapper.js","sourceRoot":"","sources":["../../../../../../packages/utils/contentful/src/lib/ExperienceMapper.ts"],"names":[],"mappings":";;;AASA,qDAAkD;
|
|
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,iBAAiB,GAA+B,CACpD,OAAO,EACP,EAAE,MAAM,EAAE,EACV,EAAE,CAAC,iCACA,OAAO,KACV,EAAE,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,EAClB,MAAM,EAAE,MAAM,IACd,CAAC;AAEH,MAAa,gBAAgB;IAC3B,MAAM,CAAC,aAAa,CAClB,KAAsB,EACtB,QAAsB,EACtB,OAA4C;QAE5C,MAAM,YAAY,GAAG,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW;YACxC,kBAAkB,CAA8B,CAAC;QACnD,MAAM,WAAW,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,KAAI,iBAAiB,CAAC;QAE7D,MAAM,MAAM,mBACV,OAAO,EAAE,CAAC,EACV,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EACxB,UAAU,EAAE;gBACV;oBACE,QAAQ,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE;oBACpB,QAAQ,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;iBACtC;aACF,IACE,KAAK,CAAC,MAAM,CAAC,SAAS,CAC1B,CAAC;QACF,MAAM,iBAAiB,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,MAAM,CAC/D,CAAC,gBAAgB,EAAsC,EAAE,CACvD,CAAC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AC,eAAe,EAAE;4BACpB,OAAO,IAAI,CAAC;yBACb;wBAED,OAAO,WAAW,CAAC,eAAe,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;oBAClE,CAAC,CAAC;yBACD,MAAM,CAAC,CAAC,OAAO,EAAsB,EAAE,CAAC,OAAO,KAAK,IAAI,CAAC;iBAC7D,CAAC;YACJ,CAAC,CAAC,IACF;IACJ,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,KAAsB;QACzC,OAAO,IAAI,CAAC,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"}
|
|
@@ -6,7 +6,7 @@ declare type Config = {
|
|
|
6
6
|
traffic: number;
|
|
7
7
|
components: BaselineWithVariants[];
|
|
8
8
|
};
|
|
9
|
-
declare type
|
|
9
|
+
declare type ExperienceFields<VariantEntry extends Entry<unknown> = Entry<unknown>> = {
|
|
10
10
|
/**
|
|
11
11
|
* The name of the experience (Short Text)
|
|
12
12
|
*/
|
|
@@ -18,7 +18,7 @@ declare type Experiencefields<VariantEntryTypes extends Entry<unknown> = Entry<u
|
|
|
18
18
|
/**
|
|
19
19
|
* The config of the experience (JSON)
|
|
20
20
|
*/
|
|
21
|
-
nt_config
|
|
21
|
+
nt_config?: EntryFields.Object<Config>;
|
|
22
22
|
/**
|
|
23
23
|
* The audience of the experience (Audience)
|
|
24
24
|
*/
|
|
@@ -26,7 +26,7 @@ declare type Experiencefields<VariantEntryTypes extends Entry<unknown> = Entry<u
|
|
|
26
26
|
/**
|
|
27
27
|
* All used variants of the experience (Contentful references to other Content Types)
|
|
28
28
|
*/
|
|
29
|
-
nt_variants
|
|
29
|
+
nt_variants?: VariantEntry[];
|
|
30
30
|
};
|
|
31
|
-
export declare type ExperienceEntry = Entry<
|
|
31
|
+
export declare type ExperienceEntry = Entry<ExperienceFields>;
|
|
32
32
|
export {};
|