@campaign-lite/landing-page-common
v1.0.1
Published
Common modules for landing pages
Readme
Landing Page Common
This package provides a library of common modules and utilities designed to be shared and imported across various landing page projects.
Installation
You can install this package into your other local projects or use it as a dependency once published.
npm install @campaign-lite/landing-page-commonFeatures
- TypeScript Native: Built with TypeScript for full type safety.
- ESM Support: Exports modern ES modules out of the box.
- CampaignLite Client: Provides a client for interacting with the Campaign Lite API.
Usage
CampaignLite Client
The CampaignLite client is a wrapper for making authenticated requests to the Campaign Lite backend. It supports pagination, sorting, filtering, and bulk operations.
Initialization
import { CampaignLite } from "landing-page-common";
// Initialize with base URL
const client = new CampaignLite("https://api.campaignlite.app");
// Set the client name
client.client("qualfon");
// Set the endpoint path
client.endpoint("leads");Authentication
You can authenticate the client using either Basic Auth or an API Key, depending on how the Campaign Lite endpoint is configured.
Basic Auth:
client.setBasicAuth("your-username", "your-password");API Key:
client.setApiKey("your-api-key");Fetching Data (GET)
The fetch method allows you to retrieve data with optional pagination, sorting, and filtering parameters.
const response = await client.fetch({
page: 0,
size: 50,
sortBy: "createdAt",
sortDirection: "desc",
startAtField: "status",
startAt: "active",
});
const data = await response.json();
console.log(data);Pushing Data (POST)
The push method allows you to submit new records.
Single Record:
const response = await client.push({
email: "[email protected]",
name: "John Doe",
});Bulk Insert:
const records = [
{ email: "[email protected]" },
{ email: "[email protected]" },
];
// Set the second parameter to true to enable the /bulk endpoint
const bulkResponse = await client.push(records, true);Available Scripts
npm run build: Cleans thedistdirectory and compiles the TypeScript code.npm run clean: Removes thedistdirectory.npm test: Runs the Vitest test suite.npm run test:coverage: Runs the test suite and generates a coverage report.npm run lint: Lints the codebase using ESLint.npm run lint:fix: Automatically fixes linting errors where possible.
License
ISC
