import {z} from 'zod' export type OrdersOrderRequestParamProduct = 'identity' | 'liens' | 'adverse_media' | 'bankruptcies' | 'business_enrichment' | 'documents' | 'enhanced_screenings' | 'kyc' | 'litigations' | 'people_litigations' | 'people_bankruptcies' | 'people_tax_liens' | 'people_ucc_liens' | 'people_criminal_history' | 'tin' | 'website' | 'business_verification_qualify' | 'business_verification_verify' | 'international_business_verification' | 'tax_liens' | 'ucc_liens' | 'email_risk'; export type OrdersOrderRequestParamSubproductsItem = 'articles_of_incorporation' | 'certificate_of_good_standing' | 'articles_of_incorporation_with_fallback' | 'ucc_documents' | 'web_analysis' | 'industry_classification'; export type OrdersOrderRequestParamOptions = {person_match?: boolean | undefined}; export type CreateApiV1BusinessesBusinessIdOrdersArgs = {business_id: string, body: {product?: OrdersOrderRequestParamProduct | undefined, subproducts?: Array | undefined, options?: OrdersOrderRequestParamOptions | undefined}}; export type CreateApiV1BusinessesBusinessIdOrdersOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1BusinessesBusinessIdOrdersResponse = 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 }; /** * Create an order for a business * * POST /v1/businesses/{business_id}/orders */ export const createApiV1BusinessesBusinessIdOrders = async (args: CreateApiV1BusinessesBusinessIdOrdersArgs, options?: CreateApiV1BusinessesBusinessIdOrdersOptions) => { const {baseUrl = "https://api.middesk.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/businesses/${encodeURIComponent(String(args.business_id))}/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(createApiV1BusinessesBusinessIdOrdersResponse, await res.json()) };