mirror of
https://github.com/standardnotes/server
synced 2026-01-16 20:04:32 -05:00
* fix(api-gateway): reduce exports * wip controllers * fix: imports of controllers * fix(api-gateway): rename http service interface to proxy interface * wip: self-registering services and controllers * wip: add registering controller method bindings and services in container * feat: merge two services together * wip: resolving endpoints to direct code calls * wip: bind controller container to a singleton * fix: controller binding to instantiate and self-register on controller container * fix: move signout endpoint to auth controller * wip: define inversify controllers in the controller container * fix(auth): bind inversify controllers to controller container * fix(auth): linter issues * fix(auth): specs * fix(auth): inversify controllers bindings * wip: endpoint resolving * wip: add endpoint for more auth controllers * wip: add sessions controller endpoint resolvings * wip: add subscription invites endpoint resolvings * wip: add subscription tokens endpoint resolvings * wip: add all binding for auth server controllers * wip: fix migrations path * fix: configure default env vars and ci setup
70 lines
2.6 KiB
TypeScript
70 lines
2.6 KiB
TypeScript
import { Username } from '@standardnotes/domain-core'
|
|
import {
|
|
DomainEventHandlerInterface,
|
|
DomainEventPublisherInterface,
|
|
PredicateVerificationRequestedEvent,
|
|
} from '@standardnotes/domain-events'
|
|
import { PredicateVerificationResult } from '@standardnotes/predicates'
|
|
import { inject, injectable } from 'inversify'
|
|
import { Logger } from 'winston'
|
|
|
|
import TYPES from '../../Bootstrap/Types'
|
|
import { DomainEventFactoryInterface } from '../Event/DomainEventFactoryInterface'
|
|
import { VerifyPredicate } from '../UseCase/VerifyPredicate/VerifyPredicate'
|
|
import { UserRepositoryInterface } from '../User/UserRepositoryInterface'
|
|
|
|
@injectable()
|
|
export class PredicateVerificationRequestedEventHandler implements DomainEventHandlerInterface {
|
|
constructor(
|
|
@inject(TYPES.Auth_VerifyPredicate) private verifyPredicate: VerifyPredicate,
|
|
@inject(TYPES.Auth_UserRepository) private userRepository: UserRepositoryInterface,
|
|
@inject(TYPES.Auth_DomainEventFactory) private domainEventFactory: DomainEventFactoryInterface,
|
|
@inject(TYPES.Auth_DomainEventPublisher) private domainEventPublisher: DomainEventPublisherInterface,
|
|
@inject(TYPES.Auth_Logger) private logger: Logger,
|
|
) {}
|
|
|
|
async handle(event: PredicateVerificationRequestedEvent): Promise<void> {
|
|
this.logger.debug(`Received verification request of predicate: ${event.payload.predicate.name}`)
|
|
|
|
let userUuid = event.meta.correlation.userIdentifier
|
|
if (event.meta.correlation.userIdentifierType === 'email') {
|
|
const usernameOrError = Username.create(event.meta.correlation.userIdentifier)
|
|
if (usernameOrError.isFailed()) {
|
|
return
|
|
}
|
|
const username = usernameOrError.getValue()
|
|
|
|
const user = await this.userRepository.findOneByUsernameOrEmail(username)
|
|
if (user === null) {
|
|
await this.domainEventPublisher.publish(
|
|
this.domainEventFactory.createPredicateVerifiedEvent({
|
|
predicate: event.payload.predicate,
|
|
predicateVerificationResult: PredicateVerificationResult.CouldNotBeDetermined,
|
|
userUuid,
|
|
}),
|
|
)
|
|
|
|
return
|
|
}
|
|
userUuid = user.uuid
|
|
}
|
|
|
|
const { predicateVerificationResult } = await this.verifyPredicate.execute({
|
|
predicate: event.payload.predicate,
|
|
userUuid,
|
|
})
|
|
|
|
await this.domainEventPublisher.publish(
|
|
this.domainEventFactory.createPredicateVerifiedEvent({
|
|
predicate: event.payload.predicate,
|
|
predicateVerificationResult,
|
|
userUuid,
|
|
}),
|
|
)
|
|
|
|
this.logger.debug(
|
|
`Published predicate verification (${predicateVerificationResult}) result for: ${event.payload.predicate.name}`,
|
|
)
|
|
}
|
|
}
|