import {z} from 'zod' export type GetApiV1EnterpriseTeamsTeamIdBillingArgs = {team_id: number}; export type GetApiV1EnterpriseTeamsTeamIdBillingOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const teamPaymentMethodInfo = z.object({card_brand: z.string().nullable().optional(), card_last4: z.string().nullable().optional(), expiry_month: z.string().nullable().optional(), expiry_year: z.string().nullable().optional(), title: z.string().nullable().optional(), added_at: z.string().nullable().optional()}); export const teamBillingInfo = z.object({id: z.number().int(), team_id: z.number().int(), plan_name: z.string(), price_per_seat: z.number(), base_credits_per_seat: z.number(), currency: z.string(), billing_cycle: z.string(), active_seats: z.number().int(), is_active: z.boolean(), subscription_start: z.string(), current_period_start: z.string(), current_period_end: z.string(), next_billing_date: z.string(), monthly_cost: z.number(), yearly_cost: z.number(), total_base_credits: z.number(), period_active: z.boolean().optional(), billed_online: z.boolean().optional(), period_price_per_seat: z.number().optional(), period_cost: z.number().optional(), payment_method: teamPaymentMethodInfo.nullable().optional(), auto_renew: z.boolean().optional(), next_charge_at: z.string().nullable().optional(), charge_pending: z.boolean().optional(), last_charge_failed_at: z.string().nullable().optional(), last_charge_error: z.string().nullable().optional(), charge_attempts_left: z.number().int().optional(), card_check_amount: z.number().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get Team Billing Info * * GET /v1/enterprise/teams/{team_id}/billing */ export const getApiV1EnterpriseTeamsTeamIdBilling = async (args: GetApiV1EnterpriseTeamsTeamIdBillingArgs, options: GetApiV1EnterpriseTeamsTeamIdBillingOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/enterprise/teams/${encodeURIComponent(String(args.team_id))}/billing${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(teamBillingInfo, await res.json()) };