import {z} from 'zod' export type GetApiV1AccountsAccountIdClustersClusterIdArgs = {readMask?: string | undefined, account_id: string, cluster_id: string}; export type GetApiV1AccountsAccountIdClustersClusterIdOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const gatewayEksCluster = z.object({awsAccountId: z.string(), fireworksManagerRole: z.string().optional(), region: z.string(), clusterName: z.string().optional(), storageBucketName: z.string().optional(), metricWriterRole: z.string().optional(), loadBalancerControllerRole: z.string().optional(), workloadIdentityPoolProviderId: z.string().optional(), inferenceRole: z.string().optional()}); export const gatewayFakeCluster = z.object({projectId: z.string().optional(), location: z.string().optional(), clusterName: z.string().optional()}); export const gatewayClusterState = z.enum(["STATE_UNSPECIFIED", "CREATING", "READY", "DELETING", "FAILED"]); export const gatewayCode = z.enum(["OK", "CANCELLED", "UNKNOWN", "INVALID_ARGUMENT", "DEADLINE_EXCEEDED", "NOT_FOUND", "ALREADY_EXISTS", "PERMISSION_DENIED", "UNAUTHENTICATED", "RESOURCE_EXHAUSTED", "FAILED_PRECONDITION", "ABORTED", "OUT_OF_RANGE", "UNIMPLEMENTED", "INTERNAL", "UNAVAILABLE", "DATA_LOSS"]); export const gatewayStatus = z.object({code: gatewayCode.optional(), message: z.string().optional()}); export const gatewayCluster = z.object({name: z.string().optional(), displayName: z.string().optional(), createTime: z.string().optional(), eksCluster: gatewayEksCluster.optional(), fakeCluster: gatewayFakeCluster.optional(), state: gatewayClusterState.optional(), status: gatewayStatus.optional(), updateTime: 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 }; /** * Get Cluster * * GET /v1/accounts/{account_id}/clusters/{cluster_id} */ export const getApiV1AccountsAccountIdClustersClusterId = async (args: GetApiV1AccountsAccountIdClustersClusterIdArgs, options: GetApiV1AccountsAccountIdClustersClusterIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.readMask != null) query.append("readMask", String(args.readMask)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args.account_id))}/clusters/${encodeURIComponent(String(args.cluster_id))}${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(gatewayCluster, await res.json()) };