@tomei/mailer 0.0.1
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.
- package/Jenkinsfile +41 -0
- package/package.json +23 -0
- package/src/index.ts +1 -0
- package/src/interfaces/index.ts +1 -0
- package/src/interfaces/mail-configuration.interface.ts +9 -0
- package/src/mailer/index.ts +2 -0
- package/src/mailer/mailer.ts +61 -0
- package/tsconfig.build.json +4 -0
- package/tsconfig.json +22 -0
package/Jenkinsfile
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
pipeline {
|
|
2
|
+
agent any
|
|
3
|
+
tools {nodejs "node18"}
|
|
4
|
+
stages {
|
|
5
|
+
stage('Install') {
|
|
6
|
+
steps {
|
|
7
|
+
echo 'Install Dependencies..'
|
|
8
|
+
sh 'npm install'
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
stage('Build') {
|
|
12
|
+
steps {
|
|
13
|
+
echo 'Building..'
|
|
14
|
+
sh 'npm run build'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
// stage('Publish') {
|
|
18
|
+
// steps {
|
|
19
|
+
// echo 'Publish..'
|
|
20
|
+
// sh "npm set //registry.npmjs.org/:_authToken=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"
|
|
21
|
+
// sh "npm publish"
|
|
22
|
+
// }
|
|
23
|
+
// }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
post {
|
|
27
|
+
success {
|
|
28
|
+
script {
|
|
29
|
+
def gitAuthor = sh(returnStdout: true, script: 'git log -1 --pretty=format:%an').trim()
|
|
30
|
+
discordSend description: "Git Commit: ${env.GIT_COMMIT}\nGit Branch: ${env.GIT_BRANCH}\nGit URL: ${env.GIT_URL}\nGit Author: ${gitAuthor}", footer: '', image: '', link: env.BUILD_URL, result: 'SUCCESS', scmWebUrl: '', thumbnail: '', title: "${env.JOB_NAME} Build #${env.BUILD_NUMBER} Success", webhookURL: 'https://discord.com/api/webhooks/1117763694252798014/X8IsR91wpgou9VDvkKOZRfTDpffFcMlurXdAzfntZ62uHVcbTDO9AtPOv4nBAkEYgaUo'
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
failure {
|
|
35
|
+
script {
|
|
36
|
+
def gitAuthor = sh(returnStdout: true, script: 'git log -1 --pretty=format:%an').trim()
|
|
37
|
+
discordSend description: "Git Commit: ${env.GIT_COMMIT}\nGit Branch: ${env.GIT_BRANCH}\nGit URL: ${env.GIT_URL}\nGit Author: ${gitAuthor}", footer: '', image: '', link: env.BUILD_URL, result: 'FAILURE', scmWebUrl: '', thumbnail: '', title: "${env.JOB_NAME} Build #${env.BUILD_NUMBER} Failed", webhookURL: 'https://discord.com/api/webhooks/1117763694252798014/X8IsR91wpgou9VDvkKOZRfTDpffFcMlurXdAzfntZ62uHVcbTDO9AtPOv4nBAkEYgaUo'
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tomei/mailer",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Tomei Mailer Package",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start:dev": "tsc -w",
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"prepare": "npm run build",
|
|
10
|
+
"test": "npm run test"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"author": "Tomei",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"ts-jest": "^29.1.0",
|
|
19
|
+
"ts-node": "^10.9.1",
|
|
20
|
+
"tsc-watch": "^6.0.4",
|
|
21
|
+
"typescript": "^5.1.3"
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './mailer'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './mail-configuration.interface'
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { MailConfig } from "../interfaces";
|
|
2
|
+
|
|
3
|
+
export default class Mailer {
|
|
4
|
+
private mailer: any;
|
|
5
|
+
|
|
6
|
+
constructor(mailer: any, config:MailConfig) {
|
|
7
|
+
this.mailer = mailer
|
|
8
|
+
this.configureMailer(config)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
private configureMailer(config: MailConfig): void {
|
|
12
|
+
// Set the configuration options for the mailer instance
|
|
13
|
+
// based on the provided configuration object
|
|
14
|
+
// Adjust this code according to the specific mailer library you're using
|
|
15
|
+
// For nodemailer library, it would be something like:
|
|
16
|
+
// this.mailer.createTransport({ host: config.host, port: config.port, secure: config.secure, auth: config.auth });
|
|
17
|
+
// For other mailer libraries, refer to their documentation
|
|
18
|
+
|
|
19
|
+
// Example using nodemailer library
|
|
20
|
+
this.mailer.configure({
|
|
21
|
+
host: config.host,
|
|
22
|
+
port: config.port,
|
|
23
|
+
secure: config.secure,
|
|
24
|
+
auth: config.auth,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async sendMail(
|
|
28
|
+
from: string,
|
|
29
|
+
to: string,
|
|
30
|
+
subject: string,
|
|
31
|
+
text: string,
|
|
32
|
+
): Promise<void> {
|
|
33
|
+
try {
|
|
34
|
+
await this.mailer.sendMail({
|
|
35
|
+
from,
|
|
36
|
+
to,
|
|
37
|
+
subject,
|
|
38
|
+
text,
|
|
39
|
+
});
|
|
40
|
+
} catch (error) {
|
|
41
|
+
// Retry once
|
|
42
|
+
try {
|
|
43
|
+
await this.mailer.sendMail({
|
|
44
|
+
from,
|
|
45
|
+
to,
|
|
46
|
+
subject,
|
|
47
|
+
text,
|
|
48
|
+
});
|
|
49
|
+
} catch (retryError) {
|
|
50
|
+
this.logError(retryError);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private logError(error: Error): void {
|
|
56
|
+
// Here, you can implement the logic to create a log folder and log file
|
|
57
|
+
// inside the other project, specifically for this package.
|
|
58
|
+
console.error('Error occurred while sending mail:', error);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"removeComments": true,
|
|
6
|
+
"emitDecoratorMetadata": true,
|
|
7
|
+
"experimentalDecorators": true,
|
|
8
|
+
"allowSyntheticDefaultImports": true,
|
|
9
|
+
"moduleResolution": "node",
|
|
10
|
+
"target": "es6",
|
|
11
|
+
"sourceMap": true,
|
|
12
|
+
"outDir": "./dist",
|
|
13
|
+
"baseUrl": "./",
|
|
14
|
+
"incremental": true,
|
|
15
|
+
"skipLibCheck": true,
|
|
16
|
+
"strictNullChecks": false,
|
|
17
|
+
"noImplicitAny": false,
|
|
18
|
+
"strictBindCallApply": false,
|
|
19
|
+
"forceConsistentCasingInFileNames": false,
|
|
20
|
+
"noFallthroughCasesInSwitch": false,
|
|
21
|
+
}
|
|
22
|
+
}
|