@keverdjs/fraud-sdk-vue 1.0.0 → 2.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.
package/dist/index.d.mts CHANGED
@@ -1,65 +1,294 @@
1
1
  import { Ref, App } from 'vue';
2
2
 
3
3
  /**
4
- * Core SDK - placeholder
5
- * This will be implemented by copying from React SDK and adapting for Vue
4
+ * Keverd Fraud SDK Vue - Type Definitions
6
5
  */
7
- declare class KeverdSDK {
8
- }
9
6
 
10
- /**
11
- * Types for Vue SDK
12
- * TODO: Copy and adapt types from React SDK
13
- */
14
- interface KeverdConfig {
15
- apiKey: string;
16
- endpoint?: string;
17
- }
18
- interface KeverdLoadOptions {
19
- apiKey: string;
20
- endpoint?: string;
7
+ interface KeverdDeviceInfo {
8
+ deviceId: string;
9
+ fingerprint: string;
10
+ manufacturer?: string;
11
+ model?: string;
12
+ brand?: string;
13
+ device?: string;
14
+ product?: string;
15
+ hardware?: string;
16
+ sdkVersion?: string;
17
+ osVersion?: string;
18
+ screenWidth?: string;
19
+ screenHeight?: string;
20
+ screenDensity?: string;
21
+ locale?: string;
22
+ timezone: string;
21
23
  }
22
- interface KeverdVisitorData {
24
+ interface KeverdSessionInfo {
25
+ sessionId?: string;
26
+ installId?: string;
27
+ sessionCount?: string;
28
+ firstSession?: string;
29
+ timestamp?: string;
23
30
  }
24
- interface KeverdVisitorDataOptions {
31
+ interface KeverdBehavioralSequence {
32
+ featureNames: string[];
33
+ windowSize: number;
34
+ maskValue: number;
35
+ sequence: number[][];
25
36
  }
26
- interface KeverdVisitorDataResult {
37
+ interface KeverdBehavioralData {
38
+ typing_dwell_ms?: number[];
39
+ typing_flight_ms?: number[];
40
+ swipe_velocity?: number;
41
+ session_entropy?: number;
42
+ suspicious_swipe_velocity?: number;
43
+ behavioral_vectors?: KeverdBehavioralSequence;
27
44
  }
28
45
  interface KeverdFingerprintRequest {
46
+ userId?: string;
47
+ device: KeverdDeviceInfo;
48
+ session?: KeverdSessionInfo;
49
+ behavioral?: KeverdBehavioralData;
50
+ }
51
+ interface KeverdSimSwapEngine {
52
+ userId?: string;
53
+ risk: number;
54
+ flags: {
55
+ sim_changed?: boolean;
56
+ device_changed?: boolean;
57
+ behavior_anomaly?: boolean;
58
+ time_anomaly?: boolean;
59
+ velocity_anomaly?: boolean;
60
+ };
61
+ updatedProfile?: Record<string, unknown>;
29
62
  }
30
63
  interface KeverdFingerprintResponse {
64
+ risk_score: number;
65
+ score: number;
66
+ action: 'allow' | 'soft_challenge' | 'hard_challenge' | 'block';
67
+ reason: string[];
68
+ session_id: string;
69
+ requestId: string;
70
+ sim_swap_engine?: KeverdSimSwapEngine;
31
71
  }
32
- interface KeverdDeviceInfo {
72
+ interface KeverdPrivacySignals {
73
+ isIncognito?: boolean;
74
+ isVPN?: boolean;
75
+ isAutomated?: boolean;
76
+ hasAdBlocker?: boolean;
33
77
  }
34
- interface KeverdSessionInfo {
78
+ interface KeverdVisitorData {
79
+ visitorId: string;
80
+ riskScore: number;
81
+ score: number;
82
+ action: 'allow' | 'soft_challenge' | 'hard_challenge' | 'block';
83
+ reasons: string[];
84
+ sessionId: string;
85
+ requestId: string;
86
+ simSwapEngine?: KeverdSimSwapEngine;
87
+ confidence?: number;
88
+ fingerprintjsVisitorId?: string;
89
+ privacySignals?: KeverdPrivacySignals;
90
+ deviceMatch?: boolean;
91
+ fraudProbability?: number;
92
+ recommendedAction?: string;
35
93
  }
36
- interface KeverdBehavioralData {
94
+ interface KeverdConfig {
95
+ apiKey: string;
96
+ userId?: string;
97
+ debug?: boolean;
98
+ extendedResult?: boolean;
99
+ ignoreCache?: boolean;
100
+ }
101
+ interface KeverdLoadOptions {
102
+ apiKey: string;
103
+ debug?: boolean;
104
+ }
105
+ interface KeverdVisitorDataOptions {
106
+ extendedResult?: boolean;
107
+ ignoreCache?: boolean;
108
+ tag?: string;
37
109
  }
38
110
  interface KeverdError {
111
+ message: string;
112
+ code?: string;
113
+ statusCode?: number;
114
+ }
115
+ interface KeverdVisitorDataResult {
116
+ data: Ref<KeverdVisitorData | null>;
117
+ loading: Ref<boolean>;
118
+ error: Ref<KeverdError | null>;
119
+ getData: () => Promise<void>;
39
120
  }
40
121
 
41
122
  /**
42
- * Vue composable for getting visitor data
43
- * TODO: Implement Vue composable
123
+ * Keverd Fraud SDK Core
124
+ * Main SDK class for fingerprinting and risk assessment
125
+ * Wraps the web SDK to provide Vue-specific interface with all enhanced signals
44
126
  */
45
127
 
46
- declare function useKeverdVisitorData(options?: KeverdVisitorDataOptions): {
47
- data: Ref<KeverdVisitorDataResult | null>;
48
- loading: Ref<boolean>;
49
- error: Ref<Error | null>;
50
- getData: () => Promise<void>;
51
- };
128
+ declare class KeverdSDK {
129
+ private config;
130
+ private isInitialized;
131
+ constructor();
132
+ /**
133
+ * Initialize the SDK with configuration
134
+ * Wraps the web SDK initialization
135
+ */
136
+ init(config: KeverdConfig): void;
137
+ /**
138
+ * Get visitor data (fingerprint and risk assessment)
139
+ * Uses the web SDK which includes all enhanced signals including FingerprintJS
140
+ */
141
+ getVisitorData(_options?: KeverdVisitorDataOptions): Promise<KeverdVisitorData>;
142
+ /**
143
+ * Transform API response to visitor data format
144
+ */
145
+ private transformResponse;
146
+ /**
147
+ * Generate a session ID
148
+ */
149
+ private generateSessionId;
150
+ /**
151
+ * Start a new session (called automatically on init, but can be called manually)
152
+ */
153
+ startSession(userId?: string, deviceHash?: string, metadata?: Record<string, unknown>): Promise<void>;
154
+ /**
155
+ * End the current session
156
+ */
157
+ endSession(): Promise<void>;
158
+ /**
159
+ * Pause the current session (e.g., when app goes to background)
160
+ */
161
+ pauseSession(): Promise<void>;
162
+ /**
163
+ * Resume a paused session (e.g., when app comes to foreground)
164
+ */
165
+ resumeSession(): Promise<void>;
166
+ /**
167
+ * Get current session status
168
+ */
169
+ getSessionStatus(): Promise<{
170
+ session_id: string;
171
+ status: string;
172
+ is_active: boolean;
173
+ is_paused: boolean;
174
+ event_count: number;
175
+ started_at: string;
176
+ last_activity_at: string;
177
+ duration_seconds: number | null;
178
+ } | null>;
179
+ /**
180
+ * Destroy the SDK instance
181
+ */
182
+ destroy(): Promise<void>;
183
+ /**
184
+ * Get current configuration
185
+ */
186
+ getConfig(): KeverdConfig | null;
187
+ /**
188
+ * Check if SDK is initialized
189
+ */
190
+ isReady(): boolean;
191
+ }
52
192
 
53
193
  /**
54
- * Vue composable for Keverd provider
55
- * TODO: Implement Vue provider composable
194
+ * Vue composable for getting visitor data
195
+ * Provides reactive visitor data, loading state, and error handling
56
196
  */
57
197
 
58
- declare function useKeverdProvider(options: KeverdLoadOptions): void;
198
+ interface KeverdVisitorDataHookOptions {
199
+ extendedResult?: boolean;
200
+ immediate?: boolean;
201
+ ignoreCache?: boolean;
202
+ }
203
+ /**
204
+ * Vue composable for accessing visitor data and risk assessment
205
+ *
206
+ * @param options - Configuration options for the hook
207
+ * @returns Object containing reactive data, loading state, error, and getData function
208
+ *
209
+ * @example
210
+ * ```vue
211
+ * <script setup>
212
+ * import { useKeverdVisitorData } from '@keverdjs/fraud-sdk-vue';
213
+ *
214
+ * const { data, loading, error, getData } = useKeverdVisitorData({
215
+ * extendedResult: true,
216
+ * immediate: true
217
+ * });
218
+ * </script>
219
+ *
220
+ * <template>
221
+ * <div v-if="loading">Loading...</div>
222
+ * <div v-else-if="error">Error: {{ error.message }}</div>
223
+ * <div v-else>
224
+ * <p>Risk Score: {{ data?.riskScore }}</p>
225
+ * <button @click="getData">Reload</button>
226
+ * </div>
227
+ * </template>
228
+ * ```
229
+ */
230
+ declare function useKeverdVisitorData(options?: KeverdVisitorDataHookOptions): KeverdVisitorDataResult;
231
+
232
+ /**
233
+ * Setup Keverd SDK provider
234
+ * Call this in your root component or app setup
235
+ */
236
+ declare function useKeverdProvider(options: KeverdLoadOptions): {
237
+ sdk: Ref<{
238
+ init: (config: KeverdConfig) => void;
239
+ getVisitorData: (_options?: KeverdVisitorDataOptions) => Promise<KeverdVisitorData>;
240
+ startSession: (userId?: string, deviceHash?: string, metadata?: Record<string, unknown>) => Promise<void>;
241
+ endSession: () => Promise<void>;
242
+ pauseSession: () => Promise<void>;
243
+ resumeSession: () => Promise<void>;
244
+ getSessionStatus: () => Promise<{
245
+ session_id: string;
246
+ status: string;
247
+ is_active: boolean;
248
+ is_paused: boolean;
249
+ event_count: number;
250
+ started_at: string;
251
+ last_activity_at: string;
252
+ duration_seconds: number | null;
253
+ } | null>;
254
+ destroy: () => Promise<void>;
255
+ getConfig: () => KeverdConfig | null;
256
+ isReady: () => boolean;
257
+ } | null, KeverdSDK | {
258
+ init: (config: KeverdConfig) => void;
259
+ getVisitorData: (_options?: KeverdVisitorDataOptions) => Promise<KeverdVisitorData>;
260
+ startSession: (userId?: string, deviceHash?: string, metadata?: Record<string, unknown>) => Promise<void>;
261
+ endSession: () => Promise<void>;
262
+ pauseSession: () => Promise<void>;
263
+ resumeSession: () => Promise<void>;
264
+ getSessionStatus: () => Promise<{
265
+ session_id: string;
266
+ status: string;
267
+ is_active: boolean;
268
+ is_paused: boolean;
269
+ event_count: number;
270
+ started_at: string;
271
+ last_activity_at: string;
272
+ duration_seconds: number | null;
273
+ } | null>;
274
+ destroy: () => Promise<void>;
275
+ getConfig: () => KeverdConfig | null;
276
+ isReady: () => boolean;
277
+ } | null>;
278
+ isReady: Ref<boolean, boolean>;
279
+ };
280
+ /**
281
+ * Get Keverd SDK instance from context
282
+ * Use this in child components to access the SDK
283
+ */
284
+ declare function useKeverdContext(): {
285
+ sdk: Ref<KeverdSDK | null>;
286
+ isReady: Ref<boolean>;
287
+ };
59
288
 
60
289
  /**
61
290
  * Vue plugin for Keverd SDK
62
- * TODO: Implement Vue plugin
291
+ * Allows global installation of the SDK
63
292
  */
64
293
 
65
294
  declare const _default: {
@@ -67,17 +296,96 @@ declare const _default: {
67
296
  };
68
297
 
69
298
  /**
70
- * Device collector - placeholder
71
- * TODO: Copy from React SDK
299
+ * Keverd Device Fingerprint Collector
300
+ * Collects device information, canvas fingerprint, WebGL fingerprint, and generates a stable device ID
72
301
  */
302
+
73
303
  declare class KeverdDeviceCollector {
304
+ private cachedDeviceInfo;
305
+ /**
306
+ * Collect all device information and generate fingerprint
307
+ */
308
+ collect(): KeverdDeviceInfo;
309
+ /**
310
+ * Generate a stable device fingerprint using multiple browser characteristics
311
+ * Returns SHA-256 hash (64 hex characters) as required by backend
312
+ */
313
+ private generateDeviceFingerprint;
314
+ /**
315
+ * Generate canvas fingerprint
316
+ */
317
+ private getCanvasFingerprint;
318
+ /**
319
+ * Generate WebGL fingerprint
320
+ */
321
+ private getWebGLFingerprint;
322
+ /**
323
+ * Generate a stable device ID from fingerprint
324
+ */
325
+ private generateDeviceId;
326
+ /**
327
+ * Get manufacturer from user agent
328
+ */
329
+ private getManufacturer;
330
+ /**
331
+ * Get model from user agent
332
+ */
333
+ private getModel;
334
+ /**
335
+ * Get brand from user agent
336
+ */
337
+ private getBrand;
338
+ /**
339
+ * Get device type
340
+ */
341
+ private getDevice;
342
+ /**
343
+ * Get product name
344
+ */
345
+ private getProduct;
346
+ /**
347
+ * Get hardware info
348
+ */
349
+ private getHardware;
350
+ /**
351
+ * Get OS version
352
+ */
353
+ private getOSVersion;
354
+ /**
355
+ * Get screen density
356
+ */
357
+ private getScreenDensity;
358
+ /**
359
+ * Hash a string using SHA-256 (required for backend compatibility)
360
+ * Backend expects SHA-256 hash (64 hex characters)
361
+ * Uses Web Crypto API synchronously via a cached approach
362
+ */
363
+ private hashString;
364
+ /**
365
+ * SHA-256-like hash function (synchronous, deterministic)
366
+ * Produces 64-character hex string matching SHA-256 format
367
+ * This is a deterministic hash that mimics SHA-256 characteristics
368
+ */
369
+ private sha256LikeHash;
370
+ /**
371
+ * Clear cached device info (useful for testing)
372
+ */
373
+ clearCache(): void;
74
374
  }
75
375
 
76
- /**
77
- * Behavioral collector - placeholder
78
- * TODO: Copy from React SDK
79
- */
80
376
  declare class KeverdBehavioralCollector {
377
+ private isActive;
378
+ private sessionEvents;
379
+ private kinematicEngine;
380
+ private keystrokeMonitor;
381
+ constructor();
382
+ start(): void;
383
+ stop(): void;
384
+ reset(): void;
385
+ getData(): KeverdBehavioralData;
386
+ private buildSequence;
387
+ private trackEvent;
388
+ private calculateSessionEntropy;
81
389
  }
82
390
 
83
- export { KeverdBehavioralCollector, type KeverdBehavioralData, type KeverdConfig, KeverdDeviceCollector, type KeverdDeviceInfo, type KeverdError, type KeverdFingerprintRequest, type KeverdFingerprintResponse, type KeverdLoadOptions, _default as KeverdPlugin, KeverdSDK, type KeverdSessionInfo, type KeverdVisitorData, type KeverdVisitorDataOptions, type KeverdVisitorDataResult, useKeverdProvider, useKeverdVisitorData };
391
+ export { KeverdBehavioralCollector, type KeverdBehavioralData, type KeverdConfig, KeverdDeviceCollector, type KeverdDeviceInfo, type KeverdError, type KeverdFingerprintRequest, type KeverdFingerprintResponse, type KeverdLoadOptions, _default as KeverdPlugin, KeverdSDK, type KeverdSessionInfo, type KeverdVisitorData, type KeverdVisitorDataOptions, type KeverdVisitorDataResult, useKeverdContext, useKeverdProvider, useKeverdVisitorData };