@geophrase/core 1.7.0 → 1.8.0

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/README.md CHANGED
@@ -42,7 +42,7 @@ The snippet below uses `mode: 'server'`, which needs only your API key id — no
42
42
  mode: 'server', // widget returns a token your backend exchanges for the address
43
43
  theme: 'system', // 'light' | 'dark' | 'system'
44
44
  orderId: 'ORD-98765', // your internal reference id
45
- phone: '9999999999', // pre-fill the customer phone
45
+ phone: '9999999999', // prefills the phone field
46
46
 
47
47
  onSuccess: (result) => console.log('Success:', result),
48
48
  onError: (error) => console.error('Error:', error.message),
@@ -85,8 +85,9 @@ const geo = new Geophrase({
85
85
  | `key` | `string` | **Conditional** | Your secret [Geophrase API key](https://geophrase.com/docs/api-keys). **Required if `mode` is `'client'`.** Omit if using server mode. |
86
86
  | `theme` | `string` | Optional | `'light'`, `'dark'`, or `'system'`. Defaults to `'system'`. |
87
87
  | `orderId` | `string` | Optional | Your internal reference ID for this checkout session. |
88
+ | `hubCode` | `string` | **Conditional** | Delivery hub code (from Settings > Delivery hubs). Client mode only; required when `mode` is `'client'` and your business has more than one active delivery hub. In server mode, send `hub_code` from your backend to the [resolve call](https://geophrase.com/docs/resolve-endpoint). |
88
89
  | `noteForAgent` | `string` | Optional | Note shown to your delivery agent, never to the customer. Client mode only; notes over 300 characters are cut. It is sent from the customer's device, so the customer can change it; send payment instructions, such as cash to collect, from your server or the dashboard. In server mode, send `note_for_agent` with your [resolve call](https://geophrase.com/docs/resolve-endpoint). |
89
- | `phone` | `string` | Optional | The customer's 10-digit phone number (pre-fills the widget). |
90
+ | `phone` | `string` | Optional | Pre-fills the phone field with a 10-digit Indian mobile number. |
90
91
  | `onSuccess` | `function` | **Yes** | Called upon completion. Returns an `Address` object (`mode: 'client'`) or a `Token` object (`mode: 'server'`). |
91
92
  | `onError` | `function` | Optional | Called if the API fails or a network error occurs. Returns an `Error` object. |
92
93
  | `onClose` | `function` | Optional | Called when the user closes the modal without completing the flow. |
package/index.d.ts CHANGED
@@ -13,12 +13,18 @@ export interface GeophraseAddressDetails {
13
13
  verified_mobile_num: string;
14
14
  }
15
15
 
16
+ export interface GeophraseHub {
17
+ name: string;
18
+ code: string;
19
+ }
20
+
16
21
  export interface GeophraseAddress {
17
22
  short_code: string;
18
23
  short_link: string;
19
24
  qr_code: string;
20
25
  captured_at: number;
21
26
  order_id: string;
27
+ hub?: GeophraseHub;
22
28
  address: GeophraseAddressDetails;
23
29
  }
24
30
 
@@ -37,6 +43,7 @@ export interface GeophraseOptions {
37
43
  mode?: 'client' | 'server';
38
44
  theme?: 'light' | 'dark' | 'system';
39
45
  key?: string;
46
+ hubCode?: string;
40
47
  orderId?: string;
41
48
  noteForAgent?: string;
42
49
  phone?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geophrase/core",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "Drop-in address picker widget for Indian e-commerce checkouts. Captures structured addresses with coordinates to reduce RTO.",
5
5
  "license": "MIT",
6
6
  "author": "Geophrase",
package/src/index.js CHANGED
@@ -1,3 +1,14 @@
1
+ function extractApiErrorMessage(errorData, fallback) {
2
+ if (!errorData || typeof errorData !== 'object') return fallback;
3
+ if (typeof errorData.message === 'string' && errorData.message) return errorData.message;
4
+ if (typeof errorData.detail === 'string' && errorData.detail) return errorData.detail;
5
+ for (const value of Object.values(errorData)) {
6
+ if (Array.isArray(value) && value.length > 0 && typeof value[0] === 'string') return value[0];
7
+ if (typeof value === 'string' && value) return value;
8
+ }
9
+ return fallback;
10
+ }
11
+
1
12
  class Geophrase {
2
13
  static _instanceCounter = 0;
3
14
 
@@ -36,6 +47,7 @@ class Geophrase {
36
47
 
37
48
  this.keyId = options.keyId;
38
49
  this.apiKey = this.mode === 'client' ? options.key : null;
50
+ this.hubCode = options.hubCode;
39
51
  this.orderId = options.orderId;
40
52
  this.noteForAgent = options.noteForAgent;
41
53
  this.phone = options.phone;
@@ -336,6 +348,9 @@ class Geophrase {
336
348
  let callback = null;
337
349
 
338
350
  const payload = { request_id: data.requestId };
351
+ if (this.hubCode != null && String(this.hubCode).trim()) {
352
+ payload.hub_code = String(this.hubCode).trim();
353
+ }
339
354
  if (this.orderId) payload.order_id = this.orderId;
340
355
  // Cut to the API's limit: a longer note would fail the whole address capture.
341
356
  if (this.noteForAgent) payload.note_for_agent = String(this.noteForAgent).slice(0, 300);
@@ -356,7 +371,7 @@ class Geophrase {
356
371
  callback = () => this._safeCall(this.onError, {
357
372
  type: 'API_ERROR',
358
373
  status: response.status,
359
- message: errorData.message || 'Geophrase API resolution failed'
374
+ message: extractApiErrorMessage(errorData, 'Geophrase API resolution failed')
360
375
  });
361
376
  } else {
362
377
  const responseData = await response.json();