diff --git a/CHANGES.txt b/CHANGES.txt index 7be5a08..eacfcc5 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,13 @@ 2.0.0 (Dec XX, 2023) + - Updated @splitsoftware/splitio-browserjs package to version 0.13.0 - Updated the minimum Angular version to match Angular's support up to date. Breaking change version is regarding the Angular minimum version update, there are no breaking changes to Split's plugin API or functionality itself. + - Added support for Flag Sets on the SDK, which enables grouping feature flags and interacting with the group rather than individually (more details in our documentation): + - Added new variations of the get treatment methods to support evaluating flags in given flag set/s. + - getTreatmentsByFlagSet and getTreatmentsByFlagSets + - getTreatmentsWithConfigByFlagSets and getTreatmentsWithConfigByFlagSets + - Added a new optional Split Filter configuration option. This allows the SDK and Split services to only synchronize the flags in the specified flag sets, avoiding unused or unwanted flags from being synced on the SDK instance, bringing all the benefits from a reduced payload. + - Added `sets` property to the `SplitView` object returned by the `split` and `splits` methods of the SDK manager to expose flag sets on flag views. + - Added `defaultTreatment` property to the `SplitView` object returned by the `split` and `splits` methods of the SDK manager (Related to issue https://github.com/splitio/javascript-commons/issues/225). 1.0.2 (May 16, 2023) - Updated terminology on the SDKs codebase to be more aligned with current standard without causing a breaking change. The core change is the term split for feature flag on things like logs and JSDocs tags. diff --git a/package-lock.json b/package-lock.json index 23d8520..68ffa17 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@splitsoftware/splitio-angular", - "version": "2.0.0", + "version": "1.0.3-rc.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@splitsoftware/splitio-angular", - "version": "2.0.0", + "version": "1.0.3-rc.0", "license": "Apache-2.0", "devDependencies": { "@angular-devkit/build-angular": "^15.2.10", @@ -23,7 +23,7 @@ "@angular/platform-browser": "^15.2.10", "@angular/platform-browser-dynamic": "^15.2.10", "@angular/router": "^15.2.10", - "@splitsoftware/splitio-browserjs": "0.9.5", + "@splitsoftware/splitio-browserjs": "0.13.0", "@types/jest": "^29.0.0", "@typescript-eslint/eslint-plugin": "^5.43.0", "@typescript-eslint/parser": "^5.43.0", @@ -4423,20 +4423,20 @@ } }, "node_modules/@splitsoftware/splitio-browserjs": { - "version": "0.9.5", - "resolved": "https://registry.npmjs.org/@splitsoftware/splitio-browserjs/-/splitio-browserjs-0.9.5.tgz", - "integrity": "sha512-sWwH4juAJY8N3C4Obl6h9xaKPwm2SCETFbHn8hL8OF+tMClb0BI6sP7AQ+AY8AySXwiVbCc1ux3lebJdo/LPkQ==", + "version": "0.13.0", + "resolved": "https://registry.npmjs.org/@splitsoftware/splitio-browserjs/-/splitio-browserjs-0.13.0.tgz", + "integrity": "sha512-r+XxbfIVsgt8f9z62JJ4k0p2VUMaR9J2SNpg7ytLbUnn8coVGQR+feNASrrQXD67lRTb09mhNG1FSPx8YpJ5/w==", "dev": true, "dependencies": { - "@splitsoftware/splitio-commons": "1.8.2", + "@splitsoftware/splitio-commons": "1.12.1", "@types/google.analytics": "0.0.40", "unfetch": "^4.2.0" } }, "node_modules/@splitsoftware/splitio-commons": { - "version": "1.8.2", - "resolved": "https://registry.npmjs.org/@splitsoftware/splitio-commons/-/splitio-commons-1.8.2.tgz", - "integrity": "sha512-koR3pKQCbbh9r7guUywqJ1zXQr7ElZYVs0Ikdh+cQg21rcIx8l2sKMXxUjoizY1i2Y8D6CDW+csE9G4y9rpapQ==", + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/@splitsoftware/splitio-commons/-/splitio-commons-1.12.1.tgz", + "integrity": "sha512-EkCcqlYvVafazs9c5i+pmhf6rIyj3A70dqQ4U3BKE646t7tf6mxGzqZz1sAl540xNyYI7CA/iIqisEWvDtJc0A==", "dev": true, "dependencies": { "tslib": "^2.3.1" @@ -21281,20 +21281,20 @@ } }, "@splitsoftware/splitio-browserjs": { - "version": "0.9.5", - "resolved": "https://registry.npmjs.org/@splitsoftware/splitio-browserjs/-/splitio-browserjs-0.9.5.tgz", - "integrity": "sha512-sWwH4juAJY8N3C4Obl6h9xaKPwm2SCETFbHn8hL8OF+tMClb0BI6sP7AQ+AY8AySXwiVbCc1ux3lebJdo/LPkQ==", + "version": "0.13.0", + "resolved": "https://registry.npmjs.org/@splitsoftware/splitio-browserjs/-/splitio-browserjs-0.13.0.tgz", + "integrity": "sha512-r+XxbfIVsgt8f9z62JJ4k0p2VUMaR9J2SNpg7ytLbUnn8coVGQR+feNASrrQXD67lRTb09mhNG1FSPx8YpJ5/w==", "dev": true, "requires": { - "@splitsoftware/splitio-commons": "1.8.2", + "@splitsoftware/splitio-commons": "1.12.1", "@types/google.analytics": "0.0.40", "unfetch": "^4.2.0" } }, "@splitsoftware/splitio-commons": { - "version": "1.8.2", - "resolved": "https://registry.npmjs.org/@splitsoftware/splitio-commons/-/splitio-commons-1.8.2.tgz", - "integrity": "sha512-koR3pKQCbbh9r7guUywqJ1zXQr7ElZYVs0Ikdh+cQg21rcIx8l2sKMXxUjoizY1i2Y8D6CDW+csE9G4y9rpapQ==", + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/@splitsoftware/splitio-commons/-/splitio-commons-1.12.1.tgz", + "integrity": "sha512-EkCcqlYvVafazs9c5i+pmhf6rIyj3A70dqQ4U3BKE646t7tf6mxGzqZz1sAl540xNyYI7CA/iIqisEWvDtJc0A==", "dev": true, "requires": { "tslib": "^2.3.1" diff --git a/package.json b/package.json index d5f8151..29a0836 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@splitsoftware/splitio-angular", - "version": "2.0.0", + "version": "1.0.3-rc.0", "description": "Split Angular utilities to simplify Split SDK browser client usage", "scripts": { "ng": "ng", @@ -53,7 +53,7 @@ "@angular-eslint/eslint-plugin-template": "15.2.1", "@angular-eslint/schematics": "15.2.1", "@angular-eslint/template-parser": "15.2.1", - "@splitsoftware/splitio-browserjs": "0.9.5", + "@splitsoftware/splitio-browserjs": "0.13.0", "@types/jest": "^29.0.0", "@typescript-eslint/eslint-plugin": "^5.43.0", "@typescript-eslint/parser": "^5.43.0", diff --git a/projects/splitio/package.json b/projects/splitio/package.json index 49a1227..b05c814 100644 --- a/projects/splitio/package.json +++ b/projects/splitio/package.json @@ -1,6 +1,6 @@ { "name": "@splitsoftware/splitio-angular", - "version": "2.0.0", + "version": "1.0.3-rc.0", "description": "Split Angular utilities to simplify Split SDK browser client usage", "repository": { "type": "git", @@ -21,7 +21,7 @@ "bugs": "https://github.com/splitio/angular-sdk-plugin/issues", "homepage": "https://github.com/splitio/angular-sdk-plugin#readme", "dependencies": { - "@splitsoftware/splitio-browserjs": "0.9.5" + "@splitsoftware/splitio-browserjs": "0.13.0" }, "peerDependencies": { "@angular/core": ">=15.2.1", diff --git a/projects/splitio/src/lib/__tests__/mocks/SplitView.mock.ts b/projects/splitio/src/lib/__tests__/mocks/SplitView.mock.ts index 4e53974..21fff6c 100644 --- a/projects/splitio/src/lib/__tests__/mocks/SplitView.mock.ts +++ b/projects/splitio/src/lib/__tests__/mocks/SplitView.mock.ts @@ -3,10 +3,11 @@ export const mockedFeatureFlagView = [ 'changeNumber': 0, 'configs': {}, 'killed': false, - 'name': - 'test_split', + 'name': 'test_split', 'trafficType': 'localhost', - 'treatments': ['on'] + 'treatments': ['on'], + 'defaultTreatment': 'control', + 'sets': [] }, { 'changeNumber': 0, @@ -14,9 +15,10 @@ export const mockedFeatureFlagView = [ 'off': '{"bannerText":"Click here."}' }, 'killed': false, - 'name': - 'test_split2', + 'name': 'test_split2', 'trafficType': 'localhost', - 'treatments': ['off'] + 'treatments': ['off'], + 'defaultTreatment': 'control', + 'sets': [] } ]; diff --git a/projects/splitio/src/lib/__tests__/splitio.service.spec.ts b/projects/splitio/src/lib/__tests__/splitio.service.spec.ts index a114c64..3f12900 100644 --- a/projects/splitio/src/lib/__tests__/splitio.service.spec.ts +++ b/projects/splitio/src/lib/__tests__/splitio.service.spec.ts @@ -248,6 +248,50 @@ describe('SplitService', () => { }); }); + test('Flag sets', (done) => { + expect(service.isSDKReady).toEqual(false); + + expect(service.getTreatmentsByFlagSet('set_a')).toEqual({}); + expect(logSpy.mock.calls[logCalls++][0]).toEqual('[ERROR] plugin should be initialized'); + expect(logSpy.mock.calls[logCalls++][0]).toEqual('[ERROR] client should be initialized first.'); + + expect(service.getTreatmentsWithConfigByFlagSet('set_a')).toEqual({}); + expect(logSpy.mock.calls[logCalls++][0]).toEqual('[ERROR] plugin should be initialized'); + expect(logSpy.mock.calls[logCalls++][0]).toEqual('[ERROR] client should be initialized first.'); + + expect(service.getTreatmentsByFlagSets(['set_a','set_b'])).toEqual({}); + expect(logSpy.mock.calls[logCalls++][0]).toEqual('[ERROR] plugin should be initialized'); + expect(logSpy.mock.calls[logCalls++][0]).toEqual('[ERROR] client should be initialized first.'); + + expect(service.getTreatmentsWithConfigByFlagSets(['set_a','set_b'])).toEqual({}); + expect(logSpy.mock.calls[logCalls++][0]).toEqual('[ERROR] plugin should be initialized'); + expect(logSpy.mock.calls[logCalls++][0]).toEqual('[ERROR] client should be initialized first.'); + + service.init(localhostConfig).subscribe(() => { + + const mainClient = service.getSDKClient(); + expect(service.isSDKReady).toEqual(true); + + const clientSpy = { + getTreatmentsByFlagSet: jest.spyOn(mainClient, 'getTreatmentsByFlagSet'), + getTreatmentsWithConfigByFlagSet: jest.spyOn(mainClient, 'getTreatmentsWithConfigByFlagSet'), + getTreatmentsByFlagSets: jest.spyOn(mainClient, 'getTreatmentsByFlagSets'), + getTreatmentsWithConfigByFlagSets: jest.spyOn(mainClient, 'getTreatmentsWithConfigByFlagSets'), + }; + + service.getTreatmentsByFlagSet('set_a'); + expect(clientSpy.getTreatmentsByFlagSet.mock.calls[0]).toEqual(['set_a', undefined]); + service.getTreatmentsWithConfigByFlagSet('set_a', {attr: true}); + expect(clientSpy.getTreatmentsWithConfigByFlagSet.mock.calls[0]).toEqual(['set_a', {attr: true}]); + service.getTreatmentsByFlagSets(['set_a','set_b'], {attr: true}); + expect(clientSpy.getTreatmentsByFlagSets.mock.calls[0]).toEqual([['set_a','set_b'], {attr: true}]); + service.getTreatmentsWithConfigByFlagSets(['set_a','set_b']); + expect(clientSpy.getTreatmentsWithConfigByFlagSets.mock.calls[0]).toEqual([['set_a','set_b'], undefined]); + + done(); + }); + }); + test('SDK Manager', (done) => { expect(service.getSplitNames()).toEqual([]); service.init(localhostConfig); diff --git a/projects/splitio/src/lib/splitio.service.ts b/projects/splitio/src/lib/splitio.service.ts index bd41fbe..4df437d 100644 --- a/projects/splitio/src/lib/splitio.service.ts +++ b/projects/splitio/src/lib/splitio.service.ts @@ -3,7 +3,7 @@ import { SplitFactory } from '@splitsoftware/splitio-browserjs'; import * as SplitIO from '@splitsoftware/splitio-browserjs/types/splitio'; import { from, Observable } from 'rxjs'; import { INIT_CLIENT_EXISTS, INIT_CLIENT_FIRST, CONTROL_CLIENT, DEFAULT_MANAGER, VERSION } from './utils/constants'; -import { buildInstance, parseTrackParams, parseTreatmentParams } from './utils/utils'; +import { buildInstance, parseFlagSetParams, parseTrackParams, parseTreatmentParams } from './utils/utils'; @Injectable({ providedIn: 'root' @@ -204,7 +204,7 @@ export class SplitService { /** * Validates key and returns client if it is initialized for key or controlClient if it isn't */ - private getClient(key?: SplitIO.SplitKey | undefined): any { + private getClient(key?: SplitIO.SplitKey): any { const client = this.getSDKClient(key); if (!client) { console.log('[ERROR] client' + ( key ? ' for key ' + buildInstance(key) : '') + ' should be initialized first.'); @@ -221,7 +221,7 @@ export class SplitService { * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key. * @returns {Treatment} - The treatment string. */ - getTreatment(key: SplitIO.SplitKey, featureFlagName: string, attributes?: SplitIO.Attributes | undefined): SplitIO.Treatment; + getTreatment(key: SplitIO.SplitKey, featureFlagName: string, attributes?: SplitIO.Attributes): SplitIO.Treatment; /** * Returns a Treatment value, which is the treatment string for the given feature. * @function getTreatment @@ -229,8 +229,8 @@ export class SplitService { * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key. * @returns {Treatment} - The treatment string. */ - getTreatment(featureFlagName: string, attributes?: SplitIO.Attributes | undefined): SplitIO.Treatment; - getTreatment(param1: string | SplitIO.SplitKey, param2?: string | SplitIO.Attributes | undefined, param3?: SplitIO.Attributes | undefined): SplitIO.Treatment { + getTreatment(featureFlagName: string, attributes?: SplitIO.Attributes): SplitIO.Treatment; + getTreatment(param1: string | SplitIO.SplitKey, param2?: string | SplitIO.Attributes, param3?: SplitIO.Attributes): SplitIO.Treatment { const {key, featureFlagNames, attributes} = parseTreatmentParams(param1, param2, param3); return this.getClient(key).getTreatment(featureFlagNames, attributes); } @@ -243,7 +243,7 @@ export class SplitService { * @param {Attributes} attributes - An object of type Attributes defining the attributes for the given key. * @returns {TreatmentWithConfig} - The map containing the treatment and the configuration stringified JSON (or null if there was no config for that treatment). */ - getTreatmentWithConfig(key: SplitIO.SplitKey, featureFlagName: string, attributes?: SplitIO.Attributes | undefined): SplitIO.TreatmentWithConfig; + getTreatmentWithConfig(key: SplitIO.SplitKey, featureFlagName: string, attributes?: SplitIO.Attributes): SplitIO.TreatmentWithConfig; /** * Returns a TreatmentWithConfig value, which is an object with both treatment and config string for the given feature. * @function getTreatmentWithConfig @@ -251,8 +251,8 @@ export class SplitService { * @param {Attributes} attributes - An object of type Attributes defining the attributes for the given key. * @returns {TreatmentWithConfig} - The map containing the treatment and the configuration stringified JSON (or null if there was no config for that treatment). */ - getTreatmentWithConfig(featureFlagName: string, attributes?: SplitIO.Attributes | undefined): SplitIO.TreatmentWithConfig; - getTreatmentWithConfig(param1: string | SplitIO.SplitKey, param2?: string | SplitIO.Attributes | undefined, param3?: SplitIO.Attributes | undefined): SplitIO.TreatmentWithConfig { + getTreatmentWithConfig(featureFlagName: string, attributes?: SplitIO.Attributes): SplitIO.TreatmentWithConfig; + getTreatmentWithConfig(param1: string | SplitIO.SplitKey, param2?: string | SplitIO.Attributes, param3?: SplitIO.Attributes): SplitIO.TreatmentWithConfig { const {key, featureFlagNames, attributes} = parseTreatmentParams(param1, param2, param3); return this.getClient(key).getTreatmentWithConfig(featureFlagNames, attributes); } @@ -265,7 +265,7 @@ export class SplitService { * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key. * @returns {Treatments} - The treatments object map. */ - getTreatments(key: SplitIO.SplitKey, featureFlagNames: string[], attributes?: SplitIO.Attributes | undefined): SplitIO.Treatments; + getTreatments(key: SplitIO.SplitKey, featureFlagNames: string[], attributes?: SplitIO.Attributes): SplitIO.Treatments; /** * Returns a Treatments value, which is an object map with the treatments for the given features. * @function getTreatments\ @@ -273,8 +273,8 @@ export class SplitService { * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key. * @returns {Treatments} - The treatments object map. */ - getTreatments(featureFlagNames: string[], attributes?: SplitIO.Attributes | undefined): SplitIO.Treatments; - getTreatments(param1: string[] | SplitIO.SplitKey, param2?: string[] | SplitIO.Attributes | undefined, param3?: SplitIO.Attributes | undefined): SplitIO.Treatments { + getTreatments(featureFlagNames: string[], attributes?: SplitIO.Attributes): SplitIO.Treatments; + getTreatments(param1: string[] | SplitIO.SplitKey, param2?: string[] | SplitIO.Attributes, param3?: SplitIO.Attributes): SplitIO.Treatments { const {key, featureFlagNames, attributes} = parseTreatmentParams(param1, param2, param3); return this.getClient(key).getTreatments(featureFlagNames, attributes); } @@ -287,7 +287,7 @@ export class SplitService { * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key. * @returns {TreatmentsWithConfig} The map with all the TreatmentWithConfig objects */ - getTreatmentsWithConfig(key: SplitIO.SplitKey, featureFlagNames: string[], attributes?: SplitIO.Attributes | undefined): SplitIO.TreatmentsWithConfig; + getTreatmentsWithConfig(key: SplitIO.SplitKey, featureFlagNames: string[], attributes?: SplitIO.Attributes): SplitIO.TreatmentsWithConfig; /** * Returns a TreatmentsWithConfig value, which is an object map with the TreatmentWithConfig (an object with both treatment and config string) for the given features. * @function getTreatmentsWithConfig @@ -295,12 +295,100 @@ export class SplitService { * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key. * @returns {TreatmentsWithConfig} The map with all the TreatmentWithConfig objects */ - getTreatmentsWithConfig(featureFlagNames: string[], attributes?: SplitIO.Attributes | undefined): SplitIO.TreatmentsWithConfig; - getTreatmentsWithConfig(param1: string[] | SplitIO.SplitKey, param2?: string[] | SplitIO.Attributes | undefined, param3?: SplitIO.Attributes | undefined): SplitIO.TreatmentsWithConfig { + getTreatmentsWithConfig(featureFlagNames: string[], attributes?: SplitIO.Attributes): SplitIO.TreatmentsWithConfig; + getTreatmentsWithConfig(param1: string[] | SplitIO.SplitKey, param2?: string[] | SplitIO.Attributes, param3?: SplitIO.Attributes): SplitIO.TreatmentsWithConfig { const {key, featureFlagNames, attributes} = parseTreatmentParams(param1, param2, param3); return this.getClient(key).getTreatmentsWithConfig(featureFlagNames, attributes); } + /** + * Returns a Treatments value, which is an object map with the treatments for the given flag set. + * @function getTreatmentsByFlagSet + * @param {SplitKey} key - The key for the client instance. + * @param {string} flagSetName - The string that represents the flag set we want to get the related feature flags and treatments. + * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key. + * @returns {Treatments} - The treatments object map. + */ + getTreatmentsByFlagSet(key: SplitIO.SplitKey, flagSetName: string, attributes?: SplitIO.Attributes): SplitIO.Treatments; + /** + * Returns a Treatments value, which is an object map with the treatments for the given flag set. + * @function getTreatmentsByFlagSet + * @param {string} flagSetName - The string that represents the flag set we want to get the related feature flags and treatments. + * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key. + * @returns {Treatments} - The treatments object map. + */ + getTreatmentsByFlagSet(flagSetName: string, attributes?: SplitIO.Attributes): SplitIO.Treatments; + getTreatmentsByFlagSet(param1: string | SplitIO.SplitKey, param2?: string | SplitIO.Attributes, param3?: SplitIO.Attributes): SplitIO.Treatments { + const {key, flagSetNames, attributes} = parseFlagSetParams(param1, param2, param3); + return this.getClient(key).getTreatmentsByFlagSet(flagSetNames, attributes); + } + + /** + * Returns a TreatmentsWithConfig value, which is an object map with the TreatmentWithConfig (an object with both treatment and config string) for the given flag set. + * @function getTreatmentsWithConfigByFlagSet + * @param {SplitKey} key - The key for the client instance. + * @param {string} flagSetName - The string that represents the flag set we want to get the related feature flags and treatments. + * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key. + * @returns {TreatmentsWithConfig} The map with all the TreatmentWithConfig objects + */ + getTreatmentsWithConfigByFlagSet(key: SplitIO.SplitKey, flagSetName: string, attributes?: SplitIO.Attributes): SplitIO.TreatmentsWithConfig; + /** + * Returns a TreatmentsWithConfig value, which is an object map with the TreatmentWithConfig (an object with both treatment and config string) for the given flag set. + * @function getTreatmentsWithConfigByFlagSet + * @param {string} flagSetName - The string that represents the flag set we want to get the related feature flags and treatments. + * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key. + * @returns {TreatmentsWithConfig} The map with all the TreatmentWithConfig objects + */ + getTreatmentsWithConfigByFlagSet(flagSetName: string, attributes?: SplitIO.Attributes): SplitIO.TreatmentsWithConfig; + getTreatmentsWithConfigByFlagSet(param1: string | SplitIO.SplitKey, param2?: string | SplitIO.Attributes, param3?: SplitIO.Attributes): SplitIO.TreatmentsWithConfig { + const {key, flagSetNames, attributes} = parseFlagSetParams(param1, param2, param3); + return this.getClient(key).getTreatmentsWithConfigByFlagSet(flagSetNames, attributes); + } + + /** + * Returns a Treatments value, which is an object map with the treatments for the given flag sets. + * @function getTreatmentsByFlagSets + * @param {SplitKey} key - The key for the client instance. + * @param {Array} flagSetNames - An array of the flag set names we want to get the related feature flags and treatments. + * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key. + * @returns {Treatments} - The treatments object map. + */ + getTreatmentsByFlagSets(key: SplitIO.SplitKey, flagSetNames: string[], attributes?: SplitIO.Attributes): SplitIO.Treatments; + /** + * Returns a Treatments value, which is an object map with the treatments for the given flag sets. + * @function getTreatmentsByFlagSets + * @param {Array} flagSetNames - An array of the flag set names we want to get the related feature flags and treatments. + * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key. + * @returns {Treatments} - The treatments object map. + */ + getTreatmentsByFlagSets(flagSetNames: string[], attributes?: SplitIO.Attributes): SplitIO.Treatments; + getTreatmentsByFlagSets(param1: string[] | SplitIO.SplitKey, param2?: string[] | SplitIO.Attributes, param3?: SplitIO.Attributes): SplitIO.Treatments { + const {key, flagSetNames, attributes} = parseFlagSetParams(param1, param2, param3); + return this.getClient(key).getTreatmentsByFlagSets(flagSetNames, attributes); + } + + /** + * Returns a TreatmentsWithConfig value, which is an object map with the TreatmentWithConfig (an object with both treatment and config string) for the given flag sets. + * @function getTreatmentsWithConfigByFlagSets + * @param {SplitKey} key - The key for the client instance. + * @param {Array} flagSetNames - An array of the flag set names we want to get the related feature flags and treatments. + * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key. + * @returns {TreatmentsWithConfig} The map with all the TreatmentWithConfig objects + */ + getTreatmentsWithConfigByFlagSets(key: SplitIO.SplitKey, flagSetNames: string[], attributes?: SplitIO.Attributes): SplitIO.TreatmentsWithConfig; + /** + * Returns a TreatmentsWithConfig value, which is an object map with the TreatmentWithConfig (an object with both treatment and config string) for the given flag sets. + * @function getTreatmentsWithConfigByFlagSets + * @param {Array} flagSetNames - An array of the flag set names we want to get the related feature flags and treatments. + * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key. + * @returns {TreatmentsWithConfig} The map with all the TreatmentWithConfig objects + */ + getTreatmentsWithConfigByFlagSets(flagSetNames: string[], attributes?: SplitIO.Attributes): SplitIO.TreatmentsWithConfig; + getTreatmentsWithConfigByFlagSets(param1: string[] | SplitIO.SplitKey, param2?: string[] | SplitIO.Attributes, param3?: SplitIO.Attributes): SplitIO.TreatmentsWithConfig { + const {key, flagSetNames, attributes} = parseFlagSetParams(param1, param2, param3); + return this.getClient(key).getTreatmentsWithConfigByFlagSets(flagSetNames, attributes); + } + /** * Tracks an event for a shared client to be fed to the results product on Split user interface and returns a promise to signal when the event was successfully queued (or not). * @function track @@ -311,7 +399,7 @@ export class SplitService { * @param {Properties=} properties - The properties of this event. Values can be string, number, boolean or null. * @returns {Promise} A promise that resolves to a boolean indicating if the event was added to the queue successfully or not. */ - track(key: SplitIO.SplitKey, trafficType: string, eventType: string, value?: number | undefined, properties?: SplitIO.Properties | undefined): boolean; + track(key: SplitIO.SplitKey, trafficType: string, eventType: string, value?: number, properties?: SplitIO.Properties): boolean; /** * Tracks an event to be fed to the results product on Split user interface and returns a promise to signal when the event was successfully queued (or not). * @function track @@ -321,8 +409,8 @@ export class SplitService { * @param {Properties=} properties - The properties of this event. Values can be string, number, boolean or null. * @returns {Promise} A promise that resolves to a boolean indicating if the event was added to the queue successfully or not. */ - track(trafficType: string, eventType: string, value?: number | undefined, properties?: SplitIO.Properties | undefined): boolean; - track(param1: string | SplitIO.SplitKey, param2: string, param3?: string | number | undefined, param4?: number | SplitIO.Properties | undefined, param5?: SplitIO.Properties | undefined): boolean { + track(trafficType: string, eventType: string, value?: number, properties?: SplitIO.Properties): boolean; + track(param1: string | SplitIO.SplitKey, param2: string, param3?: string | number, param4?: number | SplitIO.Properties, param5?: SplitIO.Properties): boolean { const {key, trafficType, eventType, value, properties} = parseTrackParams(param1, param2, param3, param4, param5); return this.getClient(key).track(trafficType, eventType, value, properties); } diff --git a/projects/splitio/src/lib/utils/constants.ts b/projects/splitio/src/lib/utils/constants.ts index 8b0c5f3..66a43cc 100644 --- a/projects/splitio/src/lib/utils/constants.ts +++ b/projects/splitio/src/lib/utils/constants.ts @@ -33,6 +33,10 @@ export const CONTROL_CLIENT = { }); return result; }, + getTreatmentsByFlagSet: () => { return {}; }, + getTreatmentsWithConfigByFlagSet: () => { return {}; }, + getTreatmentsByFlagSets: () => { return {}; }, + getTreatmentsWithConfigByFlagSets: () => { return {}; }, track: () => { return false; } }; diff --git a/projects/splitio/src/lib/utils/utils.ts b/projects/splitio/src/lib/utils/utils.ts index 1656c17..618bd44 100644 --- a/projects/splitio/src/lib/utils/utils.ts +++ b/projects/splitio/src/lib/utils/utils.ts @@ -7,12 +7,17 @@ export function buildInstance(key: SplitIO.SplitKey): string { return `${key.matchingKey ? key.matchingKey : key}-${key.bucketingKey ? key.bucketingKey : key}-`; } -export function parseTreatmentParams(param1: string | string[] | SplitIO.SplitKey, param2?: string | string[] | SplitIO.Attributes | undefined, param3?: SplitIO.Attributes | undefined): any { +export function parseTreatmentParams(param1: string | string[] | SplitIO.SplitKey, param2?: string | string[] | SplitIO.Attributes, param3?: SplitIO.Attributes): any { if (isString(param2) || Array.isArray(param2)) return { key: param1, featureFlagNames: param2, attributes: param3}; return { key: undefined, featureFlagNames: param1, attributes: param2 }; } -export function parseTrackParams(param1: string | SplitIO.SplitKey, param2: string, param3: number | string | undefined, param4: number | SplitIO.Properties | undefined, param5: SplitIO.Properties | undefined) { +export function parseFlagSetParams(param1: string | string[] | SplitIO.SplitKey, param2?: string | string[] | SplitIO.Attributes, param3?: SplitIO.Attributes): any { + if (isString(param2) || Array.isArray(param2)) return { key: param1, flagSetNames: param2, attributes: param3}; + return { key: undefined, flagSetNames: param1, attributes: param2 }; +} + +export function parseTrackParams(param1: string | SplitIO.SplitKey, param2: string, param3: number | string, param4: number | SplitIO.Properties, param5: SplitIO.Properties) { if (isString(param3)) return { key: param1, trafficType: param2, eventType: param3, value: param4, properties: param5}; return { key: undefined, trafficType: param1, eventType: param2, value: param3, properties: param4 }; }