@@ -68,10 +68,10 @@ export type FlagConfigurationRequestParameters = {
68
68
skipInitialPoll ?: boolean ;
69
69
} ;
70
70
71
- export interface IFlagExperiment < T > {
71
+ export interface IContainerExperiment < T > {
72
72
flagKey : string ;
73
- controlVariation : T ;
74
- treatmentVariations : Array < T > ;
73
+ controlVariationEntry : T ;
74
+ treatmentVariationEntries : Array < T > ;
75
75
}
76
76
77
77
export default class EppoClient {
@@ -531,32 +531,49 @@ export default class EppoClient {
531
531
}
532
532
533
533
/**
534
- * For use with 3rd party CMS tooling, such as the Contentful Eppo plugin
534
+ * For use with 3rd party CMS tooling, such as the Contentful Eppo plugin.
535
+ *
536
+ * CMS plugins that integrate with Eppo will follow a common format for
537
+ * creating a feature flag. The flag created by the CMS plugin will have
538
+ * variations with values 'control', 'treatment-1', 'treatment-2', etc.
539
+ * This function allows users to easily return the CMS container entry
540
+ * for the assigned variation.
541
+ *
542
+ * @param flagExperiment the flag key, control container entry and treatment container entries.
543
+ * @param subjectKey an identifier of the experiment subject, for example a user ID.
544
+ * @param subjectAttributes optional attributes associated with the subject, for example name and email.
545
+ * @returns The container entry associated with the experiment.
535
546
*/
536
- public getExperimentContainer < T > (
537
- flagExperiment : IFlagExperiment < T > ,
547
+ public getExperimentContainerEntry < T > (
548
+ flagExperiment : IContainerExperiment < T > ,
538
549
subjectKey : string ,
539
550
subjectAttributes : Attributes ,
540
551
) : T {
541
- const { flagKey, controlVariation , treatmentVariations } = flagExperiment ;
552
+ const { flagKey, controlVariationEntry , treatmentVariationEntries } = flagExperiment ;
542
553
const assignment = this . getStringAssignment ( flagKey , subjectKey , subjectAttributes , 'control' ) ;
543
554
if ( assignment === 'control' ) {
544
- return controlVariation ;
555
+ return controlVariationEntry ;
545
556
}
546
557
if ( ! assignment . startsWith ( 'treatment-' ) ) {
547
558
logger . warn (
548
559
`Variation ${ assignment } cannot be mapped to a container. Defaulting to control variation.` ,
549
560
) ;
550
- return controlVariation ;
561
+ return controlVariationEntry ;
562
+ }
563
+ const treatmentVariationIndex = Number . parseInt ( assignment . split ( '-' ) [ 1 ] ) - 1 ;
564
+ if ( isNaN ( treatmentVariationIndex ) ) {
565
+ logger . warn (
566
+ `Variation ${ assignment } cannot be mapped to a container. Defaulting to control variation.` ,
567
+ ) ;
568
+ return controlVariationEntry ;
551
569
}
552
- const treatmentVariationIndex = Number . parseInt ( assignment . split ( '-' ) [ 1 ] ) ;
553
- if ( treatmentVariationIndex > treatmentVariations . length ) {
570
+ if ( treatmentVariationIndex >= treatmentVariationEntries . length ) {
554
571
logger . warn (
555
572
`Selected treatment variation (${ treatmentVariationIndex } ) index is out of bounds. Defaulting to control variation.` ,
556
573
) ;
557
- return controlVariation ;
574
+ return controlVariationEntry ;
558
575
}
559
- return treatmentVariations [ treatmentVariationIndex - 1 ] ;
576
+ return treatmentVariationEntries [ treatmentVariationIndex ] ;
560
577
}
561
578
562
579
private evaluateBanditAction (
0 commit comments