@sanvika/geolocation 0.6.0 → 0.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanvika/geolocation",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
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",
@@ -26,9 +26,10 @@ function readEnv(key) {
26
26
  }
27
27
  }
28
28
 
29
- async function fetchMapsConfig({ apiBase, clientId }) {
29
+ async function fetchMapsConfig({ apiBase, clientId, mapsConfigPath }) {
30
30
  if (cachedConfig) return cachedConfig;
31
- const url = `${apiBase}/api/v1/mapsjs/config?clientId=${encodeURIComponent(clientId)}`;
31
+ const configPath = mapsConfigPath || "/api/v1/mapsjs/config";
32
+ const url = `${apiBase}${configPath}?clientId=${encodeURIComponent(clientId)}`;
32
33
  const res = await fetch(url, { credentials: "omit" });
33
34
  const data = await res.json().catch(() => ({}));
34
35
  if (!res.ok || !data?.success) {
@@ -43,6 +44,7 @@ export async function loadGoogleMapsScript({
43
44
  version = "weekly",
44
45
  apiBase: apiBaseInput,
45
46
  clientId: clientIdInput,
47
+ mapsConfigPath,
46
48
  } = {}) {
47
49
  if (typeof window === "undefined") {
48
50
  throw new Error("loadGoogleMapsScript must run in the browser");
@@ -64,7 +66,7 @@ export async function loadGoogleMapsScript({
64
66
  }
65
67
 
66
68
  inflight = (async () => {
67
- const config = await fetchMapsConfig({ apiBase, clientId });
69
+ const config = await fetchMapsConfig({ apiBase, clientId, mapsConfigPath });
68
70
 
69
71
  return new Promise((resolve, reject) => {
70
72
  const callbackName = `__sanvika_maps_cb_${Date.now()}`;
@@ -23,12 +23,16 @@ export class GeolocationServiceClient {
23
23
  #secret;
24
24
 
25
25
  constructor({ url, clientId, serviceKey, secret } = {}) {
26
- const finalUrl = url || readEnv("GEOLOCATION_URL") || readEnv("GEO_URL");
26
+ const finalUrl =
27
+ url ||
28
+ readEnv("GEOLOCATION_URL") ||
29
+ readEnv("GEO_URL") ||
30
+ "https://geolocation.sanvikaproduction.com";
27
31
  const finalClientId = clientId || readEnv("CLIENT_ID") || readEnv("GEOLOCATION_CLIENT_ID");
28
32
  const finalServiceKey = serviceKey || readEnv("SANVIKA_SERVICE_KEY") || "";
29
33
  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 CLIENT_ID are required");
34
+ if (!finalClientId) {
35
+ throw new Error("@sanvika/geolocation/server: CLIENT_ID is required");
32
36
  }
33
37
  this.#url = finalUrl.replace(/\/$/, "");
34
38
  this.#clientId = finalClientId;