import {z} from 'zod' export type GetApiApiV1AdminMeteringReportsArgs = {start_after?: string | undefined, max_keys?: number | undefined}; export type GetApiApiV1AdminMeteringReportsOptions = {baseUrl: string, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const meteringReport = z.object({lastModified: z.string().optional(), name: z.string().optional(), size: z.number().int().optional()}); export const getApiApiV1AdminMeteringReportsResponse = z.array(meteringReport); 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 metering reports. Only available in Kubermatic Enterprise Edition * * GET /api/v1/admin/metering/reports */ export const getApiApiV1AdminMeteringReports = async (args: GetApiApiV1AdminMeteringReportsArgs, options: GetApiApiV1AdminMeteringReportsOptions) => { const {baseUrl, fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.start_after != null) query.append("start_after", String(args.start_after)) if (args.max_keys != null) query.append("max_keys", String(args.max_keys)) if (apiKey !== undefined) headers.set("Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/admin/metering/reports${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(getApiApiV1AdminMeteringReportsResponse, await res.json()) };