import {z} from 'zod' export type LiensLienBatchRequestParamLiensItemState = 'AL' | 'AK' | 'AZ' | 'AR' | 'CA' | 'CO' | 'CT' | 'DE' | 'FL' | 'GA' | 'HI' | 'ID' | 'IL' | 'IN' | 'IA' | 'KS' | 'KY' | 'LA' | 'ME' | 'MD' | 'MA' | 'MI' | 'MN' | 'MS' | 'MO' | 'MT' | 'NE' | 'NV' | 'NH' | 'NJ' | 'NM' | 'NY' | 'NC' | 'ND' | 'OH' | 'OK' | 'OR' | 'PA' | 'RI' | 'SC' | 'SD' | 'TN' | 'TX' | 'UT' | 'VT' | 'VA' | 'WA' | 'WV' | 'WI' | 'WY'; export type LienAddressState = 'AL' | 'AK' | 'AZ' | 'AR' | 'CA' | 'CO' | 'CT' | 'DE' | 'FL' | 'GA' | 'HI' | 'ID' | 'IL' | 'IN' | 'IA' | 'KS' | 'KY' | 'LA' | 'ME' | 'MD' | 'MA' | 'MI' | 'MN' | 'MS' | 'MO' | 'MT' | 'NE' | 'NV' | 'NH' | 'NJ' | 'NM' | 'NY' | 'NC' | 'ND' | 'OH' | 'OK' | 'OR' | 'PA' | 'RI' | 'SC' | 'SD' | 'TN' | 'TX' | 'UT' | 'VT' | 'VA' | 'WA' | 'WV' | 'WI' | 'WY'; export type LienAddress = {address_line1?: string | undefined, address_line2?: string | undefined, city?: string | undefined, state?: LienAddressState | undefined, postal_code?: string | undefined}; export type LiensLienBatchRequestParamLiensItemDebtorsItem = {organization_name?: string | undefined, tin?: string | undefined, addresses?: Array | undefined}; export type LiensLienBatchRequestParamLiensItemSecuredPartiesItemRole = 'assignee' | 'assignor'; export type LiensLienBatchRequestParamLiensItemSecuredPartiesItem = {organization_name?: string | undefined, role?: LiensLienBatchRequestParamLiensItemSecuredPartiesItemRole | undefined, addresses?: Array | undefined}; export type LiensLienBatchRequestParamLiensItem = {state: LiensLienBatchRequestParamLiensItemState, debtors: Array, secured_parties?: Array | undefined, collateral?: string | undefined, loan_principal_amount_cents?: number | undefined, packet_number?: string | undefined, alternative_designation?: string | undefined}; export type CreateApiV1BusinessesBusinessIdLiensBatchArgs = {business_id: string, body: {liens: Array}}; export type CreateApiV1BusinessesBusinessIdLiensBatchOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1BusinessesBusinessIdLiensBatchResponse = 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 lien filings in batch * * POST /v1/businesses/{business_id}/liens/batch */ export const createApiV1BusinessesBusinessIdLiensBatch = async (args: CreateApiV1BusinessesBusinessIdLiensBatchArgs, options?: CreateApiV1BusinessesBusinessIdLiensBatchOptions) => { 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))}/liens/batch${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(createApiV1BusinessesBusinessIdLiensBatchResponse, await res.json()) };