Skip to content

Commit e86fe01

Browse files
Update ConfigsFetcher with new DTO
AI-Session-Id: b6e1bc93-ea86-4eef-b2d1-cfd87bd6cdcd AI-Tool: claude-code AI-Model: unknown
1 parent abfc21a commit e86fe01

2 files changed

Lines changed: 34 additions & 16 deletions

File tree

src/sync/polling/fetchers/__tests__/configsFetcher.spec.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ import { ISplitChangesResponse } from '../../../../dtos/types';
22
import { convertConfigsResponseToDefinitionChangesResponse, IConfigsResponse } from '../configsFetcher';
33

44
const INPUT: IConfigsResponse = {
5-
s: 100,
6-
t: 200,
7-
d: [{ 'name': 'SomeConfig1', 'defaultVariant': 'v2', 'variants': [{ 'name': 'v1', 'definition': { 'prop1': true, 'prop2': 123 } }, { 'name': 'v2', 'definition': { 'prop1': false, 'prop2': 456 } }], 'targeting': { 'conditions': [{ 'variant': 'v1', 'label': 'main condition', 'matchers': [{ 'type': 'IS_EQUAL_TO', 'data': { 'type': 'NUMBER', 'number': 42 }, 'attribute': 'age' }, { 'type': 'WHITELIST', 'data': { 'strings': ['a', 'b', 'c'] }, 'attribute': 'favoriteCharacter' }] }] } }],
5+
since: 100,
6+
till: 200,
7+
updated: [{
8+
name: 'SomeConfig1',
9+
variants: [{ name: 'v1', definition: { prop1: true, prop2: 123 } }, { name: 'v2', definition: { prop1: false, prop2: 456 } }],
10+
changeNumber: 0,
11+
targeting: { default: 'v2', conditions: [{ partitions: [{ variant: 'v1', size: 100 }], label: 'main condition', matchers: [{ type: 'IS_EQUAL_TO', data: { type: 'NUMBER', number: 42 }, attribute: 'age' }, { type: 'WHITELIST', data: { strings: ['a', 'b', 'c'] }, attribute: 'favoriteCharacter' }] }] }
12+
}],
813
};
914

1015
const EXPECTED_OUTPUT: ISplitChangesResponse = {

src/sync/polling/fetchers/configsFetcher.ts

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,41 @@ type IConfigMatcher = {
1313
attribute?: string;
1414
}
1515

16-
type IConfig = {
16+
interface IConfigPartition {
17+
variant: string
18+
size: number
19+
}
20+
21+
interface IConfig {
1722
name: string;
1823
variants: Array<{
1924
name: string;
2025
definition: SplitIO.JsonObject;
2126
}>;
22-
defaultVariant: string;
23-
changeNumber?: number;
27+
changeNumber: number;
28+
trafficTypeName?: string;
29+
version?: number;
30+
status?: 'ACTIVE' | 'ARCHIVED';
31+
killed?: boolean;
32+
sets?: string[];
2433
targeting?: {
34+
default?: string;
35+
seed?: number;
36+
trafficAllocation?: number,
37+
trafficAllocationSeed?: number,
2538
conditions?: Array<{
26-
variant: string;
2739
label: string;
40+
partitions: Array<IConfigPartition>;
2841
matchers: Array<IConfigMatcher>;
2942
}>
3043
};
3144
}
3245

3346
/** Interface of the parsed JSON response of `/configs` */
34-
export type IConfigsResponse = {
35-
t: number,
36-
s?: number,
37-
d: IConfig[]
47+
export interface IConfigsResponse {
48+
till: number,
49+
since?: number,
50+
updated: IConfig[]
3851
}
3952

4053
/**
@@ -100,7 +113,7 @@ function convertMatcher(matcher: IConfigMatcher): ISplitMatcher {
100113
}
101114

102115
function convertConfigToDefinition(config: IConfig): ISplit {
103-
const defaultTreatment = config.defaultVariant || (config.variants && config.variants[0]?.name) || 'control';
116+
const defaultTreatment = config.targeting?.default || config.variants[0]?.name || 'control';
104117

105118
const configurations: Record<string, SplitIO.JsonObject> = {};
106119
config.variants.forEach(variant => configurations[variant.name] = variant.definition);
@@ -112,7 +125,7 @@ function convertConfigToDefinition(config: IConfig): ISplit {
112125
combiner: 'AND',
113126
matchers: condition.matchers.map(convertMatcher),
114127
},
115-
partitions: [{ treatment: condition.variant, size: 100 }],
128+
partitions: condition.partitions.map(partition => ({ treatment: partition.variant, size: partition.size })),
116129
})) || [];
117130

118131
conditions.push(defaultCondition(defaultTreatment));
@@ -133,9 +146,9 @@ function convertConfigToDefinition(config: IConfig): ISplit {
133146
export function convertConfigsResponseToDefinitionChangesResponse(configs: IConfigsResponse): ISplitChangesResponse {
134147
return {
135148
ff: {
136-
s: configs.s,
137-
t: configs.t,
138-
d: configs.d.map(convertConfigToDefinition),
149+
s: configs.since,
150+
t: configs.till,
151+
d: configs.updated.map(convertConfigToDefinition),
139152
},
140153
};
141154
}

0 commit comments

Comments
 (0)