srx-lib-azure 0.1.4__py3-none-any.whl → 0.1.5__py3-none-any.whl

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.
srx_lib_azure/email.py CHANGED
@@ -1,22 +1,41 @@
1
1
  import os
2
- from azure.communication.email.aio import EmailClient
3
-
4
2
  import logging
3
+ from typing import Dict, Any
4
+
5
+ try:
6
+ from azure.communication.email.aio import EmailClient
7
+ except Exception: # pragma: no cover - optional dependency at import time
8
+ EmailClient = None # type: ignore
5
9
 
6
10
  logger = logging.getLogger(__name__)
7
11
 
8
12
 
9
13
  class EmailService:
10
- """Thin wrapper over Azure Communication Services EmailClient."""
14
+ """Thin wrapper over Azure Communication Services EmailClient.
15
+
16
+ Does not raise on missing configuration to keep the library optional.
17
+ If not configured, send calls are skipped with a warning and a 'skipped' status.
18
+ """
11
19
 
12
20
  def __init__(self):
13
21
  self.connection_string = os.getenv("ACS_CONNECTION_STRING")
14
22
  self.sender_address = os.getenv("EMAIL_SENDER")
15
- if not self.connection_string or not self.sender_address:
16
- raise ValueError("Missing ACS_CONNECTION_STRING or EMAIL_SENDER in environment variables")
17
- self.email_client = EmailClient.from_connection_string(self.connection_string)
23
+ if not self.connection_string or not self.sender_address or EmailClient is None:
24
+ self.email_client = None
25
+ logger.warning(
26
+ "EmailService not configured (missing ACS_CONNECTION_STRING/EMAIL_SENDER or azure SDK). Calls will be skipped."
27
+ )
28
+ else:
29
+ try:
30
+ self.email_client = EmailClient.from_connection_string(self.connection_string)
31
+ except Exception as e:
32
+ self.email_client = None
33
+ logger.warning("EmailService initialization failed: %s", e)
18
34
 
19
- async def send_notification(self, recipient: str, subject: str, body: str, html: bool = False):
35
+ async def send_notification(self, recipient: str, subject: str, body: str, html: bool = False) -> Dict[str, Any]:
36
+ if not self.email_client or not self.sender_address:
37
+ logger.warning("Email skipped: service not configured")
38
+ return {"status": "skipped", "message": "Email service not configured"}
20
39
  message = {
21
40
  "content": {"subject": subject},
22
41
  "recipients": {"to": [{"address": recipient}]},
@@ -38,4 +57,3 @@ class EmailService:
38
57
  except Exception as e:
39
58
  logger.error("Email send exception: %s", e)
40
59
  return {"status": "error", "message": str(e)}
41
-
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: srx-lib-azure
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: Azure helpers for SRX services: Blob, Email, Table
5
5
  Author-email: SRX <dev@srx.id>
6
6
  Requires-Python: >=3.12
@@ -0,0 +1,7 @@
1
+ srx_lib_azure/__init__.py,sha256=K0UCmkKw7HWJMshp6Xv3SxD4y26r7bdcPtb_2aRc2rs,174
2
+ srx_lib_azure/blob.py,sha256=uCsRUCQN4GHtlyLBtDUvy0_mZaFTxWKdCA407cRIU8I,8245
3
+ srx_lib_azure/email.py,sha256=t5W9DRFZLMJKrCaQuSoRU3jgiqNpDYqOxtvhObYn96w,2584
4
+ srx_lib_azure/table.py,sha256=_5DCsk1SLqCc27F7469hxnRASS3XeffqK_MsJE1cD7Y,3022
5
+ srx_lib_azure-0.1.5.dist-info/METADATA,sha256=qSOMza1A90Pg4AKtWyrcYznmX3NiXZfKLdtF2V0TyNM,1600
6
+ srx_lib_azure-0.1.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
+ srx_lib_azure-0.1.5.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- srx_lib_azure/__init__.py,sha256=K0UCmkKw7HWJMshp6Xv3SxD4y26r7bdcPtb_2aRc2rs,174
2
- srx_lib_azure/blob.py,sha256=uCsRUCQN4GHtlyLBtDUvy0_mZaFTxWKdCA407cRIU8I,8245
3
- srx_lib_azure/email.py,sha256=H8KCnYFuQ2dKzpWx3BsKv9tVCV-pEmm7vXUJkOnpVh4,1719
4
- srx_lib_azure/table.py,sha256=_5DCsk1SLqCc27F7469hxnRASS3XeffqK_MsJE1cD7Y,3022
5
- srx_lib_azure-0.1.4.dist-info/METADATA,sha256=P_eY6gpsYaolhdOp3eraiqlTq5ePnsr22K5VzDjcJYk,1600
6
- srx_lib_azure-0.1.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- srx_lib_azure-0.1.4.dist-info/RECORD,,