Skip to content

Commit fe27372

Browse files
Merge pull request #311 from splitio/flag_spec_version_validation
Added optional validation parameter for flag spec version
2 parents 62fb0a4 + e9a769d commit fe27372

File tree

13 files changed

+42
-31
lines changed

13 files changed

+42
-31
lines changed

CHANGES.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
1.15.0 (May 13, 2024)
2+
- Added an optional settings validation parameter to let overwrite the default flag spec version, used by the JS Synchronizer.
3+
14
1.14.0 (May 6, 2024)
25
- Added support for targeting rules based on semantic versions (https://semver.org/).
36
- Added special impression label "targeting rule type unsupported by sdk" when the matcher type is not supported by the SDK, which returns 'control' treatment.
@@ -86,7 +89,7 @@
8689
- Bugfixing - Removed js-yaml dependency to avoid resolution to an incompatible version on certain npm versions when installing third-party dependencies that also define js-yaml as transitive dependency (Related to issue https://github.com/splitio/javascript-client/issues/662).
8790

8891
1.5.0 (June 29, 2022)
89-
- Added a new config option to control the tasks that listen or poll for updates on feature flags and segments, via the new config sync.enabled . Running online, Split SDK will always pull the most recent updates upon initialization, this only affects updates fetching on a running instance. Useful when a consistent session experience is a must or to save resources when updates are not being used.
92+
- Added a new config option to control the tasks that listen or poll for updates on feature flags and segments, via the new config `sync.enabled`. Running online, Split SDK will always pull the most recent updates upon initialization, this only affects updates fetching on a running instance. Useful when a consistent session experience is a must or to save resources when updates are not being used.
9093
- Updated telemetry logic to track the anonymous config for user consent flag set to declined or unknown.
9194
- Updated submitters logic, to avoid duplicating the post of impressions to Split cloud when the SDK is destroyed while its periodic post of impressions is running.
9295

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@splitsoftware/splitio-commons",
3-
"version": "1.14.0",
3+
"version": "1.15.0",
44
"description": "Split JavaScript SDK common components",
55
"main": "cjs/index.js",
66
"module": "esm/index.js",

src/services/__tests__/splitApi.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ISettings } from '../../types';
44
import { settingsSplitApi } from '../../utils/settingsValidation/__tests__/settings.mocks';
55

66
const settingsWithRuntime = { ...settingsSplitApi, runtime: { ip: 'ip', hostname: 'hostname' } } as ISettings;
7-
const settingsWithSets = { ...settingsSplitApi, validateFilters: true, sync: { __splitFiltersValidation: { queryString: '&testFlagQueryString'}}} as ISettings;
7+
const settingsWithSets = { ...settingsSplitApi, validateFilters: true, sync: { __splitFiltersValidation: { queryString: '&testFlagQueryString' }, flagSpecVersion: '1.1' } } as ISettings;
88

99
const telemetryTrackerMock = { trackHttp: jest.fn(() => () => { }) };
1010

src/services/splitApi.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { splitHttpClientFactory } from './splitHttpClient';
44
import { ISplitApi } from './types';
55
import { objectAssign } from '../utils/lang/objectAssign';
66
import { ITelemetryTracker } from '../trackers/types';
7-
import { SPLITS, IMPRESSIONS, IMPRESSIONS_COUNT, EVENTS, TELEMETRY, TOKEN, SEGMENT, MY_SEGMENT, FLAGS_SPEC } from '../utils/constants';
7+
import { SPLITS, IMPRESSIONS, IMPRESSIONS_COUNT, EVENTS, TELEMETRY, TOKEN, SEGMENT, MY_SEGMENT } from '../utils/constants';
88
import { ERROR_TOO_MANY_SETS } from '../logger/constants';
99

1010
const noCacheHeaderOptions = { headers: { 'Cache-Control': 'no-cache' } };
@@ -29,6 +29,7 @@ export function splitApiFactory(
2929
const urls = settings.urls;
3030
const filterQueryString = settings.sync.__splitFiltersValidation && settings.sync.__splitFiltersValidation.queryString;
3131
const SplitSDKImpressionsMode = settings.sync.impressionsMode;
32+
const flagSpecVersion = settings.sync.flagSpecVersion;
3233
const splitHttpClient = splitHttpClientFactory(settings, platform.getFetch);
3334

3435
return {
@@ -44,7 +45,7 @@ export function splitApiFactory(
4445
},
4546

4647
fetchAuth(userMatchingKeys?: string[]) {
47-
let url = `${urls.auth}/v2/auth?s=${FLAGS_SPEC}`;
48+
let url = `${urls.auth}/v2/auth?s=${flagSpecVersion}`;
4849
if (userMatchingKeys) { // `userMatchingKeys` is undefined in server-side
4950
const queryParams = userMatchingKeys.map(userKeyToQueryParam).join('&');
5051
if (queryParams) url += '&' + queryParams;
@@ -53,7 +54,7 @@ export function splitApiFactory(
5354
},
5455

5556
fetchSplitChanges(since: number, noCache?: boolean, till?: number) {
56-
const url = `${urls.sdk}/splitChanges?s=${FLAGS_SPEC}&since=${since}${filterQueryString || ''}${till ? '&till=' + till : ''}`;
57+
const url = `${urls.sdk}/splitChanges?s=${flagSpecVersion}&since=${since}${filterQueryString || ''}${till ? '&till=' + till : ''}`;
5758
return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(SPLITS))
5859
.catch((err) => {
5960
if (err.statusCode === 414) settings.log.error(ERROR_TOO_MANY_SETS);

src/storages/KeyBuilder.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ISettings } from '../types';
2-
import { FLAGS_SPEC } from '../utils/constants';
32
import { startsWith } from '../utils/lang';
43
import { hash } from '../utils/murmur3/murmur3';
54

@@ -86,5 +85,5 @@ export class KeyBuilder {
8685
* The hash is in hexadecimal format (8 characters max, 32 bits).
8786
*/
8887
export function getStorageHash(settings: ISettings) {
89-
return hash(`${settings.core.authorizationKey}::${settings.sync.__splitFiltersValidation.queryString}::${FLAGS_SPEC}`).toString(16);
88+
return hash(`${settings.core.authorizationKey}::${settings.sync.__splitFiltersValidation.queryString}::${settings.sync.flagSpecVersion}`).toString(16);
9089
}

src/storages/__tests__/KeyBuilder.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,16 @@ test('KEYS / latency and exception keys (telemetry)', () => {
116116
test('getStorageHash', () => {
117117
expect(getStorageHash({
118118
core: { authorizationKey: '<fake-token-rfc>' },
119-
sync: { __splitFiltersValidation: { queryString: '&names=p1__split,p2__split' } }
119+
sync: { __splitFiltersValidation: { queryString: '&names=p1__split,p2__split' }, flagSpecVersion: '1.1' }
120120
} as ISettings)).toBe('fdf7bd89');
121121

122122
expect(getStorageHash({
123123
core: { authorizationKey: '<fake-token-rfc>' },
124-
sync: { __splitFiltersValidation: { queryString: '&names=p2__split,p3__split' } }
124+
sync: { __splitFiltersValidation: { queryString: '&names=p2__split,p3__split' }, flagSpecVersion: '1.1' }
125125
} as ISettings)).toBe('ee4ec91');
126126

127127
expect(getStorageHash({
128128
core: { authorizationKey: '<fake-token-rfc>' },
129-
sync: { __splitFiltersValidation: { queryString: null } }
129+
sync: { __splitFiltersValidation: { queryString: null }, flagSpecVersion: '1.1' }
130130
} as ISettings)).toBe('2a2c20bb');
131131
});

src/sync/streaming/SSEClient/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { isString } from '../../../utils/lang';
44
import { IAuthTokenPushEnabled } from '../AuthClient/types';
55
import { ISSEClient, ISseEventHandler } from './types';
66

7-
const VERSION = '1.1';
7+
const ABLY_API_VERSION = '1.1';
88

99
const CONTROL_CHANNEL_REGEX = /^control_/;
1010

@@ -78,7 +78,7 @@ export class SSEClient implements ISSEClient {
7878
return encodeURIComponent(params + channel);
7979
}
8080
).join(',');
81-
const url = `${this.streamingUrl}?channels=${channelsQueryParam}&accessToken=${authToken.token}&v=${VERSION}&heartbeats=true`; // same results using `&heartbeats=false`
81+
const url = `${this.streamingUrl}?channels=${channelsQueryParam}&accessToken=${authToken.token}&v=${ABLY_API_VERSION}&heartbeats=true`; // same results using `&heartbeats=false`
8282

8383
this.connection = new this.eventSource!(
8484
// For client-side SDKs, SplitSDKClientKey and SplitSDKClientKey metadata is passed as query params,

src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ export interface ISettings {
118118
impressionsMode: SplitIO.ImpressionsMode,
119119
__splitFiltersValidation: ISplitFiltersValidation,
120120
localhostMode?: SplitIO.LocalhostFactory,
121-
enabled: boolean
121+
enabled: boolean,
122+
flagSpecVersion: string
122123
},
123124
readonly runtime: {
124125
ip: string | false

src/utils/constants/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,4 @@ export const DISABLED = 0;
105105
export const ENABLED = 1;
106106
export const PAUSED = 2;
107107

108-
export const FLAGS_SPEC = '1.1';
108+
export const FLAG_SPEC_VERSION = '1.1';

0 commit comments

Comments
 (0)