import {z} from 'zod' export type GetApiQuickbooksDesktopCustomersIdArgs = {'Conductor-End-User-Id': string, id: string}; export type GetApiQuickbooksDesktopCustomersIdOptions = {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 qbdShippingAddress = z.object({name: z.string().nullable(), 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(), isDefaultShippingAddress: z.boolean().nullable()}); export const qbdCustomContactField = z.object({name: z.string(), value: z.string().nullable()}); export const qbdContact = z.object({id: z.string(), objectType: z.literal("qbd_contact"), createdAt: z.string(), updatedAt: z.string(), revisionNumber: z.string(), name: z.string().nullable(), salutation: z.string().nullable(), firstName: z.string(), middleName: z.string().nullable(), lastName: z.string().nullable(), jobTitle: z.string().nullable(), customContactFields: z.array(qbdCustomContactField)}); export const qbdCreditCard = z.object({number: z.string().nullable(), expirationMonth: z.number().nullable(), expirationYear: z.number().nullable(), name: z.string().nullable(), address: z.string().nullable(), postalCode: z.string().nullable()}); export const qbdNote = z.object({id: z.number(), date: z.string().nullable(), note: z.string()}); 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 qbdCustomer = z.object({id: z.string(), objectType: z.literal("qbd_customer"), createdAt: z.string(), updatedAt: z.string(), revisionNumber: z.string(), name: z.string(), fullName: z.string(), isActive: z.boolean(), class: z.object({id: z.string().nullable(), fullName: z.string().nullable()}).nullable(), parent: z.object({id: z.string().nullable(), fullName: z.string().nullable()}).nullable(), sublevel: z.number(), companyName: z.string().nullable(), salutation: z.string().nullable(), firstName: z.string().nullable(), middleName: z.string().nullable(), lastName: z.string().nullable(), jobTitle: z.string().nullable(), billingAddress: qbdAddress.nullable(), shippingAddress: qbdAddress.nullable(), alternateShippingAddresses: z.array(qbdShippingAddress).nullable(), phone: z.string().nullable(), alternatePhone: z.string().nullable(), fax: z.string().nullable(), email: z.string().nullable(), ccEmail: z.string().nullable(), contact: z.string().nullable(), alternateContact: z.string().nullable(), customContactFields: z.array(qbdCustomContactField), additionalContacts: z.array(qbdContact), customerType: z.object({id: z.string().nullable(), fullName: z.string().nullable()}).nullable(), terms: z.object({id: z.string().nullable(), fullName: z.string().nullable()}).nullable(), salesRepresentative: z.object({id: z.string().nullable(), fullName: z.string().nullable()}).nullable(), balance: z.string().nullable(), totalBalance: z.string().nullable(), salesTaxCode: z.object({id: z.string().nullable(), fullName: z.string().nullable()}).nullable(), salesTaxItem: z.object({id: z.string().nullable(), fullName: z.string().nullable()}).nullable(), salesTaxCountry: z.string().nullable(), resaleNumber: z.string().nullable(), accountNumber: z.string().nullable(), creditLimit: z.string().nullable(), preferredPaymentMethod: z.object({id: z.string().nullable(), fullName: z.string().nullable()}).nullable(), creditCard: qbdCreditCard.nullable(), jobStatus: z.enum(["awarded", "closed", "in_progress", "none", "not_awarded", "pending"]).nullable(), jobStartDate: z.string().nullable(), jobProjectedEndDate: z.string().nullable(), jobEndDate: z.string().nullable(), jobDescription: z.string().nullable(), jobType: z.object({id: z.string().nullable(), fullName: z.string().nullable()}).nullable(), note: z.string().nullable(), additionalNotes: z.array(qbdNote), preferredDeliveryMethod: z.enum(["email", "mail", "none"]).nullable(), priceLevel: z.object({id: z.string().nullable(), fullName: z.string().nullable()}).nullable(), externalId: z.string().nullable(), taxRegistrationNumber: z.string().nullable(), currency: z.object({id: z.string().nullable(), fullName: z.string().nullable()}).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 a customer * * GET /quickbooks-desktop/customers/{id} */ export const getApiQuickbooksDesktopCustomersId = async (args: GetApiQuickbooksDesktopCustomersIdArgs, options?: GetApiQuickbooksDesktopCustomersIdOptions) => { 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/customers/${encodeURIComponent(String(args.id))}${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(qbdCustomer, await res.json()) };