statocysts 0.8.0 → 0.9.0

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.d.ts CHANGED
@@ -1,9 +1,31 @@
1
1
  import { _ as defineTransport, a as discord, c as Sender, d as buildSenderRegistry, f as DefineProviderContext, g as Transport, h as defineProvider, i as slack, l as SenderRegistry, m as ServiceProvider, n as bark, o as HttpPayload, p as DefineProviderOptions, r as telegram, s as http, t as json, u as SenderUrl } from "./index-DcoOHy7e.js";
2
+ import { Message, MessageHeaders, SMTPConnectionOptions } from "emailjs";
2
3
 
4
+ //#region src/core/transports/smtp.d.ts
5
+ /**
6
+ * SMTP payload for SMTP transport
7
+ */
8
+ interface SmtpPayload {
9
+ /**
10
+ * SMTP client configuration
11
+ */
12
+ client: Partial<SMTPConnectionOptions>;
13
+ /**
14
+ * Email message to send
15
+ */
16
+ message: Message | MessageHeaders;
17
+ }
18
+ //#endregion
19
+ //#region src/services/specialized/email/index.d.ts
20
+ interface EmailOptions {
21
+ defaultFrom?: string;
22
+ smtpConfig?: Partial<SMTPConnectionOptions>;
23
+ }
24
+ declare const email: ServiceProvider<"email:", SmtpPayload, EmailOptions>;
25
+ //#endregion
3
26
  //#region src/index.d.ts
4
-
5
27
  declare const senderRegistry: SenderRegistry;
6
28
  declare function createSender(urls: SenderUrl[]): Sender;
7
29
  declare function send(url: string | URL, title: string, body?: string): Promise<void>;
8
30
  //#endregion
9
- export { DefineProviderContext, DefineProviderOptions, HttpPayload, Sender, SenderRegistry, SenderUrl, ServiceProvider, Transport, bark, buildSenderRegistry, createSender, defineProvider, defineTransport, discord, http, json, send, senderRegistry, slack, telegram };
31
+ export { DefineProviderContext, DefineProviderOptions, HttpPayload, Sender, SenderRegistry, SenderUrl, ServiceProvider, Transport, bark, buildSenderRegistry, createSender, defineProvider, defineTransport, discord, email, http, json, send, senderRegistry, slack, telegram };
package/dist/index.js CHANGED
@@ -1,8 +1,83 @@
1
1
  import { a as slack, c as defineTransport, i as telegram, l as defineProvider, n as bark, o as discord, r as buildSenderRegistry, s as http, t as json, u as assert } from "./json-DAUitIVf.js";
2
+ import z from "zod";
3
+ import { SMTPClient } from "emailjs";
2
4
 
5
+ //#region src/core/transports/smtp.ts
6
+ /**
7
+ * SMTP transport implementation
8
+ * Handles sending emails over SMTP protocol using emailjs
9
+ */
10
+ const smtp = defineTransport({ async send(payload) {
11
+ await new SMTPClient(payload.client).sendAsync(payload.message);
12
+ } });
13
+
14
+ //#endregion
15
+ //#region src/services/specialized/email/index.ts
16
+ const queryParamSchema = z.object({
17
+ from: z.string().email().optional(),
18
+ subject: z.string().optional(),
19
+ ssl: z.string().transform((val) => val === "true").optional(),
20
+ tls: z.string().transform((val) => val !== "false").optional()
21
+ });
22
+ const email = defineProvider("email:", {
23
+ transport: smtp,
24
+ defaultOptions: {},
25
+ async prepare(ctx, options) {
26
+ const { url, message } = ctx;
27
+ const to = url.searchParams.getAll("to");
28
+ const cc = url.searchParams.getAll("cc");
29
+ const bcc = url.searchParams.getAll("bcc");
30
+ const from = url.searchParams.get("from");
31
+ const subject = url.searchParams.get("subject");
32
+ const sslParam = url.searchParams.get("ssl");
33
+ const tlsParam = url.searchParams.get("tls");
34
+ const queryResult = queryParamSchema.safeParse({
35
+ from: from || void 0,
36
+ subject: subject || void 0,
37
+ ssl: sslParam || void 0,
38
+ tls: tlsParam || void 0
39
+ });
40
+ if (!queryResult.success) throw new Error(`Invalid email query parameters: ${queryResult.error.message}`);
41
+ const query = queryResult.data;
42
+ const host = url.hostname;
43
+ assert(host, "SMTP host is required");
44
+ const port = url.port ? Number.parseInt(url.port, 10) : 587;
45
+ const user = decodeURIComponent(url.username || "");
46
+ const password = decodeURIComponent(url.password || "");
47
+ const fromAddress = query.from || options.defaultFrom || user;
48
+ assert(fromAddress, "Sender email address (from) is required");
49
+ assert(to.length > 0, "At least one recipient email address (to) is required");
50
+ const emailSubject = query.subject || message.title;
51
+ const text = message.body ? `${message.title}\n\n${message.body}` : message.title;
52
+ return {
53
+ client: {
54
+ host,
55
+ port,
56
+ ...user && password ? {
57
+ user,
58
+ password
59
+ } : {},
60
+ ssl: query.ssl ?? false,
61
+ tls: query.tls ?? port === 587,
62
+ ...options.smtpConfig
63
+ },
64
+ message: {
65
+ from: fromAddress,
66
+ to: to.join(", "),
67
+ cc: cc.length > 0 ? cc.join(", ") : void 0,
68
+ bcc: bcc.length > 0 ? bcc.join(", ") : void 0,
69
+ subject: emailSubject,
70
+ text
71
+ }
72
+ };
73
+ }
74
+ });
75
+
76
+ //#endregion
3
77
  //#region src/index.ts
4
78
  const senderRegistry = buildSenderRegistry([
5
79
  bark,
80
+ email,
6
81
  json,
7
82
  slack,
8
83
  telegram,
@@ -23,4 +98,4 @@ async function send(url, title, body) {
23
98
  }
24
99
 
25
100
  //#endregion
26
- export { bark, buildSenderRegistry, createSender, defineProvider, defineTransport, discord, http, json, send, senderRegistry, slack, telegram };
101
+ export { bark, buildSenderRegistry, createSender, defineProvider, defineTransport, discord, email, http, json, send, senderRegistry, slack, telegram };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "statocysts",
3
3
  "type": "module",
4
- "version": "0.8.0",
4
+ "version": "0.9.0",
5
5
  "description": "Notification library for JavaScript",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/octoplorer/statocysts",
@@ -47,13 +47,16 @@
47
47
  "dependencies": {
48
48
  "add": "^2.0.6",
49
49
  "defu": "^6.1.4",
50
+ "emailjs": "^5.0.0",
50
51
  "ofetch": "^1.5.1",
51
52
  "ufo": "^1.6.1",
52
53
  "zod": "^4.2.1"
53
54
  },
54
55
  "devDependencies": {
55
56
  "@types/node": "^25.0.3",
57
+ "@types/smtp-server": "^3.5.12",
56
58
  "@vitest/coverage-v8": "4.0.16",
59
+ "smtp-server": "^3.18.0",
57
60
  "tsdown": "^0.18.2",
58
61
  "typescript": "^5.9.3",
59
62
  "vitest": "^4.0.16"