@axeptio/behavior-detection 1.0.2 → 1.0.3
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.
- package/dist/cjs/index.cjs +1422 -0
- package/package.json +16 -15
- package/dist/cjs/behavior-detector.d.ts +0 -102
- package/dist/cjs/behavior-detector.js +0 -315
- package/dist/cjs/browser.d.ts +0 -33
- package/dist/cjs/browser.js +0 -226
- package/dist/cjs/index.d.ts +0 -38
- package/dist/cjs/index.js +0 -55
- package/dist/cjs/math-utils.d.ts +0 -84
- package/dist/cjs/math-utils.js +0 -141
- package/dist/cjs/strategies/click.d.ts +0 -39
- package/dist/cjs/strategies/click.js +0 -173
- package/dist/cjs/strategies/environment.d.ts +0 -52
- package/dist/cjs/strategies/environment.js +0 -148
- package/dist/cjs/strategies/index.d.ts +0 -18
- package/dist/cjs/strategies/index.js +0 -36
- package/dist/cjs/strategies/keyboard.d.ts +0 -43
- package/dist/cjs/strategies/keyboard.js +0 -233
- package/dist/cjs/strategies/mouse.d.ts +0 -39
- package/dist/cjs/strategies/mouse.js +0 -159
- package/dist/cjs/strategies/resize.d.ts +0 -21
- package/dist/cjs/strategies/resize.js +0 -97
- package/dist/cjs/strategies/scroll.d.ts +0 -37
- package/dist/cjs/strategies/scroll.js +0 -149
- package/dist/cjs/strategies/tap.d.ts +0 -38
- package/dist/cjs/strategies/tap.js +0 -214
- package/dist/cjs/strategy.d.ts +0 -107
- package/dist/cjs/strategy.js +0 -33
- package/dist/cjs/types.d.ts +0 -168
- package/dist/cjs/types.js +0 -26
- package/dist/esm/browser-iife.d.ts +0 -5
- package/dist/esm/browser-iife.js +0 -157
package/dist/cjs/types.d.ts
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
export type EventType = 'tab-visibility' | 'scroll' | 'resize' | 'mouse-move' | 'click' | 'keypress' | 'environment';
|
|
2
|
-
export interface BaseEvent {
|
|
3
|
-
type: EventType;
|
|
4
|
-
timestamp: number;
|
|
5
|
-
}
|
|
6
|
-
export interface TabVisibilityEvent extends BaseEvent {
|
|
7
|
-
type: 'tab-visibility';
|
|
8
|
-
hidden: boolean;
|
|
9
|
-
}
|
|
10
|
-
export interface ScrollEvent extends BaseEvent {
|
|
11
|
-
type: 'scroll';
|
|
12
|
-
x: number;
|
|
13
|
-
y: number;
|
|
14
|
-
elementId?: string;
|
|
15
|
-
deltaY?: number;
|
|
16
|
-
deltaTime?: number;
|
|
17
|
-
velocity?: number;
|
|
18
|
-
isProgrammatic?: boolean;
|
|
19
|
-
}
|
|
20
|
-
export interface ResizeEvent extends BaseEvent {
|
|
21
|
-
type: 'resize';
|
|
22
|
-
width: number;
|
|
23
|
-
height: number;
|
|
24
|
-
mouseX?: number;
|
|
25
|
-
mouseY?: number;
|
|
26
|
-
mouseNearEdge?: boolean;
|
|
27
|
-
screenWidth: number;
|
|
28
|
-
screenHeight: number;
|
|
29
|
-
screenAvailWidth: number;
|
|
30
|
-
screenAvailHeight: number;
|
|
31
|
-
devicePixelRatio: number;
|
|
32
|
-
isFullscreen?: boolean;
|
|
33
|
-
}
|
|
34
|
-
export interface MouseMoveEvent extends BaseEvent {
|
|
35
|
-
type: 'mouse-move';
|
|
36
|
-
x: number;
|
|
37
|
-
y: number;
|
|
38
|
-
velocityX?: number;
|
|
39
|
-
velocityY?: number;
|
|
40
|
-
directionChange?: boolean;
|
|
41
|
-
}
|
|
42
|
-
export interface ClickEvent extends BaseEvent {
|
|
43
|
-
type: 'click';
|
|
44
|
-
x: number;
|
|
45
|
-
y: number;
|
|
46
|
-
targetX: number;
|
|
47
|
-
targetY: number;
|
|
48
|
-
targetWidth: number;
|
|
49
|
-
targetHeight: number;
|
|
50
|
-
distanceFromTarget: number;
|
|
51
|
-
mousePositionBeforeClick?: {
|
|
52
|
-
x: number;
|
|
53
|
-
y: number;
|
|
54
|
-
timestamp: number;
|
|
55
|
-
};
|
|
56
|
-
timeSinceLastMouseMove?: number;
|
|
57
|
-
targetInViewport: boolean;
|
|
58
|
-
targetVisibleArea: number;
|
|
59
|
-
}
|
|
60
|
-
export interface KeypressEvent extends BaseEvent {
|
|
61
|
-
type: 'keypress';
|
|
62
|
-
key: string;
|
|
63
|
-
timeSinceLastKey?: number;
|
|
64
|
-
}
|
|
65
|
-
export interface EnvironmentEvent extends BaseEvent {
|
|
66
|
-
type: 'environment';
|
|
67
|
-
screenWidth: number;
|
|
68
|
-
screenHeight: number;
|
|
69
|
-
screenAvailWidth: number;
|
|
70
|
-
screenAvailHeight: number;
|
|
71
|
-
windowWidth: number;
|
|
72
|
-
windowHeight: number;
|
|
73
|
-
devicePixelRatio: number;
|
|
74
|
-
colorDepth: number;
|
|
75
|
-
pixelDepth: number;
|
|
76
|
-
userAgent: string;
|
|
77
|
-
platform: string;
|
|
78
|
-
language: string;
|
|
79
|
-
languages: string[];
|
|
80
|
-
hardwareConcurrency?: number;
|
|
81
|
-
maxTouchPoints: number;
|
|
82
|
-
vendor: string;
|
|
83
|
-
hasWebGL: boolean;
|
|
84
|
-
hasWebRTC: boolean;
|
|
85
|
-
hasNotifications: boolean;
|
|
86
|
-
hasGeolocation: boolean;
|
|
87
|
-
hasIndexedDB: boolean;
|
|
88
|
-
hasLocalStorage: boolean;
|
|
89
|
-
hasSessionStorage: boolean;
|
|
90
|
-
plugins: number;
|
|
91
|
-
mimeTypes: number;
|
|
92
|
-
suspiciousRatio?: boolean;
|
|
93
|
-
suspiciousDimensions?: boolean;
|
|
94
|
-
featureInconsistency?: boolean;
|
|
95
|
-
}
|
|
96
|
-
export type TrackedEvent = TabVisibilityEvent | ScrollEvent | ResizeEvent | MouseMoveEvent | ClickEvent | KeypressEvent | EnvironmentEvent;
|
|
97
|
-
export interface EventStorage {
|
|
98
|
-
'tab-visibility': TabVisibilityEvent[];
|
|
99
|
-
'scroll': ScrollEvent[];
|
|
100
|
-
'resize': ResizeEvent[];
|
|
101
|
-
'mouse-move': MouseMoveEvent[];
|
|
102
|
-
'click': ClickEvent[];
|
|
103
|
-
'keypress': KeypressEvent[];
|
|
104
|
-
'environment': EnvironmentEvent[];
|
|
105
|
-
}
|
|
106
|
-
export interface ScoreBreakdown {
|
|
107
|
-
overall: number;
|
|
108
|
-
factors: {
|
|
109
|
-
mouseMovement?: number;
|
|
110
|
-
clickAccuracy?: number;
|
|
111
|
-
scrollBehavior?: number;
|
|
112
|
-
keyboardTiming?: number;
|
|
113
|
-
tabActivity?: number;
|
|
114
|
-
resizeBehavior?: number;
|
|
115
|
-
environmentFingerprint?: number;
|
|
116
|
-
};
|
|
117
|
-
weights: {
|
|
118
|
-
mouseMovement: number;
|
|
119
|
-
clickAccuracy: number;
|
|
120
|
-
scrollBehavior: number;
|
|
121
|
-
keyboardTiming: number;
|
|
122
|
-
tabActivity: number;
|
|
123
|
-
resizeBehavior: number;
|
|
124
|
-
environmentFingerprint: number;
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
export interface ScoreOptions {
|
|
128
|
-
breakdown?: boolean;
|
|
129
|
-
auditTrail?: boolean;
|
|
130
|
-
}
|
|
131
|
-
export interface ScoreResult {
|
|
132
|
-
score: number;
|
|
133
|
-
breakdown?: ScoreBreakdown;
|
|
134
|
-
auditTrail?: TrackedEvent[];
|
|
135
|
-
}
|
|
136
|
-
export type ScoringFunction = (events: TrackedEvent[]) => number | undefined;
|
|
137
|
-
export interface BehaviorSettings {
|
|
138
|
-
sampleRates?: {
|
|
139
|
-
mouseMove?: number;
|
|
140
|
-
scroll?: number;
|
|
141
|
-
keypress?: number;
|
|
142
|
-
};
|
|
143
|
-
rollingWindows?: {
|
|
144
|
-
mouseMove?: number;
|
|
145
|
-
scroll?: number;
|
|
146
|
-
};
|
|
147
|
-
weights?: {
|
|
148
|
-
mouseMovement?: number;
|
|
149
|
-
clickAccuracy?: number;
|
|
150
|
-
scrollBehavior?: number;
|
|
151
|
-
keyboardTiming?: number;
|
|
152
|
-
tabActivity?: number;
|
|
153
|
-
resizeBehavior?: number;
|
|
154
|
-
environmentFingerprint?: number;
|
|
155
|
-
};
|
|
156
|
-
customScorers?: {
|
|
157
|
-
mouseMovement?: ScoringFunction;
|
|
158
|
-
clickAccuracy?: ScoringFunction;
|
|
159
|
-
scrollBehavior?: ScoringFunction;
|
|
160
|
-
keyboardTiming?: ScoringFunction;
|
|
161
|
-
tabActivity?: ScoringFunction;
|
|
162
|
-
resizeBehavior?: ScoringFunction;
|
|
163
|
-
environmentFingerprint?: ScoringFunction;
|
|
164
|
-
};
|
|
165
|
-
clickMouseHistoryWindow?: number;
|
|
166
|
-
useWebWorker?: boolean;
|
|
167
|
-
}
|
|
168
|
-
export declare const DEFAULT_SETTINGS: Required<BehaviorSettings>;
|
package/dist/cjs/types.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_SETTINGS = void 0;
|
|
4
|
-
exports.DEFAULT_SETTINGS = {
|
|
5
|
-
sampleRates: {
|
|
6
|
-
mouseMove: 0.1, // Track 10% of mouse moves
|
|
7
|
-
scroll: 1.0, // Track ALL scrolls - critical for detection
|
|
8
|
-
keypress: 1.0, // Track all keypresses
|
|
9
|
-
},
|
|
10
|
-
rollingWindows: {
|
|
11
|
-
mouseMove: 30000,
|
|
12
|
-
scroll: 30000,
|
|
13
|
-
},
|
|
14
|
-
weights: {
|
|
15
|
-
mouseMovement: 0.30, // Increased - continuous behavioral signal
|
|
16
|
-
clickAccuracy: 0.30, // Increased - critical behavioral signal
|
|
17
|
-
scrollBehavior: 0.15, // Unchanged
|
|
18
|
-
keyboardTiming: 0.10, // Slightly reduced
|
|
19
|
-
tabActivity: 0.05, // Unchanged
|
|
20
|
-
resizeBehavior: 0.02, // Reduced - less reliable
|
|
21
|
-
environmentFingerprint: 0.08, // Reduced - static signal, one-time check
|
|
22
|
-
},
|
|
23
|
-
customScorers: {},
|
|
24
|
-
clickMouseHistoryWindow: 1000,
|
|
25
|
-
useWebWorker: false, // Will implement Web Worker support in phase 2
|
|
26
|
-
};
|
package/dist/esm/browser-iife.js
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Browser Build (IIFE) - Pure browser bundle without ES module exports
|
|
3
|
-
* Auto-initializing standalone bundle for CDN usage
|
|
4
|
-
*/
|
|
5
|
-
import { BehaviorDetector } from './behavior-detector';
|
|
6
|
-
import { MouseStrategy, ScrollStrategy, ClickStrategy, TapStrategy, KeyboardStrategy, EnvironmentStrategy, ResizeStrategy, } from './strategies/index.js';
|
|
7
|
-
/**
|
|
8
|
-
* Detect if the current device is mobile
|
|
9
|
-
*/
|
|
10
|
-
function isMobileDevice() {
|
|
11
|
-
const hasTouchScreen = navigator.maxTouchPoints > 0 || 'ontouchstart' in window;
|
|
12
|
-
const mobileUA = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
13
|
-
const smallScreen = window.innerWidth < 768 && window.innerHeight < 1024;
|
|
14
|
-
return (hasTouchScreen && smallScreen) || mobileUA;
|
|
15
|
-
}
|
|
16
|
-
class BehaviorDetectionAPI {
|
|
17
|
-
constructor() {
|
|
18
|
-
this.detector = null;
|
|
19
|
-
this.checkInterval = null;
|
|
20
|
-
this.settings = null;
|
|
21
|
-
}
|
|
22
|
-
init(settings) {
|
|
23
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
24
|
-
if (this.detector) {
|
|
25
|
-
this.stop();
|
|
26
|
-
}
|
|
27
|
-
this.settings = settings;
|
|
28
|
-
this.detector = new BehaviorDetector({
|
|
29
|
-
pauseOnHidden: settings.pauseOnHidden !== undefined ? settings.pauseOnHidden : true
|
|
30
|
-
});
|
|
31
|
-
const isMobile = isMobileDevice();
|
|
32
|
-
const strategies = settings.strategies || {};
|
|
33
|
-
const defaultWeights = isMobile ? {
|
|
34
|
-
mouse: 0,
|
|
35
|
-
scroll: 0.35,
|
|
36
|
-
click: 0,
|
|
37
|
-
tap: 0.35,
|
|
38
|
-
keyboard: 0.15,
|
|
39
|
-
environment: 0.10,
|
|
40
|
-
resize: 0.05,
|
|
41
|
-
} : {
|
|
42
|
-
mouse: 0.30,
|
|
43
|
-
scroll: 0.15,
|
|
44
|
-
click: 0.30,
|
|
45
|
-
tap: 0,
|
|
46
|
-
keyboard: 0.10,
|
|
47
|
-
environment: 0.08,
|
|
48
|
-
resize: 0.02,
|
|
49
|
-
};
|
|
50
|
-
if (!isMobile && ((_a = strategies.mouse) === null || _a === void 0 ? void 0 : _a.enabled) !== false) {
|
|
51
|
-
const strategy = new MouseStrategy();
|
|
52
|
-
const weight = (_c = (_b = strategies.mouse) === null || _b === void 0 ? void 0 : _b.weight) !== null && _c !== void 0 ? _c : defaultWeights.mouse;
|
|
53
|
-
this.detector.addStrategy(strategy, weight);
|
|
54
|
-
}
|
|
55
|
-
if (((_d = strategies.scroll) === null || _d === void 0 ? void 0 : _d.enabled) !== false) {
|
|
56
|
-
const strategy = new ScrollStrategy();
|
|
57
|
-
const weight = (_f = (_e = strategies.scroll) === null || _e === void 0 ? void 0 : _e.weight) !== null && _f !== void 0 ? _f : defaultWeights.scroll;
|
|
58
|
-
this.detector.addStrategy(strategy, weight);
|
|
59
|
-
}
|
|
60
|
-
if (!isMobile && ((_g = strategies.click) === null || _g === void 0 ? void 0 : _g.enabled) !== false) {
|
|
61
|
-
const strategy = new ClickStrategy();
|
|
62
|
-
const weight = (_j = (_h = strategies.click) === null || _h === void 0 ? void 0 : _h.weight) !== null && _j !== void 0 ? _j : defaultWeights.click;
|
|
63
|
-
this.detector.addStrategy(strategy, weight);
|
|
64
|
-
}
|
|
65
|
-
if (isMobile && ((_k = strategies.tap) === null || _k === void 0 ? void 0 : _k.enabled) !== false) {
|
|
66
|
-
const strategy = new TapStrategy();
|
|
67
|
-
const weight = (_m = (_l = strategies.tap) === null || _l === void 0 ? void 0 : _l.weight) !== null && _m !== void 0 ? _m : defaultWeights.tap;
|
|
68
|
-
this.detector.addStrategy(strategy, weight);
|
|
69
|
-
}
|
|
70
|
-
if (((_o = strategies.keyboard) === null || _o === void 0 ? void 0 : _o.enabled) !== false) {
|
|
71
|
-
const strategy = new KeyboardStrategy();
|
|
72
|
-
const weight = (_q = (_p = strategies.keyboard) === null || _p === void 0 ? void 0 : _p.weight) !== null && _q !== void 0 ? _q : defaultWeights.keyboard;
|
|
73
|
-
this.detector.addStrategy(strategy, weight);
|
|
74
|
-
}
|
|
75
|
-
if (((_r = strategies.environment) === null || _r === void 0 ? void 0 : _r.enabled) !== false) {
|
|
76
|
-
const strategy = new EnvironmentStrategy();
|
|
77
|
-
const weight = (_t = (_s = strategies.environment) === null || _s === void 0 ? void 0 : _s.weight) !== null && _t !== void 0 ? _t : defaultWeights.environment;
|
|
78
|
-
this.detector.addStrategy(strategy, weight);
|
|
79
|
-
}
|
|
80
|
-
if (((_u = strategies.resize) === null || _u === void 0 ? void 0 : _u.enabled) !== false) {
|
|
81
|
-
const strategy = new ResizeStrategy();
|
|
82
|
-
const weight = (_w = (_v = strategies.resize) === null || _v === void 0 ? void 0 : _v.weight) !== null && _w !== void 0 ? _w : defaultWeights.resize;
|
|
83
|
-
this.detector.addStrategy(strategy, weight);
|
|
84
|
-
}
|
|
85
|
-
if (settings.autoStart !== false) {
|
|
86
|
-
this.start();
|
|
87
|
-
}
|
|
88
|
-
if (settings.checkMs && settings.checkMs > 0) {
|
|
89
|
-
this.startPeriodicCheck(settings.checkMs);
|
|
90
|
-
}
|
|
91
|
-
if (settings.onReady) {
|
|
92
|
-
settings.onReady(this);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
start() {
|
|
96
|
-
if (!this.detector) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
this.detector.start();
|
|
100
|
-
}
|
|
101
|
-
stop() {
|
|
102
|
-
if (this.detector) {
|
|
103
|
-
this.detector.stop();
|
|
104
|
-
}
|
|
105
|
-
if (this.checkInterval !== null) {
|
|
106
|
-
clearInterval(this.checkInterval);
|
|
107
|
-
this.checkInterval = null;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
async score() {
|
|
111
|
-
if (!this.detector) {
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
return this.detector.score({ breakdown: true });
|
|
115
|
-
}
|
|
116
|
-
startPeriodicCheck(intervalMs) {
|
|
117
|
-
if (this.checkInterval !== null) {
|
|
118
|
-
clearInterval(this.checkInterval);
|
|
119
|
-
}
|
|
120
|
-
this.checkInterval = window.setInterval(async () => {
|
|
121
|
-
var _a, _b;
|
|
122
|
-
const result = await this.score();
|
|
123
|
-
if (!result || !this.settings)
|
|
124
|
-
return;
|
|
125
|
-
if (this.settings.onScore) {
|
|
126
|
-
this.settings.onScore(result);
|
|
127
|
-
}
|
|
128
|
-
const botThreshold = (_a = this.settings.botThreshold) !== null && _a !== void 0 ? _a : 0.3;
|
|
129
|
-
const humanThreshold = (_b = this.settings.humanThreshold) !== null && _b !== void 0 ? _b : 0.7;
|
|
130
|
-
if (result.score < botThreshold && this.settings.ifBot) {
|
|
131
|
-
this.settings.ifBot(result);
|
|
132
|
-
}
|
|
133
|
-
else if (result.score >= humanThreshold && this.settings.ifHuman) {
|
|
134
|
-
this.settings.ifHuman(result);
|
|
135
|
-
}
|
|
136
|
-
}, intervalMs);
|
|
137
|
-
}
|
|
138
|
-
getDetector() {
|
|
139
|
-
return this.detector;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
// Create global API instance
|
|
143
|
-
const api = new BehaviorDetectionAPI();
|
|
144
|
-
// Auto-initialize if settings are already present
|
|
145
|
-
if (typeof window !== 'undefined') {
|
|
146
|
-
window.BehaviorDetector = api;
|
|
147
|
-
const checkAndInit = () => {
|
|
148
|
-
const settings = window.bdSettings;
|
|
149
|
-
if (settings) {
|
|
150
|
-
api.init(settings);
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
checkAndInit();
|
|
154
|
-
if (document.readyState === 'loading') {
|
|
155
|
-
document.addEventListener('DOMContentLoaded', checkAndInit);
|
|
156
|
-
}
|
|
157
|
-
}
|