strapi-plugin-magic-sessionmanager 4.6.4 → 4.7.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.
Files changed (31) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +15 -8
  3. package/dist/admin/{Analytics-BJlc-yE3.js → Analytics-Cw6R2xZn.js} +5 -1
  4. package/dist/admin/{Analytics-B5IR0Awr.mjs → Analytics-Dq8PuDhs.mjs} +5 -1
  5. package/dist/admin/{App-BEniJePD.mjs → App-BIFTc3mk.mjs} +1 -1
  6. package/dist/admin/{App-DisCm99X.js → App-DLR2M3FT.js} +1 -1
  7. package/dist/admin/{License-DqDBPjZH.js → License-BZtjgFol.js} +1 -1
  8. package/dist/admin/{License-BjP7GvCt.mjs → License-W_NPUWIn.mjs} +1 -1
  9. package/dist/admin/{OnlineUsersWidget-Cm9O0Fjb.mjs → OnlineUsersWidget-BIbmzgLP.mjs} +1 -1
  10. package/dist/admin/{OnlineUsersWidget-DXdeGmfV.js → OnlineUsersWidget-CAdR0MfU.js} +1 -1
  11. package/dist/admin/{Settings-CnO501iu.mjs → Settings-BNu9EAuS.mjs} +10 -5
  12. package/dist/admin/{Settings-DoLec2MD.js → Settings-DWaflQdm.js} +10 -5
  13. package/dist/admin/{de-6rIvkYOp.mjs → de-4pAz-Ihh.mjs} +4 -3
  14. package/dist/admin/{de-DjP2WJ_V.js → de-jU7AaYIc.js} +4 -3
  15. package/dist/admin/{en-8hiv31Dv.mjs → en-BI_aBNXG.mjs} +4 -3
  16. package/dist/admin/{en-0pesBbOT.js → en-Tjp9AEhR.js} +4 -3
  17. package/dist/admin/{es-DdBRpF7F.js → es-BCgwFZPL.js} +4 -3
  18. package/dist/admin/{es-LRQ148f5.mjs → es-Bp4Uzf5h.mjs} +4 -3
  19. package/dist/admin/{fr-CKhx_qil.mjs → fr-B69qIjq2.mjs} +4 -3
  20. package/dist/admin/{fr-DJ6DbeDy.js → fr-Di5zo4wy.js} +4 -3
  21. package/dist/admin/{index-DJHhzin_.js → index-CBS3aqCW.js} +10 -10
  22. package/dist/admin/{index-CpMDG2XI.mjs → index-eSND7TDx.mjs} +10 -10
  23. package/dist/admin/index.js +1 -1
  24. package/dist/admin/index.mjs +1 -1
  25. package/dist/admin/{pt-D0SMoAmo.js → pt-DlGYOi6D.js} +4 -3
  26. package/dist/admin/{pt-DXizUvcj.mjs → pt-Drc-di4D.mjs} +4 -3
  27. package/dist/server/index.js +151 -49
  28. package/dist/server/index.mjs +151 -49
  29. package/package.json +7 -7
  30. package/scripts/geoip-updater.cjs +39 -4
  31. package/scripts/update-geoip-db.mjs +1 -0
@@ -12376,9 +12376,29 @@ var require_geoip_updater = __commonJS({
12376
12376
  var zlib = require("node:zlib");
12377
12377
  var { promisify } = require("node:util");
12378
12378
  var gunzip = promisify(zlib.gunzip);
12379
- var DEFAULT_EDITION_ID = "GeoLite2-Country";
12380
- var DEFAULT_MMDB_NAME = "GeoLite2-Country.mmdb";
12379
+ var DEFAULT_EDITION_ID = "GeoLite2-City";
12380
+ var DEFAULT_MMDB_NAME = `${DEFAULT_EDITION_ID}.mmdb`;
12381
12381
  var DEFAULT_OUTPUT_PATH = path.resolve(process2.cwd(), "data", DEFAULT_MMDB_NAME);
12382
+ var SUPPORTED_EDITION_IDS = /* @__PURE__ */ new Set([
12383
+ "GeoLite2-City",
12384
+ "GeoLite2-Country",
12385
+ "GeoIP2-City",
12386
+ "GeoIP2-Country"
12387
+ ]);
12388
+ function normalizeEditionId(value, fallback = DEFAULT_EDITION_ID) {
12389
+ return SUPPORTED_EDITION_IDS.has(value) ? value : fallback;
12390
+ }
12391
+ function inferEditionIdFromPath(filePath) {
12392
+ if (typeof filePath !== "string" || filePath.trim() === "") return "";
12393
+ const basename = path.basename(filePath.trim());
12394
+ if (/GeoIP2-City\.mmdb$/i.test(basename)) return "GeoIP2-City";
12395
+ if (/GeoIP2-Country\.mmdb$/i.test(basename)) return "GeoIP2-Country";
12396
+ if (/GeoLite2-City\.mmdb$/i.test(basename)) return "GeoLite2-City";
12397
+ if (/GeoLite2-Country\.mmdb$/i.test(basename)) return "GeoLite2-Country";
12398
+ if (/city/i.test(basename)) return "GeoLite2-City";
12399
+ if (/country/i.test(basename)) return "GeoLite2-Country";
12400
+ return "";
12401
+ }
12382
12402
  function buildDownloadUrl(editionId = DEFAULT_EDITION_ID) {
12383
12403
  return `https://download.maxmind.com/geoip/databases/${encodeURIComponent(editionId)}/download?suffix=tar.gz`;
12384
12404
  }
@@ -12387,8 +12407,11 @@ var require_geoip_updater = __commonJS({
12387
12407
  }
12388
12408
  function resolveConfig(env = process2.env, argv = process2.argv.slice(2), overrides = {}) {
12389
12409
  const force = argv.includes("--force") || overrides.force === true;
12390
- const editionId = overrides.editionId || env.MAXMIND_EDITION_ID || DEFAULT_EDITION_ID;
12391
- const outputPath = overrides.outputPath || env.MAGIC_SESSIONMANAGER_GEOIP_DATABASE || env.GEOIP_DATABASE_PATH || DEFAULT_OUTPUT_PATH;
12410
+ const configuredOutputPath = overrides.outputPath || env.MAGIC_SESSIONMANAGER_GEOIP_DATABASE || env.GEOIP_DATABASE_PATH || "";
12411
+ const editionId = normalizeEditionId(
12412
+ overrides.editionId || env.MAXMIND_EDITION_ID || inferEditionIdFromPath(configuredOutputPath) || DEFAULT_EDITION_ID
12413
+ );
12414
+ const outputPath = configuredOutputPath || path.resolve(process2.cwd(), "data", `${editionId}.mmdb`);
12392
12415
  return {
12393
12416
  accountId: overrides.accountId || env.MAXMIND_ACCOUNT_ID || env.MAXMIND_USER_ID || "",
12394
12417
  licenseKey: overrides.licenseKey || env.MAXMIND_LICENSE_KEY || "",
@@ -12546,6 +12569,7 @@ var require_geoip_updater = __commonJS({
12546
12569
  buildDownloadUrl,
12547
12570
  extractMmdbFromTarGz,
12548
12571
  fileExists,
12572
+ inferEditionIdFromPath,
12549
12573
  needsDownload,
12550
12574
  readMetadata,
12551
12575
  resolveConfig,
@@ -12558,6 +12582,7 @@ var require_geoip_updater = __commonJS({
12558
12582
  var require_geoip = __commonJS({
12559
12583
  "server/src/controllers/geoip.js"(exports2, module2) {
12560
12584
  "use strict";
12585
+ var fs = require("node:fs");
12561
12586
  var path = require("node:path");
12562
12587
  var {
12563
12588
  fileExists,
@@ -12571,6 +12596,8 @@ var require_geoip = __commonJS({
12571
12596
  normalizeGeoIpDatabasePath
12572
12597
  } = require_settings_loader();
12573
12598
  var CREDENTIALS_KEY = "geoipCredentials";
12599
+ var DEFAULT_CITY_DATABASE_PATH = path.resolve(process.cwd(), "data", "GeoLite2-City.mmdb");
12600
+ var DEFAULT_COUNTRY_DATABASE_PATH = path.resolve(process.cwd(), "data", "GeoLite2-Country.mmdb");
12574
12601
  function getGeoIpStore(strapi2) {
12575
12602
  return strapi2.store({
12576
12603
  type: "plugin",
@@ -12606,10 +12633,11 @@ var require_geoip = __commonJS({
12606
12633
  }
12607
12634
  function buildUpdaterConfig(settings, storedCredentials, force = false) {
12608
12635
  const outputPath = normalizeGeoIpDatabasePath(settings.geoIpDatabasePath);
12636
+ const existingDefaultPath = !outputPath && fs.existsSync(DEFAULT_CITY_DATABASE_PATH) ? DEFAULT_CITY_DATABASE_PATH : !outputPath && fs.existsSync(DEFAULT_COUNTRY_DATABASE_PATH) ? DEFAULT_COUNTRY_DATABASE_PATH : "";
12609
12637
  return resolveConfig(process.env, force ? ["--force"] : [], {
12610
12638
  accountId: process.env.MAXMIND_ACCOUNT_ID || storedCredentials.accountId || "",
12611
12639
  licenseKey: process.env.MAXMIND_LICENSE_KEY || storedCredentials.licenseKey || "",
12612
- outputPath: outputPath || void 0,
12640
+ outputPath: outputPath || existingDefaultPath || void 0,
12613
12641
  force
12614
12642
  });
12615
12643
  }
@@ -12633,6 +12661,7 @@ var require_geoip = __commonJS({
12633
12661
  success: true,
12634
12662
  status: {
12635
12663
  provider: settings.geoIpProvider || "auto",
12664
+ editionId: config2.editionId,
12636
12665
  databasePath: config2.outputPath,
12637
12666
  databaseDirectory: path.dirname(config2.outputPath),
12638
12667
  exists,
@@ -13263,7 +13292,7 @@ var require_session2 = __commonJS({
13263
13292
  var require_package = __commonJS({
13264
13293
  "package.json"(exports2, module2) {
13265
13294
  module2.exports = {
13266
- version: "4.6.4",
13295
+ version: "4.7.0",
13267
13296
  keywords: [
13268
13297
  "strapi",
13269
13298
  "plugin",
@@ -13327,21 +13356,21 @@ var require_package = __commonJS({
13327
13356
  "@semantic-release/changelog": "^6.0.3",
13328
13357
  "@semantic-release/commit-analyzer": "^13.0.0",
13329
13358
  "@semantic-release/git": "^10.0.1",
13330
- "@semantic-release/github": "^12.0.8",
13359
+ "@semantic-release/github": "^12.0.9",
13331
13360
  "@semantic-release/npm": "^13.1.5",
13332
13361
  "@semantic-release/release-notes-generator": "^14.1.1",
13333
- "@strapi/design-system": "^2.2.0",
13334
- "@strapi/icons": "^2.2.0",
13362
+ "@strapi/design-system": "^2.2.2",
13363
+ "@strapi/icons": "^2.2.2",
13335
13364
  "@strapi/sdk-plugin": "^6.1.1",
13336
- "@strapi/strapi": "^5.48.1",
13365
+ "@strapi/strapi": "^5.50.1",
13337
13366
  esbuild: "^0.28.1",
13338
- prettier: "^3.8.4",
13367
+ prettier: "^3.9.5",
13339
13368
  react: "^18.3.1",
13340
13369
  "react-dom": "^18.3.1",
13341
13370
  "react-intl": "^7.1.14",
13342
13371
  "react-router-dom": "^6.30.4",
13343
13372
  "semantic-release": "^25.0.5",
13344
- "styled-components": "^6.4.2"
13373
+ "styled-components": "^6.4.3"
13345
13374
  },
13346
13375
  peerDependencies: {
13347
13376
  "@strapi/design-system": "^2.0.0",
@@ -13612,7 +13641,8 @@ var require_geolocation = __commonJS({
13612
13641
  var IPAPI_RATE_LIMIT_LOG_INTERVAL_MS = 60 * 1e3;
13613
13642
  var IPAPI_MAX_CONCURRENT_REQUESTS = 4;
13614
13643
  var IPAPI_MAX_QUEUE_SIZE = 50;
13615
- var DEFAULT_MMDB_PATH = path.resolve(process.cwd(), "data", "GeoLite2-Country.mmdb");
13644
+ var DEFAULT_CITY_MMDB_PATH = path.resolve(process.cwd(), "data", "GeoLite2-City.mmdb");
13645
+ var DEFAULT_COUNTRY_MMDB_PATH = path.resolve(process.cwd(), "data", "GeoLite2-Country.mmdb");
13616
13646
  var VALID_PROVIDERS = /* @__PURE__ */ new Set(["auto", "local-mmdb", "ipapi", "disabled"]);
13617
13647
  var readerCache = /* @__PURE__ */ new Map();
13618
13648
  var ipapiCache = /* @__PURE__ */ new Map();
@@ -13624,12 +13654,32 @@ var require_geolocation = __commonJS({
13624
13654
  function normalizeProvider(value) {
13625
13655
  return VALID_PROVIDERS.has(value) ? value : "auto";
13626
13656
  }
13627
- function resolveDatabasePath(settings = {}) {
13628
- const configured = settings.geoIpDatabasePath || process.env.MAGIC_SESSIONMANAGER_GEOIP_DATABASE || process.env.GEOLITE2_COUNTRY_MMDB || DEFAULT_MMDB_PATH;
13629
- if (typeof configured !== "string" || configured.trim() === "") return "";
13630
- const trimmed = configured.trim();
13657
+ function normalizeDatabasePath(value) {
13658
+ if (typeof value !== "string" || value.trim() === "") return "";
13659
+ const trimmed = value.trim();
13631
13660
  return path.isAbsolute(trimmed) ? trimmed : path.resolve(process.cwd(), trimmed);
13632
13661
  }
13662
+ function uniqueValues(values) {
13663
+ return [...new Set(values.filter(Boolean))];
13664
+ }
13665
+ function resolveDatabaseCandidates(settings = {}) {
13666
+ const configured = normalizeDatabasePath(
13667
+ settings.geoIpDatabasePath || process.env.MAGIC_SESSIONMANAGER_GEOIP_DATABASE || process.env.GEOIP_DATABASE_PATH
13668
+ );
13669
+ if (configured) return [configured];
13670
+ return uniqueValues([
13671
+ normalizeDatabasePath(process.env.GEOLITE2_CITY_MMDB),
13672
+ normalizeDatabasePath(process.env.GEOIP_CITY_DATABASE_PATH),
13673
+ normalizeDatabasePath(process.env.GEOLITE2_COUNTRY_MMDB),
13674
+ normalizeDatabasePath(process.env.GEOIP_COUNTRY_DATABASE_PATH),
13675
+ DEFAULT_CITY_MMDB_PATH,
13676
+ DEFAULT_COUNTRY_MMDB_PATH
13677
+ ]);
13678
+ }
13679
+ function resolveExistingDatabasePath(settings = {}) {
13680
+ const candidates = resolveDatabaseCandidates(settings);
13681
+ return candidates.find((candidate) => fs.existsSync(candidate)) || candidates[0] || "";
13682
+ }
13633
13683
  async function openLocalReader(databasePath) {
13634
13684
  if (readerCache.has(databasePath)) {
13635
13685
  return readerCache.get(databasePath);
@@ -13714,6 +13764,79 @@ var require_geolocation = __commonJS({
13714
13764
  next(releaseIpapiSlot);
13715
13765
  }
13716
13766
  }
13767
+ function getName(names = {}, fallback = "") {
13768
+ return names.en || names.de || names.fr || names.es || names.pt || fallback;
13769
+ }
13770
+ function getReaderDatabaseType(reader, databasePath) {
13771
+ const metadataType = reader?.metadata?.databaseType || reader?.metadata?.database_type || reader?.metadata?.database_type_name;
13772
+ if (typeof metadataType === "string" && metadataType.trim()) {
13773
+ return metadataType;
13774
+ }
13775
+ return path.basename(databasePath || "");
13776
+ }
13777
+ function isCityDatabase(reader, databasePath) {
13778
+ return /(?:^|[-_])City(?:\.|[-_]|$)/i.test(getReaderDatabaseType(reader, databasePath));
13779
+ }
13780
+ function normalizeLocalCountryResult(data, lookupIp, getCountryFlag) {
13781
+ const country = data.country || data.registeredCountry || data.representedCountry || {};
13782
+ const countryCode = country.isoCode || data.registeredCountry?.isoCode || "XX";
13783
+ return {
13784
+ ip: lookupIp,
13785
+ country: getName(country.names, countryCode || "Unknown"),
13786
+ country_code: countryCode,
13787
+ country_flag: getCountryFlag(countryCode),
13788
+ city: "Unknown",
13789
+ region: "Unknown",
13790
+ timezone: "Unknown",
13791
+ latitude: null,
13792
+ longitude: null,
13793
+ postal: null,
13794
+ org: null,
13795
+ asn: null,
13796
+ network: data.traits?.network || null,
13797
+ isVpn: false,
13798
+ isProxy: false,
13799
+ isThreat: false,
13800
+ isAnonymous: false,
13801
+ isTor: false,
13802
+ securityScore: 100,
13803
+ riskLevel: "Low",
13804
+ _status: "ok",
13805
+ _source: "local-mmdb",
13806
+ _databaseType: "country"
13807
+ };
13808
+ }
13809
+ function normalizeLocalCityResult(data, lookupIp, getCountryFlag) {
13810
+ const country = data.country || data.registeredCountry || data.representedCountry || {};
13811
+ const countryCode = country.isoCode || data.registeredCountry?.isoCode || "XX";
13812
+ const region = Array.isArray(data.subdivisions) && data.subdivisions.length > 0 ? data.subdivisions[0] : null;
13813
+ return {
13814
+ ip: lookupIp,
13815
+ country: getName(country.names, countryCode || "Unknown"),
13816
+ country_code: countryCode,
13817
+ country_flag: getCountryFlag(countryCode),
13818
+ city: getName(data.city?.names, "Unknown"),
13819
+ region: getName(region?.names, region?.isoCode || "Unknown"),
13820
+ timezone: data.location?.timeZone || "Unknown",
13821
+ latitude: data.location?.latitude ?? null,
13822
+ longitude: data.location?.longitude ?? null,
13823
+ accuracyRadius: data.location?.accuracyRadius ?? null,
13824
+ postal: data.postal?.code || null,
13825
+ org: null,
13826
+ asn: null,
13827
+ network: data.traits?.network || null,
13828
+ isVpn: false,
13829
+ isProxy: false,
13830
+ isThreat: false,
13831
+ isAnonymous: false,
13832
+ isTor: false,
13833
+ securityScore: 100,
13834
+ riskLevel: "Low",
13835
+ _status: "ok",
13836
+ _source: "local-mmdb",
13837
+ _databaseType: "city"
13838
+ };
13839
+ }
13717
13840
  function normalizeLookupIp(ipAddress) {
13718
13841
  if (typeof ipAddress !== "string") return "";
13719
13842
  let normalized = ipAddress.trim();
@@ -13809,7 +13932,7 @@ var require_geolocation = __commonJS({
13809
13932
  return this.getLocalMmdbIpInfo(lookupIp, settings);
13810
13933
  }
13811
13934
  if (provider === "auto") {
13812
- const databasePath = resolveDatabasePath(settings);
13935
+ const databasePath = resolveExistingDatabasePath(settings);
13813
13936
  if (databasePath && fs.existsSync(databasePath)) {
13814
13937
  const localResult = await this.getLocalMmdbIpInfo(lookupIp, settings);
13815
13938
  if (localResult?._status === "ok" || settings.geoLookupFailureMode === "block") {
@@ -13832,7 +13955,9 @@ var require_geolocation = __commonJS({
13832
13955
  }
13833
13956
  },
13834
13957
  /**
13835
- * Looks up country data from a local MaxMind-compatible MMDB file.
13958
+ * Looks up geolocation data from a local MaxMind-compatible MMDB file.
13959
+ * GeoLite2-City is preferred for city-level data; GeoLite2-Country remains
13960
+ * supported for existing installations and country-only firewall decisions.
13836
13961
  * @param {string} ipAddress
13837
13962
  * @param {object} settings
13838
13963
  * @returns {Promise<object>}
@@ -13842,7 +13967,7 @@ var require_geolocation = __commonJS({
13842
13967
  if (!lookupIp || net.isIP(lookupIp) === 0) {
13843
13968
  return this.getFallbackData(ipAddress, "error", "validation", "Invalid IP address");
13844
13969
  }
13845
- const databasePath = resolveDatabasePath(settings);
13970
+ const databasePath = resolveExistingDatabasePath(settings);
13846
13971
  if (!databasePath || !fs.existsSync(databasePath)) {
13847
13972
  return this.getFallbackData(
13848
13973
  ipAddress,
@@ -13853,35 +13978,12 @@ var require_geolocation = __commonJS({
13853
13978
  }
13854
13979
  try {
13855
13980
  const reader = await openLocalReader(databasePath);
13856
- const data = reader.country(lookupIp);
13857
- const country = data.country || data.registeredCountry || data.representedCountry || {};
13858
- const countryCode = country.isoCode || data.registeredCountry?.isoCode || "XX";
13859
- const countryNames = country.names || {};
13860
- const result = {
13861
- ip: lookupIp,
13862
- country: countryNames.en || countryNames.de || countryCode || "Unknown",
13863
- country_code: countryCode,
13864
- country_flag: this.getCountryFlag(countryCode),
13865
- city: "Unknown",
13866
- region: "Unknown",
13867
- timezone: "Unknown",
13868
- latitude: null,
13869
- longitude: null,
13870
- postal: null,
13871
- org: null,
13872
- asn: null,
13873
- network: data.traits?.network || null,
13874
- isVpn: false,
13875
- isProxy: false,
13876
- isThreat: false,
13877
- isAnonymous: false,
13878
- isTor: false,
13879
- securityScore: 100,
13880
- riskLevel: "Low",
13881
- _status: "ok",
13882
- _source: "local-mmdb"
13883
- };
13884
- strapi2.log.debug(`[magic-sessionmanager/geolocation] Local MMDB IP ${lookupIp}: ${result.country_code}`);
13981
+ const useCityLookup = isCityDatabase(reader, databasePath) && typeof reader.city === "function";
13982
+ const data = useCityLookup ? reader.city(lookupIp) : reader.country(lookupIp);
13983
+ const result = useCityLookup ? normalizeLocalCityResult(data, lookupIp, this.getCountryFlag.bind(this)) : normalizeLocalCountryResult(data, lookupIp, this.getCountryFlag.bind(this));
13984
+ strapi2.log.debug(
13985
+ `[magic-sessionmanager/geolocation] Local MMDB ${result._databaseType} IP ${lookupIp}: ${result.city}, ${result.country_code}`
13986
+ );
13885
13987
  return result;
13886
13988
  } catch (error) {
13887
13989
  strapi2.log.warn(`[magic-sessionmanager/geolocation] Local MMDB lookup failed for ${lookupIp}:`, error.message);
@@ -12382,9 +12382,29 @@ var require_geoip_updater = __commonJS({
12382
12382
  var zlib = __require("node:zlib");
12383
12383
  var { promisify } = __require("node:util");
12384
12384
  var gunzip = promisify(zlib.gunzip);
12385
- var DEFAULT_EDITION_ID = "GeoLite2-Country";
12386
- var DEFAULT_MMDB_NAME = "GeoLite2-Country.mmdb";
12385
+ var DEFAULT_EDITION_ID = "GeoLite2-City";
12386
+ var DEFAULT_MMDB_NAME = `${DEFAULT_EDITION_ID}.mmdb`;
12387
12387
  var DEFAULT_OUTPUT_PATH = path.resolve(process2.cwd(), "data", DEFAULT_MMDB_NAME);
12388
+ var SUPPORTED_EDITION_IDS = /* @__PURE__ */ new Set([
12389
+ "GeoLite2-City",
12390
+ "GeoLite2-Country",
12391
+ "GeoIP2-City",
12392
+ "GeoIP2-Country"
12393
+ ]);
12394
+ function normalizeEditionId(value, fallback = DEFAULT_EDITION_ID) {
12395
+ return SUPPORTED_EDITION_IDS.has(value) ? value : fallback;
12396
+ }
12397
+ function inferEditionIdFromPath(filePath) {
12398
+ if (typeof filePath !== "string" || filePath.trim() === "") return "";
12399
+ const basename = path.basename(filePath.trim());
12400
+ if (/GeoIP2-City\.mmdb$/i.test(basename)) return "GeoIP2-City";
12401
+ if (/GeoIP2-Country\.mmdb$/i.test(basename)) return "GeoIP2-Country";
12402
+ if (/GeoLite2-City\.mmdb$/i.test(basename)) return "GeoLite2-City";
12403
+ if (/GeoLite2-Country\.mmdb$/i.test(basename)) return "GeoLite2-Country";
12404
+ if (/city/i.test(basename)) return "GeoLite2-City";
12405
+ if (/country/i.test(basename)) return "GeoLite2-Country";
12406
+ return "";
12407
+ }
12388
12408
  function buildDownloadUrl(editionId = DEFAULT_EDITION_ID) {
12389
12409
  return `https://download.maxmind.com/geoip/databases/${encodeURIComponent(editionId)}/download?suffix=tar.gz`;
12390
12410
  }
@@ -12393,8 +12413,11 @@ var require_geoip_updater = __commonJS({
12393
12413
  }
12394
12414
  function resolveConfig(env = process2.env, argv = process2.argv.slice(2), overrides = {}) {
12395
12415
  const force = argv.includes("--force") || overrides.force === true;
12396
- const editionId = overrides.editionId || env.MAXMIND_EDITION_ID || DEFAULT_EDITION_ID;
12397
- const outputPath = overrides.outputPath || env.MAGIC_SESSIONMANAGER_GEOIP_DATABASE || env.GEOIP_DATABASE_PATH || DEFAULT_OUTPUT_PATH;
12416
+ const configuredOutputPath = overrides.outputPath || env.MAGIC_SESSIONMANAGER_GEOIP_DATABASE || env.GEOIP_DATABASE_PATH || "";
12417
+ const editionId = normalizeEditionId(
12418
+ overrides.editionId || env.MAXMIND_EDITION_ID || inferEditionIdFromPath(configuredOutputPath) || DEFAULT_EDITION_ID
12419
+ );
12420
+ const outputPath = configuredOutputPath || path.resolve(process2.cwd(), "data", `${editionId}.mmdb`);
12398
12421
  return {
12399
12422
  accountId: overrides.accountId || env.MAXMIND_ACCOUNT_ID || env.MAXMIND_USER_ID || "",
12400
12423
  licenseKey: overrides.licenseKey || env.MAXMIND_LICENSE_KEY || "",
@@ -12552,6 +12575,7 @@ var require_geoip_updater = __commonJS({
12552
12575
  buildDownloadUrl,
12553
12576
  extractMmdbFromTarGz,
12554
12577
  fileExists,
12578
+ inferEditionIdFromPath,
12555
12579
  needsDownload,
12556
12580
  readMetadata,
12557
12581
  resolveConfig,
@@ -12564,6 +12588,7 @@ var require_geoip_updater = __commonJS({
12564
12588
  var require_geoip = __commonJS({
12565
12589
  "server/src/controllers/geoip.js"(exports, module) {
12566
12590
  "use strict";
12591
+ var fs = __require("node:fs");
12567
12592
  var path = __require("node:path");
12568
12593
  var {
12569
12594
  fileExists,
@@ -12577,6 +12602,8 @@ var require_geoip = __commonJS({
12577
12602
  normalizeGeoIpDatabasePath
12578
12603
  } = require_settings_loader();
12579
12604
  var CREDENTIALS_KEY = "geoipCredentials";
12605
+ var DEFAULT_CITY_DATABASE_PATH = path.resolve(process.cwd(), "data", "GeoLite2-City.mmdb");
12606
+ var DEFAULT_COUNTRY_DATABASE_PATH = path.resolve(process.cwd(), "data", "GeoLite2-Country.mmdb");
12580
12607
  function getGeoIpStore(strapi2) {
12581
12608
  return strapi2.store({
12582
12609
  type: "plugin",
@@ -12612,10 +12639,11 @@ var require_geoip = __commonJS({
12612
12639
  }
12613
12640
  function buildUpdaterConfig(settings, storedCredentials, force = false) {
12614
12641
  const outputPath = normalizeGeoIpDatabasePath(settings.geoIpDatabasePath);
12642
+ const existingDefaultPath = !outputPath && fs.existsSync(DEFAULT_CITY_DATABASE_PATH) ? DEFAULT_CITY_DATABASE_PATH : !outputPath && fs.existsSync(DEFAULT_COUNTRY_DATABASE_PATH) ? DEFAULT_COUNTRY_DATABASE_PATH : "";
12615
12643
  return resolveConfig(process.env, force ? ["--force"] : [], {
12616
12644
  accountId: process.env.MAXMIND_ACCOUNT_ID || storedCredentials.accountId || "",
12617
12645
  licenseKey: process.env.MAXMIND_LICENSE_KEY || storedCredentials.licenseKey || "",
12618
- outputPath: outputPath || void 0,
12646
+ outputPath: outputPath || existingDefaultPath || void 0,
12619
12647
  force
12620
12648
  });
12621
12649
  }
@@ -12639,6 +12667,7 @@ var require_geoip = __commonJS({
12639
12667
  success: true,
12640
12668
  status: {
12641
12669
  provider: settings.geoIpProvider || "auto",
12670
+ editionId: config.editionId,
12642
12671
  databasePath: config.outputPath,
12643
12672
  databaseDirectory: path.dirname(config.outputPath),
12644
12673
  exists,
@@ -13269,7 +13298,7 @@ var require_session2 = __commonJS({
13269
13298
  var require_package = __commonJS({
13270
13299
  "package.json"(exports, module) {
13271
13300
  module.exports = {
13272
- version: "4.6.4",
13301
+ version: "4.7.0",
13273
13302
  keywords: [
13274
13303
  "strapi",
13275
13304
  "plugin",
@@ -13333,21 +13362,21 @@ var require_package = __commonJS({
13333
13362
  "@semantic-release/changelog": "^6.0.3",
13334
13363
  "@semantic-release/commit-analyzer": "^13.0.0",
13335
13364
  "@semantic-release/git": "^10.0.1",
13336
- "@semantic-release/github": "^12.0.8",
13365
+ "@semantic-release/github": "^12.0.9",
13337
13366
  "@semantic-release/npm": "^13.1.5",
13338
13367
  "@semantic-release/release-notes-generator": "^14.1.1",
13339
- "@strapi/design-system": "^2.2.0",
13340
- "@strapi/icons": "^2.2.0",
13368
+ "@strapi/design-system": "^2.2.2",
13369
+ "@strapi/icons": "^2.2.2",
13341
13370
  "@strapi/sdk-plugin": "^6.1.1",
13342
- "@strapi/strapi": "^5.48.1",
13371
+ "@strapi/strapi": "^5.50.1",
13343
13372
  esbuild: "^0.28.1",
13344
- prettier: "^3.8.4",
13373
+ prettier: "^3.9.5",
13345
13374
  react: "^18.3.1",
13346
13375
  "react-dom": "^18.3.1",
13347
13376
  "react-intl": "^7.1.14",
13348
13377
  "react-router-dom": "^6.30.4",
13349
13378
  "semantic-release": "^25.0.5",
13350
- "styled-components": "^6.4.2"
13379
+ "styled-components": "^6.4.3"
13351
13380
  },
13352
13381
  peerDependencies: {
13353
13382
  "@strapi/design-system": "^2.0.0",
@@ -13618,7 +13647,8 @@ var require_geolocation = __commonJS({
13618
13647
  var IPAPI_RATE_LIMIT_LOG_INTERVAL_MS = 60 * 1e3;
13619
13648
  var IPAPI_MAX_CONCURRENT_REQUESTS = 4;
13620
13649
  var IPAPI_MAX_QUEUE_SIZE = 50;
13621
- var DEFAULT_MMDB_PATH = path.resolve(process.cwd(), "data", "GeoLite2-Country.mmdb");
13650
+ var DEFAULT_CITY_MMDB_PATH = path.resolve(process.cwd(), "data", "GeoLite2-City.mmdb");
13651
+ var DEFAULT_COUNTRY_MMDB_PATH = path.resolve(process.cwd(), "data", "GeoLite2-Country.mmdb");
13622
13652
  var VALID_PROVIDERS = /* @__PURE__ */ new Set(["auto", "local-mmdb", "ipapi", "disabled"]);
13623
13653
  var readerCache = /* @__PURE__ */ new Map();
13624
13654
  var ipapiCache = /* @__PURE__ */ new Map();
@@ -13630,12 +13660,32 @@ var require_geolocation = __commonJS({
13630
13660
  function normalizeProvider(value) {
13631
13661
  return VALID_PROVIDERS.has(value) ? value : "auto";
13632
13662
  }
13633
- function resolveDatabasePath(settings = {}) {
13634
- const configured = settings.geoIpDatabasePath || process.env.MAGIC_SESSIONMANAGER_GEOIP_DATABASE || process.env.GEOLITE2_COUNTRY_MMDB || DEFAULT_MMDB_PATH;
13635
- if (typeof configured !== "string" || configured.trim() === "") return "";
13636
- const trimmed = configured.trim();
13663
+ function normalizeDatabasePath(value) {
13664
+ if (typeof value !== "string" || value.trim() === "") return "";
13665
+ const trimmed = value.trim();
13637
13666
  return path.isAbsolute(trimmed) ? trimmed : path.resolve(process.cwd(), trimmed);
13638
13667
  }
13668
+ function uniqueValues(values) {
13669
+ return [...new Set(values.filter(Boolean))];
13670
+ }
13671
+ function resolveDatabaseCandidates(settings = {}) {
13672
+ const configured = normalizeDatabasePath(
13673
+ settings.geoIpDatabasePath || process.env.MAGIC_SESSIONMANAGER_GEOIP_DATABASE || process.env.GEOIP_DATABASE_PATH
13674
+ );
13675
+ if (configured) return [configured];
13676
+ return uniqueValues([
13677
+ normalizeDatabasePath(process.env.GEOLITE2_CITY_MMDB),
13678
+ normalizeDatabasePath(process.env.GEOIP_CITY_DATABASE_PATH),
13679
+ normalizeDatabasePath(process.env.GEOLITE2_COUNTRY_MMDB),
13680
+ normalizeDatabasePath(process.env.GEOIP_COUNTRY_DATABASE_PATH),
13681
+ DEFAULT_CITY_MMDB_PATH,
13682
+ DEFAULT_COUNTRY_MMDB_PATH
13683
+ ]);
13684
+ }
13685
+ function resolveExistingDatabasePath(settings = {}) {
13686
+ const candidates = resolveDatabaseCandidates(settings);
13687
+ return candidates.find((candidate) => fs.existsSync(candidate)) || candidates[0] || "";
13688
+ }
13639
13689
  async function openLocalReader(databasePath) {
13640
13690
  if (readerCache.has(databasePath)) {
13641
13691
  return readerCache.get(databasePath);
@@ -13720,6 +13770,79 @@ var require_geolocation = __commonJS({
13720
13770
  next(releaseIpapiSlot);
13721
13771
  }
13722
13772
  }
13773
+ function getName(names = {}, fallback = "") {
13774
+ return names.en || names.de || names.fr || names.es || names.pt || fallback;
13775
+ }
13776
+ function getReaderDatabaseType(reader, databasePath) {
13777
+ const metadataType = reader?.metadata?.databaseType || reader?.metadata?.database_type || reader?.metadata?.database_type_name;
13778
+ if (typeof metadataType === "string" && metadataType.trim()) {
13779
+ return metadataType;
13780
+ }
13781
+ return path.basename(databasePath || "");
13782
+ }
13783
+ function isCityDatabase(reader, databasePath) {
13784
+ return /(?:^|[-_])City(?:\.|[-_]|$)/i.test(getReaderDatabaseType(reader, databasePath));
13785
+ }
13786
+ function normalizeLocalCountryResult(data, lookupIp, getCountryFlag) {
13787
+ const country = data.country || data.registeredCountry || data.representedCountry || {};
13788
+ const countryCode = country.isoCode || data.registeredCountry?.isoCode || "XX";
13789
+ return {
13790
+ ip: lookupIp,
13791
+ country: getName(country.names, countryCode || "Unknown"),
13792
+ country_code: countryCode,
13793
+ country_flag: getCountryFlag(countryCode),
13794
+ city: "Unknown",
13795
+ region: "Unknown",
13796
+ timezone: "Unknown",
13797
+ latitude: null,
13798
+ longitude: null,
13799
+ postal: null,
13800
+ org: null,
13801
+ asn: null,
13802
+ network: data.traits?.network || null,
13803
+ isVpn: false,
13804
+ isProxy: false,
13805
+ isThreat: false,
13806
+ isAnonymous: false,
13807
+ isTor: false,
13808
+ securityScore: 100,
13809
+ riskLevel: "Low",
13810
+ _status: "ok",
13811
+ _source: "local-mmdb",
13812
+ _databaseType: "country"
13813
+ };
13814
+ }
13815
+ function normalizeLocalCityResult(data, lookupIp, getCountryFlag) {
13816
+ const country = data.country || data.registeredCountry || data.representedCountry || {};
13817
+ const countryCode = country.isoCode || data.registeredCountry?.isoCode || "XX";
13818
+ const region = Array.isArray(data.subdivisions) && data.subdivisions.length > 0 ? data.subdivisions[0] : null;
13819
+ return {
13820
+ ip: lookupIp,
13821
+ country: getName(country.names, countryCode || "Unknown"),
13822
+ country_code: countryCode,
13823
+ country_flag: getCountryFlag(countryCode),
13824
+ city: getName(data.city?.names, "Unknown"),
13825
+ region: getName(region?.names, region?.isoCode || "Unknown"),
13826
+ timezone: data.location?.timeZone || "Unknown",
13827
+ latitude: data.location?.latitude ?? null,
13828
+ longitude: data.location?.longitude ?? null,
13829
+ accuracyRadius: data.location?.accuracyRadius ?? null,
13830
+ postal: data.postal?.code || null,
13831
+ org: null,
13832
+ asn: null,
13833
+ network: data.traits?.network || null,
13834
+ isVpn: false,
13835
+ isProxy: false,
13836
+ isThreat: false,
13837
+ isAnonymous: false,
13838
+ isTor: false,
13839
+ securityScore: 100,
13840
+ riskLevel: "Low",
13841
+ _status: "ok",
13842
+ _source: "local-mmdb",
13843
+ _databaseType: "city"
13844
+ };
13845
+ }
13723
13846
  function normalizeLookupIp(ipAddress) {
13724
13847
  if (typeof ipAddress !== "string") return "";
13725
13848
  let normalized = ipAddress.trim();
@@ -13815,7 +13938,7 @@ var require_geolocation = __commonJS({
13815
13938
  return this.getLocalMmdbIpInfo(lookupIp, settings);
13816
13939
  }
13817
13940
  if (provider === "auto") {
13818
- const databasePath = resolveDatabasePath(settings);
13941
+ const databasePath = resolveExistingDatabasePath(settings);
13819
13942
  if (databasePath && fs.existsSync(databasePath)) {
13820
13943
  const localResult = await this.getLocalMmdbIpInfo(lookupIp, settings);
13821
13944
  if (localResult?._status === "ok" || settings.geoLookupFailureMode === "block") {
@@ -13838,7 +13961,9 @@ var require_geolocation = __commonJS({
13838
13961
  }
13839
13962
  },
13840
13963
  /**
13841
- * Looks up country data from a local MaxMind-compatible MMDB file.
13964
+ * Looks up geolocation data from a local MaxMind-compatible MMDB file.
13965
+ * GeoLite2-City is preferred for city-level data; GeoLite2-Country remains
13966
+ * supported for existing installations and country-only firewall decisions.
13842
13967
  * @param {string} ipAddress
13843
13968
  * @param {object} settings
13844
13969
  * @returns {Promise<object>}
@@ -13848,7 +13973,7 @@ var require_geolocation = __commonJS({
13848
13973
  if (!lookupIp || net.isIP(lookupIp) === 0) {
13849
13974
  return this.getFallbackData(ipAddress, "error", "validation", "Invalid IP address");
13850
13975
  }
13851
- const databasePath = resolveDatabasePath(settings);
13976
+ const databasePath = resolveExistingDatabasePath(settings);
13852
13977
  if (!databasePath || !fs.existsSync(databasePath)) {
13853
13978
  return this.getFallbackData(
13854
13979
  ipAddress,
@@ -13859,35 +13984,12 @@ var require_geolocation = __commonJS({
13859
13984
  }
13860
13985
  try {
13861
13986
  const reader = await openLocalReader(databasePath);
13862
- const data = reader.country(lookupIp);
13863
- const country = data.country || data.registeredCountry || data.representedCountry || {};
13864
- const countryCode = country.isoCode || data.registeredCountry?.isoCode || "XX";
13865
- const countryNames = country.names || {};
13866
- const result = {
13867
- ip: lookupIp,
13868
- country: countryNames.en || countryNames.de || countryCode || "Unknown",
13869
- country_code: countryCode,
13870
- country_flag: this.getCountryFlag(countryCode),
13871
- city: "Unknown",
13872
- region: "Unknown",
13873
- timezone: "Unknown",
13874
- latitude: null,
13875
- longitude: null,
13876
- postal: null,
13877
- org: null,
13878
- asn: null,
13879
- network: data.traits?.network || null,
13880
- isVpn: false,
13881
- isProxy: false,
13882
- isThreat: false,
13883
- isAnonymous: false,
13884
- isTor: false,
13885
- securityScore: 100,
13886
- riskLevel: "Low",
13887
- _status: "ok",
13888
- _source: "local-mmdb"
13889
- };
13890
- strapi2.log.debug(`[magic-sessionmanager/geolocation] Local MMDB IP ${lookupIp}: ${result.country_code}`);
13987
+ const useCityLookup = isCityDatabase(reader, databasePath) && typeof reader.city === "function";
13988
+ const data = useCityLookup ? reader.city(lookupIp) : reader.country(lookupIp);
13989
+ const result = useCityLookup ? normalizeLocalCityResult(data, lookupIp, this.getCountryFlag.bind(this)) : normalizeLocalCountryResult(data, lookupIp, this.getCountryFlag.bind(this));
13990
+ strapi2.log.debug(
13991
+ `[magic-sessionmanager/geolocation] Local MMDB ${result._databaseType} IP ${lookupIp}: ${result.city}, ${result.country_code}`
13992
+ );
13891
13993
  return result;
13892
13994
  } catch (error) {
13893
13995
  strapi2.log.warn(`[magic-sessionmanager/geolocation] Local MMDB lookup failed for ${lookupIp}:`, error.message);