@repobit/dex-utils 2.2.32 → 2.3.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/CHANGELOG.md CHANGED
@@ -3,6 +3,21 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [2.3.1](https://github.com/bitdefender/dex-core/compare/@repobit/dex-utils@2.3.0...@repobit/dex-utils@2.3.1) (2026-06-17)
7
+
8
+ **Note:** Version bump only for package @repobit/dex-utils
9
+
10
+
11
+
12
+
13
+
14
+ ## [2.3.0](https://github.com/bitdefender/dex-core/compare/@repobit/dex-utils@2.2.32...@repobit/dex-utils@2.3.0) (2026-06-16)
15
+
16
+ ### Features
17
+
18
+ * **DEX-27688:** update geoIp fallback to get pageCountry when availabe
19
+
20
+
6
21
  ## [2.2.32](https://github.com/bitdefender/dex-core/compare/@repobit/dex-utils@2.2.31...@repobit/dex-utils@2.2.32) (2026-06-12)
7
22
 
8
23
  **Note:** Version bump only for package @repobit/dex-utils
package/README.md CHANGED
@@ -113,6 +113,12 @@ console.log(page.getParamValue('ref')); // Retrieves the value of 'ref' from the
113
113
  ### Description:
114
114
  A class that manages user-related operations such as login, fingerprint generation, and geolocation-based locale determination.
115
115
 
116
+ ### Constructor change:
117
+
118
+ - The `User` constructor now accepts an optional `pageCountry` parameter: `new User(pageCountry?: string)`.
119
+ - When provided, `pageCountry` is used as the fallback country code for geolocation lookups (lowercased), instead of the default `'us'`.
120
+ - This is useful for pages that already know the expected country context and want deterministic fallback behavior when GeoIP calls fail or return errors.
121
+
116
122
  ### Public properties:
117
123
 
118
124
  - ## info: Promise<UserInfoResult | null>
@@ -122,7 +128,7 @@ A class that manages user-related operations such as login, fingerprint generati
122
128
  A unique ID for the user.
123
129
 
124
130
  - ## country: Promise<string>
125
- The user's country based on geolocation.
131
+ The user's country based on geolocation. If the `/geoip` call fails, or the response JSON contains an `error_code`, the `pageCountry` value passed to the constructor (if any) will be used as the fallback; otherwise the default fallback is `'us'`.
126
132
 
127
133
  - ## locale: Promise<string>
128
134
  The user's locale (e.g., "en-us") fetched using his country.
@@ -2,8 +2,10 @@ import { UserInfoResult } from './typeDefinitions.js';
2
2
  export default class User {
3
3
  private _info;
4
4
  private _fingerprint;
5
+ private _pageCountry;
5
6
  private _country;
6
7
  private _locale;
8
+ constructor(pageCountry?: string);
7
9
  private Initialise;
8
10
  private getFingerprint;
9
11
  /**
package/dist/src/user.js CHANGED
@@ -5,8 +5,14 @@ const w = window;
5
5
  export default class User {
6
6
  _info = this.Initialise();
7
7
  _fingerprint = this.getFingerprint();
8
- _country = this.getGeolocation();
9
- _locale = this.getUserLocale();
8
+ _pageCountry;
9
+ _country;
10
+ _locale;
11
+ constructor(pageCountry) {
12
+ this._pageCountry = pageCountry;
13
+ this._country = this.getGeolocation();
14
+ this._locale = this.getUserLocale();
15
+ }
10
16
  async Initialise() {
11
17
  if (!Cookies.has(Constants.LOGIN_LOGGED_USER_EXPIRY_COOKIE_NAME)) {
12
18
  return null;
@@ -63,19 +69,20 @@ export default class User {
63
69
  * This wil fetch the user's country
64
70
  */
65
71
  async getGeolocation() {
72
+ const fallbackCountry = this._pageCountry || 'us';
66
73
  try {
67
74
  const response = await fetch(`${Constants.PUBLIC_URL_ORIGIN}/geoip`);
68
75
  if (!response.ok) {
69
- return 'us';
76
+ return fallbackCountry;
70
77
  }
71
78
  const country = await response.json();
72
79
  if (country.error_code) {
73
- return 'us';
80
+ return fallbackCountry;
74
81
  }
75
82
  return country['country'].toLowerCase();
76
83
  }
77
84
  catch {
78
- return 'us';
85
+ return fallbackCountry;
79
86
  }
80
87
  }
81
88
  /** Getting the User's Locale */
@@ -1 +1 @@
1
- {"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,OAAO,MAAM,WAAW,C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gB,GAAG,IAAI,GAAG,CAAC,GAAG,SAAS,CAAC,gBAAgB,GAAG,SAAS,CAAC,cAAc,EAAE,CAAC,CAAC;YAC7F,gBAAgB,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;YACpG,gBAAgB,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAErE,+FAA+F;YAC/F,CAAC,CAAC,EAAE,CAAC,cAAc,GAAG,IAAI,CAAC;YAC3B,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IAED,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,IAAW,WAAW;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AAED,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC","sourcesContent":["import { Constants } from '@repobit/dex-constants';\nimport Cookies from './cookies';\nimport { UserInfoResult } from './typeDefinitions';\nimport UserAgent from './user-agent';\n\nconst w = window as unknown as { BD: {\n loginAttempted: boolean\n} }\n\nexport default class User {\n\n private _info : Promise<UserInfoResult | null> = this.Initialise();\n private _fingerprint: Promise<string | null> = this.getFingerprint();\n private _country : Promise<string> = this.getGeolocation();\n private _locale : Promise<`${string}-${string}`> = this.getUserLocale();\n\n private async Initialise(): Promise<UserInfoResult | null> {\n if (!Cookies.has(Constants.LOGIN_LOGGED_USER_EXPIRY_COOKIE_NAME)) {\n return null;\n }\n\n try {\n const userDataResponse = await fetch(`${Constants.LOGIN_URL_ORIGIN}/bin/login/userInfo.json`);\n return userDataResponse.ok ? (await userDataResponse.json()).result as UserInfoResult : null;\n } catch {\n return null;\n }\n }\n\n private async getFingerprint(): Promise<string | null> {\n // Try to grab the fingeprint from localstoraage\n const storageFingerprint = localStorage.getItem(Constants.FINGERPRINT_LOCAL_STORAGE_NAME);\n if (storageFingerprint) {\n return storageFingerprint;\n }\n\n // Try to grab fingerprint from login data\n const userInfo = await this._info;\n if (userInfo) {\n localStorage.setItem(Constants.FINGERPRINT_LOCAL_STORAGE_NAME, userInfo.fingerprint);\n return userInfo.fingerprint;\n }\n\n // Try to grab fingerprint from dummyPost (from user local antivirus instance)\n const fingerprintNotExist = Cookies.has(Constants.NO_FINGERPRINT_COOKIE_NAME)\n if (!fingerprintNotExist && UserAgent.isWindows) {\n try {\n const fingerprintReq = await fetch(`${Constants.WWW_ONLY_ORIGIN}/site/Main/dummyPost?${Math.random()}`, {\n method : 'POST',\n headers: {\n 'Content-type' : 'application/x-www-form-urlencoded',\n 'Pragma' : 'no-cache',\n 'Cache-Control' : 'no-store, no-cache, must-revalidate, max-age=0',\n 'Expires' : 'Tue, 01 Jan 1971 02:00:00 GMT',\n 'BDUS_A312C09A2666456D9F2B2AA5D6B463D6': 'check.bitdefender'\n }\n });\n\n if (fingerprintReq.ok && fingerprintReq.headers.has(Constants.FINGERPRINT_HEADER)) {\n const fingerprint = fingerprintReq.headers.get(Constants.FINGERPRINT_HEADER) as string;\n localStorage.setItem(Constants.FINGERPRINT_LOCAL_STORAGE_NAME, fingerprint);\n return fingerprint;\n } else {\n Cookies.set(Constants.NO_FINGERPRINT_COOKIE_NAME, 'true', { expires: 1 });\n }\n } catch { /* empty */ }\n }\n\n return null;\n }\n\n /**\n * Handling User Geolocation\n * This wil fetch the user's country\n */\n private async getGeolocation(): Promise<string> {\n try {\n const response = await fetch(`${Constants.PUBLIC_URL_ORIGIN}/geoip`);\n\n if (!response.ok) {\n return 'us';\n }\n\n const country = await response.json();\n if (country.error_code) {\n return 'us';\n }\n\n return country['country'].toLowerCase();\n\n } catch {\n return 'us';\n }\n }\n\n /** Getting the User's Locale */\n private async getUserLocale(): Promise<`${string}-${string}`> {\n const userCountry = await this._country;\n try {\n const userGeoIpCall = await fetch(`${Constants.WWW_ONLY_ORIGIN}/p-api/v1/countries/${userCountry.toUpperCase()}/locales`);\n const userGeoIpData = await userGeoIpCall.json();\n return userGeoIpData[0].locale.toLowerCase();\n } catch {\n return 'en-us'\n }\n }\n\n /** attempt to log the user in.\n * You can access it from the mega menu if it is imported.\n * If the login fails, this operation will not be permited in the same tab session. */\n public async login(): Promise<void> {\n const loginAttempt = sessionStorage.getItem(Constants.LOGIN_ATTEMPT_SESSION_STORAGE_KEY);\n const userData = await this._info;\n const userLoggedInExpirationDate = Number(Cookies.get(Constants.LOGIN_LOGGED_USER_EXPIRY_COOKIE_NAME)) || 0;\n\n if (!loginAttempt && !userData\n && userLoggedInExpirationDate > Date.now()) {\n sessionStorage.setItem(Constants.LOGIN_ATTEMPT_SESSION_STORAGE_KEY, 'true');\n const loginEndpointUrl = new URL(`${Constants.LOGIN_URL_ORIGIN}${Constants.LOGIN_ENDPOINT}`);\n loginEndpointUrl.searchParams.set('origin', `${window.location.pathname}${window.location.search}`);\n loginEndpointUrl.searchParams.set('adobe_mc_ref', document.referrer);\n\n // variable which ensures no Page Loaded Event sent to analytics on window.location.href change\n w.BD.loginAttempted = true;\n window.location.replace(loginEndpointUrl.href);\n }\n }\n\n public get info() {\n return this._info;\n }\n\n public get fingerprint() {\n return this._fingerprint;\n }\n\n public get country() {\n return this._country;\n }\n\n public get locale() {\n return this._locale;\n }\n}\n\nw.BD = w.BD || {};"]}
1
+ {"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,OAAO,MAAM,WAAW,CAAC;AAEhC,OAAO,SA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AC;QAE5G,IAAI,CAAC,YAAY,IAAI,CAAC,QAAQ;eACzB,0BAA0B,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;YAC7C,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,iCAAiC,EAAE,MAAM,CAAC,CAAC;YAC5E,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,GAAG,SAAS,CAAC,gBAAgB,GAAG,SAAS,CAAC,cAAc,EAAE,CAAC,CAAC;YAC7F,gBAAgB,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;YACpG,gBAAgB,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAErE,+FAA+F;YAC/F,CAAC,CAAC,EAAE,CAAC,cAAc,GAAG,IAAI,CAAC;YAC3B,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IAED,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,IAAW,WAAW;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AAED,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC","sourcesContent":["import { Constants } from '@repobit/dex-constants';\nimport Cookies from './cookies';\nimport { UserInfoResult } from './typeDefinitions';\nimport UserAgent from './user-agent';\n\nconst w = window as unknown as { BD: {\n loginAttempted: boolean\n} }\n\nexport default class User {\n\n private _info : Promise<UserInfoResult | null> = this.Initialise();\n private _fingerprint: Promise<string | null> = this.getFingerprint();\n private _pageCountry: string | undefined;\n private _country : Promise<string>\n private _locale : Promise<`${string}-${string}`>;\n\n constructor(pageCountry?: string) {\n this._pageCountry = pageCountry;\n this._country = this.getGeolocation();\n this._locale = this.getUserLocale();\n }\n\n private async Initialise(): Promise<UserInfoResult | null> {\n if (!Cookies.has(Constants.LOGIN_LOGGED_USER_EXPIRY_COOKIE_NAME)) {\n return null;\n }\n\n try {\n const userDataResponse = await fetch(`${Constants.LOGIN_URL_ORIGIN}/bin/login/userInfo.json`);\n return userDataResponse.ok ? (await userDataResponse.json()).result as UserInfoResult : null;\n } catch {\n return null;\n }\n }\n\n private async getFingerprint(): Promise<string | null> {\n // Try to grab the fingeprint from localstoraage\n const storageFingerprint = localStorage.getItem(Constants.FINGERPRINT_LOCAL_STORAGE_NAME);\n if (storageFingerprint) {\n return storageFingerprint;\n }\n\n // Try to grab fingerprint from login data\n const userInfo = await this._info;\n if (userInfo) {\n localStorage.setItem(Constants.FINGERPRINT_LOCAL_STORAGE_NAME, userInfo.fingerprint);\n return userInfo.fingerprint;\n }\n\n // Try to grab fingerprint from dummyPost (from user local antivirus instance)\n const fingerprintNotExist = Cookies.has(Constants.NO_FINGERPRINT_COOKIE_NAME)\n if (!fingerprintNotExist && UserAgent.isWindows) {\n try {\n const fingerprintReq = await fetch(`${Constants.WWW_ONLY_ORIGIN}/site/Main/dummyPost?${Math.random()}`, {\n method : 'POST',\n headers: {\n 'Content-type' : 'application/x-www-form-urlencoded',\n 'Pragma' : 'no-cache',\n 'Cache-Control' : 'no-store, no-cache, must-revalidate, max-age=0',\n 'Expires' : 'Tue, 01 Jan 1971 02:00:00 GMT',\n 'BDUS_A312C09A2666456D9F2B2AA5D6B463D6': 'check.bitdefender'\n }\n });\n\n if (fingerprintReq.ok && fingerprintReq.headers.has(Constants.FINGERPRINT_HEADER)) {\n const fingerprint = fingerprintReq.headers.get(Constants.FINGERPRINT_HEADER) as string;\n localStorage.setItem(Constants.FINGERPRINT_LOCAL_STORAGE_NAME, fingerprint);\n return fingerprint;\n } else {\n Cookies.set(Constants.NO_FINGERPRINT_COOKIE_NAME, 'true', { expires: 1 });\n }\n } catch { /* empty */ }\n }\n\n return null;\n }\n\n /**\n * Handling User Geolocation\n * This wil fetch the user's country\n */\n private async getGeolocation(): Promise<string> {\n const fallbackCountry = this._pageCountry || 'us';\n\n try {\n const response = await fetch(`${Constants.PUBLIC_URL_ORIGIN}/geoip`);\n if (!response.ok) {\n return fallbackCountry;\n }\n\n const country = await response.json();\n if (country.error_code) {\n return fallbackCountry;\n }\n\n return country['country'].toLowerCase();\n\n } catch {\n return fallbackCountry;\n }\n }\n\n /** Getting the User's Locale */\n private async getUserLocale(): Promise<`${string}-${string}`> {\n const userCountry = await this._country;\n try {\n const userGeoIpCall = await fetch(`${Constants.WWW_ONLY_ORIGIN}/p-api/v1/countries/${userCountry.toUpperCase()}/locales`);\n const userGeoIpData = await userGeoIpCall.json();\n return userGeoIpData[0].locale.toLowerCase();\n } catch {\n return 'en-us'\n }\n }\n\n /** attempt to log the user in.\n * You can access it from the mega menu if it is imported.\n * If the login fails, this operation will not be permited in the same tab session. */\n public async login(): Promise<void> {\n const loginAttempt = sessionStorage.getItem(Constants.LOGIN_ATTEMPT_SESSION_STORAGE_KEY);\n const userData = await this._info;\n const userLoggedInExpirationDate = Number(Cookies.get(Constants.LOGIN_LOGGED_USER_EXPIRY_COOKIE_NAME)) || 0;\n\n if (!loginAttempt && !userData\n && userLoggedInExpirationDate > Date.now()) {\n sessionStorage.setItem(Constants.LOGIN_ATTEMPT_SESSION_STORAGE_KEY, 'true');\n const loginEndpointUrl = new URL(`${Constants.LOGIN_URL_ORIGIN}${Constants.LOGIN_ENDPOINT}`);\n loginEndpointUrl.searchParams.set('origin', `${window.location.pathname}${window.location.search}`);\n loginEndpointUrl.searchParams.set('adobe_mc_ref', document.referrer);\n\n // variable which ensures no Page Loaded Event sent to analytics on window.location.href change\n w.BD.loginAttempted = true;\n window.location.replace(loginEndpointUrl.href);\n }\n }\n\n public get info() {\n return this._info;\n }\n\n public get fingerprint() {\n return this._fingerprint;\n }\n\n public get country() {\n return this._country;\n }\n\n public get locale() {\n return this._locale;\n }\n}\n\nw.BD = w.BD || {};"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@repobit/dex-utils",
3
- "version": "2.2.32",
3
+ "version": "2.3.1",
4
4
  "description": "Client for Utils",
5
5
  "author": "Constantin Ioan Mihai <iconstantin@bitdefender.com>",
6
6
  "homepage": "https://github.com/bitdefender/dex-core#readme",
@@ -30,7 +30,7 @@
30
30
  "type": "module",
31
31
  "types": "dist/src/index.d.ts",
32
32
  "dependencies": {
33
- "@repobit/dex-constants": "2.1.31",
33
+ "@repobit/dex-constants": "2.1.33",
34
34
  "js-cookie": "^3.0.5"
35
35
  },
36
36
  "volta": {
@@ -39,5 +39,5 @@
39
39
  "devDependencies": {
40
40
  "@types/js-cookie": "^3.0.6"
41
41
  },
42
- "gitHead": "7a5b68c532b9f3174a306bcf826672da421b1d2c"
42
+ "gitHead": "81584423e16ae1ca612de9c236fa98707297bc04"
43
43
  }