-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathfeature.ts
89 lines (77 loc) · 1.93 KB
/
feature.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { StrategyTransportInterface } from './strategy';
import { EnhancedStrategyTransportInterface, Segment } from './strategy/strategy';
// eslint-disable-next-line import/no-cycle
import { VariantDefinition } from './variant';
export interface Dependency {
feature: string;
variants?: string[];
enabled?: boolean;
}
export interface FeatureInterface {
name: string;
type?: string;
project?: string;
description?: string;
enabled: boolean;
stale?: boolean;
impressionData?: boolean;
strategies?: StrategyTransportInterface[];
variants?: VariantDefinition[];
dependencies?: Dependency[];
}
export interface EnhancedFeatureInterface extends Omit<FeatureInterface, 'strategies'> {
strategies?: EnhancedStrategyTransportInterface[];
}
export interface ClientFeaturesResponse {
version: number;
features: FeatureInterface[];
segments?: Segment[];
query?: any;
}
export interface ClientFeaturesDelta {
events: DeltaEvent[];
}
export const parseClientFeaturesDelta = (delta: unknown): ClientFeaturesDelta => {
if (
typeof delta === 'object' &&
delta !== null &&
'events' in delta &&
Array.isArray(delta.events)
) {
return delta as ClientFeaturesDelta;
}
throw new Error(`Invalid delta response: ${JSON.stringify(delta, null, 2)}`);
};
export type DeltaEvent =
| FeatureUpdated
| FeatureRemoved
| SegmentUpdated
| SegmentRemoved
| Hydration;
export type FeatureUpdated = {
type: 'feature-updated';
eventId: number;
feature: FeatureInterface;
};
export type FeatureRemoved = {
type: 'feature-removed';
eventId: number;
featureName: string;
project: string;
};
export type SegmentUpdated = {
type: 'segment-updated';
eventId: number;
segment: Segment;
};
export type SegmentRemoved = {
type: 'segment-removed';
eventId: number;
segmentId: number;
};
export type Hydration = {
type: 'hydration';
eventId: number;
features: FeatureInterface[];
segments: Segment[];
};