📈 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
code clean-up
Blue Mouse4eb36b39b31a
diff --git a/src/analytics/analytics.controller.ts b/src/analytics/analytics.controller.tsindex 469a9dfbf..887a2dd80 100644--- a/src/analytics/analytics.controller.ts+++ b/src/analytics/analytics.controller.ts@@ -208,7 +208,7 @@ const isPerformanceValid = (perf: any) => {)}-export const getPIDsArray = (pids, pid) => {+const getPIDsArray = (pids, pid) => {const pidsEmpty = _isEmpty(pids)const pidEmpty = _isEmpty(pid)if (pidsEmpty && pidEmpty)diff --git a/src/analytics/analytics.service.ts b/src/analytics/analytics.service.tsindex 70f331f7a..89dd532d5 100644--- a/src/analytics/analytics.service.ts+++ b/src/analytics/analytics.service.ts@@ -76,31 +76,19 @@ export const getSessionKey = (ip: string, ua: string, pid: string, salt = '') =>export const getHeartbeatKey = (pid: string, sessionID: string) =>`hb:${pid}:${sessionID}`-export const getSessionDurationKey = (sessionHash: string, pid: string) =>+const getSessionDurationKey = (sessionHash: string, pid: string) =>`sd:${sessionHash}:${pid}`-export const GMT_0_TIMEZONES = [+const GMT_0_TIMEZONES = ['Atlantic/Azores','Etc/GMT',// 'Africa/Casablanca',]-export const cols = [- 'cc',- 'pg',- 'lc',- 'br',- 'os',- 'dv',- 'ref',- 'so',- 'me',- 'ca',-]--export const captchaColumns = ['cc', 'br', 'os', 'dv']+const cols = ['cc', 'pg', 'lc', 'br', 'os', 'dv', 'ref', 'so', 'me', 'ca']-export const perfColumns = ['cc', 'pg', 'dv', 'br']+const captchaColumns = ['cc', 'br', 'os', 'dv']+const perfColumns = ['cc', 'pg', 'dv', 'br']const validPeriods = ['today',@@ -892,19 +880,6 @@ export class AnalyticsService {}}- checkTimebucket(timeBucket: TimeBucketType): void {- const isValid = _includes(- [TimeBucketType.HOUR, TimeBucketType.DAY, TimeBucketType.MONTH],- timeBucket,- )-- if (!isValid) {- throw new BadRequestException(- `The provided time bucket (${timeBucket}) is incorrect`,- )- }- }-generateDateString(row: { [key: string]: number }): string {const { year, month, day, hour } = rowdiff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.tsindex 992dd46cd..944617f04 100644--- a/src/auth/auth.controller.ts+++ b/src/auth/auth.controller.ts@@ -54,8 +54,8 @@ import {SSOGenerateDto,SSOLinkDto,SSOUnlinkDto,+ SSOProviders,} from './dtos'-import { SSOProviders } from './dtos/sso-generate.dto'import { JwtAccessTokenGuard, JwtRefreshTokenGuard, RolesGuard } from './guards'const OAUTH_RATE_LIMIT = 15diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.tsindex d424dd874..ad5810136 100644--- a/src/auth/auth.service.ts+++ b/src/auth/auth.service.ts@@ -51,7 +51,7 @@ import {JWT_ACCESS_TOKEN_SECRET,} from 'src/common/constants'import { TelegramService } from 'src/integrations/telegram/telegram.service'-import { SSOProviders } from './dtos/sso-generate.dto'+import { SSOProviders } from './dtos'import { UserGoogleDTO } from '../user/dto/user-google.dto'import { UserGithubDTO } from '../user/dto/user-github.dto'diff --git a/src/auth/dtos/google-auth-user.dto.ts b/src/auth/dtos/google-auth-user.dto.tsdeleted file mode 100644index fd143693b..000000000--- a/src/auth/dtos/google-auth-user.dto.ts+++ /dev/null@@ -1,11 +0,0 @@-import { ApiProperty } from '@nestjs/swagger'-import { IsUUID } from 'class-validator'--export class AuthUserGoogleDto {- @ApiProperty({- description: 'SSO session identifier',- example: '123e4567-e89b-12d3-a456-426614174000',- })- @IsUUID()- hash: string-}diff --git a/src/common/constants.ts b/src/common/constants.tsindex d09a9f2d3..fb60c0988 100644--- a/src/common/constants.ts+++ b/src/common/constants.ts@@ -46,7 +46,6 @@ const clickhouse = new ClickHouse({const { JWT_ACCESS_TOKEN_SECRET } = process.envconst isSelfhosted = Boolean(process.env.SELFHOSTED)-const isTgTokenPresent = Boolean(process.env.TG_BOT_TOKEN)const isNewRelicEnabled = Boolean(process.env.USE_NEW_RELIC)const isDevelopment = process.env.NODE_ENV === 'development'const PRODUCTION_ORIGIN = process.env.CLIENT_URL || 'https://swetrix.com'@@ -60,9 +59,6 @@ const SELFHOSTED_UUID = isSelfhosted ? getSelfhostedUUID() : ''const { TWO_FACTOR_AUTHENTICATION_APP_NAME } = process.env-const JWT_LIFE_TIME = 7 * 24 * 60 * 60-const HISTORY_LIFE_TIME_DAYS = 30-const ORIGINS_REGEX =/^(?=.{1,255}$)[0-9A-Za-z:](?:(?:[0-9A-Za-z:]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z:](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/const IP_REGEX =@@ -116,8 +112,6 @@ const CAPTCHA_SECRET_KEY_LENGTH = 50export {clickhouse,- JWT_LIFE_TIME,- HISTORY_LIFE_TIME_DAYS,redis,isValidPID,getRedisProjectKey,@@ -153,10 +147,8 @@ export {getRedisCaptchaKey,CAPTCHA_COOKIE_KEY,CAPTCHA_TOKEN_LIFETIME,- PID_REGEX,CAPTCHA_SECRET_KEY_LENGTH,PRODUCTION_ORIGIN,- isTgTokenPresent,DEFAULT_SELFHOSTED_UUID,REDIS_SSO_UUID,JWT_ACCESS_TOKEN_SECRET,diff --git a/src/common/utils.ts b/src/common/utils.tsindex ed6ca57b7..11e1f9df5 100644--- a/src/common/utils.ts+++ b/src/common/utils.ts@@ -64,11 +64,6 @@ const allowedToUpdateKeys = [const getRateLimitHash = (ipOrApiKey: string, salt = '') =>`rl:${hash(`${ipOrApiKey}${salt}`).toString('hex')}`-const splitAt = (x, index): Array<Array<any> | string> => [- x.slice(0, index),- x.slice(index),-]-const getRandomTip = (language = 'en'): string => {return _sample(marketingTips[language])}@@ -150,26 +145,6 @@ const updateProjectClickhouse = async (project: object) => {return clickhouse.query(query).toPromise()}-/**- * Calculates in percent, the change between 2 numbers.- * e.g from 1000 to 500 = 50%- *- * @param oldVal The initial value- * @param newVal The value that changed- * @param round Numbers after floating point- */-const getPercentageChange = (oldVal: number, newVal: number, round = 2) => {- if (oldVal === 0) {- if (newVal === 0) {- return 0- }- return _round(-100 * newVal, round)- }-- const decrease = oldVal - newVal- return _round((decrease / oldVal) * 100, round)-}-/*** Checking the % change in one number relative to the other* @param oldVal The initial value@@ -281,9 +256,7 @@ export {getProjectsClickhouse,updateProjectClickhouse,deleteProjectClickhouse,- splitAt,generateRecoveryCode,- getPercentageChange,calculateRelativePercentage,millisecondsToSeconds,generateRandomString,diff --git a/src/marketplace/extensions/extensions.service.ts b/src/marketplace/extensions/extensions.service.tsindex 676143ca3..5c6050349 100644--- a/src/marketplace/extensions/extensions.service.ts+++ b/src/marketplace/extensions/extensions.service.ts@@ -18,7 +18,7 @@ import { VersionTypes } from './interfaces'import { SearchExtensionQueries } from './dtos/search-extension-queries.dto'import { GetAllExtensionsQueries } from './dtos/get-all-extensions-queries.dto'-export const DEFAULT_EXTENSION_VERSION = '0.0.1'+const DEFAULT_EXTENSION_VERSION = '0.0.1'@Injectable()export class ExtensionsService {diff --git a/src/project/project.service.ts b/src/project/project.service.tsindex 4c0d6ec6f..939c22c36 100644--- a/src/project/project.service.ts+++ b/src/project/project.service.ts@@ -82,7 +82,7 @@ export const deleteProjectRedis = async (id: string) => {}}-export const deleteProjectsRedis = async (ids: string[]) => {+const deleteProjectsRedis = async (ids: string[]) => {await Promise.all(_map(ids, deleteProjectRedis))}@@ -100,7 +100,7 @@ export const processProjectUser = (project: Project): Project => {return project}-export const processProjectsUser = (projects: Project[]): Project[] => {+const processProjectsUser = (projects: Project[]): Project[] => {for (let i = 0; i < _size(projects); ++i) {projects[i] = processProjectUser(projects[i])}diff --git a/src/twoFactorAuth/twoFactorAuth.controller.ts b/src/twoFactorAuth/twoFactorAuth.controller.tsindex b2531a97c..033dcebfa 100644--- a/src/twoFactorAuth/twoFactorAuth.controller.ts+++ b/src/twoFactorAuth/twoFactorAuth.controller.ts@@ -18,10 +18,8 @@ import { UserType } from '../user/entities/user.entity'import { AppLoggerService } from '../logger/logger.service'import { MailerService } from '../mailer/mailer.service'import { LetterTemplate } from '../mailer/letter'-import { CurrentUserId } from '../auth/decorators/current-user-id.decorator'import { SelfhostedGuard } from '../common/guards/selfhosted.guard'-import { Roles } from '../auth/decorators/roles.decorator'-import { TwoFaNotRequired } from '../auth/decorators/two-fa-not-required.decorator'+import { TwoFaNotRequired, Roles, CurrentUserId } from '../auth/decorators'import { RolesGuard } from '../auth/guards/roles.guard'import { TwoFactorAuthDTO } from './dto/2fa-auth.dto'import { generateRecoveryCode, checkRateLimit } from '../common/utils'diff --git a/src/user/entities/user.entity.ts b/src/user/entities/user.entity.tsindex e174b90ad..1c471371b 100644--- a/src/user/entities/user.entity.ts+++ b/src/user/entities/user.entity.ts@@ -105,7 +105,7 @@ export enum UserType {ADMIN = 'admin',}-export enum ReportFrequency {+enum ReportFrequency {Never = 'never',Weekly = 'weekly',Monthly = 'monthly',