npm package: @olo/fraud-prevention-js-sdk
Description: [![npm version](https://img.shields.io/npm/v/@olo/fraud-prevention-js-sdk.svg)](https://www.npmjs.com/package/@olo/fraud-prevention-js-sdk) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
Author: Olo
Latest version: 1.0.0

# Fraud Prevention JS SDK

[![npm version](https://img.shields.io/npm/v/@olo/fraud-prevention-js-sdk.svg)](https://www.npmjs.com/package/@olo/fraud-prevention-js-sdk)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## 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](https://www.forter.com/) - 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

```bash
npm install @olo/fraud-prevention-js-sdk
```

## Quick Start

```typescript
import { ForterFP, ForterEnvironment } from "@olo/fraud-prevention-js-sdk";

// 1. Initialize once at app startup
const fraudPrevention = new ForterFP({
	siteId: "olo-forter-site-id", // Contact your Olo representative to obtain this
	environment: ForterEnvironment.Production,
});

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 `siteId` is Olo's global Forter site ID. Contact your Olo representative to obtain this value.

## Provider Documentation

For detailed integration instructions and API reference, see:

- **[Forter Integration Guide](./src/ForterFP/README.md)** - Complete setup, usage examples, and troubleshooting

## API Reference

### Core Classes

#### `ForterFP`

The Forter fraud prevention integration class.

**Constructor:**
```typescript
new ForterFP(config: ForterFPConfig)
```

**Configuration:**
- `siteId` (string, required): Olo's global Forter site ID. Contact your Olo representative to obtain this value.
- `environment` (ForterEnvironment, optional): Environment setting (Production, Staging, or Development)

**Methods:**
- `create()`: Initializes and injects the Forter script into the DOM
- `getFraudSessionId()`: Returns the fraud session ID (token) or null if not yet available
- `destroy(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](./src/ForterFP/README.md).

## Development

See [CONTRIBUTING.md](./CONTRIBUTING.md) for development setup and contribution guidelines.

### Quick Start for Contributors

```bash
# Install dependencies
npm install

# Run tests
npm run test

# Build the library
npm run build

# Run linting
npm run lint
```

## Browser Support

This library supports all modern browsers that support ES2022.

## License

MIT © [Olo](https://www.olo.com/)

## Resources

- [Forter Documentation](https://docs.forter.com/)
- [Contributing Guide](./CONTRIBUTING.md)
- [Changelog](./CHANGELOG.md)