2024-02-16 12:28:40 +00:00
|
|
|
import * as plugins from '../plugins.js';
|
|
|
|
import * as paths from '../paths.js';
|
2024-02-15 19:30:38 +00:00
|
|
|
import { MailgunConnector } from './email.classes.connector.mailgun.js';
|
|
|
|
import { RuleManager } from './email.classes.rulemanager.js';
|
|
|
|
import { ApiManager } from './email.classes.apimanager.js';
|
2024-02-16 12:28:40 +00:00
|
|
|
import { logger } from '../logger.js';
|
2024-02-15 19:30:38 +00:00
|
|
|
import type { SzPlatformService } from '../classes.platformservice.js';
|
|
|
|
|
2024-02-16 12:28:40 +00:00
|
|
|
export class EmailService {
|
2024-02-15 19:30:38 +00:00
|
|
|
public platformServiceRef: SzPlatformService;
|
|
|
|
|
|
|
|
// typedrouter
|
2024-02-16 12:28:40 +00:00
|
|
|
public typedrouter = new plugins.typedrequest.TypedRouter();
|
2024-02-15 19:30:38 +00:00
|
|
|
|
|
|
|
// connectors
|
|
|
|
public mailgunConnector: MailgunConnector;
|
|
|
|
public qenv = new plugins.qenv.Qenv('./', '.nogit/');
|
|
|
|
|
|
|
|
// server
|
|
|
|
public apiManager = new ApiManager(this);
|
|
|
|
public ruleManager: RuleManager;
|
|
|
|
|
|
|
|
constructor(platformServiceRefArg: SzPlatformService) {
|
|
|
|
this.platformServiceRef = platformServiceRefArg;
|
2024-02-16 12:28:40 +00:00
|
|
|
this.platformServiceRef.typedrouter.addTypedRouter(this.typedrouter);
|
2024-02-15 19:30:38 +00:00
|
|
|
this.mailgunConnector = new MailgunConnector(this);
|
|
|
|
this.ruleManager = new RuleManager(this);
|
|
|
|
this.platformServiceRef.typedserver.server.addRoute(
|
|
|
|
'/mailgun-notify',
|
2024-02-16 12:28:40 +00:00
|
|
|
new plugins.typedserver.servertools.Handler('POST', async (req, res) => {
|
2024-02-15 19:30:38 +00:00
|
|
|
console.log('Got a mailgun email notification');
|
|
|
|
res.status(200);
|
|
|
|
res.end();
|
|
|
|
this.ruleManager.handleNotification(req.body);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async start() {
|
|
|
|
await this.ruleManager.init();
|
|
|
|
logger.log('success', `Started email service`);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async stop() {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|