Skip to content

Commit 7baee32

Browse files
Merge branch 'rb_segments_polishing' into prerequisites_refactors
2 parents eb84a92 + fc2e7b4 commit 7baee32

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2.3.0 (April XXX, 2025)
2+
- Added support for targeting rules based on rule-based segments.
3+
14
2.2.0 (March 28, 2025)
25
- Added a new optional argument to the client `getTreatment` methods to allow passing additional evaluation options, such as a map of properties to append to the generated impressions sent to Split backend. Read more in our docs.
36
- Added two new configuration options for the SDK storage in browsers when using storage type `LOCALSTORAGE`:

src/dtos/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,10 @@ export interface IRBSegment {
203203
name: string,
204204
changeNumber: number,
205205
status: 'ACTIVE' | 'ARCHIVED',
206-
conditions: ISplitCondition[],
207-
excluded: {
208-
keys: string[],
209-
segments: string[]
206+
conditions?: ISplitCondition[],
207+
excluded?: {
208+
keys?: string[],
209+
segments?: string[]
210210
}
211211
}
212212

src/evaluator/matchers/rbsegment.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function ruleBasedSegmentMatcherContext(segmentName: string, storage: ISt
1212
return function ruleBasedSegmentMatcher({ key, attributes }: IDependencyMatcherValue, splitEvaluator: ISplitEvaluator): MaybeThenable<boolean> {
1313

1414
function matchConditions(rbsegment: IRBSegment) {
15-
const conditions = rbsegment.conditions;
15+
const conditions = rbsegment.conditions || [];
1616
const evaluator = parser(log, conditions, storage);
1717

1818
const evaluation = evaluator(
@@ -31,10 +31,11 @@ export function ruleBasedSegmentMatcherContext(segmentName: string, storage: ISt
3131

3232
function isExcluded(rbSegment: IRBSegment) {
3333
const matchingKey = getMatching(key);
34+
const excluded = rbSegment.excluded || {};
3435

35-
if (rbSegment.excluded.keys.indexOf(matchingKey) !== -1) return true;
36+
if (excluded.keys && excluded.keys.indexOf(matchingKey) !== -1) return true;
3637

37-
const isInSegment = rbSegment.excluded.segments.map(segmentName => {
38+
const isInSegment = (excluded.segments || []).map(segmentName => {
3839
return storage.segments.isInSegment(segmentName, matchingKey);
3940
});
4041

src/sync/polling/updaters/splitChangesUpdater.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function checkAllSegmentsExist(segments: ISegmentsCacheBase): Promise<boolean> {
3030
* Exported for testing purposes.
3131
*/
3232
export function parseSegments(ruleEntity: ISplit | IRBSegment, matcherType: typeof IN_SEGMENT | typeof IN_RULE_BASED_SEGMENT = IN_SEGMENT): Set<string> {
33-
const { conditions, excluded } = ruleEntity as IRBSegment;
33+
const { conditions = [], excluded } = ruleEntity as IRBSegment;
3434
const segments = new Set<string>(excluded && excluded.segments);
3535

3636
for (let i = 0; i < conditions.length; i++) {

0 commit comments

Comments
 (0)