lumera 0.9.8__tar.gz → 0.9.9__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lumera
3
- Version: 0.9.8
3
+ Version: 0.9.9
4
4
  Summary: SDK for building on Lumera platform
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: requests
@@ -13,7 +13,7 @@ except PackageNotFoundError:
13
13
  __version__ = "unknown" # Not installed (e.g., running from source)
14
14
 
15
15
  # Import new modules (as modules, not individual functions)
16
- from . import automations, exceptions, integrations, llm, locks, pb, storage, webhooks
16
+ from . import automations, email, exceptions, integrations, llm, locks, pb, storage, webhooks
17
17
  from ._utils import (
18
18
  LumeraAPIError,
19
19
  RecordNotUniqueError,
@@ -102,6 +102,7 @@ __all__ = [
102
102
  "LockHeldError",
103
103
  # New modules (use as lumera.pb, lumera.storage, etc.)
104
104
  "automations",
105
+ "email",
105
106
  "pb",
106
107
  "storage",
107
108
  "llm",
@@ -0,0 +1,156 @@
1
+ """
2
+ Email sending for Lumera automations.
3
+
4
+ Send transactional emails through the Lumera platform using AWS SES infrastructure.
5
+ Emails are logged to the lm_email_logs collection for auditing and debugging.
6
+
7
+ Functions:
8
+ send() - Send an email with HTML/text content
9
+
10
+ Example:
11
+ >>> from lumera import email
12
+ >>>
13
+ >>> # Send a simple email
14
+ >>> result = email.send(
15
+ ... to="user@example.com",
16
+ ... subject="Welcome to Lumera!",
17
+ ... body_html="<h1>Hello!</h1><p>Welcome aboard.</p>"
18
+ ... )
19
+ >>> print(result.message_id)
20
+ >>>
21
+ >>> # Send to multiple recipients with plain text fallback
22
+ >>> result = email.send(
23
+ ... to=["alice@example.com", "bob@example.com"],
24
+ ... subject="Team Update",
25
+ ... body_html="<h1>Update</h1><p>See details below.</p>",
26
+ ... body_text="Update\\n\\nSee details below.",
27
+ ... tags={"type": "notification", "team": "engineering"}
28
+ ... )
29
+ """
30
+
31
+ from __future__ import annotations
32
+
33
+ from typing import Any
34
+
35
+ from ._utils import _api_request, LumeraAPIError
36
+
37
+ __all__ = [
38
+ "send",
39
+ "SendResult",
40
+ ]
41
+
42
+
43
+ class SendResult:
44
+ """Result of sending an email.
45
+
46
+ Attributes:
47
+ message_id: The unique identifier from AWS SES for the sent email.
48
+ log_id: The PocketBase record ID in lm_email_logs for auditing.
49
+ """
50
+
51
+ def __init__(self, data: dict[str, Any]):
52
+ self.message_id: str = data.get("message_id", "")
53
+ self.log_id: str = data.get("log_id", "")
54
+ self._raw = data
55
+
56
+ def __repr__(self) -> str:
57
+ return f"SendResult(message_id={self.message_id!r}, log_id={self.log_id!r})"
58
+
59
+
60
+ def send(
61
+ to: list[str] | str,
62
+ subject: str,
63
+ *,
64
+ body_html: str | None = None,
65
+ body_text: str | None = None,
66
+ cc: list[str] | str | None = None,
67
+ bcc: list[str] | str | None = None,
68
+ from_address: str | None = None,
69
+ from_name: str | None = None,
70
+ reply_to: str | None = None,
71
+ tags: dict[str, str] | None = None,
72
+ ) -> SendResult:
73
+ """Send an email.
74
+
75
+ At least one of body_html or body_text must be provided. If only body_html
76
+ is provided, a plain text version will be auto-generated.
77
+
78
+ Args:
79
+ to: Recipient email address(es). Can be a single string or list.
80
+ subject: Email subject line.
81
+ body_html: HTML body content (optional if body_text provided).
82
+ body_text: Plain text body content (optional, auto-generated from HTML).
83
+ cc: CC recipient(s) (optional).
84
+ bcc: BCC recipient(s) (optional).
85
+ from_address: Sender email address (optional, uses platform default).
86
+ from_name: Sender display name (optional, uses platform default).
87
+ reply_to: Reply-to address (optional).
88
+ tags: Custom key-value pairs for tracking/filtering in logs (optional).
89
+
90
+ Returns:
91
+ SendResult with message_id and log_id.
92
+
93
+ Raises:
94
+ ValueError: If required fields are missing or invalid.
95
+ LumeraAPIError: If the API request fails.
96
+
97
+ Example:
98
+ >>> # Simple email
99
+ >>> result = email.send(
100
+ ... to="user@example.com",
101
+ ... subject="Password Reset",
102
+ ... body_html="<p>Click <a href='...'>here</a> to reset.</p>"
103
+ ... )
104
+ >>>
105
+ >>> # Email with all options
106
+ >>> result = email.send(
107
+ ... to=["alice@example.com", "bob@example.com"],
108
+ ... subject="Monthly Report",
109
+ ... body_html="<h1>Report</h1><p>See attached.</p>",
110
+ ... body_text="Report\\n\\nSee attached.",
111
+ ... cc="manager@example.com",
112
+ ... reply_to="reports@example.com",
113
+ ... tags={"report_type": "monthly", "department": "sales"}
114
+ ... )
115
+ """
116
+ # Normalize to lists
117
+ to_list = [to] if isinstance(to, str) else list(to) if to else []
118
+ cc_list = [cc] if isinstance(cc, str) else (list(cc) if cc else None)
119
+ bcc_list = [bcc] if isinstance(bcc, str) else (list(bcc) if bcc else None)
120
+
121
+ # Validate
122
+ if not to_list:
123
+ raise ValueError("at least one recipient is required")
124
+ if not subject or not subject.strip():
125
+ raise ValueError("subject is required")
126
+ if not body_html and not body_text:
127
+ raise ValueError("at least one of body_html or body_text is required")
128
+
129
+ # Build payload
130
+ payload: dict[str, Any] = {
131
+ "to": to_list,
132
+ "subject": subject.strip(),
133
+ }
134
+
135
+ if body_html:
136
+ payload["body_html"] = body_html
137
+ if body_text:
138
+ payload["body_text"] = body_text
139
+ if cc_list:
140
+ payload["cc"] = cc_list
141
+ if bcc_list:
142
+ payload["bcc"] = bcc_list
143
+ if from_address:
144
+ payload["from"] = from_address.strip()
145
+ if from_name:
146
+ payload["from_name"] = from_name.strip()
147
+ if reply_to:
148
+ payload["reply_to"] = reply_to.strip()
149
+ if tags:
150
+ payload["tags"] = tags
151
+
152
+ result = _api_request("POST", "email/send", json_body=payload)
153
+ if not isinstance(result, dict):
154
+ raise RuntimeError("unexpected response from email/send")
155
+
156
+ return SendResult(result)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lumera
3
- Version: 0.9.8
3
+ Version: 0.9.9
4
4
  Summary: SDK for building on Lumera platform
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: requests
@@ -2,6 +2,7 @@ pyproject.toml
2
2
  lumera/__init__.py
3
3
  lumera/_utils.py
4
4
  lumera/automations.py
5
+ lumera/email.py
5
6
  lumera/exceptions.py
6
7
  lumera/files.py
7
8
  lumera/google.py
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "lumera"
3
- version = "0.9.8"
3
+ version = "0.9.9"
4
4
  description = "SDK for building on Lumera platform"
5
5
  requires-python = ">=3.11"
6
6
  dependencies = [
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes