LeadConduit Integration Utilities

0.6.3 · active · verified Tue Apr 21

The `leadconduit-integration` package provides a specialized set of Node.js utility functions designed to streamline the development of integrations with the LeadConduit platform. Currently at version 0.6.3, it offers core functionalities such as the `HttpError` class, which allows developers to construct immediate HTTP responses with specific status codes, headers, and body content for inbound integrations, effectively short-circuiting request processing. Additionally, it includes a `test.parser` helper, invaluable for simulating and parsing richly typed LeadConduit data during unit testing, transforming raw input objects into structured, validated data based on predefined request variable configurations. Given its highly specialized niche within the LeadConduit ecosystem, its release cadence is typically driven by internal development needs rather than a strict public schedule. Its primary differentiator is its direct utility for simplifying common integration patterns and data handling specific to the LeadConduit platform, abstracting away much of the boilerplate associated with bespoke integration development for that environment.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to handle immediate HTTP responses using `HttpError` in an inbound integration, and how to use `test.parser` to simulate and parse richly typed LeadConduit data for unit testing purposes.

import { HttpError, test } from 'leadconduit-integration';

// Example 1: Handling immediate HTTP responses in an inbound integration
function handleIncomingRequest(req: { method?: string }): { status: number; body: string; headers?: Record<string, string> } {
  const method = req.method?.toLowerCase();
  if (method !== 'get' && method !== 'post') {
    throw new HttpError(
      415,
      { 'Content-Type': 'text/plain', Allow: 'GET, POST' },
      `The ${method?.toUpperCase() || 'UNKNOWN'} method is not allowed`
    );
  }
  console.log(`Processing ${method?.toUpperCase()} request...`);
  // ... actual request processing logic ...
  return { status: 200, body: 'Request handled successfully!' };
}

try {
  handleIncomingRequest({ method: 'PUT' }); // Simulate an unsupported method
} catch (e) {
  if (e instanceof HttpError) {
    console.log(`\nCaught HttpError: Status ${e.status}, Body: '${e.body}'`);
  } else {
    console.error(`\nAn unexpected error occurred: ${e instanceof Error ? e.message : String(e)}`);
  }
}

// Example 2: Using test.parser to simulate and parse richly typed data for tests
const requestVariables = [
  { name: 'zip_code', type: 'postal_code' },
  { name: 'contact_phone', type: 'phone' },
  { name: 'age_years', type: 'integer' },
  { name: 'enrollment_date', type: 'date' }
];

const parseLeadData = test.parser(requestVariables);

const rawLeadInput = {
  first_name: 'Alice',
  zip_code: '90210',
  contact_phone: '1-800-555-0199',
  age_years: '25',
  enrollment_date: '2023-11-15'
};

const parsedLeadData = parseLeadData(rawLeadInput);
console.log('\nParsed Lead Data for Testing:');
console.log(JSON.stringify(parsedLeadData, null, 2));

view raw JSON →