From a71e2a8007217020998cc9608a337ae433e1cbf9 Mon Sep 17 00:00:00 2001 From: Nikhil Shahi Date: Thu, 4 Aug 2022 14:32:22 -0500 Subject: [PATCH] add back types, enums for now --- backend/models/api-endpoint.ts | 2 +- backend/models/api-trace.ts | 4 +- backend/src/api/get-endpoints/index.ts | 2 +- backend/src/api/log-request/index.ts | 2 +- backend/src/api/spec/index.ts | 2 +- backend/src/enums.ts | 30 ++++++++++++ backend/src/services/endpoints/index.ts | 2 +- backend/src/services/get-endpoints/index.ts | 2 +- backend/src/services/log-request/index.ts | 4 +- backend/src/services/scanner/scan.ts | 2 +- backend/src/services/spec/index.ts | 4 +- backend/src/types.ts | 53 +++++++++++++++++++++ backend/tsconfig.json | 5 +- 13 files changed, 97 insertions(+), 17 deletions(-) create mode 100644 backend/src/enums.ts create mode 100644 backend/src/types.ts diff --git a/backend/models/api-endpoint.ts b/backend/models/api-endpoint.ts index 04c94488..11cdc4b1 100644 --- a/backend/models/api-endpoint.ts +++ b/backend/models/api-endpoint.ts @@ -1,6 +1,6 @@ import { BaseEntity, Column, CreateDateColumn, Entity, OneToMany, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm"; import { MatchedDataClass } from "./matched-data-class"; -import { RestMethod } from "@common/enums"; +import { RestMethod } from "../src/enums"; @Entity() export class ApiEndpoint extends BaseEntity { diff --git a/backend/models/api-trace.ts b/backend/models/api-trace.ts index da7d5009..fc6a5a12 100644 --- a/backend/models/api-trace.ts +++ b/backend/models/api-trace.ts @@ -1,6 +1,6 @@ import { BaseEntity, Column, CreateDateColumn, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from "typeorm"; -import { Meta, PairObject } from "@common/types"; -import { RestMethod } from "@common/enums"; +import { Meta, PairObject } from "../src/types"; +import { RestMethod } from "../src/enums"; import { ApiEndpoint } from "./api-endpoint"; @Entity() diff --git a/backend/src/api/get-endpoints/index.ts b/backend/src/api/get-endpoints/index.ts index 5fd8c237..7973b687 100644 --- a/backend/src/api/get-endpoints/index.ts +++ b/backend/src/api/get-endpoints/index.ts @@ -1,6 +1,6 @@ import { Request, Response } from "express"; import { GetEndpointsService } from "../../services/get-endpoints"; -import { GetEndpointParams } from "@common/types"; +import { GetEndpointParams } from "../../types"; import ApiResponseHandler from "../../api-response-handler"; export const getEndpointsHandler = async (req: Request, res: Response) => { diff --git a/backend/src/api/log-request/index.ts b/backend/src/api/log-request/index.ts index 3fd52192..aa0b18b7 100644 --- a/backend/src/api/log-request/index.ts +++ b/backend/src/api/log-request/index.ts @@ -1,6 +1,6 @@ import { Request, Response } from "express"; import { LogRequestService } from "../../services/log-request"; -import { TraceParams } from "@common/types"; +import { TraceParams } from "../../types"; import ApiResponseHandler from "../../api-response-handler"; export const logRequestSingleHandler = async (req: Request, res: Response) => { diff --git a/backend/src/api/spec/index.ts b/backend/src/api/spec/index.ts index 72510624..4319fd6f 100644 --- a/backend/src/api/spec/index.ts +++ b/backend/src/api/spec/index.ts @@ -1,6 +1,6 @@ import { Request, Response } from "express"; import yaml from "js-yaml"; -import { JSONValue } from "@common/types"; +import { JSONValue } from "../../types"; import { SpecService } from "../../services/spec"; import ApiResponseHandler from "../../api-response-handler"; import Error400BadRequest from "../../errors/error-400-bad-request"; diff --git a/backend/src/enums.ts b/backend/src/enums.ts new file mode 100644 index 00000000..30db6015 --- /dev/null +++ b/backend/src/enums.ts @@ -0,0 +1,30 @@ +export enum RestMethod { + GET = "GET", + HEAD = "HEAD", + POST = "POST", + PUT = "PUT", + PATCH = "PATCH", + DELETE = "DELETE", + CONNECT = "CONNECT", + OPTIONS = "OPTIONS", + TRACE = "TRACE", +} + +export enum DataClass { + EMAIL = "Email", + CREDIT_CARD = "Credit Card Number", + SSN = "Social Security Number", + PHONE_NUMBER = "Phone Number", + IP_ADDRESS = "IP Address", + COORDINATE = "Geographic Coordinates", + VIN = "Vehicle Identification Number", + ADDRESS = "Address", + DOB = "Date of Birth", + DL_NUMBER = "Driver License Number", +} + +export enum RiskScore { + LOW = "low", + MEDIUM = "medium", + HIGH = "high", +} diff --git a/backend/src/services/endpoints/index.ts b/backend/src/services/endpoints/index.ts index a2fa9f5a..fe872b62 100644 --- a/backend/src/services/endpoints/index.ts +++ b/backend/src/services/endpoints/index.ts @@ -2,7 +2,7 @@ import { IsNull } from "typeorm"; import { isSuspectedParamater } from "../../utils"; import { ApiEndpoint, ApiTrace } from "../../../models"; import { AppDataSource } from "../../data-source"; -import { RestMethod } from "@common/enums"; +import { RestMethod } from "../../enums"; interface GenerateEndpoint { parameterizedPath: string; diff --git a/backend/src/services/get-endpoints/index.ts b/backend/src/services/get-endpoints/index.ts index d0a1a9eb..3a40c11e 100644 --- a/backend/src/services/get-endpoints/index.ts +++ b/backend/src/services/get-endpoints/index.ts @@ -1,5 +1,5 @@ import { FindManyOptions, FindOptionsWhere } from "typeorm"; -import { GetEndpointParams } from "@common/types"; +import { GetEndpointParams } from "../../types"; import { AppDataSource } from "../../data-source"; import { ApiEndpoint } from "../../../models"; import Error500InternalServer from "../../errors/error-500-internal-server"; diff --git a/backend/src/services/log-request/index.ts b/backend/src/services/log-request/index.ts index acbf75f2..46515d5f 100644 --- a/backend/src/services/log-request/index.ts +++ b/backend/src/services/log-request/index.ts @@ -1,8 +1,8 @@ -import { PairObject, TraceParams } from "@common/types"; +import { PairObject, TraceParams } from "../../types"; import { ApiEndpoint, ApiTrace, MatchedDataClass } from "../../../models"; import { AppDataSource } from "../../data-source"; import { ScannerService } from "../scanner/scan"; -import { DataClass } from "@common/enums"; +import { DataClass } from "../../enums"; import Error500InternalServer from "../../errors/error-500-internal-server"; export class LogRequestService { diff --git a/backend/src/services/scanner/scan.ts b/backend/src/services/scanner/scan.ts index a595bbd1..d0e9ed1a 100644 --- a/backend/src/services/scanner/scan.ts +++ b/backend/src/services/scanner/scan.ts @@ -1,4 +1,4 @@ -import { DataClass } from "@common/enums"; +import { DataClass } from "../../enums"; import { ADDRESS_REGEXP, COORDINATE_REGEXP, diff --git a/backend/src/services/spec/index.ts b/backend/src/services/spec/index.ts index 03a3f1b4..bb065d16 100644 --- a/backend/src/services/spec/index.ts +++ b/backend/src/services/spec/index.ts @@ -1,7 +1,7 @@ -import { RestMethod } from "@common/enums"; +import { RestMethod } from "../../enums"; import { ApiEndpoint } from "../../../models"; import Error400BadRequest from "../../errors/error-400-bad-request"; -import { JSONValue } from "@common/types"; +import { JSONValue } from "../../types"; export class SpecService { static async uploadNewSpec(specObject: JSONValue) { diff --git a/backend/src/types.ts b/backend/src/types.ts new file mode 100644 index 00000000..f392cd8e --- /dev/null +++ b/backend/src/types.ts @@ -0,0 +1,53 @@ +import { RestMethod, RiskScore } from "./enums"; + +export interface Meta { + incoming: boolean; + source: string; + sourcePort: string; + destination: string; + destinationPort: string; +} + +export interface PairObject { + name: string; + value: string; +} + +export interface Url { + host: string; + path: string; + parameters: PairObject[]; +} + +export interface Request { + url: Url; + headers: PairObject[]; + body: string; + method: RestMethod; +} + +export interface Response { + status: number; + headers: PairObject[]; + body: string; +} + +export interface TraceParams { + request: Request; + response: Response; + meta: Meta; +} + +export interface GetEndpointParams { + host?: string; + riskScore?: RiskScore; + offset?: number; + limit?: number; +} + +export type JSONValue = + | string + | number + | boolean + | { [x: string]: JSONValue } + | Array; diff --git a/backend/tsconfig.json b/backend/tsconfig.json index 072f5357..5abebfbb 100644 --- a/backend/tsconfig.json +++ b/backend/tsconfig.json @@ -20,10 +20,7 @@ "esModuleInterop": true, "resolveJsonModule": true, "importHelpers": true, - "baseUrl": "./src", - "paths": { - "@common/*": ["../../common/dist/*"] - } + "baseUrl": "src" }, "include": [ "src/**/*.ts",