import {z} from 'zod' export type ClinVarLiteExportRequest = {variant_idx: number, hgvs_name: string, rationale: string, evidence_codes?: Array | undefined, mode_of_inheritance: string, expert_review_confirmed: boolean, hgvs_validated: boolean, expected_classification: 'P' | 'LP' | 'VUS' | 'LB' | 'B', condition_id_type?: (string | null) | undefined, condition_id_value?: (string | null) | undefined, preferred_condition_name?: (string | null) | undefined, collection_method?: string | undefined, allele_origin?: string | undefined, affected_status?: string | undefined, number_of_individuals: number, citations?: Array | undefined, gene_symbol?: (string | null) | undefined, local_id?: (string | null) | undefined, public_url?: (string | null) | undefined, variation_identifiers?: Array | undefined, alternate_designations?: Array | undefined, clinvar_accession?: (string | null) | undefined, record_status?: ('novel' | 'update' | null) | undefined}; export type CreateApiSessionsSessionIdClinvarLiteExportArgs = {session_id: string, body: ClinVarLiteExportRequest}; export type CreateApiSessionsSessionIdClinvarLiteExportOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const clinVarLiteExportResponse = z.object({package_name: z.string(), package_base64: z.string(), upload_files: z.array(z.string()), manifest: z.record(z.string(), z.unknown())}); 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 }; /** * Export one expert-reviewed variant as a ClinVar Lite package * * POST /sessions/{session_id}/clinvar-lite/export */ export const createApiSessionsSessionIdClinvarLiteExport = async (args: CreateApiSessionsSessionIdClinvarLiteExportArgs, options: CreateApiSessionsSessionIdClinvarLiteExportOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/sessions/${encodeURIComponent(String(args.session_id))}/clinvar-lite/export${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(clinVarLiteExportResponse, await res.json()) };