@netlify/dev-utils
Advanced tools
Comparing version
@@ -21,4 +21,26 @@ import { Context } from '@netlify/types'; | ||
declare class LocalState { | ||
private path; | ||
constructor(cwd: string); | ||
get all(): any; | ||
set all(val: any); | ||
get size(): number; | ||
get(key: any): string | undefined; | ||
set(...args: any[]): void; | ||
has(key: any): boolean; | ||
delete(key: any): void; | ||
clear(): void; | ||
} | ||
type Geolocation = Context['geo']; | ||
declare const mockLocation: Geolocation; | ||
/** | ||
* Returns geolocation data from a remote API, the local cache, or a mock location, depending on the | ||
* specified options. | ||
*/ | ||
declare const getGeoLocation: ({ enabled, cache, state, }: { | ||
enabled?: boolean; | ||
cache?: boolean; | ||
state: LocalState; | ||
}) => Promise<Geolocation>; | ||
@@ -59,15 +81,2 @@ type logFunction = (message?: string) => void; | ||
declare class LocalState { | ||
private path; | ||
constructor(cwd: string); | ||
get all(): any; | ||
set all(val: any); | ||
get size(): number; | ||
get(key: any): string | undefined; | ||
set(...args: any[]): void; | ||
has(key: any): boolean; | ||
delete(key: any): void; | ||
clear(): void; | ||
} | ||
interface CacheEntry<T> { | ||
@@ -200,2 +209,2 @@ enqueued?: boolean; | ||
export { type DevEvent, type DevEventHandler, EventInspector, Fixture, type Geolocation, GlobalConfigStore, HTTPServer, type Handler, LocalState, type Logger, type MemoizeCache, MockFetch, type ProcessRef, createImageServerHandler, createMockLogger, ensureNetlifyIgnore, fromWebResponse, generateImage, getAPIToken, getGlobalConfigStore, getImageResponseSize, headers, killProcess, memoize, mockLocation, netlifyBanner, netlifyCommand, netlifyCyan, renderFunctionErrorPage, resetConfigCache, shouldBase64Encode, toMultiValueHeaders, toWebRequest, watchDebounced }; | ||
export { type DevEvent, type DevEventHandler, EventInspector, Fixture, type Geolocation, GlobalConfigStore, HTTPServer, type Handler, LocalState, type Logger, type MemoizeCache, MockFetch, type ProcessRef, createImageServerHandler, createMockLogger, ensureNetlifyIgnore, fromWebResponse, generateImage, getAPIToken, getGeoLocation, getGlobalConfigStore, getImageResponseSize, headers, killProcess, memoize, mockLocation, netlifyBanner, netlifyCommand, netlifyCyan, renderFunctionErrorPage, resetConfigCache, shouldBase64Encode, toMultiValueHeaders, toWebRequest, watchDebounced }; |
@@ -152,2 +152,41 @@ // src/lib/global-config.ts | ||
}; | ||
var API_URL = "https://netlifind.netlify.app"; | ||
var STATE_GEO_PROPERTY = "geolocation"; | ||
var CACHE_TTL = 864e5; | ||
var REQUEST_TIMEOUT = 1e4; | ||
var getGeoLocation = async ({ | ||
enabled = true, | ||
cache = true, | ||
state | ||
}) => { | ||
if (!enabled) { | ||
return mockLocation; | ||
} | ||
const cacheObject = state.get(STATE_GEO_PROPERTY); | ||
if (cacheObject !== void 0 && cache) { | ||
const age = Date.now() - cacheObject.timestamp; | ||
if (age < CACHE_TTL) { | ||
return cacheObject.data; | ||
} | ||
} | ||
try { | ||
const data = await getGeoLocationFromAPI(); | ||
const newCacheObject = { | ||
data, | ||
timestamp: Date.now() | ||
}; | ||
state.set(STATE_GEO_PROPERTY, newCacheObject); | ||
return data; | ||
} catch { | ||
return mockLocation; | ||
} | ||
}; | ||
var getGeoLocationFromAPI = async () => { | ||
const res = await fetch(API_URL, { | ||
method: "GET", | ||
signal: AbortSignal.timeout(REQUEST_TIMEOUT) | ||
}); | ||
const { geo } = await res.json(); | ||
return geo; | ||
}; | ||
@@ -783,2 +822,3 @@ // src/lib/gitignore.ts | ||
getAPIToken, | ||
getGeoLocation, | ||
getGlobalConfigStore, | ||
@@ -785,0 +825,0 @@ getImageResponseSize, |
{ | ||
"name": "@netlify/dev-utils", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "TypeScript utilities for the local emulation of the Netlify environment", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
32316
4.02%1004
5.13%9
12.5%3
50%