Skip to content

Commit 66210e6

Browse files
Removed the function, which handled the logic to bound an optional traffic type to SDK clients
1 parent 4c979f7 commit 66210e6

File tree

11 files changed

+38
-201
lines changed

11 files changed

+38
-201
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Removed the deprecated `GOOGLE_ANALYTICS_TO_SPLIT` and `SPLIT_TO_GOOGLE_ANALYTICS` integrations.
1010
- Removed internal ponyfills for `Map`, `Set` and `Array.from` global objects, dropping support for IE and other outdated browsers. The SDK now requires the runtime environment to support these features natively or to provide a polyfill.
1111
- Removed the migration logic for the old format of MySegments keys in LocalStorage introduced in JavaScript SDK v10.17.3.
12+
- Removed the `sdkClientMethodCSWithTTFactory` function, which handled the logic to bound an optional traffic type to SDK clients. Client-side SDK implementations must use `sdkClientMethodCSWithTT` which, unlike the previous function, does not allow passing a traffic type but simplifies the SDK API.
1213

1314
1.17.0 (September 6, 2024)
1415
- Added `sync.requestOptions.getHeaderOverrides` configuration option to enhance SDK HTTP request Headers for Authorization Frameworks.

src/sdkClient/__tests__/sdkClientMethodCS.spec.ts

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { sdkClientMethodCSFactory as sdkClientMethodCSWithTTFactory } from '../sdkClientMethodCSWithTT';
21
import { sdkClientMethodCSFactory } from '../sdkClientMethodCS';
32
import { assertClientApi } from './testUtils';
43
import { telemetryTrackerFactory } from '../../trackers/telemetryTracker';
5-
import { settingsWithKey, settingsWithKeyAndTT, settingsWithKeyObject } from '../../utils/settingsValidation/__tests__/settings.mocks';
4+
import { settingsWithKey, settingsWithKeyObject } from '../../utils/settingsValidation/__tests__/settings.mocks';
65

76
const partialStorages: { destroy: jest.Mock }[] = [];
87

@@ -75,13 +74,7 @@ describe('sdkClientMethodCSFactory', () => {
7574
params.clients = {};
7675
});
7776

78-
// list of factory functions and their types (whether it ignores TT or not)
79-
const testTargets = [
80-
[sdkClientMethodCSWithTTFactory, false],
81-
[sdkClientMethodCSFactory, true]
82-
];
83-
84-
test.each(testTargets)('main client', (sdkClientMethodCSFactory) => {
77+
test('main client', () => {
8578
// @ts-expect-error
8679
const sdkClientMethod = sdkClientMethodCSFactory(params);
8780

@@ -106,21 +99,20 @@ describe('sdkClientMethodCSFactory', () => {
10699

107100
});
108101

109-
test.each(testTargets)('multiple clients', async (sdkClientMethodCSFactory, ignoresTT) => {
102+
test('multiple clients', async () => {
110103

111104
// @ts-expect-error
112105
const sdkClientMethod = sdkClientMethodCSFactory(params);
113106

114-
// calling the function with a diferent key than settings, should return a new client instance
107+
// calling the function with a different key than settings, should return a new client instance
115108
const newClients = new Set([
116-
sdkClientMethod('other-key'), // new client
117-
sdkClientMethod('other-key', 'other-tt'), // new client
118-
sdkClientMethod({ matchingKey: 'other-key', bucketingKey: 'buck' }) // new client
109+
sdkClientMethod('other-key'), // @ts-expect-error
110+
sdkClientMethod('other-key', 'ignored-tt'),
111+
sdkClientMethod({ matchingKey: 'other-key', bucketingKey: 'buck' })
119112
]);
120-
if (ignoresTT) expect(newClients.size).toBe(2);
121-
else expect(newClients.size).toBe(3);
113+
expect(newClients.size).toBe(2);
122114

123-
// each new client must follog the Client API
115+
// each new client must follow the Client API
124116
newClients.forEach(newClient => {
125117
assertClientApi(newClient);
126118
expect(newClient).not.toBe(sdkClientMethod());
@@ -150,7 +142,7 @@ describe('sdkClientMethodCSFactory', () => {
150142

151143
});
152144

153-
test.each(testTargets)('return main client instance if called with same key', (sdkClientMethodCSFactory) => {
145+
test('returns main client instance if called with same key', () => {
154146

155147
params.settings = settingsWithKey;
156148
// @ts-expect-error
@@ -163,20 +155,7 @@ describe('sdkClientMethodCSFactory', () => {
163155
expect(params.syncManager.shared).not.toBeCalled();
164156
});
165157

166-
test.each(testTargets)('return main client instance if called with same key and TT', (sdkClientMethodCSFactory) => {
167-
168-
params.settings = settingsWithKeyAndTT;
169-
// @ts-expect-error
170-
const sdkClientMethod = sdkClientMethodCSFactory(params);
171-
172-
expect(sdkClientMethod()).toBe(sdkClientMethod(settingsWithKeyAndTT.core.key, settingsWithKeyAndTT.core.trafficType));
173-
174-
expect(params.storage.shared).not.toBeCalled();
175-
expect(params.sdkReadinessManager.shared).not.toBeCalled();
176-
expect(params.syncManager.shared).not.toBeCalled();
177-
});
178-
179-
test.each(testTargets)('return main client instance if called with same key object', (sdkClientMethodCSFactory) => {
158+
test('returns main client instance if called with same key object', () => {
180159
// @ts-expect-error
181160
params.settings = settingsWithKeyObject;
182161
// @ts-expect-error
@@ -189,39 +168,37 @@ describe('sdkClientMethodCSFactory', () => {
189168
expect(params.syncManager.shared).not.toBeCalled();
190169
});
191170

192-
test.each(testTargets)('return same client instance if called with same key or traffic type (input validation)', (sdkClientMethodCSFactory, ignoresTT) => {
171+
test('returns same client instance if called with same key (input validation)', () => {
193172
// @ts-expect-error
194173
const sdkClientMethod = sdkClientMethodCSFactory(params);
195174

196-
const clientInstance = sdkClientMethod('key', 'tt');
175+
const clientInstance = sdkClientMethod('key');
197176

198-
expect(sdkClientMethod('key', 'tT')).toBe(clientInstance); // No new client created: TT is lowercased / ignored
199-
expect(sdkClientMethod(' key ', 'tt')).toBe(clientInstance); // No new client created: key is trimmed
200-
expect(sdkClientMethod({ matchingKey: 'key ', bucketingKey: ' key' }, 'TT')).toBe(clientInstance); // No new client created: key object is equivalent to 'key' string
177+
expect(sdkClientMethod('key')).toBe(clientInstance); // No new client created: same key
178+
expect(sdkClientMethod(' key ')).toBe(clientInstance); // No new client created: key is trimmed
179+
expect(sdkClientMethod({ matchingKey: 'key ', bucketingKey: ' key' })).toBe(clientInstance); // No new client created: key object is equivalent to 'key' string
201180

202181
expect(params.storage.shared).toBeCalledTimes(1);
203182
expect(params.sdkReadinessManager.shared).toBeCalledTimes(1);
204183
expect(params.syncManager.shared).toBeCalledTimes(1);
205184

206-
expect(sdkClientMethod('KEY', 'tt')).not.toBe(clientInstance); // New client created: key is case-sensitive
207-
if (!ignoresTT) expect(sdkClientMethod('key', 'TT ')).not.toBe(clientInstance); // New client created: TT is not trimmed
185+
expect(sdkClientMethod('KEY')).not.toBe(clientInstance); // New client created: key is case-sensitive
208186

209-
const clientCount = ignoresTT ? 2 : 3;
187+
const clientCount = 2;
210188
expect(params.storage.shared).toBeCalledTimes(clientCount);
211189
expect(params.sdkReadinessManager.shared).toBeCalledTimes(clientCount);
212190
expect(params.syncManager.shared).toBeCalledTimes(clientCount);
213191
});
214192

215-
test.each(testTargets)('invalid calls throw an error', (sdkClientMethodCSFactory, ignoresTT) => {
193+
test('invalid calls throw an error', () => {
216194
// @ts-expect-error
217-
const sdkClientMethod = sdkClientMethodCSFactory(params);
195+
const sdkClientMethod = sdkClientMethodCSFactory(params); // @ts-expect-error
218196
expect(() => sdkClientMethod({ matchingKey: settingsWithKey.core.key, bucketingKey: undefined })).toThrow('Shared Client needs a valid key.');
219-
if (!ignoresTT) expect(() => sdkClientMethod('valid-key', ['invalid-TT'])).toThrow('Shared Client needs a valid traffic type or no traffic type at all.');
220197
});
221198

222-
test.each(testTargets)('attributes binding - main client', (sdkClientMethodCSFactory) => {
199+
test('attributes binding - main client', () => {
223200
// @ts-expect-error
224-
const sdkClientMethod = sdkClientMethodCSFactory(params);
201+
const sdkClientMethod = sdkClientMethodCSFactory(params) as any;
225202

226203
// should return a function
227204
expect(typeof sdkClientMethod).toBe('function');
@@ -273,7 +250,7 @@ describe('sdkClientMethodCSFactory', () => {
273250
});
274251

275252

276-
test.each(testTargets)('attributes binding - shared clients', (sdkClientMethodCSFactory) => {
253+
test('attributes binding - shared clients', () => {
277254
// @ts-expect-error
278255
const sdkClientMethod = sdkClientMethodCSFactory(params);
279256

src/sdkClient/clientCS.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ import { clientAttributesDecoration } from './clientAttributesDecoration';
55

66

77
/**
8-
* Decorator that binds a key and (optionally) a traffic type to client methods
8+
* Decorator that binds a key to client methods
99
*
1010
* @param client sync client instance
1111
* @param key validated split key
12-
* @param trafficType validated traffic type
1312
*/
14-
export function clientCSDecorator(log: ILogger, client: SplitIO.IClient, key: SplitIO.SplitKey, trafficType?: string): SplitIO.ICsClient {
13+
export function clientCSDecorator(log: ILogger, client: SplitIO.IClient, key: SplitIO.SplitKey): SplitIO.ICsClient {
1514

1615
let clientCS = clientAttributesDecoration(log, client);
1716

1817
return objectAssign(clientCS, {
19-
// In the client-side API, we bind a key to the client `getTreatment*` methods
18+
// In the client-side API, we bind a key to the client `getTreatment*` and `track` methods
2019
getTreatment: clientCS.getTreatment.bind(clientCS, key),
2120
getTreatmentWithConfig: clientCS.getTreatmentWithConfig.bind(clientCS, key),
2221
getTreatments: clientCS.getTreatments.bind(clientCS, key),
@@ -26,12 +25,10 @@ export function clientCSDecorator(log: ILogger, client: SplitIO.IClient, key: Sp
2625
getTreatmentsByFlagSet: clientCS.getTreatmentsByFlagSet.bind(clientCS, key),
2726
getTreatmentsWithConfigByFlagSet: clientCS.getTreatmentsWithConfigByFlagSet.bind(clientCS, key),
2827

29-
// Key is bound to the `track` method. Same thing happens with trafficType but only if provided
30-
track: trafficType ? clientCS.track.bind(clientCS, key, trafficType) : clientCS.track.bind(clientCS, key),
28+
track: clientCS.track.bind(clientCS, key),
3129

3230
// Not part of the public API. These properties are used to support other modules (e.g., Split Suite)
3331
isClientSide: true,
34-
key,
35-
trafficType
32+
key
3633
}) as SplitIO.ICsClient;
3734
}

src/sdkClient/sdkClientMethodCS.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function sdkClientMethodCSFactory(params: ISdkFactoryContext): (key?: Spl
3535
return mainClientInstance;
3636
}
3737

38-
// Validate the key value. The trafficType (2nd argument) is ignored
38+
// Validate the key value
3939
const validKey = validateKey(log, key, LOG_PREFIX_CLIENT_INSTANTIATION);
4040
if (validKey === false) {
4141
throw new Error('Shared Client needs a valid key.');

src/sdkClient/sdkClientMethodCSWithTT.ts

Lines changed: 0 additions & 98 deletions
This file was deleted.

src/sdkFactory/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export interface ISdkFactoryParams {
9393

9494
// Sdk client method factory (ISDK::client method).
9595
// It Allows to distinguish SDK clients with the client-side API (`ICsSDK`) or server-side API (`ISDK` or `IAsyncSDK`).
96-
sdkClientMethodFactory: (params: ISdkFactoryContext) => ({ (): SplitIO.ICsClient; (key: SplitIO.SplitKey, trafficType?: string | undefined): SplitIO.ICsClient; } | (() => SplitIO.IClient) | (() => SplitIO.IAsyncClient))
96+
sdkClientMethodFactory: (params: ISdkFactoryContext) => ({ (): SplitIO.ICsClient; (key: SplitIO.SplitKey): SplitIO.ICsClient; } | (() => SplitIO.IClient) | (() => SplitIO.IAsyncClient))
9797

9898
// Impression observer factory.
9999
impressionsObserverFactory: () => IImpressionObserver

src/types.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export interface ISettings {
7171
readonly core: {
7272
authorizationKey: string,
7373
key: SplitIO.SplitKey,
74-
trafficType?: string,
7574
labelsEnabled: boolean,
7675
IPAddressesEnabled: boolean
7776
},
@@ -923,12 +922,6 @@ export namespace SplitIO {
923922
* @property {SplitKey} key
924923
*/
925924
key: SplitKey,
926-
/**
927-
* Traffic type associated with the customer identifier. @see {@link https://help.split.io/hc/en-us/articles/360019916311-Traffic-type}
928-
* If no provided as a setting it will be required on the client.track() calls.
929-
* @property {string} trafficType
930-
*/
931-
trafficType?: string,
932925
/**
933926
* Disable labels from being sent to Split backend. Labels may contain sensitive information.
934927
* @property {boolean} labelsEnabled
@@ -1037,10 +1030,9 @@ export namespace SplitIO {
10371030
* Returns a shared client of the SDK, with the given key and optional traffic type.
10381031
* @function client
10391032
* @param {SplitKey} key The key for the new client instance.
1040-
* @param {string=} trafficType The traffic type of the provided key.
10411033
* @returns {ICsClient} The client instance.
10421034
*/
1043-
client(key: SplitKey, trafficType?: string): ICsClient,
1035+
client(key: SplitKey): ICsClient,
10441036
/**
10451037
* Returns a manager instance of the SDK to explore available information.
10461038
* @function manager

src/utils/settingsValidation/__tests__/index.spec.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -233,40 +233,32 @@ describe('settingsValidation', () => {
233233
expect(settings.core.key).toBe(undefined);
234234
});
235235

236-
test('validates and sanitizes key and traffic type in client-side', () => {
237-
const clientSideValidationParams = { ...minimalSettingsParams, acceptKey: true, acceptTT: true };
236+
test('validates and sanitizes key in client-side', () => {
237+
const clientSideValidationParams = { ...minimalSettingsParams, acceptKey: true };
238238

239239
const samples = [{
240240
key: ' valid-key ', settingsKey: 'valid-key', // key string is trimmed
241-
trafficType: 'VALID-TT', settingsTrafficType: 'valid-tt', // TT is converted to lowercase
242241
}, {
243242
key: undefined, settingsKey: false, // undefined key is not valid in client-side
244-
trafficType: undefined, settingsTrafficType: undefined,
245243
}, {
246-
key: null, settingsKey: false,
247-
trafficType: null, settingsTrafficType: false,
244+
key: {}, settingsKey: false,
248245
}, {
249246
key: true, settingsKey: false,
250-
trafficType: true, settingsTrafficType: false,
251247
}, {
252248
key: 1.5, settingsKey: '1.5', // finite number as key is parsed
253-
trafficType: 100, settingsTrafficType: false,
254249
}, {
255250
key: { matchingKey: 100, bucketingKey: ' BUCK ' }, settingsKey: { matchingKey: '100', bucketingKey: 'BUCK' },
256-
trafficType: {}, settingsTrafficType: false,
257251
}];
258252

259-
samples.forEach(({ key, trafficType, settingsKey, settingsTrafficType }) => {
253+
samples.forEach(({ key, settingsKey }) => {
260254
const settings = settingsValidation({
261255
core: {
262256
authorizationKey: 'dummy token',
263-
key,
264-
trafficType
257+
key
265258
}
266259
}, clientSideValidationParams);
267260

268261
expect(settings.core.key).toEqual(settingsKey);
269-
expect(settings.core.trafficType).toEqual(settingsTrafficType);
270262
});
271263
});
272264

@@ -275,12 +267,11 @@ describe('settingsValidation', () => {
275267
core: {
276268
authorizationKey: 'dummy token',
277269
key: true,
278-
trafficType: true
270+
trafficType: 'ignored'
279271
}
280272
}, { ...minimalSettingsParams, acceptKey: true });
281273

282274
expect(settings.core.key).toEqual(false); // key is validated
283-
expect(settings.core.trafficType).toEqual(true); // traffic type is ignored
284275
});
285276

286277
// Not implemented yet

0 commit comments

Comments
 (0)