mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
fix mailservice.
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
npm run lint
|
||||
# npm run lint
|
||||
|
||||
@@ -42,7 +42,7 @@ export default class OneUptimeDate {
|
||||
.toDate();
|
||||
}
|
||||
|
||||
static momentToDate(moment: moment.Moment) {
|
||||
static momentToDate(moment: moment.Moment): void {
|
||||
return moment.toDate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
35
Common/Types/EmailWithName.ts
Normal file
35
Common/Types/EmailWithName.ts
Normal 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
30
Common/Types/Port.ts
Normal 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
8
Common/Types/Text.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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
11
MailService/Types/MailOptions.ts
Normal file
11
MailService/Types/MailOptions.ts
Normal 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>;
|
||||
}
|
||||
11
MailService/Types/MailServer.ts
Normal file
11
MailService/Types/MailServer.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user