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!

Merge branch 'main' into feature-uptime-monitoring

Andrii Romasiune719ea6ae62d
diff --cc apps/production/src/analytics/analytics.controller.ts
index a8faa2e29,ee8b18ed5..e6ce706bf
--- a/apps/production/src/analytics/analytics.controller.ts
+++ b/apps/production/src/analytics/analytics.controller.ts
@@@ -31,9 -26,8 +32,7 @@@ import
ForbiddenException,
Response,
Header,
- ConflictException,
- NotFoundException,
} from '@nestjs/common'
-import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'
import * as UAParser from 'ua-parser-js'
import { isbot } from 'isbot'
@@@ -98,7 -89,10 +96,11 @@@ import
performanceTransformer,
trafficTransformer,
} from './utils/transformers'
+import { GetUptimeBirdseyeDto } from './dto/get-uptime-birdseye.dto'
+ import {
+ MAX_METRICS_IN_VIEW,
+ ProjectViewCustomEventDto,
+ } from '../project/dto/create-project-view.dto'
dayjs.extend(utc)
dayjs.extend(dayjsTimezone)
@@@ -234,8 -196,6 +236,7 @@@ export class AnalyticsController
constructor(
private readonly analyticsService: AnalyticsService,
private readonly logger: AppLoggerService,
- private readonly projectsViewsRepository: ProjectsViewsRepository,
+ private readonly projectService: ProjectService,
) {}
@ApiBearerAuth()
diff --cc apps/production/src/project/project.controller.ts
index 11db97c2c,6cb406bc4..bf4d6e1e4
--- a/apps/production/src/project/project.controller.ts
+++ b/apps/production/src/project/project.controller.ts
@@@ -2151,378 -2145,6 +2153,375 @@@ export class ProjectController
this.projectService.allowedToView(project, userId, headers['x-password'])
// TODO add caching
- return this.projectService.sendPredictAiRequest(
- params.projectId,
- query.timeframe,
- )
+ return this.projectService.sendPredictAiRequest(params.projectId)
}
+
+ @ApiOperation({ summary: 'Create monitor group' })
+ @ApiBearerAuth()
+ @ApiOkResponse({ type: MonitorGroupEntity })
+ @Post(':projectId/monitor-groups')
+ @Auth([], true, true)
+ public async createMonitorGroup(
+ @Param() { projectId }: ProjectIdDto,
+ @Body() body: CreateMonitorGroupDto,
+ @CurrentUserId() userId: string,
+ ): Promise<MonitorGroupEntity> {
+ const project = await this.projectService.findProject(projectId, [
+ 'admin',
+ 'share',
+ ])
+
+ if (!project) {
+ throw new NotFoundException('Project not found.')
+ }
+
+ const user = await this.userService.findUserV2(userId, ['roles'])
+
+ if (!user) {
+ throw new NotFoundException('User not found.')
+ }
+
+ this.projectService.allowedToManage(project, userId, user.roles)
+
+ const monitorGroup =
+ await this.projectService.findMonitorGroupByProjectIdAndName(
+ projectId,
+ body.name,
+ )
+ if (monitorGroup) {
+ throw new ConflictException('Monitor group exists.')
+ }
+
+ return this.projectService.createMonitorGroup(projectId, body)
+ }
+
+ @ApiOperation({ summary: 'Get all monitor groups for a project' })
+ @ApiBearerAuth()
+ @ApiOkResponse({ type: [MonitorGroupEntity] })
+ @Get(':projectId/monitor-groups')
+ @Auth([], true, true)
+ async getMonitorGroups(
+ @Param() { projectId }: ProjectIdDto,
+ @CurrentUserId() userId: string,
+ ): Promise<MonitorGroupEntity[]> {
+ const project = await this.projectService.findProject(projectId, [
+ 'admin',
+ 'share',
+ ])
+
+ if (!project) {
+ throw new NotFoundException('Project not found.')
+ }
+
+ const user = await this.userService.findUserV2(userId, ['roles'])
+
+ if (!user) {
+ throw new NotFoundException('User not found.')
+ }
+
+ this.projectService.allowedToManage(project, userId, user.roles)
+
+ const monitorGroup =
+ await this.projectService.getMonitorGroupsByProjectId(projectId)
+
+ return monitorGroup
+ }
+
+ @ApiOperation({ summary: 'Get monitor group by ID' })
+ @ApiBearerAuth()
+ @ApiOkResponse({ type: MonitorGroupEntity })
+ @Get(':projectId/monitor-groups/:monitorGroupId')
+ @Auth([], true, true)
+ async getMonitorGroup(
+ @Param() { projectId }: ProjectIdDto,
+ @Param() { monitorGroupId }: MonitorGroupIdDto,
+ @CurrentUserId() userId: string,
+ ): Promise<MonitorGroupEntity> {
+ const project = await this.projectService.findProject(projectId, [
+ 'admin',
+ 'share',
+ ])
+
+ if (!project) {
+ throw new NotFoundException('Project not found.')
+ }
+
+ const user = await this.userService.findUserV2(userId, ['roles'])
+
+ if (!user) {
+ throw new NotFoundException('User not found.')
+ }
+
+ this.projectService.allowedToManage(project, userId, user.roles)
+
+ const monitorGroup = await this.projectService.findMonitorGroup(
+ projectId,
+ monitorGroupId,
+ )
+ if (!monitorGroup) {
+ throw new NotFoundException('Monitor group not found.')
+ }
+
+ return monitorGroup
+ }
+
+ @ApiOperation({ summary: 'Update monitor group' })
+ @ApiBearerAuth()
+ @ApiOkResponse({ type: MonitorGroupEntity })
+ @Put(':projectId/monitor-groups/:monitorGroupId')
+ @Auth([], true, true)
+ async updateMonitorGroup(
+ @Param() { projectId }: ProjectIdDto,
+ @Param() { monitorGroupId }: MonitorGroupIdDto,
+ @Body() updateMonitorGroupDto: UpdateMonitorGroupDto,
+ @CurrentUserId() userId: string,
+ ): Promise<MonitorGroupEntity> {
+ const project = await this.projectService.findProject(projectId, [
+ 'admin',
+ 'share',
+ ])
+
+ if (!project) {
+ throw new NotFoundException('Project not found.')
+ }
+
+ const user = await this.userService.findUserV2(userId, ['roles'])
+
+ if (!user) {
+ throw new NotFoundException('User not found.')
+ }
+
+ this.projectService.allowedToManage(project, userId, user.roles)
+
+ return this.projectService.updateMonitorGroup(
+ projectId,
+ monitorGroupId,
+ updateMonitorGroupDto,
+ )
+ }
+
+ @ApiOperation({ summary: 'Delete monitor group' })
+ @ApiBearerAuth()
+ @Delete(':projectId/monitor-groups/:monitorGroupId')
+ @Auth([], true, true)
+ async deleteMonitorGroup(
+ @Param() { projectId }: ProjectIdDto,
+ @Param() { monitorGroupId }: MonitorGroupIdDto,
+ @CurrentUserId() userId: string,
+ ): Promise<void> {
+ const project = await this.projectService.findProject(projectId, [
+ 'admin',
+ 'share',
+ ])
+
+ if (!project) {
+ throw new NotFoundException('Project not found.')
+ }
+
+ const user = await this.userService.findUserV2(userId, ['roles'])
+
+ if (!user) {
+ throw new NotFoundException('User not found.')
+ }
+
+ this.projectService.allowedToManage(project, userId, user.roles)
+
+ return this.projectService.deleteMonitorGroup(projectId, monitorGroupId)
+ }
+
+ @ApiOperation({ summary: 'Create monitor for the project' })
+ @ApiBearerAuth()
+ @ApiOkResponse({ type: MonitorEntity })
+ @Post(':projectId/monitor-groups/:monitorGroupId/monitor')
+ @Auth([], true, true)
+ public async createMonitor(
+ @Param() { projectId }: ProjectIdDto,
+ @Param() { monitorGroupId }: MonitorGroupIdDto,
+ @Body() body: CreateMonitorHttpRequestDTO,
+ @CurrentUserId() userId: string,
+ ): Promise<MonitorEntity> {
+ const project = await this.projectService.findProject(projectId, [
+ 'admin',
+ 'share',
+ ])
+
+ if (!project) {
+ throw new NotFoundException('Project not found.')
+ }
+
+ const user = await this.userService.findUserV2(userId, ['roles'])
+
+ if (!user) {
+ throw new NotFoundException('User not found.')
+ }
+
+ this.projectService.allowedToManage(project, userId, user.roles)
+
+ const monitorGroup = await this.projectService.findMonitorGroup(
+ monitorGroupId,
+ projectId,
+ )
+
+ if (!monitorGroup) {
+ throw new NotFoundException('Monitor group not found.')
+ }
+
+ const monitor = await this.projectService.createMonitorInGroup(
+ body,
+ monitorGroup.id,
+ )
+
+ // Create a job in service for sending httpRequest
+ await this.projectService.sendHttpRequest(monitor.id, {
+ ...monitor,
+ timeout: monitor.timeout * 1000,
+ })
+
+ return monitor
+ }
+
+ @ApiOperation({ summary: 'Get monitor for the project' })
+ @ApiBearerAuth()
+ @ApiOkResponse({ type: MonitorEntity })
+ @Get(':projectId/monitor-groups/:monitorGroupId/monitor/:monitorId')
+ @Auth([], true, true)
+ public async getMonitor(
+ @Param() { projectId }: ProjectIdDto,
+ @Param() { monitorGroupId }: MonitorGroupIdDto,
+ @Param('monitorId') monitorId: number,
+ @CurrentUserId() userId: string,
+ ): Promise<MonitorEntity> {
+ const project = await this.projectService.findProject(projectId, [
+ 'admin',
+ 'share',
+ ])
+
+ if (!project) {
+ throw new NotFoundException('Project not found.')
+ }
+
+ const user = await this.userService.findUserV2(userId, ['roles'])
+
+ if (!user) {
+ throw new NotFoundException('User not found.')
+ }
+
+ this.projectService.allowedToManage(project, userId, user.roles)
+
+ const monitorGroup = await this.projectService.findMonitorGroup(
+ monitorGroupId,
+ projectId,
+ )
+
+ if (!monitorGroup) {
+ throw new NotFoundException('Monitor group not found.')
+ }
+
+ const monitor = await this.projectService.getMonitor(monitorId)
+
+ if (!monitor) {
+ throw new NotFoundException('Monitor not found.')
+ }
+
+ return monitor
+ }
+
+ @ApiOperation({ summary: 'Update monitor for the project' })
+ @ApiBearerAuth()
+ @ApiOkResponse({ type: MonitorEntity })
+ @Patch(':projectId/monitor-groups/:monitorGroupId/monitor/:monitorId')
+ @Auth([], true, true)
+ public async updateMonitor(
+ @Param() { projectId }: ProjectIdDto,
+ @Param() { monitorGroupId }: MonitorGroupIdDto,
+ @Param('monitorId') monitorId: number,
+ @Body() body: UpdateMonitorHttpRequestDTO,
+ @CurrentUserId() userId: string,
+ ): Promise<MonitorEntity> {
+ const project = await this.projectService.findProject(projectId, [
+ 'admin',
+ 'share',
+ ])
+
+ if (!project) {
+ throw new NotFoundException('Project not found.')
+ }
+
+ const user = await this.userService.findUserV2(userId, ['roles'])
+
+ if (!user) {
+ throw new NotFoundException('User not found.')
+ }
+
+ this.projectService.allowedToManage(project, userId, user.roles)
+
+ const monitorGroup = await this.projectService.findMonitorGroup(
+ monitorGroupId,
+ projectId,
+ )
+
+ if (!monitorGroup) {
+ throw new NotFoundException('Monitor group not found.')
+ }
+
+ const monitor = await this.projectService.getMonitor(monitorId)
+
+ if (!monitor) {
+ throw new NotFoundException('Monitor not found.')
+ }
+
+ const updatedMonitor = await this.projectService.updateMonitor(
+ monitorId,
+ body,
+ )
+
+ await this.projectService.updateHttpRequest(monitor.id, monitor)
+ return updatedMonitor
+ }
+
+ @ApiOperation({ summary: 'Delete monitor from the project' })
+ @ApiBearerAuth()
+ @ApiOkResponse({ description: 'Monitor deleted successfully' })
+ @Delete(':projectId/monitor-groups/:monitorGroupId/monitor/:monitorId')
+ @Auth([], true, true)
+ public async deleteMonitor(
+ @Param() { projectId }: ProjectIdDto,
+ @Param() { monitorGroupId }: MonitorGroupIdDto,
+ @Param('monitorId') monitorId: number,
+ @CurrentUserId() userId: string,
+ ): Promise<void> {
+ const project = await this.projectService.findProject(projectId, [
+ 'admin',
+ 'share',
+ ])
+
+ if (!project) {
+ throw new NotFoundException('Project not found.')
+ }
+ const user = await this.userService.findUserV2(userId, ['roles'])
+
+ if (!user) {
+ throw new NotFoundException('User not found.')
+ }
+
+ this.projectService.allowedToManage(project, userId, user.roles)
+
+ const monitorGroup = await this.projectService.findMonitorGroup(
+ monitorGroupId,
+ projectId,
+ )
+
+ if (!monitorGroup) {
+ throw new NotFoundException('Monitor group not found.')
+ }
+
+ const monitor = await this.projectService.getMonitor(monitorId)
+
+ if (!monitor) {
+ throw new NotFoundException('Monitor not found.')
+ }
+
+ this.projectService.deleteMonitor(monitorId)
+ this.projectService.deleteHttpRequest(monitorId)
+ }
}
diff --cc apps/production/src/project/project.service.ts
index 06035ae6c,e753047ed..c85d9c9ff
--- a/apps/production/src/project/project.service.ts
+++ b/apps/production/src/project/project.service.ts
@@@ -74,15 -75,8 +77,15 @@@ import
import { ReportFrequency } from './enums'
import { nFormatter } from '../common/utils'
import { browserArgs } from '../og-image/og-image.service'
- import { TimeFrameQueryEnum } from './dto/get-prediction-query.dto'
+ import { CreateProjectViewDto } from './dto/create-project-view.dto'
import { AppLoggerService } from '../logger/logger.service'
+import { CreateMonitorHttpRequestDTO } from './dto/create-monitor.dto'
+import { CreateMonitorGroupDto } from './dto/create-monitor-group.dto'
+import { MonitorGroupEntity } from './entity/monitor-group.entity'
+import { UpdateMonitorGroupDto } from './dto/update-monitor-group.dto'
+import { MonitorEntity } from './entity/monitor.entity'
+import { UpdateMonitorHttpRequestDTO } from './dto/update-monitor.dto'
+import { HttpRequestOptions } from './interfaces/http-request-options.interface'
dayjs.extend(utc)
diff --cc package.json
index cbf79c1f3,11bc26934..15f36cd09
--- a/package.json
+++ b/package.json
@@@ -45,12 -43,10 +45,12 @@@
"@nestjs/terminus": "^10.2.3",
"@nestjs/typeorm": "^10.0.2",
"@paypal/payouts-sdk": "^1.1.1",
- "@sentry/cli": "^2.32.2",
- "@sentry/nestjs": "^8.19.0",
- "@sentry/profiling-node": "^8.19.0",
+ "@sentry/cli": "^2.33.1",
+ "@sentry/nestjs": "^8.25.0",
+ "@sentry/profiling-node": "^8.25.0",
+ "amqp-connection-manager": "^4.1.14",
+ "amqplib": "^0.10.4",
- "axios": "^1.7.2",
+ "axios": "^1.7.3",
"bcrypt": "^5.1.1",
"blake3": "^2.1.7",
"body-parser": "^1.20.2",
@@@ -71,15 -65,14 +71,15 @@@
"front-matter": "^4.0.2",
"googleapis": "^140.0.1",
"handlebars": "^4.7.8",
+ "install": "^0.13.0",
"ioredis": "^5.4.1",
"ip-range-check": "^0.2.0",
- "isbot": "^5.1.13",
+ "isbot": "^5.1.14",
"jsonwebtoken": "^9.0.2",
"lodash": "^4.17.21",
- "maxmind": "^4.3.20",
- "mysql2": "^3.10.3",
- "nanoid": "^3.3.6",
+ "maxmind": "^4.3.21",
+ "mysql2": "^3.11.0",
+ "nanoid": "^3.3.7",
"nestjs-form-data": "^1.9.91",
"nestjs-i18n": "^10.4.5",
"nestjs-telegraf": "^2.8.1",