Skip to content

Commit

Permalink
refactor(api,worker): untagle modules and deps (#6673)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChmaraX authored Oct 14, 2024
1 parent 386d6d1 commit 7624e94
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .source
3 changes: 2 additions & 1 deletion apps/api/src/app/rate-limiting/rate-limiting.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Module } from '@nestjs/common';
import { ThrottlerModule } from '@nestjs/throttler';
import { CommunityOrganizationRepository } from '@novu/dal';
import { USE_CASES } from './usecases';
import { SharedModule } from '../shared/shared.module';
import { ApiRateLimitInterceptor } from './guards';
Expand All @@ -15,7 +16,7 @@ import { ApiRateLimitInterceptor } from './guards';
},
]),
],
providers: [...USE_CASES, ApiRateLimitInterceptor],
providers: [...USE_CASES, ApiRateLimitInterceptor, CommunityOrganizationRepository],
exports: [...USE_CASES, ApiRateLimitInterceptor],
})
export class RateLimitingModule {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EnvironmentRepository, OrganizationRepository } from '@novu/dal';
import { CommunityOrganizationRepository, EnvironmentRepository } from '@novu/dal';
import { UserSession } from '@novu/testing';
import { ApiRateLimitCategoryEnum, ApiServiceLevelEnum } from '@novu/shared';
import { expect } from 'chai';
Expand Down Expand Up @@ -27,7 +27,7 @@ const mockDefaultApiRateLimits = {
describe('GetApiRateLimitMaximum', async () => {
let useCase: GetApiRateLimitMaximum;
let session: UserSession;
let organizationRepository: OrganizationRepository;
let organizationRepository: CommunityOrganizationRepository;
let environmentRepository: EnvironmentRepository;
let getDefaultApiRateLimits: GetApiRateLimitServiceMaximumConfig;

Expand All @@ -48,7 +48,7 @@ describe('GetApiRateLimitMaximum', async () => {
await session.initialize();

useCase = moduleRef.get<GetApiRateLimitMaximum>(GetApiRateLimitMaximum);
organizationRepository = moduleRef.get<OrganizationRepository>(OrganizationRepository);
organizationRepository = moduleRef.get<CommunityOrganizationRepository>(CommunityOrganizationRepository);
environmentRepository = moduleRef.get<EnvironmentRepository>(EnvironmentRepository);
getDefaultApiRateLimits = moduleRef.get<GetApiRateLimitServiceMaximumConfig>(GetApiRateLimitServiceMaximumConfig);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable, InternalServerErrorException, Logger } from '@nestjs/common';
import { EnvironmentRepository, OrganizationRepository } from '@novu/dal';
import { CommunityOrganizationRepository, EnvironmentRepository } from '@novu/dal';
import { buildMaximumApiRateLimitKey, CachedEntity, InstrumentUsecase } from '@novu/application-generic';
import { ApiRateLimitCategoryEnum, ApiServiceLevelEnum, IApiRateLimitMaximum } from '@novu/shared';
import { GetApiRateLimitMaximumCommand } from './get-api-rate-limit-maximum.command';
Expand All @@ -12,7 +12,7 @@ const LOG_CONTEXT = 'GetApiRateLimit';
export class GetApiRateLimitMaximum {
constructor(
private environmentRepository: EnvironmentRepository,
private organizationRepository: OrganizationRepository,
private organizationRepository: CommunityOrganizationRepository,
private getDefaultApiRateLimits: GetApiRateLimitServiceMaximumConfig
) {}

Expand Down
54 changes: 38 additions & 16 deletions apps/api/src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ import {
ExecuteBridgeRequest,
ExecutionLogRoute,
featureFlagsService,
getFeatureFlag,
injectCommunityAuthProviders,
getFeatureFlag,
InvalidateCacheService,
LoggerModule,
QueuesModule,
storageService,
} from '@novu/application-generic';

import { isClerkEnabled, JobTopicNameEnum } from '@novu/shared';
import { JwtModule } from '@nestjs/jwt';
import packageJson from '../../../package.json';

function getDynamicAuthProviders() {
Expand Down Expand Up @@ -85,7 +86,6 @@ const DAL_MODELS = [
WorkflowOverrideRepository,
ControlValuesRepository,
PreferencesRepository,
...getDynamicAuthProviders(),
];

const dalService = {
Expand Down Expand Up @@ -116,21 +116,43 @@ const PROVIDERS = [
getFeatureFlag,
];

const IMPORTS = [
QueuesModule.forRoot([
JobTopicNameEnum.EXECUTION_LOG,
JobTopicNameEnum.WEB_SOCKETS,
JobTopicNameEnum.WORKFLOW,
JobTopicNameEnum.INBOUND_PARSE_MAIL,
]),
LoggerModule.forRoot(
createNestLoggingModuleOptions({
serviceName: packageJson.name,
version: packageJson.version,
})
),
];

if (process.env.NODE_ENV === 'test') {
/**
* This is here only because of the tests. These providers are available at AppModule level,
* but since in tests we are often importing just the SharedModule and not the entire AppModule
* we need to make sure these providers are available.
*
* TODO: modify tests to either import all services they need explicitly, or remove repositories from SharedModule,
* and then import SharedModule + repositories explicitly.
*/
PROVIDERS.push(...getDynamicAuthProviders());
IMPORTS.push(
JwtModule.register({
secret: `${process.env.JWT_SECRET}`,
signOptions: {
expiresIn: 360000,
},
})
);
}

@Module({
imports: [
QueuesModule.forRoot([
JobTopicNameEnum.EXECUTION_LOG,
JobTopicNameEnum.WEB_SOCKETS,
JobTopicNameEnum.WORKFLOW,
JobTopicNameEnum.INBOUND_PARSE_MAIL,
]),
LoggerModule.forRoot(
createNestLoggingModuleOptions({
serviceName: packageJson.name,
version: packageJson.version,
})
),
],
imports: [...IMPORTS],
providers: [...PROVIDERS],
exports: [...PROVIDERS, LoggerModule, QueuesModule],
})
Expand Down
1 change: 0 additions & 1 deletion apps/worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
"typescript": "5.6.2"
},
"optionalDependencies": {
"@novu/ee-auth": "workspace:*",
"@novu/ee-billing": "workspace:*",
"@novu/ee-shared-services": "workspace:*",
"@novu/ee-translation": "workspace:*"
Expand Down
19 changes: 1 addition & 18 deletions apps/worker/src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
ExecuteBridgeRequest,
featureFlagsService,
GetTenant,
injectCommunityAuthProviders,
InvalidateCacheService,
LoggerModule,
MetricsModule,
Expand All @@ -43,35 +42,21 @@ import {
NotificationGroupRepository,
NotificationRepository,
NotificationTemplateRepository,
OrganizationRepository,
SubscriberPreferenceRepository,
SubscriberRepository,
TenantRepository,
TopicRepository,
TopicSubscribersRepository,
UserRepository,
WorkflowOverrideRepository,
} from '@novu/dal';

import { isClerkEnabled, JobTopicNameEnum } from '@novu/shared';
import { JobTopicNameEnum } from '@novu/shared';
import packageJson from '../../../package.json';
import { UNIQUE_WORKER_DEPENDENCIES } from '../../config/worker-init.config';
import { ActiveJobsMetricService } from '../workflow/services';
import { CreateLog } from './logs';

function getDynamicAuthProviders() {
if (isClerkEnabled()) {
// eslint-disable-next-line global-require
const eeAuthPackage = require('@novu/ee-auth');

return eeAuthPackage.injectEEAuthProviders();
} else {
return injectCommunityAuthProviders();
}
}

const DAL_MODELS = [
OrganizationRepository,
EnvironmentRepository,
ExecutionDetailsRepository,
NotificationTemplateRepository,
Expand All @@ -90,8 +75,6 @@ const DAL_MODELS = [
TenantRepository,
WorkflowOverrideRepository,
ControlValuesRepository,
UserRepository,
...getDynamicAuthProviders(),
];

const dalService = {
Expand Down
8 changes: 4 additions & 4 deletions apps/worker/src/app/telemetry/telemetry.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import {
IntegrationRepository,
NotificationRepository,
NotificationTemplateRepository,
OrganizationRepository,
SubscriberRepository,
TopicRepository,
UserRepository,
CommunityUserRepository,
CommunityOrganizationRepository,
} from '@novu/dal';
import { SharedModule } from '../shared/shared.module';
import { MachineInfoService } from './usecases/machineInfoService.usecase';
import { UserInfoService } from './usecases/userInfoService.usecase';

const REPOSITORIES = [
UserRepository,
CommunityUserRepository,
CommunityOrganizationRepository,
NotificationTemplateRepository,
NotificationRepository,
OrganizationRepository,
TopicRepository,
SubscriberRepository,
IntegrationRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ import { HttpService } from '@nestjs/axios';
import { Injectable } from '@nestjs/common';
import { Cron, CronExpression } from '@nestjs/schedule';
import {
CommunityUserRepository,
CommunityOrganizationRepository,
IntegrationRepository,
NotificationRepository,
NotificationTemplateRepository,
OrganizationRepository,
SubscriberRepository,
TopicRepository,
UserRepository,
} from '@novu/dal';
import { loadOrCreateMachineId } from '../utils/machine.utils';
import { sendDataToNovuTrace } from '../utils/sendDataToNovuTrace.utils';

@Injectable()
export class UserInfoService {
constructor(
private readonly userRepository: UserRepository,
private readonly organizationRepository: OrganizationRepository,
private readonly userRepository: CommunityUserRepository,
private readonly organizationRepository: CommunityOrganizationRepository,
private readonly notificationTemplateRepository: NotificationTemplateRepository,
private readonly notificationRepository: NotificationRepository,
private readonly topicRepository: TopicRepository,
Expand Down
4 changes: 1 addition & 3 deletions enterprise/packages/billing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"dependencies": {
"@novu/application-generic": "workspace:*",
"@novu/ee-dal": "workspace:*",
"@novu/ee-auth": "workspace:*",
"@novu/shared": "workspace:*",
"class-transformer": "0.5.1",
"class-validator": "0.14.1",
Expand Down Expand Up @@ -47,8 +48,5 @@
"@nestjs/swagger": "7.4.0",
"@nestjs/throttler": "6.2.1",
"@novu/dal": "workspace:*"
},
"optionalDependencies": {
"@novu/ee-auth": "workspace:*"
}
}
4 changes: 0 additions & 4 deletions enterprise/packages/translation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,8 @@
},
"peerDependencies": {
"@nestjs/common": "10.4.1",
"@nestjs/jwt": "10.2.0",
"@nestjs/swagger": "7.4.0",
"@nestjs/platform-express": "10.4.1",
"@novu/dal": "workspace:*"
},
"optionalDependencies": {
"@novu/ee-auth": "workspace:*"
}
}
17 changes: 3 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7624e94

Please sign in to comment.