import {z} from 'zod' export type GetApiBillingGroupBillingGroupIdInvoiceInvoiceNumberLinesArgs = {billing_group_id: string, invoice_number: string}; export type GetApiBillingGroupBillingGroupIdInvoiceInvoiceNumberLinesOptions = {baseUrl?: string | undefined, tokenAuth?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const billingGroupInvoiceLinesListResponse = z.object({errors: z.array(z.object({message: z.string(), more_info: z.string().optional(), status: z.number().int()})).optional(), lines: z.array(z.object({cloud_name: z.string().optional(), commitment_name: z.string().optional(), description: z.string(), line_pre_discount_local: z.string().optional(), line_total_local: z.string().optional(), line_total_usd: z.string(), line_type: z.enum(["commitment_fee", "credit_consumption", "extra_charge", "multiplier", "other_event", "pro_platform_charge", "rounding", "service_charge", "support_charge"]), local_currency: z.string().optional(), project_name: z.string().optional(), service_name: z.string().optional(), service_plan: z.string().optional(), service_type: z.enum(["alert_triage", "alertmanager", "application", "clickhouse", "datahub", "elasticsearch", "flink", "grafana", "kafka", "kafka_connect", "kafka_mirrormaker", "mysql", "nomadclient", "opensearch", "pg", "sandbox", "sandbox_api", "sparkpool", "stresstester", "sw", "thanos", "thanoscompactor", "thanosparquet", "thanosquery", "thanosreceiver", "thanosruler", "thanosstore", "valkey", "vector", "vmalert"]).optional(), tags: z.object({}).optional(), timestamp_begin: z.string().optional(), timestamp_end: z.string().optional()})).optional(), message: z.string().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 invoice lines for a single invoice * * GET /billing-group/{billing_group_id}/invoice/{invoice_number}/lines */ export const getApiBillingGroupBillingGroupIdInvoiceInvoiceNumberLines = async (args: GetApiBillingGroupBillingGroupIdInvoiceInvoiceNumberLinesArgs, options?: GetApiBillingGroupBillingGroupIdInvoiceInvoiceNumberLinesOptions) => { const {baseUrl = "https://api.aiven.io/v1", fetch: fetchFn = fetch, tokenAuth, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (tokenAuth !== undefined) headers.set('authorization', `Bearer ${tokenAuth}`) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/billing-group/${encodeURIComponent(String(args.billing_group_id))}/invoice/${encodeURIComponent(String(args.invoice_number))}/lines${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(billingGroupInvoiceLinesListResponse, await res.json()) };