Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions src/main/java/com/resend/services/domains/DomainClaims.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.resend.services.domains;

import com.resend.core.exception.ResendException;
import com.resend.core.net.AbstractHttpResponse;
import com.resend.core.net.HttpMethod;
import com.resend.core.service.BaseService;
import com.resend.services.domains.model.ClaimDomainOptions;
import com.resend.services.domains.model.DomainClaimResponseSuccess;
import okhttp3.MediaType;

/**
* Represents the Resend Domain Claims module.
*/
public final class DomainClaims extends BaseService {

/**
* Constructs an instance of the {@code DomainClaims} class.
*
* @param apiKey The apiKey used for authentication.
*/
public DomainClaims(final String apiKey) {
super(apiKey);
}

/**
* Claims a domain already verified by another team.
*
* @param claimDomainOptions The request object containing the domain claim details.
* @return A DomainClaimResponseSuccess representing the created claim.
* @throws ResendException If an error occurs during the domain claim process.
*/
public DomainClaimResponseSuccess create(ClaimDomainOptions claimDomainOptions) throws ResendException {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Missing null validation on claimDomainOptions parameter in create(). Passing null serializes to the string "null", producing a malformed request body.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/main/java/com/resend/services/domains/DomainClaims.java, line 32:

<comment>Missing null validation on `claimDomainOptions` parameter in `create()`. Passing null serializes to the string `"null"`, producing a malformed request body.</comment>

<file context>
@@ -0,0 +1,79 @@
+     * @return A DomainClaimResponseSuccess representing the created claim.
+     * @throws ResendException If an error occurs during the domain claim process.
+     */
+    public DomainClaimResponseSuccess create(ClaimDomainOptions claimDomainOptions) throws ResendException {
+        String payload = super.resendMapper.writeValue(claimDomainOptions);
+        AbstractHttpResponse<String> response = httpClient.perform("/domains/claim", super.apiKey, HttpMethod.POST, payload, MediaType.get("application/json"));
</file context>

String payload = super.resendMapper.writeValue(claimDomainOptions);
AbstractHttpResponse<String> response = httpClient.perform("/domains/claim", super.apiKey, HttpMethod.POST, payload, MediaType.get("application/json"));

if (!response.isSuccessful()) {
throw new ResendException(response.getCode(), response.getBody());
}

String responseBody = response.getBody();
return resendMapper.readValue(responseBody, DomainClaimResponseSuccess.class);
}

/**
* Retrieves the latest claim for a domain.
*
* @param domainId The placeholder domain ID returned when the claim was created.
* @return A DomainClaimResponseSuccess representing the current claim state.
* @throws ResendException If an error occurs during the retrieval process.
*/
public DomainClaimResponseSuccess get(String domainId) throws ResendException {
AbstractHttpResponse<String> response = httpClient.perform("/domains/" + domainId + "/claim", super.apiKey, HttpMethod.GET, null, MediaType.get("application/json"));

if (!response.isSuccessful()) {
throw new ResendException(response.getCode(), response.getBody());
}

String responseBody = response.getBody();
return resendMapper.readValue(responseBody, DomainClaimResponseSuccess.class);
}

/**
* Triggers DNS verification for a domain claim.
*
* @param domainId The placeholder domain ID returned when the claim was created.
* @return A DomainClaimResponseSuccess representing the claim after verification is triggered.
* @throws ResendException If an error occurs during the verification process.
*/
public DomainClaimResponseSuccess verify(String domainId) throws ResendException {
AbstractHttpResponse<String> response = httpClient.perform("/domains/" + domainId + "/claim/verify", super.apiKey, HttpMethod.POST, "", null);

if (!response.isSuccessful()) {
throw new ResendException(response.getCode(), response.getBody());
}

String responseBody = response.getBody();
return resendMapper.readValue(responseBody, DomainClaimResponseSuccess.class);
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/resend/services/domains/Domains.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ public UpdateDomainResponseSuccess update(UpdateDomainOptions updateDomainOption
return resendMapper.readValue(responseBody, UpdateDomainResponseSuccess.class);
}

/**
* Returns a DomainClaims object that can be used to interact with the Domain Claims service.
*
* @return A DomainClaims object.
*/
public DomainClaims claims() {
return new DomainClaims(apiKey);
}

/**
* Deletes a domain based on the provided domain ID and returns a RemoveDomainResponse.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
package com.resend.services.domains.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Represents a request to claim a domain already verified by another team.
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ClaimDomainOptions {

@JsonProperty("name")
private final String name;

@JsonProperty("region")
private final String region;

@JsonProperty("custom_return_path")
private final String customReturnPath;

@JsonProperty("open_tracking")
private final Boolean openTracking;

@JsonProperty("click_tracking")
private final Boolean clickTracking;

@JsonProperty("tracking_subdomain")
private final String trackingSubdomain;

/**
* Constructs a ClaimDomainOptions object using the provided builder.
*
* @param builder The builder to construct the ClaimDomainOptions from.
*/
public ClaimDomainOptions(Builder builder) {
this.name = builder.name;
this.region = builder.region;
this.customReturnPath = builder.customReturnPath;
this.openTracking = builder.openTracking;
this.clickTracking = builder.clickTracking;
this.trackingSubdomain = builder.trackingSubdomain;
}

/**
* Get the domain name to claim.
*
* @return The domain name.
*/
public String getName() {
return name;
}

/**
* Get the region where emails will be sent from.
*
* @return The region.
*/
public String getRegion() {
return region;
}

/**
* Get the custom return path subdomain.
*
* @return The custom return path.
*/
public String getCustomReturnPath() {
return customReturnPath;
}

/**
* Get whether open tracking is enabled.
*
* @return The open tracking setting.
*/
public Boolean getOpenTracking() {
return openTracking;
}

/**
* Get whether click tracking is enabled.
*
* @return The click tracking setting.
*/
public Boolean getClickTracking() {
return clickTracking;
}

/**
* Get the subdomain used for click and open tracking.
*
* @return The tracking subdomain.
*/
public String getTrackingSubdomain() {
return trackingSubdomain;
}

/**
* Create a new builder instance for constructing ClaimDomainOptions objects.
*
* @return A new builder instance.
*/
public static Builder builder() {
return new Builder();
}

/**
* Builder class for constructing ClaimDomainOptions objects.
*/
public static class Builder {

/**
* Creates a new Builder instance.
*/
public Builder() {
}

private String name;
private String region;
private String customReturnPath;
private Boolean openTracking;
private Boolean clickTracking;
private String trackingSubdomain;

/**
* Set the domain name to claim.
*
* @param name The domain name.
* @return The builder instance.
*/
public Builder name(String name) {
this.name = name;
return this;
}

/**
* Set the region where emails will be sent from.
*
* @param region The region.
* @return The builder instance.
*/
public Builder region(String region) {
this.region = region;
return this;
}

/**
* Set the custom return path subdomain.
*
* @param customReturnPath The custom return path.
* @return The builder instance.
*/
public Builder customReturnPath(String customReturnPath) {
this.customReturnPath = customReturnPath;
return this;
}

/**
* Set whether open tracking is enabled.
*
* @param openTracking The open tracking setting.
* @return The builder instance.
*/
public Builder openTracking(Boolean openTracking) {
this.openTracking = openTracking;
return this;
}

/**
* Set whether click tracking is enabled.
*
* @param clickTracking The click tracking setting.
* @return The builder instance.
*/
public Builder clickTracking(Boolean clickTracking) {
this.clickTracking = clickTracking;
return this;
}

/**
* Set the subdomain used for click and open tracking.
*
* @param trackingSubdomain The tracking subdomain.
* @return The builder instance.
*/
public Builder trackingSubdomain(String trackingSubdomain) {
this.trackingSubdomain = trackingSubdomain;
return this;
}

/**
* Build a new ClaimDomainOptions object.
*
* @return A new ClaimDomainOptions object.
*/
public ClaimDomainOptions build() {
return new ClaimDomainOptions(this);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.resend.services.domains.model;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Represents the TXT DNS record returned within a domain claim response.
*/
public class DomainClaimRecord {

@JsonProperty("type")
private String type;

@JsonProperty("name")
private String name;

@JsonProperty("value")
private String value;

@JsonProperty("ttl")
private String ttl;

/**
* Default constructor.
*/
public DomainClaimRecord() {
}

/**
* Constructs a DomainClaimRecord with all fields.
*
* @param type The DNS record type.
* @param name The DNS record name.
* @param value The DNS record value.
* @param ttl The TTL for the DNS record.
*/
public DomainClaimRecord(final String type,
final String name,
final String value,
final String ttl) {
this.type = type;
this.name = name;
this.value = value;
this.ttl = ttl;
}

/**
* Get the DNS record type.
*
* @return The DNS record type.
*/
public String getType() {
return type;
}

/**
* Get the DNS record name.
*
* @return The DNS record name.
*/
public String getName() {
return name;
}

/**
* Get the DNS record value.
*
* @return The DNS record value.
*/
public String getValue() {
return value;
}

/**
* Get the TTL for the DNS record.
*
* @return The TTL.
*/
public String getTtl() {
return ttl;
}
}
Loading
Loading