@quantaroute/checkout 1.4.2 → 1.4.4

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.
@@ -12,8 +12,8 @@ import {
12
12
  import { OSMView, LocationButton } from 'expo-osm-sdk';
13
13
  import type { OSMViewRef, MarkerConfig } from 'expo-osm-sdk';
14
14
  import * as Location from 'expo-location';
15
- import { getDigiPin, getLatLngFromDigiPin, isWithinIndia } from '../core/digipin';
16
- import { autocompleteAddress, looksLikeDigiPin } from '../core/api';
15
+ import { getDigiPin, getLatLngFromDigiPin, formatDigiPin, isWithinIndia } from '../core/digipin';
16
+ import { autocompleteAddress, looksLikeDigiPin, couldBeDigiPinInput } from '../core/api';
17
17
  import type { AutocompleteSuggestion } from '../core/api';
18
18
  import type { MapPinSelectorProps } from '../core/types';
19
19
  import { styles, COLORS } from '../styles/checkout.native';
@@ -139,10 +139,10 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
139
139
  // Keep the text visible in the input; just close the keyboard and dropdown.
140
140
  if (looksLikeDigiPin(trimmed)) {
141
141
  try {
142
- const coords = getLatLngFromDigiPin(trimmed.toUpperCase());
142
+ const coords = getLatLngFromDigiPin(trimmed);
143
143
  flyToCoord(parseFloat(coords.latitude), parseFloat(coords.longitude));
144
144
  setSuggestions([]);
145
- setSearchQuery(trimmed.toUpperCase());
145
+ setSearchQuery(formatDigiPin(trimmed));
146
146
  Keyboard.dismiss();
147
147
  } catch {
148
148
  setSearchError('Invalid DigiPin code');
@@ -150,6 +150,13 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
150
150
  return;
151
151
  }
152
152
 
153
+ // Partial DigiPin — wait for full code, skip autocomplete
154
+ if (couldBeDigiPinInput(trimmed)) {
155
+ setSuggestions([]);
156
+ setSearchLoading(false);
157
+ return;
158
+ }
159
+
153
160
  if (trimmed.length < 3) {
154
161
  setSuggestions([]);
155
162
  return;
@@ -1,8 +1,8 @@
1
1
  import React, { useEffect, useRef, useState, useCallback, useId } from 'react';
2
2
  import maplibregl from 'maplibre-gl';
3
3
  import 'maplibre-gl/dist/maplibre-gl.css';
4
- import { getDigiPin, getLatLngFromDigiPin, isWithinIndia } from '../core/digipin';
5
- import { autocompleteAddress, looksLikeDigiPin } from '../core/api';
4
+ import { getDigiPin, getLatLngFromDigiPin, formatDigiPin, isWithinIndia } from '../core/digipin';
5
+ import { autocompleteAddress, looksLikeDigiPin, couldBeDigiPinInput } from '../core/api';
6
6
  import type { AutocompleteSuggestion } from '../core/api';
7
7
  import { useGeolocation } from '../hooks/useGeolocation';
8
8
  import type { MapPinSelectorProps } from '../core/types';
@@ -177,20 +177,27 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
177
177
  // Keep the text in the input so the user can see what resolved.
178
178
  if (looksLikeDigiPin(trimmed)) {
179
179
  try {
180
- const coords = getLatLngFromDigiPin(trimmed.toUpperCase());
180
+ const coords = getLatLngFromDigiPin(trimmed);
181
181
  const la = parseFloat(coords.latitude);
182
182
  const lo = parseFloat(coords.longitude);
183
183
  flyToCoord(la, lo);
184
184
  setSuggestions([]);
185
185
  setDropdownOpen(false);
186
- // normalise to canonical XX-XXX-XXXX format in case user typed without dashes
187
- setSearchQuery(trimmed.toUpperCase());
186
+ setSearchQuery(formatDigiPin(trimmed));
188
187
  } catch {
189
188
  setSearchError('Invalid DigiPin code');
190
189
  }
191
190
  return;
192
191
  }
193
192
 
193
+ // Partial DigiPin (compact/spaced/dashed) — wait for full code, skip autocomplete
194
+ if (couldBeDigiPinInput(trimmed)) {
195
+ setSuggestions([]);
196
+ setDropdownOpen(false);
197
+ setSearchLoading(false);
198
+ return;
199
+ }
200
+
194
201
  // Address search — debounce 400 ms, need ≥ 3 chars
195
202
  if (trimmed.length < 3) {
196
203
  setSuggestions([]);
@@ -32,6 +32,12 @@ function LabelIcon({ label }: { label: string }) {
32
32
  return <PinIcon />;
33
33
  }
34
34
 
35
+ function formatAddressLabel(address: SavedAddress): string {
36
+ const custom = address.label_text?.trim();
37
+ if (address.label === 'other' && custom) return custom;
38
+ return address.label.charAt(0).toUpperCase() + address.label.slice(1);
39
+ }
40
+
35
41
  // ─── Address card ─────────────────────────────────────────────────────────────
36
42
 
37
43
  interface AddressCardProps {
@@ -64,7 +70,7 @@ function AddressCard({ address, onUse, onDelete, onSetDefault, deleting }: Addre
64
70
  <LabelIcon label={address.label} />
65
71
  </div>
66
72
  <span className="qr-addr-card__label">
67
- {address.label.charAt(0).toUpperCase() + address.label.slice(1)}
73
+ {formatAddressLabel(address)}
68
74
  </span>
69
75
  {address.is_default && (
70
76
  <span className="qr-addr-card__default-badge">Default</span>
package/src/core/api.ts CHANGED
@@ -1,11 +1,8 @@
1
1
  import type { LocationLookupResponse } from './types';
2
+ import { isCompleteDigiPinInput, isPotentialDigiPinInput } from './digipin';
2
3
 
3
4
  const DEFAULT_BASE_URL = 'https://api.quantaroute.com';
4
5
 
5
- // ─── DigiPin regex (matches "XXX-XXX-XXXX" with valid characters) ─────────────
6
- // Valid chars: F C 9 8 J 3 2 7 K 4 5 6 L M P T (from the 4×4 DIGIPIN_GRID)
7
- const DIGIPIN_PATTERN = /^[FC98J327K456LMPT]{3}-[FC98J327K456LMPT]{3}-[FC98J327K456LMPT]{4}$/i;
8
-
9
6
  /**
10
7
  * Cross-platform timeout signal.
11
8
  * AbortSignal.timeout() is not available in React Native / Hermes — fall back
@@ -235,7 +232,15 @@ export interface AutocompleteResponse {
235
232
  * Used to skip the API call and resolve offline instead.
236
233
  */
237
234
  export function looksLikeDigiPin(input: string): boolean {
238
- return DIGIPIN_PATTERN.test(input.trim().toUpperCase());
235
+ return isCompleteDigiPinInput(input);
236
+ }
237
+
238
+ /**
239
+ * Returns true while the user is typing a DigiPin (compact, dashed, or spaced).
240
+ * Used to suppress address autocomplete until the code is complete or abandoned.
241
+ */
242
+ export function couldBeDigiPinInput(input: string): boolean {
243
+ return isPotentialDigiPinInput(input);
239
244
  }
240
245
 
241
246
  /**
@@ -82,6 +82,8 @@ export interface SavedAddress {
82
82
  building_name: string;
83
83
  street_name: string;
84
84
  label: string;
85
+ /** Custom display text when label is `other` */
86
+ label_text: string | null;
85
87
  is_default: boolean;
86
88
  created_at: string;
87
89
  updated_at: string;
@@ -104,6 +106,7 @@ export interface SavedAddressPayload {
104
106
  street_name?: string;
105
107
  full_address_json?: Record<string, unknown>;
106
108
  label?: string;
109
+ label_text?: string | null;
107
110
  is_default?: boolean;
108
111
  }
109
112
 
@@ -32,6 +32,40 @@ const BOUNDS = {
32
32
  maxLon: 99.5,
33
33
  };
34
34
 
35
+ /** Characters that appear in the official 4×4 DigiPin grid */
36
+ const DIGIPIN_ALPHABET = 'FC98J327K456LMPT';
37
+ const VALID_DIGIPIN_BODY = new RegExp(`^[${DIGIPIN_ALPHABET}]{10}$`, 'i');
38
+ const VALID_DIGIPIN_PREFIX = new RegExp(`^[${DIGIPIN_ALPHABET}]{1,10}$`, 'i');
39
+ /** Common separators: ASCII dash/underscore/dot plus Unicode dash variants */
40
+ const DIGIPIN_SEPARATORS = /[\s\-_\u2010-\u2015\u2212.]/g;
41
+
42
+ /**
43
+ * Normalise user input to a 10-character DigiPin body (no separators).
44
+ * Accepts dashed, spaced, or compact forms — e.g. `4P3-J68-637F`, `4P3 J68 637F`, `4P3J68637F`.
45
+ */
46
+ export function normalizeDigiPinInput(input: string): string {
47
+ return input.trim().toUpperCase().replace(DIGIPIN_SEPARATORS, '');
48
+ }
49
+
50
+ /** True when normalised input is a non-empty prefix of a DigiPin (still being typed). */
51
+ export function isPotentialDigiPinInput(input: string): boolean {
52
+ const pin = normalizeDigiPinInput(input);
53
+ return pin.length > 0 && pin.length <= 10 && VALID_DIGIPIN_PREFIX.test(pin);
54
+ }
55
+
56
+ /** Canonical display format: XXX-XXX-XXXX */
57
+ export function formatDigiPin(input: string): string {
58
+ const pin = normalizeDigiPinInput(input);
59
+ if (pin.length !== 10) return input.trim().toUpperCase();
60
+ return `${pin.slice(0, 3)}-${pin.slice(3, 6)}-${pin.slice(6)}`;
61
+ }
62
+
63
+ /** True when input is a complete 10-character DigiPin (any common separator style). */
64
+ export function isCompleteDigiPinInput(input: string): boolean {
65
+ const pin = normalizeDigiPinInput(input);
66
+ return pin.length === 10 && VALID_DIGIPIN_BODY.test(pin);
67
+ }
68
+
35
69
  export interface DigiPinCoordinates {
36
70
  latitude: string;
37
71
  longitude: string;
@@ -88,9 +122,9 @@ export function getDigiPin(lat: number, lon: number): string {
88
122
  * @throws if the DigiPin format is invalid
89
123
  */
90
124
  export function getLatLngFromDigiPin(digiPin: string): DigiPinCoordinates {
91
- const pin = digiPin.replace(/-/g, '');
125
+ const pin = normalizeDigiPinInput(digiPin);
92
126
  if (pin.length !== 10) {
93
- throw new Error('Invalid DIGIPIN: must be 10 characters (excluding dashes)');
127
+ throw new Error('Invalid DIGIPIN: must be 10 characters (excluding separators)');
94
128
  }
95
129
 
96
130
  let minLat = BOUNDS.minLat;
@@ -145,9 +179,9 @@ export function getLatLngFromDigiPin(digiPin: string): DigiPinCoordinates {
145
179
  */
146
180
  export function isValidDigiPin(digiPin: string): boolean {
147
181
  if (!digiPin || typeof digiPin !== 'string') return false;
148
- if (!/^[A-Z0-9]{3}-[A-Z0-9]{3}-[A-Z0-9]{4}$/i.test(digiPin.trim())) return false;
182
+ if (!isCompleteDigiPinInput(digiPin)) return false;
149
183
  try {
150
- getLatLngFromDigiPin(digiPin.trim().toUpperCase());
184
+ getLatLngFromDigiPin(digiPin);
151
185
  return true;
152
186
  } catch {
153
187
  return false;
package/src/core/types.ts CHANGED
@@ -91,6 +91,17 @@ export interface CompleteAddress {
91
91
  formattedAddress: string;
92
92
  /** Buyer-chosen label for saved-address book (defaults to home) */
93
93
  label?: AddressLabel;
94
+ /** Custom label text when `label` is `other` (e.g. "Friend's home") */
95
+ labelText?: string;
96
+ /** Set when the buyer re-selected an existing saved row (skip createAddress). */
97
+ addressId?: string;
98
+ }
99
+
100
+ /** Imperative hooks for host pages (e.g. Shopify pre-checkout shell). */
101
+ export interface CheckoutWidgetController {
102
+ /** Navigate one step back within the widget. Returns true if handled. */
103
+ goBack: () => boolean;
104
+ getStep: () => string;
94
105
  }
95
106
 
96
107
  // ─── Checkout event (client-side analytics hook) ─────────────────────────────
@@ -327,6 +338,11 @@ export interface CheckoutWidgetProps {
327
338
  prepaidNudgeCopy?: string;
328
339
  /** Override merchant prepaid nudge CTA URL. */
329
340
  prepaidNudgeCtaUrl?: string;
341
+ /**
342
+ * Called once on mount with imperative navigation helpers for host shells
343
+ * (step-aware back button, etc.).
344
+ */
345
+ registerController?: (controller: CheckoutWidgetController) => void;
330
346
  }
331
347
 
332
348
  // ─── Phone / OTP step props ───────────────────────────────────────────────────
package/src/index.ts CHANGED
@@ -43,6 +43,10 @@ export {
43
43
  getLatLngFromDigiPin,
44
44
  isValidDigiPin,
45
45
  isWithinIndia,
46
+ normalizeDigiPinInput,
47
+ formatDigiPin,
48
+ isCompleteDigiPinInput,
49
+ isPotentialDigiPinInput,
46
50
  DIGIPIN_BOUNDS,
47
51
  } from './core/digipin';
48
52
 
@@ -52,6 +56,7 @@ export {
52
56
  reverseGeocode,
53
57
  autocompleteAddress,
54
58
  looksLikeDigiPin,
59
+ couldBeDigiPinInput,
55
60
  validatePincode,
56
61
  pincodeHasDeliveryOffice,
57
62
  } from './core/api';
@@ -814,45 +814,106 @@
814
814
  font-size: 14px;
815
815
  }
816
816
 
817
+ .qr-fieldset__legend--compact {
818
+ padding: 10px 16px 8px;
819
+ font-size: 11px;
820
+ letter-spacing: 0.08em;
821
+ }
822
+
817
823
  .qr-label-picker {
818
- display: grid;
819
- grid-template-columns: repeat(3, 1fr);
820
- gap: 8px;
824
+ display: flex;
825
+ flex-wrap: nowrap;
826
+ gap: 6px;
821
827
  padding: 0 16px 12px;
828
+ overflow-x: auto;
829
+ -webkit-overflow-scrolling: touch;
830
+ scrollbar-width: none;
831
+ }
832
+
833
+ .qr-label-picker::-webkit-scrollbar {
834
+ display: none;
822
835
  }
823
836
 
824
837
  .qr-label-picker__option {
825
- display: flex;
826
- flex-direction: column;
838
+ display: inline-flex;
839
+ flex: 1 1 0;
840
+ flex-direction: row;
827
841
  align-items: center;
828
842
  justify-content: center;
829
- gap: 4px;
830
- min-height: 72px;
831
- padding: 10px 8px;
832
- border: 1.5px solid var(--qr-border);
833
- border-radius: 10px;
834
- background: var(--qr-bg, #fff);
843
+ gap: 6px;
844
+ min-width: 0;
845
+ min-height: 44px;
846
+ padding: 0 12px;
847
+ border: 1px solid var(--qr-border);
848
+ border-radius: 999px;
849
+ background: var(--qr-bg-subtle);
835
850
  color: var(--qr-text-muted);
836
851
  font-family: inherit;
837
852
  font-size: 13px;
838
853
  font-weight: 500;
854
+ line-height: 1;
839
855
  cursor: pointer;
840
- transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
856
+ -webkit-tap-highlight-color: transparent;
857
+ user-select: none;
858
+ transition:
859
+ background 160ms ease-out,
860
+ color 160ms ease-out,
861
+ border-color 160ms ease-out,
862
+ transform 100ms ease-out;
841
863
  }
842
864
 
843
- .qr-label-picker__option:hover:not(.qr-label-picker__option--active) {
844
- border-color: color-mix(in srgb, var(--qr-accent, var(--qr-navy)) 35%, var(--qr-border));
865
+ @media (hover: hover) and (pointer: fine) {
866
+ .qr-label-picker__option:hover:not(.qr-label-picker__option--active) {
867
+ background: color-mix(in srgb, var(--qr-border) 45%, var(--qr-bg-subtle));
868
+ border-color: color-mix(in srgb, var(--qr-primary) 28%, var(--qr-border));
869
+ }
870
+ }
871
+
872
+ .qr-label-picker__option:active {
873
+ transform: scale(0.97);
845
874
  }
846
875
 
847
876
  .qr-label-picker__option--active {
848
- border-color: var(--qr-accent, var(--qr-navy));
849
- background: color-mix(in srgb, var(--qr-accent, var(--qr-navy)) 10%, var(--qr-bg, #fff));
850
- color: var(--qr-text);
877
+ border-color: transparent;
878
+ background: var(--qr-primary-light);
879
+ color: var(--qr-primary);
880
+ font-weight: 600;
851
881
  }
852
882
 
853
883
  .qr-label-picker__icon {
854
- font-size: 18px;
855
- line-height: 1;
884
+ display: flex;
885
+ flex-shrink: 0;
886
+ align-items: center;
887
+ justify-content: center;
888
+ width: 16px;
889
+ height: 16px;
890
+ }
891
+
892
+ .qr-label-picker__icon svg {
893
+ width: 16px;
894
+ height: 16px;
895
+ }
896
+
897
+ .qr-label-text-field {
898
+ padding: 0 16px 12px;
899
+ }
900
+
901
+ .qr-label-text-field .qr-field__label {
902
+ margin-bottom: 6px;
903
+ }
904
+
905
+ .qr-label-text-field .qr-field__input {
906
+ width: 100%;
907
+ }
908
+
909
+ @media (prefers-reduced-motion: reduce) {
910
+ .qr-label-picker__option {
911
+ transition: background 160ms ease, color 160ms ease, border-color 160ms ease;
912
+ }
913
+
914
+ .qr-label-picker__option:active {
915
+ transform: none;
916
+ }
856
917
  }
857
918
 
858
919
  /* ── Auto-filled grid ────────────────────────────────────── */
@@ -1409,9 +1470,14 @@
1409
1470
  .qr-locate-btn,
1410
1471
  .qr-field__input,
1411
1472
  .qr-progress__dot,
1412
- .qr-progress__line {
1473
+ .qr-progress__line,
1474
+ .qr-label-picker__option {
1413
1475
  transition: none;
1414
1476
  }
1477
+
1478
+ .qr-label-picker__option:active {
1479
+ transform: none;
1480
+ }
1415
1481
  }
1416
1482
 
1417
1483
  /* ── Focus visible (keyboard nav) ────────────────────────── */
@@ -567,6 +567,14 @@ export const styles = StyleSheet.create({
567
567
  sectionHeaderTextDark: {
568
568
  color: COLORS.textMutedDark,
569
569
  },
570
+ sectionHeaderCompact: {
571
+ paddingTop: 10,
572
+ paddingBottom: 8,
573
+ },
574
+ sectionHeaderTextCompact: {
575
+ fontSize: 11,
576
+ letterSpacing: 1,
577
+ },
570
578
  sectionDivider: {
571
579
  height: 1,
572
580
  backgroundColor: COLORS.border,
@@ -724,38 +732,36 @@ export const styles = StyleSheet.create({
724
732
  // ── Address label picker ────────────────────────────────────────────────────
725
733
  labelPicker: {
726
734
  flexDirection: 'row',
727
- gap: 8,
735
+ gap: 6,
728
736
  paddingHorizontal: 16,
729
737
  paddingBottom: 12,
730
738
  },
731
739
  labelPickerOption: {
732
740
  flex: 1,
741
+ flexDirection: 'row',
733
742
  alignItems: 'center',
734
743
  justifyContent: 'center',
735
- gap: 4,
736
- minHeight: 72,
737
- paddingVertical: 10,
738
- paddingHorizontal: 8,
739
- borderWidth: 1.5,
744
+ gap: 6,
745
+ minHeight: 44,
746
+ paddingVertical: 0,
747
+ paddingHorizontal: 12,
748
+ borderWidth: 1,
740
749
  borderColor: COLORS.border,
741
- borderRadius: 10,
742
- backgroundColor: COLORS.bg,
750
+ borderRadius: 999,
751
+ backgroundColor: COLORS.bgSubtle,
743
752
  },
744
753
  labelPickerOptionDark: {
745
754
  borderColor: COLORS.borderDark,
746
- backgroundColor: COLORS.bgDark,
755
+ backgroundColor: COLORS.bgSubtleDark,
747
756
  },
748
757
  labelPickerOptionActive: {
749
- borderColor: COLORS.primary,
758
+ borderColor: 'transparent',
750
759
  backgroundColor: COLORS.primaryLight,
751
760
  },
752
761
  labelPickerOptionActiveDark: {
753
- borderColor: COLORS.primary,
762
+ borderColor: 'transparent',
754
763
  backgroundColor: '#0c4a6e33',
755
764
  },
756
- labelPickerIcon: {
757
- fontSize: 18,
758
- },
759
765
  labelPickerText: {
760
766
  fontSize: 13,
761
767
  fontWeight: '500',
@@ -765,9 +771,13 @@ export const styles = StyleSheet.create({
765
771
  color: COLORS.textMutedDark,
766
772
  },
767
773
  labelPickerTextActive: {
768
- color: COLORS.text,
774
+ color: COLORS.primary,
769
775
  fontWeight: '600',
770
776
  },
777
+ labelTextField: {
778
+ paddingHorizontal: 16,
779
+ paddingBottom: 12,
780
+ },
771
781
 
772
782
  // ── Manual fields ───────────────────────────────────────────────────────────
773
783
  fieldsGrid: {