Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: fix typescript code errors across code base and transform to ESM and TSX (part 1) #4133

Merged
merged 76 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
cffec0a
chore: add typescript checks to actions
sjschlapbach May 29, 2024
5fac5fa
chore: update github actions
sjschlapbach May 29, 2024
19baf2c
chore: run type checks for all apps independent of individual fails
sjschlapbach May 29, 2024
aa67050
chore: build all required packages manually before running checks
sjschlapbach May 29, 2024
4f699bc
chore: build utils package
sjschlapbach May 29, 2024
a7053c8
chore: fix build order
sjschlapbach May 29, 2024
c119f33
chore: fix build paths
sjschlapbach May 29, 2024
a72d84e
chore: move grading build
sjschlapbach May 29, 2024
2f8c408
chore: update actions versions
sjschlapbach May 29, 2024
a4ad424
chore: fix typescript types in frontend-pwa components
sjschlapbach May 30, 2024
665d460
wip: fix almost all type errors on pwa pages
sjschlapbach May 30, 2024
4029b5f
chore: fix type errors in shared components
sjschlapbach May 30, 2024
81f92cf
chore: fix type errors for frontend-control
sjschlapbach May 30, 2024
bd79f19
wip: fix type errors in frontend manage
sjschlapbach May 30, 2024
a6e885e
wip: fix types on live session evaluation view
sjschlapbach May 30, 2024
b144282
wip: continue eliminating type errors from frontend-manage
sjschlapbach May 30, 2024
d138b07
chore: fix type issues in shared components package
sjschlapbach May 30, 2024
42e65d4
chore: update github actions
sjschlapbach May 30, 2024
a3a1837
chore: extend type check
sjschlapbach May 30, 2024
1c2bc14
chore: extend type check to utils package
sjschlapbach May 30, 2024
f041a56
chore: fix type errors in prisma package
sjschlapbach May 30, 2024
52ace64
chore: start fixing types in graphql service
sjschlapbach May 30, 2024
4f50add
refactor: move all packages to ESM, upgrade TypeScript and tsconfig f…
rschlaefli May 30, 2024
865aad5
Merge branch 'TypesChecking' of https://github.com/uzh-bf/klicker-uzh…
sjschlapbach May 30, 2024
2a9d231
fix type issues on leaderboard entry
rschlaefli May 30, 2024
a7d2fbb
chore: fix missing student course
sjschlapbach May 30, 2024
e02ec28
more fixes
rschlaefli May 30, 2024
a8d20be
Merge branch 'PWATypes' of https://github.com/uzh-bf/klicker-uzh into…
sjschlapbach May 30, 2024
abda8da
Merge branch 'PWATypes' of https://github.com/uzh-bf/klicker-uzh into…
sjschlapbach May 30, 2024
479754f
fix lti types
rschlaefli May 30, 2024
61b7339
chore: fix type errors in shared components
sjschlapbach May 30, 2024
89e6443
chore: fix remaining types for shared-components
sjschlapbach May 30, 2024
615f036
chore: minor type fixes
sjschlapbach May 30, 2024
2099102
more fixes
rschlaefli May 30, 2024
71d0313
Merge branch 'PWATypes' of https://github.com/uzh-bf/klicker-uzh into…
rschlaefli May 30, 2024
c542dc9
mini type fix
sjschlapbach May 30, 2024
3037f62
Merge branch 'PWATypes' of https://github.com/uzh-bf/klicker-uzh into…
sjschlapbach May 30, 2024
f662349
more stuff
rschlaefli May 30, 2024
3274373
Merge branch 'PWATypes' of https://github.com/uzh-bf/klicker-uzh into…
rschlaefli May 30, 2024
54fe070
chore: fix types for v3 import function
sjschlapbach May 30, 2024
b8b79b3
Merge branch 'PWATypes' of https://github.com/uzh-bf/klicker-uzh into…
sjschlapbach May 30, 2024
db588db
more fixes
rschlaefli May 30, 2024
b683965
Merge branch 'PWATypes' of https://github.com/uzh-bf/klicker-uzh into…
rschlaefli May 30, 2024
57107b0
add excludes for imported libraries in functions
sjschlapbach May 30, 2024
f695aeb
Merge branch 'PWATypes' of https://github.com/uzh-bf/klicker-uzh into…
sjschlapbach May 30, 2024
61e24f8
fix more stuff
rschlaefli May 30, 2024
c827efc
Merge branch 'PWATypes' of https://github.com/uzh-bf/klicker-uzh into…
rschlaefli May 30, 2024
a454e25
chore: fix types in config files
sjschlapbach May 30, 2024
5fbcbfa
Merge branch 'PWATypes' of https://github.com/uzh-bf/klicker-uzh into…
sjschlapbach May 30, 2024
95b2e35
fix more
rschlaefli May 30, 2024
db0a768
Merge branch 'PWATypes' of https://github.com/uzh-bf/klicker-uzh into…
rschlaefli May 30, 2024
ec803dc
fixes in backend-docker
rschlaefli May 30, 2024
40a6513
more fixes
rschlaefli May 30, 2024
605e97b
fix auth types
rschlaefli May 30, 2024
08c88d0
chore: fix remaining errors in prisma package
sjschlapbach May 30, 2024
1c386a0
Merge branch 'PWATypes' of https://github.com/uzh-bf/klicker-uzh into…
sjschlapbach May 30, 2024
c20e6d2
chore: exclude student question in shared-components
sjschlapbach May 30, 2024
abb6559
chore: add lib skip to office-addin config
sjschlapbach May 30, 2024
4bbb1b7
chore: simplify type check action
sjschlapbach May 30, 2024
a4be17f
tsc no emit
rschlaefli May 30, 2024
26df715
Merge branch 'PWATypes' of https://github.com/uzh-bf/klicker-uzh into…
rschlaefli May 30, 2024
def49eb
enhance: replace outdated md5 module through node crypto implementation
sjschlapbach May 30, 2024
26ecbd6
Merge branch 'PWATypes' of https://github.com/uzh-bf/klicker-uzh into…
sjschlapbach May 30, 2024
03736ea
memoized validation schema on edit form
rschlaefli May 30, 2024
54a6cb7
Merge branch 'PWATypes' of https://github.com/uzh-bf/klicker-uzh into…
rschlaefli May 30, 2024
995d9c7
chore: fix types in backend
sjschlapbach May 30, 2024
7f64f45
chore: fix push subscription types in frontend-pwa (#4136)
sjschlapbach May 31, 2024
647f6b9
Merge branch 'v3' into TypesChecking
sjschlapbach Jul 5, 2024
80589b4
Merge branch 'TypesChecking' into PWATypes
sjschlapbach Jul 5, 2024
fcb112d
chore: fix typescript types in frontends and shared components (#4134)
sjschlapbach Jul 5, 2024
c806773
Merge branch 'v3' of https://github.com/uzh-bf/klicker-uzh into Types…
rschlaefli Jul 30, 2024
2fb9afb
migrate to tsx
rschlaefli Jul 30, 2024
e63ed1f
chore: fix formatting
rschlaefli Jul 30, 2024
983b710
ci: fix auth workflow for typechecking
rschlaefli Jul 30, 2024
df05b41
fix some type issues
rschlaefli Jul 30, 2024
9e55705
fix: module and import in jest for grading test
rschlaefli Jul 30, 2024
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
134 changes: 134 additions & 0 deletions .github/workflows/check-types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
name: Check typescript types

on:
push:
branches: ['v3', 'v3*']
pull_request:
# branches: ["v3", "v3*"]
types: [opened, synchronize, reopened]

env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
TURBO_REMOTE_ONLY: true

jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 8.15.8
run_install: true
- name: Build all required packages
run: |
cd packages/prisma
pnpm run build
cd ../util
pnpm run build
cd ../grading
pnpm run build
cd ../graphql
pnpm run build
cd ../markdown
pnpm run build
cd ../shared-components
pnpm run build

- name: Check prisma package typescript types
shell: bash
run: |
cd packages/prisma
pnpm run check
- name: Check grading package typescript types
if: always() # Run this step even if the previous one fails
shell: bash
run: |
cd packages/grading
pnpm run check
- name: Check util package typescript types
if: always() # Run this step even if the previous one fails
shell: bash
run: |
cd packages/util
pnpm run check
- name: Check graphql package typescript types
if: always() # Run this step even if the previous one fails
shell: bash
run: |
cd packages/graphql
pnpm run check
- name: Check lti package typescript types
if: always()
shell: bash
run: |
cd packages/lti
pnpm run check
- name: Check shared-components package typescript types
if: always()
shell: bash
run: |
cd packages/shared-components
pnpm run check
- name: Check v2 export function typescript types
if: always()
shell: bash
run: |
cd apps/func-migration-v2-export
pnpm run check
- name: Check v3 import function typescript types
if: always()
shell: bash
run: |
cd apps/func-migration-v3-import
pnpm run check
- name: Check backend-docker typescript types
if: always()
shell: bash
run: |
cd apps/backend-docker
pnpm run check
- name: Check frontend-pwa typescript types
if: always()
shell: bash
run: |
cd apps/frontend-pwa
pnpm run check
- name: Check frontend-manage typescript types
if: always()
shell: bash
run: |
cd apps/frontend-manage
pnpm run check
- name: Check frontend-control typescript types
if: always()
shell: bash
run: |
cd apps/frontend-control
pnpm run check
- name: Check frontend-auth typescript types
if: always()
shell: bash
run: |
cd apps/auth
pnpm run check
- name: Check office-addin typescript types
if: always()
shell: bash
run: |
cd apps/office-addin
pnpm run check
- name: Check func-response-processor typescript types
if: always()
shell: bash
run: |
cd apps/func-response-processor
pnpm run check
- name: Check func-incoming-responses typescript types
if: always()
shell: bash
run: |
cd apps/func-incoming-responses
pnpm run check
6 changes: 3 additions & 3 deletions .github/workflows/cypress-testing.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Klicker automated testing with cypress
on:
push:
branches: ["v3", "v3*"]
branches: ['v3', 'v3*']
pull_request:
types: [opened, synchronize, reopened]
# workflow_dispatch:
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:

- uses: pnpm/action-setup@v2
with:
version: 8.14.1
version: 8.15.8
run_install: false

- name: Get pnpm store directory
Expand Down Expand Up @@ -129,7 +129,7 @@ jobs:
timeout-minutes: 20
with:
install: false
wait-on: "http://127.0.0.1:3000/api/graphql, http://127.0.0.1:3001, http://127.0.0.1:3002, http://127.0.0.1:3003, http://127.0.0.1:3010"
wait-on: 'http://127.0.0.1:3000/api/graphql, http://127.0.0.1:3001, http://127.0.0.1:3002, http://127.0.0.1:3003, http://127.0.0.1:3010'
wait-on-timeout: 300
record: true
browser: electron
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/format-and-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8.14.1
version: 8.15.8
run_install: true
- name: Check formatting
shell: bash
Expand All @@ -33,7 +33,7 @@ jobs:
uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8.14.1
version: 8.15.8
run_install: true
- name: Check linting
shell: bash
Expand All @@ -46,7 +46,7 @@ jobs:
# uses: actions/checkout@v3
# - uses: pnpm/action-setup@v2
# with:
# version: 8.14.1
# version: 8.15.8
# run_install: true
# - name: Check types
# shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-grading.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8.14.1
version: 8.15.8
run_install: true
- name: Test functions
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/v3_klickeruzhprod-migration-export.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

- uses: pnpm/action-setup@v2
with:
version: 8.14.1
version: 8.15.8

- name: 'Resolve Project Dependencies Using Npm'
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/v3_klickeruzhprod-migration-import.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

- uses: pnpm/action-setup@v2
with:
version: 8.14.1
version: 8.15.8

- name: 'Resolve Project Dependencies Using Npm'
shell: bash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

- uses: pnpm/action-setup@v2
with:
version: 8.14.1
version: 8.15.8

- name: 'Resolve Project Dependencies Using Npm'
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/v3_klickeruzhprod-response-processor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- uses: pnpm/action-setup@v2
with:
version: 8.14.1
version: 8.15.8

- name: 'Resolve Project Dependencies Using Npm'
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/v3_klickeruzhprod-responses(qa).yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

- uses: pnpm/action-setup@v2
with:
version: 8.14.1
version: 8.15.8

- name: 'Resolve Project Dependencies Using Npm'
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/v3_klickeruzhprod-responses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- uses: pnpm/action-setup@v2
with:
version: 8.14.1
version: 8.15.8

- name: 'Resolve Project Dependencies Using Npm'
shell: bash
Expand Down
5 changes: 5 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
semi: false,
singleQuote: true,
trailingComma: 'es5',
}
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node 20.11.0
pnpm 8.14.1
pnpm 8.15.8
4 changes: 2 additions & 2 deletions apps/auth/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ WORKDIR /app
RUN apk add --no-cache libc6-compat
RUN apk update

RUN npm i -g --ignore-scripts pnpm@8.14.1 turbo@1.11.3
RUN npm i -g --ignore-scripts pnpm@8.15.8 turbo@1.13.3

COPY . .

Expand All @@ -22,7 +22,7 @@ WORKDIR /app
RUN apk add --no-cache libc6-compat
RUN apk update

RUN npm i -g --ignore-scripts pnpm@8.14.1 turbo@1.11.3
RUN npm i -g --ignore-scripts pnpm@8.15.8 turbo@1.13.3

COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/pnpm* .
Expand Down
5 changes: 3 additions & 2 deletions apps/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@types/bcryptjs": "^2.4.2",
"@types/js-cookie": "^3.0.3",
"@types/jsonwebtoken": "^9.0.2",
"@types/node": "^18.17.4",
"@types/node": "^20.12.12",
"@types/react": "^18.2.18",
"@types/react-dom": "^18.2.7",
"autoprefixer": "10.4.14",
Expand All @@ -42,11 +42,12 @@
"prettier-plugin-tailwindcss": "0.4.1",
"prisma": "5.9.1",
"tailwindcss": "3.3.3",
"typescript": "5.0.4"
"typescript": "5.4.5"
},
"scripts": {
"build": "next build",
"build:test": "cross-env NODE_ENV=test next build",
"check": "tsc --noEmit",
"dev": "next dev --port 3010",
"dev:offline": "next dev --port 3010",
"dev:test": "cross-env NODE_ENV=test next dev --port 3010",
Expand Down
34 changes: 24 additions & 10 deletions apps/auth/src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ import prisma from 'src/lib/prisma'

export const COOKIE_NAME = 'next-auth.session-token'

interface ExtendedProfile extends Profile {
export interface ExtendedProfile extends Profile {
swissEduPersonUniqueID: string
swissEduIDLinkedAffiliation?: string[]
}

export interface ExtendedUser {
id: string
email: string
role: UserRole
shortname: string
scope: string
catalystInstitutional: boolean
catalystIndividual: boolean
}

function reduceCatalyst(acc: boolean, affiliation: string) {
try {
if (
Expand Down Expand Up @@ -207,12 +217,13 @@ export const authOptions: NextAuthOptions = {

callbacks: {
async signIn({ user, account, profile, email }) {
if (profile?.sub && account?.provider) {
const profileData = profile as ExtendedProfile
if (profileData?.sub && account?.provider) {
const userAccount = await prisma.account.findUnique({
where: {
provider_providerAccountId: {
provider: account.provider,
providerAccountId: profile.sub,
providerAccountId: profileData.sub,
},
},
})
Expand All @@ -221,11 +232,11 @@ export const authOptions: NextAuthOptions = {
const user = await prisma.user.update({
where: { id: userAccount.userId },
data: {
email: profile.email,
email: profileData.email,
lastLoginAt: new Date(),
catalystInstitutional:
(profile.email?.endsWith('uzh.ch') ||
profile.swissEduIDLinkedAffiliation?.reduce<boolean>(
(profileData.email?.endsWith('uzh.ch') ||
profileData.swissEduIDLinkedAffiliation?.reduce<boolean>(
reduceCatalyst,
false
)) ??
Expand All @@ -246,17 +257,20 @@ export const authOptions: NextAuthOptions = {
},

async jwt({ token, user, account, profile, trigger }) {
const profileData = profile as ExtendedProfile
const userData = user as ExtendedUser

if (typeof user !== 'undefined') {
token.shortname = user.shortname
token.shortname = userData.shortname

if (typeof profile?.swissEduPersonUniqueID === 'string') {
if (typeof profileData?.swissEduPersonUniqueID === 'string') {
token.scope = UserLoginScope.ACCOUNT_OWNER
} else {
token.scope = (user as any).scope as UserLoginScope
}

token.catalystInstitutional = user.catalystInstitutional
token.catalystIndividual = user.catalystIndividual
token.catalystInstitutional = userData.catalystInstitutional
token.catalystIndividual = userData.catalystIndividual

token.role = UserRole.USER
}
Expand Down
4 changes: 2 additions & 2 deletions apps/auth/src/pages/api/discourse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export default async function handler(
const nonce = ssoURL.searchParams.get('nonce')
const redirectURL = ssoURL.searchParams.get('return_sso_url')

const userEmail = session.email
const userEmail = session.email!
const userId = session.sub
const userShortname = session.shortname
const userShortname = session.shortname as string
const userRole = session.role

let payload = `nonce=${nonce}&email=${encodeURIComponent(
Expand Down
Loading
Loading