@relai-fi/x402 0.5.31 → 0.5.33
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/README.md +102 -0
- package/dist/index.cjs +61 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +61 -1
- package/dist/index.js.map +1 -1
- package/dist/plugins.cjs +150 -0
- package/dist/plugins.cjs.map +1 -0
- package/dist/plugins.d.cts +2 -0
- package/dist/plugins.d.ts +2 -0
- package/dist/plugins.js +125 -0
- package/dist/plugins.js.map +1 -0
- package/dist/server-BAPqyEka.d.cts +229 -0
- package/dist/server-BRSLRU_Y.d.ts +229 -0
- package/dist/server.cjs +61 -1
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +2 -138
- package/dist/server.d.ts +2 -138
- package/dist/server.js +61 -1
- package/dist/server.js.map +1 -1
- package/package.json +6 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { DynamicPrice, PaymentInfo, ProtectOptions,
|
|
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';
|
|
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 { DynamicPrice, PaymentInfo, ProtectOptions,
|
|
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';
|
|
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
|
@@ -448,11 +448,23 @@ async function createStripeDepositAddress(secretKey, amountUsdCents, network = "
|
|
|
448
448
|
return address;
|
|
449
449
|
}
|
|
450
450
|
var Relai = class {
|
|
451
|
-
// Cache feePayer per network
|
|
452
451
|
constructor(config) {
|
|
453
452
|
this.feePayerCache = /* @__PURE__ */ new Map();
|
|
453
|
+
this.pluginInitPromise = null;
|
|
454
454
|
this.network = config.network;
|
|
455
455
|
this.facilitatorUrl = config.facilitatorUrl || RELAI_FACILITATOR_URL;
|
|
456
|
+
this.plugins = config.plugins ?? [];
|
|
457
|
+
}
|
|
458
|
+
async runPluginInit() {
|
|
459
|
+
for (const plugin of this.plugins) {
|
|
460
|
+
if (plugin.onInit) {
|
|
461
|
+
try {
|
|
462
|
+
await plugin.onInit();
|
|
463
|
+
} catch (err) {
|
|
464
|
+
console.warn(`[Relai] Plugin '${plugin.name}' init failed:`, err);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
456
468
|
}
|
|
457
469
|
/**
|
|
458
470
|
* Get feePayer address for a network (cached)
|
|
@@ -543,6 +555,38 @@ var Relai = class {
|
|
|
543
555
|
const integritasFlow = headerIntegritasFlow || configuredIntegritas.flow;
|
|
544
556
|
const integritasMode = integritasFlow === "single" ? "single_signature_fee_included" : integritasFlow === "dual" ? "dual_signature_split" : void 0;
|
|
545
557
|
const paymentHeader = req.headers["x-payment"] || req.headers["payment-signature"] || req.headers["x-payment-signature"];
|
|
558
|
+
if (!paymentHeader && self.plugins.length > 0) {
|
|
559
|
+
if (!self.pluginInitPromise) {
|
|
560
|
+
self.pluginInitPromise = self.runPluginInit();
|
|
561
|
+
}
|
|
562
|
+
await self.pluginInitPromise;
|
|
563
|
+
const pluginCtx = {
|
|
564
|
+
network,
|
|
565
|
+
price: resolvedPrice,
|
|
566
|
+
path: req.path || req.originalUrl || "/",
|
|
567
|
+
method: (req.method || "GET").toUpperCase()
|
|
568
|
+
};
|
|
569
|
+
for (const plugin of self.plugins) {
|
|
570
|
+
if (!plugin.beforePaymentCheck) continue;
|
|
571
|
+
try {
|
|
572
|
+
const pluginResult = await plugin.beforePaymentCheck(req, pluginCtx);
|
|
573
|
+
if (pluginResult?.skip) {
|
|
574
|
+
if (pluginResult.headers) {
|
|
575
|
+
for (const [k, v] of Object.entries(pluginResult.headers)) {
|
|
576
|
+
res.setHeader(k, v);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
req.pluginMeta = { ...req.pluginMeta || {}, ...pluginResult.meta || {} };
|
|
580
|
+
req.x402Paid = false;
|
|
581
|
+
req.x402Free = true;
|
|
582
|
+
req.x402Plugin = plugin.name;
|
|
583
|
+
return next();
|
|
584
|
+
}
|
|
585
|
+
} catch (pluginErr) {
|
|
586
|
+
console.warn(`[Relai] Plugin '${plugin.name}' beforePaymentCheck error (non-blocking):`, pluginErr);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
546
590
|
if (!paymentHeader) {
|
|
547
591
|
options.onPaymentRequired?.(req, { price: resolvedPrice, network });
|
|
548
592
|
let resolvedPayTo;
|
|
@@ -681,6 +725,22 @@ var Relai = class {
|
|
|
681
725
|
Buffer.from(JSON.stringify(paymentResponse)).toString("base64")
|
|
682
726
|
);
|
|
683
727
|
options.onPaymentSettled?.(req, result);
|
|
728
|
+
if (self.plugins.length > 0) {
|
|
729
|
+
const settleCtx = {
|
|
730
|
+
network,
|
|
731
|
+
price: resolvedPrice,
|
|
732
|
+
path: req.path || req.originalUrl || "/",
|
|
733
|
+
method: (req.method || "GET").toUpperCase()
|
|
734
|
+
};
|
|
735
|
+
for (const plugin of self.plugins) {
|
|
736
|
+
if (!plugin.afterSettled) continue;
|
|
737
|
+
try {
|
|
738
|
+
await plugin.afterSettled(req, result, settleCtx);
|
|
739
|
+
} catch (pluginErr) {
|
|
740
|
+
console.warn(`[Relai] Plugin '${plugin.name}' afterSettled error (non-blocking):`, pluginErr);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
}
|
|
684
744
|
if (options.customRules) {
|
|
685
745
|
const valid = await options.customRules(req);
|
|
686
746
|
if (!valid) {
|