import {z} from 'zod' export type GetApiServicesDocumentV1DocumentsDocumentIdArgs = {documentId: string}; export type GetApiServicesDocumentV1DocumentsDocumentIdOptions = {baseUrl?: string | undefined, oAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const fileType = z.enum(["PDF", "PNG", "JPEG", "GIF", "TIF"]); export const imageType = z.enum(["ORIGINAL", "THUMBNAIL"]); export const image = z.object({mediaType: fileType.optional(), sizeInBytes: z.number().int().optional(), type: imageType.optional(), url: z.string().optional()}); export const logisticsIdentifierType = z.enum(["AIR_WAYBILL", "BILL_OF_LADING", "HOUSE_BILL_OF_LADING", "BOOKING_NUMBER", "CARRIER_IATA", "CARRIER_ICAO", "CARRIER_NAME", "CARRIER_SCAC", "FFW_SCAC", "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", "SENSITECH_DEVICE_ID", "EMERSON_DEVICE_ID", "TIVE_DEVICE_ID", "VOYAGE_NUMBER", "CARRIER_MASTER_ID", "CARRIER_NMC_ID", "CONTAINER_TYPE", "TRAIN_NUMBER", "WAGON_ID", "CAPACITY_PROVIDER_ACCOUNT_GROUP", "CAPACITY_PROVIDER_ACCOUNT_CODE", "SERIAL_NUMBER", "VEHICLE_IDENTIFICATION_NUMBER", "REFERENCE_NUMBER", "CONTAINER_PIN", "INVOICE_ID", "VESSEL_P44_ID"]); export const internalEntityType = z.enum(["MASTER_SHIPMENT_ID", "BOOKING_ID", "STOP_ID", "DRIVER_ID", "TRUCKLOAD_TRACKING_ID", "ORDER_ID", "SHIPPER_TENANT_UUID"]); export const identifier = z.object({type: z.union([logisticsIdentifierType, internalEntityType]).optional(), value: z.string().optional()}); export const documentMode = z.enum(["AIR", "OCEAN", "TL", "LTL", "PARCEL", "RAIL", "BARGE"]); export const documentType = z.enum(["BILL_OF_LADING", "HOUSE_BILL_OF_LADING", "AIRWAY_BILL", "COMMERCIAL_INVOICE", "CUSTOMS_DOCUMENTS", "PACKING_SLIP", "CERTIFICATE_OF_ORIGIN", "PROOF_OF_DELIVERY", "DELIVERY_RECEIPT", "ECMR", "WEIGHT_CERTIFICATE", "INSPECTION_CERTIFICATE", "LETTER_OF_AUTHORIZATION", "LUMPER_CERTIFICATE", "INVOICE", "HAZMAT_DOCUMENT", "SHIPPING_LABEL", "OTHER"]); export const document = z.object({addedByCompany: z.string().optional(), addedByUser: z.string().optional(), createdDateTime: z.string().optional(), deletedDateTime: z.string().optional(), files: z.array(image).optional(), identifiers: z.array(identifier).optional(), id: z.string().optional(), lastModifiedDateTime: z.string().optional(), mode: documentMode.optional(), name: z.string().optional(), parsedData: z.record(z.string(), z.unknown()).optional(), type: documentType.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 }; /** * Get Document * * GET /services/document/v1/documents/{documentId} */ export const getApiServicesDocumentV1DocumentsDocumentId = async (args: GetApiServicesDocumentV1DocumentsDocumentIdArgs, options?: GetApiServicesDocumentV1DocumentsDocumentIdOptions) => { 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 (oAuth2 !== undefined) headers.set('authorization', `Bearer ${oAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/services/document/v1/documents/${encodeURIComponent(String(args.documentId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(document, await res.json()) };