@b2y/email-service 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,39 @@
1
+ const StatusMessage = {
2
+ // Database messages
3
+ DB_CONNECTION_SUCCESS: 'Database connection has been established successfully.',
4
+ DB_CONNECTION_FAILED: 'Unable to connect to the database:',
5
+
6
+ // Email provider messages
7
+ PROVIDER_NOT_IMPLEMENTED: 'sendEmail method not implemented in BaseProvider',
8
+ PROVIDER_DEFAULT_FALLBACK: 'No valid provider specified, defaulting to Nodemailer',
9
+
10
+ // Validation messages
11
+ RECIPIENTS_REQUIRED: 'Recipients (to) are required',
12
+ SUBJECT_REQUIRED: 'Subject is required',
13
+ HTML_CONTENT_REQUIRED: 'Email content (html) is required',
14
+ TENANT_ID_REQUIRED: 'TenantID is required',
15
+ TEMPLATE_OR_HTML_REQUIRED: 'TemplateName or HTML content is required',
16
+ LANGCODE_IS_REQUIRED: 'Language code (langCode) is required',
17
+
18
+ // Template messages
19
+ TEMPLATE_NOT_FOUND: 'Template "${templateName}" not found for tenant ${tenantId}',
20
+ TEMPLATE_FETCH_ERROR: 'Error fetching template from DB: ${errorMessage}',
21
+ TEMPLATE_COMPILE_ERROR: 'Error compiling template "${templateName}": ${errorMessage}',
22
+ PLACEHOLDER_REPLACE_ERROR: 'Error replacing placeholders: ${errorMessage}',
23
+
24
+ // Email sending messages
25
+ EMAIL_SENT_SUCCESS: 'Email sent successfully for tenant: ${tenantId}',
26
+ EMAIL_SEND_FAILED: 'Failed to send email for tenant ${tenantId}: ${errorMessage}',
27
+
28
+ // Service initialization messages
29
+ PROVIDER_REQUIRED: 'Email provider is required',
30
+ DB_CLIENT_REQUIRED: 'Database client is required',
31
+ CANNOT_INSTANTIATE_BASE: 'Cannot instantiate BaseProvider directly',
32
+
33
+ NODEMAILER_SEND_ERROR:'Nodemailer failed to send email',
34
+ POSTMARK_SEND_ERROR:'Postmark failed to send email',
35
+ SENDGRID_SEND_ERROR:'SendGrid failed to send email',
36
+ AMAZON_SES_SEND_ERROR: 'Amazon SES failed to send email'
37
+ };
38
+
39
+ module.exports = StatusMessage;
@@ -0,0 +1,8 @@
1
+ const EmailProvider = {
2
+ NODE_MAILER: 'nodemailer',
3
+ SENDGRID: 'sendgrid',
4
+ POSTMARK: 'postmark',
5
+ AMAZON_SES: 'amazonses'
6
+ };
7
+
8
+ module.exports = { EmailProvider };
@@ -0,0 +1,24 @@
1
+ const { Sequelize } = require('sequelize');
2
+ const Config = require('../Config');
3
+
4
+ const sequelize = new Sequelize({
5
+ database: Config.dbName,
6
+ username: Config.dbUser,
7
+ password: Config.dbPass,
8
+ host: Config.dbHost,
9
+ port: Config.dbPort,
10
+ dialect: 'postgres',
11
+ schema: Config.dbschema,
12
+ logging: false,
13
+ define: {
14
+ timestamps: false,
15
+ freezeTableName: true
16
+ }
17
+ });
18
+
19
+ const EmailTemplate = require('./EmailTemplate')(sequelize);
20
+
21
+ module.exports = {
22
+ sequelize,
23
+ EmailTemplate
24
+ };
@@ -0,0 +1,51 @@
1
+ const { DataTypes } = require('sequelize');
2
+ require('dotenv').config();
3
+
4
+ module.exports = (sequelize) => {
5
+ return sequelize.define('EmailTemplate', {
6
+ TemplateID: {
7
+ type: DataTypes.INTEGER,
8
+ autoIncrement: true,
9
+ primaryKey: true,
10
+ },
11
+ TemplateName: {
12
+ type: DataTypes.STRING(100),
13
+ allowNull: false,
14
+ unique: true,
15
+ },
16
+ TenantId: {
17
+ type: DataTypes.INTEGER,
18
+ allowNull: false
19
+ },
20
+ LangCode: {
21
+ type: DataTypes.STRING(10),
22
+ allowNull: false,
23
+ defaultValue: 'en',
24
+ },
25
+ Subject: {
26
+ type: DataTypes.STRING(255),
27
+ allowNull: false,
28
+ },
29
+ Body: {
30
+ type: DataTypes.TEXT,
31
+ allowNull: false,
32
+ },
33
+ CreatedBy: {
34
+ type: DataTypes.STRING,
35
+ },
36
+ CreatedAt: {
37
+ type: DataTypes.DATE,
38
+ defaultValue: DataTypes.NOW,
39
+ },
40
+ UpdatedBy: {
41
+ type: DataTypes.STRING,
42
+ },
43
+ UpdatedAt: {
44
+ type: DataTypes.DATE,
45
+ defaultValue: DataTypes.NOW,
46
+ }
47
+ }, {
48
+ tableName: 'EmailTemplate',
49
+ timestamps: false,
50
+ });
51
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b2y/email-service",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "main": "index.js",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -15,6 +15,9 @@
15
15
  "providers/",
16
16
  "templates/",
17
17
  "utils/",
18
+ "constants/",
19
+ "enum",
20
+ "model",
18
21
  "*.js"
19
22
  ],
20
23
  "scripts": {