@t2000/sdk 9.3.0 → 9.3.1

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
@@ -1128,11 +1128,18 @@ function preflightPay(input) {
1128
1128
  return exports.PREFLIGHT_OK;
1129
1129
  }
1130
1130
  async function payWithMpp(args) {
1131
- const { signer, client, options } = args;
1131
+ const { signer, client } = args;
1132
+ let options = args.options;
1132
1133
  const pf = preflightPay({ url: options.url, maxPrice: options.maxPrice });
1133
1134
  if (!pf.valid) throw new exports.T2000Error(pf.code, pf.error);
1134
1135
  const method = (options.method ?? "GET").toUpperCase();
1135
1136
  const canHaveBody = method !== "GET" && method !== "HEAD";
1137
+ if (canHaveBody && typeof options.body === "string" && isJsonText(options.body) && !hasContentType(options.headers)) {
1138
+ options = {
1139
+ ...options,
1140
+ headers: { ...options.headers ?? {}, "content-type": "application/json" }
1141
+ };
1142
+ }
1136
1143
  const reqInit = {
1137
1144
  method,
1138
1145
  headers: options.headers,
@@ -1319,6 +1326,18 @@ async function ensureAddressBalanceCovers(args) {
1319
1326
  const migration = await executeTx(client, signer, () => tx, { buildClient: grpcClient });
1320
1327
  return migration.gasCostSui;
1321
1328
  }
1329
+ function isJsonText(text) {
1330
+ try {
1331
+ JSON.parse(text);
1332
+ return true;
1333
+ } catch {
1334
+ return false;
1335
+ }
1336
+ }
1337
+ function hasContentType(headers) {
1338
+ if (!headers) return false;
1339
+ return Object.keys(headers).some((k) => k.toLowerCase() === "content-type");
1340
+ }
1322
1341
  async function finalize(response, opts) {
1323
1342
  const contentType = response.headers.get("content-type") ?? "";
1324
1343
  let body2;