/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v4-mini"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { ServiceLevelWithParent, ServiceLevelWithParent$inboundSchema, ServiceLevelWithParent$Outbound, ServiceLevelWithParent$outboundSchema, } from "./servicelevelwithparent.js"; import { TrackingStatus, TrackingStatus$inboundSchema, TrackingStatus$Outbound, TrackingStatus$outboundSchema, } from "./trackingstatus.js"; import { TrackingStatusLocationBase, TrackingStatusLocationBase$inboundSchema, TrackingStatusLocationBase$Outbound, TrackingStatusLocationBase$outboundSchema, } from "./trackingstatuslocationbase.js"; export type Track = { /** * The sender address with city, state, zip and country information. */ addressFrom?: TrackingStatusLocationBase | undefined; /** * The recipient address with city, state, zip and country information. */ addressTo?: TrackingStatusLocationBase | undefined; /** * Name of the carrier of the shipment to track. See Carriers. */ carrier: string; /** * The estimated time of arrival according to the carrier, this might be updated by carriers during the life of the shipment. */ eta?: Date | undefined; messages: Array; /** * A string of up to 100 characters that can be filled with any additional information you want to attach to the object. */ metadata?: string | undefined; /** * The estimated time of arrival according to the carrier at the time the shipment first entered the system. */ originalEta?: Date | undefined; servicelevel?: ServiceLevelWithParent | undefined; /** * A list of tracking events, following the same structure as tracking_status. * * @remarks * It contains a full history of all tracking statuses, starting with the earlier tracking event first. */ trackingHistory: Array; /** * Tracking number to track. */ trackingNumber: string; /** * The latest tracking information of this shipment. */ trackingStatus?: TrackingStatus | undefined; /** * The object_id of the transaction associated with this tracking object. * * @remarks * This field is visible only to the object owner of the transaction. */ transaction?: string | undefined; }; /** @internal */ export const Track$inboundSchema: z.ZodMiniType = z.pipe( z.object({ address_from: z.optional(TrackingStatusLocationBase$inboundSchema), address_to: z.optional(TrackingStatusLocationBase$inboundSchema), carrier: z.string(), eta: z.optional(z.pipe( z.iso.datetime({ offset: true }), z.transform(v => new Date(v)), )), messages: z.array(z.string()), metadata: z.optional(z.string()), original_eta: z.optional( z.pipe(z.iso.datetime({ offset: true }), z.transform(v => new Date(v))), ), servicelevel: z.optional(ServiceLevelWithParent$inboundSchema), tracking_history: z.array(TrackingStatus$inboundSchema), tracking_number: z.string(), tracking_status: z.optional(TrackingStatus$inboundSchema), transaction: z.optional(z.string()), }), z.transform((v) => { return remap$(v, { "address_from": "addressFrom", "address_to": "addressTo", "original_eta": "originalEta", "tracking_history": "trackingHistory", "tracking_number": "trackingNumber", "tracking_status": "trackingStatus", }); }), ); /** @internal */ export type Track$Outbound = { address_from?: TrackingStatusLocationBase$Outbound | undefined; address_to?: TrackingStatusLocationBase$Outbound | undefined; carrier: string; eta?: string | undefined; messages: Array; metadata?: string | undefined; original_eta?: string | undefined; servicelevel?: ServiceLevelWithParent$Outbound | undefined; tracking_history: Array; tracking_number: string; tracking_status?: TrackingStatus$Outbound | undefined; transaction?: string | undefined; }; /** @internal */ export const Track$outboundSchema: z.ZodMiniType = z .pipe( z.object({ addressFrom: z.optional(TrackingStatusLocationBase$outboundSchema), addressTo: z.optional(TrackingStatusLocationBase$outboundSchema), carrier: z.string(), eta: z.optional(z.pipe(z.date(), z.transform(v => v.toISOString()))), messages: z.array(z.string()), metadata: z.optional(z.string()), originalEta: z.optional( z.pipe(z.date(), z.transform(v => v.toISOString())), ), servicelevel: z.optional(ServiceLevelWithParent$outboundSchema), trackingHistory: z.array(TrackingStatus$outboundSchema), trackingNumber: z.string(), trackingStatus: z.optional(TrackingStatus$outboundSchema), transaction: z.optional(z.string()), }), z.transform((v) => { return remap$(v, { addressFrom: "address_from", addressTo: "address_to", originalEta: "original_eta", trackingHistory: "tracking_history", trackingNumber: "tracking_number", trackingStatus: "tracking_status", }); }), ); export function trackToJSON(track: Track): string { return JSON.stringify(Track$outboundSchema.parse(track)); } export function trackFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Track$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Track' from JSON`, ); }