@uxf/smart-address 11.103.1 → 11.122.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +109 -45
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,50 +1,114 @@
|
|
|
1
1
|
# @uxf/smart-address
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* 7 = okres (future)
|
|
19
|
-
* 8 = kraj (future)
|
|
20
|
-
```tsx
|
|
21
|
-
const options = await SmartAddress.loadAddressOptions({ term: "Sovova", level: 1 });
|
|
22
|
-
```
|
|
23
|
-
### Options with zip code.
|
|
24
|
-
```tsx
|
|
25
|
-
const zipOptions = await SmartAddress.loadZipOptions({ term: "46001" });
|
|
2
|
+
|
|
3
|
+
Typed client helpers for the Czech [Smart Address](https://www.smart-address.cz) API — address/ZIP search, autocomplete option loaders, and address-detail lookups.
|
|
4
|
+
|
|
5
|
+
## When to use
|
|
6
|
+
|
|
7
|
+
Reach for this package when you need to search Czech addresses (RÚIAN-style data), build address/ZIP autocomplete inputs, or resolve a picked suggestion to a full address record. It is a thin, dependency-free layer over the public `https://www.smart-address.cz/api` REST API using the global `fetch`.
|
|
8
|
+
|
|
9
|
+
It is **not** a UI package: it ships no React components or hooks. The loader factories return a `(term) => Promise<Option[]>` function shaped to feed an async select/combobox, but rendering is up to the consumer.
|
|
10
|
+
|
|
11
|
+
There are two versioned surfaces, mapping to the API's `/v1` and `/v2` endpoints:
|
|
12
|
+
|
|
13
|
+
- **`@uxf/smart-address/v2`** — the current surface. Exposes individual named functions, returns a structured extended-detail response, and adds `getBuildingAddresses` and `searchCityPart`. Prefer it for new code.
|
|
14
|
+
- **`@uxf/smart-address/v1`** — the legacy surface. Exposes a single `SmartAddress` namespace object and the individual administrative-unit lookups (`getCity`, `getCityPart`, `getMomc`, `getMop`, `getStreet`) that v2 does not have.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
26
18
|
```
|
|
27
|
-
|
|
28
|
-
```tsx
|
|
29
|
-
const address = await SmartAddress.getAddress(123456);
|
|
30
|
-
```
|
|
31
|
-
### Option of location with added extension of electricity distributor, building type etc. by id.
|
|
32
|
-
```tsx
|
|
33
|
-
const address = await SmartAddress.getAddressExtended(123456);
|
|
34
|
-
```
|
|
35
|
-
### Get a specific part of the city by id.
|
|
36
|
-
```tsx
|
|
37
|
-
const cityPart = await SmartAddress.getCityPart(123456);
|
|
38
|
-
```
|
|
39
|
-
### Get a city district by id.
|
|
40
|
-
```tsx
|
|
41
|
-
const momc = await SmartAddress.getMomc(123456);
|
|
19
|
+
yarn add @uxf/smart-address
|
|
42
20
|
```
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
21
|
+
|
|
22
|
+
No peer dependencies and no runtime dependencies. It only needs a `fetch`-capable runtime (any browser, or Node 18+). No API key, token, or provider setup is required.
|
|
23
|
+
|
|
24
|
+
There is no root/default export — import from a versioned subpath (`/v1`, `/v2`) or the shared types (`/common`). A bare `@uxf/smart-address` import resolves to nothing.
|
|
25
|
+
|
|
26
|
+
## Quick start
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { SmartAddress } from "@uxf/smart-address/v1";
|
|
30
|
+
|
|
31
|
+
// Street-level autocomplete: returns [{ id, label }] ready for a select
|
|
32
|
+
const options = await SmartAddress.loadAddressOptions({ term: "Sovova", level: 2 });
|
|
33
|
+
|
|
34
|
+
// Resolve a chosen option's id to the full address record
|
|
35
|
+
const chosen = options.at(0);
|
|
36
|
+
const address = chosen ? await SmartAddress.getAddress(chosen.id) : null;
|
|
46
37
|
```
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
38
|
+
|
|
39
|
+
The same functions exist on the v2 surface as individual named exports:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { loadAddressOptions, getAddress } from "@uxf/smart-address/v2";
|
|
43
|
+
|
|
44
|
+
const options = await loadAddressOptions({ term: "Sovova", level: 2 });
|
|
50
45
|
```
|
|
46
|
+
|
|
47
|
+
## API
|
|
48
|
+
|
|
49
|
+
### Entry points
|
|
50
|
+
|
|
51
|
+
| Import path | Exposes |
|
|
52
|
+
| --- | --- |
|
|
53
|
+
| `@uxf/smart-address/v2` | Individual named functions (below) + all type definitions |
|
|
54
|
+
| `@uxf/smart-address/v1` | The `SmartAddress` namespace object holding the same-named methods, plus type definitions |
|
|
55
|
+
| `@uxf/smart-address/common` | Shared type definitions only |
|
|
56
|
+
|
|
57
|
+
### Functions
|
|
58
|
+
|
|
59
|
+
Signatures below are the v2 named exports. On v1 the same names are accessed as `SmartAddress.<name>`; v1/v2 differences are noted in the last column.
|
|
60
|
+
|
|
61
|
+
| Function | Signature | Notes |
|
|
62
|
+
| --- | --- | --- |
|
|
63
|
+
| `search` | `(props: { term: string; level: number; limit?: number; zip?: number; address?: string }) => Promise<Location[]>` | `limit` defaults to `10`. Empty `term` → `[]` (no request). |
|
|
64
|
+
| `searchZip` | `(term: string, limit?: number) => Promise<Location[]>` | Returns `[]` unless `term` is 1–5 digits. |
|
|
65
|
+
| `searchCityPart` | `(term: string, limit?: number) => Promise<CityPart[]>` | **v2 only.** Empty `term` → `[]`. |
|
|
66
|
+
| `loadAddressOptions` | `(params: { term: string; level: number; limit?: number; zip?: number; address?: string; getLabel?: (address: Location) => string }) => Promise<Option[]>` | Maps `search` results to `Option`s. Default label: `` `${ulice ?? ""}, ${obec ?? ""}` ``. |
|
|
67
|
+
| `loadZipOptions` | `(params: { term: string; limit?: number; getLabel?: (address: Location) => string }) => Promise<Option[]>` | Default label: the `psc` (ZIP). |
|
|
68
|
+
| `createAddressLoader` | `(params: { level: number; limit?: number; zip?: number; address?: string; getLabel?: (address: Location) => string }) => (term: string) => Promise<Option[]>` | Curried `loadAddressOptions` for async selects. v1 params omit `address`. |
|
|
69
|
+
| `createZipLoader` | `(params: { limit?: number; getLabel?: (address: Location) => string }) => (term: string) => Promise<Option[]>` | Curried `loadZipOptions`. v1 params omit `limit`. |
|
|
70
|
+
| `getAddress` | `(id: number) => Promise<Location>` | Single address by id. |
|
|
71
|
+
| `getAddressExtended` | `(id: number) => Promise<AddressExtended>` | Extended detail. **v1 returns the flat `LocationExtended` instead.** |
|
|
72
|
+
| `getBuildingAddresses` | `(id: number) => Promise<Location[]>` | **v2 only.** All addresses within a building. |
|
|
73
|
+
|
|
74
|
+
v1-only lookups on `SmartAddress`, each `(id: number) => Promise<Location>`: `getCity`, `getCityPart`, `getMomc`, `getMop`, `getStreet`.
|
|
75
|
+
|
|
76
|
+
### `level` reference
|
|
77
|
+
|
|
78
|
+
The `level` used by `search` / `loadAddressOptions` / `createAddressLoader` selects the granularity of the returned records (values are Czech RÚIAN terms):
|
|
79
|
+
|
|
80
|
+
| level | Meaning |
|
|
81
|
+
| --- | --- |
|
|
82
|
+
| 1 | House number — číslo domovní (číslo orientační, znak čísla orientačního) |
|
|
83
|
+
| 2 | Street — ulice |
|
|
84
|
+
| 3 | Part of municipality — název části obce |
|
|
85
|
+
| 4 | Prague municipal district (MOP) — název MOP |
|
|
86
|
+
| 5 | Municipal district / city ward (MOMC) — název MOMC |
|
|
87
|
+
| 6 | Municipality — název obce |
|
|
88
|
+
| 7 | District — okres *(future)* |
|
|
89
|
+
| 8 | Region — kraj *(future)* |
|
|
90
|
+
|
|
91
|
+
### Value model (types)
|
|
92
|
+
|
|
93
|
+
All types are exported from `@uxf/smart-address/common` (and re-exported from `/v1` and `/v2`). v1's index re-exports a subset; v2 re-exports the full set.
|
|
94
|
+
|
|
95
|
+
- **`Option`** — `{ id: number; label: string }`. The result of the `load*`/`create*Loader` helpers, ready for a select.
|
|
96
|
+
- **`Location`** — the full address record. Key fields: `id`, `obec`/`obecNazev`, `ulice`/`uliceNazev`, `castObceNazev`, `cisloDomovni`, `cisloOrientacni`, `psc` (ZIP), `okresNazev`, `krajNazev`, `level`, and `gps: Point | null`. Most fields are nullable.
|
|
97
|
+
- **`Point`** — `{ latitude: number; longitude: number }`.
|
|
98
|
+
- **`LocationExtended`** (v1 `getAddressExtended`) — a flat record adding building/energy details to an address (electricity & gas distributor, construction type, floor/unit counts, utility connections, elevator, heating, areas, object type, etc.).
|
|
99
|
+
- **`AddressExtended`** (v2 `getAddressExtended`) — the same information grouped into `{ zakladniAdresa, administrativniUdaje, udajeBudovy, udajeEnergii }` (`AddressExtendedBasicResponse` / `…AdministrativeResponse` / `…BuildingResponse` / `…EnergyResponse`).
|
|
100
|
+
- **`CityPart`** (v2) — `{ id: number; name: string; obecKod: number; obecNazev: string; zips: string[] }`.
|
|
101
|
+
- Detail sub-types used above: `BuildingType`, `BuildingUsageType`, `ConstructionType`, `ElevatorType`, `GasConnectionType`, `HeatingType`, `SewerConnectionType`, `WaterConnectionType` (all `{ id, nazev, popis, zkracenyNazev, zacatekPlatnosti, konecPlatnosti }`), and `ObjectType` / `ObjectTypeBasic` (`{ id, nazev }`).
|
|
102
|
+
|
|
103
|
+
## Gotchas
|
|
104
|
+
|
|
105
|
+
- **No root export.** Import from `@uxf/smart-address/v1`, `.../v2`, or `.../common`. There is no `main`/`exports` in `package.json`, so subpaths resolve to the built files by filesystem; a bare package import has no entry.
|
|
106
|
+
- **Needs a `fetch` global.** Every call uses `fetch` against `https://www.smart-address.cz/api`. No auth is sent.
|
|
107
|
+
- **Czech data.** All `Location` field names and `level` labels are Czech; the endpoints are specific to Czech addresses.
|
|
108
|
+
- **Empty / invalid input short-circuits.** `search` and `load*` return `[]` for an empty `term` without hitting the network; `searchZip` also rejects non-digit or >5-digit terms.
|
|
109
|
+
- **No runtime validation.** Responses are `await response.json()` cast to the declared type; malformed responses or non-2xx statuses are not checked or thrown here — handle errors at the call site.
|
|
110
|
+
- **`SmartAddress.getCity` (v1) is broken.** It concatenates the base URL twice, producing a malformed request URL. Avoid it; use the other lookups.
|
|
111
|
+
|
|
112
|
+
## Links
|
|
113
|
+
|
|
114
|
+
- [Smart Address](https://www.smart-address.cz) — the underlying API service.
|