import {z} from 'zod' export type Vendor = {id?: string | undefined, integration?: string | undefined, srcId?: string | undefined, givenName?: (string | null) | undefined, familyName?: (string | null) | undefined, companyName?: (string | null) | undefined, displayName?: (string | null) | undefined, contactName?: (string | null) | undefined, contactTitle?: (string | null) | undefined, accountNumber?: (string | null) | undefined, phone?: (string | null) | undefined, mobile?: (string | null) | undefined, fax?: (string | null) | undefined, email?: (string | null) | undefined, website?: (string | null) | undefined, address?: (string | null) | undefined, addressLine2?: (string | null) | undefined, city?: (string | null) | undefined, state?: (string | null) | undefined, country?: (string | null) | undefined, postalCode?: (string | null) | undefined, currency?: (string | null) | undefined, balance?: (number | null) | undefined, bankAccountName?: (string | null) | undefined, bankAccountNumber?: (string | null) | undefined, notes?: (string | null) | undefined, taxType?: (string | null) | undefined, isContractor?: (boolean | null) | undefined, active?: (boolean | null) | undefined, created?: (string | null) | undefined, modified?: (string | null) | undefined, termId?: (string | null) | undefined, termDays?: (number | null) | undefined, termType?: (string | null) | undefined}; export type UpdateApiVendorsIdArgs = {id: string, body: Vendor}; export type UpdateApiVendorsIdOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const vendor = z.object({id: z.string().optional(), integration: z.string().optional(), srcId: z.string().optional(), givenName: z.string().nullable().optional(), familyName: z.string().nullable().optional(), companyName: z.string().nullable().optional(), displayName: z.string().nullable().optional(), contactName: z.string().nullable().optional(), contactTitle: z.string().nullable().optional(), accountNumber: z.string().nullable().optional(), phone: z.string().nullable().optional(), mobile: z.string().nullable().optional(), fax: z.string().nullable().optional(), email: z.string().nullable().optional(), website: z.string().nullable().optional(), address: z.string().nullable().optional(), addressLine2: z.string().nullable().optional(), city: z.string().nullable().optional(), state: z.string().nullable().optional(), country: z.string().nullable().optional(), postalCode: z.string().nullable().optional(), currency: z.string().nullable().optional(), balance: z.number().int().nullable().optional(), bankAccountName: z.string().nullable().optional(), bankAccountNumber: z.string().nullable().optional(), notes: z.string().nullable().optional(), taxType: z.string().nullable().optional(), isContractor: z.boolean().nullable().optional(), active: z.boolean().nullable().optional(), created: z.string().nullable().optional(), modified: z.string().nullable().optional(), termId: z.string().nullable().optional(), termDays: z.number().int().nullable().optional(), termType: z.string().nullable().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 }; /** * Replaces the Vendor resource. * * PUT /vendors/{id} */ export const updateApiVendorsId = async (args: UpdateApiVendorsIdArgs, options?: UpdateApiVendorsIdOptions) => { const {baseUrl = "https://example.myintranetapps.com/api", fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/vendors/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(vendor, await res.json()) };