40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import { z } from "zod/v4";
|
|
import { ApiSpendLimitSchema } from "./spendLimit.js";
|
|
|
|
export const ApiEntityBillingControlsSchema = z.object({
|
|
spend_limits: z.array(ApiSpendLimitSchema).optional().meta({
|
|
description: "List of overage spend limits per feature.",
|
|
}),
|
|
});
|
|
|
|
export const ApiEntityBillingControlsInputSchema =
|
|
ApiEntityBillingControlsSchema.superRefine((billingControls, ctx) => {
|
|
const featureIds = new Set<string>();
|
|
|
|
for (const [index, spendLimit] of (
|
|
billingControls.spend_limits ?? []
|
|
).entries()) {
|
|
if (!spendLimit.feature_id) {
|
|
continue;
|
|
}
|
|
|
|
if (featureIds.has(spendLimit.feature_id)) {
|
|
ctx.addIssue({
|
|
code: "custom",
|
|
message: "Only one spend limit entry is allowed per feature_id",
|
|
path: ["spend_limits", index, "feature_id"],
|
|
});
|
|
return;
|
|
}
|
|
|
|
featureIds.add(spendLimit.feature_id);
|
|
}
|
|
});
|
|
|
|
export type ApiEntityBillingControls = z.infer<
|
|
typeof ApiEntityBillingControlsSchema
|
|
>;
|
|
export type ApiEntityBillingControlsInput = z.input<
|
|
typeof ApiEntityBillingControlsInputSchema
|
|
>;
|