@@ -16,7 +16,18 @@ export default class ConfigFeature {
16
16
/** @type {string } */
17
17
name ;
18
18
19
- /** @type {{ debug?: boolean, desktopModeEnabled?: boolean, forcedZoomEnabled?: boolean, featureSettings?: Record<string, unknown>, assets?: import('./content-feature.js').AssetConfig | undefined, site: import('./content-feature.js').Site, messagingConfig?: import('@duckduckgo/messaging').MessagingConfig } | null } */
19
+ /**
20
+ * @type {{
21
+ * debug?: boolean,
22
+ * desktopModeEnabled?: boolean,
23
+ * forcedZoomEnabled?: boolean,
24
+ * featureSettings?: Record<string, unknown>,
25
+ * assets?: import('./content-feature.js').AssetConfig | undefined,
26
+ * site: import('./content-feature.js').Site,
27
+ * messagingConfig?: import('@duckduckgo /messaging').MessagingConfig,
28
+ * currentCohorts?: [{feature: string, cohort: string, subfeature: string}],
29
+ * } | null }
30
+ */
20
31
#args;
21
32
22
33
/**
@@ -95,6 +106,9 @@ export default class ConfigFeature {
95
106
* @typedef {object } ConditionBlock
96
107
* @property {string[] | string } [domain]
97
108
* @property {object } [urlPattern]
109
+ * @property {object } [experiment]
110
+ * @property {string } [experiment.experimentName]
111
+ * @property {string } [experiment.cohort]
98
112
*/
99
113
100
114
/**
@@ -121,6 +135,7 @@ export default class ConfigFeature {
121
135
const conditionChecks = {
122
136
domain : this . _matchDomainConditional ,
123
137
urlPattern : this . _matchUrlPatternConditional ,
138
+ experiment : this . _matchExperimentConditional ,
124
139
} ;
125
140
126
141
for ( const key in conditionBlock ) {
@@ -152,6 +167,36 @@ export default class ConfigFeature {
152
167
return true ;
153
168
}
154
169
170
+ /**
171
+ * Takes a condition block and returns true if the current experiment matches the experimentName and cohort.
172
+ * Expects:
173
+ * ```json
174
+ * {
175
+ * "experiment": {
176
+ * "experimentName": "experimentName",
177
+ * "cohort": "cohort-name"
178
+ * }
179
+ * }
180
+ * ```
181
+ * Where featureName "ContentScopeExperiments" has a subfeature "experimentName" and cohort "cohort-name"
182
+ * @param {ConditionBlock } conditionBlock
183
+ * @returns {boolean }
184
+ */
185
+ _matchExperimentConditional ( conditionBlock ) {
186
+ if ( ! conditionBlock . experiment ) return false ;
187
+ const experiment = conditionBlock . experiment ;
188
+ if ( ! experiment . experimentName || ! experiment . cohort ) return false ;
189
+ const currentCohorts = this . args ?. currentCohorts ;
190
+ if ( ! currentCohorts ) return false ;
191
+ return currentCohorts . some ( ( cohort ) => {
192
+ return (
193
+ cohort . feature === "ContentScopeExperiments" &&
194
+ cohort . subfeature === experiment . experimentName &&
195
+ cohort . cohort === experiment . cohort
196
+ ) ;
197
+ } ) ;
198
+ }
199
+
155
200
/**
156
201
* Takes a condtion block and returns true if the current url matches the urlPattern.
157
202
* @param {ConditionBlock } conditionBlock
0 commit comments