/flexport-pack:flexport-sdk-patternsfrom flexport-pack
Provides production-ready Flexport API patterns for TypeScript and Python: singleton client, paginated iteration, retry wrapper, and Zod validation. Use when building typed HTTP clients or implementing pagination for Flexport logistics integration.
Ships in flexport-pack. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
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.
// src/flexport/client.ts
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 Error('Missing FLEXPORT_API_KEY');
this.instance = new FlexportClient(key);
}
return this.instance;
}
async request<T>(path: string, options: RequestInit = {}): Promise<T> {
const res = await fetch(`${this.base}${path}`, { ...options, headers: { ...this.headers, ...options.headers } });
if (res.status === 429) {
const retryAfter = parseInt(res.headers.get('Retry-After') || '60');
await new Promise(r => setTimeout(r, retryAfter * 1000));
return this.request(path, options); // Retry once
}
if (!res.ok) {
const body = await res.text();
throw new FlexportAPIError(res.status, body, path);
}
return res.json();
}
}
class FlexportAPIError extends Error {
constructor(public status: number, public body: string, public path: string) {
super(`Flexport ${status} on ${path}: ${body}`);
this.name = 'FlexportAPIError';
}
}
// Iterate all pages of a Flexport list endpoint
async function* paginate<T>(path: string, perPage = 25): AsyncGenerator<T> {
const client = FlexportClient.getInstance();
let page = 1;
while (true) {
const separator = path.includes('?') ? '&' : '?';
const res = await client.request<{ data: { records: T[]; total_count: number } }>(
`${path}${separator}page=${page}&per=${perPage}`
);
for (const record of res.data.records) yield record;
if (res.data.records.length < perPage) break;
page++;
}
}
// Usage: iterate all shipments
for await (const shipment of paginate<Shipment>('/shipments')) {
console.log(shipment.id, shipment.status);
}
const ShipmentSchema = z.object({
id: z.string(),
status: z.enum(['booked', 'in_transit', 'arrived', 'delivered']),
freight_type: z.enum(['ocean', 'air', 'trucking']),
origin_port: z.object({ code: z.string(), name: z.string() }),
destination_port: z.object({ code: z.string(), name: z.string() }),
cargo_ready_date: z.string(),
estimated_arrival_date: z.string().nullable(),
});
type Shipment = z.infer<typeof ShipmentSchema>;
async function getShipment(id: string): Promise<Shipment> {
const client = FlexportClient.getInstance();
const res = await client.request<{ data: unknown }>(`/shipments/${id}`);
return ShipmentSchema.parse(res.data); // Throws ZodError on mismatch
}
import os, requests
from dataclasses import dataclass
from typing import Iterator
@dataclass
class Shipment:
id: str
status: str
freight_type: str
class FlexportClient:
BASE = 'https://api.flexport.com'
def __init__(self):
self.session = requests.Session()
self.session.headers.update({
'Authorization': f'Bearer {os.environ["FLEXPORT_API_KEY"]}',
'Flexport-Version': '2',
})
def list_shipments(self, per: int = 25) -> Iterator[Shipment]:
page = 1
while True:
r = self.session.get(f'{self.BASE}/shipments', params={'page': page, 'per': per})
r.raise_for_status()
records = r.json()['data']['records']
for rec in records:
yield Shipment(id=rec['id'], status=rec['status'], freight_type=rec['freight_type'])
if len(records) < per:
break
page += 1
| Pattern | Use Case | Benefit |
|---|---|---|
| Singleton | All API calls | One instance, consistent config |
| Paginator | List endpoints | No data loss from pagination |
| Zod validation | Response parsing | Catches API contract changes early |
| Error class | All failures | Structured error data for logging |
Apply patterns in flexport-core-workflow-a for real-world usage.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
24 skills in this plugin
/flexport-ci-integrationConfigure CI/CD pipelines for Flexport logistics integrations with GitHub Actions,
automated API contract testing, and deployment workflows.
Trigger: "flexport CI", "flexport GitHub Actions", "flexport CI/CD pipeline".
/flexport-common-errorsDiagnose and fix common Flexport API errors including HTTP status codes,
webhook failures, and data validation issues.
Trigger: "flexport error", "fix flexport", "flexport not working", "debug flexport API".
/flexport-core-workflow-aExecute Flexport primary workflow: shipment booking and purchase order management.
Use when creating bookings, managing purchase orders, tracking freight,
or building the core shipment lifecycle integration.
Trigger: "flexport booking", "flexport purchase order", "create flexport shipment".
/flexport-core-workflow-bExecute Flexport secondary workflow: commercial invoices, products catalog, and freight invoices.
Use when managing commercial invoices for customs, maintaining product catalogs,
or handling freight billing through the Flexport API.
Trigger: "flexport invoice", "flexport products", "flexport customs documents".
/flexport-cost-tuningOptimize Flexport API usage costs through efficient pagination, caching,
webhook-driven updates, and monitoring API call volume.
Trigger: "flexport costs", "flexport API usage", "reduce flexport calls", "flexport billing".
/flexport-data-handlingImplement data handling for Flexport supply chain data including PII redaction,
shipment data retention, GDPR compliance, and secure document management.
Trigger: "flexport data handling", "flexport PII", "flexport GDPR", "flexport data retention".
npx claudepluginhub flight505/skill-forge --plugin flexport-packOther plugins' skills for the same job