getCustomers.ts
Language TypeScript2.1 KB54 lines
import { z } from "zod";import type { ToolModule } from "./types.js";import { plinthRequest, type PlinthParams } from "../lib/http.js";import { toRequestDate } from "../lib/dates.js";/*** get_customers: customer records (Plinth method `customers.fetch`),* filterable by exact email or a signup/last-login date range.** There is no phone filter: the API silently drops a phone param (fails open)* and returns the full customer list, so this tool must never accept one.* Output is not yet gated on verified identity (lib/classification.ts).** Wire notes: no wrapper key; records keyed `cust_{ordinal}`. Phone formats* are inconsistent across records.*/export const getCustomers: ToolModule = {name: "get_customers",config: {title: "Get customers",description:"Look up customer records by exact email or signup/last-login date range. Read-only. No phone lookup (fail-open).",inputSchema: {email: z.email().optional().describe("Exact-match email."),dateField: z.enum(["last_login", "signup"]).optional().describe("Default: signup."),fromDate: z.string().optional().describe("ISO YYYY-MM-DD; converted to yyyymmdd on the wire."),toDate: z.string().optional().describe("ISO YYYY-MM-DD; converted to yyyymmdd on the wire."),offset: z.number().int().min(0).optional(),limit: z.number().int().min(1).max(100).optional(),},},async handler(args, ctx) {const { email, dateField, fromDate, toDate, offset, limit } = args as {email?: string;dateField?: "last_login" | "signup";fromDate?: string;toDate?: string;offset?: number;limit?: number;};const params: PlinthParams = {email,date_field: dateField,since: fromDate !== undefined ? toRequestDate(fromDate) : undefined,until: toDate !== undefined ? toRequestDate(toDate) : undefined,offset,limit,};const body = await plinthRequest(ctx, "customers.fetch", params);return { content: [{ type: "text", text: JSON.stringify(body, null, 2) }] };},};