refactor: clean up types and tsconfig (#49360)

This commit is contained in:
Oliver Eyton-Williams
2023-02-13 12:17:55 +01:00
committed by Mrugesh Mohapatra
parent 37ed23ef38
commit f35ab4d0ba
8 changed files with 28 additions and 26 deletions

View File

@@ -56,6 +56,7 @@
"parserOptions": {
"project": [
"./tsconfig.json",
"./api/tsconfig.json",
"./config/tsconfig.json",
"./tools/ui-components/tsconfig.json",
"./utils/tsconfig.json",

View File

@@ -18,9 +18,6 @@ const start = async () => {
// NOTE: Awaited to ensure `.use` is registered on `fastify`
await fastify.register(middie);
// @ts-expect-error Types are not exported from Fastify,
// and TypeScript is not smart enough to realise types
// defined within this module have the same signature
void fastify.use('/test', testMiddleware);
void fastify.register(dbConnector);

View File

@@ -1,16 +1,20 @@
import { NextFunction } from '../utils';
import type { NextFunction, NextHandleFunction } from '@fastify/middie';
export async function auth0Verify() {
// Verify user authorization code with Auth0
}
type MiddieRequest = Parameters<NextHandleFunction>[0];
type MiddieResponse = Parameters<NextHandleFunction>[1];
export function testMiddleware(
req: Request,
_res: Response,
req: MiddieRequest,
res: MiddieResponse,
next: NextFunction
) {
//
console.log('Test middleware running');
console.log(req.headers);
console.log(req.query);
res.setHeader('X-Test-Header', 'test');
next();
}

View File

@@ -4,7 +4,7 @@
"url": "https://github.com/freeCodeCamp/freeCodeCamp/issues"
},
"dependencies": {
"@fastify/middie": "8.0.0",
"@fastify/middie": "8.1",
"@fastify/mongodb": "6.1.0",
"fastify": "4.9.2",
"fastify-plugin": "4.3.0"
@@ -32,7 +32,7 @@
"url": "git+https://github.com/freeCodeCamp/freeCodeCamp.git"
},
"scripts": {
"build": "tsc index.ts",
"build": "tsc",
"develop": "nodemon index.ts",
"start": "NODE_ENV=production node index.js",
"test": "NODE_OPTIONS='--test-only' ts-node **/*.test.ts"

11
api/tsconfig.json Normal file
View File

@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es2022",
"module": "CommonJS",
"allowJs": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"resolveJsonModule": true
}
}

View File

@@ -13,7 +13,3 @@ function sha256(buf: Buffer) {
return createHash('sha256').update(buf).digest();
}
export const challenge = base64URLEncode(sha256(Buffer.from(verifier)));
// This is used for Fastify middleware, but is not exported from Fastify itself.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type NextFunction = (err?: any) => void;

18
package-lock.json generated
View File

@@ -114,7 +114,7 @@
"version": "0.0.1",
"license": "BSD-3-Clause",
"dependencies": {
"@fastify/middie": "8.0.0",
"@fastify/middie": "8.1",
"@fastify/mongodb": "6.1.0",
"fastify": "4.9.2",
"fastify-plugin": "4.3.0"
@@ -4575,24 +4575,18 @@
}
},
"node_modules/@fastify/middie": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/@fastify/middie/-/middie-8.0.0.tgz",
"integrity": "sha512-SsZUzJwRV2IBhko8TNI5gGzUdUp2Xd0XCrU+pBTfsMN8LYGsksDI/Hb3qcUZ2/Kfg6ecbFEeRO4nZmHeFCDpHQ==",
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/@fastify/middie/-/middie-8.1.0.tgz",
"integrity": "sha512-VvUCLfKx2j6KSnh8puT8QW7d5YNzi2fD/4HcFvRQ3a7sHlCo+qtfX2fqzFvNqnMVbNft7GX1JL5if/riUiXsyg==",
"dependencies": {
"fastify-plugin": "^3.0.0",
"fastify-plugin": "^4.0.0",
"path-to-regexp": "^6.1.0",
"reusify": "^1.0.4"
}
},
"node_modules/@fastify/middie/node_modules/fastify-plugin": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/fastify-plugin/-/fastify-plugin-3.0.1.tgz",
"integrity": "sha512-qKcDXmuZadJqdTm6vlCqioEbyewF60b/0LOFCcYN1B6BIZGlYJumWWOYs70SFYLDAH4YqdE1cxH/RKMG7rFxgA=="
},
"node_modules/@fastify/middie/node_modules/path-to-regexp": {
"version": "6.2.1",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.2.1.tgz",
"integrity": "sha512-JLyh7xT1kizaEvcaXOQwOc2/Yhw6KZOvPf1S8401UyLk86CU79LN3vl7ztXGm/pZ+YjoyAJ4rxmHwbkBXJX+yw=="
"license": "MIT"
},
"node_modules/@fastify/mongodb": {
"version": "6.1.0",

View File

@@ -1,6 +1,5 @@
{
"include": [
"api",
"client/i18n/**/*",
"client/plugins/**/*",
"client/src/**/*",