@lobb-js/lobb-ext-mail 0.5.1 → 0.5.2
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobb-js/lobb-ext-mail",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"test": "bun run test:lobb",
|
|
22
|
-
"test:lobb": "bun test
|
|
22
|
+
"test:lobb": "bun test tests",
|
|
23
23
|
"dev": "bun run --watch lobb.ts",
|
|
24
24
|
"dev:studio": "vite dev",
|
|
25
25
|
"build": "vite build",
|
|
@@ -31,11 +31,12 @@
|
|
|
31
31
|
"postpublish": "lobb-ext-postpublish"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@lobb-js/core": "^0.
|
|
34
|
+
"@lobb-js/core": "^0.44.0",
|
|
35
35
|
"nodemailer": "^6.9.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@
|
|
38
|
+
"@sveltejs/vite-plugin-svelte": "^7.1.2",
|
|
39
|
+
"@lobb-js/studio": "^0.53.1",
|
|
39
40
|
"@sveltejs/package": "^2.5.7",
|
|
40
41
|
"@sveltejs/adapter-node": "^5.5.4",
|
|
41
42
|
"@sveltejs/kit": "^2.60.1",
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { Config } from "@lobb-js/core";
|
|
2
|
-
import { mail } from "../../index.ts";
|
|
3
|
-
|
|
4
|
-
export const mailConfig: Config = {
|
|
5
|
-
project: {
|
|
6
|
-
name: "MyApp",
|
|
7
|
-
force_sync: true,
|
|
8
|
-
support_email: "support@myapp.com",
|
|
9
|
-
},
|
|
10
|
-
database: {
|
|
11
|
-
host: "localhost",
|
|
12
|
-
port: 5432,
|
|
13
|
-
username: "test",
|
|
14
|
-
password: "test",
|
|
15
|
-
database: "*",
|
|
16
|
-
},
|
|
17
|
-
web_server: {
|
|
18
|
-
host: "0.0.0.0",
|
|
19
|
-
port: 0,
|
|
20
|
-
},
|
|
21
|
-
extensions: [
|
|
22
|
-
mail({
|
|
23
|
-
transporter: {
|
|
24
|
-
host: "127.0.0.1",
|
|
25
|
-
port: 2525,
|
|
26
|
-
secure: false,
|
|
27
|
-
ignoreTLS: true,
|
|
28
|
-
},
|
|
29
|
-
}),
|
|
30
|
-
],
|
|
31
|
-
collections: {
|
|
32
|
-
articles: {
|
|
33
|
-
indexes: {},
|
|
34
|
-
fields: {
|
|
35
|
-
id: { type: "integer" },
|
|
36
|
-
title: {
|
|
37
|
-
type: "string",
|
|
38
|
-
length: 255,
|
|
39
|
-
},
|
|
40
|
-
body: {
|
|
41
|
-
type: "string",
|
|
42
|
-
length: 255,
|
|
43
|
-
},
|
|
44
|
-
published: { type: "bool" },
|
|
45
|
-
number_of_likes: { type: "integer" },
|
|
46
|
-
user_id: { type: "integer" },
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Lobb } from "@lobb-js/core";
|
|
2
|
-
import { expect } from "bun:test";
|
|
3
|
-
import { SmtpServer } from "./smtpServer.ts";
|
|
4
|
-
import { afterAll, beforeAll, describe, it } from "bun:test";
|
|
5
|
-
import { mailConfig } from "./configs/mail.ts";
|
|
6
|
-
|
|
7
|
-
describe("Mail Operations", () => {
|
|
8
|
-
let lobb: Lobb;
|
|
9
|
-
|
|
10
|
-
beforeAll(async () => {
|
|
11
|
-
await SmtpServer.init();
|
|
12
|
-
lobb = await Lobb.init(mailConfig);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
afterAll(async () => {
|
|
16
|
-
await lobb.close();
|
|
17
|
-
await SmtpServer.close();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("mail should be sent successfully", async () => {
|
|
21
|
-
await lobb.eventSystem.emit("mail.send", {
|
|
22
|
-
from: "sender@example.com",
|
|
23
|
-
to: "recipient@example.com",
|
|
24
|
-
subject: "Test email",
|
|
25
|
-
text: "test email from the unit tests",
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const receivedMail = SmtpServer.getReceivedMail();
|
|
29
|
-
|
|
30
|
-
expect(receivedMail.subject).toBe("Test email");
|
|
31
|
-
expect(receivedMail.text).toBe("test email from the unit tests\n");
|
|
32
|
-
});
|
|
33
|
-
});
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { SMTPServer } from "smtp-server";
|
|
2
|
-
import { simpleParser } from "mailparser";
|
|
3
|
-
|
|
4
|
-
function sleep(ms: number) {
|
|
5
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export class SmtpServer {
|
|
9
|
-
private static server: SMTPServer | null = null;
|
|
10
|
-
public static receivedMail: any;
|
|
11
|
-
|
|
12
|
-
static init(): Promise<void> {
|
|
13
|
-
return new Promise((resolve, reject) => {
|
|
14
|
-
this.server = new SMTPServer({
|
|
15
|
-
authOptional: true,
|
|
16
|
-
closeTimeout: 100,
|
|
17
|
-
onData(stream: any, session: any, callback: any) {
|
|
18
|
-
simpleParser(stream, {}, (err: any, parsed: any) => {
|
|
19
|
-
if (err) {
|
|
20
|
-
console.error("Error parsing email:", err);
|
|
21
|
-
return callback(err); // Call callback with error if parsing fails
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Store the received mail
|
|
25
|
-
SmtpServer.receivedMail = parsed;
|
|
26
|
-
|
|
27
|
-
// Call the callback to signal that the data has been processed
|
|
28
|
-
callback(null, "Message accepted"); // Accept the message
|
|
29
|
-
});
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
this.server.listen(2525, (err: any) => {
|
|
34
|
-
if (err) {
|
|
35
|
-
return reject(err);
|
|
36
|
-
}
|
|
37
|
-
console.log("Mail server listening on port 2525");
|
|
38
|
-
resolve();
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public static getReceivedMail() {
|
|
44
|
-
return this.receivedMail;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
public static async close(): Promise<void> {
|
|
48
|
-
await sleep(0);
|
|
49
|
-
return new Promise((resolve, reject) => {
|
|
50
|
-
this.server.close((err: any) => {
|
|
51
|
-
if (err) {
|
|
52
|
-
return reject(err);
|
|
53
|
-
}
|
|
54
|
-
this.receivedMail = null;
|
|
55
|
-
this.server = null;
|
|
56
|
-
resolve();
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|