Skip to content

Commit 01db391

Browse files
npslaneyclaude
andcommitted
feat(api-contract): add customer contract
Add customer contract with CRUD operations (list, get, create, update, delete). Uses singular naming convention. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent cc0b6da commit 01db391

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

src/contracts/customer.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { oc } from "@orpc/contract";
2+
import { z } from "zod";
3+
import { CustomerSchema } from "../schemas/customer";
4+
import {
5+
PaginationInputSchema,
6+
PaginationOutputSchema,
7+
} from "../schemas/pagination";
8+
9+
const ListCustomersInputSchema = PaginationInputSchema;
10+
const ListCustomersOutputSchema = PaginationOutputSchema.extend({
11+
customers: z.array(CustomerSchema),
12+
});
13+
14+
const GetCustomerInputSchema = z.object({ id: z.string() });
15+
16+
const CreateCustomerInputSchema = z.object({
17+
name: z.string().min(1),
18+
email: z.string().email(),
19+
});
20+
21+
const UpdateCustomerInputSchema = z.object({
22+
id: z.string(),
23+
name: z.string().optional(),
24+
email: z.string().email().optional(),
25+
userMetadata: z.record(z.string(), z.string()).optional(),
26+
});
27+
28+
const DeleteCustomerInputSchema = z.object({ id: z.string() });
29+
30+
export const listCustomersContract = oc
31+
.input(ListCustomersInputSchema)
32+
.output(ListCustomersOutputSchema);
33+
34+
export const getCustomerContract = oc
35+
.input(GetCustomerInputSchema)
36+
.output(CustomerSchema);
37+
38+
export const createCustomerContract = oc
39+
.input(CreateCustomerInputSchema)
40+
.output(CustomerSchema);
41+
42+
export const updateCustomerContract = oc
43+
.input(UpdateCustomerInputSchema)
44+
.output(CustomerSchema);
45+
46+
export const deleteCustomerContract = oc
47+
.input(DeleteCustomerInputSchema)
48+
.output(z.object({ ok: z.literal(true) }));
49+
50+
export const customer = {
51+
list: listCustomersContract,
52+
get: getCustomerContract,
53+
create: createCustomerContract,
54+
update: updateCustomerContract,
55+
delete: deleteCustomerContract,
56+
};

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { checkout } from "./contracts/checkout";
2+
import { customer } from "./contracts/customer";
23
import {
34
checkouts as mcpCheckouts,
45
customers as mcpCustomers,
@@ -58,7 +59,7 @@ export {
5859
} from "./schemas/product-price-input";
5960

6061
// SDK contract - consumed by SDK clients
61-
export const contract = { checkout, onboarding, products };
62+
export const contract = { checkout, customer, onboarding, products };
6263

6364
/**
6465
* MCP contract - separate namespace for MCP tools.

0 commit comments

Comments
 (0)