@lock-sdk/geo-block
Version:
Geographic blocking module for Lock security framework
95 lines (86 loc) • 2.82 kB
TypeScript
import * as _lock_sdk_core from '@lock-sdk/core';
declare enum GeoBlockEventType {
GEO_BLOCKED = "geo.blocked"
}
type GeoStorage = 'memory' | 'redis' | 'upstash';
interface GeoBlockConfig {
mode: 'whitelist' | 'blacklist';
countries: string[];
provider: 'maxmind' | 'ipapi' | 'ipstack';
storage?: GeoStorage;
maxmindDbPath?: string;
apiKey?: string;
customLookup?: (ip: string) => Promise<GeoInfo>;
ipHeaders?: string[];
useRemoteAddress?: boolean;
blockStatusCode?: number;
blockMessage?: string;
cacheTtl?: number;
cacheSize?: number;
failBehavior?: 'open' | 'closed';
redis?: {
url?: string;
host?: string;
port?: number;
username?: string;
password?: string;
database?: number;
keyPrefix?: string;
};
upstash?: {
url: string;
token: string;
keyPrefix?: string;
};
}
interface GeoInfo {
country?: string;
region?: string;
city?: string;
latitude?: number;
longitude?: number;
}
interface GeoLookupProvider {
init(): Promise<void>;
lookup(ip: string): Promise<GeoInfo>;
}
declare function extractIp(request: any, ipHeaders?: string[], useRemoteAddress?: boolean): string | null;
declare class MemoryGeoCacheStore implements GeoCacheStore {
private cache;
constructor(config: GeoBlockConfig);
init(): Promise<void>;
get(ip: string): Promise<GeoInfo | null>;
set(ip: string, value: GeoInfo): Promise<void>;
close(): Promise<void>;
}
declare class RedisGeoCacheStore implements GeoCacheStore {
private client;
private keyPrefix;
private config;
private ttl;
constructor(config: GeoBlockConfig);
init(): Promise<void>;
get(ip: string): Promise<GeoInfo | null>;
set(ip: string, value: GeoInfo): Promise<void>;
close(): Promise<void>;
}
declare class UpstashGeoCacheStore implements GeoCacheStore {
private client;
private keyPrefix;
private config;
private ttl;
constructor(config: GeoBlockConfig);
init(): Promise<void>;
get(ip: string): Promise<GeoInfo | null>;
set(ip: string, value: GeoInfo): Promise<void>;
close(): Promise<void>;
}
interface GeoCacheStore {
init(): Promise<void>;
get(ip: string): Promise<GeoInfo | null>;
set(ip: string, value: GeoInfo): Promise<void>;
close(): Promise<void>;
}
declare function createCacheStore(config: GeoBlockConfig): Promise<GeoCacheStore>;
declare const geoBlock: (config?: Partial<GeoBlockConfig> | undefined) => _lock_sdk_core.SecurityModule;
export { type GeoBlockConfig, GeoBlockEventType, type GeoCacheStore, type GeoInfo, type GeoLookupProvider, type GeoStorage, MemoryGeoCacheStore, RedisGeoCacheStore, UpstashGeoCacheStore, createCacheStore, extractIp, geoBlock };