@geophrase/react 1.3.0 → 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.
Files changed (2) hide show
  1. package/README.md +40 -6
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @geophrase/react
2
2
 
3
- The official React and Next.js hook for Geophrase Connect. Drop the Geophrase address selector into any React checkout in minutes and capture perfectly structured Indian addresses and coordinates to eliminate Return to Origin (RTO) costs.
3
+ The official React and Next.js hook for Geophrase Connect. Drop the Geophrase address selector into any React checkout in minutes and capture perfectly structured Indian addresses and coordinates to reduce Return to Origin (RTO) costs.
4
4
 
5
5
  👉 **[Full documentation and integration guide](https://business.geophrase.com/docs)**
6
6
 
@@ -16,6 +16,8 @@ npm install @geophrase/react
16
16
 
17
17
  ## Quick Start
18
18
 
19
+ The snippet below uses `mode: 'server'` so you can drop it into any React app and see the widget end-to-end **without creating an API key first**.
20
+
19
21
  ```jsx
20
22
  import { useState } from 'react';
21
23
  import { useGeophrase } from '@geophrase/react';
@@ -24,10 +26,9 @@ export default function Checkout() {
24
26
  const [result, setResult] = useState(null);
25
27
 
26
28
  const { open } = useGeophrase({
27
- mode: 'client', // 'client' (default) or 'server'
28
- key: 'YOUR_API_KEY', // required when mode is 'client'
29
+ mode: 'server', // widget returns a token your backend exchanges for the address
29
30
  theme: 'system', // 'light' | 'dark' | 'system'
30
- orderId: 'ORD-98765', // your internal reference id
31
+ orderId: 'ORD-98765', // your internal reference id
31
32
  phone: '9999999999', // pre-fill the customer phone
32
33
 
33
34
  onSuccess: (data) => setResult(data),
@@ -44,9 +45,40 @@ export default function Checkout() {
44
45
  }
45
46
  ```
46
47
 
48
+ ## Server vs Client Mode
49
+
50
+ The SDK supports two modes. Pick whichever fits your architecture:
51
+
52
+ - **`server`**: the widget returns `{ token }`. Your backend exchanges it for the full address using your API key, which never touches the frontend.
53
+ - **`client`**: the widget resolves the address in the browser and passes it straight to `onSuccess`. Requires `key` in the options. You should restrict that key to your domain(s) in the [Geophrase Business Dashboard](https://business.geophrase.com).
54
+
55
+ If your app has a backend, `server` mode keeps your API key entirely off the frontend, which is the most secure option. If you don't have a backend (or want the fastest possible integration), `client` mode with a domain-restricted key is fine.
56
+
57
+ ```jsx
58
+ // client mode, no backend required
59
+ const { open } = useGeophrase({
60
+ mode: 'client',
61
+ key: 'YOUR_API_KEY',
62
+ onSuccess: (address) => setResult(address)
63
+ });
64
+ ```
65
+
66
+ ## Configuration Options
67
+
68
+ | Parameter | Type | Required | Description |
69
+ | :--- | :--- | :--- | :--- |
70
+ | `mode` | `string` | Optional | `'client'` (default) or `'server'`. Determines the architectural flow of the SDK. |
71
+ | `key` | `string` | **Conditional** | Your Geophrase API key. **Required if `mode` is `'client'`.** Omit if using server mode. |
72
+ | `theme` | `string` | Optional | `'light'`, `'dark'`, or `'system'`. Defaults to `'system'`. |
73
+ | `orderId` | `string` | Optional | Your internal reference ID for this checkout session. |
74
+ | `phone` | `string` | Optional | The customer's 10-digit phone number (pre-fills the widget). |
75
+ | `onSuccess` | `function` | **Yes** | Called upon completion. Returns an `Address` object (`mode: 'client'`) or a `Token` object (`mode: 'server'`). |
76
+ | `onError` | `function` | Optional | Called if the API fails or a network error occurs. Returns an `Error` object. |
77
+ | `onClose` | `function` | Optional | Called when the user closes the modal without completing the flow. |
78
+
47
79
  ### Next.js (App Router)
48
80
 
49
- The component calling `useGeophrase` relies on browser APIs, so it must be a **Client Component** — add `"use client";` at the top of the file.
81
+ The component calling `useGeophrase` relies on browser APIs, so it must be a **Client Component**. Add `"use client";` at the top of the file.
50
82
 
51
83
  ### TypeScript
52
84
 
@@ -65,4 +97,6 @@ const [result, setResult] = useState<GeophraseAddress | GeophraseToken | null>(n
65
97
  | `open()` | Opens the modal. Safe to wire directly to a button's `onClick`. |
66
98
  | `close()` | Closes the modal without firing `onSuccess`. |
67
99
 
68
- The underlying `Geophrase` instance is created on mount and destroyed on unmount automatically — you do not need to call `destroy()` manually. See the [full docs](https://business.geophrase.com/docs) for the complete configuration reference, security guidance, and response schemas.
100
+ The underlying `Geophrase` instance is created on mount and destroyed on unmount automatically, so you do not need to call `destroy()` manually.
101
+
102
+ See the [full docs](https://business.geophrase.com/docs) for the complete configuration reference, security guidance, and response schemas.
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@geophrase/react",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "React & Next.js hook for the Geophrase address picker. Drop-in widget that captures structured Indian addresses with coordinates to reduce RTO.",
5
5
  "license": "MIT",
6
6
  "author": "Geophrase",
7
7
  "homepage": "https://business.geophrase.com/docs",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "git+https://github.com/geophrase/geophrase-js.git"
10
+ "url": "https://github.com/geophrase/geophrase-js.git"
11
11
  },
12
12
  "bugs": {
13
13
  "url": "https://github.com/geophrase/geophrase-js/issues"
@@ -44,7 +44,7 @@
44
44
  "react": ">=16.8.0"
45
45
  },
46
46
  "dependencies": {
47
- "@geophrase/core": "^1.3.0"
47
+ "@geophrase/core": "^1.3.1"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public"