@uxf/smart-address 1.0.0 → 10.0.0-beta.80

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 CHANGED
@@ -1,47 +1,7 @@
1
1
  # @uxf/smart-address
2
2
 
3
- ## Použití balíčku
3
+ ## How to install
4
4
 
5
- Environment proměnné:
6
-
7
- - `SMART_ADDRESS_URL` (default: https://smart-address.cz/api/v1)
8
- - `SMART_ADDRESS_TOKEN` (required)
9
-
10
- ```tsx
11
- import { SmartAddress } from "@uxf/smart-address";
12
-
13
- const addresses = await SmartAddress.search({ term: "", level: 3, limit: 20});
14
- const address = await SmartAddress.get(/** smart address id */);
15
- const extendedAddress = await SmartAddress.getExtended(/** smart address id */);
16
- ```
17
-
18
- ## Jak vyvíjet?
19
5
  ```bash
20
- git clone git@gitlab.com:uxf-npm/smart-address.git
21
-
22
- cd ./smart-address
23
-
24
- npm install
25
- ```
26
-
27
- ## Spuštění examplu:
28
-
29
- ```bash
30
- npm run dev
31
- ```
32
-
33
- ## Vydání balíčku:
34
-
35
- Balíček se vydá po mergi do `master` branche.
36
-
37
- K publikování nových verzí do npm je opužit balíček [semantic-release](https://github.com/semantic-release/semantic-release) .
38
-
39
- ### Jak má vypadat commit message?
40
-
41
- https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines
42
-
43
- | Commit message | Release type |
44
- |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------|
45
- | `fix(pencil): stop graphite breaking when too much pressure applied` | Patch Release |
46
- | `feat(pencil): add 'graphiteWidth' option` | ~~Minor~~ Feature Release |
47
- | `perf(pencil): remove graphiteWidth option`<br><br>`BREAKING CHANGE: The graphiteWidth option has been removed.`<br>`The default graphite width of 10mm is always used for performance reasons.` | ~~Major~~ Breaking Release |
6
+ yarn add @uxf/smart-address
7
+ ```
package/config.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const smartAddressUrl = "https://www.smart-address.cz/api";
package/config.js ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.smartAddressUrl = void 0;
4
+ exports.smartAddressUrl = "https://www.smart-address.cz/api";
package/package.json CHANGED
@@ -1,63 +1,14 @@
1
1
  {
2
2
  "name": "@uxf/smart-address",
3
- "version": "1.0.0",
4
- "description": "Smart Address client",
5
- "author": "UXFans <dev@uxf.cz>",
6
- "homepage": "https://gitlab.com/uxf-npm/cms#readme",
7
- "license": "ISC",
8
- "main": "index.js",
9
- "typings": "index.d.ts",
10
- "module": "index.js",
3
+ "version": "10.0.0-beta.80",
4
+ "description": "",
11
5
  "publishConfig": {
12
6
  "access": "public"
13
7
  },
14
- "repository": {
15
- "type": "git",
16
- "url": "git+https://gitlab.com/uxf-npm/smart-address.git"
17
- },
18
8
  "scripts": {
19
- "build": "tsc -P tsconfig.build.json",
20
- "clean": "rm -rf ./dist",
21
- "dev": "parcel example/index.html",
22
- "test": "npm run-script typecheck",
23
- "typecheck": "tsc --noEmit --skipLibCheck"
24
- },
25
- "bugs": {
26
- "url": "https://gitlab.com/uxf-npm/smart-address/issues"
27
- },
28
- "devDependencies": {
29
- "@types/node": "^14.11.8",
30
- "@types/react": "^16.9.51",
31
- "@types/react-dom": "^16.9.8",
32
- "axios": "^0.20.0",
33
- "parcel-bundler": "^1.12.4",
34
- "prettier": "^2.1.2",
35
- "react": "^16.9.0",
36
- "react-dom": "^16.9.0",
37
- "ts-jest": "^25.5.1",
38
- "ts-node": "^9.0.0",
39
- "typescript": "^3.8.3"
40
- },
41
- "peerDependencies": {
42
- "axios": "^0.20"
43
- },
44
- "release": {
45
- "plugins": [
46
- "@semantic-release/commit-analyzer",
47
- "@semantic-release/release-notes-generator",
48
- [
49
- "@semantic-release/gitlab",
50
- {
51
- "gitlabUrl": "https://gitlab.com/"
52
- }
53
- ],
54
- [
55
- "@semantic-release/npm",
56
- {
57
- "pkgRoot": "dist"
58
- }
59
- ]
60
- ]
9
+ "build": "tsc -P tsconfig.json",
10
+ "typecheck": "../../node_modules/.bin/tsc --noEmit --skipLibCheck"
61
11
  },
62
- "optionalDependencies": {}
63
- }
12
+ "author": "UX Fans s.r.o",
13
+ "license": "MIT"
14
+ }
@@ -0,0 +1,9 @@
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 {};
@@ -0,0 +1,14 @@
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;
@@ -0,0 +1,6 @@
1
+ import { Location, Option } from "./types";
2
+ type Params = {
3
+ getLabel?: (address: Location) => string;
4
+ };
5
+ export declare const createZipLoader: (params: Params) => (term: string) => Promise<Option[]>;
6
+ export {};
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createZipLoader = void 0;
4
+ const load_zip_options_1 = require("./load-zip-options");
5
+ const createZipLoader = (params) => {
6
+ return (term) => (0, load_zip_options_1.loadZipOptions)({
7
+ term,
8
+ getLabel: params.getLabel,
9
+ });
10
+ };
11
+ exports.createZipLoader = createZipLoader;
@@ -0,0 +1,2 @@
1
+ import { LocationExtended } from "./types";
2
+ export declare const getAddressExtended: (id: number) => Promise<LocationExtended>;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAddressExtended = void 0;
4
+ const getAddressExtended = async (id) => {
5
+ const response = await fetch("https://www.smart-address.cz/api/v1/address/" + id + "/extended");
6
+ return JSON.parse(await response.text());
7
+ };
8
+ exports.getAddressExtended = getAddressExtended;
@@ -0,0 +1,2 @@
1
+ import { Location } from "./types";
2
+ export declare const getAddress: (id: number) => Promise<Location>;
@@ -0,0 +1,9 @@
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;
@@ -0,0 +1,2 @@
1
+ import { Location } from "./types";
2
+ export declare const getCityPart: (id: number) => Promise<Location>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCityPart = void 0;
4
+ const config_1 = require("../config");
5
+ const getCityPart = async (id) => {
6
+ const response = await fetch(config_1.smartAddressUrl + "/v1/address/city-part/" + id);
7
+ return JSON.parse(await response.text());
8
+ };
9
+ exports.getCityPart = getCityPart;
@@ -0,0 +1,2 @@
1
+ import { Location } from "./types";
2
+ export declare const getCity: (id: number) => Promise<Location>;
package/v1/get-city.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCity = void 0;
4
+ const config_1 = require("../config");
5
+ const getCity = async (id) => {
6
+ const response = await fetch(config_1.smartAddressUrl + "/v1/address/city/" + id);
7
+ return JSON.parse(await response.text());
8
+ };
9
+ exports.getCity = getCity;
@@ -0,0 +1,2 @@
1
+ import { Location } from "./types";
2
+ export declare const getMomc: (id: number) => Promise<Location>;
package/v1/get-momc.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMomc = void 0;
4
+ const config_1 = require("../config");
5
+ const getMomc = async (id) => {
6
+ const response = await fetch(config_1.smartAddressUrl + "/v1/address/momc/" + id);
7
+ return JSON.parse(await response.text());
8
+ };
9
+ exports.getMomc = getMomc;
@@ -0,0 +1,2 @@
1
+ import { Location } from "./types";
2
+ export declare const getMop: (id: number) => Promise<Location>;
package/v1/get-mop.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMop = void 0;
4
+ const config_1 = require("../config");
5
+ const getMop = async (id) => {
6
+ const response = await fetch(config_1.smartAddressUrl + "/v1/address/mop/" + id);
7
+ return JSON.parse(await response.text());
8
+ };
9
+ exports.getMop = getMop;
@@ -0,0 +1,2 @@
1
+ import { Location } from "./types";
2
+ export declare const getStreet: (id: number) => Promise<Location>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getStreet = void 0;
4
+ const config_1 = require("../config");
5
+ const getStreet = async (id) => {
6
+ const response = await fetch(config_1.smartAddressUrl + "/v1/address/street/" + id);
7
+ return JSON.parse(await response.text());
8
+ };
9
+ exports.getStreet = getStreet;
package/v1/index.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ export type { BuildingType, BuildingUsageType, ConstructionType, ElevatorType, GasConnectionType, HeatingType, Location, LocationExtended, ObjectType, ObjectTypeBasic, Point, SewerConnectionType, WaterConnectionType, } from "./types";
2
+ export declare const SmartAddress: {
3
+ createAddressLoader: (params: {
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[]>;
9
+ createZipLoader: (params: {
10
+ getLabel?: ((address: import("./types").Location) => string) | undefined;
11
+ }) => (term: string) => Promise<import("./types").Option[]>;
12
+ getAddress: (id: number) => Promise<import("./types").Location>;
13
+ getAddressExtended: (id: number) => Promise<import("./types").LocationExtended>;
14
+ getCity: (id: number) => Promise<import("./types").Location>;
15
+ getCityPart: (id: number) => Promise<import("./types").Location>;
16
+ getMomc: (id: number) => Promise<import("./types").Location>;
17
+ getMop: (id: number) => Promise<import("./types").Location>;
18
+ getStreet: (id: number) => Promise<import("./types").Location>;
19
+ loadAddressOptions: (params: {
20
+ term: string;
21
+ level: number;
22
+ limit?: number | undefined;
23
+ zip?: number | undefined;
24
+ getLabel?: ((address: import("./types").Location) => string) | undefined;
25
+ }) => Promise<import("./types").Option[]>;
26
+ loadZipOptions: (params: {
27
+ term: string;
28
+ getLabel?: ((address: import("./types").Location) => string) | undefined;
29
+ }) => Promise<import("./types").Option[]>;
30
+ search: (props: {
31
+ term: string;
32
+ level: number;
33
+ limit?: number | undefined;
34
+ zip?: number | undefined;
35
+ }) => Promise<import("./types").Location[]>;
36
+ searchZip: (term: string) => Promise<import("./types").Location[]>;
37
+ };
package/v1/index.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SmartAddress = void 0;
4
+ const create_address_loader_1 = require("./create-address-loader");
5
+ const create_zip_loader_1 = require("./create-zip-loader");
6
+ const get_address_1 = require("./get-address");
7
+ const get_address_extended_1 = require("./get-address-extended");
8
+ const get_city_1 = require("./get-city");
9
+ const get_city_part_1 = require("./get-city-part");
10
+ const get_momc_1 = require("./get-momc");
11
+ const get_mop_1 = require("./get-mop");
12
+ const get_street_1 = require("./get-street");
13
+ const load_address_options_1 = require("./load-address-options");
14
+ const load_zip_options_1 = require("./load-zip-options");
15
+ const search_1 = require("./search");
16
+ const search_zip_1 = require("./search-zip");
17
+ exports.SmartAddress = {
18
+ createAddressLoader: create_address_loader_1.createAddressLoader,
19
+ createZipLoader: create_zip_loader_1.createZipLoader,
20
+ getAddress: get_address_1.getAddress,
21
+ getAddressExtended: get_address_extended_1.getAddressExtended,
22
+ getCity: get_city_1.getCity,
23
+ getCityPart: get_city_part_1.getCityPart,
24
+ getMomc: get_momc_1.getMomc,
25
+ getMop: get_mop_1.getMop,
26
+ getStreet: get_street_1.getStreet,
27
+ loadAddressOptions: load_address_options_1.loadAddressOptions,
28
+ loadZipOptions: load_zip_options_1.loadZipOptions,
29
+ search: search_1.search,
30
+ searchZip: search_zip_1.searchZip,
31
+ };
@@ -0,0 +1,10 @@
1
+ import { Location, Option } from "./types";
2
+ type Params = {
3
+ term: string;
4
+ level: number;
5
+ limit?: number;
6
+ zip?: number;
7
+ getLabel?: (address: Location) => string;
8
+ };
9
+ export declare const loadAddressOptions: (params: Params) => Promise<Option[]>;
10
+ export {};
@@ -0,0 +1,15 @@
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;
@@ -0,0 +1,7 @@
1
+ import { Location, Option } from "./types";
2
+ type Params = {
3
+ term: string;
4
+ getLabel?: (address: Location) => string;
5
+ };
6
+ export declare const loadZipOptions: (params: Params) => Promise<Option[]>;
7
+ export {};
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadZipOptions = void 0;
4
+ const search_zip_1 = require("./search-zip");
5
+ const loadZipOptions = async (params) => {
6
+ var _a;
7
+ const getLabel = (_a = params.getLabel) !== null && _a !== void 0 ? _a : ((address) => `${address.psc}`);
8
+ if (params.term.length === 0) {
9
+ return [];
10
+ }
11
+ const response = await (0, search_zip_1.searchZip)(params.term);
12
+ return response.map((a) => ({ id: a.id, label: getLabel(a) }));
13
+ };
14
+ exports.loadZipOptions = loadZipOptions;
@@ -0,0 +1,2 @@
1
+ import { Location } from "./types";
2
+ export declare const searchZip: (term: string) => Promise<Location[]>;
@@ -0,0 +1,16 @@
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;
package/v1/search.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { Location } from "./types";
2
+ type Props = {
3
+ term: string;
4
+ level: number;
5
+ limit?: number;
6
+ zip?: number;
7
+ };
8
+ export declare const search: (props: Props) => Promise<Location[]>;
9
+ export {};
package/v1/search.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.search = void 0;
4
+ const config_1 = require("../config");
5
+ const search = async (props) => {
6
+ var _a;
7
+ const limit = (_a = props.limit) !== null && _a !== void 0 ? _a : 10;
8
+ if (props.term.length === 0) {
9
+ return [];
10
+ }
11
+ const params = new URLSearchParams({
12
+ term: props.term,
13
+ level: props.level.toString(),
14
+ limit: limit.toString(),
15
+ });
16
+ if (props.zip) {
17
+ params.append("zip", props.zip.toString());
18
+ }
19
+ const response = await fetch(config_1.smartAddressUrl + "/v1/search?" + params);
20
+ return JSON.parse(await response.text());
21
+ };
22
+ exports.search = search;
package/v1/types.d.ts ADDED
@@ -0,0 +1,89 @@
1
+ export type Option = {
2
+ id: number;
3
+ label: string;
4
+ };
5
+ export type Point = {
6
+ latitude: string;
7
+ longitude: string;
8
+ };
9
+ export type Location = {
10
+ id: number;
11
+ obecKod: number;
12
+ obecNazev: string | null;
13
+ obec: string | null;
14
+ momcKod: number | null;
15
+ momcNazev: string | null;
16
+ mopKod: number | null;
17
+ mopNazev: string | null;
18
+ castObceKod: number | null;
19
+ castObceNazev: string | null;
20
+ uliceKod: number | null;
21
+ uliceNazev: string | null;
22
+ ulice: string | null;
23
+ typSo: string | null;
24
+ cisloDomovni: number | null;
25
+ cisloOrientacni: number | null;
26
+ cisloOrientacniZnak: string | null;
27
+ psc: number | null;
28
+ search: string | null;
29
+ level: number | null;
30
+ gps: Point | null;
31
+ platiOd: string | null;
32
+ aktualizace: string | null;
33
+ okresKod: number | null;
34
+ okresNazev: string | null;
35
+ krajKod: number | null;
36
+ krajNazev: string | null;
37
+ };
38
+ export type LocationExtended = {
39
+ id: number;
40
+ distributorElektrinyKod: string | null;
41
+ distributorElektrinyId: number | null;
42
+ distributorPlynuKod: string | null;
43
+ distributorPlynuId: number | null;
44
+ typBudovy: BuildingType | null;
45
+ isknBudovaId: string | null;
46
+ druhKonstrukce: ConstructionType | null;
47
+ pocetBytu: number | null;
48
+ pocetPodlazi: number | null;
49
+ pripojeniKanalizace: SewerConnectionType | null;
50
+ pripojeniPlyn: GasConnectionType | null;
51
+ pripojeniVodovod: WaterConnectionType | null;
52
+ vybaveniVytahem: ElevatorType | null;
53
+ zpusobVytapeni: HeatingType | null;
54
+ zastavenaPlocha: number | null;
55
+ obestavenyProstor: number | null;
56
+ podlahovaPlocha: number | null;
57
+ stavebniObjektKod: string | null;
58
+ parcelaKod: string | null;
59
+ zpusobVyuzitiObjektu: BuildingUsageType | null;
60
+ createdAt: string | null;
61
+ updatedAt: string | null;
62
+ objectType: ObjectType | null;
63
+ objectTypeBasic: ObjectTypeBasic | null;
64
+ objectSize: string | null;
65
+ objectSizeSquare: number | null;
66
+ };
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
+ export {};
package/v1/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
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;
@@ -0,0 +1,87 @@
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 = void 0;
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", value: addressValue, onChange: setAddressValue, loadOptions: index_1.SmartAddress.createAddressLoader({ level: 1 }) }),
73
+ react_1.default.createElement(combobox_1.Combobox, { label: "Zip combobox", value: zipValue, onChange: setZipValue, loadOptions: index_1.SmartAddress.createZipLoader({}) }),
74
+ react_1.default.createElement(text_input_1.TextInput, { type: "text", value: textValue, onChange: setTextValue, label: "Text input" }),
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
+ }
87
+ exports.Default = Default;
package/client.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { Address, ExtendedAddress, SearchRequestQuery } from "./types";
2
- declare function search(query: SearchRequestQuery): Promise<Address[]>;
3
- declare function get(id: number): Promise<Address>;
4
- declare function getExtended(id: number): Promise<ExtendedAddress>;
5
- export declare const SmartAddress: {
6
- search: typeof search;
7
- get: typeof get;
8
- getExtended: typeof getExtended;
9
- };
10
- export {};
package/client.js DELETED
@@ -1,105 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __read = (this && this.__read) || function (o, n) {
50
- var m = typeof Symbol === "function" && o[Symbol.iterator];
51
- if (!m) return o;
52
- var i = m.call(o), r, ar = [], e;
53
- try {
54
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
55
- }
56
- catch (error) { e = { error: error }; }
57
- finally {
58
- try {
59
- if (r && !r.done && (m = i["return"])) m.call(i);
60
- }
61
- finally { if (e) throw e.error; }
62
- }
63
- return ar;
64
- };
65
- var __importDefault = (this && this.__importDefault) || function (mod) {
66
- return (mod && mod.__esModule) ? mod : { "default": mod };
67
- };
68
- var _a;
69
- Object.defineProperty(exports, "__esModule", { value: true });
70
- exports.SmartAddress = void 0;
71
- var axios_1 = __importDefault(require("axios"));
72
- var axiosInstance = axios_1.default.create({
73
- baseURL: (_a = process.env.SMART_ADDRESS_URL) !== null && _a !== void 0 ? _a : "https://smart-address.cz/api/v1",
74
- headers: {
75
- "X-Api-Token": process.env.SMART_ADDRESS_TOKEN,
76
- },
77
- });
78
- function search(query) {
79
- return axiosInstance.get("/search", { params: query }).then(function (r) { return r.data; });
80
- }
81
- function get(id) {
82
- return axiosInstance.get("/address/" + id).then(function (r) { return r.data; });
83
- }
84
- function getExtended(id) {
85
- return __awaiter(this, void 0, void 0, function () {
86
- var _a, address, extended;
87
- return __generator(this, function (_b) {
88
- switch (_b.label) {
89
- case 0: return [4 /*yield*/, Promise.all([
90
- get(id),
91
- axiosInstance.get("/address/" + id + "/extended").then(function (r) { return r.data; }),
92
- ])];
93
- case 1:
94
- _a = __read.apply(void 0, [_b.sent(), 2]), address = _a[0], extended = _a[1];
95
- return [2 /*return*/, __assign(__assign({}, address), extended)];
96
- }
97
- });
98
- });
99
- }
100
- exports.SmartAddress = {
101
- search: search,
102
- get: get,
103
- getExtended: getExtended,
104
- };
105
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xpZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2NsaWVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBQUEsZ0RBQTBCO0FBRzFCLElBQU0sYUFBYSxHQUFHLGVBQUssQ0FBQyxNQUFNLENBQUM7SUFDL0IsT0FBTyxRQUFFLE9BQU8sQ0FBQyxHQUFHLENBQUMsaUJBQWlCLG1DQUFJLGlDQUFpQztJQUMzRSxPQUFPLEVBQUU7UUFDTCxhQUFhLEVBQUUsT0FBTyxDQUFDLEdBQUcsQ0FBQyxtQkFBbUI7S0FDakQ7Q0FDSixDQUFDLENBQUM7QUFFSCxTQUFTLE1BQU0sQ0FBQyxLQUF5QjtJQUNyQyxPQUFPLGFBQWEsQ0FBQyxHQUFHLENBQUMsU0FBUyxFQUFFLEVBQUUsTUFBTSxFQUFFLEtBQUssRUFBRSxDQUFDLENBQUMsSUFBSSxDQUFDLFVBQUMsQ0FBQyxJQUFLLE9BQUEsQ0FBQyxDQUFDLElBQUksRUFBTixDQUFNLENBQUMsQ0FBQztBQUMvRSxDQUFDO0FBRUQsU0FBUyxHQUFHLENBQUMsRUFBVTtJQUNuQixPQUFPLGFBQWEsQ0FBQyxHQUFHLENBQUMsY0FBWSxFQUFJLENBQUMsQ0FBQyxJQUFJLENBQUMsVUFBQyxDQUFDLElBQUssT0FBQSxDQUFDLENBQUMsSUFBSSxFQUFOLENBQU0sQ0FBQyxDQUFDO0FBQ25FLENBQUM7QUFFRCxTQUFlLFdBQVcsQ0FBQyxFQUFVOzs7Ozt3QkFDTCxxQkFBTSxPQUFPLENBQUMsR0FBRyxDQUFDO3dCQUMxQyxHQUFHLENBQUMsRUFBRSxDQUFDO3dCQUNQLGFBQWEsQ0FBQyxHQUFHLENBQUMsY0FBWSxFQUFFLGNBQVcsQ0FBQyxDQUFDLElBQUksQ0FBQyxVQUFDLENBQUMsSUFBSyxPQUFBLENBQUMsQ0FBQyxJQUFJLEVBQU4sQ0FBTSxDQUFDO3FCQUNuRSxDQUFDLEVBQUE7O29CQUhJLEtBQUEsc0JBQXNCLFNBRzFCLEtBQUEsRUFISyxPQUFPLFFBQUEsRUFBRSxRQUFRLFFBQUE7b0JBS3hCLDRDQUNPLE9BQU8sR0FDUCxRQUFRLEdBQ2I7Ozs7Q0FDTDtBQUVZLFFBQUEsWUFBWSxHQUFHO0lBQ3hCLE1BQU0sUUFBQTtJQUNOLEdBQUcsS0FBQTtJQUNILFdBQVcsYUFBQTtDQUNkLENBQUMifQ==
package/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./client";
2
- export * from "./types";
package/index.js DELETED
@@ -1,15 +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
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./client"), exports);
14
- __exportStar(require("./types"), exports);
15
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7O0FBQUEsMkNBQXlCO0FBQ3pCLDBDQUF3QiJ9
package/types.d.ts DELETED
@@ -1,75 +0,0 @@
1
- export interface SearchRequestQuery {
2
- term?: string;
3
- level?: number;
4
- limit?: number;
5
- }
6
- export interface Address {
7
- id: number;
8
- obecKod: number;
9
- obecNazev: string;
10
- momcKod: number | null;
11
- momcNazev: string | null;
12
- mopKod: number | null;
13
- mopNazev: string | null;
14
- castObceKod: number | null;
15
- castObceNazev: string | null;
16
- uliceKod: number | null;
17
- uliceNazev: string | null;
18
- typSo: string | null;
19
- cisloDomovni: number | null;
20
- cisloOrientacni: number | null;
21
- cisloOrientacniZnak: string | null;
22
- psc: number | null;
23
- search: string;
24
- level: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
25
- gps: {
26
- latitude: number;
27
- longitude: number;
28
- };
29
- platiOd: string;
30
- aktualizace: string;
31
- okresKod: number | null;
32
- okresNazev: string | null;
33
- krajKod: number | null;
34
- krajNazev: string | null;
35
- }
36
- export interface Codebook {
37
- id: number;
38
- nazev: string;
39
- popis: string;
40
- zkracenyNazev: string;
41
- zacatekPlatnosti: null;
42
- konecPlatnosti: null;
43
- }
44
- export interface SimpleCodebook {
45
- id: number;
46
- nazev: string;
47
- }
48
- export interface ExtendedAddress extends Address {
49
- distributorElektrinyKod: string;
50
- distributorElektrinyId: number;
51
- distributorPlynuKod: string;
52
- distributorPlynuId: number;
53
- typBudovy: Codebook | null;
54
- isknBudovaId: string;
55
- druhKonstrukce: Codebook | null;
56
- pocetBytu: number | null;
57
- pocetPodlazi: number | null;
58
- pripojeniKanalizace: Codebook | null;
59
- pripojeniPlyn: Codebook | null;
60
- pripojeniVodovod: Codebook | null;
61
- vybaveniVytahem: Codebook | null;
62
- zpusobVytapeni: Codebook;
63
- zastavenaPlocha: number | null;
64
- obestavenyProstor: number | null;
65
- podlahovaPlocha: number | null;
66
- stavebniObjektKod: string | null;
67
- parcelaKod: number | null;
68
- zpusobVyuzitiObjektu: Codebook | null;
69
- createdAt: string | null;
70
- updatedAt: string | null;
71
- objectType: SimpleCodebook | null;
72
- objectTypeBasic: SimpleCodebook | null;
73
- objectSize: string | null;
74
- objectSizeSquare: number | null;
75
- }
package/types.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvdHlwZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9