From 8e2695832291f7fc1225bac8210d6b05beefc2f9 Mon Sep 17 00:00:00 2001 From: cchndl <28229098+cchndl@users.noreply.github.com> Date: Thu, 7 Nov 2024 16:00:43 +0100 Subject: [PATCH 1/8] ci(py-sdk): fix python package names (#1486) * ci (py-sdk): fix python package names Python package names are not allowed to contain '-', which is a syntax error. Replace with '_'. * Update python-config.json * Update python-pydantic-v1-config.json --------- Co-authored-by: Jay --- .github/openapi/python-config.json | 4 ++-- .github/openapi/python-pydantic-v1-config.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/openapi/python-config.json b/.github/openapi/python-config.json index 709747cf2..cedb23a7e 100644 --- a/.github/openapi/python-config.json +++ b/.github/openapi/python-config.json @@ -1,5 +1,5 @@ { "generatorName": "python", - "packageName": "scicat-sdk-py", - "projectName": "scicat-sdk-py" + "packageName": "scicat_sdk_py", + "projectName": "scicat_sdk_py" } diff --git a/.github/openapi/python-pydantic-v1-config.json b/.github/openapi/python-pydantic-v1-config.json index ef10d66f2..fc2dac9bf 100644 --- a/.github/openapi/python-pydantic-v1-config.json +++ b/.github/openapi/python-pydantic-v1-config.json @@ -1,5 +1,5 @@ { "generatorName": "python-pydantic-v1", - "packageName": "scicat-sdk-pydantic", - "projectName": "scicat-sdk-pydantic" + "packageName": "scicat_sdk_pydantic", + "projectName": "scicat_sdk_pydantic" } From b42f773ea6cafb2cc2ff289e0016e2b1cd395696 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Nov 2024 15:49:09 +0000 Subject: [PATCH 2/8] build(deps): bump @nestjs/platform-express from 10.4.6 to 10.4.7 Bumps [@nestjs/platform-express](https://github.com/nestjs/nest/tree/HEAD/packages/platform-express) from 10.4.6 to 10.4.7. - [Release notes](https://github.com/nestjs/nest/releases) - [Commits](https://github.com/nestjs/nest/commits/v10.4.7/packages/platform-express) --- updated-dependencies: - dependency-name: "@nestjs/platform-express" dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2e9c80f8a..789c75c6c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2450,9 +2450,9 @@ } }, "node_modules/@nestjs/platform-express": { - "version": "10.4.6", - "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-10.4.6.tgz", - "integrity": "sha512-HcyCpAKccAasrLSGRTGWv5BKRs0rwTIFOSsk6laNyqfqvgvYcJQAedarnm4jmaemtmSJ0PFI9PmtEZADd2ahCg==", + "version": "10.4.7", + "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-10.4.7.tgz", + "integrity": "sha512-q6XDOxZPTZ9cxALcVuKUlRBk+cVEv6dW2S8p2yVre22kpEQxq53/OI8EseDvzObGb6hepZ8+yBY04qoYqSlXNQ==", "dependencies": { "body-parser": "1.20.3", "cors": "2.8.5", From c3e7d1f481846484466ab77ca95b8f46c365a57a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Nov 2024 15:59:46 +0000 Subject: [PATCH 3/8] build(deps): bump @nestjs/axios from 3.1.0 to 3.1.2 Bumps [@nestjs/axios](https://github.com/nestjs/axios) from 3.1.0 to 3.1.2. - [Release notes](https://github.com/nestjs/axios/releases) - [Changelog](https://github.com/nestjs/axios/blob/master/.release-it.json) - [Commits](https://github.com/nestjs/axios/compare/3.1.0...3.1.2) --- updated-dependencies: - dependency-name: "@nestjs/axios" dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 789c75c6c..0da8e3318 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2139,9 +2139,9 @@ } }, "node_modules/@nestjs/axios": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@nestjs/axios/-/axios-3.1.0.tgz", - "integrity": "sha512-CpeK2ickH//ml+H7kX+QPIpeTwER4yedVcw6GPe6Nv58cmKTa0sb+3A3It7ChKD4deW4UKNvZIpYkUk18q78YQ==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@nestjs/axios/-/axios-3.1.2.tgz", + "integrity": "sha512-pFlfi4ZQsZtTNNhvgssbxjCHUd1nMpV3sXy/xOOB2uEJhw3M8j8SFR08gjFNil2we2Har7VCsXLfCkwbMHECFQ==", "peerDependencies": { "@nestjs/common": "^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0", "axios": "^1.3.1", From d772955d6e02abfef3166a4f7f72ebfac9b48d60 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Nov 2024 16:10:46 +0000 Subject: [PATCH 4/8] build(deps): bump @nestjs/common from 10.4.6 to 10.4.7 Bumps [@nestjs/common](https://github.com/nestjs/nest/tree/HEAD/packages/common) from 10.4.6 to 10.4.7. - [Release notes](https://github.com/nestjs/nest/releases) - [Commits](https://github.com/nestjs/nest/commits/v10.4.7/packages/common) --- updated-dependencies: - dependency-name: "@nestjs/common" dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0da8e3318..67e7ecb1d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2288,9 +2288,9 @@ } }, "node_modules/@nestjs/common": { - "version": "10.4.6", - "resolved": "https://registry.npmjs.org/@nestjs/common/-/common-10.4.6.tgz", - "integrity": "sha512-KkezkZvU9poWaNq4L+lNvx+386hpOxPJkfXBBeSMrcqBOx8kVr36TGN2uYkF4Ta4zNu1KbCjmZbc0rhHSg296g==", + "version": "10.4.7", + "resolved": "https://registry.npmjs.org/@nestjs/common/-/common-10.4.7.tgz", + "integrity": "sha512-gIOpjD3Mx8gfYGxYm/RHPcJzqdknNNFCyY+AxzBT3gc5Xvvik1Dn5OxaMGw5EbVfhZgJKVP0n83giUOAlZQe7w==", "dependencies": { "iterare": "1.2.1", "tslib": "2.7.0", From 660f50e6251ebef0be2f448d661310eab5a68588 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Nov 2024 16:21:09 +0000 Subject: [PATCH 5/8] build(deps-dev): bump @faker-js/faker from 9.0.3 to 9.2.0 Bumps [@faker-js/faker](https://github.com/faker-js/faker) from 9.0.3 to 9.2.0. - [Release notes](https://github.com/faker-js/faker/releases) - [Changelog](https://github.com/faker-js/faker/blob/next/CHANGELOG.md) - [Commits](https://github.com/faker-js/faker/compare/v9.0.3...v9.2.0) --- updated-dependencies: - dependency-name: "@faker-js/faker" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 67e7ecb1d..5b8ecee88 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1298,9 +1298,9 @@ } }, "node_modules/@faker-js/faker": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/@faker-js/faker/-/faker-9.0.3.tgz", - "integrity": "sha512-lWrrK4QNlFSU+13PL9jMbMKLJYXDFu3tQfayBsMXX7KL/GiQeqfB1CzHkqD5UHBUtPAuPo6XwGbMFNdVMZObRA==", + "version": "9.2.0", + "resolved": "https://registry.npmjs.org/@faker-js/faker/-/faker-9.2.0.tgz", + "integrity": "sha512-ulqQu4KMr1/sTFIYvqSdegHT8NIkt66tFAkugGnHA+1WAfEn6hMzNR+svjXGFRVLnapxvej67Z/LwchFrnLBUg==", "dev": true, "funding": [ { From 07d62ed366b633b5c16a20e9288d1d4a422f9704 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Nov 2024 16:31:51 +0000 Subject: [PATCH 6/8] build(deps-dev): bump @types/node from 22.8.1 to 22.9.0 Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 22.8.1 to 22.9.0. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5b8ecee88..bdc009447 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3158,9 +3158,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "22.8.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.8.1.tgz", - "integrity": "sha512-k6Gi8Yyo8EtrNtkHXutUu2corfDf9su95VYVP10aGYMMROM6SAItZi0w1XszA6RtWTHSVp5OeFof37w0IEqCQg==", + "version": "22.9.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.9.0.tgz", + "integrity": "sha512-vuyHg81vvWA1Z1ELfvLko2c8f34gyA0zaic0+Rllc5lbCnbSyuvb2Oxpm6TAUAC/2xZN3QGqxBNggD1nNR2AfQ==", "dependencies": { "undici-types": "~6.19.8" } From 82cdb31c555ff081d4f8c98ae9f838b77360c72b Mon Sep 17 00:00:00 2001 From: Jay Date: Tue, 12 Nov 2024 11:29:47 +0100 Subject: [PATCH 7/8] =?UTF-8?q?feat:=20add=20backend=20configuration=20adj?= =?UTF-8?q?ustments=20to=20AdminService=20for=20front=E2=80=A6=20(#1491)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add backend configuration adjustments to AdminService for frontend compatibility * improve unit test for admin service * minor type change * updated README for the new env var --------- Co-authored-by: Max Novelli --- README.md | 1 + src/admin/admin.module.ts | 3 ++- src/admin/admin.service.spec.ts | 46 +++++++++++++++++++++++---------- src/admin/admin.service.ts | 19 +++++++++++++- src/config/configuration.ts | 1 + src/main.ts | 12 ++++++--- 6 files changed, 64 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index b1ffe56a3..1f4c418bb 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,7 @@ Valid environment variables for the .env file. See [.env.example](/.env.example) | `ES_REFRESH` | string | | If set to `wait_for`, Elasticsearch will wait till data is inserted into the specified index before returning a response. | false | | `LOGGERS_CONFIG_FILE` | string | | The file name for loggers configuration, located in the project root directory. | "loggers.json" | | `SWAGGER_PATH` | string | Yes | swaggerPath is the path where the swagger UI will be available| "explorer"| +| `MAX_FILE_UPLOAD_SIZE` | string | Yes | Maximum allowed file upload size | "16mb"| ## Migrating from the old SciCat Backend diff --git a/src/admin/admin.module.ts b/src/admin/admin.module.ts index e0f55e609..abf43368b 100644 --- a/src/admin/admin.module.ts +++ b/src/admin/admin.module.ts @@ -1,10 +1,11 @@ import { Module } from "@nestjs/common"; import { AdminService } from "./admin.service"; import { AdminController } from "./admin.controller"; +import { ConfigModule } from "@nestjs/config"; @Module({ controllers: [AdminController], - imports: [], + imports: [ConfigModule], providers: [AdminService], exports: [AdminService], }) diff --git a/src/admin/admin.service.spec.ts b/src/admin/admin.service.spec.ts index 5b6c3c628..a138a3a38 100644 --- a/src/admin/admin.service.spec.ts +++ b/src/admin/admin.service.spec.ts @@ -1,27 +1,29 @@ -import { getModelToken } from "@nestjs/mongoose"; import { Test, TestingModule } from "@nestjs/testing"; +import { ConfigService } from "@nestjs/config"; import { AdminService } from "./admin.service"; import config from "../config/frontend.config.json"; +import theme from "../config/frontend.theme.json"; -const mockConfig: Record = config; - -describe("PoliciesService", () => { +describe("AdminService", () => { let service: AdminService; + const mockConfigService = { + get: jest.fn((propertyPath: string) => { + const config = { + maxFileUploadSizeInMb: "12mb", + } as Record; + + return config[propertyPath]; + }), + }; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ providers: [ + AdminService, { - provide: getModelToken("Policy"), - useValue: { - new: jest.fn().mockResolvedValue(mockConfig), - constructor: jest.fn().mockResolvedValue(mockConfig), - find: jest.fn(), - create: jest.fn(), - exec: jest.fn(), - }, + provide: ConfigService, + useValue: mockConfigService, }, - AdminService, ], }).compile(); @@ -31,4 +33,22 @@ describe("PoliciesService", () => { it("should be defined", () => { expect(service).toBeDefined(); }); + + describe("getConfig", () => { + it("should return modified config", async () => { + const result = await service.getConfig(); + + expect(result).toEqual({ + ...config, + maxFileUploadSizeInMb: "12mb", + }); + }); + }); + + describe("getTheme", () => { + it("should return theme config", async () => { + const result = await service.getTheme(); + expect(result).toEqual(theme); + }); + }); }); diff --git a/src/admin/admin.service.ts b/src/admin/admin.service.ts index 970ad4b3d..eccad92ab 100644 --- a/src/admin/admin.service.ts +++ b/src/admin/admin.service.ts @@ -1,14 +1,31 @@ import { Injectable } from "@nestjs/common"; import config from "../config/frontend.config.json"; import theme from "../config/frontend.theme.json"; +import { ConfigService } from "@nestjs/config"; @Injectable() export class AdminService { + constructor(private configService: ConfigService) {} + async getConfig(): Promise | null> { - return config; + const modifiedConfig = this.applyBackendConfigAdjustments(); + + return modifiedConfig; } async getTheme(): Promise | null> { return theme; } + + // NOTE: Adjusts backend config values for frontend use (e.g., file upload limits). + // Add future backend-dependent adjustments here as needed. + private applyBackendConfigAdjustments(): Record { + const postEncodedMaxFileUploadSize = + this.configService.get("maxFileUploadSizeInMb") || "16mb"; + + return { + ...config, + maxFileUploadSizeInMb: postEncodedMaxFileUploadSize, + }; + } } diff --git a/src/config/configuration.ts b/src/config/configuration.ts index 94a190d89..1fc02fbdc 100644 --- a/src/config/configuration.ts +++ b/src/config/configuration.ts @@ -58,6 +58,7 @@ const configuration = () => { }); const config = { + maxFileUploadSizeInMb: process.env.MAX_FILE_UPLOAD_SIZE || "16mb", // 16MB by default versions: { api: "3", }, diff --git a/src/main.ts b/src/main.ts index 3af41b802..41ba21153 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,4 @@ import session from "express-session"; -import { json } from "body-parser"; import { NestFactory } from "@nestjs/core"; import { DocumentBuilder, @@ -10,9 +9,10 @@ import { AppModule } from "./app.module"; import { Logger, ValidationPipe, VersioningType } from "@nestjs/common"; import { ConfigService } from "@nestjs/config"; import { AllExceptionsFilter, ScicatLogger } from "./loggers/logger.service"; +import { NestExpressApplication } from "@nestjs/platform-express"; async function bootstrap() { - const app = await NestFactory.create(AppModule, { + const app = await NestFactory.create(AppModule, { bufferLogs: true, }); const configService: ConfigService, false> = app.get( @@ -84,7 +84,13 @@ async function bootstrap() { }), ); - app.use(json({ limit: "16mb" })); + const fileUploadLimitInMb = configService.get("fileUploadLimitInMb"); + + app.useBodyParser("json", { limit: fileUploadLimitInMb }); + app.useBodyParser("urlencoded", { + limit: fileUploadLimitInMb, + extended: true, + }); const expressSessionSecret = configService.get( "expressSessionSecret", From e3c5ca365d0e788bf55f21a24c05c121ae77e7fe Mon Sep 17 00:00:00 2001 From: junjiequan Date: Tue, 12 Nov 2024 16:08:40 +0100 Subject: [PATCH 8/8] fix: correct wrong variable name for fileUploadLimitInMb --- src/main.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 41ba21153..327248a93 100644 --- a/src/main.ts +++ b/src/main.ts @@ -84,7 +84,9 @@ async function bootstrap() { }), ); - const fileUploadLimitInMb = configService.get("fileUploadLimitInMb"); + const fileUploadLimitInMb = configService.get( + "maxFileUploadSizeInMb", + ); app.useBodyParser("json", { limit: fileUploadLimitInMb }); app.useBodyParser("urlencoded", {