From bad874bfc2e877fd125af232088d464b656ca665 Mon Sep 17 00:00:00 2001 From: Timothy Baumgartner Date: Wed, 23 Mar 2022 23:49:43 -0700 Subject: [PATCH] Add Bryan as contributor. Add lerna config and scripts. Fix unnecessary trailing filetype for package resolution in server.ts. Update Husky script. Clean up lint issues. --- .husky/pre-commit | 2 +- lerna.json | 6 + package.json | 43 ++++--- .../client/src/components/Toaster/Toaster.tsx | 4 +- packages/client/src/components/authContext.ts | 2 + packages/client/src/routes/Login/Login.tsx | 2 +- packages/service/package.json | 116 +++++++++--------- packages/service/src/program.ts | 6 +- packages/service/src/utilities/alerter.ts | 10 +- packages/service/src/utilities/server.ts | 6 +- 10 files changed, 108 insertions(+), 89 deletions(-) create mode 100644 lerna.json diff --git a/.husky/pre-commit b/.husky/pre-commit index 8eab92d..562d3a6 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,4 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" -pushd .; cd client; npm run lint; popd; pushd .; cd service; npm run lint; popd; +pushd .; cd packages/client; npm run lint; popd; pushd .; cd packages/service; npm run lint; popd; diff --git a/lerna.json b/lerna.json new file mode 100644 index 0000000..d6707ca --- /dev/null +++ b/lerna.json @@ -0,0 +1,6 @@ +{ + "packages": [ + "packages/*" + ], + "version": "0.0.0" +} diff --git a/package.json b/package.json index 97fcad1..ff136f4 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,29 @@ { - "name": "iotsec", - "version": "1.0.0", - "description": "An IOT security system using a Particle Photon and a Raspberry Pi", - "repository": { - "type": "git", - "url": "https://github.com/timothy-b/IOT-SEC" - }, - "keywords": [ - "IOT", - "security" - ], - "author": "Timothy Baumgartner", - "license": "MIT", - "devDependencies": { - "lerna": "^4.0.0" - } + "name": "iotsec", + "version": "1.0.0", + "description": "An IOT security system using a Particle Photon and a Raspberry Pi", + "repository": { + "type": "git", + "url": "https://github.com/timothy-b/IOT-SEC" + }, + "keywords": [ + "IOT", + "security" + ], + "author": { + "name": "Timothy Baumgartner" + }, + "contributors": [ + { + "name": "Bryan Kenote" + } + ], + "license": "MIT", + "devDependencies": { + "lerna": "^4.0.0" + }, + "scripts": { + "build": "lerna run build", + "install": "lerna exec --stream -- npm install" + } } diff --git a/packages/client/src/components/Toaster/Toaster.tsx b/packages/client/src/components/Toaster/Toaster.tsx index 41a616b..36d0304 100644 --- a/packages/client/src/components/Toaster/Toaster.tsx +++ b/packages/client/src/components/Toaster/Toaster.tsx @@ -1,5 +1,5 @@ import { h } from 'preact'; -import { useCallback, useImperativeHandle, useRef, useState } from 'preact/hooks'; +import { useCallback, useImperativeHandle, useState } from 'preact/hooks'; import { forwardRef } from 'preact/compat'; import style from './style.css'; @@ -21,7 +21,7 @@ const Toaster = forwardRef(({ defaultTimeout = 5000 }, re {message} ); - }, []); + }, [defaultTimeout]); useImperativeHandle(ref, () => ({ makeToast(message: string) { diff --git a/packages/client/src/components/authContext.ts b/packages/client/src/components/authContext.ts index 2f1b245..dfc3ec9 100644 --- a/packages/client/src/components/authContext.ts +++ b/packages/client/src/components/authContext.ts @@ -1,4 +1,6 @@ import { createContext } from 'preact'; + +// eslint-disable-next-line no-spaced-func export default createContext<{ authHeader: string; setAuthHeader: (authentication: string) => void; diff --git a/packages/client/src/routes/Login/Login.tsx b/packages/client/src/routes/Login/Login.tsx index a4c6dc9..ca39d80 100644 --- a/packages/client/src/routes/Login/Login.tsx +++ b/packages/client/src/routes/Login/Login.tsx @@ -32,7 +32,7 @@ const Login: FunctionalComponent = ({ onFail }) => { return onFail?.(); } setAuthHeader(encoded); - }, [username, password]); + }, [username, password, onFail, setAuthHeader]); return (
diff --git a/packages/service/package.json b/packages/service/package.json index ca76844..b1b5b6b 100644 --- a/packages/service/package.json +++ b/packages/service/package.json @@ -1,63 +1,63 @@ { - "name": "iotsec-service", - "version": "1.0.0", - "description": "An IOT security system using a Particle Photon and a Raspberry Pi", + "name": "iotsec-service", + "version": "1.0.0", + "description": "An IOT security system using a Particle Photon and a Raspberry Pi", "type": "module", - "exports": "./dist/program.js", + "exports": "./dist/program.js", "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + "node": "^>=16.0.0" }, - "dependencies": { - "arpscan": "^0.6.0", - "bunyan": "^1.8.12", - "emailjs": "^3.7.0", - "express": "^4.17.1", - "lowdb": "^3.0.0", - "uuid-random": "^1.3.2" - }, - "devDependencies": { - "@types/async": "^3.0.2", - "@types/bunyan": "^1.8.6", - "@types/express": "^4.17.9", - "@types/jest": "^26.0.19", - "@types/node": "^12.7.12", - "@typescript-eslint/parser": "^3.10.1", - "eslint": "^5.16.0", - "eslint-config-faithlife": "^8.1.0", - "eslint-plugin-import": "^2.22.1", - "eslint-plugin-jest": "^24.1.3", - "husky": "^4.3.6", - "jest": "^26.6.3", - "prettier": "^1.19.1", - "ts-jest": "^26.4.4", - "ts-node": "^9.1.1", - "typescript": "^3.9.7" - }, - "scripts": { - "build": "./node_modules/.bin/tsc", - "watch": "./node_modules/.bin/tsc --watch", - "depcheck": "npx depcheck", - "start": "node ./dist/program.js", - "stop": "ps aux | grep node | grep iot-sec | awk '{ print $2 }' | xargs sudo kill", - "lint": "eslint ./src/**/*.ts --ignore-pattern **/dist --ignore-pattern **/node_modules", - "lint:windows": ".\\node_modules\\.bin\\eslint ./src/**/*.{js,ts} --ignore-pattern **/dist --ignore-pattern **/node_modules", - "test": "node ./node_modules/jest/bin/jest.js" - }, - "eslintConfig": { - "extends": [ - "faithlife/base", - "plugin:import/typescript" - ], - "plugins": [ - "jest" - ], - "env": { - "jest/globals": true - } - }, - "husky": { - "hooks": { - "pre-commit": "npm run lint" - } - } + "dependencies": { + "arpscan": "^0.6.0", + "bunyan": "^1.8.12", + "emailjs": "^3.7.0", + "express": "^4.17.1", + "lowdb": "^3.0.0", + "uuid-random": "^1.3.2" + }, + "devDependencies": { + "@types/async": "^3.0.2", + "@types/bunyan": "^1.8.6", + "@types/express": "^4.17.9", + "@types/jest": "^26.0.19", + "@types/node": "^12.7.12", + "@typescript-eslint/parser": "^3.10.1", + "eslint": "^5.16.0", + "eslint-config-faithlife": "^8.1.0", + "eslint-plugin-import": "^2.22.1", + "eslint-plugin-jest": "^24.1.3", + "husky": "^4.3.6", + "jest": "^26.6.3", + "prettier": "^1.19.1", + "ts-jest": "^26.4.4", + "ts-node": "^9.1.1", + "typescript": "^3.9.7" + }, + "scripts": { + "build": "./node_modules/.bin/tsc", + "watch": "./node_modules/.bin/tsc --watch", + "depcheck": "npx depcheck", + "start": "node ./dist/program.js", + "stop": "ps aux | grep node | grep iot-sec | awk '{ print $2 }' | xargs sudo kill", + "lint": "eslint ./src/**/*.ts --ignore-pattern **/dist --ignore-pattern **/node_modules", + "lint:windows": ".\\node_modules\\.bin\\eslint ./src/**/*.{js,ts} --ignore-pattern **/dist --ignore-pattern **/node_modules", + "test": "node ./node_modules/jest/bin/jest.js" + }, + "eslintConfig": { + "extends": [ + "faithlife/base", + "plugin:import/typescript" + ], + "plugins": [ + "jest" + ], + "env": { + "jest/globals": true + } + }, + "husky": { + "hooks": { + "pre-commit": "npm run lint" + } + } } diff --git a/packages/service/src/program.ts b/packages/service/src/program.ts index 0de7a20..78dc71b 100644 --- a/packages/service/src/program.ts +++ b/packages/service/src/program.ts @@ -1,7 +1,7 @@ import { createLogger } from 'bunyan'; -import Config from './config.js'; -import { createServer } from './utilities/server.js'; -import db from './utilities/db.js'; +import Config from './config'; +import { createServer } from './utilities/server'; +import db from './utilities/db'; function main() { const { bunyan, ...rest } = Config; diff --git a/packages/service/src/utilities/alerter.ts b/packages/service/src/utilities/alerter.ts index 0373178..84987bb 100644 --- a/packages/service/src/utilities/alerter.ts +++ b/packages/service/src/utilities/alerter.ts @@ -1,11 +1,11 @@ import * as Bunyan from 'bunyan'; -import { AlertType, IConfig } from '../types/IConfig.js'; +import { AlertType, IConfig } from '../types/IConfig'; import { IDevice } from '../types/IDevice'; import IEmail from '../types/IEmail'; -import { delayAsync } from './delay.js'; -import { sendEmailAsync } from './email.js'; -import { arpscanDevicesAsync } from './scanner.js'; -import { StateSmoothingFunctionMachine } from './stateSmoothingFunctionMachine.js'; +import { delayAsync } from './delay'; +import { sendEmailAsync } from './email'; +import { arpscanDevicesAsync } from './scanner'; +import { StateSmoothingFunctionMachine } from './stateSmoothingFunctionMachine'; const defaultAlertMessages: { [alertType in AlertType]: string } = { intruder: 'The fortress is in peril.', diff --git a/packages/service/src/utilities/server.ts b/packages/service/src/utilities/server.ts index 7fd57e1..e4e6637 100644 --- a/packages/service/src/utilities/server.ts +++ b/packages/service/src/utilities/server.ts @@ -3,9 +3,9 @@ import express, { Application, Express, NextFunction, Response } from 'express'; import uuid from 'uuid-random'; import { CustomRequest } from '../types/CustomRequest'; import { IConfig } from '../types/IConfig'; -import { createAlerter } from './alerter.js'; -import { isAuthenticated } from './basicAuth.js'; -import { delayAsync } from './delay.js'; +import { createAlerter } from './alerter'; +import { isAuthenticated } from './basicAuth'; +import { delayAsync } from './delay'; import { SimpleLeakyBucket, SimpleLeakyBucketEventKinds,