Skip to content

Commit 93b4a95

Browse files
authored
Merge pull request #7 from moneydevkit/mdk-403
feat: add products.list contract (MDK-403)
2 parents 9ca92c9 + d7cf0be commit 93b4a95

5 files changed

Lines changed: 317 additions & 344 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.13",
3+
"version": "0.1.14",
44
"description": "API Contract for moneydevkit",
55
"main": "./dist/index.cjs",
66
"module": "./dist/index.js",

src/contracts/products.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { oc } from "@orpc/contract";
2+
import { z } from "zod";
3+
4+
export const ProductPriceSchema = z.object({
5+
id: z.string(),
6+
amountType: z.enum(["FIXED", "CUSTOM", "FREE"]),
7+
priceAmount: z.number().nullable(),
8+
});
9+
10+
export const ProductSchema = z.object({
11+
id: z.string(),
12+
name: z.string(),
13+
description: z.string().nullable(),
14+
recurringInterval: z.enum(["MONTH", "QUARTER", "YEAR"]).nullable(),
15+
prices: z.array(ProductPriceSchema),
16+
});
17+
18+
export const ListProductsOutputSchema = z.object({
19+
products: z.array(ProductSchema),
20+
});
21+
22+
export type Product = z.infer<typeof ProductSchema>;
23+
export type ProductPrice = z.infer<typeof ProductPriceSchema>;
24+
25+
export const listProductsContract = oc
26+
.input(z.object({}).optional())
27+
.output(ListProductsOutputSchema);
28+
29+
export const products = {
30+
list: listProductsContract,
31+
};

src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { checkout } from "./contracts/checkout";
22
import { onboarding } from "./contracts/onboarding";
3+
import { products } from "./contracts/products";
34

45
export type {
56
ConfirmCheckout,
@@ -18,8 +19,14 @@ export type {
1819
} from "./contracts/onboarding";
1920
export type { Checkout } from "./schemas/checkout";
2021
export { CheckoutSchema } from "./schemas/checkout";
22+
export type { Product, ProductPrice } from "./contracts/products";
23+
export {
24+
ProductSchema,
25+
ProductPriceSchema,
26+
ListProductsOutputSchema,
27+
} from "./contracts/products";
2128

22-
export const contract = { checkout, onboarding };
29+
export const contract = { checkout, onboarding, products };
2330

2431
export type { MetadataValidationError } from "./validation/metadata-validation";
2532
export {

src/schemas/product.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@ import { z } from "zod";
22

33
export const CheckoutProductPriceSchema = z.object({
44
id: z.string(),
5-
amountType: z.enum(["FIXED", "CUSTOM", "FREE", "METERED"]),
5+
amountType: z.enum(["FIXED", "CUSTOM", "FREE"]),
66
priceAmount: z.number().nullable(),
7-
minimumAmount: z.number().nullable(),
8-
maximumAmount: z.number().nullable(),
9-
presetAmount: z.number().nullable(),
10-
unitAmount: z.number().nullable(),
11-
capAmount: z.number().nullable(),
12-
meterId: z.string().nullable(),
137
});
148

159
export const CheckoutProductSchema = z.object({

0 commit comments

Comments
 (0)