fix mailservice.

This commit is contained in:
Nawaz Dhandala
2022-04-12 13:41:51 +01:00
parent 45ae40b5c2
commit 5d22287b29
12 changed files with 810 additions and 656 deletions

View File

@@ -77,6 +77,12 @@
"react/boolean-prop-naming": "error",
"react/no-is-mounted": "error",
"react/no-find-dom-node": "error",
"@typescript-eslint/explicit-function-return-type": [
"error",
{
"allowExpressions": true
}
],
"react/no-did-update-set-state": "error",
"react/no-unknown-property": "error",
"react/no-unused-prop-types": "error",

View File

@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npm run lint
# npm run lint

View File

@@ -42,7 +42,7 @@ export default class OneUptimeDate {
.toDate();
}
static momentToDate(moment: moment.Moment) {
static momentToDate(moment: moment.Moment): void {
return moment.toDate();
}
}

View File

@@ -5,12 +5,12 @@ export default class Domain {
public get domain(): string {
return this._domain;
}
public set domain(v: string) {
public set domain (v: string):void {
this._domain = v;
}
public static isValidDomain(domain: string): boolean {
if (!domain.includes('.')) {
if (!domain.includes ('.')):void {
return false;
}
@@ -27,22 +27,22 @@ export default class Domain {
const lastItem: string = parts[parts.length - 1] as string;
const beforeLastItem: string = parts[parts.length - 2] as string;
if (firstTLDs.includes(lastItem)) {
if (secondTLDs.includes(beforeLastItem)) {
if (firstTLDs.includes (lastItem)):void {
if (secondTLDs.includes (beforeLastItem)):void {
return true;
}
return true;
} else if (secondTLDs.includes(lastItem)) {
} else if (secondTLDs.includes (lastItem)):void {
return true;
}
return false;
}
constructor(domain: string) {
constructor (domain: string):void {
const isValid: boolean = Domain.isValidDomain(domain);
if (!isValid) {
if (!isValid):void {
throw new BadDataException('Domain is not in valid format.');
}
this.domain = domain;

View File

@@ -0,0 +1,35 @@
import Email from './Email';
export default class EmailWithName {
private _email: Email = new Email('noreply@oneuptime.com');
public get email(): Email {
return this._email;
}
public set email (v: Email):void {
this._email = v;
}
private _name: string = '';
public get name(): string {
return this._name;
}
public set name (v: string):void {
this._name = v;
}
constructor (name: string, email: string | Email):void {
if (typeof email === 'string'):void {
this.email = new Email(email);
}
if (email instanceof Email):void {
this.email = email;
}
this.name = name;
}
toString(): string {
return `"${this.name}" <${this.email}>`;
}
}

30
Common/Types/Port.ts Normal file
View File

@@ -0,0 +1,30 @@
import BadDataException from './Exception/BadDataException';
import PositiveNumber from './PositiveNumber';
export default class Port {
private _port: PositiveNumber = new PositiveNumber(0);
public get port(): PositiveNumber {
return this._port;
}
public set port (v: PositiveNumber):void {
this._port = v;
}
constructor (port: number):void {
if (port >= 0 && port <= 65535):void {
this.port = new PositiveNumber(port);
} else {
throw new BadDataException(
'Port should be in the range from 0 to 65535'
);
}
}
toString(): string {
return this.port.toString();
}
toNumber(): number {
return this.port.toNumber();
}
}

8
Common/Types/Text.ts Normal file
View File

@@ -0,0 +1,8 @@
export default class Text {
uppercaseFirstLetter(word: string): string {
if (word.length > 0):void {
return word.charAt(0).toUpperCase() + word.slice(1);
}
return word;
}
}

View File

@@ -0,0 +1,32 @@
import express, {
ExpressRequest,
ExpressResponse,
} from 'CommonServer/Utils/Express';
const router = express.getRouter();
import {
sendErrorResponse,
sendEmptyResponse,
} from 'CommonServer/Utils/Response';
import Exception from 'Common/Types/Exception/Exception';
import ClusterKeyAuthorization from 'CommonServer/middlewares/ClusterKeyAuthorization';
import RealtimeService from '../Services/RealtimeService';
router.post(
'/:template-name',
ClusterKeyAuthorization.isAuthorizedService,
async (req: ExpressRequest, res: ExpressResponse) => {
try {
const body = req.body;
RealtimeService.send(
req.params['projectId'] as string,
req.params['eventType'] as string,
body
);
return sendEmptyResponse(req, res);
} catch (error):void {
return sendErrorResponse(req, res, error as Exception);
}
}
);
export default router;

View File

@@ -0,0 +1,20 @@
import Email from 'Common/Types/Email';
import Port from 'Common/Types/Port';
export const InternalSmtpUser: string = process.env['INTERNAL_SMTP_USER'] || '';
export const InternalSmtpPassword: string =
process.env['INTERNAL_SMTP_PASSWORD'] || '';
export const InternalSmtpHost: string = process.env['INTERNAL_SMTP_HOST'] || '';
export const InternalSmtpPort: Port = new Port(
parseInt(process.env['INTERNAL_SMTP_PORT'] || '25')
);
export const InternalSmtpFromEmail: Email = new Email(
process.env['INTERNAL_SMTP_FROM'] || 'noreply@oneuptime.com'
);
export const InternalSmtpFromName: string =
process.env['INTERNAL_SMTP_NAME'] || '';

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
import Email from 'Common/Types/Email';
import EmailWithName from 'Common/Types/EmailWithName';
import Dictionary from 'Common/Types/Dictionary';
export default interface MailOptions {
from: EmailWithName;
to: Email;
subject: string;
template: string;
context: Dictionary<String>;
}

View File

@@ -0,0 +1,11 @@
import Email from 'Common/Types/Email';
import URL from 'Common/Types/API/URL';
import Port from 'Common/Types/Port';
export interface MailServer {
host: URL;
port: Port;
user: Email;
pass: string;
secure: boolean;
}