platformservice/ts/email/email.classes.email.ts

48 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-02-15 19:30:38 +00:00
import * as plugins from './email.plugins.js';
import * as paths from './email.paths.js';
import { MailgunConnector } from './email.classes.connector.mailgun.js';
import { RuleManager } from './email.classes.rulemanager.js';
import { ApiManager } from './email.classes.apimanager.js';
import { logger } from './email.logging.js';
import type { SzPlatformService } from '../classes.platformservice.js';
export class Email {
public platformServiceRef: SzPlatformService;
// typedrouter
public mainTypedRouter = new plugins.typedrequest.TypedRouter();
// 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;
this.mailgunConnector = new MailgunConnector(this);
this.ruleManager = new RuleManager(this);
this.platformServiceRef.typedserver.server.addRoute(
'/mailgun-notify',
new plugins.loleServiceserver.Handler('POST', async (req, res) => {
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() {
}
}