@mugshotlabs/guardian-js
v0.2.3
Published
SDK to load Fraud Detection Agent via CDN and initialize it
Downloads
29
Readme
Guardian JS SDK (@mugshotlabs/guardian-js)
Client-side SDK to initialize the Guardian Fraud Detection Agent and create an identification event from the browser. It returns a request id you can send to your backend to fetch the full event and decide whether to pass or apply additional checks.
Installation
npm install @mugshotlabs/guardian-js
# or
yarn add @mugshotlabs/guardian-js
# or
pnpm add @mugshotlabs/guardian-jsQuick start (npm, ESM)
import { loadAgent } from "@mugshotlabs/guardian-js";
async function main() {
// Initialize with your site key (debug is optional and can be omitted)
const api = await loadAgent({ siteKey: "YOUR_SITE_KEY" });
// Create an identification event and get its request id
const response = await api.get();
const body = response && (await response.json());
const requestId = body?.requestId;
// Send requestId to your backend to retrieve the full event
// and decide whether to pass or perform additional checks
}
main();- Backend SDK: fetch the event by
requestIdand implement your decisioning with the server SDK: Guardian JS Server SDK on npm
API (client)
loadAgent({ siteKey: string }) => Promise<Agent>- Initializes the browser Agent.
debugis optional and not required.
- Initializes the browser Agent.
Agent.get() => Promise<Response | undefined>- Creates an identification event and returns a response containing a
requestId. Send thisrequestIdto your backend to fetch the event and decide whether to pass or add additional checks.
- Creates an identification event and returns a response containing a
License
MIT © Mugshot Labs
