@geophrase/core 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.
- package/README.md +39 -7
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# @geophrase/core
|
|
2
2
|
|
|
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
|
|
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
5
|
👉 **[Full documentation and integration guide](https://business.geophrase.com/docs)**
|
|
6
6
|
|
|
7
|
-
*Building a React or Next.js app? Use [`@geophrase/react`](https://www.npmjs.com/package/@geophrase/react) instead
|
|
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
|
|
|
9
9
|
---
|
|
10
10
|
|
|
11
11
|
## Install
|
|
12
12
|
|
|
13
|
-
The fastest path is to include the hosted script directly
|
|
13
|
+
The fastest path is to include the hosted script directly. No build step, no bundler:
|
|
14
14
|
|
|
15
15
|
```html
|
|
16
16
|
<script src="https://connect.geophrase.com/v1/geophrase.js"></script>
|
|
@@ -28,16 +28,17 @@ 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 end-to-end **without creating an API key first**.
|
|
32
|
+
|
|
31
33
|
```html
|
|
32
34
|
<button id="geophrase-btn">Select Delivery Address</button>
|
|
33
35
|
|
|
34
36
|
<script>
|
|
35
37
|
document.addEventListener('DOMContentLoaded', function () {
|
|
36
38
|
const geo = new Geophrase({
|
|
37
|
-
mode: '
|
|
38
|
-
key: 'YOUR_API_KEY', // required when mode is 'client'
|
|
39
|
+
mode: 'server', // widget returns a token your backend exchanges for the address
|
|
39
40
|
theme: 'system', // 'light' | 'dark' | 'system'
|
|
40
|
-
orderId: 'ORD-98765',
|
|
41
|
+
orderId: 'ORD-98765', // your internal reference id
|
|
41
42
|
phone: '9999999999', // pre-fill the customer phone
|
|
42
43
|
|
|
43
44
|
onSuccess: (result) => console.log('Success:', result),
|
|
@@ -50,7 +51,36 @@ import Geophrase from '@geophrase/core';
|
|
|
50
51
|
</script>
|
|
51
52
|
```
|
|
52
53
|
|
|
53
|
-
|
|
54
|
+
## Server vs Client Mode
|
|
55
|
+
|
|
56
|
+
The SDK supports two modes. Pick whichever fits your architecture:
|
|
57
|
+
|
|
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
|
+
|
|
61
|
+
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
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
// client mode, no backend required
|
|
65
|
+
const geo = new Geophrase({
|
|
66
|
+
mode: 'client',
|
|
67
|
+
key: 'YOUR_API_KEY',
|
|
68
|
+
onSuccess: (address) => console.log('Address:', address)
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Configuration Options
|
|
73
|
+
|
|
74
|
+
| Parameter | Type | Required | Description |
|
|
75
|
+
| :--- | :--- | :--- | :--- |
|
|
76
|
+
| `mode` | `string` | Optional | `'client'` (default) or `'server'`. Determines the architectural flow of the SDK. |
|
|
77
|
+
| `key` | `string` | **Conditional** | Your Geophrase API key. **Required if `mode` is `'client'`.** Omit if using server mode. |
|
|
78
|
+
| `theme` | `string` | Optional | `'light'`, `'dark'`, or `'system'`. Defaults to `'system'`. |
|
|
79
|
+
| `orderId` | `string` | Optional | Your internal reference ID for this checkout session. |
|
|
80
|
+
| `phone` | `string` | Optional | The customer's 10-digit phone number (pre-fills the widget). |
|
|
81
|
+
| `onSuccess` | `function` | **Yes** | Called upon completion. Returns an `Address` object (`mode: 'client'`) or a `Token` object (`mode: 'server'`). |
|
|
82
|
+
| `onError` | `function` | Optional | Called if the API fails or a network error occurs. Returns an `Error` object. |
|
|
83
|
+
| `onClose` | `function` | Optional | Called when the user closes the modal without completing the flow. |
|
|
54
84
|
|
|
55
85
|
## API
|
|
56
86
|
|
|
@@ -62,3 +92,5 @@ In `client` mode, `onSuccess` receives the fully resolved `GeophraseAddress`. In
|
|
|
62
92
|
| `.destroy()` | Remove all DOM, listeners, and callbacks. Call this when your component unmounts. |
|
|
63
93
|
|
|
64
94
|
TypeScript definitions (`GeophraseOptions`, `GeophraseAddress`, `GeophraseToken`, `GeophraseError`) ship with the package.
|
|
95
|
+
|
|
96
|
+
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/core",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
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",
|
|
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"
|