feat(v2.6.0): implement GlobalEnvelope, T1-T9 hardening, 12 tools, and CI acceptance test suite
This commit is contained in:
+45
-22
@@ -1,5 +1,6 @@
|
||||
import axios, { AxiosInstance } from "axios";
|
||||
import { CourierAdapter } from "./base.js";
|
||||
import { McpToolError, withGetRetry } from "../envelope.js";
|
||||
import {
|
||||
BalanceResponse,
|
||||
ParcelCreateRequest,
|
||||
@@ -70,7 +71,11 @@ export class SteadfastAdapter implements CourierAdapter {
|
||||
|
||||
async trackParcel(trackingCode: string): Promise<TrackingResponse> {
|
||||
if (!this.enabled) {
|
||||
throw new Error("Steadfast Courier credentials are not configured.");
|
||||
throw new McpToolError({
|
||||
code: "COURIER_NOT_CONFIGURED",
|
||||
message: "Steadfast Courier credentials are not configured.",
|
||||
courier: "steadfast",
|
||||
});
|
||||
}
|
||||
|
||||
const endpoints = [
|
||||
@@ -82,7 +87,7 @@ export class SteadfastAdapter implements CourierAdapter {
|
||||
let lastErr: any = null;
|
||||
for (const ep of endpoints) {
|
||||
try {
|
||||
const response = await this.client.get(ep);
|
||||
const response = await withGetRetry(() => this.client.get(ep));
|
||||
const data = response.data;
|
||||
if (data && (data.status === 200 || data.delivery_status)) {
|
||||
return {
|
||||
@@ -99,38 +104,53 @@ export class SteadfastAdapter implements CourierAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
// Steadfast Packzy returns HTTP 401/404 when a consignment ID does not belong to the connected merchant account
|
||||
const status = lastErr?.response?.status;
|
||||
if (status === 401 || status === 404 || status === 400) {
|
||||
return {
|
||||
success: false,
|
||||
if (status === 404 || status === 400) {
|
||||
throw new McpToolError({
|
||||
code: "CONSIGNMENT_NOT_FOUND",
|
||||
message: `Consignment '${trackingCode}' was not found in Steadfast.`,
|
||||
retryable: false,
|
||||
courier: "steadfast",
|
||||
tracking_code: trackingCode,
|
||||
status: "not_found_in_steadfast_account",
|
||||
updated_at: new Date().toISOString(),
|
||||
raw_response: {
|
||||
live_api_status: "Packzy API Queried Live",
|
||||
http_status: status,
|
||||
message: "Consignment / tracking code was not found under this merchant's Steadfast account.",
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
if (status === 401 || status === 403) {
|
||||
throw new McpToolError({
|
||||
code: "COURIER_UPSTREAM_ERROR",
|
||||
message: "Steadfast upstream authentication or consignment ownership check failed.",
|
||||
retryable: false,
|
||||
courier: "steadfast",
|
||||
});
|
||||
}
|
||||
|
||||
throw lastErr || new Error("Steadfast tracking lookup failed");
|
||||
throw lastErr || new McpToolError({
|
||||
code: "CONSIGNMENT_NOT_FOUND",
|
||||
message: `Consignment '${trackingCode}' was not found in Steadfast.`,
|
||||
retryable: false,
|
||||
courier: "steadfast",
|
||||
});
|
||||
}
|
||||
|
||||
async getBalance(): Promise<BalanceResponse> {
|
||||
if (!this.enabled) {
|
||||
throw new Error("Steadfast Courier credentials are not configured.");
|
||||
throw new McpToolError({
|
||||
code: "COURIER_NOT_CONFIGURED",
|
||||
message: "Steadfast Courier credentials are not configured.",
|
||||
courier: "steadfast",
|
||||
});
|
||||
}
|
||||
|
||||
const response = await this.client.get("/get_balance");
|
||||
const response = await withGetRetry(() => this.client.get("/get_balance"));
|
||||
const data = response.data;
|
||||
const bal = typeof data?.current_balance === "number" ? data.current_balance : Number(data?.current_balance ?? 0);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
courier: "steadfast",
|
||||
current_balance: Number(data.current_balance || 0),
|
||||
amount_bdt: bal,
|
||||
pending_bdt: 0,
|
||||
current_balance: bal,
|
||||
status: "OK",
|
||||
as_of: new Date().toISOString(),
|
||||
raw_response: data,
|
||||
};
|
||||
}
|
||||
@@ -138,14 +158,17 @@ export class SteadfastAdapter implements CourierAdapter {
|
||||
/**
|
||||
* 100% Real Live Steadfast Fraud Check API
|
||||
* Endpoint: GET /fraud_check/{phone}
|
||||
* Returns nationwide parcel history across Bangladesh: total_parcels, total_delivered, total_cancelled
|
||||
*/
|
||||
async fraudCheck(phone: string): Promise<any> {
|
||||
if (!this.enabled) {
|
||||
throw new Error("Steadfast Courier credentials are not configured.");
|
||||
throw new McpToolError({
|
||||
code: "COURIER_NOT_CONFIGURED",
|
||||
message: "Steadfast Courier credentials are not configured.",
|
||||
courier: "steadfast",
|
||||
});
|
||||
}
|
||||
const cleanPhone = phone.replace(/\D/g, "");
|
||||
const response = await this.client.get(`/fraud_check/${encodeURIComponent(cleanPhone)}`);
|
||||
const response = await withGetRetry(() => this.client.get(`/fraud_check/${encodeURIComponent(cleanPhone)}`));
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user