dominus-sdk-python-dev 2.1.6__py3-none-any.whl → 2.1.7__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.
@@ -1,251 +1,251 @@
1
- """
2
- Courier Namespace - Email delivery via Postmark.
3
-
4
- Provides email sending using Postmark templates.
5
- """
6
- from typing import Any, Dict, Optional, TYPE_CHECKING
7
-
8
- if TYPE_CHECKING:
9
- from ..start import Dominus
10
-
11
-
12
- class CourierNamespace:
13
- """
14
- Email delivery namespace.
15
-
16
- All email operations go through /api/courier/* endpoints.
17
- Uses Postmark for transactional email delivery.
18
-
19
- Usage:
20
- # Send welcome email
21
- result = await dominus.courier.send(
22
- template_alias="welcome",
23
- to="user@example.com",
24
- from_email="noreply@myapp.com",
25
- model={
26
- "name": "John Smith",
27
- "product_name": "My App"
28
- }
29
- )
30
-
31
- # Send with tracking tag
32
- result = await dominus.courier.send(
33
- template_alias="password-reset",
34
- to="user@example.com",
35
- from_email="noreply@myapp.com",
36
- model={"reset_link": "https://..."},
37
- tag="password-reset"
38
- )
39
- """
40
-
41
- def __init__(self, client: "Dominus"):
42
- self._client = client
43
-
44
- async def send(
45
- self,
46
- template_alias: str,
47
- to: str,
48
- from_email: str,
49
- model: Dict[str, Any],
50
- tag: Optional[str] = None,
51
- reply_to: Optional[str] = None
52
- ) -> Dict[str, Any]:
53
- """
54
- Send email using Postmark template.
55
-
56
- Args:
57
- template_alias: Template alias in Postmark (e.g., "welcome", "password-reset")
58
- to: Recipient email address
59
- from_email: Sender email address (must be verified in Postmark)
60
- model: Template model variables (dict of key-value pairs)
61
- tag: Optional tag for tracking/filtering in Postmark
62
- reply_to: Optional reply-to address
63
-
64
- Returns:
65
- Dict with:
66
- - to: Recipient email
67
- - message_id: Postmark message UUID
68
- - submitted_at: Timestamp
69
-
70
- Example:
71
- result = await dominus.courier.send(
72
- template_alias="welcome",
73
- to="john@example.com",
74
- from_email="hello@myapp.com",
75
- model={
76
- "name": "John",
77
- "company_name": "My App",
78
- "action_url": "https://myapp.com/verify?token=abc123"
79
- },
80
- tag="welcome"
81
- )
82
- print(f"Email sent: {result['message_id']}")
83
- """
84
- body = {
85
- "template_alias": template_alias,
86
- "to": to,
87
- "from": from_email,
88
- "model": model
89
- }
90
-
91
- if tag:
92
- body["tag"] = tag
93
- if reply_to:
94
- body["reply_to"] = reply_to
95
-
96
- return await self._client._request(
97
- endpoint="/api/courier/send",
98
- body=body
99
- )
100
-
101
- # Convenience methods for common templates
102
-
103
- async def send_welcome(
104
- self,
105
- to: str,
106
- from_email: str,
107
- name: str,
108
- product_name: str,
109
- action_url: Optional[str] = None,
110
- **extra_model
111
- ) -> Dict[str, Any]:
112
- """
113
- Send welcome email.
114
-
115
- Args:
116
- to: Recipient email
117
- from_email: Sender email
118
- name: User's name
119
- product_name: Your product/app name
120
- action_url: Optional action button URL
121
- **extra_model: Additional template variables
122
-
123
- Returns:
124
- Send result dict
125
- """
126
- model = {
127
- "name": name,
128
- "product_name": product_name,
129
- **extra_model
130
- }
131
- if action_url:
132
- model["action_url"] = action_url
133
-
134
- return await self.send(
135
- template_alias="welcome",
136
- to=to,
137
- from_email=from_email,
138
- model=model,
139
- tag="welcome"
140
- )
141
-
142
- async def send_password_reset(
143
- self,
144
- to: str,
145
- from_email: str,
146
- name: str,
147
- reset_url: str,
148
- product_name: str,
149
- **extra_model
150
- ) -> Dict[str, Any]:
151
- """
152
- Send password reset email.
153
-
154
- Args:
155
- to: Recipient email
156
- from_email: Sender email
157
- name: User's name
158
- reset_url: Password reset link
159
- product_name: Your product/app name
160
- **extra_model: Additional template variables
161
-
162
- Returns:
163
- Send result dict
164
- """
165
- return await self.send(
166
- template_alias="password-reset",
167
- to=to,
168
- from_email=from_email,
169
- model={
170
- "name": name,
171
- "action_url": reset_url,
172
- "product_name": product_name,
173
- **extra_model
174
- },
175
- tag="password-reset"
176
- )
177
-
178
- async def send_email_verification(
179
- self,
180
- to: str,
181
- from_email: str,
182
- name: str,
183
- verify_url: str,
184
- product_name: str,
185
- **extra_model
186
- ) -> Dict[str, Any]:
187
- """
188
- Send email verification email.
189
-
190
- Args:
191
- to: Recipient email
192
- from_email: Sender email
193
- name: User's name
194
- verify_url: Email verification link
195
- product_name: Your product/app name
196
- **extra_model: Additional template variables
197
-
198
- Returns:
199
- Send result dict
200
- """
201
- return await self.send(
202
- template_alias="email-verification",
203
- to=to,
204
- from_email=from_email,
205
- model={
206
- "name": name,
207
- "action_url": verify_url,
208
- "product_name": product_name,
209
- **extra_model
210
- },
211
- tag="email-verification"
212
- )
213
-
214
- async def send_invitation(
215
- self,
216
- to: str,
217
- from_email: str,
218
- name: str,
219
- invite_url: str,
220
- inviter_name: str,
221
- product_name: str,
222
- **extra_model
223
- ) -> Dict[str, Any]:
224
- """
225
- Send user invitation email.
226
-
227
- Args:
228
- to: Recipient email
229
- from_email: Sender email
230
- name: Invitee's name
231
- invite_url: Invitation accept link
232
- inviter_name: Name of person who invited
233
- product_name: Your product/app name
234
- **extra_model: Additional template variables
235
-
236
- Returns:
237
- Send result dict
238
- """
239
- return await self.send(
240
- template_alias="invitation",
241
- to=to,
242
- from_email=from_email,
243
- model={
244
- "name": name,
245
- "action_url": invite_url,
246
- "inviter_name": inviter_name,
247
- "product_name": product_name,
248
- **extra_model
249
- },
250
- tag="invitation"
251
- )
1
+ """
2
+ Courier Namespace - Email delivery via Postmark.
3
+
4
+ Provides email sending using Postmark templates.
5
+ """
6
+ from typing import Any, Dict, Optional, TYPE_CHECKING
7
+
8
+ if TYPE_CHECKING:
9
+ from ..start import Dominus
10
+
11
+
12
+ class CourierNamespace:
13
+ """
14
+ Email delivery namespace.
15
+
16
+ All email operations go through /api/courier/* endpoints.
17
+ Uses Postmark for transactional email delivery.
18
+
19
+ Usage:
20
+ # Send welcome email
21
+ result = await dominus.courier.send(
22
+ template_alias="welcome",
23
+ to="user@example.com",
24
+ from_email="noreply@myapp.com",
25
+ model={
26
+ "name": "John Smith",
27
+ "product_name": "My App"
28
+ }
29
+ )
30
+
31
+ # Send with tracking tag
32
+ result = await dominus.courier.send(
33
+ template_alias="password-reset",
34
+ to="user@example.com",
35
+ from_email="noreply@myapp.com",
36
+ model={"reset_link": "https://..."},
37
+ tag="password-reset"
38
+ )
39
+ """
40
+
41
+ def __init__(self, client: "Dominus"):
42
+ self._client = client
43
+
44
+ async def send(
45
+ self,
46
+ template_alias: str,
47
+ to: str,
48
+ from_email: str,
49
+ model: Dict[str, Any],
50
+ tag: Optional[str] = None,
51
+ reply_to: Optional[str] = None
52
+ ) -> Dict[str, Any]:
53
+ """
54
+ Send email using Postmark template.
55
+
56
+ Args:
57
+ template_alias: Template alias in Postmark (e.g., "welcome", "password-reset")
58
+ to: Recipient email address
59
+ from_email: Sender email address (must be verified in Postmark)
60
+ model: Template model variables (dict of key-value pairs)
61
+ tag: Optional tag for tracking/filtering in Postmark
62
+ reply_to: Optional reply-to address
63
+
64
+ Returns:
65
+ Dict with:
66
+ - to: Recipient email
67
+ - message_id: Postmark message UUID
68
+ - submitted_at: Timestamp
69
+
70
+ Example:
71
+ result = await dominus.courier.send(
72
+ template_alias="welcome",
73
+ to="john@example.com",
74
+ from_email="hello@myapp.com",
75
+ model={
76
+ "name": "John",
77
+ "company_name": "My App",
78
+ "action_url": "https://myapp.com/verify?token=abc123"
79
+ },
80
+ tag="welcome"
81
+ )
82
+ print(f"Email sent: {result['message_id']}")
83
+ """
84
+ body = {
85
+ "template_alias": template_alias,
86
+ "to": to,
87
+ "from": from_email,
88
+ "model": model
89
+ }
90
+
91
+ if tag:
92
+ body["tag"] = tag
93
+ if reply_to:
94
+ body["reply_to"] = reply_to
95
+
96
+ return await self._client._request(
97
+ endpoint="/api/courier/send",
98
+ body=body
99
+ )
100
+
101
+ # Convenience methods for common templates
102
+
103
+ async def send_welcome(
104
+ self,
105
+ to: str,
106
+ from_email: str,
107
+ name: str,
108
+ product_name: str,
109
+ action_url: Optional[str] = None,
110
+ **extra_model
111
+ ) -> Dict[str, Any]:
112
+ """
113
+ Send welcome email.
114
+
115
+ Args:
116
+ to: Recipient email
117
+ from_email: Sender email
118
+ name: User's name
119
+ product_name: Your product/app name
120
+ action_url: Optional action button URL
121
+ **extra_model: Additional template variables
122
+
123
+ Returns:
124
+ Send result dict
125
+ """
126
+ model = {
127
+ "name": name,
128
+ "product_name": product_name,
129
+ **extra_model
130
+ }
131
+ if action_url:
132
+ model["action_url"] = action_url
133
+
134
+ return await self.send(
135
+ template_alias="welcome",
136
+ to=to,
137
+ from_email=from_email,
138
+ model=model,
139
+ tag="welcome"
140
+ )
141
+
142
+ async def send_password_reset(
143
+ self,
144
+ to: str,
145
+ from_email: str,
146
+ name: str,
147
+ reset_url: str,
148
+ product_name: str,
149
+ **extra_model
150
+ ) -> Dict[str, Any]:
151
+ """
152
+ Send password reset email.
153
+
154
+ Args:
155
+ to: Recipient email
156
+ from_email: Sender email
157
+ name: User's name
158
+ reset_url: Password reset link
159
+ product_name: Your product/app name
160
+ **extra_model: Additional template variables
161
+
162
+ Returns:
163
+ Send result dict
164
+ """
165
+ return await self.send(
166
+ template_alias="password-reset",
167
+ to=to,
168
+ from_email=from_email,
169
+ model={
170
+ "name": name,
171
+ "action_url": reset_url,
172
+ "product_name": product_name,
173
+ **extra_model
174
+ },
175
+ tag="password-reset"
176
+ )
177
+
178
+ async def send_email_verification(
179
+ self,
180
+ to: str,
181
+ from_email: str,
182
+ name: str,
183
+ verify_url: str,
184
+ product_name: str,
185
+ **extra_model
186
+ ) -> Dict[str, Any]:
187
+ """
188
+ Send email verification email.
189
+
190
+ Args:
191
+ to: Recipient email
192
+ from_email: Sender email
193
+ name: User's name
194
+ verify_url: Email verification link
195
+ product_name: Your product/app name
196
+ **extra_model: Additional template variables
197
+
198
+ Returns:
199
+ Send result dict
200
+ """
201
+ return await self.send(
202
+ template_alias="email-verification",
203
+ to=to,
204
+ from_email=from_email,
205
+ model={
206
+ "name": name,
207
+ "action_url": verify_url,
208
+ "product_name": product_name,
209
+ **extra_model
210
+ },
211
+ tag="email-verification"
212
+ )
213
+
214
+ async def send_invitation(
215
+ self,
216
+ to: str,
217
+ from_email: str,
218
+ name: str,
219
+ invite_url: str,
220
+ inviter_name: str,
221
+ product_name: str,
222
+ **extra_model
223
+ ) -> Dict[str, Any]:
224
+ """
225
+ Send user invitation email.
226
+
227
+ Args:
228
+ to: Recipient email
229
+ from_email: Sender email
230
+ name: Invitee's name
231
+ invite_url: Invitation accept link
232
+ inviter_name: Name of person who invited
233
+ product_name: Your product/app name
234
+ **extra_model: Additional template variables
235
+
236
+ Returns:
237
+ Send result dict
238
+ """
239
+ return await self.send(
240
+ template_alias="invitation",
241
+ to=to,
242
+ from_email=from_email,
243
+ model={
244
+ "name": name,
245
+ "action_url": invite_url,
246
+ "inviter_name": inviter_name,
247
+ "product_name": product_name,
248
+ **extra_model
249
+ },
250
+ tag="invitation"
251
+ )