feat: added spend limits to customer billing controls
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { z } from "zod/v4";
|
||||
import {
|
||||
type EntityBillingControls,
|
||||
type EntityBillingControlsInput,
|
||||
type EntityBillingControlsParams,
|
||||
EntityBillingControlsSchema,
|
||||
} from "./entityBillingControls.js";
|
||||
import { PurchaseLimitIntervalEnum } from "./purchaseLimitInterval.js";
|
||||
@@ -47,6 +47,32 @@ export const CustomerBillingControlsSchema = z.object({
|
||||
}),
|
||||
});
|
||||
|
||||
export const CustomerBillingControlsParamsSchema =
|
||||
CustomerBillingControlsSchema.check((ctx) => {
|
||||
const billingControls = ctx.value;
|
||||
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.issues.push({
|
||||
code: "custom",
|
||||
message: "Only one spend limit entry is allowed per feature_id",
|
||||
input: spendLimit.feature_id,
|
||||
path: ["spend_limits", index, "feature_id"],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
featureIds.add(spendLimit.feature_id);
|
||||
}
|
||||
});
|
||||
|
||||
export type AutoTopupPurchaseLimit = z.infer<
|
||||
typeof AutoTopupPurchaseLimitSchema
|
||||
>;
|
||||
@@ -55,9 +81,13 @@ export type CustomerBillingControls = z.infer<
|
||||
typeof CustomerBillingControlsSchema
|
||||
>;
|
||||
|
||||
export type CustomerBillingControlsInput = z.input<
|
||||
typeof CustomerBillingControlsSchema
|
||||
export type CustomerBillingControlsParams = z.input<
|
||||
typeof CustomerBillingControlsParamsSchema
|
||||
>;
|
||||
|
||||
export { EntityBillingControlsSchema, DbSpendLimitSchema };
|
||||
export type { EntityBillingControls, EntityBillingControlsInput, DbSpendLimit };
|
||||
export type {
|
||||
EntityBillingControls,
|
||||
EntityBillingControlsParams,
|
||||
DbSpendLimit,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user