Framework-agnostic Clickwrap SDK for JavaScript/TypeScript projects
npm install @bharath-ravi/clickwrap-sdkA framework-agnostic TypeScript SDK for implementing SpotDraft Clickwrap functionality in any JavaScript/TypeScript project.
- 🚀 Framework Agnostic: Works with React, Vue, Angular, Svelte, or plain JavaScript
- 📦 TypeScript Support: Full TypeScript definitions included
- 🌐 Universal: Supports both ESM and CommonJS
- 🔧 Easy Integration: Simple API for quick implementation
- 📱 Browser Ready: Works in all modern browsers
``bash`
npm install @spotdraft/clickwrap-client-sdk
`bashBuild the complete package (CJS, ESM, types, and CDN version)
nx run clickwrap-client-sdk:build
$3
`bash
Show publish instructions
nx run clickwrap-client-sdk:publishPublish with specific version and tag
nx run clickwrap-client-sdk:publish-version --args="1.0.0 latest"Dry run (recommended first)
node tools/scripts/publish.mjs clickwrap-client-sdk 1.0.0 latest --dry-runActual publish
node tools/scripts/publish.mjs clickwrap-client-sdk 1.0.0 latest
`Usage
$3
`typescript
import { SdClickthrough } from "@spotdraft/clickwrap-client-sdk";// Initialize the SDK
const clickthrough = new SdClickthrough({
clickwrapId: "your-clickwrap-id",
baseUrl: "https://api.spotdraft.com",
hostLocationDomId: "clickwrap-container"
});
// Initialize and render the clickwrap
await clickthrough.init();
// Listen for acceptance changes
clickthrough.on("ACCEPTANCE_TOGGLED", isAccepted => {
console.log("Acceptance status:", isAccepted);
});
// Submit when user accepts
if (clickthrough.isAccepted()) {
await clickthrough.submit({
user_identifier: "user@example.com"
// ... other metadata
});
}
`$3
`tsx
import React, { useEffect, useRef, useState } from "react";
import { SdClickthrough } from "@spotdraft/clickwrap-client-sdk";const ClickwrapComponent: React.FC = () => {
const containerRef = useRef(null);
const [clickthrough, setClickthrough] = useState(null);
const [isAccepted, setIsAccepted] = useState(false);
useEffect(() => {
const sdk = new SdClickthrough({
clickwrapId: "your-clickwrap-id",
baseUrl: "https://api.spotdraft.com",
hostLocationDomId: "clickwrap-container"
});
sdk.on("ACCEPTANCE_TOGGLED", setIsAccepted);
sdk.init();
setClickthrough(sdk);
return () => {
// Cleanup if needed
};
}, []);
const handleSubmit = async () => {
if (clickthrough && isAccepted) {
await clickthrough.submit({
user_identifier: "user@example.com"
});
}
};
return (
);
};
`$3
`vue
`API Reference
$3
`typescript
new SdClickthrough(context: SdClickthroughContext)
`#### SdClickthroughContext
-
clickwrapId: string - Your clickwrap ID
- baseUrl: string - API base URL
- hostLocationDomId: string - DOM element ID where clickwrap will be rendered$3
####
init(): PromiseInitializes and renders the clickwrap in the specified DOM element.
####
isAccepted(): booleanReturns whether all required agreements have been accepted.
####
submit(payload: SdClickwrapSubmitPayload): PromiseSubmits the clickwrap acceptance.
####
on(event: SdClickthroughEvents, callback: Function): voidRegisters an event listener.
####
isReacceptanceRequired(userIdentifier: string): PromiseChecks if reacceptance is required for a user.
$3
-
ACCEPTANCE_TOGGLED: Fired when acceptance status changesCDN Usage (Browser)
If you prefer to use the SDK via CDN without npm:
`html
`TypeScript Support
This package includes full TypeScript definitions. All types are exported:
`typescript
import { SdClickthrough, SdClickthroughContext, SdClickthroughEvents, SdClickwrapSubmitPayload } from "@spotdraft/clickwrap-client-sdk";
``- Chrome (latest)
- Firefox (latest)
- Safari (latest)
- Edge (latest)
MIT
For support, please contact support@spotdraft.com or visit our documentation.