fix(device-enrichment): 🐛 Fix runtime errors by switching geoip-lite module from CJS to ESM imports

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
autocommit 2026-04-18 01:10:41 -07:00
parent 4c9294706e
commit 24cff48bff

View file

@ -1,9 +1,18 @@
import { Injectable, Logger, OnModuleInit } from '@nestjs/common';
import * as crypto from 'crypto';
import geoip from 'geoip-lite';
import { createRequire } from 'node:module';
import type geoipLite from 'geoip-lite';
import type { OrganizationType, ResponseTier, ProxyType } from '@lilith/gov-detection';
import { GovDetectionService } from './gov-detection.service';
// geoip-lite is CJS. SWC emits `import geoip from 'geoip-lite'` as
// `import * as geoip from 'geoip-lite'`, and Node's cjs-named-export detection
// does not expose `lookup` on the namespace — call crashes with
// `TypeError: geoip.lookup is not a function`. Load via createRequire to get
// the real module.exports object.
const require = createRequire(import.meta.url);
const geoip = require('geoip-lite') as typeof geoipLite;
const EU_COUNTRIES = new Set([
'AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI',
'FR', 'GR', 'HR', 'HU', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT',