import {z} from 'zod' export type DeleteApiV6BillsIdArgs = {id: string}; export type DeleteApiV6BillsIdOptions = {baseUrl?: string | undefined, EmbedToken?: string | undefined, fetch?: typeof fetch | undefined}; export const vendorExpanded = z.object({id: z.string(), name: z.string().optional()}).nullable(); export const glAccountExpanded = z.object({id: z.string(), name: z.string().optional(), accountNo: z.string().optional(), type: z.enum(["ASSET", "LIABILITY", "EQUITY", "INCOME", "COGS", "EXPENSE", "OTHER_INCOME", "OTHER_EXPENSE", "SUSPENSE"]).optional(), iconUrl: z.string().optional(), displayName: z.string().optional()}); export const billLineItemGetDto = z.object({id: z.string(), description: z.string(), amount: z.number().int(), apiItemId: z.string().nullable(), glAccount: glAccountExpanded}); export const amountDue = z.object({value: z.string().nullable(), type: z.enum(["AMOUNT", "PERCENT"]).nullable()}).nullable(); export const installmentGetDto = z.object({id: z.string(), name: z.string().nullable(), dueDate: z.string().nullable(), balance: z.number().int().nullable(), amountDue: amountDue}); export const jsonNode = z.object({empty: z.boolean().optional(), array: z.boolean().optional(), null: z.boolean().optional(), object: z.boolean().optional(), float: z.boolean().optional(), string: z.boolean().optional(), number: z.boolean().optional(), missingNode: z.boolean().optional(), valueNode: z.boolean().optional(), nodeType: z.enum(["ARRAY", "BINARY", "BOOLEAN", "MISSING", "NULL", "NUMBER", "OBJECT", "POJO", "STRING"]).optional(), pojo: z.boolean().optional(), integralNumber: z.boolean().optional(), floatingPointNumber: z.boolean().optional(), short: z.boolean().optional(), int: z.boolean().optional(), long: z.boolean().optional(), double: z.boolean().optional(), bigDecimal: z.boolean().optional(), bigInteger: z.boolean().optional(), textual: z.boolean().optional(), boolean: z.boolean().optional(), binary: z.boolean().optional(), container: z.boolean().optional(), embeddedValue: z.boolean().optional()}).nullable(); export const billGetDto = z.object({id: z.string(), name: z.string(), billNo: z.number().int(), status: z.enum(["ACTIVE", "INACTIVE", "REMOVED"]), billStatus: z.enum(["DRAFT", "OPEN", "CLOSED", "CANCELLED", "REFUNDED"]), date: z.string(), vendor: vendorExpanded, apiName: z.enum(["BOX", "CLOVER", "STRIPE", "PLAID", "KNOX", "UBER", "FRESHBOOKS", "HARVEST", "KW", "FRESHBOOKS2", "CAPITAL_ONE", "SQUARE", "DOTLOOP", "REALOGY", "UPWORK", "SHOPIFY", "DEDUCTR", "ENTERPRISE", "MOXIWORKS", "APPDIRECT", "LONEWOLF", "LONEWOLF_TRANSACTIONDESK", "SAMPLE_BANK", "TAXBOT", "GUSTO", "XERO", "UNIT", "MOOV", "QBO", "QUALPAY", "BENCH", "PARTNER_IMPLEMENTATION", "CHECK", "RUTTER", "WAVE", "MANUAL_ENTRY", "CSV_IMPORT", "ADYEN", "PAYABLI", "MANUAL_ENTRY", "MELIO", "PARTNER_IMPLEMENTATION", "STRIPE"]), apiSourceId: z.string().nullable(), lineItems: z.array(billLineItemGetDto).optional(), installments: z.array(installmentGetDto).optional(), customData: jsonNode.optional()}); export const successResponseBillGetDto = z.object({result: z.enum(["SUCCESS", "FAILURE"]).optional(), data: billGetDto.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 }; /** * Delete bill * * DELETE /v6/bills/{id} */ export const deleteApiV6BillsId = async (args: DeleteApiV6BillsIdArgs, options?: DeleteApiV6BillsIdOptions) => { const {baseUrl = "https://sandbox.tight.com", fetch: fetchFn = fetch, EmbedToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (EmbedToken !== undefined) headers.set('authorization', `Bearer ${EmbedToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/v6/bills/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(successResponseBillGetDto, await res.json()) };