UNPKG

@arcjet/ip

Version:

Arcjet utilities for finding the originating IP of a request

39 lines (38 loc) 1.03 kB
declare abstract class CIDR { abstract type: "v4" | "v6"; abstract partSize: 8 | 16; abstract parts: readonly number[]; abstract bits: number; contains(ip: number[]): boolean; } export declare function parseProxy(proxy: string): string | CIDR; interface PartialSocket { remoteAddress?: string; } interface PartialInfo { remoteAddress?: string; } interface PartialIdentiy { sourceIp?: string; } interface PartialRequestContext { identity?: PartialIdentiy; } export type HeaderLike = { headers: Headers; } | { headers: Record<string, string | string[] | undefined>; }; export type RequestLike = { ip?: unknown; socket?: PartialSocket; info?: PartialInfo; requestContext?: PartialRequestContext; } & HeaderLike; export type Platform = "cloudflare" | "fly-io" | "vercel" | "render"; export interface Options { platform?: Platform; proxies?: Array<string | CIDR>; } declare function findIP(request: RequestLike, options?: Options): string; export default findIP;