import {z} from 'zod' export type GetApiWorkspacesWorkspaceNameArgs = {workspaceName: string, countResources?: boolean | undefined}; export type GetApiWorkspacesWorkspaceNameOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const groupWorkspaceMapping = z.object({groupName: z.string().optional(), role: z.enum(["admin", "member"]).optional()}); export const workspaceHipaaUnsafe = z.object({enabled: z.boolean().optional(), updatedAt: z.string().optional(), updatedBy: z.string().optional()}); export const workspaceHipaaInfo = z.object({accountEnabled: z.boolean().optional(), unsafe: workspaceHipaaUnsafe.optional()}); export const metadataLabels = z.record(z.string(), z.string()); export const workspaceSandboxSettings = z.object({disableProcessLogging: z.boolean().optional()}); export const workspaceRuntime = z.object({generation: z.string().optional(), sandbox: workspaceSandboxSettings.optional()}); export const workspace = z.object({createdAt: z.string().optional(), updatedAt: z.string().optional(), createdBy: z.string().optional(), updatedBy: z.string().optional(), accountId: z.string().optional(), displayName: z.string().optional(), groupMappings: z.array(groupWorkspaceMapping).optional(), hipaaInfo: workspaceHipaaInfo.optional(), id: z.string().optional(), labels: metadataLabels.optional(), name: z.string().optional(), region: z.string().optional(), resourceCounts: z.record(z.string(), z.number().int()).optional(), runtime: workspaceRuntime.optional(), status: z.enum(["created", "account_binded", "account_configured", "workspace_configured", "ready", "error"]).optional(), statusReason: 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 workspace details * * GET /workspaces/{workspaceName} * * Also accepts auth: ApiKeyAuth */ export const getApiWorkspacesWorkspaceName = async (args: GetApiWorkspacesWorkspaceNameArgs, options?: GetApiWorkspacesWorkspaceNameOptions) => { const {baseUrl = "https://api.blaxel.ai/v0", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.countResources != null) query.append("countResources", String(args.countResources)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/workspaces/${encodeURIComponent(String(args.workspaceName))}${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(workspace, await res.json()) };