@timardex/cluemart-shared 1.3.64 → 1.3.66
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/dist/{googleImportedMarket-BECKtVJ4.d.ts → googleImportedMarket-BuxDo6MX.d.ts} +27 -25
- package/dist/{googleImportedMarket-Sl0y8deO.d.mts → googleImportedMarket-D2HOg7O-.d.mts} +27 -25
- package/dist/graphql/index.cjs +90 -20
- package/dist/graphql/index.cjs.map +1 -1
- package/dist/graphql/index.d.mts +26 -2
- package/dist/graphql/index.d.ts +26 -2
- package/dist/graphql/index.mjs +87 -20
- package/dist/graphql/index.mjs.map +1 -1
- package/dist/hooks/index.cjs +42 -19
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.mjs +42 -19
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.cjs +132 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +51 -25
- package/dist/index.d.ts +51 -25
- package/dist/index.mjs +129 -39
- package/dist/index.mjs.map +1 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/hooks/index.mjs
CHANGED
|
@@ -36,13 +36,31 @@ var useLocationSearch = (googleApi) => {
|
|
|
36
36
|
const getPredictions = async (text) => {
|
|
37
37
|
try {
|
|
38
38
|
const response = await fetch(
|
|
39
|
-
|
|
39
|
+
"https://places.googleapis.com/v1/places:autocomplete",
|
|
40
|
+
{
|
|
41
|
+
body: JSON.stringify({
|
|
42
|
+
includedRegionCodes: ["nz"],
|
|
43
|
+
input: text,
|
|
44
|
+
languageCode: "en"
|
|
45
|
+
}),
|
|
46
|
+
headers: {
|
|
47
|
+
"Content-Type": "application/json",
|
|
48
|
+
"X-Goog-Api-Key": googleApi,
|
|
49
|
+
"X-Goog-FieldMask": "suggestions.placePrediction.placeId,suggestions.placePrediction.text.text"
|
|
50
|
+
},
|
|
51
|
+
method: "POST"
|
|
52
|
+
}
|
|
40
53
|
);
|
|
41
54
|
if (!response.ok) {
|
|
42
55
|
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
43
56
|
}
|
|
44
57
|
const data = await response.json();
|
|
45
|
-
|
|
58
|
+
const suggestions = data.suggestions ?? [];
|
|
59
|
+
const predictions = suggestions.map((suggestion) => suggestion.placePrediction).filter(Boolean).map((prediction) => ({
|
|
60
|
+
description: prediction?.text?.text || "",
|
|
61
|
+
place_id: prediction?.placeId || ""
|
|
62
|
+
})).filter((prediction) => prediction.place_id && prediction.description);
|
|
63
|
+
return predictions;
|
|
46
64
|
} catch (error) {
|
|
47
65
|
console.error("Error fetching predictions:", error);
|
|
48
66
|
handleApiError(error, "Failed to fetch address predictions.");
|
|
@@ -51,42 +69,47 @@ var useLocationSearch = (googleApi) => {
|
|
|
51
69
|
const getPlaceDetails = async (placeId) => {
|
|
52
70
|
try {
|
|
53
71
|
const response = await fetch(
|
|
54
|
-
`https://
|
|
72
|
+
`https://places.googleapis.com/v1/places/${placeId}`,
|
|
73
|
+
{
|
|
74
|
+
headers: {
|
|
75
|
+
"X-Goog-Api-Key": googleApi,
|
|
76
|
+
"X-Goog-FieldMask": "addressComponents,formattedAddress,location"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
55
79
|
);
|
|
56
80
|
if (!response.ok) {
|
|
57
81
|
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
58
82
|
}
|
|
59
|
-
const
|
|
60
|
-
const {
|
|
61
|
-
const {
|
|
62
|
-
const
|
|
63
|
-
const address = address_components.reduce((acc, item) => {
|
|
83
|
+
const result = await response.json();
|
|
84
|
+
const { latitude, longitude } = result.location;
|
|
85
|
+
const { addressComponents, formattedAddress } = result;
|
|
86
|
+
const address = addressComponents.reduce((acc, item) => {
|
|
64
87
|
if (item.types.includes("street_number")) {
|
|
65
|
-
return { ...acc, streetNumber: item.
|
|
88
|
+
return { ...acc, streetNumber: item.longText };
|
|
66
89
|
}
|
|
67
90
|
if (item.types.includes("route")) {
|
|
68
|
-
return { ...acc, streetName: item.
|
|
91
|
+
return { ...acc, streetName: item.longText };
|
|
69
92
|
}
|
|
70
93
|
if (item.types.includes("locality")) {
|
|
71
|
-
return { ...acc, city: item.
|
|
94
|
+
return { ...acc, city: item.longText };
|
|
72
95
|
}
|
|
73
96
|
if (item.types.includes("administrative_area_level_1")) {
|
|
74
|
-
return { ...acc, region: item.
|
|
97
|
+
return { ...acc, region: item.longText };
|
|
75
98
|
}
|
|
76
99
|
if (item.types.includes("country")) {
|
|
77
|
-
return { ...acc, country: item.
|
|
100
|
+
return { ...acc, country: item.longText };
|
|
78
101
|
}
|
|
79
102
|
return acc;
|
|
80
103
|
}, {});
|
|
81
104
|
const newLocation = {
|
|
82
|
-
city: address.city.toLowerCase(),
|
|
83
|
-
coordinates: [
|
|
105
|
+
city: address.city ? address.city.toLowerCase() : "",
|
|
106
|
+
coordinates: [longitude, latitude],
|
|
84
107
|
// [longitude, latitude]
|
|
85
108
|
country: address.country,
|
|
86
|
-
fullAddress:
|
|
87
|
-
latitude
|
|
88
|
-
longitude
|
|
89
|
-
region: address.region.replace(/ Region$/, ""),
|
|
109
|
+
fullAddress: formattedAddress,
|
|
110
|
+
latitude,
|
|
111
|
+
longitude,
|
|
112
|
+
region: address.region ? address.region.replace(/ Region$/, "") : "",
|
|
90
113
|
// Remove " Region" suffix
|
|
91
114
|
type: "Point"
|
|
92
115
|
// Mongoose GeoJSON type
|