Skip to content

Commit 7c4bd31

Browse files
Merge branch 'sdk-configs-handle-configs-dto' into sdk-configs-rename-split-to-definition
2 parents f79a75c + 3aed036 commit 7c4bd31

1 file changed

Lines changed: 28 additions & 5 deletions

File tree

src/sync/polling/fetchers/configsFetcher.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IConfig, IConfigsResponse, ISplitChangesResponse } from '../../../dtos/types';
1+
import { IConfig, IConfigsResponse, ISplitChangesResponse, ISplitCondition } from '../../../dtos/types';
22
import { IFetchSplitChanges, IResponse } from '../../../services/types';
33
import { ISplitChangesFetcher } from './types';
44

@@ -29,21 +29,44 @@ export function configsFetcherFactory(fetchConfigs: IFetchSplitChanges): ISplitC
2929

3030
}
3131

32+
function defaultCondition(treatment: string): ISplitCondition {
33+
return {
34+
conditionType: 'ROLLOUT' as const,
35+
matcherGroup: {
36+
combiner: 'AND' as const,
37+
matchers: [{
38+
keySelector: { trafficType: 'user', attribute: null },
39+
matcherType: 'ALL_KEYS',
40+
negate: false,
41+
userDefinedSegmentMatcherData: null,
42+
whitelistMatcherData: null,
43+
unaryNumericMatcherData: null,
44+
betweenMatcherData: null,
45+
booleanMatcherData: null,
46+
dependencyMatcherData: null,
47+
stringMatcherData: null,
48+
}],
49+
},
50+
partitions: [{ treatment, size: 100 }],
51+
label: 'default rule',
52+
};
53+
}
54+
3255
function convertConfigsToSplits(configs: IConfigsResponse): ISplitChangesResponse {
3356
return {
3457
...configs,
3558
ff: configs.configs ? {
3659
...configs.configs,
3760
d: configs.configs.d?.map((config: IConfig) => {
38-
// @TODO: review defaults
61+
const dt = config.defaultTreatment || 'default';
3962
return {
4063
...config,
41-
defaultTreatment: config.defaultTreatment,
42-
conditions: config.conditions || [],
64+
defaultTreatment: dt,
65+
conditions: config.conditions && config.conditions.length > 0 ? config.conditions : [defaultCondition(dt)],
4366
killed: config.killed || false,
4467
trafficTypeName: config.trafficTypeName || 'user',
4568
seed: config.seed || 0,
46-
trafficAllocation: config.trafficAllocation || 0,
69+
trafficAllocation: config.trafficAllocation || 100,
4770
trafficAllocationSeed: config.trafficAllocationSeed || 0,
4871
};
4972
})

0 commit comments

Comments
 (0)