API Reference

Complete API reference for the Kulu SDK

API Reference

Complete reference for all Kulu SDK methods and properties.

Constructor

Create a new Kulu instance with your SDK key and optional configuration.

new Kulu(sdkKey, options)

Parameters:

  • sdkKey (string, required) - Your unique SDK key from the Kulu dashboard
  • options (object, optional) - Configuration options
    • debug (boolean) - Enable debug mode to show reset button for testing (default: false)

Example:

const kulu = new Kulu('YOUR_SDK_KEY', { 
  debug: true  // Shows reset button for testing
});

Methods

init(userId, description, end_user_type_id)

Initialize the SDK for a specific user. This must be called after resources are loaded.

Parameters:

  • userId (string, required) - Unique identifier for the user
  • description (string, optional) - Optional description for the user
  • end_user_type_id (string, optional) - User type identifier for initializing different workflows based on user roles (e.g., 'admin', 'analyst'). Defaults to 'default' if not provided. Note: User types must be created in the Kulu portal before use.

Returns: Promise<void>

Example:

// Basic initialization
await kulu.init('user-123');

// With end user type (must be created in portal first)
await kulu.init('user-123', 'This is an optional description of user-123', 'default');

destroy()

Clean up and destroy the Kulu instance. Call this when the user logs out or when you no longer need the SDK.

Returns: void

Example:

kulu.destroy();

Properties

version

The current version of the Kulu SDK.

Type: string

Example:

console.log('SDK Version:', kulu.version);

resourcesLoaded

Indicates whether the SDK resources have been loaded and are ready to use.

Type: boolean

Example:

while (!kulu.resourcesLoaded) {
  await new Promise(resolve => setTimeout(resolve, 100));
}

userInitialized

Indicates whether a user has been initialized with the init() method.

Type: boolean

Example:

if (kulu.userInitialized) {
  console.log('User is already initialized');
}

isValidSdkKey

Indicates whether the provided SDK key is valid.

Type: boolean

Example:

if (!kulu.isValidSdkKey) {
  console.error('Invalid SDK key');
}

loadedWorkflows

Array of available workflows that have been loaded for the current user.

Type: Array

Example:

console.log('Available workflows:', kulu.loadedWorkflows);

Complete Example

import { Kulu } from '@kulu/sdk';

// Initialize SDK
const initKulu = async (userId: string, description?: string, endUserTypeId?: string) => {
  try {
    // Create instance
    const kulu = new Kulu('YOUR_SDK_KEY', { 
      debug: true  // Enable debug mode for testing
    });
    
    // Wait for resources to load
    while (!kulu.resourcesLoaded) {
      await new Promise(resolve => setTimeout(resolve, 100));
    }
    
    // Verify SDK key is valid
    if (!kulu.isValidSdkKey) {
      throw new Error('Invalid SDK key');
    }
    
    // Initialize user (user type must be created in portal first)
    await kulu.init(userId, description, endUserTypeId);
    
    // Check initialization status
    console.log('SDK Version:', kulu.version);
    console.log('User Initialized:', kulu.userInitialized);
    console.log('Available Workflows:', kulu.loadedWorkflows);
    
    return kulu;
  } catch (error) {
    console.error('[Kulu] Initialization failed:', error);
    throw error;
  }
};

// Usage - Basic
const kuluInstance = await initKulu('user-123', 'John Doe');

// Usage - With user type
const adminInstance = await initKulu('admin-456', 'Admin User', 'admin');

// Cleanup on logout
const handleLogout = () => {
  kuluInstance.destroy();
  // Your logout logic here
};

Next Steps