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!

added important features

Yevhenii Kulisidi700f9923fcc4
diff --git a/src/analytics/analytics.service.ts b/src/analytics/analytics.service.ts
index a84724908..eafed64b0 100644
--- a/src/analytics/analytics.service.ts
+++ b/src/analytics/analytics.service.ts
@@ -34,7 +34,10 @@ import {
isSelfhosted,
REDIS_SESSION_SALT_KEY,
} from '../common/constants'
-import { getProjectsClickhouse, calculateRelativePercentage } from '../common/utils'
+import {
+ getProjectsClickhouse,
+ calculateRelativePercentage,
+} from '../common/utils'
import { PageviewsDTO } from './dto/pageviews.dto'
import { EventsDTO } from './dto/events.dto'
import { ProjectService } from '../project/project.service'
@@ -464,7 +467,10 @@ export class AnalyticsService {
thisWeekUnique,
lastWeekUnique,
percChange: calculateRelativePercentage(lastWeekPV, thisWeekPV),
- percChangeUnique: calculateRelativePercentage(lastWeekUnique, thisWeekUnique),
+ percChangeUnique: calculateRelativePercentage(
+ lastWeekUnique,
+ thisWeekUnique,
+ ),
}
} catch {
throw new InternalServerErrorException(
diff --git a/src/app.module.ts b/src/app.module.ts
index 8dc843b9a..9ef544dcd 100644
--- a/src/app.module.ts
+++ b/src/app.module.ts
@@ -23,10 +23,12 @@ import { MarketplaceModule } from './marketplace/marketplace.module'
import { Category } from './marketplace/categories/category.entity'
import { Extension } from './marketplace/extensions/extension.entity'
-const entities = [User, ActionToken, Project, ProjectShare, Category]
+const entities = []
if (process.env.ACTIVATE_MARKETPLACE) {
- entities.push(Extension)
+ entities.push(User, ActionToken, Project, ProjectShare, Extension, Category)
+} else {
+ entities.push(User, ActionToken, Project, ProjectShare)
}
const modules = [
diff --git a/src/common/utils.ts b/src/common/utils.ts
index 3b8148a1e..727343714 100644
--- a/src/common/utils.ts
+++ b/src/common/utils.ts
@@ -117,7 +117,6 @@ const updateProjectClickhouse = async (project: object) => {
return await clickhouse.query(query).toPromise()
}
-
/**
* Calculates in percent, the change between 2 numbers.
* e.g from 1000 to 500 = 50%
@@ -145,7 +144,11 @@ const getPercentageChange = (oldVal: number, newVal: number, round = 2) => {
* @param newVal The value that changed
* @param round Numbers after floating point
*/
-const calculateRelativePercentage = (oldVal: number, newVal: number, round = 2) => {
+const calculateRelativePercentage = (
+ oldVal: number,
+ newVal: number,
+ round = 2,
+) => {
if (oldVal === newVal) return 0
if (oldVal === 0) return 100
if (newVal === 0) return -100
diff --git a/src/marketplace/categories/categories.controller.ts b/src/marketplace/categories/categories.controller.ts
index d24673d34..bf12ff1a3 100644
--- a/src/marketplace/categories/categories.controller.ts
+++ b/src/marketplace/categories/categories.controller.ts
@@ -1,6 +1,5 @@
import {
Body,
- ConflictException,
Controller,
Delete,
Get,
@@ -71,12 +70,18 @@ export class CategoriesController {
@ApiParam({
name: 'categoryId',
description: 'Category ID',
- example: '1',
- type: String,
+ example: 1,
+ type: Number,
})
+ // TODO: add pagination for extensions
@Get(':categoryId')
async getCategory(@Param() params: GetCategoryParams): Promise<Category> {
- const category = await this.categoriesService.findById(params.categoryId)
+ const category = await this.categoriesService.findOne({
+ where: {
+ id: params.categoryId,
+ },
+ relations: ['extensions'],
+ })
if (!category) {
throw new NotFoundException('Category not found.')
@@ -91,22 +96,15 @@ export class CategoriesController {
async createCategory(
@Body() body: CreateCategory,
): Promise<ISaveCategory & Category> {
- const title = await this.categoriesService.findTitle(body.title)
-
- if (title) {
- throw new ConflictException('The category already exists.')
- }
-
const categoryInstance = this.categoriesService.create(body)
-
return await this.categoriesService.save(categoryInstance)
}
@ApiParam({
name: 'categoryId',
description: 'Category ID',
- example: '1',
- type: String,
+ example: 1,
+ type: Number,
})
@UseGuards(RolesGuard)
@Roles(UserType.ADMIN)
@@ -129,8 +127,8 @@ export class CategoriesController {
@ApiParam({
name: 'categoryId',
description: 'Category ID',
- example: '1',
- type: String,
+ example: 1,
+ type: Number,
})
@UseGuards(RolesGuard)
@Roles(UserType.ADMIN)
diff --git a/src/marketplace/categories/categories.service.ts b/src/marketplace/categories/categories.service.ts
index 3dedafd51..99a885ade 100644
--- a/src/marketplace/categories/categories.service.ts
+++ b/src/marketplace/categories/categories.service.ts
@@ -17,10 +17,6 @@ export class CategoriesService {
return await this.categoryRepository.findOne({ ...options })
}
- async findTitle(title: string): Promise<Category> {
- return await this.findOne({ where: { title }, select: ['title'] })
- }
-
create(category: ICreateCategory): Category {
return this.categoryRepository.create(category)
}
diff --git a/src/marketplace/categories/category.entity.ts b/src/marketplace/categories/category.entity.ts
index 8b966306e..3b7e0fa8e 100644
--- a/src/marketplace/categories/category.entity.ts
+++ b/src/marketplace/categories/category.entity.ts
@@ -1,4 +1,5 @@
-import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm'
+import { Column, Entity, ManyToMany, PrimaryGeneratedColumn } from 'typeorm'
+import { Extension } from '../extensions/extension.entity'
@Entity()
export class Category {
@@ -6,8 +7,8 @@ export class Category {
id!: number
@Column({ type: 'varchar', unique: true })
- title!: string
+ name!: string
- @Column({ type: 'text', nullable: true, default: null })
- description!: string | null
+ @ManyToMany(() => Extension, extension => extension.categories)
+ extensions!: Extension[]
}
diff --git a/src/marketplace/categories/dtos/create-category.dto.ts b/src/marketplace/categories/dtos/create-category.dto.ts
index 4850f67bd..a206c3fac 100644
--- a/src/marketplace/categories/dtos/create-category.dto.ts
+++ b/src/marketplace/categories/dtos/create-category.dto.ts
@@ -1,9 +1,9 @@
import { ApiProperty } from '@nestjs/swagger'
-import { IsOptional, IsString, MaxLength, MinLength } from 'class-validator'
+import { IsString, MaxLength, MinLength } from 'class-validator'
export class CreateCategory {
@ApiProperty({
- description: 'Category title',
+ description: 'Category name',
example: 'Marketing',
maxLength: 255,
minLength: 1,
@@ -12,21 +12,5 @@ export class CreateCategory {
@IsString()
@MinLength(1)
@MaxLength(255)
- readonly title!: string
-
- @ApiProperty({
- default: null,
- description: 'Category description',
- example: 'Extensions for your marketing needs.',
- maxLength: 1024,
- minLength: 1,
- nullable: true,
- required: false,
- type: String,
- })
- @IsString()
- @IsOptional()
- @MinLength(1)
- @MaxLength(1024)
- readonly description?: string | null
+ readonly name!: string
}
diff --git a/src/marketplace/categories/dtos/update-category.dto.ts b/src/marketplace/categories/dtos/update-category.dto.ts
index 35c571872..25affb003 100644
--- a/src/marketplace/categories/dtos/update-category.dto.ts
+++ b/src/marketplace/categories/dtos/update-category.dto.ts
@@ -3,7 +3,7 @@ import { IsOptional, IsString, MaxLength, MinLength } from 'class-validator'
export class UpdateCategory {
@ApiProperty({
- description: 'Category title',
+ description: 'Category name',
example: 'Marketing',
maxLength: 255,
minLength: 1,
@@ -14,20 +14,5 @@ export class UpdateCategory {
@IsOptional()
@MinLength(1)
@MaxLength(255)
- readonly title?: string
-
- @ApiProperty({
- description: 'Category description',
- example: 'Extensions for your marketing needs.',
- maxLength: 1024,
- minLength: 1,
- nullable: true,
- required: false,
- type: String,
- })
- @IsString()
- @IsOptional()
- @MinLength(1)
- @MaxLength(1024)
- readonly description?: string | null
+ readonly name?: string
}
diff --git a/src/marketplace/categories/interfaces/create-category.interface.ts b/src/marketplace/categories/interfaces/create-category.interface.ts
index 9837f2d3d..dd8c82588 100644
--- a/src/marketplace/categories/interfaces/create-category.interface.ts
+++ b/src/marketplace/categories/interfaces/create-category.interface.ts
@@ -1,4 +1,3 @@
export interface ICreateCategory {
- title: string
- description?: string | null
+ name: string
}
diff --git a/src/marketplace/categories/interfaces/save-category.interface.ts b/src/marketplace/categories/interfaces/save-category.interface.ts
index e1d3c8f77..97de4c368 100644
--- a/src/marketplace/categories/interfaces/save-category.interface.ts
+++ b/src/marketplace/categories/interfaces/save-category.interface.ts
@@ -1,4 +1,3 @@
export interface ISaveCategory {
- title: string
- description?: string | null
+ name: string
}
diff --git a/src/marketplace/categories/interfaces/update-category.interface.ts b/src/marketplace/categories/interfaces/update-category.interface.ts
index efb362c70..de2cb42ab 100644
--- a/src/marketplace/categories/interfaces/update-category.interface.ts
+++ b/src/marketplace/categories/interfaces/update-category.interface.ts
@@ -1,4 +1,3 @@
export interface IUpdateCategory {
- title?: string
- description?: string | null
+ name?: string
}
diff --git a/src/marketplace/extensions/dtos/add-extension.dto.ts b/src/marketplace/extensions/dtos/create-extension.dto.ts
similarity index 90%
rename from src/marketplace/extensions/dtos/add-extension.dto.ts
rename to src/marketplace/extensions/dtos/create-extension.dto.ts
index 6a4f66e18..505afbf29 100644
--- a/src/marketplace/extensions/dtos/add-extension.dto.ts
+++ b/src/marketplace/extensions/dtos/create-extension.dto.ts
@@ -7,9 +7,9 @@ import {
MinLength,
} from 'class-validator'
-export class AddExtension {
+export class CreateExtension {
@ApiProperty({
- description: 'Extension title',
+ description: 'Extension name',
example: '', // TODO: Add example
maxLength: 255,
minLength: 1,
@@ -18,7 +18,7 @@ export class AddExtension {
@IsString()
@MinLength(1)
@MaxLength(255)
- readonly title!: string
+ readonly name!: string
@ApiProperty({
default: null,
diff --git a/src/marketplace/extensions/dtos/delete-extension-params.dto.ts b/src/marketplace/extensions/dtos/delete-extension-params.dto.ts
new file mode 100644
index 000000000..86470c2aa
--- /dev/null
+++ b/src/marketplace/extensions/dtos/delete-extension-params.dto.ts
@@ -0,0 +1,6 @@
+import { IsString } from 'class-validator'
+
+export class DeleteExtensionParams {
+ @IsString()
+ readonly extensionId!: string
+}
diff --git a/src/marketplace/extensions/dtos/get-extension-params.dto.ts b/src/marketplace/extensions/dtos/get-extension-params.dto.ts
index 6ee0adc0c..9fee7d1ac 100644
--- a/src/marketplace/extensions/dtos/get-extension-params.dto.ts
+++ b/src/marketplace/extensions/dtos/get-extension-params.dto.ts
@@ -1,6 +1,6 @@
-import { IsNumberString } from 'class-validator'
+import { IsString } from 'class-validator'
export class GetExtensionParams {
- @IsNumberString()
- readonly extensionId!: number
+ @IsString()
+ readonly extensionId!: string
}
diff --git a/src/marketplace/extensions/dtos/remove-extension-params.dto.ts b/src/marketplace/extensions/dtos/remove-extension-params.dto.ts
deleted file mode 100644
index 297191dcd..000000000
--- a/src/marketplace/extensions/dtos/remove-extension-params.dto.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-import { IsNumberString } from 'class-validator'
-
-export class RemoveExtensionParams {
- @IsNumberString()
- readonly extensionId!: number
-}
diff --git a/src/marketplace/extensions/dtos/search-extension-queries.dto.ts b/src/marketplace/extensions/dtos/search-extension-queries.dto.ts
index 4cb59a742..74703a560 100644
--- a/src/marketplace/extensions/dtos/search-extension-queries.dto.ts
+++ b/src/marketplace/extensions/dtos/search-extension-queries.dto.ts
@@ -2,7 +2,7 @@ import { IsNumberString, IsOptional, IsString } from 'class-validator'
export class SearchExtensionQueries {
@IsString()
- readonly query!: string
+ readonly term!: string
@IsNumberString()
@IsOptional()
diff --git a/src/marketplace/extensions/dtos/update-extension-params.dto.ts b/src/marketplace/extensions/dtos/update-extension-params.dto.ts
index ede34938f..93493a1a3 100644
--- a/src/marketplace/extensions/dtos/update-extension-params.dto.ts
+++ b/src/marketplace/extensions/dtos/update-extension-params.dto.ts
@@ -1,6 +1,6 @@
-import { IsNumberString } from 'class-validator'
+import { IsString } from 'class-validator'
export class UpdateExtensionParams {
- @IsNumberString()
- readonly extensionId!: number
+ @IsString()
+ readonly extensionId!: string
}
diff --git a/src/marketplace/extensions/dtos/update-extension.dto.ts b/src/marketplace/extensions/dtos/update-extension.dto.ts
index cb860ebce..fde26880f 100644
--- a/src/marketplace/extensions/dtos/update-extension.dto.ts
+++ b/src/marketplace/extensions/dtos/update-extension.dto.ts
@@ -9,7 +9,7 @@ import {
export class UpdateExtension {
@ApiProperty({
- description: 'Extension title',
+ description: 'Extension name',
example: '', // TODO: Add example
maxLength: 255,
minLength: 1,
@@ -19,7 +19,7 @@ export class UpdateExtension {
@IsOptional()
@MinLength(1)
@MaxLength(255)
- readonly title!: string
+ readonly name!: string
@ApiProperty({
default: null,
diff --git a/src/marketplace/extensions/extension.entity.ts b/src/marketplace/extensions/extension.entity.ts
index 4e720083f..68e2a3f09 100644
--- a/src/marketplace/extensions/extension.entity.ts
+++ b/src/marketplace/extensions/extension.entity.ts
@@ -2,25 +2,25 @@ import {
Column,
CreateDateColumn,
Entity,
+ JoinTable,
+ ManyToMany,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm'
+import { Category } from '../categories/category.entity'
import { ExtensionStatus } from './enums/extension-status.enum'
@Entity()
export class Extension {
- @PrimaryGeneratedColumn('increment')
- id!: number
+ @PrimaryGeneratedColumn('uuid')
+ id!: string
- @Column({ type: 'varchar', unique: true })
- title!: string
+ @Column('varchar')
+ name: string
@Column({ type: 'text', nullable: true, default: null })
description!: string | null
- @Column({ type: 'uuid', generated: 'uuid', unique: true })
- url: string
-
@Column('varchar')
version: string
@@ -36,4 +36,8 @@ export class Extension {
@UpdateDateColumn()
updatedAt: Date
+
+ @ManyToMany(() => Category, category => category.extensions)
+ @JoinTable()
+ categories!: Category[]
}
diff --git a/src/marketplace/extensions/extensions.controller.ts b/src/marketplace/extensions/extensions.controller.ts
index faa6aed19..837258099 100644
--- a/src/marketplace/extensions/extensions.controller.ts
+++ b/src/marketplace/extensions/extensions.controller.ts
@@ -1,6 +1,5 @@
import {
Body,
- ConflictException,
Controller,
Delete,
Get,
@@ -14,8 +13,8 @@ import {
} from '@nestjs/common'
import { ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger'
import { Like } from 'typeorm'
-import { AddExtension } from './dtos/add-extension.dto'
-import { RemoveExtensionParams } from './dtos/remove-extension-params.dto'
+import { CreateExtension } from './dtos/create-extension.dto'
+import { DeleteExtensionParams } from './dtos/delete-extension-params.dto'
import { GetExtensionParams } from './dtos/get-extension-params.dto'
import { GetAllExtensionsQueries } from './dtos/get-all-extensions-queries.dto'
import { Extension } from './extension.entity'
@@ -67,9 +66,9 @@ export class ExtensionsController {
}
@ApiQuery({
- description: 'Extension query',
+ description: 'Extension term',
example: '',
- name: 'query',
+ name: 'term',
type: String,
})
@ApiQuery({
@@ -93,7 +92,7 @@ export class ExtensionsController {
}> {
const [extensions, count] = await this.extensionsService.findAndCount({
where: {
- title: Like(`%${queries.query}%`),
+ name: Like(`%${queries.term}%`),
},
skip: queries.offset || 0,
take: queries.limit > 100 ? 25 : queries.limit || 25,
@@ -105,12 +104,17 @@ export class ExtensionsController {
@ApiParam({
name: 'extensionId',
description: 'Extension ID',
- example: '1',
+ example: 'de025965-3221-4d09-ba35-a09da59793a6',
type: String,
})
@Get(':extensionId')
async getExtension(@Param() params: GetExtensionParams): Promise<Extension> {
- const extension = await this.extensionsService.findById(params.extensionId)
+ const extension = await this.extensionsService.findOne({
+ where: {
+ id: params.extensionId,
+ },
+ relations: ['categories'],
+ })
if (!extension) {
throw new NotFoundException('Extension not found.')
@@ -120,24 +124,17 @@ export class ExtensionsController {
}
@Post()
- async addExtension(
- @Body() body: AddExtension,
+ async createExtension(
+ @Body() body: CreateExtension,
): Promise<ISaveExtension & Extension> {
- const title = await this.extensionsService.findTitle(body.title)
-
- if (title) {
- throw new ConflictException('The extension already exists.')
- }
-
const extensionInstance = this.extensionsService.create(body)
-
return await this.extensionsService.save(extensionInstance)
}
@ApiParam({
name: 'extensionId',
description: 'Extension ID',
- example: '1',
+ example: 'de025965-3221-4d09-ba35-a09da59793a6',
type: String,
})
@Patch(':extensionId')
@@ -159,11 +156,11 @@ export class ExtensionsController {
@ApiParam({
name: 'extensionId',
description: 'Extension ID',
- example: '1',
+ example: 'de025965-3221-4d09-ba35-a09da59793a6',
type: String,
})
@Delete(':extensionId')
- async removeExtension(@Param() params: RemoveExtensionParams): Promise<void> {
+ async deleteExtension(@Param() params: DeleteExtensionParams): Promise<void> {
const extension = await this.extensionsService.findById(params.extensionId)
if (!extension) {
diff --git a/src/marketplace/extensions/extensions.service.ts b/src/marketplace/extensions/extensions.service.ts
index 850e2e57b..7c0a2c397 100644
--- a/src/marketplace/extensions/extensions.service.ts
+++ b/src/marketplace/extensions/extensions.service.ts
@@ -17,10 +17,6 @@ export class ExtensionsService {
return await this.extensionRepository.findOne({ ...options })
}
- async findTitle(title: string): Promise<Extension> {
- return await this.findOne({ where: { title }, select: ['title'] })
- }
-
create(extension: ICreateExtension): Extension {
return this.extensionRepository.create(extension)
}
@@ -29,15 +25,15 @@ export class ExtensionsService {
return await this.extensionRepository.save(extension)
}
- async findById(id: number): Promise<Extension> {
+ async findById(id: string): Promise<Extension> {
return await this.findOne({ where: { id } })
}
- async update(id: number, extension: IUpdateExtension) {
+ async update(id: string, extension: IUpdateExtension) {
await this.extensionRepository.update({ id }, extension)
}
- async delete(id: number): Promise<void> {
+ async delete(id: string): Promise<void> {
await this.extensionRepository.delete({ id })
}
diff --git a/src/marketplace/extensions/interfaces/create-extension.interface.ts b/src/marketplace/extensions/interfaces/create-extension.interface.ts
index 92355fc39..9c8280d40 100644
--- a/src/marketplace/extensions/interfaces/create-extension.interface.ts
+++ b/src/marketplace/extensions/interfaces/create-extension.interface.ts
@@ -1,5 +1,5 @@
export interface ICreateExtension {
- title: string
+ name: string
description?: string | null
version: string
}
diff --git a/src/marketplace/extensions/interfaces/save-extension.interface.ts b/src/marketplace/extensions/interfaces/save-extension.interface.ts
index 3bf1ad2b7..1f154f9ef 100644
--- a/src/marketplace/extensions/interfaces/save-extension.interface.ts
+++ b/src/marketplace/extensions/interfaces/save-extension.interface.ts
@@ -1,5 +1,5 @@
export interface ISaveExtension {
- title: string
+ name: string
description?: string | null
version: string
}
diff --git a/src/marketplace/extensions/interfaces/update-extension.interface.ts b/src/marketplace/extensions/interfaces/update-extension.interface.ts
index d2a590be1..7c2161b2a 100644
--- a/src/marketplace/extensions/interfaces/update-extension.interface.ts
+++ b/src/marketplace/extensions/interfaces/update-extension.interface.ts
@@ -1,5 +1,5 @@
export interface IUpdateExtension {
- title?: string
+ name?: string
description?: string | null
version?: string
}