@relai-fi/x402 0.5.35 → 0.5.37

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.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { D as DynamicPrice, F as FreeTierPluginConfig, b as PaymentInfo, g as PluginContext, h as PluginResult, P as ProtectOptions, R as Relai, d as RelaiIntegritasFlow, e as RelaiIntegritasOptions, f as RelaiPlugin, a as RelaiServerConfig, S as SettleResult, c as StripePayTo, R as default, s as stripePayTo } from './server-BAPqyEka.cjs';
1
+ export { B as BridgePluginConfig, D as DynamicPrice, F as FreeTierPluginConfig, b as PaymentInfo, g as PluginContext, h as PluginResult, P as ProtectOptions, R as Relai, d as RelaiIntegritasFlow, e as RelaiIntegritasOptions, f as RelaiPlugin, a as RelaiServerConfig, S as SettleResult, c as StripePayTo, R as default, s as stripePayTo } from './server-DPYBh7fy.cjs';
2
2
  export { RelayWebSocketFactory, RelayWebSocketLike, X402Client, X402ClientConfig, X402FetchInit, X402IntegritasConfig, X402IntegritasFlow, X402NetworkSelectionMode, X402RelayWsConfig, X402RelayWsError, X402RelayWsResponse, X402RequestOptions, default as createX402Client } from './client.cjs';
3
3
  export { A as AcceptsExtra, B as BASE_MAINNET_NETWORK, C as CAIP2_TO_NETWORK, b as CHAIN_IDS, E as EXPLORER_TX_URL, l as EvmWallet, N as NETWORK_CAIP2, e as NETWORK_LABELS, d as NETWORK_TOKENS, c as NetworkToken, P as PaymentAccept, o as PaymentRequired, R as RELAI_FACILITATOR_URL, h as RELAI_NETWORKS, a as RelaiNetwork, m as ResourceInfo, S as SOLANA_MAINNET_NETWORK, k as SolanaWallet, U as USDC_ADDRESSES, g as USDC_BASE, f as USDC_SOLANA, W as WalletSet, j as isEvm, i as isSolana, n as normalizeNetwork, r as resolveToken } from './types-Y9ni5XwY.cjs';
4
4
  export { BridgeBalances, BridgeQuoteResult, BridgeResult } from './management.cjs';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { D as DynamicPrice, F as FreeTierPluginConfig, b as PaymentInfo, g as PluginContext, h as PluginResult, P as ProtectOptions, R as Relai, d as RelaiIntegritasFlow, e as RelaiIntegritasOptions, f as RelaiPlugin, a as RelaiServerConfig, S as SettleResult, c as StripePayTo, R as default, s as stripePayTo } from './server-BRSLRU_Y.js';
1
+ export { B as BridgePluginConfig, D as DynamicPrice, F as FreeTierPluginConfig, b as PaymentInfo, g as PluginContext, h as PluginResult, P as ProtectOptions, R as Relai, d as RelaiIntegritasFlow, e as RelaiIntegritasOptions, f as RelaiPlugin, a as RelaiServerConfig, S as SettleResult, c as StripePayTo, R as default, s as stripePayTo } from './server-DJGM7dFH.js';
2
2
  export { RelayWebSocketFactory, RelayWebSocketLike, X402Client, X402ClientConfig, X402FetchInit, X402IntegritasConfig, X402IntegritasFlow, X402NetworkSelectionMode, X402RelayWsConfig, X402RelayWsError, X402RelayWsResponse, X402RequestOptions, default as createX402Client } from './client.js';
3
3
  export { A as AcceptsExtra, B as BASE_MAINNET_NETWORK, C as CAIP2_TO_NETWORK, b as CHAIN_IDS, E as EXPLORER_TX_URL, l as EvmWallet, N as NETWORK_CAIP2, e as NETWORK_LABELS, d as NETWORK_TOKENS, c as NetworkToken, P as PaymentAccept, o as PaymentRequired, R as RELAI_FACILITATOR_URL, h as RELAI_NETWORKS, a as RelaiNetwork, m as ResourceInfo, S as SOLANA_MAINNET_NETWORK, k as SolanaWallet, U as USDC_ADDRESSES, g as USDC_BASE, f as USDC_SOLANA, W as WalletSet, j as isEvm, i as isSolana, n as normalizeNetwork, r as resolveToken } from './types-Y9ni5XwY.js';
4
4
  export { BridgeBalances, BridgeQuoteResult, BridgeResult } from './management.js';
package/dist/index.js CHANGED
@@ -601,7 +601,7 @@ var Relai = class {
601
601
  resolvedPayTo = options.payTo;
602
602
  }
603
603
  const feePayer = options.feePayer || await self.getFeePayer(caip2);
604
- return res.status(402).json({
604
+ let paymentRequiredResponse = {
605
605
  x402Version: 2,
606
606
  error: "Payment required",
607
607
  resource: {
@@ -639,7 +639,24 @@ var Relai = class {
639
639
  }
640
640
  }
641
641
  } : {}
642
- });
642
+ };
643
+ if (self.plugins.length > 0) {
644
+ const enrichCtx = {
645
+ network,
646
+ price: resolvedPrice,
647
+ path: req.path || req.originalUrl || "/",
648
+ method: (req.method || "GET").toUpperCase()
649
+ };
650
+ for (const plugin of self.plugins) {
651
+ if (!plugin.enrich402Response) continue;
652
+ try {
653
+ paymentRequiredResponse = plugin.enrich402Response(paymentRequiredResponse, enrichCtx) || paymentRequiredResponse;
654
+ } catch (pluginErr) {
655
+ console.warn(`[Relai] Plugin '${plugin.name}' enrich402Response error (non-blocking):`, pluginErr);
656
+ }
657
+ }
658
+ }
659
+ return res.status(402).json(paymentRequiredResponse);
643
660
  }
644
661
  let paymentProof;
645
662
  try {
@@ -655,6 +672,39 @@ var Relai = class {
655
672
  });
656
673
  }
657
674
  }
675
+ if (paymentProof.bridged === true && paymentProof.targetTxId) {
676
+ console.log(`[Relai] Bridged payment accepted: source=${paymentProof.sourceTxId}, target=${paymentProof.targetTxId}`);
677
+ const paymentInfo2 = {
678
+ verified: true,
679
+ transactionId: paymentProof.targetTxId,
680
+ payer: paymentProof.sourceTxId || "bridge",
681
+ network,
682
+ amount: resolvedPrice
683
+ };
684
+ req.payment = paymentInfo2;
685
+ req.x402Payer = paymentProof.sourceTxId || "bridge";
686
+ req.x402Paid = true;
687
+ req.x402Transaction = paymentProof.targetTxId;
688
+ req.x402Network = network;
689
+ req.x402Bridged = true;
690
+ req.x402SourceChain = paymentProof.sourceChain;
691
+ const paymentResponse2 = {
692
+ x402Version: 2,
693
+ scheme: "exact",
694
+ network: caip2,
695
+ transaction: paymentProof.targetTxId,
696
+ payer: paymentProof.sourceTxId,
697
+ amount,
698
+ asset,
699
+ bridged: true
700
+ };
701
+ res.setHeader(
702
+ "PAYMENT-RESPONSE",
703
+ Buffer.from(JSON.stringify(paymentResponse2)).toString("base64")
704
+ );
705
+ options.onPaymentSettled?.(req, { success: true, transaction: paymentProof.targetTxId, payer: paymentProof.sourceTxId });
706
+ return next();
707
+ }
658
708
  let settlePayTo;
659
709
  if (stripeConfig) {
660
710
  settlePayTo = paymentProof.payload?.authorization?.to || paymentProof.accepted?.payTo || "";
@@ -669,7 +719,7 @@ var Relai = class {
669
719
  }
670
720
  const paymentRequirements = {
671
721
  scheme: "exact",
672
- network,
722
+ network: caip2,
673
723
  amount,
674
724
  asset,
675
725
  payTo: settlePayTo,