import {z} from 'zod' export type GetApiQuickbooksDesktopCompanyArgs = {'Conductor-End-User-Id': string}; export type GetApiQuickbooksDesktopCompanyOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const qbdAddress = z.object({line1: z.string().nullable(), line2: z.string().nullable(), line3: z.string().nullable(), line4: z.string().nullable(), line5: z.string().nullable(), city: z.string().nullable(), state: z.string().nullable(), postalCode: z.string().nullable(), country: z.string().nullable(), note: z.string().nullable()}); export const qbdService = z.object({name: z.string(), domain: z.string().nullable(), serviceStatus: z.enum(["active", "expired", "never", "pending", "suspended", "terminated", "trial"]).nullable()}); export const qbdSubscribedService = z.object({services: z.array(qbdService)}); export const qbdAccountantCopy = z.object({accountantCopyExists: z.boolean(), dividingDate: z.string().nullable()}); export const qbdCustomField = z.object({ownerId: z.string(), name: z.string(), type: z.enum(["amount_type", "date_time_type", "integer_type", "percent_type", "price_type", "quantity_type", "string_1024_type", "string_255_type"]), value: z.string()}); export const qbdCompany = z.object({isSampleCompanyFile: z.boolean(), companyName: z.string().nullable(), legalCompanyName: z.string().nullable(), address: qbdAddress.nullable(), legalAddress: qbdAddress.nullable(), addressForCustomer: qbdAddress.nullable(), phone: z.string().nullable(), fax: z.string().nullable(), email: z.string().nullable(), website: z.string().nullable(), fiscalYearStartMonth: z.enum(["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"]).nullable(), incomeTaxYearStartMonth: z.enum(["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"]).nullable(), companyType: z.string().nullable(), ein: z.string().nullable(), ssn: z.string().nullable(), taxForm: z.enum(["form_1040", "form_1065", "form_1120", "form_1120s", "form_990", "form_990pf", "form_990t", "other_or_none", "form_t1", "form_t2"]).nullable(), subscribedServices: qbdSubscribedService.nullable(), accountantCopy: qbdAccountantCopy.nullable(), customFields: z.array(qbdCustomField)}); 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 }; /** * Retrieve company file info * * GET /quickbooks-desktop/company */ export const getApiQuickbooksDesktopCompany = async (args: GetApiQuickbooksDesktopCompanyArgs, options?: GetApiQuickbooksDesktopCompanyOptions) => { const {baseUrl = "https://api.conductor.is/v1", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Conductor-End-User-Id'] != null) headers.set("Conductor-End-User-Id", String(args['Conductor-End-User-Id'])) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/quickbooks-desktop/company${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(qbdCompany, await res.json()) };