Skip to content

Commit dacc647

Browse files
authored
Merge pull request #14 from moneydevkit/mdk-456-type-exports
Export types and schemas for mcp MDK-456
2 parents 29b2180 + cbc1d56 commit dacc647

5 files changed

Lines changed: 49 additions & 60 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@moneydevkit/api-contract",
3-
"version": "0.1.19",
3+
"version": "0.1.20",
44
"description": "API Contract for moneydevkit",
55
"main": "./dist/index.cjs",
66
"module": "./dist/index.js",

src/contracts/checkout.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,17 @@ export const paymentReceivedContract = oc
148148
.output(z.object({ ok: z.boolean() }));
149149

150150
// List checkouts schemas
151-
const CheckoutStatusSchema = z.enum([
151+
export const CheckoutStatusSchema = z.enum([
152152
"UNCONFIRMED",
153153
"CONFIRMED",
154154
"PENDING_PAYMENT",
155155
"PAYMENT_RECEIVED",
156156
"EXPIRED",
157157
]);
158+
export type CheckoutStatus = z.infer<typeof CheckoutStatusSchema>;
159+
160+
export const CheckoutTypeSchema = z.enum(["PRODUCTS", "AMOUNT", "TOP_UP"]);
161+
export type CheckoutType = z.infer<typeof CheckoutTypeSchema>;
158162

159163
const ListCheckoutsInputSchema = PaginationInputSchema.extend({
160164
status: CheckoutStatusSchema.optional(),
@@ -168,14 +172,13 @@ export const listCheckoutsContract = oc
168172
.input(ListCheckoutsInputSchema)
169173
.output(ListCheckoutsOutputSchema);
170174

171-
// MCP-specific embedded customer schema
172175
const CheckoutCustomerSchema = CustomerSchema.nullable();
173176

174177
// MCP-specific summary schema for list (simpler than full CheckoutSchema)
175178
const CheckoutListItemSchema = z.object({
176179
id: z.string(),
177180
status: CheckoutStatusSchema,
178-
type: z.enum(["PRODUCTS", "AMOUNT", "TOP_UP"]),
181+
type: CheckoutTypeSchema,
179182
currency: CurrencySchema,
180183
totalAmount: z.number().nullable(),
181184
customerId: z.string().nullable(),

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/index.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ import { products } from "./contracts/products";
66
import { subscription } from "./contracts/subscription";
77

88
export type {
9+
CheckoutStatus,
10+
CheckoutType,
911
ConfirmCheckout,
1012
CreateCheckout,
1113
PaymentReceived,
1214
RegisterInvoice,
1315
} from "./contracts/checkout";
16+
export {
17+
CheckoutStatusSchema,
18+
CheckoutTypeSchema,
19+
} from "./contracts/checkout";
1420
export type {
1521
BootstrapOnboarding,
1622
BootstrapOnboardingResponse,
@@ -50,16 +56,11 @@ export {
5056
SubscriptionWebhookEventSchema,
5157
SubscriptionWebhookPayloadSchema,
5258
} from "./schemas/subscription";
53-
export type {
54-
Customer,
55-
CustomerSubscription,
56-
McpCustomer,
57-
} from "./schemas/customer";
59+
export type { Customer, CustomerWithSubscriptions } from "./schemas/customer";
5860
export {
5961
CustomerSchema,
60-
CustomerSubscriptionSchema,
62+
CustomerWithSubscriptionsSchema,
6163
GetCustomerInputSchema,
62-
McpCustomerSchema,
6364
} from "./schemas/customer";
6465

6566
// New MCP schemas
@@ -75,10 +76,12 @@ export {
7576
PaginationOutputSchema,
7677
} from "./schemas/pagination";
7778
export type {
79+
PriceAmountType,
7880
ProductPriceInput,
7981
RecurringIntervalInput,
8082
} from "./schemas/product-price-input";
8183
export {
84+
PriceAmountTypeSchema,
8285
ProductPriceInputSchema,
8386
RecurringIntervalInputSchema,
8487
} from "./schemas/product-price-input";
@@ -102,19 +105,21 @@ export const sdkContract = {
102105
registerInvoice: checkout.registerInvoice,
103106
paymentReceived: checkout.paymentReceived,
104107
},
105-
customer: {
106-
get: customer.getSdk,
107-
},
108108
onboarding,
109109
products: {
110110
list: products.list,
111111
},
112-
subscription,
113112
};
114113

115114
// MCP contract - only the methods the MCP router implements
116115
export const mcpContract = {
117-
customer,
116+
customer: {
117+
list: customer.list,
118+
get: customer.get,
119+
create: customer.create,
120+
update: customer.update,
121+
delete: customer.delete,
122+
},
118123
order,
119124
checkout: {
120125
list: checkout.listSummary,

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)