lf-sdk
v1.0.1
Published
TypeScript SDK for LightFunnels GraphQL API
Maintainers
Readme
LightFunnels SDK
TypeScript SDK for the LightFunnels GraphQL API. Provides type-safe methods for managing customers, products, orders, funnels, stores, and more.
Installation
npm install lf-sdk
# or
pnpm add lf-sdk
# or
yarn add lf-sdkQuick Start
import { LightFunnelsSDK } from 'lf-sdk';
const sdk = new LightFunnelsSDK();
// Authenticate with your user token
sdk.authenticate('your-user-token');
// Fetch customers
const customers = await sdk.getCustomers({ first: 10 });
console.log(customers.edges.map(e => e.node.email));Authentication
Using a User Token
const sdk = new LightFunnelsSDK();
sdk.authenticate('your-user-token');OAuth Flow
import { LightFunnelsSDK, getAuthorizationUrl, exchangeCodeForToken } from 'lf-sdk';
// 1. Generate authorization URL
const authUrl = getAuthorizationUrl({
clientId: 'your-client-id',
redirectUri: 'https://yourapp.com/callback',
scopes: ['funnels', 'products', 'orders', 'customers'],
});
// 2. User authorizes and is redirected back with a code
// 3. Exchange code for token
const tokenResponse = await exchangeCodeForToken('auth-code', {
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
});
// 4. Use the token
const sdk = new LightFunnelsSDK();
sdk.authenticate(tokenResponse.access_token);Configuration
const sdk = new LightFunnelsSDK({
apiUrl: 'https://services.lightfunnels.com/v2', // Custom API URL
timeout: 30000, // Request timeout in ms (default: 30000)
retries: 3, // Number of retries for 5xx errors (default: 3)
});Available Methods
Customers
getCustomers(params?)- List customers with pagination and filtersgetCustomer(id)- Get a single customercreateCustomer(customer)- Create a new customerupdateCustomer(id, customer)- Update a customer
Products
getProducts(params?)- List productsgetProduct(id)- Get a single productcreateProduct(product)- Create a new productupdateProduct(id, product)- Update a productdeleteProducts(ids)- Delete productsduplicateProduct(id)- Duplicate a product
Orders
getOrders(params?)- List ordersgetOrder(id)- Get a single orderupdateOrder(id, order)- Update an orderrefundOrder(orderId, paymentId, amount, reason?)- Refund an orderfulfillOrderItems(orderId, items, options?)- Fulfill order itemsupdateTracking(orderId, itemId, tracking)- Update tracking info
Funnels
getFunnels(params?)- List funnelsgetFunnel(id)- Get a single funnelcreateFunnel(funnel)- Create a new funnelupdateFunnel(id, funnel)- Update a funneldeleteFunnels(ids)- Delete funnels
Stores
getStores(params?)- List storesgetStore(id)- Get a single storecreateStore(store)- Create a new storeupdateStore(id, store)- Update a storedeleteStores(ids)- Delete stores
Collections
getCollections(params?)- List collectionsgetCollection(id)- Get a single collectioncreateCollection(collection)- Create a new collectionupdateCollection(id, collection)- Update a collectiondeleteCollections(ids)- Delete collections
Discounts
getDiscounts(params?)- List discountsgetDiscount(id)- Get a single discountcreateDiscount(discount)- Create a new discountupdateDiscount(id, discount)- Update a discountdeleteDiscounts(ids)- Delete discounts
Reviews
getReviews(params?)- List reviewsgetReview(id)- Get a single reviewcreateReview(review)- Create a new reviewupdateReview(id, review)- Update a reviewdeleteReviews(ids)- Delete reviews
Analytics
getAnalytics(params)- Get analytics datagetLiveAnalytics(params?)- Get live analytics
Additional Resources
- Checkouts:
getCheckouts,getCheckout - Tags:
getTags,createTag,deleteTags - Leads:
getLeads - Segments:
getSegments,getSegment,createSegment,updateSegment,deleteSegments - Webhooks:
getWebhooks,getWebhook,createWebhook,updateWebhook,deleteWebhooks - Webhook Events:
getWebhookEvents,getWebhookEvent - Domains:
getDomains,getDomain,createDomain,deleteDomains,checkDomainAvailability,searchDomains - Shipping:
getShippingGroups,getShippingGroup,createShippingGroup,updateShippingGroup,deleteShippingGroups,getShippingLocations,createShippingLocation,updateShippingLocation,deleteShippingLocations - Cloaks:
getCloaks,getCloak,createCloak,updateCloak,deleteCloaks - Media:
getImages,deleteImages,getFiles,deleteFiles,getVideos,deleteVideos,getAudios,deleteAudios - Price Bundles:
getPriceBundles,getPriceBundle,createPriceBundle,updatePriceBundle,deletePriceBundles - Payment Gateways:
getPaymentGateways,getPaymentGateway,createPaymentGateway,updatePaymentGateway,deletePaymentGateways - Account:
getAccount,updateAccount
Pagination
All list methods support pagination:
// Basic pagination
const page1 = await sdk.getCustomers({ first: 20 });
const page2 = await sdk.getCustomers({ first: 20, after: page1.pageInfo.endCursor });
// Iterate through all items
for await (const customer of sdk.paginate(
(params) => sdk.getCustomers(params),
{ first: 50 }
)) {
console.log(customer.email);
}Filtering and Sorting
// Filter customers
const customers = await sdk.getCustomers({
search: 'john',
email: '[email protected]',
tags: ['vip', 'premium'],
orderBy: 'created_at',
orderDir: 'desc',
});
// Filter orders
const orders = await sdk.getOrders({
financial_status: 'paid',
fulfillment_status: 'unfulfilled',
funnel_id: 'funnel-id',
});Custom Queries
For advanced use cases, execute raw GraphQL queries:
const result = await sdk.query<{ customField: string }>(`
query CustomQuery($id: ID!) {
node(id: $id) {
... on Customer {
id
email
customField
}
}
}
`, { id: 'customer-id' });Error Handling
import { LightFunnelsError } from 'lf-sdk';
try {
await sdk.getCustomer('invalid-id');
} catch (error) {
if (LightFunnelsError.isLightFunnelsError(error)) {
console.log('Status:', error.statusCode);
console.log('Message:', error.message);
console.log('Response:', error.response);
}
}TypeScript Support
The SDK is fully typed. All types are exported:
import type {
Customer,
Product,
Order,
Funnel,
Store,
Connection,
GetCustomersParams,
InputCustomer,
// ... and many more
} from 'lf-sdk';License
MIT
