From 1a26d1a88cb9c9a80e06238fafef24009f4afa98 Mon Sep 17 00:00:00 2001 From: Peter Date: Sat, 18 May 2024 07:45:31 +0200 Subject: [PATCH] Fix compilation errors in tests --- .../app/controllers/health/list.controller.ts | 2 - .../quests/custom/custom.router.ts | 2 +- .../controllers/quests/daily/daily.router.ts | 2 +- .../quests/gitcoin/gitcoin.router.ts | 2 +- .../quests/social/entries/post.controller.ts | 4 +- .../quests/social/social.router.ts | 14 +++++-- .../quests/webhook/webhook.router.ts | 2 +- apps/api/src/app/controllers/ve/ve.router.ts | 2 +- apps/api/src/app/util/ratelimiter.ts | 2 +- apps/api/tsconfig.app.json | 5 +-- apps/api/tsconfig.json | 11 +++-- apps/api/tsconfig.spec.json | 12 +++++- package.json | 3 ++ yarn.lock | 41 +++++++++++++++++++ 14 files changed, 80 insertions(+), 24 deletions(-) diff --git a/apps/api/src/app/controllers/health/list.controller.ts b/apps/api/src/app/controllers/health/list.controller.ts index 71b7d605c..5336c29fb 100644 --- a/apps/api/src/app/controllers/health/list.controller.ts +++ b/apps/api/src/app/controllers/health/list.controller.ts @@ -1,5 +1,4 @@ import { Request, Response } from 'express'; -import newrelic from 'newrelic'; import { fromWei } from 'web3-utils'; import { NODE_ENV } from '@thxnetwork/api/config/secrets'; import { ChainId } from '@thxnetwork/common/enums'; @@ -10,7 +9,6 @@ import { getArtifact, contractNetworks } from '@thxnetwork/api/hardhat'; import { BigNumber } from 'alchemy-sdk'; function handleError(error: Error) { - newrelic.noticeError(error); logger.error(error); return { error: 'invalid response' }; } diff --git a/apps/api/src/app/controllers/quests/custom/custom.router.ts b/apps/api/src/app/controllers/quests/custom/custom.router.ts index 21d2ab6c9..f2f9e9662 100644 --- a/apps/api/src/app/controllers/quests/custom/custom.router.ts +++ b/apps/api/src/app/controllers/quests/custom/custom.router.ts @@ -3,7 +3,7 @@ import * as CreateEntry from './entries/post.controller'; import { assertRequestInput, assertAccount } from '@thxnetwork/api/middlewares'; import { limitInSeconds } from '@thxnetwork/api/util/ratelimiter'; -export const router: express.Router = express.Router({ mergeParams: true }); +const router: express.Router = express.Router({ mergeParams: true }); router.post( '/:id/entries', diff --git a/apps/api/src/app/controllers/quests/daily/daily.router.ts b/apps/api/src/app/controllers/quests/daily/daily.router.ts index 9ab145733..09334a3ef 100644 --- a/apps/api/src/app/controllers/quests/daily/daily.router.ts +++ b/apps/api/src/app/controllers/quests/daily/daily.router.ts @@ -3,7 +3,7 @@ import * as CreateEntry from './entries/post.controller'; import { assertAccount, assertRequestInput } from '@thxnetwork/api/middlewares'; import { limitInSeconds } from '@thxnetwork/api/util/ratelimiter'; -export const router: express.Router = express.Router({ mergeParams: true }); +const router: express.Router = express.Router({ mergeParams: true }); router.post( '/:id/entries', diff --git a/apps/api/src/app/controllers/quests/gitcoin/gitcoin.router.ts b/apps/api/src/app/controllers/quests/gitcoin/gitcoin.router.ts index 21d2ab6c9..f2f9e9662 100644 --- a/apps/api/src/app/controllers/quests/gitcoin/gitcoin.router.ts +++ b/apps/api/src/app/controllers/quests/gitcoin/gitcoin.router.ts @@ -3,7 +3,7 @@ import * as CreateEntry from './entries/post.controller'; import { assertRequestInput, assertAccount } from '@thxnetwork/api/middlewares'; import { limitInSeconds } from '@thxnetwork/api/util/ratelimiter'; -export const router: express.Router = express.Router({ mergeParams: true }); +const router: express.Router = express.Router({ mergeParams: true }); router.post( '/:id/entries', diff --git a/apps/api/src/app/controllers/quests/social/entries/post.controller.ts b/apps/api/src/app/controllers/quests/social/entries/post.controller.ts index 6438ae9f2..0450a969e 100644 --- a/apps/api/src/app/controllers/quests/social/entries/post.controller.ts +++ b/apps/api/src/app/controllers/quests/social/entries/post.controller.ts @@ -11,7 +11,7 @@ import { QuestSocialRequirement } from '@thxnetwork/common/enums'; const validation = [param('id').isMongoId(), body('recaptcha').isString()]; -const controller = async ({ params, body, account }: Request, res: Response) => { +async function controller({ params, body, account }: Request, res: Response) { // Get the quest document const quest = await QuestSocial.findById(params.id); if (!quest) throw new NotFoundError('Quest not found'); @@ -63,6 +63,6 @@ const controller = async ({ params, body, account }: Request, res: Response) => }); res.json({ jobId: job.attrs._id }); -}; +} export { controller, validation }; diff --git a/apps/api/src/app/controllers/quests/social/social.router.ts b/apps/api/src/app/controllers/quests/social/social.router.ts index 6f38db8d4..72c309e5a 100644 --- a/apps/api/src/app/controllers/quests/social/social.router.ts +++ b/apps/api/src/app/controllers/quests/social/social.router.ts @@ -1,10 +1,16 @@ -import express from 'express'; +import express, { Router } from 'express'; import { assertRequestInput, assertAccount } from '@thxnetwork/api/middlewares'; import { limitInSeconds } from '@thxnetwork/api/util/ratelimiter'; -import * as Create from './entries/post.controller'; +import * as CreateEntries from './entries/post.controller'; -export const router: express.Router = express.Router({ mergeParams: true }); +const router: express.Router = Router({ mergeParams: true }); -router.post('/:id/entries', limitInSeconds(3), assertRequestInput(Create.validation), assertAccount, Create.controller); +router.post( + '/:id/entries', + limitInSeconds(3), + assertRequestInput(CreateEntries.validation), + assertAccount, + CreateEntries.controller, +); export default router; diff --git a/apps/api/src/app/controllers/quests/webhook/webhook.router.ts b/apps/api/src/app/controllers/quests/webhook/webhook.router.ts index 8ebf44eae..08f4c714c 100644 --- a/apps/api/src/app/controllers/quests/webhook/webhook.router.ts +++ b/apps/api/src/app/controllers/quests/webhook/webhook.router.ts @@ -3,7 +3,7 @@ import { assertAccount, assertRequestInput } from '@thxnetwork/api/middlewares'; import { limitInSeconds } from '@thxnetwork/api/util/ratelimiter'; import * as CreateEntry from './entries/post.controller'; -export const router: express.Router = express.Router({ mergeParams: true }); +const router: express.Router = express.Router({ mergeParams: true }); router.post( '/:id/entries', diff --git a/apps/api/src/app/controllers/ve/ve.router.ts b/apps/api/src/app/controllers/ve/ve.router.ts index ad777bcc1..b54064f7d 100644 --- a/apps/api/src/app/controllers/ve/ve.router.ts +++ b/apps/api/src/app/controllers/ve/ve.router.ts @@ -1,4 +1,4 @@ -import express, { Router } from 'express'; +import express from 'express'; import { assertRequestInput } from '@thxnetwork/api/middlewares'; import { assertWallet } from '@thxnetwork/api/middlewares/assertWallet'; diff --git a/apps/api/src/app/util/ratelimiter.ts b/apps/api/src/app/util/ratelimiter.ts index 800919f55..4900c2131 100644 --- a/apps/api/src/app/util/ratelimiter.ts +++ b/apps/api/src/app/util/ratelimiter.ts @@ -1,6 +1,6 @@ import rateLimit from 'express-rate-limit'; import { NODE_ENV } from '../config/secrets'; -const limitInSeconds = (seconds: number) => NODE_ENV !== 'test' && rateLimit({ windowMs: seconds * 1000, max: 1 }); +const limitInSeconds = (seconds: number) => rateLimit({ windowMs: NODE_ENV !== 'test' && seconds * 1000, max: 1 }); export { limitInSeconds }; diff --git a/apps/api/tsconfig.app.json b/apps/api/tsconfig.app.json index d082c3f0d..12fae6ea6 100644 --- a/apps/api/tsconfig.app.json +++ b/apps/api/tsconfig.app.json @@ -3,10 +3,7 @@ "compilerOptions": { "outDir": "../../dist/out-tsc", "module": "commonjs", - "types": ["node"], - // Custom - "noImplicitAny": false, - "strict": false + "types": ["node"] }, "exclude": ["jest.config.ts", "src/**/*.test.ts", "../../libs/common/src/lib/scss/**/*"], "include": ["src/**/*.ts", "../../libs/common/src/**/*", "../../libs/sdk/src/**/*", "src/app/hardhat/export/*.json"] diff --git a/apps/api/tsconfig.json b/apps/api/tsconfig.json index d09eefb8c..d2b6e8e03 100644 --- a/apps/api/tsconfig.json +++ b/apps/api/tsconfig.json @@ -1,5 +1,11 @@ { "extends": "../../tsconfig.base.json", + "compilerOptions": { + "esModuleInterop": true, + // Custom + "noImplicitAny": false, + "strict": false + }, "files": [], "include": [], "references": [ @@ -9,8 +15,5 @@ { "path": "./tsconfig.spec.json" } - ], - "compilerOptions": { - "esModuleInterop": true - } + ] } diff --git a/apps/api/tsconfig.spec.json b/apps/api/tsconfig.spec.json index c354ed639..e7639d7c4 100644 --- a/apps/api/tsconfig.spec.json +++ b/apps/api/tsconfig.spec.json @@ -3,7 +3,15 @@ "compilerOptions": { "outDir": "../../dist/out-tsc", "module": "commonjs", - "types": ["jest", "node"] + "types": ["jest", "node"], + // Custom + "allowJs": true }, - "include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"] + "include": [ + "jest.config.ts", + "src/**/*.test.ts", + "src/**/*.spec.ts", + "**/*.d.ts", + "../../libs/common/src/lib/types/**/*" + ] } diff --git a/package.json b/package.json index b8bbcad91..ef1186c70 100644 --- a/package.json +++ b/package.json @@ -119,13 +119,16 @@ "@typechain/hardhat": "^6.1.2", "@types/chai": "^4.2.0", "@types/color": "^3.0.3", + "@types/compression": "^1.7.5", "@types/ejs": "^3.1.5", "@types/express": "~4.17.13", "@types/jest": "29.4.4", + "@types/lusca": "^1.7.5", "@types/migrate-mongo": "^10.0.4", "@types/mixpanel-browser": "^2.38.0", "@types/mocha": ">=9.1.0", "@types/node": ">=18.0.0", + "@types/supertest": "^6.0.2", "@types/uuid": "^9.0.1", "@typescript-eslint/eslint-plugin": "7.9.0", "@typescript-eslint/parser": "7.9.0", diff --git a/yarn.lock b/yarn.lock index 2b5e88d52..817836a53 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7525,6 +7525,13 @@ dependencies: "@types/color-convert" "*" +"@types/compression@^1.7.5": + version "1.7.5" + resolved "https://registry.yarnpkg.com/@types/compression/-/compression-1.7.5.tgz#0f80efef6eb031be57b12221c4ba6bc3577808f7" + integrity sha512-AAQvK5pxMpaT+nDvhHrsBhLSYG5yQdtkaJE1WYieSNY2mVFKAgmU4ks65rkZD5oqnGCFLyQpUr1CqI4DmUMyDg== + dependencies: + "@types/express" "*" + "@types/concat-stream@^1.6.0": version "1.6.1" resolved "https://registry.yarnpkg.com/@types/concat-stream/-/concat-stream-1.6.1.tgz#24bcfc101ecf68e886aaedce60dfd74b632a1b74" @@ -7547,6 +7554,11 @@ dependencies: "@types/node" "*" +"@types/cookiejar@^2.1.5": + version "2.1.5" + resolved "https://registry.yarnpkg.com/@types/cookiejar/-/cookiejar-2.1.5.tgz#14a3e83fa641beb169a2dd8422d91c3c345a9a78" + integrity sha512-he+DHOWReW0nghN24E1WUqM0efK4kI9oTqDm6XmK8ZPe2djZ90BSNdGnIyCLzCPw7/pogPlGbzI2wHGGmi4O/Q== + "@types/debug@^4.1.7": version "4.1.12" resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.12.tgz#a155f21690871953410df4b6b6f53187f0500917" @@ -7734,6 +7746,18 @@ resolved "https://registry.yarnpkg.com/@types/lru-cache/-/lru-cache-5.1.1.tgz#c48c2e27b65d2a153b19bfc1a317e30872e01eef" integrity sha512-ssE3Vlrys7sdIzs5LOxCzTVMsU7i9oa/IaW92wF32JFb3CVczqOkru2xspuKczHEbG3nvmPY7IFqVmGGHdNbYw== +"@types/lusca@^1.7.5": + version "1.7.5" + resolved "https://registry.yarnpkg.com/@types/lusca/-/lusca-1.7.5.tgz#6fff257dc11176bd3150afba90790e626a12cd0f" + integrity sha512-l49gAf8pu2iMzbKejLcz6Pqj+51H2na6BgORv1ElnE8ByPFcBdh/eZ0WNR1Va/6ZuNSZa01Hoy1DTZ3IZ+y+kA== + dependencies: + "@types/express" "*" + +"@types/methods@^1.1.4": + version "1.1.4" + resolved "https://registry.yarnpkg.com/@types/methods/-/methods-1.1.4.tgz#d3b7ac30ac47c91054ea951ce9eed07b1051e547" + integrity sha512-ymXWVrDiCxTBE3+RIrrP533E70eA+9qu7zdWoHuOmGujkYtzf4HQF96b8nwHLqhuf4ykX61IGRIB38CC6/sImQ== + "@types/migrate-mongo@^10.0.4": version "10.0.4" resolved "https://registry.yarnpkg.com/@types/migrate-mongo/-/migrate-mongo-10.0.4.tgz#5b68fb9c3ca516e4f025ebca34021880137f94a4" @@ -7966,6 +7990,23 @@ resolved "https://registry.yarnpkg.com/@types/strip-json-comments/-/strip-json-comments-0.0.30.tgz#9aa30c04db212a9a0649d6ae6fd50accc40748a1" integrity sha512-7NQmHra/JILCd1QqpSzl8+mJRc8ZHz3uDm8YV1Ks9IhK0epEiTw8aIErbvH9PI+6XbqhyIQy3462nEsn7UVzjQ== +"@types/superagent@^8.1.0": + version "8.1.7" + resolved "https://registry.yarnpkg.com/@types/superagent/-/superagent-8.1.7.tgz#1153819ed4db34427409a1cc58f3e2f13eeec862" + integrity sha512-NmIsd0Yj4DDhftfWvvAku482PZum4DBW7U51OvS8gvOkDDY0WT1jsVyDV3hK+vplrsYw8oDwi9QxOM7U68iwww== + dependencies: + "@types/cookiejar" "^2.1.5" + "@types/methods" "^1.1.4" + "@types/node" "*" + +"@types/supertest@^6.0.2": + version "6.0.2" + resolved "https://registry.yarnpkg.com/@types/supertest/-/supertest-6.0.2.tgz#2af1c466456aaf82c7c6106c6b5cbd73a5e86588" + integrity sha512-137ypx2lk/wTQbW6An6safu9hXmajAifU/s7szAHLN/FeIm5w7yR0Wkl9fdJMRSHwOn4HLAI0DaB2TOORuhPDg== + dependencies: + "@types/methods" "^1.1.4" + "@types/superagent" "^8.1.0" + "@types/tapable@^1": version "1.0.12" resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.12.tgz#bc2cab12e87978eee89fb21576b670350d6d86ab"