UNPKG

sendrly

Version:

Official Sendrly TypeScript/JavaScript SDK - Simple, type-safe email automation for developers

111 lines (110 loc) 3.08 kB
import { type SendrlyConfig, type ContactResponse, type EventResponse, type EdgeFunctionPayload } from './types'; export type * from './types'; /** * Main Sendrly SDK class for tracking events and managing contacts * @example * // Basic usage - just API key * const sendrly = new Sendrly('your_api_key') * * // Send an event with minimal config * await sendrly.sendEvent({ * contact: { * email: 'user@example.com' * }, * event: { * name: 'signup.completed' * } * }) * * // Advanced usage with full config * const sendrly = new Sendrly({ * apiKey: 'your_api_key', * debug: true, * timeout: 5000 * }) */ export declare class Sendrly { #private; constructor(config: string | SendrlyConfig); /** * Send an event for a contact * @example * // Minimal usage * await sendrly.sendEvent({ * contact: { * email: 'user@example.com' * }, * event: { * name: 'signup.completed' * } * }) * * // Full usage with all options * await sendrly.sendEvent({ * contact: { * email: 'sarah@startup.com', * marketing_opt_out: false, * properties: { * name: 'Sarah', * company: 'Startup Inc' * } * }, * event: { * name: 'user.welcome', * properties: { * source: 'signup', * referral: 'google' * } * } * }) */ sendEvent(payload: EdgeFunctionPayload): Promise<void>; /** * Get a contact by email address * @example * // Get contact details * const contact = await sendrly.getContact('sarah@startup.com') * console.log(contact.properties.name) // 'Sarah' * * // Handle non-existent contact * try { * const contact = await sendrly.getContact('unknown@email.com') * } catch (error) { * if (error.code === 'NOT_FOUND') { * console.log('Contact does not exist') * } * } */ getContact(email: string): Promise<ContactResponse>; /** * List all events with a specific name * @example * // List all signup events * const signups = await sendrly.listEvents('user.signup') * console.log(signups[0].event_properties.source) * * // Process completed orders * const orders = await sendrly.listEvents('order.completed') * const totalRevenue = orders.reduce((sum, order) => * sum + order.event_properties.amount, 0 * ) */ listEvents(eventName: string): Promise<EventResponse[]>; /** * Delete a contact and all associated data * @example * // Delete a contact * await sendrly.deleteContact('sarah@startup.com') * * // Handle non-existent contact * try { * await sendrly.deleteContact('unknown@email.com') * } catch (error) { * if (error.code === 'NOT_FOUND') { * console.log('Contact already deleted') * } * } */ deleteContact(email: string): Promise<void>; } export default Sendrly;