Skip to content

k.commerce.address ​

Address management.

Execution ContextPrerequisitesTypical 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 / PropertyDescriptionReturns
countries()Get all countries with currency, flag, and localized namesCountry[]
provinces(country)Get provinces/states for an English country nameProvince[]
cities(country, state)Get cities for an English country and state nameCity[]
addressDetail(address)Enrich an Address with localized country/province/city detailsAddressDetail

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.

ParameterTypeRequiredDescription
countrystringYesCountry 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.

ParameterTypeRequiredDescription
countrystringYesCountry name (English)
statestringYesProvince/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, and city must match the English names in Kooboo's built-in dataset to populate countryDetail, provinceDetail, and cityDetail; unmatched entries return null.
  • AddressService.AddressDetail currently does not copy the input zip field, so zip on the returned AddressDetail is always null at runtime.
ParameterTypeRequiredDescription
addressAddressYesAddress 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 ​

PropertyDescriptionType
codeCountry codestring
nameCountry name (English)string
nameTranslationsCountry name translationsNameTranslation[]
currencyCurrency codestring
currencySymbolCurrency symbolstring
emojiFlagFlag emojistring

Province attribute ​

PropertyDescriptionType
countryCountry name (English)string
nameProvince name (English)string
nameTranslationsProvince name translationsNameTranslation[]

City property ​

PropertyDescriptionType
countryCountry name (English)string
provinceProvince name (English)string
nameCity name (English)string
nameTranslationsCity name translationsNameTranslation[]

NameTranslation Property ​

PropertyDescriptionType
keyLanguage codestring
valueTranslated stringstring

AddressDetail Property ​

PropertyDescriptionType
address1Address line 1string
address2Address line 2string
cityCity namestring
cityDetailCity detail (null when unmatched)City | null
countryCountry namestring
countryDetailCountry detail (null when unmatched)Country | null
firstNameFirst namestring
lastNameLast namestring
phonePhonestring
provinceProvince/state namestring
provinceDetailProvince detail (null when unmatched)Province | null
zipPostal 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;
}