=== UPDATES === - fieldedge: Added apps, tools, main server entry, full rebuild - lightspeed: Added complete src/ directory with tools + apps - squarespace: Full rebuild — new apps, clients, tools, types modules - toast: Full rebuild — api-client, apps, tools, types - touchbistro: Full rebuild — api-client, tools, types, gitignore - servicetitan: Added 4 React UI apps (call-tracking, lead-source-analytics, performance-metrics, schedule-calendar) All servers restructured from single-file to modular architecture.
129 lines
5.6 KiB
TypeScript
129 lines
5.6 KiB
TypeScript
/**
|
|
* Customer Management Tools
|
|
*/
|
|
|
|
import { z } from 'zod';
|
|
import type { LightspeedClient } from '../clients/lightspeed.js';
|
|
|
|
export function registerCustomerTools(client: LightspeedClient) {
|
|
return [
|
|
{
|
|
name: 'lightspeed_list_customers',
|
|
description: 'List all customers in Lightspeed. Supports pagination and email filtering.',
|
|
inputSchema: z.object({
|
|
limit: z.number().optional().describe('Number of customers to return (default 100)'),
|
|
offset: z.number().optional().describe('Offset for pagination'),
|
|
email: z.string().optional().describe('Filter by email address')
|
|
}),
|
|
handler: async (args: any) => {
|
|
const result = await client.getCustomers(args);
|
|
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
}
|
|
},
|
|
{
|
|
name: 'lightspeed_get_customer',
|
|
description: 'Get a single customer by ID with all details including contact info, purchase history reference.',
|
|
inputSchema: z.object({
|
|
customerID: z.string().describe('The customer ID')
|
|
}),
|
|
handler: async (args: any) => {
|
|
const result = await client.getCustomer(args.customerID);
|
|
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
}
|
|
},
|
|
{
|
|
name: 'lightspeed_create_customer',
|
|
description: 'Create a new customer in Lightspeed. Requires first name and last name at minimum.',
|
|
inputSchema: z.object({
|
|
firstName: z.string().describe('Customer first name'),
|
|
lastName: z.string().describe('Customer last name'),
|
|
email: z.string().optional().describe('Email address'),
|
|
phone: z.string().optional().describe('Phone number'),
|
|
mobile: z.string().optional().describe('Mobile phone number'),
|
|
company: z.string().optional().describe('Company name'),
|
|
address1: z.string().optional().describe('Address line 1'),
|
|
address2: z.string().optional().describe('Address line 2'),
|
|
city: z.string().optional().describe('City'),
|
|
state: z.string().optional().describe('State/Province'),
|
|
zip: z.string().optional().describe('Postal/ZIP code'),
|
|
country: z.string().optional().describe('Country'),
|
|
dob: z.string().optional().describe('Date of birth (YYYY-MM-DD)')
|
|
}),
|
|
handler: async (args: any) => {
|
|
const { address1, address2, city, state, zip, country, ...customerData } = args;
|
|
const customer: any = { ...customerData };
|
|
|
|
if (address1 || city || state || zip || country) {
|
|
customer.address = { address1, address2, city, state, zip, country };
|
|
}
|
|
|
|
const result = await client.createCustomer(customer);
|
|
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
}
|
|
},
|
|
{
|
|
name: 'lightspeed_update_customer',
|
|
description: 'Update an existing customer. Can modify any customer field including contact info and address.',
|
|
inputSchema: z.object({
|
|
customerID: z.string().describe('The customer ID to update'),
|
|
firstName: z.string().optional().describe('Customer first name'),
|
|
lastName: z.string().optional().describe('Customer last name'),
|
|
email: z.string().optional().describe('Email address'),
|
|
phone: z.string().optional().describe('Phone number'),
|
|
mobile: z.string().optional().describe('Mobile phone number'),
|
|
company: z.string().optional().describe('Company name'),
|
|
archived: z.boolean().optional().describe('Archive the customer')
|
|
}),
|
|
handler: async (args: any) => {
|
|
const { customerID, ...updates } = args;
|
|
const result = await client.updateCustomer(customerID, updates);
|
|
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
}
|
|
},
|
|
{
|
|
name: 'lightspeed_delete_customer',
|
|
description: 'Delete a customer from Lightspeed. This action cannot be undone.',
|
|
inputSchema: z.object({
|
|
customerID: z.string().describe('The customer ID to delete')
|
|
}),
|
|
handler: async (args: any) => {
|
|
const result = await client.deleteCustomer(args.customerID);
|
|
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
}
|
|
},
|
|
{
|
|
name: 'lightspeed_search_customers',
|
|
description: 'Search customers by name, email, or phone number.',
|
|
inputSchema: z.object({
|
|
query: z.string().describe('Search query (name, email, or phone)')
|
|
}),
|
|
handler: async (args: any) => {
|
|
const result = await client.getCustomers({ limit: 500 });
|
|
if (result.success) {
|
|
const query = args.query.toLowerCase();
|
|
const filtered = result.data.filter(c =>
|
|
c.firstName?.toLowerCase().includes(query) ||
|
|
c.lastName?.toLowerCase().includes(query) ||
|
|
c.email?.toLowerCase().includes(query) ||
|
|
c.phone?.includes(query) ||
|
|
c.mobile?.includes(query)
|
|
);
|
|
return { content: [{ type: 'text', text: JSON.stringify({ success: true, data: filtered }, null, 2) }] };
|
|
}
|
|
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
}
|
|
},
|
|
{
|
|
name: 'lightspeed_get_customer_by_email',
|
|
description: 'Find a customer by their email address.',
|
|
inputSchema: z.object({
|
|
email: z.string().describe('Customer email address')
|
|
}),
|
|
handler: async (args: any) => {
|
|
const result = await client.getCustomers({ email: args.email });
|
|
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
}
|
|
}
|
|
];
|
|
}
|