diff --git a/package-lock.json b/package-lock.json index c7db867..23816a5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,15 +18,13 @@ "@myrotvorets/facex": "^2.6.1", "@myrotvorets/oav-installer": "^4.1.0", "@myrotvorets/opentelemetry-configurator": "^6.4.1", - "@opentelemetry/instrumentation-express": "^0.33.1", - "@opentelemetry/instrumentation-http": "^0.44.0", "envalid": "^8.0.0", "express": "^4.18.2", "express-openapi-validator": "^5.0.6", "morgan": "^1.10.0" }, "devDependencies": { - "@myrotvorets/eslint-config-myrotvorets-ts": "^2.21.0", + "@myrotvorets/eslint-config-myrotvorets-ts": "^2.22.4", "@types/chai": "^4.3.8", "@types/chai-as-promised": "^7.1.6", "@types/express": "^4.17.19", @@ -340,9 +338,9 @@ } }, "node_modules/@myrotvorets/eslint-config-myrotvorets-ts": { - "version": "2.21.0", - "resolved": "https://npm.pkg.github.com/download/@myrotvorets/eslint-config-myrotvorets-ts/2.21.0/8e57d162bb4245292092bb381e362d1f6fe97da5", - "integrity": "sha512-UNvOj3RbDivCSeeGgJ+l+3E92b0Y8nxfVEK0BUUd55AVpU/LpzgVNo8Ct0f2r5ATPeWt2dAnEpl9iI+8Rv8w4w==", + "version": "2.22.4", + "resolved": "https://npm.pkg.github.com/download/@myrotvorets/eslint-config-myrotvorets-ts/2.22.4/b27eaeb773c75d3b03ad794e3c1634dbfe9d6bf9", + "integrity": "sha512-ZQGyLWRvET3jXZfZZOu9VJL16IuIxroCmwRMfCF87ueHXRz7wiNTiDmYkP+lNSQqWb6LX31HbZVUBDpoVHGPzA==", "dev": true, "license": "MIT", "dependencies": { @@ -891,63 +889,6 @@ "@opentelemetry/api": "^1.3.0" } }, - "node_modules/@opentelemetry/instrumentation-http": { - "version": "0.44.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/instrumentation-http/-/instrumentation-http-0.44.0.tgz", - "integrity": "sha512-Nlvj3Y2n9q6uIcQq9f33HbcB4Dr62erSwYA37+vkorYnzI2j9PhxKitocRTZnbYsrymYmQJW9mdq/IAfbtVnNg==", - "dependencies": { - "@opentelemetry/core": "1.17.1", - "@opentelemetry/instrumentation": "0.44.0", - "@opentelemetry/semantic-conventions": "1.17.1", - "semver": "^7.5.2" - }, - "engines": { - "node": ">=14" - }, - "peerDependencies": { - "@opentelemetry/api": "^1.3.0" - } - }, - "node_modules/@opentelemetry/instrumentation-http/node_modules/@opentelemetry/core": { - "version": "1.17.1", - "resolved": "https://registry.npmjs.org/@opentelemetry/core/-/core-1.17.1.tgz", - "integrity": "sha512-I6LrZvl1FF97FQXPR0iieWQmKnGxYtMbWA1GrAXnLUR+B1Hn2m8KqQNEIlZAucyv00GBgpWkpllmULmZfG8P3g==", - "dependencies": { - "@opentelemetry/semantic-conventions": "1.17.1" - }, - "engines": { - "node": ">=14" - }, - "peerDependencies": { - "@opentelemetry/api": ">=1.0.0 <1.7.0" - } - }, - "node_modules/@opentelemetry/instrumentation-http/node_modules/@opentelemetry/instrumentation": { - "version": "0.44.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/instrumentation/-/instrumentation-0.44.0.tgz", - "integrity": "sha512-B6OxJTRRCceAhhnPDBshyQO7K07/ltX3quOLu0icEvPK9QZ7r9P1y0RQX8O5DxB4vTv4URRkxkg+aFU/plNtQw==", - "dependencies": { - "@types/shimmer": "^1.0.2", - "import-in-the-middle": "1.4.2", - "require-in-the-middle": "^7.1.1", - "semver": "^7.5.2", - "shimmer": "^1.2.1" - }, - "engines": { - "node": ">=14" - }, - "peerDependencies": { - "@opentelemetry/api": "^1.3.0" - } - }, - "node_modules/@opentelemetry/instrumentation-http/node_modules/@opentelemetry/semantic-conventions": { - "version": "1.17.1", - "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.17.1.tgz", - "integrity": "sha512-xbR2U+2YjauIuo42qmE8XyJK6dYeRMLJuOlUP5SO4auET4VtOHOzgkRVOq+Ik18N+Xf3YPcqJs9dZMiDddz1eQ==", - "engines": { - "node": ">=14" - } - }, "node_modules/@opentelemetry/otlp-exporter-base": { "version": "0.43.0", "resolved": "https://registry.npmjs.org/@opentelemetry/otlp-exporter-base/-/otlp-exporter-base-0.43.0.tgz", diff --git a/package.json b/package.json index 493cce9..8178c7b 100644 --- a/package.json +++ b/package.json @@ -25,15 +25,13 @@ "@myrotvorets/facex": "^2.6.1", "@myrotvorets/oav-installer": "^4.1.0", "@myrotvorets/opentelemetry-configurator": "^6.4.1", - "@opentelemetry/instrumentation-express": "^0.33.1", - "@opentelemetry/instrumentation-http": "^0.44.0", "envalid": "^8.0.0", "express": "^4.18.2", "express-openapi-validator": "^5.0.6", "morgan": "^1.10.0" }, "devDependencies": { - "@myrotvorets/eslint-config-myrotvorets-ts": "^2.21.0", + "@myrotvorets/eslint-config-myrotvorets-ts": "^2.22.4", "@types/chai": "^4.3.8", "@types/chai-as-promised": "^7.1.6", "@types/express": "^4.17.19", diff --git a/src/controllers/video.mts b/src/controllers/video.mts index 73bb968..3af361f 100644 --- a/src/controllers/video.mts +++ b/src/controllers/video.mts @@ -14,7 +14,7 @@ interface UploadResponse { function uploadHandler(service: VideoService): RequestHandler { // eslint-disable-next-line @typescript-eslint/no-misused-promises return async (req: Request, res: Response): Promise => { - const guid = await service.upload((req.files as Express.Multer.File[])[0]); + const guid = await service.upload((req.files as Express.Multer.File[])[0]!); res.json({ success: true, guid, diff --git a/src/lib/tracing.mts b/src/lib/tracing.mts index 8f72aea..b549e7c 100644 --- a/src/lib/tracing.mts +++ b/src/lib/tracing.mts @@ -1,15 +1,9 @@ /* c8 ignore start */ -import { OpenTelemetryConfigurator } from '@myrotvorets/opentelemetry-configurator'; -import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'; -import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express'; - -if (!+(process.env.ENABLE_TRACING || 0)) { - process.env.OTEL_SDK_DISABLED = 'true'; -} +import { OpenTelemetryConfigurator, getExpressInstrumentations } from '@myrotvorets/opentelemetry-configurator'; const configurator = new OpenTelemetryConfigurator({ serviceName: 'psb-api-videntigraf', - instrumentations: [new ExpressInstrumentation(), new HttpInstrumentation()], + instrumentations: [...getExpressInstrumentations()], }); configurator.start(); diff --git a/src/middleware/error.mts b/src/middleware/error.mts index 7c68c63..7ed3d0d 100644 --- a/src/middleware/error.mts +++ b/src/middleware/error.mts @@ -8,31 +8,35 @@ import { BadRequestError } from '../lib/badrequesterror.mjs'; export function faceXErrorHandlerMiddleware(err: unknown, req: Request, res: Response, next: NextFunction): void { if (err && typeof err === 'object') { if (err instanceof UploadError) { - return next({ + next({ success: false, status: 400, code: 'UPLOAD_FAILED', message: `${err.message} (${err.file})`, }); + return; } if (err instanceof HttpError || err instanceof NetworkError || err instanceof BadResponseError) { - return next(badGatewayFromError(err)); + next(badGatewayFromError(err)); + return; } if (err instanceof BadRequestError) { - return next({ + next({ success: false, status: 400, code: 'BAD_REQUEST', message: `${err.message}`, }); + return; } if (err instanceof FaceXError) { - return next(errorResponseFromFaceXError(err)); + next(errorResponseFromFaceXError(err)); + return; } } - return next(err); + next(err); } diff --git a/src/middleware/upload.mts b/src/middleware/upload.mts index eef6cb5..f5c67d7 100644 --- a/src/middleware/upload.mts +++ b/src/middleware/upload.mts @@ -26,8 +26,8 @@ export function uploadErrorHandlerMiddleware(err: unknown, _req: Request, _res: break; } - return next(response); + next(response); + } else { + next(err); } - - return next(err); } diff --git a/src/server.mts b/src/server.mts index d455ffc..aa20f80 100644 --- a/src/server.mts +++ b/src/server.mts @@ -42,7 +42,7 @@ export async function configureApp(app: Express): Promise { ); /* c8 ignore start */ - if (process.env.HAVE_SWAGGER === 'true') { + if (process.env['HAVE_SWAGGER'] === 'true') { app.get('/', (_req, res) => res.redirect('/swagger/')); } /* c8 ignore stop */ diff --git a/src/services/video.mts b/src/services/video.mts index 97860cb..1d43c48 100644 --- a/src/services/video.mts +++ b/src/services/video.mts @@ -39,10 +39,10 @@ export class VideoService { const attrs = response.attributes(); return { - detections: +attrs.d || 0, - matches: +attrs.m || 0, - d_archives: +attrs.d_arx || 0, - m_archives: +attrs.m_arx || 0, + detections: +(attrs['d'] ?? 0), + matches: +(attrs['m'] ?? 0), + d_archives: +(attrs['d_arx'] ?? 0), + m_archives: +(attrs['m_arx'] ?? 0), }; } diff --git a/test/functional/controllers/monitoring.test.mts b/test/functional/controllers/monitoring.test.mts index 4d4a12f..62e301c 100644 --- a/test/functional/controllers/monitoring.test.mts +++ b/test/functional/controllers/monitoring.test.mts @@ -1,7 +1,6 @@ import express, { type Express } from 'express'; import { expect } from 'chai'; import request from 'supertest'; -import type { HealthChecker } from '@cloudnative/health-connect'; import { healthChecker, monitoringController } from '../../../src/controllers/monitoring.mjs'; describe('MonitoringController', function () { @@ -15,7 +14,7 @@ describe('MonitoringController', function () { beforeEach(function () { expect(healthChecker).not.to.be.undefined; - (healthChecker as HealthChecker).shutdownRequested = false; + healthChecker!.shutdownRequested = false; }); afterEach(function () { @@ -26,7 +25,7 @@ describe('MonitoringController', function () { request(app).get(`/monitoring/${endpoint}`).expect('Content-Type', /json/u).expect(200); const checker503 = (endpoint: string): Promise => { - (healthChecker as HealthChecker).shutdownRequested = true; + healthChecker!.shutdownRequested = true; return request(app).get(`/monitoring/${endpoint}`).expect('Content-Type', /json/u).expect(503); }; diff --git a/test/unit/services/fakeclient.mts b/test/unit/services/fakeclient.mts index ed044e9..da7e69c 100644 --- a/test/unit/services/fakeclient.mts +++ b/test/unit/services/fakeclient.mts @@ -15,15 +15,15 @@ export const getVideoStatus = func(); export class FakeFaceXVideoClient extends FaceXVideoClient { - public uploadVideo(video: VideoType, priority?: VideoUploadPriority): Promise { + public override uploadVideo(video: VideoType, priority?: VideoUploadPriority): Promise { return uploadVideo(video, priority); } - public getVideoStatus(guid: string): Promise { + public override getVideoStatus(guid: string): Promise { return getVideoStatus(guid); } - public getVideoResult(guid: string, type: VideoResultType, archiveNumber?: number): Promise { + public override getVideoResult(guid: string, type: VideoResultType, archiveNumber?: number): Promise { return getVideoResult(guid, type, archiveNumber); } } diff --git a/tsconfig.json b/tsconfig.json index f61af0b..7f4d1bc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,6 +13,10 @@ "noUnusedLocals": true, "noUnusedParameters": false, "noFallthroughCasesInSwitch": true, + "noPropertyAccessFromIndexSignature": true, + "noUncheckedIndexedAccess": true, + "noImplicitOverride": true, + "noImplicitReturns": true, "esModuleInterop": true, "resolveJsonModule": true },