@geophrase/core 1.3.1 → 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 +25 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The core vanilla JavaScript library for Geophrase Connect. Drop the Geophrase address selector into any web checkout in minutes and capture perfectly structured Indian addresses and coordinates to reduce Return to Origin (RTO) costs.
|
|
4
4
|
|
|
5
|
-
👉 **[Full documentation and integration guide](https://business.geophrase.com/docs)**
|
|
5
|
+
👉 **[Full documentation and integration guide](https://business.geophrase.com/docs/vanilla-js)**
|
|
6
6
|
|
|
7
7
|
*Building a React or Next.js app? Use [`@geophrase/react`](https://www.npmjs.com/package/@geophrase/react) instead. It wraps this core library in native hooks.*
|
|
8
8
|
|
|
@@ -28,7 +28,7 @@ import Geophrase from '@geophrase/core';
|
|
|
28
28
|
|
|
29
29
|
## Quick Start
|
|
30
30
|
|
|
31
|
-
The snippet below uses `mode: 'server'` so you can paste it into an HTML file and see the widget
|
|
31
|
+
The snippet below uses `mode: 'server'` so you can paste it into an HTML file and see the widget without creating an API key first.
|
|
32
32
|
|
|
33
33
|
```html
|
|
34
34
|
<button id="geophrase-btn">Select Delivery Address</button>
|
|
@@ -56,12 +56,15 @@ The snippet below uses `mode: 'server'` so you can paste it into an HTML file an
|
|
|
56
56
|
The SDK supports two modes. Pick whichever fits your architecture:
|
|
57
57
|
|
|
58
58
|
- **`server`**: the widget returns `{ token }`. Your backend exchanges it for the full address using your API key, which never touches the frontend.
|
|
59
|
-
- **`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).
|
|
60
59
|
|
|
61
|
-
|
|
60
|
+
- **`client`**: the widget resolves the address in the browser and passes it straight to `onSuccess`. Requires `key` in the SDK options.
|
|
61
|
+
|
|
62
|
+
> Both modes require a Geophrase API key. See [creating and securing an API key](https://business.geophrase.com/docs/api-keys).
|
|
63
|
+
>
|
|
64
|
+
> 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.
|
|
62
65
|
|
|
63
66
|
```javascript
|
|
64
|
-
// client mode, no backend required
|
|
67
|
+
// client mode, no backend integration required
|
|
65
68
|
const geo = new Geophrase({
|
|
66
69
|
mode: 'client',
|
|
67
70
|
key: 'YOUR_API_KEY',
|
|
@@ -71,26 +74,27 @@ const geo = new Geophrase({
|
|
|
71
74
|
|
|
72
75
|
## Configuration Options
|
|
73
76
|
|
|
74
|
-
| Parameter
|
|
75
|
-
|
|
|
76
|
-
| `mode`
|
|
77
|
-
| `key`
|
|
78
|
-
| `theme`
|
|
79
|
-
| `orderId`
|
|
80
|
-
| `phone`
|
|
81
|
-
| `onSuccess` | `function` | **Yes**
|
|
82
|
-
| `onError`
|
|
83
|
-
| `onClose`
|
|
77
|
+
| Parameter | Type | Required | Description |
|
|
78
|
+
| :---------- | :--------- | :-------------- | :----------------------------------------------------------- |
|
|
79
|
+
| `mode` | `string` | Optional | `'client'` (default) or `'server'`. Determines the architectural flow of the SDK. |
|
|
80
|
+
| `key` | `string` | **Conditional** | Your [Geophrase API key](https://business.geophrase.com/docs/api-keys). **Required if `mode` is `'client'`.** Omit if using server mode. |
|
|
81
|
+
| `theme` | `string` | Optional | `'light'`, `'dark'`, or `'system'`. Defaults to `'system'`. |
|
|
82
|
+
| `orderId` | `string` | Optional | Your internal reference ID for this checkout session. |
|
|
83
|
+
| `phone` | `string` | Optional | The customer's 10-digit phone number (pre-fills the widget). |
|
|
84
|
+
| `onSuccess` | `function` | **Yes** | Called upon completion. Returns an `Address` object (`mode: 'client'`) or a `Token` object (`mode: 'server'`). |
|
|
85
|
+
| `onError` | `function` | Optional | Called if the API fails or a network error occurs. Returns an `Error` object. |
|
|
86
|
+
| `onClose` | `function` | Optional | Called when the user closes the modal without completing the flow. |
|
|
84
87
|
|
|
85
88
|
## API
|
|
86
89
|
|
|
87
|
-
| Method
|
|
88
|
-
|
|
|
90
|
+
| Method | Description |
|
|
91
|
+
| :----------------------- | :----------------------------------------------------------- |
|
|
89
92
|
| `new Geophrase(options)` | Create an instance. Pre-computes the widget URL; safe to construct at module scope. |
|
|
90
|
-
| `.open()`
|
|
91
|
-
| `.close()`
|
|
92
|
-
|
|
93
|
+
| `.open()` | Open the modal. Idempotent. |
|
|
94
|
+
| `.close()` | Close the modal without firing `onSuccess`. |
|
|
95
|
+
|
|
96
|
+
The underlying `Geophrase` instance is created on mount and destroyed on unmount automatically, so you do not need to call `destroy()` manually.
|
|
93
97
|
|
|
94
98
|
TypeScript definitions (`GeophraseOptions`, `GeophraseAddress`, `GeophraseToken`, `GeophraseError`) ship with the package.
|
|
95
99
|
|
|
96
|
-
See the [full docs](https://business.geophrase.com/docs) for the complete configuration reference, security guidance, and response schemas.
|
|
100
|
+
See the [full docs](https://business.geophrase.com/docs/vanilla-js) for the complete configuration reference, security guidance, and response schemas.
|
package/package.json
CHANGED