trovesuite 1.0.4__py3-none-any.whl → 1.0.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.
trovesuite/__init__.py CHANGED
@@ -1,16 +1,18 @@
1
1
  """
2
- TroveSuite Auth Package
2
+ TroveSuite Package
3
3
 
4
- A comprehensive authentication and authorization service for ERP systems.
5
- Provides JWT token validation, user authorization, and permission checking.
4
+ A comprehensive authentication, authorization, and notification service for ERP systems.
5
+ Provides JWT token validation, user authorization, permission checking, and notification capabilities.
6
6
  """
7
7
 
8
8
  from .auth import AuthService
9
+ from .notification import NotificationService
9
10
 
10
11
  __version__ = "1.0.8"
11
12
  __author__ = "Bright Debrah Owusu"
12
13
  __email__ = "owusu.debrah@deladetech.com"
13
14
 
14
15
  __all__ = [
15
- "AuthService"
16
+ "AuthService",
17
+ "NotificationService"
16
18
  ]
@@ -5,13 +5,10 @@ Authentication and authorization services for ERP systems.
5
5
  """
6
6
 
7
7
  from .auth_service import AuthService
8
- from .auth_base import AuthBase
9
- from .auth_read_dto import AuthServiceReadDto, AuthControllerReadDto
8
+ from .auth_write_dto import AuthServiceWriteDto
10
9
 
11
10
  __all__ = [
12
11
  "AuthService",
13
- "AuthBase",
14
- "AuthServiceReadDto",
15
- "AuthControllerReadDto"
12
+ "AuthServiceWriteDto"
16
13
  ]
17
14
 
@@ -0,0 +1,14 @@
1
+ """
2
+ TroveSuite Notification Service
3
+
4
+ Provides email and SMS notification capabilities for TroveSuite applications.
5
+ """
6
+
7
+ from .notification_service import NotificationService
8
+ from .notification_write_dto import NotificationEmailServiceWriteDto, NotificationSMSServiceWriteDto
9
+
10
+ __all__ = [
11
+ "NotificationService",
12
+ "NotificationEmailServiceWriteDto",
13
+ "NotificationSMSServiceWriteDto"
14
+ ]
@@ -0,0 +1,13 @@
1
+ from typing import List, Optional, Union
2
+ from pydantic import BaseModel
3
+
4
+ class NotificationEmailBase(BaseModel):
5
+ sender_email: str
6
+ receiver_email: Union[str, List[str]]
7
+ password: str
8
+ subject: str
9
+ text_message: str
10
+ html_message: Optional[str] = None
11
+
12
+ class NotificationSMSBase(BaseModel):
13
+ pass
@@ -0,0 +1,21 @@
1
+ from src.trovesuite.notification.notification_write_dto import (
2
+ NotificationEmailControllerWriteDto,
3
+ NotificationSMSControllerWriteDto
4
+ )
5
+ from src.trovesuite.notification.notification_read_dto import (
6
+ NotificationEmailControllerReadDto,
7
+ NotificationSMSControllerReadDto
8
+ )
9
+ from src.trovesuite.notification.notification_service import NotificationService
10
+ from src.trovesuite.entities.sh_response import Respons
11
+ from fastapi import APIRouter
12
+
13
+ notification_router = APIRouter()
14
+
15
+ @notification_router.post("/send_email", response_model=Respons[NotificationEmailControllerReadDto])
16
+ async def send_email(data: NotificationEmailControllerWriteDto):
17
+ return NotificationService.send_email(data=data)
18
+
19
+ @notification_router.post("/send_sms", response_model=Respons[NotificationSMSControllerReadDto])
20
+ async def send_sms(data: NotificationSMSControllerWriteDto):
21
+ return NotificationService.send_sms(data=data)
@@ -0,0 +1,21 @@
1
+ from src.trovesuite.notification.notification_base import (
2
+ NotificationEmailBase,
3
+ NotificationSMSBase
4
+ )
5
+ from pydantic import BaseModel
6
+
7
+ # EMAIL Notification
8
+
9
+ class NotificationEmailControllerReadDto(NotificationEmailBase):
10
+ pass
11
+
12
+ class NotificationEmailServiceReadDto(BaseModel):
13
+ pass
14
+
15
+ # SMS Notification
16
+
17
+ class NotificationSMSControllerReadDto(NotificationSMSBase):
18
+ pass
19
+
20
+ class NotificationSMSServiceReadDto(BaseModel):
21
+ pass
@@ -0,0 +1,73 @@
1
+ import smtplib
2
+ from email.mime.text import MIMEText
3
+ from email.mime.multipart import MIMEMultipart
4
+ from src.trovesuite.entities.sh_response import Respons
5
+ from src.trovesuite.notification.notification_read_dto import (
6
+ NotificationEmailServiceReadDto,
7
+ NotificationSMSServiceReadDto
8
+ )
9
+ from src.trovesuite.notification.notification_write_dto import (
10
+ NotificationEmailServiceWriteDto,
11
+ NotificationSMSServiceWriteDto
12
+ )
13
+
14
+ class NotificationService:
15
+
16
+ @staticmethod
17
+ def send_email(data: NotificationEmailServiceWriteDto) -> Respons[NotificationEmailServiceReadDto]:
18
+ """
19
+ Send an email (single or multiple recipients) via Gmail SMTP.
20
+ Supports both plain text and HTML email bodies.
21
+ """
22
+
23
+ # Extract input data
24
+ receiver_email = data.receiver_email
25
+ text_message = data.text_message
26
+ html_message = getattr(data, "html_message", None)
27
+ sender_email = data.sender_email
28
+ password = data.password
29
+ subject = data.subject
30
+
31
+ # Allow single email or list
32
+ if isinstance(receiver_email, str):
33
+ receiver_email = [receiver_email]
34
+
35
+ # Create the email container
36
+ message = MIMEMultipart("alternative")
37
+ message["From"] = sender_email
38
+ message["To"] = ", ".join(receiver_email)
39
+ message["Subject"] = subject
40
+
41
+ # Attach plain text
42
+ message.attach(MIMEText(text_message, "plain"))
43
+
44
+ # Attach HTML if provided
45
+ if html_message:
46
+ message.attach(MIMEText(html_message, "html"))
47
+
48
+ try:
49
+ with smtplib.SMTP_SSL("smtp.gmail.com", 465) as server:
50
+ server.login(sender_email, password)
51
+ server.sendmail(sender_email, receiver_email, message.as_string())
52
+
53
+ return Respons[NotificationEmailServiceReadDto](
54
+ detail=f"Email successfully sent to {len(receiver_email)} recipient(s)",
55
+ error=None,
56
+ data=[],
57
+ status_code=200,
58
+ success=True,
59
+ )
60
+
61
+ except Exception as e:
62
+ print(e)
63
+ return Respons[NotificationEmailServiceReadDto](
64
+ detail="An error occurred while sending the email",
65
+ error=str(e),
66
+ data=[],
67
+ status_code=500,
68
+ success=False,
69
+ )
70
+
71
+ @staticmethod
72
+ def send_sms(data: NotificationSMSServiceWriteDto) -> Respons[NotificationSMSServiceReadDto]:
73
+ pass
@@ -0,0 +1,21 @@
1
+ from pydantic import BaseModel
2
+ from src.trovesuite.notification.notification_base import (
3
+ NotificationEmailBase,
4
+ NotificationSMSBase
5
+ )
6
+
7
+ # Email Notification
8
+
9
+ class NotificationEmailControllerWriteDto(NotificationEmailBase):
10
+ pass
11
+
12
+ class NotificationEmailServiceWriteDto(NotificationEmailControllerWriteDto):
13
+ pass
14
+
15
+ # SMS Notification
16
+
17
+ class NotificationSMSControllerWriteDto(NotificationSMSBase):
18
+ pass
19
+
20
+ class NotificationSMSServiceWriteDto(BaseModel):
21
+ pass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: trovesuite
3
- Version: 1.0.4
3
+ Version: 1.0.5
4
4
  Summary: TroveSuite services package providing authentication, authorization, notifications, and other enterprise services for TroveSuite applications
5
5
  Home-page: https://dev.azure.com/brightgclt/trovesuite/_git/packages
6
6
  Author: Bright Debrah Owusu
@@ -119,10 +119,26 @@ poetry install --with dev
119
119
 
120
120
  ## Quick Start
121
121
 
122
+ ### Import Patterns
123
+
124
+ The package provides clean, simplified import patterns:
125
+
126
+ ```python
127
+ # Import services and DTOs from main package
128
+ from trovesuite import AuthService, NotificationService
129
+ from trovesuite.auth import AuthServiceWriteDto
130
+ from trovesuite.notification import NotificationEmailServiceWriteDto, NotificationSMSServiceWriteDto
131
+
132
+ # Or import everything you need in one line
133
+ from trovesuite import AuthService, NotificationService
134
+ from trovesuite.auth import AuthServiceWriteDto
135
+ from trovesuite.notification import NotificationEmailServiceWriteDto
136
+ ```
137
+
122
138
  ### Basic Usage
123
139
 
124
140
  ```python
125
- from trovesuite import AuthService
141
+ from trovesuite import AuthService, NotificationService
126
142
  from trovesuite.configs.settings import db_settings
127
143
 
128
144
  # Configure your database settings
@@ -137,7 +153,7 @@ db_settings.SECRET_KEY = "your-secret-key"
137
153
  auth_service = AuthService()
138
154
 
139
155
  # Authorize a user
140
- from trovesuite.auth.auth_write_dto import AuthServiceWriteDto
156
+ from trovesuite.auth import AuthServiceWriteDto
141
157
  auth_data = AuthServiceWriteDto(user_id="user123", tenant="tenant456")
142
158
  result = AuthService.authorize(auth_data)
143
159
 
@@ -149,6 +165,30 @@ else:
149
165
  print(f"Authorization failed: {result.detail}")
150
166
  ```
151
167
 
168
+ ### Notification Service Usage
169
+
170
+ ```python
171
+ from trovesuite import NotificationService
172
+ from trovesuite.notification import NotificationEmailServiceWriteDto
173
+
174
+ # Send an email notification
175
+ email_data = NotificationEmailServiceWriteDto(
176
+ sender_email="your-email@gmail.com",
177
+ receiver_email=["recipient1@example.com", "recipient2@example.com"],
178
+ password="your-app-password", # Gmail app password
179
+ subject="Test Notification",
180
+ text_message="This is a plain text message",
181
+ html_message="<h1>This is an HTML message</h1><p>With rich formatting!</p>"
182
+ )
183
+
184
+ result = NotificationService.send_email(email_data)
185
+
186
+ if result.success:
187
+ print(f"Email sent successfully: {result.detail}")
188
+ else:
189
+ print(f"Email failed: {result.error}")
190
+ ```
191
+
152
192
  ### JWT Token Decoding
153
193
 
154
194
  ```python
@@ -166,7 +206,7 @@ async def protected_route(token: str = Depends(oauth2_scheme)):
166
206
  tenant_id = user_data["tenant_id"]
167
207
 
168
208
  # Authorize user
169
- from trovesuite.auth.auth_write_dto import AuthServiceWriteDto
209
+ from trovesuite.auth import AuthServiceWriteDto
170
210
  auth_data = AuthServiceWriteDto(user_id=user_id, tenant=tenant_id)
171
211
  auth_result = AuthService.authorize(auth_data)
172
212
  return auth_result
@@ -395,8 +435,84 @@ Check if user has all of the required permissions.
395
435
  **Returns:**
396
436
  - `bool`: True if user has all of the required permissions
397
437
 
438
+ ### NotificationService
439
+
440
+ #### `send_email(data: NotificationEmailServiceWriteDto) -> Respons[NotificationEmailServiceReadDto]`
441
+
442
+ Sends an email notification via Gmail SMTP. Supports both plain text and HTML email bodies.
443
+
444
+ **Parameters:**
445
+ - `data`: Email notification data including sender, recipients, subject, and message content
446
+
447
+ **Returns:**
448
+ - `Respons[NotificationEmailServiceReadDto]`: Email sending result with success status and details
449
+
450
+ **Example:**
451
+ ```python
452
+ from trovesuite import NotificationService
453
+ from trovesuite.notification import NotificationEmailServiceWriteDto
454
+
455
+ email_data = NotificationEmailServiceWriteDto(
456
+ sender_email="sender@gmail.com",
457
+ receiver_email=["user1@example.com", "user2@example.com"],
458
+ password="your-gmail-app-password",
459
+ subject="Welcome to TroveSuite",
460
+ text_message="Welcome! This is a plain text message.",
461
+ html_message="<h1>Welcome!</h1><p>This is an <strong>HTML</strong> message.</p>"
462
+ )
463
+
464
+ result = NotificationService.send_email(email_data)
465
+ if result.success:
466
+ print("Email sent successfully!")
467
+ else:
468
+ print(f"Failed to send email: {result.error}")
469
+ ```
470
+
471
+ #### `send_sms(data: NotificationSMSServiceWriteDto) -> Respons[NotificationSMSServiceReadDto]`
472
+
473
+ Sends an SMS notification (currently not implemented).
474
+
475
+ **Parameters:**
476
+ - `data`: SMS notification data
477
+
478
+ **Returns:**
479
+ - `Respons[NotificationSMSServiceReadDto]`: SMS sending result
480
+
398
481
  ### Data Models
399
482
 
483
+ #### `NotificationEmailServiceWriteDto`
484
+
485
+ ```python
486
+ class NotificationEmailServiceWriteDto(BaseModel):
487
+ sender_email: str
488
+ receiver_email: Union[str, List[str]] # Single email or list of emails
489
+ password: str # Gmail app password
490
+ subject: str
491
+ text_message: str
492
+ html_message: Optional[str] = None # Optional HTML content
493
+ ```
494
+
495
+ #### `NotificationEmailServiceReadDto`
496
+
497
+ ```python
498
+ class NotificationEmailServiceReadDto(BaseModel):
499
+ pass # Empty response model for email service
500
+ ```
501
+
502
+ #### `NotificationSMSServiceWriteDto`
503
+
504
+ ```python
505
+ class NotificationSMSServiceWriteDto(BaseModel):
506
+ pass # To be implemented for SMS functionality
507
+ ```
508
+
509
+ #### `NotificationSMSServiceReadDto`
510
+
511
+ ```python
512
+ class NotificationSMSServiceReadDto(BaseModel):
513
+ pass # To be implemented for SMS functionality
514
+ ```
515
+
400
516
  #### `AuthServiceReadDto`
401
517
 
402
518
  ```python
@@ -565,7 +681,7 @@ For support, email brightgclt@gmail.com or create a work item in the [Azure DevO
565
681
 
566
682
  ### 1.0.8
567
683
  - Restructured package for direct service imports
568
- - Added notification services
684
+ - Added comprehensive notification services with email support
569
685
  - Excluded controllers from package build
570
686
  - Updated import paths for better usability
571
687
  - JWT token validation
@@ -574,3 +690,6 @@ For support, email brightgclt@gmail.com or create a work item in the [Azure DevO
574
690
  - PostgreSQL database integration
575
691
  - Comprehensive logging
576
692
  - Azure integration support
693
+ - Email notification service with Gmail SMTP support
694
+ - Support for both plain text and HTML email content
695
+ - Multiple recipient support for email notifications
@@ -1,5 +1,5 @@
1
- trovesuite/__init__.py,sha256=a9jSrjmrhOey6yE2I83TO_rVJDogIwGDyL3HJBGiGqM,347
2
- trovesuite/auth/__init__.py,sha256=d8d5POjq9lGe7GVbc7Qm6hUpx1bgLqEVQFG1iYafdxI,337
1
+ trovesuite/__init__.py,sha256=c7z8TrIWz156VyDw2qEclTdJxKqAdbhQyCjDLY4s0uM,457
2
+ trovesuite/auth/__init__.py,sha256=OjZllVvjul1glDazJ-d5TrNjgHFigFlQQi1G99DYshk,239
3
3
  trovesuite/auth/auth_base.py,sha256=rZHQVLeJRBQ8GClgF5UwG-er4_HXVX5-nt8o6_Z29uY,75
4
4
  trovesuite/auth/auth_controller.py,sha256=mMAyTV_0rFeArpcIDu9Pr_IATvFZU6wfIo6ViQoUv0U,477
5
5
  trovesuite/auth/auth_read_dto.py,sha256=pQT1ouRVZMAiJn4wAG7NQOKQKTquTMWUe-dYcpLTmEo,533
@@ -12,10 +12,16 @@ trovesuite/configs/settings.py,sha256=yUbkiFi4QdO9JZG1RRFbP4tYurT47HmN-ohgYcs2SH
12
12
  trovesuite/entities/__init__.py,sha256=Dbl_03Bueyh2vOP2hykd40MmNMrl5nNHSRGP-kqwwNo,160
13
13
  trovesuite/entities/health.py,sha256=H8-XUywzvMfZy2dZwDyJGAUbmuULuZYvYIUWhiaVGdY,2729
14
14
  trovesuite/entities/sh_response.py,sha256=1_sw3PpVaDxWsNiBU0W9YLHZgTFxEj4JJBLBfSY63Ho,1579
15
+ trovesuite/notification/__init__.py,sha256=mjglzmlk29SREP6LfvBYGmCSc-K1SKKAEx_OJdJ2Vrs,394
16
+ trovesuite/notification/notification_base.py,sha256=6Xo0Gnnpg3RgN1_SRkAcH-K4l7DwNDZvn1gRm3oMWyk,320
17
+ trovesuite/notification/notification_controller.py,sha256=w-SpRTjeInrgsUX0sAzFVjXiBo395ge6v-dn1Cc8ogU,920
18
+ trovesuite/notification/notification_read_dto.py,sha256=pZg3KHZJA4c5MoXqTHCgUiGnd8mRrQjVOaCtWXtuT7U,450
19
+ trovesuite/notification/notification_service.py,sha256=u3-rHnTr3dgLX_RGjkG6c9mYVPspRCSEDBtDrGN-Rj0,2500
20
+ trovesuite/notification/notification_write_dto.py,sha256=WrdFWIa9sK5rrwgp1bUOOikwE7xL8O9z110EGnXedzw,479
15
21
  trovesuite/utils/__init__.py,sha256=3UPKTz9cluTgAM-ldNsJxsnoPTZiqacXlAmzUEHy6q8,143
16
22
  trovesuite/utils/helper.py,sha256=lvZ1mvaqY84dkIPB5Ov0uwYDOWBziAS8twobEJZh2Ik,1002
17
- trovesuite-1.0.4.dist-info/licenses/LICENSE,sha256=EJT35ct-Q794JYPdAQy3XNczQGKkU1HzToLeK1YVw2s,1070
18
- trovesuite-1.0.4.dist-info/METADATA,sha256=-HtCWfAoPzJCmZdj_YCKzy8DG17EKe4mCBZDleqG7aQ,16000
19
- trovesuite-1.0.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
20
- trovesuite-1.0.4.dist-info/top_level.txt,sha256=GzKhG_-MTaxeHrIgkGkBH_nof2vroGFBrjeHKWUIwNc,11
21
- trovesuite-1.0.4.dist-info/RECORD,,
23
+ trovesuite-1.0.5.dist-info/licenses/LICENSE,sha256=EJT35ct-Q794JYPdAQy3XNczQGKkU1HzToLeK1YVw2s,1070
24
+ trovesuite-1.0.5.dist-info/METADATA,sha256=JD98gu0c53MANB7pMF73Eg6axkfk_RW3HpmSU5KFVOA,19704
25
+ trovesuite-1.0.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
26
+ trovesuite-1.0.5.dist-info/top_level.txt,sha256=GzKhG_-MTaxeHrIgkGkBH_nof2vroGFBrjeHKWUIwNc,11
27
+ trovesuite-1.0.5.dist-info/RECORD,,