Skip to content

API Reference

The TaskOn Embed SDK provides a comprehensive API to integrate TaskOn into your application with ease.

Core Class

TaskOnEmbed

The main embed component class responsible for managing the iframe and user interactions.

typescript
import { TaskOnEmbed } from "@taskon/embed";

const embed = new TaskOnEmbed({
  baseUrl: "https://yourdomain.com",
  containerElement: "#taskon-container",
});

// Initialize
await embed.init();

// Login
await embed.login({
  type: "Email",
  account: "user@example.com",
  signature: serverSignature,
  timestamp: Date.now(),
});

// Check authorization status
const isAuthorized = await embed.isAuthorized("Email", "user@example.com");

// Logout with options
await embed.logout(); // Keep auth cache (default and recommend)
// await embed.logout({ clearAuth: true }); // Clear auth cache

// Clean up
embed.destroy();

View detailed docs →

Analytics Function

trackVisit()

Optional conversion analytics tracking (only use if needed).

typescript
import { trackVisit } from "@taskon/embed";

// Only if you need TaskOn conversion rate analysis
await trackVisit(); // For anonymous users
// or
await trackVisit("Email", "user@example.com"); // For known users

View Analytics API →

Node.js Utilities

signMessage()

Server-side signature generation for authentication.

typescript
import { signMessage } from "@taskon/embed/node";

const { signature, timestamp } = signMessage(
  clientId,
  "Email", // or "evm" for wallet addresses
  account,
  privateKey
);

View Server Utilities →

Type Definitions

The SDK ships with complete TypeScript type definitions:

typescript
import type {
  TaskOnEmbedConfig,
  LoginParams,
  AuthType,
  AuthUser,
  TaskOnEmbedEvents,
} from "@taskon/embed";

View Type Definitions →

Event Handling

The SDK extends EventEmitter for iframe communication:

typescript
// Listen for authentication requirements
embed.on("loginRequired", () => {
  console.log("User authentication required");
  // Trigger your login flow
});

// Listen for route changes
embed.on("routeChanged", fullPath => {
  console.log("Route changed to:", fullPath);
  // Optional: Sync with external URL
});

Quick Navigation

FeatureAPIDescription
Initializenew TaskOnEmbed(config)Create embed instance
embed.init()Initialize iframe
Authembed.login(params)User authentication
embed.logout(options?)User logout with auth cache control
embed.isAuthorized(type, account)Check authorization status
Navigationembed.setRoute(path)Set internal route
embed.currentRouteGet current route
Managementembed.updateSize(width, height)Update iframe size
embed.destroy()Clean up resources
Eventsembed.on('loginRequired', handler)Listen for auth requirements
embed.on('routeChanged', handler)Listen for route changes
AnalyticstrackVisit(type?, account?)Conversion tracking (optional)
ServersignMessage(id, type, account, key)Generate authentication signature

Complete Example

typescript
import { TaskOnEmbed, trackVisit } from "@taskon/embed";

// Optional: Track page visit for conversion analytics
// await trackVisit(); // For anonymous users

// Create instance
const embed = new TaskOnEmbed({
  baseUrl: "https://yourdomain.com",
  containerElement: "#taskon-container",
});

// Initialize
await embed.init();

// Set up event listeners
embed.on("loginRequired", async () => {
  // Trigger your login flow when TaskOn requires authentication
  console.log("Authentication required");
});

embed.on("routeChanged", fullPath => {
  console.log("Route changed to:", fullPath);
  // Optional: Sync with your external URL
});

// Login when user authenticates in your system
const email = "user@example.com";
const isAuthorized = await embed.isAuthorized("Email", email);

if (!isAuthorized) {
  // Get signature from your server
  const { signature, timestamp } = await getServerSignature(email);

  await embed.login({
    type: "Email",
    account: email,
    signature,
    timestamp,
  });
} else {
  // Already authorized, login without signature
  await embed.login({
    type: "Email",
    account: email,
  });
}

// Logout when needed
// await embed.logout();

// Clean up when component unmounts
// embed.destroy();

Learn More

Released under the MIT License.