@uxf/smart-address 11.126.0 → 14.1.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 +12 -13
- 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 +1 -1
- package/v1/create-address-loader.d.ts +3 -1
- package/v1/create-zip-loader.d.ts +3 -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/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/README.md
CHANGED
|
@@ -58,18 +58,18 @@ const options = await loadAddressOptions({ term: "Sovova", level: 2 });
|
|
|
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 | 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[]>`
|
|
61
|
+
| Function | Signature | Notes |
|
|
62
|
+
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
63
|
+
| `search` | `(props: { term: string; level: number; limit?: number; zip?: number; address?: string; signal?: AbortSignal }) => Promise<Location[]>` | `limit` defaults to `10`. Empty `term` → `[]` (no request). |
|
|
64
|
+
| `searchZip` | `(term: string, limit?: number, options?: { signal?: AbortSignal }) => 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; signal?: AbortSignal }) => Promise<Option[]>` | Maps `search` results to `Option`s. Default label: `` `${ulice ?? ""}, ${obec ?? ""}` ``. |
|
|
67
|
+
| `loadZipOptions` | `(params: { term: string; limit?: number; getLabel?: (address: Location) => string; signal?: AbortSignal }) => Promise<Option[]>` | Default label: the `psc` (ZIP). |
|
|
68
|
+
| `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`. |
|
|
69
|
+
| `createZipLoader` | `(params: { limit?: number; getLabel?: (address: Location) => string }) => (term: string, options?: { signal?: AbortSignal }) => 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
|
|
|
@@ -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
|
|
|
@@ -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
|
@@ -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/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
|
+
});
|
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