/* * 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 { ResponseMessage, ResponseMessage$inboundSchema, } from "./responsemessage.js"; import { ServiceLevelWithParent, ServiceLevelWithParent$inboundSchema, } from "./servicelevelwithparent.js"; export const Attributes = { Bestvalue: "BESTVALUE", Cheapest: "CHEAPEST", Fastest: "FASTEST", } as const; export type Attributes = ClosedEnum; export type Rate = { /** * Final Rate price, expressed in the currency used in the sender's country. */ amount: string; /** * Final Rate price, expressed in the currency used in the recipient's country. */ amountLocal: string; /** * Currency used in the sender's country, refers to `amount`. * * @remarks * The official ISO 4217 currency codes are used, e.g. `USD` or `EUR`. */ currency: string; /** * Currency used in the recipient's country, refers to `amount_local`. * * @remarks * The official ISO 4217 currency codes are used, e.g. `USD` or "EUR". */ currencyLocal: string; /** * Predicted time the carrier will deliver the package in the destination's local time zone. In the format `HH:MM:SS`. */ arrivesBy?: string | undefined; /** * An array containing specific attributes of this Rate in context of the entire shipment. * * @remarks * Attributes can be assigned `CHEAPEST`, `FASTEST`, or `BESTVALUE`. */ attributes: Array; /** * Object ID of the carrier account that has been used to retrieve the rate. */ carrierAccount: string; /** * Further clarification of the transit times. * * @remarks * Often, this includes notes that the transit time as given in "days" is only an average, not a guaranteed time. */ durationTerms?: string | undefined; /** * Estimated transit time (duration) in days of the Parcel at the given servicelevel. * * @remarks * Please note that this is not binding, but only an average value as given by the provider. * Shippo is not able to guarantee any transit times. */ estimatedDays?: number | undefined; /** * Cost to the user to insure the Rate for the requested amount of coverage, if insurance coverage was requested. * * @remarks * Expressed in the currency used in the sender's country. Will be null if no insurance coverage was requested, or if insurance is requested from a non-standard insurance provider. * Please note this price is already included in the `amount` and `amount_local` fields on the Rate. Do not add this field to them. */ includedInsurancePrice?: string | undefined; messages?: Array | undefined; /** * Date and time of Rate creation. */ objectCreated: Date; /** * Unique identifier of the given Rate object. */ objectId: string; /** * Username of the user who created the rate object. */ objectOwner: string; /** * Carrier offering the rate, e.g., `FedEx` or `Deutsche Post DHL`. */ provider: string; /** * URL to the provider logo with max. dimensions of 75*75px. * * @remarks * Please refer to the provider's Logo Usage Guidelines before using the logo. */ providerImage75?: string | undefined; /** * URL to the provider logo with max. dimensions of 200*200px. * * @remarks * Please refer to the provider's Logo Usage Guidelines before using the logo. */ providerImage200?: string | undefined; servicelevel: ServiceLevelWithParent; shipment: string; /** * Indicates whether the object has been created in test mode. */ test?: boolean | undefined; /** * The parcel's transit zone token. These tokens can vary depending on the provider. */ zone?: string | undefined; }; /** @internal */ export const Attributes$inboundSchema: z.ZodMiniEnum = z .enum(Attributes); /** @internal */ export const Rate$inboundSchema: z.ZodMiniType = z.pipe( z.object({ amount: z.string(), amount_local: z.string(), currency: z.string(), currency_local: z.string(), arrives_by: z.optional(z.string()), attributes: z.array(Attributes$inboundSchema), carrier_account: z.string(), duration_terms: z.optional(z.string()), estimated_days: z.optional(z.int()), included_insurance_price: z.optional(z.string()), messages: z.optional(z.array(ResponseMessage$inboundSchema)), object_created: z.pipe( z.iso.datetime({ offset: true }), z.transform(v => new Date(v)), ), object_id: z.string(), object_owner: z.string(), provider: z.string(), provider_image_75: z.optional(z.string()), provider_image_200: z.optional(z.string()), servicelevel: ServiceLevelWithParent$inboundSchema, shipment: z.string(), test: z.optional(z.boolean()), zone: z.optional(z.string()), }), z.transform((v) => { return remap$(v, { "amount_local": "amountLocal", "currency_local": "currencyLocal", "arrives_by": "arrivesBy", "carrier_account": "carrierAccount", "duration_terms": "durationTerms", "estimated_days": "estimatedDays", "included_insurance_price": "includedInsurancePrice", "object_created": "objectCreated", "object_id": "objectId", "object_owner": "objectOwner", "provider_image_75": "providerImage75", "provider_image_200": "providerImage200", }); }), ); export function rateFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Rate$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Rate' from JSON`, ); }