mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-09 23:48:36 +01:00
add anomaly + fix billing + add emails templates
This commit is contained in:
16
shared/schema/anomalies/AnomalyDomainSchema.ts
Normal file
16
shared/schema/anomalies/AnomalyDomainSchema.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
|
||||
export type TAnomalyDomain = {
|
||||
project_id: Schema.Types.ObjectId
|
||||
domain: string,
|
||||
created_at: Date
|
||||
}
|
||||
|
||||
const AnomalyDomainSchema = new Schema<TAnomalyDomain>({
|
||||
project_id: { type: Types.ObjectId, required: true },
|
||||
domain: { type: String, required: true },
|
||||
created_at: { type: Date, required: true },
|
||||
})
|
||||
|
||||
export const AnomalyDomainModel = model<TAnomalyDomain>('anomaly_domains', AnomalyDomainSchema);
|
||||
16
shared/schema/anomalies/AnomalyEventsSchema.ts
Normal file
16
shared/schema/anomalies/AnomalyEventsSchema.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
|
||||
export type TAnomalyEvents = {
|
||||
project_id: Schema.Types.ObjectId
|
||||
eventDate: string,
|
||||
created_at: Date
|
||||
}
|
||||
|
||||
const AnomalyEventsSchema = new Schema<TAnomalyEvents>({
|
||||
project_id: { type: Types.ObjectId, required: true },
|
||||
eventDate: { type: String, required: true },
|
||||
created_at: { type: Date, required: true },
|
||||
})
|
||||
|
||||
export const AnomalyEventsModel = model<TAnomalyEvents>('anomaly_events', AnomalyEventsSchema);
|
||||
16
shared/schema/anomalies/AnomalyVisitSchema.ts
Normal file
16
shared/schema/anomalies/AnomalyVisitSchema.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
|
||||
export type TAnomalyVisit = {
|
||||
project_id: Schema.Types.ObjectId
|
||||
visitDate: string,
|
||||
created_at: Date
|
||||
}
|
||||
|
||||
const AnomalyVisitSchema = new Schema<TAnomalyVisit>({
|
||||
project_id: { type: Types.ObjectId, required: true },
|
||||
visitDate: { type: String, required: true },
|
||||
created_at: { type: Date, required: true },
|
||||
})
|
||||
|
||||
export const AnomalyVisitModel = model<TAnomalyVisit>('anomaly_visits', AnomalyVisitSchema);
|
||||
@@ -4,6 +4,8 @@ import { LIMIT_50_EMAIL } from './email_templates/Limit50Email';
|
||||
import { LIMIT_90_EMAIL } from './email_templates/Limit90Email';
|
||||
import { LIMIT_MAX_EMAIL } from './email_templates/LimitMaxEmail';
|
||||
import { PURCHASE_EMAIL } from './email_templates/PurchaseEmail';
|
||||
import { ANOMALY_VISITS_EVENTS_EMAIL } from './email_templates/AnomalyUsageEmail';
|
||||
import { ANOMALY_DOMAIN_EMAIL } from './email_templates/AnomalyDomainEmail';
|
||||
|
||||
|
||||
class EmailService {
|
||||
@@ -99,6 +101,40 @@ class EmailService {
|
||||
}
|
||||
}
|
||||
|
||||
async sendAnomalyVisitsEventsEmail(target: string, projectName: string) {
|
||||
try {
|
||||
const sendSmtpEmail = new SendSmtpEmail();
|
||||
sendSmtpEmail.subject = "🚨 Unexpected Activity Detected by our AI";
|
||||
sendSmtpEmail.sender = { "name": "Litlyx", "email": "help@litlyx.com" };
|
||||
sendSmtpEmail.to = [{ "email": target }];
|
||||
sendSmtpEmail.htmlContent = ANOMALY_VISITS_EVENTS_EMAIL
|
||||
.replace(/\[Project Name\]/, projectName)
|
||||
.toString();;
|
||||
await this.apiInstance.sendTransacEmail(sendSmtpEmail);
|
||||
return true;
|
||||
} catch (ex) {
|
||||
console.error('ERROR SENDING EMAIL', ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async sendAnomalyDomainEmail(target: string, projectName: string) {
|
||||
try {
|
||||
const sendSmtpEmail = new SendSmtpEmail();
|
||||
sendSmtpEmail.subject = "🚨 Anomaly detected by our AI";
|
||||
sendSmtpEmail.sender = { "name": "Litlyx", "email": "help@litlyx.com" };
|
||||
sendSmtpEmail.to = [{ "email": target }];
|
||||
sendSmtpEmail.htmlContent = ANOMALY_DOMAIN_EMAIL
|
||||
.replace(/\[Project Name\]/, projectName)
|
||||
.toString();;
|
||||
await this.apiInstance.sendTransacEmail(sendSmtpEmail);
|
||||
return true;
|
||||
} catch (ex) {
|
||||
console.error('ERROR SENDING EMAIL', ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const instance = new EmailService();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
export const ANOMALY_DOMAIN_EMAIL = `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
@@ -9,17 +9,12 @@
|
||||
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333;">
|
||||
|
||||
<!-- Email Content -->
|
||||
<h2 style="color: #D32F2F;">❗️ Anomaly detected by our AI</h2>
|
||||
|
||||
<p>Dear User,</p>
|
||||
|
||||
<p>We wanted to let you know that <strong>[Project Name]</strong> on <strong>Litlyx</strong> has an anomaly that our AI agent detected. Here is the report:</p>
|
||||
<p>We wanted to let you know that <strong>[Project Name]</strong> on <strong>Litlyx</strong> has an anomaly that our AI agent detected.</p>
|
||||
|
||||
<p><strong>Anomaly:</strong> Suspicious DNS</p>
|
||||
<p><strong>Message:</strong> [Suspicious DNS name] is logging data in your project. Is that you?</p>
|
||||
<p><strong>Date:</strong> Current date!</p>
|
||||
|
||||
<p>You can analyze the suspicious DNS on your Litlyx dashboard. We put a symbol next to each suspicious DNS to let users know something might be wrong!</p>
|
||||
<p>You can analyze a suspicious DNS on your Litlyx dashboard. We put a symbol next to each suspicious DNS to let users know something might be wrong!</p>
|
||||
|
||||
<h3>What can I do?</h3>
|
||||
|
||||
@@ -45,3 +40,4 @@
|
||||
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
export const ANOMALY_VISITS_EVENTS_EMAIL = `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
@@ -9,7 +9,6 @@
|
||||
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333;">
|
||||
|
||||
<!-- Email Content -->
|
||||
<h2 style="color: #D32F2F;">🚨 Unexpected Activity Detected by our AI</h2>
|
||||
|
||||
<p>Dear User,</p>
|
||||
|
||||
@@ -40,3 +39,4 @@
|
||||
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
Reference in New Issue
Block a user