import {z} from 'zod' export type GetApiQuickbooksDesktopDeletedListObjectsArgs = {'Conductor-End-User-Id': string, objectTypes: Array<'account' | 'billing_rate' | 'class' | 'currency' | 'customer' | 'customer_message' | 'customer_type' | 'date_driven_terms' | 'employee' | 'inventory_site' | 'item_discount' | 'item_fixed_asset' | 'item_group' | 'item_inventory' | 'item_inventory_assembly' | 'item_non_inventory' | 'item_other_charge' | 'item_payment' | 'item_sales_tax' | 'item_sales_tax_group' | 'item_service' | 'item_subtotal' | 'job_type' | 'other_name' | 'payment_method' | 'payroll_item_non_wage' | 'payroll_item_wage' | 'price_level' | 'sales_representative' | 'sales_tax_code' | 'ship_method' | 'standard_terms' | 'to_do' | 'unit_of_measure_set' | 'vehicle' | 'vendor' | 'vendor_type' | 'workers_comp_code'>, deletedAfter?: string | undefined, deletedBefore?: string | undefined}; export type GetApiQuickbooksDesktopDeletedListObjectsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const qbdDeletedListObject = z.object({listType: z.enum(["account", "billing_rate", "class", "currency", "customer", "customer_message", "customer_type", "date_driven_terms", "employee", "inventory_site", "item_discount", "item_fixed_asset", "item_group", "item_inventory", "item_inventory_assembly", "item_non_inventory", "item_other_charge", "item_payment", "item_sales_tax", "item_sales_tax_group", "item_service", "item_subtotal", "job_type", "other_name", "payment_method", "payroll_item_non_wage", "payroll_item_wage", "price_level", "sales_representative", "sales_tax_code", "ship_method", "standard_terms", "to_do", "unit_of_measure_set", "vehicle", "vendor", "vendor_type", "workers_comp_code"]), id: z.string(), objectType: z.literal("qbd_deleted_list_object"), createdAt: z.string(), deletedAt: z.string(), fullName: z.string().nullable()}); export const getApiQuickbooksDesktopDeletedListObjectsResponse = z.object({objectType: z.literal("list"), url: z.string(), data: z.array(qbdDeletedListObject)}); 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 }; /** * List all deleted list-objects * * GET /quickbooks-desktop/deleted-list-objects */ export const getApiQuickbooksDesktopDeletedListObjects = async (args: GetApiQuickbooksDesktopDeletedListObjectsArgs, options?: GetApiQuickbooksDesktopDeletedListObjectsOptions) => { 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'])) for (const item of args.objectTypes ?? []) query.append("objectTypes", String(item)) if (args.deletedAfter != null) query.append("deletedAfter", String(args.deletedAfter)) if (args.deletedBefore != null) query.append("deletedBefore", String(args.deletedBefore)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/quickbooks-desktop/deleted-list-objects${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(getApiQuickbooksDesktopDeletedListObjectsResponse, await res.json()) };