import {z} from 'zod' export type DeliveryType = 'pdf' | 'xml' | 'json'; export type DeliveryFormat = 'individual' | 'zipped'; export type DeliveryFrequency = 'continuous' | 'daily' | 'weekly' | 'biweekly' | 'monthly' | 'order_due_date' | 'each_document'; export type DeliveryFrequencyDay = 0 | 1 | 2 | 3 | 4 | 5 | 6; export type DeliveryTiming = 'continuous' | 'scheduled'; export type DeliveryLocation = 'api' | 'sftp' | 's3'; export type DailyDeliveryOptions = {delivery_frequency_sub_option: unknown, delivery_frequency: 'daily'}; export type WeeklyDeliveryOptions = {delivery_frequency_sub_option: Array, delivery_frequency: 'weekly'}; export type BiweeklyDeliveryOptions = {delivery_frequency_sub_option: Array, delivery_frequency: 'biweekly'}; export type MonthlyDeliveryOptions = {delivery_frequency_sub_option: number, delivery_frequency: 'monthly'}; export type DueDateDeliveryOptions = {delivery_frequency_sub_option: unknown, delivery_frequency: 'order_due_date'}; export type EachDocumentDeliveryOptions = {delivery_frequency_sub_option: unknown, delivery_frequency: 'each_document'}; export type StructuredDataExtractionReportConfiguration = {delivery_schedule?: Array | undefined, deliver_automatically?: boolean | undefined, delivery_schedule_options?: (DailyDeliveryOptions | WeeklyDeliveryOptions | BiweeklyDeliveryOptions | MonthlyDeliveryOptions | DueDateDeliveryOptions | EachDocumentDeliveryOptions) | undefined, filename_prefix: string, include_npi?: boolean | undefined, include_diagnosis?: boolean | undefined, filter_encounters_by_requested_dos?: boolean | undefined, write_empty_encounters?: boolean | undefined}; export type ChartDetailExtractConfiguration = {delivery_schedule?: Array | undefined, deliver_automatically?: boolean | undefined, delivery_schedule_options?: (DailyDeliveryOptions | WeeklyDeliveryOptions | BiweeklyDeliveryOptions | MonthlyDeliveryOptions | DueDateDeliveryOptions | EachDocumentDeliveryOptions) | undefined, filename_template: string}; export type RequesterType = 'attorney' | 'datavant' | 'disability' | 'continuing_care' | 'copya' | 'copyi' | 'facility' | 'government' | 'insurance' | 'patient' | 'payd' | 'payi' | 'pro' | 'fac'; export type PrimaryReason = 'attorney' | 'hospital_lien' | 'patient_directive' | 'personal_injury' | 'social_security_disability' | 'subpoena' | 'workers_comp' | 'illinois_industrial_commission_subpoena' | 'florida_statute' | 'veterans_disability' | 'ssa_appeal_representative_form_1696' | 'patient_social_security_appeal' | 'life_sciences' | 'audit_of_claims' | 'clinical_research' | 'disability' | 'insurance' | 'medicare_medicaid' | 'rac' | 'revenue_cycle_management' | 'business_office_copy_risk_management' | 'special_project' | 'drg_payment_integrity' | 'hedis_audit' | 'hix' | 'radv' | 'standard_insurance_claim_payment' | 'utilization_review' | 'disability_gov_benefits' | 'forms_completion_by_provider' | 'patient_personal' | 'patient_transfer' | 'second_request_not_work_comp' | 'agency' | 'government_audit' | 'medicaid_dds' | 'non_profit' | 'state_dds' | 'workers_comp_board' | 'continuity_of_care' | 'ciox_audit' | 'mra' | 'ciox_real_world_data_team_request' | 'aca_hix' | 'drg' | 'underwriting' | 'claim' | 'general_attorney' | 'general_attorney_subpoena' | 'workers_comp_subpoena' | 'ssa_appeal' | 'pro_medicaid' | 'standard_pro' | 'value_based_care' | 'payd' | 'payer' | 'attestation' | 'unknown'; export type SecondaryReason = 'aca' | 'defense_attorney' | 'defense_subpoena' | 'personal_injury' | 'state_attorney_office' | 'represent_indignant' | 'subpoena_second_request' | 'disability_gov_benefits' | 'ssi_claim_second_request' | 'hospital_per_admission' | 'no' | 'second_request' | 'social_security_appeal' | 'patient_social_security_appeal' | 'social_security_claim_appeal_second_request' | 'forms_completion_by_provider' | 'attorney_rep_pat' | 'appeal_second_request' | 'court_issued' | 'criminal' | 'subpoena' | 'workers_comp_subpoena' | 'subpoena_deposition_trial_testimony_with_records' | 'workers_comp_second_request' | 'workers_comp' | 'workers_comp_self_insured' | 'requested_by_patient' | 'requested_by_attorney' | 'drg_payment_integrity' | 'hedis_audit' | 'hix' | 'mra' | 'radv' | 'utilization_review' | 'short_term_long_term_claim' | 'second_request_insurance' | 'bc_bs_claim' | 'non_medical_insurance_claim' | 'standard_insurance_claim_payment' | 'underwriting' | 'pharmacy' | 'aps' | 'medicare_medicaid_utl_review' | 'medicare_medicaid_eligibility' | 'rac_medicaid' | 'second_request_workers_comp' | 'standard_workers_comp' | 'county' | 'dept_of_health_human_services' | 'dept_of_welfare' | 'family_and_child' | 'omap' | 'probation' | 'public_schools' | 'social_security_application' | 'veterans_affairs' | 'voc_rehab' | 'mi_family' | 'nc_prison' | 'attorney_general' | 'state_attorney' | 'federal_public_defender' | 'utilization_review_medicare_and_medicaid' | 'home_risk_assessment' | 'in_office_assessment' | 'payment_integrity' | 'post_payment_denials' | 'pre_payment_denials' | 'provider_as_requester' | 'switchboard_for_acos' | 'whole_person_understanding'; export type Address = {normalizations?: Array | undefined, line1?: string | undefined, line2?: string | undefined, city?: string | undefined, country?: string | undefined, state?: string | undefined, postal_code?: string | undefined}; export type LegalEntity = {phone_number?: string | undefined, full_name?: string | undefined, first_name?: string | undefined, alternate_first_name?: string | undefined, middle_name?: string | undefined, last_name?: string | undefined, prefix?: string | undefined, suffix?: string | undefined, id: string, order_id?: string | undefined, address?: Address | undefined, health_plan?: string | undefined}; export type Contacts = {billing?: LegalEntity | undefined, customer?: LegalEntity | undefined}; export type RetrievalSources = 'api' | 'embedded_manual' | 'nonembedded_manual' | 'athena' | 'healthjump' | 'mock_retrieval' | 'moxe' | 'office_ally' | 'particle' | 'ses' | 'share_arkansas' | 'sidus' | 'veradigm' | 'vim' | 'iatric' | 'c3hie' | 'ghhc' | 'healow' | 'mdland'; export type AllowBlockGroup = {data_foundation_health_system_ids?: Array | undefined}; export type RetrievalAllowBlockConfiguration = {allow?: AllowBlockGroup | undefined, block?: AllowBlockGroup | undefined}; export type SubmissionSource = 'api' | 'switchboard' | 'sftp' | 'legacy'; export type Mail = {method: 'mail', entity: LegalEntity}; export type Sftp = {method: 'sftp', entity: LegalEntity}; export type AlternateDelivery = {alternate?: (Mail | Sftp) | undefined, use_only_alternate?: boolean | undefined}; export type FileRetrievalMethodEnum = 'http' | 'cdr'; export type FileLocation = {url: string}; export type CDRLocation = {uuid: string}; export type ClientFile = {method: FileRetrievalMethodEnum, location: FileLocation | CDRLocation, line_count?: number | undefined, content_bytes?: number | undefined}; export type BirthDate = {year: string, month: string, day: string}; export type Gender = 'M' | 'F' | 'O' | 'U'; export type Insurance = {name?: string | undefined, plan?: string | undefined, group_id?: string | undefined, member_id?: string | undefined}; export type UserDefinedText = {text1?: string | undefined, text2?: string | undefined, text3?: string | undefined, text4?: string | undefined}; export type Patient = {phone_number?: string | undefined, full_name?: string | undefined, first_name?: string | undefined, alternate_first_name?: string | undefined, middle_name?: string | undefined, last_name?: string | undefined, prefix?: string | undefined, suffix?: string | undefined, address?: Address | undefined, email?: string | undefined, date_of_birth: BirthDate, gender?: Gender | undefined, ssn?: string | undefined, insurance?: Insurance | undefined, user_defined_text?: UserDefinedText | undefined, customer_member_id?: string | undefined, member_id?: string | undefined}; export type Practitioner = {fax_number?: string | undefined, phone_number?: string | undefined, full_name?: string | undefined, first_name?: string | undefined, last_name?: string | undefined, contact?: string | undefined, identifier?: Record | undefined}; export type FacilityType = 'INPATIENT' | 'OUTPATIENT'; export type Facility = {fax_number?: string | undefined, phone_number?: string | undefined, name?: string | undefined, address?: Address | undefined, identifier?: Record | undefined, roi_site_id?: string | undefined, group?: string | undefined, type?: FacilityType | undefined}; export type ServiceDates = {start: string, end?: string | undefined}; export type ChartComponent = 'Entire Record' | 'Abstract'; export type ChartPackage = 'Default'; export type Encounter = {practitioner?: Practitioner | undefined, facility?: Facility | undefined, additional_information?: Record | undefined, service_date_range: ServiceDates | Array, chart_components?: Array | undefined, chart_packages?: Array | undefined}; export type CreateOrderQueryRequest = {id: string, patient: Patient, encounters: Array}; export type CodingConfiguration = {deliver_records: boolean, deliver_only_codeable_records?: boolean | undefined, deliver_records_before_coding?: boolean | undefined}; export type ChartFinderConfiguration = {coding?: boolean | undefined, audit_type?: number | undefined, review_type?: (string | number) | undefined, idsb_handling_qa?: (0 | 1) | undefined, idsb_retrieving?: (0 | 1) | undefined, idsb_retrieving_embedded?: (0 | 1) | undefined, account_manager_id?: number | undefined}; export type FlowType = 'unknown' | 'patient' | 'provider' | 'prematch_provider'; export type ImportReviewStatus = {provider_package_approved?: boolean | undefined}; export type CreateOrderRequest = {delivery_type?: Array | undefined, delivery_format?: DeliveryFormat | undefined, structured_data_file_delivery_format?: DeliveryFormat | undefined, delivery_filename_template?: string | undefined, delivery_manifest_included?: boolean | undefined, delivery_manifest_filename_template?: string | undefined, delivery_manifest_file_extension?: ('.csv' | '.txt' | '.dat') | undefined, delivery_manifest_delimiter?: (',' | '|' | ' ') | undefined, delivery_zip_filename_template?: string | undefined, delivery_frequency?: DeliveryFrequency | undefined, delivery_frequency_sub_option?: (Array | number) | undefined, delivery_schedule?: Array | undefined, delivery_timing?: DeliveryTiming | undefined, delivery_location?: DeliveryLocation | undefined, delivery_email_recipients?: Array | undefined, delivery_manifest_configuration: unknown, zip_password?: string | undefined, merge_charts?: boolean | undefined, structured_data_extraction_report_configuration?: StructuredDataExtractionReportConfiguration | undefined, chart_detail_extract_report_configuration?: ChartDetailExtractConfiguration | undefined, id: string, name?: string | undefined, project_id?: string | undefined, type: RequesterType, due_date?: string | undefined, reason?: PrimaryReason | undefined, primary_reason?: PrimaryReason | undefined, secondary_reason?: SecondaryReason | undefined, metadata?: Record | undefined, contacts?: Contacts | undefined, sources?: Array | undefined, retrieval_sources?: Array | undefined, retrieval_allow_block_configuration?: RetrievalAllowBlockConfiguration | undefined, manual_qa?: boolean | undefined, coding_required?: boolean | undefined, coding_required_v2?: boolean | undefined, submission_source?: SubmissionSource | undefined, alternate_delivery?: AlternateDelivery | undefined, file?: ClientFile | undefined, queries?: Array | undefined, provider_information_included?: boolean | undefined, demand_id?: number | undefined, wave?: number | undefined, chart_review_year?: number | undefined, target_yield?: number | undefined, yield_type?: number | undefined, ticket_number?: string | undefined, coding_configuration?: CodingConfiguration | undefined, chart_finder_config?: ChartFinderConfiguration | undefined, is_traditional?: boolean | undefined, flow_type?: FlowType | undefined, import_review_status?: ImportReviewStatus | undefined}; export type CreateApiOrdersArgs = {'version-datavant'?: string | undefined, body: CreateOrderRequest}; export type CreateApiOrdersOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const deliveryType = z.enum(["pdf", "xml", "json"]); export const deliveryFormat = z.enum(["individual", "zipped"]); export const deliveryFrequency = z.enum(["continuous", "daily", "weekly", "biweekly", "monthly", "order_due_date", "each_document"]); export const deliveryFrequencyDay = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6)]); export const deliveryTiming = z.enum(["continuous", "scheduled"]); export const deliveryLocation = z.enum(["api", "sftp", "s3"]); export const dailyDeliveryOptions = z.object({delivery_frequency_sub_option: z.unknown(), delivery_frequency: z.literal("daily")}); export const weeklyDeliveryOptions = z.object({delivery_frequency_sub_option: z.array(deliveryFrequencyDay), delivery_frequency: z.literal("weekly")}); export const biweeklyDeliveryOptions = z.object({delivery_frequency_sub_option: z.array(deliveryFrequencyDay), delivery_frequency: z.literal("biweekly")}); export const monthlyDeliveryOptions = z.object({delivery_frequency_sub_option: z.number().int(), delivery_frequency: z.literal("monthly")}); export const dueDateDeliveryOptions = z.object({delivery_frequency_sub_option: z.unknown(), delivery_frequency: z.literal("order_due_date")}); export const eachDocumentDeliveryOptions = z.object({delivery_frequency_sub_option: z.unknown(), delivery_frequency: z.literal("each_document")}); export const structuredDataExtractionReportConfiguration = z.object({delivery_schedule: z.array(z.string()).optional(), deliver_automatically: z.boolean().optional(), delivery_schedule_options: z.discriminatedUnion("delivery_frequency", [dailyDeliveryOptions, weeklyDeliveryOptions, biweeklyDeliveryOptions, monthlyDeliveryOptions, dueDateDeliveryOptions, eachDocumentDeliveryOptions]).optional(), filename_prefix: z.string(), include_npi: z.boolean().optional(), include_diagnosis: z.boolean().optional(), filter_encounters_by_requested_dos: z.boolean().optional(), write_empty_encounters: z.boolean().optional()}); export const chartDetailExtractConfiguration = z.object({delivery_schedule: z.array(z.string()).optional(), deliver_automatically: z.boolean().optional(), delivery_schedule_options: z.discriminatedUnion("delivery_frequency", [dailyDeliveryOptions, weeklyDeliveryOptions, biweeklyDeliveryOptions, monthlyDeliveryOptions, dueDateDeliveryOptions, eachDocumentDeliveryOptions]).optional(), filename_template: z.string()}); export const requesterType = z.enum(["attorney", "datavant", "disability", "continuing_care", "copya", "copyi", "facility", "government", "insurance", "patient", "payd", "payi", "pro", "fac"]); export const primaryReason = z.enum(["attorney", "hospital_lien", "patient_directive", "personal_injury", "social_security_disability", "subpoena", "workers_comp", "illinois_industrial_commission_subpoena", "florida_statute", "veterans_disability", "ssa_appeal_representative_form_1696", "patient_social_security_appeal", "life_sciences", "audit_of_claims", "clinical_research", "disability", "insurance", "medicare_medicaid", "rac", "revenue_cycle_management", "business_office_copy_risk_management", "special_project", "drg_payment_integrity", "hedis_audit", "hix", "radv", "standard_insurance_claim_payment", "utilization_review", "disability_gov_benefits", "forms_completion_by_provider", "patient_personal", "patient_transfer", "second_request_not_work_comp", "agency", "government_audit", "medicaid_dds", "non_profit", "state_dds", "workers_comp_board", "continuity_of_care", "ciox_audit", "mra", "ciox_real_world_data_team_request", "aca_hix", "drg", "underwriting", "claim", "general_attorney", "general_attorney_subpoena", "workers_comp_subpoena", "ssa_appeal", "pro_medicaid", "standard_pro", "value_based_care", "payd", "payer", "attestation", "unknown"]); export const secondaryReason = z.enum(["aca", "defense_attorney", "defense_subpoena", "personal_injury", "state_attorney_office", "represent_indignant", "subpoena_second_request", "disability_gov_benefits", "ssi_claim_second_request", "hospital_per_admission", "no", "second_request", "social_security_appeal", "patient_social_security_appeal", "social_security_claim_appeal_second_request", "forms_completion_by_provider", "attorney_rep_pat", "appeal_second_request", "court_issued", "criminal", "subpoena", "workers_comp_subpoena", "subpoena_deposition_trial_testimony_with_records", "workers_comp_second_request", "workers_comp", "workers_comp_self_insured", "requested_by_patient", "requested_by_attorney", "drg_payment_integrity", "hedis_audit", "hix", "mra", "radv", "utilization_review", "short_term_long_term_claim", "second_request_insurance", "bc_bs_claim", "non_medical_insurance_claim", "standard_insurance_claim_payment", "underwriting", "pharmacy", "aps", "medicare_medicaid_utl_review", "medicare_medicaid_eligibility", "rac_medicaid", "second_request_workers_comp", "standard_workers_comp", "county", "dept_of_health_human_services", "dept_of_welfare", "family_and_child", "omap", "probation", "public_schools", "social_security_application", "veterans_affairs", "voc_rehab", "mi_family", "nc_prison", "attorney_general", "state_attorney", "federal_public_defender", "utilization_review_medicare_and_medicaid", "home_risk_assessment", "in_office_assessment", "payment_integrity", "post_payment_denials", "pre_payment_denials", "provider_as_requester", "switchboard_for_acos", "whole_person_understanding"]); export const address = z.object({normalizations: z.array(z.unknown()).optional(), line1: z.string().optional(), line2: z.string().optional(), city: z.string().optional(), country: z.string().optional(), state: z.string().optional(), postal_code: z.string().optional()}); export const legalEntity = z.object({phone_number: z.string().optional(), full_name: z.string().optional(), first_name: z.string().optional(), alternate_first_name: z.string().optional(), middle_name: z.string().optional(), last_name: z.string().optional(), prefix: z.string().optional(), suffix: z.string().optional(), id: z.string(), order_id: z.string().optional(), address: address.optional(), health_plan: z.string().optional()}); export const contacts = z.object({billing: legalEntity.optional(), customer: legalEntity.optional()}); export const retrievalSources = z.enum(["api", "embedded_manual", "nonembedded_manual", "athena", "healthjump", "mock_retrieval", "moxe", "office_ally", "particle", "ses", "share_arkansas", "sidus", "veradigm", "vim", "iatric", "c3hie", "ghhc", "healow", "mdland"]); export const allowBlockGroup = z.object({data_foundation_health_system_ids: z.array(z.string()).optional()}); export const retrievalAllowBlockConfiguration = z.object({allow: allowBlockGroup.optional(), block: allowBlockGroup.optional()}); export const submissionSource = z.enum(["api", "switchboard", "sftp", "legacy"]); export const orderStatus = z.enum(["draft", "accepted", "rejected", "processing", "failed", "dispatched", "canceled", "complete", "pending_close", "close_in_progress", "intake_review_required", "intake_review_completed"]); export const chartFinderConfiguration = z.object({coding: z.boolean().optional(), audit_type: z.number().int().optional(), review_type: z.union([z.string(), z.number().int()]).optional(), idsb_handling_qa: z.union([z.literal(0), z.literal(1)]).optional(), idsb_retrieving: z.union([z.literal(0), z.literal(1)]).optional(), idsb_retrieving_embedded: z.union([z.literal(0), z.literal(1)]).optional(), account_manager_id: z.number().int().optional()}); export const manifestDeliveryConfig = z.object({filename_template: z.string().optional(), file_extension: z.enum([".csv", ".txt", ".dat"]).optional(), delimiter: z.enum([",", "|", " ", "~"]).optional(), header_configuration: z.array(z.object({})).optional(), template_name: z.enum(["ml_standard", "provider", "ml_merge", "arbcbs_pdf_custom", "arbcbs_cda_custom", "centene_custom", "clover_pdf_custom", "optum_ioa_custom", "bcbsmi_custom", "elevance_custom"])}); export const s3FileTransferConfig = z.object({target_type: z.literal("s3"), prefix: z.string()}); export const zipDeliveryConfig = z.object({filename_template: z.string().optional(), include_manifest: z.boolean().optional(), password: z.string().optional()}); export const pdfDeliveryConfig = z.object({filename_template: z.string().optional(), schedule: z.array(z.string()), manifest: manifestDeliveryConfig.optional(), email_recipients: z.array(z.string()).optional(), file_transfer_config: s3FileTransferConfig.optional(), zip: zipDeliveryConfig.optional(), is_continuous: z.boolean().optional(), merge: z.boolean().optional()}); export const baseDeliveryConfig = z.object({filename_template: z.string().optional(), schedule: z.array(z.string()), manifest: manifestDeliveryConfig.optional(), email_recipients: z.array(z.string()).optional(), file_transfer_config: s3FileTransferConfig.optional()}); export const extractionDeliveryConfig = z.object({include_npi: z.boolean(), include_diagnosis: z.boolean(), filter_encounters_by_requested_dos: z.boolean().optional(), write_empty_encounters: z.boolean().optional()}); export const structuredExtractionDeliveryConfig = z.object({filename_template: z.string().optional(), schedule: z.array(z.string()), manifest: manifestDeliveryConfig.optional(), email_recipients: z.array(z.string()).optional(), file_transfer_config: s3FileTransferConfig.optional(), deliver_automatically: z.boolean().optional(), report: extractionDeliveryConfig}); export const chartDetailExtractDeliveryConfig = z.object({filename_template: z.string().optional(), schedule: z.array(z.string()), manifest: manifestDeliveryConfig.optional(), email_recipients: z.array(z.string()).optional(), file_transfer_config: s3FileTransferConfig.optional(), deliver_automatically: z.boolean().optional()}); export const allDeliveryConfig = z.object({pdf: pdfDeliveryConfig.optional(), cda: baseDeliveryConfig.optional(), fhir: baseDeliveryConfig.optional(), structured_extraction: structuredExtractionDeliveryConfig.optional(), chart_detail_extract: chartDetailExtractDeliveryConfig.optional()}); export const importReviewStatus = z.object({provider_package_approved: z.boolean().optional()}); export const orderResponse = z.object({delivery_type: z.array(deliveryType).optional(), delivery_format: deliveryFormat.optional(), structured_data_file_delivery_format: deliveryFormat.optional(), delivery_filename_template: z.string().optional(), delivery_manifest_included: z.boolean().optional(), delivery_manifest_filename_template: z.string().optional(), delivery_manifest_file_extension: z.enum([".csv", ".txt", ".dat"]).optional(), delivery_manifest_delimiter: z.enum([",", "|", " "]).optional(), delivery_zip_filename_template: z.string().optional(), delivery_frequency: deliveryFrequency.optional(), delivery_frequency_sub_option: z.union([z.array(deliveryFrequencyDay), z.number().int()]).optional(), delivery_schedule: z.array(z.string()).optional(), delivery_timing: deliveryTiming.optional(), delivery_location: deliveryLocation.optional(), delivery_email_recipients: z.array(z.string()).optional(), delivery_manifest_configuration: z.unknown(), zip_password: z.string().optional(), merge_charts: z.boolean().optional(), structured_data_extraction_report_configuration: structuredDataExtractionReportConfiguration.optional(), chart_detail_extract_report_configuration: chartDetailExtractConfiguration.optional(), uuid: z.string(), id: z.string().min(1).max(100), name: z.string().optional(), project_id: z.string().optional(), project_uuid: z.string().optional(), project_name: z.string().optional(), project_config_options: z.object({}).optional(), package_configuration_pk_id: z.number().int().optional(), package_configuration_pk_id_for_project_type: z.number().int().optional(), type: requesterType, due_date: z.string().optional(), primary_reason: primaryReason, secondary_reason: secondaryReason.optional(), meta: z.object({}).optional(), contacts: contacts.optional(), retrieval_sources: z.array(retrievalSources).optional(), retrieval_allow_block_configuration: retrievalAllowBlockConfiguration.optional(), manual_qa: z.boolean().optional(), coding_required: z.boolean().optional(), coding_required_v2: z.boolean().optional(), submission_source: submissionSource.optional(), total_queries: z.number().int().optional(), status: orderStatus, created_at: z.string().optional(), updated_at: z.string().optional(), demand_id: z.number().int().optional(), wave: z.number().int().gt(0).lt(10000).optional(), chart_review_year: z.number().int().optional(), target_yield: z.number().optional(), yield_type: z.number().int().optional(), ticket_number: z.string().optional(), flow_type: z.string().optional(), chart_finder_config: chartFinderConfiguration.optional(), delivery_config: allDeliveryConfig.optional(), import_review_status: importReviewStatus.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 }; /** * Create an order * * POST /orders/ */ export const createApiOrders = async (args: CreateApiOrdersArgs, options?: CreateApiOrdersOptions) => { const {baseUrl = "https://api.datavant.io/v2", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['version-datavant'] != null) headers.set("version-datavant", String(args['version-datavant'])) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/orders/${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(orderResponse, await res.json()) };