42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { ApiBalanceV1Schema } from "@api/customers/cusFeatures/apiBalanceV1.js";
|
|
import { ApiFlagV0Schema } from "@api/customers/flags/apiFlagV0.js";
|
|
import { z } from "zod/v4";
|
|
import { ApiEntityBillingControlsSchema } from "../billingControls/entityBillingControls.js";
|
|
import {
|
|
ApiPurchaseV0Schema,
|
|
ApiSubscriptionV1Schema,
|
|
} from "../customers/cusPlans/apiSubscriptionV1.js";
|
|
import { ApiInvoiceV1Schema } from "../others/apiInvoice/apiInvoiceV1.js";
|
|
import { ApiBaseEntitySchema } from "./apiBaseEntity.js";
|
|
|
|
// V2 base entity - uses V1 subscriptions (single array with status field)
|
|
export const BaseApiEntityV2Schema = ApiBaseEntitySchema.extend({
|
|
subscriptions: z.array(ApiSubscriptionV1Schema),
|
|
purchases: z.array(ApiPurchaseV0Schema),
|
|
balances: z.record(z.string(), ApiBalanceV1Schema),
|
|
flags: z.record(z.string(), ApiFlagV0Schema),
|
|
billing_controls: ApiEntityBillingControlsSchema.optional().meta({
|
|
description: "Billing controls for the entity.",
|
|
}),
|
|
});
|
|
|
|
export const ApiEntityExpandSchema = z.object({
|
|
invoices: z
|
|
.array(ApiInvoiceV1Schema)
|
|
.optional()
|
|
.meta({
|
|
description:
|
|
"Invoices for this entity (only included when expand=invoices)",
|
|
})
|
|
.meta({
|
|
internal: true,
|
|
}),
|
|
});
|
|
|
|
export const ApiEntityV2Schema = BaseApiEntityV2Schema.extend(
|
|
ApiEntityExpandSchema.shape,
|
|
);
|
|
|
|
export type ApiEntityV2 = z.infer<typeof ApiEntityV2Schema>;
|
|
export type BaseApiEntityV2 = z.infer<typeof BaseApiEntityV2Schema>;
|