| name | flexport-sdk-patterns |
| description | Apply production-ready Flexport API patterns for TypeScript and Python.
Use when building typed HTTP clients, implementing pagination,
or establishing team coding standards for Flexport logistics integration.
Trigger: "flexport SDK patterns", "flexport best practices", "flexport client wrapper".
|
| allowed-tools | Read, Write, Edit |
| version | 1.6.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","logistics","flexport"] |
| compatibility | Designed for Claude Code |
Flexport SDK Patterns
Overview
Production-ready patterns for the Flexport REST API v2. Since Flexport has no official npm/pip SDK, you build typed HTTP clients. Key patterns: singleton client, paginated iteration, retry wrapper, and Zod response validation.
Instructions
Pattern 1: Singleton Client with Auto-Retry
import { z } from 'zod';
class FlexportClient {
private static instance: FlexportClient | null = null;
private base = 'https://api.flexport.com';
private headers: Record<string, string>;
private constructor(apiKey: string) {
this.headers = {
'Authorization': `Bearer ${apiKey}`,
'Flexport-Version': '2',
'Content-Type': 'application/json',
};
}
static getInstance(): FlexportClient {
if (!this.instance) {
const key = process.env.FLEXPORT_API_KEY;
if (!key) throw new ();
. = (key);
}
.;
}
request<T>(: , : = {}): <T> {
res = (, { ...options, : { ...., ...options. } });
(res. === ) {
retryAfter = (res..() || );
( (r, retryAfter * ));
.(path, options);
}
(!res.) {
body = res.();
(res., body, path);
}
res.();
}
}
{
() {
();
. = ;
}
}