Skip to content

Commit 52055b3

Browse files
npslaneyclaude
andcommitted
refactor: consolidate customer schemas for clearer naming
- Rename McpCustomerSchema to CustomerSchema (pure customer data) - Create CustomerWithSubscriptionsSchema for SDK endpoint (customer + full subscriptions) - Remove CustomerSubscriptionSchema (now uses full SubscriptionSchema instead) - Update all imports and exports across contracts Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 23024e3 commit 52055b3

5 files changed

Lines changed: 32 additions & 56 deletions

File tree

src/contracts/checkout.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { oc } from "@orpc/contract";
22
import { z } from "zod";
33
import { CheckoutSchema } from "../schemas/checkout";
44
import { CurrencySchema } from "../schemas/currency";
5-
import { McpCustomerSchema } from "../schemas/customer";
5+
import { CustomerSchema } from "../schemas/customer";
66
import {
77
PaginationInputSchema,
88
PaginationOutputSchema,
@@ -173,7 +173,7 @@ export const listCheckoutsContract = oc
173173
.output(ListCheckoutsOutputSchema);
174174

175175
// MCP-specific embedded customer schema (uses admin customer schema, not SDK customer)
176-
const CheckoutCustomerSchema = McpCustomerSchema.nullable();
176+
const CheckoutCustomerSchema = CustomerSchema.nullable();
177177

178178
// MCP-specific summary schema for list (simpler than full CheckoutSchema)
179179
const CheckoutListItemSchema = z.object({

src/contracts/customer.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { oc } from "@orpc/contract";
22
import { z } from "zod";
33
import {
44
CustomerSchema,
5-
McpCustomerSchema,
5+
CustomerWithSubscriptionsSchema,
66
GetCustomerInputSchema as SdkGetCustomerInputSchema,
77
} from "../schemas/customer";
88
import {
@@ -13,7 +13,7 @@ import {
1313
// MCP-specific schemas
1414
const ListCustomersInputSchema = PaginationInputSchema;
1515
const ListCustomersOutputSchema = PaginationOutputSchema.extend({
16-
customers: z.array(McpCustomerSchema),
16+
customers: z.array(CustomerSchema),
1717
});
1818

1919
const McpGetCustomerInputSchema = z.object({ id: z.string() });
@@ -35,7 +35,7 @@ const DeleteCustomerInputSchema = z.object({ id: z.string() });
3535
// SDK contract - uses flexible lookup (externalId/email/customerId)
3636
export const getSdkCustomerContract = oc
3737
.input(SdkGetCustomerInputSchema)
38-
.output(CustomerSchema);
38+
.output(CustomerWithSubscriptionsSchema);
3939

4040
// MCP contracts
4141
export const listCustomersContract = oc
@@ -44,15 +44,15 @@ export const listCustomersContract = oc
4444

4545
export const getCustomerContract = oc
4646
.input(McpGetCustomerInputSchema)
47-
.output(McpCustomerSchema);
47+
.output(CustomerSchema);
4848

4949
export const createCustomerContract = oc
5050
.input(CreateCustomerInputSchema)
51-
.output(McpCustomerSchema);
51+
.output(CustomerSchema);
5252

5353
export const updateCustomerContract = oc
5454
.input(UpdateCustomerInputSchema)
55-
.output(McpCustomerSchema);
55+
.output(CustomerSchema);
5656

5757
export const deleteCustomerContract = oc
5858
.input(DeleteCustomerInputSchema)

src/contracts/order.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { oc } from "@orpc/contract";
22
import { z } from "zod";
3-
import { McpCustomerSchema } from "../schemas/customer";
3+
import { CustomerSchema } from "../schemas/customer";
44
import { OrderItemSchema, OrderSchema } from "../schemas/order";
55
import {
66
PaginationInputSchema,
77
PaginationOutputSchema,
88
} from "../schemas/pagination";
99

10-
// Order with related data for list and get views (MCP uses admin customer schema)
10+
// Order with related data for list and get views
1111
const OrderWithRelationsSchema = OrderSchema.extend({
12-
customer: McpCustomerSchema.nullable(),
12+
customer: CustomerSchema.nullable(),
1313
orderItems: z.array(OrderItemSchema),
1414
});
1515

src/index.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,11 @@ export {
5656
SubscriptionWebhookEventSchema,
5757
SubscriptionWebhookPayloadSchema,
5858
} from "./schemas/subscription";
59-
export type {
60-
Customer,
61-
CustomerSubscription,
62-
McpCustomer,
63-
} from "./schemas/customer";
59+
export type { Customer, CustomerWithSubscriptions } from "./schemas/customer";
6460
export {
6561
CustomerSchema,
66-
CustomerSubscriptionSchema,
62+
CustomerWithSubscriptionsSchema,
6763
GetCustomerInputSchema,
68-
McpCustomerSchema,
6964
} from "./schemas/customer";
7065

7166
// New MCP schemas

src/schemas/customer.ts

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,33 @@
11
import { z } from "zod";
2-
import { CurrencySchema } from "./currency";
3-
import {
4-
RecurringIntervalSchema,
5-
SubscriptionStatusSchema,
6-
} from "./subscription";
2+
import { SubscriptionSchema } from "./subscription";
73

84
/**
9-
* Summary of a subscription for the customer response.
10-
* Contains the essential fields needed for displaying subscription status.
5+
* Customer schema for API responses.
6+
* Represents a customer in the organization (admin view).
7+
* Note: Uses modifiedAt to match Prisma schema naming.
118
*/
12-
export const CustomerSubscriptionSchema = z.object({
9+
export const CustomerSchema = z.object({
1310
id: z.string(),
14-
productId: z.string(),
15-
status: SubscriptionStatusSchema,
16-
currentPeriodStart: z.string().datetime(),
17-
currentPeriodEnd: z.string().datetime(),
18-
cancelAtPeriodEnd: z.boolean().optional(),
19-
amount: z.number(),
20-
currency: CurrencySchema,
21-
recurringInterval: RecurringIntervalSchema,
11+
name: z.string().nullable(),
12+
email: z.string().nullable(),
13+
emailVerified: z.boolean(),
14+
externalId: z.string().nullable(),
15+
userMetadata: z.record(z.string(), z.any()).nullable(),
16+
organizationId: z.string(),
17+
createdAt: z.date(),
18+
modifiedAt: z.date().nullable(),
2219
});
2320

2421
/**
25-
* Customer data with their subscriptions.
22+
* Customer data with their full subscriptions.
2623
* Returned by the SDK customer.get endpoint.
2724
*/
28-
export const CustomerSchema = z.object({
25+
export const CustomerWithSubscriptionsSchema = z.object({
2926
id: z.string(),
3027
email: z.string().nullable().optional(),
3128
name: z.string().nullable().optional(),
3229
externalId: z.string().nullable().optional(),
33-
subscriptions: z.array(CustomerSubscriptionSchema),
30+
subscriptions: z.array(SubscriptionSchema),
3431
});
3532

3633
/**
@@ -56,24 +53,8 @@ export const GetCustomerInputSchema = z
5653
},
5754
);
5855

59-
/**
60-
* Customer schema for MCP API responses.
61-
* Represents a customer in the organization (admin view).
62-
* Note: Uses modifiedAt to match Prisma schema naming.
63-
*/
64-
export const McpCustomerSchema = z.object({
65-
id: z.string(),
66-
name: z.string().nullable(),
67-
email: z.string().nullable(),
68-
emailVerified: z.boolean(),
69-
externalId: z.string().nullable(),
70-
userMetadata: z.record(z.string(), z.any()).nullable(),
71-
organizationId: z.string(),
72-
createdAt: z.date(),
73-
modifiedAt: z.date().nullable(),
74-
});
75-
76-
export type CustomerSubscription = z.infer<typeof CustomerSubscriptionSchema>;
7756
export type Customer = z.infer<typeof CustomerSchema>;
78-
export type McpCustomer = z.infer<typeof McpCustomerSchema>;
57+
export type CustomerWithSubscriptions = z.infer<
58+
typeof CustomerWithSubscriptionsSchema
59+
>;
7960
export type GetCustomerInput = z.infer<typeof GetCustomerInputSchema>;

0 commit comments

Comments
 (0)