-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtypes.ts
More file actions
94 lines (71 loc) · 3.56 KB
/
types.ts
File metadata and controls
94 lines (71 loc) · 3.56 KB
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
90
91
92
93
94
import { IAuthToken } from '../sync/streaming/AuthClient/types';
export type IRequestOptions = {
method?: string,
headers?: Record<string, string>,
body?: string
};
export type IResponse = {
ok: boolean,
status: number,
json: () => Promise<any>, // Used to parse OK response body. Promise rejects if body cannot be parsed
text: () => Promise<string>, // Used to read Not OK response body. Promise never rejects
/** Other available properties when using Unfetch */
// statusText: string, // `undefined` in Web fetch since HTTP/2 doesn't have reason phrases anymore. `node-fetch` overwrites it depending on the status code
// url: string,
// blob: () => Promise<Blob>,
// clone: () => IResponse,
// headers: {
// keys: () => string[],
// entries: () => Array<[string, string]>,
// get: (key: string) => string | undefined,
// has: (key: string) => boolean,
// }
}
export type NetworkError = Error & { statusCode?: number }
// Reduced version of Fetch API
export type IFetch = (url: string, options?: IRequestOptions) => Promise<IResponse>
// IFetch specialization
export type IHealthCheckAPI = () => Promise<boolean>
export type ISplitHttpClient = (url: string, options?: IRequestOptions, latencyTracker?: (error?: NetworkError) => void, logErrorsAsInfo?: boolean) => Promise<IResponse>
export type ISecureSplitHttpClient = {
httpClient: ISplitHttpClient;
// Expose the auth token for the SSEClient to use
getAuthData(): Promise<IAuthToken>
}
export type IFetchAuth = (userKeys?: string[]) => Promise<IResponse>
export type IFetchSplitChanges = (since: number, noCache?: boolean, till?: number, rbSince?: number) => Promise<IResponse>
export type IFetchSegmentChanges = (since: number, segmentName: string, noCache?: boolean, till?: number) => Promise<IResponse>
export type IFetchMemberships = (userMatchingKey: string, noCache?: boolean, till?: number) => Promise<IResponse>
export type IPostEventsBulk = (body: string, headers?: Record<string, string>) => Promise<IResponse>
export type IPostUniqueKeysBulkCs = (body: string, headers?: Record<string, string>) => Promise<IResponse>
export type IPostUniqueKeysBulkSs = (body: string, headers?: Record<string, string>) => Promise<IResponse>
export type IPostTestImpressionsBulk = (body: string, headers?: Record<string, string>) => Promise<IResponse>
export type IPostTestImpressionsCount = (body: string, headers?: Record<string, string>) => Promise<IResponse>
export type IPostMetricsConfig = (body: string, headers?: Record<string, string>) => Promise<IResponse>
export type IPostMetricsUsage = (body: string, headers?: Record<string, string>) => Promise<IResponse>
export interface ISplitApi {
getSdkAPIHealthCheck: IHealthCheckAPI
getEventsAPIHealthCheck: IHealthCheckAPI
fetchAuth: IFetchAuth
fetchSplitChanges: IFetchSplitChanges
fetchSegmentChanges: IFetchSegmentChanges
fetchMemberships: IFetchMemberships
postEventsBulk: IPostEventsBulk
postUniqueKeysBulkCs: IPostUniqueKeysBulkCs
postUniqueKeysBulkSs: IPostUniqueKeysBulkSs
postTestImpressionsBulk: IPostTestImpressionsBulk
postTestImpressionsCount: IPostTestImpressionsCount
postMetricsConfig: IPostMetricsConfig
postMetricsUsage: IPostMetricsUsage
}
// Minimal version of EventSource API used by the SDK
interface EventSourceEventMap {
'error': Event
'message': MessageEvent
'open': Event
}
interface IEventSource {
addEventListener<K extends keyof EventSourceEventMap>(type: K, listener: (this: IEventSource, ev: EventSourceEventMap[K]) => any): void
close(): void
}
export type IEventSourceConstructor = new (url: string, eventSourceInitDict?: any) => IEventSource