Skip to content

Commit ded2a70

Browse files
ci-stytchStytch Codegen Bot
andauthored
Add DFP Email Risk endpoint (#279)
Co-authored-by: Stytch Codegen Bot <support@stytch.com>
1 parent 80413ec commit ded2a70

File tree

5 files changed

+145
-1
lines changed

5 files changed

+145
-1
lines changed

stytch/config/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package config
22

3-
const APIVersion = "17.0.0"
3+
const APIVersion = "17.1.0"

stytch/consumer/fraud.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type FraudClient struct {
1515
Fingerprint *FraudFingerprintClient
1616
Rules *FraudRulesClient
1717
VerdictReasons *FraudVerdictReasonsClient
18+
Email *FraudEmailClient
1819
}
1920

2021
func NewFraudClient(c stytch.Client) *FraudClient {
@@ -24,5 +25,6 @@ func NewFraudClient(c stytch.Client) *FraudClient {
2425
Fingerprint: NewFraudFingerprintClient(c),
2526
Rules: NewFraudRulesClient(c),
2627
VerdictReasons: NewFraudVerdictReasonsClient(c),
28+
Email: NewFraudEmailClient(c),
2729
}
2830
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package email
2+
3+
// !!!
4+
// WARNING: This file is autogenerated
5+
// Only modify code within MANUAL() sections
6+
// or your changes may be overwritten later!
7+
// !!!
8+
9+
import (
10+
"github.com/stytchauth/stytch-go/v17/stytch/consumer/fraud"
11+
)
12+
13+
// RiskParams: Request type for `Email.Risk`.
14+
type RiskParams struct {
15+
// EmailAddress: The email address to check.
16+
EmailAddress string `json:"email_address,omitempty"`
17+
}
18+
19+
// RiskResponse: Response type for `Email.Risk`.
20+
type RiskResponse struct {
21+
// RequestID: Globally unique UUID that is returned with every API call. This value is important to log for
22+
// debugging purposes; we may ask for this value to help identify a specific API call when helping you
23+
// debug an issue.
24+
RequestID string `json:"request_id,omitempty"`
25+
// AddressInformation: Information about the email address.
26+
AddressInformation fraud.AddressInformation `json:"address_information,omitempty"`
27+
// DomainInformation: Information about the email domain.
28+
DomainInformation fraud.DomainInformation `json:"domain_information,omitempty"`
29+
// Action: The suggested action based on the attributes of the email address. The available actions are:
30+
// * `ALLOW` - This email is most likely safe to send to and not fraudulent.
31+
// * `BLOCK` - This email is invalid or exhibits signs of fraud. We recommend blocking the end user.
32+
// * `CHALLENGE` - This email has some potentially fraudulent attributes. We recommend increased friction
33+
// such as 2FA or other forms of extended user verification before allowing the privileged action to
34+
// proceed.
35+
//
36+
Action RiskResponseAction `json:"action,omitempty"`
37+
// RiskScore: A score from 0 to 100 indicating how risky the email is. 100 is the most risky.
38+
RiskScore int32 `json:"risk_score,omitempty"`
39+
// StatusCode: The HTTP status code of the response. Stytch follows standard HTTP response status code
40+
// patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX
41+
// are server errors.
42+
StatusCode int32 `json:"status_code,omitempty"`
43+
}
44+
45+
type RiskResponseAction string
46+
47+
const (
48+
RiskResponseActionALLOW RiskResponseAction = "ALLOW"
49+
RiskResponseActionCHALLENGE RiskResponseAction = "CHALLENGE"
50+
RiskResponseActionBLOCK RiskResponseAction = "BLOCK"
51+
)

stytch/consumer/fraud/types.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,37 @@ type ASNProperties struct {
2020
Network string `json:"network,omitempty"`
2121
}
2222

23+
// AddressInformation:
24+
type AddressInformation struct {
25+
// HasKnownBounces: Whether email sent to this address is known to have bounced previously.
26+
HasKnownBounces bool `json:"has_known_bounces,omitempty"`
27+
// HasValidSyntax: Whether this email address is valid.
28+
HasValidSyntax bool `json:"has_valid_syntax,omitempty"`
29+
// IsSuspectedRoleAddress: Whether the local part of the email appears to be a role or group, rather than
30+
// an individual end user.
31+
IsSuspectedRoleAddress bool `json:"is_suspected_role_address,omitempty"`
32+
// NormalizedEmail: The normalized email address after removing '.' characters and any characters after a
33+
// '+'.
34+
NormalizedEmail string `json:"normalized_email,omitempty"`
35+
// TumblingCharacterCount: The number of '.' and '+' characters in the email address. A higher tumbling
36+
// count indicates a higher potential for fraud.
37+
TumblingCharacterCount int32 `json:"tumbling_character_count,omitempty"`
38+
}
39+
2340
// BrowserProperties:
2441
type BrowserProperties struct {
2542
// UserAgent: The user agent of the user's browser.
2643
UserAgent string `json:"user_agent,omitempty"`
2744
}
2845

46+
// DomainInformation:
47+
type DomainInformation struct {
48+
// HasMXOrARecord: Whether the email has appropriate DNS records to deliver a message.
49+
HasMXOrARecord bool `json:"has_mx_or_a_record,omitempty"`
50+
// IsDisposableDomain: Whether the email domain is known to be disposable.
51+
IsDisposableDomain bool `json:"is_disposable_domain,omitempty"`
52+
}
53+
2954
// Fingerprints:
3055
type Fingerprints struct {
3156
// NetworkFingerprint: Combination of signals associated with a specific network commonly known as TLS

stytch/consumer/fraud_email.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package consumer
2+
3+
// !!!
4+
// WARNING: This file is autogenerated
5+
// Only modify code within MANUAL() sections
6+
// or your changes may be overwritten later!
7+
// !!!
8+
9+
import (
10+
"context"
11+
"encoding/json"
12+
13+
"github.com/stytchauth/stytch-go/v17/stytch"
14+
"github.com/stytchauth/stytch-go/v17/stytch/consumer/fraud/email"
15+
"github.com/stytchauth/stytch-go/v17/stytch/stytcherror"
16+
)
17+
18+
type FraudEmailClient struct {
19+
C stytch.Client
20+
}
21+
22+
func NewFraudEmailClient(c stytch.Client) *FraudEmailClient {
23+
return &FraudEmailClient{
24+
C: c,
25+
}
26+
}
27+
28+
// Risk: Get risk information for a specific email address.
29+
// The response will contain a recommended action (`ALLOW`, `BLOCK`, or `CHALLENGE`) and a more granular
30+
// `risk_score`.
31+
// You can also check the `address_information` and `domain_information` fields for more information about
32+
// the email address and email domain.
33+
//
34+
// This feature is in beta. Reach out to us
35+
// [here](mailto:fraud-team@stytch.com?subject=Email_Intelligence_Early_Access) if you'd like to request
36+
// early access.
37+
func (c *FraudEmailClient) Risk(
38+
ctx context.Context,
39+
body *email.RiskParams,
40+
) (*email.RiskResponse, error) {
41+
var jsonBody []byte
42+
var err error
43+
if body != nil {
44+
jsonBody, err = json.Marshal(body)
45+
if err != nil {
46+
return nil, stytcherror.NewClientLibraryError("error marshaling request body")
47+
}
48+
}
49+
50+
headers := make(map[string][]string)
51+
52+
var retVal email.RiskResponse
53+
err = c.C.NewRequest(
54+
ctx,
55+
stytch.RequestParams{
56+
Method: "POST",
57+
Path: "/v1/email/risk",
58+
QueryParams: nil,
59+
Body: jsonBody,
60+
V: &retVal,
61+
Headers: headers,
62+
BaseURLType: "FRAUD",
63+
},
64+
)
65+
return &retVal, err
66+
}

0 commit comments

Comments
 (0)