@geophrase/core 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 +49 -13
- 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
|
-
👉 **[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
|
-
*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 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,15 +51,50 @@ 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
|
+
|
|
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.
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
// client mode, no backend integration required
|
|
68
|
+
const geo = new Geophrase({
|
|
69
|
+
mode: 'client',
|
|
70
|
+
key: 'YOUR_API_KEY',
|
|
71
|
+
onSuccess: (address) => console.log('Address:', address)
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Configuration Options
|
|
76
|
+
|
|
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. |
|
|
54
87
|
|
|
55
88
|
## API
|
|
56
89
|
|
|
57
|
-
| Method
|
|
58
|
-
|
|
|
90
|
+
| Method | Description |
|
|
91
|
+
| :----------------------- | :----------------------------------------------------------- |
|
|
59
92
|
| `new Geophrase(options)` | Create an instance. Pre-computes the widget URL; safe to construct at module scope. |
|
|
60
|
-
| `.open()`
|
|
61
|
-
| `.close()`
|
|
62
|
-
|
|
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.
|
|
63
97
|
|
|
64
98
|
TypeScript definitions (`GeophraseOptions`, `GeophraseAddress`, `GeophraseToken`, `GeophraseError`) ship with the package.
|
|
99
|
+
|
|
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
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geophrase/core",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
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"
|