deepfake-sdk-js
v1.0.4
Published
JavaScript SDK for Deepfake Detection API
Readme
Deepfake Detection SDK
A powerful JavaScript SDK designed for seamless integration with the Deepfake Detection backend. This SDK enables developers to consume backend APIs with ease, including authentication, deepfake file analysis, liveness detection, ID verification, content provenance, analytics, and feedback handling — all with automatic token management and secure request handling.
Table of Contents
- Overview
- Tech Stack
- Features
- SDK Structure
- Installation
- Initialization
- Usage Examples
- Authentication Methods
- ML & Detection Methods
- User Profile Methods
- Analytics Methods
- Feedback Methods
- Error Handling
- Security Notes
- Publishing Guide
Overview
This SDK provides a developer-friendly wrapper around the Deepfake Detection Backend REST API. It enables:
Authentication: Register,Verify OTP,Resend OTP,Login,Refresh Token,Logout,ForgotPassword,Verify Email
Deepfake Detection: File and URL analysis for images, videos, audio, and text
Liveness Detection: Verifying real-time human presence
ID Verification: Matching face ID documents with live images
Content Provenance: Metadata verification and write operations
Analytics: Media usage analytics and activity stats
Feedback Submission: ML model improvement through user input
It handles:
Automatic token refresh
Error formatting
File uploads
Authorization headers
Secure cookie management
Tech Stack
Core Technologies
Language: JavaScript (ES Modules)
Build System: Rollup (ESM, CJS, UMD bundles)
HTTP Requests: Fetch API
Compatibility:
Browsers (React, Vue, Next.js)
Node.js (v18+)
Optional TypeScript Support
Type definitions (index.d.ts) included
Features
Authentication
Registration with OTP
Login with access & refresh tokens
Auto token refresh
Secure logout
ML & Detection Services
File Uploads: image, video, audio, text
URL Analysis
ID Verification
Liveness Detection
Provenance Metadata
User & Analytics
Get/update user profile
View activity analytics
View liveness/ID verification analytics
Paginated request history
Developer Tools
Zero external dependencies
Clean unified error handling
Auto retries for expired tokens
Works in both frontend and backend
SDK Structure
deepfake-sdk/
├── dist/ # Compiled SDK bundles (CJS, ESM, UMD)
├── src/
│ ├── http.js # Base HTTP client
│ ├── auth.js # Authentication logic
│ ├── ml.js # ML & detection services
│ ├── user.js # User profile
│ ├── analytics.js # Analytics module
│ └── feedback.js # Feedback module
├── package.json
├── README.md
└── .npmignore
Installation
NPM
npm install deepfake-sdk-jsYarn
yarn add deepfake-sdk-jsCDN (UMD)
<script src="https://cdn.jsdelivr.net/npm/deepfake-sdk-js/dist/index.js"></script>
<script>
const sdk = new DeepfakeSDK({
baseURL: "https://api.example.com/api/v1",
apiKey: "YOUR_SECRET_KEY"
});
</script>
Initialization
import DeepfakeSDK from "deepfake-sdk-js";
const sdk = new DeepfakeSDK({
baseURL: "https://your-api-domain.com/api/v1",
apiKey: "YOUR_SECRET_API_KEY"
});✔ Automatically attaches access tokens ✔ Auto-refreshes tokens ✔ Works with HttpOnly refresh cookies
Usage Examples
Upload a file for deepfake detection
const file = document.querySelector("#fileInput").files[0];
const result = await sdk.ml.uploadFile(file);
console.log(result);
Analyze using a URL
await sdk.ml.analyzeUrl("https://example.com/media.mp4");Authentication Methods
Register
await sdk.auth.register({
name: "John",
email: "[email protected]",
password: "Password123",
phone: "+918888888888"
});Verify OTP
await sdk.auth.verifyOtp(registrationId, "123456");Login
await sdk.auth.login("[email protected]", "Password123");
Resend OTP
await sdk.auth.resendOtp(regId);Refresh Token
await sdk.auth.refresh();Logout
await sdk.auth.logout();Forgot Password
await sdk.auth.forgotPassword("[email protected]");Verify Email
await sdk.auth.verifyEmail(token);ML & Detection Methods
Upload File (Image/Video/Audio/Text)
await sdk.ml.uploadFile(file);URL-Based Analysis
await sdk.ml.analyzeUrl("https://example.com/demo.mp4");ID Verification
await sdk.ml.idVerification(sourceImage, targetImage);Liveness Detection
await sdk.ml.livenessDetection({
lastFrame: base64string,
isLive: true,
confidence: 0.98
});Provenance Metadata
await sdk.ml.provenance(file, {
creator_name: "John",
title: "Document",
include_exif: "true"
});Face Enrollment
await sdk.ml.faceEnroll(file, { userId: "123" });Face Search
await sdk.ml.faceSearch(file);Get Face Enrollment List
await sdk.ml.getFaceEnrollment();User Profile Methods
Get Profile
await sdk.user.getProfile();Update Profile
await sdk.user.updateProfile({ name: "New Name" });Analytics Methods
Summary Analytics
await sdk.analytics.summary();Liveness Analytics
await sdk.analytics.liveness();ID Verification Analytics
await sdk.analytics.idVerification();User History (Paginated)
await sdk.analytics.history(1, 20);Paginated History
await sdk.analytics.history(1, 20);Get Record by Table + ID (NEW)
await sdk.analytics.getRecordById(3, "uuid123");Dashboard Data (NEW)
await sdk.analytics.getDashboardData();Feedback Methods
Submit Feedback
await sdk.feedback.submit({
mlFileId: "uuid",
feedback: true,
source: "web"
});Get All Feedback
Fetch entire feedback list.
const allFeedback = await sdk.feedback.getAll();
console.log(allFeedback);Get Feedback for ML File by ID
Fetch ML feedback by ML file ID.
const data = await sdk.feedback.byML("mlFileId123");
console.log(data);Get Feedback for a URL Analysis by ID
const feedback = await sdk.feedback.byURL("urlId456");
console.log(feedback);Error Handling
All errors follow a standardized format:
try {
await sdk.ml.uploadFile(file);
} catch (error) {
console.error(error.statusCode);
console.error(error.message);
console.error(error.details);
}Security Notes
To ensure secure operation:
Always use HTTPS
Backend must enable:
cors({
origin: ["https://your-frontend.com"],
credentials: true
});Refresh token must remain HttpOnly
Do NOT store access or refresh tokens in localStorage
Publishing Guide
Step 1: Build SDK
npm run buildStep 2: Version Update
npm version patchStep 3: Publish to npm
npm publish --access publicStep 4: Install in Client
npm install deepfake-sdk-js