@openinc/parse-server-opendash 3.28.0 → 3.29.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/dist/features/config/helper/customOptions.js +1 -8
- package/dist/features/notifications/index.d.ts +3 -0
- package/dist/features/notifications/index.js +8 -1
- package/dist/features/notifications/services/initEmailTransport.d.ts +1 -0
- package/dist/features/notifications/services/initEmailTransport.js +50 -0
- package/dist/features/notifications/services/sendMails.d.ts +21 -0
- package/dist/features/notifications/services/sendMails.js +83 -0
- package/dist/features/notifications/states/EmailState.d.ts +39 -0
- package/dist/features/notifications/states/EmailState.js +58 -0
- package/dist/functions/openinc-auth-email-confirmation-request.js +2 -2
- package/dist/functions/openinc-auth-login-passwordless.js +2 -2
- package/dist/functions/openinc-auth-password-reset-request.js +2 -2
- package/dist/functions/openinc-mail-test.js +2 -2
- package/dist/hooks/Core_Email.d.ts +0 -10
- package/dist/hooks/Core_Email.js +3 -79
- package/dist/hooks/Notification.js +2 -1
- package/dist/hooks/_User.js +3 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -7
- package/package.json +1 -1
|
@@ -276,14 +276,7 @@ exports.customoptions = {
|
|
|
276
276
|
public: true,
|
|
277
277
|
default: "false",
|
|
278
278
|
description: "Enable SMTP for sending e-mails.",
|
|
279
|
-
dependencies: [
|
|
280
|
-
"SMTP_HOST",
|
|
281
|
-
"SMTP_PORT",
|
|
282
|
-
"SMTP_USER",
|
|
283
|
-
"SMTP_PASS",
|
|
284
|
-
"SMTP_FROM",
|
|
285
|
-
"SMTP_SECURE",
|
|
286
|
-
],
|
|
279
|
+
dependencies: ["SMTP_HOST", "SMTP_PORT", "SMTP_FROM", "SMTP_SECURE"],
|
|
287
280
|
},
|
|
288
281
|
SMTP_HOST: {
|
|
289
282
|
env: "OPENINC_PARSE_SMTP_HOST",
|
|
@@ -2,3 +2,6 @@ export { FunctionKeys, NotificationInterface, NotificationMap, } from "./types/N
|
|
|
2
2
|
export { Notifications } from "./types/Notifications";
|
|
3
3
|
export { RegisteredNotification } from "./states/NotificationClass";
|
|
4
4
|
export { getAllNotifications, default as initNotifications, } from "./services/registerNotification";
|
|
5
|
+
export { EmailState } from "./states/EmailState";
|
|
6
|
+
export { sendSimpleEmail, sendTemplateEmail } from "./services/sendMails";
|
|
7
|
+
export { initEmailTransport } from "./services/initEmailTransport";
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.initNotifications = exports.getAllNotifications = exports.RegisteredNotification = exports.Notifications = void 0;
|
|
6
|
+
exports.initEmailTransport = exports.sendTemplateEmail = exports.sendSimpleEmail = exports.EmailState = exports.initNotifications = exports.getAllNotifications = exports.RegisteredNotification = exports.Notifications = void 0;
|
|
7
7
|
var Notifications_1 = require("./types/Notifications");
|
|
8
8
|
Object.defineProperty(exports, "Notifications", { enumerable: true, get: function () { return Notifications_1.Notifications; } });
|
|
9
9
|
var NotificationClass_1 = require("./states/NotificationClass");
|
|
@@ -11,3 +11,10 @@ Object.defineProperty(exports, "RegisteredNotification", { enumerable: true, get
|
|
|
11
11
|
var registerNotification_1 = require("./services/registerNotification");
|
|
12
12
|
Object.defineProperty(exports, "getAllNotifications", { enumerable: true, get: function () { return registerNotification_1.getAllNotifications; } });
|
|
13
13
|
Object.defineProperty(exports, "initNotifications", { enumerable: true, get: function () { return __importDefault(registerNotification_1).default; } });
|
|
14
|
+
var EmailState_1 = require("./states/EmailState");
|
|
15
|
+
Object.defineProperty(exports, "EmailState", { enumerable: true, get: function () { return EmailState_1.EmailState; } });
|
|
16
|
+
var sendMails_1 = require("./services/sendMails");
|
|
17
|
+
Object.defineProperty(exports, "sendSimpleEmail", { enumerable: true, get: function () { return sendMails_1.sendSimpleEmail; } });
|
|
18
|
+
Object.defineProperty(exports, "sendTemplateEmail", { enumerable: true, get: function () { return sendMails_1.sendTemplateEmail; } });
|
|
19
|
+
var initEmailTransport_1 = require("./services/initEmailTransport");
|
|
20
|
+
Object.defineProperty(exports, "initEmailTransport", { enumerable: true, get: function () { return initEmailTransport_1.initEmailTransport; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function initEmailTransport(): Promise<void>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.initEmailTransport = initEmailTransport;
|
|
7
|
+
const nodemailer_1 = __importDefault(require("nodemailer"));
|
|
8
|
+
const nunjucks_1 = __importDefault(require("nunjucks"));
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const __1 = require("..");
|
|
11
|
+
const config_1 = require("../../config");
|
|
12
|
+
async function initEmailTransport() {
|
|
13
|
+
try {
|
|
14
|
+
if (config_1.ConfigInstance.getInstance().getBoolean("SMTP_ENABLED")) {
|
|
15
|
+
const emailState = __1.EmailState.getInstance();
|
|
16
|
+
console.log("[@openinc/parse-server-opendash] Initializing email transport...");
|
|
17
|
+
const transportOptions = {
|
|
18
|
+
host: config_1.ConfigInstance.getInstance().get("SMTP_HOST"),
|
|
19
|
+
port: config_1.ConfigInstance.getInstance().getNumber("SMTP_PORT"),
|
|
20
|
+
secure: config_1.ConfigInstance.getInstance().getBoolean("SMTP_SECURE"),
|
|
21
|
+
ignoreTLS: config_1.ConfigInstance.getInstance().getBoolean("SMTP_IGNORE_TLS"),
|
|
22
|
+
};
|
|
23
|
+
if (config_1.ConfigInstance.getInstance().get("SMTP_USER") &&
|
|
24
|
+
config_1.ConfigInstance.getInstance().get("SMTP_PASS")) {
|
|
25
|
+
transportOptions.auth = {
|
|
26
|
+
user: config_1.ConfigInstance.getInstance().get("SMTP_USER"),
|
|
27
|
+
pass: config_1.ConfigInstance.getInstance().get("SMTP_PASS"),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const transport = nodemailer_1.default.createTransport(transportOptions);
|
|
31
|
+
if (config_1.ConfigInstance.getInstance().get("SMTP_USER") &&
|
|
32
|
+
config_1.ConfigInstance.getInstance().get("SMTP_PASS")) {
|
|
33
|
+
console.log("[@openinc/parse-server-opendash] Verifying SMTP transport...");
|
|
34
|
+
await transport.verify();
|
|
35
|
+
}
|
|
36
|
+
emailState.setTransport(transport);
|
|
37
|
+
const templateDir = (0, path_1.resolve)(process.cwd(), config_1.ConfigInstance.getInstance().get("EMAIL_TEMPLATE_DIR"));
|
|
38
|
+
emailState.setEmailTemplateDir(templateDir);
|
|
39
|
+
nunjucks_1.default.configure(templateDir, { autoescape: true });
|
|
40
|
+
console.log("[@openinc/parse-server-opendash] Email transport initialized successfully");
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
console.log("[@openinc/parse-server-opendash] SMTP disabled, skipping email transport initialization");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
console.error(`Parse SMTP Adapter: Error when trying to establish the SMTP connection:`);
|
|
48
|
+
console.error(error);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Core_Email } from "../../../types";
|
|
2
|
+
/**
|
|
3
|
+
* Send a simple email
|
|
4
|
+
* @param to The recipient email address
|
|
5
|
+
* @param subject The subject of the email
|
|
6
|
+
* @param text The plain text content of the email
|
|
7
|
+
* @returns The saved email object
|
|
8
|
+
*/
|
|
9
|
+
export declare function sendSimpleEmail(to: string, subject: string, text: string): Promise<Core_Email>;
|
|
10
|
+
/**
|
|
11
|
+
* Send a template email
|
|
12
|
+
* @param param0
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export declare function sendTemplateEmail({ to, subject, fallback, template, data, }: {
|
|
16
|
+
to: string;
|
|
17
|
+
subject: string;
|
|
18
|
+
fallback: string;
|
|
19
|
+
template: string;
|
|
20
|
+
data: any;
|
|
21
|
+
}): Promise<Core_Email>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.sendSimpleEmail = sendSimpleEmail;
|
|
7
|
+
exports.sendTemplateEmail = sendTemplateEmail;
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const nunjucks_1 = __importDefault(require("nunjucks"));
|
|
10
|
+
const path_1 = require("path");
|
|
11
|
+
const types_1 = require("../../../types");
|
|
12
|
+
const EmailState_1 = require("../states/EmailState");
|
|
13
|
+
/**
|
|
14
|
+
* Send a simple email
|
|
15
|
+
* @param to The recipient email address
|
|
16
|
+
* @param subject The subject of the email
|
|
17
|
+
* @param text The plain text content of the email
|
|
18
|
+
* @returns The saved email object
|
|
19
|
+
*/
|
|
20
|
+
async function sendSimpleEmail(to, subject, text) {
|
|
21
|
+
const email = new types_1.Core_Email({
|
|
22
|
+
payload: {
|
|
23
|
+
to,
|
|
24
|
+
subject,
|
|
25
|
+
text,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
await email.save(null, { useMasterKey: true });
|
|
29
|
+
return email;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Send a template email
|
|
33
|
+
* @param param0
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
async function sendTemplateEmail({ to, subject, fallback, template, data, }) {
|
|
37
|
+
const email = new types_1.Core_Email({
|
|
38
|
+
payload: {
|
|
39
|
+
to,
|
|
40
|
+
subject: renderEmailTemplate("subject", template, data, subject),
|
|
41
|
+
text: renderEmailTemplate("txt", template, data, fallback),
|
|
42
|
+
html: renderEmailTemplate("html", template, data, undefined),
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
await email.save(null, { useMasterKey: true });
|
|
46
|
+
return email;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Validate if an email template exists in the specified directory
|
|
50
|
+
* @param templateDir The directory where email templates are stored
|
|
51
|
+
* @param template The specific template file to validate
|
|
52
|
+
* @returns Whether the template exists in the directory
|
|
53
|
+
*/
|
|
54
|
+
function validateEmailTemplate(templateDir, template) {
|
|
55
|
+
const templatePath = (0, path_1.join)(templateDir, template);
|
|
56
|
+
if (!fs_1.default.existsSync(templateDir)) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
if (!fs_1.default.existsSync(templatePath)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Render an email template
|
|
66
|
+
* @param type The type of the email template (txt, html, subject)
|
|
67
|
+
* @param template The base name of the template file
|
|
68
|
+
* @param data The data to be used for rendering the template
|
|
69
|
+
* @param fallback The fallback content if the template is not found
|
|
70
|
+
* @returns The rendered email content
|
|
71
|
+
*/
|
|
72
|
+
function renderEmailTemplate(type, template, data, fallback) {
|
|
73
|
+
const emailState = EmailState_1.EmailState.getInstance();
|
|
74
|
+
const emailTemplateDir = emailState.getEmailTemplateDir();
|
|
75
|
+
const fullTemplate = template + "." + type;
|
|
76
|
+
if (validateEmailTemplate(emailTemplateDir, fullTemplate)) {
|
|
77
|
+
return nunjucks_1.default.render(fullTemplate, data);
|
|
78
|
+
}
|
|
79
|
+
if (type === "html") {
|
|
80
|
+
return renderEmailTemplate("txt", template, data, fallback);
|
|
81
|
+
}
|
|
82
|
+
return fallback || "";
|
|
83
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Transporter } from "nodemailer";
|
|
2
|
+
import SMTPTransport from "nodemailer/lib/smtp-transport";
|
|
3
|
+
/**
|
|
4
|
+
* Singleton class to manage email transport and template directory
|
|
5
|
+
*/
|
|
6
|
+
export declare class EmailState {
|
|
7
|
+
private static instance;
|
|
8
|
+
emailTemplateDir: string;
|
|
9
|
+
transport: Transporter<SMTPTransport.SentMessageInfo> | undefined;
|
|
10
|
+
private constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Get the singleton instance
|
|
13
|
+
*/
|
|
14
|
+
static getInstance(): EmailState;
|
|
15
|
+
/**
|
|
16
|
+
* Set the email transport
|
|
17
|
+
*/
|
|
18
|
+
setTransport(transport: Transporter<SMTPTransport.SentMessageInfo>): void;
|
|
19
|
+
/**
|
|
20
|
+
* Get the email transport
|
|
21
|
+
*/
|
|
22
|
+
getTransport(): Transporter<SMTPTransport.SentMessageInfo> | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Set the email template directory
|
|
25
|
+
*/
|
|
26
|
+
setEmailTemplateDir(dir: string): void;
|
|
27
|
+
/**
|
|
28
|
+
* Get the email template directory
|
|
29
|
+
*/
|
|
30
|
+
getEmailTemplateDir(): string;
|
|
31
|
+
/**
|
|
32
|
+
* Check if email transport is configured and ready
|
|
33
|
+
*/
|
|
34
|
+
isConfigured(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Reset the singleton (useful for testing)
|
|
37
|
+
*/
|
|
38
|
+
static reset(): void;
|
|
39
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmailState = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Singleton class to manage email transport and template directory
|
|
6
|
+
*/
|
|
7
|
+
class EmailState {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.emailTemplateDir = "";
|
|
10
|
+
this.transport = undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get the singleton instance
|
|
14
|
+
*/
|
|
15
|
+
static getInstance() {
|
|
16
|
+
if (!EmailState.instance) {
|
|
17
|
+
EmailState.instance = new EmailState();
|
|
18
|
+
}
|
|
19
|
+
return EmailState.instance;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Set the email transport
|
|
23
|
+
*/
|
|
24
|
+
setTransport(transport) {
|
|
25
|
+
this.transport = transport;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get the email transport
|
|
29
|
+
*/
|
|
30
|
+
getTransport() {
|
|
31
|
+
return this.transport;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Set the email template directory
|
|
35
|
+
*/
|
|
36
|
+
setEmailTemplateDir(dir) {
|
|
37
|
+
this.emailTemplateDir = dir;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get the email template directory
|
|
41
|
+
*/
|
|
42
|
+
getEmailTemplateDir() {
|
|
43
|
+
return this.emailTemplateDir;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if email transport is configured and ready
|
|
47
|
+
*/
|
|
48
|
+
isConfigured() {
|
|
49
|
+
return this.transport !== undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Reset the singleton (useful for testing)
|
|
53
|
+
*/
|
|
54
|
+
static reset() {
|
|
55
|
+
EmailState.instance = undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.EmailState = EmailState;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.init = init;
|
|
4
|
-
const
|
|
4
|
+
const notifications_1 = require("../features/notifications");
|
|
5
5
|
const transformLogin_1 = require("../helper/transformLogin");
|
|
6
6
|
const openinc_auth_common_1 = require("./openinc-auth.common");
|
|
7
7
|
async function init(name) {
|
|
@@ -14,7 +14,7 @@ async function init(name) {
|
|
|
14
14
|
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, "No user was found with the given email.");
|
|
15
15
|
}
|
|
16
16
|
const { url } = await (0, openinc_auth_common_1.createToken)("verify-email", user.id, request.params.url);
|
|
17
|
-
await (0,
|
|
17
|
+
await (0, notifications_1.sendTemplateEmail)({
|
|
18
18
|
template: "openinc-auth-email-confirmation",
|
|
19
19
|
subject: "E-Mail Bestätigung / Email confirmation",
|
|
20
20
|
to: email,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.init = init;
|
|
4
|
-
const
|
|
4
|
+
const notifications_1 = require("../features/notifications");
|
|
5
5
|
const transformLogin_1 = require("../helper/transformLogin");
|
|
6
6
|
const openinc_auth_common_1 = require("./openinc-auth.common");
|
|
7
7
|
async function init(name) {
|
|
@@ -22,7 +22,7 @@ async function init(name) {
|
|
|
22
22
|
});
|
|
23
23
|
const url = urlTemplate.replace("{{token}}", sessionToken);
|
|
24
24
|
console.log(url);
|
|
25
|
-
await (0,
|
|
25
|
+
await (0, notifications_1.sendTemplateEmail)({
|
|
26
26
|
template: "openinc-auth-login-passwordless",
|
|
27
27
|
subject: "Passwordless Login",
|
|
28
28
|
to: email,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.init = init;
|
|
4
|
-
const
|
|
4
|
+
const notifications_1 = require("../features/notifications");
|
|
5
5
|
const transformLogin_1 = require("../helper/transformLogin");
|
|
6
6
|
const openinc_auth_common_1 = require("./openinc-auth.common");
|
|
7
7
|
async function init(name) {
|
|
@@ -14,7 +14,7 @@ async function init(name) {
|
|
|
14
14
|
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, "No user was found with the given email.");
|
|
15
15
|
}
|
|
16
16
|
const { url } = await (0, openinc_auth_common_1.createToken)("password-reset", user.id, request.params.url);
|
|
17
|
-
await (0,
|
|
17
|
+
await (0, notifications_1.sendTemplateEmail)({
|
|
18
18
|
template: "openinc-auth-password-reset",
|
|
19
19
|
subject: "Passwort zurücksetzen / Password reset",
|
|
20
20
|
to: email,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.init = init;
|
|
4
|
-
const
|
|
4
|
+
const notifications_1 = require("../features/notifications");
|
|
5
5
|
async function init(name) {
|
|
6
6
|
// sendTestEmail - Sends a test email
|
|
7
7
|
Parse.Cloud.define(name, async (request) => {
|
|
@@ -9,7 +9,7 @@ async function init(name) {
|
|
|
9
9
|
return { message: "Unauthorized" };
|
|
10
10
|
}
|
|
11
11
|
const { to } = request.params;
|
|
12
|
-
const mail = await (0,
|
|
12
|
+
const mail = await (0, notifications_1.sendSimpleEmail)(to, "open.INC Test Mail", "This is a test email from open.INC Stack.");
|
|
13
13
|
return mail;
|
|
14
14
|
}, {
|
|
15
15
|
requireUser: true,
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
import { Core_Email } from "../types";
|
|
2
|
-
export declare function initEmailTransport(): Promise<void>;
|
|
3
|
-
export declare function sendSimpleEmail(to: string, subject: string, text: string): Promise<Core_Email>;
|
|
4
|
-
export declare function sendTemplateEmail({ to, subject, fallback, template, data, }: {
|
|
5
|
-
to: string;
|
|
6
|
-
subject: string;
|
|
7
|
-
fallback: string;
|
|
8
|
-
template: string;
|
|
9
|
-
data: any;
|
|
10
|
-
}): Promise<Core_Email>;
|
|
11
1
|
export declare function init(): Promise<void>;
|
package/dist/hooks/Core_Email.js
CHANGED
|
@@ -1,92 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.initEmailTransport = initEmailTransport;
|
|
7
|
-
exports.sendSimpleEmail = sendSimpleEmail;
|
|
8
|
-
exports.sendTemplateEmail = sendTemplateEmail;
|
|
9
3
|
exports.init = init;
|
|
10
|
-
const fs_1 = __importDefault(require("fs"));
|
|
11
|
-
const nodemailer_1 = __importDefault(require("nodemailer"));
|
|
12
|
-
const nunjucks_1 = __importDefault(require("nunjucks"));
|
|
13
|
-
const path_1 = require("path");
|
|
14
4
|
const __1 = require("..");
|
|
15
5
|
const config_1 = require("../features/config");
|
|
6
|
+
const notifications_1 = require("../features/notifications");
|
|
16
7
|
const types_1 = require("../types");
|
|
17
|
-
let emailTemplateDir = "";
|
|
18
|
-
let transport = undefined;
|
|
19
|
-
async function initEmailTransport() {
|
|
20
|
-
try {
|
|
21
|
-
if (config_1.ConfigInstance.getInstance().getBoolean("SMTP_ENABLED")) {
|
|
22
|
-
transport = nodemailer_1.default.createTransport({
|
|
23
|
-
host: config_1.ConfigInstance.getInstance().get("SMTP_HOST"),
|
|
24
|
-
port: config_1.ConfigInstance.getInstance().getNumber("SMTP_PORT"),
|
|
25
|
-
secure: config_1.ConfigInstance.getInstance().getBoolean("SMTP_SECURE"),
|
|
26
|
-
ignoreTLS: config_1.ConfigInstance.getInstance().getBoolean("SMTP_IGNORE_TLS"),
|
|
27
|
-
auth: {
|
|
28
|
-
user: config_1.ConfigInstance.getInstance().get("SMTP_USER"),
|
|
29
|
-
pass: config_1.ConfigInstance.getInstance().get("SMTP_PASS"),
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
await transport.verify();
|
|
33
|
-
emailTemplateDir = (0, path_1.resolve)(process.cwd(), config_1.ConfigInstance.getInstance().get("EMAIL_TEMPLATE_DIR"));
|
|
34
|
-
nunjucks_1.default.configure(emailTemplateDir, { autoescape: true });
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
console.error(`Parse SMTP Adapter: Error when trying to establish the SMTP connection:`);
|
|
39
|
-
console.error(error);
|
|
40
|
-
process.exit(1);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
async function sendSimpleEmail(to, subject, text) {
|
|
44
|
-
const email = new types_1.Core_Email({
|
|
45
|
-
payload: {
|
|
46
|
-
to,
|
|
47
|
-
subject,
|
|
48
|
-
text,
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
await email.save(null, { useMasterKey: true });
|
|
52
|
-
return email;
|
|
53
|
-
}
|
|
54
|
-
async function sendTemplateEmail({ to, subject, fallback, template, data, }) {
|
|
55
|
-
const email = new types_1.Core_Email({
|
|
56
|
-
payload: {
|
|
57
|
-
to,
|
|
58
|
-
subject: renderEmailTemplate("subject", template, data, subject),
|
|
59
|
-
text: renderEmailTemplate("txt", template, data, fallback),
|
|
60
|
-
html: renderEmailTemplate("html", template, data, undefined),
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
await email.save(null, { useMasterKey: true });
|
|
64
|
-
return email;
|
|
65
|
-
}
|
|
66
|
-
function validateEmailTemplate(templateDir, template) {
|
|
67
|
-
const templatePath = (0, path_1.join)(templateDir, template);
|
|
68
|
-
if (!fs_1.default.existsSync(templateDir)) {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
if (!fs_1.default.existsSync(templatePath)) {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
function renderEmailTemplate(type, template, data, fallback) {
|
|
77
|
-
const fullTemplate = template + "." + type;
|
|
78
|
-
if (validateEmailTemplate(emailTemplateDir, fullTemplate)) {
|
|
79
|
-
return nunjucks_1.default.render(fullTemplate, data);
|
|
80
|
-
}
|
|
81
|
-
if (type === "html") {
|
|
82
|
-
return renderEmailTemplate("txt", template, data, fallback);
|
|
83
|
-
}
|
|
84
|
-
return fallback || "";
|
|
85
|
-
}
|
|
86
8
|
async function init() {
|
|
87
9
|
(0, __1.beforeSaveHook)(types_1.Core_Email, async (request) => {
|
|
88
10
|
const { object } = request;
|
|
89
11
|
object.setACL(new Parse.ACL());
|
|
12
|
+
const emailState = notifications_1.EmailState.getInstance();
|
|
13
|
+
const transport = emailState.getTransport();
|
|
90
14
|
if (!transport) {
|
|
91
15
|
object.sent = false;
|
|
92
16
|
object.success = false;
|
|
@@ -7,6 +7,7 @@ exports.init = init;
|
|
|
7
7
|
const web_push_1 = __importDefault(require("web-push"));
|
|
8
8
|
const __1 = require("..");
|
|
9
9
|
const config_1 = require("../features/config");
|
|
10
|
+
const notifications_1 = require("../features/notifications");
|
|
10
11
|
const types_1 = require("../types");
|
|
11
12
|
async function init() {
|
|
12
13
|
(0, __1.beforeSaveHook)(types_1.Notification, async (request) => {
|
|
@@ -32,7 +33,7 @@ async function init() {
|
|
|
32
33
|
body += config_1.ConfigInstance.getInstance().get("APP_URL");
|
|
33
34
|
body += object.get("data")?.url;
|
|
34
35
|
}
|
|
35
|
-
await (0,
|
|
36
|
+
await (0, notifications_1.sendSimpleEmail)(email, title, body);
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
// Handle Push
|
package/dist/hooks/_User.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.init = init;
|
|
4
4
|
const __1 = require("..");
|
|
5
5
|
const config_1 = require("../features/config");
|
|
6
|
+
const notifications_1 = require("../features/notifications");
|
|
6
7
|
const settings_1 = require("../features/user/settings");
|
|
7
8
|
const transformLogin_1 = require("../helper/transformLogin");
|
|
8
9
|
const types_1 = require("../types");
|
|
@@ -111,7 +112,7 @@ async function init() {
|
|
|
111
112
|
.equalTo("tenantAdmin", true)
|
|
112
113
|
.findAll({ useMasterKey: true });
|
|
113
114
|
for (const admin of admins) {
|
|
114
|
-
await (0,
|
|
115
|
+
await (0, notifications_1.sendTemplateEmail)({
|
|
115
116
|
template: "openinc-auth-tenant-verification-request",
|
|
116
117
|
subject: "Ein neuer Nutzer muss verifiziert werden",
|
|
117
118
|
to: admin.get("email"),
|
|
@@ -126,7 +127,7 @@ async function init() {
|
|
|
126
127
|
object.get("tenantVerified") === true) {
|
|
127
128
|
const email = object.get("email");
|
|
128
129
|
verificationEmailCache[object.id] = true;
|
|
129
|
-
await (0,
|
|
130
|
+
await (0, notifications_1.sendTemplateEmail)({
|
|
130
131
|
template: "openinc-auth-tenant-verification",
|
|
131
132
|
subject: "Dein Account wurde verifiziert",
|
|
132
133
|
to: email,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Cloud as ParseCloud } from "parse";
|
|
2
2
|
import { Permission } from "./types";
|
|
3
|
-
export { sendSimpleEmail, sendTemplateEmail } from "./hooks/Core_Email";
|
|
4
3
|
/**
|
|
5
4
|
* Initializes the Cloud Code for open.DASH.
|
|
6
5
|
* This function performs various initialization tasks such as
|
|
@@ -194,3 +193,4 @@ export declare function autoloadCloudCode(path: string, regex?: RegExp): Promise
|
|
|
194
193
|
* @returns The updated or newly created permission.
|
|
195
194
|
*/
|
|
196
195
|
export declare function ensurePermission(key: string, acl?: Parse.ACL): Promise<Permission>;
|
|
196
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.sendTemplateEmail = exports.sendSimpleEmail = void 0;
|
|
7
6
|
exports.init = init;
|
|
8
7
|
exports.hasPermission = hasPermission;
|
|
9
8
|
exports.requirePermission = requirePermission;
|
|
@@ -38,7 +37,6 @@ const types_1 = require("./types");
|
|
|
38
37
|
const notifications_1 = require("./features/notifications");
|
|
39
38
|
const permissions_1 = require("./features/permissions");
|
|
40
39
|
const settings_1 = require("./features/user/settings");
|
|
41
|
-
const Core_Email_1 = require("./hooks/Core_Email");
|
|
42
40
|
const importDocs_1 = require("./features/documentation/functions/importDocs");
|
|
43
41
|
const openservice_1 = require("./features/openservice");
|
|
44
42
|
const translations_1 = require("./features/translations");
|
|
@@ -49,12 +47,8 @@ dayjs_1.default.extend(weekday_1.default);
|
|
|
49
47
|
dayjs_1.default.extend(dayOfYear_1.default);
|
|
50
48
|
dayjs_1.default.extend(weekOfYear_1.default);
|
|
51
49
|
dayjs_1.default.extend(duration_1.default);
|
|
52
|
-
var Core_Email_2 = require("./hooks/Core_Email");
|
|
53
|
-
Object.defineProperty(exports, "sendSimpleEmail", { enumerable: true, get: function () { return Core_Email_2.sendSimpleEmail; } });
|
|
54
|
-
Object.defineProperty(exports, "sendTemplateEmail", { enumerable: true, get: function () { return Core_Email_2.sendTemplateEmail; } });
|
|
55
50
|
const PREFIX = "OD3_";
|
|
56
51
|
let config;
|
|
57
|
-
// const lang_deu = require("../i18n/deu.json");
|
|
58
52
|
let schema = {};
|
|
59
53
|
/**
|
|
60
54
|
* Initializes the Cloud Code for open.DASH.
|
|
@@ -85,7 +79,7 @@ async function init() {
|
|
|
85
79
|
config = config_1.ConfigInstance.getInstance();
|
|
86
80
|
await config.init(true);
|
|
87
81
|
await (0, translations_1.initTranslations)();
|
|
88
|
-
await (0,
|
|
82
|
+
await (0, notifications_1.initEmailTransport)();
|
|
89
83
|
await initWebPush();
|
|
90
84
|
await initSchema();
|
|
91
85
|
await initDefaultRoles();
|