@openinc/parse-server-opendash 3.29.0 → 3.29.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.
@@ -10,9 +10,10 @@ const path_1 = require("path");
10
10
  const __1 = require("..");
11
11
  const config_1 = require("../../config");
12
12
  async function initEmailTransport() {
13
- const emailState = __1.EmailState.getInstance();
14
13
  try {
15
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...");
16
17
  const transportOptions = {
17
18
  host: config_1.ConfigInstance.getInstance().get("SMTP_HOST"),
18
19
  port: config_1.ConfigInstance.getInstance().getNumber("SMTP_PORT"),
@@ -27,7 +28,11 @@ async function initEmailTransport() {
27
28
  };
28
29
  }
29
30
  const transport = nodemailer_1.default.createTransport(transportOptions);
30
- await transport.verify();
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
+ }
31
36
  emailState.setTransport(transport);
32
37
  const templateDir = (0, path_1.resolve)(process.cwd(), config_1.ConfigInstance.getInstance().get("EMAIL_TEMPLATE_DIR"));
33
38
  emailState.setEmailTemplateDir(templateDir);
@@ -49,6 +49,7 @@ async function assignUsersAndRoles(ticket, assignedTo, fetchOptions, assigningUs
49
49
  const userNotifiedIds = [];
50
50
  for await (const assignedTo of newUsers) {
51
51
  const resipientlanguage = await (0, getUserLanguage_1.getUserLanguage)(assignedTo);
52
+ const recipientlink = await (0, getTicketLink_1.getTicketLink)(ticket, assignedTo);
52
53
  await i18next_1.default.changeLanguage(resipientlanguage);
53
54
  assignments.push(new types_1.Maintenance_Ticket_Assignment({
54
55
  ticket,
@@ -74,7 +75,7 @@ async function assignUsersAndRoles(ticket, assignedTo, fetchOptions, assigningUs
74
75
  description: i18next_1.default.t("maintenance:ticket.assignuser.notification.description", {
75
76
  username: (0, openinc_openservice_save_ticket_data_1.getUsername)(assigningUser) ?? "System",
76
77
  ticketName: ticket.get("title"),
77
- ticketLink: (0, getTicketLink_1.getTicketLink)(ticket),
78
+ ticketLink: recipientlink,
78
79
  }),
79
80
  }).save(null, { useMasterKey: true });
80
81
  userNotifiedIds.push(assignedTo.id);
@@ -96,6 +97,7 @@ async function assignUsersAndRoles(ticket, assignedTo, fetchOptions, assigningUs
96
97
  roleUser.id === assigningUser?.id)
97
98
  continue;
98
99
  const resipientlanguage = await (0, getUserLanguage_1.getUserLanguage)(roleUser);
100
+ const recipientlink = await (0, getTicketLink_1.getTicketLink)(ticket, roleUser);
99
101
  await i18next_1.default.changeLanguage(resipientlanguage);
100
102
  await new types_1.Notification({
101
103
  data: {
@@ -114,7 +116,7 @@ async function assignUsersAndRoles(ticket, assignedTo, fetchOptions, assigningUs
114
116
  username: (0, openinc_openservice_save_ticket_data_1.getUsername)(assigningUser) ?? "System",
115
117
  ticketName: ticket.get("title"),
116
118
  role: assignedTo.get("label"),
117
- ticketLink: (0, getTicketLink_1.getTicketLink)(ticket),
119
+ ticketLink: recipientlink,
118
120
  }),
119
121
  }).save(null, { useMasterKey: true });
120
122
  }
@@ -1,2 +1,7 @@
1
- import { Maintenance_Ticket } from "../../../types";
2
- export declare function getTicketLink(ticket: Maintenance_Ticket): string;
1
+ import { _User, Maintenance_Ticket } from "../../../types";
2
+ /**
3
+ * Returns the link to a ticket.
4
+ * @param ticket
5
+ * @returns
6
+ */
7
+ export declare function getTicketLink(ticket: Maintenance_Ticket, user: _User): Promise<string>;
@@ -2,14 +2,23 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getTicketLink = getTicketLink;
4
4
  const config_1 = require("../../config");
5
- function getTicketLink(ticket) {
6
- //Get hostname from environment variable or default to localhost
5
+ /**
6
+ * Returns the link to a ticket.
7
+ * @param ticket
8
+ * @returns
9
+ */
10
+ async function getTicketLink(ticket, user) {
11
+ //Get hostname from tenant or environment variable or default to localhost
7
12
  let hostname = "localhost";
8
13
  try {
14
+ const baseurl = user.get("tenant")?.get("baseUrl");
9
15
  const publicurl = config_1.ConfigInstance.getInstance()
10
16
  .get("PARSE_PUBLIC_SERVER_URL")
11
17
  .replace("/parse", "");
12
- if (publicurl) {
18
+ if (baseurl !== undefined && baseurl !== "") {
19
+ hostname = baseurl;
20
+ }
21
+ else if (publicurl) {
13
22
  hostname = publicurl;
14
23
  }
15
24
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.init = init;
4
- const __1 = require("..");
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, __1.sendTemplateEmail)({
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 __1 = require("..");
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, __1.sendTemplateEmail)({
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 __1 = require("..");
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, __1.sendTemplateEmail)({
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 __1 = require("..");
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, __1.sendSimpleEmail)(to, "open.INC Test Mail", "This is a test email from open.INC Stack.");
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,
@@ -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, __1.sendSimpleEmail)(email, title, body);
36
+ await (0, notifications_1.sendSimpleEmail)(email, title, body);
36
37
  }
37
38
  }
38
39
  // Handle Push
@@ -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, __1.sendTemplateEmail)({
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, __1.sendTemplateEmail)({
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 "./features/notifications";
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;
@@ -48,12 +47,8 @@ dayjs_1.default.extend(weekday_1.default);
48
47
  dayjs_1.default.extend(dayOfYear_1.default);
49
48
  dayjs_1.default.extend(weekOfYear_1.default);
50
49
  dayjs_1.default.extend(duration_1.default);
51
- var notifications_2 = require("./features/notifications");
52
- Object.defineProperty(exports, "sendSimpleEmail", { enumerable: true, get: function () { return notifications_2.sendSimpleEmail; } });
53
- Object.defineProperty(exports, "sendTemplateEmail", { enumerable: true, get: function () { return notifications_2.sendTemplateEmail; } });
54
50
  const PREFIX = "OD3_";
55
51
  let config;
56
- // const lang_deu = require("../i18n/deu.json");
57
52
  let schema = {};
58
53
  /**
59
54
  * Initializes the Cloud Code for open.DASH.
@@ -5,6 +5,7 @@ export interface TenantAttributes {
5
5
  objectId: string;
6
6
  createdAt: Date;
7
7
  updatedAt: Date;
8
+ baseUrl: string;
8
9
  dataProtectionUrl: string;
9
10
  dataSource?: Source | undefined;
10
11
  description: string;
@@ -21,6 +22,8 @@ export interface TenantAttributes {
21
22
  export declare class Tenant extends Parse.Object<TenantAttributes> {
22
23
  static className: string;
23
24
  constructor(data?: Partial<TenantAttributes>);
25
+ get baseUrl(): string;
26
+ set baseUrl(value: string);
24
27
  get dataProtectionUrl(): string;
25
28
  set dataProtectionUrl(value: string);
26
29
  get dataSource(): Source | undefined;
@@ -5,6 +5,12 @@ class Tenant extends Parse.Object {
5
5
  constructor(data) {
6
6
  super("OD3_Tenant", data);
7
7
  }
8
+ get baseUrl() {
9
+ return super.get("baseUrl");
10
+ }
11
+ set baseUrl(value) {
12
+ super.set("baseUrl", value);
13
+ }
8
14
  get dataProtectionUrl() {
9
15
  return super.get("dataProtectionUrl");
10
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openinc/parse-server-opendash",
3
- "version": "3.29.0",
3
+ "version": "3.29.2",
4
4
  "description": "Parse Server Cloud Code for open.INC Stack.",
5
5
  "packageManager": "pnpm@10.20.0",
6
6
  "keywords": [