@quantaroute/checkout 1.4.3 → 1.4.5

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.
@@ -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
 
@@ -302,6 +305,59 @@ export async function checkCodEligibility(
302
305
  return data.data as CodEligibilityResult;
303
306
  }
304
307
 
308
+ // ─── Merchant serviceability (courier / 3PL pincode check) ───────────────────
309
+
310
+ export interface ServiceabilityResult {
311
+ /** Whether a merchant serviceability endpoint was configured and enabled. */
312
+ enabled: boolean;
313
+ /** Whether the merchant endpoint returned a definitive response. */
314
+ checked: boolean;
315
+ /** true/false when checked, null when disabled or failed open. */
316
+ serviceable: boolean | null;
317
+ /** Normalized 6-digit pincode when valid; otherwise the trimmed input. */
318
+ pincode: string;
319
+ /** Buyer-facing merchant message, when supplied by the merchant endpoint. */
320
+ message?: string;
321
+ /** Whether the widget should block address submission when not serviceable. */
322
+ block_checkout: boolean;
323
+ /** Whether the merchant wants the soft India Post info banner as fallback. */
324
+ show_india_post_delivery_warning: boolean;
325
+ /** Present when the endpoint was skipped or failed open. */
326
+ reason?:
327
+ | 'not_configured'
328
+ | 'invalid_pincode'
329
+ | 'merchant_error'
330
+ | 'merchant_unreachable'
331
+ | 'invalid_response';
332
+ }
333
+
334
+ /**
335
+ * Check merchant courier serviceability for a pincode.
336
+ * Uses the merchant's configured webhook on checkout.merchants and fails open.
337
+ */
338
+ export async function checkServiceability(
339
+ config: CheckoutApiConfig,
340
+ sessionToken: string,
341
+ pincode: string,
342
+ coords?: { lat?: number; lng?: number }
343
+ ): Promise<ServiceabilityResult> {
344
+ const res = await fetch(`${config.functionBaseUrl}/checkout-addresses`, {
345
+ method: 'POST',
346
+ headers: addressHeaders(sessionToken),
347
+ body: JSON.stringify({
348
+ action: 'serviceability_check',
349
+ pincode,
350
+ ...(coords?.lat !== undefined ? { lat: coords.lat } : {}),
351
+ ...(coords?.lng !== undefined ? { lng: coords.lng } : {}),
352
+ }),
353
+ });
354
+ const data = await res.json().catch(() => ({}));
355
+ if (!res.ok || !data.success) {
356
+ throw new Error(data.error ?? 'Failed to check delivery serviceability.');
357
+ }
358
+ return data.data as ServiceabilityResult;
359
+ }
360
+
305
361
  // ─── Funnel events (server-side analytics) ────────────────────────────────────
306
362
 
307
363
  export interface FunnelEventPayload {
@@ -35,13 +35,22 @@ const BOUNDS = {
35
35
  /** Characters that appear in the official 4×4 DigiPin grid */
36
36
  const DIGIPIN_ALPHABET = 'FC98J327K456LMPT';
37
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;
38
41
 
39
42
  /**
40
43
  * Normalise user input to a 10-character DigiPin body (no separators).
41
44
  * Accepts dashed, spaced, or compact forms — e.g. `4P3-J68-637F`, `4P3 J68 637F`, `4P3J68637F`.
42
45
  */
43
46
  export function normalizeDigiPinInput(input: string): string {
44
- return input.trim().toUpperCase().replace(/[\s\-_.]/g, '');
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);
45
54
  }
46
55
 
47
56
  /** Canonical display format: XXX-XXX-XXXX */
package/src/core/types.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { ReactNode } from 'react';
2
2
  import type { UtmParams } from './utm';
3
- import type { SessionContextPayload } from './checkout-api';
3
+ import type { CheckoutApiConfig, ServiceabilityResult, SessionContextPayload } from './checkout-api';
4
4
 
5
5
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
6
  type AnyStyle = any; // CSSProperties on web · StyleProp<ViewStyle> on native
@@ -91,6 +91,8 @@ 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;
94
96
  /** Set when the buyer re-selected an existing saved row (skip createAddress). */
95
97
  addressId?: string;
96
98
  }
@@ -205,6 +207,18 @@ export interface AddressFormProps {
205
207
  onBack: () => void;
206
208
  onError?: (error: Error) => void;
207
209
  theme?: 'light' | 'dark';
210
+ /** Checkout API config for merchant serviceability checks. */
211
+ checkoutConfig?: CheckoutApiConfig;
212
+ /** Buyer session token used by checkout-addresses serviceability_check. */
213
+ serviceabilitySessionToken?: string;
214
+ /** When true, calls the merchant courier serviceability endpoint after pincode validation. */
215
+ enableServiceabilityCheck?: boolean;
216
+ /** Shows a soft India Post home-delivery info banner when merchant check is absent/failed. */
217
+ showIndiaPostDeliveryWarning?: boolean;
218
+ /** Optional client override for blocking address save when merchant says not serviceable. */
219
+ serviceabilityBlockCheckout?: boolean;
220
+ /** Optional observer for the merchant serviceability result. */
221
+ onServiceabilityResult?: (result: ServiceabilityResult) => void;
208
222
  }
209
223
 
210
224
  export interface CheckoutWidgetProps {
@@ -280,6 +294,21 @@ export interface CheckoutWidgetProps {
280
294
  * `checkout.merchants.enable_cod` and optional D1/D2 columns.
281
295
  */
282
296
  enableCod?: boolean;
297
+ /**
298
+ * Call the merchant's courier serviceability webhook for the resolved pincode.
299
+ * Requires `merchantId`, `supabaseFunctionBaseUrl`, and an authenticated checkout session.
300
+ */
301
+ enableServiceabilityCheck?: boolean;
302
+ /**
303
+ * Opt-in fallback banner for India Post "Non Delivery" pincodes.
304
+ * Defaults off because courier partners may still deliver.
305
+ */
306
+ showIndiaPostDeliveryWarning?: boolean;
307
+ /**
308
+ * Client override: block address save when merchant serviceability says not deliverable.
309
+ * If omitted, the server result from checkout.merchants.serviceability_block_checkout is used.
310
+ */
311
+ serviceabilityBlockCheckout?: boolean;
283
312
  /**
284
313
  * Cart total in paise for the COD cart cap (D2). Omit if the cart total is unknown.
285
314
  */
package/src/index.ts CHANGED
@@ -46,6 +46,7 @@ export {
46
46
  normalizeDigiPinInput,
47
47
  formatDigiPin,
48
48
  isCompleteDigiPinInput,
49
+ isPotentialDigiPinInput,
49
50
  DIGIPIN_BOUNDS,
50
51
  } from './core/digipin';
51
52
 
@@ -55,6 +56,7 @@ export {
55
56
  reverseGeocode,
56
57
  autocompleteAddress,
57
58
  looksLikeDigiPin,
59
+ couldBeDigiPinInput,
58
60
  validatePincode,
59
61
  pincodeHasDeliveryOffice,
60
62
  } from './core/api';
@@ -70,6 +72,7 @@ export {
70
72
  deleteAddress,
71
73
  setDefaultAddress,
72
74
  checkCodEligibility,
75
+ checkServiceability,
73
76
  notifyAddressCompleted,
74
77
  logFunnelEvent,
75
78
  notifySessionAbandoned,
@@ -87,6 +90,7 @@ export type {
87
90
  SavedAddress,
88
91
  SavedAddressPayload,
89
92
  CodEligibilityResult,
93
+ ServiceabilityResult,
90
94
  SessionContextPayload,
91
95
  FunnelEventPayload,
92
96
  SessionOffer,
@@ -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) ────────────────────────── */
@@ -1857,10 +1923,39 @@
1857
1923
  border-color: rgba(245, 158, 11, 0.35);
1858
1924
  }
1859
1925
 
1926
+ .qr-pincode-banner--error {
1927
+ background: rgba(239, 68, 68, 0.1);
1928
+ border: 1px solid rgba(239, 68, 68, 0.38);
1929
+ color: var(--qr-text);
1930
+ }
1931
+
1932
+ .qr-checkout--dark .qr-pincode-banner--error {
1933
+ background: rgba(239, 68, 68, 0.14);
1934
+ border-color: rgba(239, 68, 68, 0.34);
1935
+ }
1936
+
1937
+ .qr-pincode-banner--info {
1938
+ background: color-mix(in srgb, var(--qr-primary) 9%, transparent);
1939
+ border: 1px solid color-mix(in srgb, var(--qr-primary) 28%, transparent);
1940
+ color: var(--qr-text);
1941
+ }
1942
+
1943
+ .qr-checkout--dark .qr-pincode-banner--info {
1944
+ background: color-mix(in srgb, var(--qr-primary) 13%, transparent);
1945
+ border-color: color-mix(in srgb, var(--qr-primary) 26%, transparent);
1946
+ }
1947
+
1860
1948
  .qr-pincode-banner__icon {
1861
1949
  flex-shrink: 0;
1950
+ display: inline-flex;
1951
+ align-items: center;
1952
+ justify-content: center;
1953
+ width: 18px;
1954
+ height: 18px;
1955
+ border-radius: 999px;
1862
1956
  font-size: 16px;
1863
1957
  line-height: 1.2;
1958
+ font-weight: 700;
1864
1959
  }
1865
1960
 
1866
1961
  .qr-pincode-banner__text {
@@ -519,13 +519,38 @@ export const styles = StyleSheet.create({
519
519
  borderWidth: 1,
520
520
  borderColor: 'rgba(245, 158, 11, 0.45)',
521
521
  },
522
+ pincodeBannerWarning: {
523
+ backgroundColor: 'rgba(245, 158, 11, 0.12)',
524
+ borderColor: 'rgba(245, 158, 11, 0.45)',
525
+ },
522
526
  pincodeBannerDark: {
523
527
  backgroundColor: 'rgba(245, 158, 11, 0.15)',
524
528
  borderColor: 'rgba(245, 158, 11, 0.35)',
525
529
  },
530
+ pincodeBannerError: {
531
+ backgroundColor: 'rgba(239, 68, 68, 0.1)',
532
+ borderColor: 'rgba(239, 68, 68, 0.38)',
533
+ },
534
+ pincodeBannerErrorDark: {
535
+ backgroundColor: 'rgba(239, 68, 68, 0.14)',
536
+ borderColor: 'rgba(239, 68, 68, 0.34)',
537
+ },
538
+ pincodeBannerInfo: {
539
+ backgroundColor: 'rgba(14, 165, 233, 0.09)',
540
+ borderColor: 'rgba(14, 165, 233, 0.28)',
541
+ },
542
+ pincodeBannerInfoDark: {
543
+ backgroundColor: 'rgba(14, 165, 233, 0.13)',
544
+ borderColor: 'rgba(14, 165, 233, 0.26)',
545
+ },
526
546
  pincodeBannerIcon: {
547
+ width: 18,
548
+ height: 18,
549
+ borderRadius: 9,
550
+ textAlign: 'center',
527
551
  fontSize: 16,
528
552
  lineHeight: 20,
553
+ fontWeight: '700',
529
554
  },
530
555
  pincodeBannerTitle: {
531
556
  fontSize: 13,
@@ -567,6 +592,14 @@ export const styles = StyleSheet.create({
567
592
  sectionHeaderTextDark: {
568
593
  color: COLORS.textMutedDark,
569
594
  },
595
+ sectionHeaderCompact: {
596
+ paddingTop: 10,
597
+ paddingBottom: 8,
598
+ },
599
+ sectionHeaderTextCompact: {
600
+ fontSize: 11,
601
+ letterSpacing: 1,
602
+ },
570
603
  sectionDivider: {
571
604
  height: 1,
572
605
  backgroundColor: COLORS.border,
@@ -724,38 +757,36 @@ export const styles = StyleSheet.create({
724
757
  // ── Address label picker ────────────────────────────────────────────────────
725
758
  labelPicker: {
726
759
  flexDirection: 'row',
727
- gap: 8,
760
+ gap: 6,
728
761
  paddingHorizontal: 16,
729
762
  paddingBottom: 12,
730
763
  },
731
764
  labelPickerOption: {
732
765
  flex: 1,
766
+ flexDirection: 'row',
733
767
  alignItems: 'center',
734
768
  justifyContent: 'center',
735
- gap: 4,
736
- minHeight: 72,
737
- paddingVertical: 10,
738
- paddingHorizontal: 8,
739
- borderWidth: 1.5,
769
+ gap: 6,
770
+ minHeight: 44,
771
+ paddingVertical: 0,
772
+ paddingHorizontal: 12,
773
+ borderWidth: 1,
740
774
  borderColor: COLORS.border,
741
- borderRadius: 10,
742
- backgroundColor: COLORS.bg,
775
+ borderRadius: 999,
776
+ backgroundColor: COLORS.bgSubtle,
743
777
  },
744
778
  labelPickerOptionDark: {
745
779
  borderColor: COLORS.borderDark,
746
- backgroundColor: COLORS.bgDark,
780
+ backgroundColor: COLORS.bgSubtleDark,
747
781
  },
748
782
  labelPickerOptionActive: {
749
- borderColor: COLORS.primary,
783
+ borderColor: 'transparent',
750
784
  backgroundColor: COLORS.primaryLight,
751
785
  },
752
786
  labelPickerOptionActiveDark: {
753
- borderColor: COLORS.primary,
787
+ borderColor: 'transparent',
754
788
  backgroundColor: '#0c4a6e33',
755
789
  },
756
- labelPickerIcon: {
757
- fontSize: 18,
758
- },
759
790
  labelPickerText: {
760
791
  fontSize: 13,
761
792
  fontWeight: '500',
@@ -765,9 +796,13 @@ export const styles = StyleSheet.create({
765
796
  color: COLORS.textMutedDark,
766
797
  },
767
798
  labelPickerTextActive: {
768
- color: COLORS.text,
799
+ color: COLORS.primary,
769
800
  fontWeight: '600',
770
801
  },
802
+ labelTextField: {
803
+ paddingHorizontal: 16,
804
+ paddingBottom: 12,
805
+ },
771
806
 
772
807
  // ── Manual fields ───────────────────────────────────────────────────────────
773
808
  fieldsGrid: {