@uxf/smart-address 14.0.0 → 15.2.1
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/LICENSE +21 -0
- package/README.md +14 -12
- package/common/__tests__/create-loader.test.d.ts +1 -0
- package/common/__tests__/create-loader.test.js +29 -0
- package/common/__tests__/search-zip.test.js +1 -1
- package/common/__tests__/search.test.js +1 -1
- package/common/create-loader.d.ts +7 -1
- package/common/create-loader.js +4 -1
- package/common/load-address-options.d.ts +1 -0
- package/common/load-address-options.js +1 -0
- package/common/load-zip-options.d.ts +1 -0
- package/common/load-zip-options.js +1 -1
- package/common/search-zip.d.ts +3 -1
- package/common/search-zip.js +2 -2
- package/common/search.d.ts +1 -0
- package/common/search.js +1 -1
- package/package.json +4 -3
- package/v1/create-address-loader.d.ts +3 -1
- package/v1/create-zip-loader.d.ts +3 -1
- package/v1/index.d.ts +12 -3
- package/v1/load-address-options.d.ts +1 -0
- package/v1/load-zip-options.d.ts +1 -0
- package/v1/search-zip.d.ts +3 -1
- package/v1/search.d.ts +1 -0
- package/v2/create-address-loader.d.ts +3 -1
- package/v2/create-zip-loader.d.ts +3 -1
- package/v2/load-address-options.d.ts +1 -0
- package/v2/load-zip-options.d.ts +1 -0
- package/v2/search-zip.d.ts +3 -1
- package/v2/search.d.ts +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022–2026 UX Fans s.r.o.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @uxf/smart-address
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@uxf/smart-address)
|
|
4
|
+
|
|
3
5
|
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
6
|
|
|
5
7
|
## When to use
|
|
@@ -58,18 +60,18 @@ const options = await loadAddressOptions({ term: "Sovova", level: 2 });
|
|
|
58
60
|
|
|
59
61
|
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
62
|
|
|
61
|
-
| Function | Signature
|
|
62
|
-
| ---------------------- |
|
|
63
|
-
| `search` | `(props: { term: string; level: number; limit?: number; zip?: number; address?: string }) => Promise<Location[]>`
|
|
64
|
-
| `searchZip` | `(term: string, limit?: number) => Promise<Location[]>` | Returns `[]` unless `term` is 1–5 digits.
|
|
65
|
-
| `searchCityPart` | `(term: string, limit?: number) => Promise<CityPart[]>`
|
|
66
|
-
| `loadAddressOptions` | `(params: { term: string; level: number; limit?: number; zip?: number; address?: string; getLabel?: (address: Location) => string }) => Promise<Option[]>`
|
|
67
|
-
| `loadZipOptions` | `(params: { term: string; limit?: number; getLabel?: (address: Location) => string }) => Promise<Option[]>`
|
|
68
|
-
| `createAddressLoader` | `(params: { level: number; limit?: number; zip?: number; address?: string; getLabel?: (address: Location) => string }) => (term: string) => Promise<Option[]>` | Curried `loadAddressOptions` for async selects
|
|
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>`
|
|
71
|
-
| `getAddressExtended` | `(id: number) => Promise<AddressExtended>`
|
|
72
|
-
| `getBuildingAddresses` | `(id: number) => Promise<Location[]>`
|
|
63
|
+
| Function | Signature | Notes |
|
|
64
|
+
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
65
|
+
| `search` | `(props: { term: string; level: number; limit?: number; zip?: number; address?: string; signal?: AbortSignal }) => Promise<Location[]>` | `limit` defaults to `10`. Empty `term` → `[]` (no request). |
|
|
66
|
+
| `searchZip` | `(term: string, limit?: number, options?: { signal?: AbortSignal }) => Promise<Location[]>` | Returns `[]` unless `term` is 1–5 digits. |
|
|
67
|
+
| `searchCityPart` | `(term: string, limit?: number) => Promise<CityPart[]>` | **v2 only.** Empty `term` → `[]`. |
|
|
68
|
+
| `loadAddressOptions` | `(params: { term: string; level: number; limit?: number; zip?: number; address?: string; getLabel?: (address: Location) => string; signal?: AbortSignal }) => Promise<Option[]>` | Maps `search` results to `Option`s. Default label: `` `${ulice ?? ""}, ${obec ?? ""}` ``. |
|
|
69
|
+
| `loadZipOptions` | `(params: { term: string; limit?: number; getLabel?: (address: Location) => string; signal?: AbortSignal }) => Promise<Option[]>` | Default label: the `psc` (ZIP). |
|
|
70
|
+
| `createAddressLoader` | `(params: { level: number; limit?: number; zip?: number; address?: string; getLabel?: (address: Location) => string }) => (term: string, options?: { signal?: AbortSignal }) => Promise<Option[]>` | Curried `loadAddressOptions` for async selects; pass it as `loadOptions` and the combobox passes the abort `signal`. v1 params omit `address`. |
|
|
71
|
+
| `createZipLoader` | `(params: { limit?: number; getLabel?: (address: Location) => string }) => (term: string, options?: { signal?: AbortSignal }) => Promise<Option[]>` | Curried `loadZipOptions`. v1 params omit `limit`. |
|
|
72
|
+
| `getAddress` | `(id: number) => Promise<Location>` | Single address by id. |
|
|
73
|
+
| `getAddressExtended` | `(id: number) => Promise<AddressExtended>` | Extended detail. **v1 returns the flat `LocationExtended` instead.** |
|
|
74
|
+
| `getBuildingAddresses` | `(id: number) => Promise<Location[]>` | **v2 only.** All addresses within a building. |
|
|
73
75
|
|
|
74
76
|
v1-only lookups on `SmartAddress`, each `(id: number) => Promise<Location>`: `getCity`, `getCityPart`, `getMomc`, `getMop`, `getStreet`.
|
|
75
77
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const create_address_loader_1 = require("../../v1/create-address-loader");
|
|
4
|
+
const create_zip_loader_1 = require("../../v1/create-zip-loader");
|
|
5
|
+
const create_address_loader_2 = require("../../v2/create-address-loader");
|
|
6
|
+
const create_zip_loader_2 = require("../../v2/create-zip-loader");
|
|
7
|
+
const fetchMock = jest.fn(() => Promise.resolve({ json: () => Promise.resolve([]) }));
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
fetchMock.mockClear();
|
|
10
|
+
global.fetch = fetchMock;
|
|
11
|
+
});
|
|
12
|
+
const cases = [
|
|
13
|
+
{ name: "v1 address loader", load: (0, create_address_loader_1.createAddressLoader)({ level: 1 }), term: "Praha" },
|
|
14
|
+
{ name: "v2 address loader", load: (0, create_address_loader_2.createAddressLoader)({ level: 1 }), term: "Praha" },
|
|
15
|
+
{ name: "v1 zip loader", load: (0, create_zip_loader_1.createZipLoader)({}), term: "11000" },
|
|
16
|
+
{ name: "v2 zip loader", load: (0, create_zip_loader_2.createZipLoader)({}), term: "11000" },
|
|
17
|
+
];
|
|
18
|
+
cases.forEach(({ name, load, term }) => {
|
|
19
|
+
test(`${name} passes the abort signal on to fetch`, async () => {
|
|
20
|
+
var _a;
|
|
21
|
+
const controller = new AbortController();
|
|
22
|
+
await load(term, { signal: controller.signal });
|
|
23
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
24
|
+
expect((_a = fetchMock.mock.calls.at(0)) === null || _a === void 0 ? void 0 : _a.at(1)).toEqual({ signal: controller.signal });
|
|
25
|
+
});
|
|
26
|
+
test(`${name} still works without a signal`, async () => {
|
|
27
|
+
await expect(load(term)).resolves.toEqual([]);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -36,6 +36,6 @@ describe("searchZip", () => {
|
|
|
36
36
|
}));
|
|
37
37
|
const result = await (0, search_zip_1.searchZip)("12345");
|
|
38
38
|
expect(result).toEqual(mockResponse);
|
|
39
|
-
expect(fetch).toHaveBeenCalledWith(`${config_1.smartAddressUrl}/v1/zip/search?term=12345
|
|
39
|
+
expect(fetch).toHaveBeenCalledWith(`${config_1.smartAddressUrl}/v1/zip/search?term=12345`, { signal: undefined });
|
|
40
40
|
});
|
|
41
41
|
});
|
|
@@ -18,7 +18,7 @@ describe("SmartAddress v1 search", () => {
|
|
|
18
18
|
json: jest.fn().mockResolvedValue(mockResponse),
|
|
19
19
|
});
|
|
20
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
|
|
21
|
+
expect(fetch).toHaveBeenCalledWith(`${config_1.smartAddressUrl}/v1/search?term=test&level=2&limit=5&zip=12345&address=some+address`, { signal: undefined });
|
|
22
22
|
expect(result).toEqual(mockResponse);
|
|
23
23
|
});
|
|
24
24
|
});
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { Option } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* A `loadOptions` for `Combobox`: `signal`, which the combobox passes, cancels a search it no longer waits for.
|
|
4
|
+
*/
|
|
2
5
|
export declare const createLoaderGeneral: <Params extends object>(loadOptions: (params: Params & {
|
|
3
6
|
term: string;
|
|
4
|
-
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
}) => Promise<Option[]>, params: Params) => ((term: string, options?: {
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
}) => Promise<Option[]>);
|
package/common/create-loader.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createLoaderGeneral = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A `loadOptions` for `Combobox`: `signal`, which the combobox passes, cancels a search it no longer waits for.
|
|
6
|
+
*/
|
|
4
7
|
const createLoaderGeneral = (loadOptions, params) => {
|
|
5
|
-
return (term) => loadOptions({ ...params, term });
|
|
8
|
+
return (term, options) => loadOptions({ ...params, term, signal: options === null || options === void 0 ? void 0 : options.signal });
|
|
6
9
|
};
|
|
7
10
|
exports.createLoaderGeneral = createLoaderGeneral;
|
|
@@ -8,7 +8,7 @@ const loadZipOptionsGeneral = (url) => async (params) => {
|
|
|
8
8
|
if (params.term.length === 0) {
|
|
9
9
|
return [];
|
|
10
10
|
}
|
|
11
|
-
const response = await (0, search_zip_1.searchZipGeneral)(url)(params.term, params.limit);
|
|
11
|
+
const response = await (0, search_zip_1.searchZipGeneral)(url)(params.term, params.limit, { signal: params.signal });
|
|
12
12
|
return response.map((a) => ({ id: a.id, label: getLabel(a) }));
|
|
13
13
|
};
|
|
14
14
|
exports.loadZipOptionsGeneral = loadZipOptionsGeneral;
|
package/common/search-zip.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { Location } from "./types";
|
|
2
|
-
export declare const searchZipGeneral: (url: `/${string}`) => (term: string, limit?: number
|
|
2
|
+
export declare const searchZipGeneral: (url: `/${string}`) => (term: string, limit?: number, options?: {
|
|
3
|
+
signal?: AbortSignal;
|
|
4
|
+
}) => Promise<Location[]>;
|
package/common/search-zip.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.searchZipGeneral = void 0;
|
|
4
4
|
const config_1 = require("../config");
|
|
5
5
|
const regexp = /^([0-9]{1,5})$/;
|
|
6
|
-
const searchZipGeneral = (url) => async (term, limit) => {
|
|
6
|
+
const searchZipGeneral = (url) => async (term, limit, options) => {
|
|
7
7
|
if (term.length === 0 || !regexp.test(term)) {
|
|
8
8
|
return [];
|
|
9
9
|
}
|
|
@@ -13,7 +13,7 @@ const searchZipGeneral = (url) => async (term, limit) => {
|
|
|
13
13
|
if (limit) {
|
|
14
14
|
params.append("limit", limit.toString());
|
|
15
15
|
}
|
|
16
|
-
const response = await fetch(`${config_1.smartAddressUrl}${url}?${params}
|
|
16
|
+
const response = await fetch(`${config_1.smartAddressUrl}${url}?${params}`, { signal: options === null || options === void 0 ? void 0 : options.signal });
|
|
17
17
|
return await response.json();
|
|
18
18
|
};
|
|
19
19
|
exports.searchZipGeneral = searchZipGeneral;
|
package/common/search.d.ts
CHANGED
package/common/search.js
CHANGED
|
@@ -19,7 +19,7 @@ const searchGeneral = (url) => async (props) => {
|
|
|
19
19
|
if (props.address) {
|
|
20
20
|
params.append("address", props.address);
|
|
21
21
|
}
|
|
22
|
-
const response = await fetch(`${config_1.smartAddressUrl}${url}?${params}
|
|
22
|
+
const response = await fetch(`${config_1.smartAddressUrl}${url}?${params}`, { signal: props.signal });
|
|
23
23
|
return await response.json();
|
|
24
24
|
};
|
|
25
25
|
exports.searchGeneral = searchGeneral;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/smart-address",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "15.2.1",
|
|
4
|
+
"description": "Typed client helpers for the Czech Smart Address API: address and ZIP search, autocomplete loaders, address details",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"build": "tsc -P tsconfig.json",
|
|
10
10
|
"typecheck": "tsc --noEmit"
|
|
11
11
|
},
|
|
12
|
-
"author": "UX Fans s.r.o",
|
|
12
|
+
"author": "UX Fans s.r.o. <dev@uxf.cz>",
|
|
13
|
+
"homepage": "https://fe.uxf.dev/docs/smart-address",
|
|
13
14
|
"license": "MIT"
|
|
14
15
|
}
|
|
@@ -5,5 +5,7 @@ type Params = {
|
|
|
5
5
|
zip?: number;
|
|
6
6
|
getLabel?: (address: Location) => string;
|
|
7
7
|
};
|
|
8
|
-
export declare const createAddressLoader: (params: Params) => (term: string
|
|
8
|
+
export declare const createAddressLoader: (params: Params) => (term: string, options?: {
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
}) => Promise<import("./types").Option[]>;
|
|
9
11
|
export {};
|
|
@@ -2,5 +2,7 @@ import { Location } from "./types";
|
|
|
2
2
|
type Params = {
|
|
3
3
|
getLabel?: (address: Location) => string;
|
|
4
4
|
};
|
|
5
|
-
export declare const createZipLoader: (params: Params) => (term: string
|
|
5
|
+
export declare const createZipLoader: (params: Params) => (term: string, options?: {
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
}) => Promise<import("./types").Option[]>;
|
|
6
8
|
export {};
|
package/v1/index.d.ts
CHANGED
|
@@ -5,10 +5,14 @@ export declare const SmartAddress: {
|
|
|
5
5
|
limit?: number;
|
|
6
6
|
zip?: number;
|
|
7
7
|
getLabel?: (address: import("./types").Location) => string;
|
|
8
|
-
}) => (term: string
|
|
8
|
+
}) => (term: string, options?: {
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
}) => Promise<import("./types").Option[]>;
|
|
9
11
|
createZipLoader: (params: {
|
|
10
12
|
getLabel?: (address: import("./types").Location) => string;
|
|
11
|
-
}) => (term: string
|
|
13
|
+
}) => (term: string, options?: {
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
}) => Promise<import("./types").Option[]>;
|
|
12
16
|
getAddress: (id: number) => Promise<import("./types").Location>;
|
|
13
17
|
getAddressExtended: (id: number) => Promise<import("./types").LocationExtended>;
|
|
14
18
|
getCity: (id: number) => Promise<import("./types").Location>;
|
|
@@ -23,11 +27,13 @@ export declare const SmartAddress: {
|
|
|
23
27
|
zip?: number;
|
|
24
28
|
address?: string;
|
|
25
29
|
getLabel?: (address: import("./types").Location) => string;
|
|
30
|
+
signal?: AbortSignal;
|
|
26
31
|
}) => Promise<import("./types").Option[]>;
|
|
27
32
|
loadZipOptions: (params: {
|
|
28
33
|
term: string;
|
|
29
34
|
limit?: number;
|
|
30
35
|
getLabel?: (address: import("./types").Location) => string;
|
|
36
|
+
signal?: AbortSignal;
|
|
31
37
|
}) => Promise<import("./types").Option[]>;
|
|
32
38
|
search: (props: {
|
|
33
39
|
term: string;
|
|
@@ -35,6 +41,9 @@ export declare const SmartAddress: {
|
|
|
35
41
|
limit?: number;
|
|
36
42
|
zip?: number;
|
|
37
43
|
address?: string;
|
|
44
|
+
signal?: AbortSignal;
|
|
45
|
+
}) => Promise<import("./types").Location[]>;
|
|
46
|
+
searchZip: (term: string, limit?: number, options?: {
|
|
47
|
+
signal?: AbortSignal;
|
|
38
48
|
}) => Promise<import("./types").Location[]>;
|
|
39
|
-
searchZip: (term: string, limit?: number) => Promise<import("./types").Location[]>;
|
|
40
49
|
};
|
package/v1/load-zip-options.d.ts
CHANGED
package/v1/search-zip.d.ts
CHANGED
package/v1/search.d.ts
CHANGED
|
@@ -6,5 +6,7 @@ type Params = {
|
|
|
6
6
|
address?: string;
|
|
7
7
|
getLabel?: (address: Location) => string;
|
|
8
8
|
};
|
|
9
|
-
export declare const createAddressLoader: (params: Params) => (term: string
|
|
9
|
+
export declare const createAddressLoader: (params: Params) => (term: string, options?: {
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}) => Promise<import("./types").Option[]>;
|
|
10
12
|
export {};
|
|
@@ -3,5 +3,7 @@ type Params = {
|
|
|
3
3
|
limit?: number;
|
|
4
4
|
getLabel?: (address: Location) => string;
|
|
5
5
|
};
|
|
6
|
-
export declare const createZipLoader: (params: Params) => (term: string
|
|
6
|
+
export declare const createZipLoader: (params: Params) => (term: string, options?: {
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
}) => Promise<import("./types").Option[]>;
|
|
7
9
|
export {};
|
package/v2/load-zip-options.d.ts
CHANGED
package/v2/search-zip.d.ts
CHANGED