@geophrase/core 1.5.1 β†’ 1.6.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 CHANGED
@@ -4,6 +4,8 @@ The core vanilla JavaScript library for Geophrase Connect. Drop the Geophrase ad
4
4
 
5
5
  πŸ‘‰ **[Full documentation and integration guide](https://geophrase.com/docs/vanilla-js)**
6
6
 
7
+ πŸ—ΊοΈ **[How GPS address capture works with couriers or your own riders](https://geophrase.com/features/gps-address-capture)**
8
+
7
9
  *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
10
 
9
11
  ---
@@ -28,7 +30,7 @@ import Geophrase from '@geophrase/core';
28
30
 
29
31
  ## Quick Start
30
32
 
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.
33
+ The snippet below uses `mode: 'server'`, which needs only your API key id β€” no secret API key. Drop it into an HTML file, swap in your own `keyId`, and the widget runs.
32
34
 
33
35
  ```html
34
36
  <button id="geophrase-btn">Select Delivery Address</button>
@@ -36,6 +38,7 @@ The snippet below uses `mode: 'server'` so you can paste it into an HTML file an
36
38
  <script>
37
39
  document.addEventListener('DOMContentLoaded', function () {
38
40
  const geo = new Geophrase({
41
+ keyId: 'YOUR_API_KEY_ID', // required β€” your API key id (both modes)
39
42
  mode: 'server', // widget returns a token your backend exchanges for the address
40
43
  theme: 'system', // 'light' | 'dark' | 'system'
41
44
  orderId: 'ORD-98765', // your internal reference id
@@ -59,13 +62,14 @@ The SDK supports two modes. Pick whichever fits your architecture:
59
62
 
60
63
  - **`client`**: the widget resolves the address in the browser and passes it straight to `onSuccess`. Requires `key` in the SDK options.
61
64
 
62
- > Both modes require a Geophrase API key. See [creating and securing an API key](https://geophrase.com/docs/api-keys).
65
+ > Every integration requires your API key id (`keyId`) in the SDK options β€” it identifies your account to the widget. On top of that, `client` mode needs your secret API key (`key`) in the browser, while `server` mode uses that secret only on your backend. See [creating and securing an API key](https://geophrase.com/docs/api-keys).
63
66
  >
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.
67
+ > If your app has a backend, `server` mode keeps your secret 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
68
 
66
69
  ```javascript
67
70
  // client mode, no backend integration required
68
71
  const geo = new Geophrase({
72
+ keyId: 'YOUR_API_KEY_ID',
69
73
  mode: 'client',
70
74
  key: 'YOUR_API_KEY',
71
75
  onSuccess: (address) => console.log('Address:', address)
@@ -76,8 +80,9 @@ const geo = new Geophrase({
76
80
 
77
81
  | Parameter | Type | Required | Description |
78
82
  | :---------- | :--------- | :-------------- | :----------------------------------------------------------- |
83
+ | `keyId` | `string` | **Yes** | Your 8-character [Geophrase API key id](https://geophrase.com/docs/api-keys). Required in **both** modes; sent to the widget to identify your account. |
79
84
  | `mode` | `string` | Optional | `'client'` (default) or `'server'`. Determines the architectural flow of the SDK. |
80
- | `key` | `string` | **Conditional** | Your [Geophrase API key](https://geophrase.com/docs/api-keys). **Required if `mode` is `'client'`.** Omit if using server mode. |
85
+ | `key` | `string` | **Conditional** | Your secret [Geophrase API key](https://geophrase.com/docs/api-keys). **Required if `mode` is `'client'`.** Omit if using server mode. |
81
86
  | `theme` | `string` | Optional | `'light'`, `'dark'`, or `'system'`. Defaults to `'system'`. |
82
87
  | `orderId` | `string` | Optional | Your internal reference ID for this checkout session. |
83
88
  | `phone` | `string` | Optional | The customer's 10-digit phone number (pre-fills the widget). |
package/index.d.ts CHANGED
@@ -33,6 +33,7 @@ export interface GeophraseError {
33
33
  }
34
34
 
35
35
  export interface GeophraseOptions {
36
+ keyId: string;
36
37
  mode?: 'client' | 'server';
37
38
  theme?: 'light' | 'dark' | 'system';
38
39
  key?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geophrase/core",
3
- "version": "1.5.1",
3
+ "version": "1.6.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",
package/src/index.js CHANGED
@@ -14,10 +14,18 @@ class Geophrase {
14
14
  // 1. Mode validation
15
15
  this.mode = options.mode || 'client';
16
16
  if (!['client', 'server'].includes(this.mode)) {
17
- throw new Error(`Geophrase: Invalid mode '${this.mode}'. Expected 'client' or 'server'.`);
17
+ throw new Error(`Geophrase Error: Invalid mode '${this.mode}'. Expected 'client' or 'server'.`);
18
18
  }
19
19
 
20
- // 2. API key validation
20
+ // 2. Key ID validation β€” required in every mode; the widget needs it to identify the merchant.
21
+ if (!options.keyId) {
22
+ throw new Error("Geophrase Error: 'keyId' is required.");
23
+ }
24
+ if (typeof options.keyId !== 'string' || options.keyId.length !== 8) {
25
+ throw new Error("Geophrase Error: 'keyId' must be an 8-character string.");
26
+ }
27
+
28
+ // 3. API key validation
21
29
  if (this.mode === 'client' && !options.key) {
22
30
  throw new Error("Geophrase Error: 'key' is required when mode is 'client'.");
23
31
  }
@@ -26,11 +34,12 @@ class Geophrase {
26
34
  console.warn("Geophrase Warning: 'key' is ignored when mode is 'server'. Ensure you are not exposing a Secret Key in your frontend.");
27
35
  }
28
36
 
37
+ this.keyId = options.keyId;
29
38
  this.apiKey = this.mode === 'client' ? options.key : null;
30
39
  this.orderId = options.orderId;
31
40
  this.phone = options.phone;
32
41
 
33
- // 3. Theme validation
42
+ // 4. Theme validation
34
43
  this.theme = options.theme;
35
44
  if (this.theme && !['light', 'dark', 'system'].includes(this.theme)) {
36
45
  console.warn(`Geophrase Warning: Invalid theme '${this.theme}'. Falling back to default.`);
@@ -41,13 +50,13 @@ class Geophrase {
41
50
  this.onError = options.onError;
42
51
  this.onClose = options.onClose;
43
52
 
44
- // 4. Per-instance DOM IDs so multiple instances don't collide
53
+ // 5. Per-instance DOM IDs so multiple instances don't collide
45
54
  const instanceId = ++Geophrase._instanceCounter;
46
55
  this.iframeId = `geophrase-iframe-${instanceId}`;
47
56
  this.overlayId = `geophrase-overlay-${instanceId}`;
48
57
  this.styleId = `geophrase-styles-${instanceId}`;
49
58
 
50
- // 5. Endpoints (undocumented override for staging)
59
+ // 6. Endpoints (undocumented override for staging)
51
60
  const endpoints = options._endpoints || {};
52
61
  this.widgetOrigin = endpoints.widgetOrigin || 'https://connect.geophrase.com';
53
62
  this.apiBase = endpoints.apiBase || 'https://api.geophrase.com';
@@ -57,8 +66,9 @@ class Geophrase {
57
66
  // null when not applied; an object of saved values otherwise.
58
67
  this._savedHostState = null;
59
68
 
60
- // 6. Pre-compute the secure widget URL
69
+ // 7. Pre-compute the secure widget URL
61
70
  const url = new URL(this.widgetOrigin);
71
+ url.searchParams.append('key-id', this.keyId);
62
72
  if (this.phone) url.searchParams.append('phone', this.phone);
63
73
  if (this.theme) url.searchParams.append('theme', this.theme);
64
74
  this.widgetUrl = url.toString();