diff --git a/apps/backend/fly.toml b/apps/backend/fly.toml index 847a962..85eff32 100644 --- a/apps/backend/fly.toml +++ b/apps/backend/fly.toml @@ -29,3 +29,8 @@ primary_region = "waw" cpu_kind = "shared" cpus = 1 memory_mb = 512 + +[services.concurrency] + hard_limit = 200 + soft_limit = 200 + type = "connections" diff --git a/apps/backend/src/core/application.ts b/apps/backend/src/core/application.ts index 51110fd..52a9962 100644 --- a/apps/backend/src/core/application.ts +++ b/apps/backend/src/core/application.ts @@ -35,12 +35,12 @@ export class Application { await databaseManager.bootstrapDatabase(container); } - loggerService.info({ + loggerService.debug({ message: 'Migrations run success.', source: Application.name, }); } catch (error) { - loggerService.info({ + loggerService.error({ message: 'Migrations run error.', source: Application.name, }); @@ -69,7 +69,7 @@ export class Application { const userExists = await sqliteDatabaseClient(userTable.name).where({ email }).first(); if (userExists) { - loggerService.info({ + loggerService.debug({ message: 'Admin user already exists.', email, source: Application.name, @@ -91,7 +91,7 @@ export class Application { role: UserRole.admin, }); - loggerService.info({ + loggerService.debug({ message: 'Admin user created.', email, source: Application.name, @@ -139,8 +139,6 @@ export class Application { public static async start(): Promise { const container = Application.createContainer(); - const loggerService = container.get(coreSymbols.loggerService); - await this.setupDatabase(container); await this.createAdminUser(container); @@ -148,10 +146,5 @@ export class Application { const server = new HttpServer(container); await server.start(); - - loggerService.log({ - message: `Application started.`, - source: Application.name, - }); } } diff --git a/apps/backend/src/libs/httpService/clients/httpClient/httpClient.ts b/apps/backend/src/libs/httpService/clients/httpClient/httpClient.ts deleted file mode 100644 index c2a991f..0000000 --- a/apps/backend/src/libs/httpService/clients/httpClient/httpClient.ts +++ /dev/null @@ -1,12 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ - -import { type Response } from 'node-fetch'; - -export interface FetchPayload { - readonly url: string; - readonly init?: any; -} - -export interface HttpClient { - fetch(payload: FetchPayload): Promise; -} diff --git a/apps/backend/src/libs/httpService/clients/httpClient/httpClientImpl.ts b/apps/backend/src/libs/httpService/clients/httpClient/httpClientImpl.ts deleted file mode 100644 index 609c8a9..0000000 --- a/apps/backend/src/libs/httpService/clients/httpClient/httpClientImpl.ts +++ /dev/null @@ -1,11 +0,0 @@ -import fetch, { type Response } from 'node-fetch'; - -import { type HttpClient, type FetchPayload } from './httpClient.js'; - -export class HttpClientImpl implements HttpClient { - public async fetch(payload: FetchPayload): Promise { - const { url, init } = payload; - - return fetch(url, init); - } -} diff --git a/apps/backend/src/libs/httpService/errors/httpServiceError.ts b/apps/backend/src/libs/httpService/errors/httpServiceError.ts deleted file mode 100644 index eb4e88a..0000000 --- a/apps/backend/src/libs/httpService/errors/httpServiceError.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { ApplicationError } from '../../../common/errors/base/applicationError.js'; - -interface Context { - readonly name?: string; - readonly message: string; -} - -export class HttpServiceError extends ApplicationError { - public constructor(context: Context) { - super('HttpServiceError', 'Http service error.', context); - } -} diff --git a/apps/backend/src/libs/httpService/factories/httpClientFactory/httpClientFactory.ts b/apps/backend/src/libs/httpService/factories/httpClientFactory/httpClientFactory.ts deleted file mode 100644 index a27ce7e..0000000 --- a/apps/backend/src/libs/httpService/factories/httpClientFactory/httpClientFactory.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { type HttpClient } from '../../clients/httpClient/httpClient.js'; -import { HttpClientImpl } from '../../clients/httpClient/httpClientImpl.js'; - -export class HttpClientFactory { - public static create(): HttpClient { - return new HttpClientImpl(); - } -} diff --git a/apps/backend/src/libs/httpService/factories/httpServiceFactory/httpServiceFactory.ts b/apps/backend/src/libs/httpService/factories/httpServiceFactory/httpServiceFactory.ts deleted file mode 100644 index ee583d5..0000000 --- a/apps/backend/src/libs/httpService/factories/httpServiceFactory/httpServiceFactory.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { type LoggerService } from '../../../logger/services/loggerService/loggerService.js'; -import { type HttpService } from '../../services/httpService/httpService.js'; -import { HttpServiceImpl } from '../../services/httpService/httpServiceImpl.js'; -import { HttpClientFactory } from '../httpClientFactory/httpClientFactory.js'; - -export class HttpServiceFactory { - public constructor(private readonly loggerService: LoggerService) {} - - public create(): HttpService { - const httpClient = HttpClientFactory.create(); - - return new HttpServiceImpl(httpClient, this.loggerService); - } -} diff --git a/apps/backend/src/libs/httpService/services/httpService/httpService.ts b/apps/backend/src/libs/httpService/services/httpService/httpService.ts deleted file mode 100644 index 2baf614..0000000 --- a/apps/backend/src/libs/httpService/services/httpService/httpService.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ - -import { type HttpMethodName } from '../../../../common/types/http/httpMethodName.js'; -import { type HttpStatusCode } from '../../../../common/types/http/httpStatusCode.js'; - -export interface SendRequestPayload { - readonly method: HttpMethodName; - readonly url: string; - readonly headers?: Record; - readonly queryParams?: Record; - readonly body?: any; -} - -export interface HttpResponse { - readonly statusCode: HttpStatusCode; - readonly body: ReponseBody; -} - -export interface HttpService { - sendRequest(payload: SendRequestPayload): Promise>; -} diff --git a/apps/backend/src/libs/httpService/services/httpService/httpServiceImpl.ts b/apps/backend/src/libs/httpService/services/httpService/httpServiceImpl.ts deleted file mode 100644 index fbaf069..0000000 --- a/apps/backend/src/libs/httpService/services/httpService/httpServiceImpl.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { stringify } from 'querystring'; - -import { type HttpResponse, type HttpService, type SendRequestPayload } from './httpService.js'; -import { type LoggerService } from '../../../logger/services/loggerService/loggerService.js'; -import { type HttpClient } from '../../clients/httpClient/httpClient.js'; -import { HttpServiceError } from '../../errors/httpServiceError.js'; - -export class HttpServiceImpl implements HttpService { - public constructor( - private readonly httpClient: HttpClient, - private readonly loggerService: LoggerService, - ) {} - - public async sendRequest(payload: SendRequestPayload): Promise> { - const { method, url: initialUrl, headers, queryParams, body: requestBody } = payload; - - const body = JSON.stringify(requestBody); - - let url = initialUrl; - - if (queryParams && Object.keys(queryParams).length) { - url += `?${stringify(queryParams)}`; - } - - this.loggerService.debug({ - message: 'Sending http request...', - url, - method, - headers, - }); - - try { - const response = await this.httpClient.fetch({ - url, - init: { - method, - headers: headers as never, - body, - }, - }); - - const responseBodyText = await response.text(); - - const responseBody = !responseBodyText.length ? {} : JSON.parse(responseBodyText); - - this.loggerService.debug({ - message: 'Http request sent.', - response: { - statusCode: response.status, - body: response.status >= 200 && response.status < 300 ? 'hidden' : responseBody, - }, - }); - - return { - body: responseBody as ResponseBody, - statusCode: response.status, - }; - } catch (error) { - const { name, message } = - error instanceof Error - ? error - : { - name: '', - message: JSON.stringify(error), - }; - - this.loggerService.error({ - message: 'Http request error.', - error: { - name, - message, - }, - }); - - throw new HttpServiceError({ - name, - message, - }); - } - } -} diff --git a/apps/backend/src/modules/resourceModule/application/commandHandlers/deleteResourceCommandHandler/deleteResourceCommandHandlerImpl.ts b/apps/backend/src/modules/resourceModule/application/commandHandlers/deleteResourceCommandHandler/deleteResourceCommandHandlerImpl.ts index cdae000..79c7e41 100644 --- a/apps/backend/src/modules/resourceModule/application/commandHandlers/deleteResourceCommandHandler/deleteResourceCommandHandlerImpl.ts +++ b/apps/backend/src/modules/resourceModule/application/commandHandlers/deleteResourceCommandHandler/deleteResourceCommandHandlerImpl.ts @@ -52,7 +52,7 @@ export class DeleteResourceCommandHandlerImpl implements DeleteResourceCommandHa resourceName, }); - this.loggerService.info({ + this.loggerService.debug({ message: 'Resource deleted.', userId, bucketName, diff --git a/apps/backend/src/modules/resourceModule/application/queryHandlers/downloadImageQueryHandler/downloadImageQueryHandlerImpl.ts b/apps/backend/src/modules/resourceModule/application/queryHandlers/downloadImageQueryHandler/downloadImageQueryHandlerImpl.ts index 1063d71..11245b5 100644 --- a/apps/backend/src/modules/resourceModule/application/queryHandlers/downloadImageQueryHandler/downloadImageQueryHandlerImpl.ts +++ b/apps/backend/src/modules/resourceModule/application/queryHandlers/downloadImageQueryHandler/downloadImageQueryHandlerImpl.ts @@ -63,7 +63,7 @@ export class DownloadImageQueryHandlerImpl implements DownloadImageQueryHandler const resizedImageData = resource.data.pipe(resizing); - this.loggerService.info({ + this.loggerService.debug({ message: 'Image Resource downloaded.', userId, bucketName, diff --git a/apps/backend/src/modules/resourceModule/application/queryHandlers/downloadResourceQueryHandler/downloadResourceQueryHandlerImpl.ts b/apps/backend/src/modules/resourceModule/application/queryHandlers/downloadResourceQueryHandler/downloadResourceQueryHandlerImpl.ts index bda5d1c..19e4fc2 100644 --- a/apps/backend/src/modules/resourceModule/application/queryHandlers/downloadResourceQueryHandler/downloadResourceQueryHandlerImpl.ts +++ b/apps/backend/src/modules/resourceModule/application/queryHandlers/downloadResourceQueryHandler/downloadResourceQueryHandlerImpl.ts @@ -40,7 +40,7 @@ export class DownloadResourceQueryHandlerImpl implements DownloadResourceQueryHa resourceName, }); - this.loggerService.info({ + this.loggerService.debug({ message: 'Resource downloaded.', userId, bucketName, diff --git a/apps/backend/src/modules/resourceModule/application/queryHandlers/downloadResourcesQueryHandler/downloadResourcesQueryHandlerImpl.ts b/apps/backend/src/modules/resourceModule/application/queryHandlers/downloadResourcesQueryHandler/downloadResourcesQueryHandlerImpl.ts index 21d117a..05f24d6 100644 --- a/apps/backend/src/modules/resourceModule/application/queryHandlers/downloadResourcesQueryHandler/downloadResourcesQueryHandlerImpl.ts +++ b/apps/backend/src/modules/resourceModule/application/queryHandlers/downloadResourcesQueryHandler/downloadResourcesQueryHandlerImpl.ts @@ -80,7 +80,7 @@ export class DownloadResourcesQueryHandlerImpl implements DownloadResourcesQuery archive.finalize(); - this.loggerService.info({ + this.loggerService.debug({ message: 'Resources downloaded.', userId, bucketName, diff --git a/apps/backend/src/modules/resourceModule/application/queryHandlers/findResourcesMetadataQueryHandler/findResourcesMetadataQueryHandlerImpl.ts b/apps/backend/src/modules/resourceModule/application/queryHandlers/findResourcesMetadataQueryHandler/findResourcesMetadataQueryHandlerImpl.ts index 74cfdff..ecdda74 100644 --- a/apps/backend/src/modules/resourceModule/application/queryHandlers/findResourcesMetadataQueryHandler/findResourcesMetadataQueryHandlerImpl.ts +++ b/apps/backend/src/modules/resourceModule/application/queryHandlers/findResourcesMetadataQueryHandler/findResourcesMetadataQueryHandlerImpl.ts @@ -44,7 +44,7 @@ export class FindResourcesMetadataQueryHandlerImpl implements FindResourcesMetad pageSize, }); - this.loggerService.info({ + this.loggerService.debug({ message: 'Resources fetched.', userId, bucketName, diff --git a/apps/backend/src/modules/userModule/application/commandHandlers/createUserCommandHandler/createUserCommandHandlerImpl.ts b/apps/backend/src/modules/userModule/application/commandHandlers/createUserCommandHandler/createUserCommandHandlerImpl.ts index f3ad5a8..2b168cc 100644 --- a/apps/backend/src/modules/userModule/application/commandHandlers/createUserCommandHandler/createUserCommandHandlerImpl.ts +++ b/apps/backend/src/modules/userModule/application/commandHandlers/createUserCommandHandler/createUserCommandHandlerImpl.ts @@ -48,7 +48,7 @@ export class CrateUserCommandHandlerImpl implements CreateUserCommandHandler { role: UserRole.user, }); - this.loggerService.info({ + this.loggerService.debug({ message: 'User created.', userId: user.getId(), email, diff --git a/apps/backend/src/modules/userModule/application/commandHandlers/deleteUserCommandHandler/deleteUserCommandHandlerImpl.ts b/apps/backend/src/modules/userModule/application/commandHandlers/deleteUserCommandHandler/deleteUserCommandHandlerImpl.ts index fea38a7..5be9615 100644 --- a/apps/backend/src/modules/userModule/application/commandHandlers/deleteUserCommandHandler/deleteUserCommandHandlerImpl.ts +++ b/apps/backend/src/modules/userModule/application/commandHandlers/deleteUserCommandHandler/deleteUserCommandHandlerImpl.ts @@ -18,7 +18,7 @@ export class DeleteUserCommandHandlerImpl implements DeleteUserCommandHandler { await this.userRepository.deleteUser({ id: userId }); - this.loggerService.info({ + this.loggerService.debug({ message: 'User deleted.', userId, }); diff --git a/apps/backend/src/modules/userModule/application/commandHandlers/grantBucketAccessCommandHandler/grantBucketAccessCommandHandlerImpl.ts b/apps/backend/src/modules/userModule/application/commandHandlers/grantBucketAccessCommandHandler/grantBucketAccessCommandHandlerImpl.ts index 086499e..dc078a2 100644 --- a/apps/backend/src/modules/userModule/application/commandHandlers/grantBucketAccessCommandHandler/grantBucketAccessCommandHandlerImpl.ts +++ b/apps/backend/src/modules/userModule/application/commandHandlers/grantBucketAccessCommandHandler/grantBucketAccessCommandHandlerImpl.ts @@ -33,7 +33,7 @@ export class GrantBucketAccessCommandHandlerImpl implements GrantBucketAccessCom const existingBuckets = await this.userRepository.findUserBuckets({ userId }); if (existingBuckets.find((userBucket) => userBucket.getBucketName() === bucketName)) { - this.loggerService.info({ + this.loggerService.debug({ message: 'Bucket access already granted.', userId, bucketName, @@ -51,7 +51,7 @@ export class GrantBucketAccessCommandHandlerImpl implements GrantBucketAccessCom domainActions: existingUser.getDomainActions(), }); - this.loggerService.info({ + this.loggerService.debug({ message: 'Bucket access granted.', userId, bucketName, diff --git a/apps/backend/src/modules/userModule/application/commandHandlers/loginUserCommandHandler/loginUserCommandHandlerImpl.ts b/apps/backend/src/modules/userModule/application/commandHandlers/loginUserCommandHandler/loginUserCommandHandlerImpl.ts index aa30655..400693e 100644 --- a/apps/backend/src/modules/userModule/application/commandHandlers/loginUserCommandHandler/loginUserCommandHandlerImpl.ts +++ b/apps/backend/src/modules/userModule/application/commandHandlers/loginUserCommandHandler/loginUserCommandHandlerImpl.ts @@ -82,7 +82,7 @@ export class LoginUserCommandHandlerImpl implements LoginUserCommandHandler { domainActions: user.getDomainActions(), }); - this.loggerService.info({ + this.loggerService.debug({ message: 'User logged in.', email, userId: user.getId(), diff --git a/apps/backend/src/modules/userModule/application/commandHandlers/refreshUserTokensCommandHandler/refreshUserTokensCommandHandlerImpl.ts b/apps/backend/src/modules/userModule/application/commandHandlers/refreshUserTokensCommandHandler/refreshUserTokensCommandHandlerImpl.ts index f13c8cb..e14f025 100644 --- a/apps/backend/src/modules/userModule/application/commandHandlers/refreshUserTokensCommandHandler/refreshUserTokensCommandHandlerImpl.ts +++ b/apps/backend/src/modules/userModule/application/commandHandlers/refreshUserTokensCommandHandler/refreshUserTokensCommandHandlerImpl.ts @@ -81,7 +81,7 @@ export class RefreshUserTokensCommandHandlerImpl implements RefreshUserTokensCom expiresIn: accessTokenExpiresIn, }); - this.loggerService.info({ + this.loggerService.debug({ message: 'User tokens refreshed.', userId, }); diff --git a/apps/backend/src/modules/userModule/application/commandHandlers/revokeBucketAccessCommandHandler/revokeBucketAccessCommandHandlerImpl.ts b/apps/backend/src/modules/userModule/application/commandHandlers/revokeBucketAccessCommandHandler/revokeBucketAccessCommandHandlerImpl.ts index 3366d14..7e84896 100644 --- a/apps/backend/src/modules/userModule/application/commandHandlers/revokeBucketAccessCommandHandler/revokeBucketAccessCommandHandlerImpl.ts +++ b/apps/backend/src/modules/userModule/application/commandHandlers/revokeBucketAccessCommandHandler/revokeBucketAccessCommandHandlerImpl.ts @@ -33,7 +33,7 @@ export class RevokeBucketAccessCommandHandlerImpl implements RevokeBucketAccessC const existingBuckets = await this.userRepository.findUserBuckets({ userId }); if (!existingBuckets.find((userBucket) => userBucket.getBucketName() === bucketName)) { - this.loggerService.info({ + this.loggerService.debug({ message: 'User does not have access to the bucket.', userId, bucketName, @@ -51,7 +51,7 @@ export class RevokeBucketAccessCommandHandlerImpl implements RevokeBucketAccessC domainActions: existingUser.getDomainActions(), }); - this.loggerService.info({ + this.loggerService.debug({ message: 'Bucket access revoked.', userId, bucketName,