feat(v2.6.0): implement GlobalEnvelope, T1-T9 hardening, 12 tools, and CI acceptance test suite

This commit is contained in:
Amirul Islam Redwan71
2026-11-10 08:22:06 +06:00
parent c47d78f3a7
commit b3fec955cc
55 changed files with 5316 additions and 2157 deletions
+28 -83
View File
@@ -1,5 +1,6 @@
import axios, { AxiosInstance } from "axios";
import { CourierAdapter } from "./base.js";
import { McpToolError, withGetRetry } from "../envelope.js";
import {
BalanceResponse,
LocationResolutionResponse,
@@ -267,12 +268,18 @@ export class PathaoAdapter implements CourierAdapter {
async trackParcel(trackingCode: string): Promise<TrackingResponse> {
if (!this.isConfigured()) {
throw new Error("Pathao credentials are not configured.");
throw new McpToolError({
code: "COURIER_NOT_CONFIGURED",
message: "Pathao credentials are not configured.",
courier: "pathao",
});
}
try {
const client = await this.getClient();
const response = await client.get(`/aladdin/api/v1/orders/${encodeURIComponent(trackingCode)}/info`);
const response = await withGetRetry(() =>
client.get(`/aladdin/api/v1/orders/${encodeURIComponent(trackingCode)}/info`)
);
const data = response.data?.data || {};
return {
@@ -284,98 +291,32 @@ export class PathaoAdapter implements CourierAdapter {
raw_response: response.data,
};
} catch (err: any) {
if (err?.response?.status === 404 || err?.response?.status === 400 || err?.response?.status === 422) {
return {
success: false,
const status = err?.response?.status;
if (status === 404 || status === 400 || status === 422) {
throw new McpToolError({
code: "CONSIGNMENT_NOT_FOUND",
message: `Consignment '${trackingCode}' was not found in Pathao.`,
retryable: false,
courier: "pathao",
tracking_code: trackingCode,
status: "not_found_in_pathao",
updated_at: new Date().toISOString(),
raw_response: err.response?.data || { message: "Consignment ID not found in Pathao database." },
};
});
}
throw err;
}
}
/**
* 100% Live Pathao Merchant Balance & Order Settlement Telemetry
* Queries GET /aladdin/api/v1/orders/all and GET /aladdin/api/v1/stores
* Pathao does not expose a live wallet balance API endpoint (T3).
* Returns amount_bdt: null, current_balance: null, status: UNSUPPORTED_BY_PROVIDER.
*/
async getBalance(): Promise<BalanceResponse> {
if (!this.isConfigured()) {
throw new Error("Pathao credentials are not configured.");
}
const client = await this.getClient();
const [ordersRes, storesRes] = await Promise.all([
client.get("/aladdin/api/v1/orders/all?page=1&limit=50").catch(() => ({ data: { data: { data: [], total: 0 } } })),
client.get("/aladdin/api/v1/stores").catch(() => ({ data: { data: { data: [] } } })),
]);
const orders: any[] = ordersRes.data?.data?.data || [];
const totalOrders = Number(ordersRes.data?.data?.total || orders.length);
const stores: any[] = storesRes.data?.data?.data || [];
const activeStore = stores.find((s: any) => s.is_active) || stores[0] || null;
let deliveredCount = 0;
let inTransitCount = 0;
let cancelledOrReturnedCount = 0;
let deliveredCodBdt = 0;
let inTransitCodBdt = 0;
let totalFeesBdt = 0;
let unpaidPendingBdt = 0;
for (const o of orders) {
const st = String(o.order_status || "").toLowerCase();
const amt = Number(o.order_amount || 0);
const fee = Number(o.total_fee || o.delivery_fee || 0);
const billing = String(o.billing_status || "").toLowerCase();
if (st.includes("cancel") || st.includes("return")) {
cancelledOrReturnedCount++;
} else if (st.includes("deliver") && !st.includes("hub") && !st.includes("way")) {
deliveredCount++;
deliveredCodBdt += amt;
totalFeesBdt += fee;
if (billing === "unpaid") {
unpaidPendingBdt += Math.max(0, amt - fee);
}
} else {
inTransitCount++;
inTransitCodBdt += amt;
}
}
const netDeliveredPayoutBdt = Math.max(0, deliveredCodBdt - totalFeesBdt);
return {
success: true,
courier: "pathao",
current_balance: netDeliveredPayoutBdt,
raw_response: {
live_api_status: "OAuth 2.0 Authenticated & Synced",
currency: "BDT",
total_orders: totalOrders,
recent_page_analyzed: orders.length,
delivered_orders: deliveredCount,
in_transit_orders: inTransitCount,
cancelled_or_returned_orders: cancelledOrReturnedCount,
delivered_cod_collected_bdt: deliveredCodBdt,
in_transit_cod_bdt: inTransitCodBdt,
total_carrier_fees_bdt: totalFeesBdt,
net_merchant_payout_bdt: netDeliveredPayoutBdt,
unpaid_pending_disbursement_bdt: unpaidPendingBdt,
active_pickup_store: activeStore
? {
store_id: activeStore.store_id,
store_name: activeStore.store_name,
store_address: activeStore.store_address,
city_id: activeStore.city_id,
zone_id: activeStore.zone_id,
}
: undefined,
},
amount_bdt: null,
pending_bdt: null,
current_balance: null,
status: "UNSUPPORTED_BY_PROVIDER",
hint: "Use Pathao merchant portal",
};
}
@@ -385,7 +326,11 @@ export class PathaoAdapter implements CourierAdapter {
*/
async fraudCheck(phone: string): Promise<any> {
if (!this.isConfigured()) {
throw new Error("Pathao credentials are not configured.");
throw new McpToolError({
code: "COURIER_NOT_CONFIGURED",
message: "Pathao credentials are not configured.",
courier: "pathao",
});
}
const cleanPhone = phone.replace(/\D/g, "").replace(/^88/, "");
const client = await this.getClient();