@sanvika/geolocation 0.4.0 → 0.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanvika/geolocation",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
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",
@@ -15,7 +15,10 @@
15
15
  "README.md"
16
16
  ],
17
17
  "dependencies": {
18
- "@sanvika/logger": ">=0.2"
18
+ "@sanvika/geolocation": "0.5.0",
19
+ "@sanvika/lang": "0.6.0",
20
+ "@sanvika/logger": ">=0.2",
21
+ "@sanvika/realtime": "0.7.0"
19
22
  },
20
23
  "keywords": [
21
24
  "sanvika",
@@ -33,4 +36,4 @@
33
36
  "publishConfig": {
34
37
  "access": "public"
35
38
  }
36
- }
39
+ }
@@ -4,11 +4,11 @@
4
4
  //
5
5
  // Env vars (read from process.env in Next.js / similar):
6
6
  // NEXT_PUBLIC_GEOLOCATION_URL=https://geolocation.sanvikaproduction.com
7
- // NEXT_PUBLIC_GEOLOCATION_CLIENT_ID=fapk
7
+ // NEXT_PUBLIC_CLIENT_ID=<slug> (universal)
8
+ // (fallback) NEXT_PUBLIC_GEOLOCATION_CLIENT_ID
8
9
  //
9
10
  // Consumer projects NO LONGER need proxy routes for geolocation.
10
11
  // All calls go directly to geolocation.sanvikaproduction.com via public clientId auth.
11
- // Only getUserLocation / updateUserLocation still need FAPK routes (they use SA SSO auth).
12
12
 
13
13
  import { createLogger } from "@sanvika/logger";
14
14
  import { setWithTTL, getWithTTL, TTL } from "./localStorageTTL.js";
@@ -21,7 +21,11 @@ function _geoUrl() {
21
21
  }
22
22
 
23
23
  function _clientId() {
24
- return (typeof process !== "undefined" && process.env?.NEXT_PUBLIC_GEOLOCATION_CLIENT_ID) || "";
24
+ // Phase 2 universal first, then legacy fallback (Next.js requires static access)
25
+ if (typeof process === "undefined" || !process.env) return "";
26
+ return process.env.NEXT_PUBLIC_CLIENT_ID
27
+ || process.env.NEXT_PUBLIC_GEOLOCATION_CLIENT_ID
28
+ || "";
25
29
  }
26
30
 
27
31
  async function _servicePost(path, body) {
@@ -50,10 +50,17 @@ export async function loadGoogleMapsScript({
50
50
  if (window.google?.maps?.Map) return window.google;
51
51
  if (inflight) return inflight;
52
52
 
53
- const apiBase = (apiBaseInput || readEnv("NEXT_PUBLIC_GEOLOCATION_URL") || "").replace(/\/$/, "");
54
- const clientId = clientIdInput || readEnv("NEXT_PUBLIC_GEOLOCATION_CLIENT_ID");
55
- if (!apiBase || !clientId) {
56
- throw new Error("loadGoogleMapsScript: NEXT_PUBLIC_GEOLOCATION_URL and NEXT_PUBLIC_GEOLOCATION_CLIENT_ID are required");
53
+ const apiBase = (
54
+ apiBaseInput ||
55
+ readEnv("NEXT_PUBLIC_GEOLOCATION_URL") ||
56
+ "https://geolocation.sanvikaproduction.com"
57
+ ).replace(/\/$/, "");
58
+ const clientId =
59
+ clientIdInput ||
60
+ readEnv("NEXT_PUBLIC_CLIENT_ID") ||
61
+ readEnv("NEXT_PUBLIC_GEOLOCATION_CLIENT_ID");
62
+ if (!clientId) {
63
+ throw new Error("loadGoogleMapsScript: NEXT_PUBLIC_CLIENT_ID (or NEXT_PUBLIC_GEOLOCATION_CLIENT_ID) is required");
57
64
  }
58
65
 
59
66
  inflight = (async () => {
@@ -1,7 +1,7 @@
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
3
  // Universal S2S Auth Pattern (ecosystem rule §21):
4
- // PROJECT_NAME — clientId
4
+ // CLIENT_ID — clientId
5
5
  // SANVIKA_SERVICE_KEY — Tier 1 trust
6
6
  // GEOLOCATION_URL (or GEO_URL) — service endpoint
7
7
  // GEOLOCATION_CLIENT_SECRET — (optional, Tier 2 fallback for 3rd-party)
@@ -24,11 +24,11 @@ export class GeolocationServiceClient {
24
24
 
25
25
  constructor({ url, clientId, serviceKey, secret } = {}) {
26
26
  const finalUrl = url || readEnv("GEOLOCATION_URL") || readEnv("GEO_URL");
27
- const finalClientId = clientId || readEnv("PROJECT_NAME") || readEnv("GEOLOCATION_CLIENT_ID");
27
+ const finalClientId = clientId || readEnv("CLIENT_ID") || readEnv("GEOLOCATION_CLIENT_ID");
28
28
  const finalServiceKey = serviceKey || readEnv("SANVIKA_SERVICE_KEY") || "";
29
29
  const finalSecret = secret || readEnv("GEOLOCATION_CLIENT_SECRET") || ""; // Tier 2 fallback (optional)
30
30
  if (!finalUrl || !finalClientId) {
31
- throw new Error("@sanvika/geolocation/server: GEOLOCATION_URL and PROJECT_NAME are required");
31
+ throw new Error("@sanvika/geolocation/server: GEOLOCATION_URL and CLIENT_ID are required");
32
32
  }
33
33
  this.#url = finalUrl.replace(/\/$/, "");
34
34
  this.#clientId = finalClientId;