Skip to content

Commit

Permalink
chore: update import and export names, default new routes
Browse files Browse the repository at this point in the history
  • Loading branch information
utsabc committed Nov 9, 2023
1 parent c14b689 commit 21e68d5
Show file tree
Hide file tree
Showing 46 changed files with 130 additions and 348 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@typescript-eslint/no-explicit-any": "off",
"class-methods-use-this": "off",
"@typescript-eslint/return-await": "error",
"import/prefer-default-export": "error",
"import/prefer-default-export": "off",
"sonarjs/no-ignored-return": "error",
"no-new": "error",
"@typescript-eslint/no-shadow": "error",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"build:ci": "tsc -p tsconfig.json",
"build:swagger": "npm run build && npm run setup:swagger",
"build": "npm run build:ci && npm run copy",
"build:clean": "npm run clean && npm run build",
"clean:build": "npm run clean && npm run build",
"verify": "eslint . || exit 1; npm run test:js || exit 1",
"test:testRouter": "jest testRouter --detectOpenHandles --coverage --notify --watchAll=false",
"test:benchmark": "node benchmark/index.js",
Expand Down
12 changes: 6 additions & 6 deletions src/controllers/delivery.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Context } from 'koa';
import MiscService from '../services/misc';
import { MiscService } from '../services/misc';
import { DeliveryResponse, ProcessorTransformationOutput } from '../types/index';
import ServiceSelector from '../helpers/serviceSelector';
import DeliveryTestService from '../services/delivertTest/deliveryTest';
import ControllerUtility from './util';
import { ServiceSelector } from '../helpers/serviceSelector';
import { DeliveryTestService } from '../services/delivertTest/deliveryTest';
import { ControllerUtility } from './util';
import logger from '../logger';
import DestinationPostTransformationService from '../services/destination/postTransformation';
import { DestinationPostTransformationService } from '../services/destination/postTransformation';
import tags from '../v0/util/tags';
import { FixMe } from '../util/types';

export default class DeliveryController {
export class DeliveryController {
public static async deliverToDestination(ctx: Context) {
logger.debug('Native(Delivery):: Request to transformer::', JSON.stringify(ctx.request.body));
let deliveryResponse: DeliveryResponse;
Expand Down
26 changes: 13 additions & 13 deletions src/controllers/destination.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { Context } from 'koa';
import MiscService from '../services/misc';
import PreTransformationDestinationService from '../services/destination/preTransformation';
import PostTransformationDestinationService from '../services/destination/postTransformation';
import { MiscService } from '../services/misc';
import { DestinationPreTransformationService } from '../services/destination/preTransformation';
import { DestinationPostTransformationService } from '../services/destination/postTransformation';
import {
ProcessorTransformationRequest,
RouterTransformationRequest,
ProcessorTransformationResponse,
RouterTransformationResponse,
} from '../types/index';
import ServiceSelector from '../helpers/serviceSelector';
import ControllerUtility from './util';
import { ServiceSelector } from '../helpers/serviceSelector';
import { ControllerUtility } from './util';
import stats from '../util/stats';
import logger from '../logger';
import { getIntegrationVersion } from '../util/utils';
import tags from '../v0/util/tags';
import DynamicConfigParser from '../util/dynamicConfigParser';
import { DynamicConfigParser } from '../util/dynamicConfigParser';

export default class DestinationController {
export class DestinationController {
public static async destinationTransformAtProcessor(ctx: Context) {
const startTime = new Date();
logger.debug(
Expand All @@ -36,7 +36,7 @@ export default class DestinationController {
const integrationService = ServiceSelector.getDestinationService(events);
try {
integrationService.init();
events = PreTransformationDestinationService.preProcess(
events = DestinationPreTransformationService.preProcess(
events,
ctx,
) as ProcessorTransformationRequest[];
Expand All @@ -59,7 +59,7 @@ export default class DestinationController {
tags.FEATURES.PROCESSOR,
);
metaTO.metadata = ev.metadata;
const errResp = PostTransformationDestinationService.handleProcessorTransformFailureEvents(
const errResp = DestinationPostTransformationService.handleProcessorTransformFailureEvents(

Check warning on line 62 in src/controllers/destination.ts

View check run for this annotation

Codecov / codecov/patch

src/controllers/destination.ts#L62

Added line #L62 was not covered by tests
error,
metaTO,
);
Expand Down Expand Up @@ -110,7 +110,7 @@ export default class DestinationController {
const integrationService = ServiceSelector.getDestinationService(events);
let resplist: RouterTransformationResponse[];
try {
events = PreTransformationDestinationService.preProcess(events, ctx);
events = DestinationPreTransformationService.preProcess(events, ctx);
const timestampCorrectEvents = ControllerUtility.handleTimestampInEvents(events);
events = DynamicConfigParser.process(timestampCorrectEvents);
resplist = await integrationService.doRouterTransformation(
Expand All @@ -127,7 +127,7 @@ export default class DestinationController {
tags.FEATURES.ROUTER,
);
metaTO.metadatas = events.map((ev) => ev.metadata);
const errResp = PostTransformationDestinationService.handleRouterTransformFailureEvents(
const errResp = DestinationPostTransformationService.handleRouterTransformFailureEvents(

Check warning on line 130 in src/controllers/destination.ts

View check run for this annotation

Codecov / codecov/patch

src/controllers/destination.ts#L130

Added line #L130 was not covered by tests
error,
metaTO,
);
Expand Down Expand Up @@ -165,7 +165,7 @@ export default class DestinationController {
let events = routerRequest.input;
const integrationService = ServiceSelector.getDestinationService(events);
try {
events = PreTransformationDestinationService.preProcess(events, ctx);
events = DestinationPreTransformationService.preProcess(events, ctx);
const timestampCorrectEvents = ControllerUtility.handleTimestampInEvents(events);
const resplist = integrationService.doBatchTransformation(
timestampCorrectEvents,
Expand All @@ -182,7 +182,7 @@ export default class DestinationController {
tags.FEATURES.BATCH,
);
metaTO.metadatas = events.map((ev) => ev.metadata);
const errResp = PostTransformationDestinationService.handleBatchTransformFailureEvents(
const errResp = DestinationPostTransformationService.handleBatchTransformFailureEvents(

Check warning on line 185 in src/controllers/destination.ts

View check run for this annotation

Codecov / codecov/patch

src/controllers/destination.ts#L185

Added line #L185 was not covered by tests
error,
metaTO,
);
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/eventTest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Context } from 'koa';
import EventTesterService from '../services/eventTest/eventTester';
import { EventTesterService } from '../services/eventTest/eventTester';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { CatchErr, FixMe } from '../util/types';

export default class EventTestController {
export class EventTestController {
private static API_VERSION = '1';

public static async testEvent(ctx: Context) {
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/misc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Context } from 'koa';
import MiscService from '../services/misc';
import { MiscService } from '../services/misc';

export default class MiscController {
export class MiscController {
public static healthStats(ctx: Context) {
ctx.body = MiscService.getHealthInfo();
ctx.status = 200;
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/profile.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Context } from 'koa';
import ProfileService from '../services/profile';
import ControllerUtility from './util';
import { ProfileService } from '../services/profile';
import { ControllerUtility } from './util';

export default class ProfileController {
export class ProfileController {
/**
* Example usage of API
*
Expand Down
9 changes: 4 additions & 5 deletions src/controllers/regulation.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Context } from 'koa';
import logger from '../logger';
import { UserDeletionRequest, UserDeletionResponse } from '../types';
import ServiceSelector from '../helpers/serviceSelector';
import { ServiceSelector } from '../helpers/serviceSelector';
import tags from '../v0/util/tags';
import stats from '../util/stats';
import PostTransformationDestinationService from '../services/destination/postTransformation';
import { DestinationPostTransformationService } from '../services/destination/postTransformation';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { CatchErr } from '../util/types';

// TODO: refactor this class to new format
export default class RegulationController {
export class RegulationController {
public static async deleteUsers(ctx: Context) {
logger.debug(
'Native(Process-Transform):: Requst to transformer::',
Expand Down Expand Up @@ -44,7 +43,7 @@ export default class RegulationController {
tags.FEATURES.USER_DELETION,
);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const errResp = PostTransformationDestinationService.handleUserDeletionFailureEvents(
const errResp = DestinationPostTransformationService.handleUserDeletionFailureEvents(

Check warning on line 46 in src/controllers/regulation.ts

View check run for this annotation

Codecov / codecov/patch

src/controllers/regulation.ts#L46

Added line #L46 was not covered by tests
error,
metaTO,
);
Expand Down
12 changes: 6 additions & 6 deletions src/controllers/source.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Context } from 'koa';
import MiscService from '../services/misc';
import ServiceSelector from '../helpers/serviceSelector';
import ControllerUtility from './util';
import { MiscService } from '../services/misc';
import { ServiceSelector } from '../helpers/serviceSelector';
import { ControllerUtility } from './util';
import logger from '../logger';
import PostTransformationServiceSource from '../services/source/postTransformation';
import { SourcePostTransformationService } from '../services/source/postTransformation';

export default class SourceController {
export class SourceController {
public static async sourceTransform(ctx: Context) {
logger.debug(
'Native(Source-Transform):: Request to transformer::',
Expand All @@ -25,7 +25,7 @@ export default class SourceController {
ctx.body = resplist;
} catch (err: any) {
const metaTO = integrationService.getTags();
const resp = PostTransformationServiceSource.handleFailureEventsSource(err, metaTO);
const resp = SourcePostTransformationService.handleFailureEventsSource(err, metaTO);

Check warning on line 28 in src/controllers/source.ts

View check run for this annotation

Codecov / codecov/patch

src/controllers/source.ts#L28

Added line #L28 was not covered by tests
ctx.body = [resp];
}
ControllerUtility.postProcess(ctx);
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/trackingPlan.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Context } from 'koa';
import TrackingPlanservice from '../services/trackingPlan';
import ControllerUtility from './util';
import { TrackingPlanservice } from '../services/trackingPlan';
import { ControllerUtility } from './util';

export default class TrackingPlanController {
export class TrackingPlanController {
public static async validateTrackingPlan(ctx: Context) {
const events = ctx.request.body;
const requestSize = Number(ctx.request.get('content-length'));
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/userTransform.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Context } from 'koa';
import { ProcessorTransformationRequest, UserTransformationServiceResponse } from '../types/index';
import UserTransformService from '../services/userTransform';
import { UserTransformService } from '../services/userTransform';
import logger from '../logger';
import {
setupUserTransformHandler,
extractLibraries,
validateCode,
} from '../util/customTransformer';
import ControllerUtility from './util';
import { ControllerUtility } from './util';

export default class UserTransformController {
export class UserTransformController {
public static async transform(ctx: Context) {
logger.debug(
'(User transform - router:/customTransform ):: Request to transformer',
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getValueFromMessage } from '../../v0/util';
import genericFieldMap from '../../v0/util/data/GenericFieldMapping.json';
import { EventType, MappedToDestinationKey } from '../../constants';

export default class ControllerUtility {
export class ControllerUtility {
public static timestampValsMap: Record<string, string[]> = {
[EventType.IDENTIFY]: [
`context.${RETL_TIMESTAMP}`,
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/fetchHandlers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import MiscService from '../services/misc';
import { MiscService } from '../services/misc';

export default class FetchHandler {
export class FetchHandler {
private static sourceHandlerMap: Map<string, any> = new Map();

private static destHandlerMap: Map<string, any> = new Map();
Expand Down
16 changes: 8 additions & 8 deletions src/helpers/serviceSelector.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { ProcessorTransformationRequest, RouterTransformationRequestData } from '../types/index';
import { INTEGRATION_SERVICE } from '../routes/utils/constants';
import CDKV1DestinationService from '../services/destination/cdkV1Integration';
import CDKV2DestinationService from '../services/destination/cdkV2Integration';
import DestinationService from '../interfaces/DestinationService';
import NativeIntegrationDestinationService from '../services/destination/nativeIntegration';
import SourceService from '../interfaces/SourceService';
import NativeIntegrationSourceService from '../services/source/nativeIntegration';
import { CDKV1DestinationService } from '../services/destination/cdkV1Integration';
import { CDKV2DestinationService } from '../services/destination/cdkV2Integration';
import { DestinationService } from '../interfaces/DestinationService';
import { NativeIntegrationDestinationService } from '../services/destination/nativeIntegration';
import { SourceService } from '../interfaces/SourceService';
import { NativeIntegrationSourceService } from '../services/source/nativeIntegration';
import { PlatformError } from '../v0/util/errorTypes';
import ComparatorService from '../services/comparator';
import { ComparatorService } from '../services/comparator';
import { FixMe } from '../util/types';

export default class ServiceSelector {
export class ServiceSelector {
private static serviceMap: Map<string, any> = new Map();

private static services = {
Expand Down
14 changes: 2 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import gracefulShutdown from 'http-graceful-shutdown';
import dotenv from 'dotenv';
import logger from './logger';
import cluster from './util/cluster';
import { router } from './legacy/router';
import { testRouter } from './testRouter';
import { metricsRouter } from './routes/metricsRouter';
import { addStatMiddleware, addRequestSizeMiddleware, initPyroscope } from './middleware';
import { logProcessInfo } from './util/utils';
Expand All @@ -14,7 +12,6 @@ import { RedisDB } from './util/redis/redisConnector';

dotenv.config();
const clusterEnabled = process.env.CLUSTER_ENABLED !== 'false';
const useUpdatedRoutes = process.env.ENABLE_NEW_ROUTES !== 'false';
const port = parseInt(process.env.PORT ?? '9090', 10);
const metricsPort = parseInt(process.env.METRICS_PORT || '9091', 10);

Expand All @@ -35,15 +32,8 @@ app.use(
addRequestSizeMiddleware(app);
addSwaggerRoutes(app);

if (useUpdatedRoutes) {
logger.info('Using new routes');
applicationRoutes(app);
} else {
// To be depricated
logger.info('Using old routes');
app.use(router.routes()).use(router.allowedMethods());
app.use(testRouter.routes()).use(testRouter.allowedMethods());
}
logger.info('Using new routes');
applicationRoutes(app);

function finalFunction() {
RedisDB.disconnect();
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/DestinationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
UserDeletionResponse,
} from '../types/index';

export default interface DestinationService {
export interface DestinationService {
getName(): string;

init(): void;
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/SourceService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MetaTransferObject, SourceTransformationResponse } from '../types/index';

export default interface SourceService {
export interface SourceService {
getTags(): MetaTransferObject;

sourceTransformRoutine(
Expand Down
2 changes: 1 addition & 1 deletion src/middlewares/featureFlag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface FeatureFlags {

export const FEATURE_FILTER_CODE = 'filter-code';

export default class FeatureFlagMiddleware {
export class FeatureFlagMiddleware {
public static async handle(ctx: Context, next: Next): Promise<void> {
// Initialize ctx.state.features if it doesn't exist
ctx.state.features = (ctx.state.features || {}) as FeatureFlags;
Expand Down
2 changes: 1 addition & 1 deletion src/middlewares/routeActivation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const destinationFilterList = process.env.DESTINATION_FILTER_LIST?.toLocaleLower
const sourceFilteList = process.env.SOURCE_FILTER_LIST?.toLocaleLowerCase();
const deliveryFilterList = process.env.DESTINATION_DELIVERY_FILTER_LIST?.toLocaleLowerCase();

export default class RouteActivationMiddleware {
export class RouteActivationMiddleware {
private static executeActivationRule(ctx: Context, next: Next, shouldActivate: boolean) {
if (shouldActivate) {
return next();
Expand Down
4 changes: 2 additions & 2 deletions src/routes/delivery.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Router from '@koa/router';
import DeliveryController from '../controllers/delivery';
import RouteActivationMiddleware from '../middlewares/routeActivation';
import { DeliveryController } from '../controllers/delivery';
import { RouteActivationMiddleware } from '../middlewares/routeActivation';

const router = new Router();

Expand Down
Loading

0 comments on commit 21e68d5

Please sign in to comment.