From 8aad4a177178f25e0c63e6059ba9f3d3fc9a3af0 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sat, 8 Jun 2024 23:14:36 +0530 Subject: [PATCH 01/23] feat: import routers --- server/src/routes/index.ts | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 server/src/routes/index.ts diff --git a/server/src/routes/index.ts b/server/src/routes/index.ts new file mode 100644 index 00000000..b55bf658 --- /dev/null +++ b/server/src/routes/index.ts @@ -0,0 +1,9 @@ +import { router as record} from './record'; +import { router as workflow} from './workflow'; +import { router as storage} from './storage'; + +export { + record, + workflow, + storage, +}; From d5576a146310c5aad21b799b491a85ab7bd32840 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sat, 8 Jun 2024 23:15:32 +0530 Subject: [PATCH 02/23] chore: lint --- server/src/routes/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/src/routes/index.ts b/server/src/routes/index.ts index b55bf658..ff6f8402 100644 --- a/server/src/routes/index.ts +++ b/server/src/routes/index.ts @@ -1,6 +1,6 @@ -import { router as record} from './record'; -import { router as workflow} from './workflow'; -import { router as storage} from './storage'; +import { router as record } from './record'; +import { router as workflow } from './workflow'; +import { router as storage } from './storage'; export { record, From b5e177cd2b70a73d7739b9745120a79ede71c70b Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sat, 8 Jun 2024 23:18:20 +0530 Subject: [PATCH 03/23] feat: set record router --- server/src/routes/record.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 server/src/routes/record.ts diff --git a/server/src/routes/record.ts b/server/src/routes/record.ts new file mode 100644 index 00000000..93e8984a --- /dev/null +++ b/server/src/routes/record.ts @@ -0,0 +1,18 @@ +/** + * RESTful API endpoints handling remote browser recording sessions. + */ +import { Router } from 'express'; + +import { + initializeRemoteBrowserForRecording, + destroyRemoteBrowser, + getActiveBrowserId, + interpretWholeWorkflow, + stopRunningInterpretation, + getRemoteBrowserCurrentUrl, getRemoteBrowserCurrentTabs, +} from '../browser-management/controller' +import { chromium } from "playwright"; +import logger from "../logger"; + +export const router = Router(); + From 99080b45966ade9b9fa29dfa01846cdb8f9fe39e Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sat, 8 Jun 2024 23:19:10 +0530 Subject: [PATCH 04/23] feat: log info about rb recording session --- server/src/routes/record.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server/src/routes/record.ts b/server/src/routes/record.ts index 93e8984a..e830ef36 100644 --- a/server/src/routes/record.ts +++ b/server/src/routes/record.ts @@ -16,3 +16,11 @@ import logger from "../logger"; export const router = Router(); +/** + * Logs information about remote browser recording session. + */ +router.all('/', (req, res, next) => { + logger.log('debug',`The record API was invoked: ${req.url}`) + next() // pass control to the next handler +}) + From a0f13e2c7e359e588a125c3b0a7fa5649e716b7e Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sat, 8 Jun 2024 23:19:31 +0530 Subject: [PATCH 05/23] feat: start RB record session --- server/src/routes/record.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/server/src/routes/record.ts b/server/src/routes/record.ts index e830ef36..dbac1646 100644 --- a/server/src/routes/record.ts +++ b/server/src/routes/record.ts @@ -24,3 +24,17 @@ router.all('/', (req, res, next) => { next() // pass control to the next handler }) +/** + * GET endpoint for starting the remote browser recording session. + * returns session's id + */ +router.get('/start', (req, res) => { + const id = initializeRemoteBrowserForRecording({ + browser: chromium, + launchOptions: { + headless: true, + } + }); + return res.send(id); +}); + From e5d2f06f91018dffadbdd1de7af0c170bcb965ce Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sun, 9 Jun 2024 00:36:12 +0530 Subject: [PATCH 06/23] feat: accept browser launch options --- server/src/routes/record.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/src/routes/record.ts b/server/src/routes/record.ts index dbac1646..272ac26f 100644 --- a/server/src/routes/record.ts +++ b/server/src/routes/record.ts @@ -38,3 +38,12 @@ router.get('/start', (req, res) => { return res.send(id); }); + +router.post('/start', (req, res) => { + const id = initializeRemoteBrowserForRecording({ + browser: chromium, + launchOptions: req.body, + }); + return res.send(id); +}); + From 57adb06a44c3b1166492c31a251c63ac0dc887f5 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sun, 9 Jun 2024 00:36:36 +0530 Subject: [PATCH 07/23] docs: RB launch options --- server/src/routes/record.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/src/routes/record.ts b/server/src/routes/record.ts index 272ac26f..3676e4d5 100644 --- a/server/src/routes/record.ts +++ b/server/src/routes/record.ts @@ -38,7 +38,10 @@ router.get('/start', (req, res) => { return res.send(id); }); - +/** + * POST endpoint for starting the remote browser recording session accepting browser launch options. + * returns session's id + */ router.post('/start', (req, res) => { const id = initializeRemoteBrowserForRecording({ browser: chromium, From aabbafc4e7940c9a4a947e4ab0d7dfc068ba638f Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sun, 9 Jun 2024 00:37:11 +0530 Subject: [PATCH 08/23] feat: terminate RB record session --- server/src/routes/record.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/src/routes/record.ts b/server/src/routes/record.ts index 3676e4d5..7c157291 100644 --- a/server/src/routes/record.ts +++ b/server/src/routes/record.ts @@ -50,3 +50,12 @@ router.post('/start', (req, res) => { return res.send(id); }); +/** + * GET endpoint for terminating the remote browser recording session. + * returns whether the termination was successful + */ +router.get('/stop/:browserId', async (req, res) => { + const success = await destroyRemoteBrowser(req.params.browserId); + return res.send(success); +}); + From 06ac9eccbeb0c3f536828091a0871de07f4b8869 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sun, 9 Jun 2024 00:37:35 +0530 Subject: [PATCH 09/23] feat: get id of active RB --- server/src/routes/record.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/src/routes/record.ts b/server/src/routes/record.ts index 7c157291..79ce2f73 100644 --- a/server/src/routes/record.ts +++ b/server/src/routes/record.ts @@ -59,3 +59,10 @@ router.get('/stop/:browserId', async (req, res) => { return res.send(success); }); +/** + * GET endpoint for getting the id of the active remote browser. + */ +router.get('/active', (req, res) => { + const id = getActiveBrowserId(); + return res.send(id); +}); From 0a3d334aa8a7e765f4abba23a464b5ca0f0c1ac5 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sun, 9 Jun 2024 00:37:55 +0530 Subject: [PATCH 10/23] feat: get current url of active RB --- server/src/routes/record.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/server/src/routes/record.ts b/server/src/routes/record.ts index 79ce2f73..0c27ceec 100644 --- a/server/src/routes/record.ts +++ b/server/src/routes/record.ts @@ -66,3 +66,16 @@ router.get('/active', (req, res) => { const id = getActiveBrowserId(); return res.send(id); }); + +/** + * GET endpoint for getting the current url of the active remote browser. + */ +router.get('/active/url', (req, res) => { + const id = getActiveBrowserId(); + if (id) { + const url = getRemoteBrowserCurrentUrl(id); + return res.send(url); + } + return res.send(null); +}); + From 5d0f7ef09c793f32be9467009b2fa2820687ac06 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sun, 9 Jun 2024 00:38:16 +0530 Subject: [PATCH 11/23] feat: get crennt tabs of active RB --- server/src/routes/record.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server/src/routes/record.ts b/server/src/routes/record.ts index 0c27ceec..51085a01 100644 --- a/server/src/routes/record.ts +++ b/server/src/routes/record.ts @@ -79,3 +79,15 @@ router.get('/active/url', (req, res) => { return res.send(null); }); +/** + * GET endpoint for getting the current tabs of the active remote browser. + */ +router.get('/active/tabs', (req, res) => { + const id = getActiveBrowserId(); + if (id) { + const hosts = getRemoteBrowserCurrentTabs(id); + return res.send(hosts); + } + return res.send([]); +}); + From a8d2a1ee808e0afce483994fac27cd5180965ac8 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sun, 9 Jun 2024 00:39:18 +0530 Subject: [PATCH 12/23] feat: interpret currently generated workflow --- server/src/routes/record.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/server/src/routes/record.ts b/server/src/routes/record.ts index 51085a01..816349f7 100644 --- a/server/src/routes/record.ts +++ b/server/src/routes/record.ts @@ -91,3 +91,16 @@ router.get('/active/tabs', (req, res) => { return res.send([]); }); +/** + * GET endpoint for starting an interpretation of the currently generated workflow. + */ +router.get('/interpret', async (req, res) => { + try { + await interpretWholeWorkflow(); + return res.send('interpretation done'); + } catch (e) { + return res.send('interpretation done'); + return res.status(400); + } +}); + From 3ccf3d247f4f6d5c71853e2ebdaf619a288fa021 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sun, 9 Jun 2024 00:39:57 +0530 Subject: [PATCH 13/23] feat: stop ongoing interpretation --- server/src/routes/record.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/src/routes/record.ts b/server/src/routes/record.ts index 816349f7..5fc9428f 100644 --- a/server/src/routes/record.ts +++ b/server/src/routes/record.ts @@ -104,3 +104,10 @@ router.get('/interpret', async (req, res) => { } }); +/** + * GET endpoint for stopping an ongoing interpretation of the currently generated workflow. + */ +router.get('/interpret/stop', async (req, res) => { + await stopRunningInterpretation(); + return res.send('interpretation stopped'); +}); From 48717ce77bdf709798e406db3b4e966ad8ba34a8 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sun, 9 Jun 2024 00:40:13 +0530 Subject: [PATCH 14/23] chore: lint --- server/src/routes/record.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/routes/record.ts b/server/src/routes/record.ts index 5fc9428f..da62bf8e 100644 --- a/server/src/routes/record.ts +++ b/server/src/routes/record.ts @@ -20,7 +20,7 @@ export const router = Router(); * Logs information about remote browser recording session. */ router.all('/', (req, res, next) => { - logger.log('debug',`The record API was invoked: ${req.url}`) + logger.log('debug', `The record API was invoked: ${req.url}`) next() // pass control to the next handler }) From e03b482a119779ce7236ff78099fa454dac8c4b7 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sun, 9 Jun 2024 00:42:51 +0530 Subject: [PATCH 15/23] feat: init workflow router --- server/src/routes/workflow.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 server/src/routes/workflow.ts diff --git a/server/src/routes/workflow.ts b/server/src/routes/workflow.ts new file mode 100644 index 00000000..c44a5d79 --- /dev/null +++ b/server/src/routes/workflow.ts @@ -0,0 +1,11 @@ +/** + * RESTful API endpoints handling currently generated workflow management. + */ + +import { Router } from 'express'; +import logger from "../logger"; +import { browserPool } from "../server"; +import { readFile } from "../workflow-management/storage"; + +export const router = Router(); + From c79b8c73f679f0c8fe75b8642dd69d9b02761dcd Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sun, 9 Jun 2024 00:43:11 +0530 Subject: [PATCH 16/23] feat: log workflow API info --- server/src/routes/workflow.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/src/routes/workflow.ts b/server/src/routes/workflow.ts index c44a5d79..0a3e87f8 100644 --- a/server/src/routes/workflow.ts +++ b/server/src/routes/workflow.ts @@ -9,3 +9,10 @@ import { readFile } from "../workflow-management/storage"; export const router = Router(); +/** + * Logs information about workflow API. + */ +router.all('/', (req, res, next) => { + logger.log('debug',`The workflow API was invoked: ${req.url}`) + next() // pass control to the next handler +}) From 527dbe7dc1a33b60b751af6ec676a9fa7da6b939 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sun, 9 Jun 2024 00:43:46 +0530 Subject: [PATCH 17/23] feat: get record linked to RB instance --- server/src/routes/workflow.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/server/src/routes/workflow.ts b/server/src/routes/workflow.ts index 0a3e87f8..d40c1856 100644 --- a/server/src/routes/workflow.ts +++ b/server/src/routes/workflow.ts @@ -16,3 +16,17 @@ router.all('/', (req, res, next) => { logger.log('debug',`The workflow API was invoked: ${req.url}`) next() // pass control to the next handler }) + +/** + * GET endpoint for a recording linked to a remote browser instance. + * returns session's id + */ +router.get('/:browserId', (req, res) => { + const activeBrowser = browserPool.getRemoteBrowser(req.params.browserId); + let workflowFile = null; + if (activeBrowser && activeBrowser.generator) { + workflowFile = activeBrowser.generator.getWorkflowFile(); + } + return res.send(workflowFile); +}); + From b573453d2d61f724213960cb3036f33c1bfd6f46 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sun, 9 Jun 2024 00:45:00 +0530 Subject: [PATCH 18/23] feat: return param array of recording associated with browserId --- server/src/routes/workflow.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server/src/routes/workflow.ts b/server/src/routes/workflow.ts index d40c1856..195921a3 100644 --- a/server/src/routes/workflow.ts +++ b/server/src/routes/workflow.ts @@ -30,3 +30,15 @@ router.get('/:browserId', (req, res) => { return res.send(workflowFile); }); +/** + * Get endpoint returning the parameter array of the recording associated with the browserId browser instance. + */ +router.get('/params/:browserId', (req, res) => { + const activeBrowser = browserPool.getRemoteBrowser(req.params.browserId); + let params = null; + if (activeBrowser && activeBrowser.generator) { + params = activeBrowser.generator.getParams(); + } + return res.send(params); +}); + From 7774d8a72a280261b21f781f513749a221580ce6 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sun, 9 Jun 2024 00:45:32 +0530 Subject: [PATCH 19/23] feat: del pair from workflow --- server/src/routes/workflow.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/server/src/routes/workflow.ts b/server/src/routes/workflow.ts index 195921a3..c44decf5 100644 --- a/server/src/routes/workflow.ts +++ b/server/src/routes/workflow.ts @@ -42,3 +42,19 @@ router.get('/params/:browserId', (req, res) => { return res.send(params); }); +/** + * DELETE endpoint for deleting a pair from the generated workflow. + */ +router.delete('/pair/:index', (req, res) => { + const id = browserPool.getActiveBrowserId(); + if (id) { + const browser = browserPool.getRemoteBrowser(id); + if (browser) { + browser.generator?.removePairFromWorkflow(parseInt(req.params.index)); + const workflowFile = browser.generator?.getWorkflowFile(); + return res.send(workflowFile); + } + } + return res.send(null); +}); + From 6607508add51f75c29dc7923ffb12031a9c4e225 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sun, 9 Jun 2024 00:45:56 +0530 Subject: [PATCH 20/23] feat: add pair to workflow --- server/src/routes/workflow.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/server/src/routes/workflow.ts b/server/src/routes/workflow.ts index c44decf5..6572b02f 100644 --- a/server/src/routes/workflow.ts +++ b/server/src/routes/workflow.ts @@ -58,3 +58,23 @@ router.delete('/pair/:index', (req, res) => { return res.send(null); }); +/** + * POST endpoint for adding a pair to the generated workflow. + */ +router.post('/pair/:index', (req, res) => { + const id = browserPool.getActiveBrowserId(); + if (id) { + const browser = browserPool.getRemoteBrowser(id); + logger.log('debug', `Adding pair to workflow`); + if (browser) { + logger.log('debug', `Adding pair to workflow: ${JSON.stringify(req.body)}`); + if (req.body.pair) { + browser.generator?.addPairToWorkflow(parseInt(req.params.index), req.body.pair); + const workflowFile = browser.generator?.getWorkflowFile(); + return res.send(workflowFile); + } + } + } + return res.send(null); +}); + From 5ad8d3ab4d21ff3ba06501ec27496ee3edfbe92a Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sun, 9 Jun 2024 00:46:15 +0530 Subject: [PATCH 21/23] feat: update pair in workflow --- server/src/routes/workflow.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/server/src/routes/workflow.ts b/server/src/routes/workflow.ts index 6572b02f..f2730914 100644 --- a/server/src/routes/workflow.ts +++ b/server/src/routes/workflow.ts @@ -78,3 +78,23 @@ router.post('/pair/:index', (req, res) => { return res.send(null); }); +/** + * PUT endpoint for updating a pair in the generated workflow. + */ +router.put('/pair/:index', (req, res) => { + const id = browserPool.getActiveBrowserId(); + if (id) { + const browser = browserPool.getRemoteBrowser(id); + logger.log('debug', `Updating pair in workflow`); + if (browser) { + logger.log('debug', `New value: ${JSON.stringify(req.body)}`); + if (req.body.pair) { + browser.generator?.updatePairInWorkflow(parseInt(req.params.index), req.body.pair); + const workflowFile = browser.generator?.getWorkflowFile(); + return res.send(workflowFile); + } + } + } + return res.send(null); +}); + From c14eb7995e4170d886710d27e402440f81f4a469 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sun, 9 Jun 2024 00:46:45 +0530 Subject: [PATCH 22/23] feat: update currently generated workflow file from the storage one --- server/src/routes/workflow.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/server/src/routes/workflow.ts b/server/src/routes/workflow.ts index f2730914..5efb0a1e 100644 --- a/server/src/routes/workflow.ts +++ b/server/src/routes/workflow.ts @@ -98,3 +98,26 @@ router.put('/pair/:index', (req, res) => { return res.send(null); }); +/** + * PUT endpoint for updating the currently generated workflow file from the one in the storage. + */ +router.put('/:browserId/:fileName', async (req, res) => { + try { + const browser = browserPool.getRemoteBrowser(req.params.browserId); + logger.log('debug', `Updating workflow file`); + if (browser && browser.generator) { + const recording = await readFile(`./../storage/recordings/${req.params.fileName}.waw.json`) + const parsedRecording = JSON.parse(recording); + if (parsedRecording.recording) { + browser.generator?.updateWorkflowFile(parsedRecording.recording, parsedRecording.recording_meta); + const workflowFile = browser.generator?.getWorkflowFile(); + return res.send(workflowFile); + } + } + return res.send(null); + } catch (e) { + const {message} = e as Error; + logger.log('info', `Error while reading a recording with name: ${req.params.fileName}.waw.json`); + return res.send(null); + } +}); From bd9ef281555c6c2c283e5f91cda909aa1fa6b467 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sun, 9 Jun 2024 00:46:59 +0530 Subject: [PATCH 23/23] chore: lint --- server/src/routes/workflow.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/routes/workflow.ts b/server/src/routes/workflow.ts index 5efb0a1e..73d8f490 100644 --- a/server/src/routes/workflow.ts +++ b/server/src/routes/workflow.ts @@ -13,7 +13,7 @@ export const router = Router(); * Logs information about workflow API. */ router.all('/', (req, res, next) => { - logger.log('debug',`The workflow API was invoked: ${req.url}`) + logger.log('debug', `The workflow API was invoked: ${req.url}`) next() // pass control to the next handler }) @@ -116,7 +116,7 @@ router.put('/:browserId/:fileName', async (req, res) => { } return res.send(null); } catch (e) { - const {message} = e as Error; + const { message } = e as Error; logger.log('info', `Error while reading a recording with name: ${req.params.fileName}.waw.json`); return res.send(null); }