Skip to content

Commit

Permalink
add back types, enums for now
Browse files Browse the repository at this point in the history
  • Loading branch information
NikhilShahi committed Aug 4, 2022
1 parent 365fd1f commit a71e2a8
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 17 deletions.
2 changes: 1 addition & 1 deletion backend/models/api-endpoint.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions backend/models/api-trace.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
2 changes: 1 addition & 1 deletion backend/src/api/get-endpoints/index.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/api/log-request/index.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/api/spec/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
30 changes: 30 additions & 0 deletions backend/src/enums.ts
Original file line number Diff line number Diff line change
@@ -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",
}
2 changes: 1 addition & 1 deletion backend/src/services/endpoints/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/services/get-endpoints/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
4 changes: 2 additions & 2 deletions backend/src/services/log-request/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/services/scanner/scan.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DataClass } from "@common/enums";
import { DataClass } from "../../enums";
import {
ADDRESS_REGEXP,
COORDINATE_REGEXP,
Expand Down
4 changes: 2 additions & 2 deletions backend/src/services/spec/index.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
53 changes: 53 additions & 0 deletions backend/src/types.ts
Original file line number Diff line number Diff line change
@@ -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<JSONValue>;
5 changes: 1 addition & 4 deletions backend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
"esModuleInterop": true,
"resolveJsonModule": true,
"importHelpers": true,
"baseUrl": "./src",
"paths": {
"@common/*": ["../../common/dist/*"]
}
"baseUrl": "src"
},
"include": [
"src/**/*.ts",
Expand Down

0 comments on commit a71e2a8

Please sign in to comment.