UNPKG

ses-mail-protector

Version:

Node.js library for AWS SES email sending with bounce & complaint handling using MongoDB.

65 lines (60 loc) 1.45 kB
require("dotenv/config"); const { Sequelize, DataTypes } = require("sequelize"); // Setup connection const sqlClient = new Sequelize( process.env.SQL_DB_NAME, process.env.SQL_DB_USER_NAME, process.env.SQL_DB_PASSWORD, { host: process.env.SQL_DB_HOST, // Change this if using remote DB dialect: process.env.SQL_DB_DIALECT, // Can be 'mysql' | 'postgres' | 'sqlite' | 'mariadb' | 'mssql' } ); sqlClient .authenticate() .then(() => { // console.log("✅ Connection has been established successfully."); }) .catch((err) => console.error("❌ Unable to connect to DB:", err)); const Suppression = sqlClient.define( "Suppression", { email: { type: DataTypes.STRING, primaryKey: true, allowNull: false, validate: { isEmail: true, }, }, type: { type: DataTypes.ENUM( "bounce", "complaint", "unsubscribe", "manual", "aws-suppressed" ), allowNull: false, }, details: { type: DataTypes.TEXT, allowNull: true, }, reason: { type: DataTypes.STRING, allowNull: true, }, createdAt: { type: DataTypes.DATE, defaultValue: DataTypes.NOW, }, }, { tableName: "suppressions", timestamps: false, freezeTableName: true, id: false, } ); module.exports = { sqlClient, Suppression };