Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Task/harden validation of scraper configuration in asset profile endpoint (#7322)

Thomas Kaul00c37f026cc1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 85df11fdb5..a0a652c449 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Hardened the validation of the countries in the asset profile endpoints
- Hardened the validation of the holdings in the asset profile endpoints
+- Hardened the validation of the scraper configuration in the asset profile endpoint
- Hardened the validation of the sectors in the asset profile endpoints
- Rounded the value of the _Fear & Greed Index_ (market mood) in the twitter bot service
- Set the change detection strategy to `OnPush` in the _X-ray_ page
diff --git a/libs/common/src/lib/dtos/index.ts b/libs/common/src/lib/dtos/index.ts
index c531313a63..7851153565 100644
--- a/libs/common/src/lib/dtos/index.ts
+++ b/libs/common/src/lib/dtos/index.ts
@@ -12,6 +12,7 @@ import { CreateTagDto } from './create-tag.dto';
import { CreateWatchlistItemDto } from './create-watchlist-item.dto';
import { DeleteOwnUserDto } from './delete-own-user.dto';
import { HoldingDto } from './holding.dto';
+import { ScraperConfigurationDto } from './scraper-configuration.dto';
import { SectorDto } from './sector.dto';
import { TransferBalanceDto } from './transfer-balance.dto';
import { UpdateAccessDto } from './update-access.dto';
@@ -42,6 +43,7 @@ export {
CreateWatchlistItemDto,
DeleteOwnUserDto,
HoldingDto,
+ ScraperConfigurationDto,
SectorDto,
TransferBalanceDto,
UpdateAccessDto,
diff --git a/libs/common/src/lib/dtos/scraper-configuration.dto.ts b/libs/common/src/lib/dtos/scraper-configuration.dto.ts
new file mode 100644
index 0000000000..52cadb80cc
--- /dev/null
+++ b/libs/common/src/lib/dtos/scraper-configuration.dto.ts
@@ -0,0 +1,35 @@
+import {
+ IsIn,
+ IsNumber,
+ IsObject,
+ IsOptional,
+ IsString,
+ IsUrl
+} from 'class-validator';
+
+export class ScraperConfigurationDto {
+ @IsNumber()
+ @IsOptional()
+ defaultMarketPrice?: number;
+
+ @IsObject()
+ @IsOptional()
+ headers?: { [key: string]: string };
+
+ @IsOptional()
+ @IsString()
+ locale?: string;
+
+ @IsIn(['instant', 'lazy'])
+ @IsOptional()
+ mode?: 'instant' | 'lazy';
+
+ @IsString()
+ selector: string;
+
+ @IsUrl({
+ protocols: ['http', 'https'],
+ require_protocol: true
+ })
+ url: string;
+}
diff --git a/libs/common/src/lib/dtos/update-asset-profile.dto.ts b/libs/common/src/lib/dtos/update-asset-profile.dto.ts
index 2204fd0abd..a6e2230e8e 100644
--- a/libs/common/src/lib/dtos/update-asset-profile.dto.ts
+++ b/libs/common/src/lib/dtos/update-asset-profile.dto.ts
@@ -21,6 +21,7 @@ import {
import { CountryDto } from './country.dto';
import { HoldingDto } from './holding.dto';
+import { ScraperConfigurationDto } from './scraper-configuration.dto';
import { SectorDto } from './sector.dto';
export class UpdateAssetProfileDto {
@@ -70,6 +71,8 @@ export class UpdateAssetProfileDto {
@IsObject()
@IsOptional()
+ @Type(() => ScraperConfigurationDto)
+ @ValidateNested()
scraperConfiguration?: Prisma.InputJsonObject;
@IsArray()