@olo/fraud-prevention-js-sdk
v1.2.0
Published
[](https://www.npmjs.com/package/@olo/fraud-prevention-js-sdk) [](https://opensource.org/licenses/MIT)
Keywords
Readme
Fraud Prevention JS SDK
Introduction
The Fraud Prevention JS SDK is a lightweight, browser-based JavaScript library that simplifies fraud prevention integration in web applications. The SDK handles script injection, session tracking, and token management automatically, so you can protect your application from fraudulent transactions with just a few lines of code.
Currently Supported Providers:
- Forter - Real-time fraud prevention platform
Key Features:
- Simple, minimal API - just initialize, create, and get the token
- TypeScript support with full type definitions
- Automatic session tracking and token generation
- Memory leak prevention with built-in cleanup
Installation
npm install @olo/fraud-prevention-js-sdkQuick Start
import { ForterFP, ForterEnvironment } from "@olo/fraud-prevention-js-sdk";
// 1. Initialize once at app startup
const fraudPrevention = new ForterFP({
environment: ForterEnvironment.Production, // Optional, defaults to Production
// Optional: Enable CSP support if your site uses Content Security Policy
csp: true,
});
fraudPrevention.create();
// 2. Make it globally accessible
window.fraudPrevention = fraudPrevention;
// 3. Use throughout your app when submitting orders
await fetch("/api/orders", {
method: "POST",
body: JSON.stringify({
...orderData,
fraudSessionId: window.fraudPrevention?.getFraudSessionId() ?? undefined,
}),
});Note: The SDK automatically uses Olo's environment-specific Forter site ID based on your environment setting (Production or Test). Site IDs are internal to the SDK to prevent configuration errors.
Provider Documentation
For detailed integration instructions and API reference, see:
- Forter Integration Guide - Complete setup, usage examples, and troubleshooting
API Reference
Core Classes
ForterFP
The Forter fraud prevention integration class.
Constructor:
new ForterFP(config?: ForterFPConfig)Configuration:
environment(ForterEnvironment, optional): Environment setting (Production or Test). Defaults to Production. The SDK automatically uses Olo's environment-specific site ID based on this setting.csp(boolean, optional): Enable Content Security Policy support. Set totrueif your site uses CSP headers to avoid violation reports. Default:false
Methods:
create(): Initializes and injects the Forter script into the DOMgetFraudSessionId(): Returns the fraud session ID (token) or null if not yet availabledestroy(removeScript?: boolean): Cleans up event listeners and optionally removes the script from the DOM
For complete API documentation and usage examples, refer to the Forter Integration Guide.
Development
See CONTRIBUTING.md for development setup and contribution guidelines.
Quick Start for Contributors
# Install dependencies
npm install
# Run tests
npm run test
# Build the library
npm run build
# Run linting
npm run lintBrowser Support
This library supports all modern browsers that support ES2022.
License
MIT © Olo
