@usenotra/geo
Version:
Request capture SDK for AI traffic attribution and agent feedback collection
129 lines (127 loc) • 3.72 kB
TypeScript
type AiAgentCategory = "training-crawler" | "search-index" | "assistant-browse";
type AiAgentConfidence = "verified" | "reported" | "heuristic";
type AiAgentMatchMode = "contains" | "exact";
interface AiAgentSignature {
agent: string;
vendor: string;
category: AiAgentCategory;
userAgents: string[];
match?: AiAgentMatchMode;
confidence: AiAgentConfidence;
verification: string | null;
source: string;
}
interface AiAgentMatch {
agent: string;
vendor: string;
category: AiAgentCategory;
confidence: AiAgentConfidence;
}
interface GeoLocation {
country?: string;
region?: string;
city?: string;
timezone?: string;
latitude?: string;
longitude?: string;
}
interface GeoRequestSignals {
clientHints: boolean;
fetchMode: string | null;
tracing: boolean;
prefetch?: boolean;
}
interface GeoRequestPayload {
timestamp?: string;
method: string;
url: string;
ip?: string;
geo?: GeoLocation;
referer?: string;
userAgent?: string;
accept?: string;
acceptLanguage?: string;
requestId?: string;
status?: number;
signals?: GeoRequestSignals;
}
interface TagMarkdownLinksOptions {
host?: string;
}
interface TagHtmlLinksOptions {
host?: string;
}
type GeoPathRule = string | RegExp | ((request: Request, url: URL) => boolean);
type GeoExcludeRule = GeoPathRule;
interface GeoTagLinksConfig {
host?: string;
paths?: (string | RegExp)[];
html?: boolean;
}
type GeoTagLinksOption = boolean | GeoTagLinksConfig;
interface GeoTagResponseOptions {
fetch?: typeof fetch;
onError?: (error: unknown) => void;
exclude?: GeoExcludeRule[];
}
type GeoTagMode = "markdown" | "html";
interface GeoTrackerOptions {
token: string;
endpoint?: string;
exclude?: GeoExcludeRule[];
sample?: number;
onError?: (error: unknown) => void;
fetch?: typeof fetch;
}
interface GeoNextOptions extends GeoTrackerOptions {
tagLinks?: GeoTagLinksOption;
}
type WaitUntil = (promise: Promise<unknown>) => void;
interface GeoReactRouterOptions extends GeoTrackerOptions {
waitUntil?: WaitUntil;
}
interface ReactRouterMiddlewareArgs {
request: Request;
}
interface WaitUntilContext {
waitUntil(promise: Promise<unknown>): void;
}
interface NetlifyGeoContext {
city?: string;
country?: {
code?: string;
};
subdivision?: {
code?: string;
};
timezone?: string;
latitude?: number;
longitude?: number;
}
interface NetlifyContext {
waitUntil?(promise: Promise<unknown>): void;
geo?: NetlifyGeoContext;
}
interface NodeRequestLike {
method?: string;
url?: string;
headers: Record<string, string | string[] | undefined>;
}
interface NitroEventLike {
node?: {
req: NodeRequestLike;
};
request?: Request;
}
interface TanStackMiddlewareContext<T> {
request: Request;
next(): T | Promise<T>;
}
interface AstroMiddlewareContext {
request: Request;
}
interface SvelteKitHandleInput<TEvent, TResponse> {
event: TEvent;
resolve(event: TEvent): TResponse | Promise<TResponse>;
}
export type { AstroMiddlewareContext as A, GeoTrackerOptions as G, NetlifyContext as N, ReactRouterMiddlewareArgs as R, SvelteKitHandleInput as S, TagHtmlLinksOptions as T, WaitUntilContext as W, AiAgentMatch as a, GeoExcludeRule as b, GeoPathRule as c, GeoRequestPayload as d, GeoTagLinksOption as e, GeoTagLinksConfig as f, GeoTagMode as g, GeoTagResponseOptions as h, GeoLocation as i, GeoNextOptions as j, GeoRequestSignals as k, TagMarkdownLinksOptions as l, WaitUntil as m, NitroEventLike as n, GeoReactRouterOptions as o, AiAgentSignature as p, TanStackMiddlewareContext as q };