@playpilot/tpi 6.2.1 → 6.2.3

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": "@playpilot/tpi",
3
- "version": "6.2.1",
3
+ "version": "6.2.3",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -10,12 +10,14 @@ export async function getRegionBasedOnIp(timeout = 5000): Promise<string> {
10
10
 
11
11
  const data: { ip: string, country: string } = await response.json()
12
12
 
13
- const country = data?.country?.toLowerCase()
14
- if (!country) throw new Error('No country was returned by api.country.is')
13
+ let region = data?.country?.toLowerCase()
14
+ if (!region) throw new Error('No country was returned by api.country.is')
15
15
 
16
- setSavedRegion(country)
16
+ if (region === 'gb') region = 'uk'
17
17
 
18
- return country
18
+ setSavedRegion(region)
19
+
20
+ return region
19
21
  } catch (error: any) {
20
22
  track(TrackingEvent.RegionRequestFailed, null, { message: error.message })
21
23
 
@@ -72,12 +72,12 @@
72
72
 
73
73
  window.PlayPilotLinkInjections.config = config
74
74
 
75
- isUrlExcluded = !!(config?.exclude_urls_pattern && url.match(new RegExp(config.exclude_urls_pattern)))
76
- if (isUrlExcluded) return
77
-
78
75
  if (config?.custom_style) insertCustomStyle(config.custom_style || '')
79
76
  if (config?.explore_navigation_selector) insertExploreIntoNavigation()
80
77
 
78
+ isUrlExcluded = !!(config?.exclude_urls_pattern && url.match(new RegExp(config.exclude_urls_pattern)))
79
+ if (isUrlExcluded) return
80
+
81
81
  setElements(config?.html_selector || '', config?.exclude_elements_selector || '')
82
82
  } catch(error) {
83
83
  // We return if the config did not get fetched properly, as we can't determine what should and should
@@ -87,4 +87,10 @@ describe('getRegionBasedOnIp', () => {
87
87
 
88
88
  vi.useRealTimers()
89
89
  })
90
+
91
+ it('Should use uk region when GB is returned by api endpoint', async () => {
92
+ fakeFetch({ response: { ip: '127.0.0.1', country: 'GB' } })
93
+
94
+ expect(await getRegionBasedOnIp()).toBe('uk')
95
+ })
90
96
  })