import {z} from 'zod' export type GetApiBillingPhoneRentalSubscriptionsArgs = {limit?: number | undefined, offset?: number | undefined, search?: string | undefined, status?: (Array<'active' | 'canceled'> | null) | undefined, plan_interval?: (Array<'day' | 'week' | 'month' | 'year'> | null) | undefined, cancel_at_period_end?: ('true' | 'false') | undefined, payment_status?: (Array<'healthy' | 'past_due'> | null) | undefined, current_period_end_after?: string | undefined, current_period_end_before?: string | undefined, order_by?: string | undefined}; export type GetApiBillingPhoneRentalSubscriptionsOptions = {baseUrl: string, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const phoneRentalSubscriptionResponse = z.object({cancel_at_period_end: z.boolean(), canceled_at: z.string().optional(), current_period_end_at: z.string(), current_period_start_at: z.string(), id: z.string(), organization_id: z.string(), payment_status: z.enum(["healthy", "past_due"]), phone_id: z.string().optional(), phone_name: z.string().optional(), phone_nickname: z.string().optional(), plan_id: z.string(), plan_interval: z.enum(["day", "week", "month", "year"]), plan_name: z.string(), plan_price_microdollars: z.number().int(), status: z.enum(["active", "canceled"])}); export const phoneRentalIntervalSummary = z.object({count: z.number().int(), interval: z.enum(["day", "week", "month", "year"]), monthly_microdollars: z.number().int()}); export const phoneRentalUpcomingCharge = z.object({amount_microdollars: z.number().int(), count: z.number().int(), due_at: z.string()}); export const phoneRentalSummary = z.object({active_count: z.number().int(), combined_monthly_microdollars: z.number().int(), per_interval: z.array(phoneRentalIntervalSummary).nullable(), upcoming_charges: z.array(phoneRentalUpcomingCharge).nullable()}); export const phoneRentalSubscriptionListResponse = z.object({$schema: z.string().optional(), subscriptions: z.array(phoneRentalSubscriptionResponse).nullable(), summary: phoneRentalSummary, total: z.number().int()}); 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 }; /** * List phone rentals * * GET /billing/phone-rental-subscriptions */ export const getApiBillingPhoneRentalSubscriptions = async (args: GetApiBillingPhoneRentalSubscriptionsArgs, options: GetApiBillingPhoneRentalSubscriptionsOptions) => { const {baseUrl, fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.search != null) query.append("search", String(args.search)) if (args.status != null) query.append("status", args.status.join(',')) if (args.plan_interval != null) query.append("plan_interval", args.plan_interval.join(',')) if (args.cancel_at_period_end != null) query.append("cancel_at_period_end", String(args.cancel_at_period_end)) if (args.payment_status != null) query.append("payment_status", args.payment_status.join(',')) if (args.current_period_end_after != null) query.append("current_period_end_after", String(args.current_period_end_after)) if (args.current_period_end_before != null) query.append("current_period_end_before", String(args.current_period_end_before)) if (args.order_by != null) query.append("order_by", String(args.order_by)) if (apiKeyAuth !== undefined) headers.set("X-Axilio-Api-Key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/billing/phone-rental-subscriptions${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(phoneRentalSubscriptionListResponse, await res.json()) };