@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.cjs
CHANGED
|
@@ -66,13 +66,31 @@ var useLocationSearch = (googleApi) => {
|
|
|
66
66
|
const getPredictions = async (text) => {
|
|
67
67
|
try {
|
|
68
68
|
const response = await fetch(
|
|
69
|
-
|
|
69
|
+
"https://places.googleapis.com/v1/places:autocomplete",
|
|
70
|
+
{
|
|
71
|
+
body: JSON.stringify({
|
|
72
|
+
includedRegionCodes: ["nz"],
|
|
73
|
+
input: text,
|
|
74
|
+
languageCode: "en"
|
|
75
|
+
}),
|
|
76
|
+
headers: {
|
|
77
|
+
"Content-Type": "application/json",
|
|
78
|
+
"X-Goog-Api-Key": googleApi,
|
|
79
|
+
"X-Goog-FieldMask": "suggestions.placePrediction.placeId,suggestions.placePrediction.text.text"
|
|
80
|
+
},
|
|
81
|
+
method: "POST"
|
|
82
|
+
}
|
|
70
83
|
);
|
|
71
84
|
if (!response.ok) {
|
|
72
85
|
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
73
86
|
}
|
|
74
87
|
const data = await response.json();
|
|
75
|
-
|
|
88
|
+
const suggestions = data.suggestions ?? [];
|
|
89
|
+
const predictions = suggestions.map((suggestion) => suggestion.placePrediction).filter(Boolean).map((prediction) => ({
|
|
90
|
+
description: prediction?.text?.text || "",
|
|
91
|
+
place_id: prediction?.placeId || ""
|
|
92
|
+
})).filter((prediction) => prediction.place_id && prediction.description);
|
|
93
|
+
return predictions;
|
|
76
94
|
} catch (error) {
|
|
77
95
|
console.error("Error fetching predictions:", error);
|
|
78
96
|
handleApiError(error, "Failed to fetch address predictions.");
|
|
@@ -81,42 +99,47 @@ var useLocationSearch = (googleApi) => {
|
|
|
81
99
|
const getPlaceDetails = async (placeId) => {
|
|
82
100
|
try {
|
|
83
101
|
const response = await fetch(
|
|
84
|
-
`https://
|
|
102
|
+
`https://places.googleapis.com/v1/places/${placeId}`,
|
|
103
|
+
{
|
|
104
|
+
headers: {
|
|
105
|
+
"X-Goog-Api-Key": googleApi,
|
|
106
|
+
"X-Goog-FieldMask": "addressComponents,formattedAddress,location"
|
|
107
|
+
}
|
|
108
|
+
}
|
|
85
109
|
);
|
|
86
110
|
if (!response.ok) {
|
|
87
111
|
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
88
112
|
}
|
|
89
|
-
const
|
|
90
|
-
const {
|
|
91
|
-
const {
|
|
92
|
-
const
|
|
93
|
-
const address = address_components.reduce((acc, item) => {
|
|
113
|
+
const result = await response.json();
|
|
114
|
+
const { latitude, longitude } = result.location;
|
|
115
|
+
const { addressComponents, formattedAddress } = result;
|
|
116
|
+
const address = addressComponents.reduce((acc, item) => {
|
|
94
117
|
if (item.types.includes("street_number")) {
|
|
95
|
-
return { ...acc, streetNumber: item.
|
|
118
|
+
return { ...acc, streetNumber: item.longText };
|
|
96
119
|
}
|
|
97
120
|
if (item.types.includes("route")) {
|
|
98
|
-
return { ...acc, streetName: item.
|
|
121
|
+
return { ...acc, streetName: item.longText };
|
|
99
122
|
}
|
|
100
123
|
if (item.types.includes("locality")) {
|
|
101
|
-
return { ...acc, city: item.
|
|
124
|
+
return { ...acc, city: item.longText };
|
|
102
125
|
}
|
|
103
126
|
if (item.types.includes("administrative_area_level_1")) {
|
|
104
|
-
return { ...acc, region: item.
|
|
127
|
+
return { ...acc, region: item.longText };
|
|
105
128
|
}
|
|
106
129
|
if (item.types.includes("country")) {
|
|
107
|
-
return { ...acc, country: item.
|
|
130
|
+
return { ...acc, country: item.longText };
|
|
108
131
|
}
|
|
109
132
|
return acc;
|
|
110
133
|
}, {});
|
|
111
134
|
const newLocation = {
|
|
112
|
-
city: address.city.toLowerCase(),
|
|
113
|
-
coordinates: [
|
|
135
|
+
city: address.city ? address.city.toLowerCase() : "",
|
|
136
|
+
coordinates: [longitude, latitude],
|
|
114
137
|
// [longitude, latitude]
|
|
115
138
|
country: address.country,
|
|
116
|
-
fullAddress:
|
|
117
|
-
latitude
|
|
118
|
-
longitude
|
|
119
|
-
region: address.region.replace(/ Region$/, ""),
|
|
139
|
+
fullAddress: formattedAddress,
|
|
140
|
+
latitude,
|
|
141
|
+
longitude,
|
|
142
|
+
region: address.region ? address.region.replace(/ Region$/, "") : "",
|
|
120
143
|
// Remove " Region" suffix
|
|
121
144
|
type: "Point"
|
|
122
145
|
// Mongoose GeoJSON type
|