Skip to content

Commit 63558ca

Browse files
Merge pull request #92 from splitio/update_types
Update type definitions to reuse SplitIO namespace definitions and avoid name conflicts
2 parents c53852a + 7fa2644 commit 63558ca

File tree

2 files changed

+143
-194
lines changed

2 files changed

+143
-194
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
- Added support for synchronizing feature flags with rule-based segments. These segments determine membership at runtime by evaluating their configured rules against the user attributes provided to the SDK.
33
- Added support for synchronizing feature flags with prerequisites. This allows customers to define dependency conditions between flags, which are evaluated before any allowlists or targeting rules.
44
- Added support for synchronizing SDK impressions with properties.
5+
- Added support for the new impressions tracking toggle available on feature flags.
56
- Added `sync.requestOptions.getHeaderOverrides` configuration option to enhance Synchronizer HTTP request Headers for Authorization Frameworks.
67
- Updated @splitsoftware/splitio-commons package to version 2.3.0 and some transitive dependencies for vulnerability fixes and other improvements.
78
- BREAKING CHANGES:

types/index.d.ts

Lines changed: 142 additions & 194 deletions
Original file line numberDiff line numberDiff line change
@@ -2,246 +2,194 @@
22
// Project: https://www.split.io/
33
// Definitions by: Emiliano Sanchez <https://github.com/EmilianoSanchez/>
44

5+
import '@splitsoftware/splitio-commons';
56
import { RequestOptions } from 'http';
67

7-
export = JsSyncTools;
8-
9-
declare module JsSyncTools {
8+
/**
9+
* JavaScript synchronizer tool.
10+
*
11+
* @see {@link https://help.split.io/hc/en-us/articles/4421513571469-Split-JavaScript-synchronizer-tools}.
12+
*/
13+
export class Synchronizer {
1014
/**
11-
* JavaScript synchronizer tool.
15+
* Creates a new Synchronizer instance
1216
*
13-
* @see {@link https://help.split.io/hc/en-us/articles/4421513571469-Split-JavaScript-synchronizer-tools}.
17+
* @param config - The synchronizer config object
1418
*/
15-
export class Synchronizer {
16-
/**
17-
* Creates a new Synchronizer instance
18-
*
19-
* @param config - The synchronizer config object
20-
*/
21-
constructor(config: ISynchronizerSettings);
22-
/**
23-
* Execute synchronization
24-
*
25-
* @param cb - Optional error-first callback to be invoked when the synchronization ends. The callback will be invoked with an error as first argument if the synchronization fails.
26-
* @returns A promise that resolves when the operation ends, with a boolean indicating if operation succeeded or not. The promise never rejects.
27-
*/
28-
execute(cb?: (err?: Error) => void): Promise<boolean>;
29-
// @TODO expose settings eventually
30-
// settings: ISettings
31-
}
32-
19+
constructor(config: ISynchronizerSettings);
3320
/**
34-
* Log levels.
21+
* Execute synchronization
22+
*
23+
* @param cb - Optional error-first callback to be invoked when the synchronization ends. The callback will be invoked with an error as first argument if the synchronization fails.
24+
* @returns A promise that resolves when the operation ends, with a boolean indicating if operation succeeded or not. The promise never rejects.
3525
*/
36-
type LogLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'NONE';
26+
execute(cb?: (err?: Error) => void): Promise<boolean>;
27+
// @TODO expose settings eventually
28+
// settings: ISettings
29+
}
30+
31+
/**
32+
* Settings interface for Synchronizer instances.
33+
*
34+
* @see {@link https://help.split.io/hc/en-us/articles/4421513571469-Split-JavaScript-synchronizer-tools#configuration}
35+
*/
36+
export interface ISynchronizerSettings {
3737
/**
38-
* Available URL settings for the synchronizer.
38+
* Core settings.
3939
*/
40-
type UrlSettings = {
41-
/**
42-
* String property to override the base URL where the synchronizer will get feature flagging related data like a feature flag rollout plan or segments information.
43-
*
44-
* @defaultValue `'https://sdk.split.io/api'`
45-
*/
46-
sdk?: string
40+
core: {
4741
/**
48-
* String property to override the base URL where the synchronizer will post impressions and events.
42+
* Your SDK key.
4943
*
50-
* @defaultValue `'https://events.split.io/api'`
44+
* @see {@link https://help.split.io/hc/en-us/articles/360019916211-API-keys}
5145
*/
52-
events?: string,
53-
/**
54-
* String property to override the base URL where the synchronizer will post telemetry data.
55-
*
56-
* @defaultValue `'https://telemetry.split.io/api'`
57-
*/
58-
telemetry?: string
59-
};
60-
61-
/**
62-
* SplitFilter type.
63-
*/
64-
type SplitFilterType = 'byName' | 'bySet';
46+
authorizationKey: string
47+
}
6548
/**
66-
* Defines a feature flag filter, described by a type and list of values.
49+
* Defines which kind of storage we should instantiate.
6750
*/
68-
interface SplitFilter {
51+
storage: {
52+
/**
53+
* Storage type. The only possible value is `'PLUGGABLE'`, which is the default.
54+
*/
55+
type?: 'PLUGGABLE',
6956
/**
70-
* Type of the filter.
57+
* A valid storage instance.
7158
*/
72-
type: SplitFilterType,
59+
wrapper: Object
7360
/**
74-
* List of values: feature flag names for 'byName' filter type, and feature flag name prefixes for 'byPrefix' type.
61+
* Optional prefix added to the storage keys to prevent any kind of data collision between SDK versions.
62+
*
63+
* @defaultValue `'SPLITIO'`
7564
*/
76-
values: string[],
65+
prefix?: string
7766
}
7867
/**
79-
* ImpressionsMode type.
68+
* List of URLs that the Synchronizer will use as base for it's synchronization functionalities.
69+
* Do not change these settings unless you're working an advanced use case, like connecting to a proxy.
8070
*/
81-
type ImpressionsMode = 'OPTIMIZED' | 'DEBUG';
71+
urls?: SplitIO.UrlSettings
8272
/**
83-
* Settings interface for Synchronizer instances.
73+
* Boolean value to indicate whether the logger should be enabled or disabled by default, or a log level string.
74+
*
75+
* Examples:
76+
* ```
77+
* config.debug = true
78+
* config.debug = 'WARN'
79+
* ```
8480
*
85-
* @see {@link https://help.split.io/hc/en-us/articles/4421513571469-Split-JavaScript-synchronizer-tools#configuration}
81+
* @defaultValue `false`
8682
*/
87-
interface ISynchronizerSettings {
88-
/**
89-
* Core settings.
90-
*/
91-
core: {
92-
/**
93-
* Your SDK key.
94-
*
95-
* @see {@link https://help.split.io/hc/en-us/articles/360019916211-API-keys}
96-
*/
97-
authorizationKey: string
98-
}
83+
debug?: boolean | SplitIO.LogLevel
84+
/**
85+
* Synchronization settings.
86+
*/
87+
sync?: {
9988
/**
100-
* Defines which kind of storage we should instantiate.
89+
* List of feature flag filters. These filters are used to fetch a subset of the feature flag definitions in your environment.
90+
*
91+
* Example:
92+
* ```
93+
* splitFilter: [
94+
* { type: 'byName', values: ['my_feature_flag_1', 'my_feature_flag_2'] }, // will fetch feature flags named 'my_feature_flag_1' and 'my_feature_flag_2'
95+
* ]
96+
* ```
10197
*/
102-
storage: {
103-
/**
104-
* Storage type. The only possible value is `'PLUGGABLE'`, which is the default.
105-
*/
106-
type?: 'PLUGGABLE',
107-
/**
108-
* A valid storage instance.
109-
*/
110-
wrapper: Object
111-
/**
112-
* Optional prefix added to the storage keys to prevent any kind of data collision between SDK versions.
113-
*
114-
* @defaultValue `'SPLITIO'`
115-
*/
116-
prefix?: string
117-
}
98+
splitFilters?: SplitIO.SplitFilter[]
11899
/**
119-
* List of URLs that the Synchronizer will use as base for it's synchronization functionalities.
120-
* Do not change these settings unless you're working an advanced use case, like connecting to a proxy.
100+
* Feature Flag Spec version. Option to determine which version of the feature flag definitions are fetched and stored.
101+
* Possible values are `'1.0'`, `'1.1'`, `'1.2'`, and `'1.3'`.
102+
*
103+
* @defaultValue `'1.3'`
121104
*/
122-
urls?: UrlSettings
105+
flagSpecVersion?: '1.0' | '1.1' | '1.2' | '1.3'
123106
/**
124-
* Boolean value to indicate whether the logger should be enabled or disabled by default, or a log level string.
107+
* Impressions Collection Mode. Option to determine how impressions are going to be sent to Split Servers.
125108
*
126-
* Examples:
127-
* ```
128-
* config.debug = true
129-
* config.debug = 'WARN'
130-
* ```
109+
* Possible values are `'DEBUG'` and `'OPTIMIZED'`.
110+
* - DEBUG: will send all the impressions generated (recommended only for debugging purposes).
111+
* - OPTIMIZED: will send unique impressions to Split Servers avoiding a considerable amount of traffic that duplicated impressions could generate.
131112
*
132-
* @defaultValue `false`
113+
* @defaultValue `'OPTIMIZED'`
133114
*/
134-
debug?: boolean | LogLevel
115+
impressionsMode?: SplitIO.ImpressionsMode
135116
/**
136-
* Synchronization settings.
117+
* Custom options object for HTTP(S) requests in Node.js.
118+
* If provided, this object is merged with the options object passed for Node-Fetch calls.
119+
*
120+
* @see {@link https://www.npmjs.com/package/node-fetch#options}
137121
*/
138-
sync?: {
122+
requestOptions?: {
139123
/**
140-
* List of feature flag filters. These filters are used to fetch a subset of the feature flag definitions in your environment.
124+
* Custom function called before each request, allowing you to add or update headers in Synchronizer HTTP requests.
125+
* Some headers, such as `SplitSDKVersion`, are required by the Synchronizer and cannot be overridden.
126+
* To pass multiple headers with the same name, combine their values into a single line, separated by commas. Example: `{ 'Authorization': 'value1, value2' }`
127+
* Or provide keys with different cases since headers are case-insensitive. Example: `{ 'authorization': 'value1', 'Authorization': 'value2' }`
128+
*
129+
* @defaultValue `undefined`
141130
*
142-
* Example:
131+
* @param context - The context for the request, which contains the `headers` property object representing the current headers in the request.
132+
* @returns An object representing a set of headers to be merged with the current headers.
133+
*
134+
* @example
143135
* ```
144-
* splitFilter: [
145-
* { type: 'byName', values: ['my_feature_flag_1', 'my_feature_flag_2'] }, // will fetch feature flags named 'my_feature_flag_1' and 'my_feature_flag_2'
146-
* ]
136+
* const getHeaderOverrides = (context) => {
137+
* return {
138+
* 'Authorization': context.headers['Authorization'] + ', other-value',
139+
* 'custom-header': 'custom-value'
140+
* };
141+
* };
147142
* ```
148143
*/
149-
splitFilters?: SplitFilter[]
144+
getHeaderOverrides?: (context: { headers: Record<string, string> }) => Record<string, string>;
150145
/**
151-
* Feature Flag Spec version. Option to determine which version of the feature flag definitions are fetched and stored.
152-
* Possible values are `'1.0'`, `'1.1'`, `'1.2'`, and `'1.3'`.
146+
* Custom Node.js HTTP(S) Agent used for HTTP(S) requests.
153147
*
154-
* @defaultValue `'1.3'`
155-
*/
156-
flagSpecVersion?: '1.0' | '1.1' | '1.2' | '1.3'
157-
/**
158-
* Impressions Collection Mode. Option to determine how impressions are going to be sent to Split Servers.
148+
* You can use it, for example, for certificate pinning or setting a network proxy:
159149
*
160-
* Possible values are `'DEBUG'` and `'OPTIMIZED'`.
161-
* - DEBUG: will send all the impressions generated (recommended only for debugging purposes).
162-
* - OPTIMIZED: will send unique impressions to Split Servers avoiding a considerable amount of traffic that duplicated impressions could generate.
163-
*
164-
* @defaultValue `'OPTIMIZED'`
165-
*/
166-
impressionsMode?: ImpressionsMode
167-
/**
168-
* Custom options object for HTTP(S) requests in Node.js.
169-
* If provided, this object is merged with the options object passed for Node-Fetch calls.
150+
* ```
151+
* const { HttpsProxyAgent } = require('https-proxy-agent');
170152
*
171-
* @see {@link https://www.npmjs.com/package/node-fetch#options}
172-
*/
173-
requestOptions?: {
174-
/**
175-
* Custom function called before each request, allowing you to add or update headers in Synchronizer HTTP requests.
176-
* Some headers, such as `SplitSDKVersion`, are required by the Synchronizer and cannot be overridden.
177-
* To pass multiple headers with the same name, combine their values into a single line, separated by commas. Example: `{ 'Authorization': 'value1, value2' }`
178-
* Or provide keys with different cases since headers are case-insensitive. Example: `{ 'authorization': 'value1', 'Authorization': 'value2' }`
179-
*
180-
* @defaultValue `undefined`
181-
*
182-
* @param context - The context for the request, which contains the `headers` property object representing the current headers in the request.
183-
* @returns An object representing a set of headers to be merged with the current headers.
184-
*
185-
* @example
186-
* ```
187-
* const getHeaderOverrides = (context) => {
188-
* return {
189-
* 'Authorization': context.headers['Authorization'] + ', other-value',
190-
* 'custom-header': 'custom-value'
191-
* };
192-
* };
193-
* ```
194-
*/
195-
getHeaderOverrides?: (context: { headers: Record<string, string> }) => Record<string, string>;
196-
/**
197-
* Custom Node.js HTTP(S) Agent used for HTTP(S) requests.
198-
*
199-
* You can use it, for example, for certificate pinning or setting a network proxy:
200-
*
201-
* ```
202-
* const { HttpsProxyAgent } = require('https-proxy-agent');
203-
*
204-
* const proxyAgent = new HttpsProxyAgent(process.env.HTTPS_PROXY || 'http://10.10.1.10:1080');
205-
*
206-
* const synchronizer = Synchronizer({
207-
* ...
208-
* sync: {
209-
* requestOptions: {
210-
* agent: proxyAgent
211-
* }
212-
* }
213-
* })
214-
* ```
215-
*
216-
* @see {@link https://nodejs.org/api/https.html#class-httpsagent}
217-
*
218-
* @defaultValue `undefined`
219-
*/
220-
agent?: RequestOptions['agent']
221-
},
222-
}
223-
/**
224-
* Scheduler settings.
225-
*/
226-
scheduler?: {
227-
/**
228-
* Maximum number of impressions to send per POST request.
153+
* const proxyAgent = new HttpsProxyAgent(process.env.HTTPS_PROXY || 'http://10.10.1.10:1080');
229154
*
230-
* @defaultValue `1000`
231-
*/
232-
impressionsPerPost?: number
233-
/**
234-
* Maximum number of events to send per POST request.
155+
* const synchronizer = Synchronizer({
156+
* ...
157+
* sync: {
158+
* requestOptions: {
159+
* agent: proxyAgent
160+
* }
161+
* }
162+
* })
163+
* ```
235164
*
236-
* @defaultValue `1000`
237-
*/
238-
eventsPerPost?: number
239-
/**
240-
* Maximum number of retry attempts for posting impressions and events.
165+
* @see {@link https://nodejs.org/api/https.html#class-httpsagent}
241166
*
242-
* @defaultValue `3`
167+
* @defaultValue `undefined`
243168
*/
244-
maxRetries?: number
245-
}
169+
agent?: RequestOptions['agent']
170+
},
171+
}
172+
/**
173+
* Scheduler settings.
174+
*/
175+
scheduler?: {
176+
/**
177+
* Maximum number of impressions to send per POST request.
178+
*
179+
* @defaultValue `1000`
180+
*/
181+
impressionsPerPost?: number
182+
/**
183+
* Maximum number of events to send per POST request.
184+
*
185+
* @defaultValue `1000`
186+
*/
187+
eventsPerPost?: number
188+
/**
189+
* Maximum number of retry attempts for posting impressions and events.
190+
*
191+
* @defaultValue `3`
192+
*/
193+
maxRetries?: number
246194
}
247195
}

0 commit comments

Comments
 (0)