diff --git a/packages/api/src/address/address.controller.ts b/packages/api/src/address/address.controller.ts index 2f461b4521..8b953062f5 100644 --- a/packages/api/src/address/address.controller.ts +++ b/packages/api/src/address/address.controller.ts @@ -24,9 +24,8 @@ import { LogService } from "../log/log.service"; import { ParseAddressPipe, ADDRESS_REGEX_PATTERN } from "../common/pipes/parseAddress.pipe"; import { TransferService } from "../transfer/transfer.service"; import { TransferDto } from "../transfer/transfer.dto"; -import config from "../config"; +import { swagger } from "../config/featureFlags"; -const { swagger } = config(); const entityName = "address"; @ApiTags("Address BFF") diff --git a/packages/api/src/app.module.ts b/packages/api/src/app.module.ts index fccac26cbf..cce4f45ef6 100644 --- a/packages/api/src/app.module.ts +++ b/packages/api/src/app.module.ts @@ -20,11 +20,9 @@ import { StatsModule } from "./stats/stats.module"; import { MetricsMiddleware } from "./middlewares/metrics.middleware"; import { metricProviders } from "./metrics"; import { DbMetricsService } from "./dbMetrics.service"; +import { disableExternalAPI } from "./config/featureFlags"; import config from "./config"; -// TMP: disable external API until release -const { disableExternalAPI } = config(); - @Module({ imports: [ ConfigModule.forRoot({ isGlobal: true, load: [config] }), @@ -35,6 +33,7 @@ const { disableExternalAPI } = config(); }), ApiModule, ApiContractModule, + // TMP: disable external API until release ...(disableExternalAPI ? [] : [ApiBlockModule, ApiAccountModule, ApiTransactionModule, ApiLogModule]), TokenModule, AddressModule, diff --git a/packages/api/src/batch/batch.controller.ts b/packages/api/src/batch/batch.controller.ts index ce14911034..a9666b7338 100644 --- a/packages/api/src/batch/batch.controller.ts +++ b/packages/api/src/batch/batch.controller.ts @@ -15,9 +15,8 @@ import { ApiListPageOkResponse } from "../common/decorators/apiListPageOkRespons import { BatchService } from "./batch.service"; import { BatchDto } from "./batch.dto"; import { BatchDetailsDto } from "./batchDetails.dto"; -import config from "../config"; +import { swagger } from "../config/featureFlags"; -const { swagger } = config(); const entityName = "batches"; @ApiTags("Batch BFF") diff --git a/packages/api/src/block/block.controller.ts b/packages/api/src/block/block.controller.ts index 1eab712754..25488e4506 100644 --- a/packages/api/src/block/block.controller.ts +++ b/packages/api/src/block/block.controller.ts @@ -15,9 +15,8 @@ import { ApiListPageOkResponse } from "../common/decorators/apiListPageOkRespons import { BlockService } from "./block.service"; import { BlockDto } from "./block.dto"; import { BlockDetailDto } from "./blockDetail.dto"; -import config from "../config"; +import { swagger } from "../config/featureFlags"; -const { swagger } = config(); const entityName = "blocks"; @ApiTags("Block BFF") diff --git a/packages/api/src/config/featureFlags.spec.ts b/packages/api/src/config/featureFlags.spec.ts new file mode 100644 index 0000000000..61a1530792 --- /dev/null +++ b/packages/api/src/config/featureFlags.spec.ts @@ -0,0 +1,7 @@ +import * as featureFlags from "./featureFlags.spec"; + +describe("featureFlags", () => { + it("sets default values", () => { + expect(featureFlags).toEqual({}); + }); +}); diff --git a/packages/api/src/config/featureFlags.ts b/packages/api/src/config/featureFlags.ts new file mode 100644 index 0000000000..ef77b0a852 --- /dev/null +++ b/packages/api/src/config/featureFlags.ts @@ -0,0 +1,11 @@ +import { config } from "dotenv"; +config(); + +const { DISABLE_API_SCHEMA_DOCS, DISABLE_BFF_API_SCHEMA_DOCS, DISABLE_EXTERNAL_API } = process.env; + +export const swagger = { + enabled: DISABLE_API_SCHEMA_DOCS !== "true", + bffEnabled: DISABLE_BFF_API_SCHEMA_DOCS !== "true", +}; + +export const disableExternalAPI = DISABLE_EXTERNAL_API === "true"; diff --git a/packages/api/src/config.spec.ts b/packages/api/src/config/index.spec.ts similarity index 87% rename from packages/api/src/config.spec.ts rename to packages/api/src/config/index.spec.ts index 87733cae0f..f7a1b7bf14 100644 --- a/packages/api/src/config.spec.ts +++ b/packages/api/src/config/index.spec.ts @@ -1,4 +1,9 @@ -import config from "./config"; +import config from "../config"; + +jest.mock("./featureFlags", () => ({ + feature1Enabled: true, + feature2Enabled: false, +})); describe("config", () => { const env = process.env; @@ -36,12 +41,11 @@ describe("config", () => { retryDelay: 3000, applicationName: "block-explorer-api", }, - swagger: { - enabled: true, - bffEnabled: true, - }, contractVerificationApiUrl: "http://127.0.0.1:3070", - disableExternalAPI: false, + featureFlags: { + feature1Enabled: true, + feature2Enabled: false, + }, }); }); diff --git a/packages/api/src/config.ts b/packages/api/src/config/index.ts similarity index 90% rename from packages/api/src/config.ts rename to packages/api/src/config/index.ts index db21c7d9a8..6b9c5f2a57 100644 --- a/packages/api/src/config.ts +++ b/packages/api/src/config/index.ts @@ -1,4 +1,5 @@ import { TypeOrmModuleOptions } from "@nestjs/typeorm"; +import * as featureFlags from "./featureFlags"; export default () => { const { @@ -9,9 +10,6 @@ export default () => { DATABASE_URL, DATABASE_CONNECTION_POOL_SIZE, DATABASE_CONNECTION_IDLE_TIMEOUT_MS, - DISABLE_API_SCHEMA_DOCS, - DISABLE_BFF_API_SCHEMA_DOCS, - DISABLE_EXTERNAL_API, DATABASE_STATEMENT_TIMEOUT_MS, CONTRACT_VERIFICATION_API_URL, } = process.env; @@ -74,11 +72,7 @@ export default () => { collectDbConnectionPoolMetricsInterval: parseInt(COLLECT_DB_CONNECTION_POOL_METRICS_INTERVAL, 10) || 10000, }, typeORM: getTypeOrmModuleOptions(), - swagger: { - enabled: DISABLE_API_SCHEMA_DOCS !== "true", - bffEnabled: DISABLE_BFF_API_SCHEMA_DOCS !== "true", - }, - disableExternalAPI: DISABLE_EXTERNAL_API === "true", contractVerificationApiUrl: CONTRACT_VERIFICATION_API_URL || "http://127.0.0.1:3070", + featureFlags, }; }; diff --git a/packages/api/src/main.ts b/packages/api/src/main.ts index 8be6b8bdd9..49246daeb9 100644 --- a/packages/api/src/main.ts +++ b/packages/api/src/main.ts @@ -22,7 +22,7 @@ async function bootstrap() { const metricsApp = await NestFactory.create(AppMetricsModule); metricsApp.enableShutdownHooks(); - if (configService.get("swagger.enabled")) { + if (configService.get("featureFlags.swagger.enabled")) { const swaggerConfig = new DocumentBuilder() .setTitle("Block explorer API") .setDescription("ZkSync Block Explorer API") diff --git a/packages/api/src/stats/stats.controller.ts b/packages/api/src/stats/stats.controller.ts index 91745e24bb..6878b0fe73 100644 --- a/packages/api/src/stats/stats.controller.ts +++ b/packages/api/src/stats/stats.controller.ts @@ -5,9 +5,8 @@ import { BatchService } from "../batch/batch.service"; import { BlockService } from "../block/block.service"; import { TransactionService } from "../transaction/transaction.service"; import { StatsDto } from "./stats.dto"; -import config from "../config"; +import { swagger } from "../config/featureFlags"; -const { swagger } = config(); const entityName = "stats"; @ApiTags("Stats BFF") diff --git a/packages/api/src/token/token.controller.ts b/packages/api/src/token/token.controller.ts index 5b91587e1a..6a17e72657 100644 --- a/packages/api/src/token/token.controller.ts +++ b/packages/api/src/token/token.controller.ts @@ -15,9 +15,8 @@ import { TransferService } from "../transfer/transfer.service"; import { TokenDto } from "./token.dto"; import { TransferDto } from "../transfer/transfer.dto"; import { ParseAddressPipe, ADDRESS_REGEX_PATTERN } from "../common/pipes/parseAddress.pipe"; -import config from "../config"; +import { swagger } from "../config/featureFlags"; -const { swagger } = config(); const entityName = "tokens"; @ApiTags("Token BFF") diff --git a/packages/api/src/transaction/transaction.controller.ts b/packages/api/src/transaction/transaction.controller.ts index ee1cd3e596..de59347454 100644 --- a/packages/api/src/transaction/transaction.controller.ts +++ b/packages/api/src/transaction/transaction.controller.ts @@ -19,9 +19,8 @@ import { LogDto } from "../log/log.dto"; import { LogService } from "../log/log.service"; import { TransactionService } from "./transaction.service"; import { ParseTransactionHashPipe, TX_HASH_REGEX_PATTERN } from "../common/pipes/parseTransactionHash.pipe"; -import config from "../config"; +import { swagger } from "../config/featureFlags"; -const { swagger } = config(); const entityName = "transactions"; @ApiTags("Transaction BFF")