lumera 0.9.7__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.7
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)
@@ -23,7 +23,15 @@ Example:
23
23
  >>> print(result["url"])
24
24
  """
25
25
 
26
- __all__ = ["upload", "upload_file", "download_url", "list_files", "UploadResult"]
26
+ __all__ = [
27
+ "upload",
28
+ "upload_file",
29
+ "download_url",
30
+ "list_files",
31
+ "UploadResult",
32
+ "get_download_url",
33
+ "download",
34
+ ]
27
35
 
28
36
  import mimetypes
29
37
  import os
@@ -268,3 +276,76 @@ def list_files(prefix: str | None = None) -> list[dict[str, Any]]:
268
276
  files = [f for f in files if f.get("name", "").startswith(prefix)]
269
277
 
270
278
  return files
279
+
280
+
281
+ def get_download_url(object_key: str) -> str:
282
+ """Get a presigned download URL for a file by its object_key.
283
+
284
+ Use this to get download URLs for files stored in lumera_file fields on records.
285
+ The object_key is found in the file descriptor (e.g., record["file"]["object_key"]).
286
+
287
+ Args:
288
+ object_key: The storage object key from a lumera_file field descriptor
289
+
290
+ Returns:
291
+ Presigned download URL (valid for ~15 minutes)
292
+
293
+ Raises:
294
+ ValueError: If object_key is empty
295
+ requests.HTTPError: If the file doesn't exist or request fails
296
+
297
+ Example:
298
+ >>> record = pb.get("documents", "rec_123")
299
+ >>> url = storage.get_download_url(record["file"]["object_key"])
300
+ >>> # Use url to download the file
301
+ """
302
+ if not object_key or not object_key.strip():
303
+ raise ValueError("object_key is required and cannot be empty")
304
+
305
+ token = get_lumera_token()
306
+ headers = {"Authorization": f"token {token}", "Content-Type": "application/json"}
307
+
308
+ resp = requests.post(
309
+ f"{API_BASE}/pb/uploads/download",
310
+ json={"object_key": object_key.strip()},
311
+ headers=headers,
312
+ timeout=30,
313
+ )
314
+ resp.raise_for_status()
315
+
316
+ data = resp.json()
317
+ url = data.get("download_url")
318
+ if not url:
319
+ raise RuntimeError("uploads/download response missing download_url")
320
+
321
+ return url
322
+
323
+
324
+ def download(object_key: str) -> bytes:
325
+ """Download file content by its object_key.
326
+
327
+ Use this to download files stored in lumera_file fields on records.
328
+ The object_key is found in the file descriptor (e.g., record["file"]["object_key"]).
329
+
330
+ Args:
331
+ object_key: The storage object key from a lumera_file field descriptor
332
+
333
+ Returns:
334
+ File content as bytes
335
+
336
+ Raises:
337
+ ValueError: If object_key is empty
338
+ requests.HTTPError: If the file doesn't exist or download fails
339
+
340
+ Example:
341
+ >>> record = pb.get("documents", "rec_123")
342
+ >>> content = storage.download(record["file"]["object_key"])
343
+ >>> with open("local_copy.pdf", "wb") as f:
344
+ ... f.write(content)
345
+ """
346
+ url = get_download_url(object_key)
347
+
348
+ response = requests.get(url, timeout=300)
349
+ response.raise_for_status()
350
+
351
+ return response.content
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lumera
3
- Version: 0.9.7
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.7"
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