k.commerce.address
Address management.
| Execution Context | Prerequisites | Typical Use |
|---|---|---|
KScript API (k.api.get / k.api.post), server-side <script env="server"> | None (built-in global geographic dataset) | Build cascading country/state/city selectors and resolve localized address metadata |
k.commerce.address provides address lookup helpers for countries, provinces/states, cities, and localized address details.
Quick Start
js
k.api.get(() => {
const countries = k.commerce.address.countries()
const provinces = k.commerce.address.provinces("China")
const cities = k.commerce.address.cities("China", "Fujian")
return {
countryCount: countries.length,
provinceCount: provinces.length,
citySample: cities.slice(0, 3)
}
})Quick Reference
| Method / Property | Description | Returns |
|---|---|---|
countries() | Get all countries with currency, flag, and localized names | Country[] |
provinces(country) | Get provinces/states for an English country name | Province[] |
cities(country, state) | Get cities for an English country and state name | City[] |
addressDetail(address) | Enrich an Address with localized country/province/city details | AddressDetail |
countries()
Get all country information. No parameters.
Returns: Country[]
js
k.api.get(() => {
const countries = k.commerce.address.countries()
return { count: countries.length, items: countries.slice(0, 3) }
})provinces()
Get list of provinces based on country name.
| Parameter | Type | Required | Description |
|---|---|---|---|
country | string | Yes | Country name (English) |
Returns: Province[]
js
k.api.get(() => {
const provinces = k.commerce.address.provinces("China")
return { count: provinces.length, items: provinces.slice(0, 3) }
})cities()
Get a list of cities by country and province/state.
| Parameter | Type | Required | Description |
|---|---|---|---|
country | string | Yes | Country name (English) |
state | string | Yes | Province/state name (English) |
Returns: City[]
js
k.api.get(() => {
const cities = k.commerce.address.cities("China", "Fujian")
return { count: cities.length, items: cities.slice(0, 3) }
})addressDetail()
Resolve an Address object into a detailed address object with country, province, and city translation metadata.
Runtime Behavior Notes
country,province, andcitymust match the English names in Kooboo's built-in dataset to populatecountryDetail,provinceDetail, andcityDetail; unmatched entries returnnull.AddressService.AddressDetailcurrently does not copy the inputzipfield, sozipon the returnedAddressDetailis alwaysnullat runtime.
| Parameter | Type | Required | Description |
|---|---|---|---|
address | Address | Yes | Address object |
Returns: AddressDetail
js
k.api.post(() => {
return k.commerce.address.addressDetail({
country: "China",
province: "Fujian",
city: "Xiamen",
address1: "Software Park",
address2: "",
zip: "361000", // Input field only; AddressDetail.zip is always null at runtime
firstName: "Test",
lastName: "User",
phone: "13800138000",
isDefault: true
})
})Structure
Country property
| Property | Description | Type |
|---|---|---|
code | Country code | string |
name | Country name (English) | string |
nameTranslations | Country name translations | NameTranslation[] |
currency | Currency code | string |
currencySymbol | Currency symbol | string |
emojiFlag | Flag emoji | string |
Province attribute
| Property | Description | Type |
|---|---|---|
country | Country name (English) | string |
name | Province name (English) | string |
nameTranslations | Province name translations | NameTranslation[] |
City property
| Property | Description | Type |
|---|---|---|
country | Country name (English) | string |
province | Province name (English) | string |
name | City name (English) | string |
nameTranslations | City name translations | NameTranslation[] |
NameTranslation Property
| Property | Description | Type |
|---|---|---|
key | Language code | string |
value | Translated string | string |
AddressDetail Property
| Property | Description | Type |
|---|---|---|
address1 | Address line 1 | string |
address2 | Address line 2 | string |
city | City name | string |
cityDetail | City detail (null when unmatched) | City | null |
country | Country name | string |
countryDetail | Country detail (null when unmatched) | Country | null |
firstName | First name | string |
lastName | Last name | string |
phone | Phone | string |
province | Province/state name | string |
provinceDetail | Province detail (null when unmatched) | Province | null |
zip | Postal code (always null at runtime because AddressService does not copy input zip) | string | null |
TypeScript Definitions
Show full TypeScript definitions
ts
interface KAddress {
countries(): Country[];
provinces(country: string): Province[];
cities(country: string, state: string): City[];
addressDetail(address: any): AddressDetail;
}
interface Country {
code: string;
name: string;
nameTranslations: any;
currency: string;
currencySymbol: string;
emojiFlag: string;
}
interface Province {
country: string;
name: string;
nameTranslations: any;
}
interface City {
country: string;
province: string;
name: string;
nameTranslations: any;
}
interface AddressDetail {
address1: string;
address2: string;
city: string;
cityDetail: City;
country: string;
countryDetail: Country;
firstName: string;
lastName: string;
phone: string;
province: string;
provinceDetail: Province;
zip: string;
}Related Docs
- k.commerce - E-commerce module overview
- customer - Customer Management
- order - Order Management