@geophrase/react 1.3.0 → 1.3.2
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 +42 -6
- 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
|
|
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 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: '
|
|
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',
|
|
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,42 @@ 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 SDK options.
|
|
54
|
+
|
|
55
|
+
> Both modes require a Geophrase API key. See [creating and securing an API key](https://business.geophrase.com/docs/api-keys).
|
|
56
|
+
>
|
|
57
|
+
> 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.
|
|
58
|
+
|
|
59
|
+
```jsx
|
|
60
|
+
// client mode, no backend integration required
|
|
61
|
+
const { open } = useGeophrase({
|
|
62
|
+
mode: 'client',
|
|
63
|
+
key: 'YOUR_API_KEY',
|
|
64
|
+
onSuccess: (address) => setResult(address)
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Configuration Options
|
|
69
|
+
|
|
70
|
+
| Parameter | Type | Required | Description |
|
|
71
|
+
| :--- | :--- | :--- | :--- |
|
|
72
|
+
| `mode` | `string` | Optional | `'client'` (default) or `'server'`. Determines the architectural flow of the SDK. |
|
|
73
|
+
| `key` | `string` | **Conditional** | Your [Geophrase API key](https://business.geophrase.com/docs/api-keys). **Required if `mode` is `'client'`.** Omit if using server mode. |
|
|
74
|
+
| `theme` | `string` | Optional | `'light'`, `'dark'`, or `'system'`. Defaults to `'system'`. |
|
|
75
|
+
| `orderId` | `string` | Optional | Your internal reference ID for this checkout session. |
|
|
76
|
+
| `phone` | `string` | Optional | The customer's 10-digit phone number (pre-fills the widget). |
|
|
77
|
+
| `onSuccess` | `function` | **Yes** | Called upon completion. Returns an `Address` object (`mode: 'client'`) or a `Token` object (`mode: 'server'`). |
|
|
78
|
+
| `onError` | `function` | Optional | Called if the API fails or a network error occurs. Returns an `Error` object. |
|
|
79
|
+
| `onClose` | `function` | Optional | Called when the user closes the modal without completing the flow. |
|
|
80
|
+
|
|
47
81
|
### Next.js (App Router)
|
|
48
82
|
|
|
49
|
-
The component calling `useGeophrase` relies on browser APIs, so it must be a **Client Component
|
|
83
|
+
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
84
|
|
|
51
85
|
### TypeScript
|
|
52
86
|
|
|
@@ -65,4 +99,6 @@ const [result, setResult] = useState<GeophraseAddress | GeophraseToken | null>(n
|
|
|
65
99
|
| `open()` | Opens the modal. Safe to wire directly to a button's `onClick`. |
|
|
66
100
|
| `close()` | Closes the modal without firing `onSuccess`. |
|
|
67
101
|
|
|
68
|
-
The underlying `Geophrase` instance is created on mount and destroyed on unmount automatically
|
|
102
|
+
The underlying `Geophrase` instance is created on mount and destroyed on unmount automatically, so you do not need to call `destroy()` manually.
|
|
103
|
+
|
|
104
|
+
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.
|
|
3
|
+
"version": "1.3.2",
|
|
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": "
|
|
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.
|
|
47
|
+
"@geophrase/core": "^1.3.2"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|