/* * 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 { Address, Address$inboundSchema, Address$Outbound, Address$outboundSchema, } from "./address.js"; import { Currency, Currency$inboundSchema, Currency$outboundSchema, } from "./currency.js"; import { CustomField, CustomField$inboundSchema, CustomField$Outbound, CustomField$outboundSchema, } from "./customfield.js"; import { InvoiceLineItem, InvoiceLineItem$inboundSchema, InvoiceLineItemInput, InvoiceLineItemInput$Outbound, InvoiceLineItemInput$outboundSchema, } from "./invoicelineitem.js"; import { LinkedCustomer, LinkedCustomer$inboundSchema, } from "./linkedcustomer.js"; import { LinkedCustomerInput, LinkedCustomerInput$Outbound, LinkedCustomerInput$outboundSchema, } from "./linkedcustomerinput.js"; import { LinkedTrackingCategory, LinkedTrackingCategory$inboundSchema, LinkedTrackingCategory$Outbound, LinkedTrackingCategory$outboundSchema, } from "./linkedtrackingcategory.js"; import { PassThroughBody, PassThroughBody$inboundSchema, PassThroughBody$Outbound, PassThroughBody$outboundSchema, } from "./passthroughbody.js"; /** * Sales order status, in order of precedence: `cancelled`; `closed` (the order is closed or completed, whether or not it was billed); `invoiced` (fully billed but not yet closed); `back_ordered`; `on_hold` (including credit hold); `draft` (including pending approval); `open` (every other active state, including partially shipped and partially invoiced); `other` for states that fit none of these. */ export const SalesOrderStatus = { Draft: "draft", Open: "open", OnHold: "on_hold", BackOrdered: "back_ordered", Invoiced: "invoiced", Closed: "closed", Cancelled: "cancelled", Other: "other", } as const; /** * Sales order status, in order of precedence: `cancelled`; `closed` (the order is closed or completed, whether or not it was billed); `invoiced` (fully billed but not yet closed); `back_ordered`; `on_hold` (including credit hold); `draft` (including pending approval); `open` (every other active state, including partially shipped and partially invoiced); `other` for states that fit none of these. */ export type SalesOrderStatus = OpenEnum; export type SalesOrder = { /** * A unique identifier for an object. */ id?: string | undefined; /** * The third-party API ID of original entity */ downstreamId?: string | null | undefined; /** * Sales order number, as assigned by the accounting system. */ number?: string | null | undefined; /** * The customer this entity is linked to. */ customer?: LinkedCustomer | null | undefined; /** * The unique identifier for the quote. */ quoteId?: string | null | undefined; /** * ID of the invoice created from this sales order. Populated when the accounting system records a single invoice on the order (see the connector gotchas); null when the order has not been invoiced, or when it was invoiced in parts and the system keeps no single link. */ invoiceId?: string | null | undefined; /** * The company ID the transaction belongs to */ companyId?: string | null | undefined; /** * The ID of the department */ departmentId?: string | null | undefined; /** * The ID of the location */ locationId?: string | null | undefined; /** * The unique identifier for the linked project. */ projectId?: string | undefined; /** * The ID of the subsidiary */ subsidiaryId?: string | null | undefined; /** * Date the sales order was placed - YYYY-MM-DD. */ orderDate?: Date | null | undefined; /** * The requested delivery date: the date the customer asked to receive the goods or services - YYYY-MM-DD. Promised ship dates and payment due dates are not mapped here. */ deliveryDate?: Date | null | undefined; /** * The order or transaction type of the sales order, as configured in the accounting system. On create, selects the type to create when the system supports several; omit to use the connection default. See the connector gotchas for the values each system accepts. */ orderType?: string | null | undefined; /** * Payment terms of the sales order. */ terms?: string | null | undefined; /** * The ID of the payment terms */ termsId?: string | null | undefined; /** * A PO Number uniquely identifies a purchase order and is generally defined by the buyer. The buyer will match the PO number in the invoice to the Purchase Order. */ poNumber?: string | null | undefined; /** * Optional reference identifier for the transaction. */ reference?: string | null | undefined; /** * Sales order status, in order of precedence: `cancelled`; `closed` (the order is closed or completed, whether or not it was billed); `invoiced` (fully billed but not yet closed); `back_ordered`; `on_hold` (including credit hold); `draft` (including pending approval); `open` (every other active state, including partially shipped and partially invoiced); `other` for states that fit none of these. */ status?: SalesOrderStatus | 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; /** * Amounts are including tax */ taxInclusive?: boolean | null | undefined; /** * Sub-total amount, normally before tax. */ subTotal?: number | null | undefined; /** * Total tax amount applied to this sales order. */ totalTax?: number | null | undefined; /** * Applicable tax id/code override if tax is not supplied on a line item basis. */ taxCode?: string | null | undefined; /** * Discount percentage applied to this sales order. */ discountPercentage?: number | null | undefined; /** * Discount amount applied to this sales order. */ discountAmount?: number | null | undefined; /** * Total amount of the sales order, including tax. */ total?: number | null | undefined; /** * Amount of the sales order not yet invoiced. Not the amount owed: see `balance` on the invoices created from the order for that. */ unbilledAmount?: number | null | undefined; /** * Shipping method or carrier code for the order. */ shippingMethod?: string | null | undefined; /** * Payment method used for the transaction, such as cash, credit card, bank transfer, or check */ paymentMethod?: string | null | undefined; /** * Message to the customer, shown on the sales order. */ customerMemo?: string | null | undefined; /** * Internal notes for the sales order, not shown to the customer. */ notes?: string | null | undefined; lineItems?: Array | undefined; billingAddress?: Address | undefined; shippingAddress?: Address | undefined; /** * A list of linked tracking categories. */ trackingCategories?: Array | null | undefined; /** * Optional sales order template */ templateId?: string | null | undefined; /** * URL link to a source document - shown as 'Go to [appName]' in the downstream app. */ sourceDocumentUrl?: string | null | undefined; /** * When custom mappings are configured on the resource, the result is included here. */ customMappings?: { [k: string]: any } | null | undefined; customFields?: Array | 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 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; /** * 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 SalesOrderInput = { /** * Sales order number, as assigned by the accounting system. */ number?: string | null | undefined; /** * The customer this entity is linked to. */ customer?: LinkedCustomerInput | null | undefined; /** * The unique identifier for the quote. */ quoteId?: string | null | undefined; /** * The company ID the transaction belongs to */ companyId?: string | null | undefined; /** * The ID of the department */ departmentId?: string | null | undefined; /** * The ID of the location */ locationId?: string | null | undefined; /** * The unique identifier for the linked project. */ projectId?: string | undefined; /** * The ID of the subsidiary */ subsidiaryId?: string | null | undefined; /** * Date the sales order was placed - YYYY-MM-DD. */ orderDate?: Date | null | undefined; /** * The requested delivery date: the date the customer asked to receive the goods or services - YYYY-MM-DD. Promised ship dates and payment due dates are not mapped here. */ deliveryDate?: Date | null | undefined; /** * The order or transaction type of the sales order, as configured in the accounting system. On create, selects the type to create when the system supports several; omit to use the connection default. See the connector gotchas for the values each system accepts. */ orderType?: string | null | undefined; /** * Payment terms of the sales order. */ terms?: string | null | undefined; /** * The ID of the payment terms */ termsId?: string | null | undefined; /** * A PO Number uniquely identifies a purchase order and is generally defined by the buyer. The buyer will match the PO number in the invoice to the Purchase Order. */ poNumber?: string | null | undefined; /** * Optional reference identifier for the transaction. */ reference?: string | null | undefined; /** * Sales order status, in order of precedence: `cancelled`; `closed` (the order is closed or completed, whether or not it was billed); `invoiced` (fully billed but not yet closed); `back_ordered`; `on_hold` (including credit hold); `draft` (including pending approval); `open` (every other active state, including partially shipped and partially invoiced); `other` for states that fit none of these. */ status?: SalesOrderStatus | 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; /** * Amounts are including tax */ taxInclusive?: boolean | null | undefined; /** * Sub-total amount, normally before tax. */ subTotal?: number | null | undefined; /** * Total tax amount applied to this sales order. */ totalTax?: number | null | undefined; /** * Applicable tax id/code override if tax is not supplied on a line item basis. */ taxCode?: string | null | undefined; /** * Discount percentage applied to this sales order. */ discountPercentage?: number | null | undefined; /** * Discount amount applied to this sales order. */ discountAmount?: number | null | undefined; /** * Total amount of the sales order, including tax. */ total?: number | null | undefined; /** * Shipping method or carrier code for the order. */ shippingMethod?: string | null | undefined; /** * Payment method used for the transaction, such as cash, credit card, bank transfer, or check */ paymentMethod?: string | null | undefined; /** * Message to the customer, shown on the sales order. */ customerMemo?: string | null | undefined; /** * Internal notes for the sales order, not shown to the customer. */ notes?: string | null | undefined; lineItems?: Array | undefined; billingAddress?: Address | undefined; shippingAddress?: Address | undefined; /** * A list of linked tracking categories. */ trackingCategories?: Array | null | undefined; /** * Optional sales order template */ templateId?: string | null | undefined; /** * URL link to a source document - shown as 'Go to [appName]' in the downstream app. */ sourceDocumentUrl?: string | null | undefined; customFields?: Array | 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 SalesOrderStatus$inboundSchema: z.ZodType< SalesOrderStatus, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => openEnums.inboundSchema(SalesOrderStatus) ); /** @internal */ export const SalesOrderStatus$outboundSchema: z.ZodType< string, z.ZodTypeDef, SalesOrderStatus > = /* @__PURE__ */ lazySchema$(() => openEnums.outboundSchema(SalesOrderStatus) ); /** @internal */ export const SalesOrder$inboundSchema: z.ZodType< SalesOrder, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => z.object({ id: types.optional(types.string()), downstream_id: z.nullable(types.string()).optional(), number: z.nullable(types.string()).optional(), customer: z.nullable(LinkedCustomer$inboundSchema).optional(), quote_id: z.nullable(types.string()).optional(), invoice_id: z.nullable(types.string()).optional(), company_id: z.nullable(types.string()).optional(), department_id: z.nullable(types.string()).optional(), location_id: z.nullable(types.string()).optional(), project_id: types.optional(types.string()), subsidiary_id: z.nullable(types.string()).optional(), order_date: z.nullable(types.date()).optional(), delivery_date: z.nullable(types.date()).optional(), order_type: z.nullable(types.string()).optional(), terms: z.nullable(types.string()).optional(), terms_id: z.nullable(types.string()).optional(), po_number: z.nullable(types.string()).optional(), reference: z.nullable(types.string()).optional(), status: z.nullable(SalesOrderStatus$inboundSchema).optional(), currency: z.nullable(Currency$inboundSchema).optional(), currency_rate: z.nullable(types.number()).optional(), tax_inclusive: z.nullable(types.boolean()).optional(), sub_total: z.nullable(types.number()).optional(), total_tax: z.nullable(types.number()).optional(), tax_code: z.nullable(types.string()).optional(), discount_percentage: z.nullable(types.number()).optional(), discount_amount: z.nullable(types.number()).optional(), total: z.nullable(types.number()).optional(), unbilled_amount: z.nullable(types.number()).optional(), shipping_method: z.nullable(types.string()).optional(), payment_method: z.nullable(types.string()).optional(), customer_memo: z.nullable(types.string()).optional(), notes: z.nullable(types.string()).optional(), line_items: types.optional(z.array(InvoiceLineItem$inboundSchema)), billing_address: types.optional(Address$inboundSchema), shipping_address: types.optional(Address$inboundSchema), tracking_categories: z.nullable( z.array(types.nullable(LinkedTrackingCategory$inboundSchema)), ).optional(), template_id: z.nullable(types.string()).optional(), source_document_url: z.nullable(types.string()).optional(), custom_mappings: z.nullable(z.record(z.any())).optional(), custom_fields: types.optional(z.array(CustomField$inboundSchema)), row_version: z.nullable(types.string()).optional(), updated_by: z.nullable(types.string()).optional(), created_by: z.nullable(types.string()).optional(), updated_at: z.nullable(types.date()).optional(), created_at: z.nullable(types.date()).optional(), pass_through: types.optional(z.array(PassThroughBody$inboundSchema)), }).transform((v) => { return remap$(v, { "downstream_id": "downstreamId", "quote_id": "quoteId", "invoice_id": "invoiceId", "company_id": "companyId", "department_id": "departmentId", "location_id": "locationId", "project_id": "projectId", "subsidiary_id": "subsidiaryId", "order_date": "orderDate", "delivery_date": "deliveryDate", "order_type": "orderType", "terms_id": "termsId", "po_number": "poNumber", "currency_rate": "currencyRate", "tax_inclusive": "taxInclusive", "sub_total": "subTotal", "total_tax": "totalTax", "tax_code": "taxCode", "discount_percentage": "discountPercentage", "discount_amount": "discountAmount", "unbilled_amount": "unbilledAmount", "shipping_method": "shippingMethod", "payment_method": "paymentMethod", "customer_memo": "customerMemo", "line_items": "lineItems", "billing_address": "billingAddress", "shipping_address": "shippingAddress", "tracking_categories": "trackingCategories", "template_id": "templateId", "source_document_url": "sourceDocumentUrl", "custom_mappings": "customMappings", "custom_fields": "customFields", "row_version": "rowVersion", "updated_by": "updatedBy", "created_by": "createdBy", "updated_at": "updatedAt", "created_at": "createdAt", "pass_through": "passThrough", }); }) ); export function salesOrderFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => SalesOrder$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SalesOrder' from JSON`, ); } /** @internal */ export type SalesOrderInput$Outbound = { number?: string | null | undefined; customer?: LinkedCustomerInput$Outbound | null | undefined; quote_id?: string | null | undefined; company_id?: string | null | undefined; department_id?: string | null | undefined; location_id?: string | null | undefined; project_id?: string | undefined; subsidiary_id?: string | null | undefined; order_date?: string | null | undefined; delivery_date?: string | null | undefined; order_type?: string | null | undefined; terms?: string | null | undefined; terms_id?: string | null | undefined; po_number?: string | null | undefined; reference?: string | null | undefined; status?: string | null | undefined; currency?: string | null | undefined; currency_rate?: number | null | undefined; tax_inclusive?: boolean | null | undefined; sub_total?: number | null | undefined; total_tax?: number | null | undefined; tax_code?: string | null | undefined; discount_percentage?: number | null | undefined; discount_amount?: number | null | undefined; total?: number | null | undefined; shipping_method?: string | null | undefined; payment_method?: string | null | undefined; customer_memo?: string | null | undefined; notes?: string | null | undefined; line_items?: Array | undefined; billing_address?: Address$Outbound | undefined; shipping_address?: Address$Outbound | undefined; tracking_categories?: | Array | null | undefined; template_id?: string | null | undefined; source_document_url?: string | null | undefined; custom_fields?: Array | undefined; row_version?: string | null | undefined; pass_through?: Array | undefined; }; /** @internal */ export const SalesOrderInput$outboundSchema: z.ZodType< SalesOrderInput$Outbound, z.ZodTypeDef, SalesOrderInput > = /* @__PURE__ */ lazySchema$(() => z.object({ number: z.nullable(z.string()).optional(), customer: z.nullable(LinkedCustomerInput$outboundSchema).optional(), quoteId: z.nullable(z.string()).optional(), companyId: z.nullable(z.string()).optional(), departmentId: z.nullable(z.string()).optional(), locationId: z.nullable(z.string()).optional(), projectId: z.string().optional(), subsidiaryId: z.nullable(z.string()).optional(), orderDate: z.nullable( z.date().transform(v => v.toISOString().slice(0, "YYYY-MM-DD".length)), ).optional(), deliveryDate: z.nullable( z.date().transform(v => v.toISOString().slice(0, "YYYY-MM-DD".length)), ).optional(), orderType: z.nullable(z.string()).optional(), terms: z.nullable(z.string()).optional(), termsId: z.nullable(z.string()).optional(), poNumber: z.nullable(z.string()).optional(), reference: z.nullable(z.string()).optional(), status: z.nullable(SalesOrderStatus$outboundSchema).optional(), currency: z.nullable(Currency$outboundSchema).optional(), currencyRate: z.nullable(z.number()).optional(), taxInclusive: z.nullable(z.boolean()).optional(), subTotal: z.nullable(z.number()).optional(), totalTax: z.nullable(z.number()).optional(), taxCode: z.nullable(z.string()).optional(), discountPercentage: z.nullable(z.number()).optional(), discountAmount: z.nullable(z.number()).optional(), total: z.nullable(z.number()).optional(), shippingMethod: z.nullable(z.string()).optional(), paymentMethod: z.nullable(z.string()).optional(), customerMemo: z.nullable(z.string()).optional(), notes: z.nullable(z.string()).optional(), lineItems: z.array(InvoiceLineItemInput$outboundSchema).optional(), billingAddress: Address$outboundSchema.optional(), shippingAddress: Address$outboundSchema.optional(), trackingCategories: z.nullable( z.array(z.nullable(LinkedTrackingCategory$outboundSchema)), ).optional(), templateId: z.nullable(z.string()).optional(), sourceDocumentUrl: z.nullable(z.string()).optional(), customFields: z.array(CustomField$outboundSchema).optional(), rowVersion: z.nullable(z.string()).optional(), passThrough: z.array(PassThroughBody$outboundSchema).optional(), }).transform((v) => { return remap$(v, { quoteId: "quote_id", companyId: "company_id", departmentId: "department_id", locationId: "location_id", projectId: "project_id", subsidiaryId: "subsidiary_id", orderDate: "order_date", deliveryDate: "delivery_date", orderType: "order_type", termsId: "terms_id", poNumber: "po_number", currencyRate: "currency_rate", taxInclusive: "tax_inclusive", subTotal: "sub_total", totalTax: "total_tax", taxCode: "tax_code", discountPercentage: "discount_percentage", discountAmount: "discount_amount", shippingMethod: "shipping_method", paymentMethod: "payment_method", customerMemo: "customer_memo", lineItems: "line_items", billingAddress: "billing_address", shippingAddress: "shipping_address", trackingCategories: "tracking_categories", templateId: "template_id", sourceDocumentUrl: "source_document_url", customFields: "custom_fields", rowVersion: "row_version", passThrough: "pass_through", }); }) ); export function salesOrderInputToJSON( salesOrderInput: SalesOrderInput, ): string { return JSON.stringify(SalesOrderInput$outboundSchema.parse(salesOrderInput)); }