From c7f1b4707dbad48642c8ed76c52c089d1d42e872 Mon Sep 17 00:00:00 2001 From: Catalin Faur <52102171+cfaur09@users.noreply.github.com> Date: Fri, 24 Nov 2023 13:35:44 +0200 Subject: [PATCH] add features flag (#1153) --- src/endpoints/network/entities/about.ts | 5 ++++ .../network/entities/feature.configs.ts | 25 +++++++++++++++++++ src/endpoints/network/network.service.ts | 9 +++++++ src/test/unit/services/network.spec.ts | 15 +++++++++++ 4 files changed, 54 insertions(+) create mode 100644 src/endpoints/network/entities/feature.configs.ts diff --git a/src/endpoints/network/entities/about.ts b/src/endpoints/network/entities/about.ts index f47ee289f..81c012c55 100644 --- a/src/endpoints/network/entities/about.ts +++ b/src/endpoints/network/entities/about.ts @@ -1,5 +1,6 @@ import { Field, ObjectType } from "@nestjs/graphql"; import { ApiProperty } from "@nestjs/swagger"; +import { FeatureConfigs } from "./feature.configs"; @ObjectType("About", { description: "About object type." }) export class About { @@ -30,4 +31,8 @@ export class About { @Field(() => String, { description: "Scam engine version.", nullable: true }) @ApiProperty({ type: String, nullable: true }) scamEngineVersion: string | undefined = undefined; + + @Field(() => FeatureConfigs, { description: "Feature Flags.", nullable: true }) + @ApiProperty({ type: FeatureConfigs, nullable: true }) + features: FeatureConfigs | undefined = undefined; } diff --git a/src/endpoints/network/entities/feature.configs.ts b/src/endpoints/network/entities/feature.configs.ts new file mode 100644 index 000000000..5b8f7c3cb --- /dev/null +++ b/src/endpoints/network/entities/feature.configs.ts @@ -0,0 +1,25 @@ +import { Field, ObjectType } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; + +@ObjectType("FeatureConfigs", { description: "FeatureConfigs object type." }) +export class FeatureConfigs { + constructor(init?: Partial) { + Object.assign(this, init); + } + + @Field(() => Boolean, { description: "Update Collection Extra Details flag details." }) + @ApiProperty({ description: 'Update Collection extra details flag activation value' }) + updateCollectionExtraDetails: boolean = false; + + @Field(() => Boolean, { description: "Marketplace flag details." }) + @ApiProperty({ description: 'Marketplace flag activation value' }) + marketplace: boolean = false; + + @Field(() => Boolean, { description: "Exchange flag details." }) + @ApiProperty({ description: 'Exchange flag activation value' }) + exchange: boolean = false; + + @Field(() => Boolean, { description: "DataApi flag details." }) + @ApiProperty({ description: 'DataApi flag activation value' }) + dataApi: boolean = false; +} diff --git a/src/endpoints/network/network.service.ts b/src/endpoints/network/network.service.ts index 730c85c56..05872d7ef 100644 --- a/src/endpoints/network/network.service.ts +++ b/src/endpoints/network/network.service.ts @@ -21,6 +21,7 @@ import { SmartContractResultService } from '../sc-results/scresult.service'; import { TokenService } from '../tokens/token.service'; import { AccountFilter } from '../accounts/entities/account.filter'; import { DataApiService } from 'src/common/data-api/data-api.service'; +import { FeatureConfigs } from './entities/feature.configs'; @Injectable() export class NetworkService { @@ -332,12 +333,20 @@ export class NetworkService { } } + const features = new FeatureConfigs({ + updateCollectionExtraDetails: this.apiConfigService.isUpdateCollectionExtraDetailsEnabled(), + marketplace: this.apiConfigService.isMarketplaceFeatureEnabled(), + exchange: this.apiConfigService.isExchangeEnabled(), + dataApi: this.apiConfigService.isDataApiFeatureEnabled(), + }); + const about = new About({ appVersion, pluginsVersion, network: this.apiConfigService.getNetwork(), cluster: this.apiConfigService.getCluster(), version: apiVersion, + features: features, }); await this.pluginService.processAbout(about); diff --git a/src/test/unit/services/network.spec.ts b/src/test/unit/services/network.spec.ts index c2769434e..7bcec2472 100644 --- a/src/test/unit/services/network.spec.ts +++ b/src/test/unit/services/network.spec.ts @@ -44,6 +44,10 @@ describe('NetworkService', () => { getMetaChainShardId: jest.fn(), getAuctionContractAddress: jest.fn(), getDelegationContractAddress: jest.fn(), + isUpdateCollectionExtraDetailsEnabled: jest.fn(), + isMarketplaceFeatureEnabled: jest.fn(), + isExchangeEnabled: jest.fn(), + isDataApiFeatureEnabled: jest.fn(), }, }, { @@ -338,6 +342,12 @@ describe('NetworkService', () => { cluster: undefined, version: '', scamEngineVersion: '1.0.0', + features: { + updateCollectionExtraDetails: false, + marketplace: true, + exchange: true, + dataApi: true, + }, }; jest .spyOn(networkService['cachingService'], 'getOrSet') @@ -357,6 +367,11 @@ describe('NetworkService', () => { }); })); + jest.spyOn(apiConfigService, 'isUpdateCollectionExtraDetailsEnabled').mockReturnValue(false); + jest.spyOn(apiConfigService, 'isMarketplaceFeatureEnabled').mockReturnValue(true); + jest.spyOn(apiConfigService, 'isExchangeEnabled').mockReturnValue(true); + jest.spyOn(apiConfigService, 'isDataApiFeatureEnabled').mockReturnValue(true); + const result = await networkService.getAbout(); expect(result).toStrictEqual(expectedValues); });