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