From 5c58c64a67b25e8b489462767c2cab1f00bdda56 Mon Sep 17 00:00:00 2001 From: MerlinTheWhiz Date: Tue, 2 Jun 2026 08:14:05 +0100 Subject: [PATCH] chore(tsconfig): enable stricter TypeScript compiler checks --- backend/src/app.ts | 2 +- backend/src/controllers/sse.controller.ts | 1 + backend/src/controllers/stream.controller.ts | 1 - backend/src/controllers/user.controller.ts | 8 +++---- backend/src/lib/prisma-sandbox.ts | 22 -------------------- backend/src/middleware/error.middleware.ts | 2 +- backend/src/services/claimable.service.ts | 5 ----- backend/src/services/sorobanService.ts | 6 +++--- backend/tests/integration/top-up.test.ts | 1 - backend/tests/rate-limiter.test.ts | 2 +- backend/tests/sandbox.middleware.test.ts | 2 +- backend/tests/soroban-indexer.test.ts | 2 +- backend/tests/soroban-worker.helpers.test.ts | 2 +- backend/tests/soroban.service.test.ts | 2 +- backend/tests/sse.service.test.ts | 2 +- backend/tests/stream-rate-limiter.test.ts | 6 +++--- backend/tests/user-summary-cache.test.ts | 1 - backend/tsconfig.json | 6 +++--- package-lock.json | 21 +++++++++++++++++++ 19 files changed, 43 insertions(+), 51 deletions(-) diff --git a/backend/src/app.ts b/backend/src/app.ts index a2cf3f43..582ccc02 100644 --- a/backend/src/app.ts +++ b/backend/src/app.ts @@ -102,7 +102,7 @@ app.use((req: Request, res: Response, next: NextFunction) => { // This was a versioned request, route to v1 handlers return v1Routes(req, res, next); } - next(); // Not versioned, continue to deprecated handlers + return next(); // Not versioned, continue to deprecated handlers }); // Legacy routes (deprecated - redirect to v1) diff --git a/backend/src/controllers/sse.controller.ts b/backend/src/controllers/sse.controller.ts index 7678e65d..9547aaf7 100644 --- a/backend/src/controllers/sse.controller.ts +++ b/backend/src/controllers/sse.controller.ts @@ -80,6 +80,7 @@ export const subscribe = async (req: Request, res: Response) => { res.write(`data: ${JSON.stringify({ type: 'connected', clientId, requestId })}\n\n`); sseService.addClient(clientId, res, subscriptions, sourceIp); + return; } catch (error: unknown) { if (error instanceof z.ZodError) { return res.status(400).json({ diff --git a/backend/src/controllers/stream.controller.ts b/backend/src/controllers/stream.controller.ts index a2fec806..a621a1e0 100644 --- a/backend/src/controllers/stream.controller.ts +++ b/backend/src/controllers/stream.controller.ts @@ -284,7 +284,6 @@ export const getStreamEvents = async (req: Request, res: Response) => { const rawOffset = req.query['offset']; const rawPage = req.query['page']; const cursor = typeof req.query['cursor'] === 'string' ? req.query['cursor'] : undefined; - const direction = req.query['direction'] === 'asc' ? 'asc' as const : 'desc' as const; const order = req.query['order'] === 'asc' ? 'asc' as const : 'desc' as const; const eventType = typeof req.query['eventType'] === 'string' ? req.query['eventType'] : undefined; diff --git a/backend/src/controllers/user.controller.ts b/backend/src/controllers/user.controller.ts index 082205fb..95f6b3d3 100644 --- a/backend/src/controllers/user.controller.ts +++ b/backend/src/controllers/user.controller.ts @@ -30,7 +30,7 @@ export const registerUser = async (req: Request, res: Response, next: NextFuncti logger.info(`User registered: ${publicKey}`); return res.status(201).json(user); } catch (error) { - next(error); + return next(error); } }; @@ -61,7 +61,7 @@ export const getUser = async (req: Request, res: Response, next: NextFunction) = return res.status(200).json(user); } catch (error) { - next(error); + return next(error); } }; @@ -119,7 +119,7 @@ export const getUserEvents = async (req: Request, res: Response, next: NextFunct offset }); } catch (error) { - next(error); + return next(error); } }; @@ -160,6 +160,6 @@ export const getCurrentUser = async (req: Request, res: Response, next: NextFunc return res.status(200).json(user); } catch (error) { - next(error); + return next(error); } }; diff --git a/backend/src/lib/prisma-sandbox.ts b/backend/src/lib/prisma-sandbox.ts index 98b673fa..b6e5ae49 100644 --- a/backend/src/lib/prisma-sandbox.ts +++ b/backend/src/lib/prisma-sandbox.ts @@ -1,32 +1,10 @@ import { PrismaClient } from '../generated/prisma/index.js'; -import { getSandboxConfig } from '../config/sandbox.js'; - -/** - * Sandbox Prisma Client - * - * Uses a separate database connection for sandbox mode to ensure - * complete isolation from production data. - */ const globalForSandboxPrisma = globalThis as unknown as { sandboxPrisma: PrismaClient | undefined; }; -/** - * Get sandbox Prisma client instance - * - * If SANDBOX_DATABASE_URL is set, uses that database. - * Otherwise, uses the default DATABASE_URL with a sandbox suffix. - */ export function getSandboxPrisma(): PrismaClient { - const config = getSandboxConfig(); - - // Use sandbox-specific database URL if provided - const databaseUrl = config.databaseUrl || - (process.env.DATABASE_URL - ? `${process.env.DATABASE_URL}_sandbox` - : 'file:./sandbox.db'); - if (globalForSandboxPrisma.sandboxPrisma) { return globalForSandboxPrisma.sandboxPrisma; } diff --git a/backend/src/middleware/error.middleware.ts b/backend/src/middleware/error.middleware.ts index fc71b12b..252cdfb0 100644 --- a/backend/src/middleware/error.middleware.ts +++ b/backend/src/middleware/error.middleware.ts @@ -49,7 +49,7 @@ export const errorHandler = ( const statusCode = (err instanceof Error && (err as any).status) || (err instanceof Error && (err as any).statusCode) || 500; const message = err instanceof Error ? err.message : 'Internal Server Error'; - res.status(statusCode).json({ + return res.status(statusCode).json({ error: statusCode === 500 ? 'Internal Server Error' : 'Error', message: statusCode === 500 ? 'A technical error occurred. Please try again later.' : message }); diff --git a/backend/src/services/claimable.service.ts b/backend/src/services/claimable.service.ts index 92d66c3b..939ea930 100644 --- a/backend/src/services/claimable.service.ts +++ b/backend/src/services/claimable.service.ts @@ -25,11 +25,6 @@ export interface ClaimableAmountResult { cached: boolean; } -interface ClaimableCacheEntry { - value: Omit; - expiresAtMs: number; -} - interface ClaimableServiceOptions { cacheTtlMs?: number; nowMs?: () => number; diff --git a/backend/src/services/sorobanService.ts b/backend/src/services/sorobanService.ts index 090734e8..ddf05ccc 100644 --- a/backend/src/services/sorobanService.ts +++ b/backend/src/services/sorobanService.ts @@ -1,4 +1,4 @@ -import { rpc, xdr, StrKey, Contract, nativeToScVal, Keypair, TransactionBuilder, Account, Networks } from '@stellar/stellar-sdk'; +import { rpc, xdr, StrKey, Contract, nativeToScVal, Keypair, TransactionBuilder, Networks } from '@stellar/stellar-sdk'; import logger from '../logger.js'; const RPC_URL = process.env.SOROBAN_RPC_URL ?? 'https://soroban-testnet.stellar.org'; @@ -206,7 +206,7 @@ export async function pauseStream( const senderAddr = new Address(senderAddress); - const retval = await simulateContractCall('pause_stream', [ + await simulateContractCall('pause_stream', [ senderAddr.toScVal(), nativeToScVal(streamId, { type: 'u64' }), ]); @@ -240,7 +240,7 @@ export async function resumeStream( const senderAddr = new Address(senderAddress); - const retval = await simulateContractCall('resume_stream', [ + await simulateContractCall('resume_stream', [ senderAddr.toScVal(), nativeToScVal(streamId, { type: 'u64' }), ]); diff --git a/backend/tests/integration/top-up.test.ts b/backend/tests/integration/top-up.test.ts index 9ec3f9fb..e6549e8f 100644 --- a/backend/tests/integration/top-up.test.ts +++ b/backend/tests/integration/top-up.test.ts @@ -77,7 +77,6 @@ vi.mock('../../src/middleware/auth.js', async (importOriginal) => { // App import after mocks import app from '../../src/app.js'; -import { prisma } from '../../src/lib/prisma.js'; import { topUpStream } from '../../src/services/sorobanService.js'; // ── Tests ───────────────────────────────────────────────────────────────────── diff --git a/backend/tests/rate-limiter.test.ts b/backend/tests/rate-limiter.test.ts index 15afd9db..07d43d05 100644 --- a/backend/tests/rate-limiter.test.ts +++ b/backend/tests/rate-limiter.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, beforeEach } from 'vitest'; +import { describe, it, expect } from 'vitest'; import request from 'supertest'; import express from 'express'; import { rateLimit } from 'express-rate-limit'; diff --git a/backend/tests/sandbox.middleware.test.ts b/backend/tests/sandbox.middleware.test.ts index adb5db6c..cc0b3c3c 100644 --- a/backend/tests/sandbox.middleware.test.ts +++ b/backend/tests/sandbox.middleware.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'; -import { sandboxMiddleware, isSandboxRequest, requireSandbox } from '../src/middleware/sandbox.middleware.js'; +import { sandboxMiddleware, requireSandbox } from '../src/middleware/sandbox.middleware.js'; import * as sandboxConfig from '../src/config/sandbox.js'; import type { Response, NextFunction } from 'express'; import type { SandboxRequest } from '../src/middleware/sandbox.middleware.js'; diff --git a/backend/tests/soroban-indexer.test.ts b/backend/tests/soroban-indexer.test.ts index df175cc1..50bb04c7 100644 --- a/backend/tests/soroban-indexer.test.ts +++ b/backend/tests/soroban-indexer.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { describe, it, vi, beforeEach } from 'vitest'; import { sorobanIndexerService } from '../src/services/soroban-indexer.service.js'; vi.mock('../src/logger.js', () => ({ diff --git a/backend/tests/soroban-worker.helpers.test.ts b/backend/tests/soroban-worker.helpers.test.ts index 59ff3461..1730c657 100644 --- a/backend/tests/soroban-worker.helpers.test.ts +++ b/backend/tests/soroban-worker.helpers.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, vi } from 'vitest'; +import { describe, it, expect } from 'vitest'; import { decodeSymbol, decodeU64, decodeI128, decodeAddress, decodeMap } from '../src/workers/soroban-event-worker.js'; import { xdr, StrKey } from '@stellar/stellar-sdk'; diff --git a/backend/tests/soroban.service.test.ts b/backend/tests/soroban.service.test.ts index 8d635a5f..b472eb8b 100644 --- a/backend/tests/soroban.service.test.ts +++ b/backend/tests/soroban.service.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { describe, it, expect } from 'vitest'; import { isStale } from '../src/services/sorobanService.js'; describe('Soroban Service', () => { diff --git a/backend/tests/sse.service.test.ts b/backend/tests/sse.service.test.ts index f8928ff4..58d34a86 100644 --- a/backend/tests/sse.service.test.ts +++ b/backend/tests/sse.service.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; import { EventEmitter } from 'node:events'; -import { SSEService, sseService } from '../src/services/sse.service.js'; +import { SSEService } from '../src/services/sse.service.js'; function createMockResponse() { const emitter = new EventEmitter(); diff --git a/backend/tests/stream-rate-limiter.test.ts b/backend/tests/stream-rate-limiter.test.ts index d1ebdb60..d579e2b6 100644 --- a/backend/tests/stream-rate-limiter.test.ts +++ b/backend/tests/stream-rate-limiter.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest'; +import { describe, it, expect, beforeEach } from 'vitest'; import request from 'supertest'; import express, { type Request, type Response, type NextFunction } from 'express'; import { createStreamRateLimiter } from '../src/middleware/stream-rate-limiter.middleware.js'; @@ -246,7 +246,7 @@ describe('Stream Creation Rate Limiter Middleware', () => { const originalEnv = process.env.STREAM_CREATE_RATE_LIMIT; process.env.STREAM_CREATE_RATE_LIMIT = '5'; - const limiter = createStreamRateLimiter({ windowMs: 10000 }); + createStreamRateLimiter({ windowMs: 10000 }); // The limiter should be created with max: 5 from env // Clean up @@ -262,7 +262,7 @@ describe('Stream Creation Rate Limiter Middleware', () => { delete process.env.STREAM_CREATE_RATE_LIMIT; // The limiter should be created with max: 10 by default - const limiter = createStreamRateLimiter({ windowMs: 10000 }); + createStreamRateLimiter({ windowMs: 10000 }); // Clean up if (originalEnv) { diff --git a/backend/tests/user-summary-cache.test.ts b/backend/tests/user-summary-cache.test.ts index 6643abc1..2cf2a131 100644 --- a/backend/tests/user-summary-cache.test.ts +++ b/backend/tests/user-summary-cache.test.ts @@ -23,7 +23,6 @@ describe('User Summary Cache Pruning (Issue #682)', () => { } const cache = new Map(); - const TTL_MS = 30_000; const pruneCache = (nowMs: number): void => { for (const [key, entry] of cache.entries()) { diff --git a/backend/tsconfig.json b/backend/tsconfig.json index 74629456..69851e52 100644 --- a/backend/tsconfig.json +++ b/backend/tsconfig.json @@ -24,11 +24,11 @@ "noUncheckedIndexedAccess": true, "exactOptionalPropertyTypes": true, // Style Options - // "noImplicitReturns": true, + "noImplicitReturns": true, // "noImplicitOverride": true, - // "noUnusedLocals": true, + "noUnusedLocals": true, // "noUnusedParameters": true, - // "noFallthroughCasesInSwitch": true, + "noFallthroughCasesInSwitch": true, // "noPropertyAccessFromIndexSignature": true, // Recommended Options "strict": true, diff --git a/package-lock.json b/package-lock.json index 8ee3cf03..d4340427 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7438,6 +7438,27 @@ "url": "https://opencollective.com/parcel" } }, + "node_modules/lightningcss/node_modules/lightningcss-darwin-x64": { + "version": "1.31.1", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.31.1.tgz", + "integrity": "sha512-1ObhyoCY+tGxtsz1lSx5NXCj3nirk0Y0kB/g8B8DT+sSx4G9djitg9ejFnjb3gJNWo7qXH4DIy2SUHvpoFwfTA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, "node_modules/lilconfig": { "version": "2.1.0", "dev": true,