import { getDeviceInfo } from "../device.ts" import type { DeviceInfo } from "../device.ts" import { getFeatureFlags } from "../feature.ts" import type { FeatureFlags } from "../feature.ts" import { getGeoInfo } from "../geo.ts" import type { GeoInfo } from "../geo.ts" import { getRuntimeFlags } from "../runtime.ts" import type { RuntimeFlags } from "../runtime.ts" import { getVariablesHosted } from "../variable/variable.node.ts" import type { AnyVariables } from "../variable/variable.node.ts" /** * @description Describe a consolidated environment snapshot. */ export interface Snapshot { geo: GeoInfo device: DeviceInfo runtime: RuntimeFlags feature: FeatureFlags variables: AnyVariables timestamp: number } /** * @description Collect a consolidated environment snapshot. */ export const getSnapshot = async (): Promise => { const geoInfo = await getGeoInfo() const deviceInfo = getDeviceInfo(navigator.userAgent) const runtimeFlags = getRuntimeFlags() const featureFlags = getFeatureFlags() const variables = getVariablesHosted() const timestamp = Date.now() return { geo: geoInfo, device: deviceInfo, runtime: runtimeFlags, feature: featureFlags, variables, timestamp, } } /** * @description Print the consolidated environment snapshot to console. */ export const printSnapshot = async (): Promise => { const snap = await getSnapshot() console.group("[detect]") console.table(snap.geo) console.table(snap.device) console.table(snap.runtime) console.table(snap.feature) console.table(snap.variables) console.log("time:", new Date(snap.timestamp).toISOString()) console.groupEnd() }