@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.cjs
CHANGED
|
@@ -554,17 +554,36 @@ async function payWithMpp(args) {
|
|
|
554
554
|
}
|
|
555
555
|
const requirements = await pickSuiExactRequirements(probe, client.network);
|
|
556
556
|
if (requirements) {
|
|
557
|
-
|
|
557
|
+
const result = await payViaX402({ signer, client, options, reqInit, requirements });
|
|
558
|
+
await reportDirectPayment(result, options.url);
|
|
559
|
+
return result;
|
|
558
560
|
}
|
|
559
561
|
const headerChallenge = await parseMppSuiChallenge(probe);
|
|
560
562
|
if (headerChallenge) {
|
|
561
|
-
|
|
563
|
+
const result = await payViaMppHeader({ signer, client, options });
|
|
564
|
+
await reportDirectPayment(result, options.url);
|
|
565
|
+
return result;
|
|
562
566
|
}
|
|
563
567
|
throw new exports.T2000Error(
|
|
564
568
|
"FACILITATOR_REJECTION",
|
|
565
569
|
`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.`
|
|
566
570
|
);
|
|
567
571
|
}
|
|
572
|
+
var MPP_REPORT_URL = "https://mpp.t2000.ai/api/mpp/report";
|
|
573
|
+
var REPORT_TIMEOUT_MS = 2e3;
|
|
574
|
+
async function reportDirectPayment(result, url) {
|
|
575
|
+
if (!result.paid || !result.receipt?.reference) return;
|
|
576
|
+
try {
|
|
577
|
+
if (new URL(url).origin === new URL(MPP_REPORT_URL).origin) return;
|
|
578
|
+
await fetch(MPP_REPORT_URL, {
|
|
579
|
+
method: "POST",
|
|
580
|
+
headers: { "content-type": "application/json" },
|
|
581
|
+
body: JSON.stringify({ digest: result.receipt.reference, url }),
|
|
582
|
+
signal: AbortSignal.timeout(REPORT_TIMEOUT_MS)
|
|
583
|
+
});
|
|
584
|
+
} catch {
|
|
585
|
+
}
|
|
586
|
+
}
|
|
568
587
|
async function parseMppSuiChallenge(response) {
|
|
569
588
|
try {
|
|
570
589
|
const { Challenge } = await import('mppx');
|