0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-27 21:39:16 -05:00

refactor(connector): refactor passwordless connector

This commit is contained in:
Darcy Ye 2022-07-12 21:15:14 +08:00
parent 16fde21778
commit d42c12b747
No known key found for this signature in database
GPG key ID: B46F4C07EDEFC610
5 changed files with 25 additions and 25 deletions

View file

@ -37,7 +37,7 @@ export default class AliyunDmConnector implements EmailConnector {
const emailConfig = await this.getConfig(this.metadata.id); const emailConfig = await this.getConfig(this.metadata.id);
await this.validateConfig(emailConfig); await this.validateConfig(emailConfig);
return this.sendMessageCore(address, type, data, emailConfig); return this.sendMessageBy(emailConfig, address, type, data);
}; };
public sendTestMessage: EmailSendMessageFunction = async (address, type, data, config) => { public sendTestMessage: EmailSendMessageFunction = async (address, type, data, config) => {
@ -47,14 +47,14 @@ export default class AliyunDmConnector implements EmailConnector {
await this.validateConfig(config); await this.validateConfig(config);
return this.sendMessageCore(address, type, data, config as AliyunDmConfig); return this.sendMessageBy(config as AliyunDmConfig, address, type, data);
}; };
private readonly sendMessageCore = async ( private readonly sendMessageBy = async (
config: AliyunDmConfig,
address: string, address: string,
type: keyof EmailMessageTypes, type: keyof EmailMessageTypes,
data: EmailMessageTypes[typeof type], data: EmailMessageTypes[typeof type]
config: AliyunDmConfig
) => { ) => {
const { accessKeyId, accessKeySecret, accountName, fromAlias, templates } = config; const { accessKeyId, accessKeySecret, accountName, fromAlias, templates } = config;
const template = templates.find((template) => template.usageType === type); const template = templates.find((template) => template.usageType === type);

View file

@ -32,7 +32,7 @@ export default class AliyunSmsConnector implements SmsConnector {
const smsConfig = await this.getConfig(this.metadata.id); const smsConfig = await this.getConfig(this.metadata.id);
await this.validateConfig(smsConfig); await this.validateConfig(smsConfig);
return this.sendMessageCore(phone, type, { code }, smsConfig); return this.sendMessageBy(smsConfig, phone, type, { code });
}; };
public sendTestMessage: SmsSendMessageFunction = async (phone, type, { code }, config) => { public sendTestMessage: SmsSendMessageFunction = async (phone, type, { code }, config) => {
@ -42,14 +42,14 @@ export default class AliyunSmsConnector implements SmsConnector {
await this.validateConfig(config); await this.validateConfig(config);
return this.sendMessageCore(phone, type, { code }, config as AliyunSmsConfig); return this.sendMessageBy(config as AliyunSmsConfig, phone, type, { code });
}; };
private readonly sendMessageCore = async ( private readonly sendMessageBy = async (
config: AliyunSmsConfig,
phone: string, phone: string,
type: keyof SmsMessageTypes, type: keyof SmsMessageTypes,
data: SmsMessageTypes[typeof type], data: SmsMessageTypes[typeof type]
config: AliyunSmsConfig
) => { ) => {
const { accessKeyId, accessKeySecret, signName, templates } = config; const { accessKeyId, accessKeySecret, signName, templates } = config;
const template = templates.find(({ usageType }) => usageType === type); const template = templates.find(({ usageType }) => usageType === type);

View file

@ -38,7 +38,7 @@ export default class SendGridMailConnector implements EmailConnector {
const emailConfig = await this.getConfig(this.metadata.id); const emailConfig = await this.getConfig(this.metadata.id);
await this.validateConfig(emailConfig); await this.validateConfig(emailConfig);
return this.sendMessageCore(address, type, data, emailConfig); return this.sendMessageBy(emailConfig, address, type, data);
}; };
public sendTestMessage: EmailSendMessageFunction = async (address, type, data, config) => { public sendTestMessage: EmailSendMessageFunction = async (address, type, data, config) => {
@ -48,14 +48,14 @@ export default class SendGridMailConnector implements EmailConnector {
await this.validateConfig(config); await this.validateConfig(config);
return this.sendMessageCore(address, type, data, config as SendGridMailConfig); return this.sendMessageBy(config as SendGridMailConfig, address, type, data);
}; };
private readonly sendMessageCore = async ( private readonly sendMessageBy = async (
config: SendGridMailConfig,
address: string, address: string,
type: keyof EmailMessageTypes, type: keyof EmailMessageTypes,
data: EmailMessageTypes[typeof type], data: EmailMessageTypes[typeof type]
config: SendGridMailConfig
) => { ) => {
const { apiKey, fromEmail, fromName, templates } = config; const { apiKey, fromEmail, fromName, templates } = config;
const template = templates.find((template) => template.usageType === type); const template = templates.find((template) => template.usageType === type);

View file

@ -32,7 +32,7 @@ export default class SmtpConnector implements EmailConnector {
const emailConfig = await this.getConfig(this.metadata.id); const emailConfig = await this.getConfig(this.metadata.id);
await this.validateConfig(emailConfig); await this.validateConfig(emailConfig);
return this.sendMessageCore(address, type, data, emailConfig); return this.sendMessageBy(emailConfig, address, type, data);
}; };
public sendTestMessage: EmailSendMessageFunction = async (address, type, data, config) => { public sendTestMessage: EmailSendMessageFunction = async (address, type, data, config) => {
@ -42,14 +42,14 @@ export default class SmtpConnector implements EmailConnector {
await this.validateConfig(config); await this.validateConfig(config);
return this.sendMessageCore(address, type, data, config as SmtpConfig); return this.sendMessageBy(config as SmtpConfig, address, type, data);
}; };
private readonly sendMessageCore = async ( private readonly sendMessageBy = async (
config: SmtpConfig,
address: string, address: string,
type: keyof EmailMessageTypes, type: keyof EmailMessageTypes,
data: EmailMessageTypes[typeof type], data: EmailMessageTypes[typeof type]
config: SmtpConfig
) => { ) => {
const { host, port, username, password, fromEmail, replyTo, templates } = config; const { host, port, username, password, fromEmail, replyTo, templates } = config;
const template = templates.find((template) => template.usageType === type); const template = templates.find((template) => template.usageType === type);

View file

@ -31,7 +31,7 @@ export default class TwilioSmsConnector implements SmsConnector {
const smsConfig = await this.getConfig(this.metadata.id); const smsConfig = await this.getConfig(this.metadata.id);
await this.validateConfig(smsConfig); await this.validateConfig(smsConfig);
return this.sendMessageCore(address, type, data, smsConfig); return this.sendMessageBy(smsConfig, address, type, data);
}; };
public sendTestMessage: SmsSendMessageFunction = async (address, type, data, config) => { public sendTestMessage: SmsSendMessageFunction = async (address, type, data, config) => {
@ -41,14 +41,14 @@ export default class TwilioSmsConnector implements SmsConnector {
await this.validateConfig(config); await this.validateConfig(config);
return this.sendMessageCore(address, type, data, config as TwilioSmsConfig); return this.sendMessageBy(config as TwilioSmsConfig, address, type, data);
}; };
private readonly sendMessageCore = async ( private readonly sendMessageBy = async (
config: TwilioSmsConfig,
phone: string, phone: string,
type: keyof SmsMessageTypes, type: keyof SmsMessageTypes,
data: SmsMessageTypes[typeof type], data: SmsMessageTypes[typeof type]
config: TwilioSmsConfig
) => { ) => {
const { accountSID, authToken, fromMessagingServiceSID, templates } = config; const { accountSID, authToken, fromMessagingServiceSID, templates } = config;
const template = templates.find((template) => template.usageType === type); const template = templates.find((template) => template.usageType === type);