Skip to content

Commit 05c871c

Browse files
npslaneyclaude
andcommitted
feat(api-contract): add order contract
Add order contract with list and get operations. Uses singular naming convention. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 01db391 commit 05c871c

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

src/contracts/order.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { oc } from "@orpc/contract";
2+
import { z } from "zod";
3+
import { CustomerSchema } from "../schemas/customer";
4+
import { OrderItemSchema, OrderSchema } from "../schemas/order";
5+
import {
6+
PaginationInputSchema,
7+
PaginationOutputSchema,
8+
} from "../schemas/pagination";
9+
10+
// Order with related data for list view
11+
const OrderWithRelationsSchema = OrderSchema.extend({
12+
customer: CustomerSchema.nullable(),
13+
orderItems: z.array(OrderItemSchema),
14+
});
15+
16+
// Order with full details for get view
17+
const OrderDetailSchema = OrderWithRelationsSchema;
18+
19+
const ListOrdersInputSchema = PaginationInputSchema.extend({
20+
customerId: z.string().optional(),
21+
status: z.string().optional(), // Prisma uses String type for status
22+
});
23+
24+
const ListOrdersOutputSchema = PaginationOutputSchema.extend({
25+
orders: z.array(OrderWithRelationsSchema),
26+
});
27+
28+
export const listOrdersContract = oc
29+
.input(ListOrdersInputSchema)
30+
.output(ListOrdersOutputSchema);
31+
32+
export const getOrderContract = oc
33+
.input(z.object({ id: z.string() }))
34+
.output(OrderDetailSchema);
35+
36+
export const order = {
37+
list: listOrdersContract,
38+
get: getOrderContract,
39+
};

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
products as mcpProducts,
88
} from "./contracts/mcp";
99
import { onboarding } from "./contracts/onboarding";
10+
import { order } from "./contracts/order";
1011
import { products } from "./contracts/products";
1112

1213
export type {
@@ -59,7 +60,7 @@ export {
5960
} from "./schemas/product-price-input";
6061

6162
// SDK contract - consumed by SDK clients
62-
export const contract = { checkout, customer, onboarding, products };
63+
export const contract = { checkout, customer, onboarding, order, products };
6364

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

0 commit comments

Comments
 (0)