Skip to content

Commit 357f786

Browse files
ci-stytchStytch Codegen Bot
andauthored
Add DFP Email Risk endpoint (#306)
Co-authored-by: Stytch Codegen Bot <support@stytch.com>
1 parent ba849bf commit 357f786

5 files changed

Lines changed: 138 additions & 1 deletion

File tree

stytch/consumer/api/fraud.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from __future__ import annotations
88

9+
from stytch.consumer.api.fraud_email import Email
910
from stytch.consumer.api.fraud_fingerprint import Fingerprint
1011
from stytch.consumer.api.fraud_rules import Rules
1112
from stytch.consumer.api.fraud_verdict_reasons import VerdictReasons
@@ -35,3 +36,8 @@ def __init__(
3536
sync_client=self.sync_client,
3637
async_client=self.async_client,
3738
)
39+
self.email = Email(
40+
api_base=self.api_base,
41+
sync_client=self.sync_client,
42+
async_client=self.async_client,
43+
)

stytch/consumer/api/fraud_email.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# !!!
2+
# WARNING: This file is autogenerated
3+
# Only modify code within MANUAL() sections
4+
# or your changes may be overwritten later!
5+
# !!!
6+
7+
from __future__ import annotations
8+
9+
from typing import Any, Dict
10+
11+
from stytch.consumer.models.fraud_email import RiskResponse
12+
from stytch.core.api_base import ApiBase
13+
from stytch.core.http.client import AsyncClient, SyncClient
14+
15+
16+
class Email:
17+
def __init__(
18+
self, api_base: ApiBase, sync_client: SyncClient, async_client: AsyncClient
19+
) -> None:
20+
self.api_base = api_base
21+
self.sync_client = sync_client
22+
self.async_client = async_client
23+
24+
def risk(
25+
self,
26+
email_address: str,
27+
) -> RiskResponse:
28+
"""Get risk information for a specific email address.
29+
The response will contain a recommended action (`ALLOW`, `BLOCK`, or `CHALLENGE`) and a more granular `risk_score`.
30+
You can also check the `address_information` and `domain_information` fields for more information about the email address and email domain.
31+
32+
This feature is in beta. Reach out to us [here](mailto:fraud-team@stytch.com?subject=Email_Intelligence_Early_Access) if you'd like to request early access.
33+
34+
Fields:
35+
- email_address: The email address to check.
36+
""" # noqa
37+
headers: Dict[str, str] = {}
38+
data: Dict[str, Any] = {
39+
"email_address": email_address,
40+
}
41+
42+
url = self.api_base.url_for("/v1/email/risk", data)
43+
res = self.sync_client.post(url, data, headers)
44+
return RiskResponse.from_json(res.response.status_code, res.json)
45+
46+
async def risk_async(
47+
self,
48+
email_address: str,
49+
) -> RiskResponse:
50+
"""Get risk information for a specific email address.
51+
The response will contain a recommended action (`ALLOW`, `BLOCK`, or `CHALLENGE`) and a more granular `risk_score`.
52+
You can also check the `address_information` and `domain_information` fields for more information about the email address and email domain.
53+
54+
This feature is in beta. Reach out to us [here](mailto:fraud-team@stytch.com?subject=Email_Intelligence_Early_Access) if you'd like to request early access.
55+
56+
Fields:
57+
- email_address: The email address to check.
58+
""" # noqa
59+
headers: Dict[str, str] = {}
60+
data: Dict[str, Any] = {
61+
"email_address": email_address,
62+
}
63+
64+
url = self.api_base.url_for("/v1/email/risk", data)
65+
res = await self.async_client.post(url, data, headers)
66+
return RiskResponse.from_json(res.response.status, res.json)

stytch/consumer/models/fraud.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@ class ASNProperties(pydantic.BaseModel):
6363
network: str
6464

6565

66+
class AddressInformation(pydantic.BaseModel):
67+
"""
68+
Fields:
69+
- has_known_bounces: Whether email sent to this address is known to have bounced previously.
70+
- has_valid_syntax: Whether this email address is valid.
71+
- is_suspected_role_address: Whether the local part of the email appears to be a role or group, rather than an individual end user.
72+
- normalized_email: The normalized email address after removing '.' characters and any characters after a '+'.
73+
- tumbling_character_count: The number of '.' and '+' characters in the email address. A higher tumbling count indicates a higher potential for fraud.
74+
""" # noqa
75+
76+
has_known_bounces: bool
77+
has_valid_syntax: bool
78+
is_suspected_role_address: bool
79+
normalized_email: str
80+
tumbling_character_count: int
81+
82+
6683
class BrowserProperties(pydantic.BaseModel):
6784
"""
6885
Fields:
@@ -72,6 +89,17 @@ class BrowserProperties(pydantic.BaseModel):
7289
user_agent: str
7390

7491

92+
class DomainInformation(pydantic.BaseModel):
93+
"""
94+
Fields:
95+
- has_mx_or_a_record: Whether the email has appropriate DNS records to deliver a message.
96+
- is_disposable_domain: Whether the email domain is known to be disposable.
97+
""" # noqa
98+
99+
has_mx_or_a_record: bool
100+
is_disposable_domain: bool
101+
102+
75103
class Fingerprints(pydantic.BaseModel):
76104
"""
77105
Fields:
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# !!!
2+
# WARNING: This file is autogenerated
3+
# Only modify code within MANUAL() sections
4+
# or your changes may be overwritten later!
5+
# !!!
6+
7+
from __future__ import annotations
8+
9+
import enum
10+
11+
from stytch.consumer.models.fraud import AddressInformation, DomainInformation
12+
from stytch.core.response_base import ResponseBase
13+
14+
15+
class RiskResponseAction(str, enum.Enum):
16+
ALLOW = "ALLOW"
17+
CHALLENGE = "CHALLENGE"
18+
BLOCK = "BLOCK"
19+
20+
21+
class RiskResponse(ResponseBase):
22+
"""Response type for `Email.risk`.
23+
Fields:
24+
- address_information: Information about the email address.
25+
- domain_information: Information about the email domain.
26+
- action: The suggested action based on the attributes of the email address. The available actions are:
27+
* `ALLOW` - This email is most likely safe to send to and not fraudulent.
28+
* `BLOCK` - This email is invalid or exhibits signs of fraud. We recommend blocking the end user.
29+
* `CHALLENGE` - This email has some potentially fraudulent attributes. We recommend increased friction such as 2FA or other forms of extended user verification before allowing the privileged action to proceed.
30+
31+
- risk_score: A score from 0 to 100 indicating how risky the email is. 100 is the most risky.
32+
""" # noqa
33+
34+
address_information: AddressInformation
35+
domain_information: DomainInformation
36+
action: RiskResponseAction
37+
risk_score: int

stytch/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "14.1.0"
1+
__version__ = "14.2.0"

0 commit comments

Comments
 (0)