@latchd/sdk
v0.3.6
Published
Latchd JavaScript SDK for consent capture and cookie management
Maintainers
Readme
@latchd/sdk
JavaScript SDK for Latchd consent capture, cookie preferences, legal document rendering, and DSAR flows.
Install
npm install @latchd/sdkQuick Start
import { init, fetchDocument, captureConsent } from "@latchd/sdk";
const client = init({
apiKey: "latchd_pk_live_...",
});
const document = await fetchDocument(client, "privacy-policy");
await captureConsent(client, {
documentId: document.id,
documentVersion: document.versionNumber,
userId: "user_123",
type: "clickwrap",
contentHash: "sha256-of-rendered-document",
});Cookie Consent
import {
createCookieConsentEngine,
renderCookieBanner,
} from "@latchd/sdk";
const consent = createCookieConsentEngine({
categories: {
essential: {
required: true,
label: "Essential",
description: "Required for core site functionality.",
},
analytics: {
label: "Analytics",
description: "Helps us understand site usage.",
},
marketing: {
label: "Marketing",
description: "Used for ads and campaign measurement.",
},
functional: {
label: "Functional",
description: "Stores convenience preferences.",
},
},
storage: { cookieName: "latchd_cookie_prefs" },
sync: { client, userId: "user_123" },
});
await consent.initialize();
renderCookieBanner(client, "user_123");Included APIs
LatchdClientfor direct authenticated API accessfetchDocument()for retrieving published legal documentscaptureConsent()andcheckConsent()for clickwrap and consent statesaveCookiePreference()andgetCookiePreferences()for cookie settingscreateCookieConsentEngine()for category-based cookie consent staterenderCookieBanner()for a lightweight cookie consent UI with manage-preferences controlssubmitDsarRequest()andverifyDsarRequest()for DSAR flows
Configuration
import { init } from "@latchd/sdk";
const client = init({
apiKey: "latchd_pk_live_...",
baseUrl: "https://api.latchd.com",
});apiKey is required. baseUrl is optional and defaults to the hosted Latchd API.
Package Notes
- Zero-dependency package runtime
- Published with provenance from GitHub Actions
- React integrations are available separately in
@latchd/react
More public documentation is coming soon.
