Skip to content

Commit d050ad3

Browse files
committed
Merge main into mdk-401
Resolve conflicts: - package.json: use version 0.1.18 from main, keep prepare script - src/index.ts: add subscription to contracts, keep MCP schemas/contracts - src/contracts/customer.ts: keep both SDK and MCP customer endpoints - src/schemas/customer.ts: keep both CustomerSchema (SDK) and McpCustomerSchema (MCP)
2 parents 631f90c + b2ff3f5 commit d050ad3

10 files changed

Lines changed: 482 additions & 59 deletions

File tree

package.json

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,50 @@
11
{
2-
"name": "@moneydevkit/api-contract",
3-
"version": "0.1.17",
4-
"description": "API Contract for moneydevkit",
5-
"main": "./dist/index.cjs",
6-
"module": "./dist/index.js",
7-
"types": "./dist/index.d.ts",
8-
"type": "module",
9-
"files": [
10-
"dist"
11-
],
12-
"exports": {
13-
".": {
14-
"import": {
15-
"types": "./dist/index.d.ts",
16-
"import": "./dist/index.js"
17-
},
18-
"require": {
19-
"types": "./dist/index.d.cts",
20-
"require": "./dist/index.cjs"
21-
}
22-
}
23-
},
24-
"scripts": {
25-
"build": "tsup",
26-
"prepare": "pnpm run build",
27-
"test": "vitest",
28-
"check": "biome check ./src --fix"
29-
},
30-
"engines": {
31-
"node": ">=18"
32-
},
33-
"author": "",
34-
"license": "Apache-2.0",
35-
"publishConfig": {
36-
"registry": "https://registry.npmjs.org/",
37-
"access": "public"
38-
},
39-
"packageManager": "pnpm@9.0.0",
40-
"devDependencies": {
41-
"@biomejs/biome": "1.9.4",
42-
"@sindresorhus/tsconfig": "^7.0.0",
43-
"@types/node": "^22.19.3",
44-
"tsup": "^8.5.1",
45-
"typescript": "^5.9.3",
46-
"vitest": "^3.2.4"
47-
},
48-
"dependencies": {
49-
"@orpc/contract": "1.3.0",
50-
"zod": "^3.25.76"
51-
}
2+
"name": "@moneydevkit/api-contract",
3+
"version": "0.1.18",
4+
"description": "API Contract for moneydevkit",
5+
"main": "./dist/index.cjs",
6+
"module": "./dist/index.js",
7+
"types": "./dist/index.d.ts",
8+
"type": "module",
9+
"files": ["dist"],
10+
"exports": {
11+
".": {
12+
"import": {
13+
"types": "./dist/index.d.ts",
14+
"import": "./dist/index.js"
15+
},
16+
"require": {
17+
"types": "./dist/index.d.cts",
18+
"require": "./dist/index.cjs"
19+
}
20+
}
21+
},
22+
"scripts": {
23+
"build": "tsup",
24+
"prepare": "pnpm run build",
25+
"test": "vitest",
26+
"check": "biome check ./src --fix"
27+
},
28+
"engines": {
29+
"node": ">=18"
30+
},
31+
"author": "",
32+
"license": "Apache-2.0",
33+
"publishConfig": {
34+
"registry": "https://registry.npmjs.org/",
35+
"access": "public"
36+
},
37+
"packageManager": "pnpm@9.0.0",
38+
"devDependencies": {
39+
"@biomejs/biome": "1.9.4",
40+
"@sindresorhus/tsconfig": "^7.0.0",
41+
"@types/node": "^22.19.3",
42+
"tsup": "^8.5.1",
43+
"typescript": "^5.9.3",
44+
"vitest": "^3.2.4"
45+
},
46+
"dependencies": {
47+
"@orpc/contract": "1.3.0",
48+
"zod": "^3.25.76"
49+
}
5250
}

src/contracts/checkout.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { oc } from "@orpc/contract";
22
import { z } from "zod";
33
import { CheckoutSchema } from "../schemas/checkout";
44
import { CurrencySchema } from "../schemas/currency";
5+
import { CustomerSchema } from "../schemas/customer";
6+
import {
7+
PaginationInputSchema,
8+
PaginationOutputSchema,
9+
} from "../schemas/pagination";
510

611
/**
712
* Helper to treat empty strings as undefined (not provided).
@@ -142,10 +147,74 @@ export const paymentReceivedContract = oc
142147
.input(PaymentReceivedInputSchema)
143148
.output(z.object({ ok: z.boolean() }));
144149

150+
// List checkouts schemas
151+
const CheckoutStatusSchema = z.enum([
152+
"UNCONFIRMED",
153+
"CONFIRMED",
154+
"PENDING_PAYMENT",
155+
"PAYMENT_RECEIVED",
156+
"EXPIRED",
157+
]);
158+
159+
const ListCheckoutsInputSchema = PaginationInputSchema.extend({
160+
status: CheckoutStatusSchema.optional(),
161+
});
162+
163+
const ListCheckoutsOutputSchema = PaginationOutputSchema.extend({
164+
checkouts: z.array(CheckoutSchema),
165+
});
166+
167+
export const listCheckoutsContract = oc
168+
.input(ListCheckoutsInputSchema)
169+
.output(ListCheckoutsOutputSchema);
170+
171+
// MCP-specific embedded customer schema
172+
const CheckoutCustomerSchema = CustomerSchema.nullable();
173+
174+
// MCP-specific summary schema for list (simpler than full CheckoutSchema)
175+
const CheckoutListItemSchema = z.object({
176+
id: z.string(),
177+
status: CheckoutStatusSchema,
178+
type: z.enum(["PRODUCTS", "AMOUNT", "TOP_UP"]),
179+
currency: CurrencySchema,
180+
totalAmount: z.number().nullable(),
181+
customerId: z.string().nullable(),
182+
customer: CheckoutCustomerSchema,
183+
productId: z.string().nullable(),
184+
organizationId: z.string(),
185+
expiresAt: z.date(),
186+
createdAt: z.date(),
187+
modifiedAt: z.date().nullable(),
188+
});
189+
190+
// MCP-specific detailed schema for get (includes additional fields)
191+
const CheckoutDetailSchema = CheckoutListItemSchema.extend({
192+
userMetadata: z.record(z.unknown()).nullable(),
193+
successUrl: z.string().nullable(),
194+
discountAmount: z.number().nullable(),
195+
netAmount: z.number().nullable(),
196+
taxAmount: z.number().nullable(),
197+
});
198+
199+
const ListCheckoutsSummaryOutputSchema = PaginationOutputSchema.extend({
200+
checkouts: z.array(CheckoutListItemSchema),
201+
});
202+
203+
export const listCheckoutsSummaryContract = oc
204+
.input(ListCheckoutsInputSchema)
205+
.output(ListCheckoutsSummaryOutputSchema);
206+
207+
export const getCheckoutSummaryContract = oc
208+
.input(GetCheckoutInputSchema)
209+
.output(CheckoutDetailSchema);
210+
145211
export const checkout = {
146212
get: getCheckoutContract,
147213
create: createCheckoutContract,
148214
confirm: confirmCheckoutContract,
149215
registerInvoice: registerInvoiceContract,
150216
paymentReceived: paymentReceivedContract,
217+
list: listCheckoutsContract,
218+
listSummary: listCheckoutsSummaryContract,
219+
getSummary: getCheckoutSummaryContract,
151220
};

src/contracts/customer.ts

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,68 @@
11
import { oc } from "@orpc/contract";
2-
import { CustomerSchema, GetCustomerInputSchema } from "../schemas/customer";
2+
import { z } from "zod";
3+
import {
4+
CustomerSchema,
5+
McpCustomerSchema,
6+
GetCustomerInputSchema as SdkGetCustomerInputSchema,
7+
} from "../schemas/customer";
8+
import {
9+
PaginationInputSchema,
10+
PaginationOutputSchema,
11+
} from "../schemas/pagination";
312

4-
export const getCustomerContract = oc
5-
.input(GetCustomerInputSchema)
13+
// MCP-specific schemas
14+
const ListCustomersInputSchema = PaginationInputSchema;
15+
const ListCustomersOutputSchema = PaginationOutputSchema.extend({
16+
customers: z.array(McpCustomerSchema),
17+
});
18+
19+
const McpGetCustomerInputSchema = z.object({ id: z.string() });
20+
21+
const CreateCustomerInputSchema = z.object({
22+
name: z.string().min(1),
23+
email: z.string().email(),
24+
});
25+
26+
const UpdateCustomerInputSchema = z.object({
27+
id: z.string(),
28+
name: z.string().optional(),
29+
email: z.string().email().optional(),
30+
userMetadata: z.record(z.string(), z.string()).optional(),
31+
});
32+
33+
const DeleteCustomerInputSchema = z.object({ id: z.string() });
34+
35+
// SDK contract - uses flexible lookup (externalId/email/customerId)
36+
export const getSdkCustomerContract = oc
37+
.input(SdkGetCustomerInputSchema)
638
.output(CustomerSchema);
739

40+
// MCP contracts
41+
export const listCustomersContract = oc
42+
.input(ListCustomersInputSchema)
43+
.output(ListCustomersOutputSchema);
44+
45+
export const getCustomerContract = oc
46+
.input(McpGetCustomerInputSchema)
47+
.output(McpCustomerSchema);
48+
49+
export const createCustomerContract = oc
50+
.input(CreateCustomerInputSchema)
51+
.output(McpCustomerSchema);
52+
53+
export const updateCustomerContract = oc
54+
.input(UpdateCustomerInputSchema)
55+
.output(McpCustomerSchema);
56+
57+
export const deleteCustomerContract = oc
58+
.input(DeleteCustomerInputSchema)
59+
.output(z.object({ ok: z.literal(true) }));
60+
861
export const customer = {
62+
list: listCustomersContract,
963
get: getCustomerContract,
64+
getSdk: getSdkCustomerContract,
65+
create: createCustomerContract,
66+
update: updateCustomerContract,
67+
delete: deleteCustomerContract,
1068
};

src/contracts/order.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 and get views
11+
const OrderWithRelationsSchema = OrderSchema.extend({
12+
customer: CustomerSchema.nullable(),
13+
orderItems: z.array(OrderItemSchema),
14+
});
15+
16+
const ListOrdersInputSchema = PaginationInputSchema.extend({
17+
customerId: z.string().optional(),
18+
status: z.string().optional(), // Prisma uses String type for status
19+
});
20+
21+
const ListOrdersOutputSchema = PaginationOutputSchema.extend({
22+
orders: z.array(OrderWithRelationsSchema),
23+
});
24+
25+
export const listOrdersContract = oc
26+
.input(ListOrdersInputSchema)
27+
.output(ListOrdersOutputSchema);
28+
29+
export const getOrderContract = oc
30+
.input(z.object({ id: z.string() }))
31+
.output(OrderWithRelationsSchema);
32+
33+
export const order = {
34+
list: listOrdersContract,
35+
get: getOrderContract,
36+
};

src/contracts/products.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { oc } from "@orpc/contract";
22
import { z } from "zod";
33
import { CurrencySchema } from "../schemas/currency";
4+
import { ProductPriceInputSchema } from "../schemas/product-price-input";
45

56
export const ProductPriceSchema = z.object({
67
id: z.string(),
@@ -31,6 +32,42 @@ export const listProductsContract = oc
3132
.input(z.object({}).optional())
3233
.output(ListProductsOutputSchema);
3334

35+
// CRUD input schemas
36+
const CreateProductInputSchema = z.object({
37+
name: z.string().min(1),
38+
description: z.string().optional(),
39+
price: ProductPriceInputSchema,
40+
userMetadata: z.record(z.string(), z.string()).optional(),
41+
});
42+
43+
const UpdateProductInputSchema = z.object({
44+
id: z.string(),
45+
name: z.string().min(1).optional(),
46+
description: z.string().optional(),
47+
price: ProductPriceInputSchema.optional(),
48+
userMetadata: z.record(z.string(), z.string()).optional(),
49+
});
50+
51+
export const getProductContract = oc
52+
.input(z.object({ id: z.string() }))
53+
.output(ProductSchema);
54+
55+
export const createProductContract = oc
56+
.input(CreateProductInputSchema)
57+
.output(ProductSchema);
58+
59+
export const updateProductContract = oc
60+
.input(UpdateProductInputSchema)
61+
.output(ProductSchema);
62+
63+
export const deleteProductContract = oc
64+
.input(z.object({ id: z.string() }))
65+
.output(z.object({ ok: z.literal(true) }));
66+
3467
export const products = {
3568
list: listProductsContract,
69+
get: getProductContract,
70+
create: createProductContract,
71+
update: updateProductContract,
72+
delete: deleteProductContract,
3673
};

0 commit comments

Comments
 (0)