/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { lazySchema as lazySchema$, safeParse } from "../../lib/schemas.js"; import * as openEnums from "../../types/enums.js"; import { OpenEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import * as types from "../../types/primitives.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { Currency, Currency$inboundSchema, Currency$outboundSchema, } from "./currency.js"; import { CustomField, CustomField$inboundSchema, CustomField$Outbound, CustomField$outboundSchema, } from "./customfield.js"; import { ExpenseLineItem, ExpenseLineItem$inboundSchema, } from "./expenselineitem.js"; import { ExpenseLineItemInput, ExpenseLineItemInput$Outbound, ExpenseLineItemInput$outboundSchema, } from "./expenselineiteminput.js"; import { LinkedDepartment, LinkedDepartment$inboundSchema, } from "./linkeddepartment.js"; import { LinkedDepartmentInput, LinkedDepartmentInput$Outbound, LinkedDepartmentInput$outboundSchema, } from "./linkeddepartmentinput.js"; import { LinkedFinancialAccount, LinkedFinancialAccount$inboundSchema, LinkedFinancialAccountInput, LinkedFinancialAccountInput$Outbound, LinkedFinancialAccountInput$outboundSchema, } from "./linkedfinancialaccount.js"; import { LinkedLocation, LinkedLocation$inboundSchema, } from "./linkedlocation.js"; import { LinkedLocationInput, LinkedLocationInput$Outbound, LinkedLocationInput$outboundSchema, } from "./linkedlocationinput.js"; import { LinkedSupplier, LinkedSupplier$inboundSchema, } from "./linkedsupplier.js"; import { LinkedSupplierInput, LinkedSupplierInput$Outbound, LinkedSupplierInput$outboundSchema, } from "./linkedsupplierinput.js"; import { LinkedTaxRate, LinkedTaxRate$inboundSchema } from "./linkedtaxrate.js"; import { LinkedTaxRateInput, LinkedTaxRateInput$Outbound, LinkedTaxRateInput$outboundSchema, } from "./linkedtaxrateinput.js"; import { LinkedTrackingCategory, LinkedTrackingCategory$inboundSchema, LinkedTrackingCategory$Outbound, LinkedTrackingCategory$outboundSchema, } from "./linkedtrackingcategory.js"; import { PassThroughBody, PassThroughBody$inboundSchema, PassThroughBody$Outbound, PassThroughBody$outboundSchema, } from "./passthroughbody.js"; /** * The type of payment for the expense. */ export const ExpensePaymentType = { Cash: "cash", Check: "check", CreditCard: "credit_card", Other: "other", } as const; /** * The type of payment for the expense. */ export type ExpensePaymentType = OpenEnum; /** * The type of expense. */ export const ExpenseType = { Expense: "expense", Refund: "refund", } as const; /** * The type of expense. */ export type ExpenseType = OpenEnum; /** * Expense status */ export const ExpenseStatus = { Draft: "draft", Posted: "posted", Voided: "voided", } as const; /** * Expense status */ export type ExpenseStatus = OpenEnum; export type Expense = { /** * A unique identifier for an object. */ id?: string | undefined; /** * Id to be displayed. */ displayId?: string | null | undefined; /** * Number. */ number?: string | null | undefined; /** * The date of the transaction - YYYY:MM::DDThh:mm:ss.sTZD */ transactionDate: Date | null; /** * The unique identifier for the ledger account that this expense should be credited to. Deprecated, use account instead. * * @deprecated field: Deprecated. Use account instead.. */ accountId?: string | undefined; /** * A flexible account reference that can represent a ledger account (GL account), a bank account, or an employee payable account, depending on the connector's requirements. */ account?: LinkedFinancialAccount | null | undefined; /** * The ID of the supplier this entity is linked to. Deprecated, use supplier instead. * * @deprecated field: Deprecated. Use supplier instead.. */ supplierId?: string | undefined; /** * The supplier this entity is linked to. */ supplier?: LinkedSupplier | null | undefined; /** * The company ID the transaction belongs to */ companyId?: string | null | undefined; location?: LinkedLocation | null | undefined; /** * The ID of the department */ departmentId?: string | null | undefined; department?: LinkedDepartment | null | undefined; /** * The type of payment for the expense. */ paymentType?: ExpensePaymentType | null | undefined; /** * Indicates the associated currency for an amount of money. Values correspond to [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217). */ currency?: Currency | null | undefined; /** * Currency Exchange Rate at the time entity was recorded/generated. */ currencyRate?: number | null | undefined; /** * The type of expense. */ type?: ExpenseType | null | undefined; /** * The memo of the expense. */ memo?: string | null | undefined; taxRate?: LinkedTaxRate | undefined; /** * Amounts are including tax */ taxInclusive?: boolean | null | undefined; /** * Subtotal amount, normally before tax. */ subTotal?: number | null | undefined; /** * Total tax amount applied to this transaction. */ totalTax?: number | null | undefined; /** * The total amount of the expense line item. */ totalAmount?: number | null | undefined; /** * A list of linked tracking categories. */ trackingCategories?: Array | null | undefined; /** * Expense line items linked to this expense. */ lineItems: Array; /** * Optional reference identifier for the transaction. */ reference?: string | null | undefined; /** * URL link to a source document - shown as 'Go to [appName]' in the downstream app. Currently only supported for Xero. */ sourceDocumentUrl?: string | null | undefined; customFields?: Array | undefined; /** * When custom mappings are configured on the resource, the result is included here. */ customMappings?: { [k: string]: any } | null | undefined; /** * Expense status */ status?: ExpenseStatus | null | undefined; /** * The date and time when the object was last updated. */ updatedAt?: Date | null | undefined; /** * The date and time when the object was created. */ createdAt?: Date | null | undefined; /** * A binary value used to detect updates to a object and prevent data conflicts. It is incremented each time an update is made to the object. */ rowVersion?: string | null | undefined; /** * The user who last updated the object. */ updatedBy?: string | null | undefined; /** * The user who created the object. */ createdBy?: string | null | undefined; /** * The pass_through property allows passing service-specific, custom data or structured modifications in request body when creating or updating resources. */ passThrough?: Array | undefined; }; export type ExpenseInput = { /** * Id to be displayed. */ displayId?: string | null | undefined; /** * Number. */ number?: string | null | undefined; /** * The date of the transaction - YYYY:MM::DDThh:mm:ss.sTZD */ transactionDate: Date | null; /** * The unique identifier for the ledger account that this expense should be credited to. Deprecated, use account instead. * * @deprecated field: Deprecated. Use account instead.. */ accountId?: string | undefined; /** * A flexible account reference that can represent a ledger account (GL account), a bank account, or an employee payable account, depending on the connector's requirements. */ account?: LinkedFinancialAccountInput | null | undefined; /** * The ID of the supplier this entity is linked to. Deprecated, use supplier instead. * * @deprecated field: Deprecated. Use supplier instead.. */ supplierId?: string | undefined; /** * The supplier this entity is linked to. */ supplier?: LinkedSupplierInput | null | undefined; /** * The company ID the transaction belongs to */ companyId?: string | null | undefined; location?: LinkedLocationInput | null | undefined; /** * The ID of the department */ departmentId?: string | null | undefined; department?: LinkedDepartmentInput | null | undefined; /** * The type of payment for the expense. */ paymentType?: ExpensePaymentType | null | undefined; /** * Indicates the associated currency for an amount of money. Values correspond to [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217). */ currency?: Currency | null | undefined; /** * Currency Exchange Rate at the time entity was recorded/generated. */ currencyRate?: number | null | undefined; /** * The type of expense. */ type?: ExpenseType | null | undefined; /** * The memo of the expense. */ memo?: string | null | undefined; taxRate?: LinkedTaxRateInput | undefined; /** * Amounts are including tax */ taxInclusive?: boolean | null | undefined; /** * Subtotal amount, normally before tax. */ subTotal?: number | null | undefined; /** * Total tax amount applied to this transaction. */ totalTax?: number | null | undefined; /** * The total amount of the expense line item. */ totalAmount?: number | null | undefined; /** * A list of linked tracking categories. */ trackingCategories?: Array | null | undefined; /** * Expense line items linked to this expense. */ lineItems: Array; /** * Optional reference identifier for the transaction. */ reference?: string | null | undefined; /** * URL link to a source document - shown as 'Go to [appName]' in the downstream app. Currently only supported for Xero. */ sourceDocumentUrl?: string | null | undefined; customFields?: Array | undefined; /** * Expense status */ status?: ExpenseStatus | null | undefined; /** * A binary value used to detect updates to a object and prevent data conflicts. It is incremented each time an update is made to the object. */ rowVersion?: string | null | undefined; /** * The pass_through property allows passing service-specific, custom data or structured modifications in request body when creating or updating resources. */ passThrough?: Array | undefined; }; /** @internal */ export const ExpensePaymentType$inboundSchema: z.ZodType< ExpensePaymentType, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => openEnums.inboundSchema(ExpensePaymentType) ); /** @internal */ export const ExpensePaymentType$outboundSchema: z.ZodType< string, z.ZodTypeDef, ExpensePaymentType > = /* @__PURE__ */ lazySchema$(() => openEnums.outboundSchema(ExpensePaymentType) ); /** @internal */ export const ExpenseType$inboundSchema: z.ZodType< ExpenseType, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => openEnums.inboundSchema(ExpenseType)); /** @internal */ export const ExpenseType$outboundSchema: z.ZodType< string, z.ZodTypeDef, ExpenseType > = /* @__PURE__ */ lazySchema$(() => openEnums.outboundSchema(ExpenseType)); /** @internal */ export const ExpenseStatus$inboundSchema: z.ZodType< ExpenseStatus, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => openEnums.inboundSchema(ExpenseStatus)); /** @internal */ export const ExpenseStatus$outboundSchema: z.ZodType< string, z.ZodTypeDef, ExpenseStatus > = /* @__PURE__ */ lazySchema$(() => openEnums.outboundSchema(ExpenseStatus)); /** @internal */ export const Expense$inboundSchema: z.ZodType = /* @__PURE__ */ lazySchema$(() => z.object({ id: types.optional(types.string()), display_id: z.nullable(types.string()).optional(), number: z.nullable(types.string()).optional(), transaction_date: types.nullable(types.date()), account_id: types.optional(types.string()), account: z.nullable(LinkedFinancialAccount$inboundSchema).optional(), supplier_id: types.optional(types.string()), supplier: z.nullable(LinkedSupplier$inboundSchema).optional(), company_id: z.nullable(types.string()).optional(), location: z.nullable(LinkedLocation$inboundSchema).optional(), department_id: z.nullable(types.string()).optional(), department: z.nullable(LinkedDepartment$inboundSchema).optional(), payment_type: z.nullable(ExpensePaymentType$inboundSchema).optional(), currency: z.nullable(Currency$inboundSchema).optional(), currency_rate: z.nullable(types.number()).optional(), type: z.nullable(ExpenseType$inboundSchema).optional(), memo: z.nullable(types.string()).optional(), tax_rate: types.optional(LinkedTaxRate$inboundSchema), tax_inclusive: z.nullable(types.boolean()).optional(), sub_total: z.nullable(types.number()).optional(), total_tax: z.nullable(types.number()).optional(), total_amount: z.nullable(types.number()).optional(), tracking_categories: z.nullable( z.array(types.nullable(LinkedTrackingCategory$inboundSchema)), ).optional(), line_items: z.array(ExpenseLineItem$inboundSchema), reference: z.nullable(types.string()).optional(), source_document_url: z.nullable(types.string()).optional(), custom_fields: types.optional(z.array(CustomField$inboundSchema)), custom_mappings: z.nullable(z.record(z.any())).optional(), status: z.nullable(ExpenseStatus$inboundSchema).optional(), updated_at: z.nullable(types.date()).optional(), created_at: z.nullable(types.date()).optional(), row_version: z.nullable(types.string()).optional(), updated_by: z.nullable(types.string()).optional(), created_by: z.nullable(types.string()).optional(), pass_through: types.optional(z.array(PassThroughBody$inboundSchema)), }).transform((v) => { return remap$(v, { "display_id": "displayId", "transaction_date": "transactionDate", "account_id": "accountId", "supplier_id": "supplierId", "company_id": "companyId", "department_id": "departmentId", "payment_type": "paymentType", "currency_rate": "currencyRate", "tax_rate": "taxRate", "tax_inclusive": "taxInclusive", "sub_total": "subTotal", "total_tax": "totalTax", "total_amount": "totalAmount", "tracking_categories": "trackingCategories", "line_items": "lineItems", "source_document_url": "sourceDocumentUrl", "custom_fields": "customFields", "custom_mappings": "customMappings", "updated_at": "updatedAt", "created_at": "createdAt", "row_version": "rowVersion", "updated_by": "updatedBy", "created_by": "createdBy", "pass_through": "passThrough", }); }) ); export function expenseFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Expense$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Expense' from JSON`, ); } /** @internal */ export type ExpenseInput$Outbound = { display_id?: string | null | undefined; number?: string | null | undefined; transaction_date: string | null; account_id?: string | undefined; account?: LinkedFinancialAccountInput$Outbound | null | undefined; supplier_id?: string | undefined; supplier?: LinkedSupplierInput$Outbound | null | undefined; company_id?: string | null | undefined; location?: LinkedLocationInput$Outbound | null | undefined; department_id?: string | null | undefined; department?: LinkedDepartmentInput$Outbound | null | undefined; payment_type?: string | null | undefined; currency?: string | null | undefined; currency_rate?: number | null | undefined; type?: string | null | undefined; memo?: string | null | undefined; tax_rate?: LinkedTaxRateInput$Outbound | undefined; tax_inclusive?: boolean | null | undefined; sub_total?: number | null | undefined; total_tax?: number | null | undefined; total_amount?: number | null | undefined; tracking_categories?: | Array | null | undefined; line_items: Array; reference?: string | null | undefined; source_document_url?: string | null | undefined; custom_fields?: Array | undefined; status?: string | null | undefined; row_version?: string | null | undefined; pass_through?: Array | undefined; }; /** @internal */ export const ExpenseInput$outboundSchema: z.ZodType< ExpenseInput$Outbound, z.ZodTypeDef, ExpenseInput > = /* @__PURE__ */ lazySchema$(() => z.object({ displayId: z.nullable(z.string()).optional(), number: z.nullable(z.string()).optional(), transactionDate: z.nullable(z.date().transform(v => v.toISOString())), accountId: z.string().optional(), account: z.nullable(LinkedFinancialAccountInput$outboundSchema).optional(), supplierId: z.string().optional(), supplier: z.nullable(LinkedSupplierInput$outboundSchema).optional(), companyId: z.nullable(z.string()).optional(), location: z.nullable(LinkedLocationInput$outboundSchema).optional(), departmentId: z.nullable(z.string()).optional(), department: z.nullable(LinkedDepartmentInput$outboundSchema).optional(), paymentType: z.nullable(ExpensePaymentType$outboundSchema).optional(), currency: z.nullable(Currency$outboundSchema).optional(), currencyRate: z.nullable(z.number()).optional(), type: z.nullable(ExpenseType$outboundSchema).optional(), memo: z.nullable(z.string()).optional(), taxRate: LinkedTaxRateInput$outboundSchema.optional(), taxInclusive: z.nullable(z.boolean()).optional(), subTotal: z.nullable(z.number()).optional(), totalTax: z.nullable(z.number()).optional(), totalAmount: z.nullable(z.number()).optional(), trackingCategories: z.nullable( z.array(z.nullable(LinkedTrackingCategory$outboundSchema)), ).optional(), lineItems: z.array(ExpenseLineItemInput$outboundSchema), reference: z.nullable(z.string()).optional(), sourceDocumentUrl: z.nullable(z.string()).optional(), customFields: z.array(CustomField$outboundSchema).optional(), status: z.nullable(ExpenseStatus$outboundSchema).optional(), rowVersion: z.nullable(z.string()).optional(), passThrough: z.array(PassThroughBody$outboundSchema).optional(), }).transform((v) => { return remap$(v, { displayId: "display_id", transactionDate: "transaction_date", accountId: "account_id", supplierId: "supplier_id", companyId: "company_id", departmentId: "department_id", paymentType: "payment_type", currencyRate: "currency_rate", taxRate: "tax_rate", taxInclusive: "tax_inclusive", subTotal: "sub_total", totalTax: "total_tax", totalAmount: "total_amount", trackingCategories: "tracking_categories", lineItems: "line_items", sourceDocumentUrl: "source_document_url", customFields: "custom_fields", rowVersion: "row_version", passThrough: "pass_through", }); }) ); export function expenseInputToJSON(expenseInput: ExpenseInput): string { return JSON.stringify(ExpenseInput$outboundSchema.parse(expenseInput)); }