@keverdjs/fraud-sdk-vue 1.0.0 → 1.1.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,243 @@
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
+ endpoint?: string;
97
+ userId?: string;
98
+ debug?: boolean;
99
+ extendedResult?: boolean;
100
+ ignoreCache?: boolean;
101
+ }
102
+ interface KeverdLoadOptions {
103
+ apiKey: string;
104
+ endpoint?: string;
105
+ debug?: boolean;
106
+ }
107
+ interface KeverdVisitorDataOptions {
108
+ extendedResult?: boolean;
109
+ ignoreCache?: boolean;
110
+ tag?: string;
37
111
  }
38
112
  interface KeverdError {
113
+ message: string;
114
+ code?: string;
115
+ statusCode?: number;
116
+ }
117
+ interface KeverdVisitorDataResult {
118
+ data: Ref<KeverdVisitorData | null>;
119
+ loading: Ref<boolean>;
120
+ error: Ref<KeverdError | null>;
121
+ getData: () => Promise<void>;
39
122
  }
40
123
 
41
124
  /**
42
- * Vue composable for getting visitor data
43
- * TODO: Implement Vue composable
125
+ * Keverd Fraud SDK Core
126
+ * Main SDK class for fingerprinting and risk assessment
127
+ * Wraps the web SDK to provide Vue-specific interface with all enhanced signals
44
128
  */
45
129
 
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
- };
130
+ declare class KeverdSDK {
131
+ private config;
132
+ private isInitialized;
133
+ constructor();
134
+ /**
135
+ * Initialize the SDK with configuration
136
+ * Wraps the web SDK initialization
137
+ */
138
+ init(config: KeverdConfig): void;
139
+ /**
140
+ * Get visitor data (fingerprint and risk assessment)
141
+ * Uses the web SDK which includes all enhanced signals including FingerprintJS
142
+ */
143
+ getVisitorData(_options?: KeverdVisitorDataOptions): Promise<KeverdVisitorData>;
144
+ /**
145
+ * Transform API response to visitor data format
146
+ */
147
+ private transformResponse;
148
+ /**
149
+ * Get default endpoint
150
+ */
151
+ private getDefaultEndpoint;
152
+ /**
153
+ * Generate a session ID
154
+ */
155
+ private generateSessionId;
156
+ /**
157
+ * Destroy the SDK instance
158
+ */
159
+ destroy(): void;
160
+ /**
161
+ * Get current configuration
162
+ */
163
+ getConfig(): KeverdConfig | null;
164
+ /**
165
+ * Check if SDK is initialized
166
+ */
167
+ isReady(): boolean;
168
+ }
52
169
 
53
170
  /**
54
- * Vue composable for Keverd provider
55
- * TODO: Implement Vue provider composable
171
+ * Vue composable for getting visitor data
172
+ * Provides reactive visitor data, loading state, and error handling
56
173
  */
57
174
 
58
- declare function useKeverdProvider(options: KeverdLoadOptions): void;
175
+ interface KeverdVisitorDataHookOptions {
176
+ extendedResult?: boolean;
177
+ immediate?: boolean;
178
+ ignoreCache?: boolean;
179
+ }
180
+ /**
181
+ * Vue composable for accessing visitor data and risk assessment
182
+ *
183
+ * @param options - Configuration options for the hook
184
+ * @returns Object containing reactive data, loading state, error, and getData function
185
+ *
186
+ * @example
187
+ * ```vue
188
+ * <script setup>
189
+ * import { useKeverdVisitorData } from '@keverdjs/fraud-sdk-vue';
190
+ *
191
+ * const { data, loading, error, getData } = useKeverdVisitorData({
192
+ * extendedResult: true,
193
+ * immediate: true
194
+ * });
195
+ * </script>
196
+ *
197
+ * <template>
198
+ * <div v-if="loading">Loading...</div>
199
+ * <div v-else-if="error">Error: {{ error.message }}</div>
200
+ * <div v-else>
201
+ * <p>Risk Score: {{ data?.riskScore }}</p>
202
+ * <button @click="getData">Reload</button>
203
+ * </div>
204
+ * </template>
205
+ * ```
206
+ */
207
+ declare function useKeverdVisitorData(options?: KeverdVisitorDataHookOptions): KeverdVisitorDataResult;
208
+
209
+ /**
210
+ * Setup Keverd SDK provider
211
+ * Call this in your root component or app setup
212
+ */
213
+ declare function useKeverdProvider(options: KeverdLoadOptions): {
214
+ sdk: Ref<{
215
+ init: (config: KeverdConfig) => void;
216
+ getVisitorData: (_options?: KeverdVisitorDataOptions) => Promise<KeverdVisitorData>;
217
+ destroy: () => void;
218
+ getConfig: () => KeverdConfig | null;
219
+ isReady: () => boolean;
220
+ } | null, KeverdSDK | {
221
+ init: (config: KeverdConfig) => void;
222
+ getVisitorData: (_options?: KeverdVisitorDataOptions) => Promise<KeverdVisitorData>;
223
+ destroy: () => void;
224
+ getConfig: () => KeverdConfig | null;
225
+ isReady: () => boolean;
226
+ } | null>;
227
+ isReady: Ref<boolean, boolean>;
228
+ };
229
+ /**
230
+ * Get Keverd SDK instance from context
231
+ * Use this in child components to access the SDK
232
+ */
233
+ declare function useKeverdContext(): {
234
+ sdk: Ref<KeverdSDK | null>;
235
+ isReady: Ref<boolean>;
236
+ };
59
237
 
60
238
  /**
61
239
  * Vue plugin for Keverd SDK
62
- * TODO: Implement Vue plugin
240
+ * Allows global installation of the SDK
63
241
  */
64
242
 
65
243
  declare const _default: {
@@ -67,17 +245,96 @@ declare const _default: {
67
245
  };
68
246
 
69
247
  /**
70
- * Device collector - placeholder
71
- * TODO: Copy from React SDK
248
+ * Keverd Device Fingerprint Collector
249
+ * Collects device information, canvas fingerprint, WebGL fingerprint, and generates a stable device ID
72
250
  */
251
+
73
252
  declare class KeverdDeviceCollector {
253
+ private cachedDeviceInfo;
254
+ /**
255
+ * Collect all device information and generate fingerprint
256
+ */
257
+ collect(): KeverdDeviceInfo;
258
+ /**
259
+ * Generate a stable device fingerprint using multiple browser characteristics
260
+ * Returns SHA-256 hash (64 hex characters) as required by backend
261
+ */
262
+ private generateDeviceFingerprint;
263
+ /**
264
+ * Generate canvas fingerprint
265
+ */
266
+ private getCanvasFingerprint;
267
+ /**
268
+ * Generate WebGL fingerprint
269
+ */
270
+ private getWebGLFingerprint;
271
+ /**
272
+ * Generate a stable device ID from fingerprint
273
+ */
274
+ private generateDeviceId;
275
+ /**
276
+ * Get manufacturer from user agent
277
+ */
278
+ private getManufacturer;
279
+ /**
280
+ * Get model from user agent
281
+ */
282
+ private getModel;
283
+ /**
284
+ * Get brand from user agent
285
+ */
286
+ private getBrand;
287
+ /**
288
+ * Get device type
289
+ */
290
+ private getDevice;
291
+ /**
292
+ * Get product name
293
+ */
294
+ private getProduct;
295
+ /**
296
+ * Get hardware info
297
+ */
298
+ private getHardware;
299
+ /**
300
+ * Get OS version
301
+ */
302
+ private getOSVersion;
303
+ /**
304
+ * Get screen density
305
+ */
306
+ private getScreenDensity;
307
+ /**
308
+ * Hash a string using SHA-256 (required for backend compatibility)
309
+ * Backend expects SHA-256 hash (64 hex characters)
310
+ * Uses Web Crypto API synchronously via a cached approach
311
+ */
312
+ private hashString;
313
+ /**
314
+ * SHA-256-like hash function (synchronous, deterministic)
315
+ * Produces 64-character hex string matching SHA-256 format
316
+ * This is a deterministic hash that mimics SHA-256 characteristics
317
+ */
318
+ private sha256LikeHash;
319
+ /**
320
+ * Clear cached device info (useful for testing)
321
+ */
322
+ clearCache(): void;
74
323
  }
75
324
 
76
- /**
77
- * Behavioral collector - placeholder
78
- * TODO: Copy from React SDK
79
- */
80
325
  declare class KeverdBehavioralCollector {
326
+ private isActive;
327
+ private sessionEvents;
328
+ private kinematicEngine;
329
+ private keystrokeMonitor;
330
+ constructor();
331
+ start(): void;
332
+ stop(): void;
333
+ reset(): void;
334
+ getData(): KeverdBehavioralData;
335
+ private buildSequence;
336
+ private trackEvent;
337
+ private calculateSessionEntropy;
81
338
  }
82
339
 
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 };
340
+ 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 };