Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4d86d2c
Update Backend Configuration and Documentation
Mars190 Mar 18, 2025
0303662
Updated notes
Mars190 Mar 18, 2025
7f1e13a
chore: upgrade class-validator to fix critical SQL injection vulnerab…
Mars190 Mar 18, 2025
7b8dc21
chore: Updated all tree-sitter dependencies
Mars190 Mar 18, 2025
1d48189
chore: Update express-session to latest
Mars190 Mar 18, 2025
47063fb
chore: Updated @sentry/node to latest
Mars190 Mar 18, 2025
d6cfe6c
chore: Updated passport to latest
Mars190 Mar 18, 2025
91ee052
chore: Updated typeorm & pg to latest
Mars190 Mar 18, 2025
d1f4cbf
chore: Updated reflect-metadata to latest
Mars190 Mar 18, 2025
56a3707
Removed dependency pg-query-stream because it is unused
Mars190 Mar 18, 2025
8cae81c
chore: Updated rimraf & rxjs to latest
Mars190 Mar 18, 2025
be5df4d
chore: Updated socket.io to latest
Mars190 Mar 18, 2025
f070a47
chore: Update prettier
Mars190 Mar 18, 2025
80f65c6
chore: Update jest, ts-jest & remove ts-loader & ts-node
Mars190 Mar 18, 2025
32474c8
Changed nest commands
Mars190 Mar 18, 2025
48a5c03
chore: Updated @types
Mars190 Mar 18, 2025
03552ff
chore: Updated typescript dev-dependency
Mars190 Mar 18, 2025
fc6b655
Removed eslint for now, adding after upgrade
Mars190 Mar 18, 2025
8cf7c5e
chore: Updated NestJS Framework to latest version
Mars190 Mar 18, 2025
d18c460
Updated yarn to 4.7
Mars190 Mar 18, 2025
3c01b3e
Update notes
Mars190 Mar 18, 2025
adff29e
Added eslint
Mars190 Mar 18, 2025
527c7e0
Found circular dependency?
Mars190 Mar 19, 2025
d0120c8
Added pg-query-stream again
Mars190 Mar 19, 2025
c3a1813
Updated backend documentation for GitHub Oauth
Mars190 Mar 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"makefile.configureOnOpen": false
}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ run-backend-dev:
yarn --cwd ./packages/back-nest start:dev

run-dev-db:
docker compose -f ./packages/back-nest/docker-compose.yml up -d
docker compose --env-file ./packages/back-nest/.env -f ./packages/back-nest/docker-compose.yml up -d

run-seed-codesources:
yarn --cwd ./packages/back-nest command seed-challenges
Expand Down
9 changes: 9 additions & 0 deletions NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### General
- `/docs` directory?
- Split CONTRIBUTING.md into docs for backend and frontend
- Setup: use nvm, yarn 4.7, build-options, docker
- Tests?
- Go from packages/front&backend to /frontend & /backend -> rm make file

### Backend (NestJS)
- Use `Logging` instead of `console.log()`
5 changes: 0 additions & 5 deletions packages/back-nest/.env.development

This file was deleted.

14 changes: 14 additions & 0 deletions packages/back-nest/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
APP_PORT=1337

GITHUB_ACCESS_TOKEN="<YOUR_GITHUB_ACCESS_TOKEN"

GITHUB_CLIENT_ID="<YOUR_GITHUB_CLIENT_ID>"
GITHUB_CLIENT_SECRET="<YOUR_GITHUB_CLIENT_SECRET>"

SESSION_SECRET="<YOUR_SESSION_SECRET>"

DB_USERNAME="postgres"
DB_PASSWORD="postgres"
DB_HOST=localhost
DB_PORT=5432
DB_NAME="speedtyper"
25 changes: 0 additions & 25 deletions packages/back-nest/.eslintrc.js

This file was deleted.

5 changes: 4 additions & 1 deletion packages/back-nest/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ lerna-debug.log*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/extensions.json

# yarn
.yarn/*
1 change: 1 addition & 0 deletions packages/back-nest/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
38 changes: 29 additions & 9 deletions packages/back-nest/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
## Seed challenge data
## Setting up environment variables
For local development, you will have to set these variables in the `.env` file in the `./packages/back-nest/` directory, that you have copied (Refer to: [Contributing](../../CONTRIBUTING.md), Backend)

### Seed test challenges
### General
- `APP_PORT`: The port the backend will listen on, just use 1337
- `GITHUB_ACCESS_TOKEN`: Used to access the open source projects that are used for the challenges. Refer to this [guide](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic), and when you get asked about scopes, select none and create it.
- `GITHUB_CLIENT_ID` & `GITHUB_CLIENT_SECRET`: These are required for OAuth integration with GitHub. Without these, GitHub OAuth won't work. [Here](https://github.com/settings/applications/new) you can add a new application. For the callback url, set it to `http://localhost:1337/api/auth/github/callback`. If you are running the app on a different port, set it to that port.
- `SESSION_SECRET`: Used for encrypting session cookies. This should be a unique and secret string to ensure the security of session data. To generate a random secret you could use this [site](https://www.browserling.com/tools/random-hex). *It should be at least be 32 characters long!*

`yarn command seed-challenges`
### Database Configuration
The following environment variables are used to configure the connection to your PostgreSQL database. These should be defined in your `.env` file as well:

### Seed production challenges
- `DB_USERNAME`: The username for connecting to your PostgreSQL database.
- `DB_PASSWORD`: The password associated with the database user.
- `DB_HOST`: The host address where your PostgreSQL instance is running. For local development, this will typically be `localhost`.
- `DB_PORT`: The port on which your PostgreSQL instance is running. By default, PostgreSQL uses `5432`.
- `DB_NAME`: The name of the database that the application should connect to. Just stick to `speedtyper` if you don't know what you are doing.

## Seed challenge data

This requires you to have a GitHub access token, as seen above.

Requires configuring a personal `GITHUB_ACCESS_TOKEN` in your .env file
### Seed test challenges
```
yarn command seed-challenges
```

`yarn command import-projects`
`yarn command sync-projects`
`yarn command import-files`
`yarn command import-challenges`
### Seed production challenges
```
yarn command import-projects
yarn command import-files
yarn command import-challenges
yarn command sync-projects
```
21 changes: 12 additions & 9 deletions packages/back-nest/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
# Use postgres/example user/password credentials
version: "3.1"
# TODO: Distinguish between dev & production dockerfile?

services:
db:
image: postgres
restart: always

restart: unless-stopped
ports:
- 5432:5432

- ${DB_PORT}:5432
environment:
POSTGRES_USERNAME: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_USERNAME: ${DB_USERNAME}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_NAME}
volumes:
- postgres_data:/var/lib/postgresql/data

adminer:
image: adminer
restart: always
restart: unless-stopped
ports:
- 8080:8080

volumes:
postgres_data:
35 changes: 35 additions & 0 deletions packages/back-nest/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// @ts-check
import eslint from '@eslint/js';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import globals from 'globals';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{
ignores: ['eslint.config.mjs'],
},
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
eslintPluginPrettierRecommended,
{
languageOptions: {
globals: {
...globals.node,
...globals.jest,
},
ecmaVersion: 5,
sourceType: 'module',
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
{
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-floating-promises': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn'
},
},
);
5 changes: 4 additions & 1 deletion packages/back-nest/nest-cli.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src"
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
}
}
142 changes: 73 additions & 69 deletions packages/back-nest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,87 +9,90 @@
"command": "TS_NODE_PROJECT=./tsconfig.json ts-node -r tsconfig-paths/register ./src/commands.ts",
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "yarn start:prod",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"dev": "nest start --watch",
"debug": "nest start --debug --watch",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
"test:e2e": "jest --config ./test/jest-e2e.json",
"preview": "node dist/main",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
},
"dependencies": {
"@nestjs/axios": "^0.1.0",
"@nestjs/common": "^9.0.0",
"@nestjs/config": "^2.2.0",
"@nestjs/core": "^9.0.0",
"@nestjs/passport": "^9.0.0",
"@nestjs/platform-express": "^9.0.0",
"@nestjs/platform-socket.io": "^9.1.4",
"@nestjs/typeorm": "^10.0.1",
"@nestjs/websockets": "^9.1.4",
"@sentry/node": "^7.37.2",
"@types/passport-github": "^1.1.7",
"@eslint/eslintrc": "^3.3.0",
"@eslint/js": "^9.22.0",
"@nestjs/axios": "^4.0.0",
"@nestjs/common": "^11.0.11",
"@nestjs/config": "^4.0.1",
"@nestjs/core": "^11.0.11",
"@nestjs/passport": "^11.0.5",
"@nestjs/platform-express": "^11.0.11",
"@nestjs/platform-socket.io": "^11.0.11",
"@nestjs/typeorm": "^11.0.0",
"@nestjs/websockets": "^11.0.11",
"@sentry/node": "^9.6.0",
"@types/passport-github": "^1.1.12",
"@types/supertest": "^6.0.2",
"axios": "^1.8.3",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"class-validator": "^0.14.1",
"connect-typeorm": "^2.0.0",
"express-session": "^1.17.3",
"eslint": "^9.22.0",
"eslint-config-prettier": "^10.1.1",
"eslint-plugin-prettier": "^5.2.3",
"express-session": "^1.18.1",
"express-socket.io-session": "^1.3.5",
"nest-commander": "^3.1.0",
"passport": "^0.6.0",
"globals": "^16.0.0",
"nest-commander": "^3.17.0",
"passport": "^0.7.0",
"passport-github": "^1.1.0",
"pg": "^8.8.0",
"pg-query-stream": "^4.3.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0",
"socket.io": "^4.5.2",
"tree-sitter": "^0.20.0",
"tree-sitter-c": "^0.19.0",
"tree-sitter-c-sharp": "^0.19.0",
"tree-sitter-cpp": "^0.19.0",
"tree-sitter-css": "^0.19.0",
"tree-sitter-go": "^0.19.1",
"tree-sitter-java": "^0.19.1",
"tree-sitter-javascript": "^0.19.0",
"tree-sitter-lua": "^1.6.2",
"tree-sitter-ocaml": "^0.19.0",
"tree-sitter-php": "^0.19.0",
"tree-sitter-python": "^0.19.0",
"tree-sitter-ruby": "^0.19.0",
"tree-sitter-rust": "^0.19.1",
"tree-sitter-scala": "^0.19.0",
"tree-sitter-typescript": "^0.19.0",
"typeorm": "^0.3.10",
"pg": "^8.14.1",
"pg-query-stream": "^4.8.1",
"reflect-metadata": "^0.2.2",
"rimraf": "^6.0.1",
"rxjs": "^7.8.2",
"socket.io": "^4.8.1",
"supertest": "^7.0.0",
"tree-sitter": "^0.22.4",
"tree-sitter-c": "^0.23.5",
"tree-sitter-c-sharp": "^0.23.1",
"tree-sitter-cpp": "^0.23.4",
"tree-sitter-css": "^0.23.2",
"tree-sitter-go": "^0.23.4",
"tree-sitter-java": "^0.23.5",
"tree-sitter-javascript": "^0.23.1",
"tree-sitter-lua": "^2.1.3",
"tree-sitter-ocaml": "^0.24.0",
"tree-sitter-php": "^0.23.12",
"tree-sitter-python": "^0.23.6",
"tree-sitter-ruby": "^0.23.1",
"tree-sitter-rust": "^0.23.2",
"tree-sitter-scala": "^0.23.4",
"tree-sitter-typescript": "^0.23.2",
"ts-node": "^10.9.2",
"typeorm": "^0.3.21",
"typescript-eslint": "^8.26.1",
"unique-names-generator": "^4.7.1"
},
"devDependencies": {
"@nestjs/cli": "^9.0.0",
"@nestjs/schematics": "^9.0.0",
"@nestjs/testing": "^9.0.0",
"@types/express": "^4.17.13",
"@types/express-session": "^1.17.5",
"@types/express-socket.io-session": "^1.3.6",
"@types/jest": "28.1.8",
"@types/node": "^20.0.0",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "28.1.3",
"prettier": "^2.3.2",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
"ts-jest": "28.0.8",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "4.1.0",
"typescript": "^4.7.4"
"@nestjs/cli": "^11.0.5",
"@nestjs/schematics": "^11.0.2",
"@nestjs/testing": "^11.0.11",
"@types/express": "^5.0.0",
"@types/express-session": "^1.18.1",
"@types/express-socket.io-session": "^1.3.9",
"@types/inquirer": "^8.1.3",
"@types/jest": "^29.5.14",
"@types/node": "^22.13.10",
"jest": "^29.7.0",
"prettier": "^3.5.3",
"source-map-support": "^0.5.21",
"ts-jest": "^29.2.6",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.8.2",
"yarn-upgrade-all": "^0.7.5"
},
"jest": {
"moduleFileExtensions": [
Expand All @@ -111,5 +114,6 @@
"moduleNameMapper": {
"^src/(.*)$": "<rootDir>/$1"
}
}
},
"packageManager": "yarn@4.7.0"
}
5 changes: 4 additions & 1 deletion packages/back-nest/src/auth/github/github.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { UpsertGithubUserDTO } from 'src/users/entities/upsertGithubUserDTO';

@Injectable()
export class GithubStrategy extends PassportStrategy(Strategy, 'github') {
constructor(cfg: ConfigService, private userService: UserService) {
constructor(
cfg: ConfigService,
private userService: UserService,
) {
const BASE_URL =
process.env.NODE_ENV === 'production'
? 'https://v3.speedtyper.dev'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class ChallengeImportRunner extends CommandRunner {
const fileExtension = path.split('.').pop();
const parser = this.parserService.getParser(fileExtension);
const content = Buffer.from(base64Content, 'base64').toString();
const nodes = parser.parseTrackedNodes(content);
const nodes = parser.parseCode(content);
return nodes;
}
}
Loading