@guardianstack/guardian-js
v0.2.5
Published
SDK to load Fraud Detection Agent via CDN and initialize it
Readme
Guardian JS SDK (@guardianstack/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 @guardianstack/guardian-js
# or
yarn add @guardianstack/guardian-js
# or
pnpm add @guardianstack/guardian-jsQuick start (npm, ESM)
import { loadAgent } from "@guardianstack/guardian-js";
async function main() {
// Initialize with your site key
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, debug?: boolean, collectionTimeoutMs?: number, onError?: (error: Error) => void }) => Promise<Agent>- Initializes the browser Agent.
collectionTimeoutMslimits how long the agent waits to collect signals before rejecting;onErroris called on errors (including timeouts).
- 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
