LeadConduit Integration Utilities
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
-
TypeError: require is not a function
cause Attempting to use `require()` in an ECMAScript Module (ESM) context without proper transpilation or a Node.js wrapper.fixUse ESM `import { HttpError, test } from 'leadconduit-integration';` instead of `require()`. Ensure your Node.js project is configured for ESM (e.g., `"type": "module"` in `package.json`) or use a bundler that handles CommonJS interoperability. -
TypeError: HttpError is not a constructor
cause Incorrectly importing `HttpError` as a default export, or not accessing it as a named property from the `require()` result.fixUse named import `import { HttpError } from 'leadconduit-integration';` for ESM, or destructure from `require`: `const { HttpError } = require('leadconduit-integration');` for CommonJS. -
TypeError: Cannot read properties of undefined (reading 'parser')
cause Attempting to access `parser` from an `undefined` `test` object, often due to incorrect import or destructuring of the `test` utility.fixEnsure `test` is correctly imported as a named export (`import { test } from 'leadconduit-integration';`) or accessed as a property of the main CommonJS `require` object (`const parser = require('leadconduit-integration').test.parser;`). Then, access `parser` via `test.parser`.
Warnings
- breaking This package is currently in a pre-1.0 release phase (v0.6.3). Breaking changes may be introduced in minor version updates without strictly adhering to semantic versioning for major increments. Always review the release notes carefully when upgrading.
- gotcha The documentation and examples primarily feature CommonJS (`require`) syntax. While the package supports ESM `import` statements, users integrating into pure ESM projects should ensure their build setup correctly handles named exports, especially for nested utilities like `test.parser`.
- gotcha This is a highly specialized utility module designed for LeadConduit integrations. Its concepts (e.g., 'request vars', 'type parser') are specific to the LeadConduit platform. Developers unfamiliar with LeadConduit's integration patterns might find it difficult to use without prior context.
Install
-
npm install leadconduit-integration -
yarn add leadconduit-integration -
pnpm add leadconduit-integration
Imports
- HttpError
import HttpError from 'leadconduit-integration'; const HttpError = require('leadconduit-integration');import { HttpError } from 'leadconduit-integration'; - test.parser
import { parser } from 'leadconduit-integration'; const parser = require('leadconduit-integration').parser;import { test } from 'leadconduit-integration'; const parser = test.parser; - CommonJS named exports
const lcIntegration = require('leadconduit-integration'); // then expect lcIntegration.HttpError to be a class directly without destructuringconst { HttpError, test } = require('leadconduit-integration');
Quickstart
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));