import {z} from 'zod' export type GetApiV1WorkspacesWorkspaceRegistriesRegistryIdArgs = {registry_id: string, workspace: string}; export type GetApiV1WorkspacesWorkspaceRegistriesRegistryIdOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const registryResponse = z.object({created_at: z.string(), credentials_secret_id: z.string().nullable().optional(), description: z.string().nullable(), id: z.string(), is_active: z.boolean(), item_count: z.number().int(), last_sync_error: z.string().nullable(), last_synced_at: z.string().nullable(), mode: z.enum(["mirror", "upstream"]), name: z.string(), recommendation_priority: z.number().int(), registry_type: z.string(), scope: z.enum(["platform", "workspace"]), source_path: z.string().nullable().optional(), source_ref: z.string().nullable().optional(), source_type: z.string(), source_url: z.string(), trust: z.enum(["official", "verified", "community", "private"]), updated_at: z.string(), workspace_id: z.string().nullable().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 Registry * * GET /v1/workspaces/{workspace}/registries/{registry_id} */ export const getApiV1WorkspacesWorkspaceRegistriesRegistryId = async (args: GetApiV1WorkspacesWorkspaceRegistriesRegistryIdArgs, options: GetApiV1WorkspacesWorkspaceRegistriesRegistryIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/workspaces/${encodeURIComponent(String(args.workspace))}/registries/${encodeURIComponent(String(args.registry_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(registryResponse, await res.json()) };