From 7b342d3f2a444eaa3c9e7ca5b74749aaf4929a16 Mon Sep 17 00:00:00 2001 From: ZigBalthazar Date: Sat, 21 Dec 2024 00:34:46 +0330 Subject: [PATCH] fix: some issues --- .env.example | 4 +- .../jwt-strategy-validate.interface.ts | 1 - src/modules/auth/strategies/jwt.strategy.ts | 2 +- src/modules/config/config.service.ts | 14 +++-- .../config/controllers/config.controller.ts | 9 +++- src/modules/config/dto/limitation.dto.ts | 28 +++++----- src/modules/config/dto/nip11.dto.ts | 53 ++++++++++--------- .../config/entities/limitaion.entity.ts | 28 +++++----- src/modules/config/entities/nip11.entity.ts | 52 +++++++++--------- src/modules/grpc/immortal-grpc.client.ts | 29 +++++----- src/modules/health/health.controller.ts | 6 +-- src/modules/health/health.module.ts | 1 + .../service-registry.controller.ts | 7 ++- .../service-registry.module.ts | 3 +- .../service-registry-health-check.service.ts | 5 +- .../services/service-registry.service.ts | 7 +-- .../subscriptions/subscriptions.controller.ts | 7 ++- src/shared/services/api-config.service.ts | 3 +- yarn.lock | 9 +--- 19 files changed, 145 insertions(+), 123 deletions(-) diff --git a/.env.example b/.env.example index feb9bb6..14484b6 100644 --- a/.env.example +++ b/.env.example @@ -8,8 +8,10 @@ ENABLE_DOCUMENTATION=true #== MONGO -MONGO_URI="mongodb://..." +MONGO_DB_URL="mongodb://..." MONGO_DB_NAME=IMMORTAL +MONGO_DB_USERNAME=IMMORTAL +MONGO_DB_PASSWORD=IMMORTAL MONGO_DB_CONNECTION_TIMEOUT_IN_MS=500 #== JWT diff --git a/src/modules/auth/interfaces/jwt-strategy-validate.interface.ts b/src/modules/auth/interfaces/jwt-strategy-validate.interface.ts index f3365c4..9545937 100644 --- a/src/modules/auth/interfaces/jwt-strategy-validate.interface.ts +++ b/src/modules/auth/interfaces/jwt-strategy-validate.interface.ts @@ -1,4 +1,3 @@ export interface IJwtStrategyValidate { - id: string; email: string; } diff --git a/src/modules/auth/strategies/jwt.strategy.ts b/src/modules/auth/strategies/jwt.strategy.ts index 865593a..896f753 100644 --- a/src/modules/auth/strategies/jwt.strategy.ts +++ b/src/modules/auth/strategies/jwt.strategy.ts @@ -17,8 +17,8 @@ export default class JwtStrategy extends PassportStrategy(Strategy) { } validate(payload: UserEntity): IJwtStrategyValidate { + console.log(payload) return { - id: payload._id.toString(), email: payload.email, }; } diff --git a/src/modules/config/config.service.ts b/src/modules/config/config.service.ts index eb1b7a3..f42b325 100644 --- a/src/modules/config/config.service.ts +++ b/src/modules/config/config.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@nestjs/common'; +import { Injectable, NotFoundException } from '@nestjs/common'; import { Nip11Repository } from './repositories/nip11.repository'; import type { UpdateNip11Dto } from './dto/update-config.dto'; @@ -6,14 +6,18 @@ import { EventEmitter } from 'node:stream'; @Injectable() export class ConfigService extends EventEmitter { - constructor( - private readonly nip11Repo: Nip11Repository, - ) { + constructor(private readonly nip11Repo: Nip11Repository) { super(); } async getNip11() { - return this.nip11Repo.findOne(); + const entity = await this.nip11Repo.findOne(); + + if (!entity) { + throw new NotFoundException('NIP-11 not found.'); + } + + return entity; } async updateNip11(props: UpdateNip11Dto) { diff --git a/src/modules/config/controllers/config.controller.ts b/src/modules/config/controllers/config.controller.ts index 565b422..0646163 100644 --- a/src/modules/config/controllers/config.controller.ts +++ b/src/modules/config/controllers/config.controller.ts @@ -1,19 +1,24 @@ -import { Body, Controller, Get, Patch } from '@nestjs/common'; -import { ApiTags } from '@nestjs/swagger'; +import { Body, Controller, Get, Patch, UseGuards } from '@nestjs/common'; +import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; import { ConfigService } from '../config.service'; import { UpdateNip11Dto } from '../dto/update-config.dto'; +import JwtAuthGuard from '../../../../src/modules/auth/guards/jwt-auth.guard'; @Controller('config') @ApiTags('config') export class ServiceConfigController { constructor(private readonly configService: ConfigService) {} + @UseGuards(JwtAuthGuard) + @ApiBearerAuth() @Patch() async update(@Body() props: UpdateNip11Dto) { return this.configService.updateNip11(props); } + @UseGuards(JwtAuthGuard) + @ApiBearerAuth() @Get() async get() { const config = await this.configService.getNip11(); diff --git a/src/modules/config/dto/limitation.dto.ts b/src/modules/config/dto/limitation.dto.ts index bb633f1..27eef68 100644 --- a/src/modules/config/dto/limitation.dto.ts +++ b/src/modules/config/dto/limitation.dto.ts @@ -6,57 +6,57 @@ import { AbstractDto } from '../../../common/dto/abstract.dto'; export class LimitationDto { @ApiProperty() @IsInt() - maxMessageLength?: number; + max_message_length?: number; @ApiProperty() @IsInt() - maxSubscriptions?: number; + max_subscriptions?: number; @ApiProperty() @IsInt() - maxFilters?: number; + max_filters?: number; @ApiProperty() @IsInt() - maxSubidLength?: number; + max_subid_length?: number; @ApiProperty() @IsInt() - minPowDifficulty?: number; + min_pow_difficulty?: number; @ApiProperty() @IsBoolean() - authRequired?: boolean; + auth_required?: boolean; @ApiProperty() @IsBoolean() - paymentRequired?: boolean; + payment_required?: boolean; @ApiProperty() @IsBoolean() - restrictedWrites?: boolean; + restricted_writes?: boolean; @ApiProperty() @IsInt() - maxEventTags?: number; + max_event_tags?: number; @ApiProperty() @IsInt() - maxContentLength?: number; + max_content_length?: number; @ApiProperty() @IsInt() - createdAtLowerLimit?: number; + created_at_lower_limit?: number; @ApiProperty() @IsInt() - createdAtUpperLimit?: number; + created_at_upper_limit?: number; @ApiProperty() @IsInt() - maxQueryLimit?: number; + max_limit?: number; @ApiProperty() @IsInt() - defaultQueryLimit?: number; + default_query_limit?: number; } diff --git a/src/modules/config/dto/nip11.dto.ts b/src/modules/config/dto/nip11.dto.ts index be26b2f..2a34364 100644 --- a/src/modules/config/dto/nip11.dto.ts +++ b/src/modules/config/dto/nip11.dto.ts @@ -16,6 +16,10 @@ export class Nip11DTO extends AbstractDto { @IsString() description: string; + @ApiProperty() + @IsString() + banner: string; + @ApiProperty() @IsString() pubkey: string; @@ -30,7 +34,7 @@ export class Nip11DTO extends AbstractDto { @ApiProperty({ type: [Number] }) @IsArray() - supportedNips: number[]; + supported_nips: number[]; @ApiProperty() @IsString() @@ -38,11 +42,11 @@ export class Nip11DTO extends AbstractDto { @ApiProperty({ type: [String] }) @IsArray() - relayCountries: string[]; + relay_countries: string[]; @ApiProperty({ type: [String] }) @IsArray() - languageTags: string[]; + language_tags: string[]; @ApiProperty({ type: [String] }) @IsArray() @@ -51,12 +55,12 @@ export class Nip11DTO extends AbstractDto { @ApiProperty({ required: false }) @IsOptional() @IsString() - postingPolicy?: string; + posting_policy?: string; @ApiProperty({ required: false }) @IsOptional() @IsString() - paymentsUrl?: string; + payments_url?: string; @ApiProperty({ required: false }) @IsOptional() @@ -87,14 +91,15 @@ export class Nip11DTO extends AbstractDto { this.description = e.description; this.pubkey = e.pubkey; this.contact = e.contact; + this.banner = e.banner; this.software = e.software; - this.supportedNips = e.supportedNips; + this.supported_nips = e.supported_nips; this.version = e.version; - this.relayCountries = e.relayCountries; - this.languageTags = e.languageTags; + this.relay_countries = e.relay_countries; + this.language_tags = e.language_tags; this.tags = e.tags; - this.postingPolicy = e.postingPolicy; - this.paymentsUrl = e.paymentsUrl; + this.posting_policy = e.posting_policy; + this.payments_url = e.payments_url; this.icon = e.icon; this.url = e.url; this.retention = { @@ -120,20 +125,20 @@ export class Nip11DTO extends AbstractDto { }; this.limitations = { - authRequired: e.limitations?.authRequired, - maxMessageLength: e.limitations?.maxMessageLength, - maxSubidLength: e.limitations?.maxSubidLength, - maxFilters: e.limitations?.maxFilters, - maxSubscriptions: e.limitations?.maxSubscriptions, - minPowDifficulty: e.limitations?.minPowDifficulty, - paymentRequired: e.limitations?.paymentRequired, - restrictedWrites: e.limitations?.restrictedWrites, - maxEventTags: e.limitations?.maxEventTags, - maxContentLength: e.limitations?.maxContentLength, - createdAtLowerLimit: e.limitations?.createdAtLowerLimit, - createdAtUpperLimit: e.limitations?.createdAtUpperLimit, - defaultQueryLimit: e.limitations?.maxQueryLimit, - maxQueryLimit: e.limitations?.maxQueryLimit, + auth_required: e.limitations?.auth_required, + max_message_length: e.limitations?.max_message_length, + max_subid_length: e.limitations?.max_subid_length, + max_filters: e.limitations?.max_filters, + max_subscriptions: e.limitations?.max_subscriptions, + min_pow_difficulty: e.limitations?.min_pow_difficulty, + payment_required: e.limitations?.payment_required, + restricted_writes: e.limitations?.restricted_writes, + max_event_tags: e.limitations?.max_event_tags, + max_content_length: e.limitations?.max_content_length, + created_at_lower_limit: e.limitations?.created_at_lower_limit, + created_at_upper_limit: e.limitations?.created_at_upper_limit, + default_query_limit: e.limitations?.max_limit, + max_limit: e.limitations?.max_limit, }; } } diff --git a/src/modules/config/entities/limitaion.entity.ts b/src/modules/config/entities/limitaion.entity.ts index 8a42ddd..b504566 100644 --- a/src/modules/config/entities/limitaion.entity.ts +++ b/src/modules/config/entities/limitaion.entity.ts @@ -2,44 +2,44 @@ import { Column } from 'typeorm'; export class LimitationEntity { @Column({ type: 'int' }) - maxMessageLength?: number; + max_message_length?: number; @Column({ type: 'int' }) - maxSubscriptions?: number; + max_subscriptions?: number; @Column({ type: 'int' }) - maxFilters?: number; + max_filters?: number; @Column({ type: 'int' }) - maxSubidLength?: number; + max_subid_length?: number; @Column({ type: 'int' }) - minPowDifficulty?: number; + min_pow_difficulty?: number; @Column({ type: 'boolean' }) - authRequired?: boolean; + auth_required?: boolean; @Column({ type: 'boolean' }) - paymentRequired?: boolean; + payment_required?: boolean; @Column({ type: 'boolean' }) - restrictedWrites?: boolean; + restricted_writes?: boolean; @Column({ type: 'int' }) - maxEventTags?: number; + max_event_tags?: number; @Column({ type: 'int' }) - maxContentLength?: number; + max_content_length?: number; @Column({ type: 'bigint' }) - createdAtLowerLimit?: number; + created_at_lower_limit?: number; @Column({ type: 'bigint' }) - createdAtUpperLimit?: number; + created_at_upper_limit?: number; @Column({ type: 'int' }) - maxQueryLimit?: number; + max_limit?: number; @Column({ type: 'int' }) - defaultQueryLimit?: number; + default_query_limit?: number; } diff --git a/src/modules/config/entities/nip11.entity.ts b/src/modules/config/entities/nip11.entity.ts index 42aa950..470803d 100644 --- a/src/modules/config/entities/nip11.entity.ts +++ b/src/modules/config/entities/nip11.entity.ts @@ -19,6 +19,9 @@ export class Nip11Entity extends AbstractEntity { @Column({ type: 'varchar' }) pubkey: string; + @Column({ type: 'varchar' }) + banner: string; + @Column({ type: 'varchar' }) contact: string; @@ -26,25 +29,25 @@ export class Nip11Entity extends AbstractEntity { software: string; @Column('simple-array') - supportedNips: number[]; + supported_nips: number[]; @Column({ type: 'varchar' }) version: string; @Column('simple-array') - relayCountries: string[]; + relay_countries: string[]; @Column('simple-array') - languageTags: string[]; + language_tags: string[]; @Column('simple-array') tags: string[]; @Column({ type: 'varchar', nullable: true }) - postingPolicy: string; + posting_policy: string; @Column({ type: 'varchar', nullable: true }) - paymentsUrl: string; + payments_url: string; @Column({ type: 'varchar', nullable: true }) icon: string; @@ -78,15 +81,16 @@ export class Nip11Entity extends AbstractEntity { this.name = item.name ?? this.name; this.description = item.description ?? this.description; this.pubkey = item.pubkey ?? this.pubkey; + this.banner = item.banner ?? this.banner; this.contact = item.contact ?? this.contact; this.software = item.software ?? this.software; - this.supportedNips = item.supportedNips ?? this.supportedNips; + this.supported_nips = item.supported_nips ?? this.supported_nips; this.version = item.version ?? this.version; - this.relayCountries = item.relayCountries ?? this.relayCountries; - this.languageTags = item.languageTags ?? this.languageTags; + this.relay_countries = item.relay_countries ?? this.relay_countries; + this.language_tags = item.language_tags ?? this.language_tags; this.tags = item.tags ?? this.tags; - this.postingPolicy = item.postingPolicy ?? this.postingPolicy; - this.paymentsUrl = item.paymentsUrl ?? this.paymentsUrl; + this.posting_policy = item.posting_policy ?? this.posting_policy; + this.payments_url = item.payments_url ?? this.payments_url; this.icon = item.icon ?? this.icon; this.url = item.url ?? this.url; @@ -112,20 +116,20 @@ export class Nip11Entity extends AbstractEntity { this.limitations = { ...this.limitations, ...(item.limitations ?? {}), - maxMessageLength: item.limitations?.maxMessageLength ?? this.limitations?.maxMessageLength, - maxSubscriptions: item.limitations?.maxSubscriptions ?? this.limitations?.maxSubscriptions, - maxFilters: item.limitations?.maxFilters ?? this.limitations?.maxFilters, - maxSubidLength: item.limitations?.maxSubidLength ?? this.limitations?.maxSubidLength, - minPowDifficulty: item.limitations?.minPowDifficulty ?? this.limitations?.minPowDifficulty, - authRequired: item.limitations?.authRequired ?? this.limitations?.authRequired, - paymentRequired: item.limitations?.paymentRequired ?? this.limitations?.paymentRequired, - restrictedWrites: item.limitations?.restrictedWrites ?? this.limitations?.restrictedWrites, - maxEventTags: item.limitations?.maxEventTags ?? this.limitations?.maxEventTags, - maxContentLength: item.limitations?.maxContentLength ?? this.limitations?.maxContentLength, - createdAtLowerLimit: item.limitations?.createdAtLowerLimit ?? this.limitations?.createdAtLowerLimit, - createdAtUpperLimit: item.limitations?.createdAtUpperLimit ?? this.limitations?.createdAtUpperLimit, - maxQueryLimit: item.limitations?.maxQueryLimit ?? this.limitations?.maxQueryLimit, - defaultQueryLimit: item.limitations?.defaultQueryLimit ?? this.limitations?.defaultQueryLimit, + max_message_length: item.limitations?.max_message_length ?? this.limitations?.max_message_length, + max_subscriptions: item.limitations?.max_subscriptions ?? this.limitations?.max_subscriptions, + max_filters: item.limitations?.max_filters ?? this.limitations?.max_filters, + max_subid_length: item.limitations?.max_subid_length ?? this.limitations?.max_subid_length, + min_pow_difficulty: item.limitations?.min_pow_difficulty ?? this.limitations?.min_pow_difficulty, + auth_required: item.limitations?.auth_required ?? this.limitations?.auth_required, + payment_required: item.limitations?.payment_required ?? this.limitations?.payment_required, + restricted_writes: item.limitations?.restricted_writes ?? this.limitations?.restricted_writes, + max_event_tags: item.limitations?.max_event_tags ?? this.limitations?.max_event_tags, + max_content_length: item.limitations?.max_content_length ?? this.limitations?.max_content_length, + created_at_lower_limit: item.limitations?.created_at_lower_limit ?? this.limitations?.created_at_lower_limit, + created_at_upper_limit: item.limitations?.created_at_upper_limit ?? this.limitations?.created_at_upper_limit, + max_limit: item.limitations?.max_limit ?? this.limitations?.max_limit, + default_query_limit: item.limitations?.default_query_limit ?? this.limitations?.default_query_limit, }; } diff --git a/src/modules/grpc/immortal-grpc.client.ts b/src/modules/grpc/immortal-grpc.client.ts index 98a2002..140b0e5 100644 --- a/src/modules/grpc/immortal-grpc.client.ts +++ b/src/modules/grpc/immortal-grpc.client.ts @@ -1,27 +1,31 @@ import path from 'node:path'; - import { ChannelCredentials } from '@grpc/grpc-js'; -import type { OnModuleInit } from '@nestjs/common'; -import type { ClientGrpc, ClientOptions } from '@nestjs/microservices'; -import { Client, Transport } from '@nestjs/microservices'; +import { Injectable, OnModuleInit } from '@nestjs/common'; +import { ClientGrpc, ClientOptions, ClientProxyFactory, Transport } from '@nestjs/microservices'; import type { HealthServiceClient } from './gen/ts/immortal-health-service'; import { HEALTH_SERVICE_NAME, IMMORTAL_PACKAGE_NAME } from './gen/ts/immortal-health-service'; +@Injectable() export class ImmortalGrpcClient implements OnModuleInit { static instance: ImmortalGrpcClient; private clientGrpc: ClientGrpc; - public serviceClient: HealthServiceClient; - constructor( - private readonly url: string, - private readonly isSecure: boolean, - ) { + private isSecure = false; + private url = ''; + + constructor() { ImmortalGrpcClient.instance = this; + this.initializeClient(); + } + + setUrl(url: string, isSecure = false): void { + if (this.url !== url) { + this.url = url; + this.isSecure = isSecure; - if (this.url) { this.initializeClient(); } } @@ -37,10 +41,11 @@ export class ImmortalGrpcClient implements OnModuleInit { }, }; - Client(clientOptions)(this, 'clientGrpc'); + this.clientGrpc = ClientProxyFactory.create(clientOptions) as unknown as ClientGrpc; + this.serviceClient = this.clientGrpc.getService(HEALTH_SERVICE_NAME); } - onModuleInit() { + onModuleInit(): void { this.serviceClient = this.clientGrpc.getService(HEALTH_SERVICE_NAME); } } diff --git a/src/modules/health/health.controller.ts b/src/modules/health/health.controller.ts index 7326dc8..0f11754 100644 --- a/src/modules/health/health.controller.ts +++ b/src/modules/health/health.controller.ts @@ -1,6 +1,6 @@ import { Controller, Get, UseGuards } from '@nestjs/common'; import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; -import { HealthCheck, HealthCheckService, MongooseHealthIndicator } from '@nestjs/terminus'; +import { HealthCheck, HealthCheckService, TypeOrmHealthIndicator, } from '@nestjs/terminus'; import JwtAuthGuard from '../auth/guards/jwt-auth.guard'; @@ -11,7 +11,7 @@ export default class HealthController { constructor( private health: HealthCheckService, - private mongoose: MongooseHealthIndicator, + private typeOrm: TypeOrmHealthIndicator, ) {} @Get() @@ -20,7 +20,7 @@ export default class HealthController { @HealthCheck() async check() { return { - health: await this.health.check([async () => this.mongoose.pingCheck('mongoose')]), + health: await this.health.check([async () => this.typeOrm.pingCheck('TypeOrm',{timeout:2000})]), uptime: this.getFormattedUptime(), }; } diff --git a/src/modules/health/health.module.ts b/src/modules/health/health.module.ts index bfc9507..5730c49 100644 --- a/src/modules/health/health.module.ts +++ b/src/modules/health/health.module.ts @@ -2,6 +2,7 @@ import { Module } from '@nestjs/common'; import { TerminusModule } from '@nestjs/terminus'; import HealthController from './health.controller'; +import { ImmortalGrpcClient } from '../grpc/immortal-grpc.client'; @Module({ imports: [TerminusModule], diff --git a/src/modules/service-registry/controllers/service-registry.controller.ts b/src/modules/service-registry/controllers/service-registry.controller.ts index a8ea6eb..6b56426 100644 --- a/src/modules/service-registry/controllers/service-registry.controller.ts +++ b/src/modules/service-registry/controllers/service-registry.controller.ts @@ -1,14 +1,17 @@ -import { Controller, Get } from '@nestjs/common'; -import { ApiTags } from '@nestjs/swagger'; +import { Controller, Get, UseGuards } from '@nestjs/common'; +import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; import type RegisterServiceRegistryDto from '../dtos/service-registry-register.dto'; import ServiceRegistryService from '../services/service-registry.service'; +import JwtAuthGuard from 'src/modules/auth/guards/jwt-auth.guard'; @Controller('service-registry') @ApiTags('service-registry') export default class ServiceRegistryController { constructor(private readonly serviceRegistryService: ServiceRegistryService) {} + @UseGuards(JwtAuthGuard) + @ApiBearerAuth() @Get() async getServices() { const services = await this.serviceRegistryService.findAll(); diff --git a/src/modules/service-registry/service-registry.module.ts b/src/modules/service-registry/service-registry.module.ts index ab20f95..9e2e53d 100644 --- a/src/modules/service-registry/service-registry.module.ts +++ b/src/modules/service-registry/service-registry.module.ts @@ -7,11 +7,12 @@ import { ServiceRegistryEntity } from './entities/service-registry.entity'; import { ServiceRegistryRepository } from './service-registry.repository'; import ServiceRegistryService from './services/service-registry.service'; import ServiceRegistryHealthCheckService from './services/service-registry-health-check.service'; +import { ImmortalGrpcClient } from '../grpc/immortal-grpc.client'; @Module({ imports: [TypeOrmModule.forFeature([ServiceRegistryEntity])], controllers: [ServiceRegistryController, ServiceRegistryGrpcController], - providers: [ServiceRegistryService, ServiceRegistryRepository, ServiceRegistryHealthCheckService], + providers: [ServiceRegistryService, ServiceRegistryRepository, ServiceRegistryHealthCheckService, ImmortalGrpcClient], exports: [ServiceRegistryService], }) export default class ServiceRegistryModule {} diff --git a/src/modules/service-registry/services/service-registry-health-check.service.ts b/src/modules/service-registry/services/service-registry-health-check.service.ts index 724cccf..84ae9c4 100644 --- a/src/modules/service-registry/services/service-registry-health-check.service.ts +++ b/src/modules/service-registry/services/service-registry-health-check.service.ts @@ -19,6 +19,7 @@ export default class ServiceRegistryHealthCheckService implements OnModuleInit, constructor( private readonly serviceRegistryService: ServiceRegistryService, private readonly serviceRegistryRepository: ServiceRegistryRepository, + private readonly immortalGrpcClient: ImmortalGrpcClient, ) { this.serviceRegistryService.on('SERVICE_REGISTERED', (service: ServiceRegistryEntity) => { this.logger.log(`New service registered: ${service.type} (ID: ${service._id})`); @@ -80,9 +81,9 @@ export default class ServiceRegistryHealthCheckService implements OnModuleInit, let isHealthy = false; if (service.type === ServiceType.RELAY) { - const client = new ImmortalGrpcClient(service.url, false); + this.immortalGrpcClient.setUrl(service.url) - const res = await lastValueFrom(client.serviceClient.status({})); + const res = await lastValueFrom(this.immortalGrpcClient.serviceClient.status({})); isHealthy = res.services.every((s) => s.status === Status.CONNECTED); } diff --git a/src/modules/service-registry/services/service-registry.service.ts b/src/modules/service-registry/services/service-registry.service.ts index d0df618..7ca791e 100644 --- a/src/modules/service-registry/services/service-registry.service.ts +++ b/src/modules/service-registry/services/service-registry.service.ts @@ -6,14 +6,12 @@ import { ApiConfigService } from '../../../../src/shared/services/api-config.ser import type RegisterServiceRegistryDto from '../dtos/service-registry-register.dto'; import { ServiceRegistryEntity } from '../entities/service-registry.entity'; import { ServiceRegistryRepository } from '../service-registry.repository'; +import { ImmortalGrpcClient } from 'src/modules/grpc/immortal-grpc.client'; @Injectable() // eslint-disable-next-line unicorn/prefer-event-target export default class ServiceRegistryService extends EventEmitter { - constructor( - private readonly serviceRegistryRepository: ServiceRegistryRepository, - private readonly apiConfig: ApiConfigService, - ) { + constructor(private readonly serviceRegistryRepository: ServiceRegistryRepository) { super(); } @@ -36,7 +34,6 @@ export default class ServiceRegistryService extends EventEmitter { return this.serviceRegistryRepository.findOne({ where: { token } }); } - generateApiKey(serviceType: string, region: string): string { const timestamp = Date.now().toString(36); const randomPart = Math.floor(Math.random() * 1e6).toString(36); diff --git a/src/modules/subscriptions/subscriptions.controller.ts b/src/modules/subscriptions/subscriptions.controller.ts index f64f2b2..00e3bb6 100644 --- a/src/modules/subscriptions/subscriptions.controller.ts +++ b/src/modules/subscriptions/subscriptions.controller.ts @@ -1,12 +1,13 @@ import * as crypto from 'node:crypto'; -import { Body, Controller, Delete, Headers, Param, Patch, Post, UnauthorizedException } from '@nestjs/common'; -import { ApiTags } from '@nestjs/swagger'; +import { Body, Controller, Delete, Headers, Param, Patch, Post, UnauthorizedException, UseGuards } from '@nestjs/common'; +import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; import { ApiConfigService } from '../../../src/shared/services/api-config.service'; import { SubscriptionGenerateCheckoutSessionDto } from './dto/subscription-generate-checkout-session.dto'; import { SubscriptionsService } from './subscriptions.service'; import { UpdateSubscriptionDto } from './dto/update-subscription.dto'; +import JwtAuthGuard from '../auth/guards/jwt-auth.guard'; @Controller('subscriptions') @ApiTags('subscriptions') @@ -80,6 +81,8 @@ export class SubscriptionsController { } } + @UseGuards(JwtAuthGuard) + @ApiBearerAuth() @Post('seedRedis') seedRedis() { return this.subscriptionService.seedRedis(); diff --git a/src/shared/services/api-config.service.ts b/src/shared/services/api-config.service.ts index 8e4e31a..375aee6 100644 --- a/src/shared/services/api-config.service.ts +++ b/src/shared/services/api-config.service.ts @@ -90,8 +90,7 @@ export class ApiConfigService { dropSchema: this.isTest, synchronize: true, type: 'mongodb', - // database:"test", - url: this.getString('MONGO_URI'), + url: this.get('MONGO_DB_URL'), logging: this.getBoolean('ENABLE_ORM_LOGS'), connectTimeoutMS: this.getNumber('MONGO_DB_CONNECTION_TIMEOUT_IN_MS'), entities, diff --git a/yarn.lock b/yarn.lock index 9d265be..fa77c0e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7315,14 +7315,7 @@ run-parallel@^1.1.9: dependencies: queue-microtask "^1.2.2" -rxjs@7.8.1, rxjs@^7.5.5: - version "7.8.1" - resolved "https://registry.npmjs.org/rxjs/-/rxjs-7.8.1.tgz" - integrity sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg== - dependencies: - tslib "^2.1.0" - -rxjs@^7.8.1: +rxjs@7.8.1, rxjs@^7.5.5, rxjs@^7.8.1: version "7.8.1" resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.8.1.tgz#6f6f3d99ea8044291efd92e7c7fcf562c4057543" integrity sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==