import {z} from 'zod' export type GetApiManagementV1InfoOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const consoleInfo = z.object({"commit-sha": z.string().nullable().optional(), edition: z.string(), version: z.string()}); export const licenseStatus = z.object({audience: z.string().nullable().optional(), customer: z.string().nullable().optional(), error: z.string().nullable().optional(), expiration: z.string().nullable().optional(), issuer: z.string().nullable().optional(), "license-id": z.string().nullable().optional(), "license-type": z.string(), valid: z.boolean()}); export const serverInfo = z.object({"authz-backend": z.string(), "aws-system-identities-enabled": z.boolean(), "azure-system-identities-enabled": z.boolean(), bootstrapped: z.boolean(), console: consoleInfo.nullable().optional(), "default-project-id": z.string().nullable().optional(), "gcp-system-identities-enabled": z.boolean(), "lakekeeper-commit-sha": z.string().nullable().optional(), "lakekeeper-enterprise-commit-sha": z.string().nullable().optional(), "lakekeeper-enterprise-version": z.string().nullable().optional(), "lakekeeper-version": z.string(), "license-status": licenseStatus, queues: z.array(z.string()), "server-id": z.string(), version: z.string()}); 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 Server Info * * GET /management/v1/info */ export const getApiManagementV1Info = async (options?: GetApiManagementV1InfoOptions) => { const {baseUrl = "https://localhost", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/management/v1/info${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(serverInfo, await res.json()) };