@t2000/sdk 9.3.1 → 9.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.cjs +21 -2
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +21 -2
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +21 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +21 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -552,17 +552,36 @@ async function payWithMpp(args) {
|
|
|
552
552
|
}
|
|
553
553
|
const requirements = await pickSuiExactRequirements(probe, client.network);
|
|
554
554
|
if (requirements) {
|
|
555
|
-
|
|
555
|
+
const result = await payViaX402({ signer, client, options, reqInit, requirements });
|
|
556
|
+
await reportDirectPayment(result, options.url);
|
|
557
|
+
return result;
|
|
556
558
|
}
|
|
557
559
|
const headerChallenge = await parseMppSuiChallenge(probe);
|
|
558
560
|
if (headerChallenge) {
|
|
559
|
-
|
|
561
|
+
const result = await payViaMppHeader({ signer, client, options });
|
|
562
|
+
await reportDirectPayment(result, options.url);
|
|
563
|
+
return result;
|
|
560
564
|
}
|
|
561
565
|
throw new T2000Error(
|
|
562
566
|
"FACILITATOR_REJECTION",
|
|
563
567
|
`Endpoint returned 402 without an x402 'exact' / sui:${client.network} requirement in the body or an MPP 'sui' challenge in WWW-Authenticate. Nothing this SDK can pay.`
|
|
564
568
|
);
|
|
565
569
|
}
|
|
570
|
+
var MPP_REPORT_URL = "https://mpp.t2000.ai/api/mpp/report";
|
|
571
|
+
var REPORT_TIMEOUT_MS = 2e3;
|
|
572
|
+
async function reportDirectPayment(result, url) {
|
|
573
|
+
if (!result.paid || !result.receipt?.reference) return;
|
|
574
|
+
try {
|
|
575
|
+
if (new URL(url).origin === new URL(MPP_REPORT_URL).origin) return;
|
|
576
|
+
await fetch(MPP_REPORT_URL, {
|
|
577
|
+
method: "POST",
|
|
578
|
+
headers: { "content-type": "application/json" },
|
|
579
|
+
body: JSON.stringify({ digest: result.receipt.reference, url }),
|
|
580
|
+
signal: AbortSignal.timeout(REPORT_TIMEOUT_MS)
|
|
581
|
+
});
|
|
582
|
+
} catch {
|
|
583
|
+
}
|
|
584
|
+
}
|
|
566
585
|
async function parseMppSuiChallenge(response) {
|
|
567
586
|
try {
|
|
568
587
|
const { Challenge } = await import('mppx');
|