-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(api,application-generic,ws,worker,webhook): resolve circular…
… dependencies; import refactor (#6268)
- Loading branch information
Showing
19 changed files
with
214 additions
and
258 deletions.
There are no files selected for viewing
Submodule .source
updated
from 018796 to 6e18f2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
libs/application-generic/src/utils/inject-auth-providers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { Reflector } from '@nestjs/core'; | ||
import { JwtService } from '@nestjs/jwt'; | ||
import { | ||
CommunityUserRepository, | ||
CommunityMemberRepository, | ||
CommunityOrganizationRepository, | ||
EnvironmentRepository, | ||
SubscriberRepository, | ||
UserRepository, | ||
MemberRepository, | ||
OrganizationRepository, | ||
} from '@novu/dal'; | ||
import { | ||
AnalyticsService, | ||
CommunityAuthService, | ||
CommunityUserAuthGuard, | ||
} from '../services'; | ||
import { CreateUser, SwitchOrganization } from '../usecases'; | ||
|
||
/** | ||
* Injects community auth providers, or providers handling user management (services, repositories, guards ...) into the application. | ||
* This function is closely related to its enterprise counterpart: | ||
* | ||
* @see @novu/ee-auth -> injectEEAuthProviders() | ||
* | ||
*/ | ||
export function injectCommunityAuthProviders( | ||
{ repositoriesOnly }: { repositoriesOnly?: boolean } = { | ||
repositoriesOnly: true, | ||
} | ||
) { | ||
const userRepositoryProvider = { | ||
provide: 'USER_REPOSITORY', | ||
useClass: CommunityUserRepository, | ||
}; | ||
|
||
const memberRepositoryProvider = { | ||
provide: 'MEMBER_REPOSITORY', | ||
useClass: CommunityMemberRepository, | ||
}; | ||
|
||
const organizationRepositoryProvider = { | ||
provide: 'ORGANIZATION_REPOSITORY', | ||
useClass: CommunityOrganizationRepository, | ||
}; | ||
|
||
const authServiceProvider = { | ||
provide: 'AUTH_SERVICE', | ||
useFactory: ( | ||
userRepository: UserRepository, | ||
subscriberRepository: SubscriberRepository, | ||
createUserUsecase: CreateUser, | ||
jwtService: JwtService, | ||
analyticsService: AnalyticsService, | ||
organizationRepository: OrganizationRepository, | ||
environmentRepository: EnvironmentRepository, | ||
memberRepository: MemberRepository, | ||
switchOrganizationUsecase: SwitchOrganization | ||
) => { | ||
return new CommunityAuthService( | ||
userRepository, | ||
subscriberRepository, | ||
createUserUsecase, | ||
jwtService, | ||
analyticsService, | ||
organizationRepository, | ||
environmentRepository, | ||
memberRepository, | ||
switchOrganizationUsecase | ||
); | ||
}, | ||
inject: [ | ||
UserRepository, | ||
SubscriberRepository, | ||
CreateUser, | ||
JwtService, | ||
AnalyticsService, | ||
OrganizationRepository, | ||
EnvironmentRepository, | ||
MemberRepository, | ||
SwitchOrganization, | ||
], | ||
}; | ||
|
||
const userAuthGuardProvider = { | ||
provide: 'USER_AUTH_GUARD', | ||
useFactory: (reflector: Reflector) => { | ||
return new CommunityUserAuthGuard(reflector); | ||
}, | ||
inject: [Reflector], | ||
}; | ||
|
||
if (repositoriesOnly) { | ||
return [ | ||
userRepositoryProvider, | ||
memberRepositoryProvider, | ||
organizationRepositoryProvider, | ||
]; | ||
} | ||
|
||
return [ | ||
userRepositoryProvider, | ||
memberRepositoryProvider, | ||
organizationRepositoryProvider, | ||
authServiceProvider, | ||
userAuthGuardProvider, | ||
]; | ||
} |
Oops, something went wrong.