import {z} from 'zod' export type CapacityProviderIdentifier = {type?: ('SCAC' | 'DOT_NUMBER' | 'MC_NUMBER' | 'P44_EU' | 'SYSTEM' | 'P44_GLOBAL' | 'VAT') | undefined, value?: string | undefined}; export type TruckloadEquipmentIdentifier = {shouldDelete?: boolean | undefined, type?: ('MOBILE_PHONE_NUMBER' | 'VEHICLE_ID' | 'LICENSE_PLATE' | 'SENSITECH_DEVICE_ID' | 'TIVE_DEVICE_ID') | undefined, value?: string | undefined}; export type TruckloadShipmentIdentifier = {type?: ('BILL_OF_LADING' | 'ORDER') | undefined, value?: string | undefined}; export type TruckloadEquipmentIdentifierAssignment = {carrierIdentifier?: CapacityProviderIdentifier | undefined, customerAccountNumber?: string | undefined, equipmentIdentifiers?: Array | undefined, scheduledTruckChangeDateTime?: string | undefined, shipmentIdentifiers?: Array | undefined, shouldDelete?: boolean | undefined}; export type CreateApiApiV4CapacityprovidersTlEquipmentIdentifierAssignmentsArgs = {body: TruckloadEquipmentIdentifierAssignment}; export type CreateApiApiV4CapacityprovidersTlEquipmentIdentifierAssignmentsOptions = {baseUrl?: string | undefined, oAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const capacityProviderIdentifier = z.object({type: z.enum(["SCAC", "DOT_NUMBER", "MC_NUMBER", "P44_EU", "SYSTEM", "P44_GLOBAL", "VAT"]).optional(), value: z.string().optional()}); export const truckloadEquipmentIdentifier = z.object({shouldDelete: z.boolean().optional(), type: z.enum(["MOBILE_PHONE_NUMBER", "VEHICLE_ID", "LICENSE_PLATE", "SENSITECH_DEVICE_ID", "TIVE_DEVICE_ID"]).optional(), value: z.string().optional()}); export const truckloadShipmentIdentifier = z.object({type: z.enum(["BILL_OF_LADING", "ORDER"]).optional(), value: z.string().optional()}); export const truckloadEquipmentIdentifierAssignment = z.object({carrierIdentifier: capacityProviderIdentifier.optional(), customerAccountNumber: z.string().optional(), equipmentIdentifiers: z.array(truckloadEquipmentIdentifier).optional(), scheduledTruckChangeDateTime: z.string().optional(), shipmentIdentifiers: z.array(truckloadShipmentIdentifier).optional(), shouldDelete: 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 }; /** * postEquipmentIdentifierAssignment * * POST /api/v4/capacityproviders/tl/equipmentIdentifierAssignments */ export const createApiApiV4CapacityprovidersTlEquipmentIdentifierAssignments = async (args: CreateApiApiV4CapacityprovidersTlEquipmentIdentifierAssignmentsArgs, options?: CreateApiApiV4CapacityprovidersTlEquipmentIdentifierAssignmentsOptions) => { const {baseUrl = "https://na12.api.project44.com", fetch: fetchFn = fetch, oAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oAuth2 !== undefined) headers.set('authorization', `Bearer ${oAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v4/capacityproviders/tl/equipmentIdentifierAssignments${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(truckloadEquipmentIdentifierAssignment, await res.json()) };