import {z} from 'zod' export type DeleteApiServicesBookingV1PackagingArgs = {id?: string | undefined, 'identifier.type'?: string | undefined, 'identifier.value'?: string | undefined}; export type DeleteApiServicesBookingV1PackagingOptions = {baseUrl?: string | undefined, oAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const logisticsIdentifierTypeEnum = z.enum(["AIR_WAYBILL", "BILL_OF_LADING", "HOUSE_BILL_OF_LADING", "BOOKING_NUMBER", "CARRIER_IATA", "CARRIER_ICAO", "CARRIER_NAME", "CARRIER_SCAC", "FFW_SCAC", "NVOCC_SCAC", "NVOCC_NAME", "FFW_NAME", "FFW_MASTER_ID", "NVOCC_MASTER_ID", "CONTAINER_ID", "CUSTOMER_REFERENCE", "DELIVERY_NUMBER", "EXTERNAL", "FLIGHT_NUMBER", "ORDER", "PICKUP", "PRO", "PURCHASE_ORDER", "RAIL_CAR_ID", "RAIL_WAYBILL", "TRACKING_NUMBER", "TRAILER_ID", "UNKNOWN", "VESSEL_IMO", "VESSEL_NAME", "WAYBILL", "VESSEL_CALL_SIGN", "VESSEL_MMSI", "CARRIER_US_DOT_NUMBER", "CARRIER_MC_NUMBER", "SUBSCRIPTION_ID", "HOUSE_AIR_WAYBILL", "SALES_ORDER", "WAREHOUSE_MOVEMENT_ORDER", "ADVANCED_SHIPMENT_NOTICE", "DRIVER_MOBILE_PHONE_NUMBER", "VEHICLE_ID", "LICENSE_PLATE", "TRAILER_LICENSE_PLATE", "SENSITECH_DEVICE_ID", "EMERSON_DEVICE_ID", "TIVE_DEVICE_ID", "ZILLION_DEVICE_ID", "VOYAGE_NUMBER", "CARRIER_MASTER_ID", "CARRIER_NMC_ID", "CONTAINER_TYPE", "TRAIN_NUMBER", "WAGON_ID", "TRAIN_ID", "CAPACITY_PROVIDER_ACCOUNT_GROUP", "CAPACITY_PROVIDER_ACCOUNT_CODE", "SERIAL_NUMBER", "VEHICLE_IDENTIFICATION_NUMBER", "REFERENCE_NUMBER", "CONTAINER_PIN", "VESSEL_P44_ID", "EXPORT_CUSTOMS_BROKER", "IMPORT_CUSTOMS_BROKER", "POL_QUALITY_CONTROL_PROVIDER", "POD_QUALITY_CONTROL_PROVIDER", "AIRCRAFT_ICAO", "AIRLINE_NAME", "SEAL_NUMBER", "DRAYAGE_CARRIER_SCAC", "EXPORT_DRAYAGE_CARRIER_SCAC", "IMPORT_DRAYAGE_CARRIER_SCAC", "INBOUND_VOYAGE_NUMBER"]); export const logisticsIdentifier = z.object({type: logisticsIdentifierTypeEnum.optional(), value: z.string().min(1).optional()}); export const packageDeletionConfirmation = z.object({id: z.string().optional(), identifiers: z.array(logisticsIdentifier).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 }; /** * Delete Package * * DELETE /services/booking/v1/packaging */ export const deleteApiServicesBookingV1Packaging = async (args: DeleteApiServicesBookingV1PackagingArgs, options?: DeleteApiServicesBookingV1PackagingOptions) => { const {baseUrl = "https://na12.api.project44.com", fetch: fetchFn = fetch, oAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.id != null) query.append("id", String(args.id)) if (args['identifier.type'] != null) query.append("identifier.type", String(args['identifier.type'])) if (args['identifier.value'] != null) query.append("identifier.value", String(args['identifier.value'])) if (oAuth2 !== undefined) headers.set('authorization', `Bearer ${oAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/services/booking/v1/packaging${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(packageDeletionConfirmation, await res.json()) };