@quantaroute/checkout 1.2.1 → 1.3.1
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/lib/index.d.ts +64 -0
- package/dist/lib/quantaroute-checkout.es.js +323 -93
- package/dist/lib/quantaroute-checkout.umd.js +71 -56
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/CheckoutWidget.tsx +4 -0
- package/src/components/MapPinSelector.native.tsx +148 -2
- package/src/components/MapPinSelector.tsx +217 -6
- package/src/core/api.ts +92 -0
- package/src/core/types.ts +19 -0
- package/src/index.ts +7 -2
- package/src/styles/checkout.css +175 -0
- package/src/styles/checkout.native.ts +87 -0
package/dist/lib/index.d.ts
CHANGED
|
@@ -50,6 +50,45 @@ export declare interface AdministrativeInfo {
|
|
|
50
50
|
|
|
51
51
|
declare type AnyStyle = any;
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Call QuantaRoute's autocomplete API.
|
|
55
|
+
* Minimum 3 characters required; max 10 suggestions.
|
|
56
|
+
*
|
|
57
|
+
* Pass userLat / userLng (the map pin's current position) to unlock:
|
|
58
|
+
* – Location-biased results (~50 km soft radius around the pin)
|
|
59
|
+
* – "Near me" / "nearby" keyword support with a tight ~10 km hard radius
|
|
60
|
+
*/
|
|
61
|
+
export declare function autocompleteAddress(query: string, apiKey: string, baseUrl?: string, limit?: number, userLat?: number, userLng?: number): Promise<AutocompleteSuggestion[]>;
|
|
62
|
+
|
|
63
|
+
export declare interface AutocompleteResponse {
|
|
64
|
+
success: boolean;
|
|
65
|
+
data: AutocompleteSuggestion[];
|
|
66
|
+
error?: string;
|
|
67
|
+
message?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** One address suggestion from /v1/digipin/autocomplete */
|
|
71
|
+
export declare interface AutocompleteSuggestion {
|
|
72
|
+
displayName: string;
|
|
73
|
+
address: string;
|
|
74
|
+
coordinates: {
|
|
75
|
+
latitude: number;
|
|
76
|
+
longitude: number;
|
|
77
|
+
};
|
|
78
|
+
confidence: number;
|
|
79
|
+
addressComponents: {
|
|
80
|
+
house_number?: string;
|
|
81
|
+
road?: string;
|
|
82
|
+
neighbourhood?: string;
|
|
83
|
+
suburb?: string;
|
|
84
|
+
city?: string;
|
|
85
|
+
state?: string;
|
|
86
|
+
postcode?: string;
|
|
87
|
+
country?: string;
|
|
88
|
+
[key: string]: string | undefined;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
53
92
|
/**
|
|
54
93
|
* QuantaRoute Checkout Widget
|
|
55
94
|
*
|
|
@@ -97,6 +136,13 @@ export declare interface CheckoutWidgetProps {
|
|
|
97
136
|
* Example: indiaBoundaryUrl="/geojson/india.geojson"
|
|
98
137
|
*/
|
|
99
138
|
indiaBoundaryUrl?: string;
|
|
139
|
+
/**
|
|
140
|
+
* Show the smart search bar on the map step (default: true).
|
|
141
|
+
* Supports address search (API) and DigiPin lookup (100% offline).
|
|
142
|
+
* As India Post promotes DigiPin, buyers can just type their 10-char code
|
|
143
|
+
* and the map instantly flies to their ~4m × 4m location — zero API cost.
|
|
144
|
+
*/
|
|
145
|
+
enableSearch?: boolean;
|
|
100
146
|
}
|
|
101
147
|
|
|
102
148
|
export declare interface CompleteAddress {
|
|
@@ -200,6 +246,12 @@ export declare interface LocationLookupResponse {
|
|
|
200
246
|
message?: string;
|
|
201
247
|
}
|
|
202
248
|
|
|
249
|
+
/**
|
|
250
|
+
* Returns true if the trimmed input looks like a complete DigiPin code.
|
|
251
|
+
* Used to skip the API call and resolve offline instead.
|
|
252
|
+
*/
|
|
253
|
+
export declare function looksLikeDigiPin(input: string): boolean;
|
|
254
|
+
|
|
203
255
|
/**
|
|
204
256
|
* Call QuantaRoute's Location Lookup API.
|
|
205
257
|
* Converts lat/lng → full Indian administrative address + DigiPin.
|
|
@@ -223,6 +275,18 @@ export declare interface MapPinSelectorProps {
|
|
|
223
275
|
* Example: indiaBoundaryUrl="/geojson/india.geojson"
|
|
224
276
|
*/
|
|
225
277
|
indiaBoundaryUrl?: string;
|
|
278
|
+
/**
|
|
279
|
+
* Show the search bar above the map (default: true).
|
|
280
|
+
* Supports two modes automatically:
|
|
281
|
+
* – Address search → calls /v1/digipin/autocomplete (debounced 400ms)
|
|
282
|
+
* – DigiPin input → decoded offline, zero API call, instant flyTo
|
|
283
|
+
* Pass apiKey to enable address search. DigiPin search always works offline.
|
|
284
|
+
*/
|
|
285
|
+
enableSearch?: boolean;
|
|
286
|
+
/** Required when enableSearch is true — used to call the autocomplete API. */
|
|
287
|
+
apiKey?: string;
|
|
288
|
+
/** API base URL for autocomplete. Defaults to https://api.quantaroute.com */
|
|
289
|
+
apiBaseUrl?: string;
|
|
226
290
|
}
|
|
227
291
|
|
|
228
292
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @quantaroute/checkout v1.
|
|
2
|
+
* @quantaroute/checkout v1.3.1
|
|
3
3
|
* (c) 2026 QuantaRoute – https://quantaroute.com
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* expo-location >= 17.0.0
|
|
20
20
|
*/
|
|
21
21
|
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
22
|
-
import { useState, useCallback, useRef, useEffect, useReducer, useMemo } from "react";
|
|
22
|
+
import { useState, useCallback, useRef, useId, useEffect, useReducer, useMemo } from "react";
|
|
23
23
|
import maplibregl from "maplibre-gl";
|
|
24
24
|
const DIGIPIN_GRID = [
|
|
25
25
|
["F", "C", "9", "8"],
|
|
@@ -122,6 +122,127 @@ function isValidDigiPin(digiPin) {
|
|
|
122
122
|
function isWithinIndia(lat, lon) {
|
|
123
123
|
return lat >= BOUNDS.minLat && lat <= BOUNDS.maxLat && lon >= BOUNDS.minLon && lon <= BOUNDS.maxLon;
|
|
124
124
|
}
|
|
125
|
+
const DEFAULT_BASE_URL = "https://api.quantaroute.com";
|
|
126
|
+
const DIGIPIN_PATTERN = /^[FC98J327K456LMPT]{3}-[FC98J327K456LMPT]{3}-[FC98J327K456LMPT]{4}$/i;
|
|
127
|
+
function makeTimeoutSignal(ms) {
|
|
128
|
+
if (typeof AbortSignal !== "undefined" && typeof AbortSignal.timeout === "function") {
|
|
129
|
+
return AbortSignal.timeout(ms);
|
|
130
|
+
}
|
|
131
|
+
const ctrl = new AbortController();
|
|
132
|
+
setTimeout(() => ctrl.abort(), ms);
|
|
133
|
+
return ctrl.signal;
|
|
134
|
+
}
|
|
135
|
+
async function lookupLocation(lat, lng, apiKey, baseUrl = DEFAULT_BASE_URL) {
|
|
136
|
+
const url = `${baseUrl.replace(/\/$/, "")}/v1/location/lookup`;
|
|
137
|
+
let res;
|
|
138
|
+
try {
|
|
139
|
+
res = await fetch(url, {
|
|
140
|
+
method: "POST",
|
|
141
|
+
headers: {
|
|
142
|
+
"Content-Type": "application/json",
|
|
143
|
+
"x-api-key": apiKey
|
|
144
|
+
},
|
|
145
|
+
body: JSON.stringify({ latitude: lat, longitude: lng }),
|
|
146
|
+
signal: makeTimeoutSignal(15e3)
|
|
147
|
+
});
|
|
148
|
+
} catch (err) {
|
|
149
|
+
if (err instanceof Error && (err.name === "TimeoutError" || err.name === "AbortError")) {
|
|
150
|
+
throw new Error("Request timed out. Check your internet connection.");
|
|
151
|
+
}
|
|
152
|
+
throw new Error(`Network error: ${err instanceof Error ? err.message : String(err)}`);
|
|
153
|
+
}
|
|
154
|
+
if (!res.ok) {
|
|
155
|
+
let body = "";
|
|
156
|
+
try {
|
|
157
|
+
body = await res.text();
|
|
158
|
+
} catch {
|
|
159
|
+
}
|
|
160
|
+
if (res.status === 401 || res.status === 403) {
|
|
161
|
+
throw new Error("Invalid API key. Check your QuantaRoute API key.");
|
|
162
|
+
}
|
|
163
|
+
if (res.status === 429) {
|
|
164
|
+
throw new Error("Rate limit exceeded. Upgrade your plan or try again later.");
|
|
165
|
+
}
|
|
166
|
+
throw new Error(`API error ${res.status}: ${body || res.statusText}`);
|
|
167
|
+
}
|
|
168
|
+
const data = await res.json();
|
|
169
|
+
if (!data.success) {
|
|
170
|
+
throw new Error(data.message ?? "Location lookup failed");
|
|
171
|
+
}
|
|
172
|
+
return data;
|
|
173
|
+
}
|
|
174
|
+
function looksLikeDigiPin(input) {
|
|
175
|
+
return DIGIPIN_PATTERN.test(input.trim().toUpperCase());
|
|
176
|
+
}
|
|
177
|
+
async function autocompleteAddress(query, apiKey, baseUrl = DEFAULT_BASE_URL, limit = 5, userLat, userLng) {
|
|
178
|
+
let url = `${baseUrl.replace(/\/$/, "")}/v1/digipin/autocomplete?q=${encodeURIComponent(query.trim())}&limit=${Math.min(limit, 10)}`;
|
|
179
|
+
if (typeof userLat === "number" && typeof userLng === "number") {
|
|
180
|
+
url += `&lat=${userLat.toFixed(6)}&lng=${userLng.toFixed(6)}`;
|
|
181
|
+
}
|
|
182
|
+
let res;
|
|
183
|
+
try {
|
|
184
|
+
res = await fetch(url, {
|
|
185
|
+
method: "GET",
|
|
186
|
+
headers: { "x-api-key": apiKey },
|
|
187
|
+
signal: makeTimeoutSignal(8e3)
|
|
188
|
+
});
|
|
189
|
+
} catch (err) {
|
|
190
|
+
if (err instanceof Error && (err.name === "TimeoutError" || err.name === "AbortError")) {
|
|
191
|
+
throw new Error("Autocomplete request timed out.");
|
|
192
|
+
}
|
|
193
|
+
throw new Error(`Network error: ${err instanceof Error ? err.message : String(err)}`);
|
|
194
|
+
}
|
|
195
|
+
if (!res.ok) {
|
|
196
|
+
if (res.status === 401 || res.status === 403) {
|
|
197
|
+
throw new Error("Invalid API key.");
|
|
198
|
+
}
|
|
199
|
+
if (res.status === 429) {
|
|
200
|
+
throw new Error("Rate limit exceeded.");
|
|
201
|
+
}
|
|
202
|
+
return [];
|
|
203
|
+
}
|
|
204
|
+
const data = await res.json();
|
|
205
|
+
return data.success ? data.data ?? [] : [];
|
|
206
|
+
}
|
|
207
|
+
async function reverseGeocode(digipin, apiKey, baseUrl = DEFAULT_BASE_URL) {
|
|
208
|
+
const url = `${baseUrl.replace(/\/$/, "")}/v1/digipin/reverse`;
|
|
209
|
+
let res;
|
|
210
|
+
try {
|
|
211
|
+
res = await fetch(url, {
|
|
212
|
+
method: "POST",
|
|
213
|
+
headers: {
|
|
214
|
+
"Content-Type": "application/json",
|
|
215
|
+
"x-api-key": apiKey
|
|
216
|
+
},
|
|
217
|
+
body: JSON.stringify({ digipin }),
|
|
218
|
+
signal: makeTimeoutSignal(15e3)
|
|
219
|
+
});
|
|
220
|
+
} catch (err) {
|
|
221
|
+
if (err instanceof Error && (err.name === "TimeoutError" || err.name === "AbortError")) {
|
|
222
|
+
throw new Error("Request timed out. Check your internet connection.");
|
|
223
|
+
}
|
|
224
|
+
throw new Error(`Network error: ${err instanceof Error ? err.message : String(err)}`);
|
|
225
|
+
}
|
|
226
|
+
if (!res.ok) {
|
|
227
|
+
let body = "";
|
|
228
|
+
try {
|
|
229
|
+
body = await res.text();
|
|
230
|
+
} catch {
|
|
231
|
+
}
|
|
232
|
+
if (res.status === 401 || res.status === 403) {
|
|
233
|
+
throw new Error("Invalid API key. Check your QuantaRoute API key.");
|
|
234
|
+
}
|
|
235
|
+
if (res.status === 429) {
|
|
236
|
+
throw new Error("Rate limit exceeded. Upgrade your plan or try again later.");
|
|
237
|
+
}
|
|
238
|
+
throw new Error(`API error ${res.status}: ${body || res.statusText}`);
|
|
239
|
+
}
|
|
240
|
+
const data = await res.json();
|
|
241
|
+
if (!data.success) {
|
|
242
|
+
throw new Error(data.message ?? "Reverse geocoding failed");
|
|
243
|
+
}
|
|
244
|
+
return data;
|
|
245
|
+
}
|
|
125
246
|
function useGeolocation() {
|
|
126
247
|
const [state, setState] = useState({ loading: false, error: null });
|
|
127
248
|
const locate = useCallback((onSuccess) => {
|
|
@@ -224,8 +345,10 @@ const MapPinSelector = ({
|
|
|
224
345
|
defaultLng,
|
|
225
346
|
mapHeight = "380px",
|
|
226
347
|
theme: _theme = "light",
|
|
227
|
-
|
|
228
|
-
|
|
348
|
+
indiaBoundaryUrl,
|
|
349
|
+
enableSearch = true,
|
|
350
|
+
apiKey,
|
|
351
|
+
apiBaseUrl
|
|
229
352
|
}) => {
|
|
230
353
|
const containerRef = useRef(null);
|
|
231
354
|
const mapRef = useRef(null);
|
|
@@ -239,10 +362,90 @@ const MapPinSelector = ({
|
|
|
239
362
|
() => computeDigiPinSafe(initLat, initLng)
|
|
240
363
|
);
|
|
241
364
|
const [mapLoaded, setMapLoaded] = useState(false);
|
|
365
|
+
const [searchQuery, setSearchQuery] = useState("");
|
|
366
|
+
const [suggestions, setSuggestions] = useState([]);
|
|
367
|
+
const [searchLoading, setSearchLoading] = useState(false);
|
|
368
|
+
const [searchError, setSearchError] = useState(null);
|
|
369
|
+
const [dropdownOpen, setDropdownOpen] = useState(false);
|
|
370
|
+
const debounceRef = useRef(null);
|
|
371
|
+
const searchInputRef = useRef(null);
|
|
372
|
+
const listboxId = useId();
|
|
242
373
|
const { loading: geoLoading, error: geoError, locate, clearError } = useGeolocation();
|
|
243
374
|
const refreshDigipin = useCallback((la, lo) => {
|
|
244
375
|
setDigipin(computeDigiPinSafe(la, lo));
|
|
245
376
|
}, []);
|
|
377
|
+
const flyToCoord = useCallback((la, lo) => {
|
|
378
|
+
var _a;
|
|
379
|
+
setLat(la);
|
|
380
|
+
setLng(lo);
|
|
381
|
+
refreshDigipin(la, lo);
|
|
382
|
+
if (mapRef.current) {
|
|
383
|
+
mapRef.current.flyTo({ center: [lo, la], zoom: STREET_ZOOM, duration: 900, essential: true });
|
|
384
|
+
}
|
|
385
|
+
(_a = markerRef.current) == null ? void 0 : _a.setLngLat([lo, la]);
|
|
386
|
+
}, [refreshDigipin]);
|
|
387
|
+
const handleSearchChange = useCallback((e) => {
|
|
388
|
+
const value = e.target.value;
|
|
389
|
+
setSearchQuery(value);
|
|
390
|
+
setSearchError(null);
|
|
391
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
392
|
+
const trimmed = value.trim();
|
|
393
|
+
if (!trimmed) {
|
|
394
|
+
setSuggestions([]);
|
|
395
|
+
setDropdownOpen(false);
|
|
396
|
+
setSearchLoading(false);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
if (looksLikeDigiPin(trimmed)) {
|
|
400
|
+
try {
|
|
401
|
+
const coords = getLatLngFromDigiPin(trimmed.toUpperCase());
|
|
402
|
+
const la = parseFloat(coords.latitude);
|
|
403
|
+
const lo = parseFloat(coords.longitude);
|
|
404
|
+
flyToCoord(la, lo);
|
|
405
|
+
setSuggestions([]);
|
|
406
|
+
setDropdownOpen(false);
|
|
407
|
+
setSearchQuery("");
|
|
408
|
+
} catch {
|
|
409
|
+
setSearchError("Invalid DigiPin code");
|
|
410
|
+
}
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
if (trimmed.length < 3) {
|
|
414
|
+
setSuggestions([]);
|
|
415
|
+
setDropdownOpen(false);
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
setSearchLoading(true);
|
|
419
|
+
debounceRef.current = setTimeout(async () => {
|
|
420
|
+
try {
|
|
421
|
+
const key = apiKey ?? "";
|
|
422
|
+
const results = await autocompleteAddress(trimmed, key, apiBaseUrl, 5, lat, lng);
|
|
423
|
+
setSuggestions(results);
|
|
424
|
+
setDropdownOpen(results.length > 0);
|
|
425
|
+
} catch (err) {
|
|
426
|
+
setSearchError(err instanceof Error ? err.message : "Search failed");
|
|
427
|
+
setSuggestions([]);
|
|
428
|
+
setDropdownOpen(false);
|
|
429
|
+
} finally {
|
|
430
|
+
setSearchLoading(false);
|
|
431
|
+
}
|
|
432
|
+
}, 400);
|
|
433
|
+
}, [apiKey, apiBaseUrl, flyToCoord]);
|
|
434
|
+
const handleSuggestionSelect = useCallback((s) => {
|
|
435
|
+
var _a;
|
|
436
|
+
flyToCoord(s.coordinates.latitude, s.coordinates.longitude);
|
|
437
|
+
setSearchQuery("");
|
|
438
|
+
setSuggestions([]);
|
|
439
|
+
setDropdownOpen(false);
|
|
440
|
+
(_a = searchInputRef.current) == null ? void 0 : _a.blur();
|
|
441
|
+
}, [flyToCoord]);
|
|
442
|
+
const handleSearchKeyDown = useCallback((e) => {
|
|
443
|
+
if (e.key === "Escape") {
|
|
444
|
+
setSuggestions([]);
|
|
445
|
+
setDropdownOpen(false);
|
|
446
|
+
setSearchQuery("");
|
|
447
|
+
}
|
|
448
|
+
}, []);
|
|
246
449
|
useEffect(() => {
|
|
247
450
|
if (!containerRef.current) return;
|
|
248
451
|
const boundaryPromise = indiaBoundaryUrl ? fetch(indiaBoundaryUrl).then((r) => r.ok ? r.json() : null).catch(() => null) : Promise.resolve(null);
|
|
@@ -360,6 +563,114 @@ const MapPinSelector = ({
|
|
|
360
563
|
/* @__PURE__ */ jsx("span", { className: "qr-step-sub", children: "Tap the map or drag the pin to your exact home / office" })
|
|
361
564
|
] })
|
|
362
565
|
] }),
|
|
566
|
+
enableSearch && /* @__PURE__ */ jsxs("div", { className: "qr-search-bar", role: "search", children: [
|
|
567
|
+
/* @__PURE__ */ jsxs("div", { className: "qr-search-bar__input-wrap", children: [
|
|
568
|
+
/* @__PURE__ */ jsxs(
|
|
569
|
+
"svg",
|
|
570
|
+
{
|
|
571
|
+
className: "qr-search-bar__icon",
|
|
572
|
+
"aria-hidden": "true",
|
|
573
|
+
viewBox: "0 0 24 24",
|
|
574
|
+
fill: "none",
|
|
575
|
+
stroke: "currentColor",
|
|
576
|
+
strokeWidth: "2",
|
|
577
|
+
strokeLinecap: "round",
|
|
578
|
+
strokeLinejoin: "round",
|
|
579
|
+
children: [
|
|
580
|
+
/* @__PURE__ */ jsx("circle", { cx: "11", cy: "11", r: "8" }),
|
|
581
|
+
/* @__PURE__ */ jsx("path", { d: "M21 21l-4.35-4.35" })
|
|
582
|
+
]
|
|
583
|
+
}
|
|
584
|
+
),
|
|
585
|
+
/* @__PURE__ */ jsx(
|
|
586
|
+
"input",
|
|
587
|
+
{
|
|
588
|
+
ref: searchInputRef,
|
|
589
|
+
type: "search",
|
|
590
|
+
className: "qr-search-bar__input",
|
|
591
|
+
placeholder: "Search address, 'pharmacy near me', or DigiPin…",
|
|
592
|
+
value: searchQuery,
|
|
593
|
+
onChange: handleSearchChange,
|
|
594
|
+
onKeyDown: handleSearchKeyDown,
|
|
595
|
+
autoComplete: "off",
|
|
596
|
+
autoCorrect: "off",
|
|
597
|
+
autoCapitalize: "characters",
|
|
598
|
+
spellCheck: false,
|
|
599
|
+
"aria-label": "Search address or DigiPin",
|
|
600
|
+
"aria-autocomplete": "list",
|
|
601
|
+
"aria-controls": dropdownOpen ? listboxId : void 0,
|
|
602
|
+
"aria-expanded": dropdownOpen
|
|
603
|
+
}
|
|
604
|
+
),
|
|
605
|
+
searchLoading && /* @__PURE__ */ jsx("span", { className: "qr-search-bar__spinner qr-spinner qr-spinner--sm", "aria-hidden": "true" }),
|
|
606
|
+
searchQuery && !searchLoading && /* @__PURE__ */ jsx(
|
|
607
|
+
"button",
|
|
608
|
+
{
|
|
609
|
+
type: "button",
|
|
610
|
+
className: "qr-search-bar__clear",
|
|
611
|
+
onClick: () => {
|
|
612
|
+
setSearchQuery("");
|
|
613
|
+
setSuggestions([]);
|
|
614
|
+
setDropdownOpen(false);
|
|
615
|
+
setSearchError(null);
|
|
616
|
+
},
|
|
617
|
+
"aria-label": "Clear search",
|
|
618
|
+
tabIndex: -1,
|
|
619
|
+
children: "×"
|
|
620
|
+
}
|
|
621
|
+
)
|
|
622
|
+
] }),
|
|
623
|
+
searchError && /* @__PURE__ */ jsx("p", { className: "qr-search-bar__error", role: "alert", children: searchError }),
|
|
624
|
+
dropdownOpen && suggestions.length > 0 && /* @__PURE__ */ jsx(
|
|
625
|
+
"ul",
|
|
626
|
+
{
|
|
627
|
+
id: listboxId,
|
|
628
|
+
className: "qr-search-bar__dropdown",
|
|
629
|
+
role: "listbox",
|
|
630
|
+
"aria-label": "Address suggestions",
|
|
631
|
+
children: suggestions.map((s, i) => /* @__PURE__ */ jsxs(
|
|
632
|
+
"li",
|
|
633
|
+
{
|
|
634
|
+
className: "qr-search-bar__suggestion",
|
|
635
|
+
role: "option",
|
|
636
|
+
"aria-selected": "false",
|
|
637
|
+
onMouseDown: (e) => {
|
|
638
|
+
e.preventDefault();
|
|
639
|
+
handleSuggestionSelect(s);
|
|
640
|
+
},
|
|
641
|
+
children: [
|
|
642
|
+
/* @__PURE__ */ jsxs(
|
|
643
|
+
"svg",
|
|
644
|
+
{
|
|
645
|
+
className: "qr-search-bar__suggestion-icon",
|
|
646
|
+
"aria-hidden": "true",
|
|
647
|
+
viewBox: "0 0 24 24",
|
|
648
|
+
fill: "none",
|
|
649
|
+
stroke: "currentColor",
|
|
650
|
+
strokeWidth: "1.8",
|
|
651
|
+
strokeLinecap: "round",
|
|
652
|
+
strokeLinejoin: "round",
|
|
653
|
+
children: [
|
|
654
|
+
/* @__PURE__ */ jsx("path", { d: "M12 2C8.134 2 5 5.134 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.866-3.134-7-7-7z" }),
|
|
655
|
+
/* @__PURE__ */ jsx("circle", { cx: "12", cy: "9", r: "2.5" })
|
|
656
|
+
]
|
|
657
|
+
}
|
|
658
|
+
),
|
|
659
|
+
/* @__PURE__ */ jsxs("div", { className: "qr-search-bar__suggestion-text", children: [
|
|
660
|
+
/* @__PURE__ */ jsx("span", { className: "qr-search-bar__suggestion-name", children: s.displayName }),
|
|
661
|
+
s.address && s.address !== s.displayName && /* @__PURE__ */ jsx("span", { className: "qr-search-bar__suggestion-sub", children: s.address })
|
|
662
|
+
] })
|
|
663
|
+
]
|
|
664
|
+
},
|
|
665
|
+
i
|
|
666
|
+
))
|
|
667
|
+
}
|
|
668
|
+
),
|
|
669
|
+
/* @__PURE__ */ jsxs("p", { className: "qr-search-bar__hint", children: [
|
|
670
|
+
/* @__PURE__ */ jsx("span", { className: "qr-search-bar__hint-chip", children: "DigiPin" }),
|
|
671
|
+
"Type your DigiPin code for instant offline lookup — no API call"
|
|
672
|
+
] })
|
|
673
|
+
] }),
|
|
363
674
|
/* @__PURE__ */ jsxs("div", { className: "qr-map-outer", style: { height: mapHeight }, children: [
|
|
364
675
|
/* @__PURE__ */ jsx("div", { ref: containerRef, className: "qr-map-canvas" }),
|
|
365
676
|
digipin && /* @__PURE__ */ jsxs("div", { className: "qr-digipin-badge", "aria-live": "polite", "aria-label": `DigiPin: ${digipin}`, children: [
|
|
@@ -450,93 +761,6 @@ const MapPinSelector = ({
|
|
|
450
761
|
] })
|
|
451
762
|
] });
|
|
452
763
|
};
|
|
453
|
-
const DEFAULT_BASE_URL = "https://api.quantaroute.com";
|
|
454
|
-
function makeTimeoutSignal(ms) {
|
|
455
|
-
if (typeof AbortSignal !== "undefined" && typeof AbortSignal.timeout === "function") {
|
|
456
|
-
return AbortSignal.timeout(ms);
|
|
457
|
-
}
|
|
458
|
-
const ctrl = new AbortController();
|
|
459
|
-
setTimeout(() => ctrl.abort(), ms);
|
|
460
|
-
return ctrl.signal;
|
|
461
|
-
}
|
|
462
|
-
async function lookupLocation(lat, lng, apiKey, baseUrl = DEFAULT_BASE_URL) {
|
|
463
|
-
const url = `${baseUrl.replace(/\/$/, "")}/v1/location/lookup`;
|
|
464
|
-
let res;
|
|
465
|
-
try {
|
|
466
|
-
res = await fetch(url, {
|
|
467
|
-
method: "POST",
|
|
468
|
-
headers: {
|
|
469
|
-
"Content-Type": "application/json",
|
|
470
|
-
"x-api-key": apiKey
|
|
471
|
-
},
|
|
472
|
-
body: JSON.stringify({ latitude: lat, longitude: lng }),
|
|
473
|
-
signal: makeTimeoutSignal(15e3)
|
|
474
|
-
});
|
|
475
|
-
} catch (err) {
|
|
476
|
-
if (err instanceof Error && (err.name === "TimeoutError" || err.name === "AbortError")) {
|
|
477
|
-
throw new Error("Request timed out. Check your internet connection.");
|
|
478
|
-
}
|
|
479
|
-
throw new Error(`Network error: ${err instanceof Error ? err.message : String(err)}`);
|
|
480
|
-
}
|
|
481
|
-
if (!res.ok) {
|
|
482
|
-
let body = "";
|
|
483
|
-
try {
|
|
484
|
-
body = await res.text();
|
|
485
|
-
} catch {
|
|
486
|
-
}
|
|
487
|
-
if (res.status === 401 || res.status === 403) {
|
|
488
|
-
throw new Error("Invalid API key. Check your QuantaRoute API key.");
|
|
489
|
-
}
|
|
490
|
-
if (res.status === 429) {
|
|
491
|
-
throw new Error("Rate limit exceeded. Upgrade your plan or try again later.");
|
|
492
|
-
}
|
|
493
|
-
throw new Error(`API error ${res.status}: ${body || res.statusText}`);
|
|
494
|
-
}
|
|
495
|
-
const data = await res.json();
|
|
496
|
-
if (!data.success) {
|
|
497
|
-
throw new Error(data.message ?? "Location lookup failed");
|
|
498
|
-
}
|
|
499
|
-
return data;
|
|
500
|
-
}
|
|
501
|
-
async function reverseGeocode(digipin, apiKey, baseUrl = DEFAULT_BASE_URL) {
|
|
502
|
-
const url = `${baseUrl.replace(/\/$/, "")}/v1/digipin/reverse`;
|
|
503
|
-
let res;
|
|
504
|
-
try {
|
|
505
|
-
res = await fetch(url, {
|
|
506
|
-
method: "POST",
|
|
507
|
-
headers: {
|
|
508
|
-
"Content-Type": "application/json",
|
|
509
|
-
"x-api-key": apiKey
|
|
510
|
-
},
|
|
511
|
-
body: JSON.stringify({ digipin }),
|
|
512
|
-
signal: makeTimeoutSignal(15e3)
|
|
513
|
-
});
|
|
514
|
-
} catch (err) {
|
|
515
|
-
if (err instanceof Error && (err.name === "TimeoutError" || err.name === "AbortError")) {
|
|
516
|
-
throw new Error("Request timed out. Check your internet connection.");
|
|
517
|
-
}
|
|
518
|
-
throw new Error(`Network error: ${err instanceof Error ? err.message : String(err)}`);
|
|
519
|
-
}
|
|
520
|
-
if (!res.ok) {
|
|
521
|
-
let body = "";
|
|
522
|
-
try {
|
|
523
|
-
body = await res.text();
|
|
524
|
-
} catch {
|
|
525
|
-
}
|
|
526
|
-
if (res.status === 401 || res.status === 403) {
|
|
527
|
-
throw new Error("Invalid API key. Check your QuantaRoute API key.");
|
|
528
|
-
}
|
|
529
|
-
if (res.status === 429) {
|
|
530
|
-
throw new Error("Rate limit exceeded. Upgrade your plan or try again later.");
|
|
531
|
-
}
|
|
532
|
-
throw new Error(`API error ${res.status}: ${body || res.statusText}`);
|
|
533
|
-
}
|
|
534
|
-
const data = await res.json();
|
|
535
|
-
if (!data.success) {
|
|
536
|
-
throw new Error(data.message ?? "Reverse geocoding failed");
|
|
537
|
-
}
|
|
538
|
-
return data;
|
|
539
|
-
}
|
|
540
764
|
const INITIAL_FIELDS = {
|
|
541
765
|
flatNumber: "",
|
|
542
766
|
floorNumber: "",
|
|
@@ -946,7 +1170,8 @@ const CheckoutWidget = ({
|
|
|
946
1170
|
style,
|
|
947
1171
|
mapHeight = "380px",
|
|
948
1172
|
title = "Add Delivery Address",
|
|
949
|
-
indiaBoundaryUrl
|
|
1173
|
+
indiaBoundaryUrl,
|
|
1174
|
+
enableSearch = true
|
|
950
1175
|
}) => {
|
|
951
1176
|
const [step, setStep] = useState("map");
|
|
952
1177
|
const [confirmedLocation, setConfirmedLocation] = useState(null);
|
|
@@ -1011,7 +1236,10 @@ const CheckoutWidget = ({
|
|
|
1011
1236
|
defaultLng,
|
|
1012
1237
|
mapHeight,
|
|
1013
1238
|
theme,
|
|
1014
|
-
indiaBoundaryUrl
|
|
1239
|
+
indiaBoundaryUrl,
|
|
1240
|
+
enableSearch,
|
|
1241
|
+
apiKey,
|
|
1242
|
+
apiBaseUrl
|
|
1015
1243
|
}
|
|
1016
1244
|
),
|
|
1017
1245
|
step === "form" && confirmedLocation && /* @__PURE__ */ jsx(
|
|
@@ -1062,11 +1290,13 @@ export {
|
|
|
1062
1290
|
CheckoutWidget,
|
|
1063
1291
|
BOUNDS as DIGIPIN_BOUNDS,
|
|
1064
1292
|
MapPinSelector,
|
|
1293
|
+
autocompleteAddress,
|
|
1065
1294
|
CheckoutWidget as default,
|
|
1066
1295
|
getDigiPin,
|
|
1067
1296
|
getLatLngFromDigiPin,
|
|
1068
1297
|
isValidDigiPin,
|
|
1069
1298
|
isWithinIndia,
|
|
1299
|
+
looksLikeDigiPin,
|
|
1070
1300
|
lookupLocation,
|
|
1071
1301
|
reverseGeocode,
|
|
1072
1302
|
useDigiPin,
|