@uxf/smart-address 11.123.0 → 14.0.0
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 +27 -28
- package/package.json +1 -1
- package/v1/get-city.js +1 -1
- package/v1/get-city.test.d.ts +1 -0
- package/v1/get-city.test.js +13 -0
package/README.md
CHANGED
|
@@ -48,28 +48,28 @@ const options = await loadAddressOptions({ term: "Sovova", level: 2 });
|
|
|
48
48
|
|
|
49
49
|
### Entry points
|
|
50
50
|
|
|
51
|
-
| Import path
|
|
52
|
-
|
|
|
53
|
-
| `@uxf/smart-address/v2`
|
|
54
|
-
| `@uxf/smart-address/v1`
|
|
55
|
-
| `@uxf/smart-address/common` | Shared type definitions only
|
|
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
56
|
|
|
57
57
|
### Functions
|
|
58
58
|
|
|
59
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
60
|
|
|
61
|
-
| Function
|
|
62
|
-
|
|
|
63
|
-
| `search`
|
|
64
|
-
| `searchZip`
|
|
65
|
-
| `searchCityPart`
|
|
66
|
-
| `loadAddressOptions`
|
|
67
|
-
| `loadZipOptions`
|
|
68
|
-
| `createAddressLoader`
|
|
69
|
-
| `createZipLoader`
|
|
70
|
-
| `getAddress`
|
|
71
|
-
| `getAddressExtended`
|
|
72
|
-
| `getBuildingAddresses` | `(id: number) => Promise<Location[]>`
|
|
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
73
|
|
|
74
74
|
v1-only lookups on `SmartAddress`, each `(id: number) => Promise<Location>`: `getCity`, `getCityPart`, `getMomc`, `getMop`, `getStreet`.
|
|
75
75
|
|
|
@@ -77,16 +77,16 @@ v1-only lookups on `SmartAddress`, each `(id: number) => Promise<Location>`: `ge
|
|
|
77
77
|
|
|
78
78
|
The `level` used by `search` / `loadAddressOptions` / `createAddressLoader` selects the granularity of the returned records (values are Czech RÚIAN terms):
|
|
79
79
|
|
|
80
|
-
| level | Meaning
|
|
81
|
-
|
|
|
82
|
-
| 1
|
|
83
|
-
| 2
|
|
84
|
-
| 3
|
|
85
|
-
| 4
|
|
86
|
-
| 5
|
|
87
|
-
| 6
|
|
88
|
-
| 7
|
|
89
|
-
| 8
|
|
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
90
|
|
|
91
91
|
### Value model (types)
|
|
92
92
|
|
|
@@ -107,7 +107,6 @@ All types are exported from `@uxf/smart-address/common` (and re-exported from `/
|
|
|
107
107
|
- **Czech data.** All `Location` field names and `level` labels are Czech; the endpoints are specific to Czech addresses.
|
|
108
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
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
110
|
|
|
112
111
|
## Links
|
|
113
112
|
|
package/package.json
CHANGED
package/v1/get-city.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getCity = void 0;
|
|
4
4
|
const config_1 = require("../config");
|
|
5
5
|
const getCity = async (id) => {
|
|
6
|
-
const response = await fetch(
|
|
6
|
+
const response = await fetch(`${config_1.smartAddressUrl}/v1/address/city/${id}`);
|
|
7
7
|
return await response.json();
|
|
8
8
|
};
|
|
9
9
|
exports.getCity = getCity;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/** @jest-environment node */
|
|
4
|
+
const config_1 = require("../config");
|
|
5
|
+
const get_city_1 = require("./get-city");
|
|
6
|
+
afterEach(() => {
|
|
7
|
+
jest.restoreAllMocks();
|
|
8
|
+
});
|
|
9
|
+
test("asks the city endpoint once, with the base URL once", async () => {
|
|
10
|
+
const fetchMock = jest.spyOn(global, "fetch").mockResolvedValue(new Response("{}"));
|
|
11
|
+
await (0, get_city_1.getCity)(42);
|
|
12
|
+
expect(fetchMock).toHaveBeenCalledWith(`${config_1.smartAddressUrl}/v1/address/city/42`);
|
|
13
|
+
});
|