Files
cfw-autumn/shared/api/balances/check/checkResponseV3.ts
2026-05-06 18:30:07 +08:00

53 lines
1.8 KiB
TypeScript

import { ApiFlagV0Schema } from "@api/models.js";
import { z } from "zod/v4";
import { ApiBalanceV1Schema } from "../../customers/cusFeatures/apiBalanceV1.js";
import { CheckFeaturePreviewSchema } from "./checkFeaturePreview.js";
/**
* Check response V3 - uses ApiBalanceV1 (V2.1 format)
* This is the server's internal response format
*/
export const CheckResponseV3Schema = z.object({
allowed: z.boolean().meta({
description:
"Whether the customer is allowed to use the feature. True if they have sufficient balance or the feature is unlimited/boolean.",
}),
customer_id: z.string().meta({
description: "The ID of the customer that was checked.",
}),
entity_id: z.string().nullish().meta({
description:
"The ID of the entity, if an entity-scoped check was performed.",
}),
required_balance: z.number().optional().meta({
description: "The required balance that was checked against.",
}),
balance: ApiBalanceV1Schema.nullable().meta({
description:
"The customer's balance for this feature. Null if the customer has no balance for this feature.",
}),
balances: z
.record(z.string(), ApiBalanceV1Schema.nullable())
.optional()
.meta({
description:
"Map of feature_id to balance for the checked feature and any related features (e.g. linked credit systems). ",
}),
flag: ApiFlagV0Schema.nullable().meta({
description: "The flag associated with this check, if any.",
}),
// lock_id: z.string().optional().meta({
// description:
// "The lock ID associated with this check when lock mode is enabled.",
// }),
preview: CheckFeaturePreviewSchema.optional().meta({
description:
"Upgrade/upsell information when access is denied. Only present if with_preview was true and allowed is false.",
}),
});
export type CheckResponseV3 = z.infer<typeof CheckResponseV3Schema>;