📈 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!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Fix TypeScript related errors
Blue Mousef14552a69d53
diff --git a/backend/apps/production/src/alert/alert.module.ts b/backend/apps/production/src/alert/alert.module.tsindex e27a5bcf6..2ae17192e 100644--- a/backend/apps/production/src/alert/alert.module.ts+++ b/backend/apps/production/src/alert/alert.module.ts@@ -1,9 +1,9 @@import { Module } from '@nestjs/common'import { TypeOrmModule } from '@nestjs/typeorm'-import { ProjectModule } from 'src/project/project.module'-import { AppLoggerModule } from 'src/logger/logger.module'-import { UserModule } from 'src/user/user.module'+import { ProjectModule } from '../project/project.module'+import { AppLoggerModule } from '../logger/logger.module'+import { UserModule } from '../user/user.module'import { AlertService } from './alert.service'import { Alert } from './entity/alert.entity'import { AlertController } from './alert.controller'diff --git a/backend/apps/production/src/auth/decorators/roles.decorator.ts b/backend/apps/production/src/auth/decorators/roles.decorator.tsindex 2a56336a4..fcbea69e4 100644--- a/backend/apps/production/src/auth/decorators/roles.decorator.ts+++ b/backend/apps/production/src/auth/decorators/roles.decorator.ts@@ -1,5 +1,5 @@import { SetMetadata } from '@nestjs/common'-import { UserType } from 'src/user/entities/user.entity'+import { UserType } from '../../user/entities/user.entity'export const ROLES_KEY = 'roles'export const Roles = (...roles: UserType[]) => SetMetadata(ROLES_KEY, roles)diff --git a/backend/apps/production/src/auth/guards/roles.guard.ts b/backend/apps/production/src/auth/guards/roles.guard.tsindex dac5d324b..f1bd5d2ad 100644--- a/backend/apps/production/src/auth/guards/roles.guard.ts+++ b/backend/apps/production/src/auth/guards/roles.guard.ts@@ -3,9 +3,9 @@ import { Reflector } from '@nestjs/core'import { ExtractJwt } from 'passport-jwt'import { verify } from 'jsonwebtoken'-import { UserType } from 'src/user/entities/user.entity'-import { UserService } from 'src/user/user.service'-import { JWT_ACCESS_TOKEN_SECRET } from 'src/common/constants'+import { UserType } from '../../user/entities/user.entity'+import { UserService } from '../../user/user.service'+import { JWT_ACCESS_TOKEN_SECRET } from '../../common/constants'import { IS_TWO_FA_NOT_REQUIRED_KEY, ROLES_KEY } from '../decorators'@Injectable()diff --git a/backend/apps/production/src/auth/strategies/jwt-access-token.strategy.ts b/backend/apps/production/src/auth/strategies/jwt-access-token.strategy.tsindex f1aac8a2e..95b47f6c9 100644--- a/backend/apps/production/src/auth/strategies/jwt-access-token.strategy.ts+++ b/backend/apps/production/src/auth/strategies/jwt-access-token.strategy.ts@@ -3,8 +3,8 @@ import { ConfigService } from '@nestjs/config'import { PassportStrategy } from '@nestjs/passport'import { Strategy, ExtractJwt } from 'passport-jwt'-import { JWT_ACCESS_TOKEN_SECRET } from 'src/common/constants'-import { UserService } from 'src/user/user.service'+import { JWT_ACCESS_TOKEN_SECRET } from '../../common/constants'+import { UserService } from '../../user/user.service'import { IJwtPayload } from '../interfaces'@Injectable()diff --git a/backend/apps/production/src/integrations/telegram/scene/settings.scene.ts b/backend/apps/production/src/integrations/telegram/scene/settings.scene.tsindex a7dc07f44..284c5bd7a 100644--- a/backend/apps/production/src/integrations/telegram/scene/settings.scene.ts+++ b/backend/apps/production/src/integrations/telegram/scene/settings.scene.ts@@ -1,6 +1,6 @@import { Ctx, Hears, Scene, SceneEnter } from 'nestjs-telegraf'import { Markup } from 'telegraf'-import { UserService } from 'src/user/user.service'+import { UserService } from '../../../user/user.service'import { Context } from '../interface/context.interface'import { UNLINK_ACCOUNT_SCENE_ID } from './unlink-account.scene'import { START_SCENE_ID } from './start.scene'diff --git a/backend/apps/production/src/integrations/telegram/scene/start.scene.ts b/backend/apps/production/src/integrations/telegram/scene/start.scene.tsindex 75c582197..d11578f14 100644--- a/backend/apps/production/src/integrations/telegram/scene/start.scene.ts+++ b/backend/apps/production/src/integrations/telegram/scene/start.scene.ts@@ -1,5 +1,5 @@import { Ctx, Hears, Scene, SceneEnter } from 'nestjs-telegraf'-import { UserService } from 'src/user/user.service'+import { UserService } from '../../../user/user.service'import { Context } from '../interface/context.interface'import { PROJECTS_SCENE_ID } from './projects.scene'import { SETTINGS_SCENE_ID } from './settings.scene'diff --git a/backend/apps/production/src/integrations/telegram/scene/unlink-account.scene.ts b/backend/apps/production/src/integrations/telegram/scene/unlink-account.scene.tsindex e4ccb3dc8..21538c4ad 100644--- a/backend/apps/production/src/integrations/telegram/scene/unlink-account.scene.ts+++ b/backend/apps/production/src/integrations/telegram/scene/unlink-account.scene.ts@@ -1,6 +1,6 @@import { Ctx, Hears, Scene, SceneEnter } from 'nestjs-telegraf'import { Markup } from 'telegraf'-import { UserService } from 'src/user/user.service'+import { UserService } from '../../../user/user.service'import { Context } from '../interface/context.interface'import { START_SCENE_ID } from './start.scene'import { TelegramService } from '../telegram.service'diff --git a/backend/apps/production/src/integrations/telegram/telegram.module.ts b/backend/apps/production/src/integrations/telegram/telegram.module.tsindex a22e90ebd..9bd47e6bf 100644--- a/backend/apps/production/src/integrations/telegram/telegram.module.ts+++ b/backend/apps/production/src/integrations/telegram/telegram.module.ts@@ -2,9 +2,6 @@ import { Module } from '@nestjs/common'import { ConfigService } from '@nestjs/config'import { TelegrafModule } from 'nestjs-telegraf'import { session } from 'telegraf'-import { UserModule } from 'src/user/user.module'-import { ProjectModule } from 'src/project/project.module'-import { AnalyticsModule } from 'src/analytics/analytics.module'import { TypeOrmModule } from '@nestjs/typeorm'import { TelegramController } from './telegram.controller'import { TelegramUpdate } from './telegram.update'@@ -14,6 +11,9 @@ import { SettingsScene } from './scene/settings.scene'import { UnlinkAccountScene } from './scene/unlink-account.scene'import { TelegramService } from './telegram.service'import { Message } from './entities/message.entity'+import { UserModule } from '../../user/user.module'+import { ProjectModule } from '../../project/project.module'+import { AnalyticsModule } from '../../analytics/analytics.module'@Module({imports: [diff --git a/backend/apps/production/src/integrations/telegram/telegram.service.ts b/backend/apps/production/src/integrations/telegram/telegram.service.tsindex b53af6db2..07f1f6c59 100644--- a/backend/apps/production/src/integrations/telegram/telegram.service.ts+++ b/backend/apps/production/src/integrations/telegram/telegram.service.ts@@ -2,11 +2,11 @@ import { Injectable, Optional } from '@nestjs/common'import { ConfigService } from '@nestjs/config'import { InjectBot } from 'nestjs-telegraf'import { Markup, Telegraf } from 'telegraf'-import { UserService } from 'src/user/user.service'import { InjectRepository } from '@nestjs/typeorm'import { Repository } from 'typeorm'import { Context } from './interface/context.interface'import { Message } from './entities/message.entity'+import { UserService } from '../../user/user.service'@Injectable()export class TelegramService {diff --git a/backend/apps/production/src/marketplace/categories/categories.controller.spec.ts b/backend/apps/production/src/marketplace/categories/categories.controller.spec.tsdeleted file mode 100644index fc3f6db07..000000000--- a/backend/apps/production/src/marketplace/categories/categories.controller.spec.ts+++ /dev/null@@ -1,55 +0,0 @@-import { Test, TestingModule } from '@nestjs/testing'-import { getRepositoryToken } from '@nestjs/typeorm'-import { User } from 'src/user/entities/user.entity'-import { CategoriesController } from './categories.controller'-import { CategoriesService } from './categories.service'-import { Category } from './category.entity'-import { UserService } from '../../user/user.service'--describe('CategoriesController', () => {- let controller: CategoriesController- const USER_REPOSITORY_TOKEN = getRepositoryToken(User)- const CATEGORY_REPOSITORY_TOKEN = getRepositoryToken(Category)- beforeEach(async () => {- const module: TestingModule = await Test.createTestingModule({- controllers: [CategoriesController],- providers: [- UserService,- {- provide: USER_REPOSITORY_TOKEN,- useValue: { create: jest.fn(), save: jest.fn(), findOne: jest.fn() },- },- CategoriesService,- {- provide: CATEGORY_REPOSITORY_TOKEN,- useValue: { create: jest.fn(), save: jest.fn(), findOne: jest.fn() },- },- ],- }).compile()-- controller = module.get<CategoriesController>(CategoriesController)- })-- describe('root', () => {- it('should be defined', () => {- expect(controller).toBeDefined()- })-- it('createCategory should be defined', () => {- expect(controller.createCategory).toBeDefined()- })- it('deleteCategory should be defined', () => {- expect(controller.deleteCategory).toBeDefined()- })- it('getAllCategories should be defined', () => {- expect(controller.getAllCategories).toBeDefined()- })-- it('getCategory should be defined', () => {- expect(controller.getCategory).toBeDefined()- })- it('updateCategory should be defined', () => {- expect(controller.updateCategory).toBeDefined()- })- })-})diff --git a/backend/apps/production/src/marketplace/categories/categories.controller.ts b/backend/apps/production/src/marketplace/categories/categories.controller.tsindex 8f7c33350..5a77b6e96 100644--- a/backend/apps/production/src/marketplace/categories/categories.controller.ts+++ b/backend/apps/production/src/marketplace/categories/categories.controller.ts@@ -14,7 +14,7 @@ import {ValidationPipe,} from '@nestjs/common'import { ApiBearerAuth, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger'-import { JwtAccessTokenGuard } from 'src/auth/guards'+import { JwtAccessTokenGuard } from '../../auth/guards'import { Roles } from '../../auth/decorators/roles.decorator'import { RolesGuard } from '../../auth/guards/roles.guard'import { UserType } from '../../user/entities/user.entity'diff --git a/backend/apps/production/src/marketplace/categories/categories.service.spec.ts b/backend/apps/production/src/marketplace/categories/categories.service.spec.tsdeleted file mode 100644index 3fe854481..000000000--- a/backend/apps/production/src/marketplace/categories/categories.service.spec.ts+++ /dev/null@@ -1,58 +0,0 @@-import { Test, TestingModule } from '@nestjs/testing'-import { Repository } from 'typeorm'-import { getRepositoryToken } from '@nestjs/typeorm'-import { CategoriesService } from './categories.service'-import { Category } from './category.entity'--describe('CategoriesService', () => {- let service: CategoriesService- // eslint-disable-next-line no-unused-vars- let repository: Repository<Category>-- const CATEGORY_REPOSITORY_TOKEN = getRepositoryToken(Category)-- beforeEach(async () => {- const module: TestingModule = await Test.createTestingModule({- providers: [- CategoriesService,- {- provide: CATEGORY_REPOSITORY_TOKEN,- useValue: { create: jest.fn(), save: jest.fn(), findOne: jest.fn() },- },- ],- }).compile()-- service = module.get<CategoriesService>(CategoriesService)- repository = module.get<Repository<Category>>(CATEGORY_REPOSITORY_TOKEN)- })-- describe('root', () => {- it('should be defined', () => {- expect(service).toBeDefined()- })- it('create should be defined', () => {- expect(service.create).toBeDefined()- })- it('delete create should be defined', () => {- expect(service.delete).toBeDefined()- })- it('findAndCount delete create should be defined', () => {- expect(service.findAndCount).toBeDefined()- })- it('findById delete create should be defined', () => {- expect(service.findById).toBeDefined()- })- it('findByName delete create should be defined', () => {- expect(service.findByName).toBeDefined()- })- it('findOne delete create should be defined', () => {- expect(service.findOne).toBeDefined()- })- it('save delete create should be defined', () => {- expect(service.save).toBeDefined()- })- it('update delete create should be defined', () => {- expect(service.update).toBeDefined()- })- })-})diff --git a/backend/apps/production/src/marketplace/cdn/cdn.service.spec.ts b/backend/apps/production/src/marketplace/cdn/cdn.service.spec.tsdeleted file mode 100644index 77712814d..000000000--- a/backend/apps/production/src/marketplace/cdn/cdn.service.spec.ts+++ /dev/null@@ -1,18 +0,0 @@-import { Test, TestingModule } from '@nestjs/testing'-import { CdnService } from './cdn.service'--describe('CdnService', () => {- let service: CdnService-- beforeEach(async () => {- const module: TestingModule = await Test.createTestingModule({- providers: [CdnService],- }).compile()-- service = module.get<CdnService>(CdnService)- })-- it('should be defined', () => {- expect(service).toBeDefined()- })-})diff --git a/backend/apps/production/src/marketplace/complaints/complaints.controller.spec.ts b/backend/apps/production/src/marketplace/complaints/complaints.controller.spec.tsdeleted file mode 100644index d289165ed..000000000--- a/backend/apps/production/src/marketplace/complaints/complaints.controller.spec.ts+++ /dev/null@@ -1,18 +0,0 @@-import { Test, TestingModule } from '@nestjs/testing'-import { ComplaintsController } from './complaints.controller'--describe('ComplaintsController', () => {- let controller: ComplaintsController-- beforeEach(async () => {- const module: TestingModule = await Test.createTestingModule({- controllers: [ComplaintsController],- }).compile()-- controller = module.get<ComplaintsController>(ComplaintsController)- })-- it('should be defined', () => {- expect(controller).toBeDefined()- })-})diff --git a/backend/apps/production/src/marketplace/complaints/complaints.controller.ts b/backend/apps/production/src/marketplace/complaints/complaints.controller.tsindex 56f8c8d09..cfa75b386 100644--- a/backend/apps/production/src/marketplace/complaints/complaints.controller.ts+++ b/backend/apps/production/src/marketplace/complaints/complaints.controller.ts@@ -9,10 +9,10 @@ import {Query,} from '@nestjs/common'import { ApiBearerAuth, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger'-import { UserType } from 'src/user/entities/user.entity'-import { RolesGuard } from 'src/auth/guards/roles.guard'-import { Roles } from 'src/auth/decorators/roles.decorator'-import { JwtAccessTokenGuard } from 'src/auth/guards'+import { UserType } from '../../user/entities/user.entity'+import { RolesGuard } from '../../auth/guards/roles.guard'+import { Roles } from '../../auth/decorators/roles.decorator'+import { JwtAccessTokenGuard } from '../../auth/guards'import { UserService } from '../../user/user.service'import { ExtensionsService } from '../extensions/extensions.service'import { ComplaintsService } from './complaints.service'diff --git a/backend/apps/production/src/marketplace/complaints/complaints.service.spec.ts b/backend/apps/production/src/marketplace/complaints/complaints.service.spec.tsdeleted file mode 100644index 1cbfb3a1e..000000000--- a/backend/apps/production/src/marketplace/complaints/complaints.service.spec.ts+++ /dev/null@@ -1,18 +0,0 @@-import { Test, TestingModule } from '@nestjs/testing'-import { ComplaintsService } from './complaints.service'--describe('ComplaintsService', () => {- let service: ComplaintsService-- beforeEach(async () => {- const module: TestingModule = await Test.createTestingModule({- providers: [ComplaintsService],- }).compile()-- service = module.get<ComplaintsService>(ComplaintsService)- })-- it('should be defined', () => {- expect(service).toBeDefined()- })-})diff --git a/backend/apps/production/src/marketplace/extensions/extensions.controller.spec.ts b/backend/apps/production/src/marketplace/extensions/extensions.controller.spec.tsdeleted file mode 100644index 99a5d3996..000000000--- a/backend/apps/production/src/marketplace/extensions/extensions.controller.spec.ts+++ /dev/null@@ -1,53 +0,0 @@-import { Test, TestingModule } from '@nestjs/testing'-import { getRepositoryToken } from '@nestjs/typeorm'-import { Extension } from './entities/extension.entity'-import { CategoriesService } from '../categories/categories.service'-import { ExtensionsController } from './extensions.controller'-import { ExtensionsService } from './extensions.service'-import { Category } from '../categories/category.entity'--describe('ExtensionsController', () => {- let controller: ExtensionsController- const EXTENSION_REPOSITORY_TOKEN = getRepositoryToken(Extension)- const CATEGORY_REPOSITORY_TOKEN = getRepositoryToken(Category)- beforeEach(async () => {- const module: TestingModule = await Test.createTestingModule({- controllers: [ExtensionsController],- providers: [- ExtensionsService,- {- provide: EXTENSION_REPOSITORY_TOKEN,- useValue: { create: jest.fn(), save: jest.fn(), findOne: jest.fn() },- },- CategoriesService,- {- provide: CATEGORY_REPOSITORY_TOKEN,- useValue: { create: jest.fn(), save: jest.fn(), findOne: jest.fn() },- },- ],- }).compile()-- controller = module.get<ExtensionsController>(ExtensionsController)- })- describe('root', () => {- it('should be defined', () => {- expect(controller).toBeDefined()- })- it('createExtension should be defined', () => {- expect(controller.createExtension).toBeDefined()- })- it('deleteExtension should be defined', () => {- expect(controller.deleteExtension).toBeDefined()- })- it('getAllExtension should be defined', () => {- expect(controller.getExtension).toBeDefined()- })-- it('getExtension should be defined', () => {- expect(controller.getExtension).toBeDefined()- })- it('updateExtension should be defined', () => {- expect(controller.updateExtension).toBeDefined()- })- })-})diff --git a/backend/apps/production/src/marketplace/extensions/extensions.service.spec.ts b/backend/apps/production/src/marketplace/extensions/extensions.service.spec.tsdeleted file mode 100644index b69b585c1..000000000--- a/backend/apps/production/src/marketplace/extensions/extensions.service.spec.ts+++ /dev/null@@ -1,28 +0,0 @@-import { Test, TestingModule } from '@nestjs/testing'-import { getRepositoryToken } from '@nestjs/typeorm'-import { Extension } from './entities/extension.entity'-import { ExtensionsService } from './extensions.service'--describe('ExtensionsService', () => {- let service: ExtensionsService- const EXTENSION_REPOSITORY_TOKEN = getRepositoryToken(Extension)- beforeEach(async () => {- const module: TestingModule = await Test.createTestingModule({- providers: [- ExtensionsService,- {- provide: EXTENSION_REPOSITORY_TOKEN,- useValue: { create: jest.fn(), save: jest.fn(), findOne: jest.fn() },- },- ],- }).compile()-- service = module.get<ExtensionsService>(ExtensionsService)- })-- describe('root', () => {- it('should be defined', () => {- expect(service).toBeDefined()- })- })-})diff --git a/backend/apps/production/src/marketplace/extensions/extensions.service.ts b/backend/apps/production/src/marketplace/extensions/extensions.service.tsindex 498f8c44e..09b616b18 100644--- a/backend/apps/production/src/marketplace/extensions/extensions.service.ts+++ b/backend/apps/production/src/marketplace/extensions/extensions.service.ts@@ -2,7 +2,7 @@ import { ForbiddenException, Injectable } from '@nestjs/common'import _pick from 'lodash/pick'import { InjectRepository } from '@nestjs/typeorm'import { FindManyOptions, FindOneOptions, Like, Repository } from 'typeorm'-import { UserService } from 'src/user/user.service'+import { UserService } from '../../user/user.service'import { ExtensionToProject } from './entities/extension-to-project.entity'import { ExtensionToUser } from './entities/extension-to-user.entity'import { Extension } from './entities/extension.entity'diff --git a/backend/apps/production/src/marketplace/extensions/interfaces/create-extension.interface.ts b/backend/apps/production/src/marketplace/extensions/interfaces/create-extension.interface.tsindex 37b02a650..315d14d5a 100644--- a/backend/apps/production/src/marketplace/extensions/interfaces/create-extension.interface.ts+++ b/backend/apps/production/src/marketplace/extensions/interfaces/create-extension.interface.ts@@ -1,4 +1,4 @@-import { User } from 'src/user/entities/user.entity'+import { User } from '../../../user/entities/user.entity'import { Category } from '../../categories/category.entity'import { ExtensionStatus } from '../enums/extension-status.enum'diff --git a/backend/apps/selfhosted/src/analytics/analytics.service.ts b/backend/apps/selfhosted/src/analytics/analytics.service.tsindex f8a574c48..b3df566d6 100644--- a/backend/apps/selfhosted/src/analytics/analytics.service.ts+++ b/backend/apps/selfhosted/src/analytics/analytics.service.ts@@ -52,7 +52,7 @@ import {} from '../common/constants'import { clickhouse } from '../common/integrations/clickhouse'import {- getFunnelsClickhouse,+ getFunnelClickhouse,hash,millisecondsToSeconds,sumArrays,@@ -748,7 +748,7 @@ export class AnalyticsService {): Promise<string[]> {if (funnelId && projectId) {const funnel = this.projectService.formatFunnelFromClickhouse(- await getFunnelsClickhouse(projectId, funnelId),+ await getFunnelClickhouse(projectId, funnelId),)if (!funnel || _isEmpty(funnel)) {diff --git a/backend/apps/selfhosted/src/auth/decorators/roles.decorator.ts b/backend/apps/selfhosted/src/auth/decorators/roles.decorator.tsindex 2a56336a4..fcbea69e4 100644--- a/backend/apps/selfhosted/src/auth/decorators/roles.decorator.ts+++ b/backend/apps/selfhosted/src/auth/decorators/roles.decorator.ts@@ -1,5 +1,5 @@import { SetMetadata } from '@nestjs/common'-import { UserType } from 'src/user/entities/user.entity'+import { UserType } from '../../user/entities/user.entity'export const ROLES_KEY = 'roles'export const Roles = (...roles: UserType[]) => SetMetadata(ROLES_KEY, roles)diff --git a/backend/apps/selfhosted/src/common/types.ts b/backend/apps/selfhosted/src/common/types.tsnew file mode 100644index 000000000..61e2e9a49--- /dev/null+++ b/backend/apps/selfhosted/src/common/types.ts@@ -0,0 +1,26 @@+export interface ClickhouseSFUser {+ id: string+ timezone: string | null+ timeFormat: string | null+ showLiveVisitorsInTitle: number | null+}++export interface ClickhouseProject {+ id: string+ name: string+ origins: string | null+ ipBlacklist: string | null+ active: number+ public: number+ isPasswordProtected: number+ passwordHash: string | null+ created: string+}++export interface ClickhouseFunnel {+ id: string+ name: string+ steps: string+ projectId: string+ created: string+}diff --git a/backend/apps/selfhosted/src/common/utils.ts b/backend/apps/selfhosted/src/common/utils.tsindex 65038c845..22b7b4622 100644--- a/backend/apps/selfhosted/src/common/utils.ts+++ b/backend/apps/selfhosted/src/common/utils.ts@@ -29,9 +29,10 @@ import {import { clickhouse } from './integrations/clickhouse'import { DEFAULT_TIMEZONE, TimeFormat } from '../user/entities/user.entity'import { Project } from '../project/entity/project.entity'-import { Funnel } from '../project/entity/funnel.entity'import { ProjectViewEntity } from '../project/entity/project-view.entity'+import { ClickhouseFunnel, ClickhouseSFUser } from './types'+dayjs.extend(utc)export const hash = (content: string): string => {@@ -76,26 +77,15 @@ const checkRateLimit = async (await redis.set(rlHash, 1 + rlCount, 'EX', reqTimeout)}-const getFunnelsClickhouse = async (projectId: string, funnelId = null) => {+const getFunnelClickhouse = async (+ projectId: string,+ funnelId = null,+): Promise<ClickhouseFunnel> => {const queryParams = {projectId,funnelId,}- if (!funnelId) {- const query =- 'SELECT * FROM funnel WHERE projectId = {projectId:FixedString(12)}'-- const { data } = await clickhouse- .query({- query,- query_params: queryParams,- })- .then(resultSet => resultSet.json())-- return data- }-const query = `SELECT*@@ -109,7 +99,7 @@ const getFunnelsClickhouse = async (projectId: string, funnelId = null) => {query,query_params: queryParams,})- .then(resultSet => resultSet.json())+ .then(resultSet => resultSet.json<ClickhouseFunnel>())if (_isEmpty(data)) {throw new NotFoundException(@@ -120,6 +110,26 @@ const getFunnelsClickhouse = async (projectId: string, funnelId = null) => {return _head(data)}+const getFunnelsClickhouse = async (+ projectId: string,+): Promise<ClickhouseFunnel[]> => {+ const queryParams = {+ projectId,+ }++ const query =+ 'SELECT * FROM funnel WHERE projectId = {projectId:FixedString(12)}'++ const { data } = await clickhouse+ .query({+ query,+ query_params: queryParams,+ })+ .then(resultSet => resultSet.json<ClickhouseFunnel>())++ return data+}+const updateFunnelClickhouse = async (funnel: any) => {const filtered = _reduce(_filter(_keys(funnel), key => ALLOWED_FUNNEL_KEYS.includes(key)),@@ -152,7 +162,7 @@ const deleteFunnelClickhouse = async (id: string) => {})}-const createFunnelClickhouse = async (funnel: Partial<Funnel>) => {+const createFunnelClickhouse = async (funnel: Partial<ClickhouseFunnel>) => {const { id, name, steps, projectId } = funnelawait clickhouse.insert({@@ -170,10 +180,30 @@ const createFunnelClickhouse = async (funnel: Partial<Funnel>) => {})}-const getProjectsClickhouse = async (id = null, search: string = null) => {- if (!id) {- if (search) {- const query = `+const getProjectClickhouse = async (id: string): Promise<Project> => {+ const query = `SELECT * FROM project WHERE id = {id:FixedString(12)};`++ const { data } = await clickhouse+ .query({+ query,+ query_params: {+ id,+ },+ })+ .then(resultSet => resultSet.json<Project>())++ if (_isEmpty(data)) {+ throw new NotFoundException(`Project ${id} was not found in the database`)+ }++ return _head(data)+}++const getProjectsClickhouse = async (+ search: string = null,+): Promise<Project[]> => {+ if (search) {+ const query = `SELECT*FROM project@@ -183,45 +213,27 @@ const getProjectsClickhouse = async (id = null, search: string = null) => {ORDER BY created ASC`- const { data } = await clickhouse- .query({- query,- query_params: {- search: `%${search}%`,- },- })- .then(resultSet => resultSet.json())-- return data- }-- const query = 'SELECT * FROM project ORDER BY created ASC;'-const { data } = await clickhouse.query({query,+ query_params: {+ search: `%${search}%`,+ },})- .then(resultSet => resultSet.json())+ .then(resultSet => resultSet.json<Project>())return data}- const query = `SELECT * FROM project WHERE id = {id:FixedString(12)};`+ const query = 'SELECT * FROM project ORDER BY created ASC;'const { data } = await clickhouse.query({query,- query_params: {- id,- },})- .then(resultSet => resultSet.json())-- if (_isEmpty(data)) {- throw new NotFoundException(`Project ${id} was not found in the database`)- }+ .then(resultSet => resultSet.json<Project>())- return _head(data)+ return data}const updateProjectClickhouse = async (project: any) => {@@ -387,9 +399,9 @@ const getUserClickhouse = async () => {id: CLICKHOUSE_SETTINGS_ID,},})- .then(resultSet => resultSet.json())+ .then(resultSet => resultSet.json<ClickhouseSFUser>())- return data[0] || {}+ return data[0] || ({} as ClickhouseSFUser)} catch {return {}}@@ -737,6 +749,7 @@ const sumArrays = (source: number[], target: number[]) => {export {checkRateLimit,createProjectClickhouse,+ getProjectClickhouse,getProjectsClickhouse,updateProjectClickhouse,deleteProjectClickhouse,@@ -752,6 +765,7 @@ export {getGeoDetails,getIPFromHeaders,sumArrays,+ getFunnelClickhouse,getFunnelsClickhouse,updateFunnelClickhouse,deleteFunnelClickhouse,diff --git a/backend/apps/selfhosted/src/project/project.controller.ts b/backend/apps/selfhosted/src/project/project.controller.tsindex bde79af31..f519f3939 100644--- a/backend/apps/selfhosted/src/project/project.controller.ts+++ b/backend/apps/selfhosted/src/project/project.controller.ts@@ -76,6 +76,8 @@ import {findProjectViewsClickhouse,doesProjectViewExistClickhouse,updateProjectViewClickhouse,+ getProjectClickhouse,+ getFunnelClickhouse,} from '../common/utils'import { Funnel } from './entity/funnel.entity'import { ProjectViewEntity } from './entity/project-view.entity'@@ -106,7 +108,7 @@ export class ProjectController {): Promise<Pagination<Project> | Project[] | object> {this.logger.log({ userId, take, skip }, 'GET /project')- const chResults = await getProjectsClickhouse(null, search)+ const chResults = await getProjectsClickhouse(search)const formatted = _map(chResults, this.projectService.formatFromClickhouse)const pidsWithData =@@ -130,6 +132,7 @@ export class ProjectController {const funnelsMap = _reduce(funnelsData,+ // @ts-expect-error This one is super sus, take a look at this in future(acc, { status, value }) => {if (status !== 'fulfilled') {return acc@@ -245,7 +248,7 @@ export class ProjectController {throw new UnauthorizedException('Please auth first')}- const project = getProjectsClickhouse(funnelDTO.pid)+ const project = getProjectClickhouse(funnelDTO.pid)if (!project) {throw new NotFoundException('Project not found.')@@ -283,14 +286,14 @@ export class ProjectController {throw new UnauthorizedException('Please auth first')}- const project = getProjectsClickhouse(funnelDTO.pid)+ const project = getProjectClickhouse(funnelDTO.pid)if (!project) {throw new NotFoundException('Project not found.')}const oldFunnel = this.projectService.formatFunnelFromClickhouse(- await getFunnelsClickhouse(funnelDTO.pid, funnelDTO.id),+ await getFunnelClickhouse(funnelDTO.pid, funnelDTO.id),)if (!oldFunnel) {@@ -320,7 +323,7 @@ export class ProjectController {throw new UnauthorizedException('Please auth first')}- const oldFunnel = getFunnelsClickhouse(pid, id)+ const oldFunnel = getFunnelClickhouse(pid, id)if (!oldFunnel) {throw new NotFoundException('Funnel not found.')@@ -343,7 +346,7 @@ export class ProjectController {throw new UnauthorizedException('Please auth first')}- const project = await getProjectsClickhouse(pid)+ const project = await getProjectClickhouse(pid)if (!project) {throw new NotFoundException('Project not found.')@@ -366,7 +369,7 @@ export class ProjectController {): Promise<boolean> {this.logger.log({ projectId }, 'GET /project/password/:projectId')- const project = await getProjectsClickhouse(projectId)+ const project = await getProjectClickhouse(projectId)if (!project) {throw new NotFoundException('Project not found.')@@ -424,7 +427,7 @@ export class ProjectController {}// Checking if project exists- getProjectsClickhouse(pid)+ getProjectClickhouse(pid)from = dayjs(from).format('YYYY-MM-DD')to = dayjs(to).format('YYYY-MM-DD 23:59:59')@@ -474,7 +477,7 @@ export class ProjectController {): Promise<any> {this.logger.log({ projectDTO, uid, id }, 'PUT /project/:id')this.projectService.validateProject(projectDTO)- const project = await getProjectsClickhouse(id)+ const project = await getProjectClickhouse(id)if (_isEmpty(project)) {throw new NotFoundException()@@ -541,7 +544,7 @@ export class ProjectController {)}- const project = await getProjectsClickhouse(id)+ const project = await getProjectClickhouse(id)if (_isEmpty(project)) {throw new NotFoundException('Project was not found in the database')@@ -584,7 +587,7 @@ export class ProjectController {@CurrentUserId() userId: string,@Headers() headers: { 'x-password'?: string },) {- const project = await getProjectsClickhouse(params.projectId)+ const project = await getProjectClickhouse(params.projectId)if (_isEmpty(project)) {throw new NotFoundException('Project was not found in the database')@@ -609,7 +612,7 @@ export class ProjectController {throw new UnauthorizedException('Please auth first')}- const project = await getProjectsClickhouse(params.projectId)+ const project = await getProjectClickhouse(params.projectId)if (_isEmpty(project)) {throw new NotFoundException('Project was not found in the database')@@ -632,6 +635,7 @@ export class ProjectController {}await createProjectViewClickhouse(+ // @ts-expect-errorthis.projectService.formatViewToClickhouse({...body,customEvents,@@ -655,7 +659,7 @@ export class ProjectController {@CurrentUserId() userId: string,@Headers() headers: { 'x-password'?: string },) {- const project = await getProjectsClickhouse(params.projectId)+ const project = await getProjectClickhouse(params.projectId)if (_isEmpty(project)) {throw new NotFoundException('Project was not found in the database')diff --git a/backend/apps/selfhosted/src/project/project.service.ts b/backend/apps/selfhosted/src/project/project.service.tsindex 30d0b6f85..ea458b271 100644--- a/backend/apps/selfhosted/src/project/project.service.ts+++ b/backend/apps/selfhosted/src/project/project.service.ts@@ -35,7 +35,7 @@ import {TRAFFIC_METAKEY_COLUMNS,} from '../common/constants'import { clickhouse } from '../common/integrations/clickhouse'-import { getProjectsClickhouse } from '../common/utils'+import { getProjectClickhouse } from '../common/utils'import { MAX_PROJECT_PASSWORD_LENGTH, UpdateProjectDto } from './dto'import { Funnel } from './entity/funnel.entity'import { ProjectViewEntity } from './entity/project-view.entity'@@ -45,6 +45,7 @@ import {ProjectViewCustomEventDto,} from './dto/create-project-view.dto'import { ProjectViewCustomEventEntity } from './entity/project-view-custom-event.entity'+import { ClickhouseFunnel } from '../common/types'// A list of characters that can be used in a Project IDconst LEGAL_PID_CHARACTERS =@@ -68,7 +69,7 @@ export class ProjectService {let project: string | Project = await redis.get(pidKey)if (_isEmpty(project)) {- project = this.formatFromClickhouse(await getProjectsClickhouse(pid))+ project = this.formatFromClickhouse(await getProjectClickhouse(pid))if (_isEmpty(project))throw new BadRequestException(@@ -116,11 +117,11 @@ export class ProjectService {throw new ForbiddenException('You are not allowed to view this project')}- isPIDUnique(projects: Array<object>, pid: string): boolean {+ isPIDUnique(projects: Project[], pid: string): boolean {return !_find(projects, ({ id }) => id === pid)}- checkIfIDUnique(projects: Array<object>, pid: string): void {+ checkIfIDUnique(projects: Project[], pid: string): void {const isUnique = this.isPIDUnique(projects, pid)if (!isUnique) {@@ -336,8 +337,8 @@ export class ProjectService {return _filter(filters,({ column }) =>- _includes(ALL_COLUMNS, column) ||- _includes(TRAFFIC_METAKEY_COLUMNS, column),+ _includes(ALL_COLUMNS, column as string) ||+ _includes(TRAFFIC_METAKEY_COLUMNS, column as string),)}@@ -363,7 +364,7 @@ export class ProjectService {formatCustomEventsToClickhouse(viewId: string,- customEvents: ProjectViewCustomEventEntity[] | ProjectViewCustomEventDto[],+ customEvents: (ProjectViewCustomEventEntity | ProjectViewCustomEventDto)[],) {if (_isEmpty(customEvents)) {return []@@ -417,8 +418,8 @@ export class ProjectService {return updView}- formatFunnelToClickhouse(funnel: Funnel): any {- const updFunnel = { ...funnel }+ formatFunnelToClickhouse(funnel: Funnel): ClickhouseFunnel {+ const updFunnel = { ...funnel } as unknown as ClickhouseFunnelupdFunnel.name = _trim(funnel.name)updFunnel.steps = _isString(updFunnel.steps)? updFunnel.steps@@ -427,7 +428,7 @@ export class ProjectService {return updFunnel}- formatFunnelsFromClickhouse(funnels: any[]): Funnel[] {+ formatFunnelsFromClickhouse(funnels: ClickhouseFunnel[]): Funnel[] {if (_isEmpty(funnels)) {return []}diff --git a/backend/apps/selfhosted/src/user/entities/user.entity.ts b/backend/apps/selfhosted/src/user/entities/user.entity.tsindex 6516ad877..d5f8d86b7 100644--- a/backend/apps/selfhosted/src/user/entities/user.entity.ts+++ b/backend/apps/selfhosted/src/user/entities/user.entity.ts@@ -43,7 +43,7 @@ export const getSelfhostedUser = async (): Promise<SelfhostedUser> => {let settings = {}try {- settings = _omit((await getUserClickhouse()) || {}, ['id'])+ settings = _omit(await getUserClickhouse(), ['id'])} catch (reason) {console.error('[ERROR] getSelfhostedUser: ', reason)}diff --git a/backend/apps/selfhosted/src/user/user.controller.ts b/backend/apps/selfhosted/src/user/user.controller.tsindex 8e4e4c07d..0a9d4a8c2 100644--- a/backend/apps/selfhosted/src/user/user.controller.ts+++ b/backend/apps/selfhosted/src/user/user.controller.ts@@ -85,7 +85,7 @@ export class UserController {})const user = generateSelfhostedUser()- const settings = _omit((await getUserClickhouse()) || {}, ['id'])+ const settings = _omit(await getUserClickhouse(), ['id'])return {...user,