@ninetailed/experience.js-utils
Advanced tools
Comparing version 2.2.0 to 2.2.2
{ | ||
"name": "@ninetailed/experience.js-utils", | ||
"version": "2.2.0", | ||
"version": "2.2.2", | ||
"type": "commonjs", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
import { ExperienceConfiguration } from '@ninetailed/experience.js'; | ||
import { z } from 'zod'; | ||
declare const ExperienceEntry: z.ZodObject<{ | ||
id: z.ZodString; | ||
type: z.ZodUnion<[z.ZodLiteral<"nt_experiment">, z.ZodLiteral<"nt_personalization">]>; | ||
variants: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{ | ||
id: z.ZodString; | ||
}, "passthrough", z.ZodTypeAny, { | ||
id: string; | ||
}, { | ||
id: string; | ||
}>, "many">>>; | ||
name: z.ZodString; | ||
config: z.ZodOptional<z.ZodDefault<z.ZodObject<{ | ||
distribution: z.ZodDefault<z.ZodArray<z.ZodNumber, "many">>; | ||
traffic: z.ZodDefault<z.ZodNumber>; | ||
components: z.ZodDefault<z.ZodArray<z.ZodObject<{ | ||
baseline: z.ZodObject<{ | ||
id: z.ZodDefault<z.ZodString>; | ||
}, "strip", z.ZodTypeAny, { | ||
id: string; | ||
}, { | ||
id?: string | undefined; | ||
}>; | ||
variants: z.ZodArray<z.ZodObject<{ | ||
id: z.ZodDefault<z.ZodString>; | ||
hidden: z.ZodDefault<z.ZodBoolean>; | ||
}, "strip", z.ZodTypeAny, { | ||
id: string; | ||
hidden: boolean; | ||
}, { | ||
id?: string | undefined; | ||
hidden?: boolean | undefined; | ||
}>, "many">; | ||
}, "strip", z.ZodTypeAny, { | ||
baseline: { | ||
id: string; | ||
}; | ||
variants: { | ||
id: string; | ||
hidden: boolean; | ||
}[]; | ||
}, { | ||
baseline: { | ||
id?: string | undefined; | ||
}; | ||
variants: { | ||
id?: string | undefined; | ||
hidden?: boolean | undefined; | ||
}[]; | ||
}>, "many">>; | ||
}, "strip", z.ZodTypeAny, { | ||
distribution: number[]; | ||
traffic: number; | ||
components: { | ||
baseline: { | ||
id: string; | ||
}; | ||
variants: { | ||
id: string; | ||
hidden: boolean; | ||
}[]; | ||
}[]; | ||
}, { | ||
distribution?: number[] | undefined; | ||
traffic?: number | undefined; | ||
components?: { | ||
baseline: { | ||
id?: string | undefined; | ||
}; | ||
variants: { | ||
id?: string | undefined; | ||
hidden?: boolean | undefined; | ||
}[]; | ||
}[] | undefined; | ||
}>>>; | ||
audience: z.ZodNullable<z.ZodOptional<z.ZodObject<{ | ||
id: z.ZodString; | ||
}, "strip", z.ZodTypeAny, { | ||
id: string; | ||
}, { | ||
id: string; | ||
}>>>; | ||
}, "strip", z.ZodTypeAny, { | ||
variants?: { | ||
id: string; | ||
}[] | undefined; | ||
config?: { | ||
distribution: number[]; | ||
traffic: number; | ||
components: { | ||
baseline: { | ||
id: string; | ||
}; | ||
variants: { | ||
id: string; | ||
hidden: boolean; | ||
}[]; | ||
}[]; | ||
} | undefined; | ||
audience?: { | ||
id: string; | ||
} | null | undefined; | ||
id: string; | ||
type: "nt_experiment" | "nt_personalization"; | ||
name: string; | ||
}, { | ||
variants?: { | ||
id: string; | ||
}[] | undefined; | ||
config?: { | ||
distribution?: number[] | undefined; | ||
traffic?: number | undefined; | ||
components?: { | ||
baseline: { | ||
id?: string | undefined; | ||
}; | ||
variants: { | ||
id?: string | undefined; | ||
hidden?: boolean | undefined; | ||
}[]; | ||
}[] | undefined; | ||
} | undefined; | ||
audience?: { | ||
id: string; | ||
} | null | undefined; | ||
id: string; | ||
type: "nt_experiment" | "nt_personalization"; | ||
name: string; | ||
}>; | ||
declare type ExperienceEntry = z.infer<typeof ExperienceEntry>; | ||
declare const ExperimentEntry: z.ZodObject<{ | ||
id: z.ZodString; | ||
type: z.ZodLiteral<"nt_experiment">; | ||
variants: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{ | ||
id: z.ZodString; | ||
}, "passthrough", z.ZodTypeAny, { | ||
id: string; | ||
}, { | ||
id: string; | ||
}>, "many">>>; | ||
name: z.ZodString; | ||
config: z.ZodOptional<z.ZodDefault<z.ZodObject<{ | ||
distribution: z.ZodDefault<z.ZodArray<z.ZodNumber, "many">>; | ||
traffic: z.ZodDefault<z.ZodNumber>; | ||
components: z.ZodDefault<z.ZodArray<z.ZodObject<{ | ||
baseline: z.ZodObject<{ | ||
id: z.ZodDefault<z.ZodString>; | ||
}, "strip", z.ZodTypeAny, { | ||
id: string; | ||
}, { | ||
id?: string | undefined; | ||
}>; | ||
variants: z.ZodArray<z.ZodObject<{ | ||
id: z.ZodDefault<z.ZodString>; | ||
hidden: z.ZodDefault<z.ZodBoolean>; | ||
}, "strip", z.ZodTypeAny, { | ||
id: string; | ||
hidden: boolean; | ||
}, { | ||
id?: string | undefined; | ||
hidden?: boolean | undefined; | ||
}>, "many">; | ||
}, "strip", z.ZodTypeAny, { | ||
baseline: { | ||
id: string; | ||
}; | ||
variants: { | ||
id: string; | ||
hidden: boolean; | ||
}[]; | ||
}, { | ||
baseline: { | ||
id?: string | undefined; | ||
}; | ||
variants: { | ||
id?: string | undefined; | ||
hidden?: boolean | undefined; | ||
}[]; | ||
}>, "many">>; | ||
}, "strip", z.ZodTypeAny, { | ||
distribution: number[]; | ||
traffic: number; | ||
components: { | ||
baseline: { | ||
id: string; | ||
}; | ||
variants: { | ||
id: string; | ||
hidden: boolean; | ||
}[]; | ||
}[]; | ||
}, { | ||
distribution?: number[] | undefined; | ||
traffic?: number | undefined; | ||
components?: { | ||
baseline: { | ||
id?: string | undefined; | ||
}; | ||
variants: { | ||
id?: string | undefined; | ||
hidden?: boolean | undefined; | ||
}[]; | ||
}[] | undefined; | ||
}>>>; | ||
audience: z.ZodNullable<z.ZodOptional<z.ZodObject<{ | ||
id: z.ZodString; | ||
}, "strip", z.ZodTypeAny, { | ||
id: string; | ||
}, { | ||
id: string; | ||
}>>>; | ||
}, "strip", z.ZodTypeAny, { | ||
variants?: { | ||
id: string; | ||
}[] | undefined; | ||
config?: { | ||
distribution: number[]; | ||
traffic: number; | ||
components: { | ||
baseline: { | ||
id: string; | ||
}; | ||
variants: { | ||
id: string; | ||
hidden: boolean; | ||
}[]; | ||
}[]; | ||
} | undefined; | ||
audience?: { | ||
id: string; | ||
} | null | undefined; | ||
id: string; | ||
type: "nt_experiment"; | ||
name: string; | ||
}, { | ||
variants?: { | ||
id: string; | ||
}[] | undefined; | ||
config?: { | ||
distribution?: number[] | undefined; | ||
traffic?: number | undefined; | ||
components?: { | ||
baseline: { | ||
id?: string | undefined; | ||
}; | ||
variants: { | ||
id?: string | undefined; | ||
hidden?: boolean | undefined; | ||
}[]; | ||
}[] | undefined; | ||
} | undefined; | ||
audience?: { | ||
id: string; | ||
} | null | undefined; | ||
id: string; | ||
type: "nt_experiment"; | ||
name: string; | ||
}>; | ||
declare type ExperimentEntry = z.infer<typeof ExperimentEntry>; | ||
import { Experience, Experiment } from '../types'; | ||
declare type ExperienceEntry = z.input<typeof Experience>; | ||
declare type ExperimentEntry = z.input<typeof Experiment>; | ||
export declare class ExperienceMapper { | ||
static isExperienceEntry(experience: ExperienceEntry): experience is ExperienceEntry; | ||
static isExperienceEntry(experience: ExperienceEntry): experience is Experience; | ||
static mapExperience(experience: ExperienceEntry): ExperienceConfiguration; | ||
static isExperimentEntry(experiment: ExperimentEntry): experiment is ExperimentEntry; | ||
static isExperimentEntry(experiment: ExperimentEntry): experiment is Experiment; | ||
static mapExperiment(experiment: ExperimentEntry): ExperienceConfiguration; | ||
} | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ExperienceMapper = void 0; | ||
const experience_js_1 = require("@ninetailed/experience.js"); | ||
const types_1 = require("../types"); | ||
const ExperienceEntry = types_1.Experience.partial({ config: true, variants: true }); | ||
const ExperimentEntry = types_1.Experiment.partial({ config: true, variants: true }); | ||
class ExperienceMapper { | ||
static isExperienceEntry(experience) { | ||
return ExperienceEntry.safeParse(experience).success; | ||
return types_1.Experience.safeParse(experience).success; | ||
} | ||
@@ -14,3 +13,4 @@ static mapExperience(experience) { | ||
if (!parsedExperience.success) { | ||
throw new Error('The Experience Input is not valid. Please filter data first with `ExperienceMapper.isExperienceEntry`.'); | ||
experience_js_1.logger.warn('[Ninetailed ExperienceMapper]', 'Error parsing experience', parsedExperience.error.format()); | ||
throw new Error(`[Ninetailed ExperienceMapper] The Experience Input is not valid. Please filter data first with "ExperienceMapper.isExperienceEntry".\n${parsedExperience.error.format()}`); | ||
} | ||
@@ -46,3 +46,3 @@ const { id, type, audience, config, variants } = parsedExperience.data; | ||
static isExperimentEntry(experiment) { | ||
return ExperimentEntry.safeParse(experiment).success; | ||
return types_1.Experiment.safeParse(experiment).success; | ||
} | ||
@@ -49,0 +49,0 @@ static mapExperiment(experiment) { |
Sorry, the diff of this file is not supported yet
23992
537