@t2000/sdk 10.25.1 → 10.26.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 CHANGED
@@ -544,11 +544,8 @@ function preflightPay(input) {
544
544
  }
545
545
  return PREFLIGHT_OK;
546
546
  }
547
- async function payWithX402(args) {
548
- const { signer, client } = args;
549
- let options = args.options;
550
- const pf = preflightPay({ url: options.url, maxPrice: options.maxPrice });
551
- if (!pf.valid) throw new exports.T2000Error(pf.code, pf.error);
547
+ function normalizePayRequest(input) {
548
+ let options = input;
552
549
  const method = (options.method ?? "GET").toUpperCase();
553
550
  const canHaveBody = method !== "GET" && method !== "HEAD";
554
551
  if (canHaveBody && typeof options.body === "string" && isJsonText(options.body) && !hasContentType(options.headers)) {
@@ -557,11 +554,23 @@ async function payWithX402(args) {
557
554
  headers: { ...options.headers ?? {}, "content-type": "application/json" }
558
555
  };
559
556
  }
560
- const reqInit = {
561
- method,
562
- headers: options.headers,
563
- body: canHaveBody ? options.body : void 0
557
+ return {
558
+ options,
559
+ reqInit: {
560
+ method,
561
+ headers: options.headers,
562
+ body: canHaveBody ? options.body : void 0
563
+ }
564
564
  };
565
+ }
566
+ async function payWithX402(args) {
567
+ const { signer, client } = args;
568
+ let options = args.options;
569
+ const pf = preflightPay({ url: options.url, maxPrice: options.maxPrice });
570
+ if (!pf.valid) throw new exports.T2000Error(pf.code, pf.error);
571
+ const normalized = normalizePayRequest(options);
572
+ options = normalized.options;
573
+ const reqInit = normalized.reqInit;
565
574
  const probe = await fetch(options.url, reqInit);
566
575
  if (probe.status !== 402) {
567
576
  return finalize(probe, { paid: false });