MCPcopy
hub / github.com/FlowiseAI/Flowise / getGeolocation

Function getGeolocation

packages/server/src/utils/telemetry.ts:54–74  ·  view source on GitHub ↗

* Derives country code and region from an IP address using GeoIP lookup. * * This function performs a non-blocking geolocation lookup to extract geographic * information before the IP address is masked for privacy compliance. Returns * ISO country codes and region identifiers that are GDPR/HIPAA

(ipAddress: string)

Source from the content-addressed store, hash-verified

52 * @returns An object containing optional `countryCode` (ISO 3166-1 alpha-2) and `region` (state/province), or empty object if lookup fails or IP is invalid
53 */
54function getGeolocation(ipAddress: string): {
55 countryCode?: string
56 region?: string
57} {
58 if (!isValidIPAddress(ipAddress)) {
59 return {}
60 }
61
62 try {
63 const geo = geoip.lookup(ipAddress)
64 if (!geo) return {}
65
66 return {
67 countryCode: geo.country,
68 region: geo.region
69 }
70 } catch (error) {
71 logger.error(`Failed to resolve geolocation for IP: ${error}`)
72 return {}
73 }
74}
75
76/**
77 * Categories for telemetry events, used for filtering and compliance reporting.

Callers 1

emitEventFunction · 0.85

Calls 2

isValidIPAddressFunction · 0.90
lookupMethod · 0.80

Tested by

no test coverage detected