kii-aggregator-sdk-test
Version:
KII Aggregator SDK
83 lines (78 loc) • 2.65 kB
TypeScript
// Bundled TypeScript definitions
export interface SdkConfig {
clientId: string;
apiKey: string;
sdkVersion: string;
}
export interface ClientSdkLicense {
clientId: string;
sdk_version: string;
name: string;
status: string;
[key: string]: any;
}
import 'dotenv/config';
import type { SdkConfig, ClientSdkLicense } from './types';
export interface WebhookEvent {
event_type: string;
[key: string]: any;
}
export interface WebhookResponse {
status: 'success' | 'error';
processed?: number;
results?: any[];
error?: string;
message?: string;
}
export declare class KiiAggregatorSdk {
private static readonly API_BASE_URL;
private readonly http;
private validated;
private licenseInfo;
constructor(config: SdkConfig);
validate(): Promise<boolean>;
isValidated(): boolean;
getLicense(): ClientSdkLicense | undefined;
/**
* Factory helper with automatic validation
*/
static createAndValidate(config: SdkConfig): Promise<KiiAggregatorSdk | null>;
/**
* Send events to the aggregator server - handles all webhook requirements
* Supports single events, multiple events, and various event types
*
* @param payload - Can be:
* - Single event object with event_type
* - Array of event objects
* - Event type string (will create event with just event_type)
* - Object with eventType and data properties
* @param additionalData - Optional additional data to merge with the event(s)
* @returns Promise<WebhookResponse>
*
* @example
* // Single event with event_type
* await sdk.sendEvent({ event_type: 'product.fetched', product_id: 'prod_123' });
*
* // Just event type string
* await sdk.sendEvent('product.fetched');
*
* // Event type with additional data
* await sdk.sendEvent('product.fetched', { product_id: 'prod_123' });
*
* // Multiple events
* await sdk.sendEvent([
* { event_type: 'product.fetched', product_id: 'prod_1' },
* { event_type: 'user.login', user_id: 'user_123' }
* ]);
*
* // Using eventType and data structure
* await sdk.sendEvent({ eventType: 'product.fetched', data: { product_id: 'prod_123' } });
*/
sendEvent(payload: WebhookEvent | WebhookEvent[] | string | {
eventType: string;
data?: Record<string, any>;
}, additionalData?: Record<string, any>): Promise<WebhookResponse>;
}
export { KiiAggregatorSdk } from './kii-aggregator';
export type { WebhookEvent, WebhookResponse } from './kii-aggregator';
export * from './types';