mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 21:15:32 +09:00
refactor(api): collapse single-impl interfaces and facades (#3382)
This commit is contained in:
1 parent
e7b13fd19f
commit
c16d414d93
426 files changed
+2085
-6445
No files matched your search
@@ -1,26 +0,0 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import type {I18nResult} from '@fluxer/i18n/src/runtime/I18nTypes';
|
||||
import {getEmailTemplate} from '@pkgs/email/src/email_i18n/EmailI18n';
|
||||
import type {EmailTemplateVariables} from '@pkgs/email/src/email_i18n/EmailI18nTypes';
|
||||
import type {EmailTemplate, EmailTemplateKey} from '@pkgs/email/src/email_i18n/EmailI18nTypes.generated';
|
||||
|
||||
export interface IEmailI18nService {
|
||||
getTemplate<T extends EmailTemplateKey>(
|
||||
templateKey: T,
|
||||
locale: string | null,
|
||||
variables: EmailTemplateVariables[T],
|
||||
productName: string,
|
||||
): I18nResult<EmailTemplateKey, EmailTemplate>;
|
||||
}
|
||||
|
||||
export class EmailI18nService implements IEmailI18nService {
|
||||
getTemplate<T extends EmailTemplateKey>(
|
||||
templateKey: T,
|
||||
locale: string | null,
|
||||
variables: EmailTemplateVariables[T],
|
||||
productName: string,
|
||||
): I18nResult<EmailTemplateKey, EmailTemplate> {
|
||||
return getEmailTemplate(templateKey, locale, variables, productName);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {createLogger} from '@fluxer/logger/src/Logger';
|
||||
import type {IEmailI18nService} from '@pkgs/email/src/EmailI18nService';
|
||||
import type {EmailConfig, IEmailProvider, UserBouncedEmailChecker} from '@pkgs/email/src/EmailProviderTypes';
|
||||
import {getEmailTemplate} from '@pkgs/email/src/email_i18n/EmailI18n';
|
||||
import type {
|
||||
EmailLegalLinks,
|
||||
EmailTemplateVariables,
|
||||
@@ -37,18 +37,15 @@ function legalLinkVariables(config: EmailConfig): {
|
||||
|
||||
export class EmailService implements IEmailService {
|
||||
private readonly config: EmailConfig;
|
||||
private readonly emailI18n: IEmailI18nService;
|
||||
private readonly provider: IEmailProvider | null;
|
||||
private readonly bouncedEmailChecker: UserBouncedEmailChecker | null;
|
||||
|
||||
constructor(
|
||||
config: EmailConfig,
|
||||
emailI18n: IEmailI18nService,
|
||||
provider: IEmailProvider | null = null,
|
||||
bouncedEmailChecker: UserBouncedEmailChecker | null = null,
|
||||
) {
|
||||
this.config = config;
|
||||
this.emailI18n = emailI18n;
|
||||
this.provider = provider;
|
||||
this.bouncedEmailChecker = bouncedEmailChecker;
|
||||
}
|
||||
@@ -394,7 +391,7 @@ export class EmailService implements IEmailService {
|
||||
locale: string | null,
|
||||
variables: EmailTemplateVariables[T],
|
||||
): Promise<boolean> {
|
||||
const result = this.emailI18n.getTemplate(templateKey, locale, variables, this.config.productName);
|
||||
const result = getEmailTemplate(templateKey, locale, variables, this.config.productName);
|
||||
if (!result.ok) {
|
||||
logger.error({key: templateKey, locale: result.locale, error: result.error}, 'Failed to resolve email template');
|
||||
return false;
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import type {IEmailService} from '@pkgs/email/src/IEmailService';
|
||||
|
||||
export interface SentEmailRecord {
|
||||
to: string;
|
||||
type: string;
|
||||
timestamp: Date;
|
||||
metadata: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface ITestEmailService extends IEmailService {
|
||||
listSentEmails(): Array<SentEmailRecord>;
|
||||
clearSentEmails(): void;
|
||||
}
|
||||
@@ -1,7 +1,14 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import type {ReportReceivedTargetKind} from '@pkgs/email/src/email_i18n/EmailI18nTypes';
|
||||
import type {ITestEmailService, SentEmailRecord} from '@pkgs/email/src/ITestEmailService';
|
||||
import type {IEmailService} from '@pkgs/email/src/IEmailService';
|
||||
|
||||
export interface SentEmailRecord {
|
||||
to: string;
|
||||
type: string;
|
||||
timestamp: Date;
|
||||
metadata: Record<string, string>;
|
||||
}
|
||||
|
||||
function maskToken(token: string): string {
|
||||
if (token.length <= 8) {
|
||||
@@ -12,7 +19,7 @@ function maskToken(token: string): string {
|
||||
|
||||
const noopLogger = {info: (_message: string) => {}};
|
||||
|
||||
export class TestEmailService implements ITestEmailService {
|
||||
export class TestEmailService implements IEmailService {
|
||||
private readonly sentEmails: Array<SentEmailRecord> = [];
|
||||
private readonly logger: {
|
||||
info: (message: string) => void;
|
||||
|
||||
Reference in new issue
Block a user