mirror of
https://github.com/logto-io/logto.git
synced 2024-12-30 20:33:54 -05:00
refactor(connector): refactor passwordless connector
This commit is contained in:
parent
16fde21778
commit
d42c12b747
5 changed files with 25 additions and 25 deletions
|
@ -37,7 +37,7 @@ export default class AliyunDmConnector implements EmailConnector {
|
|||
const emailConfig = await this.getConfig(this.metadata.id);
|
||||
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) => {
|
||||
|
@ -47,14 +47,14 @@ export default class AliyunDmConnector implements EmailConnector {
|
|||
|
||||
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,
|
||||
type: keyof EmailMessageTypes,
|
||||
data: EmailMessageTypes[typeof type],
|
||||
config: AliyunDmConfig
|
||||
data: EmailMessageTypes[typeof type]
|
||||
) => {
|
||||
const { accessKeyId, accessKeySecret, accountName, fromAlias, templates } = config;
|
||||
const template = templates.find((template) => template.usageType === type);
|
||||
|
|
|
@ -32,7 +32,7 @@ export default class AliyunSmsConnector implements SmsConnector {
|
|||
const smsConfig = await this.getConfig(this.metadata.id);
|
||||
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) => {
|
||||
|
@ -42,14 +42,14 @@ export default class AliyunSmsConnector implements SmsConnector {
|
|||
|
||||
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,
|
||||
type: keyof SmsMessageTypes,
|
||||
data: SmsMessageTypes[typeof type],
|
||||
config: AliyunSmsConfig
|
||||
data: SmsMessageTypes[typeof type]
|
||||
) => {
|
||||
const { accessKeyId, accessKeySecret, signName, templates } = config;
|
||||
const template = templates.find(({ usageType }) => usageType === type);
|
||||
|
|
|
@ -38,7 +38,7 @@ export default class SendGridMailConnector implements EmailConnector {
|
|||
const emailConfig = await this.getConfig(this.metadata.id);
|
||||
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) => {
|
||||
|
@ -48,14 +48,14 @@ export default class SendGridMailConnector implements EmailConnector {
|
|||
|
||||
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,
|
||||
type: keyof EmailMessageTypes,
|
||||
data: EmailMessageTypes[typeof type],
|
||||
config: SendGridMailConfig
|
||||
data: EmailMessageTypes[typeof type]
|
||||
) => {
|
||||
const { apiKey, fromEmail, fromName, templates } = config;
|
||||
const template = templates.find((template) => template.usageType === type);
|
||||
|
|
|
@ -32,7 +32,7 @@ export default class SmtpConnector implements EmailConnector {
|
|||
const emailConfig = await this.getConfig(this.metadata.id);
|
||||
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) => {
|
||||
|
@ -42,14 +42,14 @@ export default class SmtpConnector implements EmailConnector {
|
|||
|
||||
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,
|
||||
type: keyof EmailMessageTypes,
|
||||
data: EmailMessageTypes[typeof type],
|
||||
config: SmtpConfig
|
||||
data: EmailMessageTypes[typeof type]
|
||||
) => {
|
||||
const { host, port, username, password, fromEmail, replyTo, templates } = config;
|
||||
const template = templates.find((template) => template.usageType === type);
|
||||
|
|
|
@ -31,7 +31,7 @@ export default class TwilioSmsConnector implements SmsConnector {
|
|||
const smsConfig = await this.getConfig(this.metadata.id);
|
||||
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) => {
|
||||
|
@ -41,14 +41,14 @@ export default class TwilioSmsConnector implements SmsConnector {
|
|||
|
||||
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,
|
||||
type: keyof SmsMessageTypes,
|
||||
data: SmsMessageTypes[typeof type],
|
||||
config: TwilioSmsConfig
|
||||
data: SmsMessageTypes[typeof type]
|
||||
) => {
|
||||
const { accountSID, authToken, fromMessagingServiceSID, templates } = config;
|
||||
const template = templates.find((template) => template.usageType === type);
|
||||
|
|
Loading…
Reference in a new issue