@uxf/smart-address 11.32.0 → 11.80.2

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.
Files changed (43) hide show
  1. package/package.json +13 -13
  2. package/{v1 → smart-address/v1}/get-address-extended.js +2 -1
  3. package/smart-address/v1/load-address-options.test.d.ts +1 -0
  4. package/smart-address/v1/load-address-options.test.js +127 -0
  5. package/smart-address/v1/load-zip-options.test.d.ts +1 -0
  6. package/smart-address/v1/load-zip-options.test.js +34 -0
  7. package/smart-address/v1/search-zip.test.d.ts +1 -0
  8. package/smart-address/v1/search-zip.test.js +40 -0
  9. package/smart-address/v1/search.test.d.ts +1 -0
  10. package/smart-address/v1/search.test.js +33 -0
  11. package/v1/v1.stories.d.ts +0 -6
  12. package/v1/v1.stories.js +0 -86
  13. /package/{config.d.ts → smart-address/config.d.ts} +0 -0
  14. /package/{config.js → smart-address/config.js} +0 -0
  15. /package/{v1 → smart-address/v1}/create-address-loader.d.ts +0 -0
  16. /package/{v1 → smart-address/v1}/create-address-loader.js +0 -0
  17. /package/{v1 → smart-address/v1}/create-zip-loader.d.ts +0 -0
  18. /package/{v1 → smart-address/v1}/create-zip-loader.js +0 -0
  19. /package/{v1 → smart-address/v1}/get-address-extended.d.ts +0 -0
  20. /package/{v1 → smart-address/v1}/get-address.d.ts +0 -0
  21. /package/{v1 → smart-address/v1}/get-address.js +0 -0
  22. /package/{v1 → smart-address/v1}/get-city-part.d.ts +0 -0
  23. /package/{v1 → smart-address/v1}/get-city-part.js +0 -0
  24. /package/{v1 → smart-address/v1}/get-city.d.ts +0 -0
  25. /package/{v1 → smart-address/v1}/get-city.js +0 -0
  26. /package/{v1 → smart-address/v1}/get-momc.d.ts +0 -0
  27. /package/{v1 → smart-address/v1}/get-momc.js +0 -0
  28. /package/{v1 → smart-address/v1}/get-mop.d.ts +0 -0
  29. /package/{v1 → smart-address/v1}/get-mop.js +0 -0
  30. /package/{v1 → smart-address/v1}/get-street.d.ts +0 -0
  31. /package/{v1 → smart-address/v1}/get-street.js +0 -0
  32. /package/{v1 → smart-address/v1}/index.d.ts +0 -0
  33. /package/{v1 → smart-address/v1}/index.js +0 -0
  34. /package/{v1 → smart-address/v1}/load-address-options.d.ts +0 -0
  35. /package/{v1 → smart-address/v1}/load-address-options.js +0 -0
  36. /package/{v1 → smart-address/v1}/load-zip-options.d.ts +0 -0
  37. /package/{v1 → smart-address/v1}/load-zip-options.js +0 -0
  38. /package/{v1 → smart-address/v1}/search-zip.d.ts +0 -0
  39. /package/{v1 → smart-address/v1}/search-zip.js +0 -0
  40. /package/{v1 → smart-address/v1}/search.d.ts +0 -0
  41. /package/{v1 → smart-address/v1}/search.js +0 -0
  42. /package/{v1 → smart-address/v1}/types.d.ts +0 -0
  43. /package/{v1 → smart-address/v1}/types.js +0 -0
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
- "name": "@uxf/smart-address",
3
- "version": "11.32.0",
4
- "description": "",
5
- "publishConfig": {
6
- "access": "public"
7
- },
8
- "scripts": {
9
- "build": "tsc -P tsconfig.json",
10
- "typecheck": "../../node_modules/.bin/tsc --noEmit --skipLibCheck"
11
- },
12
- "author": "UX Fans s.r.o",
13
- "license": "MIT"
14
- }
2
+ "name": "@uxf/smart-address",
3
+ "version": "11.80.2",
4
+ "description": "",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "scripts": {
9
+ "build": "tsc -P tsconfig.json",
10
+ "typecheck": "../../node_modules/.bin/tsc --noEmit --skipLibCheck"
11
+ },
12
+ "author": "UX Fans s.r.o",
13
+ "license": "MIT"
14
+ }
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAddressExtended = void 0;
4
+ const config_1 = require("../config");
4
5
  const getAddressExtended = async (id) => {
5
- const response = await fetch("https://www.smart-address.cz/api/v1/address/" + id + "/extended");
6
+ const response = await fetch(config_1.smartAddressUrl + "/v1/address/" + id + "/extended");
6
7
  return JSON.parse(await response.text());
7
8
  };
8
9
  exports.getAddressExtended = getAddressExtended;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const load_address_options_1 = require("./load-address-options");
4
+ const search_1 = require("./search");
5
+ jest.mock("./search");
6
+ describe("loadAddressOptions", () => {
7
+ beforeEach(() => {
8
+ jest.clearAllMocks();
9
+ });
10
+ it("should return an empty array if term is empty", async () => {
11
+ const options = await (0, load_address_options_1.loadAddressOptions)({ term: "", level: 1 });
12
+ expect(options).toEqual([]);
13
+ });
14
+ it("should call search with correct parameters", async () => {
15
+ const term = "Prague";
16
+ const level = 1;
17
+ const mockResponse = [
18
+ {
19
+ id: 1,
20
+ obecKod: 123,
21
+ obecNazev: null,
22
+ obec: null,
23
+ momcKod: null,
24
+ momcNazev: null,
25
+ mopKod: null,
26
+ mopNazev: null,
27
+ castObceKod: null,
28
+ castObceNazev: null,
29
+ uliceKod: null,
30
+ uliceNazev: null,
31
+ ulice: null,
32
+ typSo: null,
33
+ cisloDomovni: null,
34
+ cisloOrientacni: null,
35
+ cisloOrientacniZnak: null,
36
+ psc: null,
37
+ search: "",
38
+ level: 1,
39
+ gps: { latitude: "50.0755", longitude: "14.4378" },
40
+ platiOd: "2024-01-01",
41
+ aktualizace: "2024-10-01",
42
+ okresKod: 456,
43
+ okresNazev: "Prague",
44
+ krajKod: 789,
45
+ krajNazev: "Czech Republic",
46
+ },
47
+ ];
48
+ search_1.search.mockResolvedValue(mockResponse);
49
+ await (0, load_address_options_1.loadAddressOptions)({ term, level });
50
+ expect(search_1.search).toHaveBeenCalledWith({ term, level, limit: 10, zip: undefined });
51
+ });
52
+ const term = "Prague";
53
+ const level = 1;
54
+ it("should return address options with correct labels", async () => {
55
+ const mockResponse = [
56
+ {
57
+ id: 1,
58
+ obecKod: 123,
59
+ obecNazev: null,
60
+ obec: null,
61
+ momcKod: null,
62
+ momcNazev: null,
63
+ mopKod: null,
64
+ mopNazev: null,
65
+ castObceKod: null,
66
+ castObceNazev: null,
67
+ uliceKod: null,
68
+ uliceNazev: null,
69
+ ulice: "Main St",
70
+ typSo: null,
71
+ cisloDomovni: null,
72
+ cisloOrientacni: null,
73
+ cisloOrientacniZnak: null,
74
+ psc: null,
75
+ search: "",
76
+ level: 1,
77
+ gps: { latitude: "50.0755", longitude: "14.4378" },
78
+ platiOd: "2024-01-01",
79
+ aktualizace: "2024-10-01",
80
+ okresKod: 456,
81
+ okresNazev: "Prague",
82
+ krajKod: 789,
83
+ krajNazev: "Czech Republic",
84
+ },
85
+ ];
86
+ search_1.search.mockResolvedValue(mockResponse);
87
+ const options = await (0, load_address_options_1.loadAddressOptions)({ term, level });
88
+ expect(options).toEqual([{ id: 1, label: "Main St, null" }]);
89
+ });
90
+ it("should use custom getLabel function if provided", async () => {
91
+ const mockResponse = [
92
+ {
93
+ id: 1,
94
+ obecKod: 123,
95
+ obecNazev: null,
96
+ obec: null,
97
+ momcKod: null,
98
+ momcNazev: null,
99
+ mopKod: null,
100
+ mopNazev: null,
101
+ castObceKod: null,
102
+ castObceNazev: null,
103
+ uliceKod: null,
104
+ uliceNazev: null,
105
+ ulice: "Main St",
106
+ typSo: null,
107
+ cisloDomovni: null,
108
+ cisloOrientacni: null,
109
+ cisloOrientacniZnak: null,
110
+ psc: null,
111
+ search: "",
112
+ level: 1,
113
+ gps: { latitude: "50.0755", longitude: "14.4378" },
114
+ platiOd: "2024-01-01",
115
+ aktualizace: "2024-10-01",
116
+ okresKod: 456,
117
+ okresNazev: "Prague",
118
+ krajKod: 789,
119
+ krajNazev: "Czech Republic",
120
+ },
121
+ ];
122
+ search_1.search.mockResolvedValue(mockResponse);
123
+ const customGetLabel = (address) => `${address.obec} - ${address.ulice}`;
124
+ const options = await (0, load_address_options_1.loadAddressOptions)({ term, level, getLabel: customGetLabel });
125
+ expect(options).toEqual([{ id: 1, label: "null - Main St" }]);
126
+ });
127
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const load_zip_options_1 = require("./load-zip-options");
4
+ const search_zip_1 = require("./search-zip");
5
+ jest.mock("./search-zip");
6
+ describe("loadZipOptions", () => {
7
+ it("should return empty array when term is empty", async () => {
8
+ const result = await (0, load_zip_options_1.loadZipOptions)({ term: "" });
9
+ expect(result).toEqual([]);
10
+ });
11
+ it("should return formatted options with default label when term is provided", async () => {
12
+ search_zip_1.searchZip.mockResolvedValueOnce([
13
+ { id: 1, psc: 12345 },
14
+ { id: 2, psc: 54321 },
15
+ ]);
16
+ const result = await (0, load_zip_options_1.loadZipOptions)({ term: "123" });
17
+ expect(result).toEqual([
18
+ { id: 1, label: "12345" },
19
+ { id: 2, label: "54321" },
20
+ ]);
21
+ });
22
+ it("should return formatted options with custom label when getLabel is provided", async () => {
23
+ search_zip_1.searchZip.mockResolvedValueOnce([
24
+ { id: 1, psc: 12345 },
25
+ { id: 2, psc: 54321 },
26
+ ]);
27
+ const customLabel = (address) => `Zip: ${address.psc}`;
28
+ const result = await (0, load_zip_options_1.loadZipOptions)({ term: "123", getLabel: customLabel });
29
+ expect(result).toEqual([
30
+ { id: 1, label: "Zip: 12345" },
31
+ { id: 2, label: "Zip: 54321" },
32
+ ]);
33
+ });
34
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const config_1 = require("../config");
4
+ const search_zip_1 = require("./search-zip");
5
+ jest.mock("../config", () => ({
6
+ smartAddressUrl: "http://example.com",
7
+ }));
8
+ describe("searchZip", () => {
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_zip_1.searchZip)("");
17
+ expect(result).toEqual([]);
18
+ });
19
+ it("should return an empty array for non-numeric input", async () => {
20
+ const result = await (0, search_zip_1.searchZip)("abc");
21
+ expect(result).toEqual([]);
22
+ });
23
+ it("should return an empty array for invalid zip code", async () => {
24
+ const result = await (0, search_zip_1.searchZip)("123456");
25
+ expect(result).toEqual([]);
26
+ });
27
+ it("should return an array of locations for valid zip code", async () => {
28
+ const mockResponse = [
29
+ { id: 1, name: "Location 1" },
30
+ { id: 2, name: "Location 2" },
31
+ ];
32
+ fetch.mockImplementation(() => Promise.resolve({
33
+ status: 200,
34
+ text: () => Promise.resolve(JSON.stringify(mockResponse)),
35
+ }));
36
+ const result = await (0, search_zip_1.searchZip)("12345");
37
+ expect(result).toEqual(mockResponse);
38
+ expect(fetch).toHaveBeenCalledWith(`${config_1.smartAddressUrl}/v1/zip/search?term=12345`);
39
+ });
40
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
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
+ });
@@ -1,6 +0,0 @@
1
- import React from "react";
2
- declare const _default: {
3
- title: string;
4
- };
5
- export default _default;
6
- export declare function Default(): React.JSX.Element;
package/v1/v1.stories.js DELETED
@@ -1,86 +0,0 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.Default = Default;
27
- const button_1 = require("@uxf/ui/button");
28
- const combobox_1 = require("@uxf/ui/combobox");
29
- const text_input_1 = require("@uxf/ui/text-input");
30
- const react_1 = __importStar(require("react"));
31
- const index_1 = require("./index");
32
- exports.default = {
33
- title: "Smart address/v1",
34
- };
35
- function Default() {
36
- const [addressValue, setAddressValue] = (0, react_1.useState)(null);
37
- const [zipValue, setZipValue] = (0, react_1.useState)(null);
38
- const [textValue, setTextValue] = (0, react_1.useState)("");
39
- const [content, setContent] = (0, react_1.useState)([]);
40
- const load = (type) => async () => {
41
- switch (type) {
42
- case "load-address":
43
- setContent(await index_1.SmartAddress.loadAddressOptions({ term: textValue, level: 1 }));
44
- break;
45
- case "load-zip":
46
- setContent(await index_1.SmartAddress.loadZipOptions({ term: textValue }));
47
- break;
48
- case "get-address":
49
- setContent(await index_1.SmartAddress.getAddress(parseInt(textValue, 10)));
50
- break;
51
- case "get-address-extended":
52
- setContent(await index_1.SmartAddress.getAddressExtended(parseInt(textValue, 10)));
53
- break;
54
- case "get-city":
55
- setContent(await index_1.SmartAddress.getCity(parseInt(textValue, 10)));
56
- break;
57
- case "get-city-part":
58
- setContent(await index_1.SmartAddress.getCityPart(parseInt(textValue, 10)));
59
- break;
60
- case "get-momc":
61
- setContent(await index_1.SmartAddress.getMomc(parseInt(textValue, 10)));
62
- break;
63
- case "get-mop":
64
- setContent(await index_1.SmartAddress.getMop(parseInt(textValue, 10)));
65
- break;
66
- case "get-street":
67
- setContent(await index_1.SmartAddress.getStreet(parseInt(textValue, 10)));
68
- break;
69
- }
70
- };
71
- return (react_1.default.createElement("div", { className: "mx-auto max-w-3xl space-y-4 rounded border bg-white p-4" },
72
- react_1.default.createElement(combobox_1.Combobox, { label: "Address combobox", loadOptions: index_1.SmartAddress.createAddressLoader({ level: 1 }), name: "combobox", onChange: setAddressValue, value: addressValue }),
73
- react_1.default.createElement(combobox_1.Combobox, { label: "Zip combobox", loadOptions: index_1.SmartAddress.createZipLoader({}), name: "combobox-smart-address", onChange: setZipValue, value: zipValue }),
74
- react_1.default.createElement(text_input_1.TextInput, { label: "Text input", name: "text-input", onChange: setTextValue, type: "text", value: textValue }),
75
- react_1.default.createElement("div", { className: "grid grid-cols-2 gap-4" },
76
- react_1.default.createElement(button_1.Button, { onClick: load("load-address") }, "Load Address Options"),
77
- react_1.default.createElement(button_1.Button, { onClick: load("load-zip") }, "Load Zip Options"),
78
- react_1.default.createElement(button_1.Button, { onClick: load("get-address") }, "Get Address"),
79
- react_1.default.createElement(button_1.Button, { onClick: load("get-address-extended") }, "Get Address Extended"),
80
- react_1.default.createElement(button_1.Button, { onClick: load("get-city") }, "Get City"),
81
- react_1.default.createElement(button_1.Button, { onClick: load("get-city-part") }, "Get City Part"),
82
- react_1.default.createElement(button_1.Button, { onClick: load("get-momc") }, "Get Momc"),
83
- react_1.default.createElement(button_1.Button, { onClick: load("get-mop") }, "Get Mop"),
84
- react_1.default.createElement(button_1.Button, { onClick: load("get-street") }, "Get Street")),
85
- react_1.default.createElement("pre", { className: "bg-gray-100 p-2 text-sm" }, JSON.stringify(content, null, 4))));
86
- }
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
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