Skip to content

Commit 1d8ac06

Browse files
npslaneyclaude
andcommitted
feat(api-contract): add SDK and MCP-specific contract exports
Add sdkContract and mcpContract exports that contain only the methods each router implements. This allows proper TypeScript validation while keeping the unified contract for type sharing. - sdkContract: checkout.get/create/confirm/etc, onboarding.*, products.list - mcpContract: customer.*, order.*, checkout.list/get (summary), products.* - Add CheckoutListItemSchema and CheckoutDetailSchema for MCP endpoints - These are simpler than the full CheckoutSchema used by SDK Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 1653e90 commit 1d8ac06

2 files changed

Lines changed: 81 additions & 1 deletion

File tree

src/contracts/checkout.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,65 @@ export const listCheckoutsContract = oc
167167
.input(ListCheckoutsInputSchema)
168168
.output(ListCheckoutsOutputSchema);
169169

170+
// MCP-specific embedded customer schema
171+
const CheckoutCustomerSchema = z
172+
.object({
173+
id: z.string(),
174+
name: z.string().nullable(),
175+
email: z.string().nullable(),
176+
emailVerified: z.boolean(),
177+
externalId: z.string().nullable(),
178+
userMetadata: z.record(z.unknown()).nullable(),
179+
organizationId: z.string(),
180+
createdAt: z.date(),
181+
modifiedAt: z.date().nullable(),
182+
})
183+
.nullable();
184+
185+
// MCP-specific summary schema for list (simpler than full CheckoutSchema)
186+
const CheckoutListItemSchema = z.object({
187+
id: z.string(),
188+
status: CheckoutStatusSchema,
189+
type: z.enum(["PRODUCTS", "AMOUNT", "TOP_UP"]),
190+
currency: CurrencySchema,
191+
totalAmount: z.number().nullable(),
192+
customerId: z.string().nullable(),
193+
customer: CheckoutCustomerSchema,
194+
productId: z.string().nullable(),
195+
organizationId: z.string(),
196+
expiresAt: z.date(),
197+
createdAt: z.date(),
198+
modifiedAt: z.date().nullable(),
199+
});
200+
201+
// MCP-specific detailed schema for get (includes additional fields)
202+
const CheckoutDetailSchema = CheckoutListItemSchema.extend({
203+
userMetadata: z.record(z.unknown()).nullable(),
204+
successUrl: z.string().nullable(),
205+
discountAmount: z.number().nullable(),
206+
netAmount: z.number().nullable(),
207+
taxAmount: z.number().nullable(),
208+
});
209+
210+
const ListCheckoutsSummaryOutputSchema = PaginationOutputSchema.extend({
211+
checkouts: z.array(CheckoutListItemSchema),
212+
});
213+
214+
export const listCheckoutsSummaryContract = oc
215+
.input(ListCheckoutsInputSchema)
216+
.output(ListCheckoutsSummaryOutputSchema);
217+
218+
export const getCheckoutSummaryContract = oc
219+
.input(GetCheckoutInputSchema)
220+
.output(CheckoutDetailSchema);
221+
170222
export const checkout = {
171223
get: getCheckoutContract,
172224
create: createCheckoutContract,
173225
confirm: confirmCheckoutContract,
174226
registerInvoice: registerInvoiceContract,
175227
paymentReceived: paymentReceivedContract,
176228
list: listCheckoutsContract,
229+
listSummary: listCheckoutsSummaryContract,
230+
getSummary: getCheckoutSummaryContract,
177231
};

src/index.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,35 @@ export {
5353
RecurringIntervalInputSchema,
5454
} from "./schemas/product-price-input";
5555

56-
// Unified contract - consumed by both SDK and MCP
56+
// Unified contract - contains all methods from both SDK and MCP
5757
export const contract = { checkout, customer, onboarding, order, products };
5858

59+
// SDK contract - only the methods the SDK router implements
60+
export const sdkContract = {
61+
checkout: {
62+
get: checkout.get,
63+
create: checkout.create,
64+
confirm: checkout.confirm,
65+
registerInvoice: checkout.registerInvoice,
66+
paymentReceived: checkout.paymentReceived,
67+
},
68+
onboarding,
69+
products: {
70+
list: products.list,
71+
},
72+
};
73+
74+
// MCP contract - only the methods the MCP router implements
75+
export const mcpContract = {
76+
customer,
77+
order,
78+
checkout: {
79+
list: checkout.listSummary,
80+
get: checkout.getSummary,
81+
},
82+
products,
83+
};
84+
5985
export type { MetadataValidationError } from "./validation/metadata-validation";
6086
export {
6187
MAX_KEY_COUNT,

0 commit comments

Comments
 (0)