Skip to content

Commit

Permalink
Added new config option
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilianoSanchez committed May 13, 2024
1 parent 584dc6d commit 74cca85
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
0.6.0 (May 15, 2024)
- Added a new configuration option `sync.flagSpecVersion` to specify the flags spec version to be fetched and stored.
- Updated @splitsoftware/splitio-commons package to version 1.15.0 that includes minor updates:
- Added support for targeting rules based on semantic versions (https://semver.org/).
- Updated Split API client to include the flags spec version query parameter for the `splitChanges` and `auth` endpoints.

0.5.1 (February 29, 2024)
- Updated @splitsoftware/splitio-commons package to version 1.13.1 and some transitive dependencies for vulnerability fixes.

Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@splitsoftware/splitio-sync-tools",
"version": "0.5.1",
"version": "0.5.2-rc.0",
"description": "Split JavaScript Sync Tools",
"main": "lib/cjs/index.js",
"module": "lib/esm/index.js",
Expand Down Expand Up @@ -51,7 +51,7 @@
"prepublishOnly": "npm run check && npm run test && npm run build"
},
"dependencies": {
"@splitsoftware/splitio-commons": "1.13.2-rc.7",
"@splitsoftware/splitio-commons": "1.14.1-rc.0",
"dotenv": "^9.0.1",
"node-fetch": "^2.6.7",
"yargs": "^17.0.1"
Expand Down
13 changes: 10 additions & 3 deletions src/settings/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { synchronizerSettingsValidator } from '../index';
import { defaults } from '../defaults';
import { ISynchronizerSettings } from '../../../types';

describe('synchronizerSettingsValidator', () => {

test('should return default values when no param or invalid param is provided', () => {
const config = {
const config: ISynchronizerSettings = {
core: {
authorizationKey: 'fake-key',
},
Expand All @@ -13,12 +14,18 @@ describe('synchronizerSettingsValidator', () => {
impressionsPerPost: -1, // invalid, must be a positive integer
maxRetries: 10, // overwriting default value
},
}; // @ts-ignore
sync: {
// @ts-expect-error
flagSpecVersion: 'invalid',
},
storage: { wrapper: {} },
};
const settings = synchronizerSettingsValidator(config);

expect(settings.scheduler.eventsPerPost).toBe(defaults.scheduler.eventsPerPost);
expect(settings.scheduler.impressionsPerPost).toBe(defaults.scheduler.impressionsPerPost);
expect(settings.scheduler.maxRetries).toBe(config.scheduler.maxRetries);
expect(settings.scheduler.maxRetries).toBe(config.scheduler!.maxRetries);
expect(settings.sync.flagSpecVersion).toBe('1.1');
});

});
9 changes: 9 additions & 0 deletions src/settings/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { ILogger } from '@splitsoftware/splitio-commons/src/logger/types';
import { ISettings } from '@splitsoftware/splitio-commons/src/types';
import { FLAG_SPEC_VERSION } from '@splitsoftware/splitio-commons/src/utils/constants';
import { isIntegerNumber } from '@splitsoftware/splitio-commons/src/utils/lang';
import { settingsValidation } from '@splitsoftware/splitio-commons/src/utils/settingsValidation/index';
import { validateLogger } from '@splitsoftware/splitio-commons/src/utils/settingsValidation/logger/builtinLogger';
import { ISynchronizerSettings } from '../../types';
import { defaults } from './defaults';

const FLAG_SPEC_VERSIONS = ['1.0', FLAG_SPEC_VERSION];

/**
* Object with some default values to instantiate the application and fullfil internal
* requirements.
Expand All @@ -15,6 +18,12 @@ const params = {
defaults,
consent: () => undefined,
runtime: () => { return { ip: false, hostname: false }; },
flagSpec: ({ sync: { flagSpecVersion }, log }: ISettings) => {
if (FLAG_SPEC_VERSIONS.indexOf(flagSpecVersion) > -1) return flagSpecVersion;

log.error(`settings: you passed an invalid "flagSpecVersion" config param. It should be one of the following values: ${FLAG_SPEC_VERSIONS.map((version => `"${version}"`))}. Defaulting to "${FLAG_SPEC_VERSION}"`);
return FLAG_SPEC_VERSION;
},
};

function validatePositiveInteger(log: ILogger, paramName: string, actualValue: any, defaultValue: number) {
Expand Down
7 changes: 7 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ declare module JsSyncTools {
* @property {SplitFilter[]} splitFilters
*/
splitFilters?: SplitFilter[]
/**
* Feature Flag Spec version. Option to determine which version of the feature flag definitions are fetched and stored.
* Possible values are '1.0' and '1.1'.
*
* @default '1.1'
*/
flagSpecVersion?: '1.0' | '1.1'
/**
* Impressions Collection Mode. Option to determine how impressions are going to be sent to Split Servers.
*
Expand Down

0 comments on commit 74cca85

Please sign in to comment.