Skip to content

Add supported countries and states endpoints for domain registration#1282

Merged
oguzkocer merged 7 commits intotrunkfrom
domain-supported-country-and-states
Apr 22, 2026
Merged

Add supported countries and states endpoints for domain registration#1282
oguzkocer merged 7 commits intotrunkfrom
domain-supported-country-and-states

Conversation

@oguzkocer
Copy link
Copy Markdown
Contributor

No description provided.

@oguzkocer oguzkocer added this to the 0.2 milestone Apr 15, 2026
@oguzkocer oguzkocer added the Rust label Apr 15, 2026
@oguzkocer oguzkocer changed the title Add supported countries and states endpoints for domain registration Add supported countries and states endpoints Apr 15, 2026
@oguzkocer oguzkocer changed the title Add supported countries and states endpoints Add supported countries and states endpoints for domain registration Apr 15, 2026
@wpmobilebot
Copy link
Copy Markdown
Collaborator

wpmobilebot commented Apr 15, 2026

XCFramework Build

This PR's XCFramework is available for testing. Add to your Package.swift:

.package(url: "https://github.com/automattic/wordpress-rs", branch: "pr-build/1282")

Built from b738f36

@oguzkocer oguzkocer marked this pull request as ready for review April 15, 2026 06:15
@oguzkocer oguzkocer enabled auto-merge (squash) April 15, 2026 06:15
@oguzkocer oguzkocer requested a review from jkmassel April 15, 2026 06:16
#[get(url = "/domains/supported-countries", output = Vec<SupportedCountry>)]
SupportedCountries,
#[get(url = "/domains/supported-states/<country_code>", output = Vec<SupportedState>)]
SupportedStates,
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.

Both of these could be pretty trivially added to the WP.com e2e test suite for ongoing validation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added in 99c2ea3.

@oguzkocer oguzkocer force-pushed the domain-supported-country-and-states branch from cac7ec7 to 2b498e7 Compare April 16, 2026 20:37
@oguzkocer oguzkocer requested a review from jkmassel April 16, 2026 20:54
Copy link
Copy Markdown
Contributor

@jkmassel jkmassel left a comment

Choose a reason for hiding this comment

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

Just one question about the CountryCode that's worth checking before this lands.

Comment thread wp_api/src/wp_com/domains.rs Outdated
#[derive(Debug, Clone, Serialize, Deserialize, uniffi::Record)]
pub struct SupportedCountry {
/// ISO 3166-1 alpha-2 code (e.g. `"US"`).
pub code: String,
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.

Should this be CountryCode?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This didn't work when we didn't have the enum for the divider, but should be good now. Addressed in 05815c3.

#[serde(untagged)]
enum SupportedCountryEntry {
Country(SupportedCountry),
Divider {
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.

If someone were to ever align the response type to match Country here, this would no longer match properly. We could solve it by assuming an empty code and name are the separator, but it's pretty theoretical.

This note is mostly just in case anyone ever has to come back to it down the line.

.collect()
};

let divider_pos = entries
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.

If more than one separator is found, we just use the position of the first one and subsequent ones are filtered out. This seems fine.

@oguzkocer oguzkocer force-pushed the domain-supported-country-and-states branch from 5e76a97 to 05815c3 Compare April 18, 2026 03:50
@oguzkocer oguzkocer requested a review from jkmassel April 18, 2026 03:51
Copy link
Copy Markdown
Contributor

@jkmassel jkmassel left a comment

Choose a reason for hiding this comment

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

Approved pending merge fixes, though I left a small improvement suggestion for comparison, and I'm wondering if we should reuse CountryCode

Comment thread wp_api/src/wp_com/domains.rs Outdated
/// Additional country codes whose tax rules apply alongside this one.
#[serde(default)]
#[uniffi(default = [])]
pub tax_country_codes: Vec<String>,
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.

Should this be Vec<CountryCode>?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in b738f36

let us = response
.featured
.iter()
.find(|c| c.code.0 == "US")
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.

Should we implement From<&str> for CountryCode? There's a few spots like this that seem to suggest it'd be helpful

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in a9bbc11

Comment thread wp_com_e2e/src/domains_tests.rs Outdated
let states = ctx
.client
.domains()
.supported_states(&CountryCode("DE".to_string()))
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.

This was the other case that had me wondering about From<&str>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in a9bbc11

- Introduce `CountryCode` newtype for ISO 3166-1 alpha-2 codes
- Add `SupportedCountry` and `SupportedState` types with deserialization
- Wire up `GET /domains/supported-countries` and `GET /domains/supported-states/<country_code>` endpoints
- Replace segments test fixtures with synthetic data
…ries

The WordPress.com supported-countries API returns a flat array with a
sentinel divider separating featured countries from the full list.
Introduce a SupportedCountries wrapper that deserializes via an internal
untagged enum (Country | Divider), splits at the sentinel, and exposes
`featured` and `all` vectors. This also lets us tighten vat_supported,
tax_needs_city, and tax_needs_subdivision from Option<bool> to bool
since the sentinel (the only entry missing those fields) is now filtered
out during deserialization.
Change tax_needs_address and tax_needs_organization from Option<bool> to
bool, and tax_country_codes from Option<Vec<String>> to Vec<String>,
defaulting to false/empty when absent. The three required bool fields
(vat_supported, tax_needs_city, tax_needs_subdivision) still lack
defaults, which is sufficient for the untagged enum to reject the
divider entry.
@oguzkocer oguzkocer force-pushed the domain-supported-country-and-states branch from 05815c3 to b738f36 Compare April 22, 2026 19:49
@oguzkocer oguzkocer merged commit 0d8cf99 into trunk Apr 22, 2026
33 checks passed
@oguzkocer oguzkocer deleted the domain-supported-country-and-states branch April 22, 2026 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants