@t2000/sdk 9.3.1 → 9.4.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/index.js
CHANGED
|
@@ -1145,17 +1145,36 @@ async function payWithMpp(args) {
|
|
|
1145
1145
|
}
|
|
1146
1146
|
const requirements = await pickSuiExactRequirements(probe, client.network);
|
|
1147
1147
|
if (requirements) {
|
|
1148
|
-
|
|
1148
|
+
const result = await payViaX402({ signer, client, options, reqInit, requirements });
|
|
1149
|
+
await reportDirectPayment(result, options.url);
|
|
1150
|
+
return result;
|
|
1149
1151
|
}
|
|
1150
1152
|
const headerChallenge = await parseMppSuiChallenge(probe);
|
|
1151
1153
|
if (headerChallenge) {
|
|
1152
|
-
|
|
1154
|
+
const result = await payViaMppHeader({ signer, client, options });
|
|
1155
|
+
await reportDirectPayment(result, options.url);
|
|
1156
|
+
return result;
|
|
1153
1157
|
}
|
|
1154
1158
|
throw new T2000Error(
|
|
1155
1159
|
"FACILITATOR_REJECTION",
|
|
1156
1160
|
`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.`
|
|
1157
1161
|
);
|
|
1158
1162
|
}
|
|
1163
|
+
var MPP_REPORT_URL = "https://mpp.t2000.ai/api/mpp/report";
|
|
1164
|
+
var REPORT_TIMEOUT_MS = 2e3;
|
|
1165
|
+
async function reportDirectPayment(result, url) {
|
|
1166
|
+
if (!result.paid || !result.receipt?.reference) return;
|
|
1167
|
+
try {
|
|
1168
|
+
if (new URL(url).origin === new URL(MPP_REPORT_URL).origin) return;
|
|
1169
|
+
await fetch(MPP_REPORT_URL, {
|
|
1170
|
+
method: "POST",
|
|
1171
|
+
headers: { "content-type": "application/json" },
|
|
1172
|
+
body: JSON.stringify({ digest: result.receipt.reference, url }),
|
|
1173
|
+
signal: AbortSignal.timeout(REPORT_TIMEOUT_MS)
|
|
1174
|
+
});
|
|
1175
|
+
} catch {
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1159
1178
|
async function parseMppSuiChallenge(response) {
|
|
1160
1179
|
try {
|
|
1161
1180
|
const { Challenge } = await import('mppx');
|