@relai-fi/x402 0.6.0-rc.2 → 0.6.0-rc.4

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
@@ -656,6 +656,47 @@ var Relai = class {
656
656
  req.x402Paid = false;
657
657
  req.x402Free = true;
658
658
  req.x402Plugin = plugin.name;
659
+ const skipPluginsWithHook = self.plugins.filter((p) => !!p.afterSettled);
660
+ if (skipPluginsWithHook.length > 0) {
661
+ const skipCtx = {
662
+ network,
663
+ price: resolvedPrice,
664
+ path: req.path || req.originalUrl || "/",
665
+ method: (req.method || "GET").toUpperCase()
666
+ };
667
+ const skipResult = {
668
+ success: true,
669
+ payer: req.headers?.["x-wallet-address"] || req.headers?.["x-buyer-address"] || req.ip || req.socket?.remoteAddress || "unknown",
670
+ transaction: ""
671
+ };
672
+ const originalJsonSkip = res.json?.bind(res);
673
+ const originalSendSkip = res.send?.bind(res);
674
+ let skipFired = false;
675
+ const fireSkipAfterSettled = (statusCode) => {
676
+ if (skipFired) return;
677
+ skipFired = true;
678
+ const resultWithStatus = { ...skipResult, statusCode };
679
+ for (const p of skipPluginsWithHook) {
680
+ p.afterSettled(req, resultWithStatus, skipCtx).catch((e) => {
681
+ console.warn(`[Relai] Plugin '${p.name}' afterSettled (skip) error:`, e);
682
+ });
683
+ }
684
+ };
685
+ if (typeof originalJsonSkip === "function") {
686
+ res.json = function(body) {
687
+ fireSkipAfterSettled(res.statusCode ?? 200);
688
+ res.json = originalJsonSkip;
689
+ return originalJsonSkip(body);
690
+ };
691
+ }
692
+ if (typeof originalSendSkip === "function") {
693
+ res.send = function(body) {
694
+ fireSkipAfterSettled(res.statusCode ?? 200);
695
+ res.send = originalSendSkip;
696
+ return originalSendSkip(body);
697
+ };
698
+ }
699
+ }
659
700
  return next();
660
701
  }
661
702
  } catch (pluginErr) {