import express from "express"; import { DDBConnector } from "./models/connector/DDBConnector"; import { BidRequestAdapter } from "./adapters/BidRequestAdapter"; import { KafkaConnector } from "./models/connector/KafkaProducer"; import { CampaignModel } from "./models/CampaignModel"; import { AdModel } from "./models/AdModel"; import { ExternalInventoryService } from "./funnels/external.funnel"; import { BidRequestService } from "./services/BidRequestService"; import InternalFunnel from "./funnels/internal.funnel"; import { ContextService } from "./services/targeting/ContextService"; import HeaderBiddingFunnel from "./funnels/header-bidding.funnel"; import { HealthService } from "./services/HealthService"; import { ContextHashMap } from "./services/scoringSystem/contextHashMap.service"; import CallToActionHashMap from "./services/scoringSystem/callToActionHashMap.service"; import AudienceHashMap from "./services/scoringSystem/audienceHashMap.service"; import { InternalApiController } from "./controllers/InternalApiController"; import { HealthController } from "./controllers/HealthController"; import { MetricController } from "./controllers/MetricController"; import { PingController } from "./controllers/PingController"; import S3Service from "./services/s3.service"; import { ExternalBlacklistService } from "./services/ExternalBlacklist.service"; import { config, isTest } from "./utils/config"; import { DVFraudService } from "./services/dvFraud.service"; import { FraudController } from "./controllers/FraudController"; import { ProfilerController } from "./controllers/ProfilerController"; import { ExternalApiController } from "./controllers/ExternalApiController"; import { MsAuctionService } from "./services/auction/MsAuction.service"; import SpeedService from "./services/speed.service"; import { BrandSafetyController } from "./controllers/BrandSafetyController"; import { StepFactory } from "./steps/stepFactory"; export const init = async (router: express.Router) => { const bidRequestAdapter = new BidRequestAdapter(); const dataConnector = new DDBConnector(config.DB_NAME_DATA, config.DAX_ENDPOINT_DATA); const cappingsConnector = new DDBConnector(config.DB_NAME_CAPPINGS, undefined); const kafkaBidRequestConnector = new KafkaConnector(config.BROKER_LIST_CLUSTER_A, "bidrequest"); const kafkaBidRequestRawConnector = new KafkaConnector( config.BROKER_LIST_CLUSTER_B, "_bidrequestraw" ); const kafkaInternalRequestConnector = new KafkaConnector( config.BROKER_LIST_CLUSTER_B, "choices_requests" ); if (!isTest()) { await Promise.all([ kafkaBidRequestConnector.readyPromise, kafkaBidRequestRawConnector.readyPromise, kafkaInternalRequestConnector.readyPromise, dataConnector.getClient(), cappingsConnector.getClient(), ]); } const campaignModel = new CampaignModel(dataConnector); const adModel = new AdModel(cappingsConnector); const contextService = new ContextService(ContextHashMap.getInstance()); const bidRequestService = new BidRequestService( bidRequestAdapter, adModel, kafkaBidRequestConnector, kafkaBidRequestRawConnector ); const dvFraudService = new DVFraudService(); const speedService = new SpeedService(); const healthService = new HealthService( dataConnector, ContextHashMap.getInstance(), CallToActionHashMap.getInstance(), AudienceHashMap.getInstance() ); const stepFactory = new StepFactory(campaignModel, contextService, dvFraudService, speedService); if (config.INVENTORY === "external") { const s3Service = new S3Service(); const externalBlacklistService = new ExternalBlacklistService( s3Service, campaignModel, parseFloat(config.S3_BLACKLIST_EXTERNAL_RELOAD_TIME_IN_MINUTE), config.S3_BLACKLIST_EXTERNAL_BUCKET, config.S3_BLACKLIST_EXTERNAL_FILENAME ); stepFactory.initExternalBlacklist(externalBlacklistService); const externalInventoryService = new ExternalInventoryService( campaignModel, bidRequestService, kafkaInternalRequestConnector, stepFactory ); const apiController = new ExternalApiController(externalInventoryService); router.use(apiController.router); } else { const msAuctionService = new MsAuctionService(campaignModel, config.MS_AUCTION_HOST, adModel); stepFactory.initProgrammatic(msAuctionService); const internalInventoryService = new InternalFunnel( campaignModel, stepFactory, kafkaInternalRequestConnector ); const headerBiddingService = new HeaderBiddingFunnel( campaignModel, stepFactory, kafkaInternalRequestConnector ); const apiController = new InternalApiController(internalInventoryService, headerBiddingService); router.use(apiController.router); const pingController = new PingController(); router.use(pingController.router); const fraudController = new FraudController(dvFraudService); router.use(fraudController.router); const brandSafetyController = new BrandSafetyController(); router.use(brandSafetyController.router); } const healthController = new HealthController(healthService); router.use(healthController.router); const metricController = new MetricController(); router.use(metricController.router); const profilerController = new ProfilerController(); router.use(profilerController.router); };