Response Model
Every method in the Bigship SDK returns an ApiResponse<T> object. The SDK provides type guard functions to safely narrow the response type.
ApiResponse Structure
Section titled “ApiResponse Structure”interface ApiResponse<T> { status: boolean; message: string; status_code: number; data: T | null;}statusindicates whether the API call succeeded (true/false)datacontains the typed payload on success, ornullon failuremessagecontains an error message on failurestatus_codecontains the HTTP status code
Type Guards
Section titled “Type Guards”The SDK exports two type guard functions:
| Guard | Narrows to | When |
|---|---|---|
isSuccessResponse<T>(res) |
ApiResponse<T> & { status: true; data: T } |
status === true |
isFailedResponse(res) |
ApiResponse<null> & { status: false; data: null } |
status === false |
Usage with isSuccessResponse
Section titled “Usage with isSuccessResponse”import { isSuccessResponse, isFailedResponse } from '@agamya/bigship-sdk';
const response = await client.getProfile();
if (isSuccessResponse(response)) { // response.data is guaranteed to be non-null console.log('Profile:', response.data);}
if (isFailedResponse(response)) { // response.data is null, response.message has the error console.error('Error:', response.message);}Usage with Early Return
Section titled “Usage with Early Return”const response = await client.createOrder({ /* ... */ });
if (isFailedResponse(response)) { throw new Error(response.message ?? 'Order creation failed');}
// response.data is typed and non-null from hereconsole.log('Order ID:', response.data?.CustomGlobalOrderId);Without Type Guards
Section titled “Without Type Guards”Without type guards, you must null-check data manually:
const response = await client.getOrderDetail('311276742');
if (response.data) { console.log('AWB:', response.data.getOrderDetails.AwbNumber);}Type guards are preferred because they provide full type narrowing without manual checks.