Anon Frontend SDK
The@anon-dot-com/frontend package provides a lightweight JavaScript library for embedding the Anon Enterprise Data Migration platform directly into your web application. This SDK handles user authentication, migration status checking, and provides seamless integration through a secure iframe modal.
Overview
The SDK creates a responsive iframe modal that displays the Anon migration interface within any web application. It provides event-driven communication and handles the complete migration lifecycle using a secure token-based authentication flow.The SDK uses a two-step authentication process: your backend generates a link token using your API key, and the frontend exchanges it for an access token that’s stored securely in the browser.
Installation
This is a private npm package that requires authentication to install.Configure npm Authentication
Create or update your.npmrc file in your project root with the authentication token:
Contact your Anon point-of-contact to obtain the access token for your
.npmrc configuration.Install the Package
Once your.npmrc is configured, you can install the package using your preferred package manager:
Quick Start
Basic Integration
The SDK provides two main methods for integrating the migration modal:Advanced Configuration
Configure the modal with additional options for more control over the migration process:Global Script Usage
If you’re not using a module bundler, include the library as a global script:API Reference
Methods
init(options: AnonInitOptions)
init(options: AnonInitOptions)
Initializes the SDK and finds any existing migration for the user. This method checks localStorage for previous migration options and attempts to continue an existing migration if found.Parameters:
options: Configuration object of typeAnonInitOptions
- Promise that resolves with migration metadata if an existing migration is found, or undefined
startModal(options: AnonLinkOptions)
startModal(options: AnonLinkOptions)
Creates a new modal link for the user and immediately shows the iframe modal. This method requires a link token obtained from your backend.Parameters:
options: Configuration object of typeAnonLinkOptions
- Promise that resolves when the modal is started
Configuration Options
AnonInitOptions
TheAnonInitOptions interface accepts the following properties:
| Property | Type | Required | Description |
|---|---|---|---|
onEvent | (event: EventData) => void | No | Callback for migration events |
target | string | No | CSS selector for target element (defaults to “body”) |
baseURL | string | No | Base URL for API requests (defaults to “https://worker.anon.com”) |
AnonLinkOptions
TheAnonLinkOptions interface extends AnonInitOptions and accepts additional properties:
| Property | Type | Required | Description |
|---|---|---|---|
userId | string | Yes | User identifier (UUID or email address) |
linkToken | string | Yes | Link token obtained from your backend’s /api/v1/link-token endpoint |
sourceProviders | string[] | No | Pre-configured source providers for migration |
Event Structure
TheonEvent callback receives events with the following structure:
Common event types include
migration_modal.completed, migration_modal.failed, and migration_modal.cancelled.Authentication Flow
The SDK uses a secure two-step authentication process:- Link Token Generation: Your backend calls the Anon API to create a link token
- Access Token Exchange: The frontend exchanges the link token for a browser-safe access token
Step 1: Backend Link Token Generation
Your backend must implement an endpoint that generates link tokens:- Next.js
- Express.js
Step 2: Frontend Access Token Exchange
The SDK automatically handles the access token exchange when you callstartModal() with a link token. The access token is stored in localStorage and used for subsequent API calls.
Migration Persistence
The SDK automatically persists migration state in the browser’s localStorage. When you callinit(), it checks for any existing migration options and attempts to continue where the user left off.
Architecture Flow
The following diagram illustrates the new authentication flow:Backend Requirements
Required Endpoints
Your backend needs to implement the following endpoint:| Endpoint | Method | Purpose |
|---|---|---|
/api/anon/link-token | POST | Generate a link token for frontend authentication |
Security Considerations
- Store your Anon API key securely in environment variables
- Implement proper authentication/authorization for the link token endpoint
- Consider rate limiting the link token endpoint to prevent abuse
- Link tokens are short-lived (60 seconds) and single-use for security
Migration from Previous Versions
If you’re migrating from a previous version that usedloadModal() and proxy URLs:
Before (v0.x)
After (v1.x)
Breaking Changes
loadModal()has been replaced withinit()for resuming existing migrationsproxyUrlis no longer required; the SDK communicates directly with Anon APIslinkTokenis now required forstartModal()- New
/api/v1/link-tokenendpoint required on your backend
Next Steps
Embedding the Modal
Learn more about iframe integration best practices
Webhooks
Set up webhooks to receive migration status updates
API Reference
Explore the complete Anon API documentation
Messages
Handle migration events and messages