11import fetch from 'node-fetch'
2+ import { type Geolocation , mockLocation } from '@netlify/dev-utils'
23
34const API_URL = 'https://netlifind.netlify.app'
45const STATE_GEO_PROPERTY = 'geolocation'
@@ -8,35 +9,13 @@ const CACHE_TTL = 8.64e7
89// 10 seconds
910const REQUEST_TIMEOUT = 1e4
1011
11- export type Geolocation = {
12- city : string
13- country : {
14- code : string
15- name : string
16- }
17- subdivision : {
18- code : string
19- name : string
20- }
21- longitude : number
22- latitude : number
23- timezone : string
24- }
12+ export { Geolocation }
2513
2614interface State {
2715 get ( key : string ) : unknown
2816 set ( key : string , value : unknown ) : void
2917}
3018
31- export const mockLocation : Geolocation = {
32- city : 'San Francisco' ,
33- country : { code : 'US' , name : 'United States' } ,
34- subdivision : { code : 'CA' , name : 'California' } ,
35- longitude : 0 ,
36- latitude : 0 ,
37- timezone : 'UTC' ,
38- }
39-
4019/**
4120 * Returns geolocation data from a remote API, the local cache, or a mock location, depending on the
4221 * specified mode.
@@ -63,7 +42,7 @@ export const getGeoLocation = async ({
6342 // `cache`, let's try to use it.
6443 // Or, if the country we're trying to mock is the same one as we have in the
6544 // cache, let's use the cache instead of the mock.
66- if ( cacheObject !== undefined && ( mode === 'cache' || cacheObject . data . country . code === geoCountry ) ) {
45+ if ( cacheObject !== undefined && ( mode === 'cache' || cacheObject . data . country ? .code === geoCountry ) ) {
6746 const age = Date . now ( ) - cacheObject . timestamp
6847
6948 // Let's use the cached data if it's not older than the TTL. Also, if the
0 commit comments