UNPKG

@gnosticdev/highlevel-sdk

Version:
72 lines (69 loc) 2.1 kB
type webhooks = Record<string, never>; type components = { schemas: never; responses: never; parameters: never; requestBodies: never; headers: never; pathItems: never; }; /** * Type helper for extracting webhook payload types */ type WebhookPayload<T extends keyof webhooks> = components['schemas'][T]; /** * Type helper for webhook handlers */ type WebhookHandler<T extends keyof webhooks> = (payload: WebhookPayload<T>) => Promise<void> | void; declare class WebhooksClient { private handlers; /** * Register a handler for a specific webhook event * * @example * ```ts * const webhooks = new WebhooksClient() * * webhooks.on('ContactCreate', async (payload) => { * // payload is fully typed as ContactCreate schema * const { firstName, lastName, email } = payload * await db.contacts.create({ firstName, lastName, email }) * }) * ``` */ on<T extends keyof webhooks>(event: T, handler: WebhookHandler<T>): this; /** * Validate and handle an incoming webhook payload * * @example * ```ts * app.post('/webhooks/:event', async (ctx) => { * try { * await webhooks.handle(ctx.params.event, ctx.request.body) * return ctx.status(200).end() * } catch (error) { * return ctx.status(400).json({ error: error.message }) * } * }) * ``` */ handle<T extends keyof webhooks>(event: T, payload: WebhookPayload<T>): Promise<void>; /** * Get the TypeScript type for a webhook payload * Useful for type checking in your IDE * * @example * ```ts * const webhooks = new WebhooksClient() * * const contactType = webhooks.type<'ContactCreate'>() * // contactType is fully typed as ContactCreate schema * ``` */ type<T extends keyof webhooks>(): WebhookPayload<T>; } /** * Create a new webhooks client for handling HighLevel webhook events */ declare function createWebhooksClient(): WebhooksClient; export { WebhooksClient, createWebhooksClient };