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
+30 -47
View File
@@ -1,4 +1,5 @@
import axios from "axios";
import { McpToolError } from "../envelope.js";
export class PaperflyAdapter {
courierName = "paperfly";
apiKey;
@@ -62,24 +63,29 @@ export class PaperflyAdapter {
}
async trackParcel(trackingCode) {
if (!this.enabled) {
throw new Error("Paperfly credentials are not configured.");
throw new McpToolError({
code: "COURIER_NOT_CONFIGURED",
message: "Paperfly credentials are not configured.",
courier: "paperfly",
});
}
if (!this.username || !this.password) {
throw new Error("Paperfly tracking needs your merchant-panel username & password (Basic Auth). Add them to use track_parcel.");
throw new McpToolError({
code: "COURIER_NOT_CONFIGURED",
message: "Paperfly tracking requires merchant-panel username and password.",
courier: "paperfly",
});
}
try {
// Paperfly tracks by your merchant order reference (merchantOrderReference) via POST /API-Order-Tracking
const response = await this.client.post("/API-Order-Tracking", { ReferenceNumber: trackingCode }, { headers: { paperflykey: this.apiKey }, auth: { username: this.username, password: this.password } });
const data = response.data;
if (data?.error) {
return {
success: false,
throw new McpToolError({
code: "CONSIGNMENT_NOT_FOUND",
message: `Consignment '${trackingCode}' was not found in Paperfly.`,
retryable: false,
courier: "paperfly",
tracking_code: trackingCode,
status: "not_found_in_paperfly",
updated_at: new Date().toISOString(),
raw_response: data,
};
});
}
const st = data?.success?.trackingStatus?.[0] || {};
const stages = [
@@ -102,54 +108,31 @@ export class PaperflyAdapter {
};
}
catch (err) {
if (err instanceof McpToolError)
throw err;
if (err?.response?.status === 400 || err?.response?.status === 404) {
return {
success: false,
throw new McpToolError({
code: "CONSIGNMENT_NOT_FOUND",
message: `Consignment '${trackingCode}' was not found in Paperfly.`,
retryable: false,
courier: "paperfly",
tracking_code: trackingCode,
status: "not_found_in_paperfly",
updated_at: new Date().toISOString(),
raw_response: err.response?.data || { message: "No order found in Paperfly for this ReferenceNumber." },
};
});
}
throw err;
}
}
/**
* 100% Live Paperfly Go Merchant Authentication & Account Settlement Verification
* Verifies Basic Auth + paperflykey against https://api.paperfly.com.bd/API-Order-Tracking
* Paperfly does not expose a live wallet balance API endpoint (T3).
*/
async getBalance() {
if (!this.enabled) {
throw new Error("Paperfly credentials are not configured.");
}
let liveVerified = false;
let apiResponseCode = 200;
try {
const res = await this.client.post("/API-Order-Tracking", { ReferenceNumber: "AURA-AUTH-PROBE" }, {
headers: { paperflykey: this.apiKey },
auth: { username: this.username, password: this.password },
validateStatus: (s) => s < 500,
});
apiResponseCode = res.status;
liveVerified = res.status === 200 || (res.status === 400 && Boolean(res.data?.error));
}
catch (_) {
liveVerified = false;
}
return {
success: liveVerified,
success: true,
courier: "paperfly",
current_balance: 0,
raw_response: {
live_api_status: liveVerified
? "Paperfly Go API Authenticated & Active"
: `Paperfly Probe Status ${apiResponseCode}`,
currency: "BDT",
merchant_code: this.username,
store_name: this.storeName || "Default Store",
settlement_cycle: "Paperfly Direct BEFTN / Bank Auto-Disbursement",
},
amount_bdt: null,
pending_bdt: null,
current_balance: null,
status: "UNSUPPORTED_BY_PROVIDER",
hint: "Use Paperfly merchant portal",
};
}
}