/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { Currency, Currency$inboundSchema, Currency$outboundSchema, } from "./currency.js"; import { CustomMappings, CustomMappings$inboundSchema, CustomMappings$Outbound, CustomMappings$outboundSchema, } from "./custommappings.js"; import { EcommerceAddress, EcommerceAddress$inboundSchema, EcommerceAddress$Outbound, EcommerceAddress$outboundSchema, } from "./ecommerceaddress.js"; import { EcommerceDiscount, EcommerceDiscount$inboundSchema, EcommerceDiscount$Outbound, EcommerceDiscount$outboundSchema, } from "./ecommercediscount.js"; import { EcommerceOrderLineItem, EcommerceOrderLineItem$inboundSchema, EcommerceOrderLineItem$Outbound, EcommerceOrderLineItem$outboundSchema, } from "./ecommerceorderlineitem.js"; import { EcommerceOrderStatus, EcommerceOrderStatus$inboundSchema, EcommerceOrderStatus$outboundSchema, } from "./ecommerceorderstatus.js"; import { LinkedEcommerceCustomer, LinkedEcommerceCustomer$inboundSchema, LinkedEcommerceCustomer$Outbound, LinkedEcommerceCustomer$outboundSchema, } from "./linkedecommercecustomer.js"; import { TrackingItem, TrackingItem$inboundSchema, TrackingItem$Outbound, TrackingItem$outboundSchema, } from "./trackingitem.js"; /** * Current payment status of the order. */ export const EcommerceOrderPaymentStatus = { Pending: "pending", Authorized: "authorized", Paid: "paid", Partial: "partial", Refunded: "refunded", Voided: "voided", Unknown: "unknown", } as const; /** * Current payment status of the order. */ export type EcommerceOrderPaymentStatus = ClosedEnum< typeof EcommerceOrderPaymentStatus >; /** * Current fulfillment status of the order. */ export const FulfillmentStatus = { Pending: "pending", Shipped: "shipped", Partial: "partial", Delivered: "delivered", Cancelled: "cancelled", Returned: "returned", Unknown: "unknown", } as const; /** * Current fulfillment status of the order. */ export type FulfillmentStatus = ClosedEnum; export type EcommerceOrder = { /** * A unique identifier for an object. */ id: string; /** * Order number, if any. */ orderNumber?: string | 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; discounts?: Array | undefined; /** * Sub-total amount, normally before tax. */ subTotal?: string | null | undefined; /** * Shipping cost, if any. */ shippingCost?: string | null | undefined; /** * Coupon discount, if any. */ couponDiscount?: string | null | undefined; /** * Total discount, if any. */ totalDiscount?: string | null | undefined; /** * Total tax, if any. */ totalTax?: string | null | undefined; /** * Total amount due. */ totalAmount?: string | null | undefined; /** * Refunded amount, if any. */ refundedAmount?: string | null | undefined; /** * Current status of the order. */ status?: EcommerceOrderStatus | null | undefined; /** * Current payment status of the order. */ paymentStatus?: EcommerceOrderPaymentStatus | null | undefined; /** * Current fulfillment status of the order. */ fulfillmentStatus?: FulfillmentStatus | null | undefined; /** * Payment method used for this order. */ paymentMethod?: string | null | undefined; /** * The customer this entity is linked to. */ customer?: LinkedEcommerceCustomer | undefined; /** * An object representing a shipping or billing address. */ billingAddress?: EcommerceAddress | undefined; /** * An object representing a shipping or billing address. */ shippingAddress?: EcommerceAddress | undefined; tracking?: Array | undefined; lineItems?: Array | undefined; /** * Note for the order. */ note?: string | null | undefined; /** * When custom mappings are configured on the resource, the result is included here. */ customMappings?: CustomMappings | null | undefined; /** * The date and time when the object was created. */ createdAt?: Date | null | undefined; /** * The date and time when the object was last updated. */ updatedAt?: Date | null | undefined; }; /** @internal */ export const EcommerceOrderPaymentStatus$inboundSchema: z.ZodNativeEnum< typeof EcommerceOrderPaymentStatus > = z.nativeEnum(EcommerceOrderPaymentStatus); /** @internal */ export const EcommerceOrderPaymentStatus$outboundSchema: z.ZodNativeEnum< typeof EcommerceOrderPaymentStatus > = EcommerceOrderPaymentStatus$inboundSchema; /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace EcommerceOrderPaymentStatus$ { /** @deprecated use `EcommerceOrderPaymentStatus$inboundSchema` instead. */ export const inboundSchema = EcommerceOrderPaymentStatus$inboundSchema; /** @deprecated use `EcommerceOrderPaymentStatus$outboundSchema` instead. */ export const outboundSchema = EcommerceOrderPaymentStatus$outboundSchema; } /** @internal */ export const FulfillmentStatus$inboundSchema: z.ZodNativeEnum< typeof FulfillmentStatus > = z.nativeEnum(FulfillmentStatus); /** @internal */ export const FulfillmentStatus$outboundSchema: z.ZodNativeEnum< typeof FulfillmentStatus > = FulfillmentStatus$inboundSchema; /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace FulfillmentStatus$ { /** @deprecated use `FulfillmentStatus$inboundSchema` instead. */ export const inboundSchema = FulfillmentStatus$inboundSchema; /** @deprecated use `FulfillmentStatus$outboundSchema` instead. */ export const outboundSchema = FulfillmentStatus$outboundSchema; } /** @internal */ export const EcommerceOrder$inboundSchema: z.ZodType< EcommerceOrder, z.ZodTypeDef, unknown > = z.object({ id: z.string(), order_number: z.nullable(z.string()).optional(), currency: z.nullable(Currency$inboundSchema).optional(), discounts: z.array(EcommerceDiscount$inboundSchema).optional(), sub_total: z.nullable(z.string()).optional(), shipping_cost: z.nullable(z.string()).optional(), coupon_discount: z.nullable(z.string()).optional(), total_discount: z.nullable(z.string()).optional(), total_tax: z.nullable(z.string()).optional(), total_amount: z.nullable(z.string()).optional(), refunded_amount: z.nullable(z.string()).optional(), status: z.nullable(EcommerceOrderStatus$inboundSchema).optional(), payment_status: z.nullable(EcommerceOrderPaymentStatus$inboundSchema) .optional(), fulfillment_status: z.nullable(FulfillmentStatus$inboundSchema).optional(), payment_method: z.nullable(z.string()).optional(), customer: LinkedEcommerceCustomer$inboundSchema.optional(), billing_address: EcommerceAddress$inboundSchema.optional(), shipping_address: EcommerceAddress$inboundSchema.optional(), tracking: z.array(TrackingItem$inboundSchema).optional(), line_items: z.array(EcommerceOrderLineItem$inboundSchema).optional(), note: z.nullable(z.string()).optional(), custom_mappings: z.nullable(CustomMappings$inboundSchema).optional(), created_at: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), updated_at: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), }).transform((v) => { return remap$(v, { "order_number": "orderNumber", "sub_total": "subTotal", "shipping_cost": "shippingCost", "coupon_discount": "couponDiscount", "total_discount": "totalDiscount", "total_tax": "totalTax", "total_amount": "totalAmount", "refunded_amount": "refundedAmount", "payment_status": "paymentStatus", "fulfillment_status": "fulfillmentStatus", "payment_method": "paymentMethod", "billing_address": "billingAddress", "shipping_address": "shippingAddress", "line_items": "lineItems", "custom_mappings": "customMappings", "created_at": "createdAt", "updated_at": "updatedAt", }); }); /** @internal */ export type EcommerceOrder$Outbound = { id: string; order_number?: string | null | undefined; currency?: string | null | undefined; discounts?: Array | undefined; sub_total?: string | null | undefined; shipping_cost?: string | null | undefined; coupon_discount?: string | null | undefined; total_discount?: string | null | undefined; total_tax?: string | null | undefined; total_amount?: string | null | undefined; refunded_amount?: string | null | undefined; status?: string | null | undefined; payment_status?: string | null | undefined; fulfillment_status?: string | null | undefined; payment_method?: string | null | undefined; customer?: LinkedEcommerceCustomer$Outbound | undefined; billing_address?: EcommerceAddress$Outbound | undefined; shipping_address?: EcommerceAddress$Outbound | undefined; tracking?: Array | undefined; line_items?: Array | undefined; note?: string | null | undefined; custom_mappings?: CustomMappings$Outbound | null | undefined; created_at?: string | null | undefined; updated_at?: string | null | undefined; }; /** @internal */ export const EcommerceOrder$outboundSchema: z.ZodType< EcommerceOrder$Outbound, z.ZodTypeDef, EcommerceOrder > = z.object({ id: z.string(), orderNumber: z.nullable(z.string()).optional(), currency: z.nullable(Currency$outboundSchema).optional(), discounts: z.array(EcommerceDiscount$outboundSchema).optional(), subTotal: z.nullable(z.string()).optional(), shippingCost: z.nullable(z.string()).optional(), couponDiscount: z.nullable(z.string()).optional(), totalDiscount: z.nullable(z.string()).optional(), totalTax: z.nullable(z.string()).optional(), totalAmount: z.nullable(z.string()).optional(), refundedAmount: z.nullable(z.string()).optional(), status: z.nullable(EcommerceOrderStatus$outboundSchema).optional(), paymentStatus: z.nullable(EcommerceOrderPaymentStatus$outboundSchema) .optional(), fulfillmentStatus: z.nullable(FulfillmentStatus$outboundSchema).optional(), paymentMethod: z.nullable(z.string()).optional(), customer: LinkedEcommerceCustomer$outboundSchema.optional(), billingAddress: EcommerceAddress$outboundSchema.optional(), shippingAddress: EcommerceAddress$outboundSchema.optional(), tracking: z.array(TrackingItem$outboundSchema).optional(), lineItems: z.array(EcommerceOrderLineItem$outboundSchema).optional(), note: z.nullable(z.string()).optional(), customMappings: z.nullable(CustomMappings$outboundSchema).optional(), createdAt: z.nullable(z.date().transform(v => v.toISOString())).optional(), updatedAt: z.nullable(z.date().transform(v => v.toISOString())).optional(), }).transform((v) => { return remap$(v, { orderNumber: "order_number", subTotal: "sub_total", shippingCost: "shipping_cost", couponDiscount: "coupon_discount", totalDiscount: "total_discount", totalTax: "total_tax", totalAmount: "total_amount", refundedAmount: "refunded_amount", paymentStatus: "payment_status", fulfillmentStatus: "fulfillment_status", paymentMethod: "payment_method", billingAddress: "billing_address", shippingAddress: "shipping_address", lineItems: "line_items", customMappings: "custom_mappings", createdAt: "created_at", updatedAt: "updated_at", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace EcommerceOrder$ { /** @deprecated use `EcommerceOrder$inboundSchema` instead. */ export const inboundSchema = EcommerceOrder$inboundSchema; /** @deprecated use `EcommerceOrder$outboundSchema` instead. */ export const outboundSchema = EcommerceOrder$outboundSchema; /** @deprecated use `EcommerceOrder$Outbound` instead. */ export type Outbound = EcommerceOrder$Outbound; } export function ecommerceOrderToJSON(ecommerceOrder: EcommerceOrder): string { return JSON.stringify(EcommerceOrder$outboundSchema.parse(ecommerceOrder)); } export function ecommerceOrderFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => EcommerceOrder$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'EcommerceOrder' from JSON`, ); }