|
1 | | -import { IConfig, IConfigsResponse, ISplitChangesResponse } from '../../../dtos/types'; |
| 1 | +import { IConfig, IConfigsResponse, ISplitChangesResponse, ISplitCondition } from '../../../dtos/types'; |
2 | 2 | import { IFetchSplitChanges, IResponse } from '../../../services/types'; |
3 | 3 | import { ISplitChangesFetcher } from './types'; |
4 | 4 |
|
@@ -29,21 +29,44 @@ export function configsFetcherFactory(fetchConfigs: IFetchSplitChanges): ISplitC |
29 | 29 |
|
30 | 30 | } |
31 | 31 |
|
| 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 | + |
32 | 55 | function convertConfigsToSplits(configs: IConfigsResponse): ISplitChangesResponse { |
33 | 56 | return { |
34 | 57 | ...configs, |
35 | 58 | ff: configs.configs ? { |
36 | 59 | ...configs.configs, |
37 | 60 | d: configs.configs.d?.map((config: IConfig) => { |
38 | | - // @TODO: review defaults |
| 61 | + const dt = config.defaultTreatment || 'default'; |
39 | 62 | return { |
40 | 63 | ...config, |
41 | | - defaultTreatment: config.defaultTreatment, |
42 | | - conditions: config.conditions || [], |
| 64 | + defaultTreatment: dt, |
| 65 | + conditions: config.conditions && config.conditions.length > 0 ? config.conditions : [defaultCondition(dt)], |
43 | 66 | killed: config.killed || false, |
44 | 67 | trafficTypeName: config.trafficTypeName || 'user', |
45 | 68 | seed: config.seed || 0, |
46 | | - trafficAllocation: config.trafficAllocation || 0, |
| 69 | + trafficAllocation: config.trafficAllocation || 100, |
47 | 70 | trafficAllocationSeed: config.trafficAllocationSeed || 0, |
48 | 71 | }; |
49 | 72 | }) |
|
0 commit comments