From 44d4160a11f88e1fda65803b9c74e7c967db3129 Mon Sep 17 00:00:00 2001 From: Sebastian Klingler Date: Tue, 16 Apr 2024 14:51:34 -0500 Subject: [PATCH] Fix ddex webapp client lint (#8127) --- packages/ddex/webapp/server/.eslintrc.cjs | 29 ++--------------- packages/ddex/webapp/server/src/app.ts | 30 +++++++++--------- .../src/controllers/collectionController.ts | 4 +-- packages/ddex/webapp/server/src/index.ts | 31 ++++++++++--------- .../server/src/routers/collectionRouters.ts | 6 ++-- .../ddex/webapp/server/src/routers/index.ts | 13 ++++---- .../webapp/server/src/routers/uploadRouter.ts | 5 +-- .../webapp/server/src/services/dbService.ts | 2 +- .../ddex/webapp/server/src/services/s3.ts | 8 ++--- .../webapp/server/src/services/sdkService.ts | 16 +++++----- packages/ddex/webapp/server/src/trpc.ts | 2 +- packages/ddex/webapp/server/src/userSchema.ts | 5 +-- 12 files changed, 66 insertions(+), 85 deletions(-) diff --git a/packages/ddex/webapp/server/.eslintrc.cjs b/packages/ddex/webapp/server/.eslintrc.cjs index aa81f41fe30..f8af33259c5 100644 --- a/packages/ddex/webapp/server/.eslintrc.cjs +++ b/packages/ddex/webapp/server/.eslintrc.cjs @@ -1,30 +1,5 @@ module.exports = { root: true, env: { node: true, es2020: true }, - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/recommended', - 'prettier', - 'plugin:prettier/recommended', - ], - ignorePatterns: ['dist', '.eslintrc.cjs'], - parser: '@typescript-eslint/parser', - plugins: ['prettier'], - rules: { - '@typescript-eslint/no-unsafe-call': 'off', - '@typescript-eslint/no-unsafe-assignment': 'off', - '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/no-non-null-assertion': 'off', - '@typescript-eslint/no-empty-function': 'off', - 'prettier/prettier': ['error', { - singleQuote: true, - semi: false, - useTabs: false, - tabWidth: 2, - trailingComma: 'es5', - printWidth: 80, - bracketSpacing: true, - arrowParens: 'always', - }], - }, -}; + extends: ['audius'] +} diff --git a/packages/ddex/webapp/server/src/app.ts b/packages/ddex/webapp/server/src/app.ts index 758e08a04e7..80ce32479b7 100644 --- a/packages/ddex/webapp/server/src/app.ts +++ b/packages/ddex/webapp/server/src/app.ts @@ -1,10 +1,12 @@ -import express, { Express, NextFunction, Request, Response } from 'express' import path from 'path' -import session from 'express-session' + +import { ProfilePicture } from '@audius/sdk' import connectMongoDBSession from 'connect-mongodb-session' -import User from './userSchema' +import express, { Express, NextFunction, Request, Response } from 'express' +import session from 'express-session' + import createSdkService from './services/sdkService' -import { ProfilePicture } from '@audius/sdk' +import User from './userSchema' declare module 'express-session' { interface SessionData { @@ -39,10 +41,10 @@ export default function createApp( const MongoDBStore = connectMongoDBSession(session) const store = new MongoDBStore({ uri: dbUrl, - collection: 'authSessions', + collection: 'authSessions' }) store.on('error', function (error: any) { - console.log(error) + console.error(error) }) if (!process.env.SESSION_SECRET) { @@ -52,12 +54,12 @@ export default function createApp( const sess: session.SessionOptions = { secret: process.env.SESSION_SECRET, cookie: { - maxAge: 1000 * 60 * 60 * 24 * 7 * 3, // 3 weeks + maxAge: 1000 * 60 * 60 * 24 * 7 * 3 // 3 weeks }, store, resave: false, saveUninitialized: false, - rolling: true, // Reset maxAge on every response + rolling: true // Reset maxAge on every response } if (app.get('env') === 'production') { @@ -79,7 +81,7 @@ export default function createApp( // The frontend does this for the user on OAuth (there's no actual login button UI) and re-checks the session via /auth/session on page load. app.post('/auth/login', async (req: Request, res: Response) => { const decodedJwt = await sdkService.users.verifyIDToken({ - token: req.body.token, + token: req.body.token }) if (decodedJwt?.data) { const { userId, handle, email, name, verified, profilePicture } = @@ -90,7 +92,7 @@ export default function createApp( email, name, verified, - profilePicture, + profilePicture }) req.session.user = { @@ -100,7 +102,7 @@ export default function createApp( name: user.name, verified: user.verified, profilePicture: user.profilePicture, - isAdmin: user.isAdmin, + isAdmin: user.isAdmin } req.session.save((err) => { @@ -136,7 +138,7 @@ export default function createApp( name: updatedUser.name, verified: updatedUser.verified, profilePicture: updatedUser.profilePicture, - isAdmin: updatedUser.isAdmin, + isAdmin: updatedUser.isAdmin } req.session.save((err) => { if (err) { @@ -175,8 +177,8 @@ export default function createApp( data: { env: process.env.NODE_ENV, ddexKey: process.env.DDEX_KEY, - ddexChoreography: process.env.DDEX_CHOREOGRAPHY, - }, + ddexChoreography: process.env.DDEX_CHOREOGRAPHY + } } res.json(envData) }) diff --git a/packages/ddex/webapp/server/src/controllers/collectionController.ts b/packages/ddex/webapp/server/src/controllers/collectionController.ts index ec384195678..f0508ab8dc3 100644 --- a/packages/ddex/webapp/server/src/controllers/collectionController.ts +++ b/packages/ddex/webapp/server/src/controllers/collectionController.ts @@ -1,11 +1,11 @@ import { Request, Response } from 'express' -import mongoose from 'mongoose' import { Sort } from 'mongodb' +import mongoose from 'mongoose' export const collections = [ 'deliveries', 'pending_releases', - 'published_releases', + 'published_releases' ] export const getCollection = (collection: string) => { diff --git a/packages/ddex/webapp/server/src/index.ts b/packages/ddex/webapp/server/src/index.ts index f4642ba10da..c46eb0ec62e 100644 --- a/packages/ddex/webapp/server/src/index.ts +++ b/packages/ddex/webapp/server/src/index.ts @@ -1,6 +1,16 @@ -import dotenv from 'dotenv' import path from 'path' + +import * as trpcExpress from '@trpc/server/adapters/express' +import dotenv from 'dotenv' + +import createApp from './app' +import createAppRouter from './routers' +import collectionRouters from './routers/collectionRouters' +import makeUploadRouter from './routers/uploadRouter' +import { dialDb } from './services/dbService' import createS3 from './services/s3' +import createSdkService from './services/sdkService' +import { createContext, router } from './trpc' // Load env vars from ddex package root dotenv.config({ path: path.join(__dirname, '..', '..', '..', '.env') }) @@ -17,15 +27,6 @@ switch (process.env.NETWORK) { process.env.NODE_ENV = 'development' } -import createApp from './app' -import { dialDb } from './services/dbService' -import { createContext, router } from './trpc' -import * as trpcExpress from '@trpc/server/adapters/express' -import collectionRouters from './routers/collectionRouters' -import makeUploadRouter from './routers/uploadRouter' -import createAppRouter from './routers' -import createSdkService from './services/sdkService' - // TODO: Use superjson export type AppRouter = ReturnType @@ -45,9 +46,9 @@ const port = process.env.DDEX_PORT || 9000 const s3 = createS3() const appRouter = router({ upload: makeUploadRouter(s3), - deliveries: collectionRouters['deliveries'], - pendingReleases: collectionRouters['pending_releases'], - publishedReleases: collectionRouters['published_releases'], + deliveries: collectionRouters.deliveries, + pendingReleases: collectionRouters.pending_releases, + publishedReleases: collectionRouters.published_releases }) app.use( @@ -55,12 +56,12 @@ const port = process.env.DDEX_PORT || 9000 isAuthedAsAdmin, trpcExpress.createExpressMiddleware({ router: appRouter, - createContext: (opts) => createContext(opts, {}), + createContext: (opts) => createContext(opts, {}) }) ) app.listen(port, () => { - console.log(`[server]: Server is running at http://localhost:${port}`) + console.info(`[server]: Server is running at http://localhost:${port}`) }) } catch (error) { console.error('Failed to initialize:', error) diff --git a/packages/ddex/webapp/server/src/routers/collectionRouters.ts b/packages/ddex/webapp/server/src/routers/collectionRouters.ts index 607dc07d15a..5920adf8642 100644 --- a/packages/ddex/webapp/server/src/routers/collectionRouters.ts +++ b/packages/ddex/webapp/server/src/routers/collectionRouters.ts @@ -1,9 +1,9 @@ +import { Sort } from 'mongodb' +import mongoose from 'mongoose' import { z } from 'zod' -import { router, publicProcedure } from '../trpc' import { collections } from '../controllers/collectionController' -import mongoose from 'mongoose' -import { Sort } from 'mongodb' +import { router, publicProcedure } from '../trpc' const getCollectionInput = z.object({ nextId: z.string().optional(), diff --git a/packages/ddex/webapp/server/src/routers/index.ts b/packages/ddex/webapp/server/src/routers/index.ts index f08dbde5921..47b1f5c3aaf 100644 --- a/packages/ddex/webapp/server/src/routers/index.ts +++ b/packages/ddex/webapp/server/src/routers/index.ts @@ -1,14 +1,15 @@ -import { router } from '../trpc' import createS3 from '../services/s3' -import makeUploadRouter from './uploadRouter' +import { router } from '../trpc' + import collectionRouters from './collectionRouters' +import makeUploadRouter from './uploadRouter' export default function createAppRouter(s3: ReturnType) { return router({ upload: makeUploadRouter(s3), - uploads: collectionRouters['uploads'], - deliveries: collectionRouters['deliveries'], - pendingReleases: collectionRouters['pending_releases'], - publishedReleases: collectionRouters['published_releases'], + uploads: collectionRouters.uploads, + deliveries: collectionRouters.deliveries, + pendingReleases: collectionRouters.pending_releases, + publishedReleases: collectionRouters.published_releases }) } diff --git a/packages/ddex/webapp/server/src/routers/uploadRouter.ts b/packages/ddex/webapp/server/src/routers/uploadRouter.ts index c5a3a5e0fcc..53294419df7 100644 --- a/packages/ddex/webapp/server/src/routers/uploadRouter.ts +++ b/packages/ddex/webapp/server/src/routers/uploadRouter.ts @@ -1,4 +1,5 @@ import { z } from 'zod' + import createS3 from '../services/s3' import { router, publicProcedure } from '../trpc' @@ -7,12 +8,12 @@ export default function makeUploadRouter(s3: ReturnType) { generateSignedUrl: publicProcedure .input( z.object({ - fileName: z.string(), + fileName: z.string() }) ) .mutation(async ({ input }) => { const { fileName } = input return await s3.getSignedFileUrl(fileName) - }), + }) }) } diff --git a/packages/ddex/webapp/server/src/services/dbService.ts b/packages/ddex/webapp/server/src/services/dbService.ts index 0dd46437f9e..068cc7680a3 100644 --- a/packages/ddex/webapp/server/src/services/dbService.ts +++ b/packages/ddex/webapp/server/src/services/dbService.ts @@ -2,5 +2,5 @@ import mongoose from 'mongoose' export const dialDb = async (dbUrl: string) => { await mongoose.connect(dbUrl) - console.log('MongoDB connected...') + console.info('MongoDB connected...') } diff --git a/packages/ddex/webapp/server/src/services/s3.ts b/packages/ddex/webapp/server/src/services/s3.ts index 35dda451e76..cfd24697a30 100644 --- a/packages/ddex/webapp/server/src/services/s3.ts +++ b/packages/ddex/webapp/server/src/services/s3.ts @@ -1,5 +1,5 @@ -import { getSignedUrl } from '@aws-sdk/s3-request-presigner' import { S3Client, PutObjectCommand, S3ClientConfig } from '@aws-sdk/client-s3' +import { getSignedUrl } from '@aws-sdk/s3-request-presigner' export default function createS3() { if (!process.env.AWS_ACCESS_KEY_ID || !process.env.AWS_SECRET_ACCESS_KEY) { @@ -9,9 +9,9 @@ export default function createS3() { const config: S3ClientConfig = { credentials: { accessKeyId: process.env.AWS_ACCESS_KEY_ID, - secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, + secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY }, - region: process.env.AWS_REGION, + region: process.env.AWS_REGION } const bucket = process.env.AWS_BUCKET_RAW const client = new S3Client(config) @@ -22,7 +22,7 @@ export default function createS3() { ) { const command = new PutObjectCommand({ Bucket: bucket, - Key: fileName, + Key: fileName }) return await getSignedUrl(client, command, { expiresIn: expiresInSeconds }) diff --git a/packages/ddex/webapp/server/src/services/sdkService.ts b/packages/ddex/webapp/server/src/services/sdkService.ts index 6d2bea36b61..82fb65754bb 100644 --- a/packages/ddex/webapp/server/src/services/sdkService.ts +++ b/packages/ddex/webapp/server/src/services/sdkService.ts @@ -8,7 +8,7 @@ import { developmentConfig, stagingConfig, productionConfig, - sdk, + sdk } from '@audius/sdk' const createSdkService = async (): Promise => { @@ -52,13 +52,13 @@ const createSdkService = async (): Promise => { // Init SDK const discoveryNodeSelector = new DiscoveryNodeSelector({ - initialSelectedNode, + initialSelectedNode }) const storageNodeSelector = new StorageNodeSelector({ auth: new AppAuth(ddexKey, ddexSecret), - discoveryNodeSelector: discoveryNodeSelector, + discoveryNodeSelector, bootstrapNodes: config.storageNodes, - logger, + logger }) const sdkInstance = sdk({ services: { @@ -69,16 +69,16 @@ const createSdkService = async (): Promise => { contractAddress: config.entityManagerContractAddress, identityServiceUrl: config.identityServiceUrl, useDiscoveryRelay: true, - logger, + logger }), storageNodeSelector, - logger, + logger }, apiKey: ddexKey, apiSecret: ddexSecret, - appName: 'DDEX Demo', + appName: 'DDEX Demo' }) - console.log(`SDK initialized for ${env}`) + console.info(`SDK initialized for ${env}`) return sdkInstance } catch (error) { throw new Error(`SDK failed to initialize for ${env}: ${error}`) diff --git a/packages/ddex/webapp/server/src/trpc.ts b/packages/ddex/webapp/server/src/trpc.ts index 8b606a468da..0ca761d717c 100644 --- a/packages/ddex/webapp/server/src/trpc.ts +++ b/packages/ddex/webapp/server/src/trpc.ts @@ -12,7 +12,7 @@ export function createContext( return { req: options.req, res: options.res, - ...customContext, + ...customContext } } diff --git a/packages/ddex/webapp/server/src/userSchema.ts b/packages/ddex/webapp/server/src/userSchema.ts index 67f11591603..99f7147530a 100644 --- a/packages/ddex/webapp/server/src/userSchema.ts +++ b/packages/ddex/webapp/server/src/userSchema.ts @@ -1,5 +1,6 @@ import type { ProfilePicture } from '@audius/sdk' import mongoose from 'mongoose' + import { decodeHashedId, isUserAdmin } from './utils' export interface IUser { @@ -16,7 +17,7 @@ export interface IUser { const profilePictureSchema = new mongoose.Schema({ '150x150': String, '480x480': String, - '1000x1000': String, + '1000x1000': String }) interface IUserMethods { @@ -38,7 +39,7 @@ const userSchema = new mongoose.Schema({ name: String, verified: { type: Boolean, default: false }, profilePicture: { type: profilePictureSchema, default: null }, - isAdmin: { type: Boolean, default: false }, + isAdmin: { type: Boolean, default: false } }) userSchema.method('updateRoles', async function updateRoles() {