import {z} from 'zod' export type IsoDatetime = string; export type Currency = string; export type CbfRow = {'lineitem/id'?: string | undefined, 'lineitem/type'?: ('Usage' | 'Tax' | 'Support' | 'Purchase' | 'CommittedUsePurchase' | 'Discount' | 'Credit' | 'Fee' | 'Adjustment') | undefined, 'lineitem/description'?: string | undefined, 'time/usage_start': IsoDatetime, 'time/usage_end'?: IsoDatetime | undefined, 'resource/id'?: string | undefined, 'resource/service'?: string | undefined, 'resource/account'?: string | undefined, 'resource/region'?: string | undefined, 'resource/usage_family'?: string | undefined, 'action/operation'?: string | undefined, 'action/usage_type'?: string | undefined, 'action/region'?: string | undefined, 'action/account'?: string | undefined, 'usage/amount'?: string | undefined, 'usage/units'?: string | undefined, 'cost/cost': Currency, 'cost/discounted_cost'?: Currency | undefined, 'cost/amortized_cost'?: Currency | undefined, 'cost/discounted_amortized_cost'?: Currency | undefined, 'cost/on_demand_cost'?: Currency | undefined, 'bill/invoice_id'?: string | undefined, 'k8s/cluster'?: string | undefined, 'k8s/namespace'?: string | undefined, 'k8s/deployment'?: string | undefined, 'k8s/labels'?: string | undefined}; export type AnycostStreamConnectionBillingDrop = {month?: IsoDatetime | undefined, operation?: ('replace_drop' | 'replace_hourly' | 'sum') | undefined, data: Array}; export type CreateApiV2ConnectionsBillingAnycostConnectionIdBillingDropsArgs = {'cloudzero-idempotency-key'?: string | undefined, 'cloudzero-test-key'?: string | undefined, connection_id: string, body: AnycostStreamConnectionBillingDrop}; export type CreateApiV2ConnectionsBillingAnycostConnectionIdBillingDropsOptions = {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 createApiV2ConnectionsBillingAnycostConnectionIdBillingDropsResponse = z.object({connection: anycostStreamConnectionBillingDropSummary.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 }; /** * Create a single AnyCost Stream Connection Billing Drop. * * POST /v2/connections/billing/anycost/{connection_id}/billing_drops */ export const createApiV2ConnectionsBillingAnycostConnectionIdBillingDrops = async (args: CreateApiV2ConnectionsBillingAnycostConnectionIdBillingDropsArgs, options?: CreateApiV2ConnectionsBillingAnycostConnectionIdBillingDropsOptions) => { const {baseUrl = "https://api.cloudzero.com", fetch: fetchFn = fetch, APIKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiV2ConnectionsBillingAnycostConnectionIdBillingDropsResponse, await res.json()) };