diff --git a/backend/.eslintrc.json b/backend/.eslintrc.json new file mode 100644 index 00000000..1a8461be --- /dev/null +++ b/backend/.eslintrc.json @@ -0,0 +1,63 @@ +{ + "plugins": [ + "@typescript-eslint", + "unicorn", + "jsdoc", + "import", + "promise", + "sonarjs" + ], + "extends": [ + "eslint:recommended", + "plugin:n/recommended", + "plugin:@typescript-eslint/recommended", + "plugin:unicorn/recommended", + "plugin:jsdoc/recommended", + "plugin:import/recommended", + "plugin:promise/recommended", + "plugin:sonarjs/recommended", + "plugin:security/recommended" + ], + "root": true, + "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": "./tsconfig.json", + "ecmaVersion": "latest", + "sourceType": "module" + }, + "rules": { + "@typescript-eslint/no-unused-vars": [ + "error", + { + "argsIgnorePattern": "^_", + "varsIgnorePattern": "^_", + "ignoreRestSiblings": true + } + ], + "@typescript-eslint/no-misused-promises": [ + "error", + { + "checksVoidReturn": false + } + ], + "@typescript-eslint/no-var-requires": "off", + "@typescript-eslint/ban-ts-comment": "off", + "jsdoc/require-jsdoc": ["warn", { "publicOnly": true }], + "jsdoc/require-description": "off", + "import/no-unresolved": "off", + "unicorn/no-empty-file": "off", + "unicorn/consistent-function-scoping": [ + "error", + { + "checkArrowFunctions": false + } + ], + "unicorn/prefer-module": "off", + "unicorn/prevent-abbreviations": "off", + "unicorn/catch-error-name": "off", + "unicorn/prefer-ternary": "off", + "unicorn/prefer-event-target": "off", + "security/detect-object-injection": "off", + "security/detect-non-literal-fs-filename": "off" + } +} diff --git a/backend/app.js b/backend/app.js index 037ba245..9e5d75cc 100644 --- a/backend/app.js +++ b/backend/app.js @@ -36,6 +36,7 @@ if ( process.env.NODE_ENV === "production" && process.env.ZU_SECURE_HEADERS !== "false" ) { + // @ts-ignore app.use(helmet()); } diff --git a/backend/global.d.ts b/backend/global.d.ts new file mode 100644 index 00000000..fc1ca3a2 --- /dev/null +++ b/backend/global.d.ts @@ -0,0 +1 @@ +declare module "axios"; diff --git a/backend/jsconfig.json b/backend/jsconfig.json deleted file mode 100644 index 011412e5..00000000 --- a/backend/jsconfig.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "exclude": ["node_modules", "**/node_modules/*"], - "typeAcquisition": { - "exclude": ["dotenv"] - } -} diff --git a/backend/package.json b/backend/package.json index 448b4538..b2abce88 100644 --- a/backend/package.json +++ b/backend/package.json @@ -2,20 +2,36 @@ "name": "backend", "private": true, "scripts": { - "start": "node ./bin/www" + "start": "node ./bin/www", + "lint": "eslint . --report-unused-disable-directives --max-warnings 0", + "typecheck": "tsc --pretty --noEmit -p tsconfig.json" }, "dependencies": { "axios": "^0.27.2", "compression": "^1.7.4", - "debug": "~4.3.4", - "dotenv": "^16.0.1", - "express": "~4.18.1", + "debug": "^4.3.4", + "dotenv": "^16.3.1", + "express": "^4.18.2", "express-bearer-token": "^2.4.0", "helmet": "^5.1.1", "lodash": "^4.17.21", "lowdb": "^1.0.0", - "morgan": "~1.10.0", + "morgan": "^1.10.0", "node-cron": "^3.0.2", "pbkdf2-wrapper": "^1.3.4" + }, + "devDependencies": { + "@types/express": "^4.17.18", + "@typescript-eslint/eslint-plugin": "^6.7.4", + "@typescript-eslint/parser": "^6.7.4", + "eslint": "^8.50.0", + "eslint-plugin-import": "^2.28.1", + "eslint-plugin-jsdoc": "^46.8.2", + "eslint-plugin-n": "^16.1.0", + "eslint-plugin-promise": "^6.1.1", + "eslint-plugin-security": "^1.7.1", + "eslint-plugin-sonarjs": "^0.21.0", + "eslint-plugin-unicorn": "^48.0.1", + "typescript": "^5.2.2" } } diff --git a/backend/routes/member.js b/backend/routes/member.js index 1ee33ed5..8c3c0120 100644 --- a/backend/routes/member.js +++ b/backend/routes/member.js @@ -8,6 +8,7 @@ const api = require("../utils/controller-api"); // get all members router.get("/", auth.isAuthorized, async function (req, res) { + // @ts-ignore const nwid = req.params.nwid; api .get("controller/network/" + nwid + "/member") @@ -23,6 +24,7 @@ router.get("/", auth.isAuthorized, async function (req, res) { // get member router.get("/:mid", auth.isAuthorized, async function (req, res) { + // @ts-ignore const nwid = req.params.nwid; const mid = req.params.mid; const data = await member.getMembersData(nwid, [mid]); @@ -35,6 +37,7 @@ router.get("/:mid", auth.isAuthorized, async function (req, res) { // update member router.post("/:mid", auth.isAuthorized, async function (req, res) { + // @ts-ignore const nwid = req.params.nwid; const mid = req.params.mid; member.updateMemberAdditionalData(nwid, mid, req.body); @@ -56,6 +59,7 @@ router.post("/:mid", auth.isAuthorized, async function (req, res) { // delete member router.delete("/:mid", auth.isAuthorized, async function (req, res) { + // @ts-ignore const nwid = req.params.nwid; const mid = req.params.mid; member.deleteMemberAdditionalData(nwid, mid); diff --git a/backend/services/member.js b/backend/services/member.js index fc919906..3f9f2d64 100644 --- a/backend/services/member.js +++ b/backend/services/member.js @@ -71,6 +71,7 @@ async function getMemberAdditionalData(data) { networkId: data.nwid, nodeId: data.id, controllerId: ZT_ADDRESS, + // @ts-ignore lastOnline: lastOnline, ...additionalData, ...peerData, diff --git a/backend/tsconfig.json b/backend/tsconfig.json new file mode 100644 index 00000000..beb0bca4 --- /dev/null +++ b/backend/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "rootDir": ".", + "baseUrl": ".", + "allowJs": true, + "checkJs": true, + "noEmit": true, + "skipLibCheck": true, + "module": "CommonJS", + "moduleResolution": "Node", + "target": "ESNext", + "lib": ["ESNext", "dom"], + "strict": true, + "noImplicitAny": false, + "allowSyntheticDefaultImports": true + }, + "include": ["."] +} diff --git a/backend/utils/zt-address.js b/backend/utils/zt-address.js index c91b0523..07ba7835 100644 --- a/backend/utils/zt-address.js +++ b/backend/utils/zt-address.js @@ -6,6 +6,7 @@ module.exports = async function () { return res.data.address; } catch (err) { console.error( + // @ts-ignore "Couldn't connect to the controller on " + err.config.baseURL ); } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..7d2c9df2 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "allowJs": true, + "checkJs": true, + "noEmit": true, + "skipLibCheck": true, + "target": "ESNext", + "lib": ["ESNext", "dom"], + "strict": true, + "noImplicitAny": false, + "allowSyntheticDefaultImports": true + }, + "include": ["backend", "frontend"] +}