import {z} from 'zod' export type LiensLienRequestParamState = '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 LiensLienRequestParamStatesItem = '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 LiensLienRequestParamDebtorsItem = {organization_name?: string | undefined, tin?: string | undefined, addresses?: Array | undefined}; export type LiensLienRequestParamSecuredPartiesItemRole = 'assignee' | 'assignor'; export type LiensLienRequestParamSecuredPartiesItem = {organization_name?: string | undefined, role?: LiensLienRequestParamSecuredPartiesItemRole | undefined, addresses?: Array | undefined}; export type LiensLienRequestParamSecuredPartyRole = 'assignee' | 'assignor'; export type LiensLienRequestParamSecuredParty = {organization_name?: string | undefined, role?: LiensLienRequestParamSecuredPartyRole | undefined, addresses?: Array | undefined}; export type CreateApiV1BusinessesBusinessIdLiensArgs = {business_id: string, body: {state?: LiensLienRequestParamState | undefined, states?: Array | undefined, debtors: Array, secured_parties?: Array | undefined, secured_party?: LiensLienRequestParamSecuredParty | undefined, collateral?: string | undefined, loan_principal_amount_cents?: number | undefined, packet_number?: string | undefined, alternative_designation?: string | undefined}}; export type CreateApiV1BusinessesBusinessIdLiensOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1BusinessesBusinessIdLiensResponse = 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 a lien for a business * * POST /v1/businesses/{business_id}/liens */ export const createApiV1BusinessesBusinessIdLiens = async (args: CreateApiV1BusinessesBusinessIdLiensArgs, options?: CreateApiV1BusinessesBusinessIdLiensOptions) => { 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${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(createApiV1BusinessesBusinessIdLiensResponse, await res.json()) };