Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Selfhosted: Move project ID validation to DTOs

Blue Mouse31b6252274e3
diff --git a/backend/apps/production/src/analytics/analytics.controller.ts b/backend/apps/production/src/analytics/analytics.controller.ts
index 5fe27cd80..93c3d73e4 100644
--- a/backend/apps/production/src/analytics/analytics.controller.ts
+++ b/backend/apps/production/src/analytics/analytics.controller.ts
@@ -96,6 +96,7 @@ import { extensions } from './utils/ua-parser'
import { GetOverallStatsDto } from './dto/get-overall-stats.dto'
import { NoscriptDto } from './dto/noscript.dto'
import { LiveVisitorsDto } from './dto/live-visitors.dto'
+import { GetHeartbeatStatsDto } from './dto/get-heartbeat-stats'
dayjs.extend(utc)
dayjs.extend(dayjsTimezone)
@@ -978,7 +979,7 @@ export class AnalyticsController {
@Get('hb')
async getHeartBeatStats(
- @Query() data,
+ @Query() data: GetHeartbeatStatsDto,
@CurrentUserId() uid: string,
@Headers() headers: { 'x-password'?: string },
): Promise<object> {
diff --git a/backend/apps/production/src/analytics/dto/get-heartbeat-stats.ts b/backend/apps/production/src/analytics/dto/get-heartbeat-stats.ts
new file mode 100644
index 000000000..a65be160e
--- /dev/null
+++ b/backend/apps/production/src/analytics/dto/get-heartbeat-stats.ts
@@ -0,0 +1,20 @@
+import { IsOptional, Matches, ValidateIf } from 'class-validator'
+import { ApiProperty } from '@nestjs/swagger'
+import { PID_REGEX } from '../../common/constants'
+
+export class GetHeartbeatStatsDto {
+ @ApiProperty({ description: 'Array of project IDs', required: false })
+ @ValidateIf(o => o.pids || !o.pid)
+ @IsOptional()
+ @Matches(PID_REGEX, {
+ message: 'One of the provided Project IDs (pids) is incorrect',
+ each: true,
+ })
+ pids?: string[]
+
+ @ApiProperty({ description: 'Single project ID', required: false })
+ @ValidateIf(o => !o.pids || o.pid)
+ @IsOptional()
+ @Matches(PID_REGEX, { message: 'The provided Project ID (pid) is incorrect' })
+ pid?: string
+}
diff --git a/backend/apps/selfhosted/src/analytics/analytics.controller.ts b/backend/apps/selfhosted/src/analytics/analytics.controller.ts
index a31d3afd3..bd73bbfae 100644
--- a/backend/apps/selfhosted/src/analytics/analytics.controller.ts
+++ b/backend/apps/selfhosted/src/analytics/analytics.controller.ts
@@ -37,8 +37,8 @@ import { VALID_PERIODS } from './decorators/validate-period.decorator'
import { CurrentUserId } from '../auth/decorators/current-user-id.decorator'
import { DEFAULT_TIMEZONE } from '../user/entities/user.entity'
import { RolesGuard } from '../auth/guards/roles.guard'
-import { PageviewsDTO } from './dto/pageviews.dto'
-import { EventsDTO } from './dto/events.dto'
+import { PageviewsDto } from './dto/pageviews.dto'
+import { EventsDto } from './dto/events.dto'
import { GetDataDto, ChartRenderMode } from './dto/getData.dto'
import { GetFiltersDto } from './dto/get-filters.dto'
import { GetCustomEventMetadata } from './dto/get-custom-event-meta.dto'
@@ -63,10 +63,10 @@ import {
} from './interfaces'
import { GetSessionsDto } from './dto/get-sessions.dto'
import { GetSessionDto } from './dto/get-session.dto'
-import { ErrorDTO } from './dto/error.dto'
+import { ErrorDto } from './dto/error.dto'
import { GetErrorsDto } from './dto/get-errors.dto'
-import { GetErrorDTO } from './dto/get-error.dto'
-import { PatchStatusDTO } from './dto/patch-status.dto'
+import { GetErrorDto } from './dto/get-error.dto'
+import { PatchStatusDto } from './dto/patch-status.dto'
import {
customEventTransformer,
errorEventTransformer,
@@ -76,6 +76,9 @@ import {
import { MAX_METRICS_IN_VIEW } from '../project/dto/create-project-view.dto'
import { extensions } from './utils/ua-parser'
import { GetOverallStatsDto } from './dto/get-overall-stats.dto'
+import { GetHeartbeatStatsDto } from './dto/get-heartbeat-stats'
+import { LiveVisitorsDto } from './dto/live-visitors.dto'
+import { NoscriptDto } from './dto/noscript.dto'
dayjs.extend(utc)
dayjs.extend(dayjsTimezone)
@@ -191,7 +194,6 @@ export class AnalyticsController {
mode = ChartRenderMode.PERIODICAL,
metrics,
} = data
- this.analyticsService.validatePID(pid)
await this.analyticsService.checkProjectAccess(
pid,
@@ -324,7 +326,6 @@ export class AnalyticsController {
pages,
funnelId,
} = data
- this.analyticsService.validatePID(pid)
const pagesArr = await this.analyticsService.getPagesArray(
pages,
@@ -385,7 +386,6 @@ export class AnalyticsController {
@Headers() headers: { 'x-password'?: string },
): Promise<ReturnType<typeof this.analyticsService.getCustomEventMetadata>> {
const { pid } = data
- this.analyticsService.validatePID(pid)
await this.analyticsService.checkProjectAccess(
pid,
@@ -404,7 +404,6 @@ export class AnalyticsController {
@Headers() headers: { 'x-password'?: string },
): Promise<ReturnType<typeof this.analyticsService.getPagePropertyMeta>> {
const { pid } = data
- this.analyticsService.validatePID(pid)
await this.analyticsService.checkProjectAccess(
pid,
@@ -423,7 +422,6 @@ export class AnalyticsController {
@Headers() headers: { 'x-password'?: string },
) {
const { pid, type } = data
- this.analyticsService.validatePID(pid)
await this.analyticsService.checkProjectAccess(
pid,
@@ -451,7 +449,6 @@ export class AnalyticsController {
timezone = DEFAULT_TIMEZONE,
mode = ChartRenderMode.PERIODICAL,
} = data
- this.analyticsService.validatePID(pid)
const [filtersQuery, filtersParams, parsedFilters, customEVFilterApplied] =
this.analyticsService.getFiltersQuery(filters, DataType.ANALYTICS)
@@ -513,7 +510,6 @@ export class AnalyticsController {
timezone = DEFAULT_TIMEZONE,
measure = DEFAULT_MEASURE,
} = data
- this.analyticsService.validatePID(pid)
this.analyticsService.checkIfPerfMeasureIsValid(measure)
@@ -601,7 +597,6 @@ export class AnalyticsController {
timezone = DEFAULT_TIMEZONE,
measure = DEFAULT_MEASURE,
} = data
- this.analyticsService.validatePID(pid)
this.analyticsService.checkIfPerfMeasureIsValid(measure)
@@ -655,7 +650,6 @@ export class AnalyticsController {
@Headers() headers: { 'x-password'?: string },
): Promise<IUserFlow | { appliedFilters: any[] }> {
const { pid, period, from, to, timezone = DEFAULT_TIMEZONE, filters } = data
- this.analyticsService.validatePID(pid)
await this.analyticsService.checkProjectAccess(
pid,
@@ -723,7 +717,6 @@ export class AnalyticsController {
const pidsArray = getPIDsArray(pids, pid)
const validationPromises = _map(pidsArray, async currentPID => {
- this.analyticsService.validatePID(currentPID)
await this.analyticsService.checkProjectAccess(
currentPID,
uid,
@@ -769,7 +762,6 @@ export class AnalyticsController {
}
const validationPromises = _map(pidsArray, async currentPID => {
- this.analyticsService.validatePID(currentPID)
await this.analyticsService.checkProjectAccess(
currentPID,
uid,
@@ -792,7 +784,7 @@ export class AnalyticsController {
@Get('hb')
async getHeartBeatStats(
- @Query() data,
+ @Query() data: GetHeartbeatStatsDto,
@CurrentUserId() uid: string,
@Headers() headers: { 'x-password'?: string },
): Promise<object> {
@@ -800,7 +792,6 @@ export class AnalyticsController {
const pidsArray = getPIDsArray(pids, pid)
const validationPromises = _map(pidsArray, async currentPID => {
- this.analyticsService.validatePID(currentPID)
await this.analyticsService.checkProjectAccess(
currentPID,
uid,
@@ -830,13 +821,12 @@ export class AnalyticsController {
@Get('liveVisitors')
@Auth([], true, true)
async getLiveVisitors(
- @Query() queryParams,
+ @Query() queryParams: LiveVisitorsDto,
@CurrentUserId() uid: string,
@Headers() headers: { 'x-password'?: string },
): Promise<object> {
const { pid } = queryParams
- this.analyticsService.validatePID(pid)
await this.analyticsService.checkProjectAccess(
pid,
uid,
@@ -885,7 +875,7 @@ export class AnalyticsController {
@Post('custom')
@Public()
async logCustom(
- @Body() eventsDTO: EventsDTO,
+ @Body() eventsDTO: EventsDto,
@Headers() headers,
@Ip() reqIP,
) {
@@ -966,7 +956,7 @@ export class AnalyticsController {
@Post('hb')
@Auth([], true, true)
async heartbeat(
- @Body() logDTO: PageviewsDTO,
+ @Body() logDTO: PageviewsDto,
@Headers() headers,
@Ip() reqIP,
) {
@@ -991,7 +981,7 @@ export class AnalyticsController {
@Post()
@Public()
- async log(@Body() logDTO: PageviewsDTO, @Headers() headers, @Ip() reqIP) {
+ async log(@Body() logDTO: PageviewsDto, @Headers() headers, @Ip() reqIP) {
const { 'user-agent': userAgent, origin } = headers
const ip = getIPFromHeaders(headers) || reqIP || ''
@@ -1110,7 +1100,7 @@ export class AnalyticsController {
@Get('noscript')
@Public()
async noscript(
- @Query() data,
+ @Query() data: NoscriptDto,
@Headers() headers,
@Ip() reqIP,
@Response() res,
@@ -1127,7 +1117,7 @@ export class AnalyticsController {
const ip = getIPFromHeaders(headers) || reqIP || ''
- const logDTO: PageviewsDTO = {
+ const logDTO: PageviewsDto = {
pid,
}
@@ -1196,7 +1186,6 @@ export class AnalyticsController {
@Headers() headers: { 'x-password'?: string },
) {
const { pid, period, from, to, filters, timezone = DEFAULT_TIMEZONE } = data
- this.analyticsService.validatePID(pid)
await this.analyticsService.checkProjectAccess(
pid,
@@ -1282,7 +1271,6 @@ export class AnalyticsController {
timezone = DEFAULT_TIMEZONE,
//
} = data
- this.analyticsService.validatePID(pid)
await this.analyticsService.checkProjectAccess(
pid,
@@ -1317,7 +1305,6 @@ export class AnalyticsController {
timezone = DEFAULT_TIMEZONE,
customEvents,
} = data
- this.analyticsService.validatePID(pid)
await this.analyticsService.checkProjectAccess(
pid,
@@ -1409,7 +1396,6 @@ export class AnalyticsController {
@Headers() headers: { 'x-password'?: string },
) {
const { pid, type } = data
- this.analyticsService.validatePID(pid)
await this.analyticsService.checkProjectAccess(
pid,
@@ -1422,7 +1408,7 @@ export class AnalyticsController {
@Post('error')
@Public()
- async logError(@Body() errorDTO: ErrorDTO, @Headers() headers, @Ip() reqIP) {
+ async logError(@Body() errorDTO: ErrorDto, @Headers() headers, @Ip() reqIP) {
const { 'user-agent': userAgent, origin } = headers
const ip = getIPFromHeaders(headers) || reqIP || ''
@@ -1479,7 +1465,7 @@ export class AnalyticsController {
@Patch('error-status')
@Auth([], true, true)
async patchStatus(
- @Body() statusDTO: PatchStatusDTO,
+ @Body() statusDTO: PatchStatusDto,
@CurrentUserId() uid: string,
@Headers() headers,
@Ip() reqIP,
@@ -1489,7 +1475,6 @@ export class AnalyticsController {
await checkRateLimit(ip, 'error-status', 100, 1800)
- this.analyticsService.validatePID(pid)
await this.analyticsService.checkProjectAccess(
pid,
uid,
@@ -1519,7 +1504,6 @@ export class AnalyticsController {
timezone = DEFAULT_TIMEZONE,
options,
} = data
- this.analyticsService.validatePID(pid)
await this.analyticsService.checkProjectAccess(
pid,
@@ -1595,7 +1579,7 @@ export class AnalyticsController {
@Get('get-error')
@Auth([], true, true)
async getError(
- @Query() data: GetErrorDTO,
+ @Query() data: GetErrorDto,
@CurrentUserId() uid: string,
@Headers() headers: { 'x-password'?: string },
) {
@@ -1608,7 +1592,6 @@ export class AnalyticsController {
to,
//
} = data
- this.analyticsService.validatePID(pid)
await this.analyticsService.checkProjectAccess(
pid,
diff --git a/backend/apps/selfhosted/src/analytics/analytics.service.ts b/backend/apps/selfhosted/src/analytics/analytics.service.ts
index c88ee096c..a38d78587 100644
--- a/backend/apps/selfhosted/src/analytics/analytics.service.ts
+++ b/backend/apps/selfhosted/src/analytics/analytics.service.ts
@@ -58,8 +58,8 @@ import {
millisecondsToSeconds,
sumArrays,
} from '../common/utils'
-import { PageviewsDTO } from './dto/pageviews.dto'
-import { EventsDTO } from './dto/events.dto'
+import { PageviewsDto } from './dto/pageviews.dto'
+import { EventsDto } from './dto/events.dto'
import { ProjectService } from '../project/project.service'
import { BotsProtectionLevel, Project } from '../project/entity/project.entity'
import { GetCustomEventMetadata } from './dto/get-custom-event-meta.dto'
@@ -90,7 +90,7 @@ import {
IPageProperty,
ICustomEvent,
} from './interfaces'
-import { ErrorDTO } from './dto/error.dto'
+import { ErrorDto } from './dto/error.dto'
import { GetPagePropertyMetaDto } from './dto/get-page-property-meta.dto'
import { ProjectViewCustomEventMetaValueType } from '../project/entity/project-view-custom-event.entity'
import { ProjectViewCustomEventDto } from '../project/dto/create-project-view.dto'
@@ -384,7 +384,7 @@ export class AnalyticsService {
}
async validate(
- logDTO: PageviewsDTO | EventsDTO | ErrorDTO,
+ logDTO: PageviewsDto | EventsDto | ErrorDto,
origin: string,
ip?: string,
): Promise<string | null> {
@@ -393,7 +393,6 @@ export class AnalyticsService {
}
const { pid } = logDTO
- this.validatePID(pid)
// 'tz' does not need validation as it's based on getCountryForTimezone detection
const { lc } = logDTO
@@ -430,7 +429,7 @@ export class AnalyticsService {
}
async validateHeartbeat(
- logDTO: PageviewsDTO,
+ logDTO: PageviewsDto,
origin: string,
ip?: string,
): Promise<string | null> {
@@ -439,7 +438,6 @@ export class AnalyticsService {
}
const { pid } = logDTO
- this.validatePID(pid)
const project = await this.projectService.getRedisProject(pid)
@@ -3338,7 +3336,7 @@ export class AnalyticsService {
}
}
- getErrorID(errorDTO: ErrorDTO): string {
+ getErrorID(errorDTO: ErrorDto): string {
const { name, message, colno, lineno, filename } = errorDTO
return hash(`${name}${message}${colno}${lineno}${filename}`).substring(
diff --git a/backend/apps/selfhosted/src/analytics/dto/error.dto.ts b/backend/apps/selfhosted/src/analytics/dto/error.dto.ts
index efa35255e..d1e644523 100644
--- a/backend/apps/selfhosted/src/analytics/dto/error.dto.ts
+++ b/backend/apps/selfhosted/src/analytics/dto/error.dto.ts
@@ -9,7 +9,7 @@ import {
} from 'class-validator'
import { PID_REGEX } from '../../common/constants'
-export class ErrorDTO {
+export class ErrorDto {
@ApiProperty({
example: 'aUn1quEid-3',
required: true,
@@ -17,7 +17,7 @@ export class ErrorDTO {
})
@IsNotEmpty()
@Matches(PID_REGEX, {
- message: 'Incorrect project ID format.',
+ message: 'The provided Project ID (pid) is incorrect',
})
pid: string
diff --git a/backend/apps/selfhosted/src/analytics/dto/events.dto.ts b/backend/apps/selfhosted/src/analytics/dto/events.dto.ts
index 7b5a14a99..cdaf5c403 100644
--- a/backend/apps/selfhosted/src/analytics/dto/events.dto.ts
+++ b/backend/apps/selfhosted/src/analytics/dto/events.dto.ts
@@ -11,6 +11,7 @@ import {
Validate,
Matches,
} from 'class-validator'
+import { PID_REGEX } from '../../common/constants'
export const MAX_METADATA_KEYS = 20
export const MAX_METADATA_VALUE_LENGTH = 1000
@@ -48,13 +49,14 @@ export class MetadataValueType implements ValidatorConstraintInterface {
}
}
-export class EventsDTO {
+export class EventsDto {
@ApiProperty({
example: 'aUn1quEid-3',
required: true,
description: 'The project ID',
})
@IsNotEmpty()
+ @Matches(PID_REGEX, { message: 'The provided Project ID (pid) is incorrect' })
pid: string
@ApiProperty({
diff --git a/backend/apps/selfhosted/src/analytics/dto/get-error.dto.ts b/backend/apps/selfhosted/src/analytics/dto/get-error.dto.ts
index fcef7ea54..c0d5e892c 100644
--- a/backend/apps/selfhosted/src/analytics/dto/get-error.dto.ts
+++ b/backend/apps/selfhosted/src/analytics/dto/get-error.dto.ts
@@ -2,7 +2,7 @@ import { ApiProperty, PickType } from '@nestjs/swagger'
import { IsNotEmpty } from 'class-validator'
import { GetDataDto } from './getData.dto'
-export class GetErrorDTO extends PickType(GetDataDto, [
+export class GetErrorDto extends PickType(GetDataDto, [
'pid',
'period',
'from',
diff --git a/backend/apps/selfhosted/src/analytics/dto/get-filters.dto.ts b/backend/apps/selfhosted/src/analytics/dto/get-filters.dto.ts
index 408bf0fc5..2f1e599ad 100644
--- a/backend/apps/selfhosted/src/analytics/dto/get-filters.dto.ts
+++ b/backend/apps/selfhosted/src/analytics/dto/get-filters.dto.ts
@@ -1,5 +1,6 @@
import { ApiProperty } from '@nestjs/swagger'
-import { IsNotEmpty } from 'class-validator'
+import { IsNotEmpty, Matches } from 'class-validator'
+import { PID_REGEX } from '../../common/constants'
export class GetFiltersDto {
@ApiProperty({
@@ -8,6 +9,7 @@ export class GetFiltersDto {
description: 'The project ID',
})
@IsNotEmpty()
+ @Matches(PID_REGEX, { message: 'The provided Project ID (pid) is incorrect' })
pid: string
@ApiProperty({
diff --git a/backend/apps/selfhosted/src/analytics/dto/get-heartbeat-stats.ts b/backend/apps/selfhosted/src/analytics/dto/get-heartbeat-stats.ts
new file mode 100644
index 000000000..a65be160e
--- /dev/null
+++ b/backend/apps/selfhosted/src/analytics/dto/get-heartbeat-stats.ts
@@ -0,0 +1,20 @@
+import { IsOptional, Matches, ValidateIf } from 'class-validator'
+import { ApiProperty } from '@nestjs/swagger'
+import { PID_REGEX } from '../../common/constants'
+
+export class GetHeartbeatStatsDto {
+ @ApiProperty({ description: 'Array of project IDs', required: false })
+ @ValidateIf(o => o.pids || !o.pid)
+ @IsOptional()
+ @Matches(PID_REGEX, {
+ message: 'One of the provided Project IDs (pids) is incorrect',
+ each: true,
+ })
+ pids?: string[]
+
+ @ApiProperty({ description: 'Single project ID', required: false })
+ @ValidateIf(o => !o.pids || o.pid)
+ @IsOptional()
+ @Matches(PID_REGEX, { message: 'The provided Project ID (pid) is incorrect' })
+ pid?: string
+}
diff --git a/backend/apps/selfhosted/src/analytics/dto/get-overall-stats.dto.ts b/backend/apps/selfhosted/src/analytics/dto/get-overall-stats.dto.ts
index 1b644086c..80b008912 100644
--- a/backend/apps/selfhosted/src/analytics/dto/get-overall-stats.dto.ts
+++ b/backend/apps/selfhosted/src/analytics/dto/get-overall-stats.dto.ts
@@ -1,19 +1,23 @@
import { ApiProperty } from '@nestjs/swagger'
-import { IsOptional, IsString, ValidateIf } from 'class-validator'
+import { IsOptional, IsString, Matches, ValidateIf } from 'class-validator'
import { DEFAULT_TIMEZONE } from '../../user/entities/user.entity'
import { ValidatePeriod } from '../decorators/validate-period.decorator'
+import { PID_REGEX } from '../../common/constants'
export class GetOverallStatsDto {
@ApiProperty({ description: 'Array of project IDs', required: false })
@ValidateIf(o => o.pids || !o.pid)
@IsOptional()
- @IsString({ each: true })
+ @Matches(PID_REGEX, {
+ message: 'One of the provided Project IDs (pids) is incorrect',
+ each: true,
+ })
pids?: string[]
@ApiProperty({ description: 'Single project ID', required: false })
@ValidateIf(o => !o.pids || o.pid)
@IsOptional()
- @IsString()
+ @Matches(PID_REGEX, { message: 'The provided Project ID (pid) is incorrect' })
pid?: string
@ApiProperty({ required: false })
diff --git a/backend/apps/selfhosted/src/analytics/dto/get-session.dto.ts b/backend/apps/selfhosted/src/analytics/dto/get-session.dto.ts
index 9782d45fd..5d5c59bb4 100644
--- a/backend/apps/selfhosted/src/analytics/dto/get-session.dto.ts
+++ b/backend/apps/selfhosted/src/analytics/dto/get-session.dto.ts
@@ -1,11 +1,17 @@
import { ApiProperty } from '@nestjs/swagger'
-import { IsNotEmpty } from 'class-validator'
+import { IsNotEmpty, Matches } from 'class-validator'
import { DEFAULT_TIMEZONE } from '../../user/entities/user.entity'
+import { PID_REGEX } from '../../common/constants'
// eslint-disable-next-line @typescript-eslint/naming-convention
export class GetSessionDto {
- @ApiProperty()
+ @ApiProperty({
+ example: 'aUn1quEid-3',
+ required: true,
+ description: 'The project ID',
+ })
@IsNotEmpty()
+ @Matches(PID_REGEX, { message: 'The provided Project ID (pid) is incorrect' })
pid: string
@ApiProperty()
diff --git a/backend/apps/selfhosted/src/analytics/dto/getData.dto.ts b/backend/apps/selfhosted/src/analytics/dto/getData.dto.ts
index d648005db..745defa11 100644
--- a/backend/apps/selfhosted/src/analytics/dto/getData.dto.ts
+++ b/backend/apps/selfhosted/src/analytics/dto/getData.dto.ts
@@ -1,7 +1,8 @@
import { ApiProperty } from '@nestjs/swagger'
-import { IsEnum, IsNotEmpty, IsOptional } from 'class-validator'
+import { IsNotEmpty, IsOptional, IsEnum, Matches } from 'class-validator'
import { DEFAULT_TIMEZONE } from '../../user/entities/user.entity'
import { ValidatePeriod } from '../decorators/validate-period.decorator'
+import { PID_REGEX } from '../../common/constants'
export enum TimeBucketType {
MINUTE = 'minute',
@@ -18,8 +19,13 @@ export enum ChartRenderMode {
// eslint-disable-next-line @typescript-eslint/naming-convention
export class GetDataDto {
- @ApiProperty()
+ @ApiProperty({
+ example: 'aUn1quEid-3',
+ required: true,
+ description: 'The project ID',
+ })
@IsNotEmpty()
+ @Matches(PID_REGEX, { message: 'The provided Project ID (pid) is incorrect' })
pid: string
@ApiProperty({ required: false })
@@ -32,15 +38,16 @@ export class GetDataDto {
@IsEnum(TimeBucketType, { message: 'The provided timebucket is incorrect' })
timeBucket: TimeBucketType
- @ApiProperty()
+ @ApiProperty({ required: false })
from: string
- @ApiProperty()
+ @ApiProperty({ required: false })
to: string
@ApiProperty({
description:
'A stringified array of properties to filter [{ column, filter, isExclusive }]',
+ required: false,
})
filters: string
diff --git a/backend/apps/selfhosted/src/analytics/dto/getFunnels.dto.ts b/backend/apps/selfhosted/src/analytics/dto/getFunnels.dto.ts
index e88365717..6e8229d36 100644
--- a/backend/apps/selfhosted/src/analytics/dto/getFunnels.dto.ts
+++ b/backend/apps/selfhosted/src/analytics/dto/getFunnels.dto.ts
@@ -1,12 +1,17 @@
import { ApiProperty } from '@nestjs/swagger'
-import { IsNotEmpty, IsOptional } from 'class-validator'
+import { IsNotEmpty, IsOptional, Matches } from 'class-validator'
import { DEFAULT_TIMEZONE } from '../../user/entities/user.entity'
import { ValidatePeriod } from '../decorators/validate-period.decorator'
+import { PID_REGEX } from '../../common/constants'
-// eslint-disable-next-line @typescript-eslint/naming-convention
export class GetFunnelsDto {
- @ApiProperty()
+ @ApiProperty({
+ example: 'aUn1quEid-3',
+ required: true,
+ description: 'The project ID',
+ })
@IsNotEmpty()
+ @Matches(PID_REGEX, { message: 'The provided Project ID (pid) is incorrect' })
pid: string
@ApiProperty({ required: false })
@@ -29,7 +34,7 @@ export class GetFunnelsDto {
@ApiProperty({
description: 'A stringified array of pages to generate funnel for',
})
- pages: string
+ pages?: string
@ApiProperty({
description: 'Funnel ID',
diff --git a/backend/apps/selfhosted/src/analytics/dto/getUserFlow.dto.ts b/backend/apps/selfhosted/src/analytics/dto/getUserFlow.dto.ts
index 774962487..566e8d78b 100644
--- a/backend/apps/selfhosted/src/analytics/dto/getUserFlow.dto.ts
+++ b/backend/apps/selfhosted/src/analytics/dto/getUserFlow.dto.ts
@@ -1,11 +1,17 @@
import { ApiProperty } from '@nestjs/swagger'
-import { IsNotEmpty, IsOptional } from 'class-validator'
+import { IsNotEmpty, IsOptional, Matches } from 'class-validator'
import { DEFAULT_TIMEZONE } from '../../user/entities/user.entity'
import { ValidatePeriod } from '../decorators/validate-period.decorator'
+import { PID_REGEX } from '../../common/constants'
export class GetUserFlowDto {
- @ApiProperty()
+ @ApiProperty({
+ example: 'aUn1quEid-3',
+ required: true,
+ description: 'The project ID',
+ })
@IsNotEmpty()
+ @Matches(PID_REGEX, { message: 'The provided Project ID (pid) is incorrect' })
pid: string
@ApiProperty({ required: false })
diff --git a/backend/apps/selfhosted/src/analytics/dto/live-visitors.dto.ts b/backend/apps/selfhosted/src/analytics/dto/live-visitors.dto.ts
new file mode 100644
index 000000000..72969a0ee
--- /dev/null
+++ b/backend/apps/selfhosted/src/analytics/dto/live-visitors.dto.ts
@@ -0,0 +1,14 @@
+import { IsNotEmpty, Matches } from 'class-validator'
+import { ApiProperty } from '@nestjs/swagger'
+import { PID_REGEX } from '../../common/constants'
+
+export class LiveVisitorsDto {
+ @ApiProperty({
+ example: 'aUn1quEid-3',
+ required: true,
+ description: 'The project ID',
+ })
+ @IsNotEmpty()
+ @Matches(PID_REGEX, { message: 'The provided Project ID (pid) is incorrect' })
+ pid: string
+}
diff --git a/backend/apps/selfhosted/src/analytics/dto/noscript.dto.ts b/backend/apps/selfhosted/src/analytics/dto/noscript.dto.ts
new file mode 100644
index 000000000..9470df6fa
--- /dev/null
+++ b/backend/apps/selfhosted/src/analytics/dto/noscript.dto.ts
@@ -0,0 +1,14 @@
+import { IsNotEmpty, Matches } from 'class-validator'
+import { ApiProperty } from '@nestjs/swagger'
+import { PID_REGEX } from '../../common/constants'
+
+export class NoscriptDto {
+ @ApiProperty({
+ example: 'aUn1quEid-3',
+ required: true,
+ description: 'The project ID',
+ })
+ @IsNotEmpty()
+ @Matches(PID_REGEX, { message: 'The provided Project ID (pid) is incorrect' })
+ pid: string
+}
diff --git a/backend/apps/selfhosted/src/analytics/dto/pageviews.dto.ts b/backend/apps/selfhosted/src/analytics/dto/pageviews.dto.ts
index c350819cd..b08793ac2 100644
--- a/backend/apps/selfhosted/src/analytics/dto/pageviews.dto.ts
+++ b/backend/apps/selfhosted/src/analytics/dto/pageviews.dto.ts
@@ -1,5 +1,11 @@
import { ApiProperty } from '@nestjs/swagger'
-import { IsNotEmpty, IsObject, IsOptional, Validate } from 'class-validator'
+import {
+ IsNotEmpty,
+ IsObject,
+ IsOptional,
+ Matches,
+ Validate,
+} from 'class-validator'
import {
MAX_METADATA_KEYS,
@@ -8,14 +14,16 @@ import {
MetadataValueType,
MetadataSizeLimit,
} from './events.dto'
+import { PID_REGEX } from '../../common/constants'
-export class PageviewsDTO {
+export class PageviewsDto {
@ApiProperty({
example: 'aUn1quEid-3',
required: true,
description: 'The project ID',
})
@IsNotEmpty()
+ @Matches(PID_REGEX, { message: 'The provided Project ID (pid) is incorrect' })
pid: string
// Tracking metrics
diff --git a/backend/apps/selfhosted/src/analytics/dto/patch-status.dto.ts b/backend/apps/selfhosted/src/analytics/dto/patch-status.dto.ts
index 2da498d93..44a8dc921 100644
--- a/backend/apps/selfhosted/src/analytics/dto/patch-status.dto.ts
+++ b/backend/apps/selfhosted/src/analytics/dto/patch-status.dto.ts
@@ -9,7 +9,7 @@ import {
} from 'class-validator'
import { PID_REGEX } from '../../common/constants'
-export class PatchStatusDTO {
+export class PatchStatusDto {
@ApiProperty({
example: 'aUn1quEid-3',
required: true,
@@ -17,7 +17,7 @@ export class PatchStatusDTO {
})
@IsNotEmpty()
@Matches(PID_REGEX, {
- message: 'Incorrect project ID format.',
+ message: 'The provided Project ID (pid) is incorrect',
})
pid: string