From e3199ce772a656fa1aa4a785a2e4f0a20e2e2041 Mon Sep 17 00:00:00 2001 From: Emmanuel Zamora Date: Fri, 15 Dec 2023 18:09:19 -0300 Subject: [PATCH] Add some tests. use js-browser@0.13.0. remove unnecesary undefined types. update changes file. --- CHANGES.txt | 9 ++- package-lock.json | 34 +++++------ package.json | 4 +- projects/splitio/package.json | 4 +- .../src/lib/__tests__/mocks/SplitView.mock.ts | 6 +- .../src/lib/__tests__/splitio.service.spec.ts | 17 ++++++ projects/splitio/src/lib/splitio.service.ts | 56 +++++++++---------- projects/splitio/src/lib/utils/constants.ts | 8 +-- projects/splitio/src/lib/utils/utils.ts | 6 +- 9 files changed, 83 insertions(+), 61 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 864dd74..eacfcc5 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +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. - - Updated @splitsoftware/splitio-browserjs package to version 0.12.0 + - 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 e3f4b13..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.12.0", + "@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.12.0", - "resolved": "https://registry.npmjs.org/@splitsoftware/splitio-browserjs/-/splitio-browserjs-0.12.0.tgz", - "integrity": "sha512-SAq5O+KLoyzS4k4l6ON9Hm6EDutgiF/h5HVWRxYce5Zl7QrKWP2MTNzLhTaM/a5xdignnBI5tO4zei1yNeZj6A==", + "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.11.0", + "@splitsoftware/splitio-commons": "1.12.1", "@types/google.analytics": "0.0.40", "unfetch": "^4.2.0" } }, "node_modules/@splitsoftware/splitio-commons": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/@splitsoftware/splitio-commons/-/splitio-commons-1.11.0.tgz", - "integrity": "sha512-JxXltOwFrTSDgvuM4MTzrNzxYEX2YSaNLNM/STtehLNRC20O7rYgUrEWT3xcvVOgGMwouyFOpGpNL94TthN2Aw==", + "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.12.0", - "resolved": "https://registry.npmjs.org/@splitsoftware/splitio-browserjs/-/splitio-browserjs-0.12.0.tgz", - "integrity": "sha512-SAq5O+KLoyzS4k4l6ON9Hm6EDutgiF/h5HVWRxYce5Zl7QrKWP2MTNzLhTaM/a5xdignnBI5tO4zei1yNeZj6A==", + "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.11.0", + "@splitsoftware/splitio-commons": "1.12.1", "@types/google.analytics": "0.0.40", "unfetch": "^4.2.0" } }, "@splitsoftware/splitio-commons": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/@splitsoftware/splitio-commons/-/splitio-commons-1.11.0.tgz", - "integrity": "sha512-JxXltOwFrTSDgvuM4MTzrNzxYEX2YSaNLNM/STtehLNRC20O7rYgUrEWT3xcvVOgGMwouyFOpGpNL94TthN2Aw==", + "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 ea73acd..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.12.0", + "@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 5f021ca..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.12.0" + "@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 793aba4..21fff6c 100644 --- a/projects/splitio/src/lib/__tests__/mocks/SplitView.mock.ts +++ b/projects/splitio/src/lib/__tests__/mocks/SplitView.mock.ts @@ -3,8 +3,7 @@ export const mockedFeatureFlagView = [ 'changeNumber': 0, 'configs': {}, 'killed': false, - 'name': - 'test_split', + 'name': 'test_split', 'trafficType': 'localhost', 'treatments': ['on'], 'defaultTreatment': 'control', @@ -16,8 +15,7 @@ export const mockedFeatureFlagView = [ 'off': '{"bannerText":"Click here."}' }, 'killed': false, - 'name': - 'test_split2', + 'name': 'test_split2', 'trafficType': 'localhost', 'treatments': ['off'], 'defaultTreatment': 'control', diff --git a/projects/splitio/src/lib/__tests__/splitio.service.spec.ts b/projects/splitio/src/lib/__tests__/splitio.service.spec.ts index db5de8f..3f12900 100644 --- a/projects/splitio/src/lib/__tests__/splitio.service.spec.ts +++ b/projects/splitio/src/lib/__tests__/splitio.service.spec.ts @@ -250,6 +250,23 @@ 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(); diff --git a/projects/splitio/src/lib/splitio.service.ts b/projects/splitio/src/lib/splitio.service.ts index 10f911d..4df437d 100644 --- a/projects/splitio/src/lib/splitio.service.ts +++ b/projects/splitio/src/lib/splitio.service.ts @@ -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,8 +295,8 @@ 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); } @@ -309,7 +309,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. */ - getTreatmentsByFlagSet(key: SplitIO.SplitKey, flagSetName: string, attributes?: SplitIO.Attributes | undefined): SplitIO.Treatments; + 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 @@ -317,8 +317,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. */ - getTreatmentsByFlagSet(flagSetName: string, attributes?: SplitIO.Attributes | undefined): SplitIO.Treatments; - getTreatmentsByFlagSet(param1: string | SplitIO.SplitKey, param2?: string | SplitIO.Attributes | undefined, param3?: SplitIO.Attributes | undefined): SplitIO.Treatments { + 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); } @@ -331,7 +331,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 */ - getTreatmentsWithConfigByFlagSet(key: SplitIO.SplitKey, flagSetName: string, attributes?: SplitIO.Attributes | undefined): SplitIO.TreatmentsWithConfig; + 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 @@ -339,8 +339,8 @@ 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 */ - getTreatmentsWithConfigByFlagSet(flagSetName: string, attributes?: SplitIO.Attributes | undefined): SplitIO.TreatmentsWithConfig; - getTreatmentsWithConfigByFlagSet(param1: string | SplitIO.SplitKey, param2?: string | SplitIO.Attributes | undefined, param3?: SplitIO.Attributes | undefined): SplitIO.TreatmentsWithConfig { + 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); } @@ -353,7 +353,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. */ - getTreatmentsByFlagSets(key: SplitIO.SplitKey, flagSetNames: string[], attributes?: SplitIO.Attributes | undefined): SplitIO.Treatments; + 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 @@ -361,8 +361,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. */ - getTreatmentsByFlagSets(flagSetNames: string[], attributes?: SplitIO.Attributes | undefined): SplitIO.Treatments; - getTreatmentsByFlagSets(param1: string[] | SplitIO.SplitKey, param2?: string[] | SplitIO.Attributes | undefined, param3?: SplitIO.Attributes | undefined): SplitIO.Treatments { + 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); } @@ -375,7 +375,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 */ - getTreatmentsWithConfigByFlagSets(key: SplitIO.SplitKey, flagSetNames: string[], attributes?: SplitIO.Attributes | undefined): SplitIO.TreatmentsWithConfig; + 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 @@ -383,8 +383,8 @@ 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 */ - getTreatmentsWithConfigByFlagSets(flagSetNames: string[], attributes?: SplitIO.Attributes | undefined): SplitIO.TreatmentsWithConfig; - getTreatmentsWithConfigByFlagSets(param1: string[] | SplitIO.SplitKey, param2?: string[] | SplitIO.Attributes | undefined, param3?: SplitIO.Attributes | undefined): SplitIO.TreatmentsWithConfig { + 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); } @@ -399,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 @@ -409,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 b6f4700..66a43cc 100644 --- a/projects/splitio/src/lib/utils/constants.ts +++ b/projects/splitio/src/lib/utils/constants.ts @@ -33,10 +33,10 @@ export const CONTROL_CLIENT = { }); return result; }, - getTreatmentsByFlagSet: () => { return []; }, - getTreatmentsWithConfigByFlagSet: () => { return []; }, - getTreatmentsByFlagSets: () => { return []; }, - getTreatmentsWithConfigByFlagSets: () => { return []; }, + 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 9349997..618bd44 100644 --- a/projects/splitio/src/lib/utils/utils.ts +++ b/projects/splitio/src/lib/utils/utils.ts @@ -7,17 +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 parseFlagSetParams(param1: string | string[] | SplitIO.SplitKey, param2?: string | string[] | SplitIO.Attributes | undefined, param3?: SplitIO.Attributes | undefined): any { +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 | undefined, param4: number | SplitIO.Properties | undefined, param5: SplitIO.Properties | undefined) { +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 }; }