import {z} from 'zod' export type GetApiV2ConnectionsBillingAnycostConnectionIdBillingDropsArgs = {'cloudzero-idempotency-key'?: string | undefined, 'cloudzero-test-key'?: string | undefined, connection_id: string}; export type GetApiV2ConnectionsBillingAnycostConnectionIdBillingDropsOptions = {baseUrl?: string | undefined, APIKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const isoDatetime = z.string(); export const anycostStreamConnectionBillingDropSummary = z.object({drop_id: z.string().optional(), month: isoDatetime.optional(), row_count: z.number().int().optional()}); export const anycostStreamConnectionBillingDropSummaries = z.array(anycostStreamConnectionBillingDropSummary); export const getApiV2ConnectionsBillingAnycostConnectionIdBillingDropsResponse = z.object({billing_drops: anycostStreamConnectionBillingDropSummaries.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 all AnyCost Stream Connection Billing Drops * * GET /v2/connections/billing/anycost/{connection_id}/billing_drops */ export const getApiV2ConnectionsBillingAnycostConnectionIdBillingDrops = async (args: GetApiV2ConnectionsBillingAnycostConnectionIdBillingDropsArgs, options?: GetApiV2ConnectionsBillingAnycostConnectionIdBillingDropsOptions) => { 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 (APIKeyAuth !== undefined) headers.set("Authorization", APIKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v2/connections/billing/anycost/${encodeURIComponent(String(args.connection_id))}/billing_drops${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(getApiV2ConnectionsBillingAnycostConnectionIdBillingDropsResponse, await res.json()) };