@uxf/smart-address 11.11.2 → 11.46.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/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
- "name": "@uxf/smart-address",
3
- "version": "11.11.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
- }
2
+ "name": "@uxf/smart-address",
3
+ "version": "11.46.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
+ }
@@ -5,5 +5,5 @@ type Params = {
5
5
  zip?: number;
6
6
  getLabel?: (address: Location) => string;
7
7
  };
8
- export declare const createAddressLoader: (params: Params) => (term: string) => Promise<Option[]>;
8
+ export declare const createAddressLoader: (params: Params) => ((term: string) => Promise<Option[]>);
9
9
  export {};
@@ -2,5 +2,5 @@ import { Location, Option } from "./types";
2
2
  type Params = {
3
3
  getLabel?: (address: Location) => string;
4
4
  };
5
- export declare const createZipLoader: (params: Params) => (term: string) => Promise<Option[]>;
5
+ export declare const createZipLoader: (params: Params) => ((term: string) => Promise<Option[]>);
6
6
  export {};
@@ -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;
package/v1/index.d.ts CHANGED
@@ -2,13 +2,13 @@ export type { BuildingType, BuildingUsageType, ConstructionType, ElevatorType, G
2
2
  export declare const SmartAddress: {
3
3
  createAddressLoader: (params: {
4
4
  level: number;
5
- limit?: number | undefined;
6
- zip?: number | undefined;
7
- getLabel?: ((address: import("./types").Location) => string) | undefined;
8
- }) => (term: string) => Promise<import("./types").Option[]>;
5
+ limit?: number;
6
+ zip?: number;
7
+ getLabel?: (address: import("./types").Location) => string;
8
+ }) => ((term: string) => Promise<import("./types").Option[]>);
9
9
  createZipLoader: (params: {
10
- getLabel?: ((address: import("./types").Location) => string) | undefined;
11
- }) => (term: string) => Promise<import("./types").Option[]>;
10
+ getLabel?: (address: import("./types").Location) => string;
11
+ }) => ((term: string) => Promise<import("./types").Option[]>);
12
12
  getAddress: (id: number) => Promise<import("./types").Location>;
13
13
  getAddressExtended: (id: number) => Promise<import("./types").LocationExtended>;
14
14
  getCity: (id: number) => Promise<import("./types").Location>;
@@ -19,19 +19,19 @@ export declare const SmartAddress: {
19
19
  loadAddressOptions: (params: {
20
20
  term: string;
21
21
  level: number;
22
- limit?: number | undefined;
23
- zip?: number | undefined;
24
- getLabel?: ((address: import("./types").Location) => string) | undefined;
22
+ limit?: number;
23
+ zip?: number;
24
+ getLabel?: (address: import("./types").Location) => string;
25
25
  }) => Promise<import("./types").Option[]>;
26
26
  loadZipOptions: (params: {
27
27
  term: string;
28
- getLabel?: ((address: import("./types").Location) => string) | undefined;
28
+ getLabel?: (address: import("./types").Location) => string;
29
29
  }) => Promise<import("./types").Option[]>;
30
30
  search: (props: {
31
31
  term: string;
32
32
  level: number;
33
- limit?: number | undefined;
34
- zip?: number | undefined;
33
+ limit?: number;
34
+ zip?: number;
35
35
  }) => Promise<import("./types").Location[]>;
36
36
  searchZip: (term: string) => Promise<import("./types").Location[]>;
37
37
  };
@@ -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
+ });
package/v1/types.d.ts CHANGED
@@ -1,3 +1,25 @@
1
+ type BasicType = {
2
+ id: number;
3
+ nazev: string | null;
4
+ };
5
+ type Type = {
6
+ id: number;
7
+ nazev: string | null;
8
+ popis: string | null;
9
+ zkracenyNazev: string | null;
10
+ zacatekPlatnosti: string | null;
11
+ konecPlatnosti: string | null;
12
+ };
13
+ export type ObjectType = BasicType;
14
+ export type ObjectTypeBasic = BasicType;
15
+ export type BuildingType = Type;
16
+ export type ConstructionType = Type;
17
+ export type SewerConnectionType = Type;
18
+ export type GasConnectionType = Type;
19
+ export type WaterConnectionType = Type;
20
+ export type ElevatorType = Type;
21
+ export type HeatingType = Type;
22
+ export type BuildingUsageType = Type;
1
23
  export type Option = {
2
24
  id: number;
3
25
  label: string;
@@ -64,26 +86,4 @@ export type LocationExtended = {
64
86
  objectSize: string | null;
65
87
  objectSizeSquare: number | null;
66
88
  };
67
- type BasicType = {
68
- id: number;
69
- nazev: string | null;
70
- };
71
- type Type = {
72
- id: number;
73
- nazev: string | null;
74
- popis: string | null;
75
- zkracenyNazev: string | null;
76
- zacatekPlatnosti: string | null;
77
- konecPlatnosti: string | null;
78
- };
79
- export type ObjectType = BasicType;
80
- export type ObjectTypeBasic = BasicType;
81
- export type BuildingType = Type;
82
- export type ConstructionType = Type;
83
- export type SewerConnectionType = Type;
84
- export type GasConnectionType = Type;
85
- export type WaterConnectionType = Type;
86
- export type ElevatorType = Type;
87
- export type HeatingType = Type;
88
- export type BuildingUsageType = Type;
89
89
  export {};
package/v1/v1.stories.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.Default = void 0;
26
+ exports.Default = Default;
27
27
  const button_1 = require("@uxf/ui/button");
28
28
  const combobox_1 = require("@uxf/ui/combobox");
29
29
  const text_input_1 = require("@uxf/ui/text-input");
@@ -69,9 +69,9 @@ function Default() {
69
69
  }
70
70
  };
71
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", value: addressValue, onChange: setAddressValue, loadOptions: index_1.SmartAddress.createAddressLoader({ level: 1 }), name: "combobox" }),
73
- react_1.default.createElement(combobox_1.Combobox, { label: "Zip combobox", value: zipValue, onChange: setZipValue, loadOptions: index_1.SmartAddress.createZipLoader({}), name: "combobox-smart-address" }),
74
- react_1.default.createElement(text_input_1.TextInput, { type: "text", value: textValue, onChange: setTextValue, label: "Text input", name: "text-input" }),
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
75
  react_1.default.createElement("div", { className: "grid grid-cols-2 gap-4" },
76
76
  react_1.default.createElement(button_1.Button, { onClick: load("load-address") }, "Load Address Options"),
77
77
  react_1.default.createElement(button_1.Button, { onClick: load("load-zip") }, "Load Zip Options"),
@@ -84,4 +84,3 @@ function Default() {
84
84
  react_1.default.createElement(button_1.Button, { onClick: load("get-street") }, "Get Street")),
85
85
  react_1.default.createElement("pre", { className: "bg-gray-100 p-2 text-sm" }, JSON.stringify(content, null, 4))));
86
86
  }
87
- exports.Default = Default;