* --init * -- * replace old structure with new DI * fix type * -- * moving stuff around * moving stuff around again * minor clean up * -- * resolve conflict * clea up * old schema clean up * further clean up * removing unwanted merged responsibilities * -- * improve DI and SOLID * some type fixes * --1 * clean up --cont * fix DI in facade for test * more fix * fix * checking * o.o * fix import * fix failing test --2 * fix failing test --3 * fix failing test --4 * normalization use * introduce facade container injection * uniform async telemetry spans * further improvements * replace prismock with repo mocks * ensure we don't pass prisma outside of repo * fix import * remove try catch from repo calls * async await fixes * using deps pattern * more clean up and fixes * more clean up * address feedback --1 * separation of concern * clean up * test clean up * feedback --2 * remove extra fetch * remove await * migrate _post test from prismock * fix type * -- * fix tokens path * rename AuditRepo * test --1 * update _post to integration test * fix test * fix test * test fix maybe? * -- * feedback * feedback * fixes * more feedback * NIT * use sentry and logger imports as planned * assertion in test * add missing test case * add tests for controllers and services * NITs * fix domain normalisation
60 lines
1.9 KiB
TypeScript
60 lines
1.9 KiB
TypeScript
import type { IBlockingService, BlockingResult } from "../interface/IBlockingService";
|
|
import type { IOrganizationWatchlistRepository } from "../interface/IWatchlistRepositories";
|
|
import { WatchlistType } from "../types";
|
|
import { normalizeEmail, extractDomainFromEmail, normalizeDomain } from "../utils/normalization";
|
|
|
|
type Deps = {
|
|
orgRepo: IOrganizationWatchlistRepository;
|
|
};
|
|
|
|
/**
|
|
* Service for organization-specific blocking operations
|
|
* Handles blocking rules that apply only to a specific organization
|
|
*/
|
|
export class OrganizationBlockingService implements IBlockingService {
|
|
constructor(private readonly deps: Deps) {}
|
|
|
|
async isBlocked(email: string, organizationId: number): Promise<BlockingResult> {
|
|
const normalizedEmail = normalizeEmail(email);
|
|
const normalizedDomain = extractDomainFromEmail(normalizedEmail);
|
|
|
|
const emailPromise = this.deps.orgRepo.findBlockedEmail({ email: normalizedEmail, organizationId });
|
|
const domainPromise = this.deps.orgRepo.findBlockedDomain(normalizedDomain, organizationId);
|
|
|
|
const [emailEntry, domainEntry] = await Promise.all([emailPromise, domainPromise]);
|
|
|
|
if (emailEntry) {
|
|
return {
|
|
isBlocked: true,
|
|
reason: WatchlistType.EMAIL,
|
|
watchlistEntry: emailEntry,
|
|
};
|
|
}
|
|
|
|
if (domainEntry) {
|
|
return {
|
|
isBlocked: true,
|
|
reason: WatchlistType.DOMAIN,
|
|
watchlistEntry: domainEntry,
|
|
};
|
|
}
|
|
|
|
return { isBlocked: false };
|
|
}
|
|
|
|
async isDomainBlocked(domain: string, organizationId: number): Promise<BlockingResult> {
|
|
const normalizedDomain = normalizeDomain(domain);
|
|
|
|
return this.deps.orgRepo.findBlockedDomain(normalizedDomain, organizationId).then((domainEntry) => {
|
|
if (domainEntry) {
|
|
return {
|
|
isBlocked: true,
|
|
reason: WatchlistType.DOMAIN,
|
|
watchlistEntry: domainEntry,
|
|
};
|
|
}
|
|
return { isBlocked: false };
|
|
});
|
|
}
|
|
}
|