import {z} from 'zod' export type UPSReferenceFields = {prefix?: string | undefined, value?: string | undefined, ref_sort?: number | undefined}; export type Alcohol = {contains_alcohol?: boolean | undefined, recipient_type?: ('licensee' | 'consumer') | undefined}; export type Billing = {account?: string | undefined, country?: unknown | undefined, participation_code?: string | undefined, type?: ('SENDER' | 'RECIPIENT' | 'THIRD_PARTY' | 'THIRD_PARTY_CONSIGNEE' | 'COLLECT') | undefined, zip?: string | undefined}; export type COD = {amount?: string | undefined, currency?: string | undefined, payment_method?: ('SECURED_FUNDS' | 'CASH' | 'ANY') | undefined}; export type CustomerReference = {prefix?: string | undefined, value?: string | undefined, ref_sort?: number | undefined}; export type DangerousGoodsBiologicalMaterial = {contains?: boolean | undefined}; export type DangerousGoodsLithiumBatteries = {contains?: boolean | undefined}; export type DangerousGoodsObject = {contains?: boolean | undefined, biological_material?: DangerousGoodsBiologicalMaterial | undefined, lithium_batteries?: DangerousGoodsLithiumBatteries | undefined}; export type DepartmentNumber = {prefix?: string | undefined, value?: string | undefined, ref_sort?: number | undefined}; export type DryIce = {contains_dry_ice?: boolean | undefined, weight?: string | undefined}; export type Insurance = {amount?: string | undefined, content?: string | undefined, currency?: unknown | undefined, provider?: ('FEDEX' | 'UPS' | 'ONTRAC') | undefined}; export type InvoiceNumber = {prefix?: string | undefined, value?: string | undefined, ref_sort?: number | undefined}; export type ShipmentExtraLasershipAttributesEnum = 'TwoPersonDelivery' | 'Explosive' | 'Alcohol' | 'Hazmat' | 'ControlledSubstance' | 'Refrigerated' | 'DryIce' | 'Perishable' | 'NoRTS'; export type PoNumber = {prefix?: string | undefined, value?: string | undefined, ref_sort?: number | undefined}; export type RmaNumber = {prefix?: string | undefined, value?: string | undefined, ref_sort?: number | undefined}; export type ShipmentExtra = {accounts_receivable_customer_account?: UPSReferenceFields | undefined, alcohol?: Alcohol | undefined, ancillary_endorsement?: ('FORWARDING_SERVICE_REQUESTED' | 'RETURN_SERVICE_REQUESTED') | undefined, appropriation_number?: UPSReferenceFields | undefined, authority_to_leave?: boolean | undefined, bill_of_lading_number?: UPSReferenceFields | undefined, billing?: Billing | undefined, bypass_address_validation?: boolean | undefined, carbon_neutral?: boolean | undefined, carrier_hub_id?: string | undefined, carrier_hub_travel_time?: number | undefined, COD?: COD | undefined, cod_number?: UPSReferenceFields | undefined, container_type?: string | undefined, critical_pull_time?: string | undefined, customer_branch?: string | undefined, customer_reference?: CustomerReference | undefined, dangerous_goods?: DangerousGoodsObject | undefined, dangerous_goods_code?: ('01' | '02' | '03' | '04' | '05' | '06' | '07' | '08' | '09') | undefined, dealer_order_number?: UPSReferenceFields | undefined, delivery_instructions?: string | undefined, dept_number?: DepartmentNumber | undefined, dry_ice?: DryIce | undefined, fda_product_code?: UPSReferenceFields | undefined, fulfillment_center?: string | undefined, insurance?: Insurance | undefined, invoice_number?: InvoiceNumber | undefined, is_return?: boolean | undefined, lasership_attrs?: Array | undefined, lasership_declared_value?: string | undefined, manifest_number?: UPSReferenceFields | undefined, model_number?: UPSReferenceFields | undefined, part_number?: UPSReferenceFields | undefined, po_number?: PoNumber | undefined, preferred_delivery_timeframe?: ('10001200' | '12001400' | '14001600' | '16001800' | '18002000' | '19002100') | undefined, premium?: boolean | undefined, production_code?: UPSReferenceFields | undefined, purchase_request_number?: UPSReferenceFields | undefined, qr_code_requested?: boolean | undefined, reference_1?: string | undefined, reference_2?: string | undefined, request_retail_rates?: boolean | undefined, return_service_type?: ('PRINT_AND_MAIL' | 'ATTEMPT_1' | 'ATTEMPT_3' | 'ELECTRONIC_LABEL' | 'NO_RETURN') | undefined, rma_number?: RmaNumber | undefined, saturday_delivery?: boolean | undefined, salesperson_number?: UPSReferenceFields | undefined, serial_number?: UPSReferenceFields | undefined, signature_confirmation?: ('STANDARD' | 'ADULT' | 'CERTIFIED' | 'INDIRECT' | 'CARRIER_CONFIRMATION') | undefined, store_number?: UPSReferenceFields | undefined, transaction_reference_number?: UPSReferenceFields | undefined, usmca_eligible?: boolean | undefined}; export type AddressCreateRequest = {name?: string | undefined, company?: string | undefined, street1?: string | undefined, street2?: string | undefined, street3?: string | undefined, street_no?: string | undefined, city?: string | undefined, state?: string | undefined, zip?: string | undefined, country: string, phone?: string | undefined, email?: string | undefined, is_residential?: boolean | undefined, metadata?: string | undefined, validate?: boolean | undefined}; export type CustomsTaxIdentification = {number?: string | undefined, type?: ('EIN' | 'VAT' | 'IOSS' | 'ARN') | undefined}; export type CustomsExporterIdentification = {eori_number?: string | undefined, tax_id?: CustomsTaxIdentification | undefined}; export type AddressImporter = {name?: string | undefined, company?: string | undefined, street1?: string | undefined, street2?: string | undefined, street3?: string | undefined, street_no?: string | undefined, city?: string | undefined, state?: string | undefined, zip?: string | undefined, country?: string | undefined, phone?: string | undefined, email?: string | undefined, is_residential?: boolean | undefined}; export type CustomsDeclarationContentsTypeEnum = 'DOCUMENTS' | 'GIFT' | 'SAMPLE' | 'MERCHANDISE' | 'HUMANITARIAN_DONATION' | 'RETURN_MERCHANDISE' | 'OTHER'; export type CustomsDeclarationEelPfcEnum = 'NOEEI_30_37_a' | 'NOEEI_30_37_h' | 'NOEEI_30_37_f' | 'NOEEI_30_36' | 'AES_ITN'; export type CustomsDeclarationIncotermEnum = 'DDP' | 'DDU' | 'FCA' | 'DAP' | 'eDAP'; export type WeightUnitEnum = 'g' | 'kg' | 'lb' | 'oz'; export type CustomsItemCreateRequest = {description: string, eccn_ear99?: string | undefined, mass_unit: WeightUnitEnum, metadata?: string | undefined, net_weight: string, origin_country: string, quantity: number, sku_code?: string | undefined, hs_code?: string | undefined, tariff_number?: string | undefined, value_amount: string, value_currency: string}; export type CustomsDeclarationNonDeliveryOptionEnum = 'ABANDON' | 'RETURN'; export type CustomsDeclarationCreateRequest = {aes_itn?: string | undefined, b13a_filing_option?: ('FILED_ELECTRONICALLY' | 'SUMMARY_REPORTING' | 'NOT_REQUIRED') | undefined, b13a_number?: string | undefined, certificate?: string | undefined, certify: boolean, certify_signer: string, commercial_invoice?: boolean | undefined, contents_explanation?: string | undefined, disclaimer?: string | undefined, duties_payor?: ({account?: string | undefined, type?: ('SENDER' | 'RECIPIENT' | 'THIRD_PARTY') | undefined, address?: ({name?: string | undefined, zip?: string | undefined, country?: string | undefined}) | undefined}) | undefined, exporter_identification?: CustomsExporterIdentification | undefined, exporter_reference?: string | undefined, importer_reference?: string | undefined, is_vat_collected?: boolean | undefined, invoice?: string | undefined, license?: string | undefined, metadata?: string | undefined, notes?: string | undefined, address_importer?: AddressImporter | undefined, contents_type: CustomsDeclarationContentsTypeEnum, eel_pfc?: CustomsDeclarationEelPfcEnum | undefined, incoterm?: CustomsDeclarationIncotermEnum | undefined, items: Array, non_delivery_option: CustomsDeclarationNonDeliveryOptionEnum, test?: boolean | undefined}; export type ParcelInsurance = {amount?: string | undefined, content?: string | undefined, currency?: string | undefined, provider?: ('FEDEX' | 'UPS' | 'ONTRAC') | undefined}; export type ParcelExtra = {COD?: COD | undefined, insurance?: ParcelInsurance | undefined, reference_1?: string | undefined, reference_2?: string | undefined}; export type DistanceUnitEnum = 'cm' | 'in' | 'ft' | 'm' | 'mm' | 'yd'; export type ParcelCreateRequest = {extra?: ParcelExtra | undefined, metadata?: string | undefined, mass_unit: WeightUnitEnum, weight: string, distance_unit: DistanceUnitEnum, height: string, length: string, width: string}; export type ParcelTemplateEnumSet = 'FedEx_Box_10kg' | 'FedEx_Box_25kg' | 'FedEx_Box_Extra_Large_1' | 'FedEx_Box_Extra_Large_2' | 'FedEx_Box_Large_1' | 'FedEx_Box_Large_2' | 'FedEx_Box_Medium_1' | 'FedEx_Box_Medium_2' | 'FedEx_Box_Small_1' | 'FedEx_Box_Small_2' | 'FedEx_Envelope' | 'FedEx_Padded_Pak' | 'FedEx_Pak_1' | 'FedEx_Pak_2' | 'FedEx_Tube' | 'FedEx_XL_Pak' | 'UPS_Box_10kg' | 'UPS_Box_25kg' | 'UPS_Express_Box' | 'UPS_Express_Box_Large' | 'UPS_Express_Box_Medium' | 'UPS_Express_Box_Small' | 'UPS_Express_Envelope' | 'UPS_Express_Hard_Pak' | 'UPS_Express_Legal_Envelope' | 'UPS_Express_Pak' | 'UPS_Express_Tube' | 'UPS_Laboratory_Pak' | 'UPS_MI_BPM' | 'UPS_MI_BPM_Flat' | 'UPS_MI_BPM_Parcel' | 'UPS_MI_First_Class' | 'UPS_MI_Flat' | 'UPS_MI_Irregular' | 'UPS_MI_Machinable' | 'UPS_MI_MEDIA_MAIL' | 'UPS_MI_Parcel_Post' | 'UPS_MI_Priority' | 'UPS_MI_Standard_Flat' | 'UPS_Pad_Pak' | 'UPS_Pallet' | 'USPS_FlatRateCardboardEnvelope' | 'USPS_FlatRateEnvelope' | 'USPS_FlatRateGiftCardEnvelope' | 'USPS_FlatRateLegalEnvelope' | 'USPS_FlatRatePaddedEnvelope' | 'USPS_FlatRateWindowEnvelope' | 'USPS_IrregularParcel' | 'USPS_LargeFlatRateBoardGameBox' | 'USPS_LargeFlatRateBox' | 'USPS_APOFlatRateBox' | 'USPS_LargeVideoFlatRateBox' | 'USPS_MediumFlatRateBox1' | 'USPS_MediumFlatRateBox2' | 'USPS_RegionalRateBoxA1' | 'USPS_RegionalRateBoxA2' | 'USPS_RegionalRateBoxB1' | 'USPS_RegionalRateBoxB2' | 'USPS_SmallFlatRateBox' | 'USPS_SmallFlatRateEnvelope' | 'USPS_SoftPack' | 'DHLeC_Irregular' | 'DHLeC_SM_Flats' | 'DPD_UK_Express_Pak' | 'Fastway_Australia_Satchel_A2' | 'Fastway_Australia_Satchel_A3' | 'Fastway_Australia_Satchel_A4' | 'Fastway_Australia_Satchel_A5'; export type ParcelCreateFromTemplateRequest = {extra?: ParcelExtra | undefined, metadata?: string | undefined, mass_unit: WeightUnitEnum, weight: string, template: ParcelTemplateEnumSet}; export type ShipmentCreateRequest = {extra?: ShipmentExtra | undefined, metadata?: string | undefined, shipment_date?: string | undefined, address_from: AddressCreateRequest | string, address_return?: (AddressCreateRequest | string) | undefined, address_to: AddressCreateRequest | string, customs_declaration?: (CustomsDeclarationCreateRequest | string) | undefined, async?: boolean | undefined, carrier_accounts?: Array | undefined, parcels: Array}; export type BatchShipmentCreateRequest = {carrier_account?: string | undefined, metadata?: string | undefined, servicelevel_token?: string | undefined, shipment: ShipmentCreateRequest}; export type CreateApiBatchesBatchIdAddShipmentsArgs = {BatchId: string, 'SHIPPO-API-VERSION'?: string | undefined, body: Array}; export type CreateApiBatchesBatchIdAddShipmentsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const labelFileTypeEnum = z.enum(["PNG", "PNG_2.3x7.5", "PDF", "PDF_2.3x7.5", "PDF_4x6", "PDF_4x8", "PDF_A4", "PDF_A5", "PDF_A6", "ZPLII"]); export const batchShipment = z.object({carrier_account: z.string().optional(), metadata: z.string().max(100).optional(), servicelevel_token: z.string().optional(), messages: z.array(z.unknown()).optional(), object_id: z.string(), shipment: z.string(), status: z.enum(["INVALID", "VALID", "INCOMPLETE", "TRANSACTION_FAILED"]), transaction: z.string().optional()}); export const batchShipmentPaginatedList = z.object({next: z.string().optional(), previous: z.string().optional(), results: z.array(batchShipment).optional()}); export const batch = z.object({default_carrier_account: z.string(), default_servicelevel_token: z.string(), label_filetype: labelFileTypeEnum.optional(), metadata: z.string().max(100).optional(), batch_shipments: batchShipmentPaginatedList, label_url: z.array(z.string()), object_created: z.string(), object_id: z.string(), object_owner: z.string(), object_results: z.object({creation_failed: z.number().int(), creation_succeeded: z.number().int(), purchase_failed: z.number().int(), purchase_succeeded: z.number().int()}), object_updated: z.string(), status: z.enum(["VALIDATING", "VALID", "INVALID", "PURCHASING", "PURCHASED"]), test: z.boolean().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Add shipments to a batch * * POST /batches/{BatchId}/add_shipments */ export const createApiBatchesBatchIdAddShipments = async (args: CreateApiBatchesBatchIdAddShipmentsArgs, options?: CreateApiBatchesBatchIdAddShipmentsOptions) => { const {baseUrl = "https://api.goshippo.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['SHIPPO-API-VERSION'] != null) headers.set("SHIPPO-API-VERSION", String(args['SHIPPO-API-VERSION'])) const url = `${baseUrl.replace(/\/+$/, '')}/batches/${encodeURIComponent(String(args.BatchId))}/add_shipments${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(batch, await res.json()) };