UNPKG

sadbot

Version:

SadBot is a tooling _to thwart_ (someone/"somebot") from accomplishing an action in a given resource, it blocks, throttles and time-restricts the access like a security guard guy when the party is packed or you're not so sober to be welcome.

52 lines (51 loc) 1.7 kB
import { SadBotBase, SadBotBaseParams } from './SadBotBase'; export declare const enum ThrottlingTimeSpan { Seconds = 1, Minutes = 60, Hours = 3600, Days = 86400 } export interface ThrottlingConstraint { constraint: () => string; maxRequests: number; timeValue: number; timeSpan: ThrottlingTimeSpan; } export declare class ThrottlingConstraintBuilder { private constraint; private maxRequests; private timeValue; private timeSpan; by: (fn: () => string) => this; limitRequestsTo: (totalRequests: number) => this; duration: (perValue: number) => this; seconds: () => this; second: () => this; minutes: () => this; minute: () => this; hours: () => this; hour: () => this; days: () => this; day: () => this; build: () => { constraint: () => string; maxRequests: number; timeSpan: ThrottlingTimeSpan; timeValue: number; }; } export declare class RequestLimitExceeded extends Error { constructor(resourceId: string, currentRate: number); } export declare class Throttling extends SadBotBase { prefix: string; maxKeys: number; private configure; constructor(params: SadBotBaseParams | undefined, fn: (conf: ThrottlingConstraintBuilder) => ThrottlingConstraintBuilder); hashedResourceId: (resourceId: string) => string; hashedPrefix: (resourceId: string) => string; touchInputRequest: (resourceId: string, expiration?: number) => Promise<string | null>; rate: (resourceId: string) => Promise<number>; throttleBy: (fn: () => string) => Promise<void>; throttle: () => Promise<void>; }