import {z} from 'zod' export type IsoDatetime = string; export type GetApiV2ConnectionsBillingAnycostConnectionIdBillingDropsMonthArgs = {'cloudzero-idempotency-key'?: string | undefined, 'cloudzero-test-key'?: string | undefined, connection_id: string, month: IsoDatetime, limit?: number | undefined, page_token?: string | undefined}; export type GetApiV2ConnectionsBillingAnycostConnectionIdBillingDropsMonthOptions = {baseUrl?: string | undefined, APIKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const isoDatetime = z.string(); export const currency = z.string(); export const cbfRow = z.object({"lineitem/id": z.string().optional(), "lineitem/type": z.enum(["Usage", "Tax", "Support", "Purchase", "CommittedUsePurchase", "Discount", "Credit", "Fee", "Adjustment"]).optional(), "lineitem/description": z.string().optional(), "time/usage_start": isoDatetime, "time/usage_end": isoDatetime.optional(), "resource/id": z.string().optional(), "resource/service": z.string().optional(), "resource/account": z.string().optional(), "resource/region": z.string().optional(), "resource/usage_family": z.string().optional(), "action/operation": z.string().optional(), "action/usage_type": z.string().optional(), "action/region": z.string().optional(), "action/account": z.string().optional(), "usage/amount": z.string().optional(), "usage/units": z.string().optional(), "cost/cost": currency, "cost/discounted_cost": currency.optional(), "cost/amortized_cost": currency.optional(), "cost/discounted_amortized_cost": currency.optional(), "cost/on_demand_cost": currency.optional(), "bill/invoice_id": z.string().optional(), "k8s/cluster": z.string().optional(), "k8s/namespace": z.string().optional(), "k8s/deployment": z.string().optional(), "k8s/labels": z.string().optional()}); export const getApiV2ConnectionsBillingAnycostConnectionIdBillingDropsMonthResponse = z.object({billing_drop: z.array(cbfRow).optional(), next_page_token: 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 }; /** * Retrieve billing drop contents for a specific month. * * GET /v2/connections/billing/anycost/{connection_id}/billing_drops/{month} */ export const getApiV2ConnectionsBillingAnycostConnectionIdBillingDropsMonth = async (args: GetApiV2ConnectionsBillingAnycostConnectionIdBillingDropsMonthArgs, options?: GetApiV2ConnectionsBillingAnycostConnectionIdBillingDropsMonthOptions) => { const {baseUrl = "https://api.cloudzero.com", fetch: fetchFn = fetch, APIKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['cloudzero-idempotency-key'] != null) headers.set("cloudzero-idempotency-key", String(args['cloudzero-idempotency-key'])) if (args['cloudzero-test-key'] != null) headers.set("cloudzero-test-key", String(args['cloudzero-test-key'])) if (args.limit != null) query.append("limit", String(args.limit)) if (args.page_token != null) query.append("page_token", String(args.page_token)) if (APIKeyAuth !== undefined) headers.set("Authorization", APIKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v2/connections/billing/anycost/${encodeURIComponent(String(args.connection_id))}/billing_drops/${encodeURIComponent(String(args.month))}${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(getApiV2ConnectionsBillingAnycostConnectionIdBillingDropsMonthResponse, await res.json()) };