import {z} from 'zod' export type PropertyAccountingSalesorderShippingAddress = {address1?: string | undefined, address2?: string | undefined, city?: string | undefined, region?: string | undefined, region_code?: string | undefined, postal_code?: string | undefined, country?: string | undefined, country_code?: string | undefined}; export type PropertyAccountingSalesorderBillingAddress = {address1?: string | undefined, address2?: string | undefined, city?: string | undefined, region?: string | undefined, region_code?: string | undefined, postal_code?: string | undefined, country?: string | undefined, country_code?: string | undefined}; export type PropertyAccountingLineitemCategoryIds = Array; export type AccountingReference = {id?: string | undefined, name?: string | undefined}; export type PropertyAccountingLineitemLocations = Array; export type PropertyAccountingLineitemItemVariants = Array; export type AccountingFee = {type: 'TAX' | 'DISCOUNT' | 'PROMOTION' | 'SHIPPING' | 'GIFT_WRAP' | 'COD' | 'SURCHARGE' | 'TIP' | 'SERVICE_CHARGE' | 'OTHER', original_type?: string | undefined, amount: number, currency?: string | undefined}; export type PropertyAccountingLineitemFees = Array; export type AccountingLineitem = {id?: string | undefined, created_at?: string | undefined, updated_at?: string | undefined, refunded_at?: string | undefined, total_amount?: number | undefined, refund_amount?: number | undefined, discount_amount?: number | undefined, tax_amount?: number | undefined, item_id?: string | undefined, unit_amount?: number | undefined, unit_quantity?: number | undefined, item_sku?: string | undefined, item_name?: string | undefined, item_description?: string | undefined, notes?: string | undefined, taxrate_id?: string | undefined, account_id?: string | undefined, category_ids?: PropertyAccountingLineitemCategoryIds | undefined, locations?: PropertyAccountingLineitemLocations | undefined, item_variants?: PropertyAccountingLineitemItemVariants | undefined, fees?: PropertyAccountingLineitemFees | undefined, contact_id?: string | undefined, project_id?: string | undefined, exchange_rate?: number | undefined, is_billable?: boolean | undefined}; export type PropertyAccountingSalesorderLineitems = Array; export type PropertyAccountingSalesorderFees = Array; export type PropertyAccountingSalesorderCategoryIds = Array; export type AccountingMetadata = {id?: string | undefined, slug?: string | undefined, value?: ({[key: string]: unknown} | string | number | boolean | Array | string | number | boolean>) | undefined, namespace?: string | undefined, format?: ('TEXT' | 'NUMBER' | 'DATE' | 'BOOLEAN' | 'FILE' | 'TEXTAREA' | 'SINGLE_SELECT' | 'MULTIPLE_SELECT' | 'MEASUREMENT' | 'PRICE' | 'YES_NO' | 'CURRENCY' | 'URL') | undefined, extra_data?: ({[key: string]: unknown} | string | number | boolean | Array | string | number | boolean>) | undefined}; export type PropertyAccountingSalesorderMetadata = Array; export type AccountingPaymentReference = {payment_id?: string | undefined, amount?: number | undefined, allocated_at?: string | undefined}; export type PropertyAccountingSalesorderPayments = Array; export type AccountingSalesorder = {id?: string | undefined, created_at?: string | undefined, updated_at?: string | undefined, posted_at?: string | undefined, contact_id?: string | undefined, account_id?: string | undefined, currency?: string | undefined, total_amount?: number | undefined, shipping_address?: PropertyAccountingSalesorderShippingAddress | undefined, billing_address?: PropertyAccountingSalesorderBillingAddress | undefined, status?: ('DRAFT' | 'VOIDED' | 'AUTHORIZED' | 'PAID' | 'PARTIALLY_PAID' | 'PARTIALLY_REFUNDED' | 'REFUNDED' | 'SUBMITTED' | 'DELETED' | 'OPEN' | 'COMPLETED' | 'CANCELED') | undefined, lineitems?: PropertyAccountingSalesorderLineitems | undefined, sales_channel?: string | undefined, organization_id?: string | undefined, fees?: PropertyAccountingSalesorderFees | undefined, category_ids?: PropertyAccountingSalesorderCategoryIds | undefined, metadata?: PropertyAccountingSalesorderMetadata | undefined, order_number?: string | undefined, location_id?: string | undefined, employee_user_id?: string | undefined, device_id?: string | undefined, fulfillment_type?: ('DINE_IN' | 'TAKEOUT' | 'DELIVERY' | 'PICKUP' | 'CURBSIDE' | 'SHIPPING' | 'DIGITAL' | 'OTHER') | undefined, guest_count?: number | undefined, subtotal_amount?: number | undefined, tax_amount?: number | undefined, discount_amount?: number | undefined, tip_amount?: number | undefined, service_charge_amount?: number | undefined, refunded_amount?: number | undefined, closed_at?: string | undefined, subscription_id?: string | undefined, payments?: PropertyAccountingSalesorderPayments | undefined, table_id?: string | undefined, paid_amount?: number | undefined, raw?: {[key: string]: unknown} | undefined}; export type UpdateApiAccountingConnectionIdSalesorderIdArgs = {fields?: (Array<'id' | 'created_at' | 'updated_at' | 'posted_at' | 'contact_id' | 'account_id' | 'currency' | 'total_amount' | 'shipping_address' | 'billing_address' | 'status' | 'lineitems' | 'sales_channel' | 'organization_id' | 'fees' | 'category_ids' | 'metadata' | 'order_number' | 'location_id' | 'employee_user_id' | 'device_id' | 'fulfillment_type' | 'guest_count' | 'subtotal_amount' | 'tax_amount' | 'discount_amount' | 'tip_amount' | 'service_charge_amount' | 'refunded_amount' | 'closed_at' | 'subscription_id' | 'payments' | 'table_id' | 'paid_amount' | 'raw'>) | undefined, raw?: string | undefined, connection_id: string, id: string, body: AccountingSalesorder}; export type UpdateApiAccountingConnectionIdSalesorderIdOptions = {baseUrl?: string | undefined, jwt?: string | undefined, fetch?: typeof fetch | undefined}; export const propertyAccountingSalesorderShippingAddress = z.object({address1: z.string().optional(), address2: z.string().optional(), city: z.string().optional(), region: z.string().optional(), region_code: z.string().optional(), postal_code: z.string().optional(), country: z.string().optional(), country_code: z.string().optional()}); export const propertyAccountingSalesorderBillingAddress = z.object({address1: z.string().optional(), address2: z.string().optional(), city: z.string().optional(), region: z.string().optional(), region_code: z.string().optional(), postal_code: z.string().optional(), country: z.string().optional(), country_code: z.string().optional()}); export const propertyAccountingLineitemCategoryIds = z.array(z.string()); export const accountingReference = z.object({id: z.string().optional(), name: z.string().optional()}); export const propertyAccountingLineitemLocations = z.array(accountingReference); export const propertyAccountingLineitemItemVariants = z.array(accountingReference); export const accountingFee = z.object({type: z.enum(["TAX", "DISCOUNT", "PROMOTION", "SHIPPING", "GIFT_WRAP", "COD", "SURCHARGE", "TIP", "SERVICE_CHARGE", "OTHER"]), original_type: z.string().optional(), amount: z.number(), currency: z.string().optional()}); export const propertyAccountingLineitemFees = z.array(accountingFee); export const accountingLineitem = z.object({id: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), refunded_at: z.string().optional(), total_amount: z.number().optional(), refund_amount: z.number().optional(), discount_amount: z.number().optional(), tax_amount: z.number().optional(), item_id: z.string().optional(), unit_amount: z.number().optional(), unit_quantity: z.number().optional(), item_sku: z.string().optional(), item_name: z.string().optional(), item_description: z.string().optional(), notes: z.string().optional(), taxrate_id: z.string().optional(), account_id: z.string().optional(), category_ids: propertyAccountingLineitemCategoryIds.optional(), locations: propertyAccountingLineitemLocations.optional(), item_variants: propertyAccountingLineitemItemVariants.optional(), fees: propertyAccountingLineitemFees.optional(), contact_id: z.string().optional(), project_id: z.string().optional(), exchange_rate: z.number().optional(), is_billable: z.boolean().optional()}); export const propertyAccountingSalesorderLineitems = z.array(accountingLineitem); export const propertyAccountingSalesorderFees = z.array(accountingFee); export const propertyAccountingSalesorderCategoryIds = z.array(z.string()); export const accountingMetadata = z.object({id: z.string().optional(), slug: z.string().optional(), value: z.union([z.record(z.string(), z.unknown()), z.string(), z.number(), z.boolean(), z.array(z.union([z.object({}), z.string(), z.number(), z.boolean()]))]).optional(), namespace: z.string().optional(), format: z.enum(["TEXT", "NUMBER", "DATE", "BOOLEAN", "FILE", "TEXTAREA", "SINGLE_SELECT", "MULTIPLE_SELECT", "MEASUREMENT", "PRICE", "YES_NO", "CURRENCY", "URL"]).optional(), extra_data: z.union([z.record(z.string(), z.unknown()), z.string(), z.number(), z.boolean(), z.array(z.union([z.object({}), z.string(), z.number(), z.boolean()]))]).optional()}); export const propertyAccountingSalesorderMetadata = z.array(accountingMetadata); export const accountingPaymentReference = z.object({payment_id: z.string().optional(), amount: z.number().optional(), allocated_at: z.string().optional()}); export const propertyAccountingSalesorderPayments = z.array(accountingPaymentReference); export const accountingSalesorder = z.object({id: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), posted_at: z.string().optional(), contact_id: z.string().optional(), account_id: z.string().optional(), currency: z.string().optional(), total_amount: z.number().optional(), shipping_address: propertyAccountingSalesorderShippingAddress.optional(), billing_address: propertyAccountingSalesorderBillingAddress.optional(), status: z.enum(["DRAFT", "VOIDED", "AUTHORIZED", "PAID", "PARTIALLY_PAID", "PARTIALLY_REFUNDED", "REFUNDED", "SUBMITTED", "DELETED", "OPEN", "COMPLETED", "CANCELED"]).optional(), lineitems: propertyAccountingSalesorderLineitems.optional(), sales_channel: z.string().optional(), organization_id: z.string().optional(), fees: propertyAccountingSalesorderFees.optional(), category_ids: propertyAccountingSalesorderCategoryIds.optional(), metadata: propertyAccountingSalesorderMetadata.optional(), order_number: z.string().optional(), location_id: z.string().optional(), employee_user_id: z.string().optional(), device_id: z.string().optional(), fulfillment_type: z.enum(["DINE_IN", "TAKEOUT", "DELIVERY", "PICKUP", "CURBSIDE", "SHIPPING", "DIGITAL", "OTHER"]).optional(), guest_count: z.number().optional(), subtotal_amount: z.number().optional(), tax_amount: z.number().optional(), discount_amount: z.number().optional(), tip_amount: z.number().optional(), service_charge_amount: z.number().optional(), refunded_amount: z.number().optional(), closed_at: z.string().optional(), subscription_id: z.string().optional(), payments: propertyAccountingSalesorderPayments.optional(), table_id: z.string().optional(), paid_amount: z.number().optional(), raw: z.record(z.string(), z.unknown()).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 }; /** * Update a salesorder * * PUT /accounting/{connection_id}/salesorder/{id} */ export const updateApiAccountingConnectionIdSalesorderId = async (args: UpdateApiAccountingConnectionIdSalesorderIdArgs, options?: UpdateApiAccountingConnectionIdSalesorderIdOptions) => { const {baseUrl = "https://api.unified.to", fetch: fetchFn = fetch, jwt} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") for (const item of args.fields ?? []) query.append("fields", String(item)) if (args.raw != null) query.append("raw", String(args.raw)) if (jwt !== undefined) headers.set("authorization", jwt) const url = `${baseUrl.replace(/\/+$/, '')}/accounting/${encodeURIComponent(String(args.connection_id))}/salesorder/${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(accountingSalesorder, await res.json()) };