npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

agentic-suite-event-sdk

v1.0.7

Published

A wrapper around confluent kafka to send the messages securely.

Readme

Agentic Suite Event SDK

A secure and efficient wrapper around Confluent Kafka for event emission with built-in data validation.

Features

  • Singleton pattern for consistent event emission
    • Ensures only one Kafka connection per application
    • Prevents resource duplication
    • Maintains consistent state across your application
  • Schema validation using AJV
  • Automatic Kafka connection management
  • Built-in GZIP message compression via KafkaJS
  • Configurable retry settings:
    • maxRetryTime: Maximum time to retry operations
    • initialRetryTime: Initial delay between retries
    • retries: Number of retry attempts
  • Comprehensive logging
  • Strict configuration validation

Installation

npm install agentic-suite-event-sdk

Singleton Pattern Explanation

The SDK uses the Singleton pattern to ensure that only one instance of the event emitter exists throughout your application. This is important because:

  1. Connection Management: Maintains a single Kafka connection instead of creating multiple connections
  2. Resource Efficiency: Prevents memory leaks and resource wastage
  3. State Consistency: Ensures all events are emitted through the same connection

Example of how the Singleton pattern works:

// First initialization - creates the instance
const emitter1 = new AnalyticsEventEmitter({
  clientId: 'your-client-id',
  brokers: ['kafka-broker:9092'],
  retryConfig: {
    maxRetryTime: 30000,
    initialRetryTime: 1000,
    retries: 5
  }
}, Logger); //  pass motifer require('motifer').Logger as a param.

// Second initialization - returns the existing instance
const emitter2 = new AnalyticsEventEmitter({
  clientId: 'different-client-id',  // This will be ignored
  brokers: ['different-broker:9092'], // This will be ignored
  retryConfig: {
    maxRetryTime: 20000,  // This will be ignored
    initialRetryTime: 500,
    retries: 3
  }
}, Logger); // pass motifer require('motifer').Logger as a param.

// Both variables reference the same instance
console.log(emitter1 === emitter2); // true

Important Notes:

  • The configuration provided in subsequent initializations is ignored
  • Always store the initial configuration carefully as it will be used throughout the application's lifecycle
  • The same instance is shared across different modules that import the SDK

Configuration

The SDK requires a configuration object that is strictly validated to ensure proper initialization. Here's the detailed configuration structure:

const config = {
  // Required: Client identifier for Kafka (1-255 characters)
  clientId: 'your-client-id',

  // Required: Array of Kafka brokers in host:port format
  // Must have at least one broker
  brokers: [
    'kafka-broker1:9092',
    'kafka-broker2:9092'
  ],

  // Required: Retry configuration for Kafka operations
  retryConfig: {
    // Minimum: 1000ms (1 second)
    maxRetryTime: 30000,    // Maximum retry time in milliseconds
    
    // Minimum: 100ms
    initialRetryTime: 1000, // Initial retry time in milliseconds
    
    // Must be between 1 and 10
    retries: 5             // Number of retries
  }
};

Configuration Validation Rules

The SDK performs strict validation of the configuration object with the following rules:

  1. clientId:

    • Required
    • Must be a string
    • Length: 1-255 characters
  2. brokers:

    • Required
    • Must be an array with at least one broker
    • Each broker must be in the format hostname:port
    • Example: ['localhost:9092']
  3. retryConfig:

    • Required
    • Must include all three retry parameters
    • maxRetryTime:
      • Minimum value: 1000ms (1 second)
    • initialRetryTime:
      • Minimum value: 100ms
    • retries:
      • Must be between 1 and 10

If any of these validation rules are violated, the SDK will throw an error with a detailed message indicating which part of the configuration is invalid.

Example with validation error:

try {
  const emitter = new AnalyticsEventEmitter({
    clientId: "test",
    brokers: ["invalid-broker-format"],  // Missing port number
    retryConfig: {
      maxRetryTime: 500,  // Too low, minimum is 1000ms
      initialRetryTime: 200,
      retries: 3
    }
  }, Logger); //  pass motifer require('motifer').Logger as a param.
} catch (error) {
  console.error(error.message);
  // Output: "Invalid configuration: /brokers/0: must match pattern "^[^:]+:[0-9]+$"; 
  //          /retryConfig/maxRetryTime: must be >= 1000"
}

Usage

const AnalyticsEventEmitter = require('agentic-suite-event-sdk');

// Initialize the emitter
const emitter = new AnalyticsEventEmitter({
  clientId: 'your-client-id',
  brokers: ['kafka-broker-1:9092'],
  retryConfig: {
    maxRetryTime: 30000,
    initialRetryTime: 1000,
    retries: 5
  }
}, Logger); //  pass motifer require('motifer').Logger as a param.

// Emit an event
const eventData = {
  analyticsId: 'analytics_id',  // Required string (1-50 chars)
  tenantId: 'uuid-v4-string',     // Required UUID
  uid: 'uuid-v4-string',          // Required UUID
  entity: 'user',                 // Required string (1-50 chars)
  eventName: 'login',             // Required string (1-50 chars)
  properties: {                   // Required object
    // Any valid JSON object
    source: 'web',
    browser: 'chrome'
  }
};

try {
  await emitter.emit('your-topic-name', eventData);
  console.log('Event emitted successfully');
} catch (error) {
  console.error('Error emitting event:', error);
}

Event Schema

All events must conform to the following schema:

{
  ts: string,              // ISO 8601 date-time (auto-generated)
  analyticsId: string,     // Length: 1-50 characters
  tenantId: string,        // UUID v4
  uid: string,             // UUID v4
  entity: string,          // Length: 1-50 characters
  eventName: string,       // Length: 1-50 characters
  properties: object       // Any valid JSON object
}

Error Handling

The SDK throws errors in the following cases:

  • Invalid configuration parameters
  • Schema validation failures
  • Kafka connection issues
  • Message publishing failures

All errors include detailed error messages and are properly logged using the Motifer logger.

Dependencies

  • @confluentinc/kafka-javascript: 1.3.1
  • ajv: 8.17.1
  • ajv-formats: 3.0.1
  • motifer: 1.2.5
  • uuid: 11.0.5

License

UNLICENSED - All rights reserved by SearchUnify.