From f1561310d358dac5922bd4bd2692e906151564d9 Mon Sep 17 00:00:00 2001 From: Ian Bouchard Date: Wed, 8 Jan 2025 02:18:03 -0500 Subject: [PATCH] Ib cleanup types (#3) * Add utils file * Add back Response type * Move App.vue logic to own file --- packages/frontend/src/data/response.ts | 10 - .../src/services/InteractshService.ts | 11 +- packages/frontend/src/types.ts | 11 + packages/frontend/src/utils.ts | 13 ++ packages/frontend/src/views/App.vue | 191 ++---------------- packages/frontend/src/views/useLogic.ts | 187 +++++++++++++++++ 6 files changed, 232 insertions(+), 191 deletions(-) delete mode 100644 packages/frontend/src/data/response.ts create mode 100644 packages/frontend/src/utils.ts create mode 100644 packages/frontend/src/views/useLogic.ts diff --git a/packages/frontend/src/data/response.ts b/packages/frontend/src/data/response.ts deleted file mode 100644 index 151c5d8..0000000 --- a/packages/frontend/src/data/response.ts +++ /dev/null @@ -1,10 +0,0 @@ -interface Response { - protocol: string; - uniqueId: string; // Converted to camelCase for consistency - fullId: string; // Converted to camelCase for consistency - qType: string; // Query type - rawRequest: string; - rawResponse: string; - remoteAddress: string; - timestamp: string; // Use Date type for parsing if necessary -} diff --git a/packages/frontend/src/services/InteractshService.ts b/packages/frontend/src/services/InteractshService.ts index b3d56c0..0e763bd 100644 --- a/packages/frontend/src/services/InteractshService.ts +++ b/packages/frontend/src/services/InteractshService.ts @@ -3,6 +3,7 @@ import { v4 as uuidv4 } from "uuid"; import { type Ref, ref } from "vue"; import { cryptoService } from "@/services/CryptoService"; +import { generateRandomID } from "@/utils"; enum State { Idle = 0, @@ -267,16 +268,6 @@ export const useClientService = () => { return JSON.stringify(session, null, 2); // Return JSON string for download or storage }; - // Generate a random ID - const generateRandomID = (length: number): string => { - const chars = "abcdefghijklmnopqrstuvwxyz0123456789"; - let id = ""; - for (let i = 0; i < length; i++) { - id += chars.charAt(Math.floor(Math.random() * chars.length)); - } - return id; - }; - // Generate a new interaction URL const generateUrl = (): string => { if ( diff --git a/packages/frontend/src/types.ts b/packages/frontend/src/types.ts index 2773e5b..5824b0e 100644 --- a/packages/frontend/src/types.ts +++ b/packages/frontend/src/types.ts @@ -2,3 +2,14 @@ import type { Caido } from "@caido/sdk-frontend"; import type { API } from "backend"; export type FrontendSDK = Caido; + +export type Response = { + protocol: string; + uniqueId: string; // Converted to camelCase for consistency + fullId: string; // Converted to camelCase for consistency + qType: string; // Query type + rawRequest: string; + rawResponse: string; + remoteAddress: string; + timestamp: string; // Use Date type for parsing if necessary +}; diff --git a/packages/frontend/src/utils.ts b/packages/frontend/src/utils.ts new file mode 100644 index 0000000..c64076c --- /dev/null +++ b/packages/frontend/src/utils.ts @@ -0,0 +1,13 @@ +/** + * Generate a random ID + * @param length - The length of the ID + * @returns The random ID + */ +export const generateRandomID = (length: number): string => { + const chars = "abcdefghijklmnopqrstuvwxyz0123456789"; + let id = ""; + for (let i = 0; i < length; i++) { + id += chars.charAt(Math.floor(Math.random() * chars.length)); + } + return id; +}; diff --git a/packages/frontend/src/views/App.vue b/packages/frontend/src/views/App.vue index 60418f6..bdc689e 100644 --- a/packages/frontend/src/views/App.vue +++ b/packages/frontend/src/views/App.vue @@ -1,173 +1,26 @@ @@ -195,11 +48,7 @@ onMounted(() => { style="width: 200px" @click="onGenerateClick" /> -