From 202383d23357e7083891e126afa7a3e7d6f59c8d Mon Sep 17 00:00:00 2001 From: JAMES FUQIAN Date: Fri, 25 Nov 2022 08:10:10 -0800 Subject: [PATCH] cleanup un-used artifacts and fix linting, sync with changed CI check workflow file. --- server/build.ts | 63 --------------------------- server/index.ts | 104 +++++++++++++++++++++++--------------------- server/package.json | 2 +- 3 files changed, 55 insertions(+), 114 deletions(-) delete mode 100644 server/build.ts diff --git a/server/build.ts b/server/build.ts deleted file mode 100644 index ee24868..0000000 --- a/server/build.ts +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Remove old files, copy front-end ones. - */ - -import fs from 'fs-extra'; -import Logger from 'jet-logger'; -import childProcess from 'child_process'; - -// Setup logger -const logger = new Logger(); -logger.timestamp = false; - - - - -(async () => { - try { - // Remove current build - await remove('./dist/'); - // Copy front-end files - await copy('./src/public', './dist/public'); - await copy('./src/views', './dist/views'); - // Copy production env file - await copy('./src/pre-start/env/production.env', './dist/pre-start/env/production.env'); - // Copy back-end files - await exec('tsc --build tsconfig.prod.json', './') - } catch (err) { - logger.err(err); - } -})(); - - -function remove(loc: string): Promise { - return new Promise((res, rej) => { - return fs.remove(loc, (err) => { - return (!!err ? rej(err) : res()); - }); - }); -} - - -function copy(src: string, dest: string): Promise { - return new Promise((res, rej) => { - return fs.copy(src, dest, (err) => { - return (!!err ? rej(err) : res()); - }); - }); -} - - -function exec(cmd: string, loc: string): Promise { - return new Promise((res, rej) => { - return childProcess.exec(cmd, {cwd: loc}, (err, stdout, stderr) => { - if (!!stdout) { - logger.info(stdout); - } - if (!!stderr) { - logger.warn(stderr); - } - return (!!err ? rej(err) : res()); - }); - }); -} diff --git a/server/index.ts b/server/index.ts index 1980877..84479e4 100644 --- a/server/index.ts +++ b/server/index.ts @@ -45,59 +45,62 @@ app.get("/api/authorize/authurl", (req: Request, res: Response) => { }); // auth flow: oauth2 call back -app.get("/api/bluebutton/callback", async (req: Request, res: Response) => { - if (typeof req.query.error === "string") { - // clear all cached claims eob data since the bene has denied access - // for the application - clearBB2Data(); - let errMsg = req.query.error; - if (req.query.error === BENE_DENIED_ACCESS) { - errMsg = FE_MSG_ACCESS_DENIED; - } - loggedInUser.eobData = {"message": errMsg}; - process.stdout.write(errMsg + '\n'); - } else { - if ( - typeof req.query.code === "string" && - typeof req.query.state === "string" - ) { - try { - authToken = await bb.getAuthorizationToken( - authData, - req.query.code, - req.query.state - ); - // data flow: after access granted - // the app logic can fetch the beneficiary's data in app specific ways: - // e.g. download EOB periodically etc. - // access token can expire, SDK automatically refresh access token when that happens. - const eobResults = await bb.getExplanationOfBenefitData(authToken); - authToken = eobResults.token; // in case authToken got refreshed during fhir call - - loggedInUser.authToken = authToken; - - loggedInUser.eobData = eobResults.response?.data; - } catch (e) { - loggedInUser.eobData = {}; - process.stdout.write(ERR_QUERY_EOB + '\n'); - process.stdout.write("Exception: " + e + '\n'); +app.get("/api/bluebutton/callback", (req: Request, res: Response) => { + (async (req: Request, res: Response) => { + if (typeof req.query.error === "string") { + // clear all cached claims eob data since the bene has denied access + // for the application + clearBB2Data(); + let errMsg = req.query.error; + if (req.query.error === BENE_DENIED_ACCESS) { + errMsg = FE_MSG_ACCESS_DENIED; + } + loggedInUser.eobData = {"message": errMsg}; + process.stdout.write(errMsg + '\n'); + } else { + if ( + typeof req.query.code === "string" && + typeof req.query.state === "string" + ) { + try { + authToken = await bb.getAuthorizationToken( + authData, + req.query.code, + req.query.state + ); + // data flow: after access granted + // the app logic can fetch the beneficiary's data in app specific ways: + // e.g. download EOB periodically etc. + // access token can expire, SDK automatically refresh access token when that happens. + const eobResults = await bb.getExplanationOfBenefitData(authToken); + authToken = eobResults.token; // in case authToken got refreshed during fhir call + + loggedInUser.authToken = authToken; + + loggedInUser.eobData = eobResults.response?.data; + } catch (e) { + loggedInUser.eobData = {}; + process.stdout.write(ERR_QUERY_EOB + '\n'); + process.stdout.write("Exception: " + e + '\n'); + } + } else { + clearBB2Data(); + process.stdout.write(ERR_MISSING_AUTH_CODE + '\n'); + process.stdout.write("OR" + '\n'); + process.stdout.write(ERR_MISSING_STATE + '\n'); + process.stdout.write("AUTH CODE: " + req.query.code + '\n'); + process.stdout.write("STATE: " + req.query.state + '\n'); + } + } + const fe_redirect_url = + process.env.SELENIUM_TESTS ? 'http://client:3000' : 'http://localhost:3000'; + res.redirect(fe_redirect_url); } - } else { - clearBB2Data(); - process.stdout.write(ERR_MISSING_AUTH_CODE + '\n'); - process.stdout.write("OR" + '\n'); - process.stdout.write(ERR_MISSING_STATE + '\n'); - process.stdout.write("AUTH CODE: " + req.query.code + '\n'); - process.stdout.write("STATE: " + req.query.state + '\n'); - } - } - const fe_redirect_url = - process.env.SELENIUM_TESTS ? 'http://client:3000' : 'http://localhost:3000'; - res.redirect(fe_redirect_url); + )(req, res); }); // data flow: front end fetch eob -app.get("/api/data/benefit", async (req: Request, res: Response) => { +app.get("/api/data/benefit", (req: Request, res: Response) => { if (loggedInUser.eobData) { res.json(loggedInUser.eobData); } @@ -105,5 +108,6 @@ app.get("/api/data/benefit", async (req: Request, res: Response) => { const port = 3001; app.listen(port, () => { - console.log(`[server]: Server is running at https://localhost:${port}`); + process.stdout.write(`[server]: Server is running at https://localhost:${port}`); + process.stdout.write("\n"); }); diff --git a/server/package.json b/server/package.json index 39e98e2..783bd0c 100644 --- a/server/package.json +++ b/server/package.json @@ -5,7 +5,7 @@ "author": "CMS Blue Button API team", "license": "MIT", "scripts": { - "lint": "eslint --fix --ext .ts --ext .tsx .", + "lint": "eslint --fix --ext .ts --ext .tsx index.ts", "start": "node ./node_modules/.bin/ts-node -r tsconfig-paths/register .", "start:debug": "node --inspect=0.0.0.0:9229 ./node_modules/.bin/ts-node -r tsconfig-paths/register ." },