@uxf/smart-address 11.80.4 → 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/{v1 → common/__tests__}/load-address-options.test.js +22 -14
- package/{v1 → common/__tests__}/load-zip-options.test.js +10 -5
- package/{v1 → common/__tests__}/search-zip.test.js +5 -4
- package/common/__tests__/search.test.js +24 -0
- package/common/create-loader.d.ts +4 -0
- package/common/create-loader.js +7 -0
- package/common/get-address-extended.d.ts +2 -0
- package/common/get-address-extended.js +9 -0
- package/common/get-address.d.ts +2 -0
- package/common/get-address.js +9 -0
- package/common/index.d.ts +1 -0
- package/common/index.js +17 -0
- package/common/load-address-options.d.ts +11 -0
- package/common/load-address-options.js +21 -0
- package/common/load-zip-options.d.ts +8 -0
- package/common/load-zip-options.js +14 -0
- package/common/search-zip.d.ts +2 -0
- package/common/search-zip.js +19 -0
- package/common/search.d.ts +10 -0
- package/common/search.js +25 -0
- package/common/types.d.ts +88 -0
- package/common/types.js +2 -0
- package/package.json +1 -1
- package/v1/create-address-loader.d.ts +2 -2
- package/v1/create-address-loader.js +2 -9
- package/v1/create-zip-loader.d.ts +2 -2
- package/v1/create-zip-loader.js +2 -6
- package/v1/get-address-extended.d.ts +1 -2
- package/v1/get-address-extended.js +2 -6
- package/v1/get-address.d.ts +1 -2
- package/v1/get-address.js +2 -6
- package/v1/get-city-part.js +2 -2
- package/v1/get-city.js +2 -2
- package/v1/get-momc.js +2 -2
- package/v1/get-mop.js +2 -2
- package/v1/get-street.js +1 -1
- package/v1/index.d.ts +6 -3
- package/v1/load-address-options.d.ts +4 -6
- package/v1/load-address-options.js +2 -12
- package/v1/load-zip-options.d.ts +4 -6
- package/v1/load-zip-options.js +2 -11
- package/v1/search-zip.d.ts +1 -2
- package/v1/search-zip.js +2 -13
- package/v1/search.d.ts +3 -5
- package/v1/search.js +2 -19
- package/v1/types.d.ts +1 -89
- package/v1/types.js +15 -0
- package/v2/__tests__/get-building-addresses.test.d.ts +1 -0
- package/v2/__tests__/get-building-addresses.test.js +49 -0
- package/v2/__tests__/search-city-part.test.d.ts +1 -0
- package/v2/__tests__/search-city-part.test.js +46 -0
- package/v2/create-address-loader.d.ts +10 -0
- package/v2/create-address-loader.js +7 -0
- package/v2/create-zip-loader.d.ts +7 -0
- package/v2/create-zip-loader.js +7 -0
- package/v2/get-address-extended.d.ts +2 -0
- package/v2/get-address-extended.js +5 -0
- package/v2/get-address.d.ts +1 -0
- package/v2/get-address.js +5 -0
- package/v2/get-building-addresses.d.ts +2 -0
- package/v2/get-building-addresses.js +9 -0
- package/v2/index.d.ts +11 -0
- package/v2/index.js +27 -0
- package/v2/load-address-options.d.ts +8 -0
- package/v2/load-address-options.js +5 -0
- package/v2/load-zip-options.d.ts +5 -0
- package/v2/load-zip-options.js +5 -0
- package/v2/search-city-part.d.ts +2 -0
- package/v2/search-city-part.js +18 -0
- package/v2/search-zip.d.ts +1 -0
- package/v2/search-zip.js +5 -0
- package/v2/search.d.ts +7 -0
- package/v2/search.js +5 -0
- package/v2/types.d.ts +48 -0
- package/v2/types.js +17 -0
- package/v1/search.test.js +0 -33
- /package/{v1 → common/__tests__}/load-address-options.test.d.ts +0 -0
- /package/{v1 → common/__tests__}/load-zip-options.test.d.ts +0 -0
- /package/{v1 → common/__tests__}/search-zip.test.d.ts +0 -0
- /package/{v1 → common/__tests__}/search.test.d.ts +0 -0
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.
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const load_address_options_1 = require("
|
|
4
|
-
const search_1 = require("
|
|
5
|
-
jest.
|
|
3
|
+
const load_address_options_1 = require("../../v1/load-address-options");
|
|
4
|
+
const search_1 = require("../search");
|
|
5
|
+
global.fetch = jest.fn();
|
|
6
|
+
jest.mock("../search");
|
|
6
7
|
describe("loadAddressOptions", () => {
|
|
7
8
|
beforeEach(() => {
|
|
8
9
|
jest.clearAllMocks();
|
|
@@ -36,7 +37,7 @@ describe("loadAddressOptions", () => {
|
|
|
36
37
|
psc: null,
|
|
37
38
|
search: "",
|
|
38
39
|
level: 1,
|
|
39
|
-
gps: { latitude:
|
|
40
|
+
gps: { latitude: 50.0755, longitude: 14.4378 },
|
|
40
41
|
platiOd: "2024-01-01",
|
|
41
42
|
aktualizace: "2024-10-01",
|
|
42
43
|
okresKod: 456,
|
|
@@ -45,9 +46,12 @@ describe("loadAddressOptions", () => {
|
|
|
45
46
|
krajNazev: "Czech Republic",
|
|
46
47
|
},
|
|
47
48
|
];
|
|
48
|
-
|
|
49
|
+
const mockSearch = jest.fn();
|
|
50
|
+
search_1.searchGeneral.mockReturnValue(mockSearch);
|
|
51
|
+
mockSearch.mockResolvedValue(mockResponse);
|
|
49
52
|
await (0, load_address_options_1.loadAddressOptions)({ term, level });
|
|
50
|
-
expect(search_1.
|
|
53
|
+
expect(search_1.searchGeneral).toHaveBeenCalledWith("/v1/search");
|
|
54
|
+
expect(mockSearch).toHaveBeenCalledWith({ term, level, limit: 10, zip: undefined });
|
|
51
55
|
});
|
|
52
56
|
const term = "Prague";
|
|
53
57
|
const level = 1;
|
|
@@ -57,7 +61,7 @@ describe("loadAddressOptions", () => {
|
|
|
57
61
|
id: 1,
|
|
58
62
|
obecKod: 123,
|
|
59
63
|
obecNazev: null,
|
|
60
|
-
obec:
|
|
64
|
+
obec: "Vrchlabi",
|
|
61
65
|
momcKod: null,
|
|
62
66
|
momcNazev: null,
|
|
63
67
|
mopKod: null,
|
|
@@ -74,7 +78,7 @@ describe("loadAddressOptions", () => {
|
|
|
74
78
|
psc: null,
|
|
75
79
|
search: "",
|
|
76
80
|
level: 1,
|
|
77
|
-
gps: { latitude:
|
|
81
|
+
gps: { latitude: 50.0755, longitude: 14.4378 },
|
|
78
82
|
platiOd: "2024-01-01",
|
|
79
83
|
aktualizace: "2024-10-01",
|
|
80
84
|
okresKod: 456,
|
|
@@ -83,9 +87,11 @@ describe("loadAddressOptions", () => {
|
|
|
83
87
|
krajNazev: "Czech Republic",
|
|
84
88
|
},
|
|
85
89
|
];
|
|
86
|
-
|
|
90
|
+
const mockSearch = jest.fn();
|
|
91
|
+
search_1.searchGeneral.mockReturnValue(mockSearch);
|
|
92
|
+
mockSearch.mockResolvedValue(mockResponse);
|
|
87
93
|
const options = await (0, load_address_options_1.loadAddressOptions)({ term, level });
|
|
88
|
-
expect(options).toEqual([{ id: 1, label: "Main St,
|
|
94
|
+
expect(options).toEqual([{ id: 1, label: "Main St, Vrchlabi" }]);
|
|
89
95
|
});
|
|
90
96
|
it("should use custom getLabel function if provided", async () => {
|
|
91
97
|
const mockResponse = [
|
|
@@ -93,7 +99,7 @@ describe("loadAddressOptions", () => {
|
|
|
93
99
|
id: 1,
|
|
94
100
|
obecKod: 123,
|
|
95
101
|
obecNazev: null,
|
|
96
|
-
obec:
|
|
102
|
+
obec: "Vrchlabi",
|
|
97
103
|
momcKod: null,
|
|
98
104
|
momcNazev: null,
|
|
99
105
|
mopKod: null,
|
|
@@ -110,7 +116,7 @@ describe("loadAddressOptions", () => {
|
|
|
110
116
|
psc: null,
|
|
111
117
|
search: "",
|
|
112
118
|
level: 1,
|
|
113
|
-
gps: { latitude:
|
|
119
|
+
gps: { latitude: 50.0755, longitude: 14.4378 },
|
|
114
120
|
platiOd: "2024-01-01",
|
|
115
121
|
aktualizace: "2024-10-01",
|
|
116
122
|
okresKod: 456,
|
|
@@ -119,9 +125,11 @@ describe("loadAddressOptions", () => {
|
|
|
119
125
|
krajNazev: "Czech Republic",
|
|
120
126
|
},
|
|
121
127
|
];
|
|
122
|
-
|
|
128
|
+
const mockSearch = jest.fn();
|
|
129
|
+
search_1.searchGeneral.mockReturnValue(mockSearch);
|
|
130
|
+
mockSearch.mockResolvedValue(mockResponse);
|
|
123
131
|
const customGetLabel = (address) => `${address.obec} - ${address.ulice}`;
|
|
124
132
|
const options = await (0, load_address_options_1.loadAddressOptions)({ term, level, getLabel: customGetLabel });
|
|
125
|
-
expect(options).toEqual([{ id: 1, label: "
|
|
133
|
+
expect(options).toEqual([{ id: 1, label: "Vrchlabi - Main St" }]);
|
|
126
134
|
});
|
|
127
135
|
});
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const load_zip_options_1 = require("
|
|
4
|
-
const search_zip_1 = require("
|
|
5
|
-
jest.
|
|
3
|
+
const load_zip_options_1 = require("../../v1/load-zip-options");
|
|
4
|
+
const search_zip_1 = require("../search-zip");
|
|
5
|
+
global.fetch = jest.fn();
|
|
6
|
+
jest.mock("../search-zip");
|
|
6
7
|
describe("loadZipOptions", () => {
|
|
7
8
|
it("should return empty array when term is empty", async () => {
|
|
8
9
|
const result = await (0, load_zip_options_1.loadZipOptions)({ term: "" });
|
|
9
10
|
expect(result).toEqual([]);
|
|
10
11
|
});
|
|
11
12
|
it("should return formatted options with default label when term is provided", async () => {
|
|
12
|
-
|
|
13
|
+
const mockSearch = jest.fn();
|
|
14
|
+
search_zip_1.searchZipGeneral.mockReturnValue(mockSearch);
|
|
15
|
+
mockSearch.mockResolvedValueOnce([
|
|
13
16
|
{ id: 1, psc: 12345 },
|
|
14
17
|
{ id: 2, psc: 54321 },
|
|
15
18
|
]);
|
|
@@ -20,7 +23,9 @@ describe("loadZipOptions", () => {
|
|
|
20
23
|
]);
|
|
21
24
|
});
|
|
22
25
|
it("should return formatted options with custom label when getLabel is provided", async () => {
|
|
23
|
-
|
|
26
|
+
const mockSearch = jest.fn();
|
|
27
|
+
search_zip_1.searchZipGeneral.mockReturnValue(mockSearch);
|
|
28
|
+
mockSearch.mockResolvedValueOnce([
|
|
24
29
|
{ id: 1, psc: 12345 },
|
|
25
30
|
{ id: 2, psc: 54321 },
|
|
26
31
|
]);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const config_1 = require("
|
|
4
|
-
const search_zip_1 = require("
|
|
5
|
-
jest.
|
|
3
|
+
const config_1 = require("../../config");
|
|
4
|
+
const search_zip_1 = require("../../v1/search-zip");
|
|
5
|
+
global.fetch = jest.fn();
|
|
6
|
+
jest.mock("../../config", () => ({
|
|
6
7
|
smartAddressUrl: "http://example.com",
|
|
7
8
|
}));
|
|
8
9
|
describe("searchZip", () => {
|
|
@@ -31,7 +32,7 @@ describe("searchZip", () => {
|
|
|
31
32
|
];
|
|
32
33
|
fetch.mockImplementation(() => Promise.resolve({
|
|
33
34
|
status: 200,
|
|
34
|
-
|
|
35
|
+
json: () => Promise.resolve(mockResponse),
|
|
35
36
|
}));
|
|
36
37
|
const result = await (0, search_zip_1.searchZip)("12345");
|
|
37
38
|
expect(result).toEqual(mockResponse);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_1 = require("../../config");
|
|
4
|
+
const search_1 = require("../../v1/search");
|
|
5
|
+
global.fetch = jest.fn();
|
|
6
|
+
describe("SmartAddress v1 search", () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
jest.clearAllMocks();
|
|
9
|
+
});
|
|
10
|
+
it("should return an empty array when term is empty", async () => {
|
|
11
|
+
const result = await (0, search_1.search)({ term: "", level: 1 });
|
|
12
|
+
expect(result).toEqual([]);
|
|
13
|
+
expect(fetch).not.toHaveBeenCalled();
|
|
14
|
+
});
|
|
15
|
+
it("should call fetch with correct parameters including address", async () => {
|
|
16
|
+
const mockResponse = [{ id: 1, name: "Test Location" }];
|
|
17
|
+
fetch.mockResolvedValue({
|
|
18
|
+
json: jest.fn().mockResolvedValue(mockResponse),
|
|
19
|
+
});
|
|
20
|
+
const result = await (0, search_1.search)({ term: "test", level: 2, limit: 5, zip: 12345, address: "some address" });
|
|
21
|
+
expect(fetch).toHaveBeenCalledWith(`${config_1.smartAddressUrl}/v1/search?term=test&level=2&limit=5&zip=12345&address=some+address`);
|
|
22
|
+
expect(result).toEqual(mockResponse);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLoaderGeneral = void 0;
|
|
4
|
+
const createLoaderGeneral = (loadOptions, params) => {
|
|
5
|
+
return (term) => loadOptions({ ...params, term });
|
|
6
|
+
};
|
|
7
|
+
exports.createLoaderGeneral = createLoaderGeneral;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAddressExtendedGeneral = void 0;
|
|
4
|
+
const config_1 = require("../config");
|
|
5
|
+
const getAddressExtendedGeneral = (url) => async (id) => {
|
|
6
|
+
const response = await fetch(`${config_1.smartAddressUrl}${url}${id}/extended`);
|
|
7
|
+
return await response.json();
|
|
8
|
+
};
|
|
9
|
+
exports.getAddressExtendedGeneral = getAddressExtendedGeneral;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAddressGeneral = void 0;
|
|
4
|
+
const config_1 = require("../config");
|
|
5
|
+
const getAddressGeneral = (url) => async (id) => {
|
|
6
|
+
const response = await fetch(config_1.smartAddressUrl + url + id);
|
|
7
|
+
return await response.json();
|
|
8
|
+
};
|
|
9
|
+
exports.getAddressGeneral = getAddressGeneral;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./types";
|
package/common/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Location, Option } from "./types";
|
|
2
|
+
type Params = {
|
|
3
|
+
term: string;
|
|
4
|
+
level: number;
|
|
5
|
+
limit?: number;
|
|
6
|
+
zip?: number;
|
|
7
|
+
address?: string;
|
|
8
|
+
getLabel?: (address: Location) => string;
|
|
9
|
+
};
|
|
10
|
+
export declare const loadAddressOptionsGeneral: (url: `/${string}`) => (params: Params) => Promise<Option[]>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadAddressOptionsGeneral = void 0;
|
|
4
|
+
const search_1 = require("./search");
|
|
5
|
+
const loadAddressOptionsGeneral = (url) => async (params) => {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
const limit = (_a = params.limit) !== null && _a !== void 0 ? _a : 10;
|
|
8
|
+
const getLabel = (_b = params.getLabel) !== null && _b !== void 0 ? _b : ((address) => { var _a, _b; return `${(_a = address.ulice) !== null && _a !== void 0 ? _a : ""}, ${(_b = address.obec) !== null && _b !== void 0 ? _b : ""}`; });
|
|
9
|
+
if (params.term.length === 0) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
const response = await (0, search_1.searchGeneral)(url)({
|
|
13
|
+
term: params.term,
|
|
14
|
+
level: params.level,
|
|
15
|
+
limit,
|
|
16
|
+
zip: params.zip,
|
|
17
|
+
address: params.address,
|
|
18
|
+
});
|
|
19
|
+
return response.map((a) => ({ id: a.id, label: getLabel(a) }));
|
|
20
|
+
};
|
|
21
|
+
exports.loadAddressOptionsGeneral = loadAddressOptionsGeneral;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadZipOptionsGeneral = void 0;
|
|
4
|
+
const search_zip_1 = require("./search-zip");
|
|
5
|
+
const loadZipOptionsGeneral = (url) => async (params) => {
|
|
6
|
+
var _a;
|
|
7
|
+
const getLabel = (_a = params.getLabel) !== null && _a !== void 0 ? _a : ((address) => `${address.psc}`);
|
|
8
|
+
if (params.term.length === 0) {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
const response = await (0, search_zip_1.searchZipGeneral)(url)(params.term, params.limit);
|
|
12
|
+
return response.map((a) => ({ id: a.id, label: getLabel(a) }));
|
|
13
|
+
};
|
|
14
|
+
exports.loadZipOptionsGeneral = loadZipOptionsGeneral;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.searchZipGeneral = void 0;
|
|
4
|
+
const config_1 = require("../config");
|
|
5
|
+
const regexp = /^([0-9]{1,5})$/;
|
|
6
|
+
const searchZipGeneral = (url) => async (term, limit) => {
|
|
7
|
+
if (term.length === 0 || !regexp.test(term)) {
|
|
8
|
+
return [];
|
|
9
|
+
}
|
|
10
|
+
const params = new URLSearchParams({
|
|
11
|
+
term: term,
|
|
12
|
+
});
|
|
13
|
+
if (limit) {
|
|
14
|
+
params.append("limit", limit.toString());
|
|
15
|
+
}
|
|
16
|
+
const response = await fetch(`${config_1.smartAddressUrl}${url}?${params}`);
|
|
17
|
+
return await response.json();
|
|
18
|
+
};
|
|
19
|
+
exports.searchZipGeneral = searchZipGeneral;
|
package/common/search.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.searchGeneral = void 0;
|
|
4
|
+
const config_1 = require("../config");
|
|
5
|
+
const searchGeneral = (url) => async (props) => {
|
|
6
|
+
var _a;
|
|
7
|
+
const limit = (_a = props.limit) !== null && _a !== void 0 ? _a : 10;
|
|
8
|
+
if (props.term.length === 0) {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
const params = new URLSearchParams({
|
|
12
|
+
term: props.term,
|
|
13
|
+
level: props.level.toString(),
|
|
14
|
+
limit: limit.toString(),
|
|
15
|
+
});
|
|
16
|
+
if (props.zip) {
|
|
17
|
+
params.append("zip", props.zip.toString());
|
|
18
|
+
}
|
|
19
|
+
if (props.address) {
|
|
20
|
+
params.append("address", props.address);
|
|
21
|
+
}
|
|
22
|
+
const response = await fetch(`${config_1.smartAddressUrl}${url}?${params}`);
|
|
23
|
+
return await response.json();
|
|
24
|
+
};
|
|
25
|
+
exports.searchGeneral = searchGeneral;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export type BasicType = {
|
|
2
|
+
id: number;
|
|
3
|
+
nazev: string | null;
|
|
4
|
+
};
|
|
5
|
+
export type Type = {
|
|
6
|
+
id: number;
|
|
7
|
+
nazev: string | null;
|
|
8
|
+
popis: string | null;
|
|
9
|
+
zkracenyNazev: string | null;
|
|
10
|
+
zacatekPlatnosti: string | null;
|
|
11
|
+
konecPlatnosti: string | null;
|
|
12
|
+
};
|
|
13
|
+
export type ObjectType = BasicType;
|
|
14
|
+
export type ObjectTypeBasic = BasicType;
|
|
15
|
+
export type BuildingType = Type;
|
|
16
|
+
export type ConstructionType = Type;
|
|
17
|
+
export type SewerConnectionType = Type;
|
|
18
|
+
export type GasConnectionType = Type;
|
|
19
|
+
export type WaterConnectionType = Type;
|
|
20
|
+
export type ElevatorType = Type;
|
|
21
|
+
export type HeatingType = Type;
|
|
22
|
+
export type BuildingUsageType = Type;
|
|
23
|
+
export type Option = {
|
|
24
|
+
id: number;
|
|
25
|
+
label: string;
|
|
26
|
+
};
|
|
27
|
+
export type Point = {
|
|
28
|
+
latitude: number;
|
|
29
|
+
longitude: number;
|
|
30
|
+
};
|
|
31
|
+
export type Location = {
|
|
32
|
+
id: number;
|
|
33
|
+
obecKod: number;
|
|
34
|
+
obecNazev: string | null;
|
|
35
|
+
obec: string | null;
|
|
36
|
+
momcKod: number | null;
|
|
37
|
+
momcNazev: string | null;
|
|
38
|
+
mopKod: number | null;
|
|
39
|
+
mopNazev: string | null;
|
|
40
|
+
castObceKod: number | null;
|
|
41
|
+
castObceNazev: string | null;
|
|
42
|
+
uliceKod: number | null;
|
|
43
|
+
uliceNazev: string | null;
|
|
44
|
+
ulice: string | null;
|
|
45
|
+
typSo: string | null;
|
|
46
|
+
cisloDomovni: number | null;
|
|
47
|
+
cisloOrientacni: number | null;
|
|
48
|
+
cisloOrientacniZnak: string | null;
|
|
49
|
+
psc: number | null;
|
|
50
|
+
search: string | null;
|
|
51
|
+
level: number | null;
|
|
52
|
+
gps: Point | null;
|
|
53
|
+
platiOd: string | null;
|
|
54
|
+
aktualizace: string | null;
|
|
55
|
+
okresKod: number | null;
|
|
56
|
+
okresNazev: string | null;
|
|
57
|
+
krajKod: number | null;
|
|
58
|
+
krajNazev: string | null;
|
|
59
|
+
};
|
|
60
|
+
export type LocationExtended = {
|
|
61
|
+
id: number;
|
|
62
|
+
distributorElektrinyKod: string | null;
|
|
63
|
+
distributorElektrinyId: number | null;
|
|
64
|
+
distributorPlynuKod: string | null;
|
|
65
|
+
distributorPlynuId: number | null;
|
|
66
|
+
typBudovy: BuildingType | null;
|
|
67
|
+
isknBudovaId: string | null;
|
|
68
|
+
druhKonstrukce: ConstructionType | null;
|
|
69
|
+
pocetBytu: number | null;
|
|
70
|
+
pocetPodlazi: number | null;
|
|
71
|
+
pripojeniKanalizace: SewerConnectionType | null;
|
|
72
|
+
pripojeniPlyn: GasConnectionType | null;
|
|
73
|
+
pripojeniVodovod: WaterConnectionType | null;
|
|
74
|
+
vybaveniVytahem: ElevatorType | null;
|
|
75
|
+
zpusobVytapeni: HeatingType | null;
|
|
76
|
+
zastavenaPlocha: number | null;
|
|
77
|
+
obestavenyProstor: number | null;
|
|
78
|
+
podlahovaPlocha: number | null;
|
|
79
|
+
stavebniObjektKod: string | null;
|
|
80
|
+
parcelaKod: string | null;
|
|
81
|
+
zpusobVyuzitiObjektu: BuildingUsageType | null;
|
|
82
|
+
createdAt: string | null;
|
|
83
|
+
updatedAt: string | null;
|
|
84
|
+
objectType: ObjectType | null;
|
|
85
|
+
objectTypeBasic: ObjectTypeBasic | null;
|
|
86
|
+
objectSize: string | null;
|
|
87
|
+
objectSizeSquare: number | null;
|
|
88
|
+
};
|
package/common/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Location
|
|
1
|
+
import { Location } from "./types";
|
|
2
2
|
type Params = {
|
|
3
3
|
level: number;
|
|
4
4
|
limit?: number;
|
|
5
5
|
zip?: number;
|
|
6
6
|
getLabel?: (address: Location) => string;
|
|
7
7
|
};
|
|
8
|
-
export declare const createAddressLoader: (params: Params) => (
|
|
8
|
+
export declare const createAddressLoader: (params: Params) => (term: string) => Promise<import("./types").Option[]>;
|
|
9
9
|
export {};
|