@t2000/cli 9.3.0 → 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.
@@ -9959,11 +9959,18 @@ function preflightPay(input) {
9959
9959
  return PREFLIGHT_OK;
9960
9960
  }
9961
9961
  async function payWithMpp(args) {
9962
- const { signer, client, options } = args;
9962
+ const { signer, client } = args;
9963
+ let options = args.options;
9963
9964
  const pf = preflightPay({ url: options.url, maxPrice: options.maxPrice });
9964
9965
  if (!pf.valid) throw new T2000Error(pf.code, pf.error);
9965
9966
  const method = (options.method ?? "GET").toUpperCase();
9966
9967
  const canHaveBody = method !== "GET" && method !== "HEAD";
9968
+ if (canHaveBody && typeof options.body === "string" && isJsonText(options.body) && !hasContentType(options.headers)) {
9969
+ options = {
9970
+ ...options,
9971
+ headers: { ...options.headers ?? {}, "content-type": "application/json" }
9972
+ };
9973
+ }
9967
9974
  const reqInit = {
9968
9975
  method,
9969
9976
  headers: options.headers,
@@ -9975,17 +9982,36 @@ async function payWithMpp(args) {
9975
9982
  }
9976
9983
  const requirements = await pickSuiExactRequirements(probe, client.network);
9977
9984
  if (requirements) {
9978
- return payViaX402({ signer, client, options, reqInit, requirements });
9985
+ const result = await payViaX402({ signer, client, options, reqInit, requirements });
9986
+ await reportDirectPayment(result, options.url);
9987
+ return result;
9979
9988
  }
9980
9989
  const headerChallenge = await parseMppSuiChallenge(probe);
9981
9990
  if (headerChallenge) {
9982
- return payViaMppHeader({ signer, client, options });
9991
+ const result = await payViaMppHeader({ signer, client, options });
9992
+ await reportDirectPayment(result, options.url);
9993
+ return result;
9983
9994
  }
9984
9995
  throw new T2000Error(
9985
9996
  "FACILITATOR_REJECTION",
9986
9997
  `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.`
9987
9998
  );
9988
9999
  }
10000
+ var MPP_REPORT_URL = "https://mpp.t2000.ai/api/mpp/report";
10001
+ var REPORT_TIMEOUT_MS = 2e3;
10002
+ async function reportDirectPayment(result, url) {
10003
+ if (!result.paid || !result.receipt?.reference) return;
10004
+ try {
10005
+ if (new URL(url).origin === new URL(MPP_REPORT_URL).origin) return;
10006
+ await fetch(MPP_REPORT_URL, {
10007
+ method: "POST",
10008
+ headers: { "content-type": "application/json" },
10009
+ body: JSON.stringify({ digest: result.receipt.reference, url }),
10010
+ signal: AbortSignal.timeout(REPORT_TIMEOUT_MS)
10011
+ });
10012
+ } catch {
10013
+ }
10014
+ }
9989
10015
  async function parseMppSuiChallenge(response) {
9990
10016
  try {
9991
10017
  const { Challenge } = await import("./dist-UO6YV6D3.js");
@@ -10150,6 +10176,18 @@ async function ensureAddressBalanceCovers(args) {
10150
10176
  const migration = await executeTx(client, signer, () => tx, { buildClient: grpcClient });
10151
10177
  return migration.gasCostSui;
10152
10178
  }
10179
+ function isJsonText(text) {
10180
+ try {
10181
+ JSON.parse(text);
10182
+ return true;
10183
+ } catch {
10184
+ return false;
10185
+ }
10186
+ }
10187
+ function hasContentType(headers) {
10188
+ if (!headers) return false;
10189
+ return Object.keys(headers).some((k) => k.toLowerCase() === "content-type");
10190
+ }
10153
10191
  async function finalize(response, opts) {
10154
10192
  const contentType = response.headers.get("content-type") ?? "";
10155
10193
  let body2;
@@ -12479,4 +12517,4 @@ export {
12479
12517
  @scure/bip39/index.js:
12480
12518
  (*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
12481
12519
  */
12482
- //# sourceMappingURL=chunk-DY7BZMEW.js.map
12520
+ //# sourceMappingURL=chunk-H7T7CQ27.js.map