@keverdjs/fraud-sdk-react 1.1.2 → 3.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/README.md CHANGED
@@ -18,20 +18,14 @@ yarn add @keverdjs/fraud-sdk-react
18
18
 
19
19
  ## Quick Start
20
20
 
21
- ### 1. Wrap your application with KeverdProvider
22
-
23
- In your `_app.tsx` (Next.js) or root component:
21
+ ### 1. Wrap your application with `KeverdProvider`
24
22
 
25
23
  ```tsx
26
24
  import { KeverdProvider } from '@keverdjs/fraud-sdk-react';
27
25
 
28
26
  function MyApp({ Component, pageProps }) {
29
27
  return (
30
- <KeverdProvider
31
- loadOptions={{
32
- apiKey: 'your-api-key-here',
33
- }}
34
- >
28
+ <KeverdProvider apiKey="pk_live_your_api_key_here">
35
29
  <Component {...pageProps} />
36
30
  </KeverdProvider>
37
31
  );
@@ -40,26 +34,19 @@ function MyApp({ Component, pageProps }) {
40
34
  export default MyApp;
41
35
  ```
42
36
 
43
- ### 2. Use the hook in your components
37
+ ### 2. Use `useKeverd` in your components
44
38
 
45
39
  ```tsx
46
- import { useKeverdVisitorData } from '@keverdjs/fraud-sdk-react';
40
+ import { useKeverd } from '@keverdjs/fraud-sdk-react';
47
41
 
48
42
  export default function Home() {
49
- const { isLoading, error, data, getData } = useKeverdVisitorData({
50
- immediate: true, // Automatically fetch on mount
51
- extendedResult: true,
52
- });
53
-
43
+ const { deviceId, riskScore, isLoading } = useKeverd();
54
44
  if (isLoading) return <div>Loading...</div>;
55
- if (error) return <div>Error: {error.message}</div>;
56
45
 
57
46
  return (
58
47
  <div>
59
- <h1>Risk Score: {data?.riskScore}%</h1>
60
- <p>Action: {data?.action}</p>
61
- <p>Reasons: {data?.reasons.join(', ')}</p>
62
- <button onClick={() => getData()}>Refresh Data</button>
48
+ <h1>Device ID: {deviceId}</h1>
49
+ <p>Risk Score: {riskScore}</p>
63
50
  </div>
64
51
  );
65
52
  }
@@ -75,7 +62,10 @@ The provider component that initializes the SDK and makes it available to child
75
62
 
76
63
  ```typescript
77
64
  interface KeverdProviderProps {
78
- loadOptions: KeverdLoadOptions;
65
+ apiKey?: string;
66
+ endpoint?: string;
67
+ debug?: boolean;
68
+ loadOptions?: KeverdLoadOptions; // legacy compatibility
79
69
  children: React.ReactNode;
80
70
  }
81
71
  ```
@@ -89,11 +79,17 @@ interface KeverdLoadOptions {
89
79
  }
90
80
  ```
91
81
 
92
- ### useKeverdVisitorData
82
+ ### useKeverd
83
+
84
+ High-level hook for quick integrations.
93
85
 
94
- Hook to access visitor data and risk assessment results.
86
+ ```tsx
87
+ const { deviceId, riskScore, isLoading, error, refresh } = useKeverd();
88
+ ```
89
+
90
+ ### useKeverdVisitorData
95
91
 
96
- **Usage:**
92
+ Advanced hook to access full visitor and risk payloads.
97
93
 
98
94
  ```tsx
99
95
  const {
@@ -156,10 +152,8 @@ Enable debug logging for development:
156
152
 
157
153
  ```tsx
158
154
  <KeverdProvider
159
- loadOptions={{
160
- apiKey: 'your-api-key',
161
- debug: true,
162
- }}
155
+ apiKey="your-api-key"
156
+ debug
163
157
  >
164
158
  {children}
165
159
  </KeverdProvider>
@@ -229,11 +223,7 @@ import { KeverdProvider } from '@keverdjs/fraud-sdk-react';
229
223
 
230
224
  function MyApp({ Component, pageProps }: AppProps) {
231
225
  return (
232
- <KeverdProvider
233
- loadOptions={{
234
- apiKey: process.env.NEXT_PUBLIC_KEVERD_API_KEY!,
235
- }}
236
- >
226
+ <KeverdProvider apiKey={process.env.NEXT_PUBLIC_KEVERD_API_KEY!}>
237
227
  <Component {...pageProps} />
238
228
  </KeverdProvider>
239
229
  );
@@ -256,11 +246,7 @@ export default function RootLayout({
256
246
  return (
257
247
  <html>
258
248
  <body>
259
- <KeverdProvider
260
- loadOptions={{
261
- apiKey: process.env.NEXT_PUBLIC_KEVERD_API_KEY!,
262
- }}
263
- >
249
+ <KeverdProvider apiKey={process.env.NEXT_PUBLIC_KEVERD_API_KEY!}>
264
250
  {children}
265
251
  </KeverdProvider>
266
252
  </body>
package/dist/index.d.mts CHANGED
@@ -61,13 +61,34 @@ interface KeverdSimSwapEngine {
61
61
  updatedProfile?: Record<string, unknown>;
62
62
  }
63
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;
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
+ fingerprint?: string;
71
+ event_id?: string;
72
+ device_id?: string;
73
+ similarity?: number;
74
+ is_new?: boolean;
75
+ is_drifted?: boolean;
76
+ history_count?: number;
77
+ times_seen?: number;
78
+ first_seen?: string;
79
+ last_seen?: string;
70
80
  sim_swap_engine?: KeverdSimSwapEngine;
81
+ confidence?: number;
82
+ device_match?: boolean;
83
+ fraud_probability?: number;
84
+ recommended_action?: string;
85
+ adaptive_response?: {
86
+ recommended_action?: string;
87
+ challenges?: string[];
88
+ reason?: string;
89
+ confidence?: number;
90
+ [key: string]: unknown;
91
+ };
71
92
  }
72
93
  interface KeverdVisitorData {
73
94
  visitorId: string;
@@ -79,16 +100,29 @@ interface KeverdVisitorData {
79
100
  requestId: string;
80
101
  simSwapEngine?: KeverdSimSwapEngine;
81
102
  confidence?: number;
103
+ deviceMatch?: boolean;
104
+ fraudProbability?: number;
105
+ recommendedAction?: string;
106
+ adaptiveResponse?: {
107
+ recommendedAction?: string;
108
+ challenges?: string[];
109
+ reason?: string;
110
+ confidence?: number;
111
+ [key: string]: unknown;
112
+ };
113
+ extendedResult?: Record<string, unknown>;
82
114
  }
83
115
  interface KeverdConfig {
84
- apiKey: string;
116
+ apiKey?: string;
85
117
  userId?: string;
118
+ endpoint?: string;
86
119
  debug?: boolean;
87
120
  extendedResult?: boolean;
88
121
  ignoreCache?: boolean;
89
122
  }
90
123
  interface KeverdLoadOptions {
91
- apiKey: string;
124
+ apiKey?: string;
125
+ endpoint?: string;
92
126
  debug?: boolean;
93
127
  }
94
128
  interface KeverdVisitorDataOptions {
@@ -112,6 +146,21 @@ interface KeverdVisitorDataResult$1 {
112
146
  data: KeverdVisitorData | null;
113
147
  getData: (options?: KeverdVisitorDataOptions) => Promise<KeverdVisitorData>;
114
148
  }
149
+ type LoginResult = 'success' | 'failure';
150
+ type AuthMethod = 'password' | 'password_otp' | 'password_totp' | 'sso' | 'magic_link' | 'passkey' | 'unknown';
151
+ interface LoginContext {
152
+ identifierHash?: string;
153
+ result?: LoginResult;
154
+ failureReason?: string;
155
+ authMethod?: AuthMethod;
156
+ mfaUsed?: boolean;
157
+ attemptId?: string;
158
+ }
159
+ interface VerifyLoginOptions {
160
+ userId?: string;
161
+ login?: LoginContext;
162
+ metadata?: Record<string, unknown>;
163
+ }
115
164
 
116
165
  /**
117
166
  * Keverd Fraud SDK Core
@@ -133,6 +182,13 @@ declare class KeverdSDK {
133
182
  * Get visitor data (fingerprint and risk assessment)
134
183
  */
135
184
  getVisitorData(options?: KeverdVisitorDataOptions): Promise<KeverdVisitorData>;
185
+ /**
186
+ * Verify user identity during login attempts.
187
+ *
188
+ * This is a thin wrapper around the core web SDK `verifyLogin`, so it sends
189
+ * the same enhanced signals and structured login context as the vanilla SDK.
190
+ */
191
+ verifyLogin(options?: VerifyLoginOptions): Promise<KeverdFingerprintResponse>;
136
192
  /**
137
193
  * Extract origin and referrer from browser
138
194
  */
@@ -145,10 +201,25 @@ declare class KeverdSDK {
145
201
  * Transform API response to visitor data format
146
202
  */
147
203
  private transformResponse;
148
- /**
149
- * Get default endpoint
204
+ private buildV2SignalsPayload;
205
+ private getWebGLInfo;
206
+ private parseBrowserInfo;
207
+ private parseOsInfo;
208
+ private detectBasicFonts;
209
+ private calculatePersistenceScore;
210
+ private getStorageFlags;
211
+ private isApiAvailable;
212
+ private getAudioCodecs;
213
+ private collectPrivacySignals;
214
+ private isStorageUnavailable;
215
+ private detectAdBlocker;
216
+ private computeSimpleHash;
217
+ private actionFromRisk;
218
+ /**
219
+ * Resolve endpoint: config > env > production default.
150
220
  */
151
221
  private getDefaultEndpoint;
222
+ private normalizeEndpoint;
152
223
  /**
153
224
  * Generate a session ID
154
225
  */
@@ -206,13 +277,16 @@ interface KeverdContextValue {
206
277
  isReady: boolean;
207
278
  }
208
279
  interface KeverdProviderProps {
209
- loadOptions: KeverdLoadOptions;
280
+ apiKey?: string;
281
+ endpoint?: string;
282
+ debug?: boolean;
283
+ loadOptions?: KeverdLoadOptions;
210
284
  children: ReactNode;
211
285
  }
212
286
  /**
213
287
  * KeverdProvider - Wrap your app with this component to enable Keverd SDK
214
288
  */
215
- declare function KeverdProvider({ loadOptions, children }: KeverdProviderProps): react_jsx_runtime.JSX.Element;
289
+ declare function KeverdProvider({ apiKey, endpoint, debug, loadOptions, children }: KeverdProviderProps): react_jsx_runtime.JSX.Element;
216
290
  /**
217
291
  * Hook to access Keverd SDK from context
218
292
  */
@@ -260,6 +334,48 @@ interface KeverdVisitorDataResult {
260
334
  */
261
335
  declare function useKeverdVisitorData(options?: KeverdVisitorDataHookOptions): KeverdVisitorDataResult;
262
336
 
337
+ interface UseKeverdResult {
338
+ deviceId: string | null;
339
+ riskScore: number | null;
340
+ isLoading: boolean;
341
+ error: {
342
+ message: string;
343
+ code?: string;
344
+ statusCode?: number;
345
+ } | null;
346
+ refresh: () => Promise<void>;
347
+ }
348
+ /**
349
+ * High-level hook used by the React quickstart.
350
+ */
351
+ declare function useKeverd(): UseKeverdResult;
352
+
353
+ interface HashLoginIdentifierOptions {
354
+ salt?: string;
355
+ prefix?: string;
356
+ }
357
+ interface BuildLoginContextOptions {
358
+ identifier: string;
359
+ result?: LoginResult;
360
+ failureReason?: string;
361
+ authMethod?: AuthMethod;
362
+ mfaUsed?: boolean;
363
+ attemptId?: string;
364
+ salt?: string;
365
+ }
366
+ declare function hashLoginIdentifier(identifier: string, options?: HashLoginIdentifierOptions): Promise<string>;
367
+ declare function buildLoginContextFromIdentifier(options: BuildLoginContextOptions): Promise<LoginContext>;
368
+
369
+ interface AdaptiveActionHandlers {
370
+ onAllow?: (response: KeverdFingerprintResponse) => void;
371
+ onSoftChallenge?: (response: KeverdFingerprintResponse) => void;
372
+ onHardChallenge?: (response: KeverdFingerprintResponse) => void;
373
+ onBlock?: (response: KeverdFingerprintResponse) => void;
374
+ onChallenges?: (response: KeverdFingerprintResponse, challenges: string[]) => void;
375
+ onUnknown?: (response: KeverdFingerprintResponse) => void;
376
+ }
377
+ declare function handleAdaptiveResponse(response: KeverdFingerprintResponse, handlers: AdaptiveActionHandlers): void;
378
+
263
379
  /**
264
380
  * Keverd Device Fingerprint Collector
265
381
  * Collects device information, canvas fingerprint, WebGL fingerprint, and generates a stable device ID
@@ -353,4 +469,4 @@ declare class KeverdBehavioralCollector {
353
469
  private calculateSessionEntropy;
354
470
  }
355
471
 
356
- export { KeverdBehavioralCollector, type KeverdBehavioralData, type KeverdConfig, KeverdDeviceCollector, type KeverdDeviceInfo, type KeverdError, type KeverdFingerprintRequest, type KeverdFingerprintResponse, type KeverdLoadOptions, KeverdProvider, KeverdSDK, type KeverdSessionInfo, type KeverdSimSwapEngine, type KeverdVisitorData, type KeverdVisitorDataHookOptions, type KeverdVisitorDataOptions, type KeverdVisitorDataResult$1 as KeverdVisitorDataResult, useKeverdContext, useKeverdVisitorData };
472
+ export { KeverdBehavioralCollector, type KeverdBehavioralData, type KeverdConfig, KeverdDeviceCollector, type KeverdDeviceInfo, type KeverdError, type KeverdFingerprintRequest, type KeverdFingerprintResponse, type KeverdLoadOptions, KeverdProvider, KeverdSDK, type KeverdSessionInfo, type KeverdSimSwapEngine, type KeverdVisitorData, type KeverdVisitorDataHookOptions, type KeverdVisitorDataOptions, type KeverdVisitorDataResult$1 as KeverdVisitorDataResult, type UseKeverdResult, buildLoginContextFromIdentifier, handleAdaptiveResponse, hashLoginIdentifier, useKeverd, useKeverdContext, useKeverdVisitorData };
package/dist/index.d.ts CHANGED
@@ -61,13 +61,34 @@ interface KeverdSimSwapEngine {
61
61
  updatedProfile?: Record<string, unknown>;
62
62
  }
63
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;
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
+ fingerprint?: string;
71
+ event_id?: string;
72
+ device_id?: string;
73
+ similarity?: number;
74
+ is_new?: boolean;
75
+ is_drifted?: boolean;
76
+ history_count?: number;
77
+ times_seen?: number;
78
+ first_seen?: string;
79
+ last_seen?: string;
70
80
  sim_swap_engine?: KeverdSimSwapEngine;
81
+ confidence?: number;
82
+ device_match?: boolean;
83
+ fraud_probability?: number;
84
+ recommended_action?: string;
85
+ adaptive_response?: {
86
+ recommended_action?: string;
87
+ challenges?: string[];
88
+ reason?: string;
89
+ confidence?: number;
90
+ [key: string]: unknown;
91
+ };
71
92
  }
72
93
  interface KeverdVisitorData {
73
94
  visitorId: string;
@@ -79,16 +100,29 @@ interface KeverdVisitorData {
79
100
  requestId: string;
80
101
  simSwapEngine?: KeverdSimSwapEngine;
81
102
  confidence?: number;
103
+ deviceMatch?: boolean;
104
+ fraudProbability?: number;
105
+ recommendedAction?: string;
106
+ adaptiveResponse?: {
107
+ recommendedAction?: string;
108
+ challenges?: string[];
109
+ reason?: string;
110
+ confidence?: number;
111
+ [key: string]: unknown;
112
+ };
113
+ extendedResult?: Record<string, unknown>;
82
114
  }
83
115
  interface KeverdConfig {
84
- apiKey: string;
116
+ apiKey?: string;
85
117
  userId?: string;
118
+ endpoint?: string;
86
119
  debug?: boolean;
87
120
  extendedResult?: boolean;
88
121
  ignoreCache?: boolean;
89
122
  }
90
123
  interface KeverdLoadOptions {
91
- apiKey: string;
124
+ apiKey?: string;
125
+ endpoint?: string;
92
126
  debug?: boolean;
93
127
  }
94
128
  interface KeverdVisitorDataOptions {
@@ -112,6 +146,21 @@ interface KeverdVisitorDataResult$1 {
112
146
  data: KeverdVisitorData | null;
113
147
  getData: (options?: KeverdVisitorDataOptions) => Promise<KeverdVisitorData>;
114
148
  }
149
+ type LoginResult = 'success' | 'failure';
150
+ type AuthMethod = 'password' | 'password_otp' | 'password_totp' | 'sso' | 'magic_link' | 'passkey' | 'unknown';
151
+ interface LoginContext {
152
+ identifierHash?: string;
153
+ result?: LoginResult;
154
+ failureReason?: string;
155
+ authMethod?: AuthMethod;
156
+ mfaUsed?: boolean;
157
+ attemptId?: string;
158
+ }
159
+ interface VerifyLoginOptions {
160
+ userId?: string;
161
+ login?: LoginContext;
162
+ metadata?: Record<string, unknown>;
163
+ }
115
164
 
116
165
  /**
117
166
  * Keverd Fraud SDK Core
@@ -133,6 +182,13 @@ declare class KeverdSDK {
133
182
  * Get visitor data (fingerprint and risk assessment)
134
183
  */
135
184
  getVisitorData(options?: KeverdVisitorDataOptions): Promise<KeverdVisitorData>;
185
+ /**
186
+ * Verify user identity during login attempts.
187
+ *
188
+ * This is a thin wrapper around the core web SDK `verifyLogin`, so it sends
189
+ * the same enhanced signals and structured login context as the vanilla SDK.
190
+ */
191
+ verifyLogin(options?: VerifyLoginOptions): Promise<KeverdFingerprintResponse>;
136
192
  /**
137
193
  * Extract origin and referrer from browser
138
194
  */
@@ -145,10 +201,25 @@ declare class KeverdSDK {
145
201
  * Transform API response to visitor data format
146
202
  */
147
203
  private transformResponse;
148
- /**
149
- * Get default endpoint
204
+ private buildV2SignalsPayload;
205
+ private getWebGLInfo;
206
+ private parseBrowserInfo;
207
+ private parseOsInfo;
208
+ private detectBasicFonts;
209
+ private calculatePersistenceScore;
210
+ private getStorageFlags;
211
+ private isApiAvailable;
212
+ private getAudioCodecs;
213
+ private collectPrivacySignals;
214
+ private isStorageUnavailable;
215
+ private detectAdBlocker;
216
+ private computeSimpleHash;
217
+ private actionFromRisk;
218
+ /**
219
+ * Resolve endpoint: config > env > production default.
150
220
  */
151
221
  private getDefaultEndpoint;
222
+ private normalizeEndpoint;
152
223
  /**
153
224
  * Generate a session ID
154
225
  */
@@ -206,13 +277,16 @@ interface KeverdContextValue {
206
277
  isReady: boolean;
207
278
  }
208
279
  interface KeverdProviderProps {
209
- loadOptions: KeverdLoadOptions;
280
+ apiKey?: string;
281
+ endpoint?: string;
282
+ debug?: boolean;
283
+ loadOptions?: KeverdLoadOptions;
210
284
  children: ReactNode;
211
285
  }
212
286
  /**
213
287
  * KeverdProvider - Wrap your app with this component to enable Keverd SDK
214
288
  */
215
- declare function KeverdProvider({ loadOptions, children }: KeverdProviderProps): react_jsx_runtime.JSX.Element;
289
+ declare function KeverdProvider({ apiKey, endpoint, debug, loadOptions, children }: KeverdProviderProps): react_jsx_runtime.JSX.Element;
216
290
  /**
217
291
  * Hook to access Keverd SDK from context
218
292
  */
@@ -260,6 +334,48 @@ interface KeverdVisitorDataResult {
260
334
  */
261
335
  declare function useKeverdVisitorData(options?: KeverdVisitorDataHookOptions): KeverdVisitorDataResult;
262
336
 
337
+ interface UseKeverdResult {
338
+ deviceId: string | null;
339
+ riskScore: number | null;
340
+ isLoading: boolean;
341
+ error: {
342
+ message: string;
343
+ code?: string;
344
+ statusCode?: number;
345
+ } | null;
346
+ refresh: () => Promise<void>;
347
+ }
348
+ /**
349
+ * High-level hook used by the React quickstart.
350
+ */
351
+ declare function useKeverd(): UseKeverdResult;
352
+
353
+ interface HashLoginIdentifierOptions {
354
+ salt?: string;
355
+ prefix?: string;
356
+ }
357
+ interface BuildLoginContextOptions {
358
+ identifier: string;
359
+ result?: LoginResult;
360
+ failureReason?: string;
361
+ authMethod?: AuthMethod;
362
+ mfaUsed?: boolean;
363
+ attemptId?: string;
364
+ salt?: string;
365
+ }
366
+ declare function hashLoginIdentifier(identifier: string, options?: HashLoginIdentifierOptions): Promise<string>;
367
+ declare function buildLoginContextFromIdentifier(options: BuildLoginContextOptions): Promise<LoginContext>;
368
+
369
+ interface AdaptiveActionHandlers {
370
+ onAllow?: (response: KeverdFingerprintResponse) => void;
371
+ onSoftChallenge?: (response: KeverdFingerprintResponse) => void;
372
+ onHardChallenge?: (response: KeverdFingerprintResponse) => void;
373
+ onBlock?: (response: KeverdFingerprintResponse) => void;
374
+ onChallenges?: (response: KeverdFingerprintResponse, challenges: string[]) => void;
375
+ onUnknown?: (response: KeverdFingerprintResponse) => void;
376
+ }
377
+ declare function handleAdaptiveResponse(response: KeverdFingerprintResponse, handlers: AdaptiveActionHandlers): void;
378
+
263
379
  /**
264
380
  * Keverd Device Fingerprint Collector
265
381
  * Collects device information, canvas fingerprint, WebGL fingerprint, and generates a stable device ID
@@ -353,4 +469,4 @@ declare class KeverdBehavioralCollector {
353
469
  private calculateSessionEntropy;
354
470
  }
355
471
 
356
- export { KeverdBehavioralCollector, type KeverdBehavioralData, type KeverdConfig, KeverdDeviceCollector, type KeverdDeviceInfo, type KeverdError, type KeverdFingerprintRequest, type KeverdFingerprintResponse, type KeverdLoadOptions, KeverdProvider, KeverdSDK, type KeverdSessionInfo, type KeverdSimSwapEngine, type KeverdVisitorData, type KeverdVisitorDataHookOptions, type KeverdVisitorDataOptions, type KeverdVisitorDataResult$1 as KeverdVisitorDataResult, useKeverdContext, useKeverdVisitorData };
472
+ export { KeverdBehavioralCollector, type KeverdBehavioralData, type KeverdConfig, KeverdDeviceCollector, type KeverdDeviceInfo, type KeverdError, type KeverdFingerprintRequest, type KeverdFingerprintResponse, type KeverdLoadOptions, KeverdProvider, KeverdSDK, type KeverdSessionInfo, type KeverdSimSwapEngine, type KeverdVisitorData, type KeverdVisitorDataHookOptions, type KeverdVisitorDataOptions, type KeverdVisitorDataResult$1 as KeverdVisitorDataResult, type UseKeverdResult, buildLoginContextFromIdentifier, handleAdaptiveResponse, hashLoginIdentifier, useKeverd, useKeverdContext, useKeverdVisitorData };