-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtypes.ts
More file actions
117 lines (100 loc) · 4.94 KB
/
types.ts
File metadata and controls
117 lines (100 loc) · 4.94 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { IIntegrationManager, IIntegrationFactoryParams } from '../integrations/types';
import { ISignalListener } from '../listeners/types';
import { IReadinessManager, ISdkReadinessManager } from '../readiness/types';
import type { sdkManagerFactory } from '../sdkManager';
import type { splitApiFactory } from '../services/splitApi';
import { IFetch, ISplitApi, IEventSourceConstructor } from '../services/types';
import { IStorageAsync, IStorageSync, IStorageFactoryParams } from '../storages/types';
import { ISyncManager, ITask } from '../sync/types';
import { IImpressionObserver } from '../trackers/impressionObserver/types';
import { IImpressionsTracker, IEventTracker, ITelemetryTracker, IFilterAdapter, IUniqueKeysTracker } from '../trackers/types';
import { SplitIO, ISettings, IEventEmitter, IBasicClient } from '../types';
/**
* Environment related dependencies.
*/
export interface IPlatform {
/**
* If provided, it is used to retrieve the Fetch API for HTTP requests. Otherwise, the global fetch is used.
*/
getFetch?: (settings: ISettings) => (IFetch | undefined)
/**
* If provided, it is used to pass additional options to fetch and eventsource calls.
*/
getOptions?: (settings: ISettings) => object
/**
* If provided, it is used to retrieve the EventSource constructor for streaming support.
*/
getEventSource?: (settings: ISettings) => (IEventSourceConstructor | undefined)
/**
* EventEmitter constructor, like NodeJS.EventEmitter or a polyfill.
*/
EventEmitter: new () => IEventEmitter,
/**
* Function used to track latencies for telemetry.
*/
now?: () => number
}
export interface ISdkFactoryContext {
platform: IPlatform,
sdkReadinessManager: ISdkReadinessManager,
readiness: IReadinessManager,
settings: ISettings
impressionsTracker: IImpressionsTracker,
eventTracker: IEventTracker,
telemetryTracker: ITelemetryTracker,
storage: IStorageSync | IStorageAsync,
uniqueKeysTracker?: IUniqueKeysTracker,
signalListener?: ISignalListener
splitApi?: ISplitApi
syncManager?: ISyncManager,
mySegmentsSyncManager?: ITask,
clients: Record<string, IBasicClient>,
}
export interface ISdkFactoryContextSync extends ISdkFactoryContext {
storage: IStorageSync,
splitApi: ISplitApi
syncManager: ISyncManager,
}
export interface ISdkFactoryContextAsync extends ISdkFactoryContext {
storage: IStorageAsync,
splitApi: undefined,
syncManager: undefined
}
/**
* Object parameter with the modules required to create an SDK factory instance
*/
export interface ISdkFactoryParams {
// The settings must be already validated
settings: ISettings,
// Platform dependencies
platform: IPlatform,
// Storage factory. The result storage type implies the type of the SDK:
// sync SDK (`ISDK` or `ICsSDK`) with `IStorageSync`, and async SDK (`IAsyncSDK`) with `IStorageAsync`
storageFactory: (params: IStorageFactoryParams) => IStorageSync | IStorageAsync,
// Factory of Split Api (HTTP Client Service).
// It is not required when providing an asynchronous storage or offline SyncManager
splitApiFactory?: typeof splitApiFactory,
// SyncManager factory.
// Not required when providing an asynchronous storage (consumer mode), but required in standalone mode to avoid SDK timeout.
// It can create an offline or online sync manager, with or without streaming support.
syncManagerFactory?: (params: ISdkFactoryContextSync) => ISyncManager,
// Sdk manager factory
sdkManagerFactory: typeof sdkManagerFactory,
// Sdk client method factory (ISDK::client method).
// It Allows to distinguish SDK clients with the client-side API (`ICsSDK`) or server-side API (`ISDK` or `IAsyncSDK`).
sdkClientMethodFactory: (params: ISdkFactoryContext) => ({ (): SplitIO.ICsClient; (key: SplitIO.SplitKey, trafficType?: string | undefined): SplitIO.ICsClient; } | (() => SplitIO.IClient) | (() => SplitIO.IAsyncClient))
// Impression observer factory.
impressionsObserverFactory: () => IImpressionObserver
filterAdapterFactory?: () => IFilterAdapter
// Optional signal listener constructor. Used to handle special app states, like shutdown, app paused or resumed.
// Pass only if `syncManager` (used by Node listener) and `splitApi` (used by Browser listener) are passed.
SignalListener?: new (
syncManager: ISyncManager | undefined, // Used by NodeSignalListener to flush data, and by BrowserSignalListener to close streaming connection.
settings: ISettings, // Used by BrowserSignalListener
storage: IStorageSync | IStorageAsync, // Used by BrowserSignalListener
serviceApi: ISplitApi | undefined) => ISignalListener, // Used by BrowserSignalListener
// @TODO review impressionListener and integrations interfaces. What about handling impressionListener as an integration ?
integrationsManagerFactory?: (params: IIntegrationFactoryParams) => IIntegrationManager | undefined,
// Optional function to assign additional properties to the factory instance
extraProps?: (params: ISdkFactoryContext) => object
}