@uxf/smart-address 11.80.2 → 11.103.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/README.md +1 -1
- package/{smart-address/v1 → common/__tests__}/load-address-options.test.js +22 -14
- package/{smart-address/v1 → common/__tests__}/load-zip-options.test.js +10 -5
- package/{smart-address/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/{smart-address/v1 → common}/load-address-options.d.ts +2 -1
- package/common/load-address-options.js +21 -0
- package/{smart-address/v1 → common}/load-zip-options.d.ts +2 -1
- package/{smart-address/v1 → common}/load-zip-options.js +4 -4
- package/common/search-zip.d.ts +2 -0
- package/common/search-zip.js +19 -0
- package/{smart-address/v1 → common}/search.d.ts +2 -1
- package/{smart-address/v1 → common}/search.js +8 -5
- package/{smart-address/v1 → common}/types.d.ts +4 -5
- package/package.json +1 -1
- package/v1/create-address-loader.d.ts +9 -0
- package/v1/create-address-loader.js +7 -0
- package/v1/create-zip-loader.d.ts +6 -0
- package/{smart-address/v1 → v1}/create-zip-loader.js +2 -6
- package/{smart-address/v1 → v1}/get-address-extended.d.ts +1 -2
- package/v1/get-address-extended.js +5 -0
- package/v1/get-address.d.ts +1 -0
- package/v1/get-address.js +5 -0
- package/{smart-address/v1 → v1}/get-city-part.js +2 -2
- package/{smart-address/v1 → v1}/get-city.js +2 -2
- package/{smart-address/v1 → v1}/get-momc.js +2 -2
- package/{smart-address/v1 → v1}/get-mop.js +2 -2
- package/{smart-address/v1 → v1}/get-street.js +1 -1
- package/{smart-address/v1 → v1}/index.d.ts +6 -3
- package/v1/load-address-options.d.ts +8 -0
- package/v1/load-address-options.js +5 -0
- package/v1/load-zip-options.d.ts +5 -0
- package/v1/load-zip-options.js +5 -0
- package/v1/search-zip.d.ts +1 -0
- package/v1/search-zip.js +5 -0
- package/v1/search.d.ts +7 -0
- package/v1/search.js +5 -0
- package/v1/types.d.ts +1 -0
- package/v1/types.js +17 -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/smart-address/v1/create-address-loader.d.ts +0 -9
- package/smart-address/v1/create-address-loader.js +0 -14
- package/smart-address/v1/create-zip-loader.d.ts +0 -6
- package/smart-address/v1/get-address-extended.js +0 -9
- package/smart-address/v1/get-address.d.ts +0 -2
- package/smart-address/v1/get-address.js +0 -9
- package/smart-address/v1/load-address-options.js +0 -15
- package/smart-address/v1/search-zip.d.ts +0 -2
- package/smart-address/v1/search-zip.js +0 -16
- package/smart-address/v1/search.test.js +0 -33
- /package/{smart-address/v1 → common/__tests__}/load-address-options.test.d.ts +0 -0
- /package/{smart-address/v1 → common/__tests__}/load-zip-options.test.d.ts +0 -0
- /package/{smart-address/v1 → common/__tests__}/search-zip.test.d.ts +0 -0
- /package/{smart-address/v1 → common/__tests__}/search.test.d.ts +0 -0
- /package/{smart-address/v1 → common}/types.js +0 -0
- /package/{smart-address/config.d.ts → config.d.ts} +0 -0
- /package/{smart-address/config.js → config.js} +0 -0
- /package/{smart-address/v1 → v1}/get-city-part.d.ts +0 -0
- /package/{smart-address/v1 → v1}/get-city.d.ts +0 -0
- /package/{smart-address/v1 → v1}/get-momc.d.ts +0 -0
- /package/{smart-address/v1 → v1}/get-mop.d.ts +0 -0
- /package/{smart-address/v1 → v1}/get-street.d.ts +0 -0
- /package/{smart-address/v1 → v1}/index.js +0 -0
package/v1/types.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("../common/types"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_1 = require("../../config");
|
|
4
|
+
const get_building_addresses_1 = require("../get-building-addresses");
|
|
5
|
+
global.fetch = jest.fn();
|
|
6
|
+
describe("getBuildingAddresses", () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
jest.clearAllMocks();
|
|
9
|
+
});
|
|
10
|
+
it("should fetch building addresses for given id", async () => {
|
|
11
|
+
const mockLocations = [
|
|
12
|
+
{
|
|
13
|
+
id: 1,
|
|
14
|
+
obecKod: 123,
|
|
15
|
+
obecNazev: null,
|
|
16
|
+
obec: null,
|
|
17
|
+
momcKod: null,
|
|
18
|
+
momcNazev: null,
|
|
19
|
+
mopKod: null,
|
|
20
|
+
mopNazev: null,
|
|
21
|
+
castObceKod: null,
|
|
22
|
+
castObceNazev: null,
|
|
23
|
+
uliceKod: null,
|
|
24
|
+
uliceNazev: null,
|
|
25
|
+
ulice: "Main St",
|
|
26
|
+
typSo: null,
|
|
27
|
+
cisloDomovni: null,
|
|
28
|
+
cisloOrientacni: null,
|
|
29
|
+
cisloOrientacniZnak: null,
|
|
30
|
+
psc: null,
|
|
31
|
+
search: "",
|
|
32
|
+
level: 1,
|
|
33
|
+
gps: { latitude: 50.0755, longitude: 14.4378 },
|
|
34
|
+
platiOd: "2024-01-01",
|
|
35
|
+
aktualizace: "2024-10-01",
|
|
36
|
+
okresKod: 456,
|
|
37
|
+
okresNazev: "Prague",
|
|
38
|
+
krajKod: 789,
|
|
39
|
+
krajNazev: "Czech Republic",
|
|
40
|
+
},
|
|
41
|
+
];
|
|
42
|
+
fetch.mockResolvedValue({
|
|
43
|
+
json: jest.fn().mockResolvedValue(mockLocations),
|
|
44
|
+
});
|
|
45
|
+
const result = await (0, get_building_addresses_1.getBuildingAddresses)(123);
|
|
46
|
+
expect(fetch).toHaveBeenCalledWith(`${config_1.smartAddressUrl}/v2/address/123/building-addresses`);
|
|
47
|
+
expect(result).toEqual(mockLocations);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_1 = require("../../config");
|
|
4
|
+
const search_city_part_1 = require("../search-city-part");
|
|
5
|
+
jest.mock("../../config", () => ({
|
|
6
|
+
smartAddressUrl: "http://example.com",
|
|
7
|
+
}));
|
|
8
|
+
describe("searchCityPart", () => {
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
global.fetch = jest.fn();
|
|
11
|
+
});
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
jest.resetAllMocks();
|
|
14
|
+
});
|
|
15
|
+
it("should return an empty array for empty input", async () => {
|
|
16
|
+
const result = await (0, search_city_part_1.searchCityPart)("");
|
|
17
|
+
expect(result).toEqual([]);
|
|
18
|
+
});
|
|
19
|
+
it("should return an array of city parts for valid input", async () => {
|
|
20
|
+
const mockResponse = [
|
|
21
|
+
{
|
|
22
|
+
id: 1,
|
|
23
|
+
name: "Part 1",
|
|
24
|
+
obecKod: 111,
|
|
25
|
+
obecNazev: "City 1",
|
|
26
|
+
zips: ["12345"],
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
fetch.mockImplementation(() => Promise.resolve({
|
|
30
|
+
status: 200,
|
|
31
|
+
json: () => Promise.resolve(mockResponse),
|
|
32
|
+
}));
|
|
33
|
+
const result = await (0, search_city_part_1.searchCityPart)("Vrchlabí");
|
|
34
|
+
expect(result).toEqual(mockResponse);
|
|
35
|
+
expect(fetch).toHaveBeenCalledWith(`${config_1.smartAddressUrl}/v2/city-part/search?term=Vrchlab%C3%AD`);
|
|
36
|
+
});
|
|
37
|
+
it("should respect limit parameter", async () => {
|
|
38
|
+
const mockResponse = [{ id: 1 }];
|
|
39
|
+
fetch.mockImplementation(() => Promise.resolve({
|
|
40
|
+
status: 200,
|
|
41
|
+
json: () => Promise.resolve(mockResponse),
|
|
42
|
+
}));
|
|
43
|
+
await (0, search_city_part_1.searchCityPart)("Praha", 5);
|
|
44
|
+
expect(fetch).toHaveBeenCalledWith(`${config_1.smartAddressUrl}/v2/city-part/search?term=Praha&limit=5`);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Location } from "./types";
|
|
2
|
+
type Params = {
|
|
3
|
+
level: number;
|
|
4
|
+
limit?: number;
|
|
5
|
+
zip?: number;
|
|
6
|
+
address?: string;
|
|
7
|
+
getLabel?: (address: Location) => string;
|
|
8
|
+
};
|
|
9
|
+
export declare const createAddressLoader: (params: Params) => (term: string) => Promise<import("./types").Option[]>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAddressLoader = void 0;
|
|
4
|
+
const create_loader_1 = require("../common/create-loader");
|
|
5
|
+
const load_address_options_1 = require("./load-address-options");
|
|
6
|
+
const createAddressLoader = (params) => (0, create_loader_1.createLoaderGeneral)(load_address_options_1.loadAddressOptions, params);
|
|
7
|
+
exports.createAddressLoader = createAddressLoader;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createZipLoader = void 0;
|
|
4
|
+
const create_loader_1 = require("../common/create-loader");
|
|
5
|
+
const load_zip_options_1 = require("./load-zip-options");
|
|
6
|
+
const createZipLoader = (params) => (0, create_loader_1.createLoaderGeneral)(load_zip_options_1.loadZipOptions, params);
|
|
7
|
+
exports.createZipLoader = createZipLoader;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAddressExtended = void 0;
|
|
4
|
+
const get_address_extended_1 = require("../common/get-address-extended");
|
|
5
|
+
exports.getAddressExtended = (0, get_address_extended_1.getAddressExtendedGeneral)("/v2/address/");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getAddress: (id: number) => Promise<import("./types").Location>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBuildingAddresses = void 0;
|
|
4
|
+
const config_1 = require("../config");
|
|
5
|
+
const getBuildingAddresses = async (id) => {
|
|
6
|
+
const response = await fetch(`${config_1.smartAddressUrl}/v2/address/${id}/building-addresses`);
|
|
7
|
+
return await response.json();
|
|
8
|
+
};
|
|
9
|
+
exports.getBuildingAddresses = getBuildingAddresses;
|
package/v2/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./create-address-loader";
|
|
2
|
+
export * from "./create-zip-loader";
|
|
3
|
+
export * from "./get-address";
|
|
4
|
+
export * from "./get-address-extended";
|
|
5
|
+
export * from "./get-building-addresses";
|
|
6
|
+
export * from "./load-address-options";
|
|
7
|
+
export * from "./load-zip-options";
|
|
8
|
+
export * from "./search";
|
|
9
|
+
export * from "./search-city-part";
|
|
10
|
+
export * from "./search-zip";
|
|
11
|
+
export * from "./types";
|
package/v2/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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("./create-address-loader"), exports);
|
|
18
|
+
__exportStar(require("./create-zip-loader"), exports);
|
|
19
|
+
__exportStar(require("./get-address"), exports);
|
|
20
|
+
__exportStar(require("./get-address-extended"), exports);
|
|
21
|
+
__exportStar(require("./get-building-addresses"), exports);
|
|
22
|
+
__exportStar(require("./load-address-options"), exports);
|
|
23
|
+
__exportStar(require("./load-zip-options"), exports);
|
|
24
|
+
__exportStar(require("./search"), exports);
|
|
25
|
+
__exportStar(require("./search-city-part"), exports);
|
|
26
|
+
__exportStar(require("./search-zip"), exports);
|
|
27
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadAddressOptions = void 0;
|
|
4
|
+
const load_address_options_1 = require("../common/load-address-options");
|
|
5
|
+
exports.loadAddressOptions = (0, load_address_options_1.loadAddressOptionsGeneral)("/v2/search");
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadZipOptions = void 0;
|
|
4
|
+
const load_zip_options_1 = require("../common/load-zip-options");
|
|
5
|
+
exports.loadZipOptions = (0, load_zip_options_1.loadZipOptionsGeneral)("/v2/zip/search");
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.searchCityPart = void 0;
|
|
4
|
+
const config_1 = require("../config");
|
|
5
|
+
const searchCityPart = async (term, limit) => {
|
|
6
|
+
if (term.length === 0) {
|
|
7
|
+
return [];
|
|
8
|
+
}
|
|
9
|
+
const params = new URLSearchParams({
|
|
10
|
+
term,
|
|
11
|
+
});
|
|
12
|
+
if (limit) {
|
|
13
|
+
params.append("limit", limit.toString());
|
|
14
|
+
}
|
|
15
|
+
const response = await fetch(`${config_1.smartAddressUrl}/v2/city-part/search?${params.toString()}`);
|
|
16
|
+
return (await response.json());
|
|
17
|
+
};
|
|
18
|
+
exports.searchCityPart = searchCityPart;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const searchZip: (term: string, limit?: number) => Promise<import("./types").Location[]>;
|
package/v2/search-zip.js
ADDED
package/v2/search.d.ts
ADDED
package/v2/search.js
ADDED
package/v2/types.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export * from "../common/types";
|
|
2
|
+
import { BuildingType, BuildingUsageType, ConstructionType, ElevatorType, GasConnectionType, HeatingType, Location, ObjectType, ObjectTypeBasic, SewerConnectionType, WaterConnectionType } from "../common/types";
|
|
3
|
+
export type AddressExtendedBasicResponse = Location;
|
|
4
|
+
export type AddressExtendedAdministrativeResponse = {
|
|
5
|
+
id: number;
|
|
6
|
+
isknBudovaId: string | null;
|
|
7
|
+
stavebniObjektKod: string | null;
|
|
8
|
+
parcelaKod: string | null;
|
|
9
|
+
zpusobVyuzitiObjektu: BuildingUsageType | null;
|
|
10
|
+
objectType: ObjectType | null;
|
|
11
|
+
objectTypeBasic: ObjectTypeBasic | null;
|
|
12
|
+
};
|
|
13
|
+
export type AddressExtendedBuildingResponse = {
|
|
14
|
+
id: number;
|
|
15
|
+
typBudovy: BuildingType | null;
|
|
16
|
+
druhKonstrukce: ConstructionType | null;
|
|
17
|
+
pocetBytu: number | null;
|
|
18
|
+
pocetPodlazi: number | null;
|
|
19
|
+
pripojeniKanalizace: SewerConnectionType | null;
|
|
20
|
+
pripojeniVodovod: WaterConnectionType | null;
|
|
21
|
+
vybaveniVytahem: ElevatorType | null;
|
|
22
|
+
zastavenaPlocha: number | null;
|
|
23
|
+
obestavenyProstor: number | null;
|
|
24
|
+
podlahovaPlocha: number | null;
|
|
25
|
+
objectSize: string | null;
|
|
26
|
+
};
|
|
27
|
+
export type AddressExtendedEnergyResponse = {
|
|
28
|
+
id: number;
|
|
29
|
+
distributorElektrinyKod: string | null;
|
|
30
|
+
distributorElektrinyId: number | null;
|
|
31
|
+
distributorPlynuKod: string | null;
|
|
32
|
+
distributorPlynuId: number | null;
|
|
33
|
+
pripojeniPlyn: GasConnectionType | null;
|
|
34
|
+
zpusobVytapeni: HeatingType | null;
|
|
35
|
+
};
|
|
36
|
+
export type AddressExtended = {
|
|
37
|
+
zakladniAdresa: AddressExtendedBasicResponse;
|
|
38
|
+
administrativniUdaje: AddressExtendedAdministrativeResponse;
|
|
39
|
+
udajeBudovy: AddressExtendedBuildingResponse;
|
|
40
|
+
udajeEnergii: AddressExtendedEnergyResponse;
|
|
41
|
+
};
|
|
42
|
+
export type CityPart = {
|
|
43
|
+
id: number;
|
|
44
|
+
name: string;
|
|
45
|
+
obecKod: number;
|
|
46
|
+
obecNazev: string;
|
|
47
|
+
zips: string[];
|
|
48
|
+
};
|
package/v2/types.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("../common/types"), exports);
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Location, Option } from "./types";
|
|
2
|
-
type Params = {
|
|
3
|
-
level: number;
|
|
4
|
-
limit?: number;
|
|
5
|
-
zip?: number;
|
|
6
|
-
getLabel?: (address: Location) => string;
|
|
7
|
-
};
|
|
8
|
-
export declare const createAddressLoader: (params: Params) => ((term: string) => Promise<Option[]>);
|
|
9
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createAddressLoader = void 0;
|
|
4
|
-
const load_address_options_1 = require("./load-address-options");
|
|
5
|
-
const createAddressLoader = (params) => {
|
|
6
|
-
return (term) => (0, load_address_options_1.loadAddressOptions)({
|
|
7
|
-
term,
|
|
8
|
-
level: params.level,
|
|
9
|
-
limit: params.limit,
|
|
10
|
-
zip: params.zip,
|
|
11
|
-
getLabel: params.getLabel,
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
exports.createAddressLoader = createAddressLoader;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAddressExtended = void 0;
|
|
4
|
-
const config_1 = require("../config");
|
|
5
|
-
const getAddressExtended = async (id) => {
|
|
6
|
-
const response = await fetch(config_1.smartAddressUrl + "/v1/address/" + id + "/extended");
|
|
7
|
-
return JSON.parse(await response.text());
|
|
8
|
-
};
|
|
9
|
-
exports.getAddressExtended = getAddressExtended;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAddress = void 0;
|
|
4
|
-
const config_1 = require("../config");
|
|
5
|
-
const getAddress = async (id) => {
|
|
6
|
-
const response = await fetch(config_1.smartAddressUrl + "/v1/address/" + id);
|
|
7
|
-
return JSON.parse(await response.text());
|
|
8
|
-
};
|
|
9
|
-
exports.getAddress = getAddress;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadAddressOptions = void 0;
|
|
4
|
-
const search_1 = require("./search");
|
|
5
|
-
const loadAddressOptions = 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) => `${address.ulice}, ${address.obec}`);
|
|
9
|
-
if (params.term.length === 0) {
|
|
10
|
-
return [];
|
|
11
|
-
}
|
|
12
|
-
const response = await (0, search_1.search)({ term: params.term, level: params.level, limit, zip: params.zip });
|
|
13
|
-
return response.map((a) => ({ id: a.id, label: getLabel(a) }));
|
|
14
|
-
};
|
|
15
|
-
exports.loadAddressOptions = loadAddressOptions;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.searchZip = void 0;
|
|
4
|
-
const config_1 = require("../config");
|
|
5
|
-
const regexp = /^([0-9]{1,5})$/;
|
|
6
|
-
const searchZip = async (term) => {
|
|
7
|
-
if (term.length === 0 || !regexp.test(term)) {
|
|
8
|
-
return [];
|
|
9
|
-
}
|
|
10
|
-
const response = await fetch(config_1.smartAddressUrl + "/v1/zip/search?" + new URLSearchParams({ term: term }));
|
|
11
|
-
if (response.status !== 200) {
|
|
12
|
-
return [];
|
|
13
|
-
}
|
|
14
|
-
return JSON.parse(await response.text());
|
|
15
|
-
};
|
|
16
|
-
exports.searchZip = searchZip;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const config_1 = require("../config");
|
|
4
|
-
const search_1 = require("./search");
|
|
5
|
-
global.fetch = jest.fn();
|
|
6
|
-
describe("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 and return data", async () => {
|
|
16
|
-
const mockResponse = [{ id: 1, name: "Test Location" }];
|
|
17
|
-
fetch.mockResolvedValue({
|
|
18
|
-
text: jest.fn().mockResolvedValue(JSON.stringify(mockResponse)),
|
|
19
|
-
});
|
|
20
|
-
const result = await (0, search_1.search)({ term: "test", level: 2, limit: 5, zip: 12345 });
|
|
21
|
-
expect(fetch).toHaveBeenCalledWith(`${config_1.smartAddressUrl}/v1/search?term=test&level=2&limit=5&zip=12345`);
|
|
22
|
-
expect(result).toEqual(mockResponse);
|
|
23
|
-
});
|
|
24
|
-
it("should call fetch without zip when zip is not provided", async () => {
|
|
25
|
-
const mockResponse = [{ id: 2, name: "Another Location" }];
|
|
26
|
-
fetch.mockResolvedValue({
|
|
27
|
-
text: jest.fn().mockResolvedValue(JSON.stringify(mockResponse)),
|
|
28
|
-
});
|
|
29
|
-
const result = await (0, search_1.search)({ term: "another test", level: 1 });
|
|
30
|
-
expect(fetch).toHaveBeenCalledWith(`${config_1.smartAddressUrl}/v1/search?term=another+test&level=1&limit=10`);
|
|
31
|
-
expect(result).toEqual(mockResponse);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|