/* * 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 { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { DistanceUnitEnum, DistanceUnitEnum$inboundSchema, DistanceUnitEnum$outboundSchema, } from "./distanceunitenum.js"; import { ParcelExtra, ParcelExtra$inboundSchema, ParcelExtra$Outbound, ParcelExtra$outboundSchema, } from "./parcelextra.js"; import { ParcelTemplateEnumSet, ParcelTemplateEnumSet$inboundSchema, ParcelTemplateEnumSet$Outbound, ParcelTemplateEnumSet$outboundSchema, } from "./parceltemplateenumset.js"; import { WeightUnitEnum, WeightUnitEnum$inboundSchema, WeightUnitEnum$outboundSchema, } from "./weightunitenum.js"; /** * A Parcel will only be valid when all required values have been sent and validated successfully. */ export const ObjectState = { Valid: "VALID", } as const; /** * A Parcel will only be valid when all required values have been sent and validated successfully. */ export type ObjectState = ClosedEnum; export type Parcel = { /** * An object holding optional extra services to be requested for each parcel in a multi-piece shipment. * * @remarks * See the Parcel Extra table below for all available services. */ extra?: ParcelExtra | undefined; metadata?: string | undefined; /** * The unit used for weight. */ massUnit: WeightUnitEnum; /** * Weight of the parcel. Up to six digits in front and four digits after the decimal separator are accepted. */ weight: string; /** * The measure unit used for length, width and height. */ distanceUnit: DistanceUnitEnum; /** * Height of the parcel. Up to six digits in front and four digits after the decimal separator are accepted. */ height: string; /** * Length of the Parcel. Up to six digits in front and four digits after the decimal separator are accepted. */ length: string; /** * Width of the Parcel. Up to six digits in front and four digits after the decimal separator are accepted. */ width: string; /** * Date and time of Parcel creation. */ objectCreated?: Date | undefined; /** * Unique identifier of the given Parcel object. This ID is required to create a Shipment object. */ objectId?: string | undefined; /** * Username of the user who created the Parcel object. */ objectOwner?: string | undefined; /** * A Parcel will only be valid when all required values have been sent and validated successfully. */ objectState?: ObjectState | undefined; /** * Date and time of last Parcel update. Since you cannot update Parcels after they were created, this time stamp reflects the time when the Parcel was changed by Shippo's systems for the last time, e.g., during sorting the dimensions given. */ objectUpdated?: Date | undefined; /** * If template is passed, `length`, `width`, `height`, and `distance_unit` are not required */ template?: ParcelTemplateEnumSet | undefined; /** * Indicates whether the object has been created in test mode. */ test?: boolean | undefined; }; /** @internal */ export const ObjectState$inboundSchema: z.ZodMiniEnum = z .enum(ObjectState); /** @internal */ export const ObjectState$outboundSchema: z.ZodMiniEnum = ObjectState$inboundSchema; /** @internal */ export const Parcel$inboundSchema: z.ZodMiniType = z.pipe( z.object({ extra: z.optional(ParcelExtra$inboundSchema), metadata: z.optional(z.string()), mass_unit: WeightUnitEnum$inboundSchema, weight: z.string(), distance_unit: DistanceUnitEnum$inboundSchema, height: z.string(), length: z.string(), width: z.string(), object_created: z.optional( z.pipe(z.iso.datetime({ offset: true }), z.transform(v => new Date(v))), ), object_id: z.optional(z.string()), object_owner: z.optional(z.string()), object_state: z.optional(ObjectState$inboundSchema), object_updated: z.optional( z.pipe(z.iso.datetime({ offset: true }), z.transform(v => new Date(v))), ), template: z.optional(ParcelTemplateEnumSet$inboundSchema), test: z.optional(z.boolean()), }), z.transform((v) => { return remap$(v, { "mass_unit": "massUnit", "distance_unit": "distanceUnit", "object_created": "objectCreated", "object_id": "objectId", "object_owner": "objectOwner", "object_state": "objectState", "object_updated": "objectUpdated", }); }), ); /** @internal */ export type Parcel$Outbound = { extra?: ParcelExtra$Outbound | undefined; metadata?: string | undefined; mass_unit: string; weight: string; distance_unit: string; height: string; length: string; width: string; object_created?: string | undefined; object_id?: string | undefined; object_owner?: string | undefined; object_state?: string | undefined; object_updated?: string | undefined; template?: ParcelTemplateEnumSet$Outbound | undefined; test?: boolean | undefined; }; /** @internal */ export const Parcel$outboundSchema: z.ZodMiniType = z .pipe( z.object({ extra: z.optional(ParcelExtra$outboundSchema), metadata: z.optional(z.string()), massUnit: WeightUnitEnum$outboundSchema, weight: z.string(), distanceUnit: DistanceUnitEnum$outboundSchema, height: z.string(), length: z.string(), width: z.string(), objectCreated: z.optional( z.pipe(z.date(), z.transform(v => v.toISOString())), ), objectId: z.optional(z.string()), objectOwner: z.optional(z.string()), objectState: z.optional(ObjectState$outboundSchema), objectUpdated: z.optional( z.pipe(z.date(), z.transform(v => v.toISOString())), ), template: z.optional(ParcelTemplateEnumSet$outboundSchema), test: z.optional(z.boolean()), }), z.transform((v) => { return remap$(v, { massUnit: "mass_unit", distanceUnit: "distance_unit", objectCreated: "object_created", objectId: "object_id", objectOwner: "object_owner", objectState: "object_state", objectUpdated: "object_updated", }); }), ); export function parcelToJSON(parcel: Parcel): string { return JSON.stringify(Parcel$outboundSchema.parse(parcel)); } export function parcelFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Parcel$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Parcel' from JSON`, ); }