Skip to content

Commit ce79d4a

Browse files
committed
fix attachment types
Signed-off-by: gabriel miranda <gabrielmfern@outlook.com>
1 parent 5fb1ac5 commit ce79d4a

1 file changed

Lines changed: 51 additions & 22 deletions

File tree

resend/emails/_received_email.py

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
from typing import Dict, List, Optional
22

3-
from typing_extensions import NotRequired, TypedDict
3+
from typing_extensions import Literal, NotRequired, TypedDict
44

55
from resend._base_response import BaseResponse
66

77

88
class EmailAttachment(TypedDict):
99
"""
10-
EmailAttachment type that wraps an attachment object from an email.
10+
Attachment metadata embedded in a received (inbound) email, as returned by
11+
``Emails.Receiving.get`` and ``Emails.Receiving.list``.
12+
13+
These are raw values from the inbound MIME parts, so ``filename``,
14+
``content_id``, and ``content_disposition`` can be null (e.g. S/MIME
15+
signatures or calendar invites), and ``size`` is null in list responses.
1116
1217
Attributes:
1318
id (str): The attachment ID.
1419
filename (Optional[str]): The filename of the attachment.
1520
content_type (str): The content type of the attachment.
21+
content_id (Optional[str]): The content ID for inline attachments.
1622
content_disposition (Optional[str]): The content disposition of the attachment.
17-
content_id (NotRequired[str]): The content ID for inline attachments.
18-
size (NotRequired[int]): The size of the attachment in bytes.
23+
size (Optional[int]): The size of the attachment in bytes.
1924
"""
2025

2126
id: str
@@ -30,58 +35,59 @@ class EmailAttachment(TypedDict):
3035
"""
3136
The content type of the attachment.
3237
"""
33-
content_disposition: Optional[str]
38+
content_id: Optional[str]
3439
"""
35-
The content disposition of the attachment.
40+
The content ID for inline attachments.
3641
"""
37-
content_id: NotRequired[str]
42+
content_disposition: Optional[str]
3843
"""
39-
The content ID for inline attachments.
44+
The content disposition of the attachment.
4045
"""
41-
size: NotRequired[int]
46+
size: Optional[int]
4247
"""
4348
The size of the attachment in bytes.
4449
"""
4550

4651

47-
class EmailAttachmentDetails(TypedDict):
52+
class AttachmentWithSignedUrl(TypedDict):
4853
"""
49-
EmailAttachmentDetails type that wraps an email attachment with download details.
54+
Attachment returned by the signed-URL endpoints that list or retrieve
55+
attachments (for both sent and received emails).
5056
5157
Attributes:
52-
object (str): The object type.
5358
id (str): The attachment ID.
54-
filename (Optional[str]): The filename of the attachment.
59+
filename (NotRequired[str]): The filename of the attachment.
5560
content_type (str): The content type of the attachment.
56-
content_disposition (Optional[str]): The content disposition of the attachment.
5761
content_id (NotRequired[str]): The content ID for inline attachments.
62+
content_disposition (Literal["inline", "attachment"]): The content disposition of the attachment.
63+
size (int): The size of the attachment in bytes.
5864
download_url (str): The URL to download the attachment.
5965
expires_at (str): When the download URL expires.
6066
"""
6167

62-
object: str
63-
"""
64-
The object type.
65-
"""
6668
id: str
6769
"""
6870
The attachment ID.
6971
"""
70-
filename: Optional[str]
72+
filename: NotRequired[str]
7173
"""
7274
The filename of the attachment.
7375
"""
7476
content_type: str
7577
"""
7678
The content type of the attachment.
7779
"""
78-
content_disposition: Optional[str]
80+
content_id: NotRequired[str]
81+
"""
82+
The content ID for inline attachments.
83+
"""
84+
content_disposition: Literal["inline", "attachment"]
7985
"""
8086
The content disposition of the attachment.
8187
"""
82-
content_id: NotRequired[str]
88+
size: int
8389
"""
84-
The content ID for inline attachments.
90+
The size of the attachment in bytes.
8591
"""
8692
download_url: str
8793
"""
@@ -93,6 +99,29 @@ class EmailAttachmentDetails(TypedDict):
9399
"""
94100

95101

102+
class EmailAttachmentDetails(AttachmentWithSignedUrl):
103+
"""
104+
A single attachment retrieved from a dedicated attachment endpoint. Same as
105+
``AttachmentWithSignedUrl`` with an added ``object`` field.
106+
107+
Attributes:
108+
object (str): The object type.
109+
id (str): The attachment ID.
110+
filename (NotRequired[str]): The filename of the attachment.
111+
content_type (str): The content type of the attachment.
112+
content_id (NotRequired[str]): The content ID for inline attachments.
113+
content_disposition (Literal["inline", "attachment"]): The content disposition of the attachment.
114+
size (int): The size of the attachment in bytes.
115+
download_url (str): The URL to download the attachment.
116+
expires_at (str): When the download URL expires.
117+
"""
118+
119+
object: str
120+
"""
121+
The object type.
122+
"""
123+
124+
96125
# Uses functional typed dict syntax here in order to support "from" reserved keyword
97126
_ReceivedEmailFromParam = TypedDict(
98127
"_ReceivedEmailFromParam",

0 commit comments

Comments
 (0)