Files
cfw-autumn/shared/api/entities/apiEntity.ts
2025-11-11 16:01:14 +00:00

54 lines
1.7 KiB
TypeScript

import { ApiBalanceSchema } from "@api/customers/cusFeatures/apiBalance.js";
import { ApiSubscriptionSchema } from "@api/customers/cusPlans/apiSubscription.js";
import { ApiInvoiceSchema } from "@api/others/apiInvoice.js";
import { AppEnv } from "@models/genModels/genEnums.js";
import { z } from "zod/v4";
const entityDescriptions = {
id: "The unique identifier of the entity",
name: "The name of the entity",
customer_id: "The customer ID this entity belongs to",
feature_id: "The feature ID this entity belongs to",
created_at: "Unix timestamp when the entity was created",
env: "The environment (sandbox/live)",
};
export const ApiBaseEntitySchema = z.object({
autumn_id: z.string().optional(),
id: z.string().nullable().meta({
description: entityDescriptions.id,
}),
name: z.string().nullable().meta({
description: entityDescriptions.name,
}),
customer_id: z.string().nullish().meta({
description: entityDescriptions.customer_id,
}),
feature_id: z.string().nullish().meta({
description: entityDescriptions.feature_id,
}),
created_at: z.number().meta({
description: entityDescriptions.created_at,
}),
env: z.enum(AppEnv).meta({
description: entityDescriptions.env,
}),
});
export const ApiEntitySchema = ApiBaseEntitySchema.extend({
subscriptions: z.array(ApiSubscriptionSchema).optional().meta({
description: "Plans associated with this entity",
example: [],
}),
balances: z.record(z.string(), ApiBalanceSchema).optional().meta({
description: "Features associated with this entity",
}),
invoices: z.array(ApiInvoiceSchema).optional().meta({
description:
"Invoices for this entity (only included when expand=invoices)",
}),
});
export type ApiEntity = z.infer<typeof ApiEntitySchema>;