11import type { Context } from '@netlify/types'
22
3+ import { LocalState } from './local-state.js'
4+
35export type Geolocation = Context [ 'geo' ]
46
57export const mockLocation : Geolocation = {
@@ -19,11 +21,6 @@ const CACHE_TTL = 8.64e7
1921// 10 seconds
2022const REQUEST_TIMEOUT = 1e4
2123
22- interface State {
23- get ( key : string ) : unknown
24- set ( key : string , value : unknown ) : void
25- }
26-
2724/**
2825 * Returns geolocation data from a remote API, the local cache, or a mock location, depending on the
2926 * specified mode.
@@ -37,7 +34,7 @@ export const getGeoLocation = async ({
3734 mode : 'cache' | 'update' | 'mock'
3835 geoCountry ?: string | undefined
3936 offline ?: boolean | undefined
40- state : State
37+ state : LocalState
4138} ) : Promise < Geolocation > => {
4239 // Early return for pure mock mode (no geoCountry, no offline)
4340 if ( mode === 'mock' && ! geoCountry && ! offline ) {
@@ -63,14 +60,15 @@ export const getGeoLocation = async ({
6360 }
6461 }
6562
66- // If `--country` was used, we also set `--mode=mock`.
63+ // If a country code was provided, we use mock mode to generate
64+ // location data for that country.
6765 if ( geoCountry ) {
6866 mode = 'mock'
6967 }
7068
71- // If the `--geo` option is set to `mock`, we use the default mock location.
72- // If the `-- offline` option was used, we can't talk to the API, so let's
73- // also use the mock location. Otherwise, use the country code passed in by
69+ // If the mode is set to `mock`, we use the default mock location.
70+ // If the `offline` option was used, we can't talk to the API, so let's
71+ // also use the mock location. Otherwise, use the country code passed in by
7472 // the user.
7573 if ( mode === 'mock' || offline || geoCountry ) {
7674 if ( geoCountry ) {
0 commit comments