@svkruik/sk-dispatch-connector 0.0.1 → 0.0.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/dist/index.js CHANGED
@@ -4,6 +4,21 @@ exports.sendMail = sendMail;
4
4
  const sk_platform_formatters_1 = require("@svkruik/sk-platform-formatters");
5
5
  const sk_uplink_connector_1 = require("@svkruik/sk-uplink-connector");
6
6
  const path_1 = require("path");
7
+ const mailSubjectLookup = {
8
+ "2fa-code": "Your 2FA Verification Code",
9
+ "new-guest-login": "New Guest Login Notification",
10
+ "new-login": "New Login Alert"
11
+ };
12
+ /**
13
+ * Sends an email using the Dispatch service.
14
+ *
15
+ * @param mailDetails Options for the mail itself.
16
+ * @param protocol Send the request via Uplink or a fetch to the API.
17
+ * If you use "http", ensure that DISPATCH_HTTP_API_URL is set in your environment variables.
18
+ * If you use "amqp", ensure that your Uplink Connector is properly configured.
19
+ * @param appName The name of the application sending the mail.
20
+ * @returns
21
+ */
7
22
  async function sendMail(mailDetails, protocol, appName) {
8
23
  if (!process.env.DISPATCH_HTTP_API_URL && protocol === "http")
9
24
  return (0, sk_platform_formatters_1.logError)(new Error("DISPATCH_HTTP_API_URL is not defined in environment variables."));
@@ -13,7 +28,8 @@ async function sendMail(mailDetails, protocol, appName) {
13
28
  if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(mailDetails.to))
14
29
  throw new Error(`Invalid email address provided: ${mailDetails.to}`);
15
30
  const payload = JSON.stringify({
16
- mailDetails
31
+ ...mailDetails,
32
+ subject: mailSubjectLookup[mailDetails.fileName]
17
33
  });
18
34
  if (protocol === "http") {
19
35
  await fetch(process.env.DISPATCH_HTTP_API_URL, {
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "amqp",
9
9
  "rabbitmq"
10
10
  ],
11
- "version": "0.0.1",
11
+ "version": "0.0.2",
12
12
  "author": "Stefan Kruik",
13
13
  "repository": {
14
14
  "type": "git",
package/types.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  // Functions
2
2
  export function sendMail<T extends validFileNames>(
3
3
  mailDetails: MailDetails<T>,
4
- protocol: validProtocols
4
+ protocol: validProtocols,
5
+ appName: string
5
6
  ): Promise<void>;
6
7
 
7
8
  // Types