@riavzon/bot-detector 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1607 @@
1
+ /// <reference types="node" />
2
+ import z from "zod";
3
+ import maxmind from "maxmind";
4
+ import { RootDatabase } from "lmdb";
5
+ import { Storage } from "unstorage";
6
+ import { IResult } from "ua-parser-js";
7
+ import { Request, RequestHandler } from "express";
8
+ import { BgpRecord, CityGeoRecord, CrawlersRecord, GeoRecord, JA4, ProxyRecord, ThreatRecord, TorRecord, UserAgentRecord } from "@riavzon/shield-base";
9
+ import mysql from "mysql2/promise";
10
+ import postgresql from "db0/connectors/postgresql";
11
+ import betterSqlite3Connector from "db0/connectors/better-sqlite3";
12
+ import cloudflareD1Connector from "db0/connectors/cloudflare-d1";
13
+ import planetscale from "db0/connectors/planetscale";
14
+ import redisDriver from "unstorage/drivers/redis";
15
+ import lruDriver from "unstorage/drivers/lru-cache";
16
+ import fsLiteDriver from "unstorage/drivers/fs-lite";
17
+ import upstashDriver from "unstorage/drivers/upstash";
18
+ import vercelRuntimeCacheDriver from "unstorage/drivers/vercel-runtime-cache";
19
+ import cloudflareR2BindingDriver from "unstorage/drivers/cloudflare-r2-binding";
20
+ import cloudflareKVBindingDriver from "unstorage/drivers/cloudflare-kv-binding";
21
+ import cloudflareKVHTTPDriver from "unstorage/drivers/cloudflare-kv-http";
22
+ import { SendOptions } from "send";
23
+ import { EventEmitter } from "events";
24
+ import * as http from "http";
25
+ import { ParsedQs } from "qs";
26
+ import { Options, Ranges, Result } from "range-parser";
27
+
28
+ //#region src/botDetector/middlewares/canaryCookieChecker.d.ts
29
+ declare global {
30
+ namespace Express {
31
+ interface Request {
32
+ newVisitorId?: string;
33
+ botDetection: {
34
+ success: boolean;
35
+ banned: boolean;
36
+ time: string;
37
+ ipAddress: string;
38
+ };
39
+ }
40
+ }
41
+ }
42
+ declare function validator(buildCustomContext?: (req: Request) => unknown): RequestHandler;
43
+ //#endregion
44
+ //#region src/botDetector/types/dbTypes.d.ts
45
+ type Opts$1<T extends (opts?: any) => any> = NonNullable<Parameters<T>[0]>;
46
+ interface SupportedDbDrivers {
47
+ 'mysql-pool': mysql.PoolOptions;
48
+ postgresql: Opts$1<typeof postgresql>;
49
+ sqlite: Opts$1<typeof betterSqlite3Connector>;
50
+ 'cloudflare-d1': Opts$1<typeof cloudflareD1Connector>;
51
+ planetscale: Opts$1<typeof planetscale>;
52
+ }
53
+ type DbConfig = { [K in keyof SupportedDbDrivers]: {
54
+ driver: K;
55
+ } & SupportedDbDrivers[K] }[keyof SupportedDbDrivers];
56
+ //#endregion
57
+ //#region src/botDetector/types/storageTypes.d.ts
58
+ type Opts<T extends (opts?: any) => any> = NonNullable<Parameters<T>[0]>;
59
+ interface SupportedDrivers {
60
+ upstash: Opts<typeof upstashDriver>;
61
+ 'lru': Opts<typeof lruDriver>;
62
+ redis: Opts<typeof redisDriver>;
63
+ 'fs': Opts<typeof fsLiteDriver>;
64
+ 'cloudflare-kv-binding': Opts<typeof cloudflareKVBindingDriver>;
65
+ 'cloudflare-kv-http': Opts<typeof cloudflareKVHTTPDriver>;
66
+ 'cloudflare-r2-binding': Opts<typeof cloudflareR2BindingDriver>;
67
+ 'vercel': Opts<typeof vercelRuntimeCacheDriver>;
68
+ }
69
+ type CacheConfig = { [K in keyof SupportedDrivers]: {
70
+ driver: K;
71
+ } & SupportedDrivers[K] }[keyof SupportedDrivers];
72
+ //#endregion
73
+ //#region src/botDetector/types/configSchema.d.ts
74
+ declare const configSchema: z.ZodObject<{
75
+ store: z.ZodObject<{
76
+ main: z.ZodNonOptional<z.ZodCustom<DbConfig, DbConfig>>;
77
+ }, z.z.core.$strict>;
78
+ banScore: z.ZodDefault<z.ZodNumber>;
79
+ maxScore: z.ZodDefault<z.ZodNumber>;
80
+ restoredReputationPoints: z.ZodDefault<z.ZodNumber>;
81
+ setNewComputedScore: z.ZodDefault<z.ZodBoolean>;
82
+ whiteList: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodIPv4, z.ZodIPv6, z.ZodString]>>>>;
83
+ checksTimeRateControl: z.ZodPrefault<z.ZodObject<{
84
+ checkEveryRequest: z.ZodDefault<z.ZodBoolean>;
85
+ checkEvery: z.ZodDefault<z.ZodNumber>;
86
+ }, z.z.core.$strip>>;
87
+ batchQueue: z.ZodPrefault<z.ZodObject<{
88
+ flushIntervalMs: z.ZodDefault<z.ZodNumber>;
89
+ maxBufferSize: z.ZodDefault<z.ZodNumber>;
90
+ maxRetries: z.ZodDefault<z.ZodNumber>;
91
+ }, z.z.core.$strip>>;
92
+ storage: z.ZodOptional<z.ZodCustom<CacheConfig, CacheConfig>>;
93
+ checkers: z.ZodObject<{
94
+ localeMapsCheck: z.ZodPrefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
95
+ enable: z.ZodLiteral<false>;
96
+ }, z.z.core.$strip>, z.ZodObject<{
97
+ enable: z.ZodLiteral<true>;
98
+ penalties: z.ZodPrefault<z.ZodObject<{
99
+ ipAndHeaderMismatch: z.ZodDefault<z.ZodNumber>;
100
+ missingHeader: z.ZodDefault<z.ZodNumber>;
101
+ missingGeoData: z.ZodDefault<z.ZodNumber>;
102
+ malformedHeader: z.ZodDefault<z.ZodNumber>;
103
+ }, z.z.core.$strip>>;
104
+ }, z.z.core.$strip>], "enable">>;
105
+ knownBadUserAgents: z.ZodPrefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
106
+ enable: z.ZodLiteral<false>;
107
+ }, z.z.core.$strip>, z.ZodObject<{
108
+ enable: z.ZodLiteral<true>;
109
+ penalties: z.ZodPrefault<z.ZodObject<{
110
+ criticalSeverity: z.ZodDefault<z.ZodNumber>;
111
+ highSeverity: z.ZodDefault<z.ZodNumber>;
112
+ mediumSeverity: z.ZodDefault<z.ZodNumber>;
113
+ lowSeverity: z.ZodDefault<z.ZodNumber>;
114
+ }, z.z.core.$strip>>;
115
+ }, z.z.core.$strip>], "enable">>;
116
+ enableIpChecks: z.ZodPrefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
117
+ enable: z.ZodLiteral<false>;
118
+ }, z.z.core.$strip>, z.ZodObject<{
119
+ enable: z.ZodLiteral<true>;
120
+ penalties: z.ZodDefault<z.ZodNumber>;
121
+ }, z.z.core.$strip>], "enable">>;
122
+ enableGoodBotsChecks: z.ZodPrefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
123
+ enable: z.ZodLiteral<false>;
124
+ }, z.z.core.$strip>, z.ZodObject<{
125
+ enable: z.ZodLiteral<true>;
126
+ banUnlistedBots: z.ZodDefault<z.ZodBoolean>;
127
+ penalties: z.ZodDefault<z.ZodNumber>;
128
+ }, z.z.core.$strip>], "enable">>;
129
+ enableBehaviorRateCheck: z.ZodPrefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
130
+ enable: z.ZodLiteral<false>;
131
+ }, z.z.core.$strip>, z.ZodObject<{
132
+ enable: z.ZodLiteral<true>;
133
+ behavioral_window: z.ZodDefault<z.ZodNumber>;
134
+ behavioral_threshold: z.ZodDefault<z.ZodNumber>;
135
+ penalties: z.ZodDefault<z.ZodNumber>;
136
+ }, z.z.core.$strip>], "enable">>;
137
+ enableProxyIspCookiesChecks: z.ZodPrefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
138
+ enable: z.ZodLiteral<false>;
139
+ }, z.z.core.$strip>, z.ZodObject<{
140
+ enable: z.ZodLiteral<true>;
141
+ penalties: z.ZodPrefault<z.ZodObject<{
142
+ cookieMissing: z.ZodDefault<z.ZodNumber>;
143
+ proxyDetected: z.ZodDefault<z.ZodNumber>;
144
+ multiSourceBonus2to3: z.ZodDefault<z.ZodNumber>;
145
+ multiSourceBonus4plus: z.ZodDefault<z.ZodNumber>;
146
+ hostingDetected: z.ZodDefault<z.ZodNumber>;
147
+ ispUnknown: z.ZodDefault<z.ZodNumber>;
148
+ orgUnknown: z.ZodDefault<z.ZodNumber>;
149
+ }, z.z.core.$strip>>;
150
+ }, z.z.core.$strip>], "enable">>;
151
+ enableUaAndHeaderChecks: z.ZodPrefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
152
+ enable: z.ZodLiteral<false>;
153
+ }, z.z.core.$strip>, z.ZodObject<{
154
+ enable: z.ZodLiteral<true>;
155
+ penalties: z.ZodPrefault<z.ZodObject<{
156
+ headlessBrowser: z.ZodDefault<z.ZodNumber>;
157
+ shortUserAgent: z.ZodDefault<z.ZodNumber>;
158
+ tlsCheckFailed: z.ZodDefault<z.ZodNumber>;
159
+ badUaChecker: z.ZodDefault<z.ZodBoolean>;
160
+ }, z.z.core.$strip>>;
161
+ }, z.z.core.$strip>], "enable">>;
162
+ enableBrowserAndDeviceChecks: z.ZodPrefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
163
+ enable: z.ZodLiteral<false>;
164
+ }, z.z.core.$strip>, z.ZodObject<{
165
+ enable: z.ZodLiteral<true>;
166
+ penalties: z.ZodPrefault<z.ZodObject<{
167
+ cliOrLibrary: z.ZodDefault<z.ZodNumber>;
168
+ internetExplorer: z.ZodDefault<z.ZodNumber>;
169
+ linuxOs: z.ZodDefault<z.ZodNumber>;
170
+ impossibleBrowserCombinations: z.ZodDefault<z.ZodNumber>;
171
+ browserTypeUnknown: z.ZodDefault<z.ZodNumber>;
172
+ browserNameUnknown: z.ZodDefault<z.ZodNumber>;
173
+ desktopWithoutOS: z.ZodDefault<z.ZodNumber>;
174
+ deviceVendorUnknown: z.ZodDefault<z.ZodNumber>;
175
+ browserVersionUnknown: z.ZodDefault<z.ZodNumber>;
176
+ deviceModelUnknown: z.ZodDefault<z.ZodNumber>;
177
+ }, z.z.core.$strip>>;
178
+ }, z.z.core.$strip>], "enable">>;
179
+ enableGeoChecks: z.ZodPrefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
180
+ enable: z.ZodLiteral<false>;
181
+ }, z.z.core.$strip>, z.ZodObject<{
182
+ enable: z.ZodLiteral<true>;
183
+ bannedCountries: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString>>>;
184
+ penalties: z.ZodPrefault<z.ZodObject<{
185
+ countryUnknown: z.ZodDefault<z.ZodNumber>;
186
+ regionUnknown: z.ZodDefault<z.ZodNumber>;
187
+ latLonUnknown: z.ZodDefault<z.ZodNumber>;
188
+ districtUnknown: z.ZodDefault<z.ZodNumber>;
189
+ cityUnknown: z.ZodDefault<z.ZodNumber>;
190
+ timezoneUnknown: z.ZodDefault<z.ZodNumber>;
191
+ subregionUnknown: z.ZodDefault<z.ZodNumber>;
192
+ phoneUnknown: z.ZodDefault<z.ZodNumber>;
193
+ continentUnknown: z.ZodDefault<z.ZodNumber>;
194
+ }, z.z.core.$strip>>;
195
+ }, z.z.core.$strip>], "enable">>;
196
+ enableKnownThreatsDetections: z.ZodPrefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
197
+ enable: z.ZodLiteral<false>;
198
+ }, z.z.core.$strip>, z.ZodObject<{
199
+ enable: z.ZodLiteral<true>;
200
+ penalties: z.ZodPrefault<z.ZodObject<{
201
+ anonymiseNetwork: z.ZodDefault<z.ZodNumber>;
202
+ threatLevels: z.ZodPrefault<z.ZodObject<{
203
+ criticalLevel1: z.ZodDefault<z.ZodNumber>;
204
+ currentAttacksLevel2: z.ZodDefault<z.ZodNumber>;
205
+ threatLevel3: z.ZodDefault<z.ZodNumber>;
206
+ threatLevel4: z.ZodDefault<z.ZodNumber>;
207
+ }, z.z.core.$strip>>;
208
+ }, z.z.core.$strip>>;
209
+ }, z.z.core.$strip>], "enable">>;
210
+ enableAsnClassification: z.ZodPrefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
211
+ enable: z.ZodLiteral<false>;
212
+ }, z.z.core.$strip>, z.ZodObject<{
213
+ enable: z.ZodLiteral<true>;
214
+ penalties: z.ZodPrefault<z.ZodObject<{
215
+ contentClassification: z.ZodDefault<z.ZodNumber>;
216
+ unknownClassification: z.ZodDefault<z.ZodNumber>;
217
+ lowVisibilityPenalty: z.ZodDefault<z.ZodNumber>;
218
+ lowVisibilityThreshold: z.ZodDefault<z.ZodNumber>;
219
+ comboHostingLowVisibility: z.ZodDefault<z.ZodNumber>;
220
+ }, z.z.core.$strip>>;
221
+ }, z.z.core.$strip>], "enable">>;
222
+ enableTorAnalysis: z.ZodPrefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
223
+ enable: z.ZodLiteral<false>;
224
+ }, z.z.core.$strip>, z.ZodObject<{
225
+ enable: z.ZodLiteral<true>;
226
+ penalties: z.ZodPrefault<z.ZodObject<{
227
+ runningNode: z.ZodDefault<z.ZodNumber>;
228
+ exitNode: z.ZodDefault<z.ZodNumber>;
229
+ webExitCapable: z.ZodDefault<z.ZodNumber>;
230
+ guardNode: z.ZodDefault<z.ZodNumber>;
231
+ badExit: z.ZodDefault<z.ZodNumber>;
232
+ obsoleteVersion: z.ZodDefault<z.ZodNumber>;
233
+ }, z.z.core.$strip>>;
234
+ }, z.z.core.$strip>], "enable">>;
235
+ enableTimezoneConsistency: z.ZodPrefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
236
+ enable: z.ZodLiteral<false>;
237
+ }, z.z.core.$strip>, z.ZodObject<{
238
+ enable: z.ZodLiteral<true>;
239
+ penalties: z.ZodDefault<z.ZodNumber>;
240
+ }, z.z.core.$strip>], "enable">>;
241
+ honeypot: z.ZodPrefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
242
+ enable: z.ZodLiteral<false>;
243
+ }, z.z.core.$strip>, z.ZodObject<{
244
+ enable: z.ZodLiteral<true>;
245
+ paths: z.ZodDefault<z.ZodArray<z.ZodString>>;
246
+ }, z.z.core.$strip>], "enable">>;
247
+ enableSessionCoherence: z.ZodPrefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
248
+ enable: z.ZodLiteral<false>;
249
+ }, z.z.core.$strip>, z.ZodObject<{
250
+ enable: z.ZodLiteral<true>;
251
+ penalties: z.ZodPrefault<z.ZodObject<{
252
+ pathMismatch: z.ZodDefault<z.ZodNumber>;
253
+ missingReferer: z.ZodDefault<z.ZodNumber>;
254
+ domainMismatch: z.ZodDefault<z.ZodNumber>;
255
+ }, z.z.core.$strip>>;
256
+ }, z.z.core.$strip>], "enable">>;
257
+ enableVelocityFingerprint: z.ZodPrefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
258
+ enable: z.ZodLiteral<false>;
259
+ }, z.z.core.$strip>, z.ZodObject<{
260
+ enable: z.ZodLiteral<true>;
261
+ cvThreshold: z.ZodDefault<z.ZodNumber>;
262
+ penalties: z.ZodDefault<z.ZodNumber>;
263
+ }, z.z.core.$strip>], "enable">>;
264
+ enableKnownBadIpsCheck: z.ZodPrefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
265
+ enable: z.ZodLiteral<false>;
266
+ }, z.z.core.$strip>, z.ZodObject<{
267
+ enable: z.ZodLiteral<true>;
268
+ highRiskPenalty: z.ZodDefault<z.ZodNumber>;
269
+ }, z.z.core.$strip>], "enable">>;
270
+ }, z.z.core.$strip>;
271
+ generator: z.ZodPrefault<z.ZodObject<{
272
+ scoreThreshold: z.ZodDefault<z.ZodNumber>;
273
+ generateTypes: z.ZodDefault<z.ZodBoolean>;
274
+ deleteAfterBuild: z.ZodDefault<z.ZodBoolean>;
275
+ mmdbctlPath: z.ZodDefault<z.ZodString>;
276
+ }, z.z.core.$strip>>;
277
+ headerOptions: z.ZodPrefault<z.ZodObject<{
278
+ weightPerMustHeader: z.ZodDefault<z.ZodNumber>;
279
+ missingBrowserEngine: z.ZodDefault<z.ZodNumber>;
280
+ postManOrInsomiaHeaders: z.ZodDefault<z.ZodNumber>;
281
+ AJAXHeaderExists: z.ZodDefault<z.ZodNumber>;
282
+ connectionHeaderIsClose: z.ZodDefault<z.ZodNumber>;
283
+ originHeaderIsNULL: z.ZodDefault<z.ZodNumber>;
284
+ originHeaderMismatch: z.ZodDefault<z.ZodNumber>;
285
+ omittedAcceptHeader: z.ZodDefault<z.ZodNumber>;
286
+ clientHintsMissingForBlink: z.ZodDefault<z.ZodNumber>;
287
+ teHeaderUnexpectedForBlink: z.ZodDefault<z.ZodNumber>;
288
+ clientHintsUnexpectedForGecko: z.ZodDefault<z.ZodNumber>;
289
+ teHeaderMissingForGecko: z.ZodDefault<z.ZodNumber>;
290
+ aggressiveCacheControlOnGet: z.ZodDefault<z.ZodNumber>;
291
+ crossSiteRequestMissingReferer: z.ZodDefault<z.ZodNumber>;
292
+ inconsistentSecFetchMode: z.ZodDefault<z.ZodNumber>;
293
+ hostMismatchWeight: z.ZodDefault<z.ZodNumber>;
294
+ }, z.z.core.$strip>>;
295
+ pathTraveler: z.ZodPrefault<z.ZodObject<{
296
+ maxIterations: z.ZodDefault<z.ZodNumber>;
297
+ maxPathLength: z.ZodDefault<z.ZodNumber>;
298
+ pathLengthToLong: z.ZodDefault<z.ZodNumber>;
299
+ longDecoding: z.ZodDefault<z.ZodNumber>;
300
+ traversalDetected: z.ZodDefault<z.ZodNumber>;
301
+ }, z.z.core.$strip>>;
302
+ punishmentType: z.ZodPrefault<z.ZodObject<{
303
+ enableFireWallBan: z.ZodDefault<z.ZodBoolean>;
304
+ }, z.z.core.$strip>>;
305
+ logLevel: z.ZodDefault<z.ZodEnum<{
306
+ error: "error";
307
+ debug: "debug";
308
+ info: "info";
309
+ warn: "warn";
310
+ fatal: "fatal";
311
+ }>>;
312
+ }, z.z.core.$strip>;
313
+ type BotDetectorConfig = z.infer<typeof configSchema>;
314
+ type BotDetectorConfigInput = z.input<typeof configSchema>;
315
+ //#endregion
316
+ //#region src/botDetector/types/generator.d.ts
317
+ interface BannedRecord {
318
+ range: string;
319
+ score: number;
320
+ country: string | null;
321
+ userAgent: string | null;
322
+ reason: string;
323
+ comment: 'Automatically generated by @riavzon/botDetector';
324
+ }
325
+ interface HighRiskRecord {
326
+ range: string;
327
+ visitorId: string;
328
+ score: number;
329
+ country: string | null;
330
+ region: string | null;
331
+ regionName: string | null;
332
+ city: string | null;
333
+ lat: string | null;
334
+ lon: string | null;
335
+ timezone: string | null;
336
+ isp: string | null;
337
+ org: string | null;
338
+ browser: string | null;
339
+ browserType: string | null;
340
+ browserVersion: string | null;
341
+ os: string | null;
342
+ deviceType: string | null;
343
+ deviceVendor: string | null;
344
+ deviceModel: string | null;
345
+ proxy: boolean;
346
+ hosting: boolean;
347
+ requestCount: number;
348
+ firstSeen: string | null;
349
+ lastSeen: string | null;
350
+ comment: 'Automatically generated by @riavzon/botDetector';
351
+ }
352
+ //#endregion
353
+ //#region src/botDetector/helpers/mmdbDataReaders.d.ts
354
+ type ThreatRecordModified = ThreatRecord & {
355
+ network: string;
356
+ };
357
+ interface DataReaders {
358
+ asnDataBase(ip: string): BgpRecord | null;
359
+ cityDataBase(ip: string): CityGeoRecord | null;
360
+ countryDataBase(ip: string): GeoRecord | null;
361
+ goodBotsDataBase(ip: string): CrawlersRecord | null;
362
+ torDataBase(ip: string): TorRecord | null;
363
+ proxyDataBase(ip: string): ProxyRecord | null;
364
+ fireholAnonDataBase(ip: string): ThreatRecordModified | null;
365
+ fireholLvl1DataBase(ip: string): ThreatRecordModified | null;
366
+ fireholLvl2DataBase(ip: string): ThreatRecordModified | null;
367
+ fireholLvl3DataBase(ip: string): ThreatRecordModified | null;
368
+ fireholLvl4DataBase(ip: string): ThreatRecordModified | null;
369
+ bannedDataBase(ip: string): BannedRecord | null;
370
+ highRiskDataBase(ip: string): HighRiskRecord | null;
371
+ getUserAgentLmdb(): RootDatabase<UserAgentRecord, string>;
372
+ getJa4Lmdb(): RootDatabase<JA4, string>;
373
+ }
374
+ declare class DataSources implements DataReaders {
375
+ private readonly readers;
376
+ private constructor();
377
+ static initialize(): Promise<DataSources>;
378
+ asnDataBase(ip: string): BgpRecord | null;
379
+ cityDataBase(ip: string): CityGeoRecord | null;
380
+ countryDataBase(ip: string): GeoRecord | null;
381
+ goodBotsDataBase(ip: string): CrawlersRecord | null;
382
+ torDataBase(ip: string): TorRecord | null;
383
+ proxyDataBase(ip: string): ProxyRecord | null;
384
+ fireholAnonDataBase(ip: string): ThreatRecordModified | null;
385
+ fireholLvl1DataBase(ip: string): ThreatRecordModified | null;
386
+ fireholLvl2DataBase(ip: string): ThreatRecordModified | null;
387
+ fireholLvl3DataBase(ip: string): ThreatRecordModified | null;
388
+ fireholLvl4DataBase(ip: string): ThreatRecordModified | null;
389
+ bannedDataBase(ip: string): BannedRecord | null;
390
+ highRiskDataBase(ip: string): HighRiskRecord | null;
391
+ getUserAgentLmdb(): RootDatabase<UserAgentRecord, string>;
392
+ getJa4Lmdb(): RootDatabase<JA4, string>;
393
+ }
394
+ //#endregion
395
+ //#region src/botDetector/types/geoTypes.d.ts
396
+ interface GeoResponse {
397
+ country?: string;
398
+ countryCode?: string;
399
+ region?: string;
400
+ regionName?: string;
401
+ subregion?: string;
402
+ state?: string;
403
+ zipCode?: string;
404
+ city?: string;
405
+ phone?: string;
406
+ numericCode?: string;
407
+ native?: string;
408
+ continent?: string;
409
+ capital?: string;
410
+ district?: string;
411
+ lat?: string;
412
+ lon?: string;
413
+ timezone?: string;
414
+ timeZoneName?: string;
415
+ utc_offset?: string;
416
+ tld?: string;
417
+ nationality?: string;
418
+ currency?: string;
419
+ iso639?: string;
420
+ languages?: string;
421
+ isp?: string;
422
+ org?: string;
423
+ as_org?: string;
424
+ proxy?: boolean;
425
+ hosting?: boolean;
426
+ }
427
+ //#endregion
428
+ //#region src/botDetector/types/UAparserTypes.d.ts
429
+ interface ParsedUAResult {
430
+ device: string;
431
+ deviceVendor?: string;
432
+ deviceModel?: string;
433
+ browser?: string;
434
+ browserType?: string;
435
+ browserVersion?: string;
436
+ botAI: boolean;
437
+ bot: boolean;
438
+ os?: string;
439
+ allResults: IResult;
440
+ }
441
+ //#endregion
442
+ //#region src/botDetector/types/botDetectorTypes.d.ts
443
+ interface ValidationContext<TCustom = Record<string, never>> {
444
+ req: Request;
445
+ ipAddress: string;
446
+ parsedUA: Partial<ParsedUAResult>;
447
+ geoData: Partial<GeoResponse>;
448
+ cookie?: string;
449
+ proxy: {
450
+ isProxy: boolean;
451
+ proxyType?: string;
452
+ };
453
+ anon: boolean;
454
+ bgp: Partial<Omit<BgpRecord, 'range'>>;
455
+ tor: Partial<Omit<TorRecord, 'range'>>;
456
+ threatLevel: 1 | 2 | 3 | 4 | null;
457
+ custom: TCustom;
458
+ }
459
+ //#endregion
460
+ //#region src/botDetector/types/checkersTypes.d.ts
461
+ type BanReasonCode = 'IP_INVALID' | 'BEHAVIOR_TOO_FAST' | 'GOOD_BOT_IDENTIFIED' | 'BAD_GOOGLEBOT' | 'SHORT_USER_AGENT' | 'CLI_OR_LIBRARY' | 'KALI_LINUX_OS' | 'INTERNET_EXPLORER' | 'COOKIE_MISSING' | 'BANNED_COUNTRY' | 'COUNTRY_UNKNOWN' | 'PROXY_DETECTED' | 'HOSTING_DETECTED' | 'TIMEZONE_UNKNOWN' | 'ISP_UNKNOWN' | 'REGION_UNKNOWN' | 'LAT_LON_UNKNOWN' | 'ORG_UNKNOWN' | 'DEVICE_TYPE_UNKNOWN' | 'DEVICE_VENDOR_UNKNOWN' | 'BROWSER_TYPE_UNKNOWN' | 'BROWSER_VERSION_UNKNOWN' | 'DISTRICT_UNKNOWN' | 'CITY_UNKNOWN' | 'OS_UNKNOWN' | 'BROWSER_NAME_UNKNOWN' | 'HEADLESS_BROWSER_DETECTED' | 'LOCALE_MISMATCH' | 'TZ_MISMATCH' | 'TLS_CHECK_FAILED' | 'HEADER_SCORE_TOO_HIGH' | 'META_UA_CHECK_FAILED' | 'DESKTOP_WITHOUT_OS' | 'NO_MODEL' | 'XSS SCRIPTING ATTEMPT' | 'PATH_TRAVELER_FOUND' | 'BAD_UA_DETECTED' | 'BAD_BOT_DETECTED' | 'ANONYMITY_NETWORK' | 'FIREHOL_L1_THREAT' | 'FIREHOL_L2_THREAT' | 'FIREHOL_L3_THREAT' | 'FIREHOL_L4_THREAT' | 'ASN_HOSTING_CLASSIFIED' | 'ASN_CLASSIFICATION_UNKNOWN' | 'ASN_LOW_VISIBILITY' | 'ASN_HOSTING_LOW_VISIBILITY_COMBO' | 'TOR_ACTIVE_NODE' | 'TOR_EXIT_NODE' | 'TOR_WEB_EXIT_CAPABLE' | 'TOR_GUARD_NODE' | 'TOR_BAD_EXIT' | 'TOR_OBSOLETE_VERSION' | 'TZ_HEADER_GEO_MISMATCH' | 'HONEYPOT_PATH_HIT' | 'SESSION_COHERENCE_VIOLATION' | 'SESSION_COHERENCE_PATH_MISMATCH' | 'SESSION_COHERENCE_MISSING_REFERER' | 'SESSION_COHERENCE_DOMAIN_MISMATCH' | 'SESSION_COHERENCE_INVALID_REFERER' | 'TIMING_TOO_REGULAR' | 'PREVIOUSLY_BANNED_IP' | 'PREVIOUSLY_HIGH_RISK_IP';
462
+ interface BannedInfo {
463
+ score: number;
464
+ reasons: BanReasonCode[];
465
+ }
466
+ interface IBotChecker<Code, TCustom = Record<string, never>> {
467
+ name: string;
468
+ phase: 'cheap' | 'heavy';
469
+ isEnabled(config: BotDetectorConfig): boolean;
470
+ run(ctx: ValidationContext<TCustom>, config: BotDetectorConfig): Promise<{
471
+ score: number;
472
+ reasons: Code[] | BanReasonCode[];
473
+ }> | {
474
+ score: number;
475
+ reasons: Code[] | BanReasonCode[];
476
+ };
477
+ }
478
+ //#endregion
479
+ //#region src/botDetector/types/fingerPrint.d.ts
480
+ interface userValidation {
481
+ cookie: string | null;
482
+ visitorId: string;
483
+ userAgent: string;
484
+ ipAddress: string;
485
+ country: string | null;
486
+ region: string | null;
487
+ regionName: string | null;
488
+ city: string | null;
489
+ district: string | null;
490
+ lat: string | null;
491
+ lon: string;
492
+ timezone: string | null;
493
+ currency: string | null;
494
+ isp: string | null;
495
+ org: string | null;
496
+ as: string | null;
497
+ device_type: string | null;
498
+ browser: string | null;
499
+ proxy: boolean;
500
+ hosting: boolean;
501
+ is_bot: boolean;
502
+ first_seen: string | null;
503
+ last_seen: string | null;
504
+ request_count: number;
505
+ deviceVendor?: string;
506
+ deviceModel?: string;
507
+ browserType?: string;
508
+ browserVersion?: string;
509
+ os?: string;
510
+ activity_score?: string;
511
+ }
512
+ //#endregion
513
+ //#region src/botDetector/types/batchQueue.d.ts
514
+ interface VisitorUpsertParams {
515
+ insert: userValidation;
516
+ }
517
+ interface ScoreUpdateParams {
518
+ score: number;
519
+ cookie: string;
520
+ }
521
+ interface IsBotUpdateParams {
522
+ isBot: boolean;
523
+ cookie: string;
524
+ }
525
+ interface BannedIpParams {
526
+ cookie: string;
527
+ ipAddress: string;
528
+ country: string;
529
+ user_agent: string;
530
+ info: BannedInfo;
531
+ }
532
+ interface OpParams {
533
+ visitor_upsert: VisitorUpsertParams;
534
+ score_update: ScoreUpdateParams;
535
+ is_bot_update: IsBotUpdateParams;
536
+ update_banned_ip: BannedIpParams;
537
+ }
538
+ type BatchQueueOps = 'visitor_upsert' | 'score_update' | 'is_bot_update' | 'update_banned_ip';
539
+ type Priority = 'immediate' | 'deferred';
540
+ //#endregion
541
+ //#region src/botDetector/db/batchQueue.d.ts
542
+ declare class BatchQueue {
543
+ private jobs;
544
+ private timer;
545
+ private flushPromise;
546
+ private get config();
547
+ private get log();
548
+ addQueue<T extends BatchQueueOps>(canary: string, ipAddress: string, type: T, params: OpParams[T], priority?: Priority): Promise<void>;
549
+ flush(): Promise<void>;
550
+ private runJob;
551
+ private executeBatch;
552
+ shutdown(): Promise<void>;
553
+ }
554
+ //#endregion
555
+ //#region src/botDetector/config/config.d.ts
556
+ /**
557
+ * @description
558
+ * The bot detector library's configuration object.
559
+ * Contains the core configuration to make the library usable client side.
560
+ * @module jwtAuth/config
561
+ * @see {@link ./jwtAuth/types/configSchema.js}
562
+ */
563
+ declare function configuration(config: BotDetectorConfigInput): Promise<void>;
564
+ declare function getBatchQueue(): BatchQueue;
565
+ declare function getStorage(): Storage;
566
+ declare function getDataSources(): DataSources;
567
+ //#endregion
568
+ //#region node_modules/@types/express-serve-static-core/index.d.ts
569
+ declare global {
570
+ namespace Express {
571
+ // These open interfaces may be extended in an application-specific manner via declaration merging.
572
+ // See for example method-override.d.ts (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/method-override/index.d.ts)
573
+ interface Request {}
574
+ interface Response {}
575
+ interface Locals {}
576
+ interface Application {}
577
+ }
578
+ }
579
+ interface NextFunction {
580
+ (err?: any): void;
581
+ /**
582
+ * "Break-out" of a router by calling {next('router')};
583
+ * @see {https://expressjs.com/en/guide/using-middleware.html#middleware.router}
584
+ */
585
+ (deferToNext: "router"): void;
586
+ /**
587
+ * "Break-out" of a route by calling {next('route')};
588
+ * @see {https://expressjs.com/en/guide/using-middleware.html#middleware.application}
589
+ */
590
+ (deferToNext: "route"): void;
591
+ }
592
+ interface ParamsDictionary {
593
+ [key: string]: string | string[];
594
+ [key: number]: string;
595
+ }
596
+ interface ParamsFlatDictionary {
597
+ [key: string | number]: string;
598
+ }
599
+ interface Locals extends Express.Locals {}
600
+ interface RequestHandler$1<P = ParamsDictionary, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>> {
601
+ // tslint:disable-next-line callable-types (This is extended from and can't extend from a type alias in ts<2.2)
602
+ (req: Request$1<P, ResBody, ReqBody, ReqQuery, LocalsObj>, res: Response<ResBody, LocalsObj>, next: NextFunction): unknown;
603
+ }
604
+ type ErrorRequestHandler<P = ParamsDictionary, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>> = (err: any, req: Request$1<P, ResBody, ReqBody, ReqQuery, LocalsObj>, res: Response<ResBody, LocalsObj>, next: NextFunction) => unknown;
605
+ type PathParams = string | RegExp | Array<string | RegExp>;
606
+ type RequestHandlerParams<P = ParamsDictionary, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>> = RequestHandler$1<P, ResBody, ReqBody, ReqQuery, LocalsObj> | ErrorRequestHandler<P, ResBody, ReqBody, ReqQuery, LocalsObj> | Array<RequestHandler$1<P> | ErrorRequestHandler<P>>;
607
+ type RemoveTail<S extends string, Tail extends string> = S extends `${infer P}${Tail}` ? P : S;
608
+ type GetRouteParameter<S extends string> = RemoveTail<RemoveTail<RemoveTail<S, `/${string}`>, `-${string}`>, `.${string}`>; // dprint-ignore
609
+ type RouteParameters<Route extends string | RegExp> = Route extends string ? Route extends `${infer Required}{${infer Optional}}${infer Next}` ? ParseRouteParameters<Required> & Partial<ParseRouteParameters<Optional>> & RouteParameters<Next> : ParseRouteParameters<Route> : ParamsFlatDictionary;
610
+ type ParseRouteParameters<Route extends string> = string extends Route ? ParamsDictionary : Route extends `${string}:${infer Rest}` ? (GetRouteParameter<Rest> extends never ? ParamsDictionary : { [P in GetRouteParameter<Rest>]: string }) & (Rest extends `${GetRouteParameter<Rest>}${infer Next}` ? RouteParameters<Next> : unknown) : Route extends `${string}*${infer Rest}` ? (GetRouteParameter<Rest> extends never ? ParamsDictionary : { [P in GetRouteParameter<Rest>]: string[] }) & (Rest extends `${GetRouteParameter<Rest>}${infer Next}` ? RouteParameters<Next> : unknown) : {};
611
+ /* eslint-disable @definitelytyped/no-unnecessary-generics */
612
+ interface IRouterMatcher<T, Method extends "all" | "get" | "post" | "put" | "delete" | "patch" | "options" | "head" = any> {
613
+ <Route extends string | RegExp, P = RouteParameters<Route>, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>>(// (it's used as the default type parameter for P)
614
+ path: Route, // (This generic is meant to be passed explicitly.)
615
+ ...handlers: Array<RequestHandler$1<P, ResBody, ReqBody, ReqQuery, LocalsObj>>): T;
616
+ <Path extends string | RegExp, P = RouteParameters<Path>, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>>(// (it's used as the default type parameter for P)
617
+ path: Path, // (This generic is meant to be passed explicitly.)
618
+ ...handlers: Array<RequestHandlerParams<P, ResBody, ReqBody, ReqQuery, LocalsObj>>): T;
619
+ <P = ParamsDictionary, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>>(path: PathParams, // (This generic is meant to be passed explicitly.)
620
+ ...handlers: Array<RequestHandler$1<P, ResBody, ReqBody, ReqQuery, LocalsObj>>): T;
621
+ <P = ParamsDictionary, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>>(path: PathParams, // (This generic is meant to be passed explicitly.)
622
+ ...handlers: Array<RequestHandlerParams<P, ResBody, ReqBody, ReqQuery, LocalsObj>>): T;
623
+ (path: PathParams, subApplication: Application): T;
624
+ }
625
+ interface IRouterHandler<T, Route extends string | RegExp = string> {
626
+ (...handlers: Array<RequestHandler$1<RouteParameters<Route>>>): T;
627
+ (...handlers: Array<RequestHandlerParams<RouteParameters<Route>>>): T;
628
+ <P = RouteParameters<Route>, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>>(// (This generic is meant to be passed explicitly.)
629
+ // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
630
+ ...handlers: Array<RequestHandler$1<P, ResBody, ReqBody, ReqQuery, LocalsObj>>): T;
631
+ <P = RouteParameters<Route>, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>>(// (This generic is meant to be passed explicitly.)
632
+ // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
633
+ ...handlers: Array<RequestHandlerParams<P, ResBody, ReqBody, ReqQuery, LocalsObj>>): T;
634
+ <P = ParamsDictionary, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>>(// (This generic is meant to be passed explicitly.)
635
+ // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
636
+ ...handlers: Array<RequestHandler$1<P, ResBody, ReqBody, ReqQuery, LocalsObj>>): T;
637
+ <P = ParamsDictionary, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>>(// (This generic is meant to be passed explicitly.)
638
+ // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
639
+ ...handlers: Array<RequestHandlerParams<P, ResBody, ReqBody, ReqQuery, LocalsObj>>): T;
640
+ }
641
+ /* eslint-enable @definitelytyped/no-unnecessary-generics */
642
+ interface IRouter extends RequestHandler$1 {
643
+ /**
644
+ * Map the given param placeholder `name`(s) to the given callback(s).
645
+ *
646
+ * Parameter mapping is used to provide pre-conditions to routes
647
+ * which use normalized placeholders. For example a _:user_id_ parameter
648
+ * could automatically load a user's information from the database without
649
+ * any additional code,
650
+ *
651
+ * The callback uses the samesignature as middleware, the only differencing
652
+ * being that the value of the placeholder is passed, in this case the _id_
653
+ * of the user. Once the `next()` function is invoked, just like middleware
654
+ * it will continue on to execute the route, or subsequent parameter functions.
655
+ *
656
+ * app.param('user_id', function(req, res, next, id){
657
+ * User.find(id, function(err, user){
658
+ * if (err) {
659
+ * next(err);
660
+ * } else if (user) {
661
+ * req.user = user;
662
+ * next();
663
+ * } else {
664
+ * next(new Error('failed to load user'));
665
+ * }
666
+ * });
667
+ * });
668
+ */
669
+ param(name: string, handler: RequestParamHandler): this;
670
+ /**
671
+ * Special-cased "all" method, applying the given route `path`,
672
+ * middleware, and callback to _every_ HTTP method.
673
+ */
674
+ all: IRouterMatcher<this, "all">;
675
+ get: IRouterMatcher<this, "get">;
676
+ post: IRouterMatcher<this, "post">;
677
+ put: IRouterMatcher<this, "put">;
678
+ delete: IRouterMatcher<this, "delete">;
679
+ patch: IRouterMatcher<this, "patch">;
680
+ options: IRouterMatcher<this, "options">;
681
+ head: IRouterMatcher<this, "head">;
682
+ checkout: IRouterMatcher<this>;
683
+ connect: IRouterMatcher<this>;
684
+ copy: IRouterMatcher<this>;
685
+ lock: IRouterMatcher<this>;
686
+ merge: IRouterMatcher<this>;
687
+ mkactivity: IRouterMatcher<this>;
688
+ mkcol: IRouterMatcher<this>;
689
+ move: IRouterMatcher<this>;
690
+ "m-search": IRouterMatcher<this>;
691
+ notify: IRouterMatcher<this>;
692
+ propfind: IRouterMatcher<this>;
693
+ proppatch: IRouterMatcher<this>;
694
+ purge: IRouterMatcher<this>;
695
+ report: IRouterMatcher<this>;
696
+ search: IRouterMatcher<this>;
697
+ subscribe: IRouterMatcher<this>;
698
+ trace: IRouterMatcher<this>;
699
+ unlock: IRouterMatcher<this>;
700
+ unsubscribe: IRouterMatcher<this>;
701
+ link: IRouterMatcher<this>;
702
+ unlink: IRouterMatcher<this>;
703
+ use: IRouterHandler<this> & IRouterMatcher<this>;
704
+ route<T extends string | RegExp>(prefix: T): IRoute<T>;
705
+ route(prefix: PathParams): IRoute;
706
+ /**
707
+ * Stack of configured routes
708
+ */
709
+ stack: ILayer[];
710
+ }
711
+ interface ILayer {
712
+ route?: IRoute;
713
+ name: string | "<anonymous>";
714
+ params?: Record<string, any>;
715
+ keys: string[];
716
+ path?: string;
717
+ method: string;
718
+ regexp: RegExp;
719
+ handle: (req: Request$1, res: Response, next: NextFunction) => any;
720
+ }
721
+ interface IRoute<Route extends string | RegExp = string> {
722
+ path: string;
723
+ stack: ILayer[];
724
+ all: IRouterHandler<this, Route>;
725
+ get: IRouterHandler<this, Route>;
726
+ post: IRouterHandler<this, Route>;
727
+ put: IRouterHandler<this, Route>;
728
+ delete: IRouterHandler<this, Route>;
729
+ patch: IRouterHandler<this, Route>;
730
+ options: IRouterHandler<this, Route>;
731
+ head: IRouterHandler<this, Route>;
732
+ checkout: IRouterHandler<this, Route>;
733
+ copy: IRouterHandler<this, Route>;
734
+ lock: IRouterHandler<this, Route>;
735
+ merge: IRouterHandler<this, Route>;
736
+ mkactivity: IRouterHandler<this, Route>;
737
+ mkcol: IRouterHandler<this, Route>;
738
+ move: IRouterHandler<this, Route>;
739
+ "m-search": IRouterHandler<this, Route>;
740
+ notify: IRouterHandler<this, Route>;
741
+ purge: IRouterHandler<this, Route>;
742
+ report: IRouterHandler<this, Route>;
743
+ search: IRouterHandler<this, Route>;
744
+ subscribe: IRouterHandler<this, Route>;
745
+ trace: IRouterHandler<this, Route>;
746
+ unlock: IRouterHandler<this, Route>;
747
+ unsubscribe: IRouterHandler<this, Route>;
748
+ }
749
+ interface Router$1 extends IRouter {}
750
+ /**
751
+ * Options passed down into `res.cookie`
752
+ * @link https://expressjs.com/en/api.html#res.cookie
753
+ */
754
+ interface CookieOptions {
755
+ /** Convenient option for setting the expiry time relative to the current time in **milliseconds**. */
756
+ maxAge?: number | undefined;
757
+ /** Indicates if the cookie should be signed. */
758
+ signed?: boolean | undefined;
759
+ /** Expiry date of the cookie in GMT. If not specified (undefined), creates a session cookie. */
760
+ expires?: Date | undefined;
761
+ /** Flags the cookie to be accessible only by the web server. */
762
+ httpOnly?: boolean | undefined;
763
+ /** Path for the cookie. Defaults to “/”. */
764
+ path?: string | undefined;
765
+ /** Domain name for the cookie. Defaults to the domain name of the app. */
766
+ domain?: string | undefined;
767
+ /** Marks the cookie to be used with HTTPS only. */
768
+ secure?: boolean | undefined;
769
+ /** A synchronous function used for cookie value encoding. Defaults to encodeURIComponent. */
770
+ encode?: ((val: string) => string) | undefined;
771
+ /**
772
+ * Value of the “SameSite” Set-Cookie attribute.
773
+ * @link https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00#section-4.1.1.
774
+ */
775
+ sameSite?: boolean | "lax" | "strict" | "none" | undefined;
776
+ /**
777
+ * Value of the “Priority” Set-Cookie attribute.
778
+ * @link https://datatracker.ietf.org/doc/html/draft-west-cookie-priority-00#section-4.3
779
+ */
780
+ priority?: "low" | "medium" | "high";
781
+ /** Marks the cookie to use partioned storage. */
782
+ partitioned?: boolean | undefined;
783
+ }
784
+ type Errback = (err: Error) => void;
785
+ /**
786
+ * @param P For most requests, this should be `ParamsDictionary`, but if you're
787
+ * using this in a route handler for a route that uses a `RegExp`, then `req.params`
788
+ * will only contains strings, in which case you should use `ParamsFlatDictionary` instead.
789
+ *
790
+ * @example
791
+ * app.get('/user/:id', (req, res) => res.send(req.params.id)); // implicitly `ParamsDictionary`, parameter is string
792
+ * app.get('/user/*id', (req, res) => res.send(req.params.id)); // implicitly `ParamsDictionary`, parameter is string[]
793
+ * app.get(/user\/(?<id>.*)/, (req, res) => res.send(req.params.id)); // implicitly `ParamsFlatDictionary`, parameter is string
794
+ * app.get(/user\/(.*)/, (req, res) => res.send(req.params[0])); // implicitly `ParamsFlatDictionary`, parameter is string
795
+ */
796
+ interface Request$1<P = ParamsDictionary, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>> extends http.IncomingMessage, Express.Request {
797
+ /**
798
+ * Return request header.
799
+ *
800
+ * The `Referrer` header field is special-cased,
801
+ * both `Referrer` and `Referer` are interchangeable.
802
+ *
803
+ * Examples:
804
+ *
805
+ * req.get('Content-Type');
806
+ * // => "text/plain"
807
+ *
808
+ * req.get('content-type');
809
+ * // => "text/plain"
810
+ *
811
+ * req.get('Something');
812
+ * // => undefined
813
+ *
814
+ * Aliased as `req.header()`.
815
+ */
816
+ get(name: "set-cookie"): string[] | undefined;
817
+ get(name: string): string | undefined;
818
+ header(name: "set-cookie"): string[] | undefined;
819
+ header(name: string): string | undefined;
820
+ /**
821
+ * Check if the given `type(s)` is acceptable, returning
822
+ * the best match when true, otherwise `undefined`, in which
823
+ * case you should respond with 406 "Not Acceptable".
824
+ *
825
+ * The `type` value may be a single mime type string
826
+ * such as "application/json", the extension name
827
+ * such as "json", a comma-delimted list such as "json, html, text/plain",
828
+ * or an array `["json", "html", "text/plain"]`. When a list
829
+ * or array is given the _best_ match, if any is returned.
830
+ *
831
+ * Examples:
832
+ *
833
+ * // Accept: text/html
834
+ * req.accepts('html');
835
+ * // => "html"
836
+ *
837
+ * // Accept: text/*, application/json
838
+ * req.accepts('html');
839
+ * // => "html"
840
+ * req.accepts('text/html');
841
+ * // => "text/html"
842
+ * req.accepts('json, text');
843
+ * // => "json"
844
+ * req.accepts('application/json');
845
+ * // => "application/json"
846
+ *
847
+ * // Accept: text/*, application/json
848
+ * req.accepts('image/png');
849
+ * req.accepts('png');
850
+ * // => false
851
+ *
852
+ * // Accept: text/*;q=.5, application/json
853
+ * req.accepts(['html', 'json']);
854
+ * req.accepts('html, json');
855
+ * // => "json"
856
+ */
857
+ accepts(): string[];
858
+ accepts(type: string): string | false;
859
+ accepts(type: string[]): string | false;
860
+ accepts(...type: string[]): string | false;
861
+ /**
862
+ * Returns the first accepted charset of the specified character sets,
863
+ * based on the request's Accept-Charset HTTP header field.
864
+ * If none of the specified charsets is accepted, returns false.
865
+ *
866
+ * For more information, or if you have issues or concerns, see accepts.
867
+ */
868
+ acceptsCharsets(): string[];
869
+ acceptsCharsets(charset: string): string | false;
870
+ acceptsCharsets(charset: string[]): string | false;
871
+ acceptsCharsets(...charset: string[]): string | false;
872
+ /**
873
+ * Returns the first accepted encoding of the specified encodings,
874
+ * based on the request's Accept-Encoding HTTP header field.
875
+ * If none of the specified encodings is accepted, returns false.
876
+ *
877
+ * For more information, or if you have issues or concerns, see accepts.
878
+ */
879
+ acceptsEncodings(): string[];
880
+ acceptsEncodings(encoding: string): string | false;
881
+ acceptsEncodings(encoding: string[]): string | false;
882
+ acceptsEncodings(...encoding: string[]): string | false;
883
+ /**
884
+ * Returns the first accepted language of the specified languages,
885
+ * based on the request's Accept-Language HTTP header field.
886
+ * If none of the specified languages is accepted, returns false.
887
+ *
888
+ * For more information, or if you have issues or concerns, see accepts.
889
+ */
890
+ acceptsLanguages(): string[];
891
+ acceptsLanguages(lang: string): string | false;
892
+ acceptsLanguages(lang: string[]): string | false;
893
+ acceptsLanguages(...lang: string[]): string | false;
894
+ /**
895
+ * Parse Range header field, capping to the given `size`.
896
+ *
897
+ * Unspecified ranges such as "0-" require knowledge of your resource length. In
898
+ * the case of a byte range this is of course the total number of bytes.
899
+ * If the Range header field is not given `undefined` is returned.
900
+ * If the Range header field is given, return value is a result of range-parser.
901
+ * See more ./types/range-parser/index.d.ts
902
+ *
903
+ * NOTE: remember that ranges are inclusive, so for example "Range: users=0-3"
904
+ * should respond with 4 users when available, not 3.
905
+ */
906
+ range(size: number, options?: Options): Ranges | Result | undefined;
907
+ /**
908
+ * Return an array of Accepted media types
909
+ * ordered from highest quality to lowest.
910
+ */
911
+ accepted: MediaType[];
912
+ /**
913
+ * Check if the incoming request contains the "Content-Type"
914
+ * header field, and it contains the give mime `type`.
915
+ *
916
+ * Examples:
917
+ *
918
+ * // With Content-Type: text/html; charset=utf-8
919
+ * req.is('html');
920
+ * req.is('text/html');
921
+ * req.is('text/*');
922
+ * // => true
923
+ *
924
+ * // When Content-Type is application/json
925
+ * req.is('json');
926
+ * req.is('application/json');
927
+ * req.is('application/*');
928
+ * // => true
929
+ *
930
+ * req.is('html');
931
+ * // => false
932
+ */
933
+ is(type: string | string[]): string | false | null;
934
+ /**
935
+ * Return the protocol string "http" or "https"
936
+ * when requested with TLS. When the "trust proxy"
937
+ * setting is enabled the "X-Forwarded-Proto" header
938
+ * field will be trusted. If you're running behind
939
+ * a reverse proxy that supplies https for you this
940
+ * may be enabled.
941
+ */
942
+ readonly protocol: string;
943
+ /**
944
+ * Short-hand for:
945
+ *
946
+ * req.protocol == 'https'
947
+ */
948
+ readonly secure: boolean;
949
+ /**
950
+ * Return the remote address, or when
951
+ * "trust proxy" is `true` return
952
+ * the upstream addr.
953
+ *
954
+ * Value may be undefined if the `req.socket` is destroyed
955
+ * (for example, if the client disconnected).
956
+ */
957
+ readonly ip: string | undefined;
958
+ /**
959
+ * When "trust proxy" is `true`, parse
960
+ * the "X-Forwarded-For" ip address list.
961
+ *
962
+ * For example if the value were "client, proxy1, proxy2"
963
+ * you would receive the array `["client", "proxy1", "proxy2"]`
964
+ * where "proxy2" is the furthest down-stream.
965
+ */
966
+ readonly ips: string[];
967
+ /**
968
+ * Return subdomains as an array.
969
+ *
970
+ * Subdomains are the dot-separated parts of the host before the main domain of
971
+ * the app. By default, the domain of the app is assumed to be the last two
972
+ * parts of the host. This can be changed by setting "subdomain offset".
973
+ *
974
+ * For example, if the domain is "tobi.ferrets.example.com":
975
+ * If "subdomain offset" is not set, req.subdomains is `["ferrets", "tobi"]`.
976
+ * If "subdomain offset" is 3, req.subdomains is `["tobi"]`.
977
+ */
978
+ readonly subdomains: string[];
979
+ /**
980
+ * Short-hand for `url.parse(req.url).pathname`.
981
+ */
982
+ readonly path: string;
983
+ /**
984
+ * Contains the hostname derived from the `Host` HTTP header.
985
+ */
986
+ readonly hostname: string;
987
+ /**
988
+ * Contains the host derived from the `Host` HTTP header.
989
+ */
990
+ readonly host: string;
991
+ /**
992
+ * Check if the request is fresh, aka
993
+ * Last-Modified and/or the ETag
994
+ * still match.
995
+ */
996
+ readonly fresh: boolean;
997
+ /**
998
+ * Check if the request is stale, aka
999
+ * "Last-Modified" and / or the "ETag" for the
1000
+ * resource has changed.
1001
+ */
1002
+ readonly stale: boolean;
1003
+ /**
1004
+ * Check if the request was an _XMLHttpRequest_.
1005
+ */
1006
+ readonly xhr: boolean; // body: { username: string; password: string; remember: boolean; title: string; };
1007
+ body: ReqBody; // cookies: { string; remember: boolean; };
1008
+ cookies: any;
1009
+ method: string;
1010
+ params: P;
1011
+ query: ReqQuery;
1012
+ route: any;
1013
+ signedCookies: any;
1014
+ originalUrl: string;
1015
+ url: string;
1016
+ baseUrl: string;
1017
+ app: Application;
1018
+ /**
1019
+ * After middleware.init executed, Request will contain res and next properties
1020
+ * See: express/lib/middleware/init.js
1021
+ */
1022
+ res?: Response<ResBody, LocalsObj> | undefined;
1023
+ next?: NextFunction | undefined;
1024
+ }
1025
+ interface MediaType {
1026
+ value: string;
1027
+ quality: number;
1028
+ type: string;
1029
+ subtype: string;
1030
+ }
1031
+ type Send<ResBody = any, T = Response<ResBody>> = (body?: ResBody) => T;
1032
+ interface SendFileOptions extends SendOptions {
1033
+ /** Object containing HTTP headers to serve with the file. */
1034
+ headers?: Record<string, unknown>;
1035
+ }
1036
+ interface DownloadOptions extends SendOptions {
1037
+ /** Object containing HTTP headers to serve with the file. The header `Content-Disposition` will be overridden by the filename argument. */
1038
+ headers?: Record<string, unknown>;
1039
+ }
1040
+ interface Response<ResBody = any, LocalsObj extends Record<string, any> = Record<string, any>, StatusCode extends number = number> extends http.ServerResponse, Express.Response {
1041
+ /**
1042
+ * Set status `code`.
1043
+ */
1044
+ status(code: StatusCode): this;
1045
+ /**
1046
+ * Set the response HTTP status code to `statusCode` and send its string representation as the response body.
1047
+ * @link http://expressjs.com/4x/api.html#res.sendStatus
1048
+ *
1049
+ * Examples:
1050
+ *
1051
+ * res.sendStatus(200); // equivalent to res.status(200).send('OK')
1052
+ * res.sendStatus(403); // equivalent to res.status(403).send('Forbidden')
1053
+ * res.sendStatus(404); // equivalent to res.status(404).send('Not Found')
1054
+ * res.sendStatus(500); // equivalent to res.status(500).send('Internal Server Error')
1055
+ */
1056
+ sendStatus(code: StatusCode): this;
1057
+ /**
1058
+ * Set Link header field with the given `links`.
1059
+ *
1060
+ * Examples:
1061
+ *
1062
+ * res.links({
1063
+ * next: 'http://api.example.com/users?page=2',
1064
+ * last: 'http://api.example.com/users?page=5'
1065
+ * });
1066
+ */
1067
+ links(links: any): this;
1068
+ /**
1069
+ * Send a response.
1070
+ *
1071
+ * Examples:
1072
+ *
1073
+ * res.send(new Buffer('wahoo'));
1074
+ * res.send({ some: 'json' });
1075
+ * res.send('<p>some html</p>');
1076
+ * res.status(404).send('Sorry, cant find that');
1077
+ */
1078
+ send: Send<ResBody, this>;
1079
+ /**
1080
+ * Send JSON response.
1081
+ *
1082
+ * Examples:
1083
+ *
1084
+ * res.json(null);
1085
+ * res.json({ user: 'tj' });
1086
+ * res.status(500).json('oh noes!');
1087
+ * res.status(404).json('I dont have that');
1088
+ */
1089
+ json: Send<ResBody, this>;
1090
+ /**
1091
+ * Send JSON response with JSONP callback support.
1092
+ *
1093
+ * Examples:
1094
+ *
1095
+ * res.jsonp(null);
1096
+ * res.jsonp({ user: 'tj' });
1097
+ * res.status(500).jsonp('oh noes!');
1098
+ * res.status(404).jsonp('I dont have that');
1099
+ */
1100
+ jsonp: Send<ResBody, this>;
1101
+ /**
1102
+ * Transfer the file at the given `path`.
1103
+ *
1104
+ * Automatically sets the _Content-Type_ response header field.
1105
+ * The callback `fn(err)` is invoked when the transfer is complete
1106
+ * or when an error occurs. Be sure to check `res.headersSent`
1107
+ * if you wish to attempt responding, as the header and some data
1108
+ * may have already been transferred.
1109
+ *
1110
+ * Options:
1111
+ *
1112
+ * - `maxAge` defaulting to 0 (can be string converted by `ms`)
1113
+ * - `root` root directory for relative filenames
1114
+ * - `headers` object of headers to serve with file
1115
+ * - `dotfiles` serve dotfiles, defaulting to false; can be `"allow"` to send them
1116
+ *
1117
+ * Other options are passed along to `send`.
1118
+ *
1119
+ * Examples:
1120
+ *
1121
+ * The following example illustrates how `res.sendFile()` may
1122
+ * be used as an alternative for the `static()` middleware for
1123
+ * dynamic situations. The code backing `res.sendFile()` is actually
1124
+ * the same code, so HTTP cache support etc is identical.
1125
+ *
1126
+ * app.get('/user/:uid/photos/:file', function(req, res){
1127
+ * var uid = req.params.uid
1128
+ * , file = req.params.file;
1129
+ *
1130
+ * req.user.mayViewFilesFrom(uid, function(yes){
1131
+ * if (yes) {
1132
+ * res.sendFile('/uploads/' + uid + '/' + file);
1133
+ * } else {
1134
+ * res.send(403, 'Sorry! you cant see that.');
1135
+ * }
1136
+ * });
1137
+ * });
1138
+ *
1139
+ * @api public
1140
+ */
1141
+ sendFile(path: string, fn?: Errback): void;
1142
+ sendFile(path: string, options: SendFileOptions, fn?: Errback): void;
1143
+ /**
1144
+ * Transfer the file at the given `path` as an attachment.
1145
+ *
1146
+ * Optionally providing an alternate attachment `filename`,
1147
+ * and optional callback `fn(err)`. The callback is invoked
1148
+ * when the data transfer is complete, or when an error has
1149
+ * ocurred. Be sure to check `res.headersSent` if you plan to respond.
1150
+ *
1151
+ * The optional options argument passes through to the underlying
1152
+ * res.sendFile() call, and takes the exact same parameters.
1153
+ *
1154
+ * This method uses `res.sendFile()`.
1155
+ */
1156
+ download(path: string, fn?: Errback): void;
1157
+ download(path: string, filename: string, fn?: Errback): void;
1158
+ download(path: string, filename: string, options: DownloadOptions, fn?: Errback): void;
1159
+ /**
1160
+ * Set _Content-Type_ response header with `type` through `mime.lookup()`
1161
+ * when it does not contain "/", or set the Content-Type to `type` otherwise.
1162
+ *
1163
+ * Examples:
1164
+ *
1165
+ * res.type('.html');
1166
+ * res.type('html');
1167
+ * res.type('json');
1168
+ * res.type('application/json');
1169
+ * res.type('png');
1170
+ */
1171
+ contentType(type: string): this;
1172
+ /**
1173
+ * Set _Content-Type_ response header with `type` through `mime.lookup()`
1174
+ * when it does not contain "/", or set the Content-Type to `type` otherwise.
1175
+ *
1176
+ * Examples:
1177
+ *
1178
+ * res.type('.html');
1179
+ * res.type('html');
1180
+ * res.type('json');
1181
+ * res.type('application/json');
1182
+ * res.type('png');
1183
+ */
1184
+ type(type: string): this;
1185
+ /**
1186
+ * Respond to the Acceptable formats using an `obj`
1187
+ * of mime-type callbacks.
1188
+ *
1189
+ * This method uses `req.accepted`, an array of
1190
+ * acceptable types ordered by their quality values.
1191
+ * When "Accept" is not present the _first_ callback
1192
+ * is invoked, otherwise the first match is used. When
1193
+ * no match is performed the server responds with
1194
+ * 406 "Not Acceptable".
1195
+ *
1196
+ * Content-Type is set for you, however if you choose
1197
+ * you may alter this within the callback using `res.type()`
1198
+ * or `res.set('Content-Type', ...)`.
1199
+ *
1200
+ * res.format({
1201
+ * 'text/plain': function(){
1202
+ * res.send('hey');
1203
+ * },
1204
+ *
1205
+ * 'text/html': function(){
1206
+ * res.send('<p>hey</p>');
1207
+ * },
1208
+ *
1209
+ * 'appliation/json': function(){
1210
+ * res.send({ message: 'hey' });
1211
+ * }
1212
+ * });
1213
+ *
1214
+ * In addition to canonicalized MIME types you may
1215
+ * also use extnames mapped to these types:
1216
+ *
1217
+ * res.format({
1218
+ * text: function(){
1219
+ * res.send('hey');
1220
+ * },
1221
+ *
1222
+ * html: function(){
1223
+ * res.send('<p>hey</p>');
1224
+ * },
1225
+ *
1226
+ * json: function(){
1227
+ * res.send({ message: 'hey' });
1228
+ * }
1229
+ * });
1230
+ *
1231
+ * By default Express passes an `Error`
1232
+ * with a `.status` of 406 to `next(err)`
1233
+ * if a match is not made. If you provide
1234
+ * a `.default` callback it will be invoked
1235
+ * instead.
1236
+ */
1237
+ format(obj: any): this;
1238
+ /**
1239
+ * Set _Content-Disposition_ header to _attachment_ with optional `filename`.
1240
+ */
1241
+ attachment(filename?: string): this;
1242
+ /**
1243
+ * Set header `field` to `val`, or pass
1244
+ * an object of header fields.
1245
+ *
1246
+ * Examples:
1247
+ *
1248
+ * res.set('Foo', ['bar', 'baz']);
1249
+ * res.set('Accept', 'application/json');
1250
+ * res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
1251
+ *
1252
+ * Aliased as `res.header()`.
1253
+ */
1254
+ set(field: any): this;
1255
+ set(field: string, value?: string | string[]): this;
1256
+ header(field: any): this;
1257
+ header(field: string, value?: string | string[]): this; // Property indicating if HTTP headers has been sent for the response.
1258
+ headersSent: boolean;
1259
+ /** Get value for header `field`. */
1260
+ get(field: string): string | undefined;
1261
+ /** Clear cookie `name`. */
1262
+ clearCookie(name: string, options?: CookieOptions): this;
1263
+ /**
1264
+ * Set cookie `name` to `val`, with the given `options`.
1265
+ *
1266
+ * Options:
1267
+ *
1268
+ * - `maxAge` max-age in milliseconds, converted to `expires`
1269
+ * - `signed` sign the cookie
1270
+ * - `path` defaults to "/"
1271
+ *
1272
+ * Examples:
1273
+ *
1274
+ * // "Remember Me" for 15 minutes
1275
+ * res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });
1276
+ *
1277
+ * // save as above
1278
+ * res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
1279
+ */
1280
+ cookie(name: string, val: string, options: CookieOptions): this;
1281
+ cookie(name: string, val: any, options: CookieOptions): this;
1282
+ cookie(name: string, val: any): this;
1283
+ /**
1284
+ * Set the location header to `url`.
1285
+ *
1286
+ * Examples:
1287
+ *
1288
+ * res.location('/foo/bar').;
1289
+ * res.location('http://example.com');
1290
+ * res.location('../login'); // /blog/post/1 -> /blog/login
1291
+ *
1292
+ * Mounting:
1293
+ *
1294
+ * When an application is mounted and `res.location()`
1295
+ * is given a path that does _not_ lead with "/" it becomes
1296
+ * relative to the mount-point. For example if the application
1297
+ * is mounted at "/blog", the following would become "/blog/login".
1298
+ *
1299
+ * res.location('login');
1300
+ *
1301
+ * While the leading slash would result in a location of "/login":
1302
+ *
1303
+ * res.location('/login');
1304
+ */
1305
+ location(url: string): this;
1306
+ /**
1307
+ * Redirect to the given `url` with optional response `status`
1308
+ * defaulting to 302.
1309
+ *
1310
+ * The resulting `url` is determined by `res.location()`, so
1311
+ * it will play nicely with mounted apps, relative paths, etc.
1312
+ *
1313
+ * Examples:
1314
+ *
1315
+ * res.redirect('/foo/bar');
1316
+ * res.redirect('http://example.com');
1317
+ * res.redirect(301, 'http://example.com');
1318
+ * res.redirect('../login'); // /blog/post/1 -> /blog/login
1319
+ */
1320
+ redirect(url: string): void;
1321
+ redirect(status: number, url: string): void;
1322
+ /**
1323
+ * Render `view` with the given `options` and optional callback `fn`.
1324
+ * When a callback function is given a response will _not_ be made
1325
+ * automatically, otherwise a response of _200_ and _text/html_ is given.
1326
+ *
1327
+ * Options:
1328
+ *
1329
+ * - `cache` boolean hinting to the engine it should cache
1330
+ * - `filename` filename of the view being rendered
1331
+ */
1332
+ render(view: string, options?: object, callback?: (err: Error, html: string) => void): void;
1333
+ render(view: string, callback?: (err: Error, html: string) => void): void;
1334
+ locals: LocalsObj & Locals;
1335
+ charset: string;
1336
+ /**
1337
+ * Adds the field to the Vary response header, if it is not there already.
1338
+ * Examples:
1339
+ *
1340
+ * res.vary('User-Agent').render('docs');
1341
+ */
1342
+ vary(field: string): this;
1343
+ app: Application;
1344
+ /**
1345
+ * Appends the specified value to the HTTP response header field.
1346
+ * If the header is not already set, it creates the header with the specified value.
1347
+ * The value parameter can be a string or an array.
1348
+ *
1349
+ * Note: calling res.set() after res.append() will reset the previously-set header value.
1350
+ *
1351
+ * @since 4.11.0
1352
+ */
1353
+ append(field: string, value?: string[] | string): this;
1354
+ /**
1355
+ * After middleware.init executed, Response will contain req property
1356
+ * See: express/lib/middleware/init.js
1357
+ */
1358
+ req: Request$1;
1359
+ }
1360
+ type RequestParamHandler = (req: Request$1, res: Response, next: NextFunction, value: any, name: string) => any;
1361
+ type ApplicationRequestHandler<T> = IRouterHandler<T> & IRouterMatcher<T> & ((...handlers: RequestHandlerParams[]) => T);
1362
+ interface Application<LocalsObj extends Record<string, any> = Record<string, any>> extends EventEmitter, IRouter, Express.Application {
1363
+ /**
1364
+ * Express instance itself is a request handler, which could be invoked without
1365
+ * third argument.
1366
+ */
1367
+ (req: Request$1 | http.IncomingMessage, res: Response | http.ServerResponse): any;
1368
+ /**
1369
+ * Initialize the server.
1370
+ *
1371
+ * - setup default configuration
1372
+ * - setup default middleware
1373
+ * - setup route reflection methods
1374
+ */
1375
+ init(): void;
1376
+ /**
1377
+ * Initialize application configuration.
1378
+ */
1379
+ defaultConfiguration(): void;
1380
+ /**
1381
+ * Register the given template engine callback `fn`
1382
+ * as `ext`.
1383
+ *
1384
+ * By default will `require()` the engine based on the
1385
+ * file extension. For example if you try to render
1386
+ * a "foo.jade" file Express will invoke the following internally:
1387
+ *
1388
+ * app.engine('jade', require('jade').__express);
1389
+ *
1390
+ * For engines that do not provide `.__express` out of the box,
1391
+ * or if you wish to "map" a different extension to the template engine
1392
+ * you may use this method. For example mapping the EJS template engine to
1393
+ * ".html" files:
1394
+ *
1395
+ * app.engine('html', require('ejs').renderFile);
1396
+ *
1397
+ * In this case EJS provides a `.renderFile()` method with
1398
+ * the same signature that Express expects: `(path, options, callback)`,
1399
+ * though note that it aliases this method as `ejs.__express` internally
1400
+ * so if you're using ".ejs" extensions you dont need to do anything.
1401
+ *
1402
+ * Some template engines do not follow this convention, the
1403
+ * [Consolidate.js](https://github.com/visionmedia/consolidate.js)
1404
+ * library was created to map all of node's popular template
1405
+ * engines to follow this convention, thus allowing them to
1406
+ * work seamlessly within Express.
1407
+ */
1408
+ engine(ext: string, fn: (path: string, options: object, callback: (e: any, rendered?: string) => void) => void): this;
1409
+ /**
1410
+ * Assign `setting` to `val`, or return `setting`'s value.
1411
+ *
1412
+ * app.set('foo', 'bar');
1413
+ * app.get('foo');
1414
+ * // => "bar"
1415
+ * app.set('foo', ['bar', 'baz']);
1416
+ * app.get('foo');
1417
+ * // => ["bar", "baz"]
1418
+ *
1419
+ * Mounted servers inherit their parent server's settings.
1420
+ */
1421
+ set(setting: string, val: any): this;
1422
+ get: ((name: string) => any) & IRouterMatcher<this>;
1423
+ param(name: string | string[], handler: RequestParamHandler): this;
1424
+ /**
1425
+ * Return the app's absolute pathname
1426
+ * based on the parent(s) that have
1427
+ * mounted it.
1428
+ *
1429
+ * For example if the application was
1430
+ * mounted as "/admin", which itself
1431
+ * was mounted as "/blog" then the
1432
+ * return value would be "/blog/admin".
1433
+ */
1434
+ path(): string;
1435
+ /**
1436
+ * Check if `setting` is enabled (truthy).
1437
+ *
1438
+ * app.enabled('foo')
1439
+ * // => false
1440
+ *
1441
+ * app.enable('foo')
1442
+ * app.enabled('foo')
1443
+ * // => true
1444
+ */
1445
+ enabled(setting: string): boolean;
1446
+ /**
1447
+ * Check if `setting` is disabled.
1448
+ *
1449
+ * app.disabled('foo')
1450
+ * // => true
1451
+ *
1452
+ * app.enable('foo')
1453
+ * app.disabled('foo')
1454
+ * // => false
1455
+ */
1456
+ disabled(setting: string): boolean;
1457
+ /** Enable `setting`. */
1458
+ enable(setting: string): this;
1459
+ /** Disable `setting`. */
1460
+ disable(setting: string): this;
1461
+ /**
1462
+ * Render the given view `name` name with `options`
1463
+ * and a callback accepting an error and the
1464
+ * rendered template string.
1465
+ *
1466
+ * Example:
1467
+ *
1468
+ * app.render('email', { name: 'Tobi' }, function(err, html){
1469
+ * // ...
1470
+ * })
1471
+ */
1472
+ render(name: string, options?: object, callback?: (err: Error, html: string) => void): void;
1473
+ render(name: string, callback: (err: Error, html: string) => void): void;
1474
+ /**
1475
+ * Listen for connections.
1476
+ *
1477
+ * A node `http.Server` is returned, with this
1478
+ * application (which is a `Function`) as its
1479
+ * callback. If you wish to create both an HTTP
1480
+ * and HTTPS server you may do so with the "http"
1481
+ * and "https" modules as shown here:
1482
+ *
1483
+ * var http = require('http')
1484
+ * , https = require('https')
1485
+ * , express = require('express')
1486
+ * , app = express();
1487
+ *
1488
+ * http.createServer(app).listen(80);
1489
+ * https.createServer({ ... }, app).listen(443);
1490
+ */
1491
+ listen(port: number, hostname: string, backlog: number, callback?: (error?: Error) => void): http.Server;
1492
+ listen(port: number, hostname: string, callback?: (error?: Error) => void): http.Server;
1493
+ listen(port: number, callback?: (error?: Error) => void): http.Server;
1494
+ listen(callback?: (error?: Error) => void): http.Server;
1495
+ listen(path: string, callback?: (error?: Error) => void): http.Server;
1496
+ listen(handle: any, listeningListener?: (error?: Error) => void): http.Server;
1497
+ router: Router$1;
1498
+ settings: any;
1499
+ resource: any;
1500
+ map: any;
1501
+ locals: LocalsObj & Locals;
1502
+ /**
1503
+ * The app.routes object houses all of the routes defined mapped by the
1504
+ * associated HTTP verb. This object may be used for introspection
1505
+ * capabilities, for example Express uses this internally not only for
1506
+ * routing but to provide default OPTIONS behaviour unless app.options()
1507
+ * is used. Your application or framework may also remove routes by
1508
+ * simply by removing them from this object.
1509
+ */
1510
+ routes: any;
1511
+ /**
1512
+ * Used to get all registered routes in Express Application
1513
+ */
1514
+ _router: any;
1515
+ use: ApplicationRequestHandler<this>;
1516
+ /**
1517
+ * The mount event is fired on a sub-app, when it is mounted on a parent app.
1518
+ * The parent app is passed to the callback function.
1519
+ *
1520
+ * NOTE:
1521
+ * Sub-apps will:
1522
+ * - Not inherit the value of settings that have a default value. You must set the value in the sub-app.
1523
+ * - Inherit the value of settings with no default value.
1524
+ */
1525
+ on: (event: "mount", callback: (parent: Application) => void) => this;
1526
+ /**
1527
+ * The app.mountpath property contains one or more path patterns on which a sub-app was mounted.
1528
+ */
1529
+ mountpath: string | string[];
1530
+ }
1531
+ interface Express extends Application {
1532
+ request: Request$1;
1533
+ response: Response;
1534
+ }
1535
+ //#endregion
1536
+ //#region src/botDetector/routes/visitorLog.d.ts
1537
+ declare const router: Router$1;
1538
+ //#endregion
1539
+ //#region src/botDetector/db/generator.d.ts
1540
+ declare function runGeneration(): Promise<void>;
1541
+ //#endregion
1542
+ //#region src/botDetector/penalties/banIP.d.ts
1543
+ declare function banIp(ip: string, info: BannedInfo): Promise<void> | void;
1544
+ //#endregion
1545
+ //#region src/botDetector/helpers/UAparser.d.ts
1546
+ declare function parseUA(userAgent: string | number): ParsedUAResult;
1547
+ //#endregion
1548
+ //#region src/botDetector/helpers/getIPInformation.d.ts
1549
+ declare function getData(ip: string): GeoResponse;
1550
+ //#endregion
1551
+ //#region src/botDetector/db/updateIsBot.d.ts
1552
+ declare function updateIsBot(isBot: boolean, cookie: string): Promise<void>;
1553
+ //#endregion
1554
+ //#region src/botDetector/db/updateBanned.d.ts
1555
+ declare function updateBannedIP(cookie: string, ipAddress: string, country: string, user_agent: string, info: BannedInfo): Promise<void>;
1556
+ //#endregion
1557
+ //#region src/botDetector/db/warmUp.d.ts
1558
+ declare function warmUp(): Promise<void>;
1559
+ //#endregion
1560
+ //#region src/botDetector/db/customUpdate.d.ts
1561
+ interface VisitorFingerPrint {
1562
+ userAgent: string;
1563
+ ipAddress: string;
1564
+ country: string;
1565
+ region: string;
1566
+ regionName: string;
1567
+ city: string;
1568
+ district: string;
1569
+ lat: string;
1570
+ lon: string;
1571
+ timezone: string;
1572
+ currency: string;
1573
+ isp: string;
1574
+ org: string;
1575
+ as: string;
1576
+ device_type: string;
1577
+ browser: string;
1578
+ proxy: boolean;
1579
+ hosting: boolean;
1580
+ deviceVendor: string;
1581
+ deviceModel: string;
1582
+ browserType: string;
1583
+ browserVersion: string;
1584
+ os: string;
1585
+ }
1586
+ declare function updateVisitors(data: VisitorFingerPrint, cookie: string, visitor_id: string): Promise<{
1587
+ success: boolean;
1588
+ reason?: string;
1589
+ }>;
1590
+ //#endregion
1591
+ //#region src/botDetector/checkers/CheckerRegistry.d.ts
1592
+ declare const CheckerRegistry: {
1593
+ register(checker: IBotChecker<BanReasonCode>): void;
1594
+ getEnabled(phase: "cheap" | "heavy", config: BotDetectorConfig): IBotChecker<BanReasonCode>[];
1595
+ clear(): void;
1596
+ };
1597
+ //#endregion
1598
+ //#region src/botDetector/helpers/exceptions.d.ts
1599
+ declare class BadBotDetected extends Error {
1600
+ constructor(message?: string);
1601
+ }
1602
+ declare class GoodBotDetected extends Error {
1603
+ constructor(message?: string);
1604
+ }
1605
+ //#endregion
1606
+ export { router as ApiResponse, BadBotDetected, type BanReasonCode, type BannedInfo, type BotDetectorConfig, type BotDetectorConfigInput, type CacheConfig, CheckerRegistry, DbConfig, type GeoResponse, GoodBotDetected, type IBotChecker, type ParsedUAResult, SupportedDbDrivers, SupportedDrivers, type ThreatRecordModified, type ValidationContext, type VisitorFingerPrint, banIp, configuration as defineConfiguration, validator as detectBots, getBatchQueue, getDataSources, getData as getGeoData, getStorage, parseUA, runGeneration, updateBannedIP, updateIsBot, updateVisitors, type userValidation, warmUp };
1607
+ //# sourceMappingURL=main.d.mts.map