@sanvika/geolocation 0.3.1 → 0.4.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanvika/geolocation",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Sanvika ecosystem geolocation SDK — fully centralized via geolocation.sanvikaproduction.com. IP lookup, reverse/forward geocoding, Places autocomplete + details, Maps JS loader. Zero Google API keys in consumer projects.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -17,7 +17,13 @@
17
17
  "dependencies": {
18
18
  "@sanvika/logger": ">=0.2"
19
19
  },
20
- "keywords": ["sanvika", "geolocation", "ip", "location", "india"],
20
+ "keywords": [
21
+ "sanvika",
22
+ "geolocation",
23
+ "ip",
24
+ "location",
25
+ "india"
26
+ ],
21
27
  "author": "Sanvika Production",
22
28
  "license": "UNLICENSED",
23
29
  "repository": {
@@ -27,4 +33,4 @@
27
33
  "publishConfig": {
28
34
  "access": "public"
29
35
  }
30
- }
36
+ }
@@ -1,6 +1,10 @@
1
1
  // packages/sanvika-geolocation-sdk/src/server/serviceClient.js
2
2
  // HTTP client for geolocation.sanvikaproduction.com — used by all server-side helpers.
3
- // Env vars: GEOLOCATION_URL, GEOLOCATION_CLIENT_SECRET (or pass to constructor).
3
+ // Universal S2S Auth Pattern (ecosystem rule §21):
4
+ // PROJECT_NAME — clientId
5
+ // SANVIKA_SERVICE_KEY — Tier 1 trust
6
+ // GEOLOCATION_URL (or GEO_URL) — service endpoint
7
+ // GEOLOCATION_CLIENT_SECRET — (optional, Tier 2 fallback for 3rd-party)
4
8
 
5
9
  const DEFAULT_TIMEOUT_MS = 6000;
6
10
 
@@ -14,15 +18,21 @@ function readEnv(key) {
14
18
 
15
19
  export class GeolocationServiceClient {
16
20
  #url;
21
+ #clientId;
22
+ #serviceKey;
17
23
  #secret;
18
24
 
19
- constructor({ url, secret } = {}) {
20
- const finalUrl = url || readEnv("GEOLOCATION_URL");
21
- const finalSecret = secret || readEnv("GEOLOCATION_CLIENT_SECRET");
22
- if (!finalUrl || !finalSecret) {
23
- throw new Error("@sanvika/geolocation/server: GEOLOCATION_URL and GEOLOCATION_CLIENT_SECRET are required");
25
+ constructor({ url, clientId, serviceKey, secret } = {}) {
26
+ const finalUrl = url || readEnv("GEOLOCATION_URL") || readEnv("GEO_URL");
27
+ const finalClientId = clientId || readEnv("PROJECT_NAME") || readEnv("GEOLOCATION_CLIENT_ID");
28
+ const finalServiceKey = serviceKey || readEnv("SANVIKA_SERVICE_KEY") || "";
29
+ const finalSecret = secret || readEnv("GEOLOCATION_CLIENT_SECRET") || ""; // Tier 2 fallback (optional)
30
+ if (!finalUrl || !finalClientId) {
31
+ throw new Error("@sanvika/geolocation/server: GEOLOCATION_URL and PROJECT_NAME are required");
24
32
  }
25
33
  this.#url = finalUrl.replace(/\/$/, "");
34
+ this.#clientId = finalClientId;
35
+ this.#serviceKey = finalServiceKey;
26
36
  this.#secret = finalSecret;
27
37
  }
28
38
 
@@ -35,7 +45,11 @@ export class GeolocationServiceClient {
35
45
  const qs = query ? "?" + new URLSearchParams(query).toString() : "";
36
46
  const init = {
37
47
  method,
38
- headers: { "x-client-secret": this.#secret },
48
+ headers: {
49
+ "x-client-id": this.#clientId,
50
+ "x-service-key": this.#serviceKey,
51
+ "x-client-secret": this.#secret,
52
+ },
39
53
  signal: controller.signal,
40
54
  };
41
55
  if (body !== undefined) {