@uxf/smart-address 14.1.0 → 16.16.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/LICENSE +21 -0
- package/README.md +2 -0
- package/common/__tests__/create-loader.test.js +8 -8
- package/common/__tests__/load-address-options.test.js +11 -11
- package/common/__tests__/load-zip-options.test.js +8 -8
- package/common/__tests__/search-zip.test.js +8 -8
- package/common/__tests__/search.test.js +5 -5
- package/common/create-loader.d.ts +1 -1
- package/common/get-address-extended.d.ts +1 -1
- package/common/get-address-extended.js +2 -2
- package/common/get-address.d.ts +1 -1
- package/common/get-address.js +2 -2
- package/common/index.d.ts +1 -1
- package/common/index.js +1 -1
- package/common/load-address-options.d.ts +1 -1
- package/common/load-address-options.js +2 -2
- package/common/load-zip-options.d.ts +1 -1
- package/common/load-zip-options.js +2 -2
- package/common/search-zip.d.ts +1 -1
- package/common/search-zip.js +2 -2
- package/common/search.d.ts +1 -1
- package/common/search.js +2 -2
- package/package.json +4 -3
- package/v1/create-address-loader.d.ts +2 -2
- package/v1/create-address-loader.js +3 -3
- package/v1/create-zip-loader.d.ts +2 -2
- package/v1/create-zip-loader.js +3 -3
- package/v1/get-address-extended.d.ts +1 -1
- package/v1/get-address-extended.js +2 -2
- package/v1/get-address.d.ts +1 -1
- package/v1/get-address.js +2 -2
- package/v1/get-city-part.d.ts +1 -1
- package/v1/get-city-part.js +2 -2
- package/v1/get-city.d.ts +1 -1
- package/v1/get-city.js +2 -2
- package/v1/get-city.test.js +4 -4
- package/v1/get-momc.d.ts +1 -1
- package/v1/get-momc.js +2 -2
- package/v1/get-mop.d.ts +1 -1
- package/v1/get-mop.js +2 -2
- package/v1/get-street.d.ts +1 -1
- package/v1/get-street.js +2 -2
- package/v1/index.d.ts +23 -27
- package/v1/index.js +26 -26
- package/v1/load-address-options.d.ts +2 -2
- package/v1/load-address-options.js +2 -2
- package/v1/load-zip-options.d.ts +2 -2
- package/v1/load-zip-options.js +2 -2
- package/v1/search-zip.d.ts +1 -1
- package/v1/search-zip.js +2 -2
- package/v1/search.d.ts +1 -1
- package/v1/search.js +2 -2
- package/v1/types.d.ts +1 -1
- package/v1/types.js +1 -1
- package/v2/__tests__/get-building-addresses.test.js +4 -4
- package/v2/__tests__/search-city-part.test.js +8 -8
- package/v2/create-address-loader.d.ts +2 -2
- package/v2/create-address-loader.js +3 -3
- package/v2/create-zip-loader.d.ts +2 -2
- package/v2/create-zip-loader.js +3 -3
- package/v2/get-address-extended.d.ts +1 -1
- package/v2/get-address-extended.js +2 -2
- package/v2/get-address.d.ts +1 -1
- package/v2/get-address.js +2 -2
- package/v2/get-building-addresses.d.ts +1 -1
- package/v2/get-building-addresses.js +2 -2
- package/v2/index.d.ts +11 -11
- package/v2/index.js +11 -11
- package/v2/load-address-options.d.ts +2 -2
- package/v2/load-address-options.js +2 -2
- package/v2/load-zip-options.d.ts +2 -2
- package/v2/load-zip-options.js +2 -2
- package/v2/search-city-part.d.ts +1 -1
- package/v2/search-city-part.js +2 -2
- package/v2/search-zip.d.ts +1 -1
- package/v2/search-zip.js +2 -2
- package/v2/search.d.ts +1 -1
- package/v2/search.js +2 -2
- package/v2/types.d.ts +2 -2
- package/v2/types.js +1 -1
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
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
3
|
+
const create_address_loader_ts_1 = require("../../v1/create-address-loader.js");
|
|
4
|
+
const create_zip_loader_ts_1 = require("../../v1/create-zip-loader.js");
|
|
5
|
+
const create_address_loader_ts_2 = require("../../v2/create-address-loader.js");
|
|
6
|
+
const create_zip_loader_ts_2 = require("../../v2/create-zip-loader.js");
|
|
7
7
|
const fetchMock = jest.fn(() => Promise.resolve({ json: () => Promise.resolve([]) }));
|
|
8
8
|
beforeEach(() => {
|
|
9
9
|
fetchMock.mockClear();
|
|
10
10
|
global.fetch = fetchMock;
|
|
11
11
|
});
|
|
12
12
|
const cases = [
|
|
13
|
-
{ name: "v1 address loader", load: (0,
|
|
14
|
-
{ name: "v2 address loader", load: (0,
|
|
15
|
-
{ name: "v1 zip loader", load: (0,
|
|
16
|
-
{ name: "v2 zip loader", load: (0,
|
|
13
|
+
{ name: "v1 address loader", load: (0, create_address_loader_ts_1.createAddressLoader)({ level: 1 }), term: "Praha" },
|
|
14
|
+
{ name: "v2 address loader", load: (0, create_address_loader_ts_2.createAddressLoader)({ level: 1 }), term: "Praha" },
|
|
15
|
+
{ name: "v1 zip loader", load: (0, create_zip_loader_ts_1.createZipLoader)({}), term: "11000" },
|
|
16
|
+
{ name: "v2 zip loader", load: (0, create_zip_loader_ts_2.createZipLoader)({}), term: "11000" },
|
|
17
17
|
];
|
|
18
18
|
cases.forEach(({ name, load, term }) => {
|
|
19
19
|
test(`${name} passes the abort signal on to fetch`, async () => {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
3
|
+
const load_address_options_ts_1 = require("../../v1/load-address-options.js");
|
|
4
|
+
const search_ts_1 = require("../search.js");
|
|
5
5
|
global.fetch = jest.fn();
|
|
6
|
-
jest.mock("../search");
|
|
6
|
+
jest.mock("../search.ts");
|
|
7
7
|
describe("loadAddressOptions", () => {
|
|
8
8
|
beforeEach(() => {
|
|
9
9
|
jest.clearAllMocks();
|
|
10
10
|
});
|
|
11
11
|
it("should return an empty array if term is empty", async () => {
|
|
12
|
-
const options = await (0,
|
|
12
|
+
const options = await (0, load_address_options_ts_1.loadAddressOptions)({ term: "", level: 1 });
|
|
13
13
|
expect(options).toEqual([]);
|
|
14
14
|
});
|
|
15
15
|
it("should call search with correct parameters", async () => {
|
|
@@ -47,10 +47,10 @@ describe("loadAddressOptions", () => {
|
|
|
47
47
|
},
|
|
48
48
|
];
|
|
49
49
|
const mockSearch = jest.fn();
|
|
50
|
-
|
|
50
|
+
search_ts_1.searchGeneral.mockReturnValue(mockSearch);
|
|
51
51
|
mockSearch.mockResolvedValue(mockResponse);
|
|
52
|
-
await (0,
|
|
53
|
-
expect(
|
|
52
|
+
await (0, load_address_options_ts_1.loadAddressOptions)({ term, level });
|
|
53
|
+
expect(search_ts_1.searchGeneral).toHaveBeenCalledWith("/v1/search");
|
|
54
54
|
expect(mockSearch).toHaveBeenCalledWith({ term, level, limit: 10, zip: undefined });
|
|
55
55
|
});
|
|
56
56
|
const term = "Prague";
|
|
@@ -88,9 +88,9 @@ describe("loadAddressOptions", () => {
|
|
|
88
88
|
},
|
|
89
89
|
];
|
|
90
90
|
const mockSearch = jest.fn();
|
|
91
|
-
|
|
91
|
+
search_ts_1.searchGeneral.mockReturnValue(mockSearch);
|
|
92
92
|
mockSearch.mockResolvedValue(mockResponse);
|
|
93
|
-
const options = await (0,
|
|
93
|
+
const options = await (0, load_address_options_ts_1.loadAddressOptions)({ term, level });
|
|
94
94
|
expect(options).toEqual([{ id: 1, label: "Main St, Vrchlabi" }]);
|
|
95
95
|
});
|
|
96
96
|
it("should use custom getLabel function if provided", async () => {
|
|
@@ -126,10 +126,10 @@ describe("loadAddressOptions", () => {
|
|
|
126
126
|
},
|
|
127
127
|
];
|
|
128
128
|
const mockSearch = jest.fn();
|
|
129
|
-
|
|
129
|
+
search_ts_1.searchGeneral.mockReturnValue(mockSearch);
|
|
130
130
|
mockSearch.mockResolvedValue(mockResponse);
|
|
131
131
|
const customGetLabel = (address) => `${address.obec} - ${address.ulice}`;
|
|
132
|
-
const options = await (0,
|
|
132
|
+
const options = await (0, load_address_options_ts_1.loadAddressOptions)({ term, level, getLabel: customGetLabel });
|
|
133
133
|
expect(options).toEqual([{ id: 1, label: "Vrchlabi - Main St" }]);
|
|
134
134
|
});
|
|
135
135
|
});
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
3
|
+
const load_zip_options_ts_1 = require("../../v1/load-zip-options.js");
|
|
4
|
+
const search_zip_ts_1 = require("../search-zip.js");
|
|
5
5
|
global.fetch = jest.fn();
|
|
6
|
-
jest.mock("../search-zip");
|
|
6
|
+
jest.mock("../search-zip.ts");
|
|
7
7
|
describe("loadZipOptions", () => {
|
|
8
8
|
it("should return empty array when term is empty", async () => {
|
|
9
|
-
const result = await (0,
|
|
9
|
+
const result = await (0, load_zip_options_ts_1.loadZipOptions)({ term: "" });
|
|
10
10
|
expect(result).toEqual([]);
|
|
11
11
|
});
|
|
12
12
|
it("should return formatted options with default label when term is provided", async () => {
|
|
13
13
|
const mockSearch = jest.fn();
|
|
14
|
-
|
|
14
|
+
search_zip_ts_1.searchZipGeneral.mockReturnValue(mockSearch);
|
|
15
15
|
mockSearch.mockResolvedValueOnce([
|
|
16
16
|
{ id: 1, psc: 12345 },
|
|
17
17
|
{ id: 2, psc: 54321 },
|
|
18
18
|
]);
|
|
19
|
-
const result = await (0,
|
|
19
|
+
const result = await (0, load_zip_options_ts_1.loadZipOptions)({ term: "123" });
|
|
20
20
|
expect(result).toEqual([
|
|
21
21
|
{ id: 1, label: "12345" },
|
|
22
22
|
{ id: 2, label: "54321" },
|
|
@@ -24,13 +24,13 @@ describe("loadZipOptions", () => {
|
|
|
24
24
|
});
|
|
25
25
|
it("should return formatted options with custom label when getLabel is provided", async () => {
|
|
26
26
|
const mockSearch = jest.fn();
|
|
27
|
-
|
|
27
|
+
search_zip_ts_1.searchZipGeneral.mockReturnValue(mockSearch);
|
|
28
28
|
mockSearch.mockResolvedValueOnce([
|
|
29
29
|
{ id: 1, psc: 12345 },
|
|
30
30
|
{ id: 2, psc: 54321 },
|
|
31
31
|
]);
|
|
32
32
|
const customLabel = (address) => `Zip: ${address.psc}`;
|
|
33
|
-
const result = await (0,
|
|
33
|
+
const result = await (0, load_zip_options_ts_1.loadZipOptions)({ term: "123", getLabel: customLabel });
|
|
34
34
|
expect(result).toEqual([
|
|
35
35
|
{ id: 1, label: "Zip: 12345" },
|
|
36
36
|
{ id: 2, label: "Zip: 54321" },
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
3
|
+
const config_ts_1 = require("../../config.js");
|
|
4
|
+
const search_zip_ts_1 = require("../../v1/search-zip.js");
|
|
5
5
|
global.fetch = jest.fn();
|
|
6
|
-
jest.mock("../../config", () => ({
|
|
6
|
+
jest.mock("../../config.ts", () => ({
|
|
7
7
|
smartAddressUrl: "http://example.com",
|
|
8
8
|
}));
|
|
9
9
|
describe("searchZip", () => {
|
|
@@ -14,15 +14,15 @@ describe("searchZip", () => {
|
|
|
14
14
|
jest.resetAllMocks();
|
|
15
15
|
});
|
|
16
16
|
it("should return an empty array for empty input", async () => {
|
|
17
|
-
const result = await (0,
|
|
17
|
+
const result = await (0, search_zip_ts_1.searchZip)("");
|
|
18
18
|
expect(result).toEqual([]);
|
|
19
19
|
});
|
|
20
20
|
it("should return an empty array for non-numeric input", async () => {
|
|
21
|
-
const result = await (0,
|
|
21
|
+
const result = await (0, search_zip_ts_1.searchZip)("abc");
|
|
22
22
|
expect(result).toEqual([]);
|
|
23
23
|
});
|
|
24
24
|
it("should return an empty array for invalid zip code", async () => {
|
|
25
|
-
const result = await (0,
|
|
25
|
+
const result = await (0, search_zip_ts_1.searchZip)("123456");
|
|
26
26
|
expect(result).toEqual([]);
|
|
27
27
|
});
|
|
28
28
|
it("should return an array of locations for valid zip code", async () => {
|
|
@@ -34,8 +34,8 @@ describe("searchZip", () => {
|
|
|
34
34
|
status: 200,
|
|
35
35
|
json: () => Promise.resolve(mockResponse),
|
|
36
36
|
}));
|
|
37
|
-
const result = await (0,
|
|
37
|
+
const result = await (0, search_zip_ts_1.searchZip)("12345");
|
|
38
38
|
expect(result).toEqual(mockResponse);
|
|
39
|
-
expect(fetch).toHaveBeenCalledWith(`${
|
|
39
|
+
expect(fetch).toHaveBeenCalledWith(`${config_ts_1.smartAddressUrl}/v1/zip/search?term=12345`, { signal: undefined });
|
|
40
40
|
});
|
|
41
41
|
});
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
3
|
+
const config_ts_1 = require("../../config.js");
|
|
4
|
+
const search_ts_1 = require("../../v1/search.js");
|
|
5
5
|
global.fetch = jest.fn();
|
|
6
6
|
describe("SmartAddress v1 search", () => {
|
|
7
7
|
beforeEach(() => {
|
|
8
8
|
jest.clearAllMocks();
|
|
9
9
|
});
|
|
10
10
|
it("should return an empty array when term is empty", async () => {
|
|
11
|
-
const result = await (0,
|
|
11
|
+
const result = await (0, search_ts_1.search)({ term: "", level: 1 });
|
|
12
12
|
expect(result).toEqual([]);
|
|
13
13
|
expect(fetch).not.toHaveBeenCalled();
|
|
14
14
|
});
|
|
@@ -17,8 +17,8 @@ describe("SmartAddress v1 search", () => {
|
|
|
17
17
|
fetch.mockResolvedValue({
|
|
18
18
|
json: jest.fn().mockResolvedValue(mockResponse),
|
|
19
19
|
});
|
|
20
|
-
const result = await (0,
|
|
21
|
-
expect(fetch).toHaveBeenCalledWith(`${
|
|
20
|
+
const result = await (0, search_ts_1.search)({ term: "test", level: 2, limit: 5, zip: 12345, address: "some address" });
|
|
21
|
+
expect(fetch).toHaveBeenCalledWith(`${config_ts_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,2 +1,2 @@
|
|
|
1
|
-
import { LocationExtended } from "./types";
|
|
1
|
+
import { LocationExtended } from "./types.ts";
|
|
2
2
|
export declare const getAddressExtendedGeneral: <TResponse = LocationExtended>(url: `/${string}/`) => (id: number) => Promise<TResponse>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAddressExtendedGeneral = void 0;
|
|
4
|
-
const
|
|
4
|
+
const config_ts_1 = require("../config.js");
|
|
5
5
|
const getAddressExtendedGeneral = (url) => async (id) => {
|
|
6
|
-
const response = await fetch(`${
|
|
6
|
+
const response = await fetch(`${config_ts_1.smartAddressUrl}${url}${id}/extended`);
|
|
7
7
|
return await response.json();
|
|
8
8
|
};
|
|
9
9
|
exports.getAddressExtendedGeneral = getAddressExtendedGeneral;
|
package/common/get-address.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Location } from "./types";
|
|
1
|
+
import { Location } from "./types.ts";
|
|
2
2
|
export declare const getAddressGeneral: (url: `/${string}/`) => (id: number) => Promise<Location>;
|
package/common/get-address.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAddressGeneral = void 0;
|
|
4
|
-
const
|
|
4
|
+
const config_ts_1 = require("../config.js");
|
|
5
5
|
const getAddressGeneral = (url) => async (id) => {
|
|
6
|
-
const response = await fetch(
|
|
6
|
+
const response = await fetch(config_ts_1.smartAddressUrl + url + id);
|
|
7
7
|
return await response.json();
|
|
8
8
|
};
|
|
9
9
|
exports.getAddressGeneral = getAddressGeneral;
|
package/common/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./types";
|
|
1
|
+
export * from "./types.ts";
|
package/common/index.js
CHANGED
|
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./types"), exports);
|
|
17
|
+
__exportStar(require("./types.js"), exports);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loadAddressOptionsGeneral = void 0;
|
|
4
|
-
const
|
|
4
|
+
const search_ts_1 = require("./search.js");
|
|
5
5
|
const loadAddressOptionsGeneral = (url) => async (params) => {
|
|
6
6
|
var _a, _b;
|
|
7
7
|
const limit = (_a = params.limit) !== null && _a !== void 0 ? _a : 10;
|
|
@@ -9,7 +9,7 @@ const loadAddressOptionsGeneral = (url) => async (params) => {
|
|
|
9
9
|
if (params.term.length === 0) {
|
|
10
10
|
return [];
|
|
11
11
|
}
|
|
12
|
-
const response = await (0,
|
|
12
|
+
const response = await (0, search_ts_1.searchGeneral)(url)({
|
|
13
13
|
term: params.term,
|
|
14
14
|
level: params.level,
|
|
15
15
|
limit,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loadZipOptionsGeneral = void 0;
|
|
4
|
-
const
|
|
4
|
+
const search_zip_ts_1 = require("./search-zip.js");
|
|
5
5
|
const loadZipOptionsGeneral = (url) => async (params) => {
|
|
6
6
|
var _a;
|
|
7
7
|
const getLabel = (_a = params.getLabel) !== null && _a !== void 0 ? _a : ((address) => `${address.psc}`);
|
|
8
8
|
if (params.term.length === 0) {
|
|
9
9
|
return [];
|
|
10
10
|
}
|
|
11
|
-
const response = await (0,
|
|
11
|
+
const response = await (0, search_zip_ts_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
package/common/search-zip.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.searchZipGeneral = void 0;
|
|
4
|
-
const
|
|
4
|
+
const config_ts_1 = require("../config.js");
|
|
5
5
|
const regexp = /^([0-9]{1,5})$/;
|
|
6
6
|
const searchZipGeneral = (url) => async (term, limit, options) => {
|
|
7
7
|
if (term.length === 0 || !regexp.test(term)) {
|
|
@@ -13,7 +13,7 @@ const searchZipGeneral = (url) => async (term, limit, options) => {
|
|
|
13
13
|
if (limit) {
|
|
14
14
|
params.append("limit", limit.toString());
|
|
15
15
|
}
|
|
16
|
-
const response = await fetch(`${
|
|
16
|
+
const response = await fetch(`${config_ts_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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.searchGeneral = void 0;
|
|
4
|
-
const
|
|
4
|
+
const config_ts_1 = require("../config.js");
|
|
5
5
|
const searchGeneral = (url) => async (props) => {
|
|
6
6
|
var _a;
|
|
7
7
|
const limit = (_a = props.limit) !== null && _a !== void 0 ? _a : 10;
|
|
@@ -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(`${
|
|
22
|
+
const response = await fetch(`${config_ts_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": "16.16.0",
|
|
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
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Location } from "./types";
|
|
1
|
+
import { Location } from "./types.ts";
|
|
2
2
|
type Params = {
|
|
3
3
|
level: number;
|
|
4
4
|
limit?: number;
|
|
@@ -7,5 +7,5 @@ type Params = {
|
|
|
7
7
|
};
|
|
8
8
|
export declare const createAddressLoader: (params: Params) => (term: string, options?: {
|
|
9
9
|
signal?: AbortSignal;
|
|
10
|
-
}) => Promise<import("./types").Option[]>;
|
|
10
|
+
}) => Promise<import("./types.ts").Option[]>;
|
|
11
11
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createAddressLoader = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const createAddressLoader = (params) => (0,
|
|
4
|
+
const create_loader_ts_1 = require("../common/create-loader.js");
|
|
5
|
+
const load_address_options_ts_1 = require("./load-address-options.js");
|
|
6
|
+
const createAddressLoader = (params) => (0, create_loader_ts_1.createLoaderGeneral)(load_address_options_ts_1.loadAddressOptions, params);
|
|
7
7
|
exports.createAddressLoader = createAddressLoader;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Location } from "./types";
|
|
1
|
+
import { Location } from "./types.ts";
|
|
2
2
|
type Params = {
|
|
3
3
|
getLabel?: (address: Location) => string;
|
|
4
4
|
};
|
|
5
5
|
export declare const createZipLoader: (params: Params) => (term: string, options?: {
|
|
6
6
|
signal?: AbortSignal;
|
|
7
|
-
}) => Promise<import("./types").Option[]>;
|
|
7
|
+
}) => Promise<import("./types.ts").Option[]>;
|
|
8
8
|
export {};
|
package/v1/create-zip-loader.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createZipLoader = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const createZipLoader = (params) => (0,
|
|
4
|
+
const create_loader_ts_1 = require("../common/create-loader.js");
|
|
5
|
+
const load_zip_options_ts_1 = require("./load-zip-options.js");
|
|
6
|
+
const createZipLoader = (params) => (0, create_loader_ts_1.createLoaderGeneral)(load_zip_options_ts_1.loadZipOptions, params);
|
|
7
7
|
exports.createZipLoader = createZipLoader;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const getAddressExtended: (id: number) => Promise<import("./types").LocationExtended>;
|
|
1
|
+
export declare const getAddressExtended: (id: number) => Promise<import("./types.ts").LocationExtended>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAddressExtended = void 0;
|
|
4
|
-
const
|
|
5
|
-
exports.getAddressExtended = (0,
|
|
4
|
+
const get_address_extended_ts_1 = require("../common/get-address-extended.js");
|
|
5
|
+
exports.getAddressExtended = (0, get_address_extended_ts_1.getAddressExtendedGeneral)("/v1/address/");
|
package/v1/get-address.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const getAddress: (id: number) => Promise<import("./types").Location>;
|
|
1
|
+
export declare const getAddress: (id: number) => Promise<import("./types.ts").Location>;
|
package/v1/get-address.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAddress = void 0;
|
|
4
|
-
const
|
|
5
|
-
exports.getAddress = (0,
|
|
4
|
+
const get_address_ts_1 = require("../common/get-address.js");
|
|
5
|
+
exports.getAddress = (0, get_address_ts_1.getAddressGeneral)("/v1/address/");
|
package/v1/get-city-part.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Location } from "./types";
|
|
1
|
+
import { Location } from "./types.ts";
|
|
2
2
|
export declare const getCityPart: (id: number) => Promise<Location>;
|
package/v1/get-city-part.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCityPart = void 0;
|
|
4
|
-
const
|
|
4
|
+
const config_ts_1 = require("../config.js");
|
|
5
5
|
const getCityPart = async (id) => {
|
|
6
|
-
const response = await fetch(`${
|
|
6
|
+
const response = await fetch(`${config_ts_1.smartAddressUrl}/v1/address/city-part/${id}`);
|
|
7
7
|
return await response.json();
|
|
8
8
|
};
|
|
9
9
|
exports.getCityPart = getCityPart;
|
package/v1/get-city.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Location } from "./types";
|
|
1
|
+
import { Location } from "./types.ts";
|
|
2
2
|
export declare const getCity: (id: number) => Promise<Location>;
|
package/v1/get-city.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCity = void 0;
|
|
4
|
-
const
|
|
4
|
+
const config_ts_1 = require("../config.js");
|
|
5
5
|
const getCity = async (id) => {
|
|
6
|
-
const response = await fetch(`${
|
|
6
|
+
const response = await fetch(`${config_ts_1.smartAddressUrl}/v1/address/city/${id}`);
|
|
7
7
|
return await response.json();
|
|
8
8
|
};
|
|
9
9
|
exports.getCity = getCity;
|
package/v1/get-city.test.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
/** @jest-environment node */
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const config_ts_1 = require("../config.js");
|
|
5
|
+
const get_city_ts_1 = require("./get-city.js");
|
|
6
6
|
afterEach(() => {
|
|
7
7
|
jest.restoreAllMocks();
|
|
8
8
|
});
|
|
9
9
|
test("asks the city endpoint once, with the base URL once", async () => {
|
|
10
10
|
const fetchMock = jest.spyOn(global, "fetch").mockResolvedValue(new Response("{}"));
|
|
11
|
-
await (0,
|
|
12
|
-
expect(fetchMock).toHaveBeenCalledWith(`${
|
|
11
|
+
await (0, get_city_ts_1.getCity)(42);
|
|
12
|
+
expect(fetchMock).toHaveBeenCalledWith(`${config_ts_1.smartAddressUrl}/v1/address/city/42`);
|
|
13
13
|
});
|
package/v1/get-momc.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Location } from "./types";
|
|
1
|
+
import { Location } from "./types.ts";
|
|
2
2
|
export declare const getMomc: (id: number) => Promise<Location>;
|
package/v1/get-momc.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getMomc = void 0;
|
|
4
|
-
const
|
|
4
|
+
const config_ts_1 = require("../config.js");
|
|
5
5
|
const getMomc = async (id) => {
|
|
6
|
-
const response = await fetch(`${
|
|
6
|
+
const response = await fetch(`${config_ts_1.smartAddressUrl}/v1/address/momc/${id}`);
|
|
7
7
|
return await response.json();
|
|
8
8
|
};
|
|
9
9
|
exports.getMomc = getMomc;
|
package/v1/get-mop.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Location } from "./types";
|
|
1
|
+
import { Location } from "./types.ts";
|
|
2
2
|
export declare const getMop: (id: number) => Promise<Location>;
|
package/v1/get-mop.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getMop = void 0;
|
|
4
|
-
const
|
|
4
|
+
const config_ts_1 = require("../config.js");
|
|
5
5
|
const getMop = async (id) => {
|
|
6
|
-
const response = await fetch(`${
|
|
6
|
+
const response = await fetch(`${config_ts_1.smartAddressUrl}/v1/address/mop/${id}`);
|
|
7
7
|
return await response.json();
|
|
8
8
|
};
|
|
9
9
|
exports.getMop = getMop;
|
package/v1/get-street.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Location } from "./types";
|
|
1
|
+
import { Location } from "./types.ts";
|
|
2
2
|
export declare const getStreet: (id: number) => Promise<Location>;
|
package/v1/get-street.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getStreet = void 0;
|
|
4
|
-
const
|
|
4
|
+
const config_ts_1 = require("../config.js");
|
|
5
5
|
const getStreet = async (id) => {
|
|
6
|
-
const response = await fetch(
|
|
6
|
+
const response = await fetch(config_ts_1.smartAddressUrl + "/v1/address/street/" + id);
|
|
7
7
|
return await response.json();
|
|
8
8
|
};
|
|
9
9
|
exports.getStreet = getStreet;
|