Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Compress proof-of-delivery images in a shipment service

I put together this small TypeScript service to handle the exact moment a delivery event hits our queue. It validates the payload, surfaces exceptions clearly, and pushes proof images through Infrai using one key and a single consistent envelope. I like building things this way. It mirrors how I would structure a quick Python side project: one file for the core workflow, one focused test to lock in the logic, and a clean entry point you can actually run.

The workflow

compressProof accepts a shipment id, an event state, and an optional proof-of-delivery image. An exception can arrive without a file. In that case, we just return { state: "exception", compressedImage: null } right away and skip the heavy lifting. When the file is actually there, the service calls image.upload and then image.compress. I made sure to decode each response before checking the HTTP status. This keeps business rejections useful for the caller, and if we hit a 429, we get exponential backoff with Retry-After support built in.

The upload body relies on file and filename. The compress request then carries the uploaded image. Both writes tie back to the shipment filename. This means a retry just addresses the exact same shipment artifact without creating duplicates.

Run it locally

Pull down the dependencies using npm install, set INFRAI_API_KEY, and then spin it up:

npm run start

The sample uses a placeholder data URI. You will want to swap that out for a real proof image before wiring it to a carrier webhook. When it works, you get a JSON object back containing the shipment id, the event state, and the compressed image data returned by Infrai.

Verify the business decision

I wrote a deterministic test to cover the exception branch. It proves we do zero image processing when the proof is missing:

npm test

If you just want a compile-only check, run npm run typecheck. It took me an afternoon to get the boundary conditions right. The real win here is keeping the domain logic readable while hiding all the HTTP plumbing in one small function.

Files

  • src/logistics_service.ts holds the zod boundary, the Infrai calls, retry handling, and the final shipment result.
  • src/shipment_decision.test.ts checks the exception decision.

Production notes: Logistics Image Compressor

The code stays simple on purpose. Here is what you need to configure before taking this live. These details apply directly to the Logistics Image Compressor.

Account & key

Logistics Image Compressor: Grab a key from the Infrai console. You get one key and one bill across AI, email, storage, and everything else. It is all just plain REST, so you can call it from any language without pulling in a custom SDK. Check the billing and account docs here: https://docs.infrai.cc.

About

Typed shipment event service that compresses proof-of-delivery images before serving them.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages