@wikicasa-dev/utilities 0.1.0 → 0.1.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 (51) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/utilities.cjs +5 -0
  3. package/dist/{utilities.umd.cjs → utilities.iife.js} +4 -4
  4. package/dist/{utilities.js → utilities.mjs} +57 -51
  5. package/dist/utils/DateUtils.d.ts +1 -0
  6. package/package.json +10 -7
  7. package/src/custom/constants.ts +3 -0
  8. package/src/custom/icons.ts +63 -0
  9. package/src/custom/leaflet_map.ts +946 -0
  10. package/src/index.ts +173 -0
  11. package/src/services/agencyAPI.ts +105 -0
  12. package/src/services/geographyAPI.ts +129 -0
  13. package/src/services/insightsAPI.ts +20 -0
  14. package/src/services/mailAPI.ts +89 -0
  15. package/src/services/placesAPI.ts +72 -0
  16. package/src/services/portfolioCustomerAPI.ts +16 -0
  17. package/src/services/publicUserAPI.ts +216 -0
  18. package/src/services/realEstateAPI.ts +133 -0
  19. package/src/services/requestAPI.ts +40 -0
  20. package/src/services/servicesUtils.ts +27 -0
  21. package/src/services/statisticsAPI.ts +84 -0
  22. package/src/services/valuationAPI.ts +45 -0
  23. package/src/services/wikicasaPro.ts +25 -0
  24. package/src/utils/AppRedirectUtils.ts +26 -0
  25. package/src/utils/ArrayUtils.ts +2 -0
  26. package/src/utils/ColorUtils.ts +11 -0
  27. package/src/utils/CookieUtils.ts +43 -0
  28. package/src/utils/CurrencyUtils.ts +18 -0
  29. package/src/utils/DOMUtils.ts +28 -0
  30. package/src/utils/DateUtils.ts +9 -0
  31. package/src/utils/DeviceDetectionUtils.ts +17 -0
  32. package/src/utils/EmailUtils.ts +45 -0
  33. package/src/utils/FavoriteUtils.ts +19 -0
  34. package/src/utils/FunctionUtils.ts +29 -0
  35. package/src/utils/GAEvents.ts +414 -0
  36. package/src/utils/GAutocompleteUtils.ts +70 -0
  37. package/src/utils/GenericUtils.ts +37 -0
  38. package/src/utils/LazyLoadingBg.ts +18 -0
  39. package/src/utils/MapUtils.ts +118 -0
  40. package/src/utils/NumberUtils.ts +90 -0
  41. package/src/utils/ObjectUtils.ts +34 -0
  42. package/src/utils/ObserverUtils.ts +32 -0
  43. package/src/utils/PermissionUtils.ts +41 -0
  44. package/src/utils/RESB_UrlBuilder.ts +99 -0
  45. package/src/utils/RequestUtils.ts +20 -0
  46. package/src/utils/StringUtils.ts +67 -0
  47. package/src/utils/URLBuilderUtils.ts +21 -0
  48. package/src/utils/URLPagesFactory.ts +20 -0
  49. package/src/vite-env.d.ts +1 -0
  50. package/tsconfig.json +38 -0
  51. package/vite.config.ts +42 -0
package/src/index.ts ADDED
@@ -0,0 +1,173 @@
1
+ // SERVICE
2
+
3
+ export {
4
+ sendAgencyContactAsync,
5
+ getAgencyById,
6
+ sendMortgage,
7
+ getAgenciesData,
8
+ } from "@services/agencyAPI";
9
+
10
+ export {
11
+ getPlacesAddressAutocomplete,
12
+ getPlacesDetails,
13
+ guessPlace,
14
+ getPlaceFromPlaceID,
15
+ getCountryPolygonJSON,
16
+ getRegionPolygonJSON,
17
+ getProvincePolygonJSON,
18
+ getCityPolygonJSON,
19
+ } from "@services/geographyAPI";
20
+
21
+ export { getTransactionGraphData } from "@services/insightsAPI";
22
+
23
+ export {
24
+ sendInfoPremium,
25
+ sendBrochureRequest,
26
+ sendJobApplicationForm,
27
+ sendBrochureMR,
28
+ sendInfoMR,
29
+ } from "@services/mailAPI";
30
+
31
+ export {
32
+ getPlacesByQuery,
33
+ getPlace,
34
+ getZones,
35
+ getDistrictsByZoneId,
36
+ } from "@services/placesAPI";
37
+
38
+ export { updateNewsletterConsent } from "@services/portfolioCustomerAPI";
39
+
40
+ export {
41
+ getMenuInfo,
42
+ getPublicUser,
43
+ getMarketingConsent,
44
+ deleteAllSaveSearch,
45
+ deleteSaveSearch,
46
+ getFavourites,
47
+ addUserFavorite,
48
+ deleteUserFavorite,
49
+ updateNote,
50
+ removeFavourites,
51
+ saveUserFirebaseToken,
52
+ deleteUserFirebaseToken,
53
+ updateMarketingConsent,
54
+ getPublicUserSaveSearchList,
55
+ updatePublicUserSavedSearchBean,
56
+ getSavedSearchesCount,
57
+ } from "@services/publicUserAPI";
58
+
59
+ export {
60
+ getRealEstateNotes,
61
+ saveSearch,
62
+ saveSearchFromRequest,
63
+ getRealEstateCounter,
64
+ getRealEstatesData,
65
+ getMapMarkers,
66
+ } from "@services/realEstateAPI";
67
+
68
+ export {
69
+ sendSuggestion,
70
+ addGenericRequest,
71
+ sendWidgetRequest,
72
+ } from "@services/requestAPI";
73
+
74
+ export { handleAxiosError } from "@services/servicesUtils";
75
+
76
+ export {
77
+ updateViewListing,
78
+ updateRealEstateSearch,
79
+ updatePhoneView,
80
+ getPlaceTrendData,
81
+ getSaleGraphData,
82
+ } from "@services/statisticsAPI";
83
+
84
+ export { evaluateRealEstateWidget } from "@services/valuationAPI";
85
+
86
+ export { userValuationWithPhotoFeedback } from "@services/wikicasaPro";
87
+
88
+ // UTILITIES
89
+
90
+ export { redirectToApp } from "@utils/AppRedirectUtils";
91
+
92
+ export { isArrNullOrEmpty } from "@utils/ArrayUtils";
93
+
94
+ export { rgba } from "@utils/ColorUtils";
95
+
96
+ export {
97
+ encodeCookie,
98
+ getCookie,
99
+ decodeCookie,
100
+ removeCookie,
101
+ } from "@utils/CookieUtils";
102
+
103
+ export { formatCurrency } from "@utils/CurrencyUtils";
104
+
105
+ export { formatDate } from "@utils/DateUtils";
106
+
107
+ export { isiOSDevice, isMobile, isSafari } from "@utils/DeviceDetectionUtils";
108
+
109
+ export {
110
+ getSingleElement,
111
+ emptyElem,
112
+ showElem,
113
+ hideElem,
114
+ } from "@utils/DOMUtils";
115
+
116
+ export { hashEmail } from "@utils/EmailUtils";
117
+
118
+ export {
119
+ showAddFavoritesIcon,
120
+ showRemoveFavoritesIcons,
121
+ } from "@utils/FavoriteUtils";
122
+
123
+ export { sendGAEvent } from "@utils/GAEvents";
124
+
125
+ export {
126
+ googlePlaceConverter,
127
+ getPlaceFromGAutocomplete,
128
+ } from "@utils/GAutocompleteUtils";
129
+
130
+ export { awaitableSetTimeout } from "@utils/GenericUtils";
131
+
132
+ export {
133
+ formatInteger,
134
+ formatFloat,
135
+ parseLocaleNumber,
136
+ formatLocaleNumber,
137
+ formatNumber,
138
+ formatterNumberObj,
139
+ } from "@utils/NumberUtils";
140
+
141
+ export {
142
+ isEmptyObject,
143
+ shallowCopyObjectTo,
144
+ deepCopy,
145
+ } from "@utils/ObjectUtils";
146
+
147
+ export { observeOnce } from "@utils/ObserverUtils";
148
+
149
+ export {
150
+ addPermissionStateListener,
151
+ onNotificationsPermissionChange,
152
+ } from "@utils/PermissionUtils";
153
+
154
+ export { sendRequestGeneric } from "@utils/RequestUtils";
155
+
156
+ export {
157
+ buildURL,
158
+ buildParams,
159
+ buildParamsForAgency,
160
+ } from "@utils/RESB_UrlBuilder";
161
+
162
+ export {
163
+ replaceAll,
164
+ replaceAllTokens,
165
+ capitalizeFirstLetter,
166
+ formatAddress,
167
+ decodeTextWithEntities,
168
+ cleanASCII,
169
+ } from "@utils/StringUtils";
170
+
171
+ export { appendQueryString } from "@utils/URLBuilderUtils";
172
+
173
+ export { getURLPage } from "@utils/URLPagesFactory";
@@ -0,0 +1,105 @@
1
+ import { baseURL, handleAxiosError } from "./servicesUtils";
2
+ import axios, { AxiosError } from "axios";
3
+ import type {
4
+ AgencyItem,
5
+ MapMarker,
6
+ Contacts,
7
+ Nullable,
8
+ } from "@wikicasa-dev/types";
9
+ import { deepCopy } from "@utils/ObjectUtils";
10
+
11
+ declare global {
12
+ interface Window {
13
+ _serializedAgencySearchBean?: Nullable<any>;
14
+ }
15
+ }
16
+
17
+ const baseController = `${baseURL}/rest/agency`;
18
+
19
+ export const sendAgencyContactAsync = async (
20
+ data: Contacts
21
+ ): Promise<boolean> => {
22
+ try {
23
+ const res = await axios.post(`${baseController}/agencyContacts`, data);
24
+ return res.data as boolean;
25
+ } catch (error) {
26
+ handleAxiosError(error as AxiosError);
27
+ throw error;
28
+ }
29
+ };
30
+ export const getAgencyById = async (
31
+ agencyId: number,
32
+ lang: string
33
+ ): Promise<AgencyItem> => {
34
+ try {
35
+ const res = await axios.get(
36
+ `/rest/agency/getAgencyByIDLang/${agencyId}/${lang}`
37
+ );
38
+ return res.data;
39
+ } catch (error) {
40
+ handleAxiosError(error as AxiosError);
41
+ throw error;
42
+ }
43
+ };
44
+ export const sendMortgage = async (data: {
45
+ name: string;
46
+ email: string;
47
+ phone: string;
48
+ url: string;
49
+ realEstateId: number;
50
+ price: number;
51
+ tenantId: number;
52
+ }): Promise<boolean> => {
53
+ try {
54
+ const res = await axios.post("/rest/agency/sendMutuo", data);
55
+ return res.data;
56
+ } catch (error) {
57
+ handleAxiosError(error as AxiosError);
58
+ throw error;
59
+ }
60
+ };
61
+
62
+ export const getAgenciesData = async (
63
+ ids: Array<number>
64
+ ): Promise<AgencyItem[]> => {
65
+ try {
66
+ const res = await axios.post(
67
+ `${baseController}/getAgencyListForInfoWindow`,
68
+ ids
69
+ );
70
+ return res.data as AgencyItem[];
71
+ } catch (error) {
72
+ handleAxiosError(error as AxiosError);
73
+ throw error;
74
+ }
75
+ };
76
+
77
+ export const getMapMarkers = async (): Promise<
78
+ Array<MapMarker> | undefined
79
+ > => {
80
+ if (!window["_serializedAgencySearchBean"]) return;
81
+
82
+ const agencySearchBean = deepCopy(
83
+ JSON.parse(window["_serializedAgencySearchBean"])
84
+ );
85
+
86
+ delete agencySearchBean["latitude"];
87
+ delete agencySearchBean["longitude"];
88
+
89
+ try {
90
+ const res = await axios.post(
91
+ `${baseController}/getAgenciesMarkers`,
92
+ agencySearchBean,
93
+ {
94
+ headers: {
95
+ "Content-Type": "application/json",
96
+ Accept: "application/json",
97
+ },
98
+ }
99
+ );
100
+ return res.data as MapMarker[];
101
+ } catch (error) {
102
+ handleAxiosError(error as AxiosError);
103
+ throw [];
104
+ }
105
+ };
@@ -0,0 +1,129 @@
1
+ import axios, { AxiosError } from "axios";
2
+ import { v4 as uuidv4 } from "uuid";
3
+ import type {
4
+ Place,
5
+ GAutocompleteTypes,
6
+ GooglePredictionType,
7
+ GPlaceDetails,
8
+ Nullable,
9
+ } from "@wikicasa-dev/types";
10
+
11
+ import { appendQueryString } from "@utils/URLBuilderUtils";
12
+ import { handleAxiosError, baseURL } from "./servicesUtils";
13
+
14
+ const baseController = `${baseURL}/rest/geography`;
15
+
16
+ let sessionToken = uuidv4();
17
+
18
+ export const getPlacesAddressAutocomplete = async (
19
+ query: string,
20
+ radius: number,
21
+ types: GAutocompleteTypes[] = []
22
+ ): Promise<GooglePredictionType[]> => {
23
+ if (!sessionToken) sessionToken = uuidv4();
24
+
25
+ const url = new URL(`${baseController}/placesAddressAutocomplete`);
26
+
27
+ const length = types.length;
28
+ const _types = types.reduce((acc, cur, currentIndex) => {
29
+ if (length === 1) return cur;
30
+
31
+ if (currentIndex === length - 1) return acc;
32
+
33
+ return (acc += `${cur}|`);
34
+ }, "");
35
+
36
+ const urlWithQueryString = appendQueryString(url, {
37
+ query,
38
+ radius,
39
+ sessionToken: sessionToken,
40
+ types: _types,
41
+ });
42
+ const res = await axios.get(urlWithQueryString.toString());
43
+ if (res.data.status !== "OK")
44
+ throw new Error("There was an error in the request");
45
+
46
+ return res.data.predictions as GooglePredictionType[];
47
+ };
48
+
49
+ export const getPlacesDetails = async (
50
+ placeId: string
51
+ ): Promise<GPlaceDetails> => {
52
+ const url = new URL(`${baseController}/getPlacesDetails`);
53
+ const urlWithQueryString = appendQueryString(url, {
54
+ placeId,
55
+ sessionToken: sessionToken,
56
+ });
57
+
58
+ const res = await axios.get(urlWithQueryString.toString());
59
+ sessionToken = "";
60
+
61
+ if (res.data.status !== "OK")
62
+ throw new Error("There was an error in the request");
63
+
64
+ return res.data.result as GPlaceDetails;
65
+ };
66
+
67
+ export const guessPlace = async (
68
+ latitude?: number,
69
+ longitude?: number
70
+ ): Promise<Place> => {
71
+ const url = new URL(
72
+ `${baseController}/guessCityPlace/${latitude}/${longitude}`
73
+ );
74
+ const res = await axios.get(url.toString());
75
+ return res.data as Place;
76
+ };
77
+
78
+ export const getPlaceFromPlaceID = async (
79
+ id?: Nullable<number>
80
+ ): Promise<Place> => {
81
+ if (id === null || id === undefined) throw new Error("The id can't be null");
82
+
83
+ const res = await axios.get(`${baseController}/getPlaceFromPlaceID/${id}`);
84
+ return res.data as Place;
85
+ };
86
+
87
+ export const getCountryPolygonJSON = async (id: number): Promise<any> => {
88
+ try {
89
+ const res = await axios.get(
90
+ `${baseController}/getCountryPolygonJson/${id}`
91
+ );
92
+ return res.data;
93
+ } catch (e) {
94
+ handleAxiosError(e as AxiosError);
95
+ throw e;
96
+ }
97
+ };
98
+
99
+ export const getRegionPolygonJSON = async (id: number): Promise<any> => {
100
+ try {
101
+ const res = await axios.get(`${baseController}/getRegionPolygonJson/${id}`);
102
+ return res.data;
103
+ } catch (e) {
104
+ handleAxiosError(e as AxiosError);
105
+ throw e;
106
+ }
107
+ };
108
+
109
+ export const getCityPolygonJSON = async (id: number): Promise<any> => {
110
+ try {
111
+ const res = await axios.get(`${baseController}/getCityPolygonJson/${id}`);
112
+ return res.data;
113
+ } catch (e) {
114
+ handleAxiosError(e as AxiosError);
115
+ throw e;
116
+ }
117
+ };
118
+
119
+ export const getProvincePolygonJSON = async (id: number): Promise<any> => {
120
+ try {
121
+ const res = await axios.get(
122
+ `${baseController}/getProvincePolygonJson/${id}`
123
+ );
124
+ return res.data;
125
+ } catch (e) {
126
+ handleAxiosError(e as AxiosError);
127
+ throw e;
128
+ }
129
+ };
@@ -0,0 +1,20 @@
1
+ import axios, { AxiosError } from "axios";
2
+ import { handleAxiosError } from "./servicesUtils";
3
+ import type { Place, GraphData } from "@wikicasa-dev/types";
4
+
5
+ const baseStatisticControllerUrl = "/rest/insights";
6
+
7
+ export const getTransactionGraphData = async (
8
+ place: Place
9
+ ): Promise<GraphData[]> => {
10
+ try {
11
+ const res = await axios.post(
12
+ `${baseStatisticControllerUrl}/getTransactionsGraphData`,
13
+ place
14
+ );
15
+ return res.data;
16
+ } catch (error) {
17
+ handleAxiosError(error as AxiosError);
18
+ throw error;
19
+ }
20
+ };
@@ -0,0 +1,89 @@
1
+ import axios, { AxiosError } from "axios";
2
+ import { baseURL, handleAxiosError } from "./servicesUtils";
3
+
4
+ const baseController = `${baseURL}/rest/mail`;
5
+
6
+ type InfoPremiumPayload = {
7
+ name: string;
8
+ phone: string;
9
+ agency?: string;
10
+ agency_name?: string;
11
+ email: string;
12
+ contact_preference: number;
13
+ service?: string;
14
+ };
15
+
16
+ export const sendInfoPremium = async (
17
+ data: InfoPremiumPayload
18
+ ): Promise<boolean> => {
19
+ try {
20
+ const res = await axios.post(`${baseController}/infoPremium`, data);
21
+ return res.data as boolean;
22
+ } catch (err) {
23
+ handleAxiosError(err as AxiosError);
24
+ throw err;
25
+ }
26
+ };
27
+
28
+ export const sendBrochureRequest = async (data: {
29
+ email: string;
30
+ }): Promise<boolean> => {
31
+ try {
32
+ const res = await axios.post(`${baseController}/sendBrochurePremium`, data);
33
+ return res.data as boolean;
34
+ } catch (err) {
35
+ handleAxiosError(err as AxiosError);
36
+ throw err;
37
+ }
38
+ };
39
+
40
+ export const sendJobApplicationForm = async (
41
+ data: FormData
42
+ ): Promise<boolean> => {
43
+ try {
44
+ const res = await axios.post<boolean>(
45
+ `${baseController}/submitJobApplication`,
46
+ data,
47
+ {
48
+ headers: {
49
+ "Content-Type": "multipart/form-data",
50
+ },
51
+ }
52
+ );
53
+ return res.data;
54
+ } catch (e) {
55
+ handleAxiosError(e as AxiosError);
56
+ throw e;
57
+ }
58
+ };
59
+
60
+ /* Market Report */
61
+ export const sendBrochureMR = async (data: {
62
+ email: string;
63
+ }): Promise<boolean> => {
64
+ try {
65
+ const res = await axios.post<boolean>(
66
+ `${baseController}/sendBrochureMR`,
67
+ data
68
+ );
69
+ return res.data;
70
+ } catch (e) {
71
+ handleAxiosError(e as AxiosError);
72
+ throw e;
73
+ }
74
+ };
75
+
76
+ export const sendInfoMR = async (data: {
77
+ phone: string;
78
+ email: string;
79
+ agency: string;
80
+ name?: string;
81
+ }): Promise<boolean> => {
82
+ try {
83
+ const res = await axios.post<boolean>(`${baseController}/infoMR`, data);
84
+ return res.data;
85
+ } catch (e) {
86
+ handleAxiosError(e as AxiosError);
87
+ throw e;
88
+ }
89
+ };
@@ -0,0 +1,72 @@
1
+ import axios, { AxiosError } from "axios";
2
+ import { handleAxiosError } from "./servicesUtils";
3
+ import type { PLACE_TYPE, Place } from "@wikicasa-dev/types";
4
+ import { appendQueryString } from "@utils/URLBuilderUtils";
5
+
6
+ //@ts-ignore
7
+ const baseURL = window["_baseURLIt"];
8
+ const baseController = "/ws";
9
+
10
+ export const getPlacesByQuery = async (
11
+ value: string,
12
+ placeType: PLACE_TYPE[] = [],
13
+ provinceId: number | string | null = ""
14
+ ): Promise<Place[]> => {
15
+ try {
16
+ if (!provinceId) provinceId = "";
17
+
18
+ const res = await axios.get(
19
+ `${baseController}/places?query=${value}&type=${placeType.join(",")}${
20
+ provinceId ? `&provinceID=${provinceId}` : ""
21
+ }`
22
+ );
23
+ return res.data as Place[];
24
+ } catch (err) {
25
+ handleAxiosError(err as AxiosError);
26
+ throw err;
27
+ }
28
+ };
29
+
30
+ export function getPlace(
31
+ query: string,
32
+ types = "C,P,Z,L,I,R,A"
33
+ ): Promise<Array<Place>> {
34
+ return new Promise((resolve) => {
35
+ axios
36
+ .get(`${baseController}/places?query=${query}&type=${types}`)
37
+ .then((response) => {
38
+ if (!response?.data) {
39
+ resolve([]);
40
+ }
41
+ resolve(response?.data);
42
+ });
43
+ });
44
+ }
45
+
46
+ export function getZones(cityID: number): Promise<Array<Place>> {
47
+ return new Promise((resolve) => {
48
+ axios.get(`${baseController}/zones?cityID=${cityID}`).then((response) => {
49
+ if (!response?.data) {
50
+ resolve([]);
51
+ return;
52
+ }
53
+ resolve(response?.data);
54
+ });
55
+ });
56
+ }
57
+
58
+ export const getDistrictsByZoneId = async (
59
+ zoneID: number
60
+ ): Promise<Place[]> => {
61
+ try {
62
+ const res = await axios.get(
63
+ appendQueryString(new URL(`${baseURL}${baseController}/districts`), {
64
+ zoneID,
65
+ }).toString()
66
+ );
67
+ return res.data as Place[];
68
+ } catch (e) {
69
+ handleAxiosError(e as AxiosError);
70
+ throw e;
71
+ }
72
+ };
@@ -0,0 +1,16 @@
1
+ import axios, { AxiosError } from "axios";
2
+ import { handleAxiosError } from "./servicesUtils";
3
+
4
+ export const updateNewsletterConsent = async (
5
+ email: string
6
+ ): Promise<boolean> => {
7
+ try {
8
+ const res = await axios.post(
9
+ `/rest/portfolioCustomer/updateNewsletterConsent/?email=${email}`
10
+ );
11
+ return res.data;
12
+ } catch (error) {
13
+ handleAxiosError(error as AxiosError);
14
+ throw error;
15
+ }
16
+ };