Skip to content

Commit

Permalink
Use @nmshd/typescript-ioc and @nmshd/typescript-rest to get rid o…
Browse files Browse the repository at this point in the history
…f vulnerabilities (#283)

* chore: bump libs

* refactor: use new libs

* refactor: update tests

* chore: remove audit excludes

* fix: add typescript-rest package
  • Loading branch information
jkoenig134 authored Oct 14, 2024
1 parent e6d2709 commit ff6f961
Show file tree
Hide file tree
Showing 18 changed files with 168 additions and 598 deletions.
2 changes: 1 addition & 1 deletion .ci/runChecks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ npm run lint:prettier

# auditing
npx license-check --ignoreRegex @nmshd/connector
npx better-npm-audit audit --exclude 1096302,1093639
npx better-npm-audit audit
669 changes: 113 additions & 556 deletions package-lock.json

Large diffs are not rendered by default.

21 changes: 7 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@
"@js-soft/docdb-access-mongo": "1.1.9",
"@js-soft/node-logger": "1.2.0",
"@js-soft/ts-utils": "^2.3.3",
"@nmshd/runtime": "6.3.0",
"@nmshd/runtime": "6.3.1",
"@nmshd/typescript-ioc": "^3.2.4",
"@nmshd/typescript-rest": "^3.0.5",
"agentkeepalive": "4.5.0",
"amqplib": "^0.10.4",
"axios": "^1.7.7",
Expand All @@ -97,25 +99,22 @@
"json-stringify-safe": "5.0.1",
"jsonschema": "1.4.1",
"mqtt": "^5.10.1",
"multer": "^1.4.5-lts.1",
"nconf": "0.12.1",
"on-headers": "1.0.2",
"rapidoc": "9.3.8",
"redis": "^4.7.0",
"reflect-metadata": "0.2.2",
"swagger-ui-express": "5.0.1",
"typescript-ioc": "3.2.2",
"typescript-rest": "3.0.4",
"typescript-rest-ioc": "1.0.1",
"yamljs": "0.3.0"
},
"devDependencies": {
"@apidevtools/swagger-parser": "^10.1.0",
"@js-soft/eslint-config-ts": "1.6.12",
"@js-soft/license-check": "1.0.9",
"@nmshd/connector-sdk": "*",
"@nmshd/content": "6.3.0",
"@nmshd/core-types": "6.3.0",
"@nmshd/content": "6.3.1",
"@nmshd/core-types": "6.3.1",
"@nmshd/typescript-rest-swagger": "^1.4.1",
"@types/amqplib": "^0.10.5",
"@types/compression": "^1.7.5",
"@types/cors": "^2.8.17",
Expand Down Expand Up @@ -144,12 +143,6 @@
"prettier": "^3.3.3",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.6.3",
"typescript-rest-swagger": "github:nmshd/typescript-rest-swagger#1.4.0"
},
"overrides": {
"typescript-rest": {
"multer": "$multer"
}
"typescript": "^5.6.3"
}
}
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"build:schemas:watch": "npx nodemon -e ts -w 'src/types' --exec 'npm run build:schemas'"
},
"dependencies": {
"@nmshd/content": "6.3.0",
"@nmshd/content": "6.3.1",
"axios": "^1.7.7",
"form-data": "^4.0.1",
"qs": "^6.13.0"
Expand Down
26 changes: 23 additions & 3 deletions src/infrastructure/httpServer/HttpServer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { sleep } from "@js-soft/ts-utils";
import { Container } from "@nmshd/typescript-ioc";
import { Server } from "@nmshd/typescript-rest";
import compression from "compression";
import correlator from "correlation-id";
import cors, { CorsOptions } from "cors";
import express, { Application, RequestHandler } from "express";
import helmet, { HelmetOptions } from "helmet";
import http from "http";
import { Server } from "typescript-rest";
import typescriptRestIOC from "typescript-rest-ioc";
import { buildInformation } from "../../buildInformation";
import { ConnectorInfrastructure, InfrastructureConfiguration } from "../ConnectorInfastructure";
import { HttpMethod } from "./HttpMethod";
Expand Down Expand Up @@ -230,7 +230,27 @@ export class HttpServer extends ConnectorInfrastructure<HttpServerConfiguration>
}

private useCustomControllers() {
Server.registerServiceFactory(typescriptRestIOC);
Server.registerServiceFactory({
create: (serviceClass: any) => {
return Container.get(serviceClass);
},
getTargetClass: (serviceClass: Function) => {
let typeConstructor: any = serviceClass;
if (typeConstructor["name"] && typeConstructor["name"] !== "ioc_wrapper") {
return typeConstructor as FunctionConstructor;
}
typeConstructor = typeConstructor["__parent"];
while (typeConstructor) {
if (typeConstructor["name"] && typeConstructor["name"] !== "ioc_wrapper") {
return typeConstructor as FunctionConstructor;
}
typeConstructor = typeConstructor["__parent"];
}

this.logger.error("Can not identify the base Type for requested target: %o", serviceClass);
throw new TypeError("Can not identify the base Type for requested target");
}
});

for (const controller of this.controllers) {
Server.loadControllers(this.app, controller.globs, controller.baseDirectory);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ApplicationError } from "@js-soft/ts-utils";
import { RuntimeErrors } from "@nmshd/runtime";
import { RequestError, TransportCoreErrors } from "@nmshd/transport";
import { Errors } from "@nmshd/typescript-rest";
import express from "express";
import stringify from "json-stringify-safe";
import { Errors } from "typescript-rest";
import { ConnectorMode } from "../../../ConnectorMode";
import { ConnectorLoggerFactory } from "../../../logging/ConnectorLoggerFactory";
import { Envelope, HttpError, HttpErrors } from "../common";
Expand Down
2 changes: 1 addition & 1 deletion src/modules/coreHttpApi/common/BaseController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Result } from "@js-soft/ts-utils";
import { Return } from "@nmshd/typescript-rest";
import express from "express";
import { Return } from "typescript-rest";
import { Envelope } from "../../../infrastructure";

export abstract class BaseController {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/coreHttpApi/controllers/AccountController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TransportServices } from "@nmshd/runtime";
import { Inject } from "typescript-ioc";
import { Accept, GET, Path, POST } from "typescript-rest";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, GET, Path, POST } from "@nmshd/typescript-rest";
import { Envelope } from "../../../infrastructure";
import { BaseController } from "../common/BaseController";

Expand Down
4 changes: 2 additions & 2 deletions src/modules/coreHttpApi/controllers/AttributesController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConsumptionServices, RuntimeErrors, TransportServices } from "@nmshd/runtime";
import { Inject } from "typescript-ioc";
import { Accept, Context, DELETE, GET, POST, Path, PathParam, QueryParam, Return, ServiceContext } from "typescript-rest";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, Context, DELETE, GET, POST, Path, PathParam, QueryParam, Return, ServiceContext } from "@nmshd/typescript-rest";
import { Envelope } from "../../../infrastructure";
import { BaseController } from "../common/BaseController";

Expand Down
4 changes: 2 additions & 2 deletions src/modules/coreHttpApi/controllers/ChallengesController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TransportServices } from "@nmshd/runtime";
import { Inject } from "typescript-ioc";
import { Accept, Path, POST, Return } from "typescript-rest";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, Path, POST, Return } from "@nmshd/typescript-rest";
import { Envelope } from "../../../infrastructure";
import { BaseController } from "../common/BaseController";

Expand Down
4 changes: 2 additions & 2 deletions src/modules/coreHttpApi/controllers/FilesController.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { OwnerRestriction, TransportServices } from "@nmshd/runtime";
import { Reference } from "@nmshd/transport";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, Context, ContextAccept, ContextResponse, Errors, FileParam, FormParam, GET, POST, Path, PathParam, Return, ServiceContext } from "@nmshd/typescript-rest";
import express from "express";
import { Inject } from "typescript-ioc";
import { Accept, Context, ContextAccept, ContextResponse, Errors, FileParam, FormParam, GET, POST, Path, PathParam, Return, ServiceContext } from "typescript-rest";
import { Envelope } from "../../../infrastructure";
import { BaseController, Mimetype } from "../common/BaseController";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConsumptionServices } from "@nmshd/runtime";
import { Inject } from "typescript-ioc";
import { Accept, Context, GET, Path, PathParam, PUT, ServiceContext } from "typescript-rest";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, Context, GET, Path, PathParam, PUT, ServiceContext } from "@nmshd/typescript-rest";
import { Envelope } from "../../../infrastructure";
import { BaseController } from "../common/BaseController";

Expand Down
4 changes: 2 additions & 2 deletions src/modules/coreHttpApi/controllers/MessagesController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TransportServices } from "@nmshd/runtime";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, Context, ContextResponse, GET, Path, PathParam, POST, Return, ServiceContext } from "@nmshd/typescript-rest";
import express from "express";
import { Inject } from "typescript-ioc";
import { Accept, Context, ContextResponse, GET, Path, PathParam, POST, Return, ServiceContext } from "typescript-rest";
import { Envelope } from "../../../infrastructure";
import { BaseController, Mimetype } from "../common/BaseController";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConsumptionServices } from "@nmshd/runtime";
import { Inject } from "typescript-ioc";
import { Accept, Context, GET, Path, PathParam, POST, Return, ServiceContext } from "typescript-rest";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, Context, GET, Path, PathParam, POST, Return, ServiceContext } from "@nmshd/typescript-rest";
import { Envelope } from "../../../infrastructure";
import { BaseController } from "../common/BaseController";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OwnerRestriction, TransportServices } from "@nmshd/runtime";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, Context, ContextAccept, ContextResponse, Errors, GET, POST, Path, PathParam, Return, ServiceContext } from "@nmshd/typescript-rest";
import express from "express";
import { Inject } from "typescript-ioc";
import { Accept, Context, ContextAccept, ContextResponse, Errors, GET, POST, Path, PathParam, Return, ServiceContext } from "typescript-rest";
import { Envelope } from "../../../infrastructure";
import { BaseController, Mimetype } from "../common/BaseController";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TransportServices } from "@nmshd/runtime";
import { Inject } from "typescript-ioc";
import { Accept, Context, DELETE, GET, Path, PathParam, POST, PUT, Return, ServiceContext } from "typescript-rest";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, Context, DELETE, GET, Path, PathParam, POST, PUT, Return, ServiceContext } from "@nmshd/typescript-rest";
import { Envelope } from "../../../infrastructure";
import { BaseController } from "../common/BaseController";

Expand Down
4 changes: 2 additions & 2 deletions src/modules/coreHttpApi/controllers/TokensController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OwnerRestriction, TransportServices } from "@nmshd/runtime";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, Context, ContextAccept, ContextResponse, Errors, GET, Path, PathParam, POST, Return, ServiceContext } from "@nmshd/typescript-rest";
import express from "express";
import { Inject } from "typescript-ioc";
import { Accept, Context, ContextAccept, ContextResponse, Errors, GET, Path, PathParam, POST, Return, ServiceContext } from "typescript-rest";
import { Envelope } from "../../../infrastructure";
import { BaseController, Mimetype } from "../common/BaseController";

Expand Down
2 changes: 1 addition & 1 deletion test/spec.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable jest/no-conditional-in-test */
import swaggerParser from "@apidevtools/swagger-parser";
import { MetadataGenerator, SpecGenerator, Swagger } from "@nmshd/typescript-rest-swagger";
import { OpenAPIV3 } from "openapi-types";
import { MetadataGenerator, SpecGenerator, Swagger } from "typescript-rest-swagger";
import yamljs from "yamljs";

describe("test openapi spec against routes", () => {
Expand Down

0 comments on commit ff6f961

Please sign in to comment.