44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import { notNullish } from "@autumn/shared";
|
|
import { z } from "zod/v4";
|
|
|
|
export const UpdateBalanceParamsSchema = z
|
|
.object({
|
|
customer_id: z.string().meta({
|
|
description: "The ID of the customer.",
|
|
}),
|
|
entity_id: z.string().optional().meta({
|
|
description:
|
|
"The ID of the entity to update balance for (if using entity balances).",
|
|
}),
|
|
feature_id: z.string().meta({
|
|
description: "The ID of the feature to update balance for.",
|
|
}),
|
|
current_balance: z.number().optional().meta({
|
|
description: "The new balance value to set.",
|
|
}),
|
|
usage: z.number().optional().meta({
|
|
description: "The new usage value to set.",
|
|
}),
|
|
})
|
|
.refine(
|
|
(data) => {
|
|
if (notNullish(data.current_balance) && notNullish(data.usage)) {
|
|
return false;
|
|
}
|
|
if (!notNullish(data.current_balance) && !notNullish(data.usage)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
{
|
|
message:
|
|
"Either 'current_balance' or 'usage' must be provided, but not both.",
|
|
},
|
|
);
|
|
|
|
export type UpdateBalanceParams = z.infer<typeof UpdateBalanceParamsSchema>;
|
|
|
|
// Legacy export for backwards compatibility
|
|
export const BalancesUpdateParamsSchema = UpdateBalanceParamsSchema;
|
|
export type BalancesUpdateParams = UpdateBalanceParams;
|