@ninetailed/experience.js-utils-contentful
Advanced tools
Comparing version 2.0.0-beta.28 to 2.0.0-beta.29
{ | ||
"name": "@ninetailed/experience.js-utils-contentful", | ||
"version": "2.0.0-beta.28", | ||
"version": "2.0.0-beta.29", | ||
"type": "commonjs", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -1,2 +0,2 @@ | ||
import { Baseline, Variant, ExperienceConfiguration } from '@ninetailed/experience.js'; | ||
import { Variant, ExperienceConfiguration } from '@ninetailed/experience.js'; | ||
import { Entry } from 'contentful'; | ||
@@ -8,10 +8,8 @@ import { ExperienceEntry } from '../types'; | ||
}; | ||
declare type MapBaseline<BaselineType = Entry<unknown>> = (baseline: BaselineType) => Baseline; | ||
declare type MapVariant<VariantType = Entry<unknown>> = (variant: VariantType, options: MapVariantOptions) => Variant; | ||
declare type MapExperienceOptions<BaselineType = Entry<unknown>, VariantType = Entry<unknown>> = { | ||
mapBaseline?: MapBaseline<BaselineType>; | ||
declare type MapExperienceOptions<VariantType = Entry<unknown>> = { | ||
mapVariant?: MapVariant<VariantType>; | ||
}; | ||
export declare class ExperienceMapper { | ||
static mapExperience<BaselineType = Entry<unknown>>(entry: ExperienceEntry, baseline: BaselineType, options?: MapExperienceOptions<BaselineType>): ExperienceConfiguration; | ||
static mapExperience(entry: ExperienceEntry, options?: MapExperienceOptions): ExperienceConfiguration; | ||
static mapExperiment(entry: ExperienceEntry): ExperienceConfiguration; | ||
@@ -18,0 +16,0 @@ static mapBaselineWithExperiences(entry: BaselineWithExperiencesEntry): ExperienceConfiguration[]; |
@@ -5,8 +5,5 @@ "use strict"; | ||
const AudienceMapper_1 = require("./AudienceMapper"); | ||
const defaultMapBaseline = (baseline) => (Object.assign(Object.assign({}, baseline), { id: baseline.sys.id })); | ||
const defaultMapVariant = (variant, { hidden }) => (Object.assign(Object.assign({}, variant), { id: variant.sys.id, hidden: hidden })); | ||
class ExperienceMapper { | ||
static mapExperience(entry, baseline, options) { | ||
const _mapBaseline = ((options === null || options === void 0 ? void 0 : options.mapBaseline) || | ||
defaultMapBaseline); | ||
static mapExperience(entry, options) { | ||
const _mapVariant = (options === null || options === void 0 ? void 0 : options.mapVariant) || defaultMapVariant; | ||
@@ -30,3 +27,3 @@ const config = Object.assign({ traffic: 0, distribution: [0.5, 0.5], components: [ | ||
return { | ||
baseline: _mapBaseline(baseline), | ||
baseline: component.baseline, | ||
variants: component.variants | ||
@@ -48,4 +45,3 @@ .map((variant) => { | ||
static mapExperiment(entry) { | ||
return this.mapExperience(entry, null, { | ||
mapBaseline: () => ({ id: '' }), | ||
return this.mapExperience(entry, { | ||
mapVariant: () => ({ id: '', hidden: false }), | ||
@@ -55,3 +51,3 @@ }); | ||
static mapBaselineWithExperiences(entry) { | ||
return entry.fields.nt_experiences.map((experience) => this.mapExperience(experience, entry)); | ||
return entry.fields.nt_experiences.map((experience) => this.mapExperience(experience)); | ||
} | ||
@@ -58,0 +54,0 @@ } |
Sorry, the diff of this file is not supported yet
11973
165